veryfi-lens-wasm 2.0.4 → 2.0.5-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/blurModal.js +10 -4
- package/components/documentModal.js +13 -4
- package/package.json +1 -1
- package/utils/parser-wrapper.js +118 -1
- package/veryfi-lens.js +30 -5
package/components/blurModal.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const createBlurModal = (container, croppedImage, onRetake, onSubmit) => {
|
|
1
|
+
export const createBlurModal = (container, croppedImage, onRetake, onSubmit, options = {}) => {
|
|
2
2
|
const modal = document.createElement('div');
|
|
3
3
|
modal.id = 'veryfi-blur-modal';
|
|
4
4
|
modal.style.display = 'none';
|
|
@@ -31,6 +31,12 @@ export const createBlurModal = (container, croppedImage, onRetake, onSubmit) =>
|
|
|
31
31
|
secondaryButtonColor: '#1e293b'
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
const defaultOptions = {
|
|
35
|
+
blurModalMessage: 'Oops, The image is too blurry to process'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Merge provided options with defaults
|
|
39
|
+
const modalOptions = { ...defaultOptions, ...options };
|
|
34
40
|
// Apply styles with fallback to default values
|
|
35
41
|
Object.entries(defaultStyles).forEach(([key, value]) => {
|
|
36
42
|
const cssVar = `--blur-modal-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`;
|
|
@@ -50,7 +56,7 @@ export const createBlurModal = (container, croppedImage, onRetake, onSubmit) =>
|
|
|
50
56
|
font-size: var(--blur-modal-text-font-size, ${defaultStyles.textFontSize});
|
|
51
57
|
font-family: var(--blur-modal-text-font-family, ${defaultStyles.textFontFamily});
|
|
52
58
|
">
|
|
53
|
-
|
|
59
|
+
${modalOptions.blurModalMessage.replace(/</g, '<').replace(/>/g, '>')}
|
|
54
60
|
</p>
|
|
55
61
|
<div style="display: flex; flex-direction: column; align-items: center; gap: 8px;">
|
|
56
62
|
<button id="veryfi-retake-blur" style="
|
|
@@ -69,7 +75,7 @@ export const createBlurModal = (container, croppedImage, onRetake, onSubmit) =>
|
|
|
69
75
|
font-family: var(--blur-modal-button-font-family, ${defaultStyles.buttonFontFamily});
|
|
70
76
|
text-transform: var(--blur-modal-button-text-transform, ${defaultStyles.buttonTextTransform});
|
|
71
77
|
">
|
|
72
|
-
|
|
78
|
+
${modalOptions.retakeButtonText.replace(/</g, '<').replace(/>/g, '>')}
|
|
73
79
|
</p>
|
|
74
80
|
</button>
|
|
75
81
|
<button id="veryfi-submit-blur" style="
|
|
@@ -88,7 +94,7 @@ export const createBlurModal = (container, croppedImage, onRetake, onSubmit) =>
|
|
|
88
94
|
font-family: var(--blur-modal-button-font-family, ${defaultStyles.buttonFontFamily});
|
|
89
95
|
text-transform: var(--blur-modal-button-text-transform, ${defaultStyles.buttonTextTransform});
|
|
90
96
|
">
|
|
91
|
-
|
|
97
|
+
${modalOptions.submitButtonText.replace(/</g, '<').replace(/>/g, '>')}
|
|
92
98
|
</p>
|
|
93
99
|
</button>
|
|
94
100
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const createDocumentModal = (container, croppedImage, onRetake, onSubmit) => {
|
|
1
|
+
export const createDocumentModal = (container, croppedImage, onRetake, onSubmit, options = {}) => {
|
|
2
2
|
const modal = document.createElement('div');
|
|
3
3
|
modal.id = 'veryfi-document-modal';
|
|
4
4
|
modal.style.display = 'none';
|
|
@@ -32,6 +32,15 @@ export const createDocumentModal = (container, croppedImage, onRetake, onSubmit)
|
|
|
32
32
|
secondaryButtonColor: '#1e293b'
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
const defaultOptions = {
|
|
36
|
+
noDocumentMessage: 'Oops, There appears to be no document on your image',
|
|
37
|
+
retakeButtonText: 'Retake a picture',
|
|
38
|
+
submitButtonText: 'Submit Anyway'
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Merge provided options with defaults
|
|
42
|
+
const modalOptions = { ...defaultOptions, ...options };
|
|
43
|
+
|
|
35
44
|
// Apply styles with fallback to default values
|
|
36
45
|
Object.entries(defaultStyles).forEach(([key, value]) => {
|
|
37
46
|
const cssVar = `--modal-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`;
|
|
@@ -52,7 +61,7 @@ export const createDocumentModal = (container, croppedImage, onRetake, onSubmit)
|
|
|
52
61
|
font-size: var(--modal-text-font-size, ${defaultStyles.textFontSize});
|
|
53
62
|
font-family: var(--modal-text-font-family, ${defaultStyles.textFontFamily});
|
|
54
63
|
">
|
|
55
|
-
|
|
64
|
+
${modalOptions.noDocumentMessage.replace(/</g, '<').replace(/>/g, '>')}
|
|
56
65
|
</p>
|
|
57
66
|
<div style="display: flex; flex-direction: column; align-items: center; gap: 8px;">
|
|
58
67
|
<button id="veryfi-retake-document" style="
|
|
@@ -71,7 +80,7 @@ export const createDocumentModal = (container, croppedImage, onRetake, onSubmit)
|
|
|
71
80
|
font-family: var(--modal-button-font-family, ${defaultStyles.buttonFontFamily});
|
|
72
81
|
text-transform: var(--modal-button-text-transform, ${defaultStyles.buttonTextTransform});
|
|
73
82
|
">
|
|
74
|
-
|
|
83
|
+
${modalOptions.retakeButtonText.replace(/</g, '<').replace(/>/g, '>')}
|
|
75
84
|
</p>
|
|
76
85
|
</button>
|
|
77
86
|
<button id="veryfi-submit-document" style="
|
|
@@ -90,7 +99,7 @@ export const createDocumentModal = (container, croppedImage, onRetake, onSubmit)
|
|
|
90
99
|
font-family: var(--modal-button-font-family, ${defaultStyles.buttonFontFamily});
|
|
91
100
|
text-transform: var(--modal-button-text-transform, ${defaultStyles.buttonTextTransform});
|
|
92
101
|
">
|
|
93
|
-
|
|
102
|
+
${modalOptions.submitButtonText.replace(/</g, '<').replace(/>/g, '>')}
|
|
94
103
|
</p>
|
|
95
104
|
</button>
|
|
96
105
|
</div>
|
package/package.json
CHANGED
package/utils/parser-wrapper.js
CHANGED
|
@@ -1,2 +1,119 @@
|
|
|
1
1
|
import './ua-parser.js';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
// Create a wrapper that ensures we always have something to export
|
|
4
|
+
const UAParserWrapper = function(ua, extensions) {
|
|
5
|
+
// First try to use the global UAParser
|
|
6
|
+
if (typeof window !== 'undefined' && typeof window.UAParser === 'function') {
|
|
7
|
+
try {
|
|
8
|
+
return new window.UAParser(ua, extensions);
|
|
9
|
+
} catch (e) {
|
|
10
|
+
console.warn('Error initializing UAParser:', e);
|
|
11
|
+
// Fall through to fallback
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// If we can't use the global UAParser, create a basic parser that extracts some info
|
|
16
|
+
// This is a simplified version that handles common patterns
|
|
17
|
+
const userAgent = ua || (typeof navigator !== 'undefined' ? navigator.userAgent : '');
|
|
18
|
+
|
|
19
|
+
// Extract basic browser info
|
|
20
|
+
let browserName = 'unknown';
|
|
21
|
+
let browserVersion = 'unknown';
|
|
22
|
+
let osName = 'unknown';
|
|
23
|
+
let osVersion = 'unknown';
|
|
24
|
+
let deviceType = 'desktop';
|
|
25
|
+
let deviceVendor = 'unknown';
|
|
26
|
+
let deviceModel = 'unknown';
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
// Basic browser detection
|
|
30
|
+
if (userAgent.indexOf('Chrome') > -1) {
|
|
31
|
+
browserName = 'Chrome';
|
|
32
|
+
const match = userAgent.match(/Chrome\/([\d\.]+)/);
|
|
33
|
+
if (match) browserVersion = match[1];
|
|
34
|
+
} else if (userAgent.indexOf('Firefox') > -1) {
|
|
35
|
+
browserName = 'Firefox';
|
|
36
|
+
const match = userAgent.match(/Firefox\/([\d\.]+)/);
|
|
37
|
+
if (match) browserVersion = match[1];
|
|
38
|
+
} else if (userAgent.indexOf('Safari') > -1) {
|
|
39
|
+
browserName = 'Safari';
|
|
40
|
+
const match = userAgent.match(/Version\/([\d\.]+)/);
|
|
41
|
+
if (match) browserVersion = match[1];
|
|
42
|
+
} else if (userAgent.indexOf('Edge') > -1 || userAgent.indexOf('Edg/') > -1) {
|
|
43
|
+
browserName = 'Edge';
|
|
44
|
+
const match = userAgent.match(/Edge?\/([\d\.]+)/);
|
|
45
|
+
if (match) browserVersion = match[1];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Basic OS detection
|
|
49
|
+
if (userAgent.indexOf('Windows') > -1) {
|
|
50
|
+
osName = 'Windows';
|
|
51
|
+
if (userAgent.indexOf('Windows NT 10.0') > -1) osVersion = '10';
|
|
52
|
+
else if (userAgent.indexOf('Windows NT 6.3') > -1) osVersion = '8.1';
|
|
53
|
+
else if (userAgent.indexOf('Windows NT 6.2') > -1) osVersion = '8';
|
|
54
|
+
else if (userAgent.indexOf('Windows NT 6.1') > -1) osVersion = '7';
|
|
55
|
+
} else if (userAgent.indexOf('Mac OS X') > -1) {
|
|
56
|
+
osName = 'Mac OS';
|
|
57
|
+
const match = userAgent.match(/Mac OS X (\d+[._]\d+[._\d]*)/);
|
|
58
|
+
if (match) osVersion = match[1].replace(/_/g, '.');
|
|
59
|
+
} else if (userAgent.indexOf('Android') > -1) {
|
|
60
|
+
osName = 'Android';
|
|
61
|
+
deviceType = 'mobile';
|
|
62
|
+
const match = userAgent.match(/Android (\d+\.\d+)/);
|
|
63
|
+
if (match) osVersion = match[1];
|
|
64
|
+
} else if (userAgent.indexOf('iOS') > -1 || userAgent.indexOf('iPhone') > -1 || userAgent.indexOf('iPad') > -1) {
|
|
65
|
+
osName = 'iOS';
|
|
66
|
+
deviceType = userAgent.indexOf('iPad') > -1 ? 'tablet' : 'mobile';
|
|
67
|
+
deviceVendor = 'Apple';
|
|
68
|
+
deviceModel = userAgent.indexOf('iPad') > -1 ? 'iPad' : 'iPhone';
|
|
69
|
+
const match = userAgent.match(/OS (\d+_\d+)/);
|
|
70
|
+
if (match) osVersion = match[1].replace(/_/g, '.');
|
|
71
|
+
} else if (userAgent.indexOf('Linux') > -1) {
|
|
72
|
+
osName = 'Linux';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Mobile detection
|
|
76
|
+
if (userAgent.indexOf('Mobile') > -1) {
|
|
77
|
+
deviceType = 'mobile';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Device vendor detection
|
|
81
|
+
if (userAgent.indexOf('iPhone') > -1 || userAgent.indexOf('iPad') > -1 || userAgent.indexOf('iPod') > -1) {
|
|
82
|
+
deviceVendor = 'Apple';
|
|
83
|
+
} else if (userAgent.indexOf('Samsung') > -1) {
|
|
84
|
+
deviceVendor = 'Samsung';
|
|
85
|
+
} else if (userAgent.indexOf('Pixel') > -1) {
|
|
86
|
+
deviceVendor = 'Google';
|
|
87
|
+
} else if (userAgent.indexOf('Huawei') > -1) {
|
|
88
|
+
deviceVendor = 'Huawei';
|
|
89
|
+
}
|
|
90
|
+
} catch (e) {
|
|
91
|
+
console.warn('Error in fallback UA parsing:', e);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Fallback implementation
|
|
95
|
+
return {
|
|
96
|
+
getResult: function() {
|
|
97
|
+
return {
|
|
98
|
+
ua: userAgent,
|
|
99
|
+
browser: { name: browserName, version: browserVersion },
|
|
100
|
+
engine: { name: 'unknown', version: 'unknown' },
|
|
101
|
+
os: { name: osName, version: osVersion },
|
|
102
|
+
device: { model: deviceModel, type: deviceType, vendor: deviceVendor },
|
|
103
|
+
cpu: { architecture: 'unknown' }
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
getBrowser: function() { return { name: browserName, version: browserVersion }; },
|
|
107
|
+
getEngine: function() { return { name: 'unknown', version: 'unknown' }; },
|
|
108
|
+
getOS: function() { return { name: osName, version: osVersion }; },
|
|
109
|
+
getDevice: function() { return { model: deviceModel, type: deviceType, vendor: deviceVendor }; },
|
|
110
|
+
getCPU: function() { return { architecture: 'unknown' }; },
|
|
111
|
+
getUA: function() { return userAgent; },
|
|
112
|
+
setUA: function(newUA) {
|
|
113
|
+
// This doesn't actually update the parsed values in this fallback
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export default UAParserWrapper;
|
package/veryfi-lens.js
CHANGED
|
@@ -138,6 +138,10 @@ const VeryfiLens = (function () {
|
|
|
138
138
|
submitButtonShown: false,
|
|
139
139
|
backScanningStartTime: null,
|
|
140
140
|
sdkVersion: "2.0.0",
|
|
141
|
+
documentModalMessage: 'Oops, There appears to be no document on your image',
|
|
142
|
+
blurModalMessage: 'Oops, The image is too blurry to process',
|
|
143
|
+
submitButtonText: 'Submit Anyway',
|
|
144
|
+
retakeButtonText: 'Retake a picture',
|
|
141
145
|
};
|
|
142
146
|
|
|
143
147
|
|
|
@@ -858,11 +862,22 @@ const VeryfiLens = (function () {
|
|
|
858
862
|
};
|
|
859
863
|
|
|
860
864
|
const parseUA = () => {
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
865
|
+
try {
|
|
866
|
+
const userAgentString = navigator.userAgent;
|
|
867
|
+
const parser = UAParser(userAgentString); // Note: no 'new' keyword needed now
|
|
868
|
+
let parserResults = parser.getResult();
|
|
869
|
+
if (parserResults) {
|
|
870
|
+
return parserResults;
|
|
871
|
+
}
|
|
872
|
+
// ...
|
|
873
|
+
} catch (error) {
|
|
874
|
+
console.error('Error parsing user agent:', error);
|
|
875
|
+
// Return fallback object
|
|
876
|
+
return {
|
|
877
|
+
browser: { name: 'unknown', version: 'unknown' },
|
|
878
|
+
os: { name: 'unknown', version: 'unknown' },
|
|
879
|
+
device: { model: 'unknown', type: 'unknown', vendor: 'unknown' }
|
|
880
|
+
};
|
|
866
881
|
}
|
|
867
882
|
};
|
|
868
883
|
|
|
@@ -933,6 +948,11 @@ const VeryfiLens = (function () {
|
|
|
933
948
|
state.debug_mode && console.log("Submitting anyway");
|
|
934
949
|
hideVideoOverlay();
|
|
935
950
|
state.submitHandler && state.submitHandler(state.finalImage);
|
|
951
|
+
},
|
|
952
|
+
{
|
|
953
|
+
blurModalMessage: state.blurModalMessage,
|
|
954
|
+
retakeButtonText: state.retakeButtonText,
|
|
955
|
+
submitButtonText: state.submitButtonText
|
|
936
956
|
}
|
|
937
957
|
);
|
|
938
958
|
}
|
|
@@ -950,6 +970,11 @@ const VeryfiLens = (function () {
|
|
|
950
970
|
state.debug_mode && console.log("Submitting anyway");
|
|
951
971
|
hideVideoOverlay();
|
|
952
972
|
state.submitHandler && state.submitHandler(state.finalImage);
|
|
973
|
+
},
|
|
974
|
+
{
|
|
975
|
+
noDocumentMessage: state.documentModalMessage,
|
|
976
|
+
retakeButtonText: state.retakeButtonText,
|
|
977
|
+
submitButtonText: state.submitButtonText
|
|
953
978
|
}
|
|
954
979
|
);
|
|
955
980
|
}
|