mindee 3.5.0 → 3.7.0
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 +63 -39
- package/package.json +3 -3
- package/src/api/{response.d.ts → documentResponse.d.ts} +2 -2
- package/src/api/endpoint.d.ts +32 -5
- package/src/api/endpoint.js +104 -34
- package/src/api/index.d.ts +3 -2
- package/src/api/index.js +5 -3
- package/src/api/predictResponse.d.ts +33 -0
- package/src/api/predictResponse.js +52 -0
- package/src/cli.js +210 -50
- package/src/client.d.ts +20 -4
- package/src/client.js +75 -23
- package/src/documents/custom/fields.js +1 -1
- package/src/documents/custom/lineitems.d.ts +41 -0
- package/src/documents/custom/lineitems.js +127 -0
- package/src/documents/document.d.ts +1 -1
- package/src/documents/documentConfig.d.ts +14 -6
- package/src/documents/documentConfig.js +59 -28
- package/src/documents/eu/licensePlate/licensePlateV1.js +4 -2
- package/src/documents/financialDocument/financialDocumentV0.d.ts +28 -0
- package/src/documents/financialDocument/financialDocumentV0.js +140 -0
- package/src/documents/financialDocument/financialDocumentV1.d.ts +44 -15
- package/src/documents/financialDocument/financialDocumentV1.js +154 -110
- package/src/documents/fr/bankAccountDetails/bankAccountDetailsV1.js +3 -2
- package/src/documents/fr/carteVitale/carteVitaleV1.js +2 -2
- package/src/documents/fr/idCard/idCardV1.js +10 -10
- package/src/documents/index.d.ts +5 -1
- package/src/documents/index.js +10 -2
- package/src/documents/invoice/invoiceV4.d.ts +3 -2
- package/src/documents/invoice/invoiceV4.js +85 -86
- package/src/documents/invoiceSplitter/invoiceSplitterV1.d.ts +3 -3
- package/src/documents/invoiceSplitter/invoiceSplitterV1.js +1 -0
- package/src/documents/mindeeVision/mindeeVisionV1.d.ts +8 -0
- package/src/documents/mindeeVision/mindeeVisionV1.js +29 -0
- package/src/documents/proofOfAddress/proofOfAddressV1.d.ts +24 -0
- package/src/documents/proofOfAddress/proofOfAddressV1.js +77 -0
- package/src/documents/receipt/receiptV3.d.ts +2 -2
- package/src/documents/receipt/receiptV3.js +1 -2
- package/src/documents/receipt/receiptV4.d.ts +3 -4
- package/src/documents/receipt/receiptV4.js +53 -65
- package/src/documents/{shipping_container → shippingContainer}/shippingContainerV1.js +2 -2
- package/src/fields/classification.d.ts +8 -0
- package/src/fields/classification.js +11 -0
- package/src/fields/field.d.ts +2 -2
- package/src/fields/field.js +1 -6
- package/src/fields/index.d.ts +1 -0
- package/src/fields/index.js +3 -1
- package/src/geometry.d.ts +18 -4
- package/src/geometry.js +40 -3
- package/src/index.d.ts +2 -2
- package/src/index.js +3 -1
- package/src/math/index.d.ts +1 -0
- package/src/math/index.js +5 -0
- package/src/math/precision.d.ts +1 -0
- package/src/math/precision.js +13 -0
- /package/src/api/{response.js → documentResponse.js} +0 -0
- /package/src/documents/{shipping_container → shippingContainer}/shippingContainerV1.d.ts +0 -0
package/src/cli.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.cli = void 0;
|
|
4
27
|
const commander_1 = require("commander");
|
|
@@ -6,113 +29,150 @@ const documents_1 = require("./documents");
|
|
|
6
29
|
const api_1 = require("./api");
|
|
7
30
|
const client_1 = require("./client");
|
|
8
31
|
const inputs_1 = require("./inputs");
|
|
32
|
+
const console = __importStar(require("console"));
|
|
9
33
|
const program = new commander_1.Command();
|
|
10
34
|
const COMMAND_CUSTOM = "custom";
|
|
35
|
+
//
|
|
36
|
+
// PRODUCT CONFIGURATION
|
|
37
|
+
//
|
|
11
38
|
// The Map's key is the command name as it will appear on the console.
|
|
12
39
|
//
|
|
13
40
|
const CLI_COMMAND_CONFIG = new Map([
|
|
14
41
|
[
|
|
15
42
|
COMMAND_CUSTOM,
|
|
16
43
|
{
|
|
17
|
-
|
|
44
|
+
displayName: "Custom Document",
|
|
18
45
|
docClass: documents_1.CustomV1,
|
|
19
46
|
fullText: false,
|
|
47
|
+
async: false,
|
|
48
|
+
sync: true,
|
|
20
49
|
},
|
|
21
50
|
],
|
|
22
51
|
[
|
|
23
52
|
"invoice",
|
|
24
53
|
{
|
|
25
|
-
|
|
54
|
+
displayName: "Invoice",
|
|
26
55
|
docClass: documents_1.InvoiceV4,
|
|
27
56
|
fullText: true,
|
|
57
|
+
async: false,
|
|
58
|
+
sync: true,
|
|
28
59
|
},
|
|
29
60
|
],
|
|
30
61
|
[
|
|
31
62
|
"invoice-splitter",
|
|
32
63
|
{
|
|
33
|
-
|
|
64
|
+
displayName: "Invoice Splitter",
|
|
34
65
|
docClass: documents_1.InvoiceSplitterV1,
|
|
35
66
|
fullText: false,
|
|
67
|
+
async: true,
|
|
68
|
+
sync: false,
|
|
36
69
|
},
|
|
37
70
|
],
|
|
38
71
|
[
|
|
39
72
|
"receipt",
|
|
40
73
|
{
|
|
41
|
-
|
|
74
|
+
displayName: "Expense Receipt",
|
|
42
75
|
docClass: documents_1.ReceiptV4,
|
|
43
76
|
fullText: true,
|
|
77
|
+
async: false,
|
|
78
|
+
sync: true,
|
|
44
79
|
},
|
|
45
80
|
],
|
|
46
81
|
[
|
|
47
82
|
"passport",
|
|
48
83
|
{
|
|
49
|
-
|
|
84
|
+
displayName: "Passport",
|
|
50
85
|
docClass: documents_1.PassportV1,
|
|
51
86
|
fullText: false,
|
|
87
|
+
async: false,
|
|
88
|
+
sync: true,
|
|
52
89
|
},
|
|
53
90
|
],
|
|
54
91
|
[
|
|
55
92
|
"financial",
|
|
56
93
|
{
|
|
57
|
-
|
|
94
|
+
displayName: "Financial Document",
|
|
58
95
|
docClass: documents_1.FinancialDocumentV1,
|
|
59
96
|
fullText: true,
|
|
97
|
+
async: false,
|
|
98
|
+
sync: true,
|
|
60
99
|
},
|
|
61
100
|
],
|
|
62
101
|
[
|
|
63
102
|
"fr-id-card",
|
|
64
103
|
{
|
|
65
|
-
|
|
104
|
+
displayName: "FR ID Card",
|
|
66
105
|
docClass: documents_1.fr.IdCardV1,
|
|
67
106
|
fullText: false,
|
|
107
|
+
async: false,
|
|
108
|
+
sync: true,
|
|
68
109
|
},
|
|
69
110
|
],
|
|
70
111
|
[
|
|
71
112
|
"fr-bank-account-details",
|
|
72
113
|
{
|
|
73
|
-
|
|
114
|
+
displayName: "FR Bank Account Details",
|
|
74
115
|
docClass: documents_1.fr.BankAccountDetailsV1,
|
|
75
116
|
fullText: false,
|
|
117
|
+
async: false,
|
|
118
|
+
sync: true,
|
|
76
119
|
},
|
|
77
120
|
],
|
|
78
121
|
[
|
|
79
122
|
"fr-carte-vitale",
|
|
80
123
|
{
|
|
81
|
-
|
|
124
|
+
displayName: "FR Carte Vitale",
|
|
82
125
|
docClass: documents_1.fr.CarteVitaleV1,
|
|
83
126
|
fullText: false,
|
|
127
|
+
async: false,
|
|
128
|
+
sync: true,
|
|
84
129
|
},
|
|
85
130
|
],
|
|
86
131
|
[
|
|
87
132
|
"eu-license-plate",
|
|
88
133
|
{
|
|
89
|
-
|
|
134
|
+
displayName: "EU License Plate",
|
|
90
135
|
docClass: documents_1.eu.LicensePlateV1,
|
|
91
136
|
fullText: false,
|
|
137
|
+
async: false,
|
|
138
|
+
sync: true,
|
|
92
139
|
},
|
|
93
140
|
],
|
|
94
141
|
[
|
|
95
142
|
"us-bank-check",
|
|
96
143
|
{
|
|
97
|
-
|
|
144
|
+
displayName: "US Bank Check",
|
|
98
145
|
docClass: documents_1.us.BankCheckV1,
|
|
99
146
|
fullText: false,
|
|
147
|
+
async: false,
|
|
148
|
+
sync: true,
|
|
100
149
|
},
|
|
101
150
|
],
|
|
102
151
|
[
|
|
103
152
|
"shipping-container",
|
|
104
153
|
{
|
|
105
|
-
|
|
154
|
+
displayName: "Shipping Container",
|
|
106
155
|
docClass: documents_1.ShippingContainerV1,
|
|
107
156
|
fullText: false,
|
|
157
|
+
async: false,
|
|
158
|
+
sync: true,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
[
|
|
162
|
+
"mvision",
|
|
163
|
+
{
|
|
164
|
+
displayName: "Mindee Vision",
|
|
165
|
+
docClass: documents_1.MindeeVisionV1,
|
|
166
|
+
fullText: false,
|
|
167
|
+
async: false,
|
|
168
|
+
sync: true,
|
|
108
169
|
},
|
|
109
170
|
],
|
|
110
171
|
]);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
172
|
+
//
|
|
173
|
+
// EXECUTE THE COMMANDS
|
|
174
|
+
//
|
|
175
|
+
function initClient(command, options) {
|
|
116
176
|
const mindeeClient = new client_1.Client({
|
|
117
177
|
apiKey: options.apiKey,
|
|
118
178
|
debug: options.debug,
|
|
@@ -123,7 +183,16 @@ async function predictCall(command, inputPath, options) {
|
|
|
123
183
|
endpointName: options.documentType,
|
|
124
184
|
});
|
|
125
185
|
}
|
|
126
|
-
|
|
186
|
+
return mindeeClient;
|
|
187
|
+
}
|
|
188
|
+
function getConfig(command) {
|
|
189
|
+
const conf = CLI_COMMAND_CONFIG.get(command);
|
|
190
|
+
if (conf === undefined) {
|
|
191
|
+
throw new Error(`Invalid document type ${command}`);
|
|
192
|
+
}
|
|
193
|
+
return conf;
|
|
194
|
+
}
|
|
195
|
+
function getPredictParams(command, options, conf) {
|
|
127
196
|
let pageOptions = undefined;
|
|
128
197
|
if (options.cutPages) {
|
|
129
198
|
pageOptions = {
|
|
@@ -138,7 +207,38 @@ async function predictCall(command, inputPath, options) {
|
|
|
138
207
|
fullText: options.fullText,
|
|
139
208
|
pageOptions: pageOptions,
|
|
140
209
|
};
|
|
210
|
+
return predictParams;
|
|
211
|
+
}
|
|
212
|
+
async function callParse(command, inputPath, options) {
|
|
213
|
+
const conf = getConfig(command);
|
|
214
|
+
const mindeeClient = initClient(command, options);
|
|
215
|
+
const predictParams = getPredictParams(command, options, conf);
|
|
216
|
+
const doc = mindeeClient.docFromPath(inputPath);
|
|
141
217
|
const response = await doc.parse(conf.docClass, predictParams);
|
|
218
|
+
printResponse(response, options);
|
|
219
|
+
}
|
|
220
|
+
async function callEnqueue(command, inputPath, options) {
|
|
221
|
+
const conf = getConfig(command);
|
|
222
|
+
const mindeeClient = initClient(command, options);
|
|
223
|
+
const predictParams = getPredictParams(command, options, conf);
|
|
224
|
+
const doc = mindeeClient.docFromPath(inputPath);
|
|
225
|
+
const response = await doc.enqueue(conf.docClass, predictParams);
|
|
226
|
+
console.log(response.job);
|
|
227
|
+
}
|
|
228
|
+
async function callParseQueued(command, inputPath, options) {
|
|
229
|
+
const conf = getConfig(command);
|
|
230
|
+
const mindeeClient = initClient(command, options);
|
|
231
|
+
const predictParams = getPredictParams(command, options, conf);
|
|
232
|
+
const doc = mindeeClient.docForAsync();
|
|
233
|
+
const response = await doc.parseQueued(conf.docClass, predictParams, inputPath);
|
|
234
|
+
if (response.document !== undefined) {
|
|
235
|
+
printResponse(response.document, options);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
console.log(response);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function printResponse(response, options) {
|
|
142
242
|
if (options.fullText) {
|
|
143
243
|
response.pages.forEach((page) => {
|
|
144
244
|
console.log(page.fullText?.toString());
|
|
@@ -153,43 +253,103 @@ async function predictCall(command, inputPath, options) {
|
|
|
153
253
|
console.log(`\n${response.document}`);
|
|
154
254
|
}
|
|
155
255
|
}
|
|
256
|
+
//
|
|
257
|
+
// BUILD THE COMMANDS
|
|
258
|
+
//
|
|
259
|
+
function addMainOptions(prog) {
|
|
260
|
+
prog.option("-k, --api-key <api_key>", "API key for document endpoint");
|
|
261
|
+
}
|
|
262
|
+
function addPostOptions(prog, info) {
|
|
263
|
+
prog.option("-c, --cut-pages", "keep only the first 5 pages of the document");
|
|
264
|
+
if (info.fullText) {
|
|
265
|
+
prog.option("-t, --full-text", "include full document text in response");
|
|
266
|
+
}
|
|
267
|
+
prog.argument("<input_path>", "full path to the file");
|
|
268
|
+
}
|
|
269
|
+
function addCustomPostOptions(prog) {
|
|
270
|
+
prog.requiredOption("-e, --endpoint <endpoint_name>", "API endpoint name (required)");
|
|
271
|
+
prog.requiredOption("-a, --account <account_name>", "API account name for the endpoint (required)");
|
|
272
|
+
prog.option("-v, --version <version>", "version for the endpoint, use the latest version if not specified");
|
|
273
|
+
}
|
|
274
|
+
function addDisplayOptions(prog) {
|
|
275
|
+
prog.option("-p, --pages", "show content of individual pages");
|
|
276
|
+
}
|
|
277
|
+
function routeSwitchboard(command, inputPath, allOptions) {
|
|
278
|
+
switch (command.parent?.name()) {
|
|
279
|
+
case "parse": {
|
|
280
|
+
return callParse(command.name(), inputPath, allOptions);
|
|
281
|
+
}
|
|
282
|
+
case "enqueue": {
|
|
283
|
+
return callEnqueue(command.name(), inputPath, allOptions);
|
|
284
|
+
}
|
|
285
|
+
case "parse-queued": {
|
|
286
|
+
return callParseQueued(command.name(), inputPath, allOptions);
|
|
287
|
+
}
|
|
288
|
+
default: {
|
|
289
|
+
throw new Error("Unhandled parent command.");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function addAction(prog) {
|
|
294
|
+
if (prog.name() === COMMAND_CUSTOM) {
|
|
295
|
+
prog.action(function (inputPath, options, command) {
|
|
296
|
+
const allOptions = {
|
|
297
|
+
...program.opts(),
|
|
298
|
+
...options,
|
|
299
|
+
};
|
|
300
|
+
return routeSwitchboard(command, inputPath, allOptions);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
prog.action(function (inputPath, options, command) {
|
|
305
|
+
const allOptions = {
|
|
306
|
+
...program.opts(),
|
|
307
|
+
...options,
|
|
308
|
+
};
|
|
309
|
+
return routeSwitchboard(command, inputPath, allOptions);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
156
313
|
function cli() {
|
|
157
314
|
program.name("mindee");
|
|
158
315
|
program.option("-d, --debug", "high verbosity mode");
|
|
316
|
+
const predict = program.command("parse").description("Parse synchronously.");
|
|
317
|
+
addMainOptions(predict);
|
|
318
|
+
const enqueue = program
|
|
319
|
+
.command("enqueue")
|
|
320
|
+
.description("Add to async parse queue.");
|
|
321
|
+
addMainOptions(enqueue);
|
|
322
|
+
const parseQueued = program
|
|
323
|
+
.command("parse-queued")
|
|
324
|
+
.description("Parse from async queue.");
|
|
325
|
+
addMainOptions(parseQueued);
|
|
159
326
|
CLI_COMMAND_CONFIG.forEach((info, name) => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
prog
|
|
170
|
-
prog.option("-v, --version <version>", "Version for the endpoint, use the latest version if not specified.");
|
|
171
|
-
prog.argument("<endpoint_name>", "API endpoint name");
|
|
172
|
-
}
|
|
173
|
-
prog.argument("<input_path>", "Full path to the file");
|
|
174
|
-
if (name === COMMAND_CUSTOM) {
|
|
175
|
-
prog.action((endpointName, inputPath, options, command) => {
|
|
176
|
-
const allOptions = {
|
|
177
|
-
...program.opts(),
|
|
178
|
-
...options,
|
|
179
|
-
documentType: endpointName,
|
|
180
|
-
};
|
|
181
|
-
predictCall(command.name(), inputPath, allOptions);
|
|
182
|
-
});
|
|
327
|
+
if (info.sync) {
|
|
328
|
+
const prog = predict
|
|
329
|
+
.command(name)
|
|
330
|
+
.description(`Parse an ${info.displayName}.`);
|
|
331
|
+
if (name === COMMAND_CUSTOM) {
|
|
332
|
+
addCustomPostOptions(prog);
|
|
333
|
+
}
|
|
334
|
+
addDisplayOptions(prog);
|
|
335
|
+
addPostOptions(prog, info);
|
|
336
|
+
addAction(prog);
|
|
183
337
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
338
|
+
if (info.async) {
|
|
339
|
+
const progEnqueue = enqueue
|
|
340
|
+
.command(name)
|
|
341
|
+
.description(`Add an ${info.displayName} to the queue.`);
|
|
342
|
+
if (name === COMMAND_CUSTOM) {
|
|
343
|
+
addCustomPostOptions(progEnqueue);
|
|
344
|
+
}
|
|
345
|
+
addPostOptions(progEnqueue, info);
|
|
346
|
+
addAction(progEnqueue);
|
|
347
|
+
const progParse = parseQueued
|
|
348
|
+
.command(name)
|
|
349
|
+
.description(`Parse an ${info.displayName} from the queue.`)
|
|
350
|
+
.argument("<doc_id>", "ID of the document");
|
|
351
|
+
addDisplayOptions(progParse);
|
|
352
|
+
addAction(progParse);
|
|
193
353
|
}
|
|
194
354
|
});
|
|
195
355
|
program.parse(process.argv);
|
package/src/client.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { Readable } from "stream";
|
|
4
4
|
import { InputSource, PageOptions } from "./inputs";
|
|
5
|
-
import { Response } from "./api";
|
|
5
|
+
import { Response, AsyncPredictResponse } from "./api";
|
|
6
6
|
import { Document, DocumentSig } from "./documents";
|
|
7
7
|
import { DocumentConfig } from "./documents/documentConfig";
|
|
8
8
|
type DocConfigs = Map<string[], DocumentConfig<any>>;
|
|
@@ -41,15 +41,27 @@ export interface PredictOptions {
|
|
|
41
41
|
pageOptions?: PageOptions;
|
|
42
42
|
}
|
|
43
43
|
declare class DocumentClient {
|
|
44
|
-
inputSource: InputSource;
|
|
45
44
|
docConfigs: DocConfigs;
|
|
46
|
-
|
|
45
|
+
inputSource?: InputSource;
|
|
46
|
+
constructor(docConfigs: DocConfigs, inputSource?: InputSource);
|
|
47
47
|
/**
|
|
48
|
-
* Send a document to
|
|
48
|
+
* Send a document to a synchronous endpoint and parse the predictions.
|
|
49
49
|
* @param documentClass
|
|
50
50
|
* @param params
|
|
51
51
|
*/
|
|
52
52
|
parse<DocType extends Document>(documentClass: DocumentSig<DocType>, params?: PredictOptions): Promise<Response<DocType>>;
|
|
53
|
+
/**
|
|
54
|
+
* Send the document to an asynchronous endpoint and return its ID in the queue.
|
|
55
|
+
* @param documentClass
|
|
56
|
+
* @param params
|
|
57
|
+
*/
|
|
58
|
+
enqueue<DocType extends Document>(documentClass: DocumentSig<DocType>, params?: PredictOptions): Promise<AsyncPredictResponse<DocType>>;
|
|
59
|
+
parseQueued<DocType extends Document>(documentClass: DocumentSig<DocType>, params: {
|
|
60
|
+
endpointName?: string | undefined;
|
|
61
|
+
accountName?: string | undefined;
|
|
62
|
+
} | undefined, queueId: string): Promise<AsyncPredictResponse<DocType>>;
|
|
63
|
+
protected getBooleanParam(param?: boolean): boolean;
|
|
64
|
+
protected getDocConfig<DocType extends Document>(documentClass: DocumentSig<DocType>, endpointName?: string, accountName?: string): DocumentConfig<DocType>;
|
|
53
65
|
}
|
|
54
66
|
export interface CustomConfigParams {
|
|
55
67
|
/** Your organization's username on the API Builder. */
|
|
@@ -122,5 +134,9 @@ export declare class Client {
|
|
|
122
134
|
* @param filename
|
|
123
135
|
*/
|
|
124
136
|
docFromBuffer(buffer: Buffer, filename: string): DocumentClient;
|
|
137
|
+
/**
|
|
138
|
+
* Load an empty input document from an asynchronous call.
|
|
139
|
+
*/
|
|
140
|
+
docForAsync(): DocumentClient;
|
|
125
141
|
}
|
|
126
142
|
export {};
|
package/src/client.js
CHANGED
|
@@ -8,12 +8,12 @@ const documentConfig_1 = require("./documents/documentConfig");
|
|
|
8
8
|
const handler_1 = require("./errors/handler");
|
|
9
9
|
const logger_1 = require("./logger");
|
|
10
10
|
class DocumentClient {
|
|
11
|
-
constructor(
|
|
11
|
+
constructor(docConfigs, inputSource) {
|
|
12
12
|
this.inputSource = inputSource;
|
|
13
13
|
this.docConfigs = docConfigs;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Send a document to
|
|
16
|
+
* Send a document to a synchronous endpoint and parse the predictions.
|
|
17
17
|
* @param documentClass
|
|
18
18
|
* @param params
|
|
19
19
|
*/
|
|
@@ -24,12 +24,54 @@ class DocumentClient {
|
|
|
24
24
|
cropper: false,
|
|
25
25
|
pageOptions: undefined,
|
|
26
26
|
}) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const docConfig = this.getDocConfig(documentClass, params.endpointName, params.accountName);
|
|
28
|
+
if (this.inputSource === undefined) {
|
|
29
|
+
throw new Error("The 'parse' function requires an input document.");
|
|
30
|
+
}
|
|
31
|
+
return await docConfig.predict({
|
|
32
|
+
inputDoc: this.inputSource,
|
|
33
|
+
includeWords: this.getBooleanParam(params.fullText),
|
|
34
|
+
pageOptions: params.pageOptions,
|
|
35
|
+
cropper: this.getBooleanParam(params.cropper),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Send the document to an asynchronous endpoint and return its ID in the queue.
|
|
40
|
+
* @param documentClass
|
|
41
|
+
* @param params
|
|
42
|
+
*/
|
|
43
|
+
async enqueue(documentClass, params = {
|
|
44
|
+
endpointName: "",
|
|
45
|
+
accountName: "",
|
|
46
|
+
fullText: false,
|
|
47
|
+
cropper: false,
|
|
48
|
+
pageOptions: undefined,
|
|
49
|
+
}) {
|
|
50
|
+
const docConfig = this.getDocConfig(documentClass, params.endpointName, params.accountName);
|
|
51
|
+
if (this.inputSource === undefined) {
|
|
52
|
+
throw new Error("The 'enqueue' function requires an input document.");
|
|
53
|
+
}
|
|
54
|
+
return await docConfig.asyncPredict({
|
|
55
|
+
inputDoc: this.inputSource,
|
|
56
|
+
includeWords: this.getBooleanParam(params.fullText),
|
|
57
|
+
pageOptions: params.pageOptions,
|
|
58
|
+
cropper: this.getBooleanParam(params.cropper),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async parseQueued(documentClass, params = {
|
|
62
|
+
endpointName: "",
|
|
63
|
+
accountName: "",
|
|
64
|
+
}, queueId) {
|
|
65
|
+
const docConfig = this.getDocConfig(documentClass, params.endpointName, params.accountName);
|
|
66
|
+
return await docConfig.getQueuedDocument(queueId);
|
|
67
|
+
}
|
|
68
|
+
getBooleanParam(param) {
|
|
69
|
+
return param !== undefined ? param : false;
|
|
70
|
+
}
|
|
71
|
+
getDocConfig(documentClass, endpointName, accountName) {
|
|
72
|
+
const docType = endpointName === undefined || endpointName === ""
|
|
31
73
|
? documentClass.name
|
|
32
|
-
:
|
|
74
|
+
: endpointName;
|
|
33
75
|
const found = [];
|
|
34
76
|
this.docConfigs.forEach((config, configKey) => {
|
|
35
77
|
if (configKey[1] === docType) {
|
|
@@ -43,20 +85,15 @@ class DocumentClient {
|
|
|
43
85
|
if (found.length === 1) {
|
|
44
86
|
configKey = found[0];
|
|
45
87
|
}
|
|
46
|
-
else if (
|
|
47
|
-
configKey = [
|
|
88
|
+
else if (accountName) {
|
|
89
|
+
configKey = [accountName, docType];
|
|
48
90
|
}
|
|
49
91
|
const docConfig = this.docConfigs.get(configKey);
|
|
50
92
|
if (docConfig === undefined) {
|
|
51
93
|
// TODO: raise error printing all usernames
|
|
52
94
|
throw `Couldn't find the config '${configKey}'`;
|
|
53
95
|
}
|
|
54
|
-
return
|
|
55
|
-
inputDoc: this.inputSource,
|
|
56
|
-
includeWords: fullText,
|
|
57
|
-
pageOptions: params.pageOptions,
|
|
58
|
-
cropper: cropper,
|
|
59
|
-
});
|
|
96
|
+
return docConfig;
|
|
60
97
|
}
|
|
61
98
|
}
|
|
62
99
|
/**
|
|
@@ -79,7 +116,10 @@ class Client {
|
|
|
79
116
|
}
|
|
80
117
|
// TODO: init only those endpoints we actually need.
|
|
81
118
|
addStandardEndpoints() {
|
|
82
|
-
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.
|
|
119
|
+
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.FinancialDocumentV0.name], new documentConfig_1.FinancialDocV0Config(this.apiKey));
|
|
120
|
+
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.FinancialDocumentV1.name], new documentConfig_1.DocumentConfig(documents_1.FinancialDocumentV1, [
|
|
121
|
+
new api_1.StandardEndpoint("financial_document", "1", this.apiKey),
|
|
122
|
+
]));
|
|
83
123
|
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.InvoiceV3.name], new documentConfig_1.DocumentConfig(documents_1.InvoiceV3, [
|
|
84
124
|
new api_1.StandardEndpoint("invoices", "3", this.apiKey),
|
|
85
125
|
]));
|
|
@@ -87,7 +127,7 @@ class Client {
|
|
|
87
127
|
new api_1.StandardEndpoint("invoices", "4", this.apiKey),
|
|
88
128
|
]));
|
|
89
129
|
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.InvoiceSplitterV1.name], new documentConfig_1.DocumentConfig(documents_1.InvoiceSplitterV1, [
|
|
90
|
-
new api_1.StandardEndpoint("
|
|
130
|
+
new api_1.StandardEndpoint("invoice_splitter_async_beta", "1", this.apiKey),
|
|
91
131
|
]));
|
|
92
132
|
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ReceiptV3.name], new documentConfig_1.DocumentConfig(documents_1.ReceiptV3, [
|
|
93
133
|
new api_1.StandardEndpoint("expense_receipts", "3", this.apiKey),
|
|
@@ -119,6 +159,12 @@ class Client {
|
|
|
119
159
|
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ShippingContainerV1.name], new documentConfig_1.DocumentConfig(documents_1.ShippingContainerV1, [
|
|
120
160
|
new api_1.StandardEndpoint("shipping_containers", "1", this.apiKey),
|
|
121
161
|
]));
|
|
162
|
+
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.MindeeVisionV1.name], new documentConfig_1.DocumentConfig(documents_1.MindeeVisionV1, [
|
|
163
|
+
new api_1.StandardEndpoint("mindee_vision", "1", this.apiKey),
|
|
164
|
+
]));
|
|
165
|
+
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ProofOfAddressV1.name], new documentConfig_1.DocumentConfig(documents_1.ProofOfAddressV1, [
|
|
166
|
+
new api_1.StandardEndpoint("proof_of_address", "1", this.apiKey),
|
|
167
|
+
]));
|
|
122
168
|
}
|
|
123
169
|
/**
|
|
124
170
|
* Add a custom endpoint to the client.
|
|
@@ -143,7 +189,7 @@ class Client {
|
|
|
143
189
|
const doc = new inputs_1.PathInput({
|
|
144
190
|
inputPath: inputPath,
|
|
145
191
|
});
|
|
146
|
-
return new DocumentClient(
|
|
192
|
+
return new DocumentClient(this.docConfigs, doc);
|
|
147
193
|
}
|
|
148
194
|
/**
|
|
149
195
|
* Load an input document from a base64 encoded string.
|
|
@@ -155,7 +201,7 @@ class Client {
|
|
|
155
201
|
inputString: inputString,
|
|
156
202
|
filename: filename,
|
|
157
203
|
});
|
|
158
|
-
return new DocumentClient(
|
|
204
|
+
return new DocumentClient(this.docConfigs, doc);
|
|
159
205
|
}
|
|
160
206
|
/**
|
|
161
207
|
* Load an input document from a `stream.Readable` object.
|
|
@@ -167,7 +213,7 @@ class Client {
|
|
|
167
213
|
inputStream: inputStream,
|
|
168
214
|
filename: filename,
|
|
169
215
|
});
|
|
170
|
-
return new DocumentClient(
|
|
216
|
+
return new DocumentClient(this.docConfigs, doc);
|
|
171
217
|
}
|
|
172
218
|
/**
|
|
173
219
|
* Load an input document from a bytes string.
|
|
@@ -179,7 +225,7 @@ class Client {
|
|
|
179
225
|
inputBytes: inputBytes,
|
|
180
226
|
filename: filename,
|
|
181
227
|
});
|
|
182
|
-
return new DocumentClient(
|
|
228
|
+
return new DocumentClient(this.docConfigs, doc);
|
|
183
229
|
}
|
|
184
230
|
/**
|
|
185
231
|
* Load an input document from a URL.
|
|
@@ -189,7 +235,7 @@ class Client {
|
|
|
189
235
|
const doc = new inputs_1.UrlInput({
|
|
190
236
|
url: url,
|
|
191
237
|
});
|
|
192
|
-
return new DocumentClient(
|
|
238
|
+
return new DocumentClient(this.docConfigs, doc);
|
|
193
239
|
}
|
|
194
240
|
/**
|
|
195
241
|
* Load an input document from a Buffer.
|
|
@@ -201,7 +247,13 @@ class Client {
|
|
|
201
247
|
buffer: buffer,
|
|
202
248
|
filename: filename,
|
|
203
249
|
});
|
|
204
|
-
return new DocumentClient(
|
|
250
|
+
return new DocumentClient(this.docConfigs, doc);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Load an empty input document from an asynchronous call.
|
|
254
|
+
*/
|
|
255
|
+
docForAsync() {
|
|
256
|
+
return new DocumentClient(this.docConfigs);
|
|
205
257
|
}
|
|
206
258
|
}
|
|
207
259
|
exports.Client = Client;
|
|
@@ -28,7 +28,7 @@ class ListFieldValue {
|
|
|
28
28
|
this.confidence = prediction["confidence"];
|
|
29
29
|
if (prediction["polygon"]) {
|
|
30
30
|
this.polygon = prediction["polygon"];
|
|
31
|
-
this.bbox = (0, geometry_1.
|
|
31
|
+
this.bbox = (0, geometry_1.getBoundingBox)(prediction.polygon);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
toString() {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BBox, Polygon } from "../../geometry";
|
|
2
|
+
import { ListField, ListFieldValue } from "./fields";
|
|
3
|
+
export declare class Line {
|
|
4
|
+
/**
|
|
5
|
+
* Number of the current line.
|
|
6
|
+
* Starts to 1.
|
|
7
|
+
*/
|
|
8
|
+
rowNumber: number;
|
|
9
|
+
/**
|
|
10
|
+
* List of the fields associated to the current line, identified by their column name.
|
|
11
|
+
*/
|
|
12
|
+
fields: Map<string, ListFieldValue>;
|
|
13
|
+
/**
|
|
14
|
+
* The BBox of the current line.
|
|
15
|
+
*/
|
|
16
|
+
bbox: BBox;
|
|
17
|
+
/**
|
|
18
|
+
* The height tolerance used to build the line.
|
|
19
|
+
* It helps when the higth of an expected line can vary.
|
|
20
|
+
*/
|
|
21
|
+
heightTolerance: number;
|
|
22
|
+
constructor(rowNumber: number, heightTolerance: number);
|
|
23
|
+
/**
|
|
24
|
+
* Extends the current bbox of the line with the bbox.
|
|
25
|
+
*/
|
|
26
|
+
extendWithBbox(bbox: BBox): void;
|
|
27
|
+
/**
|
|
28
|
+
* Extends the current bbox of the line with the polygon.
|
|
29
|
+
*/
|
|
30
|
+
extendWith(polygon: Polygon): void;
|
|
31
|
+
/**
|
|
32
|
+
* Check if the bbox fits the current line.
|
|
33
|
+
*/
|
|
34
|
+
contains(bbox: BBox): boolean;
|
|
35
|
+
updateField(name: string, fieldValue: ListFieldValue): void;
|
|
36
|
+
}
|
|
37
|
+
export declare class LineItems {
|
|
38
|
+
rows: Line[];
|
|
39
|
+
constructor(lines: Line[]);
|
|
40
|
+
}
|
|
41
|
+
export declare function getLineItems(anchorNames: string[], heigthLineTolerance: number, fieldNamesTargeted: string[], fields: Map<string, ListField>): LineItems;
|