@microblink/biometrics 1000.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.
@@ -0,0 +1,846 @@
1
+ import { BiometricsError as e, BiometricsError as t, ConfigurationError as n, ConfigurationError as r, LicenseError as i, PermissionError as a, SessionError as o, SessionError as s, checkBiometricsSupport as c, createBiometricsCapture as l, createDerivedDeviceInfo as u, emitBiometricsDiagnostic as d, getBiometricsFaceFromCaptureResult as f, getDeviceInfo as p, getUserAgentData as m, isFaceCaptureResult as h, normalizeBiometricsError as g, normalizeBiometricsError as _ } from "@microblink/biometrics-core";
2
+ import { createBiometricsUxManager as ee } from "@microblink/biometrics-ux-manager/core";
3
+ import { createBiometricsFeedbackUi as te } from "@microblink/biometrics-ux-manager/ui";
4
+ import { CameraError as ne, CameraManager as re } from "@microblink/camera-manager/core";
5
+ import { createCameraManagerUi as ie } from "@microblink/camera-manager/ui";
6
+ //#region ../../node_modules/.pnpm/nanoid@5.1.16/node_modules/nanoid/url-alphabet/index.js
7
+ var ae = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", oe = (e = 21) => {
8
+ let t = "", n = crypto.getRandomValues(new Uint8Array(e |= 0));
9
+ for (; e--;) t += ae[n[e] & 63];
10
+ return t;
11
+ };
12
+ //#endregion
13
+ //#region ../core-common/dist/getUserId.js
14
+ function se(e) {
15
+ if (!ce()) return oe();
16
+ let t = localStorage.getItem(e);
17
+ if (t) return t;
18
+ let n = oe();
19
+ return localStorage.setItem(e, n), n;
20
+ }
21
+ function ce() {
22
+ try {
23
+ return localStorage.setItem("test", "test"), localStorage.removeItem("test"), !0;
24
+ } catch {
25
+ return !1;
26
+ }
27
+ }
28
+ //#endregion
29
+ //#region src/BiometricsAnalytics.ts
30
+ var le = "biometrics-userid";
31
+ function ue(e) {
32
+ return {
33
+ enabled: e?.enabled !== !1,
34
+ userId: e?.userId ?? se(le),
35
+ pingProxyUrl: e?.pingProxyUrl
36
+ };
37
+ }
38
+ var de = {
39
+ enabled: !1,
40
+ forSession: () => de,
41
+ ping: () => Promise.resolve(),
42
+ report: () => Promise.resolve(),
43
+ logInitStarted: () => Promise.resolve(),
44
+ logInitCompleted: () => Promise.resolve(),
45
+ logInitFailed: () => Promise.resolve(),
46
+ logNonFatal: () => Promise.resolve(),
47
+ logCaptureStarted: () => Promise.resolve(),
48
+ logSessionEvent: () => Promise.resolve(),
49
+ logDiagnostic: () => Promise.resolve(),
50
+ logSdkClosed: () => Promise.resolve(),
51
+ sendPinglets: () => Promise.resolve()
52
+ };
53
+ async function v(e, t) {
54
+ try {
55
+ await e.ping(t);
56
+ } catch (e) {
57
+ console.warn("Biometrics analytics ping failed:", e);
58
+ }
59
+ }
60
+ async function fe(e) {
61
+ try {
62
+ await e.sendPinglets();
63
+ } catch (e) {
64
+ console.warn("Send pinglets failed:", e);
65
+ }
66
+ }
67
+ function pe(e) {
68
+ if (typeof e != "object" || !e) return;
69
+ let t = "code" in e ? e.code : void 0;
70
+ return typeof t == "string" ? t : void 0;
71
+ }
72
+ function me(e) {
73
+ if (typeof e != "object" || !e) return;
74
+ let t = "isRetryable" in e ? e.isRetryable : void 0;
75
+ return typeof t == "boolean" ? t : void 0;
76
+ }
77
+ function he(e) {
78
+ return e instanceof Error ? e.name : "Error";
79
+ }
80
+ function ge(e) {
81
+ if (e instanceof Error) return e.message;
82
+ if (typeof e == "object" && e) try {
83
+ return JSON.stringify(e);
84
+ } catch {
85
+ return Object.prototype.toString.call(e);
86
+ }
87
+ return String(e);
88
+ }
89
+ function _e(e) {
90
+ return {
91
+ livenessFrameCount: e.livenessFrames.length,
92
+ requestMode: e.livenessFrames.length > 0 ? "engineFrames" : "singleImage",
93
+ hasCaptureFrame: e.captureFrame !== void 0,
94
+ hasLivenessBatchSignature: e.livenessBatchSignature !== void 0
95
+ };
96
+ }
97
+ function ve(e, t) {
98
+ if (!e.enabled) return de;
99
+ function n(e) {
100
+ async function r(n, r = {}) {
101
+ let { sessionId: i, sessionNumber: a } = e;
102
+ await v(t, {
103
+ schemaName: "ping.log",
104
+ schemaVersion: "1.0.0",
105
+ sessionNumber: a,
106
+ data: {
107
+ logLevel: "Info",
108
+ logMessage: JSON.stringify({
109
+ product: "Biometrics",
110
+ eventName: n,
111
+ sessionId: i,
112
+ sessionNumber: a,
113
+ ...r
114
+ })
115
+ }
116
+ });
117
+ }
118
+ async function i(e, t, n = {}) {
119
+ await r(e, {
120
+ ...n,
121
+ errorName: he(t),
122
+ errorCode: pe(t),
123
+ retryable: me(t)
124
+ });
125
+ }
126
+ async function a(n, r) {
127
+ let i = pe(r);
128
+ await v(t, {
129
+ schemaName: "ping.error",
130
+ schemaVersion: "1.0.0",
131
+ sessionNumber: e.sessionNumber,
132
+ data: {
133
+ errorType: "NonFatal",
134
+ errorMessage: `${n}: ${i ? `${i}: ` : ""}${ge(r)}`,
135
+ stackTrace: r instanceof Error ? r.stack : void 0
136
+ }
137
+ });
138
+ }
139
+ return {
140
+ enabled: !0,
141
+ forSession: (e) => n(e),
142
+ ping: (e) => v(t, e),
143
+ report: (n) => v(t, {
144
+ ...n,
145
+ sessionNumber: e.sessionNumber
146
+ }),
147
+ logInitStarted: () => r("sdk.init.started"),
148
+ logInitCompleted: () => r("sdk.init.completed"),
149
+ logInitFailed: async (e) => {
150
+ await i("sdk.init.failed", e), await a("sdk.init", e);
151
+ },
152
+ logNonFatal: a,
153
+ logCaptureStarted: () => r("capture.started"),
154
+ logDiagnostic: (e) => r("sdk.diagnostic", {
155
+ phase: e.phase,
156
+ component: e.component,
157
+ status: e.status,
158
+ durationMs: e.durationMs,
159
+ errorCode: e.errorCode,
160
+ resourceKind: e.resource?.kind
161
+ }),
162
+ logSdkClosed: () => r("sdk.closed"),
163
+ sendPinglets: () => fe(t),
164
+ async logSessionEvent(n) {
165
+ switch (n.kind) {
166
+ case "faceGuidance":
167
+ await r("capture.feedback.changed", { feedback: n.feedback });
168
+ return;
169
+ case "captureFinished":
170
+ await r("capture.completed", _e(n.result)), await fe(t);
171
+ return;
172
+ case "captureTimeout":
173
+ await r("capture.timed_out"), await v(t, {
174
+ schemaName: "ping.sdk.ux.event",
175
+ schemaVersion: "1.3.0",
176
+ sessionNumber: e.sessionNumber,
177
+ data: { eventType: "StepTimeout" }
178
+ }), await fe(t);
179
+ return;
180
+ case "captureTechnicalData": return;
181
+ }
182
+ }
183
+ };
184
+ }
185
+ return n({ sessionNumber: 0 });
186
+ }
187
+ //#endregion
188
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/checkPrivateRedeclaration.js
189
+ function ye(e, t) {
190
+ if (t.has(e)) throw TypeError("Cannot initialize the same private elements twice on an object");
191
+ }
192
+ //#endregion
193
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/classPrivateMethodInitSpec.js
194
+ function be(e, t) {
195
+ ye(e, t), t.add(e);
196
+ }
197
+ //#endregion
198
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/typeof.js
199
+ function y(e) {
200
+ "@babel/helpers - typeof";
201
+ return y = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
202
+ return typeof e;
203
+ } : function(e) {
204
+ return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
205
+ }, y(e);
206
+ }
207
+ //#endregion
208
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPrimitive.js
209
+ function xe(e, t) {
210
+ if (y(e) != "object" || !e) return e;
211
+ var n = e[Symbol.toPrimitive];
212
+ if (n !== void 0) {
213
+ var r = n.call(e, t || "default");
214
+ if (y(r) != "object") return r;
215
+ throw TypeError("@@toPrimitive must return a primitive value.");
216
+ }
217
+ return (t === "string" ? String : Number)(e);
218
+ }
219
+ //#endregion
220
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPropertyKey.js
221
+ function Se(e) {
222
+ var t = xe(e, "string");
223
+ return y(t) == "symbol" ? t : t + "";
224
+ }
225
+ //#endregion
226
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/defineProperty.js
227
+ function b(e, t, n) {
228
+ return (t = Se(t)) in e ? Object.defineProperty(e, t, {
229
+ value: n,
230
+ enumerable: !0,
231
+ configurable: !0,
232
+ writable: !0
233
+ }) : e[t] = n, e;
234
+ }
235
+ //#endregion
236
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/classPrivateFieldInitSpec.js
237
+ function x(e, t, n) {
238
+ ye(e, t), t.set(e, n);
239
+ }
240
+ //#endregion
241
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/assertClassBrand.js
242
+ function S(e, t, n) {
243
+ if (typeof e == "function" ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
244
+ throw TypeError("Private element is not present on this object");
245
+ }
246
+ //#endregion
247
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/classPrivateFieldGet2.js
248
+ function C(e, t) {
249
+ return e.get(S(e, t));
250
+ }
251
+ //#endregion
252
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/classPrivateFieldSet2.js
253
+ function w(e, t, n) {
254
+ return e.set(S(e, t), n), n;
255
+ }
256
+ //#endregion
257
+ //#region src/BiometricsSession.ts
258
+ function Ce(e) {
259
+ return e instanceof t && e.stage === "capture" ? e : _(e, {
260
+ stage: "capture",
261
+ component: "sdk"
262
+ });
263
+ }
264
+ function T() {
265
+ return new s("Session is finished", "SESSION_CLOSED");
266
+ }
267
+ var E = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakMap(), B = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakSet(), we = class {
268
+ constructor(e, t = {}, n, r = () => () => void 0) {
269
+ be(this, V), b(this, "createCaptureSession", void 0), b(this, "config", void 0), b(this, "analytics", void 0), b(this, "subscribeDiagnostic", void 0), x(this, E, /* @__PURE__ */ new Set()), x(this, D, /* @__PURE__ */ new Set()), x(this, O, /* @__PURE__ */ new Set()), x(this, k, /* @__PURE__ */ new Set()), x(this, A, /* @__PURE__ */ new Set()), x(this, j, { phase: "idle" }), x(this, M, void 0), x(this, N, 0), x(this, P, 0), x(this, F, void 0), x(this, I, void 0), x(this, L, void 0), x(this, R, void 0), x(this, z, void 0), x(this, B, void 0), this.createCaptureSession = e, this.config = t, this.analytics = n, this.subscribeDiagnostic = r, S(V, this, Oe).call(this);
270
+ }
271
+ getState() {
272
+ return C(j, this);
273
+ }
274
+ subscribe(e) {
275
+ return C(E, this).add(e), S(V, this, Ie).call(this, e, C(j, this)), () => C(E, this).delete(e);
276
+ }
277
+ processFrame(e) {
278
+ return C(I, this) ? C(I, this).processFrame(e) : C(F, this)?.then((t) => t.processFrame(e), () => e.data.buffer) ?? Promise.resolve(e.data.buffer);
279
+ }
280
+ setCameraSource(e, t) {
281
+ w(L, this, e && t ? {
282
+ videoElement: e,
283
+ track: t
284
+ } : void 0), C(I, this)?.setCameraSource(e, t);
285
+ }
286
+ setCaptureTimeoutPaused(e) {
287
+ C(j, this).phase === "capturing" && C(I, this)?.setCaptureTimeoutPaused(e);
288
+ }
289
+ run() {
290
+ if (S(V, this, Me).call(this), C(j, this).phase !== "idle") throw new s("This session has already been started", "SESSION_NOT_IDLE");
291
+ return S(V, this, Te).call(this);
292
+ }
293
+ retry() {
294
+ if (S(V, this, Me).call(this), C(j, this).phase !== "failed" || !C(j, this).error.isRetryable) throw new s("The current session state cannot be retried", "SESSION_NOT_RETRYABLE");
295
+ return S(V, this, Te).call(this);
296
+ }
297
+ onEvent(e) {
298
+ return C(D, this).add(e), () => C(D, this).delete(e);
299
+ }
300
+ onError(e) {
301
+ return C(O, this).add(e), () => C(O, this).delete(e);
302
+ }
303
+ onDiagnostic(e) {
304
+ let t = this.subscribeDiagnostic(e);
305
+ return C(k, this).add(t), () => {
306
+ C(k, this).delete(t), t();
307
+ };
308
+ }
309
+ async getSessionContext() {
310
+ return C(z, this) ?? w(z, this, S(V, this, Oe).call(this).then((e) => (C(R, this) ?? w(R, this, this.analytics?.forSession(e.context)), Object.freeze({
311
+ sessionId: e.context.sessionId,
312
+ traceId: e.context.traceId,
313
+ sessionNumber: e.context.sessionNumber,
314
+ report: (e) => C(R, this)?.report(e) ?? Promise.resolve(),
315
+ flush: () => C(R, this)?.sendPinglets() ?? Promise.resolve()
316
+ }))).catch((e) => {
317
+ throw w(z, this, void 0), e;
318
+ })), C(z, this);
319
+ }
320
+ finish() {
321
+ if (C(j, this).phase !== "finished") {
322
+ w(N, this, C(N, this) + 1), w(M, this, void 0), S(V, this, W).call(this, { phase: "finished" }), S(V, this, Le).call(this, S(V, this, ke).call(this)), C(D, this).clear(), C(O, this).clear();
323
+ for (let e of C(k, this)) e();
324
+ C(k, this).clear();
325
+ }
326
+ }
327
+ };
328
+ async function Te() {
329
+ var e;
330
+ let t = S(V, this, Ae).call(this), n = w(P, this, (e = C(P, this), ++e));
331
+ S(V, this, W).call(this, {
332
+ phase: "capturing",
333
+ capture: {
334
+ sessionState: "IDLE",
335
+ feedback: "FACE_NOT_FOUND"
336
+ }
337
+ });
338
+ let r;
339
+ try {
340
+ if (r = await S(V, this, Oe).call(this), !S(V, this, U).call(this, t, n)) throw T();
341
+ C(R, this) ?? w(R, this, this.analytics?.forSession(r.context));
342
+ let e = C(R, this)?.logCaptureStarted();
343
+ if (S(V, this, Pe).call(this, e), await e?.catch(() => void 0), !S(V, this, U).call(this, t, n)) throw T();
344
+ } catch (e) {
345
+ return S(V, this, Ee).call(this, e, t);
346
+ }
347
+ let { thresholds: i, ...a } = this.config.captureFace ?? {}, o;
348
+ try {
349
+ o = await r.capture({
350
+ ...a,
351
+ timeoutMs: this.config.captureTimeoutMs,
352
+ onStateChange: (e) => {
353
+ e !== "COMPLETE" && S(V, this, U).call(this, t, n) && S(V, this, H).call(this, { sessionState: e });
354
+ },
355
+ onFeedbackChange: (e) => {
356
+ S(V, this, U).call(this, t, n) && (S(V, this, H).call(this, { feedback: e }), S(V, this, G).call(this, {
357
+ kind: "faceGuidance",
358
+ feedback: e
359
+ }));
360
+ },
361
+ onTimeout: () => {
362
+ S(V, this, U).call(this, t, n) && S(V, this, G).call(this, { kind: "captureTimeout" });
363
+ },
364
+ onAnalysisResult: (e) => {
365
+ if (!S(V, this, U).call(this, t, n)) return;
366
+ let r = {
367
+ normalizedFaceBounds: e.boundingBox,
368
+ landmarks: e.landmarks,
369
+ inputImageSize: e.inputImageSize
370
+ };
371
+ S(V, this, H).call(this, { technicalData: r }), S(V, this, G).call(this, {
372
+ kind: "captureTechnicalData",
373
+ data: r
374
+ });
375
+ },
376
+ onCapture: (e) => {
377
+ S(V, this, U).call(this, t, n) && S(V, this, De).call(this, e);
378
+ }
379
+ });
380
+ } catch (e) {
381
+ return S(V, this, Ee).call(this, e, t);
382
+ }
383
+ if (!S(V, this, U).call(this, t, n)) throw T();
384
+ return C(j, this).phase === "capturing" && C(j, this).capture.sessionState !== "COMPLETE" && S(V, this, De).call(this, o), S(V, this, je).call(this, t), S(V, this, W).call(this, {
385
+ phase: "succeeded",
386
+ result: o
387
+ }), await S(V, this, ke).call(this), o;
388
+ }
389
+ async function Ee(e, t) {
390
+ if (!S(V, this, Ne).call(this, t)) throw T();
391
+ C(I, this) || w(F, this, void 0);
392
+ let n = Ce(e);
393
+ throw S(V, this, Pe).call(this, (C(R, this) ?? this.analytics)?.logNonFatal("sdk.capture", n)), S(V, this, je).call(this, t), S(V, this, W).call(this, {
394
+ phase: "failed",
395
+ stage: "capture",
396
+ error: n
397
+ }), S(V, this, Fe).call(this, C(O, this), n), n.isRetryable || await S(V, this, ke).call(this), n;
398
+ }
399
+ function De(e) {
400
+ S(V, this, H).call(this, { sessionState: "COMPLETE" }), S(V, this, G).call(this, {
401
+ kind: "captureFinished",
402
+ result: e
403
+ });
404
+ }
405
+ function H(e) {
406
+ C(j, this).phase === "capturing" && S(V, this, W).call(this, {
407
+ phase: "capturing",
408
+ capture: {
409
+ ...C(j, this).capture,
410
+ ...e
411
+ }
412
+ });
413
+ }
414
+ function Oe() {
415
+ if (C(I, this)) return Promise.resolve(C(I, this));
416
+ if (C(F, this)) return C(F, this);
417
+ let e;
418
+ try {
419
+ e = this.createCaptureSession();
420
+ } catch (t) {
421
+ e = Promise.reject(t);
422
+ }
423
+ return w(F, this, e), e.then((t) => {
424
+ C(F, this) === e && (w(I, this, t), t.setCameraSource(C(L, this)?.videoElement, C(L, this)?.track));
425
+ }, () => {
426
+ C(F, this) === e && w(F, this, void 0);
427
+ }), e;
428
+ }
429
+ function ke() {
430
+ return C(B, this) ?? w(B, this, (async () => {
431
+ let e = C(I, this) ?? await C(F, this)?.catch(() => void 0);
432
+ for (; C(A, this).size > 0;) await Promise.all(C(A, this));
433
+ await e?.close();
434
+ })()), C(B, this);
435
+ }
436
+ function Ae() {
437
+ let e = { epoch: C(N, this) };
438
+ return w(M, this, e), e;
439
+ }
440
+ function je(e) {
441
+ C(M, this) === e && w(M, this, void 0);
442
+ }
443
+ function Me() {
444
+ if (C(j, this).phase === "finished") throw T();
445
+ if (C(M, this)) throw new s("A session operation is already active", "SESSION_ALREADY_ACTIVE");
446
+ }
447
+ function Ne(e) {
448
+ return C(M, this) === e && e.epoch === C(N, this) && C(j, this).phase !== "finished";
449
+ }
450
+ function U(e, t) {
451
+ return S(V, this, Ne).call(this, e) && t === C(P, this) && C(j, this).phase === "capturing";
452
+ }
453
+ function W(e) {
454
+ w(j, this, e), S(V, this, Fe).call(this, C(E, this), e);
455
+ }
456
+ function G(e) {
457
+ S(V, this, Pe).call(this, C(R, this)?.logSessionEvent(e)), S(V, this, Fe).call(this, C(D, this), e);
458
+ }
459
+ function Pe(e) {
460
+ if (!e) return;
461
+ let t = e.catch(() => void 0).finally(() => C(A, this).delete(t));
462
+ C(A, this).add(t);
463
+ }
464
+ function Fe(e, t) {
465
+ for (let n of e) S(V, this, Ie).call(this, n, t);
466
+ }
467
+ function Ie(e, t) {
468
+ try {
469
+ e?.(t);
470
+ } catch {
471
+ return;
472
+ }
473
+ }
474
+ function Le(e) {
475
+ e?.catch(() => void 0);
476
+ }
477
+ //#endregion
478
+ //#region src/init.ts
479
+ var Re = 6e4;
480
+ function ze() {
481
+ return globalThis.performance?.now() ?? Date.now();
482
+ }
483
+ function Be(e, t) {
484
+ try {
485
+ e?.(t);
486
+ } catch {
487
+ return;
488
+ }
489
+ }
490
+ var Ve = /* @__PURE__ */ new WeakMap(), He = /* @__PURE__ */ new WeakMap(), Ue = /* @__PURE__ */ new WeakMap(), We = /* @__PURE__ */ new WeakMap(), Ge = /* @__PURE__ */ new WeakMap(), Ke = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), qe = /* @__PURE__ */ new WeakMap(), Je = /* @__PURE__ */ new WeakMap(), q = /* @__PURE__ */ new WeakMap(), J = /* @__PURE__ */ new WeakMap(), Ye = /* @__PURE__ */ new WeakMap(), Y = /* @__PURE__ */ new WeakSet(), Xe = class {
491
+ constructor(e) {
492
+ be(this, Y), x(this, Ve, void 0), x(this, He, void 0), x(this, Ue, void 0), x(this, We, ze()), x(this, Ge, void 0), x(this, Ke, []), x(this, K, /* @__PURE__ */ new Set()), x(this, qe, /* @__PURE__ */ new WeakSet()), x(this, Je, void 0), x(this, q, Promise.resolve()), x(this, J, 0), x(this, Ye, !1), b(this, "uxDiagnosticSink", (e) => {
493
+ C(J, this) === 0 && this.emitDiagnostic(e);
494
+ }), b(this, "subscribeDiagnostic", (e) => (C(K, this).add(e), () => C(K, this).delete(e)));
495
+ let t = e.timeoutMs ?? Re;
496
+ if (!Number.isFinite(t) || t <= 0) {
497
+ let t = new r("initializationTimeoutMs must be a positive finite number.", "INVALID_CONFIGURATION");
498
+ throw Be(e.onError, t), t;
499
+ }
500
+ w(Ve, this, e.timeoutMessage(t)), w(He, this, e.onDiagnostic), w(Ue, this, e.onError), w(Ge, this, C(We, this) + t), this.emitDiagnostic({
501
+ phase: "initialization",
502
+ component: "sdk",
503
+ status: "started",
504
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
505
+ });
506
+ }
507
+ remainingMs() {
508
+ return Math.max(0, C(Ge, this) - ze());
509
+ }
510
+ wait(e, t = "sdk", n) {
511
+ return new Promise((r, i) => {
512
+ let a = this.remainingMs(), o = a === 0, s = a > 0 ? setTimeout(() => {
513
+ o = !0, i(S(Y, this, Qe).call(this, t));
514
+ }, a) : void 0;
515
+ o && i(S(Y, this, Qe).call(this, t)), e.then((e) => {
516
+ if (o) {
517
+ n && Promise.resolve().then(() => n(e)).catch(() => void 0);
518
+ return;
519
+ }
520
+ clearTimeout(s), r(e);
521
+ }, (e) => {
522
+ o || (clearTimeout(s), i(e));
523
+ });
524
+ });
525
+ }
526
+ async waitForCleanup(e, t) {
527
+ if (t.code === "INITIALIZATION_TIMEOUT") {
528
+ e.catch(() => void 0);
529
+ return;
530
+ }
531
+ await this.wait(e).catch(() => void 0);
532
+ }
533
+ reportError(e, t = "sdk") {
534
+ return S(Y, this, Ze).call(this, _(e, {
535
+ stage: "initialization",
536
+ component: t,
537
+ preserve: !0
538
+ }));
539
+ }
540
+ reportInitializationError(e, t = "sdk") {
541
+ return S(Y, this, Ze).call(this, _(e, {
542
+ stage: "initialization",
543
+ component: t
544
+ }));
545
+ }
546
+ flushDiagnostics() {
547
+ return C(q, this);
548
+ }
549
+ setAnalytics(e) {
550
+ w(Je, this, e);
551
+ for (let t of C(Ke, this).splice(0)) S(Y, this, $e).call(this, e, t);
552
+ }
553
+ emitDiagnostic(e) {
554
+ d(C(He, this), e);
555
+ let t = C(Je, this);
556
+ t ? S(Y, this, $e).call(this, t, e) : C(Ke, this).push(e), w(J, this, C(J, this) + 1);
557
+ try {
558
+ for (let t of [...C(K, this)]) d(t, e);
559
+ } finally {
560
+ w(J, this, C(J, this) - 1);
561
+ }
562
+ }
563
+ complete() {
564
+ S(Y, this, et).call(this, "completed");
565
+ }
566
+ fail(e) {
567
+ S(Y, this, et).call(this, e.code === "INITIALIZATION_TIMEOUT" ? "timed-out" : "failed", e);
568
+ }
569
+ };
570
+ function Ze(e) {
571
+ return C(qe, this).has(e) || (C(qe, this).add(e), Be(C(Ue, this), e)), e;
572
+ }
573
+ function Qe(e) {
574
+ return new t({
575
+ message: C(Ve, this),
576
+ code: "INITIALIZATION_TIMEOUT",
577
+ stage: "initialization",
578
+ component: e,
579
+ isRetryable: !0
580
+ });
581
+ }
582
+ function $e(e, t) {
583
+ w(q, this, C(q, this).then(() => e.logDiagnostic(t)).catch(() => void 0));
584
+ }
585
+ function et(e, t) {
586
+ C(Ye, this) || (w(Ye, this, !0), this.emitDiagnostic({
587
+ phase: "initialization",
588
+ component: "sdk",
589
+ status: e,
590
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
591
+ durationMs: Math.max(0, ze() - C(We, this)),
592
+ errorCode: t?.code
593
+ }));
594
+ }
595
+ //#endregion
596
+ //#region src/createBiometrics.ts
597
+ function tt(e) {
598
+ let t = typeof window > "u" ? void 0 : window.location.href, n = e ?? t;
599
+ if (n === void 0) return;
600
+ let r = t === void 0 ? new URL(n) : new URL(n, t);
601
+ return new URL("resources/", r).href;
602
+ }
603
+ var X = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakMap(), nt = class {
604
+ constructor(e, t, n, r) {
605
+ b(this, "subscribeDiagnostic", void 0), b(this, "flushDiagnostics", void 0), x(this, X, void 0), x(this, Z, void 0), x(this, Q, void 0), this.subscribeDiagnostic = n, this.flushDiagnostics = r, w(X, this, e), w(Z, this, t);
606
+ }
607
+ startSession(e = {}) {
608
+ return new we(() => C(X, this).startSession(e.captureFace?.thresholds), e, C(Z, this), this.subscribeDiagnostic);
609
+ }
610
+ close() {
611
+ return C(Q, this) ?? w(Q, this, (async () => {
612
+ let e;
613
+ try {
614
+ await this.flushDiagnostics();
615
+ } catch (t) {
616
+ e = t;
617
+ }
618
+ try {
619
+ await C(Z, this).logSdkClosed();
620
+ } catch (t) {
621
+ e ??= t;
622
+ }
623
+ try {
624
+ await C(X, this).close();
625
+ } catch (t) {
626
+ e ??= t;
627
+ }
628
+ if (e !== void 0) throw e;
629
+ })()), C(Q, this);
630
+ }
631
+ };
632
+ async function rt(e, t) {
633
+ let n = ue(e.analytics), r, i;
634
+ try {
635
+ let a = l({
636
+ licenseKey: e.licenseKey,
637
+ ...e.capture,
638
+ resourcePath: tt(e.resourcesLocation),
639
+ wasmVariant: e.wasmVariant,
640
+ initializationTimeoutMs: Math.max(1, t.remainingMs()),
641
+ onDownloadProgress: e.onDownloadProgress,
642
+ onDiagnostic: (e) => {
643
+ (e.phase !== "initialization" || e.component !== "sdk") && t.emitDiagnostic(e);
644
+ },
645
+ analytics: {
646
+ userId: n.userId,
647
+ pingProxyUrl: n.pingProxyUrl
648
+ }
649
+ });
650
+ return r = await t.wait(a, "sdk", (e) => e.close()), i = ve(n, r), t.setAnalytics(i), i.logInitStarted().catch(() => void 0), i.logInitCompleted().catch(() => void 0), {
651
+ sdk: new nt(r, i, t.subscribeDiagnostic, () => t.flushDiagnostics()),
652
+ analytics: i
653
+ };
654
+ } catch (e) {
655
+ let n = t.reportInitializationError(e);
656
+ throw t.fail(n), await t.waitForCleanup((async () => {
657
+ i && (await i.logInitFailed(n).catch(() => void 0), await t.flushDiagnostics().catch(() => void 0), await i.sendPinglets().catch(() => void 0)), await r?.close().catch(() => void 0);
658
+ })(), n), n;
659
+ }
660
+ }
661
+ async function it(e) {
662
+ let t = new Xe({
663
+ timeoutMs: e.initializationTimeoutMs,
664
+ timeoutMessage: (e) => `Biometrics initialization timed out after ${e}ms.`,
665
+ onDiagnostic: e.onDiagnostic
666
+ }), { sdk: n } = await rt(e, t);
667
+ return t.complete(), n;
668
+ }
669
+ //#endregion
670
+ //#region src/createBiometricsUi.ts
671
+ function $() {
672
+ return globalThis.performance?.now() ?? Date.now();
673
+ }
674
+ function at(e, ...t) {
675
+ try {
676
+ e?.(...t);
677
+ } catch {
678
+ return;
679
+ }
680
+ }
681
+ async function ot(e, t) {
682
+ if (t && (await e.getCameraDevices()).some((e) => e.deviceInfo.deviceId === t)) {
683
+ await e.startCameraStream({ preferredCamera: (e) => e.find((e) => e.deviceInfo.deviceId === t) });
684
+ return;
685
+ }
686
+ await e.startCameraStream({ preferredFacing: "front" });
687
+ }
688
+ async function st(e) {
689
+ let t = new Xe({
690
+ timeoutMs: e.initializationTimeoutMs,
691
+ timeoutMessage: () => "Biometrics UI initialization timed out.",
692
+ onDiagnostic: e.onDiagnostic,
693
+ onError: e.onError
694
+ }), n = e.feedbackUiOptions?.helpTooltipShowDelay;
695
+ if (n != null && (!Number.isFinite(n) || n < 0)) {
696
+ let e = new r("feedbackUiOptions.helpTooltipShowDelay must be a non-negative finite number or null.", "INVALID_HELP_TOOLTIP_SHOW_DELAY");
697
+ throw t.reportError(e), t.fail(e), e;
698
+ }
699
+ let { sdk: i, analytics: a } = await rt({
700
+ licenseKey: e.licenseKey,
701
+ resourcesLocation: e.resourcesLocation,
702
+ wasmVariant: e.wasmVariant,
703
+ capture: e.capture,
704
+ analytics: e.analytics
705
+ }, t), o;
706
+ try {
707
+ o = i.startSession({
708
+ captureTimeoutMs: e.captureTimeoutMs,
709
+ captureFace: e.captureFace
710
+ });
711
+ } catch (e) {
712
+ let n = t.reportError(e);
713
+ t.fail(n);
714
+ let r = (async () => {
715
+ await a.logInitFailed(n).catch(() => void 0), await t.flushDiagnostics().catch(() => void 0), await a.sendPinglets().catch(() => void 0), await i.close().catch(() => void 0);
716
+ })();
717
+ throw await t.waitForCleanup(r, n), n;
718
+ }
719
+ let s = o, c, l, u, d, f, p, m, h, g = () => {
720
+ let e = u;
721
+ u = void 0;
722
+ let t = d;
723
+ d = void 0;
724
+ let n = f;
725
+ f = void 0;
726
+ let r = p;
727
+ p = void 0;
728
+ let i = l;
729
+ l = void 0;
730
+ let a;
731
+ for (let o of [
732
+ () => e?.dismiss(),
733
+ () => t?.(),
734
+ () => n?.(),
735
+ () => r?.(),
736
+ () => i?.dismount(),
737
+ () => m?.reset()
738
+ ]) try {
739
+ o();
740
+ } catch (e) {
741
+ a ??= e;
742
+ }
743
+ if (a !== void 0) throw a;
744
+ }, _ = (e = "Sdk") => (c ??= (async () => {
745
+ let t, n = (e) => {
746
+ try {
747
+ e();
748
+ } catch (e) {
749
+ t ??= e;
750
+ }
751
+ };
752
+ n(() => o.finish()), n(() => h?.close(e)), n(g);
753
+ try {
754
+ await i.close();
755
+ } catch (e) {
756
+ t ??= e;
757
+ }
758
+ if (t !== void 0) throw t;
759
+ })(), c);
760
+ try {
761
+ m = new re({ preferredResolution: "1080p" });
762
+ let r = ee(m, s, {
763
+ showOnboarding: e.feedbackUiOptions?.showOnboardingGuide,
764
+ helpNudgeDelayMs: n,
765
+ showDebugOverlay: e.captureFace?.debugMode === !0,
766
+ analytics: a.enabled ? a : void 0,
767
+ onEvent: (t) => {
768
+ at(e.onEvent, t);
769
+ },
770
+ onError: (e) => {
771
+ t.reportError(e);
772
+ },
773
+ onDiagnostic: t.uxDiagnosticSink,
774
+ onResult: (t) => {
775
+ c || (g(), at(e.onResult, t));
776
+ }
777
+ });
778
+ h = await t.wait(r, "sdk", (e) => e.close());
779
+ let i = ie(m, e.targetNode, {
780
+ showMirrorCameraButton: !0,
781
+ ...e.cameraManagerUiOptions
782
+ });
783
+ l = await t.wait(i, "sdk", (e) => e.dismount()), f = m.subscribe((e) => e.selectedCamera, (t) => {
784
+ at(e.onSelectedCameraDeviceIdChange, t?.deviceInfo.deviceId);
785
+ }, { fireImmediately: !0 }), p = l.addOnDismountCallback(() => {
786
+ _();
787
+ }), d = m.subscribe((e) => e.playbackState, (t) => {
788
+ t === "playback" && u === void 0 && l !== void 0 && h !== void 0 && (u = te(h, l, {
789
+ localizationStrings: e.feedbackUiOptions?.localizationStrings,
790
+ showHelpButton: e.feedbackUiOptions?.showHelpButton,
791
+ onClose: () => {
792
+ _("User");
793
+ }
794
+ }), d?.(), d = void 0);
795
+ });
796
+ let o = $();
797
+ t.emitDiagnostic({
798
+ phase: "initialization",
799
+ component: "camera",
800
+ status: "started",
801
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
802
+ });
803
+ try {
804
+ let n = ot(m, e.preferredCameraDeviceId);
805
+ await t.wait(n, "camera", () => {
806
+ c || m?.reset();
807
+ }), t.emitDiagnostic({
808
+ phase: "initialization",
809
+ component: "camera",
810
+ status: "completed",
811
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
812
+ durationMs: Math.max(0, $() - o)
813
+ });
814
+ } catch (n) {
815
+ if (n instanceof ne && n.code === "PERMISSION_DENIED" && e.cameraManagerUiOptions?.showCameraErrorModal !== !1) t.emitDiagnostic({
816
+ phase: "initialization",
817
+ component: "camera",
818
+ status: "failed",
819
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
820
+ durationMs: Math.max(0, $() - o),
821
+ errorCode: "CAMERA_ACCESS_DENIED"
822
+ });
823
+ else {
824
+ let e = t.reportError(n, "camera");
825
+ throw t.emitDiagnostic({
826
+ phase: "initialization",
827
+ component: "camera",
828
+ status: e.code === "INITIALIZATION_TIMEOUT" ? "timed-out" : "failed",
829
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
830
+ durationMs: Math.max(0, $() - o),
831
+ errorCode: e.code
832
+ }), e;
833
+ }
834
+ }
835
+ return t.complete(), { destroy: () => _("Sdk") };
836
+ } catch (e) {
837
+ let n = t.reportError(e);
838
+ t.fail(n);
839
+ let r = (async () => {
840
+ await a.logInitFailed(n).catch(() => void 0), await t.flushDiagnostics().catch(() => void 0), await a.sendPinglets().catch(() => void 0), await _().catch(() => void 0);
841
+ })();
842
+ throw await t.waitForCleanup(r, n), n;
843
+ }
844
+ }
845
+ //#endregion
846
+ export { e as BiometricsError, n as ConfigurationError, i as LicenseError, a as PermissionError, o as SessionError, c as checkBiometricsSupport, it as createBiometrics, st as createBiometricsUi, u as createDerivedDeviceInfo, f as getBiometricsFaceFromCaptureResult, p as getDeviceInfo, m as getUserAgentData, h as isFaceCaptureResult, g as normalizeBiometricsError };