veryfi-lens-wasm 3.2.2 → 3.3.2
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/components/anydocPageControls.js +5 -1
- package/components/greenBox.js +11 -0
- package/components/multiCaptureModal.js +23 -0
- package/components/submitButton.js +7 -0
- package/components/video.js +12 -0
- package/core/api.js +46 -1
- package/core/capture/anydoc.js +15 -26
- package/core/capture/document.js +8 -3
- package/core/capture/prescription_label.js +21 -5
- package/core/constants.js +17 -3
- package/core/lifecycle.js +31 -1
- package/core/multi-submission.js +90 -0
- package/core/state.js +45 -0
- package/core/ui-core.js +8 -0
- package/package.json +1 -1
- package/veryfi-lens.js +6 -2
|
@@ -127,7 +127,11 @@ export const createAnydocPageControls = (container, onAddPage, onSubmit, removeO
|
|
|
127
127
|
} catch (error) {
|
|
128
128
|
console.error('Error during anydoc submission:', error);
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
// When autoCloseOnSubmit is false the onSubmit handler owns teardown
|
|
131
|
+
// (multi-submission loop prompts for another capture instead of closing).
|
|
132
|
+
if (options.autoCloseOnSubmit !== false) {
|
|
133
|
+
removeOverlay();
|
|
134
|
+
}
|
|
131
135
|
};
|
|
132
136
|
submitButton.addEventListener('click', submitClickHandler);
|
|
133
137
|
|
package/components/greenBox.js
CHANGED
|
@@ -20,6 +20,17 @@ export const createGreenBox = (container) => {
|
|
|
20
20
|
const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768 || isDesktopModeOnMobile();
|
|
21
21
|
const isFullscreen = container.dataset.fullscreen === 'true';
|
|
22
22
|
|
|
23
|
+
if (container.dataset.longDocDesktop === 'true') {
|
|
24
|
+
boxCanvas.style.position = 'fixed';
|
|
25
|
+
boxCanvas.style.top = '0';
|
|
26
|
+
boxCanvas.style.left = '0';
|
|
27
|
+
boxCanvas.style.width = '100vw';
|
|
28
|
+
boxCanvas.style.height = '100vh';
|
|
29
|
+
boxCanvas.style.maxWidth = 'none';
|
|
30
|
+
boxCanvas.style.objectFit = 'contain';
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
if (!isMobile) {
|
|
24
35
|
if (isFullscreen) {
|
|
25
36
|
boxCanvas.style.position = 'fixed';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createModal } from './modalBase.js';
|
|
2
|
+
|
|
3
|
+
export const createMultiCaptureModal = (container, onCaptureAnother, onFinish, options = {}) => {
|
|
4
|
+
const defaults = {
|
|
5
|
+
message: 'Do you need to capture another document?',
|
|
6
|
+
yesButtonText: 'Capture another',
|
|
7
|
+
noButtonText: "No, I'm done",
|
|
8
|
+
};
|
|
9
|
+
const o = { ...defaults, ...options };
|
|
10
|
+
|
|
11
|
+
return createModal(container, {
|
|
12
|
+
id: 'veryfi-multi-capture-modal',
|
|
13
|
+
cssPrefix: 'multi-capture-modal',
|
|
14
|
+
message: o.message,
|
|
15
|
+
primaryButtonText: o.yesButtonText,
|
|
16
|
+
primaryButtonId: 'veryfi-multi-capture-another',
|
|
17
|
+
secondaryButtonText: o.noButtonText,
|
|
18
|
+
secondaryButtonId: 'veryfi-multi-capture-finish',
|
|
19
|
+
onPrimaryClick: onCaptureAnother,
|
|
20
|
+
onSecondaryClick: onFinish,
|
|
21
|
+
useBackdrop: true,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -57,6 +57,13 @@ export const createSubmitButton = (container, onSubmit, removeOverlay, options =
|
|
|
57
57
|
if (button.disabled) {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
+
// When autoClose is false the onSubmit handler owns teardown/continuation
|
|
61
|
+
// (used by the multi-submission loop, which prompts for another capture
|
|
62
|
+
// instead of removing the overlay after a successful submit).
|
|
63
|
+
if (options.autoClose === false) {
|
|
64
|
+
await onSubmit();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
60
67
|
try {
|
|
61
68
|
await onSubmit();
|
|
62
69
|
} finally {
|
package/components/video.js
CHANGED
|
@@ -23,6 +23,18 @@ export const createVideo = (container) => {
|
|
|
23
23
|
const isFullscreen = container.dataset.fullscreen === 'true';
|
|
24
24
|
const isLandscape = window.innerWidth > window.innerHeight;
|
|
25
25
|
|
|
26
|
+
if (container.dataset.longDocDesktop === 'true') {
|
|
27
|
+
video.style.position = 'fixed';
|
|
28
|
+
video.style.top = '0';
|
|
29
|
+
video.style.left = '0';
|
|
30
|
+
video.style.width = '100vw';
|
|
31
|
+
video.style.height = '100vh';
|
|
32
|
+
video.style.maxWidth = 'none';
|
|
33
|
+
video.style.transform = 'none';
|
|
34
|
+
video.style.objectFit = 'contain';
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
if (!isMobile) {
|
|
27
39
|
if (isFullscreen) {
|
|
28
40
|
video.style.position = 'fixed';
|
package/core/api.js
CHANGED
|
@@ -5,6 +5,10 @@ import { createSpinner } from '../components/spinner.js';
|
|
|
5
5
|
import { API_URLS } from './constants.js';
|
|
6
6
|
import { shouldRunFieldDetection } from './field-detection-policy.js';
|
|
7
7
|
|
|
8
|
+
export const getQrSessionId = () => {
|
|
9
|
+
return new URLSearchParams(window.location.search).get('session');
|
|
10
|
+
};
|
|
11
|
+
|
|
8
12
|
export const validatePartner = async (client_id) => {
|
|
9
13
|
try {
|
|
10
14
|
state.updateHandler?.({ status: 'validation_started' });
|
|
@@ -314,7 +318,7 @@ export const handleSubmit = async (image) => {
|
|
|
314
318
|
...customData,
|
|
315
319
|
};
|
|
316
320
|
|
|
317
|
-
const qrSessionId =
|
|
321
|
+
const qrSessionId = getQrSessionId();
|
|
318
322
|
|
|
319
323
|
const requestOptions = {
|
|
320
324
|
method: 'POST',
|
|
@@ -351,6 +355,7 @@ export const handleSubmit = async (image) => {
|
|
|
351
355
|
state.debug_mode && console.log("Success handler called");
|
|
352
356
|
successHandler(result);
|
|
353
357
|
}
|
|
358
|
+
return result;
|
|
354
359
|
} finally {
|
|
355
360
|
spinner.remove();
|
|
356
361
|
}
|
|
@@ -372,6 +377,46 @@ export const handleSubmit = async (image) => {
|
|
|
372
377
|
}
|
|
373
378
|
};
|
|
374
379
|
|
|
380
|
+
export const finishBatch = async () => {
|
|
381
|
+
const clientId = state.clientId;
|
|
382
|
+
const qrSessionId = getQrSessionId();
|
|
383
|
+
|
|
384
|
+
if (!clientId || !qrSessionId) {
|
|
385
|
+
throw new Error('CLIENT-ID and QR session are required to finish the batch');
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
state.updateHandler?.({ status: 'batch_finish_started' });
|
|
389
|
+
|
|
390
|
+
const response = await fetch(API_URLS.FINISH_BATCH, {
|
|
391
|
+
method: 'POST',
|
|
392
|
+
headers: {
|
|
393
|
+
'CLIENT-ID': clientId,
|
|
394
|
+
'QR-SESSION-ID': qrSessionId,
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
if (!response.ok) {
|
|
399
|
+
const errorData = await response.json().catch(() => null);
|
|
400
|
+
const message = errorData?.detail || `HTTP error! status: ${response.status}`;
|
|
401
|
+
const error = new Error(message);
|
|
402
|
+
error.status = response.status;
|
|
403
|
+
error.detail = errorData;
|
|
404
|
+
state.updateHandler?.({
|
|
405
|
+
status: 'batch_finish_failed',
|
|
406
|
+
error: errorData,
|
|
407
|
+
statusCode: response.status,
|
|
408
|
+
});
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const result = await response.json();
|
|
413
|
+
state.updateHandler?.({
|
|
414
|
+
status: 'batch_finish_completed',
|
|
415
|
+
document_count: result.document_count,
|
|
416
|
+
});
|
|
417
|
+
return result;
|
|
418
|
+
};
|
|
419
|
+
|
|
375
420
|
export const fetchBlueprints = async () => {
|
|
376
421
|
const requestOptions = {
|
|
377
422
|
method: 'POST',
|
package/core/capture/anydoc.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { state } from '../state.js';
|
|
2
2
|
import { handleSubmit, ensurePackageUploaded, fireResultSetter } from '../api.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { createVideo } from '../../components/video.js';
|
|
3
|
+
import { removeOverlay, restartCameraForNextCapture } from '../lifecycle.js';
|
|
4
|
+
import { promptForAnotherCapture } from '../multi-submission.js';
|
|
6
5
|
import { createAnydocPageControls } from '../../components/anydocPageControls.js';
|
|
7
6
|
|
|
8
7
|
export const handleAnydocPageCapture = () => {
|
|
@@ -31,28 +30,7 @@ export const handleAnydocPageCapture = () => {
|
|
|
31
30
|
async () => {
|
|
32
31
|
state.debug_mode && console.log('Add page clicked, restarting camera');
|
|
33
32
|
state.anydocPageControls?.hide();
|
|
34
|
-
|
|
35
|
-
if (state.cropImgRef.previewImg) {
|
|
36
|
-
state.cropImgRef.previewImg.style.display = 'none';
|
|
37
|
-
state.cropImgRef.previewImg.style.top = '';
|
|
38
|
-
state.cropImgRef.previewImg.style.left = '';
|
|
39
|
-
state.cropImgRef.previewImg.style.transform = '';
|
|
40
|
-
state.cropImgRef.previewImg.src = '';
|
|
41
|
-
}
|
|
42
|
-
const ctx = state.cropImgRef.getContext("2d");
|
|
43
|
-
ctx.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
|
|
44
|
-
state.cropImgRef.hideBorder?.();
|
|
45
|
-
}
|
|
46
|
-
if (!state.videoRef) {
|
|
47
|
-
state.videoRef = document.getElementById("veryfi-video-ref");
|
|
48
|
-
if (!state.videoRef && state.container) {
|
|
49
|
-
createVideo(state.container);
|
|
50
|
-
await new Promise(resolve => setTimeout(resolve, 10));
|
|
51
|
-
state.videoRef = document.getElementById("veryfi-video-ref");
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
showVideoOverlay();
|
|
55
|
-
await newStartLens();
|
|
33
|
+
await restartCameraForNextCapture();
|
|
56
34
|
},
|
|
57
35
|
async () => {
|
|
58
36
|
state.debug_mode && console.log(`Submitting ${state.anydocPages.length} anydoc pages`);
|
|
@@ -70,6 +48,16 @@ export const handleAnydocPageCapture = () => {
|
|
|
70
48
|
// upload the cumulative zip now and surface bucket/package_path
|
|
71
49
|
// through the showCamera setter.
|
|
72
50
|
await fireResultSetter({ image: state.finalImage });
|
|
51
|
+
} else if (state.multiSubmission) {
|
|
52
|
+
// Multi-submission QR: submit this document, then ask whether another
|
|
53
|
+
// capture is needed instead of tearing the overlay down. autoCloseOnSubmit
|
|
54
|
+
// is false below so teardown is owned here.
|
|
55
|
+
const result = await handleSubmit(state.finalImage);
|
|
56
|
+
if (result) {
|
|
57
|
+
promptForAnotherCapture(restartCameraForNextCapture);
|
|
58
|
+
} else {
|
|
59
|
+
removeOverlay();
|
|
60
|
+
}
|
|
73
61
|
} else {
|
|
74
62
|
handleSubmit(state.finalImage);
|
|
75
63
|
}
|
|
@@ -79,7 +67,8 @@ export const handleAnydocPageCapture = () => {
|
|
|
79
67
|
addPageText: state.anydocAddPageText,
|
|
80
68
|
submitText: partnerDriven ? 'Done' : state.anydocSubmitText,
|
|
81
69
|
onClose: state.onClose,
|
|
82
|
-
onCloseRedirectUrl: state.onCloseRedirectUrl
|
|
70
|
+
onCloseRedirectUrl: state.onCloseRedirectUrl,
|
|
71
|
+
autoCloseOnSubmit: !state.multiSubmission,
|
|
83
72
|
}
|
|
84
73
|
);
|
|
85
74
|
|
package/core/capture/document.js
CHANGED
|
@@ -3,7 +3,8 @@ import { cropWasm } from '../wasm-processing.js';
|
|
|
3
3
|
import { checkIfDocumentOnCapture, checkIfBlurOnCapture, checkIfLcdOnCapture } from '../validation.js';
|
|
4
4
|
import { docReady, handleSubmit, ensurePackageUploaded, fireResultSetter } from '../api.js';
|
|
5
5
|
import { hideVideoOverlay } from '../overlay-controls.js';
|
|
6
|
-
import { stopLens, startStitching, stopStitching, removeOverlay } from '../lifecycle.js';
|
|
6
|
+
import { stopLens, startStitching, stopStitching, removeOverlay, restartCameraForNextCapture } from '../lifecycle.js';
|
|
7
|
+
import { promptForAnotherCapture } from '../multi-submission.js';
|
|
7
8
|
import { onCropPreviewReady, holdSubmitForFieldDetectionIfNeeded } from '../crop-field-detection.js';
|
|
8
9
|
import { generateDeviceIDifNeeded } from '../device.js';
|
|
9
10
|
import { createSubmitButton } from '../../components/submitButton.js';
|
|
@@ -273,11 +274,15 @@ export const newCapture = async () => {
|
|
|
273
274
|
const packageInfo = await ensurePackageUploaded();
|
|
274
275
|
state.customSubmitHandler(state.finalImage, packageInfo);
|
|
275
276
|
} else {
|
|
276
|
-
await handleSubmit(state.finalImage);
|
|
277
|
+
const result = await handleSubmit(state.finalImage);
|
|
278
|
+
if (state.multiSubmission && result) {
|
|
279
|
+
state.submitButton?.hide?.();
|
|
280
|
+
promptForAnotherCapture(restartCameraForNextCapture);
|
|
281
|
+
}
|
|
277
282
|
}
|
|
278
283
|
},
|
|
279
284
|
removeOverlay,
|
|
280
|
-
{ buttonText: partnerDriven ? 'Done' : 'Submit' }
|
|
285
|
+
{ buttonText: partnerDriven ? 'Done' : 'Submit', autoClose: !state.multiSubmission }
|
|
281
286
|
);
|
|
282
287
|
(state.enableSubmit || partnerDriven) && state.submitButton.show();
|
|
283
288
|
holdSubmitForFieldDetectionIfNeeded();
|
|
@@ -2,6 +2,7 @@ import { state } from '../state.js';
|
|
|
2
2
|
import { handleSubmit, addPackageScan, ensurePackageUploaded } from '../api.js';
|
|
3
3
|
import { hideVideoOverlay, showVideoOverlay } from '../overlay-controls.js';
|
|
4
4
|
import { removeOverlay, newStartLens } from '../lifecycle.js';
|
|
5
|
+
import { promptForAnotherCapture } from '../multi-submission.js';
|
|
5
6
|
import { createSubmitButton } from '../../components/submitButton.js';
|
|
6
7
|
|
|
7
8
|
let previewRecorder = null;
|
|
@@ -480,18 +481,20 @@ const submitVideoBlob = async (videoBlob) => {
|
|
|
480
481
|
state.updateHandler?.({ status: 'processing_completed' });
|
|
481
482
|
|
|
482
483
|
const uploadStartTime = performance.now();
|
|
484
|
+
let submitResult;
|
|
483
485
|
if (typeof state.customSubmitHandler === 'function') {
|
|
484
486
|
const packageInfo = await ensurePackageUploaded();
|
|
485
487
|
state.customSubmitHandler(videoBlob, packageInfo);
|
|
488
|
+
submitResult = videoBlob;
|
|
486
489
|
} else {
|
|
487
|
-
await handleSubmit(submitData);
|
|
490
|
+
submitResult = await handleSubmit(submitData);
|
|
488
491
|
}
|
|
489
492
|
const uploadDurationSec = (performance.now() - uploadStartTime) / 1000;
|
|
490
493
|
const totalDurationSec = (performance.now() - submissionStartTime) / 1000;
|
|
491
494
|
console.log(`[prescription_label] submission complete — total: ${totalDurationSec.toFixed(2)}s, upload: ${uploadDurationSec.toFixed(2)}s, video: ${(videoBlob.size / 1024).toFixed(1)} KB`);
|
|
492
495
|
|
|
493
496
|
state.updateHandler?.({ status: 'capture_completed' });
|
|
494
|
-
return
|
|
497
|
+
return submitResult;
|
|
495
498
|
};
|
|
496
499
|
|
|
497
500
|
export const capturePrescriptionLabel = async () => {
|
|
@@ -532,13 +535,26 @@ export const capturePrescriptionLabel = async () => {
|
|
|
532
535
|
isBase64: false,
|
|
533
536
|
});
|
|
534
537
|
|
|
538
|
+
const restartPrescription = async () => {
|
|
539
|
+
cleanupPreview();
|
|
540
|
+
showVideoOverlay();
|
|
541
|
+
state.prescriptionLabelGuide?.show?.();
|
|
542
|
+
await newStartLens();
|
|
543
|
+
};
|
|
544
|
+
|
|
535
545
|
state.submitButton = createSubmitButton(
|
|
536
546
|
state.container,
|
|
537
547
|
async () => {
|
|
538
|
-
await submitVideoBlob(submissionBlob);
|
|
539
|
-
|
|
548
|
+
const result = await submitVideoBlob(submissionBlob);
|
|
549
|
+
if (state.multiSubmission && result) {
|
|
550
|
+
state.submitButton?.hide?.();
|
|
551
|
+
promptForAnotherCapture(restartPrescription);
|
|
552
|
+
} else {
|
|
553
|
+
removeOverlay();
|
|
554
|
+
}
|
|
540
555
|
},
|
|
541
|
-
() => {}
|
|
556
|
+
() => {},
|
|
557
|
+
{ autoClose: false }
|
|
542
558
|
);
|
|
543
559
|
const submitBtnEl = document.getElementById('veryfi-submit-button');
|
|
544
560
|
if (submitBtnEl) {
|
package/core/constants.js
CHANGED
|
@@ -15,6 +15,7 @@ const buildApiUrls = (base) => ({
|
|
|
15
15
|
SEND_CROPPED: `${base}/rest/send-cropped`,
|
|
16
16
|
SEND_PACKAGE: `${base}/rest/send-package`,
|
|
17
17
|
PROCESS_DOCUMENT: `${base}/api/document`,
|
|
18
|
+
FINISH_BATCH: `${base}/api/finish`,
|
|
18
19
|
BLUEPRINTS: `${base}/api/blueprints`,
|
|
19
20
|
FINGERPRINT: 'https://fp.veryfi.com',
|
|
20
21
|
FINGERPRINT_SCRIPT: 'https://fp.veryfi.com/web/v<version>/<apiKey>/loader_v<loaderVersion>.js',
|
|
@@ -27,12 +28,18 @@ export const API_URLS = buildApiUrls(API_BASES.PROD);
|
|
|
27
28
|
|
|
28
29
|
export const setApiEnvironment = (useDevApi) => {
|
|
29
30
|
const base = useDevApi ? API_BASES.DEV : API_BASES.PROD;
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
setApiBaseUrl(base);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Point all SDK API and WASM requests at a specific LFB origin (e.g. local Docker). */
|
|
35
|
+
export const setApiBaseUrl = (base) => {
|
|
36
|
+
const normalized = String(base || '').replace(/\/$/, '');
|
|
37
|
+
Object.assign(API_URLS, buildApiUrls(normalized));
|
|
38
|
+
WASM.BASE_URL = `${normalized}${WASM_PATH}`;
|
|
32
39
|
};
|
|
33
40
|
|
|
34
41
|
export const DEFAULTS = {
|
|
35
|
-
SDK_VERSION: '3.
|
|
42
|
+
SDK_VERSION: '3.3.2',
|
|
36
43
|
BLUR_THRESHOLD: 0.7,
|
|
37
44
|
LCD_THRESHOLD: 0.5,
|
|
38
45
|
BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
|
|
@@ -86,6 +93,13 @@ export const MESSAGES = {
|
|
|
86
93
|
ANYDOC_SUBMIT: 'Submit',
|
|
87
94
|
ANYDOC_FLIP: 'Please flip the document and capture the other side',
|
|
88
95
|
ANYDOC_FLIP_CONTINUE: 'Continue',
|
|
96
|
+
MULTI_CAPTURE_PROMPT: 'Do you need to capture another document?',
|
|
97
|
+
MULTI_CAPTURE_YES: 'Capture another',
|
|
98
|
+
MULTI_CAPTURE_NO: "No, I'm done",
|
|
99
|
+
BATCH_FINISHING: 'Completing batch...',
|
|
100
|
+
BATCH_FINISH_FAILED: 'Failed to notify your system. Would you like to try again?',
|
|
101
|
+
BATCH_FINISH_RETRY: 'Retry',
|
|
102
|
+
BATCH_FINISH_CANCEL: 'Close without notifying',
|
|
89
103
|
AUTH_FAILED: 'Authorization failed, please provide correct client-id or contact customer support at support@veryfi.com',
|
|
90
104
|
AUTH_FAILED_CONTACT: 'Authorization failed, please contact customer support at support@veryfi.com',
|
|
91
105
|
};
|
package/core/lifecycle.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { state, refs, resetState, actions } from './state.js';
|
|
2
2
|
import { getVideo, displayVideo } from './camera.js';
|
|
3
3
|
import { initializeWasmWrapper, sendWasm, sendCardWasm, getLongImage, logDocument, stopWasm, resetAutoCaptureCounters, resetFieldDetectorBootstrap } from './wasm-processing.js';
|
|
4
|
-
import { hideVideoOverlay } from './overlay-controls.js';
|
|
4
|
+
import { hideVideoOverlay, showVideoOverlay } from './overlay-controls.js';
|
|
5
5
|
import { docReady, handleSubmit, fireResultSetter } from './api.js';
|
|
6
6
|
import { createSubmitButton } from '../components/submitButton.js';
|
|
7
|
+
import { createVideo } from '../components/video.js';
|
|
7
8
|
import {
|
|
8
9
|
cancelCropFieldDetection,
|
|
9
10
|
onCropPreviewReady,
|
|
@@ -158,6 +159,35 @@ export const newStartLens = async () => {
|
|
|
158
159
|
}
|
|
159
160
|
};
|
|
160
161
|
|
|
162
|
+
// Re-enter capture without tearing down the overlay/container. Clears the crop
|
|
163
|
+
// preview, makes sure the video element exists, re-shows the overlay and
|
|
164
|
+
// restarts the lens. Shared by the anydoc "Add Page" loop and the
|
|
165
|
+
// multi-submission "Capture another" loop.
|
|
166
|
+
export const restartCameraForNextCapture = async () => {
|
|
167
|
+
if (state.cropImgRef) {
|
|
168
|
+
if (state.cropImgRef.previewImg) {
|
|
169
|
+
state.cropImgRef.previewImg.style.display = 'none';
|
|
170
|
+
state.cropImgRef.previewImg.style.top = '';
|
|
171
|
+
state.cropImgRef.previewImg.style.left = '';
|
|
172
|
+
state.cropImgRef.previewImg.style.transform = '';
|
|
173
|
+
state.cropImgRef.previewImg.src = '';
|
|
174
|
+
}
|
|
175
|
+
const ctx = state.cropImgRef.getContext('2d');
|
|
176
|
+
ctx?.clearRect(0, 0, state.cropImgRef.width, state.cropImgRef.height);
|
|
177
|
+
state.cropImgRef.hideBorder?.();
|
|
178
|
+
}
|
|
179
|
+
if (!state.videoRef) {
|
|
180
|
+
state.videoRef = document.getElementById('veryfi-video-ref');
|
|
181
|
+
if (!state.videoRef && state.container) {
|
|
182
|
+
createVideo(state.container);
|
|
183
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
184
|
+
state.videoRef = document.getElementById('veryfi-video-ref');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
showVideoOverlay();
|
|
188
|
+
await newStartLens();
|
|
189
|
+
};
|
|
190
|
+
|
|
161
191
|
export const stopLens = () => {
|
|
162
192
|
state.started = false;
|
|
163
193
|
if (state.intervalRef) {
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { state, resetForNextSubmission } from './state.js';
|
|
2
|
+
import { removeOverlay, restartCameraForNextCapture } from './lifecycle.js';
|
|
3
|
+
import { createMultiCaptureModal } from '../components/multiCaptureModal.js';
|
|
4
|
+
import { finishBatch } from './api.js';
|
|
5
|
+
import { createSpinner } from '../components/spinner.js';
|
|
6
|
+
import { MESSAGES } from './constants.js';
|
|
7
|
+
|
|
8
|
+
const showBatchFinishRetryDialog = (onRetry) => {
|
|
9
|
+
const retryModal = createMultiCaptureModal(
|
|
10
|
+
state.container,
|
|
11
|
+
async () => {
|
|
12
|
+
retryModal.remove();
|
|
13
|
+
await onRetry();
|
|
14
|
+
},
|
|
15
|
+
() => {
|
|
16
|
+
retryModal.remove();
|
|
17
|
+
removeOverlay();
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
message: MESSAGES.BATCH_FINISH_FAILED,
|
|
21
|
+
yesButtonText: MESSAGES.BATCH_FINISH_RETRY,
|
|
22
|
+
noButtonText: MESSAGES.BATCH_FINISH_CANCEL,
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
retryModal.show();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const finishBatchSession = async () => {
|
|
30
|
+
const spinner = createSpinner(state.container, MESSAGES.BATCH_FINISHING);
|
|
31
|
+
spinner.show();
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
await finishBatch();
|
|
35
|
+
removeOverlay();
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error.status === 502) {
|
|
38
|
+
showBatchFinishRetryDialog(finishBatchSession);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
state.failureHandler?.(error);
|
|
42
|
+
removeOverlay();
|
|
43
|
+
} finally {
|
|
44
|
+
spinner.remove();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleMultiSubmissionDone = async () => {
|
|
49
|
+
if (state.batchReady) {
|
|
50
|
+
await finishBatchSession();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
state.updateHandler?.({ status: 'multi_submission_completed' });
|
|
55
|
+
removeOverlay();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const promptForAnotherCapture = (restart) => {
|
|
59
|
+
const doRestart = typeof restart === 'function' ? restart : restartCameraForNextCapture;
|
|
60
|
+
|
|
61
|
+
const modal = createMultiCaptureModal(
|
|
62
|
+
state.container,
|
|
63
|
+
async () => {
|
|
64
|
+
modal.remove();
|
|
65
|
+
resetForNextSubmission();
|
|
66
|
+
try {
|
|
67
|
+
await doRestart();
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error('Failed to restart capture for next submission:', error);
|
|
70
|
+
state.failureHandler?.(error);
|
|
71
|
+
removeOverlay();
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
() => {
|
|
75
|
+
modal.remove();
|
|
76
|
+
handleMultiSubmissionDone().catch((error) => {
|
|
77
|
+
console.error('Failed to complete multi-submission session:', error);
|
|
78
|
+
state.failureHandler?.(error);
|
|
79
|
+
removeOverlay();
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
message: state.multiCaptureModalMessage,
|
|
84
|
+
yesButtonText: state.multiCaptureYesButtonText,
|
|
85
|
+
noButtonText: state.multiCaptureNoButtonText,
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
modal.show();
|
|
90
|
+
};
|
package/core/state.js
CHANGED
|
@@ -135,6 +135,11 @@ export const state = {
|
|
|
135
135
|
packageUploadId: null,
|
|
136
136
|
anydocAddPageText: MESSAGES.ANYDOC_ADD_PAGE,
|
|
137
137
|
anydocSubmitText: MESSAGES.ANYDOC_SUBMIT,
|
|
138
|
+
multiSubmission: false,
|
|
139
|
+
batchReady: false,
|
|
140
|
+
multiCaptureModalMessage: MESSAGES.MULTI_CAPTURE_PROMPT,
|
|
141
|
+
multiCaptureYesButtonText: MESSAGES.MULTI_CAPTURE_YES,
|
|
142
|
+
multiCaptureNoButtonText: MESSAGES.MULTI_CAPTURE_NO,
|
|
138
143
|
anydocShowFlipMessage: false,
|
|
139
144
|
anydocFlipMessageText: MESSAGES.ANYDOC_FLIP,
|
|
140
145
|
anydocFlipContinueText: MESSAGES.ANYDOC_FLIP_CONTINUE,
|
|
@@ -380,3 +385,43 @@ export const resetState = () => {
|
|
|
380
385
|
|
|
381
386
|
state.debug_mode && console.log("State reset complete");
|
|
382
387
|
};
|
|
388
|
+
|
|
389
|
+
// Soft reset between submissions of a multi-submission QR session. Clears only
|
|
390
|
+
// the per-document accumulators and per-submission UI so the next capture
|
|
391
|
+
// produces a fresh, independent document — while keeping the session alive
|
|
392
|
+
// (hasInit, clientData/session, camera) so we don't re-init the whole SDK.
|
|
393
|
+
export const resetForNextSubmission = () => {
|
|
394
|
+
state.debug_mode && console.log("Resetting state for next submission");
|
|
395
|
+
|
|
396
|
+
if (state.submitButton) {
|
|
397
|
+
state.submitButton.remove();
|
|
398
|
+
state.submitButton = null;
|
|
399
|
+
}
|
|
400
|
+
if (state.anydocPageControls) {
|
|
401
|
+
state.anydocPageControls.remove();
|
|
402
|
+
state.anydocPageControls = null;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
state.docReadyResult = null;
|
|
406
|
+
state.fullSizeImage = null;
|
|
407
|
+
state.finalImage = null;
|
|
408
|
+
state.frontImage = null;
|
|
409
|
+
state.backImage = null;
|
|
410
|
+
state.previewData = null;
|
|
411
|
+
state.fieldDetectionResult = null;
|
|
412
|
+
state.blurStatus = "";
|
|
413
|
+
state.lcdStatus = false;
|
|
414
|
+
state.isDocument = false;
|
|
415
|
+
state.hasCoordinates = false;
|
|
416
|
+
state.coordinates = [];
|
|
417
|
+
state.anydocPages = [];
|
|
418
|
+
state.packageScans = [];
|
|
419
|
+
state.packageFilename = null;
|
|
420
|
+
state.packageUploadId = null;
|
|
421
|
+
|
|
422
|
+
if (state.lensFlavor === 'checks') {
|
|
423
|
+
state.isCapturingFront = true;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
state.exitButtonRef?.show?.();
|
|
427
|
+
};
|
package/core/ui-core.js
CHANGED
|
@@ -12,6 +12,14 @@ export const createCoreElements = async () => {
|
|
|
12
12
|
|
|
13
13
|
if (state.container) {
|
|
14
14
|
state.container.dataset.fullscreen = state.enableFullScreen.toString();
|
|
15
|
+
|
|
16
|
+
// Long-receipt on desktop: render the camera view and green box full-screen at the
|
|
17
|
+
// camera's native aspect ratio (object-fit: contain) so the detector contour lines
|
|
18
|
+
// up with the displayed frame instead of being mismatched by cover-vs-fill scaling.
|
|
19
|
+
const isDesktop = !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
20
|
+
navigator.userAgent
|
|
21
|
+
);
|
|
22
|
+
state.container.dataset.longDocDesktop = (isDesktop && state.lensFlavor === 'long_document').toString();
|
|
15
23
|
}
|
|
16
24
|
|
|
17
25
|
if (state.lensFlavor !== "credit_card" && state.lensFlavor !== "upload") {
|
package/package.json
CHANGED
package/veryfi-lens.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { state, refs, actions } from './core/state.js';
|
|
2
|
-
import { DEFAULTS, setApiEnvironment } from './core/constants.js';
|
|
2
|
+
import { DEFAULTS, setApiEnvironment, setApiBaseUrl } from './core/constants.js';
|
|
3
3
|
import { flattenObject, parseUA, getBrowserData } from './core/utils.js';
|
|
4
4
|
import { generateDeviceIDifNeeded, setLCDDetectionSettings, setFrontBackDetectionSettings, getDocumentLcdStatus } from './core/device.js';
|
|
5
5
|
import {
|
|
@@ -42,7 +42,11 @@ const VeryfiLens = {
|
|
|
42
42
|
config.debug_mode && console.log("init", config);
|
|
43
43
|
state.clientId = clientId;
|
|
44
44
|
state.useDevApi = config.useDevApi ?? false;
|
|
45
|
-
|
|
45
|
+
if (config.lfbApiBaseUrl) {
|
|
46
|
+
setApiBaseUrl(config.lfbApiBaseUrl);
|
|
47
|
+
} else {
|
|
48
|
+
setApiEnvironment(state.useDevApi);
|
|
49
|
+
}
|
|
46
50
|
state.clientData = await validatePartner(state.clientId);
|
|
47
51
|
config.debug_mode && console.log(state.clientData);
|
|
48
52
|
|