mindee 5.0.0-rc1 → 5.0.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 +29 -3
- package/package.json +33 -33
- package/src/geometry/polygon.d.ts +1 -0
- package/src/geometry/polygon.js +3 -0
- package/src/http/apiCore.d.ts +4 -4
- package/src/http/apiCore.js +3 -4
- package/src/http/baseSettings.d.ts +1 -1
- package/src/http/baseSettings.js +4 -2
- package/src/v1/http/endpoint.js +6 -5
- package/src/v1/http/workflowEndpoint.js +3 -2
- package/src/v2/cli.js +10 -13
- package/src/v2/client/baseParameters.d.ts +2 -5
- package/src/v2/client/baseParameters.js +2 -5
- package/src/v2/client/index.d.ts +1 -1
- package/src/v2/client/pollingOptions.d.ts +11 -13
- package/src/v2/client/pollingOptions.js +9 -5
- package/src/v2/http/{apiSettingsV2.d.ts → apiSettings.d.ts} +1 -1
- package/src/v2/http/{apiSettingsV2.js → apiSettings.js} +2 -1
- package/src/v2/http/errors.d.ts +3 -0
- package/src/v2/http/errors.js +3 -0
- package/src/v2/http/mindeeApiV2.d.ts +2 -2
- package/src/v2/http/mindeeApiV2.js +7 -6
- package/src/v2/index.d.ts +2 -1
- package/src/v2/index.js +1 -0
- package/src/v2/parsing/inference/baseInference.d.ts +6 -1
- package/src/v2/parsing/inference/baseInference.js +3 -0
- package/src/v2/parsing/inference/inferenceJob.d.ts +9 -0
- package/src/v2/parsing/inference/inferenceJob.js +10 -0
- package/src/v2/product/baseProduct.d.ts +5 -0
- package/src/v2/product/baseProduct.js +5 -0
- package/src/v2/product/classification/classification.d.ts +3 -0
- package/src/v2/product/classification/classification.js +3 -0
- package/src/v2/product/crop/crop.d.ts +3 -0
- package/src/v2/product/crop/crop.js +3 -0
- package/src/v2/product/extraction/extraction.d.ts +3 -0
- package/src/v2/product/extraction/extraction.js +3 -0
- package/src/v2/product/extraction/params/extractionParameters.d.ts +1 -0
- package/src/v2/product/extraction/params/extractionParameters.js +1 -0
- package/src/v2/product/ocr/ocr.d.ts +3 -0
- package/src/v2/product/ocr/ocr.js +3 -0
- package/src/v2/product/split/split.d.ts +3 -0
- package/src/v2/product/split/split.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## v5.0.0 - 2026-02-19
|
|
4
|
+
### ¡Breaking Changes!
|
|
5
|
+
* :boom: :sparkles: move PDF and image libraries to optional dependencies (resolves #388)
|
|
6
|
+
* :recycle: :boom: rework of directory structure and exports (resolves #276)
|
|
7
|
+
* :boom: drop support for node.js 18
|
|
8
|
+
* :boom: :recycle: separate polling options
|
|
9
|
+
* :coffin: remove support for API builder (no longer maintained, use v2)
|
|
10
|
+
* :coffin: remove support for v1 products available in v2
|
|
11
|
+
* :coffin: remove support for unused products
|
|
12
|
+
### Changes
|
|
13
|
+
* :sparkles: add support for all utility products
|
|
14
|
+
* :sparkles: add V2 CLI
|
|
15
|
+
* :sparkles: add Job to inference responses
|
|
16
|
+
* :sparkles: handle abort signal stream inputs
|
|
17
|
+
* :recycle: use undici (compatible with v6 or v7) for HTTP requests and mocking
|
|
18
|
+
* :sparkles: add ability for a user to specify their own undici `Dispatcher` instance
|
|
19
|
+
* :recycle: migrate to ES modules
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## v5.0.0-rc2 - 2026-02-18
|
|
23
|
+
### Changes
|
|
24
|
+
* :sparkles: add Job to inference responses
|
|
25
|
+
### Fixes
|
|
26
|
+
* :bug: fix for bin scripts
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## v5.0.0-rc1 - 2026-02-17
|
|
4
30
|
### Changes
|
|
5
31
|
* :boom: drop support for node.js 18
|
|
6
32
|
* :boom: :recycle: separate polling options
|
|
7
33
|
|
|
8
34
|
|
|
9
|
-
##
|
|
35
|
+
## v5.0.0-alpha2 - 2026-02-16
|
|
10
36
|
### Changes
|
|
11
37
|
* :recycle: use node test methods
|
|
12
38
|
* :recycle: v1 ocr word should be a class
|
|
@@ -14,7 +40,7 @@
|
|
|
14
40
|
* :bug: fix for optional node-poppler
|
|
15
41
|
|
|
16
42
|
|
|
17
|
-
##
|
|
43
|
+
## v5.0.0-alpha1 - 2026-02-13
|
|
18
44
|
### :boom: :recycle: base for v5
|
|
19
45
|
* :arrow_up: update file-type
|
|
20
46
|
* :recycle: migrate to ES modules (node18)
|
package/package.json
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Mindee",
|
|
7
|
+
"email": "opensource@mindee.com",
|
|
8
|
+
"url": "https://mindee.com/"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/mindee/mindee-api-nodejs.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/mindee/mindee-api-nodejs/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://mindee.com/",
|
|
19
|
+
"type": "module",
|
|
5
20
|
"main": "src/index.js",
|
|
6
21
|
"bin": {
|
|
7
22
|
"mindeeV1": "bin/mindeeV1.js",
|
|
8
23
|
"mindeeV2": "bin/mindeeV2.js"
|
|
9
24
|
},
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"type": "module",
|
|
12
25
|
"scripts": {
|
|
13
26
|
"build": "tsc --build && tsc-alias",
|
|
14
27
|
"build-for-dist": "tsc --build && tsc-alias && cp LICENSE README.md CHANGELOG.md ./dist",
|
|
@@ -33,46 +46,33 @@
|
|
|
33
46
|
"engines": {
|
|
34
47
|
"node": ">= 20.1"
|
|
35
48
|
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"email": "opensource@mindee.com",
|
|
43
|
-
"url": "https://mindee.com/"
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"commander": "^14.0.3",
|
|
51
|
+
"file-type": "^21.3.0",
|
|
52
|
+
"tmp": "^0.2.3",
|
|
53
|
+
"tslib": "^2.8.1",
|
|
54
|
+
"undici": ">=6.23.0 <8.0.0"
|
|
44
55
|
},
|
|
45
|
-
"
|
|
46
|
-
"
|
|
56
|
+
"optionalDependencies": {
|
|
57
|
+
"@cantoo/pdf-lib": "^2.5.3",
|
|
58
|
+
"node-poppler": "^9.1.1",
|
|
59
|
+
"pdf.js-extract": "~0.2.1",
|
|
60
|
+
"sharp": "~0.34.5"
|
|
47
61
|
},
|
|
48
|
-
"homepage": "https://mindee.com/",
|
|
49
62
|
"devDependencies": {
|
|
50
63
|
"@types/mocha": "^10.0.10",
|
|
51
|
-
"@types/node": "^
|
|
64
|
+
"@types/node": "^20.19.33",
|
|
52
65
|
"@types/tmp": "^0.2.6",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
54
|
-
"@typescript-eslint/parser": "^8.
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
67
|
+
"@typescript-eslint/parser": "^8.56.0",
|
|
55
68
|
"eslint": "^9.39.2",
|
|
56
|
-
"eslint-plugin-jsdoc": "^
|
|
57
|
-
"mocha": "^11.
|
|
69
|
+
"eslint-plugin-jsdoc": "^62.6.0",
|
|
70
|
+
"mocha": "^11.7.5",
|
|
58
71
|
"tsc-alias": "^1.8.16",
|
|
59
72
|
"tsx": "^4.21.0",
|
|
60
|
-
"typedoc": "
|
|
73
|
+
"typedoc": "^0.28.17",
|
|
61
74
|
"typescript": "^5.9.3"
|
|
62
75
|
},
|
|
63
|
-
"dependencies": {
|
|
64
|
-
"commander": "~9.4.1",
|
|
65
|
-
"file-type": "^19.6.0",
|
|
66
|
-
"tmp": "^0.2.3",
|
|
67
|
-
"tslib": "^2.8.1",
|
|
68
|
-
"undici": "^6.23.0"
|
|
69
|
-
},
|
|
70
|
-
"optionalDependencies": {
|
|
71
|
-
"@cantoo/pdf-lib": "^2.3.2",
|
|
72
|
-
"node-poppler": "^7.2.4",
|
|
73
|
-
"pdf.js-extract": "^0.2.1",
|
|
74
|
-
"sharp": "~0.34.5"
|
|
75
|
-
},
|
|
76
76
|
"keywords": [
|
|
77
77
|
"typescript",
|
|
78
78
|
"mindee",
|
package/src/geometry/polygon.js
CHANGED
package/src/http/apiCore.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Dispatcher } from "undici";
|
|
1
|
+
import { Dispatcher, FormData } from "undici";
|
|
2
2
|
import { InputSource, PageOptions } from "../input/index.js";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const TIMEOUT_SECS_DEFAULT: number;
|
|
4
4
|
export interface RequestOptions {
|
|
5
5
|
hostname: string;
|
|
6
6
|
path: string;
|
|
7
7
|
method: any;
|
|
8
|
-
|
|
8
|
+
timeoutSecs: number;
|
|
9
9
|
headers: any;
|
|
10
|
-
body?:
|
|
10
|
+
body?: FormData | string;
|
|
11
11
|
}
|
|
12
12
|
export interface BaseHttpResponse {
|
|
13
13
|
messageObj: any;
|
package/src/http/apiCore.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { logger } from "../logger.js";
|
|
2
2
|
import { request } from "undici";
|
|
3
3
|
import { LocalInputSource } from "../input/index.js";
|
|
4
|
-
export const
|
|
4
|
+
export const TIMEOUT_SECS_DEFAULT = 120;
|
|
5
5
|
/**
|
|
6
6
|
* Cuts a document's pages according to the given options.
|
|
7
7
|
* @param inputDoc input document.
|
|
@@ -24,10 +24,9 @@ export async function sendRequestAndReadResponse(dispatcher, options) {
|
|
|
24
24
|
const response = await request(url, {
|
|
25
25
|
method: options.method,
|
|
26
26
|
headers: options.headers,
|
|
27
|
-
|
|
27
|
+
headersTimeout: options.timeoutSecs * 1000,
|
|
28
28
|
body: options.body,
|
|
29
|
-
|
|
30
|
-
dispatcher: dispatcher
|
|
29
|
+
dispatcher: dispatcher,
|
|
31
30
|
});
|
|
32
31
|
logger.debug("Parsing the response ...");
|
|
33
32
|
let responseBody = await response.body.text();
|
|
@@ -6,7 +6,7 @@ export interface MindeeApiConstructorProps {
|
|
|
6
6
|
export declare abstract class BaseSettings {
|
|
7
7
|
apiKey: string;
|
|
8
8
|
hostname: string;
|
|
9
|
-
|
|
9
|
+
timeoutSecs: number;
|
|
10
10
|
dispatcher: Dispatcher;
|
|
11
11
|
protected constructor(apiKey?: string, dispatcher?: Dispatcher);
|
|
12
12
|
protected getUserAgent(): string;
|
package/src/http/baseSettings.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getGlobalDispatcher } from "undici";
|
|
2
2
|
import packageJson from "../../package.json" with { type: "json" };
|
|
3
3
|
import * as os from "os";
|
|
4
|
-
import {
|
|
4
|
+
import { TIMEOUT_SECS_DEFAULT } from "./apiCore.js";
|
|
5
5
|
export class BaseSettings {
|
|
6
6
|
constructor(apiKey, dispatcher) {
|
|
7
7
|
if (apiKey === undefined || !apiKey || apiKey.length === 0) {
|
|
@@ -12,7 +12,9 @@ export class BaseSettings {
|
|
|
12
12
|
}
|
|
13
13
|
this.dispatcher = dispatcher ?? getGlobalDispatcher();
|
|
14
14
|
this.hostname = this.hostnameFromEnv();
|
|
15
|
-
this.
|
|
15
|
+
this.timeoutSecs = process.env.MINDEE_REQUEST_TIMEOUT
|
|
16
|
+
? parseInt(process.env.MINDEE_REQUEST_TIMEOUT)
|
|
17
|
+
: TIMEOUT_SECS_DEFAULT;
|
|
16
18
|
}
|
|
17
19
|
getUserAgent() {
|
|
18
20
|
let platform = os.type().toLowerCase();
|
package/src/v1/http/endpoint.js
CHANGED
|
@@ -5,8 +5,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
5
5
|
};
|
|
6
6
|
var _Endpoint_instances, _Endpoint_predictReqPost, _Endpoint_predictAsyncReqPost, _Endpoint_documentQueueReqGet, _Endpoint_documentGetReq, _Endpoint_documentFeedbackPutReq;
|
|
7
7
|
import { URLSearchParams } from "url";
|
|
8
|
+
import { FormData } from "undici";
|
|
8
9
|
import { LocalInputSource } from "../../input/index.js";
|
|
9
|
-
import { cutDocPages, sendRequestAndReadResponse } from "../../http/apiCore.js";
|
|
10
|
+
import { cutDocPages, sendRequestAndReadResponse, } from "../../http/apiCore.js";
|
|
10
11
|
import { handleError } from "./errors.js";
|
|
11
12
|
import { isValidAsyncResponse, isValidSyncResponse } from "./responseValidation.js";
|
|
12
13
|
/**
|
|
@@ -162,7 +163,7 @@ export class Endpoint {
|
|
|
162
163
|
headers: this.settings.baseHeaders,
|
|
163
164
|
hostname: this.settings.hostname,
|
|
164
165
|
path: path,
|
|
165
|
-
|
|
166
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
166
167
|
body: form,
|
|
167
168
|
};
|
|
168
169
|
return await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
|
@@ -193,7 +194,7 @@ async function _Endpoint_documentQueueReqGet(queueId) {
|
|
|
193
194
|
headers: this.settings.baseHeaders,
|
|
194
195
|
hostname: this.settings.hostname,
|
|
195
196
|
path: `${this.urlRoot}/documents/queue/${queueId}`,
|
|
196
|
-
|
|
197
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
197
198
|
};
|
|
198
199
|
return await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
|
199
200
|
}, _Endpoint_documentGetReq =
|
|
@@ -207,7 +208,7 @@ async function _Endpoint_documentGetReq(documentId) {
|
|
|
207
208
|
headers: this.settings.baseHeaders,
|
|
208
209
|
hostname: this.settings.hostname,
|
|
209
210
|
path: `${this.urlRoot}/documents/${documentId}`,
|
|
210
|
-
|
|
211
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
211
212
|
};
|
|
212
213
|
return await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
|
213
214
|
}, _Endpoint_documentFeedbackPutReq =
|
|
@@ -223,7 +224,7 @@ async function _Endpoint_documentFeedbackPutReq(documentId, feedback) {
|
|
|
223
224
|
hostname: this.settings.hostname,
|
|
224
225
|
path: `/v1/documents/${documentId}/feedback`,
|
|
225
226
|
body: JSON.stringify(feedback),
|
|
226
|
-
|
|
227
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
227
228
|
};
|
|
228
229
|
return await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
|
229
230
|
};
|
|
@@ -5,8 +5,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
5
5
|
};
|
|
6
6
|
var _WorkflowEndpoint_instances, _WorkflowEndpoint_workflowReqPost;
|
|
7
7
|
import { URLSearchParams } from "url";
|
|
8
|
+
import { FormData } from "undici";
|
|
8
9
|
import { LocalInputSource } from "../../input/index.js";
|
|
9
|
-
import { cutDocPages, sendRequestAndReadResponse } from "../../http/apiCore.js";
|
|
10
|
+
import { cutDocPages, sendRequestAndReadResponse, } from "../../http/apiCore.js";
|
|
10
11
|
import { handleError } from "./errors.js";
|
|
11
12
|
import { isValidSyncResponse } from "./responseValidation.js";
|
|
12
13
|
/**
|
|
@@ -78,7 +79,7 @@ export class WorkflowEndpoint {
|
|
|
78
79
|
headers: this.settings.baseHeaders,
|
|
79
80
|
hostname: this.settings.hostname,
|
|
80
81
|
path: path,
|
|
81
|
-
|
|
82
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
82
83
|
body: form,
|
|
83
84
|
};
|
|
84
85
|
return await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
package/src/v2/cli.js
CHANGED
|
@@ -16,13 +16,10 @@ function initClient(options) {
|
|
|
16
16
|
async function enqueueAndGetInference(product, inputPath, options) {
|
|
17
17
|
const mindeeClient = initClient(options);
|
|
18
18
|
const inputSource = new PathInput({ inputPath: inputPath });
|
|
19
|
-
const response = await mindeeClient.enqueueAndGetResult(product, inputSource, {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
delaySec: 1.5,
|
|
24
|
-
maxRetries: 80,
|
|
25
|
-
}
|
|
19
|
+
const response = await mindeeClient.enqueueAndGetResult(product, inputSource, { modelId: options.model }, {
|
|
20
|
+
initialDelaySec: 2,
|
|
21
|
+
delaySec: 1.5,
|
|
22
|
+
maxRetries: 80,
|
|
26
23
|
});
|
|
27
24
|
if (!response.inference) {
|
|
28
25
|
throw Error("Inference could not be retrieved");
|
|
@@ -47,11 +44,11 @@ export function cli() {
|
|
|
47
44
|
.option("-d, --debug", "high verbosity mode")
|
|
48
45
|
.option("-k, --api-key <api_key>", "your Mindee API key");
|
|
49
46
|
const inferenceTypes = [
|
|
50
|
-
{ name: "extraction", description: "Extract data from a document.",
|
|
51
|
-
{ name: "crop", description: "Crop a document.",
|
|
52
|
-
{ name: "split", description: "Split a document into pages.",
|
|
53
|
-
{ name: "ocr", description: "Read text from a document.",
|
|
54
|
-
{ name: "classification", description: "Classify a document.",
|
|
47
|
+
{ name: "extraction", description: "Extract data from a document.", productClass: Extraction },
|
|
48
|
+
{ name: "crop", description: "Crop a document.", productClass: Crop },
|
|
49
|
+
{ name: "split", description: "Split a document into pages.", productClass: Split },
|
|
50
|
+
{ name: "ocr", description: "Read text from a document.", productClass: Ocr },
|
|
51
|
+
{ name: "classification", description: "Classify a document.", productClass: Classification },
|
|
55
52
|
];
|
|
56
53
|
for (const inference of inferenceTypes) {
|
|
57
54
|
const inferenceCmd = program.command(inference.name)
|
|
@@ -59,7 +56,7 @@ export function cli() {
|
|
|
59
56
|
addMainOptions(inferenceCmd);
|
|
60
57
|
inferenceCmd.action(function (inputPath, options) {
|
|
61
58
|
const allOptions = { ...program.opts(), ...options };
|
|
62
|
-
return enqueueAndGetInference(inference.
|
|
59
|
+
return enqueueAndGetInference(inference.productClass, inputPath, allOptions);
|
|
63
60
|
});
|
|
64
61
|
}
|
|
65
62
|
program.parse(process.argv);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FormData } from "undici";
|
|
1
2
|
/**
|
|
2
3
|
* Constructor parameters for BaseParameters and its subclasses.
|
|
3
4
|
*/
|
|
@@ -8,7 +9,7 @@ export interface BaseParametersConstructor {
|
|
|
8
9
|
closeFile?: boolean;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
|
-
* Parameters accepted by
|
|
12
|
+
* Parameters accepted by all v2 products.
|
|
12
13
|
*
|
|
13
14
|
* All fields are optional except `modelId`.
|
|
14
15
|
*
|
|
@@ -19,10 +20,6 @@ export interface BaseParametersConstructor {
|
|
|
19
20
|
* rag: true,
|
|
20
21
|
* alias: "YOUR_ALIAS",
|
|
21
22
|
* webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"],
|
|
22
|
-
* pollingOptions: {
|
|
23
|
-
* initialDelaySec: 2,
|
|
24
|
-
* delaySec: 1.5,
|
|
25
|
-
* }
|
|
26
23
|
* };
|
|
27
24
|
*/
|
|
28
25
|
export declare abstract class BaseParameters {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { FormData } from "undici";
|
|
1
2
|
import { MindeeConfigurationError } from "../../errors/index.js";
|
|
2
3
|
/**
|
|
3
|
-
* Parameters accepted by
|
|
4
|
+
* Parameters accepted by all v2 products.
|
|
4
5
|
*
|
|
5
6
|
* All fields are optional except `modelId`.
|
|
6
7
|
*
|
|
@@ -11,10 +12,6 @@ import { MindeeConfigurationError } from "../../errors/index.js";
|
|
|
11
12
|
* rag: true,
|
|
12
13
|
* alias: "YOUR_ALIAS",
|
|
13
14
|
* webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"],
|
|
14
|
-
* pollingOptions: {
|
|
15
|
-
* initialDelaySec: 2,
|
|
16
|
-
* delaySec: 1.5,
|
|
17
|
-
* }
|
|
18
15
|
* };
|
|
19
16
|
*/
|
|
20
17
|
export class BaseParameters {
|
package/src/v2/client/index.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ export interface PollingOptionsConstructor {
|
|
|
13
13
|
* Parameters for the internal polling loop in `enqueueAndGetInference()`.
|
|
14
14
|
*
|
|
15
15
|
* Default behavior:
|
|
16
|
-
* - `initialDelaySec` =
|
|
17
|
-
* - `delaySec` = 1.
|
|
16
|
+
* - `initialDelaySec` = 2
|
|
17
|
+
* - `delaySec` = 1.5
|
|
18
18
|
* - `maxRetries` = 80
|
|
19
19
|
*
|
|
20
20
|
* Validation rules:
|
|
@@ -23,17 +23,21 @@ export interface PollingOptionsConstructor {
|
|
|
23
23
|
* - `maxRetries` >= 2
|
|
24
24
|
*
|
|
25
25
|
* The `initialTimerOptions` and `recurringTimerOptions` objects let you pass an
|
|
26
|
-
* `AbortSignal` or make the timer `
|
|
26
|
+
* `AbortSignal` or make the timer `ref`-ed to the `setTimeout()`.
|
|
27
27
|
*
|
|
28
28
|
* @category ClientV2
|
|
29
29
|
* @example
|
|
30
|
-
*
|
|
30
|
+
* ```
|
|
31
|
+
* const pollingOptions = {
|
|
31
32
|
* initialDelaySec: 4,
|
|
32
33
|
* delaySec: 2,
|
|
33
34
|
* maxRetries: 50
|
|
34
35
|
* };
|
|
35
36
|
*
|
|
36
|
-
* const inference = await client.enqueueAndGetInference(
|
|
37
|
+
* const inference = await client.enqueueAndGetInference(
|
|
38
|
+
* inputDoc, params, pollingOptions
|
|
39
|
+
* );
|
|
40
|
+
* ```
|
|
37
41
|
*/
|
|
38
42
|
export declare class PollingOptions {
|
|
39
43
|
/** Number of seconds to wait *before the first poll*. */
|
|
@@ -43,15 +47,9 @@ export declare class PollingOptions {
|
|
|
43
47
|
/** Maximum number of polling attempts (including the first one). */
|
|
44
48
|
maxRetries: number;
|
|
45
49
|
/** Options passed to the initial `setTimeout()`. */
|
|
46
|
-
initialTimerOptions?:
|
|
47
|
-
ref?: boolean;
|
|
48
|
-
signal?: AbortSignal;
|
|
49
|
-
};
|
|
50
|
+
initialTimerOptions?: TimerOptions;
|
|
50
51
|
/** Options passed to every recurring `setTimeout()`. */
|
|
51
|
-
recurringTimerOptions?:
|
|
52
|
-
ref?: boolean;
|
|
53
|
-
signal?: AbortSignal;
|
|
54
|
-
};
|
|
52
|
+
recurringTimerOptions?: TimerOptions;
|
|
55
53
|
constructor(params?: PollingOptionsConstructor);
|
|
56
54
|
validateOptions(): void;
|
|
57
55
|
toString(): string;
|
|
@@ -7,8 +7,8 @@ const minRetries = 2;
|
|
|
7
7
|
* Parameters for the internal polling loop in `enqueueAndGetInference()`.
|
|
8
8
|
*
|
|
9
9
|
* Default behavior:
|
|
10
|
-
* - `initialDelaySec` =
|
|
11
|
-
* - `delaySec` = 1.
|
|
10
|
+
* - `initialDelaySec` = 2
|
|
11
|
+
* - `delaySec` = 1.5
|
|
12
12
|
* - `maxRetries` = 80
|
|
13
13
|
*
|
|
14
14
|
* Validation rules:
|
|
@@ -17,17 +17,21 @@ const minRetries = 2;
|
|
|
17
17
|
* - `maxRetries` >= 2
|
|
18
18
|
*
|
|
19
19
|
* The `initialTimerOptions` and `recurringTimerOptions` objects let you pass an
|
|
20
|
-
* `AbortSignal` or make the timer `
|
|
20
|
+
* `AbortSignal` or make the timer `ref`-ed to the `setTimeout()`.
|
|
21
21
|
*
|
|
22
22
|
* @category ClientV2
|
|
23
23
|
* @example
|
|
24
|
-
*
|
|
24
|
+
* ```
|
|
25
|
+
* const pollingOptions = {
|
|
25
26
|
* initialDelaySec: 4,
|
|
26
27
|
* delaySec: 2,
|
|
27
28
|
* maxRetries: 50
|
|
28
29
|
* };
|
|
29
30
|
*
|
|
30
|
-
* const inference = await client.enqueueAndGetInference(
|
|
31
|
+
* const inference = await client.enqueueAndGetInference(
|
|
32
|
+
* inputDoc, params, pollingOptions
|
|
33
|
+
* );
|
|
34
|
+
* ```
|
|
31
35
|
*/
|
|
32
36
|
export class PollingOptions {
|
|
33
37
|
constructor(params) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseSettings, MindeeApiConstructorProps } from "../../http/baseSettings.js";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class ApiSettings extends BaseSettings {
|
|
3
3
|
baseHeaders: Record<string, string>;
|
|
4
4
|
constructor({ apiKey, dispatcher, }: MindeeApiConstructorProps);
|
|
5
5
|
protected apiKeyFromEnv(): string;
|
|
@@ -4,7 +4,7 @@ import { MindeeConfigurationError } from "../../errors/index.js";
|
|
|
4
4
|
const API_V2_KEY_ENVVAR_NAME = "MINDEE_V2_API_KEY";
|
|
5
5
|
const API_V2_HOST_ENVVAR_NAME = "MINDEE_V2_API_HOST";
|
|
6
6
|
const DEFAULT_MINDEE_API_HOST = "api-v2.mindee.net";
|
|
7
|
-
export class
|
|
7
|
+
export class ApiSettings extends BaseSettings {
|
|
8
8
|
constructor({ apiKey, dispatcher, }) {
|
|
9
9
|
super(apiKey, dispatcher);
|
|
10
10
|
if (!this.apiKey || this.apiKey.length === 0) {
|
|
@@ -16,6 +16,7 @@ export class ApiSettingsV2 extends BaseSettings {
|
|
|
16
16
|
"User-Agent": this.getUserAgent(),
|
|
17
17
|
Authorization: `${this.apiKey}`,
|
|
18
18
|
};
|
|
19
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
19
20
|
}
|
|
20
21
|
apiKeyFromEnv() {
|
|
21
22
|
const envVarValue = process.env[API_V2_KEY_ENVVAR_NAME];
|
package/src/v2/http/errors.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ErrorDetails, ErrorItem, ErrorResponse } from "../../v2/parsing/index.js";
|
|
2
2
|
import { MindeeError } from "../../errors/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* HTTP error returned by the API.
|
|
5
|
+
*/
|
|
3
6
|
export declare class MindeeHttpErrorV2 extends MindeeError implements ErrorDetails {
|
|
4
7
|
status: number;
|
|
5
8
|
detail: string;
|
package/src/v2/http/errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiSettings } from "./apiSettings.js";
|
|
2
2
|
import { Dispatcher } from "undici";
|
|
3
3
|
import { BaseParameters } from "../../v2/client/index.js";
|
|
4
4
|
import { JobResponse } from "../../v2/parsing/index.js";
|
|
@@ -6,7 +6,7 @@ import { InputSource } from "../../input/index.js";
|
|
|
6
6
|
import { BaseProduct } from "../../v2/product/baseProduct.js";
|
|
7
7
|
export declare class MindeeApiV2 {
|
|
8
8
|
#private;
|
|
9
|
-
settings:
|
|
9
|
+
settings: ApiSettings;
|
|
10
10
|
constructor(dispatcher?: Dispatcher, apiKey?: string);
|
|
11
11
|
/**
|
|
12
12
|
* Sends a file to the extraction inference queue.
|
|
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
var _MindeeApiV2_instances, _MindeeApiV2_processResponse, _MindeeApiV2_reqPostProductEnqueue, _MindeeApiV2_reqGetJob, _MindeeApiV2_reqGetProductResult;
|
|
7
|
-
import {
|
|
7
|
+
import { ApiSettings } from "./apiSettings.js";
|
|
8
8
|
import { ErrorResponse, JobResponse, } from "../../v2/parsing/index.js";
|
|
9
9
|
import { sendRequestAndReadResponse } from "../../http/apiCore.js";
|
|
10
10
|
import { LocalInputSource } from "../../input/index.js";
|
|
@@ -14,7 +14,7 @@ import { logger } from "../../logger.js";
|
|
|
14
14
|
export class MindeeApiV2 {
|
|
15
15
|
constructor(dispatcher, apiKey) {
|
|
16
16
|
_MindeeApiV2_instances.add(this);
|
|
17
|
-
this.settings = new
|
|
17
|
+
this.settings = new ApiSettings({ dispatcher: dispatcher, apiKey: apiKey });
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Sends a file to the extraction inference queue.
|
|
@@ -58,7 +58,8 @@ export class MindeeApiV2 {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
_MindeeApiV2_instances = new WeakSet(), _MindeeApiV2_processResponse = function _MindeeApiV2_processResponse(result, responseClass) {
|
|
61
|
-
if (result.messageObj?.statusCode
|
|
61
|
+
if (result.messageObj?.statusCode
|
|
62
|
+
&& (result.messageObj?.statusCode > 399 || result.messageObj?.statusCode < 200)) {
|
|
62
63
|
if (result.data?.status !== null) {
|
|
63
64
|
throw new MindeeHttpErrorV2(new ErrorResponse(result.data));
|
|
64
65
|
}
|
|
@@ -99,7 +100,7 @@ async function _MindeeApiV2_reqPostProductEnqueue(product, inputSource, params)
|
|
|
99
100
|
hostname: this.settings.hostname,
|
|
100
101
|
path: path,
|
|
101
102
|
body: form,
|
|
102
|
-
|
|
103
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
103
104
|
};
|
|
104
105
|
return await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
|
105
106
|
}, _MindeeApiV2_reqGetJob = async function _MindeeApiV2_reqGetJob(jobId) {
|
|
@@ -108,7 +109,7 @@ async function _MindeeApiV2_reqPostProductEnqueue(product, inputSource, params)
|
|
|
108
109
|
headers: this.settings.baseHeaders,
|
|
109
110
|
hostname: this.settings.hostname,
|
|
110
111
|
path: `/v2/jobs/${jobId}`,
|
|
111
|
-
|
|
112
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
112
113
|
};
|
|
113
114
|
return await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
|
114
115
|
}, _MindeeApiV2_reqGetProductResult =
|
|
@@ -125,7 +126,7 @@ async function _MindeeApiV2_reqGetProductResult(inferenceId, slug) {
|
|
|
125
126
|
headers: this.settings.baseHeaders,
|
|
126
127
|
hostname: this.settings.hostname,
|
|
127
128
|
path: `/v2/products/${slug}/results/${inferenceId}`,
|
|
128
|
-
|
|
129
|
+
timeoutSecs: this.settings.timeoutSecs,
|
|
129
130
|
};
|
|
130
131
|
return await sendRequestAndReadResponse(this.settings.dispatcher, options);
|
|
131
132
|
};
|
package/src/v2/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export * as parsing from "./parsing/index.js";
|
|
|
3
3
|
export * as product from "./product/index.js";
|
|
4
4
|
export { Client } from "./client.js";
|
|
5
5
|
export { JobResponse, ErrorResponse, LocalResponse, } from "./parsing/index.js";
|
|
6
|
-
export type {
|
|
6
|
+
export type { BaseParameters, TimerOptions } from "./client/index.js";
|
|
7
|
+
export { PollingOptions } from "./client/index.js";
|
package/src/v2/index.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { StringDict } from "../../../parsing/index.js";
|
|
1
2
|
import { InferenceModel } from "./inferenceModel.js";
|
|
2
3
|
import { InferenceFile } from "./inferenceFile.js";
|
|
3
|
-
import {
|
|
4
|
+
import { InferenceJob } from "./inferenceJob.js";
|
|
4
5
|
export declare abstract class BaseInference {
|
|
5
6
|
/**
|
|
6
7
|
* Model info for the inference.
|
|
7
8
|
*/
|
|
8
9
|
model: InferenceModel;
|
|
10
|
+
/**
|
|
11
|
+
* Job the inference belongs to.
|
|
12
|
+
*/
|
|
13
|
+
job: InferenceJob;
|
|
9
14
|
/**
|
|
10
15
|
* File info for the inference.
|
|
11
16
|
*/
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { InferenceModel } from "./inferenceModel.js";
|
|
2
2
|
import { InferenceFile } from "./inferenceFile.js";
|
|
3
|
+
import { InferenceJob } from "./inferenceJob.js";
|
|
3
4
|
export class BaseInference {
|
|
4
5
|
constructor(serverResponse) {
|
|
5
6
|
this.id = serverResponse["id"];
|
|
7
|
+
this.job = new InferenceJob(serverResponse["job"]);
|
|
6
8
|
this.model = new InferenceModel(serverResponse["model"]);
|
|
7
9
|
this.file = new InferenceFile(serverResponse["file"]);
|
|
8
10
|
}
|
|
9
11
|
toString() {
|
|
10
12
|
return ("Inference\n" +
|
|
11
13
|
"#########\n" +
|
|
14
|
+
this.job.toString() + "\n" +
|
|
12
15
|
this.model.toString() + "\n" +
|
|
13
16
|
this.file.toString() + "\n");
|
|
14
17
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { BaseParameters } from "../../v2/client/index.js";
|
|
2
2
|
import { ResponseConstructor } from "../../v2/parsing/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Base class for all V2 product definitions.
|
|
5
|
+
*
|
|
6
|
+
* Child classes are passed to the Client when making requests.
|
|
7
|
+
*/
|
|
3
8
|
export declare abstract class BaseProduct {
|
|
4
9
|
static get parametersClass(): new (...args: any[]) => BaseParameters;
|
|
5
10
|
static get responseClass(): ResponseConstructor<any>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ClassificationResponse } from "./classificationResponse.js";
|
|
2
2
|
import { ClassificationParameters } from "./params/index.js";
|
|
3
3
|
import { BaseProduct } from "../../../v2/product/baseProduct.js";
|
|
4
|
+
/**
|
|
5
|
+
* Automatically sort any image or scanned document into categories.
|
|
6
|
+
*/
|
|
4
7
|
export declare class Classification extends BaseProduct {
|
|
5
8
|
static get parametersClass(): typeof ClassificationParameters;
|
|
6
9
|
static get responseClass(): typeof ClassificationResponse;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ClassificationResponse } from "./classificationResponse.js";
|
|
2
2
|
import { ClassificationParameters } from "./params/index.js";
|
|
3
3
|
import { BaseProduct } from "../../../v2/product/baseProduct.js";
|
|
4
|
+
/**
|
|
5
|
+
* Automatically sort any image or scanned document into categories.
|
|
6
|
+
*/
|
|
4
7
|
export class Classification extends BaseProduct {
|
|
5
8
|
static get parametersClass() {
|
|
6
9
|
return ClassificationParameters;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { CropResponse } from "./cropResponse.js";
|
|
2
2
|
import { CropParameters } from "./params/index.js";
|
|
3
3
|
import { BaseProduct } from "../../../v2/product/baseProduct.js";
|
|
4
|
+
/**
|
|
5
|
+
* Identify the borders of documents on each page, matching each one to a category.
|
|
6
|
+
*/
|
|
4
7
|
export declare class Crop extends BaseProduct {
|
|
5
8
|
static get parametersClass(): typeof CropParameters;
|
|
6
9
|
static get responseClass(): typeof CropResponse;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { CropResponse } from "./cropResponse.js";
|
|
2
2
|
import { CropParameters } from "./params/index.js";
|
|
3
3
|
import { BaseProduct } from "../../../v2/product/baseProduct.js";
|
|
4
|
+
/**
|
|
5
|
+
* Identify the borders of documents on each page, matching each one to a category.
|
|
6
|
+
*/
|
|
4
7
|
export class Crop extends BaseProduct {
|
|
5
8
|
static get parametersClass() {
|
|
6
9
|
return CropParameters;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ExtractionResponse } from "./extractionResponse.js";
|
|
2
2
|
import { ExtractionParameters } from "./params/index.js";
|
|
3
3
|
import { BaseProduct } from "../../../v2/product/baseProduct.js";
|
|
4
|
+
/**
|
|
5
|
+
* Automatically extract structured data from any image or scanned document.
|
|
6
|
+
*/
|
|
4
7
|
export declare class Extraction extends BaseProduct {
|
|
5
8
|
static get parametersClass(): typeof ExtractionParameters;
|
|
6
9
|
static get responseClass(): typeof ExtractionResponse;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ExtractionResponse } from "./extractionResponse.js";
|
|
2
2
|
import { ExtractionParameters } from "./params/index.js";
|
|
3
3
|
import { BaseProduct } from "../../../v2/product/baseProduct.js";
|
|
4
|
+
/**
|
|
5
|
+
* Automatically extract structured data from any image or scanned document.
|
|
6
|
+
*/
|
|
4
7
|
export class Extraction extends BaseProduct {
|
|
5
8
|
static get parametersClass() {
|
|
6
9
|
return ExtractionParameters;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { OcrResponse } from "./ocrResponse.js";
|
|
2
2
|
import { OcrParameters } from "./params/index.js";
|
|
3
3
|
import { BaseProduct } from "../../../v2/product/baseProduct.js";
|
|
4
|
+
/**
|
|
5
|
+
* Extract raw text (OCR) from any image or scanned document.
|
|
6
|
+
*/
|
|
4
7
|
export declare class Ocr extends BaseProduct {
|
|
5
8
|
static get parametersClass(): typeof OcrParameters;
|
|
6
9
|
static get responseClass(): typeof OcrResponse;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { OcrResponse } from "./ocrResponse.js";
|
|
2
2
|
import { OcrParameters } from "./params/index.js";
|
|
3
3
|
import { BaseProduct } from "../../../v2/product/baseProduct.js";
|
|
4
|
+
/**
|
|
5
|
+
* Extract raw text (OCR) from any image or scanned document.
|
|
6
|
+
*/
|
|
4
7
|
export class Ocr extends BaseProduct {
|
|
5
8
|
static get parametersClass() {
|
|
6
9
|
return OcrParameters;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { SplitResponse } from "./splitResponse.js";
|
|
2
2
|
import { SplitParameters } from "./params/index.js";
|
|
3
3
|
import { BaseProduct } from "../../../v2/product/baseProduct.js";
|
|
4
|
+
/**
|
|
5
|
+
* Break a multipage source file into separate documents, associating a class for each one.
|
|
6
|
+
*/
|
|
4
7
|
export declare class Split extends BaseProduct {
|
|
5
8
|
static get parametersClass(): typeof SplitParameters;
|
|
6
9
|
static get responseClass(): typeof SplitResponse;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { SplitResponse } from "./splitResponse.js";
|
|
2
2
|
import { SplitParameters } from "./params/index.js";
|
|
3
3
|
import { BaseProduct } from "../../../v2/product/baseProduct.js";
|
|
4
|
+
/**
|
|
5
|
+
* Break a multipage source file into separate documents, associating a class for each one.
|
|
6
|
+
*/
|
|
4
7
|
export class Split extends BaseProduct {
|
|
5
8
|
static get parametersClass() {
|
|
6
9
|
return SplitParameters;
|