mindee 4.28.0 → 4.29.0-rc2
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 +15 -0
- package/README.md +22 -167
- package/package.json +7 -7
- package/src/cli.js +17 -7
- package/src/cliProducts.js +17 -7
- package/src/client.d.ts +3 -2
- package/src/client.js +9 -9
- package/src/clientV2.d.ts +190 -0
- package/src/clientV2.js +216 -0
- package/src/errors/mindeeError.d.ts +8 -0
- package/src/errors/mindeeError.js +17 -1
- package/src/http/apiSettings.d.ts +2 -8
- package/src/http/apiSettings.js +3 -41
- package/src/http/apiSettingsV2.d.ts +10 -0
- package/src/http/apiSettingsV2.js +46 -0
- package/src/http/baseEndpoint.d.ts +2 -2
- package/src/http/baseEndpoint.js +3 -3
- package/src/http/baseSettings.d.ts +11 -0
- package/src/http/baseSettings.js +59 -0
- package/src/http/endpoint.js +6 -6
- package/src/http/mindeeApiV2.d.ts +34 -0
- package/src/http/mindeeApiV2.js +120 -0
- package/src/http/workflowEndpoint.js +2 -2
- package/src/imageOperations/common/imageExtractor.d.ts +1 -1
- package/src/imageOperations/imageCompressor.d.ts +1 -1
- package/src/index.d.ts +2 -1
- package/src/index.js +20 -8
- package/src/input/localResponse.d.ts +13 -0
- package/src/input/localResponse.js +36 -7
- package/src/input/sources/localInputSource.d.ts +6 -0
- package/src/input/sources/localInputSource.js +26 -8
- package/src/internal.js +17 -7
- package/src/parsing/common/dateParser.d.ts +1 -0
- package/src/parsing/common/dateParser.js +12 -0
- package/src/parsing/common/execution.d.ts +0 -1
- package/src/parsing/common/execution.js +5 -9
- package/src/parsing/common/index.d.ts +1 -0
- package/src/parsing/common/index.js +20 -8
- package/src/parsing/index.d.ts +1 -0
- package/src/parsing/index.js +19 -8
- package/src/parsing/v2/commonResponse.d.ts +16 -0
- package/src/parsing/v2/commonResponse.js +19 -0
- package/src/parsing/v2/errorResponse.d.ts +15 -0
- package/src/parsing/v2/errorResponse.js +13 -0
- package/src/parsing/v2/field/baseField.d.ts +9 -0
- package/src/parsing/v2/field/baseField.js +18 -0
- package/src/parsing/v2/field/fieldConfidence.d.ts +9 -0
- package/src/parsing/v2/field/fieldConfidence.js +13 -0
- package/src/parsing/v2/field/fieldFactory.d.ts +8 -0
- package/src/parsing/v2/field/fieldFactory.js +22 -0
- package/src/parsing/v2/field/fieldLocation.d.ts +13 -0
- package/src/parsing/v2/field/fieldLocation.js +18 -0
- package/src/parsing/v2/field/index.d.ts +6 -0
- package/src/parsing/v2/field/index.js +15 -0
- package/src/parsing/v2/field/inferenceFields.d.ts +9 -0
- package/src/parsing/v2/field/inferenceFields.js +38 -0
- package/src/parsing/v2/field/listField.d.ts +12 -0
- package/src/parsing/v2/field/listField.js +36 -0
- package/src/parsing/v2/field/objectField.d.ts +9 -0
- package/src/parsing/v2/field/objectField.js +18 -0
- package/src/parsing/v2/field/simpleField.d.ts +7 -0
- package/src/parsing/v2/field/simpleField.js +17 -0
- package/src/parsing/v2/index.d.ts +12 -0
- package/src/parsing/v2/index.js +27 -0
- package/src/parsing/v2/inference.d.ts +24 -0
- package/src/parsing/v2/inference.js +26 -0
- package/src/parsing/v2/inferenceResponse.d.ts +10 -0
- package/src/parsing/v2/inferenceResponse.js +12 -0
- package/src/parsing/v2/inferenceResult.d.ts +15 -0
- package/src/parsing/v2/inferenceResult.js +25 -0
- package/src/parsing/v2/inferenceResultFile.d.ts +13 -0
- package/src/parsing/v2/inferenceResultFile.js +16 -0
- package/src/parsing/v2/inferenceResultModel.d.ts +8 -0
- package/src/parsing/v2/inferenceResultModel.js +9 -0
- package/src/parsing/v2/inferenceResultOptions.d.ts +9 -0
- package/src/parsing/v2/inferenceResultOptions.js +10 -0
- package/src/parsing/v2/job.d.ts +49 -0
- package/src/parsing/v2/job.js +29 -0
- package/src/parsing/v2/jobResponse.d.ts +10 -0
- package/src/parsing/v2/jobResponse.js +12 -0
- package/src/parsing/v2/jobResponseWebhook.d.ts +24 -0
- package/src/parsing/v2/jobResponseWebhook.js +19 -0
- package/src/parsing/v2/rawText.d.ts +15 -0
- package/src/parsing/v2/rawText.js +13 -0
- package/src/pdf/pdfCompressor.js +17 -7
- package/src/product/fr/internal.js +17 -7
- package/src/product/ind/internal.js +17 -7
- package/src/product/index.js +17 -7
- package/src/product/internal.js +17 -7
- package/src/product/us/internal.js +17 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.29.0-rc2 - 2025-07-25
|
|
4
|
+
### Changes
|
|
5
|
+
* :recycle: harmonize with other client libraries
|
|
6
|
+
|
|
7
|
+
## v4.29.0-rc1 - 2025-07-21
|
|
8
|
+
### Changes
|
|
9
|
+
* :sparkles: add support for V2 client
|
|
10
|
+
* :recycle: tweak CI & testing
|
|
11
|
+
* :recycle: deprecate `cutPdf()` in favor of `applyPageOperations()` in `LocalInputSource`
|
|
12
|
+
* :recycle: refactor some internals to account for new changes
|
|
13
|
+
|
|
14
|
+
### Fixes
|
|
15
|
+
* :bug: fix bug where polling parameters could ignore validation checks on V1
|
|
16
|
+
|
|
17
|
+
|
|
3
18
|
## v4.28.0 - 2025-06-03
|
|
4
19
|
### Changes
|
|
5
20
|
* :sparkles: add support for address fields
|
package/README.md
CHANGED
|
@@ -3,184 +3,39 @@
|
|
|
3
3
|
# Mindee API Helper Library for Node.js
|
|
4
4
|
Quickly and easily connect to Mindee's API services using Node.js.
|
|
5
5
|
|
|
6
|
-
##
|
|
7
|
-
|
|
6
|
+
## Mindee API Versions
|
|
7
|
+
This client library has support for both Mindee platform versions.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Latest - V2
|
|
10
|
+
This is the new platform located here:
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
```shell
|
|
13
|
-
npm install mindee
|
|
14
|
-
```
|
|
12
|
+
https://app.mindee.com
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
It uses **API version 2**.
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
Consult the
|
|
17
|
+
**[Latest Documentation](https://docs.mindee.com/integrations/client-libraries-sdk)**
|
|
19
18
|
|
|
20
|
-
#### Global Documents
|
|
21
|
-
```js
|
|
22
|
-
const mindee = require("mindee");
|
|
23
|
-
// for TS or modules:
|
|
24
|
-
// import * as mindee from "mindee";
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
### Legacy - V1
|
|
21
|
+
This is the legacy platform located here:
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext");
|
|
23
|
+
https://platform.mindee.com/
|
|
31
24
|
|
|
32
|
-
|
|
33
|
-
const apiResponse = mindeeClient.parse(mindee.product.InvoiceV4, inputSource);
|
|
34
|
-
```
|
|
25
|
+
It uses **API version 1**.
|
|
35
26
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
A base64 encoded string:
|
|
39
|
-
```js
|
|
40
|
-
const inputSource = mindeeClient.docFromBase64(myInputString, "my-file-name.ext")
|
|
41
|
-
```
|
|
27
|
+
Consult the
|
|
28
|
+
**[Legacy Documentation](https://developers.mindee.com/docs/nodejs-getting-started)**
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
const inputSource = mindeeClient.docFromBytes(myInputBytes, "my-file-name.ext")
|
|
46
|
-
```
|
|
30
|
+
## Additional Information
|
|
47
31
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const inputSource = mindeeClient.docFromBuffer(myBuffer, "my-file-name.ext")
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
A URL (`https` only):
|
|
59
|
-
```js
|
|
60
|
-
const inputSource = mindeeClient.docFromUrl("https://my-url");
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
You can also load the document locally before sending it:
|
|
64
|
-
```js
|
|
65
|
-
const inputSource = mindeeClient.docFromUrl("https://my-url");
|
|
66
|
-
await inputSource.init();
|
|
67
|
-
const localInputSource = inputSource.asLocalInputSource();
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
**Note:** Files hidden behind redirections are rejected by the server; this solution helps to circumvent that issue.
|
|
71
|
-
|
|
72
|
-
#### Region-Specific Documents
|
|
73
|
-
|
|
74
|
-
Region-Specific Documents use the following syntax:
|
|
75
|
-
|
|
76
|
-
```js
|
|
77
|
-
const mindee = require("mindee");
|
|
78
|
-
// for TS or modules:
|
|
79
|
-
// import * as mindee from "mindee";
|
|
80
|
-
|
|
81
|
-
const mindeeClient = new mindee.Client({ apiKey: "my-api-key" });
|
|
82
|
-
|
|
83
|
-
const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext");
|
|
84
|
-
|
|
85
|
-
// The IdCardV1 product belongs to mindee.product.fr, not mindee.product itself
|
|
86
|
-
const apiResponse = mindeeClient.parse(mindee.product.fr.IdCardV1, inputSource);
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
#### Custom Documents (docTI & Custom APIs)
|
|
90
|
-
|
|
91
|
-
Custom documents will require you to provide their endpoint manually.
|
|
92
|
-
|
|
93
|
-
```js
|
|
94
|
-
const mindee = require("mindee");
|
|
95
|
-
// for TS or modules:
|
|
96
|
-
// import * as mindee from "mindee";
|
|
97
|
-
|
|
98
|
-
// Init a new client
|
|
99
|
-
const mindeeClient = new mindee.Client({
|
|
100
|
-
apiKey: "my-api-key"
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// Load a file from disk
|
|
104
|
-
const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext");
|
|
105
|
-
|
|
106
|
-
// Create a custom endpoint for your product
|
|
107
|
-
const customEndpoint = mindeeClient.createEndpoint(
|
|
108
|
-
"my-endpoint",
|
|
109
|
-
"my-account",
|
|
110
|
-
"my-version" // will default to 1 if not provided
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
// Parse it
|
|
114
|
-
const apiResponse = await mindeeClient
|
|
115
|
-
.enqueueAndParse(
|
|
116
|
-
mindee.product.GeneratedV1,
|
|
117
|
-
inputSource,
|
|
118
|
-
{
|
|
119
|
-
endpoint: customEndpoint
|
|
120
|
-
}
|
|
121
|
-
);
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Handling the Return
|
|
125
|
-
```js
|
|
126
|
-
// Handle the response Promise
|
|
127
|
-
apiResponse.then((resp) => {
|
|
128
|
-
// print a string summary
|
|
129
|
-
console.log(resp.document.toString());
|
|
130
|
-
|
|
131
|
-
// individual pages (array)
|
|
132
|
-
console.log(res.document.inference.pages);
|
|
133
|
-
});
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
### Additional Options
|
|
137
|
-
Options to pass when sending a file to be parsed.
|
|
138
|
-
|
|
139
|
-
#### Page Options
|
|
140
|
-
Allows only sending certain pages in a PDF.
|
|
141
|
-
|
|
142
|
-
In this example we only send the first, penultimate, and last pages:
|
|
143
|
-
|
|
144
|
-
```js
|
|
145
|
-
const apiResponse = mindeeClient.parse(
|
|
146
|
-
mindee.product.InvoiceV4,
|
|
147
|
-
inputSource,
|
|
148
|
-
{
|
|
149
|
-
pageOptions: {
|
|
150
|
-
pageIndexes: [0, -2, -1],
|
|
151
|
-
operation: mindee.PageOptionsOperation.KeepOnly,
|
|
152
|
-
onMinPages: 2
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
## Further Reading
|
|
158
|
-
Complete details on the working of the library are available in the following guides:
|
|
159
|
-
|
|
160
|
-
* [Node.js Getting Started](https://developers.mindee.com/docs/nodejs-getting-started)
|
|
161
|
-
* [Node.js Generated API](https://developers.mindee.com/docs/nodejs-generated-ocr)
|
|
162
|
-
* [Node.js Custom OCR (Deprecated)](https://developers.mindee.com/docs/nodejs-api-builder)
|
|
163
|
-
* [Node.js Invoice OCR](https://developers.mindee.com/docs/nodejs-invoice-ocr)
|
|
164
|
-
* [Node.js International Id OCR](https://developers.mindee.com/docs/nodejs-international-id-ocr)
|
|
165
|
-
* [Node.js Receipt OCR](https://developers.mindee.com/docs/nodejs-receipt-ocr)
|
|
166
|
-
* [Node.js Resume OCR](https://developers.mindee.com/docs/nodejs-resume-ocr)
|
|
167
|
-
* [Node.js Financial Document OCR](https://developers.mindee.com/docs/nodejs-financial-document-ocr)
|
|
168
|
-
* [Node.js Passport OCR](https://developers.mindee.com/docs/nodejs-passport-ocr)
|
|
169
|
-
* [Node.js FR Bank Account Detail OCR](https://developers.mindee.com/docs/nodejs-fr-bank-account-details-ocr)
|
|
170
|
-
* [Node.js FR Health Card OCR](https://developers.mindee.com/docs/nodejs-fr-health-card-ocr)
|
|
171
|
-
* [Node.js FR ID Card OCR](https://developers.mindee.com/docs/nodejs-fr-carte-nationale-didentite-ocr)
|
|
172
|
-
* [Node.js US Bank Check OCR](https://developers.mindee.com/docs/nodejs-us-bank-check-ocr)
|
|
173
|
-
* [Node.js Barcode Reader API](https://developers.mindee.com/docs/nodejs-barcode-reader-ocr)
|
|
174
|
-
* [Node.js Cropper API](https://developers.mindee.com/docs/nodejs-cropper-ocr)
|
|
175
|
-
* [Node.js Invoice Splitter API](https://developers.mindee.com/docs/nodejs-invoice-splitter-ocr)
|
|
176
|
-
* [Node.js Multi Receipts Detector API](https://developers.mindee.com/docs/nodejs-multi-receipts-detector-ocr)
|
|
177
|
-
|
|
178
|
-
You can also take a look at the **[Reference Documentation](https://mindee.github.io/mindee-api-nodejs/)**.
|
|
179
|
-
|
|
180
|
-
## License
|
|
32
|
+
**[Source Code](https://github.com/mindee/mindee-api-nodejs)**
|
|
33
|
+
|
|
34
|
+
**[Reference Documentation](https://mindee.github.io/mindee-api-nodejs/)**
|
|
35
|
+
|
|
36
|
+
**[Feedback](https://feedback.mindee.com/)**
|
|
37
|
+
|
|
38
|
+
### License
|
|
181
39
|
Copyright © Mindee
|
|
182
40
|
|
|
183
41
|
Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
184
|
-
|
|
185
|
-
## Questions?
|
|
186
|
-
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.29.0-rc2",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "bin/mindee.js",
|
|
@@ -9,8 +9,8 @@
|
|
|
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
|
|
13
|
-
"test-integration": "mocha
|
|
12
|
+
"test": "mocha \"tests/**/*.spec.ts\" --config .mocharc.json",
|
|
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",
|
|
16
16
|
"docs": "typedoc --out docs/_build ./src/index.ts",
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
"@types/mocha": "^10.0.10",
|
|
45
45
|
"@types/node": "^18.15.11",
|
|
46
46
|
"@types/tmp": "^0.2.6",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
48
|
-
"@typescript-eslint/parser": "^8.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.36.0",
|
|
48
|
+
"@typescript-eslint/parser": "^8.36.0",
|
|
49
49
|
"chai": "^4.3.10",
|
|
50
50
|
"eslint": "^9.15.0",
|
|
51
51
|
"eslint-plugin-jsdoc": "^50.5.0",
|
|
52
|
-
"mocha": "^11.1
|
|
52
|
+
"mocha": "^11.7.1",
|
|
53
53
|
"nock": "^13.5.6",
|
|
54
54
|
"ts-node": "^10.9.2",
|
|
55
|
-
"typedoc": "~0.
|
|
55
|
+
"typedoc": "~0.28.7",
|
|
56
56
|
"typescript": "^5.6.3"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
package/src/cli.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.cli = cli;
|
|
27
37
|
const commander_1 = require("commander");
|
package/src/cliProducts.js
CHANGED
|
@@ -20,13 +20,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
20
20
|
}) : function(o, v) {
|
|
21
21
|
o["default"] = v;
|
|
22
22
|
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || function (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
30
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
41
|
exports.CLI_COMMAND_CONFIG = exports.COMMAND_GENERATED = exports.COMMAND_CUSTOM = void 0;
|
|
32
42
|
const product = __importStar(require("./product"));
|
package/src/client.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Base64Input, BufferInput, BytesInput, InputSource, LocalResponse, PageOptions, PathInput, StreamInput, UrlInput } from "./input";
|
|
1
|
+
import { InputSource, LocalResponse, PageOptions } from "./input";
|
|
3
2
|
import { Endpoint } from "./http";
|
|
4
3
|
import { AsyncPredictResponse, ExecutionPriority, FeedbackResponse, Inference, PredictResponse, StringDict } from "./parsing/common";
|
|
5
4
|
import { GeneratedV1 } from "./product";
|
|
6
5
|
import { WorkflowResponse } from "./parsing/common/workflowResponse";
|
|
6
|
+
import { Base64Input, BufferInput, BytesInput, PathInput, StreamInput, UrlInput } from "./input";
|
|
7
|
+
import { Readable } from "stream";
|
|
7
8
|
/**
|
|
8
9
|
* Common options for workflows & predictions.
|
|
9
10
|
*/
|
package/src/client.js
CHANGED
|
@@ -7,7 +7,6 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
7
7
|
var _Client_instances, _Client_setAsyncParams, _Client_buildProductEndpoint, _Client_buildApiSettings, _Client_initializeOTSEndpoint, _Client_cleanAccountName, _Client_getOtsEndpoint;
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.Client = void 0;
|
|
10
|
-
const input_1 = require("./input");
|
|
11
10
|
const http_1 = require("./http");
|
|
12
11
|
const common_1 = require("./parsing/common");
|
|
13
12
|
const handler_1 = require("./errors/handler");
|
|
@@ -18,6 +17,7 @@ const promises_1 = require("node:timers/promises");
|
|
|
18
17
|
const errors_1 = require("./errors");
|
|
19
18
|
const workflowResponse_1 = require("./parsing/common/workflowResponse");
|
|
20
19
|
const workflowEndpoint_1 = require("./http/workflowEndpoint");
|
|
20
|
+
const input_1 = require("./input");
|
|
21
21
|
/**
|
|
22
22
|
* Mindee Client class that centralizes most basic operations.
|
|
23
23
|
*
|
|
@@ -82,7 +82,7 @@ class Client {
|
|
|
82
82
|
async enqueue(productClass, inputSource, params = {}) {
|
|
83
83
|
const endpoint = params?.endpoint ?? __classPrivateFieldGet(this, _Client_instances, "m", _Client_initializeOTSEndpoint).call(this, productClass);
|
|
84
84
|
if (inputSource === undefined) {
|
|
85
|
-
throw new Error("The '
|
|
85
|
+
throw new Error("The 'enqueue' function requires an input document.");
|
|
86
86
|
}
|
|
87
87
|
const rawResponse = await endpoint.predictAsync({
|
|
88
88
|
inputDoc: inputSource,
|
|
@@ -141,7 +141,7 @@ class Client {
|
|
|
141
141
|
async executeWorkflow(inputSource, workflowId, params = {}) {
|
|
142
142
|
const workflowEndpoint = new workflowEndpoint_1.WorkflowEndpoint(__classPrivateFieldGet(this, _Client_instances, "m", _Client_buildApiSettings).call(this), workflowId);
|
|
143
143
|
if (inputSource === undefined) {
|
|
144
|
-
throw new Error("The '
|
|
144
|
+
throw new Error("The 'executeWorkflow' function requires an input document.");
|
|
145
145
|
}
|
|
146
146
|
const rawResponse = await workflowEndpoint.executeWorkflow({
|
|
147
147
|
inputDoc: inputSource,
|
|
@@ -210,25 +210,25 @@ class Client {
|
|
|
210
210
|
recurringTimerOptions: undefined,
|
|
211
211
|
}) {
|
|
212
212
|
const validatedAsyncParams = __classPrivateFieldGet(this, _Client_instances, "m", _Client_setAsyncParams).call(this, asyncParams);
|
|
213
|
-
const enqueueResponse = await this.enqueue(productClass, inputSource,
|
|
213
|
+
const enqueueResponse = await this.enqueue(productClass, inputSource, validatedAsyncParams);
|
|
214
214
|
if (enqueueResponse.job.id === undefined || enqueueResponse.job.id.length === 0) {
|
|
215
215
|
throw Error("Enqueueing of the document failed.");
|
|
216
216
|
}
|
|
217
217
|
const queueId = enqueueResponse.job.id;
|
|
218
218
|
logger_1.logger.debug(`Successfully enqueued document with job id: ${queueId}.`);
|
|
219
|
-
await (0, promises_1.setTimeout)(validatedAsyncParams.initialDelaySec * 1000, undefined,
|
|
219
|
+
await (0, promises_1.setTimeout)(validatedAsyncParams.initialDelaySec * 1000, undefined, validatedAsyncParams.initialTimerOptions);
|
|
220
220
|
let retryCounter = 1;
|
|
221
221
|
let pollResults;
|
|
222
|
-
pollResults = await this.parseQueued(productClass, queueId,
|
|
222
|
+
pollResults = await this.parseQueued(productClass, queueId, validatedAsyncParams);
|
|
223
223
|
while (retryCounter < validatedAsyncParams.maxRetries) {
|
|
224
224
|
logger_1.logger.debug(`Polling server for parsing result with queueId: ${queueId}.
|
|
225
|
-
Attempt n°${retryCounter}/${
|
|
225
|
+
Attempt n°${retryCounter}/${validatedAsyncParams.maxRetries}.
|
|
226
226
|
Job status: ${pollResults.job.status}.`);
|
|
227
227
|
if (pollResults.job.status === "completed") {
|
|
228
228
|
break;
|
|
229
229
|
}
|
|
230
|
-
await (0, promises_1.setTimeout)(validatedAsyncParams.delaySec * 1000, undefined,
|
|
231
|
-
pollResults = await this.parseQueued(productClass, queueId,
|
|
230
|
+
await (0, promises_1.setTimeout)(validatedAsyncParams.delaySec * 1000, undefined, validatedAsyncParams.recurringTimerOptions);
|
|
231
|
+
pollResults = await this.parseQueued(productClass, queueId, validatedAsyncParams);
|
|
232
232
|
retryCounter++;
|
|
233
233
|
}
|
|
234
234
|
if (pollResults.job.status !== "completed") {
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { Base64Input, BufferInput, BytesInput, LocalInputSource, PathInput, StreamInput, UrlInput } from "./input";
|
|
2
|
+
import { InferenceResponse, JobResponse } from "./parsing/v2";
|
|
3
|
+
import { MindeeApiV2 } from "./http/mindeeApiV2";
|
|
4
|
+
import { Readable } from "stream";
|
|
5
|
+
/**
|
|
6
|
+
* Parameters for the internal polling loop in {@link ClientV2.enqueueAndGetInference | enqueueAndGetInference()} .
|
|
7
|
+
*
|
|
8
|
+
* Default behavior:
|
|
9
|
+
* - `initialDelaySec` = 2s
|
|
10
|
+
* - `delaySec` = 1.5s
|
|
11
|
+
* - `maxRetries` = 80
|
|
12
|
+
*
|
|
13
|
+
* Validation rules:
|
|
14
|
+
* - `initialDelaySec` >= 1
|
|
15
|
+
* - `delaySec` >= 1
|
|
16
|
+
* - `maxRetries` >= 2
|
|
17
|
+
*
|
|
18
|
+
* The `initialTimerOptions` and `recurringTimerOptions` objects let you pass an
|
|
19
|
+
* `AbortSignal` or make the timer `unref`-ed to the `setTimeout()`.
|
|
20
|
+
*
|
|
21
|
+
* @property initialDelaySec Number of seconds to wait **before the first poll**.
|
|
22
|
+
* @property delaySec Interval in seconds between two consecutive polls.
|
|
23
|
+
* @property maxRetries Maximum number of polling attempts (including the first one).
|
|
24
|
+
* @property initialTimerOptions Options passed to the initial `setTimeout()`.
|
|
25
|
+
* @property recurringTimerOptions Options passed to every recurring `setTimeout()`.
|
|
26
|
+
*
|
|
27
|
+
* @category ClientV2
|
|
28
|
+
* @example
|
|
29
|
+
* const params = {
|
|
30
|
+
* initialDelaySec: 4,
|
|
31
|
+
* delaySec: 2,
|
|
32
|
+
* maxRetries: 50
|
|
33
|
+
* };
|
|
34
|
+
*
|
|
35
|
+
* const inference = await client.enqueueAndGetInference(inputDoc, params);
|
|
36
|
+
*/
|
|
37
|
+
export interface PollingOptions {
|
|
38
|
+
initialDelaySec?: number;
|
|
39
|
+
delaySec?: number;
|
|
40
|
+
maxRetries?: number;
|
|
41
|
+
initialTimerOptions?: {
|
|
42
|
+
ref?: boolean;
|
|
43
|
+
signal?: AbortSignal;
|
|
44
|
+
};
|
|
45
|
+
recurringTimerOptions?: {
|
|
46
|
+
ref?: boolean;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Parameters accepted by the asynchronous **inference** v2 endpoint.
|
|
52
|
+
*
|
|
53
|
+
* All fields are optional except `modelId`.
|
|
54
|
+
*
|
|
55
|
+
* @property modelId Identifier of the model that must process the document. **Required**.
|
|
56
|
+
* @property rag When `true`, activates Retrieval-Augmented Generation (RAG).
|
|
57
|
+
* @property alias Custom alias assigned to the uploaded document.
|
|
58
|
+
* @property webhookIds List of webhook UUIDs that will receive the final API response.
|
|
59
|
+
* @property pollingOptions Client-side polling configuration (see {@link PollingOptions}).
|
|
60
|
+
* @property closeFile By default the file is closed once the upload is finished, set to `false` to keep it open.
|
|
61
|
+
* @category ClientV2
|
|
62
|
+
* @example
|
|
63
|
+
* const params = {
|
|
64
|
+
* modelId: "YOUR_MODEL_ID",
|
|
65
|
+
* rag: true,
|
|
66
|
+
* alias: "YOUR_ALIAS",
|
|
67
|
+
* webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"],
|
|
68
|
+
* pollingOptions: {
|
|
69
|
+
* initialDelaySec: 2,
|
|
70
|
+
* delaySec: 1.5,
|
|
71
|
+
* }
|
|
72
|
+
* };
|
|
73
|
+
*/
|
|
74
|
+
export interface InferenceParameters {
|
|
75
|
+
modelId: string;
|
|
76
|
+
rag?: boolean;
|
|
77
|
+
alias?: string;
|
|
78
|
+
webhookIds?: string[];
|
|
79
|
+
pollingOptions?: PollingOptions;
|
|
80
|
+
closeFile?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Options for the V2 Mindee Client.
|
|
84
|
+
*
|
|
85
|
+
* @property apiKey Your API key for all endpoints.
|
|
86
|
+
* @property throwOnError Raise an `Error` on errors.
|
|
87
|
+
* @property debug Log debug messages.
|
|
88
|
+
*
|
|
89
|
+
* @category ClientV2
|
|
90
|
+
* @example
|
|
91
|
+
* const client = new MindeeClientV2({
|
|
92
|
+
* apiKey: "YOUR_API_KEY",
|
|
93
|
+
* throwOnError: true,
|
|
94
|
+
* debug: false
|
|
95
|
+
* });
|
|
96
|
+
*/
|
|
97
|
+
export interface ClientOptions {
|
|
98
|
+
apiKey?: string;
|
|
99
|
+
throwOnError?: boolean;
|
|
100
|
+
debug?: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Mindee Client V2 class that centralizes most basic operations.
|
|
104
|
+
*
|
|
105
|
+
* @category ClientV2
|
|
106
|
+
*/
|
|
107
|
+
export declare class ClientV2 {
|
|
108
|
+
#private;
|
|
109
|
+
/** Key of the API. */
|
|
110
|
+
protected mindeeApi: MindeeApiV2;
|
|
111
|
+
/**
|
|
112
|
+
* @param {ClientOptions} options options for the initialization of a client.
|
|
113
|
+
*/
|
|
114
|
+
constructor({ apiKey, throwOnError, debug }?: ClientOptions);
|
|
115
|
+
/**
|
|
116
|
+
* Send the document to an asynchronous endpoint and return its ID in the queue.
|
|
117
|
+
* @param inputSource file to parse.
|
|
118
|
+
* @param params parameters relating to prediction options.
|
|
119
|
+
* @category Asynchronous
|
|
120
|
+
* @returns a `Promise` containing the job (queue) corresponding to a document.
|
|
121
|
+
*/
|
|
122
|
+
enqueueInference(inputSource: LocalInputSource, params: InferenceParameters): Promise<JobResponse>;
|
|
123
|
+
/**
|
|
124
|
+
* Retrieves an inference.
|
|
125
|
+
*
|
|
126
|
+
* @param inferenceId id of the queue to poll.
|
|
127
|
+
* @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`.
|
|
128
|
+
* @category Asynchronous
|
|
129
|
+
* @returns a `Promise` containing a `Job`, which also contains a `Document` if the
|
|
130
|
+
* parsing is complete.
|
|
131
|
+
*/
|
|
132
|
+
getInference(inferenceId: string): Promise<InferenceResponse>;
|
|
133
|
+
/**
|
|
134
|
+
* Get the status of an inference that was previously enqueued.
|
|
135
|
+
* Can be used for polling.
|
|
136
|
+
*
|
|
137
|
+
* @param jobId id of the queue to poll.
|
|
138
|
+
* @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`.
|
|
139
|
+
* @category Asynchronous
|
|
140
|
+
* @returns a `Promise` containing a `Job`, which also contains a `Document` if the
|
|
141
|
+
* parsing is complete.
|
|
142
|
+
*/
|
|
143
|
+
getJob(jobId: string): Promise<JobResponse>;
|
|
144
|
+
/**
|
|
145
|
+
* Send a document to an endpoint and poll the server until the result is sent or
|
|
146
|
+
* until the maximum number of tries is reached.
|
|
147
|
+
*
|
|
148
|
+
* @param inputDoc document to parse.
|
|
149
|
+
* @param params parameters relating to prediction options.
|
|
150
|
+
*
|
|
151
|
+
* @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`.
|
|
152
|
+
* @category Synchronous
|
|
153
|
+
* @returns a `Promise` containing parsing results.
|
|
154
|
+
*/
|
|
155
|
+
enqueueAndGetInference(inputDoc: LocalInputSource, params: InferenceParameters): Promise<InferenceResponse>;
|
|
156
|
+
/**
|
|
157
|
+
* Load an input source from a local path.
|
|
158
|
+
* @param inputPath
|
|
159
|
+
*/
|
|
160
|
+
sourceFromPath(inputPath: string): PathInput;
|
|
161
|
+
/**
|
|
162
|
+
* Load an input source from a base64 encoded string.
|
|
163
|
+
* @param inputString input content, as a string.
|
|
164
|
+
* @param filename file name.
|
|
165
|
+
*/
|
|
166
|
+
sourceFromBase64(inputString: string, filename: string): Base64Input;
|
|
167
|
+
/**
|
|
168
|
+
* Load an input source from a `stream.Readable` object.
|
|
169
|
+
* @param inputStream input content, as a readable stream.
|
|
170
|
+
* @param filename file name.
|
|
171
|
+
*/
|
|
172
|
+
sourceFromStream(inputStream: Readable, filename: string): StreamInput;
|
|
173
|
+
/**
|
|
174
|
+
* Load an input source from bytes.
|
|
175
|
+
* @param inputBytes input content, as a Uint8Array or Buffer.
|
|
176
|
+
* @param filename file name.
|
|
177
|
+
*/
|
|
178
|
+
sourceFromBytes(inputBytes: Uint8Array, filename: string): BytesInput;
|
|
179
|
+
/**
|
|
180
|
+
* Load an input source from a Buffer.
|
|
181
|
+
* @param buffer input content, as a buffer.
|
|
182
|
+
* @param filename file name.
|
|
183
|
+
*/
|
|
184
|
+
sourceFromBuffer(buffer: Buffer, filename: string): BufferInput;
|
|
185
|
+
/**
|
|
186
|
+
* Load an input source from a URL.
|
|
187
|
+
* @param url input url. Must be HTTPS.
|
|
188
|
+
*/
|
|
189
|
+
sourceFromUrl(url: string): UrlInput;
|
|
190
|
+
}
|