veryfi-lens-wasm 2.0.0-beta.2 → 2.0.0-beta.4

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.
@@ -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 = '20px';
32
- button.style.top = '215px';
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 {
@@ -0,0 +1,44 @@
1
+ export const createCardDataButton = (container, onGetData, removeOverlay) => {
2
+ const button = document.createElement('button');
3
+ button.id = 'veryfi-card-data-button';
4
+ button.textContent = 'Get Card Data';
5
+
6
+ const defaultStyles = {
7
+ position: 'absolute',
8
+ bottom: '50px',
9
+ right: 'calc(50% - 50px)', // Position on the right side
10
+ padding: '10px 20px',
11
+ backgroundColor: '#4CAF50',
12
+ color: 'white',
13
+ border: 'none',
14
+ borderRadius: '5px',
15
+ cursor: 'pointer',
16
+ fontSize: '16px',
17
+ zIndex: '1000',
18
+ display: 'none',
19
+ pointerEvents: 'auto'
20
+ };
21
+
22
+ Object.entries(defaultStyles).forEach(([key, value]) => {
23
+ button.style[key] = value;
24
+ });
25
+
26
+ button.addEventListener('click', () => {
27
+ onGetData();
28
+ if (removeOverlay) {
29
+ removeOverlay();
30
+ }
31
+ });
32
+
33
+ container.appendChild(button);
34
+
35
+ return {
36
+ show: () => {
37
+ button.style.display = 'block';
38
+ },
39
+ hide: () => {
40
+ button.style.display = 'none';
41
+ },
42
+ button: button
43
+ };
44
+ };
@@ -114,8 +114,10 @@ export const createCreditCardComponent = (container) => {
114
114
  const showFlipMessage = () => {
115
115
  const flipMessage = document.createElement('p');
116
116
  flipMessage.textContent = 'Please flip your card';
117
+ flipMessage.id = 'flip-message';
117
118
  flipMessage.style.cssText = `
118
119
  position: absolute;
120
+ display: block;
119
121
  width: var(--flip-message-width);
120
122
  bottom: var(--flip-message-bottom);
121
123
  left: 50%;
@@ -129,6 +131,13 @@ export const createCreditCardComponent = (container) => {
129
131
  return flipMessage;
130
132
  };
131
133
 
134
+ const hideFlipMessage = () => {
135
+ const flipMessage = cardOverlay.querySelector('#flip-message');
136
+ if (flipMessage) {
137
+ flipMessage.style.display = 'none';
138
+ }
139
+ };
140
+
132
141
  // Method to update CSS variables
133
142
  const updateStyles = (styles) => {
134
143
  Object.entries(styles).forEach(([key, value]) => {
@@ -140,6 +149,7 @@ export const createCreditCardComponent = (container) => {
140
149
  element: cardOverlay,
141
150
  updateCardData,
142
151
  showFlipMessage,
152
+ hideFlipMessage,
143
153
  updateStyles,
144
154
  };
145
155
  };
@@ -20,14 +20,14 @@ export const createCroppedImage = (container) => {
20
20
 
21
21
  if (isMobile) {
22
22
  cropImgCanvas.style.width = '370px';
23
- cropImgCanvas.style.height = '90vh';
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 = '90%';
30
+ cropImgCanvas.style.height = '95%';
31
31
  cropImgCanvas.style.maxWidth = '370px';
32
32
  cropImgCanvas.style.position = 'absolute';
33
33
  cropImgCanvas.style.top = '';
@@ -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 = '44px';
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 {
@@ -1,4 +1,5 @@
1
1
  export const createOverlayContainer = () => {
2
+ console.log("Creating overlay container");
2
3
  // Create and append a style element with reset CSS
3
4
  const style = document.createElement('style');
4
5
  style.textContent = `
@@ -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 = '44px';
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.4",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
package/veryfi-lens.js CHANGED
@@ -23,6 +23,7 @@ import { createCreditCardComponent } from './components/creditCard.js';
23
23
  import { createStitchingButton } from './components/stitchingButton.js';
24
24
  import { createCheckImages } from './components/checkImages.js';
25
25
  import { createSpinner } from './components/spinner.js';
26
+ import { createCardDataButton } from './components/cardDataButton.js';
26
27
 
27
28
 
28
29
 
@@ -84,6 +85,8 @@ const VeryfiLens = (function () {
84
85
  visitorIdPro: null,
85
86
  uuidv4: null,
86
87
  fpPromise: null,
88
+ debug_mode: false,
89
+ enableSubmit: true,
87
90
 
88
91
  // UI Configuration
89
92
  docValidation: true,
@@ -103,6 +106,7 @@ const VeryfiLens = (function () {
103
106
  usingOverlayContainer: false,
104
107
  frontImageSetter: null,
105
108
  backImageSetter: null,
109
+ cardDataButton: null,
106
110
 
107
111
  // Handlers
108
112
  successHandler: null,
@@ -170,6 +174,10 @@ const VeryfiLens = (function () {
170
174
  };
171
175
 
172
176
  const getVideo = async (lensFlavor) => {
177
+ if (!state.videoRef) {
178
+ console.error('Video element not found');
179
+ throw new Error('Video element not initialized');
180
+ }
173
181
  const isDesktop = window.screen.width > window.screen.height;
174
182
  const isAndroid = /Android/i.test(navigator.userAgent);
175
183
 
@@ -254,7 +262,7 @@ const VeryfiLens = (function () {
254
262
  if (navigator) {
255
263
  try {
256
264
  const devices = await navigator.mediaDevices.enumerateDevices();
257
- console.log(devices);
265
+ state.debug_mode && console.log(devices);
258
266
  const videoDevices = devices.filter(
259
267
  (device) => device.kind === "videoinput"
260
268
  );
@@ -264,7 +272,7 @@ const VeryfiLens = (function () {
264
272
  if (isAndroid) {
265
273
  for (const device of videoDevices) {
266
274
  if (device.label.includes("camera2 0")) {
267
- console.log("Main camera found", device.deviceId);
275
+ state.debug_mode && console.log("Main camera found", device.deviceId);
268
276
  mainCameraDeviceId = device.deviceId;
269
277
  useMainCamera = true;
270
278
  break;
@@ -315,7 +323,7 @@ const VeryfiLens = (function () {
315
323
  console.error("Error accessing the camera", error);
316
324
  }
317
325
  } else {
318
- console.log("No navigator available");
326
+ state.debug_mode && console.log("No navigator available");
319
327
  }
320
328
  };
321
329
 
@@ -342,10 +350,10 @@ const VeryfiLens = (function () {
342
350
  console.error("Error toggling torch:", err);
343
351
  }
344
352
  } else {
345
- console.log("Torch not supported on this device");
353
+ state.debug_mode && console.log("Torch not supported on this device");
346
354
  }
347
355
  } else {
348
- console.log("Camera not initialized");
356
+ state.debug_mode && console.log("Camera not initialized");
349
357
  }
350
358
  };
351
359
 
@@ -409,14 +417,14 @@ const VeryfiLens = (function () {
409
417
  if (!state.shouldProcessCC) return;
410
418
 
411
419
  if (state.CCPhase === "FlipCard") {
412
- console.log("In flip phase");
420
+ state.debug_mode && console.log("In flip phase");
413
421
  if (state.timeStamp === 0) {
414
- console.log("Starting flip timer");
422
+ state.debug_mode && console.log("Starting flip timer");
415
423
  state.timeStamp = Date.now();
416
424
  }
417
425
 
418
426
  if (Date.now() - state.timeStamp > 3000) {
419
- console.log("Flip time complete, switching to back scanning");
427
+ state.debug_mode && console.log("Flip time complete, switching to back scanning");
420
428
  state.CCPhase = "ScanningBack";
421
429
  state.timeStamp = 0;
422
430
  state.backScanningStartTime = Date.now();
@@ -428,16 +436,28 @@ const VeryfiLens = (function () {
428
436
  return;
429
437
  }
430
438
 
431
- // Check if we're scanning back and 5 seconds have passed
432
- if (state.CCPhase === "ScanningBack" &&
433
- state.backScanningStartTime &&
434
- Date.now() - state.backScanningStartTime > 5000 &&
435
- !state.submitButtonShown) {
436
- console.log("5 seconds elapsed during back scanning, showing submit button");
437
- showSubmitButton();
438
- return;
439
+ // Check if we're in back scanning phase
440
+ if (state.CCPhase === "ScanningBack") {
441
+ // Initialize back scanning start time if not set
442
+ if (!state.backScanningStartTime) {
443
+ state.backScanningStartTime = Date.now();
444
+ }
445
+
446
+ // Check if 5 seconds have passed during back scanning
447
+ if (Date.now() - state.backScanningStartTime > 5000) {
448
+ if (!state.submitButtonShown) {
449
+ state.debug_mode && console.log("5 seconds elapsed during back scanning, showing card data button");
450
+ showCardDataButton();
451
+ state.shouldProcessCC = false; // Stop further processing
452
+ if (state.cardOverlay) {
453
+ // state.cardOverlay.element.style.display = 'none'; // Hide card overlay
454
+ }
455
+ return;
456
+ }
457
+ }
439
458
  }
440
459
 
460
+ // Rest of the existing sendCardWasm logic...
441
461
  if (state.cardData.status === "AutoCaptureResultDone" &&
442
462
  state.CCPhase === "ScanningBack") return;
443
463
 
@@ -497,7 +517,7 @@ const VeryfiLens = (function () {
497
517
  };
498
518
 
499
519
  function logDocument(detectorResult, corners, nDocs) {
500
- console.log(
520
+ state.debug_mode && console.log(
501
521
  `Detector Result: ${detectorResult}, Documents Detected: ${nDocs}`
502
522
  );
503
523
  if (nDocs > 0) {
@@ -535,7 +555,7 @@ const VeryfiLens = (function () {
535
555
  );
536
556
 
537
557
  state.creditCardStatus = status;
538
- console.log("New card data:", newData);
558
+ state.debug_mode && console.log("New card data:", newData);
539
559
 
540
560
  // Track if card data has changed
541
561
  let hasDataChanged = false;
@@ -545,7 +565,7 @@ const VeryfiLens = (function () {
545
565
  if (newData[key] !== undefined &&
546
566
  newData[key] !== null &&
547
567
  newData[key] !== "" &&
548
- state.cardData[key] !== newData[key]) { // Check if value is actually different
568
+ state.cardData[key] !== newData[key]) {
549
569
 
550
570
  state.cardData[key] = newData[key];
551
571
  hasDataChanged = true;
@@ -555,7 +575,7 @@ const VeryfiLens = (function () {
555
575
 
556
576
  // Call resultSetter if data has changed
557
577
  if (hasDataChanged && state.resultSetter && typeof state.resultSetter === 'function') {
558
- console.log("Updating result with new card data:", state.cardData);
578
+ state.debug_mode && console.log("Updating result with new card data:", state.cardData);
559
579
  state.resultSetter(state.cardData);
560
580
  }
561
581
 
@@ -564,7 +584,7 @@ const VeryfiLens = (function () {
564
584
  if (state.cardData.status === "AutoCaptureResultDone") {
565
585
  switch (state.CCPhase) {
566
586
  case "ScanningFront":
567
- console.log("Front scan complete, switching to flip phase");
587
+ state.debug_mode && console.log("Front scan complete, switching to flip phase");
568
588
  state.cardData.status = ""; // Reset status for next phase
569
589
  state.CCPhase = "FlipCard";
570
590
  state.timeStamp = 0; // Reset timestamp
@@ -572,20 +592,25 @@ const VeryfiLens = (function () {
572
592
  break;
573
593
 
574
594
  case "ScanningBack":
575
- console.log("Back scan processing");
576
- // Check what data we still need to scan for
577
- const scanForNumber = !state.cardData.number;
578
- const scanForName = !state.cardData.name;
579
- const scanForDate = !state.cardData.date;
580
- const scanForCvv = !state.cardData.cvv;
581
-
595
+ state.debug_mode && console.log("Back scan processing");
596
+
582
597
  // If we have CVV, show submit button immediately
583
598
  if (state.cardData.cvv) {
584
- console.log("CVV captured");
585
- state.successHandler && state.successHandler({
586
- cardData: state.cardData
587
- });
588
- stopWasm();
599
+ state.debug_mode && console.log("CVV captured, showing card data button");
600
+ showCardDataButton();
601
+ state.cardOverlay.hideFlipMessage();
602
+ state.shouldProcessCC = false; // Stop further processing
603
+ return;
604
+ }
605
+
606
+ // If no CVV after 5 seconds, show button anyway
607
+ if (state.backScanningStartTime &&
608
+ Date.now() - state.backScanningStartTime > 5000 &&
609
+ !state.submitButtonShown) {
610
+ state.debug_mode && console.log("5 seconds elapsed during back scanning, showing card data button");
611
+ showCardDataButton();
612
+ state.cardOverlay.hideFlipMessage();
613
+ state.shouldProcessCC = false;
589
614
  }
590
615
  break;
591
616
  }
@@ -771,7 +796,7 @@ const VeryfiLens = (function () {
771
796
  ];
772
797
 
773
798
  const uuid = sections.join('-').toLowerCase();
774
- console.log("Generated UUID:", uuid);
799
+ state.debug_mode && console.log("Generated UUID:", uuid);
775
800
 
776
801
  return uuid;
777
802
  };
@@ -783,13 +808,13 @@ const VeryfiLens = (function () {
783
808
  return { blurStatus: state.blurStatus, variance: variance };
784
809
  } else if (variance < 0) {
785
810
  state.blurStatus = false;
786
- console.log(
811
+ state.debug_mode && console.log(
787
812
  "Variance is lower than 0, Which means image was not cropped and did not pass through blur detection"
788
813
  );
789
814
  return { blurStatus: state.blurStatus, variance: variance };
790
815
  } else {
791
816
  state.blurStatus = true;
792
- console.log(state.blurStatus, state.variance)
817
+ state.debug_mode && console.log(state.blurStatus, state.variance)
793
818
  return { blurStatus: state.blurStatus, variance: variance };
794
819
  }
795
820
  };
@@ -828,7 +853,7 @@ const VeryfiLens = (function () {
828
853
  };
829
854
 
830
855
  const renderVideoOverlayIfNeeded = () => {
831
- console.log("Rendering video overlay");
856
+ state.debug_mode && console.log("Rendering video overlay");
832
857
  !state.videoOverlay && (state.videoOverlay = createVideoOverlay(state.container));
833
858
 
834
859
  if (state.exitButton) {
@@ -852,7 +877,7 @@ const VeryfiLens = (function () {
852
877
  };
853
878
 
854
879
  const renderCreditCardIfNeeded = () => {
855
- console.log("Rendering credit card overlay");
880
+ state.debug_mode && console.log("Rendering credit card overlay");
856
881
  if (state.videoRef) {
857
882
  createVideo(state.container);
858
883
  state.videoRef = document.getElementById("veryfi-video-ref");
@@ -867,19 +892,19 @@ const VeryfiLens = (function () {
867
892
  }
868
893
 
869
894
  const renderModalsIfNeeded = () => {
870
- console.log("Initializing modals");
895
+ state.debug_mode && console.log("Initializing modals");
871
896
 
872
897
  if (state.isBlurModal) {
873
898
  state.blurModal = createBlurModal(
874
899
  state.container,
875
900
  state.croppedImage,
876
901
  async () => {
877
- console.log("Retaking photo");
902
+ state.debug_mode && console.log("Retaking photo");
878
903
  await newStartLens();
879
904
  showVideoOverlay();
880
905
  },
881
906
  () => {
882
- console.log("Submitting anyway");
907
+ state.debug_mode && console.log("Submitting anyway");
883
908
  hideVideoOverlay();
884
909
  state.submitHandler && state.submitHandler(state.finalImage);
885
910
  }
@@ -891,12 +916,12 @@ const VeryfiLens = (function () {
891
916
  state.container,
892
917
  state.croppedImage,
893
918
  async () => {
894
- console.log("Retaking photo");
919
+ state.debug_mode && console.log("Retaking photo");
895
920
  await newStartLens();
896
921
  showVideoOverlay();
897
922
  },
898
923
  () => {
899
- console.log("Submitting anyway");
924
+ state.debug_mode && console.log("Submitting anyway");
900
925
  hideVideoOverlay();
901
926
  state.submitHandler && state.submitHandler(state.finalImage);
902
927
  }
@@ -923,13 +948,13 @@ const VeryfiLens = (function () {
923
948
  if (!response.ok) {
924
949
  state.updateHandler && state.updateHandler({ status: 'validation_failed' });
925
950
  if (response.status === 401) {
926
- throw new Error('Authorization failed, please provide correct client-id or contact customer support');
951
+ throw new Error('Authorization failed, please provide correct client-id or contact customer support at support@veryfi.com');
927
952
  }
928
953
  throw new Error(`HTTP error! status: ${response.status}`);
929
954
  }
930
955
  if (response.status === 200) {
931
956
  state.updateHandler && state.updateHandler({ status: 'validation_completed' });
932
- console.log('Partner validated')
957
+ state.debug_mode && console.log('Partner validated')
933
958
  return response.json()
934
959
  }
935
960
  } catch (error) {
@@ -985,7 +1010,7 @@ const VeryfiLens = (function () {
985
1010
 
986
1011
  if (!response.ok) {
987
1012
  if (response.status === 401) {
988
- throw new Error('Authorization failed, please contact customer support');
1013
+ throw new Error('Authorization failed, please contact customer support at support@veryfi.com');
989
1014
  }
990
1015
  throw new Error(`HTTP error! status: ${response.status}`);
991
1016
  }
@@ -1039,10 +1064,10 @@ const VeryfiLens = (function () {
1039
1064
  }
1040
1065
  throw new Error(`HTTP error! status: ${response.status}`);
1041
1066
  }
1042
- console.log("Document submitted successfully");
1067
+ state.debug_mode && console.log("Document submitted successfully");
1043
1068
  state.updateHandler && state.updateHandler({ status: 'submission_completed' });
1044
1069
  if (state.successHandler && typeof state.successHandler === 'function') {
1045
- console.log("Success handler called");
1070
+ state.debug_mode && console.log("Success handler called");
1046
1071
  const result = await response.json();
1047
1072
  state.successHandler(result);
1048
1073
  }
@@ -1071,37 +1096,71 @@ const VeryfiLens = (function () {
1071
1096
  stopLens();
1072
1097
  document.body.removeChild(state.container);
1073
1098
  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
1099
  } else {
1087
1100
  stopLens();
1088
- state.hasInit = false;
1089
- state.started = false;
1090
- state.videoOverlay = null;
1091
- state.cardOverlay = null;
1092
- state.blurModal = null;
1093
- state.documentModal = null;
1094
- state.frameRef = null;
1095
- state.cropImgRef = null;
1096
- state.videoRef = null;
1097
- state.boxRef = null;
1101
+ }
1102
+ resetState();
1103
+ };
1104
+
1105
+ const resetState = () => {
1106
+ state.debug_mode && console.log("Resetting state");
1107
+ // Reset all state properties
1108
+ state.hasInit = false;
1109
+ state.started = false;
1110
+ state.isProcessing = false;
1111
+ state.isStitching = false;
1112
+ state.isCapturingFront = false;
1113
+ state.shouldProcessCC = true;
1114
+ state.isDocument = false;
1115
+ state.hasCoordinates = false;
1116
+ state.coordinates = [];
1117
+ state.blurStatus = "";
1118
+ state.variance = null;
1119
+ state.docReadyResult = null;
1120
+ state.fullSizeImage = null;
1121
+ state.finalImage = null;
1122
+ state.frontImage = null;
1123
+ state.backImage = null;
1124
+ state.previewData = null;
1125
+
1126
+ // Reset UI references
1127
+ state.videoOverlay = null;
1128
+ state.cardOverlay = null;
1129
+ state.blurModal = null;
1130
+ state.documentModal = null;
1131
+ state.frameRef = null;
1132
+ state.cropImgRef = null;
1133
+ state.videoRef = null;
1134
+ state.boxRef = null;
1135
+ state.torchButton = null;
1136
+ state.captureButton = null;
1137
+ state.submitButton = null;
1138
+ state.exitButton = null;
1139
+ state.longPreview = null;
1140
+ state.stitchingButton = null;
1141
+ state.checkImagesComponent = null;
1142
+
1143
+ // Reset container if using overlay
1144
+ if (state.usingOverlayContainer) {
1145
+ state.container = null;
1146
+ state.usingOverlayContainer = false;
1147
+ }
1148
+
1149
+ // Reset intervals and tracks
1150
+ state.intervalRef = null;
1151
+ state.torchTrack = null;
1152
+
1153
+ // Reset WASM
1154
+ if (wasmWrapper) {
1098
1155
  wasmWrapper.release();
1099
1156
  wasmWrapper = null;
1100
1157
  }
1158
+
1159
+ state.debug_mode && console.log("State reset complete");
1101
1160
  };
1102
1161
 
1103
1162
  const startStitching = () => {
1104
- console.log("[EVENT] start stitching");
1163
+ state.debug_mode && console.log("[EVENT] start stitching");
1105
1164
  state.isStitching = true;
1106
1165
  state.isStitchingProcess = true;
1107
1166
  state.stitchingButton.setStitching(true);
@@ -1109,7 +1168,7 @@ const VeryfiLens = (function () {
1109
1168
  };
1110
1169
 
1111
1170
  const stopStitching = async () => {
1112
- console.log("[EVENT] stop stitching");
1171
+ state.debug_mode && console.log("[EVENT] stop stitching");
1113
1172
  state.isStitching = false;
1114
1173
  state.isStitchingProcess = false;
1115
1174
  state.stitchingButton.setStitching(false);
@@ -1124,16 +1183,16 @@ const VeryfiLens = (function () {
1124
1183
  if (state.resultSetter && typeof state.resultSetter === 'function') {
1125
1184
  state.resultSetter({ ...state.docReadyResult, image: state.finalImage });
1126
1185
  }
1127
- state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
1186
+ state.estate.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
1128
1187
  handleSubmit(state.finalImage);
1129
1188
  }, removeOverlay);
1130
- state.submitButton.show();
1189
+ state.enableSubmit && state.submitButton.show();
1131
1190
  }
1132
1191
  state.updateHandler && state.updateHandler({ status: 'stitching_completed' });
1133
1192
  };
1134
1193
 
1135
1194
  const captureUploaded = async (imageFile) => {
1136
- console.log("Setting document callback");
1195
+ state.debug_mode && console.log("Setting document callback");
1137
1196
  // wasmWrapper.setDocumentCallback(logDocument);
1138
1197
  return new Promise((resolve, reject) => {
1139
1198
  const reader = new FileReader();
@@ -1165,7 +1224,7 @@ const VeryfiLens = (function () {
1165
1224
  state.resultSetter && state.resultSetter(croppedBase64);
1166
1225
  } else {
1167
1226
  // No document detected, return the original image
1168
- console.log("No document detected, returning original image");
1227
+ state.debug_mode && console.log("No document detected, returning original image");
1169
1228
  const canvas = document.createElement('canvas');
1170
1229
  canvas.width = img.width;
1171
1230
  canvas.height = img.height;
@@ -1191,13 +1250,13 @@ const VeryfiLens = (function () {
1191
1250
 
1192
1251
  const newCapture = async () => {
1193
1252
  try {
1194
- console.log("[EVENT] capture");
1253
+ state.debug_mode && console.log("[EVENT] capture");
1195
1254
  state.updateHandler && state.updateHandler({ status: 'capture_started' });
1196
1255
 
1197
1256
  switch (state.lensFlavor) {
1198
1257
  case "long_document":
1199
1258
  if (!state.isStitching) {
1200
- console.log("Starting stitching");
1259
+ state.debug_mode && console.log("Starting stitching");
1201
1260
  startStitching();
1202
1261
  } else {
1203
1262
  await stopStitching();
@@ -1226,7 +1285,7 @@ const VeryfiLens = (function () {
1226
1285
  state.updateHandler && state.updateHandler({ status: 'processing_started' });
1227
1286
  state.docReadyResult = await docReady();
1228
1287
  state.updateHandler && state.updateHandler({ status: 'processing_completed' });
1229
- console.log("Document processed successfully");
1288
+ state.debug_mode && console.log("Document processed successfully");
1230
1289
  }
1231
1290
 
1232
1291
  if (state.resultSetter && typeof state.resultSetter === 'function') {
@@ -1246,7 +1305,7 @@ const VeryfiLens = (function () {
1246
1305
  state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
1247
1306
  handleSubmit(state.finalImage);
1248
1307
  }, removeOverlay);
1249
- state.submitButton.show();
1308
+ state.enableSubmit && state.submitButton.show();
1250
1309
  }
1251
1310
  }
1252
1311
  } catch (error) {
@@ -1274,7 +1333,7 @@ const VeryfiLens = (function () {
1274
1333
  state.finalImage = state.frontImage;
1275
1334
  stopLens();
1276
1335
 
1277
- console.log("Front capture - Document detected:", state.isDocument);
1336
+ state.debug_mode && console.log("Front capture - Document detected:", state.isDocument);
1278
1337
  const isDocumentDetected = checkIfDocumentOnCapture();
1279
1338
  if (!isDocumentDetected) {
1280
1339
  showVideoOverlay();
@@ -1314,7 +1373,7 @@ const VeryfiLens = (function () {
1314
1373
  state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
1315
1374
  handleSubmit(state.frontImage);
1316
1375
  }, removeOverlay);
1317
- state.submitButton.show();
1376
+ state.enableSubmit && state.submitButton.show();
1318
1377
  }
1319
1378
  // Call success handler with front image only
1320
1379
  if (state.resultSetter && typeof state.resultSetter === 'function') {
@@ -1333,7 +1392,7 @@ const VeryfiLens = (function () {
1333
1392
  state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
1334
1393
  handleSubmit(state.frontImage);
1335
1394
  }, removeOverlay);
1336
- state.submitButton.show();
1395
+ state.enableSubmit && state.submitButton.show();
1337
1396
  }
1338
1397
  // Call success handler with front image only
1339
1398
  if (state.resultSetter && typeof state.resultSetter === 'function') {
@@ -1346,13 +1405,13 @@ const VeryfiLens = (function () {
1346
1405
  } else {
1347
1406
  state.backImage = await cropWasm();
1348
1407
 
1349
- console.log("Back capture - Document detected:", state.isDocument);
1408
+ state.debug_mode && console.log("Back capture - Document detected:", state.isDocument);
1350
1409
  // Check for document first
1351
1410
  const isDocumentDetected = checkIfDocumentOnCapture();
1352
- console.log("Back capture - Document check result:", isDocumentDetected);
1411
+ state.debug_mode && console.log("Back capture - Document check result:", isDocumentDetected);
1353
1412
 
1354
1413
  if (!isDocumentDetected) {
1355
- console.log("Back capture - No document detected, showing video overlay");
1414
+ state.debug_mode && console.log("Back capture - No document detected, showing video overlay");
1356
1415
  showVideoOverlay();
1357
1416
  return;
1358
1417
  }
@@ -1390,7 +1449,7 @@ const VeryfiLens = (function () {
1390
1449
  state.captureBackOfCheck ? handleSubmit(zipContent) : handleSubmit(state.frontImage);
1391
1450
 
1392
1451
  }, removeOverlay);
1393
- state.submitButton.show();
1452
+ state.enableSubmit && state.submitButton.show();
1394
1453
  }
1395
1454
 
1396
1455
  // Call success handler with properly structured data
@@ -1416,7 +1475,7 @@ const VeryfiLens = (function () {
1416
1475
 
1417
1476
  const checkIfDocumentOnCapture = () => {
1418
1477
  if (!state.isDocument) {
1419
- console.log("No document detected");
1478
+ state.debug_mode && console.log("No document detected");
1420
1479
  if (state.isDocumentSetter && typeof state.isDocumentSetter === 'function') {
1421
1480
  state.isDocumentSetter(false);
1422
1481
  }
@@ -1437,7 +1496,7 @@ const VeryfiLens = (function () {
1437
1496
 
1438
1497
  const checkIfBlurOnCapture = () => {
1439
1498
  if (state.blurStatus) {
1440
- console.log("Blur detected");
1499
+ state.debug_mode && console.log("Blur detected");
1441
1500
  if (state.isBlurrySetter && typeof state.isBlurrySetter === 'function') {
1442
1501
  state.isBlurrySetter(true);
1443
1502
  }
@@ -1540,35 +1599,84 @@ const VeryfiLens = (function () {
1540
1599
 
1541
1600
  }
1542
1601
 
1543
- const createCoreElements = () => {
1544
- console.log("Creating core elements");
1545
- if (state.lensFlavor !== "credit_card" && state.lensFlavor !== "upload") {
1546
- if (!state.cropImgRef) {
1547
- state.croppedImage = createCroppedImage(state.container);
1548
- state.cropImgRef = document.getElementById("veryfi-crop-img-ref");
1549
- }
1550
- if (!state.frameRef) {
1551
- createFrame(state.container);
1552
- state.frameRef = document.getElementById("veryfi-frame-ref");
1602
+ const createCoreElements = async () => {
1603
+ state.debug_mode && console.log("Creating core elements");
1604
+
1605
+ try {
1606
+ // Wait a small amount of time to ensure DOM is ready
1607
+ await new Promise(resolve => setTimeout(resolve, 0));
1608
+
1609
+ if (state.lensFlavor !== "credit_card" && state.lensFlavor !== "upload") {
1610
+ // Create cropped image
1611
+ if (!state.cropImgRef) {
1612
+ state.croppedImage = createCroppedImage(state.container);
1613
+ state.cropImgRef = document.getElementById("veryfi-crop-img-ref");
1614
+ if (!state.cropImgRef) {
1615
+ throw new Error('Failed to create cropped image element');
1616
+ }
1617
+ }
1618
+
1619
+ // Create frame
1620
+ if (!state.frameRef) {
1621
+ createFrame(state.container);
1622
+ state.frameRef = document.getElementById("veryfi-frame-ref");
1623
+ if (!state.frameRef) {
1624
+ throw new Error('Failed to create frame element');
1625
+ }
1626
+ }
1627
+
1628
+ // Create box
1629
+ if (!state.boxRef) {
1630
+ createGreenBox(state.container);
1631
+ state.boxRef = document.getElementById("veryfi-box-ref");
1632
+ if (!state.boxRef) {
1633
+ throw new Error('Failed to create box element');
1634
+ }
1635
+ }
1553
1636
  }
1554
- if (!state.boxRef) {
1555
- createGreenBox(state.container);
1556
- state.boxRef = document.getElementById("veryfi-box-ref");
1637
+
1638
+ // Create video element for all flavors except upload
1639
+ if (state.lensFlavor !== "upload") {
1640
+ if (!state.videoRef) {
1641
+ // Ensure container exists before creating video
1642
+ if (!state.container) {
1643
+ throw new Error('Container not found');
1644
+ }
1645
+
1646
+ // Create video element
1647
+ createVideo(state.container);
1648
+
1649
+ // Wait briefly for DOM update
1650
+ await new Promise(resolve => setTimeout(resolve, 10));
1651
+
1652
+ // Get video reference
1653
+ state.videoRef = document.getElementById("veryfi-video-ref");
1654
+
1655
+ if (!state.videoRef) {
1656
+ throw new Error('Failed to create video element');
1657
+ }
1658
+ }
1557
1659
  }
1558
- }
1559
- if (state.lensFlavor !== "upload") {
1560
- if (!state.videoRef) {
1561
- createVideo(state.container);
1562
- state.videoRef = document.getElementById("veryfi-video-ref");
1660
+
1661
+ // Log creation status
1662
+ state.debug_mode && console.log("Core elements created:", {
1663
+ container: !!state.container,
1664
+ cropImgRef: !!state.cropImgRef,
1665
+ frameRef: !!state.frameRef,
1666
+ videoRef: !!state.videoRef,
1667
+ boxRef: !!state.boxRef
1668
+ });
1669
+
1670
+ // Verify critical elements exist based on lens flavor
1671
+ if (state.lensFlavor !== "upload" && !state.videoRef) {
1672
+ throw new Error('Critical elements missing: video element required');
1563
1673
  }
1674
+
1675
+ return true;
1676
+ } catch (error) {
1677
+ console.error("Error creating core elements:", error);
1678
+ throw error;
1564
1679
  }
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
1680
  };
1573
1681
 
1574
1682
  const getDeviceData = async () => {
@@ -1595,22 +1703,35 @@ const VeryfiLens = (function () {
1595
1703
  return wasmWrapper.lcdStatus();
1596
1704
  }
1597
1705
 
1598
- const showSubmitButton = () => {
1706
+ const showCardDataButton = () => {
1599
1707
  if (!state.submitButtonShown) {
1600
- console.log("Showing submit button");
1708
+ state.debug_mode && console.log("Showing submit button");
1601
1709
  state.submitButtonShown = true;
1602
1710
  hideVideoOverlay();
1603
- if (state.submitHandler && typeof state.submitHandler === 'function') {
1604
- console.log(state.submitHandler);
1605
- state.submitButton = createSubmitButton(
1606
- state.cardOverlay.element,
1711
+
1712
+ if (state.lensFlavor === "credit_card") {
1713
+ state.cardDataButton = createCardDataButton(
1714
+ state.container,
1607
1715
  () => {
1608
- state.submitHandler(state.cardData);
1609
- state.successHandler && state.successHandler(state.cardData);
1716
+ // Hide card overlay when button is pressed
1717
+ if (state.cardOverlay) {
1718
+ state.cardOverlay.element.style.display = 'none';
1719
+ }
1720
+
1721
+ // Handle card data
1722
+ if (state.resultSetter) {
1723
+ state.resultSetter(state.cardData);
1724
+ }
1725
+ if (state.successHandler) {
1726
+ state.successHandler(state.cardData);
1727
+ }
1610
1728
  },
1611
1729
  removeOverlay
1612
1730
  );
1613
- state.submitButton.show();
1731
+
1732
+ if (state.cardDataButton) {
1733
+ state.cardDataButton.show();
1734
+ }
1614
1735
  }
1615
1736
  }
1616
1737
  };
@@ -1620,7 +1741,7 @@ const VeryfiLens = (function () {
1620
1741
  const fp = await FingerprintJS.load();
1621
1742
  const result = await fp.get();
1622
1743
  state.visitorId = result.visitorId;
1623
- console.log("Basic fingerprint obtained:", state.visitorId);
1744
+ state.debug_mode && console.log("Basic fingerprint obtained:", state.visitorId);
1624
1745
  } catch (error) {
1625
1746
  console.error('Failed to load FingerprintJS:', error);
1626
1747
  throw error;
@@ -1634,7 +1755,7 @@ const VeryfiLens = (function () {
1634
1755
  });
1635
1756
  const result = await fp.get();
1636
1757
  state.visitorId = result.visitorId;
1637
- console.log("Pro fingerprint obtained:", state.visitorId);
1758
+ state.debug_mode && console.log("Pro fingerprint obtained:", state.visitorId);
1638
1759
  } catch (error) {
1639
1760
  console.error('Failed to load FingerprintJS Pro:', error);
1640
1761
  throw error;
@@ -1647,13 +1768,16 @@ const VeryfiLens = (function () {
1647
1768
  try {
1648
1769
  if (state.hasInit) return;
1649
1770
  state.hasInit = true;
1650
- console.log("init", config);
1771
+ config.debug_mode && (state.debug_mode = true);
1772
+ config.debug_mode && console.log("init", config);
1651
1773
  state.clientId = clientId
1652
1774
  state.clientData = await validatePartner(state.clientId);
1653
- console.log(state.clientData);
1775
+ config.debug_mode && console.log(state.clientData);
1654
1776
 
1655
1777
  if (typeof window !== 'undefined') {
1778
+
1656
1779
  try {
1780
+ state.debug_mode && console.log("Getting fingerprint");
1657
1781
  if (state.clientData.fingerprint_js_on) {
1658
1782
  await getFingerprintPro();
1659
1783
  } else {
@@ -1673,7 +1797,6 @@ const VeryfiLens = (function () {
1673
1797
  case "credit_card":
1674
1798
  }
1675
1799
 
1676
- // console.log(config);
1677
1800
  Object.keys(config).forEach(key => {
1678
1801
  if (state.hasOwnProperty(key)) {
1679
1802
  state[key] = config[key];
@@ -1681,12 +1804,14 @@ const VeryfiLens = (function () {
1681
1804
  });
1682
1805
 
1683
1806
  if (config.container) {
1807
+ state.debug_mode && console.log("Container found", config.container);
1684
1808
  state.container = document.getElementById(config.container);
1685
1809
  } else {
1686
1810
  state.usingOverlayContainer = true;
1687
1811
  state.container = createOverlayContainer();
1688
1812
  }
1689
- console.log(state.onSuccess);
1813
+
1814
+ state.debug_mode && console.log(state);
1690
1815
 
1691
1816
  } catch (error) {
1692
1817
  console.error("Error initializing Lens:", error);
@@ -1699,22 +1824,29 @@ const VeryfiLens = (function () {
1699
1824
 
1700
1825
  showCamera: async (setter) => {
1701
1826
  try {
1702
- console.log("Starting camera initialization");
1827
+ state.debug_mode && console.log("Starting camera initialization");
1703
1828
  setter && (state.resultSetter = setter);
1704
1829
 
1705
1830
  // Ensure container exists
1706
1831
  if (!state.container) {
1707
- console.log("Creating overlay container");
1832
+ state.debug_mode && console.log("Creating overlay container");
1708
1833
  state.container = createOverlayContainer();
1834
+ if (!state.container) {
1835
+ throw new Error('Failed to create container');
1836
+ }
1709
1837
  }
1710
1838
 
1711
- // Create core elements first
1712
- console.log("Creating core elements");
1713
- createCoreElements();
1839
+ // Create core elements and verify success
1840
+ const elementsCreated = await createCoreElements();
1841
+
1842
+ if (!elementsCreated) {
1843
+ throw new Error('Failed to create core elements');
1844
+ }
1714
1845
 
1715
1846
  // Initialize WASM if needed
1716
1847
  await initializeWasmWrapper();
1717
1848
 
1849
+ // Render appropriate UI elements based on lens flavor
1718
1850
  switch (state.lensFlavor) {
1719
1851
  case 'upload':
1720
1852
  !state.fileUpload && (state.fileUpload = createFileUpload(state.container, captureUploaded, handleSubmit));
@@ -1723,7 +1855,7 @@ const VeryfiLens = (function () {
1723
1855
  renderCreditCardIfNeeded();
1724
1856
  break;
1725
1857
  default:
1726
- console.log('Rendering UI elements');
1858
+ state.debug_mode && console.log('Rendering UI elements');
1727
1859
  renderModalsIfNeeded();
1728
1860
  renderVideoOverlayIfNeeded();
1729
1861
  break;
@@ -1731,16 +1863,17 @@ const VeryfiLens = (function () {
1731
1863
 
1732
1864
  // Start lens if not already started
1733
1865
  if (!state.started) {
1734
- console.log("Starting lens");
1866
+ state.debug_mode && console.log("Starting lens");
1735
1867
  await newStartLens();
1736
1868
  }
1737
1869
 
1738
- console.log("Camera initialization complete");
1870
+ state.debug_mode && console.log("Camera initialization complete");
1739
1871
  } catch (error) {
1740
1872
  console.error("Error in showCamera:", error);
1741
1873
  if (state.failureHandler && typeof state.failureHandler === 'function') {
1742
1874
  state.failureHandler(error);
1743
1875
  }
1876
+ throw error;
1744
1877
  }
1745
1878
  },
1746
1879
 
@@ -1784,8 +1917,17 @@ const VeryfiLens = (function () {
1784
1917
  },
1785
1918
 
1786
1919
  stop: () => {
1787
- stopLens();
1788
- removeOverlay();
1920
+ try {
1921
+ state.debug_mode && console.log("Stopping VeryfiLens");
1922
+ stopLens();
1923
+ removeOverlay();
1924
+ state.debug_mode && console.log("VeryfiLens stopped successfully");
1925
+ } catch (error) {
1926
+ console.error("Error stopping VeryfiLens:", error);
1927
+ if (state.failureHandler) {
1928
+ state.failureHandler(error);
1929
+ }
1930
+ }
1789
1931
  }
1790
1932
  };
1791
1933
  })();