veryfi-lens-wasm 3.5.7 → 3.5.9

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 |
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, images }` — `image` is the last page, `images` every page in order), or calls `customSubmitHandler(image, null)` when set, then closes |
115
+ | `sendCroppedImage` | `boolean` | `true` | 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 |
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 |
@@ -145,6 +146,7 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
145
146
  | `isDocumentModal` | `boolean` | `true` | Show modal when no document detected |
146
147
  | `isLcdModal` | `boolean` | `true` | Show modal when LCD/screen capture detected |
147
148
  | `isDesktopModeModal` | `boolean` | `true` | Show the modal asking mobile users to leave "Desktop site" mode |
149
+ | `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`) |
148
150
  | `enforceDocumentDetection` | `boolean` | `false` | Block submission if no document detected |
149
151
  | `enforceBlurDetection` | `boolean` | `false` | Block submission if image is blurry |
150
152
  | `enforceLcdDetection` | `boolean` | `false` | Block submission if screen capture detected |
@@ -170,7 +172,7 @@ VeryfiLens.onFailure((error) => { /* error occurred */ });
170
172
  | Option | Type | Default | Description |
171
173
  |---|---|---|---|
172
174
  | `captureBackOfCheck` | `boolean` | `false` | Enable back side capture |
173
- | `enforceBothSides` | `boolean` | `false` | Require both sides |
175
+ | `enforceBothSides` | `boolean` | `false` | Require both sides. After the front, shows `checkEnforcedModalMessage` with a Continue button that opens the camera for the back |
174
176
  | `enforceAndSkipBothSides` | `boolean` | `false` | Auto-proceed to back capture without prompt |
175
177
  | `delayBetweenCaptures` | `number` | `0` | Delay (ms) between front and back capture |
176
178
  | `frontBackDetectionForChecks` | `boolean` | `false` | Enable front/back side detection |
@@ -221,6 +223,9 @@ When `multiSubmission` is set or `maxDocuments` is not `1`, `init()` asks the ba
221
223
  | `reviewRetakeText` | `string` | `"Retake"` | Retake action text |
222
224
  | `reviewDeleteText` | `string` | `"Delete"` | Delete action text |
223
225
  | `reviewShowQualityBadges` | `boolean` | `true` | Badge pages that failed a quality check. Applies to multi-document frames, which are committed with the failing pages flagged instead of blocked |
226
+ | `reviewDownloadButton` | `boolean` | `true` | Show the Download action on the page toolbar |
227
+ | `reviewRotateButton` | `boolean` | `true` | Show the Rotate action on the page toolbar (images only) |
228
+ | `reviewCropButton` | `boolean` | `true` | Show the Crop action on the page toolbar (images only) |
224
229
  | `reviewIssueBlurText` | `string` | `"Blurry"` | Badge text for a blurry page |
225
230
  | `reviewIssueLcdText` | `string` | `"Screen"` | Badge text for a screen/LCD page |
226
231
  | `reviewSubmitButtonColor` | `string` | `"#00AA00"` | Submit button color (also used as the crop editor accent) |
@@ -299,6 +304,9 @@ When `multiSubmission` is set or `maxDocuments` is not `1`, `init()` asks the ba
299
304
  | `documentModalMessage` | `string` | `"Oops, There appears to be no document on your image"` |
300
305
  | `blurModalMessage` | `string` | `"Oops, The image is too blurry to process"` |
301
306
  | `lcdModalMessage` | `string` | `"LCD screen detected. Please capture a printed document instead"` |
307
+ | `receiptGroupingModalMessage` | `string` | `"Several receipts were found. Are they part of one transaction?"` |
308
+ | `receiptGroupingOneTransactionText` | `string` | `"One transaction"` |
309
+ | `receiptGroupingSeparateText` | `string` | `"Separate receipts"` |
302
310
  | `submitButtonText` | `string` | `"Submit Anyway"` |
303
311
  | `retakeButtonText` | `string` | `"Retake a picture"` |
304
312
  | `cameraPermissionDeniedMessage` | `string` | `"Camera access was blocked. Please allow camera access in your browser settings and try again."` |
@@ -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
+ };
@@ -96,11 +96,15 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
96
96
  submitButtonTextColor: options.submitButtonTextColor || '#FFFFFF',
97
97
  imageQuality: options.imageQuality || 0.97,
98
98
  pageAspectRatio: options.pageAspectRatio || '3 / 4',
99
+ pageObjectFit: options.pageObjectFit || 'cover',
99
100
  stackedPages: options.stackedPages === true,
100
101
  pageLabels: Array.isArray(options.pageLabels) ? options.pageLabels : null,
101
102
  allowAddPage: options.allowAddPage !== false,
102
103
  allowAddDocument: options.allowAddDocument !== false,
103
104
  showQualityBadges: options.showQualityBadges !== false,
105
+ showDownload: options.showDownload !== false,
106
+ showRotate: options.showRotate !== false,
107
+ showCrop: options.showCrop !== false,
104
108
  issueLabels: options.issueLabels || { blur: 'Blurry', lcd: 'Screen' },
105
109
  showDocumentStrip: options.showDocumentStrip !== false,
106
110
  showClose: options.showClose !== false,
@@ -994,7 +998,7 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
994
998
  justifyContent: 'stretch',
995
999
  cursor: 'pointer',
996
1000
  });
997
- const thumb = buildPageThumb(page, { objectFit: 'cover', borderRadius: '0' });
1001
+ const thumb = buildPageThumb(page, { objectFit: o.pageObjectFit, borderRadius: '0' });
998
1002
  thumb.style.pointerEvents = 'none';
999
1003
  if (thumb.tagName === 'VIDEO') thumb.controls = false;
1000
1004
  cell.appendChild(thumb);
@@ -1070,19 +1074,25 @@ export const createReviewGallery = (container, callbacks = {}, options = {}) =>
1070
1074
  if (!page) return;
1071
1075
 
1072
1076
  if (page.kind !== 'video') {
1073
- topBarRight.appendChild(
1074
- toolButton('rotate-cw', o.rotateText, async () => {
1075
- const data = await rotateImageData(page.data);
1076
- callbacks.onEditPage?.(activeIndex, detailIndex, data);
1077
- })
1078
- );
1079
- topBarRight.appendChild(
1080
- toolButton('crop', o.cropText, () =>
1081
- openCropEditor(page, (data) => callbacks.onEditPage?.(activeIndex, detailIndex, data))
1082
- )
1083
- );
1077
+ if (o.showRotate) {
1078
+ topBarRight.appendChild(
1079
+ toolButton('rotate-cw', o.rotateText, async () => {
1080
+ const data = await rotateImageData(page.data);
1081
+ callbacks.onEditPage?.(activeIndex, detailIndex, data);
1082
+ })
1083
+ );
1084
+ }
1085
+ if (o.showCrop) {
1086
+ topBarRight.appendChild(
1087
+ toolButton('crop', o.cropText, () =>
1088
+ openCropEditor(page, (data) => callbacks.onEditPage?.(activeIndex, detailIndex, data))
1089
+ )
1090
+ );
1091
+ }
1092
+ }
1093
+ if (o.showDownload) {
1094
+ topBarRight.appendChild(toolButton('download', o.downloadText, () => downloadPage(page)));
1084
1095
  }
1085
- topBarRight.appendChild(toolButton('download', o.downloadText, () => downloadPage(page)));
1086
1096
  topBarRight.appendChild(
1087
1097
  toolButton('refresh-cw', o.retakeText, () => callbacks.onRetakePage?.(activeIndex, detailIndex))
1088
1098
  );
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') {
@@ -2,7 +2,7 @@ import { state, refs } from '../state.js';
2
2
  import { cropWasm } from '../wasm-processing.js';
3
3
  import { checkIfDocumentOnCapture, checkIfBlurOnCapture, checkIfLcdOnCapture } from '../validation.js';
4
4
  import { showVideoOverlay } from '../overlay-controls.js';
5
- import { restartCameraForNextCapture } from '../lifecycle.js';
5
+ import { restartCameraForNextCapture, stopLens } from '../lifecycle.js';
6
6
  import * as store from '../capture-store.js';
7
7
  const syncCapturingSide = () => {
8
8
  if (state.recaptureTarget) {
@@ -54,6 +54,7 @@ export const captureChecks = async () => {
54
54
  state.frontImage = await cropWasm(state.testBlurDetection);
55
55
  }
56
56
  state.finalImage = state.frontImage;
57
+ stopLens();
57
58
 
58
59
  if (state.videoRef) state.videoRef.style.display = 'none';
59
60
  if (state.boxRef) state.boxRef.style.display = 'none';
@@ -145,6 +146,7 @@ export const captureChecks = async () => {
145
146
  state.backImage = await cropWasm(state.testBlurDetection);
146
147
  }
147
148
  state.finalImage = state.backImage;
149
+ stopLens();
148
150
 
149
151
  state.debug_mode && console.log("Back capture - Document detected:", state.isDocument);
150
152
  const isDocumentDetected = checkIfDocumentOnCapture();
@@ -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 () => {
@@ -184,9 +205,12 @@ export const newCapture = async () => {
184
205
  }
185
206
  break;
186
207
  case "checks": {
208
+ // captureChecks owns the whole checks capture (stop, validation, commit).
209
+ // It can restart the camera for the back side before returning, so the
210
+ // shared post-capture steps below must not run for checks.
187
211
  const { captureChecks } = await import('./checks.js');
188
212
  await captureChecks();
189
- break;
213
+ return null;
190
214
  }
191
215
  default:
192
216
  if (state.fullSizeImage && state.fullSizeImage.close) {
@@ -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.7',
42
+ SDK_VERSION: '3.5.9',
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,9 @@ 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',
110
113
  REVIEW_TITLE: 'Review',
111
114
  REVIEW_ADD_PAGE: 'Add Page',
112
115
  REVIEW_ADD_DOCUMENT: 'Add Document',
package/core/drawing.js CHANGED
@@ -151,9 +151,10 @@ export const drawContours = (input) => {
151
151
  ctx.restore();
152
152
 
153
153
  // Capture uses the first quad's true corners; the overlay keeps all quads
154
- // for multi-doc redraw.
154
+ // for multi-doc redraw. Store them unexpanded so a redraw doesn't
155
+ // re-expand the previous frame's box.
155
156
  setCoordinates(first);
156
- state.allCoordinates = expanded;
157
+ state.allCoordinates = quads;
157
158
  setHasCoordinates(true);
158
159
  } else {
159
160
  ctx.clearRect(0, 0, BoxCanvas.width, BoxCanvas.height);
@@ -29,6 +29,10 @@ import * as store from './capture-store.js';
29
29
  const isPartnerDriven = () =>
30
30
  state.packageMode && !state.enableSubmit && typeof state.customSubmitHandler !== 'function';
31
31
 
32
+ // enableSubmit:false without packageMode: the partner uploads the captures
33
+ // itself, so Submit only hands them over and nothing is sent to Veryfi.
34
+ const isLocalOnlySubmit = () => !state.enableSubmit && !state.packageMode;
35
+
32
36
  // Flavors that need a custom camera re-entry (restore their overlay/guide) set
33
37
  // actions.reviewRestart / actions.nextDocKind. Defaults suit the document flavor.
34
38
  const restartCamera = async () => {
@@ -62,6 +66,9 @@ const galleryOptions = () => ({
62
66
  submitButtonTextColor: state.reviewSubmitButtonTextColor || DEFAULTS.SUBMIT_BUTTON_TEXT_COLOR,
63
67
  imageQuality: state.imageQuality || DEFAULTS.IMAGE_QUALITY,
64
68
  showQualityBadges: state.reviewShowQualityBadges,
69
+ showDownload: state.reviewDownloadButton,
70
+ showRotate: state.reviewRotateButton,
71
+ showCrop: state.reviewCropButton,
65
72
  issueLabels: {
66
73
  blur: state.reviewIssueBlurText,
67
74
  lcd: state.reviewIssueLcdText,
@@ -75,6 +82,7 @@ const galleryOptions = () => ({
75
82
  ...(state.lensFlavor === 'checks' ? {
76
83
  stackedPages: true,
77
84
  pageAspectRatio: `${DEFAULTS.CHECK_ASPECT_RATIO} / 1`,
85
+ pageObjectFit: 'contain',
78
86
  pageLabels: ['Front', 'Back'],
79
87
  } : {}),
80
88
  });
@@ -128,6 +136,16 @@ const shouldAutoAdvanceCheckBack = () => {
128
136
  return (doc?.pages?.length || 0) === 1;
129
137
  };
130
138
 
139
+ // enforceBothSides: once the front is accepted, prompt to flip the check
140
+ // (checkEnforcedModalMessage) and reopen the camera for the back.
141
+ const shouldPromptCheckFlip = () => {
142
+ if (state.lensFlavor !== 'checks') return false;
143
+ if (!state.enforceBothSides) return false;
144
+ if (state.recaptureTarget) return false;
145
+ const doc = store.getActiveDoc();
146
+ return (doc?.pages?.length || 0) === 1;
147
+ };
148
+
131
149
  // Anydocs with anydocShowFlipMessage and a 2-page cap: after the first page,
132
150
  // skip the gallery and prompt to flip, then reopen the camera for page 2.
133
151
  const shouldAutoAdvanceAnydocBack = () => {
@@ -137,21 +155,27 @@ const shouldAutoAdvanceAnydocBack = () => {
137
155
  return (doc?.pages?.length || 0) === 1;
138
156
  };
139
157
 
140
- const promptAnydocFlip = () => {
141
- state.updateHandler?.({ status: 'anydoc_flip_prompted' });
142
- if (state.anydocFlipModal) {
143
- state.anydocFlipModal.show();
158
+ const promptFlip = (modal, status) => {
159
+ state.updateHandler?.({ status });
160
+ if (modal) {
161
+ modal.show();
144
162
  return;
145
163
  }
146
164
  goToCamera();
147
165
  };
148
166
 
149
- export const continueAnydocFlip = async () => {
150
- state.anydocFlipModal?.hide();
151
- state.updateHandler?.({ status: 'anydoc_flip_continued' });
167
+ const continueFlip = async (modal, status) => {
168
+ modal?.hide();
169
+ state.updateHandler?.({ status });
152
170
  await goToCamera();
153
171
  };
154
172
 
173
+ export const continueAnydocFlip = () =>
174
+ continueFlip(state.anydocFlipModal, 'anydoc_flip_continued');
175
+
176
+ export const continueCheckFlip = () =>
177
+ continueFlip(state.checkFlipModal, 'capture_back_side_required');
178
+
155
179
  const closeReview = () => {
156
180
  if (typeof state.onClose === 'function') state.onClose(false);
157
181
  if (state.onCloseRedirectUrl) window.location.href = state.onCloseRedirectUrl;
@@ -225,6 +249,25 @@ const submitOneDocument = async (docIndex) => {
225
249
  });
226
250
  }
227
251
 
252
+ // Checks preserve their legacy setter contract: a single payload keyed by
253
+ // front/back (images + per-side LCD and front/back-detection results). The
254
+ // front image is what partner handlers receive (parity with the pre-gallery
255
+ // handleChecksBackAccepted path).
256
+ const isChecks = state.lensFlavor === 'checks';
257
+ const checksExtra = isChecks ? buildChecksExtra(doc) : null;
258
+ const setterImage = isChecks ? (doc.pages[0]?.data ?? null) : image;
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
+
228
271
  // Rebuild the per-document package buffer from the store so deletes/retakes
229
272
  // are reflected, and give each document its own package identity.
230
273
  if (state.packageMode) {
@@ -243,14 +286,6 @@ const submitOneDocument = async (docIndex) => {
243
286
  }
244
287
  }
245
288
 
246
- // Checks preserve their legacy setter contract: a single payload keyed by
247
- // front/back (images + per-side LCD and front/back-detection results). The
248
- // front image is what partner handlers receive (parity with the pre-gallery
249
- // handleChecksBackAccepted path).
250
- const isChecks = state.lensFlavor === 'checks';
251
- const checksExtra = isChecks ? buildChecksExtra(doc) : null;
252
- const setterImage = isChecks ? (doc.pages[0]?.data ?? null) : image;
253
-
254
289
  if (isPartnerDriven()) {
255
290
  const packageInfo = await ensurePackageUploaded();
256
291
  state.resultSetter?.({ ...(packageInfo || {}), ...(checksExtra || { image: originalData }) });
@@ -267,6 +302,7 @@ const submitOneDocument = async (docIndex) => {
267
302
  if (isChecks) state.resultSetter?.(checksExtra);
268
303
  return await handleSubmit(image, {
269
304
  fieldDetection: store.documentFieldDetection(docIndex),
305
+ fieldDetectionPages: store.documentPageFieldDetections(docIndex),
270
306
  });
271
307
  };
272
308
 
@@ -412,9 +448,17 @@ export const commitCaptureToReview = async ({ kind = 'image', data, isBase64 = k
412
448
  return page;
413
449
  }
414
450
 
451
+ if (shouldPromptCheckFlip()) {
452
+ state.recaptureTarget = null;
453
+ hideVideoOverlay();
454
+ state.cropImgRef?.setCheckDisplay?.();
455
+ promptFlip(state.checkFlipModal, 'capture_back_side');
456
+ return page;
457
+ }
458
+
415
459
  if (shouldAutoAdvanceAnydocBack()) {
416
460
  state.recaptureTarget = null;
417
- promptAnydocFlip();
461
+ promptFlip(state.anydocFlipModal, 'anydoc_flip_prompted');
418
462
  return page;
419
463
  }
420
464
 
package/core/state.js CHANGED
@@ -90,6 +90,7 @@ export const state = {
90
90
  isDocumentModal: true,
91
91
  isLcdModal: true,
92
92
  isDesktopModeModal: true,
93
+ isReceiptGroupingModal: false,
93
94
  container: null,
94
95
  exitButton: false,
95
96
  showCameraPermissionDeniedMessage: true,
@@ -165,6 +166,9 @@ export const state = {
165
166
  reviewRetakeText: MESSAGES.REVIEW_RETAKE,
166
167
  reviewDeleteText: MESSAGES.REVIEW_DELETE,
167
168
  reviewShowQualityBadges: true,
169
+ reviewDownloadButton: true,
170
+ reviewRotateButton: true,
171
+ reviewCropButton: true,
168
172
  reviewIssueBlurText: MESSAGES.REVIEW_ISSUE_BLUR,
169
173
  reviewIssueLcdText: MESSAGES.REVIEW_ISSUE_LCD,
170
174
  reviewSubmitButtonColor: DEFAULTS.SUBMIT_BUTTON_COLOR,
@@ -209,6 +213,8 @@ export const state = {
209
213
  documentModal: null,
210
214
  lcdModal: null,
211
215
  anydocFlipModal: null,
216
+ checkFlipModal: null,
217
+ receiptGroupingModal: null,
212
218
  torchButtonRef: null,
213
219
  mirrorButtonRef: null,
214
220
  switchCameraButtonRef: null,
@@ -230,6 +236,9 @@ export const state = {
230
236
  documentModalMessage: MESSAGES.DOCUMENT_NOT_FOUND,
231
237
  blurModalMessage: MESSAGES.BLUR_DETECTED,
232
238
  lcdModalMessage: MESSAGES.LCD_DETECTED,
239
+ receiptGroupingModalMessage: MESSAGES.RECEIPT_GROUPING_PROMPT,
240
+ receiptGroupingOneTransactionText: MESSAGES.RECEIPT_GROUPING_ONE,
241
+ receiptGroupingSeparateText: MESSAGES.RECEIPT_GROUPING_SEPARATE,
233
242
  submitButtonText: MESSAGES.SUBMIT_ANYWAY,
234
243
  retakeButtonText: MESSAGES.RETAKE,
235
244
 
@@ -323,6 +332,7 @@ export const state = {
323
332
  customData: {},
324
333
 
325
334
  packageMode: false,
335
+ sendCroppedImage: false,
326
336
 
327
337
  enforceFingerprint: false,
328
338
  disableFingerprint: false,
@@ -375,6 +385,8 @@ export const resetState = () => {
375
385
  state.documentModal = null;
376
386
  state.lcdModal = null;
377
387
  state.anydocFlipModal = null;
388
+ state.checkFlipModal = null;
389
+ state.receiptGroupingModal = null;
378
390
  state.frameRef = null;
379
391
  state.cropImgRef = null;
380
392
  state.videoRef = null;
@@ -13,6 +13,7 @@ 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';
16
17
  import { createWatermark } from '../components/watermark.js';
17
18
  import { createCardDataButton } from '../components/cardDataButton.js';
18
19
  import { createBottleCapOverlay } from '../components/bottleCapOverlay.js';
@@ -310,6 +311,33 @@ export const renderModalsIfNeeded = () => {
310
311
  }
311
312
  );
312
313
  }
314
+
315
+ if (state.enforceBothSides && !state.enforceAndSkipBothSides && state.lensFlavor === 'checks') {
316
+ state.checkFlipModal = createAnydocFlipModal(
317
+ state.container,
318
+ state.croppedImage,
319
+ async () => {
320
+ const { continueCheckFlip } = await import('./review-flow.js');
321
+ await continueCheckFlip();
322
+ },
323
+ {
324
+ message: state.checkEnforcedModalMessage,
325
+ continueText: state.checkContinueButtonText,
326
+ }
327
+ );
328
+ }
329
+
330
+ if (state.isReceiptGroupingModal && state.lensFlavor === 'document') {
331
+ state.receiptGroupingModal = createReceiptGroupingModal(
332
+ state.container,
333
+ state.croppedImage,
334
+ {
335
+ message: state.receiptGroupingModalMessage,
336
+ oneTransactionText: state.receiptGroupingOneTransactionText,
337
+ separateText: state.receiptGroupingSeparateText,
338
+ }
339
+ );
340
+ }
313
341
  };
314
342
 
315
343
  export const renderBottleCapOverlayIfNeeded = () => {
@@ -125,6 +125,7 @@ export function logLongDocument(stitcherResult, corners, nDocs, preview) {
125
125
  state.previewData = preview;
126
126
  state.shouldUpdatePreview = stitcherResult === 0;
127
127
  state.isDocument = corners.length > 0 && stitcherResult === 0;
128
+ drawContours(state.coordinates.length === 4 ? [state.coordinates] : []);
128
129
  }
129
130
 
130
131
  export const logCard = (status, name, number, date, cvv) => {
@@ -393,7 +394,16 @@ const applyOrientationCorrection = async (cropOut) => {
393
394
  const prediction = refs.wasmWrapper.classifyOrientation(bmp);
394
395
  bmp.close();
395
396
  if (!prediction) return cropOut;
396
- const correction = (360 - prediction.angle) % 360;
397
+ let { angle } = prediction;
398
+ // Checks are always landscape: a landscape crop may only flip 180°, a portrait
399
+ // crop must turn 90° — the classifier just picks the direction.
400
+ if (state.lensFlavor === 'checks') {
401
+ const { probs } = prediction;
402
+ angle = outputWidth >= outputHeight
403
+ ? (probs[2] > probs[0] ? 180 : 0)
404
+ : (probs[3] > probs[1] ? 270 : 90);
405
+ }
406
+ const correction = (360 - angle) % 360;
397
407
  state.debug_mode && console.log(`[Orient] detected=${prediction.angle}° correcting by ${correction}° probs=${prediction.probs.map(p => p.toFixed(3)).join(',')}`);
398
408
  if (correction === 0) return cropOut;
399
409
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "3.5.7",
3
+ "version": "3.5.9",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",