mindee 3.3.0 → 3.4.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 +5 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/client.d.ts +1 -1
- package/src/documents/document.d.ts +1 -1
- package/src/documents/eu/licensePlate/licensePlateV1.js +2 -1
- package/src/documents/fr/carteVitale/carteVitaleV1.js +1 -0
- package/src/documents/invoice/invoiceLineItem.js +2 -2
- package/src/documents/invoice/invoiceV3.js +16 -16
- package/src/documents/invoice/invoiceV4.d.ts +2 -0
- package/src/documents/invoice/invoiceV4.js +13 -1
- package/src/documents/passport/passportV1.js +1 -1
- package/src/documents/receipt/receiptV4.d.ts +4 -0
- package/src/documents/receipt/receiptV4.js +11 -1
- package/src/documents/receipt/tax.d.ts +3 -3
- package/src/documents/receipt/tax.js +7 -7
- package/src/documents/shipping_container/shippingContainerV1.js +1 -0
- package/src/fields/amount.js +5 -4
- package/src/fields/field.d.ts +1 -1
- package/src/fields/fullText.d.ts +2 -2
- package/src/fields/tax.d.ts +2 -2
- package/src/fields/tax.js +2 -2
- package/src/geometry.d.ts +4 -4
- package/src/index.d.ts +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ const mindeeClient = new mindee.Client({ apiKey: "my-api-key" });
|
|
|
27
27
|
// Load a file from disk and parse it
|
|
28
28
|
const apiResponse = mindeeClient
|
|
29
29
|
.docFromPath("/path/to/the/file.ext")
|
|
30
|
-
.parse(mindee.
|
|
30
|
+
.parse(mindee.InvoiceV4);
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
#### Region-Specific Documents
|
package/package.json
CHANGED
package/src/client.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Response } from "./api";
|
|
|
5
5
|
import { Document, DocumentSig } from "./documents";
|
|
6
6
|
import { DocumentConfig } from "./documents/documentConfig";
|
|
7
7
|
import { ReadStream } from "fs";
|
|
8
|
-
|
|
8
|
+
type DocConfigs = Map<string[], DocumentConfig<any>>;
|
|
9
9
|
export interface PredictOptions {
|
|
10
10
|
/**
|
|
11
11
|
* For custom endpoints, the "API name" field in the "Settings" page of the API Builder.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InputSource } from "../inputs";
|
|
2
2
|
import { PositionField, FullText, OrientationField, stringDict } from "../fields";
|
|
3
|
-
export
|
|
3
|
+
export type DocumentSig<DocType extends Document> = {
|
|
4
4
|
new ({ prediction, orientation, extras, inputSource, pageId, fullText, documentType, }: DocumentConstructorProps): DocType;
|
|
5
5
|
};
|
|
6
6
|
export interface DocumentConstructorProps extends BaseDocumentConstructorProps {
|
|
@@ -20,7 +20,8 @@ class LicensePlateV1 extends document_1.Document {
|
|
|
20
20
|
}
|
|
21
21
|
toString() {
|
|
22
22
|
const outStr = `----- EU License plate V1 -----
|
|
23
|
-
|
|
23
|
+
Filename: ${this.filename}
|
|
24
|
+
License plates: ${this.licensePlates.map((plate) => plate.value).join(", ")}
|
|
24
25
|
----------------------
|
|
25
26
|
`;
|
|
26
27
|
return LicensePlateV1.cleanOutString(outStr);
|
|
@@ -32,6 +32,7 @@ class CarteVitaleV1 extends document_1.Document {
|
|
|
32
32
|
}
|
|
33
33
|
toString() {
|
|
34
34
|
const outStr = `----- FR Carte Vitale V1 -----
|
|
35
|
+
Filename: ${this.filename}
|
|
35
36
|
Given names: ${this.givenNames.map((name) => name.value).join(" ")}
|
|
36
37
|
Surname: ${this.surname}
|
|
37
38
|
ID Number: ${this.idNumber}
|
|
@@ -45,7 +45,7 @@ class InvoiceLineItem {
|
|
|
45
45
|
const unitPrice = this.unitPrice !== null ? (0, amount_1.floatToString)(this.unitPrice) : "";
|
|
46
46
|
const totalAmount = this.totalAmount !== null ? (0, amount_1.floatToString)(this.totalAmount) : "";
|
|
47
47
|
let tax = this.taxAmount !== null ? (0, amount_1.floatToString)(this.taxAmount) : "";
|
|
48
|
-
tax += this.taxRate !== null ? ` (${this.taxRate}
|
|
48
|
+
tax += this.taxRate !== null ? ` (${(0, amount_1.floatToString)(this.taxRate)}%)` : "";
|
|
49
49
|
let description = this.description ?? "";
|
|
50
50
|
if (description.length > 32) {
|
|
51
51
|
description = this.description.substring(0, 32) + "...";
|
|
@@ -58,7 +58,7 @@ class InvoiceLineItem {
|
|
|
58
58
|
" | " +
|
|
59
59
|
totalAmount.padEnd(8) +
|
|
60
60
|
" | " +
|
|
61
|
-
tax.padEnd(
|
|
61
|
+
tax.padEnd(16) +
|
|
62
62
|
" | " +
|
|
63
63
|
description);
|
|
64
64
|
}
|
|
@@ -12,6 +12,22 @@ const fields_1 = require("../../fields");
|
|
|
12
12
|
const checks_1 = require("./checks");
|
|
13
13
|
const reconstruction_1 = require("./reconstruction");
|
|
14
14
|
class InvoiceV3 extends document_1.Document {
|
|
15
|
+
/** The total amount without the tax value. */
|
|
16
|
+
get totalExcl() {
|
|
17
|
+
return this.totalNet;
|
|
18
|
+
}
|
|
19
|
+
/** The total amount without the tax value. */
|
|
20
|
+
set totalExcl(value) {
|
|
21
|
+
this.totalNet = value;
|
|
22
|
+
}
|
|
23
|
+
/** The total amount with tax included. */
|
|
24
|
+
get totalIncl() {
|
|
25
|
+
return this.totalAmount;
|
|
26
|
+
}
|
|
27
|
+
/** The total amount with tax included. */
|
|
28
|
+
set totalIncl(value) {
|
|
29
|
+
this.totalAmount = value;
|
|
30
|
+
}
|
|
15
31
|
constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {
|
|
16
32
|
super({
|
|
17
33
|
inputSource: inputSource,
|
|
@@ -33,22 +49,6 @@ class InvoiceV3 extends document_1.Document {
|
|
|
33
49
|
__classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_checklist).call(this);
|
|
34
50
|
__classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_reconstruct).call(this);
|
|
35
51
|
}
|
|
36
|
-
/** The total amount without the tax value. */
|
|
37
|
-
get totalExcl() {
|
|
38
|
-
return this.totalNet;
|
|
39
|
-
}
|
|
40
|
-
/** The total amount without the tax value. */
|
|
41
|
-
set totalExcl(value) {
|
|
42
|
-
this.totalNet = value;
|
|
43
|
-
}
|
|
44
|
-
/** The total amount with tax included. */
|
|
45
|
-
get totalIncl() {
|
|
46
|
-
return this.totalAmount;
|
|
47
|
-
}
|
|
48
|
-
/** The total amount with tax included. */
|
|
49
|
-
set totalIncl(value) {
|
|
50
|
-
this.totalAmount = value;
|
|
51
|
-
}
|
|
52
52
|
toString() {
|
|
53
53
|
const taxes = this.taxes.map((item) => item.toString()).join("\n ");
|
|
54
54
|
const paymentDetails = this.paymentDetails
|
|
@@ -7,6 +7,8 @@ export declare class InvoiceV4 extends Document {
|
|
|
7
7
|
locale: Locale;
|
|
8
8
|
/** The nature of the invoice. */
|
|
9
9
|
documentType: BaseField;
|
|
10
|
+
/** List of Reference numbers including PO number. */
|
|
11
|
+
referenceNumbers: Field[];
|
|
10
12
|
/** The total amount with tax included. */
|
|
11
13
|
totalAmount: Amount;
|
|
12
14
|
/** The creation date of the invoice. */
|
|
@@ -22,6 +22,8 @@ class InvoiceV4 extends document_1.Document {
|
|
|
22
22
|
extras: extras,
|
|
23
23
|
});
|
|
24
24
|
_InvoiceV4_instances.add(this);
|
|
25
|
+
/** List of Reference numbers including PO number. */
|
|
26
|
+
this.referenceNumbers = [];
|
|
25
27
|
/** The payment information. */
|
|
26
28
|
this.supplierPaymentDetails = [];
|
|
27
29
|
/** The supplier company regitration information. */
|
|
@@ -38,6 +40,9 @@ class InvoiceV4 extends document_1.Document {
|
|
|
38
40
|
}
|
|
39
41
|
toString() {
|
|
40
42
|
const taxes = this.taxes.map((item) => item.toString()).join("\n ");
|
|
43
|
+
const referenceNumbers = this.referenceNumbers
|
|
44
|
+
.map((item) => item.toString())
|
|
45
|
+
.join(", ");
|
|
41
46
|
const paymentDetails = this.supplierPaymentDetails
|
|
42
47
|
.map((item) => item.toString())
|
|
43
48
|
.join("\n ");
|
|
@@ -50,13 +55,14 @@ class InvoiceV4 extends document_1.Document {
|
|
|
50
55
|
let lineItems = "\n";
|
|
51
56
|
if (this.lineItems.length > 0) {
|
|
52
57
|
lineItems =
|
|
53
|
-
"\n Code | QTY | Price | Amount | Tax (Rate)
|
|
58
|
+
"\n Code | QTY | Price | Amount | Tax (Rate) | Description\n ";
|
|
54
59
|
lineItems += this.lineItems.map((item) => item.toString()).join("\n ");
|
|
55
60
|
}
|
|
56
61
|
const outStr = `----- Invoice V4 -----
|
|
57
62
|
Filename: ${this.filename}
|
|
58
63
|
Locale: ${this.locale}
|
|
59
64
|
Invoice number: ${this.invoiceNumber}
|
|
65
|
+
Reference numbers: ${referenceNumbers}
|
|
60
66
|
Invoice date: ${this.date}
|
|
61
67
|
Invoice due date: ${this.dueDate}
|
|
62
68
|
Supplier name: ${this.supplierName}
|
|
@@ -86,6 +92,12 @@ _InvoiceV4_instances = new WeakSet(), _InvoiceV4_initFromApiPrediction = functio
|
|
|
86
92
|
prediction: apiPrediction.document_type,
|
|
87
93
|
valueKey: "value",
|
|
88
94
|
});
|
|
95
|
+
this.referenceNumbers = apiPrediction.reference_numbers.map(function (prediction) {
|
|
96
|
+
return new fields_1.Field({
|
|
97
|
+
prediction: prediction,
|
|
98
|
+
pageId: pageId,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
89
101
|
this.totalAmount = new fields_1.Amount({
|
|
90
102
|
prediction: apiPrediction.total_amount,
|
|
91
103
|
valueKey: "value",
|
|
@@ -101,7 +101,7 @@ class PassportV1 extends document_1.Document {
|
|
|
101
101
|
return new Date(year, month - 1, day, 0, 0, 0, 0);
|
|
102
102
|
}
|
|
103
103
|
toString() {
|
|
104
|
-
const outStr = `-----Passport
|
|
104
|
+
const outStr = `----- Passport V1 -----
|
|
105
105
|
Filename: ${this.filename}
|
|
106
106
|
Full name: ${this.fullName}
|
|
107
107
|
Given names: ${this.givenNames.map((name) => name.value).join(" ")}
|
|
@@ -8,6 +8,10 @@ export declare class ReceiptV4 extends Document {
|
|
|
8
8
|
date: DateField;
|
|
9
9
|
/** The type of purchase. */
|
|
10
10
|
category: Field;
|
|
11
|
+
/** The receipt sub category among predefined classes. */
|
|
12
|
+
subCategory: Field;
|
|
13
|
+
/** The receipt document type provdes the information whether the document is an expense receipt or a credit card receipt. */
|
|
14
|
+
documentType: Field;
|
|
11
15
|
/** Merchant's name as seen on the receipt. */
|
|
12
16
|
supplier: Field;
|
|
13
17
|
/** Time as seen on the receipt in HH:MM format. */
|
|
@@ -33,6 +33,8 @@ Total net: ${this.totalNet}
|
|
|
33
33
|
Tip: ${this.tip}
|
|
34
34
|
Date: ${this.date}
|
|
35
35
|
Category: ${this.category}
|
|
36
|
+
Subcategory: ${this.subCategory}
|
|
37
|
+
Document type: ${this.documentType}
|
|
36
38
|
Time: ${this.time}
|
|
37
39
|
Supplier name: ${this.supplier}
|
|
38
40
|
Taxes: ${taxes}
|
|
@@ -77,6 +79,14 @@ _ReceiptV4_instances = new WeakSet(), _ReceiptV4_initFromApiPrediction = functio
|
|
|
77
79
|
prediction: apiPrediction.category,
|
|
78
80
|
pageId: pageId,
|
|
79
81
|
});
|
|
82
|
+
this.subCategory = new fields_1.Field({
|
|
83
|
+
prediction: apiPrediction.subcategory,
|
|
84
|
+
pageId: pageId,
|
|
85
|
+
});
|
|
86
|
+
this.documentType = new fields_1.Field({
|
|
87
|
+
prediction: apiPrediction.document_type,
|
|
88
|
+
pageId: pageId,
|
|
89
|
+
});
|
|
80
90
|
this.supplier = new fields_1.Field({
|
|
81
91
|
prediction: apiPrediction.supplier,
|
|
82
92
|
pageId: pageId,
|
|
@@ -91,6 +101,6 @@ _ReceiptV4_instances = new WeakSet(), _ReceiptV4_initFromApiPrediction = functio
|
|
|
91
101
|
valueKey: "value",
|
|
92
102
|
rateKey: "rate",
|
|
93
103
|
codeKey: "code",
|
|
94
|
-
|
|
104
|
+
baseKey: "base",
|
|
95
105
|
})));
|
|
96
106
|
};
|
|
@@ -4,13 +4,13 @@ interface ReceiptTaxConstructor {
|
|
|
4
4
|
valueKey?: string;
|
|
5
5
|
rateKey?: string;
|
|
6
6
|
codeKey?: string;
|
|
7
|
-
|
|
7
|
+
baseKey?: string;
|
|
8
8
|
reconstructed?: boolean;
|
|
9
9
|
pageId?: number;
|
|
10
10
|
}
|
|
11
11
|
export declare class ReceiptTaxField extends TaxField {
|
|
12
12
|
/** The tax base */
|
|
13
|
-
|
|
13
|
+
base?: number;
|
|
14
14
|
/**
|
|
15
15
|
* @param {Object} prediction - Prediction object from HTTP response
|
|
16
16
|
* @param {String} valueKey - Key to use in the prediction dict to get the tax value
|
|
@@ -19,7 +19,7 @@ export declare class ReceiptTaxField extends TaxField {
|
|
|
19
19
|
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
20
20
|
* @param {Integer} pageNumber - Page ID for multi-page document
|
|
21
21
|
*/
|
|
22
|
-
constructor({ prediction, valueKey, rateKey, codeKey,
|
|
22
|
+
constructor({ prediction, valueKey, rateKey, codeKey, baseKey, reconstructed, pageId, }: ReceiptTaxConstructor);
|
|
23
23
|
toString(): string;
|
|
24
24
|
}
|
|
25
25
|
export {};
|
|
@@ -12,13 +12,13 @@ class ReceiptTaxField extends fields_1.TaxField {
|
|
|
12
12
|
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
13
13
|
* @param {Integer} pageNumber - Page ID for multi-page document
|
|
14
14
|
*/
|
|
15
|
-
constructor({ prediction, valueKey = "value", rateKey = "rate", codeKey = "code",
|
|
15
|
+
constructor({ prediction, valueKey = "value", rateKey = "rate", codeKey = "code", baseKey = "base", reconstructed = false, pageId = undefined, }) {
|
|
16
16
|
super({ prediction, valueKey, rateKey, codeKey, reconstructed, pageId });
|
|
17
17
|
/** The tax base */
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
if (isNaN(this.
|
|
21
|
-
this.
|
|
18
|
+
this.base = undefined;
|
|
19
|
+
this.base = parseFloat(prediction[baseKey]);
|
|
20
|
+
if (isNaN(this.base))
|
|
21
|
+
this.base = undefined;
|
|
22
22
|
}
|
|
23
23
|
toString() {
|
|
24
24
|
let outStr = "";
|
|
@@ -31,8 +31,8 @@ class ReceiptTaxField extends fields_1.TaxField {
|
|
|
31
31
|
if (this.code !== undefined) {
|
|
32
32
|
outStr += ` ${this.code}`;
|
|
33
33
|
}
|
|
34
|
-
if (this.
|
|
35
|
-
outStr += ` ${this.
|
|
34
|
+
if (this.base !== undefined) {
|
|
35
|
+
outStr += ` ${this.base}`;
|
|
36
36
|
}
|
|
37
37
|
return outStr.trim();
|
|
38
38
|
}
|
package/src/fields/amount.js
CHANGED
|
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Amount = exports.floatToString = void 0;
|
|
4
4
|
const field_1 = require("./field");
|
|
5
5
|
function floatToString(value) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
return value.toLocaleString(undefined, {
|
|
7
|
+
minimumFractionDigits: 2,
|
|
8
|
+
maximumFractionDigits: 3,
|
|
9
|
+
useGrouping: false,
|
|
10
|
+
});
|
|
10
11
|
}
|
|
11
12
|
exports.floatToString = floatToString;
|
|
12
13
|
class Amount extends field_1.Field {
|
package/src/fields/field.d.ts
CHANGED
package/src/fields/fullText.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as geometry from "../geometry";
|
|
2
|
-
export
|
|
2
|
+
export type Word = {
|
|
3
3
|
/**
|
|
4
4
|
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
5
5
|
* the field in the document.
|
|
@@ -8,7 +8,7 @@ export declare type Word = {
|
|
|
8
8
|
text: string;
|
|
9
9
|
confidence: number;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
type Line = Word[];
|
|
12
12
|
export declare class FullText {
|
|
13
13
|
words: Word[];
|
|
14
14
|
/**
|
package/src/fields/tax.d.ts
CHANGED
|
@@ -10,9 +10,9 @@ interface TaxConstructor {
|
|
|
10
10
|
export declare class TaxField extends Field {
|
|
11
11
|
/** The tax amount. */
|
|
12
12
|
value?: number;
|
|
13
|
-
/** The tax code (HST, GST... for Canadian; City Tax, State tax for US, etc..). */
|
|
14
|
-
rate?: number;
|
|
15
13
|
/** The tax rate. */
|
|
14
|
+
rate?: number;
|
|
15
|
+
/** The tax code (HST, GST... for Canadian; City Tax, State tax for US, etc..). */
|
|
16
16
|
code?: string;
|
|
17
17
|
/** The document page on which the information was found. */
|
|
18
18
|
pageId: number;
|
package/src/fields/tax.js
CHANGED
|
@@ -16,9 +16,9 @@ class TaxField extends field_1.Field {
|
|
|
16
16
|
super({ prediction, valueKey, reconstructed, pageId });
|
|
17
17
|
/** The tax amount. */
|
|
18
18
|
this.value = undefined;
|
|
19
|
-
/** The tax code (HST, GST... for Canadian; City Tax, State tax for US, etc..). */
|
|
20
|
-
this.rate = undefined;
|
|
21
19
|
/** The tax rate. */
|
|
20
|
+
this.rate = undefined;
|
|
21
|
+
/** The tax code (HST, GST... for Canadian; City Tax, State tax for US, etc..). */
|
|
22
22
|
this.code = undefined;
|
|
23
23
|
this.rate = +parseFloat(prediction[rateKey]);
|
|
24
24
|
if (isNaN(this.rate))
|
package/src/geometry.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
type MinMax = {
|
|
2
2
|
min: number;
|
|
3
3
|
max: number;
|
|
4
4
|
};
|
|
5
5
|
/** A point on the document defined by 2 coordinates: X, Y */
|
|
6
|
-
export
|
|
6
|
+
export type Point = [number, number];
|
|
7
7
|
/** A bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */
|
|
8
|
-
export
|
|
8
|
+
export type BoundingBox = [number, number, number, number];
|
|
9
9
|
/** A polygon, composed of several Points. */
|
|
10
|
-
export
|
|
10
|
+
export type Polygon = Array<Point>;
|
|
11
11
|
/**
|
|
12
12
|
* Given a Polygon, calculate a polygon that encompasses all points.
|
|
13
13
|
*/
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { CustomV1, FinancialDocumentV1, InvoiceV3, InvoiceV4, PassportV1, ReceiptV3, ReceiptV4, CropperV1, ShippingContainerV1, fr, us, eu, } from "./documents";
|
|
2
|
-
export { Client } from "./client";
|
|
2
|
+
export { Client, ClientOptions } from "./client";
|
|
3
3
|
export { PageOptionsOperation } from "./inputs";
|