mindee 3.4.0 → 3.5.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 (74) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +5 -0
  3. package/package.json +19 -19
  4. package/src/api/index.d.ts +1 -1
  5. package/src/api/response.d.ts +3 -0
  6. package/src/cli.js +19 -11
  7. package/src/client.d.ts +3 -3
  8. package/src/client.js +4 -1
  9. package/src/documents/{custom.d.ts → custom/customV1.d.ts} +4 -4
  10. package/src/documents/{custom.js → custom/customV1.js} +2 -2
  11. package/src/{fields/apiBuilder.d.ts → documents/custom/fields.d.ts} +8 -6
  12. package/src/{fields/apiBuilder.js → documents/custom/fields.js} +1 -1
  13. package/src/documents/document.d.ts +4 -4
  14. package/src/documents/eu/licensePlate/licensePlateV1.d.ts +3 -3
  15. package/src/documents/eu/licensePlate/licensePlateV1.js +2 -2
  16. package/src/documents/financialDocument/financialDocumentV1.d.ts +9 -9
  17. package/src/documents/financialDocument/financialDocumentV1.js +5 -5
  18. package/src/documents/fr/bankAccountDetails/bankAccountDetailsV1.d.ts +8 -7
  19. package/src/documents/fr/bankAccountDetails/bankAccountDetailsV1.js +4 -3
  20. package/src/documents/fr/carteVitale/carteVitaleV1.d.ts +6 -6
  21. package/src/documents/fr/carteVitale/carteVitaleV1.js +5 -5
  22. package/src/documents/fr/idCard/idCardV1.d.ts +10 -10
  23. package/src/documents/fr/idCard/idCardV1.js +8 -8
  24. package/src/documents/index.d.ts +2 -1
  25. package/src/documents/index.js +6 -3
  26. package/src/documents/invoice/invoiceLineItem.d.ts +2 -2
  27. package/src/documents/invoice/invoiceV3.d.ts +7 -7
  28. package/src/documents/invoice/invoiceV3.js +5 -5
  29. package/src/documents/invoice/invoiceV4.d.ts +7 -9
  30. package/src/documents/invoice/invoiceV4.js +6 -6
  31. package/src/documents/invoice/reconstruction.js +5 -4
  32. package/src/documents/invoiceSplitter/invoiceSplitterV1.d.ts +14 -0
  33. package/src/documents/invoiceSplitter/invoiceSplitterV1.js +46 -0
  34. package/src/documents/passport/passportV1.d.ts +16 -16
  35. package/src/documents/passport/passportV1.js +15 -13
  36. package/src/documents/receipt/receiptV3.d.ts +4 -4
  37. package/src/documents/receipt/receiptV3.js +6 -7
  38. package/src/documents/receipt/receiptV4.d.ts +10 -10
  39. package/src/documents/receipt/receiptV4.js +6 -8
  40. package/src/documents/shipping_container/shippingContainerV1.d.ts +4 -4
  41. package/src/documents/shipping_container/shippingContainerV1.js +3 -3
  42. package/src/documents/us/bankCheck/bankCheckV1.d.ts +8 -8
  43. package/src/documents/us/bankCheck/bankCheckV1.js +4 -4
  44. package/src/fields/amount.d.ts +1 -1
  45. package/src/fields/amount.js +2 -0
  46. package/src/fields/base.d.ts +27 -0
  47. package/src/fields/base.js +53 -0
  48. package/src/fields/companyRegistration.d.ts +3 -1
  49. package/src/fields/date.d.ts +4 -1
  50. package/src/fields/date.js +16 -8
  51. package/src/fields/field.d.ts +8 -38
  52. package/src/fields/field.js +6 -53
  53. package/src/fields/fullText.d.ts +1 -1
  54. package/src/fields/fullText.js +4 -4
  55. package/src/fields/index.d.ts +3 -3
  56. package/src/fields/index.js +5 -8
  57. package/src/fields/locale.d.ts +13 -9
  58. package/src/fields/locale.js +4 -3
  59. package/src/fields/orientation.d.ts +3 -1
  60. package/src/fields/orientation.js +2 -2
  61. package/src/fields/paymentDetails.d.ts +4 -1
  62. package/src/fields/paymentDetails.js +26 -23
  63. package/src/fields/position.d.ts +2 -2
  64. package/src/fields/tax.d.ts +7 -2
  65. package/src/fields/tax.js +10 -1
  66. package/src/fields/text.d.ts +13 -0
  67. package/src/fields/text.js +10 -0
  68. package/src/geometry.d.ts +1 -2
  69. package/src/index.d.ts +4 -3
  70. package/src/index.js +5 -1
  71. package/src/inputs/sources.d.ts +4 -4
  72. package/src/inputs/sources.js +9 -9
  73. package/src/documents/receipt/tax.d.ts +0 -25
  74. package/src/documents/receipt/tax.js +0 -40
@@ -1,9 +1,11 @@
1
+ import { StringDict } from "./base";
1
2
  import { Field } from "./field";
2
3
  interface TaxConstructor {
3
- prediction: any;
4
+ prediction: StringDict;
4
5
  valueKey?: string;
5
6
  rateKey?: string;
6
7
  codeKey?: string;
8
+ baseKey?: string;
7
9
  reconstructed?: boolean;
8
10
  pageId?: number;
9
11
  }
@@ -14,6 +16,8 @@ export declare class TaxField extends Field {
14
16
  rate?: number;
15
17
  /** The tax code (HST, GST... for Canadian; City Tax, State tax for US, etc..). */
16
18
  code?: string;
19
+ /** The tax base */
20
+ base?: number;
17
21
  /** The document page on which the information was found. */
18
22
  pageId: number;
19
23
  /**
@@ -21,10 +25,11 @@ export declare class TaxField extends Field {
21
25
  * @param {String} valueKey - Key to use in the prediction dict to get the tax value
22
26
  * @param {String} rateKey - Key to use to get the tax rate in the prediction dict
23
27
  * @param {String} codeKey - Key to use to get the tax code in the prediction dict
28
+ * @param {String} baseKey - Key to use to get the base tax in the prediction dict
24
29
  * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
25
30
  * @param {Integer} pageNumber - Page ID for multi-page document
26
31
  */
27
- constructor({ prediction, valueKey, rateKey, codeKey, reconstructed, pageId, }: TaxConstructor);
32
+ constructor({ prediction, valueKey, rateKey, codeKey, baseKey, reconstructed, pageId, }: TaxConstructor);
28
33
  toString(): string;
29
34
  }
30
35
  export {};
package/src/fields/tax.js CHANGED
@@ -9,10 +9,11 @@ class TaxField extends field_1.Field {
9
9
  * @param {String} valueKey - Key to use in the prediction dict to get the tax value
10
10
  * @param {String} rateKey - Key to use to get the tax rate in the prediction dict
11
11
  * @param {String} codeKey - Key to use to get the tax code in the prediction dict
12
+ * @param {String} baseKey - Key to use to get the base tax in the prediction dict
12
13
  * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
13
14
  * @param {Integer} pageNumber - Page ID for multi-page document
14
15
  */
15
- constructor({ prediction, valueKey = "value", rateKey = "rate", codeKey = "code", reconstructed = false, pageId = undefined, }) {
16
+ constructor({ prediction, valueKey = "value", rateKey = "rate", codeKey = "code", baseKey = "base", reconstructed = false, pageId = undefined, }) {
16
17
  super({ prediction, valueKey, reconstructed, pageId });
17
18
  /** The tax amount. */
18
19
  this.value = undefined;
@@ -20,6 +21,8 @@ class TaxField extends field_1.Field {
20
21
  this.rate = undefined;
21
22
  /** The tax code (HST, GST... for Canadian; City Tax, State tax for US, etc..). */
22
23
  this.code = undefined;
24
+ /** The tax base */
25
+ this.base = undefined;
23
26
  this.rate = +parseFloat(prediction[rateKey]);
24
27
  if (isNaN(this.rate))
25
28
  this.rate = undefined;
@@ -32,6 +35,9 @@ class TaxField extends field_1.Field {
32
35
  this.value = undefined;
33
36
  this.confidence = 0.0;
34
37
  }
38
+ this.base = parseFloat(prediction[baseKey]);
39
+ if (isNaN(this.base))
40
+ this.base = undefined;
35
41
  }
36
42
  toString() {
37
43
  let outStr = "";
@@ -44,6 +50,9 @@ class TaxField extends field_1.Field {
44
50
  if (this.code !== undefined) {
45
51
  outStr += ` ${this.code}`;
46
52
  }
53
+ if (this.base !== undefined) {
54
+ outStr += ` ${(0, amount_1.floatToString)(this.base)}`;
55
+ }
47
56
  return outStr.trim();
48
57
  }
49
58
  }
@@ -0,0 +1,13 @@
1
+ import { StringDict } from "./base";
2
+ import { Field } from "./field";
3
+ export interface FieldConstructor {
4
+ prediction: StringDict;
5
+ valueKey?: string;
6
+ reconstructed?: boolean;
7
+ pageId?: number | undefined;
8
+ }
9
+ export declare class TextField extends Field {
10
+ /** The value. */
11
+ value?: string;
12
+ constructor({ prediction, valueKey, reconstructed, pageId, }: FieldConstructor);
13
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextField = void 0;
4
+ const field_1 = require("./field");
5
+ class TextField extends field_1.Field {
6
+ constructor({ prediction, valueKey = "value", reconstructed = false, pageId, }) {
7
+ super({ prediction, valueKey, reconstructed, pageId });
8
+ }
9
+ }
10
+ exports.TextField = TextField;
package/src/geometry.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type MinMax = {
1
+ export type MinMax = {
2
2
  min: number;
3
3
  max: number;
4
4
  };
@@ -56,4 +56,3 @@ export declare function isPointInPolygonX(centroid: Point, polygon: Polygon): bo
56
56
  * Can be used to order (sort) words in the same line.
57
57
  */
58
58
  export declare function relativeX(polygon: Polygon): number;
59
- export {};
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export { CustomV1, FinancialDocumentV1, InvoiceV3, InvoiceV4, PassportV1, ReceiptV3, ReceiptV4, CropperV1, ShippingContainerV1, fr, us, eu, } from "./documents";
2
- export { Client, ClientOptions } from "./client";
3
- export { PageOptionsOperation } from "./inputs";
1
+ export { CustomV1, Document, FinancialDocumentV1, InvoiceV3, InvoiceV4, PassportV1, ReceiptV3, ReceiptV4, CropperV1, ShippingContainerV1, fr, us, eu, } from "./documents";
2
+ export { Client, ClientOptions, CustomConfigParams, PredictOptions, } from "./client";
3
+ export { ResponseSig, Response } from "./api";
4
+ export { InputSource, PageOptionsOperation } from "./inputs";
package/src/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PageOptionsOperation = exports.Client = exports.eu = exports.us = exports.fr = exports.ShippingContainerV1 = exports.CropperV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceV4 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.CustomV1 = void 0;
3
+ exports.PageOptionsOperation = exports.InputSource = exports.Response = exports.Client = exports.eu = exports.us = exports.fr = exports.ShippingContainerV1 = exports.CropperV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceV4 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.Document = exports.CustomV1 = void 0;
4
4
  var documents_1 = require("./documents");
5
5
  Object.defineProperty(exports, "CustomV1", { enumerable: true, get: function () { return documents_1.CustomV1; } });
6
+ Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return documents_1.Document; } });
6
7
  Object.defineProperty(exports, "FinancialDocumentV1", { enumerable: true, get: function () { return documents_1.FinancialDocumentV1; } });
7
8
  Object.defineProperty(exports, "InvoiceV3", { enumerable: true, get: function () { return documents_1.InvoiceV3; } });
8
9
  Object.defineProperty(exports, "InvoiceV4", { enumerable: true, get: function () { return documents_1.InvoiceV4; } });
@@ -16,5 +17,8 @@ Object.defineProperty(exports, "us", { enumerable: true, get: function () { retu
16
17
  Object.defineProperty(exports, "eu", { enumerable: true, get: function () { return documents_1.eu; } });
17
18
  var client_1 = require("./client");
18
19
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
20
+ var api_1 = require("./api");
21
+ Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return api_1.Response; } });
19
22
  var inputs_1 = require("./inputs");
23
+ Object.defineProperty(exports, "InputSource", { enumerable: true, get: function () { return inputs_1.InputSource; } });
20
24
  Object.defineProperty(exports, "PageOptionsOperation", { enumerable: true, get: function () { return inputs_1.PageOptionsOperation; } });
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { ReadStream } from "fs";
4
- import { Buffer } from "node:buffer";
3
+ import { Readable } from "stream";
4
+ import { Buffer } from "buffer";
5
5
  import { InputSource } from "./base";
6
6
  interface PathInputProps {
7
7
  inputPath: string;
@@ -23,7 +23,7 @@ export declare class Base64Input extends InputSource {
23
23
  init(): Promise<void>;
24
24
  }
25
25
  interface StreamInputProps {
26
- inputStream: ReadStream;
26
+ inputStream: Readable;
27
27
  filename: string;
28
28
  }
29
29
  export declare class StreamInput extends InputSource {
@@ -31,7 +31,7 @@ export declare class StreamInput extends InputSource {
31
31
  fileObject: Buffer;
32
32
  constructor({ inputStream, filename }: StreamInputProps);
33
33
  init(): Promise<void>;
34
- stream2buffer(stream: ReadStream): Promise<Buffer>;
34
+ stream2buffer(stream: Readable): Promise<Buffer>;
35
35
  }
36
36
  interface BytesInputProps {
37
37
  inputBytes: string;
@@ -27,7 +27,7 @@ exports.BufferInput = exports.UrlInput = exports.BytesInput = exports.StreamInpu
27
27
  const fs_1 = require("fs");
28
28
  const path = __importStar(require("path"));
29
29
  const handler_1 = require("../errors/handler");
30
- const node_buffer_1 = require("node:buffer");
30
+ const buffer_1 = require("buffer");
31
31
  const logger_1 = require("../logger");
32
32
  const base_1 = require("./base");
33
33
  class PathInput extends base_1.InputSource {
@@ -35,13 +35,13 @@ class PathInput extends base_1.InputSource {
35
35
  super({
36
36
  inputType: base_1.INPUT_TYPE_PATH,
37
37
  });
38
- this.fileObject = node_buffer_1.Buffer.alloc(0);
38
+ this.fileObject = buffer_1.Buffer.alloc(0);
39
39
  this.inputPath = inputPath;
40
40
  this.filename = path.basename(this.inputPath);
41
41
  }
42
42
  async init() {
43
43
  logger_1.logger.debug(`Loading from: ${this.inputPath}`);
44
- this.fileObject = node_buffer_1.Buffer.from(await fs_1.promises.readFile(this.inputPath));
44
+ this.fileObject = buffer_1.Buffer.from(await fs_1.promises.readFile(this.inputPath));
45
45
  this.mimeType = await this.checkMimetype();
46
46
  }
47
47
  }
@@ -51,12 +51,12 @@ class Base64Input extends base_1.InputSource {
51
51
  super({
52
52
  inputType: base_1.INPUT_TYPE_BASE64,
53
53
  });
54
- this.fileObject = node_buffer_1.Buffer.alloc(0);
54
+ this.fileObject = buffer_1.Buffer.alloc(0);
55
55
  this.filename = filename;
56
56
  this.inputString = inputString;
57
57
  }
58
58
  async init() {
59
- this.fileObject = node_buffer_1.Buffer.from(this.inputString, "base64");
59
+ this.fileObject = buffer_1.Buffer.from(this.inputString, "base64");
60
60
  this.mimeType = await this.checkMimetype();
61
61
  // clear out the string
62
62
  this.inputString = "";
@@ -68,7 +68,7 @@ class StreamInput extends base_1.InputSource {
68
68
  super({
69
69
  inputType: base_1.INPUT_TYPE_STREAM,
70
70
  });
71
- this.fileObject = node_buffer_1.Buffer.alloc(0);
71
+ this.fileObject = buffer_1.Buffer.alloc(0);
72
72
  this.filename = filename;
73
73
  this.inputStream = inputStream;
74
74
  }
@@ -80,7 +80,7 @@ class StreamInput extends base_1.InputSource {
80
80
  return new Promise((resolve, reject) => {
81
81
  const _buf = Array();
82
82
  stream.on("data", (chunk) => _buf.push(chunk));
83
- stream.on("end", () => resolve(node_buffer_1.Buffer.concat(_buf)));
83
+ stream.on("end", () => resolve(buffer_1.Buffer.concat(_buf)));
84
84
  stream.on("error", (err) => reject(`Error converting stream - ${err}`));
85
85
  });
86
86
  }
@@ -91,12 +91,12 @@ class BytesInput extends base_1.InputSource {
91
91
  super({
92
92
  inputType: base_1.INPUT_TYPE_BYTES,
93
93
  });
94
- this.fileObject = node_buffer_1.Buffer.alloc(0);
94
+ this.fileObject = buffer_1.Buffer.alloc(0);
95
95
  this.filename = filename;
96
96
  this.inputBytes = inputBytes;
97
97
  }
98
98
  async init() {
99
- this.fileObject = node_buffer_1.Buffer.from(this.inputBytes, "hex");
99
+ this.fileObject = buffer_1.Buffer.from(this.inputBytes, "hex");
100
100
  this.mimeType = await this.checkMimetype();
101
101
  // clear out the string
102
102
  this.inputBytes = "";
@@ -1,25 +0,0 @@
1
- import { TaxField } from "../../fields";
2
- interface ReceiptTaxConstructor {
3
- prediction: any;
4
- valueKey?: string;
5
- rateKey?: string;
6
- codeKey?: string;
7
- baseKey?: string;
8
- reconstructed?: boolean;
9
- pageId?: number;
10
- }
11
- export declare class ReceiptTaxField extends TaxField {
12
- /** The tax base */
13
- base?: number;
14
- /**
15
- * @param {Object} prediction - Prediction object from HTTP response
16
- * @param {String} valueKey - Key to use in the prediction dict to get the tax value
17
- * @param {String} rateKey - Key to use to get the tax rate in the prediction dict
18
- * @param {String} codeKey - Key to use to get the tax code in the prediction dict
19
- * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
20
- * @param {Integer} pageNumber - Page ID for multi-page document
21
- */
22
- constructor({ prediction, valueKey, rateKey, codeKey, baseKey, reconstructed, pageId, }: ReceiptTaxConstructor);
23
- toString(): string;
24
- }
25
- export {};
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReceiptTaxField = void 0;
4
- const fields_1 = require("../../fields");
5
- const amount_1 = require("../../fields/amount");
6
- class ReceiptTaxField extends fields_1.TaxField {
7
- /**
8
- * @param {Object} prediction - Prediction object from HTTP response
9
- * @param {String} valueKey - Key to use in the prediction dict to get the tax value
10
- * @param {String} rateKey - Key to use to get the tax rate in the prediction dict
11
- * @param {String} codeKey - Key to use to get the tax code in the prediction dict
12
- * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
13
- * @param {Integer} pageNumber - Page ID for multi-page document
14
- */
15
- constructor({ prediction, valueKey = "value", rateKey = "rate", codeKey = "code", baseKey = "base", reconstructed = false, pageId = undefined, }) {
16
- super({ prediction, valueKey, rateKey, codeKey, reconstructed, pageId });
17
- /** The tax base */
18
- this.base = undefined;
19
- this.base = parseFloat(prediction[baseKey]);
20
- if (isNaN(this.base))
21
- this.base = undefined;
22
- }
23
- toString() {
24
- let outStr = "";
25
- if (this.value !== undefined) {
26
- outStr += `${(0, amount_1.floatToString)(this.value)}`;
27
- }
28
- if (this.rate !== undefined) {
29
- outStr += ` ${(0, amount_1.floatToString)(this.rate)}%`;
30
- }
31
- if (this.code !== undefined) {
32
- outStr += ` ${this.code}`;
33
- }
34
- if (this.base !== undefined) {
35
- outStr += ` ${this.base}`;
36
- }
37
- return outStr.trim();
38
- }
39
- }
40
- exports.ReceiptTaxField = ReceiptTaxField;