@schoolpalm/message-bridge 0.1.0 → 1.2.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,79 +0,0 @@
1
- /**
2
- * @fileoverview Module-side bridge for communication with the host application.
3
- * @module @schoolpalm/message-bridge/moduleBridge
4
- */
5
-
6
- // src/moduleBridge.ts
7
- import { BridgeBase } from './bridgeBase';
8
- import { MessageType } from './messageTypes';
9
- import {
10
- HandshakeReadyPayload,
11
- UIUpdatePayload,
12
- ErrorPayload
13
- } from './payloadSchemas';
14
-
15
- /**
16
- * Module-side bridge for communication with the host application.
17
- *
18
- * This class extends BridgeBase to provide module-specific functionality for
19
- * communicating with the parent host application. It handles handshake,
20
- * UI updates, and error reporting from the embedded module.
21
- *
22
- * @example
23
- * ```typescript
24
- * const moduleBridge = new ModuleBridge('https://host.example.com');
25
- *
26
- * // Send handshake when module is ready
27
- * moduleBridge.sendHandshake({
28
- * version: '1.0.0',
29
- * timestamp: Date.now()
30
- * });
31
- *
32
- * // Update UI in the host
33
- * moduleBridge.sendUIUpdate({
34
- * title: 'Dashboard',
35
- * breadcrumb: ['Home', 'Dashboard'],
36
- * theme: 'dark'
37
- * });
38
- *
39
- * // Listen for module start from host
40
- * moduleBridge.on(MessageType.MODULE_START, (payload) => {
41
- * console.log('Module started:', payload.route);
42
- * });
43
- * ```
44
- */
45
- export class ModuleBridge extends BridgeBase {
46
- /**
47
- * Creates a new ModuleBridge instance.
48
- * @param targetOrigin - The origin to restrict messages to (default: '*').
49
- */
50
- constructor(targetOrigin: string = '*') {
51
- super(window.parent, targetOrigin);
52
- }
53
-
54
- /**
55
- * Notifies the host application that the module is ready.
56
- * This should be called after the module has initialized.
57
- * @param payload - The handshake payload containing version and timestamp.
58
- */
59
- sendHandshake(payload: HandshakeReadyPayload) {
60
- this.send(MessageType.HANDSHAKE_READY, payload);
61
- }
62
-
63
- /**
64
- * Notifies the host application of UI updates.
65
- * This includes changes to title, breadcrumb, and theme.
66
- * @param payload - The UI update payload.
67
- */
68
- sendUIUpdate(payload: UIUpdatePayload) {
69
- this.send(MessageType.UI_UPDATE, payload);
70
- }
71
-
72
- /**
73
- * Notifies the host application of an error.
74
- * @param payload - The error payload containing error details.
75
- */
76
- sendError(payload: ErrorPayload) {
77
- this.send(MessageType.ERROR, payload);
78
- }
79
- }
@@ -1,115 +0,0 @@
1
- /**
2
- * @fileoverview Payload schema definitions for message-based communication.
3
- * @module @schoolpalm/message-bridge/payloadSchemas
4
- */
5
-
6
- // src/payloadSchemas.ts
7
- import { MessageType } from './messageTypes';
8
-
9
- /**
10
- * Payload interfaces for each message type in the bridge communication protocol.
11
- *
12
- * These interfaces define the structure of data exchanged between host applications
13
- * and embedded modules. Each payload corresponds to a specific message type and
14
- * contains the necessary information for that communication scenario.
15
- */
16
-
17
- /**
18
- * Payload for handshake ready message.
19
- * Sent by modules to indicate they are ready for communication.
20
- */
21
- export interface HandshakeReadyPayload {
22
- /** Version of the module or SDK */
23
- version: string;
24
- /** Timestamp when the handshake was initiated */
25
- timestamp: number;
26
- }
27
-
28
- /**
29
- * Payload for module start message.
30
- * Sent by host to initialize a module with context.
31
- */
32
- export interface ModuleStartPayload {
33
- /** Route or path to navigate to in the module */
34
- route: string;
35
- /** Context data passed to the module (user info, permissions, etc.) */
36
- context: Record<string, any>;
37
- /** Timestamp when the module start was requested */
38
- timestamp: number;
39
- }
40
-
41
- /**
42
- * Payload for UI update message.
43
- * Sent by modules to update the host application's UI.
44
- */
45
- export interface UIUpdatePayload {
46
- /** Title to display in the host UI */
47
- title: string;
48
- /** Breadcrumb navigation path */
49
- breadcrumb: string[];
50
- /** Optional theme to apply to the host UI */
51
- theme?: string;
52
- }
53
-
54
- /**
55
- * Payload for data request message.
56
- * Sent by modules to request data from the host.
57
- */
58
- export interface DataRequestPayload {
59
- /** Unique identifier for tracking the request */
60
- requestId: string;
61
- /** Action or endpoint to request data from */
62
- action: string;
63
- /** Optional payload data for the request */
64
- payload?: Record<string, any>;
65
- }
66
-
67
- /**
68
- * Payload for data response message.
69
- * Sent by host in response to data requests.
70
- */
71
- export interface DataResponsePayload {
72
- /** Unique identifier matching the original request */
73
- requestId: string;
74
- /** Status of the response */
75
- status: 'success' | 'error';
76
- /** Response data (present on success) */
77
- payload?: any;
78
- }
79
-
80
- /**
81
- * Payload for error message.
82
- * Sent by modules to report errors to the host.
83
- */
84
- export interface ErrorPayload {
85
- /** Error code for categorization */
86
- code: string;
87
- /** Human-readable error message */
88
- message: string;
89
- /** Optional additional error details */
90
- details?: any;
91
- }
92
-
93
- /**
94
- * Payload for module exit message.
95
- * Sent by host to signal module termination.
96
- */
97
- export interface ModuleExitPayload {
98
- /** Optional reason for the module exit */
99
- reason?: string;
100
- }
101
-
102
- /**
103
- * Union type representing all possible message payloads.
104
- *
105
- * This type is used internally for type safety when handling messages
106
- * of any type in the bridge classes.
107
- */
108
- export type MessagePayload =
109
- | HandshakeReadyPayload
110
- | ModuleStartPayload
111
- | UIUpdatePayload
112
- | DataRequestPayload
113
- | DataResponsePayload
114
- | ErrorPayload
115
- | ModuleExitPayload;
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ESNext",
5
- "moduleResolution": "node",
6
- "outDir": "dist",
7
- "rootDir": "src",
8
- "declaration": true,
9
- "declarationMap": true,
10
- "sourceMap": true,
11
- "strict": true,
12
- "esModuleInterop": true,
13
- "skipLibCheck": true,
14
- "forceConsistentCasingInFileNames": true
15
- },
16
- "include": ["src/**/*"],
17
- "exclude": ["node_modules", "dist"]
18
- }
package/vitest.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- environment: 'jsdom',
6
- globals: true,
7
- },
8
- });