mindee 3.5.0 → 3.6.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,25 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v3.6.0 - 2023-02-01
4
+ ### Changes
5
+ * :sparkles: Add support for the mindee_vision API (for internal testing)
6
+ * :sparkles: support Proof of Address V1
7
+ * :sparkles: Add support for: financial document v1
8
+ * :arrow_up: update jsdoc
9
+
10
+ ### ¡Warning!
11
+ The `FinancialDocumentV1` class now uses an actual API call to the new route `financial_document`.
12
+ Previously, determining whether a document is an invoice or a receipt was done internally by this library.
13
+
14
+ The API call way is **much** better, however some fields have been renamed compared to the internal handling.
15
+ This was done so field names now match exactly `Invoice` and `Receipt` classes.
16
+
17
+ As such, we encourage users to migrate to the new field structure.
18
+
19
+ If this is problematic, it's possible to use the deprecated way.
20
+ Simply pass `FinancialDocumentV0` to the `parse` method.
21
+ Usage is otherwise identical.
22
+
3
23
  ## v3.5.0 - 2023-01-17
4
24
  ### Changes
5
25
  * :memo: updates to class documentation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
@@ -12,7 +12,7 @@
12
12
  "test": "mocha 'tests/**/*.spec.ts'",
13
13
  "lint-fix": "eslint '**/*.ts' --fix",
14
14
  "lint": "eslint '**/*.ts' --report-unused-disable-directives && echo 'Your .ts files look good.'",
15
- "docs": "jsdoc -r src -d docs"
15
+ "docs": "jsdoc -r dist/src -d docs"
16
16
  },
17
17
  "files": [
18
18
  "src/*",
@@ -47,7 +47,7 @@
47
47
  "eslint": "^8.31.0",
48
48
  "eslint-config-prettier": "^8.6.0",
49
49
  "eslint-plugin-prettier": "^4.2.1",
50
- "jsdoc": "^3.6.11",
50
+ "jsdoc": "~4.0",
51
51
  "mocha": "^10.1.0",
52
52
  "prettier": "^2.8.1",
53
53
  "ts-node": "^10.9.1",
package/src/cli.js CHANGED
@@ -54,7 +54,7 @@ const CLI_COMMAND_CONFIG = new Map([
54
54
  [
55
55
  "financial",
56
56
  {
57
- description: "Financial Document (receipt or invoice)",
57
+ description: "Financial Document",
58
58
  docClass: documents_1.FinancialDocumentV1,
59
59
  fullText: true,
60
60
  },
@@ -107,6 +107,14 @@ const CLI_COMMAND_CONFIG = new Map([
107
107
  fullText: false,
108
108
  },
109
109
  ],
110
+ [
111
+ "mvision",
112
+ {
113
+ description: "Mindee Vision",
114
+ docClass: documents_1.MindeeVisionV1,
115
+ fullText: false,
116
+ },
117
+ ],
110
118
  ]);
111
119
  async function predictCall(command, inputPath, options) {
112
120
  const conf = CLI_COMMAND_CONFIG.get(command);
package/src/client.js CHANGED
@@ -79,7 +79,10 @@ class Client {
79
79
  }
80
80
  // TODO: init only those endpoints we actually need.
81
81
  addStandardEndpoints() {
82
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.FinancialDocumentV1.name], new documentConfig_1.FinancialDocV1Config(this.apiKey));
82
+ this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.FinancialDocumentV0.name], new documentConfig_1.FinancialDocV0Config(this.apiKey));
83
+ this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.FinancialDocumentV1.name], new documentConfig_1.DocumentConfig(documents_1.FinancialDocumentV1, [
84
+ new api_1.StandardEndpoint("financial_document", "1", this.apiKey),
85
+ ]));
83
86
  this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.InvoiceV3.name], new documentConfig_1.DocumentConfig(documents_1.InvoiceV3, [
84
87
  new api_1.StandardEndpoint("invoices", "3", this.apiKey),
85
88
  ]));
@@ -119,6 +122,12 @@ class Client {
119
122
  this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ShippingContainerV1.name], new documentConfig_1.DocumentConfig(documents_1.ShippingContainerV1, [
120
123
  new api_1.StandardEndpoint("shipping_containers", "1", this.apiKey),
121
124
  ]));
125
+ this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.MindeeVisionV1.name], new documentConfig_1.DocumentConfig(documents_1.MindeeVisionV1, [
126
+ new api_1.StandardEndpoint("mindee_vision", "1", this.apiKey),
127
+ ]));
128
+ this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ProofOfAddressV1.name], new documentConfig_1.DocumentConfig(documents_1.ProofOfAddressV1, [
129
+ new api_1.StandardEndpoint("proof_of_address", "1", this.apiKey),
130
+ ]));
122
131
  }
123
132
  /**
124
133
  * Add a custom endpoint to the client.
@@ -1,6 +1,6 @@
1
1
  import { InputSource } from "../inputs";
2
2
  import { Response, Endpoint, predictResponse } from "../api";
3
- import { Document, FinancialDocumentV1, CustomV1, DocumentSig } from "./index";
3
+ import { Document, FinancialDocumentV0, CustomV1, DocumentSig } from "./index";
4
4
  import { PageOptions } from "../inputs";
5
5
  interface CustomDocConstructor {
6
6
  endpointName: string;
@@ -27,7 +27,7 @@ export declare class DocumentConfig<DocType extends Document> {
27
27
  export declare class CustomDocConfig extends DocumentConfig<CustomV1> {
28
28
  constructor({ endpointName, accountName, version, apiKey, }: CustomDocConstructor);
29
29
  }
30
- export declare class FinancialDocV1Config extends DocumentConfig<FinancialDocumentV1> {
30
+ export declare class FinancialDocV0Config extends DocumentConfig<FinancialDocumentV0> {
31
31
  constructor(apiKey: string);
32
32
  protected predictRequest(inputDoc: InputSource, includeWords: boolean, cropping: boolean): Promise<predictResponse>;
33
33
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FinancialDocV1Config = exports.CustomDocConfig = exports.DocumentConfig = void 0;
3
+ exports.FinancialDocV0Config = exports.CustomDocConfig = exports.DocumentConfig = void 0;
4
4
  const api_1 = require("../api");
5
5
  const index_1 = require("./index");
6
6
  const handler_1 = require("../errors/handler");
@@ -65,13 +65,13 @@ class CustomDocConfig extends DocumentConfig {
65
65
  }
66
66
  }
67
67
  exports.CustomDocConfig = CustomDocConfig;
68
- class FinancialDocV1Config extends DocumentConfig {
68
+ class FinancialDocV0Config extends DocumentConfig {
69
69
  constructor(apiKey) {
70
70
  const endpoints = [
71
71
  new api_1.StandardEndpoint("invoices", "3", apiKey),
72
72
  new api_1.StandardEndpoint("expense_receipts", "3", apiKey),
73
73
  ];
74
- super(index_1.FinancialDocumentV1, endpoints);
74
+ super(index_1.FinancialDocumentV0, endpoints);
75
75
  }
76
76
  async predictRequest(inputDoc, includeWords, cropping) {
77
77
  let endpoint;
@@ -84,4 +84,4 @@ class FinancialDocV1Config extends DocumentConfig {
84
84
  return await endpoint.predictReqPost(inputDoc, includeWords, cropping);
85
85
  }
86
86
  }
87
- exports.FinancialDocV1Config = FinancialDocV1Config;
87
+ exports.FinancialDocV0Config = FinancialDocV0Config;
@@ -0,0 +1,28 @@
1
+ import { Document, DocumentConstructorProps } from "../document";
2
+ import { TaxField, TextField, Amount, Locale, DateField as Date, CompanyRegistration } from "../../fields";
3
+ /**
4
+ * @deprecated You should use FinancialDocumentV1 instead.
5
+ */
6
+ export declare class FinancialDocumentV0 extends Document {
7
+ #private;
8
+ pageId: number | undefined;
9
+ locale: Locale;
10
+ totalIncl: Amount;
11
+ date: Date;
12
+ dueDate: Date;
13
+ category: TextField;
14
+ time: TextField;
15
+ taxes: TaxField[];
16
+ totalTax: Amount;
17
+ totalExcl: Amount;
18
+ supplier: TextField;
19
+ supplierAddress: TextField;
20
+ invoiceNumber: TextField;
21
+ companyRegistration: CompanyRegistration[];
22
+ customerName: TextField;
23
+ customerAddress: TextField;
24
+ paymentDetails: TextField[];
25
+ customerCompanyRegistration: CompanyRegistration[];
26
+ constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
27
+ toString(): string;
28
+ }
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _FinancialDocumentV0_instances, _FinancialDocumentV0_initFromApiPrediction, _FinancialDocumentV0_checklist, _FinancialDocumentV0_taxesMatchTotalIncl;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.FinancialDocumentV0 = void 0;
10
+ const document_1 = require("../document");
11
+ const invoiceV3_1 = require("../invoice/invoiceV3");
12
+ const receiptV3_1 = require("../receipt/receiptV3");
13
+ const fields_1 = require("../../fields");
14
+ /**
15
+ * @deprecated You should use FinancialDocumentV1 instead.
16
+ */
17
+ class FinancialDocumentV0 extends document_1.Document {
18
+ constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {
19
+ super({
20
+ inputSource: inputSource,
21
+ pageId: pageId,
22
+ orientation: orientation,
23
+ fullText: fullText,
24
+ extras: extras,
25
+ });
26
+ _FinancialDocumentV0_instances.add(this);
27
+ this.taxes = [];
28
+ this.companyRegistration = [];
29
+ this.paymentDetails = [];
30
+ this.customerCompanyRegistration = [];
31
+ __classPrivateFieldGet(this, _FinancialDocumentV0_instances, "m", _FinancialDocumentV0_initFromApiPrediction).call(this, prediction, inputSource, pageId, orientation, extras);
32
+ __classPrivateFieldGet(this, _FinancialDocumentV0_instances, "m", _FinancialDocumentV0_checklist).call(this);
33
+ }
34
+ toString() {
35
+ const outStr = `-----Financial document-----
36
+ Filename: ${this.filename}
37
+ Total amount: ${this.totalIncl.value}
38
+ Date: ${this.date.value}
39
+ Supplier: ${this.supplier.value}
40
+ Total taxes: ${this.totalTax.value}
41
+ ----------------------
42
+ `;
43
+ return FinancialDocumentV0.cleanOutString(outStr);
44
+ }
45
+ }
46
+ exports.FinancialDocumentV0 = FinancialDocumentV0;
47
+ _FinancialDocumentV0_instances = new WeakSet(), _FinancialDocumentV0_initFromApiPrediction = function _FinancialDocumentV0_initFromApiPrediction(prediction, inputFile, pageNumber, orientation, extras) {
48
+ if (Object.keys(prediction).includes("invoice_number")) {
49
+ const invoice = new invoiceV3_1.InvoiceV3({
50
+ prediction: prediction,
51
+ inputSource: inputFile,
52
+ pageId: pageNumber,
53
+ orientation: orientation,
54
+ extras: extras,
55
+ });
56
+ this.locale = invoice.locale;
57
+ this.totalIncl = invoice.totalIncl;
58
+ this.totalExcl = invoice.totalExcl;
59
+ this.date = invoice.date;
60
+ this.invoiceNumber = invoice.invoiceNumber;
61
+ this.dueDate = invoice.dueDate;
62
+ this.taxes = invoice.taxes;
63
+ this.supplier = invoice.supplier;
64
+ this.supplierAddress = invoice.supplierAddress;
65
+ this.paymentDetails = invoice.paymentDetails;
66
+ this.companyRegistration = invoice.customerCompanyRegistration;
67
+ this.orientation = invoice.orientation;
68
+ this.totalTax = invoice.totalTax;
69
+ this.time = new fields_1.TextField({
70
+ prediction: { value: undefined, confidence: 0.0 },
71
+ });
72
+ this.customerName = invoice.customerName;
73
+ this.customerAddress = invoice.customerAddress;
74
+ this.customerCompanyRegistration = invoice.customerCompanyRegistration;
75
+ }
76
+ else {
77
+ const receipt = new receiptV3_1.ReceiptV3({
78
+ prediction: prediction,
79
+ inputSource: inputFile,
80
+ pageId: pageNumber,
81
+ orientation: orientation,
82
+ extras: extras,
83
+ });
84
+ this.orientation = receipt.orientation;
85
+ this.date = receipt.date;
86
+ this.dueDate = receipt.date;
87
+ this.taxes = receipt.taxes;
88
+ this.locale = receipt.locale;
89
+ this.totalIncl = receipt.totalIncl;
90
+ this.totalExcl = receipt.totalExcl;
91
+ this.supplier = receipt.merchantName;
92
+ this.supplierAddress = new fields_1.TextField({
93
+ prediction: { value: undefined, confidence: 0.0 },
94
+ });
95
+ this.time = receipt.time;
96
+ this.totalTax = receipt.totalTax;
97
+ this.invoiceNumber = new fields_1.TextField({
98
+ prediction: { value: undefined, confidence: 0.0 },
99
+ });
100
+ this.customerName = new fields_1.TextField({
101
+ prediction: { value: undefined, confidence: 0.0 },
102
+ });
103
+ this.customerAddress = new fields_1.TextField({
104
+ prediction: { value: undefined, confidence: 0.0 },
105
+ });
106
+ }
107
+ }, _FinancialDocumentV0_checklist = function _FinancialDocumentV0_checklist() {
108
+ this.checklist = {
109
+ taxesMatchTotalIncl: __classPrivateFieldGet(this, _FinancialDocumentV0_instances, "m", _FinancialDocumentV0_taxesMatchTotalIncl).call(this),
110
+ };
111
+ }, _FinancialDocumentV0_taxesMatchTotalIncl = function _FinancialDocumentV0_taxesMatchTotalIncl() {
112
+ // Check taxes and total include exist
113
+ if (this.taxes.length === 0 || this.totalIncl.value === undefined)
114
+ return false;
115
+ // Reconstruct totalIncl from taxes
116
+ let totalVat = 0;
117
+ let reconstructedTotal = 0;
118
+ this.taxes.forEach((tax) => {
119
+ if (tax.value === undefined || !tax.rate)
120
+ return false;
121
+ totalVat += tax.value;
122
+ reconstructedTotal += tax.value + (100 * tax.value) / tax.rate;
123
+ });
124
+ // Sanity check
125
+ if (totalVat <= 0)
126
+ return false;
127
+ // Crate epsilon
128
+ const eps = 1 / (100 * totalVat);
129
+ if (this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal &&
130
+ reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02) {
131
+ this.taxes = this.taxes.map((tax) => ({
132
+ ...tax,
133
+ confidence: 1.0,
134
+ }));
135
+ this.totalTax.confidence = 1.0;
136
+ this.totalIncl.confidence = 1.0;
137
+ return true;
138
+ }
139
+ return false;
140
+ };
@@ -1,25 +1,54 @@
1
1
  import { Document, DocumentConstructorProps } from "../document";
2
- import { TaxField, TextField, Amount, Locale, DateField as Date, CompanyRegistration } from "../../fields";
2
+ import { TaxField, PaymentDetails, Locale, Amount, TextField, DateField, CompanyRegistration, BaseField } from "../../fields";
3
+ import { InvoiceLineItem } from "../invoice/invoiceLineItem";
4
+ /**
5
+ * Financial Document.
6
+ */
3
7
  export declare class FinancialDocumentV1 extends Document {
4
- #private;
5
- pageId: number | undefined;
8
+ /** Locale information. */
6
9
  locale: Locale;
7
- totalIncl: Amount;
8
- date: Date;
9
- dueDate: Date;
10
- category: TextField;
11
- time: TextField;
12
- taxes: TaxField[];
13
- totalTax: Amount;
14
- totalExcl: Amount;
15
- supplier: TextField;
10
+ /** The nature of the document. */
11
+ documentType: BaseField;
12
+ /** List of Reference numbers including PO number. */
13
+ referenceNumbers: TextField[];
14
+ /** The creation date of the invoice or the purchase date. */
15
+ date: DateField;
16
+ /** The due date of the invoice. */
17
+ dueDate: DateField;
18
+ /** The supplier name. */
19
+ supplierName: TextField;
20
+ /** The supplier address. */
16
21
  supplierAddress: TextField;
22
+ /** The payment information. */
23
+ supplierPaymentDetails: PaymentDetails[];
24
+ /** The supplier company registration information. */
25
+ supplierCompanyRegistrations: CompanyRegistration[];
26
+ /** The invoice number. */
17
27
  invoiceNumber: TextField;
18
- companyRegistration: CompanyRegistration[];
28
+ /** The name of the customer. */
19
29
  customerName: TextField;
30
+ /** The address of the customer. */
20
31
  customerAddress: TextField;
21
- paymentDetails: TextField[];
22
- customerCompanyRegistration: CompanyRegistration[];
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. */
51
+ totalTax: Amount;
23
52
  constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
24
53
  toString(): string;
25
54
  }
@@ -1,16 +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 _FinancialDocumentV1_instances, _FinancialDocumentV1_initFromApiPrediction, _FinancialDocumentV1_checklist, _FinancialDocumentV1_taxesMatchTotalIncl;
8
2
  Object.defineProperty(exports, "__esModule", { value: true });
9
3
  exports.FinancialDocumentV1 = void 0;
10
4
  const document_1 = require("../document");
11
- const invoiceV3_1 = require("../invoice/invoiceV3");
12
- const receiptV3_1 = require("../receipt/receiptV3");
13
5
  const fields_1 = require("../../fields");
6
+ const invoiceLineItem_1 = require("../invoice/invoiceLineItem");
7
+ /**
8
+ * Financial Document.
9
+ */
14
10
  class FinancialDocumentV1 extends document_1.Document {
15
11
  constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {
16
12
  super({
@@ -20,118 +16,166 @@ class FinancialDocumentV1 extends document_1.Document {
20
16
  fullText: fullText,
21
17
  extras: extras,
22
18
  });
23
- _FinancialDocumentV1_instances.add(this);
19
+ /** List of Reference numbers including PO number. */
20
+ this.referenceNumbers = [];
21
+ /** The payment information. */
22
+ this.supplierPaymentDetails = [];
23
+ /** The supplier company registration information. */
24
+ this.supplierCompanyRegistrations = [];
25
+ /** The company registration information for the customer. */
26
+ this.customerCompanyRegistrations = [];
27
+ /** The list of the taxes. */
24
28
  this.taxes = [];
25
- this.companyRegistration = [];
26
- this.paymentDetails = [];
27
- this.customerCompanyRegistration = [];
28
- __classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_initFromApiPrediction).call(this, prediction, inputSource, pageId, orientation, extras);
29
- __classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_checklist).call(this);
30
- }
31
- toString() {
32
- const outStr = `-----Financial document-----
33
- Filename: ${this.filename}
34
- Total amount: ${this.totalIncl.value}
35
- Date: ${this.date.value}
36
- Supplier: ${this.supplier.value}
37
- Total taxes: ${this.totalTax.value}
38
- ----------------------
39
- `;
40
- return FinancialDocumentV1.cleanOutString(outStr);
41
- }
42
- }
43
- exports.FinancialDocumentV1 = FinancialDocumentV1;
44
- _FinancialDocumentV1_instances = new WeakSet(), _FinancialDocumentV1_initFromApiPrediction = function _FinancialDocumentV1_initFromApiPrediction(prediction, inputFile, pageNumber, orientation, extras) {
45
- if (Object.keys(prediction).includes("invoice_number")) {
46
- const invoice = new invoiceV3_1.InvoiceV3({
47
- prediction: prediction,
48
- inputSource: inputFile,
49
- pageId: pageNumber,
50
- orientation: orientation,
51
- extras: extras,
29
+ /** Line items details. */
30
+ this.lineItems = [];
31
+ this.locale = new fields_1.Locale({
32
+ prediction: prediction.locale,
33
+ valueKey: "language",
52
34
  });
53
- this.locale = invoice.locale;
54
- this.totalIncl = invoice.totalIncl;
55
- this.totalExcl = invoice.totalExcl;
56
- this.date = invoice.date;
57
- this.invoiceNumber = invoice.invoiceNumber;
58
- this.dueDate = invoice.dueDate;
59
- this.taxes = invoice.taxes;
60
- this.supplier = invoice.supplier;
61
- this.supplierAddress = invoice.supplierAddress;
62
- this.paymentDetails = invoice.paymentDetails;
63
- this.companyRegistration = invoice.customerCompanyRegistration;
64
- this.orientation = invoice.orientation;
65
- this.totalTax = invoice.totalTax;
66
- this.time = new fields_1.TextField({
67
- prediction: { value: undefined, confidence: 0.0 },
35
+ this.documentType = new fields_1.BaseField({
36
+ prediction: prediction.document_type,
37
+ valueKey: "value",
68
38
  });
69
- this.customerName = invoice.customerName;
70
- this.customerAddress = invoice.customerAddress;
71
- this.customerCompanyRegistration = invoice.customerCompanyRegistration;
72
- }
73
- else {
74
- const receipt = new receiptV3_1.ReceiptV3({
75
- prediction: prediction,
76
- inputSource: inputFile,
77
- pageId: pageNumber,
78
- orientation: orientation,
79
- extras: extras,
39
+ this.referenceNumbers = prediction.reference_numbers.map(function (prediction) {
40
+ return new fields_1.TextField({
41
+ prediction: prediction,
42
+ pageId: pageId,
43
+ });
80
44
  });
81
- this.orientation = receipt.orientation;
82
- this.date = receipt.date;
83
- this.dueDate = receipt.date;
84
- this.taxes = receipt.taxes;
85
- this.locale = receipt.locale;
86
- this.totalIncl = receipt.totalIncl;
87
- this.totalExcl = receipt.totalExcl;
88
- this.supplier = receipt.merchantName;
89
- this.supplierAddress = new fields_1.TextField({
90
- prediction: { value: undefined, confidence: 0.0 },
45
+ this.totalAmount = new fields_1.Amount({
46
+ prediction: prediction.total_amount,
47
+ valueKey: "value",
48
+ pageId: pageId,
49
+ });
50
+ this.totalTax = new fields_1.Amount({
51
+ prediction: prediction.total_tax,
52
+ valueKey: "value",
53
+ pageId: pageId,
54
+ });
55
+ this.totalNet = new fields_1.Amount({
56
+ prediction: prediction.total_net,
57
+ valueKey: "value",
58
+ pageId: pageId,
59
+ });
60
+ this.date = new fields_1.DateField({
61
+ prediction: prediction.date,
62
+ pageId,
63
+ });
64
+ this.dueDate = new fields_1.DateField({
65
+ prediction: prediction.due_date,
66
+ pageId: pageId,
91
67
  });
92
- this.time = receipt.time;
93
- this.totalTax = receipt.totalTax;
94
68
  this.invoiceNumber = new fields_1.TextField({
95
- prediction: { value: undefined, confidence: 0.0 },
69
+ prediction: prediction.invoice_number,
70
+ pageId: pageId,
71
+ });
72
+ this.supplierName = new fields_1.TextField({
73
+ prediction: prediction.supplier_name,
74
+ pageId: pageId,
75
+ });
76
+ this.supplierAddress = new fields_1.TextField({
77
+ prediction: prediction.supplier_address,
78
+ pageId: pageId,
96
79
  });
80
+ this.supplierCompanyRegistrations =
81
+ prediction.supplier_company_registrations.map(function (prediction) {
82
+ return new fields_1.CompanyRegistration({
83
+ prediction: prediction,
84
+ pageId: pageId,
85
+ });
86
+ });
97
87
  this.customerName = new fields_1.TextField({
98
- prediction: { value: undefined, confidence: 0.0 },
88
+ prediction: prediction.customer_name,
89
+ pageId: pageId,
99
90
  });
100
91
  this.customerAddress = new fields_1.TextField({
101
- prediction: { value: undefined, confidence: 0.0 },
92
+ prediction: prediction.customer_address,
93
+ pageId: pageId,
94
+ });
95
+ prediction.customer_company_registrations.map((prediction) => this.customerCompanyRegistrations.push(new fields_1.CompanyRegistration({
96
+ prediction: prediction,
97
+ pageId: pageId,
98
+ })));
99
+ prediction.supplier_payment_details.map((prediction) => this.supplierPaymentDetails.push(new fields_1.PaymentDetails({
100
+ prediction: prediction,
101
+ pageId: pageId,
102
+ })));
103
+ prediction.line_items.map((prediction) => this.lineItems.push(new invoiceLineItem_1.InvoiceLineItem({
104
+ prediction: prediction,
105
+ })));
106
+ this.tip = new fields_1.Amount({
107
+ prediction: prediction.tip,
108
+ valueKey: "value",
109
+ pageId: pageId,
110
+ });
111
+ this.category = new fields_1.TextField({
112
+ prediction: prediction.category,
113
+ pageId: pageId,
114
+ });
115
+ this.subCategory = new fields_1.TextField({
116
+ prediction: prediction.subcategory,
117
+ pageId: pageId,
102
118
  });
119
+ this.time = new fields_1.TextField({
120
+ prediction: prediction.time,
121
+ pageId: pageId,
122
+ });
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
+ })));
103
131
  }
104
- }, _FinancialDocumentV1_checklist = function _FinancialDocumentV1_checklist() {
105
- this.checklist = {
106
- taxesMatchTotalIncl: __classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_taxesMatchTotalIncl).call(this),
107
- };
108
- }, _FinancialDocumentV1_taxesMatchTotalIncl = function _FinancialDocumentV1_taxesMatchTotalIncl() {
109
- // Check taxes and total include exist
110
- if (this.taxes.length === 0 || this.totalIncl.value === undefined)
111
- return false;
112
- // Reconstruct totalIncl from taxes
113
- let totalVat = 0;
114
- let reconstructedTotal = 0;
115
- this.taxes.forEach((tax) => {
116
- if (tax.value === undefined || !tax.rate)
117
- return false;
118
- totalVat += tax.value;
119
- reconstructedTotal += tax.value + (100 * tax.value) / tax.rate;
120
- });
121
- // Sanity check
122
- if (totalVat <= 0)
123
- return false;
124
- // Crate epsilon
125
- const eps = 1 / (100 * totalVat);
126
- if (this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal &&
127
- reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02) {
128
- this.taxes = this.taxes.map((tax) => ({
129
- ...tax,
130
- confidence: 1.0,
131
- }));
132
- this.totalTax.confidence = 1.0;
133
- this.totalIncl.confidence = 1.0;
134
- return true;
132
+ toString() {
133
+ const taxes = this.taxes.map((item) => item.toString()).join("\n ");
134
+ const referenceNumbers = this.referenceNumbers
135
+ .map((item) => item.toString())
136
+ .join(", ");
137
+ const paymentDetails = this.supplierPaymentDetails
138
+ .map((item) => item.toString())
139
+ .join("\n ");
140
+ const customerCompanyRegistration = this.customerCompanyRegistrations
141
+ .map((item) => item.toString())
142
+ .join("; ");
143
+ const supplierCompanyRegistration = this.supplierCompanyRegistrations
144
+ .map((item) => item.toString())
145
+ .join("; ");
146
+ let lineItems = "";
147
+ if (this.lineItems.length > 0) {
148
+ lineItems =
149
+ "\n Code | QTY | Price | Amount | Tax (Rate) | Description\n ";
150
+ lineItems += this.lineItems.map((item) => item.toString()).join("\n ");
151
+ }
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
+ ----------------------
177
+ `;
178
+ return FinancialDocumentV1.cleanOutString(outStr);
135
179
  }
136
- return false;
137
- };
180
+ }
181
+ exports.FinancialDocumentV1 = FinancialDocumentV1;
@@ -4,9 +4,12 @@ export { InvoiceSplitterV1, PageGroup, } from "./invoiceSplitter/invoiceSplitter
4
4
  export { ReceiptV3 } from "./receipt/receiptV3";
5
5
  export { ReceiptV4 } from "./receipt/receiptV4";
6
6
  export { PassportV1 } from "./passport/passportV1";
7
+ export { FinancialDocumentV0 } from "./financialDocument/financialDocumentV0";
7
8
  export { FinancialDocumentV1 } from "./financialDocument/financialDocumentV1";
8
9
  export { CustomV1 } from "./custom/customV1";
9
10
  export { CropperV1 } from "./cropper/cropperV1";
11
+ export { MindeeVisionV1 } from "./mindeeVision/mindeeVisionV1";
12
+ export { ProofOfAddressV1 } from "./proofOfAddress/proofOfAddressV1";
10
13
  export { ShippingContainerV1 } from "./shipping_container/shippingContainerV1";
11
14
  export { Document, DocumentConstructorProps, DocumentSig } from "./document";
12
15
  export * as fr from "./fr";
@@ -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.CropperV1 = exports.CustomV1 = exports.FinancialDocumentV1 = 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.CustomV1 = exports.FinancialDocumentV1 = exports.FinancialDocumentV0 = exports.PassportV1 = 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");
@@ -37,12 +37,18 @@ var receiptV4_1 = require("./receipt/receiptV4");
37
37
  Object.defineProperty(exports, "ReceiptV4", { enumerable: true, get: function () { return receiptV4_1.ReceiptV4; } });
38
38
  var passportV1_1 = require("./passport/passportV1");
39
39
  Object.defineProperty(exports, "PassportV1", { enumerable: true, get: function () { return passportV1_1.PassportV1; } });
40
+ var financialDocumentV0_1 = require("./financialDocument/financialDocumentV0");
41
+ Object.defineProperty(exports, "FinancialDocumentV0", { enumerable: true, get: function () { return financialDocumentV0_1.FinancialDocumentV0; } });
40
42
  var financialDocumentV1_1 = require("./financialDocument/financialDocumentV1");
41
43
  Object.defineProperty(exports, "FinancialDocumentV1", { enumerable: true, get: function () { return financialDocumentV1_1.FinancialDocumentV1; } });
42
44
  var customV1_1 = require("./custom/customV1");
43
45
  Object.defineProperty(exports, "CustomV1", { enumerable: true, get: function () { return customV1_1.CustomV1; } });
44
46
  var cropperV1_1 = require("./cropper/cropperV1");
45
47
  Object.defineProperty(exports, "CropperV1", { enumerable: true, get: function () { return cropperV1_1.CropperV1; } });
48
+ var mindeeVisionV1_1 = require("./mindeeVision/mindeeVisionV1");
49
+ Object.defineProperty(exports, "MindeeVisionV1", { enumerable: true, get: function () { return mindeeVisionV1_1.MindeeVisionV1; } });
50
+ var proofOfAddressV1_1 = require("./proofOfAddress/proofOfAddressV1");
51
+ Object.defineProperty(exports, "ProofOfAddressV1", { enumerable: true, get: function () { return proofOfAddressV1_1.ProofOfAddressV1; } });
46
52
  var shippingContainerV1_1 = require("./shipping_container/shippingContainerV1");
47
53
  Object.defineProperty(exports, "ShippingContainerV1", { enumerable: true, get: function () { return shippingContainerV1_1.ShippingContainerV1; } });
48
54
  var document_1 = require("./document");
@@ -1,6 +1,7 @@
1
1
  import { Document, DocumentConstructorProps } from "../document";
2
2
  import { TaxField, PaymentDetails, Locale, Amount, TextField, DateField, CompanyRegistration, BaseField } from "../../fields";
3
3
  import { InvoiceLineItem } from "./invoiceLineItem";
4
+ /** Invoice V4 */
4
5
  export declare class InvoiceV4 extends Document {
5
6
  #private;
6
7
  /** Locale information. */
@@ -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 _InvoiceV4_instances, _InvoiceV4_initFromApiPrediction, _InvoiceV4_checklist, _InvoiceV4_reconstruct;
7
+ var _InvoiceV4_instances, _InvoiceV4_checklist, _InvoiceV4_reconstruct;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.InvoiceV4 = void 0;
10
10
  const document_1 = require("../document");
@@ -12,6 +12,7 @@ const fields_1 = require("../../fields");
12
12
  const invoiceLineItem_1 = require("./invoiceLineItem");
13
13
  const checks_1 = require("./checks");
14
14
  const reconstruction_1 = require("./reconstruction");
15
+ /** Invoice V4 */
15
16
  class InvoiceV4 extends document_1.Document {
16
17
  constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {
17
18
  super({
@@ -34,7 +35,88 @@ class InvoiceV4 extends document_1.Document {
34
35
  this.taxes = [];
35
36
  /** Line items details. */
36
37
  this.lineItems = [];
37
- __classPrivateFieldGet(this, _InvoiceV4_instances, "m", _InvoiceV4_initFromApiPrediction).call(this, prediction, pageId);
38
+ this.locale = new fields_1.Locale({
39
+ prediction: prediction.locale,
40
+ valueKey: "language",
41
+ });
42
+ this.documentType = new fields_1.BaseField({
43
+ prediction: prediction.document_type,
44
+ valueKey: "value",
45
+ });
46
+ this.referenceNumbers = prediction.reference_numbers.map(function (prediction) {
47
+ return new fields_1.TextField({
48
+ prediction: prediction,
49
+ pageId: pageId,
50
+ });
51
+ });
52
+ this.totalAmount = new fields_1.Amount({
53
+ prediction: prediction.total_amount,
54
+ valueKey: "value",
55
+ pageId: pageId,
56
+ });
57
+ this.totalTax = new fields_1.Amount({
58
+ prediction: { value: undefined, confidence: 0.0 },
59
+ valueKey: "value",
60
+ pageId: pageId,
61
+ });
62
+ this.totalNet = new fields_1.Amount({
63
+ prediction: prediction.total_net,
64
+ valueKey: "value",
65
+ pageId: pageId,
66
+ });
67
+ this.date = new fields_1.DateField({
68
+ prediction: prediction.date,
69
+ pageId,
70
+ });
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
+ })));
78
+ this.supplierCompanyRegistrations =
79
+ prediction.supplier_company_registrations.map(function (prediction) {
80
+ return new fields_1.CompanyRegistration({
81
+ prediction: prediction,
82
+ pageId: pageId,
83
+ });
84
+ });
85
+ this.dueDate = new fields_1.DateField({
86
+ prediction: prediction.due_date,
87
+ pageId: pageId,
88
+ });
89
+ this.invoiceNumber = new fields_1.TextField({
90
+ prediction: prediction.invoice_number,
91
+ pageId: pageId,
92
+ });
93
+ this.supplierName = new fields_1.TextField({
94
+ prediction: prediction.supplier_name,
95
+ pageId: pageId,
96
+ });
97
+ this.supplierAddress = new fields_1.TextField({
98
+ prediction: prediction.supplier_address,
99
+ pageId: pageId,
100
+ });
101
+ this.customerName = new fields_1.TextField({
102
+ prediction: prediction.customer_name,
103
+ pageId: pageId,
104
+ });
105
+ this.customerAddress = new fields_1.TextField({
106
+ prediction: prediction.customer_address,
107
+ pageId: pageId,
108
+ });
109
+ prediction.customer_company_registrations.map((prediction) => this.customerCompanyRegistrations.push(new fields_1.CompanyRegistration({
110
+ prediction: prediction,
111
+ pageId: pageId,
112
+ })));
113
+ prediction.supplier_payment_details.map((prediction) => this.supplierPaymentDetails.push(new fields_1.PaymentDetails({
114
+ prediction: prediction,
115
+ pageId: pageId,
116
+ })));
117
+ prediction.line_items.map((prediction) => this.lineItems.push(new invoiceLineItem_1.InvoiceLineItem({
118
+ prediction: prediction,
119
+ })));
38
120
  __classPrivateFieldGet(this, _InvoiceV4_instances, "m", _InvoiceV4_checklist).call(this);
39
121
  __classPrivateFieldGet(this, _InvoiceV4_instances, "m", _InvoiceV4_reconstruct).call(this);
40
122
  }
@@ -83,90 +165,7 @@ Total amount including taxes: ${this.totalAmount}
83
165
  }
84
166
  }
85
167
  exports.InvoiceV4 = InvoiceV4;
86
- _InvoiceV4_instances = new WeakSet(), _InvoiceV4_initFromApiPrediction = function _InvoiceV4_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.referenceNumbers = apiPrediction.reference_numbers.map(function (prediction) {
96
- return new fields_1.TextField({
97
- prediction: prediction,
98
- pageId: pageId,
99
- });
100
- });
101
- this.totalAmount = new fields_1.Amount({
102
- prediction: apiPrediction.total_amount,
103
- valueKey: "value",
104
- pageId: pageId,
105
- });
106
- this.totalTax = new fields_1.Amount({
107
- prediction: { value: undefined, confidence: 0.0 },
108
- valueKey: "value",
109
- pageId: pageId,
110
- });
111
- this.totalNet = new fields_1.Amount({
112
- prediction: apiPrediction.total_net,
113
- valueKey: "value",
114
- pageId: pageId,
115
- });
116
- this.date = new fields_1.DateField({
117
- prediction: apiPrediction.date,
118
- pageId,
119
- });
120
- apiPrediction.taxes.map((prediction) => this.taxes.push(new fields_1.TaxField({
121
- prediction: prediction,
122
- pageId: pageId,
123
- valueKey: "value",
124
- rateKey: "rate",
125
- codeKey: "code",
126
- })));
127
- this.supplierCompanyRegistrations =
128
- apiPrediction.supplier_company_registrations.map(function (prediction) {
129
- return new fields_1.CompanyRegistration({
130
- prediction: prediction,
131
- pageId: pageId,
132
- });
133
- });
134
- this.dueDate = new fields_1.DateField({
135
- prediction: apiPrediction.due_date,
136
- pageId: pageId,
137
- });
138
- this.invoiceNumber = new fields_1.TextField({
139
- prediction: apiPrediction.invoice_number,
140
- pageId: pageId,
141
- });
142
- this.supplierName = new fields_1.TextField({
143
- prediction: apiPrediction.supplier_name,
144
- pageId: pageId,
145
- });
146
- this.supplierAddress = new fields_1.TextField({
147
- prediction: apiPrediction.supplier_address,
148
- pageId: pageId,
149
- });
150
- this.customerName = new fields_1.TextField({
151
- prediction: apiPrediction.customer_name,
152
- pageId: pageId,
153
- });
154
- this.customerAddress = new fields_1.TextField({
155
- prediction: apiPrediction.customer_address,
156
- pageId: pageId,
157
- });
158
- apiPrediction.customer_company_registrations.map((prediction) => this.customerCompanyRegistrations.push(new fields_1.CompanyRegistration({
159
- prediction: prediction,
160
- pageId: pageId,
161
- })));
162
- apiPrediction.supplier_payment_details.map((prediction) => this.supplierPaymentDetails.push(new fields_1.PaymentDetails({
163
- prediction: prediction,
164
- pageId: pageId,
165
- })));
166
- apiPrediction.line_items.map((prediction) => this.lineItems.push(new invoiceLineItem_1.InvoiceLineItem({
167
- prediction: prediction,
168
- })));
169
- }, _InvoiceV4_checklist = function _InvoiceV4_checklist() {
168
+ _InvoiceV4_instances = new WeakSet(), _InvoiceV4_checklist = function _InvoiceV4_checklist() {
170
169
  this.checklist = {
171
170
  taxesMatchTotalIncl: (0, checks_1.taxesMatchTotalIncl)(this),
172
171
  taxesMatchTotalExcl: (0, checks_1.taxesMatchTotalExcl)(this),
@@ -0,0 +1,8 @@
1
+ import { Document, DocumentConstructorProps } from "../document";
2
+ import { Word } from "../../fields";
3
+ export declare class MindeeVisionV1 extends Document {
4
+ /** List of words found on the page. */
5
+ allWords: Word[];
6
+ constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
7
+ toString(): string;
8
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MindeeVisionV1 = void 0;
4
+ const document_1 = require("../document");
5
+ const fields_1 = require("../../fields");
6
+ class MindeeVisionV1 extends document_1.Document {
7
+ constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {
8
+ super({
9
+ inputSource: inputSource,
10
+ pageId: pageId,
11
+ orientation: orientation,
12
+ fullText: fullText,
13
+ extras: extras,
14
+ });
15
+ /** List of words found on the page. */
16
+ this.allWords = [];
17
+ if (prediction.all_words !== undefined) {
18
+ prediction.all_words.map((prediction) => {
19
+ this.allWords.push(prediction);
20
+ });
21
+ }
22
+ }
23
+ toString() {
24
+ const fullText = new fields_1.FullText();
25
+ fullText.words = this.allWords;
26
+ return fullText.toString();
27
+ }
28
+ }
29
+ exports.MindeeVisionV1 = MindeeVisionV1;
@@ -0,0 +1,24 @@
1
+ import { Document, DocumentConstructorProps } from "../document";
2
+ import { CompanyRegistration, DateField, Locale, TextField } from "../../fields";
3
+ export declare class ProofOfAddressV1 extends Document {
4
+ /** ISO date yyyy-mm-dd. Works both for European and US dates. */
5
+ issuanceDate: DateField;
6
+ /** All extrated ISO date yyyy-mm-dd. Works both for European and US dates. */
7
+ dates: DateField[];
8
+ /** Address of the document's issuer. */
9
+ issuerAddress: TextField;
10
+ /** Generic: VAT NUMBER, TAX ID, COMPANY REGISTRATION NUMBER or country specific. */
11
+ issuerCompanyRegistration: CompanyRegistration[];
12
+ /** Name of the person or company issuing the document. */
13
+ issuerName: TextField;
14
+ /** ISO 639-1 code, works best with ca, de, en, es, fr, it, nl and pt. */
15
+ locale: Locale;
16
+ /** Address of supplier. */
17
+ recipientAddress: TextField;
18
+ /** Generic: VAT NUMBER, TAX ID, COMPANY REGISTRATION NUMBER or country specific. */
19
+ recipientCompanyRegistration: CompanyRegistration[];
20
+ /** Name of the document's recipient. */
21
+ recipientName: TextField;
22
+ constructor({ prediction, orientation, extras, inputSource, pageId, }: DocumentConstructorProps);
23
+ toString(): string;
24
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProofOfAddressV1 = void 0;
4
+ const document_1 = require("../document");
5
+ const fields_1 = require("../../fields");
6
+ class ProofOfAddressV1 extends document_1.Document {
7
+ constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, pageId = undefined, }) {
8
+ super({
9
+ inputSource: inputSource,
10
+ pageId: pageId,
11
+ orientation: orientation,
12
+ extras: extras,
13
+ });
14
+ /** All extrated ISO date yyyy-mm-dd. Works both for European and US dates. */
15
+ this.dates = [];
16
+ /** Generic: VAT NUMBER, TAX ID, COMPANY REGISTRATION NUMBER or country specific. */
17
+ this.issuerCompanyRegistration = [];
18
+ /** Generic: VAT NUMBER, TAX ID, COMPANY REGISTRATION NUMBER or country specific. */
19
+ this.recipientCompanyRegistration = [];
20
+ this.locale = new fields_1.Locale({
21
+ prediction: prediction.locale,
22
+ valueKey: "language",
23
+ });
24
+ this.issuanceDate = new fields_1.DateField({
25
+ prediction: prediction.date,
26
+ pageId: pageId,
27
+ });
28
+ prediction.dates.map((prediction) => this.dates.push(new fields_1.DateField({
29
+ prediction: prediction,
30
+ pageId: pageId,
31
+ })));
32
+ this.issuerAddress = new fields_1.TextField({
33
+ prediction: prediction.issuer_address,
34
+ pageId: pageId,
35
+ });
36
+ prediction.issuer_company_registration.map((prediction) => this.issuerCompanyRegistration.push(new fields_1.CompanyRegistration({
37
+ prediction: prediction,
38
+ pageId: pageId,
39
+ })));
40
+ this.issuerName = new fields_1.TextField({
41
+ prediction: prediction.issuer_name,
42
+ pageId: pageId,
43
+ });
44
+ prediction.recipient_company_registration.map((prediction) => this.recipientCompanyRegistration.push(new fields_1.CompanyRegistration({
45
+ prediction: prediction,
46
+ pageId: pageId,
47
+ })));
48
+ this.recipientAddress = new fields_1.TextField({
49
+ prediction: prediction.recipient_address,
50
+ pageId: pageId,
51
+ });
52
+ this.recipientName = new fields_1.TextField({
53
+ prediction: prediction.recipient_name,
54
+ pageId: pageId,
55
+ });
56
+ }
57
+ toString() {
58
+ const outStr = `----- Proof of Address V1 -----
59
+ Filename: ${this.filename}
60
+ Locale: ${this.locale}
61
+ Issuer name: ${this.issuerName}
62
+ Issuer Address: ${this.issuerAddress}
63
+ Issuer Company Registrations: ${this.issuerCompanyRegistration
64
+ .map((icr) => icr.value)
65
+ .join(", ")}
66
+ Recipient name: ${this.recipientName}
67
+ Recipient Address: ${this.recipientAddress}
68
+ Recipient Company Registrations: ${this.recipientCompanyRegistration
69
+ .map((rcr) => rcr.value)
70
+ .join(", ")}
71
+ Issuance Date: ${this.issuanceDate}
72
+ Dates: ${this.dates.map((rcr) => rcr.value).join("\n ")}
73
+ ----------------------
74
+ `;
75
+ return ProofOfAddressV1.cleanOutString(outStr);
76
+ }
77
+ }
78
+ exports.ProofOfAddressV1 = ProofOfAddressV1;
@@ -1,7 +1,6 @@
1
1
  import { Document, DocumentConstructorProps } from "../document";
2
2
  import { Amount, DateField, TextField, Locale, TaxField } from "../../fields";
3
3
  export declare class ReceiptV4 extends Document {
4
- #private;
5
4
  /** Where the purchase was made, the language, and the currency. */
6
5
  locale: Locale;
7
6
  /** The purchase date. */
@@ -1,10 +1,4 @@
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 _ReceiptV4_instances, _ReceiptV4_initFromApiPrediction;
8
2
  Object.defineProperty(exports, "__esModule", { value: true });
9
3
  exports.ReceiptV4 = void 0;
10
4
  const document_1 = require("../document");
@@ -18,10 +12,63 @@ class ReceiptV4 extends document_1.Document {
18
12
  extras: extras,
19
13
  fullText: fullText,
20
14
  });
21
- _ReceiptV4_instances.add(this);
22
15
  /** List of taxes detected on the receipt. */
23
16
  this.taxes = [];
24
- __classPrivateFieldGet(this, _ReceiptV4_instances, "m", _ReceiptV4_initFromApiPrediction).call(this, prediction, pageId);
17
+ this.locale = new fields_1.Locale({
18
+ prediction: prediction.locale,
19
+ });
20
+ this.totalTax = new fields_1.Amount({
21
+ prediction: prediction.total_tax,
22
+ valueKey: "value",
23
+ pageId: pageId,
24
+ });
25
+ this.totalAmount = new fields_1.Amount({
26
+ prediction: prediction.total_amount,
27
+ valueKey: "value",
28
+ pageId: pageId,
29
+ });
30
+ this.totalNet = new fields_1.Amount({
31
+ prediction: prediction.total_net,
32
+ valueKey: "value",
33
+ pageId: pageId,
34
+ });
35
+ this.tip = new fields_1.Amount({
36
+ prediction: prediction.tip,
37
+ valueKey: "value",
38
+ pageId: pageId,
39
+ });
40
+ this.date = new fields_1.DateField({
41
+ prediction: prediction.date,
42
+ pageId: pageId,
43
+ });
44
+ this.category = new fields_1.TextField({
45
+ prediction: prediction.category,
46
+ pageId: pageId,
47
+ });
48
+ this.subCategory = new fields_1.TextField({
49
+ prediction: prediction.subcategory,
50
+ pageId: pageId,
51
+ });
52
+ this.documentType = new fields_1.TextField({
53
+ prediction: prediction.document_type,
54
+ pageId: pageId,
55
+ });
56
+ this.supplier = new fields_1.TextField({
57
+ prediction: prediction.supplier,
58
+ pageId: pageId,
59
+ });
60
+ this.time = new fields_1.TextField({
61
+ prediction: prediction.time,
62
+ pageId: pageId,
63
+ });
64
+ prediction.taxes.map((taxPrediction) => this.taxes.push(new fields_1.TaxField({
65
+ prediction: taxPrediction,
66
+ pageId: pageId,
67
+ valueKey: "value",
68
+ rateKey: "rate",
69
+ codeKey: "code",
70
+ baseKey: "base",
71
+ })));
25
72
  }
26
73
  toString() {
27
74
  const taxes = this.taxes.map((item) => item.toString()).join("\n ");
@@ -45,60 +92,3 @@ Locale: ${this.locale}
45
92
  }
46
93
  }
47
94
  exports.ReceiptV4 = ReceiptV4;
48
- _ReceiptV4_instances = new WeakSet(), _ReceiptV4_initFromApiPrediction = function _ReceiptV4_initFromApiPrediction(apiPrediction, pageId) {
49
- this.locale = new fields_1.Locale({
50
- prediction: apiPrediction.locale,
51
- });
52
- this.totalTax = new fields_1.Amount({
53
- prediction: apiPrediction.total_tax,
54
- valueKey: "value",
55
- pageId: pageId,
56
- });
57
- this.totalAmount = new fields_1.Amount({
58
- prediction: apiPrediction.total_amount,
59
- valueKey: "value",
60
- pageId: pageId,
61
- });
62
- this.totalNet = new fields_1.Amount({
63
- prediction: apiPrediction.total_net,
64
- valueKey: "value",
65
- pageId: pageId,
66
- });
67
- this.tip = new fields_1.Amount({
68
- prediction: apiPrediction.tip,
69
- valueKey: "value",
70
- pageId: pageId,
71
- });
72
- this.date = new fields_1.DateField({
73
- prediction: apiPrediction.date,
74
- pageId: pageId,
75
- });
76
- this.category = new fields_1.TextField({
77
- prediction: apiPrediction.category,
78
- pageId: pageId,
79
- });
80
- this.subCategory = new fields_1.TextField({
81
- prediction: apiPrediction.subcategory,
82
- pageId: pageId,
83
- });
84
- this.documentType = new fields_1.TextField({
85
- prediction: apiPrediction.document_type,
86
- pageId: pageId,
87
- });
88
- this.supplier = new fields_1.TextField({
89
- prediction: apiPrediction.supplier,
90
- pageId: pageId,
91
- });
92
- this.time = new fields_1.TextField({
93
- prediction: apiPrediction.time,
94
- pageId: pageId,
95
- });
96
- apiPrediction.taxes.map((taxPrediction) => this.taxes.push(new fields_1.TaxField({
97
- prediction: taxPrediction,
98
- pageId: pageId,
99
- valueKey: "value",
100
- rateKey: "rate",
101
- codeKey: "code",
102
- baseKey: "base",
103
- })));
104
- };
package/src/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { CustomV1, Document, FinancialDocumentV1, InvoiceV3, InvoiceV4, PassportV1, ReceiptV3, ReceiptV4, CropperV1, ShippingContainerV1, fr, us, eu, } from "./documents";
1
+ export { CustomV1, Document, FinancialDocumentV0, FinancialDocumentV1, InvoiceV3, InvoiceV4, PassportV1, ReceiptV3, ReceiptV4, CropperV1, ShippingContainerV1, fr, us, eu, } from "./documents";
2
2
  export { Client, ClientOptions, CustomConfigParams, PredictOptions, } from "./client";
3
3
  export { ResponseSig, Response } from "./api";
4
4
  export { InputSource, PageOptionsOperation } from "./inputs";
package/src/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PageOptionsOperation = exports.InputSource = exports.Response = exports.Client = exports.eu = exports.us = exports.fr = exports.ShippingContainerV1 = exports.CropperV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceV4 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.Document = exports.CustomV1 = void 0;
3
+ exports.PageOptionsOperation = exports.InputSource = exports.Response = exports.Client = exports.eu = exports.us = exports.fr = exports.ShippingContainerV1 = exports.CropperV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceV4 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.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; } });
7
+ Object.defineProperty(exports, "FinancialDocumentV0", { enumerable: true, get: function () { return documents_1.FinancialDocumentV0; } });
7
8
  Object.defineProperty(exports, "FinancialDocumentV1", { enumerable: true, get: function () { return documents_1.FinancialDocumentV1; } });
8
9
  Object.defineProperty(exports, "InvoiceV3", { enumerable: true, get: function () { return documents_1.InvoiceV3; } });
9
10
  Object.defineProperty(exports, "InvoiceV4", { enumerable: true, get: function () { return documents_1.InvoiceV4; } });