veryfi-lens-wasm 3.0.5 → 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/components/croppedImage.js +7 -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 +106 -48
- package/core/capture/specialty.js +35 -7
- package/core/constants.js +2 -1
- package/core/lifecycle.js +7 -2
- package/core/state.js +8 -0
- package/core/ui-renderer.js +4 -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
|
@@ -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);
|
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
|
};
|
package/core/capture/checks.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { state, refs } from '../state.js';
|
|
2
2
|
import { cropWasm } from '../wasm-processing.js';
|
|
3
3
|
import { checkIfDocumentOnCapture, checkIfBlurOnCapture, checkIfLcdOnCapture } from '../validation.js';
|
|
4
|
-
import { docReady, handleSubmit } from '../api.js';
|
|
4
|
+
import { docReady, handleSubmit, ensurePackageUploaded, fireResultSetter } from '../api.js';
|
|
5
5
|
import { hideVideoOverlay, showVideoOverlay } from '../overlay-controls.js';
|
|
6
6
|
import { newStartLens, removeOverlay } from '../lifecycle.js';
|
|
7
7
|
import { createSubmitButton } from '../../components/submitButton.js';
|
|
@@ -19,14 +19,23 @@ export const handleChecksFrontAccepted = async () => {
|
|
|
19
19
|
state.updateHandler?.({ status: 'processing_completed' });
|
|
20
20
|
state.debug_mode && console.log("Front check image processed successfully");
|
|
21
21
|
|
|
22
|
-
state.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const isBackExpected = state.captureBackOfCheck || state.enforceBothSides || state.enforceAndSkipBothSides;
|
|
23
|
+
|
|
24
|
+
const finalized = await fireResultSetter(
|
|
25
|
+
{
|
|
26
|
+
...state.docReadyResult,
|
|
27
|
+
frontImage: state.frontImage,
|
|
28
|
+
frontLcdResult: state.frontLcdResult,
|
|
29
|
+
frontFrontBackResult: state.frontFrontBackResult
|
|
30
|
+
},
|
|
31
|
+
{ autoUpload: !isBackExpected }
|
|
32
|
+
);
|
|
33
|
+
if (finalized) {
|
|
34
|
+
removeOverlay();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
28
37
|
|
|
29
|
-
if (
|
|
38
|
+
if (isBackExpected) {
|
|
30
39
|
if (state.enforceAndSkipBothSides) {
|
|
31
40
|
const proceedToBackCapture = () => {
|
|
32
41
|
if (state.videoRef) state.videoRef.style.display = 'block';
|
|
@@ -73,9 +82,10 @@ export const handleChecksFrontAccepted = async () => {
|
|
|
73
82
|
state.enforceBothSides ? null : () => {
|
|
74
83
|
hideVideoOverlay();
|
|
75
84
|
if (state.isDocument) {
|
|
76
|
-
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
85
|
+
state.submitButton = createSubmitButton(state.videoOverlay.overlay, async () => {
|
|
77
86
|
if (typeof state.customSubmitHandler === 'function') {
|
|
78
|
-
|
|
87
|
+
const packageInfo = await ensurePackageUploaded();
|
|
88
|
+
state.customSubmitHandler(state.frontImage, packageInfo);
|
|
79
89
|
} else {
|
|
80
90
|
handleSubmit(state.frontImage);
|
|
81
91
|
}
|
|
@@ -101,16 +111,21 @@ export const handleChecksFrontAccepted = async () => {
|
|
|
101
111
|
} else {
|
|
102
112
|
hideVideoOverlay();
|
|
103
113
|
if (state.isDocument) {
|
|
104
|
-
|
|
114
|
+
const finalized = await fireResultSetter({
|
|
105
115
|
...state.docReadyResult,
|
|
106
116
|
frontImage: state.frontImage,
|
|
107
117
|
frontLcdResult: state.frontLcdResult,
|
|
108
118
|
frontFrontBackResult: state.frontFrontBackResult
|
|
109
119
|
});
|
|
120
|
+
if (finalized) {
|
|
121
|
+
removeOverlay();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
110
124
|
|
|
111
|
-
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
125
|
+
state.submitButton = createSubmitButton(state.videoOverlay.overlay, async () => {
|
|
112
126
|
if (typeof state.customSubmitHandler === 'function') {
|
|
113
|
-
|
|
127
|
+
const packageInfo = await ensurePackageUploaded();
|
|
128
|
+
state.customSubmitHandler(state.frontImage, packageInfo);
|
|
114
129
|
} else {
|
|
115
130
|
handleSubmit(state.frontImage);
|
|
116
131
|
}
|
|
@@ -140,32 +155,29 @@ export const handleChecksBackAccepted = async () => {
|
|
|
140
155
|
try {
|
|
141
156
|
const elements = await refs.checkImagesComponent.renderCheckImages(state.frontImage, state.backImage, state.cropImgRef);
|
|
142
157
|
if (state.isDocument) {
|
|
143
|
-
|
|
144
|
-
const zip = new JSZip();
|
|
145
|
-
zip.file("front.jpg", state.frontImage, { base64: true });
|
|
146
|
-
zip.file("back.jpg", state.backImage, { base64: true });
|
|
147
|
-
const zipContent = await zip.generateAsync({ type: "base64" });
|
|
148
|
-
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
158
|
+
state.submitButton = createSubmitButton(state.videoOverlay.overlay, async () => {
|
|
149
159
|
if (typeof state.customSubmitHandler === 'function') {
|
|
150
|
-
|
|
160
|
+
const packageInfo = await ensurePackageUploaded();
|
|
161
|
+
state.customSubmitHandler(state.frontImage, packageInfo);
|
|
151
162
|
} else {
|
|
152
|
-
|
|
163
|
+
handleSubmit(state.frontImage);
|
|
153
164
|
}
|
|
154
165
|
}, removeOverlay);
|
|
155
166
|
state.enableSubmit && state.submitButton.show();
|
|
156
167
|
}
|
|
157
168
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
state.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
+
state.debug_mode && console.log("Setting result setter");
|
|
170
|
+
const finalized = await fireResultSetter({
|
|
171
|
+
...state.docReadyResult,
|
|
172
|
+
frontImage: state.frontImage,
|
|
173
|
+
backImage: state.backImage,
|
|
174
|
+
frontLcdResult: state.frontLcdResult,
|
|
175
|
+
backLcdResult: state.backLcdResult,
|
|
176
|
+
frontFrontBackResult: state.frontFrontBackResult,
|
|
177
|
+
backFrontBackResult: state.backFrontBackResult
|
|
178
|
+
});
|
|
179
|
+
if (finalized) {
|
|
180
|
+
removeOverlay();
|
|
169
181
|
}
|
|
170
182
|
} catch (error) {
|
|
171
183
|
console.error('Error rendering check images:', error);
|
package/core/capture/document.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { state, refs } from '../state.js';
|
|
2
2
|
import { cropWasm } from '../wasm-processing.js';
|
|
3
3
|
import { checkIfDocumentOnCapture, checkIfBlurOnCapture, checkIfLcdOnCapture } from '../validation.js';
|
|
4
|
-
import { docReady, handleSubmit } from '../api.js';
|
|
4
|
+
import { docReady, handleSubmit, ensurePackageUploaded, fireResultSetter } from '../api.js';
|
|
5
5
|
import { hideVideoOverlay } from '../overlay-controls.js';
|
|
6
6
|
import { stopLens, startStitching, stopStitching, removeOverlay } from '../lifecycle.js';
|
|
7
7
|
import { generateDeviceIDifNeeded } from '../device.js';
|
|
@@ -117,7 +117,15 @@ export const handleDocumentAutoCaptureDone = async () => {
|
|
|
117
117
|
state.lcdStatus = documentLcdResult.is_lcd || (documentLcdResult.lcdProb !== undefined && documentLcdResult.lcdProb > state.lcdThreshold);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
// anydocs is multi-page; defer the eager upload until "Done" is clicked.
|
|
121
|
+
const finalized = await fireResultSetter(
|
|
122
|
+
{ ...state.docReadyResult, image: state.finalImage },
|
|
123
|
+
{ autoUpload: state.lensFlavor !== 'anydocs' }
|
|
124
|
+
);
|
|
125
|
+
if (finalized) {
|
|
126
|
+
removeOverlay();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
121
129
|
|
|
122
130
|
const isDocumentDetected = checkIfDocumentOnCapture();
|
|
123
131
|
const documentModalShown = !isDocumentDetected && state.isDocumentModal && !!state.documentModal;
|
|
@@ -134,9 +142,10 @@ export const handleDocumentAutoCaptureDone = async () => {
|
|
|
134
142
|
const { handleAnydocPageCapture } = await import('./anydoc.js');
|
|
135
143
|
handleAnydocPageCapture();
|
|
136
144
|
} else {
|
|
137
|
-
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
145
|
+
state.submitButton = createSubmitButton(state.videoOverlay.overlay, async () => {
|
|
138
146
|
if (typeof state.customSubmitHandler === 'function') {
|
|
139
|
-
|
|
147
|
+
const packageInfo = await ensurePackageUploaded();
|
|
148
|
+
state.customSubmitHandler(state.finalImage, packageInfo);
|
|
140
149
|
} else {
|
|
141
150
|
handleSubmit(state.finalImage);
|
|
142
151
|
}
|
|
@@ -226,7 +235,14 @@ export const newCapture = async () => {
|
|
|
226
235
|
state.debug_mode && console.log(`LCD detection - prob: ${documentLcdResult.lcdProb}, threshold: ${state.lcdThreshold}, detected: ${state.lcdStatus}`);
|
|
227
236
|
}
|
|
228
237
|
|
|
229
|
-
|
|
238
|
+
const finalized = await fireResultSetter(
|
|
239
|
+
{ ...state.docReadyResult, image: state.finalImage },
|
|
240
|
+
{ autoUpload: state.lensFlavor !== 'anydocs' }
|
|
241
|
+
);
|
|
242
|
+
if (finalized) {
|
|
243
|
+
removeOverlay();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
230
246
|
}
|
|
231
247
|
|
|
232
248
|
const documentModalShown = !isDocumentDetected && state.isDocumentModal && !!state.documentModal;
|
|
@@ -244,9 +260,10 @@ export const newCapture = async () => {
|
|
|
244
260
|
const { handleAnydocPageCapture } = await import('./anydoc.js');
|
|
245
261
|
handleAnydocPageCapture();
|
|
246
262
|
} else {
|
|
247
|
-
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
263
|
+
state.submitButton = createSubmitButton(state.videoOverlay.overlay, async () => {
|
|
248
264
|
if (typeof state.customSubmitHandler === 'function') {
|
|
249
|
-
|
|
265
|
+
const packageInfo = await ensurePackageUploaded();
|
|
266
|
+
state.customSubmitHandler(state.finalImage, packageInfo);
|
|
250
267
|
} else {
|
|
251
268
|
handleSubmit(state.finalImage);
|
|
252
269
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { state } from '../state.js';
|
|
2
|
-
import { handleSubmit } from '../api.js';
|
|
2
|
+
import { handleSubmit, addPackageScan, ensurePackageUploaded } from '../api.js';
|
|
3
3
|
import { hideVideoOverlay, showVideoOverlay } from '../overlay-controls.js';
|
|
4
4
|
import { removeOverlay, newStartLens } from '../lifecycle.js';
|
|
5
5
|
import { createSubmitButton } from '../../components/submitButton.js';
|
|
6
6
|
|
|
7
|
-
let
|
|
8
|
-
let
|
|
7
|
+
let previewRecorder = null;
|
|
8
|
+
let previewChunks = [];
|
|
9
|
+
let submissionRecorder = null;
|
|
10
|
+
let submissionChunks = [];
|
|
9
11
|
let isRecording = false;
|
|
10
12
|
let recordingIndicator = null;
|
|
11
13
|
let pulseStyleEl = null;
|
|
@@ -15,6 +17,7 @@ let playPauseButtonEl = null;
|
|
|
15
17
|
let lastVideoBlob = null;
|
|
16
18
|
let cropCanvas = null;
|
|
17
19
|
let cropAnimationFrameId = null;
|
|
20
|
+
let recordingStartTime = 0;
|
|
18
21
|
|
|
19
22
|
const ensurePulseKeyframes = () => {
|
|
20
23
|
if (pulseStyleEl) return;
|
|
@@ -182,7 +185,6 @@ const computeSourceCropRegion = (videoElement) => {
|
|
|
182
185
|
};
|
|
183
186
|
|
|
184
187
|
const startCroppedDrawLoop = (videoElement, region) => {
|
|
185
|
-
// Even dimensions are required by some video codecs (e.g. H.264).
|
|
186
188
|
const outW = Math.max(2, Math.floor(region.srcW / 2) * 2);
|
|
187
189
|
const outH = Math.max(2, Math.floor(region.srcH / 2) * 2);
|
|
188
190
|
|
|
@@ -207,8 +209,6 @@ const startCroppedDrawLoop = (videoElement, region) => {
|
|
|
207
209
|
cropAnimationFrameId = requestAnimationFrame(draw);
|
|
208
210
|
};
|
|
209
211
|
draw();
|
|
210
|
-
|
|
211
|
-
return cropCanvas.captureStream(30);
|
|
212
212
|
};
|
|
213
213
|
|
|
214
214
|
const stopCroppedDrawLoop = () => {
|
|
@@ -227,39 +227,48 @@ const startRecording = () => {
|
|
|
227
227
|
return;
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
previewChunks = [];
|
|
231
|
+
submissionChunks = [];
|
|
231
232
|
const mimeType = getRecorderMimeType();
|
|
232
233
|
const recorderOptions = mimeType ? { mimeType } : {};
|
|
233
234
|
console.log(`[prescription_label] MediaRecorder options:`, recorderOptions);
|
|
234
235
|
|
|
235
|
-
let
|
|
236
|
+
let previewStream = stream;
|
|
237
|
+
let submissionStream = stream;
|
|
236
238
|
const region = computeSourceCropRegion(state.videoRef);
|
|
237
239
|
if (region) {
|
|
238
240
|
try {
|
|
239
|
-
|
|
241
|
+
startCroppedDrawLoop(state.videoRef, region);
|
|
240
242
|
state.debug_mode && console.log(`[prescription_label] Cropping video to ${cropCanvas.width}x${cropCanvas.height} (source region ${Math.round(region.srcW)}x${Math.round(region.srcH)} at ${Math.round(region.srcX)},${Math.round(region.srcY)})`);
|
|
243
|
+
previewStream = cropCanvas.captureStream(30);
|
|
244
|
+
submissionStream = cropCanvas.captureStream(30);
|
|
241
245
|
} catch (e) {
|
|
242
246
|
console.warn('[prescription_label] Failed to set up cropped recording stream, falling back to full video:', e);
|
|
243
247
|
stopCroppedDrawLoop();
|
|
244
|
-
|
|
248
|
+
previewStream = stream;
|
|
249
|
+
submissionStream = stream;
|
|
245
250
|
}
|
|
246
251
|
}
|
|
247
252
|
|
|
248
253
|
try {
|
|
249
|
-
|
|
254
|
+
previewRecorder = new MediaRecorder(previewStream, recorderOptions);
|
|
255
|
+
submissionRecorder = new MediaRecorder(submissionStream, recorderOptions);
|
|
250
256
|
} catch (e) {
|
|
251
257
|
console.error('Failed to create MediaRecorder:', e);
|
|
252
258
|
state.failureHandler?.(e);
|
|
253
259
|
return;
|
|
254
260
|
}
|
|
255
261
|
|
|
256
|
-
|
|
257
|
-
if (event.data.size > 0)
|
|
258
|
-
|
|
259
|
-
|
|
262
|
+
previewRecorder.ondataavailable = (event) => {
|
|
263
|
+
if (event.data.size > 0) previewChunks.push(event.data);
|
|
264
|
+
};
|
|
265
|
+
submissionRecorder.ondataavailable = (event) => {
|
|
266
|
+
if (event.data.size > 0) submissionChunks.push(event.data);
|
|
260
267
|
};
|
|
261
268
|
|
|
262
|
-
|
|
269
|
+
previewRecorder.start(200);
|
|
270
|
+
submissionRecorder.start(200);
|
|
271
|
+
recordingStartTime = performance.now();
|
|
263
272
|
isRecording = true;
|
|
264
273
|
updateRecordingUI(true);
|
|
265
274
|
state.prescriptionLabelGuide?.hide?.();
|
|
@@ -269,24 +278,40 @@ const startRecording = () => {
|
|
|
269
278
|
|
|
270
279
|
const stopRecording = () => {
|
|
271
280
|
return new Promise((resolve) => {
|
|
272
|
-
if (!
|
|
281
|
+
if (!previewRecorder || !submissionRecorder || !isRecording) {
|
|
273
282
|
resolve(null);
|
|
274
283
|
return;
|
|
275
284
|
}
|
|
276
285
|
|
|
277
|
-
|
|
286
|
+
let previewBlob = null;
|
|
287
|
+
let submissionBlob = null;
|
|
288
|
+
const finalize = () => {
|
|
289
|
+
if (!previewBlob || !submissionBlob) return;
|
|
290
|
+
const durationSec = (performance.now() - recordingStartTime) / 1000;
|
|
291
|
+
console.log(`[prescription_label] preview blob — size: ${previewBlob.size} bytes (${(previewBlob.size / 1024).toFixed(1)} KB), duration: ${durationSec.toFixed(2)}s, bitrate: ${((previewBlob.size * 8) / durationSec / 1000).toFixed(0)} kbps`);
|
|
292
|
+
console.log(`[prescription_label] submission blob — size: ${submissionBlob.size} bytes (${(submissionBlob.size / 1024).toFixed(1)} KB), duration: ${durationSec.toFixed(2)}s, bitrate: ${((submissionBlob.size * 8) / durationSec / 1000).toFixed(0)} kbps`);
|
|
293
|
+
previewChunks = [];
|
|
294
|
+
submissionChunks = [];
|
|
295
|
+
previewRecorder = null;
|
|
296
|
+
submissionRecorder = null;
|
|
278
297
|
isRecording = false;
|
|
279
298
|
updateRecordingUI(false);
|
|
280
|
-
const blob = new Blob(recordedChunks, { type: mediaRecorder.mimeType });
|
|
281
|
-
recordedChunks = [];
|
|
282
|
-
mediaRecorder = null;
|
|
283
299
|
stopCroppedDrawLoop();
|
|
284
300
|
state.updateHandler?.({ status: 'recording_stopped' });
|
|
285
|
-
|
|
286
|
-
|
|
301
|
+
resolve({ previewBlob, submissionBlob });
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
previewRecorder.onstop = () => {
|
|
305
|
+
previewBlob = new Blob(previewChunks, { type: previewRecorder.mimeType });
|
|
306
|
+
finalize();
|
|
307
|
+
};
|
|
308
|
+
submissionRecorder.onstop = () => {
|
|
309
|
+
submissionBlob = new Blob(submissionChunks, { type: submissionRecorder.mimeType });
|
|
310
|
+
finalize();
|
|
287
311
|
};
|
|
288
312
|
|
|
289
|
-
|
|
313
|
+
previewRecorder.stop();
|
|
314
|
+
submissionRecorder.stop();
|
|
290
315
|
});
|
|
291
316
|
};
|
|
292
317
|
|
|
@@ -424,6 +449,11 @@ const showVideoPreview = (videoBlob) => {
|
|
|
424
449
|
state.submitButton.remove();
|
|
425
450
|
state.submitButton = null;
|
|
426
451
|
}
|
|
452
|
+
// The recording-end addPackageScan accumulated a scan in package mode;
|
|
453
|
+
// drop it so the next recording replaces (not appends to) it.
|
|
454
|
+
if (state.packageMode && state.packageScans?.length) {
|
|
455
|
+
state.packageScans.pop();
|
|
456
|
+
}
|
|
427
457
|
showVideoOverlay();
|
|
428
458
|
state.prescriptionLabelGuide?.show?.();
|
|
429
459
|
await newStartLens();
|
|
@@ -432,27 +462,36 @@ const showVideoPreview = (videoBlob) => {
|
|
|
432
462
|
};
|
|
433
463
|
|
|
434
464
|
const submitVideoBlob = async (videoBlob) => {
|
|
465
|
+
const submissionStartTime = performance.now();
|
|
435
466
|
state.updateHandler?.({ status: 'processing_started' });
|
|
436
467
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
468
|
+
// /api/document accepts either { package_path, ... } (packageMode true) or
|
|
469
|
+
// { image: <base64> } (legacy). Blobs cannot be JSON-serialized, so for the
|
|
470
|
+
// legacy path we zip+base64 the video here, mirroring the pre-refactor flow.
|
|
471
|
+
let submitData = videoBlob;
|
|
472
|
+
if (!state.packageMode) {
|
|
473
|
+
const ext = videoBlob.type.includes('mp4') ? 'mp4' : videoBlob.type.includes('quicktime') ? 'mov' : 'webm';
|
|
474
|
+
const { default: JSZip } = await import('jszip');
|
|
475
|
+
const zip = new JSZip();
|
|
476
|
+
zip.file(`prescription_label.${ext}`, videoBlob);
|
|
477
|
+
submitData = await zip.generateAsync({ type: 'base64' });
|
|
478
|
+
}
|
|
444
479
|
|
|
445
|
-
state.finalImage = zipBase64;
|
|
446
480
|
state.updateHandler?.({ status: 'processing_completed' });
|
|
447
481
|
|
|
482
|
+
const uploadStartTime = performance.now();
|
|
448
483
|
if (typeof state.customSubmitHandler === 'function') {
|
|
449
|
-
|
|
484
|
+
const packageInfo = await ensurePackageUploaded();
|
|
485
|
+
state.customSubmitHandler(videoBlob, packageInfo);
|
|
450
486
|
} else {
|
|
451
|
-
await handleSubmit(
|
|
487
|
+
await handleSubmit(submitData);
|
|
452
488
|
}
|
|
489
|
+
const uploadDurationSec = (performance.now() - uploadStartTime) / 1000;
|
|
490
|
+
const totalDurationSec = (performance.now() - submissionStartTime) / 1000;
|
|
491
|
+
console.log(`[prescription_label] submission complete — total: ${totalDurationSec.toFixed(2)}s, upload: ${uploadDurationSec.toFixed(2)}s, video: ${(videoBlob.size / 1024).toFixed(1)} KB`);
|
|
453
492
|
|
|
454
493
|
state.updateHandler?.({ status: 'capture_completed' });
|
|
455
|
-
return
|
|
494
|
+
return videoBlob;
|
|
456
495
|
};
|
|
457
496
|
|
|
458
497
|
export const capturePrescriptionLabel = async () => {
|
|
@@ -466,10 +505,11 @@ export const capturePrescriptionLabel = async () => {
|
|
|
466
505
|
state.debug_mode && console.log('[EVENT] stopping prescription label recording');
|
|
467
506
|
state.updateHandler?.({ status: 'capture_started' });
|
|
468
507
|
|
|
469
|
-
const
|
|
470
|
-
if (!
|
|
508
|
+
const result = await stopRecording();
|
|
509
|
+
if (!result || !result.previewBlob || result.previewBlob.size === 0 || !result.submissionBlob || result.submissionBlob.size === 0) {
|
|
471
510
|
throw new Error('Failed to record video');
|
|
472
511
|
}
|
|
512
|
+
const { previewBlob, submissionBlob } = result;
|
|
473
513
|
|
|
474
514
|
hideVideoOverlay();
|
|
475
515
|
state.exitButtonRef?.hide?.();
|
|
@@ -478,12 +518,24 @@ export const capturePrescriptionLabel = async () => {
|
|
|
478
518
|
state.videoRef.srcObject.getTracks().forEach((track) => track.stop());
|
|
479
519
|
}
|
|
480
520
|
|
|
481
|
-
showVideoPreview(
|
|
521
|
+
showVideoPreview(previewBlob);
|
|
522
|
+
|
|
523
|
+
// Per-capture upload, parity with image flavors' docReady() on crop accept:
|
|
524
|
+
// - packageMode: true => accumulate scan into state.packageScans
|
|
525
|
+
// - packageMode: false => POST multipart Blob to /rest/send-cropped now
|
|
526
|
+
const ext = submissionBlob.type.includes('mp4') ? 'mp4'
|
|
527
|
+
: submissionBlob.type.includes('quicktime') ? 'mov'
|
|
528
|
+
: 'webm';
|
|
529
|
+
state.docReadyResult = await addPackageScan({
|
|
530
|
+
data: submissionBlob,
|
|
531
|
+
fileName: `prescription_label.${ext}`,
|
|
532
|
+
isBase64: false,
|
|
533
|
+
});
|
|
482
534
|
|
|
483
535
|
state.submitButton = createSubmitButton(
|
|
484
536
|
state.container,
|
|
485
537
|
async () => {
|
|
486
|
-
await submitVideoBlob(
|
|
538
|
+
await submitVideoBlob(submissionBlob);
|
|
487
539
|
removeOverlay();
|
|
488
540
|
},
|
|
489
541
|
() => {}
|
|
@@ -500,7 +552,14 @@ export const capturePrescriptionLabel = async () => {
|
|
|
500
552
|
}
|
|
501
553
|
state.submitButton.show();
|
|
502
554
|
|
|
503
|
-
state.
|
|
555
|
+
if (state.packageMode && !state.enableSubmit) {
|
|
556
|
+
// packageMode + !enableSubmit: upload now and surface bucket/package_path
|
|
557
|
+
// through the setter alongside the raw videoBlob.
|
|
558
|
+
const packageInfo = await ensurePackageUploaded();
|
|
559
|
+
state.resultSetter?.({ ...(packageInfo || {}), image: submissionBlob });
|
|
560
|
+
} else {
|
|
561
|
+
state.resultSetter?.(submissionBlob);
|
|
562
|
+
}
|
|
504
563
|
|
|
505
564
|
return null;
|
|
506
565
|
} catch (error) {
|
|
@@ -512,15 +571,14 @@ export const capturePrescriptionLabel = async () => {
|
|
|
512
571
|
};
|
|
513
572
|
|
|
514
573
|
export const cleanupPrescriptionLabelRecording = () => {
|
|
515
|
-
if (
|
|
516
|
-
try {
|
|
517
|
-
|
|
518
|
-
} catch (e) {
|
|
519
|
-
// ignore
|
|
520
|
-
}
|
|
574
|
+
if (isRecording) {
|
|
575
|
+
try { previewRecorder?.stop(); } catch (e) { /* ignore */ }
|
|
576
|
+
try { submissionRecorder?.stop(); } catch (e) { /* ignore */ }
|
|
521
577
|
}
|
|
522
|
-
|
|
523
|
-
|
|
578
|
+
previewRecorder = null;
|
|
579
|
+
submissionRecorder = null;
|
|
580
|
+
previewChunks = [];
|
|
581
|
+
submissionChunks = [];
|
|
524
582
|
isRecording = false;
|
|
525
583
|
updateRecordingUI(false);
|
|
526
584
|
stopCroppedDrawLoop();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { state } from '../state.js';
|
|
2
|
-
import { docReady, handleSubmit } from '../api.js';
|
|
2
|
+
import { docReady, handleSubmit, ensurePackageUploaded, fireResultSetter } from '../api.js';
|
|
3
3
|
import { hideVideoOverlay } from '../overlay-controls.js';
|
|
4
4
|
import { removeOverlay } from '../lifecycle.js';
|
|
5
5
|
import { createSubmitButton } from '../../components/submitButton.js';
|
|
@@ -22,6 +22,14 @@ export const captureBottleCap = async () => {
|
|
|
22
22
|
state.isDocument = true;
|
|
23
23
|
hideVideoOverlay();
|
|
24
24
|
|
|
25
|
+
// hideVideoOverlay() doesn't cover the bottle-cap dark mask (it lives in
|
|
26
|
+
// its own overlay), and capturing doesn't stop the camera stream — so
|
|
27
|
+
// without this the cropped preview shows through a grey backdrop and the
|
|
28
|
+
// device camera LED stays on. Hide the specialty overlay and stop the
|
|
29
|
+
// tracks now that the still frame has been captured.
|
|
30
|
+
state.bottleCapOverlay?.hide?.();
|
|
31
|
+
state.videoRef?.srcObject?.getTracks?.().forEach((track) => track.stop());
|
|
32
|
+
|
|
25
33
|
state.cropImgRef?.setSquareDisplay?.();
|
|
26
34
|
state.cropImgRef?.showSuccessBorder?.();
|
|
27
35
|
|
|
@@ -31,14 +39,20 @@ export const captureBottleCap = async () => {
|
|
|
31
39
|
state.updateHandler?.({ status: 'processing_started' });
|
|
32
40
|
state.docReadyResult = await docReady();
|
|
33
41
|
state.updateHandler?.({ status: 'processing_completed' });
|
|
34
|
-
|
|
42
|
+
const finalized = await fireResultSetter({ ...state.docReadyResult, image: state.finalImage });
|
|
43
|
+
if (finalized) {
|
|
44
|
+
state.updateHandler?.({ status: 'capture_completed' });
|
|
45
|
+
removeOverlay();
|
|
46
|
+
return state.finalImage;
|
|
47
|
+
}
|
|
35
48
|
} catch (error) {
|
|
36
49
|
console.error("Error processing document:", error);
|
|
37
50
|
}
|
|
38
51
|
|
|
39
|
-
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
52
|
+
state.submitButton = createSubmitButton(state.videoOverlay.overlay, async () => {
|
|
40
53
|
if (typeof state.customSubmitHandler === 'function') {
|
|
41
|
-
|
|
54
|
+
const packageInfo = await ensurePackageUploaded();
|
|
55
|
+
state.customSubmitHandler(state.finalImage, packageInfo);
|
|
42
56
|
} else {
|
|
43
57
|
handleSubmit(state.finalImage);
|
|
44
58
|
}
|
|
@@ -74,6 +88,14 @@ export const captureCodeStrip = async () => {
|
|
|
74
88
|
state.isDocument = true;
|
|
75
89
|
hideVideoOverlay();
|
|
76
90
|
|
|
91
|
+
// hideVideoOverlay() doesn't cover the code-strips dark mask (it lives in
|
|
92
|
+
// its own overlay), and capturing doesn't stop the camera stream — so
|
|
93
|
+
// without this the cropped preview shows through a grey backdrop and the
|
|
94
|
+
// device camera LED stays on. Hide the specialty overlay and stop the
|
|
95
|
+
// tracks now that the still frame has been captured.
|
|
96
|
+
state.codeStripsOverlay?.hide?.();
|
|
97
|
+
state.videoRef?.srcObject?.getTracks?.().forEach((track) => track.stop());
|
|
98
|
+
|
|
77
99
|
state.cropImgRef?.setRectangleDisplay?.();
|
|
78
100
|
state.cropImgRef?.showSuccessBorder?.();
|
|
79
101
|
|
|
@@ -83,14 +105,20 @@ export const captureCodeStrip = async () => {
|
|
|
83
105
|
state.updateHandler?.({ status: 'processing_started' });
|
|
84
106
|
state.docReadyResult = await docReady();
|
|
85
107
|
state.updateHandler?.({ status: 'processing_completed' });
|
|
86
|
-
|
|
108
|
+
const finalized = await fireResultSetter({ ...state.docReadyResult, image: state.finalImage });
|
|
109
|
+
if (finalized) {
|
|
110
|
+
state.updateHandler?.({ status: 'capture_completed' });
|
|
111
|
+
removeOverlay();
|
|
112
|
+
return state.finalImage;
|
|
113
|
+
}
|
|
87
114
|
} catch (error) {
|
|
88
115
|
console.error("Error processing document:", error);
|
|
89
116
|
}
|
|
90
117
|
|
|
91
|
-
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
118
|
+
state.submitButton = createSubmitButton(state.videoOverlay.overlay, async () => {
|
|
92
119
|
if (typeof state.customSubmitHandler === 'function') {
|
|
93
|
-
|
|
120
|
+
const packageInfo = await ensurePackageUploaded();
|
|
121
|
+
state.customSubmitHandler(state.finalImage, packageInfo);
|
|
94
122
|
} else {
|
|
95
123
|
handleSubmit(state.finalImage);
|
|
96
124
|
}
|
package/core/constants.js
CHANGED
|
@@ -5,6 +5,7 @@ export const WASM = {
|
|
|
5
5
|
export const API_URLS = {
|
|
6
6
|
VALIDATE_PARTNER: 'https://lens.veryfi.com/rest/validate_partner',
|
|
7
7
|
SEND_CROPPED: 'https://lens.veryfi.com/rest/send-cropped',
|
|
8
|
+
SEND_PACKAGE: 'https://lens.veryfi.com/rest/send-package',
|
|
8
9
|
PROCESS_DOCUMENT: 'https://lens.veryfi.com/api/document',
|
|
9
10
|
BLUEPRINTS: 'https://lens.veryfi.com/api/blueprints',
|
|
10
11
|
FINGERPRINT: 'https://fp.veryfi.com',
|
|
@@ -12,7 +13,7 @@ export const API_URLS = {
|
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
export const DEFAULTS = {
|
|
15
|
-
SDK_VERSION: '3.0
|
|
16
|
+
SDK_VERSION: '3.1.0',
|
|
16
17
|
BLUR_THRESHOLD: 0.7,
|
|
17
18
|
LCD_THRESHOLD: 0.5,
|
|
18
19
|
BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
|
package/core/lifecycle.js
CHANGED
|
@@ -2,7 +2,7 @@ import { state, refs, resetState, actions } from './state.js';
|
|
|
2
2
|
import { getVideo, displayVideo } from './camera.js';
|
|
3
3
|
import { initializeWasmWrapper, sendWasm, sendCardWasm, getLongImage, logDocument, stopWasm, resetAutoCaptureCounters } from './wasm-processing.js';
|
|
4
4
|
import { hideVideoOverlay } from './overlay-controls.js';
|
|
5
|
-
import { docReady, handleSubmit } from './api.js';
|
|
5
|
+
import { docReady, handleSubmit, fireResultSetter } from './api.js';
|
|
6
6
|
import { createSubmitButton } from '../components/submitButton.js';
|
|
7
7
|
import { createLongPreview } from '../components/longPreview.js';
|
|
8
8
|
import { createCheckOverlay } from '../components/checkOverlay.js';
|
|
@@ -171,7 +171,12 @@ export const stopStitching = async () => {
|
|
|
171
171
|
hideVideoOverlay();
|
|
172
172
|
state.resultSetter?.(state.finalImage);
|
|
173
173
|
state.docReadyResult = await docReady();
|
|
174
|
-
|
|
174
|
+
const finalized = await fireResultSetter({ ...state.docReadyResult, image: state.finalImage });
|
|
175
|
+
if (finalized) {
|
|
176
|
+
state.updateHandler?.({ status: 'stitching_completed' });
|
|
177
|
+
removeOverlay();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
175
180
|
state.submitButton = createSubmitButton(state.videoOverlay.overlay, () => {
|
|
176
181
|
handleSubmit(state.finalImage);
|
|
177
182
|
}, () => actions.removeOverlay());
|
package/core/state.js
CHANGED
|
@@ -124,6 +124,9 @@ export const state = {
|
|
|
124
124
|
anydocPages: [],
|
|
125
125
|
anydocMaxPages: null,
|
|
126
126
|
anydocPageControls: null,
|
|
127
|
+
packageScans: [],
|
|
128
|
+
packageFilename: null,
|
|
129
|
+
packageUploadId: null,
|
|
127
130
|
anydocAddPageText: MESSAGES.ANYDOC_ADD_PAGE,
|
|
128
131
|
anydocSubmitText: MESSAGES.ANYDOC_SUBMIT,
|
|
129
132
|
anydocShowFlipMessage: false,
|
|
@@ -250,6 +253,8 @@ export const state = {
|
|
|
250
253
|
|
|
251
254
|
customData: {},
|
|
252
255
|
|
|
256
|
+
packageMode: false,
|
|
257
|
+
|
|
253
258
|
enforceFingerprint: false,
|
|
254
259
|
disableFingerprint: false,
|
|
255
260
|
|
|
@@ -326,6 +331,9 @@ export const resetState = () => {
|
|
|
326
331
|
state.blueprintsData = null;
|
|
327
332
|
state.anydocPages = [];
|
|
328
333
|
state.anydocPageControls = null;
|
|
334
|
+
state.packageScans = [];
|
|
335
|
+
state.packageFilename = null;
|
|
336
|
+
state.packageUploadId = null;
|
|
329
337
|
|
|
330
338
|
if (state.usingOverlayContainer) {
|
|
331
339
|
state.container = null;
|
package/core/ui-renderer.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { state, refs, actions } from './state.js';
|
|
2
2
|
import { hideVideoOverlay, showVideoOverlay } from './overlay-controls.js';
|
|
3
3
|
import { toggleTorchLight, mirrorVideo, switchCamera } from './camera.js';
|
|
4
|
+
import { ensurePackageUploaded } from './api.js';
|
|
4
5
|
import { createVideo } from '../components/video.js';
|
|
5
6
|
import { createBlurModal } from '../components/blurModal.js';
|
|
6
7
|
import { createDocumentModal } from '../components/documentModal.js';
|
|
@@ -88,7 +89,7 @@ const createSpecialtyOverlayOnReady = (overlayKey, createFn, options) => {
|
|
|
88
89
|
};
|
|
89
90
|
|
|
90
91
|
const getModalSubmitHandler = () => {
|
|
91
|
-
return () => {
|
|
92
|
+
return async () => {
|
|
92
93
|
hideVideoOverlay();
|
|
93
94
|
if (state.lensFlavor === 'anydocs') {
|
|
94
95
|
actions.handleAnydocPageCapture();
|
|
@@ -99,7 +100,8 @@ const getModalSubmitHandler = () => {
|
|
|
99
100
|
actions.handleChecksBackAccepted?.();
|
|
100
101
|
}
|
|
101
102
|
} else if (typeof state.customSubmitHandler === 'function') {
|
|
102
|
-
|
|
103
|
+
const packageInfo = await ensurePackageUploaded();
|
|
104
|
+
state.customSubmitHandler(state.finalImage, packageInfo);
|
|
103
105
|
} else {
|
|
104
106
|
state.submitHandler?.(state.finalImage);
|
|
105
107
|
}
|
package/flavors/upload.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createFileUpload } from '../components/createFileUpload.js';
|
|
2
2
|
import { createExitButton } from '../components/exitButton.js';
|
|
3
3
|
import { captureUploaded } from '../core/capture/document.js';
|
|
4
|
-
import { handleSubmit } from '../core/api.js';
|
|
4
|
+
import { docReady, handleSubmit, ensurePackageUploaded, fireResultSetter } from '../core/api.js';
|
|
5
5
|
import { removeOverlay } from '../core/lifecycle.js';
|
|
6
6
|
|
|
7
7
|
export const setup = async (state, refs, actions) => {
|
|
@@ -9,17 +9,37 @@ export const setup = async (state, refs, actions) => {
|
|
|
9
9
|
|
|
10
10
|
export const render = async (state, refs, actions) => {
|
|
11
11
|
if (!state.fileUpload) {
|
|
12
|
-
state.fileUpload = createFileUpload(state.container, captureUploaded, (result) => {
|
|
12
|
+
state.fileUpload = createFileUpload(state.container, captureUploaded, async (result) => {
|
|
13
13
|
const formattedResult = typeof result === 'string'
|
|
14
14
|
? { image: result, doc_type: 'receipt' }
|
|
15
15
|
: result;
|
|
16
16
|
|
|
17
17
|
if (!state.enableSubmit) {
|
|
18
18
|
state.debug_mode && console.log("Submit disabled, handling image directly");
|
|
19
|
-
state.
|
|
19
|
+
if (state.packageMode) {
|
|
20
|
+
// packageMode + !enableSubmit: upload the cumulative zip on capture so
|
|
21
|
+
// the showCamera setter receives bucket/package_path alongside image.
|
|
22
|
+
state.finalImage = formattedResult.image;
|
|
23
|
+
try {
|
|
24
|
+
state.docReadyResult = await docReady();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
state.debug_mode && console.error('docReady failed for gallery upload:', error);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const finalized = await fireResultSetter(formattedResult);
|
|
30
|
+
if (finalized) {
|
|
31
|
+
removeOverlay();
|
|
32
|
+
}
|
|
20
33
|
} else {
|
|
34
|
+
state.finalImage = formattedResult.image;
|
|
35
|
+
try {
|
|
36
|
+
state.docReadyResult = await docReady();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
state.debug_mode && console.error('docReady failed for gallery upload:', error);
|
|
39
|
+
}
|
|
21
40
|
if (typeof state.customSubmitHandler === 'function') {
|
|
22
|
-
|
|
41
|
+
const packageInfo = await ensurePackageUploaded();
|
|
42
|
+
state.customSubmitHandler(formattedResult.image, packageInfo);
|
|
23
43
|
} else {
|
|
24
44
|
handleSubmit(formattedResult.image);
|
|
25
45
|
}
|
package/package.json
CHANGED
package/utils/device-data.js
CHANGED
|
@@ -33,8 +33,8 @@ async function gatherBrowserData () {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
return {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
37
|
+
timezone_offset: new Date().getTimezoneOffset(),
|
|
38
38
|
screenSize: `${window.screen.width}x${window.screen.height}x${window.screen.colorDepth}`,
|
|
39
39
|
isCookiesEnabled: navigator.cookieEnabled,
|
|
40
40
|
domLocalStorage: typeof window.localStorage !== 'undefined',
|
package/veryfi-lens.js
CHANGED
|
@@ -74,6 +74,7 @@ const VeryfiLens = {
|
|
|
74
74
|
|
|
75
75
|
state.enforceFingerprint = config.enforceFingerprint ?? false;
|
|
76
76
|
state.disableFingerprint = config.disableFingerprint ?? false;
|
|
77
|
+
state.packageMode = config.packageMode ?? true;
|
|
77
78
|
|
|
78
79
|
} catch (error) {
|
|
79
80
|
console.error("Error initializing Lens:", error);
|