mindee 4.18.0 → 4.19.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 +16 -1
- package/package.json +12 -12
- package/src/cli.js +1 -2
- package/src/client.d.ts +44 -12
- package/src/client.js +25 -1
- package/src/geometry/boundingBoxUtils.js +5 -6
- package/src/geometry/polygonUtils.js +13 -14
- package/src/http/apiSettings.d.ts +2 -0
- package/src/http/apiSettings.js +3 -1
- package/src/http/baseEndpoint.d.ts +10 -3
- package/src/http/baseEndpoint.js +14 -2
- package/src/http/endpoint.d.ts +3 -11
- package/src/http/endpoint.js +26 -22
- package/src/http/error.js +5 -5
- package/src/http/httpParams.d.ts +17 -0
- package/src/http/httpParams.js +2 -0
- package/src/http/index.d.ts +1 -0
- package/src/http/responseValidation.js +9 -4
- package/src/http/workflowEndpoint.d.ts +29 -0
- package/src/http/workflowEndpoint.js +99 -0
- package/src/imageOperations/common/extractedImage.d.ts +0 -1
- package/src/imageOperations/common/imageExtractor.js +1 -2
- package/src/imageOperations/invoiceSplitterExtractor/invoiceSplitterExtractor.js +1 -2
- package/src/imageOperations/multiReceiptsExtractor/multiReceiptsExtractor.js +1 -2
- package/src/input/base.d.ts +0 -1
- package/src/input/localResponse.d.ts +0 -1
- package/src/input/localResponse.js +2 -2
- package/src/input/pageOptions.js +1 -1
- package/src/input/sources.d.ts +0 -2
- package/src/parsing/common/asyncPredictResponse.d.ts +1 -1
- package/src/parsing/common/asyncPredictResponse.js +10 -9
- package/src/parsing/common/execution.d.ts +39 -0
- package/src/parsing/common/execution.js +32 -0
- package/src/parsing/common/executionFile.d.ts +12 -0
- package/src/parsing/common/executionFile.js +14 -0
- package/src/parsing/common/executionPriority.d.ts +5 -0
- package/src/parsing/common/executionPriority.js +9 -0
- package/src/parsing/common/index.d.ts +4 -1
- package/src/parsing/common/index.js +9 -3
- package/src/parsing/common/page.js +1 -1
- package/src/parsing/common/summaryHelper.js +4 -5
- package/src/parsing/common/workflowResponse.d.ts +17 -0
- package/src/parsing/common/workflowResponse.js +17 -0
- package/src/parsing/custom/lineItems.js +2 -2
- package/src/parsing/generated/generatedObject.js +2 -2
- package/src/parsing/standard/paymentDetails.js +4 -4
- package/src/pdf/pdfOperation.d.ts +0 -1
- package/src/pdf/pdfOperation.js +2 -3
- package/src/product/index.d.ts +0 -1
- package/src/product/index.js +1 -3
- package/src/product/internationalId/internal.d.ts +0 -2
- package/src/product/internationalId/internal.js +1 -5
- package/src/product/internationalId/internationalIdV1.d.ts +0 -16
- package/src/product/internationalId/internationalIdV1.js +0 -27
- package/src/product/internationalId/internationalIdV1Document.d.ts +0 -42
- package/src/product/internationalId/internationalIdV1Document.js +0 -101
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## v4.19.0 - 2024-11-27
|
|
4
|
+
### Changes
|
|
5
|
+
* :coffin: remove support for international ID V1
|
|
6
|
+
* :sparkles: add support for workflows
|
|
7
|
+
* :sparkles: add configurable http request timeout
|
|
8
|
+
### Fixes
|
|
9
|
+
* :bug: fix http errors improperly showing as 500 in rare instances
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## v4.18.1 - 2024-11-19
|
|
13
|
+
### Fixes
|
|
14
|
+
* :bug: fix composed API server response not properly filling full_text_ocr in pages
|
|
15
|
+
* :arrow_up: bump dependencies
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## v4.18.0 - 2024-11-14
|
|
4
19
|
### Changes
|
|
5
20
|
* :sparkles: add support for business cards V1
|
|
6
21
|
* :sparkles: add support for delivery note V1.1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.19.0",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "bin/mindee.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"build": "tsc --build",
|
|
10
10
|
"build-for-dist": "tsc --build && cp LICENSE README.md CHANGELOG.md ./dist",
|
|
11
11
|
"clean": "rm -rf ./dist ./docs/_build",
|
|
12
|
-
"test": "mocha 'tests/**/*.spec.ts'",
|
|
12
|
+
"test": "mocha 'tests/**/*.spec.ts' --config .mocharc.json",
|
|
13
13
|
"test-integration": "mocha 'tests/**/*.integration.ts'",
|
|
14
14
|
"lint": "eslint './src/**/*.ts' --report-unused-disable-directives && echo 'Your .ts files look good.'",
|
|
15
15
|
"lint-fix": "eslint './src/**/*.ts' --fix",
|
|
@@ -41,18 +41,18 @@
|
|
|
41
41
|
"homepage": "https://mindee.com/",
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/chai": "^4.3.4",
|
|
44
|
-
"@types/mocha": "^
|
|
44
|
+
"@types/mocha": "^10.0.9",
|
|
45
45
|
"@types/node": "^18.15.11",
|
|
46
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
47
|
-
"@typescript-eslint/parser": "^
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^8.15.0",
|
|
47
|
+
"@typescript-eslint/parser": "^8.15.0",
|
|
48
48
|
"chai": "^4.3.10",
|
|
49
|
-
"eslint": "^
|
|
50
|
-
"eslint-plugin-jsdoc": "^
|
|
51
|
-
"mocha": "^10.
|
|
52
|
-
"nock": "^13.
|
|
53
|
-
"ts-node": "^10.9.
|
|
54
|
-
"typedoc": "~0.
|
|
55
|
-
"typescript": "^5.
|
|
49
|
+
"eslint": "^9.15.0",
|
|
50
|
+
"eslint-plugin-jsdoc": "^50.5.0",
|
|
51
|
+
"mocha": "^10.8.2",
|
|
52
|
+
"nock": "^13.5.6",
|
|
53
|
+
"ts-node": "^10.9.2",
|
|
54
|
+
"typedoc": "~0.26.11",
|
|
55
|
+
"typescript": "^5.6.3"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"commander": "~9.4.1",
|
package/src/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.cli =
|
|
26
|
+
exports.cli = cli;
|
|
27
27
|
const commander_1 = require("commander");
|
|
28
28
|
const product = __importStar(require("./product"));
|
|
29
29
|
const client_1 = require("./client");
|
|
@@ -491,4 +491,3 @@ function cli() {
|
|
|
491
491
|
});
|
|
492
492
|
program.parse(process.argv);
|
|
493
493
|
}
|
|
494
|
-
exports.cli = cli;
|
package/src/client.d.ts
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
1
|
import { Readable } from "stream";
|
|
5
2
|
import { Base64Input, BufferInput, BytesInput, InputSource, LocalResponse, PageOptions, PathInput, StreamInput, UrlInput } from "./input";
|
|
6
3
|
import { Endpoint } from "./http";
|
|
7
|
-
import { AsyncPredictResponse, FeedbackResponse, Inference, PredictResponse, StringDict } from "./parsing/common";
|
|
4
|
+
import { AsyncPredictResponse, ExecutionPriority, FeedbackResponse, Inference, PredictResponse, StringDict } from "./parsing/common";
|
|
5
|
+
import { GeneratedV1 } from "./product";
|
|
6
|
+
import { WorkflowResponse } from "./parsing/common/workflowResponse";
|
|
7
|
+
/**
|
|
8
|
+
* Common options for workflows & predictions.
|
|
9
|
+
*/
|
|
10
|
+
interface BaseOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Whether to include the full ocr text. Only available on compatible APIs.
|
|
13
|
+
*/
|
|
14
|
+
fullText?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* If set, remove pages from the document as specified.
|
|
17
|
+
* This is done before sending the file to the server and is useful to avoid page limitations.
|
|
18
|
+
*/
|
|
19
|
+
pageOptions?: PageOptions;
|
|
20
|
+
}
|
|
8
21
|
/**
|
|
9
22
|
* Options relating to predictions.
|
|
10
23
|
*/
|
|
11
|
-
export interface PredictOptions {
|
|
24
|
+
export interface PredictOptions extends BaseOptions {
|
|
12
25
|
/** A custom endpoint. */
|
|
13
26
|
endpoint?: Endpoint;
|
|
14
27
|
/**
|
|
@@ -17,19 +30,28 @@ export interface PredictOptions {
|
|
|
17
30
|
* This performs a full OCR operation on the server and will increase response time.
|
|
18
31
|
*/
|
|
19
32
|
allWords?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Whether to include the full ocr text. Only available on compatible APIs.
|
|
22
|
-
*/
|
|
23
|
-
fullText?: boolean;
|
|
24
33
|
/**
|
|
25
34
|
* Whether to include cropper results for each page.
|
|
26
35
|
*/
|
|
27
36
|
cropper?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Options relating to workflows.
|
|
40
|
+
* @category Workflow
|
|
41
|
+
*/
|
|
42
|
+
export interface WorkflowOptions extends BaseOptions {
|
|
28
43
|
/**
|
|
29
|
-
*
|
|
30
|
-
* This is done before sending the file to the server and is useful to avoid page limitations.
|
|
44
|
+
* Alias to give to the document.
|
|
31
45
|
*/
|
|
32
|
-
|
|
46
|
+
alias?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Priority to give to the document.
|
|
49
|
+
*/
|
|
50
|
+
priority?: ExecutionPriority;
|
|
51
|
+
/**
|
|
52
|
+
* A unique, encrypted URL for accessing the document validation interface without requiring authentication.
|
|
53
|
+
*/
|
|
54
|
+
publicUrl?: string;
|
|
33
55
|
}
|
|
34
56
|
/**
|
|
35
57
|
* Asynchronous polling parameters.
|
|
@@ -114,6 +136,15 @@ export declare class Client {
|
|
|
114
136
|
*/
|
|
115
137
|
parseQueued<T extends Inference>(productClass: new (httpResponse: StringDict) => T, queueId: string, params?: PredictOptions): Promise<AsyncPredictResponse<T>>;
|
|
116
138
|
loadPrediction<T extends Inference>(productClass: new (httpResponse: StringDict) => T, localResponse: LocalResponse): Promise<AsyncPredictResponse<T> | PredictResponse<T>>;
|
|
139
|
+
/**
|
|
140
|
+
* Send the document to an asynchronous endpoint and return its ID in the queue.
|
|
141
|
+
* @param inputSource file to send to the API.
|
|
142
|
+
* @param workflowId ID of the workflow.
|
|
143
|
+
* @param params parameters relating to prediction options.
|
|
144
|
+
* @category Workflow
|
|
145
|
+
* @returns a `Promise` containing the job (queue) corresponding to a document.
|
|
146
|
+
*/
|
|
147
|
+
executeWorkflow(inputSource: InputSource, workflowId: string, params?: WorkflowOptions): Promise<WorkflowResponse<GeneratedV1>>;
|
|
117
148
|
/**
|
|
118
149
|
* Fetch prediction results from a document already processed.
|
|
119
150
|
*
|
|
@@ -207,3 +238,4 @@ export declare class Client {
|
|
|
207
238
|
*/
|
|
208
239
|
docFromBuffer(buffer: Buffer, filename: string): BufferInput;
|
|
209
240
|
}
|
|
241
|
+
export {};
|
package/src/client.js
CHANGED
|
@@ -16,6 +16,8 @@ const inference_1 = require("./parsing/common/inference");
|
|
|
16
16
|
const product_1 = require("./product");
|
|
17
17
|
const promises_1 = require("node:timers/promises");
|
|
18
18
|
const errors_1 = require("./errors");
|
|
19
|
+
const workflowResponse_1 = require("./parsing/common/workflowResponse");
|
|
20
|
+
const workflowEndpoint_1 = require("./http/workflowEndpoint");
|
|
19
21
|
/**
|
|
20
22
|
* Mindee Client class that centralizes most basic operations.
|
|
21
23
|
*
|
|
@@ -122,10 +124,32 @@ class Client {
|
|
|
122
124
|
}
|
|
123
125
|
return new common_1.PredictResponse(productClass, localResponse.asDict());
|
|
124
126
|
}
|
|
125
|
-
catch
|
|
127
|
+
catch {
|
|
126
128
|
throw new errors_1.MindeeError("No prediction found in local response.");
|
|
127
129
|
}
|
|
128
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Send the document to an asynchronous endpoint and return its ID in the queue.
|
|
133
|
+
* @param inputSource file to send to the API.
|
|
134
|
+
* @param workflowId ID of the workflow.
|
|
135
|
+
* @param params parameters relating to prediction options.
|
|
136
|
+
* @category Workflow
|
|
137
|
+
* @returns a `Promise` containing the job (queue) corresponding to a document.
|
|
138
|
+
*/
|
|
139
|
+
async executeWorkflow(inputSource, workflowId, params = {}) {
|
|
140
|
+
const workflowEndpoint = new workflowEndpoint_1.WorkflowEndpoint(__classPrivateFieldGet(this, _Client_instances, "m", _Client_buildApiSettings).call(this), workflowId);
|
|
141
|
+
if (inputSource === undefined) {
|
|
142
|
+
throw new Error("The 'parse' function requires an input document.");
|
|
143
|
+
}
|
|
144
|
+
const rawResponse = await workflowEndpoint.executeWorkflow({
|
|
145
|
+
inputDoc: inputSource,
|
|
146
|
+
alias: params.alias,
|
|
147
|
+
priority: params.priority,
|
|
148
|
+
pageOptions: params?.pageOptions,
|
|
149
|
+
fullText: this.getBooleanParam(params.fullText),
|
|
150
|
+
});
|
|
151
|
+
return new workflowResponse_1.WorkflowResponse(product_1.GeneratedV1, rawResponse.data);
|
|
152
|
+
}
|
|
129
153
|
/**
|
|
130
154
|
* Fetch prediction results from a document already processed.
|
|
131
155
|
*
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getBoundingBox = getBoundingBox;
|
|
4
|
+
exports.getBoundingBoxFromBBox = getBoundingBoxFromBBox;
|
|
5
|
+
exports.mergeBbox = mergeBbox;
|
|
6
|
+
exports.getBbox = getBbox;
|
|
7
|
+
exports.getBBoxForPolygons = getBBoxForPolygons;
|
|
4
8
|
const boundingBox_1 = require("./boundingBox");
|
|
5
9
|
/**
|
|
6
10
|
* Given a Polygon, calculate a polygon that encompasses all points.
|
|
@@ -9,7 +13,6 @@ function getBoundingBox(polygon) {
|
|
|
9
13
|
const bbox = getBbox(polygon);
|
|
10
14
|
return getBoundingBoxFromBBox(bbox);
|
|
11
15
|
}
|
|
12
|
-
exports.getBoundingBox = getBoundingBox;
|
|
13
16
|
/**
|
|
14
17
|
* Given a BBox, generate the associated bounding box.
|
|
15
18
|
*/
|
|
@@ -21,14 +24,12 @@ function getBoundingBoxFromBBox(bbox) {
|
|
|
21
24
|
[bbox.xMin, bbox.yMax],
|
|
22
25
|
];
|
|
23
26
|
}
|
|
24
|
-
exports.getBoundingBoxFromBBox = getBoundingBoxFromBBox;
|
|
25
27
|
/**
|
|
26
28
|
* Given 2 bbox, merge them.
|
|
27
29
|
*/
|
|
28
30
|
function mergeBbox(bbox1, bbox2) {
|
|
29
31
|
return new boundingBox_1.BBox(Math.min(bbox1.xMin, bbox2.xMin), Math.min(bbox1.yMin, bbox2.yMin), Math.max(bbox1.xMax, bbox2.xMax), Math.max(bbox1.yMax, bbox2.yMax));
|
|
30
32
|
}
|
|
31
|
-
exports.mergeBbox = mergeBbox;
|
|
32
33
|
/**
|
|
33
34
|
* Given a Polygon, calculate a BBox that encompasses all points.
|
|
34
35
|
*/
|
|
@@ -37,7 +38,6 @@ function getBbox(polygon) {
|
|
|
37
38
|
const allX = polygon.map((point) => point[0]);
|
|
38
39
|
return new boundingBox_1.BBox(Math.min(...allX), Math.min(...allY), Math.max(...allX), Math.max(...allY));
|
|
39
40
|
}
|
|
40
|
-
exports.getBbox = getBbox;
|
|
41
41
|
/**
|
|
42
42
|
* Given polygons, calculate a BBox that encompasses all points.
|
|
43
43
|
*/
|
|
@@ -46,4 +46,3 @@ function getBBoxForPolygons(polygons) {
|
|
|
46
46
|
const allX = polygons.flatMap((polygon) => polygon.map((point) => point[0]));
|
|
47
47
|
return new boundingBox_1.BBox(Math.min(...allX), Math.min(...allY), Math.max(...allX), Math.max(...allY));
|
|
48
48
|
}
|
|
49
|
-
exports.getBBoxForPolygons = getBBoxForPolygons;
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getCentroid = getCentroid;
|
|
4
|
+
exports.isPointInY = isPointInY;
|
|
5
|
+
exports.getMinMaxY = getMinMaxY;
|
|
6
|
+
exports.isPointInPolygonY = isPointInPolygonY;
|
|
7
|
+
exports.relativeY = relativeY;
|
|
8
|
+
exports.isPointInX = isPointInX;
|
|
9
|
+
exports.getMinMaxX = getMinMaxX;
|
|
10
|
+
exports.isPointInPolygonX = isPointInPolygonX;
|
|
11
|
+
exports.relativeX = relativeX;
|
|
12
|
+
exports.getMinYCoordinate = getMinYCoordinate;
|
|
13
|
+
exports.getMinXCoordinate = getMinXCoordinate;
|
|
14
|
+
exports.compareOnY = compareOnY;
|
|
15
|
+
exports.compareOnX = compareOnX;
|
|
4
16
|
/**
|
|
5
17
|
* Get the central point (centroid) given a list of points.
|
|
6
18
|
*/
|
|
@@ -14,14 +26,12 @@ function getCentroid(vertices) {
|
|
|
14
26
|
.reduce((prev, cur) => prev + cur);
|
|
15
27
|
return [xSum / numbVertices, ySum / numbVertices];
|
|
16
28
|
}
|
|
17
|
-
exports.getCentroid = getCentroid;
|
|
18
29
|
/**
|
|
19
30
|
* Determine if a Point is within two Y coordinates.
|
|
20
31
|
*/
|
|
21
32
|
function isPointInY(centroid, yMin, yMax) {
|
|
22
33
|
return yMin <= centroid[1] && centroid[1] <= yMax;
|
|
23
34
|
}
|
|
24
|
-
exports.isPointInY = isPointInY;
|
|
25
35
|
/**
|
|
26
36
|
* Get the maximum and minimum Y coordinates in a given list of Points.
|
|
27
37
|
*/
|
|
@@ -29,7 +39,6 @@ function getMinMaxY(vertices) {
|
|
|
29
39
|
const points = vertices.map((point) => point[1]);
|
|
30
40
|
return { min: Math.min(...points), max: Math.max(...points) };
|
|
31
41
|
}
|
|
32
|
-
exports.getMinMaxY = getMinMaxY;
|
|
33
42
|
/**
|
|
34
43
|
* Determine if a Point is within a Polygon's Y axis.
|
|
35
44
|
*/
|
|
@@ -37,7 +46,6 @@ function isPointInPolygonY(centroid, polygon) {
|
|
|
37
46
|
const yCoords = getMinMaxY(polygon);
|
|
38
47
|
return isPointInY(centroid, yCoords.min, yCoords.max);
|
|
39
48
|
}
|
|
40
|
-
exports.isPointInPolygonY = isPointInPolygonY;
|
|
41
49
|
/**
|
|
42
50
|
* Calculate the relative Y position of a Polygon.
|
|
43
51
|
*
|
|
@@ -49,14 +57,12 @@ function relativeY(polygon) {
|
|
|
49
57
|
.reduce((prev, cur) => prev + cur);
|
|
50
58
|
return polygon.length * sum;
|
|
51
59
|
}
|
|
52
|
-
exports.relativeY = relativeY;
|
|
53
60
|
/**
|
|
54
61
|
* Determine if a Point is within two X coordinates.
|
|
55
62
|
*/
|
|
56
63
|
function isPointInX(centroid, xMin, xMax) {
|
|
57
64
|
return xMin <= centroid[0] && centroid[0] <= xMax;
|
|
58
65
|
}
|
|
59
|
-
exports.isPointInX = isPointInX;
|
|
60
66
|
/**
|
|
61
67
|
* Get the maximum and minimum X coordinates in a given list of Points.
|
|
62
68
|
*/
|
|
@@ -64,7 +70,6 @@ function getMinMaxX(vertices) {
|
|
|
64
70
|
const points = vertices.map((point) => point[0]);
|
|
65
71
|
return { min: Math.min(...points), max: Math.max(...points) };
|
|
66
72
|
}
|
|
67
|
-
exports.getMinMaxX = getMinMaxX;
|
|
68
73
|
/**
|
|
69
74
|
* Determine if a Point is within a Polygon's X axis.
|
|
70
75
|
*/
|
|
@@ -72,7 +77,6 @@ function isPointInPolygonX(centroid, polygon) {
|
|
|
72
77
|
const xCoords = getMinMaxX(polygon);
|
|
73
78
|
return isPointInX(centroid, xCoords.min, xCoords.max);
|
|
74
79
|
}
|
|
75
|
-
exports.isPointInPolygonX = isPointInPolygonX;
|
|
76
80
|
/**
|
|
77
81
|
* Calculate the relative X position of a Polygon.
|
|
78
82
|
*
|
|
@@ -84,7 +88,6 @@ function relativeX(polygon) {
|
|
|
84
88
|
.reduce((prev, cur) => prev + cur);
|
|
85
89
|
return polygon.length * sum;
|
|
86
90
|
}
|
|
87
|
-
exports.relativeX = relativeX;
|
|
88
91
|
function getMinYCoordinate(polygon) {
|
|
89
92
|
return polygon.sort((point1, point2) => {
|
|
90
93
|
if (point1[1] < point2[1]) {
|
|
@@ -96,7 +99,6 @@ function getMinYCoordinate(polygon) {
|
|
|
96
99
|
return 0;
|
|
97
100
|
})[0][1];
|
|
98
101
|
}
|
|
99
|
-
exports.getMinYCoordinate = getMinYCoordinate;
|
|
100
102
|
function getMinXCoordinate(polygon) {
|
|
101
103
|
return polygon.sort((point1, point2) => {
|
|
102
104
|
if (point1[0] < point2[0]) {
|
|
@@ -108,7 +110,6 @@ function getMinXCoordinate(polygon) {
|
|
|
108
110
|
return 0;
|
|
109
111
|
})[0][0];
|
|
110
112
|
}
|
|
111
|
-
exports.getMinXCoordinate = getMinXCoordinate;
|
|
112
113
|
function compareOnY(polygon1, polygon2) {
|
|
113
114
|
const sort = getMinYCoordinate(polygon1) - getMinYCoordinate(polygon2);
|
|
114
115
|
if (sort === 0) {
|
|
@@ -116,7 +117,6 @@ function compareOnY(polygon1, polygon2) {
|
|
|
116
117
|
}
|
|
117
118
|
return sort < 0 ? -1 : 1;
|
|
118
119
|
}
|
|
119
|
-
exports.compareOnY = compareOnY;
|
|
120
120
|
function compareOnX(polygon1, polygon2) {
|
|
121
121
|
const sort = getMinXCoordinate(polygon1) - getMinXCoordinate(polygon2);
|
|
122
122
|
if (sort === 0) {
|
|
@@ -124,4 +124,3 @@ function compareOnX(polygon1, polygon2) {
|
|
|
124
124
|
}
|
|
125
125
|
return sort < 0 ? -1 : 1;
|
|
126
126
|
}
|
|
127
|
-
exports.compareOnX = compareOnX;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const API_KEY_ENVVAR_NAME: string;
|
|
2
2
|
export declare const API_HOST_ENVVAR_NAME: string;
|
|
3
3
|
export declare const STANDARD_API_OWNER: string;
|
|
4
|
+
export declare const TIMEOUT_DEFAULT: number;
|
|
4
5
|
interface MindeeApiConstructorProps {
|
|
5
6
|
apiKey: string;
|
|
6
7
|
}
|
|
@@ -8,6 +9,7 @@ export declare class ApiSettings {
|
|
|
8
9
|
apiKey: string;
|
|
9
10
|
baseHeaders: Record<string, string>;
|
|
10
11
|
hostname: string;
|
|
12
|
+
timeout: number;
|
|
11
13
|
constructor({ apiKey, }: MindeeApiConstructorProps);
|
|
12
14
|
protected apiKeyFromEnv(): string;
|
|
13
15
|
protected hostnameFromEnv(): string;
|
package/src/http/apiSettings.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ApiSettings = exports.STANDARD_API_OWNER = exports.API_HOST_ENVVAR_NAME = exports.API_KEY_ENVVAR_NAME = void 0;
|
|
26
|
+
exports.ApiSettings = exports.TIMEOUT_DEFAULT = exports.STANDARD_API_OWNER = exports.API_HOST_ENVVAR_NAME = exports.API_KEY_ENVVAR_NAME = void 0;
|
|
27
27
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
28
28
|
const logger_1 = require("../logger");
|
|
29
29
|
const package_json_1 = require("../../package.json");
|
|
@@ -31,6 +31,7 @@ const os = __importStar(require("os"));
|
|
|
31
31
|
exports.API_KEY_ENVVAR_NAME = "MINDEE_API_KEY";
|
|
32
32
|
exports.API_HOST_ENVVAR_NAME = "MINDEE_API_HOST";
|
|
33
33
|
exports.STANDARD_API_OWNER = "mindee";
|
|
34
|
+
exports.TIMEOUT_DEFAULT = 120;
|
|
34
35
|
const DEFAULT_MINDEE_API_HOST = "api.mindee.net";
|
|
35
36
|
const USER_AGENT = `mindee-api-nodejs@v${package_json_1.version} nodejs-${process.version} ${os.type().toLowerCase()}`;
|
|
36
37
|
class ApiSettings {
|
|
@@ -50,6 +51,7 @@ class ApiSettings {
|
|
|
50
51
|
Authorization: `Token ${this.apiKey}`,
|
|
51
52
|
};
|
|
52
53
|
this.hostname = this.hostnameFromEnv();
|
|
54
|
+
this.timeout = process.env.MINDEE_REQUEST_TIMEOUT ? parseInt(process.env.MINDEE_REQUEST_TIMEOUT) : exports.TIMEOUT_DEFAULT;
|
|
53
55
|
}
|
|
54
56
|
apiKeyFromEnv() {
|
|
55
57
|
const envVarValue = process.env[exports.API_KEY_ENVVAR_NAME];
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
import { ApiSettings } from "./apiSettings";
|
|
4
2
|
import { IncomingMessage, ClientRequest } from "http";
|
|
5
3
|
import { RequestOptions } from "https";
|
|
4
|
+
import { InputSource, PageOptions } from "../input";
|
|
6
5
|
export interface EndpointResponse {
|
|
7
6
|
messageObj: IncomingMessage;
|
|
8
7
|
data: {
|
|
@@ -15,7 +14,15 @@ export interface EndpointResponse {
|
|
|
15
14
|
export declare abstract class BaseEndpoint {
|
|
16
15
|
/** Settings relating to the API. */
|
|
17
16
|
settings: ApiSettings;
|
|
18
|
-
|
|
17
|
+
/** Entire root of the URL for API calls. */
|
|
18
|
+
urlRoot: string;
|
|
19
|
+
protected constructor(settings: ApiSettings, urlRoot: string);
|
|
20
|
+
/**
|
|
21
|
+
* Cuts a document's pages according to the given options.
|
|
22
|
+
* @param inputDoc input document.
|
|
23
|
+
* @param pageOptions page cutting options.
|
|
24
|
+
*/
|
|
25
|
+
protected cutDocPages(inputDoc: InputSource, pageOptions: PageOptions): Promise<void>;
|
|
19
26
|
/**
|
|
20
27
|
* Reads a response from the API and processes it.
|
|
21
28
|
* @param options options related to the request itself.
|
package/src/http/baseEndpoint.js
CHANGED
|
@@ -3,12 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseEndpoint = void 0;
|
|
4
4
|
const logger_1 = require("../logger");
|
|
5
5
|
const https_1 = require("https");
|
|
6
|
+
const base_1 = require("../input/base");
|
|
6
7
|
/**
|
|
7
8
|
* Base endpoint for the Mindee API.
|
|
8
9
|
*/
|
|
9
10
|
class BaseEndpoint {
|
|
10
|
-
constructor(settings) {
|
|
11
|
+
constructor(settings, urlRoot) {
|
|
11
12
|
this.settings = settings;
|
|
13
|
+
this.urlRoot = urlRoot;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Cuts a document's pages according to the given options.
|
|
17
|
+
* @param inputDoc input document.
|
|
18
|
+
* @param pageOptions page cutting options.
|
|
19
|
+
*/
|
|
20
|
+
async cutDocPages(inputDoc, pageOptions) {
|
|
21
|
+
if (inputDoc instanceof base_1.LocalInputSource && inputDoc.isPdf()) {
|
|
22
|
+
await inputDoc.cutPdf(pageOptions);
|
|
23
|
+
}
|
|
12
24
|
}
|
|
13
25
|
/**
|
|
14
26
|
* Reads a response from the API and processes it.
|
|
@@ -46,7 +58,7 @@ class BaseEndpoint {
|
|
|
46
58
|
reject(error);
|
|
47
59
|
}
|
|
48
60
|
}
|
|
49
|
-
catch
|
|
61
|
+
catch {
|
|
50
62
|
logger_1.logger.error("Could not parse the return as JSON.");
|
|
51
63
|
logger_1.logger.debug(responseBody);
|
|
52
64
|
resolve({
|
package/src/http/endpoint.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { InputSource } from "../input";
|
|
2
|
-
import { PageOptions } from "../input";
|
|
3
2
|
import { ApiSettings } from "./apiSettings";
|
|
4
3
|
import { BaseEndpoint, EndpointResponse } from "./baseEndpoint";
|
|
5
4
|
import { StringDict } from "../parsing/common";
|
|
6
|
-
|
|
7
|
-
inputDoc: InputSource;
|
|
8
|
-
includeWords: boolean;
|
|
9
|
-
fullText: boolean;
|
|
10
|
-
pageOptions?: PageOptions;
|
|
11
|
-
cropper: boolean;
|
|
12
|
-
}
|
|
5
|
+
import { PredictParams } from "./httpParams";
|
|
13
6
|
/**
|
|
14
7
|
* Endpoint for a product (OTS or Custom).
|
|
15
8
|
*/
|
|
@@ -21,11 +14,9 @@ export declare class Endpoint extends BaseEndpoint {
|
|
|
21
14
|
owner: string;
|
|
22
15
|
/** Product's version, as a string. */
|
|
23
16
|
version: string;
|
|
24
|
-
/** Entire root of the URL for API calls. */
|
|
25
|
-
urlRoot: string;
|
|
26
17
|
constructor(urlName: string, owner: string, version: string, settings: ApiSettings);
|
|
27
18
|
/**
|
|
28
|
-
* Sends a
|
|
19
|
+
* Sends a document to the API and parses out the result.
|
|
29
20
|
* Throws an error if the server's response contains one.
|
|
30
21
|
* @param {PredictParams} params parameters relating to prediction options.
|
|
31
22
|
* @category Synchronous
|
|
@@ -40,6 +31,7 @@ export declare class Endpoint extends BaseEndpoint {
|
|
|
40
31
|
* @returns a `Promise` containing queue data.
|
|
41
32
|
*/
|
|
42
33
|
predictAsync(params: PredictParams): Promise<EndpointResponse>;
|
|
34
|
+
private extractStatusMessage;
|
|
43
35
|
/**
|
|
44
36
|
* Requests the results of a queued document from the API.
|
|
45
37
|
* Throws an error if the server's response contains one.
|
package/src/http/endpoint.js
CHANGED
|
@@ -7,7 +7,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
7
7
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
9
|
};
|
|
10
|
-
var _Endpoint_instances,
|
|
10
|
+
var _Endpoint_instances, _Endpoint_predictReqPost, _Endpoint_predictAsyncReqPost, _Endpoint_documentQueueReqGet, _Endpoint_documentGetReq, _Endpoint_documentFeedbackPutReq;
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Endpoint = void 0;
|
|
13
13
|
const url_1 = require("url");
|
|
@@ -21,15 +21,14 @@ const responseValidation_1 = require("./responseValidation");
|
|
|
21
21
|
*/
|
|
22
22
|
class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
23
23
|
constructor(urlName, owner, version, settings) {
|
|
24
|
-
super(settings);
|
|
24
|
+
super(settings, `/v1/products/${owner}/${urlName}/v${version}`);
|
|
25
25
|
_Endpoint_instances.add(this);
|
|
26
26
|
this.owner = owner;
|
|
27
27
|
this.urlName = urlName;
|
|
28
28
|
this.version = version;
|
|
29
|
-
this.urlRoot = `/v1/products/${owner}/${urlName}/v${version}`;
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
|
-
* Sends a
|
|
31
|
+
* Sends a document to the API and parses out the result.
|
|
33
32
|
* Throws an error if the server's response contains one.
|
|
34
33
|
* @param {PredictParams} params parameters relating to prediction options.
|
|
35
34
|
* @category Synchronous
|
|
@@ -38,11 +37,11 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
38
37
|
async predict(params) {
|
|
39
38
|
await params.inputDoc.init();
|
|
40
39
|
if (params.pageOptions !== undefined) {
|
|
41
|
-
await
|
|
40
|
+
await super.cutDocPages(params.inputDoc, params.pageOptions);
|
|
42
41
|
}
|
|
43
42
|
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper);
|
|
44
43
|
if (!(0, responseValidation_1.isValidSyncResponse)(response)) {
|
|
45
|
-
(0, error_1.handleError)(this.urlName, response, response
|
|
44
|
+
(0, error_1.handleError)(this.urlName, response, this.extractStatusMessage(response));
|
|
46
45
|
}
|
|
47
46
|
return response;
|
|
48
47
|
}
|
|
@@ -56,14 +55,28 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
56
55
|
async predictAsync(params) {
|
|
57
56
|
await params.inputDoc.init();
|
|
58
57
|
if (params.pageOptions !== undefined) {
|
|
59
|
-
await
|
|
58
|
+
await super.cutDocPages(params.inputDoc, params.pageOptions);
|
|
60
59
|
}
|
|
61
60
|
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictAsyncReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper);
|
|
62
61
|
if (!(0, responseValidation_1.isValidAsyncResponse)(response)) {
|
|
63
|
-
(0, error_1.handleError)(this.urlName, response, response
|
|
62
|
+
(0, error_1.handleError)(this.urlName, response, this.extractStatusMessage(response));
|
|
64
63
|
}
|
|
65
64
|
return response;
|
|
66
65
|
}
|
|
66
|
+
extractStatusMessage(response) {
|
|
67
|
+
if (response.messageObj?.statusMessage !== undefined && response.messageObj?.statusMessage !== null) {
|
|
68
|
+
return response.messageObj?.statusMessage;
|
|
69
|
+
}
|
|
70
|
+
const errorDetail = response.data?.api_request?.error?.detail;
|
|
71
|
+
if (errorDetail) {
|
|
72
|
+
return JSON.stringify(errorDetail);
|
|
73
|
+
}
|
|
74
|
+
const errorMessage = response.data?.api_request?.error?.message;
|
|
75
|
+
if (errorMessage) {
|
|
76
|
+
return JSON.stringify(errorMessage);
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
67
80
|
/**
|
|
68
81
|
* Requests the results of a queued document from the API.
|
|
69
82
|
* Throws an error if the server's response contains one.
|
|
@@ -75,7 +88,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
75
88
|
const queueResponse = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_documentQueueReqGet).call(this, queueId);
|
|
76
89
|
const queueStatusCode = queueResponse.messageObj.statusCode;
|
|
77
90
|
if (!(0, responseValidation_1.isValidAsyncResponse)(queueResponse)) {
|
|
78
|
-
(0, error_1.handleError)(this.urlName, queueResponse, queueResponse
|
|
91
|
+
(0, error_1.handleError)(this.urlName, queueResponse, this.extractStatusMessage(queueResponse));
|
|
79
92
|
}
|
|
80
93
|
if (queueStatusCode === 302 &&
|
|
81
94
|
queueResponse.messageObj.headers.location !== undefined) {
|
|
@@ -93,7 +106,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
93
106
|
async getDocument(documentId) {
|
|
94
107
|
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_documentGetReq).call(this, documentId);
|
|
95
108
|
if (!(0, responseValidation_1.isValidAsyncResponse)(response)) {
|
|
96
|
-
(0, error_1.handleError)("document", response, response
|
|
109
|
+
(0, error_1.handleError)("document", response, this.extractStatusMessage(response));
|
|
97
110
|
}
|
|
98
111
|
return response;
|
|
99
112
|
}
|
|
@@ -105,7 +118,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
105
118
|
async sendFeedback(documentId, feedback) {
|
|
106
119
|
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_documentFeedbackPutReq).call(this, documentId, feedback);
|
|
107
120
|
if (!(0, responseValidation_1.isValidSyncResponse)(response)) {
|
|
108
|
-
(0, error_1.handleError)("feedback", response, response
|
|
121
|
+
(0, error_1.handleError)("feedback", response, this.extractStatusMessage(response));
|
|
109
122
|
}
|
|
110
123
|
return response;
|
|
111
124
|
}
|
|
@@ -148,6 +161,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
148
161
|
headers: headers,
|
|
149
162
|
hostname: this.settings.hostname,
|
|
150
163
|
path: path,
|
|
164
|
+
timeout: this.settings.timeout,
|
|
151
165
|
};
|
|
152
166
|
const req = this.readResponse(options, resolve, reject);
|
|
153
167
|
form.pipe(req);
|
|
@@ -157,17 +171,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
157
171
|
}
|
|
158
172
|
}
|
|
159
173
|
exports.Endpoint = Endpoint;
|
|
160
|
-
_Endpoint_instances = new WeakSet(),
|
|
161
|
-
/**
|
|
162
|
-
* Cuts a document's pages according to the given options.
|
|
163
|
-
* @param inputDoc input document.
|
|
164
|
-
* @param pageOptions page cutting options.
|
|
165
|
-
*/
|
|
166
|
-
async function _Endpoint_cutDocPages(inputDoc, pageOptions) {
|
|
167
|
-
if (inputDoc instanceof base_1.LocalInputSource && inputDoc.isPdf()) {
|
|
168
|
-
await inputDoc.cutPdf(pageOptions);
|
|
169
|
-
}
|
|
170
|
-
}, _Endpoint_predictReqPost = function _Endpoint_predictReqPost(input, includeWords = false, fullText = false, cropper = false) {
|
|
174
|
+
_Endpoint_instances = new WeakSet(), _Endpoint_predictReqPost = function _Endpoint_predictReqPost(input, includeWords = false, fullText = false, cropper = false) {
|
|
171
175
|
return this.sendFileForPrediction(input, "predict", includeWords, fullText, cropper);
|
|
172
176
|
}, _Endpoint_predictAsyncReqPost = function _Endpoint_predictAsyncReqPost(input, includeWords = false, fullText = false, cropper = false) {
|
|
173
177
|
return this.sendFileForPrediction(input, "predict_async", includeWords, fullText, cropper);
|