diff --git a/CHANGELOG.md b/CHANGELOG.md index 7afa95949..a22ffa988 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,19 +1,19 @@ # CHANGELOG -## 5.0.0-rc2 - 2026-01-18 +## v5.0.0-rc2 - 2026-01-18 ### Changes * :sparkles: add Job to inference responses ### Fixes * :bug: fix for bin scripts -## 5.0.0-rc1 - 2026-01-17 +## v5.0.0-rc1 - 2026-01-17 ### Changes * :boom: drop support for node.js 18 * :boom: :recycle: separate polling options -## 5.0.0-alpha2 - 2026-01-16 +## v5.0.0-alpha2 - 2026-01-16 ### Changes * :recycle: use node test methods * :recycle: v1 ocr word should be a class @@ -21,7 +21,7 @@ * :bug: fix for optional node-poppler -## 5.0.0-alpha1 - 2026-01-13 +## v5.0.0-alpha1 - 2026-01-13 ### :boom: :recycle: base for v5 * :arrow_up: update file-type * :recycle: migrate to ES modules (node18) diff --git a/package-lock.json b/package-lock.json index 804d68a34..e59728518 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,8 @@ "version": "5.0.0-rc2", "license": "MIT", "dependencies": { - "commander": "~9.4.1", - "file-type": "^19.6.0", + "commander": "^14.0.3", + "file-type": "^21.3.0", "tmp": "^0.2.3", "tslib": "^2.8.1", "undici": "^6.23.0" @@ -34,11 +34,11 @@ "typescript": "^5.9.3" }, "engines": { - "node": ">= 20.1" + "node": ">= 20.9" }, "optionalDependencies": { - "@cantoo/pdf-lib": "^2.3.2", - "node-poppler": "^7.2.4", + "@cantoo/pdf-lib": "^2.5.3", + "node-poppler": "^9.1.1", "pdf.js-extract": "^0.2.1", "sharp": "~0.34.5" } @@ -1356,12 +1356,6 @@ "node": ">=14" } }, - "node_modules/@sec-ant/readable-stream": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@sec-ant/readable-stream/-/readable-stream-0.4.1.tgz", - "integrity": "sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==", - "license": "MIT" - }, "node_modules/@shikijs/engine-oniguruma": { "version": "3.22.0", "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-3.22.0.tgz", @@ -1424,6 +1418,23 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@tokenizer/inflate": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@tokenizer/inflate/-/inflate-0.4.1.tgz", + "integrity": "sha512-2mAv+8pkG6GIZiF1kNg1jAjh27IDxEPKwdGul3snfztFerfPGI1LjDezZp3i7BElXompqEtPmoPx6c2wgtWsOA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "token-types": "^6.1.1" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Borewit" + } + }, "node_modules/@tokenizer/token": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.3.0.tgz", @@ -2071,12 +2082,12 @@ } }, "node_modules/commander": { - "version": "9.4.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-9.4.1.tgz", - "integrity": "sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw==", + "version": "14.0.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-14.0.3.tgz", + "integrity": "sha512-H+y0Jo/T1RZ9qPP4Eh1pkcQcLRglraJaSLoyOtHxu6AapkjWVCy2Sit1QQ4x3Dng8qDlSsZEet7g5Pq06MvTgw==", "license": "MIT", "engines": { - "node": "^12.20.0 || >=14" + "node": ">=20" } }, "node_modules/comment-parser": { @@ -2122,7 +2133,6 @@ "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", - "dev": true, "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -2655,18 +2665,18 @@ } }, "node_modules/file-type": { - "version": "19.6.0", - "resolved": "https://registry.npmjs.org/file-type/-/file-type-19.6.0.tgz", - "integrity": "sha512-VZR5I7k5wkD0HgFnMsq5hOsSc710MJMu5Nc5QYsbe38NN5iPV/XTObYLc/cpttRTf6lX538+5uO1ZQRhYibiZQ==", + "version": "21.3.0", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-21.3.0.tgz", + "integrity": "sha512-8kPJMIGz1Yt/aPEwOsrR97ZyZaD1Iqm8PClb1nYFclUCkBi0Ma5IsYNQzvSFS9ib51lWyIw5mIT9rWzI/xjpzA==", "license": "MIT", "dependencies": { - "get-stream": "^9.0.1", - "strtok3": "^9.0.1", - "token-types": "^6.0.0", - "uint8array-extras": "^1.3.0" + "@tokenizer/inflate": "^0.4.1", + "strtok3": "^10.3.4", + "token-types": "^6.1.1", + "uint8array-extras": "^1.4.0" }, "engines": { - "node": ">=18" + "node": ">=20" }, "funding": { "url": "https://github.com/sindresorhus/file-type?sponsor=1" @@ -2775,22 +2785,6 @@ "node": "6.* || 8.* || >= 10.*" } }, - "node_modules/get-stream": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-9.0.1.tgz", - "integrity": "sha512-kVCxPF3vQM/N0B1PmoqVUqgHP+EeVjmZSQn+1oCRPxd2P21P2F19lIgbR3HBosbB1PUhOAoctJnfEn2GbN2eZA==", - "license": "MIT", - "dependencies": { - "@sec-ant/readable-stream": "^0.4.1", - "is-stream": "^4.0.1" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/get-tsconfig": { "version": "4.13.6", "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.13.6.tgz", @@ -2920,6 +2914,19 @@ ], "license": "MIT" }, + "node_modules/ice-barrage": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ice-barrage/-/ice-barrage-1.0.0.tgz", + "integrity": "sha512-xdp/aktysCDxBasbht01dMC2oSgmM4PrQITSCFdBjsxop4ZO1FwNIEEb+wGNSCUp/+8mz/lnkLR2pc4F9ubgIw==", + "license": "MIT", + "optional": true, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/Fdawgs" + } + }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -3060,18 +3067,6 @@ "node": ">=8" } }, - "node_modules/is-stream": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-4.0.1.tgz", - "integrity": "sha512-Dnz92NInDqYckGEUJv689RbRiTSEHCQ7wOVeALbkOz999YpqT46yMRIGtSNl2iCL1waAZSx40+h59NV/EwzV/A==", - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/is-unicode-supported": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", @@ -3385,7 +3380,6 @@ "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true, "license": "MIT" }, "node_modules/mylas": { @@ -3420,17 +3414,40 @@ } }, "node_modules/node-poppler": { - "version": "7.2.4", - "resolved": "https://registry.npmjs.org/node-poppler/-/node-poppler-7.2.4.tgz", - "integrity": "sha512-+YvPbEQ2uxsUVBXDIZiUEu0C3wMOo37D+cIqzWu5gZra3p6MHhBFJtZ/2slzj+5QPmWcHd9SAEjXk2ogBSHg9Q==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/node-poppler/-/node-poppler-9.1.1.tgz", + "integrity": "sha512-uT/WxcJjwsDElPJoZ9HftRpGg6V1QjAsKpTDZHpJbl53EkaemzuNBisxsFMc5h98eZETMqpsziZCczcNkCCa7Q==", "license": "MIT", "optional": true, "dependencies": { "camelcase": "^6.3.0", - "semver": "^7.6.3" + "ice-barrage": "^1.0.0", + "semver": "^7.7.2" }, "engines": { - "node": ">=18" + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/Fdawgs" + }, + "optionalDependencies": { + "node-poppler-win32": "^1.0.1" + } + }, + "node_modules/node-poppler-win32": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/node-poppler-win32/-/node-poppler-win32-1.0.2.tgz", + "integrity": "sha512-U2YVdM7EEXNE21TD4ajJxfd1pKx7yEF2tcuHc4eCa7uxmw+mfSNPB+yHRtNrdxJqV6dKoz4Rvhuyy5rn6mg3ZA==", + "cpu": [ + "x64" + ], + "license": "GPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=20" }, "funding": { "url": "https://github.com/sponsors/Fdawgs" @@ -3608,19 +3625,6 @@ "node": ">=12.0.0" } }, - "node_modules/peek-readable": { - "version": "5.4.2", - "resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-5.4.2.tgz", - "integrity": "sha512-peBp3qZyuS6cNIJ2akRNG1uo1WJ1d0wTxg/fxMdZ0BqCVhx242bSFHM9eNqflfJVS9SsgkzgT/1UgnsurBOTMg==", - "license": "MIT", - "engines": { - "node": ">=14.16" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Borewit" - } - }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -4105,16 +4109,15 @@ } }, "node_modules/strtok3": { - "version": "9.1.1", - "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-9.1.1.tgz", - "integrity": "sha512-FhwotcEqjr241ZbjFzjlIYg6c5/L/s4yBGWSMvJ9UoExiSqL+FnFA/CaeZx17WGaZMS/4SOZp8wH18jSS4R4lw==", + "version": "10.3.4", + "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-10.3.4.tgz", + "integrity": "sha512-KIy5nylvC5le1OdaaoCJ07L+8iQzJHGH6pWDuzS+d07Cu7n1MZ2x26P8ZKIWfbK02+XIL8Mp4RkWeqdUCrDMfg==", "license": "MIT", "dependencies": { - "@tokenizer/token": "^0.3.0", - "peek-readable": "^5.3.1" + "@tokenizer/token": "^0.3.0" }, "engines": { - "node": ">=16" + "node": ">=18" }, "funding": { "type": "github", @@ -4268,6 +4271,16 @@ "fsevents": "~2.3.2" } }, + "node_modules/tsc-alias/node_modules/commander": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || >=14" + } + }, "node_modules/tsc-alias/node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", diff --git a/package.json b/package.json index 98b5f500a..7888ee7ed 100644 --- a/package.json +++ b/package.json @@ -47,16 +47,16 @@ "node": ">= 20.1" }, "dependencies": { - "commander": "~9.4.1", - "file-type": "^19.6.0", + "commander": "^14.0.3", + "file-type": "^21.3.0", "tmp": "^0.2.3", "tslib": "^2.8.1", - "undici": "^6.23.0" + "undici": ">=6.23.0 <8.0.0" }, "optionalDependencies": { - "@cantoo/pdf-lib": "^2.3.2", - "node-poppler": "^7.2.4", - "pdf.js-extract": "^0.2.1", + "@cantoo/pdf-lib": "^2.5.3", + "node-poppler": "^9.1.1", + "pdf.js-extract": "~0.2.1", "sharp": "~0.34.5" }, "devDependencies": { diff --git a/src/http/apiCore.ts b/src/http/apiCore.ts index 98819997e..9b0057c6a 100644 --- a/src/http/apiCore.ts +++ b/src/http/apiCore.ts @@ -1,16 +1,16 @@ import { logger } from "@/logger.js"; -import { request, Dispatcher } from "undici"; +import { request, Dispatcher, FormData } from "undici"; import { InputSource, PageOptions, LocalInputSource } from "@/input/index.js"; -export const TIMEOUT_DEFAULT: number = 120; +export const TIMEOUT_SECS_DEFAULT: number = 120; export interface RequestOptions { hostname: string; path: string; method: any; - timeout: number; + timeoutSecs: number; headers: any; - body?: any; + body?: FormData | string; } export interface BaseHttpResponse { @@ -40,17 +40,16 @@ export async function sendRequestAndReadResponse( options: RequestOptions, ): Promise { const url: string = `https://${options.hostname}${options.path}`; - logger.debug(`${options.method}: ${url}`); + logger.debug(`${options.method}: ${url}`); const response = await request( url, { method: options.method, headers: options.headers, - bodyTimeout: options.timeout, + headersTimeout: options.timeoutSecs * 1000, body: options.body, - throwOnError: false, - dispatcher: dispatcher + dispatcher: dispatcher, } ); logger.debug("Parsing the response ..."); diff --git a/src/http/baseSettings.ts b/src/http/baseSettings.ts index ba275b36b..5a9224350 100644 --- a/src/http/baseSettings.ts +++ b/src/http/baseSettings.ts @@ -1,7 +1,7 @@ import { Dispatcher, getGlobalDispatcher } from "undici"; import packageJson from "../../package.json" with { type: "json" }; import * as os from "os"; -import { TIMEOUT_DEFAULT } from "./apiCore.js"; +import { TIMEOUT_SECS_DEFAULT } from "./apiCore.js"; export interface MindeeApiConstructorProps { apiKey?: string; @@ -11,7 +11,7 @@ export interface MindeeApiConstructorProps { export abstract class BaseSettings { apiKey: string; hostname: string; - timeout: number; + timeoutSecs: number; dispatcher: Dispatcher; protected constructor(apiKey?: string, dispatcher?: Dispatcher) { @@ -22,7 +22,9 @@ export abstract class BaseSettings { } this.dispatcher = dispatcher ?? getGlobalDispatcher(); this.hostname = this.hostnameFromEnv(); - this.timeout = process.env.MINDEE_REQUEST_TIMEOUT ? parseInt(process.env.MINDEE_REQUEST_TIMEOUT) : TIMEOUT_DEFAULT; + this.timeoutSecs = process.env.MINDEE_REQUEST_TIMEOUT + ? parseInt(process.env.MINDEE_REQUEST_TIMEOUT) + : TIMEOUT_SECS_DEFAULT; } protected getUserAgent(): string { diff --git a/src/v1/http/endpoint.ts b/src/v1/http/endpoint.ts index d74cf2ca9..79fa0910a 100644 --- a/src/v1/http/endpoint.ts +++ b/src/v1/http/endpoint.ts @@ -1,7 +1,13 @@ import { URLSearchParams } from "url"; +import { FormData } from "undici"; import { InputSource, LocalInputSource } from "@/input/index.js"; import { StringDict } from "@/parsing/stringDict.js"; -import { cutDocPages, sendRequestAndReadResponse, BaseHttpResponse } from "@/http/apiCore.js"; +import { + cutDocPages, + sendRequestAndReadResponse, + BaseHttpResponse, + RequestOptions, +} from "@/http/apiCore.js"; import { ApiSettingsV1 } from "./apiSettingsV1.js"; import { handleError } from "./errors.js"; import { PredictParams } from "./httpParams.js"; @@ -208,12 +214,12 @@ export class Endpoint { path += `?${searchParams}`; } - const options = { + const options: RequestOptions = { method: "POST", headers: this.settings.baseHeaders, hostname: this.settings.hostname, path: path, - timeout: this.settings.timeout, + timeoutSecs: this.settings.timeoutSecs, body: form, }; return await sendRequestAndReadResponse(this.settings.dispatcher, options); @@ -268,12 +274,12 @@ export class Endpoint { * @param queueId */ async #documentQueueReqGet(queueId: string): Promise { - const options = { + const options: RequestOptions = { method: "GET", headers: this.settings.baseHeaders, hostname: this.settings.hostname, path: `${this.urlRoot}/documents/queue/${queueId}`, - timeout: this.settings.timeout, + timeoutSecs: this.settings.timeoutSecs, }; return await sendRequestAndReadResponse(this.settings.dispatcher, options); } @@ -283,12 +289,12 @@ export class Endpoint { * @param documentId */ async #documentGetReq(documentId: string): Promise { - const options = { + const options: RequestOptions = { method: "GET", headers: this.settings.baseHeaders, hostname: this.settings.hostname, path: `${this.urlRoot}/documents/${documentId}`, - timeout: this.settings.timeout, + timeoutSecs: this.settings.timeoutSecs, }; return await sendRequestAndReadResponse(this.settings.dispatcher, options); } @@ -299,13 +305,13 @@ export class Endpoint { * @param feedback */ async #documentFeedbackPutReq(documentId: string, feedback: StringDict): Promise { - const options = { + const options: RequestOptions = { method: "PUT", headers: this.settings.baseHeaders, hostname: this.settings.hostname, path: `/v1/documents/${documentId}/feedback`, body: JSON.stringify(feedback), - timeout: this.settings.timeout, + timeoutSecs: this.settings.timeoutSecs, }; return await sendRequestAndReadResponse(this.settings.dispatcher, options); } diff --git a/src/v1/http/workflowEndpoint.ts b/src/v1/http/workflowEndpoint.ts index 7a4b5959f..6a32daee5 100644 --- a/src/v1/http/workflowEndpoint.ts +++ b/src/v1/http/workflowEndpoint.ts @@ -1,7 +1,13 @@ import { URLSearchParams } from "url"; +import { FormData } from "undici"; import { InputSource, LocalInputSource } from "@/input/index.js"; import { ExecutionPriority } from "@/v1/parsing/common/index.js"; -import { cutDocPages, sendRequestAndReadResponse, BaseHttpResponse } from "../../http/apiCore.js"; +import { + cutDocPages, + sendRequestAndReadResponse, + BaseHttpResponse, + RequestOptions, +} from "@/http/apiCore.js"; import { ApiSettingsV1 } from "./apiSettingsV1.js"; import { handleError } from "./errors.js"; import { WorkflowParams } from "./httpParams.js"; @@ -105,12 +111,12 @@ export class WorkflowEndpoint { path += `?${searchParams}`; } - const options = { + const options: RequestOptions = { method: "POST", headers: this.settings.baseHeaders, hostname: this.settings.hostname, path: path, - timeout: this.settings.timeout, + timeoutSecs: this.settings.timeoutSecs, body: form, }; return await sendRequestAndReadResponse(this.settings.dispatcher, options); diff --git a/src/v2/cli.ts b/src/v2/cli.ts index fc7fa8fd1..22e69f8c6 100644 --- a/src/v2/cli.ts +++ b/src/v2/cli.ts @@ -12,6 +12,12 @@ import { Split, } from "@/v2/product/index.js"; +interface CliProduct { + name: string; + description: string; + productClass: typeof BaseProduct; +} + const program = new Command(); // @@ -35,13 +41,11 @@ async function enqueueAndGetInference( const response = await mindeeClient.enqueueAndGetResult( product, inputSource, + { modelId: options.model }, { - modelId: options.model, - pollingOptions: { - initialDelaySec: 2, - delaySec: 1.5, - maxRetries: 80, - } + initialDelaySec: 2, + delaySec: 1.5, + maxRetries: 80, } ); if (!response.inference) { @@ -76,12 +80,12 @@ export function cli() { .option("-d, --debug", "high verbosity mode") .option("-k, --api-key ", "your Mindee API key"); - const inferenceTypes = [ - { name: "extraction", description: "Extract data from a document.", product: Extraction }, - { name: "crop", description: "Crop a document.", product: Crop }, - { name: "split", description: "Split a document into pages.", product: Split }, - { name: "ocr", description: "Read text from a document.", product: Ocr }, - { name: "classification", description: "Classify a document.", product: Classification }, + const inferenceTypes: CliProduct[] = [ + { name: "extraction", description: "Extract data from a document.", productClass: Extraction }, + { name: "crop", description: "Crop a document.", productClass: Crop }, + { name: "split", description: "Split a document into pages.", productClass: Split }, + { name: "ocr", description: "Read text from a document.", productClass: Ocr }, + { name: "classification", description: "Classify a document.", productClass: Classification }, ]; for (const inference of inferenceTypes) { @@ -95,7 +99,7 @@ export function cli() { options: OptionValues, ) { const allOptions = { ...program.opts(), ...options }; - return enqueueAndGetInference(inference.product, inputPath, allOptions); + return enqueueAndGetInference(inference.productClass, inputPath, allOptions); }); } diff --git a/src/v2/client/baseParameters.ts b/src/v2/client/baseParameters.ts index 5d75a8f01..b4c9952df 100644 --- a/src/v2/client/baseParameters.ts +++ b/src/v2/client/baseParameters.ts @@ -1,3 +1,4 @@ +import { FormData } from "undici"; import { MindeeConfigurationError } from "@/errors/index.js"; /** diff --git a/src/v2/http/mindeeApiV2.ts b/src/v2/http/mindeeApiV2.ts index db75a16b7..aeb35df7c 100644 --- a/src/v2/http/mindeeApiV2.ts +++ b/src/v2/http/mindeeApiV2.ts @@ -7,7 +7,11 @@ import { ResponseConstructor, JobResponse, } from "@/v2/parsing/index.js"; -import { sendRequestAndReadResponse, BaseHttpResponse } from "@/http/apiCore.js"; +import { + sendRequestAndReadResponse, + BaseHttpResponse, + RequestOptions +} from "@/http/apiCore.js"; import { InputSource, LocalInputSource, UrlInput } from "@/input/index.js"; import { MindeeDeserializationError } from "@/errors/index.js"; import { MindeeHttpErrorV2 } from "./errors.js"; @@ -127,24 +131,24 @@ export class MindeeApiV2 { form.set("url", (inputSource as UrlInput).url); } const path = `/v2/products/${product.slug}/enqueue`; - const options = { + const options: RequestOptions = { method: "POST", headers: this.settings.baseHeaders, hostname: this.settings.hostname, path: path, body: form, - timeout: this.settings.timeout, + timeoutSecs: this.settings.timeoutSecs, }; return await sendRequestAndReadResponse(this.settings.dispatcher, options); } async #reqGetJob(jobId: string): Promise { - const options = { + const options: RequestOptions = { method: "GET", headers: this.settings.baseHeaders, hostname: this.settings.hostname, path: `/v2/jobs/${jobId}`, - timeout: this.settings.timeout, + timeoutSecs: this.settings.timeoutSecs, }; return await sendRequestAndReadResponse(this.settings.dispatcher, options); } @@ -157,12 +161,12 @@ export class MindeeApiV2 { * @returns a `Promise` containing either the parsed result, or information on the queue. */ async #reqGetProductResult(inferenceId: string, slug: string): Promise { - const options = { + const options: RequestOptions = { method: "GET", headers: this.settings.baseHeaders, hostname: this.settings.hostname, path: `/v2/products/${slug}/results/${inferenceId}`, - timeout: this.settings.timeout, + timeoutSecs: this.settings.timeoutSecs, }; return await sendRequestAndReadResponse(this.settings.dispatcher, options); } diff --git a/src/v2/product/extraction/params/extractionParameters.ts b/src/v2/product/extraction/params/extractionParameters.ts index fe3b8f1c6..552791b50 100644 --- a/src/v2/product/extraction/params/extractionParameters.ts +++ b/src/v2/product/extraction/params/extractionParameters.ts @@ -1,3 +1,4 @@ +import { FormData } from "undici"; import { StringDict } from "@/parsing/stringDict.js"; import { DataSchema } from "./dataSchema.js"; import { BaseParameters, BaseParametersConstructor } from "@/v2/client/baseParameters.js"; diff --git a/tests/v1/api/endpoint.spec.ts b/tests/v1/api/endpoint.spec.ts index 666a66d34..88b73e3f2 100644 --- a/tests/v1/api/endpoint.spec.ts +++ b/tests/v1/api/endpoint.spec.ts @@ -118,7 +118,7 @@ describe ("Endpoint parameters" , () => { "dummy-account" ); assert.strictEqual(customEndpoint.version, "1"); - assert.strictEqual(customEndpoint.settings.timeout, 120); + assert.strictEqual(customEndpoint.settings.timeoutSecs, 120); assert.strictEqual(customEndpoint.settings.hostname, "api.mindee.net"); assert.strictEqual(customEndpoint.settings.apiKey, "dummy-api-key"); }); @@ -134,7 +134,7 @@ describe ("Endpoint parameters" , () => { "dummy-account" ); assert.strictEqual(customEndpoint.version, "1"); - assert.strictEqual(customEndpoint.settings.timeout, 30); + assert.strictEqual(customEndpoint.settings.timeoutSecs, 30); assert.strictEqual(customEndpoint.settings.hostname, "v1-endpoint-host"); assert.strictEqual(customEndpoint.settings.apiKey, "dummy-key");