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.
@@ -235,7 +235,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
235
235
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
236
236
  };
237
237
 
238
- var webSdkVersion = '2.3.127';
238
+ var webSdkVersion = '2.3.129';
239
239
 
240
240
  function getPlatform() {
241
241
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -385,11 +385,13 @@ function attachMetadataToRequest(request, _a) {
385
385
  var selfieCaptureAttempts = _a.selfieCaptureAttempts,
386
386
  idFrontCaptureAttempts = _a.idFrontCaptureAttempts,
387
387
  idBackCaptureAttempts = _a.idBackCaptureAttempts,
388
+ barcodeCaptureAttempts = _a.barcodeCaptureAttempts,
388
389
  geolocationResult = _a.geolocationResult;
389
390
  var metadata = {
390
391
  selfie: selfieCaptureAttempts,
391
392
  front: idFrontCaptureAttempts,
392
393
  back: idBackCaptureAttempts,
394
+ barcode: barcodeCaptureAttempts,
393
395
  isRealIDCheckRequired: 'false',
394
396
  sdkVersion: "WebSDK_".concat(webSdkVersion),
395
397
  Resolution: typeof window !== 'undefined' ? "".concat(window.innerWidth, " x ").concat(window.innerHeight) : 'unknown'
@@ -1114,6 +1116,26 @@ function setServerUrl(url) {
1114
1116
  setDefaultSubmissionUrl(url + '/swagger');
1115
1117
  setDefaultDocumentServiceUrl(url + '/files/');
1116
1118
  }
1119
+ var capturedDocumentTypeToSubmissionKey = {
1120
+ idCardFront: 'idFrontImage',
1121
+ idCardBack: 'idBackImage',
1122
+ passport: 'passportImage',
1123
+ singlePage: 'idFrontImage',
1124
+ selfie: 'selfieImage',
1125
+ idFrontIrImage: 'idFrontIrImage',
1126
+ idBackIrImage: 'idBackIrImage',
1127
+ idFrontUvImage: 'idFrontUvImage',
1128
+ idBackUvImage: 'idBackUvImage',
1129
+ idBarcodeImage: 'idBarcodeImage'
1130
+ };
1131
+ var sanitizeMetadata = function sanitizeMetadata(metadata) {
1132
+ var entries = Object.entries(metadata).filter(function (_a) {
1133
+ var value = _a[1];
1134
+ return value !== undefined && value !== null;
1135
+ });
1136
+ if (!entries.length) return null;
1137
+ return Object.fromEntries(entries);
1138
+ };
1117
1139
  var SubmissionContext = /*#__PURE__*/React.createContext({
1118
1140
  submit: function submit() {
1119
1141
  return __awaiter(void 0, void 0, void 0, function () {
@@ -1201,6 +1223,9 @@ var SubmissionContext = /*#__PURE__*/React.createContext({
1201
1223
  setAdditionalDocuments: function setAdditionalDocuments() {
1202
1224
  return null;
1203
1225
  },
1226
+ setDocumentFileMetadata: function setDocumentFileMetadata() {
1227
+ return null;
1228
+ },
1204
1229
  uploadDocument: Promise.resolve,
1205
1230
  logIdFrontCaptureAttempt: function logIdFrontCaptureAttempt() {
1206
1231
  return null;
@@ -1352,60 +1377,139 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1352
1377
  var _18 = React.useState(null),
1353
1378
  signatureVideoMetadata = _18[0],
1354
1379
  setSignatureVideoMetadata = _18[1];
1355
- var _19 = React.useState(null),
1356
- idCaptureVideoUrl = _19[0],
1357
- setIdCaptureVideoUrl = _19[1];
1358
- var _20 = React.useState(null),
1359
- idCaptureVideoIdFrontImage = _20[0],
1360
- setIdCaptureVideoIdFrontImage = _20[1];
1380
+ var _19 = React.useState({}),
1381
+ documentFileMetadata = _19[0],
1382
+ setDocumentFileMetadataState = _19[1];
1383
+ var _20 = React.useState([]),
1384
+ barcodeCaptureAttempts = _20[0],
1385
+ setBarcodeCaptureAttempts = _20[1];
1361
1386
  var _21 = React.useState(null),
1362
- idCaptureVideoIdBackImage = _21[0],
1363
- setIdCaptureVideoIdBackImage = _21[1];
1387
+ idCaptureVideoUrl = _21[0],
1388
+ setIdCaptureVideoUrl = _21[1];
1364
1389
  var _22 = React.useState(null),
1365
- idCaptureVideoAudioUrl = _22[0],
1366
- setIdCaptureVideoAudioUrl = _22[1];
1390
+ idCaptureVideoIdFrontImage = _22[0],
1391
+ setIdCaptureVideoIdFrontImage = _22[1];
1367
1392
  var _23 = React.useState(null),
1368
- idCaptureVideoAudioStartsAt = _23[0],
1369
- setIdCaptureVideoAudioStartsAt = _23[1];
1393
+ idCaptureVideoIdBackImage = _23[0],
1394
+ setIdCaptureVideoIdBackImage = _23[1];
1370
1395
  var _24 = React.useState(null),
1371
- expectedAudioText = _24[0],
1372
- setExpectedAudioText = _24[1];
1396
+ idCaptureVideoAudioUrl = _24[0],
1397
+ setIdCaptureVideoAudioUrl = _24[1];
1373
1398
  var _25 = React.useState(null),
1374
- additionalDocuments = _25[0],
1375
- setAdditionalDocuments = _25[1];
1399
+ idCaptureVideoAudioStartsAt = _25[0],
1400
+ setIdCaptureVideoAudioStartsAt = _25[1];
1376
1401
  var _26 = React.useState(null),
1377
- geolocationResult = _26[0],
1378
- setGeolocationResult = _26[1];
1379
- var _27 = React.useState(0),
1380
- geolocationAttempts = _27[0],
1381
- setGeolocationAttempts = _27[1];
1382
- var _28 = React.useState(false),
1383
- geolocationBlocked = _28[0],
1384
- setGeolocationBlocked = _28[1];
1385
- var _29 = React.useState([]),
1386
- idFrontCaptureAttempts = _29[0],
1387
- setIdFrontCaptureAttempts = _29[1];
1388
- var _30 = React.useState([]),
1389
- idBackCaptureAttempts = _30[0],
1390
- setIdBackCaptureAttempts = _30[1];
1402
+ expectedAudioText = _26[0],
1403
+ setExpectedAudioText = _26[1];
1404
+ var _27 = React.useState(null),
1405
+ additionalDocuments = _27[0],
1406
+ setAdditionalDocuments = _27[1];
1407
+ var setDocumentFileMetadata = React.useCallback(function (key, metadata) {
1408
+ var sanitized = metadata ? sanitizeMetadata(metadata) : null;
1409
+ setDocumentFileMetadataState(function (current) {
1410
+ var _a;
1411
+ if (!sanitized) {
1412
+ if (!(key in current)) return current;
1413
+ var next = _assign({}, current);
1414
+ delete next[key];
1415
+ if (key === 'idBarcodeImage') {
1416
+ setBarcodeCaptureAttempts([]);
1417
+ }
1418
+ return next;
1419
+ }
1420
+ return _assign(_assign({}, current), (_a = {}, _a[key] = sanitized, _a));
1421
+ });
1422
+ }, []);
1423
+ var _28 = React.useState(null),
1424
+ geolocationResult = _28[0],
1425
+ setGeolocationResult = _28[1];
1426
+ var _29 = React.useState(0),
1427
+ geolocationAttempts = _29[0],
1428
+ setGeolocationAttempts = _29[1];
1429
+ var _30 = React.useState(false),
1430
+ geolocationBlocked = _30[0],
1431
+ setGeolocationBlocked = _30[1];
1391
1432
  var _31 = React.useState([]),
1392
- selfieCaptureAttempts = _31[0],
1393
- setSelfieCaptureAttempts = _31[1];
1394
- var logIdFrontCaptureAttempt = React.useCallback(function (attempt) {
1433
+ idFrontCaptureAttempts = _31[0],
1434
+ setIdFrontCaptureAttempts = _31[1];
1435
+ var _32 = React.useState([]),
1436
+ idBackCaptureAttempts = _32[0],
1437
+ setIdBackCaptureAttempts = _32[1];
1438
+ var _33 = React.useState([]),
1439
+ selfieCaptureAttempts = _33[0],
1440
+ setSelfieCaptureAttempts = _33[1];
1441
+ var logIdFrontCaptureAttempt = React.useCallback(function (attempt, documentType) {
1395
1442
  setIdFrontCaptureAttempts(function (attempts) {
1396
1443
  return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
1397
1444
  });
1398
- }, []);
1399
- var logIdBackCaptureAttempt = React.useCallback(function (attempt) {
1445
+ var submissionKey = capturedDocumentTypeToSubmissionKey[documentType];
1446
+ if (submissionKey) {
1447
+ setDocumentFileMetadata(submissionKey, {
1448
+ documentType: documentType,
1449
+ documentKey: submissionKey,
1450
+ captureMode: attempt.captureMode,
1451
+ autoCapture: attempt.autoCapture,
1452
+ captureTime: attempt.captureTime,
1453
+ operationTime: attempt.operationTime,
1454
+ bestDetectionScore: attempt.bestDetectionScore,
1455
+ bestFocusScore: attempt.bestFocusScore,
1456
+ bestBarcodeScore: attempt.bestBarcodeScore,
1457
+ boundingBox: attempt.boundingBox
1458
+ });
1459
+ }
1460
+ if (attempt.bestBarcodeScore !== undefined && attempt.bestBarcodeScore !== null) {
1461
+ setBarcodeCaptureAttempts(function (attempts) {
1462
+ return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
1463
+ });
1464
+ setDocumentFileMetadata('idBarcodeImage', {
1465
+ documentType: 'idBarcodeImage',
1466
+ sourceDocumentType: documentType,
1467
+ documentKey: 'idBarcodeImage',
1468
+ bestBarcodeScore: attempt.bestBarcodeScore,
1469
+ captureMode: attempt.captureMode,
1470
+ autoCapture: attempt.autoCapture,
1471
+ captureTime: attempt.captureTime,
1472
+ operationTime: attempt.operationTime
1473
+ });
1474
+ }
1475
+ }, [setDocumentFileMetadata]);
1476
+ var logIdBackCaptureAttempt = React.useCallback(function (attempt, documentType) {
1400
1477
  setIdBackCaptureAttempts(function (attempts) {
1401
1478
  return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
1402
1479
  });
1403
- }, []);
1480
+ var submissionKey = capturedDocumentTypeToSubmissionKey[documentType];
1481
+ if (submissionKey) {
1482
+ setDocumentFileMetadata(submissionKey, {
1483
+ documentType: documentType,
1484
+ documentKey: submissionKey,
1485
+ captureMode: attempt.captureMode,
1486
+ autoCapture: attempt.autoCapture,
1487
+ captureTime: attempt.captureTime,
1488
+ operationTime: attempt.operationTime,
1489
+ bestDetectionScore: attempt.bestDetectionScore,
1490
+ bestFocusScore: attempt.bestFocusScore,
1491
+ bestBarcodeScore: attempt.bestBarcodeScore,
1492
+ boundingBox: attempt.boundingBox
1493
+ });
1494
+ }
1495
+ }, [setDocumentFileMetadata]);
1404
1496
  var logSelfieCaptureAttempt = React.useCallback(function (attempt) {
1405
1497
  setSelfieCaptureAttempts(function (attempts) {
1406
1498
  return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
1407
1499
  });
1408
- }, []);
1500
+ setDocumentFileMetadata('selfieImage', {
1501
+ documentType: 'selfie',
1502
+ documentKey: 'selfieImage',
1503
+ captureMode: attempt.captureMode,
1504
+ autoCapture: attempt.autoCapture,
1505
+ captureTime: attempt.captureTime,
1506
+ operationTime: attempt.operationTime,
1507
+ livenessScore: attempt.livenessScore,
1508
+ bestDetectionScore: attempt.bestDetectionScore,
1509
+ bestFocusScore: attempt.bestFocusScore,
1510
+ boundingBox: attempt.boundingBox
1511
+ });
1512
+ }, [setDocumentFileMetadata]);
1409
1513
  useRevokeObjectUrlOnUnmount(signatureVideoUrl);
1410
1514
  useRevokeObjectUrlOnUnmount(idCaptureVideoUrl);
1411
1515
  useRevokeObjectUrlOnUnmount(idCaptureVideoAudioUrl);
@@ -1555,14 +1659,15 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1555
1659
  if (!documentServiceUrl) return [3 /*break*/, 8];
1556
1660
  return [4 /*yield*/, Promise.all(Object.keys(documents).map(function (k) {
1557
1661
  return __awaiter(void 0, void 0, void 0, function () {
1558
- var filetype, metadata, _a, _b;
1662
+ var filetype, metadataSource, metadata, _a, _b;
1559
1663
  return __generator(this, function (_c) {
1560
1664
  switch (_c.label) {
1561
1665
  case 0:
1562
1666
  if (!documents[k]) return [3 /*break*/, 2];
1563
1667
  filetype = k.endsWith('Video') ? 'video/mp4' : k.endsWith('Audio') ? 'audio/mp4' : 'image/jpeg';
1564
- metadata = k === 'signatureVideo' ? {
1565
- filemetadata: JSON.stringify(signatureVideoMetadata)
1668
+ metadataSource = k === 'signatureVideo' && signatureVideoMetadata ? signatureVideoMetadata : documentFileMetadata[k];
1669
+ metadata = metadataSource ? {
1670
+ filemetadata: JSON.stringify(metadataSource)
1566
1671
  } : {};
1567
1672
  _a = documents;
1568
1673
  _b = k;
@@ -1713,7 +1818,8 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1713
1818
  selfieCaptureAttempts: selfieCaptureAttempts,
1714
1819
  idFrontCaptureAttempts: idFrontCaptureAttempts,
1715
1820
  idBackCaptureAttempts: idBackCaptureAttempts,
1716
- geolocationResult: geolocationResult
1821
+ geolocationResult: geolocationResult,
1822
+ barcodeCaptureAttempts: barcodeCaptureAttempts
1717
1823
  });
1718
1824
  if (!onBeforeSubmit.current) return [3 /*break*/, 10];
1719
1825
  return [4 /*yield*/, onBeforeSubmit.current(submissionRequest)];
@@ -1726,7 +1832,7 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1726
1832
  }
1727
1833
  });
1728
1834
  });
1729
- }, [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]);
1835
+ }, [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]);
1730
1836
  var defaultOnSubmit = React.useCallback(function () {
1731
1837
  return __awaiter(void 0, void 0, void 0, function () {
1732
1838
  var submissionResponse_1, payload, host, endpoint, response, statusMessage, submissionResponse_2, e_1, err;
@@ -1886,7 +1992,8 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1886
1992
  selfieCaptureAttempts: selfieCaptureAttempts,
1887
1993
  idFrontCaptureAttempts: idFrontCaptureAttempts,
1888
1994
  idBackCaptureAttempts: idBackCaptureAttempts,
1889
- geolocationResult: geolocationResult
1995
+ geolocationResult: geolocationResult,
1996
+ barcodeCaptureAttempts: barcodeCaptureAttempts
1890
1997
  });
1891
1998
  if (!onBeforeLivenessCheck.current) return [3 /*break*/, 5];
1892
1999
  return [4 /*yield*/, onBeforeLivenessCheck.current(request)];
@@ -1900,7 +2007,7 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1900
2007
  }
1901
2008
  });
1902
2009
  });
1903
- }, [clientRequestID, documentServiceUrl, estimateAge, geolocationResult, idBackCaptureAttempts, idCardForFaceMatch, idFrontCaptureAttempts, jobId, predictGender, selfieCaptureAttempts, uploadDocument, useDocumentServiceForLivenessChecks, webhooksStripSpecialCharacters]);
2010
+ }, [clientRequestID, documentServiceUrl, estimateAge, geolocationResult, barcodeCaptureAttempts, idBackCaptureAttempts, idCardForFaceMatch, idFrontCaptureAttempts, jobId, predictGender, selfieCaptureAttempts, uploadDocument, useDocumentServiceForLivenessChecks, webhooksStripSpecialCharacters]);
1904
2011
  var checkLiveness = React.useCallback(function (imageDataUrl) {
1905
2012
  return __awaiter(void 0, void 0, void 0, function () {
1906
2013
  var request, host, endpoint, response, statusMessage, submissionResponse_3, e_2, err;
@@ -2033,6 +2140,7 @@ var SubmissionProvider = function SubmissionProvider(_a) {
2033
2140
  setIdCaptureVideoAudioStartsAt: setIdCaptureVideoAudioStartsAt,
2034
2141
  setExpectedAudioText: setExpectedAudioText,
2035
2142
  setAdditionalDocuments: setAdditionalDocuments,
2143
+ setDocumentFileMetadata: setDocumentFileMetadata,
2036
2144
  uploadDocument: uploadDocument,
2037
2145
  logIdFrontCaptureAttempt: logIdFrontCaptureAttempt,
2038
2146
  logIdBackCaptureAttempt: logIdBackCaptureAttempt,
@@ -2041,7 +2149,7 @@ var SubmissionProvider = function SubmissionProvider(_a) {
2041
2149
  checkLiveness: checkLiveness,
2042
2150
  retryLocationAccess: retryLocationAccess
2043
2151
  };
2044
- }, [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]);
2152
+ }, [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]);
2045
2153
  return /*#__PURE__*/React__namespace.default.createElement(SubmissionContext.Provider, {
2046
2154
  value: value
2047
2155
  }, geolocationRequired && geolocationBlocked ? ( /*#__PURE__*/React__namespace.default.createElement(GeolocationAccessDeniedOverlay, null)) : children, submissionError && ( /*#__PURE__*/React__namespace.default.createElement(SubmissionErrorOverlay, {
@@ -2105,9 +2213,50 @@ function getEnvFromUrl(url) {
2105
2213
  }
2106
2214
  return 'unknown';
2107
2215
  }
2216
+ var CREATE_UPLOAD_RETRY_DELAYS = [1500, 3000, 6000, 12000];
2217
+ var RETRYABLE_STATUS_CODES = new Set([408, 409, 423]);
2218
+ function shouldRetryTusError(error, retryableMethods) {
2219
+ var _a, _b, _c, _d;
2220
+ if (typeof ProgressEvent !== 'undefined' && error instanceof ProgressEvent) {
2221
+ return true;
2222
+ }
2223
+ if (error instanceof tusJsClient.DetailedError) {
2224
+ var method = void 0;
2225
+ try {
2226
+ method = (_b = (_a = error.originalRequest) === null || _a === void 0 ? void 0 : _a.getMethod) === null || _b === void 0 ? void 0 : _b.call(_a);
2227
+ } catch (requestMethodError) {
2228
+ warn('Unable to read request method from tus error', requestMethodError);
2229
+ return false;
2230
+ }
2231
+ if (method && retryableMethods.length && !retryableMethods.includes(method)) {
2232
+ return false;
2233
+ }
2234
+ var status_1 = (_d = (_c = error.originalResponse) === null || _c === void 0 ? void 0 : _c.getStatus) === null || _d === void 0 ? void 0 : _d.call(_c);
2235
+ if (typeof status_1 === 'number') {
2236
+ if (status_1 >= 500 || RETRYABLE_STATUS_CODES.has(status_1)) {
2237
+ return true;
2238
+ }
2239
+ return false;
2240
+ }
2241
+ return true;
2242
+ }
2243
+ return false;
2244
+ }
2245
+ function shouldRetryCreateRequest(error) {
2246
+ return shouldRetryTusError(error, ['POST']);
2247
+ }
2248
+ function shouldRetryChunkRequest(error) {
2249
+ return shouldRetryTusError(error, ['PATCH', 'POST']);
2250
+ }
2251
+ function normalizeUploadError(error) {
2252
+ if (error instanceof Error) {
2253
+ return error;
2254
+ }
2255
+ return new Error('tus upload failed');
2256
+ }
2108
2257
  function performUpload(_a) {
2109
2258
  return __awaiter(this, arguments, void 0, function (_b) {
2110
- var fingerprint;
2259
+ var fingerprint, headers, maxRetries, attempt, error_1, shouldRetry, normalizedError, finalError;
2111
2260
  var blob = _b.blob,
2112
2261
  endpoint = _b.endpoint,
2113
2262
  sessionId = _b.sessionId,
@@ -2121,68 +2270,124 @@ function performUpload(_a) {
2121
2270
  return [4 /*yield*/, calculateMd5(blob)];
2122
2271
  case 1:
2123
2272
  fingerprint = _c.sent();
2124
- return [2 /*return*/, new Promise(function (resolve, reject) {
2125
- var documentId;
2126
- var headers = {
2127
- 'X-Session-Id': sessionId
2128
- };
2129
- if (metadata === null || metadata === void 0 ? void 0 : metadata.jobid) headers['X-Job-Id'] = metadata.jobid;
2130
- if (metadata === null || metadata === void 0 ? void 0 : metadata.taskid) headers['X-Task-Id'] = metadata.taskid;
2131
- var upload = createUpload(blob, {
2132
- endpoint: endpoint,
2133
- retryDelays: [0, 1000, 1000, 1000, 3000, 5000, 10000, 20000],
2134
- headers: headers,
2135
- metadata: _assign({
2136
- filetype: blob.type,
2137
- contentType: blob.type,
2138
- fingerprint: fingerprint
2139
- }, metadata || {}),
2140
- onProgress: function onProgress(bytesUploaded, bytesTotal) {
2141
- onDocumentUploadProgress === null || onDocumentUploadProgress === void 0 ? void 0 : onDocumentUploadProgress({
2142
- bytesUploaded: bytesUploaded,
2143
- bytesTotal: bytesTotal,
2144
- percentage: (bytesUploaded / bytesTotal * 100).toFixed(2) + '%',
2145
- metadata: metadata
2146
- });
2147
- },
2148
- onAfterResponse: function onAfterResponse(_req, res) {
2149
- var contentType = res.getHeader('Content-Type');
2150
- if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('application/json'))) return;
2151
- var body = res.getBody();
2152
- if (!body) return;
2153
- try {
2154
- var parsedId = JSON.parse(body).id;
2155
- if (parsedId.startsWith('urn:documentsv1:')) {
2156
- documentId = parsedId;
2157
- }
2158
- } catch (e) {
2159
- warn('Failed to parse documents service response body', e);
2160
- }
2161
- },
2162
- onSuccess: function onSuccess() {
2163
- var _a;
2164
- documentId || (documentId = "urn:documentsv1:".concat(getEnvFromUrl(upload.url), ":").concat((_a = upload.url.split('/files/').pop()) === null || _a === void 0 ? void 0 : _a.split('+').shift()));
2165
- onDocumentUploaded === null || onDocumentUploaded === void 0 ? void 0 : onDocumentUploaded(documentId, metadata);
2166
- resolve(documentId);
2167
- },
2168
- onError: function onError(error) {
2169
- log('Failed because: ' + error);
2170
- onDocumentUploadFailed === null || onDocumentUploadFailed === void 0 ? void 0 : onDocumentUploadFailed(error, metadata);
2171
- reject(error);
2172
- }
2173
- });
2174
- // Check if there are any previous uploads to continue.
2175
- upload.findPreviousUploads().then(function (previousUploads) {
2176
- // Found previous uploads so we select the first one.
2177
- if (previousUploads.length) {
2178
- upload.resumeFromPreviousUpload(previousUploads[0]);
2179
- }
2180
- // Start the upload
2181
- upload.start();
2182
- });
2273
+ headers = {
2274
+ 'X-Session-Id': sessionId
2275
+ };
2276
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.jobid) headers['X-Job-Id'] = metadata.jobid;
2277
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.taskid) headers['X-Task-Id'] = metadata.taskid;
2278
+ maxRetries = CREATE_UPLOAD_RETRY_DELAYS.length;
2279
+ attempt = 0;
2280
+ _c.label = 2;
2281
+ case 2:
2282
+ if (!(attempt <= maxRetries)) return [3 /*break*/, 9];
2283
+ _c.label = 3;
2284
+ case 3:
2285
+ _c.trys.push([3, 5,, 8]);
2286
+ return [4 /*yield*/, startTusUpload({
2287
+ blob: blob,
2288
+ endpoint: endpoint,
2289
+ headers: headers,
2290
+ metadata: metadata,
2291
+ fingerprint: fingerprint,
2292
+ onDocumentUploadProgress: onDocumentUploadProgress,
2293
+ onDocumentUploaded: onDocumentUploaded
2183
2294
  })];
2295
+ case 4:
2296
+ return [2 /*return*/, _c.sent()];
2297
+ case 5:
2298
+ error_1 = _c.sent();
2299
+ shouldRetry = attempt < maxRetries && shouldRetryCreateRequest(error_1);
2300
+ normalizedError = normalizeUploadError(error_1);
2301
+ if (!shouldRetry) return [3 /*break*/, 7];
2302
+ log("Retrying tus upload creation (attempt ".concat(attempt + 2, "/").concat(maxRetries + 1, ") after error: ").concat(normalizedError.message));
2303
+ return [4 /*yield*/, waitFor(CREATE_UPLOAD_RETRY_DELAYS[attempt])];
2304
+ case 6:
2305
+ _c.sent();
2306
+ return [3 /*break*/, 8];
2307
+ case 7:
2308
+ log('Failed because: ' + normalizedError.message);
2309
+ onDocumentUploadFailed === null || onDocumentUploadFailed === void 0 ? void 0 : onDocumentUploadFailed(normalizedError, metadata);
2310
+ throw normalizedError;
2311
+ case 8:
2312
+ attempt++;
2313
+ return [3 /*break*/, 2];
2314
+ case 9:
2315
+ finalError = new Error('tus upload failed after retries');
2316
+ onDocumentUploadFailed === null || onDocumentUploadFailed === void 0 ? void 0 : onDocumentUploadFailed(finalError, metadata);
2317
+ throw finalError;
2318
+ }
2319
+ });
2320
+ });
2321
+ }
2322
+ function startTusUpload(_a) {
2323
+ var blob = _a.blob,
2324
+ endpoint = _a.endpoint,
2325
+ headers = _a.headers,
2326
+ metadata = _a.metadata,
2327
+ fingerprint = _a.fingerprint,
2328
+ onDocumentUploadProgress = _a.onDocumentUploadProgress,
2329
+ onDocumentUploaded = _a.onDocumentUploaded;
2330
+ return new Promise(function (resolve, reject) {
2331
+ var documentId;
2332
+ var upload = createUpload(blob, {
2333
+ endpoint: endpoint,
2334
+ retryDelays: [0, 1000, 1000, 1000, 3000, 5000, 10000, 20000],
2335
+ headers: headers,
2336
+ metadata: _assign({
2337
+ filetype: blob.type,
2338
+ contentType: blob.type,
2339
+ fingerprint: fingerprint
2340
+ }, metadata || {}),
2341
+ onProgress: function onProgress(bytesUploaded, bytesTotal) {
2342
+ onDocumentUploadProgress === null || onDocumentUploadProgress === void 0 ? void 0 : onDocumentUploadProgress({
2343
+ bytesUploaded: bytesUploaded,
2344
+ bytesTotal: bytesTotal,
2345
+ percentage: (bytesUploaded / bytesTotal * 100).toFixed(2) + '%',
2346
+ metadata: metadata
2347
+ });
2348
+ },
2349
+ onAfterResponse: function onAfterResponse(_req, res) {
2350
+ var contentType = res.getHeader('Content-Type');
2351
+ if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('application/json'))) return;
2352
+ var body = res.getBody();
2353
+ if (!body) return;
2354
+ try {
2355
+ var parsedId = JSON.parse(body).id;
2356
+ if (parsedId.startsWith('urn:documentsv1:')) {
2357
+ documentId = parsedId;
2358
+ }
2359
+ } catch (e) {
2360
+ warn('Failed to parse documents service response body', e);
2361
+ }
2362
+ },
2363
+ onSuccess: function onSuccess() {
2364
+ var _a;
2365
+ documentId || (documentId = "urn:documentsv1:".concat(getEnvFromUrl(upload.url), ":").concat((_a = upload.url.split('/files/').pop()) === null || _a === void 0 ? void 0 : _a.split('+').shift()));
2366
+ if (!documentId) {
2367
+ reject(new Error('Document upload succeeded but no document id was returned'));
2368
+ return;
2369
+ }
2370
+ void (onDocumentUploaded === null || onDocumentUploaded === void 0 ? void 0 : onDocumentUploaded(documentId, metadata));
2371
+ resolve(documentId);
2372
+ },
2373
+ onError: function onError(error) {
2374
+ reject(error);
2375
+ },
2376
+ onShouldRetry: function onShouldRetry(error) {
2377
+ return shouldRetryChunkRequest(error);
2184
2378
  }
2185
2379
  });
2380
+ upload.findPreviousUploads().then(function (previousUploads) {
2381
+ if (previousUploads.length) {
2382
+ upload.resumeFromPreviousUpload(previousUploads[0]);
2383
+ }
2384
+ upload.start();
2385
+ })["catch"](reject);
2386
+ });
2387
+ }
2388
+ function waitFor(ms) {
2389
+ return new Promise(function (resolve) {
2390
+ setTimeout(resolve, ms);
2186
2391
  });
2187
2392
  }
2188
2393
  function useSubmissionContext() {
@@ -7117,7 +7322,8 @@ var IdCapture = function IdCapture(_a) {
7117
7322
  var capturedDocumentType = documentType;
7118
7323
  setTimeout(function () {
7119
7324
  var _a, _b;
7120
- var captureTime = performance.now() - ((_a = state.captureStartedAt) !== null && _a !== void 0 ? _a : new Date()).getTime();
7325
+ var captureStartedAt = (_a = state.captureStartedAt) === null || _a === void 0 ? void 0 : _a.getTime();
7326
+ var captureTime = captureStartedAt ? Date.now() - captureStartedAt : 0;
7121
7327
  var metadata = {
7122
7328
  autoCapture: 'Y',
7123
7329
  captureTime: captureTime,
@@ -10977,12 +11183,14 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
10977
11183
  captureState = _a.captureState,
10978
11184
  operationStartedAt = _a.operationStartedAt,
10979
11185
  requestedDocumentType = _a.requestedDocumentType;
11186
+ if (!requestedDocumentType) return;
11187
+ var docType = requestedDocumentType;
10980
11188
  metadata.operationTime = new Date().getTime() - (operationStartedAt !== null && operationStartedAt !== void 0 ? operationStartedAt : new Date()).getTime();
10981
11189
  metadata.captureMode = isFallbackMode ? 'Manual' : captureState === 'uploading' ? 'Upload' : 'Auto';
10982
- if (requestedDocumentType === 'idCardBack') {
10983
- logIdBackCaptureAttempt(metadata);
11190
+ if (docType === 'idCardBack') {
11191
+ logIdBackCaptureAttempt(metadata, docType);
10984
11192
  } else {
10985
- logIdFrontCaptureAttempt(metadata);
11193
+ logIdFrontCaptureAttempt(metadata, docType);
10986
11194
  }
10987
11195
  }, [isFallbackMode, logIdBackCaptureAttempt, logIdFrontCaptureAttempt]);
10988
11196
  React.useEffect(function startModelsWhenCapturing() {
@@ -14496,10 +14704,12 @@ var useVideoSignatureStore = zustand.create()(middleware.devtools(function (set,
14496
14704
  });
14497
14705
  }
14498
14706
  };
14499
- signatureRecorder.start(250);
14500
- // const interval = setInterval(() => signatureRecorder?.requestData(), 250)
14707
+ signatureRecorder.start();
14708
+ var interval = setInterval(function () {
14709
+ return signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.requestData();
14710
+ }, 250);
14501
14711
  set({
14502
- // requestDataInterval: interval,
14712
+ requestDataInterval: interval,
14503
14713
  recordingStartRequestedAt: performance.now()
14504
14714
  });
14505
14715
  },
@@ -14567,6 +14777,7 @@ var useVideoSignatureStore = zustand.create()(middleware.devtools(function (set,
14567
14777
  recordingStopRequestedAt: performance.now(),
14568
14778
  recordingStoppedAt: undefined
14569
14779
  });
14780
+ clearInterval(get().requestDataInterval);
14570
14781
  return [4 /*yield*/, waitForOneMoreChunk()
14571
14782
  // this represents the time that it is safe to release the camera access
14572
14783
  ];
@@ -15382,10 +15593,16 @@ function SelfieCaptureWizard(_a) {
15382
15593
  onCapture === null || onCapture === void 0 ? void 0 : onCapture(imageUrl);
15383
15594
  }, [logCaptureMetadata, onCapture]);
15384
15595
  var onFallbackImageCaptured = React.useCallback(function (imageUrl) {
15596
+ logSelfieCaptureAttempt({
15597
+ autoCapture: 'N',
15598
+ captureMode: 'Upload',
15599
+ captureTime: 0,
15600
+ operationTime: 0
15601
+ });
15385
15602
  setSelfieImage(imageUrl);
15386
15603
  setCaptureState('SUCCESS');
15387
15604
  onCapture === null || onCapture === void 0 ? void 0 : onCapture(imageUrl);
15388
- }, [onCapture, setSelfieImage]);
15605
+ }, [logSelfieCaptureAttempt, onCapture, setSelfieImage]);
15389
15606
  var guidesByRequestState = React.useCallback(function (props) {
15390
15607
  var GuidesComponent = guidesComponent !== null && guidesComponent !== void 0 ? guidesComponent : FaceCaptureGuideOverlay;
15391
15608
  var status = ['IN_PROGRESS', 'CAPTURE_STARTED', 'GUIDANCE_SATISFIED', 'CAPTURED'].includes(captureState) ? 'processing' : ['FAILED', 'ERROR'].includes(captureState) ? 'failure' : 'ready';