scandoc-ai-components 0.0.85 → 0.0.87

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 +97 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11160,7 +11160,9 @@ __webpack_require__.r(__webpack_exports__);
11160
11160
  /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../config */ "./src/lib/config.js");
11161
11161
  /* harmony import */ var _requests_extraction__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../requests/extraction */ "./src/lib/requests/extraction.js");
11162
11162
  /* harmony import */ var _requests_validation__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../requests/validation */ "./src/lib/requests/validation.js");
11163
- /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./utils */ "./src/lib/components/utils.js");
11163
+ /* harmony import */ var _requests_error_logging__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../requests/error_logging */ "./src/lib/requests/error_logging.js");
11164
+ /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./utils */ "./src/lib/components/utils.js");
11165
+
11164
11166
 
11165
11167
 
11166
11168
 
@@ -11193,7 +11195,7 @@ class ExtractorVideo {
11193
11195
  this.lastMessage = null;
11194
11196
  this.waitingForSecondSide = false;
11195
11197
  this.hasShownTurnMessage = false;
11196
- this.awaitingNewPresence = false;
11198
+ this.turnMessageTimer = null;
11197
11199
  }
11198
11200
  reset() {
11199
11201
  this.stopVideo();
@@ -11209,7 +11211,8 @@ class ExtractorVideo {
11209
11211
  this.lastMessage = null;
11210
11212
  this.waitingForSecondSide = false;
11211
11213
  this.hasShownTurnMessage = false;
11212
- this.awaitingNewPresence = false;
11214
+ clearTimeout(this.turnMessageTimer);
11215
+ this.turnMessageTimer = null;
11213
11216
  }
11214
11217
  async analyzeVideoStream() {
11215
11218
  if (!this.isRunning) return;
@@ -11232,12 +11235,9 @@ class ExtractorVideo {
11232
11235
  setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
11233
11236
  return;
11234
11237
  }
11235
- const fullImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, 1280, 720, false);
11236
- const validationImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, ExtractorVideo.VALIDATION_IMG_WIDTH, ExtractorVideo.VALIDATION_IMG_HEIGHT, true);
11238
+ const fullImage = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.videoImgToBase64)(video, canvas, 1280, 720, false);
11239
+ const validationImage = (0,_utils__WEBPACK_IMPORTED_MODULE_5__.videoImgToBase64)(video, canvas, ExtractorVideo.VALIDATION_IMG_WIDTH, ExtractorVideo.VALIDATION_IMG_HEIGHT, true);
11237
11240
  DOCUMENT_DETECTOR.isDocumentPresent(video).then(async isPresent => {
11238
- if (this.awaitingNewPresence && isPresent) {
11239
- this.awaitingNewPresence = false;
11240
- }
11241
11241
  if (!isPresent) return;
11242
11242
  this.candidateImages.push({
11243
11243
  fullImg: fullImage,
@@ -11250,12 +11250,22 @@ class ExtractorVideo {
11250
11250
  this.candidateImages = [];
11251
11251
  return;
11252
11252
  }
11253
+ if (!isValidationOk) {
11254
+ const isDocUnsupported = response?.InfoCode === "1006";
11255
+ const transactionId = response?.TransactionID;
11256
+ if (isDocUnsupported && transactionId && this.candidateImages.length > 0) {
11257
+ const frontImage = this.candidateImages[this.candidateImages.length - 1].fullImg;
11258
+ await (0,_requests_error_logging__WEBPACK_IMPORTED_MODULE_4__["default"])(frontImage, "", transactionId);
11259
+ this.showMessage("Unsupported document. Logged issue.");
11260
+ }
11261
+ this.candidateImages = [];
11262
+ return;
11263
+ }
11253
11264
  const infoCode = response["InfoCode"];
11254
11265
  const imageId = response["Index"];
11255
11266
  const imageSide = response["Side"];
11256
11267
  const message = response["Info"];
11257
11268
  const isNewSide = this.extractionImages[imageSide] === undefined;
11258
- const numScannedSides = Object.keys(this.extractionImages).length;
11259
11269
  if (!this.waitingForSecondSide || isNewSide) {
11260
11270
  this.showMessage(message);
11261
11271
  }
@@ -11273,13 +11283,19 @@ class ExtractorVideo {
11273
11283
  if (Object.keys(this.extractionImages).length === 1) {
11274
11284
  this.waitingForSecondSide = true;
11275
11285
  this.hasShownTurnMessage = true;
11276
- this.awaitingNewPresence = true;
11277
11286
  this.scanStartTime = Date.now();
11278
11287
  this.showMessage("Turn to the other side", true);
11288
+
11289
+ // Clear lock after 3 seconds
11290
+ clearTimeout(this.turnMessageTimer);
11291
+ this.turnMessageTimer = setTimeout(() => {
11292
+ this.hasShownTurnMessage = false;
11293
+ this.waitingForSecondSide = false;
11294
+ this.lastMessage = null; // allow same message again later
11295
+ }, 3000);
11279
11296
  } else if (Object.keys(this.extractionImages).length === 2) {
11280
11297
  this.waitingForSecondSide = false;
11281
11298
  this.hasShownTurnMessage = false;
11282
- this.awaitingNewPresence = false;
11283
11299
  this.showMessage("Validation successful", true);
11284
11300
  const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(this.extractionImages["FRONT"], this.extractionImages["BACK"], {
11285
11301
  IgnoreBackImage: false
@@ -11290,7 +11306,6 @@ class ExtractorVideo {
11290
11306
  } else if (infoCode === "1000") {
11291
11307
  this.waitingForSecondSide = false;
11292
11308
  this.hasShownTurnMessage = false;
11293
- this.awaitingNewPresence = false;
11294
11309
  this.showMessage("Validation successful");
11295
11310
  this.showMessage("Extracting data");
11296
11311
  const image = images[imageId].fullImg;
@@ -11307,7 +11322,7 @@ class ExtractorVideo {
11307
11322
  }
11308
11323
  showMessage(message, force = false) {
11309
11324
  if (!message || this.lastMessage === message) return;
11310
- if (this.hasShownTurnMessage && this.awaitingNewPresence && !force) return;
11325
+ if (this.waitingForSecondSide && !force) return;
11311
11326
  this.lastMessage = message;
11312
11327
  const messageElement = document.getElementById("ScanDocAIMessage");
11313
11328
  if (messageElement) {
@@ -11317,6 +11332,8 @@ class ExtractorVideo {
11317
11332
  onExtraction(isExtractionOk, extractionData) {
11318
11333
  this.candidateImages = [];
11319
11334
  this.extractionImages = {};
11335
+ clearTimeout(this.turnMessageTimer);
11336
+ this.turnMessageTimer = null;
11320
11337
  this.stopVideo();
11321
11338
  if (isExtractionOk) {
11322
11339
  this.showMessage("Success - data extracted", "success");
@@ -11399,6 +11416,8 @@ class ExtractorVideo {
11399
11416
  }
11400
11417
  this.video.srcObject = null;
11401
11418
  }
11419
+ clearTimeout(this.turnMessageTimer);
11420
+ this.turnMessageTimer = null;
11402
11421
  }
11403
11422
  adjustOverlayPosition() {
11404
11423
  const video = this.video;
@@ -11845,6 +11864,71 @@ function getScanDocAIConfig() {
11845
11864
 
11846
11865
  /***/ }),
11847
11866
 
11867
+ /***/ "./src/lib/requests/error_logging.js":
11868
+ /*!*******************************************!*\
11869
+ !*** ./src/lib/requests/error_logging.js ***!
11870
+ \*******************************************/
11871
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
11872
+
11873
+ "use strict";
11874
+ __webpack_require__.r(__webpack_exports__);
11875
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
11876
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
11877
+ /* harmony export */ });
11878
+ /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../config */ "./src/lib/config.js");
11879
+ /* harmony import */ var _utility_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../utility/utils */ "./src/lib/utility/utils.js");
11880
+
11881
+
11882
+ async function callErrorLogging(frontImage, backImage, transactionId) {
11883
+ try {
11884
+ const serviceConfig = (0,_config__WEBPACK_IMPORTED_MODULE_0__.getScanDocAIConfig)();
11885
+ const cfgValues = (0,_config__WEBPACK_IMPORTED_MODULE_0__.getScanDocAIConfigValues)();
11886
+ const {
11887
+ os,
11888
+ browser,
11889
+ device
11890
+ } = (0,_utility_utils__WEBPACK_IMPORTED_MODULE_1__.detectEnvironment)();
11891
+ let tryCount = 0;
11892
+ let errors = [];
11893
+ while (tryCount < cfgValues.MAX_REQUEST_TRY) {
11894
+ const response = await fetch(`${cfgValues.SCAN_APP_URL}error_logging/`, {
11895
+ method: "POST",
11896
+ headers: {
11897
+ Authorization: await serviceConfig.getAccessToken(true),
11898
+ Accept: "application/json",
11899
+ "Content-Type": "application/json"
11900
+ },
11901
+ body: JSON.stringify({
11902
+ AcceptTermsAndConditions: true,
11903
+ TransactionID: transactionId,
11904
+ FrontImage: frontImage,
11905
+ BackImage: backImage ?? "",
11906
+ OS: os,
11907
+ Device: device,
11908
+ Browser: browser
11909
+ })
11910
+ });
11911
+ if (response.status === 202) {
11912
+ return [true, null];
11913
+ }
11914
+ if (response.status === 401 || response.status === 403) {
11915
+ errors = ["Unauthorized access"];
11916
+ await serviceConfig.refreshTokens();
11917
+ } else {
11918
+ const data = await response.json();
11919
+ errors = data.Errors ?? (data.detail ? [data.detail] : ["Backend error, but no details provided!"]);
11920
+ }
11921
+ tryCount++;
11922
+ }
11923
+ return [false, errors];
11924
+ } catch (error) {
11925
+ return [false, [error.message]];
11926
+ }
11927
+ }
11928
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (callErrorLogging);
11929
+
11930
+ /***/ }),
11931
+
11848
11932
  /***/ "./src/lib/requests/extraction.js":
11849
11933
  /*!****************************************!*\
11850
11934
  !*** ./src/lib/requests/extraction.js ***!
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "scandoc-ai-components",
3
3
  "author": "ScanDoc-AI",
4
- "version": "0.0.85",
4
+ "version": "0.0.87",
5
5
  "private": false,
6
6
  "description": "Pure JavaScript package for integrating ScanDoc-AI services.",
7
7
  "keywords": [