@schoolpalm/message-bridge 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,69 +1,18 @@
1
- /**
2
- * @fileoverview Base bridge class for message-based communication.
3
- * @module @schoolpalm/message-bridge/bridgeBase
4
- */
5
1
  import { MessageType } from './messageTypes';
6
- import { MessagePayload } from './payloadSchemas';
7
- /**
8
- * Type definition for message handler functions.
9
- * @template T - The type of message payload this handler accepts.
10
- */
11
- type MessageHandler<T extends MessagePayload> = (payload: T) => void;
12
- /**
13
- * Base class for Host and Module bridges.
14
- *
15
- * This abstract base class provides the core functionality for message-based
16
- * communication between windows using the postMessage API. It handles sending
17
- * messages, registering listeners, and managing event listeners.
18
- *
19
- * @example
20
- * ```typescript
21
- * class CustomBridge extends BridgeBase {
22
- * constructor(targetWindow: Window) {
23
- * super(targetWindow, 'https://example.com');
24
- * }
25
- *
26
- * // Add custom methods here
27
- * }
28
- * ```
29
- */
2
+ import { MessagePayloadMap } from './payloadSchemas';
3
+ import { RequestPayload } from './payloadSchemas';
4
+ type MessageHandler<T> = (payload: T) => void;
30
5
  export declare class BridgeBase {
31
- /** The target window to send messages to. */
32
6
  protected targetWindow: Window;
33
- /** The origin to restrict messages to. */
34
7
  protected targetOrigin: string;
35
- /** Map of message type to array of handler functions. */
36
8
  private listeners;
37
- /**
38
- * Creates a new BridgeBase instance.
39
- * @param targetWindow - The window to send messages to.
40
- * @param targetOrigin - The origin to restrict messages to (default: '*').
41
- */
9
+ private pendingRequests;
10
+ private boundHandler;
42
11
  constructor(targetWindow: Window, targetOrigin?: string);
43
- /**
44
- * Sends a message to the target window.
45
- * @template T - The type of the message payload.
46
- * @param type - The message type to send.
47
- * @param payload - The payload data to send.
48
- */
49
- send<T extends MessagePayload>(type: MessageType, payload: T): void;
50
- /**
51
- * Registers a listener for a specific message type.
52
- * @template T - The type of the message payload.
53
- * @param type - The message type to listen for.
54
- * @param callback - The function to call when a message of this type is received.
55
- */
56
- on<T extends MessagePayload>(type: MessageType, callback: MessageHandler<T>): void;
57
- /**
58
- * Internal message handler for incoming postMessage events.
59
- * @private
60
- * @param event - The message event received.
61
- */
62
- private _handleMessage;
63
- /**
64
- * Cleans up event listeners and resources.
65
- * Call this method when the bridge is no longer needed.
66
- */
12
+ send<T extends MessageType>(type: T, payload: MessagePayloadMap[T]): void;
13
+ request<R = any>(type: MessageType, payload: RequestPayload, timeout?: number): Promise<R>;
14
+ on<T extends MessageType>(type: T, callback: MessageHandler<MessagePayloadMap[T]>): void;
15
+ protected handleMessage(event: MessageEvent): void;
67
16
  destroy(): void;
68
17
  }
69
18
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"bridgeBase.d.ts","sourceRoot":"","sources":["../src/bridgeBase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;GAGG;AACH,KAAK,cAAc,CAAC,CAAC,SAAS,cAAc,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;AAErE;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,UAAU;IACrB,6CAA6C;IAC7C,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAC/B,0CAA0C;IAC1C,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAC/B,yDAAyD;IACzD,OAAO,CAAC,SAAS,CAAsD;IAEvE;;;;OAIG;gBACS,YAAY,EAAE,MAAM,EAAE,YAAY,GAAE,MAAY;IAM5D;;;;;OAKG;IACH,IAAI,CAAC,CAAC,SAAS,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;IAI5D;;;;;OAKG;IACH,EAAE,CAAC,CAAC,SAAS,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;IAK3E;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAMtB;;;OAGG;IACH,OAAO;CAIR"}
1
+ {"version":3,"file":"bridgeBase.d.ts","sourceRoot":"","sources":["../src/bridgeBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAmB,MAAM,kBAAkB,CAAA;AAElE,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAA;AAE7C,qBAAa,UAAU;IACrB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAA;IAC9B,SAAS,CAAC,YAAY,EAAE,MAAM,CAAA;IAE9B,OAAO,CAAC,SAAS,CAAgD;IACjE,OAAO,CAAC,eAAe,CAA4C;IACnE,OAAO,CAAC,YAAY,CAA+B;gBAEvC,YAAY,EAAE,MAAM,EAAE,YAAY,GAAE,MAAY;IAW5D,IAAI,CAAC,CAAC,SAAS,WAAW,EACxB,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAQhC,OAAO,CAAC,CAAC,GAAG,GAAG,EACd,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,cAAc,EACvB,OAAO,SAAO,GACb,OAAO,CAAC,CAAC,CAAC;IA2BX,EAAE,CAAC,CAAC,SAAS,WAAW,EACtB,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAWhD,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,YAAY;IAqB3C,OAAO;CAKR"}
@@ -1,76 +1,77 @@
1
- /**
2
- * @fileoverview Base bridge class for message-based communication.
3
- * @module @schoolpalm/message-bridge/bridgeBase
4
- */
5
- /**
6
- * Base class for Host and Module bridges.
7
- *
8
- * This abstract base class provides the core functionality for message-based
9
- * communication between windows using the postMessage API. It handles sending
10
- * messages, registering listeners, and managing event listeners.
11
- *
12
- * @example
13
- * ```typescript
14
- * class CustomBridge extends BridgeBase {
15
- * constructor(targetWindow: Window) {
16
- * super(targetWindow, 'https://example.com');
17
- * }
18
- *
19
- * // Add custom methods here
20
- * }
21
- * ```
22
- */
1
+ import { MessageType } from './messageTypes';
23
2
  export class BridgeBase {
24
- /**
25
- * Creates a new BridgeBase instance.
26
- * @param targetWindow - The window to send messages to.
27
- * @param targetOrigin - The origin to restrict messages to (default: '*').
28
- */
29
3
  constructor(targetWindow, targetOrigin = '*') {
30
- /** Map of message type to array of handler functions. */
31
4
  this.listeners = new Map();
5
+ this.pendingRequests = new Map();
32
6
  this.targetWindow = targetWindow;
33
7
  this.targetOrigin = targetOrigin;
34
- window.addEventListener('message', this._handleMessage.bind(this));
8
+ this.boundHandler = this.handleMessage.bind(this);
9
+ window.addEventListener('message', this.boundHandler);
35
10
  }
36
- /**
37
- * Sends a message to the target window.
38
- * @template T - The type of the message payload.
39
- * @param type - The message type to send.
40
- * @param payload - The payload data to send.
41
- */
11
+ // --------------------
12
+ // Send (typed)
13
+ // --------------------
42
14
  send(type, payload) {
43
15
  this.targetWindow.postMessage({ type, payload }, this.targetOrigin);
44
16
  }
45
- /**
46
- * Registers a listener for a specific message type.
47
- * @template T - The type of the message payload.
48
- * @param type - The message type to listen for.
49
- * @param callback - The function to call when a message of this type is received.
50
- */
17
+ // --------------------
18
+ // Request / Response
19
+ // --------------------
20
+ request(type, payload, timeout = 5000) {
21
+ return new Promise((resolve, reject) => {
22
+ const requestId = payload.requestId;
23
+ this.pendingRequests.set(requestId, (response) => {
24
+ if (response.status === 'error') {
25
+ reject(new Error(response.error ?? 'Unknown error'));
26
+ }
27
+ else {
28
+ resolve(response.payload);
29
+ }
30
+ });
31
+ this.send(type, payload);
32
+ setTimeout(() => {
33
+ if (this.pendingRequests.has(requestId)) {
34
+ this.pendingRequests.delete(requestId);
35
+ reject(new Error(`Request ${payload.type} timed out`));
36
+ }
37
+ }, timeout);
38
+ });
39
+ }
40
+ // --------------------
41
+ // Listeners (typed)
42
+ // --------------------
51
43
  on(type, callback) {
52
- if (!this.listeners.has(type))
44
+ if (!this.listeners.has(type)) {
53
45
  this.listeners.set(type, []);
54
- this.listeners.get(type)?.push(callback);
46
+ }
47
+ this.listeners.get(type).push(callback);
55
48
  }
56
- /**
57
- * Internal message handler for incoming postMessage events.
58
- * @private
59
- * @param event - The message event received.
60
- */
61
- _handleMessage(event) {
49
+ // --------------------
50
+ // Dispatcher
51
+ // --------------------
52
+ handleMessage(event) {
53
+ if (this.targetOrigin !== '*' && event.origin !== this.targetOrigin)
54
+ return;
62
55
  const { type, payload } = event.data || {};
63
- if (!type || !this.listeners.has(type))
56
+ if (!type)
64
57
  return;
65
- this.listeners.get(type)?.forEach(cb => cb(payload));
58
+ // Handle responses
59
+ if (type === MessageType.DATA_RESPONSE) {
60
+ const response = payload;
61
+ const resolver = this.pendingRequests.get(response.requestId);
62
+ if (resolver) {
63
+ resolver(response);
64
+ this.pendingRequests.delete(response.requestId);
65
+ return;
66
+ }
67
+ }
68
+ const handlers = this.listeners.get(type);
69
+ handlers?.forEach(cb => cb(payload));
66
70
  }
67
- /**
68
- * Cleans up event listeners and resources.
69
- * Call this method when the bridge is no longer needed.
70
- */
71
71
  destroy() {
72
- window.removeEventListener('message', this._handleMessage.bind(this));
72
+ window.removeEventListener('message', this.boundHandler);
73
73
  this.listeners.clear();
74
+ this.pendingRequests.clear();
74
75
  }
75
76
  }
76
77
  //# sourceMappingURL=bridgeBase.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridgeBase.js","sourceRoot":"","sources":["../src/bridgeBase.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,UAAU;IAQrB;;;;OAIG;IACH,YAAY,YAAoB,EAAE,eAAuB,GAAG;QAR5D,yDAAyD;QACjD,cAAS,GAA4C,IAAI,GAA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IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;YAC7D,IAAI,QAAQ,EAAE,CAAC;gBACb,QAAQ,CAAC,QAAQ,CAAC,CAAA;gBAClB,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;gBAC/C,OAAM;YACR,CAAC;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACzC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IACtC,CAAC;IAED,OAAO;QACL,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;QACxD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAA;QACtB,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAA;IAC9B,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export declare class BridgeError extends Error {
2
+ code: string;
3
+ constructor(message: string, code: string);
4
+ }
5
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAY,SAAQ,KAAK;IACA,IAAI,EAAE,MAAM;gBAApC,OAAO,EAAE,MAAM,EAAS,IAAI,EAAE,MAAM;CAGjD"}
package/dist/errors.js ADDED
@@ -0,0 +1,7 @@
1
+ export class BridgeError extends Error {
2
+ constructor(message, code) {
3
+ super(message);
4
+ this.code = code;
5
+ }
6
+ }
7
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe,EAAS,IAAY;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAA;QADoB,SAAI,GAAJ,IAAI,CAAQ;IAEhD,CAAC;CACF"}
@@ -1,52 +1,23 @@
1
- /**
2
- * @fileoverview Host-side bridge for communication with embedded modules.
3
- * @module @schoolpalm/message-bridge/hostBridge
4
- */
5
1
  import { BridgeBase } from './bridgeBase';
6
- import { ModuleStartPayload } from './payloadSchemas';
7
- /**
8
- * Host-side bridge for communication with embedded modules.
9
- *
10
- * This class extends BridgeBase to provide host-specific functionality for
11
- * communicating with modules embedded in iframes. It handles initialization
12
- * and termination of modules.
13
- *
14
- * @example
15
- * ```typescript
16
- * const iframe = document.getElementById('module-iframe') as HTMLIFrameElement;
17
- * const hostBridge = new HostBridge(iframe, 'https://module.example.com');
18
- *
19
- * // Start a module
20
- * hostBridge.sendModuleStart({
21
- * route: '/dashboard',
22
- * context: { userId: 123 },
23
- * timestamp: Date.now()
24
- * });
25
- *
26
- * // Listen for UI updates from the module
27
- * hostBridge.on(MessageType.UI_UPDATE, (payload) => {
28
- * console.log('UI Update:', payload);
29
- * });
30
- * ```
31
- */
2
+ import { ModuleStartPayload, UIUpdatePayload, ErrorPayload, ModuleContextPayload, HandshakeReadyPayload } from './payloadSchemas';
32
3
  export declare class HostBridge extends BridgeBase {
33
- /**
34
- * Creates a new HostBridge instance.
35
- * @param iframe - The iframe element containing the module.
36
- * @param targetOrigin - The origin to restrict messages to (default: '*').
37
- */
4
+ private handshakeCompleted;
5
+ private handshakePayload;
6
+ private pendingStartPayload;
38
7
  constructor(iframe: HTMLIFrameElement, targetOrigin?: string);
39
- /**
40
- * Sends a module-start message to the embedded module.
41
- * This initializes the module with the provided route and context.
42
- * @param payload - The module start payload containing route, context, and timestamp.
43
- */
8
+ onHandshakeReady(callback: (payload: HandshakeReadyPayload) => void): void;
9
+ private heartbeatTimer?;
10
+ startHeartbeat(interval?: number): void;
11
+ stopHeartbeat(): void;
12
+ private lastHeartbeat;
13
+ listenHeartbeat(timeout?: number): void;
14
+ startModule(payload: ModuleStartPayload, timeout?: number): void;
44
15
  sendModuleStart(payload: ModuleStartPayload): void;
45
- /**
46
- * Sends a module-exit message to the embedded module.
47
- * This signals the module to clean up and terminate.
48
- * @param reason - Optional reason for the module exit.
49
- */
50
16
  sendModuleExit(reason?: string): void;
17
+ onUIUpdate(callback: (payload: UIUpdatePayload) => void): void;
18
+ onError(callback: (payload: ErrorPayload) => void): void;
19
+ sendContextUpdate(payload: ModuleContextPayload): void;
20
+ requestData<T = any, R = any>(type: string, payload?: T, timeout?: number): Promise<R>;
21
+ reset(): void;
51
22
  }
52
23
  //# sourceMappingURL=hostBridge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hostBridge.d.ts","sourceRoot":"","sources":["../src/hostBridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,UAAW,SAAQ,UAAU;IACxC;;;;OAIG;gBACS,MAAM,EAAE,iBAAiB,EAAE,YAAY,GAAE,MAAY;IAIjE;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,kBAAkB;IAI3C;;;;OAIG;IACH,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM;CAG/B"}
1
+ {"version":3,"file":"hostBridge.d.ts","sourceRoot":"","sources":["../src/hostBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,EACL,kBAAkB,EAElB,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EAGtB,MAAM,kBAAkB,CAAA;AAGzB,qBAAa,UAAW,SAAQ,UAAU;IACxC,OAAO,CAAC,kBAAkB,CAAQ;IAClC,OAAO,CAAC,gBAAgB,CAAqC;IAC7D,OAAO,CAAC,mBAAmB,CAAkC;gBAEjD,MAAM,EAAE,iBAAiB,EAAE,YAAY,GAAE,MAAY;IAUnE,gBAAgB,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,IAAI;IA2BnE,OAAO,CAAC,cAAc,CAAC,CAAQ;IAE/B,cAAc,CAAC,QAAQ,SAAO;IAS9B,aAAa;IAOb,OAAO,CAAC,aAAa,CAAa;IAElC,eAAe,CAAC,OAAO,SAAQ;IAiB7B,WAAW,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,SAAO;IAevD,eAAe,CAAC,OAAO,EAAE,kBAAkB;IAI3C,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM;IAO9B,UAAU,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,IAAI;IAIvD,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI;IAOjD,iBAAiB,CAAC,OAAO,EAAE,oBAAoB;IAOhD,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,CAAC,EACX,OAAO,SAAO,GACb,OAAO,CAAC,CAAC,CAAC;IAiBX,KAAK;CAKN"}
@@ -1,59 +1,115 @@
1
- /**
2
- * @fileoverview Host-side bridge for communication with embedded modules.
3
- * @module @schoolpalm/message-bridge/hostBridge
4
- */
5
- // src/hostBridge.ts
6
1
  import { BridgeBase } from './bridgeBase';
7
2
  import { MessageType } from './messageTypes';
8
- /**
9
- * Host-side bridge for communication with embedded modules.
10
- *
11
- * This class extends BridgeBase to provide host-specific functionality for
12
- * communicating with modules embedded in iframes. It handles initialization
13
- * and termination of modules.
14
- *
15
- * @example
16
- * ```typescript
17
- * const iframe = document.getElementById('module-iframe') as HTMLIFrameElement;
18
- * const hostBridge = new HostBridge(iframe, 'https://module.example.com');
19
- *
20
- * // Start a module
21
- * hostBridge.sendModuleStart({
22
- * route: '/dashboard',
23
- * context: { userId: 123 },
24
- * timestamp: Date.now()
25
- * });
26
- *
27
- * // Listen for UI updates from the module
28
- * hostBridge.on(MessageType.UI_UPDATE, (payload) => {
29
- * console.log('UI Update:', payload);
30
- * });
31
- * ```
32
- */
3
+ import { PROTOCOL_VERSION } from './protocol';
33
4
  export class HostBridge extends BridgeBase {
34
- /**
35
- * Creates a new HostBridge instance.
36
- * @param iframe - The iframe element containing the module.
37
- * @param targetOrigin - The origin to restrict messages to (default: '*').
38
- */
39
5
  constructor(iframe, targetOrigin = '*') {
6
+ if (!iframe.contentWindow) {
7
+ throw new Error('Iframe has no contentWindow');
8
+ }
40
9
  super(iframe.contentWindow, targetOrigin);
10
+ this.handshakeCompleted = false;
11
+ this.handshakePayload = null;
12
+ this.pendingStartPayload = null;
13
+ this.lastHeartbeat = Date.now();
14
+ }
15
+ // --------------------
16
+ // Handshake (sticky)
17
+ // --------------------
18
+ onHandshakeReady(callback) {
19
+ if (this.handshakeCompleted && this.handshakePayload) {
20
+ callback(this.handshakePayload);
21
+ return;
22
+ }
23
+ this.on(MessageType.HANDSHAKE_READY, payload => {
24
+ // ✅ payload is HandshakeReadyPayload
25
+ if (payload.version !== PROTOCOL_VERSION) {
26
+ console.warn(`Protocol mismatch: host=${PROTOCOL_VERSION}, module=${payload.version}`);
27
+ }
28
+ this.handshakeCompleted = true;
29
+ this.handshakePayload = payload;
30
+ callback(payload);
31
+ if (this.pendingStartPayload) {
32
+ this.sendModuleStart(this.pendingStartPayload);
33
+ this.pendingStartPayload = null;
34
+ }
35
+ });
36
+ }
37
+ startHeartbeat(interval = 5000) {
38
+ this.stopHeartbeat();
39
+ this.heartbeatTimer = window.setInterval(() => {
40
+ this.send(MessageType.HEARTBEAT, { timestamp: Date.now() });
41
+ }, interval);
42
+ }
43
+ stopHeartbeat() {
44
+ if (this.heartbeatTimer) {
45
+ clearInterval(this.heartbeatTimer);
46
+ this.heartbeatTimer = undefined;
47
+ }
48
+ }
49
+ listenHeartbeat(timeout = 15000) {
50
+ this.on(MessageType.HEARTBEAT, () => {
51
+ this.lastHeartbeat = Date.now();
52
+ });
53
+ setInterval(() => {
54
+ if (Date.now() - this.lastHeartbeat > timeout) {
55
+ console.error('Module heartbeat lost');
56
+ this.sendModuleExit('heartbeat-timeout');
57
+ }
58
+ }, timeout);
59
+ }
60
+ // --------------------
61
+ // Start (idempotent)
62
+ // --------------------
63
+ startModule(payload, timeout = 5000) {
64
+ if (this.handshakeCompleted) {
65
+ this.sendModuleStart(payload);
66
+ return;
67
+ }
68
+ this.pendingStartPayload = payload;
69
+ const timer = setTimeout(() => {
70
+ console.error('Module handshake timeout');
71
+ }, timeout);
72
+ this.onHandshakeReady(() => clearTimeout(timer));
41
73
  }
42
- /**
43
- * Sends a module-start message to the embedded module.
44
- * This initializes the module with the provided route and context.
45
- * @param payload - The module start payload containing route, context, and timestamp.
46
- */
47
74
  sendModuleStart(payload) {
48
75
  this.send(MessageType.MODULE_START, payload);
49
76
  }
50
- /**
51
- * Sends a module-exit message to the embedded module.
52
- * This signals the module to clean up and terminate.
53
- * @param reason - Optional reason for the module exit.
54
- */
55
77
  sendModuleExit(reason) {
56
78
  this.send(MessageType.MODULE_EXIT, { reason });
57
79
  }
80
+ // --------------------
81
+ // UI / Errors
82
+ // --------------------
83
+ onUIUpdate(callback) {
84
+ this.on(MessageType.UI_UPDATE, callback);
85
+ }
86
+ onError(callback) {
87
+ this.on(MessageType.ERROR, callback);
88
+ }
89
+ // --------------------
90
+ // Context sync
91
+ // --------------------
92
+ sendContextUpdate(payload) {
93
+ this.send(MessageType.CONTEXT_UPDATE, payload);
94
+ }
95
+ // --------------------
96
+ // Requests
97
+ // --------------------
98
+ requestData(type, payload, timeout = 5000) {
99
+ const request = {
100
+ requestId: crypto.randomUUID(),
101
+ type,
102
+ payload: payload,
103
+ };
104
+ return this.request(MessageType.DATA_REQUEST, request, timeout);
105
+ }
106
+ // --------------------
107
+ // Reset (reconnect)
108
+ // --------------------
109
+ reset() {
110
+ this.handshakeCompleted = false;
111
+ this.handshakePayload = null;
112
+ this.pendingStartPayload = null;
113
+ }
58
114
  }
59
115
  //# sourceMappingURL=hostBridge.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hostBridge.js","sourceRoot":"","sources":["../src/hostBridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oBAAoB;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;IACxC;;;;OAIG;IACH,YAAY,MAAyB,EAAE,eAAuB,GAAG;QAC/D,KAAK,CAAC,MAAM,CAAC,aAAc,EAAE,YAAY,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,OAA2B;QACzC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,MAAe;QAC5B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC;CACF"}
1
+ {"version":3,"file":"hostBridge.js","sourceRoot":"","sources":["../src/hostBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAW5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,OAAO,UAAW,SAAQ,UAAU;IAKxC,YAAY,MAAyB,EAAE,eAAuB,GAAG;QAC/D,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAChD,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,aAAa,EAAE,Y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AC,YAAY,EAAE,OAAO,CAAC,CAAA;IAC9C,CAAC;IAED,cAAc,CAAC,MAAe;QAC5B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,MAAM,EAAuB,CAAC,CAAA;IACrE,CAAC;IAED,uBAAuB;IACvB,cAAc;IACd,uBAAuB;IACvB,UAAU,CAAC,QAA4C;QACrD,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;IAC1C,CAAC;IAED,OAAO,CAAC,QAAyC;QAC/C,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IACtC,CAAC;IAED,uBAAuB;IACvB,eAAe;IACf,uBAAuB;IACvB,iBAAiB,CAAC,OAA6B;QAC7C,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;IAChD,CAAC;IAED,uBAAuB;IACvB,WAAW;IACX,uBAAuB;IACxB,WAAW,CACV,IAAY,EACZ,OAAW,EACX,OAAO,GAAG,IAAI;QAEd,MAAM,OAAO,GAAmB;YAC9B,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE;YAC9B,IAAI;YACJ,OAAO,EAAE,OAAc;SACxB,CAAA;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,WAAW,CAAC,YAAY,EACxB,OAAO,EACP,OAAO,CACR,CAAA;IACH,CAAC;IAEC,uBAAuB;IACvB,oBAAoB;IACpB,uBAAuB;IACvB,KAAK;QACH,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAA;QAC/B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAA;QAC5B,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAA;IACjC,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export declare const debug: (...args: any[]) => void;
2
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,GAAI,GAAG,MAAM,GAAG,EAAE,SAGnC,CAAA"}
package/dist/logger.js ADDED
@@ -0,0 +1,4 @@
1
+ export const debug = (...args) => {
2
+ console.debug('[MessageBridge]', ...args);
3
+ };
4
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;IACpC,OAAO,CAAC,KAAK,CAAC,iBAAiB,EAAE,GAAG,IAAI,CAAC,CAAA;AAE7C,CAAC,CAAA"}
@@ -33,6 +33,8 @@ export declare enum MessageType {
33
33
  /** Module → Host: Reports an error to the host. */
34
34
  ERROR = "error",
35
35
  /** Host → Module: Signals the module to exit and clean up. */
36
- MODULE_EXIT = "module:exit"
36
+ MODULE_EXIT = "module:exit",
37
+ CONTEXT_UPDATE = "context:update",
38
+ HEARTBEAT = "heartbeat"
37
39
  }
38
40
  //# sourceMappingURL=messageTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"messageTypes.d.ts","sourceRoot":"","sources":["../src/messageTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;;;;;;;GAgBG;AACH,oBAAY,WAAW;IACrB,sEAAsE;IACtE,eAAe,oBAAoB;IACnC,wEAAwE;IACxE,YAAY,iBAAiB;IAC7B,qEAAqE;IACrE,SAAS,cAAc;IACvB,kDAAkD;IAClD,YAAY,iBAAiB;IAC7B,iDAAiD;IACjD,aAAa,kBAAkB;IAC/B,mDAAmD;IACnD,KAAK,UAAU;IACf,8DAA8D;IAC9D,WAAW,gBAAgB;CAC5B"}
1
+ {"version":3,"file":"messageTypes.d.ts","sourceRoot":"","sources":["../src/messageTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;;;;;;;GAgBG;AACH,oBAAY,WAAW;IACrB,sEAAsE;IACtE,eAAe,oBAAoB;IACnC,wEAAwE;IACxE,YAAY,iBAAiB;IAC7B,qEAAqE;IACrE,SAAS,cAAc;IACvB,kDAAkD;IAClD,YAAY,iBAAiB;IAC7B,iDAAiD;IACjD,aAAa,kBAAkB;IAC/B,mDAAmD;IACnD,KAAK,UAAU;IACf,8DAA8D;IAC9D,WAAW,gBAAgB;IAC3B,cAAc,mBAAmB;IAEjC,SAAS,cAAc;CAExB"}
@@ -36,5 +36,8 @@ export var MessageType;
36
36
  MessageType["ERROR"] = "error";
37
37
  /** Host → Module: Signals the module to exit and clean up. */
38
38
  MessageType["MODULE_EXIT"] = "module:exit";
39
+ MessageType["CONTEXT_UPDATE"] = "context:update";
40
+ // messageTypes.ts
41
+ MessageType["HEARTBEAT"] = "heartbeat";
39
42
  })(MessageType || (MessageType = {}));
40
43
  //# sourceMappingURL=messageTypes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"messageTypes.js","sourceRoot":"","sources":["../src/messageTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sBAAsB;AAEtB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAN,IAAY,WAeX;AAfD,WAAY,WAAW;IACrB,sEAAsE;IACtE,kDAAmC,CAAA;IACnC,wEAAwE;IACxE,4CAA6B,CAAA;IAC7B,qEAAqE;IACrE,sCAAuB,CAAA;IACvB,kDAAkD;IAClD,4CAA6B,CAAA;IAC7B,iDAAiD;IACjD,8CAA+B,CAAA;IAC/B,mDAAmD;IACnD,8BAAe,CAAA;IACf,8DAA8D;IAC9D,0CAA2B,CAAA;AAC7B,CAAC,EAfW,WAAW,KAAX,WAAW,QAetB"}
1
+ {"version":3,"file":"messageTypes.js","sourceRoot":"","sources":["../src/messageTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sBAAsB;AAEtB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAN,IAAY,WAmBX;AAnBD,WAAY,WAAW;IACrB,sEAAsE;IACtE,kDAAmC,CAAA;IACnC,wEAAwE;IACxE,4CAA6B,CAAA;IAC7B,qEAAqE;IACrE,sCAAuB,CAAA;IACvB,kDAAkD;IAClD,4CAA6B,CAAA;IAC7B,iDAAiD;IACjD,8CAA+B,CAAA;IAC/B,mDAAmD;IACnD,8BAAe,CAAA;IACf,8DAA8D;IAC9D,0CAA2B,CAAA;IAC3B,gDAAiC,CAAA;IACjC,kBAAkB;IAClB,sCAAuB,CAAA;AAEzB,CAAC,EAnBW,WAAW,KAAX,WAAW,QAmBtB"}
@@ -1,61 +1,14 @@
1
- /**
2
- * @fileoverview Module-side bridge for communication with the host application.
3
- * @module @schoolpalm/message-bridge/moduleBridge
4
- */
5
1
  import { BridgeBase } from './bridgeBase';
6
- import { HandshakeReadyPayload, UIUpdatePayload, ErrorPayload } from './payloadSchemas';
7
- /**
8
- * Module-side bridge for communication with the host application.
9
- *
10
- * This class extends BridgeBase to provide module-specific functionality for
11
- * communicating with the parent host application. It handles handshake,
12
- * UI updates, and error reporting from the embedded module.
13
- *
14
- * @example
15
- * ```typescript
16
- * const moduleBridge = new ModuleBridge('https://host.example.com');
17
- *
18
- * // Send handshake when module is ready
19
- * moduleBridge.sendHandshake({
20
- * version: '1.0.0',
21
- * timestamp: Date.now()
22
- * });
23
- *
24
- * // Update UI in the host
25
- * moduleBridge.sendUIUpdate({
26
- * title: 'Dashboard',
27
- * breadcrumb: ['Home', 'Dashboard'],
28
- * theme: 'dark'
29
- * });
30
- *
31
- * // Listen for module start from host
32
- * moduleBridge.on(MessageType.MODULE_START, (payload) => {
33
- * console.log('Module started:', payload.route);
34
- * });
35
- * ```
36
- */
2
+ import { HandshakeReadyPayload, UIUpdatePayload, ErrorPayload, HeartbeatPayload } from './payloadSchemas';
37
3
  export declare class ModuleBridge extends BridgeBase {
38
- /**
39
- * Creates a new ModuleBridge instance.
40
- * @param targetOrigin - The origin to restrict messages to (default: '*').
41
- */
4
+ private startedPayload;
42
5
  constructor(targetOrigin?: string);
43
- /**
44
- * Notifies the host application that the module is ready.
45
- * This should be called after the module has initialized.
46
- * @param payload - The handshake payload containing version and timestamp.
47
- */
48
6
  sendHandshake(payload: HandshakeReadyPayload): void;
49
- /**
50
- * Notifies the host application of UI updates.
51
- * This includes changes to title, breadcrumb, and theme.
52
- * @param payload - The UI update payload.
53
- */
7
+ onModuleStart(callback: (payload: any) => void): void;
8
+ onHeartbeat(callback?: (payload: HeartbeatPayload) => void): void;
54
9
  sendUIUpdate(payload: UIUpdatePayload): void;
55
- /**
56
- * Notifies the host application of an error.
57
- * @param payload - The error payload containing error details.
58
- */
59
10
  sendError(payload: ErrorPayload): void;
11
+ requestData<T = any, R = any>(type: string, payload?: T, timeout?: number): Promise<R>;
12
+ respondData(requestId: string, data: any, status?: 'success' | 'error'): void;
60
13
  }
61
14
  //# sourceMappingURL=moduleBridge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"moduleBridge.d.ts","sourceRoot":"","sources":["../src/moduleBridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,YAAY,EACb,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,YAAa,SAAQ,UAAU;IAC1C;;;OAGG;gBACS,YAAY,GAAE,MAAY;IAItC;;;;OAIG;IACH,aAAa,CAAC,OAAO,EAAE,qBAAqB;IAI5C;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,eAAe;IAIrC;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,YAAY;CAGhC"}
1
+ {"version":3,"file":"moduleBridge.d.ts","sourceRoot":"","sources":["../src/moduleBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,YAAY,EAGZ,gBAAgB,EAEjB,MAAM,kBAAkB,CAAA;AAEzB,qBAAa,YAAa,SAAQ,UAAU;IAC1C,OAAO,CAAC,cAAc,CAAmB;gBAE7B,YAAY,GAAE,MAAY;IAOtC,aAAa,CAAC,OAAO,EAAE,qBAAqB;IAO5C,aAAa,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI;IAc9C,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,IAAI;IAmB1D,YAAY,CAAC,OAAO,EAAE,eAAe;IAIrC,SAAS,CAAC,OAAO,EAAE,YAAY;IAO3B,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAChC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,CAAC,EACX,OAAO,SAAO,GACb,OAAO,CAAC,CAAC,CAAC;IAyBX,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,GAAE,SAAS,GAAG,OAAmB;CAQlF"}
@@ -1,70 +1,79 @@
1
- /**
2
- * @fileoverview Module-side bridge for communication with the host application.
3
- * @module @schoolpalm/message-bridge/moduleBridge
4
- */
5
- // src/moduleBridge.ts
6
1
  import { BridgeBase } from './bridgeBase';
7
2
  import { MessageType } from './messageTypes';
8
- /**
9
- * Module-side bridge for communication with the host application.
10
- *
11
- * This class extends BridgeBase to provide module-specific functionality for
12
- * communicating with the parent host application. It handles handshake,
13
- * UI updates, and error reporting from the embedded module.
14
- *
15
- * @example
16
- * ```typescript
17
- * const moduleBridge = new ModuleBridge('https://host.example.com');
18
- *
19
- * // Send handshake when module is ready
20
- * moduleBridge.sendHandshake({
21
- * version: '1.0.0',
22
- * timestamp: Date.now()
23
- * });
24
- *
25
- * // Update UI in the host
26
- * moduleBridge.sendUIUpdate({
27
- * title: 'Dashboard',
28
- * breadcrumb: ['Home', 'Dashboard'],
29
- * theme: 'dark'
30
- * });
31
- *
32
- * // Listen for module start from host
33
- * moduleBridge.on(MessageType.MODULE_START, (payload) => {
34
- * console.log('Module started:', payload.route);
35
- * });
36
- * ```
37
- */
38
3
  export class ModuleBridge extends BridgeBase {
39
- /**
40
- * Creates a new ModuleBridge instance.
41
- * @param targetOrigin - The origin to restrict messages to (default: '*').
42
- */
43
4
  constructor(targetOrigin = '*') {
44
5
  super(window.parent, targetOrigin);
6
+ this.startedPayload = null;
45
7
  }
46
- /**
47
- * Notifies the host application that the module is ready.
48
- * This should be called after the module has initialized.
49
- * @param payload - The handshake payload containing version and timestamp.
50
- */
8
+ // --------------------
9
+ // Handshake
10
+ // --------------------
51
11
  sendHandshake(payload) {
52
12
  this.send(MessageType.HANDSHAKE_READY, payload);
53
13
  }
54
- /**
55
- * Notifies the host application of UI updates.
56
- * This includes changes to title, breadcrumb, and theme.
57
- * @param payload - The UI update payload.
58
- */
14
+ // --------------------
15
+ // Start (sticky)
16
+ // --------------------
17
+ onModuleStart(callback) {
18
+ if (this.startedPayload) {
19
+ callback(this.startedPayload);
20
+ }
21
+ this.on(MessageType.MODULE_START, payload => {
22
+ this.startedPayload = payload;
23
+ callback(payload);
24
+ });
25
+ }
26
+ // --------------------
27
+ // Heartbeat
28
+ // --------------------
29
+ onHeartbeat(callback) {
30
+ this.on(MessageType.HEARTBEAT, (payload) => {
31
+ const hb = payload;
32
+ // Ignore ACK-only heartbeats
33
+ if (hb.ack)
34
+ return;
35
+ callback?.(hb);
36
+ this.send(MessageType.HEARTBEAT, {
37
+ timestamp: Date.now(),
38
+ ack: true
39
+ });
40
+ });
41
+ }
42
+ // --------------------
43
+ // UI / Errors
44
+ // --------------------
59
45
  sendUIUpdate(payload) {
60
46
  this.send(MessageType.UI_UPDATE, payload);
61
47
  }
62
- /**
63
- * Notifies the host application of an error.
64
- * @param payload - The error payload containing error details.
65
- */
66
48
  sendError(payload) {
67
49
  this.send(MessageType.ERROR, payload);
68
50
  }
51
+ // --------------------
52
+ // Requests
53
+ // --------------------
54
+ async requestData(type, payload, timeout = 5000) {
55
+ const request = {
56
+ requestId: crypto.randomUUID(),
57
+ type,
58
+ payload: payload
59
+ };
60
+ // Call base request (returns generic MessagePayload)
61
+ const response = (await this.request(MessageType.DATA_REQUEST, request, timeout)); // Cast safely here
62
+ if (response.status === 'error') {
63
+ throw new Error(response.error || 'Unknown error from host');
64
+ }
65
+ return response.payload;
66
+ }
67
+ // --------------------
68
+ // Respond to host requests
69
+ // --------------------
70
+ respondData(requestId, data, status = 'success') {
71
+ const response = {
72
+ requestId,
73
+ status,
74
+ payload: data
75
+ };
76
+ this.send(MessageType.DATA_RESPONSE, response);
77
+ }
69
78
  }
70
79
  //# sourceMappingURL=moduleBridge.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"moduleBridge.js","sourceRoot":"","sources":["../src/moduleBridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sBAAsB;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAC1C;;;OAGG;IACH,YAAY,eAAuB,GAAG;QACpC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACrC,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAC,OAA8B;QAC1C,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,OAAwB;QACnC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,OAAqB;QAC7B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;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/**
2
- * @fileoverview Payload schema definitions for message-based communication.
3
- * @module @schoolpalm/message-bridge/payloadSchemas
4
- */
5
- /**
6
- * Payload interfaces for each message type in the bridge communication protocol.
7
- *
8
- * These interfaces define the structure of data exchanged between host applications
9
- * and embedded modules. Each payload corresponds to a specific message type and
10
- * contains the necessary information for that communication scenario.
11
- */
12
- /**
13
- * Payload for handshake ready message.
14
- * Sent by modules to indicate they are ready for communication.
15
- */
16
1
  export interface HandshakeReadyPayload {
17
- /** Version of the module or SDK */
18
2
  version: string;
19
- /** Timestamp when the handshake was initiated */
20
3
  timestamp: number;
4
+ capabilities?: string[];
21
5
  }
22
- /**
23
- * Payload for module start message.
24
- * Sent by host to initialize a module with context.
25
- */
26
6
  export interface ModuleStartPayload {
27
- /** Route or path to navigate to in the module */
7
+ moduleId: string;
28
8
  route: string;
29
- /** Context data passed to the module (user info, permissions, etc.) */
30
9
  context: Record<string, any>;
31
- /** Timestamp when the module start was requested */
32
10
  timestamp: number;
33
11
  }
34
- /**
35
- * Payload for UI update message.
36
- * Sent by modules to update the host application's UI.
37
- */
12
+ export interface ModuleExitPayload {
13
+ reason?: string;
14
+ }
38
15
  export interface UIUpdatePayload {
39
- /** Title to display in the host UI */
40
16
  title: string;
41
- /** Breadcrumb navigation path */
42
17
  breadcrumb: string[];
43
- /** Optional theme to apply to the host UI */
44
18
  theme?: string;
45
19
  }
46
- /**
47
- * Payload for data request message.
48
- * Sent by modules to request data from the host.
49
- */
50
- export interface DataRequestPayload {
51
- /** Unique identifier for tracking the request */
20
+ export interface ErrorPayload {
21
+ code: string;
22
+ message: string;
23
+ details?: any;
24
+ }
25
+ export interface ModuleContextPayload {
26
+ user?: Record<string, any>;
27
+ tenant?: Record<string, any>;
28
+ permissions?: string[];
29
+ theme?: string;
30
+ }
31
+ export interface RequestPayload {
52
32
  requestId: string;
53
- /** Action or endpoint to request data from */
54
- action: string;
55
- /** Optional payload data for the request */
56
- payload?: Record<string, any>;
33
+ type: string;
34
+ payload?: any;
57
35
  }
58
- /**
59
- * Payload for data response message.
60
- * Sent by host in response to data requests.
61
- */
62
- export interface DataResponsePayload {
63
- /** Unique identifier matching the original request */
36
+ export interface ResponsePayload {
64
37
  requestId: string;
65
- /** Status of the response */
66
38
  status: 'success' | 'error';
67
- /** Response data (present on success) */
68
39
  payload?: any;
40
+ error?: string;
69
41
  }
70
42
  /**
71
- * Payload for error message.
72
- * Sent by modules to report errors to the host.
43
+ * Payload for heartbeat messages.
44
+ * Host Module
73
45
  */
74
- export interface ErrorPayload {
75
- /** Error code for categorization */
76
- code: string;
77
- /** Human-readable error message */
78
- message: string;
79
- /** Optional additional error details */
80
- details?: any;
46
+ export interface HeartbeatPayload {
47
+ timestamp: number;
48
+ ack?: boolean;
81
49
  }
82
- /**
83
- * Payload for module exit message.
84
- * Sent by host to signal module termination.
85
- */
86
- export interface ModuleExitPayload {
87
- /** Optional reason for the module exit */
88
- reason?: string;
50
+ export type MessagePayload = HandshakeReadyPayload | ModuleStartPayload | ModuleExitPayload | UIUpdatePayload | ErrorPayload | ModuleContextPayload | RequestPayload | ResponsePayload | HeartbeatPayload;
51
+ import { MessageType } from './messageTypes';
52
+ export interface MessagePayloadMap {
53
+ [MessageType.HANDSHAKE_READY]: HandshakeReadyPayload;
54
+ [MessageType.MODULE_START]: ModuleStartPayload;
55
+ [MessageType.MODULE_EXIT]: ModuleExitPayload;
56
+ [MessageType.UI_UPDATE]: UIUpdatePayload;
57
+ [MessageType.ERROR]: ErrorPayload;
58
+ [MessageType.CONTEXT_UPDATE]: ModuleContextPayload;
59
+ [MessageType.DATA_REQUEST]: RequestPayload;
60
+ [MessageType.DATA_RESPONSE]: ResponsePayload;
61
+ [MessageType.HEARTBEAT]: HeartbeatPayload;
89
62
  }
90
- /**
91
- * Union type representing all possible message payloads.
92
- *
93
- * This type is used internally for type safety when handling messages
94
- * of any type in the bridge classes.
95
- */
96
- export type MessagePayload = HandshakeReadyPayload | ModuleStartPayload | UIUpdatePayload | DataRequestPayload | DataResponsePayload | ErrorPayload | ModuleExitPayload;
97
63
  //# sourceMappingURL=payloadSchemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"payloadSchemas.d.ts","sourceRoot":"","sources":["../src/payloadSchemas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;;;;;GAMG;AAEH;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC;IAC5B,yCAAyC;IACzC,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,mCAAm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- * @fileoverview Payload schema definitions for message-based communication.
3
- * @module @schoolpalm/message-bridge/payloadSchemas
4
- */
5
- export {};
1
+ import { MessageType } from './messageTypes';
6
2
  //# sourceMappingURL=payloadSchemas.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"payloadSchemas.js","sourceRoot":"","sources":["../src/payloadSchemas.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
1
+ {"version":3,"file":"payloadSchemas.js","sourceRoot":"","sources":["../src/payloadSchemas.ts"],"names":[],"mappings":"AAuEA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,8 @@
1
+ export declare enum ProtocolState {
2
+ INIT = "init",
3
+ HANDSHAKEN = "handshaken",
4
+ STARTED = "started",
5
+ EXITED = "exited"
6
+ }
7
+ export declare const PROTOCOL_VERSION = "1.0.0";
8
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAEA,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,UAAU,eAAe;IACzB,OAAO,YAAY;IACnB,MAAM,WAAW;CAClB;AAED,eAAO,MAAM,gBAAgB,UAAU,CAAA"}
@@ -0,0 +1,10 @@
1
+ // src/protocol.ts
2
+ export var ProtocolState;
3
+ (function (ProtocolState) {
4
+ ProtocolState["INIT"] = "init";
5
+ ProtocolState["HANDSHAKEN"] = "handshaken";
6
+ ProtocolState["STARTED"] = "started";
7
+ ProtocolState["EXITED"] = "exited";
8
+ })(ProtocolState || (ProtocolState = {}));
9
+ export const PROTOCOL_VERSION = '1.0.0';
10
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAElB,MAAM,CAAN,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,0CAAyB,CAAA;IACzB,oCAAmB,CAAA;IACnB,kCAAiB,CAAA;AACnB,CAAC,EALW,aAAa,KAAb,aAAa,QAKxB;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schoolpalm/message-bridge",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "TypeScript SDK for message-based communication between SchoolPalm host and vendor modules.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",