mindee 4.28.0 → 4.29.0-rc1
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 +11 -0
- package/README.md +0 -21
- package/package.json +7 -7
- package/src/baseClient.d.ts +38 -0
- package/src/baseClient.js +69 -0
- package/src/cli.js +17 -7
- package/src/cliProducts.js +17 -7
- package/src/client.d.ts +3 -37
- package/src/client.js +11 -72
- package/src/clientV2.d.ts +156 -0
- package/src/clientV2.js +155 -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 +1 -0
- 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,16 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.29.0-rc1 - 2025-07-21
|
|
4
|
+
### Changes
|
|
5
|
+
* :sparkles: add support for V2 client
|
|
6
|
+
* :recycle: tweak CI & testing
|
|
7
|
+
* :recycle: deprecate `cutPdf()` in favor of `applyPageOperations()` in `LocalInputSource`
|
|
8
|
+
* :recycle: refactor some internals to account for new changes
|
|
9
|
+
|
|
10
|
+
### Fixes
|
|
11
|
+
* :bug: fix bug where polling parameters could ignore validation checks on V1
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
## v4.28.0 - 2025-06-03
|
|
4
15
|
### Changes
|
|
5
16
|
* :sparkles: add support for address fields
|
package/README.md
CHANGED
|
@@ -154,27 +154,6 @@ const apiResponse = mindeeClient.parse(
|
|
|
154
154
|
});
|
|
155
155
|
```
|
|
156
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
157
|
You can also take a look at the **[Reference Documentation](https://mindee.github.io/mindee-api-nodejs/)**.
|
|
179
158
|
|
|
180
159
|
## License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.29.0-rc1",
|
|
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": {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Base64Input, BufferInput, BytesInput, PathInput, StreamInput, UrlInput } from "./input";
|
|
2
|
+
import { Readable } from "stream";
|
|
3
|
+
export declare abstract class BaseClient {
|
|
4
|
+
/**
|
|
5
|
+
* Load an input document from a local path.
|
|
6
|
+
* @param inputPath
|
|
7
|
+
*/
|
|
8
|
+
docFromPath(inputPath: string): PathInput;
|
|
9
|
+
/**
|
|
10
|
+
* Load an input document from a base64 encoded string.
|
|
11
|
+
* @param inputString input content, as a string.
|
|
12
|
+
* @param filename file name.
|
|
13
|
+
*/
|
|
14
|
+
docFromBase64(inputString: string, filename: string): Base64Input;
|
|
15
|
+
/**
|
|
16
|
+
* Load an input document from a `stream.Readable` object.
|
|
17
|
+
* @param inputStream input content, as a readable stream.
|
|
18
|
+
* @param filename file name.
|
|
19
|
+
*/
|
|
20
|
+
docFromStream(inputStream: Readable, filename: string): StreamInput;
|
|
21
|
+
/**
|
|
22
|
+
* Load an input document from bytes.
|
|
23
|
+
* @param inputBytes input content, as a Uint8Array or Buffer.
|
|
24
|
+
* @param filename file name.
|
|
25
|
+
*/
|
|
26
|
+
docFromBytes(inputBytes: Uint8Array, filename: string): BytesInput;
|
|
27
|
+
/**
|
|
28
|
+
* Load an input document from a URL.
|
|
29
|
+
* @param url input url. Must be HTTPS.
|
|
30
|
+
*/
|
|
31
|
+
docFromUrl(url: string): UrlInput;
|
|
32
|
+
/**
|
|
33
|
+
* Load an input document from a Buffer.
|
|
34
|
+
* @param buffer input content, as a buffer.
|
|
35
|
+
* @param filename file name.
|
|
36
|
+
*/
|
|
37
|
+
docFromBuffer(buffer: Buffer, filename: string): BufferInput;
|
|
38
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseClient = void 0;
|
|
4
|
+
const input_1 = require("./input");
|
|
5
|
+
class BaseClient {
|
|
6
|
+
/**
|
|
7
|
+
* Load an input document from a local path.
|
|
8
|
+
* @param inputPath
|
|
9
|
+
*/
|
|
10
|
+
docFromPath(inputPath) {
|
|
11
|
+
return new input_1.PathInput({
|
|
12
|
+
inputPath: inputPath,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Load an input document from a base64 encoded string.
|
|
17
|
+
* @param inputString input content, as a string.
|
|
18
|
+
* @param filename file name.
|
|
19
|
+
*/
|
|
20
|
+
docFromBase64(inputString, filename) {
|
|
21
|
+
return new input_1.Base64Input({
|
|
22
|
+
inputString: inputString,
|
|
23
|
+
filename: filename,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Load an input document from a `stream.Readable` object.
|
|
28
|
+
* @param inputStream input content, as a readable stream.
|
|
29
|
+
* @param filename file name.
|
|
30
|
+
*/
|
|
31
|
+
docFromStream(inputStream, filename) {
|
|
32
|
+
return new input_1.StreamInput({
|
|
33
|
+
inputStream: inputStream,
|
|
34
|
+
filename: filename,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Load an input document from bytes.
|
|
39
|
+
* @param inputBytes input content, as a Uint8Array or Buffer.
|
|
40
|
+
* @param filename file name.
|
|
41
|
+
*/
|
|
42
|
+
docFromBytes(inputBytes, filename) {
|
|
43
|
+
return new input_1.BytesInput({
|
|
44
|
+
inputBytes: inputBytes,
|
|
45
|
+
filename: filename,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Load an input document from a URL.
|
|
50
|
+
* @param url input url. Must be HTTPS.
|
|
51
|
+
*/
|
|
52
|
+
docFromUrl(url) {
|
|
53
|
+
return new input_1.UrlInput({
|
|
54
|
+
url: url,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Load an input document from a Buffer.
|
|
59
|
+
* @param buffer input content, as a buffer.
|
|
60
|
+
* @param filename file name.
|
|
61
|
+
*/
|
|
62
|
+
docFromBuffer(buffer, filename) {
|
|
63
|
+
return new input_1.BufferInput({
|
|
64
|
+
buffer: buffer,
|
|
65
|
+
filename: filename,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.BaseClient = BaseClient;
|
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,9 @@
|
|
|
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 { BaseClient } from "./baseClient";
|
|
7
7
|
/**
|
|
8
8
|
* Common options for workflows & predictions.
|
|
9
9
|
*/
|
|
@@ -103,7 +103,7 @@ export interface ClientOptions {
|
|
|
103
103
|
*
|
|
104
104
|
* @category Client
|
|
105
105
|
*/
|
|
106
|
-
export declare class Client {
|
|
106
|
+
export declare class Client extends BaseClient {
|
|
107
107
|
#private;
|
|
108
108
|
/** Key of the API. */
|
|
109
109
|
protected apiKey: string;
|
|
@@ -211,39 +211,5 @@ export declare class Client {
|
|
|
211
211
|
* @returns Endpoint a new product endpoint
|
|
212
212
|
*/
|
|
213
213
|
createEndpoint(endpointName: string, accountName: string, endpointVersion?: string): Endpoint;
|
|
214
|
-
/**
|
|
215
|
-
* Load an input document from a local path.
|
|
216
|
-
* @param inputPath
|
|
217
|
-
*/
|
|
218
|
-
docFromPath(inputPath: string): PathInput;
|
|
219
|
-
/**
|
|
220
|
-
* Load an input document from a base64 encoded string.
|
|
221
|
-
* @param inputString input content, as a string.
|
|
222
|
-
* @param filename file name.
|
|
223
|
-
*/
|
|
224
|
-
docFromBase64(inputString: string, filename: string): Base64Input;
|
|
225
|
-
/**
|
|
226
|
-
* Load an input document from a `stream.Readable` object.
|
|
227
|
-
* @param inputStream input content, as a readable stream.
|
|
228
|
-
* @param filename file name.
|
|
229
|
-
*/
|
|
230
|
-
docFromStream(inputStream: Readable, filename: string): StreamInput;
|
|
231
|
-
/**
|
|
232
|
-
* Load an input document from bytes.
|
|
233
|
-
* @param inputBytes input content, as a Uint8Array or Buffer.
|
|
234
|
-
* @param filename file name.
|
|
235
|
-
*/
|
|
236
|
-
docFromBytes(inputBytes: Uint8Array, filename: string): BytesInput;
|
|
237
|
-
/**
|
|
238
|
-
* Load an input document from a URL.
|
|
239
|
-
* @param url input url. Must be HTTPS.
|
|
240
|
-
*/
|
|
241
|
-
docFromUrl(url: string): UrlInput;
|
|
242
|
-
/**
|
|
243
|
-
* Load an input document from a Buffer.
|
|
244
|
-
* @param buffer input content, as a buffer.
|
|
245
|
-
* @param filename file name.
|
|
246
|
-
*/
|
|
247
|
-
docFromBuffer(buffer: Buffer, filename: string): BufferInput;
|
|
248
214
|
}
|
|
249
215
|
export {};
|
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,12 +17,13 @@ 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 baseClient_1 = require("./baseClient");
|
|
21
21
|
/**
|
|
22
22
|
* Mindee Client class that centralizes most basic operations.
|
|
23
23
|
*
|
|
24
24
|
* @category Client
|
|
25
25
|
*/
|
|
26
|
-
class Client {
|
|
26
|
+
class Client extends baseClient_1.BaseClient {
|
|
27
27
|
/**
|
|
28
28
|
* @param {ClientOptions} options options for the initialization of a client.
|
|
29
29
|
*/
|
|
@@ -32,6 +32,7 @@ class Client {
|
|
|
32
32
|
throwOnError: true,
|
|
33
33
|
debug: false,
|
|
34
34
|
}) {
|
|
35
|
+
super();
|
|
35
36
|
_Client_instances.add(this);
|
|
36
37
|
this.apiKey = apiKey ? apiKey : "";
|
|
37
38
|
handler_1.errorHandler.throwOnError = throwOnError ?? true;
|
|
@@ -82,7 +83,7 @@ class Client {
|
|
|
82
83
|
async enqueue(productClass, inputSource, params = {}) {
|
|
83
84
|
const endpoint = params?.endpoint ?? __classPrivateFieldGet(this, _Client_instances, "m", _Client_initializeOTSEndpoint).call(this, productClass);
|
|
84
85
|
if (inputSource === undefined) {
|
|
85
|
-
throw new Error("The '
|
|
86
|
+
throw new Error("The 'enqueue' function requires an input document.");
|
|
86
87
|
}
|
|
87
88
|
const rawResponse = await endpoint.predictAsync({
|
|
88
89
|
inputDoc: inputSource,
|
|
@@ -141,7 +142,7 @@ class Client {
|
|
|
141
142
|
async executeWorkflow(inputSource, workflowId, params = {}) {
|
|
142
143
|
const workflowEndpoint = new workflowEndpoint_1.WorkflowEndpoint(__classPrivateFieldGet(this, _Client_instances, "m", _Client_buildApiSettings).call(this), workflowId);
|
|
143
144
|
if (inputSource === undefined) {
|
|
144
|
-
throw new Error("The '
|
|
145
|
+
throw new Error("The 'executeWorkflow' function requires an input document.");
|
|
145
146
|
}
|
|
146
147
|
const rawResponse = await workflowEndpoint.executeWorkflow({
|
|
147
148
|
inputDoc: inputSource,
|
|
@@ -210,25 +211,25 @@ class Client {
|
|
|
210
211
|
recurringTimerOptions: undefined,
|
|
211
212
|
}) {
|
|
212
213
|
const validatedAsyncParams = __classPrivateFieldGet(this, _Client_instances, "m", _Client_setAsyncParams).call(this, asyncParams);
|
|
213
|
-
const enqueueResponse = await this.enqueue(productClass, inputSource,
|
|
214
|
+
const enqueueResponse = await this.enqueue(productClass, inputSource, validatedAsyncParams);
|
|
214
215
|
if (enqueueResponse.job.id === undefined || enqueueResponse.job.id.length === 0) {
|
|
215
216
|
throw Error("Enqueueing of the document failed.");
|
|
216
217
|
}
|
|
217
218
|
const queueId = enqueueResponse.job.id;
|
|
218
219
|
logger_1.logger.debug(`Successfully enqueued document with job id: ${queueId}.`);
|
|
219
|
-
await (0, promises_1.setTimeout)(validatedAsyncParams.initialDelaySec * 1000, undefined,
|
|
220
|
+
await (0, promises_1.setTimeout)(validatedAsyncParams.initialDelaySec * 1000, undefined, validatedAsyncParams.initialTimerOptions);
|
|
220
221
|
let retryCounter = 1;
|
|
221
222
|
let pollResults;
|
|
222
|
-
pollResults = await this.parseQueued(productClass, queueId,
|
|
223
|
+
pollResults = await this.parseQueued(productClass, queueId, validatedAsyncParams);
|
|
223
224
|
while (retryCounter < validatedAsyncParams.maxRetries) {
|
|
224
225
|
logger_1.logger.debug(`Polling server for parsing result with queueId: ${queueId}.
|
|
225
|
-
Attempt n°${retryCounter}/${
|
|
226
|
+
Attempt n°${retryCounter}/${validatedAsyncParams.maxRetries}.
|
|
226
227
|
Job status: ${pollResults.job.status}.`);
|
|
227
228
|
if (pollResults.job.status === "completed") {
|
|
228
229
|
break;
|
|
229
230
|
}
|
|
230
|
-
await (0, promises_1.setTimeout)(validatedAsyncParams.delaySec * 1000, undefined,
|
|
231
|
-
pollResults = await this.parseQueued(productClass, queueId,
|
|
231
|
+
await (0, promises_1.setTimeout)(validatedAsyncParams.delaySec * 1000, undefined, validatedAsyncParams.recurringTimerOptions);
|
|
232
|
+
pollResults = await this.parseQueued(productClass, queueId, validatedAsyncParams);
|
|
232
233
|
retryCounter++;
|
|
233
234
|
}
|
|
234
235
|
if (pollResults.job.status !== "completed") {
|
|
@@ -270,68 +271,6 @@ Job status: ${pollResults.job.status}.`);
|
|
|
270
271
|
}
|
|
271
272
|
return __classPrivateFieldGet(this, _Client_instances, "m", _Client_buildProductEndpoint).call(this, endpointName, cleanAccountName, cleanEndpointVersion);
|
|
272
273
|
}
|
|
273
|
-
/**
|
|
274
|
-
* Load an input document from a local path.
|
|
275
|
-
* @param inputPath
|
|
276
|
-
*/
|
|
277
|
-
docFromPath(inputPath) {
|
|
278
|
-
return new input_1.PathInput({
|
|
279
|
-
inputPath: inputPath,
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Load an input document from a base64 encoded string.
|
|
284
|
-
* @param inputString input content, as a string.
|
|
285
|
-
* @param filename file name.
|
|
286
|
-
*/
|
|
287
|
-
docFromBase64(inputString, filename) {
|
|
288
|
-
return new input_1.Base64Input({
|
|
289
|
-
inputString: inputString,
|
|
290
|
-
filename: filename,
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Load an input document from a `stream.Readable` object.
|
|
295
|
-
* @param inputStream input content, as a readable stream.
|
|
296
|
-
* @param filename file name.
|
|
297
|
-
*/
|
|
298
|
-
docFromStream(inputStream, filename) {
|
|
299
|
-
return new input_1.StreamInput({
|
|
300
|
-
inputStream: inputStream,
|
|
301
|
-
filename: filename,
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Load an input document from bytes.
|
|
306
|
-
* @param inputBytes input content, as a Uint8Array or Buffer.
|
|
307
|
-
* @param filename file name.
|
|
308
|
-
*/
|
|
309
|
-
docFromBytes(inputBytes, filename) {
|
|
310
|
-
return new input_1.BytesInput({
|
|
311
|
-
inputBytes: inputBytes,
|
|
312
|
-
filename: filename,
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Load an input document from a URL.
|
|
317
|
-
* @param url input url. Must be HTTPS.
|
|
318
|
-
*/
|
|
319
|
-
docFromUrl(url) {
|
|
320
|
-
return new input_1.UrlInput({
|
|
321
|
-
url: url,
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Load an input document from a Buffer.
|
|
326
|
-
* @param buffer input content, as a buffer.
|
|
327
|
-
* @param filename file name.
|
|
328
|
-
*/
|
|
329
|
-
docFromBuffer(buffer, filename) {
|
|
330
|
-
return new input_1.BufferInput({
|
|
331
|
-
buffer: buffer,
|
|
332
|
-
filename: filename,
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
274
|
}
|
|
336
275
|
exports.Client = Client;
|
|
337
276
|
_Client_instances = new WeakSet(), _Client_setAsyncParams = function _Client_setAsyncParams(asyncParams) {
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { LocalInputSource } from "./input";
|
|
2
|
+
import { InferenceResponse, JobResponse } from "./parsing/v2";
|
|
3
|
+
import { MindeeApiV2 } from "./http/mindeeApiV2";
|
|
4
|
+
import { BaseClient } from "./baseClient";
|
|
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 extends BaseClient {
|
|
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
|
+
}
|