@realeyes/verifeye-sdk 1.1.2 → 1.3.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.
@@ -1,2293 +0,0 @@
1
- import { jsx as s, jsxs as S, Fragment as pt } from "react/jsx-runtime";
2
- import { useEffect as Z, useState as D, lazy as gt, useRef as C, Suspense as vt } from "react";
3
- import { useMediaQuery as yt, Box as Se, Link as St, CircularProgress as Ee, createTheme as Et, ThemeProvider as wt, ScopedCssBaseline as bt, Container as Ct, Dialog as Ve, DialogTitle as Pe, DialogContent as ze, DialogContentText as Fe, DialogActions as Rt, Button as Dt } from "@mui/material";
4
- import $ from "@mui/material/DialogContent";
5
- import It from "@mui/material/IconButton";
6
- import xt from "@mui/material/SvgIcon";
7
- import U from "@mui/material/Stack";
8
- import R from "@mui/material/Typography";
9
- import { useTheme as W, responsiveFontSizes as Q } from "@mui/material/styles";
10
- import At from "@mui/material/Dialog";
11
- import Tt from "@mui/icons-material/InfoOutlined";
12
- import { KinesisClient as kt, PutRecordCommand as Mt } from "@aws-sdk/client-kinesis";
13
- import './index.css';class Ot {
14
- sessionId;
15
- accessToken;
16
- onCompleted;
17
- headless;
18
- constructor(e, t, r, i = !1) {
19
- this.sessionId = e, this.accessToken = t, this.onCompleted = r, this.headless = i;
20
- }
21
- async initSession(e) {
22
- return e.initCoreSession(this.sessionId, this.accessToken, this.headless);
23
- }
24
- async fetchResult(e, t, r, i) {
25
- return await t.callVerify(e, r, i), { sessionId: e };
26
- }
27
- complete(e, t) {
28
- this.onCompleted(e.sessionId);
29
- }
30
- }
31
- const Ge = ["eu", "us"];
32
- function Lt(o) {
33
- return typeof o == "string" && Ge.includes(o);
34
- }
35
- class Nt {
36
- region;
37
- constructor(e) {
38
- this.region = e;
39
- }
40
- getCurrentEnvironment() {
41
- return "production";
42
- }
43
- getApiBaseUrl() {
44
- switch (this.region) {
45
- case "eu":
46
- return "https://verifeye-service-eu.realeyes.ai";
47
- case "us":
48
- return "https://verifeye-service-us.realeyes.ai";
49
- default:
50
- throw new Error(`Invalid region: ${this.region}`);
51
- }
52
- }
53
- }
54
- const Ut = ({ size: o = 16, color: e }) => /* @__PURE__ */ s(xt, { children: /* @__PURE__ */ S("svg", { xmlns: "http://www.w3.org/2000/svg", style: { height: o, width: o }, viewBox: "0 0 24 24", fill: e || "currentColor", children: [
55
- /* @__PURE__ */ s("path", { d: "M0 0h24v24H0V0z", fill: "none" }),
56
- /* @__PURE__ */ s("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z" })
57
- ] }) }), ee = ({ uniqueId: o, visible: e = !1 }) => e ? /* @__PURE__ */ s(pt, { children: o && /* @__PURE__ */ s(
58
- R,
59
- {
60
- variant: "body2",
61
- component: "div",
62
- sx: {
63
- flexGrow: 1,
64
- fontSize: "0.75rem",
65
- marginTop: "30px !important",
66
- marginBottom: "10px !important",
67
- lineHeight: 1.6
68
- },
69
- children: /* @__PURE__ */ S("span", { style: { color: "#b0b0b0" }, children: [
70
- "Session ID: ",
71
- /* @__PURE__ */ s("br", {}),
72
- o
73
- ] })
74
- }
75
- ) }) : null, q = ({ open: o, children: e }) => {
76
- if (!o) return;
77
- const t = W(), i = !yt(t.breakpoints.up("md"));
78
- return /* @__PURE__ */ s(
79
- At,
80
- {
81
- fullScreen: i,
82
- fullWidth: !0,
83
- maxWidth: !1,
84
- open: o,
85
- disableAutoFocus: !0,
86
- "aria-labelledby": "responsive-dialog-title",
87
- slotProps: {
88
- paper: {
89
- sx: (d) => ({
90
- [d.breakpoints.up("md")]: {
91
- maxWidth: 420,
92
- minHeight: 520
93
- },
94
- borderRadius: 3
95
- })
96
- }
97
- },
98
- children: e
99
- }
100
- );
101
- }, se = "data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3csvg%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20version='1.1'%20viewBox='0%200%20147%20147'%3e%3c!--%20Generator:%20Adobe%20Illustrator%2030.2.0,%20SVG%20Export%20Plug-In%20.%20SVG%20Version:%202.1.1%20Build%20105)%20--%3e%3cdefs%3e%3cstyle%3e%20.st0%20{%20fill:%20%23263235;%20}%20.st1%20{%20fill:%20%2327eabf;%20}%20%3c/style%3e%3c/defs%3e%3ccircle%20class='st1'%20cx='73.2500001'%20cy='73.7499999'%20r='59.9414062'/%3e%3cpath%20class='st0'%20d='M73,73.5c-2.55,0-4.6875001-.8625-6.4125001-2.5875s-2.5875-3.8625001-2.5875-6.4125001c0-2.4999985.8625-4.6250016,2.5875-6.3750001s3.8625001-2.625,6.4125001-2.625c2.4999985,0,4.6250016.8750015,6.3750001,2.625s2.625,3.8750016,2.625,6.3750001c0,2.55-.8750015,4.6875001-2.625,6.4125001s-3.8750016,2.5875-6.3750001,2.5875ZM54.9999997,88.5000002v-2.7c0-1.05.2625-2.0374993.7875-2.9625s1.2375-1.6624993,2.1375-2.2125c2.2999993-1.35,4.7125008-2.3749993,7.2375001-3.075s5.1375001-1.05,7.8375001-1.05,5.3124986.3499992,7.8375001,1.05,4.9374985,1.725,7.2375001,3.075c.9.5500008,1.6125,1.2874993,2.1375,2.2125s.7875,1.9125.7875,2.9625v2.7c0,.8500008-.2874985,1.5625008-.8625,2.1375-.5750015.5750004-1.2875015.8625-2.1375.8625h-30.0000004c-.8500008,0-1.5625008-.2874996-2.1375-.8625-.5750004-.5749992-.8625-1.2874993-.8625-2.1375ZM48.9999996,103.5000004c-1.65,0-3.0625002-.5875002-4.2375001-1.7625s-1.7625-2.5875-1.7625-4.2375001v-9.0000001c0-.8500008.2875002-1.5625008.8625-2.1375s1.2874998-.8625,2.1375-.8625c.8499996,0,1.5624996.2875008,2.1375.8625s.8625,1.2874993.8625,2.1375v9.0000001h9.0000001c.8500008,0,1.5625008.2874996,2.1375.8625s.8625,1.2875004.8625,2.1375c0,.8500002-.2875008,1.5625002-.8625,2.1375s-1.2874993.8625-2.1375.8625h-9.0000001ZM42.9999996,58.4999998v-9.0000001c0-1.65.5875002-3.0624985,1.7625-4.2375001s2.5875-1.7625,4.2375001-1.7625h9.0000001c.8500008,0,1.5625008.2874985,2.1375.8625s.8625,1.2875015.8625,2.1375-.2875008,1.5624985-.8625,2.1375-1.2874993.8625-2.1375.8625h-9.0000001v9.0000001c0,.8499985-.2874996,1.5624985-.8625,2.1375s-1.2875004.8625-2.1375.8625c-.8500002,0-1.5625002-.2874985-2.1375-.8625s-.8625-1.2875015-.8625-2.1375ZM97.0000004,103.5000004h-9.0000001c-.8499985,0-1.5624985-.2875002-2.1375-.8625s-.8625-1.2874998-.8625-2.1375c0-.8499996.2874985-1.5624996.8625-2.1375s1.2875015-.8625,2.1375-.8625h9.0000001v-9.0000001c0-.8500008.2874985-1.5625008.8625-2.1375s1.2875015-.8625,2.1375-.8625,1.5624985.2875008,2.1375.8625.8625,1.2874993.8625,2.1375v9.0000001c0,1.65-.5874985,3.0625002-1.7625,4.2375001s-2.5875,1.7625-4.2375001,1.7625ZM97.0000004,58.4999998v-9.0000001h-9.0000001c-.8499985,0-1.5624985-.2874985-2.1375-.8625s-.8625-1.2875015-.8625-2.1375.2874985-1.5624985.8625-2.1375,1.2875015-.8625,2.1375-.8625h9.0000001c1.65,0,3.0624985.5874985,4.2375001,1.7625s1.7625,2.5875,1.7625,4.2375001v9.0000001c0,.8499985-.2874985,1.5624985-.8625,2.1375s-1.2875015.8625-2.1375.8625-1.5624985-.2874985-2.1375-.8625-.8625-1.2875015-.8625-2.1375Z'/%3e%3c/svg%3e", Vt = ({
102
- isOpen: o,
103
- onAccept: e,
104
- onClose: t,
105
- uniqueId: r,
106
- isConsentButtonLoading: i,
107
- showVerificationSessionId: d
108
- }) => {
109
- if (!o) return;
110
- const h = W(), c = Q(h).typography;
111
- return /* @__PURE__ */ s(q, { open: o, children: /* @__PURE__ */ S(
112
- $,
113
- {
114
- sx: {
115
- display: "flex",
116
- textAlign: "center !important",
117
- justifyContent: "center !important",
118
- alignItems: "center !important"
119
- },
120
- children: [
121
- /* @__PURE__ */ s(
122
- It,
123
- {
124
- sx: {
125
- position: "absolute",
126
- right: 10,
127
- top: 10,
128
- color: "#b0b0b0",
129
- "&:hover": {
130
- color: "#263235"
131
- }
132
- },
133
- onClick: t,
134
- children: /* @__PURE__ */ s(Ut, { size: 30 })
135
- }
136
- ),
137
- /* @__PURE__ */ S(
138
- U,
139
- {
140
- direction: "column",
141
- sx: {
142
- textAlign: "center",
143
- justifyContent: "center",
144
- alignItems: "center",
145
- width: "100%"
146
- },
147
- children: [
148
- /* @__PURE__ */ s(
149
- "img",
150
- {
151
- src: se,
152
- alt: "Face Verification",
153
- style: { width: 90, height: 90, marginBottom: 8 }
154
- }
155
- ),
156
- /* @__PURE__ */ s(
157
- R,
158
- {
159
- variant: "h2",
160
- component: "div",
161
- sx: {
162
- fontSize: c.h2.fontSize,
163
- fontWeight: "700",
164
- color: "#263235"
165
- },
166
- children: "One quick check"
167
- }
168
- ),
169
- /* @__PURE__ */ S(
170
- R,
171
- {
172
- variant: "body2",
173
- component: "div",
174
- sx: {
175
- fontSize: c.body2.fontSize,
176
- lineHeight: 1.6,
177
- color: "#263235",
178
- mt: "10px"
179
- },
180
- children: [
181
- "Use your camera to verify in seconds.",
182
- /* @__PURE__ */ s("br", {}),
183
- "Fast, secure and ",
184
- /* @__PURE__ */ s("b", { children: "no images are stored." })
185
- ]
186
- }
187
- ),
188
- /* @__PURE__ */ S(
189
- Se,
190
- {
191
- sx: {
192
- backgroundColor: "#F5F5F5",
193
- borderRadius: 2,
194
- p: 1.5,
195
- display: "flex",
196
- alignItems: "flex-start",
197
- gap: 1,
198
- textAlign: "left",
199
- mt: 3,
200
- mb: 4,
201
- width: "100%"
202
- },
203
- children: [
204
- /* @__PURE__ */ s(Tt, { sx: { fontSize: 20, color: "#666666", flexShrink: 0, mt: "1px" } }),
205
- /* @__PURE__ */ S(
206
- R,
207
- {
208
- variant: "body2",
209
- sx: { fontSize: "0.8rem", color: "#666666", lineHeight: 1.5 },
210
- children: [
211
- "By continuing, you give consent to the use of your camera and image for the verification process. Read our",
212
- " ",
213
- /* @__PURE__ */ s(
214
- St,
215
- {
216
- href: "https://realeyes.ai/privacy-policy/",
217
- target: "_blank",
218
- rel: "noopener noreferrer",
219
- sx: { color: "#666666", textDecorationColor: "#666666" },
220
- children: "Privacy Policy"
221
- }
222
- ),
223
- "."
224
- ]
225
- }
226
- )
227
- ]
228
- }
229
- ),
230
- /* @__PURE__ */ S(
231
- "button",
232
- {
233
- className: "realeyes-btn realeyes-btn--rounded",
234
- onClick: e,
235
- disabled: i,
236
- style: { width: "100%", justifyContent: "center" },
237
- children: [
238
- /* @__PURE__ */ s("span", { children: "Continue" }),
239
- i && /* @__PURE__ */ s(
240
- Ee,
241
- {
242
- size: 20,
243
- sx: { color: "white" }
244
- }
245
- )
246
- ]
247
- }
248
- ),
249
- /* @__PURE__ */ s(ee, { uniqueId: r, visible: d })
250
- ]
251
- }
252
- )
253
- ]
254
- }
255
- ) });
256
- };
257
- class ye extends Error {
258
- status;
259
- constructor(e, t) {
260
- super(e), this.name = "PermanentSessionError", this.status = t, Object.setPrototypeOf(this, new.target.prototype);
261
- }
262
- }
263
- class H extends Error {
264
- constructor(e = "Server is busy, please try again later.") {
265
- super(e), this.name = "ServerBusyError", Object.setPrototypeOf(this, new.target.prototype);
266
- }
267
- }
268
- class M {
269
- mediaStream;
270
- videoElement;
271
- canvasElement;
272
- isReady;
273
- adjustLoop;
274
- cameraReadinessLoop;
275
- // Host-supplied stream reused by startVideo instead of getUserMedia. The host owns its
276
- // lifecycle, so stopVideo must not stop its tracks (ownership is derived from whether
277
- // mediaStream is this same object — see stopVideo).
278
- externalStream;
279
- // Video capture settings
280
- static VIDEO_WIDTH = 1280;
281
- static VIDEO_HEIGHT = 720;
282
- static VIDEO_FRAME_RATE = 24;
283
- constructor() {
284
- this.isReady = !1;
285
- }
286
- setExternalStream(e) {
287
- this.externalStream = e;
288
- }
289
- async startVideo(e = void 0, t = void 0) {
290
- const r = this.externalStream?.getVideoTracks().some((i) => i.readyState === "live");
291
- if (this.externalStream && r)
292
- try {
293
- return this.mediaStream = this.externalStream, this.setupVideoElement(), { status: !0, error: null };
294
- } catch (i) {
295
- return console.error(i), { status: !1, error: i?.name || "UnknownError" };
296
- }
297
- else this.externalStream && console.warn(
298
- "CameraManager: external stream has no live video track; falling back to getUserMedia."
299
- );
300
- if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia)
301
- try {
302
- const i = {
303
- video: {
304
- width: {
305
- min: 320,
306
- ideal: M.VIDEO_WIDTH,
307
- max: M.VIDEO_WIDTH
308
- },
309
- height: {
310
- min: 240,
311
- ideal: M.VIDEO_HEIGHT,
312
- max: M.VIDEO_HEIGHT
313
- },
314
- frameRate: {
315
- ideal: M.VIDEO_FRAME_RATE,
316
- max: M.VIDEO_FRAME_RATE
317
- },
318
- facingMode: t ?? { ideal: "user" }
319
- },
320
- audio: !1
321
- }, d = await navigator.mediaDevices.getUserMedia(
322
- e ? { video: { deviceId: e } } : i
323
- );
324
- return this.mediaStream = d, this.setupVideoElement(), { status: !0, error: null };
325
- } catch (i) {
326
- return console.error(i), { status: !1, error: i?.name || "UnknownError" };
327
- }
328
- return { status: !1, error: "NoMediaDevices" };
329
- }
330
- setupVideoElement() {
331
- this.videoElement = document.createElement("video"), this.videoElement.id = "videoExperienceSdk", this.canvasElement = document.createElement("canvas"), this.canvasElement.width = M.VIDEO_WIDTH, this.canvasElement.height = M.VIDEO_HEIGHT, document.body.appendChild(this.videoElement), this.videoElement.pause(), this.videoElement.setAttribute("playsinline", ""), this.videoElement.playsInline = !0, this.videoElement.setAttribute("muted", ""), this.videoElement.controls = !0, this.videoElement.muted = !0, this.videoElement.autoplay = !0, this.videoElement.src = "", this.videoElement.style.width = "1px", this.videoElement.style.height = "1px";
332
- try {
333
- this.videoElement.srcObject = this.mediaStream;
334
- } catch (t) {
335
- console.error(t), this.videoElement.src = window.URL.createObjectURL(
336
- this.mediaStream
337
- );
338
- } finally {
339
- this.videoElement.play();
340
- }
341
- const e = this;
342
- e.videoElement.addEventListener("loadedmetadata", () => {
343
- e.cameraReadinessLoop = setInterval(() => {
344
- e.videoElement && !e.videoElement.paused && !e.videoElement.ended && (e.videoElement.currentTime || 0) > 0 && (e.isReady = !0, clearInterval(e.cameraReadinessLoop), e.adjustLoop = setInterval(() => {
345
- if (e.mediaStream == null) return;
346
- const t = e.mediaStream.getVideoTracks()[0].getSettings().width, r = e.mediaStream.getVideoTracks()[0].getSettings().height;
347
- e.videoElement.width !== t && (e.videoElement.width = e.mediaStream.getVideoTracks()[0].getSettings().width, e.canvasElement.width = e.videoElement.width), e.videoElement.height !== r && (e.videoElement.height = e.mediaStream.getVideoTracks()[0].getSettings().height, e.canvasElement.height = e.videoElement.height);
348
- }, 150));
349
- }, 100);
350
- });
351
- }
352
- /**
353
- * Returns a promise with the image data from the camera.
354
- * @async
355
- * @function getImage
356
- * @memberof CameraManager
357
- * @instance
358
- * @returns {Promise<string>} - A promise with the base64 image data.
359
- * @throws {string} No media stream. Call startVideo to initialize the camera.
360
- *
361
- **/
362
- async getImage() {
363
- const e = this;
364
- return e.mediaStream == null ? Promise.reject(
365
- "Error: No media stream. Call startVideo to initialize the camera."
366
- ) : new Promise((t, r) => {
367
- let i = 0;
368
- const d = () => {
369
- if (i > 10) {
370
- r("Error: Could not get image from camera.");
371
- return;
372
- }
373
- if (e.isReady && e.videoElement && e.canvasElement?.width && e.canvasElement?.height) {
374
- e.canvasElement.getContext("2d").drawImage(
375
- e.videoElement,
376
- 0,
377
- 0,
378
- e.canvasElement.width,
379
- e.canvasElement.height
380
- );
381
- const h = e.canvasElement.toDataURL("image/png");
382
- t(h);
383
- return;
384
- }
385
- i++, setTimeout(d, 150);
386
- };
387
- d();
388
- });
389
- }
390
- /**
391
- * Stops the video stream if it was created by the SDK.
392
- * @function stopVideo
393
- * @memberof CameraManager
394
- * @instance
395
- * @returns {void}
396
- */
397
- stopVideo() {
398
- if (this.mediaStream) {
399
- if (clearInterval(this.adjustLoop), clearInterval(this.cameraReadinessLoop), this.isReady = !1, this.mediaStream !== this.externalStream)
400
- try {
401
- this.mediaStream.getVideoTracks().forEach(function(e) {
402
- e.stop();
403
- });
404
- } catch {
405
- }
406
- this.mediaStream = void 0, this.videoElement.srcObject = null, this.videoElement.removeAttribute("src"), document.body.removeChild(this.videoElement), this.videoElement = void 0, this.canvasElement = void 0, this.adjustLoop = void 0, this.cameraReadinessLoop = void 0;
407
- }
408
- }
409
- }
410
- class Pt {
411
- browser;
412
- version;
413
- constructor() {
414
- this.browser = null, this.version = null;
415
- }
416
- }
417
- class N {
418
- static extractVersion(e, t, r) {
419
- const i = e.match(t);
420
- return i && i.length >= r ? parseInt(i[r], 10) : null;
421
- }
422
- static detectBrowser(e) {
423
- const t = e && e.navigator, r = new Pt();
424
- return typeof e > "u" || !e.navigator ? (r.browser = "Not a browser", r) : (t.mozGetUserMedia && t.userAgent.match(/Firefox\/(\d+)\./) ? (r.browser = "firefox", r.version = N.extractVersion(
425
- t.userAgent,
426
- /Firefox\/(\d+)\./,
427
- 1
428
- )) : t.webkitGetUserMedia && t.userAgent.match(/Chrom(e|ium)\/(\d+)\./) ? (r.browser = "chrome", r.version = N.extractVersion(
429
- t.userAgent,
430
- /Chrom(e|ium)\/(\d+)\./,
431
- 2
432
- )) : t.mediaDevices && t.userAgent.match(/Edge\/(\d+).(\d+)$/) ? (r.browser = "edge", r.version = N.extractVersion(
433
- t.userAgent,
434
- /Edge\/(\d+).(\d+)$/,
435
- 2
436
- )) : e.RTCPeerConnection && t.userAgent.match(/AppleWebKit\/(\d+)\./) ? (r.browser = "safari", r.version = N.extractVersion(
437
- t.userAgent,
438
- /AppleWebKit\/(\d+)\./,
439
- 1
440
- )) : r.browser = "Not supported", r);
441
- }
442
- }
443
- class zt {
444
- shimCreateObjectURL(e) {
445
- const t = e && e.URL;
446
- if (typeof e == "object" && e.HTMLMediaElement && "srcObject" in e.HTMLMediaElement.prototype && t.createObjectURL && t.revokeObjectURL) {
447
- const r = t.createObjectURL.bind(t), i = t.revokeObjectURL.bind(t), d = /* @__PURE__ */ new Map();
448
- let h = 0;
449
- t.createObjectURL = function(a) {
450
- if ("getTracks" in a) {
451
- const l = "polyblob:" + ++h;
452
- return d.set(l, a), l;
453
- }
454
- return r(a);
455
- }, t.revokeObjectURL = function(a) {
456
- i(a), d.delete(a);
457
- };
458
- const c = Object.getOwnPropertyDescriptor(
459
- e.HTMLMediaElement.prototype,
460
- "src"
461
- );
462
- Object.defineProperty(e.HTMLMediaElement.prototype, "src", {
463
- get: function() {
464
- if (c && typeof c.get == "function")
465
- return c.get.call(this);
466
- },
467
- set: function(a) {
468
- if (this.srcObject = d.get(a) || null, c && typeof c.set == "function")
469
- return c.set.call(this, a);
470
- }
471
- });
472
- const n = e.HTMLMediaElement.prototype.setAttribute;
473
- e.HTMLMediaElement.prototype.setAttribute = function() {
474
- return arguments.length === 2 && ("" + arguments[0]).toLowerCase() === "src" && (this.srcObject = d.get(arguments[1]) || null), n.apply(this, arguments);
475
- };
476
- }
477
- }
478
- }
479
- class Ft {
480
- init(e) {
481
- const t = N.detectBrowser(e), r = e && e.navigator, i = function(n) {
482
- if (typeof n != "object" || n.mandatory || n.optional) return n;
483
- const a = {};
484
- return Object.keys(n).forEach(function(l) {
485
- if (l !== "require" && l !== "advanced" && l !== "mediaSource") {
486
- const u = typeof n[l] == "object" ? n[l] : {
487
- ideal: n[l]
488
- };
489
- u.exact !== void 0 && typeof u.exact == "number" && (u.min = u.max = u.exact);
490
- const p = function(f, v) {
491
- return f ? f + v.charAt(0).toUpperCase() + v.slice(1) : v === "deviceId" ? "sourceId" : v;
492
- };
493
- if (u.ideal !== void 0) {
494
- a.optional = a.optional || [];
495
- let f = {};
496
- typeof u.ideal == "number" ? (f[p("min", l)] = u.ideal, a.optional.push(f), f = {}, f[p("max", l)] = u.ideal) : f[p("", l)] = u.ideal, a.optional.push(f);
497
- }
498
- u.exact !== void 0 && typeof u.exact != "number" ? (a.mandatory = a.mandatory || {}, a.mandatory[p("", l)] = u.exact) : ["min", "max"].forEach(function(f) {
499
- u[f] !== void 0 && (a.mandatory = a.mandatory || {}, a.mandatory[p(f, l)] = u[f]);
500
- });
501
- }
502
- }), n.advanced && (a.optional = (a.optional || []).concat(n.advanced)), a;
503
- }, d = function(n, a) {
504
- if (t.version && 61 <= t.version)
505
- return a(n);
506
- if ((n = JSON.parse(JSON.stringify(n))) && typeof n.audio == "object") {
507
- const l = function(u, p, f) {
508
- p in u && !(f in u) && (u[f] = u[p], delete u[p]);
509
- };
510
- n = JSON.parse(JSON.stringify(n)), l(
511
- n.audio,
512
- "autoGainControl",
513
- "googAutoGainControl"
514
- ), l(
515
- n.audio,
516
- "noiseSuppression",
517
- "googNoiseSuppression"
518
- ), n.audio = i(n.audio);
519
- }
520
- if (n && typeof n.video == "object") {
521
- let l = n.video.facingMode;
522
- l = l && (typeof l == "object" ? l : {
523
- ideal: l
524
- });
525
- const u = t.version && 66 > t.version;
526
- if (!(!l || l.exact !== "user" && l.exact !== "environment" && l.ideal !== "user" && l.ideal !== "environment" || r.mediaDevices.getSupportedConstraints && r.mediaDevices.getSupportedConstraints().facingMode && !u)) {
527
- delete n.video.facingMode;
528
- let p = null;
529
- if (l.exact === "environment" || l.ideal === "environment" ? p = ["back", "rear"] : (l.exact === "user" || l.ideal === "user") && (p = ["front"]), p)
530
- return r.mediaDevices.enumerateDevices().then(function(f) {
531
- f = f.filter(function(T) {
532
- return T.kind === "videoinput";
533
- });
534
- let v = f.find(
535
- function(T) {
536
- return p.some(function(oe) {
537
- return T.label.toLowerCase().indexOf(oe) !== -1;
538
- });
539
- }
540
- );
541
- return !v && f.length && p.indexOf("back") !== -1 && (v = f[f.length - 1]), v && (n.video.deviceId = l.exact ? {
542
- exact: v.deviceId
543
- } : {
544
- ideal: v.deviceId
545
- }), n.video = i(n.video), a(n);
546
- });
547
- }
548
- n.video = i(n.video);
549
- }
550
- return a(n);
551
- }, h = function(n) {
552
- return {
553
- name: {
554
- PermissionDeniedError: "NotAllowedError",
555
- PermissionDismissedError: "NotAllowedError",
556
- InvalidStateError: "NotAllowedError",
557
- DevicesNotFoundError: "NotFoundError",
558
- ConstraintNotSatisfiedError: "OverconstrainedError",
559
- TrackStartError: "NotReadableError",
560
- MediaDeviceFailedDueToShutdown: "NotAllowedError",
561
- MediaDeviceKillSwitchOn: "NotAllowedError",
562
- TabCaptureError: "AbortError",
563
- ScreenCaptureError: "AbortError",
564
- DeviceCaptureError: "AbortError"
565
- }[n.name] || n.name,
566
- message: n.message,
567
- constraint: n.constraint || n.constraintName,
568
- toString: function() {
569
- return this.name + (this.message && ": ") + this.message;
570
- }
571
- };
572
- };
573
- r.getUserMedia = function(n, a, l) {
574
- d(n, function(u) {
575
- r.webkitGetUserMedia(
576
- u,
577
- a,
578
- function(p) {
579
- l && l(h(p));
580
- }
581
- );
582
- });
583
- };
584
- const c = function(n) {
585
- return new Promise(function(a, l) {
586
- r.getUserMedia(
587
- n,
588
- a,
589
- l
590
- );
591
- });
592
- };
593
- if (r.mediaDevices || (r.mediaDevices = {
594
- getUserMedia: c,
595
- enumerateDevices: function() {
596
- return new Promise(function(n) {
597
- const a = {
598
- audio: "audioinput",
599
- video: "videoinput"
600
- };
601
- return e.MediaStreamTrack.getSources(function(l) {
602
- n(
603
- l.map(function(u) {
604
- return {
605
- label: u.label,
606
- kind: a[u.kind],
607
- deviceId: u.id,
608
- groupId: ""
609
- };
610
- })
611
- );
612
- });
613
- });
614
- },
615
- getSupportedConstraints: function() {
616
- return {
617
- deviceId: !0,
618
- echoCancellation: !0,
619
- facingMode: !0,
620
- frameRate: !0,
621
- height: !0,
622
- width: !0
623
- };
624
- }
625
- }), r.mediaDevices.getUserMedia) {
626
- const n = r.mediaDevices.getUserMedia.bind(
627
- r.mediaDevices
628
- );
629
- r.mediaDevices.getUserMedia = function(a) {
630
- return d(
631
- a,
632
- function(l) {
633
- return n(l).then(
634
- function(u) {
635
- if (l.audio && !u.getAudioTracks().length || l.video && !u.getVideoTracks().length)
636
- throw u.getTracks().forEach(function(p) {
637
- p.stop();
638
- }), new DOMException("", "NotFoundError");
639
- return u;
640
- },
641
- function(u) {
642
- return Promise.reject(h(u));
643
- }
644
- );
645
- }
646
- );
647
- };
648
- } else
649
- r.mediaDevices.getUserMedia = function(n) {
650
- return c(n);
651
- };
652
- typeof r.mediaDevices.addEventListener > "u" && (r.mediaDevices.addEventListener = function() {
653
- }), typeof r.mediaDevices.removeEventListener > "u" && (r.mediaDevices.removeEventListener = function() {
654
- });
655
- }
656
- }
657
- class _t {
658
- shimGetUserMedia(e) {
659
- return new Ft().init(e);
660
- }
661
- shimMediaStream(e) {
662
- e.MediaStream = e.MediaStream || e.webkitMediaStream;
663
- }
664
- shimSourceObject(e) {
665
- const t = e && e.URL;
666
- typeof e == "object" && (!e.HTMLMediaElement || "srcObject" in e.HTMLMediaElement.prototype || Object.defineProperty(
667
- e.HTMLMediaElement.prototype,
668
- "srcObject",
669
- {
670
- get: function() {
671
- return this._srcObject;
672
- },
673
- set: function(r) {
674
- const i = this;
675
- this._srcObject = r, this.src && t.revokeObjectURL(this.src), r ? (this.src = t.createObjectURL(r), r.addEventListener("addtrack", function() {
676
- i.src && t.revokeObjectURL(i.src), i.src = t.createObjectURL(r);
677
- }), r.addEventListener("removetrack", function() {
678
- i.src && t.revokeObjectURL(i.src), i.src = t.createObjectURL(r);
679
- })) : this.src = "";
680
- }
681
- }
682
- ));
683
- }
684
- }
685
- class Gt {
686
- init(e) {
687
- e = e && e.navigator;
688
- const t = function(i) {
689
- return {
690
- name: {
691
- PermissionDeniedError: "NotAllowedError"
692
- }[i.name] || i.name,
693
- message: i.message,
694
- constraint: i.constraint,
695
- toString: function() {
696
- return this.name;
697
- }
698
- };
699
- }, r = e.mediaDevices.getUserMedia.bind(
700
- e.mediaDevices
701
- );
702
- e.mediaDevices.getUserMedia = function(i) {
703
- return r(i).catch(function(d) {
704
- return Promise.reject(t(d));
705
- });
706
- };
707
- }
708
- }
709
- class Bt {
710
- shimGetUserMedia(e) {
711
- return new Gt().init(e);
712
- }
713
- }
714
- class jt {
715
- init(e) {
716
- const t = N.detectBrowser(e), r = e && e.navigator;
717
- e = e && e.MediaStreamTrack;
718
- const i = function(c) {
719
- return {
720
- name: {
721
- InternalError: "NotReadableError",
722
- NotSupportedError: "TypeError",
723
- PermissionDeniedError: "NotAllowedError",
724
- SecurityError: "NotAllowedError"
725
- }[c.name] || c.name,
726
- message: {
727
- "The operation is insecure.": "The request is not allowed by the user agent or the platform in the current context."
728
- }[c.message] || c.message,
729
- constraint: c.constraint,
730
- toString: function() {
731
- return this.name + (this.message && ": ") + this.message;
732
- }
733
- };
734
- }, d = function(c, n, a) {
735
- const l = function(u) {
736
- if (typeof u != "object" || u.require) return u;
737
- const p = [];
738
- return Object.keys(u).forEach(function(f) {
739
- if (f !== "require" && f !== "advanced" && f !== "mediaSource") {
740
- const v = u[f] = typeof u[f] == "object" ? u[f] : {
741
- ideal: u[f]
742
- };
743
- if (v.min === void 0 && v.max === void 0 && v.exact === void 0 || p.push(f), v.exact !== void 0 && (typeof v.exact == "number" ? v.min = v.max = v.exact : u[f] = v.exact, delete v.exact), v.ideal !== void 0) {
744
- u.advanced = u.advanced || [];
745
- const T = {};
746
- T[f] = typeof v.ideal == "number" ? {
747
- min: v.ideal,
748
- max: v.ideal
749
- } : v.ideal, u.advanced.push(T), delete v.ideal, Object.keys(v).length || delete u[f];
750
- }
751
- }
752
- }), p.length && (u.require = p), u;
753
- };
754
- return c = JSON.parse(JSON.stringify(c)), t.version && 38 > t.version && (c.audio && (c.audio = l(c.audio)), c.video && (c.video = l(c.video))), r.mozGetUserMedia(
755
- c,
756
- n,
757
- function(u) {
758
- a(i(u));
759
- }
760
- );
761
- }, h = function(c) {
762
- return new Promise(function(n, a) {
763
- d(c, n, a);
764
- });
765
- };
766
- if (r.mediaDevices || (r.mediaDevices = {
767
- getUserMedia: h,
768
- addEventListener: function() {
769
- },
770
- removeEventListener: function() {
771
- }
772
- }), r.mediaDevices.enumerateDevices = r.mediaDevices.enumerateDevices || function() {
773
- return new Promise(function(c) {
774
- c([
775
- {
776
- kind: "audioinput",
777
- deviceId: "default",
778
- label: "",
779
- groupId: ""
780
- },
781
- {
782
- kind: "videoinput",
783
- deviceId: "default",
784
- label: "",
785
- groupId: ""
786
- }
787
- ]);
788
- });
789
- }, t.version && 41 > t.version) {
790
- const c = r.mediaDevices.enumerateDevices.bind(
791
- r.mediaDevices
792
- );
793
- r.mediaDevices.enumerateDevices = function() {
794
- return c().then(void 0, function(n) {
795
- if (n.name === "NotFoundError") return [];
796
- throw n;
797
- });
798
- };
799
- }
800
- if (t.version && 49 > t.version) {
801
- const c = r.mediaDevices.getUserMedia.bind(
802
- r.mediaDevices
803
- );
804
- r.mediaDevices.getUserMedia = function(n) {
805
- return c(n).then(
806
- function(a) {
807
- if (n.audio && !a.getAudioTracks().length || n.video && !a.getVideoTracks().length)
808
- throw a.getTracks().forEach(function(l) {
809
- l.stop();
810
- }), new DOMException(
811
- "The object can not be found here.",
812
- "NotFoundError"
813
- );
814
- return a;
815
- },
816
- function(a) {
817
- return Promise.reject(i(a));
818
- }
819
- );
820
- };
821
- }
822
- if (!(t.version && 55 < t.version && "autoGainControl" in r.mediaDevices.getSupportedConstraints())) {
823
- const c = function(a, l, u) {
824
- l in a && !(u in a) && (a[u] = a[l], delete a[l]);
825
- }, n = r.mediaDevices.getUserMedia.bind(
826
- r.mediaDevices
827
- );
828
- if (r.mediaDevices.getUserMedia = function(a) {
829
- return typeof a == "object" && typeof a.audio == "object" && (a = JSON.parse(JSON.stringify(a)), c(a.audio, "autoGainControl", "mozAutoGainControl"), c(a.audio, "noiseSuppression", "mozNoiseSuppression")), n(a);
830
- }, e && e.prototype.getSettings) {
831
- const a = e.prototype.getSettings;
832
- e.prototype.getSettings = function() {
833
- const l = a.apply(this, arguments);
834
- return c(l, "mozAutoGainControl", "autoGainControl"), c(l, "mozNoiseSuppression", "noiseSuppression"), l;
835
- };
836
- }
837
- if (e && e.prototype.applyConstraints) {
838
- const a = e.prototype.applyConstraints;
839
- e.prototype.applyConstraints = function(l) {
840
- return this.kind === "audio" && typeof l == "object" && (l = JSON.parse(JSON.stringify(l)), c(l, "autoGainControl", "mozAutoGainControl"), c(l, "noiseSuppression", "mozNoiseSuppression")), a.apply(this, [l]);
841
- };
842
- }
843
- }
844
- r.getUserMedia = function(c, n, a) {
845
- if (t.version && 44 > t.version)
846
- return d(
847
- c,
848
- n,
849
- a
850
- );
851
- console.warn(
852
- "navigator.getUserMedia",
853
- "navigator.mediaDevices.getUserMedia"
854
- ), r.mediaDevices.getUserMedia(c).then(n, a);
855
- };
856
- }
857
- }
858
- class Ht {
859
- shimGetUserMedia(e) {
860
- return new jt().init(e);
861
- }
862
- shimSourceObject(e) {
863
- typeof e == "object" && (!e.HTMLMediaElement || "srcObject" in e.HTMLMediaElement.prototype || Object.defineProperty(
864
- e.HTMLMediaElement.prototype,
865
- "srcObject",
866
- {
867
- get: function() {
868
- return this.mozSrcObject;
869
- },
870
- set: function(t) {
871
- this.mozSrcObject = t;
872
- }
873
- }
874
- ));
875
- }
876
- }
877
- class $t {
878
- shimGetUserMedia(e) {
879
- const t = e && e.navigator;
880
- t.getUserMedia || (t.webkitGetUserMedia ? t.getUserMedia = t.webkitGetUserMedia.bind(t) : t.mediaDevices && t.mediaDevices.getUserMedia && (t.getUserMedia = (function(r, i, d) {
881
- t.mediaDevices.getUserMedia(r).then(i, d);
882
- }).bind(t)));
883
- }
884
- }
885
- class Wt {
886
- browserDetails;
887
- browserAdapter;
888
- commonAdapter;
889
- extractVersion;
890
- constructor(e, t, r, i) {
891
- this.browserDetails = e, this.browserAdapter = t, this.commonAdapter = r, this.extractVersion = i;
892
- }
893
- }
894
- class qt {
895
- init() {
896
- const e = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : {}, t = e && e.window, r = N.detectBrowser(t), i = new _t(), d = new Bt(), h = new Ht(), c = new $t(), n = new zt(), a = new Wt(
897
- r,
898
- null,
899
- n,
900
- N.extractVersion
901
- );
902
- switch (r.browser) {
903
- case "chrome":
904
- a.browserAdapter = i, n.shimCreateObjectURL(t), i.shimGetUserMedia(t), i.shimMediaStream(t), i.shimSourceObject(t);
905
- break;
906
- case "firefox":
907
- a.browserAdapter = h, n.shimCreateObjectURL(t), h.shimGetUserMedia(t), h.shimSourceObject(t);
908
- break;
909
- case "edge":
910
- a.browserAdapter = d, n.shimCreateObjectURL(t), d.shimGetUserMedia(t);
911
- break;
912
- case "safari":
913
- a.browserAdapter = c, n.shimCreateObjectURL(t), c.shimGetUserMedia(t);
914
- break;
915
- }
916
- return a;
917
- }
918
- }
919
- class Kt {
920
- cameraManager;
921
- constructor() {
922
- this.cameraManager = new M();
923
- }
924
- async init() {
925
- return new qt().init();
926
- }
927
- async startVideo(e) {
928
- const t = await this.cameraManager.startVideo(
929
- e,
930
- { ideal: "user" }
931
- );
932
- return this.translateMediaError(t);
933
- }
934
- async getImage() {
935
- return await this.cameraManager.getImage();
936
- }
937
- stopVideo() {
938
- return this.cameraManager.stopVideo();
939
- }
940
- setExternalStream(e) {
941
- this.cameraManager.setExternalStream(e);
942
- }
943
- getCameraManager() {
944
- return this.cameraManager;
945
- }
946
- getVideoElement() {
947
- return this.cameraManager.videoElement;
948
- }
949
- translateMediaError(e) {
950
- if (e.status)
951
- return new F(
952
- L.GRANTED,
953
- z.GRANTED
954
- );
955
- switch (e.error) {
956
- case "AbortError":
957
- return new F(
958
- L.CAMERA_ERROR,
959
- z.ABORT_ERROR
960
- );
961
- case "NotAllowedError":
962
- return new F(
963
- L.DENIED,
964
- z.NOT_ALLOWED_ERROR
965
- );
966
- case "NotFoundError":
967
- return new F(
968
- L.NO_CAMERA,
969
- z.NOT_FOUND_ERROR
970
- );
971
- case "NotReadableError":
972
- return new F(
973
- L.CAMERA_ERROR,
974
- z.NOT_READABLE_ERROR
975
- );
976
- case "OverconstrainedError":
977
- return new F(
978
- L.NO_CAMERA,
979
- z.OVERCONSTRAINED_ERROR
980
- );
981
- case "SecurityError":
982
- return new F(
983
- L.DENIED,
984
- z.SECURITY_ERROR
985
- );
986
- default:
987
- return new F(
988
- L.CAMERA_ERROR,
989
- z.UNKNOWN_ERROR
990
- );
991
- }
992
- }
993
- }
994
- const L = {
995
- GRANTED: "granted",
996
- NO_CAMERA: "no-camera",
997
- CAMERA_ERROR: "camera-error",
998
- DENIED: "denied"
999
- }, z = {
1000
- GRANTED: "granted",
1001
- ABORT_ERROR: "abort-error",
1002
- NOT_ALLOWED_ERROR: "not-allowed-error",
1003
- NOT_FOUND_ERROR: "not-found-error",
1004
- NOT_READABLE_ERROR: "not-readable-error",
1005
- OVERCONSTRAINED_ERROR: "overconstrained-error",
1006
- SECURITY_ERROR: "security-error",
1007
- UNKNOWN_ERROR: "unknown-error"
1008
- };
1009
- class F {
1010
- cameraAccessResult;
1011
- detailedCameraAccessResult;
1012
- isGranted;
1013
- constructor(e, t) {
1014
- this.cameraAccessResult = e, this.isGranted = e === L.GRANTED, this.detailedCameraAccessResult = t;
1015
- }
1016
- }
1017
- function Be() {
1018
- return crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(16).slice(2)}`;
1019
- }
1020
- function X() {
1021
- const o = "verify-correlation-id";
1022
- let e = sessionStorage.getItem(o);
1023
- return e || (e = Be(), e = e.replaceAll("-", ""), sessionStorage.setItem(o, e)), e;
1024
- }
1025
- function Jt(o) {
1026
- sessionStorage.setItem("verify-event-info-account-hash", o.accountHash), sessionStorage.setItem("verify-event-info-verification-session-id", o.verificationSessionId);
1027
- }
1028
- function j() {
1029
- const o = sessionStorage.getItem("verify-event-info-account-hash") || "", e = sessionStorage.getItem("verify-event-info-verification-session-id") || "";
1030
- return {
1031
- accountHash: o,
1032
- verificationSessionId: e
1033
- };
1034
- }
1035
- function Yt(o) {
1036
- const e = o.getFullYear(), t = (o.getMonth() + 1).toString().padStart(2, "0"), r = o.getDate().toString().padStart(2, "0"), i = o.getHours().toString().padStart(2, "0"), d = o.getMinutes().toString().padStart(2, "0"), h = o.getSeconds().toString().padStart(2, "0"), c = o.getMilliseconds().toString().padStart(3, "0"), n = -o.getTimezoneOffset(), a = n >= 0 ? "+" : "-", l = Math.abs(n), u = Math.floor(l / 60).toString().padStart(2, "0"), p = (l % 60).toString().padStart(2, "0");
1037
- return `${e}-${t}-${r}T${i}:${d}:${h}.${c}${a}${u}:${p}`;
1038
- }
1039
- class Zt {
1040
- kinesisClient = null;
1041
- kinesisConfig = null;
1042
- sequenceNumber = 1;
1043
- serverTimeOffset = 0;
1044
- eventQueue = [];
1045
- environment;
1046
- constructor(e) {
1047
- this.environment = e.getCurrentEnvironment();
1048
- }
1049
- initialize(e) {
1050
- if (!e) {
1051
- this.logMessage("warn", "Kinesis configuration not available - events will not be sent"), this.kinesisClient = null, this.kinesisConfig = null;
1052
- return;
1053
- }
1054
- this.kinesisConfig = e;
1055
- const t = Date.now(), r = new Date(e.serverTime).getTime();
1056
- this.serverTimeOffset = r - t, this.logMessage("log", `Server time offset: ${this.serverTimeOffset}ms`), this.kinesisClient = new kt({
1057
- region: e.region,
1058
- credentials: {
1059
- accessKeyId: e.accessKeyId,
1060
- secretAccessKey: e.secretAccessKey,
1061
- sessionToken: e.sessionToken
1062
- },
1063
- retryMode: "standard",
1064
- maxAttempts: 3
1065
- }), this.logMessage("log", `Kinesis client initialized for stream: ${e.streamName}`);
1066
- }
1067
- async sendEvent(e, t, r, i) {
1068
- const d = i ?? Date.now(), h = new Date(d + this.serverTimeOffset), c = h.toISOString(), n = Yt(h), a = {
1069
- type: e,
1070
- absolute_utc_time: c,
1071
- absolute_local_time: n,
1072
- sequence_number: this.sequenceNumber++,
1073
- args: r
1074
- };
1075
- if (this.eventQueue.push(a), !t)
1076
- return !0;
1077
- if (!this.kinesisClient || !this.kinesisConfig)
1078
- return this.logMessage("warn", `Kinesis not configured - event '${e}' queued but not sent`), !1;
1079
- const l = j();
1080
- let u = !0;
1081
- for (; this.eventQueue.length > 0; ) {
1082
- const p = this.eventQueue.shift();
1083
- p.source_id = t, p.account_hash = l.accountHash, p.region = this.kinesisConfig.logicalRegion, p.host = this.kinesisConfig.domain, p.pid = X();
1084
- try {
1085
- const f = new Mt({
1086
- StreamName: this.kinesisConfig.streamName,
1087
- PartitionKey: p.source_id,
1088
- Data: new TextEncoder().encode(JSON.stringify(p))
1089
- }), v = await this.kinesisClient.send(f);
1090
- this.logMessage("log", `Event '${p.type}' sent to Kinesis:`, {
1091
- sequenceNumber: v.SequenceNumber,
1092
- shardId: v.ShardId
1093
- });
1094
- } catch (f) {
1095
- this.logMessage("warn", `Failed to send event '${p.type}' to Kinesis:`, f), u = !1;
1096
- }
1097
- }
1098
- return u;
1099
- }
1100
- logMessage(e, t, r) {
1101
- this.environment !== "production" && console[e](`[KinesisService] ${t}`, r || "");
1102
- }
1103
- }
1104
- class Qt {
1105
- timers = /* @__PURE__ */ new Map();
1106
- stats = [];
1107
- kinesisService;
1108
- sessionIdRef;
1109
- constructor(e, t) {
1110
- this.kinesisService = e, this.sessionIdRef = t;
1111
- }
1112
- startTimer(e) {
1113
- this.timers.set(e, performance.now());
1114
- }
1115
- sendStatsCheckpoint() {
1116
- const e = this.getAllStatsAsObject();
1117
- Object.keys(e).length > 0 && this.kinesisService.sendEvent("StatsCollected", this.sessionIdRef.current, e);
1118
- }
1119
- stopTimer(e, t = !0) {
1120
- const r = this.timers.get(e);
1121
- if (r === void 0)
1122
- return this.stats.push({ type: e, duration: 0 }), t && this.sendStatsCheckpoint(), 0;
1123
- const i = Math.round(performance.now() - r);
1124
- return this.stats.push({ type: e, duration: i }), this.timers.delete(e), t && this.sendStatsCheckpoint(), i;
1125
- }
1126
- addStat(e, t, r = !0) {
1127
- this.stats.push({ type: e, duration: Math.round(t) }), r && this.sendStatsCheckpoint();
1128
- }
1129
- addStatIfMissing(e, t, r = !0) {
1130
- this.stats.some((i) => i.type === e) || this.addStat(e, t, r);
1131
- }
1132
- async forceSendStats() {
1133
- const e = this.getAllStatsAsObject();
1134
- return console.log("Force sending stats:", e), Object.keys(e).length > 0 ? await this.kinesisService.sendEvent("StatsCollected", this.sessionIdRef.current, e) : !0;
1135
- }
1136
- getAllStats() {
1137
- return [...this.stats];
1138
- }
1139
- getAllStatsAsObject() {
1140
- const e = {};
1141
- for (const t of this.stats)
1142
- e[t.type] = t.duration;
1143
- return e;
1144
- }
1145
- reset() {
1146
- this.timers.clear(), this.stats.length = 0;
1147
- }
1148
- }
1149
- class Xt {
1150
- cameraSdk;
1151
- kinesisService;
1152
- statsService = null;
1153
- apiBaseUrl;
1154
- livenessCheckType = void 0;
1155
- mediaPipeInitPromise = null;
1156
- faceDetectionServiceModule = null;
1157
- videoRecorderServiceModule = null;
1158
- // Signal piped through to every fetch issued by this service so the host component can
1159
- // abort in-flight init / capture-image / capture-video calls on unmount. The Verification
1160
- // page sets this from its lifecycle AbortController; if nobody sets it, signal is undefined
1161
- // and fetches behave as before.
1162
- abortSignal = void 0;
1163
- accessToken = void 0;
1164
- constructor(e, t) {
1165
- this.cameraSdk = new Kt(), this.apiBaseUrl = t.getApiBaseUrl(), this.kinesisService = e;
1166
- }
1167
- setAbortSignal(e) {
1168
- this.abortSignal = e;
1169
- }
1170
- getAccessToken() {
1171
- return this.accessToken;
1172
- }
1173
- preloadMediaPipe() {
1174
- this.mediaPipeInitPromise || (this.mediaPipeInitPromise = this.loadAndInitMediaPipe().catch(() => {
1175
- this.mediaPipeInitPromise = null;
1176
- }));
1177
- }
1178
- async loadAndInitMediaPipe() {
1179
- this.faceDetectionServiceModule = await import("./faceDetectionService-CohHJWWF.js"), await this.faceDetectionServiceModule.faceDetectionService.initialize(), this.livenessCheckType === "basic" && (this.videoRecorderServiceModule = await import("./videoRecorderService-eqEwhEav.js"), await this.videoRecorderServiceModule.videoRecorderService.initialize());
1180
- }
1181
- async ensureMediaPipeInitialized() {
1182
- this.mediaPipeInitPromise || this.preloadMediaPipe(), await this.mediaPipeInitPromise;
1183
- }
1184
- async initCoreSession(e, t, r = !1) {
1185
- sessionStorage.clear();
1186
- const i = performance.now(), d = await this.callInitCoreSession(e, t, r);
1187
- return d.sessionToken = t, this.applyInitSessionResponse(d, i);
1188
- }
1189
- // Called by RedirectStrategy after it fetches /init-redirect-session itself,
1190
- // to apply the side effects that belong to the core service (liveness type,
1191
- // camera init, kinesis bootstrap).
1192
- async applyInitSessionResponse(e, t) {
1193
- return e.sessionToken && (this.accessToken = e.sessionToken), this.livenessCheckType = e.livenessCheckType?.toLowerCase(), console.log(`Liveness check type: ${this.livenessCheckType}`), (this.livenessCheckType === "disabled" || this.livenessCheckType === "basic") && await this.cameraSdk.init(), Jt({ accountHash: e.accountHash ?? "", verificationSessionId: e.verificationSessionId }), this.kinesisService.initialize(e.kinesisConfig), this.kinesisService.sendEvent("SessionInitialized", e.verificationSessionId, {
1194
- duration: performance.now() - t
1195
- }), e;
1196
- }
1197
- async checkCameraAccess() {
1198
- try {
1199
- return (await navigator.permissions.query({
1200
- name: "camera"
1201
- })).state;
1202
- } catch {
1203
- return "unknown";
1204
- }
1205
- }
1206
- async startCamera(e = void 0) {
1207
- return await this.cameraSdk.startVideo(e);
1208
- }
1209
- async stopCamera() {
1210
- this.cameraSdk.stopVideo();
1211
- }
1212
- setExternalStream(e) {
1213
- this.cameraSdk.setExternalStream(e);
1214
- }
1215
- async detectFace(e, t = void 0) {
1216
- let r = 2;
1217
- const i = await this.cameraSdk.startVideo(
1218
- t
1219
- );
1220
- let d = new _(!1);
1221
- if (i.isGranted) {
1222
- if (await this.ensureMediaPipeInitialized(), !this.faceDetectionServiceModule)
1223
- throw new Error("MediaPipe not initialized");
1224
- const h = this.cameraSdk.getVideoElement();
1225
- return h ? (await this.retryInCaseOfError(
1226
- async () => {
1227
- const c = await this.faceDetectionServiceModule.faceDetectionService.findBestFaceFrame(
1228
- h,
1229
- 2e3,
1230
- 0.9
1231
- );
1232
- if (!c.hasFace || !c.base64Image)
1233
- return d.base64Image = c.base64Image, new _(!1);
1234
- if (this.livenessCheckType === "basic") {
1235
- if (!this.videoRecorderServiceModule)
1236
- throw new Error("Video recorder not initialized");
1237
- const n = await this.videoRecorderServiceModule.videoRecorderService.recordVideo(
1238
- h,
1239
- 500
1240
- );
1241
- if (!n.hasFaceDetected)
1242
- return d.base64Image = c.base64Image, new _(!1);
1243
- this.statsService?.startTimer("callCaptureVideoDuration"), d = await this.callCaptureVideo(
1244
- new tr(
1245
- e,
1246
- n.videoBlob,
1247
- n.cryptoChain,
1248
- n.mimeType
1249
- )
1250
- ), this.statsService?.stopTimer("callCaptureVideoDuration");
1251
- } else
1252
- this.statsService?.startTimer("callCaptureImageDuration"), d = await this.callCaptureImage(
1253
- new er(e, c.base64Image)
1254
- ), this.statsService?.stopTimer("callCaptureImageDuration");
1255
- return d.faceDetected || (d.base64Image = c.base64Image), d;
1256
- },
1257
- async (c) => c && c.faceDetected ? { shouldRetry: !1 } : (r--, { shouldRetry: r >= 0 }),
1258
- () => Promise.resolve({ shouldRetry: !0 })
1259
- ).finally(() => {
1260
- this.cameraSdk.stopVideo();
1261
- }), d) : (this.cameraSdk.stopVideo(), new _(!1));
1262
- }
1263
- return new _(!1);
1264
- }
1265
- async retryInCaseOfError(e, t, r) {
1266
- let i = 2;
1267
- do
1268
- try {
1269
- const d = await e();
1270
- if ((await t(d)).shouldRetry)
1271
- i = 2;
1272
- else break;
1273
- } catch (d) {
1274
- if (!(await r(d)).shouldRetry)
1275
- break;
1276
- if (i--, i <= 0)
1277
- throw d;
1278
- }
1279
- while (!0);
1280
- }
1281
- resolveTechUserId() {
1282
- let t = new URL(window.location.href).searchParams.get("reTechUserId");
1283
- return t != null ? localStorage.setItem("verify-tech-user-id", t) : (t = localStorage.getItem("verify-tech-user-id"), t == null && (t = Be(), localStorage.setItem("verify-tech-user-id", t))), t;
1284
- }
1285
- async callInitCoreSession(e, t, r) {
1286
- const i = await fetch(
1287
- `${this.apiBaseUrl}/api/v1/verification/init-session`,
1288
- {
1289
- method: "POST",
1290
- headers: {
1291
- "Content-Type": "application/json",
1292
- "x-verify-correlation-id": X(),
1293
- "x-verify-tech-user-id": this.resolveTechUserId(),
1294
- Authorization: `Bearer ${t}`
1295
- },
1296
- body: JSON.stringify({ verificationSessionId: e, localTime: (/* @__PURE__ */ new Date()).toISOString(), isHeadless: r }),
1297
- signal: this.abortSignal
1298
- }
1299
- );
1300
- return this.parseInitResponse(i);
1301
- }
1302
- async parseInitResponse(e) {
1303
- if (!e.ok) {
1304
- if (e.status === 429) throw new H();
1305
- const r = (await e.text()).trim() || "An error occurred during initializing the session!";
1306
- throw e.status >= 400 && e.status < 500 ? new ye(r, e.status) : new Error(r);
1307
- }
1308
- return e.json();
1309
- }
1310
- async callVerify(e, t, r) {
1311
- let i = `${this.apiBaseUrl}/api/v1/verification/verify`;
1312
- const d = await fetch(i, {
1313
- method: "POST",
1314
- headers: {
1315
- "Content-Type": "application/json",
1316
- Authorization: `Bearer ${this.accessToken}`,
1317
- "x-verify-correlation-id": X(),
1318
- "x-verify-account-hash": j().accountHash,
1319
- "x-verify-event-source-id": j().verificationSessionId
1320
- },
1321
- body: JSON.stringify({ verificationSessionId: e, failedReason: t }),
1322
- signal: r ?? this.abortSignal
1323
- });
1324
- if (!d.ok)
1325
- throw d.status === 429 ? new H() : new Error(await d.text() || "Verification failed");
1326
- }
1327
- async callCaptureImage(e) {
1328
- const t = await fetch(
1329
- `${this.apiBaseUrl}/api/v1/verification/capture-image`,
1330
- {
1331
- method: "POST",
1332
- headers: {
1333
- "Content-Type": "application/json",
1334
- Authorization: `Bearer ${this.accessToken}`,
1335
- "x-verify-correlation-id": X(),
1336
- "x-verify-account-hash": j().accountHash,
1337
- "x-verify-event-source-id": j().verificationSessionId
1338
- },
1339
- body: JSON.stringify(e),
1340
- signal: this.abortSignal
1341
- }
1342
- );
1343
- if (!t.ok)
1344
- throw t.status === 429 ? new H() : t.status === 400 ? new Error(await t.text()) : new Error("An error occurred during capturing image!");
1345
- return new _(!0);
1346
- }
1347
- async callCaptureVideo(e) {
1348
- const t = await this.blobToBase64(e.videoBlob), r = await fetch(
1349
- `${this.apiBaseUrl}/api/v1/verification/capture-video`,
1350
- {
1351
- method: "POST",
1352
- headers: {
1353
- "Content-Type": "application/json",
1354
- Authorization: `Bearer ${this.accessToken}`,
1355
- "x-verify-correlation-id": X(),
1356
- "x-verify-account-hash": j().accountHash,
1357
- "x-verify-event-source-id": j().verificationSessionId
1358
- },
1359
- body: JSON.stringify({
1360
- verificationSessionId: e.verificationSessionId,
1361
- base64Video: t,
1362
- cryptoChain: e.cryptoChain,
1363
- mimeType: e.mimeType
1364
- }),
1365
- signal: this.abortSignal
1366
- }
1367
- );
1368
- if (!r.ok)
1369
- throw r.status === 429 ? new H() : r.status === 400 ? new Error(await r.text()) : new Error("An error occurred during capturing video!");
1370
- return new _(!0);
1371
- }
1372
- async blobToBase64(e) {
1373
- if (!e || e.size === 0)
1374
- throw new Error("Empty or invalid video blob");
1375
- return new Promise((t, r) => {
1376
- const i = new FileReader();
1377
- i.onloadend = () => {
1378
- const d = i.result;
1379
- if (!d || typeof d != "string") {
1380
- r(new Error("Failed to read blob as data URL"));
1381
- return;
1382
- }
1383
- const h = d.split(",");
1384
- if (h.length !== 2 || !h[1]) {
1385
- r(new Error("Invalid data URL format"));
1386
- return;
1387
- }
1388
- const c = h[1];
1389
- console.log(`Video blob converted to base64: ${(c.length * 0.75 / 1024).toFixed(2)} KB`), t(c);
1390
- }, i.onerror = () => {
1391
- r(new Error(`FileReader error: ${i.error?.message || "Unknown error"}`));
1392
- }, i.readAsDataURL(e);
1393
- });
1394
- }
1395
- }
1396
- class er {
1397
- verificationSessionId;
1398
- base64Image;
1399
- constructor(e, t) {
1400
- this.verificationSessionId = e, this.base64Image = t;
1401
- }
1402
- }
1403
- class tr {
1404
- verificationSessionId;
1405
- videoBlob;
1406
- cryptoChain;
1407
- mimeType;
1408
- constructor(e, t, r, i) {
1409
- this.verificationSessionId = e, this.videoBlob = t, this.cryptoChain = r, this.mimeType = i;
1410
- }
1411
- }
1412
- class _ {
1413
- faceDetected;
1414
- base64Image;
1415
- constructor(e, t = void 0) {
1416
- this.faceDetected = e, this.base64Image = t;
1417
- }
1418
- }
1419
- const rr = ({
1420
- isOpen: o,
1421
- uniqueId: e,
1422
- onPermissionGranted: t,
1423
- onPermissionDenied: r,
1424
- verificationService: i
1425
- }) => {
1426
- if (!o) return;
1427
- const d = W(), h = Q(d).typography;
1428
- return i.checkCameraAccess().then((c) => {
1429
- if (c === "granted") {
1430
- t();
1431
- return;
1432
- } else if (c === "denied") {
1433
- r();
1434
- return;
1435
- } else
1436
- i.startCamera().then((n) => {
1437
- if (n.isGranted) {
1438
- i.stopCamera(), t();
1439
- return;
1440
- }
1441
- r();
1442
- }).catch(() => {
1443
- r();
1444
- });
1445
- }), /* @__PURE__ */ s(q, { open: o, children: /* @__PURE__ */ s(
1446
- $,
1447
- {
1448
- sx: {
1449
- display: "flex",
1450
- textAlign: "center !important",
1451
- justifyContent: "center !important",
1452
- alignItems: "center !important"
1453
- },
1454
- children: /* @__PURE__ */ S(
1455
- U,
1456
- {
1457
- direction: "column",
1458
- spacing: 2,
1459
- sx: {
1460
- textAlign: "center",
1461
- justifyContent: "center",
1462
- alignItems: "center"
1463
- },
1464
- children: [
1465
- /* @__PURE__ */ s(
1466
- R,
1467
- {
1468
- variant: "h2",
1469
- component: "div",
1470
- sx: {
1471
- fontSize: h.h2.fontSize,
1472
- fontWeight: "bold",
1473
- color: "#263235"
1474
- },
1475
- children: "Verify you are not a robot with a selfie"
1476
- }
1477
- ),
1478
- /* @__PURE__ */ S(
1479
- R,
1480
- {
1481
- variant: "body2",
1482
- component: "div",
1483
- sx: {
1484
- fontSize: h.body2.fontSize,
1485
- color: "#263235"
1486
- },
1487
- children: [
1488
- "Realeyes needs brief camera access ",
1489
- /* @__PURE__ */ s("br", {}),
1490
- "Please, click “Allow”"
1491
- ]
1492
- }
1493
- ),
1494
- /* @__PURE__ */ s("div", { className: "face-icon-container", children: /* @__PURE__ */ s(
1495
- "img",
1496
- {
1497
- src: se,
1498
- alt: "Face Verification",
1499
- className: "face-icon"
1500
- }
1501
- ) }),
1502
- /* @__PURE__ */ S(
1503
- U,
1504
- {
1505
- direction: "column",
1506
- sx: {
1507
- textAlign: "center",
1508
- justifyContent: "center",
1509
- alignItems: "center"
1510
- },
1511
- children: [
1512
- /* @__PURE__ */ s(
1513
- R,
1514
- {
1515
- variant: "body2",
1516
- component: "div",
1517
- sx: {
1518
- flexGrow: 1,
1519
- fontSize: h.body2.fontSize,
1520
- fontWeight: "bold",
1521
- color: "#263235"
1522
- },
1523
- children: "No one will ever see you"
1524
- }
1525
- ),
1526
- /* @__PURE__ */ s(
1527
- R,
1528
- {
1529
- variant: "body2",
1530
- component: "div",
1531
- sx: {
1532
- flexGrow: 1,
1533
- fontSize: h.body2.fontSize,
1534
- fontWeight: "bold",
1535
- color: "#263235"
1536
- },
1537
- children: "Your data is encrypted"
1538
- }
1539
- )
1540
- ]
1541
- }
1542
- ),
1543
- /* @__PURE__ */ s(ee, { uniqueId: e })
1544
- ]
1545
- }
1546
- )
1547
- }
1548
- ) });
1549
- }, ve = ({ isOpen: o, text: e }) => {
1550
- if (o)
1551
- return e || (e = "Loading..."), /* @__PURE__ */ s(q, { open: o, children: /* @__PURE__ */ s(
1552
- $,
1553
- {
1554
- sx: {
1555
- display: "flex",
1556
- textAlign: "center !important",
1557
- justifyContent: "center !important",
1558
- alignItems: "center !important"
1559
- },
1560
- children: /* @__PURE__ */ S(
1561
- Se,
1562
- {
1563
- display: "flex",
1564
- flexDirection: "column",
1565
- alignItems: "center",
1566
- justifyContent: "center",
1567
- minHeight: "100px",
1568
- minWidth: "300px",
1569
- children: [
1570
- /* @__PURE__ */ s(Ee, { sx: { color: "#10b981" } }),
1571
- /* @__PURE__ */ s(R, { variant: "body2", sx: { mt: 2 }, children: e })
1572
- ]
1573
- }
1574
- )
1575
- }
1576
- ) });
1577
- }, ir = ({
1578
- isOpen: o,
1579
- uniqueId: e,
1580
- onTryAgain: t
1581
- }) => {
1582
- if (!o) return;
1583
- const r = W(), i = Q(r).typography;
1584
- return /* @__PURE__ */ s(q, { open: o, children: /* @__PURE__ */ s(
1585
- $,
1586
- {
1587
- sx: {
1588
- display: "flex",
1589
- textAlign: "center !important",
1590
- justifyContent: "center !important",
1591
- alignItems: "center !important"
1592
- },
1593
- children: /* @__PURE__ */ S(
1594
- U,
1595
- {
1596
- direction: "column",
1597
- spacing: 2,
1598
- sx: {
1599
- textAlign: "center",
1600
- justifyContent: "center",
1601
- alignItems: "center"
1602
- },
1603
- children: [
1604
- /* @__PURE__ */ s(
1605
- R,
1606
- {
1607
- variant: "h2",
1608
- component: "div",
1609
- sx: {
1610
- flexGrow: 1,
1611
- fontSize: i.h2.fontSize,
1612
- fontWeight: "bold",
1613
- color: "#263235"
1614
- },
1615
- children: "Verify you are not a robot with a selfie"
1616
- }
1617
- ),
1618
- /* @__PURE__ */ S(
1619
- R,
1620
- {
1621
- variant: "body2",
1622
- component: "div",
1623
- sx: {
1624
- fontSize: i.body2.fontSize,
1625
- color: "#263235"
1626
- },
1627
- children: [
1628
- "Realeyes needs brief camera access ",
1629
- /* @__PURE__ */ s("br", {}),
1630
- 'Please allow your camera and click on "Try Again".'
1631
- ]
1632
- }
1633
- ),
1634
- /* @__PURE__ */ s("div", { className: "face-icon-container", children: /* @__PURE__ */ s(
1635
- "img",
1636
- {
1637
- src: se,
1638
- alt: "Face Verification",
1639
- className: "face-icon"
1640
- }
1641
- ) }),
1642
- /* @__PURE__ */ S(
1643
- U,
1644
- {
1645
- direction: "column",
1646
- sx: {
1647
- textAlign: "center",
1648
- justifyContent: "center",
1649
- alignItems: "center"
1650
- },
1651
- children: [
1652
- /* @__PURE__ */ s(
1653
- R,
1654
- {
1655
- variant: "body2",
1656
- component: "div",
1657
- sx: {
1658
- flexGrow: 1,
1659
- fontSize: i.body2.fontSize,
1660
- fontWeight: "bold",
1661
- color: "#263235"
1662
- },
1663
- children: "No one will ever see you"
1664
- }
1665
- ),
1666
- /* @__PURE__ */ s(
1667
- R,
1668
- {
1669
- variant: "body2",
1670
- component: "div",
1671
- sx: {
1672
- flexGrow: 1,
1673
- fontSize: i.body2.fontSize,
1674
- fontWeight: "bold",
1675
- color: "#263235"
1676
- },
1677
- children: "Your data is encrypted"
1678
- }
1679
- )
1680
- ]
1681
- }
1682
- ),
1683
- /* @__PURE__ */ s("button", { className: "realeyes-btn", onClick: t, children: "Try Again" }),
1684
- /* @__PURE__ */ s(ee, { uniqueId: e })
1685
- ]
1686
- }
1687
- )
1688
- }
1689
- ) });
1690
- }, nr = ({
1691
- isOpen: o,
1692
- uniqueId: e,
1693
- onFaceDetected: t,
1694
- onNoFaceDetected: r,
1695
- detectFace: i
1696
- }) => {
1697
- const d = W(), h = Q(d).typography;
1698
- return Z(() => {
1699
- o && i().then((c) => {
1700
- c.faceDetected ? t() : r(c.base64Image);
1701
- });
1702
- }, [o]), o ? /* @__PURE__ */ s(q, { open: o, children: /* @__PURE__ */ s(
1703
- $,
1704
- {
1705
- sx: {
1706
- display: "flex",
1707
- textAlign: "center !important",
1708
- justifyContent: "center !important",
1709
- alignItems: "center !important"
1710
- },
1711
- children: /* @__PURE__ */ S(
1712
- U,
1713
- {
1714
- direction: "column",
1715
- spacing: 2,
1716
- sx: {
1717
- textAlign: "center",
1718
- justifyContent: "center",
1719
- alignItems: "center"
1720
- },
1721
- children: [
1722
- /* @__PURE__ */ s(
1723
- R,
1724
- {
1725
- variant: "h2",
1726
- component: "div",
1727
- sx: {
1728
- flexGrow: 1,
1729
- fontSize: h.h2.fontSize,
1730
- fontWeight: "bold",
1731
- color: "#263235"
1732
- },
1733
- children: "Verification in progress"
1734
- }
1735
- ),
1736
- /* @__PURE__ */ s("div", { className: "face-icon-container", children: /* @__PURE__ */ s(
1737
- "img",
1738
- {
1739
- src: se,
1740
- alt: "Face Verification",
1741
- className: "face-icon"
1742
- }
1743
- ) }),
1744
- /* @__PURE__ */ s(Ee, { size: "4rem", sx: { color: "#10b981" } }),
1745
- /* @__PURE__ */ s(ee, { uniqueId: e })
1746
- ]
1747
- }
1748
- )
1749
- }
1750
- ) }) : null;
1751
- }, sr = ({
1752
- isOpen: o,
1753
- uniqueId: e,
1754
- onRetry: t,
1755
- base64Image: r
1756
- }) => {
1757
- if (!o) return;
1758
- const i = W(), d = Q(i).typography;
1759
- return /* @__PURE__ */ s(q, { open: o, children: /* @__PURE__ */ s(
1760
- $,
1761
- {
1762
- sx: {
1763
- display: "flex",
1764
- textAlign: "center !important",
1765
- justifyContent: "center !important",
1766
- alignItems: "center !important"
1767
- },
1768
- children: /* @__PURE__ */ S(
1769
- U,
1770
- {
1771
- direction: "column",
1772
- spacing: 2,
1773
- sx: {
1774
- textAlign: "center",
1775
- justifyContent: "center",
1776
- alignItems: "center"
1777
- },
1778
- children: [
1779
- /* @__PURE__ */ s(
1780
- R,
1781
- {
1782
- variant: "h2",
1783
- component: "div",
1784
- sx: {
1785
- flexGrow: 1,
1786
- fontSize: d.h2.fontSize,
1787
- fontWeight: "bold",
1788
- color: "#263235"
1789
- },
1790
- children: "We cannot see your face"
1791
- }
1792
- ),
1793
- /* @__PURE__ */ s(
1794
- U,
1795
- {
1796
- direction: "column",
1797
- spacing: 0,
1798
- sx: {
1799
- textAlign: "center",
1800
- justifyContent: "center",
1801
- alignItems: "center"
1802
- },
1803
- children: /* @__PURE__ */ s(
1804
- "img",
1805
- {
1806
- src: r,
1807
- alt: "No face detected",
1808
- style: { maxWidth: "300px" }
1809
- }
1810
- )
1811
- }
1812
- ),
1813
- /* @__PURE__ */ s(
1814
- R,
1815
- {
1816
- variant: "body2",
1817
- component: "div",
1818
- sx: {
1819
- fontSize: d.body2.fontSize,
1820
- textAlign: "left",
1821
- color: "#263235"
1822
- },
1823
- style: { marginTop: 10 },
1824
- children: /* @__PURE__ */ S("ul", { style: { paddingLeft: 0 }, children: [
1825
- /* @__PURE__ */ S("li", { children: [
1826
- /* @__PURE__ */ s("b", { children: "Look" }),
1827
- " into the camera"
1828
- ] }),
1829
- /* @__PURE__ */ S("li", { children: [
1830
- "Check your ",
1831
- /* @__PURE__ */ s("b", { children: "ligthning" })
1832
- ] }),
1833
- /* @__PURE__ */ S("li", { children: [
1834
- "Make sure only this page ",
1835
- /* @__PURE__ */ s("b", { children: "uses your camera" })
1836
- ] })
1837
- ] })
1838
- }
1839
- ),
1840
- /* @__PURE__ */ s("button", { className: "realeyes-btn", onClick: t, children: "Retry" }),
1841
- /* @__PURE__ */ s(ee, { uniqueId: e })
1842
- ]
1843
- }
1844
- )
1845
- }
1846
- ) });
1847
- }, or = ({
1848
- isOpen: o,
1849
- onOk: e
1850
- }) => {
1851
- const [t, r] = D(60), i = W(), d = Q(i).typography;
1852
- return Z(() => {
1853
- if (!o) {
1854
- r(60);
1855
- return;
1856
- }
1857
- const h = setInterval(() => {
1858
- r((c) => c <= 1 ? (clearInterval(h), e(), 0) : c - 1);
1859
- }, 1e3);
1860
- return () => clearInterval(h);
1861
- }, [o, e]), o ? /* @__PURE__ */ s(q, { open: o, children: /* @__PURE__ */ s(
1862
- $,
1863
- {
1864
- sx: {
1865
- display: "flex",
1866
- textAlign: "center !important",
1867
- justifyContent: "center !important",
1868
- alignItems: "center !important"
1869
- },
1870
- children: /* @__PURE__ */ S(
1871
- U,
1872
- {
1873
- direction: "column",
1874
- spacing: 3,
1875
- sx: {
1876
- textAlign: "center",
1877
- justifyContent: "center",
1878
- alignItems: "center"
1879
- },
1880
- children: [
1881
- /* @__PURE__ */ s(
1882
- R,
1883
- {
1884
- variant: "h2",
1885
- component: "div",
1886
- sx: {
1887
- fontSize: d.h2.fontSize,
1888
- fontWeight: "700",
1889
- color: "#263235"
1890
- },
1891
- children: "Session timeout"
1892
- }
1893
- ),
1894
- /* @__PURE__ */ s(
1895
- R,
1896
- {
1897
- variant: "body2",
1898
- component: "div",
1899
- sx: {
1900
- fontSize: d.body2.fontSize,
1901
- color: "#263235"
1902
- },
1903
- children: "Your session has expired. Please try again."
1904
- }
1905
- ),
1906
- /* @__PURE__ */ S(
1907
- R,
1908
- {
1909
- variant: "body2",
1910
- component: "div",
1911
- sx: {
1912
- fontSize: d.body2.fontSize,
1913
- color: "#666666"
1914
- },
1915
- children: [
1916
- "Redirecting in ",
1917
- t,
1918
- " seconds..."
1919
- ]
1920
- }
1921
- ),
1922
- /* @__PURE__ */ s("button", { className: "realeyes-btn", onClick: e, children: "OK" })
1923
- ]
1924
- }
1925
- )
1926
- }
1927
- ) }) : null;
1928
- }, ar = gt(() => import("./livenessCheckDialog-BaqSpUpX.js")), cr = Et({
1929
- palette: {
1930
- mode: "light"
1931
- },
1932
- typography: {
1933
- fontFamily: "Lexend Deca",
1934
- h1: {
1935
- fontSize: "3rem",
1936
- lineHeight: "1.2"
1937
- },
1938
- h2: {
1939
- fontSize: "2rem",
1940
- lineHeight: "1.2"
1941
- },
1942
- body1: {
1943
- fontSize: "1.125rem",
1944
- lineHeight: "1.2"
1945
- },
1946
- body2: {
1947
- fontSize: "0.9rem",
1948
- lineHeight: "1.2"
1949
- }
1950
- },
1951
- components: {
1952
- MuiBackdrop: {
1953
- styleOverrides: {
1954
- root: {
1955
- backgroundColor: "rgba(0,0,0,0)"
1956
- }
1957
- }
1958
- }
1959
- }
1960
- }), lr = 300 * 1e3, _e = {
1961
- SkipIfCameraGranted: "1",
1962
- AlwaysSkip: "2"
1963
- }, dr = ({ strategy: o, config: e, consentSkipMode: t, headless: r = !1, onServiceError: i, headlessCallbacks: d, showVerificationSessionId: h = !1, mediaStream: c }) => {
1964
- const [n, a] = D(!1), [l, u] = D(!1), [p, f] = D(!1), [v, T] = D(!1), [oe, we] = D(!1), [ae, K] = D(!1), [je, ce] = D(!1), [be, Ce] = D(!1), [Re, He] = D(!0), [$e, De] = D(!1), [Ie, le] = D(!1), [de, x] = D(""), [We, xe] = D(!0), [ue, me] = D(null), te = C(2), fe = C(3), Ae = C(0), Te = C(0), [qe, Ke] = D(""), [J, Je] = D("..."), Y = C(!1), G = C(null), he = C(!1), E = C("..."), ke = C(""), Me = C(""), w = C(new Zt(e)).current, g = C(new Qt(w, E)).current, I = C(new Xt(w, e)).current;
1965
- I.statsService = g;
1966
- const Oe = C(i);
1967
- Oe.current = i;
1968
- const V = (m) => {
1969
- console.error(`Error during ${m}`), Oe.current?.(m);
1970
- }, re = C(d);
1971
- re.current = d;
1972
- const ie = C(c);
1973
- ie.current = c;
1974
- const Le = C(!1), pe = C(null);
1975
- Z(() => {
1976
- const m = new AbortController();
1977
- if (pe.current = m, G.current)
1978
- I.setAbortSignal(m.signal);
1979
- else {
1980
- const b = new AbortController();
1981
- I.setAbortSignal(b.signal), w.sendEvent("PageLoaded", null, {}), r || Ye(), G.current = Ne(
1982
- () => Qe(),
1983
- 1e3,
1984
- 4,
1985
- (k) => {
1986
- Ae.current = k;
1987
- }
1988
- ).finally(() => {
1989
- I.setAbortSignal(pe.current?.signal);
1990
- }).catch(() => {
1991
- V("init-session");
1992
- }), r && Ze();
1993
- }
1994
- const y = setTimeout(async () => {
1995
- if (!he.current) {
1996
- g.stopTimer("consentDuration", !1), g.stopTimer("permissionDuration", !1), g.stopTimer("livenessDuration", !1), g.stopTimer("captureImageDuration", !1), g.stopTimer("initDuration", !1);
1997
- const b = window.__pageLoadStart;
1998
- b !== void 0 && g.addStat("sessionDuration", performance.now() - b, !1), await g.forceSendStats(), w.sendEvent("ClientSideFailed", E.current, { reason: "session_timeout" }), Ce(!0), A("SESSION_TIMEOUT", { status: "timeout" });
1999
- }
2000
- }, lr);
2001
- return () => {
2002
- clearTimeout(y), m.abort();
2003
- };
2004
- }, []), Z(() => {
2005
- if (!l) return;
2006
- let m = 0;
2007
- const y = requestAnimationFrame(() => {
2008
- m = requestAnimationFrame(() => {
2009
- g.startTimer("consentDuration");
2010
- });
2011
- });
2012
- return () => {
2013
- cancelAnimationFrame(y), m && cancelAnimationFrame(m);
2014
- };
2015
- }, [l]), Z(() => {
2016
- if (!ae) return;
2017
- let m = 0;
2018
- const y = requestAnimationFrame(() => {
2019
- m = requestAnimationFrame(() => {
2020
- g.startTimer("permissionDuration");
2021
- });
2022
- });
2023
- return () => {
2024
- cancelAnimationFrame(y), m && cancelAnimationFrame(m);
2025
- };
2026
- }, [ae]), Z(() => {
2027
- if (!p) return;
2028
- let m = 0;
2029
- const y = requestAnimationFrame(() => {
2030
- m = requestAnimationFrame(() => {
2031
- g.startTimer("livenessDuration");
2032
- });
2033
- });
2034
- return () => {
2035
- cancelAnimationFrame(y), m && cancelAnimationFrame(m);
2036
- };
2037
- }, [p]);
2038
- const Ye = async () => {
2039
- switch (He(!1), t) {
2040
- case _e.SkipIfCameraGranted: {
2041
- const m = await I.checkCameraAccess();
2042
- m !== "granted" ? (w.sendEvent("ConsentShown", E.current, { consentMode: t, cameraAccess: m }), u(!0)) : (w.sendEvent("ConsentSkipped", E.current, { contentMode: t, cameraAccess: m }), K(!0));
2043
- break;
2044
- }
2045
- case _e.AlwaysSkip:
2046
- w.sendEvent("ConsentSkipped", E.current, { consentMode: t }), K(!0);
2047
- break;
2048
- default:
2049
- w.sendEvent("ConsentShown", E.current, { consentMode: t }), u(!0);
2050
- }
2051
- }, Ze = async () => {
2052
- re.current?.onVerificationStarting?.();
2053
- try {
2054
- await G.current;
2055
- } catch {
2056
- }
2057
- if (Y.current) {
2058
- ie.current && (Le.current ? console.warn("VerifyVerifier: 'mediaStream' is ignored for AWS-liveness sessions.") : I.setExternalStream(ie.current));
2059
- try {
2060
- if (re.current?.onBeforeCameraAccess?.(), !ie.current) {
2061
- const y = await I.checkCameraAccess();
2062
- if (y === "unknown" || y !== "granted") {
2063
- const b = await I.startCamera();
2064
- if (await I.stopCamera(), b === "unknown" || !b.isGranted) {
2065
- w.sendEvent("CameraPermissionDenied", E.current, {}), await A("CAMERA_ACCESS_ERROR", { status: "camera_error" });
2066
- return;
2067
- }
2068
- }
2069
- }
2070
- re.current?.onAfterCameraAccess?.(), w.sendEvent("CameraPermissionGranted", E.current, {}), g.startTimer("captureImageDuration");
2071
- const m = await Ue();
2072
- g.stopTimer("captureImageDuration"), m.faceDetected ? await A() : (w.sendEvent("ClientSideFailed", E.current, { reason: "no_face" }), await A());
2073
- } catch {
2074
- V("unknown");
2075
- }
2076
- }
2077
- }, Ne = async (m, y = 1e3, b = 4, k) => {
2078
- const ne = Date.now();
2079
- let P = y, O = 1;
2080
- for (; ; )
2081
- try {
2082
- return await m();
2083
- } catch {
2084
- const mt = Date.now() - ne;
2085
- if (O > b)
2086
- throw new Error(`Retry limit exceeded after ${mt / 1e3} seconds`);
2087
- console.warn(`Retrying (attempt: ${O}) in ${P / 1e3} seconds...`), me(`Retrying (attempt: ${O}) in ${P / 1e3} seconds...`), await new Promise(async (ft) => {
2088
- for (let ge = 0; ge < P / 1e3; ge++)
2089
- me(
2090
- `Retrying (attempt: ${O}) in ${P / 1e3} / ${P / 1e3 - ge} seconds...`
2091
- ), await new Promise((ht) => setTimeout(ht, 1e3));
2092
- setTimeout(ft, 0);
2093
- }), P *= 2, k?.(O), O++;
2094
- }
2095
- }, Qe = async () => {
2096
- x(""), g.startTimer("initDuration");
2097
- const m = window.__pageLoadStart;
2098
- m && g.addStat("pageLoadDuration", performance.now() - m);
2099
- try {
2100
- const y = await o.initSession(I);
2101
- if (E.current = y.verificationSessionId, Je(y.verificationSessionId), I.livenessCheckType = y.livenessCheckType?.toLowerCase(), y.livenessCheckConfig) {
2102
- a(!0), Le.current = !0, Me.current = y.livenessCheckConfig.aws_project_region, ke.current = y.livenessCheckSessionId;
2103
- const { Amplify: b } = await import("aws-amplify");
2104
- b.configure(y.livenessCheckConfig);
2105
- } else
2106
- I.preloadMediaPipe();
2107
- Y.current = !0, g.stopTimer("initDuration");
2108
- } catch (y) {
2109
- if (y instanceof H)
2110
- throw y;
2111
- y instanceof DOMException && y.name === "AbortError" || (y instanceof ye ? (x(y.message), xe(!1), V("init-session")) : y instanceof Error ? (x(y.message), V("init-session")) : (x("An error occurred during initializing the session!"), V("init-session")));
2112
- }
2113
- }, Ue = async () => {
2114
- x("");
2115
- try {
2116
- return await I.detectFace(E.current);
2117
- } catch (m) {
2118
- if (m instanceof H)
2119
- throw m;
2120
- m instanceof ye ? (x(m.message), xe(!1)) : m instanceof Error ? x(m.message) : x("An error occurred during face detection!"), V("capture-image");
2121
- }
2122
- return new _(!1);
2123
- }, A = async (m, y = { status: "completed" }) => {
2124
- if (!he.current) {
2125
- g.startTimer("getResultDuration"), he.current = !0, le(!0);
2126
- try {
2127
- await Ne(
2128
- async () => {
2129
- try {
2130
- const b = await o.fetchResult(
2131
- E.current,
2132
- I,
2133
- m,
2134
- pe.current?.signal
2135
- );
2136
- g.stopTimer("getResultDuration", !1);
2137
- const k = g.getAllStatsAsObject(), ne = (k.consentDuration ?? 0) + (k.permissionDuration ?? 0) + (k.livenessDuration ?? 0), P = (k.initDuration ?? 0) + (k.pageLoadDuration ?? 0) + (k.getResultDuration ?? 0) + (k.captureImageDuration ?? 0);
2138
- g.addStat("totalUserInteractionDuration", ne, !1), g.addStat("totalDuration", ne + P, !1);
2139
- const O = window.__pageLoadStart;
2140
- O !== void 0 && g.addStatIfMissing("sessionDuration", performance.now() - O, !1), g.addStat("throttlingInitRetryCount", Ae.current, !1), g.addStat("throttlingGetResultRetryCount", Te.current, !1), g.addStat("cameraPermissionRetryCount", 3 - fe.current, !1), g.addStat("noFaceRetryCount", 2 - te.current, !1), await g.forceSendStats() || console.error("[StatsService] forceSendStats failed - StatsCollected event not sent to Kinesis"), await w.sendEvent(
2141
- "VerificationCompleted",
2142
- E.current,
2143
- b.logPayload ?? {}
2144
- ), g.reset(), o.complete(b, y);
2145
- } catch (b) {
2146
- if (b instanceof H) throw b;
2147
- console.error("completeVerification failed:", b), x("An error occurred during the verification!"), le(!1), V("verify");
2148
- }
2149
- },
2150
- 1e3,
2151
- 4,
2152
- (b) => {
2153
- Te.current = b;
2154
- }
2155
- );
2156
- } catch (b) {
2157
- console.error("completeVerification throttling retry exhausted:", b), m !== "THROTTLING_LIMIT" && o.onThrottlingLimitExhausted?.(E.current, I), x("Service is currently busy. Please try again later."), le(!1), V("verify");
2158
- } finally {
2159
- me(null);
2160
- }
2161
- }
2162
- }, Xe = async () => {
2163
- Y.current || (De(!0), await G.current, De(!1)), g.stopTimer("consentDuration"), w.sendEvent("ConsentClosed", E.current, { result: "accepted" }), u(!1), K(!0);
2164
- }, et = async () => {
2165
- Y.current || await G.current, g.stopTimer("consentDuration"), w.sendEvent("ConsentClosed", E.current, { result: "declined" }), w.sendEvent("ClientSideFailed", E.current, { reason: "no_consent" }), u(!1), await A("CONSENT_DECLINED", { status: "consent_declined" });
2166
- }, tt = async () => {
2167
- Y.current || await G.current, g.stopTimer("permissionDuration"), w.sendEvent("CameraPermissionGranted", E.current, {}), K(!1), n ? (w.sendEvent("LivenessCheckStarted", E.current, {}), f(!0)) : (g.startTimer("captureImageDuration"), T(!0));
2168
- }, rt = async () => {
2169
- Y.current || await G.current, g.stopTimer("permissionDuration"), w.sendEvent("CameraPermissionDenied", E.current, {}), K(!1), ce(!0);
2170
- }, it = async () => {
2171
- if (fe.current <= 0) {
2172
- ce(!1), await A("CAMERA_ACCESS_ERROR", { status: "camera_error" });
2173
- return;
2174
- }
2175
- fe.current -= 1, ce(!1), K(!0);
2176
- }, nt = async () => {
2177
- g.stopTimer("captureImageDuration"), T(!1), await A();
2178
- }, st = async (m) => {
2179
- g.stopTimer("captureImageDuration"), T(!1), Ke(m), te.current <= 0 ? (w.sendEvent("ClientSideFailed", E.current, { reason: "no_face" }), await A()) : (te.current -= 1, we(!0));
2180
- }, ot = async () => {
2181
- we(!1), te.current >= 0 ? (g.startTimer("captureImageDuration"), T(!0)) : await A();
2182
- }, at = async () => {
2183
- console.log("Liveness check completed"), g.stopTimer("livenessDuration"), w.sendEvent("LivenessCheckPassed", E.current, {}), f(!1), await A();
2184
- }, ct = async (m) => {
2185
- if (console.error("Liveness check failed:", m), m.state === "CAMERA_ACCESS_ERROR") {
2186
- x("Please allow the camera for the liveness test!");
2187
- return;
2188
- }
2189
- if (m.state === "MOBILE_LANDSCAPE_ERROR") {
2190
- x("Please use the mobile in portrait mode!");
2191
- return;
2192
- }
2193
- g.stopTimer("livenessDuration"), w.sendEvent("LivenessCheckFailed", E.current, { reason: m.state }), f(!1), await A(m.state, { status: "liveness_error" });
2194
- }, lt = async () => {
2195
- g.stopTimer("livenessDuration"), w.sendEvent("ClientSideFailed", E.current, { reason: "liveness_cancelled" }), f(!1), await A("LIVENESS_CANCELED", { status: "liveness_canceled" });
2196
- }, dt = async () => {
2197
- Ce(!1), o.onSessionTimeout?.(E.current);
2198
- };
2199
- if (r)
2200
- return null;
2201
- let B;
2202
- return ue ? B = /* @__PURE__ */ S(Ve, { open: !!ue, maxWidth: "xs", fullWidth: !0, children: [
2203
- /* @__PURE__ */ s(Pe, { children: "Server is busy" }),
2204
- /* @__PURE__ */ s(ze, { children: /* @__PURE__ */ s(Fe, { children: ue }) })
2205
- ] }) : de ? B = /* @__PURE__ */ S(Ve, { open: !!de, maxWidth: "xs", fullWidth: !0, children: [
2206
- /* @__PURE__ */ s(Pe, { children: "Error" }),
2207
- /* @__PURE__ */ s(ze, { children: /* @__PURE__ */ s(Fe, { children: de }) }),
2208
- We && /* @__PURE__ */ s(Rt, { children: /* @__PURE__ */ s(Dt, { onClick: () => window.location.reload(), variant: "contained", color: "primary", children: "Retry" }) })
2209
- ] }) : be ? B = /* @__PURE__ */ s(or, { isOpen: be, onOk: dt }) : Re ? B = /* @__PURE__ */ s(ve, { isOpen: Re }) : Ie ? B = /* @__PURE__ */ s(ve, { isOpen: Ie, text: "Verifying..." }) : B = /* @__PURE__ */ S(Se, { children: [
2210
- /* @__PURE__ */ s(
2211
- Vt,
2212
- {
2213
- isOpen: l,
2214
- onAccept: Xe,
2215
- onClose: et,
2216
- uniqueId: J,
2217
- isConsentButtonLoading: $e,
2218
- showVerificationSessionId: h
2219
- }
2220
- ),
2221
- /* @__PURE__ */ s(
2222
- rr,
2223
- {
2224
- isOpen: ae,
2225
- uniqueId: J,
2226
- onPermissionGranted: tt,
2227
- onPermissionDenied: rt,
2228
- verificationService: I
2229
- }
2230
- ),
2231
- /* @__PURE__ */ s(
2232
- ir,
2233
- {
2234
- isOpen: je,
2235
- uniqueId: J,
2236
- onTryAgain: it
2237
- }
2238
- ),
2239
- /* @__PURE__ */ s(
2240
- nr,
2241
- {
2242
- isOpen: v,
2243
- uniqueId: J,
2244
- detectFace: Ue,
2245
- onFaceDetected: nt,
2246
- onNoFaceDetected: st
2247
- }
2248
- ),
2249
- /* @__PURE__ */ s(
2250
- sr,
2251
- {
2252
- isOpen: oe,
2253
- uniqueId: J,
2254
- onRetry: ot,
2255
- base64Image: qe
2256
- }
2257
- ),
2258
- n && p && /* @__PURE__ */ s(vt, { fallback: /* @__PURE__ */ s(ve, { isOpen: !0 }), children: /* @__PURE__ */ s(
2259
- ar,
2260
- {
2261
- isOpen: p,
2262
- uniqueId: J,
2263
- livenessSessionId: ke.current,
2264
- livenessRegion: Me.current,
2265
- onLivenessComplete: at,
2266
- onLivenessError: ct,
2267
- onClose: lt
2268
- }
2269
- ) })
2270
- ] }), /* @__PURE__ */ S(wt, { theme: cr, children: [
2271
- /* @__PURE__ */ s(bt, {}),
2272
- /* @__PURE__ */ s(Ct, { children: B })
2273
- ] });
2274
- }, Ir = ({ sessionId: o, accessToken: e, onVerificationCompleted: t, consentSkipMode: r, headless: i = !1, onServiceError: d, headlessCallbacks: h, showVerificationSessionId: c, region: n, createConfig: a, mediaStream: l }) => {
2275
- if (!Lt(n))
2276
- throw new Error(
2277
- `VerifyVerifier: invalid "region" prop ${JSON.stringify(n)}. Expected one of: ${Ge.map((f) => `"${f}"`).join(", ")}.`
2278
- );
2279
- if (l && !i)
2280
- throw new Error(
2281
- 'VerifyVerifier: "mediaStream" prop is only valid when "headless" is true.'
2282
- );
2283
- const u = C(a ? a(n) : new Nt(n)), p = C(new Ot(o, e, t, i));
2284
- return /* @__PURE__ */ s(dr, { strategy: p.current, config: u.current, consentSkipMode: r, headless: i, onServiceError: d, headlessCallbacks: h, showVerificationSessionId: c, mediaStream: l });
2285
- };
2286
- export {
2287
- Ut as C,
2288
- ee as D,
2289
- q as R,
2290
- Ir as V,
2291
- _e as a,
2292
- Ge as b
2293
- };