mindee 4.14.0 → 4.15.0
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 +19 -0
- package/README.md +9 -9
- package/package.json +3 -2
- package/src/client.d.ts +5 -3
- package/src/client.js +7 -1
- package/src/http/endpoint.d.ts +3 -1
- package/src/http/endpoint.js +12 -8
- package/src/http/responseValidation.js +11 -4
- package/src/imageOperations/invoiceSplitterExtractor/invoiceSplitterExtractor.d.ts +2 -1
- package/src/imageOperations/invoiceSplitterExtractor/invoiceSplitterExtractor.js +2 -1
- package/src/imageOperations/multiReceiptsExtractor/multiReceiptsExtractor.js +3 -1
- package/src/input/localResponse.d.ts +1 -0
- package/src/input/localResponse.js +1 -0
- package/src/parsing/common/document.d.ts +1 -0
- package/src/parsing/common/document.js +27 -6
- package/src/parsing/common/extras/fullTextOcrExtra.d.ts +11 -0
- package/src/parsing/common/extras/fullTextOcrExtra.js +20 -0
- package/src/parsing/common/extras/index.d.ts +3 -0
- package/src/parsing/common/extras/index.js +9 -0
- package/src/parsing/common/index.d.ts +1 -0
- package/src/parsing/common/index.js +25 -1
- package/src/parsing/common/page.d.ts +1 -0
- package/src/parsing/common/page.js +30 -7
- package/src/parsing/generated/generatedObject.d.ts +3 -3
- package/src/parsing/generated/generatedObject.js +14 -5
- package/src/pdf/pdfOperation.d.ts +1 -1
- package/src/pdf/pdfOperation.js +12 -7
- package/src/product/barcodeReader/index.d.ts +1 -0
- package/src/product/barcodeReader/index.js +5 -0
- package/src/product/cropper/index.d.ts +1 -0
- package/src/product/cropper/index.js +5 -0
- package/src/product/eu/driverLicense/index.d.ts +1 -0
- package/src/product/eu/driverLicense/index.js +5 -0
- package/src/product/eu/driverLicense/internal.d.ts +1 -0
- package/src/product/eu/driverLicense/internal.js +3 -1
- package/src/product/eu/index.d.ts +1 -1
- package/src/product/eu/index.js +3 -3
- package/src/product/eu/internal.d.ts +1 -1
- package/src/product/eu/internal.js +2 -2
- package/src/product/eu/licensePlate/index.d.ts +1 -0
- package/src/product/eu/licensePlate/index.js +5 -0
- package/src/product/financialDocument/index.d.ts +1 -0
- package/src/product/financialDocument/index.js +5 -0
- package/src/product/fr/bankAccountDetails/index.d.ts +2 -0
- package/src/product/fr/bankAccountDetails/index.js +7 -0
- package/src/product/fr/bankAccountDetails/internal.d.ts +1 -1
- package/src/product/fr/bankAccountDetails/internal.js +3 -3
- package/src/product/fr/carteGrise/index.d.ts +1 -0
- package/src/product/fr/carteGrise/index.js +5 -0
- package/src/product/fr/carteVitale/index.d.ts +1 -0
- package/src/product/fr/carteVitale/index.js +5 -0
- package/src/product/fr/idCard/index.d.ts +2 -0
- package/src/product/fr/idCard/index.js +7 -0
- package/src/product/fr/idCard/internal.d.ts +3 -1
- package/src/product/fr/idCard/internal.js +7 -3
- package/src/product/fr/index.d.ts +3 -3
- package/src/product/fr/index.js +7 -7
- package/src/product/fr/internal.d.ts +1 -1
- package/src/product/fr/internal.js +2 -2
- package/src/product/generated/generatedV1.js +2 -1
- package/src/product/index.d.ts +2 -2
- package/src/product/index.js +5 -5
- package/src/product/internal.d.ts +1 -1
- package/src/product/internal.js +2 -2
- package/src/product/internationalId/index.d.ts +1 -0
- package/src/product/internationalId/index.js +5 -0
- package/src/product/invoice/index.d.ts +1 -0
- package/src/product/invoice/index.js +5 -0
- package/src/product/multiReceiptsDetector/index.d.ts +1 -0
- package/src/product/multiReceiptsDetector/index.js +5 -0
- package/src/product/passport/index.d.ts +1 -0
- package/src/product/passport/index.js +5 -0
- package/src/product/proofOfAddress/index.d.ts +1 -0
- package/src/product/proofOfAddress/index.js +5 -0
- package/src/product/receipt/index.d.ts +1 -0
- package/src/product/receipt/index.js +5 -0
- package/src/product/resume/index.d.ts +1 -0
- package/src/product/resume/index.js +5 -0
- package/src/product/resume/internal.d.ts +1 -1
- package/src/product/resume/internal.js +3 -3
- package/src/product/us/bankCheck/index.d.ts +1 -0
- package/src/product/us/bankCheck/index.js +5 -0
- package/src/product/us/driverLicense/index.d.ts +1 -0
- package/src/product/us/driverLicense/index.js +5 -0
- package/src/product/us/healthcareCard/internal.d.ts +3 -0
- package/src/product/us/healthcareCard/internal.js +9 -0
- package/src/product/us/internal.d.ts +1 -0
- package/src/product/us/internal.js +2 -1
- package/src/product/us/w9/index.d.ts +1 -0
- package/src/product/us/w9/index.js +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.15.0 - 2024-09-12
|
|
4
|
+
### Changes
|
|
5
|
+
* :sparkles: add support for full text OCR extraction
|
|
6
|
+
* :wrench: add stricter linting rules
|
|
7
|
+
* :recycle: add integration tests
|
|
8
|
+
### Fixes
|
|
9
|
+
* :bug: fix page operations not taking minimum threshold into account.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## v4.14.1 - 2024-09-03
|
|
13
|
+
### Changes
|
|
14
|
+
* :memo: add classification detail to guide documentation
|
|
15
|
+
### Fixes
|
|
16
|
+
* :arrow_up: update dependencies
|
|
17
|
+
* :memo: fix broken documentation URLs
|
|
18
|
+
* :recycle: generate missing accessors for products
|
|
19
|
+
* :recycle: add missing async code samples
|
|
20
|
+
|
|
21
|
+
|
|
3
22
|
## v4.14.0 - 2024-07-24
|
|
4
23
|
### Changes
|
|
5
24
|
* :sparkles: add support for Healthcare Card V1
|
package/README.md
CHANGED
|
@@ -144,8 +144,8 @@ const apiResponse = mindeeClient.parse(
|
|
|
144
144
|
Complete details on the working of the library are available in the following guides:
|
|
145
145
|
|
|
146
146
|
* [Node.js Getting Started](https://developers.mindee.com/docs/nodejs-getting-started)
|
|
147
|
-
* [Node.js Generated API](https://developers.mindee.com/docs/nodejs-generated-
|
|
148
|
-
* [Node.js Custom OCR](https://developers.mindee.com/docs/nodejs-api-builder)
|
|
147
|
+
* [Node.js Generated API](https://developers.mindee.com/docs/nodejs-generated-ocr)
|
|
148
|
+
* [Node.js Custom OCR (Deprecated)](https://developers.mindee.com/docs/nodejs-api-builder)
|
|
149
149
|
* [Node.js Invoice OCR](https://developers.mindee.com/docs/nodejs-invoice-ocr)
|
|
150
150
|
* [Node.js International Id OCR](https://developers.mindee.com/docs/nodejs-international-id-ocr)
|
|
151
151
|
* [Node.js Receipt OCR](https://developers.mindee.com/docs/nodejs-receipt-ocr)
|
|
@@ -153,18 +153,18 @@ Complete details on the working of the library are available in the following gu
|
|
|
153
153
|
* [Node.js Financial Document OCR](https://developers.mindee.com/docs/nodejs-financial-document-ocr)
|
|
154
154
|
* [Node.js Passport OCR](https://developers.mindee.com/docs/nodejs-passport-ocr)
|
|
155
155
|
* [Node.js Proof of Address OCR](https://developers.mindee.com/docs/nodejs-proof-of-address-ocr)
|
|
156
|
-
* [Node.js EU License Plate OCR](https://developers.mindee.com/docs/nodejs-eu-license-
|
|
156
|
+
* [Node.js EU License Plate OCR](https://developers.mindee.com/docs/nodejs-eu-license-plate-ocr)
|
|
157
157
|
* [Node.js EU Driver License OCR](https://developers.mindee.com/docs/nodejs-eu-driver-license-ocr)
|
|
158
158
|
* [Node.js FR Bank Account Detail OCR](https://developers.mindee.com/docs/nodejs-fr-bank-account-details-ocr)
|
|
159
159
|
* [Node.js FR Carte Vitale OCR](https://developers.mindee.com/docs/nodejs-fr-carte-vitale-ocr)
|
|
160
|
-
* [Node.js FR ID Card OCR](https://developers.mindee.com/docs/nodejs-fr-
|
|
161
|
-
* [Node.js US Bank Check OCR](https://developers.mindee.com/docs/nodejs-us-bank-
|
|
160
|
+
* [Node.js FR ID Card OCR](https://developers.mindee.com/docs/nodejs-fr-carte-nationale-didentite-ocr)
|
|
161
|
+
* [Node.js US Bank Check OCR](https://developers.mindee.com/docs/nodejs-us-bank-check-ocr)
|
|
162
162
|
* [Node.js US W9 OCR](https://developers.mindee.com/docs/nodejs-us-w9-ocr)
|
|
163
163
|
* [Node.js US Driver License OCR](https://developers.mindee.com/docs/nodejs-us-driver-license-ocr)
|
|
164
|
-
* [Node.js Barcode Reader API](https://developers.mindee.com/docs/nodejs-barcode-reader-
|
|
165
|
-
* [Node.js Cropper API](https://developers.mindee.com/docs/nodejs-cropper-
|
|
166
|
-
* [Node.js Invoice Splitter API](https://developers.mindee.com/docs/nodejs-invoice-splitter-
|
|
167
|
-
* [Node.js Multi Receipts Detector API](https://developers.mindee.com/docs/nodejs-multi-receipts-detector-
|
|
164
|
+
* [Node.js Barcode Reader API](https://developers.mindee.com/docs/nodejs-barcode-reader-ocr)
|
|
165
|
+
* [Node.js Cropper API](https://developers.mindee.com/docs/nodejs-cropper-ocr)
|
|
166
|
+
* [Node.js Invoice Splitter API](https://developers.mindee.com/docs/nodejs-invoice-splitter-ocr)
|
|
167
|
+
* [Node.js Multi Receipts Detector API](https://developers.mindee.com/docs/nodejs-multi-receipts-detector-ocr)
|
|
168
168
|
|
|
169
169
|
You can also take a look at the **[Reference Documentation](https://mindee.github.io/mindee-api-nodejs/)**.
|
|
170
170
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.0",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "bin/mindee.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"build-for-dist": "tsc --build && cp LICENSE README.md CHANGELOG.md ./dist",
|
|
11
11
|
"clean": "rm -rf ./dist ./docs/_build",
|
|
12
12
|
"test": "mocha 'tests/**/*.spec.ts'",
|
|
13
|
+
"test-integration": "mocha 'tests/**/*.integration.ts'",
|
|
13
14
|
"lint": "eslint './src/**/*.ts' --report-unused-disable-directives && echo 'Your .ts files look good.'",
|
|
14
15
|
"lint-fix": "eslint './src/**/*.ts' --fix",
|
|
15
16
|
"docs": "typedoc --out docs/_build ./src/index.ts",
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"chai": "^4.3.10",
|
|
49
50
|
"eslint": "^8.49.0",
|
|
50
51
|
"eslint-plugin-jsdoc": "^46.8.2",
|
|
51
|
-
"lint-staged": "^
|
|
52
|
+
"lint-staged": "^15.2.10",
|
|
52
53
|
"mocha": "^10.1.0",
|
|
53
54
|
"nock": "^13.3.3",
|
|
54
55
|
"ts-node": "^10.9.1",
|
package/src/client.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import { Readable } from "stream";
|
|
5
|
-
import { Base64Input, BytesInput, InputSource,
|
|
5
|
+
import { Base64Input, BufferInput, BytesInput, InputSource, LocalResponse, PageOptions, PathInput, StreamInput, UrlInput } from "./input";
|
|
6
6
|
import { Endpoint } from "./http";
|
|
7
7
|
import { AsyncPredictResponse, FeedbackResponse, Inference, PredictResponse, StringDict } from "./parsing/common";
|
|
8
8
|
/**
|
|
@@ -17,10 +17,12 @@ export interface PredictOptions {
|
|
|
17
17
|
* This performs a full OCR operation on the server and will increase response time.
|
|
18
18
|
*/
|
|
19
19
|
allWords?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to include the full ocr text. Only available on compatible APIs.
|
|
22
|
+
*/
|
|
23
|
+
fullText?: boolean;
|
|
20
24
|
/**
|
|
21
25
|
* Whether to include cropper results for each page.
|
|
22
|
-
*
|
|
23
|
-
* This performs a cropping operation on the server and will increase response time.
|
|
24
26
|
*/
|
|
25
27
|
cropper?: boolean;
|
|
26
28
|
/**
|
package/src/client.js
CHANGED
|
@@ -52,6 +52,7 @@ class Client {
|
|
|
52
52
|
async parse(productClass, inputSource, params = {
|
|
53
53
|
endpoint: undefined,
|
|
54
54
|
allWords: undefined,
|
|
55
|
+
fullText: undefined,
|
|
55
56
|
cropper: undefined,
|
|
56
57
|
pageOptions: undefined,
|
|
57
58
|
}) {
|
|
@@ -62,6 +63,7 @@ class Client {
|
|
|
62
63
|
const rawPrediction = await endpoint.predict({
|
|
63
64
|
inputDoc: inputSource,
|
|
64
65
|
includeWords: this.getBooleanParam(params.allWords),
|
|
66
|
+
fullText: this.getBooleanParam(params.fullText),
|
|
65
67
|
pageOptions: params.pageOptions,
|
|
66
68
|
cropper: this.getBooleanParam(params.cropper),
|
|
67
69
|
});
|
|
@@ -83,6 +85,7 @@ class Client {
|
|
|
83
85
|
const rawResponse = await endpoint.predictAsync({
|
|
84
86
|
inputDoc: inputSource,
|
|
85
87
|
includeWords: this.getBooleanParam(params.allWords),
|
|
88
|
+
fullText: this.getBooleanParam(params.fullText),
|
|
86
89
|
pageOptions: params?.pageOptions,
|
|
87
90
|
cropper: this.getBooleanParam(params.cropper),
|
|
88
91
|
});
|
|
@@ -171,6 +174,7 @@ class Client {
|
|
|
171
174
|
async enqueueAndParse(productClass, inputSource, asyncParams = {
|
|
172
175
|
endpoint: undefined,
|
|
173
176
|
allWords: undefined,
|
|
177
|
+
fullText: undefined,
|
|
174
178
|
cropper: undefined,
|
|
175
179
|
pageOptions: undefined,
|
|
176
180
|
initialDelaySec: 4,
|
|
@@ -202,7 +206,9 @@ Job status: ${pollResults.job.status}.`);
|
|
|
202
206
|
retryCounter++;
|
|
203
207
|
}
|
|
204
208
|
if (pollResults.job.status !== "completed") {
|
|
205
|
-
throw Error(
|
|
209
|
+
throw Error("Asynchronous parsing request timed out after " +
|
|
210
|
+
validatedAsyncParams.delaySec * retryCounter +
|
|
211
|
+
" seconds");
|
|
206
212
|
}
|
|
207
213
|
return pollResults;
|
|
208
214
|
}
|
package/src/http/endpoint.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { StringDict } from "../parsing/common";
|
|
|
6
6
|
export interface PredictParams {
|
|
7
7
|
inputDoc: InputSource;
|
|
8
8
|
includeWords: boolean;
|
|
9
|
+
fullText: boolean;
|
|
9
10
|
pageOptions?: PageOptions;
|
|
10
11
|
cropper: boolean;
|
|
11
12
|
}
|
|
@@ -63,7 +64,8 @@ export declare class Endpoint extends BaseEndpoint {
|
|
|
63
64
|
* @param input
|
|
64
65
|
* @param predictUrl
|
|
65
66
|
* @param includeWords
|
|
67
|
+
* @param fullText
|
|
66
68
|
* @param cropper
|
|
67
69
|
*/
|
|
68
|
-
protected sendFileForPrediction(input: InputSource, predictUrl: string, includeWords?: boolean, cropper?: boolean): Promise<EndpointResponse>;
|
|
70
|
+
protected sendFileForPrediction(input: InputSource, predictUrl: string, includeWords?: boolean, fullText?: boolean, cropper?: boolean): Promise<EndpointResponse>;
|
|
69
71
|
}
|
package/src/http/endpoint.js
CHANGED
|
@@ -40,7 +40,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
40
40
|
if (params.pageOptions !== undefined) {
|
|
41
41
|
await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_cutDocPages).call(this, params.inputDoc, params.pageOptions);
|
|
42
42
|
}
|
|
43
|
-
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictReqPost).call(this, params.inputDoc, params.includeWords, params.cropper);
|
|
43
|
+
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper);
|
|
44
44
|
if (!(0, responseValidation_1.isValidSyncResponse)(response)) {
|
|
45
45
|
(0, error_1.handleError)(this.urlName, response, response.messageObj?.statusMessage);
|
|
46
46
|
}
|
|
@@ -58,7 +58,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
58
58
|
if (params.pageOptions !== undefined) {
|
|
59
59
|
await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_cutDocPages).call(this, params.inputDoc, params.pageOptions);
|
|
60
60
|
}
|
|
61
|
-
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictAsyncReqPost).call(this, params.inputDoc, params.includeWords, params.cropper);
|
|
61
|
+
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictAsyncReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper);
|
|
62
62
|
if (!(0, responseValidation_1.isValidAsyncResponse)(response)) {
|
|
63
63
|
(0, error_1.handleError)(this.urlName, response, response.messageObj?.statusMessage);
|
|
64
64
|
}
|
|
@@ -114,14 +114,18 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
114
114
|
* @param input
|
|
115
115
|
* @param predictUrl
|
|
116
116
|
* @param includeWords
|
|
117
|
+
* @param fullText
|
|
117
118
|
* @param cropper
|
|
118
119
|
*/
|
|
119
|
-
sendFileForPrediction(input, predictUrl, includeWords = false, cropper = false) {
|
|
120
|
+
sendFileForPrediction(input, predictUrl, includeWords = false, fullText = false, cropper = false) {
|
|
120
121
|
return new Promise((resolve, reject) => {
|
|
121
122
|
const searchParams = new url_1.URLSearchParams();
|
|
122
123
|
if (cropper) {
|
|
123
124
|
searchParams.append("cropper", "true");
|
|
124
125
|
}
|
|
126
|
+
if (fullText) {
|
|
127
|
+
searchParams.append("full_text_ocr", "true");
|
|
128
|
+
}
|
|
125
129
|
const form = new form_data_1.default();
|
|
126
130
|
if (input instanceof base_1.LocalInputSource && input.fileObject instanceof Buffer) {
|
|
127
131
|
form.append("document", input.fileObject, {
|
|
@@ -136,7 +140,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
136
140
|
}
|
|
137
141
|
const headers = { ...this.settings.baseHeaders, ...form.getHeaders() };
|
|
138
142
|
let path = `${this.urlRoot}/${predictUrl}`;
|
|
139
|
-
if (searchParams.
|
|
143
|
+
if (searchParams.toString().length > 0) {
|
|
140
144
|
path += `?${searchParams}`;
|
|
141
145
|
}
|
|
142
146
|
const options = {
|
|
@@ -163,10 +167,10 @@ async function _Endpoint_cutDocPages(inputDoc, pageOptions) {
|
|
|
163
167
|
if (inputDoc instanceof base_1.LocalInputSource && inputDoc.isPdf()) {
|
|
164
168
|
await inputDoc.cutPdf(pageOptions);
|
|
165
169
|
}
|
|
166
|
-
}, _Endpoint_predictReqPost = function _Endpoint_predictReqPost(input, includeWords = false, cropper = false) {
|
|
167
|
-
return this.sendFileForPrediction(input, "predict", includeWords, cropper);
|
|
168
|
-
}, _Endpoint_predictAsyncReqPost = function _Endpoint_predictAsyncReqPost(input, includeWords = false, cropper = false) {
|
|
169
|
-
return this.sendFileForPrediction(input, "predict_async", includeWords, cropper);
|
|
170
|
+
}, _Endpoint_predictReqPost = function _Endpoint_predictReqPost(input, includeWords = false, fullText = false, cropper = false) {
|
|
171
|
+
return this.sendFileForPrediction(input, "predict", includeWords, fullText, cropper);
|
|
172
|
+
}, _Endpoint_predictAsyncReqPost = function _Endpoint_predictAsyncReqPost(input, includeWords = false, fullText = false, cropper = false) {
|
|
173
|
+
return this.sendFileForPrediction(input, "predict_async", includeWords, fullText, cropper);
|
|
170
174
|
}, _Endpoint_documentQueueReqGet = function _Endpoint_documentQueueReqGet(queueId) {
|
|
171
175
|
return new Promise((resolve, reject) => {
|
|
172
176
|
const options = {
|
|
@@ -11,7 +11,9 @@ function isValidSyncResponse(response) {
|
|
|
11
11
|
if (!response.messageObj || !response.messageObj.statusCode) {
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
|
-
return !(isNaN(response.messageObj.statusCode) ||
|
|
14
|
+
return !(isNaN(response.messageObj.statusCode) ||
|
|
15
|
+
parseInt(response.messageObj.statusCode.toString()) < 200 ||
|
|
16
|
+
parseInt(response.messageObj.statusCode.toString()) > 302);
|
|
15
17
|
}
|
|
16
18
|
exports.isValidSyncResponse = isValidSyncResponse;
|
|
17
19
|
/**
|
|
@@ -37,7 +39,9 @@ function isValidAsyncResponse(response) {
|
|
|
37
39
|
if (!response.data["job"]) {
|
|
38
40
|
return false;
|
|
39
41
|
}
|
|
40
|
-
return !(response.data["job"] &&
|
|
42
|
+
return !(response.data["job"] &&
|
|
43
|
+
response.data["job"]["error"] &&
|
|
44
|
+
Object.keys(response.data["job"]["error"]).length > 0);
|
|
41
45
|
}
|
|
42
46
|
exports.isValidAsyncResponse = isValidAsyncResponse;
|
|
43
47
|
/**
|
|
@@ -54,10 +58,13 @@ function cleanRequestData(response) {
|
|
|
54
58
|
return response;
|
|
55
59
|
}
|
|
56
60
|
if (response.data) {
|
|
57
|
-
if (response.data["api_request"] &&
|
|
61
|
+
if (response.data["api_request"] &&
|
|
62
|
+
response.data["api_request"]["status_code"] &&
|
|
63
|
+
parseInt(response.data["api_request"]["status_code"].toString()) > 399) {
|
|
58
64
|
response.messageObj.statusCode = parseInt(response.data["api_request"]["status_code"].toString());
|
|
59
65
|
}
|
|
60
|
-
if (response.data["job"] && response.data["job"]["error"] &&
|
|
66
|
+
if (response.data["job"] && response.data["job"]["error"] &&
|
|
67
|
+
Object.keys(response.data["job"]["error"]).length > 0) {
|
|
61
68
|
response.messageObj.statusCode = 500;
|
|
62
69
|
}
|
|
63
70
|
}
|
|
@@ -5,7 +5,8 @@ import { ExtractedInvoiceSplitterImage } from "./extractedInvoiceSplitterImage";
|
|
|
5
5
|
* Extracts & cuts the pages of a main document invoice according to the provided indexes.
|
|
6
6
|
*
|
|
7
7
|
* @param inputFile File to extract sub-invoices from.
|
|
8
|
-
* @param indexes List of indexes to cut the document according to.
|
|
8
|
+
* @param indexes List of indexes to cut the document according to.
|
|
9
|
+
* Can be provided either as a InvoiceSplitterV1 inference, or a direct list of splits.
|
|
9
10
|
* @param strict If set to true, doesn't cut pages where the API isn't 100% confident.
|
|
10
11
|
* @returns A promise of extracted images, as an array of ExtractedInvoiceSplitterImage.
|
|
11
12
|
*/
|
|
@@ -40,7 +40,8 @@ async function getPdfDoc(inputFile) {
|
|
|
40
40
|
* Extracts & cuts the pages of a main document invoice according to the provided indexes.
|
|
41
41
|
*
|
|
42
42
|
* @param inputFile File to extract sub-invoices from.
|
|
43
|
-
* @param indexes List of indexes to cut the document according to.
|
|
43
|
+
* @param indexes List of indexes to cut the document according to.
|
|
44
|
+
* Can be provided either as a InvoiceSplitterV1 inference, or a direct list of splits.
|
|
44
45
|
* @param strict If set to true, doesn't cut pages where the API isn't 100% confident.
|
|
45
46
|
* @returns A promise of extracted images, as an array of ExtractedInvoiceSplitterImage.
|
|
46
47
|
*/
|
|
@@ -25,7 +25,9 @@ async function extractReceiptsFromPage(pdfPage, boundingBoxes, pageId) {
|
|
|
25
25
|
async function loadPdfDoc(inputFile) {
|
|
26
26
|
let pdfDoc;
|
|
27
27
|
if (!["image/jpeg", "image/jpg", "image/png", "application/pdf"].includes(inputFile.mimeType)) {
|
|
28
|
-
throw new errors_1.MindeeMimeTypeError(
|
|
28
|
+
throw new errors_1.MindeeMimeTypeError('Unsupported file type "' +
|
|
29
|
+
inputFile.mimeType +
|
|
30
|
+
'" Currently supported types are .png, .jpg and .pdf');
|
|
29
31
|
}
|
|
30
32
|
else if (inputFile.isPdf()) {
|
|
31
33
|
pdfDoc = await pdf_lib_1.PDFDocument.load(inputFile.fileObject);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Document = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const extras_1 = require("./extras");
|
|
5
|
+
const extras_2 = require("./extras/extras");
|
|
6
6
|
const ocr_1 = require("./ocr");
|
|
7
7
|
/**
|
|
8
8
|
* Document prediction wrapper class. Holds the results of a parsed document.
|
|
@@ -19,18 +19,23 @@ class Document {
|
|
|
19
19
|
this.filename = httpResponse?.name ?? "";
|
|
20
20
|
this.ocr = httpResponse.ocr && Object.keys(httpResponse.ocr).length > 0 ? new ocr_1.Ocr(httpResponse.ocr) : undefined;
|
|
21
21
|
this.inference = new inferenceClass(httpResponse["inference"]);
|
|
22
|
-
// Note: this is a convoluted but functional way of being able to implement/use Extras fields
|
|
23
|
-
// as an extension of a Map object (like having an adapted toString() method, for instance).
|
|
24
22
|
if (httpResponse["extras"] &&
|
|
25
23
|
Object.keys(httpResponse["extras"].length > 0)) {
|
|
26
24
|
const extras = {};
|
|
27
25
|
Object.entries(httpResponse["extras"]).forEach(([extraKey, extraValue]) => {
|
|
28
26
|
switch (extraKey) {
|
|
29
27
|
case "cropper":
|
|
30
|
-
extras["cropper"] = new
|
|
28
|
+
extras["cropper"] = new extras_1.CropperExtra(extraValue);
|
|
29
|
+
break;
|
|
30
|
+
case "full_text_ocr":
|
|
31
|
+
extras["fullTextOcr"] = new extras_1.FullTextOcrExtra(extraValue);
|
|
32
|
+
break;
|
|
31
33
|
}
|
|
32
34
|
});
|
|
33
|
-
this.extras = new
|
|
35
|
+
this.extras = new extras_2.Extras(extras);
|
|
36
|
+
}
|
|
37
|
+
if (!this.extras || !("fullTextOcr" in this.extras) || this.extras["full_text_ocr"].toString().length === 0) {
|
|
38
|
+
this.injectFullTextOcr(httpResponse);
|
|
34
39
|
}
|
|
35
40
|
this.nPages = httpResponse["n_pages"];
|
|
36
41
|
}
|
|
@@ -44,5 +49,21 @@ class Document {
|
|
|
44
49
|
|
|
45
50
|
${this.inference?.toString()}`;
|
|
46
51
|
}
|
|
52
|
+
injectFullTextOcr(rawPrediction) {
|
|
53
|
+
if (rawPrediction["inference"]["pages"].length < 1 ||
|
|
54
|
+
rawPrediction["inference"]["pages"][0]["extras"].length < 1 ||
|
|
55
|
+
!("full_text_ocr" in rawPrediction["inference"]["pages"][0]["extras"])) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const fullTextOcr = rawPrediction["inference"]["pages"].filter((e) => "extras" in e).map((e) => e["extras"]["full_text_ocr"]["content"]).join("\n");
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
60
|
+
const artificialTextObj = { "full_text_ocr": { "content": fullTextOcr.length > 0 ? fullTextOcr : "" } };
|
|
61
|
+
if (!this.extras) {
|
|
62
|
+
this.extras = new extras_2.Extras({ "fullTextOcr": new extras_1.FullTextOcrExtra(artificialTextObj) });
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.extras["fullTextOcr"] = new extras_1.FullTextOcrExtra(artificialTextObj);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
47
68
|
}
|
|
48
69
|
exports.Document = Document;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { StringDict } from "../stringDict";
|
|
2
|
+
import { ExtraField } from "./extras";
|
|
3
|
+
export declare class FullTextOcrExtra extends ExtraField {
|
|
4
|
+
content?: string;
|
|
5
|
+
languages?: string;
|
|
6
|
+
constructor(rawPrediction: StringDict);
|
|
7
|
+
/**
|
|
8
|
+
* Default string representation.
|
|
9
|
+
*/
|
|
10
|
+
toString(): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FullTextOcrExtra = void 0;
|
|
4
|
+
const extras_1 = require("./extras");
|
|
5
|
+
class FullTextOcrExtra extends extras_1.ExtraField {
|
|
6
|
+
constructor(rawPrediction) {
|
|
7
|
+
super();
|
|
8
|
+
if (rawPrediction["full_text_ocr"] !== undefined && rawPrediction["full_text_ocr"]["content"]) {
|
|
9
|
+
this.content = "content" in rawPrediction["full_text_ocr"] ? rawPrediction["full_text_ocr"]["content"] : "";
|
|
10
|
+
this.languages = "languages" in rawPrediction["full_text_ocr"] ? rawPrediction["full_text_ocr"]["languages"] : "";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Default string representation.
|
|
15
|
+
*/
|
|
16
|
+
toString() {
|
|
17
|
+
return this.content !== undefined ? this.content : "";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.FullTextOcrExtra = FullTextOcrExtra;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FullTextOcrExtra = exports.Extras = exports.CropperExtra = void 0;
|
|
4
|
+
var cropperExtra_1 = require("./cropperExtra");
|
|
5
|
+
Object.defineProperty(exports, "CropperExtra", { enumerable: true, get: function () { return cropperExtra_1.CropperExtra; } });
|
|
6
|
+
var extras_1 = require("./extras");
|
|
7
|
+
Object.defineProperty(exports, "Extras", { enumerable: true, get: function () { return extras_1.Extras; } });
|
|
8
|
+
var fullTextOcrExtra_1 = require("./fullTextOcrExtra");
|
|
9
|
+
Object.defineProperty(exports, "FullTextOcrExtra", { enumerable: true, get: function () { return fullTextOcrExtra_1.FullTextOcrExtra; } });
|
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lineSeparator = exports.cleanOutString = exports.Page = exports.Prediction = exports.PredictResponse = exports.AsyncPredictResponse = exports.Inference = exports.OrientationField = exports.FeedbackResponse = exports.Document = void 0;
|
|
26
|
+
exports.extras = exports.lineSeparator = exports.cleanOutString = exports.Page = exports.Prediction = exports.PredictResponse = exports.AsyncPredictResponse = exports.Inference = exports.OrientationField = exports.FeedbackResponse = exports.Document = void 0;
|
|
4
27
|
var document_1 = require("./document");
|
|
5
28
|
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
|
|
6
29
|
var feedbackResponse_1 = require("./feedback/feedbackResponse");
|
|
@@ -20,3 +43,4 @@ Object.defineProperty(exports, "Page", { enumerable: true, get: function () { re
|
|
|
20
43
|
var summaryHelper_1 = require("./summaryHelper");
|
|
21
44
|
Object.defineProperty(exports, "cleanOutString", { enumerable: true, get: function () { return summaryHelper_1.cleanOutString; } });
|
|
22
45
|
Object.defineProperty(exports, "lineSeparator", { enumerable: true, get: function () { return summaryHelper_1.lineSeparator; } });
|
|
46
|
+
exports.extras = __importStar(require("./extras"));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Page = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const extras_1 = require("./extras");
|
|
5
|
+
const extras_2 = require("./extras/extras");
|
|
6
6
|
const orientation_1 = require("./orientation");
|
|
7
7
|
/**
|
|
8
8
|
* Page prediction wrapper class. Holds the results of a parsed document's page.
|
|
@@ -23,9 +23,6 @@ class Page {
|
|
|
23
23
|
pageId: pageId,
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
else {
|
|
27
|
-
orientation = undefined;
|
|
28
|
-
}
|
|
29
26
|
this.id = pageId;
|
|
30
27
|
this.prediction = new predictionType(rawPrediction["prediction"], pageId);
|
|
31
28
|
if (rawPrediction["extras"] &&
|
|
@@ -34,10 +31,17 @@ class Page {
|
|
|
34
31
|
Object.entries(rawPrediction["extras"]).forEach(([extraKey, extraValue]) => {
|
|
35
32
|
switch (extraKey) {
|
|
36
33
|
case "cropper":
|
|
37
|
-
extras["cropper"] = new
|
|
34
|
+
extras["cropper"] = new extras_1.CropperExtra(extraValue);
|
|
35
|
+
break;
|
|
36
|
+
case "full_text_ocr":
|
|
37
|
+
extras["fullTextOcr"] = new extras_1.FullTextOcrExtra(extraValue);
|
|
38
|
+
break;
|
|
38
39
|
}
|
|
39
40
|
});
|
|
40
|
-
this.extras = new
|
|
41
|
+
this.extras = new extras_2.Extras(extras);
|
|
42
|
+
}
|
|
43
|
+
if (!this.extras || !("fullTextOcr" in this.extras) || this.extras["fullTextOcr"].toString().length === 0) {
|
|
44
|
+
this.injectFullTextOcr(rawPrediction);
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
/**
|
|
@@ -50,5 +54,24 @@ ${"-".repeat(title.length)}
|
|
|
50
54
|
${this.prediction.toString()}
|
|
51
55
|
`;
|
|
52
56
|
}
|
|
57
|
+
injectFullTextOcr(rawPrediction) {
|
|
58
|
+
if (!("extras" in rawPrediction) || !("full_text_ocr" in rawPrediction["extras"])) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const fullTextOcr = rawPrediction.map((e) => e["extras"]["full_text_ocr"]["content"]).join("\n");
|
|
62
|
+
const artificialTextObj = {
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
64
|
+
"full_text_ocr": {
|
|
65
|
+
"content": fullTextOcr.length > 0 ? fullTextOcr : "",
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
if (!this.extras) {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
70
|
+
this.extras = new extras_2.Extras({ "full_text_ocr": new extras_1.FullTextOcrExtra(artificialTextObj) });
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.extras["fullTextOcr"] = new extras_1.FullTextOcrExtra(artificialTextObj);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
53
76
|
}
|
|
54
77
|
exports.Page = Page;
|
|
@@ -13,8 +13,8 @@ export declare class GeneratedObjectField {
|
|
|
13
13
|
constructor({ prediction, pageId, }: BaseFieldConstructor);
|
|
14
14
|
/**
|
|
15
15
|
* ReSTructured-compliant string representation.
|
|
16
|
-
|
|
17
|
-
* @param level
|
|
16
|
+
Takes into account level of indentation & displays elements as list elements.
|
|
17
|
+
* @param level Level of indentation. 0 by default.
|
|
18
18
|
*/
|
|
19
19
|
toStringLevel(level?: number): string;
|
|
20
20
|
/**
|
|
@@ -26,7 +26,7 @@ export declare class GeneratedObjectField {
|
|
|
26
26
|
toString(): string;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Checks whether
|
|
29
|
+
* Checks whether a field is a custom object or not.
|
|
30
30
|
* @param strDict input dictionary to check.
|
|
31
31
|
*/
|
|
32
32
|
export declare function isGeneratedObject(strDict: StringDict): boolean;
|
|
@@ -12,7 +12,13 @@ class GeneratedObjectField {
|
|
|
12
12
|
itemPageId = fieldValue;
|
|
13
13
|
}
|
|
14
14
|
else if (["polygon", "rectangle", "quadrangle", "bounding_box"].includes(fieldName)) {
|
|
15
|
-
Object.assign(this, {
|
|
15
|
+
Object.assign(this, {
|
|
16
|
+
[fieldName]: new standard_1.PositionField({
|
|
17
|
+
prediction: { [fieldName]: fieldValue },
|
|
18
|
+
valueKey: fieldName,
|
|
19
|
+
pageId: pageId,
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
16
22
|
this.printableValues.push(fieldName);
|
|
17
23
|
}
|
|
18
24
|
else if (fieldName === "confidence") {
|
|
@@ -26,7 +32,10 @@ class GeneratedObjectField {
|
|
|
26
32
|
Object.assign(this, { [fieldName]: this.toNumberString(fieldValue) });
|
|
27
33
|
}
|
|
28
34
|
else {
|
|
29
|
-
Object.assign(this, {
|
|
35
|
+
Object.assign(this, {
|
|
36
|
+
[fieldName]: (fieldValue !== undefined && fieldValue !== null) ?
|
|
37
|
+
String(fieldValue) : null,
|
|
38
|
+
});
|
|
30
39
|
}
|
|
31
40
|
this.printableValues.push(fieldName);
|
|
32
41
|
}
|
|
@@ -35,8 +44,8 @@ class GeneratedObjectField {
|
|
|
35
44
|
}
|
|
36
45
|
/**
|
|
37
46
|
* ReSTructured-compliant string representation.
|
|
38
|
-
|
|
39
|
-
* @param level
|
|
47
|
+
Takes into account level of indentation & displays elements as list elements.
|
|
48
|
+
* @param level Level of indentation. 0 by default.
|
|
40
49
|
*/
|
|
41
50
|
toStringLevel(level = 0) {
|
|
42
51
|
const indent = " " + " ".repeat(level);
|
|
@@ -64,7 +73,7 @@ class GeneratedObjectField {
|
|
|
64
73
|
}
|
|
65
74
|
exports.GeneratedObjectField = GeneratedObjectField;
|
|
66
75
|
/**
|
|
67
|
-
* Checks whether
|
|
76
|
+
* Checks whether a field is a custom object or not.
|
|
68
77
|
* @param strDict input dictionary to check.
|
|
69
78
|
*/
|
|
70
79
|
function isGeneratedObject(strDict) {
|
|
@@ -8,7 +8,7 @@ export interface SplitPdf {
|
|
|
8
8
|
* Cut pages from a pdf file. If pages index are out of bound, it will throw an error.
|
|
9
9
|
* @param file
|
|
10
10
|
* @param pageOptions
|
|
11
|
-
* @returns the new
|
|
11
|
+
* @returns the new cut pdf file.
|
|
12
12
|
*/
|
|
13
13
|
export declare function extractPages(file: Buffer, pageOptions: PageOptions): Promise<SplitPdf>;
|
|
14
14
|
export declare function countPages(file: Buffer): Promise<number>;
|