mindee 3.6.0 → 3.7.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 +43 -39
- package/package.json +1 -1
- package/src/api/{response.d.ts → documentResponse.d.ts} +2 -2
- package/src/api/endpoint.d.ts +32 -5
- package/src/api/endpoint.js +104 -34
- package/src/api/index.d.ts +3 -2
- package/src/api/index.js +5 -3
- package/src/api/predictResponse.d.ts +33 -0
- package/src/api/predictResponse.js +52 -0
- package/src/cli.js +203 -51
- package/src/client.d.ts +20 -4
- package/src/client.js +65 -22
- package/src/documents/custom/fields.js +1 -1
- package/src/documents/custom/lineitems.d.ts +41 -0
- package/src/documents/custom/lineitems.js +127 -0
- package/src/documents/document.d.ts +1 -1
- package/src/documents/documentConfig.d.ts +12 -4
- package/src/documents/documentConfig.js +55 -24
- package/src/documents/eu/licensePlate/licensePlateV1.js +4 -2
- package/src/documents/fr/bankAccountDetails/bankAccountDetailsV1.js +3 -2
- package/src/documents/fr/carteVitale/carteVitaleV1.js +2 -2
- package/src/documents/fr/idCard/idCardV1.js +10 -10
- package/src/documents/index.d.ts +2 -1
- package/src/documents/index.js +4 -2
- package/src/documents/invoice/invoiceV4.d.ts +2 -2
- package/src/documents/invoice/invoiceV4.js +1 -1
- package/src/documents/invoiceSplitter/invoiceSplitterV1.d.ts +3 -3
- package/src/documents/invoiceSplitter/invoiceSplitterV1.js +1 -0
- package/src/documents/proofOfAddress/proofOfAddressV1.js +5 -6
- package/src/documents/receipt/receiptV3.d.ts +2 -2
- package/src/documents/receipt/receiptV3.js +1 -2
- package/src/documents/receipt/receiptV4.d.ts +3 -3
- package/src/documents/receipt/receiptV4.js +2 -4
- package/src/documents/{shipping_container → shippingContainer}/shippingContainerV1.js +2 -2
- package/src/fields/classification.d.ts +8 -0
- package/src/fields/classification.js +11 -0
- package/src/fields/field.d.ts +2 -2
- package/src/fields/field.js +1 -6
- package/src/fields/index.d.ts +1 -0
- package/src/fields/index.js +3 -1
- package/src/geometry.d.ts +18 -4
- package/src/geometry.js +40 -3
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
- package/src/math/index.d.ts +1 -0
- package/src/math/index.js +5 -0
- package/src/math/precision.d.ts +1 -0
- package/src/math/precision.js +13 -0
- /package/src/api/{response.js → documentResponse.js} +0 -0
- /package/src/documents/{shipping_container → shippingContainer}/shippingContainerV1.d.ts +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLineItems = exports.LineItems = exports.Line = void 0;
|
|
4
|
+
const handler_1 = require("../../errors/handler");
|
|
5
|
+
const errors_1 = require("../../errors");
|
|
6
|
+
const geometry_1 = require("../../geometry");
|
|
7
|
+
const fields_1 = require("./fields");
|
|
8
|
+
const math_1 = require("../../math");
|
|
9
|
+
class Line {
|
|
10
|
+
constructor(rowNumber, heightTolerance) {
|
|
11
|
+
this.rowNumber = rowNumber;
|
|
12
|
+
this.bbox = [1, 1, 0, 0];
|
|
13
|
+
this.fields = new Map();
|
|
14
|
+
this.heightTolerance = heightTolerance;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Extends the current bbox of the line with the bbox.
|
|
18
|
+
*/
|
|
19
|
+
extendWithBbox(bbox) {
|
|
20
|
+
this.bbox = (0, geometry_1.mergeBbox)(this.bbox, bbox);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Extends the current bbox of the line with the polygon.
|
|
24
|
+
*/
|
|
25
|
+
extendWith(polygon) {
|
|
26
|
+
this.bbox = (0, geometry_1.mergeBbox)(this.bbox, (0, geometry_1.getBbox)(polygon));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if the bbox fits the current line.
|
|
30
|
+
*/
|
|
31
|
+
contains(bbox) {
|
|
32
|
+
return (0, math_1.precisionEquals)(this.bbox[1], bbox[1], this.heightTolerance);
|
|
33
|
+
}
|
|
34
|
+
updateField(name, fieldValue) {
|
|
35
|
+
if (!this.fields.has(name)) {
|
|
36
|
+
this.fields.set(name, fieldValue);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const existingField = this.fields.get(name);
|
|
40
|
+
if (existingField === undefined) {
|
|
41
|
+
handler_1.errorHandler.throw(new errors_1.MindeeError(`The field '${name}' should exist but was not found.`));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const mergedContent = existingField?.content === undefined
|
|
45
|
+
? fieldValue.content
|
|
46
|
+
: existingField.content + " " + fieldValue.content;
|
|
47
|
+
const mergedBbox = (0, geometry_1.getBBoxForPolygons)([
|
|
48
|
+
existingField.polygon,
|
|
49
|
+
fieldValue.polygon,
|
|
50
|
+
]);
|
|
51
|
+
this.fields.set(name, new fields_1.ListFieldValue({
|
|
52
|
+
content: mergedContent,
|
|
53
|
+
confidence: existingField.confidence * fieldValue.confidence,
|
|
54
|
+
polygon: (0, geometry_1.getBoundingBoxFromBBox)(mergedBbox),
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Line = Line;
|
|
60
|
+
class LineItems {
|
|
61
|
+
constructor(lines) {
|
|
62
|
+
this.rows = [];
|
|
63
|
+
this.rows = lines;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.LineItems = LineItems;
|
|
67
|
+
function getLineItems(anchorNames, heigthLineTolerance, fieldNamesTargeted, fields) {
|
|
68
|
+
const fieldsToTransformIntoLines = new Map([...fields].filter(([k]) => fieldNamesTargeted.includes(k)));
|
|
69
|
+
const anchorName = findBestAnchor(anchorNames, fieldsToTransformIntoLines);
|
|
70
|
+
const lineItemsPrepared = prepare(anchorName, fieldsToTransformIntoLines, heigthLineTolerance);
|
|
71
|
+
lineItemsPrepared.rows.forEach((currentLine) => {
|
|
72
|
+
fieldsToTransformIntoLines.forEach((field, fieldName) => {
|
|
73
|
+
field.values.forEach((listFieldValue) => {
|
|
74
|
+
const minYCurrentValue = (0, geometry_1.getMinMaxY)(listFieldValue.polygon).min;
|
|
75
|
+
if (minYCurrentValue < currentLine.bbox[3] &&
|
|
76
|
+
minYCurrentValue >= currentLine.bbox[1]) {
|
|
77
|
+
currentLine.updateField(fieldName, listFieldValue);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
return lineItemsPrepared;
|
|
83
|
+
}
|
|
84
|
+
exports.getLineItems = getLineItems;
|
|
85
|
+
function findBestAnchor(possibleAnchorNames, fields) {
|
|
86
|
+
let anchorName = "";
|
|
87
|
+
let anchorRows = 0;
|
|
88
|
+
possibleAnchorNames.forEach((fieldName) => {
|
|
89
|
+
const fieldValues = fields.get(fieldName)?.values;
|
|
90
|
+
if (fieldValues !== undefined && fieldValues.length > anchorRows) {
|
|
91
|
+
anchorRows = fieldValues.length;
|
|
92
|
+
anchorName = fieldName;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
if (anchorName === "") {
|
|
96
|
+
handler_1.errorHandler.throw(new errors_1.MindeeError("No anchor was found."));
|
|
97
|
+
}
|
|
98
|
+
return anchorName;
|
|
99
|
+
}
|
|
100
|
+
function prepare(anchorName, fields, heigthLineTolerance) {
|
|
101
|
+
const lineItemsPrepared = [];
|
|
102
|
+
const anchorField = fields.get(anchorName);
|
|
103
|
+
if (anchorField === undefined || anchorField.values.length === 0) {
|
|
104
|
+
handler_1.errorHandler.throw(new errors_1.MindeeError("No lines have been detected."));
|
|
105
|
+
}
|
|
106
|
+
let currentLineNumber = 1;
|
|
107
|
+
let currentLine = new Line(currentLineNumber, heigthLineTolerance);
|
|
108
|
+
let currentValue = anchorField.values[0];
|
|
109
|
+
currentLine.extendWith(currentValue.polygon);
|
|
110
|
+
if (anchorField !== undefined) {
|
|
111
|
+
for (let index = 1; index < anchorField.values.length; index++) {
|
|
112
|
+
currentValue = anchorField.values[index];
|
|
113
|
+
const currentFieldBbox = (0, geometry_1.getBbox)(currentValue.polygon);
|
|
114
|
+
if (!currentLine.contains(currentFieldBbox)) {
|
|
115
|
+
lineItemsPrepared.push(currentLine);
|
|
116
|
+
currentLineNumber++;
|
|
117
|
+
currentLine = new Line(currentLineNumber, heigthLineTolerance);
|
|
118
|
+
}
|
|
119
|
+
currentLine.extendWithBbox(currentFieldBbox);
|
|
120
|
+
}
|
|
121
|
+
if (lineItemsPrepared.filter((line) => line.rowNumber === currentLineNumber)
|
|
122
|
+
.length === 0) {
|
|
123
|
+
lineItemsPrepared.push(currentLine);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return new LineItems(lineItemsPrepared);
|
|
127
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InputSource } from "../inputs";
|
|
2
2
|
import { PositionField, FullText, OrientationField, StringDict } from "../fields";
|
|
3
3
|
export type DocumentSig<DocType extends Document> = {
|
|
4
|
-
new ({ prediction, orientation, extras,
|
|
4
|
+
new ({ prediction, orientation, extras, pageId, fullText, documentType, inputSource, }: DocumentConstructorProps): DocType;
|
|
5
5
|
};
|
|
6
6
|
export interface DocumentConstructorProps extends BaseDocumentConstructorProps {
|
|
7
7
|
/** JSON parsed prediction from HTTP response */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InputSource } from "../inputs";
|
|
2
|
-
import { Response, Endpoint,
|
|
2
|
+
import { Response, Endpoint, EndpointResponse, AsyncPredictResponse } from "../api";
|
|
3
3
|
import { Document, FinancialDocumentV0, CustomV1, DocumentSig } from "./index";
|
|
4
4
|
import { PageOptions } from "../inputs";
|
|
5
5
|
interface CustomDocConstructor {
|
|
@@ -13,15 +13,23 @@ export declare class DocumentConfig<DocType extends Document> {
|
|
|
13
13
|
readonly endpoints: Array<Endpoint>;
|
|
14
14
|
readonly documentClass: DocumentSig<DocType>;
|
|
15
15
|
constructor(documentClass: DocumentSig<DocType>, endpoints: Array<Endpoint>, documentType?: string);
|
|
16
|
-
protected predictRequest(inputDoc: InputSource, includeWords: boolean, cropping: boolean): Promise<predictResponse>;
|
|
17
|
-
buildResult(inputFile: InputSource, response: predictResponse): Response<DocType>;
|
|
18
16
|
predict(params: {
|
|
19
17
|
inputDoc: InputSource;
|
|
20
18
|
includeWords: boolean;
|
|
21
19
|
pageOptions?: PageOptions;
|
|
22
20
|
cropper: boolean;
|
|
23
21
|
}): Promise<Response<DocType>>;
|
|
22
|
+
asyncPredict(params: {
|
|
23
|
+
inputDoc: InputSource;
|
|
24
|
+
includeWords: boolean;
|
|
25
|
+
pageOptions?: PageOptions;
|
|
26
|
+
cropper: boolean;
|
|
27
|
+
}): Promise<AsyncPredictResponse<DocType>>;
|
|
28
|
+
getQueuedDocument(queuId: string): Promise<AsyncPredictResponse<DocType>>;
|
|
24
29
|
cutDocPages(inputDoc: InputSource, pageOptions: PageOptions): Promise<void>;
|
|
30
|
+
protected predictRequest(inputDoc: InputSource, includeWords: boolean, cropping: boolean): Promise<EndpointResponse>;
|
|
31
|
+
protected handleError(response: EndpointResponse, statusCode?: number): void;
|
|
32
|
+
protected buildResult(response: EndpointResponse, inputFile?: InputSource): Response<DocType>;
|
|
25
33
|
protected checkApiKeys(): void;
|
|
26
34
|
}
|
|
27
35
|
export declare class CustomDocConfig extends DocumentConfig<CustomV1> {
|
|
@@ -29,6 +37,6 @@ export declare class CustomDocConfig extends DocumentConfig<CustomV1> {
|
|
|
29
37
|
}
|
|
30
38
|
export declare class FinancialDocV0Config extends DocumentConfig<FinancialDocumentV0> {
|
|
31
39
|
constructor(apiKey: string);
|
|
32
|
-
protected predictRequest(inputDoc: InputSource, includeWords: boolean, cropping: boolean): Promise<
|
|
40
|
+
protected predictRequest(inputDoc: InputSource, includeWords: boolean, cropping: boolean): Promise<EndpointResponse>;
|
|
33
41
|
}
|
|
34
42
|
export {};
|
|
@@ -10,28 +10,6 @@ class DocumentConfig {
|
|
|
10
10
|
this.endpoints = endpoints;
|
|
11
11
|
this.documentClass = documentClass;
|
|
12
12
|
}
|
|
13
|
-
async predictRequest(inputDoc, includeWords, cropping) {
|
|
14
|
-
return await this.endpoints[0].predictReqPost(inputDoc, includeWords, cropping);
|
|
15
|
-
}
|
|
16
|
-
buildResult(inputFile, response) {
|
|
17
|
-
const statusCode = response.messageObj.statusCode;
|
|
18
|
-
if (statusCode === undefined || statusCode > 201) {
|
|
19
|
-
const errorMessage = JSON.stringify(response.data, null, 2);
|
|
20
|
-
handler_1.errorHandler.throw(new Error(`${this.endpoints[0].urlName} API ${statusCode} HTTP error: ${errorMessage}`));
|
|
21
|
-
return new api_1.Response(this.documentClass, {
|
|
22
|
-
httpResponse: response,
|
|
23
|
-
documentType: this.documentType,
|
|
24
|
-
input: inputFile,
|
|
25
|
-
error: true,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return new api_1.Response(this.documentClass, {
|
|
29
|
-
httpResponse: response,
|
|
30
|
-
documentType: this.documentType,
|
|
31
|
-
input: inputFile,
|
|
32
|
-
error: false,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
13
|
async predict(params) {
|
|
36
14
|
this.checkApiKeys();
|
|
37
15
|
await params.inputDoc.init();
|
|
@@ -39,17 +17,70 @@ class DocumentConfig {
|
|
|
39
17
|
await this.cutDocPages(params.inputDoc, params.pageOptions);
|
|
40
18
|
}
|
|
41
19
|
const response = await this.predictRequest(params.inputDoc, params.includeWords, params.cropper);
|
|
42
|
-
return this.buildResult(params.inputDoc
|
|
20
|
+
return this.buildResult(response, params.inputDoc);
|
|
21
|
+
}
|
|
22
|
+
async asyncPredict(params) {
|
|
23
|
+
this.checkApiKeys();
|
|
24
|
+
await params.inputDoc.init();
|
|
25
|
+
if (params.pageOptions !== undefined) {
|
|
26
|
+
await this.cutDocPages(params.inputDoc, params.pageOptions);
|
|
27
|
+
}
|
|
28
|
+
const response = await this.endpoints[0].predictAsyncReqPost(params.inputDoc, params.includeWords, params.cropper);
|
|
29
|
+
const statusCode = response.messageObj.statusCode;
|
|
30
|
+
if (statusCode === undefined || statusCode >= 202) {
|
|
31
|
+
this.handleError(response, statusCode);
|
|
32
|
+
}
|
|
33
|
+
return new api_1.AsyncPredictResponse(response.data);
|
|
34
|
+
}
|
|
35
|
+
async getQueuedDocument(queuId) {
|
|
36
|
+
this.checkApiKeys();
|
|
37
|
+
const queueResponse = await this.endpoints[0].documentQueueReqGet(queuId);
|
|
38
|
+
const queueStatusCode = queueResponse.messageObj.statusCode;
|
|
39
|
+
if (queueStatusCode === undefined ||
|
|
40
|
+
queueStatusCode < 200 ||
|
|
41
|
+
queueStatusCode > 302) {
|
|
42
|
+
this.handleError(queueResponse, queueStatusCode);
|
|
43
|
+
}
|
|
44
|
+
if (queueStatusCode === 302 &&
|
|
45
|
+
queueResponse.messageObj.headers.location !== undefined) {
|
|
46
|
+
const docId = queueResponse.messageObj.headers.location.split("/").pop();
|
|
47
|
+
if (docId !== undefined) {
|
|
48
|
+
const docResponse = await this.endpoints[0].documentGetReq(docId);
|
|
49
|
+
const document = this.buildResult(docResponse);
|
|
50
|
+
return new api_1.AsyncPredictResponse(docResponse.data, document);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return new api_1.AsyncPredictResponse(queueResponse.data);
|
|
43
54
|
}
|
|
44
55
|
async cutDocPages(inputDoc, pageOptions) {
|
|
45
56
|
if (inputDoc.isPdf()) {
|
|
46
57
|
await inputDoc.cutPdf(pageOptions);
|
|
47
58
|
}
|
|
48
59
|
}
|
|
60
|
+
// this is only a separate function because of financial docs
|
|
61
|
+
async predictRequest(inputDoc, includeWords, cropping) {
|
|
62
|
+
return await this.endpoints[0].predictReqPost(inputDoc, includeWords, cropping);
|
|
63
|
+
}
|
|
64
|
+
handleError(response, statusCode) {
|
|
65
|
+
const errorMessage = JSON.stringify(response.data, null, 2);
|
|
66
|
+
handler_1.errorHandler.throw(new Error(`${this.endpoints[0].urlName} API ${statusCode} HTTP error: ${errorMessage}`));
|
|
67
|
+
}
|
|
68
|
+
buildResult(response, inputFile) {
|
|
69
|
+
const statusCode = response.messageObj.statusCode;
|
|
70
|
+
if (statusCode === undefined || statusCode > 201) {
|
|
71
|
+
this.handleError(response, statusCode);
|
|
72
|
+
}
|
|
73
|
+
return new api_1.Response(this.documentClass, {
|
|
74
|
+
httpResponse: response,
|
|
75
|
+
documentType: this.documentType,
|
|
76
|
+
error: false,
|
|
77
|
+
input: inputFile,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
49
80
|
checkApiKeys() {
|
|
50
81
|
this.endpoints.forEach((endpoint) => {
|
|
51
82
|
if (!endpoint.apiKey) {
|
|
52
|
-
throw new Error(`Missing API key for '${
|
|
83
|
+
throw new Error(`Missing API key for '${endpoint.urlName} ${endpoint.version}', check your Client configuration.
|
|
53
84
|
You can set this using the '${api_1.API_KEY_ENVVAR_NAME}' environment variable.\n`);
|
|
54
85
|
}
|
|
55
86
|
});
|
|
@@ -19,9 +19,11 @@ class LicensePlateV1 extends document_1.Document {
|
|
|
19
19
|
})));
|
|
20
20
|
}
|
|
21
21
|
toString() {
|
|
22
|
-
const outStr = `----- EU License
|
|
22
|
+
const outStr = `----- EU License Plate V1 -----
|
|
23
23
|
Filename: ${this.filename}
|
|
24
|
-
License
|
|
24
|
+
License Plates: ${this.licensePlates
|
|
25
|
+
.map((plate) => plate.value)
|
|
26
|
+
.join("\n ")}
|
|
25
27
|
----------------------
|
|
26
28
|
`;
|
|
27
29
|
return LicensePlateV1.cleanOutString(outStr);
|
|
@@ -27,9 +27,10 @@ class BankAccountDetailsV1 extends document_1.Document {
|
|
|
27
27
|
}
|
|
28
28
|
toString() {
|
|
29
29
|
const outStr = `----- FR Bank Account Details V1 -----
|
|
30
|
+
Filename: ${this.filename}
|
|
30
31
|
IBAN: ${this.iban}
|
|
31
|
-
Account
|
|
32
|
-
SWIFT: ${this.swift}
|
|
32
|
+
Account Holder's Name: ${this.accountHolderName}
|
|
33
|
+
SWIFT Code: ${this.swift}
|
|
33
34
|
----------------------
|
|
34
35
|
`;
|
|
35
36
|
return BankAccountDetailsV1.cleanOutString(outStr);
|
|
@@ -33,10 +33,10 @@ class CarteVitaleV1 extends document_1.Document {
|
|
|
33
33
|
toString() {
|
|
34
34
|
const outStr = `----- FR Carte Vitale V1 -----
|
|
35
35
|
Filename: ${this.filename}
|
|
36
|
-
Given
|
|
36
|
+
Given Name(s): ${this.givenNames.map((name) => name.value).join(" ")}
|
|
37
37
|
Surname: ${this.surname}
|
|
38
38
|
Social Security Number: ${this.socialSecurity}
|
|
39
|
-
Issuance
|
|
39
|
+
Issuance Date: ${this.issuanceDate}
|
|
40
40
|
----------------------
|
|
41
41
|
`;
|
|
42
42
|
return CarteVitaleV1.cleanOutString(outStr);
|
|
@@ -58,19 +58,19 @@ class IdCardV1 extends document_1.Document {
|
|
|
58
58
|
})));
|
|
59
59
|
}
|
|
60
60
|
toString() {
|
|
61
|
-
const outStr = `----- FR
|
|
61
|
+
const outStr = `----- FR Carte Nationale d'Identité V1 -----
|
|
62
62
|
Filename: ${this.filename}
|
|
63
|
-
Document
|
|
64
|
-
|
|
65
|
-
Given
|
|
63
|
+
Document Side: ${this.documentSide}
|
|
64
|
+
Identity Number: ${this.idNumber}
|
|
65
|
+
Given Name(s): ${this.givenNames.map((name) => name.value).join(" ")}
|
|
66
66
|
Surname: ${this.surname}
|
|
67
|
+
Date of Birth: ${this.birthDate}
|
|
68
|
+
Place of Birth: ${this.birthPlace}
|
|
69
|
+
Expiry Date: ${this.expiryDate}
|
|
70
|
+
Issuing Authority: ${this.authority}
|
|
67
71
|
Gender: ${this.gender}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
Birth place: ${this.birthPlace}
|
|
71
|
-
Expiry date: ${this.expiryDate}
|
|
72
|
-
MRZ 1: ${this.mrz1}
|
|
73
|
-
MRZ 2: ${this.mrz2}
|
|
72
|
+
MRZ Line 1: ${this.mrz1}
|
|
73
|
+
MRZ Line 2: ${this.mrz2}
|
|
74
74
|
----------------------
|
|
75
75
|
`;
|
|
76
76
|
return IdCardV1.cleanOutString(outStr);
|
package/src/documents/index.d.ts
CHANGED
|
@@ -7,10 +7,11 @@ export { PassportV1 } from "./passport/passportV1";
|
|
|
7
7
|
export { FinancialDocumentV0 } from "./financialDocument/financialDocumentV0";
|
|
8
8
|
export { FinancialDocumentV1 } from "./financialDocument/financialDocumentV1";
|
|
9
9
|
export { CustomV1 } from "./custom/customV1";
|
|
10
|
+
export { getLineItems } from "./custom/lineitems";
|
|
10
11
|
export { CropperV1 } from "./cropper/cropperV1";
|
|
11
12
|
export { MindeeVisionV1 } from "./mindeeVision/mindeeVisionV1";
|
|
12
13
|
export { ProofOfAddressV1 } from "./proofOfAddress/proofOfAddressV1";
|
|
13
|
-
export { ShippingContainerV1 } from "./
|
|
14
|
+
export { ShippingContainerV1 } from "./shippingContainer/shippingContainerV1";
|
|
14
15
|
export { Document, DocumentConstructorProps, DocumentSig } from "./document";
|
|
15
16
|
export * as fr from "./fr";
|
|
16
17
|
export * as us from "./us";
|
package/src/documents/index.js
CHANGED
|
@@ -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.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.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");
|
|
@@ -43,13 +43,15 @@ var financialDocumentV1_1 = require("./financialDocument/financialDocumentV1");
|
|
|
43
43
|
Object.defineProperty(exports, "FinancialDocumentV1", { enumerable: true, get: function () { return financialDocumentV1_1.FinancialDocumentV1; } });
|
|
44
44
|
var customV1_1 = require("./custom/customV1");
|
|
45
45
|
Object.defineProperty(exports, "CustomV1", { enumerable: true, get: function () { return customV1_1.CustomV1; } });
|
|
46
|
+
var lineitems_1 = require("./custom/lineitems");
|
|
47
|
+
Object.defineProperty(exports, "getLineItems", { enumerable: true, get: function () { return lineitems_1.getLineItems; } });
|
|
46
48
|
var cropperV1_1 = require("./cropper/cropperV1");
|
|
47
49
|
Object.defineProperty(exports, "CropperV1", { enumerable: true, get: function () { return cropperV1_1.CropperV1; } });
|
|
48
50
|
var mindeeVisionV1_1 = require("./mindeeVision/mindeeVisionV1");
|
|
49
51
|
Object.defineProperty(exports, "MindeeVisionV1", { enumerable: true, get: function () { return mindeeVisionV1_1.MindeeVisionV1; } });
|
|
50
52
|
var proofOfAddressV1_1 = require("./proofOfAddress/proofOfAddressV1");
|
|
51
53
|
Object.defineProperty(exports, "ProofOfAddressV1", { enumerable: true, get: function () { return proofOfAddressV1_1.ProofOfAddressV1; } });
|
|
52
|
-
var shippingContainerV1_1 = require("./
|
|
54
|
+
var shippingContainerV1_1 = require("./shippingContainer/shippingContainerV1");
|
|
53
55
|
Object.defineProperty(exports, "ShippingContainerV1", { enumerable: true, get: function () { return shippingContainerV1_1.ShippingContainerV1; } });
|
|
54
56
|
var document_1 = require("./document");
|
|
55
57
|
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Document, DocumentConstructorProps } from "../document";
|
|
2
|
-
import { TaxField, PaymentDetails, Locale, Amount, TextField, DateField, CompanyRegistration
|
|
2
|
+
import { ClassificationField, TaxField, 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 {
|
|
@@ -7,7 +7,7 @@ export declare class InvoiceV4 extends Document {
|
|
|
7
7
|
/** Locale information. */
|
|
8
8
|
locale: Locale;
|
|
9
9
|
/** The nature of the invoice. */
|
|
10
|
-
documentType:
|
|
10
|
+
documentType: ClassificationField;
|
|
11
11
|
/** List of Reference numbers including PO number. */
|
|
12
12
|
referenceNumbers: TextField[];
|
|
13
13
|
/** The total amount with tax included. */
|
|
@@ -39,7 +39,7 @@ class InvoiceV4 extends document_1.Document {
|
|
|
39
39
|
prediction: prediction.locale,
|
|
40
40
|
valueKey: "language",
|
|
41
41
|
});
|
|
42
|
-
this.documentType = new fields_1.
|
|
42
|
+
this.documentType = new fields_1.ClassificationField({
|
|
43
43
|
prediction: prediction.document_type,
|
|
44
44
|
valueKey: "value",
|
|
45
45
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Document, DocumentConstructorProps } from "../document";
|
|
2
|
+
import { StringDict } from "../../fields";
|
|
2
3
|
export declare class PageGroup {
|
|
3
4
|
pageIndexes: number[];
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
5
|
+
confidence: number;
|
|
6
|
+
constructor(prediction: StringDict);
|
|
7
7
|
toString(): string;
|
|
8
8
|
}
|
|
9
9
|
export declare class InvoiceSplitterV1 extends Document {
|
|
@@ -19,7 +19,6 @@ class ProofOfAddressV1 extends document_1.Document {
|
|
|
19
19
|
this.recipientCompanyRegistration = [];
|
|
20
20
|
this.locale = new fields_1.Locale({
|
|
21
21
|
prediction: prediction.locale,
|
|
22
|
-
valueKey: "language",
|
|
23
22
|
});
|
|
24
23
|
this.issuanceDate = new fields_1.DateField({
|
|
25
24
|
prediction: prediction.date,
|
|
@@ -58,18 +57,18 @@ class ProofOfAddressV1 extends document_1.Document {
|
|
|
58
57
|
const outStr = `----- Proof of Address V1 -----
|
|
59
58
|
Filename: ${this.filename}
|
|
60
59
|
Locale: ${this.locale}
|
|
61
|
-
Issuer
|
|
62
|
-
Issuer Address: ${this.issuerAddress}
|
|
60
|
+
Issuer Name: ${this.issuerName}
|
|
63
61
|
Issuer Company Registrations: ${this.issuerCompanyRegistration
|
|
64
62
|
.map((icr) => icr.value)
|
|
65
63
|
.join(", ")}
|
|
66
|
-
|
|
67
|
-
Recipient
|
|
64
|
+
Issuer Address: ${this.issuerAddress}
|
|
65
|
+
Recipient Name: ${this.recipientName}
|
|
68
66
|
Recipient Company Registrations: ${this.recipientCompanyRegistration
|
|
69
67
|
.map((rcr) => rcr.value)
|
|
70
68
|
.join(", ")}
|
|
71
|
-
|
|
69
|
+
Recipient Address: ${this.recipientAddress}
|
|
72
70
|
Dates: ${this.dates.map((rcr) => rcr.value).join("\n ")}
|
|
71
|
+
Date of Issue: ${this.issuanceDate}
|
|
73
72
|
----------------------
|
|
74
73
|
`;
|
|
75
74
|
return ProofOfAddressV1.cleanOutString(outStr);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Document, DocumentConstructorProps } from "../document";
|
|
2
|
-
import { TaxField, TextField, Amount, Locale, DateField } from "../../fields";
|
|
2
|
+
import { ClassificationField, TaxField, TextField, Amount, Locale, DateField } from "../../fields";
|
|
3
3
|
export declare class ReceiptV3 extends Document {
|
|
4
4
|
#private;
|
|
5
5
|
/** Total amount with the tax amount of the purchase. */
|
|
@@ -9,7 +9,7 @@ export declare class ReceiptV3 extends Document {
|
|
|
9
9
|
/** The purchase date. */
|
|
10
10
|
date: DateField;
|
|
11
11
|
/** The type of purchase. */
|
|
12
|
-
category:
|
|
12
|
+
category: ClassificationField;
|
|
13
13
|
/** Merchant's name as seen on the receipt. */
|
|
14
14
|
merchantName: TextField;
|
|
15
15
|
/** Time as seen on the receipt in HH:MM format. */
|
|
@@ -67,9 +67,8 @@ _ReceiptV3_instances = new WeakSet(), _ReceiptV3_initFromApiPrediction = functio
|
|
|
67
67
|
prediction: apiPrediction.date,
|
|
68
68
|
pageId: pageId,
|
|
69
69
|
});
|
|
70
|
-
this.category = new fields_1.
|
|
70
|
+
this.category = new fields_1.ClassificationField({
|
|
71
71
|
prediction: apiPrediction.category,
|
|
72
|
-
pageId: pageId,
|
|
73
72
|
});
|
|
74
73
|
this.merchantName = new fields_1.TextField({
|
|
75
74
|
prediction: apiPrediction.supplier,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Document, DocumentConstructorProps } from "../document";
|
|
2
|
-
import { Amount, DateField, TextField, Locale, TaxField } from "../../fields";
|
|
2
|
+
import { ClassificationField, Amount, DateField, TextField, Locale, TaxField } from "../../fields";
|
|
3
3
|
export declare class ReceiptV4 extends Document {
|
|
4
4
|
/** Where the purchase was made, the language, and the currency. */
|
|
5
5
|
locale: Locale;
|
|
6
6
|
/** The purchase date. */
|
|
7
7
|
date: DateField;
|
|
8
8
|
/** The receipt category among predefined classes. */
|
|
9
|
-
category:
|
|
9
|
+
category: ClassificationField;
|
|
10
10
|
/** The receipt sub-category among predefined classes. */
|
|
11
|
-
subCategory:
|
|
11
|
+
subCategory: ClassificationField;
|
|
12
12
|
/** Whether the document is an expense receipt or a credit card receipt. */
|
|
13
13
|
documentType: TextField;
|
|
14
14
|
/** The name of the supplier or merchant, as seen on the receipt. */
|
|
@@ -41,13 +41,11 @@ class ReceiptV4 extends document_1.Document {
|
|
|
41
41
|
prediction: prediction.date,
|
|
42
42
|
pageId: pageId,
|
|
43
43
|
});
|
|
44
|
-
this.category = new fields_1.
|
|
44
|
+
this.category = new fields_1.ClassificationField({
|
|
45
45
|
prediction: prediction.category,
|
|
46
|
-
pageId: pageId,
|
|
47
46
|
});
|
|
48
|
-
this.subCategory = new fields_1.
|
|
47
|
+
this.subCategory = new fields_1.ClassificationField({
|
|
49
48
|
prediction: prediction.subcategory,
|
|
50
|
-
pageId: pageId,
|
|
51
49
|
});
|
|
52
50
|
this.documentType = new fields_1.TextField({
|
|
53
51
|
prediction: prediction.document_type,
|
|
@@ -28,8 +28,8 @@ class ShippingContainerV1 extends document_1.Document {
|
|
|
28
28
|
const outStr = `----- Shipping Container V1 -----
|
|
29
29
|
Filename: ${this.filename}
|
|
30
30
|
Owner: ${this.owner}
|
|
31
|
-
Serial
|
|
32
|
-
Size and
|
|
31
|
+
Serial Number: ${this.serialNumber}
|
|
32
|
+
Size and Type: ${this.sizeType}
|
|
33
33
|
----------------------
|
|
34
34
|
`;
|
|
35
35
|
return ShippingContainerV1.cleanOutString(outStr);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseField, BaseFieldConstructor } from "./base";
|
|
2
|
+
export declare class ClassificationField extends BaseField {
|
|
3
|
+
/** The confidence score of the prediction. */
|
|
4
|
+
confidence: number;
|
|
5
|
+
/** The classification. */
|
|
6
|
+
value?: string;
|
|
7
|
+
constructor({ prediction, valueKey, reconstructed, }: BaseFieldConstructor);
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClassificationField = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
class ClassificationField extends base_1.BaseField {
|
|
6
|
+
constructor({ prediction, valueKey = "value", reconstructed = false, }) {
|
|
7
|
+
super({ prediction, valueKey, reconstructed });
|
|
8
|
+
this.confidence = prediction.confidence ? prediction.confidence : 0.0;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.ClassificationField = ClassificationField;
|
package/src/fields/field.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StringDict, BaseField } from "./base";
|
|
2
|
-
import { Polygon } from "../geometry";
|
|
2
|
+
import { Polygon, BoundingBox } from "../geometry";
|
|
3
3
|
export interface FieldConstructor {
|
|
4
4
|
prediction: StringDict;
|
|
5
5
|
valueKey?: string;
|
|
@@ -11,7 +11,7 @@ export declare class Field extends BaseField {
|
|
|
11
11
|
* Contains exactly 4 relative vertices coordinates (points) of a right
|
|
12
12
|
* rectangle containing the field in the document.
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
boundingBox: BoundingBox;
|
|
15
15
|
/**
|
|
16
16
|
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
17
17
|
* the field in the document.
|
package/src/fields/field.js
CHANGED
|
@@ -13,11 +13,6 @@ class Field extends base_1.BaseField {
|
|
|
13
13
|
*/
|
|
14
14
|
constructor({ prediction, valueKey = "value", reconstructed = false, pageId, }) {
|
|
15
15
|
super({ prediction, valueKey, reconstructed });
|
|
16
|
-
/**
|
|
17
|
-
* Contains exactly 4 relative vertices coordinates (points) of a right
|
|
18
|
-
* rectangle containing the field in the document.
|
|
19
|
-
*/
|
|
20
|
-
this.bbox = [];
|
|
21
16
|
/**
|
|
22
17
|
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
23
18
|
* the field in the document.
|
|
@@ -27,8 +22,8 @@ class Field extends base_1.BaseField {
|
|
|
27
22
|
this.confidence = prediction.confidence ? prediction.confidence : 0.0;
|
|
28
23
|
if (prediction.polygon) {
|
|
29
24
|
this.polygon = prediction.polygon;
|
|
30
|
-
this.bbox = (0, geometry_1.getBboxAsPolygon)(prediction.polygon);
|
|
31
25
|
}
|
|
26
|
+
this.boundingBox = (0, geometry_1.getBoundingBox)(this.polygon);
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
34
29
|
@param {Field[]} array1 - first Array of Fields
|
package/src/fields/index.d.ts
CHANGED
package/src/fields/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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 = 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.ClassificationField = void 0;
|
|
4
|
+
var classification_1 = require("./classification");
|
|
5
|
+
Object.defineProperty(exports, "ClassificationField", { enumerable: true, get: function () { return classification_1.ClassificationField; } });
|
|
4
6
|
var tax_1 = require("./tax");
|
|
5
7
|
Object.defineProperty(exports, "TaxField", { enumerable: true, get: function () { return tax_1.TaxField; } });
|
|
6
8
|
var paymentDetails_1 = require("./paymentDetails");
|