mindee 4.29.0-rc1 → 4.29.0-rc3
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 +22 -146
- package/package.json +1 -1
- package/src/client.d.ts +37 -2
- package/src/client.js +64 -3
- package/src/clientV2.d.ts +41 -7
- package/src/clientV2.js +65 -4
- package/src/http/mindeeApiV2.d.ts +3 -3
- package/src/http/mindeeApiV2.js +14 -8
- package/src/index.d.ts +1 -1
- package/src/input/sources/urlInput.d.ts +1 -1
- package/src/parsing/v2/field/baseField.d.ts +0 -2
- package/src/parsing/v2/field/baseField.js +0 -6
- package/src/parsing/v2/field/dynamicField.d.ts +7 -0
- package/src/parsing/v2/field/dynamicField.js +16 -0
- package/src/parsing/v2/field/objectField.d.ts +2 -2
- package/src/parsing/v2/field/objectField.js +2 -2
- package/src/parsing/v2/field/simpleField.d.ts +2 -2
- package/src/parsing/v2/field/simpleField.js +2 -2
- package/src/baseClient.d.ts +0 -38
- package/src/baseClient.js +0 -69
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.29.0-rc3 - 2025-07-25
|
|
4
|
+
### Changes
|
|
5
|
+
* :sparkles: add support for URL input source
|
|
6
|
+
### Fixes
|
|
7
|
+
* :arrow_up: bump dependencies to cover vulnerabilities
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## v4.29.0-rc2 - 2025-07-25
|
|
11
|
+
### Changes
|
|
12
|
+
* :recycle: harmonize with other client libraries
|
|
13
|
+
|
|
3
14
|
## v4.29.0-rc1 - 2025-07-21
|
|
4
15
|
### Changes
|
|
5
16
|
* :sparkles: add support for V2 client
|
package/README.md
CHANGED
|
@@ -3,163 +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
|
-
You can also take a look at the **[Reference Documentation](https://mindee.github.io/mindee-api-nodejs/)**.
|
|
158
|
-
|
|
159
|
-
## 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
|
|
160
39
|
Copyright © Mindee
|
|
161
40
|
|
|
162
41
|
Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
163
|
-
|
|
164
|
-
## Questions?
|
|
165
|
-
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g)
|
package/package.json
CHANGED
package/src/client.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { Endpoint } from "./http";
|
|
|
3
3
|
import { AsyncPredictResponse, ExecutionPriority, FeedbackResponse, Inference, PredictResponse, StringDict } from "./parsing/common";
|
|
4
4
|
import { GeneratedV1 } from "./product";
|
|
5
5
|
import { WorkflowResponse } from "./parsing/common/workflowResponse";
|
|
6
|
-
import {
|
|
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
|
*/
|
|
@@ -103,7 +104,7 @@ export interface ClientOptions {
|
|
|
103
104
|
*
|
|
104
105
|
* @category Client
|
|
105
106
|
*/
|
|
106
|
-
export declare class Client
|
|
107
|
+
export declare class Client {
|
|
107
108
|
#private;
|
|
108
109
|
/** Key of the API. */
|
|
109
110
|
protected apiKey: string;
|
|
@@ -211,5 +212,39 @@ export declare class Client extends BaseClient {
|
|
|
211
212
|
* @returns Endpoint a new product endpoint
|
|
212
213
|
*/
|
|
213
214
|
createEndpoint(endpointName: string, accountName: string, endpointVersion?: string): Endpoint;
|
|
215
|
+
/**
|
|
216
|
+
* Load an input document from a local path.
|
|
217
|
+
* @param inputPath
|
|
218
|
+
*/
|
|
219
|
+
docFromPath(inputPath: string): PathInput;
|
|
220
|
+
/**
|
|
221
|
+
* Load an input document from a base64 encoded string.
|
|
222
|
+
* @param inputString input content, as a string.
|
|
223
|
+
* @param filename file name.
|
|
224
|
+
*/
|
|
225
|
+
docFromBase64(inputString: string, filename: string): Base64Input;
|
|
226
|
+
/**
|
|
227
|
+
* Load an input document from a `stream.Readable` object.
|
|
228
|
+
* @param inputStream input content, as a readable stream.
|
|
229
|
+
* @param filename file name.
|
|
230
|
+
*/
|
|
231
|
+
docFromStream(inputStream: Readable, filename: string): StreamInput;
|
|
232
|
+
/**
|
|
233
|
+
* Load an input document from bytes.
|
|
234
|
+
* @param inputBytes input content, as a Uint8Array or Buffer.
|
|
235
|
+
* @param filename file name.
|
|
236
|
+
*/
|
|
237
|
+
docFromBytes(inputBytes: Uint8Array, filename: string): BytesInput;
|
|
238
|
+
/**
|
|
239
|
+
* Load an input document from a URL.
|
|
240
|
+
* @param url input url. Must be HTTPS.
|
|
241
|
+
*/
|
|
242
|
+
docFromUrl(url: string): UrlInput;
|
|
243
|
+
/**
|
|
244
|
+
* Load an input document from a Buffer.
|
|
245
|
+
* @param buffer input content, as a buffer.
|
|
246
|
+
* @param filename file name.
|
|
247
|
+
*/
|
|
248
|
+
docFromBuffer(buffer: Buffer, filename: string): BufferInput;
|
|
214
249
|
}
|
|
215
250
|
export {};
|
package/src/client.js
CHANGED
|
@@ -17,13 +17,13 @@ const promises_1 = require("node:timers/promises");
|
|
|
17
17
|
const errors_1 = require("./errors");
|
|
18
18
|
const workflowResponse_1 = require("./parsing/common/workflowResponse");
|
|
19
19
|
const workflowEndpoint_1 = require("./http/workflowEndpoint");
|
|
20
|
-
const
|
|
20
|
+
const input_1 = require("./input");
|
|
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 {
|
|
27
27
|
/**
|
|
28
28
|
* @param {ClientOptions} options options for the initialization of a client.
|
|
29
29
|
*/
|
|
@@ -32,7 +32,6 @@ class Client extends baseClient_1.BaseClient {
|
|
|
32
32
|
throwOnError: true,
|
|
33
33
|
debug: false,
|
|
34
34
|
}) {
|
|
35
|
-
super();
|
|
36
35
|
_Client_instances.add(this);
|
|
37
36
|
this.apiKey = apiKey ? apiKey : "";
|
|
38
37
|
handler_1.errorHandler.throwOnError = throwOnError ?? true;
|
|
@@ -271,6 +270,68 @@ Job status: ${pollResults.job.status}.`);
|
|
|
271
270
|
}
|
|
272
271
|
return __classPrivateFieldGet(this, _Client_instances, "m", _Client_buildProductEndpoint).call(this, endpointName, cleanAccountName, cleanEndpointVersion);
|
|
273
272
|
}
|
|
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
|
+
}
|
|
274
335
|
}
|
|
275
336
|
exports.Client = Client;
|
|
276
337
|
_Client_instances = new WeakSet(), _Client_setAsyncParams = function _Client_setAsyncParams(asyncParams) {
|
package/src/clientV2.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Base64Input, BufferInput, BytesInput, InputSource, PathInput, StreamInput, UrlInput } from "./input";
|
|
2
2
|
import { InferenceResponse, JobResponse } from "./parsing/v2";
|
|
3
3
|
import { MindeeApiV2 } from "./http/mindeeApiV2";
|
|
4
|
-
import {
|
|
4
|
+
import { Readable } from "stream";
|
|
5
5
|
/**
|
|
6
6
|
* Parameters for the internal polling loop in {@link ClientV2.enqueueAndGetInference | enqueueAndGetInference()} .
|
|
7
7
|
*
|
|
@@ -104,9 +104,9 @@ export interface ClientOptions {
|
|
|
104
104
|
*
|
|
105
105
|
* @category ClientV2
|
|
106
106
|
*/
|
|
107
|
-
export declare class ClientV2
|
|
107
|
+
export declare class ClientV2 {
|
|
108
108
|
#private;
|
|
109
|
-
/**
|
|
109
|
+
/** Mindee API handler. */
|
|
110
110
|
protected mindeeApi: MindeeApiV2;
|
|
111
111
|
/**
|
|
112
112
|
* @param {ClientOptions} options options for the initialization of a client.
|
|
@@ -114,12 +114,12 @@ export declare class ClientV2 extends BaseClient {
|
|
|
114
114
|
constructor({ apiKey, throwOnError, debug }?: ClientOptions);
|
|
115
115
|
/**
|
|
116
116
|
* Send the document to an asynchronous endpoint and return its ID in the queue.
|
|
117
|
-
* @param inputSource file to parse.
|
|
117
|
+
* @param inputSource file or URL to parse.
|
|
118
118
|
* @param params parameters relating to prediction options.
|
|
119
119
|
* @category Asynchronous
|
|
120
120
|
* @returns a `Promise` containing the job (queue) corresponding to a document.
|
|
121
121
|
*/
|
|
122
|
-
enqueueInference(inputSource:
|
|
122
|
+
enqueueInference(inputSource: InputSource, params: InferenceParameters): Promise<JobResponse>;
|
|
123
123
|
/**
|
|
124
124
|
* Retrieves an inference.
|
|
125
125
|
*
|
|
@@ -152,5 +152,39 @@ export declare class ClientV2 extends BaseClient {
|
|
|
152
152
|
* @category Synchronous
|
|
153
153
|
* @returns a `Promise` containing parsing results.
|
|
154
154
|
*/
|
|
155
|
-
enqueueAndGetInference(inputDoc:
|
|
155
|
+
enqueueAndGetInference(inputDoc: InputSource, 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;
|
|
156
190
|
}
|
package/src/clientV2.js
CHANGED
|
@@ -7,18 +7,18 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
7
7
|
var _ClientV2_instances, _ClientV2_setAsyncParams;
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ClientV2 = void 0;
|
|
10
|
+
const input_1 = require("./input");
|
|
10
11
|
const handler_1 = require("./errors/handler");
|
|
11
12
|
const logger_1 = require("./logger");
|
|
12
13
|
const promises_1 = require("node:timers/promises");
|
|
13
14
|
const mindeeApiV2_1 = require("./http/mindeeApiV2");
|
|
14
|
-
const baseClient_1 = require("./baseClient");
|
|
15
15
|
const mindeeError_1 = require("./errors/mindeeError");
|
|
16
16
|
/**
|
|
17
17
|
* Mindee Client V2 class that centralizes most basic operations.
|
|
18
18
|
*
|
|
19
19
|
* @category ClientV2
|
|
20
20
|
*/
|
|
21
|
-
class ClientV2
|
|
21
|
+
class ClientV2 {
|
|
22
22
|
/**
|
|
23
23
|
* @param {ClientOptions} options options for the initialization of a client.
|
|
24
24
|
*/
|
|
@@ -27,7 +27,6 @@ class ClientV2 extends baseClient_1.BaseClient {
|
|
|
27
27
|
throwOnError: true,
|
|
28
28
|
debug: false,
|
|
29
29
|
}) {
|
|
30
|
-
super();
|
|
31
30
|
_ClientV2_instances.add(this);
|
|
32
31
|
this.mindeeApi = new mindeeApiV2_1.MindeeApiV2(apiKey);
|
|
33
32
|
handler_1.errorHandler.throwOnError = throwOnError ?? true;
|
|
@@ -39,7 +38,7 @@ class ClientV2 extends baseClient_1.BaseClient {
|
|
|
39
38
|
}
|
|
40
39
|
/**
|
|
41
40
|
* Send the document to an asynchronous endpoint and return its ID in the queue.
|
|
42
|
-
* @param inputSource file to parse.
|
|
41
|
+
* @param inputSource file or URL to parse.
|
|
43
42
|
* @param params parameters relating to prediction options.
|
|
44
43
|
* @category Asynchronous
|
|
45
44
|
* @returns a `Promise` containing the job (queue) corresponding to a document.
|
|
@@ -120,6 +119,68 @@ Job status: ${pollResults.job.status}.`);
|
|
|
120
119
|
validatedAsyncParams.delaySec * retryCounter +
|
|
121
120
|
" seconds");
|
|
122
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Load an input source from a local path.
|
|
124
|
+
* @param inputPath
|
|
125
|
+
*/
|
|
126
|
+
sourceFromPath(inputPath) {
|
|
127
|
+
return new input_1.PathInput({
|
|
128
|
+
inputPath: inputPath,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Load an input source from a base64 encoded string.
|
|
133
|
+
* @param inputString input content, as a string.
|
|
134
|
+
* @param filename file name.
|
|
135
|
+
*/
|
|
136
|
+
sourceFromBase64(inputString, filename) {
|
|
137
|
+
return new input_1.Base64Input({
|
|
138
|
+
inputString: inputString,
|
|
139
|
+
filename: filename,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Load an input source from a `stream.Readable` object.
|
|
144
|
+
* @param inputStream input content, as a readable stream.
|
|
145
|
+
* @param filename file name.
|
|
146
|
+
*/
|
|
147
|
+
sourceFromStream(inputStream, filename) {
|
|
148
|
+
return new input_1.StreamInput({
|
|
149
|
+
inputStream: inputStream,
|
|
150
|
+
filename: filename,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Load an input source from bytes.
|
|
155
|
+
* @param inputBytes input content, as a Uint8Array or Buffer.
|
|
156
|
+
* @param filename file name.
|
|
157
|
+
*/
|
|
158
|
+
sourceFromBytes(inputBytes, filename) {
|
|
159
|
+
return new input_1.BytesInput({
|
|
160
|
+
inputBytes: inputBytes,
|
|
161
|
+
filename: filename,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Load an input source from a Buffer.
|
|
166
|
+
* @param buffer input content, as a buffer.
|
|
167
|
+
* @param filename file name.
|
|
168
|
+
*/
|
|
169
|
+
sourceFromBuffer(buffer, filename) {
|
|
170
|
+
return new input_1.BufferInput({
|
|
171
|
+
buffer: buffer,
|
|
172
|
+
filename: filename,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Load an input source from a URL.
|
|
177
|
+
* @param url input url. Must be HTTPS.
|
|
178
|
+
*/
|
|
179
|
+
sourceFromUrl(url) {
|
|
180
|
+
return new input_1.UrlInput({
|
|
181
|
+
url: url,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
123
184
|
}
|
|
124
185
|
exports.ClientV2 = ClientV2;
|
|
125
186
|
_ClientV2_instances = new WeakSet(), _ClientV2_setAsyncParams = function _ClientV2_setAsyncParams(asyncParams = undefined) {
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { ApiSettingsV2 } from "./apiSettingsV2";
|
|
2
2
|
import { InferenceParameters } from "../clientV2";
|
|
3
3
|
import { InferenceResponse, JobResponse } from "../parsing/v2";
|
|
4
|
-
import {
|
|
4
|
+
import { InputSource } from "../input";
|
|
5
5
|
export declare class MindeeApiV2 {
|
|
6
6
|
#private;
|
|
7
7
|
settings: ApiSettingsV2;
|
|
8
8
|
constructor(apiKey?: string);
|
|
9
9
|
/**
|
|
10
10
|
* Sends a file to the inference queue.
|
|
11
|
-
* @param
|
|
11
|
+
* @param inputSource Local file loaded as an input.
|
|
12
12
|
* @param params {InferenceParameters} parameters relating to the enqueueing options.
|
|
13
13
|
* @category V2
|
|
14
14
|
* @throws Error if the server's response contains one.
|
|
15
15
|
* @returns a `Promise` containing a job response.
|
|
16
16
|
*/
|
|
17
|
-
reqPostInferenceEnqueue(
|
|
17
|
+
reqPostInferenceEnqueue(inputSource: InputSource, params: InferenceParameters): Promise<JobResponse>;
|
|
18
18
|
/**
|
|
19
19
|
* Requests the job of a queued document from the API.
|
|
20
20
|
* Throws an error if the server's response contains one.
|
package/src/http/mindeeApiV2.js
CHANGED
|
@@ -14,6 +14,7 @@ const apiSettingsV2_1 = require("./apiSettingsV2");
|
|
|
14
14
|
const v2_1 = require("../parsing/v2");
|
|
15
15
|
const form_data_1 = __importDefault(require("form-data"));
|
|
16
16
|
const baseEndpoint_1 = require("./baseEndpoint");
|
|
17
|
+
const input_1 = require("../input");
|
|
17
18
|
const mindeeError_1 = require("../errors/mindeeError");
|
|
18
19
|
const logger_1 = require("../logger");
|
|
19
20
|
class MindeeApiV2 {
|
|
@@ -23,18 +24,18 @@ class MindeeApiV2 {
|
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Sends a file to the inference queue.
|
|
26
|
-
* @param
|
|
27
|
+
* @param inputSource Local file loaded as an input.
|
|
27
28
|
* @param params {InferenceParameters} parameters relating to the enqueueing options.
|
|
28
29
|
* @category V2
|
|
29
30
|
* @throws Error if the server's response contains one.
|
|
30
31
|
* @returns a `Promise` containing a job response.
|
|
31
32
|
*/
|
|
32
|
-
async reqPostInferenceEnqueue(
|
|
33
|
-
await
|
|
33
|
+
async reqPostInferenceEnqueue(inputSource, params) {
|
|
34
|
+
await inputSource.init();
|
|
34
35
|
if (params.modelId === undefined || params.modelId === null || params.modelId === "") {
|
|
35
36
|
throw new Error("Model ID must be provided");
|
|
36
37
|
}
|
|
37
|
-
const result = await __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_documentEnqueuePost).call(this,
|
|
38
|
+
const result = await __classPrivateFieldGet(this, _MindeeApiV2_instances, "m", _MindeeApiV2_documentEnqueuePost).call(this, inputSource, params);
|
|
38
39
|
if (result.data.error?.code !== undefined) {
|
|
39
40
|
throw new mindeeError_1.MindeeHttpErrorV2(result.data.error.code, result.data.error.message ?? "Unknown error.");
|
|
40
41
|
}
|
|
@@ -78,7 +79,7 @@ _MindeeApiV2_instances = new WeakSet(), _MindeeApiV2_processResponse = function
|
|
|
78
79
|
logger_1.logger.error(`Raised '${e}' Couldn't deserialize response object:\n${JSON.stringify(result.data)}`);
|
|
79
80
|
throw new mindeeError_1.MindeeApiV2Error("Couldn't deserialize response object.");
|
|
80
81
|
}
|
|
81
|
-
}, _MindeeApiV2_documentEnqueuePost = function _MindeeApiV2_documentEnqueuePost(
|
|
82
|
+
}, _MindeeApiV2_documentEnqueuePost = function _MindeeApiV2_documentEnqueuePost(inputSource, params) {
|
|
82
83
|
const form = new form_data_1.default();
|
|
83
84
|
form.append("model_id", params.modelId);
|
|
84
85
|
if (params.rag) {
|
|
@@ -87,9 +88,14 @@ _MindeeApiV2_instances = new WeakSet(), _MindeeApiV2_processResponse = function
|
|
|
87
88
|
if (params.webhookIds && params.webhookIds.length > 0) {
|
|
88
89
|
form.append("webhook_ids", params.webhookIds.join(","));
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
if (inputSource instanceof input_1.LocalInputSource) {
|
|
92
|
+
form.append("file", inputSource.fileObject, {
|
|
93
|
+
filename: inputSource.filename,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
form.append("url", inputSource.url);
|
|
98
|
+
}
|
|
93
99
|
const path = "/v2/inferences/enqueue";
|
|
94
100
|
const headers = { ...this.settings.baseHeaders, ...form.getHeaders() };
|
|
95
101
|
const options = {
|
package/src/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export * as product from "./product";
|
|
|
2
2
|
export { Client, PredictOptions } from "./client";
|
|
3
3
|
export { ClientV2, InferenceParameters, PollingOptions } from "./clientV2";
|
|
4
4
|
export { AsyncPredictResponse, PredictResponse, Inference, Prediction, Document, Page, } from "./parsing/common";
|
|
5
|
-
export { InputSource, PageOptionsOperation, LocalResponse } from "./input";
|
|
5
|
+
export { InputSource, PageOptions, PageOptionsOperation, LocalResponse } from "./input";
|
|
6
6
|
export * as internal from "./internal";
|
|
7
7
|
export * as imageOperations from "./imageOperations";
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { FieldConfidence } from "./fieldConfidence";
|
|
2
|
-
import { FieldLocation } from "./fieldLocation";
|
|
3
2
|
import { StringDict } from "../../common";
|
|
4
3
|
export declare abstract class BaseField {
|
|
5
4
|
protected _indentLevel: number;
|
|
6
|
-
locations: Array<FieldLocation> | undefined;
|
|
7
5
|
confidence: FieldConfidence | undefined;
|
|
8
6
|
protected constructor(rawResponse: StringDict, indentLevel?: number);
|
|
9
7
|
}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseField = void 0;
|
|
4
|
-
const fieldLocation_1 = require("./fieldLocation");
|
|
5
4
|
class BaseField {
|
|
6
5
|
constructor(rawResponse, indentLevel = 0) {
|
|
7
6
|
this._indentLevel = indentLevel;
|
|
8
|
-
if (rawResponse["locations"]) {
|
|
9
|
-
this.locations = rawResponse["locations"].map((location) => {
|
|
10
|
-
return location ? new fieldLocation_1.FieldLocation(location) : "";
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
7
|
if (rawResponse["confidence"] !== undefined) {
|
|
14
8
|
this.confidence = rawResponse["confidence"];
|
|
15
9
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseField } from "./baseField";
|
|
2
|
+
import { FieldLocation } from "./fieldLocation";
|
|
3
|
+
import { StringDict } from "../../common";
|
|
4
|
+
export declare class DynamicField extends BaseField {
|
|
5
|
+
locations: Array<FieldLocation> | undefined;
|
|
6
|
+
constructor(rawResponse: StringDict, indentLevel?: number);
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicField = void 0;
|
|
4
|
+
const baseField_1 = require("./baseField");
|
|
5
|
+
const fieldLocation_1 = require("./fieldLocation");
|
|
6
|
+
class DynamicField extends baseField_1.BaseField {
|
|
7
|
+
constructor(rawResponse, indentLevel = 0) {
|
|
8
|
+
super(rawResponse, indentLevel);
|
|
9
|
+
if (rawResponse["locations"]) {
|
|
10
|
+
this.locations = rawResponse["locations"].map((location) => {
|
|
11
|
+
return location ? new fieldLocation_1.FieldLocation(location) : "";
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.DynamicField = DynamicField;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseField } from "./baseField";
|
|
2
1
|
import { InferenceFields } from "./inferenceFields";
|
|
3
2
|
import { StringDict } from "../../common";
|
|
4
|
-
|
|
3
|
+
import { DynamicField } from "./dynamicField";
|
|
4
|
+
export declare class ObjectField extends DynamicField {
|
|
5
5
|
readonly fields: InferenceFields;
|
|
6
6
|
constructor(serverResponse: StringDict, indentLevel?: number);
|
|
7
7
|
toString(): string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObjectField = void 0;
|
|
4
|
-
const baseField_1 = require("./baseField");
|
|
5
4
|
const inferenceFields_1 = require("./inferenceFields");
|
|
6
|
-
|
|
5
|
+
const dynamicField_1 = require("./dynamicField");
|
|
6
|
+
class ObjectField extends dynamicField_1.DynamicField {
|
|
7
7
|
constructor(serverResponse, indentLevel = 0) {
|
|
8
8
|
super(serverResponse, indentLevel);
|
|
9
9
|
this.fields = new inferenceFields_1.InferenceFields(serverResponse["fields"], this._indentLevel + 1);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BaseField } from "./baseField";
|
|
2
1
|
import { StringDict } from "../../common";
|
|
3
|
-
|
|
2
|
+
import { DynamicField } from "./dynamicField";
|
|
3
|
+
export declare class SimpleField extends DynamicField {
|
|
4
4
|
readonly value: string | number | boolean | null;
|
|
5
5
|
constructor(serverResponse: StringDict, indentLevel?: number);
|
|
6
6
|
toString(): string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SimpleField = void 0;
|
|
4
|
-
const
|
|
5
|
-
class SimpleField extends
|
|
4
|
+
const dynamicField_1 = require("./dynamicField");
|
|
5
|
+
class SimpleField extends dynamicField_1.DynamicField {
|
|
6
6
|
constructor(serverResponse, indentLevel = 0) {
|
|
7
7
|
super(serverResponse, indentLevel);
|
|
8
8
|
this.value =
|
package/src/baseClient.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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
|
-
}
|
package/src/baseClient.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
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;
|