@nevermined-io/ui-widgets 0.5.10 → 0.5.11

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.
package/dist/index.mjs CHANGED
@@ -231,15 +231,21 @@ var y = class {
231
231
  start(e) {
232
232
  if (this.destroyed) throw Error("[CheckoutWidget] cannot start: instance has been destroyed");
233
233
  if (!e.did || typeof e.did != "string") throw Error("[CheckoutWidget] did is required");
234
- this.manager?.destroy();
235
- let t = new URL(this.webappBase).origin, n = window.location.origin, r = new URL(`/embed/checkout/${encodeURIComponent(e.did)}`, this.webappBase);
236
- r.searchParams.set("parentOrigin", n), e.planId && r.searchParams.set("planId", e.planId);
237
- let i = new y(t);
238
- this.manager = i, i.create(r.toString(), {
239
- container: e.container,
240
- width: e.width,
241
- height: e.height
242
- }), i.onMessage((t) => this.handleMessage(t, e, i));
234
+ let t = new URL(`/embed/checkout/${encodeURIComponent(e.did)}`, this.webappBase);
235
+ e.planId && t.searchParams.set("planId", e.planId), this.mount(t, e, (t) => ({
236
+ did: t.did ?? e.did,
237
+ planId: t.planId ?? e.planId,
238
+ txHash: t.txHash
239
+ }), e.onSuccess);
240
+ }
241
+ startPlan(e) {
242
+ if (this.destroyed) throw Error("[CheckoutWidget] cannot start: instance has been destroyed");
243
+ if (!e.planId || typeof e.planId != "string") throw Error("[CheckoutWidget] planId is required");
244
+ let t = new URL(`/embed/checkout/plan/${encodeURIComponent(e.planId)}`, this.webappBase);
245
+ this.mount(t, e, (t) => ({
246
+ planId: t.planId ?? e.planId,
247
+ txHash: t.txHash
248
+ }), e.onSuccess);
243
249
  }
244
250
  destroy() {
245
251
  this.destroyed = !0, this.manager?.destroy(), this.manager = null;
@@ -250,7 +256,18 @@ var y = class {
250
256
  buildSuccessHandle(e, t) {
251
257
  return { close: () => this.closeFromIframe(e, t) };
252
258
  }
253
- handleMessage(e, t, n) {
259
+ mount(e, t, n, r) {
260
+ this.manager?.destroy();
261
+ let i = new URL(this.webappBase).origin;
262
+ e.searchParams.set("parentOrigin", window.location.origin);
263
+ let a = new y(i);
264
+ this.manager = a, a.create(e.toString(), {
265
+ container: t.container,
266
+ width: t.width,
267
+ height: t.height
268
+ }), a.onMessage((e) => this.handleMessage(e, t, a, n, r));
269
+ }
270
+ handleMessage(e, t, n, r, i) {
254
271
  if (!w(e, t)) switch (e.type) {
255
272
  case f.BOOTED:
256
273
  this.manager?.postMessage(g(f.INIT, { sessionToken: this.session.getToken() })), t.onBooted?.();
@@ -259,13 +276,9 @@ var y = class {
259
276
  t.onReady?.();
260
277
  return;
261
278
  case f.SUCCESS: {
262
- let r = e.payload ?? {}, i = {
263
- did: r.did ?? t.did,
264
- planId: r.planId ?? t.planId,
265
- txHash: r.txHash
266
- };
267
- t.onSuccess?.({
268
- result: i,
279
+ let a = r(e.payload != null && typeof e.payload == "object" ? e.payload : {});
280
+ i?.({
281
+ result: a,
269
282
  handle: this.buildSuccessHandle(t, n)
270
283
  });
271
284
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nevermined-io/ui-widgets",
3
- "version": "0.5.10",
3
+ "version": "0.5.11",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -1,11 +0,0 @@
1
- type EventHandler<T> = (payload: T) => void;
2
- export declare class TypedEventEmitter<Events extends object> {
3
- private listeners;
4
- on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
5
- off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
6
- once<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
7
- removeAllListeners(event?: keyof Events): this;
8
- emit<K extends keyof Events>(event: K, payload: Events[K]): void;
9
- }
10
- export {};
11
- //# sourceMappingURL=event-emitter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../src/event-emitter.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAA;AAE3C,qBAAa,iBAAiB,CAAC,MAAM,SAAS,MAAM;IAClD,OAAO,CAAC,SAAS,CAAsD;IAEvE,EAAE,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAO5E,GAAG,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAS7E,IAAI,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAS9E,kBAAkB,CAAC,KAAK,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI;IAS9C,IAAI,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI;CAWjE"}
@@ -1,44 +0,0 @@
1
- import { type WidgetMessage } from './messages.js';
2
- export interface IframeOptions {
3
- container?: HTMLElement;
4
- style?: Partial<CSSStyleDeclaration>;
5
- /**
6
- * Fixed CSS width for inline (container) mode. #1668: the widget renders
7
- * as a fixed-size box, like a Privy UI component, so the integrator can
8
- * place it predictably on their page. Clamped to
9
- * `[INLINE_MIN_WIDTH, INLINE_MAX_WIDTH]`. Default: `INLINE_DEFAULT_WIDTH`
10
- * — the constants are the single source of truth, so future re-tunings
11
- * don't require touching this JSDoc. Ignored in fullscreen overlay mode.
12
- */
13
- width?: number;
14
- /**
15
- * Fixed CSS height for inline mode. Clamped to
16
- * `[INLINE_MIN_HEIGHT, INLINE_MAX_HEIGHT]`. Default: `INLINE_DEFAULT_HEIGHT`.
17
- * The embed content uses responsive CSS to adapt to the dimensions the
18
- * integrator picks — within the clamped range — without distorting (no
19
- * CSS transform scale). Ignored in fullscreen overlay mode.
20
- */
21
- height?: number;
22
- }
23
- export declare const INLINE_MIN_WIDTH = 440;
24
- export declare const INLINE_MAX_WIDTH = 720;
25
- export declare const INLINE_DEFAULT_WIDTH = 480;
26
- export declare const INLINE_MIN_HEIGHT = 640;
27
- export declare const INLINE_MAX_HEIGHT = 960;
28
- export declare const INLINE_DEFAULT_HEIGHT = 720;
29
- export declare class IframeManager {
30
- private expectedOrigin;
31
- private iframe;
32
- private messageHandlers;
33
- private protocolErrorHandlers;
34
- private messageListener;
35
- private destroyed;
36
- constructor(expectedOrigin: string);
37
- create(url: string, options?: IframeOptions): HTMLIFrameElement;
38
- destroy(): void;
39
- postMessage(msg: WidgetMessage): void;
40
- onMessage(handler: (msg: WidgetMessage) => void): () => void;
41
- onProtocolError(handler: (reason: string) => void): () => void;
42
- private ensureListener;
43
- }
44
- //# sourceMappingURL=iframe-manager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"iframe-manager.d.ts","sourceRoot":"","sources":["../src/iframe-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,aAAa,EAAE,MAAM,eAAe,CAAA;AAEhE,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAA;IACpC;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AASD,eAAO,MAAM,gBAAgB,MAAM,CAAA;AACnC,eAAO,MAAM,gBAAgB,MAAM,CAAA;AACnC,eAAO,MAAM,oBAAoB,MAAM,CAAA;AACvC,eAAO,MAAM,iBAAiB,MAAM,CAAA;AACpC,eAAO,MAAM,iBAAiB,MAAM,CAAA;AACpC,eAAO,MAAM,qBAAqB,M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V,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACxD,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC5E,YAAY,EACV,UAAU,EACV,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,0BAA0B,CAAA;AACjC,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
@@ -1,28 +0,0 @@
1
- export declare enum WidgetMessageType {
2
- INIT = "nvm:init",
3
- CLOSE = "nvm:close",
4
- BOOTED = "nvm:booted",
5
- READY = "nvm:ready",
6
- RESIZE = "nvm:resize",
7
- SUCCESS = "nvm:success",
8
- ERROR = "nvm:error",
9
- CARD_ACTION = "nvm:card-action",
10
- AUTH_MISMATCH = "nvm:auth-mismatch",
11
- AUTH_SWITCH_REQUEST = "nvm:auth-switch-request"
12
- }
13
- export interface WidgetMessage<T = unknown> {
14
- type: WidgetMessageType;
15
- version: '1';
16
- payload?: T;
17
- }
18
- export declare const WIDGET_MESSAGE_VERSION: "1";
19
- export declare function createMessage<T>(type: WidgetMessageType, payload?: T): WidgetMessage<T>;
20
- export type ParseResult<T = unknown> = {
21
- ok: true;
22
- message: WidgetMessage<T>;
23
- } | {
24
- ok: false;
25
- reason: string;
26
- };
27
- export declare function parseMessage(data: unknown): ParseResult;
28
- //# sourceMappingURL=messages.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB;IAE3B,IAAI,aAAa;IACjB,KAAK,cAAc;IAEnB,MAAM,eAAe;IACrB,KAAK,cAAc;IACnB,MAAM,eAAe;IACrB,OAAO,gBAAgB;IACvB,KAAK,cAAc;IAInB,WAAW,oBAAoB;IAI/B,aAAa,sBAAsB;IAKnC,mBAAmB,4BAA4B;CAChD;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO;IACxC,IAAI,EAAE,iBAAiB,CAAA;IACvB,OAAO,EAAE,GAAG,CAAA;IACZ,OAAO,CAAC,EAAE,CAAC,CAAA;CACZ;AAED,eAAO,MAAM,sBAAsB,EAAG,GAAY,CAAA;AAWlD,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAMvF;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAC/B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAAE,GACvC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAEjC,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,CA8BvD"}
@@ -1,36 +0,0 @@
1
- import type { WidgetConfig, WidgetAccount } from './types.js';
2
- import { CheckoutWidget } from './widgets/checkout.js';
3
- import { DelegationsWidget } from './widgets/delegations.js';
4
- interface NeverminedWidgetsEvents {
5
- 'session-expired': void;
6
- }
7
- export declare class NeverminedWidgets {
8
- private readonly sessionManager;
9
- private readonly _account;
10
- private readonly environment;
11
- private _checkout;
12
- private _delegations;
13
- private readonly events;
14
- private constructor();
15
- static initialize(config: WidgetConfig): Promise<NeverminedWidgets>;
16
- private refreshSession;
17
- on<K extends keyof NeverminedWidgetsEvents>(event: K, handler: (payload: NeverminedWidgetsEvents[K]) => void): this;
18
- off<K extends keyof NeverminedWidgetsEvents>(event: K, handler: (payload: NeverminedWidgetsEvents[K]) => void): this;
19
- get account(): WidgetAccount;
20
- get hasValidSession(): boolean;
21
- getSessionToken(): string;
22
- get checkout(): CheckoutWidget;
23
- get delegations(): DelegationsWidget;
24
- /**
25
- * Resets the parent widget container: tears down any live child widget (e.g.
26
- * the checkout widget) and clears the internal cache. This is a reset, not a
27
- * terminal state — accessing `widget.checkout` after `destroy()` lazily
28
- * creates a fresh `CheckoutWidget` instance. If you need a terminal "this
29
- * widget can no longer be used" semantics, call `destroy()` on the child
30
- * widget directly (e.g. `widget.checkout.destroy()`), which flips its
31
- * internal `destroyed` flag and makes subsequent `start()` calls throw.
32
- */
33
- destroy(): void;
34
- }
35
- export {};
36
- //# sourceMappingURL=nevermined-widgets.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nevermined-widgets.d.ts","sourceRoot":"","sources":["../src/nevermined-widgets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAA8B,MAAM,YAAY,CAAA;AAMzF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE5D,UAAU,uBAAuB;IAC/B,iBAAiB,EAAE,IAAI,CAAA;CACxB;AAYD,qBAAa,iBAAiB;IAM1B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAP9B,OAAO,CAAC,SAAS,CAA8B;IAC/C,OAAO,CAAC,YAAY,CAAiC;IACrD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmD;IAE1E,OAAO;WAMM,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC;YA0B3D,cAAc;IAwB5B,EAAE,CAAC,CAAC,SAAS,MAAM,uBAAuB,EACxC,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,KAAK,IAAI,GACrD,IAAI;IAKP,GAAG,CAAC,CAAC,SAAS,MAAM,uBAAuB,EACzC,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,KAAK,IAAI,GACrD,IAAI;IAKP,IAAI,OAAO,IAAI,aAAa,CAE3B;IAED,IAAI,eAAe,IAAI,OAAO,CAE7B;IAED,eAAe,IAAI,MAAM;IAKzB,IAAI,QAAQ,IAAI,cAAc,CAK7B;IAED,IAAI,WAAW,IAAI,iBAAiB,CASnC;IAED;;;;;;;;OAQG;IACH,OAAO,IAAI,IAAI;CAQhB"}
package/dist/session.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import type { WidgetSession } from './types.js';
2
- export declare class SessionManager {
3
- private session;
4
- private expiresMs;
5
- private timer;
6
- constructor(session: WidgetSession);
7
- isValid(): boolean;
8
- getToken(): string;
9
- getSession(): WidgetSession;
10
- startAutoRefresh(refreshFn: () => Promise<WidgetSession>, onExpired: () => void): void;
11
- stopAutoRefresh(): void;
12
- }
13
- //# sourceMappingURL=session.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAI/C,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,KAAK,CAA6C;gBAE9C,OAAO,EAAE,aAAa;IAWlC,OAAO,IAAI,OAAO;IAIlB,QAAQ,IAAI,MAAM;IAIlB,UAAU,IAAI,aAAa;IAI3B,gBAAgB,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,MAAM,IAAI,GAAG,IAAI;IA8BtF,eAAe,IAAI,IAAI;CAMxB"}
package/dist/types.d.ts DELETED
@@ -1,109 +0,0 @@
1
- export declare const ENVIRONMENTS: readonly ["local", "sandbox", "live", "staging_sandbox", "staging_live"];
2
- export type Environment = (typeof ENVIRONMENTS)[number];
3
- export interface WidgetConfig {
4
- /**
5
- * Widget session minted server-to-server by the integrator backend
6
- * (typically via `@nevermined-io/ui-widgets-server.createWidgetSession`).
7
- * Forward the response object verbatim — the SDK never holds the widget
8
- * key `rawSecret`.
9
- */
10
- session: WidgetSession;
11
- environment: Environment;
12
- }
13
- export interface WidgetSession {
14
- sessionToken: string;
15
- userId: string;
16
- userWallet: `0x${string}`;
17
- /**
18
- * Hash of the NVM API key bound to this widget session user. Returned by
19
- * `POST /api/v1/widgets/session` so host pages that want to call user-scoped
20
- * endpoints directly (outside the iframe) have the bearer token to do so.
21
- * The embedded iframe flow consumes it via the session JWT claims rather
22
- * than this field.
23
- */
24
- apiKeyHash: string;
25
- expiresAt: string;
26
- }
27
- export interface WidgetAccount {
28
- userId: string;
29
- userWallet: `0x${string}`;
30
- }
31
- export interface EmbedError {
32
- code: 'UNAUTHORIZED' | 'NETWORK' | 'PAYMENT_NOT_CONFIRMED' | 'UNKNOWN';
33
- /**
34
- * Raw, host-facing message. Carries the underlying detail (e.g. the backend
35
- * `NVMException.message`) and is what the SDK forwards over the `nvm:error`
36
- * postMessage for the integrator to log. May contain operational/technical
37
- * text, so it is NOT safe to render in an end-user surface verbatim.
38
- */
39
- message: string;
40
- /**
41
- * Safe, user-facing message. Generic per-`code` copy with no operational
42
- * detail — render this (falling back to `message`) in any UI shown to the
43
- * end user, such as the widgets' terminal error panels. Optional and
44
- * additive: existing host integrations that only read `message` are
45
- * unaffected.
46
- */
47
- userMessage?: string;
48
- status?: number;
49
- apiCode?: string;
50
- }
51
- /**
52
- * Emitted (via the per-widget `onAuthMismatch` callback) when the iframe
53
- * detects a live host Privy session whose email does not match the email
54
- * the widget session was minted for. The iframe renders a two-button prompt
55
- * (continue as the host identity, or switch to the widget-session identity
56
- * by signing out of Privy inside the iframe) and the host page is informed
57
- * so it can mirror that affordance on its own UI. The widget is effectively
58
- * halted until either button is clicked or the host re-mints a widget
59
- * session via the action below.
60
- */
61
- export interface AuthMismatchDetail {
62
- /** Email the widget session was minted for (normalized — trimmed, lower-cased). */
63
- expectedEmail: string;
64
- }
65
- /**
66
- * Emitted (via the per-widget `onAuthSwitchRequest` callback) when the user
67
- * picks "Continue as <hostEmail>" on the mismatch prompt. The host page is
68
- * expected to re-mint a widget session bound to `requestedEmail` and reopen
69
- * the widget; the iframe stays on the prompt until that happens.
70
- *
71
- * **Security note for integrators:** the SDK posts this event to the host
72
- * via `window.postMessage`, but the host's `window.addEventListener('message',
73
- * ...)` listens to ALL frames on the page. Validate `event.origin === <your
74
- * widget host>` (e.g. `https://app.nevermined.io`) before re-minting a
75
- * session — otherwise a malicious sub-frame could spoof this event and
76
- * trick your backend into minting a session for an attacker-supplied email.
77
- */
78
- export interface AuthSwitchRequestDetail {
79
- /** Email the user wants the widget to operate under (their live Privy identity). */
80
- requestedEmail: string;
81
- /** Email the original widget session was minted for, for reference / telemetry. */
82
- expectedEmail: string;
83
- }
84
- /**
85
- * Control surface passed to every widget's `onSuccess` callback (#1668
86
- * sub-tasks 3 + 4). The iframe stays mounted indefinitely after a
87
- * successful action so the integrator can show their own post-action UI
88
- * (toast, next-step prompt, etc.) while the success state remains visible
89
- * inside the widget. The integrator dismisses the widget by calling
90
- * `handle.close()` — which destroys the iframe and invokes `onClose` —
91
- * whenever their own flow is ready.
92
- */
93
- export interface WidgetSuccessHandle {
94
- /**
95
- * Destroys the iframe and invokes the widget's `onClose` callback.
96
- * Idempotent: calling close on an already-closed widget is a no-op.
97
- */
98
- close(): void;
99
- }
100
- /**
101
- * Payload shape passed to every widget's `onSuccess` callback. `result`
102
- * is the per-widget data (paymentMethodId, delegationId, etc.); `handle`
103
- * lets the integrator dismiss the widget on their own schedule.
104
- */
105
- export interface WidgetSuccessEvent<T> {
106
- result: T;
107
- handle: WidgetSuccessHandle;
108
- }
109
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings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E,mBAAmB,CAAA;CAC5B"}
@@ -1,4 +0,0 @@
1
- import type { Environment } from '../types.js';
2
- export declare function getApiBaseUrl(environment: Environment): string;
3
- export declare function getWebappBaseUrl(environment: Environment): string;
4
- //# sourceMappingURL=environment.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAkB9C,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAE9D;AAED,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAEjE"}
@@ -1,39 +0,0 @@
1
- export declare const WIDGET_ERRORS: {
2
- readonly MISSING_SESSION: {
3
- readonly numericCode: "WDG.0001";
4
- readonly message: "session is required — pass the WidgetSession returned by createWidgetSession on the backend";
5
- };
6
- readonly INVALID_ENVIRONMENT: {
7
- readonly numericCode: "WDG.0002";
8
- readonly message: "environment must be one of: sandbox, live, staging_sandbox, staging_live, local";
9
- };
10
- readonly INVALID_SESSION: {
11
- readonly numericCode: "WDG.0003";
12
- readonly message: "session is missing required fields";
13
- };
14
- readonly SESSION_EXPIRED: {
15
- readonly numericCode: "WDG.0006";
16
- readonly message: "Widget session has expired";
17
- };
18
- };
19
- export type WidgetErrorCode = keyof typeof WIDGET_ERRORS;
20
- export declare class WidgetInitError extends Error {
21
- readonly code: WidgetErrorCode;
22
- constructor(code: WidgetErrorCode, message?: string, cause?: unknown);
23
- }
24
- export declare class WidgetSessionExpiredError extends Error {
25
- readonly code: "SESSION_EXPIRED";
26
- constructor();
27
- }
28
- /**
29
- * Thrown by SDK methods that hit the API directly (no iframe), e.g.
30
- * `delegations.revokeCard()` / `delegations.revokeDelegation()`. Carries the
31
- * HTTP status and the optional BCK error code so consumers can branch on
32
- * 401/403/etc. without parsing the message.
33
- */
34
- export declare class WidgetApiError extends Error {
35
- readonly status?: number | undefined;
36
- readonly apiCode?: string | undefined;
37
- constructor(message: string, status?: number | undefined, apiCode?: string | undefined);
38
- }
39
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;CAemD,CAAA;AAE7E,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,aAAa,CAAA;AAExD,qBAAa,eAAgB,SAAQ,KAAK;aAEtB,IAAI,EAAE,eAAe;gBAArB,IAAI,EAAE,eAAe,EACrC,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,OAAO;CAKlB;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,QAAQ,CAAC,IAAI,EAAG,iBAAiB,CAAS;;CAM3C;AAED;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,KAAK;aAGrB,MAAM,CAAC,EAAE,MAAM;aACf,OAAO,CAAC,EAAE,MAAM;gBAFhC,OAAO,EAAE,MAAM,EACC,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,OAAO,CAAC,EAAE,MAAM,YAAA;CAKnC"}
@@ -1,110 +0,0 @@
1
- import { SessionManager } from '../session.js';
2
- import { type WidgetMessage } from '../messages.js';
3
- import type { AuthMismatchDetail, AuthSwitchRequestDetail, EmbedError, WidgetSuccessEvent } from '../types.js';
4
- export interface CheckoutResult {
5
- did: string;
6
- planId?: string;
7
- txHash?: string;
8
- }
9
- export interface CheckoutOptions {
10
- did: string;
11
- planId?: string;
12
- container?: HTMLElement;
13
- /**
14
- * Fixed iframe width in pixels. Clamped by the SDK to a supported range
15
- * (see `INLINE_MIN_WIDTH` / `INLINE_MAX_WIDTH` / `INLINE_DEFAULT_WIDTH`
16
- * in `iframe-manager`). Ignored in fullscreen overlay mode (no container).
17
- */
18
- width?: number;
19
- /**
20
- * Fixed iframe height in pixels. Clamped by the SDK to a supported range
21
- * (see `INLINE_MIN_HEIGHT` / `INLINE_MAX_HEIGHT` / `INLINE_DEFAULT_HEIGHT`
22
- * in `iframe-manager`). Ignored in fullscreen overlay mode.
23
- */
24
- height?: number;
25
- onBooted?: () => void;
26
- onReady?: () => void;
27
- /**
28
- * Fires when the iframe posts `nvm:success`. The widget stays mounted in
29
- * its success state — the integrator dismisses it via `event.handle.close()`
30
- * when their own post-success flow is ready. There is no auto-dismiss.
31
- */
32
- onSuccess?: (event: WidgetSuccessEvent<CheckoutResult>) => void;
33
- onError?: (error: EmbedError) => void;
34
- /**
35
- * Fires when the iframe detects that the live host Privy session belongs
36
- * to a different account than the email the widget session was minted for.
37
- * The iframe stays mounted on a two-button prompt; the host can mirror that
38
- * affordance on its own UI. See `AuthMismatchDetail`.
39
- */
40
- onAuthMismatch?: (detail: AuthMismatchDetail) => void;
41
- /**
42
- * Fires when, on the mismatch prompt, the user picks "Continue as
43
- * <hostEmail>". The host should re-mint a widget session bound to
44
- * `requestedEmail` and reopen the widget. The iframe stays on the prompt
45
- * until then. See `AuthSwitchRequestDetail`.
46
- */
47
- onAuthSwitchRequest?: (detail: AuthSwitchRequestDetail) => void;
48
- onClose?: () => void;
49
- }
50
- /**
51
- * Checkout widget.
52
- *
53
- * Lifecycle note for SDK consumers: when the iframe sends `nvm:close` the
54
- * widget instance auto-calls `destroy()` and becomes terminal — any
55
- * subsequent `start()` call throws. If the host page needs to re-show the
56
- * checkout after a close, construct a new `CheckoutWidget` (typically via
57
- * `nvm.checkout`) and call `start()` on the fresh instance.
58
- */
59
- export declare class CheckoutWidget {
60
- private readonly session;
61
- private readonly webappBase;
62
- private manager;
63
- private destroyed;
64
- constructor(session: SessionManager, webappBase: string);
65
- /**
66
- * Mounts the checkout iframe into `options.container`.
67
- * Throws if called after `destroy()` (including the implicit destroy on
68
- * `nvm:close` — see class JSDoc).
69
- */
70
- start(options: CheckoutOptions): void;
71
- destroy(): void;
72
- /**
73
- * Shared close path for `handle.close()` (integrator-driven) and
74
- * `nvm:close` (iframe-driven). Idempotent — multiple calls collapse to a
75
- * single `onClose` + destroy, which matters because `handle.close()`
76
- * could race with a `nvm:close` from the iframe if the integrator's
77
- * post-success UI happens to mount instantly.
78
- *
79
- * `manager` is the IframeManager this close was bound to when the handle
80
- * was minted. A stale handle from a previous mount (the instance was
81
- * remounted via a second `start()` without an intervening close) must NOT
82
- * tear down the now-live iframe, so we bail once it no longer owns
83
- * `this.manager`.
84
- *
85
- * Ordering is load-bearing: `destroy()` runs before `onClose()` so a
86
- * throwing `onClose` cannot leak a second close — `destroyed` is already
87
- * true by the time the callback runs.
88
- */
89
- private closeFromIframe;
90
- private buildSuccessHandle;
91
- private handleMessage;
92
- }
93
- /**
94
- * Drop the message if the payload doesn't match the contract — keeps stray
95
- * protocol updates from crashing host pages.
96
- */
97
- export declare function parseAuthMismatch(payload: unknown): AuthMismatchDetail | null;
98
- export declare function parseAuthSwitchRequest(payload: unknown): AuthSwitchRequestDetail | null;
99
- export interface AuthMessageHandlers {
100
- onAuthMismatch?: (detail: AuthMismatchDetail) => void;
101
- onAuthSwitchRequest?: (detail: AuthSwitchRequestDetail) => void;
102
- }
103
- /**
104
- * Centralizes the auth-related iframe → host messages so every widget
105
- * `handleMessage` switch can stay a one-liner. Returns true when the message
106
- * was an auth event (the caller should `return` and skip the rest of its
107
- * switch), false otherwise.
108
- */
109
- export declare function handleAuthMessage(msg: WidgetMessage, options: AuthMessageHandlers): boolean;
110
- //# sourceMappingURL=checkout.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/widgets/checkout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAoC,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACrF,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,UAAU,EACV,kBAAkB,EACnB,MAAM,aAAa,CAAA;AAEpB,M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