@nevermined-io/ui-widgets 0.5.11 → 0.5.13

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.
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,44 @@
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
@@ -0,0 +1 @@
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,MAAM,CAAA;AAMxC,qBAAa,aAAa;IAOZ,OAAO,CAAC,cAAc;IANlC,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,eAAe,CAA0C;IACjE,OAAO,CAAC,qBAAqB,CAAsC;IACnE,OAAO,CAAC,eAAe,CAA+C;IACtE,OAAO,CAAC,SAAS,CAAQ;gBAEL,cAAc,EAAE,MAAM;IAQ1C,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,iBAAiB;IAiD/D,OAAO,IAAI,IAAI;IAYf,WAAW,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI;IAKrC,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,IAAI,GAAG,MAAM,IAAI;IAO5D,eAAe,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI;IAO9D,OAAO,CAAC,cAAc;CAiCvB"}
package/dist/index.d.ts CHANGED
@@ -1,580 +1,14 @@
1
- /**
2
- * Emitted (via the per-widget `onAuthMismatch` callback) when the iframe
3
- * detects a live host Privy session whose email does not match the email
4
- * the widget session was minted for. The iframe renders a two-button prompt
5
- * (continue as the host identity, or switch to the widget-session identity
6
- * by signing out of Privy inside the iframe) and the host page is informed
7
- * so it can mirror that affordance on its own UI. The widget is effectively
8
- * halted until either button is clicked or the host re-mints a widget
9
- * session via the action below.
10
- */
11
- export declare interface AuthMismatchDetail {
12
- /** Email the widget session was minted for (normalized — trimmed, lower-cased). */
13
- expectedEmail: string;
14
- }
15
-
16
- /**
17
- * Emitted (via the per-widget `onAuthSwitchRequest` callback) when the user
18
- * picks "Continue as <hostEmail>" on the mismatch prompt. The host page is
19
- * expected to re-mint a widget session bound to `requestedEmail` and reopen
20
- * the widget; the iframe stays on the prompt until that happens.
21
- *
22
- * **Security note for integrators:** the SDK posts this event to the host
23
- * via `window.postMessage`, but the host's `window.addEventListener('message',
24
- * ...)` listens to ALL frames on the page. Validate `event.origin === <your
25
- * widget host>` (e.g. `https://app.nevermined.io`) before re-minting a
26
- * session — otherwise a malicious sub-frame could spoof this event and
27
- * trick your backend into minting a session for an attacker-supplied email.
28
- */
29
- export declare interface AuthSwitchRequestDetail {
30
- /** Email the user wants the widget to operate under (their live Privy identity). */
31
- requestedEmail: string;
32
- /** Email the original widget session was minted for, for reference / telemetry. */
33
- expectedEmail: string;
34
- }
35
-
36
- export declare interface CardAction {
37
- /**
38
- * `delegate` — the user asked to create a delegation for this card (host
39
- * should mount `createDelegation`). `revoked` — the user removed this card
40
- * inline; the list iframe stays open so this is an intra-flow event, not
41
- * flow completion (which is why it is NOT an `nvm:success`). See #1411.
42
- */
43
- action: 'delegate' | 'revoked';
44
- paymentMethodId: string;
45
- }
46
-
47
- export declare interface CheckoutOptions {
48
- did: string;
49
- planId?: string;
50
- container?: HTMLElement;
51
- /**
52
- * Fixed iframe width in pixels. Clamped by the SDK to a supported range
53
- * (see `INLINE_MIN_WIDTH` / `INLINE_MAX_WIDTH` / `INLINE_DEFAULT_WIDTH`
54
- * in `iframe-manager`). Ignored in fullscreen overlay mode (no container).
55
- */
56
- width?: number;
57
- /**
58
- * Fixed iframe height in pixels. Clamped by the SDK to a supported range
59
- * (see `INLINE_MIN_HEIGHT` / `INLINE_MAX_HEIGHT` / `INLINE_DEFAULT_HEIGHT`
60
- * in `iframe-manager`). Ignored in fullscreen overlay mode.
61
- */
62
- height?: number;
63
- onBooted?: () => void;
64
- onReady?: () => void;
65
- /**
66
- * Fires when the iframe posts `nvm:success`. The widget stays mounted in
67
- * its success state — the integrator dismisses it via `event.handle.close()`
68
- * when their own post-success flow is ready. There is no auto-dismiss.
69
- */
70
- onSuccess?: (event: WidgetSuccessEvent<CheckoutResult>) => void;
71
- onError?: (error: EmbedError) => void;
72
- /**
73
- * Fires when the iframe detects that the live host Privy session belongs
74
- * to a different account than the email the widget session was minted for.
75
- * The iframe stays mounted on a two-button prompt; the host can mirror that
76
- * affordance on its own UI. See `AuthMismatchDetail`.
77
- */
78
- onAuthMismatch?: (detail: AuthMismatchDetail) => void;
79
- /**
80
- * Fires when, on the mismatch prompt, the user picks "Continue as
81
- * <hostEmail>". The host should re-mint a widget session bound to
82
- * `requestedEmail` and reopen the widget. The iframe stays on the prompt
83
- * until then. See `AuthSwitchRequestDetail`.
84
- */
85
- onAuthSwitchRequest?: (detail: AuthSwitchRequestDetail) => void;
86
- onClose?: () => void;
87
- }
88
-
89
- export declare interface CheckoutResult {
90
- did: string;
91
- planId?: string;
92
- txHash?: string;
93
- }
94
-
95
- /**
96
- * Checkout widget.
97
- *
98
- * Lifecycle note for SDK consumers: when the iframe sends `nvm:close` the
99
- * widget instance auto-calls `destroy()` and becomes terminal — any
100
- * subsequent `start()` call throws. If the host page needs to re-show the
101
- * checkout after a close, construct a new `CheckoutWidget` (typically via
102
- * `nvm.checkout`) and call `start()` on the fresh instance.
103
- */
104
- export declare class CheckoutWidget {
105
- private readonly session;
106
- private readonly webappBase;
107
- private manager;
108
- private destroyed;
109
- constructor(session: SessionManager, webappBase: string);
110
- /**
111
- * Mounts the checkout iframe into `options.container`.
112
- * Throws if called after `destroy()` (including the implicit destroy on
113
- * `nvm:close` — see class JSDoc).
114
- */
115
- start(options: CheckoutOptions): void;
116
- /**
117
- * Mounts a plan-only checkout iframe (no agent DID required).
118
- * Throws if called after `destroy()` (including the implicit destroy on
119
- * `nvm:close` — see class JSDoc).
120
- */
121
- startPlan(options: PlanCheckoutOptions): void;
122
- destroy(): void;
123
- /**
124
- * Shared close path for `handle.close()` (integrator-driven) and
125
- * `nvm:close` (iframe-driven). Idempotent — multiple calls collapse to a
126
- * single `onClose` + destroy, which matters because `handle.close()`
127
- * could race with a `nvm:close` from the iframe if the integrator's
128
- * post-success UI happens to mount instantly.
129
- *
130
- * `manager` is the IframeManager this close was bound to when the handle
131
- * was minted. A stale handle from a previous mount (the instance was
132
- * remounted via a second `start()` without an intervening close) must NOT
133
- * tear down the now-live iframe, so we bail once it no longer owns
134
- * `this.manager`.
135
- *
136
- * Ordering is load-bearing: `destroy()` runs before `onClose()` so a
137
- * throwing `onClose` cannot leak a second close — `destroyed` is already
138
- * true by the time the callback runs.
139
- */
140
- private closeFromIframe;
141
- private buildSuccessHandle;
142
- private mount;
143
- private handleMessage;
144
- }
145
-
146
- export declare interface CreateDelegationOptions {
147
- paymentMethodId: string;
148
- container?: HTMLElement;
149
- /** See `CheckoutOptions.width`. */
150
- width?: number;
151
- /** See `CheckoutOptions.height`. */
152
- height?: number;
153
- onBooted?: () => void;
154
- onReady?: () => void;
155
- /** See `CheckoutOptions.onSuccess`. */
156
- onSuccess?: (event: WidgetSuccessEvent<CreateDelegationResult>) => void;
157
- onError?: (error: EmbedError) => void;
158
- /** See `CheckoutOptions.onAuthMismatch`. */
159
- onAuthMismatch?: (detail: AuthMismatchDetail) => void;
160
- /** See `CheckoutOptions.onAuthSwitchRequest`. */
161
- onAuthSwitchRequest?: (detail: AuthSwitchRequestDetail) => void;
162
- onClose?: () => void;
163
- }
164
-
165
- export declare interface CreateDelegationResult {
166
- delegationId: string;
167
- paymentMethodId: string;
168
- }
169
-
170
- export declare function createMessage<T>(type: WidgetMessageType, payload?: T): WidgetMessage<T>;
171
-
172
- /**
173
- * Card and delegation management widget.
174
- *
175
- * Surfaces three iframe-based flows (enrollment, listing, delegation creation)
176
- * and two SDK-direct revocations. The three iframe flows share the single
177
- * `manager` slot — calling any of them destroys the previously-mounted iframe
178
- * (same semantics as calling `enrollCard()` twice). Once any iframe is closed
179
- * by the user (`nvm:close`), the instance is implicitly destroyed and any
180
- * subsequent iframe call throws. Construct a fresh widget (via
181
- * `nvm.delegations`) to mount another flow after a close.
182
- *
183
- * The two `revoke*` methods do NOT use an iframe — they hit the
184
- * `/api/v1/widgets/...` endpoints directly with the widget session token.
185
- * They exist because the SDK consumer on the host page only holds the widget
186
- * session token; the apiKeyHash that gates the standard delegation/payment
187
- * endpoints never leaves the embedded iframe.
188
- */
189
- export declare class DelegationsWidget {
190
- private readonly session;
191
- private readonly webappBase;
192
- private readonly apiBase;
193
- private manager;
194
- private destroyed;
195
- constructor(session: SessionManager, webappBase: string, apiBase: string);
196
- /**
197
- * Mounts the enrollment iframe at `/embed/cards/enroll`.
198
- * Throws if called after `destroy()` (including the implicit destroy on
199
- * `nvm:close` — see class JSDoc).
200
- */
201
- enrollCard(options: EnrollCardOptions): void;
202
- /**
203
- * Mounts the cards-list iframe at `/embed/cards/list`. Per-row actions
204
- * ("Create Delegation" → `'delegate'`, "Remove Card" → `'revoked'`) are
205
- * forwarded via `onCardAction` so the host can react (mount a follow-up
206
- * widget, refresh its own list, etc.). See `CardAction`.
207
- */
208
- listCards(options: ListCardsOptions): void;
209
- /**
210
- * Mounts the delegation creation iframe at `/embed/cards/delegate` for a
211
- * specific payment method. The `paymentMethodId` is required and is passed
212
- * as a search param so the embed route can scope the form to that card.
213
- */
214
- createDelegation(options: CreateDelegationOptions): void;
215
- /**
216
- * Revoke (detach) a payment method via the widget-prefixed API endpoint.
217
- * Resolves on 2xx; throws `WidgetApiError` on any other response or
218
- * network failure.
219
- */
220
- revokeCard(paymentMethodId: string): Promise<void>;
221
- /**
222
- * Revoke a delegation via the widget-prefixed API endpoint.
223
- * Resolves on 2xx; throws `WidgetApiError` on any other response or
224
- * network failure.
225
- */
226
- revokeDelegation(delegationId: string): Promise<void>;
227
- destroy(): void;
228
- private assertAlive;
229
- private mountIframe;
230
- private postInitOnBooted;
231
- private handleEnrollMessage;
232
- private handleListMessage;
233
- private handleCreateDelegationMessage;
234
- /**
235
- * #1668: shared close path for `handle.close()` (integrator-driven) and
236
- * `nvm:close` (iframe-driven). Idempotent so a race between the
237
- * integrator dismissing the widget and the iframe emitting CLOSE
238
- * collapses to a single `onClose` + destroy. Generic over the three
239
- * options shapes — only `onClose` is referenced.
240
- *
241
- * `manager` is the IframeManager this close was bound to when the handle
242
- * was minted. The three iframe flows share the single `manager` slot, so a
243
- * stale handle from an earlier flow (e.g. an uncalled `enrollCard` success
244
- * handle held past a later `createDelegation`) must NOT tear down the
245
- * now-live iframe — we bail once it no longer owns `this.manager`.
246
- *
247
- * Ordering is load-bearing: `destroy()` runs before `onClose()` so a
248
- * throwing `onClose` cannot leak a second close — `destroyed` is already
249
- * true by the time the callback runs.
250
- */
251
- private closeFromIframe;
252
- private buildSuccessHandle;
253
- private deleteWithSession;
254
- }
255
-
256
- export declare interface EmbedError {
257
- code: 'UNAUTHORIZED' | 'NETWORK' | 'PAYMENT_NOT_CONFIRMED' | 'UNKNOWN';
258
- /**
259
- * Raw, host-facing message. Carries the underlying detail (e.g. the backend
260
- * `NVMException.message`) and is what the SDK forwards over the `nvm:error`
261
- * postMessage for the integrator to log. May contain operational/technical
262
- * text, so it is NOT safe to render in an end-user surface verbatim.
263
- */
264
- message: string;
265
- /**
266
- * Safe, user-facing message. Generic per-`code` copy with no operational
267
- * detail — render this (falling back to `message`) in any UI shown to the
268
- * end user, such as the widgets' terminal error panels. Optional and
269
- * additive: existing host integrations that only read `message` are
270
- * unaffected.
271
- */
272
- userMessage?: string;
273
- status?: number;
274
- apiCode?: string;
275
- }
276
-
277
- export declare interface EnrollCardOptions {
278
- container?: HTMLElement;
279
- /** See `CheckoutOptions.width`. */
280
- width?: number;
281
- /** See `CheckoutOptions.height`. */
282
- height?: number;
283
- /** See `EnrollCardProvider`. Defaults to `'stripe'`. */
284
- provider?: EnrollCardProvider;
285
- onBooted?: () => void;
286
- onReady?: () => void;
287
- /** See `CheckoutOptions.onSuccess`. */
288
- onSuccess?: (event: WidgetSuccessEvent<EnrollCardResult>) => void;
289
- onError?: (error: EmbedError) => void;
290
- /** See `CheckoutOptions.onAuthMismatch`. */
291
- onAuthMismatch?: (detail: AuthMismatchDetail) => void;
292
- /** See `CheckoutOptions.onAuthSwitchRequest`. */
293
- onAuthSwitchRequest?: (detail: AuthSwitchRequestDetail) => void;
294
- onClose?: () => void;
295
- }
296
-
297
- /**
298
- * #1668 sub-task 2: which tokenization flow renders inside the embedded
299
- * enrol-card iframe.
300
- *
301
- * - `'stripe'` (default): Stripe Elements + SetupIntent. The existing flow.
302
- * - `'braintree'`: Braintree Drop-in (PayPal vault).
303
- * - `'visa'`: Visa Agentic Tokens via VGS Collect → CMP. **Requires an
304
- * HTTPS parent page** — the Visa VTS iframe enforces
305
- * `frame-ancestors 'self' https:` so a non-HTTPS host (e.g. plain
306
- * `http://localhost`) cannot embed this provider.
307
- */
308
- export declare type EnrollCardProvider = 'stripe' | 'braintree' | 'visa';
309
-
310
- export declare interface EnrollCardResult {
311
- paymentMethodId: string;
312
- }
313
-
314
- export declare type Environment = (typeof ENVIRONMENTS)[number];
315
-
316
- declare const ENVIRONMENTS: readonly ["local", "sandbox", "live", "staging_sandbox", "staging_live"];
317
-
318
- declare type EventHandler<T> = (payload: T) => void;
319
-
320
- export declare class IframeManager {
321
- private expectedOrigin;
322
- private iframe;
323
- private messageHandlers;
324
- private protocolErrorHandlers;
325
- private messageListener;
326
- private destroyed;
327
- constructor(expectedOrigin: string);
328
- create(url: string, options?: IframeOptions): HTMLIFrameElement;
329
- destroy(): void;
330
- postMessage(msg: WidgetMessage): void;
331
- onMessage(handler: (msg: WidgetMessage) => void): () => void;
332
- onProtocolError(handler: (reason: string) => void): () => void;
333
- private ensureListener;
334
- }
335
-
336
- export declare interface IframeOptions {
337
- container?: HTMLElement;
338
- style?: Partial<CSSStyleDeclaration>;
339
- /**
340
- * Fixed CSS width for inline (container) mode. #1668: the widget renders
341
- * as a fixed-size box, like a Privy UI component, so the integrator can
342
- * place it predictably on their page. Clamped to
343
- * `[INLINE_MIN_WIDTH, INLINE_MAX_WIDTH]`. Default: `INLINE_DEFAULT_WIDTH`
344
- * — the constants are the single source of truth, so future re-tunings
345
- * don't require touching this JSDoc. Ignored in fullscreen overlay mode.
346
- */
347
- width?: number;
348
- /**
349
- * Fixed CSS height for inline mode. Clamped to
350
- * `[INLINE_MIN_HEIGHT, INLINE_MAX_HEIGHT]`. Default: `INLINE_DEFAULT_HEIGHT`.
351
- * The embed content uses responsive CSS to adapt to the dimensions the
352
- * integrator picks — within the clamped range — without distorting (no
353
- * CSS transform scale). Ignored in fullscreen overlay mode.
354
- */
355
- height?: number;
356
- }
357
-
358
- export declare interface ListCardsOptions {
359
- container?: HTMLElement;
360
- /** See `CheckoutOptions.width`. */
361
- width?: number;
362
- /** See `CheckoutOptions.height`. */
363
- height?: number;
364
- onBooted?: () => void;
365
- onReady?: () => void;
366
- onCardAction?: (action: CardAction) => void;
367
- onError?: (error: EmbedError) => void;
368
- /** See `CheckoutOptions.onAuthMismatch`. */
369
- onAuthMismatch?: (detail: AuthMismatchDetail) => void;
370
- /** See `CheckoutOptions.onAuthSwitchRequest`. */
371
- onAuthSwitchRequest?: (detail: AuthSwitchRequestDetail) => void;
372
- onClose?: () => void;
373
- }
374
-
375
- export declare class NeverminedWidgets {
376
- private readonly sessionManager;
377
- private readonly _account;
378
- private readonly environment;
379
- private _checkout;
380
- private _delegations;
381
- private readonly events;
382
- private constructor();
383
- static initialize(config: WidgetConfig): Promise<NeverminedWidgets>;
384
- private refreshSession;
385
- on<K extends keyof NeverminedWidgetsEvents>(event: K, handler: (payload: NeverminedWidgetsEvents[K]) => void): this;
386
- off<K extends keyof NeverminedWidgetsEvents>(event: K, handler: (payload: NeverminedWidgetsEvents[K]) => void): this;
387
- get account(): WidgetAccount;
388
- get hasValidSession(): boolean;
389
- getSessionToken(): string;
390
- get checkout(): CheckoutWidget;
391
- get delegations(): DelegationsWidget;
392
- /**
393
- * Resets the parent widget container: tears down any live child widget (e.g.
394
- * the checkout widget) and clears the internal cache. This is a reset, not a
395
- * terminal state — accessing `widget.checkout` after `destroy()` lazily
396
- * creates a fresh `CheckoutWidget` instance. If you need a terminal "this
397
- * widget can no longer be used" semantics, call `destroy()` on the child
398
- * widget directly (e.g. `widget.checkout.destroy()`), which flips its
399
- * internal `destroyed` flag and makes subsequent `start()` calls throw.
400
- */
401
- destroy(): void;
402
- }
403
-
404
- declare interface NeverminedWidgetsEvents {
405
- 'session-expired': void;
406
- }
407
-
408
- export declare function parseMessage(data: unknown): ParseResult;
409
-
410
- export declare type ParseResult<T = unknown> = {
411
- ok: true;
412
- message: WidgetMessage<T>;
413
- } | {
414
- ok: false;
415
- reason: string;
416
- };
417
-
418
- declare interface PlanCheckoutOptions {
419
- planId: string;
420
- container?: HTMLElement;
421
- width?: number;
422
- height?: number;
423
- onBooted?: () => void;
424
- onReady?: () => void;
425
- onSuccess?: (event: WidgetSuccessEvent<PlanCheckoutResult>) => void;
426
- onError?: (error: EmbedError) => void;
427
- onAuthMismatch?: (detail: AuthMismatchDetail) => void;
428
- onAuthSwitchRequest?: (detail: AuthSwitchRequestDetail) => void;
429
- onClose?: () => void;
430
- }
431
-
432
- declare interface PlanCheckoutResult {
433
- planId: string;
434
- txHash?: string;
435
- }
436
-
437
- export declare class SessionManager {
438
- private session;
439
- private expiresMs;
440
- private timer;
441
- constructor(session: WidgetSession);
442
- isValid(): boolean;
443
- getToken(): string;
444
- getSession(): WidgetSession;
445
- startAutoRefresh(refreshFn: () => Promise<WidgetSession>, onExpired: () => void): void;
446
- stopAutoRefresh(): void;
447
- }
448
-
449
- export declare class TypedEventEmitter<Events extends object> {
450
- private listeners;
451
- on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
452
- off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
453
- once<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
454
- removeAllListeners(event?: keyof Events): this;
455
- emit<K extends keyof Events>(event: K, payload: Events[K]): void;
456
- }
457
-
458
- declare const WIDGET_ERRORS: {
459
- readonly MISSING_SESSION: {
460
- readonly numericCode: "WDG.0001";
461
- readonly message: "session is required — pass the WidgetSession returned by createWidgetSession on the backend";
462
- };
463
- readonly INVALID_ENVIRONMENT: {
464
- readonly numericCode: "WDG.0002";
465
- readonly message: "environment must be one of: sandbox, live, staging_sandbox, staging_live, local";
466
- };
467
- readonly INVALID_SESSION: {
468
- readonly numericCode: "WDG.0003";
469
- readonly message: "session is missing required fields";
470
- };
471
- readonly SESSION_EXPIRED: {
472
- readonly numericCode: "WDG.0006";
473
- readonly message: "Widget session has expired";
474
- };
475
- };
476
-
477
- export declare const WIDGET_MESSAGE_VERSION: "1";
478
-
479
- export declare interface WidgetAccount {
480
- userId: string;
481
- userWallet: `0x${string}`;
482
- }
483
-
484
- /**
485
- * Thrown by SDK methods that hit the API directly (no iframe), e.g.
486
- * `delegations.revokeCard()` / `delegations.revokeDelegation()`. Carries the
487
- * HTTP status and the optional BCK error code so consumers can branch on
488
- * 401/403/etc. without parsing the message.
489
- */
490
- export declare class WidgetApiError extends Error {
491
- readonly status?: number | undefined;
492
- readonly apiCode?: string | undefined;
493
- constructor(message: string, status?: number | undefined, apiCode?: string | undefined);
494
- }
495
-
496
- export declare interface WidgetConfig {
497
- /**
498
- * Widget session minted server-to-server by the integrator backend
499
- * (typically via `@nevermined-io/ui-widgets-server.createWidgetSession`).
500
- * Forward the response object verbatim — the SDK never holds the widget
501
- * key `rawSecret`.
502
- */
503
- session: WidgetSession;
504
- environment: Environment;
505
- }
506
-
507
- declare type WidgetErrorCode = keyof typeof WIDGET_ERRORS;
508
-
509
- export declare class WidgetInitError extends Error {
510
- readonly code: WidgetErrorCode;
511
- constructor(code: WidgetErrorCode, message?: string, cause?: unknown);
512
- }
513
-
514
- export declare interface WidgetMessage<T = unknown> {
515
- type: WidgetMessageType;
516
- version: '1';
517
- payload?: T;
518
- }
519
-
520
- export declare enum WidgetMessageType {
521
- INIT = "nvm:init",
522
- CLOSE = "nvm:close",
523
- BOOTED = "nvm:booted",
524
- READY = "nvm:ready",
525
- RESIZE = "nvm:resize",
526
- SUCCESS = "nvm:success",
527
- ERROR = "nvm:error",
528
- CARD_ACTION = "nvm:card-action",
529
- AUTH_MISMATCH = "nvm:auth-mismatch",
530
- AUTH_SWITCH_REQUEST = "nvm:auth-switch-request"
531
- }
532
-
533
- export declare interface WidgetSession {
534
- sessionToken: string;
535
- userId: string;
536
- userWallet: `0x${string}`;
537
- /**
538
- * Hash of the NVM API key bound to this widget session user. Returned by
539
- * `POST /api/v1/widgets/session` so host pages that want to call user-scoped
540
- * endpoints directly (outside the iframe) have the bearer token to do so.
541
- * The embedded iframe flow consumes it via the session JWT claims rather
542
- * than this field.
543
- */
544
- apiKeyHash: string;
545
- expiresAt: string;
546
- }
547
-
548
- export declare class WidgetSessionExpiredError extends Error {
549
- readonly code: "SESSION_EXPIRED";
550
- constructor();
551
- }
552
-
553
- /**
554
- * Payload shape passed to every widget's `onSuccess` callback. `result`
555
- * is the per-widget data (paymentMethodId, delegationId, etc.); `handle`
556
- * lets the integrator dismiss the widget on their own schedule.
557
- */
558
- export declare interface WidgetSuccessEvent<T> {
559
- result: T;
560
- handle: WidgetSuccessHandle;
561
- }
562
-
563
- /**
564
- * Control surface passed to every widget's `onSuccess` callback (#1668
565
- * sub-tasks 3 + 4). The iframe stays mounted indefinitely after a
566
- * successful action so the integrator can show their own post-action UI
567
- * (toast, next-step prompt, etc.) while the success state remains visible
568
- * inside the widget. The integrator dismisses the widget by calling
569
- * `handle.close()` — which destroys the iframe and invokes `onClose` —
570
- * whenever their own flow is ready.
571
- */
572
- export declare interface WidgetSuccessHandle {
573
- /**
574
- * Destroys the iframe and invokes the widget's `onClose` callback.
575
- * Idempotent: calling close on an already-closed widget is a no-op.
576
- */
577
- close(): void;
578
- }
579
-
580
- export { }
1
+ export { NeverminedWidgets } from './nevermined-widgets.js';
2
+ export { SessionManager } from './session.js';
3
+ export { IframeManager } from './iframe-manager.js';
4
+ export { CheckoutWidget } from './widgets/checkout.js';
5
+ export { DelegationsWidget } from './widgets/delegations.js';
6
+ export { TypedEventEmitter } from './event-emitter.js';
7
+ export { WidgetMessageType, WIDGET_MESSAGE_VERSION, createMessage, parseMessage, } from './messages.js';
8
+ export { WidgetApiError, WidgetInitError, WidgetSessionExpiredError } from './utils/errors.js';
9
+ export type { WidgetConfig, WidgetSession, WidgetAccount, Environment, EmbedError, WidgetSuccessHandle, WidgetSuccessEvent, } from './types.js';
10
+ export type { IframeOptions } from './iframe-manager.js';
11
+ export type { CheckoutOptions, CheckoutResult } from './widgets/checkout.js';
12
+ export type { CardAction, CreateDelegationOptions, CreateDelegationResult, EnrollCardOptions, EnrollCardProvider, EnrollCardResult, ListCardsOptions, } from './widgets/delegations.js';
13
+ export type { WidgetMessage, ParseResult } from './messages.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,YAAY,GACb,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAC9F,YAAY,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,WAAW,EACX,UAAU,EACV,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"}