@incodetech/core 0.0.0-dev-20260717-8aab9f6d → 0.0.0-dev-20260717-17d23610

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.
Files changed (58) hide show
  1. package/dist/authentication.d.ts +2 -2
  2. package/dist/authentication.esm.js +2 -2
  3. package/dist/{authenticationManager-G-k-13Fe.d.ts → authenticationManager-BCm7eGoK.d.ts} +1 -1
  4. package/dist/{authenticationManager-CCsoE3a3.esm.js → authenticationManager-C5nO8GhV.esm.js} +2 -2
  5. package/dist/{authenticationStateMachine-DfscLUkp.esm.js → authenticationStateMachine-C2Rxpvux.esm.js} +2 -2
  6. package/dist/consent.d.ts +1 -1
  7. package/dist/{consentManager-3Pbtj-RV.d.ts → consentManager-uhDPdU6i.d.ts} +4 -4
  8. package/dist/curp-validation.d.ts +1 -1
  9. package/dist/{curpValidationManager--HSBTwOy.d.ts → curpValidationManager-DRQrbEhj.d.ts} +1 -1
  10. package/dist/{deepsightLoader-Dv4RBBlg.esm.js → deepsightLoader-OXrP5BZB.esm.js} +1 -1
  11. package/dist/document-upload.d.ts +4 -4
  12. package/dist/ekyb.d.ts +1 -1
  13. package/dist/ekyb.esm.js +2 -2
  14. package/dist/{ekybManager-CwzaAdjM.esm.js → ekybManager-CQEK0tV2.esm.js} +1 -1
  15. package/dist/{ekybStateMachine-BOG89tFg.esm.js → ekybStateMachine-Di32xFWm.esm.js} +1 -1
  16. package/dist/extensibility.d.ts +8 -8
  17. package/dist/extensibility.esm.js +6 -6
  18. package/dist/{faceCaptureManagerFactory-BWD3O4Eg.d.ts → faceCaptureManagerFactory-DPf1rRsd.d.ts} +2 -2
  19. package/dist/{faceCaptureManagerFactory-aKmM3ism.esm.js → faceCaptureManagerFactory-DWbsV9Hb.esm.js} +1 -1
  20. package/dist/{faceCaptureSetup-CbLgaydb.esm.js → faceCaptureSetup-D0OgPQ4h.esm.js} +2 -2
  21. package/dist/flow-events.d.ts +1 -1
  22. package/dist/flow.d.ts +2 -2
  23. package/dist/flow.esm.js +1 -1
  24. package/dist/{flowServices-CaH1ElaI.esm.js → flowServices-VcegkvP8.esm.js} +2 -2
  25. package/dist/home.d.ts +1 -1
  26. package/dist/id.d.ts +1 -1
  27. package/dist/id.esm.js +2 -2
  28. package/dist/{idCaptureManager-Cmcwu1iM.d.ts → idCaptureManager-QSB3ejX0.d.ts} +1 -1
  29. package/dist/{idCaptureManager-Cni6kB_4.esm.js → idCaptureManager-qzGxTU-i.esm.js} +1 -1
  30. package/dist/{idCaptureStateMachine-CZWjw6Qa.esm.js → idCaptureStateMachine-5NIUTkyD.esm.js} +5 -5
  31. package/dist/{index-DQ2fdqoI.d.ts → index-Ci9wEPiD.d.ts} +1 -1
  32. package/dist/index.esm.js +1 -1
  33. package/dist/mandatory-consent.d.ts +1 -1
  34. package/dist/{mandatoryConsentManager-Bztc-cm2.d.ts → mandatoryConsentManager-BYyb8A34.d.ts} +5 -5
  35. package/dist/{onDeviceFaceResults-wRyQ24qM.esm.js → onDeviceFaceResults-BCVwIXUb.esm.js} +1 -1
  36. package/dist/personhood.d.ts +1 -1
  37. package/dist/personhood.esm.js +2 -2
  38. package/dist/{recordingService-5by5uVOf.esm.js → recordingService-DmC3aGiF.esm.js} +1 -1
  39. package/dist/selfie.d.ts +3 -3
  40. package/dist/selfie.esm.js +5 -5
  41. package/dist/{selfieUploadService-B4LnSIf6.esm.js → selfieErrorUtils-wgI_IxO1.esm.js} +20 -1
  42. package/dist/{selfieManager-D57f1R4V.esm.js → selfieManager-BpKCOb4e.esm.js} +2 -2
  43. package/dist/{selfieManager-CN8wJ14s.d.ts → selfieManager-Dq9wNlcg.d.ts} +1 -1
  44. package/dist/{selfieStateMachine-nqQV3aNZ.esm.js → selfieStateMachine-O16pT4th.esm.js} +3 -13
  45. package/dist/session-Cc3O3VPK.esm.js +1 -0
  46. package/dist/session.d.ts +1 -1
  47. package/dist/session.esm.js +2 -2
  48. package/dist/{sessionInitializer-CCiF0nzE.esm.js → sessionInitializer-DNt98Rr1.esm.js} +1 -1
  49. package/dist/{setup-DmEcArzU.esm.js → setup-BEpnb0QN.esm.js} +1 -1
  50. package/dist/{types-BnEHzP1K.d.ts → types-BjTTkLmd.d.ts} +1 -1
  51. package/dist/{types-ctqh-iS4.d.ts → types-DMMk51Ec.d.ts} +1 -1
  52. package/dist/video-selfie.d.ts +39 -20
  53. package/dist/video-selfie.esm.js +307 -57
  54. package/dist/wasm.esm.js +1 -1
  55. package/dist/workflow.d.ts +5 -5
  56. package/dist/workflow.esm.js +5 -5
  57. package/package.json +3 -3
  58. package/dist/session-dUSz_co4.esm.js +0 -1
@@ -1,5 +1,5 @@
1
1
  import { t as WasmUtilProvider } from "./WasmUtilProvider-DAshwHhX.esm.js";
2
- import { t as ensureWasmPipelines } from "./setup-DmEcArzU.esm.js";
2
+ import { t as ensureWasmPipelines } from "./setup-BEpnb0QN.esm.js";
3
3
  import { t as BrowserTimerProvider } from "./BrowserTimerProvider-BXhgNxLt.esm.js";
4
4
  import { t as api } from "./api-BDTZNnca.esm.js";
5
5
  import { t as endpoints } from "./endpoints-DLQ0g4-R.esm.js";
@@ -7,10 +7,11 @@ import { c as createManager, o as createActor, r as assign, t as setup } from ".
7
7
  import { n as fromPromise, t as fromCallback } from "./xstate-actors.esm-CtI5S0f4.esm.js";
8
8
  import { t as checkPermission } from "./permissionServices-DwNCUB2I.esm.js";
9
9
  import { i as requestCameraWithFallback, r as requestCameraAccess } from "./camera-BmFEyPP_.esm.js";
10
- import { _ as StreamCanvasProcessingSession, a as encryptSelfieImage, l as startDetection, v as FaceDetectionProvider } from "./onDeviceFaceResults-wRyQ24qM.esm.js";
10
+ import { _ as StreamCanvasProcessingSession, a as encryptSelfieImage, l as startDetection, v as FaceDetectionProvider } from "./onDeviceFaceResults-BCVwIXUb.esm.js";
11
11
  import { n as getBackCameraStream } from "./backCameraStream-Heg6vA1j.esm.js";
12
12
  import { n as getWindowDimensions } from "./getDeviceClass-CeBiEayS.esm.js";
13
- import { n as uploadSelfie, t as processFace } from "./selfieUploadService-B4LnSIf6.esm.js";
13
+ import { t as FACE_ERROR_CODES } from "./types-BN5RPPIZ.esm.js";
14
+ import { i as uploadSelfie, r as processFace, t as getFaceErrorCodeFromUnknown } from "./selfieErrorUtils-wgI_IxO1.esm.js";
14
15
  import { t as StreamCanvasCapture } from "./StreamCanvasCapture-D2XcXCZ4.esm.js";
15
16
  import { n as getSupportedMediaRecorderMimeType } from "./mediaRecorderOptions-BhSZDDNb.esm.js";
16
17
  import { n as resolveVideoSelfieSteps, r as videoSelfieWasmPipelines, t as facingModeForStep } from "./videoSelfieSteps-DHcibfYH.esm.js";
@@ -39,12 +40,6 @@ function isFaceRecognitionMatch(confidence) {
39
40
  if (typeof confidence !== "number") return true;
40
41
  return confidence >= 1;
41
42
  }
42
- /**
43
- * Max selfie capture attempts before the step fails. Each backend rejection
44
- * (e.g. 4077 low quality / liveness) re-arms the pipeline and scans again;
45
- * after this many tries the step rejects. Mirrors V1's `numberOfTries`.
46
- */
47
- const MAX_SELFIE_ATTEMPTS = 3;
48
43
  const SELFIE_SUCCESS_DWELL_MS = 900;
49
44
  /**
50
45
  * How long the ID step holds on the "success" state (green check) after the
@@ -53,6 +48,58 @@ const SELFIE_SUCCESS_DWELL_MS = 900;
53
48
  * IdVideoSelfie success flash.
54
49
  */
55
50
  const ID_SUCCESS_DWELL_MS = 900;
51
+ const SELFIE_VALIDATION_ERROR_CODES = [
52
+ FACE_ERROR_CODES.FACE_OCCLUDED,
53
+ FACE_ERROR_CODES.LIVENESS,
54
+ FACE_ERROR_CODES.BRIGHTNESS,
55
+ FACE_ERROR_CODES.LENSES,
56
+ FACE_ERROR_CODES.MASK,
57
+ FACE_ERROR_CODES.CLOSED_EYES,
58
+ FACE_ERROR_CODES.HEAD_COVER,
59
+ FACE_ERROR_CODES.FACE_NOT_FOUND,
60
+ FACE_ERROR_CODES.MULTIPLE_FACES,
61
+ FACE_ERROR_CODES.TOO_BLURRY,
62
+ FACE_ERROR_CODES.TOO_DARK,
63
+ FACE_ERROR_CODES.USER_IS_NOT_RECOGNIZED,
64
+ FACE_ERROR_CODES.SPOOF_ATTEMPT_DETECTED,
65
+ FACE_ERROR_CODES.FACE_TOO_DARK,
66
+ FACE_ERROR_CODES.LENSES_DETECTED,
67
+ FACE_ERROR_CODES.FACE_MASK_DETECTED,
68
+ FACE_ERROR_CODES.CLOSED_EYES_DETECTED,
69
+ FACE_ERROR_CODES.HEAD_COVER_DETECTED,
70
+ FACE_ERROR_CODES.FACE_CROPPING_FAILED,
71
+ FACE_ERROR_CODES.FACE_TOO_SMALL,
72
+ FACE_ERROR_CODES.FACE_TOO_BLURRY,
73
+ FACE_ERROR_CODES.BAD_PHOTO_QUALITY,
74
+ FACE_ERROR_CODES.SELFIE_IMAGE_LOW_QUALITY
75
+ ];
76
+ const SELFIE_VALIDATION_STATUS_CODES = [
77
+ 3004,
78
+ 3005,
79
+ 3006,
80
+ 3007,
81
+ 4010,
82
+ 4019,
83
+ 4077,
84
+ 4078
85
+ ];
86
+ function getErrorStatus(error) {
87
+ if (typeof error !== "object" || error === null) return;
88
+ if ("data" in error) {
89
+ const data = error.data;
90
+ if (typeof data === "object" && data !== null && "status" in data && typeof data.status === "number") return data.status;
91
+ }
92
+ if ("status" in error && typeof error.status === "number") return error.status;
93
+ }
94
+ function isSelfieValidationError(error) {
95
+ const errorCode = getFaceErrorCodeFromUnknown(error);
96
+ if (errorCode !== void 0 && SELFIE_VALIDATION_ERROR_CODES.includes(errorCode)) return true;
97
+ const status = getErrorStatus(error);
98
+ return status !== void 0 && SELFIE_VALIDATION_STATUS_CODES.includes(status);
99
+ }
100
+ function isIdComparisonValidationError(error) {
101
+ return typeof error === "object" && error !== null && "status" in error && typeof error.status === "number" && error.status > 0;
102
+ }
56
103
  function abortError() {
57
104
  return /* @__PURE__ */ new Error("aborted");
58
105
  }
@@ -189,15 +236,15 @@ async function detectSelfie(params) {
189
236
  if (signal.aborted) onAbort();
190
237
  });
191
238
  try {
192
- for (let attempt = 1; attempt <= MAX_SELFIE_ATTEMPTS; attempt++) try {
193
- await runAttempt();
194
- return;
195
- } catch (error) {
196
- if (signal.aborted || attempt >= MAX_SELFIE_ATTEMPTS) throw error;
197
- onStatus?.("error");
198
- provider.reset();
199
- await delay(1500, signal);
200
- }
239
+ await runAttempt();
240
+ return { outcome: "success" };
241
+ } catch (error) {
242
+ if (signal.aborted || !isSelfieValidationError(error)) throw error;
243
+ onStatus?.("error");
244
+ return {
245
+ outcome: "validationFailed",
246
+ failure: "selfieVerificationFailed"
247
+ };
201
248
  } finally {
202
249
  capturer.dispose();
203
250
  provider.dispose();
@@ -277,16 +324,33 @@ async function detectId(params) {
277
324
  onStatus?.("capturing");
278
325
  (async () => {
279
326
  try {
280
- if (await validateIdFrame(step, config, base64Image)) {
327
+ const result = await validateIdFrame(step, config, base64Image);
328
+ if (result.outcome === "success") {
281
329
  throwIfAborted(signal);
282
330
  onStatus?.("success");
283
331
  await delay(ID_SUCCESS_DWELL_MS, signal);
284
- settle(resolve);
332
+ settle(() => resolve(result));
285
333
  return;
286
334
  }
287
- validating = false;
335
+ onStatus?.("error");
336
+ settle(() => resolve(result));
288
337
  } catch (error) {
289
- settle(() => reject(error instanceof Error ? error : new Error(String(error))));
338
+ if (signal.aborted) {
339
+ settle(() => reject(error instanceof Error ? error : new Error(String(error))));
340
+ return;
341
+ }
342
+ onStatus?.("error");
343
+ if (isIdComparisonValidationError(error)) {
344
+ settle(() => resolve({
345
+ outcome: "validationFailed",
346
+ failure: "idScanFailed"
347
+ }));
348
+ return;
349
+ }
350
+ settle(() => resolve({
351
+ outcome: "retryableFailure",
352
+ failure: "idScanFailed"
353
+ }));
290
354
  }
291
355
  })();
292
356
  }
@@ -301,25 +365,43 @@ async function validateIdFrame(step, config, base64Image) {
301
365
  if (step === "backId") {
302
366
  if (config.compareBackIdEnabled) {
303
367
  const result = await compareVideoSelfieBackId(base64Image);
304
- if (result.idSideMatched === false || result.success === false) return false;
368
+ if (result.idSideMatched === false || result.success === false) return {
369
+ outcome: "validationFailed",
370
+ failure: "idTypeMismatch"
371
+ };
305
372
  }
306
373
  if (config.compareBackOcrEnabled) {
307
- if ((await compareVideoSelfieBackOcr(base64Image)).success === false) return false;
374
+ if ((await compareVideoSelfieBackOcr(base64Image)).success === false) return {
375
+ outcome: "validationFailed",
376
+ failure: "nameVerificationFailed"
377
+ };
308
378
  }
309
- return true;
379
+ return { outcome: "success" };
310
380
  }
311
381
  if (config.compareIdEnabled) {
312
382
  const result = await compareVideoSelfieId(base64Image);
313
- if (result.idTypeMatched === false) return false;
314
- if (typeof result.faceRecognitionConfidence === "number" && !isFaceRecognitionMatch(result.faceRecognitionConfidence)) return false;
383
+ if (result.idTypeMatched === false) return {
384
+ outcome: "validationFailed",
385
+ failure: "idTypeMismatch"
386
+ };
387
+ if (typeof result.faceRecognitionConfidence === "number" && !isFaceRecognitionMatch(result.faceRecognitionConfidence)) return {
388
+ outcome: "validationFailed",
389
+ failure: "photoVerificationFailed"
390
+ };
315
391
  }
316
392
  if (config.compareOcrEnabled) {
317
- if ((await compareVideoSelfieOcr(base64Image)).success === false) return false;
393
+ if ((await compareVideoSelfieOcr(base64Image)).success === false) return {
394
+ outcome: "validationFailed",
395
+ failure: "nameVerificationFailed"
396
+ };
318
397
  }
319
- return true;
398
+ return { outcome: "success" };
320
399
  }
321
400
  //#endregion
322
401
  //#region ../infra/src/media/CameraCompositor.ts
402
+ const MAX_COMPOSITE_LONG_EDGE = 1280;
403
+ const MAX_COMPOSITE_SHORT_EDGE = 720;
404
+ const FRAME_INTERVAL_TOLERANCE_RATIO = .9;
323
405
  /**
324
406
  * Composites the *active* camera into a canvas and exposes the canvas as a
325
407
  * single, stable `MediaStream` to record. Switching cameras (front ↔ back)
@@ -336,11 +418,15 @@ var CameraCompositor = class {
336
418
  this.canvas = null;
337
419
  this.ctx = null;
338
420
  this.video = null;
339
- this.rafId = null;
421
+ this.frameRequestId = null;
422
+ this.frameRequestKind = null;
423
+ this.lastDrawTimeMs = null;
424
+ this.lastVideoTimeSeconds = null;
340
425
  this.audioTrack = null;
341
426
  this.videoTrack = null;
342
427
  this.composite = null;
343
428
  this.fps = options.fps ?? 30;
429
+ this.frameIntervalMs = this.fps > 0 ? 1e3 / this.fps : 0;
344
430
  }
345
431
  /**
346
432
  * Begin compositing `stream` and return the composite stream to record. The
@@ -370,6 +456,7 @@ var CameraCompositor = class {
370
456
  if (!this.composite) return;
371
457
  const previousVideoTrack = this.videoTrack;
372
458
  this.setVideoSource(stream);
459
+ this.startDrawLoop();
373
460
  if (previousVideoTrack) previousVideoTrack.stop();
374
461
  }
375
462
  /** The composite stream being recorded, if compositing is active. */
@@ -378,10 +465,7 @@ var CameraCompositor = class {
378
465
  }
379
466
  /** Stop compositing and release the canvas, audio, and video tracks. */
380
467
  stop() {
381
- if (this.rafId !== null) {
382
- cancelAnimationFrame(this.rafId);
383
- this.rafId = null;
384
- }
468
+ this.cancelDrawLoop();
385
469
  this.videoTrack?.stop();
386
470
  this.audioTrack?.stop();
387
471
  this.composite?.getTracks().forEach((track) => track.stop());
@@ -401,20 +485,56 @@ var CameraCompositor = class {
401
485
  video.play().catch(() => {});
402
486
  }
403
487
  startDrawLoop() {
404
- const draw = () => {
405
- const video = this.video;
406
- const canvas = this.canvas;
407
- const ctx = this.ctx;
408
- if (video && canvas && ctx && video.videoWidth > 0) {
409
- if (canvas.width !== video.videoWidth || canvas.height !== video.videoHeight) {
410
- canvas.width = video.videoWidth;
411
- canvas.height = video.videoHeight;
412
- }
413
- ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
414
- }
415
- this.rafId = requestAnimationFrame(draw);
488
+ this.cancelDrawLoop();
489
+ this.lastDrawTimeMs = null;
490
+ this.lastVideoTimeSeconds = null;
491
+ const draw = (timeMs) => {
492
+ const elapsed = this.lastDrawTimeMs === null ? Infinity : timeMs - this.lastDrawTimeMs;
493
+ if ((this.frameIntervalMs === 0 || elapsed >= this.frameIntervalMs * FRAME_INTERVAL_TOLERANCE_RATIO) && this.drawCurrentFrame()) this.lastDrawTimeMs = timeMs;
494
+ this.scheduleNextFrame(draw);
495
+ };
496
+ this.scheduleNextFrame(draw);
497
+ }
498
+ scheduleNextFrame(callback) {
499
+ const video = this.video;
500
+ if (video && typeof video.requestVideoFrameCallback === "function") {
501
+ this.frameRequestKind = "video";
502
+ this.frameRequestId = video.requestVideoFrameCallback(callback);
503
+ return;
504
+ }
505
+ this.frameRequestKind = "animation";
506
+ this.frameRequestId = requestAnimationFrame(callback);
507
+ }
508
+ cancelDrawLoop() {
509
+ if (this.frameRequestId === null) return;
510
+ if (this.frameRequestKind === "video" && this.video && typeof this.video.cancelVideoFrameCallback === "function") this.video.cancelVideoFrameCallback(this.frameRequestId);
511
+ else cancelAnimationFrame(this.frameRequestId);
512
+ this.frameRequestId = null;
513
+ this.frameRequestKind = null;
514
+ }
515
+ drawCurrentFrame() {
516
+ const video = this.video;
517
+ const canvas = this.canvas;
518
+ const ctx = this.ctx;
519
+ if (!video || !canvas || !ctx || video.videoWidth <= 0) return false;
520
+ if (this.lastVideoTimeSeconds === video.currentTime) return false;
521
+ const dimensions = this.getBoundedDimensions(video.videoWidth, video.videoHeight);
522
+ if (canvas.width !== dimensions.width || canvas.height !== dimensions.height) {
523
+ canvas.width = dimensions.width;
524
+ canvas.height = dimensions.height;
525
+ }
526
+ ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
527
+ this.lastVideoTimeSeconds = video.currentTime;
528
+ return true;
529
+ }
530
+ getBoundedDimensions(width, height) {
531
+ const longEdge = Math.max(width, height);
532
+ const shortEdge = Math.min(width, height);
533
+ const scale = Math.min(1, MAX_COMPOSITE_LONG_EDGE / longEdge, MAX_COMPOSITE_SHORT_EDGE / shortEdge);
534
+ return {
535
+ width: Math.max(1, Math.round(width * scale)),
536
+ height: Math.max(1, Math.round(height * scale))
416
537
  };
417
- this.rafId = requestAnimationFrame(draw);
418
538
  }
419
539
  };
420
540
  //#endregion
@@ -739,9 +859,31 @@ function detectionStatusFromEvent(event) {
739
859
  function detectionErrorFromEvent(event) {
740
860
  return event.error;
741
861
  }
862
+ function validationFailureFromEvent(event) {
863
+ return event.failure;
864
+ }
865
+ function retryableFailureFromEvent(event) {
866
+ return event.failure;
867
+ }
742
868
  const SWITCHING_CAMERA_MIN_DWELL_MS = 3e3;
743
869
  const ID_FLIP_DWELL_MS = 4e3;
744
870
  const FINAL_SUCCESS_DWELL_MS = 3e3;
871
+ const VALIDATION_FEEDBACK_DWELL_MS = 3e3;
872
+ const DEFAULT_ATTEMPTS_PER_STEP = 3;
873
+ const UNLIMITED_ATTEMPTS = -1;
874
+ function normalizeAttempts(attempts) {
875
+ if (attempts === UNLIMITED_ATTEMPTS) return UNLIMITED_ATTEMPTS;
876
+ if (typeof attempts === "number" && attempts > 0) return attempts;
877
+ return DEFAULT_ATTEMPTS_PER_STEP;
878
+ }
879
+ function isIdStep(step) {
880
+ return step === "frontId" || step === "backId";
881
+ }
882
+ function nextModuleIndex(context) {
883
+ let index = context.stepIndex + 1;
884
+ while (isIdStep(context.steps[index])) index += 1;
885
+ return index;
886
+ }
745
887
  function waitForDwell(ms, signal) {
746
888
  const timerProvider = BrowserTimerProvider.getInstance();
747
889
  return new Promise((resolve) => {
@@ -784,7 +926,8 @@ const videoSelfieRecordingSetup = setup({
784
926
  },
785
927
  delays: {
786
928
  ID_FLIP_DWELL: ID_FLIP_DWELL_MS,
787
- FINAL_SUCCESS_DWELL: FINAL_SUCCESS_DWELL_MS
929
+ FINAL_SUCCESS_DWELL: FINAL_SUCCESS_DWELL_MS,
930
+ VALIDATION_FEEDBACK_DWELL: VALIDATION_FEEDBACK_DWELL_MS
788
931
  },
789
932
  actors: {
790
933
  acquireCamera: fromPromise(async ({ input, signal }) => {
@@ -826,7 +969,23 @@ const videoSelfieRecordingSetup = setup({
826
969
  type: "DETECTION_STATUS",
827
970
  status
828
971
  })
829
- }).then(() => sendBack({ type: "DETECTION_DONE" })).catch((err) => {
972
+ }).then((result) => {
973
+ if (result.outcome === "retryableFailure") {
974
+ sendBack({
975
+ type: "RETRYABLE_FAILURE",
976
+ failure: result.failure
977
+ });
978
+ return;
979
+ }
980
+ if (result.outcome === "validationFailed") {
981
+ sendBack({
982
+ type: "VALIDATION_FAILED",
983
+ failure: result.failure
984
+ });
985
+ return;
986
+ }
987
+ sendBack({ type: "DETECTION_DONE" });
988
+ }).catch((err) => {
830
989
  if (!controller.signal.aborted) sendBack({
831
990
  type: "DETECTION_FAILED",
832
991
  error: String(err)
@@ -836,15 +995,45 @@ const videoSelfieRecordingSetup = setup({
836
995
  })
837
996
  },
838
997
  actions: {
839
- advanceStep: assign({ stepIndex: ({ context }) => context.stepIndex + 1 }),
998
+ advanceStep: assign({
999
+ stepIndex: ({ context }) => context.stepIndex + 1,
1000
+ attemptsRemaining: ({ context }) => context.attemptsPerStep,
1001
+ validationFailure: () => void 0
1002
+ }),
1003
+ advancePastIdSection: assign({
1004
+ stepIndex: ({ context }) => nextModuleIndex(context),
1005
+ attemptsRemaining: ({ context }) => context.attemptsPerStep,
1006
+ validationFailure: () => void 0
1007
+ }),
840
1008
  setDetectionStatus: assign({ detectionStatus: ({ event }) => detectionStatusFromEvent(event) }),
841
1009
  setDetectionError: assign({ detectionError: ({ event }) => detectionErrorFromEvent(event) }),
1010
+ setValidationFailure: assign(({ context, event }) => ({
1011
+ attemptsRemaining: context.attemptsRemaining === UNLIMITED_ATTEMPTS ? UNLIMITED_ATTEMPTS : Math.max(0, context.attemptsRemaining - 1),
1012
+ validationFailure: validationFailureFromEvent(event),
1013
+ detectionStatus: "error"
1014
+ })),
1015
+ setUncountedRetryableFailure: assign(({ event }) => ({
1016
+ validationFailure: retryableFailureFromEvent(event),
1017
+ detectionStatus: "error"
1018
+ })),
842
1019
  setErrorFromDetection: assign({ error: ({ event }) => detectionErrorFromEvent(event) }),
843
1020
  clearDetectionFeedback: assign({
844
1021
  detectionStatus: () => void 0,
845
- detectionError: () => void 0
1022
+ detectionError: () => void 0,
1023
+ validationFailure: () => void 0
846
1024
  }),
847
1025
  setUploadFailedError: assign({ error: () => "Video upload failed" }),
1026
+ resetSession: assign(({ context }) => ({
1027
+ stepIndex: 0,
1028
+ stream: void 0,
1029
+ composite: void 0,
1030
+ detectionStatus: void 0,
1031
+ detectionError: void 0,
1032
+ validationFailure: void 0,
1033
+ attemptsRemaining: context.attemptsPerStep,
1034
+ recordingId: null,
1035
+ error: void 0
1036
+ })),
848
1037
  cleanup: ({ context }) => {
849
1038
  context.service.cleanup();
850
1039
  context.compositor.stop();
@@ -853,7 +1042,14 @@ const videoSelfieRecordingSetup = setup({
853
1042
  },
854
1043
  guards: {
855
1044
  isLastStep: ({ context }) => context.stepIndex >= context.steps.length - 1,
1045
+ hasAttemptsRemaining: ({ context }) => context.attemptsRemaining === UNLIMITED_ATTEMPTS || context.attemptsRemaining > 0,
856
1046
  nextStepFlipsId: ({ context }) => context.steps[context.stepIndex] === "frontId" && context.steps[context.stepIndex + 1] === "backId",
1047
+ exhaustedIdFinishes: ({ context }) => isIdStep(context.steps[context.stepIndex]) && nextModuleIndex(context) >= context.steps.length,
1048
+ nextModuleFlipsCamera: ({ context }) => isIdStep(context.steps[context.stepIndex]) && facingModeForStep(context.steps[context.stepIndex]) !== facingModeForStep(context.steps[nextModuleIndex(context)]),
1049
+ isIdExhaustion: ({ context }) => isIdStep(context.steps[context.stepIndex]),
1050
+ exhaustedNonIdFinishes: ({ context }) => !isIdStep(context.steps[context.stepIndex]) && context.stepIndex >= context.steps.length - 1,
1051
+ exhaustedNonIdNextStepFlipsCamera: ({ context }) => !isIdStep(context.steps[context.stepIndex]) && facingModeForStep(context.steps[context.stepIndex]) !== facingModeForStep(context.steps[context.stepIndex + 1]),
1052
+ isNonIdExhaustion: ({ context }) => !isIdStep(context.steps[context.stepIndex]),
857
1053
  nextStepFlipsCamera: ({ context }) => facingModeForStep(context.steps[context.stepIndex]) !== facingModeForStep(context.steps[context.stepIndex + 1]),
858
1054
  uploadReturnedNoRecordingId: ({ event }) => recordingIdFromEvent(event) === null
859
1055
  }
@@ -892,6 +1088,9 @@ const videoSelfieRecordingMachine = videoSelfieRecordingSetup.createMachine({
892
1088
  composite: void 0,
893
1089
  detectionStatus: void 0,
894
1090
  detectionError: void 0,
1091
+ validationFailure: void 0,
1092
+ attemptsPerStep: normalizeAttempts(input.attemptsPerStep),
1093
+ attemptsRemaining: normalizeAttempts(input.attemptsPerStep),
895
1094
  recordingId: null,
896
1095
  error: void 0,
897
1096
  switchingCameraMinDwellMs: input.dependencies?.switchingCameraMinDwellMs ?? SWITCHING_CAMERA_MIN_DWELL_MS
@@ -946,12 +1145,55 @@ const videoSelfieRecordingMachine = videoSelfieRecordingSetup.createMachine({
946
1145
  DETECTION_STATUS: { actions: "setDetectionStatus" },
947
1146
  DETECTION_DONE: ADVANCE_TRANSITIONS,
948
1147
  NEXT_STEP: ADVANCE_TRANSITIONS,
1148
+ VALIDATION_FAILED: {
1149
+ target: "validationFeedback",
1150
+ actions: "setValidationFailure"
1151
+ },
1152
+ RETRYABLE_FAILURE: {
1153
+ target: "validationFeedback",
1154
+ actions: "setUncountedRetryableFailure"
1155
+ },
949
1156
  DETECTION_FAILED: {
950
1157
  target: "error",
951
1158
  actions: "setErrorFromDetection"
952
1159
  }
953
1160
  }
954
1161
  },
1162
+ validationFeedback: { after: { VALIDATION_FEEDBACK_DWELL: [{
1163
+ target: "recording",
1164
+ guard: "hasAttemptsRemaining"
1165
+ }, ...[
1166
+ {
1167
+ target: "finalizing",
1168
+ guard: "exhaustedIdFinishes"
1169
+ },
1170
+ {
1171
+ target: "switchingCamera",
1172
+ guard: "nextModuleFlipsCamera",
1173
+ actions: "advancePastIdSection"
1174
+ },
1175
+ {
1176
+ target: "recording",
1177
+ reenter: true,
1178
+ guard: "isIdExhaustion",
1179
+ actions: "advancePastIdSection"
1180
+ },
1181
+ {
1182
+ target: "finalizing",
1183
+ guard: "exhaustedNonIdFinishes"
1184
+ },
1185
+ {
1186
+ target: "switchingCamera",
1187
+ guard: "exhaustedNonIdNextStepFlipsCamera",
1188
+ actions: "advanceStep"
1189
+ },
1190
+ {
1191
+ target: "recording",
1192
+ reenter: true,
1193
+ guard: "isNonIdExhaustion",
1194
+ actions: "advanceStep"
1195
+ }
1196
+ ]] } },
955
1197
  flippingId: {
956
1198
  after: { ID_FLIP_DWELL: {
957
1199
  target: "recording",
@@ -1002,8 +1244,11 @@ const videoSelfieRecordingMachine = videoSelfieRecordingSetup.createMachine({
1002
1244
  },
1003
1245
  finished: { type: "final" },
1004
1246
  error: {
1005
- type: "final",
1006
- entry: "cleanup"
1247
+ entry: "cleanup",
1248
+ on: { RETRY: {
1249
+ target: "acquiringCamera",
1250
+ actions: "resetSession"
1251
+ } }
1007
1252
  },
1008
1253
  aborted: {
1009
1254
  type: "final",
@@ -1018,6 +1263,7 @@ function createVideoSelfieRecordingActor(options = {}) {
1018
1263
  const detect = options.dependencies?.detect ?? (config ? createDefaultStepDetector(config, { getWasmUtil: () => WasmUtilProvider.getInstance() }) : void 0);
1019
1264
  return createActor(videoSelfieRecordingMachine, { input: {
1020
1265
  steps: config ? resolveVideoSelfieSteps(config) : void 0,
1266
+ attemptsPerStep: config?.numberOfTries,
1021
1267
  dependencies: {
1022
1268
  ...options.dependencies,
1023
1269
  detect
@@ -1040,6 +1286,8 @@ function mapState(snapshot) {
1040
1286
  stream: context.stream,
1041
1287
  composite: context.composite,
1042
1288
  detectionStatus: context.detectionStatus,
1289
+ validationFailure: context.validationFailure,
1290
+ attemptsRemaining: context.attemptsRemaining,
1043
1291
  recordingId: context.recordingId,
1044
1292
  error: context.error
1045
1293
  };
@@ -1050,6 +1298,9 @@ function createApi({ actor }) {
1050
1298
  start() {
1051
1299
  actor.send({ type: "START" });
1052
1300
  },
1301
+ retry() {
1302
+ actor.send({ type: "RETRY" });
1303
+ },
1053
1304
  /**
1054
1305
  * Advance to the next step. Switches the camera when the next step's
1055
1306
  * facing mode differs; finalizes the upload on the last step.
@@ -1567,10 +1818,9 @@ function createConsentRecorder() {
1567
1818
  * it starts in a non-final `running` state and never transitions, so the
1568
1819
  * orchestrated flow stays in `runningModule` until the UI advances it.
1569
1820
  *
1570
- * **Completion contract:** the L2 `incode-video-selfie` web component MUST call
1571
- * `flowManager.completeModule()` once the recording manager reaches `finished`
1572
- * (success) or `error` (terminal failure). Until that event is sent, the flow
1573
- * orchestrator remains in `runningModule` — this is intentional.
1821
+ * **Completion contract:** the L2 `incode-video-selfie` web component calls
1822
+ * `flowManager.completeModule()` once the recording manager reaches `finished`.
1823
+ * Recoverable errors stay inside the module until the user retries.
1574
1824
  *
1575
1825
  * **Abort / unmount:** if the user closes the module or the web component
1576
1826
  * unmounts before completion, the orchestrated flow manager's existing close /
package/dist/wasm.esm.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import { i as warmupWasm } from "./WasmUtilProvider-DAshwHhX.esm.js";
2
- import { a as setWasmConfig, c as DEFAULT_WASM_VERSION, d as resolveWasmConfig, l as buildDefaultWasmConfig, n as initializeWasmUtil, s as upgradeToWasmHttpClient, t as ensureWasmPipelines, u as buildWasmConfigFromBasePath } from "./setup-DmEcArzU.esm.js";
2
+ import { a as setWasmConfig, c as DEFAULT_WASM_VERSION, d as resolveWasmConfig, l as buildDefaultWasmConfig, n as initializeWasmUtil, s as upgradeToWasmHttpClient, t as ensureWasmPipelines, u as buildWasmConfigFromBasePath } from "./setup-BEpnb0QN.esm.js";
3
3
  export { DEFAULT_WASM_VERSION, buildDefaultWasmConfig, buildWasmConfigFromBasePath, ensureWasmPipelines, initializeWasmUtil, resolveWasmConfig, setWasmConfig, upgradeToWasmHttpClient, warmupWasm };
@@ -3,7 +3,7 @@ import { t as CallbackActorLogic } from "./callback-645_omgz.js";
3
3
  import "./StateMachine-EDpYWy0i.js";
4
4
  import { t as Manager } from "./Manager-CQQ99QOI.js";
5
5
  import { a as TotalScore, i as GetTotalScoreStatusFn, n as FinishStatus, r as GetFinishStatusFn } from "./flowCompletionService-BlAHsKyv.js";
6
- import { o as FlowEventSubscribable } from "./index-DQ2fdqoI.js";
6
+ import { o as FlowEventSubscribable } from "./index-Ci9wEPiD.js";
7
7
  import { a as WorkflowModuleRegistry, i as RunChildModuleInput, r as RunChildModuleEvent, t as ModuleConfigMappers } from "./types-BfgmV7s7.js";
8
8
  //#region src/modules/workflow/types.d.ts
9
9
  /** Possible node types returned by the workflow server. */
@@ -320,10 +320,6 @@ declare const workflowMachine: StateMachine<WorkflowContext, {
320
320
  id: string | undefined;
321
321
  };
322
322
  }>, Values<{
323
- setError: {
324
- type: "setError";
325
- params: NonReducibleUnknown;
326
- };
327
323
  setLoadingResult: {
328
324
  type: "setLoadingResult";
329
325
  params: NonReducibleUnknown;
@@ -352,6 +348,10 @@ declare const workflowMachine: StateMachine<WorkflowContext, {
352
348
  type: "setFinishStatusFailed";
353
349
  params: NonReducibleUnknown;
354
350
  };
351
+ setError: {
352
+ type: "setError";
353
+ params: NonReducibleUnknown;
354
+ };
355
355
  setModuleError: {
356
356
  type: "setModuleError";
357
357
  params: NonReducibleUnknown;
@@ -2,25 +2,25 @@ import { g as updateFeatureManagementUser } from "./feature-management-Dw96qEMs.
2
2
  import { t as api } from "./api-BDTZNnca.esm.js";
3
3
  import { m as addEvent, n as eventModuleNames, o as createManagerInstrumentation } from "./events-Dy8PyVO5.esm.js";
4
4
  import { t as endpoints } from "./endpoints-DLQ0g4-R.esm.js";
5
- import { i as initializeSession, r as getSessionFingerprintResult } from "./sessionInitializer-CCiF0nzE.esm.js";
5
+ import { i as initializeSession, r as getSessionFingerprintResult } from "./sessionInitializer-DNt98Rr1.esm.js";
6
6
  import { c as createManager, o as createActor, r as assign, t as setup } from "./xstate.esm-Cf4e0Cfd.esm.js";
7
7
  import { n as fromPromise } from "./xstate-actors.esm-CtI5S0f4.esm.js";
8
8
  import { r as toIncodeApiError } from "./apiError-B-PkYxln.esm.js";
9
9
  import { n as electronicSignatureMachine } from "./electronicSignatureManager-Ty1oUQ8W.esm.js";
10
10
  import "./ae-signature.esm.js";
11
11
  import { t as antifraudMachine } from "./antifraudStateMachine-Bf-IiCq7.esm.js";
12
- import { t as authenticationMachine } from "./authenticationStateMachine-DfscLUkp.esm.js";
12
+ import { t as authenticationMachine } from "./authenticationStateMachine-C2Rxpvux.esm.js";
13
13
  import { t as certificateIssuanceMachine } from "./certificateIssuanceStateMachine-Ce568YfR.esm.js";
14
14
  import { t as consentMachine } from "./consentStateMachine-Pc3Ez3mV.esm.js";
15
15
  import { t as curpValidationMachine } from "./curpValidationStateMachine-7i3TD8J2.esm.js";
16
16
  import { t as customWatchlistMachine } from "./customWatchlistStateMachine-D23XTxl2.esm.js";
17
17
  import { t as documentCaptureMachine } from "./documentCaptureStateMachine-qgsrlcVh.esm.js";
18
18
  import { t as dynamicFormsMachine } from "./dynamicFormsStateMachine-kajUEkCO.esm.js";
19
- import { n as toEkybConfig, t as ekybMachine } from "./ekybStateMachine-BOG89tFg.esm.js";
19
+ import { n as toEkybConfig, t as ekybMachine } from "./ekybStateMachine-Di32xFWm.esm.js";
20
20
  import { n as toEkycConfig, t as ekycMachine } from "./ekycStateMachine-a7oP-XWo.esm.js";
21
21
  import { t as emailMachine } from "./emailStateMachine-ChNwY22u.esm.js";
22
- import { t as selfieMachine } from "./selfieStateMachine-nqQV3aNZ.esm.js";
23
- import { t as idCaptureMachine } from "./idCaptureStateMachine-CZWjw6Qa.esm.js";
22
+ import { t as selfieMachine } from "./selfieStateMachine-O16pT4th.esm.js";
23
+ import { t as idCaptureMachine } from "./idCaptureStateMachine-5NIUTkyD.esm.js";
24
24
  import { t as phoneMachine } from "./phoneStateMachine-wDQtaT38.esm.js";
25
25
  import { n as identityReuseMachine } from "./identityReuseStateMachine-CM45EBrb.esm.js";
26
26
  import { t as mandatoryConsentMachine } from "./mandatoryConsentStateMachine-BN4Obfl7.esm.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@incodetech/core",
3
- "version": "0.0.0-dev-20260717-8aab9f6d",
3
+ "version": "0.0.0-dev-20260717-17d23610",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/IncodeTechnologies/incode-web-sdk.git"
@@ -281,8 +281,8 @@
281
281
  "tsdown": "^0.22.8",
282
282
  "typescript": "^5.9.3",
283
283
  "vitest": "4.1.4",
284
- "@incodetech/config": "1.0.2",
285
- "@incodetech/infra": "1.2.0"
284
+ "@incodetech/infra": "1.2.0",
285
+ "@incodetech/config": "1.0.2"
286
286
  },
287
287
  "scripts": {
288
288
  "build": "tsdown -c tsdown.config.ts",
@@ -1 +0,0 @@
1
- import "./sessionInitializer-CCiF0nzE.esm.js";