@incodetech/core 0.0.0-dev-20260804-177eb012 → 0.0.0-dev-20260804-aaf46585

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 (62) hide show
  1. package/dist/ae-signature.esm.js +1 -1
  2. package/dist/{apiError-qp8Z828t.esm.js → apiError-eRypMxcU.esm.js} +1 -1
  3. package/dist/authentication.esm.js +2 -2
  4. package/dist/{authenticationManager-BzFhg9yK.esm.js → authenticationManager-DzPHEt-8.esm.js} +2 -2
  5. package/dist/{authenticationStateMachine-C8KY3BQH.esm.js → authenticationStateMachine-B7tJiWTU.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/{deepsightLoader-Cdth1XqO.esm.js → deepsightLoader-DL7Y2GDJ.esm.js} +3 -3
  9. package/dist/document-capture.d.ts +1 -1
  10. package/dist/document-upload.d.ts +4 -4
  11. package/dist/{documentCaptureManager-B-J1lXcH.d.ts → documentCaptureManager-pEqMY_Oo.d.ts} +4 -4
  12. package/dist/dynamic-forms.esm.js +2 -2
  13. package/dist/{dynamicFormsManager-ByUTzSNY.esm.js → dynamicFormsManager-BooCrMaK.esm.js} +1 -1
  14. package/dist/{dynamicFormsStateMachine-YkxwkKk_.esm.js → dynamicFormsStateMachine-Bjn28VPz.esm.js} +1 -1
  15. package/dist/ekyb.esm.js +3 -3
  16. package/dist/{ekybManager-C5YFZvpX.esm.js → ekybManager-h28g_Xtv.esm.js} +1 -1
  17. package/dist/{ekybStateMachine-xKI3fmbD.esm.js → ekybStateMachine-bnK91htx.esm.js} +1 -1
  18. package/dist/electronic-signature.esm.js +1 -1
  19. package/dist/{electronicSignatureManager-CRsn7IrI.esm.js → electronicSignatureManager-k8eOulTu.esm.js} +1 -1
  20. package/dist/extensibility.d.ts +3 -3
  21. package/dist/extensibility.esm.js +9 -9
  22. package/dist/{faceCaptureManagerFactory-CYmsy-tv.esm.js → faceCaptureManagerFactory-XgV9yjtn.esm.js} +1 -1
  23. package/dist/{faceCaptureSetup-fbtI2WfQ.esm.js → faceCaptureSetup-CVS6IhMo.esm.js} +2 -2
  24. package/dist/flow.esm.js +3 -3
  25. package/dist/{flowCompletionService-C96XV7wT.esm.js → flowCompletionService-B66s2grx.esm.js} +1 -1
  26. package/dist/{flowServices-C4_82oGS.esm.js → flowServices-Dqeralkm.esm.js} +3 -3
  27. package/dist/geolocation.esm.js +2 -2
  28. package/dist/{geolocationManager-DMdsIldY.esm.js → geolocationManager-Ci0ZCKr6.esm.js} +1 -1
  29. package/dist/{geolocationStateMachine-WOe8_QgL.esm.js → geolocationStateMachine-j-nPXT5l.esm.js} +1 -1
  30. package/dist/id-selfie-flow.d.ts +1 -1
  31. package/dist/id-selfie-flow.esm.js +7 -7
  32. package/dist/id.esm.js +3 -3
  33. package/dist/{idCaptureManager-BIJo891d.esm.js → idCaptureManager-DCdBkzIB.esm.js} +1 -1
  34. package/dist/{idCaptureServices-acrkNUTH.esm.js → idCaptureServices-pFRvnFdd.esm.js} +2 -2
  35. package/dist/{idCaptureStateMachine-CoX_o4MR.esm.js → idCaptureStateMachine-BPZDytNe.esm.js} +7 -7
  36. package/dist/index.esm.js +1 -1
  37. package/dist/mandatory-consent.d.ts +1 -1
  38. package/dist/{mandatoryConsentManager-DyPzUmsZ.d.ts → mandatoryConsentManager-B29kR0XA.d.ts} +4 -4
  39. package/dist/{onDeviceFaceResults-CrSi9d8M.esm.js → onDeviceFaceResults-DzrHstja.esm.js} +3 -3
  40. package/dist/personhood.esm.js +3 -3
  41. package/dist/qe-signature.esm.js +1 -1
  42. package/dist/{recordingService-w-84scs6.esm.js → recordingService-DvWs45V_.esm.js} +1 -1
  43. package/dist/{runChildModule-B7TdhdJh.esm.js → runChildModule-BnlwDAAF.esm.js} +1 -1
  44. package/dist/selfie.esm.js +5 -5
  45. package/dist/{selfieErrorUtils-DggLa9pg.esm.js → selfieErrorUtils-EEHiYwTi.esm.js} +11 -2
  46. package/dist/{selfieManager-BjzolRxU.esm.js → selfieManager-hCzyzJU_.esm.js} +2 -2
  47. package/dist/{selfieStateMachine-CJkfG2Ed.esm.js → selfieStateMachine-bPv7LlHS.esm.js} +3 -3
  48. package/dist/{session-CiObMfq3.esm.js → session-DtiTFOeb.esm.js} +4 -4
  49. package/dist/session.esm.js +4 -4
  50. package/dist/{sessionInitializer-B2LGDRyB.esm.js → sessionInitializer-67b35_K1.esm.js} +2 -2
  51. package/dist/{setup-EktXQNTl.esm.js → setup-Ba31IGP9.esm.js} +12 -10
  52. package/dist/trueSight-C5D_RAuu.esm.js +1 -0
  53. package/dist/{trueSightService-JQYBE_kV.esm.js → trueSightService-CAM-jmTL.esm.js} +1 -1
  54. package/dist/video-selfie.d.ts +34 -10
  55. package/dist/video-selfie.esm.js +280 -64
  56. package/dist/{videoSelfieCameraWarmer-DyDChaVU.esm.js → videoSelfieCameraWarmer-BdfteLhE.esm.js} +49 -12
  57. package/dist/{videoSelfieStepDetector-144x423X.d.ts → videoSelfieStepDetector-OoiAbUo2.d.ts} +8 -2
  58. package/dist/wasm.esm.js +1 -1
  59. package/dist/workflow.d.ts +4 -4
  60. package/dist/workflow.esm.js +14 -14
  61. package/package.json +3 -3
  62. package/dist/trueSight-mqjLK_4M.esm.js +0 -1
@@ -1,35 +1,37 @@
1
1
  import { r as WasmUtilProvider } from "./safeStorage-Ep56I-f_.esm.js";
2
- import { c as abortVideoSelfieUpload, d as uploadVideoSelfiePart, l as completeVideoSelfieUpload, t as ensureWasmPipelines, u as initiateVideoSelfieUpload } from "./setup-EktXQNTl.esm.js";
2
+ import { c as abortVideoSelfieUpload, d as uploadVideoSelfiePart, l as completeVideoSelfieUpload, t as ensureWasmPipelines, u as initiateVideoSelfieUpload } from "./setup-Ba31IGP9.esm.js";
3
3
  import { t as BrowserTimerProvider } from "./BrowserTimerProvider-BXhgNxLt.esm.js";
4
4
  import { t as api } from "./api-Bx3gKW_y.esm.js";
5
5
  import { t as endpoints } from "./endpoints-CCzL3XD_.esm.js";
6
- import { d as videoSelfieWasmPipelines, l as facingModeForStep, u as resolveVideoSelfieSteps } from "./flowServices-C4_82oGS.esm.js";
6
+ import { d as videoSelfieWasmPipelines, l as facingModeForStep, u as resolveVideoSelfieSteps } from "./flowServices-Dqeralkm.esm.js";
7
7
  import { c as createManager, o as createActor, r as assign, t as setup } from "./xstate.esm-Cf4e0Cfd.esm.js";
8
8
  import { n as fromPromise, t as fromCallback } from "./xstate-actors.esm-CtI5S0f4.esm.js";
9
9
  import { n as getSupportedMediaRecorderMimeType } from "./mediaRecorderOptions-CUsftWlH.esm.js";
10
- import { i as createDefaultStepDetector, n as defaultAcquireCamera, r as CameraCompositor, t as createVideoSelfieCameraWarmer } from "./videoSelfieCameraWarmer-DyDChaVU.esm.js";
10
+ import { i as createDefaultStepDetector, n as defaultAcquireCamera, o as isConnectionError, r as CameraCompositor, t as createVideoSelfieCameraWarmer } from "./videoSelfieCameraWarmer-BdfteLhE.esm.js";
11
11
  //#region ../infra/src/providers/browser/MultipartRecordingProvider.ts
12
12
  /**
13
- * S3 multipart requires every part except the last to be at least 5 MB, so we
14
- * buffer recorded data until it crosses this threshold before emitting a part.
15
- */
16
- const MIN_PART_SIZE_BYTES = 5 * 1024 * 1024;
17
- /**
18
13
  * How often `MediaRecorder` hands us buffered data (incremental blobs).
14
+ * 500 ms keeps each blob — and therefore each upload chunk — small: less
15
+ * tail lost when a session is interrupted, and a smaller first blob (init
16
+ * header + keyframe), which is the largest and most timeout-prone chunk.
17
+ * Not lower: request rate doubles per halving, and browsers stop honoring
18
+ * very small timeslices reliably.
19
19
  */
20
- const TIMESLICE_MS = 1e3;
20
+ const TIMESLICE_MS = 500;
21
21
  /**
22
22
  * Encoder target for the full video-selfie session. Higher than the
23
- * short-clip liveness path (0.5–1 Mbps) so a multi-minute session keeps usable
24
- * quality and accumulates past the 5 MB part threshold instead of compressing a
25
- * near-static face down to a single sub-5 MB part. It's a ceiling — a still
26
- * scene still encodes well below it.
23
+ * short-clip liveness path (0.5–1 Mbps) so a multi-minute session keeps
24
+ * usable quality. It's a ceiling — a still scene still encodes well below it.
27
25
  */
28
26
  const VIDEO_BITS_PER_SECOND = 25e5;
29
27
  /**
30
- * Records a stream and streams it out as size-bounded parts for S3 multipart
31
- * upload. Parts are emitted during recording (not buffered to the end), so the
32
- * client never holds more than ~one part in memory regardless of video length.
28
+ * Records a stream and emits every `MediaRecorder` timeslice blob as its own
29
+ * part, in order. Each blob is a whole container fragment (WebM cluster /
30
+ * fMP4 `moof`+`mdat`), which is the property the video-selfie-service's
31
+ * gap-splicing depends on — parts must never cut a fragment at a byte
32
+ * offset. The service stages sub-5 MiB chunks and combines them server-side,
33
+ * so emitting the smallest whole-fragment unit (~0.5 s of video) maximizes
34
+ * what an interrupted session can salvage.
33
35
  *
34
36
  * Unlike the short-clip liveness recorder, this does NOT auto-pause on
35
37
  * `visibilitychange`: a video-selfie session must record continuously, and a
@@ -43,8 +45,6 @@ var MultipartRecordingProvider = class {
43
45
  this._hasError = false;
44
46
  this._error = null;
45
47
  this.mimeType = "";
46
- this.buffer = [];
47
- this.bufferedBytes = 0;
48
48
  this.partNumber = 0;
49
49
  this.onPart = null;
50
50
  }
@@ -59,8 +59,6 @@ var MultipartRecordingProvider = class {
59
59
  }
60
60
  startRecording(stream, onPart) {
61
61
  this.reset();
62
- this.buffer = [];
63
- this.bufferedBytes = 0;
64
62
  this.partNumber = 0;
65
63
  this.onPart = onPart;
66
64
  try {
@@ -70,10 +68,12 @@ var MultipartRecordingProvider = class {
70
68
  videoBitsPerSecond: VIDEO_BITS_PER_SECOND
71
69
  });
72
70
  recorder.ondataavailable = (event) => {
73
- if (event.data.size > 0) {
74
- this.buffer.push(event.data);
75
- this.bufferedBytes += event.data.size;
76
- if (this.bufferedBytes >= MIN_PART_SIZE_BYTES) this.flushPart();
71
+ if (event.data.size > 0 && this.onPart) {
72
+ this.partNumber += 1;
73
+ this.onPart({
74
+ chunk: event.data,
75
+ partNumber: this.partNumber
76
+ });
77
77
  }
78
78
  };
79
79
  recorder.onerror = (event) => {
@@ -98,7 +98,6 @@ var MultipartRecordingProvider = class {
98
98
  return new Promise((resolve) => {
99
99
  if (recorder && this._isRecording) {
100
100
  recorder.onstop = () => {
101
- this.flushPart();
102
101
  resolve();
103
102
  };
104
103
  recorder.stop();
@@ -118,26 +117,214 @@ var MultipartRecordingProvider = class {
118
117
  this.mediaRecorder = null;
119
118
  }
120
119
  this.onPart = null;
121
- this.buffer = [];
122
- this.bufferedBytes = 0;
123
120
  this._isRecording = false;
124
121
  this._error = null;
125
122
  this._hasError = false;
126
123
  }
127
- flushPart() {
128
- if (this.bufferedBytes === 0 || !this.onPart) return;
129
- const chunk = new Blob(this.buffer, { type: this.mimeType });
130
- this.partNumber += 1;
131
- this.onPart({
124
+ };
125
+ //#endregion
126
+ //#region ../infra/src/providers/browser/BrowserNetworkStatusProvider.ts
127
+ var BrowserNetworkStatusProvider = class {
128
+ onOnline(listener) {
129
+ if (typeof window === "undefined" || typeof window.addEventListener !== "function") return () => {};
130
+ window.addEventListener("online", listener);
131
+ return () => {
132
+ window.removeEventListener("online", listener);
133
+ };
134
+ }
135
+ };
136
+ //#endregion
137
+ //#region src/internal/recordings/videoSelfieChunkUploader.ts
138
+ /**
139
+ * How many part uploads run concurrently. The service allows 10 rps with a
140
+ * burst of 30 per session; a real recorder emits ~2 chunks/s, so this cap
141
+ * only matters when a backlog is draining after a network stall.
142
+ */
143
+ const MAX_IN_FLIGHT = 3;
144
+ /** Attempts per chunk in the live round (first try + retries). */
145
+ const MAX_ATTEMPTS = 4;
146
+ /** Extra attempts per parked chunk during the final drain() round. */
147
+ const DRAIN_ATTEMPTS = 2;
148
+ const BACKOFF_BASE_MS = 500;
149
+ const BACKOFF_CAP_MS = 8e3;
150
+ /** Upper bound honored for a server-sent `Retry-After` (seconds). */
151
+ const RETRY_AFTER_CAP_MS = 3e4;
152
+ /**
153
+ * Ceiling on un-acknowledged chunk bytes held in memory. On a network slower
154
+ * than the encoder the backlog grows without bound; past this the upload
155
+ * cannot realistically catch up, so the uploader fails instead of eating
156
+ * memory on a low-end device. ~48 MiB ≈ 2.5 minutes of video at our bitrate.
157
+ */
158
+ const MAX_BUFFERED_BYTES = 48 * 1024 * 1024;
159
+ function httpStatusOf$1(error) {
160
+ if (typeof error === "object" && error !== null && "status" in error && typeof error.status === "number") return error.status;
161
+ return null;
162
+ }
163
+ function retryAfterMsOf(error) {
164
+ if (typeof error === "object" && error !== null && "headers" in error && typeof error.headers === "object") {
165
+ const headers = error.headers;
166
+ const seconds = Number(headers?.["retry-after"]);
167
+ if (Number.isFinite(seconds) && seconds >= 0) return Math.min(seconds * 1e3, RETRY_AFTER_CAP_MS);
168
+ }
169
+ return null;
170
+ }
171
+ /**
172
+ * Uploads video-selfie chunks with the client-side half of the service's
173
+ * resilience contract (`video-selfie-service` README, "What a client can
174
+ * rely on"):
175
+ *
176
+ * - **Keep-until-ack** — every chunk is held in memory until its upload
177
+ * returns 200 (a hole in the sequence can only be filled by that exact
178
+ * data). Acked bytes are durable in S3 (stored as a part or staged), so
179
+ * the blob is released the moment the ack lands.
180
+ * - **Retry with backoff** — transient failures (network error/timeout,
181
+ * 408, 429, 5xx) retry the same bytes under the same partNumber with
182
+ * exponential backoff + full jitter; 429 honors the server's
183
+ * `Retry-After`. Chunks may land out of order — the service stages them.
184
+ * - **Park, then drain** — a chunk that exhausts its live retries is parked
185
+ * (blob kept) without failing the recording; {@link drain} gives every
186
+ * parked chunk a final round once recording stops, so a mid-recording
187
+ * network outage only fails the upload if it persists to the end. A
188
+ * browser `online` event un-parks early: parked chunks get a fresh live
189
+ * round as soon as connectivity returns instead of waiting for stop.
190
+ * - **409 is fatal** — a newer initiate fenced this session out ("latest
191
+ * initiate wins"); no retry can succeed, so the uploader stops.
192
+ * - **Bounded memory** — when un-acked bytes exceed the ceiling the
193
+ * uploader fails rather than buffering a runaway backlog.
194
+ */
195
+ var VideoSelfieChunkUploader = class {
196
+ constructor(session, dependencies = {}) {
197
+ this.queue = [];
198
+ this.parked = [];
199
+ this.inFlight = 0;
200
+ this.bufferedBytes = 0;
201
+ this.fatal = false;
202
+ this.disposed = false;
203
+ this.tasks = [];
204
+ this.session = session;
205
+ this.timer = dependencies.timer ?? BrowserTimerProvider.getInstance();
206
+ this.jitter = dependencies.jitter ?? Math.random;
207
+ const networkStatus = dependencies.networkStatus ?? new BrowserNetworkStatusProvider();
208
+ this.unsubscribeOnline = networkStatus.onOnline(() => this.unparkEarly());
209
+ }
210
+ /** True once the upload cannot complete (fenced out or over the memory cap). */
211
+ get failed() {
212
+ return this.fatal;
213
+ }
214
+ /**
215
+ * Accepts the next chunk for upload. Non-blocking: the upload (and any
216
+ * retries) run in the background; failures surface through {@link failed}
217
+ * and {@link drain}.
218
+ */
219
+ enqueue(partNumber, chunk) {
220
+ if (this.fatal || this.disposed) return;
221
+ this.bufferedBytes += chunk.size;
222
+ if (this.bufferedBytes > MAX_BUFFERED_BYTES) {
223
+ this.fatal = true;
224
+ return;
225
+ }
226
+ this.queue.push({
227
+ partNumber,
132
228
  chunk,
133
- partNumber: this.partNumber
229
+ attempts: 0
230
+ });
231
+ this.pump();
232
+ }
233
+ /**
234
+ * Waits for every accepted chunk to be acknowledged, giving parked chunks
235
+ * one final retry round. Returns `true` when all chunks landed and the
236
+ * upload can be completed.
237
+ */
238
+ async drain() {
239
+ this.unsubscribeOnline();
240
+ await this.settleLiveRound();
241
+ while (!this.fatal && this.parked.length > 0) {
242
+ const chunk = this.parked.shift();
243
+ chunk.attempts = MAX_ATTEMPTS - DRAIN_ATTEMPTS;
244
+ this.queue.push(chunk);
245
+ this.pump();
246
+ await this.settleLiveRound();
247
+ if (this.parked.some((p) => p.partNumber === chunk.partNumber)) return false;
248
+ }
249
+ return !this.fatal && this.parked.length === 0;
250
+ }
251
+ /** Cancels all pending work; held blobs are released. */
252
+ dispose() {
253
+ this.disposed = true;
254
+ this.queue = [];
255
+ this.parked = [];
256
+ this.unsubscribeOnline();
257
+ }
258
+ /**
259
+ * Connectivity is back (browser `online` event) — give parked chunks a
260
+ * fresh live round right away instead of holding them until {@link drain}.
261
+ * The event is only a hint: chunks that still fail simply park again.
262
+ */
263
+ unparkEarly() {
264
+ if (this.fatal || this.disposed || this.parked.length === 0) return;
265
+ for (const chunk of this.parked.splice(0)) {
266
+ chunk.attempts = 0;
267
+ this.queue.push(chunk);
268
+ }
269
+ this.pump();
270
+ }
271
+ async settleLiveRound() {
272
+ while (this.tasks.length > 0) {
273
+ const snapshot = [...this.tasks];
274
+ await Promise.all(snapshot);
275
+ this.tasks = this.tasks.filter((task) => !snapshot.includes(task));
276
+ }
277
+ }
278
+ pump() {
279
+ while (!this.fatal && !this.disposed && this.inFlight < MAX_IN_FLIGHT && this.queue.length > 0) {
280
+ const chunk = this.queue.shift();
281
+ this.inFlight += 1;
282
+ const task = this.uploadWithRetry(chunk).finally(() => {
283
+ this.inFlight -= 1;
284
+ this.pump();
285
+ });
286
+ this.tasks.push(task);
287
+ }
288
+ }
289
+ async uploadWithRetry(pending) {
290
+ while (!this.disposed) {
291
+ pending.attempts += 1;
292
+ try {
293
+ await uploadVideoSelfiePart(this.session, pending.partNumber, pending.chunk);
294
+ this.bufferedBytes -= pending.chunk.size;
295
+ return;
296
+ } catch (error) {
297
+ const status = httpStatusOf$1(error);
298
+ if (status === 409) {
299
+ this.fatal = true;
300
+ return;
301
+ }
302
+ if (status !== null && status >= 400 && status < 500 && status !== 408 && status !== 429 || pending.attempts >= MAX_ATTEMPTS) {
303
+ this.parked.push(pending);
304
+ return;
305
+ }
306
+ await this.delayBeforeRetry(pending.attempts, error);
307
+ }
308
+ }
309
+ }
310
+ delayBeforeRetry(attempt, error) {
311
+ const retryAfterMs = retryAfterMsOf(error);
312
+ const backoffCeiling = Math.min(BACKOFF_BASE_MS * 2 ** (attempt - 1), BACKOFF_CAP_MS);
313
+ const waitMs = retryAfterMs ?? backoffCeiling / 2 + this.jitter() * (backoffCeiling / 2);
314
+ return new Promise((resolve) => {
315
+ this.timer.setTimeout(resolve, waitMs);
134
316
  });
135
- this.buffer = [];
136
- this.bufferedBytes = 0;
137
317
  }
138
318
  };
139
319
  //#endregion
140
320
  //#region src/internal/recordings/multipartRecordingService.ts
321
+ /** Attempts for `complete` — documented safe to repeat if the response was lost. */
322
+ const COMPLETE_ATTEMPTS = 3;
323
+ const COMPLETE_BACKOFF_MS = 500;
324
+ function httpStatusOf(error) {
325
+ if (typeof error === "object" && error !== null && "status" in error && typeof error.status === "number") return error.status;
326
+ return null;
327
+ }
141
328
  /**
142
329
  * Records the camera on-device and streams it to the backend as it is
143
330
  * captured, using the video-selfie-service multipart upload protocol
@@ -148,19 +335,21 @@ var MultipartRecordingProvider = class {
148
335
  * / `OpenViduRecordingService`) — it is the replacement for server-side
149
336
  * (OpenVidu) recording, not a sibling of it.
150
337
  *
151
- * Parts upload concurrently with recording, so `stop()` only flushes the final
152
- * part and finalizes — keeping the whole session inside the server's
153
- * video-selfie timeout regardless of length, with client memory bounded to
154
- * ~one part. No client-side encryption: video is encrypted at rest server-side
338
+ * Every ~1 s recorder blob uploads as its own chunk, concurrently with
339
+ * recording, through {@link VideoSelfieChunkUploader} (keep-until-ack +
340
+ * retry with backoff — see its doc for the full policy). The service stages
341
+ * sub-5 MiB chunks and combines them server-side, so `stop()` only drains
342
+ * the stragglers and finalizes; client memory holds un-acked chunks only.
343
+ * No client-side encryption: video is encrypted at rest server-side
155
344
  * (S3 SSE-AES-256).
156
345
  */
157
346
  var MultipartRecordingService = class {
158
347
  constructor() {
159
348
  this.recorder = new MultipartRecordingProvider();
349
+ this.timer = BrowserTimerProvider.getInstance();
160
350
  this.session = null;
161
- this.parts = [];
162
- this.inflight = [];
163
- this.uploadFailed = false;
351
+ this.uploader = null;
352
+ this.chunksEmitted = 0;
164
353
  }
165
354
  get isRecording() {
166
355
  return this.recorder.isRecording;
@@ -175,33 +364,26 @@ var MultipartRecordingService = class {
175
364
  uploadId: initiated.uploadId,
176
365
  epoch: initiated.epoch
177
366
  };
178
- this.parts = [];
179
- this.inflight = [];
180
- this.uploadFailed = false;
367
+ this.uploader = new VideoSelfieChunkUploader(this.session);
368
+ this.chunksEmitted = 0;
181
369
  this.recorder.startRecording(stream, ({ chunk, partNumber }) => {
182
- const session = this.session;
183
- if (!session) return;
184
- const task = uploadVideoSelfiePart(session, partNumber, chunk).then((part) => {
185
- this.parts.push(part);
186
- }).catch(() => {
187
- this.uploadFailed = true;
188
- });
189
- this.inflight.push(task);
370
+ this.chunksEmitted += 1;
371
+ this.uploader?.enqueue(partNumber, chunk);
190
372
  });
191
373
  }
192
374
  async stop() {
193
375
  const session = this.session;
194
- if (!this.recorder.isRecording || !session) return { recordingId: null };
376
+ const uploader = this.uploader;
377
+ if (!this.recorder.isRecording || !session || !uploader) return { recordingId: null };
195
378
  await this.recorder.stopRecording();
196
- await Promise.all(this.inflight);
197
- if (this.uploadFailed || this.parts.length === 0) {
379
+ if (!await uploader.drain() || uploader.failed || this.chunksEmitted === 0) {
198
380
  this.abandonUpload(session);
199
381
  return { recordingId: null };
200
382
  }
201
- const orderedParts = [...this.parts].sort((a, b) => a.partNumber - b.partNumber);
202
383
  try {
203
- await completeVideoSelfieUpload(session, orderedParts);
384
+ await this.completeWithRetry(session);
204
385
  this.session = null;
386
+ this.uploader = null;
205
387
  return { recordingId: session.uploadId };
206
388
  } catch {
207
389
  this.abandonUpload(session);
@@ -213,13 +395,34 @@ var MultipartRecordingService = class {
213
395
  this.recorder.reset();
214
396
  }
215
397
  /**
398
+ * `complete` is idempotent server-side ("safe to repeat if the response
399
+ * was lost"), so transient failures — network errors, 5xx, 429 — retry a
400
+ * couple of times before the recording is declared failed. A 4xx (e.g.
401
+ * `400` naming a missing part) is permanent: after a clean drain every
402
+ * chunk was acked, so a reported hole cannot be filled from here.
403
+ */
404
+ async completeWithRetry(session) {
405
+ for (let attempt = 1;; attempt += 1) try {
406
+ await completeVideoSelfieUpload(session);
407
+ return;
408
+ } catch (error) {
409
+ const status = httpStatusOf(error);
410
+ if (status !== null && status >= 400 && status < 500 && status !== 408 && status !== 429 || attempt >= COMPLETE_ATTEMPTS) throw error;
411
+ await new Promise((resolve) => {
412
+ this.timer.setTimeout(resolve, COMPLETE_BACKOFF_MS * attempt);
413
+ });
414
+ }
415
+ }
416
+ /**
216
417
  * Fire-and-forget abort: the upload can no longer complete, so tell the
217
418
  * backend to fail it immediately rather than at its expiry. Best-effort —
218
419
  * an abort that doesn't land (including a 409 from a newer epoch having
219
- * taken over) just means the server falls back to expiry.
420
+ * taken over) just means the server falls back to expiry or salvage.
220
421
  */
221
422
  abandonUpload(session) {
222
423
  this.session = null;
424
+ this.uploader?.dispose();
425
+ this.uploader = null;
223
426
  abortVideoSelfieUpload(session).catch(() => {});
224
427
  }
225
428
  };
@@ -245,6 +448,9 @@ function detectionErrorFromEvent(event) {
245
448
  function validationFailureFromEvent(event) {
246
449
  return event.failure;
247
450
  }
451
+ function errorKindFromEvent(event) {
452
+ return event.kind;
453
+ }
248
454
  function retryableFailureFromEvent(event) {
249
455
  return event.failure;
250
456
  }
@@ -378,7 +584,8 @@ const videoSelfieRecordingSetup = setup({
378
584
  }).catch((err) => {
379
585
  if (!controller.signal.aborted) sendBack({
380
586
  type: "DETECTION_FAILED",
381
- error: String(err)
587
+ error: String(err),
588
+ kind: isConnectionError(err) ? "connection" : "technical"
382
589
  });
383
590
  });
384
591
  return () => controller.abort();
@@ -407,14 +614,20 @@ const videoSelfieRecordingSetup = setup({
407
614
  validationFailure: retryableFailureFromEvent(event),
408
615
  detectionStatus: "error"
409
616
  })),
410
- setErrorFromDetection: assign({ error: ({ event }) => detectionErrorFromEvent(event) }),
617
+ setErrorFromDetection: assign({
618
+ error: ({ event }) => detectionErrorFromEvent(event),
619
+ errorKind: ({ event }) => errorKindFromEvent(event)
620
+ }),
411
621
  clearDetectionFeedback: assign({
412
622
  detectionStatus: () => void 0,
413
623
  detectionError: () => void 0,
414
624
  validationFailure: () => void 0,
415
625
  orientation: () => void 0
416
626
  }),
417
- setUploadFailedError: assign({ error: () => "Video upload failed" }),
627
+ setUploadFailedError: assign({
628
+ error: () => "Video upload failed",
629
+ errorKind: () => "connection"
630
+ }),
418
631
  resetSession: assign(({ context }) => ({
419
632
  stepIndex: 0,
420
633
  stream: void 0,
@@ -425,7 +638,8 @@ const videoSelfieRecordingSetup = setup({
425
638
  validationFailure: void 0,
426
639
  attemptsRemaining: context.attemptsPerStep,
427
640
  recordingId: null,
428
- error: void 0
641
+ error: void 0,
642
+ errorKind: void 0
429
643
  })),
430
644
  cleanup: ({ context }) => {
431
645
  context.service.cleanup();
@@ -487,6 +701,7 @@ const videoSelfieRecordingMachine = videoSelfieRecordingSetup.createMachine({
487
701
  attemptsRemaining: normalizeAttempts(input.attemptsPerStep),
488
702
  recordingId: null,
489
703
  error: void 0,
704
+ errorKind: void 0,
490
705
  switchingCameraMinDwellMs: input.dependencies?.switchingCameraMinDwellMs ?? SWITCHING_CAMERA_MIN_DWELL_MS
491
706
  }),
492
707
  on: { ABORT: { target: ".aborted" } },
@@ -685,7 +900,8 @@ function mapState(snapshot) {
685
900
  validationFailure: context.validationFailure,
686
901
  attemptsRemaining: context.attemptsRemaining,
687
902
  recordingId: context.recordingId,
688
- error: context.error
903
+ error: context.error,
904
+ errorKind: context.errorKind
689
905
  };
690
906
  }
691
907
  function createApi({ actor }) {
@@ -1,14 +1,14 @@
1
1
  import { t as BrowserTimerProvider } from "./BrowserTimerProvider-BXhgNxLt.esm.js";
2
2
  import { t as api } from "./api-Bx3gKW_y.esm.js";
3
3
  import { t as endpoints } from "./endpoints-CCzL3XD_.esm.js";
4
- import { l as facingModeForStep, u as resolveVideoSelfieSteps } from "./flowServices-C4_82oGS.esm.js";
4
+ import { l as facingModeForStep, u as resolveVideoSelfieSteps } from "./flowServices-Dqeralkm.esm.js";
5
5
  import { t as checkPermission } from "./permissionServices-3UAjhmjw.esm.js";
6
6
  import { i as requestCameraWithFallback, r as requestCameraAccess } from "./camera-BmFEyPP_.esm.js";
7
- import { _ as StreamCanvasProcessingSession, a as encryptSelfieImage, l as startDetection, v as FaceDetectionProvider } from "./onDeviceFaceResults-CrSi9d8M.esm.js";
7
+ import { _ as StreamCanvasProcessingSession, a as encryptSelfieImage, l as startDetection, v as FaceDetectionProvider } from "./onDeviceFaceResults-DzrHstja.esm.js";
8
8
  import { n as getBackCameraStream } from "./backCameraStream-BqiXcU28.esm.js";
9
9
  import { n as getWindowDimensions } from "./getDeviceClass-CeBiEayS.esm.js";
10
10
  import { t as FACE_ERROR_CODES } from "./types-BN5RPPIZ.esm.js";
11
- import { i as uploadSelfie, r as processFace, t as getFaceErrorCodeFromUnknown } from "./selfieErrorUtils-DggLa9pg.esm.js";
11
+ import { i as uploadSelfie, r as processFace, t as getFaceErrorCodeFromUnknown } from "./selfieErrorUtils-EEHiYwTi.esm.js";
12
12
  import { t as StreamCanvasCapture } from "./StreamCanvasCapture-D2XcXCZ4.esm.js";
13
13
  import { n as DEFAULT_ID_CAPTURE_THRESHOLDS, r as IdCaptureProvider, t as DEFAULT_ID_CAPTURE_GEOMETRY } from "./idCaptureDefaults-DrQe0hWr.esm.js";
14
14
  //#region src/modules/video-selfie/videoSelfieCompareService.ts
@@ -92,6 +92,29 @@ function isSelfieValidationError(error) {
92
92
  const status = getErrorStatus(error);
93
93
  return status !== void 0 && SELFIE_VALIDATION_STATUS_CODES.includes(status);
94
94
  }
95
+ /** Attempts for the selfie upload + process round (first try + retries). */
96
+ const SELFIE_SUBMIT_ATTEMPTS = 3;
97
+ const SELFIE_SUBMIT_BACKOFF_MS = 2e3;
98
+ /**
99
+ * True for HTTP-transport-shaped failures — network error / client-side
100
+ * timeout (status 0), 408, 429, 5xx — as opposed to a backend verdict.
101
+ * Plain Errors (aborts, programming faults) are not connection errors.
102
+ */
103
+ function isConnectionError(error) {
104
+ if (typeof error !== "object" || error === null || !("status" in error)) return false;
105
+ const status = error.status;
106
+ if (typeof status !== "number") return false;
107
+ return status === 0 || status === 408 || status === 429 || status >= 500;
108
+ }
109
+ /**
110
+ * True for errors where the selfie submission never got a meaningful backend
111
+ * verdict, as opposed to a validation outcome. Re-sending the same payload
112
+ * can succeed, so these are retried in place instead of failing the whole
113
+ * recording.
114
+ */
115
+ function isSelfieTransportError(error) {
116
+ return !isSelfieValidationError(error) && isConnectionError(error);
117
+ }
95
118
  function isIdComparisonValidationError(error) {
96
119
  return typeof error === "object" && error !== null && "status" in error && typeof error.status === "number" && error.status > 0;
97
120
  }
@@ -207,13 +230,19 @@ async function detectSelfie(params) {
207
230
  dependencies: { getWasmUtil: async () => deps.getWasmUtil() }
208
231
  });
209
232
  throwIfAborted(signal);
210
- await uploadSelfie({
211
- encryptedBase64Image,
212
- faceCoordinates,
213
- imageType
214
- });
215
- throwIfAborted(signal);
216
- await processFace(imageType);
233
+ for (let attempt = 1;; attempt += 1) try {
234
+ await uploadSelfie({
235
+ encryptedBase64Image,
236
+ faceCoordinates,
237
+ imageType
238
+ });
239
+ throwIfAborted(signal);
240
+ await processFace(imageType);
241
+ break;
242
+ } catch (error) {
243
+ if (signal.aborted || !isSelfieTransportError(error) || attempt >= SELFIE_SUBMIT_ATTEMPTS) throw error;
244
+ await delay(SELFIE_SUBMIT_BACKOFF_MS * attempt, signal);
245
+ }
217
246
  throwIfAborted(signal);
218
247
  onStatus?.("success");
219
248
  await delay(SELFIE_SUCCESS_DWELL_MS, signal);
@@ -235,7 +264,15 @@ async function detectSelfie(params) {
235
264
  await runAttempt();
236
265
  return { outcome: "success" };
237
266
  } catch (error) {
238
- if (signal.aborted || !isSelfieValidationError(error)) throw error;
267
+ if (signal.aborted) throw error;
268
+ if (isSelfieTransportError(error)) {
269
+ onStatus?.("error");
270
+ return {
271
+ outcome: "retryableFailure",
272
+ failure: "selfieUploadFailed"
273
+ };
274
+ }
275
+ if (!isSelfieValidationError(error)) throw error;
239
276
  onStatus?.("error");
240
277
  return {
241
278
  outcome: "validationFailed",
@@ -611,4 +648,4 @@ function createVideoSelfieCameraWarmer(config) {
611
648
  };
612
649
  }
613
650
  //#endregion
614
- export { delay as a, createDefaultStepDetector as i, defaultAcquireCamera as n, isSelfieValidationError as o, CameraCompositor as r, isWrongVideoSelfieIdSide as s, createVideoSelfieCameraWarmer as t };
651
+ export { delay as a, isWrongVideoSelfieIdSide as c, createDefaultStepDetector as i, defaultAcquireCamera as n, isConnectionError as o, CameraCompositor as r, isSelfieValidationError as s, createVideoSelfieCameraWarmer as t };
@@ -78,7 +78,13 @@ declare class CameraCompositor {
78
78
  //#endregion
79
79
  //#region src/modules/video-selfie/videoSelfieStepDetector.d.ts
80
80
  type VideoSelfieDetectionStatus = DetectionStatus | 'wrongSide';
81
- type VideoSelfieValidationFailure = 'selfieVerificationFailed' | 'nameVerificationFailed' | 'photoVerificationFailed' | 'idTypeMismatch' | 'idScanFailed';
81
+ type VideoSelfieValidationFailure = 'selfieVerificationFailed' | 'nameVerificationFailed' | 'photoVerificationFailed' | 'idTypeMismatch' | 'idScanFailed' | 'selfieUploadFailed';
82
+ /**
83
+ * Failures that re-run the current step WITHOUT consuming an attempt or the
84
+ * recording: the capture itself was fine — a transport-level problem kept
85
+ * the backend from delivering a verdict.
86
+ */
87
+ type VideoSelfieRetryableFailure = 'idScanFailed' | 'selfieUploadFailed';
82
88
  type StepDetectionResult = {
83
89
  outcome: 'success';
84
90
  } | {
@@ -86,7 +92,7 @@ type StepDetectionResult = {
86
92
  failure: VideoSelfieValidationFailure;
87
93
  } | {
88
94
  outcome: 'retryableFailure';
89
- failure: 'idScanFailed';
95
+ failure: VideoSelfieRetryableFailure;
90
96
  };
91
97
  /**
92
98
  * Runs the WASM detection + backend validation for a single capture step over
package/dist/wasm.esm.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { a as resolveWasmConfig, n as buildDefaultWasmConfig, r as buildWasmConfigFromBasePath, t as DEFAULT_WASM_VERSION } from "./wasmDefaults-DTUrftxR.esm.js";
2
2
  import { s as warmupWasm } from "./safeStorage-Ep56I-f_.esm.js";
3
- import { a as setWasmConfig, n as initializeWasmUtil, s as upgradeToWasmHttpClient, t as ensureWasmPipelines } from "./setup-EktXQNTl.esm.js";
3
+ import { a as setWasmConfig, n as initializeWasmUtil, s as upgradeToWasmHttpClient, t as ensureWasmPipelines } from "./setup-Ba31IGP9.esm.js";
4
4
  export { DEFAULT_WASM_VERSION, buildDefaultWasmConfig, buildWasmConfigFromBasePath, ensureWasmPipelines, initializeWasmUtil, resolveWasmConfig, setWasmConfig, upgradeToWasmHttpClient, warmupWasm };
@@ -330,10 +330,6 @@ declare const workflowMachine: StateMachine<WorkflowContext, {
330
330
  id: string | undefined;
331
331
  };
332
332
  }>, Values<{
333
- setError: {
334
- type: "setError";
335
- params: NonReducibleUnknown;
336
- };
337
333
  setLoadingResult: {
338
334
  type: "setLoadingResult";
339
335
  params: NonReducibleUnknown;
@@ -366,6 +362,10 @@ declare const workflowMachine: StateMachine<WorkflowContext, {
366
362
  type: "setFinishStatusFailed";
367
363
  params: NonReducibleUnknown;
368
364
  };
365
+ setError: {
366
+ type: "setError";
367
+ params: NonReducibleUnknown;
368
+ };
369
369
  setModuleError: {
370
370
  type: "setModuleError";
371
371
  params: NonReducibleUnknown;