mindee 4.8.0 → 4.8.2
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 +1 -0
- package/package.json +1 -1
- package/src/cli.js +2 -2
- package/src/client.d.ts +14 -1
- package/src/client.js +16 -14
- package/src/parsing/generated/generatedList.js +1 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.8.2 - 2024-02-09
|
|
4
|
+
### Changes
|
|
5
|
+
* :recycle: increased update time for async retries
|
|
6
|
+
|
|
7
|
+
### Fixes
|
|
8
|
+
* :bug: fixed improper float parsing for Generated list objects
|
|
9
|
+
* :bug: typescript should now allow the use of default values for enqueueAndParse() async options
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## v4.8.1 - 2024-02-06
|
|
13
|
+
### Fixes
|
|
14
|
+
* :bug: fixed invalid code samples for generated & async generic APIs
|
|
15
|
+
* :memo: fix corresponding docs
|
|
16
|
+
|
|
17
|
+
|
|
3
18
|
## v4.8.0 - 2024-02-05
|
|
4
19
|
### Changes
|
|
5
20
|
* :sparkles: add support for Generated APIs
|
package/README.md
CHANGED
|
@@ -144,6 +144,7 @@ const apiResponse = mindeeClient.parse(
|
|
|
144
144
|
Complete details on the working of the library are available in the following guides:
|
|
145
145
|
|
|
146
146
|
* [Node.js Getting Started](https://developers.mindee.com/docs/nodejs-getting-started)
|
|
147
|
+
* [Node.js Generated API](https://developers.mindee.com/docs/nodejs-generated-api)
|
|
147
148
|
* [Node.js Custom OCR](https://developers.mindee.com/docs/nodejs-api-builder)
|
|
148
149
|
* [Node.js Invoice OCR](https://developers.mindee.com/docs/nodejs-invoice-ocr)
|
|
149
150
|
* [Node.js Receipt OCR](https://developers.mindee.com/docs/nodejs-receipt-ocr)
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -241,7 +241,7 @@ async function callEnqueueAndParse(productClass, command, inputPath, options) {
|
|
|
241
241
|
cropper: predictParams.cropper,
|
|
242
242
|
initialDelaySec: 4,
|
|
243
243
|
delaySec: 2,
|
|
244
|
-
maxRetries:
|
|
244
|
+
maxRetries: 60,
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
247
|
else {
|
|
@@ -251,7 +251,7 @@ async function callEnqueueAndParse(productClass, command, inputPath, options) {
|
|
|
251
251
|
cropper: predictParams.cropper,
|
|
252
252
|
initialDelaySec: 4,
|
|
253
253
|
delaySec: 2,
|
|
254
|
-
maxRetries:
|
|
254
|
+
maxRetries: 60,
|
|
255
255
|
});
|
|
256
256
|
if (!response.document) {
|
|
257
257
|
throw Error("Document could not be retrieved");
|
package/src/client.d.ts
CHANGED
|
@@ -32,6 +32,19 @@ export interface PredictOptions {
|
|
|
32
32
|
/**
|
|
33
33
|
* Asynchronous polling parameters.
|
|
34
34
|
*/
|
|
35
|
+
export interface OptionalAsyncOptions extends PredictOptions {
|
|
36
|
+
initialDelaySec?: number;
|
|
37
|
+
delaySec?: number;
|
|
38
|
+
maxRetries?: number;
|
|
39
|
+
initialTimerOptions?: {
|
|
40
|
+
ref?: boolean;
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
};
|
|
43
|
+
recurringTimerOptions?: {
|
|
44
|
+
ref?: boolean;
|
|
45
|
+
signal?: AbortSignal;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
35
48
|
export interface AsyncOptions extends PredictOptions {
|
|
36
49
|
initialDelaySec: number;
|
|
37
50
|
delaySec: number;
|
|
@@ -139,7 +152,7 @@ export declare class Client {
|
|
|
139
152
|
* @category Synchronous
|
|
140
153
|
* @returns a `Promise` containing parsing results.
|
|
141
154
|
*/
|
|
142
|
-
enqueueAndParse<T extends Inference>(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, asyncParams?:
|
|
155
|
+
enqueueAndParse<T extends Inference>(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, asyncParams?: OptionalAsyncOptions): Promise<AsyncPredictResponse<T>>;
|
|
143
156
|
/**
|
|
144
157
|
* Forces boolean coercion on truthy/falsy parameters.
|
|
145
158
|
* @param param input parameter to check.
|
package/src/client.js
CHANGED
|
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
5
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
6
|
};
|
|
7
|
-
var _Client_instances,
|
|
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
10
|
const input_1 = require("./input");
|
|
@@ -155,34 +155,34 @@ class Client {
|
|
|
155
155
|
pageOptions: undefined,
|
|
156
156
|
initialDelaySec: 4,
|
|
157
157
|
delaySec: 2,
|
|
158
|
-
maxRetries:
|
|
158
|
+
maxRetries: 60,
|
|
159
159
|
initialTimerOptions: undefined,
|
|
160
160
|
recurringTimerOptions: undefined,
|
|
161
161
|
}) {
|
|
162
|
-
__classPrivateFieldGet(this, _Client_instances, "m",
|
|
162
|
+
const validatedAsyncParams = __classPrivateFieldGet(this, _Client_instances, "m", _Client_setAsyncParams).call(this, asyncParams);
|
|
163
163
|
const enqueueResponse = await this.enqueue(productClass, inputSource, asyncParams);
|
|
164
164
|
if (enqueueResponse.job.id === undefined || enqueueResponse.job.id.length === 0) {
|
|
165
165
|
throw Error("Enqueueing of the document failed.");
|
|
166
166
|
}
|
|
167
167
|
const queueId = enqueueResponse.job.id;
|
|
168
168
|
logger_1.logger.debug(`Successfully enqueued document with job id: ${queueId}.`);
|
|
169
|
-
await (0, promises_1.setTimeout)(
|
|
169
|
+
await (0, promises_1.setTimeout)(validatedAsyncParams.initialDelaySec * 1000, undefined, asyncParams.initialTimerOptions);
|
|
170
170
|
let retryCounter = 1;
|
|
171
171
|
let pollResults;
|
|
172
172
|
pollResults = await this.parseQueued(productClass, queueId, asyncParams);
|
|
173
|
-
while (retryCounter <
|
|
173
|
+
while (retryCounter < validatedAsyncParams.maxRetries) {
|
|
174
174
|
logger_1.logger.debug(`Polling server for parsing result with queueId: ${queueId}.
|
|
175
175
|
Attempt n°${retryCounter}/${asyncParams.maxRetries}.
|
|
176
176
|
Job status: ${pollResults.job.status}.`);
|
|
177
177
|
if (pollResults.job.status === "completed") {
|
|
178
178
|
break;
|
|
179
179
|
}
|
|
180
|
-
await (0, promises_1.setTimeout)(
|
|
180
|
+
await (0, promises_1.setTimeout)(validatedAsyncParams.delaySec * 1000, undefined, asyncParams.recurringTimerOptions);
|
|
181
181
|
pollResults = await this.parseQueued(productClass, queueId, asyncParams);
|
|
182
182
|
retryCounter++;
|
|
183
183
|
}
|
|
184
184
|
if (pollResults.job.status !== "completed") {
|
|
185
|
-
throw Error(`Asynchronous parsing request timed out after ${
|
|
185
|
+
throw Error(`Asynchronous parsing request timed out after ${validatedAsyncParams.delaySec * retryCounter} seconds`);
|
|
186
186
|
}
|
|
187
187
|
return pollResults;
|
|
188
188
|
}
|
|
@@ -282,22 +282,24 @@ Job status: ${pollResults.job.status}.`);
|
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
exports.Client = Client;
|
|
285
|
-
_Client_instances = new WeakSet(),
|
|
285
|
+
_Client_instances = new WeakSet(), _Client_setAsyncParams = function _Client_setAsyncParams(asyncParams) {
|
|
286
286
|
const minDelaySec = 1;
|
|
287
287
|
const minInitialDelay = 2;
|
|
288
288
|
const minRetries = 2;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
289
|
+
const newAsyncParams = { ...asyncParams };
|
|
290
|
+
newAsyncParams.delaySec ?? (newAsyncParams.delaySec = 2);
|
|
291
|
+
newAsyncParams.initialDelaySec ?? (newAsyncParams.initialDelaySec = 4);
|
|
292
|
+
newAsyncParams.maxRetries ?? (newAsyncParams.maxRetries = 60);
|
|
293
|
+
if (newAsyncParams.delaySec < minDelaySec) {
|
|
293
294
|
throw Error(`Cannot set auto-parsing delay to less than ${minDelaySec} seconds.`);
|
|
294
295
|
}
|
|
295
|
-
if (
|
|
296
|
+
if (newAsyncParams.initialDelaySec < minInitialDelay) {
|
|
296
297
|
throw Error(`Cannot set initial parsing delay to less than ${minInitialDelay} seconds.`);
|
|
297
298
|
}
|
|
298
|
-
if (
|
|
299
|
+
if (newAsyncParams.maxRetries < minRetries) {
|
|
299
300
|
throw Error(`Cannot set retry to less than ${minRetries}.`);
|
|
300
301
|
}
|
|
302
|
+
return newAsyncParams;
|
|
301
303
|
}, _Client_buildProductEndpoint = function _Client_buildProductEndpoint(endpointName, accountName, endpointVersion) {
|
|
302
304
|
return new http_1.Endpoint(endpointName, accountName, endpointVersion, __classPrivateFieldGet(this, _Client_instances, "m", _Client_buildApiSettings).call(this));
|
|
303
305
|
}, _Client_buildApiSettings = function _Client_buildApiSettings() {
|
|
@@ -18,10 +18,7 @@ class GeneratedListField {
|
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
20
|
const valueStr = { ...value };
|
|
21
|
-
if (valueStr["value"] !== null && valueStr["value"] !== undefined
|
|
22
|
-
valueStr["value"] = value["value"].toFixed(1);
|
|
23
|
-
}
|
|
24
|
-
else if (value["value"] !== undefined && value["value"] !== null) {
|
|
21
|
+
if (valueStr["value"] !== null && valueStr["value"] !== undefined) {
|
|
25
22
|
valueStr["value"] = value["value"].toString();
|
|
26
23
|
}
|
|
27
24
|
this.values.push(new standard_1.StringField({ prediction: valueStr, pageId: pageId }));
|