mindee 4.31.0 → 4.32.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 +10 -0
- package/README.md +1 -1
- package/package.json +9 -9
- package/src/clientV2.js +1 -3
- package/src/input/sources/base64Input.js +5 -0
- package/src/input/sources/bufferInput.js +5 -0
- package/src/input/sources/bytesInput.js +5 -0
- package/src/input/sources/localInputSource.d.ts +16 -0
- package/src/input/sources/localInputSource.js +35 -21
- package/src/input/sources/pathInput.js +4 -1
- package/src/input/sources/streamInput.js +5 -0
- package/src/input/sources/urlInput.js +5 -0
- package/src/pdf/pdfOperation.d.ts +5 -0
- package/src/pdf/pdfOperation.js +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.32.0 - 2025-10-13
|
|
4
|
+
### Changes
|
|
5
|
+
* :sparkles: add getting page count of a local source
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## v4.31.1 - 2025-10-08
|
|
9
|
+
### Fixes
|
|
10
|
+
* :bug: make sure input sources are only initialized once
|
|
11
|
+
|
|
12
|
+
|
|
3
13
|
## v4.31.0 - 2025-10-07
|
|
4
14
|
### Changes
|
|
5
15
|
* :sparkles: allow comparing v2 field confidence
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://opensource.org/licenses/MIT) [](https://opensource.org/licenses/MIT) [](https://github.com/mindee/mindee-api-nodejs) [](https://www.npmjs.com/package/mindee) [](https://www.npmjs.com/package/mindee)
|
|
2
2
|
|
|
3
3
|
# Mindee API Helper Library for Node.js
|
|
4
4
|
Quickly and easily connect to Mindee's API services using Node.js.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.32.0",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "bin/mindee.js",
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"@types/mocha": "^10.0.10",
|
|
45
45
|
"@types/node": "^18.15.13",
|
|
46
46
|
"@types/tmp": "^0.2.6",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
48
|
-
"@typescript-eslint/parser": "^8.
|
|
49
|
-
"chai": "^4.
|
|
50
|
-
"eslint": "^9.
|
|
51
|
-
"eslint-plugin-jsdoc": "^50.
|
|
52
|
-
"mocha": "^11.7.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.42.1",
|
|
48
|
+
"@typescript-eslint/parser": "^8.42.1",
|
|
49
|
+
"chai": "^4.4.1",
|
|
50
|
+
"eslint": "^9.20.1",
|
|
51
|
+
"eslint-plugin-jsdoc": "^50.6.17",
|
|
52
|
+
"mocha": "^11.7.4",
|
|
53
53
|
"nock": "^13.5.6",
|
|
54
54
|
"ts-node": "^10.9.2",
|
|
55
|
-
"typedoc": "~0.28.
|
|
56
|
-
"typescript": "^5.
|
|
55
|
+
"typedoc": "~0.28.14",
|
|
56
|
+
"typescript": "^5.7.3"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@cantoo/pdf-lib": "^2.3.2",
|
package/src/clientV2.js
CHANGED
|
@@ -46,9 +46,7 @@ class ClientV2 {
|
|
|
46
46
|
if (inputSource === undefined) {
|
|
47
47
|
throw new Error("The 'enqueue' function requires an input document.");
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
await inputSource.init();
|
|
51
|
-
}
|
|
49
|
+
await inputSource.init();
|
|
52
50
|
return await this.mindeeApi.reqPostInferenceEnqueue(inputSource, params);
|
|
53
51
|
}
|
|
54
52
|
/**
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Base64Input = void 0;
|
|
4
4
|
const localInputSource_1 = require("./localInputSource");
|
|
5
5
|
const inputSource_1 = require("./inputSource");
|
|
6
|
+
const logger_1 = require("../../logger");
|
|
6
7
|
class Base64Input extends localInputSource_1.LocalInputSource {
|
|
7
8
|
constructor({ inputString, filename }) {
|
|
8
9
|
super({
|
|
@@ -13,6 +14,10 @@ class Base64Input extends localInputSource_1.LocalInputSource {
|
|
|
13
14
|
this.inputString = inputString;
|
|
14
15
|
}
|
|
15
16
|
async init() {
|
|
17
|
+
if (this.initialized) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
logger_1.logger.debug("Loading from base64");
|
|
16
21
|
this.fileObject = Buffer.from(this.inputString, "base64");
|
|
17
22
|
this.mimeType = await this.checkMimetype();
|
|
18
23
|
// clear out the string
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BufferInput = void 0;
|
|
4
4
|
const localInputSource_1 = require("./localInputSource");
|
|
5
5
|
const inputSource_1 = require("./inputSource");
|
|
6
|
+
const logger_1 = require("../../logger");
|
|
6
7
|
class BufferInput extends localInputSource_1.LocalInputSource {
|
|
7
8
|
constructor({ buffer, filename }) {
|
|
8
9
|
super({
|
|
@@ -12,6 +13,10 @@ class BufferInput extends localInputSource_1.LocalInputSource {
|
|
|
12
13
|
this.filename = filename;
|
|
13
14
|
}
|
|
14
15
|
async init() {
|
|
16
|
+
if (this.initialized) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
logger_1.logger.debug("Loading from buffer");
|
|
15
20
|
this.mimeType = await this.checkMimetype();
|
|
16
21
|
this.initialized = true;
|
|
17
22
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BytesInput = void 0;
|
|
4
4
|
const inputSource_1 = require("./inputSource");
|
|
5
5
|
const localInputSource_1 = require("./localInputSource");
|
|
6
|
+
const logger_1 = require("../../logger");
|
|
6
7
|
class BytesInput extends localInputSource_1.LocalInputSource {
|
|
7
8
|
constructor({ inputBytes, filename }) {
|
|
8
9
|
super({
|
|
@@ -13,6 +14,10 @@ class BytesInput extends localInputSource_1.LocalInputSource {
|
|
|
13
14
|
this.inputBytes = inputBytes;
|
|
14
15
|
}
|
|
15
16
|
async init() {
|
|
17
|
+
if (this.initialized) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
logger_1.logger.debug("Loading from bytes");
|
|
16
21
|
this.fileObject = Buffer.from(this.inputBytes);
|
|
17
22
|
this.mimeType = await this.checkMimetype();
|
|
18
23
|
this.inputBytes = new Uint8Array(0);
|
|
@@ -11,6 +11,16 @@ export declare abstract class LocalInputSource extends InputSource {
|
|
|
11
11
|
*/
|
|
12
12
|
protected constructor({ inputType }: InputConstructor);
|
|
13
13
|
protected checkMimetype(): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the file object as a Buffer.
|
|
16
|
+
* @returns Buffer representation of the file object
|
|
17
|
+
* @protected
|
|
18
|
+
*/
|
|
19
|
+
protected getBuffer(): Buffer;
|
|
20
|
+
/**
|
|
21
|
+
* Determines whether the current file is a PDF.
|
|
22
|
+
* @returns {boolean} Returns true if the file is a PDF; otherwise, returns false.
|
|
23
|
+
*/
|
|
14
24
|
isPdf(): boolean;
|
|
15
25
|
/**
|
|
16
26
|
* Cut PDF pages.
|
|
@@ -41,4 +51,10 @@ export declare abstract class LocalInputSource extends InputSource {
|
|
|
41
51
|
* @return boolean
|
|
42
52
|
*/
|
|
43
53
|
hasSourceText(): Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the number of pages in the input source.
|
|
56
|
+
* For PDFs, returns the actual page count. For images, returns 1.
|
|
57
|
+
* @return Promise<number> The number of pages
|
|
58
|
+
*/
|
|
59
|
+
getPageCount(): Promise<number>;
|
|
44
60
|
}
|
|
@@ -104,6 +104,21 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
104
104
|
logger_1.logger.debug(`File is of type: ${mimeType}`);
|
|
105
105
|
return mimeType;
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns the file object as a Buffer.
|
|
109
|
+
* @returns Buffer representation of the file object
|
|
110
|
+
* @protected
|
|
111
|
+
*/
|
|
112
|
+
getBuffer() {
|
|
113
|
+
if (typeof this.fileObject === "string") {
|
|
114
|
+
return Buffer.from(this.fileObject);
|
|
115
|
+
}
|
|
116
|
+
return this.fileObject;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Determines whether the current file is a PDF.
|
|
120
|
+
* @returns {boolean} Returns true if the file is a PDF; otherwise, returns false.
|
|
121
|
+
*/
|
|
107
122
|
isPdf() {
|
|
108
123
|
if (!this.initialized) {
|
|
109
124
|
throw new Error("The `init()` method must be called before calling `isPdf()`.");
|
|
@@ -115,13 +130,9 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
115
130
|
* @param pageOptions
|
|
116
131
|
*/
|
|
117
132
|
async applyPageOptions(pageOptions) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (!(this.fileObject instanceof Buffer)) {
|
|
122
|
-
throw new Error(`Cannot modify an input source of type ${this.inputType}.`);
|
|
123
|
-
}
|
|
124
|
-
const processedPdf = await (0, pdf_2.extractPages)(this.fileObject, pageOptions);
|
|
133
|
+
await this.init();
|
|
134
|
+
const buffer = this.getBuffer();
|
|
135
|
+
const processedPdf = await (0, pdf_2.extractPages)(buffer, pageOptions);
|
|
125
136
|
this.fileObject = processedPdf.file;
|
|
126
137
|
}
|
|
127
138
|
/**
|
|
@@ -145,16 +156,8 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
145
156
|
* @returns A Promise that resolves when the compression is complete.
|
|
146
157
|
*/
|
|
147
158
|
async compress(quality = 85, maxWidth = null, maxHeight = null, forceSourceText = false, disableSourceText = true) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
let buffer;
|
|
152
|
-
if (typeof this.fileObject === "string") {
|
|
153
|
-
buffer = Buffer.from(this.fileObject);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
buffer = this.fileObject;
|
|
157
|
-
}
|
|
159
|
+
await this.init();
|
|
160
|
+
const buffer = this.getBuffer();
|
|
158
161
|
if (this.isPdf()) {
|
|
159
162
|
this.fileObject = await (0, pdf_1.compressPdf)(buffer, quality, forceSourceText, disableSourceText);
|
|
160
163
|
}
|
|
@@ -167,14 +170,25 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
167
170
|
* @return boolean
|
|
168
171
|
*/
|
|
169
172
|
async hasSourceText() {
|
|
170
|
-
|
|
171
|
-
await this.init();
|
|
172
|
-
}
|
|
173
|
+
await this.init();
|
|
173
174
|
if (!this.isPdf()) {
|
|
174
175
|
return false;
|
|
175
176
|
}
|
|
176
|
-
const buffer =
|
|
177
|
+
const buffer = this.getBuffer();
|
|
177
178
|
return (0, pdf_2.hasSourceText)(buffer);
|
|
178
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Returns the number of pages in the input source.
|
|
182
|
+
* For PDFs, returns the actual page count. For images, returns 1.
|
|
183
|
+
* @return Promise<number> The number of pages
|
|
184
|
+
*/
|
|
185
|
+
async getPageCount() {
|
|
186
|
+
await this.init();
|
|
187
|
+
if (!this.isPdf()) {
|
|
188
|
+
return 1;
|
|
189
|
+
}
|
|
190
|
+
const buffer = this.getBuffer();
|
|
191
|
+
return (0, pdf_1.countPages)(buffer);
|
|
192
|
+
}
|
|
179
193
|
}
|
|
180
194
|
exports.LocalInputSource = LocalInputSource;
|
|
@@ -19,7 +19,10 @@ class PathInput extends localInputSource_1.LocalInputSource {
|
|
|
19
19
|
this.filename = path_1.default.basename(this.inputPath);
|
|
20
20
|
}
|
|
21
21
|
async init() {
|
|
22
|
-
|
|
22
|
+
if (this.initialized) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
logger_1.logger.debug(`Loading from path: ${this.inputPath}`);
|
|
23
26
|
this.fileObject = Buffer.from(await fs_1.promises.readFile(this.inputPath));
|
|
24
27
|
this.mimeType = await this.checkMimetype();
|
|
25
28
|
this.initialized = true;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.StreamInput = void 0;
|
|
4
4
|
const localInputSource_1 = require("./localInputSource");
|
|
5
5
|
const inputSource_1 = require("./inputSource");
|
|
6
|
+
const logger_1 = require("../../logger");
|
|
6
7
|
class StreamInput extends localInputSource_1.LocalInputSource {
|
|
7
8
|
constructor({ inputStream, filename }) {
|
|
8
9
|
super({
|
|
@@ -13,6 +14,10 @@ class StreamInput extends localInputSource_1.LocalInputSource {
|
|
|
13
14
|
this.inputStream = inputStream;
|
|
14
15
|
}
|
|
15
16
|
async init() {
|
|
17
|
+
if (this.initialized) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
logger_1.logger.debug("Loading from stream");
|
|
16
21
|
this.fileObject = await this.stream2buffer(this.inputStream);
|
|
17
22
|
this.mimeType = await this.checkMimetype();
|
|
18
23
|
this.initialized = true;
|
|
@@ -8,12 +8,17 @@ const crypto_1 = require("crypto");
|
|
|
8
8
|
const promises_1 = require("fs/promises");
|
|
9
9
|
const https_1 = require("https");
|
|
10
10
|
const bytesInput_1 = require("./bytesInput");
|
|
11
|
+
const logger_1 = require("../../logger");
|
|
11
12
|
class UrlInput extends inputSource_1.InputSource {
|
|
12
13
|
constructor({ url }) {
|
|
13
14
|
super();
|
|
14
15
|
this.url = url;
|
|
15
16
|
}
|
|
16
17
|
async init() {
|
|
18
|
+
if (this.initialized) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
logger_1.logger.debug(`source URL: ${this.url}`);
|
|
17
22
|
if (!this.url.toLowerCase().startsWith("https")) {
|
|
18
23
|
throw new Error("URL must be HTTPS");
|
|
19
24
|
}
|
|
@@ -10,4 +10,9 @@ export interface SplitPdf {
|
|
|
10
10
|
* @returns the new cut pdf file.
|
|
11
11
|
*/
|
|
12
12
|
export declare function extractPages(file: Buffer, pageOptions: PageOptions): Promise<SplitPdf>;
|
|
13
|
+
/**
|
|
14
|
+
* Count the number of pages in a pdf file.
|
|
15
|
+
* @param file
|
|
16
|
+
* @returns the number of pages in the file.
|
|
17
|
+
*/
|
|
13
18
|
export declare function countPages(file: Buffer): Promise<number>;
|
package/src/pdf/pdfOperation.js
CHANGED
|
@@ -66,6 +66,11 @@ async function extractPages(file, pageOptions) {
|
|
|
66
66
|
const fileBuffer = Buffer.from(await newPdf.save());
|
|
67
67
|
return { file: fileBuffer, totalPagesRemoved: sumRemovedPages };
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Count the number of pages in a pdf file.
|
|
71
|
+
* @param file
|
|
72
|
+
* @returns the number of pages in the file.
|
|
73
|
+
*/
|
|
69
74
|
async function countPages(file) {
|
|
70
75
|
const currentPdf = await pdf_lib_1.PDFDocument.load(file, {
|
|
71
76
|
ignoreEncryption: true,
|