mindee 4.29.0-rc4 → 4.29.0-rc6
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 +10 -0
- package/package.json +5 -5
- package/src/client.js +4 -3
- package/src/clientV2.d.ts +3 -38
- package/src/clientV2.js +6 -66
- package/src/index.d.ts +3 -2
- package/src/index.js +10 -1
- package/src/input/localResponse.d.ts +5 -5
- package/src/input/localResponse.js +17 -7
- package/src/input/sources/base64Input.js +1 -0
- package/src/input/sources/bufferInput.js +1 -0
- package/src/input/sources/bytesInput.js +1 -0
- package/src/input/sources/inputSource.d.ts +2 -0
- package/src/input/sources/inputSource.js +4 -0
- package/src/input/sources/localInputSource.d.ts +2 -2
- package/src/input/sources/localInputSource.js +16 -4
- package/src/input/sources/pathInput.js +1 -0
- package/src/input/sources/streamInput.js +1 -0
- package/src/input/sources/urlInput.js +1 -0
- package/src/parsing/v2/field/baseField.d.ts +2 -0
- package/src/parsing/v2/field/baseField.js +7 -1
- package/src/parsing/v2/field/fieldConfidence.d.ts +4 -4
- package/src/parsing/v2/field/fieldConfidence.js +5 -4
- package/src/parsing/v2/field/fieldLocation.js +2 -4
- 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/parsing/v2/field/dynamicField.d.ts +0 -7
- package/src/parsing/v2/field/dynamicField.js +0 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.29.0-rc6 - 2025-08-22
|
|
4
|
+
### Changes
|
|
5
|
+
* :recycle: rework local and input sources
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## v4.29.0-rc5 - 2025-07-30
|
|
9
|
+
### Changes
|
|
10
|
+
* :recycle: allow direct import of input sources
|
|
11
|
+
|
|
12
|
+
|
|
3
13
|
## v4.29.0-rc4 - 2025-07-29
|
|
4
14
|
### Changes
|
|
5
15
|
* :sparkles: add support for page count & mime type + fix syntaxes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "4.29.0-
|
|
3
|
+
"version": "4.29.0-rc6",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "bin/mindee.js",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://mindee.com/",
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@types/chai": "^4.3.
|
|
43
|
+
"@types/chai": "^4.3.20",
|
|
44
44
|
"@types/mocha": "^10.0.10",
|
|
45
|
-
"@types/node": "^18.15.
|
|
45
|
+
"@types/node": "^18.15.13",
|
|
46
46
|
"@types/tmp": "^0.2.6",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
48
|
-
"@typescript-eslint/parser": "^8.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.40.0",
|
|
48
|
+
"@typescript-eslint/parser": "^8.40.0",
|
|
49
49
|
"chai": "^4.3.10",
|
|
50
50
|
"eslint": "^9.15.0",
|
|
51
51
|
"eslint-plugin-jsdoc": "^50.5.0",
|
package/src/client.js
CHANGED
|
@@ -121,10 +121,11 @@ class Client {
|
|
|
121
121
|
* @returns A valid prediction
|
|
122
122
|
*/
|
|
123
123
|
try {
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
const asDict = await localResponse.asDict();
|
|
125
|
+
if (Object.prototype.hasOwnProperty.call(asDict, "job")) {
|
|
126
|
+
return new common_1.AsyncPredictResponse(productClass, asDict);
|
|
126
127
|
}
|
|
127
|
-
return new common_1.PredictResponse(productClass,
|
|
128
|
+
return new common_1.PredictResponse(productClass, asDict);
|
|
128
129
|
}
|
|
129
130
|
catch {
|
|
130
131
|
throw new errors_1.MindeeError("No prediction found in local response.");
|
package/src/clientV2.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InputSource } from "./input";
|
|
2
2
|
import { InferenceResponse, JobResponse } from "./parsing/v2";
|
|
3
3
|
import { MindeeApiV2 } from "./http/mindeeApiV2";
|
|
4
|
-
import { Readable } from "stream";
|
|
5
4
|
/**
|
|
6
5
|
* Parameters for the internal polling loop in {@link ClientV2.enqueueAndGetInference | enqueueAndGetInference()} .
|
|
7
6
|
*
|
|
@@ -145,46 +144,12 @@ export declare class ClientV2 {
|
|
|
145
144
|
* Send a document to an endpoint and poll the server until the result is sent or
|
|
146
145
|
* until the maximum number of tries is reached.
|
|
147
146
|
*
|
|
148
|
-
* @param
|
|
147
|
+
* @param inputSource file or URL to parse.
|
|
149
148
|
* @param params parameters relating to prediction options.
|
|
150
149
|
*
|
|
151
150
|
* @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`.
|
|
152
151
|
* @category Synchronous
|
|
153
152
|
* @returns a `Promise` containing parsing results.
|
|
154
153
|
*/
|
|
155
|
-
enqueueAndGetInference(
|
|
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;
|
|
154
|
+
enqueueAndGetInference(inputSource: InputSource, params: InferenceParameters): Promise<InferenceResponse>;
|
|
190
155
|
}
|
package/src/clientV2.js
CHANGED
|
@@ -7,7 +7,6 @@ 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");
|
|
11
10
|
const handler_1 = require("./errors/handler");
|
|
12
11
|
const logger_1 = require("./logger");
|
|
13
12
|
const promises_1 = require("node:timers/promises");
|
|
@@ -47,6 +46,9 @@ class ClientV2 {
|
|
|
47
46
|
if (inputSource === undefined) {
|
|
48
47
|
throw new Error("The 'enqueue' function requires an input document.");
|
|
49
48
|
}
|
|
49
|
+
if (!inputSource.isInitialized()) {
|
|
50
|
+
await inputSource.init();
|
|
51
|
+
}
|
|
50
52
|
return await this.mindeeApi.reqPostInferenceEnqueue(inputSource, params);
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
@@ -78,16 +80,16 @@ class ClientV2 {
|
|
|
78
80
|
* Send a document to an endpoint and poll the server until the result is sent or
|
|
79
81
|
* until the maximum number of tries is reached.
|
|
80
82
|
*
|
|
81
|
-
* @param
|
|
83
|
+
* @param inputSource file or URL to parse.
|
|
82
84
|
* @param params parameters relating to prediction options.
|
|
83
85
|
*
|
|
84
86
|
* @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`.
|
|
85
87
|
* @category Synchronous
|
|
86
88
|
* @returns a `Promise` containing parsing results.
|
|
87
89
|
*/
|
|
88
|
-
async enqueueAndGetInference(
|
|
90
|
+
async enqueueAndGetInference(inputSource, params) {
|
|
89
91
|
const validatedAsyncParams = __classPrivateFieldGet(this, _ClientV2_instances, "m", _ClientV2_setAsyncParams).call(this, params.pollingOptions);
|
|
90
|
-
const enqueueResponse = await this.enqueueInference(
|
|
92
|
+
const enqueueResponse = await this.enqueueInference(inputSource, params);
|
|
91
93
|
if (enqueueResponse.job.id === undefined || enqueueResponse.job.id.length === 0) {
|
|
92
94
|
logger_1.logger.error(`Failed enqueueing:\n${enqueueResponse.getRawHttp()}`);
|
|
93
95
|
throw Error("Enqueueing of the document failed.");
|
|
@@ -119,68 +121,6 @@ Job status: ${pollResults.job.status}.`);
|
|
|
119
121
|
validatedAsyncParams.delaySec * retryCounter +
|
|
120
122
|
" seconds");
|
|
121
123
|
}
|
|
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
|
-
}
|
|
184
124
|
}
|
|
185
125
|
exports.ClientV2 = ClientV2;
|
|
186
126
|
_ClientV2_instances = new WeakSet(), _ClientV2_setAsyncParams = function _ClientV2_setAsyncParams(asyncParams = undefined) {
|
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * as product from "./product";
|
|
2
|
-
export { Client, PredictOptions } from "./client";
|
|
2
|
+
export { Client, PredictOptions, WorkflowOptions } from "./client";
|
|
3
3
|
export { ClientV2, InferenceParameters, PollingOptions } from "./clientV2";
|
|
4
4
|
export { AsyncPredictResponse, PredictResponse, Inference, Prediction, Document, Page, } from "./parsing/common";
|
|
5
|
-
export {
|
|
5
|
+
export { InferenceResponse, JobResponse, } from "./parsing/v2";
|
|
6
|
+
export { InputSource, Base64Input, BufferInput, BytesInput, PathInput, StreamInput, UrlInput, PageOptions, PageOptionsOperation, LocalResponse } from "./input";
|
|
6
7
|
export * as internal from "./internal";
|
|
7
8
|
export * as imageOperations from "./imageOperations";
|
package/src/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.imageOperations = exports.internal = exports.LocalResponse = exports.PageOptionsOperation = exports.InputSource = exports.Page = exports.Document = exports.Prediction = exports.Inference = exports.PredictResponse = exports.AsyncPredictResponse = exports.ClientV2 = exports.Client = exports.product = void 0;
|
|
36
|
+
exports.imageOperations = exports.internal = exports.LocalResponse = exports.PageOptionsOperation = exports.UrlInput = exports.StreamInput = exports.PathInput = exports.BytesInput = exports.BufferInput = exports.Base64Input = exports.InputSource = exports.JobResponse = exports.InferenceResponse = exports.Page = exports.Document = exports.Prediction = exports.Inference = exports.PredictResponse = exports.AsyncPredictResponse = exports.ClientV2 = exports.Client = exports.product = void 0;
|
|
37
37
|
exports.product = __importStar(require("./product"));
|
|
38
38
|
var client_1 = require("./client");
|
|
39
39
|
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|
|
@@ -46,8 +46,17 @@ Object.defineProperty(exports, "Inference", { enumerable: true, get: function ()
|
|
|
46
46
|
Object.defineProperty(exports, "Prediction", { enumerable: true, get: function () { return common_1.Prediction; } });
|
|
47
47
|
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return common_1.Document; } });
|
|
48
48
|
Object.defineProperty(exports, "Page", { enumerable: true, get: function () { return common_1.Page; } });
|
|
49
|
+
var v2_1 = require("./parsing/v2");
|
|
50
|
+
Object.defineProperty(exports, "InferenceResponse", { enumerable: true, get: function () { return v2_1.InferenceResponse; } });
|
|
51
|
+
Object.defineProperty(exports, "JobResponse", { enumerable: true, get: function () { return v2_1.JobResponse; } });
|
|
49
52
|
var input_1 = require("./input");
|
|
50
53
|
Object.defineProperty(exports, "InputSource", { enumerable: true, get: function () { return input_1.InputSource; } });
|
|
54
|
+
Object.defineProperty(exports, "Base64Input", { enumerable: true, get: function () { return input_1.Base64Input; } });
|
|
55
|
+
Object.defineProperty(exports, "BufferInput", { enumerable: true, get: function () { return input_1.BufferInput; } });
|
|
56
|
+
Object.defineProperty(exports, "BytesInput", { enumerable: true, get: function () { return input_1.BytesInput; } });
|
|
57
|
+
Object.defineProperty(exports, "PathInput", { enumerable: true, get: function () { return input_1.PathInput; } });
|
|
58
|
+
Object.defineProperty(exports, "StreamInput", { enumerable: true, get: function () { return input_1.StreamInput; } });
|
|
59
|
+
Object.defineProperty(exports, "UrlInput", { enumerable: true, get: function () { return input_1.UrlInput; } });
|
|
51
60
|
Object.defineProperty(exports, "PageOptionsOperation", { enumerable: true, get: function () { return input_1.PageOptionsOperation; } });
|
|
52
61
|
Object.defineProperty(exports, "LocalResponse", { enumerable: true, get: function () { return input_1.LocalResponse; } });
|
|
53
62
|
exports.internal = __importStar(require("./internal"));
|
|
@@ -8,6 +8,7 @@ import { CommonResponse } from "../parsing/v2";
|
|
|
8
8
|
export declare class LocalResponse {
|
|
9
9
|
private file;
|
|
10
10
|
private readonly inputHandle;
|
|
11
|
+
protected initialized: boolean;
|
|
11
12
|
/**
|
|
12
13
|
* Creates an instance of LocalResponse.
|
|
13
14
|
*/
|
|
@@ -17,7 +18,7 @@ export declare class LocalResponse {
|
|
|
17
18
|
* Returns the dictionary representation of the file.
|
|
18
19
|
* @returns A JSON-like object.
|
|
19
20
|
*/
|
|
20
|
-
asDict(): StringDict
|
|
21
|
+
asDict(): Promise<StringDict>;
|
|
21
22
|
/**
|
|
22
23
|
* Returns the HMAC signature of the local response, from the secret key provided.
|
|
23
24
|
* @param secretKey - Secret key, either a string or a byte/byte array.
|
|
@@ -32,15 +33,14 @@ export declare class LocalResponse {
|
|
|
32
33
|
*/
|
|
33
34
|
isValidHmacSignature(secretKey: string | Buffer | Uint8Array, signature: string): boolean;
|
|
34
35
|
/**
|
|
35
|
-
* Deserialize the loaded local response into the requested CommonResponse
|
|
36
|
+
* Deserialize the loaded local response into the requested CommonResponse-derived class.
|
|
36
37
|
*
|
|
37
38
|
* Typically used when dealing with V2 webhook callbacks.
|
|
38
39
|
*
|
|
39
40
|
* @typeParam ResponseT - A class that extends `CommonResponse`.
|
|
40
|
-
* @param responseClass - The constructor of the class into which
|
|
41
|
-
* the payload should be deserialized.
|
|
41
|
+
* @param responseClass - The constructor of the class into which the payload should be deserialized.
|
|
42
42
|
* @returns An instance of `responseClass` populated with the file content.
|
|
43
43
|
* @throws MindeeError If the provided class cannot be instantiated.
|
|
44
44
|
*/
|
|
45
|
-
deserializeResponse<ResponseT extends CommonResponse>(responseClass: new (serverResponse: StringDict) => ResponseT): ResponseT
|
|
45
|
+
deserializeResponse<ResponseT extends CommonResponse>(responseClass: new (serverResponse: StringDict) => ResponseT): Promise<ResponseT>;
|
|
46
46
|
}
|
|
@@ -47,6 +47,7 @@ class LocalResponse {
|
|
|
47
47
|
* Creates an instance of LocalResponse.
|
|
48
48
|
*/
|
|
49
49
|
constructor(inputFile) {
|
|
50
|
+
this.initialized = false;
|
|
50
51
|
this.file = buffer_1.Buffer.alloc(0);
|
|
51
52
|
this.inputHandle = inputFile;
|
|
52
53
|
}
|
|
@@ -71,12 +72,16 @@ class LocalResponse {
|
|
|
71
72
|
else {
|
|
72
73
|
throw new errors_1.MindeeError("Incompatible type for input.");
|
|
73
74
|
}
|
|
75
|
+
this.initialized = true;
|
|
74
76
|
}
|
|
75
77
|
/**
|
|
76
78
|
* Returns the dictionary representation of the file.
|
|
77
79
|
* @returns A JSON-like object.
|
|
78
80
|
*/
|
|
79
|
-
asDict() {
|
|
81
|
+
async asDict() {
|
|
82
|
+
if (!this.initialized) {
|
|
83
|
+
await this.init();
|
|
84
|
+
}
|
|
80
85
|
try {
|
|
81
86
|
const content = this.file.toString("utf-8");
|
|
82
87
|
return JSON.parse(content);
|
|
@@ -91,6 +96,9 @@ class LocalResponse {
|
|
|
91
96
|
* @returns The HMAC signature of the local response.
|
|
92
97
|
*/
|
|
93
98
|
getHmacSignature(secretKey) {
|
|
99
|
+
if (!this.initialized) {
|
|
100
|
+
throw new Error("The `init()` method must be called before calling `getHmacSignature()`.");
|
|
101
|
+
}
|
|
94
102
|
const algorithm = "sha256";
|
|
95
103
|
try {
|
|
96
104
|
const hmac = crypto.createHmac(algorithm, secretKey);
|
|
@@ -108,25 +116,27 @@ class LocalResponse {
|
|
|
108
116
|
* @returns True if the HMAC signature is valid.
|
|
109
117
|
*/
|
|
110
118
|
isValidHmacSignature(secretKey, signature) {
|
|
119
|
+
if (!this.initialized) {
|
|
120
|
+
throw new Error("The `init()` method must be called before calling `isValidHmacSignature()`.");
|
|
121
|
+
}
|
|
111
122
|
return signature === this.getHmacSignature(secretKey);
|
|
112
123
|
}
|
|
113
124
|
/**
|
|
114
|
-
* Deserialize the loaded local response into the requested CommonResponse
|
|
125
|
+
* Deserialize the loaded local response into the requested CommonResponse-derived class.
|
|
115
126
|
*
|
|
116
127
|
* Typically used when dealing with V2 webhook callbacks.
|
|
117
128
|
*
|
|
118
129
|
* @typeParam ResponseT - A class that extends `CommonResponse`.
|
|
119
|
-
* @param responseClass - The constructor of the class into which
|
|
120
|
-
* the payload should be deserialized.
|
|
130
|
+
* @param responseClass - The constructor of the class into which the payload should be deserialized.
|
|
121
131
|
* @returns An instance of `responseClass` populated with the file content.
|
|
122
132
|
* @throws MindeeError If the provided class cannot be instantiated.
|
|
123
133
|
*/
|
|
124
|
-
deserializeResponse(responseClass) {
|
|
134
|
+
async deserializeResponse(responseClass) {
|
|
125
135
|
try {
|
|
126
|
-
return new responseClass(this.asDict());
|
|
136
|
+
return new responseClass(await this.asDict());
|
|
127
137
|
}
|
|
128
138
|
catch {
|
|
129
|
-
throw new errors_1.MindeeError("Invalid
|
|
139
|
+
throw new errors_1.MindeeError("Invalid response provided.");
|
|
130
140
|
}
|
|
131
141
|
}
|
|
132
142
|
}
|
|
@@ -16,6 +16,7 @@ class BytesInput extends localInputSource_1.LocalInputSource {
|
|
|
16
16
|
this.fileObject = Buffer.from(this.inputBytes);
|
|
17
17
|
this.mimeType = await this.checkMimetype();
|
|
18
18
|
this.inputBytes = new Uint8Array(0);
|
|
19
|
+
this.initialized = true;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
exports.BytesInput = BytesInput;
|
|
@@ -12,5 +12,7 @@ export declare const INPUT_TYPE_PATH = "path";
|
|
|
12
12
|
export declare const INPUT_TYPE_BUFFER = "buffer";
|
|
13
13
|
export declare abstract class InputSource {
|
|
14
14
|
fileObject: Buffer | string;
|
|
15
|
+
protected initialized: boolean;
|
|
15
16
|
init(): Promise<void>;
|
|
17
|
+
isInitialized(): boolean;
|
|
16
18
|
}
|
|
@@ -9,9 +9,13 @@ exports.INPUT_TYPE_BUFFER = "buffer";
|
|
|
9
9
|
class InputSource {
|
|
10
10
|
constructor() {
|
|
11
11
|
this.fileObject = "";
|
|
12
|
+
this.initialized = false;
|
|
12
13
|
}
|
|
13
14
|
async init() {
|
|
14
15
|
throw new Error("not Implemented");
|
|
15
16
|
}
|
|
17
|
+
isInitialized() {
|
|
18
|
+
return this.initialized;
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
21
|
exports.InputSource = InputSource;
|
|
@@ -10,8 +10,8 @@ export declare abstract class LocalInputSource extends InputSource {
|
|
|
10
10
|
* @param {InputConstructor} constructor Constructor parameters.
|
|
11
11
|
*/
|
|
12
12
|
protected constructor({ inputType }: InputConstructor);
|
|
13
|
+
protected checkMimetype(): Promise<string>;
|
|
13
14
|
isPdf(): boolean;
|
|
14
|
-
checkMimetype(): Promise<string>;
|
|
15
15
|
/**
|
|
16
16
|
* Cut PDF pages.
|
|
17
17
|
* @param pageOptions
|
|
@@ -20,7 +20,7 @@ export declare abstract class LocalInputSource extends InputSource {
|
|
|
20
20
|
/**
|
|
21
21
|
* Cut PDF pages.
|
|
22
22
|
* @param pageOptions
|
|
23
|
-
* @deprecated Deprecated in favor of {@link LocalInputSource.applyPageOptions
|
|
23
|
+
* @deprecated Deprecated in favor of {@link LocalInputSource.applyPageOptions}.
|
|
24
24
|
*/
|
|
25
25
|
cutPdf(pageOptions: PageOptions): Promise<void>;
|
|
26
26
|
/**
|
|
@@ -78,9 +78,6 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
78
78
|
this.inputType = inputType;
|
|
79
79
|
logger_1.logger.debug(`Loading file from: ${inputType}`);
|
|
80
80
|
}
|
|
81
|
-
isPdf() {
|
|
82
|
-
return this.mimeType === "application/pdf";
|
|
83
|
-
}
|
|
84
81
|
async checkMimetype() {
|
|
85
82
|
if (!(this.fileObject instanceof Buffer)) {
|
|
86
83
|
throw new Error(`MIME type cannot be verified on input source of type ${this.inputType}.`);
|
|
@@ -107,11 +104,20 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
107
104
|
logger_1.logger.debug(`File is of type: ${mimeType}`);
|
|
108
105
|
return mimeType;
|
|
109
106
|
}
|
|
107
|
+
isPdf() {
|
|
108
|
+
if (!this.initialized) {
|
|
109
|
+
throw new Error("The `init()` method must be called before calling `isPdf()`.");
|
|
110
|
+
}
|
|
111
|
+
return this.mimeType === "application/pdf";
|
|
112
|
+
}
|
|
110
113
|
/**
|
|
111
114
|
* Cut PDF pages.
|
|
112
115
|
* @param pageOptions
|
|
113
116
|
*/
|
|
114
117
|
async applyPageOptions(pageOptions) {
|
|
118
|
+
if (!this.initialized) {
|
|
119
|
+
await this.init();
|
|
120
|
+
}
|
|
115
121
|
if (!(this.fileObject instanceof Buffer)) {
|
|
116
122
|
throw new Error(`Cannot modify an input source of type ${this.inputType}.`);
|
|
117
123
|
}
|
|
@@ -121,7 +127,7 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
121
127
|
/**
|
|
122
128
|
* Cut PDF pages.
|
|
123
129
|
* @param pageOptions
|
|
124
|
-
* @deprecated Deprecated in favor of {@link LocalInputSource.applyPageOptions
|
|
130
|
+
* @deprecated Deprecated in favor of {@link LocalInputSource.applyPageOptions}.
|
|
125
131
|
*/
|
|
126
132
|
async cutPdf(pageOptions) {
|
|
127
133
|
return this.applyPageOptions(pageOptions);
|
|
@@ -139,6 +145,9 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
139
145
|
* @returns A Promise that resolves when the compression is complete.
|
|
140
146
|
*/
|
|
141
147
|
async compress(quality = 85, maxWidth = null, maxHeight = null, forceSourceText = false, disableSourceText = true) {
|
|
148
|
+
if (!this.initialized) {
|
|
149
|
+
await this.init();
|
|
150
|
+
}
|
|
142
151
|
let buffer;
|
|
143
152
|
if (typeof this.fileObject === "string") {
|
|
144
153
|
buffer = Buffer.from(this.fileObject);
|
|
@@ -158,6 +167,9 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
158
167
|
* @return boolean
|
|
159
168
|
*/
|
|
160
169
|
async hasSourceText() {
|
|
170
|
+
if (!this.initialized) {
|
|
171
|
+
await this.init();
|
|
172
|
+
}
|
|
161
173
|
if (!this.isPdf()) {
|
|
162
174
|
return false;
|
|
163
175
|
}
|
|
@@ -22,6 +22,7 @@ class PathInput extends localInputSource_1.LocalInputSource {
|
|
|
22
22
|
logger_1.logger.debug(`Loading from: ${this.inputPath}`);
|
|
23
23
|
this.fileObject = Buffer.from(await fs_1.promises.readFile(this.inputPath));
|
|
24
24
|
this.mimeType = await this.checkMimetype();
|
|
25
|
+
this.initialized = true;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
exports.PathInput = PathInput;
|
|
@@ -15,6 +15,7 @@ class StreamInput extends localInputSource_1.LocalInputSource {
|
|
|
15
15
|
async init() {
|
|
16
16
|
this.fileObject = await this.stream2buffer(this.inputStream);
|
|
17
17
|
this.mimeType = await this.checkMimetype();
|
|
18
|
+
this.initialized = true;
|
|
18
19
|
}
|
|
19
20
|
async stream2buffer(stream) {
|
|
20
21
|
return new Promise((resolve, reject) => {
|
|
@@ -18,6 +18,7 @@ class UrlInput extends inputSource_1.InputSource {
|
|
|
18
18
|
throw new Error("URL must be HTTPS");
|
|
19
19
|
}
|
|
20
20
|
this.fileObject = this.url;
|
|
21
|
+
this.initialized = true;
|
|
21
22
|
}
|
|
22
23
|
async fetchFileContent(options) {
|
|
23
24
|
const { username, password, token, headers = {}, maxRedirects = 3 } = options;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { FieldConfidence } from "./fieldConfidence";
|
|
2
2
|
import { StringDict } from "../../common";
|
|
3
|
+
import { FieldLocation } from "./fieldLocation";
|
|
3
4
|
export declare abstract class BaseField {
|
|
4
5
|
protected _indentLevel: number;
|
|
5
6
|
confidence: FieldConfidence | undefined;
|
|
7
|
+
locations: Array<FieldLocation> | undefined;
|
|
6
8
|
protected constructor(rawResponse: StringDict, indentLevel?: number);
|
|
7
9
|
}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseField = void 0;
|
|
4
|
+
const fieldLocation_1 = require("./fieldLocation");
|
|
4
5
|
class BaseField {
|
|
5
6
|
constructor(rawResponse, indentLevel = 0) {
|
|
6
7
|
this._indentLevel = indentLevel;
|
|
7
|
-
if (rawResponse["confidence"] !==
|
|
8
|
+
if ("confidence" in rawResponse && rawResponse["confidence"] !== null) {
|
|
8
9
|
this.confidence = rawResponse["confidence"];
|
|
9
10
|
}
|
|
11
|
+
if ("locations" in rawResponse && rawResponse["locations"]) {
|
|
12
|
+
this.locations = rawResponse["locations"].map((location) => {
|
|
13
|
+
return location ? new fieldLocation_1.FieldLocation(location) : "";
|
|
14
|
+
});
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
17
|
}
|
|
12
18
|
exports.BaseField = BaseField;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.FieldConfidence = void 0;
|
|
4
5
|
/**
|
|
@@ -6,8 +7,8 @@ exports.FieldConfidence = void 0;
|
|
|
6
7
|
*/
|
|
7
8
|
var FieldConfidence;
|
|
8
9
|
(function (FieldConfidence) {
|
|
9
|
-
FieldConfidence["
|
|
10
|
-
FieldConfidence["
|
|
11
|
-
FieldConfidence["
|
|
12
|
-
FieldConfidence["
|
|
10
|
+
FieldConfidence["Certain"] = "Certain";
|
|
11
|
+
FieldConfidence["High"] = "High";
|
|
12
|
+
FieldConfidence["Medium"] = "Medium";
|
|
13
|
+
FieldConfidence["Low"] = "Low";
|
|
13
14
|
})(FieldConfidence || (exports.FieldConfidence = FieldConfidence = {}));
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FieldLocation = void 0;
|
|
4
|
-
const geometry_1 = require("../../../geometry");
|
|
5
4
|
/**
|
|
6
5
|
* Location of a field.
|
|
7
6
|
*/
|
|
8
7
|
class FieldLocation {
|
|
9
8
|
constructor(serverResponse) {
|
|
10
|
-
this.polygon =
|
|
11
|
-
this.page = "
|
|
12
|
-
typeof serverResponse["page"] === "number" ? serverResponse["page"] : undefined;
|
|
9
|
+
this.polygon = serverResponse["polygon"];
|
|
10
|
+
this.page = "page" in serverResponse ? serverResponse["page"] : undefined;
|
|
13
11
|
}
|
|
14
12
|
toString() {
|
|
15
13
|
return this.polygon?.toString() ?? "";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InferenceFields } from "./inferenceFields";
|
|
2
2
|
import { StringDict } from "../../common";
|
|
3
|
-
import {
|
|
4
|
-
export declare class ObjectField extends
|
|
3
|
+
import { BaseField } from "./baseField";
|
|
4
|
+
export declare class ObjectField extends BaseField {
|
|
5
5
|
readonly fields: InferenceFields;
|
|
6
6
|
constructor(serverResponse: StringDict, indentLevel?: number);
|
|
7
7
|
toString(): string;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObjectField = void 0;
|
|
4
4
|
const inferenceFields_1 = require("./inferenceFields");
|
|
5
|
-
const
|
|
6
|
-
class ObjectField extends
|
|
5
|
+
const baseField_1 = require("./baseField");
|
|
6
|
+
class ObjectField extends baseField_1.BaseField {
|
|
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
1
|
import { StringDict } from "../../common";
|
|
2
|
-
import {
|
|
3
|
-
export declare class SimpleField extends
|
|
2
|
+
import { BaseField } from "./baseField";
|
|
3
|
+
export declare class SimpleField extends BaseField {
|
|
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 baseField_1 = require("./baseField");
|
|
5
|
+
class SimpleField extends baseField_1.BaseField {
|
|
6
6
|
constructor(serverResponse, indentLevel = 0) {
|
|
7
7
|
super(serverResponse, indentLevel);
|
|
8
8
|
this.value =
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
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;
|