@nevermined-io/ui-widgets 0.4.6 → 0.5.1
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/event-emitter.d.ts +11 -0
- package/dist/event-emitter.d.ts.map +1 -0
- package/dist/iframe-manager.d.ts +21 -0
- package/dist/iframe-manager.d.ts.map +1 -0
- package/dist/index.d.ts +14 -345
- package/dist/index.d.ts.map +1 -0
- package/dist/messages.d.ts +26 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/nevermined-widgets.d.ts +36 -0
- package/dist/nevermined-widgets.d.ts.map +1 -0
- package/dist/session.d.ts +13 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/types.d.ts +31 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/environment.d.ts +4 -0
- package/dist/utils/environment.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +47 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/widgets/checkout.d.ts +42 -0
- package/dist/widgets/checkout.d.ts.map +1 -0
- package/dist/widgets/delegations.d.ts +103 -0
- package/dist/widgets/delegations.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -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,21 @@
|
|
|
1
|
+
import { type WidgetMessage } from './messages.js';
|
|
2
|
+
export interface IframeOptions {
|
|
3
|
+
container?: HTMLElement;
|
|
4
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
5
|
+
}
|
|
6
|
+
export declare class IframeManager {
|
|
7
|
+
private expectedOrigin;
|
|
8
|
+
private iframe;
|
|
9
|
+
private messageHandlers;
|
|
10
|
+
private protocolErrorHandlers;
|
|
11
|
+
private messageListener;
|
|
12
|
+
private destroyed;
|
|
13
|
+
constructor(expectedOrigin: string);
|
|
14
|
+
create(url: string, options?: IframeOptions): HTMLIFrameElement;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
postMessage(msg: WidgetMessage): void;
|
|
17
|
+
onMessage(handler: (msg: WidgetMessage) => void): () => void;
|
|
18
|
+
onProtocolError(handler: (reason: string) => void): () => void;
|
|
19
|
+
private ensureListener;
|
|
20
|
+
}
|
|
21
|
+
//# 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;CACrC;AAED,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;IA6B/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,345 +1,14 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
onClose?: () => void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export declare interface CheckoutResult {
|
|
19
|
-
did: string;
|
|
20
|
-
planId?: string;
|
|
21
|
-
txHash?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Checkout widget.
|
|
26
|
-
*
|
|
27
|
-
* Lifecycle note for SDK consumers: when the iframe sends `nvm:close` the
|
|
28
|
-
* widget instance auto-calls `destroy()` and becomes terminal — any
|
|
29
|
-
* subsequent `start()` call throws. If the host page needs to re-show the
|
|
30
|
-
* checkout after a close, construct a new `CheckoutWidget` (typically via
|
|
31
|
-
* `nvm.checkout`) and call `start()` on the fresh instance.
|
|
32
|
-
*/
|
|
33
|
-
export declare class CheckoutWidget {
|
|
34
|
-
private readonly session;
|
|
35
|
-
private readonly webappBase;
|
|
36
|
-
private manager;
|
|
37
|
-
private destroyed;
|
|
38
|
-
constructor(session: SessionManager, webappBase: string);
|
|
39
|
-
/**
|
|
40
|
-
* Mounts the checkout iframe into `options.container`.
|
|
41
|
-
* Throws if called after `destroy()` (including the implicit destroy on
|
|
42
|
-
* `nvm:close` — see class JSDoc).
|
|
43
|
-
*/
|
|
44
|
-
start(options: CheckoutOptions): void;
|
|
45
|
-
destroy(): void;
|
|
46
|
-
private handleMessage;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export declare interface CreateDelegationOptions {
|
|
50
|
-
paymentMethodId: string;
|
|
51
|
-
container?: HTMLElement;
|
|
52
|
-
onBooted?: () => void;
|
|
53
|
-
onReady?: () => void;
|
|
54
|
-
onSuccess?: (result: CreateDelegationResult) => void;
|
|
55
|
-
onError?: (error: EmbedError) => void;
|
|
56
|
-
onClose?: () => void;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export declare interface CreateDelegationResult {
|
|
60
|
-
delegationId: string;
|
|
61
|
-
paymentMethodId: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export declare function createMessage<T>(type: WidgetMessageType, payload?: T): WidgetMessage<T>;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Card and delegation management widget.
|
|
68
|
-
*
|
|
69
|
-
* Surfaces three iframe-based flows (enrollment, listing, delegation creation)
|
|
70
|
-
* and two SDK-direct revocations. The three iframe flows share the single
|
|
71
|
-
* `manager` slot — calling any of them destroys the previously-mounted iframe
|
|
72
|
-
* (same semantics as calling `enrollCard()` twice). Once any iframe is closed
|
|
73
|
-
* by the user (`nvm:close`), the instance is implicitly destroyed and any
|
|
74
|
-
* subsequent iframe call throws. Construct a fresh widget (via
|
|
75
|
-
* `nvm.delegations`) to mount another flow after a close.
|
|
76
|
-
*
|
|
77
|
-
* The two `revoke*` methods do NOT use an iframe — they hit the
|
|
78
|
-
* `/api/v1/widgets/...` endpoints directly with the widget session token.
|
|
79
|
-
* They exist because the SDK consumer on the host page only holds the widget
|
|
80
|
-
* session token; the apiKeyHash that gates the standard delegation/payment
|
|
81
|
-
* endpoints never leaves the embedded iframe.
|
|
82
|
-
*/
|
|
83
|
-
export declare class DelegationsWidget {
|
|
84
|
-
private readonly session;
|
|
85
|
-
private readonly webappBase;
|
|
86
|
-
private readonly apiBase;
|
|
87
|
-
private manager;
|
|
88
|
-
private destroyed;
|
|
89
|
-
constructor(session: SessionManager, webappBase: string, apiBase: string);
|
|
90
|
-
/**
|
|
91
|
-
* Mounts the enrollment iframe at `/embed/cards/enroll`.
|
|
92
|
-
* Throws if called after `destroy()` (including the implicit destroy on
|
|
93
|
-
* `nvm:close` — see class JSDoc).
|
|
94
|
-
*/
|
|
95
|
-
enrollCard(options: EnrollCardOptions): void;
|
|
96
|
-
/**
|
|
97
|
-
* Mounts the cards-list iframe at `/embed/cards/list`. Per-row actions
|
|
98
|
-
* (currently only "Create Delegation") are forwarded via `onCardAction` so
|
|
99
|
-
* the host can mount the appropriate follow-up widget.
|
|
100
|
-
*/
|
|
101
|
-
listCards(options: ListCardsOptions): void;
|
|
102
|
-
/**
|
|
103
|
-
* Mounts the delegation creation iframe at `/embed/cards/delegate` for a
|
|
104
|
-
* specific payment method. The `paymentMethodId` is required and is passed
|
|
105
|
-
* as a search param so the embed route can scope the form to that card.
|
|
106
|
-
*/
|
|
107
|
-
createDelegation(options: CreateDelegationOptions): void;
|
|
108
|
-
/**
|
|
109
|
-
* Revoke (detach) a payment method via the widget-prefixed API endpoint.
|
|
110
|
-
* Resolves on 2xx; throws `WidgetApiError` on any other response or
|
|
111
|
-
* network failure.
|
|
112
|
-
*/
|
|
113
|
-
revokeCard(paymentMethodId: string): Promise<void>;
|
|
114
|
-
/**
|
|
115
|
-
* Revoke a delegation via the widget-prefixed API endpoint.
|
|
116
|
-
* Resolves on 2xx; throws `WidgetApiError` on any other response or
|
|
117
|
-
* network failure.
|
|
118
|
-
*/
|
|
119
|
-
revokeDelegation(delegationId: string): Promise<void>;
|
|
120
|
-
destroy(): void;
|
|
121
|
-
private assertAlive;
|
|
122
|
-
private mountIframe;
|
|
123
|
-
private postInitOnBooted;
|
|
124
|
-
private handleEnrollMessage;
|
|
125
|
-
private handleListMessage;
|
|
126
|
-
private handleCreateDelegationMessage;
|
|
127
|
-
private deleteWithSession;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export declare interface EmbedError {
|
|
131
|
-
code: 'UNAUTHORIZED' | 'NETWORK' | 'PAYMENT_NOT_CONFIRMED' | 'UNKNOWN';
|
|
132
|
-
message: string;
|
|
133
|
-
status?: number;
|
|
134
|
-
apiCode?: string;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export declare interface EnrollCardOptions {
|
|
138
|
-
container?: HTMLElement;
|
|
139
|
-
onBooted?: () => void;
|
|
140
|
-
onReady?: () => void;
|
|
141
|
-
onSuccess?: (result: EnrollCardResult) => void;
|
|
142
|
-
onError?: (error: EmbedError) => void;
|
|
143
|
-
onClose?: () => void;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export declare interface EnrollCardResult {
|
|
147
|
-
paymentMethodId: string;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export declare type Environment = (typeof ENVIRONMENTS)[number];
|
|
151
|
-
|
|
152
|
-
declare const ENVIRONMENTS: readonly ["local", "sandbox", "live", "staging_sandbox", "staging_live"];
|
|
153
|
-
|
|
154
|
-
declare type EventHandler<T> = (payload: T) => void;
|
|
155
|
-
|
|
156
|
-
export declare class IframeManager {
|
|
157
|
-
private expectedOrigin;
|
|
158
|
-
private iframe;
|
|
159
|
-
private messageHandlers;
|
|
160
|
-
private protocolErrorHandlers;
|
|
161
|
-
private messageListener;
|
|
162
|
-
private destroyed;
|
|
163
|
-
constructor(expectedOrigin: string);
|
|
164
|
-
create(url: string, options?: IframeOptions): HTMLIFrameElement;
|
|
165
|
-
destroy(): void;
|
|
166
|
-
postMessage(msg: WidgetMessage): void;
|
|
167
|
-
onMessage(handler: (msg: WidgetMessage) => void): () => void;
|
|
168
|
-
onProtocolError(handler: (reason: string) => void): () => void;
|
|
169
|
-
private ensureListener;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export declare interface IframeOptions {
|
|
173
|
-
container?: HTMLElement;
|
|
174
|
-
style?: Partial<CSSStyleDeclaration>;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export declare interface ListCardsOptions {
|
|
178
|
-
container?: HTMLElement;
|
|
179
|
-
onBooted?: () => void;
|
|
180
|
-
onReady?: () => void;
|
|
181
|
-
onCardAction?: (action: CardAction) => void;
|
|
182
|
-
onError?: (error: EmbedError) => void;
|
|
183
|
-
onClose?: () => void;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export declare class NeverminedWidgets {
|
|
187
|
-
private readonly sessionManager;
|
|
188
|
-
private readonly _account;
|
|
189
|
-
private readonly environment;
|
|
190
|
-
private _checkout;
|
|
191
|
-
private _delegations;
|
|
192
|
-
private readonly events;
|
|
193
|
-
private constructor();
|
|
194
|
-
static initialize(config: WidgetConfig): Promise<NeverminedWidgets>;
|
|
195
|
-
private refreshSession;
|
|
196
|
-
on<K extends keyof NeverminedWidgetsEvents>(event: K, handler: (payload: NeverminedWidgetsEvents[K]) => void): this;
|
|
197
|
-
off<K extends keyof NeverminedWidgetsEvents>(event: K, handler: (payload: NeverminedWidgetsEvents[K]) => void): this;
|
|
198
|
-
get account(): WidgetAccount;
|
|
199
|
-
get hasValidSession(): boolean;
|
|
200
|
-
getSessionToken(): string;
|
|
201
|
-
get checkout(): CheckoutWidget;
|
|
202
|
-
get delegations(): DelegationsWidget;
|
|
203
|
-
/**
|
|
204
|
-
* Resets the parent widget container: tears down any live child widget (e.g.
|
|
205
|
-
* the checkout widget) and clears the internal cache. This is a reset, not a
|
|
206
|
-
* terminal state — accessing `widget.checkout` after `destroy()` lazily
|
|
207
|
-
* creates a fresh `CheckoutWidget` instance. If you need a terminal "this
|
|
208
|
-
* widget can no longer be used" semantics, call `destroy()` on the child
|
|
209
|
-
* widget directly (e.g. `widget.checkout.destroy()`), which flips its
|
|
210
|
-
* internal `destroyed` flag and makes subsequent `start()` calls throw.
|
|
211
|
-
*/
|
|
212
|
-
destroy(): void;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
declare interface NeverminedWidgetsEvents {
|
|
216
|
-
'session-expired': void;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export declare function parseMessage(data: unknown): ParseResult;
|
|
220
|
-
|
|
221
|
-
export declare type ParseResult<T = unknown> = {
|
|
222
|
-
ok: true;
|
|
223
|
-
message: WidgetMessage<T>;
|
|
224
|
-
} | {
|
|
225
|
-
ok: false;
|
|
226
|
-
reason: string;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
export declare class SessionManager {
|
|
230
|
-
private session;
|
|
231
|
-
private expiresMs;
|
|
232
|
-
private timer;
|
|
233
|
-
constructor(session: WidgetSession);
|
|
234
|
-
isValid(): boolean;
|
|
235
|
-
getToken(): string;
|
|
236
|
-
getSession(): WidgetSession;
|
|
237
|
-
startAutoRefresh(refreshFn: () => Promise<WidgetSession>, onExpired: () => void): void;
|
|
238
|
-
stopAutoRefresh(): void;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
export declare class TypedEventEmitter<Events extends object> {
|
|
242
|
-
private listeners;
|
|
243
|
-
on<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
|
|
244
|
-
off<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
|
|
245
|
-
once<K extends keyof Events>(event: K, handler: EventHandler<Events[K]>): this;
|
|
246
|
-
removeAllListeners(event?: keyof Events): this;
|
|
247
|
-
emit<K extends keyof Events>(event: K, payload: Events[K]): void;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
declare const WIDGET_ERRORS: {
|
|
251
|
-
readonly MISSING_INIT_TOKEN: {
|
|
252
|
-
readonly numericCode: "WDG.0001";
|
|
253
|
-
readonly message: "initToken is required and must be a non-empty string";
|
|
254
|
-
};
|
|
255
|
-
readonly INVALID_ENVIRONMENT: {
|
|
256
|
-
readonly numericCode: "WDG.0002";
|
|
257
|
-
readonly message: "environment must be one of: sandbox, live, staging_sandbox, staging_live, local";
|
|
258
|
-
};
|
|
259
|
-
readonly INVALID_INIT_TOKEN: {
|
|
260
|
-
readonly numericCode: "WDG.0003";
|
|
261
|
-
readonly message: "Init token is invalid or expired";
|
|
262
|
-
};
|
|
263
|
-
readonly INVALID_RESPONSE: {
|
|
264
|
-
readonly numericCode: "WDG.0004";
|
|
265
|
-
readonly message: "Server response is missing required fields";
|
|
266
|
-
};
|
|
267
|
-
readonly NETWORK_ERROR: {
|
|
268
|
-
readonly numericCode: "WDG.0005";
|
|
269
|
-
readonly message: "Network request failed";
|
|
270
|
-
};
|
|
271
|
-
readonly SESSION_EXPIRED: {
|
|
272
|
-
readonly numericCode: "WDG.0006";
|
|
273
|
-
readonly message: "Widget session has expired";
|
|
274
|
-
};
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
export declare const WIDGET_MESSAGE_VERSION: "1";
|
|
278
|
-
|
|
279
|
-
export declare interface WidgetAccount {
|
|
280
|
-
userId: string;
|
|
281
|
-
userWallet: `0x${string}`;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Thrown by SDK methods that hit the API directly (no iframe), e.g.
|
|
286
|
-
* `delegations.revokeCard()` / `delegations.revokeDelegation()`. Carries the
|
|
287
|
-
* HTTP status and the optional BCK error code so consumers can branch on
|
|
288
|
-
* 401/403/etc. without parsing the message.
|
|
289
|
-
*/
|
|
290
|
-
export declare class WidgetApiError extends Error {
|
|
291
|
-
readonly status?: number | undefined;
|
|
292
|
-
readonly apiCode?: string | undefined;
|
|
293
|
-
constructor(message: string, status?: number | undefined, apiCode?: string | undefined);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
export declare interface WidgetConfig {
|
|
297
|
-
initToken: string;
|
|
298
|
-
environment: Environment;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
declare type WidgetErrorCode = keyof typeof WIDGET_ERRORS;
|
|
302
|
-
|
|
303
|
-
export declare class WidgetInitError extends Error {
|
|
304
|
-
readonly code: WidgetErrorCode;
|
|
305
|
-
constructor(code: WidgetErrorCode, message?: string, cause?: unknown);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
export declare interface WidgetMessage<T = unknown> {
|
|
309
|
-
type: WidgetMessageType;
|
|
310
|
-
version: '1';
|
|
311
|
-
payload?: T;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
export declare enum WidgetMessageType {
|
|
315
|
-
INIT = "nvm:init",
|
|
316
|
-
CLOSE = "nvm:close",
|
|
317
|
-
BOOTED = "nvm:booted",
|
|
318
|
-
READY = "nvm:ready",
|
|
319
|
-
RESIZE = "nvm:resize",
|
|
320
|
-
SUCCESS = "nvm:success",
|
|
321
|
-
ERROR = "nvm:error",
|
|
322
|
-
CARD_ACTION = "nvm:card-action"
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export declare interface WidgetSession {
|
|
326
|
-
sessionToken: string;
|
|
327
|
-
userId: string;
|
|
328
|
-
userWallet: `0x${string}`;
|
|
329
|
-
/**
|
|
330
|
-
* Hash of the NVM API key bound to this widget session user. Returned by
|
|
331
|
-
* `POST /api/v1/widgets/session` so host pages that want to call user-scoped
|
|
332
|
-
* endpoints directly (outside the iframe) have the bearer token to do so.
|
|
333
|
-
* The embedded iframe flow consumes it via the session JWT claims rather
|
|
334
|
-
* than this field.
|
|
335
|
-
*/
|
|
336
|
-
apiKeyHash: string;
|
|
337
|
-
expiresAt: string;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export declare class WidgetSessionExpiredError extends Error {
|
|
341
|
-
readonly code: "SESSION_EXPIRED";
|
|
342
|
-
constructor();
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
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, } 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, 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,GACX,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,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,0BAA0B,CAAA;AACjC,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|
|
11
|
+
export interface WidgetMessage<T = unknown> {
|
|
12
|
+
type: WidgetMessageType;
|
|
13
|
+
version: '1';
|
|
14
|
+
payload?: T;
|
|
15
|
+
}
|
|
16
|
+
export declare const WIDGET_MESSAGE_VERSION: "1";
|
|
17
|
+
export declare function createMessage<T>(type: WidgetMessageType, payload?: T): WidgetMessage<T>;
|
|
18
|
+
export type ParseResult<T = unknown> = {
|
|
19
|
+
ok: true;
|
|
20
|
+
message: WidgetMessage<T>;
|
|
21
|
+
} | {
|
|
22
|
+
ok: false;
|
|
23
|
+
reason: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function parseMessage(data: unknown): ParseResult;
|
|
26
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;CAChC;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"}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;YA+C3D,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
initToken: string;
|
|
5
|
+
environment: Environment;
|
|
6
|
+
}
|
|
7
|
+
export interface WidgetSession {
|
|
8
|
+
sessionToken: string;
|
|
9
|
+
userId: string;
|
|
10
|
+
userWallet: `0x${string}`;
|
|
11
|
+
/**
|
|
12
|
+
* Hash of the NVM API key bound to this widget session user. Returned by
|
|
13
|
+
* `POST /api/v1/widgets/session` so host pages that want to call user-scoped
|
|
14
|
+
* endpoints directly (outside the iframe) have the bearer token to do so.
|
|
15
|
+
* The embedded iframe flow consumes it via the session JWT claims rather
|
|
16
|
+
* than this field.
|
|
17
|
+
*/
|
|
18
|
+
apiKeyHash: string;
|
|
19
|
+
expiresAt: string;
|
|
20
|
+
}
|
|
21
|
+
export interface WidgetAccount {
|
|
22
|
+
userId: string;
|
|
23
|
+
userWallet: `0x${string}`;
|
|
24
|
+
}
|
|
25
|
+
export interface EmbedError {
|
|
26
|
+
code: 'UNAUTHORIZED' | 'NETWORK' | 'PAYMENT_NOT_CONFIRMED' | 'UNKNOWN';
|
|
27
|
+
message: string;
|
|
28
|
+
status?: number;
|
|
29
|
+
apiCode?: string;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,0EAA2E,CAAA;AACpG,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAEvD,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,WAAW,CAAA;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,KAAK,MAAM,EAAE,CAAA;IACzB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,KAAK,MAAM,EAAE,CAAA;CAC1B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,cAAc,GAAG,SAAS,GAAG,uBAAuB,GAAG,SAAS,CAAA;IACtE,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare const WIDGET_ERRORS: {
|
|
2
|
+
readonly MISSING_INIT_TOKEN: {
|
|
3
|
+
readonly numericCode: "WDG.0001";
|
|
4
|
+
readonly message: "initToken is required and must be a non-empty string";
|
|
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_INIT_TOKEN: {
|
|
11
|
+
readonly numericCode: "WDG.0003";
|
|
12
|
+
readonly message: "Init token is invalid or expired";
|
|
13
|
+
};
|
|
14
|
+
readonly INVALID_RESPONSE: {
|
|
15
|
+
readonly numericCode: "WDG.0004";
|
|
16
|
+
readonly message: "Server response is missing required fields";
|
|
17
|
+
};
|
|
18
|
+
readonly NETWORK_ERROR: {
|
|
19
|
+
readonly numericCode: "WDG.0005";
|
|
20
|
+
readonly message: "Network request failed";
|
|
21
|
+
};
|
|
22
|
+
readonly SESSION_EXPIRED: {
|
|
23
|
+
readonly numericCode: "WDG.0006";
|
|
24
|
+
readonly message: "Widget session has expired";
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export type WidgetErrorCode = keyof typeof WIDGET_ERRORS;
|
|
28
|
+
export declare class WidgetInitError extends Error {
|
|
29
|
+
readonly code: WidgetErrorCode;
|
|
30
|
+
constructor(code: WidgetErrorCode, message?: string, cause?: unknown);
|
|
31
|
+
}
|
|
32
|
+
export declare class WidgetSessionExpiredError extends Error {
|
|
33
|
+
readonly code: "SESSION_EXPIRED";
|
|
34
|
+
constructor();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Thrown by SDK methods that hit the API directly (no iframe), e.g.
|
|
38
|
+
* `delegations.revokeCard()` / `delegations.revokeDelegation()`. Carries the
|
|
39
|
+
* HTTP status and the optional BCK error code so consumers can branch on
|
|
40
|
+
* 401/403/etc. without parsing the message.
|
|
41
|
+
*/
|
|
42
|
+
export declare class WidgetApiError extends Error {
|
|
43
|
+
readonly status?: number | undefined;
|
|
44
|
+
readonly apiCode?: string | undefined;
|
|
45
|
+
constructor(message: string, status?: number | undefined, apiCode?: string | undefined);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;CAgBmD,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"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SessionManager } from '../session.js';
|
|
2
|
+
import type { EmbedError } from '../types.js';
|
|
3
|
+
export interface CheckoutResult {
|
|
4
|
+
did: string;
|
|
5
|
+
planId?: string;
|
|
6
|
+
txHash?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CheckoutOptions {
|
|
9
|
+
did: string;
|
|
10
|
+
planId?: string;
|
|
11
|
+
container?: HTMLElement;
|
|
12
|
+
onBooted?: () => void;
|
|
13
|
+
onReady?: () => void;
|
|
14
|
+
onSuccess?: (result: CheckoutResult) => void;
|
|
15
|
+
onError?: (error: EmbedError) => void;
|
|
16
|
+
onClose?: () => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checkout widget.
|
|
20
|
+
*
|
|
21
|
+
* Lifecycle note for SDK consumers: when the iframe sends `nvm:close` the
|
|
22
|
+
* widget instance auto-calls `destroy()` and becomes terminal — any
|
|
23
|
+
* subsequent `start()` call throws. If the host page needs to re-show the
|
|
24
|
+
* checkout after a close, construct a new `CheckoutWidget` (typically via
|
|
25
|
+
* `nvm.checkout`) and call `start()` on the fresh instance.
|
|
26
|
+
*/
|
|
27
|
+
export declare class CheckoutWidget {
|
|
28
|
+
private readonly session;
|
|
29
|
+
private readonly webappBase;
|
|
30
|
+
private manager;
|
|
31
|
+
private destroyed;
|
|
32
|
+
constructor(session: SessionManager, webappBase: string);
|
|
33
|
+
/**
|
|
34
|
+
* Mounts the checkout iframe into `options.container`.
|
|
35
|
+
* Throws if called after `destroy()` (including the implicit destroy on
|
|
36
|
+
* `nvm:close` — see class JSDoc).
|
|
37
|
+
*/
|
|
38
|
+
start(options: CheckoutOptions): void;
|
|
39
|
+
destroy(): void;
|
|
40
|
+
private handleMessage;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=checkout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/widgets/checkout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAA;IAC5C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB;AAID;;;;;;;;GAQG;AACH,qBAAa,cAAc;IAKvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAL7B,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,SAAS,CAAQ;gBAGN,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,MAAM;IAGrC;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAwBrC,OAAO,IAAI,IAAI;IAMf,OAAO,CAAC,aAAa;CAsCtB"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { SessionManager } from '../session.js';
|
|
2
|
+
import type { EmbedError } from '../types.js';
|
|
3
|
+
export interface EnrollCardResult {
|
|
4
|
+
paymentMethodId: string;
|
|
5
|
+
}
|
|
6
|
+
export interface EnrollCardOptions {
|
|
7
|
+
container?: HTMLElement;
|
|
8
|
+
onBooted?: () => void;
|
|
9
|
+
onReady?: () => void;
|
|
10
|
+
onSuccess?: (result: EnrollCardResult) => void;
|
|
11
|
+
onError?: (error: EmbedError) => void;
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
}
|
|
14
|
+
export interface CardAction {
|
|
15
|
+
/** Currently the only emitted action; reserved as a discriminator for future ones. */
|
|
16
|
+
action: 'delegate';
|
|
17
|
+
paymentMethodId: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ListCardsOptions {
|
|
20
|
+
container?: HTMLElement;
|
|
21
|
+
onBooted?: () => void;
|
|
22
|
+
onReady?: () => void;
|
|
23
|
+
onCardAction?: (action: CardAction) => void;
|
|
24
|
+
onError?: (error: EmbedError) => void;
|
|
25
|
+
onClose?: () => void;
|
|
26
|
+
}
|
|
27
|
+
export interface CreateDelegationResult {
|
|
28
|
+
delegationId: string;
|
|
29
|
+
paymentMethodId: string;
|
|
30
|
+
}
|
|
31
|
+
export interface CreateDelegationOptions {
|
|
32
|
+
paymentMethodId: string;
|
|
33
|
+
container?: HTMLElement;
|
|
34
|
+
onBooted?: () => void;
|
|
35
|
+
onReady?: () => void;
|
|
36
|
+
onSuccess?: (result: CreateDelegationResult) => void;
|
|
37
|
+
onError?: (error: EmbedError) => void;
|
|
38
|
+
onClose?: () => void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Card and delegation management widget.
|
|
42
|
+
*
|
|
43
|
+
* Surfaces three iframe-based flows (enrollment, listing, delegation creation)
|
|
44
|
+
* and two SDK-direct revocations. The three iframe flows share the single
|
|
45
|
+
* `manager` slot — calling any of them destroys the previously-mounted iframe
|
|
46
|
+
* (same semantics as calling `enrollCard()` twice). Once any iframe is closed
|
|
47
|
+
* by the user (`nvm:close`), the instance is implicitly destroyed and any
|
|
48
|
+
* subsequent iframe call throws. Construct a fresh widget (via
|
|
49
|
+
* `nvm.delegations`) to mount another flow after a close.
|
|
50
|
+
*
|
|
51
|
+
* The two `revoke*` methods do NOT use an iframe — they hit the
|
|
52
|
+
* `/api/v1/widgets/...` endpoints directly with the widget session token.
|
|
53
|
+
* They exist because the SDK consumer on the host page only holds the widget
|
|
54
|
+
* session token; the apiKeyHash that gates the standard delegation/payment
|
|
55
|
+
* endpoints never leaves the embedded iframe.
|
|
56
|
+
*/
|
|
57
|
+
export declare class DelegationsWidget {
|
|
58
|
+
private readonly session;
|
|
59
|
+
private readonly webappBase;
|
|
60
|
+
private readonly apiBase;
|
|
61
|
+
private manager;
|
|
62
|
+
private destroyed;
|
|
63
|
+
constructor(session: SessionManager, webappBase: string, apiBase: string);
|
|
64
|
+
/**
|
|
65
|
+
* Mounts the enrollment iframe at `/embed/cards/enroll`.
|
|
66
|
+
* Throws if called after `destroy()` (including the implicit destroy on
|
|
67
|
+
* `nvm:close` — see class JSDoc).
|
|
68
|
+
*/
|
|
69
|
+
enrollCard(options: EnrollCardOptions): void;
|
|
70
|
+
/**
|
|
71
|
+
* Mounts the cards-list iframe at `/embed/cards/list`. Per-row actions
|
|
72
|
+
* (currently only "Create Delegation") are forwarded via `onCardAction` so
|
|
73
|
+
* the host can mount the appropriate follow-up widget.
|
|
74
|
+
*/
|
|
75
|
+
listCards(options: ListCardsOptions): void;
|
|
76
|
+
/**
|
|
77
|
+
* Mounts the delegation creation iframe at `/embed/cards/delegate` for a
|
|
78
|
+
* specific payment method. The `paymentMethodId` is required and is passed
|
|
79
|
+
* as a search param so the embed route can scope the form to that card.
|
|
80
|
+
*/
|
|
81
|
+
createDelegation(options: CreateDelegationOptions): void;
|
|
82
|
+
/**
|
|
83
|
+
* Revoke (detach) a payment method via the widget-prefixed API endpoint.
|
|
84
|
+
* Resolves on 2xx; throws `WidgetApiError` on any other response or
|
|
85
|
+
* network failure.
|
|
86
|
+
*/
|
|
87
|
+
revokeCard(paymentMethodId: string): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Revoke a delegation via the widget-prefixed API endpoint.
|
|
90
|
+
* Resolves on 2xx; throws `WidgetApiError` on any other response or
|
|
91
|
+
* network failure.
|
|
92
|
+
*/
|
|
93
|
+
revokeDelegation(delegationId: string): Promise<void>;
|
|
94
|
+
destroy(): void;
|
|
95
|
+
private assertAlive;
|
|
96
|
+
private mountIframe;
|
|
97
|
+
private postInitOnBooted;
|
|
98
|
+
private handleEnrollMessage;
|
|
99
|
+
private handleListMessage;
|
|
100
|
+
private handleCreateDelegationMessage;
|
|
101
|
+
private deleteWithSession;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=delegations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegations.d.ts","sourceRoot":"","sources":["../../src/widgets/delegations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAA;IAC9C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,sFAAsF;IACtF,MAAM,EAAE,UAAU,CAAA;IAClB,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAA;IAC3C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,eAAe,EAAE,MAAM,CAAA;IACvB,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI,CAAA;IACpD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB;AAYD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,iBAAiB;IAK1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAN1B,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,SAAS,CAAQ;gBAGN,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM;IAGlC;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAM5C;;;;OAIG;IACH,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAM1C;;;;OAIG;IACH,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI;IAWxD;;;;OAIG;IACG,UAAU,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxD;;;;OAIG;IACG,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3D,OAAO,IAAI,IAAI;IAMf,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,WAAW;IAsBnB,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,mBAAmB;IAsC3B,OAAO,CAAC,iBAAiB;IA6CzB,OAAO,CAAC,6BAA6B;YAyCvB,iBAAiB;CAgChC"}
|