Typed postMessage bridge between aiNav (iframe) and Rakaposhi (host).
npm install github:SmartOrgDevelopment/bridge-clientimport{createAiNavBridge}from"@smartorg/bridge-client";constbridge=createAiNavBridge({allowedOrigins: ["https://app.smartorg.com"],strictOriginCheck: true,});bridge.send("NODE_DATA_UPDATED",{tool_name: "save_node_description",node_data: {nodeId: "...",treeId: "...",nodeName: "..."},});import{createHostBridge}from"@smartorg/bridge-client";constbridge=createHostBridge({allowedOrigins: ["https://ainav.smartorg.com"],strictOriginCheck: true,});constunsubscribe=bridge.onMessage({type: "NODE_DATA_UPDATED",handler: (payload)=>{// typed payload},});// Cleanup on destroyunsubscribe();bridge.destroy();import{z}from"zod";constNodeDataSchema=z.object({nodeId: z.string(),treeId: z.string(),});bridge.onMessage({type: "NODE_DATA_UPDATED",schema: NodeDataSchema,handler: (payload)=>{// payload is typed as z.infer<typeof NodeDataSchema>// schema mismatch logs an error instead of crashing},});| Option | Type | Default | Description |
|---|---|---|---|
source | "ainav-web" | "rakaposhi-host" | required | Identifies the caller |
allowedOrigins | string[] | [] | Allowed origins (empty = allow all) |
strictOriginCheck | boolean | false | Enable origin validation |
targetOrigin | string | "*" | Target origin for postMessage |
validate | boolean | true | Validate outgoing envelope schema |
Shorthands that set source automatically.
Send a message to the host window.
Register a typed handler. Returns a cleanup function.
Remove listeners and release resources.