@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,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.store = exports.INITIAL_STATE = void 0;
4
+ exports.setAuth = setAuth;
5
+ exports.setDevice = setDevice;
6
+ exports.setLoginUI = setLoginUI;
7
+ const INITIAL_AUTH = {
8
+ user: null,
9
+ loading: true,
10
+ authenticated: false,
11
+ };
12
+ const INITIAL_DEVICE = {
13
+ platform: "web",
14
+ locale: "en-US",
15
+ safeArea: { top: 0, bottom: 0 },
16
+ backendUrl: "",
17
+ };
18
+ const INITIAL_LOGIN_UI = {
19
+ open: false,
20
+ step: "providers",
21
+ emailMode: "code",
22
+ providers: [],
23
+ providersLoading: false,
24
+ error: null,
25
+ submitting: false,
26
+ };
27
+ exports.INITIAL_STATE = {
28
+ auth: INITIAL_AUTH,
29
+ device: INITIAL_DEVICE,
30
+ loginUI: INITIAL_LOGIN_UI,
31
+ };
32
+ let snapshot = exports.INITIAL_STATE;
33
+ const listeners = new Set();
34
+ exports.store = {
35
+ getSnapshot() {
36
+ return snapshot;
37
+ },
38
+ getServerSnapshot() {
39
+ return exports.INITIAL_STATE;
40
+ },
41
+ subscribe(listener) {
42
+ listeners.add(listener);
43
+ return () => listeners.delete(listener);
44
+ },
45
+ reset() {
46
+ snapshot = exports.INITIAL_STATE;
47
+ for (const l of listeners)
48
+ l();
49
+ },
50
+ };
51
+ function publish(next) {
52
+ snapshot = next;
53
+ for (const l of listeners)
54
+ l();
55
+ }
56
+ function setAuth(patch) {
57
+ const current = snapshot.auth;
58
+ const nextAuth = { ...current, ...patch };
59
+ if (nextAuth.user === current.user &&
60
+ nextAuth.loading === current.loading &&
61
+ nextAuth.authenticated === current.authenticated) {
62
+ return;
63
+ }
64
+ publish({ ...snapshot, auth: nextAuth });
65
+ }
66
+ function setDevice(patch) {
67
+ const current = snapshot.device;
68
+ const nextDevice = { ...current, ...patch };
69
+ const changed = Object.keys(nextDevice).some((key) => nextDevice[key] !== current[key]);
70
+ if (!changed)
71
+ return;
72
+ publish({ ...snapshot, device: nextDevice });
73
+ }
74
+ function setLoginUI(patch) {
75
+ const current = snapshot.loginUI;
76
+ const next = { ...current, ...patch };
77
+ const changed = Object.keys(next).some((key) => next[key] !== current[key]);
78
+ if (!changed)
79
+ return;
80
+ publish({ ...snapshot, loginUI: next });
81
+ }
82
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/internal/store.ts"],"names":[],"mappings":";;;AA6EA,0BAWC;AAED,8BAQC;AAED,gCAQC;AAzFD,MAAM,YAAY,GAAc;IAC9B,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,IAAI;IACb,aAAa,EAAE,KAAK;CACrB,CAAC;AAEF,MAAM,cAAc,GAAkB;IACpC,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,OAAO;IACf,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;IAC/B,UAAU,EAAE,EAAE;CACf,CAAC;AAEF,MAAM,gBAAgB,GAAiB;IACrC,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,WAAW;IACjB,SAAS,EAAE,MAAM;IACjB,SAAS,EAAE,EAAE;IACb,gBAAgB,EAAE,KAAK;IACvB,KAAK,EAAE,IAAI;IACX,UAAU,EAAE,KAAK;CA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AAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC;IAChC,MAAM,UAAU,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;IAC5C,MAAM,OAAO,GAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAgC,CAAC,IAAI,CAC1E,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,CAC1C,CAAC;IACF,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,CAAC,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;AAC/C,CAAC;AAED,SAAgB,UAAU,CAAC,KAA4B;IACrD,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IACjC,MAAM,IAAI,GAAiB,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;IACpD,MAAM,OAAO,GAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAA+B,CAAC,IAAI,CACnE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,CACpC,CAAC;IACF,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,CAAC,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,24 @@
1
+ import * as React from "react";
2
+ import type { EazoState } from "./types";
3
+ /**
4
+ * Mounts the SDK runtime. Place once at the root of your React tree.
5
+ *
6
+ * <EazoProvider>
7
+ * <App />
8
+ * </EazoProvider>
9
+ *
10
+ * Renders the shared login UI so `auth.login()` works anywhere in the app
11
+ * without the consumer mounting anything else.
12
+ */
13
+ export declare function EazoProvider(props: {
14
+ children: React.ReactNode;
15
+ }): React.ReactElement;
16
+ /**
17
+ * Subscribe to a slice of the Eazo state. The selector runs on every update;
18
+ * the hook only re-renders when the selector's return value changes (Object.is).
19
+ *
20
+ * const user = useEazo(s => s.auth.user);
21
+ * const { platform, safeArea } = useEazo(s => s.device);
22
+ */
23
+ export declare function useEazo<T>(selector: (state: EazoState) => T): T;
24
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIzC;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,GAAG,KAAK,CAAC,YAAY,CAcrF;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,CAAC,GAAG,CAAC,CAkB/D"}
package/dist/react.js ADDED
@@ -0,0 +1,81 @@
1
+ "use client";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.EazoProvider = EazoProvider;
37
+ exports.useEazo = useEazo;
38
+ const jsx_runtime_1 = require("react/jsx-runtime");
39
+ const React = __importStar(require("react"));
40
+ const bootstrap_1 = require("./internal/bootstrap");
41
+ const auth_1 = require("./internal/capabilities/auth");
42
+ const device_1 = require("./internal/capabilities/device");
43
+ const login_ui_1 = require("./internal/login-ui");
44
+ const store_1 = require("./internal/store");
45
+ const MountedContext = React.createContext(false);
46
+ /**
47
+ * Mounts the SDK runtime. Place once at the root of your React tree.
48
+ *
49
+ * <EazoProvider>
50
+ * <App />
51
+ * </EazoProvider>
52
+ *
53
+ * Renders the shared login UI so `auth.login()` works anywhere in the app
54
+ * without the consumer mounting anything else.
55
+ */
56
+ function EazoProvider(props) {
57
+ React.useEffect(() => {
58
+ // Starting the bridge is idempotent; capability access may have already done so.
59
+ (0, bootstrap_1.getBridge)();
60
+ void (0, auth_1._bootstrapAuth)();
61
+ void (0, device_1._bootstrapDevice)();
62
+ }, []);
63
+ return ((0, jsx_runtime_1.jsxs)(MountedContext.Provider, { value: true, children: [props.children, (0, jsx_runtime_1.jsx)(login_ui_1.LoginUI, {})] }));
64
+ }
65
+ /**
66
+ * Subscribe to a slice of the Eazo state. The selector runs on every update;
67
+ * the hook only re-renders when the selector's return value changes (Object.is).
68
+ *
69
+ * const user = useEazo(s => s.auth.user);
70
+ * const { platform, safeArea } = useEazo(s => s.device);
71
+ */
72
+ function useEazo(selector) {
73
+ const mounted = React.useContext(MountedContext);
74
+ if (process.env.NODE_ENV !== "production" && !mounted) {
75
+ console.warn("[@eazo/sdk] useEazo() called without <EazoProvider>. Mount it at the root of your app.");
76
+ }
77
+ const getSnapshot = React.useCallback(() => selector(store_1.store.getSnapshot()), [selector]);
78
+ const getServerSnapshot = React.useCallback(() => selector(store_1.INITIAL_STATE), [selector]);
79
+ return React.useSyncExternalStore(store_1.store.subscribe, getSnapshot, getServerSnapshot);
80
+ }
81
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBb,oCAcC;AASD,0BAkBC;;AA9DD,6CAA+B;AAE/B,oDAAiD;AACjD,uDAA8D;AAC9D,2DAAkE;AAClE,kDAA8C;AAC9C,4CAAwD;AAGxD,MAAM,cAAc,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAElD;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAAC,KAAoC;IAC/D,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,iFAAiF;QACjF,IAAA,qBAAS,GAAE,CAAC;QACZ,KAAK,IAAA,qBAAc,GAAE,CAAC;QACtB,KAAK,IAAA,yBAAgB,GAAE,CAAC;IAC1B,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,wBAAC,cAAc,CAAC,QAAQ,IAAC,KAAK,EAAE,IAAI,aACjC,KAAK,CAAC,QAAQ,EACf,uBAAC,kBAAO,KAAG,IACa,CAC3B,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,OAAO,CAAI,QAAiC;IAC1D,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IACjD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,CAAC,OAAO,EAAE,CAAC;QACtD,OAAO,CAAC,IAAI,CACV,wFAAwF,CACzF,CAAC;IACJ,CAAC;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CACnC,GAAG,EAAE,CAAC,QAAQ,CAAC,aAAK,CAAC,WAAW,EAAE,CAAC,EACnC,CAAC,QAAQ,CAAC,CACX,CAAC;IACF,MAAM,iBAAiB,GAAG,KAAK,CAAC,WAAW,CACzC,GAAG,EAAE,CAAC,QAAQ,CAAC,qBAAa,CAAC,EAC7B,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,OAAO,KAAK,CAAC,oBAAoB,CAAC,aAAK,CAAC,SAAS,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC;AACrF,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { User } from "./types";
2
+ /** Minimal Request-like shape — avoids importing next/server types. */
3
+ interface HeaderRequest {
4
+ headers: {
5
+ get(name: string): string | null;
6
+ };
7
+ }
8
+ export type AuthResult = {
9
+ ok: true;
10
+ user: User;
11
+ } | {
12
+ ok: false;
13
+ response: Response;
14
+ };
15
+ /**
16
+ * Server-side auth guard. Reads the `x-eazo-session` header, decrypts the
17
+ * encrypted session with EAZO_PRIVATE_KEY, and returns the user.
18
+ */
19
+ export declare function requireAuth(request: HeaderRequest): AuthResult;
20
+ export type { User } from "./types";
21
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAyBpC,uEAAuE;AACvE,UAAU,aAAa;IACrB,OAAO,EAAE;QAAE,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CAC/C;AAED,MAAM,MAAM,UAAU,GAClB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GACxB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC;AAStC;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,UAAU,CAiB9D;AAED,YAAY,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC"}
package/dist/server.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireAuth = requireAuth;
4
+ const auth_primitive_1 = require("./internal/auth-primitive");
5
+ let authServer = null;
6
+ function getAuthServer() {
7
+ if (authServer)
8
+ return authServer;
9
+ const privateKey = process.env.EAZO_PRIVATE_KEY;
10
+ if (!privateKey) {
11
+ throw new Error("@eazo/sdk/server: EAZO_PRIVATE_KEY is required for requireAuth().");
12
+ }
13
+ authServer = new auth_primitive_1.EazoAuthServer({ privateKey });
14
+ return authServer;
15
+ }
16
+ function normalize(info) {
17
+ return {
18
+ id: String(info.userId),
19
+ email: info.email ?? null,
20
+ name: info.nickname ?? null,
21
+ avatarUrl: info.avatarUrl ?? null,
22
+ };
23
+ }
24
+ function unauthorized(message) {
25
+ return new Response(JSON.stringify({ error: message }), {
26
+ status: 401,
27
+ headers: { "Content-Type": "application/json" },
28
+ });
29
+ }
30
+ /**
31
+ * Server-side auth guard. Reads the `x-eazo-session` header, decrypts the
32
+ * encrypted session with EAZO_PRIVATE_KEY, and returns the user.
33
+ */
34
+ function requireAuth(request) {
35
+ const raw = request.headers.get("x-eazo-session");
36
+ if (!raw)
37
+ return { ok: false, response: unauthorized("Missing session") };
38
+ let parsed;
39
+ try {
40
+ parsed = JSON.parse(raw);
41
+ }
42
+ catch {
43
+ return { ok: false, response: unauthorized("Malformed session") };
44
+ }
45
+ try {
46
+ const info = getAuthServer().verifySession(parsed);
47
+ return { ok: true, user: normalize(info) };
48
+ }
49
+ catch {
50
+ return { ok: false, response: unauthorized("Invalid session") };
51
+ }
52
+ }
53
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","source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AI,CAAC,KAAK,CAAC,GAAG,CAAiB,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,mBAAmB,CAAC,EAAE,CAAC;IACpE,CAAC;IAED,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,aAAa,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACnD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAClE,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Test helpers. NOT for production code paths.
3
+ *
4
+ * import { __resetSDK } from "@eazo/sdk/testing";
5
+ * afterEach(() => __resetSDK());
6
+ */
7
+ export declare function __resetSDK(): void;
8
+ /**
9
+ * Dispatches a fake message on the window. Use to simulate host → app envelopes
10
+ * in tests that don't mount a real RN WebView.
11
+ */
12
+ export declare function __dispatchHostMessage(envelope: unknown): void;
13
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AAEH,wBAAgB,UAAU,IAAI,IAAI,CAYjC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAG7D"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.__resetSDK = __resetSDK;
4
+ exports.__dispatchHostMessage = __dispatchHostMessage;
5
+ const bootstrap_1 = require("./internal/bootstrap");
6
+ const auth_1 = require("./internal/capabilities/auth");
7
+ const device_1 = require("./internal/capabilities/device");
8
+ const store_1 = require("./internal/store");
9
+ /**
10
+ * Test helpers. NOT for production code paths.
11
+ *
12
+ * import { __resetSDK } from "@eazo/sdk/testing";
13
+ * afterEach(() => __resetSDK());
14
+ */
15
+ function __resetSDK() {
16
+ (0, auth_1.__resetAuthCapability)();
17
+ (0, device_1.__resetDeviceCapability)();
18
+ (0, bootstrap_1.__resetBootstrap)();
19
+ store_1.store.reset();
20
+ if (typeof window !== "undefined") {
21
+ try {
22
+ window.localStorage.removeItem("eazo.session");
23
+ }
24
+ catch {
25
+ /* ignore */
26
+ }
27
+ }
28
+ }
29
+ /**
30
+ * Dispatches a fake message on the window. Use to simulate host → app envelopes
31
+ * in tests that don't mount a real RN WebView.
32
+ */
33
+ function __dispatchHostMessage(envelope) {
34
+ if (typeof window === "undefined")
35
+ return;
36
+ window.dispatchEvent(new MessageEvent("message", { data: envelope }));
37
+ }
38
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":";;AAYA,gCAYC;AAMD,sDAGC;AAjCD,oDAAwD;AACxD,uDAAqE;AACrE,2DAAyE;AACzE,4CAAyC;AAEzC;;;;;GAKG;AAEH,SAAgB,UAAU;IACxB,IAAA,4BAAqB,GAAE,CAAC;IACxB,IAAA,gCAAuB,GAAE,CAAC;IAC1B,IAAA,4BAAgB,GAAE,CAAC;IACnB,aAAK,CAAC,KAAK,EAAE,CAAC;IACd,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,IAAI,CAAC;YACH,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;QACjD,CAAC;QAAC,MAAM,CAAC;YACP,YAAY;QACd,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,QAAiB;IACrD,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO;IAC1C,MAAM,CAAC,aAAa,CAAC,IAAI,YAAY,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Public semantic types. These are the shapes app developers import.
3
+ * Protocol / envelope / transport details stay in internal/.
4
+ */
5
+ export interface User {
6
+ id: string;
7
+ email: string | null;
8
+ name: string | null;
9
+ avatarUrl: string | null;
10
+ }
11
+ export interface DeviceContext {
12
+ platform: "web" | "mobile";
13
+ locale: string;
14
+ safeArea: {
15
+ top: number;
16
+ bottom: number;
17
+ };
18
+ backendUrl: string;
19
+ }
20
+ export interface AuthState {
21
+ user: User | null;
22
+ loading: boolean;
23
+ authenticated: boolean;
24
+ }
25
+ /**
26
+ * The full reactive state tree selected by `useEazo(selector)`.
27
+ * Each capability contributes one namespace; adding a capability adds a field here.
28
+ */
29
+ export interface EazoState {
30
+ auth: AuthState;
31
+ device: DeviceContext;
32
+ }
33
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,KAAK,GAAG,QAAQ,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;CACvB"}
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Public semantic types. These are the shapes app developers import.
4
+ * Protocol / envelope / transport details stay in internal/.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@eazo/sdk",
3
+ "version": "0.4.0",
4
+ "description": "Eazo platform SDK — capability-first API for web apps that run on Eazo Mobile and the web browser",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./react": {
13
+ "types": "./dist/react.d.ts",
14
+ "default": "./dist/react.js"
15
+ },
16
+ "./server": {
17
+ "types": "./dist/server.d.ts",
18
+ "default": "./dist/server.js"
19
+ },
20
+ "./testing": {
21
+ "types": "./dist/testing.d.ts",
22
+ "default": "./dist/testing.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "PROTOCOL.md"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsc && node scripts/fix-use-client.js",
32
+ "test": "vitest run",
33
+ "test:watch": "vitest",
34
+ "prepublishOnly": "npm run build"
35
+ },
36
+ "keywords": [
37
+ "eazo",
38
+ "sdk",
39
+ "capability",
40
+ "platform",
41
+ "host-bridge"
42
+ ],
43
+ "author": "Eazo",
44
+ "license": "MIT",
45
+ "dependencies": {
46
+ "@radix-ui/react-dialog": "^1.1.4",
47
+ "authing-js-sdk": "^4.23.55",
48
+ "elliptic": "^6.6.1"
49
+ },
50
+ "peerDependencies": {
51
+ "react": ">=18"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "react": {
55
+ "optional": true
56
+ }
57
+ },
58
+ "devDependencies": {
59
+ "@testing-library/react": "^16.1.0",
60
+ "@types/elliptic": "^6.4.18",
61
+ "@types/node": "^20.0.0",
62
+ "@types/react": "^19.0.0",
63
+ "happy-dom": "^15.11.7",
64
+ "react": "^19.0.0",
65
+ "typescript": "^5.3.0",
66
+ "vitest": "^2.1.8"
67
+ },
68
+ "engines": {
69
+ "node": ">=18.0.0"
70
+ }
71
+ }