Skip to content

SmartOrgDevelopment/bridge-client

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";

const bridge = 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";

const bridge = createHostBridge({
  allowedOrigins: ["https://ainav.smartorg.com"],
  strictOriginCheck: true,
});

const unsubscribe = bridge.onMessage({
  type: "NODE_DATA_UPDATED",
  handler: (payload) => {
    // typed payload
  },
});

// Cleanup on destroy
unsubscribe();
bridge.destroy();

With Zod validation

import { z } from "zod";

const NodeDataSchema = 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)

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

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

Watchers

Forks

Packages

 
 
 

Contributors