scandoc-ai-components 0.1.0 → 0.1.2
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 +65 -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 = {
|
|
@@ -11779,6 +11798,7 @@ class ServiceConfig {
|
|
|
11779
11798
|
if (isOk) {
|
|
11780
11799
|
this.accessToken = data["access_token"];
|
|
11781
11800
|
this.refreshToken = data["refresh_token"];
|
|
11801
|
+
console.log(this.accessToken);
|
|
11782
11802
|
return this.accessToken;
|
|
11783
11803
|
} else {
|
|
11784
11804
|
console.error("Could not authenticate! Check your static key!");
|
|
@@ -11857,6 +11877,34 @@ class InactiveServiceConfig {
|
|
|
11857
11877
|
}
|
|
11858
11878
|
async refreshTokens() {}
|
|
11859
11879
|
}
|
|
11880
|
+
class TokenServiceConfig {
|
|
11881
|
+
static CONFIG = undefined;
|
|
11882
|
+
constructor() {
|
|
11883
|
+
this.accessToken = undefined;
|
|
11884
|
+
}
|
|
11885
|
+
setAccessToken(token) {
|
|
11886
|
+
this.accessToken = token || undefined;
|
|
11887
|
+
}
|
|
11888
|
+
async getAccessToken() {
|
|
11889
|
+
if (!this.accessToken) {
|
|
11890
|
+
const err = new Error("Missing access token");
|
|
11891
|
+
err.status = 401;
|
|
11892
|
+
throw err;
|
|
11893
|
+
}
|
|
11894
|
+
return this.accessToken;
|
|
11895
|
+
}
|
|
11896
|
+
async refreshTokens() {
|
|
11897
|
+
// client provides a new token
|
|
11898
|
+
}
|
|
11899
|
+
}
|
|
11900
|
+
function setScanDocAIAccessToken(token) {
|
|
11901
|
+
const config = getScanDocAIConfigValues();
|
|
11902
|
+
if (config.USE_KEY_SERVICE === false) return;
|
|
11903
|
+
if (TokenServiceConfig.CONFIG === undefined) {
|
|
11904
|
+
TokenServiceConfig.CONFIG = new TokenServiceConfig();
|
|
11905
|
+
}
|
|
11906
|
+
TokenServiceConfig.CONFIG.setAccessToken(token);
|
|
11907
|
+
}
|
|
11860
11908
|
function createScanDocAIConfig(staticKey, subClient) {
|
|
11861
11909
|
const config = getScanDocAIConfigValues();
|
|
11862
11910
|
if (config.USE_KEY_SERVICE) {
|
|
@@ -11872,11 +11920,15 @@ function getScanDocAIConfig() {
|
|
|
11872
11920
|
if (config.USE_KEY_SERVICE === false) {
|
|
11873
11921
|
return new InactiveServiceConfig();
|
|
11874
11922
|
}
|
|
11875
|
-
|
|
11876
|
-
|
|
11877
|
-
throw new Error("Service config not created!");
|
|
11923
|
+
if (TokenServiceConfig.CONFIG !== undefined) {
|
|
11924
|
+
return TokenServiceConfig.CONFIG;
|
|
11878
11925
|
}
|
|
11879
|
-
|
|
11926
|
+
if (ServiceConfig.CONFIG !== undefined) {
|
|
11927
|
+
return ServiceConfig.CONFIG;
|
|
11928
|
+
}
|
|
11929
|
+
const err = new Error("Service config not created (missing token or static key)!");
|
|
11930
|
+
err.status = 401;
|
|
11931
|
+
throw err;
|
|
11880
11932
|
}
|
|
11881
11933
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (createScanDocAIConfig);
|
|
11882
11934
|
|
|
@@ -11986,7 +12038,7 @@ async function callDocumentExtraction(frontImage, backImage, ignoreBackImage) {
|
|
|
11986
12038
|
const response = await fetch(`${cfgValues.SCAN_APP_URL}extraction/`, {
|
|
11987
12039
|
method: "POST",
|
|
11988
12040
|
headers: {
|
|
11989
|
-
Authorization: await serviceConfig.getAccessToken(
|
|
12041
|
+
Authorization: await serviceConfig.getAccessToken(false),
|
|
11990
12042
|
Accept: "application/json",
|
|
11991
12043
|
"Content-Type": "application/json"
|
|
11992
12044
|
},
|
|
@@ -12013,6 +12065,7 @@ async function callDocumentExtraction(frontImage, backImage, ignoreBackImage) {
|
|
|
12013
12065
|
}
|
|
12014
12066
|
//
|
|
12015
12067
|
if (response.status === 401 || response.status === 403) {
|
|
12068
|
+
errors = ["Token expired/invalid"];
|
|
12016
12069
|
await serviceConfig.refreshTokens();
|
|
12017
12070
|
} else {
|
|
12018
12071
|
const data = await response.json();
|
|
@@ -12096,7 +12149,7 @@ async function callDocumentValidation(images, blur_values) {
|
|
|
12096
12149
|
}
|
|
12097
12150
|
//
|
|
12098
12151
|
if (response.status === 401 || response.status === 403) {
|
|
12099
|
-
errors = ["
|
|
12152
|
+
errors = ["Token expired/invalid"];
|
|
12100
12153
|
await serviceConfig.refreshTokens();
|
|
12101
12154
|
} else {
|
|
12102
12155
|
const data = await response.json();
|