@idmission/websdk-core 0.1.0-rc.1
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.
- package/README.md +66 -0
- package/dist/attestation/attestationState.d.ts +24 -0
- package/dist/attestation/attestationState.d.ts.map +1 -0
- package/dist/attestation/attestationState.js +57 -0
- package/dist/attestation/clientAttestation.d.ts +40 -0
- package/dist/attestation/clientAttestation.d.ts.map +1 -0
- package/dist/attestation/clientAttestation.js +19 -0
- package/dist/attestation/collectClientAttestation.d.ts +10 -0
- package/dist/attestation/collectClientAttestation.d.ts.map +1 -0
- package/dist/attestation/collectClientAttestation.js +18 -0
- package/dist/attestation/index.d.ts +5 -0
- package/dist/attestation/index.d.ts.map +1 -0
- package/dist/attestation/index.js +4 -0
- package/dist/attestation/nativeAttestationBridge.d.ts +3 -0
- package/dist/attestation/nativeAttestationBridge.d.ts.map +1 -0
- package/dist/attestation/nativeAttestationBridge.js +38 -0
- package/dist/barcode/AAMVAParser.d.ts +77 -0
- package/dist/barcode/AAMVAParser.d.ts.map +1 -0
- package/dist/barcode/AAMVAParser.js +422 -0
- package/dist/barcode/NativeBarcodeDecoder.d.ts +157 -0
- package/dist/barcode/NativeBarcodeDecoder.d.ts.map +1 -0
- package/dist/barcode/NativeBarcodeDecoder.js +832 -0
- package/dist/barcode/Parse.d.ts +6 -0
- package/dist/barcode/Parse.d.ts.map +1 -0
- package/dist/barcode/Parse.js +148 -0
- package/dist/barcode/decodeSummary.d.ts +45 -0
- package/dist/barcode/decodeSummary.d.ts.map +1 -0
- package/dist/barcode/decodeSummary.js +23 -0
- package/dist/barcode/index.d.ts +5 -0
- package/dist/barcode/index.d.ts.map +1 -0
- package/dist/barcode/index.js +4 -0
- package/dist/camera/Camera.d.ts +37 -0
- package/dist/camera/Camera.d.ts.map +1 -0
- package/dist/camera/Camera.js +453 -0
- package/dist/camera/acquireCamera.d.ts +29 -0
- package/dist/camera/acquireCamera.d.ts.map +1 -0
- package/dist/camera/acquireCamera.js +224 -0
- package/dist/camera/cameraSignals.d.ts +23 -0
- package/dist/camera/cameraSignals.d.ts.map +1 -0
- package/dist/camera/cameraSignals.js +32 -0
- package/dist/camera/getUserMediaIntegrity.d.ts +72 -0
- package/dist/camera/getUserMediaIntegrity.d.ts.map +1 -0
- package/dist/camera/getUserMediaIntegrity.js +256 -0
- package/dist/camera/index.d.ts +6 -0
- package/dist/camera/index.d.ts.map +1 -0
- package/dist/camera/index.js +5 -0
- package/dist/camera/isVirtualCamera.d.ts +10 -0
- package/dist/camera/isVirtualCamera.d.ts.map +1 -0
- package/dist/camera/isVirtualCamera.js +11 -0
- package/dist/client/IdmissionClient.d.ts +151 -0
- package/dist/client/IdmissionClient.d.ts.map +1 -0
- package/dist/client/IdmissionClient.js +638 -0
- package/dist/client/additionalDocument.d.ts +14 -0
- package/dist/client/additionalDocument.d.ts.map +1 -0
- package/dist/client/additionalDocument.js +24 -0
- package/dist/client/artifacts.d.ts +146 -0
- package/dist/client/artifacts.d.ts.map +1 -0
- package/dist/client/artifacts.js +1 -0
- package/dist/client/blobToB64.d.ts +2 -0
- package/dist/client/blobToB64.d.ts.map +1 -0
- package/dist/client/blobToB64.js +17 -0
- package/dist/client/endpoints.d.ts +7 -0
- package/dist/client/endpoints.d.ts.map +1 -0
- package/dist/client/endpoints.js +59 -0
- package/dist/client/errors.d.ts +20 -0
- package/dist/client/errors.d.ts.map +1 -0
- package/dist/client/errors.js +45 -0
- package/dist/client/index.d.ts +23 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +38 -0
- package/dist/client/payload.d.ts +36 -0
- package/dist/client/payload.d.ts.map +1 -0
- package/dist/client/payload.js +397 -0
- package/dist/client/sessionMachine.d.ts +26 -0
- package/dist/client/sessionMachine.d.ts.map +1 -0
- package/dist/client/sessionMachine.js +23 -0
- package/dist/client/submissionMetadata.d.ts +31 -0
- package/dist/client/submissionMetadata.d.ts.map +1 -0
- package/dist/client/submissionMetadata.js +90 -0
- package/dist/client/timings.d.ts +49 -0
- package/dist/client/timings.d.ts.map +1 -0
- package/dist/client/timings.js +32 -0
- package/dist/client/types.d.ts +305 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +18 -0
- package/dist/client/upload.d.ts +60 -0
- package/dist/client/upload.d.ts.map +1 -0
- package/dist/client/upload.js +313 -0
- package/dist/client/uploadedDocument.d.ts +7 -0
- package/dist/client/uploadedDocument.d.ts.map +1 -0
- package/dist/client/uploadedDocument.js +4 -0
- package/dist/client/urls.d.ts +30 -0
- package/dist/client/urls.d.ts.map +1 -0
- package/dist/client/urls.js +73 -0
- package/dist/client/validateSession.d.ts +7 -0
- package/dist/client/validateSession.d.ts.map +1 -0
- package/dist/client/validateSession.js +63 -0
- package/dist/config/cdn.d.ts +2 -0
- package/dist/config/cdn.d.ts.map +1 -0
- package/dist/config/cdn.js +1 -0
- package/dist/diagnostics/buffer.d.ts +8 -0
- package/dist/diagnostics/buffer.d.ts.map +1 -0
- package/dist/diagnostics/buffer.js +25 -0
- package/dist/diagnostics/envCapability.d.ts +3 -0
- package/dist/diagnostics/envCapability.d.ts.map +1 -0
- package/dist/diagnostics/envCapability.js +40 -0
- package/dist/diagnostics/floodControl.d.ts +6 -0
- package/dist/diagnostics/floodControl.d.ts.map +1 -0
- package/dist/diagnostics/floodControl.js +29 -0
- package/dist/diagnostics/index.d.ts +8 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +17 -0
- package/dist/diagnostics/install.d.ts +20 -0
- package/dist/diagnostics/install.d.ts.map +1 -0
- package/dist/diagnostics/install.js +159 -0
- package/dist/diagnostics/redaction.d.ts +7 -0
- package/dist/diagnostics/redaction.d.ts.map +1 -0
- package/dist/diagnostics/redaction.js +73 -0
- package/dist/diagnostics/transport.d.ts +15 -0
- package/dist/diagnostics/transport.d.ts.map +1 -0
- package/dist/diagnostics/transport.js +35 -0
- package/dist/diagnostics/types.d.ts +59 -0
- package/dist/diagnostics/types.d.ts.map +1 -0
- package/dist/diagnostics/types.js +1 -0
- package/dist/documentCapture/controller.d.ts +35 -0
- package/dist/documentCapture/controller.d.ts.map +1 -0
- package/dist/documentCapture/controller.js +254 -0
- package/dist/documentCapture/index.d.ts +4 -0
- package/dist/documentCapture/index.d.ts.map +1 -0
- package/dist/documentCapture/index.js +8 -0
- package/dist/documentCapture/reducer.d.ts +31 -0
- package/dist/documentCapture/reducer.d.ts.map +1 -0
- package/dist/documentCapture/reducer.js +87 -0
- package/dist/documentCapture/state.d.ts +49 -0
- package/dist/documentCapture/state.d.ts.map +1 -0
- package/dist/documentCapture/state.js +36 -0
- package/dist/idCapture/controller.d.ts +228 -0
- package/dist/idCapture/controller.d.ts.map +1 -0
- package/dist/idCapture/controller.js +1453 -0
- package/dist/idCapture/errors.d.ts +36 -0
- package/dist/idCapture/errors.d.ts.map +1 -0
- package/dist/idCapture/errors.js +18 -0
- package/dist/idCapture/guidance.d.ts +80 -0
- package/dist/idCapture/guidance.d.ts.map +1 -0
- package/dist/idCapture/guidance.js +143 -0
- package/dist/idCapture/index.d.ts +22 -0
- package/dist/idCapture/index.d.ts.map +1 -0
- package/dist/idCapture/index.js +46 -0
- package/dist/idCapture/phase.d.ts +10 -0
- package/dist/idCapture/phase.d.ts.map +1 -0
- package/dist/idCapture/phase.js +28 -0
- package/dist/idCapture/pipeline.d.ts +176 -0
- package/dist/idCapture/pipeline.d.ts.map +1 -0
- package/dist/idCapture/pipeline.js +1028 -0
- package/dist/idCapture/reducer.d.ts +3 -0
- package/dist/idCapture/reducer.d.ts.map +1 -0
- package/dist/idCapture/reducer.js +661 -0
- package/dist/idCapture/requirements.d.ts +10 -0
- package/dist/idCapture/requirements.d.ts.map +1 -0
- package/dist/idCapture/requirements.js +43 -0
- package/dist/idCapture/stabilizer.d.ts +2 -0
- package/dist/idCapture/stabilizer.d.ts.map +1 -0
- package/dist/idCapture/stabilizer.js +4 -0
- package/dist/idCapture/state.d.ts +426 -0
- package/dist/idCapture/state.d.ts.map +1 -0
- package/dist/idCapture/state.js +91 -0
- package/dist/idCapture/submit.d.ts +33 -0
- package/dist/idCapture/submit.d.ts.map +1 -0
- package/dist/idCapture/submit.js +105 -0
- package/dist/idCapture/types.d.ts +20 -0
- package/dist/idCapture/types.d.ts.map +1 -0
- package/dist/idCapture/types.js +12 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/liveness/challengeGeometry.d.ts +66 -0
- package/dist/liveness/challengeGeometry.d.ts.map +1 -0
- package/dist/liveness/challengeGeometry.js +226 -0
- package/dist/liveness/challengeSequence.d.ts +49 -0
- package/dist/liveness/challengeSequence.d.ts.map +1 -0
- package/dist/liveness/challengeSequence.js +71 -0
- package/dist/liveness/index.d.ts +4 -0
- package/dist/liveness/index.d.ts.map +1 -0
- package/dist/liveness/index.js +3 -0
- package/dist/liveness/livenessResult.d.ts +11 -0
- package/dist/liveness/livenessResult.d.ts.map +1 -0
- package/dist/liveness/livenessResult.js +16 -0
- package/dist/models/BarcodeReadability.d.ts +36 -0
- package/dist/models/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/BarcodeReadability.js +71 -0
- package/dist/models/CapabilityProbing.d.ts +25 -0
- package/dist/models/CapabilityProbing.d.ts.map +1 -0
- package/dist/models/CapabilityProbing.js +172 -0
- package/dist/models/DocumentDetection.d.ts +96 -0
- package/dist/models/DocumentDetection.d.ts.map +1 -0
- package/dist/models/DocumentDetection.js +257 -0
- package/dist/models/FaceDetection.d.ts +21 -0
- package/dist/models/FaceDetection.d.ts.map +1 -0
- package/dist/models/FaceDetection.js +4 -0
- package/dist/models/Focus.d.ts +36 -0
- package/dist/models/Focus.d.ts.map +1 -0
- package/dist/models/Focus.js +69 -0
- package/dist/models/FrameLoop.d.ts +13 -0
- package/dist/models/FrameLoop.d.ts.map +1 -0
- package/dist/models/FrameLoop.js +56 -0
- package/dist/models/VisionRuntime.d.ts +18 -0
- package/dist/models/VisionRuntime.d.ts.map +1 -0
- package/dist/models/VisionRuntime.js +158 -0
- package/dist/models/defaults/BarcodeReadability.d.ts +3 -0
- package/dist/models/defaults/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/defaults/BarcodeReadability.js +3 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.d.ts +3 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/BarcodeReadabilityLiteRT.js +3 -0
- package/dist/models/defaults/DocumentDetector.d.ts +3 -0
- package/dist/models/defaults/DocumentDetector.d.ts.map +1 -0
- package/dist/models/defaults/DocumentDetector.js +3 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts +3 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/DocumentDetectorLiteRT.js +3 -0
- package/dist/models/defaults/FaceDetector.d.ts +3 -0
- package/dist/models/defaults/FaceDetector.d.ts.map +1 -0
- package/dist/models/defaults/FaceDetector.js +3 -0
- package/dist/models/defaults/FaceLandmarker.d.ts +3 -0
- package/dist/models/defaults/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/defaults/FaceLandmarker.js +8 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.d.ts +3 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/FaceLandmarkerLiteRT.js +3 -0
- package/dist/models/defaults/Focus.d.ts +3 -0
- package/dist/models/defaults/Focus.d.ts.map +1 -0
- package/dist/models/defaults/Focus.js +3 -0
- package/dist/models/defaults/FocusLiteRT.d.ts +3 -0
- package/dist/models/defaults/FocusLiteRT.d.ts.map +1 -0
- package/dist/models/defaults/FocusLiteRT.js +3 -0
- package/dist/models/defaults/index.d.ts +31 -0
- package/dist/models/defaults/index.d.ts.map +1 -0
- package/dist/models/defaults/index.js +38 -0
- package/dist/models/helpers.d.ts +25 -0
- package/dist/models/helpers.d.ts.map +1 -0
- package/dist/models/helpers.js +98 -0
- package/dist/models/index.d.ts +15 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +14 -0
- package/dist/models/modelLifecycle.d.ts +26 -0
- package/dist/models/modelLifecycle.d.ts.map +1 -0
- package/dist/models/modelLifecycle.js +137 -0
- package/dist/models/occlusion.d.ts +20 -0
- package/dist/models/occlusion.d.ts.map +1 -0
- package/dist/models/occlusion.js +109 -0
- package/dist/models/passportBooklet.d.ts +34 -0
- package/dist/models/passportBooklet.d.ts.map +1 -0
- package/dist/models/passportBooklet.js +152 -0
- package/dist/models/preloadModels.d.ts +42 -0
- package/dist/models/preloadModels.d.ts.map +1 -0
- package/dist/models/preloadModels.js +204 -0
- package/dist/models/providers/litert/BarcodeReadability.d.ts +11 -0
- package/dist/models/providers/litert/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/providers/litert/BarcodeReadability.js +135 -0
- package/dist/models/providers/litert/CapabilityProbe.d.ts +3 -0
- package/dist/models/providers/litert/CapabilityProbe.d.ts.map +1 -0
- package/dist/models/providers/litert/CapabilityProbe.js +44 -0
- package/dist/models/providers/litert/DocumentDetection.d.ts +18 -0
- package/dist/models/providers/litert/DocumentDetection.d.ts.map +1 -0
- package/dist/models/providers/litert/DocumentDetection.js +194 -0
- package/dist/models/providers/litert/FaceDetection.d.ts +11 -0
- package/dist/models/providers/litert/FaceDetection.d.ts.map +1 -0
- package/dist/models/providers/litert/FaceDetection.js +204 -0
- package/dist/models/providers/litert/FaceLandmarker.d.ts +11 -0
- package/dist/models/providers/litert/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/providers/litert/FaceLandmarker.js +199 -0
- package/dist/models/providers/litert/Focus.d.ts +11 -0
- package/dist/models/providers/litert/Focus.d.ts.map +1 -0
- package/dist/models/providers/litert/Focus.js +141 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.d.ts +6 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/barcodeReadabilityPrePost.js +68 -0
- package/dist/models/providers/litert/blazeFacePrePost.d.ts +30 -0
- package/dist/models/providers/litert/blazeFacePrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/blazeFacePrePost.js +206 -0
- package/dist/models/providers/litert/docDetectPrePost.d.ts +25 -0
- package/dist/models/providers/litert/docDetectPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/docDetectPrePost.js +197 -0
- package/dist/models/providers/litert/faceMeshPrePost.d.ts +23 -0
- package/dist/models/providers/litert/faceMeshPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/faceMeshPrePost.js +86 -0
- package/dist/models/providers/litert/focusPrePost.d.ts +6 -0
- package/dist/models/providers/litert/focusPrePost.d.ts.map +1 -0
- package/dist/models/providers/litert/focusPrePost.js +67 -0
- package/dist/models/providers/litert/runtime.d.ts +14 -0
- package/dist/models/providers/litert/runtime.d.ts.map +1 -0
- package/dist/models/providers/litert/runtime.js +83 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.d.ts +11 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/BarcodeReadability.js +68 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.d.ts +2 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/CapabilityProbe.js +14 -0
- package/dist/models/providers/mediapipe/DocumentDetection.d.ts +12 -0
- package/dist/models/providers/mediapipe/DocumentDetection.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/DocumentDetection.js +90 -0
- package/dist/models/providers/mediapipe/FaceDetection.d.ts +11 -0
- package/dist/models/providers/mediapipe/FaceDetection.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/FaceDetection.js +93 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.d.ts +46 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/FaceLandmarker.js +166 -0
- package/dist/models/providers/mediapipe/Focus.d.ts +11 -0
- package/dist/models/providers/mediapipe/Focus.d.ts.map +1 -0
- package/dist/models/providers/mediapipe/Focus.js +51 -0
- package/dist/models/runtimeSelection.d.ts +5 -0
- package/dist/models/runtimeSelection.d.ts.map +1 -0
- package/dist/models/runtimeSelection.js +21 -0
- package/dist/selfieCapture/challengeRunner.d.ts +38 -0
- package/dist/selfieCapture/challengeRunner.d.ts.map +1 -0
- package/dist/selfieCapture/challengeRunner.js +181 -0
- package/dist/selfieCapture/controller.d.ts +166 -0
- package/dist/selfieCapture/controller.d.ts.map +1 -0
- package/dist/selfieCapture/controller.js +1253 -0
- package/dist/selfieCapture/faceTracking.d.ts +67 -0
- package/dist/selfieCapture/faceTracking.d.ts.map +1 -0
- package/dist/selfieCapture/faceTracking.js +158 -0
- package/dist/selfieCapture/guidance.d.ts +24 -0
- package/dist/selfieCapture/guidance.d.ts.map +1 -0
- package/dist/selfieCapture/guidance.js +41 -0
- package/dist/selfieCapture/index.d.ts +18 -0
- package/dist/selfieCapture/index.d.ts.map +1 -0
- package/dist/selfieCapture/index.js +11 -0
- package/dist/selfieCapture/lighting.d.ts +36 -0
- package/dist/selfieCapture/lighting.d.ts.map +1 -0
- package/dist/selfieCapture/lighting.js +95 -0
- package/dist/selfieCapture/livenessMachine.d.ts +66 -0
- package/dist/selfieCapture/livenessMachine.d.ts.map +1 -0
- package/dist/selfieCapture/livenessMachine.js +137 -0
- package/dist/selfieCapture/pipeline.d.ts +42 -0
- package/dist/selfieCapture/pipeline.d.ts.map +1 -0
- package/dist/selfieCapture/pipeline.js +282 -0
- package/dist/selfieCapture/reducer.d.ts +35 -0
- package/dist/selfieCapture/reducer.d.ts.map +1 -0
- package/dist/selfieCapture/reducer.js +143 -0
- package/dist/selfieCapture/state.d.ts +40 -0
- package/dist/selfieCapture/state.d.ts.map +1 -0
- package/dist/selfieCapture/state.js +36 -0
- package/dist/selfieCapture/testing/challengeFixtures.d.ts +43 -0
- package/dist/selfieCapture/testing/challengeFixtures.d.ts.map +1 -0
- package/dist/selfieCapture/testing/challengeFixtures.js +43 -0
- package/dist/signature/frameDecode.d.ts +48 -0
- package/dist/signature/frameDecode.d.ts.map +1 -0
- package/dist/signature/frameDecode.js +491 -0
- package/dist/signature/index.d.ts +5 -0
- package/dist/signature/index.d.ts.map +1 -0
- package/dist/signature/index.js +4 -0
- package/dist/signature/metadata.d.ts +63 -0
- package/dist/signature/metadata.d.ts.map +1 -0
- package/dist/signature/metadata.js +1 -0
- package/dist/signature/quality.d.ts +169 -0
- package/dist/signature/quality.d.ts.map +1 -0
- package/dist/signature/quality.js +186 -0
- package/dist/signature/signatureValidity.d.ts +149 -0
- package/dist/signature/signatureValidity.d.ts.map +1 -0
- package/dist/signature/signatureValidity.js +305 -0
- package/dist/signatureCapture/controller.d.ts +67 -0
- package/dist/signatureCapture/controller.d.ts.map +1 -0
- package/dist/signatureCapture/controller.js +534 -0
- package/dist/signatureCapture/guidance.d.ts +9 -0
- package/dist/signatureCapture/guidance.d.ts.map +1 -0
- package/dist/signatureCapture/guidance.js +7 -0
- package/dist/signatureCapture/index.d.ts +6 -0
- package/dist/signatureCapture/index.d.ts.map +1 -0
- package/dist/signatureCapture/index.js +5 -0
- package/dist/signatureCapture/pipeline.d.ts +111 -0
- package/dist/signatureCapture/pipeline.d.ts.map +1 -0
- package/dist/signatureCapture/pipeline.js +680 -0
- package/dist/signatureCapture/reducer.d.ts +42 -0
- package/dist/signatureCapture/reducer.d.ts.map +1 -0
- package/dist/signatureCapture/reducer.js +159 -0
- package/dist/signatureCapture/state.d.ts +92 -0
- package/dist/signatureCapture/state.d.ts.map +1 -0
- package/dist/signatureCapture/state.js +24 -0
- package/dist/utils/canvas.d.ts +4 -0
- package/dist/utils/canvas.d.ts.map +1 -0
- package/dist/utils/canvas.js +21 -0
- package/dist/utils/cropping.d.ts +8 -0
- package/dist/utils/cropping.d.ts.map +1 -0
- package/dist/utils/cropping.js +85 -0
- package/dist/utils/dataUrlToBase64.d.ts +7 -0
- package/dist/utils/dataUrlToBase64.d.ts.map +1 -0
- package/dist/utils/dataUrlToBase64.js +67 -0
- package/dist/utils/getFrameDimensions.d.ts +3 -0
- package/dist/utils/getFrameDimensions.d.ts.map +1 -0
- package/dist/utils/getFrameDimensions.js +12 -0
- package/dist/utils/isMobile.d.ts +3 -0
- package/dist/utils/isMobile.d.ts.map +1 -0
- package/dist/utils/isMobile.js +36 -0
- package/dist/utils/logger.d.ts +19 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +25 -0
- package/dist/utils/platform.d.ts +4 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +11 -0
- package/dist/utils/stabilizer.d.ts +26 -0
- package/dist/utils/stabilizer.d.ts.map +1 -0
- package/dist/utils/stabilizer.js +65 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +1 -0
- package/dist/videoIdCapture/controller.d.ts +108 -0
- package/dist/videoIdCapture/controller.d.ts.map +1 -0
- package/dist/videoIdCapture/controller.js +833 -0
- package/dist/videoIdCapture/index.d.ts +5 -0
- package/dist/videoIdCapture/index.d.ts.map +1 -0
- package/dist/videoIdCapture/index.js +2 -0
- package/dist/videoIdCapture/state.d.ts +88 -0
- package/dist/videoIdCapture/state.d.ts.map +1 -0
- package/dist/videoIdCapture/state.js +67 -0
- package/package.json +111 -0
|
@@ -0,0 +1,1453 @@
|
|
|
1
|
+
// createIdCaptureController — the headless controller shell composing the
|
|
2
|
+
// pure flow reducer (reducer.ts — which owns the single-slot guidance
|
|
3
|
+
// stabilizer, stepped once per detection frame), the detection pipeline
|
|
4
|
+
// (pipeline.ts), camera acquisition (camera/acquireCamera.ts) and guidance
|
|
5
|
+
// derivation (guidance.ts) into one framework-free surface.
|
|
6
|
+
//
|
|
7
|
+
// The effect layer is a line-by-line port of the wizard's side effects:
|
|
8
|
+
// - sdk2/src/components/id_capture/IdCaptureWizard.tsx (cited per effect)
|
|
9
|
+
// - sdk2/src/components/id_capture/IdCapture.tsx:126,151-233 (auto-capture)
|
|
10
|
+
// - sdk2/src/components/id_capture/IdCaptureStateProvider.tsx:1246-1270
|
|
11
|
+
// (override -> requiredDocumentType 'none'; resetWizard on unmount)
|
|
12
|
+
// React effect mechanics translate as: one store subscription diffing the
|
|
13
|
+
// previous snapshot against the next (deps-array analog), timers tracked in a
|
|
14
|
+
// Map keyed by effect name and cleared on state exit + detach (effect-cleanup
|
|
15
|
+
// analog).
|
|
16
|
+
import { createStore } from 'zustand/vanilla';
|
|
17
|
+
import { initialFlowState, } from './state';
|
|
18
|
+
import { reduceIdCapture } from './reducer';
|
|
19
|
+
import { createDetectionPipeline, defaultIdCaptureThresholds, } from './pipeline';
|
|
20
|
+
import { deriveGuidance, deriveInstruction, deriveRequestedAction, isSatisfiedCode, } from './guidance';
|
|
21
|
+
import { derivePhase } from './phase';
|
|
22
|
+
import { CaptureAttachError } from './errors';
|
|
23
|
+
import { acquireCamera, } from '../camera/acquireCamera';
|
|
24
|
+
import { decodePDF417, decodePDF417WithDetails, getZxingAttemptCount, resetZxingAttemptCount, } from '../barcode/NativeBarcodeDecoder';
|
|
25
|
+
import { summarizeBarcodeDecode, } from '../barcode/decodeSummary';
|
|
26
|
+
import { defaultDocumentDetectionBoundaries, } from '../models/DocumentDetection';
|
|
27
|
+
import { defaultOcclusionGuidanceEnabled, resolveRuntime, } from '../models/runtimeSelection';
|
|
28
|
+
import { dataUrlToBase64 } from '../utils/dataUrlToBase64';
|
|
29
|
+
import { log } from '../utils/logger';
|
|
30
|
+
import { buildIdCaptureArtifacts } from './submit';
|
|
31
|
+
import { NetworkError } from '../client/errors';
|
|
32
|
+
// sdk2/src/components/id_capture/IdCaptureWizard.tsx:253-262
|
|
33
|
+
const lastDocumentDetectedAtDefaults = {
|
|
34
|
+
idCardFront: null,
|
|
35
|
+
idCardBack: null,
|
|
36
|
+
passport: null,
|
|
37
|
+
singlePage: null,
|
|
38
|
+
none: null,
|
|
39
|
+
};
|
|
40
|
+
const isCapturingState = (s) =>
|
|
41
|
+
// wizard 315-317: isCapturing spans live capture and barcode recapture
|
|
42
|
+
s === 'capturing' || s === 'requestingBetterBarcode';
|
|
43
|
+
// IdCapture.tsx:490-493
|
|
44
|
+
const timeSince = (t, now) => {
|
|
45
|
+
if (!t)
|
|
46
|
+
return 0;
|
|
47
|
+
return Math.abs(now.getTime() - t.getTime());
|
|
48
|
+
};
|
|
49
|
+
export function createIdCaptureController(config) {
|
|
50
|
+
// setTimeout/clearTimeout/fetch are bound to globalThis: browsers' native
|
|
51
|
+
// implementations are branded WindowOrWorkerGlobalScope members and throw
|
|
52
|
+
// `TypeError: Illegal invocation` unless invoked with the real global as
|
|
53
|
+
// their receiver. Every call site below invokes these as methods of this
|
|
54
|
+
// `io` object (`io.setTimeout(...)`, `io.clearTimeout(...)`,
|
|
55
|
+
// `io.fetch(...)`), which makes the receiver `io`, not the global -- an
|
|
56
|
+
// unbound reference fails the brand check. Node's timers/fetch tolerate
|
|
57
|
+
// the detached receiver, which is why this was invisible to unit tests
|
|
58
|
+
// that don't inject a receiver-strict fake.
|
|
59
|
+
const io = {
|
|
60
|
+
now: config.io?.now ?? (() => new Date()),
|
|
61
|
+
setTimeout: config.io?.setTimeout ?? setTimeout.bind(globalThis),
|
|
62
|
+
clearTimeout: config.io?.clearTimeout ?? clearTimeout.bind(globalThis),
|
|
63
|
+
acquireCamera: config.io?.acquireCamera ?? acquireCamera,
|
|
64
|
+
createPipeline: config.io?.createPipeline ?? createDetectionPipeline,
|
|
65
|
+
decodePDF417: config.io?.decodePDF417 ?? decodePDF417,
|
|
66
|
+
decodePDF417WithDetails: config.io?.decodePDF417WithDetails ?? decodePDF417WithDetails,
|
|
67
|
+
getZxingAttemptCount: config.io?.getZxingAttemptCount ?? getZxingAttemptCount,
|
|
68
|
+
resetZxingAttemptCount: config.io?.resetZxingAttemptCount ?? resetZxingAttemptCount,
|
|
69
|
+
fetch: config.io?.fetch ?? fetch.bind(globalThis),
|
|
70
|
+
};
|
|
71
|
+
// ---------------------------------------------------------------------
|
|
72
|
+
// Resolved config (wizard prop defaults, IdCaptureWizard.tsx:274-306, and
|
|
73
|
+
// the occlusion-guidance runtime-conditional defaults from the wrapper,
|
|
74
|
+
// IdCaptureWizard.tsx:1636-1647).
|
|
75
|
+
// ---------------------------------------------------------------------
|
|
76
|
+
const captureRequirement = config.captureRequirement ?? 'idCardOrPassport';
|
|
77
|
+
const defaultGuidanceOn = defaultOcclusionGuidanceEnabled(resolveRuntime(config.documentDetectorRuntime, config.runtime));
|
|
78
|
+
const enableFingerOcclusionGuidance = config.enableFingerOcclusionGuidance ?? defaultGuidanceOn;
|
|
79
|
+
const enableGlareOcclusionGuidance = config.enableGlareOcclusionGuidance ?? defaultGuidanceOn;
|
|
80
|
+
const enableHologramOcclusionGuidance = config.enableHologramOcclusionGuidance ?? defaultGuidanceOn;
|
|
81
|
+
// wizard 306 + 394: aggressive parsing is the default mode
|
|
82
|
+
const aggressiveModeEnabled = (config.barcodeParsingMode ?? 'aggressive') === 'aggressive';
|
|
83
|
+
const barcodeRecaptureBboxGrowthPct = config.barcodeRecaptureBboxGrowthPct ?? 20;
|
|
84
|
+
const barcodeRecaptureMoveCloserTimeoutMs = config.barcodeRecaptureMoveCloserTimeoutMs ?? 10_000;
|
|
85
|
+
const barcodeRecaptureTimeoutMs = config.barcodeRecaptureTimeoutMs ?? 5000;
|
|
86
|
+
const documentDetectionThrottleMs = config.documentDetectionThrottleMs ?? 0;
|
|
87
|
+
const flipConfirmation = config.flipConfirmation ?? 'auto';
|
|
88
|
+
// ---------------------------------------------------------------------
|
|
89
|
+
// Store
|
|
90
|
+
// ---------------------------------------------------------------------
|
|
91
|
+
const internal = createStore(() => ({
|
|
92
|
+
...initialFlowState,
|
|
93
|
+
error: null,
|
|
94
|
+
submission: 'idle',
|
|
95
|
+
models: { ready: false, loadState: 'not-started', downloadProgress: 0 },
|
|
96
|
+
camera: { ready: false, isRearFacing: false, accessRequested: false },
|
|
97
|
+
recaptureGrowthSatisfied: false,
|
|
98
|
+
barcodeDecodeSummary: null,
|
|
99
|
+
}));
|
|
100
|
+
function dispatch(action) {
|
|
101
|
+
internal.setState((s) => ({ ...s, ...reduceIdCapture(s, action, io.now) }));
|
|
102
|
+
}
|
|
103
|
+
// ---------------------------------------------------------------------
|
|
104
|
+
// Non-reactive instance state (formerly wizard refs)
|
|
105
|
+
// ---------------------------------------------------------------------
|
|
106
|
+
let videoEl = null;
|
|
107
|
+
let cameraHandle = null;
|
|
108
|
+
let pipeline = null;
|
|
109
|
+
let pipelineLoaded = false;
|
|
110
|
+
let pipelineLoadFailed = false;
|
|
111
|
+
let attached = false;
|
|
112
|
+
let attaching = false;
|
|
113
|
+
let captureStartDeferred = false;
|
|
114
|
+
// The attachGeneration the in-flight doAttach belongs to (see doAttach).
|
|
115
|
+
let attachingGeneration = -1;
|
|
116
|
+
let active = true;
|
|
117
|
+
// Bumped by detach(). `active` alone cannot express staleness here: a
|
|
118
|
+
// re-attach sets it back to true, so an acquisition orphaned by the
|
|
119
|
+
// detach in between would find `active === true` and land anyway.
|
|
120
|
+
let attachGeneration = 0;
|
|
121
|
+
// Carry-forward (Task 6 review): sdk2's cameraStore remembers a continuity
|
|
122
|
+
// camera denial across requestCameraAccess attempts
|
|
123
|
+
// (cameraStore.tsx:176-195 gates selection on iphoneContinuityCameraDenied,
|
|
124
|
+
// :265-275 sets it). acquireCamera is one-shot, so the controller carries
|
|
125
|
+
// the memory and disables the preference on retries after a denial.
|
|
126
|
+
let continuityCameraDenied = false;
|
|
127
|
+
// Barcode-recapture growth gating (wizard 353-359)
|
|
128
|
+
let initialBarcodeBbox = null;
|
|
129
|
+
let recapturePhaseStarted = false;
|
|
130
|
+
// Generation counter standing in for the last-chance decode's `aborted`
|
|
131
|
+
// cleanup flag (wizard 1147/1188-1190) and for orphaning stale async work
|
|
132
|
+
// after detach.
|
|
133
|
+
let recaptureGeneration = 0;
|
|
134
|
+
// onDocumentDetected throttle memory (wizard 465-467)
|
|
135
|
+
let lastDocumentDetectedAt = {
|
|
136
|
+
...lastDocumentDetectedAtDefaults,
|
|
137
|
+
};
|
|
138
|
+
// Live boundaries mirror (the wizard reads documentDetectionBoundaries from
|
|
139
|
+
// context, 416-453; the controller tracks what it last set).
|
|
140
|
+
let currentBoundaries = {
|
|
141
|
+
...defaultDocumentDetectionBoundaries,
|
|
142
|
+
edgeMarginPct: config.documentEdgeDistancePct ?? 0,
|
|
143
|
+
};
|
|
144
|
+
// Capture-attempt accumulation for the submit bridge (Task 9; sdk2's
|
|
145
|
+
// idFrontCaptureAttempts/idBackCaptureAttempts/barcodeCaptureAttempts,
|
|
146
|
+
// SubmissionProvider.tsx:558-563 + 553). Bucketed by
|
|
147
|
+
// `requestedDocumentType` at capture time, exactly like logCaptureMetadata
|
|
148
|
+
// reads it off the store (wizard 469-491) -- `idCardBack` -> back,
|
|
149
|
+
// everything else -> front. Session-scoped: reset on detach(), not on
|
|
150
|
+
// retake() (sdk2's arrays live on the SubmissionProvider, which outlives
|
|
151
|
+
// individual wizard retakes within the same session).
|
|
152
|
+
let captureAttempts = { front: [], back: [], barcode: [] };
|
|
153
|
+
function recordCaptureAttempt(metadata, requestedDocumentType) {
|
|
154
|
+
if (requestedDocumentType === 'idCardBack') {
|
|
155
|
+
// logIdBackCaptureAttempt (SubmissionProvider.tsx:590-641): the id-back
|
|
156
|
+
// entry is STRIPPED of its barcode fields, which are re-routed into a
|
|
157
|
+
// separate BarcodeCaptureMetadata accumulator (the `barcode` bucket
|
|
158
|
+
// payload.ts's buildNoBarcodeOCRMetadata fallback counts).
|
|
159
|
+
const { bestBarcodeScore, barcodeBoundingBox, ...captureAttemptWithoutBarcode } = metadata;
|
|
160
|
+
captureAttempts.back.push(captureAttemptWithoutBarcode);
|
|
161
|
+
// :619-629 -- appended whenever a barcode score was recorded at all
|
|
162
|
+
// (0 counts: auto-capture stamps `bestBarcodeScore: bestBarcode?.score
|
|
163
|
+
// ?? 0`, so every auto back capture contributes an entry, barcode seen
|
|
164
|
+
// or not -- exactly like sdk2). The bounding box falls back to the
|
|
165
|
+
// document's own box when no barcode-specific one exists (:620-621).
|
|
166
|
+
if (bestBarcodeScore !== undefined && bestBarcodeScore !== null) {
|
|
167
|
+
captureAttempts.barcode.push({
|
|
168
|
+
captureTime: metadata.captureTime,
|
|
169
|
+
operationTime: metadata.operationTime,
|
|
170
|
+
bestBarcodeScore,
|
|
171
|
+
boundingBox: barcodeBoundingBox ?? metadata.boundingBox,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
// logIdFrontCaptureAttempt (SubmissionProvider.tsx:568-589): the full
|
|
177
|
+
// attempt, un-stripped; front captures never feed the barcode bucket.
|
|
178
|
+
captureAttempts.front.push(metadata);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// ---------------------------------------------------------------------
|
|
182
|
+
// Timers — Map keyed by effect name, cleared on state exit and detach
|
|
183
|
+
// ---------------------------------------------------------------------
|
|
184
|
+
const timers = new Map();
|
|
185
|
+
function armTimer(name, ms, fn) {
|
|
186
|
+
clearTimer(name);
|
|
187
|
+
timers.set(name, io.setTimeout(() => {
|
|
188
|
+
timers.delete(name);
|
|
189
|
+
fn();
|
|
190
|
+
}, ms));
|
|
191
|
+
}
|
|
192
|
+
function clearTimer(name) {
|
|
193
|
+
const handle = timers.get(name);
|
|
194
|
+
if (handle !== undefined) {
|
|
195
|
+
io.clearTimeout(handle);
|
|
196
|
+
timers.delete(name);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function clearAllTimers() {
|
|
200
|
+
for (const handle of timers.values())
|
|
201
|
+
io.clearTimeout(handle);
|
|
202
|
+
timers.clear();
|
|
203
|
+
}
|
|
204
|
+
// ---------------------------------------------------------------------
|
|
205
|
+
// Public-state derivation
|
|
206
|
+
// ---------------------------------------------------------------------
|
|
207
|
+
const listeners = new Set();
|
|
208
|
+
function toPublicState(s, raw) {
|
|
209
|
+
return {
|
|
210
|
+
...s,
|
|
211
|
+
phase: derivePhase(s),
|
|
212
|
+
// The held code drives every green surface (sdk2 PR #254): `satisfied`
|
|
213
|
+
// is derived from the held code, never raw.satisfied. Only
|
|
214
|
+
// detectedDocumentType is live — the satisfied pill's text interpolates
|
|
215
|
+
// the current frame's document type while the code is held.
|
|
216
|
+
guidance: {
|
|
217
|
+
code: s.guidance.displayed,
|
|
218
|
+
satisfied: isSatisfiedCode(s.guidance.displayed),
|
|
219
|
+
detectedDocumentType: raw.detectedDocumentType,
|
|
220
|
+
},
|
|
221
|
+
rawGuidance: raw,
|
|
222
|
+
instruction: deriveInstruction(s),
|
|
223
|
+
requestedAction: deriveRequestedAction(s),
|
|
224
|
+
// wizard 1404-1407
|
|
225
|
+
progress: s.goodFramesThreshold > 0
|
|
226
|
+
? Math.min(s.goodFramesCount / s.goodFramesThreshold, 1)
|
|
227
|
+
: 0,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
// Last published snapshot. getState() must be referentially stable between
|
|
231
|
+
// changes (React's useSyncExternalStore contract: "getSnapshot should be
|
|
232
|
+
// cached", or every render loops). publish() runs on every internal store
|
|
233
|
+
// change (the store subscription below) — the only thing a snapshot derives
|
|
234
|
+
// from (the held guidance lives in the reducer's state, re-evaluated once
|
|
235
|
+
// per detection frame; there is no wall-clock re-eval timer) — so
|
|
236
|
+
// refreshing the cache there makes it exhaustive; getState() only computes
|
|
237
|
+
// when nothing has been published yet.
|
|
238
|
+
let snapshot = null;
|
|
239
|
+
function publish() {
|
|
240
|
+
const s = internal.getState();
|
|
241
|
+
const raw = deriveGuidance(s, s.recaptureGrowthSatisfied);
|
|
242
|
+
const pub = toPublicState(s, raw);
|
|
243
|
+
snapshot = pub;
|
|
244
|
+
for (const cb of [...listeners])
|
|
245
|
+
cb(pub);
|
|
246
|
+
}
|
|
247
|
+
// ---------------------------------------------------------------------
|
|
248
|
+
// Model-state aggregation
|
|
249
|
+
// ---------------------------------------------------------------------
|
|
250
|
+
function handleModelState(aggregate) {
|
|
251
|
+
internal.setState({
|
|
252
|
+
models: {
|
|
253
|
+
ready: aggregate.ready,
|
|
254
|
+
loadState: aggregate.modelLoadState,
|
|
255
|
+
downloadProgress: aggregate.modelDownloadProgress,
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
// A model error AFTER a successful attach (e.g. the all-zero self-heal,
|
|
259
|
+
// DocumentDetectionModelProvider.tsx:209-216) flips sdk2 into fallback
|
|
260
|
+
// mode (wizard 463: isFallbackMode = forceFallbackMode || modelError).
|
|
261
|
+
// The headless translation of "fallback UI" is a typed error state.
|
|
262
|
+
// During attach the load() rejection carries the same error, so this only
|
|
263
|
+
// fires for post-attach failures.
|
|
264
|
+
if (attached && aggregate.modelError && !internal.getState().error) {
|
|
265
|
+
// The running pipeline is dead: mark it for rebuild so a later retry()
|
|
266
|
+
// genuinely re-creates and re-loads it — doAttach's `if
|
|
267
|
+
// (!pipelineLoaded)` gate would otherwise skip the reload and fake a
|
|
268
|
+
// recovery (clear the error over a pipeline that never reloads).
|
|
269
|
+
pipelineLoaded = false;
|
|
270
|
+
pipelineLoadFailed = true;
|
|
271
|
+
internal.setState({
|
|
272
|
+
error: {
|
|
273
|
+
code: 'MODEL_LOAD_FAILED',
|
|
274
|
+
recoverable: true,
|
|
275
|
+
model: aggregate.failedModel ?? 'documentDetector',
|
|
276
|
+
cause: aggregate.modelError,
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// ---------------------------------------------------------------------
|
|
282
|
+
// Pipeline creation (IdCaptureModelsProvider props from the wizard
|
|
283
|
+
// wrapper, IdCaptureWizard.tsx:1660-1688; thresholds from
|
|
284
|
+
// IdCapture.tsx:128-130; boundaries from wizard 416-428)
|
|
285
|
+
// ---------------------------------------------------------------------
|
|
286
|
+
function createPipelineInstance() {
|
|
287
|
+
const p = io.createPipeline({
|
|
288
|
+
video: () => videoEl,
|
|
289
|
+
documentDetectorRuntime: config.documentDetectorRuntime,
|
|
290
|
+
focusRuntime: config.focusRuntime,
|
|
291
|
+
barcodeReadabilityRuntime: config.barcodeReadabilityRuntime,
|
|
292
|
+
runtime: config.runtime,
|
|
293
|
+
allowSinglePageIdCapture: config.allowSinglePageIdCapture,
|
|
294
|
+
enableFingerOcclusionGuidance,
|
|
295
|
+
fingerOcclusionThresholds: config.fingerOcclusionThresholds,
|
|
296
|
+
enableGlareOcclusionGuidance,
|
|
297
|
+
enableHologramOcclusionGuidance,
|
|
298
|
+
requireFullPassportBooklet: config.requireFullPassportBooklet,
|
|
299
|
+
aggressiveModeEnabled,
|
|
300
|
+
aggressiveModeDecodeThreshold: config.aggressiveModeDecodeThreshold,
|
|
301
|
+
aggressiveModeDecodeIntervalMs: config.aggressiveModeDecodeIntervalMs,
|
|
302
|
+
// wizard 1682-1687
|
|
303
|
+
onAggressiveDecodeSuccess: (result) => dispatch({ type: 'aggressiveDecodeSuccess', payload: result }),
|
|
304
|
+
// pipeline counter actions forwarded to the reducer
|
|
305
|
+
// (IdCaptureModelsProvider.tsx:763-769)
|
|
306
|
+
onIdCaptureAction: (action) => dispatch(action),
|
|
307
|
+
modelAssetPaths: {
|
|
308
|
+
documentDetector: config.assets?.documentDetectionModelUrl,
|
|
309
|
+
focus: config.assets?.focusModelUrl,
|
|
310
|
+
},
|
|
311
|
+
modelLoadTimeoutMs: config.modelLoadTimeoutMs,
|
|
312
|
+
onModelStateChange: handleModelState,
|
|
313
|
+
});
|
|
314
|
+
p.onPredictionMade(handlePrediction);
|
|
315
|
+
// IdCapture.tsx:105 + 128-130
|
|
316
|
+
p.setThresholds(config.thresholds ?? defaultIdCaptureThresholds);
|
|
317
|
+
// wizard 416-428: documentEdgeDistancePct -> boundaries edgeMarginPct
|
|
318
|
+
currentBoundaries = {
|
|
319
|
+
...defaultDocumentDetectionBoundaries,
|
|
320
|
+
edgeMarginPct: config.documentEdgeDistancePct ?? 0,
|
|
321
|
+
};
|
|
322
|
+
p.setBoundaries(currentBoundaries);
|
|
323
|
+
return p;
|
|
324
|
+
}
|
|
325
|
+
// ---------------------------------------------------------------------
|
|
326
|
+
// requiredDocumentType mapping (wizard 1376-1394)
|
|
327
|
+
// ---------------------------------------------------------------------
|
|
328
|
+
function applyRequiredDocumentTypeMapping(requested) {
|
|
329
|
+
if (!pipeline)
|
|
330
|
+
return;
|
|
331
|
+
if (requested === 'idCardFront') {
|
|
332
|
+
if (captureRequirement === 'idCardOrPassport') {
|
|
333
|
+
pipeline.setRequiredDocumentType(['idCardFront', 'passport']);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
pipeline.setRequiredDocumentType('idCardFront');
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (requested === 'idCardBack')
|
|
340
|
+
pipeline.setRequiredDocumentType('idCardBack');
|
|
341
|
+
if (requested === 'passport')
|
|
342
|
+
pipeline.setRequiredDocumentType('passport');
|
|
343
|
+
}
|
|
344
|
+
// ---------------------------------------------------------------------
|
|
345
|
+
// Prediction handler (wizard 515-609)
|
|
346
|
+
// ---------------------------------------------------------------------
|
|
347
|
+
function handlePrediction(prediction) {
|
|
348
|
+
if (!attached || !pipeline)
|
|
349
|
+
return;
|
|
350
|
+
const s = internal.getState();
|
|
351
|
+
const thresholdKey = `${s.requestedDocumentType}DetectionThresholdMet`;
|
|
352
|
+
const thresholdMet = prediction[thresholdKey];
|
|
353
|
+
if (s.captureState === 'capturing' ||
|
|
354
|
+
s.captureState === 'requestingBetterBarcode') {
|
|
355
|
+
if (s.captureState === 'requestingBetterBarcode') {
|
|
356
|
+
// Barcode-recapture bbox-growth gate (wizard 529-570)
|
|
357
|
+
const growthPct = Math.max(0, Math.min(barcodeRecaptureBboxGrowthPct, 200));
|
|
358
|
+
const requiredMultiplier = 1 + growthPct / 100;
|
|
359
|
+
if (!recapturePhaseStarted) {
|
|
360
|
+
if (requiredMultiplier === 1) {
|
|
361
|
+
// Growth requirement disabled: begin recapture immediately.
|
|
362
|
+
recapturePhaseStarted = true;
|
|
363
|
+
setGrowthSatisfied(true);
|
|
364
|
+
pipeline.startBarcodeRecapturePhase();
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
const pdf417Box = prediction.bestPDF417?.box;
|
|
368
|
+
const frameWidth = prediction.frameWidth ?? 0;
|
|
369
|
+
const frameHeight = prediction.frameHeight ?? 0;
|
|
370
|
+
if (pdf417Box && frameWidth > 0 && frameHeight > 0) {
|
|
371
|
+
const widthRatio = pdf417Box.width / frameWidth;
|
|
372
|
+
const heightRatio = pdf417Box.height / frameHeight;
|
|
373
|
+
if (!initialBarcodeBbox) {
|
|
374
|
+
// First observed bbox when we enter recapture (wizard 551-553)
|
|
375
|
+
initialBarcodeBbox = { widthRatio, heightRatio };
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
const widthSatisfied = widthRatio >= initialBarcodeBbox.widthRatio * requiredMultiplier;
|
|
379
|
+
const heightSatisfied = heightRatio >= initialBarcodeBbox.heightRatio * requiredMultiplier;
|
|
380
|
+
if (widthSatisfied && heightSatisfied) {
|
|
381
|
+
recapturePhaseStarted = true;
|
|
382
|
+
setGrowthSatisfied(true);
|
|
383
|
+
pipeline.startBarcodeRecapturePhase();
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
// Throttled onDocumentDetected (wizard 572-587): fires the first time a
|
|
391
|
+
// type is seen, then only after documentDetectionThrottleMs elapses
|
|
392
|
+
// (never again when the throttle is 0).
|
|
393
|
+
if (prediction.detectedDocumentType !== 'none') {
|
|
394
|
+
const nowMs = io.now().getTime();
|
|
395
|
+
const last = lastDocumentDetectedAt[prediction.detectedDocumentType];
|
|
396
|
+
if (!last ||
|
|
397
|
+
(documentDetectionThrottleMs &&
|
|
398
|
+
nowMs - (last ?? 0) > documentDetectionThrottleMs)) {
|
|
399
|
+
lastDocumentDetectedAt[prediction.detectedDocumentType] = nowMs;
|
|
400
|
+
config.onDocumentDetected?.(prediction.detectedDocumentType);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
dispatch({ type: 'objectsDetected', payload: { prediction } });
|
|
404
|
+
// Auto-capture check runs on every objectsDetected-driven emit
|
|
405
|
+
// (IdCapture.tsx's shouldCapture effect re-evaluates per store change).
|
|
406
|
+
maybeAutoCapture();
|
|
407
|
+
}
|
|
408
|
+
else if (s.captureState === 'requestingFlip' &&
|
|
409
|
+
s.requestedDocumentType !== 'selfie' &&
|
|
410
|
+
thresholdMet) {
|
|
411
|
+
// Flip completes early once the (new) requested side crosses its
|
|
412
|
+
// detection threshold (wizard 593-600).
|
|
413
|
+
pipeline.resetBestFrame();
|
|
414
|
+
dispatch({ type: 'flipRequestCompleted' });
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function setGrowthSatisfied(value) {
|
|
418
|
+
if (internal.getState().recaptureGrowthSatisfied !== value) {
|
|
419
|
+
internal.setState({ recaptureGrowthSatisfied: value });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
// ---------------------------------------------------------------------
|
|
423
|
+
// Auto-capture (IdCapture.tsx:151-233)
|
|
424
|
+
// ---------------------------------------------------------------------
|
|
425
|
+
function maybeAutoCapture() {
|
|
426
|
+
if (!pipeline)
|
|
427
|
+
return;
|
|
428
|
+
const s = internal.getState();
|
|
429
|
+
// IdCapture.tsx:151-158 — occlusion blocks the current frame directly,
|
|
430
|
+
// ahead of the goodFramesCount decay grace period.
|
|
431
|
+
const shouldCapture = s.captureState === 'capturing' &&
|
|
432
|
+
s.goodFramesThresholdMet &&
|
|
433
|
+
!s.fingersOccludingDocument &&
|
|
434
|
+
!s.glareOccludingDocument &&
|
|
435
|
+
!s.hologramOccludingDocument &&
|
|
436
|
+
!s.capturing &&
|
|
437
|
+
timeSince(s.captureStartedAt, io.now()) >= 3000;
|
|
438
|
+
if (!shouldCapture)
|
|
439
|
+
return;
|
|
440
|
+
dispatch({ type: 'capturing' });
|
|
441
|
+
const bestFrame = pipeline.getBestFrame();
|
|
442
|
+
if (!bestFrame) {
|
|
443
|
+
// IdCapture.tsx:166-170 — a missing best frame is a soft failure, not a
|
|
444
|
+
// throw: captureFailed drives the CAPTURE_FAILED instruction.
|
|
445
|
+
dispatch({ type: 'captureFailed' });
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
// Passport MRZ guard (IdCapture.tsx:172-180): only ID-card/single-page
|
|
449
|
+
// captures legitimately produce a barcode.
|
|
450
|
+
const bestBarcode = bestFrame.documentType !== 'passport' ? pipeline.getBestBarcode() : null;
|
|
451
|
+
if (bestBarcode) {
|
|
452
|
+
dispatch({
|
|
453
|
+
type: 'barcodeCaptured',
|
|
454
|
+
payload: {
|
|
455
|
+
imageUrl: bestBarcode.canvas.toDataURL('image/jpeg', 0.95),
|
|
456
|
+
barcodeReadabilityScore: bestBarcode.score,
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
const { canvas, documentType, boundingBox, detectionScore, focusScore, maxGlareScore, maxHologramScore, } = bestFrame;
|
|
461
|
+
const { width, height } = canvas;
|
|
462
|
+
const imageUrl = canvas.toDataURL('image/jpeg', 0.95);
|
|
463
|
+
dispatch({ type: 'frameCaptured', payload: { imageUrl } });
|
|
464
|
+
const capturedDocumentType = documentType;
|
|
465
|
+
// Snapshot before the dispatches above can reset it (the sdk2 effect
|
|
466
|
+
// closed over state.captureStartedAt the same way, IdCapture.tsx:210).
|
|
467
|
+
const captureStartedAtMs = s.captureStartedAt?.getTime();
|
|
468
|
+
// IdCapture.tsx:209-225 — metadata assembly + documentCaptured behind a
|
|
469
|
+
// setTimeout(0).
|
|
470
|
+
armTimer('capture:finalize', 0, () => {
|
|
471
|
+
const captureTime = captureStartedAtMs
|
|
472
|
+
? io.now().getTime() - captureStartedAtMs
|
|
473
|
+
: 0;
|
|
474
|
+
const metadata = {
|
|
475
|
+
autoCapture: 'Y',
|
|
476
|
+
captureTime,
|
|
477
|
+
boundingBox,
|
|
478
|
+
barcodeBoundingBox: bestBarcode?.boundingBox,
|
|
479
|
+
bestDetectionScore: detectionScore,
|
|
480
|
+
bestFocusScore: focusScore,
|
|
481
|
+
bestMaxGlareScore: maxGlareScore,
|
|
482
|
+
bestMaxHologramScore: maxHologramScore,
|
|
483
|
+
bestBarcodeScore: bestBarcode?.score ?? 0,
|
|
484
|
+
};
|
|
485
|
+
// wizard onCapture (915-942) + logCaptureMetadata (469-494): stamp
|
|
486
|
+
// operationTime/captureMode before surfacing the metadata. The
|
|
487
|
+
// controller never enters sdk2's fallback/upload modes, so the mode is
|
|
488
|
+
// always 'Auto' here.
|
|
489
|
+
const current = internal.getState();
|
|
490
|
+
metadata.operationTime =
|
|
491
|
+
io.now().getTime() - (current.operationStartedAt ?? io.now()).getTime();
|
|
492
|
+
metadata.captureMode = 'Auto';
|
|
493
|
+
recordCaptureAttempt(metadata, current.requestedDocumentType);
|
|
494
|
+
config.onDocumentCaptured?.(metadata);
|
|
495
|
+
lastDocumentDetectedAt = { ...lastDocumentDetectedAtDefaults };
|
|
496
|
+
dispatch({
|
|
497
|
+
type: 'documentCaptured',
|
|
498
|
+
payload: {
|
|
499
|
+
imageData: imageUrl,
|
|
500
|
+
width,
|
|
501
|
+
height,
|
|
502
|
+
documentType: capturedDocumentType,
|
|
503
|
+
boundingBox: metadata.boundingBox,
|
|
504
|
+
detectionScore: metadata.bestDetectionScore,
|
|
505
|
+
focusScore: metadata.bestFocusScore,
|
|
506
|
+
maxGlareScore: metadata.bestMaxGlareScore,
|
|
507
|
+
maxHologramScore: metadata.bestMaxHologramScore,
|
|
508
|
+
},
|
|
509
|
+
});
|
|
510
|
+
dispatch({ type: 'captured' });
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
// ---------------------------------------------------------------------
|
|
514
|
+
// Decode chain on complete (wizard 616-913)
|
|
515
|
+
// ---------------------------------------------------------------------
|
|
516
|
+
function convertToStateDetails(details, imageUsed) {
|
|
517
|
+
// wizard 727-764
|
|
518
|
+
return {
|
|
519
|
+
nativeApi: details.nativeApi,
|
|
520
|
+
zxing: details.zxing,
|
|
521
|
+
imageUsed,
|
|
522
|
+
rotationsAttempted: {
|
|
523
|
+
original: {
|
|
524
|
+
nativeResult: details.rotationsAttempted.original.nativeResult,
|
|
525
|
+
zxingResult: details.rotationsAttempted.original.zxingResult,
|
|
526
|
+
},
|
|
527
|
+
rotated90: details.rotationsAttempted.rotated90
|
|
528
|
+
? {
|
|
529
|
+
nativeResult: details.rotationsAttempted.rotated90.nativeResult,
|
|
530
|
+
zxingResult: details.rotationsAttempted.rotated90.zxingResult,
|
|
531
|
+
}
|
|
532
|
+
: undefined,
|
|
533
|
+
rotated270: details.rotationsAttempted.rotated270
|
|
534
|
+
? {
|
|
535
|
+
nativeResult: details.rotationsAttempted.rotated270.nativeResult,
|
|
536
|
+
zxingResult: details.rotationsAttempted.rotated270.zxingResult,
|
|
537
|
+
}
|
|
538
|
+
: undefined,
|
|
539
|
+
},
|
|
540
|
+
fineRotationsAttempted: details.fineRotationsAttempted
|
|
541
|
+
? Object.fromEntries(Object.entries(details.fineRotationsAttempted).map(([key, val]) => [
|
|
542
|
+
key,
|
|
543
|
+
{ nativeResult: val.nativeResult, zxingResult: val.zxingResult },
|
|
544
|
+
]))
|
|
545
|
+
: undefined,
|
|
546
|
+
rotationApplied: details.rotationApplied,
|
|
547
|
+
startedAt: details.startedAt,
|
|
548
|
+
completedAt: details.completedAt,
|
|
549
|
+
durationMs: details.durationMs,
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
// wizard 690-697: image URL -> Blob through the injected fetch (data-url
|
|
553
|
+
// aware)
|
|
554
|
+
const imageToBlob = async (imageUrl) => {
|
|
555
|
+
const res = await io.fetch(imageUrl.startsWith('data:')
|
|
556
|
+
? imageUrl
|
|
557
|
+
: `data:image/jpeg;base64,${imageUrl}`);
|
|
558
|
+
return res.blob();
|
|
559
|
+
};
|
|
560
|
+
function runDecodeChain() {
|
|
561
|
+
const s = internal.getState();
|
|
562
|
+
// Guards (wizard 625-628): run once per wizard session
|
|
563
|
+
if (s.captureState !== 'complete')
|
|
564
|
+
return;
|
|
565
|
+
if (s.nativeBarcodeDecodeResult)
|
|
566
|
+
return;
|
|
567
|
+
if (s.nativeBarcodeDecoding)
|
|
568
|
+
return;
|
|
569
|
+
if (s.nativeBarcodeDecodeAttempted)
|
|
570
|
+
return;
|
|
571
|
+
// Aggressive short-circuit (wizard 631-675): reuse the in-capture decode
|
|
572
|
+
if (s.aggressiveModeDecodeComplete && s.aggressiveModeDecodeResult) {
|
|
573
|
+
const result = s.aggressiveModeDecodeResult;
|
|
574
|
+
dispatch({
|
|
575
|
+
type: 'nativeBarcodeDecoded',
|
|
576
|
+
payload: {
|
|
577
|
+
text: result.text,
|
|
578
|
+
format: result.format,
|
|
579
|
+
method: result.method,
|
|
580
|
+
rotationApplied: result.rotationApplied,
|
|
581
|
+
details: {
|
|
582
|
+
nativeApi: {
|
|
583
|
+
available: true,
|
|
584
|
+
supportsPDF417: true,
|
|
585
|
+
attempted: true,
|
|
586
|
+
result: 'success',
|
|
587
|
+
},
|
|
588
|
+
zxing: {
|
|
589
|
+
attempted: result.method === 'zxing',
|
|
590
|
+
result: result.method === 'zxing' ? 'success' : null,
|
|
591
|
+
},
|
|
592
|
+
imageUsed: 'primary',
|
|
593
|
+
rotationsAttempted: {
|
|
594
|
+
original: {
|
|
595
|
+
nativeResult: result.method === 'native' ? 'success' : null,
|
|
596
|
+
zxingResult: result.method === 'zxing' ? 'success' : null,
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
rotationApplied: result.rotationApplied,
|
|
600
|
+
startedAt: io.now().toISOString(),
|
|
601
|
+
completedAt: io.now().toISOString(),
|
|
602
|
+
durationMs: 0, // aggressive mode — already decoded during capture
|
|
603
|
+
},
|
|
604
|
+
},
|
|
605
|
+
});
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const barcodeImage = s.capturedDocuments.idBarcodeImage?.imageData;
|
|
609
|
+
if (!barcodeImage)
|
|
610
|
+
return;
|
|
611
|
+
dispatch({ type: 'nativeBarcodeDecodeStarted' });
|
|
612
|
+
// wizard 701-724. Read lazily so the recapture-completion dispatch burst
|
|
613
|
+
// (score/image updates that follow barcodeCaptured) has settled; sdk2's
|
|
614
|
+
// effect ran against the post-render, settled state.
|
|
615
|
+
const getFallbackImage = () => {
|
|
616
|
+
const now = internal.getState();
|
|
617
|
+
if (!now.initialCaptureBarcodeImage || !now.recaptureBarcodeImage) {
|
|
618
|
+
return null; // no fallback available
|
|
619
|
+
}
|
|
620
|
+
const recaptureWasChosen = now.recaptureBarcodeScore !== null &&
|
|
621
|
+
now.recaptureBarcodeScore > now.initialBarcodeScore;
|
|
622
|
+
// The fallback is the non-preferred image (the one not chosen)
|
|
623
|
+
return recaptureWasChosen
|
|
624
|
+
? now.initialCaptureBarcodeImage
|
|
625
|
+
: now.recaptureBarcodeImage;
|
|
626
|
+
};
|
|
627
|
+
const setSummary = (summary) => internal.setState({ barcodeDecodeSummary: summary });
|
|
628
|
+
// wizard 767-898. Decode failure is NON-fatal: details are recorded and
|
|
629
|
+
// the flow proceeds to review — never a phase 'error' transition.
|
|
630
|
+
void (async () => {
|
|
631
|
+
try {
|
|
632
|
+
const blob = await imageToBlob(barcodeImage);
|
|
633
|
+
const primaryResult = await io.decodePDF417WithDetails(blob, {
|
|
634
|
+
tryFineRotations: true,
|
|
635
|
+
});
|
|
636
|
+
let finalResult = primaryResult.result;
|
|
637
|
+
let finalDetails = primaryResult.details;
|
|
638
|
+
let imageUsed = 'primary';
|
|
639
|
+
// Primary failed -> try the fallback image (wizard 784-808)
|
|
640
|
+
if (!finalResult) {
|
|
641
|
+
const fallbackImage = getFallbackImage();
|
|
642
|
+
if (fallbackImage) {
|
|
643
|
+
const fallbackBlob = await imageToBlob(fallbackImage);
|
|
644
|
+
const fallbackResult = await io.decodePDF417WithDetails(fallbackBlob, {
|
|
645
|
+
tryFineRotations: true,
|
|
646
|
+
});
|
|
647
|
+
if (fallbackResult.result) {
|
|
648
|
+
finalResult = fallbackResult.result;
|
|
649
|
+
finalDetails = fallbackResult.details;
|
|
650
|
+
imageUsed = 'fallback';
|
|
651
|
+
}
|
|
652
|
+
// else: keep the primary details (wizard 800-806)
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const stateDetails = convertToStateDetails(finalDetails, imageUsed);
|
|
656
|
+
// wizard 812-823
|
|
657
|
+
setSummary(summarizeBarcodeDecode({
|
|
658
|
+
details: stateDetails,
|
|
659
|
+
decodeResult: finalResult
|
|
660
|
+
? {
|
|
661
|
+
method: finalResult.method,
|
|
662
|
+
rotationApplied: finalResult.rotationApplied,
|
|
663
|
+
}
|
|
664
|
+
: null,
|
|
665
|
+
pdf417DetectionCount: internal.getState().pdf417DetectionCount,
|
|
666
|
+
}));
|
|
667
|
+
if (finalResult) {
|
|
668
|
+
dispatch({
|
|
669
|
+
type: 'nativeBarcodeDecoded',
|
|
670
|
+
payload: {
|
|
671
|
+
text: finalResult.text,
|
|
672
|
+
format: finalResult.format,
|
|
673
|
+
method: finalResult.method,
|
|
674
|
+
rotationApplied: finalResult.rotationApplied,
|
|
675
|
+
details: stateDetails,
|
|
676
|
+
},
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
dispatch({
|
|
681
|
+
type: 'nativeBarcodeDecodeFailed',
|
|
682
|
+
payload: { details: stateDetails },
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
catch (err) {
|
|
687
|
+
// wizard 853-888: a thrown decode error is recorded as details, NOT
|
|
688
|
+
// surfaced as a phase error.
|
|
689
|
+
const errorDetails = {
|
|
690
|
+
nativeApi: {
|
|
691
|
+
available: false,
|
|
692
|
+
supportsPDF417: false,
|
|
693
|
+
attempted: false,
|
|
694
|
+
result: 'error',
|
|
695
|
+
errorMessage: err instanceof Error ? err.message : String(err),
|
|
696
|
+
},
|
|
697
|
+
zxing: {
|
|
698
|
+
attempted: false,
|
|
699
|
+
result: null,
|
|
700
|
+
},
|
|
701
|
+
imageUsed: null,
|
|
702
|
+
rotationsAttempted: {
|
|
703
|
+
original: { nativeResult: null, zxingResult: null },
|
|
704
|
+
},
|
|
705
|
+
rotationApplied: null,
|
|
706
|
+
startedAt: io.now().toISOString(),
|
|
707
|
+
completedAt: io.now().toISOString(),
|
|
708
|
+
durationMs: 0,
|
|
709
|
+
};
|
|
710
|
+
setSummary(summarizeBarcodeDecode({
|
|
711
|
+
details: errorDetails,
|
|
712
|
+
decodeResult: null,
|
|
713
|
+
pdf417DetectionCount: internal.getState().pdf417DetectionCount,
|
|
714
|
+
}));
|
|
715
|
+
dispatch({
|
|
716
|
+
type: 'nativeBarcodeDecodeFailed',
|
|
717
|
+
payload: { details: errorDetails },
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
finally {
|
|
721
|
+
// wizard 889-897: always sync the zxing attempt counter to state
|
|
722
|
+
dispatch({
|
|
723
|
+
type: 'addZxingParseAttempts',
|
|
724
|
+
payload: io.getZxingAttemptCount(),
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
})();
|
|
728
|
+
}
|
|
729
|
+
// ---------------------------------------------------------------------
|
|
730
|
+
// Recapture cluster (wizard 361-373, 433-453, 1114-1374)
|
|
731
|
+
// ---------------------------------------------------------------------
|
|
732
|
+
function startLastChanceDecode(s) {
|
|
733
|
+
// wizard 1144-1195: try to deskew + decode the captured barcode before
|
|
734
|
+
// the full recapture sequence completes; success short-circuits it.
|
|
735
|
+
const barcodeImageData = s.capturedDocuments.idBarcodeImage?.imageData ?? s.initialCaptureBarcodeImage;
|
|
736
|
+
if (!barcodeImageData)
|
|
737
|
+
return;
|
|
738
|
+
const generation = recaptureGeneration;
|
|
739
|
+
void (async () => {
|
|
740
|
+
try {
|
|
741
|
+
const blob = await imageToBlob(barcodeImageData);
|
|
742
|
+
const result = await io.decodePDF417(blob, { tryFineRotations: true });
|
|
743
|
+
if (generation !== recaptureGeneration)
|
|
744
|
+
return; // aborted (wizard 1167)
|
|
745
|
+
if (result) {
|
|
746
|
+
dispatch({ type: 'aggressiveDecodeSuccess', payload: result });
|
|
747
|
+
dispatch({ type: 'barcodeRecaptureCompleted' });
|
|
748
|
+
}
|
|
749
|
+
// No result -> nothing; the recapture timers carry the flow.
|
|
750
|
+
}
|
|
751
|
+
catch (err) {
|
|
752
|
+
// wizard 1181-1185: last-chance decode errors are logged and ignored
|
|
753
|
+
// (the recapture timers still complete the flow) — kept verbatim.
|
|
754
|
+
if (generation === recaptureGeneration) {
|
|
755
|
+
log('[createIdCaptureController] Last-chance fine rotation decode error:', err);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
})();
|
|
759
|
+
}
|
|
760
|
+
function moveCloserWindowExpired() {
|
|
761
|
+
// wizard 1218-1269
|
|
762
|
+
if (!pipeline)
|
|
763
|
+
return;
|
|
764
|
+
if (recapturePhaseStarted)
|
|
765
|
+
return;
|
|
766
|
+
const recaptureBarcode = pipeline.getRecaptureBestBarcode();
|
|
767
|
+
const recaptureScore = recaptureBarcode?.score ?? null;
|
|
768
|
+
const s = internal.getState();
|
|
769
|
+
const improved = !!recaptureBarcode && recaptureBarcode.score > s.initialBarcodeScore;
|
|
770
|
+
if (improved) {
|
|
771
|
+
dispatch({
|
|
772
|
+
type: 'barcodeCaptured',
|
|
773
|
+
payload: {
|
|
774
|
+
imageUrl: recaptureBarcode.canvas.toDataURL('image/jpeg', 0.95),
|
|
775
|
+
barcodeReadabilityScore: recaptureBarcode.score,
|
|
776
|
+
},
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
// Always record the best move-closer score for diagnostics (wizard 1248-1253)
|
|
780
|
+
dispatch({
|
|
781
|
+
type: 'barcodeRecaptureScoreUpdated',
|
|
782
|
+
payload: { recaptureBarcodeScore: recaptureScore },
|
|
783
|
+
});
|
|
784
|
+
if (recaptureBarcode) {
|
|
785
|
+
dispatch({
|
|
786
|
+
type: 'recaptureBarcodeImageCaptured',
|
|
787
|
+
payload: {
|
|
788
|
+
recaptureBarcodeImage: recaptureBarcode.canvas.toDataURL('image/jpeg', 0.95),
|
|
789
|
+
},
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
dispatch({ type: 'barcodeRecaptureCompleted' });
|
|
793
|
+
}
|
|
794
|
+
function growthWindowExpired() {
|
|
795
|
+
// wizard 1284-1349
|
|
796
|
+
if (!pipeline)
|
|
797
|
+
return;
|
|
798
|
+
const recaptureBarcode = pipeline.getRecaptureBestBarcode();
|
|
799
|
+
const bestBarcode = pipeline.getBestBarcode();
|
|
800
|
+
const recaptureScore = recaptureBarcode?.score ?? null;
|
|
801
|
+
const s = internal.getState();
|
|
802
|
+
const improved = !!bestBarcode && bestBarcode.score > s.initialBarcodeScore;
|
|
803
|
+
dispatch({
|
|
804
|
+
type: 'barcodeRecaptureScoreUpdated',
|
|
805
|
+
payload: { recaptureBarcodeScore: recaptureScore },
|
|
806
|
+
});
|
|
807
|
+
if (recaptureBarcode) {
|
|
808
|
+
dispatch({
|
|
809
|
+
type: 'recaptureBarcodeImageCaptured',
|
|
810
|
+
payload: {
|
|
811
|
+
recaptureBarcodeImage: recaptureBarcode.canvas.toDataURL('image/jpeg', 0.95),
|
|
812
|
+
},
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
else if (improved) {
|
|
816
|
+
// Improved without a recapture-specific best: persist the "after" image
|
|
817
|
+
// for debug comparison (wizard 1317-1329)
|
|
818
|
+
dispatch({
|
|
819
|
+
type: 'recaptureBarcodeImageCaptured',
|
|
820
|
+
payload: {
|
|
821
|
+
recaptureBarcodeImage: bestBarcode.canvas.toDataURL('image/jpeg', 0.95),
|
|
822
|
+
},
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
if (improved) {
|
|
826
|
+
dispatch({
|
|
827
|
+
type: 'barcodeCaptured',
|
|
828
|
+
payload: {
|
|
829
|
+
imageUrl: bestBarcode.canvas.toDataURL('image/jpeg', 0.95),
|
|
830
|
+
barcodeReadabilityScore: bestBarcode.score,
|
|
831
|
+
},
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
dispatch({ type: 'barcodeRecaptureCompleted' });
|
|
835
|
+
}
|
|
836
|
+
function enterRecapture(next) {
|
|
837
|
+
if (!pipeline)
|
|
838
|
+
return;
|
|
839
|
+
// Reset recapture gating on entry (wizard 361-368)
|
|
840
|
+
initialBarcodeBbox = null;
|
|
841
|
+
recapturePhaseStarted = false;
|
|
842
|
+
setGrowthSatisfied(false);
|
|
843
|
+
// Relax detection boundaries so edge detections survive while the user
|
|
844
|
+
// zooms in (wizard 433-444). NOTE: sdk2's "restore on exit" branch
|
|
845
|
+
// (wizard 445-452) never calls setDocumentDetectionBoundaries — it is
|
|
846
|
+
// dead code — so the port deliberately has no restore either.
|
|
847
|
+
pipeline.setBoundaries({
|
|
848
|
+
top: 0,
|
|
849
|
+
bottom: 0,
|
|
850
|
+
left: 0,
|
|
851
|
+
right: 0,
|
|
852
|
+
edgeMarginPct: currentBoundaries.edgeMarginPct,
|
|
853
|
+
});
|
|
854
|
+
// Recapture init (wizard 1114-1140): only when the reducer didn't already
|
|
855
|
+
// seed initialCaptureBarcodeImage (i.e. there was no captured barcode
|
|
856
|
+
// image). When it did, the "already initialized" guard also skips the
|
|
857
|
+
// immediate startBarcodeRecapturePhase — kept verbatim.
|
|
858
|
+
if (next.initialCaptureBarcodeImage === null) {
|
|
859
|
+
dispatch({
|
|
860
|
+
type: 'barcodeRecaptureStarted',
|
|
861
|
+
payload: {
|
|
862
|
+
initialBarcodeScore: next.initialBarcodeScore,
|
|
863
|
+
initialCaptureBarcodeImage: next.capturedDocuments.idBarcodeImage?.imageData ?? null,
|
|
864
|
+
},
|
|
865
|
+
});
|
|
866
|
+
// Start immediately so barcode analysis runs with relaxed conditions
|
|
867
|
+
pipeline.startBarcodeRecapturePhase();
|
|
868
|
+
}
|
|
869
|
+
// wizard 1144-1195
|
|
870
|
+
startLastChanceDecode(internal.getState());
|
|
871
|
+
// wizard 1198-1209: ignore early frames before the user can move closer
|
|
872
|
+
armTimer('recapture:resetBestBarcode', 1000, () => pipeline?.resetBestBarcode());
|
|
873
|
+
// wizard 1216: continue detection. sdk2 leaks this setTimeout (no
|
|
874
|
+
// cleanup); the port tracks it so detach()/state-exit can clear it —
|
|
875
|
+
// sanctioned deviation, noted in the task report.
|
|
876
|
+
armTimer('recapture:delayedStart', 100, () => pipeline?.start());
|
|
877
|
+
// wizard 1218-1269: move-closer window
|
|
878
|
+
armTimer('recapture:moveCloser', barcodeRecaptureMoveCloserTimeoutMs, moveCloserWindowExpired);
|
|
879
|
+
// wizard 1362-1366: point detection at the barcode side
|
|
880
|
+
pipeline.setRequiredDocumentType('idCardBack');
|
|
881
|
+
}
|
|
882
|
+
function exitRecapture() {
|
|
883
|
+
clearTimer('recapture:resetBestBarcode');
|
|
884
|
+
clearTimer('recapture:delayedStart');
|
|
885
|
+
clearTimer('recapture:moveCloser');
|
|
886
|
+
clearTimer('recapture:growthWindow');
|
|
887
|
+
// Abort any in-flight last-chance decode (wizard 1188-1190 cleanup)
|
|
888
|
+
recaptureGeneration += 1;
|
|
889
|
+
// wizard 1368-1373 cleanup
|
|
890
|
+
pipeline?.setRequiredDocumentType('none');
|
|
891
|
+
pipeline?.endBarcodeRecapturePhase();
|
|
892
|
+
// wizard 370-372: reset gating whenever we leave the recapture flow
|
|
893
|
+
initialBarcodeBbox = null;
|
|
894
|
+
recapturePhaseStarted = false;
|
|
895
|
+
setGrowthSatisfied(false);
|
|
896
|
+
}
|
|
897
|
+
// ---------------------------------------------------------------------
|
|
898
|
+
// Effect layer — ONE subscription diffing transitions (wizard-effect table)
|
|
899
|
+
// ---------------------------------------------------------------------
|
|
900
|
+
function enterCapturing() {
|
|
901
|
+
// wizard 506-513: reset aggressive decode state + zxing counter whenever
|
|
902
|
+
// capture (re)starts
|
|
903
|
+
pipeline?.resetAggressiveDecode();
|
|
904
|
+
dispatch({ type: 'resetAggressiveDecode' });
|
|
905
|
+
io.resetZxingAttemptCount();
|
|
906
|
+
}
|
|
907
|
+
function startCaptureSession() {
|
|
908
|
+
// wizard 496-503 (startModelsWhenCapturing): UI-owned loading overlays
|
|
909
|
+
// pass deferCaptureStart to attach(), then actions.start() removes this
|
|
910
|
+
// gate when the user continues. Eager/headless attach keeps the existing
|
|
911
|
+
// start-immediately behavior.
|
|
912
|
+
if (captureStartDeferred)
|
|
913
|
+
return;
|
|
914
|
+
dispatch({ type: 'captureStarted' });
|
|
915
|
+
pipeline?.start();
|
|
916
|
+
}
|
|
917
|
+
function runEffects(prev, next) {
|
|
918
|
+
const stateChanged = prev.captureState !== next.captureState;
|
|
919
|
+
if (stateChanged) {
|
|
920
|
+
// -- exits --
|
|
921
|
+
if (prev.captureState === 'requestingFlip') {
|
|
922
|
+
clearTimer('flip:autoConfirm'); // wizard 1109-1111 cleanup
|
|
923
|
+
}
|
|
924
|
+
if (prev.captureState === 'requestingBetterBarcode') {
|
|
925
|
+
exitRecapture();
|
|
926
|
+
}
|
|
927
|
+
// -- entries --
|
|
928
|
+
if (next.captureState === 'capturing') {
|
|
929
|
+
enterCapturing();
|
|
930
|
+
}
|
|
931
|
+
if (isCapturingState(next.captureState) &&
|
|
932
|
+
!isCapturingState(prev.captureState)) {
|
|
933
|
+
startCaptureSession();
|
|
934
|
+
}
|
|
935
|
+
if (next.captureState === 'requestingFlip') {
|
|
936
|
+
// wizard 1100-1112: auto flip confirmation after 6s. Manual mode
|
|
937
|
+
// (sdk2's separateIdCardCaptureSequence) never arms the timer.
|
|
938
|
+
if (flipConfirmation === 'auto') {
|
|
939
|
+
armTimer('flip:autoConfirm', 6000, () => {
|
|
940
|
+
pipeline?.resetBestFrame();
|
|
941
|
+
dispatch({ type: 'flipRequestCompleted' });
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
if (next.captureState === 'requestingBetterBarcode') {
|
|
946
|
+
enterRecapture(next);
|
|
947
|
+
}
|
|
948
|
+
if (next.captureState === 'complete') {
|
|
949
|
+
pipeline?.stop(); // wizard 611-613
|
|
950
|
+
runDecodeChain(); // wizard 616-913
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
// documentCount -> resetBestFrame, skipped during recapture
|
|
954
|
+
// (wizard 455-461; the sdk2 effect also re-runs on captureState changes)
|
|
955
|
+
const prevCount = Object.keys(prev.capturedDocuments).length;
|
|
956
|
+
const nextCount = Object.keys(next.capturedDocuments).length;
|
|
957
|
+
if ((prevCount !== nextCount || stateChanged) &&
|
|
958
|
+
next.captureState !== 'requestingBetterBarcode' &&
|
|
959
|
+
nextCount > 0) {
|
|
960
|
+
pipeline?.resetBestFrame();
|
|
961
|
+
}
|
|
962
|
+
// requestedDocumentType -> pipeline required-type mapping (wizard 1376-1394)
|
|
963
|
+
if (prev.requestedDocumentType !== next.requestedDocumentType) {
|
|
964
|
+
applyRequiredDocumentTypeMapping(next.requestedDocumentType);
|
|
965
|
+
}
|
|
966
|
+
// Override accepted -> stop filtering by document type
|
|
967
|
+
// (IdCaptureStateProvider.tsx:1246-1253)
|
|
968
|
+
if (!prev.overrideWrongDocumentTypeGuidance &&
|
|
969
|
+
next.overrideWrongDocumentTypeGuidance) {
|
|
970
|
+
pipeline?.setRequiredDocumentType('none');
|
|
971
|
+
}
|
|
972
|
+
// Growth satisfied while recapturing -> arm the capture window
|
|
973
|
+
// (wizard 1280-1359)
|
|
974
|
+
const prevWindowArmed = prev.captureState === 'requestingBetterBarcode' && prev.recaptureGrowthSatisfied;
|
|
975
|
+
const nextWindowArmed = next.captureState === 'requestingBetterBarcode' && next.recaptureGrowthSatisfied;
|
|
976
|
+
if (nextWindowArmed && !prevWindowArmed) {
|
|
977
|
+
armTimer('recapture:growthWindow', barcodeRecaptureTimeoutMs, growthWindowExpired);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
internal.subscribe((next, prev) => {
|
|
981
|
+
if (attached)
|
|
982
|
+
runEffects(prev, next);
|
|
983
|
+
publish();
|
|
984
|
+
});
|
|
985
|
+
// ---------------------------------------------------------------------
|
|
986
|
+
// Attach / retry / detach
|
|
987
|
+
// ---------------------------------------------------------------------
|
|
988
|
+
function cameraOptions() {
|
|
989
|
+
const base = config.camera ?? {};
|
|
990
|
+
return continuityCameraDenied
|
|
991
|
+
? { ...base, preferIphoneContinuityCamera: false }
|
|
992
|
+
: base;
|
|
993
|
+
}
|
|
994
|
+
async function acquireCameraStep(el) {
|
|
995
|
+
const opts = cameraOptions();
|
|
996
|
+
// See selfieCapture/controller.ts's acquireCameraStep for the full
|
|
997
|
+
// reasoning: a detach() while getUserMedia is in flight orphans this
|
|
998
|
+
// acquisition, and landing it would both leak the stream and let
|
|
999
|
+
// acquireCamera's entry-time global release null `srcObject` on whatever
|
|
1000
|
+
// element the live session has since wired up.
|
|
1001
|
+
const generation = attachGeneration;
|
|
1002
|
+
try {
|
|
1003
|
+
const acquired = await io.acquireCamera(el, opts);
|
|
1004
|
+
if (!active || generation !== attachGeneration) {
|
|
1005
|
+
acquired.release();
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
cameraHandle = acquired;
|
|
1009
|
+
internal.setState({
|
|
1010
|
+
camera: { ready: true, isRearFacing: acquired.isRearFacing, accessRequested: true },
|
|
1011
|
+
// On recovery from a prior camera-permission error, clear it so the
|
|
1012
|
+
// phase is no longer stuck on 'error' (which is derived and always
|
|
1013
|
+
// wins). See selfieCapture/controller.ts:950-959 for the identical
|
|
1014
|
+
// recovery pattern.
|
|
1015
|
+
error: null,
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
catch (e) {
|
|
1019
|
+
if (e instanceof CaptureAttachError) {
|
|
1020
|
+
if (e.captureError.code === 'CAMERA_PERMISSION_DENIED' &&
|
|
1021
|
+
opts.preferIphoneContinuityCamera !== false) {
|
|
1022
|
+
// A denial while the continuity preference was in effect is what
|
|
1023
|
+
// sdk2 records as iphoneContinuityCameraDenied (cameraStore.tsx:
|
|
1024
|
+
// 265-275); the next attempt must not prefer it.
|
|
1025
|
+
continuityCameraDenied = true;
|
|
1026
|
+
}
|
|
1027
|
+
throw e;
|
|
1028
|
+
}
|
|
1029
|
+
// acquireCamera rethrows genuinely unexpected errors verbatim
|
|
1030
|
+
// (cameraStore.tsx:382-385); the controller still owes the store a
|
|
1031
|
+
// typed error, so unknowns land in the CAMERA_UNAVAILABLE bucket.
|
|
1032
|
+
throw new CaptureAttachError({
|
|
1033
|
+
code: 'CAMERA_UNAVAILABLE',
|
|
1034
|
+
recoverable: true,
|
|
1035
|
+
cause: e,
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
finally {
|
|
1039
|
+
// Latch mirrors sdk2 cameraStore's `finally { cameraAccessRequested:
|
|
1040
|
+
// true }` (cameraStore.tsx:386-401): a request SETTLED (granted or
|
|
1041
|
+
// denied), not that deferred mode was used. The success path above
|
|
1042
|
+
// already published accessRequested: true as part of its single
|
|
1043
|
+
// setState; this only covers the denial path (and is a no-op if the
|
|
1044
|
+
// success branch already latched it).
|
|
1045
|
+
const cam = internal.getState().camera;
|
|
1046
|
+
if (!cam.accessRequested)
|
|
1047
|
+
internal.setState({ camera: { ...cam, accessRequested: true } });
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
async function loadPipelineStep() {
|
|
1051
|
+
if (!pipeline || pipelineLoadFailed) {
|
|
1052
|
+
// A settled pipeline load() is memoized (pipeline.ts caches its load
|
|
1053
|
+
// promise and a rejected one stays rejected), so a retry rebuilds the
|
|
1054
|
+
// pipeline before loading again.
|
|
1055
|
+
pipeline?.close();
|
|
1056
|
+
pipeline = createPipelineInstance();
|
|
1057
|
+
pipelineLoadFailed = false;
|
|
1058
|
+
}
|
|
1059
|
+
try {
|
|
1060
|
+
await pipeline.load();
|
|
1061
|
+
}
|
|
1062
|
+
catch (e) {
|
|
1063
|
+
pipelineLoadFailed = true;
|
|
1064
|
+
if (e instanceof CaptureAttachError)
|
|
1065
|
+
throw e;
|
|
1066
|
+
throw new CaptureAttachError({
|
|
1067
|
+
code: 'MODEL_LOAD_FAILED',
|
|
1068
|
+
recoverable: true,
|
|
1069
|
+
model: 'documentDetector',
|
|
1070
|
+
cause: e,
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
pipelineLoaded = true;
|
|
1074
|
+
}
|
|
1075
|
+
function finalizeAttach() {
|
|
1076
|
+
attached = true;
|
|
1077
|
+
const requestedBefore = internal.getState().requestedDocumentType;
|
|
1078
|
+
const captureStateBefore = internal.getState().captureState;
|
|
1079
|
+
// wizard 375-414 (configureWizard on mount), with the wizard's prop
|
|
1080
|
+
// defaults (274-306)
|
|
1081
|
+
dispatch({
|
|
1082
|
+
type: 'configureWizard',
|
|
1083
|
+
payload: {
|
|
1084
|
+
captureRequirement,
|
|
1085
|
+
precapturedDocuments: config.precapturedDocuments,
|
|
1086
|
+
allowSinglePageIdCapture: config.allowSinglePageIdCapture,
|
|
1087
|
+
requireFullPassportBooklet: config.requireFullPassportBooklet,
|
|
1088
|
+
allowIdCardBackToFrontCapture: config.allowIdCardBackToFrontCapture,
|
|
1089
|
+
idCardBackCaptureRequired: config.idCardBackCaptureRequired,
|
|
1090
|
+
enableFingerOcclusionGuidance,
|
|
1091
|
+
fingerOcclusionThresholds: config.fingerOcclusionThresholds,
|
|
1092
|
+
enableGlareOcclusionGuidance,
|
|
1093
|
+
enableHologramOcclusionGuidance,
|
|
1094
|
+
enableOverrideWrongDocumentTypeDialog: config.enableOverrideWrongDocumentTypeDialog ?? false,
|
|
1095
|
+
allowOverrideWrongDocumentTypeAfterMs: config.allowOverrideWrongDocumentTypeAfterMs ?? 8000,
|
|
1096
|
+
// The headless controller has no upload-from-storage screen
|
|
1097
|
+
allowUploadingDocumentsFromStorage: false,
|
|
1098
|
+
enableBarcodeRecapture: config.enableBarcodeRecapture ?? false,
|
|
1099
|
+
barcodeRecaptureThreshold: config.barcodeRecaptureThreshold ?? 0.3,
|
|
1100
|
+
barcodeRecaptureTimeoutMs,
|
|
1101
|
+
aggressiveModeEnabled,
|
|
1102
|
+
},
|
|
1103
|
+
});
|
|
1104
|
+
// IdCapture.tsx:126
|
|
1105
|
+
dispatch({ type: 'captureInitialized' });
|
|
1106
|
+
// Mount-run of the mapping effect (wizard 1376-1394): the transition diff
|
|
1107
|
+
// already handled it if configureWizard changed the requested type.
|
|
1108
|
+
if (internal.getState().requestedDocumentType === requestedBefore) {
|
|
1109
|
+
applyRequiredDocumentTypeMapping(requestedBefore);
|
|
1110
|
+
}
|
|
1111
|
+
// Mount-run of the capturing-entry effects (wizard 506-513 + 496-503):
|
|
1112
|
+
// when the store was ALREADY in a capturing state before configureWizard
|
|
1113
|
+
// (re-attach after detach — resetWizard leaves captureState 'capturing'),
|
|
1114
|
+
// no transition fires above, so run them explicitly or detection never
|
|
1115
|
+
// starts (captureStarted + pipeline.start() would be skipped).
|
|
1116
|
+
if (isCapturingState(captureStateBefore) &&
|
|
1117
|
+
isCapturingState(internal.getState().captureState)) {
|
|
1118
|
+
enterCapturing();
|
|
1119
|
+
startCaptureSession();
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
async function doAttach() {
|
|
1123
|
+
const generation = attachGeneration;
|
|
1124
|
+
// A detach() bumps attachGeneration, so an attach still in flight belongs to
|
|
1125
|
+
// a session that no longer exists and must not block this one. Without the
|
|
1126
|
+
// generation comparison the `attaching` latch rejected the RE-attach half of
|
|
1127
|
+
// every detach+re-attach (React replacing the <video> on a retry), and
|
|
1128
|
+
// the view layer swallows attach() rejections -- so the new element
|
|
1129
|
+
// silently never got a camera.
|
|
1130
|
+
// retry() reaches doAttach WITHOUT a detach, so its generation is unchanged
|
|
1131
|
+
// and a genuine concurrent call still throws.
|
|
1132
|
+
if (attaching && attachingGeneration === generation) {
|
|
1133
|
+
throw new Error('createIdCaptureController: attach()/retry() already in progress');
|
|
1134
|
+
}
|
|
1135
|
+
attaching = true;
|
|
1136
|
+
attachingGeneration = generation;
|
|
1137
|
+
const superseded = () => !active || generation !== attachGeneration;
|
|
1138
|
+
try {
|
|
1139
|
+
const el = videoEl;
|
|
1140
|
+
if (!el) {
|
|
1141
|
+
throw new Error('createIdCaptureController: retry() called before attach()');
|
|
1142
|
+
}
|
|
1143
|
+
if (internal.getState().error)
|
|
1144
|
+
internal.setState({ error: null });
|
|
1145
|
+
const pipelineWasLoaded = pipelineLoaded;
|
|
1146
|
+
if (!cameraHandle && !config.deferCameraAcquisition)
|
|
1147
|
+
await acquireCameraStep(el);
|
|
1148
|
+
// detach() during the awaits above is the sdk2 unmount-during-load
|
|
1149
|
+
// analog: stop quietly instead of finishing the attach.
|
|
1150
|
+
if (superseded())
|
|
1151
|
+
return;
|
|
1152
|
+
if (!pipelineLoaded)
|
|
1153
|
+
await loadPipelineStep();
|
|
1154
|
+
if (superseded())
|
|
1155
|
+
return;
|
|
1156
|
+
if (!attached) {
|
|
1157
|
+
finalizeAttach();
|
|
1158
|
+
}
|
|
1159
|
+
else if (!pipelineWasLoaded) {
|
|
1160
|
+
// Post-attach pipeline rebuild (retry() after a post-attach model
|
|
1161
|
+
// error): the wizard is already configured, so instead of re-running
|
|
1162
|
+
// finalizeAttach's mount dispatches, re-point the fresh pipeline at
|
|
1163
|
+
// the current wizard state and resume capture.
|
|
1164
|
+
applyRequiredDocumentTypeMapping(internal.getState().requestedDocumentType);
|
|
1165
|
+
if (isCapturingState(internal.getState().captureState)) {
|
|
1166
|
+
startCaptureSession();
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
catch (e) {
|
|
1171
|
+
// A superseded attach unwinds silently -- see the selfie controller.
|
|
1172
|
+
if (superseded())
|
|
1173
|
+
return;
|
|
1174
|
+
// attach() rejects typed AND the store lands in phase 'error' with the
|
|
1175
|
+
// SAME CaptureError — one truth in both places.
|
|
1176
|
+
const attachError = e instanceof CaptureAttachError
|
|
1177
|
+
? e
|
|
1178
|
+
: new CaptureAttachError({
|
|
1179
|
+
code: 'CAMERA_UNAVAILABLE',
|
|
1180
|
+
recoverable: true,
|
|
1181
|
+
cause: e,
|
|
1182
|
+
});
|
|
1183
|
+
internal.setState({ error: attachError.captureError });
|
|
1184
|
+
throw attachError;
|
|
1185
|
+
}
|
|
1186
|
+
finally {
|
|
1187
|
+
if (generation === attachGeneration)
|
|
1188
|
+
attaching = false;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
function detach() {
|
|
1192
|
+
// resetWizard analog of IdCaptureStateProvider unmounting
|
|
1193
|
+
// (IdCaptureStateProvider.tsx:1265-1267) plus the models/camera teardown
|
|
1194
|
+
// sdk2 spreads across provider unmount effects.
|
|
1195
|
+
active = false;
|
|
1196
|
+
attached = false;
|
|
1197
|
+
clearAllTimers();
|
|
1198
|
+
recaptureGeneration += 1;
|
|
1199
|
+
attachGeneration += 1;
|
|
1200
|
+
if (pipeline) {
|
|
1201
|
+
pipeline.stop();
|
|
1202
|
+
// effect cleanups on unmount: mapping (wizard 1391-1393) + recapture
|
|
1203
|
+
// (wizard 1368-1373)
|
|
1204
|
+
pipeline.setRequiredDocumentType('none');
|
|
1205
|
+
pipeline.endBarcodeRecapturePhase();
|
|
1206
|
+
pipeline.close();
|
|
1207
|
+
pipeline = null;
|
|
1208
|
+
}
|
|
1209
|
+
pipelineLoaded = false;
|
|
1210
|
+
pipelineLoadFailed = false;
|
|
1211
|
+
captureStartDeferred = false;
|
|
1212
|
+
cameraHandle?.release();
|
|
1213
|
+
cameraHandle = null;
|
|
1214
|
+
videoEl = null;
|
|
1215
|
+
initialBarcodeBbox = null;
|
|
1216
|
+
recapturePhaseStarted = false;
|
|
1217
|
+
lastDocumentDetectedAt = { ...lastDocumentDetectedAtDefaults };
|
|
1218
|
+
captureAttempts = { front: [], back: [], barcode: [] };
|
|
1219
|
+
inFlightSubmit = null;
|
|
1220
|
+
internal.setState({
|
|
1221
|
+
// Divergence #5: accessRequested is carried forward, NOT reset here.
|
|
1222
|
+
// It latches "a camera request settled at some point", so a
|
|
1223
|
+
// detach()/re-attach (e.g. the ring-intro remount) must not forget a
|
|
1224
|
+
// prior grant/denial and re-prompt or re-gate unnecessarily.
|
|
1225
|
+
camera: {
|
|
1226
|
+
ready: false,
|
|
1227
|
+
isRearFacing: false,
|
|
1228
|
+
accessRequested: internal.getState().camera.accessRequested,
|
|
1229
|
+
},
|
|
1230
|
+
// The pipeline (and its load state) is gone with it — don't leave a
|
|
1231
|
+
// stale ready/loaded snapshot on the public state.
|
|
1232
|
+
models: { ready: false, loadState: 'not-started', downloadProgress: 0 },
|
|
1233
|
+
recaptureGrowthSatisfied: false,
|
|
1234
|
+
});
|
|
1235
|
+
dispatch({ type: 'resetWizard' });
|
|
1236
|
+
}
|
|
1237
|
+
// ---------------------------------------------------------------------
|
|
1238
|
+
// Submit bridge (Task 9): builds SubmissionArtifacts via submit.ts's pure
|
|
1239
|
+
// mapping, then owns the submitting/submitted/error store lifecycle around
|
|
1240
|
+
// `client.submit()`. Deliberately does NOT call `client.validateSession()`
|
|
1241
|
+
// -- session orchestration stays with the consumer, exactly like sdk2's
|
|
1242
|
+
// CompositeWizard split (SubmissionProvider drives its own session state;
|
|
1243
|
+
// IdCaptureWizard's onSubmitClick never touches it).
|
|
1244
|
+
// ---------------------------------------------------------------------
|
|
1245
|
+
// retryable derivation: no generic `isRetryableHttpStatus`-style helper is
|
|
1246
|
+
// exported from client/errors.ts, and SubmissionError's `status.statusCode`
|
|
1247
|
+
// is a string that is sometimes a business code ('000'/'001'/...) and
|
|
1248
|
+
// sometimes `response.statusText` (IdmissionClient.ts's HTTP-failure
|
|
1249
|
+
// branch) -- never a reliable numeric HTTP status to threshold against. So,
|
|
1250
|
+
// per the task brief's documented fallback: only a bare NetworkError (a
|
|
1251
|
+
// transport-level failure) is treated as retryable; everything else
|
|
1252
|
+
// (SubmissionError, AuthenticationError, or any other thrown value) is not.
|
|
1253
|
+
function deriveRetryable(error) {
|
|
1254
|
+
return error instanceof NetworkError;
|
|
1255
|
+
}
|
|
1256
|
+
let inFlightSubmit = null;
|
|
1257
|
+
// Serialises `captureManually`. The slot an image lands in is decided by
|
|
1258
|
+
// `state.requestedDocumentType` at DISPATCH time (reducer.ts:631-644), but
|
|
1259
|
+
// the action awaits `dataUrlToBase64` first -- so two overlapping calls can
|
|
1260
|
+
// dispatch in decode order rather than call order and swap front for back.
|
|
1261
|
+
// The metadata stamped before the await has the same hazard. sdk2 carries
|
|
1262
|
+
// the identical shape (IdCaptureWizard.tsx:1489-1494); chaining here fixes
|
|
1263
|
+
// every caller at once, and only changes behaviour when calls actually
|
|
1264
|
+
// overlap -- where the current behaviour is the bug.
|
|
1265
|
+
let manualCaptureQueue = Promise.resolve();
|
|
1266
|
+
async function runManualCapture(imageDataUrl, options) {
|
|
1267
|
+
// wizard 1396-1402 (handleCapture). sdk2's manual/fallback capture
|
|
1268
|
+
// path does not itself run logCaptureMetadata (that's onCapture,
|
|
1269
|
+
// the auto-capture-only callback) -- but the submit bridge's
|
|
1270
|
+
// captureAttempts feed still needs an entry for manual captures, so
|
|
1271
|
+
// the controller stamps operationTime/captureMode here the same way
|
|
1272
|
+
// maybeAutoCapture's finalize timer does, tagged 'Manual'/'N'.
|
|
1273
|
+
const current = internal.getState();
|
|
1274
|
+
const captureStartedAtMs = current.captureStartedAt?.getTime();
|
|
1275
|
+
const metadata = {
|
|
1276
|
+
autoCapture: 'N',
|
|
1277
|
+
captureTime: captureStartedAtMs ? io.now().getTime() - captureStartedAtMs : 0,
|
|
1278
|
+
operationTime: io.now().getTime() - (current.operationStartedAt ?? io.now()).getTime(),
|
|
1279
|
+
captureMode: options?.captureMode ?? 'Manual',
|
|
1280
|
+
};
|
|
1281
|
+
recordCaptureAttempt(metadata, current.requestedDocumentType);
|
|
1282
|
+
const imageData = await dataUrlToBase64(imageDataUrl);
|
|
1283
|
+
dispatch({ type: 'documentCapturedManually', payload: { imageData } });
|
|
1284
|
+
}
|
|
1285
|
+
// Shared by `collectArtifacts()` and `doSubmit()` so the two can never
|
|
1286
|
+
// diverge: this is the ONLY place `IdCaptureSubmitInputs` gets assembled
|
|
1287
|
+
// from `internal.getState()` + the closure-internal `captureAttempts`
|
|
1288
|
+
// accumulators. Pure read -- no dispatch, no I/O.
|
|
1289
|
+
function collectSubmissionArtifacts() {
|
|
1290
|
+
const s = internal.getState();
|
|
1291
|
+
const decodeResult = s.nativeBarcodeDecodeResult ?? s.aggressiveModeDecodeResult;
|
|
1292
|
+
const inputs = {
|
|
1293
|
+
capturedDocuments: s.capturedDocuments,
|
|
1294
|
+
decodeResult,
|
|
1295
|
+
barcodeDecodeSummary: s.barcodeDecodeSummary,
|
|
1296
|
+
captureAttempts: {
|
|
1297
|
+
front: [...captureAttempts.front],
|
|
1298
|
+
back: [...captureAttempts.back],
|
|
1299
|
+
barcode: [...captureAttempts.barcode],
|
|
1300
|
+
},
|
|
1301
|
+
};
|
|
1302
|
+
return buildIdCaptureArtifacts(inputs, io.now);
|
|
1303
|
+
}
|
|
1304
|
+
// `| null` when the client's `onSubmit` took the request instead of posting
|
|
1305
|
+
// it: there is no response to hand back, and the capture is still complete.
|
|
1306
|
+
async function doSubmit() {
|
|
1307
|
+
const artifacts = collectSubmissionArtifacts();
|
|
1308
|
+
// A fresh submit attempt (including a retry) clears any stale
|
|
1309
|
+
// SUBMISSION_FAILED error up front, mirroring doAttach's own
|
|
1310
|
+
// error-clearing before a new attempt.
|
|
1311
|
+
internal.setState({ submission: 'submitting', error: null });
|
|
1312
|
+
try {
|
|
1313
|
+
const response = await config.client.submit(artifacts, config.submission);
|
|
1314
|
+
internal.setState({
|
|
1315
|
+
submission: 'submitted',
|
|
1316
|
+
attestationAttached: config.client.getState().attestationAttached,
|
|
1317
|
+
});
|
|
1318
|
+
return response;
|
|
1319
|
+
}
|
|
1320
|
+
catch (e) {
|
|
1321
|
+
const captureError = {
|
|
1322
|
+
code: 'SUBMISSION_FAILED',
|
|
1323
|
+
recoverable: true,
|
|
1324
|
+
retryable: deriveRetryable(e),
|
|
1325
|
+
cause: e,
|
|
1326
|
+
};
|
|
1327
|
+
// submit() rejects with the SAME typed error object stored here --
|
|
1328
|
+
// one truth in both places (mirrors doAttach()/attach()).
|
|
1329
|
+
internal.setState({ submission: 'idle', error: captureError });
|
|
1330
|
+
throw new CaptureAttachError(captureError);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
function submitAction() {
|
|
1334
|
+
// Double-submit guard (CompositeWizard's submittedRef analog,
|
|
1335
|
+
// CompositeWizard.tsx:156-175): a submit already in flight returns the
|
|
1336
|
+
// SAME promise rather than firing client.submit() again.
|
|
1337
|
+
if (inFlightSubmit)
|
|
1338
|
+
return inFlightSubmit;
|
|
1339
|
+
const p = doSubmit().finally(() => {
|
|
1340
|
+
inFlightSubmit = null;
|
|
1341
|
+
});
|
|
1342
|
+
inFlightSubmit = p;
|
|
1343
|
+
return p;
|
|
1344
|
+
}
|
|
1345
|
+
// ---------------------------------------------------------------------
|
|
1346
|
+
// Public surface
|
|
1347
|
+
// ---------------------------------------------------------------------
|
|
1348
|
+
return {
|
|
1349
|
+
async attach(el, options = {}) {
|
|
1350
|
+
if (attached) {
|
|
1351
|
+
throw new Error('createIdCaptureController: attach() called while already attached');
|
|
1352
|
+
}
|
|
1353
|
+
active = true;
|
|
1354
|
+
videoEl = el;
|
|
1355
|
+
captureStartDeferred = options.deferCaptureStart ?? false;
|
|
1356
|
+
await doAttach();
|
|
1357
|
+
},
|
|
1358
|
+
detach,
|
|
1359
|
+
getState() {
|
|
1360
|
+
// Referentially stable: return the last published snapshot. Every state
|
|
1361
|
+
// mutation flows through the store subscription, which publish()es and
|
|
1362
|
+
// refreshes the cache, so a fresh computation is only needed before the
|
|
1363
|
+
// first publish.
|
|
1364
|
+
if (snapshot)
|
|
1365
|
+
return snapshot;
|
|
1366
|
+
const s = internal.getState();
|
|
1367
|
+
snapshot = toPublicState(s, deriveGuidance(s, s.recaptureGrowthSatisfied));
|
|
1368
|
+
return snapshot;
|
|
1369
|
+
},
|
|
1370
|
+
collectArtifacts() {
|
|
1371
|
+
return collectSubmissionArtifacts();
|
|
1372
|
+
},
|
|
1373
|
+
subscribe(cb) {
|
|
1374
|
+
listeners.add(cb);
|
|
1375
|
+
return () => {
|
|
1376
|
+
listeners.delete(cb);
|
|
1377
|
+
};
|
|
1378
|
+
},
|
|
1379
|
+
actions: {
|
|
1380
|
+
start() {
|
|
1381
|
+
if (!captureStartDeferred)
|
|
1382
|
+
return;
|
|
1383
|
+
captureStartDeferred = false;
|
|
1384
|
+
if (attached && isCapturingState(internal.getState().captureState)) {
|
|
1385
|
+
startCaptureSession();
|
|
1386
|
+
}
|
|
1387
|
+
},
|
|
1388
|
+
confirmFlip() {
|
|
1389
|
+
// Manual-mode / early flip confirmation — same body as the auto
|
|
1390
|
+
// timer's completion (wizard 1104-1107).
|
|
1391
|
+
pipeline?.resetBestFrame();
|
|
1392
|
+
dispatch({ type: 'flipRequestCompleted' });
|
|
1393
|
+
},
|
|
1394
|
+
retake() {
|
|
1395
|
+
// wizard 1032-1035 (onRetryClick dispatches resetWizard); the
|
|
1396
|
+
// capturing re-entry effects then restart the pipeline. The explicit
|
|
1397
|
+
// resetBestFrame covers sdk2's post-reset canvas remounts.
|
|
1398
|
+
dispatch({ type: 'resetWizard' });
|
|
1399
|
+
pipeline?.resetBestFrame();
|
|
1400
|
+
},
|
|
1401
|
+
captureManually(imageDataUrl, options) {
|
|
1402
|
+
// A rejected capture must not wedge every later one, so the tail the
|
|
1403
|
+
// next call chains onto is the settled queue, while the caller still
|
|
1404
|
+
// receives this call's own rejection.
|
|
1405
|
+
const result = manualCaptureQueue.then(() => runManualCapture(imageDataUrl, options));
|
|
1406
|
+
manualCaptureQueue = result.then(() => undefined, () => undefined);
|
|
1407
|
+
return result;
|
|
1408
|
+
},
|
|
1409
|
+
overrideWrongDocumentType() {
|
|
1410
|
+
// The override dialog's confirm: overrideFlipRequirement; the effect
|
|
1411
|
+
// layer then forces the pipeline's required type to 'none'
|
|
1412
|
+
// (IdCaptureStateProvider.tsx:1246-1253).
|
|
1413
|
+
dispatch({ type: 'overrideFlipRequirement' });
|
|
1414
|
+
},
|
|
1415
|
+
submit() {
|
|
1416
|
+
return submitAction();
|
|
1417
|
+
},
|
|
1418
|
+
async retry() {
|
|
1419
|
+
const error = internal.getState().error;
|
|
1420
|
+
if (!error)
|
|
1421
|
+
return;
|
|
1422
|
+
if (error.code === 'SUBMISSION_FAILED') {
|
|
1423
|
+
await submitAction();
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
await doAttach();
|
|
1427
|
+
},
|
|
1428
|
+
async requestCamera() {
|
|
1429
|
+
if (!videoEl)
|
|
1430
|
+
throw new Error('requestCamera() requires attach() first');
|
|
1431
|
+
// Non-deferred mode (or a second call after the camera is already
|
|
1432
|
+
// held): no-op resolve, no re-acquisition.
|
|
1433
|
+
if (cameraHandle)
|
|
1434
|
+
return;
|
|
1435
|
+
try {
|
|
1436
|
+
await acquireCameraStep(videoEl);
|
|
1437
|
+
}
|
|
1438
|
+
catch (e) {
|
|
1439
|
+
// Same normalization + single-truth store write as doAttach's catch.
|
|
1440
|
+
const attachError = e instanceof CaptureAttachError
|
|
1441
|
+
? e
|
|
1442
|
+
: new CaptureAttachError({
|
|
1443
|
+
code: 'CAMERA_UNAVAILABLE',
|
|
1444
|
+
recoverable: true,
|
|
1445
|
+
cause: e,
|
|
1446
|
+
});
|
|
1447
|
+
internal.setState({ error: attachError.captureError });
|
|
1448
|
+
throw attachError;
|
|
1449
|
+
}
|
|
1450
|
+
},
|
|
1451
|
+
},
|
|
1452
|
+
};
|
|
1453
|
+
}
|