@idmission/websdk-core 0.2.0 → 0.5.0

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 (181) hide show
  1. package/README.md +19 -0
  2. package/dist/attestation/clientAttestation.d.ts +5 -0
  3. package/dist/attestation/clientAttestation.d.ts.map +1 -1
  4. package/dist/attestation/clientAttestation.js +4 -4
  5. package/dist/attestation/collectClientAttestation.d.ts +3 -1
  6. package/dist/attestation/collectClientAttestation.d.ts.map +1 -1
  7. package/dist/attestation/collectClientAttestation.js +4 -3
  8. package/dist/camera/acquireCamera.d.ts +5 -0
  9. package/dist/camera/acquireCamera.d.ts.map +1 -1
  10. package/dist/camera/acquireCamera.js +25 -5
  11. package/dist/captureProgress/actor.d.ts +30 -0
  12. package/dist/captureProgress/actor.d.ts.map +1 -0
  13. package/dist/captureProgress/actor.js +754 -0
  14. package/dist/captureProgress/encoder.d.ts +7 -0
  15. package/dist/captureProgress/encoder.d.ts.map +1 -0
  16. package/dist/captureProgress/encoder.js +195 -0
  17. package/dist/captureProgress/index.d.ts +4 -0
  18. package/dist/captureProgress/index.d.ts.map +1 -0
  19. package/dist/captureProgress/index.js +45 -0
  20. package/dist/captureProgress/internal.d.ts +3 -0
  21. package/dist/captureProgress/internal.d.ts.map +1 -0
  22. package/dist/captureProgress/internal.js +1 -0
  23. package/dist/captureProgress/protocol.d.ts +224 -0
  24. package/dist/captureProgress/protocol.d.ts.map +1 -0
  25. package/dist/captureProgress/protocol.js +106 -0
  26. package/dist/captureProgress/recorder.d.ts +32 -0
  27. package/dist/captureProgress/recorder.d.ts.map +1 -0
  28. package/dist/captureProgress/recorder.js +554 -0
  29. package/dist/captureProgress/transport.d.ts +33 -0
  30. package/dist/captureProgress/transport.d.ts.map +1 -0
  31. package/dist/captureProgress/transport.js +109 -0
  32. package/dist/captureProgress/types.d.ts +35 -0
  33. package/dist/captureProgress/types.d.ts.map +1 -0
  34. package/dist/captureProgress/types.js +27 -0
  35. package/dist/client/IdmissionClient.d.ts +6 -1
  36. package/dist/client/IdmissionClient.d.ts.map +1 -1
  37. package/dist/client/IdmissionClient.js +93 -27
  38. package/dist/client/approval.d.ts +15 -0
  39. package/dist/client/approval.d.ts.map +1 -0
  40. package/dist/client/approval.js +19 -0
  41. package/dist/client/documentFileMetadata.d.ts +13 -0
  42. package/dist/client/documentFileMetadata.d.ts.map +1 -0
  43. package/dist/client/documentFileMetadata.js +51 -0
  44. package/dist/client/index.d.ts +3 -0
  45. package/dist/client/index.d.ts.map +1 -1
  46. package/dist/client/index.js +2 -0
  47. package/dist/client/payload.d.ts +3 -0
  48. package/dist/client/payload.d.ts.map +1 -1
  49. package/dist/client/payload.js +1 -0
  50. package/dist/client/submissionMetadata.d.ts +4 -1
  51. package/dist/client/submissionMetadata.d.ts.map +1 -1
  52. package/dist/client/submissionMetadata.js +13 -8
  53. package/dist/client/types.d.ts +6 -0
  54. package/dist/client/types.d.ts.map +1 -1
  55. package/dist/client/validateSession.d.ts +2 -0
  56. package/dist/client/validateSession.d.ts.map +1 -1
  57. package/dist/client/validateSession.js +53 -24
  58. package/dist/documentCapture/autoCaptureEngine.d.ts.map +1 -1
  59. package/dist/documentCapture/autoCaptureEngine.js +27 -8
  60. package/dist/documentCapture/autoCaptureGeometry.d.ts +97 -7
  61. package/dist/documentCapture/autoCaptureGeometry.d.ts.map +1 -1
  62. package/dist/documentCapture/autoCaptureGeometry.js +87 -6
  63. package/dist/documentCapture/autoCaptureMetadata.d.ts +12 -4
  64. package/dist/documentCapture/autoCaptureMetadata.d.ts.map +1 -1
  65. package/dist/documentCapture/autoCaptureMetadata.js +8 -5
  66. package/dist/documentCapture/autoCaptureOptions.d.ts +4 -5
  67. package/dist/documentCapture/autoCaptureOptions.d.ts.map +1 -1
  68. package/dist/documentCapture/autoCaptureOptions.js +4 -5
  69. package/dist/documentCapture/controller.d.ts +5 -0
  70. package/dist/documentCapture/controller.d.ts.map +1 -1
  71. package/dist/documentCapture/controller.js +37 -21
  72. package/dist/documentCapture/index.d.ts +1 -1
  73. package/dist/documentCapture/index.d.ts.map +1 -1
  74. package/dist/documentCapture/index.js +1 -1
  75. package/dist/idCapture/controller.d.ts +4 -1
  76. package/dist/idCapture/controller.d.ts.map +1 -1
  77. package/dist/idCapture/controller.js +69 -10
  78. package/dist/idCapture/state.d.ts +1 -3
  79. package/dist/idCapture/state.d.ts.map +1 -1
  80. package/dist/idCapture/submit.d.ts.map +1 -1
  81. package/dist/idCapture/submit.js +35 -1
  82. package/dist/idCapture/types.d.ts +2 -0
  83. package/dist/idCapture/types.d.ts.map +1 -1
  84. package/dist/index.d.ts +2 -0
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +1 -0
  87. package/dist/liveness/challengeGeometry.d.ts +48 -17
  88. package/dist/liveness/challengeGeometry.d.ts.map +1 -1
  89. package/dist/liveness/challengeGeometry.js +101 -54
  90. package/dist/models/DocumentDetection.d.ts.map +1 -1
  91. package/dist/models/DocumentDetection.js +38 -2
  92. package/dist/models/defaults/DocumentDetectorLiteRT.d.ts +2 -2
  93. package/dist/models/defaults/DocumentDetectorLiteRT.d.ts.map +1 -1
  94. package/dist/models/defaults/DocumentDetectorLiteRT.js +27 -2
  95. package/dist/models/defaults/HandLandmarkLiteRT.d.ts +3 -0
  96. package/dist/models/defaults/HandLandmarkLiteRT.d.ts.map +1 -0
  97. package/dist/models/defaults/HandLandmarkLiteRT.js +5 -0
  98. package/dist/models/defaults/IrisLandmarkLiteRT.d.ts +3 -0
  99. package/dist/models/defaults/IrisLandmarkLiteRT.d.ts.map +1 -0
  100. package/dist/models/defaults/IrisLandmarkLiteRT.js +5 -0
  101. package/dist/models/defaults/PalmDetectionLiteRT.d.ts +3 -0
  102. package/dist/models/defaults/PalmDetectionLiteRT.d.ts.map +1 -0
  103. package/dist/models/defaults/PalmDetectionLiteRT.js +5 -0
  104. package/dist/models/defaults/PoaDocumentDetectorLiteRT.d.ts +2 -2
  105. package/dist/models/defaults/PoaDocumentDetectorLiteRT.d.ts.map +1 -1
  106. package/dist/models/defaults/PoaDocumentDetectorLiteRT.js +12 -8
  107. package/dist/models/defaults/index.d.ts +10 -1
  108. package/dist/models/defaults/index.d.ts.map +1 -1
  109. package/dist/models/defaults/index.js +12 -0
  110. package/dist/models/preloadModels.d.ts +4 -3
  111. package/dist/models/preloadModels.d.ts.map +1 -1
  112. package/dist/models/preloadModels.js +23 -3
  113. package/dist/models/providers/litert/FaceLandmarker.d.ts +8 -1
  114. package/dist/models/providers/litert/FaceLandmarker.d.ts.map +1 -1
  115. package/dist/models/providers/litert/FaceLandmarker.js +95 -3
  116. package/dist/models/providers/litert/HandOverFaceDetector.d.ts +27 -0
  117. package/dist/models/providers/litert/HandOverFaceDetector.d.ts.map +1 -0
  118. package/dist/models/providers/litert/HandOverFaceDetector.js +162 -0
  119. package/dist/models/providers/litert/blazeFacePrePost.js +4 -2
  120. package/dist/models/providers/litert/docDetectPrePost.d.ts.map +1 -1
  121. package/dist/models/providers/litert/docDetectPrePost.js +17 -5
  122. package/dist/models/providers/litert/handLandmarkPrePost.d.ts +20 -0
  123. package/dist/models/providers/litert/handLandmarkPrePost.d.ts.map +1 -0
  124. package/dist/models/providers/litert/handLandmarkPrePost.js +72 -0
  125. package/dist/models/providers/litert/handOverFace.d.ts +44 -0
  126. package/dist/models/providers/litert/handOverFace.d.ts.map +1 -0
  127. package/dist/models/providers/litert/handOverFace.js +139 -0
  128. package/dist/models/providers/litert/irisPrePost.d.ts +38 -0
  129. package/dist/models/providers/litert/irisPrePost.d.ts.map +1 -0
  130. package/dist/models/providers/litert/irisPrePost.js +101 -0
  131. package/dist/models/providers/litert/palmPrePost.d.ts +55 -0
  132. package/dist/models/providers/litert/palmPrePost.d.ts.map +1 -0
  133. package/dist/models/providers/litert/palmPrePost.js +151 -0
  134. package/dist/sdkVersions.d.ts +18 -0
  135. package/dist/sdkVersions.d.ts.map +1 -0
  136. package/dist/sdkVersions.js +8 -0
  137. package/dist/selfieCapture/captureQuality.d.ts +43 -0
  138. package/dist/selfieCapture/captureQuality.d.ts.map +1 -0
  139. package/dist/selfieCapture/captureQuality.js +87 -0
  140. package/dist/selfieCapture/challengeRunner.d.ts +9 -2
  141. package/dist/selfieCapture/challengeRunner.d.ts.map +1 -1
  142. package/dist/selfieCapture/challengeRunner.js +2 -5
  143. package/dist/selfieCapture/controller.d.ts +62 -1
  144. package/dist/selfieCapture/controller.d.ts.map +1 -1
  145. package/dist/selfieCapture/controller.js +470 -105
  146. package/dist/selfieCapture/faceTracking.d.ts +69 -1
  147. package/dist/selfieCapture/faceTracking.d.ts.map +1 -1
  148. package/dist/selfieCapture/faceTracking.js +134 -6
  149. package/dist/selfieCapture/guidance.d.ts +15 -0
  150. package/dist/selfieCapture/guidance.d.ts.map +1 -1
  151. package/dist/selfieCapture/guidance.js +23 -0
  152. package/dist/selfieCapture/index.d.ts +3 -2
  153. package/dist/selfieCapture/index.d.ts.map +1 -1
  154. package/dist/selfieCapture/index.js +1 -1
  155. package/dist/selfieCapture/livenessMachine.d.ts +2 -0
  156. package/dist/selfieCapture/livenessMachine.d.ts.map +1 -1
  157. package/dist/selfieCapture/livenessMachine.js +8 -0
  158. package/dist/selfieCapture/pipeline.d.ts +8 -0
  159. package/dist/selfieCapture/pipeline.d.ts.map +1 -1
  160. package/dist/selfieCapture/pipeline.js +2 -2
  161. package/dist/selfieCapture/reducer.d.ts +7 -0
  162. package/dist/selfieCapture/reducer.d.ts.map +1 -1
  163. package/dist/selfieCapture/reducer.js +45 -4
  164. package/dist/selfieCapture/state.d.ts +6 -0
  165. package/dist/selfieCapture/state.d.ts.map +1 -1
  166. package/dist/selfieCapture/state.js +1 -0
  167. package/dist/signature/frameDecode.d.ts.map +1 -1
  168. package/dist/signature/frameDecode.js +29 -0
  169. package/dist/signature/metadata.d.ts +10 -1
  170. package/dist/signature/metadata.d.ts.map +1 -1
  171. package/dist/signature/quality.d.ts +14 -6
  172. package/dist/signature/quality.d.ts.map +1 -1
  173. package/dist/signature/quality.js +13 -4
  174. package/dist/signatureCapture/controller.d.ts +2 -1
  175. package/dist/signatureCapture/controller.d.ts.map +1 -1
  176. package/dist/signatureCapture/controller.js +47 -2
  177. package/dist/signatureCapture/pipeline.d.ts.map +1 -1
  178. package/dist/signatureCapture/pipeline.js +6 -1
  179. package/dist/version.d.ts +1 -1
  180. package/dist/version.js +1 -1
  181. package/package.json +10 -2
@@ -0,0 +1,554 @@
1
+ const maxTime = 86_400_000;
2
+ const maxCount = 1_000_000;
3
+ export const count = (value) => Math.min(maxCount, Math.max(0, Math.floor(value)));
4
+ const time = (value) => Math.min(maxTime, Math.max(0, Math.floor(value)));
5
+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
6
+ const emptyDuration = () => ({ wallMs: 0, visibleMs: 0, entries: 1 });
7
+ const unobserved = { kind: "unobserved" };
8
+ export function createRecorder(input) {
9
+ const common = {
10
+ context: input.context,
11
+ streamId: input.streamId,
12
+ attemptId: input.attemptId,
13
+ attemptOrdinal: input.attemptOrdinal,
14
+ attemptStatus: "active",
15
+ sequence: 0,
16
+ reason: "entry",
17
+ attemptStartedAtUnixMs: Math.floor(input.unixMs),
18
+ elapsedMs: 0,
19
+ visibility: input.visibility,
20
+ visibleMs: 0,
21
+ lastObservationAgeMs: null,
22
+ counters: {
23
+ retries: 0,
24
+ failures: {},
25
+ transitionsDropped: 0,
26
+ reportsDropped: 0,
27
+ },
28
+ current: null,
29
+ phaseTotals: [],
30
+ recentTransitions: [],
31
+ milestones: {},
32
+ };
33
+ const report = input.lane === "sdk"
34
+ ? {
35
+ ...common,
36
+ lane: "sdk",
37
+ guidanceTotals: [],
38
+ controllerGuidanceTotals: [],
39
+ lastSDKObservationAgeMs: null,
40
+ signature: null,
41
+ }
42
+ : { ...common, lane: "workflow" };
43
+ return {
44
+ openedAt: input.now,
45
+ lastObservationAt: null,
46
+ lastSDKObservationAt: null,
47
+ held: null,
48
+ transitionIndex: 0,
49
+ phaseIndex: 0,
50
+ guidanceChanges: [],
51
+ report,
52
+ };
53
+ }
54
+ function settle(state, now) {
55
+ const elapsedMs = time(now - state.openedAt);
56
+ const delta = state.report.attemptStatus === "active"
57
+ ? Math.max(0, elapsedMs - state.report.elapsedMs)
58
+ : 0;
59
+ const visible = state.report.visibility === "visible" ? delta : 0;
60
+ let report = {
61
+ ...state.report,
62
+ elapsedMs: state.report.elapsedMs + delta,
63
+ visibleMs: state.report.visibleMs + visible,
64
+ };
65
+ if (report.lane === "sdk") {
66
+ const current = report.current;
67
+ if (current && !current.ended) {
68
+ report = {
69
+ ...report,
70
+ current: {
71
+ ...current,
72
+ phaseRunWallMs: current.phaseRunWallMs + delta,
73
+ phaseRunVisibleMs: current.phaseRunVisibleMs + visible,
74
+ guidanceRunWallMs: current.guidanceRunWallMs + delta,
75
+ guidanceRunVisibleMs: current.guidanceRunVisibleMs + visible,
76
+ },
77
+ phaseTotals: report.phaseTotals.map((total) => total.phase === current.phase
78
+ ? {
79
+ ...total,
80
+ duration: {
81
+ ...total.duration,
82
+ wallMs: total.duration.wallMs + delta,
83
+ visibleMs: total.duration.visibleMs + visible,
84
+ },
85
+ }
86
+ : total),
87
+ guidanceTotals: report.guidanceTotals.map((total) => total.phase === current.phase &&
88
+ same(total.exposure, current.exposure)
89
+ ? {
90
+ ...total,
91
+ duration: {
92
+ ...total.duration,
93
+ wallMs: total.duration.wallMs + delta,
94
+ visibleMs: total.duration.visibleMs + visible,
95
+ },
96
+ }
97
+ : total),
98
+ controllerGuidanceTotals: report.controllerGuidanceTotals.map((total) => total.phase === current.phase && same(total.guidance, state.held)
99
+ ? {
100
+ ...total,
101
+ duration: {
102
+ ...total.duration,
103
+ wallMs: total.duration.wallMs + delta,
104
+ visibleMs: total.duration.visibleMs + visible,
105
+ },
106
+ }
107
+ : total),
108
+ };
109
+ }
110
+ report = {
111
+ ...report,
112
+ lastSDKObservationAgeMs: state.lastSDKObservationAt === null
113
+ ? null
114
+ : time(now - state.lastSDKObservationAt),
115
+ };
116
+ }
117
+ else {
118
+ const current = report.current;
119
+ if (current && !current.ended) {
120
+ report = {
121
+ ...report,
122
+ current: {
123
+ ...current,
124
+ phaseRunWallMs: current.phaseRunWallMs + delta,
125
+ phaseRunVisibleMs: current.phaseRunVisibleMs + visible,
126
+ },
127
+ phaseTotals: report.phaseTotals.map((total) => total.phase === current.phase
128
+ ? {
129
+ ...total,
130
+ duration: {
131
+ ...total.duration,
132
+ wallMs: total.duration.wallMs + delta,
133
+ visibleMs: total.duration.visibleMs + visible,
134
+ },
135
+ }
136
+ : total),
137
+ };
138
+ }
139
+ }
140
+ report = {
141
+ ...report,
142
+ lastObservationAgeMs: state.lastObservationAt === null
143
+ ? null
144
+ : time(now - state.lastObservationAt),
145
+ };
146
+ return { ...state, report };
147
+ }
148
+ function appendTransition(state, transition) {
149
+ const recentTransitions = [...state.report.recentTransitions, transition];
150
+ const dropped = Math.max(0, recentTransitions.length - 32);
151
+ const counters = {
152
+ ...state.report.counters,
153
+ transitionsDropped: count(state.report.counters.transitionsDropped + dropped),
154
+ };
155
+ if (state.report.lane === "workflow") {
156
+ if (transition.kind === "guidance")
157
+ return state;
158
+ const transitions = [...state.report.recentTransitions, transition].slice(-32);
159
+ return {
160
+ ...state,
161
+ transitionIndex: transition.index,
162
+ report: {
163
+ ...state.report,
164
+ counters,
165
+ recentTransitions: transitions,
166
+ },
167
+ };
168
+ }
169
+ return {
170
+ ...state,
171
+ transitionIndex: transition.index,
172
+ report: {
173
+ ...state.report,
174
+ counters,
175
+ recentTransitions: recentTransitions.slice(-32),
176
+ },
177
+ };
178
+ }
179
+ function exposureFits(phase, guidance) {
180
+ if (guidance.family === "id")
181
+ return ["id-front", "id-back", "passport"].includes(phase);
182
+ if (guidance.family === "selfie" || guidance.family === "face")
183
+ return phase === "selfie";
184
+ return phase === "signature" || phase === "review";
185
+ }
186
+ export function reduceObservation(state, observation, now) {
187
+ state = settle(state, now);
188
+ if (state.report.attemptStatus !== "active")
189
+ return state;
190
+ const observed = observation.kind !== "visibility";
191
+ state = {
192
+ ...state,
193
+ lastObservationAt: observed ? now : state.lastObservationAt,
194
+ lastSDKObservationAt: observed && state.report.lane === "sdk"
195
+ ? now
196
+ : state.lastSDKObservationAt,
197
+ };
198
+ let report = state.report;
199
+ const atMs = report.elapsedMs;
200
+ const index = state.transitionIndex + 1;
201
+ switch (observation.kind) {
202
+ case "visibility":
203
+ if (observation.visibility === report.visibility)
204
+ return state;
205
+ state = {
206
+ ...state,
207
+ report: { ...report, visibility: observation.visibility },
208
+ };
209
+ return appendTransition(state, {
210
+ kind: "visibility",
211
+ visibility: observation.visibility,
212
+ index,
213
+ atMs,
214
+ });
215
+ case "phase": {
216
+ if (report.current?.phase === observation.phase && !report.current.ended)
217
+ return state;
218
+ const phaseEntryOrdinal = state.phaseIndex + 1;
219
+ const current = {
220
+ phaseEntryOrdinal,
221
+ phaseEnteredAtMs: atMs,
222
+ phaseRunWallMs: 0,
223
+ phaseRunVisibleMs: 0,
224
+ ended: null,
225
+ };
226
+ if (report.lane === "sdk" && "mode" in observation) {
227
+ const phase = observation.phase;
228
+ const found = report.phaseTotals.some((total) => total.phase === phase);
229
+ report = {
230
+ ...report,
231
+ current: {
232
+ ...current,
233
+ phase,
234
+ exposure: unobserved,
235
+ guidanceRunWallMs: 0,
236
+ guidanceRunVisibleMs: 0,
237
+ },
238
+ phaseTotals: found
239
+ ? report.phaseTotals.map((total) => total.phase === phase
240
+ ? {
241
+ ...total,
242
+ duration: {
243
+ ...total.duration,
244
+ entries: count(total.duration.entries + 1),
245
+ },
246
+ }
247
+ : total)
248
+ : [
249
+ ...report.phaseTotals,
250
+ { phase, duration: emptyDuration(), completions: 0 },
251
+ ],
252
+ guidanceTotals: addExposure(report, phase, unobserved),
253
+ };
254
+ state = {
255
+ ...state,
256
+ phaseIndex: phaseEntryOrdinal,
257
+ held: null,
258
+ guidanceChanges: [],
259
+ report,
260
+ };
261
+ return appendTransition(state, { kind: "phase", phase, index, atMs });
262
+ }
263
+ if (report.lane === "workflow" && !("mode" in observation)) {
264
+ const phase = observation.phase;
265
+ const found = report.phaseTotals.some((total) => total.phase === phase);
266
+ report = {
267
+ ...report,
268
+ current: { ...current, phase },
269
+ phaseTotals: found
270
+ ? report.phaseTotals.map((total) => total.phase === phase
271
+ ? {
272
+ ...total,
273
+ duration: {
274
+ ...total.duration,
275
+ entries: count(total.duration.entries + 1),
276
+ },
277
+ }
278
+ : total)
279
+ : [
280
+ ...report.phaseTotals,
281
+ { phase, duration: emptyDuration(), completions: 0 },
282
+ ],
283
+ };
284
+ return appendTransition({ ...state, phaseIndex: phaseEntryOrdinal, report }, { kind: "phase", phase, index, atMs });
285
+ }
286
+ return state;
287
+ }
288
+ case "displayed-guidance": {
289
+ if (report.lane !== "sdk" || !report.current || report.current.ended)
290
+ return state;
291
+ const exposure = observation.exposure;
292
+ if (exposure.kind === "displayed" &&
293
+ !exposureFits(report.current.phase, exposure.message))
294
+ return state;
295
+ if (same(exposure, report.current.exposure))
296
+ return state;
297
+ report = {
298
+ ...report,
299
+ guidanceTotals: addExposure(report, report.current.phase, exposure),
300
+ current: {
301
+ ...report.current,
302
+ exposure,
303
+ guidanceRunWallMs: 0,
304
+ guidanceRunVisibleMs: 0,
305
+ },
306
+ };
307
+ return appendTransition({
308
+ ...state,
309
+ report,
310
+ guidanceChanges: exposure.kind === "displayed"
311
+ ? [...state.guidanceChanges, report.visibleMs].slice(-32)
312
+ : state.guidanceChanges,
313
+ }, { kind: "guidance", exposure, index, atMs });
314
+ }
315
+ case "held-guidance": {
316
+ if (report.lane !== "sdk" ||
317
+ !report.current ||
318
+ report.current.ended ||
319
+ !exposureFits(report.current.phase, observation.guidance))
320
+ return state;
321
+ if (same(state.held, observation.guidance))
322
+ return state;
323
+ const phase = report.current.phase;
324
+ const guidance = observation.guidance;
325
+ const found = report.controllerGuidanceTotals.some((total) => total.phase === phase && same(total.guidance, guidance));
326
+ report = {
327
+ ...report,
328
+ controllerGuidanceTotals: found
329
+ ? report.controllerGuidanceTotals.map((total) => total.phase === phase && same(total.guidance, guidance)
330
+ ? {
331
+ ...total,
332
+ duration: {
333
+ ...total.duration,
334
+ entries: count(total.duration.entries + 1),
335
+ },
336
+ }
337
+ : total)
338
+ : [
339
+ ...report.controllerGuidanceTotals,
340
+ { phase, guidance, duration: emptyDuration() },
341
+ ],
342
+ };
343
+ return { ...state, held: guidance, report };
344
+ }
345
+ case "milestone": {
346
+ if ([
347
+ "document-captured",
348
+ "selfie-captured",
349
+ "challenge-completed",
350
+ "drawing-started",
351
+ ].includes(observation.code))
352
+ state = { ...state, guidanceChanges: [] };
353
+ if (report.lane === "sdk") {
354
+ const code = observation.code;
355
+ report = {
356
+ ...report,
357
+ milestones: {
358
+ ...report.milestones,
359
+ [code]: count((report.milestones[code] ?? 0) + 1),
360
+ },
361
+ };
362
+ }
363
+ else {
364
+ const code = observation.code;
365
+ report = {
366
+ ...report,
367
+ milestones: {
368
+ ...report.milestones,
369
+ [code]: count((report.milestones[code] ?? 0) + 1),
370
+ },
371
+ };
372
+ if (code === "instructions-dismissed" &&
373
+ report.current?.phase === "instructions") {
374
+ report = {
375
+ ...report,
376
+ current: null,
377
+ phaseTotals: report.phaseTotals.map((total) => total.phase === "instructions"
378
+ ? { ...total, completions: count(total.completions + 1) }
379
+ : total),
380
+ };
381
+ }
382
+ }
383
+ return { ...state, report };
384
+ }
385
+ case "failure":
386
+ state = {
387
+ ...state,
388
+ report: {
389
+ ...report,
390
+ counters: {
391
+ ...report.counters,
392
+ failures: {
393
+ ...report.counters.failures,
394
+ [observation.code]: count((report.counters.failures[observation.code] ?? 0) + 1),
395
+ },
396
+ },
397
+ },
398
+ };
399
+ return "terminal" in observation && observation.terminal
400
+ ? endAttempt(state, "failed", now)
401
+ : state;
402
+ case "phase-completed":
403
+ if (report.lane !== "sdk" || !report.current)
404
+ return state;
405
+ return {
406
+ ...state,
407
+ held: null,
408
+ report: {
409
+ ...report,
410
+ current: null,
411
+ phaseTotals: report.phaseTotals.map((total) => total.phase === report.current?.phase
412
+ ? { ...total, completions: count(total.completions + 1) }
413
+ : total),
414
+ },
415
+ };
416
+ case "flow-completed":
417
+ return endAttempt(state, "completed", now);
418
+ case "completed":
419
+ if (report.lane !== "workflow")
420
+ return state;
421
+ state = {
422
+ ...state,
423
+ report: {
424
+ ...report,
425
+ milestones: {
426
+ ...report.milestones,
427
+ "task-completed": count((report.milestones["task-completed"] ?? 0) + 1),
428
+ },
429
+ },
430
+ };
431
+ return endAttempt(state, "completed", now);
432
+ case "signature-interaction": {
433
+ if (report.lane !== "sdk" || report.current?.phase !== "signature")
434
+ return state;
435
+ const signature = signatureFacts(report);
436
+ const ink = observation.inkInteraction || observation.pointCount > 0;
437
+ const started = !signature.drawingStarted && ink;
438
+ return {
439
+ ...state,
440
+ guidanceChanges: started ? [] : state.guidanceChanges,
441
+ report: {
442
+ ...report,
443
+ milestones: started
444
+ ? { ...report.milestones, "drawing-started": 1 }
445
+ : report.milestones,
446
+ signature: {
447
+ ...signature,
448
+ drawingStarted: signature.drawingStarted || ink,
449
+ drawingStartedAtMs: signature.drawingStartedAtMs ?? (ink ? atMs : null),
450
+ lastInteractionAtMs: ink ? atMs : signature.lastInteractionAtMs,
451
+ maxPointsSeen: Math.max(signature.maxPointsSeen, count(observation.pointCount)),
452
+ inkInteractionCount: count(signature.inkInteractionCount +
453
+ (observation.inkInteraction ? 1 : 0)),
454
+ },
455
+ },
456
+ };
457
+ }
458
+ case "recording-interruption": {
459
+ if (report.lane !== "sdk")
460
+ return state;
461
+ const signature = signatureFacts(report);
462
+ return {
463
+ ...state,
464
+ report: {
465
+ ...report,
466
+ signature: {
467
+ ...signature,
468
+ interruptions: count(signature.interruptions + 1),
469
+ interruptionsWithInk: count(signature.interruptionsWithInk + (observation.hadInk ? 1 : 0)),
470
+ interruptionCapReached: signature.interruptionCapReached || observation.capReached,
471
+ },
472
+ },
473
+ };
474
+ }
475
+ case "retry":
476
+ return state;
477
+ }
478
+ }
479
+ function addExposure(report, phase, exposure) {
480
+ const found = report.guidanceTotals.some((total) => total.phase === phase && same(total.exposure, exposure));
481
+ return found
482
+ ? report.guidanceTotals.map((total) => total.phase === phase && same(total.exposure, exposure)
483
+ ? {
484
+ ...total,
485
+ duration: {
486
+ ...total.duration,
487
+ entries: count(total.duration.entries + 1),
488
+ },
489
+ }
490
+ : total)
491
+ : [
492
+ ...report.guidanceTotals,
493
+ { phase, exposure, duration: emptyDuration() },
494
+ ];
495
+ }
496
+ function signatureFacts(report) {
497
+ return (report.signature ?? {
498
+ drawingStarted: false,
499
+ drawingStartedAtMs: null,
500
+ lastInteractionAtMs: null,
501
+ maxPointsSeen: 0,
502
+ inkInteractionCount: 0,
503
+ interruptions: 0,
504
+ interruptionsWithInk: 0,
505
+ interruptionCapReached: false,
506
+ });
507
+ }
508
+ export function endAttempt(state, status, now) {
509
+ state = settle(state, now);
510
+ if (state.report.attemptStatus !== "active")
511
+ return state;
512
+ const report = state.report;
513
+ if (report.lane === "sdk")
514
+ return {
515
+ ...state,
516
+ report: {
517
+ ...report,
518
+ attemptStatus: status,
519
+ current: report.current ? { ...report.current, ended: status } : null,
520
+ },
521
+ };
522
+ return {
523
+ ...state,
524
+ report: {
525
+ ...report,
526
+ attemptStatus: status,
527
+ current: report.current ? { ...report.current, ended: status } : null,
528
+ },
529
+ };
530
+ }
531
+ export function snapshotAt(state, now, sequence, reason) {
532
+ return { ...settle(state, now).report, sequence, reason };
533
+ }
534
+ export function nextCheckpointAfter(visibleMs) {
535
+ if (visibleMs < 20_000)
536
+ return 20_000;
537
+ if (visibleMs < 40_000)
538
+ return 40_000;
539
+ if (visibleMs < 60_000)
540
+ return 60_000;
541
+ return (Math.floor(visibleMs / 60_000) + 1) * 60_000;
542
+ }
543
+ export function valuableStateDue(snapshot, previousVisibleMs, guidanceChanges = []) {
544
+ const current = snapshot.current;
545
+ if (!current ||
546
+ current.ended ||
547
+ current.exposure.kind !== "displayed" ||
548
+ snapshot.visibleMs - previousVisibleMs < 20_000)
549
+ return false;
550
+ if (current.guidanceRunVisibleMs >= 15_000)
551
+ return true;
552
+ return (guidanceChanges.filter((at) => snapshot.visibleMs - at <= 30_000).length >=
553
+ 6);
554
+ }
@@ -0,0 +1,33 @@
1
+ import type { FrozenBatch } from "./protocol";
2
+ export type DeliveryOutcome = {
3
+ kind: "committed";
4
+ } | {
5
+ kind: "temporary";
6
+ retryAfterMs?: number;
7
+ } | {
8
+ kind: "unsupported";
9
+ } | {
10
+ kind: "permanent";
11
+ };
12
+ export type EligibilityOutcome = {
13
+ kind: "enabled";
14
+ bindingId: string;
15
+ } | {
16
+ kind: "disabled";
17
+ } | {
18
+ kind: "unsupported";
19
+ } | {
20
+ kind: "temporary";
21
+ retryAfterMs?: number;
22
+ };
23
+ export type EmergencyResult = {
24
+ queued: boolean;
25
+ confirmation?: Promise<DeliveryOutcome>;
26
+ };
27
+ export type ProgressTransport = {
28
+ eligibility(context: string, signal: AbortSignal): Promise<EligibilityOutcome>;
29
+ send(batch: FrozenBatch, signal: AbortSignal): Promise<DeliveryOutcome>;
30
+ emergency(batch: FrozenBatch): EmergencyResult;
31
+ };
32
+ export declare function createTransport(sessionId: string, authUrl: string): ProgressTransport;
33
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/captureProgress/transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC;AAC1B,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACjD,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;CACzC,CAAC;AACF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,CACT,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/B,IAAI,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACxE,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,eAAe,CAAC;CAChD,CAAC;AAgDF,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,iBAAiB,CA4EnB"}
@@ -0,0 +1,109 @@
1
+ import { normalizeAuthUrl } from "../client/urls";
2
+ async function outcome(response) {
3
+ if (response.status === 204)
4
+ return { kind: "committed" };
5
+ if (response.status === 404 || response.status === 405)
6
+ return { kind: "unsupported" };
7
+ if (response.status === 429) {
8
+ const body = await response.json().catch(() => null);
9
+ if (body &&
10
+ typeof body === "object" &&
11
+ "reason" in body &&
12
+ body.reason === "session-cap")
13
+ return { kind: "permanent" };
14
+ }
15
+ if (response.status >= 400 &&
16
+ response.status < 500 &&
17
+ ![408, 421, 425, 429].includes(response.status))
18
+ return { kind: "permanent" };
19
+ const retryAfter = response.headers.get("Retry-After");
20
+ const seconds = retryAfter === null ? NaN : Number(retryAfter);
21
+ const delay = Number.isFinite(seconds)
22
+ ? seconds * 1000
23
+ : retryAfter
24
+ ? Date.parse(retryAfter) - Date.now()
25
+ : 0;
26
+ const nextUTC = new Date().setUTCHours(24, 0, 0, 0) - Date.now();
27
+ return {
28
+ kind: "temporary",
29
+ retryAfterMs: Math.min(nextUTC, Math.max(0, delay || 0)),
30
+ };
31
+ }
32
+ function queueBeacon(url, body) {
33
+ try {
34
+ return (typeof navigator !== "undefined" &&
35
+ typeof navigator.sendBeacon === "function" &&
36
+ navigator.sendBeacon(url, body));
37
+ }
38
+ catch {
39
+ return false;
40
+ }
41
+ }
42
+ export function createTransport(sessionId, authUrl) {
43
+ const base = `${normalizeAuthUrl(authUrl)}/websdk-capture-progress`;
44
+ const post = async (url, body, signal) => fetch(url, {
45
+ method: "POST",
46
+ headers: { "Content-Type": "application/json" },
47
+ body,
48
+ signal,
49
+ credentials: "omit",
50
+ });
51
+ return {
52
+ async eligibility(context, signal) {
53
+ try {
54
+ const response = await post(`${base}/eligibility`, JSON.stringify({ sessionId, context }), signal);
55
+ if (response.status !== 200) {
56
+ const result = await outcome(response);
57
+ return result.kind === "temporary" || result.kind === "unsupported"
58
+ ? result
59
+ : { kind: "disabled" };
60
+ }
61
+ const body = await response.json();
62
+ if (!body || typeof body !== "object" || !("enabled" in body))
63
+ return { kind: "disabled" };
64
+ if (body.enabled === true &&
65
+ "bindingId" in body &&
66
+ typeof body.bindingId === "string" &&
67
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(body.bindingId))
68
+ return { kind: "enabled", bindingId: body.bindingId };
69
+ return { kind: "disabled" };
70
+ }
71
+ catch {
72
+ return { kind: "temporary" };
73
+ }
74
+ },
75
+ async send(batch, signal) {
76
+ try {
77
+ return outcome(await post(base, new TextDecoder().decode(batch.bytes), signal));
78
+ }
79
+ catch {
80
+ return { kind: "temporary" };
81
+ }
82
+ },
83
+ emergency(batch) {
84
+ try {
85
+ const body = new Blob([new TextDecoder().decode(batch.bytes)], {
86
+ // Safelisted content avoids a credentialed cross-origin preflight.
87
+ // Portal parses the JSON bytes independently of Content-Type.
88
+ type: "text/plain;charset=UTF-8",
89
+ });
90
+ if (queueBeacon(base, body))
91
+ return { queued: true };
92
+ if (typeof Request === "undefined" ||
93
+ !("keepalive" in Request.prototype))
94
+ return { queued: false };
95
+ const confirmation = fetch(base, {
96
+ method: "POST",
97
+ headers: { "Content-Type": "application/json" },
98
+ body,
99
+ keepalive: true,
100
+ credentials: "omit",
101
+ }).then(outcome, () => ({ kind: "temporary" }));
102
+ return { queued: true, confirmation };
103
+ }
104
+ catch {
105
+ return { queued: false };
106
+ }
107
+ },
108
+ };
109
+ }