mindee 3.7.4 → 3.9.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 (36) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/package.json +3 -3
  3. package/src/cli.js +1 -1
  4. package/src/client.js +4 -1
  5. package/src/documents/documentConfig.d.ts +1 -1
  6. package/src/documents/documentConfig.js +3 -3
  7. package/src/documents/financialDocument/financialDocumentV1.d.ts +39 -36
  8. package/src/documents/financialDocument/financialDocumentV1.js +124 -108
  9. package/src/documents/financialDocument/financialDocumentV1LineItem.d.ts +40 -0
  10. package/src/documents/financialDocument/financialDocumentV1LineItem.js +107 -0
  11. package/src/documents/index.d.ts +1 -0
  12. package/src/documents/index.js +3 -1
  13. package/src/documents/invoice/invoiceV3.d.ts +2 -2
  14. package/src/documents/invoice/invoiceV3.js +83 -98
  15. package/src/documents/invoice/invoiceV4.d.ts +2 -2
  16. package/src/documents/invoice/invoiceV4.js +21 -34
  17. package/src/documents/proofOfAddress/proofOfAddressV1.d.ts +1 -1
  18. package/src/documents/proofOfAddress/proofOfAddressV1.js +2 -2
  19. package/src/documents/receipt/receiptV3.d.ts +1 -1
  20. package/src/documents/receipt/receiptV3.js +34 -48
  21. package/src/documents/receipt/receiptV4.js +16 -30
  22. package/src/documents/receipt/receiptV5.d.ts +43 -0
  23. package/src/documents/receipt/receiptV5.js +140 -0
  24. package/src/documents/receipt/receiptV5LineItem.d.ts +34 -0
  25. package/src/documents/receipt/receiptV5LineItem.js +81 -0
  26. package/src/documents/us/bankCheck/bankCheckV1.js +0 -1
  27. package/src/fields/amount.js +1 -1
  28. package/src/fields/index.d.ts +1 -1
  29. package/src/fields/index.js +2 -1
  30. package/src/fields/locale.d.ts +1 -1
  31. package/src/fields/locale.js +2 -1
  32. package/src/fields/paymentDetails.d.ts +5 -5
  33. package/src/fields/tax.d.ts +19 -0
  34. package/src/fields/tax.js +82 -14
  35. package/src/index.d.ts +1 -1
  36. package/src/index.js +2 -1
@@ -12,29 +12,23 @@ class ReceiptV4 extends document_1.Document {
12
12
  extras: extras,
13
13
  fullText: fullText,
14
14
  });
15
- /** List of taxes detected on the receipt. */
16
- this.taxes = [];
17
15
  this.locale = new fields_1.Locale({
18
16
  prediction: prediction.locale,
19
17
  });
20
18
  this.totalTax = new fields_1.Amount({
21
19
  prediction: prediction.total_tax,
22
- valueKey: "value",
23
20
  pageId: pageId,
24
21
  });
25
22
  this.totalAmount = new fields_1.Amount({
26
23
  prediction: prediction.total_amount,
27
- valueKey: "value",
28
24
  pageId: pageId,
29
25
  });
30
26
  this.totalNet = new fields_1.Amount({
31
27
  prediction: prediction.total_net,
32
- valueKey: "value",
33
28
  pageId: pageId,
34
29
  });
35
30
  this.tip = new fields_1.Amount({
36
31
  prediction: prediction.tip,
37
- valueKey: "value",
38
32
  pageId: pageId,
39
33
  });
40
34
  this.date = new fields_1.DateField({
@@ -59,32 +53,24 @@ class ReceiptV4 extends document_1.Document {
59
53
  prediction: prediction.time,
60
54
  pageId: pageId,
61
55
  });
62
- prediction.taxes.map((taxPrediction) => this.taxes.push(new fields_1.TaxField({
63
- prediction: taxPrediction,
64
- pageId: pageId,
65
- valueKey: "value",
66
- rateKey: "rate",
67
- codeKey: "code",
68
- baseKey: "base",
69
- })));
56
+ this.taxes = new fields_1.Taxes().init(prediction["taxes"], pageId);
70
57
  }
71
58
  toString() {
72
- const taxes = this.taxes.map((item) => item.toString()).join("\n ");
73
- const outStr = `----- Receipt V4 -----
74
- Filename: ${this.filename}
75
- Total amount: ${this.totalAmount}
76
- Total net: ${this.totalNet}
77
- Tip: ${this.tip}
78
- Date: ${this.date}
79
- Category: ${this.category}
80
- Subcategory: ${this.subCategory}
81
- Document type: ${this.documentType}
82
- Time: ${this.time}
83
- Supplier name: ${this.supplier}
84
- Taxes: ${taxes}
85
- Total taxes: ${this.totalTax}
86
- Locale: ${this.locale}
87
- ----------------------
59
+ const outStr = `Receipt V4 Prediction
60
+ =====================
61
+ :Filename: ${this.filename}
62
+ :Total amount: ${this.totalAmount}
63
+ :Total net: ${this.totalNet}
64
+ :Tip: ${this.tip}
65
+ :Date: ${this.date}
66
+ :Category: ${this.category}
67
+ :Subcategory: ${this.subCategory}
68
+ :Document type: ${this.documentType}
69
+ :Time: ${this.time}
70
+ :Supplier name: ${this.supplier}
71
+ :Taxes: ${this.taxes}
72
+ :Total tax: ${this.totalTax}
73
+ :Locale: ${this.locale}
88
74
  `;
89
75
  return ReceiptV4.cleanOutString(outStr);
90
76
  }
@@ -0,0 +1,43 @@
1
+ import { Document, DocumentConstructorProps } from "../document";
2
+ import { Amount, ClassificationField, CompanyRegistration, DateField, Locale, TaxField, TextField } from "../../fields";
3
+ import { ReceiptV5LineItem } from "./receiptV5LineItem";
4
+ /**
5
+ * Document data for Receipt, API version 5.
6
+ */
7
+ export declare class ReceiptV5 extends Document {
8
+ #private;
9
+ /** The locale identifier in BCP 47 (RFC 5646) format: ISO language code, '-', ISO country code. */
10
+ locale: Locale;
11
+ /** The receipt category among predefined classes. */
12
+ category: ClassificationField;
13
+ /** The receipt sub category among predefined classes for transport and food. */
14
+ subcategory: ClassificationField;
15
+ /** The receipt document type provides the information whether the document is an expense receipt or a credit card receipt. */
16
+ documentType: ClassificationField;
17
+ /** The date the purchase was made. */
18
+ date: DateField;
19
+ /** Time of purchase with 24 hours formatting (HH:MM). */
20
+ time: TextField;
21
+ /** The total amount paid including taxes, discounts, fees, tips, and gratuity. */
22
+ totalAmount: Amount;
23
+ /** The total amount excluding taxes. */
24
+ totalNet: Amount;
25
+ /** The total amount of taxes. */
26
+ totalTax: Amount;
27
+ /** The total amount of tip and gratuity. */
28
+ tip: Amount;
29
+ /** List of tax lines information including: Amount, tax rate, tax base amount and tax code. */
30
+ taxes: TaxField[];
31
+ /** The name of the supplier or merchant. */
32
+ supplierName: TextField;
33
+ /** List of supplier company registrations or identifiers. */
34
+ supplierCompanyRegistrations: CompanyRegistration[];
35
+ /** The address of the supplier or merchant returned as a single string. */
36
+ supplierAddress: TextField;
37
+ /** The Phone number of the supplier or merchant returned as a single string. */
38
+ supplierPhoneNumber: TextField;
39
+ /** Full extraction of lines, including: description, quantity, unit price and total. */
40
+ lineItems: ReceiptV5LineItem[];
41
+ constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
42
+ toString(): string;
43
+ }
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _ReceiptV5_instances, _ReceiptV5_lineItemsSeparator, _ReceiptV5_lineItemsToString;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ReceiptV5 = void 0;
10
+ const document_1 = require("../document");
11
+ const fields_1 = require("../../fields");
12
+ const receiptV5LineItem_1 = require("./receiptV5LineItem");
13
+ /**
14
+ * Document data for Receipt, API version 5.
15
+ */
16
+ class ReceiptV5 extends document_1.Document {
17
+ constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {
18
+ super({
19
+ inputSource: inputSource,
20
+ pageId: pageId,
21
+ orientation: orientation,
22
+ extras: extras,
23
+ fullText: fullText,
24
+ });
25
+ _ReceiptV5_instances.add(this);
26
+ /** List of supplier company registrations or identifiers. */
27
+ this.supplierCompanyRegistrations = [];
28
+ /** Full extraction of lines, including: description, quantity, unit price and total. */
29
+ this.lineItems = [];
30
+ this.locale = new fields_1.Locale({
31
+ prediction: prediction["locale"],
32
+ });
33
+ this.category = new fields_1.ClassificationField({
34
+ prediction: prediction["category"],
35
+ });
36
+ this.subcategory = new fields_1.ClassificationField({
37
+ prediction: prediction["subcategory"],
38
+ });
39
+ this.documentType = new fields_1.ClassificationField({
40
+ prediction: prediction["document_type"],
41
+ });
42
+ this.date = new fields_1.DateField({
43
+ prediction: prediction["date"],
44
+ pageId: pageId,
45
+ });
46
+ this.time = new fields_1.TextField({
47
+ prediction: prediction["time"],
48
+ pageId: pageId,
49
+ });
50
+ this.totalAmount = new fields_1.Amount({
51
+ prediction: prediction["total_amount"],
52
+ pageId: pageId,
53
+ });
54
+ this.totalNet = new fields_1.Amount({
55
+ prediction: prediction["total_net"],
56
+ pageId: pageId,
57
+ });
58
+ this.totalTax = new fields_1.Amount({
59
+ prediction: prediction["total_tax"],
60
+ pageId: pageId,
61
+ });
62
+ this.tip = new fields_1.Amount({
63
+ prediction: prediction["tip"],
64
+ pageId: pageId,
65
+ });
66
+ this.taxes = new fields_1.Taxes().init(prediction["taxes"], pageId);
67
+ this.supplierName = new fields_1.TextField({
68
+ prediction: prediction["supplier_name"],
69
+ pageId: pageId,
70
+ });
71
+ prediction["supplier_company_registrations"].map((itemPrediction) => this.supplierCompanyRegistrations.push(new fields_1.CompanyRegistration({
72
+ prediction: itemPrediction,
73
+ pageId: pageId,
74
+ })));
75
+ this.supplierAddress = new fields_1.TextField({
76
+ prediction: prediction["supplier_address"],
77
+ pageId: pageId,
78
+ });
79
+ this.supplierPhoneNumber = new fields_1.TextField({
80
+ prediction: prediction["supplier_phone_number"],
81
+ pageId: pageId,
82
+ });
83
+ prediction["line_items"].map((itemPrediction) => this.lineItems.push(new receiptV5LineItem_1.ReceiptV5LineItem({
84
+ prediction: itemPrediction,
85
+ pageId: pageId,
86
+ })));
87
+ }
88
+ toString() {
89
+ const supplierCompanyRegistrations = this.supplierCompanyRegistrations
90
+ .map((item) => item.toString())
91
+ .join("; ");
92
+ const outStr = `Receipt V5 Prediction
93
+ =====================
94
+ :Filename: ${this.filename}
95
+ :Expense Locale: ${this.locale}
96
+ :Expense Category: ${this.category}
97
+ :Expense Sub Category: ${this.subcategory}
98
+ :Document Type: ${this.documentType}
99
+ :Purchase Date: ${this.date}
100
+ :Purchase Time: ${this.time}
101
+ :Total Amount: ${this.totalAmount}
102
+ :Total Excluding Taxes: ${this.totalNet}
103
+ :Total Tax: ${this.totalTax}
104
+ :Tip and Gratuity: ${this.tip}
105
+ :Taxes: ${this.taxes}
106
+ :Supplier Name: ${this.supplierName}
107
+ :Supplier Company Registrations: ${supplierCompanyRegistrations}
108
+ :Supplier Address: ${this.supplierAddress}
109
+ :Supplier Phone Number: ${this.supplierPhoneNumber}
110
+ :Line Items: ${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsToString).call(this)}
111
+ `;
112
+ return ReceiptV5.cleanOutString(outStr);
113
+ }
114
+ }
115
+ exports.ReceiptV5 = ReceiptV5;
116
+ _ReceiptV5_instances = new WeakSet(), _ReceiptV5_lineItemsSeparator = function _ReceiptV5_lineItemsSeparator(char) {
117
+ let outStr = " ";
118
+ outStr += `+${char.repeat(38)}`;
119
+ outStr += `+${char.repeat(10)}`;
120
+ outStr += `+${char.repeat(14)}`;
121
+ outStr += `+${char.repeat(12)}`;
122
+ return outStr + "+";
123
+ }, _ReceiptV5_lineItemsToString = function _ReceiptV5_lineItemsToString() {
124
+ if (this.lineItems.length === 0) {
125
+ return "";
126
+ }
127
+ const lines = this.lineItems
128
+ .map((item) => item.toTableLine())
129
+ .join(`\n${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsSeparator).call(this, "-")}\n `);
130
+ let outStr = "";
131
+ outStr += `\n${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsSeparator).call(this, "-")}\n `;
132
+ outStr += " | Description ";
133
+ outStr += " | Quantity";
134
+ outStr += " | Total Amount";
135
+ outStr += " | Unit Price";
136
+ outStr += ` |\n${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsSeparator).call(this, "=")}`;
137
+ outStr += `\n ${lines}`;
138
+ outStr += `\n${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsSeparator).call(this, "-")}`;
139
+ return outStr;
140
+ };
@@ -0,0 +1,34 @@
1
+ import { StringDict } from "../../fields";
2
+ import { Polygon } from "../../geometry";
3
+ /**
4
+ * Full extraction of lines, including: description, quantity, unit price and total.
5
+ */
6
+ export declare class ReceiptV5LineItem {
7
+ #private;
8
+ /** The item description. */
9
+ description: string | null;
10
+ /** The item quantity. */
11
+ quantity: number | null;
12
+ /** The item total amount. */
13
+ totalAmount: number | null;
14
+ /** The item unit price. */
15
+ unitPrice: number | null;
16
+ /** Confidence score */
17
+ confidence: number;
18
+ /** The document page on which the information was found. */
19
+ pageId: number;
20
+ /**
21
+ * Contains the relative vertices coordinates (points) of a polygon containing
22
+ * the field in the document.
23
+ */
24
+ polygon: Polygon;
25
+ constructor({ prediction }: StringDict);
26
+ /**
27
+ * Default string representation.
28
+ */
29
+ toString(): string;
30
+ /**
31
+ * Output in a format suitable for inclusion in an rST table.
32
+ */
33
+ toTableLine(): string;
34
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _ReceiptV5LineItem_instances, _ReceiptV5LineItem_printableValues;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ReceiptV5LineItem = void 0;
10
+ const amount_1 = require("../../fields/amount");
11
+ /**
12
+ * Full extraction of lines, including: description, quantity, unit price and total.
13
+ */
14
+ class ReceiptV5LineItem {
15
+ constructor({ prediction }) {
16
+ _ReceiptV5LineItem_instances.add(this);
17
+ /** Confidence score */
18
+ this.confidence = 0.0;
19
+ /**
20
+ * Contains the relative vertices coordinates (points) of a polygon containing
21
+ * the field in the document.
22
+ */
23
+ this.polygon = [];
24
+ this.description = prediction["description"];
25
+ this.quantity = +parseFloat(prediction["quantity"]).toFixed(3);
26
+ if (isNaN(this.quantity)) {
27
+ this.quantity = null;
28
+ }
29
+ this.totalAmount = +parseFloat(prediction["total_amount"]).toFixed(3);
30
+ if (isNaN(this.totalAmount)) {
31
+ this.totalAmount = null;
32
+ }
33
+ this.unitPrice = +parseFloat(prediction["unit_price"]).toFixed(3);
34
+ if (isNaN(this.unitPrice)) {
35
+ this.unitPrice = null;
36
+ }
37
+ this.pageId = prediction["page_id"];
38
+ this.confidence = prediction["confidence"] ? prediction.confidence : 0.0;
39
+ if (prediction["polygon"]) {
40
+ this.polygon = prediction.polygon;
41
+ }
42
+ }
43
+ /**
44
+ * Default string representation.
45
+ */
46
+ toString() {
47
+ const printable = __classPrivateFieldGet(this, _ReceiptV5LineItem_instances, "m", _ReceiptV5LineItem_printableValues).call(this);
48
+ return ("Description: " +
49
+ printable.description +
50
+ "Quantity: " +
51
+ printable.quantity +
52
+ "Total Amount: " +
53
+ printable.totalAmount +
54
+ "Unit Price: " +
55
+ printable.unitPrice).trim();
56
+ }
57
+ /**
58
+ * Output in a format suitable for inclusion in an rST table.
59
+ */
60
+ toTableLine() {
61
+ const printable = __classPrivateFieldGet(this, _ReceiptV5LineItem_instances, "m", _ReceiptV5LineItem_printableValues).call(this);
62
+ return ("| " +
63
+ printable.description.padEnd(36) +
64
+ " | " +
65
+ printable.quantity.padEnd(8) +
66
+ " | " +
67
+ printable.totalAmount.padEnd(12) +
68
+ " | " +
69
+ printable.unitPrice.padEnd(10) +
70
+ " |");
71
+ }
72
+ }
73
+ exports.ReceiptV5LineItem = ReceiptV5LineItem;
74
+ _ReceiptV5LineItem_instances = new WeakSet(), _ReceiptV5LineItem_printableValues = function _ReceiptV5LineItem_printableValues() {
75
+ return {
76
+ description: this.description ?? "",
77
+ quantity: this.quantity !== null ? (0, amount_1.floatToString)(this.quantity) : "",
78
+ totalAmount: this.totalAmount !== null ? (0, amount_1.floatToString)(this.totalAmount) : "",
79
+ unitPrice: this.unitPrice !== null ? (0, amount_1.floatToString)(this.unitPrice) : "",
80
+ };
81
+ };
@@ -23,7 +23,6 @@ class BankCheckV1 extends document_1.Document {
23
23
  });
24
24
  this.amount = new fields_1.Amount({
25
25
  prediction: prediction.amount,
26
- valueKey: "value",
27
26
  pageId: pageId,
28
27
  });
29
28
  this.checkPosition = new fields_1.PositionField({
@@ -17,7 +17,7 @@ class Amount extends field_1.Field {
17
17
  * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
18
18
  * @param {Integer} pageId - Page ID for multi-page document
19
19
  */
20
- constructor({ prediction, valueKey = "amount", reconstructed = false, pageId = undefined, }) {
20
+ constructor({ prediction, valueKey = "value", reconstructed = false, pageId = undefined, }) {
21
21
  super({ prediction, valueKey, reconstructed, pageId });
22
22
  /** The value. */
23
23
  this.value = undefined;
@@ -1,5 +1,5 @@
1
1
  export { ClassificationField } from "./classification";
2
- export { TaxField } from "./tax";
2
+ export { Taxes, TaxField } from "./tax";
3
3
  export { PaymentDetails } from "./paymentDetails";
4
4
  export { OrientationField } from "./orientation";
5
5
  export { Locale } from "./locale";
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TextField = exports.PositionField = exports.CompanyRegistration = exports.FullText = exports.BaseField = exports.DateField = exports.Amount = exports.Locale = exports.OrientationField = exports.PaymentDetails = exports.TaxField = exports.ClassificationField = void 0;
3
+ exports.TextField = exports.PositionField = exports.CompanyRegistration = exports.FullText = exports.BaseField = exports.DateField = exports.Amount = exports.Locale = exports.OrientationField = exports.PaymentDetails = exports.TaxField = exports.Taxes = exports.ClassificationField = void 0;
4
4
  var classification_1 = require("./classification");
5
5
  Object.defineProperty(exports, "ClassificationField", { enumerable: true, get: function () { return classification_1.ClassificationField; } });
6
6
  var tax_1 = require("./tax");
7
+ Object.defineProperty(exports, "Taxes", { enumerable: true, get: function () { return tax_1.Taxes; } });
7
8
  Object.defineProperty(exports, "TaxField", { enumerable: true, get: function () { return tax_1.TaxField; } });
8
9
  var paymentDetails_1 = require("./paymentDetails");
9
10
  Object.defineProperty(exports, "PaymentDetails", { enumerable: true, get: function () { return paymentDetails_1.PaymentDetails; } });
@@ -15,6 +15,6 @@ export declare class Locale extends BaseField {
15
15
  * @param {String} valueKey - Key to use in the prediction dict
16
16
  * @param {boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
17
17
  */
18
- constructor({ prediction, reconstructed, valueKey, }: BaseFieldConstructor);
18
+ constructor({ prediction, reconstructed }: BaseFieldConstructor);
19
19
  toString(): string;
20
20
  }
@@ -8,7 +8,8 @@ class Locale extends base_1.BaseField {
8
8
  * @param {String} valueKey - Key to use in the prediction dict
9
9
  * @param {boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
10
10
  */
11
- constructor({ prediction, reconstructed = false, valueKey = "value", }) {
11
+ constructor({ prediction, reconstructed = false }) {
12
+ const valueKey = prediction.value !== undefined ? "value" : "language";
12
13
  super({ prediction, valueKey, reconstructed });
13
14
  this.confidence = prediction.confidence ? prediction.confidence : 0.0;
14
15
  this.language = undefined;
@@ -15,13 +15,13 @@ export declare class PaymentDetails extends Field {
15
15
  /** Synonym for the `iban` property */
16
16
  value?: string | undefined;
17
17
  /** The account number. */
18
- accountNumber: number | undefined;
19
- /** The account IBAN. */
18
+ accountNumber: string | undefined;
19
+ /** The International Bank Account Number (IBAN). */
20
20
  iban: string | undefined;
21
21
  /** The routing number. */
22
- routingNumber: number | undefined;
23
- /** The SWIFT value. */
24
- swift: number | undefined;
22
+ routingNumber: string | undefined;
23
+ /** The bank's SWIFT Business Identifier Code (BIC). */
24
+ swift: string | undefined;
25
25
  /**
26
26
  * @param {Object} prediction - Prediction object from HTTP response
27
27
  * @param {String} valueKey - Key to use in the prediction dict to get the iban
@@ -9,7 +9,11 @@ interface TaxConstructor {
9
9
  reconstructed?: boolean;
10
10
  pageId?: number;
11
11
  }
12
+ /**
13
+ * Represent a single tax line.
14
+ */
12
15
  export declare class TaxField extends Field {
16
+ #private;
13
17
  /** The tax amount. */
14
18
  value?: number;
15
19
  /** The tax rate. */
@@ -30,6 +34,21 @@ export declare class TaxField extends Field {
30
34
  * @param {Integer} pageNumber - Page ID for multi-page document
31
35
  */
32
36
  constructor({ prediction, valueKey, rateKey, codeKey, baseKey, reconstructed, pageId, }: TaxConstructor);
37
+ /**
38
+ * Output in a format suitable for inclusion in an rST table.
39
+ */
40
+ toTableLine(): string;
41
+ /**
42
+ * Default string representation.
43
+ */
44
+ toString(): string;
45
+ }
46
+ /**
47
+ * Represent all items.
48
+ */
49
+ export declare class Taxes extends Array<TaxField> {
50
+ #private;
51
+ init(prediction: StringDict[], pageId: number | undefined): this;
33
52
  toString(): string;
34
53
  }
35
54
  export {};
package/src/fields/tax.js CHANGED
@@ -1,8 +1,17 @@
1
1
  "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _TaxField_instances, _TaxField_printableValues, _Taxes_instances, _Taxes_lineSeparator;
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaxField = void 0;
9
+ exports.Taxes = exports.TaxField = void 0;
4
10
  const field_1 = require("./field");
5
11
  const amount_1 = require("./amount");
12
+ /**
13
+ * Represent a single tax line.
14
+ */
6
15
  class TaxField extends field_1.Field {
7
16
  /**
8
17
  * @param {Object} prediction - Prediction object from HTTP response
@@ -15,6 +24,7 @@ class TaxField extends field_1.Field {
15
24
  */
16
25
  constructor({ prediction, valueKey = "value", rateKey = "rate", codeKey = "code", baseKey = "base", reconstructed = false, pageId = undefined, }) {
17
26
  super({ prediction, valueKey, reconstructed, pageId });
27
+ _TaxField_instances.add(this);
18
28
  /** The tax amount. */
19
29
  this.value = undefined;
20
30
  /** The tax rate. */
@@ -39,21 +49,79 @@ class TaxField extends field_1.Field {
39
49
  if (isNaN(this.base))
40
50
  this.base = undefined;
41
51
  }
52
+ /**
53
+ * Output in a format suitable for inclusion in an rST table.
54
+ */
55
+ toTableLine() {
56
+ const printable = __classPrivateFieldGet(this, _TaxField_instances, "m", _TaxField_printableValues).call(this);
57
+ return ("| " +
58
+ printable.base.padEnd(13) +
59
+ " | " +
60
+ printable.code.padEnd(6) +
61
+ " | " +
62
+ printable.rate.padEnd(8) +
63
+ " | " +
64
+ printable.value.padEnd(13) +
65
+ " |");
66
+ }
67
+ /**
68
+ * Default string representation.
69
+ */
42
70
  toString() {
43
- let outStr = "";
44
- if (this.value !== undefined) {
45
- outStr += `${(0, amount_1.floatToString)(this.value)}`;
46
- }
47
- if (this.rate !== undefined) {
48
- outStr += ` ${(0, amount_1.floatToString)(this.rate)}%`;
49
- }
50
- if (this.code !== undefined) {
51
- outStr += ` ${this.code}`;
71
+ const printable = __classPrivateFieldGet(this, _TaxField_instances, "m", _TaxField_printableValues).call(this);
72
+ return ("Base: " +
73
+ printable.base +
74
+ ", Code: " +
75
+ printable.code +
76
+ ", Rate (%): " +
77
+ printable.rate +
78
+ ", Amount: " +
79
+ printable.value).trim();
80
+ }
81
+ }
82
+ exports.TaxField = TaxField;
83
+ _TaxField_instances = new WeakSet(), _TaxField_printableValues = function _TaxField_printableValues() {
84
+ return {
85
+ code: this.code ?? "",
86
+ base: this.base !== undefined ? (0, amount_1.floatToString)(this.base) : "",
87
+ rate: this.rate !== undefined ? (0, amount_1.floatToString)(this.rate) : "",
88
+ value: this.value !== undefined ? (0, amount_1.floatToString)(this.value) : "",
89
+ };
90
+ };
91
+ /**
92
+ * Represent all items.
93
+ */
94
+ class Taxes extends Array {
95
+ constructor() {
96
+ super(...arguments);
97
+ _Taxes_instances.add(this);
98
+ }
99
+ init(prediction, pageId) {
100
+ for (const entry of prediction) {
101
+ this.push(new TaxField({
102
+ prediction: entry,
103
+ pageId: pageId,
104
+ }));
52
105
  }
53
- if (this.base !== undefined) {
54
- outStr += ` ${(0, amount_1.floatToString)(this.base)}`;
106
+ return this;
107
+ }
108
+ toString() {
109
+ let outStr = `
110
+ ${__classPrivateFieldGet(this, _Taxes_instances, "m", _Taxes_lineSeparator).call(this, "-")}
111
+ | Base | Code | Rate (%) | Amount |
112
+ ${__classPrivateFieldGet(this, _Taxes_instances, "m", _Taxes_lineSeparator).call(this, "=")}`;
113
+ for (const entry of this.entries()) {
114
+ outStr += `\n ${entry[1].toTableLine()}\n${__classPrivateFieldGet(this, _Taxes_instances, "m", _Taxes_lineSeparator).call(this, "-")}`;
55
115
  }
56
- return outStr.trim();
116
+ return outStr;
57
117
  }
58
118
  }
59
- exports.TaxField = TaxField;
119
+ exports.Taxes = Taxes;
120
+ _Taxes_instances = new WeakSet(), _Taxes_lineSeparator = function _Taxes_lineSeparator(char) {
121
+ let outStr = " ";
122
+ outStr += `+${char.repeat(15)}`;
123
+ outStr += `+${char.repeat(8)}`;
124
+ outStr += `+${char.repeat(10)}`;
125
+ outStr += `+${char.repeat(15)}`;
126
+ return outStr + "+";
127
+ };
package/src/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { CustomV1, Document, FinancialDocumentV0, FinancialDocumentV1, InvoiceV3, InvoiceV4, InvoiceSplitterV1, PassportV1, ReceiptV3, ReceiptV4, CropperV1, ShippingContainerV1, MindeeVisionV1, ProofOfAddressV1, fr, us, eu, } from "./documents";
1
+ export { CustomV1, Document, FinancialDocumentV0, FinancialDocumentV1, InvoiceV3, InvoiceV4, InvoiceSplitterV1, PassportV1, ReceiptV3, ReceiptV4, ReceiptV5, CropperV1, ShippingContainerV1, MindeeVisionV1, ProofOfAddressV1, fr, us, eu, } from "./documents";
2
2
  export { Client, ClientOptions, CustomConfigParams, DocumentClient, PredictOptions, } from "./client";
3
3
  export { ResponseSig, Response, AsyncPredictResponse } from "./api";
4
4
  export { InputSource, PageOptionsOperation } from "./inputs";
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PageOptionsOperation = exports.InputSource = exports.AsyncPredictResponse = exports.Response = exports.DocumentClient = exports.Client = exports.eu = exports.us = exports.fr = exports.ProofOfAddressV1 = exports.MindeeVisionV1 = exports.ShippingContainerV1 = exports.CropperV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceSplitterV1 = exports.InvoiceV4 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.FinancialDocumentV0 = exports.Document = exports.CustomV1 = void 0;
3
+ exports.PageOptionsOperation = exports.InputSource = exports.AsyncPredictResponse = exports.Response = exports.DocumentClient = exports.Client = exports.eu = exports.us = exports.fr = exports.ProofOfAddressV1 = exports.MindeeVisionV1 = exports.ShippingContainerV1 = exports.CropperV1 = exports.ReceiptV5 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceSplitterV1 = exports.InvoiceV4 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.FinancialDocumentV0 = 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
6
  Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return documents_1.Document; } });
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "InvoiceSplitterV1", { enumerable: true, get: fun
12
12
  Object.defineProperty(exports, "PassportV1", { enumerable: true, get: function () { return documents_1.PassportV1; } });
13
13
  Object.defineProperty(exports, "ReceiptV3", { enumerable: true, get: function () { return documents_1.ReceiptV3; } });
14
14
  Object.defineProperty(exports, "ReceiptV4", { enumerable: true, get: function () { return documents_1.ReceiptV4; } });
15
+ Object.defineProperty(exports, "ReceiptV5", { enumerable: true, get: function () { return documents_1.ReceiptV5; } });
15
16
  Object.defineProperty(exports, "CropperV1", { enumerable: true, get: function () { return documents_1.CropperV1; } });
16
17
  Object.defineProperty(exports, "ShippingContainerV1", { enumerable: true, get: function () { return documents_1.ShippingContainerV1; } });
17
18
  Object.defineProperty(exports, "MindeeVisionV1", { enumerable: true, get: function () { return documents_1.MindeeVisionV1; } });