veryfi-lens-wasm 2.0.0-beta.2 → 2.0.0-beta.3
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/captureButton.js +2 -2
- package/components/croppedImage.js +2 -2
- package/components/exitButton.js +2 -2
- package/components/overlayContainer.js +1 -0
- package/components/stitchingButton.js +12 -0
- package/components/torchButton.js +4 -2
- package/package.json +1 -1
- package/veryfi-lens.js +226 -116
|
@@ -28,8 +28,8 @@ export const createCaptureButton = (container, onCapture, onStopStitching) => {
|
|
|
28
28
|
const isLandscape = window.innerWidth > window.innerHeight;
|
|
29
29
|
|
|
30
30
|
if (isMobile && isLandscape) {
|
|
31
|
-
button.style.right = '
|
|
32
|
-
button.style.top = '
|
|
31
|
+
button.style.right = '10px';
|
|
32
|
+
button.style.top = 'calc(50vh - 2rem)';
|
|
33
33
|
button.style.left = 'unset';
|
|
34
34
|
button.style.bottom = 'unset';
|
|
35
35
|
} else {
|
|
@@ -20,14 +20,14 @@ export const createCroppedImage = (container) => {
|
|
|
20
20
|
|
|
21
21
|
if (isMobile) {
|
|
22
22
|
cropImgCanvas.style.width = '370px';
|
|
23
|
-
cropImgCanvas.style.height = '
|
|
23
|
+
cropImgCanvas.style.height = '95vh';
|
|
24
24
|
cropImgCanvas.style.maxWidth = '350px';
|
|
25
25
|
cropImgCanvas.style.position = 'fixed';
|
|
26
26
|
cropImgCanvas.style.top = '';
|
|
27
27
|
cropImgCanvas.style.left = '';
|
|
28
28
|
} else {
|
|
29
29
|
cropImgCanvas.style.width = '100%';
|
|
30
|
-
cropImgCanvas.style.height = '
|
|
30
|
+
cropImgCanvas.style.height = '95%';
|
|
31
31
|
cropImgCanvas.style.maxWidth = '370px';
|
|
32
32
|
cropImgCanvas.style.position = 'absolute';
|
|
33
33
|
cropImgCanvas.style.top = '';
|
package/components/exitButton.js
CHANGED
|
@@ -43,8 +43,8 @@ export const createExitButton = (container, options, removeOverlay) => {
|
|
|
43
43
|
const isLandscape = window.innerWidth > window.innerHeight;
|
|
44
44
|
|
|
45
45
|
if (isMobile && isLandscape) {
|
|
46
|
-
button.style.right = '
|
|
47
|
-
button.style.top = '20vh';
|
|
46
|
+
button.style.right = '50px';
|
|
47
|
+
button.style.top = 'calc(20vh - 20px)';
|
|
48
48
|
button.style.left = 'unset';
|
|
49
49
|
button.style.bottom = 'unset';
|
|
50
50
|
} else {
|
|
@@ -32,6 +32,18 @@ export const createStitchingButton = (container, onStartStitching, onStopStitchi
|
|
|
32
32
|
button.style.setProperty(key, `var(${cssVar}, ${value})`);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
+
const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
|
|
36
|
+
const isLandscape = window.innerWidth > window.innerHeight;
|
|
37
|
+
|
|
38
|
+
if (isMobile && isLandscape) {
|
|
39
|
+
button.style.right = '10px';
|
|
40
|
+
button.style.top = 'calc(50vh - 2rem)';
|
|
41
|
+
button.style.left = 'unset';
|
|
42
|
+
button.style.bottom = 'unset';
|
|
43
|
+
} else {
|
|
44
|
+
// Apply default styles directly
|
|
45
|
+
}
|
|
46
|
+
|
|
35
47
|
let isStitching = false;
|
|
36
48
|
|
|
37
49
|
const updateButtonAppearance = () => {
|
|
@@ -36,10 +36,12 @@ export const createTorchButton = (container, toggleCallback) => {
|
|
|
36
36
|
|
|
37
37
|
const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
|
|
38
38
|
const isLandscape = window.innerWidth > window.innerHeight;
|
|
39
|
+
|
|
40
|
+
!isMobile && (button.style.display = 'none');
|
|
39
41
|
|
|
40
42
|
if (isMobile && isLandscape) {
|
|
41
|
-
button.style.right = '
|
|
42
|
-
button.style.botom = '20vh';
|
|
43
|
+
button.style.right = '50px';
|
|
44
|
+
button.style.botom = 'calc(20vh - 20px)';
|
|
43
45
|
button.style.left = 'unset';
|
|
44
46
|
button.style.top = 'unset';
|
|
45
47
|
} else {
|
package/package.json
CHANGED
package/veryfi-lens.js
CHANGED
|
@@ -84,6 +84,8 @@ const VeryfiLens = (function () {
|
|
|
84
84
|
visitorIdPro: null,
|
|
85
85
|
uuidv4: null,
|
|
86
86
|
fpPromise: null,
|
|
87
|
+
debug_mode: false,
|
|
88
|
+
enableSubmit: true,
|
|
87
89
|
|
|
88
90
|
// UI Configuration
|
|
89
91
|
docValidation: true,
|
|
@@ -170,6 +172,10 @@ const VeryfiLens = (function () {
|
|
|
170
172
|
};
|
|
171
173
|
|
|
172
174
|
const getVideo = async (lensFlavor) => {
|
|
175
|
+
if (!state.videoRef) {
|
|
176
|
+
console.error('Video element not found');
|
|
177
|
+
throw new Error('Video element not initialized');
|
|
178
|
+
}
|
|
173
179
|
const isDesktop = window.screen.width > window.screen.height;
|
|
174
180
|
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
175
181
|
|
|
@@ -254,7 +260,7 @@ const VeryfiLens = (function () {
|
|
|
254
260
|
if (navigator) {
|
|
255
261
|
try {
|
|
256
262
|
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
257
|
-
console.log(devices);
|
|
263
|
+
state.debug_mode && console.log(devices);
|
|
258
264
|
const videoDevices = devices.filter(
|
|
259
265
|
(device) => device.kind === "videoinput"
|
|
260
266
|
);
|
|
@@ -264,7 +270,7 @@ const VeryfiLens = (function () {
|
|
|
264
270
|
if (isAndroid) {
|
|
265
271
|
for (const device of videoDevices) {
|
|
266
272
|
if (device.label.includes("camera2 0")) {
|
|
267
|
-
console.log("Main camera found", device.deviceId);
|
|
273
|
+
state.debug_mode && console.log("Main camera found", device.deviceId);
|
|
268
274
|
mainCameraDeviceId = device.deviceId;
|
|
269
275
|
useMainCamera = true;
|
|
270
276
|
break;
|
|
@@ -315,7 +321,7 @@ const VeryfiLens = (function () {
|
|
|
315
321
|
console.error("Error accessing the camera", error);
|
|
316
322
|
}
|
|
317
323
|
} else {
|
|
318
|
-
console.log("No navigator available");
|
|
324
|
+
state.debug_mode && console.log("No navigator available");
|
|
319
325
|
}
|
|
320
326
|
};
|
|
321
327
|
|
|
@@ -342,10 +348,10 @@ const VeryfiLens = (function () {
|
|
|
342
348
|
console.error("Error toggling torch:", err);
|
|
343
349
|
}
|
|
344
350
|
} else {
|
|
345
|
-
console.log("Torch not supported on this device");
|
|
351
|
+
state.debug_mode && console.log("Torch not supported on this device");
|
|
346
352
|
}
|
|
347
353
|
} else {
|
|
348
|
-
console.log("Camera not initialized");
|
|
354
|
+
state.debug_mode && console.log("Camera not initialized");
|
|
349
355
|
}
|
|
350
356
|
};
|
|
351
357
|
|
|
@@ -409,14 +415,14 @@ const VeryfiLens = (function () {
|
|
|
409
415
|
if (!state.shouldProcessCC) return;
|
|
410
416
|
|
|
411
417
|
if (state.CCPhase === "FlipCard") {
|
|
412
|
-
console.log("In flip phase");
|
|
418
|
+
state.debug_mode && console.log("In flip phase");
|
|
413
419
|
if (state.timeStamp === 0) {
|
|
414
|
-
console.log("Starting flip timer");
|
|
420
|
+
state.debug_mode && console.log("Starting flip timer");
|
|
415
421
|
state.timeStamp = Date.now();
|
|
416
422
|
}
|
|
417
423
|
|
|
418
424
|
if (Date.now() - state.timeStamp > 3000) {
|
|
419
|
-
console.log("Flip time complete, switching to back scanning");
|
|
425
|
+
state.debug_mode && console.log("Flip time complete, switching to back scanning");
|
|
420
426
|
state.CCPhase = "ScanningBack";
|
|
421
427
|
state.timeStamp = 0;
|
|
422
428
|
state.backScanningStartTime = Date.now();
|
|
@@ -433,8 +439,8 @@ const VeryfiLens = (function () {
|
|
|
433
439
|
state.backScanningStartTime &&
|
|
434
440
|
Date.now() - state.backScanningStartTime > 5000 &&
|
|
435
441
|
!state.submitButtonShown) {
|
|
436
|
-
console.log("5 seconds elapsed during back scanning, showing submit button");
|
|
437
|
-
showSubmitButton();
|
|
442
|
+
state.debug_mode && console.log("5 seconds elapsed during back scanning, showing submit button");
|
|
443
|
+
state.enableSubmit && showSubmitButton();
|
|
438
444
|
return;
|
|
439
445
|
}
|
|
440
446
|
|
|
@@ -497,7 +503,7 @@ const VeryfiLens = (function () {
|
|
|
497
503
|
};
|
|
498
504
|
|
|
499
505
|
function logDocument(detectorResult, corners, nDocs) {
|
|
500
|
-
console.log(
|
|
506
|
+
state.debug_mode && console.log(
|
|
501
507
|
`Detector Result: ${detectorResult}, Documents Detected: ${nDocs}`
|
|
502
508
|
);
|
|
503
509
|
if (nDocs > 0) {
|
|
@@ -535,7 +541,7 @@ const VeryfiLens = (function () {
|
|
|
535
541
|
);
|
|
536
542
|
|
|
537
543
|
state.creditCardStatus = status;
|
|
538
|
-
console.log("New card data:", newData);
|
|
544
|
+
state.debug_mode && console.log("New card data:", newData);
|
|
539
545
|
|
|
540
546
|
// Track if card data has changed
|
|
541
547
|
let hasDataChanged = false;
|
|
@@ -555,7 +561,7 @@ const VeryfiLens = (function () {
|
|
|
555
561
|
|
|
556
562
|
// Call resultSetter if data has changed
|
|
557
563
|
if (hasDataChanged && state.resultSetter && typeof state.resultSetter === 'function') {
|
|
558
|
-
console.log("Updating result with new card data:", state.cardData);
|
|
564
|
+
state.debug_mode && console.log("Updating result with new card data:", state.cardData);
|
|
559
565
|
state.resultSetter(state.cardData);
|
|
560
566
|
}
|
|
561
567
|
|
|
@@ -564,7 +570,7 @@ const VeryfiLens = (function () {
|
|
|
564
570
|
if (state.cardData.status === "AutoCaptureResultDone") {
|
|
565
571
|
switch (state.CCPhase) {
|
|
566
572
|
case "ScanningFront":
|
|
567
|
-
console.log("Front scan complete, switching to flip phase");
|
|
573
|
+
state.debug_mode && console.log("Front scan complete, switching to flip phase");
|
|
568
574
|
state.cardData.status = ""; // Reset status for next phase
|
|
569
575
|
state.CCPhase = "FlipCard";
|
|
570
576
|
state.timeStamp = 0; // Reset timestamp
|
|
@@ -572,7 +578,7 @@ const VeryfiLens = (function () {
|
|
|
572
578
|
break;
|
|
573
579
|
|
|
574
580
|
case "ScanningBack":
|
|
575
|
-
console.log("Back scan processing");
|
|
581
|
+
state.debug_mode && console.log("Back scan processing");
|
|
576
582
|
// Check what data we still need to scan for
|
|
577
583
|
const scanForNumber = !state.cardData.number;
|
|
578
584
|
const scanForName = !state.cardData.name;
|
|
@@ -581,7 +587,7 @@ const VeryfiLens = (function () {
|
|
|
581
587
|
|
|
582
588
|
// If we have CVV, show submit button immediately
|
|
583
589
|
if (state.cardData.cvv) {
|
|
584
|
-
console.log("CVV captured");
|
|
590
|
+
state.debug_mode && console.log("CVV captured");
|
|
585
591
|
state.successHandler && state.successHandler({
|
|
586
592
|
cardData: state.cardData
|
|
587
593
|
});
|
|
@@ -771,7 +777,7 @@ const VeryfiLens = (function () {
|
|
|
771
777
|
];
|
|
772
778
|
|
|
773
779
|
const uuid = sections.join('-').toLowerCase();
|
|
774
|
-
console.log("Generated UUID:", uuid);
|
|
780
|
+
state.debug_mode && console.log("Generated UUID:", uuid);
|
|
775
781
|
|
|
776
782
|
return uuid;
|
|
777
783
|
};
|
|
@@ -783,13 +789,13 @@ const VeryfiLens = (function () {
|
|
|
783
789
|
return { blurStatus: state.blurStatus, variance: variance };
|
|
784
790
|
} else if (variance < 0) {
|
|
785
791
|
state.blurStatus = false;
|
|
786
|
-
console.log(
|
|
792
|
+
state.debug_mode && console.log(
|
|
787
793
|
"Variance is lower than 0, Which means image was not cropped and did not pass through blur detection"
|
|
788
794
|
);
|
|
789
795
|
return { blurStatus: state.blurStatus, variance: variance };
|
|
790
796
|
} else {
|
|
791
797
|
state.blurStatus = true;
|
|
792
|
-
console.log(state.blurStatus, state.variance)
|
|
798
|
+
state.debug_mode && console.log(state.blurStatus, state.variance)
|
|
793
799
|
return { blurStatus: state.blurStatus, variance: variance };
|
|
794
800
|
}
|
|
795
801
|
};
|
|
@@ -828,7 +834,7 @@ const VeryfiLens = (function () {
|
|
|
828
834
|
};
|
|
829
835
|
|
|
830
836
|
const renderVideoOverlayIfNeeded = () => {
|
|
831
|
-
console.log("Rendering video overlay");
|
|
837
|
+
state.debug_mode && console.log("Rendering video overlay");
|
|
832
838
|
!state.videoOverlay && (state.videoOverlay = createVideoOverlay(state.container));
|
|
833
839
|
|
|
834
840
|
if (state.exitButton) {
|
|
@@ -852,7 +858,7 @@ const VeryfiLens = (function () {
|
|
|
852
858
|
};
|
|
853
859
|
|
|
854
860
|
const renderCreditCardIfNeeded = () => {
|
|
855
|
-
console.log("Rendering credit card overlay");
|
|
861
|
+
state.debug_mode && console.log("Rendering credit card overlay");
|
|
856
862
|
if (state.videoRef) {
|
|
857
863
|
createVideo(state.container);
|
|
858
864
|
state.videoRef = document.getElementById("veryfi-video-ref");
|
|
@@ -867,19 +873,19 @@ const VeryfiLens = (function () {
|
|
|
867
873
|
}
|
|
868
874
|
|
|
869
875
|
const renderModalsIfNeeded = () => {
|
|
870
|
-
console.log("Initializing modals");
|
|
876
|
+
state.debug_mode && console.log("Initializing modals");
|
|
871
877
|
|
|
872
878
|
if (state.isBlurModal) {
|
|
873
879
|
state.blurModal = createBlurModal(
|
|
874
880
|
state.container,
|
|
875
881
|
state.croppedImage,
|
|
876
882
|
async () => {
|
|
877
|
-
console.log("Retaking photo");
|
|
883
|
+
state.debug_mode && console.log("Retaking photo");
|
|
878
884
|
await newStartLens();
|
|
879
885
|
showVideoOverlay();
|
|
880
886
|
},
|
|
881
887
|
() => {
|
|
882
|
-
console.log("Submitting anyway");
|
|
888
|
+
state.debug_mode && console.log("Submitting anyway");
|
|
883
889
|
hideVideoOverlay();
|
|
884
890
|
state.submitHandler && state.submitHandler(state.finalImage);
|
|
885
891
|
}
|
|
@@ -891,12 +897,12 @@ const VeryfiLens = (function () {
|
|
|
891
897
|
state.container,
|
|
892
898
|
state.croppedImage,
|
|
893
899
|
async () => {
|
|
894
|
-
console.log("Retaking photo");
|
|
900
|
+
state.debug_mode && console.log("Retaking photo");
|
|
895
901
|
await newStartLens();
|
|
896
902
|
showVideoOverlay();
|
|
897
903
|
},
|
|
898
904
|
() => {
|
|
899
|
-
console.log("Submitting anyway");
|
|
905
|
+
state.debug_mode && console.log("Submitting anyway");
|
|
900
906
|
hideVideoOverlay();
|
|
901
907
|
state.submitHandler && state.submitHandler(state.finalImage);
|
|
902
908
|
}
|
|
@@ -923,13 +929,13 @@ const VeryfiLens = (function () {
|
|
|
923
929
|
if (!response.ok) {
|
|
924
930
|
state.updateHandler && state.updateHandler({ status: 'validation_failed' });
|
|
925
931
|
if (response.status === 401) {
|
|
926
|
-
throw new Error('Authorization failed, please provide correct client-id or contact customer support');
|
|
932
|
+
throw new Error('Authorization failed, please provide correct client-id or contact customer support at support@veryfi.com');
|
|
927
933
|
}
|
|
928
934
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
929
935
|
}
|
|
930
936
|
if (response.status === 200) {
|
|
931
937
|
state.updateHandler && state.updateHandler({ status: 'validation_completed' });
|
|
932
|
-
|
|
938
|
+
state.debug_mode && console.log('Partner validated')
|
|
933
939
|
return response.json()
|
|
934
940
|
}
|
|
935
941
|
} catch (error) {
|
|
@@ -985,7 +991,7 @@ const VeryfiLens = (function () {
|
|
|
985
991
|
|
|
986
992
|
if (!response.ok) {
|
|
987
993
|
if (response.status === 401) {
|
|
988
|
-
throw new Error('Authorization failed, please contact customer support');
|
|
994
|
+
throw new Error('Authorization failed, please contact customer support at support@veryfi.com');
|
|
989
995
|
}
|
|
990
996
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
991
997
|
}
|
|
@@ -1039,10 +1045,10 @@ const VeryfiLens = (function () {
|
|
|
1039
1045
|
}
|
|
1040
1046
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
1041
1047
|
}
|
|
1042
|
-
console.log("Document submitted successfully");
|
|
1048
|
+
state.debug_mode && console.log("Document submitted successfully");
|
|
1043
1049
|
state.updateHandler && state.updateHandler({ status: 'submission_completed' });
|
|
1044
1050
|
if (state.successHandler && typeof state.successHandler === 'function') {
|
|
1045
|
-
|
|
1051
|
+
state.debug_mode && console.log("Success handler called");
|
|
1046
1052
|
const result = await response.json();
|
|
1047
1053
|
state.successHandler(result);
|
|
1048
1054
|
}
|
|
@@ -1071,37 +1077,71 @@ const VeryfiLens = (function () {
|
|
|
1071
1077
|
stopLens();
|
|
1072
1078
|
document.body.removeChild(state.container);
|
|
1073
1079
|
state.usingOverlayContainer = false;
|
|
1074
|
-
state.hasInit = false;
|
|
1075
|
-
state.started = false;
|
|
1076
|
-
state.videoOverlay = null;
|
|
1077
|
-
state.cardOverlay = null;
|
|
1078
|
-
state.blurModal = null;
|
|
1079
|
-
state.documentModal = null;
|
|
1080
|
-
state.frameRef = null;
|
|
1081
|
-
state.cropImgRef = null;
|
|
1082
|
-
state.videoRef = null;
|
|
1083
|
-
state.boxRef = null;
|
|
1084
|
-
wasmWrapper.release();
|
|
1085
|
-
wasmWrapper = null;
|
|
1086
1080
|
} else {
|
|
1087
1081
|
stopLens();
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1082
|
+
}
|
|
1083
|
+
resetState();
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
const resetState = () => {
|
|
1087
|
+
state.debug_mode && console.log("Resetting state");
|
|
1088
|
+
// Reset all state properties
|
|
1089
|
+
state.hasInit = false;
|
|
1090
|
+
state.started = false;
|
|
1091
|
+
state.isProcessing = false;
|
|
1092
|
+
state.isStitching = false;
|
|
1093
|
+
state.isCapturingFront = false;
|
|
1094
|
+
state.shouldProcessCC = true;
|
|
1095
|
+
state.isDocument = false;
|
|
1096
|
+
state.hasCoordinates = false;
|
|
1097
|
+
state.coordinates = [];
|
|
1098
|
+
state.blurStatus = "";
|
|
1099
|
+
state.variance = null;
|
|
1100
|
+
state.docReadyResult = null;
|
|
1101
|
+
state.fullSizeImage = null;
|
|
1102
|
+
state.finalImage = null;
|
|
1103
|
+
state.frontImage = null;
|
|
1104
|
+
state.backImage = null;
|
|
1105
|
+
state.previewData = null;
|
|
1106
|
+
|
|
1107
|
+
// Reset UI references
|
|
1108
|
+
state.videoOverlay = null;
|
|
1109
|
+
state.cardOverlay = null;
|
|
1110
|
+
state.blurModal = null;
|
|
1111
|
+
state.documentModal = null;
|
|
1112
|
+
state.frameRef = null;
|
|
1113
|
+
state.cropImgRef = null;
|
|
1114
|
+
state.videoRef = null;
|
|
1115
|
+
state.boxRef = null;
|
|
1116
|
+
state.torchButton = null;
|
|
1117
|
+
state.captureButton = null;
|
|
1118
|
+
state.submitButton = null;
|
|
1119
|
+
state.exitButton = null;
|
|
1120
|
+
state.longPreview = null;
|
|
1121
|
+
state.stitchingButton = null;
|
|
1122
|
+
state.checkImagesComponent = null;
|
|
1123
|
+
|
|
1124
|
+
// Reset container if using overlay
|
|
1125
|
+
if (state.usingOverlayContainer) {
|
|
1126
|
+
state.container = null;
|
|
1127
|
+
state.usingOverlayContainer = false;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// Reset intervals and tracks
|
|
1131
|
+
state.intervalRef = null;
|
|
1132
|
+
state.torchTrack = null;
|
|
1133
|
+
|
|
1134
|
+
// Reset WASM
|
|
1135
|
+
if (wasmWrapper) {
|
|
1098
1136
|
wasmWrapper.release();
|
|
1099
1137
|
wasmWrapper = null;
|
|
1100
1138
|
}
|
|
1139
|
+
|
|
1140
|
+
state.debug_mode && console.log("State reset complete");
|
|
1101
1141
|
};
|
|
1102
1142
|
|
|
1103
1143
|
const startStitching = () => {
|
|
1104
|
-
console.log("[EVENT] start stitching");
|
|
1144
|
+
state.debug_mode && console.log("[EVENT] start stitching");
|
|
1105
1145
|
state.isStitching = true;
|
|
1106
1146
|
state.isStitchingProcess = true;
|
|
1107
1147
|
state.stitchingButton.setStitching(true);
|
|
@@ -1109,7 +1149,7 @@ const VeryfiLens = (function () {
|
|
|
1109
1149
|
};
|
|
1110
1150
|
|
|
1111
1151
|
const stopStitching = async () => {
|
|
1112
|
-
|
|
1152
|
+
state.debug_mode && console.log("[EVENT] stop stitching");
|
|
1113
1153
|
state.isStitching = false;
|
|
1114
1154
|
state.isStitchingProcess = false;
|
|
1115
1155
|
state.stitchingButton.setStitching(false);
|
|
@@ -1124,16 +1164,16 @@ const VeryfiLens = (function () {
|
|
|
1124
1164
|
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
1125
1165
|
state.resultSetter({ ...state.docReadyResult, image: state.finalImage });
|
|
1126
1166
|
}
|
|
1127
|
-
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
1167
|
+
state.estate.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
1128
1168
|
handleSubmit(state.finalImage);
|
|
1129
1169
|
}, removeOverlay);
|
|
1130
|
-
state.submitButton.show();
|
|
1170
|
+
state.enableSubmit && state.submitButton.show();
|
|
1131
1171
|
}
|
|
1132
1172
|
state.updateHandler && state.updateHandler({ status: 'stitching_completed' });
|
|
1133
1173
|
};
|
|
1134
1174
|
|
|
1135
1175
|
const captureUploaded = async (imageFile) => {
|
|
1136
|
-
|
|
1176
|
+
state.debug_mode && console.log("Setting document callback");
|
|
1137
1177
|
// wasmWrapper.setDocumentCallback(logDocument);
|
|
1138
1178
|
return new Promise((resolve, reject) => {
|
|
1139
1179
|
const reader = new FileReader();
|
|
@@ -1165,7 +1205,7 @@ const VeryfiLens = (function () {
|
|
|
1165
1205
|
state.resultSetter && state.resultSetter(croppedBase64);
|
|
1166
1206
|
} else {
|
|
1167
1207
|
// No document detected, return the original image
|
|
1168
|
-
|
|
1208
|
+
state.debug_mode && console.log("No document detected, returning original image");
|
|
1169
1209
|
const canvas = document.createElement('canvas');
|
|
1170
1210
|
canvas.width = img.width;
|
|
1171
1211
|
canvas.height = img.height;
|
|
@@ -1191,13 +1231,13 @@ const VeryfiLens = (function () {
|
|
|
1191
1231
|
|
|
1192
1232
|
const newCapture = async () => {
|
|
1193
1233
|
try {
|
|
1194
|
-
console.log("[EVENT] capture");
|
|
1234
|
+
state.debug_mode && console.log("[EVENT] capture");
|
|
1195
1235
|
state.updateHandler && state.updateHandler({ status: 'capture_started' });
|
|
1196
1236
|
|
|
1197
1237
|
switch (state.lensFlavor) {
|
|
1198
1238
|
case "long_document":
|
|
1199
1239
|
if (!state.isStitching) {
|
|
1200
|
-
|
|
1240
|
+
state.debug_mode && console.log("Starting stitching");
|
|
1201
1241
|
startStitching();
|
|
1202
1242
|
} else {
|
|
1203
1243
|
await stopStitching();
|
|
@@ -1226,7 +1266,7 @@ const VeryfiLens = (function () {
|
|
|
1226
1266
|
state.updateHandler && state.updateHandler({ status: 'processing_started' });
|
|
1227
1267
|
state.docReadyResult = await docReady();
|
|
1228
1268
|
state.updateHandler && state.updateHandler({ status: 'processing_completed' });
|
|
1229
|
-
|
|
1269
|
+
state.debug_mode && console.log("Document processed successfully");
|
|
1230
1270
|
}
|
|
1231
1271
|
|
|
1232
1272
|
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
@@ -1246,7 +1286,7 @@ const VeryfiLens = (function () {
|
|
|
1246
1286
|
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
1247
1287
|
handleSubmit(state.finalImage);
|
|
1248
1288
|
}, removeOverlay);
|
|
1249
|
-
state.submitButton.show();
|
|
1289
|
+
state.enableSubmit && state.submitButton.show();
|
|
1250
1290
|
}
|
|
1251
1291
|
}
|
|
1252
1292
|
} catch (error) {
|
|
@@ -1274,7 +1314,7 @@ const VeryfiLens = (function () {
|
|
|
1274
1314
|
state.finalImage = state.frontImage;
|
|
1275
1315
|
stopLens();
|
|
1276
1316
|
|
|
1277
|
-
|
|
1317
|
+
state.debug_mode && console.log("Front capture - Document detected:", state.isDocument);
|
|
1278
1318
|
const isDocumentDetected = checkIfDocumentOnCapture();
|
|
1279
1319
|
if (!isDocumentDetected) {
|
|
1280
1320
|
showVideoOverlay();
|
|
@@ -1314,7 +1354,7 @@ const VeryfiLens = (function () {
|
|
|
1314
1354
|
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
1315
1355
|
handleSubmit(state.frontImage);
|
|
1316
1356
|
}, removeOverlay);
|
|
1317
|
-
|
|
1357
|
+
state.enableSubmit && state.submitButton.show();
|
|
1318
1358
|
}
|
|
1319
1359
|
// Call success handler with front image only
|
|
1320
1360
|
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
@@ -1333,7 +1373,7 @@ const VeryfiLens = (function () {
|
|
|
1333
1373
|
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
1334
1374
|
handleSubmit(state.frontImage);
|
|
1335
1375
|
}, removeOverlay);
|
|
1336
|
-
state.submitButton.show();
|
|
1376
|
+
state.enableSubmit && state.submitButton.show();
|
|
1337
1377
|
}
|
|
1338
1378
|
// Call success handler with front image only
|
|
1339
1379
|
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
@@ -1346,13 +1386,13 @@ const VeryfiLens = (function () {
|
|
|
1346
1386
|
} else {
|
|
1347
1387
|
state.backImage = await cropWasm();
|
|
1348
1388
|
|
|
1349
|
-
console.log("Back capture - Document detected:", state.isDocument);
|
|
1389
|
+
state.debug_mode && console.log("Back capture - Document detected:", state.isDocument);
|
|
1350
1390
|
// Check for document first
|
|
1351
1391
|
const isDocumentDetected = checkIfDocumentOnCapture();
|
|
1352
|
-
console.log("Back capture - Document check result:", isDocumentDetected);
|
|
1392
|
+
state.debug_mode && console.log("Back capture - Document check result:", isDocumentDetected);
|
|
1353
1393
|
|
|
1354
1394
|
if (!isDocumentDetected) {
|
|
1355
|
-
console.log("Back capture - No document detected, showing video overlay");
|
|
1395
|
+
state.debug_mode && console.log("Back capture - No document detected, showing video overlay");
|
|
1356
1396
|
showVideoOverlay();
|
|
1357
1397
|
return;
|
|
1358
1398
|
}
|
|
@@ -1390,7 +1430,7 @@ const VeryfiLens = (function () {
|
|
|
1390
1430
|
state.captureBackOfCheck ? handleSubmit(zipContent) : handleSubmit(state.frontImage);
|
|
1391
1431
|
|
|
1392
1432
|
}, removeOverlay);
|
|
1393
|
-
|
|
1433
|
+
state.enableSubmit && state.submitButton.show();
|
|
1394
1434
|
}
|
|
1395
1435
|
|
|
1396
1436
|
// Call success handler with properly structured data
|
|
@@ -1416,7 +1456,7 @@ const VeryfiLens = (function () {
|
|
|
1416
1456
|
|
|
1417
1457
|
const checkIfDocumentOnCapture = () => {
|
|
1418
1458
|
if (!state.isDocument) {
|
|
1419
|
-
|
|
1459
|
+
state.debug_mode && console.log("No document detected");
|
|
1420
1460
|
if (state.isDocumentSetter && typeof state.isDocumentSetter === 'function') {
|
|
1421
1461
|
state.isDocumentSetter(false);
|
|
1422
1462
|
}
|
|
@@ -1437,7 +1477,7 @@ const VeryfiLens = (function () {
|
|
|
1437
1477
|
|
|
1438
1478
|
const checkIfBlurOnCapture = () => {
|
|
1439
1479
|
if (state.blurStatus) {
|
|
1440
|
-
|
|
1480
|
+
state.debug_mode && console.log("Blur detected");
|
|
1441
1481
|
if (state.isBlurrySetter && typeof state.isBlurrySetter === 'function') {
|
|
1442
1482
|
state.isBlurrySetter(true);
|
|
1443
1483
|
}
|
|
@@ -1540,35 +1580,84 @@ const VeryfiLens = (function () {
|
|
|
1540
1580
|
|
|
1541
1581
|
}
|
|
1542
1582
|
|
|
1543
|
-
const createCoreElements = () => {
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
if (
|
|
1551
|
-
|
|
1552
|
-
state.
|
|
1583
|
+
const createCoreElements = async () => {
|
|
1584
|
+
state.debug_mode && console.log("Creating core elements");
|
|
1585
|
+
|
|
1586
|
+
try {
|
|
1587
|
+
// Wait a small amount of time to ensure DOM is ready
|
|
1588
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
1589
|
+
|
|
1590
|
+
if (state.lensFlavor !== "credit_card" && state.lensFlavor !== "upload") {
|
|
1591
|
+
// Create cropped image
|
|
1592
|
+
if (!state.cropImgRef) {
|
|
1593
|
+
state.croppedImage = createCroppedImage(state.container);
|
|
1594
|
+
state.cropImgRef = document.getElementById("veryfi-crop-img-ref");
|
|
1595
|
+
if (!state.cropImgRef) {
|
|
1596
|
+
throw new Error('Failed to create cropped image element');
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
// Create frame
|
|
1601
|
+
if (!state.frameRef) {
|
|
1602
|
+
createFrame(state.container);
|
|
1603
|
+
state.frameRef = document.getElementById("veryfi-frame-ref");
|
|
1604
|
+
if (!state.frameRef) {
|
|
1605
|
+
throw new Error('Failed to create frame element');
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
// Create box
|
|
1610
|
+
if (!state.boxRef) {
|
|
1611
|
+
createGreenBox(state.container);
|
|
1612
|
+
state.boxRef = document.getElementById("veryfi-box-ref");
|
|
1613
|
+
if (!state.boxRef) {
|
|
1614
|
+
throw new Error('Failed to create box element');
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1553
1617
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1618
|
+
|
|
1619
|
+
// Create video element for all flavors except upload
|
|
1620
|
+
if (state.lensFlavor !== "upload") {
|
|
1621
|
+
if (!state.videoRef) {
|
|
1622
|
+
// Ensure container exists before creating video
|
|
1623
|
+
if (!state.container) {
|
|
1624
|
+
throw new Error('Container not found');
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
// Create video element
|
|
1628
|
+
createVideo(state.container);
|
|
1629
|
+
|
|
1630
|
+
// Wait briefly for DOM update
|
|
1631
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
1632
|
+
|
|
1633
|
+
// Get video reference
|
|
1634
|
+
state.videoRef = document.getElementById("veryfi-video-ref");
|
|
1635
|
+
|
|
1636
|
+
if (!state.videoRef) {
|
|
1637
|
+
throw new Error('Failed to create video element');
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1557
1640
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
state.
|
|
1641
|
+
|
|
1642
|
+
// Log creation status
|
|
1643
|
+
state.debug_mode && console.log("Core elements created:", {
|
|
1644
|
+
container: !!state.container,
|
|
1645
|
+
cropImgRef: !!state.cropImgRef,
|
|
1646
|
+
frameRef: !!state.frameRef,
|
|
1647
|
+
videoRef: !!state.videoRef,
|
|
1648
|
+
boxRef: !!state.boxRef
|
|
1649
|
+
});
|
|
1650
|
+
|
|
1651
|
+
// Verify critical elements exist based on lens flavor
|
|
1652
|
+
if (state.lensFlavor !== "upload" && !state.videoRef) {
|
|
1653
|
+
throw new Error('Critical elements missing: video element required');
|
|
1563
1654
|
}
|
|
1655
|
+
|
|
1656
|
+
return true;
|
|
1657
|
+
} catch (error) {
|
|
1658
|
+
console.error("Error creating core elements:", error);
|
|
1659
|
+
throw error;
|
|
1564
1660
|
}
|
|
1565
|
-
// Log creation of elements
|
|
1566
|
-
console.log("Core elements created:", {
|
|
1567
|
-
cropImgRef: !!state.cropImgRef,
|
|
1568
|
-
frameRef: !!state.frameRef,
|
|
1569
|
-
videoRef: !!state.videoRef,
|
|
1570
|
-
boxRef: !!state.boxRef
|
|
1571
|
-
});
|
|
1572
1661
|
};
|
|
1573
1662
|
|
|
1574
1663
|
const getDeviceData = async () => {
|
|
@@ -1597,11 +1686,11 @@ const VeryfiLens = (function () {
|
|
|
1597
1686
|
|
|
1598
1687
|
const showSubmitButton = () => {
|
|
1599
1688
|
if (!state.submitButtonShown) {
|
|
1600
|
-
console.log("Showing submit button");
|
|
1689
|
+
state.debug_mode && console.log("Showing submit button");
|
|
1601
1690
|
state.submitButtonShown = true;
|
|
1602
1691
|
hideVideoOverlay();
|
|
1603
1692
|
if (state.submitHandler && typeof state.submitHandler === 'function') {
|
|
1604
|
-
console.log(state.submitHandler);
|
|
1693
|
+
state.debug_mode && console.log(state.submitHandler);
|
|
1605
1694
|
state.submitButton = createSubmitButton(
|
|
1606
1695
|
state.cardOverlay.element,
|
|
1607
1696
|
() => {
|
|
@@ -1610,7 +1699,7 @@ const VeryfiLens = (function () {
|
|
|
1610
1699
|
},
|
|
1611
1700
|
removeOverlay
|
|
1612
1701
|
);
|
|
1613
|
-
|
|
1702
|
+
state.submitButton.show();
|
|
1614
1703
|
}
|
|
1615
1704
|
}
|
|
1616
1705
|
};
|
|
@@ -1620,7 +1709,7 @@ const VeryfiLens = (function () {
|
|
|
1620
1709
|
const fp = await FingerprintJS.load();
|
|
1621
1710
|
const result = await fp.get();
|
|
1622
1711
|
state.visitorId = result.visitorId;
|
|
1623
|
-
console.log("Basic fingerprint obtained:", state.visitorId);
|
|
1712
|
+
state.debug_mode && console.log("Basic fingerprint obtained:", state.visitorId);
|
|
1624
1713
|
} catch (error) {
|
|
1625
1714
|
console.error('Failed to load FingerprintJS:', error);
|
|
1626
1715
|
throw error;
|
|
@@ -1634,7 +1723,7 @@ const VeryfiLens = (function () {
|
|
|
1634
1723
|
});
|
|
1635
1724
|
const result = await fp.get();
|
|
1636
1725
|
state.visitorId = result.visitorId;
|
|
1637
|
-
console.log("Pro fingerprint obtained:", state.visitorId);
|
|
1726
|
+
state.debug_mode && console.log("Pro fingerprint obtained:", state.visitorId);
|
|
1638
1727
|
} catch (error) {
|
|
1639
1728
|
console.error('Failed to load FingerprintJS Pro:', error);
|
|
1640
1729
|
throw error;
|
|
@@ -1647,13 +1736,16 @@ const VeryfiLens = (function () {
|
|
|
1647
1736
|
try {
|
|
1648
1737
|
if (state.hasInit) return;
|
|
1649
1738
|
state.hasInit = true;
|
|
1650
|
-
|
|
1739
|
+
config.debug_mode && (state.debug_mode = true);
|
|
1740
|
+
config.debug_mode && console.log("init", config);
|
|
1651
1741
|
state.clientId = clientId
|
|
1652
1742
|
state.clientData = await validatePartner(state.clientId);
|
|
1653
|
-
console.log(state.clientData);
|
|
1743
|
+
config.debug_mode && console.log(state.clientData);
|
|
1654
1744
|
|
|
1655
1745
|
if (typeof window !== 'undefined') {
|
|
1746
|
+
|
|
1656
1747
|
try {
|
|
1748
|
+
state.debug_mode && console.log("Getting fingerprint");
|
|
1657
1749
|
if (state.clientData.fingerprint_js_on) {
|
|
1658
1750
|
await getFingerprintPro();
|
|
1659
1751
|
} else {
|
|
@@ -1673,7 +1765,6 @@ const VeryfiLens = (function () {
|
|
|
1673
1765
|
case "credit_card":
|
|
1674
1766
|
}
|
|
1675
1767
|
|
|
1676
|
-
// console.log(config);
|
|
1677
1768
|
Object.keys(config).forEach(key => {
|
|
1678
1769
|
if (state.hasOwnProperty(key)) {
|
|
1679
1770
|
state[key] = config[key];
|
|
@@ -1681,12 +1772,14 @@ const VeryfiLens = (function () {
|
|
|
1681
1772
|
});
|
|
1682
1773
|
|
|
1683
1774
|
if (config.container) {
|
|
1775
|
+
state.debug_mode && console.log("Container found", config.container);
|
|
1684
1776
|
state.container = document.getElementById(config.container);
|
|
1685
1777
|
} else {
|
|
1686
1778
|
state.usingOverlayContainer = true;
|
|
1687
1779
|
state.container = createOverlayContainer();
|
|
1688
1780
|
}
|
|
1689
|
-
|
|
1781
|
+
|
|
1782
|
+
state.debug_mode && console.log(state);
|
|
1690
1783
|
|
|
1691
1784
|
} catch (error) {
|
|
1692
1785
|
console.error("Error initializing Lens:", error);
|
|
@@ -1699,22 +1792,29 @@ const VeryfiLens = (function () {
|
|
|
1699
1792
|
|
|
1700
1793
|
showCamera: async (setter) => {
|
|
1701
1794
|
try {
|
|
1702
|
-
|
|
1795
|
+
state.debug_mode && console.log("Starting camera initialization");
|
|
1703
1796
|
setter && (state.resultSetter = setter);
|
|
1704
1797
|
|
|
1705
1798
|
// Ensure container exists
|
|
1706
1799
|
if (!state.container) {
|
|
1707
|
-
console.log("Creating overlay container");
|
|
1800
|
+
state.debug_mode && console.log("Creating overlay container");
|
|
1708
1801
|
state.container = createOverlayContainer();
|
|
1802
|
+
if (!state.container) {
|
|
1803
|
+
throw new Error('Failed to create container');
|
|
1804
|
+
}
|
|
1709
1805
|
}
|
|
1710
1806
|
|
|
1711
|
-
// Create core elements
|
|
1712
|
-
|
|
1713
|
-
|
|
1807
|
+
// Create core elements and verify success
|
|
1808
|
+
const elementsCreated = await createCoreElements();
|
|
1809
|
+
|
|
1810
|
+
if (!elementsCreated) {
|
|
1811
|
+
throw new Error('Failed to create core elements');
|
|
1812
|
+
}
|
|
1714
1813
|
|
|
1715
1814
|
// Initialize WASM if needed
|
|
1716
1815
|
await initializeWasmWrapper();
|
|
1717
1816
|
|
|
1817
|
+
// Render appropriate UI elements based on lens flavor
|
|
1718
1818
|
switch (state.lensFlavor) {
|
|
1719
1819
|
case 'upload':
|
|
1720
1820
|
!state.fileUpload && (state.fileUpload = createFileUpload(state.container, captureUploaded, handleSubmit));
|
|
@@ -1723,7 +1823,7 @@ const VeryfiLens = (function () {
|
|
|
1723
1823
|
renderCreditCardIfNeeded();
|
|
1724
1824
|
break;
|
|
1725
1825
|
default:
|
|
1726
|
-
console.log('Rendering UI elements');
|
|
1826
|
+
state.debug_mode && console.log('Rendering UI elements');
|
|
1727
1827
|
renderModalsIfNeeded();
|
|
1728
1828
|
renderVideoOverlayIfNeeded();
|
|
1729
1829
|
break;
|
|
@@ -1731,16 +1831,17 @@ const VeryfiLens = (function () {
|
|
|
1731
1831
|
|
|
1732
1832
|
// Start lens if not already started
|
|
1733
1833
|
if (!state.started) {
|
|
1734
|
-
console.log("Starting lens");
|
|
1834
|
+
state.debug_mode && console.log("Starting lens");
|
|
1735
1835
|
await newStartLens();
|
|
1736
1836
|
}
|
|
1737
1837
|
|
|
1738
|
-
console.log("Camera initialization complete");
|
|
1838
|
+
state.debug_mode && console.log("Camera initialization complete");
|
|
1739
1839
|
} catch (error) {
|
|
1740
1840
|
console.error("Error in showCamera:", error);
|
|
1741
1841
|
if (state.failureHandler && typeof state.failureHandler === 'function') {
|
|
1742
1842
|
state.failureHandler(error);
|
|
1743
1843
|
}
|
|
1844
|
+
throw error;
|
|
1744
1845
|
}
|
|
1745
1846
|
},
|
|
1746
1847
|
|
|
@@ -1784,8 +1885,17 @@ const VeryfiLens = (function () {
|
|
|
1784
1885
|
},
|
|
1785
1886
|
|
|
1786
1887
|
stop: () => {
|
|
1787
|
-
|
|
1788
|
-
|
|
1888
|
+
try {
|
|
1889
|
+
state.debug_mode && console.log("Stopping VeryfiLens");
|
|
1890
|
+
stopLens();
|
|
1891
|
+
removeOverlay();
|
|
1892
|
+
state.debug_mode && console.log("VeryfiLens stopped successfully");
|
|
1893
|
+
} catch (error) {
|
|
1894
|
+
console.error("Error stopping VeryfiLens:", error);
|
|
1895
|
+
if (state.failureHandler) {
|
|
1896
|
+
state.failureHandler(error);
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1789
1899
|
}
|
|
1790
1900
|
};
|
|
1791
1901
|
})();
|