mindee 3.6.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +43 -39
  2. package/package.json +1 -1
  3. package/src/api/{response.d.ts → documentResponse.d.ts} +2 -2
  4. package/src/api/endpoint.d.ts +32 -5
  5. package/src/api/endpoint.js +104 -34
  6. package/src/api/index.d.ts +3 -2
  7. package/src/api/index.js +5 -3
  8. package/src/api/predictResponse.d.ts +33 -0
  9. package/src/api/predictResponse.js +52 -0
  10. package/src/cli.js +203 -51
  11. package/src/client.d.ts +20 -4
  12. package/src/client.js +65 -22
  13. package/src/documents/custom/fields.js +1 -1
  14. package/src/documents/custom/lineitems.d.ts +41 -0
  15. package/src/documents/custom/lineitems.js +127 -0
  16. package/src/documents/document.d.ts +1 -1
  17. package/src/documents/documentConfig.d.ts +12 -4
  18. package/src/documents/documentConfig.js +55 -24
  19. package/src/documents/eu/licensePlate/licensePlateV1.js +4 -2
  20. package/src/documents/fr/bankAccountDetails/bankAccountDetailsV1.js +3 -2
  21. package/src/documents/fr/carteVitale/carteVitaleV1.js +2 -2
  22. package/src/documents/fr/idCard/idCardV1.js +10 -10
  23. package/src/documents/index.d.ts +2 -1
  24. package/src/documents/index.js +4 -2
  25. package/src/documents/invoice/invoiceV4.d.ts +2 -2
  26. package/src/documents/invoice/invoiceV4.js +1 -1
  27. package/src/documents/invoiceSplitter/invoiceSplitterV1.d.ts +3 -3
  28. package/src/documents/invoiceSplitter/invoiceSplitterV1.js +1 -0
  29. package/src/documents/proofOfAddress/proofOfAddressV1.js +5 -6
  30. package/src/documents/receipt/receiptV3.d.ts +2 -2
  31. package/src/documents/receipt/receiptV3.js +1 -2
  32. package/src/documents/receipt/receiptV4.d.ts +3 -3
  33. package/src/documents/receipt/receiptV4.js +2 -4
  34. package/src/documents/{shipping_container → shippingContainer}/shippingContainerV1.js +2 -2
  35. package/src/fields/classification.d.ts +8 -0
  36. package/src/fields/classification.js +11 -0
  37. package/src/fields/field.d.ts +2 -2
  38. package/src/fields/field.js +1 -6
  39. package/src/fields/index.d.ts +1 -0
  40. package/src/fields/index.js +3 -1
  41. package/src/geometry.d.ts +18 -4
  42. package/src/geometry.js +40 -3
  43. package/src/index.d.ts +1 -1
  44. package/src/index.js +2 -1
  45. package/src/math/index.d.ts +1 -0
  46. package/src/math/index.js +5 -0
  47. package/src/math/precision.d.ts +1 -0
  48. package/src/math/precision.js +13 -0
  49. /package/src/api/{response.js → documentResponse.js} +0 -0
  50. /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,121 +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
- description: "A custom document",
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
- description: "Invoice",
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
- description: "Invoice Splitter",
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
- description: "Expense Receipt",
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
- description: "Passport",
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
- description: "Financial Document",
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
- description: "FR ID Card",
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
- description: "FR Bank Account Details",
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
- description: "FR Carte Vitale",
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
- description: "EU License Plate",
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
- description: "US Bank Check",
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
- description: "Shipping Container",
154
+ displayName: "Shipping Container",
106
155
  docClass: documents_1.ShippingContainerV1,
107
156
  fullText: false,
157
+ async: false,
158
+ sync: true,
108
159
  },
109
160
  ],
110
161
  [
111
162
  "mvision",
112
163
  {
113
- description: "Mindee Vision",
164
+ displayName: "Mindee Vision",
114
165
  docClass: documents_1.MindeeVisionV1,
115
166
  fullText: false,
167
+ async: false,
168
+ sync: true,
116
169
  },
117
170
  ],
118
171
  ]);
119
- async function predictCall(command, inputPath, options) {
120
- const conf = CLI_COMMAND_CONFIG.get(command);
121
- if (conf === undefined) {
122
- throw new Error(`Invalid document type ${command}`);
123
- }
172
+ //
173
+ // EXECUTE THE COMMANDS
174
+ //
175
+ function initClient(command, options) {
124
176
  const mindeeClient = new client_1.Client({
125
177
  apiKey: options.apiKey,
126
178
  debug: options.debug,
@@ -131,7 +183,16 @@ async function predictCall(command, inputPath, options) {
131
183
  endpointName: options.documentType,
132
184
  });
133
185
  }
134
- const doc = mindeeClient.docFromPath(inputPath);
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) {
135
196
  let pageOptions = undefined;
136
197
  if (options.cutPages) {
137
198
  pageOptions = {
@@ -146,7 +207,38 @@ async function predictCall(command, inputPath, options) {
146
207
  fullText: options.fullText,
147
208
  pageOptions: pageOptions,
148
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);
149
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) {
150
242
  if (options.fullText) {
151
243
  response.pages.forEach((page) => {
152
244
  console.log(page.fullText?.toString());
@@ -161,43 +253,103 @@ async function predictCall(command, inputPath, options) {
161
253
  console.log(`\n${response.document}`);
162
254
  }
163
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
+ }
164
313
  function cli() {
165
314
  program.name("mindee");
166
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);
167
326
  CLI_COMMAND_CONFIG.forEach((info, name) => {
168
- const prog = program.command(name);
169
- prog.description(info.description);
170
- prog.option("-k, --api-key <api_key>", "API key for document endpoint");
171
- prog.option("-c, --cut-pages", "Keep only the first 5 pages of the document.");
172
- prog.option("-p, --pages", "Show pages content");
173
- if (info.fullText) {
174
- prog.option("-t, --full-text", "Include full document text in response");
175
- }
176
- if (name === COMMAND_CUSTOM) {
177
- prog.requiredOption("-u, --user <username>", "API account name for the endpoint");
178
- prog.option("-v, --version <version>", "Version for the endpoint, use the latest version if not specified.");
179
- prog.argument("<endpoint_name>", "API endpoint name");
180
- }
181
- prog.argument("<input_path>", "Full path to the file");
182
- if (name === COMMAND_CUSTOM) {
183
- prog.action((endpointName, inputPath, options, command) => {
184
- const allOptions = {
185
- ...program.opts(),
186
- ...options,
187
- documentType: endpointName,
188
- };
189
- predictCall(command.name(), inputPath, allOptions);
190
- });
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);
191
337
  }
192
- else {
193
- prog.action((inputPath, options, command) => {
194
- const allOptions = {
195
- ...program.opts(),
196
- ...options,
197
- endpointName: undefined,
198
- };
199
- predictCall(command.name(), inputPath, allOptions);
200
- });
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);
201
353
  }
202
354
  });
203
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
- constructor(inputSource: InputSource, docConfigs: DocConfigs);
45
+ inputSource?: InputSource;
46
+ constructor(docConfigs: DocConfigs, inputSource?: InputSource);
47
47
  /**
48
- * Send a document to an endpoint and parse the predictions.
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(inputSource, docConfigs) {
11
+ constructor(docConfigs, inputSource) {
12
12
  this.inputSource = inputSource;
13
13
  this.docConfigs = docConfigs;
14
14
  }
15
15
  /**
16
- * Send a document to an endpoint and parse the predictions.
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
- // seems like there should be a better way of doing this
28
- const fullText = params?.fullText !== undefined ? params.fullText : false;
29
- const cropper = params?.cropper !== undefined ? params.cropper : false;
30
- const docType = params.endpointName === undefined || params.endpointName === ""
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
- : params.endpointName;
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 (params.accountName) {
47
- configKey = [params.accountName, docType];
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 await docConfig.predict({
55
- inputDoc: this.inputSource,
56
- includeWords: fullText,
57
- pageOptions: params.pageOptions,
58
- cropper: cropper,
59
- });
96
+ return docConfig;
60
97
  }
61
98
  }
62
99
  /**
@@ -90,7 +127,7 @@ class Client {
90
127
  new api_1.StandardEndpoint("invoices", "4", this.apiKey),
91
128
  ]));
92
129
  this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.InvoiceSplitterV1.name], new documentConfig_1.DocumentConfig(documents_1.InvoiceSplitterV1, [
93
- new api_1.StandardEndpoint("invoice_splitter_beta", "1", this.apiKey),
130
+ new api_1.StandardEndpoint("invoice_splitter_async_beta", "1", this.apiKey),
94
131
  ]));
95
132
  this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ReceiptV3.name], new documentConfig_1.DocumentConfig(documents_1.ReceiptV3, [
96
133
  new api_1.StandardEndpoint("expense_receipts", "3", this.apiKey),
@@ -152,7 +189,7 @@ class Client {
152
189
  const doc = new inputs_1.PathInput({
153
190
  inputPath: inputPath,
154
191
  });
155
- return new DocumentClient(doc, this.docConfigs);
192
+ return new DocumentClient(this.docConfigs, doc);
156
193
  }
157
194
  /**
158
195
  * Load an input document from a base64 encoded string.
@@ -164,7 +201,7 @@ class Client {
164
201
  inputString: inputString,
165
202
  filename: filename,
166
203
  });
167
- return new DocumentClient(doc, this.docConfigs);
204
+ return new DocumentClient(this.docConfigs, doc);
168
205
  }
169
206
  /**
170
207
  * Load an input document from a `stream.Readable` object.
@@ -176,7 +213,7 @@ class Client {
176
213
  inputStream: inputStream,
177
214
  filename: filename,
178
215
  });
179
- return new DocumentClient(doc, this.docConfigs);
216
+ return new DocumentClient(this.docConfigs, doc);
180
217
  }
181
218
  /**
182
219
  * Load an input document from a bytes string.
@@ -188,7 +225,7 @@ class Client {
188
225
  inputBytes: inputBytes,
189
226
  filename: filename,
190
227
  });
191
- return new DocumentClient(doc, this.docConfigs);
228
+ return new DocumentClient(this.docConfigs, doc);
192
229
  }
193
230
  /**
194
231
  * Load an input document from a URL.
@@ -198,7 +235,7 @@ class Client {
198
235
  const doc = new inputs_1.UrlInput({
199
236
  url: url,
200
237
  });
201
- return new DocumentClient(doc, this.docConfigs);
238
+ return new DocumentClient(this.docConfigs, doc);
202
239
  }
203
240
  /**
204
241
  * Load an input document from a Buffer.
@@ -210,7 +247,13 @@ class Client {
210
247
  buffer: buffer,
211
248
  filename: filename,
212
249
  });
213
- return new DocumentClient(doc, this.docConfigs);
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);
214
257
  }
215
258
  }
216
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.getBboxAsPolygon)(prediction.polygon);
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;