mindee 3.7.4 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v3.8.0 - 2023-05-25
4
+ ### Changes
5
+ * :sparkles: add support for receipt v5
6
+ * :sparkles: print taxes in table layout
7
+
8
+
3
9
  ## v3.7.4 - 2023-04-20
4
10
  ### Changes
5
11
  * :white_check_mark: minor improvements to tests
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "3.7.4",
3
+ "version": "3.8.0",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
@@ -48,11 +48,11 @@
48
48
  "eslint": "^8.32.0",
49
49
  "eslint-config-prettier": "^8.6.0",
50
50
  "eslint-plugin-prettier": "^4.2.1",
51
- "typedoc": "~0.23",
52
51
  "mocha": "^10.1.0",
53
52
  "prettier": "^2.8.1",
54
53
  "ts-node": "^10.9.1",
55
- "typescript": "^5.0.3"
54
+ "typedoc": "~0.23",
55
+ "typescript": "^5.0.4"
56
56
  },
57
57
  "dependencies": {
58
58
  "commander": "~9.4.1",
package/src/cli.js CHANGED
@@ -72,7 +72,7 @@ const CLI_COMMAND_CONFIG = new Map([
72
72
  "receipt",
73
73
  {
74
74
  displayName: "Expense Receipt",
75
- docClass: _1.ReceiptV4,
75
+ docClass: _1.ReceiptV5,
76
76
  fullText: true,
77
77
  async: false,
78
78
  sync: true,
package/src/client.js CHANGED
@@ -51,7 +51,7 @@ class DocumentClient {
51
51
  if (this.inputSource === undefined) {
52
52
  throw new Error("The 'enqueue' function requires an input document.");
53
53
  }
54
- return await docConfig.asyncPredict({
54
+ return await docConfig.predictAsync({
55
55
  inputDoc: this.inputSource,
56
56
  includeWords: this.getBooleanParam(params.fullText),
57
57
  pageOptions: params.pageOptions,
@@ -136,6 +136,9 @@ class Client {
136
136
  this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ReceiptV4.name], new documentConfig_1.DocumentConfig(documents_1.ReceiptV4, [
137
137
  new api_1.StandardEndpoint("expense_receipts", "4", this.apiKey),
138
138
  ]));
139
+ this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ReceiptV5.name], new documentConfig_1.DocumentConfig(documents_1.ReceiptV5, [
140
+ new api_1.StandardEndpoint("expense_receipts", "5", this.apiKey),
141
+ ]));
139
142
  this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.PassportV1.name], new documentConfig_1.DocumentConfig(documents_1.PassportV1, [
140
143
  new api_1.StandardEndpoint("passport", "1", this.apiKey),
141
144
  ]));
@@ -19,7 +19,7 @@ export declare class DocumentConfig<DocType extends Document> {
19
19
  pageOptions?: PageOptions;
20
20
  cropper: boolean;
21
21
  }): Promise<Response<DocType>>;
22
- asyncPredict(params: {
22
+ predictAsync(params: {
23
23
  inputDoc: InputSource;
24
24
  includeWords: boolean;
25
25
  pageOptions?: PageOptions;
@@ -19,7 +19,7 @@ class DocumentConfig {
19
19
  const response = await this.predictRequest(params.inputDoc, params.includeWords, params.cropper);
20
20
  return this.buildResult(response, params.inputDoc);
21
21
  }
22
- async asyncPredict(params) {
22
+ async predictAsync(params) {
23
23
  this.checkApiKeys();
24
24
  await params.inputDoc.init();
25
25
  if (params.pageOptions !== undefined) {
@@ -24,17 +24,14 @@ class FinancialDocumentV1 extends document_1.Document {
24
24
  this.supplierCompanyRegistrations = [];
25
25
  /** The company registration information for the customer. */
26
26
  this.customerCompanyRegistrations = [];
27
- /** The list of the taxes. */
28
- this.taxes = [];
29
27
  /** Line items details. */
30
28
  this.lineItems = [];
31
29
  this.locale = new fields_1.Locale({
32
30
  prediction: prediction.locale,
33
31
  valueKey: "language",
34
32
  });
35
- this.documentType = new fields_1.BaseField({
33
+ this.documentType = new fields_1.ClassificationField({
36
34
  prediction: prediction.document_type,
37
- valueKey: "value",
38
35
  });
39
36
  this.referenceNumbers = prediction.reference_numbers.map(function (prediction) {
40
37
  return new fields_1.TextField({
@@ -44,17 +41,14 @@ class FinancialDocumentV1 extends document_1.Document {
44
41
  });
45
42
  this.totalAmount = new fields_1.Amount({
46
43
  prediction: prediction.total_amount,
47
- valueKey: "value",
48
44
  pageId: pageId,
49
45
  });
50
46
  this.totalTax = new fields_1.Amount({
51
47
  prediction: prediction.total_tax,
52
- valueKey: "value",
53
48
  pageId: pageId,
54
49
  });
55
50
  this.totalNet = new fields_1.Amount({
56
51
  prediction: prediction.total_net,
57
- valueKey: "value",
58
52
  pageId: pageId,
59
53
  });
60
54
  this.date = new fields_1.DateField({
@@ -105,7 +99,6 @@ class FinancialDocumentV1 extends document_1.Document {
105
99
  })));
106
100
  this.tip = new fields_1.Amount({
107
101
  prediction: prediction.tip,
108
- valueKey: "value",
109
102
  pageId: pageId,
110
103
  });
111
104
  this.category = new fields_1.TextField({
@@ -120,17 +113,9 @@ class FinancialDocumentV1 extends document_1.Document {
120
113
  prediction: prediction.time,
121
114
  pageId: pageId,
122
115
  });
123
- prediction.taxes.map((taxPrediction) => this.taxes.push(new fields_1.TaxField({
124
- prediction: taxPrediction,
125
- pageId: pageId,
126
- valueKey: "value",
127
- rateKey: "rate",
128
- codeKey: "code",
129
- baseKey: "base",
130
- })));
116
+ this.taxes = new fields_1.Taxes().init(prediction["taxes"], pageId);
131
117
  }
132
118
  toString() {
133
- const taxes = this.taxes.map((item) => item.toString()).join("\n ");
134
119
  const referenceNumbers = this.referenceNumbers
135
120
  .map((item) => item.toString())
136
121
  .join(", ");
@@ -149,31 +134,31 @@ class FinancialDocumentV1 extends document_1.Document {
149
134
  "\n Code | QTY | Price | Amount | Tax (Rate) | Description\n ";
150
135
  lineItems += this.lineItems.map((item) => item.toString()).join("\n ");
151
136
  }
152
- const outStr = `----- Financial Document V1 -----
153
- Filename: ${this.filename}
154
- Document type: ${this.documentType}
155
- Category: ${this.category}
156
- Subcategory: ${this.subCategory}
157
- Locale: ${this.locale}
158
- Invoice number: ${this.invoiceNumber}
159
- Reference numbers: ${referenceNumbers}
160
- Date: ${this.date}
161
- Due date: ${this.dueDate}
162
- Time: ${this.time}
163
- Supplier name: ${this.supplierName}
164
- Supplier address: ${this.supplierAddress}
165
- Supplier company registrations: ${supplierCompanyRegistration}
166
- Supplier payment details: ${paymentDetails}
167
- Customer name: ${this.customerName}
168
- Customer address: ${this.customerAddress}
169
- Customer company registrations: ${customerCompanyRegistration}
170
- Tip: ${this.tip}
171
- Taxes: ${taxes}
172
- Total tax: ${this.totalTax}
173
- Total net: ${this.totalNet}
174
- Total amount: ${this.totalAmount}
175
- Line Items: ${lineItems}
176
- ----------------------
137
+ const outStr = `Financial Document V1 Prediction
138
+ ================================
139
+ :Filename: ${this.filename}
140
+ :Document type: ${this.documentType}
141
+ :Category: ${this.category}
142
+ :Subcategory: ${this.subCategory}
143
+ :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}
149
+ :Supplier name: ${this.supplierName}
150
+ :Supplier address: ${this.supplierAddress}
151
+ :Supplier company registrations: ${supplierCompanyRegistration}
152
+ :Supplier payment details: ${paymentDetails}
153
+ :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}
177
162
  `;
178
163
  return FinancialDocumentV1.cleanOutString(outStr);
179
164
  }
@@ -3,6 +3,7 @@ export { InvoiceV4 } from "./invoice/invoiceV4";
3
3
  export { InvoiceSplitterV1, PageGroup, } from "./invoiceSplitter/invoiceSplitterV1";
4
4
  export { ReceiptV3 } from "./receipt/receiptV3";
5
5
  export { ReceiptV4 } from "./receipt/receiptV4";
6
+ export { ReceiptV5 } from "./receipt/receiptV5";
6
7
  export { PassportV1 } from "./passport/passportV1";
7
8
  export { FinancialDocumentV0 } from "./financialDocument/financialDocumentV0";
8
9
  export { FinancialDocumentV1 } from "./financialDocument/financialDocumentV1";
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.eu = exports.us = exports.fr = exports.Document = exports.ShippingContainerV1 = exports.ProofOfAddressV1 = exports.MindeeVisionV1 = exports.CropperV1 = exports.getLineItems = exports.CustomV1 = exports.FinancialDocumentV1 = exports.FinancialDocumentV0 = exports.PassportV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PageGroup = exports.InvoiceSplitterV1 = exports.InvoiceV4 = exports.InvoiceV3 = void 0;
26
+ exports.eu = exports.us = exports.fr = exports.Document = exports.ShippingContainerV1 = exports.ProofOfAddressV1 = exports.MindeeVisionV1 = exports.CropperV1 = exports.getLineItems = exports.CustomV1 = exports.FinancialDocumentV1 = exports.FinancialDocumentV0 = exports.PassportV1 = exports.ReceiptV5 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PageGroup = exports.InvoiceSplitterV1 = exports.InvoiceV4 = exports.InvoiceV3 = void 0;
27
27
  var invoiceV3_1 = require("./invoice/invoiceV3");
28
28
  Object.defineProperty(exports, "InvoiceV3", { enumerable: true, get: function () { return invoiceV3_1.InvoiceV3; } });
29
29
  var invoiceV4_1 = require("./invoice/invoiceV4");
@@ -35,6 +35,8 @@ var receiptV3_1 = require("./receipt/receiptV3");
35
35
  Object.defineProperty(exports, "ReceiptV3", { enumerable: true, get: function () { return receiptV3_1.ReceiptV3; } });
36
36
  var receiptV4_1 = require("./receipt/receiptV4");
37
37
  Object.defineProperty(exports, "ReceiptV4", { enumerable: true, get: function () { return receiptV4_1.ReceiptV4; } });
38
+ var receiptV5_1 = require("./receipt/receiptV5");
39
+ Object.defineProperty(exports, "ReceiptV5", { enumerable: true, get: function () { return receiptV5_1.ReceiptV5; } });
38
40
  var passportV1_1 = require("./passport/passportV1");
39
41
  Object.defineProperty(exports, "PassportV1", { enumerable: true, get: function () { return passportV1_1.PassportV1; } });
40
42
  var financialDocumentV0_1 = require("./financialDocument/financialDocumentV0");
@@ -1,5 +1,5 @@
1
1
  import { Document, DocumentConstructorProps } from "../document";
2
- import { BaseField, TaxField, PaymentDetails, Locale, Amount, TextField, DateField, CompanyRegistration } from "../../fields";
2
+ import { BaseField, Taxes, PaymentDetails, Locale, Amount, TextField, DateField, CompanyRegistration } from "../../fields";
3
3
  export declare class InvoiceV3 extends Document {
4
4
  #private;
5
5
  /** Total amount with the tax amount of the purchase. */
@@ -31,7 +31,7 @@ export declare class InvoiceV3 extends Document {
31
31
  /** The address of the customer. */
32
32
  customerAddress: TextField;
33
33
  /** The list of the taxes. */
34
- taxes: TaxField[];
34
+ taxes: Taxes;
35
35
  /** The payment information. */
36
36
  paymentDetails: PaymentDetails[];
37
37
  /** The company registration information for the customer. */
@@ -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 _InvoiceV3_instances, _InvoiceV3_initFromApiPrediction, _InvoiceV3_checklist, _InvoiceV3_reconstruct;
7
+ var _InvoiceV3_instances, _InvoiceV3_checklist, _InvoiceV3_reconstruct;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.InvoiceV3 = void 0;
10
10
  const document_1 = require("../document");
@@ -39,18 +39,77 @@ class InvoiceV3 extends document_1.Document {
39
39
  _InvoiceV3_instances.add(this);
40
40
  /** The company regitration information. */
41
41
  this.companyRegistration = [];
42
- /** The list of the taxes. */
43
- this.taxes = [];
44
42
  /** The payment information. */
45
43
  this.paymentDetails = [];
46
44
  /** The company registration information for the customer. */
47
45
  this.customerCompanyRegistration = [];
48
- __classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_initFromApiPrediction).call(this, prediction, pageId);
46
+ this.locale = new fields_1.Locale({
47
+ prediction: prediction.locale,
48
+ valueKey: "language",
49
+ });
50
+ this.documentType = new fields_1.BaseField({
51
+ prediction: prediction.document_type,
52
+ });
53
+ this.totalIncl = new fields_1.Amount({
54
+ prediction: prediction.total_incl,
55
+ pageId: pageId,
56
+ });
57
+ this.totalAmount = this.totalIncl;
58
+ this.totalTax = new fields_1.Amount({
59
+ prediction: { value: undefined, confidence: 0.0 },
60
+ pageId: pageId,
61
+ });
62
+ this.totalNet = new fields_1.Amount({
63
+ prediction: prediction.total_excl,
64
+ pageId: pageId,
65
+ });
66
+ this.date = new fields_1.DateField({
67
+ prediction: prediction.date,
68
+ pageId,
69
+ });
70
+ this.taxes = new fields_1.Taxes().init(prediction["taxes"], pageId);
71
+ this.companyRegistration = prediction.company_registration.map(function (prediction) {
72
+ return new fields_1.CompanyRegistration({
73
+ prediction: prediction,
74
+ pageId: pageId,
75
+ });
76
+ });
77
+ this.dueDate = new fields_1.DateField({
78
+ prediction: prediction.due_date,
79
+ pageId: pageId,
80
+ });
81
+ this.invoiceNumber = new fields_1.TextField({
82
+ prediction: prediction.invoice_number,
83
+ pageId: pageId,
84
+ });
85
+ this.supplier = new fields_1.TextField({
86
+ prediction: prediction.supplier,
87
+ pageId: pageId,
88
+ });
89
+ this.supplierAddress = new fields_1.TextField({
90
+ prediction: prediction.supplier_address,
91
+ pageId: pageId,
92
+ });
93
+ this.customerName = new fields_1.TextField({
94
+ prediction: prediction.customer,
95
+ pageId: pageId,
96
+ });
97
+ this.customerAddress = new fields_1.TextField({
98
+ prediction: prediction.customer_address,
99
+ pageId: pageId,
100
+ });
101
+ prediction.customer_company_registration.map((prediction) => this.customerCompanyRegistration.push(new fields_1.CompanyRegistration({
102
+ prediction: prediction,
103
+ pageId: pageId,
104
+ })));
105
+ prediction.payment_details.map((prediction) => this.paymentDetails.push(new fields_1.PaymentDetails({
106
+ prediction: prediction,
107
+ pageId: pageId,
108
+ })));
49
109
  __classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_checklist).call(this);
50
110
  __classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_reconstruct).call(this);
51
111
  }
52
112
  toString() {
53
- const taxes = this.taxes.map((item) => item.toString()).join("\n ");
54
113
  const paymentDetails = this.paymentDetails
55
114
  .map((item) => item.toString())
56
115
  .join("\n ");
@@ -60,104 +119,30 @@ class InvoiceV3 extends document_1.Document {
60
119
  const companyRegistration = this.companyRegistration
61
120
  .map((item) => item.toString())
62
121
  .join("; ");
63
- const outStr = `----- Invoice V3 -----
64
- Filename: ${this.filename}
65
- Invoice number: ${this.invoiceNumber}
66
- Total amount including taxes: ${this.totalIncl}
67
- Total amount excluding taxes: ${this.totalExcl}
68
- Invoice date: ${this.date}
69
- Invoice due date: ${this.dueDate}
70
- Supplier name: ${this.supplier}
71
- Supplier address: ${this.supplierAddress}
72
- Customer name: ${this.customerName}
73
- Customer company registration: ${customerCompanyRegistration}
74
- Customer address: ${this.customerAddress}
75
- Payment details: ${paymentDetails}
76
- Company numbers: ${companyRegistration}
77
- Taxes: ${taxes}
78
- Total taxes: ${this.totalTax}
79
- Locale: ${this.locale}
80
- ----------------------
122
+ const outStr = `Invoice V3 Prediction
123
+ =====================
124
+ :Filename: ${this.filename}
125
+ :Invoice number: ${this.invoiceNumber}
126
+ :Total amount: ${this.totalIncl}
127
+ :Total net: ${this.totalExcl}
128
+ :Invoice date: ${this.date}
129
+ :Invoice due date: ${this.dueDate}
130
+ :Supplier name: ${this.supplier}
131
+ :Supplier address: ${this.supplierAddress}
132
+ :Customer name: ${this.customerName}
133
+ :Customer company registration: ${customerCompanyRegistration}
134
+ :Customer address: ${this.customerAddress}
135
+ :Payment details: ${paymentDetails}
136
+ :Company numbers: ${companyRegistration}
137
+ :Taxes: ${this.taxes}
138
+ :Total tax: ${this.totalTax}
139
+ :Locale: ${this.locale}
81
140
  `;
82
141
  return InvoiceV3.cleanOutString(outStr);
83
142
  }
84
143
  }
85
144
  exports.InvoiceV3 = InvoiceV3;
86
- _InvoiceV3_instances = new WeakSet(), _InvoiceV3_initFromApiPrediction = function _InvoiceV3_initFromApiPrediction(apiPrediction, pageId) {
87
- this.locale = new fields_1.Locale({
88
- prediction: apiPrediction.locale,
89
- valueKey: "language",
90
- });
91
- this.documentType = new fields_1.BaseField({
92
- prediction: apiPrediction.document_type,
93
- valueKey: "value",
94
- });
95
- this.totalIncl = new fields_1.Amount({
96
- prediction: apiPrediction.total_incl,
97
- valueKey: "value",
98
- pageId: pageId,
99
- });
100
- this.totalAmount = this.totalIncl;
101
- this.totalTax = new fields_1.Amount({
102
- prediction: { value: undefined, confidence: 0.0 },
103
- valueKey: "value",
104
- pageId: pageId,
105
- });
106
- this.totalNet = new fields_1.Amount({
107
- prediction: apiPrediction.total_excl,
108
- valueKey: "value",
109
- pageId: pageId,
110
- });
111
- this.date = new fields_1.DateField({
112
- prediction: apiPrediction.date,
113
- pageId,
114
- });
115
- apiPrediction.taxes.map((prediction) => this.taxes.push(new fields_1.TaxField({
116
- prediction: prediction,
117
- pageId: pageId,
118
- valueKey: "value",
119
- rateKey: "rate",
120
- codeKey: "code",
121
- })));
122
- this.companyRegistration = apiPrediction.company_registration.map(function (prediction) {
123
- return new fields_1.CompanyRegistration({
124
- prediction: prediction,
125
- pageId: pageId,
126
- });
127
- });
128
- this.dueDate = new fields_1.DateField({
129
- prediction: apiPrediction.due_date,
130
- pageId: pageId,
131
- });
132
- this.invoiceNumber = new fields_1.TextField({
133
- prediction: apiPrediction.invoice_number,
134
- pageId: pageId,
135
- });
136
- this.supplier = new fields_1.TextField({
137
- prediction: apiPrediction.supplier,
138
- pageId: pageId,
139
- });
140
- this.supplierAddress = new fields_1.TextField({
141
- prediction: apiPrediction.supplier_address,
142
- pageId: pageId,
143
- });
144
- this.customerName = new fields_1.TextField({
145
- prediction: apiPrediction.customer,
146
- pageId: pageId,
147
- });
148
- this.customerAddress = new fields_1.TextField({
149
- prediction: apiPrediction.customer_address,
150
- pageId: pageId,
151
- });
152
- apiPrediction.customer_company_registration.map((prediction) => this.customerCompanyRegistration.push(new fields_1.CompanyRegistration({
153
- prediction: prediction,
154
- pageId: pageId,
155
- })));
156
- apiPrediction.payment_details.map((prediction) => this.paymentDetails.push(new fields_1.PaymentDetails({
157
- prediction: prediction,
158
- pageId: pageId,
159
- })));
160
- }, _InvoiceV3_checklist = function _InvoiceV3_checklist() {
145
+ _InvoiceV3_instances = new WeakSet(), _InvoiceV3_checklist = function _InvoiceV3_checklist() {
161
146
  this.checklist = {
162
147
  taxesMatchTotalIncl: (0, checks_1.taxesMatchTotalIncl)(this),
163
148
  taxesMatchTotalExcl: (0, checks_1.taxesMatchTotalExcl)(this),
@@ -1,5 +1,5 @@
1
1
  import { Document, DocumentConstructorProps } from "../document";
2
- import { ClassificationField, TaxField, PaymentDetails, Locale, Amount, TextField, DateField, CompanyRegistration } from "../../fields";
2
+ import { ClassificationField, Taxes, PaymentDetails, Locale, Amount, TextField, DateField, CompanyRegistration } from "../../fields";
3
3
  import { InvoiceLineItem } from "./invoiceLineItem";
4
4
  /** Invoice V4 */
5
5
  export declare class InvoiceV4 extends Document {
@@ -37,7 +37,7 @@ export declare class InvoiceV4 extends Document {
37
37
  /** The company registration information for the customer. */
38
38
  customerCompanyRegistrations: CompanyRegistration[];
39
39
  /** The list of the taxes. */
40
- taxes: TaxField[];
40
+ taxes: Taxes;
41
41
  /** Line items details. */
42
42
  lineItems: InvoiceLineItem[];
43
43
  constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
@@ -31,8 +31,6 @@ class InvoiceV4 extends document_1.Document {
31
31
  this.supplierCompanyRegistrations = [];
32
32
  /** The company registration information for the customer. */
33
33
  this.customerCompanyRegistrations = [];
34
- /** The list of the taxes. */
35
- this.taxes = [];
36
34
  /** Line items details. */
37
35
  this.lineItems = [];
38
36
  this.locale = new fields_1.Locale({
@@ -41,7 +39,6 @@ class InvoiceV4 extends document_1.Document {
41
39
  });
42
40
  this.documentType = new fields_1.ClassificationField({
43
41
  prediction: prediction.document_type,
44
- valueKey: "value",
45
42
  });
46
43
  this.referenceNumbers = prediction.reference_numbers.map(function (prediction) {
47
44
  return new fields_1.TextField({
@@ -51,30 +48,21 @@ class InvoiceV4 extends document_1.Document {
51
48
  });
52
49
  this.totalAmount = new fields_1.Amount({
53
50
  prediction: prediction.total_amount,
54
- valueKey: "value",
55
51
  pageId: pageId,
56
52
  });
57
53
  this.totalTax = new fields_1.Amount({
58
54
  prediction: { value: undefined, confidence: 0.0 },
59
- valueKey: "value",
60
55
  pageId: pageId,
61
56
  });
62
57
  this.totalNet = new fields_1.Amount({
63
58
  prediction: prediction.total_net,
64
- valueKey: "value",
65
59
  pageId: pageId,
66
60
  });
67
61
  this.date = new fields_1.DateField({
68
62
  prediction: prediction.date,
69
63
  pageId,
70
64
  });
71
- prediction.taxes.map((prediction) => this.taxes.push(new fields_1.TaxField({
72
- prediction: prediction,
73
- pageId: pageId,
74
- valueKey: "value",
75
- rateKey: "rate",
76
- codeKey: "code",
77
- })));
65
+ this.taxes = new fields_1.Taxes().init(prediction["taxes"], pageId);
78
66
  this.supplierCompanyRegistrations =
79
67
  prediction.supplier_company_registrations.map(function (prediction) {
80
68
  return new fields_1.CompanyRegistration({
@@ -121,7 +109,6 @@ class InvoiceV4 extends document_1.Document {
121
109
  __classPrivateFieldGet(this, _InvoiceV4_instances, "m", _InvoiceV4_reconstruct).call(this);
122
110
  }
123
111
  toString() {
124
- const taxes = this.taxes.map((item) => item.toString()).join("\n ");
125
112
  const referenceNumbers = this.referenceNumbers
126
113
  .map((item) => item.toString())
127
114
  .join(", ");
@@ -140,26 +127,26 @@ class InvoiceV4 extends document_1.Document {
140
127
  "\n Code | QTY | Price | Amount | Tax (Rate) | Description\n ";
141
128
  lineItems += this.lineItems.map((item) => item.toString()).join("\n ");
142
129
  }
143
- const outStr = `----- Invoice V4 -----
144
- Filename: ${this.filename}
145
- Locale: ${this.locale}
146
- Invoice number: ${this.invoiceNumber}
147
- Reference numbers: ${referenceNumbers}
148
- Invoice date: ${this.date}
149
- Invoice due date: ${this.dueDate}
150
- Supplier name: ${this.supplierName}
151
- Supplier address: ${this.supplierAddress}
152
- Supplier company registrations: ${companyRegistration}
153
- Supplier payment details: ${paymentDetails}
154
- Customer name: ${this.customerName}
155
- Customer company registrations: ${customerCompanyRegistration}
156
- Customer address: ${this.customerAddress}
157
- Line Items: ${lineItems}
158
- Taxes: ${taxes}
159
- Total taxes: ${this.totalTax}
160
- Total amount excluding taxes: ${this.totalNet}
161
- Total amount including taxes: ${this.totalAmount}
162
- ----------------------
130
+ const outStr = `Invoice V4 Prediction
131
+ =====================
132
+ :Filename: ${this.filename}
133
+ :Locale: ${this.locale}
134
+ :Invoice number: ${this.invoiceNumber}
135
+ :Reference numbers: ${referenceNumbers}
136
+ :Invoice date: ${this.date}
137
+ :Invoice due date: ${this.dueDate}
138
+ :Supplier name: ${this.supplierName}
139
+ :Supplier address: ${this.supplierAddress}
140
+ :Supplier company registrations: ${companyRegistration}
141
+ :Supplier payment details: ${paymentDetails}
142
+ :Customer name: ${this.customerName}
143
+ :Customer company registrations: ${customerCompanyRegistration}
144
+ :Customer address: ${this.customerAddress}
145
+ :Line Items: ${lineItems}
146
+ :Taxes: ${this.taxes}
147
+ :Total tax: ${this.totalTax}
148
+ :Total net: ${this.totalNet}
149
+ :Total amount: ${this.totalAmount}
163
150
  `;
164
151
  return InvoiceV4.cleanOutString(outStr);
165
152
  }
@@ -2,7 +2,7 @@ import { Document, DocumentConstructorProps } from "../document";
2
2
  import { CompanyRegistration, DateField, Locale, TextField } from "../../fields";
3
3
  export declare class ProofOfAddressV1 extends Document {
4
4
  /** ISO date yyyy-mm-dd. Works both for European and US dates. */
5
- issuanceDate: DateField;
5
+ date: DateField;
6
6
  /** All extrated ISO date yyyy-mm-dd. Works both for European and US dates. */
7
7
  dates: DateField[];
8
8
  /** Address of the document's issuer. */
@@ -20,7 +20,7 @@ class ProofOfAddressV1 extends document_1.Document {
20
20
  this.locale = new fields_1.Locale({
21
21
  prediction: prediction.locale,
22
22
  });
23
- this.issuanceDate = new fields_1.DateField({
23
+ this.date = new fields_1.DateField({
24
24
  prediction: prediction.date,
25
25
  pageId: pageId,
26
26
  });
@@ -68,7 +68,7 @@ Recipient Company Registrations: ${this.recipientCompanyRegistration
68
68
  .join(", ")}
69
69
  Recipient Address: ${this.recipientAddress}
70
70
  Dates: ${this.dates.map((rcr) => rcr.value).join("\n ")}
71
- Date of Issue: ${this.issuanceDate}
71
+ Date of Issue: ${this.date}
72
72
  ----------------------
73
73
  `;
74
74
  return ProofOfAddressV1.cleanOutString(outStr);
@@ -18,7 +18,7 @@ export declare class ReceiptV3 extends Document {
18
18
  totalTax: Amount;
19
19
  /** Total amount without tax of the purchase. */
20
20
  totalExcl: Amount;
21
- /** List of different taxe. */
21
+ /** List of different taxes. */
22
22
  taxes: TaxField[];
23
23
  constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
24
24
  toString(): string;
@@ -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; } });