mindee 5.6.1 → 5.7.1
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 +14 -0
- package/package.json +1 -3
- package/src/http/apiCore.d.ts +0 -7
- package/src/http/apiCore.js +0 -11
- package/src/http/baseSettings.js +2 -2
- package/src/http/dispatcher.d.ts +6 -0
- package/src/http/dispatcher.js +17 -0
- package/src/http/index.d.ts +1 -0
- package/src/http/index.js +1 -0
- package/src/input/urlInput.js +3 -2
- package/src/parsing/{localResponseBase.d.ts → baseLocalResponse.d.ts} +6 -2
- package/src/parsing/{localResponseBase.js → baseLocalResponse.js} +32 -7
- package/src/pdf/pdfCompressor.js +0 -17
- package/src/v1/http/baseEndpoint.d.ts +15 -0
- package/src/v1/http/baseEndpoint.js +17 -0
- package/src/v1/http/endpoint.d.ts +2 -5
- package/src/v1/http/endpoint.js +6 -6
- package/src/v1/http/workflowEndpoint.d.ts +2 -5
- package/src/v1/http/workflowEndpoint.js +5 -5
- package/src/v1/parsing/localResponse.d.ts +2 -2
- package/src/v1/parsing/localResponse.js +2 -2
- package/src/v2/client.d.ts +9 -0
- package/src/v2/client.js +18 -1
- package/src/v2/clientOptions/{baseParameters.d.ts → baseProductParameters.d.ts} +7 -19
- package/src/v2/clientOptions/baseProductParameters.js +30 -0
- package/src/v2/clientOptions/baseSearchParameters.d.ts +26 -0
- package/src/v2/clientOptions/baseSearchParameters.js +23 -0
- package/src/v2/clientOptions/index.d.ts +2 -1
- package/src/v2/clientOptions/index.js +2 -1
- package/src/v2/http/mindeeApiV2.d.ts +16 -15
- package/src/v2/http/mindeeApiV2.js +33 -32
- package/src/v2/index.d.ts +2 -1
- package/src/v2/index.js +1 -0
- package/src/v2/parsing/inference/field/listField.d.ts +1 -1
- package/src/v2/parsing/inference/field/listField.js +9 -9
- package/src/v2/parsing/inference/field/ragMetadata.d.ts +1 -1
- package/src/v2/parsing/inference/field/ragMetadata.js +1 -1
- package/src/v2/parsing/localResponse.d.ts +2 -2
- package/src/v2/parsing/localResponse.js +2 -2
- package/src/v2/parsing/search/baseSearchResponse.d.ts +19 -0
- package/src/v2/parsing/search/baseSearchResponse.js +17 -0
- package/src/v2/parsing/search/index.d.ts +2 -0
- package/src/v2/parsing/search/index.js +2 -0
- package/src/v2/parsing/search/modelWebhook.d.ts +1 -1
- package/src/v2/parsing/search/modelWebhook.js +1 -1
- package/src/v2/parsing/search/paginationMetadata.d.ts +1 -1
- package/src/v2/parsing/search/paginationMetadata.js +1 -1
- package/src/v2/parsing/search/searchModel.d.ts +2 -2
- package/src/v2/parsing/search/searchModel.js +1 -1
- package/src/v2/parsing/search/searchModels.d.ts +9 -0
- package/src/v2/parsing/search/searchModels.js +22 -0
- package/src/v2/parsing/search/searchRagDocument.d.ts +35 -0
- package/src/v2/parsing/search/searchRagDocument.js +16 -0
- package/src/v2/parsing/search/searchRagDocuments.d.ts +9 -0
- package/src/v2/parsing/search/searchRagDocuments.js +26 -0
- package/src/v2/parsing/search/searchResponse.d.ts +3 -13
- package/src/v2/parsing/search/searchResponse.js +3 -17
- package/src/v2/product/baseProduct.d.ts +5 -2
- package/src/v2/product/baseProduct.js +3 -0
- package/src/v2/product/classification/classification.d.ts +3 -3
- package/src/v2/product/classification/classification.js +3 -3
- package/src/v2/product/classification/params/classificationParameters.d.ts +4 -18
- package/src/v2/product/classification/params/classificationParameters.js +3 -17
- package/src/v2/product/crop/crop.d.ts +3 -3
- package/src/v2/product/crop/crop.js +3 -3
- package/src/v2/product/crop/params/cropParameters.d.ts +4 -18
- package/src/v2/product/crop/params/cropParameters.js +3 -17
- package/src/v2/product/extraction/extraction.d.ts +3 -3
- package/src/v2/product/extraction/extraction.js +3 -3
- package/src/v2/product/extraction/params/extractionParameters.d.ts +5 -21
- package/src/v2/product/extraction/params/extractionParameters.js +12 -32
- package/src/v2/product/ocr/ocr.d.ts +3 -3
- package/src/v2/product/ocr/ocr.js +3 -3
- package/src/v2/product/ocr/params/ocrParameters.d.ts +4 -18
- package/src/v2/product/ocr/params/ocrParameters.js +3 -17
- package/src/v2/product/split/params/splitParameters.d.ts +4 -18
- package/src/v2/product/split/params/splitParameters.js +3 -17
- package/src/v2/product/split/split.d.ts +3 -3
- package/src/v2/product/split/split.js +3 -3
- package/src/v2/search/baseSearch.d.ts +15 -0
- package/src/v2/search/baseSearch.js +19 -0
- package/src/v2/search/index.d.ts +6 -0
- package/src/v2/search/index.js +6 -0
- package/src/v2/search/models/index.d.ts +3 -0
- package/src/v2/search/models/index.js +3 -0
- package/src/v2/search/models/modelSearch.d.ts +19 -0
- package/src/v2/search/models/modelSearch.js +25 -0
- package/src/v2/search/models/modelSearchParameters.d.ts +24 -0
- package/src/v2/search/models/modelSearchParameters.js +22 -0
- package/src/v2/search/models/modelSearchResponse.d.ts +14 -0
- package/src/v2/search/models/modelSearchResponse.js +14 -0
- package/src/v2/search/ragDocuments/index.d.ts +3 -0
- package/src/v2/search/ragDocuments/index.js +3 -0
- package/src/v2/search/ragDocuments/ragDocumentSearch.d.ts +14 -0
- package/src/v2/search/ragDocuments/ragDocumentSearch.js +20 -0
- package/src/v2/search/ragDocuments/ragDocumentSearchParameters.d.ts +24 -0
- package/src/v2/search/ragDocuments/ragDocumentSearchParameters.js +24 -0
- package/src/v2/search/ragDocuments/ragDocumentSearchResponse.d.ts +14 -0
- package/src/v2/search/ragDocuments/ragDocumentSearchResponse.js +14 -0
- package/src/v2/clientOptions/baseParameters.js +0 -42
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Mindee Node.js API Library Changelog
|
|
2
2
|
|
|
3
|
+
## v5.7.1 - 2026-09-10
|
|
4
|
+
### Fixes
|
|
5
|
+
* :bug: constant-time HMAC security fix
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## v5.7.0 - 2026-08-20
|
|
9
|
+
### Changes
|
|
10
|
+
* :sparkles: add support for RAG search API
|
|
11
|
+
* :recycle: rework and mutualize a lot of http classes
|
|
12
|
+
|
|
13
|
+
### Fixes
|
|
14
|
+
* :bug: fix undici unexpectedly re-using request agents when not specified
|
|
15
|
+
|
|
16
|
+
|
|
3
17
|
## v5.6.1 - 2026-08-19
|
|
4
18
|
### Changes
|
|
5
19
|
* :arrow_up: security updates
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.1",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Mindee",
|
|
@@ -32,11 +32,9 @@
|
|
|
32
32
|
"test:integration:light": "node tests/runner.mjs integration",
|
|
33
33
|
"test:v2": "tsc --noEmit && node tests/runner.mjs spec v2",
|
|
34
34
|
"lint": "tsc --noEmit && eslint --report-unused-disable-directives './src/**/*.ts' './tests/**/*.ts'",
|
|
35
|
-
"lint:check": "npm run lint",
|
|
36
35
|
"lint:fix": "tsc --noEmit && eslint --fix --report-unused-disable-directives './src/**/*.ts' './tests/**/*.ts'",
|
|
37
36
|
"lint:package": "npm run build:dist && publint ./dist && attw --pack ./dist --profile esm-only",
|
|
38
37
|
"lint:secrets": "secretlint '**/*'",
|
|
39
|
-
"lint:full": "npm run lint:check && npm run lint:package && npm run lint:secrets",
|
|
40
38
|
"license:check": "license-checker-rseidelsohn --onlyAllow \"MIT;Apache-2.0;BSD-2-Clause;BSD-3-Clause;ISC;LGPL-3.0-or-later;Python-2.0;BlueOak-1.0.0;CC-BY-3.0;CC0-1.0;0BSD;LGPL-3.0-only;WTFPL;Artistic-2.0;Unlicense\"",
|
|
41
39
|
"docs": "typedoc --out docs/_build ./src/index.ts",
|
|
42
40
|
"docs:dist": "typedoc --out docs/_build ./src/index.ts && cp -r ./docs/code_samples ./docs/_build/",
|
package/src/http/apiCore.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Dispatcher, FormData } from "undici";
|
|
2
|
-
import { InputSource, PageOptions } from "../input/index.js";
|
|
3
2
|
export declare const TIMEOUT_SECS_DEFAULT: number;
|
|
4
3
|
export interface RequestOptions {
|
|
5
4
|
hostname?: string;
|
|
@@ -16,12 +15,6 @@ export interface BaseHttpResponse {
|
|
|
16
15
|
[key: string]: any;
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Cuts a document's pages according to the given options.
|
|
21
|
-
* @param inputDoc input document.
|
|
22
|
-
* @param pageOptions page cutting options.
|
|
23
|
-
*/
|
|
24
|
-
export declare function cutDocPages(inputDoc: InputSource, pageOptions: PageOptions): Promise<void>;
|
|
25
18
|
/**
|
|
26
19
|
* Reads a response from the API and processes it.
|
|
27
20
|
* @param dispatcher custom dispatcher to use for the request.
|
package/src/http/apiCore.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { logger } from "../logger.js";
|
|
2
2
|
import { request } from "undici";
|
|
3
|
-
import { LocalInputSource } from "../input/index.js";
|
|
4
3
|
export const TIMEOUT_SECS_DEFAULT = 120;
|
|
5
|
-
/**
|
|
6
|
-
* Cuts a document's pages according to the given options.
|
|
7
|
-
* @param inputDoc input document.
|
|
8
|
-
* @param pageOptions page cutting options.
|
|
9
|
-
*/
|
|
10
|
-
export async function cutDocPages(inputDoc, pageOptions) {
|
|
11
|
-
if (inputDoc instanceof LocalInputSource && inputDoc.isPdf()) {
|
|
12
|
-
await inputDoc.applyPageOptions(pageOptions);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
4
|
/**
|
|
16
5
|
* Reads a response from the API and processes it.
|
|
17
6
|
* @param dispatcher custom dispatcher to use for the request.
|
package/src/http/baseSettings.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getGlobalDispatcher } from "undici";
|
|
2
1
|
// eslint-disable-next-line no-restricted-imports
|
|
3
2
|
import packageJson from "../../package.json" with { type: "json" };
|
|
4
3
|
import * as os from "os";
|
|
5
4
|
import { TIMEOUT_SECS_DEFAULT } from "./apiCore.js";
|
|
5
|
+
import { resolveDefaultDispatcher } from "./dispatcher.js";
|
|
6
6
|
export class BaseSettings {
|
|
7
7
|
constructor(apiKey, dispatcher) {
|
|
8
8
|
if (apiKey === undefined || !apiKey || apiKey.length === 0) {
|
|
@@ -11,7 +11,7 @@ export class BaseSettings {
|
|
|
11
11
|
else {
|
|
12
12
|
this.apiKey = apiKey;
|
|
13
13
|
}
|
|
14
|
-
this.dispatcher = dispatcher ??
|
|
14
|
+
this.dispatcher = dispatcher ?? resolveDefaultDispatcher();
|
|
15
15
|
this.hostname = this.hostnameFromEnv();
|
|
16
16
|
this.timeoutSecs = process.env.MINDEE_REQUEST_TIMEOUT
|
|
17
17
|
? parseInt(process.env.MINDEE_REQUEST_TIMEOUT)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Agent, Dispatcher, getGlobalDispatcher } from "undici";
|
|
2
|
+
import { logger } from "../logger.js";
|
|
3
|
+
/** Library-owned fallback dispatcher, shared across all components. */
|
|
4
|
+
let fallbackDispatcher;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the global undici dispatcher, provided it was created by the same
|
|
7
|
+
* undici copy this library imports.
|
|
8
|
+
*/
|
|
9
|
+
export function resolveDefaultDispatcher() {
|
|
10
|
+
const globalDispatcher = getGlobalDispatcher();
|
|
11
|
+
if (globalDispatcher instanceof Dispatcher) {
|
|
12
|
+
return globalDispatcher;
|
|
13
|
+
}
|
|
14
|
+
logger.debug("Global dispatcher belongs to a different undici instance, using a library-owned Agent instead.");
|
|
15
|
+
fallbackDispatcher ?? (fallbackDispatcher = new Agent());
|
|
16
|
+
return fallbackDispatcher;
|
|
17
|
+
}
|
package/src/http/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export type { BaseHttpResponse } from "./apiCore.js";
|
|
2
2
|
export { isValidSyncResponse, isValidAsyncResponse, cleanRequestData, } from "../v1/http/responseValidation.js";
|
|
3
3
|
export { BaseSettings } from "./baseSettings.js";
|
|
4
|
+
export { resolveDefaultDispatcher } from "./dispatcher.js";
|
package/src/http/index.js
CHANGED
package/src/input/urlInput.js
CHANGED
|
@@ -3,16 +3,17 @@ import { URL } from "url";
|
|
|
3
3
|
import { basename, extname } from "path";
|
|
4
4
|
import { randomBytes } from "crypto";
|
|
5
5
|
import { writeFile } from "fs/promises";
|
|
6
|
-
import { request
|
|
6
|
+
import { request } from "undici";
|
|
7
7
|
import { logger } from "../logger.js";
|
|
8
8
|
import { MindeeInputSourceError } from "../errors/index.js";
|
|
9
|
+
import { resolveDefaultDispatcher } from "../http/dispatcher.js";
|
|
9
10
|
import { BytesInput } from "./bytesInput.js";
|
|
10
11
|
/** Remote input source represented by a validated HTTPS URL. */
|
|
11
12
|
export class UrlInput extends InputSource {
|
|
12
13
|
constructor({ url, dispatcher }) {
|
|
13
14
|
super();
|
|
14
15
|
this.url = url;
|
|
15
|
-
this.dispatcher = dispatcher ??
|
|
16
|
+
this.dispatcher = dispatcher ?? resolveDefaultDispatcher();
|
|
16
17
|
logger.debug("Initialized URL input source.");
|
|
17
18
|
}
|
|
18
19
|
/** Initializes this source by validating and storing the URL. */
|
|
@@ -4,8 +4,8 @@ import { Buffer } from "buffer";
|
|
|
4
4
|
* Local response loaded from a file.
|
|
5
5
|
* Note: Has to be initialized through init() before use.
|
|
6
6
|
*/
|
|
7
|
-
export declare abstract class
|
|
8
|
-
private
|
|
7
|
+
export declare abstract class BaseLocalResponse {
|
|
8
|
+
private fileBytes;
|
|
9
9
|
private readonly inputHandle;
|
|
10
10
|
/** Whether the local response payload has been loaded. */
|
|
11
11
|
protected initialized: boolean;
|
|
@@ -33,4 +33,8 @@ export declare abstract class LocalResponseBase {
|
|
|
33
33
|
* @returns True if the HMAC signature is valid.
|
|
34
34
|
*/
|
|
35
35
|
isValidHmacSignature(secretKey: string | Buffer | Uint8Array, signature: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Print the file as a UTF-8 string.
|
|
38
|
+
*/
|
|
39
|
+
toString(): string;
|
|
36
40
|
}
|
|
@@ -6,14 +6,20 @@ import { Buffer } from "buffer";
|
|
|
6
6
|
* Local response loaded from a file.
|
|
7
7
|
* Note: Has to be initialized through init() before use.
|
|
8
8
|
*/
|
|
9
|
-
export class
|
|
9
|
+
export class BaseLocalResponse {
|
|
10
10
|
/**
|
|
11
11
|
* Creates an instance of LocalResponse.
|
|
12
12
|
*/
|
|
13
13
|
constructor(inputFile) {
|
|
14
14
|
/** Whether the local response payload has been loaded. */
|
|
15
15
|
this.initialized = false;
|
|
16
|
-
|
|
16
|
+
if (inputFile === undefined || inputFile === null) {
|
|
17
|
+
throw new TypeError("input cannot be null or undefined");
|
|
18
|
+
}
|
|
19
|
+
if (typeof inputFile === "string" ? !inputFile.trim() : !inputFile.length) {
|
|
20
|
+
throw new TypeError("input cannot be empty");
|
|
21
|
+
}
|
|
22
|
+
this.fileBytes = Buffer.alloc(0);
|
|
17
23
|
this.inputHandle = inputFile;
|
|
18
24
|
}
|
|
19
25
|
/** Loads the local payload from a string, buffer, or file path. */
|
|
@@ -25,7 +31,7 @@ export class LocalResponseBase {
|
|
|
25
31
|
return;
|
|
26
32
|
}
|
|
27
33
|
if (Buffer.isBuffer(this.inputHandle)) {
|
|
28
|
-
this.
|
|
34
|
+
this.fileBytes = this.inputHandle;
|
|
29
35
|
}
|
|
30
36
|
else if (typeof this.inputHandle === "string") {
|
|
31
37
|
let fileContents;
|
|
@@ -36,7 +42,7 @@ export class LocalResponseBase {
|
|
|
36
42
|
catch {
|
|
37
43
|
fileContents = this.inputHandle;
|
|
38
44
|
}
|
|
39
|
-
this.
|
|
45
|
+
this.fileBytes = Buffer.from(fileContents.replace(/\r/g, "").replace(/\n/g, ""), "utf-8");
|
|
40
46
|
}
|
|
41
47
|
else {
|
|
42
48
|
throw new MindeeError("Incompatible type for input.");
|
|
@@ -52,7 +58,7 @@ export class LocalResponseBase {
|
|
|
52
58
|
await this.init();
|
|
53
59
|
}
|
|
54
60
|
try {
|
|
55
|
-
const content = this.
|
|
61
|
+
const content = this.fileBytes.toString("utf-8");
|
|
56
62
|
return JSON.parse(content);
|
|
57
63
|
}
|
|
58
64
|
catch {
|
|
@@ -71,7 +77,7 @@ export class LocalResponseBase {
|
|
|
71
77
|
const algorithm = "sha256";
|
|
72
78
|
try {
|
|
73
79
|
const hmac = crypto.createHmac(algorithm, secretKey);
|
|
74
|
-
hmac.update(this.
|
|
80
|
+
hmac.update(this.fileBytes);
|
|
75
81
|
return hmac.digest("hex");
|
|
76
82
|
}
|
|
77
83
|
catch {
|
|
@@ -88,6 +94,25 @@ export class LocalResponseBase {
|
|
|
88
94
|
if (!this.initialized) {
|
|
89
95
|
throw new Error("The `init()` method must be called before calling `isValidHmacSignature()`.");
|
|
90
96
|
}
|
|
91
|
-
|
|
97
|
+
if ((!signature || !signature?.trim())
|
|
98
|
+
|| (!secretKey || (typeof secretKey === "string" ? !secretKey?.trim() : !secretKey?.length))) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
const expectedSignature = this.getHmacSignature(secretKey);
|
|
102
|
+
if (!expectedSignature?.trim()) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const expectedBytes = Buffer.from(expectedSignature, "utf-8");
|
|
106
|
+
const actualBytes = Buffer.from(signature.toLowerCase(), "utf-8");
|
|
107
|
+
if (expectedBytes.length !== actualBytes.length) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return crypto.timingSafeEqual(expectedBytes, actualBytes);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Print the file as a UTF-8 string.
|
|
114
|
+
*/
|
|
115
|
+
toString() {
|
|
116
|
+
return this.fileBytes.toString("utf-8");
|
|
92
117
|
}
|
|
93
118
|
}
|
package/src/pdf/pdfCompressor.js
CHANGED
|
@@ -22,7 +22,6 @@ async function getPdfLib() {
|
|
|
22
22
|
* @returns A Promise resolving to the compressed PDF as a Buffer.
|
|
23
23
|
*/
|
|
24
24
|
export async function compressPdf(pdfData, imageQuality = 85, forceSourceTextCompression = false, disableSourceText = true) {
|
|
25
|
-
handleCompressionWarnings(forceSourceTextCompression, disableSourceText);
|
|
26
25
|
if (await hasSourceText(pdfData)) {
|
|
27
26
|
if (forceSourceTextCompression) {
|
|
28
27
|
if (!disableSourceText) {
|
|
@@ -48,22 +47,6 @@ export async function compressPdf(pdfData, imageQuality = 85, forceSourceTextCom
|
|
|
48
47
|
}
|
|
49
48
|
return createNewPdfFromCompressedPages(compressedPages);
|
|
50
49
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Handles compression warnings based on the provided parameters.
|
|
53
|
-
* @param forceSourceTextCompression If true, attempts to re-write detected text.
|
|
54
|
-
* @param disableSourceText If true, doesn't re-apply source text to the output PDF.
|
|
55
|
-
*/
|
|
56
|
-
function handleCompressionWarnings(forceSourceTextCompression, disableSourceText) {
|
|
57
|
-
if (forceSourceTextCompression) {
|
|
58
|
-
if (!disableSourceText) {
|
|
59
|
-
logger.warn("Re-writing PDF source-text is an EXPERIMENTAL feature.");
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
logger.warn("Source file contains text, but the disable_source_text is set to false. "
|
|
63
|
-
+ "Resulting file will not contain any embedded text.");
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
50
|
/**
|
|
68
51
|
* Compresses PDF pages and returns an array of compressed page buffers.
|
|
69
52
|
* @param pdfData The input PDF as a Buffer.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { InputSource, PageOptions } from "../../input/index.js";
|
|
2
|
+
import { ApiSettingsV1 } from "../../v1/http/apiSettingsV1.js";
|
|
3
|
+
export declare abstract class BaseEndpoint {
|
|
4
|
+
/** Settings relating to the API. */
|
|
5
|
+
settings: ApiSettingsV1;
|
|
6
|
+
/** Root of the URL for API calls. */
|
|
7
|
+
urlRoot: string;
|
|
8
|
+
protected constructor(settings: ApiSettingsV1, urlRoot: string);
|
|
9
|
+
/**
|
|
10
|
+
* Cuts a document's pages according to the given options.
|
|
11
|
+
* @param inputDoc input document.
|
|
12
|
+
* @param pageOptions page cutting options.
|
|
13
|
+
*/
|
|
14
|
+
cutDocPages(inputDoc: InputSource, pageOptions: PageOptions): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LocalInputSource } from "../../input/index.js";
|
|
2
|
+
export class BaseEndpoint {
|
|
3
|
+
constructor(settings, urlRoot) {
|
|
4
|
+
this.settings = settings;
|
|
5
|
+
this.urlRoot = urlRoot;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Cuts a document's pages according to the given options.
|
|
9
|
+
* @param inputDoc input document.
|
|
10
|
+
* @param pageOptions page cutting options.
|
|
11
|
+
*/
|
|
12
|
+
async cutDocPages(inputDoc, pageOptions) {
|
|
13
|
+
if (inputDoc instanceof LocalInputSource && inputDoc.isPdf()) {
|
|
14
|
+
await inputDoc.applyPageOptions(pageOptions);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -3,15 +3,12 @@ import { StringDict } from "../../parsing/stringDict.js";
|
|
|
3
3
|
import { BaseHttpResponse } from "../../http/apiCore.js";
|
|
4
4
|
import { ApiSettingsV1 } from "./apiSettingsV1.js";
|
|
5
5
|
import { PredictParams } from "./httpParams.js";
|
|
6
|
+
import { BaseEndpoint } from "../../v1/http/baseEndpoint.js";
|
|
6
7
|
/**
|
|
7
8
|
* Endpoint for a product (OTS or Custom).
|
|
8
9
|
*/
|
|
9
|
-
export declare class Endpoint {
|
|
10
|
+
export declare class Endpoint extends BaseEndpoint {
|
|
10
11
|
#private;
|
|
11
|
-
/** Settings relating to the API. */
|
|
12
|
-
settings: ApiSettingsV1;
|
|
13
|
-
/** Root of the URL for API calls. */
|
|
14
|
-
urlRoot: string;
|
|
15
12
|
/** URL of a product. */
|
|
16
13
|
urlName: string;
|
|
17
14
|
/** Account owning the product. */
|
package/src/v1/http/endpoint.js
CHANGED
|
@@ -7,17 +7,17 @@ var _Endpoint_instances, _Endpoint_predictReqPost, _Endpoint_predictAsyncReqPost
|
|
|
7
7
|
import { URLSearchParams } from "url";
|
|
8
8
|
import { FormData } from "undici";
|
|
9
9
|
import { LocalInputSource } from "../../input/index.js";
|
|
10
|
-
import {
|
|
10
|
+
import { sendRequestAndReadResponse, } from "../../http/apiCore.js";
|
|
11
11
|
import { handleError } from "./errors.js";
|
|
12
12
|
import { isValidAsyncResponse, isValidSyncResponse } from "./responseValidation.js";
|
|
13
|
+
import { BaseEndpoint } from "../../v1/http/baseEndpoint.js";
|
|
13
14
|
/**
|
|
14
15
|
* Endpoint for a product (OTS or Custom).
|
|
15
16
|
*/
|
|
16
|
-
export class Endpoint {
|
|
17
|
+
export class Endpoint extends BaseEndpoint {
|
|
17
18
|
constructor(urlName, owner, version, settings) {
|
|
19
|
+
super(settings, `/v1/products/${owner}/${urlName}/v${version}`);
|
|
18
20
|
_Endpoint_instances.add(this);
|
|
19
|
-
this.settings = settings;
|
|
20
|
-
this.urlRoot = `/v1/products/${owner}/${urlName}/v${version}`;
|
|
21
21
|
this.owner = owner;
|
|
22
22
|
this.urlName = urlName;
|
|
23
23
|
this.version = version;
|
|
@@ -32,7 +32,7 @@ export class Endpoint {
|
|
|
32
32
|
async predict(params) {
|
|
33
33
|
await params.inputDoc.init();
|
|
34
34
|
if (params.pageOptions !== undefined) {
|
|
35
|
-
await cutDocPages(params.inputDoc, params.pageOptions);
|
|
35
|
+
await this.cutDocPages(params.inputDoc, params.pageOptions);
|
|
36
36
|
}
|
|
37
37
|
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper);
|
|
38
38
|
if (!isValidSyncResponse(response)) {
|
|
@@ -50,7 +50,7 @@ export class Endpoint {
|
|
|
50
50
|
async predictAsync(params) {
|
|
51
51
|
await params.inputDoc.init();
|
|
52
52
|
if (params.pageOptions !== undefined) {
|
|
53
|
-
await cutDocPages(params.inputDoc, params.pageOptions);
|
|
53
|
+
await this.cutDocPages(params.inputDoc, params.pageOptions);
|
|
54
54
|
}
|
|
55
55
|
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictAsyncReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper, params.rag, params.workflowId);
|
|
56
56
|
if (!isValidAsyncResponse(response)) {
|
|
@@ -3,15 +3,12 @@ import { ExecutionPriority } from "../../v1/parsing/common/index.js";
|
|
|
3
3
|
import { BaseHttpResponse } from "../../http/apiCore.js";
|
|
4
4
|
import { ApiSettingsV1 } from "./apiSettingsV1.js";
|
|
5
5
|
import { WorkflowParams } from "./httpParams.js";
|
|
6
|
+
import { BaseEndpoint } from "../../v1/http/baseEndpoint.js";
|
|
6
7
|
/**
|
|
7
8
|
* Endpoint for a workflow.
|
|
8
9
|
*/
|
|
9
|
-
export declare class WorkflowEndpoint {
|
|
10
|
+
export declare class WorkflowEndpoint extends BaseEndpoint {
|
|
10
11
|
#private;
|
|
11
|
-
/** Settings relating to the API. */
|
|
12
|
-
settings: ApiSettingsV1;
|
|
13
|
-
/** Root of the URL for API calls. */
|
|
14
|
-
urlRoot: string;
|
|
15
12
|
constructor(settings: ApiSettingsV1, workflowId: string);
|
|
16
13
|
/**
|
|
17
14
|
* Sends a document to a workflow execution.
|
|
@@ -7,17 +7,17 @@ var _WorkflowEndpoint_instances, _WorkflowEndpoint_workflowReqPost;
|
|
|
7
7
|
import { URLSearchParams } from "url";
|
|
8
8
|
import { FormData } from "undici";
|
|
9
9
|
import { LocalInputSource } from "../../input/index.js";
|
|
10
|
-
import {
|
|
10
|
+
import { sendRequestAndReadResponse, } from "../../http/apiCore.js";
|
|
11
11
|
import { handleError } from "./errors.js";
|
|
12
12
|
import { isValidSyncResponse } from "./responseValidation.js";
|
|
13
|
+
import { BaseEndpoint } from "../../v1/http/baseEndpoint.js";
|
|
13
14
|
/**
|
|
14
15
|
* Endpoint for a workflow.
|
|
15
16
|
*/
|
|
16
|
-
export class WorkflowEndpoint {
|
|
17
|
+
export class WorkflowEndpoint extends BaseEndpoint {
|
|
17
18
|
constructor(settings, workflowId) {
|
|
19
|
+
super(settings, `/v1/workflows/${workflowId}/executions`);
|
|
18
20
|
_WorkflowEndpoint_instances.add(this);
|
|
19
|
-
this.settings = settings;
|
|
20
|
-
this.urlRoot = `/v1/workflows/${workflowId}/executions`;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Sends a document to a workflow execution.
|
|
@@ -29,7 +29,7 @@ export class WorkflowEndpoint {
|
|
|
29
29
|
async executeWorkflow(params) {
|
|
30
30
|
await params.inputDoc.init();
|
|
31
31
|
if (params.pageOptions !== undefined) {
|
|
32
|
-
await cutDocPages(params.inputDoc, params.pageOptions);
|
|
32
|
+
await this.cutDocPages(params.inputDoc, params.pageOptions);
|
|
33
33
|
}
|
|
34
34
|
const response = await __classPrivateFieldGet(this, _WorkflowEndpoint_instances, "m", _WorkflowEndpoint_workflowReqPost).call(this, params);
|
|
35
35
|
if (!isValidSyncResponse(response)) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseLocalResponse } from "../../parsing/baseLocalResponse.js";
|
|
2
2
|
import { AsyncPredictResponse, Inference, PredictResponse } from "../../v1/index.js";
|
|
3
3
|
import { StringDict } from "../../parsing/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Local response loaded from a file.
|
|
6
6
|
* Note: Has to be initialized through init() before use.
|
|
7
7
|
*/
|
|
8
|
-
export declare class LocalResponse extends
|
|
8
|
+
export declare class LocalResponse extends BaseLocalResponse {
|
|
9
9
|
/** Loads a local JSON payload into a typed prediction response wrapper. */
|
|
10
10
|
loadPrediction<T extends Inference>(productClass: new (httpResponse: StringDict) => T): Promise<AsyncPredictResponse<T> | PredictResponse<T>>;
|
|
11
11
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseLocalResponse } from "../../parsing/baseLocalResponse.js";
|
|
2
2
|
import { AsyncPredictResponse, PredictResponse } from "../../v1/index.js";
|
|
3
3
|
import { MindeeError } from "../../errors/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Local response loaded from a file.
|
|
6
6
|
* Note: Has to be initialized through init() before use.
|
|
7
7
|
*/
|
|
8
|
-
export class LocalResponse extends
|
|
8
|
+
export class LocalResponse extends BaseLocalResponse {
|
|
9
9
|
/** Loads a local JSON payload into a typed prediction response wrapper. */
|
|
10
10
|
async loadPrediction(productClass) {
|
|
11
11
|
/**
|
package/src/v2/client.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { SearchResponse } from "./parsing/search/index.js";
|
|
|
5
5
|
import { MindeeApiV2 } from "./http/mindeeApiV2.js";
|
|
6
6
|
import { PollingOptions, PollingOptionsConstructor } from "./clientOptions/index.js";
|
|
7
7
|
import { BaseProduct } from "../v2/product/baseProduct.js";
|
|
8
|
+
import { BaseSearch } from "../v2/search/baseSearch.js";
|
|
8
9
|
/**
|
|
9
10
|
* Options for the V2 Mindee Client.
|
|
10
11
|
* @example
|
|
@@ -37,8 +38,16 @@ export declare class Client {
|
|
|
37
38
|
* @param name Optional name filter.
|
|
38
39
|
* @param modelType Optional model type filter.
|
|
39
40
|
* @returns a `Promise` containing the search response.
|
|
41
|
+
* @deprecated Use `search(ModelSearch, {})` instead.
|
|
40
42
|
*/
|
|
41
43
|
searchModels(name?: string, modelType?: string): Promise<SearchResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* Search for resources matching the given criteria.
|
|
46
|
+
* @param search Search definition class to use.
|
|
47
|
+
* @param searchParameters Search parameters.
|
|
48
|
+
* @returns a `Promise` containing the search response with the matching resources.
|
|
49
|
+
*/
|
|
50
|
+
search<S extends typeof BaseSearch>(search: S, searchParameters: InstanceType<S["parametersClass"]> | ConstructorParameters<S["parametersClass"]>[0]): Promise<InstanceType<S["responseClass"]>>;
|
|
42
51
|
/** Enqueues a product inference job without waiting for completion. */
|
|
43
52
|
enqueue<P extends typeof BaseProduct>(product: P, inputSource: InputSource, params: InstanceType<P["parametersClass"]> | ConstructorParameters<P["parametersClass"]>[0]): Promise<JobResponse>;
|
|
44
53
|
/**
|
package/src/v2/client.js
CHANGED
|
@@ -5,6 +5,7 @@ import { LOG_LEVELS, logger } from "../logger.js";
|
|
|
5
5
|
import { MindeeApiV2 } from "./http/mindeeApiV2.js";
|
|
6
6
|
import { MindeeHttpErrorV2 } from "./http/errors.js";
|
|
7
7
|
import { PollingOptions } from "./clientOptions/index.js";
|
|
8
|
+
import { ModelSearch } from "../v2/search/models/modelSearch.js";
|
|
8
9
|
/**
|
|
9
10
|
* Mindee Client V2 class that centralizes most basic operations.
|
|
10
11
|
*/
|
|
@@ -30,9 +31,25 @@ export class Client {
|
|
|
30
31
|
* @param name Optional name filter.
|
|
31
32
|
* @param modelType Optional model type filter.
|
|
32
33
|
* @returns a `Promise` containing the search response.
|
|
34
|
+
* @deprecated Use `search(ModelSearch, {})` instead.
|
|
33
35
|
*/
|
|
34
36
|
async searchModels(name, modelType) {
|
|
35
|
-
return await this.
|
|
37
|
+
return await this.search(ModelSearch, { name: name, modelType: modelType });
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Search for resources matching the given criteria.
|
|
41
|
+
* @param search Search definition class to use.
|
|
42
|
+
* @param searchParameters Search parameters.
|
|
43
|
+
* @returns a `Promise` containing the search response with the matching resources.
|
|
44
|
+
*/
|
|
45
|
+
async search(search, searchParameters) {
|
|
46
|
+
if (!searchParameters) {
|
|
47
|
+
throw new MindeeError("Search parameters are required.");
|
|
48
|
+
}
|
|
49
|
+
const paramsInstance = searchParameters instanceof search.parametersClass
|
|
50
|
+
? searchParameters
|
|
51
|
+
: new search.parametersClass(searchParameters);
|
|
52
|
+
return await this.mindeeApi.reqGetSearch(search, paramsInstance);
|
|
36
53
|
}
|
|
37
54
|
/** Enqueues a product inference job without waiting for completion. */
|
|
38
55
|
async enqueue(product, inputSource, params) {
|
|
@@ -1,28 +1,16 @@
|
|
|
1
|
-
import { FormData } from "undici";
|
|
2
1
|
/**
|
|
3
2
|
* Constructor parameters for BaseParameters and its subclasses.
|
|
4
3
|
*/
|
|
5
|
-
export interface
|
|
4
|
+
export interface BaseProductParametersConstructor {
|
|
6
5
|
modelId: string;
|
|
7
6
|
alias?: string;
|
|
8
7
|
webhookIds?: string[];
|
|
9
8
|
closeFile?: boolean;
|
|
10
9
|
}
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* All fields are optional except `modelId`.
|
|
15
|
-
*
|
|
16
|
-
* @category ClientV2
|
|
17
|
-
* @example
|
|
18
|
-
* const params = {
|
|
19
|
-
* modelId: "YOUR_MODEL_ID",
|
|
20
|
-
* rag: true,
|
|
21
|
-
* alias: "YOUR_ALIAS",
|
|
22
|
-
* webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"],
|
|
23
|
-
* };
|
|
11
|
+
* Base parameters for sending a file to a Mindee V2 product.
|
|
24
12
|
*/
|
|
25
|
-
export declare abstract class
|
|
13
|
+
export declare abstract class BaseProductParameters {
|
|
26
14
|
/**
|
|
27
15
|
* Model ID to use for the inference. **Required.**
|
|
28
16
|
*/
|
|
@@ -43,10 +31,10 @@ export declare abstract class BaseParameters {
|
|
|
43
31
|
* Set to `false` to keep it open.
|
|
44
32
|
*/
|
|
45
33
|
closeFile?: boolean;
|
|
46
|
-
protected constructor(params:
|
|
34
|
+
protected constructor(params: BaseProductParametersConstructor);
|
|
47
35
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @returns A `
|
|
36
|
+
* Gets the request parameters for the enqueue request.
|
|
37
|
+
* @returns A `Record` mapping parameter names to their string values.
|
|
50
38
|
*/
|
|
51
|
-
|
|
39
|
+
getRequestParameters(): Record<string, string>;
|
|
52
40
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MindeeConfigurationError } from "../../errors/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Base parameters for sending a file to a Mindee V2 product.
|
|
4
|
+
*/
|
|
5
|
+
export class BaseProductParameters {
|
|
6
|
+
constructor(params) {
|
|
7
|
+
if (params.modelId === undefined || params.modelId === null || params.modelId === "") {
|
|
8
|
+
throw new MindeeConfigurationError("Model ID must be provided");
|
|
9
|
+
}
|
|
10
|
+
this.modelId = params.modelId;
|
|
11
|
+
this.alias = params.alias;
|
|
12
|
+
this.webhookIds = params.webhookIds;
|
|
13
|
+
this.closeFile = params.closeFile;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Gets the request parameters for the enqueue request.
|
|
17
|
+
* @returns A `Record` mapping parameter names to their string values.
|
|
18
|
+
*/
|
|
19
|
+
getRequestParameters() {
|
|
20
|
+
const parameters = {};
|
|
21
|
+
parameters["model_id"] = this.modelId;
|
|
22
|
+
if (this.alias !== undefined && this.alias !== null) {
|
|
23
|
+
parameters["alias"] = this.alias;
|
|
24
|
+
}
|
|
25
|
+
if (this.webhookIds && this.webhookIds.length > 0) {
|
|
26
|
+
parameters["webhook_ids"] = this.webhookIds.join(",");
|
|
27
|
+
}
|
|
28
|
+
return parameters;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructor parameters for BaseSearchParameters and its subclasses.
|
|
3
|
+
*/
|
|
4
|
+
export interface BaseSearchParametersConstructor {
|
|
5
|
+
page?: number;
|
|
6
|
+
perPage?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Base parameters for searches.
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class BaseSearchParameters {
|
|
12
|
+
/**
|
|
13
|
+
* 1-based page index.
|
|
14
|
+
*/
|
|
15
|
+
page?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Number of items per page.
|
|
18
|
+
*/
|
|
19
|
+
perPage?: number;
|
|
20
|
+
protected constructor(params: BaseSearchParametersConstructor);
|
|
21
|
+
/**
|
|
22
|
+
* Gets the request parameters for the search request.
|
|
23
|
+
* @returns A `Record` mapping parameter names to their string values.
|
|
24
|
+
*/
|
|
25
|
+
getRequestParameters(): Record<string, string>;
|
|
26
|
+
}
|