veryfi-lens-wasm 3.0.4 → 3.1.0
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/README.md +3 -0
- package/components/croppedImage.js +7 -0
- package/components/prescriptionLabelGuide.js +76 -0
- package/core/api.js +243 -65
- package/core/camera.js +2 -1
- package/core/capture/anydoc.js +22 -17
- package/core/capture/checks.js +44 -32
- package/core/capture/document.js +24 -7
- package/core/capture/prescription_label.js +213 -44
- package/core/capture/specialty.js +35 -7
- package/core/constants.js +4 -1
- package/core/lifecycle.js +7 -2
- package/core/state.js +13 -0
- package/core/ui-renderer.js +15 -2
- package/flavors/upload.js +24 -4
- package/package.json +1 -1
- package/utils/device-data.js +2 -2
- package/veryfi-lens.js +1 -0
package/README.md
CHANGED
|
@@ -233,6 +233,9 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
|
|
|
233
233
|
| `prescriptionLabelShowSquareOverlay` | `boolean` | `false` | Show a square/rectangular overlay guide |
|
|
234
234
|
| `prescriptionLabelSquareWidthRatio` | `number` | `0.8` | Square overlay width (0-1 relative to viewport) |
|
|
235
235
|
| `prescriptionLabelSquareHeightRatio` | `number` | `0.5` | Square overlay height (0-1 relative to viewport) |
|
|
236
|
+
| `prescriptionLabelShowGuide` | `boolean` | `false` | Show a semi-transparent guide explaining how to record the label. Auto-hides when recording starts and reappears on retake |
|
|
237
|
+
| `prescriptionLabelGuideText` | `string` | `"Position the bottle within the outline.\n\nPress the capture button to start recording, slowly rotate the bottle to capture the entire label and press the capture button again to stop recording."` | Guide text shown when the bottle outline overlay is active. Use `\n` for line breaks |
|
|
238
|
+
| `prescriptionLabelSquareGuideText` | `string` | `"Position the prescription label within the square.\n\nPress the capture button to start recording, press again to stop."` | Guide text shown when the square overlay is active. Use `\n` for line breaks |
|
|
236
239
|
|
|
237
240
|
### Upload Settings (`upload` flavor)
|
|
238
241
|
|
|
@@ -69,6 +69,13 @@ export const createCroppedImage = (container, options = {}) => {
|
|
|
69
69
|
updatePreviewImg();
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
+
const originalDrawImage = cropImgCanvas.getContext('2d').drawImage;
|
|
73
|
+
cropImgCanvas.getContext('2d').drawImage = function(...args) {
|
|
74
|
+
const result = originalDrawImage.apply(this, args);
|
|
75
|
+
updatePreviewImg();
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
78
|
+
|
|
72
79
|
const layouts = createLayoutManager(previewImg, cropImgCanvas, container, defaultStyles);
|
|
73
80
|
|
|
74
81
|
container.appendChild(cropImgCanvas);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export const createPrescriptionLabelGuide = (container, options = {}) => {
|
|
2
|
+
const text = options.text || '';
|
|
3
|
+
|
|
4
|
+
const guide = document.createElement('div');
|
|
5
|
+
guide.id = 'veryfi-prescription-label-guide';
|
|
6
|
+
|
|
7
|
+
Object.assign(guide.style, {
|
|
8
|
+
position: 'absolute',
|
|
9
|
+
top: 'calc(50% - 120px)',
|
|
10
|
+
left: '50%',
|
|
11
|
+
transform: 'translateX(-50%)',
|
|
12
|
+
width: '240px',
|
|
13
|
+
height: '240px',
|
|
14
|
+
padding: '14px 36px 14px 20px',
|
|
15
|
+
backgroundColor: 'rgba(0, 0, 0, 0.6)',
|
|
16
|
+
color: 'white',
|
|
17
|
+
borderRadius: '12px',
|
|
18
|
+
fontFamily: "system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif",
|
|
19
|
+
fontSize: '14px',
|
|
20
|
+
lineHeight: '1.5',
|
|
21
|
+
textAlign: 'left',
|
|
22
|
+
whiteSpace: 'pre-line',
|
|
23
|
+
zIndex: '1003',
|
|
24
|
+
pointerEvents: 'auto',
|
|
25
|
+
backdropFilter: 'blur(8px)',
|
|
26
|
+
WebkitBackdropFilter: 'blur(8px)',
|
|
27
|
+
border: '1px solid rgba(255, 255, 255, 0.2)',
|
|
28
|
+
boxSizing: 'border-box',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const textEl = document.createElement('div');
|
|
32
|
+
textEl.textContent = text;
|
|
33
|
+
guide.appendChild(textEl);
|
|
34
|
+
|
|
35
|
+
const closeButton = document.createElement('button');
|
|
36
|
+
closeButton.id = 'veryfi-prescription-label-guide-close';
|
|
37
|
+
closeButton.setAttribute('aria-label', 'Close guide');
|
|
38
|
+
closeButton.textContent = '\u00D7';
|
|
39
|
+
Object.assign(closeButton.style, {
|
|
40
|
+
position: 'absolute',
|
|
41
|
+
top: '6px',
|
|
42
|
+
right: '6px',
|
|
43
|
+
width: '24px',
|
|
44
|
+
height: '24px',
|
|
45
|
+
padding: '0',
|
|
46
|
+
border: 'none',
|
|
47
|
+
background: 'transparent',
|
|
48
|
+
color: 'white',
|
|
49
|
+
fontSize: '20px',
|
|
50
|
+
lineHeight: '24px',
|
|
51
|
+
fontFamily: 'sans-serif',
|
|
52
|
+
cursor: 'pointer',
|
|
53
|
+
opacity: '0.8',
|
|
54
|
+
pointerEvents: 'auto',
|
|
55
|
+
outline: 'none',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
closeButton.addEventListener('mouseenter', () => { closeButton.style.opacity = '1'; });
|
|
59
|
+
closeButton.addEventListener('mouseleave', () => { closeButton.style.opacity = '0.8'; });
|
|
60
|
+
closeButton.addEventListener('click', (e) => {
|
|
61
|
+
e.stopPropagation();
|
|
62
|
+
guide.style.display = 'none';
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
guide.appendChild(closeButton);
|
|
66
|
+
container.appendChild(guide);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
element: guide,
|
|
70
|
+
show: () => { guide.style.display = 'block'; },
|
|
71
|
+
hide: () => { guide.style.display = 'none'; },
|
|
72
|
+
remove: () => {
|
|
73
|
+
if (guide.parentNode) guide.parentNode.removeChild(guide);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
};
|
package/core/api.js
CHANGED
|
@@ -37,11 +37,16 @@ export const validatePartner = async (client_id) => {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
export const getMetaData = () => {
|
|
40
|
+
const flavor = state.lensFlavor;
|
|
41
|
+
const documentType =
|
|
42
|
+
flavor === 'checks' ? 'checks'
|
|
43
|
+
: (flavor === 'anydocs' || flavor === 'prescription_label') ? 'anydocs'
|
|
44
|
+
: 'documents';
|
|
40
45
|
return {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
document_type:
|
|
44
|
-
|
|
46
|
+
uuid: state.uuidv4,
|
|
47
|
+
sdk_version: "lfb-wasm",
|
|
48
|
+
document_type: documentType,
|
|
49
|
+
app_ver: state.sdkVersion,
|
|
45
50
|
blur_detected: state.blurStatus ? 1 : 0,
|
|
46
51
|
torch_mode: state.torchTrack?.getConstraints()?.advanced?.[0]?.torch ? 1 : 0,
|
|
47
52
|
corners: state.coordinates,
|
|
@@ -50,32 +55,153 @@ export const getMetaData = () => {
|
|
|
50
55
|
};
|
|
51
56
|
};
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
const buildJsonData = async () => {
|
|
59
|
+
const browserData = await getBrowserData();
|
|
60
|
+
const UAData = flattenObject(parseUA());
|
|
61
|
+
if ('os_name' in UAData) { UAData.device_platform = UAData.os_name; delete UAData.os_name; }
|
|
62
|
+
if ('os_version' in UAData) { UAData.system_ver = UAData.os_version; delete UAData.os_version; }
|
|
63
|
+
return { ...browserData, ...UAData, ...getMetaData() };
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Legacy per-crop flow: posts each captured scan to /rest/send-cropped, which
|
|
67
|
+
// uploads a single-scan zip to S3 and fires document_ready server-side with a
|
|
68
|
+
// generated UUID. Used when packageMode is disabled to preserve the
|
|
69
|
+
// pre-refactor behavior.
|
|
70
|
+
//
|
|
71
|
+
// - isBase64 = true => JSON body { image: <base64>, json_data, client_id }
|
|
72
|
+
// - isBase64 = false => multipart body { file: <Blob>, json_data, client_id }
|
|
73
|
+
const sendCroppedLegacy = async ({ data, fileName, isBase64 }) => {
|
|
74
|
+
const jsonData = await buildJsonData();
|
|
75
|
+
const clientId = state.clientId;
|
|
76
|
+
const sessionId = state.clientData?.session;
|
|
77
|
+
|
|
54
78
|
const spinner = createSpinner(document.body, 'Preparing document...');
|
|
55
79
|
spinner.show();
|
|
56
80
|
|
|
57
81
|
try {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const jsonData = { ...browserData, ...UAData, ...getMetaData() };
|
|
62
|
-
|
|
63
|
-
const payload = {
|
|
64
|
-
image: base64Image,
|
|
65
|
-
json_data: jsonData,
|
|
66
|
-
client_id: state.clientId
|
|
82
|
+
const headers = {
|
|
83
|
+
'CLIENT-ID': clientId,
|
|
84
|
+
'SESSION-ID': sessionId,
|
|
67
85
|
};
|
|
86
|
+
let body;
|
|
87
|
+
if (isBase64) {
|
|
88
|
+
headers['Content-Type'] = 'application/json';
|
|
89
|
+
body = JSON.stringify({
|
|
90
|
+
image: data,
|
|
91
|
+
json_data: jsonData,
|
|
92
|
+
client_id: clientId,
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
const formData = new FormData();
|
|
96
|
+
formData.append('file', data, fileName);
|
|
97
|
+
formData.append('json_data', JSON.stringify(jsonData));
|
|
98
|
+
formData.append('client_id', clientId);
|
|
99
|
+
body = formData;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const response = await fetch(API_URLS.SEND_CROPPED, { method: 'POST', headers, body });
|
|
103
|
+
if (!response.ok) {
|
|
104
|
+
if (response.status === 401) {
|
|
105
|
+
throw new Error('Authorization failed, please contact customer support at support@veryfi.com');
|
|
106
|
+
}
|
|
107
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
108
|
+
}
|
|
109
|
+
return await response.json();
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error('Error processing document:', error);
|
|
112
|
+
state.failureHandler?.(error);
|
|
113
|
+
throw error;
|
|
114
|
+
} finally {
|
|
115
|
+
spinner.remove();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Per-capture entrypoint. Two modes:
|
|
120
|
+
// packageMode = true => collect into state.packageScans for one cumulative
|
|
121
|
+
// zip uploaded at submit time via uploadPackage().
|
|
122
|
+
// Matches mobile's serverN.json + imageN.jpg layout.
|
|
123
|
+
// packageMode = false => fire the legacy per-crop /rest/send-cropped call,
|
|
124
|
+
// which uploads a single-scan zip to S3 and fires
|
|
125
|
+
// document_ready immediately with a generated UUID.
|
|
126
|
+
//
|
|
127
|
+
// Scan record shape:
|
|
128
|
+
// { data, fileName, isBase64, jsonData }
|
|
129
|
+
// - data: base64 string (image flavors) | Blob (prescription_label video)
|
|
130
|
+
// - fileName: entry name, e.g. 'image0.jpg' or 'prescription_label.mp4'
|
|
131
|
+
// - isBase64: true => JSZip will decode the string when zipping
|
|
132
|
+
// - jsonData: per-scan server{N}.json contents
|
|
133
|
+
export const addPackageScan = async ({ data, fileName, isBase64 = false }) => {
|
|
134
|
+
if (!state.packageMode) {
|
|
135
|
+
return await sendCroppedLegacy({ data, fileName, isBase64 });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const jsonData = await buildJsonData();
|
|
139
|
+
|
|
140
|
+
if (!state.packageUploadId) {
|
|
141
|
+
state.packageUploadId = (typeof crypto !== 'undefined' && crypto.randomUUID)
|
|
142
|
+
? crypto.randomUUID()
|
|
143
|
+
: `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
144
|
+
}
|
|
145
|
+
if (!state.packageFilename) {
|
|
146
|
+
const sanitizedClient = String(state.clientId || 'lfb').replace(/[^\w\-]+/g, '');
|
|
147
|
+
state.packageFilename = `${sanitizedClient}_veryfi_pckupl_${state.packageUploadId}.zip`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
state.packageScans.push({ data, fileName, isBase64, jsonData });
|
|
151
|
+
|
|
152
|
+
return { upload_id: state.packageUploadId };
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const docReady = async () => {
|
|
156
|
+
const index = state.packageScans.length;
|
|
157
|
+
return addPackageScan({
|
|
158
|
+
data: state.finalImage,
|
|
159
|
+
fileName: `image${index}.jpg`,
|
|
160
|
+
isBase64: true,
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const uploadPackage = async () => {
|
|
165
|
+
// Snapshot state into locals before any await: the submit button's click
|
|
166
|
+
// handler fires onSubmit() then synchronously calls removeOverlay(), which
|
|
167
|
+
// triggers resetState() and wipes state.packageScans/Filename/UploadId mid-flight.
|
|
168
|
+
const scans = state.packageScans?.slice();
|
|
169
|
+
const filename = state.packageFilename;
|
|
170
|
+
const uploadId = state.packageUploadId;
|
|
171
|
+
const clientId = state.clientId;
|
|
172
|
+
const sessionId = state.clientData?.session;
|
|
173
|
+
|
|
174
|
+
if (!scans?.length) {
|
|
175
|
+
throw new Error('No scans to upload');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const spinner = createSpinner(document.body, 'Processing document...');
|
|
179
|
+
spinner.show();
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
const { default: JSZip } = await import('jszip');
|
|
183
|
+
const zip = new JSZip();
|
|
184
|
+
scans.forEach((scan, index) => {
|
|
185
|
+
zip.file(scan.fileName, scan.data, scan.isBase64 ? { base64: true } : {});
|
|
186
|
+
zip.file(`server${index}.json`, JSON.stringify(scan.jsonData, null, 2));
|
|
187
|
+
});
|
|
188
|
+
const zipBlob = await zip.generateAsync({ type: 'blob' });
|
|
189
|
+
|
|
190
|
+
const lastJsonData = scans[scans.length - 1].jsonData;
|
|
191
|
+
const formData = new FormData();
|
|
192
|
+
formData.append('file', zipBlob, filename);
|
|
193
|
+
formData.append('json_data', JSON.stringify(lastJsonData));
|
|
194
|
+
formData.append('upload_id', uploadId);
|
|
68
195
|
|
|
69
196
|
const response = await fetch(
|
|
70
|
-
API_URLS.
|
|
197
|
+
API_URLS.SEND_PACKAGE,
|
|
71
198
|
{
|
|
72
199
|
method: "POST",
|
|
73
200
|
headers: {
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"SESSION-ID": state.clientData.session
|
|
201
|
+
"CLIENT-ID": clientId,
|
|
202
|
+
"SESSION-ID": sessionId
|
|
77
203
|
},
|
|
78
|
-
body:
|
|
204
|
+
body: formData
|
|
79
205
|
}
|
|
80
206
|
);
|
|
81
207
|
|
|
@@ -86,73 +212,125 @@ export const docReady = async () => {
|
|
|
86
212
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
87
213
|
}
|
|
88
214
|
const result = await response.json();
|
|
89
|
-
|
|
215
|
+
state.docReadyResult = result;
|
|
90
216
|
return result;
|
|
91
217
|
} catch (error) {
|
|
92
|
-
|
|
93
|
-
console.error("Error processing document:", error);
|
|
218
|
+
console.error("Error uploading package:", error);
|
|
94
219
|
state.failureHandler?.(error);
|
|
95
220
|
throw error;
|
|
221
|
+
} finally {
|
|
222
|
+
spinner.remove();
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export const ensurePackageUploaded = async () => {
|
|
227
|
+
if (!state.packageMode) return null;
|
|
228
|
+
if (state.docReadyResult?.package_path) {
|
|
229
|
+
return state.docReadyResult;
|
|
230
|
+
}
|
|
231
|
+
if (state.packageScans?.length) {
|
|
232
|
+
return await uploadPackage();
|
|
96
233
|
}
|
|
234
|
+
return state.docReadyResult;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export const fireResultSetter = async (payload, { autoUpload = true } = {}) => {
|
|
238
|
+
if (typeof state.resultSetter !== 'function') return false;
|
|
239
|
+
if (autoUpload && state.packageMode && !state.enableSubmit) {
|
|
240
|
+
const packageInfo = await ensurePackageUploaded();
|
|
241
|
+
if (packageInfo) {
|
|
242
|
+
state.resultSetter({ ...payload, ...packageInfo });
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
state.resultSetter(payload);
|
|
247
|
+
return false;
|
|
97
248
|
};
|
|
98
249
|
|
|
99
250
|
export const handleSubmit = async (image) => {
|
|
251
|
+
// Snapshot state into locals before any await — the submit button click handler
|
|
252
|
+
// fires removeOverlay()/resetState() concurrently with this flow.
|
|
100
253
|
const lensFlavor = state.lensFlavor;
|
|
101
254
|
const selectedBlueprint = state.selectedBlueprint;
|
|
102
255
|
const clientData = state.clientData;
|
|
103
256
|
const customData = state.customData;
|
|
257
|
+
const clientId = state.clientId;
|
|
258
|
+
const sessionId = state.clientData?.session;
|
|
259
|
+
const uploadId = state.packageUploadId;
|
|
260
|
+
const lastJsonData = state.packageScans?.[state.packageScans.length - 1]?.jsonData;
|
|
104
261
|
|
|
105
|
-
const spinner = createSpinner(document.body, 'Submitting document...');
|
|
106
|
-
spinner.show();
|
|
107
262
|
state.updateHandler?.({ status: 'submission_started' });
|
|
108
263
|
|
|
109
|
-
|
|
264
|
+
try {
|
|
265
|
+
const packageInfo = await ensurePackageUploaded();
|
|
266
|
+
const hasPackagePath = !!packageInfo?.package_path;
|
|
110
267
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (lensFlavor === 'anydocs' || lensFlavor === 'prescription_label') return 'anydocs';
|
|
114
|
-
return 'documents';
|
|
115
|
-
};
|
|
268
|
+
const spinner = createSpinner(document.body, 'Submitting document...');
|
|
269
|
+
spinner.show();
|
|
116
270
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
doc_type: getDocType(),
|
|
120
|
-
resource: "api",
|
|
121
|
-
client_name: clientData.client_name,
|
|
122
|
-
device_data: deviceData,
|
|
123
|
-
...((lensFlavor === 'anydocs' || lensFlavor === 'prescription_label') && selectedBlueprint ? { blueprint_name: selectedBlueprint } : {}),
|
|
124
|
-
...customData
|
|
125
|
-
};
|
|
271
|
+
try {
|
|
272
|
+
const deviceData = await getDeviceData();
|
|
126
273
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
'SESSION-ID': state.clientData.session
|
|
133
|
-
},
|
|
134
|
-
body: JSON.stringify(requestBody)
|
|
135
|
-
};
|
|
274
|
+
const getDocType = () => {
|
|
275
|
+
if (lensFlavor === 'checks') return 'checks';
|
|
276
|
+
if (lensFlavor === 'anydocs' || lensFlavor === 'prescription_label') return 'anydocs';
|
|
277
|
+
return 'documents';
|
|
278
|
+
};
|
|
136
279
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
280
|
+
const requestBody = {
|
|
281
|
+
doc_type: getDocType(),
|
|
282
|
+
resource: "api",
|
|
283
|
+
client_name: clientData.client_name,
|
|
284
|
+
device_data: deviceData,
|
|
285
|
+
...(hasPackagePath
|
|
286
|
+
? {
|
|
287
|
+
package_path: packageInfo.package_path,
|
|
288
|
+
bucket: packageInfo.bucket,
|
|
289
|
+
file_name: packageInfo.file_name,
|
|
290
|
+
upload_id: uploadId,
|
|
291
|
+
...(lastJsonData ? { package_metadata: lastJsonData } : {}),
|
|
292
|
+
}
|
|
293
|
+
: { image: image }),
|
|
294
|
+
...((lensFlavor === 'anydocs' || lensFlavor === 'prescription_label') && selectedBlueprint ? { blueprint_name: selectedBlueprint } : {}),
|
|
295
|
+
...customData
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const qrSessionId = new URLSearchParams(window.location.search).get('session');
|
|
299
|
+
|
|
300
|
+
const requestOptions = {
|
|
301
|
+
method: 'POST',
|
|
302
|
+
headers: {
|
|
303
|
+
'Content-Type': 'application/json',
|
|
304
|
+
'CLIENT-ID': clientId,
|
|
305
|
+
'SESSION-ID': sessionId,
|
|
306
|
+
...(qrSessionId ? { 'QR-SESSION-ID': qrSessionId } : {})
|
|
307
|
+
},
|
|
308
|
+
body: JSON.stringify(requestBody)
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const response = await fetch(API_URLS.PROCESS_DOCUMENT, requestOptions);
|
|
312
|
+
if (!response.ok) {
|
|
313
|
+
const errorData = await response.json().catch(() => null);
|
|
314
|
+
const message = errorData?.detail || `HTTP error! status: ${response.status}`;
|
|
315
|
+
console.error('Submit error:', errorData ?? response.status);
|
|
316
|
+
state.updateHandler?.({ status: 'submission_failed', error: errorData });
|
|
317
|
+
if (typeof state.failureHandler === 'function') {
|
|
318
|
+
state.failureHandler(errorData ?? new Error(message));
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
throw new Error(message);
|
|
322
|
+
}
|
|
323
|
+
state.debug_mode && console.log("Document submitted successfully");
|
|
324
|
+
state.updateHandler?.({ status: 'submission_completed' });
|
|
325
|
+
if (state.successHandler && typeof state.successHandler === 'function') {
|
|
326
|
+
state.debug_mode && console.log("Success handler called");
|
|
327
|
+
const result = await response.json();
|
|
328
|
+
state.successHandler(result);
|
|
329
|
+
}
|
|
330
|
+
} finally {
|
|
331
|
+
spinner.remove();
|
|
152
332
|
}
|
|
153
|
-
spinner.remove();
|
|
154
333
|
} catch (error) {
|
|
155
|
-
spinner.remove();
|
|
156
334
|
console.error('Error submitting document:', error);
|
|
157
335
|
state.failureHandler?.(error);
|
|
158
336
|
throw error;
|
package/core/camera.js
CHANGED
|
@@ -19,7 +19,7 @@ export const getVideo = async (lensFlavor) => {
|
|
|
19
19
|
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
20
20
|
|
|
21
21
|
let videoConfig = {
|
|
22
|
-
...(lensFlavor === 'long_document' || state.fullScreenEnabled ? {
|
|
22
|
+
...(lensFlavor === 'long_document' || lensFlavor === 'prescription_label' || state.fullScreenEnabled ? {
|
|
23
23
|
width: { ideal: 1920 },
|
|
24
24
|
height: { ideal: 1080 }
|
|
25
25
|
} : {
|
|
@@ -69,6 +69,7 @@ export const getVideo = async (lensFlavor) => {
|
|
|
69
69
|
|
|
70
70
|
state.videoRef.addEventListener('loadedmetadata', () => {
|
|
71
71
|
state.videoRef.style.opacity = '1';
|
|
72
|
+
console.log(`[camera] negotiated resolution ${state.videoRef.videoWidth}x${state.videoRef.videoHeight}`);
|
|
72
73
|
|
|
73
74
|
if (state.mirrorOnDesktop) {
|
|
74
75
|
const isMobile = window.innerWidth <= 768 || window.innerHeight <= 768;
|
package/core/capture/anydoc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { state } from '../state.js';
|
|
2
|
-
import { handleSubmit } from '../api.js';
|
|
2
|
+
import { handleSubmit, ensurePackageUploaded, fireResultSetter } from '../api.js';
|
|
3
3
|
import { showVideoOverlay } from '../overlay-controls.js';
|
|
4
4
|
import { newStartLens, removeOverlay } from '../lifecycle.js';
|
|
5
5
|
import { createVideo } from '../../components/video.js';
|
|
@@ -21,6 +21,11 @@ export const handleAnydocPageCapture = () => {
|
|
|
21
21
|
state.anydocPageControls = null;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// In packageMode + !enableSubmit + no customSubmitHandler the action button
|
|
25
|
+
// doesn't submit to /api/document — it signals "no more captures, upload now
|
|
26
|
+
// and hand the result to the showCamera setter". Label it "Done" to match.
|
|
27
|
+
const partnerDriven = state.packageMode && !state.enableSubmit && typeof state.customSubmitHandler !== 'function';
|
|
28
|
+
|
|
24
29
|
state.anydocPageControls = createAnydocPageControls(
|
|
25
30
|
state.videoOverlay.overlay,
|
|
26
31
|
async () => {
|
|
@@ -56,28 +61,23 @@ export const handleAnydocPageCapture = () => {
|
|
|
56
61
|
totalPages: state.anydocPages.length
|
|
57
62
|
});
|
|
58
63
|
|
|
59
|
-
let imageToSubmit;
|
|
60
|
-
if (state.anydocPages.length === 1) {
|
|
61
|
-
imageToSubmit = state.anydocPages[0];
|
|
62
|
-
} else {
|
|
63
|
-
const { default: JSZip } = await import('jszip');
|
|
64
|
-
const zip = new JSZip();
|
|
65
|
-
state.anydocPages.forEach((page, index) => {
|
|
66
|
-
zip.file(`page_${index + 1}.jpg`, page, { base64: true });
|
|
67
|
-
});
|
|
68
|
-
imageToSubmit = await zip.generateAsync({ type: "base64" });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
64
|
if (typeof state.customSubmitHandler === 'function') {
|
|
72
|
-
|
|
65
|
+
const packageInfo = await ensurePackageUploaded();
|
|
66
|
+
state.customSubmitHandler(state.finalImage, packageInfo);
|
|
67
|
+
} else if (state.packageMode && !state.enableSubmit) {
|
|
68
|
+
// packageMode + !enableSubmit: no SDK submit, no custom handler.
|
|
69
|
+
// "Done" is the only signal that all pages have been captured, so
|
|
70
|
+
// upload the cumulative zip now and surface bucket/package_path
|
|
71
|
+
// through the showCamera setter.
|
|
72
|
+
await fireResultSetter({ image: state.finalImage });
|
|
73
73
|
} else {
|
|
74
|
-
handleSubmit(
|
|
74
|
+
handleSubmit(state.finalImage);
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
77
|
removeOverlay,
|
|
78
78
|
{
|
|
79
79
|
addPageText: state.anydocAddPageText,
|
|
80
|
-
submitText: state.anydocSubmitText,
|
|
80
|
+
submitText: partnerDriven ? 'Done' : state.anydocSubmitText,
|
|
81
81
|
onClose: state.onClose,
|
|
82
82
|
onCloseRedirectUrl: state.onCloseRedirectUrl
|
|
83
83
|
}
|
|
@@ -97,6 +97,11 @@ export const handleAnydocPageCapture = () => {
|
|
|
97
97
|
state.cropImgRef
|
|
98
98
|
);
|
|
99
99
|
} else {
|
|
100
|
-
|
|
100
|
+
// Page controls are required to reach "Done" in both submit-enabled and
|
|
101
|
+
// packageMode-with-disabled-submit flows; only suppress them in the legacy
|
|
102
|
+
// packageMode: false + !enableSubmit case where the partner has no way to
|
|
103
|
+
// consume cumulative uploads anyway.
|
|
104
|
+
const showControls = state.enableSubmit || state.packageMode;
|
|
105
|
+
showControls && state.anydocPageControls.show(pageNum, canAddMore, state.anydocPages, state.cropImgRef);
|
|
101
106
|
}
|
|
102
107
|
};
|