Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

@smartorg/bridge-client

Typed postMessage bridge between aiNav (iframe) and Rakaposhi (host).

Install

npm install github:SmartOrgDevelopment/bridge-client

Usage

aiNav (iframe side)

import{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: "..."},});

Rakaposhi (host side)

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();

With Zod validation

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},});

API

createBridge(options)

OptionTypeDefaultDescription
source"ainav-web" | "rakaposhi-host"requiredIdentifies the caller
allowedOriginsstring[][]Allowed origins (empty = allow all)
strictOriginCheckbooleanfalseEnable origin validation
targetOriginstring"*"Target origin for postMessage
validatebooleantrueValidate outgoing envelope schema

createAiNavBridge(options) / createHostBridge(options)

Shorthands that set source automatically.

bridge.send(type, payload)

Send a message to the host window.

bridge.onMessage(handler)unsubscribe()

Register a typed handler. Returns a cleanup function.

bridge.destroy()

Remove listeners and release resources.

About

Typed postMessage bridge between aiNav and Rakaposhi

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages