@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,156 @@
1
+ import { SessionManager } from '../session.js';
2
+ import type { EmbedError, WidgetSuccessEvent } from '../types.js';
3
+ export interface EnrollCardResult {
4
+ paymentMethodId: string;
5
+ }
6
+ /**
7
+ * #1668 sub-task 2: which tokenization flow renders inside the embedded
8
+ * enrol-card iframe.
9
+ *
10
+ * - `'stripe'` (default): Stripe Elements + SetupIntent. The existing flow.
11
+ * - `'braintree'`: Braintree Drop-in (PayPal vault).
12
+ * - `'visa'`: Visa Agentic Tokens via VGS Collect → CMP. **Requires an
13
+ * HTTPS parent page** — the Visa VTS iframe enforces
14
+ * `frame-ancestors 'self' https:` so a non-HTTPS host (e.g. plain
15
+ * `http://localhost`) cannot embed this provider.
16
+ */
17
+ export type EnrollCardProvider = 'stripe' | 'braintree' | 'visa';
18
+ export interface EnrollCardOptions {
19
+ container?: HTMLElement;
20
+ /** See `CheckoutOptions.width`. */
21
+ width?: number;
22
+ /** See `CheckoutOptions.height`. */
23
+ height?: number;
24
+ /** See `EnrollCardProvider`. Defaults to `'stripe'`. */
25
+ provider?: EnrollCardProvider;
26
+ onBooted?: () => void;
27
+ onReady?: () => void;
28
+ /** See `CheckoutOptions.onSuccess`. */
29
+ onSuccess?: (event: WidgetSuccessEvent<EnrollCardResult>) => void;
30
+ onError?: (error: EmbedError) => void;
31
+ onClose?: () => void;
32
+ }
33
+ export interface CardAction {
34
+ /**
35
+ * `delegate` — the user asked to create a delegation for this card (host
36
+ * should mount `createDelegation`). `revoked` — the user removed this card
37
+ * inline; the list iframe stays open so this is an intra-flow event, not
38
+ * flow completion (which is why it is NOT an `nvm:success`). See #1411.
39
+ */
40
+ action: 'delegate' | 'revoked';
41
+ paymentMethodId: string;
42
+ }
43
+ export interface ListCardsOptions {
44
+ container?: HTMLElement;
45
+ /** See `CheckoutOptions.width`. */
46
+ width?: number;
47
+ /** See `CheckoutOptions.height`. */
48
+ height?: number;
49
+ onBooted?: () => void;
50
+ onReady?: () => void;
51
+ onCardAction?: (action: CardAction) => void;
52
+ onError?: (error: EmbedError) => void;
53
+ onClose?: () => void;
54
+ }
55
+ export interface CreateDelegationResult {
56
+ delegationId: string;
57
+ paymentMethodId: string;
58
+ }
59
+ export interface CreateDelegationOptions {
60
+ paymentMethodId: string;
61
+ container?: HTMLElement;
62
+ /** See `CheckoutOptions.width`. */
63
+ width?: number;
64
+ /** See `CheckoutOptions.height`. */
65
+ height?: number;
66
+ onBooted?: () => void;
67
+ onReady?: () => void;
68
+ /** See `CheckoutOptions.onSuccess`. */
69
+ onSuccess?: (event: WidgetSuccessEvent<CreateDelegationResult>) => void;
70
+ onError?: (error: EmbedError) => void;
71
+ onClose?: () => void;
72
+ }
73
+ /**
74
+ * Card and delegation management widget.
75
+ *
76
+ * Surfaces three iframe-based flows (enrollment, listing, delegation creation)
77
+ * and two SDK-direct revocations. The three iframe flows share the single
78
+ * `manager` slot — calling any of them destroys the previously-mounted iframe
79
+ * (same semantics as calling `enrollCard()` twice). Once any iframe is closed
80
+ * by the user (`nvm:close`), the instance is implicitly destroyed and any
81
+ * subsequent iframe call throws. Construct a fresh widget (via
82
+ * `nvm.delegations`) to mount another flow after a close.
83
+ *
84
+ * The two `revoke*` methods do NOT use an iframe — they hit the
85
+ * `/api/v1/widgets/...` endpoints directly with the widget session token.
86
+ * They exist because the SDK consumer on the host page only holds the widget
87
+ * session token; the apiKeyHash that gates the standard delegation/payment
88
+ * endpoints never leaves the embedded iframe.
89
+ */
90
+ export declare class DelegationsWidget {
91
+ private readonly session;
92
+ private readonly webappBase;
93
+ private readonly apiBase;
94
+ private manager;
95
+ private destroyed;
96
+ constructor(session: SessionManager, webappBase: string, apiBase: string);
97
+ /**
98
+ * Mounts the enrollment iframe at `/embed/cards/enroll`.
99
+ * Throws if called after `destroy()` (including the implicit destroy on
100
+ * `nvm:close` — see class JSDoc).
101
+ */
102
+ enrollCard(options: EnrollCardOptions): void;
103
+ /**
104
+ * Mounts the cards-list iframe at `/embed/cards/list`. Per-row actions
105
+ * ("Create Delegation" → `'delegate'`, "Remove Card" → `'revoked'`) are
106
+ * forwarded via `onCardAction` so the host can react (mount a follow-up
107
+ * widget, refresh its own list, etc.). See `CardAction`.
108
+ */
109
+ listCards(options: ListCardsOptions): void;
110
+ /**
111
+ * Mounts the delegation creation iframe at `/embed/cards/delegate` for a
112
+ * specific payment method. The `paymentMethodId` is required and is passed
113
+ * as a search param so the embed route can scope the form to that card.
114
+ */
115
+ createDelegation(options: CreateDelegationOptions): void;
116
+ /**
117
+ * Revoke (detach) a payment method via the widget-prefixed API endpoint.
118
+ * Resolves on 2xx; throws `WidgetApiError` on any other response or
119
+ * network failure.
120
+ */
121
+ revokeCard(paymentMethodId: string): Promise<void>;
122
+ /**
123
+ * Revoke a delegation via the widget-prefixed API endpoint.
124
+ * Resolves on 2xx; throws `WidgetApiError` on any other response or
125
+ * network failure.
126
+ */
127
+ revokeDelegation(delegationId: string): Promise<void>;
128
+ destroy(): void;
129
+ private assertAlive;
130
+ private mountIframe;
131
+ private postInitOnBooted;
132
+ private handleEnrollMessage;
133
+ private handleListMessage;
134
+ private handleCreateDelegationMessage;
135
+ /**
136
+ * #1668: shared close path for `handle.close()` (integrator-driven) and
137
+ * `nvm:close` (iframe-driven). Idempotent so a race between the
138
+ * integrator dismissing the widget and the iframe emitting CLOSE
139
+ * collapses to a single `onClose` + destroy. Generic over the three
140
+ * options shapes — only `onClose` is referenced.
141
+ *
142
+ * `manager` is the IframeManager this close was bound to when the handle
143
+ * was minted. The three iframe flows share the single `manager` slot, so a
144
+ * stale handle from an earlier flow (e.g. an uncalled `enrollCard` success
145
+ * handle held past a later `createDelegation`) must NOT tear down the
146
+ * now-live iframe — we bail once it no longer owns `this.manager`.
147
+ *
148
+ * Ordering is load-bearing: `destroy()` runs before `onClose()` so a
149
+ * throwing `onClose` cannot leak a second close — `destroyed` is already
150
+ * true by the time the callback runs.
151
+ */
152
+ private closeFromIframe;
153
+ private buildSuccessHandle;
154
+ private deleteWithSession;
155
+ }
156
+ //# 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,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGjE,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAA;AAEhE,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,wDAAwD;IACxD,QAAQ,CAAC,EAAE,kBAAkB,CAAA;IAC7B,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,uCAAuC;IACvC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAA;IACjE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB;AAED,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,MAAM,EAAE,UAAU,GAAG,SAAS,CAAA;IAC9B,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,WAAW,CAAA;IACvB,mCAAmC;IACnC,KAAK,CA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;;;;OAIG;IACH,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAY5C;;;;;OAKG;IACH,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI;IAS1C;;;;OAIG;IACH,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI;IAgBxD;;;;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;IAuBnB,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,mBAAmB;IA4C3B,OAAO,CAAC,iBAAiB;IAgDzB,OAAO,CAAC,6BAA6B;IA4CrC;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,kBAAkB;YAMZ,iBAAiB;CAgChC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nevermined-io/ui-widgets",
3
- "version": "0.5.11",
3
+ "version": "0.5.13",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",