@flonkid/kyc 1.8.2 → 1.9.0

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
@@ -2,9 +2,32 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
 
3
3
  type DocumentType = 'passport' | 'id_card' | 'driver_license';
4
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
+ }
5
21
  interface FlonkKYCOptions {
6
22
  widgetUrl?: string;
7
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;
8
31
  }
9
32
  interface WidgetInitConfig {
10
33
  serverUrl?: string;
@@ -79,11 +102,57 @@ interface VerificationResult {
79
102
  [key: string]: unknown;
80
103
  }
81
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
+
82
128
  declare class FlonkKYC {
83
- static readonly version = "1.8.2";
129
+ static readonly version = "1.9.0";
84
130
  private readonly widgetUrl;
85
131
  private readonly apiBase;
132
+ private disposeDiagnostics;
86
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;
87
156
  /**
88
157
  * Warm the project's branding (colors) ahead of time so the widget paints the
89
158
  * brand color on the first frame, with no branding round-trip at click time.
@@ -153,6 +222,22 @@ declare class FlonkKYC {
153
222
  private openWidget;
154
223
  }
155
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
+
156
241
  interface FlonkKYCProps extends FlonkKYCOptions {
157
242
  publishableKey?: string;
158
243
  serverUrl?: string;
@@ -196,13 +281,52 @@ interface FlonkKYCBrandingPreloaderProps {
196
281
  */
197
282
  declare function FlonkKYCBrandingPreloader({ publishableKey, sessionId, apiBase, }: FlonkKYCBrandingPreloaderProps): null;
198
283
 
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 & {});
199
290
  declare class FlonkError extends Error {
200
- readonly code: string;
291
+ readonly code: FlonkErrorCode;
201
292
  readonly statusCode?: number | undefined;
202
- constructor(message: string, code: string, statusCode?: number | undefined);
293
+ constructor(message: string, code: FlonkErrorCode, statusCode?: number | undefined);
203
294
  }
204
295
  declare class FlonkValidationError extends FlonkError {
205
296
  constructor(message: string);
206
297
  }
207
298
 
208
- export { type DocumentType, type EmbedInstance, FlonkError, FlonkKYC, FlonkKYCBrandingPreloader, type FlonkKYCBrandingPreloaderProps, type FlonkKYCOptions, type FlonkKYCProps, FlonkKYCWidget, FlonkValidationError, type PreviewColors, type VerificationResult, type WidgetEmbedConfig, type WidgetInitConfig, type WidgetInstance, type WidgetLanguage, type WidgetPreviewConfig };
299
+ declare const SDK_VERSION = "1.9.0";
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 };
package/dist/index.d.ts CHANGED
@@ -2,9 +2,32 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
 
3
3
  type DocumentType = 'passport' | 'id_card' | 'driver_license';
4
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
+ }
5
21
  interface FlonkKYCOptions {
6
22
  widgetUrl?: string;
7
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;
8
31
  }
9
32
  interface WidgetInitConfig {
10
33
  serverUrl?: string;
@@ -79,11 +102,57 @@ interface VerificationResult {
79
102
  [key: string]: unknown;
80
103
  }
81
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
+
82
128
  declare class FlonkKYC {
83
- static readonly version = "1.8.2";
129
+ static readonly version = "1.9.0";
84
130
  private readonly widgetUrl;
85
131
  private readonly apiBase;
132
+ private disposeDiagnostics;
86
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;
87
156
  /**
88
157
  * Warm the project's branding (colors) ahead of time so the widget paints the
89
158
  * brand color on the first frame, with no branding round-trip at click time.
@@ -153,6 +222,22 @@ declare class FlonkKYC {
153
222
  private openWidget;
154
223
  }
155
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
+
156
241
  interface FlonkKYCProps extends FlonkKYCOptions {
157
242
  publishableKey?: string;
158
243
  serverUrl?: string;
@@ -196,13 +281,52 @@ interface FlonkKYCBrandingPreloaderProps {
196
281
  */
197
282
  declare function FlonkKYCBrandingPreloader({ publishableKey, sessionId, apiBase, }: FlonkKYCBrandingPreloaderProps): null;
198
283
 
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 & {});
199
290
  declare class FlonkError extends Error {
200
- readonly code: string;
291
+ readonly code: FlonkErrorCode;
201
292
  readonly statusCode?: number | undefined;
202
- constructor(message: string, code: string, statusCode?: number | undefined);
293
+ constructor(message: string, code: FlonkErrorCode, statusCode?: number | undefined);
203
294
  }
204
295
  declare class FlonkValidationError extends FlonkError {
205
296
  constructor(message: string);
206
297
  }
207
298
 
208
- export { type DocumentType, type EmbedInstance, FlonkError, FlonkKYC, FlonkKYCBrandingPreloader, type FlonkKYCBrandingPreloaderProps, type FlonkKYCOptions, type FlonkKYCProps, FlonkKYCWidget, FlonkValidationError, type PreviewColors, type VerificationResult, type WidgetEmbedConfig, type WidgetInitConfig, type WidgetInstance, type WidgetLanguage, type WidgetPreviewConfig };
299
+ declare const SDK_VERSION = "1.9.0";
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 };