mindee 1.2.0 → 1.3.2
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 +47 -27
- package/LICENSE +21 -202
- package/README.md +15 -2
- package/coverage.lcov +0 -0
- package/dist/api/financialDocument.js +51 -0
- package/dist/api/index.js +13 -0
- package/dist/api/invoice.js +59 -0
- package/dist/api/object.js +80 -0
- package/dist/api/receipt.js +45 -0
- package/dist/api/request.js +90 -0
- package/dist/api/response.js +91 -0
- package/dist/documents/document.js +80 -0
- package/dist/documents/fields/amount.js +21 -0
- package/dist/documents/fields/date.js +17 -0
- package/dist/documents/fields/field.js +85 -0
- package/dist/documents/fields/index.js +17 -0
- package/dist/documents/fields/locale.js +25 -0
- package/dist/documents/fields/orientation.js +22 -0
- package/dist/documents/fields/paymentDetails.js +50 -0
- package/dist/documents/fields/tax.js +42 -0
- package/dist/documents/financialDocument.js +216 -0
- package/dist/documents/index.js +13 -0
- package/dist/documents/invoice.js +361 -0
- package/dist/documents/receipt.js +231 -0
- package/dist/errors/handler.js +17 -0
- package/dist/index.js +23 -0
- package/dist/inputs.js +208 -0
- package/dist/logger.js +34 -0
- package/lib/api/financialDocument.js +1 -1
- package/lib/api/invoice.js +1 -1
- package/lib/api/response.js +1 -1
- package/lib/documents/fields/field.js +4 -2
- package/lib/documents/financialDocument.js +8 -51
- package/lib/documents/invoice.js +9 -48
- package/lib/documents/receipt.js +5 -5
- package/lib/index.js +29 -30
- package/lib/inputs.js +2 -0
- package/mindee/api/request.js +16 -14
- package/mindee/inputs.js +15 -12
- package/package.json +5 -5
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.request = void 0;
|
|
30
|
+
const https = __importStar(require("https"));
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
const package_json_1 = require("../../package.json");
|
|
34
|
+
const url_1 = require("url");
|
|
35
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
36
|
+
const os = __importStar(require("os"));
|
|
37
|
+
const request = (url, method, headers, input, includeWords = false) => {
|
|
38
|
+
return new Promise(function (resolve, reject) {
|
|
39
|
+
const form = new form_data_1.default();
|
|
40
|
+
let body;
|
|
41
|
+
headers["User-Agent"] = `mindee-api-nodejs@v${package_json_1.version} nodejs-${process.version} ${os.type().toLowerCase()}`;
|
|
42
|
+
if (["path", "stream"].includes(input.inputType)) {
|
|
43
|
+
const fileParams = { filename: input.filename };
|
|
44
|
+
form.append("document", input.fileObject, fileParams);
|
|
45
|
+
if (includeWords)
|
|
46
|
+
form.append("include_mvision", "true");
|
|
47
|
+
headers = Object.assign(Object.assign({}, headers), form.getHeaders());
|
|
48
|
+
}
|
|
49
|
+
else if (input.inputType === "base64") {
|
|
50
|
+
const body_obj = { document: input.fileObject };
|
|
51
|
+
if (includeWords)
|
|
52
|
+
body_obj["include_mvision"] = "true";
|
|
53
|
+
body = JSON.stringify(body_obj);
|
|
54
|
+
headers["Content-Type"] = "application/json";
|
|
55
|
+
headers["Content-Length"] = body.length;
|
|
56
|
+
}
|
|
57
|
+
const uri = new url_1.URL(url);
|
|
58
|
+
const options = {
|
|
59
|
+
method: method,
|
|
60
|
+
headers: headers,
|
|
61
|
+
hostname: uri.hostname,
|
|
62
|
+
path: `${uri.pathname}${uri.search}`,
|
|
63
|
+
};
|
|
64
|
+
const req = https.request(options, function (res) {
|
|
65
|
+
let responseBody = [];
|
|
66
|
+
res.on("data", function (chunk) {
|
|
67
|
+
responseBody += chunk;
|
|
68
|
+
});
|
|
69
|
+
res.on("end", function () {
|
|
70
|
+
try {
|
|
71
|
+
resolve(Object.assign(Object.assign({}, res), { data: JSON.parse(responseBody) }));
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.log(responseBody, error);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
req.on("error", (err) => {
|
|
79
|
+
reject(err);
|
|
80
|
+
});
|
|
81
|
+
if (["path", "stream"].includes(input.inputType)) {
|
|
82
|
+
form.pipe(req);
|
|
83
|
+
}
|
|
84
|
+
if (input.inputType === "base64") {
|
|
85
|
+
req.write(body);
|
|
86
|
+
req.end();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
exports.request = request;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Response = void 0;
|
|
27
|
+
const receipt_1 = require("@documents/receipt");
|
|
28
|
+
const invoice_1 = require("@documents/invoice");
|
|
29
|
+
const financialDocument_1 = require("@documents/financialDocument");
|
|
30
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
31
|
+
class Response {
|
|
32
|
+
constructor(_a) {
|
|
33
|
+
var { httpResponse, documentType, input, error, reconsctruted = false } = _a, args = __rest(_a, ["httpResponse", "documentType", "input", "error", "reconsctruted"]);
|
|
34
|
+
this.httpResponse = httpResponse;
|
|
35
|
+
this.documentType = documentType;
|
|
36
|
+
this.input = input;
|
|
37
|
+
if (!error && !reconsctruted)
|
|
38
|
+
this.formatResponse();
|
|
39
|
+
if (reconsctruted === true) {
|
|
40
|
+
Object.assign(this, args);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
dump(path) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
return yield promises_1.default.writeFile(path, JSON.stringify(Object.entries(this)));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
static load(path) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const file = promises_1.default.readFile(path);
|
|
51
|
+
const args = JSON.parse(file);
|
|
52
|
+
return new Response(Object.assign({ reconsctruted: true }, args));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
formatResponse() {
|
|
56
|
+
const http_data_document = this.httpResponse.data.document;
|
|
57
|
+
const constructors = {
|
|
58
|
+
receipt: (params) => new receipt_1.Receipt(params),
|
|
59
|
+
invoice: (params) => new invoice_1.Invoice(params),
|
|
60
|
+
financialDocument: (params) => new financialDocument_1.FinancialDocument(params),
|
|
61
|
+
};
|
|
62
|
+
const predictions = http_data_document.inference.pages.entries();
|
|
63
|
+
this[`${this.documentType}s`] = [];
|
|
64
|
+
const document_words_content = [];
|
|
65
|
+
// Create a list of Document (Receipt, Invoice...) for each page of the input document
|
|
66
|
+
for (const [pageNumber, prediction] of predictions) {
|
|
67
|
+
let page_words_content = [];
|
|
68
|
+
if ("ocr" in http_data_document &&
|
|
69
|
+
Object.keys(http_data_document.ocr).length > 0) {
|
|
70
|
+
page_words_content =
|
|
71
|
+
http_data_document.ocr["mvision-v1"].pages[pageNumber].all_words;
|
|
72
|
+
document_words_content.push(...http_data_document.ocr["mvision-v1"].pages[pageNumber].all_words);
|
|
73
|
+
}
|
|
74
|
+
this[`${this.documentType}s`].push(constructors[this.documentType]({
|
|
75
|
+
apiPrediction: prediction.prediction,
|
|
76
|
+
inputFile: this.input,
|
|
77
|
+
pageNumber: pageNumber,
|
|
78
|
+
words: page_words_content,
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
// Merge the list of Document into a unique Document
|
|
82
|
+
this[this.documentType] = constructors[this.documentType]({
|
|
83
|
+
apiPrediction: http_data_document.inference.prediction,
|
|
84
|
+
inputFile: this.input,
|
|
85
|
+
pageNumber: http_data_document.n_pages,
|
|
86
|
+
level: "document",
|
|
87
|
+
words: document_words_content,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.Response = Response;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Document = void 0;
|
|
16
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
17
|
+
class Document {
|
|
18
|
+
/**
|
|
19
|
+
* Takes a list of Documents and return one Document where
|
|
20
|
+
* each field is set with the maximum probability field
|
|
21
|
+
* @param {Input} inputFile - input file given to parse the document
|
|
22
|
+
*/
|
|
23
|
+
constructor(inputFile = undefined) {
|
|
24
|
+
this.filepath = undefined;
|
|
25
|
+
this.filename = undefined;
|
|
26
|
+
this.fileExtension = undefined;
|
|
27
|
+
if (inputFile != undefined) {
|
|
28
|
+
this.filepath = inputFile.filepath;
|
|
29
|
+
this.filename = inputFile.filename;
|
|
30
|
+
this.fileExtension = inputFile.fileExtension;
|
|
31
|
+
}
|
|
32
|
+
this.checklist = {};
|
|
33
|
+
}
|
|
34
|
+
clone() {
|
|
35
|
+
return JSON.parse(JSON.stringify(this));
|
|
36
|
+
}
|
|
37
|
+
/** return true if all checklist of the document if true */
|
|
38
|
+
checkAll() {
|
|
39
|
+
return this.checklist.every((item) => item == true);
|
|
40
|
+
}
|
|
41
|
+
/** Export document into a JSON file */
|
|
42
|
+
dump(path) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
return yield promises_1.default.writeFile(path, JSON.stringify(Object.entries(this)));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** Create a Document from a JSON file */
|
|
48
|
+
static load(path) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const file = promises_1.default.readFile(path);
|
|
51
|
+
const args = JSON.parse(file);
|
|
52
|
+
return new Document(Object.assign({ reconsctruted: true }, args));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Takes a list of Documents and return one Document where
|
|
57
|
+
* each field is set with the maximum probability field
|
|
58
|
+
* @param {Array<Document>} documents - A list of Documents
|
|
59
|
+
*/
|
|
60
|
+
static mergePages(documents) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const finalDocument = documents[0].clone();
|
|
63
|
+
const attributes = Object.getOwnPropertyNames(finalDocument);
|
|
64
|
+
for (const document of documents) {
|
|
65
|
+
for (const attribute of attributes) {
|
|
66
|
+
if (Array.isArray(document === null || document === void 0 ? void 0 : document[attribute])) {
|
|
67
|
+
finalDocument[attribute] = ((_a = finalDocument[attribute]) === null || _a === void 0 ? void 0 : _a.length)
|
|
68
|
+
? finalDocument[attribute]
|
|
69
|
+
: document === null || document === void 0 ? void 0 : document[attribute];
|
|
70
|
+
}
|
|
71
|
+
else if (((_b = document === null || document === void 0 ? void 0 : document[attribute]) === null || _b === void 0 ? void 0 : _b.probability) >
|
|
72
|
+
finalDocument[attribute].probability) {
|
|
73
|
+
finalDocument[attribute] = document === null || document === void 0 ? void 0 : document[attribute];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return finalDocument;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.Document = Document;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Amount = void 0;
|
|
4
|
+
const field_1 = require("@fields/field");
|
|
5
|
+
class Amount extends field_1.Field {
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
8
|
+
* @param {String} valueKey - Key to use in the prediction dict
|
|
9
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
10
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
11
|
+
*/
|
|
12
|
+
constructor({ prediction, valueKey = "amount", reconstructed = false, pageNumber = 0, }) {
|
|
13
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
14
|
+
this.value = +parseFloat(prediction[valueKey]).toFixed(3);
|
|
15
|
+
if (isNaN(this.value)) {
|
|
16
|
+
this.value = undefined;
|
|
17
|
+
this.probability = 0;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.Amount = Amount;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateField = void 0;
|
|
4
|
+
const field_1 = require("@fields/field");
|
|
5
|
+
class DateField extends field_1.Field {
|
|
6
|
+
constructor({ prediction, valueKey = "iso", reconstructed = false, pageNumber = 0, }) {
|
|
7
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
8
|
+
this.dateObject = new Date(this.value);
|
|
9
|
+
if (!(this.dateObject instanceof Date) ||
|
|
10
|
+
isNaN(this.dateObject.valueOf())) {
|
|
11
|
+
this.dateObject = undefined;
|
|
12
|
+
this.probability = 0.0;
|
|
13
|
+
this.value = undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.DateField = DateField;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Field = void 0;
|
|
4
|
+
class Field {
|
|
5
|
+
/**
|
|
6
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
7
|
+
* @param {String} valueKey - Key to use in the prediction dict
|
|
8
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
9
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
10
|
+
* @param {Array<String>} extraFields - Extra fields to get from the prediction and to set as attribute of the Field
|
|
11
|
+
*/
|
|
12
|
+
constructor({ prediction, valueKey = "value", reconstructed = false, extraFields, pageNumber, }) {
|
|
13
|
+
this.pageNumber = pageNumber;
|
|
14
|
+
this.reconstructed = reconstructed;
|
|
15
|
+
this.value = undefined;
|
|
16
|
+
this.probability = prediction.confidence ? prediction.confidence : 0.0;
|
|
17
|
+
this.bbox = prediction.polygon ? prediction.polygon : [];
|
|
18
|
+
if (valueKey in prediction && prediction[valueKey] !== null) {
|
|
19
|
+
this.value = prediction[valueKey];
|
|
20
|
+
if (extraFields) {
|
|
21
|
+
for (const fieldName of extraFields) {
|
|
22
|
+
this[fieldName] = prediction[fieldName];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
compare(other) {
|
|
28
|
+
if (this.value == null && other.value == null)
|
|
29
|
+
return true;
|
|
30
|
+
else if (this.value == null || other.value == null)
|
|
31
|
+
return false;
|
|
32
|
+
else {
|
|
33
|
+
if (typeof this.value == "string") {
|
|
34
|
+
return this.value.toLowerCase() === other.value.toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return this.value === other.value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
@param {Array<Field>} array1 - first Array of Fields
|
|
43
|
+
@param {Array<Field>} array2 - second Array of Fields
|
|
44
|
+
@param {String} attr - Attribute to compare
|
|
45
|
+
@returns {Boolean} - true if all elements in array1 exist in array2 and vice-versa, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
static compareArrays(array1, array2, attr = "value") {
|
|
48
|
+
const list1 = array1.map((item) => item[attr]);
|
|
49
|
+
const list2 = array2.map((item) => item[attr]);
|
|
50
|
+
if (list1.length !== list2.length)
|
|
51
|
+
return false;
|
|
52
|
+
for (const item1 of list1) {
|
|
53
|
+
if (!list2.includes(item1))
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @param {Array<Field>} array - Array of Fields
|
|
60
|
+
* @returns {Number} product of all the fields probaility
|
|
61
|
+
*/
|
|
62
|
+
static arrayProbability(array) {
|
|
63
|
+
let total = 1.0;
|
|
64
|
+
for (const field of array) {
|
|
65
|
+
total *= field.probability;
|
|
66
|
+
if (isNaN(total))
|
|
67
|
+
return 0.0;
|
|
68
|
+
}
|
|
69
|
+
return total;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @param {Array<Field>} array - Array of Fields
|
|
73
|
+
* @returns {Number} Sum of all the Fields values in the array
|
|
74
|
+
*/
|
|
75
|
+
static arraySum(array) {
|
|
76
|
+
let total = 0;
|
|
77
|
+
for (const field of array) {
|
|
78
|
+
total += field.value;
|
|
79
|
+
if (isNaN(total))
|
|
80
|
+
return 0.0;
|
|
81
|
+
}
|
|
82
|
+
return total;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.Field = Field;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Field = exports.DateField = exports.Amount = exports.Locale = exports.Orientation = exports.PaymentDetails = exports.Tax = void 0;
|
|
4
|
+
var tax_1 = require("@fields/tax");
|
|
5
|
+
Object.defineProperty(exports, "Tax", { enumerable: true, get: function () { return tax_1.Tax; } });
|
|
6
|
+
var paymentDetails_1 = require("@fields/paymentDetails");
|
|
7
|
+
Object.defineProperty(exports, "PaymentDetails", { enumerable: true, get: function () { return paymentDetails_1.PaymentDetails; } });
|
|
8
|
+
var orientation_1 = require("@fields/orientation");
|
|
9
|
+
Object.defineProperty(exports, "Orientation", { enumerable: true, get: function () { return orientation_1.Orientation; } });
|
|
10
|
+
var locale_1 = require("@fields/locale");
|
|
11
|
+
Object.defineProperty(exports, "Locale", { enumerable: true, get: function () { return locale_1.Locale; } });
|
|
12
|
+
var amount_1 = require("@fields/amount");
|
|
13
|
+
Object.defineProperty(exports, "Amount", { enumerable: true, get: function () { return amount_1.Amount; } });
|
|
14
|
+
var date_1 = require("@fields/date");
|
|
15
|
+
Object.defineProperty(exports, "DateField", { enumerable: true, get: function () { return date_1.DateField; } });
|
|
16
|
+
var field_1 = require("@fields/field");
|
|
17
|
+
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return field_1.Field; } });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Locale = void 0;
|
|
4
|
+
const field_1 = require("@fields/field");
|
|
5
|
+
class Locale extends field_1.Field {
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
8
|
+
* @param {String} valueKey - Key to use in the prediction dict
|
|
9
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
10
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
11
|
+
*/
|
|
12
|
+
constructor({ prediction, valueKey = "value", reconstructed = false, pageNumber = 0, }) {
|
|
13
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
14
|
+
this.language = undefined;
|
|
15
|
+
this.country = undefined;
|
|
16
|
+
this.currency = undefined;
|
|
17
|
+
if ("language" in prediction && prediction.language !== "N/A")
|
|
18
|
+
this.language = prediction.language;
|
|
19
|
+
if ("country" in prediction && prediction.country !== "N/A")
|
|
20
|
+
this.country = prediction.country;
|
|
21
|
+
if ("currency" in prediction && prediction.currency !== "N/A")
|
|
22
|
+
this.currency = prediction.currency;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Locale = Locale;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Orientation = void 0;
|
|
4
|
+
const field_1 = require("@fields/field");
|
|
5
|
+
class Orientation extends field_1.Field {
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
8
|
+
* @param {String} valueKey - Key to use in the prediction dict
|
|
9
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
10
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
11
|
+
*/
|
|
12
|
+
constructor({ prediction, valueKey = "degrees", reconstructed = false, pageNumber = 0, }) {
|
|
13
|
+
const orientations = [0, 90, 180, 270];
|
|
14
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
15
|
+
this.value = parseInt(prediction[valueKey]);
|
|
16
|
+
if (isNaN(this.value))
|
|
17
|
+
this.probability = 0.0;
|
|
18
|
+
if (!orientations.includes(this.value))
|
|
19
|
+
this.value = 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.Orientation = Orientation;
|
|
@@ -0,0 +1,50 @@
|
|
|
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 _PaymentDetails_instances, _PaymentDetails_setKey;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PaymentDetails = void 0;
|
|
10
|
+
const field_1 = require("@fields/field");
|
|
11
|
+
class PaymentDetails extends field_1.Field {
|
|
12
|
+
/**
|
|
13
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
14
|
+
* @param {String} valueKey - Key to use in the prediction dict to get the iban
|
|
15
|
+
* @param {String} accountNumberKey - Key to use to get the account number in the prediction dict
|
|
16
|
+
* @param {String} ibanKey - Key to use to get the IBAN in the prediction dict
|
|
17
|
+
* @param {String} routingNumberKey - Key to use to get the routing number in the prediction dict
|
|
18
|
+
* @param {String} swiftKey - Key to use to get the SWIFT in the prediction dict
|
|
19
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
20
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
21
|
+
*/
|
|
22
|
+
constructor({ prediction, valueKey = "iban", accountNumberKey = "account_number", ibanKey = "iban", routingNumberKey = "routing_number", swiftKey = "swift", reconstructed = false, pageNumber = 0, }) {
|
|
23
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
24
|
+
_PaymentDetails_instances.add(this);
|
|
25
|
+
this.accountNumber = undefined;
|
|
26
|
+
this.iban = undefined;
|
|
27
|
+
this.routingNumber = undefined;
|
|
28
|
+
this.swift = undefined;
|
|
29
|
+
__classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[accountNumberKey], "accountNumber");
|
|
30
|
+
__classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[ibanKey], "iban");
|
|
31
|
+
__classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[routingNumberKey], "routingNumber");
|
|
32
|
+
__classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[swiftKey], "swift");
|
|
33
|
+
}
|
|
34
|
+
toString() {
|
|
35
|
+
let str = "";
|
|
36
|
+
const keys = ["accountNumber", "iban", "routingNumber", "swift"];
|
|
37
|
+
for (const key of keys) {
|
|
38
|
+
if (this[key])
|
|
39
|
+
str += `${this[key]}; `;
|
|
40
|
+
}
|
|
41
|
+
return str;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.PaymentDetails = PaymentDetails;
|
|
45
|
+
_PaymentDetails_instances = new WeakSet(), _PaymentDetails_setKey = function _PaymentDetails_setKey(value, key) {
|
|
46
|
+
if (typeof value === "string" && value !== "N/A")
|
|
47
|
+
this[key] = value;
|
|
48
|
+
else
|
|
49
|
+
this[key] = undefined;
|
|
50
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Tax = void 0;
|
|
4
|
+
const field_1 = require("@fields/field");
|
|
5
|
+
class Tax extends field_1.Field {
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
8
|
+
* @param {String} valueKey - Key to use in the prediction dict to get the tax value
|
|
9
|
+
* @param {String} rateKey - Key to use to get the tax rate in the prediction dict
|
|
10
|
+
* @param {String} codeKey - Key to use to get the tax code in the prediction dict
|
|
11
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
12
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
13
|
+
*/
|
|
14
|
+
constructor({ prediction, valueKey = "value", rateKey = "rate", codeKey = "code", reconstructed = false, pageNumber = 0, }) {
|
|
15
|
+
var _a;
|
|
16
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
17
|
+
this.rate = parseFloat(prediction[rateKey]);
|
|
18
|
+
if (isNaN(this.rate))
|
|
19
|
+
this.rate = undefined;
|
|
20
|
+
this.code = (_a = prediction[codeKey]) === null || _a === void 0 ? void 0 : _a.toString();
|
|
21
|
+
if (this.code === "N/A")
|
|
22
|
+
this.code = undefined;
|
|
23
|
+
this.value = parseFloat(prediction[valueKey]);
|
|
24
|
+
if (isNaN(this.value)) {
|
|
25
|
+
this.value = undefined;
|
|
26
|
+
this.probability = 0.0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
toString() {
|
|
30
|
+
let str = "";
|
|
31
|
+
const keys = ["value", "rate", "code"];
|
|
32
|
+
for (const [i, key] of keys.entries()) {
|
|
33
|
+
const value = this[key] === undefined ? "_" : this[key].toString();
|
|
34
|
+
if (i < keys.length - 1)
|
|
35
|
+
str += `${value}${key === "rate" ? "%" : ""}; `;
|
|
36
|
+
else
|
|
37
|
+
str += value;
|
|
38
|
+
}
|
|
39
|
+
return str;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Tax = Tax;
|