scandoc-ai-components 0.1.0 → 0.1.1
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 +4 -6
- package/dist/index.js +64 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,8 +42,7 @@ An example HTML page integration:
|
|
|
42
42
|
|
|
43
43
|
<script src="scandoc.js"></script>
|
|
44
44
|
<script>
|
|
45
|
-
const
|
|
46
|
-
createScanDocAIConfig(key, "test");
|
|
45
|
+
const token = ""
|
|
47
46
|
|
|
48
47
|
setScanDocAIConfig({
|
|
49
48
|
SHOULD_RETURN_DOCUMENT_IMAGE: true,
|
|
@@ -54,7 +53,7 @@ An example HTML page integration:
|
|
|
54
53
|
MAX_UNSUPPORTED_ATTEMPTS: 5,
|
|
55
54
|
});
|
|
56
55
|
|
|
57
|
-
const extractionVideo = getExtractionVideo(function (result) {
|
|
56
|
+
const extractionVideo = getExtractionVideo(token, function (result) {
|
|
58
57
|
console.log("Extraction Result:", result);
|
|
59
58
|
if (result.success) {
|
|
60
59
|
extractionVideo.reset();
|
|
@@ -82,8 +81,7 @@ An example React integration:
|
|
|
82
81
|
import { useEffect, useMemo } from "react";
|
|
83
82
|
import "scandoc-ai-components/dist/index"
|
|
84
83
|
|
|
85
|
-
const
|
|
86
|
-
window.createScanDocAIConfig(key, "test");
|
|
84
|
+
const token = "";
|
|
87
85
|
window.setScanDocAIConfig({
|
|
88
86
|
SHOULD_RETURN_DOCUMENT_IMAGE: true,
|
|
89
87
|
SHOULD_RETURN_FACE_IF_DETECTED: true,
|
|
@@ -93,7 +91,7 @@ window.setScanDocAIConfig({
|
|
|
93
91
|
MAX_UNSUPPORTED_ATTEMPTS: 4,
|
|
94
92
|
});
|
|
95
93
|
|
|
96
|
-
const extractionVideo = window.getExtractionVideo(result => {
|
|
94
|
+
const extractionVideo = window.getExtractionVideo(token, result => {
|
|
97
95
|
console.log("Extraction Result:", result);
|
|
98
96
|
if (result.success) {
|
|
99
97
|
extractionVideo.reset();
|
package/dist/index.js
CHANGED
|
@@ -11349,7 +11349,7 @@ class ExtractorVideo {
|
|
|
11349
11349
|
async startVideo() {
|
|
11350
11350
|
try {
|
|
11351
11351
|
const serviceConfig = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfig)();
|
|
11352
|
-
await serviceConfig.getAccessToken(
|
|
11352
|
+
await serviceConfig.getAccessToken(false);
|
|
11353
11353
|
const videoElem = document.getElementById("ScanDocAIVideoElement");
|
|
11354
11354
|
if (!videoElem) {
|
|
11355
11355
|
throw new Error("Video element not found.");
|
|
@@ -11418,7 +11418,7 @@ class ExtractorVideo {
|
|
|
11418
11418
|
this.onExtractedResults({
|
|
11419
11419
|
success: false,
|
|
11420
11420
|
code: error.status === 401 || error.status === 403 ? "004" : "005",
|
|
11421
|
-
info: error.status === 401 || error.status === 403 ? "Authentication failed: Invalid API key." : "Startup failed: " + (error.message || "Unknown error")
|
|
11421
|
+
info: error.status === 401 || error.status === 403 ? "Authentication failed: Invalid API key/token." : "Startup failed: " + (error.message || "Unknown error")
|
|
11422
11422
|
});
|
|
11423
11423
|
return false;
|
|
11424
11424
|
}
|
|
@@ -11610,11 +11610,29 @@ class ExtractorVideo {
|
|
|
11610
11610
|
}
|
|
11611
11611
|
}
|
|
11612
11612
|
let EXTRACTION_VIDEO = undefined;
|
|
11613
|
-
function getExtractionVideo(
|
|
11614
|
-
|
|
11615
|
-
|
|
11613
|
+
function getExtractionVideo(tokenOrCallback, maybeCallback) {
|
|
11614
|
+
let token;
|
|
11615
|
+
let cb;
|
|
11616
|
+
if (typeof tokenOrCallback === "function") {
|
|
11617
|
+
cb = tokenOrCallback;
|
|
11616
11618
|
} else {
|
|
11617
|
-
|
|
11619
|
+
token = tokenOrCallback;
|
|
11620
|
+
cb = maybeCallback;
|
|
11621
|
+
}
|
|
11622
|
+
if (token !== undefined) {
|
|
11623
|
+
(0,_config__WEBPACK_IMPORTED_MODULE_1__.setScanDocAIAccessToken)(token);
|
|
11624
|
+
}
|
|
11625
|
+
if (EXTRACTION_VIDEO === undefined) {
|
|
11626
|
+
if (typeof cb !== "function") {
|
|
11627
|
+
throw new Error("getExtractionVideo requires a callback.");
|
|
11628
|
+
}
|
|
11629
|
+
EXTRACTION_VIDEO = new ExtractorVideo(cb);
|
|
11630
|
+
return EXTRACTION_VIDEO;
|
|
11631
|
+
}
|
|
11632
|
+
|
|
11633
|
+
// If called again, update callback too
|
|
11634
|
+
if (typeof cb === "function") {
|
|
11635
|
+
EXTRACTION_VIDEO.onExtractedResults = cb;
|
|
11618
11636
|
}
|
|
11619
11637
|
return EXTRACTION_VIDEO;
|
|
11620
11638
|
}
|
|
@@ -11705,6 +11723,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
11705
11723
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
|
|
11706
11724
|
/* harmony export */ getScanDocAIConfig: () => (/* binding */ getScanDocAIConfig),
|
|
11707
11725
|
/* harmony export */ getScanDocAIConfigValues: () => (/* binding */ getScanDocAIConfigValues),
|
|
11726
|
+
/* harmony export */ setScanDocAIAccessToken: () => (/* binding */ setScanDocAIAccessToken),
|
|
11708
11727
|
/* harmony export */ setScanDocAIConfig: () => (/* binding */ setScanDocAIConfig)
|
|
11709
11728
|
/* harmony export */ });
|
|
11710
11729
|
let internalConfig = {
|
|
@@ -11857,6 +11876,34 @@ class InactiveServiceConfig {
|
|
|
11857
11876
|
}
|
|
11858
11877
|
async refreshTokens() {}
|
|
11859
11878
|
}
|
|
11879
|
+
class TokenServiceConfig {
|
|
11880
|
+
static CONFIG = undefined;
|
|
11881
|
+
constructor() {
|
|
11882
|
+
this.accessToken = undefined;
|
|
11883
|
+
}
|
|
11884
|
+
setAccessToken(token) {
|
|
11885
|
+
this.accessToken = token || undefined;
|
|
11886
|
+
}
|
|
11887
|
+
async getAccessToken() {
|
|
11888
|
+
if (!this.accessToken) {
|
|
11889
|
+
const err = new Error("Missing access token");
|
|
11890
|
+
err.status = 401;
|
|
11891
|
+
throw err;
|
|
11892
|
+
}
|
|
11893
|
+
return this.accessToken;
|
|
11894
|
+
}
|
|
11895
|
+
async refreshTokens() {
|
|
11896
|
+
// client provides a new token
|
|
11897
|
+
}
|
|
11898
|
+
}
|
|
11899
|
+
function setScanDocAIAccessToken(token) {
|
|
11900
|
+
const config = getScanDocAIConfigValues();
|
|
11901
|
+
if (config.USE_KEY_SERVICE === false) return;
|
|
11902
|
+
if (TokenServiceConfig.CONFIG === undefined) {
|
|
11903
|
+
TokenServiceConfig.CONFIG = new TokenServiceConfig();
|
|
11904
|
+
}
|
|
11905
|
+
TokenServiceConfig.CONFIG.setAccessToken(token);
|
|
11906
|
+
}
|
|
11860
11907
|
function createScanDocAIConfig(staticKey, subClient) {
|
|
11861
11908
|
const config = getScanDocAIConfigValues();
|
|
11862
11909
|
if (config.USE_KEY_SERVICE) {
|
|
@@ -11872,11 +11919,15 @@ function getScanDocAIConfig() {
|
|
|
11872
11919
|
if (config.USE_KEY_SERVICE === false) {
|
|
11873
11920
|
return new InactiveServiceConfig();
|
|
11874
11921
|
}
|
|
11875
|
-
|
|
11876
|
-
|
|
11877
|
-
throw new Error("Service config not created!");
|
|
11922
|
+
if (TokenServiceConfig.CONFIG !== undefined) {
|
|
11923
|
+
return TokenServiceConfig.CONFIG;
|
|
11878
11924
|
}
|
|
11879
|
-
|
|
11925
|
+
if (ServiceConfig.CONFIG !== undefined) {
|
|
11926
|
+
return ServiceConfig.CONFIG;
|
|
11927
|
+
}
|
|
11928
|
+
const err = new Error("Service config not created (missing token or static key)!");
|
|
11929
|
+
err.status = 401;
|
|
11930
|
+
throw err;
|
|
11880
11931
|
}
|
|
11881
11932
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (createScanDocAIConfig);
|
|
11882
11933
|
|
|
@@ -11986,7 +12037,7 @@ async function callDocumentExtraction(frontImage, backImage, ignoreBackImage) {
|
|
|
11986
12037
|
const response = await fetch(`${cfgValues.SCAN_APP_URL}extraction/`, {
|
|
11987
12038
|
method: "POST",
|
|
11988
12039
|
headers: {
|
|
11989
|
-
Authorization: await serviceConfig.getAccessToken(
|
|
12040
|
+
Authorization: await serviceConfig.getAccessToken(false),
|
|
11990
12041
|
Accept: "application/json",
|
|
11991
12042
|
"Content-Type": "application/json"
|
|
11992
12043
|
},
|
|
@@ -12013,6 +12064,7 @@ async function callDocumentExtraction(frontImage, backImage, ignoreBackImage) {
|
|
|
12013
12064
|
}
|
|
12014
12065
|
//
|
|
12015
12066
|
if (response.status === 401 || response.status === 403) {
|
|
12067
|
+
errors = ["Token expired/invalid"];
|
|
12016
12068
|
await serviceConfig.refreshTokens();
|
|
12017
12069
|
} else {
|
|
12018
12070
|
const data = await response.json();
|
|
@@ -12096,7 +12148,7 @@ async function callDocumentValidation(images, blur_values) {
|
|
|
12096
12148
|
}
|
|
12097
12149
|
//
|
|
12098
12150
|
if (response.status === 401 || response.status === 403) {
|
|
12099
|
-
errors = ["
|
|
12151
|
+
errors = ["Token expired/invalid"];
|
|
12100
12152
|
await serviceConfig.refreshTokens();
|
|
12101
12153
|
} else {
|
|
12102
12154
|
const data = await response.json();
|