mindee 3.7.3 → 3.8.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.
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
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
5
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
6
  };
7
- var _ReceiptV3_instances, _ReceiptV3_initFromApiPrediction, _ReceiptV3_checklist, _ReceiptV3_taxesMatchTotal, _ReceiptV3_reconstruct, _ReceiptV3_reconstructTotalExclFromTCCAndTaxes, _ReceiptV3_reconstructTotalTax;
7
+ var _ReceiptV3_instances, _ReceiptV3_checklist, _ReceiptV3_taxesMatchTotal, _ReceiptV3_reconstruct, _ReceiptV3_reconstructTotalExclFromTCCAndTaxes, _ReceiptV3_reconstructTotalTax;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.ReceiptV3 = void 0;
10
10
  const document_1 = require("../document");
@@ -19,73 +19,59 @@ class ReceiptV3 extends document_1.Document {
19
19
  fullText: fullText,
20
20
  });
21
21
  _ReceiptV3_instances.add(this);
22
- /** List of different taxe. */
23
- this.taxes = [];
24
22
  this.locale = new fields_1.Locale({
25
23
  prediction: prediction.locale,
26
24
  });
27
25
  this.totalTax = new fields_1.Amount({
28
26
  prediction: { value: undefined, confidence: 0 },
29
- valueKey: "value",
30
27
  pageId: pageId,
31
28
  });
32
29
  this.totalExcl = new fields_1.Amount({
33
30
  prediction: { value: undefined, confidence: 0 },
34
- valueKey: "value",
35
31
  pageId: pageId,
36
32
  });
37
- __classPrivateFieldGet(this, _ReceiptV3_instances, "m", _ReceiptV3_initFromApiPrediction).call(this, prediction, pageId);
33
+ this.totalIncl = new fields_1.Amount({
34
+ prediction: prediction.total_incl,
35
+ pageId: pageId,
36
+ });
37
+ this.date = new fields_1.DateField({
38
+ prediction: prediction.date,
39
+ pageId: pageId,
40
+ });
41
+ this.category = new fields_1.ClassificationField({
42
+ prediction: prediction.category,
43
+ });
44
+ this.merchantName = new fields_1.TextField({
45
+ prediction: prediction.supplier,
46
+ pageId: pageId,
47
+ });
48
+ this.time = new fields_1.TextField({
49
+ prediction: prediction.time,
50
+ pageId: pageId,
51
+ });
52
+ this.taxes = new fields_1.Taxes().init(prediction["taxes"], pageId);
38
53
  __classPrivateFieldGet(this, _ReceiptV3_instances, "m", _ReceiptV3_checklist).call(this);
39
54
  __classPrivateFieldGet(this, _ReceiptV3_instances, "m", _ReceiptV3_reconstruct).call(this);
40
55
  }
41
56
  toString() {
42
- const taxes = this.taxes.map((item) => item.toString()).join("\n ");
43
- const outStr = `-----Receipt data-----
44
- Filename: ${this.filename}
45
- Total amount including taxes: ${this.totalIncl}
46
- Total amount excluding taxes: ${this.totalExcl}
47
- Date: ${this.date}
48
- Category: ${this.category}
49
- Time: ${this.time}
50
- Merchant name: ${this.merchantName}
51
- Taxes: ${taxes}
52
- Total taxes: ${this.totalTax}
53
- Locale: ${this.locale}
54
- ----------------------
57
+ const outStr = `Receipt V3 Prediction
58
+ =====================
59
+ :Filename: ${this.filename}
60
+ :Total amount: ${this.totalIncl}
61
+ :Total net: ${this.totalExcl}
62
+ :Date: ${this.date}
63
+ :Category: ${this.category}
64
+ :Time: ${this.time}
65
+ :Merchant name: ${this.merchantName}
66
+ :Taxes: ${this.taxes}
67
+ :Total tax: ${this.totalTax}
68
+ :Locale: ${this.locale}
55
69
  `;
56
70
  return ReceiptV3.cleanOutString(outStr);
57
71
  }
58
72
  }
59
73
  exports.ReceiptV3 = ReceiptV3;
60
- _ReceiptV3_instances = new WeakSet(), _ReceiptV3_initFromApiPrediction = function _ReceiptV3_initFromApiPrediction(apiPrediction, pageId) {
61
- this.totalIncl = new fields_1.Amount({
62
- prediction: apiPrediction.total_incl,
63
- valueKey: "value",
64
- pageId: pageId,
65
- });
66
- this.date = new fields_1.DateField({
67
- prediction: apiPrediction.date,
68
- pageId: pageId,
69
- });
70
- this.category = new fields_1.ClassificationField({
71
- prediction: apiPrediction.category,
72
- });
73
- this.merchantName = new fields_1.TextField({
74
- prediction: apiPrediction.supplier,
75
- pageId: pageId,
76
- });
77
- this.time = new fields_1.TextField({
78
- prediction: apiPrediction.time,
79
- pageId: pageId,
80
- });
81
- apiPrediction.taxes.map((taxPrediction) => this.taxes.push(new fields_1.TaxField({
82
- prediction: taxPrediction,
83
- pageId: pageId,
84
- valueKey: "value",
85
- rateKey: "rate",
86
- codeKey: "code",
87
- })));
88
- }, _ReceiptV3_checklist = function _ReceiptV3_checklist() {
74
+ _ReceiptV3_instances = new WeakSet(), _ReceiptV3_checklist = function _ReceiptV3_checklist() {
89
75
  this.checklist = { taxesMatchTotalIncl: __classPrivateFieldGet(this, _ReceiptV3_instances, "m", _ReceiptV3_taxesMatchTotal).call(this) };
90
76
  }, _ReceiptV3_taxesMatchTotal = function _ReceiptV3_taxesMatchTotal() {
91
77
  // Check taxes and total amount exist
@@ -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,135 @@
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 outStr = `Receipt V5 Prediction
90
+ =====================
91
+ :Filename: ${this.filename}
92
+ :Expense Locale: ${this.locale}
93
+ :Expense Category: ${this.category}
94
+ :Expense Sub Category: ${this.subcategory}
95
+ :Document Type: ${this.documentType}
96
+ :Purchase Date: ${this.date}
97
+ :Purchase Time: ${this.time}
98
+ :Total Amount: ${this.totalAmount}
99
+ :Total Excluding Taxes: ${this.totalNet}
100
+ :Total Tax: ${this.totalTax}
101
+ :Tip and Gratuity: ${this.tip}
102
+ :Taxes: ${this.taxes}
103
+ :Supplier Name: ${this.supplierName}
104
+ :Supplier Company Registrations: ${this.supplierCompanyRegistrations.join(`\n ${" ".repeat(32)}`)}
105
+ :Supplier Address: ${this.supplierAddress}
106
+ :Supplier Phone Number: ${this.supplierPhoneNumber}
107
+ :Line Items: ${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsToString).call(this)}
108
+ `;
109
+ return ReceiptV5.cleanOutString(outStr);
110
+ }
111
+ }
112
+ exports.ReceiptV5 = ReceiptV5;
113
+ _ReceiptV5_instances = new WeakSet(), _ReceiptV5_lineItemsSeparator = function _ReceiptV5_lineItemsSeparator(char) {
114
+ let outStr = " ";
115
+ outStr += `+${char.repeat(38)}`;
116
+ outStr += `+${char.repeat(10)}`;
117
+ outStr += `+${char.repeat(14)}`;
118
+ outStr += `+${char.repeat(12)}`;
119
+ return outStr + "+";
120
+ }, _ReceiptV5_lineItemsToString = function _ReceiptV5_lineItemsToString() {
121
+ if (!this.lineItems) {
122
+ return "";
123
+ }
124
+ const lines = this.lineItems
125
+ .map((item) => `${item}`)
126
+ .join(`\n${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsSeparator).call(this, "-")}\n `);
127
+ let outStr = "";
128
+ outStr += `\n${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsSeparator).call(this, "-")}`;
129
+ outStr +=
130
+ "\n | Description | Quantity | Total Amount | Unit Price |";
131
+ outStr += `\n${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsSeparator).call(this, "=")}`;
132
+ outStr += `\n ${lines}`;
133
+ outStr += `\n${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsSeparator).call(this, "-")}`;
134
+ return outStr;
135
+ };
@@ -0,0 +1,16 @@
1
+ import { StringDict } from "../../fields";
2
+ /**
3
+ * Full extraction of lines, including: description, quantity, unit price and total.
4
+ */
5
+ export declare class ReceiptV5LineItem {
6
+ /** The item description. */
7
+ description: string | null;
8
+ /** The item quantity. */
9
+ quantity: number | null;
10
+ /** The item total amount. */
11
+ totalAmount: number | null;
12
+ /** The item unit price. */
13
+ unitPrice: number | null;
14
+ constructor({ prediction }: StringDict);
15
+ toString(): string;
16
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReceiptV5LineItem = void 0;
4
+ const amount_1 = require("../../fields/amount");
5
+ /**
6
+ * Full extraction of lines, including: description, quantity, unit price and total.
7
+ */
8
+ class ReceiptV5LineItem {
9
+ constructor({ prediction }) {
10
+ this.description = prediction["description"];
11
+ this.quantity = +parseFloat(prediction["quantity"]).toFixed(3);
12
+ if (isNaN(this.quantity)) {
13
+ this.quantity = null;
14
+ }
15
+ this.totalAmount = +parseFloat(prediction["total_amount"]).toFixed(3);
16
+ if (isNaN(this.totalAmount)) {
17
+ this.totalAmount = null;
18
+ }
19
+ this.unitPrice = +parseFloat(prediction["unit_price"]).toFixed(3);
20
+ if (isNaN(this.unitPrice)) {
21
+ this.unitPrice = null;
22
+ }
23
+ }
24
+ toString() {
25
+ const description = this.description ?? "";
26
+ const quantity = this.quantity !== null ? (0, amount_1.floatToString)(this.quantity) : "";
27
+ const totalAmount = this.totalAmount !== null ? (0, amount_1.floatToString)(this.totalAmount) : "";
28
+ const unitPrice = this.unitPrice !== null ? (0, amount_1.floatToString)(this.unitPrice) : "";
29
+ return ("| " +
30
+ description.padEnd(36) +
31
+ " | " +
32
+ quantity.padEnd(8) +
33
+ " | " +
34
+ totalAmount.padEnd(12) +
35
+ " | " +
36
+ unitPrice.padEnd(10) +
37
+ " |");
38
+ }
39
+ }
40
+ exports.ReceiptV5LineItem = ReceiptV5LineItem;
@@ -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; } });
@@ -10,6 +10,7 @@ interface TaxConstructor {
10
10
  pageId?: number;
11
11
  }
12
12
  export declare class TaxField extends Field {
13
+ #private;
13
14
  /** The tax amount. */
14
15
  value?: number;
15
16
  /** The tax rate. */
@@ -30,6 +31,12 @@ export declare class TaxField extends Field {
30
31
  * @param {Integer} pageNumber - Page ID for multi-page document
31
32
  */
32
33
  constructor({ prediction, valueKey, rateKey, codeKey, baseKey, reconstructed, pageId, }: TaxConstructor);
34
+ toTableLine(): string;
35
+ toString(): string;
36
+ }
37
+ export declare class Taxes extends Array<TaxField> {
38
+ #private;
39
+ init(prediction: StringDict[], pageId: number | undefined): this;
33
40
  toString(): string;
34
41
  }
35
42
  export {};
package/src/fields/tax.js CHANGED
@@ -1,6 +1,12 @@
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");
6
12
  class TaxField extends field_1.Field {
@@ -15,6 +21,7 @@ class TaxField extends field_1.Field {
15
21
  */
16
22
  constructor({ prediction, valueKey = "value", rateKey = "rate", codeKey = "code", baseKey = "base", reconstructed = false, pageId = undefined, }) {
17
23
  super({ prediction, valueKey, reconstructed, pageId });
24
+ _TaxField_instances.add(this);
18
25
  /** The tax amount. */
19
26
  this.value = undefined;
20
27
  /** The tax rate. */
@@ -39,21 +46,70 @@ class TaxField extends field_1.Field {
39
46
  if (isNaN(this.base))
40
47
  this.base = undefined;
41
48
  }
49
+ toTableLine() {
50
+ const printable = __classPrivateFieldGet(this, _TaxField_instances, "m", _TaxField_printableValues).call(this);
51
+ return ("| " +
52
+ printable.base.padEnd(13) +
53
+ " | " +
54
+ printable.code.padEnd(6) +
55
+ " | " +
56
+ printable.rate.padEnd(8) +
57
+ " | " +
58
+ printable.value.padEnd(13) +
59
+ " |");
60
+ }
42
61
  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}`;
62
+ const printable = __classPrivateFieldGet(this, _TaxField_instances, "m", _TaxField_printableValues).call(this);
63
+ return ("Base: " +
64
+ printable.base +
65
+ ", Code: " +
66
+ printable.code +
67
+ ", Rate (%): " +
68
+ printable.rate +
69
+ ", Amount: " +
70
+ printable.value).trim();
71
+ }
72
+ }
73
+ exports.TaxField = TaxField;
74
+ _TaxField_instances = new WeakSet(), _TaxField_printableValues = function _TaxField_printableValues() {
75
+ return {
76
+ code: this.code ?? "",
77
+ base: this.base !== undefined ? (0, amount_1.floatToString)(this.base) : "",
78
+ rate: this.rate !== undefined ? (0, amount_1.floatToString)(this.rate) : "",
79
+ value: this.value !== undefined ? (0, amount_1.floatToString)(this.value) : "",
80
+ };
81
+ };
82
+ class Taxes extends Array {
83
+ constructor() {
84
+ super(...arguments);
85
+ _Taxes_instances.add(this);
86
+ }
87
+ init(prediction, pageId) {
88
+ for (const entry of prediction) {
89
+ this.push(new TaxField({
90
+ prediction: entry,
91
+ pageId: pageId,
92
+ }));
52
93
  }
53
- if (this.base !== undefined) {
54
- outStr += ` ${(0, amount_1.floatToString)(this.base)}`;
94
+ return this;
95
+ }
96
+ toString() {
97
+ let outStr = `
98
+ ${__classPrivateFieldGet(this, _Taxes_instances, "m", _Taxes_lineSeparator).call(this, "-")}
99
+ | Base | Code | Rate (%) | Amount |
100
+ ${__classPrivateFieldGet(this, _Taxes_instances, "m", _Taxes_lineSeparator).call(this, "=")}`;
101
+ for (const entry of this.entries()) {
102
+ outStr += `\n ${entry[1].toTableLine()}\n${__classPrivateFieldGet(this, _Taxes_instances, "m", _Taxes_lineSeparator).call(this, "-")}`;
55
103
  }
56
- return outStr.trim();
104
+ return outStr;
57
105
  }
58
106
  }
59
- exports.TaxField = TaxField;
107
+ exports.Taxes = Taxes;
108
+ _Taxes_instances = new WeakSet(), _Taxes_lineSeparator = function _Taxes_lineSeparator(char) {
109
+ let outStr = " ";
110
+ outStr += `+${char.repeat(15)}`;
111
+ outStr += `+${char.repeat(8)}`;
112
+ outStr += `+${char.repeat(10)}`;
113
+ outStr += `+${char.repeat(15)}`;
114
+ return outStr + "+";
115
+ };
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; } });