scandoc-ai-components 0.0.20 → 0.0.23

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
@@ -50,8 +50,6 @@ An example HTML page integration:
50
50
  SHOULD_RETURN_FACE_IF_DETECTED: true,
51
51
  SHOULD_RETURN_SIGNATURE_IF_DETECTED: true,
52
52
  SKIP_DOCUMENT_SIZE_CHECK: true,
53
- DONT_USE_VALIDATION: true,
54
- CAN_STORE_IMAGES: true,
55
53
  });
56
54
 
57
55
  const extractionVideo = getExtractionVideo(function (data) {
@@ -79,13 +77,10 @@ import "scandoc-ai-components/dist/index"
79
77
  const key = ""; // Use the key provided by our team
80
78
  window.createScanDocAIConfig(key, "test");
81
79
  window.setScanDocAIConfig({
82
- SCAN_APP_URL: "https://api.scandoc.ai/ss/",
83
80
  SHOULD_RETURN_DOCUMENT_IMAGE: true,
84
- SHOULD_RETURN_FACE_IF_DETECTED: true,
85
- SHOULD_RETURN_SIGNATURE_IF_DETECTED: true,
86
- SKIP_DOCUMENT_SIZE_CHECK: true,
87
- DONT_USE_VALIDATION: true,
88
- CAN_STORE_IMAGES: true,
81
+ SHOULD_RETURN_FACE_IF_DETECTED: true,
82
+ SHOULD_RETURN_SIGNATURE_IF_DETECTED: true,
83
+ SKIP_DOCUMENT_SIZE_CHECK: true,
89
84
  });
90
85
 
91
86
  const extractionVideo = window.getExtractionVideo(data=>console.log(data));const extractionVideo = window.getExtractionVideo(data => {
package/dist/index.js CHANGED
@@ -11185,12 +11185,29 @@ class ExtractorVideo {
11185
11185
  this.onExtractedResults = onExtractedResults;
11186
11186
  this.pastBlurValues = [];
11187
11187
  this.isRunning = false;
11188
+ this.sessionStartTime = null;
11189
+ this.MAX_SESSION_DURATION_MS = 10000;
11190
+ this.failedValidations = 0;
11191
+ this.MAX_FAILED_VALIDATIONS = 5;
11192
+ this.failedExtractionAttempts = 0;
11193
+ this.MAX_EXTRACTION_ATTEMPTS = 3;
11188
11194
  }
11189
11195
  async analyzeVideoStream() {
11190
11196
  if (!this.isRunning) {
11191
11197
  return;
11192
11198
  }
11193
11199
  //
11200
+ const elapsedTime = Date.now() - this.sessionStartTime;
11201
+ if (elapsedTime > this.MAX_SESSION_DURATION_MS) {
11202
+ this.stopVideo();
11203
+ this.onExtractedResults({
11204
+ success: false,
11205
+ code: "TIMEOUT",
11206
+ message: "No document detected within allowed time."
11207
+ });
11208
+ return;
11209
+ }
11210
+ //
11194
11211
  const canvas = document.createElement("canvas");
11195
11212
  let video = document.getElementById("ScanDocAIVideoElement");
11196
11213
  //
@@ -11205,6 +11222,21 @@ class ExtractorVideo {
11205
11222
  const images = [...this.candidateImages];
11206
11223
  if (images.length >= ExtractorVideo.VALIDATION_BATCH_SIZE) {
11207
11224
  const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_2__["default"])(images.map(e => e["validationImg"]), this.pastBlurValues, {});
11225
+ if (!isValidationOk) {
11226
+ this.failedValidations++;
11227
+ if (this.failedValidations >= this.MAX_FAILED_VALIDATIONS) {
11228
+ this.stopVideo();
11229
+ this.onExtractedResults({
11230
+ success: false,
11231
+ code: "VALIDATION_FAILED",
11232
+ message: "Document validation failed repeatedly."
11233
+ });
11234
+ return;
11235
+ }
11236
+ this.candidateImages = [];
11237
+ return;
11238
+ }
11239
+ this.failedValidations = 0;
11208
11240
  if (isValidationOk) {
11209
11241
  this.showMessage(response["Info"]);
11210
11242
  //
@@ -11259,7 +11291,6 @@ class ExtractorVideo {
11259
11291
  onExtraction(isExtractionOk, extractionData) {
11260
11292
  this.candidateImages = [];
11261
11293
  this.extractionImages = {};
11262
- //
11263
11294
  if (isExtractionOk) {
11264
11295
  this.showMessage("Success - data extracted", "success");
11265
11296
  const shouldStop = this.onExtractedResults(extractionData);
@@ -11267,6 +11298,16 @@ class ExtractorVideo {
11267
11298
  setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
11268
11299
  }
11269
11300
  } else {
11301
+ this.failedExtractionAttempts++;
11302
+ if (this.failedExtractionAttempts >= this.MAX_EXTRACTION_ATTEMPTS) {
11303
+ this.stopVideo();
11304
+ this.onExtractedResults({
11305
+ success: false,
11306
+ code: "EXTRACTION_FAILED",
11307
+ message: "Document extraction failed."
11308
+ });
11309
+ return;
11310
+ }
11270
11311
  setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
11271
11312
  }
11272
11313
  }
@@ -11301,9 +11342,23 @@ class ExtractorVideo {
11301
11342
  });
11302
11343
  //
11303
11344
  setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
11304
- }).catch(error => console.log("Error accessing the camera: " + error));
11345
+ }).catch(error => {
11346
+ console.log("Error accessing the camera: " + error);
11347
+ this.onExtractedResults({
11348
+ success: false,
11349
+ code: "CAMERA_ERROR",
11350
+ message: error.message || "Unable to access camera"
11351
+ });
11352
+ });
11353
+ });
11354
+ }).catch(error => {
11355
+ console.log("Error accessing the camera: " + error);
11356
+ this.onExtractedResults({
11357
+ success: false,
11358
+ code: "CAMERA_ENUMERATION_ERROR",
11359
+ message: error.message || "Unable to enumerate camera devices"
11305
11360
  });
11306
- }).catch(() => console.log("Error accessing the camera: " + error));
11361
+ });
11307
11362
  this.showMessage("Starting scanning");
11308
11363
  return true;
11309
11364
  }
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.20",
4
+ "version": "0.0.23",
5
5
  "private": false,
6
6
  "description": "Pure JavaScript package for integrating ScanDoc-AI services.",
7
7
  "keywords": [