mindee 2.0.1 → 2.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/CHANGELOG.md +10 -0
- package/package.json +1 -1
- package/src/api/endpoint.d.ts +4 -1
- package/src/api/endpoint.js +19 -30
- package/src/api/index.d.ts +2 -2
- package/src/api/index.js +3 -1
- package/src/api/response.d.ts +5 -2
- package/src/api/response.js +19 -5
- package/src/cli.js +17 -6
- package/src/client.d.ts +1 -0
- package/src/client.js +4 -0
- package/src/constants.js +6 -0
- package/src/documents/cropper.d.ts +7 -0
- package/src/documents/cropper.js +31 -0
- package/src/documents/custom.d.ts +2 -2
- package/src/documents/custom.js +4 -4
- package/src/documents/document.d.ts +19 -15
- package/src/documents/document.js +19 -8
- package/src/documents/documentConfig.d.ts +6 -2
- package/src/documents/documentConfig.js +13 -6
- package/src/documents/financialDocument.d.ts +2 -9
- package/src/documents/financialDocument.js +10 -12
- package/src/documents/index.d.ts +3 -1
- package/src/documents/index.js +4 -1
- package/src/documents/invoice.d.ts +2 -9
- package/src/documents/invoice.js +3 -15
- package/src/documents/passport.d.ts +1 -7
- package/src/documents/passport.js +13 -19
- package/src/documents/receipt.d.ts +2 -9
- package/src/documents/receipt.js +4 -16
- package/src/fields/cropper.d.ts +16 -0
- package/src/fields/cropper.js +18 -0
- package/src/fields/field.d.ts +10 -11
- package/src/fields/field.js +4 -3
- package/src/fields/index.d.ts +3 -3
- package/src/fields/index.js +5 -4
- package/src/fields/orientation.d.ts +10 -3
- package/src/fields/orientation.js +9 -7
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v2.1.1 - 2022-10-28
|
|
4
|
+
### Fixes
|
|
5
|
+
* :bug: fix for sending base64 documents.
|
|
6
|
+
|
|
7
|
+
## v2.1.0 - 2022-10-19
|
|
8
|
+
### Changes
|
|
9
|
+
* :sparkles: add cropper support to predict requests
|
|
10
|
+
* :sparkles: add stand-alone cropper support
|
|
11
|
+
|
|
12
|
+
|
|
3
13
|
## v2.0.1 - 2022-10-13
|
|
4
14
|
### Fixes
|
|
5
15
|
* :bug: Fix for packaging and documentation related to commonJS imports
|
package/package.json
CHANGED
package/src/api/endpoint.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class Endpoint {
|
|
|
12
12
|
/**
|
|
13
13
|
* Make a prediction request.
|
|
14
14
|
*/
|
|
15
|
-
predictRequest(input: Input, includeWords?: boolean): Promise<unknown>;
|
|
15
|
+
predictRequest(input: Input, includeWords?: boolean, cropper?: boolean): Promise<unknown>;
|
|
16
16
|
protected apiKeyFromEnv(): string;
|
|
17
17
|
}
|
|
18
18
|
export declare class InvoiceEndpoint extends Endpoint {
|
|
@@ -24,6 +24,9 @@ export declare class ReceiptEndpoint extends Endpoint {
|
|
|
24
24
|
export declare class PassportEndpoint extends Endpoint {
|
|
25
25
|
constructor(apiKey: string);
|
|
26
26
|
}
|
|
27
|
+
export declare class CropperEndpoint extends Endpoint {
|
|
28
|
+
constructor(apiKey: string);
|
|
29
|
+
}
|
|
27
30
|
export declare class CustomEndpoint extends Endpoint {
|
|
28
31
|
constructor(documentType: string, accountName: string, version: string, apiKey: string);
|
|
29
32
|
}
|
package/src/api/endpoint.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.CustomEndpoint = exports.PassportEndpoint = exports.ReceiptEndpoint = exports.InvoiceEndpoint = exports.Endpoint = exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = void 0;
|
|
29
|
+
exports.CustomEndpoint = exports.CropperEndpoint = exports.PassportEndpoint = exports.ReceiptEndpoint = exports.InvoiceEndpoint = exports.Endpoint = exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = void 0;
|
|
30
30
|
const https = __importStar(require("https"));
|
|
31
31
|
const os = __importStar(require("os"));
|
|
32
32
|
const package_json_1 = require("../../package.json");
|
|
@@ -49,41 +49,30 @@ class Endpoint {
|
|
|
49
49
|
/**
|
|
50
50
|
* Make a prediction request.
|
|
51
51
|
*/
|
|
52
|
-
predictRequest(input, includeWords = false) {
|
|
52
|
+
predictRequest(input, includeWords = false, cropper = false) {
|
|
53
53
|
return new Promise((resolve, reject) => {
|
|
54
|
-
const form = new form_data_1.default();
|
|
55
|
-
let body;
|
|
56
54
|
let headers = {
|
|
57
55
|
"User-Agent": USER_AGENT,
|
|
58
56
|
Authorization: `Token ${this.apiKey}`,
|
|
59
57
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const fileParams = { filename: input.filename };
|
|
64
|
-
form.append("document", input.fileObject, fileParams);
|
|
65
|
-
if (includeWords) {
|
|
66
|
-
form.append("include_mvision", "true");
|
|
67
|
-
}
|
|
68
|
-
headers = { ...headers, ...form.getHeaders() };
|
|
58
|
+
const uri = new url_1.URL(`${this.urlRoot}/predict`);
|
|
59
|
+
if (cropper) {
|
|
60
|
+
uri.searchParams.append("cropper", "true");
|
|
69
61
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
headers["Content-Type"] = "application/json";
|
|
77
|
-
headers["Content-Length"] = body.length;
|
|
62
|
+
logger_1.logger.debug(`Prediction request: ${uri}`);
|
|
63
|
+
const form = new form_data_1.default();
|
|
64
|
+
const fileParams = { filename: input.filename };
|
|
65
|
+
form.append("document", input.fileObject, fileParams);
|
|
66
|
+
if (includeWords) {
|
|
67
|
+
form.append("include_mvision", "true");
|
|
78
68
|
}
|
|
79
|
-
|
|
69
|
+
headers = { ...headers, ...form.getHeaders() };
|
|
80
70
|
const options = {
|
|
81
71
|
method: "POST",
|
|
82
72
|
headers: headers,
|
|
83
73
|
hostname: uri.hostname,
|
|
84
74
|
path: `${uri.pathname}${uri.search}`,
|
|
85
75
|
};
|
|
86
|
-
logger_1.logger.debug(`Prediction request: ${uri}`);
|
|
87
76
|
const req = https.request(options, function (res) {
|
|
88
77
|
// when the encoding is set, data chunks will be strings
|
|
89
78
|
res.setEncoding("utf-8");
|
|
@@ -103,16 +92,10 @@ class Endpoint {
|
|
|
103
92
|
}
|
|
104
93
|
});
|
|
105
94
|
});
|
|
95
|
+
form.pipe(req);
|
|
106
96
|
req.on("error", (err) => {
|
|
107
97
|
reject(err);
|
|
108
98
|
});
|
|
109
|
-
if (["path", "stream"].includes(input.inputType)) {
|
|
110
|
-
form.pipe(req);
|
|
111
|
-
}
|
|
112
|
-
if (input.inputType === "base64") {
|
|
113
|
-
req.write(body);
|
|
114
|
-
req.end();
|
|
115
|
-
}
|
|
116
99
|
});
|
|
117
100
|
}
|
|
118
101
|
apiKeyFromEnv() {
|
|
@@ -143,6 +126,12 @@ class PassportEndpoint extends Endpoint {
|
|
|
143
126
|
}
|
|
144
127
|
}
|
|
145
128
|
exports.PassportEndpoint = PassportEndpoint;
|
|
129
|
+
class CropperEndpoint extends Endpoint {
|
|
130
|
+
constructor(apiKey) {
|
|
131
|
+
super(exports.STANDARD_API_OWNER, "cropper", "1", apiKey);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.CropperEndpoint = CropperEndpoint;
|
|
146
135
|
class CustomEndpoint extends Endpoint {
|
|
147
136
|
constructor(documentType, accountName, version, apiKey) {
|
|
148
137
|
super(accountName, documentType, version, apiKey);
|
package/src/api/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Response, InvoiceResponse, ReceiptResponse, FinancialDocResponse, PassportResponse, CustomResponse, } from "./response";
|
|
2
|
-
export { Endpoint, InvoiceEndpoint, ReceiptEndpoint, PassportEndpoint, CustomEndpoint, STANDARD_API_OWNER, API_KEY_ENVVAR_NAME, } from "./endpoint";
|
|
1
|
+
export { Response, InvoiceResponse, ReceiptResponse, FinancialDocResponse, PassportResponse, CustomResponse, CropperResponse, } from "./response";
|
|
2
|
+
export { Endpoint, InvoiceEndpoint, ReceiptEndpoint, PassportEndpoint, CustomEndpoint, CropperEndpoint, STANDARD_API_OWNER, API_KEY_ENVVAR_NAME, } from "./endpoint";
|
package/src/api/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = exports.CustomEndpoint = exports.PassportEndpoint = exports.ReceiptEndpoint = exports.InvoiceEndpoint = exports.Endpoint = exports.CustomResponse = exports.PassportResponse = exports.FinancialDocResponse = exports.ReceiptResponse = exports.InvoiceResponse = exports.Response = void 0;
|
|
3
|
+
exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = exports.CropperEndpoint = exports.CustomEndpoint = exports.PassportEndpoint = exports.ReceiptEndpoint = exports.InvoiceEndpoint = exports.Endpoint = exports.CropperResponse = exports.CustomResponse = exports.PassportResponse = exports.FinancialDocResponse = exports.ReceiptResponse = exports.InvoiceResponse = exports.Response = void 0;
|
|
4
4
|
var response_1 = require("./response");
|
|
5
5
|
Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return response_1.Response; } });
|
|
6
6
|
Object.defineProperty(exports, "InvoiceResponse", { enumerable: true, get: function () { return response_1.InvoiceResponse; } });
|
|
@@ -8,11 +8,13 @@ Object.defineProperty(exports, "ReceiptResponse", { enumerable: true, get: funct
|
|
|
8
8
|
Object.defineProperty(exports, "FinancialDocResponse", { enumerable: true, get: function () { return response_1.FinancialDocResponse; } });
|
|
9
9
|
Object.defineProperty(exports, "PassportResponse", { enumerable: true, get: function () { return response_1.PassportResponse; } });
|
|
10
10
|
Object.defineProperty(exports, "CustomResponse", { enumerable: true, get: function () { return response_1.CustomResponse; } });
|
|
11
|
+
Object.defineProperty(exports, "CropperResponse", { enumerable: true, get: function () { return response_1.CropperResponse; } });
|
|
11
12
|
var endpoint_1 = require("./endpoint");
|
|
12
13
|
Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return endpoint_1.Endpoint; } });
|
|
13
14
|
Object.defineProperty(exports, "InvoiceEndpoint", { enumerable: true, get: function () { return endpoint_1.InvoiceEndpoint; } });
|
|
14
15
|
Object.defineProperty(exports, "ReceiptEndpoint", { enumerable: true, get: function () { return endpoint_1.ReceiptEndpoint; } });
|
|
15
16
|
Object.defineProperty(exports, "PassportEndpoint", { enumerable: true, get: function () { return endpoint_1.PassportEndpoint; } });
|
|
16
17
|
Object.defineProperty(exports, "CustomEndpoint", { enumerable: true, get: function () { return endpoint_1.CustomEndpoint; } });
|
|
18
|
+
Object.defineProperty(exports, "CropperEndpoint", { enumerable: true, get: function () { return endpoint_1.CropperEndpoint; } });
|
|
17
19
|
Object.defineProperty(exports, "STANDARD_API_OWNER", { enumerable: true, get: function () { return endpoint_1.STANDARD_API_OWNER; } });
|
|
18
20
|
Object.defineProperty(exports, "API_KEY_ENVVAR_NAME", { enumerable: true, get: function () { return endpoint_1.API_KEY_ENVVAR_NAME; } });
|
package/src/api/response.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Document, Passport, Receipt, Invoice, FinancialDocument, CustomDocument, DocumentConstructorProps } from "../documents";
|
|
1
|
+
import { Document, Passport, Receipt, Invoice, FinancialDocument, CustomDocument, DocumentConstructorProps, Cropper } from "../documents";
|
|
2
2
|
import { FullText } from "../fields";
|
|
3
3
|
import { Input } from "../inputs";
|
|
4
4
|
export interface ResponseProps {
|
|
@@ -27,7 +27,7 @@ export declare class CustomResponse extends Response<CustomDocument> {
|
|
|
27
27
|
protected formatResponse(): void;
|
|
28
28
|
}
|
|
29
29
|
declare type StandardDocumentSig<DocType extends Document> = {
|
|
30
|
-
new ({
|
|
30
|
+
new ({ prediction, inputFile, pageId, fullText, }: DocumentConstructorProps): DocType;
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
33
|
* Generic class for all standard (Off-the-Shelf) endpoint responses.
|
|
@@ -49,4 +49,7 @@ export declare class FinancialDocResponse extends StandardProductResponse<Financ
|
|
|
49
49
|
export declare class PassportResponse extends StandardProductResponse<Passport> {
|
|
50
50
|
constructor(params: ResponseProps);
|
|
51
51
|
}
|
|
52
|
+
export declare class CropperResponse extends StandardProductResponse<Cropper> {
|
|
53
|
+
constructor(params: ResponseProps);
|
|
54
|
+
}
|
|
52
55
|
export {};
|
package/src/api/response.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PassportResponse = exports.FinancialDocResponse = exports.ReceiptResponse = exports.InvoiceResponse = exports.StandardProductResponse = exports.CustomResponse = exports.Response = void 0;
|
|
3
|
+
exports.CropperResponse = exports.PassportResponse = exports.FinancialDocResponse = exports.ReceiptResponse = exports.InvoiceResponse = exports.StandardProductResponse = exports.CustomResponse = exports.Response = void 0;
|
|
4
4
|
const documents_1 = require("../documents");
|
|
5
5
|
const fields_1 = require("../fields");
|
|
6
6
|
/**
|
|
@@ -38,16 +38,20 @@ class CustomResponse extends Response {
|
|
|
38
38
|
const httpDataDocument = this.httpResponse.data.document;
|
|
39
39
|
httpDataDocument.inference.pages.forEach((apiPage) => {
|
|
40
40
|
this.pages.push(new documents_1.CustomDocument({
|
|
41
|
-
|
|
41
|
+
prediction: apiPage.prediction,
|
|
42
|
+
orientation: apiPage.orientation,
|
|
43
|
+
extras: apiPage.extras,
|
|
42
44
|
inputFile: this.inputFile,
|
|
43
45
|
pageId: apiPage.id,
|
|
44
46
|
documentType: this.documentType,
|
|
45
47
|
}));
|
|
46
48
|
});
|
|
47
49
|
this.document = new documents_1.CustomDocument({
|
|
48
|
-
|
|
50
|
+
prediction: httpDataDocument.inference.prediction,
|
|
49
51
|
inputFile: this.inputFile,
|
|
50
52
|
documentType: this.documentType,
|
|
53
|
+
orientation: {},
|
|
54
|
+
extras: {},
|
|
51
55
|
});
|
|
52
56
|
}
|
|
53
57
|
}
|
|
@@ -68,15 +72,19 @@ class StandardProductResponse extends Response {
|
|
|
68
72
|
httpDataDocument.inference.pages.forEach((apiPage) => {
|
|
69
73
|
const pageText = this.getPageText(httpDataDocument, apiPage.id);
|
|
70
74
|
this.pages.push(new this.documentClass({
|
|
71
|
-
|
|
75
|
+
prediction: apiPage.prediction,
|
|
72
76
|
inputFile: this.inputFile,
|
|
73
77
|
pageId: apiPage.id,
|
|
78
|
+
orientation: apiPage.orientation,
|
|
79
|
+
extras: apiPage.extras,
|
|
74
80
|
fullText: pageText,
|
|
75
81
|
}));
|
|
76
82
|
});
|
|
77
83
|
this.document = new this.documentClass({
|
|
78
|
-
|
|
84
|
+
prediction: httpDataDocument.inference.prediction,
|
|
79
85
|
inputFile: this.inputFile,
|
|
86
|
+
orientation: {},
|
|
87
|
+
extras: {},
|
|
80
88
|
});
|
|
81
89
|
}
|
|
82
90
|
}
|
|
@@ -105,3 +113,9 @@ class PassportResponse extends StandardProductResponse {
|
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
115
|
exports.PassportResponse = PassportResponse;
|
|
116
|
+
class CropperResponse extends StandardProductResponse {
|
|
117
|
+
constructor(params) {
|
|
118
|
+
super(documents_1.Cropper, params);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.CropperResponse = CropperResponse;
|
package/src/cli.js
CHANGED
|
@@ -35,7 +35,7 @@ async function predictCall(command, inputPath, options) {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
const doc = mindeeClient.docFromPath(inputPath);
|
|
38
|
-
const
|
|
38
|
+
const predictParams = {
|
|
39
39
|
docType: command === COMMAND_CUSTOM ? options.documentType : conf.docType,
|
|
40
40
|
username: command === COMMAND_CUSTOM ? options.user : api_1.STANDARD_API_OWNER,
|
|
41
41
|
cutPages: options.cutPages,
|
|
@@ -50,23 +50,33 @@ async function predictCall(command, inputPath, options) {
|
|
|
50
50
|
let response;
|
|
51
51
|
switch (command) {
|
|
52
52
|
case COMMAND_INVOICE:
|
|
53
|
-
response = await doc.parse(api_1.InvoiceResponse,
|
|
53
|
+
response = await doc.parse(api_1.InvoiceResponse, predictParams);
|
|
54
54
|
break;
|
|
55
55
|
case COMMAND_RECEIPT:
|
|
56
|
-
response = await doc.parse(api_1.ReceiptResponse,
|
|
56
|
+
response = await doc.parse(api_1.ReceiptResponse, predictParams);
|
|
57
57
|
break;
|
|
58
58
|
case COMMAND_FINANCIAL:
|
|
59
|
-
response = await doc.parse(api_1.FinancialDocResponse,
|
|
59
|
+
response = await doc.parse(api_1.FinancialDocResponse, predictParams);
|
|
60
60
|
break;
|
|
61
61
|
case COMMAND_PASSPORT:
|
|
62
|
-
response = await doc.parse(api_1.PassportResponse,
|
|
62
|
+
response = await doc.parse(api_1.PassportResponse, predictParams);
|
|
63
63
|
break;
|
|
64
64
|
case COMMAND_CUSTOM:
|
|
65
|
-
response = await doc.parse(api_1.CustomResponse,
|
|
65
|
+
response = await doc.parse(api_1.CustomResponse, predictParams);
|
|
66
66
|
break;
|
|
67
67
|
default:
|
|
68
68
|
throw `Unhandled command: ${command}`;
|
|
69
69
|
}
|
|
70
|
+
if (options.fullText) {
|
|
71
|
+
response.pages.forEach((page) => {
|
|
72
|
+
console.log(page.fullText?.toString());
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (options.pages) {
|
|
76
|
+
response.pages.forEach((page) => {
|
|
77
|
+
console.log(`\n${page}`);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
70
80
|
if (response.document) {
|
|
71
81
|
console.log(`\n${response.document}`);
|
|
72
82
|
}
|
|
@@ -79,6 +89,7 @@ function cli() {
|
|
|
79
89
|
prog.description(info.description);
|
|
80
90
|
prog.option("-k, --api-key <api_key>", "API key for document endpoint");
|
|
81
91
|
prog.option("-C, --no-cut-pages", "Don't cut document pages");
|
|
92
|
+
prog.option("-p, --pages", "Show pages content");
|
|
82
93
|
if (info.fullText) {
|
|
83
94
|
prog.option("-t, --full-text", "Include full document text in response");
|
|
84
95
|
}
|
package/src/client.d.ts
CHANGED
package/src/client.js
CHANGED
|
@@ -18,9 +18,11 @@ class DocumentClient {
|
|
|
18
18
|
username: "",
|
|
19
19
|
cutPages: true,
|
|
20
20
|
fullText: false,
|
|
21
|
+
cropper: false,
|
|
21
22
|
}) {
|
|
22
23
|
// seems like there should be a better way of doing this
|
|
23
24
|
const fullText = params?.fullText !== undefined ? params.fullText : false;
|
|
25
|
+
const cropper = params?.cropper !== undefined ? params.cropper : false;
|
|
24
26
|
const cutPages = params?.cutPages !== undefined ? params.cutPages : true;
|
|
25
27
|
const docType = params.docType === undefined || params.docType === ""
|
|
26
28
|
? this.getDocType(responseClass.name)
|
|
@@ -50,6 +52,7 @@ class DocumentClient {
|
|
|
50
52
|
inputDoc: this.inputDoc,
|
|
51
53
|
includeWords: fullText,
|
|
52
54
|
cutPages: cutPages,
|
|
55
|
+
cropper: cropper,
|
|
53
56
|
});
|
|
54
57
|
}
|
|
55
58
|
getDocType(responseClass) {
|
|
@@ -82,6 +85,7 @@ class Client {
|
|
|
82
85
|
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.DOC_TYPE_RECEIPT], new documentConfig_1.ReceiptConfig(this.apiKey));
|
|
83
86
|
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.DOC_TYPE_FINANCIAL], new documentConfig_1.FinancialDocConfig(this.apiKey));
|
|
84
87
|
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.DOC_TYPE_PASSPORT], new documentConfig_1.PassportConfig(this.apiKey));
|
|
88
|
+
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.DOC_TYPE_CROPPER], new documentConfig_1.CropperConfig(this.apiKey));
|
|
85
89
|
}
|
|
86
90
|
addEndpoint({ accountName, documentType, version = "1", }) {
|
|
87
91
|
this.docConfigs.set([accountName, documentType], new documentConfig_1.CustomDocConfig({
|
package/src/constants.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Document, DocumentConstructorProps } from "./document";
|
|
2
|
+
import { CropperField } from "../fields";
|
|
3
|
+
export declare class Cropper extends Document {
|
|
4
|
+
cropping: CropperField[];
|
|
5
|
+
constructor({ prediction, orientation, inputFile, pageId, }: DocumentConstructorProps);
|
|
6
|
+
toString(): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Cropper = void 0;
|
|
4
|
+
const document_1 = require("./document");
|
|
5
|
+
const fields_1 = require("../fields");
|
|
6
|
+
class Cropper extends document_1.Document {
|
|
7
|
+
constructor({ prediction, orientation = undefined, inputFile = undefined, pageId = undefined, }) {
|
|
8
|
+
super({ inputFile, pageId, orientation });
|
|
9
|
+
this.cropping = [];
|
|
10
|
+
if (pageId !== undefined) {
|
|
11
|
+
prediction.cropping.forEach((crop) => {
|
|
12
|
+
this.cropping.push(new fields_1.CropperField({
|
|
13
|
+
prediction: crop,
|
|
14
|
+
pageId: pageId,
|
|
15
|
+
}));
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
toString() {
|
|
20
|
+
const cropping = this.cropping
|
|
21
|
+
.map((crop) => crop.toString())
|
|
22
|
+
.join("\n ");
|
|
23
|
+
const outStr = `----- Cropper Data -----
|
|
24
|
+
Filename: ${this.filename}
|
|
25
|
+
Cropping: ${cropping}
|
|
26
|
+
------------------------
|
|
27
|
+
`;
|
|
28
|
+
return Cropper.cleanOutString(outStr);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Cropper = Cropper;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Document, DocumentConstructorProps } from "./document";
|
|
2
2
|
import { ClassificationField, ListField } from "../fields";
|
|
3
|
-
import { stringDict } from "../fields
|
|
3
|
+
import { stringDict } from "../fields";
|
|
4
4
|
export interface CustomDocConstructorProps extends DocumentConstructorProps {
|
|
5
5
|
documentType: string;
|
|
6
6
|
}
|
|
@@ -8,7 +8,7 @@ export declare class CustomDocument extends Document {
|
|
|
8
8
|
fields: Map<string, ListField>;
|
|
9
9
|
classifications: Map<string, ClassificationField>;
|
|
10
10
|
readonly documentType: string;
|
|
11
|
-
constructor({ inputFile,
|
|
11
|
+
constructor({ inputFile, prediction, extras, orientation, pageId, documentType, }: CustomDocConstructorProps);
|
|
12
12
|
protected setField(fieldName: string, apiPrediction: stringDict, pageId: number | undefined): void;
|
|
13
13
|
toString(): string;
|
|
14
14
|
}
|
package/src/documents/custom.js
CHANGED
|
@@ -4,13 +4,13 @@ exports.CustomDocument = void 0;
|
|
|
4
4
|
const document_1 = require("./document");
|
|
5
5
|
const fields_1 = require("../fields");
|
|
6
6
|
class CustomDocument extends document_1.Document {
|
|
7
|
-
constructor({ inputFile,
|
|
8
|
-
super(inputFile, pageId);
|
|
7
|
+
constructor({ inputFile, prediction, extras = undefined, orientation = undefined, pageId, documentType, }) {
|
|
8
|
+
super({ inputFile, pageId, orientation, extras });
|
|
9
9
|
this.fields = new Map();
|
|
10
10
|
this.classifications = new Map();
|
|
11
11
|
this.documentType = documentType;
|
|
12
|
-
Object.keys(
|
|
13
|
-
this.setField(fieldName,
|
|
12
|
+
Object.keys(prediction).forEach((fieldName) => {
|
|
13
|
+
this.setField(fieldName, prediction, pageId);
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
setField(fieldName, apiPrediction, pageId) {
|
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
import { Input } from "../inputs";
|
|
2
|
-
import { FullText } from "../fields";
|
|
3
|
-
export interface DocumentConstructorProps {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { CropperField, FullText, OrientationField, stringDict } from "../fields";
|
|
3
|
+
export interface DocumentConstructorProps extends BaseDocumentConstructorProps {
|
|
4
|
+
/** JSON parsed prediction from HTTP response */
|
|
5
|
+
prediction: stringDict;
|
|
6
|
+
}
|
|
7
|
+
interface BaseDocumentConstructorProps {
|
|
8
|
+
/** Orientation JSON for page-level document */
|
|
9
|
+
orientation?: stringDict;
|
|
10
|
+
/** Extras JSON */
|
|
11
|
+
extras?: stringDict;
|
|
12
|
+
/** input file given to parse the document */
|
|
7
13
|
inputFile?: Input;
|
|
14
|
+
/** Page ID for page-level document */
|
|
8
15
|
pageId?: number;
|
|
16
|
+
/** full OCR extracted text */
|
|
9
17
|
fullText?: FullText;
|
|
10
18
|
}
|
|
11
19
|
export declare class Document {
|
|
12
20
|
checklist: {
|
|
13
21
|
[index: string]: boolean;
|
|
14
22
|
};
|
|
15
|
-
mimeType
|
|
23
|
+
mimeType?: string;
|
|
16
24
|
filename: string;
|
|
17
|
-
filepath
|
|
25
|
+
filepath?: string;
|
|
18
26
|
fullText?: FullText;
|
|
19
27
|
pageId?: number | undefined;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* @param {Input} inputFile - input file given to parse the document
|
|
24
|
-
* @param {number} pageId - Page ID for multi-page document
|
|
25
|
-
* @param {FullText} fullText - full OCR extracted text
|
|
26
|
-
*/
|
|
27
|
-
constructor(inputFile?: Input, pageId?: number, fullText?: FullText);
|
|
28
|
+
orientation?: OrientationField;
|
|
29
|
+
cropper: CropperField[];
|
|
30
|
+
constructor({ orientation, extras, inputFile, fullText, pageId, }: BaseDocumentConstructorProps);
|
|
28
31
|
clone(): any;
|
|
29
32
|
/** return true if all checklist of the document if true */
|
|
30
33
|
checkAll(): boolean;
|
|
@@ -36,3 +39,4 @@ export declare class Document {
|
|
|
36
39
|
static mergePages(documents: any): any;
|
|
37
40
|
static cleanOutString(outStr: string): string;
|
|
38
41
|
}
|
|
42
|
+
export {};
|
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Document = void 0;
|
|
4
|
+
const fields_1 = require("../fields");
|
|
4
5
|
class Document {
|
|
5
|
-
|
|
6
|
-
* Takes a list of Documents and return one Document where
|
|
7
|
-
* each field is set with the maximum probability field
|
|
8
|
-
* @param {Input} inputFile - input file given to parse the document
|
|
9
|
-
* @param {number} pageId - Page ID for multi-page document
|
|
10
|
-
* @param {FullText} fullText - full OCR extracted text
|
|
11
|
-
*/
|
|
12
|
-
constructor(inputFile, pageId, fullText) {
|
|
6
|
+
constructor({ orientation = undefined, extras = undefined, inputFile = undefined, fullText = undefined, pageId = undefined, }) {
|
|
13
7
|
this.filename = "";
|
|
8
|
+
this.cropper = [];
|
|
14
9
|
this.filepath = undefined;
|
|
15
10
|
this.pageId = pageId;
|
|
11
|
+
if (pageId !== undefined && orientation !== undefined) {
|
|
12
|
+
this.orientation = new fields_1.OrientationField({
|
|
13
|
+
prediction: orientation,
|
|
14
|
+
pageId: pageId,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (extras !== undefined) {
|
|
18
|
+
if (extras.cropper !== undefined) {
|
|
19
|
+
extras.cropper.cropping.forEach((crop) => {
|
|
20
|
+
this.cropper.push(new fields_1.CropperField({
|
|
21
|
+
prediction: crop,
|
|
22
|
+
pageId: pageId,
|
|
23
|
+
}));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
16
27
|
if (inputFile !== undefined) {
|
|
17
28
|
this.filepath = inputFile.filepath;
|
|
18
29
|
this.filename = inputFile.filename;
|
|
@@ -15,12 +15,13 @@ export declare class DocumentConfig {
|
|
|
15
15
|
readonly documentType: string;
|
|
16
16
|
readonly endpoints: Array<Endpoint>;
|
|
17
17
|
constructor(documentType: string, endpoints: Array<Endpoint>);
|
|
18
|
-
predictRequest(inputDoc: Input, includeWords
|
|
18
|
+
predictRequest(inputDoc: Input, includeWords: boolean, cropping: boolean): Promise<unknown>;
|
|
19
19
|
buildResult<RespType extends Response<Document>>(responseType: responseSig<RespType>, inputFile: Input, response: any): RespType;
|
|
20
20
|
predict<RespType extends Response<Document>>(responseType: responseSig<RespType>, params: {
|
|
21
21
|
inputDoc: Input;
|
|
22
22
|
includeWords: boolean;
|
|
23
23
|
cutPages: boolean;
|
|
24
|
+
cropper: boolean;
|
|
24
25
|
}): Promise<RespType>;
|
|
25
26
|
cutDocPages(inputDoc: Input, cutPages: boolean): Promise<void>;
|
|
26
27
|
protected checkApiKeys(): void;
|
|
@@ -33,11 +34,14 @@ export declare class ReceiptConfig extends DocumentConfig {
|
|
|
33
34
|
}
|
|
34
35
|
export declare class FinancialDocConfig extends DocumentConfig {
|
|
35
36
|
constructor(apiKey: string);
|
|
36
|
-
predictRequest(inputDoc: Input, includeWords
|
|
37
|
+
predictRequest(inputDoc: Input, includeWords: boolean, cropping: boolean): Promise<unknown>;
|
|
37
38
|
}
|
|
38
39
|
export declare class PassportConfig extends DocumentConfig {
|
|
39
40
|
constructor(apiKey: string);
|
|
40
41
|
}
|
|
42
|
+
export declare class CropperConfig extends DocumentConfig {
|
|
43
|
+
constructor(apiKey: string);
|
|
44
|
+
}
|
|
41
45
|
export declare class CustomDocConfig extends DocumentConfig {
|
|
42
46
|
constructor({ documentType, accountName, version, apiKey, }: CustomDocConstructor);
|
|
43
47
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CustomDocConfig = exports.PassportConfig = exports.FinancialDocConfig = exports.ReceiptConfig = exports.InvoiceConfig = exports.DocumentConfig = void 0;
|
|
3
|
+
exports.CustomDocConfig = exports.CropperConfig = exports.PassportConfig = exports.FinancialDocConfig = exports.ReceiptConfig = exports.InvoiceConfig = exports.DocumentConfig = void 0;
|
|
4
4
|
const api_1 = require("../api");
|
|
5
5
|
const index_1 = require("./index");
|
|
6
6
|
const handler_1 = require("../errors/handler");
|
|
@@ -9,8 +9,8 @@ class DocumentConfig {
|
|
|
9
9
|
this.documentType = documentType;
|
|
10
10
|
this.endpoints = endpoints;
|
|
11
11
|
}
|
|
12
|
-
async predictRequest(inputDoc, includeWords
|
|
13
|
-
return await this.endpoints[0].predictRequest(inputDoc, includeWords);
|
|
12
|
+
async predictRequest(inputDoc, includeWords, cropping) {
|
|
13
|
+
return await this.endpoints[0].predictRequest(inputDoc, includeWords, cropping);
|
|
14
14
|
}
|
|
15
15
|
buildResult(responseType, inputFile, response) {
|
|
16
16
|
if (response.statusCode > 201) {
|
|
@@ -34,7 +34,7 @@ class DocumentConfig {
|
|
|
34
34
|
this.checkApiKeys();
|
|
35
35
|
await params.inputDoc.init();
|
|
36
36
|
await this.cutDocPages(params.inputDoc, params.cutPages);
|
|
37
|
-
const response = await this.predictRequest(params.inputDoc, params.includeWords);
|
|
37
|
+
const response = await this.predictRequest(params.inputDoc, params.includeWords, params.cropper);
|
|
38
38
|
return this.buildResult(responseType, params.inputDoc, response);
|
|
39
39
|
}
|
|
40
40
|
async cutDocPages(inputDoc, cutPages) {
|
|
@@ -74,7 +74,7 @@ class FinancialDocConfig extends DocumentConfig {
|
|
|
74
74
|
];
|
|
75
75
|
super(index_1.DOC_TYPE_FINANCIAL, endpoints);
|
|
76
76
|
}
|
|
77
|
-
async predictRequest(inputDoc, includeWords
|
|
77
|
+
async predictRequest(inputDoc, includeWords, cropping) {
|
|
78
78
|
let endpoint;
|
|
79
79
|
if (inputDoc.isPdf()) {
|
|
80
80
|
endpoint = this.endpoints[0];
|
|
@@ -82,7 +82,7 @@ class FinancialDocConfig extends DocumentConfig {
|
|
|
82
82
|
else {
|
|
83
83
|
endpoint = this.endpoints[1];
|
|
84
84
|
}
|
|
85
|
-
return await endpoint.predictRequest(inputDoc, includeWords);
|
|
85
|
+
return await endpoint.predictRequest(inputDoc, includeWords, cropping);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
exports.FinancialDocConfig = FinancialDocConfig;
|
|
@@ -93,6 +93,13 @@ class PassportConfig extends DocumentConfig {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
exports.PassportConfig = PassportConfig;
|
|
96
|
+
class CropperConfig extends DocumentConfig {
|
|
97
|
+
constructor(apiKey) {
|
|
98
|
+
const endpoints = [new api_1.CropperEndpoint(apiKey)];
|
|
99
|
+
super(index_1.DOC_TYPE_CROPPER, endpoints);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.CropperConfig = CropperConfig;
|
|
96
103
|
class CustomDocConfig extends DocumentConfig {
|
|
97
104
|
constructor({ documentType, accountName, version, apiKey, }) {
|
|
98
105
|
const endpoints = [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Document, DocumentConstructorProps } from "./document";
|
|
2
|
-
import { TaxField, Field, Amount, Locale,
|
|
2
|
+
import { TaxField, Field, Amount, Locale, DateField as Date, CompanyRegistration } from "../fields";
|
|
3
3
|
export declare class FinancialDocument extends Document {
|
|
4
4
|
#private;
|
|
5
5
|
pageId: number | undefined;
|
|
@@ -9,7 +9,6 @@ export declare class FinancialDocument extends Document {
|
|
|
9
9
|
dueDate: Date;
|
|
10
10
|
category: Field;
|
|
11
11
|
time: Field;
|
|
12
|
-
orientation: Orientation | undefined;
|
|
13
12
|
taxes: TaxField[];
|
|
14
13
|
totalTax: Amount;
|
|
15
14
|
totalExcl: Amount;
|
|
@@ -21,12 +20,6 @@ export declare class FinancialDocument extends Document {
|
|
|
21
20
|
customerAddress: Field;
|
|
22
21
|
paymentDetails: Field[];
|
|
23
22
|
customerCompanyRegistration: CompanyRegistration[];
|
|
24
|
-
|
|
25
|
-
* @param {Object} apiPrediction - Json parsed prediction from HTTP response
|
|
26
|
-
* @param {Input} inputFile - input file given to parse the document
|
|
27
|
-
* @param {number} pageId - Page ID for multi-page document
|
|
28
|
-
* @param {FullText} fullText - full OCR extracted text
|
|
29
|
-
*/
|
|
30
|
-
constructor({ apiPrediction, inputFile, fullText, pageId, }: DocumentConstructorProps);
|
|
23
|
+
constructor({ prediction, orientation, extras, inputFile, fullText, pageId, }: DocumentConstructorProps);
|
|
31
24
|
toString(): string;
|
|
32
25
|
}
|
|
@@ -12,20 +12,14 @@ const invoice_1 = require("./invoice");
|
|
|
12
12
|
const receipt_1 = require("./receipt");
|
|
13
13
|
const fields_1 = require("../fields");
|
|
14
14
|
class FinancialDocument extends document_1.Document {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* @param {Input} inputFile - input file given to parse the document
|
|
18
|
-
* @param {number} pageId - Page ID for multi-page document
|
|
19
|
-
* @param {FullText} fullText - full OCR extracted text
|
|
20
|
-
*/
|
|
21
|
-
constructor({ apiPrediction, inputFile = undefined, fullText = undefined, pageId = undefined, }) {
|
|
22
|
-
super(inputFile, pageId, fullText);
|
|
15
|
+
constructor({ prediction, orientation = undefined, extras = undefined, inputFile = undefined, fullText = undefined, pageId = undefined, }) {
|
|
16
|
+
super({ inputFile, pageId, fullText, orientation, extras });
|
|
23
17
|
_FinancialDocument_instances.add(this);
|
|
24
18
|
this.taxes = [];
|
|
25
19
|
this.companyRegistration = [];
|
|
26
20
|
this.paymentDetails = [];
|
|
27
21
|
this.customerCompanyRegistration = [];
|
|
28
|
-
__classPrivateFieldGet(this, _FinancialDocument_instances, "m", _FinancialDocument_initFromApiPrediction).call(this,
|
|
22
|
+
__classPrivateFieldGet(this, _FinancialDocument_instances, "m", _FinancialDocument_initFromApiPrediction).call(this, prediction, inputFile, pageId, orientation, extras);
|
|
29
23
|
__classPrivateFieldGet(this, _FinancialDocument_instances, "m", _FinancialDocument_checklist).call(this);
|
|
30
24
|
}
|
|
31
25
|
toString() {
|
|
@@ -41,12 +35,14 @@ Total taxes: ${this.totalTax.value}
|
|
|
41
35
|
}
|
|
42
36
|
}
|
|
43
37
|
exports.FinancialDocument = FinancialDocument;
|
|
44
|
-
_FinancialDocument_instances = new WeakSet(), _FinancialDocument_initFromApiPrediction = function _FinancialDocument_initFromApiPrediction(prediction, inputFile, pageNumber) {
|
|
38
|
+
_FinancialDocument_instances = new WeakSet(), _FinancialDocument_initFromApiPrediction = function _FinancialDocument_initFromApiPrediction(prediction, inputFile, pageNumber, orientation, extras) {
|
|
45
39
|
if (Object.keys(prediction).includes("invoice_number")) {
|
|
46
40
|
const invoice = new invoice_1.Invoice({
|
|
47
|
-
|
|
41
|
+
prediction: prediction,
|
|
48
42
|
inputFile,
|
|
49
43
|
pageId: pageNumber,
|
|
44
|
+
orientation: orientation,
|
|
45
|
+
extras: extras,
|
|
50
46
|
});
|
|
51
47
|
this.locale = invoice.locale;
|
|
52
48
|
this.totalIncl = invoice.totalIncl;
|
|
@@ -70,9 +66,11 @@ _FinancialDocument_instances = new WeakSet(), _FinancialDocument_initFromApiPred
|
|
|
70
66
|
}
|
|
71
67
|
else {
|
|
72
68
|
const receipt = new receipt_1.Receipt({
|
|
73
|
-
|
|
69
|
+
prediction: prediction,
|
|
74
70
|
inputFile,
|
|
75
71
|
pageId: pageNumber,
|
|
72
|
+
orientation: orientation,
|
|
73
|
+
extras: extras,
|
|
76
74
|
});
|
|
77
75
|
this.orientation = receipt.orientation;
|
|
78
76
|
this.date = receipt.date;
|
package/src/documents/index.d.ts
CHANGED
|
@@ -3,10 +3,12 @@ import { Receipt } from "./receipt";
|
|
|
3
3
|
import { Passport } from "./passport";
|
|
4
4
|
import { FinancialDocument } from "./financialDocument";
|
|
5
5
|
import { CustomDocument } from "./custom";
|
|
6
|
+
import { Cropper } from "./cropper";
|
|
6
7
|
export { Document, DocumentConstructorProps } from "./document";
|
|
7
|
-
export { Receipt, Invoice, FinancialDocument, Passport, CustomDocument };
|
|
8
|
+
export { Receipt, Invoice, FinancialDocument, Passport, CustomDocument, Cropper, };
|
|
8
9
|
export declare const DOC_TYPE_INVOICE: string;
|
|
9
10
|
export declare const DOC_TYPE_RECEIPT: string;
|
|
10
11
|
export declare const DOC_TYPE_PASSPORT: string;
|
|
11
12
|
export declare const DOC_TYPE_FINANCIAL: string;
|
|
12
13
|
export declare const DOC_TYPE_CUSTOM: string;
|
|
14
|
+
export declare const DOC_TYPE_CROPPER: string;
|
package/src/documents/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DOC_TYPE_CUSTOM = exports.DOC_TYPE_FINANCIAL = exports.DOC_TYPE_PASSPORT = exports.DOC_TYPE_RECEIPT = exports.DOC_TYPE_INVOICE = exports.CustomDocument = exports.Passport = exports.FinancialDocument = exports.Invoice = exports.Receipt = exports.Document = void 0;
|
|
3
|
+
exports.DOC_TYPE_CROPPER = exports.DOC_TYPE_CUSTOM = exports.DOC_TYPE_FINANCIAL = exports.DOC_TYPE_PASSPORT = exports.DOC_TYPE_RECEIPT = exports.DOC_TYPE_INVOICE = exports.Cropper = exports.CustomDocument = exports.Passport = exports.FinancialDocument = exports.Invoice = exports.Receipt = exports.Document = void 0;
|
|
4
4
|
const invoice_1 = require("./invoice");
|
|
5
5
|
Object.defineProperty(exports, "Invoice", { enumerable: true, get: function () { return invoice_1.Invoice; } });
|
|
6
6
|
const receipt_1 = require("./receipt");
|
|
@@ -11,6 +11,8 @@ const financialDocument_1 = require("./financialDocument");
|
|
|
11
11
|
Object.defineProperty(exports, "FinancialDocument", { enumerable: true, get: function () { return financialDocument_1.FinancialDocument; } });
|
|
12
12
|
const custom_1 = require("./custom");
|
|
13
13
|
Object.defineProperty(exports, "CustomDocument", { enumerable: true, get: function () { return custom_1.CustomDocument; } });
|
|
14
|
+
const cropper_1 = require("./cropper");
|
|
15
|
+
Object.defineProperty(exports, "Cropper", { enumerable: true, get: function () { return cropper_1.Cropper; } });
|
|
14
16
|
var document_1 = require("./document");
|
|
15
17
|
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
|
|
16
18
|
exports.DOC_TYPE_INVOICE = invoice_1.Invoice.name;
|
|
@@ -18,3 +20,4 @@ exports.DOC_TYPE_RECEIPT = receipt_1.Receipt.name;
|
|
|
18
20
|
exports.DOC_TYPE_PASSPORT = passport_1.Passport.name;
|
|
19
21
|
exports.DOC_TYPE_FINANCIAL = financialDocument_1.FinancialDocument.name;
|
|
20
22
|
exports.DOC_TYPE_CUSTOM = custom_1.CustomDocument.name;
|
|
23
|
+
exports.DOC_TYPE_CROPPER = cropper_1.Cropper.name;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Document, DocumentConstructorProps } from "./document";
|
|
2
|
-
import { BaseField, TaxField, PaymentDetails,
|
|
2
|
+
import { BaseField, TaxField, PaymentDetails, Locale, Amount, Field, DateField, CompanyRegistration } from "../fields";
|
|
3
3
|
export declare class Invoice extends Document {
|
|
4
4
|
#private;
|
|
5
5
|
locale: Locale;
|
|
@@ -8,7 +8,6 @@ export declare class Invoice extends Document {
|
|
|
8
8
|
date: DateField;
|
|
9
9
|
dueDate: DateField;
|
|
10
10
|
time: Field;
|
|
11
|
-
orientation: Orientation;
|
|
12
11
|
totalTax: Amount;
|
|
13
12
|
totalExcl: Amount;
|
|
14
13
|
supplier: Field;
|
|
@@ -20,13 +19,7 @@ export declare class Invoice extends Document {
|
|
|
20
19
|
taxes: TaxField[];
|
|
21
20
|
paymentDetails: PaymentDetails[];
|
|
22
21
|
customerCompanyRegistration: CompanyRegistration[];
|
|
23
|
-
|
|
24
|
-
* @param {Object} apiPrediction - Json parsed prediction from HTTP response
|
|
25
|
-
* @param {Input} inputFile - input file given to parse the document
|
|
26
|
-
* @param {number} pageId - Page ID for multi-page document
|
|
27
|
-
* @param {FullText} fullText - full OCR extracted text
|
|
28
|
-
*/
|
|
29
|
-
constructor({ apiPrediction, inputFile, fullText, pageId, }: DocumentConstructorProps);
|
|
22
|
+
constructor({ prediction, orientation, extras, inputFile, fullText, pageId, }: DocumentConstructorProps);
|
|
30
23
|
toString(): string;
|
|
31
24
|
private taxesMatchTotalIncl;
|
|
32
25
|
/**
|
package/src/documents/invoice.js
CHANGED
|
@@ -10,20 +10,14 @@ exports.Invoice = void 0;
|
|
|
10
10
|
const document_1 = require("./document");
|
|
11
11
|
const fields_1 = require("../fields");
|
|
12
12
|
class Invoice extends document_1.Document {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @param {Input} inputFile - input file given to parse the document
|
|
16
|
-
* @param {number} pageId - Page ID for multi-page document
|
|
17
|
-
* @param {FullText} fullText - full OCR extracted text
|
|
18
|
-
*/
|
|
19
|
-
constructor({ apiPrediction, inputFile = undefined, fullText = undefined, pageId = undefined, }) {
|
|
20
|
-
super(inputFile, pageId, fullText);
|
|
13
|
+
constructor({ prediction, orientation = undefined, extras = undefined, inputFile = undefined, fullText = undefined, pageId = undefined, }) {
|
|
14
|
+
super({ inputFile, pageId, fullText, orientation, extras });
|
|
21
15
|
_Invoice_instances.add(this);
|
|
22
16
|
this.companyRegistration = [];
|
|
23
17
|
this.taxes = [];
|
|
24
18
|
this.paymentDetails = [];
|
|
25
19
|
this.customerCompanyRegistration = [];
|
|
26
|
-
__classPrivateFieldGet(this, _Invoice_instances, "m", _Invoice_initFromApiPrediction).call(this,
|
|
20
|
+
__classPrivateFieldGet(this, _Invoice_instances, "m", _Invoice_initFromApiPrediction).call(this, prediction, pageId);
|
|
27
21
|
__classPrivateFieldGet(this, _Invoice_instances, "m", _Invoice_checklist).call(this);
|
|
28
22
|
__classPrivateFieldGet(this, _Invoice_instances, "m", _Invoice_reconstruct).call(this);
|
|
29
23
|
}
|
|
@@ -218,12 +212,6 @@ _Invoice_instances = new WeakSet(), _Invoice_initFromApiPrediction = function _I
|
|
|
218
212
|
prediction: prediction,
|
|
219
213
|
pageId: pageId,
|
|
220
214
|
})));
|
|
221
|
-
if (pageId !== undefined) {
|
|
222
|
-
this.orientation = new fields_1.Orientation({
|
|
223
|
-
prediction: apiPrediction.orientation,
|
|
224
|
-
pageId: pageId,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
215
|
}, _Invoice_checklist = function _Invoice_checklist() {
|
|
228
216
|
this.checklist = {
|
|
229
217
|
taxesMatchTotalIncl: this.taxesMatchTotalIncl(),
|
|
@@ -15,13 +15,7 @@ export declare class Passport extends Document {
|
|
|
15
15
|
givenNames: Field[];
|
|
16
16
|
fullName: Field;
|
|
17
17
|
mrz: Field;
|
|
18
|
-
|
|
19
|
-
* @param {Object} apiPrediction - Json parsed prediction from HTTP response
|
|
20
|
-
* @param {Input} inputFile - input file given to parse the document
|
|
21
|
-
* @param {number} pageId - Page ID for multi-page document
|
|
22
|
-
* @param {FullText} fullText - full OCR extracted text
|
|
23
|
-
*/
|
|
24
|
-
constructor({ apiPrediction, inputFile, pageId, }: DocumentConstructorProps);
|
|
18
|
+
constructor({ prediction, orientation, extras, inputFile, pageId, }: DocumentConstructorProps);
|
|
25
19
|
static convertMRZDateToDatetime(dateString: string): Date;
|
|
26
20
|
toString(): string;
|
|
27
21
|
isExpired(): boolean;
|
|
@@ -35,57 +35,51 @@ const fields_1 = require("../fields");
|
|
|
35
35
|
// @ts-ignore
|
|
36
36
|
const MRZ = __importStar(require("mrz"));
|
|
37
37
|
class Passport extends document_1.Document {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* @param {Input} inputFile - input file given to parse the document
|
|
41
|
-
* @param {number} pageId - Page ID for multi-page document
|
|
42
|
-
* @param {FullText} fullText - full OCR extracted text
|
|
43
|
-
*/
|
|
44
|
-
constructor({ apiPrediction, inputFile = undefined, pageId = undefined, }) {
|
|
45
|
-
super(inputFile, pageId);
|
|
38
|
+
constructor({ prediction, orientation = undefined, extras = undefined, inputFile = undefined, pageId = undefined, }) {
|
|
39
|
+
super({ inputFile, pageId, orientation, extras });
|
|
46
40
|
_Passport_instances.add(this);
|
|
47
41
|
this.givenNames = [];
|
|
48
42
|
this.country = new fields_1.Field({
|
|
49
|
-
prediction:
|
|
43
|
+
prediction: prediction.country,
|
|
50
44
|
pageId: pageId,
|
|
51
45
|
});
|
|
52
46
|
this.idNumber = new fields_1.Field({
|
|
53
|
-
prediction:
|
|
47
|
+
prediction: prediction.id_number,
|
|
54
48
|
pageId: pageId,
|
|
55
49
|
});
|
|
56
50
|
this.birthDate = new fields_1.DateField({
|
|
57
|
-
prediction:
|
|
51
|
+
prediction: prediction.birth_date,
|
|
58
52
|
pageId: pageId,
|
|
59
53
|
});
|
|
60
54
|
this.expiryDate = new fields_1.DateField({
|
|
61
|
-
prediction:
|
|
55
|
+
prediction: prediction.expiry_date,
|
|
62
56
|
pageId: pageId,
|
|
63
57
|
});
|
|
64
58
|
this.issuanceDate = new fields_1.DateField({
|
|
65
|
-
prediction:
|
|
59
|
+
prediction: prediction.issuance_date,
|
|
66
60
|
pageId: pageId,
|
|
67
61
|
});
|
|
68
62
|
this.birthPlace = new fields_1.Field({
|
|
69
|
-
prediction:
|
|
63
|
+
prediction: prediction.birth_place,
|
|
70
64
|
pageId: pageId,
|
|
71
65
|
});
|
|
72
66
|
this.gender = new fields_1.Field({
|
|
73
|
-
prediction:
|
|
67
|
+
prediction: prediction.gender,
|
|
74
68
|
pageId: pageId,
|
|
75
69
|
});
|
|
76
70
|
this.surname = new fields_1.Field({
|
|
77
|
-
prediction:
|
|
71
|
+
prediction: prediction.surname,
|
|
78
72
|
pageId: pageId,
|
|
79
73
|
});
|
|
80
74
|
this.mrz1 = new fields_1.Field({
|
|
81
|
-
prediction:
|
|
75
|
+
prediction: prediction.mrz1,
|
|
82
76
|
pageId: pageId,
|
|
83
77
|
});
|
|
84
78
|
this.mrz2 = new fields_1.Field({
|
|
85
|
-
prediction:
|
|
79
|
+
prediction: prediction.mrz2,
|
|
86
80
|
pageId: pageId,
|
|
87
81
|
});
|
|
88
|
-
|
|
82
|
+
prediction.given_names.map((prediction) => this.givenNames.push(new fields_1.Field({
|
|
89
83
|
prediction: prediction,
|
|
90
84
|
pageId: pageId,
|
|
91
85
|
})));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Document, DocumentConstructorProps } from "./document";
|
|
2
|
-
import { TaxField, Field, Amount, Locale,
|
|
2
|
+
import { TaxField, Field, Amount, Locale, DateField } from "../fields";
|
|
3
3
|
export declare class Receipt extends Document {
|
|
4
4
|
#private;
|
|
5
5
|
locale: Locale;
|
|
@@ -9,16 +9,9 @@ export declare class Receipt extends Document {
|
|
|
9
9
|
category: Field;
|
|
10
10
|
merchantName: Field;
|
|
11
11
|
time: Field;
|
|
12
|
-
orientation: Orientation | undefined;
|
|
13
12
|
totalTax: Amount;
|
|
14
13
|
totalExcl: Amount;
|
|
15
14
|
taxes: TaxField[];
|
|
16
|
-
|
|
17
|
-
* @param {Object} apiPrediction - Json parsed prediction from HTTP response
|
|
18
|
-
* @param {Input} inputFile - input file given to parse the document
|
|
19
|
-
* @param {number} pageId - Page ID for multi-page document
|
|
20
|
-
* @param {FullText} fullText - full OCR extracted text
|
|
21
|
-
*/
|
|
22
|
-
constructor({ apiPrediction, inputFile, fullText, pageId, }: DocumentConstructorProps);
|
|
15
|
+
constructor({ prediction, orientation, extras, inputFile, fullText, pageId, }: DocumentConstructorProps);
|
|
23
16
|
toString(): string;
|
|
24
17
|
}
|
package/src/documents/receipt.js
CHANGED
|
@@ -10,18 +10,12 @@ exports.Receipt = void 0;
|
|
|
10
10
|
const document_1 = require("./document");
|
|
11
11
|
const fields_1 = require("../fields");
|
|
12
12
|
class Receipt extends document_1.Document {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @param {Input} inputFile - input file given to parse the document
|
|
16
|
-
* @param {number} pageId - Page ID for multi-page document
|
|
17
|
-
* @param {FullText} fullText - full OCR extracted text
|
|
18
|
-
*/
|
|
19
|
-
constructor({ apiPrediction, inputFile = undefined, fullText = undefined, pageId = undefined, }) {
|
|
20
|
-
super(inputFile, pageId, fullText);
|
|
13
|
+
constructor({ prediction, orientation = undefined, extras = undefined, inputFile = undefined, fullText = undefined, pageId = undefined, }) {
|
|
14
|
+
super({ inputFile, pageId, fullText, orientation, extras });
|
|
21
15
|
_Receipt_instances.add(this);
|
|
22
16
|
this.taxes = [];
|
|
23
17
|
this.locale = new fields_1.Locale({
|
|
24
|
-
prediction:
|
|
18
|
+
prediction: prediction.locale,
|
|
25
19
|
pageId: pageId,
|
|
26
20
|
});
|
|
27
21
|
this.totalTax = new fields_1.Amount({
|
|
@@ -34,7 +28,7 @@ class Receipt extends document_1.Document {
|
|
|
34
28
|
valueKey: "value",
|
|
35
29
|
pageId: pageId,
|
|
36
30
|
});
|
|
37
|
-
__classPrivateFieldGet(this, _Receipt_instances, "m", _Receipt_initFromApiPrediction).call(this,
|
|
31
|
+
__classPrivateFieldGet(this, _Receipt_instances, "m", _Receipt_initFromApiPrediction).call(this, prediction, pageId);
|
|
38
32
|
__classPrivateFieldGet(this, _Receipt_instances, "m", _Receipt_checklist).call(this);
|
|
39
33
|
__classPrivateFieldGet(this, _Receipt_instances, "m", _Receipt_reconstruct).call(this);
|
|
40
34
|
}
|
|
@@ -86,12 +80,6 @@ _Receipt_instances = new WeakSet(), _Receipt_initFromApiPrediction = function _R
|
|
|
86
80
|
rateKey: "rate",
|
|
87
81
|
codeKey: "code",
|
|
88
82
|
})));
|
|
89
|
-
if (pageId !== undefined) {
|
|
90
|
-
this.orientation = new fields_1.Orientation({
|
|
91
|
-
prediction: apiPrediction.orientation,
|
|
92
|
-
pageId,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
83
|
}, _Receipt_checklist = function _Receipt_checklist() {
|
|
96
84
|
this.checklist = { taxesMatchTotalIncl: __classPrivateFieldGet(this, _Receipt_instances, "m", _Receipt_taxesMatchTotal).call(this) };
|
|
97
85
|
}, _Receipt_taxesMatchTotal = function _Receipt_taxesMatchTotal() {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseField, FieldConstructor } from "./field";
|
|
2
|
+
import { Polygon } from "../geometry";
|
|
3
|
+
export declare class CropperField extends BaseField {
|
|
4
|
+
/** Straight rectangle. */
|
|
5
|
+
boundingBox: Polygon;
|
|
6
|
+
/** Free polygon with up to 30 vertices. */
|
|
7
|
+
polygon: Polygon;
|
|
8
|
+
/** Free polygon with 4 vertices. */
|
|
9
|
+
quadrangle: Polygon;
|
|
10
|
+
/** Rectangle that may be oriented (can go beyond the canvas). */
|
|
11
|
+
rectangle: Polygon;
|
|
12
|
+
/** The document page on which the information was found. */
|
|
13
|
+
pageId: number | undefined;
|
|
14
|
+
constructor({ prediction, valueKey, pageId }: FieldConstructor);
|
|
15
|
+
toString(): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CropperField = void 0;
|
|
4
|
+
const field_1 = require("./field");
|
|
5
|
+
class CropperField extends field_1.BaseField {
|
|
6
|
+
constructor({ prediction, valueKey = "polygon", pageId }) {
|
|
7
|
+
super({ prediction, valueKey });
|
|
8
|
+
this.pageId = pageId;
|
|
9
|
+
this.boundingBox = prediction.bounding_box;
|
|
10
|
+
this.polygon = prediction.polygon;
|
|
11
|
+
this.quadrangle = prediction.quadrangle;
|
|
12
|
+
this.rectangle = prediction.rectangle;
|
|
13
|
+
}
|
|
14
|
+
toString() {
|
|
15
|
+
return `Polygon with ${this.polygon.length} points.`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.CropperField = CropperField;
|
package/src/fields/field.d.ts
CHANGED
|
@@ -3,24 +3,28 @@ export declare type stringDict = {
|
|
|
3
3
|
[index: string]: any;
|
|
4
4
|
};
|
|
5
5
|
export interface FieldConstructor {
|
|
6
|
-
prediction:
|
|
7
|
-
[index: string]: any;
|
|
8
|
-
};
|
|
6
|
+
prediction: stringDict;
|
|
9
7
|
valueKey?: string;
|
|
10
8
|
reconstructed?: boolean;
|
|
11
9
|
pageId?: number | undefined;
|
|
12
10
|
}
|
|
13
|
-
interface BaseFieldConstructor {
|
|
11
|
+
export interface BaseFieldConstructor {
|
|
14
12
|
prediction: stringDict;
|
|
15
|
-
valueKey
|
|
13
|
+
valueKey?: string;
|
|
14
|
+
reconstructed?: boolean;
|
|
16
15
|
}
|
|
17
16
|
export declare class BaseField {
|
|
18
17
|
value?: any;
|
|
18
|
+
/**
|
|
19
|
+
* True if the field was reconstructed or computed using other fields.
|
|
20
|
+
*/
|
|
21
|
+
reconstructed: boolean;
|
|
19
22
|
/**
|
|
20
23
|
* @param {Object} prediction - Prediction object from HTTP response
|
|
21
24
|
* @param {String} valueKey - Key to use in the prediction dict
|
|
25
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
22
26
|
*/
|
|
23
|
-
constructor({ prediction, valueKey }: BaseFieldConstructor);
|
|
27
|
+
constructor({ prediction, valueKey, reconstructed, }: BaseFieldConstructor);
|
|
24
28
|
}
|
|
25
29
|
export declare class Field extends BaseField {
|
|
26
30
|
/**
|
|
@@ -39,10 +43,6 @@ export declare class Field extends BaseField {
|
|
|
39
43
|
* The confidence score of the prediction.
|
|
40
44
|
*/
|
|
41
45
|
confidence: number;
|
|
42
|
-
/**
|
|
43
|
-
* True if the field was reconstructed or computed using other fields.
|
|
44
|
-
*/
|
|
45
|
-
reconstructed: boolean;
|
|
46
46
|
/**
|
|
47
47
|
* @param {Object} prediction - Prediction object from HTTP response
|
|
48
48
|
* @param {String} valueKey - Key to use in the prediction dict
|
|
@@ -71,4 +71,3 @@ export declare class Field extends BaseField {
|
|
|
71
71
|
static arraySum(array: any): number;
|
|
72
72
|
toString(): string;
|
|
73
73
|
}
|
|
74
|
-
export {};
|
package/src/fields/field.js
CHANGED
|
@@ -6,9 +6,11 @@ class BaseField {
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {Object} prediction - Prediction object from HTTP response
|
|
8
8
|
* @param {String} valueKey - Key to use in the prediction dict
|
|
9
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
9
10
|
*/
|
|
10
|
-
constructor({ prediction, valueKey }) {
|
|
11
|
+
constructor({ prediction, valueKey = "value", reconstructed = false, }) {
|
|
11
12
|
this.value = undefined;
|
|
13
|
+
this.reconstructed = reconstructed;
|
|
12
14
|
if (valueKey in prediction && prediction[valueKey] !== null) {
|
|
13
15
|
this.value = prediction[valueKey];
|
|
14
16
|
}
|
|
@@ -24,7 +26,7 @@ class Field extends BaseField {
|
|
|
24
26
|
* @param {Array<String>} extraFields - Extra fields to get from the prediction and to set as attribute of the Field
|
|
25
27
|
*/
|
|
26
28
|
constructor({ prediction, valueKey = "value", reconstructed = false, pageId, }) {
|
|
27
|
-
super({ prediction, valueKey });
|
|
29
|
+
super({ prediction, valueKey, reconstructed });
|
|
28
30
|
/**
|
|
29
31
|
* Contains exactly 4 relative vertices coordinates (points) of a right
|
|
30
32
|
* rectangle containing the field in the document.
|
|
@@ -36,7 +38,6 @@ class Field extends BaseField {
|
|
|
36
38
|
*/
|
|
37
39
|
this.polygon = [];
|
|
38
40
|
this.pageId = pageId !== undefined ? pageId : prediction["page_id"];
|
|
39
|
-
this.reconstructed = reconstructed;
|
|
40
41
|
this.confidence = prediction.confidence ? prediction.confidence : 0.0;
|
|
41
42
|
if (prediction.polygon) {
|
|
42
43
|
this.polygon = prediction.polygon;
|
package/src/fields/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { TaxField } from "./tax";
|
|
2
2
|
export { PaymentDetails } from "./paymentDetails";
|
|
3
|
-
export {
|
|
3
|
+
export { OrientationField } from "./orientation";
|
|
4
4
|
export { Locale } from "./locale";
|
|
5
5
|
export { Amount } from "./amount";
|
|
6
6
|
export { DateField } from "./date";
|
|
7
|
-
export { BaseField } from "./field";
|
|
8
|
-
export { Field } from "./field";
|
|
7
|
+
export { BaseField, stringDict, Field } from "./field";
|
|
9
8
|
export { ListField, ListFieldValue, ClassificationField } from "./customDocs";
|
|
10
9
|
export { FullText } from "./fullText";
|
|
11
10
|
export { CompanyRegistration } from "./companyRegistration";
|
|
11
|
+
export { CropperField } from "./cropper";
|
package/src/fields/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompanyRegistration = exports.FullText = exports.ClassificationField = exports.ListFieldValue = exports.ListField = exports.Field = exports.BaseField = exports.DateField = exports.Amount = exports.Locale = exports.
|
|
3
|
+
exports.CropperField = exports.CompanyRegistration = exports.FullText = exports.ClassificationField = exports.ListFieldValue = exports.ListField = exports.Field = exports.BaseField = exports.DateField = exports.Amount = exports.Locale = exports.OrientationField = exports.PaymentDetails = exports.TaxField = void 0;
|
|
4
4
|
var tax_1 = require("./tax");
|
|
5
5
|
Object.defineProperty(exports, "TaxField", { enumerable: true, get: function () { return tax_1.TaxField; } });
|
|
6
6
|
var paymentDetails_1 = require("./paymentDetails");
|
|
7
7
|
Object.defineProperty(exports, "PaymentDetails", { enumerable: true, get: function () { return paymentDetails_1.PaymentDetails; } });
|
|
8
8
|
var orientation_1 = require("./orientation");
|
|
9
|
-
Object.defineProperty(exports, "
|
|
9
|
+
Object.defineProperty(exports, "OrientationField", { enumerable: true, get: function () { return orientation_1.OrientationField; } });
|
|
10
10
|
var locale_1 = require("./locale");
|
|
11
11
|
Object.defineProperty(exports, "Locale", { enumerable: true, get: function () { return locale_1.Locale; } });
|
|
12
12
|
var amount_1 = require("./amount");
|
|
@@ -15,8 +15,7 @@ var date_1 = require("./date");
|
|
|
15
15
|
Object.defineProperty(exports, "DateField", { enumerable: true, get: function () { return date_1.DateField; } });
|
|
16
16
|
var field_1 = require("./field");
|
|
17
17
|
Object.defineProperty(exports, "BaseField", { enumerable: true, get: function () { return field_1.BaseField; } });
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return field_2.Field; } });
|
|
18
|
+
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return field_1.Field; } });
|
|
20
19
|
var customDocs_1 = require("./customDocs");
|
|
21
20
|
Object.defineProperty(exports, "ListField", { enumerable: true, get: function () { return customDocs_1.ListField; } });
|
|
22
21
|
Object.defineProperty(exports, "ListFieldValue", { enumerable: true, get: function () { return customDocs_1.ListFieldValue; } });
|
|
@@ -25,3 +24,5 @@ var fullText_1 = require("./fullText");
|
|
|
25
24
|
Object.defineProperty(exports, "FullText", { enumerable: true, get: function () { return fullText_1.FullText; } });
|
|
26
25
|
var companyRegistration_1 = require("./companyRegistration");
|
|
27
26
|
Object.defineProperty(exports, "CompanyRegistration", { enumerable: true, get: function () { return companyRegistration_1.CompanyRegistration; } });
|
|
27
|
+
var cropper_1 = require("./cropper");
|
|
28
|
+
Object.defineProperty(exports, "CropperField", { enumerable: true, get: function () { return cropper_1.CropperField; } });
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BaseField, BaseFieldConstructor } from "./field";
|
|
2
|
+
interface OrientationFieldConstructor extends BaseFieldConstructor {
|
|
3
|
+
pageId: number;
|
|
4
|
+
}
|
|
5
|
+
export declare class OrientationField extends BaseField {
|
|
6
|
+
value: number;
|
|
7
|
+
pageId: number;
|
|
3
8
|
/**
|
|
4
9
|
* @param {Object} prediction - Prediction object from HTTP response
|
|
5
10
|
* @param {String} valueKey - Key to use in the prediction dict
|
|
6
11
|
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
7
12
|
* @param {Integer} pageId - Page ID for multi-page document
|
|
8
13
|
*/
|
|
9
|
-
constructor({ prediction, valueKey, reconstructed, pageId, }:
|
|
14
|
+
constructor({ prediction, valueKey, reconstructed, pageId, }: OrientationFieldConstructor);
|
|
15
|
+
toString(): string;
|
|
10
16
|
}
|
|
17
|
+
export {};
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.OrientationField = void 0;
|
|
4
4
|
const field_1 = require("./field");
|
|
5
|
-
class
|
|
5
|
+
class OrientationField extends field_1.BaseField {
|
|
6
6
|
/**
|
|
7
7
|
* @param {Object} prediction - Prediction object from HTTP response
|
|
8
8
|
* @param {String} valueKey - Key to use in the prediction dict
|
|
9
9
|
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
10
10
|
* @param {Integer} pageId - Page ID for multi-page document
|
|
11
11
|
*/
|
|
12
|
-
constructor({ prediction, valueKey = "
|
|
12
|
+
constructor({ prediction, valueKey = "value", reconstructed = false, pageId, }) {
|
|
13
|
+
super({ prediction, valueKey, reconstructed });
|
|
13
14
|
const orientations = [0, 90, 180, 270];
|
|
14
|
-
|
|
15
|
+
this.pageId = pageId;
|
|
15
16
|
this.value = parseInt(prediction[valueKey]);
|
|
16
|
-
if (isNaN(this.value))
|
|
17
|
-
this.confidence = 0.0;
|
|
18
17
|
if (!orientations.includes(this.value))
|
|
19
18
|
this.value = 0;
|
|
20
19
|
}
|
|
20
|
+
toString() {
|
|
21
|
+
return `${this.value} degrees`;
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
|
-
exports.
|
|
24
|
+
exports.OrientationField = OrientationField;
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Response, FinancialDocResponse, InvoiceResponse, PassportResponse, ReceiptResponse, CustomResponse, } from "./api";
|
|
1
|
+
export { Response, FinancialDocResponse, InvoiceResponse, PassportResponse, ReceiptResponse, CustomResponse, CropperResponse, } from "./api";
|
|
2
2
|
export { Client } from "./client";
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Client = exports.CustomResponse = exports.ReceiptResponse = exports.PassportResponse = exports.InvoiceResponse = exports.FinancialDocResponse = exports.Response = void 0;
|
|
3
|
+
exports.Client = exports.CropperResponse = exports.CustomResponse = exports.ReceiptResponse = exports.PassportResponse = exports.InvoiceResponse = exports.FinancialDocResponse = exports.Response = void 0;
|
|
4
4
|
var api_1 = require("./api");
|
|
5
5
|
Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return api_1.Response; } });
|
|
6
6
|
Object.defineProperty(exports, "FinancialDocResponse", { enumerable: true, get: function () { return api_1.FinancialDocResponse; } });
|
|
@@ -8,5 +8,6 @@ Object.defineProperty(exports, "InvoiceResponse", { enumerable: true, get: funct
|
|
|
8
8
|
Object.defineProperty(exports, "PassportResponse", { enumerable: true, get: function () { return api_1.PassportResponse; } });
|
|
9
9
|
Object.defineProperty(exports, "ReceiptResponse", { enumerable: true, get: function () { return api_1.ReceiptResponse; } });
|
|
10
10
|
Object.defineProperty(exports, "CustomResponse", { enumerable: true, get: function () { return api_1.CustomResponse; } });
|
|
11
|
+
Object.defineProperty(exports, "CropperResponse", { enumerable: true, get: function () { return api_1.CropperResponse; } });
|
|
11
12
|
var client_1 = require("./client");
|
|
12
13
|
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|