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.
@@ -211,7 +211,7 @@
211
211
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
212
212
  };
213
213
 
214
- var webSdkVersion = '2.3.127';
214
+ var webSdkVersion = '2.3.129';
215
215
 
216
216
  function getPlatform() {
217
217
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -361,11 +361,13 @@
361
361
  var selfieCaptureAttempts = _a.selfieCaptureAttempts,
362
362
  idFrontCaptureAttempts = _a.idFrontCaptureAttempts,
363
363
  idBackCaptureAttempts = _a.idBackCaptureAttempts,
364
+ barcodeCaptureAttempts = _a.barcodeCaptureAttempts,
364
365
  geolocationResult = _a.geolocationResult;
365
366
  var metadata = {
366
367
  selfie: selfieCaptureAttempts,
367
368
  front: idFrontCaptureAttempts,
368
369
  back: idBackCaptureAttempts,
370
+ barcode: barcodeCaptureAttempts,
369
371
  isRealIDCheckRequired: 'false',
370
372
  sdkVersion: "WebSDK_".concat(webSdkVersion),
371
373
  Resolution: typeof window !== 'undefined' ? "".concat(window.innerWidth, " x ").concat(window.innerHeight) : 'unknown'
@@ -2064,6 +2066,26 @@
2064
2066
  setDefaultSubmissionUrl(url + '/swagger');
2065
2067
  setDefaultDocumentServiceUrl(url + '/files/');
2066
2068
  }
2069
+ var capturedDocumentTypeToSubmissionKey = {
2070
+ idCardFront: 'idFrontImage',
2071
+ idCardBack: 'idBackImage',
2072
+ passport: 'passportImage',
2073
+ singlePage: 'idFrontImage',
2074
+ selfie: 'selfieImage',
2075
+ idFrontIrImage: 'idFrontIrImage',
2076
+ idBackIrImage: 'idBackIrImage',
2077
+ idFrontUvImage: 'idFrontUvImage',
2078
+ idBackUvImage: 'idBackUvImage',
2079
+ idBarcodeImage: 'idBarcodeImage'
2080
+ };
2081
+ var sanitizeMetadata = function sanitizeMetadata(metadata) {
2082
+ var entries = Object.entries(metadata).filter(function (_a) {
2083
+ var value = _a[1];
2084
+ return value !== undefined && value !== null;
2085
+ });
2086
+ if (!entries.length) return null;
2087
+ return Object.fromEntries(entries);
2088
+ };
2067
2089
  var SubmissionContext = /*#__PURE__*/React.createContext({
2068
2090
  submit: function submit() {
2069
2091
  return __awaiter(void 0, void 0, void 0, function () {
@@ -2151,6 +2173,9 @@
2151
2173
  setAdditionalDocuments: function setAdditionalDocuments() {
2152
2174
  return null;
2153
2175
  },
2176
+ setDocumentFileMetadata: function setDocumentFileMetadata() {
2177
+ return null;
2178
+ },
2154
2179
  uploadDocument: Promise.resolve,
2155
2180
  logIdFrontCaptureAttempt: function logIdFrontCaptureAttempt() {
2156
2181
  return null;
@@ -2302,60 +2327,139 @@
2302
2327
  var _18 = React.useState(null),
2303
2328
  signatureVideoMetadata = _18[0],
2304
2329
  setSignatureVideoMetadata = _18[1];
2305
- var _19 = React.useState(null),
2306
- idCaptureVideoUrl = _19[0],
2307
- setIdCaptureVideoUrl = _19[1];
2308
- var _20 = React.useState(null),
2309
- idCaptureVideoIdFrontImage = _20[0],
2310
- setIdCaptureVideoIdFrontImage = _20[1];
2330
+ var _19 = React.useState({}),
2331
+ documentFileMetadata = _19[0],
2332
+ setDocumentFileMetadataState = _19[1];
2333
+ var _20 = React.useState([]),
2334
+ barcodeCaptureAttempts = _20[0],
2335
+ setBarcodeCaptureAttempts = _20[1];
2311
2336
  var _21 = React.useState(null),
2312
- idCaptureVideoIdBackImage = _21[0],
2313
- setIdCaptureVideoIdBackImage = _21[1];
2337
+ idCaptureVideoUrl = _21[0],
2338
+ setIdCaptureVideoUrl = _21[1];
2314
2339
  var _22 = React.useState(null),
2315
- idCaptureVideoAudioUrl = _22[0],
2316
- setIdCaptureVideoAudioUrl = _22[1];
2340
+ idCaptureVideoIdFrontImage = _22[0],
2341
+ setIdCaptureVideoIdFrontImage = _22[1];
2317
2342
  var _23 = React.useState(null),
2318
- idCaptureVideoAudioStartsAt = _23[0],
2319
- setIdCaptureVideoAudioStartsAt = _23[1];
2343
+ idCaptureVideoIdBackImage = _23[0],
2344
+ setIdCaptureVideoIdBackImage = _23[1];
2320
2345
  var _24 = React.useState(null),
2321
- expectedAudioText = _24[0],
2322
- setExpectedAudioText = _24[1];
2346
+ idCaptureVideoAudioUrl = _24[0],
2347
+ setIdCaptureVideoAudioUrl = _24[1];
2323
2348
  var _25 = React.useState(null),
2324
- additionalDocuments = _25[0],
2325
- setAdditionalDocuments = _25[1];
2349
+ idCaptureVideoAudioStartsAt = _25[0],
2350
+ setIdCaptureVideoAudioStartsAt = _25[1];
2326
2351
  var _26 = React.useState(null),
2327
- geolocationResult = _26[0],
2328
- setGeolocationResult = _26[1];
2329
- var _27 = React.useState(0),
2330
- geolocationAttempts = _27[0],
2331
- setGeolocationAttempts = _27[1];
2332
- var _28 = React.useState(false),
2333
- geolocationBlocked = _28[0],
2334
- setGeolocationBlocked = _28[1];
2335
- var _29 = React.useState([]),
2336
- idFrontCaptureAttempts = _29[0],
2337
- setIdFrontCaptureAttempts = _29[1];
2338
- var _30 = React.useState([]),
2339
- idBackCaptureAttempts = _30[0],
2340
- setIdBackCaptureAttempts = _30[1];
2352
+ expectedAudioText = _26[0],
2353
+ setExpectedAudioText = _26[1];
2354
+ var _27 = React.useState(null),
2355
+ additionalDocuments = _27[0],
2356
+ setAdditionalDocuments = _27[1];
2357
+ var setDocumentFileMetadata = React.useCallback(function (key, metadata) {
2358
+ var sanitized = metadata ? sanitizeMetadata(metadata) : null;
2359
+ setDocumentFileMetadataState(function (current) {
2360
+ var _a;
2361
+ if (!sanitized) {
2362
+ if (!(key in current)) return current;
2363
+ var next = _assign({}, current);
2364
+ delete next[key];
2365
+ if (key === 'idBarcodeImage') {
2366
+ setBarcodeCaptureAttempts([]);
2367
+ }
2368
+ return next;
2369
+ }
2370
+ return _assign(_assign({}, current), (_a = {}, _a[key] = sanitized, _a));
2371
+ });
2372
+ }, []);
2373
+ var _28 = React.useState(null),
2374
+ geolocationResult = _28[0],
2375
+ setGeolocationResult = _28[1];
2376
+ var _29 = React.useState(0),
2377
+ geolocationAttempts = _29[0],
2378
+ setGeolocationAttempts = _29[1];
2379
+ var _30 = React.useState(false),
2380
+ geolocationBlocked = _30[0],
2381
+ setGeolocationBlocked = _30[1];
2341
2382
  var _31 = React.useState([]),
2342
- selfieCaptureAttempts = _31[0],
2343
- setSelfieCaptureAttempts = _31[1];
2344
- var logIdFrontCaptureAttempt = React.useCallback(function (attempt) {
2383
+ idFrontCaptureAttempts = _31[0],
2384
+ setIdFrontCaptureAttempts = _31[1];
2385
+ var _32 = React.useState([]),
2386
+ idBackCaptureAttempts = _32[0],
2387
+ setIdBackCaptureAttempts = _32[1];
2388
+ var _33 = React.useState([]),
2389
+ selfieCaptureAttempts = _33[0],
2390
+ setSelfieCaptureAttempts = _33[1];
2391
+ var logIdFrontCaptureAttempt = React.useCallback(function (attempt, documentType) {
2345
2392
  setIdFrontCaptureAttempts(function (attempts) {
2346
2393
  return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
2347
2394
  });
2348
- }, []);
2349
- var logIdBackCaptureAttempt = React.useCallback(function (attempt) {
2395
+ var submissionKey = capturedDocumentTypeToSubmissionKey[documentType];
2396
+ if (submissionKey) {
2397
+ setDocumentFileMetadata(submissionKey, {
2398
+ documentType: documentType,
2399
+ documentKey: submissionKey,
2400
+ captureMode: attempt.captureMode,
2401
+ autoCapture: attempt.autoCapture,
2402
+ captureTime: attempt.captureTime,
2403
+ operationTime: attempt.operationTime,
2404
+ bestDetectionScore: attempt.bestDetectionScore,
2405
+ bestFocusScore: attempt.bestFocusScore,
2406
+ bestBarcodeScore: attempt.bestBarcodeScore,
2407
+ boundingBox: attempt.boundingBox
2408
+ });
2409
+ }
2410
+ if (attempt.bestBarcodeScore !== undefined && attempt.bestBarcodeScore !== null) {
2411
+ setBarcodeCaptureAttempts(function (attempts) {
2412
+ return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
2413
+ });
2414
+ setDocumentFileMetadata('idBarcodeImage', {
2415
+ documentType: 'idBarcodeImage',
2416
+ sourceDocumentType: documentType,
2417
+ documentKey: 'idBarcodeImage',
2418
+ bestBarcodeScore: attempt.bestBarcodeScore,
2419
+ captureMode: attempt.captureMode,
2420
+ autoCapture: attempt.autoCapture,
2421
+ captureTime: attempt.captureTime,
2422
+ operationTime: attempt.operationTime
2423
+ });
2424
+ }
2425
+ }, [setDocumentFileMetadata]);
2426
+ var logIdBackCaptureAttempt = React.useCallback(function (attempt, documentType) {
2350
2427
  setIdBackCaptureAttempts(function (attempts) {
2351
2428
  return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
2352
2429
  });
2353
- }, []);
2430
+ var submissionKey = capturedDocumentTypeToSubmissionKey[documentType];
2431
+ if (submissionKey) {
2432
+ setDocumentFileMetadata(submissionKey, {
2433
+ documentType: documentType,
2434
+ documentKey: submissionKey,
2435
+ captureMode: attempt.captureMode,
2436
+ autoCapture: attempt.autoCapture,
2437
+ captureTime: attempt.captureTime,
2438
+ operationTime: attempt.operationTime,
2439
+ bestDetectionScore: attempt.bestDetectionScore,
2440
+ bestFocusScore: attempt.bestFocusScore,
2441
+ bestBarcodeScore: attempt.bestBarcodeScore,
2442
+ boundingBox: attempt.boundingBox
2443
+ });
2444
+ }
2445
+ }, [setDocumentFileMetadata]);
2354
2446
  var logSelfieCaptureAttempt = React.useCallback(function (attempt) {
2355
2447
  setSelfieCaptureAttempts(function (attempts) {
2356
2448
  return __spreadArray(__spreadArray([], attempts, true), [attempt], false);
2357
2449
  });
2358
- }, []);
2450
+ setDocumentFileMetadata('selfieImage', {
2451
+ documentType: 'selfie',
2452
+ documentKey: 'selfieImage',
2453
+ captureMode: attempt.captureMode,
2454
+ autoCapture: attempt.autoCapture,
2455
+ captureTime: attempt.captureTime,
2456
+ operationTime: attempt.operationTime,
2457
+ livenessScore: attempt.livenessScore,
2458
+ bestDetectionScore: attempt.bestDetectionScore,
2459
+ bestFocusScore: attempt.bestFocusScore,
2460
+ boundingBox: attempt.boundingBox
2461
+ });
2462
+ }, [setDocumentFileMetadata]);
2359
2463
  useRevokeObjectUrlOnUnmount(signatureVideoUrl);
2360
2464
  useRevokeObjectUrlOnUnmount(idCaptureVideoUrl);
2361
2465
  useRevokeObjectUrlOnUnmount(idCaptureVideoAudioUrl);
@@ -2505,14 +2609,15 @@
2505
2609
  if (!documentServiceUrl) return [3 /*break*/, 8];
2506
2610
  return [4 /*yield*/, Promise.all(Object.keys(documents).map(function (k) {
2507
2611
  return __awaiter(void 0, void 0, void 0, function () {
2508
- var filetype, metadata, _a, _b;
2612
+ var filetype, metadataSource, metadata, _a, _b;
2509
2613
  return __generator(this, function (_c) {
2510
2614
  switch (_c.label) {
2511
2615
  case 0:
2512
2616
  if (!documents[k]) return [3 /*break*/, 2];
2513
2617
  filetype = k.endsWith('Video') ? 'video/mp4' : k.endsWith('Audio') ? 'audio/mp4' : 'image/jpeg';
2514
- metadata = k === 'signatureVideo' ? {
2515
- filemetadata: JSON.stringify(signatureVideoMetadata)
2618
+ metadataSource = k === 'signatureVideo' && signatureVideoMetadata ? signatureVideoMetadata : documentFileMetadata[k];
2619
+ metadata = metadataSource ? {
2620
+ filemetadata: JSON.stringify(metadataSource)
2516
2621
  } : {};
2517
2622
  _a = documents;
2518
2623
  _b = k;
@@ -2663,7 +2768,8 @@
2663
2768
  selfieCaptureAttempts: selfieCaptureAttempts,
2664
2769
  idFrontCaptureAttempts: idFrontCaptureAttempts,
2665
2770
  idBackCaptureAttempts: idBackCaptureAttempts,
2666
- geolocationResult: geolocationResult
2771
+ geolocationResult: geolocationResult,
2772
+ barcodeCaptureAttempts: barcodeCaptureAttempts
2667
2773
  });
2668
2774
  if (!onBeforeSubmit.current) return [3 /*break*/, 10];
2669
2775
  return [4 /*yield*/, onBeforeSubmit.current(submissionRequest)];
@@ -2676,7 +2782,7 @@
2676
2782
  }
2677
2783
  });
2678
2784
  });
2679
- }, [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]);
2785
+ }, [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]);
2680
2786
  var defaultOnSubmit = React.useCallback(function () {
2681
2787
  return __awaiter(void 0, void 0, void 0, function () {
2682
2788
  var submissionResponse_1, payload, host, endpoint, response, statusMessage, submissionResponse_2, e_1, err;
@@ -2836,7 +2942,8 @@
2836
2942
  selfieCaptureAttempts: selfieCaptureAttempts,
2837
2943
  idFrontCaptureAttempts: idFrontCaptureAttempts,
2838
2944
  idBackCaptureAttempts: idBackCaptureAttempts,
2839
- geolocationResult: geolocationResult
2945
+ geolocationResult: geolocationResult,
2946
+ barcodeCaptureAttempts: barcodeCaptureAttempts
2840
2947
  });
2841
2948
  if (!onBeforeLivenessCheck.current) return [3 /*break*/, 5];
2842
2949
  return [4 /*yield*/, onBeforeLivenessCheck.current(request)];
@@ -2850,7 +2957,7 @@
2850
2957
  }
2851
2958
  });
2852
2959
  });
2853
- }, [clientRequestID, documentServiceUrl, estimateAge, geolocationResult, idBackCaptureAttempts, idCardForFaceMatch, idFrontCaptureAttempts, jobId, predictGender, selfieCaptureAttempts, uploadDocument, useDocumentServiceForLivenessChecks, webhooksStripSpecialCharacters]);
2960
+ }, [clientRequestID, documentServiceUrl, estimateAge, geolocationResult, barcodeCaptureAttempts, idBackCaptureAttempts, idCardForFaceMatch, idFrontCaptureAttempts, jobId, predictGender, selfieCaptureAttempts, uploadDocument, useDocumentServiceForLivenessChecks, webhooksStripSpecialCharacters]);
2854
2961
  var checkLiveness = React.useCallback(function (imageDataUrl) {
2855
2962
  return __awaiter(void 0, void 0, void 0, function () {
2856
2963
  var request, host, endpoint, response, statusMessage, submissionResponse_3, e_2, err;
@@ -2983,6 +3090,7 @@
2983
3090
  setIdCaptureVideoAudioStartsAt: setIdCaptureVideoAudioStartsAt,
2984
3091
  setExpectedAudioText: setExpectedAudioText,
2985
3092
  setAdditionalDocuments: setAdditionalDocuments,
3093
+ setDocumentFileMetadata: setDocumentFileMetadata,
2986
3094
  uploadDocument: uploadDocument,
2987
3095
  logIdFrontCaptureAttempt: logIdFrontCaptureAttempt,
2988
3096
  logIdBackCaptureAttempt: logIdBackCaptureAttempt,
@@ -2991,7 +3099,7 @@
2991
3099
  checkLiveness: checkLiveness,
2992
3100
  retryLocationAccess: retryLocationAccess
2993
3101
  };
2994
- }, [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]);
3102
+ }, [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]);
2995
3103
  return /*#__PURE__*/React.createElement(SubmissionContext.Provider, {
2996
3104
  value: value
2997
3105
  }, geolocationRequired && geolocationBlocked ? ( /*#__PURE__*/React.createElement(GeolocationAccessDeniedOverlay, null)) : children, submissionError && ( /*#__PURE__*/React.createElement(SubmissionErrorOverlay, {
@@ -3055,9 +3163,50 @@
3055
3163
  }
3056
3164
  return 'unknown';
3057
3165
  }
3166
+ var CREATE_UPLOAD_RETRY_DELAYS = [1500, 3000, 6000, 12000];
3167
+ var RETRYABLE_STATUS_CODES = new Set([408, 409, 423]);
3168
+ function shouldRetryTusError(error, retryableMethods) {
3169
+ var _a, _b, _c, _d;
3170
+ if (typeof ProgressEvent !== 'undefined' && error instanceof ProgressEvent) {
3171
+ return true;
3172
+ }
3173
+ if (error instanceof tusJsClient.DetailedError) {
3174
+ var method = void 0;
3175
+ try {
3176
+ method = (_b = (_a = error.originalRequest) === null || _a === void 0 ? void 0 : _a.getMethod) === null || _b === void 0 ? void 0 : _b.call(_a);
3177
+ } catch (requestMethodError) {
3178
+ warn('Unable to read request method from tus error', requestMethodError);
3179
+ return false;
3180
+ }
3181
+ if (method && retryableMethods.length && !retryableMethods.includes(method)) {
3182
+ return false;
3183
+ }
3184
+ var status_1 = (_d = (_c = error.originalResponse) === null || _c === void 0 ? void 0 : _c.getStatus) === null || _d === void 0 ? void 0 : _d.call(_c);
3185
+ if (typeof status_1 === 'number') {
3186
+ if (status_1 >= 500 || RETRYABLE_STATUS_CODES.has(status_1)) {
3187
+ return true;
3188
+ }
3189
+ return false;
3190
+ }
3191
+ return true;
3192
+ }
3193
+ return false;
3194
+ }
3195
+ function shouldRetryCreateRequest(error) {
3196
+ return shouldRetryTusError(error, ['POST']);
3197
+ }
3198
+ function shouldRetryChunkRequest(error) {
3199
+ return shouldRetryTusError(error, ['PATCH', 'POST']);
3200
+ }
3201
+ function normalizeUploadError(error) {
3202
+ if (error instanceof Error) {
3203
+ return error;
3204
+ }
3205
+ return new Error('tus upload failed');
3206
+ }
3058
3207
  function performUpload(_a) {
3059
3208
  return __awaiter(this, arguments, void 0, function (_b) {
3060
- var fingerprint;
3209
+ var fingerprint, headers, maxRetries, attempt, error_1, shouldRetry, normalizedError, finalError;
3061
3210
  var blob = _b.blob,
3062
3211
  endpoint = _b.endpoint,
3063
3212
  sessionId = _b.sessionId,
@@ -3071,70 +3220,126 @@
3071
3220
  return [4 /*yield*/, calculateMd5(blob)];
3072
3221
  case 1:
3073
3222
  fingerprint = _c.sent();
3074
- return [2 /*return*/, new Promise(function (resolve, reject) {
3075
- var documentId;
3076
- var headers = {
3077
- 'X-Session-Id': sessionId
3078
- };
3079
- if (metadata === null || metadata === void 0 ? void 0 : metadata.jobid) headers['X-Job-Id'] = metadata.jobid;
3080
- if (metadata === null || metadata === void 0 ? void 0 : metadata.taskid) headers['X-Task-Id'] = metadata.taskid;
3081
- var upload = createUpload(blob, {
3082
- endpoint: endpoint,
3083
- retryDelays: [0, 1000, 1000, 1000, 3000, 5000, 10000, 20000],
3084
- headers: headers,
3085
- metadata: _assign({
3086
- filetype: blob.type,
3087
- contentType: blob.type,
3088
- fingerprint: fingerprint
3089
- }, metadata || {}),
3090
- onProgress: function onProgress(bytesUploaded, bytesTotal) {
3091
- onDocumentUploadProgress === null || onDocumentUploadProgress === void 0 ? void 0 : onDocumentUploadProgress({
3092
- bytesUploaded: bytesUploaded,
3093
- bytesTotal: bytesTotal,
3094
- percentage: (bytesUploaded / bytesTotal * 100).toFixed(2) + '%',
3095
- metadata: metadata
3096
- });
3097
- },
3098
- onAfterResponse: function onAfterResponse(_req, res) {
3099
- var contentType = res.getHeader('Content-Type');
3100
- if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('application/json'))) return;
3101
- var body = res.getBody();
3102
- if (!body) return;
3103
- try {
3104
- var parsedId = JSON.parse(body).id;
3105
- if (parsedId.startsWith('urn:documentsv1:')) {
3106
- documentId = parsedId;
3107
- }
3108
- } catch (e) {
3109
- warn('Failed to parse documents service response body', e);
3110
- }
3111
- },
3112
- onSuccess: function onSuccess() {
3113
- var _a;
3114
- documentId || (documentId = "urn:documentsv1:".concat(getEnvFromUrl(upload.url), ":").concat((_a = upload.url.split('/files/').pop()) === null || _a === void 0 ? void 0 : _a.split('+').shift()));
3115
- onDocumentUploaded === null || onDocumentUploaded === void 0 ? void 0 : onDocumentUploaded(documentId, metadata);
3116
- resolve(documentId);
3117
- },
3118
- onError: function onError(error) {
3119
- log('Failed because: ' + error);
3120
- onDocumentUploadFailed === null || onDocumentUploadFailed === void 0 ? void 0 : onDocumentUploadFailed(error, metadata);
3121
- reject(error);
3122
- }
3123
- });
3124
- // Check if there are any previous uploads to continue.
3125
- upload.findPreviousUploads().then(function (previousUploads) {
3126
- // Found previous uploads so we select the first one.
3127
- if (previousUploads.length) {
3128
- upload.resumeFromPreviousUpload(previousUploads[0]);
3129
- }
3130
- // Start the upload
3131
- upload.start();
3132
- });
3223
+ headers = {
3224
+ 'X-Session-Id': sessionId
3225
+ };
3226
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.jobid) headers['X-Job-Id'] = metadata.jobid;
3227
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.taskid) headers['X-Task-Id'] = metadata.taskid;
3228
+ maxRetries = CREATE_UPLOAD_RETRY_DELAYS.length;
3229
+ attempt = 0;
3230
+ _c.label = 2;
3231
+ case 2:
3232
+ if (!(attempt <= maxRetries)) return [3 /*break*/, 9];
3233
+ _c.label = 3;
3234
+ case 3:
3235
+ _c.trys.push([3, 5,, 8]);
3236
+ return [4 /*yield*/, startTusUpload({
3237
+ blob: blob,
3238
+ endpoint: endpoint,
3239
+ headers: headers,
3240
+ metadata: metadata,
3241
+ fingerprint: fingerprint,
3242
+ onDocumentUploadProgress: onDocumentUploadProgress,
3243
+ onDocumentUploaded: onDocumentUploaded
3133
3244
  })];
3245
+ case 4:
3246
+ return [2 /*return*/, _c.sent()];
3247
+ case 5:
3248
+ error_1 = _c.sent();
3249
+ shouldRetry = attempt < maxRetries && shouldRetryCreateRequest(error_1);
3250
+ normalizedError = normalizeUploadError(error_1);
3251
+ if (!shouldRetry) return [3 /*break*/, 7];
3252
+ log("Retrying tus upload creation (attempt ".concat(attempt + 2, "/").concat(maxRetries + 1, ") after error: ").concat(normalizedError.message));
3253
+ return [4 /*yield*/, waitFor(CREATE_UPLOAD_RETRY_DELAYS[attempt])];
3254
+ case 6:
3255
+ _c.sent();
3256
+ return [3 /*break*/, 8];
3257
+ case 7:
3258
+ log('Failed because: ' + normalizedError.message);
3259
+ onDocumentUploadFailed === null || onDocumentUploadFailed === void 0 ? void 0 : onDocumentUploadFailed(normalizedError, metadata);
3260
+ throw normalizedError;
3261
+ case 8:
3262
+ attempt++;
3263
+ return [3 /*break*/, 2];
3264
+ case 9:
3265
+ finalError = new Error('tus upload failed after retries');
3266
+ onDocumentUploadFailed === null || onDocumentUploadFailed === void 0 ? void 0 : onDocumentUploadFailed(finalError, metadata);
3267
+ throw finalError;
3134
3268
  }
3135
3269
  });
3136
3270
  });
3137
3271
  }
3272
+ function startTusUpload(_a) {
3273
+ var blob = _a.blob,
3274
+ endpoint = _a.endpoint,
3275
+ headers = _a.headers,
3276
+ metadata = _a.metadata,
3277
+ fingerprint = _a.fingerprint,
3278
+ onDocumentUploadProgress = _a.onDocumentUploadProgress,
3279
+ onDocumentUploaded = _a.onDocumentUploaded;
3280
+ return new Promise(function (resolve, reject) {
3281
+ var documentId;
3282
+ var upload = createUpload(blob, {
3283
+ endpoint: endpoint,
3284
+ retryDelays: [0, 1000, 1000, 1000, 3000, 5000, 10000, 20000],
3285
+ headers: headers,
3286
+ metadata: _assign({
3287
+ filetype: blob.type,
3288
+ contentType: blob.type,
3289
+ fingerprint: fingerprint
3290
+ }, metadata || {}),
3291
+ onProgress: function onProgress(bytesUploaded, bytesTotal) {
3292
+ onDocumentUploadProgress === null || onDocumentUploadProgress === void 0 ? void 0 : onDocumentUploadProgress({
3293
+ bytesUploaded: bytesUploaded,
3294
+ bytesTotal: bytesTotal,
3295
+ percentage: (bytesUploaded / bytesTotal * 100).toFixed(2) + '%',
3296
+ metadata: metadata
3297
+ });
3298
+ },
3299
+ onAfterResponse: function onAfterResponse(_req, res) {
3300
+ var contentType = res.getHeader('Content-Type');
3301
+ if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('application/json'))) return;
3302
+ var body = res.getBody();
3303
+ if (!body) return;
3304
+ try {
3305
+ var parsedId = JSON.parse(body).id;
3306
+ if (parsedId.startsWith('urn:documentsv1:')) {
3307
+ documentId = parsedId;
3308
+ }
3309
+ } catch (e) {
3310
+ warn('Failed to parse documents service response body', e);
3311
+ }
3312
+ },
3313
+ onSuccess: function onSuccess() {
3314
+ var _a;
3315
+ documentId || (documentId = "urn:documentsv1:".concat(getEnvFromUrl(upload.url), ":").concat((_a = upload.url.split('/files/').pop()) === null || _a === void 0 ? void 0 : _a.split('+').shift()));
3316
+ if (!documentId) {
3317
+ reject(new Error('Document upload succeeded but no document id was returned'));
3318
+ return;
3319
+ }
3320
+ void (onDocumentUploaded === null || onDocumentUploaded === void 0 ? void 0 : onDocumentUploaded(documentId, metadata));
3321
+ resolve(documentId);
3322
+ },
3323
+ onError: function onError(error) {
3324
+ reject(error);
3325
+ },
3326
+ onShouldRetry: function onShouldRetry(error) {
3327
+ return shouldRetryChunkRequest(error);
3328
+ }
3329
+ });
3330
+ upload.findPreviousUploads().then(function (previousUploads) {
3331
+ if (previousUploads.length) {
3332
+ upload.resumeFromPreviousUpload(previousUploads[0]);
3333
+ }
3334
+ upload.start();
3335
+ })["catch"](reject);
3336
+ });
3337
+ }
3338
+ function waitFor(ms) {
3339
+ return new Promise(function (resolve) {
3340
+ setTimeout(resolve, ms);
3341
+ });
3342
+ }
3138
3343
  function useSubmissionContext() {
3139
3344
  var context = React.useContext(SubmissionContext);
3140
3345
  if (!context) {
@@ -16209,7 +16414,8 @@
16209
16414
  var capturedDocumentType = documentType;
16210
16415
  setTimeout(function () {
16211
16416
  var _a, _b;
16212
- var captureTime = performance.now() - ((_a = state.captureStartedAt) !== null && _a !== void 0 ? _a : new Date()).getTime();
16417
+ var captureStartedAt = (_a = state.captureStartedAt) === null || _a === void 0 ? void 0 : _a.getTime();
16418
+ var captureTime = captureStartedAt ? Date.now() - captureStartedAt : 0;
16213
16419
  var metadata = {
16214
16420
  autoCapture: 'Y',
16215
16421
  captureTime: captureTime,
@@ -20084,12 +20290,14 @@
20084
20290
  captureState = _a.captureState,
20085
20291
  operationStartedAt = _a.operationStartedAt,
20086
20292
  requestedDocumentType = _a.requestedDocumentType;
20293
+ if (!requestedDocumentType) return;
20294
+ var docType = requestedDocumentType;
20087
20295
  metadata.operationTime = new Date().getTime() - (operationStartedAt !== null && operationStartedAt !== void 0 ? operationStartedAt : new Date()).getTime();
20088
20296
  metadata.captureMode = isFallbackMode ? 'Manual' : captureState === 'uploading' ? 'Upload' : 'Auto';
20089
- if (requestedDocumentType === 'idCardBack') {
20090
- logIdBackCaptureAttempt(metadata);
20297
+ if (docType === 'idCardBack') {
20298
+ logIdBackCaptureAttempt(metadata, docType);
20091
20299
  } else {
20092
- logIdFrontCaptureAttempt(metadata);
20300
+ logIdFrontCaptureAttempt(metadata, docType);
20093
20301
  }
20094
20302
  }, [isFallbackMode, logIdBackCaptureAttempt, logIdFrontCaptureAttempt]);
20095
20303
  React.useEffect(function startModelsWhenCapturing() {
@@ -24371,10 +24579,12 @@
24371
24579
  });
24372
24580
  }
24373
24581
  };
24374
- signatureRecorder.start(250);
24375
- // const interval = setInterval(() => signatureRecorder?.requestData(), 250)
24582
+ signatureRecorder.start();
24583
+ var interval = setInterval(function () {
24584
+ return signatureRecorder === null || signatureRecorder === void 0 ? void 0 : signatureRecorder.requestData();
24585
+ }, 250);
24376
24586
  set({
24377
- // requestDataInterval: interval,
24587
+ requestDataInterval: interval,
24378
24588
  recordingStartRequestedAt: performance.now()
24379
24589
  });
24380
24590
  },
@@ -24442,6 +24652,7 @@
24442
24652
  recordingStopRequestedAt: performance.now(),
24443
24653
  recordingStoppedAt: undefined
24444
24654
  });
24655
+ clearInterval(get().requestDataInterval);
24445
24656
  return [4 /*yield*/, waitForOneMoreChunk()
24446
24657
  // this represents the time that it is safe to release the camera access
24447
24658
  ];
@@ -25257,10 +25468,16 @@
25257
25468
  onCapture === null || onCapture === void 0 ? void 0 : onCapture(imageUrl);
25258
25469
  }, [logCaptureMetadata, onCapture]);
25259
25470
  var onFallbackImageCaptured = React.useCallback(function (imageUrl) {
25471
+ logSelfieCaptureAttempt({
25472
+ autoCapture: 'N',
25473
+ captureMode: 'Upload',
25474
+ captureTime: 0,
25475
+ operationTime: 0
25476
+ });
25260
25477
  setSelfieImage(imageUrl);
25261
25478
  setCaptureState('SUCCESS');
25262
25479
  onCapture === null || onCapture === void 0 ? void 0 : onCapture(imageUrl);
25263
- }, [onCapture, setSelfieImage]);
25480
+ }, [logSelfieCaptureAttempt, onCapture, setSelfieImage]);
25264
25481
  var guidesByRequestState = React.useCallback(function (props) {
25265
25482
  var GuidesComponent = guidesComponent !== null && guidesComponent !== void 0 ? guidesComponent : FaceCaptureGuideOverlay;
25266
25483
  var status = ['IN_PROGRESS', 'CAPTURE_STARTED', 'GUIDANCE_SATISFIED', 'CAPTURED'].includes(captureState) ? 'processing' : ['FAILED', 'ERROR'].includes(captureState) ? 'failure' : 'ready';