scandoc-ai-components 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/dist/index.js +56 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11195,6 +11195,20 @@ class ExtractorVideo {
11195
11195
  this.waitingForSecondSide = false;
11196
11196
  this.hasShownTurnMessage = false;
11197
11197
  this.turnMessageTimer = null;
11198
+
11199
+ // DEBUG: detect overwrites
11200
+ Object.defineProperty(this, "onExtractedResults", {
11201
+ configurable: true,
11202
+ get: () => this.__onExtractedResults,
11203
+ set: v => {
11204
+ console.log("[ScanDocAI] onExtractedResults set to:", v, "type:", typeof v);
11205
+ console.trace("[ScanDocAI] onExtractedResults overwrite stack");
11206
+ this.__onExtractedResults = v;
11207
+ }
11208
+ });
11209
+
11210
+ // initialize through setter so we see the first set too:
11211
+ this.onExtractedResults = onExtractedResults;
11198
11212
  }
11199
11213
  reset() {
11200
11214
  this.stopVideo();
@@ -11246,6 +11260,17 @@ class ExtractorVideo {
11246
11260
  if (images.length < ExtractorVideo.VALIDATION_BATCH_SIZE) return;
11247
11261
  const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_3__["default"])(images.map(e => e.validationImg), this.pastBlurValues, {});
11248
11262
  if (!isValidationOk) {
11263
+ const msg = Array.isArray(response) ? response.join(", ") : String(response || "");
11264
+ if (msg.toLowerCase().includes("token expired/invalid")) {
11265
+ this.stopVideo();
11266
+ this.showMessage("Token expired/invalid. Please provide a new token.", true);
11267
+ this.onExtractedResults({
11268
+ success: false,
11269
+ code: "004",
11270
+ info: "Token expired/invalid."
11271
+ });
11272
+ return;
11273
+ }
11249
11274
  this.candidateImages = [];
11250
11275
  return;
11251
11276
  }
@@ -11293,6 +11318,19 @@ class ExtractorVideo {
11293
11318
  this.hasShownTurnMessage = false;
11294
11319
  this.showMessage("Validation successful", true);
11295
11320
  const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(this.extractionImages["FRONT"], this.extractionImages["BACK"], false);
11321
+ if (!isExtractionOk) {
11322
+ const msg = Array.isArray(extractionData) ? extractionData.join(", ") : String(extractionData || "");
11323
+ if (msg.toLowerCase().includes("token expired/invalid")) {
11324
+ this.stopVideo();
11325
+ this.showMessage("Token expired/invalid. Please provide a new token.", true);
11326
+ this.onExtractedResults({
11327
+ success: false,
11328
+ code: "004",
11329
+ info: "Token expired/invalid."
11330
+ });
11331
+ return;
11332
+ }
11333
+ }
11296
11334
  this.onExtraction(isExtractionOk, extractionData);
11297
11335
  return;
11298
11336
  }
@@ -11303,6 +11341,19 @@ class ExtractorVideo {
11303
11341
  this.showMessage("Extracting data");
11304
11342
  const image = images[imageId].fullImg;
11305
11343
  const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(image, undefined, true);
11344
+ if (!isExtractionOk) {
11345
+ const msg = Array.isArray(extractionData) ? extractionData.join(", ") : String(extractionData || "");
11346
+ if (msg.toLowerCase().includes("token expired/invalid")) {
11347
+ this.stopVideo();
11348
+ this.showMessage("Token expired/invalid. Please provide a new token.", true);
11349
+ this.onExtractedResults({
11350
+ success: false,
11351
+ code: "004",
11352
+ info: "Token expired/invalid."
11353
+ });
11354
+ return;
11355
+ }
11356
+ }
11306
11357
  this.onExtraction(isExtractionOk, extractionData);
11307
11358
  return;
11308
11359
  }
@@ -11633,6 +11684,8 @@ function getExtractionVideo(tokenOrCallback, maybeCallback) {
11633
11684
  // If called again, update callback too
11634
11685
  if (typeof cb === "function") {
11635
11686
  EXTRACTION_VIDEO.onExtractedResults = cb;
11687
+ } else if (cb !== undefined) {
11688
+ console.warn("Ignoring non-function callback passed to getExtractionVideo:", cb);
11636
11689
  }
11637
11690
  return EXTRACTION_VIDEO;
11638
11691
  }
@@ -12038,7 +12091,7 @@ async function callDocumentExtraction(frontImage, backImage, ignoreBackImage) {
12038
12091
  const response = await fetch(`${cfgValues.SCAN_APP_URL}extraction/`, {
12039
12092
  method: "POST",
12040
12093
  headers: {
12041
- Authorization: await serviceConfig.getAccessToken(true),
12094
+ Authorization: await serviceConfig.getAccessToken(false),
12042
12095
  Accept: "application/json",
12043
12096
  "Content-Type": "application/json"
12044
12097
  },
@@ -12065,8 +12118,7 @@ async function callDocumentExtraction(frontImage, backImage, ignoreBackImage) {
12065
12118
  }
12066
12119
  //
12067
12120
  if (response.status === 401 || response.status === 403) {
12068
- errors = ["Token expired/invalid"];
12069
- await serviceConfig.refreshTokens();
12121
+ return [false, ["Token expired/invalid"]];
12070
12122
  } else {
12071
12123
  const data = await response.json();
12072
12124
  errors = data.Errors ?? (data.detail ? [data.detail] : ["Backend error, but no details provided!"]);
@@ -12149,8 +12201,7 @@ async function callDocumentValidation(images, blur_values) {
12149
12201
  }
12150
12202
  //
12151
12203
  if (response.status === 401 || response.status === 403) {
12152
- errors = ["Token expired/invalid"];
12153
- await serviceConfig.refreshTokens();
12204
+ return [false, ["Token expired/invalid"]];
12154
12205
  } else {
12155
12206
  const data = await response.json();
12156
12207
  errors = data.Errors ?? (data.detail ? [data.detail] : ["Backend error, but no details provided!"]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "scandoc-ai-components",
3
3
  "author": "ScanDoc-AI",
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "private": false,
6
6
  "description": "Pure JavaScript package for integrating ScanDoc-AI services.",
7
7
  "keywords": [