mindee 5.0.0-rc1 → 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.
Files changed (42) hide show
  1. package/CHANGELOG.md +29 -3
  2. package/package.json +33 -33
  3. package/src/geometry/polygon.d.ts +1 -0
  4. package/src/geometry/polygon.js +3 -0
  5. package/src/http/apiCore.d.ts +4 -4
  6. package/src/http/apiCore.js +3 -4
  7. package/src/http/baseSettings.d.ts +1 -1
  8. package/src/http/baseSettings.js +4 -2
  9. package/src/v1/http/endpoint.js +6 -5
  10. package/src/v1/http/workflowEndpoint.js +3 -2
  11. package/src/v2/cli.js +10 -13
  12. package/src/v2/client/baseParameters.d.ts +2 -5
  13. package/src/v2/client/baseParameters.js +2 -5
  14. package/src/v2/client/index.d.ts +1 -1
  15. package/src/v2/client/pollingOptions.d.ts +11 -13
  16. package/src/v2/client/pollingOptions.js +9 -5
  17. package/src/v2/http/{apiSettingsV2.d.ts → apiSettings.d.ts} +1 -1
  18. package/src/v2/http/{apiSettingsV2.js → apiSettings.js} +2 -1
  19. package/src/v2/http/errors.d.ts +3 -0
  20. package/src/v2/http/errors.js +3 -0
  21. package/src/v2/http/mindeeApiV2.d.ts +2 -2
  22. package/src/v2/http/mindeeApiV2.js +7 -6
  23. package/src/v2/index.d.ts +2 -1
  24. package/src/v2/index.js +1 -0
  25. package/src/v2/parsing/inference/baseInference.d.ts +6 -1
  26. package/src/v2/parsing/inference/baseInference.js +3 -0
  27. package/src/v2/parsing/inference/inferenceJob.d.ts +9 -0
  28. package/src/v2/parsing/inference/inferenceJob.js +10 -0
  29. package/src/v2/product/baseProduct.d.ts +5 -0
  30. package/src/v2/product/baseProduct.js +5 -0
  31. package/src/v2/product/classification/classification.d.ts +3 -0
  32. package/src/v2/product/classification/classification.js +3 -0
  33. package/src/v2/product/crop/crop.d.ts +3 -0
  34. package/src/v2/product/crop/crop.js +3 -0
  35. package/src/v2/product/extraction/extraction.d.ts +3 -0
  36. package/src/v2/product/extraction/extraction.js +3 -0
  37. package/src/v2/product/extraction/params/extractionParameters.d.ts +1 -0
  38. package/src/v2/product/extraction/params/extractionParameters.js +1 -0
  39. package/src/v2/product/ocr/ocr.d.ts +3 -0
  40. package/src/v2/product/ocr/ocr.js +3 -0
  41. package/src/v2/product/split/split.d.ts +3 -0
  42. package/src/v2/product/split/split.js +3 -0
package/CHANGELOG.md CHANGED
@@ -1,12 +1,38 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 5.0.0-rc1 - 2026-01-17
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
23
+ ### Changes
24
+ * :sparkles: add Job to inference responses
25
+ ### Fixes
26
+ * :bug: fix for bin scripts
27
+
28
+
29
+ ## v5.0.0-rc1 - 2026-02-17
4
30
  ### Changes
5
31
  * :boom: drop support for node.js 18
6
32
  * :boom: :recycle: separate polling options
7
33
 
8
34
 
9
- ## 5.0.0-alpha2 - 2026-01-16
35
+ ## v5.0.0-alpha2 - 2026-02-16
10
36
  ### Changes
11
37
  * :recycle: use node test methods
12
38
  * :recycle: v1 ocr word should be a class
@@ -14,7 +40,7 @@
14
40
  * :bug: fix for optional node-poppler
15
41
 
16
42
 
17
- ## 5.0.0-alpha1 - 2026-01-13
43
+ ## v5.0.0-alpha1 - 2026-02-13
18
44
  ### :boom: :recycle: base for v5
19
45
  * :arrow_up: update file-type
20
46
  * :recycle: migrate to ES modules (node18)
package/package.json CHANGED
@@ -1,14 +1,27 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "5.0.0-rc1",
3
+ "version": "5.0.0",
4
4
  "description": "Mindee Client Library for Node.js",
5
+ "author": {
6
+ "name": "Mindee",
7
+ "email": "opensource@mindee.com",
8
+ "url": "https://mindee.com/"
9
+ },
10
+ "license": "MIT",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/mindee/mindee-api-nodejs.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/mindee/mindee-api-nodejs/issues"
17
+ },
18
+ "homepage": "https://mindee.com/",
19
+ "type": "module",
5
20
  "main": "src/index.js",
6
21
  "bin": {
7
22
  "mindeeV1": "bin/mindeeV1.js",
8
23
  "mindeeV2": "bin/mindeeV2.js"
9
24
  },
10
- "license": "MIT",
11
- "type": "module",
12
25
  "scripts": {
13
26
  "build": "tsc --build && tsc-alias",
14
27
  "build-for-dist": "tsc --build && tsc-alias && cp LICENSE README.md CHANGELOG.md ./dist",
@@ -33,46 +46,33 @@
33
46
  "engines": {
34
47
  "node": ">= 20.1"
35
48
  },
36
- "repository": {
37
- "type": "git",
38
- "url": "git+https://github.com/mindee/mindee-api-nodejs.git"
39
- },
40
- "author": {
41
- "name": "Mindee",
42
- "email": "opensource@mindee.com",
43
- "url": "https://mindee.com/"
49
+ "dependencies": {
50
+ "commander": "^14.0.3",
51
+ "file-type": "^21.3.0",
52
+ "tmp": "^0.2.3",
53
+ "tslib": "^2.8.1",
54
+ "undici": ">=6.23.0 <8.0.0"
44
55
  },
45
- "bugs": {
46
- "url": "https://github.com/mindee/mindee-api-nodejs/issues"
56
+ "optionalDependencies": {
57
+ "@cantoo/pdf-lib": "^2.5.3",
58
+ "node-poppler": "^9.1.1",
59
+ "pdf.js-extract": "~0.2.1",
60
+ "sharp": "~0.34.5"
47
61
  },
48
- "homepage": "https://mindee.com/",
49
62
  "devDependencies": {
50
63
  "@types/mocha": "^10.0.10",
51
- "@types/node": "^18.19.130",
64
+ "@types/node": "^20.19.33",
52
65
  "@types/tmp": "^0.2.6",
53
- "@typescript-eslint/eslint-plugin": "^8.55.0",
54
- "@typescript-eslint/parser": "^8.55.0",
66
+ "@typescript-eslint/eslint-plugin": "^8.56.0",
67
+ "@typescript-eslint/parser": "^8.56.0",
55
68
  "eslint": "^9.39.2",
56
- "eslint-plugin-jsdoc": "^52.0.4",
57
- "mocha": "^11.3.0",
69
+ "eslint-plugin-jsdoc": "^62.6.0",
70
+ "mocha": "^11.7.5",
58
71
  "tsc-alias": "^1.8.16",
59
72
  "tsx": "^4.21.0",
60
- "typedoc": "~0.28.16",
73
+ "typedoc": "^0.28.17",
61
74
  "typescript": "^5.9.3"
62
75
  },
63
- "dependencies": {
64
- "commander": "~9.4.1",
65
- "file-type": "^19.6.0",
66
- "tmp": "^0.2.3",
67
- "tslib": "^2.8.1",
68
- "undici": "^6.23.0"
69
- },
70
- "optionalDependencies": {
71
- "@cantoo/pdf-lib": "^2.3.2",
72
- "node-poppler": "^7.2.4",
73
- "pdf.js-extract": "^0.2.1",
74
- "sharp": "~0.34.5"
75
- },
76
76
  "keywords": [
77
77
  "typescript",
78
78
  "mindee",
@@ -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
  */
@@ -8,7 +9,7 @@ export interface BaseParametersConstructor {
8
9
  closeFile?: boolean;
9
10
  }
10
11
  /**
11
- * Parameters accepted by the asynchronous **inference** v2 endpoint.
12
+ * Parameters accepted by all v2 products.
12
13
  *
13
14
  * All fields are optional except `modelId`.
14
15
  *
@@ -19,10 +20,6 @@ export interface BaseParametersConstructor {
19
20
  * rag: true,
20
21
  * alias: "YOUR_ALIAS",
21
22
  * webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"],
22
- * pollingOptions: {
23
- * initialDelaySec: 2,
24
- * delaySec: 1.5,
25
- * }
26
23
  * };
27
24
  */
28
25
  export declare abstract class BaseParameters {
@@ -1,6 +1,7 @@
1
+ import { FormData } from "undici";
1
2
  import { MindeeConfigurationError } from "../../errors/index.js";
2
3
  /**
3
- * Parameters accepted by the asynchronous **inference** v2 endpoint.
4
+ * Parameters accepted by all v2 products.
4
5
  *
5
6
  * All fields are optional except `modelId`.
6
7
  *
@@ -11,10 +12,6 @@ import { MindeeConfigurationError } from "../../errors/index.js";
11
12
  * rag: true,
12
13
  * alias: "YOUR_ALIAS",
13
14
  * webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"],
14
- * pollingOptions: {
15
- * initialDelaySec: 2,
16
- * delaySec: 1.5,
17
- * }
18
15
  * };
19
16
  */
20
17
  export class BaseParameters {
@@ -1,3 +1,3 @@
1
1
  export { PollingOptions } from "./pollingOptions.js";
2
- export type { PollingOptionsConstructor } from "./pollingOptions.js";
2
+ export type { PollingOptionsConstructor, TimerOptions, } from "./pollingOptions.js";
3
3
  export { BaseParameters } from "./baseParameters.js";
@@ -13,8 +13,8 @@ export interface PollingOptionsConstructor {
13
13
  * Parameters for the internal polling loop in `enqueueAndGetInference()`.
14
14
  *
15
15
  * Default behavior:
16
- * - `initialDelaySec` = 2s
17
- * - `delaySec` = 1.5s
16
+ * - `initialDelaySec` = 2
17
+ * - `delaySec` = 1.5
18
18
  * - `maxRetries` = 80
19
19
  *
20
20
  * Validation rules:
@@ -23,17 +23,21 @@ export interface PollingOptionsConstructor {
23
23
  * - `maxRetries` >= 2
24
24
  *
25
25
  * The `initialTimerOptions` and `recurringTimerOptions` objects let you pass an
26
- * `AbortSignal` or make the timer `unref`-ed to the `setTimeout()`.
26
+ * `AbortSignal` or make the timer `ref`-ed to the `setTimeout()`.
27
27
  *
28
28
  * @category ClientV2
29
29
  * @example
30
- * const params = {
30
+ * ```
31
+ * const pollingOptions = {
31
32
  * initialDelaySec: 4,
32
33
  * delaySec: 2,
33
34
  * maxRetries: 50
34
35
  * };
35
36
  *
36
- * const inference = await client.enqueueAndGetInference(inputDoc, params);
37
+ * const inference = await client.enqueueAndGetInference(
38
+ * inputDoc, params, pollingOptions
39
+ * );
40
+ * ```
37
41
  */
38
42
  export declare class PollingOptions {
39
43
  /** Number of seconds to wait *before the first poll*. */
@@ -43,15 +47,9 @@ export declare class PollingOptions {
43
47
  /** Maximum number of polling attempts (including the first one). */
44
48
  maxRetries: number;
45
49
  /** Options passed to the initial `setTimeout()`. */
46
- initialTimerOptions?: {
47
- ref?: boolean;
48
- signal?: AbortSignal;
49
- };
50
+ initialTimerOptions?: TimerOptions;
50
51
  /** Options passed to every recurring `setTimeout()`. */
51
- recurringTimerOptions?: {
52
- ref?: boolean;
53
- signal?: AbortSignal;
54
- };
52
+ recurringTimerOptions?: TimerOptions;
55
53
  constructor(params?: PollingOptionsConstructor);
56
54
  validateOptions(): void;
57
55
  toString(): string;
@@ -7,8 +7,8 @@ const minRetries = 2;
7
7
  * Parameters for the internal polling loop in `enqueueAndGetInference()`.
8
8
  *
9
9
  * Default behavior:
10
- * - `initialDelaySec` = 2s
11
- * - `delaySec` = 1.5s
10
+ * - `initialDelaySec` = 2
11
+ * - `delaySec` = 1.5
12
12
  * - `maxRetries` = 80
13
13
  *
14
14
  * Validation rules:
@@ -17,17 +17,21 @@ const minRetries = 2;
17
17
  * - `maxRetries` >= 2
18
18
  *
19
19
  * The `initialTimerOptions` and `recurringTimerOptions` objects let you pass an
20
- * `AbortSignal` or make the timer `unref`-ed to the `setTimeout()`.
20
+ * `AbortSignal` or make the timer `ref`-ed to the `setTimeout()`.
21
21
  *
22
22
  * @category ClientV2
23
23
  * @example
24
- * const params = {
24
+ * ```
25
+ * const pollingOptions = {
25
26
  * initialDelaySec: 4,
26
27
  * delaySec: 2,
27
28
  * maxRetries: 50
28
29
  * };
29
30
  *
30
- * const inference = await client.enqueueAndGetInference(inputDoc, params);
31
+ * const inference = await client.enqueueAndGetInference(
32
+ * inputDoc, params, pollingOptions
33
+ * );
34
+ * ```
31
35
  */
32
36
  export class PollingOptions {
33
37
  constructor(params) {
@@ -1,5 +1,5 @@
1
1
  import { BaseSettings, MindeeApiConstructorProps } from "../../http/baseSettings.js";
2
- export declare class ApiSettingsV2 extends BaseSettings {
2
+ export declare class ApiSettings extends BaseSettings {
3
3
  baseHeaders: Record<string, string>;
4
4
  constructor({ apiKey, dispatcher, }: MindeeApiConstructorProps);
5
5
  protected apiKeyFromEnv(): string;
@@ -4,7 +4,7 @@ import { MindeeConfigurationError } from "../../errors/index.js";
4
4
  const API_V2_KEY_ENVVAR_NAME = "MINDEE_V2_API_KEY";
5
5
  const API_V2_HOST_ENVVAR_NAME = "MINDEE_V2_API_HOST";
6
6
  const DEFAULT_MINDEE_API_HOST = "api-v2.mindee.net";
7
- export class ApiSettingsV2 extends BaseSettings {
7
+ export class ApiSettings extends BaseSettings {
8
8
  constructor({ apiKey, dispatcher, }) {
9
9
  super(apiKey, dispatcher);
10
10
  if (!this.apiKey || this.apiKey.length === 0) {
@@ -16,6 +16,7 @@ export class ApiSettingsV2 extends BaseSettings {
16
16
  "User-Agent": this.getUserAgent(),
17
17
  Authorization: `${this.apiKey}`,
18
18
  };
19
+ /* eslint-enable @typescript-eslint/naming-convention */
19
20
  }
20
21
  apiKeyFromEnv() {
21
22
  const envVarValue = process.env[API_V2_KEY_ENVVAR_NAME];
@@ -1,5 +1,8 @@
1
1
  import { ErrorDetails, ErrorItem, ErrorResponse } from "../../v2/parsing/index.js";
2
2
  import { MindeeError } from "../../errors/index.js";
3
+ /**
4
+ * HTTP error returned by the API.
5
+ */
3
6
  export declare class MindeeHttpErrorV2 extends MindeeError implements ErrorDetails {
4
7
  status: number;
5
8
  detail: string;
@@ -1,4 +1,7 @@
1
1
  import { MindeeError } from "../../errors/index.js";
2
+ /**
3
+ * HTTP error returned by the API.
4
+ */
2
5
  export class MindeeHttpErrorV2 extends MindeeError {
3
6
  constructor(error) {
4
7
  super(`HTTP ${error.status} - ${error.title} :: ${error.code} - ${error.detail}`);
@@ -1,4 +1,4 @@
1
- import { ApiSettingsV2 } from "./apiSettingsV2.js";
1
+ import { ApiSettings } from "./apiSettings.js";
2
2
  import { Dispatcher } from "undici";
3
3
  import { BaseParameters } from "../../v2/client/index.js";
4
4
  import { JobResponse } from "../../v2/parsing/index.js";
@@ -6,7 +6,7 @@ import { InputSource } from "../../input/index.js";
6
6
  import { BaseProduct } from "../../v2/product/baseProduct.js";
7
7
  export declare class MindeeApiV2 {
8
8
  #private;
9
- settings: ApiSettingsV2;
9
+ settings: ApiSettings;
10
10
  constructor(dispatcher?: Dispatcher, apiKey?: string);
11
11
  /**
12
12
  * Sends a file to the extraction inference queue.
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _MindeeApiV2_instances, _MindeeApiV2_processResponse, _MindeeApiV2_reqPostProductEnqueue, _MindeeApiV2_reqGetJob, _MindeeApiV2_reqGetProductResult;
7
- import { ApiSettingsV2 } from "./apiSettingsV2.js";
7
+ import { ApiSettings } from "./apiSettings.js";
8
8
  import { ErrorResponse, JobResponse, } from "../../v2/parsing/index.js";
9
9
  import { sendRequestAndReadResponse } from "../../http/apiCore.js";
10
10
  import { LocalInputSource } from "../../input/index.js";
@@ -14,7 +14,7 @@ import { logger } from "../../logger.js";
14
14
  export class MindeeApiV2 {
15
15
  constructor(dispatcher, apiKey) {
16
16
  _MindeeApiV2_instances.add(this);
17
- this.settings = new ApiSettingsV2({ dispatcher: dispatcher, apiKey: apiKey });
17
+ this.settings = new ApiSettings({ dispatcher: dispatcher, apiKey: apiKey });
18
18
  }
19
19
  /**
20
20
  * Sends a file to the extraction inference queue.
@@ -58,7 +58,8 @@ export class MindeeApiV2 {
58
58
  }
59
59
  }
60
60
  _MindeeApiV2_instances = new WeakSet(), _MindeeApiV2_processResponse = function _MindeeApiV2_processResponse(result, responseClass) {
61
- if (result.messageObj?.statusCode && (result.messageObj?.statusCode > 399 || result.messageObj?.statusCode < 200)) {
61
+ if (result.messageObj?.statusCode
62
+ && (result.messageObj?.statusCode > 399 || result.messageObj?.statusCode < 200)) {
62
63
  if (result.data?.status !== null) {
63
64
  throw new MindeeHttpErrorV2(new ErrorResponse(result.data));
64
65
  }
@@ -99,7 +100,7 @@ async function _MindeeApiV2_reqPostProductEnqueue(product, inputSource, params)
99
100
  hostname: this.settings.hostname,
100
101
  path: path,
101
102
  body: form,
102
- timeout: this.settings.timeout,
103
+ timeoutSecs: this.settings.timeoutSecs,
103
104
  };
104
105
  return await sendRequestAndReadResponse(this.settings.dispatcher, options);
105
106
  }, _MindeeApiV2_reqGetJob = async function _MindeeApiV2_reqGetJob(jobId) {
@@ -108,7 +109,7 @@ async function _MindeeApiV2_reqPostProductEnqueue(product, inputSource, params)
108
109
  headers: this.settings.baseHeaders,
109
110
  hostname: this.settings.hostname,
110
111
  path: `/v2/jobs/${jobId}`,
111
- timeout: this.settings.timeout,
112
+ timeoutSecs: this.settings.timeoutSecs,
112
113
  };
113
114
  return await sendRequestAndReadResponse(this.settings.dispatcher, options);
114
115
  }, _MindeeApiV2_reqGetProductResult =
@@ -125,7 +126,7 @@ async function _MindeeApiV2_reqGetProductResult(inferenceId, slug) {
125
126
  headers: this.settings.baseHeaders,
126
127
  hostname: this.settings.hostname,
127
128
  path: `/v2/products/${slug}/results/${inferenceId}`,
128
- timeout: this.settings.timeout,
129
+ timeoutSecs: this.settings.timeoutSecs,
129
130
  };
130
131
  return await sendRequestAndReadResponse(this.settings.dispatcher, options);
131
132
  };
package/src/v2/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export * as parsing from "./parsing/index.js";
3
3
  export * as product from "./product/index.js";
4
4
  export { Client } from "./client.js";
5
5
  export { JobResponse, ErrorResponse, LocalResponse, } from "./parsing/index.js";
6
- export type { PollingOptions, BaseParameters } from "./client/index.js";
6
+ export type { BaseParameters, TimerOptions } from "./client/index.js";
7
+ export { PollingOptions } from "./client/index.js";
package/src/v2/index.js CHANGED
@@ -3,3 +3,4 @@ export * as parsing from "./parsing/index.js";
3
3
  export * as product from "./product/index.js";
4
4
  export { Client } from "./client.js";
5
5
  export { JobResponse, ErrorResponse, LocalResponse, } from "./parsing/index.js";
6
+ export { PollingOptions } from "./client/index.js";
@@ -1,11 +1,16 @@
1
+ import { StringDict } from "../../../parsing/index.js";
1
2
  import { InferenceModel } from "./inferenceModel.js";
2
3
  import { InferenceFile } from "./inferenceFile.js";
3
- import { StringDict } from "../../../parsing/index.js";
4
+ import { InferenceJob } from "./inferenceJob.js";
4
5
  export declare abstract class BaseInference {
5
6
  /**
6
7
  * Model info for the inference.
7
8
  */
8
9
  model: InferenceModel;
10
+ /**
11
+ * Job the inference belongs to.
12
+ */
13
+ job: InferenceJob;
9
14
  /**
10
15
  * File info for the inference.
11
16
  */
@@ -1,14 +1,17 @@
1
1
  import { InferenceModel } from "./inferenceModel.js";
2
2
  import { InferenceFile } from "./inferenceFile.js";
3
+ import { InferenceJob } from "./inferenceJob.js";
3
4
  export class BaseInference {
4
5
  constructor(serverResponse) {
5
6
  this.id = serverResponse["id"];
7
+ this.job = new InferenceJob(serverResponse["job"]);
6
8
  this.model = new InferenceModel(serverResponse["model"]);
7
9
  this.file = new InferenceFile(serverResponse["file"]);
8
10
  }
9
11
  toString() {
10
12
  return ("Inference\n" +
11
13
  "#########\n" +
14
+ this.job.toString() + "\n" +
12
15
  this.model.toString() + "\n" +
13
16
  this.file.toString() + "\n");
14
17
  }
@@ -0,0 +1,9 @@
1
+ import { StringDict } from "../../../parsing/stringDict.js";
2
+ export declare class InferenceJob {
3
+ /**
4
+ * UUID of the Job.
5
+ */
6
+ id: string;
7
+ constructor(serverResponse: StringDict);
8
+ toString(): string;
9
+ }
@@ -0,0 +1,10 @@
1
+ export class InferenceJob {
2
+ constructor(serverResponse) {
3
+ this.id = serverResponse["id"];
4
+ }
5
+ toString() {
6
+ return ("Job\n" +
7
+ "===\n" +
8
+ `:ID: ${this.id}\n`);
9
+ }
10
+ }
@@ -1,5 +1,10 @@
1
1
  import { BaseParameters } from "../../v2/client/index.js";
2
2
  import { ResponseConstructor } from "../../v2/parsing/index.js";
3
+ /**
4
+ * Base class for all V2 product definitions.
5
+ *
6
+ * Child classes are passed to the Client when making requests.
7
+ */
3
8
  export declare abstract class BaseProduct {
4
9
  static get parametersClass(): new (...args: any[]) => BaseParameters;
5
10
  static get responseClass(): ResponseConstructor<any>;
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Base class for all V2 product definitions.
3
+ *
4
+ * Child classes are passed to the Client when making requests.
5
+ */
1
6
  export class BaseProduct {
2
7
  static get parametersClass() {
3
8
  throw new Error("Must define static parameters property");
@@ -1,6 +1,9 @@
1
1
  import { ClassificationResponse } from "./classificationResponse.js";
2
2
  import { ClassificationParameters } from "./params/index.js";
3
3
  import { BaseProduct } from "../../../v2/product/baseProduct.js";
4
+ /**
5
+ * Automatically sort any image or scanned document into categories.
6
+ */
4
7
  export declare class Classification extends BaseProduct {
5
8
  static get parametersClass(): typeof ClassificationParameters;
6
9
  static get responseClass(): typeof ClassificationResponse;
@@ -1,6 +1,9 @@
1
1
  import { ClassificationResponse } from "./classificationResponse.js";
2
2
  import { ClassificationParameters } from "./params/index.js";
3
3
  import { BaseProduct } from "../../../v2/product/baseProduct.js";
4
+ /**
5
+ * Automatically sort any image or scanned document into categories.
6
+ */
4
7
  export class Classification extends BaseProduct {
5
8
  static get parametersClass() {
6
9
  return ClassificationParameters;
@@ -1,6 +1,9 @@
1
1
  import { CropResponse } from "./cropResponse.js";
2
2
  import { CropParameters } from "./params/index.js";
3
3
  import { BaseProduct } from "../../../v2/product/baseProduct.js";
4
+ /**
5
+ * Identify the borders of documents on each page, matching each one to a category.
6
+ */
4
7
  export declare class Crop extends BaseProduct {
5
8
  static get parametersClass(): typeof CropParameters;
6
9
  static get responseClass(): typeof CropResponse;
@@ -1,6 +1,9 @@
1
1
  import { CropResponse } from "./cropResponse.js";
2
2
  import { CropParameters } from "./params/index.js";
3
3
  import { BaseProduct } from "../../../v2/product/baseProduct.js";
4
+ /**
5
+ * Identify the borders of documents on each page, matching each one to a category.
6
+ */
4
7
  export class Crop extends BaseProduct {
5
8
  static get parametersClass() {
6
9
  return CropParameters;
@@ -1,6 +1,9 @@
1
1
  import { ExtractionResponse } from "./extractionResponse.js";
2
2
  import { ExtractionParameters } from "./params/index.js";
3
3
  import { BaseProduct } from "../../../v2/product/baseProduct.js";
4
+ /**
5
+ * Automatically extract structured data from any image or scanned document.
6
+ */
4
7
  export declare class Extraction extends BaseProduct {
5
8
  static get parametersClass(): typeof ExtractionParameters;
6
9
  static get responseClass(): typeof ExtractionResponse;
@@ -1,6 +1,9 @@
1
1
  import { ExtractionResponse } from "./extractionResponse.js";
2
2
  import { ExtractionParameters } from "./params/index.js";
3
3
  import { BaseProduct } from "../../../v2/product/baseProduct.js";
4
+ /**
5
+ * Automatically extract structured data from any image or scanned document.
6
+ */
4
7
  export class Extraction extends BaseProduct {
5
8
  static get parametersClass() {
6
9
  return ExtractionParameters;
@@ -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";
@@ -1,6 +1,9 @@
1
1
  import { OcrResponse } from "./ocrResponse.js";
2
2
  import { OcrParameters } from "./params/index.js";
3
3
  import { BaseProduct } from "../../../v2/product/baseProduct.js";
4
+ /**
5
+ * Extract raw text (OCR) from any image or scanned document.
6
+ */
4
7
  export declare class Ocr extends BaseProduct {
5
8
  static get parametersClass(): typeof OcrParameters;
6
9
  static get responseClass(): typeof OcrResponse;
@@ -1,6 +1,9 @@
1
1
  import { OcrResponse } from "./ocrResponse.js";
2
2
  import { OcrParameters } from "./params/index.js";
3
3
  import { BaseProduct } from "../../../v2/product/baseProduct.js";
4
+ /**
5
+ * Extract raw text (OCR) from any image or scanned document.
6
+ */
4
7
  export class Ocr extends BaseProduct {
5
8
  static get parametersClass() {
6
9
  return OcrParameters;
@@ -1,6 +1,9 @@
1
1
  import { SplitResponse } from "./splitResponse.js";
2
2
  import { SplitParameters } from "./params/index.js";
3
3
  import { BaseProduct } from "../../../v2/product/baseProduct.js";
4
+ /**
5
+ * Break a multipage source file into separate documents, associating a class for each one.
6
+ */
4
7
  export declare class Split extends BaseProduct {
5
8
  static get parametersClass(): typeof SplitParameters;
6
9
  static get responseClass(): typeof SplitResponse;
@@ -1,6 +1,9 @@
1
1
  import { SplitResponse } from "./splitResponse.js";
2
2
  import { SplitParameters } from "./params/index.js";
3
3
  import { BaseProduct } from "../../../v2/product/baseProduct.js";
4
+ /**
5
+ * Break a multipage source file into separate documents, associating a class for each one.
6
+ */
4
7
  export class Split extends BaseProduct {
5
8
  static get parametersClass() {
6
9
  return SplitParameters;