mindee 3.8.0 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v3.9.0 - 2023-06-06
4
+ ### Changes
5
+ * :sparkles: support for financial document v1.1
6
+ * :recycle: change http status code handling for async requests
7
+
8
+ ### Fixes
9
+ * :bug: fix typing in PaymentDetails
10
+ * :bug: locale value should always be set
11
+ * :bug: add missing class properties on new line items
12
+
13
+
3
14
  ## v3.8.0 - 2023-05-25
4
15
  ### Changes
5
16
  * :sparkles: add support for receipt v5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "3.8.0",
3
+ "version": "3.9.0",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
@@ -27,7 +27,7 @@ class DocumentConfig {
27
27
  }
28
28
  const response = await this.endpoints[0].predictAsyncReqPost(params.inputDoc, params.includeWords, params.cropper);
29
29
  const statusCode = response.messageObj.statusCode;
30
- if (statusCode === undefined || statusCode >= 202) {
30
+ if (statusCode === undefined || statusCode >= 300) {
31
31
  this.handleError(response, statusCode);
32
32
  }
33
33
  return new api_1.AsyncPredictResponse(response.data);
@@ -38,7 +38,7 @@ class DocumentConfig {
38
38
  const queueStatusCode = queueResponse.messageObj.statusCode;
39
39
  if (queueStatusCode === undefined ||
40
40
  queueStatusCode < 200 ||
41
- queueStatusCode > 302) {
41
+ queueStatusCode >= 400) {
42
42
  this.handleError(queueResponse, queueStatusCode);
43
43
  }
44
44
  if (queueStatusCode === 302 &&
@@ -1,54 +1,57 @@
1
1
  import { Document, DocumentConstructorProps } from "../document";
2
- import { TaxField, PaymentDetails, Locale, Amount, TextField, DateField, CompanyRegistration, BaseField } from "../../fields";
3
- import { InvoiceLineItem } from "../invoice/invoiceLineItem";
2
+ import { Amount, ClassificationField, CompanyRegistration, DateField, Locale, PaymentDetails, TaxField, TextField } from "../../fields";
3
+ import { FinancialDocumentV1LineItem } from "./financialDocumentV1LineItem";
4
4
  /**
5
- * Financial Document.
5
+ * Document data for Financial Document, API version 1.
6
6
  */
7
7
  export declare class FinancialDocumentV1 extends Document {
8
- /** Locale information. */
8
+ #private;
9
+ /** The locale detected on the document. */
9
10
  locale: Locale;
10
- /** The nature of the document. */
11
- documentType: BaseField;
12
- /** List of Reference numbers including PO number. */
11
+ /** The invoice number or identifier. */
12
+ invoiceNumber: TextField;
13
+ /** List of Reference numbers, including PO number. */
13
14
  referenceNumbers: TextField[];
14
- /** The creation date of the invoice or the purchase date. */
15
+ /** The date the purchase was made. */
15
16
  date: DateField;
16
- /** The due date of the invoice. */
17
+ /** The date on which the payment is due. */
17
18
  dueDate: DateField;
18
- /** The supplier name. */
19
- supplierName: TextField;
20
- /** The supplier address. */
21
- supplierAddress: TextField;
22
- /** The payment information. */
19
+ /** The net amount paid: does not include taxes, fees, and discounts. */
20
+ totalNet: Amount;
21
+ /** The total amount paid: includes taxes, tips, fees, and other charges. */
22
+ totalAmount: Amount;
23
+ /** List of tax lines information. */
24
+ taxes: TaxField[];
25
+ /** List of payment details associated to the supplier. */
23
26
  supplierPaymentDetails: PaymentDetails[];
24
- /** The supplier company registration information. */
27
+ /** The name of the supplier or merchant. */
28
+ supplierName: TextField;
29
+ /** List of company registrations associated to the supplier. */
25
30
  supplierCompanyRegistrations: CompanyRegistration[];
26
- /** The invoice number. */
27
- invoiceNumber: TextField;
31
+ /** The address of the supplier or merchant. */
32
+ supplierAddress: TextField;
33
+ /** The phone number of the supplier or merchant. */
34
+ supplierPhoneNumber: TextField;
28
35
  /** The name of the customer. */
29
36
  customerName: TextField;
37
+ /** List of company registrations associated to the customer. */
38
+ customerCompanyRegistrations: CompanyRegistration[];
30
39
  /** The address of the customer. */
31
40
  customerAddress: TextField;
32
- /** The company registration information for the customer. */
33
- customerCompanyRegistrations: CompanyRegistration[];
34
- /** The list of the taxes. */
35
- taxes: TaxField[];
36
- /** Line items details. */
37
- lineItems: InvoiceLineItem[];
38
- /** The receipt category among predefined classes. */
39
- category: TextField;
40
- /** The receipt sub-category among predefined classes. */
41
- subCategory: TextField;
42
- /** Time as seen on the receipt in HH:MM format. */
43
- time: TextField;
44
- /** Total amount of tip and gratuity. */
45
- tip: Amount;
46
- /** total spent including taxes, discounts, fees, tips, and gratuity. */
47
- totalAmount: Amount;
48
- /** Total amount of the purchase excluding taxes. */
49
- totalNet: Amount;
50
- /** Total tax amount of the purchase. */
41
+ /** One of: 'INVOICE', 'CREDIT NOTE', 'CREDIT CARD RECEIPT', 'EXPENSE RECEIPT'. */
42
+ documentType: ClassificationField;
43
+ /** The purchase subcategory among predefined classes for transport and food. */
44
+ subcategory: ClassificationField;
45
+ /** The purchase category among predefined classes. */
46
+ category: ClassificationField;
47
+ /** The total amount of taxes. */
51
48
  totalTax: Amount;
49
+ /** The total amount of tip and gratuity */
50
+ tip: Amount;
51
+ /** The time the purchase was made. */
52
+ time: TextField;
53
+ /** List of line item details. */
54
+ lineItems: FinancialDocumentV1LineItem[];
52
55
  constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
53
56
  toString(): string;
54
57
  }
@@ -1,11 +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 _FinancialDocumentV1_instances, _FinancialDocumentV1_lineItemsSeparator, _FinancialDocumentV1_lineItemsToString;
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.FinancialDocumentV1 = void 0;
4
10
  const document_1 = require("../document");
5
11
  const fields_1 = require("../../fields");
6
- const invoiceLineItem_1 = require("../invoice/invoiceLineItem");
12
+ const financialDocumentV1LineItem_1 = require("./financialDocumentV1LineItem");
7
13
  /**
8
- * Financial Document.
14
+ * Document data for Financial Document, API version 1.
9
15
  */
10
16
  class FinancialDocumentV1 extends document_1.Document {
11
17
  constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {
@@ -13,154 +19,179 @@ class FinancialDocumentV1 extends document_1.Document {
13
19
  inputSource: inputSource,
14
20
  pageId: pageId,
15
21
  orientation: orientation,
16
- fullText: fullText,
17
22
  extras: extras,
23
+ fullText: fullText,
18
24
  });
19
- /** List of Reference numbers including PO number. */
25
+ _FinancialDocumentV1_instances.add(this);
26
+ /** List of Reference numbers, including PO number. */
20
27
  this.referenceNumbers = [];
21
- /** The payment information. */
28
+ /** List of payment details associated to the supplier. */
22
29
  this.supplierPaymentDetails = [];
23
- /** The supplier company registration information. */
30
+ /** List of company registrations associated to the supplier. */
24
31
  this.supplierCompanyRegistrations = [];
25
- /** The company registration information for the customer. */
32
+ /** List of company registrations associated to the customer. */
26
33
  this.customerCompanyRegistrations = [];
27
- /** Line items details. */
34
+ /** List of line item details. */
28
35
  this.lineItems = [];
29
36
  this.locale = new fields_1.Locale({
30
- prediction: prediction.locale,
37
+ prediction: prediction["locale"],
31
38
  valueKey: "language",
32
39
  });
33
- this.documentType = new fields_1.ClassificationField({
34
- prediction: prediction.document_type,
35
- });
36
- this.referenceNumbers = prediction.reference_numbers.map(function (prediction) {
37
- return new fields_1.TextField({
38
- prediction: prediction,
39
- pageId: pageId,
40
- });
40
+ this.invoiceNumber = new fields_1.TextField({
41
+ prediction: prediction["invoice_number"],
42
+ pageId: pageId,
41
43
  });
42
- this.totalAmount = new fields_1.Amount({
43
- prediction: prediction.total_amount,
44
+ prediction["reference_numbers"].map((itemPrediction) => this.referenceNumbers.push(new fields_1.TextField({
45
+ prediction: itemPrediction,
46
+ pageId: pageId,
47
+ })));
48
+ this.date = new fields_1.DateField({
49
+ prediction: prediction["date"],
44
50
  pageId: pageId,
45
51
  });
46
- this.totalTax = new fields_1.Amount({
47
- prediction: prediction.total_tax,
52
+ this.dueDate = new fields_1.DateField({
53
+ prediction: prediction["due_date"],
48
54
  pageId: pageId,
49
55
  });
50
56
  this.totalNet = new fields_1.Amount({
51
- prediction: prediction.total_net,
57
+ prediction: prediction["total_net"],
52
58
  pageId: pageId,
53
59
  });
54
- this.date = new fields_1.DateField({
55
- prediction: prediction.date,
56
- pageId,
57
- });
58
- this.dueDate = new fields_1.DateField({
59
- prediction: prediction.due_date,
60
+ this.totalAmount = new fields_1.Amount({
61
+ prediction: prediction["total_amount"],
60
62
  pageId: pageId,
61
63
  });
62
- this.invoiceNumber = new fields_1.TextField({
63
- prediction: prediction.invoice_number,
64
+ this.taxes = new fields_1.Taxes().init(prediction["taxes"], pageId);
65
+ prediction["supplier_payment_details"].map((itemPrediction) => this.supplierPaymentDetails.push(new fields_1.PaymentDetails({
66
+ prediction: itemPrediction,
64
67
  pageId: pageId,
65
- });
68
+ })));
66
69
  this.supplierName = new fields_1.TextField({
67
- prediction: prediction.supplier_name,
70
+ prediction: prediction["supplier_name"],
68
71
  pageId: pageId,
69
72
  });
73
+ prediction["supplier_company_registrations"].map((itemPrediction) => this.supplierCompanyRegistrations.push(new fields_1.CompanyRegistration({
74
+ prediction: itemPrediction,
75
+ pageId: pageId,
76
+ })));
70
77
  this.supplierAddress = new fields_1.TextField({
71
- prediction: prediction.supplier_address,
78
+ prediction: prediction["supplier_address"],
72
79
  pageId: pageId,
73
80
  });
74
- this.supplierCompanyRegistrations =
75
- prediction.supplier_company_registrations.map(function (prediction) {
76
- return new fields_1.CompanyRegistration({
77
- prediction: prediction,
78
- pageId: pageId,
79
- });
80
- });
81
- this.customerName = new fields_1.TextField({
82
- prediction: prediction.customer_name,
81
+ this.supplierPhoneNumber = new fields_1.TextField({
82
+ prediction: prediction["supplier_phone_number"],
83
83
  pageId: pageId,
84
84
  });
85
- this.customerAddress = new fields_1.TextField({
86
- prediction: prediction.customer_address,
85
+ this.customerName = new fields_1.TextField({
86
+ prediction: prediction["customer_name"],
87
87
  pageId: pageId,
88
88
  });
89
- prediction.customer_company_registrations.map((prediction) => this.customerCompanyRegistrations.push(new fields_1.CompanyRegistration({
90
- prediction: prediction,
91
- pageId: pageId,
92
- })));
93
- prediction.supplier_payment_details.map((prediction) => this.supplierPaymentDetails.push(new fields_1.PaymentDetails({
94
- prediction: prediction,
89
+ prediction["customer_company_registrations"].map((itemPrediction) => this.customerCompanyRegistrations.push(new fields_1.CompanyRegistration({
90
+ prediction: itemPrediction,
95
91
  pageId: pageId,
96
92
  })));
97
- prediction.line_items.map((prediction) => this.lineItems.push(new invoiceLineItem_1.InvoiceLineItem({
98
- prediction: prediction,
99
- })));
100
- this.tip = new fields_1.Amount({
101
- prediction: prediction.tip,
93
+ this.customerAddress = new fields_1.TextField({
94
+ prediction: prediction["customer_address"],
102
95
  pageId: pageId,
103
96
  });
104
- this.category = new fields_1.TextField({
105
- prediction: prediction.category,
97
+ this.documentType = new fields_1.ClassificationField({
98
+ prediction: prediction["document_type"],
99
+ });
100
+ this.subcategory = new fields_1.ClassificationField({
101
+ prediction: prediction["subcategory"],
102
+ });
103
+ this.category = new fields_1.ClassificationField({
104
+ prediction: prediction["category"],
105
+ });
106
+ this.totalTax = new fields_1.Amount({
107
+ prediction: prediction["total_tax"],
106
108
  pageId: pageId,
107
109
  });
108
- this.subCategory = new fields_1.TextField({
109
- prediction: prediction.subcategory,
110
+ this.tip = new fields_1.Amount({
111
+ prediction: prediction["tip"],
110
112
  pageId: pageId,
111
113
  });
112
114
  this.time = new fields_1.TextField({
113
- prediction: prediction.time,
115
+ prediction: prediction["time"],
114
116
  pageId: pageId,
115
117
  });
116
- this.taxes = new fields_1.Taxes().init(prediction["taxes"], pageId);
118
+ prediction["line_items"].map((itemPrediction) => this.lineItems.push(new financialDocumentV1LineItem_1.FinancialDocumentV1LineItem({
119
+ prediction: itemPrediction,
120
+ pageId: pageId,
121
+ })));
117
122
  }
118
123
  toString() {
119
124
  const referenceNumbers = this.referenceNumbers
120
125
  .map((item) => item.toString())
121
126
  .join(", ");
122
- const paymentDetails = this.supplierPaymentDetails
127
+ const supplierPaymentDetails = this.supplierPaymentDetails
123
128
  .map((item) => item.toString())
124
129
  .join("\n ");
125
- const customerCompanyRegistration = this.customerCompanyRegistrations
130
+ const customerCompanyRegistrations = this.customerCompanyRegistrations
126
131
  .map((item) => item.toString())
127
132
  .join("; ");
128
- const supplierCompanyRegistration = this.supplierCompanyRegistrations
133
+ const supplierCompanyRegistrations = this.supplierCompanyRegistrations
129
134
  .map((item) => item.toString())
130
135
  .join("; ");
131
- let lineItems = "";
132
- if (this.lineItems.length > 0) {
133
- lineItems =
134
- "\n Code | QTY | Price | Amount | Tax (Rate) | Description\n ";
135
- lineItems += this.lineItems.map((item) => item.toString()).join("\n ");
136
- }
137
136
  const outStr = `Financial Document V1 Prediction
138
137
  ================================
139
138
  :Filename: ${this.filename}
140
- :Document type: ${this.documentType}
141
- :Category: ${this.category}
142
- :Subcategory: ${this.subCategory}
143
139
  :Locale: ${this.locale}
144
- :Invoice number: ${this.invoiceNumber}
145
- :Reference numbers: ${referenceNumbers}
146
- :Date: ${this.date}
147
- :Due date: ${this.dueDate}
148
- :Time: ${this.time}
140
+ :Invoice Number: ${this.invoiceNumber}
141
+ :Reference Numbers: ${referenceNumbers}
142
+ :Purchase Date: ${this.date}
143
+ :Due Date: ${this.dueDate}
144
+ :Total Net: ${this.totalNet}
145
+ :Total Amount: ${this.totalAmount}
146
+ :Taxes: ${this.taxes}
147
+ :Supplier Payment Details: ${supplierPaymentDetails}
149
148
  :Supplier name: ${this.supplierName}
150
- :Supplier address: ${this.supplierAddress}
151
- :Supplier company registrations: ${supplierCompanyRegistration}
152
- :Supplier payment details: ${paymentDetails}
149
+ :Supplier Company Registrations: ${customerCompanyRegistrations}
150
+ :Supplier Address: ${this.supplierAddress}
151
+ :Supplier Phone Number: ${this.supplierPhoneNumber}
153
152
  :Customer name: ${this.customerName}
154
- :Customer address: ${this.customerAddress}
155
- :Customer company registrations: ${customerCompanyRegistration}
156
- :Tip: ${this.tip}
157
- :Taxes: ${this.taxes}
158
- :Total tax: ${this.totalTax}
159
- :Total net: ${this.totalNet}
160
- :Total amount: ${this.totalAmount}
161
- :Line Items: ${lineItems}
153
+ :Customer Company Registrations: ${supplierCompanyRegistrations}
154
+ :Customer Address: ${this.customerAddress}
155
+ :Document Type: ${this.documentType}
156
+ :Purchase Subcategory: ${this.subcategory}
157
+ :Purchase Category: ${this.category}
158
+ :Total Tax: ${this.totalTax}
159
+ :Tip and Gratuity: ${this.tip}
160
+ :Purchase Time: ${this.time}
161
+ :Line Items: ${__classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_lineItemsToString).call(this)}
162
162
  `;
163
163
  return FinancialDocumentV1.cleanOutString(outStr);
164
164
  }
165
165
  }
166
166
  exports.FinancialDocumentV1 = FinancialDocumentV1;
167
+ _FinancialDocumentV1_instances = new WeakSet(), _FinancialDocumentV1_lineItemsSeparator = function _FinancialDocumentV1_lineItemsSeparator(char) {
168
+ let outStr = " ";
169
+ outStr += `+${char.repeat(38)}`;
170
+ outStr += `+${char.repeat(14)}`;
171
+ outStr += `+${char.repeat(10)}`;
172
+ outStr += `+${char.repeat(12)}`;
173
+ outStr += `+${char.repeat(14)}`;
174
+ outStr += `+${char.repeat(14)}`;
175
+ outStr += `+${char.repeat(12)}`;
176
+ return outStr + "+";
177
+ }, _FinancialDocumentV1_lineItemsToString = function _FinancialDocumentV1_lineItemsToString() {
178
+ if (this.lineItems.length === 0) {
179
+ return "";
180
+ }
181
+ const lines = this.lineItems
182
+ .map((item) => item.toTableLine())
183
+ .join(`\n${__classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_lineItemsSeparator).call(this, "-")}\n `);
184
+ let outStr = "";
185
+ outStr += `\n${__classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_lineItemsSeparator).call(this, "-")}\n `;
186
+ outStr += " | Description ";
187
+ outStr += " | Product code";
188
+ outStr += " | Quantity";
189
+ outStr += " | Tax Amount";
190
+ outStr += " | Tax Rate (%)";
191
+ outStr += " | Total Amount";
192
+ outStr += " | Unit Price";
193
+ outStr += ` |\n${__classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_lineItemsSeparator).call(this, "=")}`;
194
+ outStr += `\n ${lines}`;
195
+ outStr += `\n${__classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_lineItemsSeparator).call(this, "-")}`;
196
+ return outStr;
197
+ };
@@ -0,0 +1,40 @@
1
+ import { StringDict } from "../../fields";
2
+ import { Polygon } from "../../geometry";
3
+ /**
4
+ * List of line item details.
5
+ */
6
+ export declare class FinancialDocumentV1LineItem {
7
+ #private;
8
+ /** The item description. */
9
+ description: string | null;
10
+ /** The product code referring to the item. */
11
+ productCode: string | null;
12
+ /** The item quantity */
13
+ quantity: number | null;
14
+ /** The item tax amount. */
15
+ taxAmount: number | null;
16
+ /** The item tax rate in percentage. */
17
+ taxRate: number | null;
18
+ /** The item total amount. */
19
+ totalAmount: number | null;
20
+ /** The item unit price. */
21
+ unitPrice: number | null;
22
+ /** Confidence score */
23
+ confidence: number;
24
+ /** The document page on which the information was found. */
25
+ pageId: number;
26
+ /**
27
+ * Contains the relative vertices coordinates (points) of a polygon containing
28
+ * the field in the document.
29
+ */
30
+ polygon: Polygon;
31
+ constructor({ prediction }: StringDict);
32
+ /**
33
+ * Default string representation.
34
+ */
35
+ toString(): string;
36
+ /**
37
+ * Output in a format suitable for inclusion in an rST table.
38
+ */
39
+ toTableLine(): string;
40
+ }
@@ -0,0 +1,107 @@
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 _FinancialDocumentV1LineItem_instances, _FinancialDocumentV1LineItem_printableValues;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.FinancialDocumentV1LineItem = void 0;
10
+ const amount_1 = require("../../fields/amount");
11
+ /**
12
+ * List of line item details.
13
+ */
14
+ class FinancialDocumentV1LineItem {
15
+ constructor({ prediction }) {
16
+ _FinancialDocumentV1LineItem_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.productCode = prediction["product_code"];
26
+ this.quantity = +parseFloat(prediction["quantity"]).toFixed(3);
27
+ if (isNaN(this.quantity)) {
28
+ this.quantity = null;
29
+ }
30
+ this.taxAmount = +parseFloat(prediction["tax_amount"]).toFixed(3);
31
+ if (isNaN(this.taxAmount)) {
32
+ this.taxAmount = null;
33
+ }
34
+ this.taxRate = +parseFloat(prediction["tax_rate"]).toFixed(3);
35
+ if (isNaN(this.taxRate)) {
36
+ this.taxRate = null;
37
+ }
38
+ this.totalAmount = +parseFloat(prediction["total_amount"]).toFixed(3);
39
+ if (isNaN(this.totalAmount)) {
40
+ this.totalAmount = null;
41
+ }
42
+ this.unitPrice = +parseFloat(prediction["unit_price"]).toFixed(3);
43
+ if (isNaN(this.unitPrice)) {
44
+ this.unitPrice = null;
45
+ }
46
+ this.pageId = prediction["page_id"];
47
+ this.confidence = prediction["confidence"] ? prediction.confidence : 0.0;
48
+ if (prediction["polygon"]) {
49
+ this.polygon = prediction.polygon;
50
+ }
51
+ }
52
+ /**
53
+ * Default string representation.
54
+ */
55
+ toString() {
56
+ const printable = __classPrivateFieldGet(this, _FinancialDocumentV1LineItem_instances, "m", _FinancialDocumentV1LineItem_printableValues).call(this);
57
+ return ("Description: " +
58
+ printable.description +
59
+ "Product code: " +
60
+ printable.productCode +
61
+ "Quantity: " +
62
+ printable.quantity +
63
+ "Tax Amount: " +
64
+ printable.taxAmount +
65
+ "Tax Rate (%): " +
66
+ printable.taxRate +
67
+ "Total Amount: " +
68
+ printable.totalAmount +
69
+ "Unit Price: " +
70
+ printable.unitPrice).trim();
71
+ }
72
+ /**
73
+ * Output in a format suitable for inclusion in an rST table.
74
+ */
75
+ toTableLine() {
76
+ const printable = __classPrivateFieldGet(this, _FinancialDocumentV1LineItem_instances, "m", _FinancialDocumentV1LineItem_printableValues).call(this);
77
+ return ("| " +
78
+ (printable.description.length > 33
79
+ ? printable.description.substring(0, 33) + "..."
80
+ : printable.description).padEnd(36) +
81
+ " | " +
82
+ printable.productCode.padEnd(12) +
83
+ " | " +
84
+ printable.quantity.padEnd(8) +
85
+ " | " +
86
+ printable.taxAmount.padEnd(10) +
87
+ " | " +
88
+ printable.taxRate.padEnd(12) +
89
+ " | " +
90
+ printable.totalAmount.padEnd(12) +
91
+ " | " +
92
+ printable.unitPrice.padEnd(10) +
93
+ " |");
94
+ }
95
+ }
96
+ exports.FinancialDocumentV1LineItem = FinancialDocumentV1LineItem;
97
+ _FinancialDocumentV1LineItem_instances = new WeakSet(), _FinancialDocumentV1LineItem_printableValues = function _FinancialDocumentV1LineItem_printableValues() {
98
+ return {
99
+ description: this.description ?? "",
100
+ productCode: this.productCode ?? "",
101
+ quantity: this.quantity !== null ? (0, amount_1.floatToString)(this.quantity) : "",
102
+ taxAmount: this.taxAmount !== null ? (0, amount_1.floatToString)(this.taxAmount) : "",
103
+ taxRate: this.taxRate !== null ? (0, amount_1.floatToString)(this.taxRate) : "",
104
+ totalAmount: this.totalAmount !== null ? (0, amount_1.floatToString)(this.totalAmount) : "",
105
+ unitPrice: this.unitPrice !== null ? (0, amount_1.floatToString)(this.unitPrice) : "",
106
+ };
107
+ };
@@ -86,6 +86,9 @@ class ReceiptV5 extends document_1.Document {
86
86
  })));
87
87
  }
88
88
  toString() {
89
+ const supplierCompanyRegistrations = this.supplierCompanyRegistrations
90
+ .map((item) => item.toString())
91
+ .join("; ");
89
92
  const outStr = `Receipt V5 Prediction
90
93
  =====================
91
94
  :Filename: ${this.filename}
@@ -101,7 +104,7 @@ class ReceiptV5 extends document_1.Document {
101
104
  :Tip and Gratuity: ${this.tip}
102
105
  :Taxes: ${this.taxes}
103
106
  :Supplier Name: ${this.supplierName}
104
- :Supplier Company Registrations: ${this.supplierCompanyRegistrations.join(`\n ${" ".repeat(32)}`)}
107
+ :Supplier Company Registrations: ${supplierCompanyRegistrations}
105
108
  :Supplier Address: ${this.supplierAddress}
106
109
  :Supplier Phone Number: ${this.supplierPhoneNumber}
107
110
  :Line Items: ${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsToString).call(this)}
@@ -118,17 +121,19 @@ _ReceiptV5_instances = new WeakSet(), _ReceiptV5_lineItemsSeparator = function _
118
121
  outStr += `+${char.repeat(12)}`;
119
122
  return outStr + "+";
120
123
  }, _ReceiptV5_lineItemsToString = function _ReceiptV5_lineItemsToString() {
121
- if (!this.lineItems) {
124
+ if (this.lineItems.length === 0) {
122
125
  return "";
123
126
  }
124
127
  const lines = this.lineItems
125
- .map((item) => `${item}`)
128
+ .map((item) => item.toTableLine())
126
129
  .join(`\n${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsSeparator).call(this, "-")}\n `);
127
130
  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, "=")}`;
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, "=")}`;
132
137
  outStr += `\n ${lines}`;
133
138
  outStr += `\n${__classPrivateFieldGet(this, _ReceiptV5_instances, "m", _ReceiptV5_lineItemsSeparator).call(this, "-")}`;
134
139
  return outStr;
@@ -1,8 +1,10 @@
1
1
  import { StringDict } from "../../fields";
2
+ import { Polygon } from "../../geometry";
2
3
  /**
3
4
  * Full extraction of lines, including: description, quantity, unit price and total.
4
5
  */
5
6
  export declare class ReceiptV5LineItem {
7
+ #private;
6
8
  /** The item description. */
7
9
  description: string | null;
8
10
  /** The item quantity. */
@@ -11,6 +13,22 @@ export declare class ReceiptV5LineItem {
11
13
  totalAmount: number | null;
12
14
  /** The item unit price. */
13
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;
14
25
  constructor({ prediction }: StringDict);
26
+ /**
27
+ * Default string representation.
28
+ */
15
29
  toString(): string;
30
+ /**
31
+ * Output in a format suitable for inclusion in an rST table.
32
+ */
33
+ toTableLine(): string;
16
34
  }
@@ -1,4 +1,10 @@
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 _ReceiptV5LineItem_instances, _ReceiptV5LineItem_printableValues;
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.ReceiptV5LineItem = void 0;
4
10
  const amount_1 = require("../../fields/amount");
@@ -7,6 +13,14 @@ const amount_1 = require("../../fields/amount");
7
13
  */
8
14
  class ReceiptV5LineItem {
9
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 = [];
10
24
  this.description = prediction["description"];
11
25
  this.quantity = +parseFloat(prediction["quantity"]).toFixed(3);
12
26
  if (isNaN(this.quantity)) {
@@ -20,21 +34,48 @@ class ReceiptV5LineItem {
20
34
  if (isNaN(this.unitPrice)) {
21
35
  this.unitPrice = null;
22
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
+ }
23
42
  }
43
+ /**
44
+ * Default string representation.
45
+ */
24
46
  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) : "";
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);
29
62
  return ("| " +
30
- description.padEnd(36) +
63
+ printable.description.padEnd(36) +
31
64
  " | " +
32
- quantity.padEnd(8) +
65
+ printable.quantity.padEnd(8) +
33
66
  " | " +
34
- totalAmount.padEnd(12) +
67
+ printable.totalAmount.padEnd(12) +
35
68
  " | " +
36
- unitPrice.padEnd(10) +
69
+ printable.unitPrice.padEnd(10) +
37
70
  " |");
38
71
  }
39
72
  }
40
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
+ };
@@ -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,6 +9,9 @@ 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 {
13
16
  #private;
14
17
  /** The tax amount. */
@@ -31,9 +34,18 @@ export declare class TaxField extends Field {
31
34
  * @param {Integer} pageNumber - Page ID for multi-page document
32
35
  */
33
36
  constructor({ prediction, valueKey, rateKey, codeKey, baseKey, reconstructed, pageId, }: TaxConstructor);
37
+ /**
38
+ * Output in a format suitable for inclusion in an rST table.
39
+ */
34
40
  toTableLine(): string;
41
+ /**
42
+ * Default string representation.
43
+ */
35
44
  toString(): string;
36
45
  }
46
+ /**
47
+ * Represent all items.
48
+ */
37
49
  export declare class Taxes extends Array<TaxField> {
38
50
  #private;
39
51
  init(prediction: StringDict[], pageId: number | undefined): this;
package/src/fields/tax.js CHANGED
@@ -9,6 +9,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.Taxes = exports.TaxField = void 0;
10
10
  const field_1 = require("./field");
11
11
  const amount_1 = require("./amount");
12
+ /**
13
+ * Represent a single tax line.
14
+ */
12
15
  class TaxField extends field_1.Field {
13
16
  /**
14
17
  * @param {Object} prediction - Prediction object from HTTP response
@@ -46,6 +49,9 @@ class TaxField extends field_1.Field {
46
49
  if (isNaN(this.base))
47
50
  this.base = undefined;
48
51
  }
52
+ /**
53
+ * Output in a format suitable for inclusion in an rST table.
54
+ */
49
55
  toTableLine() {
50
56
  const printable = __classPrivateFieldGet(this, _TaxField_instances, "m", _TaxField_printableValues).call(this);
51
57
  return ("| " +
@@ -58,6 +64,9 @@ class TaxField extends field_1.Field {
58
64
  printable.value.padEnd(13) +
59
65
  " |");
60
66
  }
67
+ /**
68
+ * Default string representation.
69
+ */
61
70
  toString() {
62
71
  const printable = __classPrivateFieldGet(this, _TaxField_instances, "m", _TaxField_printableValues).call(this);
63
72
  return ("Base: " +
@@ -79,6 +88,9 @@ _TaxField_instances = new WeakSet(), _TaxField_printableValues = function _TaxFi
79
88
  value: this.value !== undefined ? (0, amount_1.floatToString)(this.value) : "",
80
89
  };
81
90
  };
91
+ /**
92
+ * Represent all items.
93
+ */
82
94
  class Taxes extends Array {
83
95
  constructor() {
84
96
  super(...arguments);