@flonkid/kyc 1.9.2 → 1.9.3

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.cts CHANGED
@@ -1,250 +1,7 @@
1
+ import { FlonkKYCOptions, WidgetLanguage, VerificationResult } from './core.cjs';
2
+ export { API_VERSION, DocumentType, EmbedInstance, FlonkDiagnostic, FlonkDiagnosticCode, FlonkDiagnosticLevel, FlonkError, FlonkErrorCode, FlonkKYC, FlonkValidationError, PROTOCOL_VERSION, PreviewColors, SDK_VERSION, WIDGET_EVENTS, WIDGET_PARAMS, WidgetEmbedConfig, WidgetInitConfig, WidgetInstance, WidgetPreviewConfig, addDiagnosticHandler } from './core.cjs';
1
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
4
 
3
- type DocumentType = 'passport' | 'id_card' | 'driver_license';
4
- type WidgetLanguage = 'en' | 'de' | 'uk';
5
- type FlonkDiagnosticLevel = 'info' | 'warn' | 'error';
6
- /**
7
- * Known diagnostic codes emitted when the SDK degrades or branches. The union
8
- * is open (`| string`) so new codes don't break consumers' exhaustiveness.
9
- */
10
- type FlonkDiagnosticCode = 'LOADER_FALLBACK_BUNDLED' | 'LOADER_SCRIPT_BLOCKED' | 'PREWARM_SKIPPED' | 'IFRAME_REUSE' | 'IFRAME_FRESH' | 'PROTOCOL_VERSION_MISMATCH' | 'READY_TIMEOUT_REVEAL' | (string & {});
11
- /**
12
- * A structured diagnostic surfaced via `onDiagnostic` (and console when
13
- * `window.__FLONK_DEBUG__` is set). Never contains tokens or PII.
14
- */
15
- interface FlonkDiagnostic {
16
- code: FlonkDiagnosticCode;
17
- level: FlonkDiagnosticLevel;
18
- message: string;
19
- detail?: Record<string, unknown>;
20
- }
21
- interface FlonkKYCOptions {
22
- widgetUrl?: string;
23
- apiBase?: string;
24
- /**
25
- * Observe SDK degradations/branches (loader fallback, blocked script, prewarm
26
- * skipped, ready-timeout reveal, …). Errors thrown here are swallowed — they
27
- * can never break the SDK. Console output for the same events is gated behind
28
- * `window.__FLONK_DEBUG__ = true` so there's no noise by default.
29
- */
30
- onDiagnostic?: (event: FlonkDiagnostic) => void;
31
- }
32
- interface WidgetInitConfig {
33
- serverUrl?: string;
34
- /**
35
- * Your project's publishable key (`pk_live_*` or `pk_sandbox_*`).
36
- * Found in Dashboard → Project Settings → API Keys.
37
- *
38
- * Enables an instant branded loading screen: the brand color is resolved
39
- * directly from the key (a Redis-cached read) in parallel with session
40
- * setup, so the loader paints your color on first frame instead of waiting
41
- * on the session. Works with both flows:
42
- * - `serverUrl` (your backend creates the session), and
43
- * - `sessionId` + `embedToken` (you pass a pre-created session).
44
- *
45
- * Without it, branding is resolved from the session and the loader shows
46
- * the default color until that request returns. Recommended for the best UX.
47
- */
48
- publishableKey?: string;
49
- sessionId?: string;
50
- embedToken?: string;
51
- /**
52
- * URL the desktop→mobile QR code points to. Needed for the mobile-transfer
53
- * QR to render. In the `serverUrl` flow, return it from your endpoint
54
- * alongside `sessionId`/`embedToken` (it's the `qrCodeUrl` from `createSession`);
55
- * in the `sessionId` + `embedToken` flow, pass it here.
56
- */
57
- qrCodeUrl?: string;
58
- clientMetadata?: Record<string, unknown>;
59
- lang?: WidgetLanguage;
60
- overlayColor?: string;
61
- allowManualUpload?: boolean;
62
- mount?: HTMLElement;
63
- /**
64
- * Extra headers sent with the `serverUrl` POST request.
65
- * Use this to pass Authorization tokens (e.g. JWT) when your
66
- * backend requires authentication.
67
- *
68
- * @example { Authorization: 'Bearer <jwt>' }
69
- */
70
- requestHeaders?: Record<string, string>;
71
- onSuccess?: (result: VerificationResult) => void;
72
- onError?: (error: string) => void;
73
- onCancel?: () => void;
74
- onReady?: () => void;
75
- }
76
- interface WidgetPreviewConfig {
77
- colors?: PreviewColors;
78
- documentType?: DocumentType;
79
- lang?: WidgetLanguage;
80
- overlayColor?: string;
81
- onSuccess?: (result: VerificationResult) => void;
82
- onError?: (error: string) => void;
83
- onCancel?: () => void;
84
- }
85
- interface WidgetEmbedConfig {
86
- container: string | HTMLElement;
87
- colors?: PreviewColors;
88
- device?: 'mobile' | 'desktop';
89
- scale?: number;
90
- documentType?: DocumentType;
91
- lang?: WidgetLanguage;
92
- }
93
- interface WidgetInstance {
94
- iframe: HTMLIFrameElement;
95
- destroy: () => void;
96
- }
97
- interface EmbedInstance extends WidgetInstance {
98
- setColors: (colors: Partial<PreviewColors>) => void;
99
- setDevice: (device: 'mobile' | 'desktop') => void;
100
- getColors: () => PreviewColors;
101
- }
102
- interface PreviewColors {
103
- primaryColor?: string;
104
- secondaryColor?: string;
105
- }
106
- interface VerificationResult {
107
- sessionId?: string;
108
- status?: string;
109
- [key: string]: unknown;
110
- }
111
-
112
- /**
113
- * Self-prewarming for the KYC widget.
114
- *
115
- * Warms the connection and assets to our widget origin BEFORE the user clicks
116
- * "Start", so the loader (and ultimately the widget) appears with little or no
117
- * wait. All work is scheduled at idle / after the host page's `load`, so it
118
- * never competes with the host page's own critical resources.
119
- *
120
- * Levels (`prewarm`):
121
- * - 'connect' (default): preconnect + idle prefetch of the loader/branding
122
- * assets and the widget document. Cheap; warms DNS/TLS + caches.
123
- * - 'intent': warm when the user signals intent (hover / focus / the trigger
124
- * scrolls into view). Best for widgets on general pages — no cost for
125
- * visitors who never engage.
126
- * - 'eager': also pre-mount a hidden iframe at idle so the full widget bundle
127
- * loads in the background. Best for dedicated, high-click-through KYC pages.
128
- * - 'none': do nothing.
129
- *
130
- * Never throws; SSR-safe (no-ops when there's no document). Sessions are NEVER
131
- * pre-created here — only static assets are warmed.
132
- */
133
- type PrewarmLevel = 'connect' | 'intent' | 'eager' | 'none';
134
-
135
- declare class FlonkKYC {
136
- static readonly version = "1.9.2";
137
- private readonly widgetUrl;
138
- private readonly apiBase;
139
- private disposeDiagnostics;
140
- constructor(options?: FlonkKYCOptions);
141
- /** Unregister this instance's `onDiagnostic` handler. */
142
- dispose(): void;
143
- /**
144
- * Prewarm the widget ahead of the user's click — preconnect + idle prefetch
145
- * of branding/assets, and (with `level:'eager'`) a hidden background iframe so
146
- * the full bundle is loaded before the click. Call on page mount / route
147
- * enter. Returns a cleanup (removes `intent` listeners). Never pre-creates a
148
- * session. SSR-safe.
149
- *
150
- * @example
151
- * FlonkKYC.prewarm({ publishableKey: 'pk_live_…', level: 'eager' });
152
- * // or, warm only when the user shows intent:
153
- * FlonkKYC.prewarm({ publishableKey: 'pk_live_…', level: 'intent', trigger: btn });
154
- */
155
- static prewarm(opts?: {
156
- publishableKey?: string;
157
- sessionId?: string;
158
- widgetUrl?: string;
159
- apiBase?: string;
160
- level?: PrewarmLevel;
161
- trigger?: Element | null;
162
- }): () => void;
163
- /**
164
- * Warm the project's branding (colors) ahead of time so the widget paints the
165
- * brand color on the first frame, with no branding round-trip at click time.
166
- *
167
- * Call it early — on page mount, route enter, or hover of the "verify" button
168
- * — well before `init()`. The result is cached (module-level, 5-min TTL) and
169
- * every subsequent `init()`/`open()` for the same key reads from it. Safe to
170
- * call repeatedly; concurrent calls dedupe. Never throws.
171
- *
172
- * @example
173
- * // in a layout effect, long before the user clicks "Verify"
174
- * FlonkKYC.preloadBranding({ publishableKey: 'pk_live_...' });
175
- */
176
- static preloadBranding(opts: {
177
- publishableKey?: string;
178
- sessionId?: string;
179
- apiBase?: string;
180
- }): Promise<void>;
181
- /**
182
- * Open the KYC verification widget.
183
- *
184
- * Flows (pick one; add `publishableKey` to any for an instant branded loader):
185
- * 1. `{ serverUrl }` — SDK auto-creates the session via your backend (recommended).
186
- * 2. `{ sessionId, embedToken }` — you created the session; pass its credentials.
187
- * 3. `{ sessionId }` — **deprecated**: exchanges the sessionId for an embedToken
188
- * via an extra round-trip. Prefer flow 2 by returning `embedToken` from your
189
- * backend alongside `sessionId`.
190
- * 4. `{ publishableKey }` — client-only; SDK mints a short-lived widget token.
191
- */
192
- init(config: WidgetInitConfig): Promise<WidgetInstance>;
193
- /**
194
- * Preview mode — no API calls, mock data.
195
- */
196
- preview(config?: WidgetPreviewConfig): WidgetInstance;
197
- /**
198
- * Embed inline preview in a container (for dashboards).
199
- */
200
- embed(config: WidgetEmbedConfig): EmbedInstance;
201
- /**
202
- * Flow 1: serverUrl — POST to client's backend, get sessionId + embedToken.
203
- *
204
- * When `publishableKey` is provided, design tokens are fetched in parallel
205
- * with the session creation request. This shows the branded loader ~200-500ms
206
- * faster because we don't have to wait for the session to be created first.
207
- */
208
- private initWithServerUrl;
209
- /**
210
- * Flow 2: sessionId + embedToken — fetch session data, open widget.
211
- */
212
- private initWithEmbedToken;
213
- /**
214
- * Flow 3: sessionId only — exchange for embedToken, then init.
215
- *
216
- * @deprecated Prefer flow 2 (`sessionId` + `embedToken`). Return the
217
- * `embedToken` from your backend together with the `sessionId` to skip this
218
- * extra token-exchange round-trip.
219
- */
220
- private initWithSession;
221
- /**
222
- * Flow 4: publishableKey — fetch widget token, open widget.
223
- */
224
- private initWithPublishableKey;
225
- private buildWidget;
226
- /**
227
- * Core: create iframe, attach listeners, return WidgetInstance.
228
- */
229
- private openWidget;
230
- }
231
-
232
- /**
233
- * Tiny observability sink. The SDK emits a structured diagnostic at every
234
- * degradation/branch point (loader fallback, blocked script, prewarm skipped,
235
- * ready-timeout reveal, …) so integrators — and we — can see WHY the SDK did
236
- * what it did, instead of guessing from a silent fallback.
237
- *
238
- * Module-level by necessity: several emit points (prewarm, the server-loader
239
- * script load) run outside any FlonkKYC instance (static / constructor). The
240
- * FlonkKYC constructor registers its `onDiagnostic` here; `window.__FLONK_DEBUG__`
241
- * additionally mirrors events to the console. Zero-cost when nothing is
242
- * registered and the debug flag is unset.
243
- */
244
- type DiagnosticHandler = (event: FlonkDiagnostic) => void;
245
- /** Register a diagnostic handler. Returns an unsubscribe. De-dupes by reference. */
246
- declare function addDiagnosticHandler(handler: DiagnosticHandler): () => void;
247
-
248
5
  interface FlonkKYCProps extends FlonkKYCOptions {
249
6
  publishableKey?: string;
250
7
  serverUrl?: string;
@@ -288,52 +45,4 @@ interface FlonkKYCBrandingPreloaderProps {
288
45
  */
289
46
  declare function FlonkKYCBrandingPreloader({ publishableKey, sessionId, apiBase, }: FlonkKYCBrandingPreloaderProps): null;
290
47
 
291
- /**
292
- * Stable, machine-branchable error codes returned by the API in the `code`
293
- * field of an error body. Open union (`| (string & {})`) so new codes don't
294
- * break consumers — branch on the ones you handle, fall through on the rest.
295
- */
296
- type FlonkErrorCode = 'authentication_error' | 'invalid_publishable_key' | 'session_not_found' | 'session_expired' | 'session_invalid_state' | 'rate_limited' | 'validation_error' | 'api_error' | (string & {});
297
- declare class FlonkError extends Error {
298
- readonly code: FlonkErrorCode;
299
- readonly statusCode?: number | undefined;
300
- constructor(message: string, code: FlonkErrorCode, statusCode?: number | undefined);
301
- }
302
- declare class FlonkValidationError extends FlonkError {
303
- constructor(message: string);
304
- }
305
-
306
- declare const SDK_VERSION = "1.9.2";
307
- /**
308
- * REST API version this SDK is built against (date-pinned, separate from the
309
- * package version). Sent as the `Flonk-Version` header so a future breaking API
310
- * change can be served the old shape to old SDKs and the new shape to new ones.
311
- * The API is additive-only within a version; a breaking change mints a new date.
312
- */
313
- declare const API_VERSION = "2026-06-01";
314
- declare const PROTOCOL_VERSION = 1;
315
- /** postMessage `type` values exchanged between the SDK and the iframe. */
316
- declare const WIDGET_EVENTS: {
317
- readonly READY: "KYC_WIDGET_READY";
318
- readonly COMPLETE: "KYC_COMPLETE";
319
- readonly CANCEL: "KYC_CANCEL";
320
- readonly ERROR: "KYC_ERROR";
321
- readonly CONFIG: "KYC_WIDGET_CONFIG";
322
- };
323
- /** Canonical iframe URL param keys the SDK stamps onto the widget src. */
324
- declare const WIDGET_PARAMS: {
325
- readonly PROTOCOL_VERSION: "pv";
326
- readonly SESSION_ID: "sessionId";
327
- readonly EMBED_TOKEN: "embedToken";
328
- readonly TOKEN: "token";
329
- readonly PUBLISHABLE_KEY: "publishableKey";
330
- readonly CLIENT_ID: "clientId";
331
- readonly CLIENT_METADATA: "clientMetadata";
332
- readonly DESIGN_TOKENS: "designTokens";
333
- readonly ALLOW_MANUAL_UPLOAD: "allowManualUpload";
334
- readonly LANG: "lang";
335
- readonly OVERLAY_COLOR: "overlayColor";
336
- readonly MODE: "mode";
337
- };
338
-
339
- export { API_VERSION, type DocumentType, type EmbedInstance, type FlonkDiagnostic, type FlonkDiagnosticCode, type FlonkDiagnosticLevel, FlonkError, type FlonkErrorCode, FlonkKYC, FlonkKYCBrandingPreloader, type FlonkKYCBrandingPreloaderProps, type FlonkKYCOptions, type FlonkKYCProps, FlonkKYCWidget, FlonkValidationError, PROTOCOL_VERSION, type PreviewColors, SDK_VERSION, type VerificationResult, WIDGET_EVENTS, WIDGET_PARAMS, type WidgetEmbedConfig, type WidgetInitConfig, type WidgetInstance, type WidgetLanguage, type WidgetPreviewConfig, addDiagnosticHandler };
48
+ export { FlonkKYCBrandingPreloader, type FlonkKYCBrandingPreloaderProps, FlonkKYCOptions, type FlonkKYCProps, FlonkKYCWidget, VerificationResult, WidgetLanguage };
package/dist/index.d.ts CHANGED
@@ -1,250 +1,7 @@
1
+ import { FlonkKYCOptions, WidgetLanguage, VerificationResult } from './core.js';
2
+ export { API_VERSION, DocumentType, EmbedInstance, FlonkDiagnostic, FlonkDiagnosticCode, FlonkDiagnosticLevel, FlonkError, FlonkErrorCode, FlonkKYC, FlonkValidationError, PROTOCOL_VERSION, PreviewColors, SDK_VERSION, WIDGET_EVENTS, WIDGET_PARAMS, WidgetEmbedConfig, WidgetInitConfig, WidgetInstance, WidgetPreviewConfig, addDiagnosticHandler } from './core.js';
1
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
4
 
3
- type DocumentType = 'passport' | 'id_card' | 'driver_license';
4
- type WidgetLanguage = 'en' | 'de' | 'uk';
5
- type FlonkDiagnosticLevel = 'info' | 'warn' | 'error';
6
- /**
7
- * Known diagnostic codes emitted when the SDK degrades or branches. The union
8
- * is open (`| string`) so new codes don't break consumers' exhaustiveness.
9
- */
10
- type FlonkDiagnosticCode = 'LOADER_FALLBACK_BUNDLED' | 'LOADER_SCRIPT_BLOCKED' | 'PREWARM_SKIPPED' | 'IFRAME_REUSE' | 'IFRAME_FRESH' | 'PROTOCOL_VERSION_MISMATCH' | 'READY_TIMEOUT_REVEAL' | (string & {});
11
- /**
12
- * A structured diagnostic surfaced via `onDiagnostic` (and console when
13
- * `window.__FLONK_DEBUG__` is set). Never contains tokens or PII.
14
- */
15
- interface FlonkDiagnostic {
16
- code: FlonkDiagnosticCode;
17
- level: FlonkDiagnosticLevel;
18
- message: string;
19
- detail?: Record<string, unknown>;
20
- }
21
- interface FlonkKYCOptions {
22
- widgetUrl?: string;
23
- apiBase?: string;
24
- /**
25
- * Observe SDK degradations/branches (loader fallback, blocked script, prewarm
26
- * skipped, ready-timeout reveal, …). Errors thrown here are swallowed — they
27
- * can never break the SDK. Console output for the same events is gated behind
28
- * `window.__FLONK_DEBUG__ = true` so there's no noise by default.
29
- */
30
- onDiagnostic?: (event: FlonkDiagnostic) => void;
31
- }
32
- interface WidgetInitConfig {
33
- serverUrl?: string;
34
- /**
35
- * Your project's publishable key (`pk_live_*` or `pk_sandbox_*`).
36
- * Found in Dashboard → Project Settings → API Keys.
37
- *
38
- * Enables an instant branded loading screen: the brand color is resolved
39
- * directly from the key (a Redis-cached read) in parallel with session
40
- * setup, so the loader paints your color on first frame instead of waiting
41
- * on the session. Works with both flows:
42
- * - `serverUrl` (your backend creates the session), and
43
- * - `sessionId` + `embedToken` (you pass a pre-created session).
44
- *
45
- * Without it, branding is resolved from the session and the loader shows
46
- * the default color until that request returns. Recommended for the best UX.
47
- */
48
- publishableKey?: string;
49
- sessionId?: string;
50
- embedToken?: string;
51
- /**
52
- * URL the desktop→mobile QR code points to. Needed for the mobile-transfer
53
- * QR to render. In the `serverUrl` flow, return it from your endpoint
54
- * alongside `sessionId`/`embedToken` (it's the `qrCodeUrl` from `createSession`);
55
- * in the `sessionId` + `embedToken` flow, pass it here.
56
- */
57
- qrCodeUrl?: string;
58
- clientMetadata?: Record<string, unknown>;
59
- lang?: WidgetLanguage;
60
- overlayColor?: string;
61
- allowManualUpload?: boolean;
62
- mount?: HTMLElement;
63
- /**
64
- * Extra headers sent with the `serverUrl` POST request.
65
- * Use this to pass Authorization tokens (e.g. JWT) when your
66
- * backend requires authentication.
67
- *
68
- * @example { Authorization: 'Bearer <jwt>' }
69
- */
70
- requestHeaders?: Record<string, string>;
71
- onSuccess?: (result: VerificationResult) => void;
72
- onError?: (error: string) => void;
73
- onCancel?: () => void;
74
- onReady?: () => void;
75
- }
76
- interface WidgetPreviewConfig {
77
- colors?: PreviewColors;
78
- documentType?: DocumentType;
79
- lang?: WidgetLanguage;
80
- overlayColor?: string;
81
- onSuccess?: (result: VerificationResult) => void;
82
- onError?: (error: string) => void;
83
- onCancel?: () => void;
84
- }
85
- interface WidgetEmbedConfig {
86
- container: string | HTMLElement;
87
- colors?: PreviewColors;
88
- device?: 'mobile' | 'desktop';
89
- scale?: number;
90
- documentType?: DocumentType;
91
- lang?: WidgetLanguage;
92
- }
93
- interface WidgetInstance {
94
- iframe: HTMLIFrameElement;
95
- destroy: () => void;
96
- }
97
- interface EmbedInstance extends WidgetInstance {
98
- setColors: (colors: Partial<PreviewColors>) => void;
99
- setDevice: (device: 'mobile' | 'desktop') => void;
100
- getColors: () => PreviewColors;
101
- }
102
- interface PreviewColors {
103
- primaryColor?: string;
104
- secondaryColor?: string;
105
- }
106
- interface VerificationResult {
107
- sessionId?: string;
108
- status?: string;
109
- [key: string]: unknown;
110
- }
111
-
112
- /**
113
- * Self-prewarming for the KYC widget.
114
- *
115
- * Warms the connection and assets to our widget origin BEFORE the user clicks
116
- * "Start", so the loader (and ultimately the widget) appears with little or no
117
- * wait. All work is scheduled at idle / after the host page's `load`, so it
118
- * never competes with the host page's own critical resources.
119
- *
120
- * Levels (`prewarm`):
121
- * - 'connect' (default): preconnect + idle prefetch of the loader/branding
122
- * assets and the widget document. Cheap; warms DNS/TLS + caches.
123
- * - 'intent': warm when the user signals intent (hover / focus / the trigger
124
- * scrolls into view). Best for widgets on general pages — no cost for
125
- * visitors who never engage.
126
- * - 'eager': also pre-mount a hidden iframe at idle so the full widget bundle
127
- * loads in the background. Best for dedicated, high-click-through KYC pages.
128
- * - 'none': do nothing.
129
- *
130
- * Never throws; SSR-safe (no-ops when there's no document). Sessions are NEVER
131
- * pre-created here — only static assets are warmed.
132
- */
133
- type PrewarmLevel = 'connect' | 'intent' | 'eager' | 'none';
134
-
135
- declare class FlonkKYC {
136
- static readonly version = "1.9.2";
137
- private readonly widgetUrl;
138
- private readonly apiBase;
139
- private disposeDiagnostics;
140
- constructor(options?: FlonkKYCOptions);
141
- /** Unregister this instance's `onDiagnostic` handler. */
142
- dispose(): void;
143
- /**
144
- * Prewarm the widget ahead of the user's click — preconnect + idle prefetch
145
- * of branding/assets, and (with `level:'eager'`) a hidden background iframe so
146
- * the full bundle is loaded before the click. Call on page mount / route
147
- * enter. Returns a cleanup (removes `intent` listeners). Never pre-creates a
148
- * session. SSR-safe.
149
- *
150
- * @example
151
- * FlonkKYC.prewarm({ publishableKey: 'pk_live_…', level: 'eager' });
152
- * // or, warm only when the user shows intent:
153
- * FlonkKYC.prewarm({ publishableKey: 'pk_live_…', level: 'intent', trigger: btn });
154
- */
155
- static prewarm(opts?: {
156
- publishableKey?: string;
157
- sessionId?: string;
158
- widgetUrl?: string;
159
- apiBase?: string;
160
- level?: PrewarmLevel;
161
- trigger?: Element | null;
162
- }): () => void;
163
- /**
164
- * Warm the project's branding (colors) ahead of time so the widget paints the
165
- * brand color on the first frame, with no branding round-trip at click time.
166
- *
167
- * Call it early — on page mount, route enter, or hover of the "verify" button
168
- * — well before `init()`. The result is cached (module-level, 5-min TTL) and
169
- * every subsequent `init()`/`open()` for the same key reads from it. Safe to
170
- * call repeatedly; concurrent calls dedupe. Never throws.
171
- *
172
- * @example
173
- * // in a layout effect, long before the user clicks "Verify"
174
- * FlonkKYC.preloadBranding({ publishableKey: 'pk_live_...' });
175
- */
176
- static preloadBranding(opts: {
177
- publishableKey?: string;
178
- sessionId?: string;
179
- apiBase?: string;
180
- }): Promise<void>;
181
- /**
182
- * Open the KYC verification widget.
183
- *
184
- * Flows (pick one; add `publishableKey` to any for an instant branded loader):
185
- * 1. `{ serverUrl }` — SDK auto-creates the session via your backend (recommended).
186
- * 2. `{ sessionId, embedToken }` — you created the session; pass its credentials.
187
- * 3. `{ sessionId }` — **deprecated**: exchanges the sessionId for an embedToken
188
- * via an extra round-trip. Prefer flow 2 by returning `embedToken` from your
189
- * backend alongside `sessionId`.
190
- * 4. `{ publishableKey }` — client-only; SDK mints a short-lived widget token.
191
- */
192
- init(config: WidgetInitConfig): Promise<WidgetInstance>;
193
- /**
194
- * Preview mode — no API calls, mock data.
195
- */
196
- preview(config?: WidgetPreviewConfig): WidgetInstance;
197
- /**
198
- * Embed inline preview in a container (for dashboards).
199
- */
200
- embed(config: WidgetEmbedConfig): EmbedInstance;
201
- /**
202
- * Flow 1: serverUrl — POST to client's backend, get sessionId + embedToken.
203
- *
204
- * When `publishableKey` is provided, design tokens are fetched in parallel
205
- * with the session creation request. This shows the branded loader ~200-500ms
206
- * faster because we don't have to wait for the session to be created first.
207
- */
208
- private initWithServerUrl;
209
- /**
210
- * Flow 2: sessionId + embedToken — fetch session data, open widget.
211
- */
212
- private initWithEmbedToken;
213
- /**
214
- * Flow 3: sessionId only — exchange for embedToken, then init.
215
- *
216
- * @deprecated Prefer flow 2 (`sessionId` + `embedToken`). Return the
217
- * `embedToken` from your backend together with the `sessionId` to skip this
218
- * extra token-exchange round-trip.
219
- */
220
- private initWithSession;
221
- /**
222
- * Flow 4: publishableKey — fetch widget token, open widget.
223
- */
224
- private initWithPublishableKey;
225
- private buildWidget;
226
- /**
227
- * Core: create iframe, attach listeners, return WidgetInstance.
228
- */
229
- private openWidget;
230
- }
231
-
232
- /**
233
- * Tiny observability sink. The SDK emits a structured diagnostic at every
234
- * degradation/branch point (loader fallback, blocked script, prewarm skipped,
235
- * ready-timeout reveal, …) so integrators — and we — can see WHY the SDK did
236
- * what it did, instead of guessing from a silent fallback.
237
- *
238
- * Module-level by necessity: several emit points (prewarm, the server-loader
239
- * script load) run outside any FlonkKYC instance (static / constructor). The
240
- * FlonkKYC constructor registers its `onDiagnostic` here; `window.__FLONK_DEBUG__`
241
- * additionally mirrors events to the console. Zero-cost when nothing is
242
- * registered and the debug flag is unset.
243
- */
244
- type DiagnosticHandler = (event: FlonkDiagnostic) => void;
245
- /** Register a diagnostic handler. Returns an unsubscribe. De-dupes by reference. */
246
- declare function addDiagnosticHandler(handler: DiagnosticHandler): () => void;
247
-
248
5
  interface FlonkKYCProps extends FlonkKYCOptions {
249
6
  publishableKey?: string;
250
7
  serverUrl?: string;
@@ -288,52 +45,4 @@ interface FlonkKYCBrandingPreloaderProps {
288
45
  */
289
46
  declare function FlonkKYCBrandingPreloader({ publishableKey, sessionId, apiBase, }: FlonkKYCBrandingPreloaderProps): null;
290
47
 
291
- /**
292
- * Stable, machine-branchable error codes returned by the API in the `code`
293
- * field of an error body. Open union (`| (string & {})`) so new codes don't
294
- * break consumers — branch on the ones you handle, fall through on the rest.
295
- */
296
- type FlonkErrorCode = 'authentication_error' | 'invalid_publishable_key' | 'session_not_found' | 'session_expired' | 'session_invalid_state' | 'rate_limited' | 'validation_error' | 'api_error' | (string & {});
297
- declare class FlonkError extends Error {
298
- readonly code: FlonkErrorCode;
299
- readonly statusCode?: number | undefined;
300
- constructor(message: string, code: FlonkErrorCode, statusCode?: number | undefined);
301
- }
302
- declare class FlonkValidationError extends FlonkError {
303
- constructor(message: string);
304
- }
305
-
306
- declare const SDK_VERSION = "1.9.2";
307
- /**
308
- * REST API version this SDK is built against (date-pinned, separate from the
309
- * package version). Sent as the `Flonk-Version` header so a future breaking API
310
- * change can be served the old shape to old SDKs and the new shape to new ones.
311
- * The API is additive-only within a version; a breaking change mints a new date.
312
- */
313
- declare const API_VERSION = "2026-06-01";
314
- declare const PROTOCOL_VERSION = 1;
315
- /** postMessage `type` values exchanged between the SDK and the iframe. */
316
- declare const WIDGET_EVENTS: {
317
- readonly READY: "KYC_WIDGET_READY";
318
- readonly COMPLETE: "KYC_COMPLETE";
319
- readonly CANCEL: "KYC_CANCEL";
320
- readonly ERROR: "KYC_ERROR";
321
- readonly CONFIG: "KYC_WIDGET_CONFIG";
322
- };
323
- /** Canonical iframe URL param keys the SDK stamps onto the widget src. */
324
- declare const WIDGET_PARAMS: {
325
- readonly PROTOCOL_VERSION: "pv";
326
- readonly SESSION_ID: "sessionId";
327
- readonly EMBED_TOKEN: "embedToken";
328
- readonly TOKEN: "token";
329
- readonly PUBLISHABLE_KEY: "publishableKey";
330
- readonly CLIENT_ID: "clientId";
331
- readonly CLIENT_METADATA: "clientMetadata";
332
- readonly DESIGN_TOKENS: "designTokens";
333
- readonly ALLOW_MANUAL_UPLOAD: "allowManualUpload";
334
- readonly LANG: "lang";
335
- readonly OVERLAY_COLOR: "overlayColor";
336
- readonly MODE: "mode";
337
- };
338
-
339
- export { API_VERSION, type DocumentType, type EmbedInstance, type FlonkDiagnostic, type FlonkDiagnosticCode, type FlonkDiagnosticLevel, FlonkError, type FlonkErrorCode, FlonkKYC, FlonkKYCBrandingPreloader, type FlonkKYCBrandingPreloaderProps, type FlonkKYCOptions, type FlonkKYCProps, FlonkKYCWidget, FlonkValidationError, PROTOCOL_VERSION, type PreviewColors, SDK_VERSION, type VerificationResult, WIDGET_EVENTS, WIDGET_PARAMS, type WidgetEmbedConfig, type WidgetInitConfig, type WidgetInstance, type WidgetLanguage, type WidgetPreviewConfig, addDiagnosticHandler };
48
+ export { FlonkKYCBrandingPreloader, type FlonkKYCBrandingPreloaderProps, FlonkKYCOptions, type FlonkKYCProps, FlonkKYCWidget, VerificationResult, WidgetLanguage };