@eazo/sdk 0.4.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.
Files changed (87) hide show
  1. package/PROTOCOL.md +134 -0
  2. package/README.md +163 -0
  3. package/dist/index.d.ts +5 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +8 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/internal/auth-primitive/EazoAuthClient.d.ts +35 -0
  8. package/dist/internal/auth-primitive/EazoAuthClient.d.ts.map +1 -0
  9. package/dist/internal/auth-primitive/EazoAuthClient.js +107 -0
  10. package/dist/internal/auth-primitive/EazoAuthClient.js.map +1 -0
  11. package/dist/internal/auth-primitive/EazoAuthServer.d.ts +18 -0
  12. package/dist/internal/auth-primitive/EazoAuthServer.d.ts.map +1 -0
  13. package/dist/internal/auth-primitive/EazoAuthServer.js +37 -0
  14. package/dist/internal/auth-primitive/EazoAuthServer.js.map +1 -0
  15. package/dist/internal/auth-primitive/decrypt.d.ts +12 -0
  16. package/dist/internal/auth-primitive/decrypt.d.ts.map +1 -0
  17. package/dist/internal/auth-primitive/decrypt.js +89 -0
  18. package/dist/internal/auth-primitive/decrypt.js.map +1 -0
  19. package/dist/internal/auth-primitive/index.d.ts +5 -0
  20. package/dist/internal/auth-primitive/index.d.ts.map +1 -0
  21. package/dist/internal/auth-primitive/index.js +13 -0
  22. package/dist/internal/auth-primitive/index.js.map +1 -0
  23. package/dist/internal/auth-primitive/types.d.ts +61 -0
  24. package/dist/internal/auth-primitive/types.d.ts.map +1 -0
  25. package/dist/internal/auth-primitive/types.js +6 -0
  26. package/dist/internal/auth-primitive/types.js.map +1 -0
  27. package/dist/internal/bootstrap.d.ts +16 -0
  28. package/dist/internal/bootstrap.d.ts.map +1 -0
  29. package/dist/internal/bootstrap.js +81 -0
  30. package/dist/internal/bootstrap.js.map +1 -0
  31. package/dist/internal/bridge/client.d.ts +40 -0
  32. package/dist/internal/bridge/client.d.ts.map +1 -0
  33. package/dist/internal/bridge/client.js +160 -0
  34. package/dist/internal/bridge/client.js.map +1 -0
  35. package/dist/internal/bridge/protocol.d.ts +61 -0
  36. package/dist/internal/bridge/protocol.d.ts.map +1 -0
  37. package/dist/internal/bridge/protocol.js +38 -0
  38. package/dist/internal/bridge/protocol.js.map +1 -0
  39. package/dist/internal/bridge/transport.d.ts +19 -0
  40. package/dist/internal/bridge/transport.d.ts.map +1 -0
  41. package/dist/internal/bridge/transport.js +66 -0
  42. package/dist/internal/bridge/transport.js.map +1 -0
  43. package/dist/internal/capabilities/auth.d.ts +55 -0
  44. package/dist/internal/capabilities/auth.d.ts.map +1 -0
  45. package/dist/internal/capabilities/auth.js +361 -0
  46. package/dist/internal/capabilities/auth.js.map +1 -0
  47. package/dist/internal/capabilities/device.d.ts +11 -0
  48. package/dist/internal/capabilities/device.d.ts.map +1 -0
  49. package/dist/internal/capabilities/device.js +65 -0
  50. package/dist/internal/capabilities/device.js.map +1 -0
  51. package/dist/internal/env.d.ts +14 -0
  52. package/dist/internal/env.d.ts.map +1 -0
  53. package/dist/internal/env.js +28 -0
  54. package/dist/internal/env.js.map +1 -0
  55. package/dist/internal/login-ui/icons.d.ts +18 -0
  56. package/dist/internal/login-ui/icons.d.ts.map +1 -0
  57. package/dist/internal/login-ui/icons.js +62 -0
  58. package/dist/internal/login-ui/icons.js.map +1 -0
  59. package/dist/internal/login-ui/index.d.ts +3 -0
  60. package/dist/internal/login-ui/index.d.ts.map +1 -0
  61. package/dist/internal/login-ui/index.js +160 -0
  62. package/dist/internal/login-ui/index.js.map +1 -0
  63. package/dist/internal/login-ui/styles.d.ts +3 -0
  64. package/dist/internal/login-ui/styles.d.ts.map +1 -0
  65. package/dist/internal/login-ui/styles.js +282 -0
  66. package/dist/internal/login-ui/styles.js.map +1 -0
  67. package/dist/internal/store.d.ts +29 -0
  68. package/dist/internal/store.d.ts.map +1 -0
  69. package/dist/internal/store.js +82 -0
  70. package/dist/internal/store.js.map +1 -0
  71. package/dist/react.d.ts +24 -0
  72. package/dist/react.d.ts.map +1 -0
  73. package/dist/react.js +81 -0
  74. package/dist/react.js.map +1 -0
  75. package/dist/server.d.ts +21 -0
  76. package/dist/server.d.ts.map +1 -0
  77. package/dist/server.js +53 -0
  78. package/dist/server.js.map +1 -0
  79. package/dist/testing.d.ts +13 -0
  80. package/dist/testing.d.ts.map +1 -0
  81. package/dist/testing.js +38 -0
  82. package/dist/testing.js.map +1 -0
  83. package/dist/types.d.ts +33 -0
  84. package/dist/types.d.ts.map +1 -0
  85. package/dist/types.js +7 -0
  86. package/dist/types.js.map +1 -0
  87. package/package.json +71 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/internal/auth-primitive/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACrD,YAAY,EACV,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,QAAQ,GACT,MAAM,SAAS,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decryptUserInfo = exports.decrypt = exports.EazoAuthServer = exports.EazoAuthClient = void 0;
4
+ // Barrel for the auth primitive layer. Internal only — consumed by SDK
5
+ // capabilities and server-side helpers; not re-exported from any public entry.
6
+ var EazoAuthClient_1 = require("./EazoAuthClient");
7
+ Object.defineProperty(exports, "EazoAuthClient", { enumerable: true, get: function () { return EazoAuthClient_1.EazoAuthClient; } });
8
+ var EazoAuthServer_1 = require("./EazoAuthServer");
9
+ Object.defineProperty(exports, "EazoAuthServer", { enumerable: true, get: function () { return EazoAuthServer_1.EazoAuthServer; } });
10
+ var decrypt_1 = require("./decrypt");
11
+ Object.defineProperty(exports, "decrypt", { enumerable: true, get: function () { return decrypt_1.decrypt; } });
12
+ Object.defineProperty(exports, "decryptUserInfo", { enumerable: true, get: function () { return decrypt_1.decryptUserInfo; } });
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/internal/auth-primitive/index.ts"],"names":[],"mappings":";;;AAAA,uEAAuE;AACvE,+EAA+E;AAC/E,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,qCAAqD;AAA5C,kGAAA,OAAO,OAAA;AAAE,0GAAA,eAAe,OAAA"}
@@ -0,0 +1,61 @@
1
+ export interface UserInfo {
2
+ userId: string;
3
+ email?: string;
4
+ nickname?: string;
5
+ avatarUrl?: string;
6
+ lang?: string;
7
+ region?: string;
8
+ createdAt?: string;
9
+ [key: string]: unknown;
10
+ }
11
+ export interface DecryptOptions {
12
+ /** Base64-encoded encrypted data */
13
+ encryptedData: string;
14
+ /** Base64-encoded encrypted AES key (ephemeral pubkey + IV + ciphertext) */
15
+ encryptedKey: string;
16
+ /** Base64-encoded AES-GCM IV */
17
+ iv: string;
18
+ /** Base64-encoded AES-GCM auth tag */
19
+ authTag: string;
20
+ /** Developer private key — 64 hex characters (secp256k1) */
21
+ privateKey: string;
22
+ }
23
+ export interface DecryptResult<T = unknown> {
24
+ data: T;
25
+ raw: string;
26
+ }
27
+ export interface SocialConnection {
28
+ id: string;
29
+ provider: string;
30
+ identifier: string;
31
+ name: string;
32
+ name_en: string;
33
+ tooltip: {
34
+ "zh-CN": string;
35
+ "en-US": string;
36
+ };
37
+ tagsStatus: boolean;
38
+ }
39
+ export interface EazoAuthClientConfig {
40
+ /** Developer ECC public key — used to exchange a GenAuth JWT for an encrypted session token. */
41
+ publicKey: string;
42
+ /** GenAuth Application ID. Defaults to the Eazo platform app. */
43
+ authAppId?: string;
44
+ /** GenAuth tenant domain. Defaults to https://eazo.genauth.ai */
45
+ authAppDomain?: string;
46
+ /** Eazo API base URL. Defaults to https://eazo.ai */
47
+ apiBase?: string;
48
+ }
49
+ export interface EazoAuthServerConfig {
50
+ /** EAZO_PRIVATE_KEY — required for session decryption */
51
+ privateKey: string;
52
+ }
53
+ /** Encrypted session token returned by the server — same shape as Eazo Mobile session. */
54
+ export type SessionToken = {
55
+ encryptedData: string;
56
+ encryptedKey: string;
57
+ iv: string;
58
+ authTag: string;
59
+ [key: string]: string;
60
+ };
61
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/internal/auth-primitive/types.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,oCAAoC;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,YAAY,EAAE,MAAM,CAAC;IACrB,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO;IACxC,IAAI,EAAE,CAAC,CAAC;IACR,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9C,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,gGAAgG;IAChG,SAAS,EAAE,MAAM,CAAC;IAClB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,0FAA0F;AAC1F,MAAM,MAAM,YAAY,GAAG;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ // ---------------------------------------------------------------------------
3
+ // Shared types for the auth primitive layer (internal; do not import from app code)
4
+ // ---------------------------------------------------------------------------
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/internal/auth-primitive/types.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,oFAAoF;AACpF,8EAA8E"}
@@ -0,0 +1,16 @@
1
+ import { BridgeClient } from "./bridge/client";
2
+ import { type HelloEnvelope } from "./bridge/protocol";
3
+ /**
4
+ * Returns the bridge client, starting it on first call. Returns null in non-browser contexts.
5
+ */
6
+ export declare function getBridge(): BridgeClient | null;
7
+ /**
8
+ * Resolves to the HelloEnvelope when the host responds within HELLO_TIMEOUT_MS,
9
+ * or null if we're in a pure-web environment (no host, or host didn't respond).
10
+ */
11
+ export declare function waitForBootstrap(): Promise<HelloEnvelope | null>;
12
+ /**
13
+ * Test-only: reset the singleton bridge + cached bootstrap state.
14
+ */
15
+ export declare function __resetBootstrap(): void;
16
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/internal/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAoB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAmBzE;;GAEG;AACH,wBAAgB,SAAS,IAAI,YAAY,GAAG,IAAI,CAE/C;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAkChE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAKvC"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBridge = getBridge;
4
+ exports.waitForBootstrap = waitForBootstrap;
5
+ exports.__resetBootstrap = __resetBootstrap;
6
+ const client_1 = require("./bridge/client");
7
+ const protocol_1 = require("./bridge/protocol");
8
+ const transport_1 = require("./bridge/transport");
9
+ const env_1 = require("./env");
10
+ let bridge = null;
11
+ let helloResolved = null;
12
+ let helloPromise = null;
13
+ function ensureBridge() {
14
+ if (!(0, env_1.isBrowser)())
15
+ return null;
16
+ if (bridge)
17
+ return bridge;
18
+ bridge = new client_1.BridgeClient(new transport_1.Transport());
19
+ bridge.start();
20
+ bridge.onHello((hello) => {
21
+ helloResolved = hello;
22
+ });
23
+ return bridge;
24
+ }
25
+ /**
26
+ * Returns the bridge client, starting it on first call. Returns null in non-browser contexts.
27
+ */
28
+ function getBridge() {
29
+ return ensureBridge();
30
+ }
31
+ /**
32
+ * Resolves to the HelloEnvelope when the host responds within HELLO_TIMEOUT_MS,
33
+ * or null if we're in a pure-web environment (no host, or host didn't respond).
34
+ */
35
+ function waitForBootstrap() {
36
+ if (helloPromise)
37
+ return helloPromise;
38
+ const b = ensureBridge();
39
+ if (!b) {
40
+ helloPromise = Promise.resolve(null);
41
+ return helloPromise;
42
+ }
43
+ helloPromise = new Promise((resolve) => {
44
+ if (helloResolved) {
45
+ resolve(helloResolved);
46
+ return;
47
+ }
48
+ const status = b.getStatus();
49
+ if (status.ready) {
50
+ // ready but hello payload wasn't retained — treat as no bootstrap data
51
+ resolve(null);
52
+ return;
53
+ }
54
+ let settled = false;
55
+ const unsub = b.onHello((hello) => {
56
+ if (settled)
57
+ return;
58
+ settled = true;
59
+ unsub();
60
+ resolve(hello);
61
+ });
62
+ setTimeout(() => {
63
+ if (settled)
64
+ return;
65
+ settled = true;
66
+ unsub();
67
+ resolve(null);
68
+ }, protocol_1.HELLO_TIMEOUT_MS + 50);
69
+ });
70
+ return helloPromise;
71
+ }
72
+ /**
73
+ * Test-only: reset the singleton bridge + cached bootstrap state.
74
+ */
75
+ function __resetBootstrap() {
76
+ bridge?.stop();
77
+ bridge = null;
78
+ helloResolved = null;
79
+ helloPromise = null;
80
+ }
81
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/internal/bootstrap.ts"],"names":[],"mappings":";;AAuBA,8BAEC;AAMD,4CAkCC;AAKD,4CAKC;AA3ED,4CAA+C;AAC/C,gDAAyE;AACzE,kDAA+C;AAC/C,+BAAkC;AAElC,IAAI,MAAM,GAAwB,IAAI,CAAC;AACvC,IAAI,aAAa,GAAyB,IAAI,CAAC;AAC/C,IAAI,YAAY,GAAyC,IAAI,CAAC;AAE9D,SAAS,YAAY;IACnB,IAAI,CAAC,IAAA,eAAS,GAAE;QAAE,OAAO,IAAI,CAAC;IAC9B,IAAI,MAAM;QAAE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AAG,IAAI,CAAC;YACf,KAAK,EAAE,CAAC;YACR,OAAO,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC,EAAE,2BAAgB,GAAG,EAAE,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IACH,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,MAAM,EAAE,IAAI,EAAE,CAAC;IACf,MAAM,GAAG,IAAI,CAAC;IACd,aAAa,GAAG,IAAI,CAAC;IACrB,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { type HelloEnvelope } from "./protocol";
2
+ import { Transport } from "./transport";
3
+ export type HelloListener = (hello: HelloEnvelope) => void;
4
+ export type EventListener = (data: unknown) => void;
5
+ export interface BridgeStatus {
6
+ ready: boolean;
7
+ capabilities: string[];
8
+ }
9
+ /**
10
+ * Bridge client — manages handshake, RPC, and events.
11
+ *
12
+ * Lifecycle:
13
+ * - start() attaches transport, sends `ready`, and waits HELLO_TIMEOUT_MS for `hello`.
14
+ * - On `hello`, status becomes ready and `onHello` listeners fire.
15
+ * - On timeout, status remains not-ready; subsequent `request()` calls throw NOT_SUPPORTED.
16
+ * - stop() detaches transport and rejects all pending requests.
17
+ */
18
+ export declare class BridgeClient {
19
+ private readonly transport;
20
+ private readonly pending;
21
+ private readonly eventListeners;
22
+ private readonly helloListeners;
23
+ private started;
24
+ private helloReceived;
25
+ private helloTimer;
26
+ private capabilities;
27
+ private unsubscribeTransport;
28
+ constructor(transport?: Transport);
29
+ start(): void;
30
+ stop(): void;
31
+ getStatus(): BridgeStatus;
32
+ onHello(listener: HelloListener): () => void;
33
+ on(eventName: string, listener: EventListener): () => void;
34
+ request<T = unknown>(fn: string, args?: unknown): Promise<T>;
35
+ private isSupported;
36
+ private dispatch;
37
+ private handleHello;
38
+ private handleResponse;
39
+ }
40
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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CAAC,cAAc;CAWvB"}
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BridgeClient = void 0;
4
+ const protocol_1 = require("./protocol");
5
+ const transport_1 = require("./transport");
6
+ let requestCounter = 0;
7
+ function newRequestId() {
8
+ requestCounter += 1;
9
+ return `eazo-${Date.now()}-${requestCounter}`;
10
+ }
11
+ /**
12
+ * Bridge client — manages handshake, RPC, and events.
13
+ *
14
+ * Lifecycle:
15
+ * - start() attaches transport, sends `ready`, and waits HELLO_TIMEOUT_MS for `hello`.
16
+ * - On `hello`, status becomes ready and `onHello` listeners fire.
17
+ * - On timeout, status remains not-ready; subsequent `request()` calls throw NOT_SUPPORTED.
18
+ * - stop() detaches transport and rejects all pending requests.
19
+ */
20
+ class BridgeClient {
21
+ constructor(transport = new transport_1.Transport()) {
22
+ this.pending = new Map();
23
+ this.eventListeners = new Map();
24
+ this.helloListeners = new Set();
25
+ this.started = false;
26
+ this.helloReceived = false;
27
+ this.helloTimer = null;
28
+ this.capabilities = [];
29
+ this.unsubscribeTransport = null;
30
+ this.transport = transport;
31
+ }
32
+ start() {
33
+ if (this.started || typeof window === "undefined")
34
+ return;
35
+ this.started = true;
36
+ this.transport.attach();
37
+ this.unsubscribeTransport = this.transport.onMessage((msg) => this.dispatch(msg));
38
+ this.transport.send({ ch: protocol_1.CHANNEL, v: protocol_1.VERSION, t: "ready" });
39
+ this.helloTimer = setTimeout(() => {
40
+ this.helloTimer = null;
41
+ if (!this.helloReceived) {
42
+ // No host responded — we're in a pure web context.
43
+ this.helloReceived = false;
44
+ }
45
+ }, protocol_1.HELLO_TIMEOUT_MS);
46
+ }
47
+ stop() {
48
+ if (!this.started)
49
+ return;
50
+ this.started = false;
51
+ if (this.helloTimer) {
52
+ clearTimeout(this.helloTimer);
53
+ this.helloTimer = null;
54
+ }
55
+ for (const [, pending] of this.pending) {
56
+ clearTimeout(pending.timer);
57
+ pending.reject(new protocol_1.BridgeErrorObject("INTERNAL", "Bridge stopped"));
58
+ }
59
+ this.pending.clear();
60
+ this.eventListeners.clear();
61
+ this.helloListeners.clear();
62
+ this.unsubscribeTransport?.();
63
+ this.unsubscribeTransport = null;
64
+ this.transport.detach();
65
+ this.helloReceived = false;
66
+ this.capabilities = [];
67
+ }
68
+ getStatus() {
69
+ return { ready: this.helloReceived, capabilities: this.capabilities.slice() };
70
+ }
71
+ onHello(listener) {
72
+ this.helloListeners.add(listener);
73
+ return () => this.helloListeners.delete(listener);
74
+ }
75
+ on(eventName, listener) {
76
+ let set = this.eventListeners.get(eventName);
77
+ if (!set) {
78
+ set = new Set();
79
+ this.eventListeners.set(eventName, set);
80
+ }
81
+ set.add(listener);
82
+ return () => {
83
+ const s = this.eventListeners.get(eventName);
84
+ s?.delete(listener);
85
+ if (s && s.size === 0)
86
+ this.eventListeners.delete(eventName);
87
+ };
88
+ }
89
+ request(fn, args) {
90
+ if (!this.helloReceived) {
91
+ return Promise.reject(new protocol_1.BridgeErrorObject("NOT_SUPPORTED", `Host not available (fn=${fn})`));
92
+ }
93
+ if (!this.isSupported(fn)) {
94
+ return Promise.reject(new protocol_1.BridgeErrorObject("NOT_SUPPORTED", `Host does not advertise ${fn}`));
95
+ }
96
+ const id = newRequestId();
97
+ const env = { ch: protocol_1.CHANNEL, v: protocol_1.VERSION, t: "req", id, fn, args };
98
+ return new Promise((resolve, reject) => {
99
+ const timer = setTimeout(() => {
100
+ if (this.pending.delete(id)) {
101
+ reject(new protocol_1.BridgeErrorObject("TIMEOUT", `Bridge request ${fn} timed out`));
102
+ }
103
+ }, protocol_1.REQUEST_TIMEOUT_MS);
104
+ this.pending.set(id, {
105
+ resolve: (data) => resolve(data),
106
+ reject,
107
+ timer,
108
+ });
109
+ this.transport.send(env);
110
+ });
111
+ }
112
+ isSupported(fn) {
113
+ if (this.capabilities.includes(fn))
114
+ return true;
115
+ const [namespace] = fn.split(".");
116
+ return this.capabilities.includes(`${namespace}.*`);
117
+ }
118
+ dispatch(msg) {
119
+ if (msg.t === "hello") {
120
+ this.handleHello(msg);
121
+ return;
122
+ }
123
+ if (msg.t === "res") {
124
+ this.handleResponse(msg);
125
+ return;
126
+ }
127
+ if (msg.t === "evt") {
128
+ const listeners = this.eventListeners.get(msg.name);
129
+ if (listeners)
130
+ for (const l of listeners)
131
+ l(msg.data);
132
+ return;
133
+ }
134
+ }
135
+ handleHello(msg) {
136
+ if (this.helloTimer) {
137
+ clearTimeout(this.helloTimer);
138
+ this.helloTimer = null;
139
+ }
140
+ this.helloReceived = true;
141
+ this.capabilities = msg.capabilities.slice();
142
+ for (const l of this.helloListeners)
143
+ l(msg);
144
+ }
145
+ handleResponse(msg) {
146
+ const pending = this.pending.get(msg.id);
147
+ if (!pending)
148
+ return;
149
+ this.pending.delete(msg.id);
150
+ clearTimeout(pending.timer);
151
+ if (msg.ok) {
152
+ pending.resolve(msg.data);
153
+ }
154
+ else {
155
+ pending.reject(new protocol_1.BridgeErrorObject(msg.err.code, msg.err.message));
156
+ }
157
+ }
158
+ }
159
+ exports.BridgeClient = BridgeClient;
160
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/internal/bridge/client.ts"],"names":[],"mappings":";;;AAAA,yCAUoB;AACpB,2CAAwC;AAWxC,IAAI,cAAc,GAAG,CAAC,CAAC;AACvB,SAAS,YAAY;IACnB,cAAc,IAAI,CAAC,CAAC;IACpB,OAAO,QAAQ,IAAI,CAAC,GAAG,EAAE,IAAI,cAAc,EAAE,CAAC;AAChD,CAAC;AAOD;;;;;;;;GAQG;AACH,MAAa,YAAY;IAYvB,YAAY,YAAuB,IAAI,qBAAS,EAAE;QAVjC,YAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;QACrC,mBAAc,GAAG,IAAI,GAAG,EAA8B,CAAC;QACvD,mBAAc,GAAG,IAAI,GAAG,EAAiB,CAAC;QAEnD,YAAO,GAAG,KAAK,CAAC;QAChB,kBAAa,G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1B,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAC7C,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,cAAc;YAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;IAEO,cAAc,CAAC,GAAqB;QAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC5B,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC;YACX,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,MAAM,CAAC,IAAI,4BAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;CACF;AAtJD,oCAsJC"}
@@ -0,0 +1,61 @@
1
+ import type { DeviceContext, User } from "../../types";
2
+ export declare const CHANNEL: "eazo-sdk";
3
+ export declare const VERSION: 1;
4
+ export declare const HELLO_TIMEOUT_MS = 1500;
5
+ export declare const REQUEST_TIMEOUT_MS = 10000;
6
+ export declare const AUTH_REQUEST_LOGIN = "auth.requestLogin";
7
+ export declare const AUTH_CHANGED_EVENT = "auth.changed";
8
+ export declare const AUTH_LOGIN_CANCELLED_EVENT = "auth.loginCancelled";
9
+ export type ErrorCode = "NOT_SUPPORTED" | "TIMEOUT" | "DENIED" | "INVALID_ARGS" | "INTERNAL";
10
+ export interface BridgeError {
11
+ code: ErrorCode;
12
+ message: string;
13
+ }
14
+ interface EnvelopeBase<T extends string> {
15
+ ch: typeof CHANNEL;
16
+ v: typeof VERSION;
17
+ t: T;
18
+ }
19
+ export interface ReadyEnvelope extends EnvelopeBase<"ready"> {
20
+ }
21
+ export interface HelloEnvelope extends EnvelopeBase<"hello"> {
22
+ session: {
23
+ authenticated: boolean;
24
+ user: User | null;
25
+ token: string | null;
26
+ };
27
+ device: DeviceContext;
28
+ capabilities: string[];
29
+ }
30
+ export interface RequestEnvelope extends EnvelopeBase<"req"> {
31
+ id: string;
32
+ fn: string;
33
+ args?: unknown;
34
+ }
35
+ export type ResponseEnvelope = (EnvelopeBase<"res"> & {
36
+ id: string;
37
+ ok: true;
38
+ data?: unknown;
39
+ }) | (EnvelopeBase<"res"> & {
40
+ id: string;
41
+ ok: false;
42
+ err: BridgeError;
43
+ });
44
+ export interface EventEnvelope extends EnvelopeBase<"evt"> {
45
+ name: string;
46
+ data?: unknown;
47
+ }
48
+ export type HostToAppEnvelope = HelloEnvelope | ResponseEnvelope | EventEnvelope;
49
+ export type AppToHostEnvelope = ReadyEnvelope | RequestEnvelope;
50
+ export declare function isEazoEnvelope(msg: unknown): msg is HostToAppEnvelope;
51
+ export declare function isCapabilitySupported(capabilities: string[], fn: string): boolean;
52
+ /**
53
+ * BridgeError thrown across capability call sites. The `code` field drives
54
+ * whether the caller falls back to web-native behavior or surfaces the error.
55
+ */
56
+ export declare class BridgeErrorObject extends Error implements BridgeError {
57
+ code: ErrorCode;
58
+ constructor(code: ErrorCode, message: string);
59
+ }
60
+ export {};
61
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/internal/bridge/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEvD,eAAO,MAAM,OAAO,EAAG,UAAmB,CAAC;AAC3C,eAAO,MAAM,OAAO,EAAG,CAAU,CAAC;AAElC,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,eAAO,M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AAK,CAAC;IAAC,GAAG,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC;AAExE,MAAM,WAAW,aAAc,SAAQ,YAAY,CAAC,KAAK,CAAC;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG,gBAAgB,GAAG,aAAa,CAAC;AACjF,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG,eAAe,CAAC;AAEhE,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,iBAAiB,CAIrE;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAIjF;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAM,YAAW,WAAW;IACjE,IAAI,EAAE,SAAS,CAAC;gBACJ,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM;CAK7C"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BridgeErrorObject = exports.AUTH_LOGIN_CANCELLED_EVENT = exports.AUTH_CHANGED_EVENT = exports.AUTH_REQUEST_LOGIN = exports.REQUEST_TIMEOUT_MS = exports.HELLO_TIMEOUT_MS = exports.VERSION = exports.CHANNEL = void 0;
4
+ exports.isEazoEnvelope = isEazoEnvelope;
5
+ exports.isCapabilitySupported = isCapabilitySupported;
6
+ exports.CHANNEL = "eazo-sdk";
7
+ exports.VERSION = 1;
8
+ exports.HELLO_TIMEOUT_MS = 1500;
9
+ exports.REQUEST_TIMEOUT_MS = 10000;
10
+ // Host-mediated method and event names used by capabilities.
11
+ exports.AUTH_REQUEST_LOGIN = "auth.requestLogin";
12
+ exports.AUTH_CHANGED_EVENT = "auth.changed";
13
+ exports.AUTH_LOGIN_CANCELLED_EVENT = "auth.loginCancelled";
14
+ function isEazoEnvelope(msg) {
15
+ if (!msg || typeof msg !== "object")
16
+ return false;
17
+ const m = msg;
18
+ return m["ch"] === exports.CHANNEL && m["v"] === exports.VERSION && typeof m["t"] === "string";
19
+ }
20
+ function isCapabilitySupported(capabilities, fn) {
21
+ if (capabilities.includes(fn))
22
+ return true;
23
+ const [namespace] = fn.split(".");
24
+ return capabilities.includes(`${namespace}.*`);
25
+ }
26
+ /**
27
+ * BridgeError thrown across capability call sites. The `code` field drives
28
+ * whether the caller falls back to web-native behavior or surfaces the error.
29
+ */
30
+ class BridgeErrorObject extends Error {
31
+ constructor(code, message) {
32
+ super(message);
33
+ this.name = "BridgeError";
34
+ this.code = code;
35
+ }
36
+ }
37
+ exports.BridgeErrorObject = BridgeErrorObject;
38
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/internal/bridge/protocol.ts"],"names":[],"mappings":";;;AA6DA,wCAIC;AAED,sDAIC;AArEY,QAAA,OAAO,GAAG,UAAmB,CAAC;AAC9B,QAAA,OAAO,GAAG,CAAU,CAAC;AAErB,QAAA,gBAAgB,GAAG,IAAI,CAAC;AACxB,QAAA,kBAAkB,GAAG,KAAM,CAAC;AAEzC,6DAA6D;AAChD,QAAA,kBAAkB,GAAG,mBAAmB,CAAC;AACzC,QAAA,kBAAkB,GAAG,cAAc,CAAC;AACpC,QAAA,0BAA0B,GAAG,qBAAqB,CAAC;AAkDhE,SAAgB,cAAc,CAAC,GAAY;IACzC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAClD,MAAM,CAAC,GAAG,GAA8B,CAAC;IACzC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,eAAO,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,eAAO,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,QAAQ,CAAC;AACjF,CAAC;AAED,SAAgB,qBAAqB,CAAC,YAAsB,EAAE,EAAU;IACtE,IAAI,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,YAAY,CAAC,QAAQ,CAAC,GAAG,SAAS,IAAI,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAE1C,YAAY,IAAe,EAAE,OAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAPD,8CAOC"}
@@ -0,0 +1,19 @@
1
+ import type { AppToHostEnvelope, HostToAppEnvelope } from "./protocol";
2
+ type RawHandler = (msg: HostToAppEnvelope) => void;
3
+ /**
4
+ * Thin wrapper around postMessage. Supports both RN WebView and iframe embeds.
5
+ * Only emits envelopes that pass `isEazoEnvelope`.
6
+ */
7
+ export declare class Transport {
8
+ private readonly handlers;
9
+ private readonly messageListener;
10
+ private attached;
11
+ attach(): void;
12
+ detach(): void;
13
+ send(msg: AppToHostEnvelope): void;
14
+ onMessage(handler: RawHandler): () => void;
15
+ private handleRaw;
16
+ private parse;
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/internal/bridge/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGvE,KAAK,UAAU,GAAG,CAAC,GAAG,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAMnD;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAClD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA+C;IAC/E,OAAO,CAAC,QAAQ,CAAS;IAEzB,MAAM,IAAI,IAAI;IAMd,MAAM,IAAI,IAAI;IAOd,IAAI,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI;IAalC,SAAS,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,IAAI;IAK1C,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,KAAK;CAWd"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Transport = void 0;
4
+ const protocol_1 = require("./protocol");
5
+ /**
6
+ * Thin wrapper around postMessage. Supports both RN WebView and iframe embeds.
7
+ * Only emits envelopes that pass `isEazoEnvelope`.
8
+ */
9
+ class Transport {
10
+ constructor() {
11
+ this.handlers = new Set();
12
+ this.messageListener = (e) => this.handleRaw(e.data);
13
+ this.attached = false;
14
+ }
15
+ attach() {
16
+ if (this.attached || typeof window === "undefined")
17
+ return;
18
+ window.addEventListener("message", this.messageListener);
19
+ this.attached = true;
20
+ }
21
+ detach() {
22
+ if (!this.attached || typeof window === "undefined")
23
+ return;
24
+ window.removeEventListener("message", this.messageListener);
25
+ this.attached = false;
26
+ this.handlers.clear();
27
+ }
28
+ send(msg) {
29
+ if (typeof window === "undefined")
30
+ return;
31
+ const payload = JSON.stringify(msg);
32
+ const rn = window.ReactNativeWebView;
33
+ if (rn) {
34
+ rn.postMessage(payload);
35
+ return;
36
+ }
37
+ if (window.parent && window.parent !== window) {
38
+ window.parent.postMessage(payload, "*");
39
+ }
40
+ }
41
+ onMessage(handler) {
42
+ this.handlers.add(handler);
43
+ return () => this.handlers.delete(handler);
44
+ }
45
+ handleRaw(raw) {
46
+ const parsed = this.parse(raw);
47
+ if (!parsed)
48
+ return;
49
+ for (const h of this.handlers)
50
+ h(parsed);
51
+ }
52
+ parse(raw) {
53
+ let value = raw;
54
+ if (typeof raw === "string") {
55
+ try {
56
+ value = JSON.parse(raw);
57
+ }
58
+ catch {
59
+ return null;
60
+ }
61
+ }
62
+ return (0, protocol_1.isEazoEnvelope)(value) ? value : null;
63
+ }
64
+ }
65
+ exports.Transport = Transport;
66
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/internal/bridge/transport.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAQ5C;;;GAGG;AACH,MAAa,SAAS;IAAtB;QACmB,aAAQ,GAAG,IAAI,GAAG,EAAc,CAAC;QACjC,oBAAe,GAAG,CAAC,CAAe,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACvE,aAAQ,GAAG,KAAK,CAAC;IAkD3B,CAAC;IAhDC,MAAM;QACJ,IAAI,IAAI,CAAC,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC3D,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QACzD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC5D,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC5D,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,CAAC,GAAsB;QACzB,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,EAAE,GAAI,MAAqC,CAAC,kBAAkB,CAAC;QACrE,IAAI,EAAE,EAAE,CAAC;YACP,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACxB,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