@nium/nium-sdk 0.1.10 → 0.1.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.d.mts +137 -60
- package/dist/index.d.ts +137 -60
- package/dist/index.js +229 -151
- package/dist/index.mjs +229 -151
- package/package.json +8 -8
package/dist/index.d.mts
CHANGED
|
@@ -1,27 +1,47 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Public type definitions for `@nium/nium-sdk`.
|
|
3
|
+
*
|
|
4
|
+
* These types are intentionally framework-agnostic. They describe the shape of
|
|
5
|
+
* configuration accepted by {@link init} and {@link createElement}, the events
|
|
6
|
+
* emitted by a mounted element, and the postMessage contract with the hosted
|
|
7
|
+
* form.
|
|
8
|
+
*
|
|
9
|
+
* Any change here is a public API change — keep it additive where possible.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A "loose autocomplete" string union: editors will suggest the listed
|
|
13
|
+
* literals while still accepting any other string. Prefer this over a bare
|
|
14
|
+
* `Literal | string` union, which collapses to `string` and loses intellisense
|
|
15
|
+
* (and trips `sonarjs/S6571`).
|
|
16
|
+
*/
|
|
17
|
+
type LooseStringUnion<T extends string> = T | (string & Record<never, never>);
|
|
18
|
+
/** Target environment for the hosted onboarding form. */
|
|
19
|
+
type NiumEnv = 'local' | 'qa' | 'preprod' | 'sandbox' | 'production';
|
|
20
|
+
/** Supported module types. Each maps to a dedicated route inside web-onboard. */
|
|
4
21
|
type NiumElementType = 'payment' | 'tax' | 'identity' | 'full';
|
|
5
|
-
/** Configuration
|
|
22
|
+
/** Configuration accepted by the top-level `init()` call. */
|
|
6
23
|
interface NiumInitOptions {
|
|
7
|
-
/** Target environment */
|
|
24
|
+
/** Target environment; determines the default hosted form URL. */
|
|
8
25
|
env: NiumEnv;
|
|
9
|
-
/**
|
|
26
|
+
/** BCP-47 locale code (for example `en`, `en-GB`, `es`). Defaults to `en`. */
|
|
10
27
|
locale?: string;
|
|
11
|
-
/** Override the hosted form base URL
|
|
28
|
+
/** Override the hosted form base URL. Primarily for local development. */
|
|
12
29
|
hostedFormUrl?: string;
|
|
13
|
-
/**
|
|
30
|
+
/** Short-lived authorization code obtained from NIAM via OAuth 2.1 / PKCE. */
|
|
14
31
|
authCode?: string;
|
|
15
|
-
/** PKCE code verifier
|
|
32
|
+
/** PKCE code verifier that matches the code challenge used to obtain `authCode`. */
|
|
16
33
|
codeVerifier?: string;
|
|
17
|
-
/**
|
|
34
|
+
/** Identifier of the customer the form is being rendered for. */
|
|
18
35
|
customerHashId?: string;
|
|
19
|
-
/**
|
|
36
|
+
/** NIUM client identifier. */
|
|
20
37
|
clientId?: string;
|
|
21
|
-
/** Pre-exchanged session token
|
|
38
|
+
/** Pre-exchanged session token. When present, `authCode`/`codeVerifier` are bypassed. */
|
|
22
39
|
sessionToken?: string;
|
|
23
40
|
}
|
|
24
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Theme overrides applied to the embedded form. Every property is optional;
|
|
43
|
+
* unspecified values fall back to the form's default design tokens.
|
|
44
|
+
*/
|
|
25
45
|
interface NiumTheme {
|
|
26
46
|
borderRadius?: string;
|
|
27
47
|
fontFamily?: string;
|
|
@@ -35,23 +55,24 @@ interface NiumTheme {
|
|
|
35
55
|
labelBackgroundColor?: string;
|
|
36
56
|
radioColor?: string;
|
|
37
57
|
}
|
|
38
|
-
/** Per-field UI customization
|
|
58
|
+
/** Per-field UI customization for the beneficiary form. */
|
|
39
59
|
interface NiumFieldCustomization {
|
|
40
60
|
hidden?: boolean;
|
|
41
61
|
disabled?: boolean;
|
|
42
62
|
}
|
|
43
|
-
/** Per-section UI customization
|
|
63
|
+
/** Per-section UI customization for the beneficiary form. */
|
|
44
64
|
interface NiumSectionCustomization {
|
|
45
65
|
hidden?: boolean;
|
|
46
66
|
}
|
|
47
|
-
/**
|
|
48
|
-
type NiumBeneficiaryFieldPath = 'name' | 'entityType' | 'line1' | 'line2' | 'city' | 'state' | 'postalCode' | 'countryCode' | 'communicationPreference' | 'contactNumber' | 'email' | 'termsCheckbox' | 'helperText'
|
|
49
|
-
|
|
50
|
-
type
|
|
51
|
-
type
|
|
52
|
-
|
|
67
|
+
/** Known field paths on the beneficiary form; additional paths are accepted. */
|
|
68
|
+
type NiumBeneficiaryFieldPath = LooseStringUnion<'name' | 'entityType' | 'line1' | 'line2' | 'city' | 'state' | 'postalCode' | 'countryCode' | 'communicationPreference' | 'contactNumber' | 'email' | 'termsCheckbox' | 'helperText'>;
|
|
69
|
+
/** Known section paths on the beneficiary form; additional paths are accepted. */
|
|
70
|
+
type NiumBeneficiarySectionPath = LooseStringUnion<'demographicInfo' | 'communicationPreferences' | 'accountType' | 'bankAccountDetails'>;
|
|
71
|
+
type NiumBeneficiaryFieldCustomizations = Partial<Record<NiumBeneficiaryFieldPath, NiumFieldCustomization>>;
|
|
72
|
+
type NiumBeneficiarySectionCustomizations = Partial<Record<NiumBeneficiarySectionPath, NiumSectionCustomization>>;
|
|
73
|
+
/** Intent driving how the payment form behaves on submit. */
|
|
53
74
|
type NiumPaymentIntent = 'create_beneficiary' | 'return_payload' | 'update_beneficiary';
|
|
54
|
-
/** Prefill
|
|
75
|
+
/** Prefill payload for the payment (beneficiary) form. */
|
|
55
76
|
interface NiumPaymentPrefill {
|
|
56
77
|
name?: string;
|
|
57
78
|
email?: string;
|
|
@@ -66,23 +87,27 @@ interface NiumPaymentPrefill {
|
|
|
66
87
|
countryCode?: string;
|
|
67
88
|
};
|
|
68
89
|
}
|
|
69
|
-
/** Options
|
|
90
|
+
/** Options accepted by {@link createElement}. */
|
|
70
91
|
interface NiumElementOptions {
|
|
71
|
-
/** Customer
|
|
92
|
+
/** Customer identifier. Required. */
|
|
72
93
|
customerHashId?: string;
|
|
73
|
-
/**
|
|
94
|
+
/** Initial values for the form. Ignored for `update_beneficiary`. */
|
|
74
95
|
prefill?: NiumPaymentPrefill;
|
|
75
|
-
/**
|
|
96
|
+
/** Visual theme overrides. */
|
|
76
97
|
theme?: NiumTheme;
|
|
77
|
-
/**
|
|
98
|
+
/** Behaviour of the submit action. Required. */
|
|
78
99
|
intent?: NiumPaymentIntent;
|
|
79
|
-
/** Beneficiary
|
|
100
|
+
/** Beneficiary identifier. Required when `intent === 'update_beneficiary'`. */
|
|
80
101
|
beneficiaryHashId?: string;
|
|
81
|
-
/**
|
|
102
|
+
/** Iframe sizing and field/section visibility. */
|
|
82
103
|
customizations?: {
|
|
104
|
+
/** Minimum iframe height in pixels. Default: 400. */
|
|
83
105
|
minHeight?: number;
|
|
106
|
+
/** Maximum iframe height in pixels. Default: 804. */
|
|
84
107
|
maxHeight?: number;
|
|
108
|
+
/** Per-field visibility/disabled overrides. */
|
|
85
109
|
fields?: NiumBeneficiaryFieldCustomizations;
|
|
110
|
+
/** Per-section visibility overrides. */
|
|
86
111
|
sections?: NiumBeneficiarySectionCustomizations;
|
|
87
112
|
};
|
|
88
113
|
}
|
|
@@ -97,6 +122,7 @@ interface NiumChangeEvent {
|
|
|
97
122
|
type: 'change';
|
|
98
123
|
data: Record<string, unknown>;
|
|
99
124
|
}
|
|
125
|
+
/** Opaque result payload returned by the hosted form on successful submit. */
|
|
100
126
|
type NiumSubmitResult = Record<string, unknown>;
|
|
101
127
|
interface NiumSubmitEvent {
|
|
102
128
|
type: 'submit';
|
|
@@ -113,7 +139,7 @@ interface NiumCancelEvent {
|
|
|
113
139
|
type: 'cancel';
|
|
114
140
|
}
|
|
115
141
|
type NiumEvent = NiumReadyEvent | NiumResizeEvent | NiumChangeEvent | NiumSubmitEvent | NiumErrorEvent | NiumCancelEvent;
|
|
116
|
-
/**
|
|
142
|
+
/** Event name → event payload map. */
|
|
117
143
|
interface NiumEventMap {
|
|
118
144
|
ready: NiumReadyEvent;
|
|
119
145
|
resize: NiumResizeEvent;
|
|
@@ -122,57 +148,101 @@ interface NiumEventMap {
|
|
|
122
148
|
error: NiumErrorEvent;
|
|
123
149
|
cancel: NiumCancelEvent;
|
|
124
150
|
}
|
|
125
|
-
/** Callback signature for a given event
|
|
151
|
+
/** Callback signature for a given event name. */
|
|
126
152
|
type NiumEventCallback<T extends keyof NiumEventMap> = (event: NiumEventMap[T]) => void;
|
|
127
153
|
|
|
128
154
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
155
|
+
* A mounted instance of a hosted NIUM form. Created by {@link createElement}
|
|
156
|
+
* and rendered via {@link NiumElement.mount}.
|
|
157
|
+
*
|
|
158
|
+
* The element wraps a single iframe pointing at the web-onboard hosted form
|
|
159
|
+
* and translates its postMessage events into typed callbacks. It also exposes
|
|
160
|
+
* a programmatic {@link NiumElement.submit} method for parent-driven submits.
|
|
161
|
+
*
|
|
162
|
+
* Lifecycle:
|
|
163
|
+
* `new` → `mount()` → events → `submit()` | `destroy()`
|
|
164
|
+
*
|
|
165
|
+
* A destroyed element cannot be re-mounted; create a new one instead.
|
|
132
166
|
*/
|
|
133
167
|
declare class NiumElement {
|
|
134
168
|
private readonly iframeSrc;
|
|
135
169
|
private readonly elementType;
|
|
136
170
|
private readonly options;
|
|
171
|
+
private readonly origin;
|
|
137
172
|
private iframe;
|
|
138
173
|
private container;
|
|
139
174
|
private listeners;
|
|
140
|
-
private
|
|
175
|
+
private messageHandler;
|
|
141
176
|
private destroyed;
|
|
142
|
-
|
|
177
|
+
/** Pending `submit()` promise — resolved/rejected when the iframe responds. */
|
|
143
178
|
private pendingSubmit;
|
|
144
179
|
constructor(iframeSrc: string, elementType: NiumElementType, options: NiumElementOptions, origin: string);
|
|
145
|
-
/**
|
|
180
|
+
/**
|
|
181
|
+
* Mount the iframe into a DOM element. The target may be a CSS selector or
|
|
182
|
+
* an `HTMLElement` reference. Calling `mount` on an already-mounted element
|
|
183
|
+
* with the same container is a no-op; a different container triggers an
|
|
184
|
+
* automatic unmount first.
|
|
185
|
+
*/
|
|
146
186
|
mount(target: string | HTMLElement): void;
|
|
147
|
-
/**
|
|
187
|
+
/**
|
|
188
|
+
* Remove the iframe from the DOM and stop listening for messages. The
|
|
189
|
+
* element can be mounted again later.
|
|
190
|
+
*/
|
|
148
191
|
unmount(): void;
|
|
149
|
-
/**
|
|
192
|
+
/**
|
|
193
|
+
* Permanently destroy the element. Removes it from the DOM, clears every
|
|
194
|
+
* listener, and rejects any pending `submit()`. A destroyed element cannot
|
|
195
|
+
* be re-mounted.
|
|
196
|
+
*/
|
|
150
197
|
destroy(): void;
|
|
151
198
|
/**
|
|
152
|
-
* Programmatically trigger form submission from the parent
|
|
153
|
-
*
|
|
154
|
-
* Sends a `nium:submit-request` message to the iframe. The hosted form
|
|
155
|
-
* validates and submits, then responds with `nium:submit` (success) or
|
|
156
|
-
* `nium:error` (failure).
|
|
199
|
+
* Programmatically trigger form submission from the parent application.
|
|
157
200
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* ```ts
|
|
162
|
-
* const result = await element.submit()
|
|
163
|
-
* console.log(result.beneficiaryId)
|
|
164
|
-
* ```
|
|
201
|
+
* Posts a `nium:submit-request` message to the iframe; the hosted form
|
|
202
|
+
* validates, submits, and responds with `nium:submit` (resolve) or
|
|
203
|
+
* `nium:error` (reject).
|
|
165
204
|
*/
|
|
166
205
|
submit(): Promise<NiumSubmitResult>;
|
|
167
206
|
/** Subscribe to an event. Returns an unsubscribe function. */
|
|
168
207
|
on<K extends keyof NiumEventMap>(event: K, callback: NiumEventCallback<K>): () => void;
|
|
169
|
-
/** Remove a
|
|
208
|
+
/** Remove a previously registered listener. */
|
|
170
209
|
off<K extends keyof NiumEventMap>(event: K, callback: NiumEventCallback<K>): void;
|
|
210
|
+
private createIframe;
|
|
211
|
+
/** Top-level `postMessage` handler. Delegates to focused helpers per event. */
|
|
171
212
|
private handleMessage;
|
|
213
|
+
/**
|
|
214
|
+
* Validates the message origin and prefix, and returns the stripped event
|
|
215
|
+
* name + payload. Returns `null` for untrusted or malformed messages so
|
|
216
|
+
* they can be silently dropped.
|
|
217
|
+
*/
|
|
218
|
+
private parseTrustedMessage;
|
|
219
|
+
/**
|
|
220
|
+
* Handles built-in side effects that the SDK performs on behalf of the
|
|
221
|
+
* consumer: iframe auto-resize on `resize`, and `submit()` promise
|
|
222
|
+
* resolution on `submit` / `error`.
|
|
223
|
+
*/
|
|
224
|
+
private applySideEffects;
|
|
225
|
+
private applyResize;
|
|
226
|
+
private resolvePendingSubmit;
|
|
227
|
+
private rejectPendingSubmit;
|
|
228
|
+
/** Dispatch a typed event payload to every registered listener. */
|
|
229
|
+
private dispatchEvent;
|
|
172
230
|
}
|
|
173
231
|
|
|
174
232
|
/**
|
|
175
|
-
*
|
|
233
|
+
* Entry point for `@nium/nium-sdk`.
|
|
234
|
+
*
|
|
235
|
+
* Public surface:
|
|
236
|
+
* - {@link init} — configure the SDK (environment + auth)
|
|
237
|
+
* - {@link createElement} — build a mountable hosted form element
|
|
238
|
+
* - {@link NiumElement} — the element class, re-exported for type use
|
|
239
|
+
* - Type re-exports — every public type consumed by integrators
|
|
240
|
+
*
|
|
241
|
+
* @packageDocumentation
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Initialize the SDK. Must be called exactly once before {@link createElement}.
|
|
176
246
|
*
|
|
177
247
|
* @example
|
|
178
248
|
* ```ts
|
|
@@ -181,15 +251,20 @@ declare class NiumElement {
|
|
|
181
251
|
* await init({
|
|
182
252
|
* env: 'sandbox',
|
|
183
253
|
* authCode: '<auth-code-from-niam>',
|
|
254
|
+
* codeVerifier: '<pkce-code-verifier>',
|
|
255
|
+
* clientId: '<nium-client-id>',
|
|
184
256
|
* })
|
|
185
257
|
*
|
|
186
|
-
* const element = await createElement('payment'
|
|
258
|
+
* const element = await createElement('payment', {
|
|
259
|
+
* customerHashId: '<customer-hash-id>',
|
|
260
|
+
* intent: 'create_beneficiary',
|
|
261
|
+
* })
|
|
187
262
|
* element.mount('#container')
|
|
188
263
|
*
|
|
189
|
-
* // Option A
|
|
264
|
+
* // Option A — react to form-driven submit
|
|
190
265
|
* element.on('submit', (e) => console.log(e.result))
|
|
191
266
|
*
|
|
192
|
-
* // Option B
|
|
267
|
+
* // Option B — drive submit from the parent app
|
|
193
268
|
* const result = await element.submit()
|
|
194
269
|
* ```
|
|
195
270
|
*/
|
|
@@ -197,10 +272,12 @@ declare const init: (options: NiumInitOptions) => Promise<void>;
|
|
|
197
272
|
/**
|
|
198
273
|
* Create an embeddable element for a specific onboarding module.
|
|
199
274
|
*
|
|
200
|
-
* @param type
|
|
201
|
-
* @param options -
|
|
202
|
-
*
|
|
275
|
+
* @param type Module to render: `'payment' | 'tax' | 'identity' | 'full'`
|
|
276
|
+
* @param options Per-element configuration (customer, intent, prefill, theme,
|
|
277
|
+
* customizations).
|
|
278
|
+
* @returns A {@link NiumElement} that can be mounted, listened to, submitted,
|
|
279
|
+
* and destroyed.
|
|
203
280
|
*/
|
|
204
281
|
declare const createElement: (type: NiumElementType, options?: NiumElementOptions) => Promise<NiumElement>;
|
|
205
282
|
|
|
206
|
-
export { type NiumBeneficiaryFieldCustomizations, type NiumBeneficiaryFieldPath, type NiumCancelEvent, type NiumChangeEvent, NiumElement, type NiumElementOptions, type NiumElementType, type NiumEnv, type NiumErrorEvent, type NiumEvent, type NiumEventCallback, type NiumEventMap, type NiumFieldCustomization, type NiumInitOptions, type NiumPaymentIntent, type NiumPaymentPrefill, type NiumReadyEvent, type NiumResizeEvent, type NiumSubmitEvent, type NiumSubmitResult, type NiumTheme, createElement, init };
|
|
283
|
+
export { type NiumBeneficiaryFieldCustomizations, type NiumBeneficiaryFieldPath, type NiumBeneficiarySectionCustomizations, type NiumBeneficiarySectionPath, type NiumCancelEvent, type NiumChangeEvent, NiumElement, type NiumElementOptions, type NiumElementType, type NiumEnv, type NiumErrorEvent, type NiumEvent, type NiumEventCallback, type NiumEventMap, type NiumFieldCustomization, type NiumInitOptions, type NiumPaymentIntent, type NiumPaymentPrefill, type NiumReadyEvent, type NiumResizeEvent, type NiumSectionCustomization, type NiumSubmitEvent, type NiumSubmitResult, type NiumTheme, createElement, init };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,47 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Public type definitions for `@nium/nium-sdk`.
|
|
3
|
+
*
|
|
4
|
+
* These types are intentionally framework-agnostic. They describe the shape of
|
|
5
|
+
* configuration accepted by {@link init} and {@link createElement}, the events
|
|
6
|
+
* emitted by a mounted element, and the postMessage contract with the hosted
|
|
7
|
+
* form.
|
|
8
|
+
*
|
|
9
|
+
* Any change here is a public API change — keep it additive where possible.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A "loose autocomplete" string union: editors will suggest the listed
|
|
13
|
+
* literals while still accepting any other string. Prefer this over a bare
|
|
14
|
+
* `Literal | string` union, which collapses to `string` and loses intellisense
|
|
15
|
+
* (and trips `sonarjs/S6571`).
|
|
16
|
+
*/
|
|
17
|
+
type LooseStringUnion<T extends string> = T | (string & Record<never, never>);
|
|
18
|
+
/** Target environment for the hosted onboarding form. */
|
|
19
|
+
type NiumEnv = 'local' | 'qa' | 'preprod' | 'sandbox' | 'production';
|
|
20
|
+
/** Supported module types. Each maps to a dedicated route inside web-onboard. */
|
|
4
21
|
type NiumElementType = 'payment' | 'tax' | 'identity' | 'full';
|
|
5
|
-
/** Configuration
|
|
22
|
+
/** Configuration accepted by the top-level `init()` call. */
|
|
6
23
|
interface NiumInitOptions {
|
|
7
|
-
/** Target environment */
|
|
24
|
+
/** Target environment; determines the default hosted form URL. */
|
|
8
25
|
env: NiumEnv;
|
|
9
|
-
/**
|
|
26
|
+
/** BCP-47 locale code (for example `en`, `en-GB`, `es`). Defaults to `en`. */
|
|
10
27
|
locale?: string;
|
|
11
|
-
/** Override the hosted form base URL
|
|
28
|
+
/** Override the hosted form base URL. Primarily for local development. */
|
|
12
29
|
hostedFormUrl?: string;
|
|
13
|
-
/**
|
|
30
|
+
/** Short-lived authorization code obtained from NIAM via OAuth 2.1 / PKCE. */
|
|
14
31
|
authCode?: string;
|
|
15
|
-
/** PKCE code verifier
|
|
32
|
+
/** PKCE code verifier that matches the code challenge used to obtain `authCode`. */
|
|
16
33
|
codeVerifier?: string;
|
|
17
|
-
/**
|
|
34
|
+
/** Identifier of the customer the form is being rendered for. */
|
|
18
35
|
customerHashId?: string;
|
|
19
|
-
/**
|
|
36
|
+
/** NIUM client identifier. */
|
|
20
37
|
clientId?: string;
|
|
21
|
-
/** Pre-exchanged session token
|
|
38
|
+
/** Pre-exchanged session token. When present, `authCode`/`codeVerifier` are bypassed. */
|
|
22
39
|
sessionToken?: string;
|
|
23
40
|
}
|
|
24
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Theme overrides applied to the embedded form. Every property is optional;
|
|
43
|
+
* unspecified values fall back to the form's default design tokens.
|
|
44
|
+
*/
|
|
25
45
|
interface NiumTheme {
|
|
26
46
|
borderRadius?: string;
|
|
27
47
|
fontFamily?: string;
|
|
@@ -35,23 +55,24 @@ interface NiumTheme {
|
|
|
35
55
|
labelBackgroundColor?: string;
|
|
36
56
|
radioColor?: string;
|
|
37
57
|
}
|
|
38
|
-
/** Per-field UI customization
|
|
58
|
+
/** Per-field UI customization for the beneficiary form. */
|
|
39
59
|
interface NiumFieldCustomization {
|
|
40
60
|
hidden?: boolean;
|
|
41
61
|
disabled?: boolean;
|
|
42
62
|
}
|
|
43
|
-
/** Per-section UI customization
|
|
63
|
+
/** Per-section UI customization for the beneficiary form. */
|
|
44
64
|
interface NiumSectionCustomization {
|
|
45
65
|
hidden?: boolean;
|
|
46
66
|
}
|
|
47
|
-
/**
|
|
48
|
-
type NiumBeneficiaryFieldPath = 'name' | 'entityType' | 'line1' | 'line2' | 'city' | 'state' | 'postalCode' | 'countryCode' | 'communicationPreference' | 'contactNumber' | 'email' | 'termsCheckbox' | 'helperText'
|
|
49
|
-
|
|
50
|
-
type
|
|
51
|
-
type
|
|
52
|
-
|
|
67
|
+
/** Known field paths on the beneficiary form; additional paths are accepted. */
|
|
68
|
+
type NiumBeneficiaryFieldPath = LooseStringUnion<'name' | 'entityType' | 'line1' | 'line2' | 'city' | 'state' | 'postalCode' | 'countryCode' | 'communicationPreference' | 'contactNumber' | 'email' | 'termsCheckbox' | 'helperText'>;
|
|
69
|
+
/** Known section paths on the beneficiary form; additional paths are accepted. */
|
|
70
|
+
type NiumBeneficiarySectionPath = LooseStringUnion<'demographicInfo' | 'communicationPreferences' | 'accountType' | 'bankAccountDetails'>;
|
|
71
|
+
type NiumBeneficiaryFieldCustomizations = Partial<Record<NiumBeneficiaryFieldPath, NiumFieldCustomization>>;
|
|
72
|
+
type NiumBeneficiarySectionCustomizations = Partial<Record<NiumBeneficiarySectionPath, NiumSectionCustomization>>;
|
|
73
|
+
/** Intent driving how the payment form behaves on submit. */
|
|
53
74
|
type NiumPaymentIntent = 'create_beneficiary' | 'return_payload' | 'update_beneficiary';
|
|
54
|
-
/** Prefill
|
|
75
|
+
/** Prefill payload for the payment (beneficiary) form. */
|
|
55
76
|
interface NiumPaymentPrefill {
|
|
56
77
|
name?: string;
|
|
57
78
|
email?: string;
|
|
@@ -66,23 +87,27 @@ interface NiumPaymentPrefill {
|
|
|
66
87
|
countryCode?: string;
|
|
67
88
|
};
|
|
68
89
|
}
|
|
69
|
-
/** Options
|
|
90
|
+
/** Options accepted by {@link createElement}. */
|
|
70
91
|
interface NiumElementOptions {
|
|
71
|
-
/** Customer
|
|
92
|
+
/** Customer identifier. Required. */
|
|
72
93
|
customerHashId?: string;
|
|
73
|
-
/**
|
|
94
|
+
/** Initial values for the form. Ignored for `update_beneficiary`. */
|
|
74
95
|
prefill?: NiumPaymentPrefill;
|
|
75
|
-
/**
|
|
96
|
+
/** Visual theme overrides. */
|
|
76
97
|
theme?: NiumTheme;
|
|
77
|
-
/**
|
|
98
|
+
/** Behaviour of the submit action. Required. */
|
|
78
99
|
intent?: NiumPaymentIntent;
|
|
79
|
-
/** Beneficiary
|
|
100
|
+
/** Beneficiary identifier. Required when `intent === 'update_beneficiary'`. */
|
|
80
101
|
beneficiaryHashId?: string;
|
|
81
|
-
/**
|
|
102
|
+
/** Iframe sizing and field/section visibility. */
|
|
82
103
|
customizations?: {
|
|
104
|
+
/** Minimum iframe height in pixels. Default: 400. */
|
|
83
105
|
minHeight?: number;
|
|
106
|
+
/** Maximum iframe height in pixels. Default: 804. */
|
|
84
107
|
maxHeight?: number;
|
|
108
|
+
/** Per-field visibility/disabled overrides. */
|
|
85
109
|
fields?: NiumBeneficiaryFieldCustomizations;
|
|
110
|
+
/** Per-section visibility overrides. */
|
|
86
111
|
sections?: NiumBeneficiarySectionCustomizations;
|
|
87
112
|
};
|
|
88
113
|
}
|
|
@@ -97,6 +122,7 @@ interface NiumChangeEvent {
|
|
|
97
122
|
type: 'change';
|
|
98
123
|
data: Record<string, unknown>;
|
|
99
124
|
}
|
|
125
|
+
/** Opaque result payload returned by the hosted form on successful submit. */
|
|
100
126
|
type NiumSubmitResult = Record<string, unknown>;
|
|
101
127
|
interface NiumSubmitEvent {
|
|
102
128
|
type: 'submit';
|
|
@@ -113,7 +139,7 @@ interface NiumCancelEvent {
|
|
|
113
139
|
type: 'cancel';
|
|
114
140
|
}
|
|
115
141
|
type NiumEvent = NiumReadyEvent | NiumResizeEvent | NiumChangeEvent | NiumSubmitEvent | NiumErrorEvent | NiumCancelEvent;
|
|
116
|
-
/**
|
|
142
|
+
/** Event name → event payload map. */
|
|
117
143
|
interface NiumEventMap {
|
|
118
144
|
ready: NiumReadyEvent;
|
|
119
145
|
resize: NiumResizeEvent;
|
|
@@ -122,57 +148,101 @@ interface NiumEventMap {
|
|
|
122
148
|
error: NiumErrorEvent;
|
|
123
149
|
cancel: NiumCancelEvent;
|
|
124
150
|
}
|
|
125
|
-
/** Callback signature for a given event
|
|
151
|
+
/** Callback signature for a given event name. */
|
|
126
152
|
type NiumEventCallback<T extends keyof NiumEventMap> = (event: NiumEventMap[T]) => void;
|
|
127
153
|
|
|
128
154
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
155
|
+
* A mounted instance of a hosted NIUM form. Created by {@link createElement}
|
|
156
|
+
* and rendered via {@link NiumElement.mount}.
|
|
157
|
+
*
|
|
158
|
+
* The element wraps a single iframe pointing at the web-onboard hosted form
|
|
159
|
+
* and translates its postMessage events into typed callbacks. It also exposes
|
|
160
|
+
* a programmatic {@link NiumElement.submit} method for parent-driven submits.
|
|
161
|
+
*
|
|
162
|
+
* Lifecycle:
|
|
163
|
+
* `new` → `mount()` → events → `submit()` | `destroy()`
|
|
164
|
+
*
|
|
165
|
+
* A destroyed element cannot be re-mounted; create a new one instead.
|
|
132
166
|
*/
|
|
133
167
|
declare class NiumElement {
|
|
134
168
|
private readonly iframeSrc;
|
|
135
169
|
private readonly elementType;
|
|
136
170
|
private readonly options;
|
|
171
|
+
private readonly origin;
|
|
137
172
|
private iframe;
|
|
138
173
|
private container;
|
|
139
174
|
private listeners;
|
|
140
|
-
private
|
|
175
|
+
private messageHandler;
|
|
141
176
|
private destroyed;
|
|
142
|
-
|
|
177
|
+
/** Pending `submit()` promise — resolved/rejected when the iframe responds. */
|
|
143
178
|
private pendingSubmit;
|
|
144
179
|
constructor(iframeSrc: string, elementType: NiumElementType, options: NiumElementOptions, origin: string);
|
|
145
|
-
/**
|
|
180
|
+
/**
|
|
181
|
+
* Mount the iframe into a DOM element. The target may be a CSS selector or
|
|
182
|
+
* an `HTMLElement` reference. Calling `mount` on an already-mounted element
|
|
183
|
+
* with the same container is a no-op; a different container triggers an
|
|
184
|
+
* automatic unmount first.
|
|
185
|
+
*/
|
|
146
186
|
mount(target: string | HTMLElement): void;
|
|
147
|
-
/**
|
|
187
|
+
/**
|
|
188
|
+
* Remove the iframe from the DOM and stop listening for messages. The
|
|
189
|
+
* element can be mounted again later.
|
|
190
|
+
*/
|
|
148
191
|
unmount(): void;
|
|
149
|
-
/**
|
|
192
|
+
/**
|
|
193
|
+
* Permanently destroy the element. Removes it from the DOM, clears every
|
|
194
|
+
* listener, and rejects any pending `submit()`. A destroyed element cannot
|
|
195
|
+
* be re-mounted.
|
|
196
|
+
*/
|
|
150
197
|
destroy(): void;
|
|
151
198
|
/**
|
|
152
|
-
* Programmatically trigger form submission from the parent
|
|
153
|
-
*
|
|
154
|
-
* Sends a `nium:submit-request` message to the iframe. The hosted form
|
|
155
|
-
* validates and submits, then responds with `nium:submit` (success) or
|
|
156
|
-
* `nium:error` (failure).
|
|
199
|
+
* Programmatically trigger form submission from the parent application.
|
|
157
200
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* ```ts
|
|
162
|
-
* const result = await element.submit()
|
|
163
|
-
* console.log(result.beneficiaryId)
|
|
164
|
-
* ```
|
|
201
|
+
* Posts a `nium:submit-request` message to the iframe; the hosted form
|
|
202
|
+
* validates, submits, and responds with `nium:submit` (resolve) or
|
|
203
|
+
* `nium:error` (reject).
|
|
165
204
|
*/
|
|
166
205
|
submit(): Promise<NiumSubmitResult>;
|
|
167
206
|
/** Subscribe to an event. Returns an unsubscribe function. */
|
|
168
207
|
on<K extends keyof NiumEventMap>(event: K, callback: NiumEventCallback<K>): () => void;
|
|
169
|
-
/** Remove a
|
|
208
|
+
/** Remove a previously registered listener. */
|
|
170
209
|
off<K extends keyof NiumEventMap>(event: K, callback: NiumEventCallback<K>): void;
|
|
210
|
+
private createIframe;
|
|
211
|
+
/** Top-level `postMessage` handler. Delegates to focused helpers per event. */
|
|
171
212
|
private handleMessage;
|
|
213
|
+
/**
|
|
214
|
+
* Validates the message origin and prefix, and returns the stripped event
|
|
215
|
+
* name + payload. Returns `null` for untrusted or malformed messages so
|
|
216
|
+
* they can be silently dropped.
|
|
217
|
+
*/
|
|
218
|
+
private parseTrustedMessage;
|
|
219
|
+
/**
|
|
220
|
+
* Handles built-in side effects that the SDK performs on behalf of the
|
|
221
|
+
* consumer: iframe auto-resize on `resize`, and `submit()` promise
|
|
222
|
+
* resolution on `submit` / `error`.
|
|
223
|
+
*/
|
|
224
|
+
private applySideEffects;
|
|
225
|
+
private applyResize;
|
|
226
|
+
private resolvePendingSubmit;
|
|
227
|
+
private rejectPendingSubmit;
|
|
228
|
+
/** Dispatch a typed event payload to every registered listener. */
|
|
229
|
+
private dispatchEvent;
|
|
172
230
|
}
|
|
173
231
|
|
|
174
232
|
/**
|
|
175
|
-
*
|
|
233
|
+
* Entry point for `@nium/nium-sdk`.
|
|
234
|
+
*
|
|
235
|
+
* Public surface:
|
|
236
|
+
* - {@link init} — configure the SDK (environment + auth)
|
|
237
|
+
* - {@link createElement} — build a mountable hosted form element
|
|
238
|
+
* - {@link NiumElement} — the element class, re-exported for type use
|
|
239
|
+
* - Type re-exports — every public type consumed by integrators
|
|
240
|
+
*
|
|
241
|
+
* @packageDocumentation
|
|
242
|
+
*/
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Initialize the SDK. Must be called exactly once before {@link createElement}.
|
|
176
246
|
*
|
|
177
247
|
* @example
|
|
178
248
|
* ```ts
|
|
@@ -181,15 +251,20 @@ declare class NiumElement {
|
|
|
181
251
|
* await init({
|
|
182
252
|
* env: 'sandbox',
|
|
183
253
|
* authCode: '<auth-code-from-niam>',
|
|
254
|
+
* codeVerifier: '<pkce-code-verifier>',
|
|
255
|
+
* clientId: '<nium-client-id>',
|
|
184
256
|
* })
|
|
185
257
|
*
|
|
186
|
-
* const element = await createElement('payment'
|
|
258
|
+
* const element = await createElement('payment', {
|
|
259
|
+
* customerHashId: '<customer-hash-id>',
|
|
260
|
+
* intent: 'create_beneficiary',
|
|
261
|
+
* })
|
|
187
262
|
* element.mount('#container')
|
|
188
263
|
*
|
|
189
|
-
* // Option A
|
|
264
|
+
* // Option A — react to form-driven submit
|
|
190
265
|
* element.on('submit', (e) => console.log(e.result))
|
|
191
266
|
*
|
|
192
|
-
* // Option B
|
|
267
|
+
* // Option B — drive submit from the parent app
|
|
193
268
|
* const result = await element.submit()
|
|
194
269
|
* ```
|
|
195
270
|
*/
|
|
@@ -197,10 +272,12 @@ declare const init: (options: NiumInitOptions) => Promise<void>;
|
|
|
197
272
|
/**
|
|
198
273
|
* Create an embeddable element for a specific onboarding module.
|
|
199
274
|
*
|
|
200
|
-
* @param type
|
|
201
|
-
* @param options -
|
|
202
|
-
*
|
|
275
|
+
* @param type Module to render: `'payment' | 'tax' | 'identity' | 'full'`
|
|
276
|
+
* @param options Per-element configuration (customer, intent, prefill, theme,
|
|
277
|
+
* customizations).
|
|
278
|
+
* @returns A {@link NiumElement} that can be mounted, listened to, submitted,
|
|
279
|
+
* and destroyed.
|
|
203
280
|
*/
|
|
204
281
|
declare const createElement: (type: NiumElementType, options?: NiumElementOptions) => Promise<NiumElement>;
|
|
205
282
|
|
|
206
|
-
export { type NiumBeneficiaryFieldCustomizations, type NiumBeneficiaryFieldPath, type NiumCancelEvent, type NiumChangeEvent, NiumElement, type NiumElementOptions, type NiumElementType, type NiumEnv, type NiumErrorEvent, type NiumEvent, type NiumEventCallback, type NiumEventMap, type NiumFieldCustomization, type NiumInitOptions, type NiumPaymentIntent, type NiumPaymentPrefill, type NiumReadyEvent, type NiumResizeEvent, type NiumSubmitEvent, type NiumSubmitResult, type NiumTheme, createElement, init };
|
|
283
|
+
export { type NiumBeneficiaryFieldCustomizations, type NiumBeneficiaryFieldPath, type NiumBeneficiarySectionCustomizations, type NiumBeneficiarySectionPath, type NiumCancelEvent, type NiumChangeEvent, NiumElement, type NiumElementOptions, type NiumElementType, type NiumEnv, type NiumErrorEvent, type NiumEvent, type NiumEventCallback, type NiumEventMap, type NiumFieldCustomization, type NiumInitOptions, type NiumPaymentIntent, type NiumPaymentPrefill, type NiumReadyEvent, type NiumResizeEvent, type NiumSectionCustomization, type NiumSubmitEvent, type NiumSubmitResult, type NiumTheme, createElement, init };
|