veryfi-lens-wasm 2.0.0-beta.1 → 2.0.0-beta.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/createFileUpload.js +8 -3
- package/components/spinner.js +56 -0
- package/components/submitButton.js +1 -1
- package/package.json +1 -1
- package/veryfi-lens.js +31 -27
|
@@ -29,12 +29,13 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
|
|
|
29
29
|
uploadZoneColor: 'black',
|
|
30
30
|
uploadZoneFontFamily: 'sans-serif',
|
|
31
31
|
buttonPadding: '10px 20px',
|
|
32
|
-
buttonBackgroundColor: '
|
|
33
|
-
buttonColor: '
|
|
32
|
+
buttonBackgroundColor: '#4CAF50',
|
|
33
|
+
buttonColor: 'white',
|
|
34
34
|
buttonBorderRadius: '5px',
|
|
35
35
|
buttonFontFamily: 'sans-serif',
|
|
36
36
|
buttonFontSize: '16px',
|
|
37
|
-
buttonGap: '
|
|
37
|
+
buttonGap: '20px',
|
|
38
|
+
buttonWidth: '100px'
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
// Apply styles with fallback to default values
|
|
@@ -89,6 +90,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
|
|
|
89
90
|
<div id="button-container" style="
|
|
90
91
|
display: none;
|
|
91
92
|
justify-content: center;
|
|
93
|
+
margin-top: 10px;
|
|
92
94
|
gap: var(--file-upload-button-gap, ${defaultStyles.buttonGap});
|
|
93
95
|
">
|
|
94
96
|
<button id="crop-button" style="
|
|
@@ -100,6 +102,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
|
|
|
100
102
|
cursor: pointer;
|
|
101
103
|
font-family: var(--file-upload-button-font-family, ${defaultStyles.buttonFontFamily});
|
|
102
104
|
font-size: var(--file-upload-button-font-size, ${defaultStyles.buttonFontSize});
|
|
105
|
+
width: var(--file-upload-button-width, ${defaultStyles.buttonWidth});
|
|
103
106
|
">Crop</button>
|
|
104
107
|
<button id="reset-button" style="
|
|
105
108
|
padding: var(--file-upload-button-padding, ${defaultStyles.buttonPadding});
|
|
@@ -110,6 +113,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
|
|
|
110
113
|
cursor: pointer;
|
|
111
114
|
font-family: var(--file-upload-button-font-family, ${defaultStyles.buttonFontFamily});
|
|
112
115
|
font-size: var(--file-upload-button-font-size, ${defaultStyles.buttonFontSize});
|
|
116
|
+
width: var(--file-upload-button-width, ${defaultStyles.buttonWidth});
|
|
113
117
|
">Reset</button>
|
|
114
118
|
<button id="submit-button" style="
|
|
115
119
|
padding: var(--file-upload-button-padding, ${defaultStyles.buttonPadding});
|
|
@@ -121,6 +125,7 @@ export function createFileUpload(container, captureUploaded, onSubmit) {
|
|
|
121
125
|
font-family: var(--file-upload-button-font-family, ${defaultStyles.buttonFontFamily});
|
|
122
126
|
font-size: var(--file-upload-button-font-size, ${defaultStyles.buttonFontSize});
|
|
123
127
|
display: none;
|
|
128
|
+
width: var(--file-upload-button-width, ${defaultStyles.buttonWidth});
|
|
124
129
|
">Submit</button>
|
|
125
130
|
</div>
|
|
126
131
|
</div>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const createSpinner = (container, message) => {
|
|
2
|
+
const spinnerOverlay = document.createElement('div');
|
|
3
|
+
spinnerOverlay.style.position = 'fixed';
|
|
4
|
+
spinnerOverlay.style.top = '0';
|
|
5
|
+
spinnerOverlay.style.left = '0';
|
|
6
|
+
spinnerOverlay.style.width = '100%';
|
|
7
|
+
spinnerOverlay.style.height = '100%';
|
|
8
|
+
spinnerOverlay.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
|
|
9
|
+
spinnerOverlay.style.display = 'flex';
|
|
10
|
+
spinnerOverlay.style.flexDirection = 'column';
|
|
11
|
+
spinnerOverlay.style.justifyContent = 'center';
|
|
12
|
+
spinnerOverlay.style.alignItems = 'center';
|
|
13
|
+
spinnerOverlay.style.zIndex = '9999';
|
|
14
|
+
|
|
15
|
+
const spinner = document.createElement('div');
|
|
16
|
+
spinner.style.border = '4px solid #f3f3f3';
|
|
17
|
+
spinner.style.borderTop = '4px solid #4CAF50';
|
|
18
|
+
spinner.style.borderRadius = '50%';
|
|
19
|
+
spinner.style.width = '40px';
|
|
20
|
+
spinner.style.height = '40px';
|
|
21
|
+
spinner.style.animation = 'spin 1s linear infinite';
|
|
22
|
+
|
|
23
|
+
const style = document.createElement('style');
|
|
24
|
+
style.textContent = `
|
|
25
|
+
@keyframes spin {
|
|
26
|
+
0% { transform: rotate(0deg); }
|
|
27
|
+
100% { transform: rotate(360deg); }
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
document.head.appendChild(style);
|
|
31
|
+
|
|
32
|
+
const messageElement = document.createElement('div');
|
|
33
|
+
messageElement.style.color = '#4CAF50';
|
|
34
|
+
messageElement.style.marginTop = '20px';
|
|
35
|
+
messageElement.style.fontSize = '16px';
|
|
36
|
+
messageElement.textContent = message;
|
|
37
|
+
|
|
38
|
+
spinnerOverlay.appendChild(spinner);
|
|
39
|
+
spinnerOverlay.appendChild(messageElement);
|
|
40
|
+
container.appendChild(spinnerOverlay);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
show: () => {
|
|
44
|
+
spinnerOverlay.style.display = 'flex';
|
|
45
|
+
},
|
|
46
|
+
hide: () => {
|
|
47
|
+
spinnerOverlay.style.display = 'none';
|
|
48
|
+
},
|
|
49
|
+
remove: () => {
|
|
50
|
+
container.removeChild(spinnerOverlay);
|
|
51
|
+
},
|
|
52
|
+
updateMessage: (newMessage) => {
|
|
53
|
+
messageElement.textContent = newMessage;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
package/package.json
CHANGED
package/veryfi-lens.js
CHANGED
|
@@ -22,6 +22,7 @@ import { createCheckCaptureModal } from './components/checkCaptureModal.js';
|
|
|
22
22
|
import { createCreditCardComponent } from './components/creditCard.js';
|
|
23
23
|
import { createStitchingButton } from './components/stitchingButton.js';
|
|
24
24
|
import { createCheckImages } from './components/checkImages.js';
|
|
25
|
+
import { createSpinner } from './components/spinner.js';
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
|
|
@@ -202,7 +203,9 @@ const VeryfiLens = (function () {
|
|
|
202
203
|
};
|
|
203
204
|
|
|
204
205
|
try {
|
|
206
|
+
state.updateHandler && state.updateHandler({ status: 'camera_initializing' });
|
|
205
207
|
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
208
|
+
state.updateHandler && state.updateHandler({ status: 'camera_ready' });
|
|
206
209
|
state.videoRef.srcObject = stream;
|
|
207
210
|
state.videoRef.autoplay = true;
|
|
208
211
|
|
|
@@ -230,6 +233,7 @@ const VeryfiLens = (function () {
|
|
|
230
233
|
wasmWrapper.setDocumentCallback(logDocument);
|
|
231
234
|
}
|
|
232
235
|
} catch (err) {
|
|
236
|
+
state.updateHandler && state.updateHandler({ status: 'camera_failed', error: err.message });
|
|
233
237
|
console.error("Error accessing camera:", err);
|
|
234
238
|
if (state.failureHandler) {
|
|
235
239
|
state.failureHandler(err);
|
|
@@ -902,6 +906,7 @@ const VeryfiLens = (function () {
|
|
|
902
906
|
|
|
903
907
|
const validatePartner = async (client_id) => {
|
|
904
908
|
try {
|
|
909
|
+
state.updateHandler && state.updateHandler({ status: 'validation_started' });
|
|
905
910
|
const response = await fetch(
|
|
906
911
|
// 'https://lens.veryfi.com/rest/validate_partner',
|
|
907
912
|
'https://lens-dev.veryfi.com/rest/validate_partner',
|
|
@@ -916,12 +921,14 @@ const VeryfiLens = (function () {
|
|
|
916
921
|
});
|
|
917
922
|
|
|
918
923
|
if (!response.ok) {
|
|
924
|
+
state.updateHandler && state.updateHandler({ status: 'validation_failed' });
|
|
919
925
|
if (response.status === 401) {
|
|
920
926
|
throw new Error('Authorization failed, please provide correct client-id or contact customer support');
|
|
921
927
|
}
|
|
922
928
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
923
929
|
}
|
|
924
930
|
if (response.status === 200) {
|
|
931
|
+
state.updateHandler && state.updateHandler({ status: 'validation_completed' });
|
|
925
932
|
console.log('Partner validated')
|
|
926
933
|
return response.json()
|
|
927
934
|
}
|
|
@@ -949,14 +956,15 @@ const VeryfiLens = (function () {
|
|
|
949
956
|
}
|
|
950
957
|
|
|
951
958
|
const docReady = async () => {
|
|
959
|
+
const spinner = createSpinner(document.body, 'Preparing document...');
|
|
960
|
+
spinner.show();
|
|
961
|
+
|
|
952
962
|
try {
|
|
953
|
-
// Replace these with actual values
|
|
954
963
|
const base64Image = state.finalImage;
|
|
955
964
|
const browserData = await getBrowserData();
|
|
956
965
|
const UAData = flattenObject(parseUA());
|
|
957
966
|
const jsonData = { ...browserData, ...UAData, ...getMetaData() };
|
|
958
967
|
|
|
959
|
-
// Prepare the payload
|
|
960
968
|
const payload = {
|
|
961
969
|
image: base64Image,
|
|
962
970
|
json_data: jsonData,
|
|
@@ -981,24 +989,27 @@ const VeryfiLens = (function () {
|
|
|
981
989
|
}
|
|
982
990
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
983
991
|
}
|
|
984
|
-
|
|
992
|
+
const result = await response.json();
|
|
993
|
+
spinner.remove();
|
|
994
|
+
return result;
|
|
985
995
|
} catch (error) {
|
|
996
|
+
spinner.remove();
|
|
986
997
|
console.error("Error processing document:", error);
|
|
987
998
|
if (state.failureHandler && typeof state.failureHandler === 'function') {
|
|
988
999
|
state.failureHandler(error);
|
|
989
1000
|
}
|
|
990
1001
|
throw error;
|
|
991
1002
|
}
|
|
992
|
-
}
|
|
1003
|
+
};
|
|
993
1004
|
|
|
994
1005
|
const handleSubmit = async (image) => {
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1006
|
+
const spinner = createSpinner(document.body, 'Submitting document...');
|
|
1007
|
+
spinner.show();
|
|
1008
|
+
state.updateHandler && state.updateHandler({ status: 'submission_started' });
|
|
998
1009
|
|
|
1010
|
+
const processDocumentUrl = "https://lens-dev.veryfi.com/api/document";
|
|
999
1011
|
const deviceData = await getDeviceData();
|
|
1000
1012
|
|
|
1001
|
-
// Create the request body as a proper object
|
|
1002
1013
|
const requestBody = {
|
|
1003
1014
|
image: image,
|
|
1004
1015
|
doc_type: state.lensFlavor === 'checks' ? 'checks' : 'documents',
|
|
@@ -1022,18 +1033,22 @@ const VeryfiLens = (function () {
|
|
|
1022
1033
|
if (!response.ok) {
|
|
1023
1034
|
const errorData = await response.json();
|
|
1024
1035
|
console.error('Submit error:', errorData);
|
|
1036
|
+
state.updateHandler && state.updateHandler({ status: 'submission_failed', error: errorData });
|
|
1025
1037
|
if (state.failureHandler && typeof state.failureHandler === 'function') {
|
|
1026
1038
|
state.failureHandler(errorData);
|
|
1027
1039
|
}
|
|
1028
1040
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
1029
1041
|
}
|
|
1030
1042
|
console.log("Document submitted successfully");
|
|
1043
|
+
state.updateHandler && state.updateHandler({ status: 'submission_completed' });
|
|
1031
1044
|
if (state.successHandler && typeof state.successHandler === 'function') {
|
|
1032
1045
|
console.log("Success handler called");
|
|
1033
1046
|
const result = await response.json();
|
|
1034
1047
|
state.successHandler(result);
|
|
1035
1048
|
}
|
|
1049
|
+
spinner.remove();
|
|
1036
1050
|
} catch (error) {
|
|
1051
|
+
spinner.remove();
|
|
1037
1052
|
console.error('Error submitting document:', error);
|
|
1038
1053
|
if (state.failureHandler && typeof state.failureHandler === 'function') {
|
|
1039
1054
|
state.failureHandler(error);
|
|
@@ -1177,6 +1192,8 @@ const VeryfiLens = (function () {
|
|
|
1177
1192
|
const newCapture = async () => {
|
|
1178
1193
|
try {
|
|
1179
1194
|
console.log("[EVENT] capture");
|
|
1195
|
+
state.updateHandler && state.updateHandler({ status: 'capture_started' });
|
|
1196
|
+
|
|
1180
1197
|
switch (state.lensFlavor) {
|
|
1181
1198
|
case "long_document":
|
|
1182
1199
|
if (!state.isStitching) {
|
|
@@ -1195,6 +1212,7 @@ const VeryfiLens = (function () {
|
|
|
1195
1212
|
|
|
1196
1213
|
if (state.lensFlavor !== 'checks' && state.resultSetter && typeof state.resultSetter === 'function') {
|
|
1197
1214
|
state.resultSetter(state.finalImage);
|
|
1215
|
+
state.updateHandler && state.updateHandler({ status: 'capture_completed' });
|
|
1198
1216
|
} else if (state.lensFlavor === 'checks' && state.resultSetter && typeof state.resultSetter === 'function') {
|
|
1199
1217
|
state.resultSetter = [state.frontImage, state.backImage];
|
|
1200
1218
|
}
|
|
@@ -1205,13 +1223,14 @@ const VeryfiLens = (function () {
|
|
|
1205
1223
|
|
|
1206
1224
|
// Process the document
|
|
1207
1225
|
if (state.lensFlavor !== 'checks') {
|
|
1208
|
-
|
|
1209
|
-
|
|
1226
|
+
state.updateHandler && state.updateHandler({ status: 'processing_started' });
|
|
1227
|
+
state.docReadyResult = await docReady();
|
|
1228
|
+
state.updateHandler && state.updateHandler({ status: 'processing_completed' });
|
|
1229
|
+
console.log("Document processed successfully");
|
|
1210
1230
|
}
|
|
1211
1231
|
|
|
1212
1232
|
if (state.resultSetter && typeof state.resultSetter === 'function') {
|
|
1213
1233
|
state.resultSetter({ ...state.docReadyResult, image: state.finalImage });
|
|
1214
|
-
// state.resultSetter({ image: state.finalImage });
|
|
1215
1234
|
}
|
|
1216
1235
|
|
|
1217
1236
|
const isBlurry = checkIfBlurOnCapture();
|
|
@@ -1225,7 +1244,6 @@ const VeryfiLens = (function () {
|
|
|
1225
1244
|
hideVideoOverlay();
|
|
1226
1245
|
if (state.isDocument && !state.blurStatus) {
|
|
1227
1246
|
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
1228
|
-
// state.submitHandler && state.submitHandler(state.finalImage);
|
|
1229
1247
|
handleSubmit(state.finalImage);
|
|
1230
1248
|
}, removeOverlay);
|
|
1231
1249
|
state.submitButton.show();
|
|
@@ -1634,20 +1652,6 @@ const VeryfiLens = (function () {
|
|
|
1634
1652
|
state.clientData = await validatePartner(state.clientId);
|
|
1635
1653
|
console.log(state.clientData);
|
|
1636
1654
|
|
|
1637
|
-
// if (!state.fpPromise) {
|
|
1638
|
-
// try {
|
|
1639
|
-
// state.fpPromise = FingerprintJS.load()
|
|
1640
|
-
// .then(async fp => {
|
|
1641
|
-
// const result = await fp.get();
|
|
1642
|
-
// state.visitorId = result.visitorId;
|
|
1643
|
-
// return fp;
|
|
1644
|
-
// });
|
|
1645
|
-
// } catch (error) {
|
|
1646
|
-
// console.error('Failed to load FingerprintJS:', error);
|
|
1647
|
-
// }
|
|
1648
|
-
// }
|
|
1649
|
-
|
|
1650
|
-
// Wait for fingerprint initialization
|
|
1651
1655
|
if (typeof window !== 'undefined') {
|
|
1652
1656
|
try {
|
|
1653
1657
|
if (state.clientData.fingerprint_js_on) {
|
|
@@ -1669,7 +1673,7 @@ const VeryfiLens = (function () {
|
|
|
1669
1673
|
case "credit_card":
|
|
1670
1674
|
}
|
|
1671
1675
|
|
|
1672
|
-
console.log(config);
|
|
1676
|
+
// console.log(config);
|
|
1673
1677
|
Object.keys(config).forEach(key => {
|
|
1674
1678
|
if (state.hasOwnProperty(key)) {
|
|
1675
1679
|
state[key] = config[key];
|