veryfi-lens-wasm 3.5.9 → 3.5.10
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 +6 -2
- package/components/longReceiptNoDocumentModal.js +22 -0
- package/components/watermark.js +9 -3
- package/core/constants.js +3 -1
- package/core/lifecycle.js +38 -22
- package/core/review-flow.js +13 -11
- package/core/state.js +6 -0
- package/core/ui-renderer.js +19 -2
- package/core/wasm-processing.js +3 -0
- package/flavors/upload.js +8 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,8 +111,8 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
|
|
|
111
111
|
| `lensFlavor` | `string` | — | **Required.** Capture mode (see [Supported Flavors](#supported-flavors)) |
|
|
112
112
|
| `container` | `string` | — | ID of an HTML element to render into. If omitted, creates a fullscreen overlay |
|
|
113
113
|
| `theme` | `"light"\|"dark"\|"system"` | `"system"` | UI color theme. `"system"` follows OS changes while the lens is open |
|
|
114
|
-
| `enableSubmit` | `boolean` | `true` | Show submit button after capture. With `false` (and `packageMode: false`) the review gallery's Submit
|
|
115
|
-
| `sendCroppedImage` | `boolean` | `
|
|
114
|
+
| `enableSubmit` | `boolean` | `true` | Show submit button after capture. With `false` (and `packageMode: false`) the review gallery's Submit does not call `/api/document`: it still posts each page to `/rest/send-cropped` (fires `document_ready`; metadata only unless `sendCroppedImage` is `true`), then fires the `showCamera` setter (checks: `{ frontImage, backImage, ...per-side LCD / front-back results }`; other flavors: `{ image, images }` — `image` is the last page, `images` every page in order), or calls `customSubmitHandler(image, null)` when set, then closes |
|
|
115
|
+
| `sendCroppedImage` | `boolean` | `false` | Include the captured image in the per-capture `/rest/send-cropped` request (`packageMode: false` only). With `false` only metadata is sent; the image is still sent to `/api/document` on submit. The request (and `document_ready`) is always made either way |
|
|
116
116
|
| `enableFullScreen` | `boolean` | `false` | Enable fullscreen mode |
|
|
117
117
|
| `debug_mode` | `boolean` | `false` | Enable console logging |
|
|
118
118
|
| `useDevApi` | `boolean` | `false` | Route API requests to `lens-dev.veryfi.com` instead of production |
|
|
@@ -132,6 +132,7 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
|
|
|
132
132
|
| `mirrorButton` | `boolean` | `true` | Show mirror/flip video button |
|
|
133
133
|
| `mirrorOnDesktop` | `boolean` | `true` | Auto-mirror video on desktop (front-facing webcam) |
|
|
134
134
|
| `exitButton` | `boolean` | `false` | Show exit/close button |
|
|
135
|
+
| `watermarkPosition` | `string` | `"top-right"` | Corner for the "Powered by Veryfi" watermark (when enabled for the client): `"top-right"`, `"top-left"`, `"bottom-right"`, `"bottom-left"` |
|
|
135
136
|
| `showCameraPermissionDeniedMessage` | `boolean` | `true` | Show the in-lens message when camera access is denied. Set `false` to render it on your own error screen. A denial always hides every on-camera control and is reported via `onUpdate` as `{ status: "camera_permission_denied", message, error }` (never via `onFailure`) |
|
|
136
137
|
| `onClose` | `function` | — | Callback when lens is closed |
|
|
137
138
|
| `onCloseRedirectUrl` | `string` | — | URL to redirect to on close |
|
|
@@ -147,6 +148,7 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
|
|
|
147
148
|
| `isLcdModal` | `boolean` | `true` | Show modal when LCD/screen capture detected |
|
|
148
149
|
| `isDesktopModeModal` | `boolean` | `true` | Show the modal asking mobile users to leave "Desktop site" mode |
|
|
149
150
|
| `isReceiptGroupingModal` | `boolean` | `false` | When a receipt (`document` flavor) frame contains several receipts, ask whether they are one transaction (submitted as one multi-page document) or separate receipts (one document each). With `false` they are always separate. Only applies when multiple documents are allowed (`multiSubmission` or `maxDocuments` other than `1`) |
|
|
151
|
+
| `isLongReceiptNoDocumentModal` | `boolean` | `true` | Long receipt (`long_document` flavor): when Stop is pressed but nothing was stitched, tell the user to hold the receipt closer and press Start only after the green box appears. Always fires `stitching_failed`; `failureHandler` is called only when this modal is disabled |
|
|
150
152
|
| `enforceDocumentDetection` | `boolean` | `false` | Block submission if no document detected |
|
|
151
153
|
| `enforceBlurDetection` | `boolean` | `false` | Block submission if image is blurry |
|
|
152
154
|
| `enforceLcdDetection` | `boolean` | `false` | Block submission if screen capture detected |
|
|
@@ -307,6 +309,8 @@ When `multiSubmission` is set or `maxDocuments` is not `1`, `init()` asks the ba
|
|
|
307
309
|
| `receiptGroupingModalMessage` | `string` | `"Several receipts were found. Are they part of one transaction?"` |
|
|
308
310
|
| `receiptGroupingOneTransactionText` | `string` | `"One transaction"` |
|
|
309
311
|
| `receiptGroupingSeparateText` | `string` | `"Separate receipts"` |
|
|
312
|
+
| `longReceiptNoDocumentMessage` | `string` | `"We could not detect the receipt. Hold the receipt closer to the camera and press Start only after you see a green box around it."` |
|
|
313
|
+
| `longReceiptNoDocumentRetryText` | `string` | `"Try again"` |
|
|
310
314
|
| `submitButtonText` | `string` | `"Submit Anyway"` |
|
|
311
315
|
| `retakeButtonText` | `string` | `"Retake a picture"` |
|
|
312
316
|
| `cameraPermissionDeniedMessage` | `string` | `"Camera access was blocked. Please allow camera access in your browser settings and try again."` |
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createModal } from './modalBase.js';
|
|
2
|
+
|
|
3
|
+
export const createLongReceiptNoDocumentModal = (container, croppedImage, onRetry, options = {}) => {
|
|
4
|
+
const defaults = {
|
|
5
|
+
message: 'We could not detect the receipt. Hold the receipt closer to the camera and press Start only after you see a green box around it.',
|
|
6
|
+
retryText: 'Try again',
|
|
7
|
+
};
|
|
8
|
+
const o = { ...defaults, ...options };
|
|
9
|
+
|
|
10
|
+
return createModal(container, {
|
|
11
|
+
id: 'veryfi-long-receipt-no-document-modal',
|
|
12
|
+
cssPrefix: 'long-receipt-no-document-modal',
|
|
13
|
+
message: o.message,
|
|
14
|
+
primaryButtonText: o.retryText,
|
|
15
|
+
primaryButtonId: 'veryfi-long-receipt-no-document-retry',
|
|
16
|
+
onPrimaryClick: onRetry,
|
|
17
|
+
croppedImage,
|
|
18
|
+
useBackdrop: true,
|
|
19
|
+
primaryClearsCanvas: false,
|
|
20
|
+
showCropBorder: false,
|
|
21
|
+
});
|
|
22
|
+
};
|
package/components/watermark.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const WATERMARK_POSITIONS = ['top-right', 'top-left', 'bottom-right', 'bottom-left'];
|
|
2
|
+
|
|
3
|
+
export const createWatermark = (container, options = {}) => {
|
|
4
|
+
const position = WATERMARK_POSITIONS.includes(options.position) ? options.position : 'top-right';
|
|
2
5
|
const watermark = document.createElement('div');
|
|
3
6
|
watermark.id = 'veryfi-watermark';
|
|
4
7
|
|
|
@@ -44,11 +47,14 @@ export const createWatermark = (container) => {
|
|
|
44
47
|
`;
|
|
45
48
|
|
|
46
49
|
const isDesktop = window.innerWidth > 768;
|
|
50
|
+
const horizontalOffset = isDesktop ? '-240px' : '-200px';
|
|
51
|
+
const [vertical, horizontal] = position.split('-');
|
|
47
52
|
|
|
48
53
|
Object.assign(watermark.style, {
|
|
49
54
|
position: 'absolute',
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
// Bottom positions sit above the bottom control row (capture/torch/exit buttons).
|
|
56
|
+
[vertical]: vertical === 'top' ? '50px' : '120px',
|
|
57
|
+
[horizontal]: horizontalOffset,
|
|
52
58
|
zIndex: '999',
|
|
53
59
|
pointerEvents: 'auto',
|
|
54
60
|
opacity: '0.9'
|
package/core/constants.js
CHANGED
|
@@ -39,7 +39,7 @@ export const setApiBaseUrl = (base) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
export const DEFAULTS = {
|
|
42
|
-
SDK_VERSION: '3.5.
|
|
42
|
+
SDK_VERSION: '3.5.10',
|
|
43
43
|
BLUR_THRESHOLD: 0.7,
|
|
44
44
|
LCD_THRESHOLD: 0.5,
|
|
45
45
|
BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
|
|
@@ -110,6 +110,8 @@ export const MESSAGES = {
|
|
|
110
110
|
RECEIPT_GROUPING_PROMPT: 'Several receipts were found. Are they part of one transaction?',
|
|
111
111
|
RECEIPT_GROUPING_ONE: 'One transaction',
|
|
112
112
|
RECEIPT_GROUPING_SEPARATE: 'Separate receipts',
|
|
113
|
+
LONG_RECEIPT_NO_DOCUMENT: 'We could not detect the receipt. Hold the receipt closer to the camera and press Start only after you see a green box around it.',
|
|
114
|
+
LONG_RECEIPT_NO_DOCUMENT_RETRY: 'Try again',
|
|
113
115
|
REVIEW_TITLE: 'Review',
|
|
114
116
|
REVIEW_ADD_PAGE: 'Add Page',
|
|
115
117
|
REVIEW_ADD_DOCUMENT: 'Add Document',
|
package/core/lifecycle.js
CHANGED
|
@@ -217,29 +217,45 @@ export const stopStitching = async () => {
|
|
|
217
217
|
state.isStitchingProcess = false;
|
|
218
218
|
state.stitchingButton.setStitching(false);
|
|
219
219
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
state.packageMode && !state.enableSubmit && typeof state.customSubmitHandler !== 'function';
|
|
229
|
-
state.submitButton = createSubmitButton(
|
|
230
|
-
state.videoOverlay.overlay,
|
|
231
|
-
() => {
|
|
232
|
-
if (!partnerDriven) {
|
|
233
|
-
handleSubmit(state.finalImage);
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
() => actions.removeOverlay(),
|
|
237
|
-
{ buttonText: partnerDriven ? 'Done' : 'Submit' }
|
|
238
|
-
);
|
|
239
|
-
(state.enableSubmit || partnerDriven) && state.submitButton.show();
|
|
240
|
-
holdSubmitForFieldDetectionIfNeeded();
|
|
241
|
-
void onCropPreviewReady();
|
|
220
|
+
// With nothing stitched (no document detected between Start and Stop) the
|
|
221
|
+
// WASM stitcher throws a raw C++ exception pointer instead of returning an
|
|
222
|
+
// empty image.
|
|
223
|
+
let longImage = null;
|
|
224
|
+
try {
|
|
225
|
+
longImage = await getLongImage();
|
|
226
|
+
} catch (error) {
|
|
227
|
+
state.debug_mode && console.log('[STITCHING] getLongImage failed:', error);
|
|
242
228
|
}
|
|
229
|
+
state.finalImage = longImage;
|
|
230
|
+
if (!state.finalImage) {
|
|
231
|
+
state.updateHandler?.({ status: 'stitching_failed' });
|
|
232
|
+
if (state.longReceiptNoDocumentModal) {
|
|
233
|
+
state.longReceiptNoDocumentModal.show();
|
|
234
|
+
} else {
|
|
235
|
+
state.failureHandler?.(new Error('No document was captured while stitching'));
|
|
236
|
+
}
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
hideVideoOverlay();
|
|
240
|
+
state.longPreview?.hide?.();
|
|
241
|
+
state.resultSetter?.(state.finalImage);
|
|
242
|
+
state.docReadyResult = await docReady();
|
|
243
|
+
await fireResultSetter({ ...state.docReadyResult, image: state.finalImage });
|
|
244
|
+
const partnerDriven =
|
|
245
|
+
state.packageMode && !state.enableSubmit && typeof state.customSubmitHandler !== 'function';
|
|
246
|
+
state.submitButton = createSubmitButton(
|
|
247
|
+
state.videoOverlay.overlay,
|
|
248
|
+
() => {
|
|
249
|
+
if (!partnerDriven) {
|
|
250
|
+
handleSubmit(state.finalImage);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
() => actions.removeOverlay(),
|
|
254
|
+
{ buttonText: partnerDriven ? 'Done' : 'Submit' }
|
|
255
|
+
);
|
|
256
|
+
(state.enableSubmit || partnerDriven) && state.submitButton.show();
|
|
257
|
+
holdSubmitForFieldDetectionIfNeeded();
|
|
258
|
+
void onCropPreviewReady();
|
|
243
259
|
state.updateHandler?.({ status: 'stitching_completed' });
|
|
244
260
|
};
|
|
245
261
|
|
package/core/review-flow.js
CHANGED
|
@@ -257,17 +257,6 @@ const submitOneDocument = async (docIndex) => {
|
|
|
257
257
|
const checksExtra = isChecks ? buildChecksExtra(doc) : null;
|
|
258
258
|
const setterImage = isChecks ? (doc.pages[0]?.data ?? null) : image;
|
|
259
259
|
|
|
260
|
-
if (isLocalOnlySubmit()) {
|
|
261
|
-
const hasHandler = typeof state.customSubmitHandler === 'function';
|
|
262
|
-
if (isChecks) {
|
|
263
|
-
state.resultSetter?.(checksExtra);
|
|
264
|
-
} else if (!hasHandler) {
|
|
265
|
-
state.resultSetter?.({ image: originalData, images: doc.pages.map((page) => page.data) });
|
|
266
|
-
}
|
|
267
|
-
if (hasHandler) state.customSubmitHandler(setterImage, null);
|
|
268
|
-
return null;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
260
|
// Rebuild the per-document package buffer from the store so deletes/retakes
|
|
272
261
|
// are reflected, and give each document its own package identity.
|
|
273
262
|
if (state.packageMode) {
|
|
@@ -286,6 +275,19 @@ const submitOneDocument = async (docIndex) => {
|
|
|
286
275
|
}
|
|
287
276
|
}
|
|
288
277
|
|
|
278
|
+
// document_ready (/rest/send-cropped above) always fires; only the
|
|
279
|
+
// /api/document submit is left to the partner.
|
|
280
|
+
if (isLocalOnlySubmit()) {
|
|
281
|
+
const hasHandler = typeof state.customSubmitHandler === 'function';
|
|
282
|
+
if (isChecks) {
|
|
283
|
+
state.resultSetter?.(checksExtra);
|
|
284
|
+
} else if (!hasHandler) {
|
|
285
|
+
state.resultSetter?.({ image: originalData, images: doc.pages.map((page) => page.data) });
|
|
286
|
+
}
|
|
287
|
+
if (hasHandler) state.customSubmitHandler(setterImage, null);
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
|
|
289
291
|
if (isPartnerDriven()) {
|
|
290
292
|
const packageInfo = await ensurePackageUploaded();
|
|
291
293
|
state.resultSetter?.({ ...(packageInfo || {}), ...(checksExtra || { image: originalData }) });
|
package/core/state.js
CHANGED
|
@@ -91,8 +91,10 @@ export const state = {
|
|
|
91
91
|
isLcdModal: true,
|
|
92
92
|
isDesktopModeModal: true,
|
|
93
93
|
isReceiptGroupingModal: false,
|
|
94
|
+
isLongReceiptNoDocumentModal: true,
|
|
94
95
|
container: null,
|
|
95
96
|
exitButton: false,
|
|
97
|
+
watermarkPosition: 'top-right',
|
|
96
98
|
showCameraPermissionDeniedMessage: true,
|
|
97
99
|
cameraPermissionDeniedMessage: MESSAGES.CAMERA_PERMISSION_DENIED,
|
|
98
100
|
onCloseRedirectUrl: null,
|
|
@@ -215,6 +217,7 @@ export const state = {
|
|
|
215
217
|
anydocFlipModal: null,
|
|
216
218
|
checkFlipModal: null,
|
|
217
219
|
receiptGroupingModal: null,
|
|
220
|
+
longReceiptNoDocumentModal: null,
|
|
218
221
|
torchButtonRef: null,
|
|
219
222
|
mirrorButtonRef: null,
|
|
220
223
|
switchCameraButtonRef: null,
|
|
@@ -239,6 +242,8 @@ export const state = {
|
|
|
239
242
|
receiptGroupingModalMessage: MESSAGES.RECEIPT_GROUPING_PROMPT,
|
|
240
243
|
receiptGroupingOneTransactionText: MESSAGES.RECEIPT_GROUPING_ONE,
|
|
241
244
|
receiptGroupingSeparateText: MESSAGES.RECEIPT_GROUPING_SEPARATE,
|
|
245
|
+
longReceiptNoDocumentMessage: MESSAGES.LONG_RECEIPT_NO_DOCUMENT,
|
|
246
|
+
longReceiptNoDocumentRetryText: MESSAGES.LONG_RECEIPT_NO_DOCUMENT_RETRY,
|
|
242
247
|
submitButtonText: MESSAGES.SUBMIT_ANYWAY,
|
|
243
248
|
retakeButtonText: MESSAGES.RETAKE,
|
|
244
249
|
|
|
@@ -387,6 +392,7 @@ export const resetState = () => {
|
|
|
387
392
|
state.anydocFlipModal = null;
|
|
388
393
|
state.checkFlipModal = null;
|
|
389
394
|
state.receiptGroupingModal = null;
|
|
395
|
+
state.longReceiptNoDocumentModal = null;
|
|
390
396
|
state.frameRef = null;
|
|
391
397
|
state.cropImgRef = null;
|
|
392
398
|
state.videoRef = null;
|
package/core/ui-renderer.js
CHANGED
|
@@ -14,6 +14,7 @@ import { createCreditCardComponent } from '../components/creditCard.js';
|
|
|
14
14
|
import { createWrongSideModal } from '../components/wrongSideModal.js';
|
|
15
15
|
import { createAnydocFlipModal } from '../components/anydocFlipModal.js';
|
|
16
16
|
import { createReceiptGroupingModal } from '../components/receiptGroupingModal.js';
|
|
17
|
+
import { createLongReceiptNoDocumentModal } from '../components/longReceiptNoDocumentModal.js';
|
|
17
18
|
import { createWatermark } from '../components/watermark.js';
|
|
18
19
|
import { createCardDataButton } from '../components/cardDataButton.js';
|
|
19
20
|
import { createBottleCapOverlay } from '../components/bottleCapOverlay.js';
|
|
@@ -32,7 +33,9 @@ export const renderWatermarkIfNeeded = () => {
|
|
|
32
33
|
if (state.clientData?.show_watermark) {
|
|
33
34
|
state.debug_mode && console.log("Rendering watermark");
|
|
34
35
|
if (!refs.watermarkComponent) {
|
|
35
|
-
refs.watermarkComponent = createWatermark(state.videoOverlay ? state.videoOverlay.overlay : state.container
|
|
36
|
+
refs.watermarkComponent = createWatermark(state.videoOverlay ? state.videoOverlay.overlay : state.container, {
|
|
37
|
+
position: state.watermarkPosition,
|
|
38
|
+
});
|
|
36
39
|
refs.watermarkComponent.show();
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -204,7 +207,9 @@ export const renderCreditCardIfNeeded = () => {
|
|
|
204
207
|
}
|
|
205
208
|
|
|
206
209
|
if (state.clientData?.show_watermark && !refs.watermarkComponent) {
|
|
207
|
-
refs.watermarkComponent = createWatermark(state.cardOverlay.element
|
|
210
|
+
refs.watermarkComponent = createWatermark(state.cardOverlay.element, {
|
|
211
|
+
position: state.watermarkPosition,
|
|
212
|
+
});
|
|
208
213
|
refs.watermarkComponent.show();
|
|
209
214
|
}
|
|
210
215
|
};
|
|
@@ -338,6 +343,18 @@ export const renderModalsIfNeeded = () => {
|
|
|
338
343
|
}
|
|
339
344
|
);
|
|
340
345
|
}
|
|
346
|
+
|
|
347
|
+
if (state.isLongReceiptNoDocumentModal && state.lensFlavor === 'long_document') {
|
|
348
|
+
state.longReceiptNoDocumentModal = createLongReceiptNoDocumentModal(
|
|
349
|
+
state.container,
|
|
350
|
+
state.croppedImage,
|
|
351
|
+
() => {},
|
|
352
|
+
{
|
|
353
|
+
message: state.longReceiptNoDocumentMessage,
|
|
354
|
+
retryText: state.longReceiptNoDocumentRetryText,
|
|
355
|
+
}
|
|
356
|
+
);
|
|
357
|
+
}
|
|
341
358
|
};
|
|
342
359
|
|
|
343
360
|
export const renderBottleCapOverlayIfNeeded = () => {
|
package/core/wasm-processing.js
CHANGED
|
@@ -360,6 +360,9 @@ export const sendCardWasm = async () => {
|
|
|
360
360
|
|
|
361
361
|
export const getLongImage = async () => {
|
|
362
362
|
const wasmOutput = await refs.wasmWrapper.getStitchedImage();
|
|
363
|
+
if (!wasmOutput?.outputWidth || !wasmOutput?.outputHeight) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
363
366
|
const { data, blurLevel, outputHeight, outputWidth } = wasmOutput;
|
|
364
367
|
const width = outputWidth;
|
|
365
368
|
const height = outputHeight;
|
package/flavors/upload.js
CHANGED
|
@@ -16,15 +16,14 @@ export const render = async (state, refs, actions) => {
|
|
|
16
16
|
|
|
17
17
|
if (!state.enableSubmit) {
|
|
18
18
|
state.debug_mode && console.log("Submit disabled, handling image directly");
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
19
|
+
// document_ready always fires: packageMode queues the scan for the
|
|
20
|
+
// cumulative zip (uploaded by fireResultSetter so the setter receives
|
|
21
|
+
// bucket/package_path); legacy mode posts /rest/send-cropped now.
|
|
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);
|
|
28
27
|
}
|
|
29
28
|
const finalized = await fireResultSetter(formattedResult);
|
|
30
29
|
if (finalized) {
|