veryfi-lens-wasm 3.5.5 → 3.5.6

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
@@ -235,6 +235,9 @@ When `multiSubmission` is set or `maxDocuments` is not `1`, `init()` asks the ba
235
235
  | `anydocMaxPages` | `number\|null` | `null` | _Deprecated:_ alias for `maxPagesPerDocument` |
236
236
  | `anydocAddPageText` | `string` | `"Add Page"` | _Deprecated:_ alias for `reviewAddPageText` |
237
237
  | `anydocSubmitText` | `string` | `"Submit"` | _Deprecated:_ alias for `reviewSubmitText` |
238
+ | `anydocShowFlipMessage` | `boolean` | `false` | After the first page of a two-page capture, show "flip the document" and go straight to capturing the second side (skips the gallery until both pages exist). Only runs when `maxPagesPerDocument` is `2`; if this is on and no page cap is set, the cap is set to `2` |
239
+ | `anydocFlipMessageText` | `string` | `"Please flip the document and capture the other side"` | Flip-prompt message |
240
+ | `anydocFlipContinueText` | `string` | `"Continue"` | Flip-prompt continue button |
238
241
  | `anydocShowGuide` | `boolean` | `false` | Show a dismissible on-screen text guide explaining how to capture. Auto-hides after each page capture and reappears when the camera restarts for the next page |
239
242
  | `anydocGuideText` | `string` | `"Position the document within the frame..."` | Guide text shown for anydocs capture. Separate steps with a blank line (`\n\n`) — each becomes a numbered step |
240
243
  | `anydocGuideTitle` | `string` | `"Steps to Capture"` | Heading of the anydocs capture guide panel |
@@ -0,0 +1,22 @@
1
+ import { createModal } from './modalBase.js';
2
+
3
+ export const createAnydocFlipModal = (container, croppedImage, onContinue, options = {}) => {
4
+ const defaults = {
5
+ message: 'Please flip the document and capture the other side',
6
+ continueText: 'Continue',
7
+ };
8
+ const o = { ...defaults, ...options };
9
+
10
+ return createModal(container, {
11
+ id: 'veryfi-anydoc-flip-modal',
12
+ cssPrefix: 'anydoc-flip-modal',
13
+ message: o.message,
14
+ primaryButtonText: o.continueText,
15
+ primaryButtonId: 'veryfi-anydoc-flip-continue',
16
+ onPrimaryClick: onContinue,
17
+ croppedImage,
18
+ useBackdrop: true,
19
+ primaryClearsCanvas: false,
20
+ showCropBorder: false,
21
+ });
22
+ };
@@ -46,6 +46,7 @@ export const createModal = (container, {
46
46
  useBackdrop = false,
47
47
  primaryClearsCanvas = true,
48
48
  secondaryHidesBorder = true,
49
+ showCropBorder = true,
49
50
  messageElementId,
50
51
  styles,
51
52
  }) => {
@@ -234,7 +235,11 @@ export const createModal = (container, {
234
235
  messageElement.innerHTML = context.message.replace(/</g, '&lt;').replace(/>/g, '&gt;');
235
236
  }
236
237
  modal.style.display = 'flex';
237
- showBorder();
238
+ if (showCropBorder) {
239
+ showBorder();
240
+ } else {
241
+ hideBorder();
242
+ }
238
243
  },
239
244
  hide: () => {
240
245
  modal.style.display = 'none';
@@ -53,6 +53,8 @@ export const createSpinner = (container, message) => {
53
53
  spinnerOverlay.appendChild(messageElement);
54
54
  container.appendChild(spinnerOverlay);
55
55
 
56
+ let removed = false;
57
+
56
58
  return {
57
59
  show: () => {
58
60
  spinnerOverlay.style.display = 'flex';
@@ -61,7 +63,9 @@ export const createSpinner = (container, message) => {
61
63
  spinnerOverlay.style.display = 'none';
62
64
  },
63
65
  remove: () => {
64
- container.removeChild(spinnerOverlay);
66
+ if (removed) return;
67
+ removed = true;
68
+ spinnerOverlay.remove();
65
69
  releaseSpinKeyframes();
66
70
  },
67
71
  updateMessage: (newMessage) => {
package/core/api.js CHANGED
@@ -470,11 +470,16 @@ export const finishBatch = async () => {
470
470
  };
471
471
 
472
472
  export const fetchBlueprints = async () => {
473
+ const clientId = state.clientId;
474
+ const sessionId = state.clientData?.session;
475
+ const qrSessionId = getQrSessionId();
473
476
  const requestOptions = {
474
477
  method: 'POST',
475
478
  headers: {
476
479
  'Content-Type': 'application/json',
477
- 'CLIENT-ID': state.clientId,
480
+ 'CLIENT-ID': clientId,
481
+ ...(sessionId ? { 'SESSION-ID': sessionId } : {}),
482
+ ...(qrSessionId ? { 'QR-SESSION-ID': qrSessionId } : {}),
478
483
  },
479
484
  body: JSON.stringify({
480
485
  client_name: state.clientData.client_name
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.5',
42
+ SDK_VERSION: '3.5.6',
43
43
  BLUR_THRESHOLD: 0.7,
44
44
  LCD_THRESHOLD: 0.5,
45
45
  BOX_COLOR: 'rgba(84, 192, 139, 0.6)',
@@ -96,9 +96,24 @@ const applyChecksSubmitGate = () => {
96
96
  }
97
97
  };
98
98
 
99
+ // Two-page anydocs (insurance cards, etc.): Submit stays disabled until the
100
+ // second side exists, same as checks with enforceBothSides.
101
+ const isAnydocTwoPageFlip = () =>
102
+ state.lensFlavor === 'anydocs'
103
+ && !!state.anydocShowFlipMessage
104
+ && state.maxPagesPerDocument === 2;
105
+
106
+ const applyAnydocFlipSubmitGate = () => {
107
+ if (!isAnydocTwoPageFlip()) return;
108
+ if ((store.getActiveDoc()?.pages?.length || 0) < 2) {
109
+ state.reviewGalleryRef?.setSubmitting(true);
110
+ }
111
+ };
112
+
99
113
  const refreshGallery = () => {
100
114
  state.reviewGalleryRef?.render(galleryPayload());
101
115
  applyChecksSubmitGate();
116
+ applyAnydocFlipSubmitGate();
102
117
  };
103
118
 
104
119
  // enforceAndSkipBothSides: once the front is accepted, skip the gallery and go
@@ -113,6 +128,30 @@ const shouldAutoAdvanceCheckBack = () => {
113
128
  return (doc?.pages?.length || 0) === 1;
114
129
  };
115
130
 
131
+ // Anydocs with anydocShowFlipMessage and a 2-page cap: after the first page,
132
+ // skip the gallery and prompt to flip, then reopen the camera for page 2.
133
+ const shouldAutoAdvanceAnydocBack = () => {
134
+ if (!isAnydocTwoPageFlip()) return false;
135
+ if (state.recaptureTarget) return false;
136
+ const doc = store.getActiveDoc();
137
+ return (doc?.pages?.length || 0) === 1;
138
+ };
139
+
140
+ const promptAnydocFlip = () => {
141
+ state.updateHandler?.({ status: 'anydoc_flip_prompted' });
142
+ if (state.anydocFlipModal) {
143
+ state.anydocFlipModal.show();
144
+ return;
145
+ }
146
+ goToCamera();
147
+ };
148
+
149
+ export const continueAnydocFlip = async () => {
150
+ state.anydocFlipModal?.hide();
151
+ state.updateHandler?.({ status: 'anydoc_flip_continued' });
152
+ await goToCamera();
153
+ };
154
+
116
155
  const closeReview = () => {
117
156
  if (typeof state.onClose === 'function') state.onClose(false);
118
157
  if (state.onCloseRedirectUrl) window.location.href = state.onCloseRedirectUrl;
@@ -135,6 +174,31 @@ const buildChecksExtra = (doc) => {
135
174
  };
136
175
  };
137
176
 
177
+ // Legacy /api/document takes a single `image` base64 field. One page stays a
178
+ // JPEG; multiple pages (or a video Blob) must be a zip, or only the last page
179
+ // would be processed. Filenames match the pre-gallery anydocs/checks submit.
180
+ const zipScansForLegacySubmit = async (scans, { flavor, lastPage }) => {
181
+ const { default: JSZip } = await import('jszip');
182
+ const zip = new JSZip();
183
+ scans.forEach((scan, index) => {
184
+ const isBlob = scan.data instanceof Blob;
185
+ let fileName;
186
+ if (isBlob) {
187
+ const type = scan.data.type || lastPage?.data?.type || '';
188
+ const ext = type.includes('mp4') ? 'mp4'
189
+ : type.includes('quicktime') ? 'mov'
190
+ : 'webm';
191
+ fileName = lastPage?.fileName || scan.fileName || `prescription_label.${ext}`;
192
+ } else if (flavor === 'checks') {
193
+ fileName = index === 0 ? 'front.jpg' : index === 1 ? 'back.jpg' : `page_${index + 1}.jpg`;
194
+ } else {
195
+ fileName = `page_${index + 1}.jpg`;
196
+ }
197
+ zip.file(fileName, scan.data, isBlob ? {} : { base64: true });
198
+ });
199
+ return zip.generateAsync({ type: 'base64' });
200
+ };
201
+
138
202
  const submitOneDocument = async (docIndex) => {
139
203
  const doc = state.capturedDocs[docIndex];
140
204
  const scans = store.buildPackageScans(docIndex);
@@ -147,17 +211,18 @@ const submitOneDocument = async (docIndex) => {
147
211
 
148
212
  // Legacy (packageMode:false) posts an inline image to /api/document. A video
149
213
  // Blob can't be JSON-serialized, so zip+base64 it (parity with the pre-store
150
- // prescription_label submitVideoBlob path). packageMode:true ignores `image`
151
- // (it sends package_path), so no conversion is needed there.
214
+ // prescription_label submitVideoBlob path). Multiple stills must also be
215
+ // zipped — otherwise only the last page is OCR'd. packageMode:true ignores
216
+ // `image` (it sends package_path), so no conversion is needed there.
152
217
  let image = originalData;
153
- if (!state.packageMode && lastPage.kind === 'video' && image instanceof Blob) {
154
- const ext = image.type.includes('mp4') ? 'mp4'
155
- : image.type.includes('quicktime') ? 'mov'
156
- : 'webm';
157
- const { default: JSZip } = await import('jszip');
158
- const zip = new JSZip();
159
- zip.file(lastPage.fileName || `prescription_label.${ext}`, image);
160
- image = await zip.generateAsync({ type: 'base64' });
218
+ const needsLegacyZip = !state.packageMode && (
219
+ scans.length > 1 || (lastPage.kind === 'video' && image instanceof Blob)
220
+ );
221
+ if (needsLegacyZip) {
222
+ image = await zipScansForLegacySubmit(scans, {
223
+ flavor: state.lensFlavor,
224
+ lastPage,
225
+ });
161
226
  }
162
227
 
163
228
  // Rebuild the per-document package buffer from the store so deletes/retakes
@@ -184,7 +249,7 @@ const submitOneDocument = async (docIndex) => {
184
249
  // handleChecksBackAccepted path).
185
250
  const isChecks = state.lensFlavor === 'checks';
186
251
  const checksExtra = isChecks ? buildChecksExtra(doc) : null;
187
- const setterImage = isChecks ? (doc.pages[0]?.data ?? null) : originalData;
252
+ const setterImage = isChecks ? (doc.pages[0]?.data ?? null) : image;
188
253
 
189
254
  if (isPartnerDriven()) {
190
255
  const packageInfo = await ensurePackageUploaded();
@@ -296,6 +361,7 @@ const openGallery = () => {
296
361
  const gallery = ensureReviewGallery(galleryCallbacks(), galleryOptions());
297
362
  gallery?.show(galleryPayload());
298
363
  applyChecksSubmitGate();
364
+ applyAnydocFlipSubmitGate();
299
365
  };
300
366
 
301
367
  export const handleCameraExit = () => {
@@ -346,6 +412,12 @@ export const commitCaptureToReview = async ({ kind = 'image', data, isBase64 = k
346
412
  return page;
347
413
  }
348
414
 
415
+ if (shouldAutoAdvanceAnydocBack()) {
416
+ state.recaptureTarget = null;
417
+ promptAnydocFlip();
418
+ return page;
419
+ }
420
+
349
421
  openGallery();
350
422
 
351
423
  // Field detection (documentFieldsToDetect) runs on this page's own image: the
package/core/state.js CHANGED
@@ -208,6 +208,7 @@ export const state = {
208
208
  blurModal: null,
209
209
  documentModal: null,
210
210
  lcdModal: null,
211
+ anydocFlipModal: null,
211
212
  torchButtonRef: null,
212
213
  mirrorButtonRef: null,
213
214
  switchCameraButtonRef: null,
@@ -373,6 +374,7 @@ export const resetState = () => {
373
374
  state.blurModal = null;
374
375
  state.documentModal = null;
375
376
  state.lcdModal = null;
377
+ state.anydocFlipModal = null;
376
378
  state.frameRef = null;
377
379
  state.cropImgRef = null;
378
380
  state.videoRef = null;
@@ -12,6 +12,7 @@ import { createVideoOverlay } from '../components/videoOverlay.js';
12
12
  import { createStitchingButton } from '../components/stitchingButton.js';
13
13
  import { createCreditCardComponent } from '../components/creditCard.js';
14
14
  import { createWrongSideModal } from '../components/wrongSideModal.js';
15
+ import { createAnydocFlipModal } from '../components/anydocFlipModal.js';
15
16
  import { createWatermark } from '../components/watermark.js';
16
17
  import { createCardDataButton } from '../components/cardDataButton.js';
17
18
  import { createBottleCapOverlay } from '../components/bottleCapOverlay.js';
@@ -294,6 +295,21 @@ export const renderModalsIfNeeded = () => {
294
295
  );
295
296
  state.debug_mode && console.log("Wrong side modal created:", !!state.wrongSideModal);
296
297
  }
298
+
299
+ if (state.anydocShowFlipMessage && state.lensFlavor === 'anydocs') {
300
+ state.anydocFlipModal = createAnydocFlipModal(
301
+ state.container,
302
+ state.croppedImage,
303
+ async () => {
304
+ const { continueAnydocFlip } = await import('./review-flow.js');
305
+ await continueAnydocFlip();
306
+ },
307
+ {
308
+ message: state.anydocFlipMessageText,
309
+ continueText: state.anydocFlipContinueText,
310
+ }
311
+ );
312
+ }
297
313
  };
298
314
 
299
315
  export const renderBottleCapOverlayIfNeeded = () => {
@@ -16,6 +16,11 @@ export const setup = async (state, refs, actions) => {
16
16
  // unless anydocMaxPages/maxPagesPerDocument caps it), single document unless
17
17
  // the partner enables multi-document capture via multiSubmission/maxDocuments.
18
18
  if (state.maxDocuments == null) state.maxDocuments = state.multiSubmission ? null : 1;
19
+ // Flip-then-capture-the-back is a two-page flow. When the partner turns it
20
+ // on without setting a page cap, lock the document at 2 pages.
21
+ if (state.anydocShowFlipMessage && state.maxPagesPerDocument == null) {
22
+ state.maxPagesPerDocument = 2;
23
+ }
19
24
  // Carry the anydoc-specific page controls labels onto the review gallery so
20
25
  // partners that customized anydocAddPageText/anydocSubmitText keep them.
21
26
  state.reviewAddPageText = state.anydocAddPageText;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfi-lens-wasm",
3
- "version": "3.5.5",
3
+ "version": "3.5.6",
4
4
  "description": "Lens For Web SDK with WASM",
5
5
  "main": "veryfi-lens.js",
6
6
  "type": "module",
package/veryfi-lens.js CHANGED
@@ -228,6 +228,10 @@ const VeryfiLens = {
228
228
 
229
229
  await flavorModule.render(state, refs, actions);
230
230
 
231
+ // Flavor render can tear the session down (e.g. anydocs blueprint
232
+ // cancel → removeOverlay()/resetState()). Don't keep initializing.
233
+ if (!state.hasInit) return;
234
+
231
235
  if (!state.started && state.lensFlavor !== 'caps' && state.lensFlavor !== 'code_strips' && state.lensFlavor !== 'prescription_label') {
232
236
  state.debug_mode && console.log("Starting lens");
233
237
  await newStartLens();