import { t as SanityInstance } from "../createSanityInstance--Lrldto8.js";
import { n as StateSource, r as BoundStoreAction } from "../createStateSourceAction-CICvr0ZE.js";
import { ChannelInput, ChannelInstance, Controller, Message, Node, NodeInput, Status } from "@sanity/comlink";
/**
 * Message sent from a containing app to an iframe
 * @public
 */
type FrameMessage = Message;
/**
 * Message sent from an iframe to a containing app
 * @public
 */
type WindowMessage = Message;
/**
 * Message from SDK (iframe) to Parent (dashboard) to request a new token
 * @internal
 */
type RequestNewTokenMessage = {
  type: 'dashboard/v1/auth/tokens/create';
  payload?: undefined;
};
/**
 * Message from Parent (dashboard) to SDK (iframe) with the new token
 * @internal
 */
type NewTokenResponseMessage = {
  type: 'dashboard/v1/auth/tokens/create';
  payload: {
    token: string | null;
    error?: string;
  };
};
/**
 * Individual channel with its relevant options
 * @public
 */
interface ChannelEntry {
  channel: ChannelInstance<FrameMessage, WindowMessage>;
  options: ChannelInput;
  refCount: number;
}
/**
 * Internal state tracking comlink connections
 * @public
 */
interface ComlinkControllerState {
  controller: Controller | null;
  controllerOrigin: string | null;
  channels: Map<string, ChannelEntry>;
}
/**
 * Calls the destroy method on the controller and resets the controller state.
 * @public
 */
export declare const destroyController: BoundStoreAction<ComlinkControllerState, [], void>;
/**
 * Retrieve or create a channel to be used for communication between
 * an application and the controller.
 * @public
 */
export declare const getOrCreateChannel: BoundStoreAction<ComlinkControllerState, [options: ChannelInput], ChannelInstance<import("@sanity/comlink").Message, import("@sanity/comlink").Message>>;
/**
 * Initializes or fetches a controller to handle communication
 * between an application and iframes.
 * @public
 */
export declare const getOrCreateController: BoundStoreAction<ComlinkControllerState, [targetOrigin: string], Controller>;
/**
 * Signals to the store that the consumer has stopped using the channel
 * @public
 */
export declare const releaseChannel: BoundStoreAction<ComlinkControllerState, [name: string], void>;
/**
 * Individual node with its relevant options
 * @public
 */
interface NodeEntry {
  node: Node<WindowMessage, FrameMessage>;
  options: NodeInput;
  status: Status;
  statusUnsub?: () => void;
}
/**
 * Internal state tracking comlink connections
 * @public
 */
interface ComlinkNodeState {
  nodes: Map<string, NodeEntry>;
  subscriptions: Map<string, Set<symbol>>;
}
/**
 * Signals to the store that the consumer has stopped using the node
 * @public
 */
export declare const releaseNode: BoundStoreAction<ComlinkNodeState, [name: string], void>;
/**
 * Retrieve or create a node to be used for communication between
 * an application and the controller -- specifically, a node should
 * be created within a frame / window to communicate with the controller.
 *
 * Nodes are shared by name, so the message types must match the protocol spoken on that name.
 * @public
 */
export declare function getOrCreateNode<TWindowMessage extends WindowMessage = WindowMessage, TFrameMessage extends FrameMessage = FrameMessage>(instance: SanityInstance, options: NodeInput): Node<TWindowMessage, TFrameMessage>;
/**
 * @public
 */
interface NodeState<TWindowMessage extends WindowMessage = WindowMessage, TFrameMessage extends FrameMessage = FrameMessage> {
  node: Node<TWindowMessage, TFrameMessage>;
  status: Status | undefined;
}
/**
 * Provides a subscribable state source for a node by name
 * @param instance - The Sanity instance to get the node state for
 * @param nodeInput - The configuration for the node to get the state for
 * @returns A subscribable state source for the node
 * @public
 */
export declare function getNodeState<TWindowMessage extends WindowMessage = WindowMessage, TFrameMessage extends FrameMessage = FrameMessage>(instance: SanityInstance, nodeInput: NodeInput): StateSource<NodeState<TWindowMessage, TFrameMessage> | undefined>;
export type { ComlinkControllerState, ComlinkNodeState, FrameMessage, NewTokenResponseMessage, NodeState, RequestNewTokenMessage, WindowMessage };
//# sourceMappingURL=comlink.d.ts.map