scandoc-ai-components 0.0.42 → 0.0.44

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 +12 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11188,7 +11188,8 @@ class ExtractorVideo {
11188
11188
  this.pastBlurValues = [];
11189
11189
  this.isRunning = false;
11190
11190
  this.scanStartTime = null;
11191
- this.unsupportedDocStartTime = null;
11191
+ this.unsupportedDocCount = 0;
11192
+ this.video = null;
11192
11193
  }
11193
11194
  reset() {
11194
11195
  this.stopVideo();
@@ -11199,6 +11200,8 @@ class ExtractorVideo {
11199
11200
  this.timeoutTimer = null;
11200
11201
  this.isRunning = false;
11201
11202
  this.unsupportedDocStartTime = null;
11203
+ this.unsupportedDocCount = 0;
11204
+ this.video = null;
11202
11205
  }
11203
11206
  async analyzeVideoStream() {
11204
11207
  if (!this.isRunning) {
@@ -11224,26 +11227,11 @@ class ExtractorVideo {
11224
11227
  const validationImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, ExtractorVideo.VALIDATION_IMG_WIDTH, ExtractorVideo.VALIDATION_IMG_HEIGHT, true);
11225
11228
  DOCUMENT_DETECTOR.isDocumentPresent(video).then(async isPresent => {
11226
11229
  if (isPresent) {
11227
- if (!this.documentDetectionStartTime) {
11228
- this.documentDetectionStartTime = Date.now();
11229
- }
11230
11230
  this.candidateImages.push({
11231
11231
  fullImg: fullImage,
11232
11232
  validationImg: validationImage
11233
11233
  });
11234
11234
  const images = [...this.candidateImages];
11235
- const timeSinceFirstDetection = Date.now() - this.documentDetectionStartTime;
11236
- if (timeSinceFirstDetection > cfgValues.VALIDATION_TIMEOUT_MS) {
11237
- this.stopVideo();
11238
- this.onExtractedResults({
11239
- success: false,
11240
- code: "002",
11241
- info: "Document template not supported."
11242
- });
11243
- this.documentDetectionStartTime = null;
11244
- this.candidateImages = [];
11245
- return;
11246
- }
11247
11235
  if (images.length >= ExtractorVideo.VALIDATION_BATCH_SIZE) {
11248
11236
  const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_3__["default"])(images.map(e => e["validationImg"]), this.pastBlurValues, {});
11249
11237
  if (isValidationOk) {
@@ -11340,7 +11328,7 @@ class ExtractorVideo {
11340
11328
  async startVideo() {
11341
11329
  try {
11342
11330
  const serviceConfig = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfig)();
11343
- await serviceConfig.getAccessToken(true); // This will throw if 401
11331
+ await serviceConfig.getAccessToken(true); // this will throw if 401
11344
11332
 
11345
11333
  const videoElem = document.getElementById("ScanDocAIVideoElement");
11346
11334
  if (!videoElem) {
@@ -11369,17 +11357,18 @@ class ExtractorVideo {
11369
11357
  await this.video.play().catch(e => {
11370
11358
  console.warn(`Error on video play: ${e}`);
11371
11359
  });
11372
- this.scanStartTime = Date.now();
11360
+ this.scanStartTime = Date.now(); // Reset timer
11373
11361
  setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
11374
11362
  this.showMessage("Starting scanning");
11375
11363
  return true;
11376
11364
  } catch (error) {
11365
+ console.error("startVideo failed:", error);
11377
11366
  this.isRunning = false;
11378
11367
  this.stopVideo();
11379
11368
  this.onExtractedResults({
11380
11369
  success: false,
11381
11370
  code: error.status === 401 ? "004" : "005",
11382
- info: error.status === 401 ? "Authentication failed." : "Video setup failed."
11371
+ info: error.status === 401 ? "Authentication failed: Invalid API key." : "Startup failed: " + (error.message || "Unknown error")
11383
11372
  });
11384
11373
  return false;
11385
11374
  }
@@ -11642,8 +11631,12 @@ class ServiceConfig {
11642
11631
  if (isOk) {
11643
11632
  this.accessToken = data["access_token"];
11644
11633
  this.refreshToken = data["refresh_token"];
11634
+ return this.accessToken;
11645
11635
  } else {
11646
11636
  console.error("Could not authenticate! Check your static key!");
11637
+ const error = new Error("Authentication failed");
11638
+ error.status = 401;
11639
+ throw error;
11647
11640
  }
11648
11641
  }
11649
11642
  return this.accessToken;
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.42",
4
+ "version": "0.0.44",
5
5
  "private": false,
6
6
  "description": "Pure JavaScript package for integrating ScanDoc-AI services.",
7
7
  "keywords": [