idmission-web-sdk 2.3.127 → 2.3.129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk2.esm.js CHANGED
@@ -5,7 +5,7 @@ import platform from 'platform';
5
5
  import styled, { keyframes, useTheme, ThemeProvider as ThemeProvider$1 } from 'styled-components';
6
6
  import { createPortal } from 'react-dom';
7
7
  import { useTranslation, initReactI18next } from 'react-i18next';
8
- import { Upload } from 'tus-js-client';
8
+ import { Upload, DetailedError } from 'tus-js-client';
9
9
  import SparkMD5 from 'spark-md5';
10
10
  import { ImageSegmenter, FilesetResolver, ObjectDetector, ImageClassifier, FaceDetector } from '@mediapipe/tasks-vision';
11
11
  import { useStore, createStore, create } from 'zustand';
@@ -204,7 +204,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
204
204
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
205
205
  };
206
206
 
207
- var webSdkVersion = '2.3.127';
207
+ var webSdkVersion = '2.3.129';
208
208
 
209
209
  function getPlatform() {
210
210
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -354,11 +354,13 @@ function attachMetadataToRequest(request, _a) {
354
354
  var selfieCaptureAttempts = _a.selfieCaptureAttempts,
355
355
  idFrontCaptureAttempts = _a.idFrontCaptureAttempts,
356
356
  idBackCaptureAttempts = _a.idBackCaptureAttempts,
357
+ barcodeCaptureAttempts = _a.barcodeCaptureAttempts,
357
358
  geolocationResult = _a.geolocationResult;
358
359
  var metadata = {
359
360
  selfie: selfieCaptureAttempts,
360
361
  front: idFrontCaptureAttempts,
361
362
  back: idBackCaptureAttempts,
363
+ barcode: barcodeCaptureAttempts,
362
364
  isRealIDCheckRequired: 'false',
363
365
  sdkVersion: "WebSDK_".concat(webSdkVersion),
364
366
  Resolution: typeof window !== 'undefined' ? "".concat(window.innerWidth, " x ").concat(window.innerHeight) : 'unknown'
@@ -1083,6 +1085,26 @@ function setServerUrl(url) {
1083
1085
  setDefaultSubmissionUrl(url + '/swagger');
1084
1086
  setDefaultDocumentServiceUrl(url + '/files/');
1085
1087
  }
1088
+ var capturedDocumentTypeToSubmissionKey = {
1089
+ idCardFront: 'idFrontImage',
1090
+ idCardBack: 'idBackImage',
1091
+ passport: 'passportImage',
1092
+ singlePage: 'idFrontImage',
1093
+ selfie: 'selfieImage',
1094
+ idFrontIrImage: 'idFrontIrImage',
1095
+ idBackIrImage: 'idBackIrImage',
1096
+ idFrontUvImage: 'idFrontUvImage',
1097
+ idBackUvImage: 'idBackUvImage',
1098
+ idBarcodeImage: 'idBarcodeImage'
1099
+ };
1100
+ var sanitizeMetadata = function sanitizeMetadata(metadata) {
1101
+ var entries = Object.entries(metadata).filter(function (_a) {
1102
+ var value = _a[1];
1103
+ return value !== undefined && value !== null;
1104
+ });
1105
+ if (!entries.length) return null;
1106
+ return Object.fromEntries(entries);
1107
+ };
1086
1108
  var SubmissionContext = /*#__PURE__*/createContext({
1087
1109
  submit: function submit() {
1088
1110
  return __awaiter(void 0, void 0, void 0, function () {
@@ -1170,6 +1192,9 @@ var SubmissionContext = /*#__PURE__*/createContext({
1170
1192
  setAdditionalDocuments: function setAdditionalDocuments() {
1171
1193
  return null;
1172
1194
  },
1195
+ setDocumentFileMetadata: function setDocumentFileMetadata() {
1196
+ return null;
1197
+ },
1173
1198
  uploadDocument: Promise.resolve,
1174
1199
  logIdFrontCaptureAttempt: function logIdFrontCaptureAttempt() {
1175
1200
  return null;
@@ -1321,60 +1346,139 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1321
1346
  var _18 = useState(null),
1322
1347
  signatureVideoMetadata = _18[0],
1323
1348
  setSignatureVideoMetadata = _18[1];
1324
- var _19 = useState(null),
1325
- idCaptureVideoUrl = _19[0],
1326
- setIdCaptureVideoUrl = _19[1];
1327
- var _20 = useState(null),
1328
- idCaptureVideoIdFrontImage = _20[0],
1329
- setIdCaptureVideoIdFrontImage = _20[1];
1349
+ var _19 = useState({}),
1350
+ documentFileMetadata = _19[0],
1351
+ setDocumentFileMetadataState = _19[1];
1352
+ var _20 = useState([]),
1353
+ barcodeCaptureAttempts = _20[0],
1354
+ setBarcodeCaptureAttempts = _20[1];
1330
1355
  var _21 = useState(null),
1331
- idCaptureVideoIdBackImage = _21[0],
1332
- setIdCaptureVideoIdBackImage = _21[1];
1356
+ idCaptureVideoUrl = _21[0],
1357
+ setIdCaptureVideoUrl = _21[1];
1333
1358
  var _22 = useState(null),
1334
- idCaptureVideoAudioUrl = _22[0],
1335
- setIdCaptureVideoAudioUrl = _22[1];
1359
+ idCaptureVideoIdFrontImage = _22[0],
1360
+ setIdCaptureVideoIdFrontImage = _22[1];
1336
1361
  var _23 = useState(null),
1337
- idCaptureVideoAudioStartsAt = _23[0],
1338
- setIdCaptureVideoAudioStartsAt = _23[1];
1362
+ idCaptureVideoIdBackImage = _23[0],
1363
+ setIdCaptureVideoIdBackImage = _23[1];
1339
1364
  var _24 = useState(null),
1340
- expectedAudioText = _24[0],
1341
- setExpectedAudioText = _24[1];
1365
+ idCaptureVideoAudioUrl = _24[0],
1366
+ setIdCaptureVideoAudioUrl = _24[1];
1342
1367
  var _25 = useState(null),
1343
- additionalDocuments = _25[0],
1344
- setAdditionalDocuments = _25[1];
1368
+ idCaptureVideoAudioStartsAt = _25[0],
1369
+ setIdCaptureVideoAudioStartsAt = _25[1];
1345
1370
  var _26 = useState(null),
1346
- geolocationResult = _26[0],
1347
- setGeolocationResult = _26[1];
1348
- var _27 = useState(0),
1349
- geolocationAttempts = _27[0],
1350
- setGeolocationAttempts = _27[1];
1351
- var _28 = useState(false),
1352
- geolocationBlocked = _28[0],
1353
- setGeolocationBlocked = _28[1];
1354
- var _29 = useState([]),
1355
- idFrontCaptureAttempts = _29[0],
1356
- setIdFrontCaptureAttempts = _29[1];
1357
- var _30 = useState([]),
1358
- idBackCaptureAttempts = _30[0],
1359
- setIdBackCaptureAttempts = _30[1];
1371
+ expectedAudioText = _26[0],
1372
+ setExpectedAudioText = _26[1];
1373
+ var _27 = useState(null),
1374
+ additionalDocuments = _27[0],
1375
+ setAdditionalDocuments = _27[1];
1376
+ var setDocumentFileMetadata = useCallback(function (key, metadata) {
1377
+ var sanitized = metadata ? sanitizeMetadata(metadata) : null;
1378
+ setDocumentFileMetadataState(function (current) {
1379
+ var _a;
1380
+ if (!sanitized) {
1381
+ if (!(key in current)) return current;
1382
+ var next = _assign({}, current);
1383
+ delete next[key];
1384
+ if (key === 'idBarcodeImage') {
1385
+ setBarcodeCaptureAttempts([]);
1386
+ }
1387
+ return next;
1388
+ }
1389
+ return _assign(_assign({}, current), (_a = {}, _a[key] = sanitized, _a));
1390
+ });
1391
+ }, []);
1392
+ var _28 = useState(null),
1393
+ geolocationResult = _28[0],
1394
+ setGeolocationResult = _28[1];
1395
+ var _29 = useState(0),
1396
+ geolocationAttempts = _29[0],
1397
+ setGeolocationAttempts = _29[1];
1398
+ var _30 = useState(false),
1399
+ geolocationBlocked = _30[0],
1400
+ setGeolocationBlocked = _30[1];
1360
1401
  var _31 = useState([]),
1361
- selfieCaptureAttempts = _31[0],
1362
- setSelfieCaptureAttempts = _31[1];
1363
- var logIdFrontCaptureAttempt = useCallback(function (attempt) {
1402
+ idFrontCaptureAttempts = _31[0],
1403
+ setIdFrontCaptureAttempts = _31[1];
1404
+ var _32 = useState([]),
1405
+ idBackCaptureAttempts = _32[0],
1406
+ setIdBackCaptureAttempts = _32[1];
1407
+ var _33 = useState([]),
1408
+ selfieCaptureAttempts = _33[0],
1409
+ setSelfieCaptureAttempts = _33[1];
1410
+ var logIdFrontCaptureAttempt = useCallback(function (attempt, documentType) {
1364
1411
  setIdFrontCaptureAttempts(function (attempts) {
1365
1412
  return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
1366
1413
  });
1367
- }, []);
1368
- var logIdBackCaptureAttempt = useCallback(function (attempt) {
1414
+ var submissionKey = capturedDocumentTypeToSubmissionKey[documentType];
1415
+ if (submissionKey) {
1416
+ setDocumentFileMetadata(submissionKey, {
1417
+ documentType: documentType,
1418
+ documentKey: submissionKey,
1419
+ captureMode: attempt.captureMode,
1420
+ autoCapture: attempt.autoCapture,
1421
+ captureTime: attempt.captureTime,
1422
+ operationTime: attempt.operationTime,
1423
+ bestDetectionScore: attempt.bestDetectionScore,
1424
+ bestFocusScore: attempt.bestFocusScore,
1425
+ bestBarcodeScore: attempt.bestBarcodeScore,
1426
+ boundingBox: attempt.boundingBox
1427
+ });
1428
+ }
1429
+ if (attempt.bestBarcodeScore !== undefined && attempt.bestBarcodeScore !== null) {
1430
+ setBarcodeCaptureAttempts(function (attempts) {
1431
+ return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
1432
+ });
1433
+ setDocumentFileMetadata('idBarcodeImage', {
1434
+ documentType: 'idBarcodeImage',
1435
+ sourceDocumentType: documentType,
1436
+ documentKey: 'idBarcodeImage',
1437
+ bestBarcodeScore: attempt.bestBarcodeScore,
1438
+ captureMode: attempt.captureMode,
1439
+ autoCapture: attempt.autoCapture,
1440
+ captureTime: attempt.captureTime,
1441
+ operationTime: attempt.operationTime
1442
+ });
1443
+ }
1444
+ }, [setDocumentFileMetadata]);
1445
+ var logIdBackCaptureAttempt = useCallback(function (attempt, documentType) {
1369
1446
  setIdBackCaptureAttempts(function (attempts) {
1370
1447
  return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
1371
1448
  });
1372
- }, []);
1449
+ var submissionKey = capturedDocumentTypeToSubmissionKey[documentType];
1450
+ if (submissionKey) {
1451
+ setDocumentFileMetadata(submissionKey, {
1452
+ documentType: documentType,
1453
+ documentKey: submissionKey,
1454
+ captureMode: attempt.captureMode,
1455
+ autoCapture: attempt.autoCapture,
1456
+ captureTime: attempt.captureTime,
1457
+ operationTime: attempt.operationTime,
1458
+ bestDetectionScore: attempt.bestDetectionScore,
1459
+ bestFocusScore: attempt.bestFocusScore,
1460
+ bestBarcodeScore: attempt.bestBarcodeScore,
1461
+ boundingBox: attempt.boundingBox
1462
+ });
1463
+ }
1464
+ }, [setDocumentFileMetadata]);
1373
1465
  var logSelfieCaptureAttempt = useCallback(function (attempt) {
1374
1466
  setSelfieCaptureAttempts(function (attempts) {
1375
1467
  return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
1376
1468
  });
1377
- }, []);
1469
+ setDocumentFileMetadata('selfieImage', {
1470
+ documentType: 'selfie',
1471
+ documentKey: 'selfieImage',
1472
+ captureMode: attempt.captureMode,
1473
+ autoCapture: attempt.autoCapture,
1474
+ captureTime: attempt.captureTime,
1475
+ operationTime: attempt.operationTime,
1476
+ livenessScore: attempt.livenessScore,
1477
+ bestDetectionScore: attempt.bestDetectionScore,
1478
+ bestFocusScore: attempt.bestFocusScore,
1479
+ boundingBox: attempt.boundingBox
1480
+ });
1481
+ }, [setDocumentFileMetadata]);
1378
1482
  useRevokeObjectUrlOnUnmount(signatureVideoUrl);
1379
1483
  useRevokeObjectUrlOnUnmount(idCaptureVideoUrl);
1380
1484
  useRevokeObjectUrlOnUnmount(idCaptureVideoAudioUrl);
@@ -1524,14 +1628,15 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1524
1628
  if (!documentServiceUrl) return [3 /*break*/, 8];
1525
1629
  return [4 /*yield*/, Promise.all(Object.keys(documents).map(function (k) {
1526
1630
  return __awaiter(void 0, void 0, void 0, function () {
1527
- var filetype, metadata, _a, _b;
1631
+ var filetype, metadataSource, metadata, _a, _b;
1528
1632
  return __generator(this, function (_c) {
1529
1633
  switch (_c.label) {
1530
1634
  case 0:
1531
1635
  if (!documents[k]) return [3 /*break*/, 2];
1532
1636
  filetype = k.endsWith('Video') ? 'video/mp4' : k.endsWith('Audio') ? 'audio/mp4' : 'image/jpeg';
1533
- metadata = k === 'signatureVideo' ? {
1534
- filemetadata: JSON.stringify(signatureVideoMetadata)
1637
+ metadataSource = k === 'signatureVideo' && signatureVideoMetadata ? signatureVideoMetadata : documentFileMetadata[k];
1638
+ metadata = metadataSource ? {
1639
+ filemetadata: JSON.stringify(metadataSource)
1535
1640
  } : {};
1536
1641
  _a = documents;
1537
1642
  _b = k;
@@ -1682,7 +1787,8 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1682
1787
  selfieCaptureAttempts: selfieCaptureAttempts,
1683
1788
  idFrontCaptureAttempts: idFrontCaptureAttempts,
1684
1789
  idBackCaptureAttempts: idBackCaptureAttempts,
1685
- geolocationResult: geolocationResult
1790
+ geolocationResult: geolocationResult,
1791
+ barcodeCaptureAttempts: barcodeCaptureAttempts
1686
1792
  });
1687
1793
  if (!onBeforeSubmit.current) return [3 /*break*/, 10];
1688
1794
  return [4 /*yield*/, onBeforeSubmit.current(submissionRequest)];
@@ -1695,7 +1801,7 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1695
1801
  }
1696
1802
  });
1697
1803
  });
1698
- }, [additionalDocuments, bypassAgeValidation, bypassNameMatching, cardData, clientRequestID, companyId, customerDataMatchConfig, deduplicationEnabled, deduplicationSynchronous, documentServiceUrl, enrollmentId, expectedAudioText, geolocationResult, idBackCaptureAttempts, idBackImage, idBackImageRequired, idBackIrImage, idBackUvImage, idBarcodeImage, idCaptureVideoAudioStartsAt, idCaptureVideoAudioUrl, idCaptureVideoIdBackImage, idCaptureVideoIdFrontImage, idCaptureVideoUrl, idCardForFaceMatch, idData, idFrontCaptureAttempts, idFrontImage, idFrontIrImage, idFrontUvImage, idImageResolutionCheck, jobId, manualReviewRequired, needImmediateResponse, passportImage, personalData, selfieCaptureAttempts, selfieImage, signatureData, signatureVideoUrl, signatureVideoMetadata, uploadDocument, verifyIdWithExternalDatabases, webhooksClientTraceId, webhooksEnabled, webhooksFireOnReview, webhooksFireOnReviewURL, webhooksSendInputImages, webhooksSendProcessedImages, webhooksStripSpecialCharacters, webhooksURL]);
1804
+ }, [additionalDocuments, bypassAgeValidation, bypassNameMatching, cardData, clientRequestID, companyId, customerDataMatchConfig, deduplicationEnabled, deduplicationSynchronous, barcodeCaptureAttempts, documentFileMetadata, documentServiceUrl, enrollmentId, expectedAudioText, geolocationResult, idBackCaptureAttempts, idBackImage, idBackImageRequired, idBackIrImage, idBackUvImage, idBarcodeImage, idCaptureVideoAudioStartsAt, idCaptureVideoAudioUrl, idCaptureVideoIdBackImage, idCaptureVideoIdFrontImage, idCaptureVideoUrl, idCardForFaceMatch, idData, idFrontCaptureAttempts, idFrontImage, idFrontIrImage, idFrontUvImage, idImageResolutionCheck, jobId, manualReviewRequired, needImmediateResponse, passportImage, personalData, selfieCaptureAttempts, selfieImage, signatureData, signatureVideoUrl, signatureVideoMetadata, uploadDocument, verifyIdWithExternalDatabases, webhooksClientTraceId, webhooksEnabled, webhooksFireOnReview, webhooksFireOnReviewURL, webhooksSendInputImages, webhooksSendProcessedImages, webhooksStripSpecialCharacters, webhooksURL]);
1699
1805
  var defaultOnSubmit = useCallback(function () {
1700
1806
  return __awaiter(void 0, void 0, void 0, function () {
1701
1807
  var submissionResponse_1, payload, host, endpoint, response, statusMessage, submissionResponse_2, e_1, err;
@@ -1855,7 +1961,8 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1855
1961
  selfieCaptureAttempts: selfieCaptureAttempts,
1856
1962
  idFrontCaptureAttempts: idFrontCaptureAttempts,
1857
1963
  idBackCaptureAttempts: idBackCaptureAttempts,
1858
- geolocationResult: geolocationResult
1964
+ geolocationResult: geolocationResult,
1965
+ barcodeCaptureAttempts: barcodeCaptureAttempts
1859
1966
  });
1860
1967
  if (!onBeforeLivenessCheck.current) return [3 /*break*/, 5];
1861
1968
  return [4 /*yield*/, onBeforeLivenessCheck.current(request)];
@@ -1869,7 +1976,7 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1869
1976
  }
1870
1977
  });
1871
1978
  });
1872
- }, [clientRequestID, documentServiceUrl, estimateAge, geolocationResult, idBackCaptureAttempts, idCardForFaceMatch, idFrontCaptureAttempts, jobId, predictGender, selfieCaptureAttempts, uploadDocument, useDocumentServiceForLivenessChecks, webhooksStripSpecialCharacters]);
1979
+ }, [clientRequestID, documentServiceUrl, estimateAge, geolocationResult, barcodeCaptureAttempts, idBackCaptureAttempts, idCardForFaceMatch, idFrontCaptureAttempts, jobId, predictGender, selfieCaptureAttempts, uploadDocument, useDocumentServiceForLivenessChecks, webhooksStripSpecialCharacters]);
1873
1980
  var checkLiveness = useCallback(function (imageDataUrl) {
1874
1981
  return __awaiter(void 0, void 0, void 0, function () {
1875
1982
  var request, host, endpoint, response, statusMessage, submissionResponse_3, e_2, err;
@@ -2002,6 +2109,7 @@ var SubmissionProvider = function SubmissionProvider(_a) {
2002
2109
  setIdCaptureVideoAudioStartsAt: setIdCaptureVideoAudioStartsAt,
2003
2110
  setExpectedAudioText: setExpectedAudioText,
2004
2111
  setAdditionalDocuments: setAdditionalDocuments,
2112
+ setDocumentFileMetadata: setDocumentFileMetadata,
2005
2113
  uploadDocument: uploadDocument,
2006
2114
  logIdFrontCaptureAttempt: logIdFrontCaptureAttempt,
2007
2115
  logIdBackCaptureAttempt: logIdBackCaptureAttempt,
@@ -2010,7 +2118,7 @@ var SubmissionProvider = function SubmissionProvider(_a) {
2010
2118
  checkLiveness: checkLiveness,
2011
2119
  retryLocationAccess: retryLocationAccess
2012
2120
  };
2013
- }, [additionalDocuments, checkLiveness, environment, idBackImage, idBackIrImage, idBackUvImage, idBarcodeImage, idCaptureVideoAudioStartsAt, idCaptureVideoAudioUrl, idCaptureVideoIdBackImage, idCaptureVideoIdFrontImage, idCaptureVideoUrl, idFrontImage, idFrontIrImage, idFrontUvImage, livenessCheckRequest, logIdBackCaptureAttempt, logIdFrontCaptureAttempt, logSelfieCaptureAttempt, passportImage, retryLocationAccess, selfieImage, signatureData, signatureVideoUrl, submissionError, submissionRequest, submissionResponse, submissionStatus, submit, uploadDocument]);
2121
+ }, [additionalDocuments, checkLiveness, environment, idBackImage, idBackIrImage, idBackUvImage, idBarcodeImage, idCaptureVideoAudioStartsAt, idCaptureVideoAudioUrl, idCaptureVideoIdBackImage, idCaptureVideoIdFrontImage, idCaptureVideoUrl, idFrontImage, idFrontIrImage, idFrontUvImage, livenessCheckRequest, logIdBackCaptureAttempt, logIdFrontCaptureAttempt, logSelfieCaptureAttempt, passportImage, retryLocationAccess, selfieImage, signatureData, signatureVideoUrl, setDocumentFileMetadata, submissionError, submissionRequest, submissionResponse, submissionStatus, submit, uploadDocument]);
2014
2122
  return /*#__PURE__*/React__default.createElement(SubmissionContext.Provider, {
2015
2123
  value: value
2016
2124
  }, geolocationRequired && geolocationBlocked ? ( /*#__PURE__*/React__default.createElement(GeolocationAccessDeniedOverlay, null)) : children, submissionError && ( /*#__PURE__*/React__default.createElement(SubmissionErrorOverlay, {
@@ -2074,9 +2182,50 @@ function getEnvFromUrl(url) {
2074
2182
  }
2075
2183
  return 'unknown';
2076
2184
  }
2185
+ var CREATE_UPLOAD_RETRY_DELAYS = [1500, 3000, 6000, 12000];
2186
+ var RETRYABLE_STATUS_CODES = new Set([408, 409, 423]);
2187
+ function shouldRetryTusError(error, retryableMethods) {
2188
+ var _a, _b, _c, _d;
2189
+ if (typeof ProgressEvent !== 'undefined' && error instanceof ProgressEvent) {
2190
+ return true;
2191
+ }
2192
+ if (error instanceof DetailedError) {
2193
+ var method = void 0;
2194
+ try {
2195
+ method = (_b = (_a = error.originalRequest) === null || _a === void 0 ? void 0 : _a.getMethod) === null || _b === void 0 ? void 0 : _b.call(_a);
2196
+ } catch (requestMethodError) {
2197
+ warn('Unable to read request method from tus error', requestMethodError);
2198
+ return false;
2199
+ }
2200
+ if (method && retryableMethods.length && !retryableMethods.includes(method)) {
2201
+ return false;
2202
+ }
2203
+ var status_1 = (_d = (_c = error.originalResponse) === null || _c === void 0 ? void 0 : _c.getStatus) === null || _d === void 0 ? void 0 : _d.call(_c);
2204
+ if (typeof status_1 === 'number') {
2205
+ if (status_1 >= 500 || RETRYABLE_STATUS_CODES.has(status_1)) {
2206
+ return true;
2207
+ }
2208
+ return false;
2209
+ }
2210
+ return true;
2211
+ }
2212
+ return false;
2213
+ }
2214
+ function shouldRetryCreateRequest(error) {
2215
+ return shouldRetryTusError(error, ['POST']);
2216
+ }
2217
+ function shouldRetryChunkRequest(error) {
2218
+ return shouldRetryTusError(error, ['PATCH', 'POST']);
2219
+ }
2220
+ function normalizeUploadError(error) {
2221
+ if (error instanceof Error) {
2222
+ return error;
2223
+ }
2224
+ return new Error('tus upload failed');
2225
+ }
2077
2226
  function performUpload(_a) {
2078
2227
  return __awaiter(this, arguments, void 0, function (_b) {
2079
- var fingerprint;
2228
+ var fingerprint, headers, maxRetries, attempt, error_1, shouldRetry, normalizedError, finalError;
2080
2229
  var blob = _b.blob,
2081
2230
  endpoint = _b.endpoint,
2082
2231
  sessionId = _b.sessionId,
@@ -2090,68 +2239,124 @@ function performUpload(_a) {
2090
2239
  return [4 /*yield*/, calculateMd5(blob)];
2091
2240
  case 1:
2092
2241
  fingerprint = _c.sent();
2093
- return [2 /*return*/, new Promise(function (resolve, reject) {
2094
- var documentId;
2095
- var headers = {
2096
- 'X-Session-Id': sessionId
2097
- };
2098
- if (metadata === null || metadata === void 0 ? void 0 : metadata.jobid) headers['X-Job-Id'] = metadata.jobid;
2099
- if (metadata === null || metadata === void 0 ? void 0 : metadata.taskid) headers['X-Task-Id'] = metadata.taskid;
2100
- var upload = createUpload(blob, {
2101
- endpoint: endpoint,
2102
- retryDelays: [0, 1000, 1000, 1000, 3000, 5000, 10000, 20000],
2103
- headers: headers,
2104
- metadata: _assign({
2105
- filetype: blob.type,
2106
- contentType: blob.type,
2107
- fingerprint: fingerprint
2108
- }, metadata || {}),
2109
- onProgress: function onProgress(bytesUploaded, bytesTotal) {
2110
- onDocumentUploadProgress === null || onDocumentUploadProgress === void 0 ? void 0 : onDocumentUploadProgress({
2111
- bytesUploaded: bytesUploaded,
2112
- bytesTotal: bytesTotal,
2113
- percentage: (bytesUploaded / bytesTotal * 100).toFixed(2) + '%',
2114
- metadata: metadata
2115
- });
2116
- },
2117
- onAfterResponse: function onAfterResponse(_req, res) {
2118
- var contentType = res.getHeader('Content-Type');
2119
- if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('application/json'))) return;
2120
- var body = res.getBody();
2121
- if (!body) return;
2122
- try {
2123
- var parsedId = JSON.parse(body).id;
2124
- if (parsedId.startsWith('urn:documentsv1:')) {
2125
- documentId = parsedId;
2126
- }
2127
- } catch (e) {
2128
- warn('Failed to parse documents service response body', e);
2129
- }
2130
- },
2131
- onSuccess: function onSuccess() {
2132
- var _a;
2133
- documentId || (documentId = "urn:documentsv1:".concat(getEnvFromUrl(upload.url), ":").concat((_a = upload.url.split('/files/').pop()) === null || _a === void 0 ? void 0 : _a.split('+').shift()));
2134
- onDocumentUploaded === null || onDocumentUploaded === void 0 ? void 0 : onDocumentUploaded(documentId, metadata);
2135
- resolve(documentId);
2136
- },
2137
- onError: function onError(error) {
2138
- log('Failed because: ' + error);
2139
- onDocumentUploadFailed === null || onDocumentUploadFailed === void 0 ? void 0 : onDocumentUploadFailed(error, metadata);
2140
- reject(error);
2141
- }
2142
- });
2143
- // Check if there are any previous uploads to continue.
2144
- upload.findPreviousUploads().then(function (previousUploads) {
2145
- // Found previous uploads so we select the first one.
2146
- if (previousUploads.length) {
2147
- upload.resumeFromPreviousUpload(previousUploads[0]);
2148
- }
2149
- // Start the upload
2150
- upload.start();
2151
- });
2242
+ headers = {
2243
+ 'X-Session-Id': sessionId
2244
+ };
2245
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.jobid) headers['X-Job-Id'] = metadata.jobid;
2246
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.taskid) headers['X-Task-Id'] = metadata.taskid;
2247
+ maxRetries = CREATE_UPLOAD_RETRY_DELAYS.length;
2248
+ attempt = 0;
2249
+ _c.label = 2;
2250
+ case 2:
2251
+ if (!(attempt <= maxRetries)) return [3 /*break*/, 9];
2252
+ _c.label = 3;
2253
+ case 3:
2254
+ _c.trys.push([3, 5,, 8]);
2255
+ return [4 /*yield*/, startTusUpload({
2256
+ blob: blob,
2257
+ endpoint: endpoint,
2258
+ headers: headers,
2259
+ metadata: metadata,
2260
+ fingerprint: fingerprint,
2261
+ onDocumentUploadProgress: onDocumentUploadProgress,
2262
+ onDocumentUploaded: onDocumentUploaded
2152
2263
  })];
2264
+ case 4:
2265
+ return [2 /*return*/, _c.sent()];
2266
+ case 5:
2267
+ error_1 = _c.sent();
2268
+ shouldRetry = attempt < maxRetries && shouldRetryCreateRequest(error_1);
2269
+ normalizedError = normalizeUploadError(error_1);
2270
+ if (!shouldRetry) return [3 /*break*/, 7];
2271
+ log("Retrying tus upload creation (attempt ".concat(attempt + 2, "/").concat(maxRetries + 1, ") after error: ").concat(normalizedError.message));
2272
+ return [4 /*yield*/, waitFor(CREATE_UPLOAD_RETRY_DELAYS[attempt])];
2273
+ case 6:
2274
+ _c.sent();
2275
+ return [3 /*break*/, 8];
2276
+ case 7:
2277
+ log('Failed because: ' + normalizedError.message);
2278
+ onDocumentUploadFailed === null || onDocumentUploadFailed === void 0 ? void 0 : onDocumentUploadFailed(normalizedError, metadata);
2279
+ throw normalizedError;
2280
+ case 8:
2281
+ attempt++;
2282
+ return [3 /*break*/, 2];
2283
+ case 9:
2284
+ finalError = new Error('tus upload failed after retries');
2285
+ onDocumentUploadFailed === null || onDocumentUploadFailed === void 0 ? void 0 : onDocumentUploadFailed(finalError, metadata);
2286
+ throw finalError;
2287
+ }
2288
+ });
2289
+ });
2290
+ }
2291
+ function startTusUpload(_a) {
2292
+ var blob = _a.blob,
2293
+ endpoint = _a.endpoint,
2294
+ headers = _a.headers,
2295
+ metadata = _a.metadata,
2296
+ fingerprint = _a.fingerprint,
2297
+ onDocumentUploadProgress = _a.onDocumentUploadProgress,
2298
+ onDocumentUploaded = _a.onDocumentUploaded;
2299
+ return new Promise(function (resolve, reject) {
2300
+ var documentId;
2301
+ var upload = createUpload(blob, {
2302
+ endpoint: endpoint,
2303
+ retryDelays: [0, 1000, 1000, 1000, 3000, 5000, 10000, 20000],
2304
+ headers: headers,
2305
+ metadata: _assign({
2306
+ filetype: blob.type,
2307
+ contentType: blob.type,
2308
+ fingerprint: fingerprint
2309
+ }, metadata || {}),
2310
+ onProgress: function onProgress(bytesUploaded, bytesTotal) {
2311
+ onDocumentUploadProgress === null || onDocumentUploadProgress === void 0 ? void 0 : onDocumentUploadProgress({
2312
+ bytesUploaded: bytesUploaded,
2313
+ bytesTotal: bytesTotal,
2314
+ percentage: (bytesUploaded / bytesTotal * 100).toFixed(2) + '%',
2315
+ metadata: metadata
2316
+ });
2317
+ },
2318
+ onAfterResponse: function onAfterResponse(_req, res) {
2319
+ var contentType = res.getHeader('Content-Type');
2320
+ if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('application/json'))) return;
2321
+ var body = res.getBody();
2322
+ if (!body) return;
2323
+ try {
2324
+ var parsedId = JSON.parse(body).id;
2325
+ if (parsedId.startsWith('urn:documentsv1:')) {
2326
+ documentId = parsedId;
2327
+ }
2328
+ } catch (e) {
2329
+ warn('Failed to parse documents service response body', e);
2330
+ }
2331
+ },
2332
+ onSuccess: function onSuccess() {
2333
+ var _a;
2334
+ documentId || (documentId = "urn:documentsv1:".concat(getEnvFromUrl(upload.url), ":").concat((_a = upload.url.split('/files/').pop()) === null || _a === void 0 ? void 0 : _a.split('+').shift()));
2335
+ if (!documentId) {
2336
+ reject(new Error('Document upload succeeded but no document id was returned'));
2337
+ return;
2338
+ }
2339
+ void (onDocumentUploaded === null || onDocumentUploaded === void 0 ? void 0 : onDocumentUploaded(documentId, metadata));
2340
+ resolve(documentId);
2341
+ },
2342
+ onError: function onError(error) {
2343
+ reject(error);
2344
+ },
2345
+ onShouldRetry: function onShouldRetry(error) {
2346
+ return shouldRetryChunkRequest(error);
2153
2347
  }
2154
2348
  });
2349
+ upload.findPreviousUploads().then(function (previousUploads) {
2350
+ if (previousUploads.length) {
2351
+ upload.resumeFromPreviousUpload(previousUploads[0]);
2352
+ }
2353
+ upload.start();
2354
+ })["catch"](reject);
2355
+ });
2356
+ }
2357
+ function waitFor(ms) {
2358
+ return new Promise(function (resolve) {
2359
+ setTimeout(resolve, ms);
2155
2360
  });
2156
2361
  }
2157
2362
  function useSubmissionContext() {
@@ -7086,7 +7291,8 @@ var IdCapture = function IdCapture(_a) {
7086
7291
  var capturedDocumentType = documentType;
7087
7292
  setTimeout(function () {
7088
7293
  var _a, _b;
7089
- var captureTime = performance.now() - ((_a = state.captureStartedAt) !== null && _a !== void 0 ? _a : new Date()).getTime();
7294
+ var captureStartedAt = (_a = state.captureStartedAt) === null || _a === void 0 ? void 0 : _a.getTime();
7295
+ var captureTime = captureStartedAt ? Date.now() - captureStartedAt : 0;
7090
7296
  var metadata = {
7091
7297
  autoCapture: 'Y',
7092
7298
  captureTime: captureTime,
@@ -10946,12 +11152,14 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
10946
11152
  captureState = _a.captureState,
10947
11153
  operationStartedAt = _a.operationStartedAt,
10948
11154
  requestedDocumentType = _a.requestedDocumentType;
11155
+ if (!requestedDocumentType) return;
11156
+ var docType = requestedDocumentType;
10949
11157
  metadata.operationTime = new Date().getTime() - (operationStartedAt !== null && operationStartedAt !== void 0 ? operationStartedAt : new Date()).getTime();
10950
11158
  metadata.captureMode = isFallbackMode ? 'Manual' : captureState === 'uploading' ? 'Upload' : 'Auto';
10951
- if (requestedDocumentType === 'idCardBack') {
10952
- logIdBackCaptureAttempt(metadata);
11159
+ if (docType === 'idCardBack') {
11160
+ logIdBackCaptureAttempt(metadata, docType);
10953
11161
  } else {
10954
- logIdFrontCaptureAttempt(metadata);
11162
+ logIdFrontCaptureAttempt(metadata, docType);
10955
11163
  }
10956
11164
  }, [isFallbackMode, logIdBackCaptureAttempt, logIdFrontCaptureAttempt]);
10957
11165
  useEffect(function startModelsWhenCapturing() {
@@ -14465,10 +14673,12 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14465
14673
  });
14466
14674
  }
14467
14675
  };
14468
- signatureRecorder.start(250);
14469
- // const interval = setInterval(() => signatureRecorder?.requestData(), 250)
14676
+ signatureRecorder.start();
14677
+ var interval = setInterval(function () {
14678
+ return signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.requestData();
14679
+ }, 250);
14470
14680
  set({
14471
- // requestDataInterval: interval,
14681
+ requestDataInterval: interval,
14472
14682
  recordingStartRequestedAt: performance.now()
14473
14683
  });
14474
14684
  },
@@ -14536,6 +14746,7 @@ var useVideoSignatureStore = create()(devtools(function (set, get) {
14536
14746
  recordingStopRequestedAt: performance.now(),
14537
14747
  recordingStoppedAt: undefined
14538
14748
  });
14749
+ clearInterval(get().requestDataInterval);
14539
14750
  return [4 /*yield*/, waitForOneMoreChunk()
14540
14751
  // this represents the time that it is safe to release the camera access
14541
14752
  ];
@@ -15351,10 +15562,16 @@ function SelfieCaptureWizard(_a) {
15351
15562
  onCapture === null || onCapture === void 0 ? void 0 : onCapture(imageUrl);
15352
15563
  }, [logCaptureMetadata, onCapture]);
15353
15564
  var onFallbackImageCaptured = useCallback(function (imageUrl) {
15565
+ logSelfieCaptureAttempt({
15566
+ autoCapture: 'N',
15567
+ captureMode: 'Upload',
15568
+ captureTime: 0,
15569
+ operationTime: 0
15570
+ });
15354
15571
  setSelfieImage(imageUrl);
15355
15572
  setCaptureState('SUCCESS');
15356
15573
  onCapture === null || onCapture === void 0 ? void 0 : onCapture(imageUrl);
15357
- }, [onCapture, setSelfieImage]);
15574
+ }, [logSelfieCaptureAttempt, onCapture, setSelfieImage]);
15358
15575
  var guidesByRequestState = useCallback(function (props) {
15359
15576
  var GuidesComponent = guidesComponent !== null && guidesComponent !== void 0 ? guidesComponent : FaceCaptureGuideOverlay;
15360
15577
  var status = ['IN_PROGRESS', 'CAPTURE_STARTED', 'GUIDANCE_SATISFIED', 'CAPTURED'].includes(captureState) ? 'processing' : ['FAILED', 'ERROR'].includes(captureState) ? 'failure' : 'ready';