veryfi-lens-wasm 3.5.8 → 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 CHANGED
@@ -111,7 +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 uploads nothing: it fires the `showCamera` setter (checks: `{ frontImage, backImage, ...per-side LCD / front-back results }`; other flavors: `{ image }`), or calls `customSubmitHandler(image, null)` when set, then closes |
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 |
115
116
  | `enableFullScreen` | `boolean` | `false` | Enable fullscreen mode |
116
117
  | `debug_mode` | `boolean` | `false` | Enable console logging |
117
118
  | `useDevApi` | `boolean` | `false` | Route API requests to `lens-dev.veryfi.com` instead of production |
@@ -131,6 +132,7 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
131
132
  | `mirrorButton` | `boolean` | `true` | Show mirror/flip video button |
132
133
  | `mirrorOnDesktop` | `boolean` | `true` | Auto-mirror video on desktop (front-facing webcam) |
133
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"` |
134
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`) |
135
137
  | `onClose` | `function` | — | Callback when lens is closed |
136
138
  | `onCloseRedirectUrl` | `string` | — | URL to redirect to on close |
@@ -145,6 +147,8 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
145
147
  | `isDocumentModal` | `boolean` | `true` | Show modal when no document detected |
146
148
  | `isLcdModal` | `boolean` | `true` | Show modal when LCD/screen capture detected |
147
149
  | `isDesktopModeModal` | `boolean` | `true` | Show the modal asking mobile users to leave "Desktop site" mode |
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 |
148
152
  | `enforceDocumentDetection` | `boolean` | `false` | Block submission if no document detected |
149
153
  | `enforceBlurDetection` | `boolean` | `false` | Block submission if image is blurry |
150
154
  | `enforceLcdDetection` | `boolean` | `false` | Block submission if screen capture detected |
@@ -302,6 +306,11 @@ When `multiSubmission` is set or `maxDocuments` is not `1`, `init()` asks the ba
302
306
  | `documentModalMessage` | `string` | `"Oops, There appears to be no document on your image"` |
303
307
  | `blurModalMessage` | `string` | `"Oops, The image is too blurry to process"` |
304
308
  | `lcdModalMessage` | `string` | `"LCD screen detected. Please capture a printed document instead"` |
309
+ | `receiptGroupingModalMessage` | `string` | `"Several receipts were found. Are they part of one transaction?"` |
310
+ | `receiptGroupingOneTransactionText` | `string` | `"One transaction"` |
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"` |
305
314
  | `submitButtonText` | `string` | `"Submit Anyway"` |
306
315
  | `retakeButtonText` | `string` | `"Retake a picture"` |
307
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
+ };
@@ -0,0 +1,44 @@
1
+ import { createModal } from './modalBase.js';
2
+
3
+ export const createReceiptGroupingModal = (container, croppedImage, options = {}) => {
4
+ const defaults = {
5
+ message: 'Several receipts were found. Are they part of one transaction?',
6
+ oneTransactionText: 'One transaction',
7
+ separateText: 'Separate receipts',
8
+ };
9
+ const o = { ...defaults, ...options };
10
+
11
+ let pendingResolve = null;
12
+ const settle = (grouping) => {
13
+ const resolve = pendingResolve;
14
+ pendingResolve = null;
15
+ resolve?.(grouping);
16
+ };
17
+
18
+ const modal = createModal(container, {
19
+ id: 'veryfi-receipt-grouping-modal',
20
+ cssPrefix: 'receipt-grouping-modal',
21
+ message: o.message,
22
+ primaryButtonText: o.oneTransactionText,
23
+ primaryButtonId: 'veryfi-receipt-grouping-one',
24
+ secondaryButtonText: o.separateText,
25
+ secondaryButtonId: 'veryfi-receipt-grouping-separate',
26
+ onPrimaryClick: () => settle('one'),
27
+ onSecondaryClick: () => settle('separate'),
28
+ croppedImage,
29
+ useBackdrop: true,
30
+ primaryClearsCanvas: false,
31
+ showCropBorder: false,
32
+ });
33
+
34
+ return {
35
+ ...modal,
36
+ // Resolves with 'one' (all receipts are pages of one document) or
37
+ // 'separate' (each receipt is its own document).
38
+ ask: () => new Promise((resolve) => {
39
+ settle('separate');
40
+ pendingResolve = resolve;
41
+ modal.show();
42
+ }),
43
+ };
44
+ };
@@ -1,4 +1,7 @@
1
- export const createWatermark = (container) => {
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
- top: '50px',
51
- right: `${isDesktop ? '-240px' : '-200px'}`,
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/api.js CHANGED
@@ -112,10 +112,12 @@ export const buildJsonData = async () => {
112
112
  //
113
113
  // - isBase64 = true => JSON body { image: <base64>, json_data, client_id }
114
114
  // - isBase64 = false => multipart body { file: <Blob>, json_data, client_id }
115
+ // With sendCroppedImage = false the image/file is omitted and only metadata is sent.
115
116
  const sendCroppedLegacy = async ({ data, fileName, isBase64 }) => {
116
117
  const jsonData = await buildJsonData();
117
118
  const clientId = state.clientId;
118
119
  const sessionId = state.clientData?.session;
120
+ const includeImage = state.sendCroppedImage;
119
121
 
120
122
  const spinner = createSubmissionSpinner(MESSAGES.REVIEW_PREPARING);
121
123
  spinner.show();
@@ -129,13 +131,15 @@ const sendCroppedLegacy = async ({ data, fileName, isBase64 }) => {
129
131
  if (isBase64) {
130
132
  headers['Content-Type'] = 'application/json';
131
133
  body = JSON.stringify({
132
- image: data,
134
+ ...(includeImage ? { image: data } : {}),
133
135
  json_data: jsonData,
134
136
  client_id: clientId,
135
137
  });
136
138
  } else {
137
139
  const formData = new FormData();
138
- formData.append('file', data, fileName);
140
+ if (includeImage) {
141
+ formData.append('file', data, fileName);
142
+ }
139
143
  formData.append('json_data', JSON.stringify(jsonData));
140
144
  formData.append('client_id', clientId);
141
145
  body = formData;
@@ -304,7 +308,9 @@ export const fireResultSetter = async (payload, { autoUpload = true } = {}) => {
304
308
  // is passed explicitly because a session can hold several documents, each with
305
309
  // its own result; state.fieldDetectionResult is only the last one computed and
306
310
  // serves as the fallback for the legacy single-document path.
307
- export const handleSubmit = async (image, { fieldDetection } = {}) => {
311
+ // `fieldDetectionPages` holds one result per page (null where none) and is
312
+ // returned as field_detection_pages for multi-page documents.
313
+ export const handleSubmit = async (image, { fieldDetection, fieldDetectionPages } = {}) => {
308
314
  // Snapshot state into locals before any await — the submit button click handler
309
315
  // fires removeOverlay()/resetState() concurrently with this flow.
310
316
  const lensFlavor = state.lensFlavor;
@@ -327,6 +333,10 @@ export const handleSubmit = async (image, { fieldDetection } = {}) => {
327
333
  const localFieldDetection = resolvedFieldDetection
328
334
  ? structuredClone(resolvedFieldDetection)
329
335
  : null;
336
+ const localFieldDetectionPages =
337
+ Array.isArray(fieldDetectionPages) && fieldDetectionPages.length > 1 && fieldDetectionPages.some(Boolean)
338
+ ? structuredClone(fieldDetectionPages)
339
+ : null;
330
340
 
331
341
  state.submitInProgress = true;
332
342
  state.updateHandler?.({ status: 'submission_started' });
@@ -396,8 +406,9 @@ export const handleSubmit = async (image, { fieldDetection } = {}) => {
396
406
  state.updateHandler?.({ status: 'submission_completed' });
397
407
  const result = await response.json();
398
408
 
399
- if (shouldRunFieldDetection(lensFlavor) && documentFieldsToDetect.length && localFieldDetection) {
400
- result.field_detection = localFieldDetection;
409
+ if (shouldRunFieldDetection(lensFlavor) && documentFieldsToDetect.length) {
410
+ if (localFieldDetection) result.field_detection = localFieldDetection;
411
+ if (localFieldDetectionPages) result.field_detection_pages = localFieldDetectionPages;
401
412
  }
402
413
 
403
414
  if (successHandler && typeof successHandler === 'function') {
@@ -55,27 +55,48 @@ export const captureUploaded = async (imageFile) => {
55
55
  });
56
56
  };
57
57
 
58
+ // Ask whether the receipts found in one frame belong to one transaction.
59
+ // Without the modal (disabled, or a non-receipt flavor) they stay separate.
60
+ const askReceiptGrouping = async (count) => {
61
+ if (!state.receiptGroupingModal) return 'separate';
62
+ state.updateHandler?.({ status: 'receipt_grouping_prompted', count });
63
+ const grouping = await state.receiptGroupingModal.ask();
64
+ state.updateHandler?.({ status: 'receipt_grouping_selected', grouping, count });
65
+ return grouping;
66
+ };
67
+
58
68
  // Commit the capture plus any additional documents the segmenter found in the
59
69
  // same frame, tagging each page with its own quality issues so the gallery can
60
- // flag them individually.
70
+ // flag them individually. One transaction commits every crop as a page of a
71
+ // single document; separate commits each crop as its own document.
61
72
  const commitCaptureAndExtras = async () => {
62
73
  const { commitCaptureToReview } = await import('../review-flow.js');
63
- await commitCaptureToReview({
74
+ const extras = state.extraCropImages;
75
+ const primaryIssues = state.primaryCropIssues;
76
+ state.extraCropImages = [];
77
+ state.primaryCropIssues = [];
78
+
79
+ const grouping = extras.length ? await askReceiptGrouping(extras.length + 1) : 'separate';
80
+
81
+ const primaryPage = await commitCaptureToReview({
64
82
  kind: 'image',
65
83
  data: state.finalImage,
66
- issues: state.primaryCropIssues,
84
+ issues: primaryIssues,
67
85
  });
68
- for (const extra of state.extraCropImages) {
69
- if (!store.canAddDocument()) break;
70
- state.startNewDocumentOnCapture = true;
86
+ const isOneTransaction = grouping === 'one' && !!primaryPage;
87
+ if (isOneTransaction) store.extendPageLimit(extras.length);
88
+
89
+ for (const extra of extras) {
90
+ if (!isOneTransaction) {
91
+ if (!store.canAddDocument()) break;
92
+ state.startNewDocumentOnCapture = true;
93
+ }
71
94
  await commitCaptureToReview({
72
95
  kind: 'image',
73
96
  data: extra.data,
74
97
  issues: extra.issues,
75
98
  });
76
99
  }
77
- state.extraCropImages = [];
78
- state.primaryCropIssues = [];
79
100
  };
80
101
 
81
102
  export const handleDocumentAutoCaptureDone = async () => {
@@ -100,7 +100,17 @@ export const canAddDocument = () =>
100
100
  export const canAddPage = (docIndex = state.activeDocIndex) => {
101
101
  const doc = state.capturedDocs[docIndex];
102
102
  if (!doc) return false;
103
- return !state.maxPagesPerDocument || doc.pages.length < state.maxPagesPerDocument;
103
+ const limit = doc.maxPages ?? state.maxPagesPerDocument;
104
+ return !limit || doc.pages.length < limit;
105
+ };
106
+
107
+ // Let one document hold `count` more pages than it has now, regardless of
108
+ // maxPagesPerDocument. Used when several receipts in one frame are grouped
109
+ // into a single transaction.
110
+ export const extendPageLimit = (count, docIndex = state.activeDocIndex) => {
111
+ const doc = state.capturedDocs[docIndex];
112
+ if (!doc) return;
113
+ doc.maxPages = doc.pages.length + count;
104
114
  };
105
115
 
106
116
  // Append a new document and make it active. When the session is already at
@@ -218,6 +228,12 @@ export const documentFieldDetection = (docIndex) =>
218
228
  state.capturedDocs[docIndex]?.pages?.find((page) => page.fieldDetection)
219
229
  ?.fieldDetection ?? null;
220
230
 
231
+ // Per-page field-detection results for a document, in page order (null for a
232
+ // page without a result). Multi-page receipt documents (one transaction) carry
233
+ // one result per receipt.
234
+ export const documentPageFieldDetections = (docIndex) =>
235
+ (state.capturedDocs[docIndex]?.pages || []).map((page) => page.fieldDetection ?? null);
236
+
221
237
  // Produce the per-scan records consumed by api.uploadPackage()/sendCropped for
222
238
  // a single document: { data, fileName, isBase64, jsonData }.
223
239
  export const buildPackageScans = (docIndex) => {
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.8',
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)',
@@ -107,6 +107,11 @@ export const MESSAGES = {
107
107
  MULTI_CAPTURE_PROMPT: 'Do you need to capture another document?',
108
108
  MULTI_CAPTURE_YES: 'Capture another',
109
109
  MULTI_CAPTURE_NO: "No, I'm done",
110
+ RECEIPT_GROUPING_PROMPT: 'Several receipts were found. Are they part of one transaction?',
111
+ RECEIPT_GROUPING_ONE: 'One transaction',
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',
110
115
  REVIEW_TITLE: 'Review',
111
116
  REVIEW_ADD_PAGE: 'Add Page',
112
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
- state.finalImage = await getLongImage();
221
- if (state.finalImage) {
222
- hideVideoOverlay();
223
- state.longPreview?.hide?.();
224
- state.resultSetter?.(state.finalImage);
225
- state.docReadyResult = await docReady();
226
- await fireResultSetter({ ...state.docReadyResult, image: state.finalImage });
227
- const partnerDriven =
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
 
@@ -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 });
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 }) });
@@ -302,6 +304,7 @@ const submitOneDocument = async (docIndex) => {
302
304
  if (isChecks) state.resultSetter?.(checksExtra);
303
305
  return await handleSubmit(image, {
304
306
  fieldDetection: store.documentFieldDetection(docIndex),
307
+ fieldDetectionPages: store.documentPageFieldDetections(docIndex),
305
308
  });
306
309
  };
307
310
 
package/core/state.js CHANGED
@@ -90,8 +90,11 @@ export const state = {
90
90
  isDocumentModal: true,
91
91
  isLcdModal: true,
92
92
  isDesktopModeModal: true,
93
+ isReceiptGroupingModal: false,
94
+ isLongReceiptNoDocumentModal: true,
93
95
  container: null,
94
96
  exitButton: false,
97
+ watermarkPosition: 'top-right',
95
98
  showCameraPermissionDeniedMessage: true,
96
99
  cameraPermissionDeniedMessage: MESSAGES.CAMERA_PERMISSION_DENIED,
97
100
  onCloseRedirectUrl: null,
@@ -213,6 +216,8 @@ export const state = {
213
216
  lcdModal: null,
214
217
  anydocFlipModal: null,
215
218
  checkFlipModal: null,
219
+ receiptGroupingModal: null,
220
+ longReceiptNoDocumentModal: null,
216
221
  torchButtonRef: null,
217
222
  mirrorButtonRef: null,
218
223
  switchCameraButtonRef: null,
@@ -234,6 +239,11 @@ export const state = {
234
239
  documentModalMessage: MESSAGES.DOCUMENT_NOT_FOUND,
235
240
  blurModalMessage: MESSAGES.BLUR_DETECTED,
236
241
  lcdModalMessage: MESSAGES.LCD_DETECTED,
242
+ receiptGroupingModalMessage: MESSAGES.RECEIPT_GROUPING_PROMPT,
243
+ receiptGroupingOneTransactionText: MESSAGES.RECEIPT_GROUPING_ONE,
244
+ receiptGroupingSeparateText: MESSAGES.RECEIPT_GROUPING_SEPARATE,
245
+ longReceiptNoDocumentMessage: MESSAGES.LONG_RECEIPT_NO_DOCUMENT,
246
+ longReceiptNoDocumentRetryText: MESSAGES.LONG_RECEIPT_NO_DOCUMENT_RETRY,
237
247
  submitButtonText: MESSAGES.SUBMIT_ANYWAY,
238
248
  retakeButtonText: MESSAGES.RETAKE,
239
249
 
@@ -327,6 +337,7 @@ export const state = {
327
337
  customData: {},
328
338
 
329
339
  packageMode: false,
340
+ sendCroppedImage: false,
330
341
 
331
342
  enforceFingerprint: false,
332
343
  disableFingerprint: false,
@@ -380,6 +391,8 @@ export const resetState = () => {
380
391
  state.lcdModal = null;
381
392
  state.anydocFlipModal = null;
382
393
  state.checkFlipModal = null;
394
+ state.receiptGroupingModal = null;
395
+ state.longReceiptNoDocumentModal = null;
383
396
  state.frameRef = null;
384
397
  state.cropImgRef = null;
385
398
  state.videoRef = null;
@@ -13,6 +13,8 @@ import { createStitchingButton } from '../components/stitchingButton.js';
13
13
  import { createCreditCardComponent } from '../components/creditCard.js';
14
14
  import { createWrongSideModal } from '../components/wrongSideModal.js';
15
15
  import { createAnydocFlipModal } from '../components/anydocFlipModal.js';
16
+ import { createReceiptGroupingModal } from '../components/receiptGroupingModal.js';
17
+ import { createLongReceiptNoDocumentModal } from '../components/longReceiptNoDocumentModal.js';
16
18
  import { createWatermark } from '../components/watermark.js';
17
19
  import { createCardDataButton } from '../components/cardDataButton.js';
18
20
  import { createBottleCapOverlay } from '../components/bottleCapOverlay.js';
@@ -31,7 +33,9 @@ export const renderWatermarkIfNeeded = () => {
31
33
  if (state.clientData?.show_watermark) {
32
34
  state.debug_mode && console.log("Rendering watermark");
33
35
  if (!refs.watermarkComponent) {
34
- 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
+ });
35
39
  refs.watermarkComponent.show();
36
40
  }
37
41
  }
@@ -203,7 +207,9 @@ export const renderCreditCardIfNeeded = () => {
203
207
  }
204
208
 
205
209
  if (state.clientData?.show_watermark && !refs.watermarkComponent) {
206
- refs.watermarkComponent = createWatermark(state.cardOverlay.element);
210
+ refs.watermarkComponent = createWatermark(state.cardOverlay.element, {
211
+ position: state.watermarkPosition,
212
+ });
207
213
  refs.watermarkComponent.show();
208
214
  }
209
215
  };
@@ -325,6 +331,30 @@ export const renderModalsIfNeeded = () => {
325
331
  }
326
332
  );
327
333
  }
334
+
335
+ if (state.isReceiptGroupingModal && state.lensFlavor === 'document') {
336
+ state.receiptGroupingModal = createReceiptGroupingModal(
337
+ state.container,
338
+ state.croppedImage,
339
+ {
340
+ message: state.receiptGroupingModalMessage,
341
+ oneTransactionText: state.receiptGroupingOneTransactionText,
342
+ separateText: state.receiptGroupingSeparateText,
343
+ }
344
+ );
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
+ }
328
358
  };
329
359
 
330
360
  export const renderBottleCapOverlayIfNeeded = () => {
@@ -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
- 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
- }
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "3.5.8",
3
+ "version": "3.5.10",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",