@blockprotocol/external-api
Version:
Implementation of the Block Protocol external API service specification for blocks and embedding applications
26 lines (25 loc) • 1.38 kB
TypeScript
import { ServiceHandler } from "@blockprotocol/core";
import { EmbedderExternalApiMessageCallbacks, EmbedderExternalApiMessages } from "./types.js";
/**
* Creates a handler for the externalApi service for the embedder.
* Register callbacks in the constructor or afterwards using the 'on' method to
* react to messages from the block. Call the relevant methods to send messages
* to the block.
*/
export declare class ExternalApiEmbedderHandler extends ServiceHandler implements EmbedderExternalApiMessages {
constructor({ callbacks, element, }: {
callbacks?: Partial<EmbedderExternalApiMessageCallbacks>;
element?: HTMLElement | null;
});
/**
* Call the provided function when the named message is received, passing the
* data/errors object from the message. If the named message expects a
* response, the callback should provide the expected data/errors object as
* the return.
* @param messageName the message name to listen for
* @param handlerFunction the function to call when the message is received,
* with the message data / errors
*/
on<K extends keyof EmbedderExternalApiMessageCallbacks>(this: ExternalApiEmbedderHandler, messageName: K, handlerFunction: NonNullable<EmbedderExternalApiMessageCallbacks[K]>): void;
getInitPayload(this: ExternalApiEmbedderHandler): Record<string, any>;
}