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