@arkyc/widget 1.0.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/README.md +85 -0
- package/dist/ArkycWidget.d.mts +50 -0
- package/dist/ArkycWidget.d.mts.map +1 -0
- package/dist/ArkycWidget.mjs +80 -0
- package/dist/ArkycWidget.mjs.map +1 -0
- package/dist/WidgetHandler.d.mts +24 -0
- package/dist/WidgetHandler.d.mts.map +1 -0
- package/dist/WidgetHandler.mjs +28 -0
- package/dist/WidgetHandler.mjs.map +1 -0
- package/dist/_virtual/_virtual_arkyc-theme-css.mjs +4 -0
- package/dist/arkyc-widget.iife.global.js +670 -0
- package/dist/arkyc-widget.iife.global.js.map +1 -0
- package/dist/capture.d.mts +73 -0
- package/dist/capture.d.mts.map +1 -0
- package/dist/capture.mjs +126 -0
- package/dist/capture.mjs.map +1 -0
- package/dist/client.d.mts +152 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +120 -0
- package/dist/client.mjs.map +1 -0
- package/dist/controller.d.mts +126 -0
- package/dist/controller.d.mts.map +1 -0
- package/dist/controller.mjs +582 -0
- package/dist/controller.mjs.map +1 -0
- package/dist/countries.mjs +967 -0
- package/dist/countries.mjs.map +1 -0
- package/dist/device.mjs +17 -0
- package/dist/device.mjs.map +1 -0
- package/dist/document.d.mts +108 -0
- package/dist/document.d.mts.map +1 -0
- package/dist/document.mjs +227 -0
- package/dist/document.mjs.map +1 -0
- package/dist/face.d.mts +82 -0
- package/dist/face.d.mts.map +1 -0
- package/dist/face.mjs +230 -0
- package/dist/face.mjs.map +1 -0
- package/dist/flow.d.mts +74 -0
- package/dist/flow.d.mts.map +1 -0
- package/dist/flow.mjs +132 -0
- package/dist/flow.mjs.map +1 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +16 -0
- package/dist/index.mjs.map +1 -0
- package/dist/qr.mjs +22 -0
- package/dist/qr.mjs.map +1 -0
- package/dist/realtime.d.mts +29 -0
- package/dist/realtime.d.mts.map +1 -0
- package/dist/realtime.mjs +107 -0
- package/dist/realtime.mjs.map +1 -0
- package/dist/theme.d.mts +42 -0
- package/dist/theme.d.mts.map +1 -0
- package/dist/theme.mjs +77 -0
- package/dist/theme.mjs.map +1 -0
- package/dist/types.d.mts +153 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/ui.mjs +931 -0
- package/dist/ui.mjs.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { ArkycClient, WidgetApiError } from "./client.mjs";
|
|
2
|
+
import { createWidgetRealtimeClient } from "./realtime.mjs";
|
|
3
|
+
import { Theme } from "./theme.mjs";
|
|
4
|
+
import { Flow } from "./flow.mjs";
|
|
5
|
+
import { WidgetView } from "./ui.mjs";
|
|
6
|
+
import { isDesktopDevice } from "./device.mjs";
|
|
7
|
+
import { renderQrSvg } from "./qr.mjs";
|
|
8
|
+
import { REALTIME_EVENT } from "@arkyc/types";
|
|
9
|
+
//#region src/controller.ts
|
|
10
|
+
/** Per-step lead-in copy shown before each capture/liveness step. */
|
|
11
|
+
const STEP_INSTRUCTIONS = {
|
|
12
|
+
front_capture: {
|
|
13
|
+
title: "Front of your document",
|
|
14
|
+
body: "Place the front of your ID flat and fully inside the frame. We’ll capture it automatically."
|
|
15
|
+
},
|
|
16
|
+
back_capture: {
|
|
17
|
+
title: "Back of your document",
|
|
18
|
+
body: "Now turn your ID over and show the back, fully inside the frame."
|
|
19
|
+
},
|
|
20
|
+
selfie_capture: {
|
|
21
|
+
title: "Take a selfie",
|
|
22
|
+
body: "Look straight at the camera in good light and hold still — we’ll capture it automatically."
|
|
23
|
+
},
|
|
24
|
+
active_liveness: {
|
|
25
|
+
title: "Quick liveness check",
|
|
26
|
+
body: "Follow the on-screen prompts (such as turn your head, blink or smile). This confirms you’re really here."
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Drives the full verification flow: renders each screen via {@link WidgetView},
|
|
31
|
+
* advances through {@link flow}, and calls the Client API at each step. Cosmetic
|
|
32
|
+
* processing screens auto-advance; capture screens wait for an image. On a
|
|
33
|
+
* terminal result it surfaces the outcome and (in hosted mode) posts
|
|
34
|
+
* `arkyc:complete` / `arkyc:error` / `arkyc:close` to the parent window.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Re-base the server-resolved project logo onto the API origin the widget is
|
|
38
|
+
* actually talking to. The stored `logo_url` carries the API's own host, which a
|
|
39
|
+
* handed-off phone cannot reach — it reaches the API through the absolute
|
|
40
|
+
* `baseUrl` passed in the handoff link. Rewriting the origin (keeping the path)
|
|
41
|
+
* makes the logo load on whatever device runs the widget. Only applied when
|
|
42
|
+
* `baseUrl` is absolute; the integrator's own branding is never re-based.
|
|
43
|
+
*/
|
|
44
|
+
function rebaseBrandingLogo(branding, baseUrl) {
|
|
45
|
+
const logo = branding.logo_url;
|
|
46
|
+
if (!logo || !baseUrl || !/^https?:\/\//i.test(baseUrl)) return branding;
|
|
47
|
+
try {
|
|
48
|
+
const base = new URL(baseUrl);
|
|
49
|
+
const resolved = new URL(logo, base);
|
|
50
|
+
if (resolved.origin === base.origin) return branding;
|
|
51
|
+
return {
|
|
52
|
+
...branding,
|
|
53
|
+
logo_url: `${base.origin}${resolved.pathname}${resolved.search}${resolved.hash}`
|
|
54
|
+
};
|
|
55
|
+
} catch {
|
|
56
|
+
return branding;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
var WidgetController = class {
|
|
60
|
+
config;
|
|
61
|
+
client;
|
|
62
|
+
view;
|
|
63
|
+
win;
|
|
64
|
+
nav;
|
|
65
|
+
postToParent;
|
|
66
|
+
scheduler;
|
|
67
|
+
transientMs;
|
|
68
|
+
pollMs;
|
|
69
|
+
maxPolls;
|
|
70
|
+
maxHandoffPolls;
|
|
71
|
+
/** Cross-device handoff: project config + whether the offer/QR is showing. */
|
|
72
|
+
handoffConfig = {
|
|
73
|
+
enabled: false,
|
|
74
|
+
allow_desktop: true,
|
|
75
|
+
url: ""
|
|
76
|
+
};
|
|
77
|
+
handoffReady = false;
|
|
78
|
+
handoffActive = false;
|
|
79
|
+
/** This session's id + how to watch it live (push transport vs. polling). */
|
|
80
|
+
sessionId = "";
|
|
81
|
+
realtimeConfig = null;
|
|
82
|
+
rtClient = null;
|
|
83
|
+
rtResolved = false;
|
|
84
|
+
/** The last status observed, so a transition only emits once per change. */
|
|
85
|
+
lastStatus = null;
|
|
86
|
+
/** Per-name event listeners registered via {@link on}. */
|
|
87
|
+
listeners = /* @__PURE__ */ new Map();
|
|
88
|
+
/** Cancels the active session watch (e.g. continue-on-this-device). */
|
|
89
|
+
stopWatch;
|
|
90
|
+
step = "welcome";
|
|
91
|
+
documentType = null;
|
|
92
|
+
country = null;
|
|
93
|
+
selfie = null;
|
|
94
|
+
livenessMode = "passive";
|
|
95
|
+
/** The session's capture model; `active` mandates a live camera (no fallback). */
|
|
96
|
+
captureModel = "passive";
|
|
97
|
+
livenessChallenges = [];
|
|
98
|
+
/** The applied workflow (orders/toggles stages, skip_ocr), or null for the default flow. */
|
|
99
|
+
workflow = null;
|
|
100
|
+
result = null;
|
|
101
|
+
/** The session was already terminal when the widget loaded (show a close-only notice). */
|
|
102
|
+
terminalOnLoad = false;
|
|
103
|
+
/** Whether the current step's instruction interstitial has been acknowledged. */
|
|
104
|
+
instructionAcked = false;
|
|
105
|
+
pendingError = null;
|
|
106
|
+
settled = false;
|
|
107
|
+
constructor(config) {
|
|
108
|
+
this.config = config;
|
|
109
|
+
const doc = config.doc ?? globalThis.document;
|
|
110
|
+
const win = config.win ?? globalThis.window;
|
|
111
|
+
if (!doc || !win) throw new Error("The Arkyc widget must run in a browser environment.");
|
|
112
|
+
this.win = win;
|
|
113
|
+
this.nav = config.nav ?? globalThis.navigator;
|
|
114
|
+
this.client = new ArkycClient({
|
|
115
|
+
token: config.token,
|
|
116
|
+
baseUrl: config.baseUrl,
|
|
117
|
+
fetch: config.fetch
|
|
118
|
+
});
|
|
119
|
+
const theme = new Theme(config.branding);
|
|
120
|
+
this.view = new WidgetView(doc, theme, this.handlers(), config.nav ?? globalThis.navigator, config.faceAnalyzer, config.faceTuning, config.documentAnalyzer, config.documentTuning);
|
|
121
|
+
this.postToParent = config.postToParent ?? (!!win.parent && win.parent !== win);
|
|
122
|
+
this.scheduler = config.scheduler ?? ((fn, ms) => setTimeout(fn, ms));
|
|
123
|
+
this.transientMs = config.transientMs ?? 700;
|
|
124
|
+
this.pollMs = config.pollMs ?? 1500;
|
|
125
|
+
this.maxPolls = config.maxPolls ?? 40;
|
|
126
|
+
this.maxHandoffPolls = config.maxHandoffPolls ?? 600;
|
|
127
|
+
}
|
|
128
|
+
/** The widget's root element — append it to an overlay or inline container. */
|
|
129
|
+
get element() {
|
|
130
|
+
return this.view.element;
|
|
131
|
+
}
|
|
132
|
+
/** Connect to the session, then route to the result, the QR, or the welcome flow. */
|
|
133
|
+
start() {
|
|
134
|
+
this.view.renderLoading();
|
|
135
|
+
this.run(() => this.bootstrap());
|
|
136
|
+
}
|
|
137
|
+
/** Tear down the view and release the camera (does not fire callbacks). */
|
|
138
|
+
destroy() {
|
|
139
|
+
this.view.destroy();
|
|
140
|
+
}
|
|
141
|
+
/** Close the widget as if the user dismissed it (fires `onClose`/`onSettle`). */
|
|
142
|
+
close() {
|
|
143
|
+
this.finishClose();
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Subscribe to a named widget event; returns an unsubscribe function. Having a
|
|
147
|
+
* listener (here or via `onEvent`) is what activates the event stream.
|
|
148
|
+
*/
|
|
149
|
+
on(event, listener) {
|
|
150
|
+
const set = this.listeners.get(event) ?? /* @__PURE__ */ new Set();
|
|
151
|
+
set.add(listener);
|
|
152
|
+
this.listeners.set(event, set);
|
|
153
|
+
return () => set.delete(listener);
|
|
154
|
+
}
|
|
155
|
+
/** Whether anyone is listening for `name` (the firehose or a named listener). */
|
|
156
|
+
hasListener(name) {
|
|
157
|
+
if (this.config.onEvent) return true;
|
|
158
|
+
const set = this.listeners.get(name);
|
|
159
|
+
return !!set && set.size > 0;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Surface an event: to local listeners (firehose + `on`), and — in hosted
|
|
163
|
+
* iframe mode — to the embedding parent as `arkyc:event` so the SDK's
|
|
164
|
+
* `handle.on(...)` works across the frame.
|
|
165
|
+
*/
|
|
166
|
+
dispatch(name, data) {
|
|
167
|
+
this.emit(name, data);
|
|
168
|
+
this.post("arkyc:event", {
|
|
169
|
+
name,
|
|
170
|
+
data
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/** Emit an event to the firehose + named listeners — but only if one is active. */
|
|
174
|
+
emit(name, data) {
|
|
175
|
+
if (!this.hasListener(name)) return;
|
|
176
|
+
try {
|
|
177
|
+
this.config.onEvent?.({
|
|
178
|
+
name,
|
|
179
|
+
data
|
|
180
|
+
});
|
|
181
|
+
} catch {}
|
|
182
|
+
const set = this.listeners.get(name);
|
|
183
|
+
if (set) for (const listener of [...set]) try {
|
|
184
|
+
listener(data);
|
|
185
|
+
} catch {}
|
|
186
|
+
}
|
|
187
|
+
/** Record an observed status, emitting `session.transition` on a real change. */
|
|
188
|
+
observe(status) {
|
|
189
|
+
if (status === this.lastStatus) return;
|
|
190
|
+
const previous = this.lastStatus;
|
|
191
|
+
this.lastStatus = status;
|
|
192
|
+
this.dispatch(REALTIME_EVENT.sessionTransition, {
|
|
193
|
+
session_id: this.sessionId,
|
|
194
|
+
status,
|
|
195
|
+
previous_status: previous
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Lazily connect the push transport for this session (once). Returns null for
|
|
200
|
+
* `polling`/`off`/`memory` or when the transport SDK can't load — the caller
|
|
201
|
+
* then polls instead.
|
|
202
|
+
*/
|
|
203
|
+
async resolveRealtime() {
|
|
204
|
+
if (this.rtResolved) return this.rtClient;
|
|
205
|
+
this.rtResolved = true;
|
|
206
|
+
const cfg = this.realtimeConfig;
|
|
207
|
+
if (!cfg || cfg.transport === "polling" || cfg.transport === "off" || cfg.transport === "memory") return null;
|
|
208
|
+
const factory = this.config.realtimeFactory ?? createWidgetRealtimeClient;
|
|
209
|
+
const apiBase = (this.config.baseUrl ?? "").replace(/\/$/, "");
|
|
210
|
+
try {
|
|
211
|
+
this.rtClient = await factory(cfg, {
|
|
212
|
+
authEndpoint: `${apiBase}/v1/client/realtime/auth`,
|
|
213
|
+
token: this.config.token
|
|
214
|
+
});
|
|
215
|
+
} catch {
|
|
216
|
+
this.rtClient = null;
|
|
217
|
+
}
|
|
218
|
+
return this.rtClient;
|
|
219
|
+
}
|
|
220
|
+
handlers() {
|
|
221
|
+
return {
|
|
222
|
+
onClose: () => this.finishClose(),
|
|
223
|
+
onStart: () => void this.run(() => this.enter(this.next())),
|
|
224
|
+
onDocumentSelected: (type, country) => {
|
|
225
|
+
this.documentType = type;
|
|
226
|
+
this.country = country || null;
|
|
227
|
+
this.run(() => this.enter("front_capture"));
|
|
228
|
+
},
|
|
229
|
+
onImage: (blob) => void this.run(() => this.onImage(blob)),
|
|
230
|
+
onActiveLiveness: (video, performed, selfie) => void this.run(async () => {
|
|
231
|
+
await this.client.submitLiveness({
|
|
232
|
+
selfie,
|
|
233
|
+
video,
|
|
234
|
+
mode: "active",
|
|
235
|
+
challenges: performed,
|
|
236
|
+
signals: this.config.signals
|
|
237
|
+
});
|
|
238
|
+
await this.enter(this.next());
|
|
239
|
+
}),
|
|
240
|
+
onAcknowledge: () => this.finishResult(),
|
|
241
|
+
onUsePhone: () => void this.run(() => this.startHandoff()),
|
|
242
|
+
onContinueHere: () => {
|
|
243
|
+
this.handoffActive = false;
|
|
244
|
+
this.stopWatch?.();
|
|
245
|
+
this.step = "welcome";
|
|
246
|
+
this.render();
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Fetch the session and route: an already-terminal session (e.g. a stale handoff
|
|
252
|
+
* link, or one finished on another device) shows a close-only notice; on a
|
|
253
|
+
* desktop with handoff enabled we lead with the QR; otherwise the welcome flow.
|
|
254
|
+
*/
|
|
255
|
+
async bootstrap() {
|
|
256
|
+
if (this.settled) return;
|
|
257
|
+
const session = await this.client.getSession();
|
|
258
|
+
if (this.settled) return;
|
|
259
|
+
this.sessionId = session.id;
|
|
260
|
+
this.realtimeConfig = session.realtime ?? null;
|
|
261
|
+
this.workflow = session.workflow ?? null;
|
|
262
|
+
if (this.config.branding == null && session.branding) this.view.applyBranding(rebaseBrandingLogo(session.branding, this.config.baseUrl));
|
|
263
|
+
this.observe(session.status);
|
|
264
|
+
if (Flow.isTerminal(session.status)) return this.showTerminal(session.status);
|
|
265
|
+
this.resolveLiveness(session);
|
|
266
|
+
if (session.handoff) this.handoffConfig = session.handoff;
|
|
267
|
+
if (this.config.handoff !== false && isDesktopDevice(this.nav) && this.handoffConfig.enabled && !!this.handoffTarget()) {
|
|
268
|
+
this.handoffReady = true;
|
|
269
|
+
await this.startHandoff();
|
|
270
|
+
} else {
|
|
271
|
+
this.step = "welcome";
|
|
272
|
+
this.render();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/** The hosted handoff page URL: a consumer override, else the server-provided one. */
|
|
276
|
+
handoffTarget() {
|
|
277
|
+
return (this.config.handoffUrl ?? this.handoffConfig.url ?? "").trim();
|
|
278
|
+
}
|
|
279
|
+
/** Render the QR for this session and wait for the other device to finish. */
|
|
280
|
+
async startHandoff() {
|
|
281
|
+
const target = this.handoffTarget();
|
|
282
|
+
if (!target) return;
|
|
283
|
+
this.handoffActive = true;
|
|
284
|
+
this.view.renderHandoff(renderQrSvg(this.buildHandoffUrl(target)), this.handoffConfig.allow_desktop);
|
|
285
|
+
await this.pollHandoff();
|
|
286
|
+
}
|
|
287
|
+
/** Build the hosted-page URL the QR encodes (carries the session token). */
|
|
288
|
+
buildHandoffUrl(target) {
|
|
289
|
+
let url = `${target}${target.includes("?") ? "&" : "?"}token=${encodeURIComponent(this.config.token)}`;
|
|
290
|
+
const apiBase = (this.config.baseUrl ?? "").trim();
|
|
291
|
+
if (/^https?:\/\//i.test(apiBase)) url += `&baseUrl=${encodeURIComponent(apiBase)}`;
|
|
292
|
+
return url;
|
|
293
|
+
}
|
|
294
|
+
/** Watch the session while the user verifies on the other device; mirror the result. */
|
|
295
|
+
async pollHandoff() {
|
|
296
|
+
const rt = await this.resolveRealtime();
|
|
297
|
+
if (rt) {
|
|
298
|
+
const status = await this.pushWatch(rt, this.maxHandoffPolls, () => this.handoffActive && !this.settled);
|
|
299
|
+
if (status) {
|
|
300
|
+
this.handoffActive = false;
|
|
301
|
+
return this.showResult(status);
|
|
302
|
+
}
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
let errors = 0;
|
|
306
|
+
for (let i = 0; i < this.maxHandoffPolls && this.handoffActive && !this.settled; i++) {
|
|
307
|
+
await this.delay(this.pollMs);
|
|
308
|
+
if (!this.handoffActive || this.settled) return;
|
|
309
|
+
try {
|
|
310
|
+
const session = await this.client.getSession();
|
|
311
|
+
errors = 0;
|
|
312
|
+
this.observe(session.status);
|
|
313
|
+
if (Flow.isTerminal(session.status)) {
|
|
314
|
+
this.handoffActive = false;
|
|
315
|
+
return this.showResult(session.status);
|
|
316
|
+
}
|
|
317
|
+
} catch (error) {
|
|
318
|
+
if (error instanceof WidgetApiError && error.status === 401) {
|
|
319
|
+
this.handoffActive = false;
|
|
320
|
+
return this.showResult("expired");
|
|
321
|
+
}
|
|
322
|
+
if (++errors >= 5) return;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Await a terminal status over the push transport. Resolves to the terminal
|
|
328
|
+
* status, or null if `active()` went false or the tick budget elapsed (push can
|
|
329
|
+
* miss events / disconnect; the budget bounds the wait). An initial fetch
|
|
330
|
+
* catches a session that finished before we subscribed.
|
|
331
|
+
*/
|
|
332
|
+
pushWatch(rt, budget, active) {
|
|
333
|
+
return new Promise((resolve) => {
|
|
334
|
+
let done = false;
|
|
335
|
+
const finish = (status) => {
|
|
336
|
+
if (done) return;
|
|
337
|
+
done = true;
|
|
338
|
+
this.stopWatch = void 0;
|
|
339
|
+
unsubscribe();
|
|
340
|
+
resolve(status);
|
|
341
|
+
};
|
|
342
|
+
const channel = this.realtimeConfig.channel;
|
|
343
|
+
const unsubscribe = rt.subscribe(channel, (event, data) => {
|
|
344
|
+
if (event !== REALTIME_EVENT.sessionTransition) return;
|
|
345
|
+
const status = data.status;
|
|
346
|
+
this.observe(status);
|
|
347
|
+
if (Flow.isTerminal(status)) finish(status);
|
|
348
|
+
});
|
|
349
|
+
this.stopWatch = () => finish(null);
|
|
350
|
+
this.client.getSession().then((session) => {
|
|
351
|
+
this.observe(session.status);
|
|
352
|
+
if (Flow.isTerminal(session.status)) finish(session.status);
|
|
353
|
+
}).catch((error) => {
|
|
354
|
+
if (error instanceof WidgetApiError && error.status === 401) finish("expired");
|
|
355
|
+
});
|
|
356
|
+
const countdown = async (n) => {
|
|
357
|
+
if (done) return;
|
|
358
|
+
if (!active() || n >= budget) return finish(null);
|
|
359
|
+
await this.delay(this.pollMs);
|
|
360
|
+
countdown(n + 1);
|
|
361
|
+
};
|
|
362
|
+
countdown(0);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
/** Resolve which liveness flow to run from the session's capture model. */
|
|
366
|
+
resolveLiveness(session) {
|
|
367
|
+
this.livenessChallenges = session.liveness_challenges ?? [];
|
|
368
|
+
const model = session.capture_model ?? "passive";
|
|
369
|
+
this.captureModel = model;
|
|
370
|
+
const wantsActive = model === "active" || model === "both";
|
|
371
|
+
this.livenessMode = wantsActive && (model === "active" || this.view.cameraSupported) ? "active" : "passive";
|
|
372
|
+
}
|
|
373
|
+
async onImage(blob) {
|
|
374
|
+
const signals = this.config.signals;
|
|
375
|
+
switch (this.step) {
|
|
376
|
+
case "front_capture":
|
|
377
|
+
await this.client.submitDocumentFront({
|
|
378
|
+
image: blob,
|
|
379
|
+
country: this.country,
|
|
380
|
+
documentType: this.documentType,
|
|
381
|
+
signals
|
|
382
|
+
});
|
|
383
|
+
return this.enter(this.next());
|
|
384
|
+
case "back_capture":
|
|
385
|
+
await this.client.submitDocumentBack({
|
|
386
|
+
image: blob,
|
|
387
|
+
country: this.country,
|
|
388
|
+
documentType: this.documentType
|
|
389
|
+
});
|
|
390
|
+
return this.enter("ocr_processing");
|
|
391
|
+
case "selfie_capture":
|
|
392
|
+
this.selfie = blob;
|
|
393
|
+
return this.enter("passive_liveness");
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/** Enter a step: render it, and drive any automatic (processing) work. */
|
|
397
|
+
async enter(step) {
|
|
398
|
+
if (this.settled) return;
|
|
399
|
+
this.step = step;
|
|
400
|
+
const instruction = STEP_INSTRUCTIONS[step];
|
|
401
|
+
if (instruction && !this.instructionAcked) {
|
|
402
|
+
this.view.renderInstruction(step, instruction.title, instruction.body, instruction.cta ?? "Continue", () => {
|
|
403
|
+
this.instructionAcked = true;
|
|
404
|
+
this.run(() => this.enter(step));
|
|
405
|
+
});
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
this.instructionAcked = false;
|
|
409
|
+
this.render();
|
|
410
|
+
switch (step) {
|
|
411
|
+
case "ocr_processing":
|
|
412
|
+
await this.delay(this.transientMs);
|
|
413
|
+
return this.enter(this.next());
|
|
414
|
+
case "passive_liveness":
|
|
415
|
+
await this.client.submitLiveness({
|
|
416
|
+
selfie: this.selfie,
|
|
417
|
+
signals: this.config.signals
|
|
418
|
+
});
|
|
419
|
+
return this.enter(this.next());
|
|
420
|
+
case "face_match":
|
|
421
|
+
await this.client.complete({ signals: this.config.signals });
|
|
422
|
+
return this.enter(this.next());
|
|
423
|
+
case "processing": return this.poll();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/** Watch the session until it reaches a terminal status (then show the result). */
|
|
427
|
+
async poll() {
|
|
428
|
+
const rt = await this.resolveRealtime();
|
|
429
|
+
if (rt) {
|
|
430
|
+
const status = await this.pushWatch(rt, this.maxPolls, () => !this.settled);
|
|
431
|
+
return this.showResult(status ?? "requires_review");
|
|
432
|
+
}
|
|
433
|
+
for (let i = 0; i < this.maxPolls && !this.settled; i++) {
|
|
434
|
+
const session = await this.client.getSession();
|
|
435
|
+
this.observe(session.status);
|
|
436
|
+
if (Flow.isTerminal(session.status)) return this.showResult(session.status);
|
|
437
|
+
await this.delay(this.pollMs);
|
|
438
|
+
}
|
|
439
|
+
this.showResult("requires_review");
|
|
440
|
+
}
|
|
441
|
+
showResult(status) {
|
|
442
|
+
this.result = {
|
|
443
|
+
status,
|
|
444
|
+
decision: Flow.statusToDecision(status)
|
|
445
|
+
};
|
|
446
|
+
this.step = "result";
|
|
447
|
+
this.render();
|
|
448
|
+
}
|
|
449
|
+
/** A session that was already terminal on load: a notice with only a Close button. */
|
|
450
|
+
showTerminal(status) {
|
|
451
|
+
this.result = {
|
|
452
|
+
status,
|
|
453
|
+
decision: Flow.statusToDecision(status)
|
|
454
|
+
};
|
|
455
|
+
this.step = "result";
|
|
456
|
+
this.terminalOnLoad = true;
|
|
457
|
+
this.render();
|
|
458
|
+
}
|
|
459
|
+
render() {
|
|
460
|
+
this.view.render({
|
|
461
|
+
step: this.step,
|
|
462
|
+
documentType: this.documentType,
|
|
463
|
+
decision: this.result?.decision,
|
|
464
|
+
status: this.result?.status,
|
|
465
|
+
terminalNotice: this.terminalOnLoad,
|
|
466
|
+
allowSkip: !!this.config.signals,
|
|
467
|
+
livenessChallenges: this.livenessChallenges,
|
|
468
|
+
requireLiveCamera: this.captureModel === "active",
|
|
469
|
+
strictCapture: this.livenessMode === "active",
|
|
470
|
+
handoffAvailable: this.handoffReady
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
next() {
|
|
474
|
+
return Flow.nextStep(this.step, {
|
|
475
|
+
documentType: this.documentType,
|
|
476
|
+
livenessMode: this.livenessMode,
|
|
477
|
+
workflow: this.workflow
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
delay(ms) {
|
|
481
|
+
return new Promise((resolve) => this.scheduler(resolve, ms));
|
|
482
|
+
}
|
|
483
|
+
/** Run an async step, routing any failure to the error screen. */
|
|
484
|
+
async run(fn) {
|
|
485
|
+
try {
|
|
486
|
+
await fn();
|
|
487
|
+
} catch (error) {
|
|
488
|
+
this.fail(error);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
fail(error) {
|
|
492
|
+
if (this.settled) return;
|
|
493
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
494
|
+
this.step = "result";
|
|
495
|
+
this.view.render({
|
|
496
|
+
step: "result",
|
|
497
|
+
documentType: this.documentType,
|
|
498
|
+
errorMessage: err.message
|
|
499
|
+
});
|
|
500
|
+
this.pendingError = err;
|
|
501
|
+
}
|
|
502
|
+
finishResult() {
|
|
503
|
+
if (this.settled) return;
|
|
504
|
+
this.settled = true;
|
|
505
|
+
this.teardownRealtime();
|
|
506
|
+
if (this.pendingError) {
|
|
507
|
+
this.post("arkyc:error", { error: serializeError(this.pendingError) });
|
|
508
|
+
this.dispatch("error", { message: this.pendingError.message });
|
|
509
|
+
this.config.onError?.(this.pendingError);
|
|
510
|
+
} else if (this.result) {
|
|
511
|
+
this.post("arkyc:complete", { payload: this.result });
|
|
512
|
+
this.dispatch("complete", this.result);
|
|
513
|
+
this.config.onComplete?.(this.result);
|
|
514
|
+
}
|
|
515
|
+
this.destroy();
|
|
516
|
+
this.config.onSettle?.();
|
|
517
|
+
}
|
|
518
|
+
finishClose() {
|
|
519
|
+
if (this.settled) return;
|
|
520
|
+
this.settled = true;
|
|
521
|
+
this.teardownRealtime();
|
|
522
|
+
this.post("arkyc:close", {});
|
|
523
|
+
this.dispatch("close");
|
|
524
|
+
this.config.onClose?.();
|
|
525
|
+
this.destroy();
|
|
526
|
+
this.config.onSettle?.();
|
|
527
|
+
}
|
|
528
|
+
/** Stop any active session watch + disconnect the push transport. */
|
|
529
|
+
teardownRealtime() {
|
|
530
|
+
this.stopWatch?.();
|
|
531
|
+
this.rtClient?.disconnect();
|
|
532
|
+
this.rtClient = null;
|
|
533
|
+
}
|
|
534
|
+
post(type, extra) {
|
|
535
|
+
if (!this.postToParent) return;
|
|
536
|
+
try {
|
|
537
|
+
this.win.parent?.postMessage({
|
|
538
|
+
type,
|
|
539
|
+
...extra
|
|
540
|
+
}, "*");
|
|
541
|
+
} catch {}
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
function serializeError(error) {
|
|
545
|
+
return {
|
|
546
|
+
message: error.message,
|
|
547
|
+
name: error.name
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
const resolveContainer = (container, doc) => {
|
|
551
|
+
const el = typeof container === "string" ? doc.querySelector(container) : container;
|
|
552
|
+
if (!el) throw new Error(`ArkycWidget.mount: container "${String(container)}" not found.`);
|
|
553
|
+
return el;
|
|
554
|
+
};
|
|
555
|
+
const buildController = (options, onSettle) => {
|
|
556
|
+
if (!options.token) throw new Error("ArkycWidget requires a client `token`.");
|
|
557
|
+
return new WidgetController({
|
|
558
|
+
token: options.token,
|
|
559
|
+
baseUrl: options.baseUrl,
|
|
560
|
+
handoff: options.handoff,
|
|
561
|
+
handoffUrl: options.handoffUrl,
|
|
562
|
+
branding: options.branding,
|
|
563
|
+
signals: options.signals,
|
|
564
|
+
onComplete: options.onComplete,
|
|
565
|
+
onError: options.onError,
|
|
566
|
+
onClose: options.onClose,
|
|
567
|
+
onEvent: options.onEvent,
|
|
568
|
+
onSettle,
|
|
569
|
+
fetch: options.fetch,
|
|
570
|
+
doc: options.doc,
|
|
571
|
+
win: options.win,
|
|
572
|
+
nav: options.nav,
|
|
573
|
+
faceAnalyzer: options.faceAnalyzer,
|
|
574
|
+
faceTuning: options.faceTuning,
|
|
575
|
+
documentAnalyzer: options.documentAnalyzer,
|
|
576
|
+
documentTuning: options.documentTuning
|
|
577
|
+
});
|
|
578
|
+
};
|
|
579
|
+
//#endregion
|
|
580
|
+
export { buildController, resolveContainer };
|
|
581
|
+
|
|
582
|
+
//# sourceMappingURL=controller.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.mjs","names":[],"sources":["../src/controller.ts"],"sourcesContent":["import type {\n DocumentType,\n LivenessChallenge,\n LivenessMode,\n SessionTransitionEvent,\n VerificationStatus,\n WidgetResult,\n WidgetStep,\n WorkflowConfig,\n} from '@arkyc/types'\nimport { REALTIME_EVENT } from '@arkyc/types'\nimport { ArkycClient, type ClientHandoff, type ClientRealtime, type ClientSession, WidgetApiError } from './client'\nimport { Flow } from './flow'\nimport { Theme } from './theme'\nimport { WidgetView, type ViewHandlers } from './ui'\nimport { isDesktopDevice } from './device'\nimport { renderQrSvg } from './qr'\nimport { createWidgetRealtimeClient, type WidgetRealtimeClient } from './realtime'\nimport type { BaseWidgetOptions, WidgetControllerConfig, WidgetEventListener } from './types'\n\n/** Per-step lead-in copy shown before each capture/liveness step. */\nconst STEP_INSTRUCTIONS: Partial<Record<WidgetStep, { title: string; body: string; cta?: string }>> = {\n front_capture: {\n title: 'Front of your document',\n body: 'Place the front of your ID flat and fully inside the frame. We’ll capture it automatically.',\n },\n back_capture: {\n title: 'Back of your document',\n body: 'Now turn your ID over and show the back, fully inside the frame.',\n },\n selfie_capture: {\n title: 'Take a selfie',\n body: 'Look straight at the camera in good light and hold still — we’ll capture it automatically.',\n },\n active_liveness: {\n title: 'Quick liveness check',\n body: 'Follow the on-screen prompts (such as turn your head, blink or smile). This confirms you’re really here.',\n },\n}\n\n/**\n * Drives the full verification flow: renders each screen via {@link WidgetView},\n * advances through {@link flow}, and calls the Client API at each step. Cosmetic\n * processing screens auto-advance; capture screens wait for an image. On a\n * terminal result it surfaces the outcome and (in hosted mode) posts\n * `arkyc:complete` / `arkyc:error` / `arkyc:close` to the parent window.\n */\n/**\n * Re-base the server-resolved project logo onto the API origin the widget is\n * actually talking to. The stored `logo_url` carries the API's own host, which a\n * handed-off phone cannot reach — it reaches the API through the absolute\n * `baseUrl` passed in the handoff link. Rewriting the origin (keeping the path)\n * makes the logo load on whatever device runs the widget. Only applied when\n * `baseUrl` is absolute; the integrator's own branding is never re-based.\n */\nfunction rebaseBrandingLogo<T extends { logo_url?: string | null }>(branding: T, baseUrl: string | undefined): T {\n const logo = branding.logo_url\n if (!logo || !baseUrl || !/^https?:\\/\\//i.test(baseUrl)) return branding\n try {\n const base = new URL(baseUrl)\n const resolved = new URL(logo, base)\n if (resolved.origin === base.origin) return branding\n return { ...branding, logo_url: `${base.origin}${resolved.pathname}${resolved.search}${resolved.hash}` }\n } catch {\n return branding\n }\n}\n\nexport class WidgetController {\n private readonly client: ArkycClient\n private readonly view: WidgetView\n private readonly win: Window\n private readonly nav: Navigator\n private readonly postToParent: boolean\n private readonly scheduler: (fn: () => void, ms: number) => void\n private readonly transientMs: number\n private readonly pollMs: number\n private readonly maxPolls: number\n private readonly maxHandoffPolls: number\n\n /** Cross-device handoff: project config + whether the offer/QR is showing. */\n private handoffConfig: ClientHandoff = { enabled: false, allow_desktop: true, url: '' }\n private handoffReady = false\n private handoffActive = false\n\n /** This session's id + how to watch it live (push transport vs. polling). */\n private sessionId = ''\n private realtimeConfig: ClientRealtime | null = null\n private rtClient: WidgetRealtimeClient | null = null\n private rtResolved = false\n /** The last status observed, so a transition only emits once per change. */\n private lastStatus: VerificationStatus | null = null\n /** Per-name event listeners registered via {@link on}. */\n private listeners = new Map<string, Set<WidgetEventListener>>()\n /** Cancels the active session watch (e.g. continue-on-this-device). */\n private stopWatch: (() => void) | undefined\n\n private step: WidgetStep = 'welcome'\n private documentType: DocumentType | null = null\n private country: string | null = null\n private selfie: Blob | null = null\n private livenessMode: LivenessMode = 'passive'\n /** The session's capture model; `active` mandates a live camera (no fallback). */\n private captureModel: 'passive' | 'active' | 'both' = 'passive'\n private livenessChallenges: LivenessChallenge[] = []\n /** The applied workflow (orders/toggles stages, skip_ocr), or null for the default flow. */\n private workflow: WorkflowConfig | null = null\n private result: WidgetResult | null = null\n /** The session was already terminal when the widget loaded (show a close-only notice). */\n private terminalOnLoad = false\n /** Whether the current step's instruction interstitial has been acknowledged. */\n private instructionAcked = false\n private pendingError: Error | null = null\n private settled = false\n\n constructor(private readonly config: WidgetControllerConfig) {\n const doc = config.doc ?? globalThis.document\n const win = config.win ?? globalThis.window\n if (!doc || !win) throw new Error('The Arkyc widget must run in a browser environment.')\n this.win = win\n this.nav = config.nav ?? globalThis.navigator\n\n this.client = new ArkycClient({\n token: config.token,\n baseUrl: config.baseUrl,\n fetch: config.fetch,\n })\n const theme = new Theme(config.branding)\n this.view = new WidgetView(\n doc,\n theme,\n this.handlers(),\n config.nav ?? globalThis.navigator,\n config.faceAnalyzer,\n config.faceTuning,\n config.documentAnalyzer,\n config.documentTuning,\n )\n\n this.postToParent = config.postToParent ?? (!!win.parent && win.parent !== win)\n this.scheduler = config.scheduler ?? ((fn, ms) => setTimeout(fn, ms))\n this.transientMs = config.transientMs ?? 700\n this.pollMs = config.pollMs ?? 1500\n this.maxPolls = config.maxPolls ?? 40\n // A handed-off session is bounded by its TTL (~15 min); poll generously.\n this.maxHandoffPolls = config.maxHandoffPolls ?? 600\n }\n\n /** The widget's root element — append it to an overlay or inline container. */\n get element(): HTMLElement {\n return this.view.element\n }\n\n /** Connect to the session, then route to the result, the QR, or the welcome flow. */\n start(): void {\n this.view.renderLoading()\n void this.run(() => this.bootstrap())\n }\n\n /** Tear down the view and release the camera (does not fire callbacks). */\n destroy(): void {\n this.view.destroy()\n }\n\n /** Close the widget as if the user dismissed it (fires `onClose`/`onSettle`). */\n close(): void {\n this.finishClose()\n }\n\n /**\n * Subscribe to a named widget event; returns an unsubscribe function. Having a\n * listener (here or via `onEvent`) is what activates the event stream.\n */\n on(event: string, listener: WidgetEventListener): () => void {\n const set = this.listeners.get(event) ?? new Set<WidgetEventListener>()\n set.add(listener)\n this.listeners.set(event, set)\n\n return () => set.delete(listener)\n }\n\n /** Whether anyone is listening for `name` (the firehose or a named listener). */\n private hasListener(name: string): boolean {\n if (this.config.onEvent) return true\n const set = this.listeners.get(name)\n\n return !!set && set.size > 0\n }\n\n /**\n * Surface an event: to local listeners (firehose + `on`), and — in hosted\n * iframe mode — to the embedding parent as `arkyc:event` so the SDK's\n * `handle.on(...)` works across the frame.\n */\n private dispatch(name: string, data?: unknown): void {\n this.emit(name, data)\n // The parent window is the consumer in iframe mode, so forwarding there isn't\n // gated on a local listener (post() already no-ops when not embedding).\n this.post('arkyc:event', { name, data })\n }\n\n /** Emit an event to the firehose + named listeners — but only if one is active. */\n private emit(name: string, data?: unknown): void {\n if (!this.hasListener(name)) return\n try {\n this.config.onEvent?.({ name, data })\n } catch {\n // A consumer callback threw — never let it break the flow.\n }\n const set = this.listeners.get(name)\n if (set) {\n for (const listener of [...set]) {\n try {\n listener(data)\n } catch {\n // ditto\n }\n }\n }\n }\n\n /** Record an observed status, emitting `session.transition` on a real change. */\n private observe(status: VerificationStatus): void {\n if (status === this.lastStatus) return\n const previous = this.lastStatus\n this.lastStatus = status\n this.dispatch(REALTIME_EVENT.sessionTransition, {\n session_id: this.sessionId,\n status,\n previous_status: previous,\n } satisfies Partial<SessionTransitionEvent>)\n }\n\n /**\n * Lazily connect the push transport for this session (once). Returns null for\n * `polling`/`off`/`memory` or when the transport SDK can't load — the caller\n * then polls instead.\n */\n private async resolveRealtime(): Promise<WidgetRealtimeClient | null> {\n if (this.rtResolved) return this.rtClient\n this.rtResolved = true\n const cfg = this.realtimeConfig\n if (!cfg || cfg.transport === 'polling' || cfg.transport === 'off' || cfg.transport === 'memory') return null\n\n const factory = this.config.realtimeFactory ?? createWidgetRealtimeClient\n const apiBase = (this.config.baseUrl ?? '').replace(/\\/$/, '')\n try {\n this.rtClient = await factory(cfg, {\n authEndpoint: `${apiBase}/v1/client/realtime/auth`,\n token: this.config.token,\n })\n } catch {\n this.rtClient = null\n }\n\n return this.rtClient\n }\n\n private handlers(): ViewHandlers {\n return {\n onClose: () => this.finishClose(),\n // The session was already fetched + resolved during bootstrap; just advance.\n onStart: () => void this.run(() => this.enter(this.next())),\n onDocumentSelected: (type, country) => {\n this.documentType = type\n this.country = country || null\n void this.run(() => this.enter('front_capture'))\n },\n onImage: (blob) => void this.run(() => this.onImage(blob)),\n onActiveLiveness: (video, performed, selfie) =>\n void this.run(async () => {\n await this.client.submitLiveness({\n selfie,\n video,\n mode: 'active',\n challenges: performed,\n signals: this.config.signals,\n })\n await this.enter(this.next())\n }),\n onAcknowledge: () => this.finishResult(),\n onUsePhone: () => void this.run(() => this.startHandoff()),\n onContinueHere: () => {\n this.handoffActive = false\n this.stopWatch?.()\n this.step = 'welcome'\n this.render()\n },\n }\n }\n\n /**\n * Fetch the session and route: an already-terminal session (e.g. a stale handoff\n * link, or one finished on another device) shows a close-only notice; on a\n * desktop with handoff enabled we lead with the QR; otherwise the welcome flow.\n */\n private async bootstrap(): Promise<void> {\n if (this.settled) return\n const session = await this.client.getSession()\n if (this.settled) return\n this.sessionId = session.id\n this.realtimeConfig = session.realtime ?? null\n this.workflow = session.workflow ?? null\n // Theme from the project's branding (server-resolved) unless the integrator\n // passed branding explicitly — their value wins.\n if (this.config.branding == null && session.branding)\n this.view.applyBranding(rebaseBrandingLogo(session.branding, this.config.baseUrl))\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) return this.showTerminal(session.status)\n this.resolveLiveness(session)\n if (session.handoff) this.handoffConfig = session.handoff\n const canHandoff =\n this.config.handoff !== false && isDesktopDevice(this.nav) && this.handoffConfig.enabled && !!this.handoffTarget()\n if (canHandoff) {\n this.handoffReady = true\n await this.startHandoff()\n } else {\n this.step = 'welcome'\n this.render()\n }\n }\n\n /** The hosted handoff page URL: a consumer override, else the server-provided one. */\n private handoffTarget(): string {\n return (this.config.handoffUrl ?? this.handoffConfig.url ?? '').trim()\n }\n\n /** Render the QR for this session and wait for the other device to finish. */\n private async startHandoff(): Promise<void> {\n const target = this.handoffTarget()\n if (!target) return\n this.handoffActive = true\n // Offer \"continue on this device\" only when the project permits it.\n this.view.renderHandoff(renderQrSvg(this.buildHandoffUrl(target)), this.handoffConfig.allow_desktop)\n await this.pollHandoff()\n }\n\n /** Build the hosted-page URL the QR encodes (carries the session token). */\n private buildHandoffUrl(target: string): string {\n const sep = target.includes('?') ? '&' : '?'\n let url = `${target}${sep}token=${encodeURIComponent(this.config.token)}`\n // The hosted page supplies its own API base; only pass one when ours is\n // absolute, so a custom cross-origin host can still reach the right API.\n const apiBase = (this.config.baseUrl ?? '').trim()\n if (/^https?:\\/\\//i.test(apiBase)) url += `&baseUrl=${encodeURIComponent(apiBase)}`\n return url\n }\n\n /** Watch the session while the user verifies on the other device; mirror the result. */\n private async pollHandoff(): Promise<void> {\n const rt = await this.resolveRealtime()\n if (rt) {\n const status = await this.pushWatch(rt, this.maxHandoffPolls, () => this.handoffActive && !this.settled)\n if (status) {\n this.handoffActive = false\n return this.showResult(status)\n }\n\n return // cancelled (continue here) or budget elapsed → the QR persists\n }\n\n let errors = 0\n for (let i = 0; i < this.maxHandoffPolls && this.handoffActive && !this.settled; i++) {\n await this.delay(this.pollMs)\n if (!this.handoffActive || this.settled) return\n try {\n const session = await this.client.getSession()\n errors = 0\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) {\n this.handoffActive = false\n return this.showResult(session.status)\n }\n } catch (error) {\n // The session/token can expire mid-wait (401) — stop and reflect that.\n if (error instanceof WidgetApiError && error.status === 401) {\n this.handoffActive = false\n return this.showResult('expired')\n }\n if (++errors >= 5) return\n }\n }\n }\n\n /**\n * Await a terminal status over the push transport. Resolves to the terminal\n * status, or null if `active()` went false or the tick budget elapsed (push can\n * miss events / disconnect; the budget bounds the wait). An initial fetch\n * catches a session that finished before we subscribed.\n */\n private pushWatch(\n rt: WidgetRealtimeClient,\n budget: number,\n active: () => boolean,\n ): Promise<VerificationStatus | null> {\n return new Promise((resolve) => {\n let done = false\n const finish = (status: VerificationStatus | null) => {\n if (done) return\n done = true\n this.stopWatch = undefined\n unsubscribe()\n resolve(status)\n }\n const channel = this.realtimeConfig!.channel\n const unsubscribe = rt.subscribe(channel, (event, data) => {\n if (event !== REALTIME_EVENT.sessionTransition) return\n const status = (data as SessionTransitionEvent).status\n this.observe(status)\n if (Flow.isTerminal(status)) finish(status)\n })\n this.stopWatch = () => finish(null)\n // Catch a race where the session already finished before we subscribed.\n void this.client\n .getSession()\n .then((session) => {\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) finish(session.status)\n })\n .catch((error) => {\n if (error instanceof WidgetApiError && error.status === 401) finish('expired')\n })\n // Bound the wait by the same tick budget the poller would use.\n const countdown = async (n: number): Promise<void> => {\n if (done) return\n if (!active() || n >= budget) return finish(null)\n await this.delay(this.pollMs)\n void countdown(n + 1)\n }\n void countdown(0)\n })\n }\n\n /** Resolve which liveness flow to run from the session's capture model. */\n private resolveLiveness(session: ClientSession): void {\n this.livenessChallenges = session.liveness_challenges ?? []\n const model = session.capture_model ?? 'passive'\n this.captureModel = model\n const wantsActive = model === 'active' || model === 'both'\n // `active` is honoured even without a live camera — the active-liveness\n // screen then shows the device as unsupported (no fallback). `both` falls\n // back to passive when the camera/recorder isn't available.\n this.livenessMode = wantsActive && (model === 'active' || this.view.cameraSupported) ? 'active' : 'passive'\n }\n\n private async onImage(blob: Blob | null): Promise<void> {\n const signals = this.config.signals\n switch (this.step) {\n case 'front_capture':\n await this.client.submitDocumentFront({\n image: blob,\n country: this.country,\n documentType: this.documentType,\n signals,\n })\n return this.enter(this.next())\n case 'back_capture':\n await this.client.submitDocumentBack({\n image: blob,\n country: this.country,\n documentType: this.documentType,\n })\n return this.enter('ocr_processing')\n case 'selfie_capture':\n this.selfie = blob\n return this.enter('passive_liveness')\n }\n }\n\n /** Enter a step: render it, and drive any automatic (processing) work. */\n private async enter(step: WidgetStep): Promise<void> {\n if (this.settled) return\n this.step = step\n\n // Lead each capture/liveness step with an instruction screen so the user\n // knows what's next and starts it deliberately. The Continue button re-enters\n // the same step with the instruction acknowledged.\n const instruction = STEP_INSTRUCTIONS[step]\n if (instruction && !this.instructionAcked) {\n this.view.renderInstruction(step, instruction.title, instruction.body, instruction.cta ?? 'Continue', () => {\n this.instructionAcked = true\n void this.run(() => this.enter(step))\n })\n return\n }\n this.instructionAcked = false\n this.render()\n\n switch (step) {\n case 'ocr_processing':\n await this.delay(this.transientMs)\n return this.enter(this.next())\n case 'passive_liveness':\n await this.client.submitLiveness({ selfie: this.selfie, signals: this.config.signals })\n return this.enter(this.next())\n case 'face_match':\n await this.client.complete({ signals: this.config.signals })\n return this.enter(this.next())\n case 'processing':\n return this.poll()\n }\n }\n\n /** Watch the session until it reaches a terminal status (then show the result). */\n private async poll(): Promise<void> {\n const rt = await this.resolveRealtime()\n if (rt) {\n const status = await this.pushWatch(rt, this.maxPolls, () => !this.settled)\n\n return this.showResult(status ?? 'requires_review')\n }\n\n for (let i = 0; i < this.maxPolls && !this.settled; i++) {\n const session = await this.client.getSession()\n this.observe(session.status)\n if (Flow.isTerminal(session.status)) return this.showResult(session.status)\n await this.delay(this.pollMs)\n }\n // Still processing after the poll budget — surface as pending review.\n this.showResult('requires_review')\n }\n\n private showResult(status: VerificationStatus): void {\n this.result = { status, decision: Flow.statusToDecision(status) }\n this.step = 'result'\n this.render()\n }\n\n /** A session that was already terminal on load: a notice with only a Close button. */\n private showTerminal(status: VerificationStatus): void {\n this.result = { status, decision: Flow.statusToDecision(status) }\n this.step = 'result'\n this.terminalOnLoad = true\n this.render()\n }\n\n private render(): void {\n this.view.render({\n step: this.step,\n documentType: this.documentType,\n decision: this.result?.decision,\n status: this.result?.status,\n terminalNotice: this.terminalOnLoad,\n allowSkip: !!this.config.signals,\n livenessChallenges: this.livenessChallenges,\n requireLiveCamera: this.captureModel === 'active',\n // The active flow is strict end-to-end: documents must be detected, not\n // manually waved through.\n strictCapture: this.livenessMode === 'active',\n handoffAvailable: this.handoffReady,\n })\n }\n\n private next(): WidgetStep {\n return Flow.nextStep(this.step, {\n documentType: this.documentType,\n livenessMode: this.livenessMode,\n workflow: this.workflow,\n })\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => this.scheduler(resolve, ms))\n }\n\n /** Run an async step, routing any failure to the error screen. */\n private async run(fn: () => Promise<void> | void): Promise<void> {\n try {\n await fn()\n } catch (error) {\n this.fail(error)\n }\n }\n\n private fail(error: unknown): void {\n if (this.settled) return\n const err = error instanceof Error ? error : new Error(String(error))\n this.step = 'result'\n\n this.view.render({\n step: 'result',\n documentType: this.documentType,\n errorMessage: err.message,\n })\n\n this.pendingError = err\n }\n\n private finishResult(): void {\n if (this.settled) return\n this.settled = true\n this.teardownRealtime()\n\n if (this.pendingError) {\n this.post('arkyc:error', { error: serializeError(this.pendingError) })\n this.dispatch('error', { message: this.pendingError.message })\n this.config.onError?.(this.pendingError)\n } else if (this.result) {\n this.post('arkyc:complete', { payload: this.result })\n this.dispatch('complete', this.result)\n this.config.onComplete?.(this.result)\n }\n\n this.destroy()\n this.config.onSettle?.()\n }\n\n private finishClose(): void {\n if (this.settled) return\n\n this.settled = true\n this.teardownRealtime()\n this.post('arkyc:close', {})\n this.dispatch('close')\n this.config.onClose?.()\n this.destroy()\n this.config.onSettle?.()\n }\n\n /** Stop any active session watch + disconnect the push transport. */\n private teardownRealtime(): void {\n this.stopWatch?.()\n this.rtClient?.disconnect()\n this.rtClient = null\n }\n\n private post(type: string, extra: Record<string, unknown>): void {\n if (!this.postToParent) return\n try {\n this.win.parent?.postMessage({ type, ...extra }, '*')\n } catch {\n // Cross-origin parent without access — nothing more we can do.\n }\n }\n}\n\nfunction serializeError(error: Error): { message: string; name: string } {\n return { message: error.message, name: error.name }\n}\n\nexport const resolveContainer = (container: string | HTMLElement, doc: Document): HTMLElement => {\n const el = typeof container === 'string' ? doc.querySelector<HTMLElement>(container) : container\n if (!el) throw new Error(`ArkycWidget.mount: container \"${String(container)}\" not found.`)\n return el\n}\n\nexport const buildController = (options: BaseWidgetOptions, onSettle: () => void): WidgetController => {\n if (!options.token) throw new Error('ArkycWidget requires a client `token`.')\n return new WidgetController({\n token: options.token,\n baseUrl: options.baseUrl,\n handoff: options.handoff,\n handoffUrl: options.handoffUrl,\n branding: options.branding,\n signals: options.signals,\n onComplete: options.onComplete,\n onError: options.onError,\n onClose: options.onClose,\n onEvent: options.onEvent,\n onSettle,\n fetch: options.fetch,\n doc: options.doc,\n win: options.win,\n nav: options.nav,\n faceAnalyzer: options.faceAnalyzer,\n faceTuning: options.faceTuning,\n documentAnalyzer: options.documentAnalyzer,\n documentTuning: options.documentTuning,\n })\n}\n"],"mappings":";;;;;;;;;;AAqBA,MAAM,oBAAgG;CACpG,eAAe;EACb,OAAO;EACP,MAAM;CACR;CACA,cAAc;EACZ,OAAO;EACP,MAAM;CACR;CACA,gBAAgB;EACd,OAAO;EACP,MAAM;CACR;CACA,iBAAiB;EACf,OAAO;EACP,MAAM;CACR;AACF;;;;;;;;;;;;;;;;AAiBA,SAAS,mBAA2D,UAAa,SAAgC;CAC/G,MAAM,OAAO,SAAS;CACtB,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,gBAAgB,KAAK,OAAO,GAAG,OAAO;CAChE,IAAI;EACF,MAAM,OAAO,IAAI,IAAI,OAAO;EAC5B,MAAM,WAAW,IAAI,IAAI,MAAM,IAAI;EACnC,IAAI,SAAS,WAAW,KAAK,QAAQ,OAAO;EAC5C,OAAO;GAAE,GAAG;GAAU,UAAU,GAAG,KAAK,SAAS,SAAS,WAAW,SAAS,SAAS,SAAS;EAAO;CACzG,QAAQ;EACN,OAAO;CACT;AACF;AAEA,IAAa,mBAAb,MAA8B;CA+CC;CA9C7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;;CAGA,gBAAuC;EAAE,SAAS;EAAO,eAAe;EAAM,KAAK;CAAG;CACtF,eAAuB;CACvB,gBAAwB;;CAGxB,YAAoB;CACpB,iBAAgD;CAChD,WAAgD;CAChD,aAAqB;;CAErB,aAAgD;;CAEhD,4BAAoB,IAAI,IAAsC;;CAE9D;CAEA,OAA2B;CAC3B,eAA4C;CAC5C,UAAiC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