mindee 1.3.2 → 2.0.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 +47 -18
- package/README.md +43 -127
- package/bin/mindee +3 -0
- package/dist/package.json +70 -0
- package/dist/src/api/endpoint.d.ts +29 -0
- package/dist/src/api/endpoint.js +148 -0
- package/dist/src/api/index.d.ts +2 -0
- package/dist/src/api/index.js +18 -0
- package/dist/src/api/response.d.ts +52 -0
- package/dist/src/api/response.js +107 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/cli.js +117 -0
- package/dist/src/client.d.ts +48 -0
- package/dist/src/client.js +134 -0
- package/dist/src/constants.d.ts +13 -0
- package/dist/src/constants.js +54 -0
- package/dist/src/documents/custom.d.ts +14 -0
- package/dist/src/documents/custom.js +48 -0
- package/dist/src/documents/document.d.ts +38 -0
- package/dist/{documents → src/documents}/document.js +15 -35
- package/dist/src/documents/documentConfig.d.ts +44 -0
- package/dist/src/documents/documentConfig.js +121 -0
- package/dist/src/documents/financialDocument.d.ts +32 -0
- package/dist/src/documents/financialDocument.js +130 -0
- package/dist/src/documents/index.d.ts +12 -0
- package/dist/src/documents/index.js +20 -0
- package/dist/src/documents/invoice.d.ts +37 -0
- package/dist/src/documents/invoice.js +303 -0
- package/dist/src/documents/passport.d.ts +36 -0
- package/dist/src/documents/passport.js +218 -0
- package/dist/src/documents/receipt.d.ts +24 -0
- package/dist/src/documents/receipt.js +157 -0
- package/dist/src/errors/handler.d.ts +7 -0
- package/dist/{errors → src/errors}/handler.js +5 -4
- package/dist/src/fields/amount.d.ts +13 -0
- package/dist/{documents → src}/fields/amount.js +19 -6
- package/dist/src/fields/companyRegistration.d.ts +6 -0
- package/dist/src/fields/companyRegistration.js +11 -0
- package/dist/src/fields/customDocs.d.ts +42 -0
- package/dist/src/fields/customDocs.js +61 -0
- package/dist/src/fields/date.d.ts +12 -0
- package/dist/src/fields/date.js +25 -0
- package/dist/src/fields/field.d.ts +74 -0
- package/dist/{documents → src}/fields/field.js +48 -27
- package/dist/src/fields/fullText.d.ts +24 -0
- package/dist/src/fields/fullText.js +89 -0
- package/dist/src/fields/index.d.ts +11 -0
- package/dist/src/fields/index.js +27 -0
- package/dist/src/fields/locale.d.ts +13 -0
- package/dist/{documents → src}/fields/locale.js +20 -5
- package/dist/src/fields/orientation.d.ts +10 -0
- package/dist/{documents → src}/fields/orientation.js +5 -5
- package/dist/src/fields/paymentDetails.d.ts +31 -0
- package/dist/{documents → src}/fields/paymentDetails.js +14 -6
- package/dist/src/fields/tax.d.ts +30 -0
- package/dist/src/fields/tax.js +51 -0
- package/dist/src/geometry.d.ts +59 -0
- package/dist/src/geometry.js +113 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +12 -0
- package/dist/src/inputs.d.ts +69 -0
- package/dist/src/inputs.js +223 -0
- package/dist/src/logger.d.ts +20 -0
- package/dist/src/logger.js +35 -0
- package/package.json +45 -26
- package/.eslintrc +0 -24
- package/.mocharc.yaml +0 -2
- package/.nyc_output/f57ba3bc-1777-4ecc-81e1-230327c2a401.json +0 -1
- package/.nyc_output/processinfo/f57ba3bc-1777-4ecc-81e1-230327c2a401.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/.prettierrc +0 -4
- package/.tool-versions +0 -1
- package/CODE_OF_CONDUCT.md +0 -63
- package/CONTRIBUTING.md +0 -84
- package/ISSUE_TEMPLATE.md +0 -45
- package/PULL_REQUEST_TEMPLATE.md +0 -45
- package/babel.config.json +0 -10
- package/coverage/coverage.json +0 -1
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -171
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov.info +0 -1595
- package/coverage.lcov +0 -1595
- package/dist/api/financialDocument.js +0 -51
- package/dist/api/index.js +0 -13
- package/dist/api/invoice.js +0 -59
- package/dist/api/object.js +0 -80
- package/dist/api/receipt.js +0 -45
- package/dist/api/request.js +0 -90
- package/dist/api/response.js +0 -91
- package/dist/documents/fields/date.js +0 -17
- package/dist/documents/fields/index.js +0 -17
- package/dist/documents/fields/tax.js +0 -42
- package/dist/documents/financialDocument.js +0 -216
- package/dist/documents/index.js +0 -13
- package/dist/documents/invoice.js +0 -361
- package/dist/documents/receipt.js +0 -231
- package/dist/index.js +0 -23
- package/dist/inputs.js +0 -208
- package/dist/logger.js +0 -34
- package/examples/.env.example +0 -2
- package/examples/documents/invoices/credit_note.pdf +0 -900
- package/examples/documents/invoices/invoice.pdf +0 -0
- package/examples/documents/invoices/invoice_6p.pdf +0 -0
- package/examples/documents/receipts/receipt.jpg +0 -0
- package/examples/financialDocument.js +0 -32
- package/examples/invoice.js +0 -74
- package/examples/receipt.js +0 -45
- package/lib/api/financialDocument.js +0 -59
- package/lib/api/index.js +0 -7
- package/lib/api/invoice.js +0 -73
- package/lib/api/object.js +0 -90
- package/lib/api/receipt.js +0 -58
- package/lib/api/request.js +0 -84
- package/lib/api/response.js +0 -92
- package/lib/documents/document.js +0 -97
- package/lib/documents/fields/amount.js +0 -35
- package/lib/documents/fields/date.js +0 -36
- package/lib/documents/fields/field.js +0 -102
- package/lib/documents/fields/index.js +0 -9
- package/lib/documents/fields/locale.js +0 -35
- package/lib/documents/fields/orientation.js +0 -33
- package/lib/documents/fields/paymentDetails.js +0 -71
- package/lib/documents/fields/tax.js +0 -57
- package/lib/documents/financialDocument.js +0 -280
- package/lib/documents/index.js +0 -7
- package/lib/documents/invoice.js +0 -451
- package/lib/documents/receipt.js +0 -332
- package/lib/errors/handler.js +0 -19
- package/lib/index.js +0 -40
- package/lib/inputs.js +0 -190
- package/lib/logger.js +0 -52
- package/mindee/api/financialDocument.js +0 -47
- package/mindee/api/index.js +0 -5
- package/mindee/api/invoice.js +0 -53
- package/mindee/api/object.js +0 -82
- package/mindee/api/receipt.js +0 -39
- package/mindee/api/request.js +0 -72
- package/mindee/api/response.js +0 -80
- package/mindee/documents/document.js +0 -69
- package/mindee/documents/fields/amount.js +0 -25
- package/mindee/documents/fields/date.js +0 -29
- package/mindee/documents/fields/field.js +0 -86
- package/mindee/documents/fields/index.js +0 -7
- package/mindee/documents/fields/locale.js +0 -30
- package/mindee/documents/fields/orientation.js +0 -24
- package/mindee/documents/fields/paymentDetails.js +0 -52
- package/mindee/documents/fields/tax.js +0 -47
- package/mindee/documents/financialDocument.js +0 -269
- package/mindee/documents/index.js +0 -5
- package/mindee/documents/invoice.js +0 -456
- package/mindee/documents/receipt.js +0 -287
- package/mindee/errors/handler.js +0 -16
- package/mindee/index.js +0 -36
- package/mindee/inputs.js +0 -158
- package/mindee/logger.js +0 -33
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.APIFinancialDocument = void 0;
|
|
13
|
-
const object_1 = require("@api/object");
|
|
14
|
-
const inputs_1 = require("@mindee/inputs");
|
|
15
|
-
class APIFinancialDocument extends object_1.APIObject {
|
|
16
|
-
constructor(invoiceToken, receiptToken) {
|
|
17
|
-
super(undefined, "financialDocument");
|
|
18
|
-
this.invoiceToken = invoiceToken;
|
|
19
|
-
this.receiptToken = receiptToken;
|
|
20
|
-
this.invoiceToken = invoiceToken;
|
|
21
|
-
this.receiptToken = receiptToken;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @param {String} file: Receipt filepath (allowed jpg, png, tiff, pdf)
|
|
25
|
-
* @param {String} inputType: String in {'path', 'stream', 'base64'}
|
|
26
|
-
* @param {Boolean} includeWords: extract all words into http_response
|
|
27
|
-
* @param {String} version: expense_receipt api version
|
|
28
|
-
* @param {Boolean} cutPdf: Automatically reconstruct pdf with more than 4 pages
|
|
29
|
-
* @returns {Response} Wrapped response with Receipts objects parsed
|
|
30
|
-
*/
|
|
31
|
-
parse({ input, inputType = "path", filename = undefined, version = "3", cutPdf = true, includeWords = false, }) {
|
|
32
|
-
const _super = Object.create(null, {
|
|
33
|
-
parse: { get: () => super.parse },
|
|
34
|
-
_request: { get: () => super._request }
|
|
35
|
-
});
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const inputFile = new inputs_1.Input(input, inputType, cutPdf, filename);
|
|
38
|
-
yield inputFile.init();
|
|
39
|
-
this.apiToken =
|
|
40
|
-
inputFile.fileExtension === "application/pdf"
|
|
41
|
-
? this.invoiceToken
|
|
42
|
-
: this.receiptToken;
|
|
43
|
-
const url = inputFile.fileExtension === "application/pdf"
|
|
44
|
-
? `/invoices/v${version}/predict`
|
|
45
|
-
: `/expense_receipts/v${version}/predict`;
|
|
46
|
-
_super.parse.call(this);
|
|
47
|
-
return _super._request.call(this, url, inputFile, includeWords);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.APIFinancialDocument = APIFinancialDocument;
|
package/dist/api/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.APIInvoice = exports.request = exports.Response = exports.APIReceipt = exports.APIObject = void 0;
|
|
4
|
-
var object_1 = require("@api/object");
|
|
5
|
-
Object.defineProperty(exports, "APIObject", { enumerable: true, get: function () { return object_1.APIObject; } });
|
|
6
|
-
var receipt_1 = require("@api/receipt");
|
|
7
|
-
Object.defineProperty(exports, "APIReceipt", { enumerable: true, get: function () { return receipt_1.APIReceipt; } });
|
|
8
|
-
var response_1 = require("@api/response");
|
|
9
|
-
Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return response_1.Response; } });
|
|
10
|
-
var request_1 = require("@api/request");
|
|
11
|
-
Object.defineProperty(exports, "request", { enumerable: true, get: function () { return request_1.request; } });
|
|
12
|
-
var invoice_1 = require("@api/invoice");
|
|
13
|
-
Object.defineProperty(exports, "APIInvoice", { enumerable: true, get: function () { return invoice_1.APIInvoice; } });
|
package/dist/api/invoice.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.APIInvoice = void 0;
|
|
13
|
-
const object_1 = require("@api/object");
|
|
14
|
-
const inputs_1 = require("@mindee/inputs");
|
|
15
|
-
class APIInvoice extends object_1.APIObject {
|
|
16
|
-
constructor(apiToken = undefined) {
|
|
17
|
-
super(apiToken, "invoice");
|
|
18
|
-
this.apiToken = apiToken;
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
20
|
-
// @ts-ignore TO DO : FIX
|
|
21
|
-
this.baseUrl = `${this.baseUrl}/invoices/`;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @param {Boolean} includeWords: , extract all words into http_response
|
|
25
|
-
* @param {Boolean} cutPdf: Automatically reconstruct pdf with more than 4 pages
|
|
26
|
-
* @param {String} inputType: String in {'path', 'stream', 'base64'}
|
|
27
|
-
* @param {String} file: Receipt filepath (allowed jpg, png, tiff, pdf)
|
|
28
|
-
* @param {String} version: expense_receipt api version
|
|
29
|
-
* @returns {Response} Wrapped response with Receipts objects parsed
|
|
30
|
-
*/
|
|
31
|
-
parse({ input, inputType = "path", filename = undefined, version = "3", cutPdf = true, includeWords = false, }) {
|
|
32
|
-
const _super = Object.create(null, {
|
|
33
|
-
parse: { get: () => super.parse },
|
|
34
|
-
_request: { get: () => super._request }
|
|
35
|
-
});
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
_super.parse.call(this);
|
|
38
|
-
const inputFile = new inputs_1.Input(input, inputType, cutPdf, filename);
|
|
39
|
-
yield inputFile.init();
|
|
40
|
-
const url = `v${version}/predict`;
|
|
41
|
-
return yield _super._request.call(this, url, inputFile, includeWords);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
@param {String} inputFile - Input object
|
|
46
|
-
@param {} response - HTTP response
|
|
47
|
-
@param {Document} documentType - Document class in {"Receipt", "Invoice", "Financial_document"}
|
|
48
|
-
@returns {Response}
|
|
49
|
-
*/
|
|
50
|
-
wrapResponse(inputFile, response, documentType) {
|
|
51
|
-
var _a, _b, _c, _d, _e;
|
|
52
|
-
const result = super.wrapResponse(inputFile, response, documentType);
|
|
53
|
-
result.documentType =
|
|
54
|
-
((_e = (_d = (_c = (_b = (_a = result.httpResponse.data) === null || _a === void 0 ? void 0 : _a.predictions) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.document_type) === null || _d === void 0 ? void 0 : _d.value) === null || _e === void 0 ? void 0 : _e.toLowerCase()) ||
|
|
55
|
-
result.documentType;
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.APIInvoice = APIInvoice;
|
package/dist/api/object.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.APIObject = void 0;
|
|
13
|
-
const response_1 = require("@api/response");
|
|
14
|
-
const handler_1 = require("@errors/handler");
|
|
15
|
-
const request_1 = require("@api/request");
|
|
16
|
-
/**
|
|
17
|
-
* Base class for APIs (APIReceipt & APIInvoice)
|
|
18
|
-
* @param {String} apiToken - Token of the API used for parsing document
|
|
19
|
-
* @param {String} apiName - Name of the API used for parsing document
|
|
20
|
-
*/
|
|
21
|
-
class APIObject {
|
|
22
|
-
constructor(apiToken = undefined, apiName = "") {
|
|
23
|
-
this.apiToken = apiToken;
|
|
24
|
-
this.apiName = apiName;
|
|
25
|
-
this.apiToken = apiToken;
|
|
26
|
-
this.baseUrl = "https://api.mindee.net/v1/products/mindee";
|
|
27
|
-
this.apiName = apiName;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
*/
|
|
31
|
-
parse() {
|
|
32
|
-
if (!this.apiToken) {
|
|
33
|
-
handler_1.errorHandler.throw({
|
|
34
|
-
error: new Error(`Missing API token for ${this.apiName}. \
|
|
35
|
-
Have you create a mindee Client with a ${this.apiName}Token in parameters ?`),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
@param {String} url - API url for request
|
|
41
|
-
@param {Input} inputFile - input file for API
|
|
42
|
-
@param {Boolean} includeWords - Include Mindee vision words in Response
|
|
43
|
-
@returns {Response}
|
|
44
|
-
*/
|
|
45
|
-
_request(url, inputFile, includeWords = false) {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const headers = {
|
|
48
|
-
"X-Inferuser-Token": this.apiToken,
|
|
49
|
-
};
|
|
50
|
-
const response = yield (0, request_1.request)(`${this.baseUrl}${url}`, "POST", headers, inputFile, includeWords);
|
|
51
|
-
return this.wrapResponse(inputFile, response, this.apiName);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
@param {String} inputFile - Input object
|
|
56
|
-
@param {} response - HTTP response
|
|
57
|
-
@param {Document} documentType - Document class in {"Receipt", "Invoice", "Financial_document"}
|
|
58
|
-
@returns {Response}
|
|
59
|
-
*/
|
|
60
|
-
wrapResponse(inputFile, response, documentType) {
|
|
61
|
-
if (response.statusCode > 201) {
|
|
62
|
-
const errorMessage = JSON.stringify(response.data, null, 4);
|
|
63
|
-
handler_1.errorHandler.throw(new Error(`${this.apiName} API ${response.statusCode} HTTP error: ${errorMessage}`));
|
|
64
|
-
return new response_1.Response({
|
|
65
|
-
httpResponse: response,
|
|
66
|
-
documentType: documentType,
|
|
67
|
-
document: undefined,
|
|
68
|
-
input: inputFile,
|
|
69
|
-
error: true,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return new response_1.Response({
|
|
73
|
-
httpResponse: response,
|
|
74
|
-
documentType: documentType,
|
|
75
|
-
document: inputFile,
|
|
76
|
-
input: inputFile,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
exports.APIObject = APIObject;
|
package/dist/api/receipt.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.APIReceipt = void 0;
|
|
13
|
-
const object_1 = require("@api/object");
|
|
14
|
-
const inputs_1 = require("@mindee/inputs");
|
|
15
|
-
class APIReceipt extends object_1.APIObject {
|
|
16
|
-
constructor(apiToken = undefined) {
|
|
17
|
-
super(apiToken, "receipt");
|
|
18
|
-
this.apiToken = apiToken;
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
20
|
-
// @ts-ignore TO DO : FIX
|
|
21
|
-
this.baseUrl = `${this.baseUrl}/expense_receipts/`;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @param {String} file: Receipt filepath (allowed jpg, png, tiff, pdf)
|
|
25
|
-
* @param {String} inputType: String in {'path', 'stream', 'base64'}
|
|
26
|
-
* @param {Boolean} includeWords: extract all words into http_response
|
|
27
|
-
* @param {String} version: expense_receipt api version
|
|
28
|
-
* @param {Boolean} cutPdf: Automatically reconstruct pdf with more than 4 pages
|
|
29
|
-
* @returns {Response} Wrapped response with Receipts objects parsed
|
|
30
|
-
*/
|
|
31
|
-
parse({ input, inputType = "path", filename = undefined, version = "3", cutPdf = true, includeWords = false, }) {
|
|
32
|
-
const _super = Object.create(null, {
|
|
33
|
-
parse: { get: () => super.parse },
|
|
34
|
-
_request: { get: () => super._request }
|
|
35
|
-
});
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
_super.parse.call(this);
|
|
38
|
-
const inputFile = new inputs_1.Input(input, inputType, cutPdf, filename);
|
|
39
|
-
yield inputFile.init();
|
|
40
|
-
const url = `v${version}/predict`;
|
|
41
|
-
return yield _super._request.call(this, url, inputFile, includeWords);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.APIReceipt = APIReceipt;
|
package/dist/api/request.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
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;
|
package/dist/api/response.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
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;
|
|
@@ -1,17 +0,0 @@
|
|
|
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;
|
|
@@ -1,17 +0,0 @@
|
|
|
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; } });
|
|
@@ -1,42 +0,0 @@
|
|
|
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;
|