mindee 5.0.0-rc2 → 5.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 CHANGED
@@ -1,19 +1,38 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 5.0.0-rc2 - 2026-01-18
3
+ ## v5.0.0 - 2026-02-19
4
+ ### ¡Breaking Changes!
5
+ * :boom: :sparkles: move PDF and image libraries to optional dependencies (resolves #388)
6
+ * :recycle: :boom: rework of directory structure and exports (resolves #276)
7
+ * :boom: drop support for node.js 18
8
+ * :boom: :recycle: separate polling options
9
+ * :coffin: remove support for API builder (no longer maintained, use v2)
10
+ * :coffin: remove support for v1 products available in v2
11
+ * :coffin: remove support for unused products
12
+ ### Changes
13
+ * :sparkles: add support for all utility products
14
+ * :sparkles: add V2 CLI
15
+ * :sparkles: add Job to inference responses
16
+ * :sparkles: handle abort signal stream inputs
17
+ * :recycle: use undici (compatible with v6 or v7) for HTTP requests and mocking
18
+ * :sparkles: add ability for a user to specify their own undici `Dispatcher` instance
19
+ * :recycle: migrate to ES modules
20
+
21
+
22
+ ## v5.0.0-rc2 - 2026-02-18
4
23
  ### Changes
5
24
  * :sparkles: add Job to inference responses
6
25
  ### Fixes
7
26
  * :bug: fix for bin scripts
8
27
 
9
28
 
10
- ## 5.0.0-rc1 - 2026-01-17
29
+ ## v5.0.0-rc1 - 2026-02-17
11
30
  ### Changes
12
31
  * :boom: drop support for node.js 18
13
32
  * :boom: :recycle: separate polling options
14
33
 
15
34
 
16
- ## 5.0.0-alpha2 - 2026-01-16
35
+ ## v5.0.0-alpha2 - 2026-02-16
17
36
  ### Changes
18
37
  * :recycle: use node test methods
19
38
  * :recycle: v1 ocr word should be a class
@@ -21,7 +40,7 @@
21
40
  * :bug: fix for optional node-poppler
22
41
 
23
42
 
24
- ## 5.0.0-alpha1 - 2026-01-13
43
+ ## v5.0.0-alpha1 - 2026-02-13
25
44
  ### :boom: :recycle: base for v5
26
45
  * :arrow_up: update file-type
27
46
  * :recycle: migrate to ES modules (node18)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "5.0.0-rc2",
3
+ "version": "5.0.0",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "author": {
6
6
  "name": "Mindee",
@@ -47,16 +47,16 @@
47
47
  "node": ">= 20.1"
48
48
  },
49
49
  "dependencies": {
50
- "commander": "~9.4.1",
51
- "file-type": "^19.6.0",
50
+ "commander": "^14.0.3",
51
+ "file-type": "^21.3.0",
52
52
  "tmp": "^0.2.3",
53
53
  "tslib": "^2.8.1",
54
- "undici": "^6.23.0"
54
+ "undici": ">=6.23.0 <8.0.0"
55
55
  },
56
56
  "optionalDependencies": {
57
- "@cantoo/pdf-lib": "^2.3.2",
58
- "node-poppler": "^7.2.4",
59
- "pdf.js-extract": "^0.2.1",
57
+ "@cantoo/pdf-lib": "^2.5.3",
58
+ "node-poppler": "^9.1.1",
59
+ "pdf.js-extract": "~0.2.1",
60
60
  "sharp": "~0.34.5"
61
61
  },
62
62
  "devDependencies": {
@@ -23,4 +23,5 @@ export declare class Polygon extends Array<Point> {
23
23
  * Determine if a Point is within the Polygon's Y axis (same line).
24
24
  */
25
25
  isPointInY(point: Point): boolean;
26
+ toString(): string;
26
27
  }
@@ -36,4 +36,7 @@ export class Polygon extends Array {
36
36
  const yCoords = this.getMinMaxY();
37
37
  return isPointInY(point, yCoords.min, yCoords.max);
38
38
  }
39
+ toString() {
40
+ return this.map((point) => `(${point})`).join(", ");
41
+ }
39
42
  }
@@ -1,13 +1,13 @@
1
- import { Dispatcher } from "undici";
1
+ import { Dispatcher, FormData } from "undici";
2
2
  import { InputSource, PageOptions } from "../input/index.js";
3
- export declare const TIMEOUT_DEFAULT: number;
3
+ export declare const TIMEOUT_SECS_DEFAULT: number;
4
4
  export interface RequestOptions {
5
5
  hostname: string;
6
6
  path: string;
7
7
  method: any;
8
- timeout: number;
8
+ timeoutSecs: number;
9
9
  headers: any;
10
- body?: any;
10
+ body?: FormData | string;
11
11
  }
12
12
  export interface BaseHttpResponse {
13
13
  messageObj: any;
@@ -1,7 +1,7 @@
1
1
  import { logger } from "../logger.js";
2
2
  import { request } from "undici";
3
3
  import { LocalInputSource } from "../input/index.js";
4
- export const TIMEOUT_DEFAULT = 120;
4
+ export const TIMEOUT_SECS_DEFAULT = 120;
5
5
  /**
6
6
  * Cuts a document's pages according to the given options.
7
7
  * @param inputDoc input document.
@@ -24,10 +24,9 @@ export async function sendRequestAndReadResponse(dispatcher, options) {
24
24
  const response = await request(url, {
25
25
  method: options.method,
26
26
  headers: options.headers,
27
- bodyTimeout: options.timeout,
27
+ headersTimeout: options.timeoutSecs * 1000,
28
28
  body: options.body,
29
- throwOnError: false,
30
- dispatcher: dispatcher
29
+ dispatcher: dispatcher,
31
30
  });
32
31
  logger.debug("Parsing the response ...");
33
32
  let responseBody = await response.body.text();
@@ -6,7 +6,7 @@ export interface MindeeApiConstructorProps {
6
6
  export declare abstract class BaseSettings {
7
7
  apiKey: string;
8
8
  hostname: string;
9
- timeout: number;
9
+ timeoutSecs: number;
10
10
  dispatcher: Dispatcher;
11
11
  protected constructor(apiKey?: string, dispatcher?: Dispatcher);
12
12
  protected getUserAgent(): string;
@@ -1,7 +1,7 @@
1
1
  import { getGlobalDispatcher } from "undici";
2
2
  import packageJson from "../../package.json" with { type: "json" };
3
3
  import * as os from "os";
4
- import { TIMEOUT_DEFAULT } from "./apiCore.js";
4
+ import { TIMEOUT_SECS_DEFAULT } from "./apiCore.js";
5
5
  export class BaseSettings {
6
6
  constructor(apiKey, dispatcher) {
7
7
  if (apiKey === undefined || !apiKey || apiKey.length === 0) {
@@ -12,7 +12,9 @@ export class BaseSettings {
12
12
  }
13
13
  this.dispatcher = dispatcher ?? getGlobalDispatcher();
14
14
  this.hostname = this.hostnameFromEnv();
15
- this.timeout = process.env.MINDEE_REQUEST_TIMEOUT ? parseInt(process.env.MINDEE_REQUEST_TIMEOUT) : TIMEOUT_DEFAULT;
15
+ this.timeoutSecs = process.env.MINDEE_REQUEST_TIMEOUT
16
+ ? parseInt(process.env.MINDEE_REQUEST_TIMEOUT)
17
+ : TIMEOUT_SECS_DEFAULT;
16
18
  }
17
19
  getUserAgent() {
18
20
  let platform = os.type().toLowerCase();
@@ -5,8 +5,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
5
5
  };
6
6
  var _Endpoint_instances, _Endpoint_predictReqPost, _Endpoint_predictAsyncReqPost, _Endpoint_documentQueueReqGet, _Endpoint_documentGetReq, _Endpoint_documentFeedbackPutReq;
7
7
  import { URLSearchParams } from "url";
8
+ import { FormData } from "undici";
8
9
  import { LocalInputSource } from "../../input/index.js";
9
- import { cutDocPages, sendRequestAndReadResponse } from "../../http/apiCore.js";
10
+ import { cutDocPages, sendRequestAndReadResponse, } from "../../http/apiCore.js";
10
11
  import { handleError } from "./errors.js";
11
12
  import { isValidAsyncResponse, isValidSyncResponse } from "./responseValidation.js";
12
13
  /**
@@ -162,7 +163,7 @@ export class Endpoint {
162
163
  headers: this.settings.baseHeaders,
163
164
  hostname: this.settings.hostname,
164
165
  path: path,
165
- timeout: this.settings.timeout,
166
+ timeoutSecs: this.settings.timeoutSecs,
166
167
  body: form,
167
168
  };
168
169
  return await sendRequestAndReadResponse(this.settings.dispatcher, options);
@@ -193,7 +194,7 @@ async function _Endpoint_documentQueueReqGet(queueId) {
193
194
  headers: this.settings.baseHeaders,
194
195
  hostname: this.settings.hostname,
195
196
  path: `${this.urlRoot}/documents/queue/${queueId}`,
196
- timeout: this.settings.timeout,
197
+ timeoutSecs: this.settings.timeoutSecs,
197
198
  };
198
199
  return await sendRequestAndReadResponse(this.settings.dispatcher, options);
199
200
  }, _Endpoint_documentGetReq =
@@ -207,7 +208,7 @@ async function _Endpoint_documentGetReq(documentId) {
207
208
  headers: this.settings.baseHeaders,
208
209
  hostname: this.settings.hostname,
209
210
  path: `${this.urlRoot}/documents/${documentId}`,
210
- timeout: this.settings.timeout,
211
+ timeoutSecs: this.settings.timeoutSecs,
211
212
  };
212
213
  return await sendRequestAndReadResponse(this.settings.dispatcher, options);
213
214
  }, _Endpoint_documentFeedbackPutReq =
@@ -223,7 +224,7 @@ async function _Endpoint_documentFeedbackPutReq(documentId, feedback) {
223
224
  hostname: this.settings.hostname,
224
225
  path: `/v1/documents/${documentId}/feedback`,
225
226
  body: JSON.stringify(feedback),
226
- timeout: this.settings.timeout,
227
+ timeoutSecs: this.settings.timeoutSecs,
227
228
  };
228
229
  return await sendRequestAndReadResponse(this.settings.dispatcher, options);
229
230
  };
@@ -5,8 +5,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
5
5
  };
6
6
  var _WorkflowEndpoint_instances, _WorkflowEndpoint_workflowReqPost;
7
7
  import { URLSearchParams } from "url";
8
+ import { FormData } from "undici";
8
9
  import { LocalInputSource } from "../../input/index.js";
9
- import { cutDocPages, sendRequestAndReadResponse } from "../../http/apiCore.js";
10
+ import { cutDocPages, sendRequestAndReadResponse, } from "../../http/apiCore.js";
10
11
  import { handleError } from "./errors.js";
11
12
  import { isValidSyncResponse } from "./responseValidation.js";
12
13
  /**
@@ -78,7 +79,7 @@ export class WorkflowEndpoint {
78
79
  headers: this.settings.baseHeaders,
79
80
  hostname: this.settings.hostname,
80
81
  path: path,
81
- timeout: this.settings.timeout,
82
+ timeoutSecs: this.settings.timeoutSecs,
82
83
  body: form,
83
84
  };
84
85
  return await sendRequestAndReadResponse(this.settings.dispatcher, options);
package/src/v2/cli.js CHANGED
@@ -16,13 +16,10 @@ function initClient(options) {
16
16
  async function enqueueAndGetInference(product, inputPath, options) {
17
17
  const mindeeClient = initClient(options);
18
18
  const inputSource = new PathInput({ inputPath: inputPath });
19
- const response = await mindeeClient.enqueueAndGetResult(product, inputSource, {
20
- modelId: options.model,
21
- pollingOptions: {
22
- initialDelaySec: 2,
23
- delaySec: 1.5,
24
- maxRetries: 80,
25
- }
19
+ const response = await mindeeClient.enqueueAndGetResult(product, inputSource, { modelId: options.model }, {
20
+ initialDelaySec: 2,
21
+ delaySec: 1.5,
22
+ maxRetries: 80,
26
23
  });
27
24
  if (!response.inference) {
28
25
  throw Error("Inference could not be retrieved");
@@ -47,11 +44,11 @@ export function cli() {
47
44
  .option("-d, --debug", "high verbosity mode")
48
45
  .option("-k, --api-key <api_key>", "your Mindee API key");
49
46
  const inferenceTypes = [
50
- { name: "extraction", description: "Extract data from a document.", product: Extraction },
51
- { name: "crop", description: "Crop a document.", product: Crop },
52
- { name: "split", description: "Split a document into pages.", product: Split },
53
- { name: "ocr", description: "Read text from a document.", product: Ocr },
54
- { name: "classification", description: "Classify a document.", product: Classification },
47
+ { name: "extraction", description: "Extract data from a document.", productClass: Extraction },
48
+ { name: "crop", description: "Crop a document.", productClass: Crop },
49
+ { name: "split", description: "Split a document into pages.", productClass: Split },
50
+ { name: "ocr", description: "Read text from a document.", productClass: Ocr },
51
+ { name: "classification", description: "Classify a document.", productClass: Classification },
55
52
  ];
56
53
  for (const inference of inferenceTypes) {
57
54
  const inferenceCmd = program.command(inference.name)
@@ -59,7 +56,7 @@ export function cli() {
59
56
  addMainOptions(inferenceCmd);
60
57
  inferenceCmd.action(function (inputPath, options) {
61
58
  const allOptions = { ...program.opts(), ...options };
62
- return enqueueAndGetInference(inference.product, inputPath, allOptions);
59
+ return enqueueAndGetInference(inference.productClass, inputPath, allOptions);
63
60
  });
64
61
  }
65
62
  program.parse(process.argv);
@@ -1,3 +1,4 @@
1
+ import { FormData } from "undici";
1
2
  /**
2
3
  * Constructor parameters for BaseParameters and its subclasses.
3
4
  */
@@ -1,3 +1,4 @@
1
+ import { FormData } from "undici";
1
2
  import { MindeeConfigurationError } from "../../errors/index.js";
2
3
  /**
3
4
  * Parameters accepted by all v2 products.
@@ -100,7 +100,7 @@ async function _MindeeApiV2_reqPostProductEnqueue(product, inputSource, params)
100
100
  hostname: this.settings.hostname,
101
101
  path: path,
102
102
  body: form,
103
- timeout: this.settings.timeout,
103
+ timeoutSecs: this.settings.timeoutSecs,
104
104
  };
105
105
  return await sendRequestAndReadResponse(this.settings.dispatcher, options);
106
106
  }, _MindeeApiV2_reqGetJob = async function _MindeeApiV2_reqGetJob(jobId) {
@@ -109,7 +109,7 @@ async function _MindeeApiV2_reqPostProductEnqueue(product, inputSource, params)
109
109
  headers: this.settings.baseHeaders,
110
110
  hostname: this.settings.hostname,
111
111
  path: `/v2/jobs/${jobId}`,
112
- timeout: this.settings.timeout,
112
+ timeoutSecs: this.settings.timeoutSecs,
113
113
  };
114
114
  return await sendRequestAndReadResponse(this.settings.dispatcher, options);
115
115
  }, _MindeeApiV2_reqGetProductResult =
@@ -126,7 +126,7 @@ async function _MindeeApiV2_reqGetProductResult(inferenceId, slug) {
126
126
  headers: this.settings.baseHeaders,
127
127
  hostname: this.settings.hostname,
128
128
  path: `/v2/products/${slug}/results/${inferenceId}`,
129
- timeout: this.settings.timeout,
129
+ timeoutSecs: this.settings.timeoutSecs,
130
130
  };
131
131
  return await sendRequestAndReadResponse(this.settings.dispatcher, options);
132
132
  };
@@ -11,6 +11,7 @@ export class BaseInference {
11
11
  toString() {
12
12
  return ("Inference\n" +
13
13
  "#########\n" +
14
+ this.job.toString() + "\n" +
14
15
  this.model.toString() + "\n" +
15
16
  this.file.toString() + "\n");
16
17
  }
@@ -1,3 +1,4 @@
1
+ import { FormData } from "undici";
1
2
  import { StringDict } from "../../../../parsing/stringDict.js";
2
3
  import { DataSchema } from "./dataSchema.js";
3
4
  import { BaseParameters, BaseParametersConstructor } from "../../../../v2/client/baseParameters.js";
@@ -1,3 +1,4 @@
1
+ import { FormData } from "undici";
1
2
  import { DataSchema } from "./dataSchema.js";
2
3
  import { BaseParameters } from "../../../../v2/client/baseParameters.js";
3
4
  import { logger } from "../../../../logger.js";