mindee 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/mindee/api/request.js +1 -1
- package/mindee/errors/handler.js +1 -1
- package/mindee/index.js +5 -2
- package/mindee/inputs.js +45 -25
- package/mindee/logger.js +8 -7
- package/package.json +13 -4
- 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/document.js +0 -80
- package/dist/documents/fields/amount.js +0 -21
- package/dist/documents/fields/date.js +0 -17
- package/dist/documents/fields/field.js +0 -85
- package/dist/documents/fields/index.js +0 -17
- package/dist/documents/fields/locale.js +0 -25
- package/dist/documents/fields/orientation.js +0 -22
- package/dist/documents/fields/paymentDetails.js +0 -50
- 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/errors/handler.js +0 -17
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v1.4.0
|
|
4
|
+
### Fixes
|
|
5
|
+
* :bug: cut/merge pages of an encrypted PDF leads to unexpected results
|
|
6
|
+
* :bug: logger not activating in some cases
|
|
7
|
+
* :bug: align PDF cut/merge with other client libs
|
|
8
|
+
|
|
9
|
+
### Changes
|
|
10
|
+
* :sparkles: Add TIFF and HEIC support
|
|
11
|
+
* :white_check_mark: fully test PDF cut function
|
|
12
|
+
|
|
13
|
+
## v1.3.3
|
|
14
|
+
|
|
15
|
+
### Fixes
|
|
16
|
+
* 🐛 reject errors instead of printing them only to the console
|
|
17
|
+
|
|
18
|
+
## v1.3.2
|
|
19
|
+
|
|
20
|
+
### Fixes
|
|
21
|
+
* 🐛 use PDF length instead of cut PDF size limit
|
|
22
|
+
|
|
3
23
|
## v1.3.1
|
|
4
24
|
|
|
5
25
|
### Fixes
|
package/mindee/api/request.js
CHANGED
package/mindee/errors/handler.js
CHANGED
package/mindee/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const errorHandler = require("./errors/handler");
|
|
2
|
-
const logger = require("./logger");
|
|
2
|
+
const { logger, LOG_LEVELS } = require("./logger");
|
|
3
3
|
const APIReceipt = require("./api/receipt");
|
|
4
4
|
const APIInvoice = require("./api/invoice");
|
|
5
5
|
const APIFinancialDocument = require("./api/financialDocument");
|
|
@@ -20,7 +20,10 @@ class Client {
|
|
|
20
20
|
this.receiptToken = receiptToken || process.env.MINDEE_RECEIPT_TOKEN;
|
|
21
21
|
this.invoiceToken = invoiceToken || process.env.MINDEE_INVOICE_TOKEN;
|
|
22
22
|
errorHandler.throwOnError = throwOnError;
|
|
23
|
-
logger.level =
|
|
23
|
+
logger.level =
|
|
24
|
+
debug ?? process.env.MINDEE_DEBUG
|
|
25
|
+
? LOG_LEVELS["debug"]
|
|
26
|
+
: LOG_LEVELS["warn"];
|
|
24
27
|
this.receipt = new APIReceipt(this.receiptToken);
|
|
25
28
|
this.invoice = new APIInvoice(this.invoiceToken);
|
|
26
29
|
this.financialDocument = new APIFinancialDocument(
|
package/mindee/inputs.js
CHANGED
|
@@ -6,17 +6,21 @@ const concat = require("concat-stream");
|
|
|
6
6
|
const { Base64Encode } = require("base64-stream");
|
|
7
7
|
const fileType = require("file-type");
|
|
8
8
|
const ArrayBufferEncode = require("base64-arraybuffer");
|
|
9
|
+
const { logger } = require("./logger");
|
|
9
10
|
|
|
10
11
|
class Input {
|
|
11
12
|
MIMETYPES = {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
pdf: "application/pdf",
|
|
14
|
+
heic: "image/heic",
|
|
15
|
+
jpg: "image/jpeg",
|
|
14
16
|
jpeg: "image/jpeg",
|
|
17
|
+
png: "image/png",
|
|
18
|
+
tif: "image/tiff",
|
|
19
|
+
tiff: "image/tiff",
|
|
15
20
|
webp: "image/webp",
|
|
16
|
-
pdf: "application/pdf",
|
|
17
21
|
};
|
|
18
22
|
ALLOWED_INPUT_TYPE = ["base64", "path", "stream", "dummy"];
|
|
19
|
-
|
|
23
|
+
MAX_DOC_PAGES = 3;
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* @param {(String | Buffer)} file - the file that will be read. Either path or base64 string, or a steam
|
|
@@ -47,6 +51,10 @@ class Input {
|
|
|
47
51
|
else if (this.inputType === "path") await this.initFile();
|
|
48
52
|
else if (this.inputType === "stream") await this.initStream();
|
|
49
53
|
else this.initDummy();
|
|
54
|
+
|
|
55
|
+
if (this.fileExtension === "application/pdf" && this.allowCutPdf === true) {
|
|
56
|
+
await this.cutPdf();
|
|
57
|
+
}
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
async initBase64() {
|
|
@@ -67,10 +75,6 @@ class Input {
|
|
|
67
75
|
const filetype = this.filename.split(".").pop();
|
|
68
76
|
this.fileExtension = this.MIMETYPES[filetype];
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
if (this.fileExtension === "application/pdf" && this.allowCutPdf == true) {
|
|
72
|
-
await this.cutPdf();
|
|
73
|
-
}
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
async initFile() {
|
|
@@ -90,10 +94,6 @@ class Input {
|
|
|
90
94
|
);
|
|
91
95
|
}
|
|
92
96
|
this.fileExtension = this.MIMETYPES[filetype];
|
|
93
|
-
|
|
94
|
-
if (this.fileExtension === "application/pdf" && this.allowCutPdf == true) {
|
|
95
|
-
await this.cutPdf();
|
|
96
|
-
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
async initStream() {
|
|
@@ -134,22 +134,42 @@ class Input {
|
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
async cutPdf() {
|
|
139
|
-
// convert document to PDFDocument & cut CUT_PDF_SIZE - 1 first pages and last page
|
|
137
|
+
async countPages() {
|
|
140
138
|
let pdfDocument = await PDFDocument.load(this.fileObject, {
|
|
141
139
|
ignoreEncryption: true,
|
|
142
140
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
141
|
+
return pdfDocument.getPageCount();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Merge PDF pages */
|
|
145
|
+
async cutPdf() {
|
|
146
|
+
let currentPdf = await PDFDocument.load(this.fileObject, {
|
|
147
|
+
ignoreEncryption: true,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const pdfLength = currentPdf.getPageCount();
|
|
151
|
+
if (pdfLength <= this.MAX_DOC_PAGES) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (currentPdf.isEncrypted) {
|
|
156
|
+
logger.warn(
|
|
157
|
+
"PDF of %d pages is encrypted, not possible to cut pages.",
|
|
158
|
+
pdfLength
|
|
159
|
+
);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const newPdf = await PDFDocument.create();
|
|
164
|
+
const pagesNumbers = [0, pdfLength - 2, pdfLength - 1].slice(
|
|
165
|
+
0,
|
|
166
|
+
this.MAX_DOC_PAGES
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
const pages = await newPdf.copyPages(currentPdf, pagesNumbers);
|
|
170
|
+
pages.forEach((page) => newPdf.addPage(page));
|
|
171
|
+
const data = await newPdf.save();
|
|
172
|
+
|
|
153
173
|
if (this.inputType === "path") {
|
|
154
174
|
this.fileObject = Buffer.from(data);
|
|
155
175
|
} else if (this.inputType === "base64") {
|
package/mindee/logger.js
CHANGED
|
@@ -12,22 +12,23 @@ class Logger {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
debug(...args) {
|
|
15
|
-
if (this.level <= LOGGER_LEVELS["debug"]) console.debug(args);
|
|
15
|
+
if (this.level <= LOGGER_LEVELS["debug"]) console.debug(...args);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
info(...args) {
|
|
19
|
-
if (this.level <= LOGGER_LEVELS["info"]) console.info(args);
|
|
19
|
+
if (this.level <= LOGGER_LEVELS["info"]) console.info(...args);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
warn(...args) {
|
|
23
|
-
if (this.level <= LOGGER_LEVELS["warn"]) console.warn(args);
|
|
23
|
+
if (this.level <= LOGGER_LEVELS["warn"]) console.warn(...args);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
error(...args) {
|
|
27
|
-
if (this.level <= LOGGER_LEVELS["error"]) console.error(args);
|
|
27
|
+
if (this.level <= LOGGER_LEVELS["error"]) console.error(...args);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
module.exports = {
|
|
32
|
+
logger: new Logger(),
|
|
33
|
+
LOG_LEVELS: LOGGER_LEVELS,
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"main": "mindee/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "babel mindee -d lib",
|
|
9
|
-
"test": "npm run build && mocha tests/**/*.js",
|
|
9
|
+
"test": "npm run build && mocha tests/*.js tests/**/*.js",
|
|
10
10
|
"lint": "eslint 'mindee/**/*.js' 'tests/*.js' --max-warnings=0 --report-unused-disable-directives && echo '✔ Your .js files look good.'",
|
|
11
11
|
"documentation": "jsdoc -r mindee -d docs"
|
|
12
12
|
},
|
|
13
|
+
"files": [
|
|
14
|
+
"mindee/",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"README.md",
|
|
17
|
+
"CHANGELOG.md"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">= 12.0.0"
|
|
21
|
+
},
|
|
13
22
|
"repository": {
|
|
14
23
|
"type": "git",
|
|
15
24
|
"url": "git+https://github.com/mindee/mindee-api-nodejs.git"
|
|
@@ -20,8 +29,8 @@
|
|
|
20
29
|
},
|
|
21
30
|
"homepage": "https://github.com/mindee/mindee-api-nodejs/#readme",
|
|
22
31
|
"devDependencies": {
|
|
23
|
-
"@babel/cli": "^7.
|
|
24
|
-
"@babel/core": "^7.12
|
|
32
|
+
"@babel/cli": "^7.17.10",
|
|
33
|
+
"@babel/core": "^7.17.12",
|
|
25
34
|
"@babel/eslint-parser": "^7.12.1",
|
|
26
35
|
"@babel/preset-env": "^7.12.7",
|
|
27
36
|
"@babel/register": "^7.12.1",
|
package/.eslintrc
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"node": true,
|
|
4
|
-
"es6": true,
|
|
5
|
-
"mocha": true
|
|
6
|
-
},
|
|
7
|
-
"parser": "@babel/eslint-parser",
|
|
8
|
-
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
|
|
9
|
-
"globals": {
|
|
10
|
-
"Promise": true
|
|
11
|
-
},
|
|
12
|
-
"rules": {
|
|
13
|
-
"quotes": [
|
|
14
|
-
"error",
|
|
15
|
-
"double",
|
|
16
|
-
{
|
|
17
|
-
"avoidEscape": true,
|
|
18
|
-
"allowTemplateLiterals": false
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
"comma-dangle": [2, "always-multiline"],
|
|
22
|
-
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
|
|
23
|
-
}
|
|
24
|
-
}
|
package/.mocharc.yaml
DELETED