mindee 5.3.1 → 5.5.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 +12 -0
- package/package.json +1 -1
- package/src/http/apiCore.d.ts +1 -0
- package/src/http/apiCore.js +21 -3
- package/src/image/extractedImage.d.ts +5 -5
- package/src/image/extractedImage.js +2 -2
- package/src/image/extractedImages.d.ts +4 -0
- package/src/image/extractedImages.js +5 -0
- package/src/image/imageExtractor.d.ts +2 -2
- package/src/image/imageExtractor.js +4 -3
- package/src/image/index.d.ts +1 -0
- package/src/image/index.js +1 -0
- package/src/pdf/extractedPdf.d.ts +3 -2
- package/src/pdf/extractedPdf.js +4 -3
- package/src/pdf/extractedPdfs.d.ts +4 -0
- package/src/{v2/fileOperations/cropFiles.js → pdf/extractedPdfs.js} +1 -1
- package/src/pdf/index.d.ts +2 -0
- package/src/pdf/index.js +2 -0
- package/src/pdf/pdfExtractor.d.ts +2 -2
- package/src/pdf/pdfExtractor.js +1 -1
- package/src/v1/extraction/invoiceSplitterExtractor/extractedInvoiceSplitterImage.d.ts +3 -3
- package/src/v1/extraction/invoiceSplitterExtractor/extractedInvoiceSplitterImage.js +4 -4
- package/src/v1/extraction/multiReceiptsExtractor/extractedMultiReceiptImage.js +1 -1
- package/src/v2/client.d.ts +9 -1
- package/src/v2/client.js +17 -8
- package/src/v2/clientOptions/baseParameters.d.ts +3 -2
- package/src/v2/clientOptions/pollingOptions.d.ts +1 -1
- package/src/v2/clientOptions/pollingOptions.js +2 -2
- package/src/v2/fileOperations/crop.d.ts +4 -4
- package/src/v2/fileOperations/crop.js +5 -6
- package/src/v2/fileOperations/split.d.ts +3 -3
- package/src/v2/fileOperations/split.js +6 -6
- package/src/v2/http/mindeeApiV2.d.ts +23 -10
- package/src/v2/http/mindeeApiV2.js +79 -68
- package/src/v2/parsing/search/index.d.ts +4 -0
- package/src/v2/parsing/search/index.js +4 -0
- package/src/v2/parsing/search/modelWebhook.d.ts +19 -0
- package/src/v2/parsing/search/modelWebhook.js +10 -0
- package/src/v2/parsing/search/paginationMetadata.d.ts +24 -0
- package/src/v2/parsing/search/paginationMetadata.js +19 -0
- package/src/v2/parsing/search/searchModel.d.ts +25 -0
- package/src/v2/parsing/search/searchModel.js +19 -0
- package/src/v2/parsing/search/searchResponse.d.ts +19 -0
- package/src/v2/parsing/search/searchResponse.js +24 -0
- package/src/v2/product/crop/cropItem.d.ts +1 -1
- package/src/v2/product/crop/cropItem.js +3 -3
- package/src/v2/product/crop/cropResponse.d.ts +0 -8
- package/src/v2/product/crop/cropResponse.js +0 -9
- package/src/v2/product/crop/cropResult.d.ts +8 -0
- package/src/v2/product/crop/cropResult.js +9 -0
- package/src/v2/product/split/splitRange.d.ts +2 -1
- package/src/v2/product/split/splitRange.js +2 -2
- package/src/v2/product/split/splitResponse.d.ts +0 -7
- package/src/v2/product/split/splitResponse.js +0 -12
- package/src/v2/product/split/splitResult.d.ts +7 -0
- package/src/v2/product/split/splitResult.js +12 -0
- package/src/v2/fileOperations/cropFiles.d.ts +0 -4
- package/src/v2/fileOperations/splitFiles.d.ts +0 -4
- package/src/v2/fileOperations/splitFiles.js +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Mindee Node.js API Library Changelog
|
|
2
2
|
|
|
3
|
+
## v5.5.0 - 2026-07-01
|
|
4
|
+
### Fixes
|
|
5
|
+
* :memo: minor tweak to SKILL file
|
|
6
|
+
* :bug: retry once on connection error
|
|
7
|
+
* :recycle: rework and fix extractors (:boom: some **undocumented** functions break)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## v5.4.0 - 2026-06-22
|
|
11
|
+
### Fixes
|
|
12
|
+
* :bug: :boom: harmonize Crop and Split extraction (now ready for public use)
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
## v5.3.1 - 2026-06-11
|
|
4
16
|
### Fixes
|
|
5
17
|
* :arrow_up: bump 'tmp' and 'file-type'
|
package/package.json
CHANGED
package/src/http/apiCore.d.ts
CHANGED
package/src/http/apiCore.js
CHANGED
|
@@ -20,14 +20,32 @@ export async function cutDocPages(inputDoc, pageOptions) {
|
|
|
20
20
|
* @returns the processed request.
|
|
21
21
|
*/
|
|
22
22
|
export async function sendRequestAndReadResponse(dispatcher, options, url) {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const requestUrl = new URL(url ?? `https://${options.hostname}${options.path}`);
|
|
24
|
+
if (options.queryParams) {
|
|
25
|
+
for (const [key, value] of Object.entries(options.queryParams)) {
|
|
26
|
+
requestUrl.searchParams.set(key, value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const requestParams = {
|
|
25
30
|
method: options.method,
|
|
26
31
|
headers: options.headers,
|
|
27
32
|
headersTimeout: options.timeoutSecs * 1000,
|
|
28
33
|
body: options.body,
|
|
29
34
|
dispatcher: dispatcher,
|
|
30
|
-
}
|
|
35
|
+
};
|
|
36
|
+
let response;
|
|
37
|
+
try {
|
|
38
|
+
response = await request(requestUrl, requestParams);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
// shenanigans in networking or freezing/thawing of the process in serverless environments
|
|
42
|
+
if (err.code === "UND_ERR_SOCKET" || err.code === "UND_ERR_CONNECT_TIMEOUT" || err.code === "ECONNRESET") {
|
|
43
|
+
logger.warn(`Socket error (${err.code}), retrying with a fresh connection...`);
|
|
44
|
+
response = await request(requestUrl, requestParams);
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
31
49
|
logger.debug("Parsing the response ...");
|
|
32
50
|
let responseBody = await response.body.text();
|
|
33
51
|
// handle empty responses from server, for example, in the case of redirects
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
2
|
import { BufferInput } from "../input/index.js";
|
|
3
3
|
/**
|
|
4
|
-
* Generic class for image extraction
|
|
4
|
+
* Generic class for image extraction.
|
|
5
5
|
*/
|
|
6
6
|
export declare class ExtractedImage {
|
|
7
7
|
buffer: Buffer;
|
|
8
8
|
filename: string;
|
|
9
|
-
pageId
|
|
10
|
-
elementId
|
|
11
|
-
constructor(buffer: Uint8Array, fileName: string, pageId
|
|
9
|
+
readonly pageId: number;
|
|
10
|
+
readonly elementId: number;
|
|
11
|
+
constructor(buffer: Uint8Array, fileName: string, pageId: number, elementId: number);
|
|
12
12
|
/**
|
|
13
13
|
* Saves the document to a file.
|
|
14
14
|
*
|
|
@@ -27,5 +27,5 @@ export declare class ExtractedImage {
|
|
|
27
27
|
*
|
|
28
28
|
* @returns A BufferInput source.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
asInputSource(): BufferInput;
|
|
31
31
|
}
|
|
@@ -7,7 +7,7 @@ import { BufferInput, MIMETYPES } from "../input/index.js";
|
|
|
7
7
|
import { logger } from "../logger.js";
|
|
8
8
|
import { loadOptionalDependency } from "../dependency/index.js";
|
|
9
9
|
/**
|
|
10
|
-
* Generic class for image extraction
|
|
10
|
+
* Generic class for image extraction.
|
|
11
11
|
*/
|
|
12
12
|
export class ExtractedImage {
|
|
13
13
|
constructor(buffer, fileName, pageId, elementId) {
|
|
@@ -92,7 +92,7 @@ export class ExtractedImage {
|
|
|
92
92
|
*
|
|
93
93
|
* @returns A BufferInput source.
|
|
94
94
|
*/
|
|
95
|
-
|
|
95
|
+
asInputSource() {
|
|
96
96
|
return new BufferInput({
|
|
97
97
|
buffer: this.buffer,
|
|
98
98
|
filename: this.filename,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Polygon } from "../geometry/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ExtractedImages } from "../image/extractedImages.js";
|
|
3
3
|
import { LocalInputSource } from "../input/index.js";
|
|
4
4
|
import type * as pdfLibTypes from "@cantoo/pdf-lib";
|
|
5
5
|
/**
|
|
@@ -8,7 +8,7 @@ import type * as pdfLibTypes from "@cantoo/pdf-lib";
|
|
|
8
8
|
* @param polygonsPerPage List of polygons to extract from per page.
|
|
9
9
|
* @param quality JPEG quality of extracted images.
|
|
10
10
|
*/
|
|
11
|
-
export declare function extractImagesFromPolygon(inputSource: LocalInputSource, polygonsPerPage: Map<number, Polygon[]>, quality?: number): Promise<
|
|
11
|
+
export declare function extractImagesFromPolygon(inputSource: LocalInputSource, polygonsPerPage: Map<number, Polygon[]>, quality?: number): Promise<ExtractedImages>;
|
|
12
12
|
/**
|
|
13
13
|
* Extracts elements from a page based off of a list of bounding boxes.
|
|
14
14
|
*
|
|
@@ -3,6 +3,7 @@ import { MindeeImageError } from "../errors/index.js";
|
|
|
3
3
|
import { getMinMaxX, getMinMaxY } from "../geometry/index.js";
|
|
4
4
|
import { adjustForRotation } from "../geometry/polygonUtils.js";
|
|
5
5
|
import { ExtractedImage } from "../image/extractedImage.js";
|
|
6
|
+
import { ExtractedImages } from "../image/extractedImages.js";
|
|
6
7
|
import { logger } from "../logger.js";
|
|
7
8
|
import { createPdfFromInputSource } from "../pdf/pdfOperation.js";
|
|
8
9
|
import { rasterizePage } from "../pdf/pdfUtils.js";
|
|
@@ -21,13 +22,13 @@ async function getPdfLib() {
|
|
|
21
22
|
* @param quality JPEG quality of extracted images.
|
|
22
23
|
*/
|
|
23
24
|
export async function extractImagesFromPolygon(inputSource, polygonsPerPage, quality) {
|
|
24
|
-
const allExtractedImages =
|
|
25
|
+
const allExtractedImages = new ExtractedImages();
|
|
25
26
|
const pdfDoc = await createPdfFromInputSource(inputSource);
|
|
26
27
|
for (const [pageId, polygons] of polygonsPerPage) {
|
|
27
28
|
logger.debug(`Extracting images from page ${pageId}`);
|
|
28
29
|
const pdfPage = pdfDoc.getPage(pageId);
|
|
29
|
-
const extractions =
|
|
30
|
-
const extractedImages = extractions.map((
|
|
30
|
+
const extractions = await extractFromPage(pdfPage, polygons, true, quality);
|
|
31
|
+
const extractedImages = extractions.map((buffer, elementId) => new ExtractedImage(buffer, inputSource.filename + `_page-${pageId}-item-${elementId}.jpg`, pageId, elementId));
|
|
31
32
|
allExtractedImages.push(...extractedImages);
|
|
32
33
|
}
|
|
33
34
|
return allExtractedImages;
|
package/src/image/index.d.ts
CHANGED
package/src/image/index.js
CHANGED
|
@@ -4,7 +4,8 @@ export declare class ExtractedPdf {
|
|
|
4
4
|
readonly buffer: Buffer;
|
|
5
5
|
readonly filename: string;
|
|
6
6
|
readonly pageCount: number;
|
|
7
|
-
|
|
7
|
+
readonly pageIndexes: number[];
|
|
8
|
+
constructor(pdfData: Buffer<ArrayBufferLike>, filename: string, pageIndexes: number[]);
|
|
8
9
|
/**
|
|
9
10
|
* Saves the document to a file.
|
|
10
11
|
*
|
|
@@ -21,5 +22,5 @@ export declare class ExtractedPdf {
|
|
|
21
22
|
*
|
|
22
23
|
* @returns A BufferInput source.
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
asInputSource(): BufferInput;
|
|
25
26
|
}
|
package/src/pdf/extractedPdf.js
CHANGED
|
@@ -5,10 +5,11 @@ import { writeFile } from "fs/promises";
|
|
|
5
5
|
import { logger } from "../logger.js";
|
|
6
6
|
import { writeFileSync } from "node:fs";
|
|
7
7
|
export class ExtractedPdf {
|
|
8
|
-
constructor(pdfData, filename,
|
|
8
|
+
constructor(pdfData, filename, pageIndexes) {
|
|
9
9
|
this.buffer = pdfData;
|
|
10
10
|
this.filename = filename;
|
|
11
|
-
this.pageCount =
|
|
11
|
+
this.pageCount = pageIndexes.length;
|
|
12
|
+
this.pageIndexes = pageIndexes;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Saves the document to a file.
|
|
@@ -56,7 +57,7 @@ export class ExtractedPdf {
|
|
|
56
57
|
*
|
|
57
58
|
* @returns A BufferInput source.
|
|
58
59
|
*/
|
|
59
|
-
|
|
60
|
+
asInputSource() {
|
|
60
61
|
return new BufferInput({
|
|
61
62
|
buffer: this.buffer,
|
|
62
63
|
filename: this.filename,
|
package/src/pdf/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { extractPages, countPages } from "./pdfOperation.js";
|
|
|
2
2
|
export type { SplitPdf } from "./pdfOperation.js";
|
|
3
3
|
export { compressPdf } from "./pdfCompressor.js";
|
|
4
4
|
export { hasSourceText } from "./pdfUtils.js";
|
|
5
|
+
export { ExtractedPdf } from "./extractedPdf.js";
|
|
6
|
+
export { ExtractedPdfs } from "./extractedPdfs.js";
|
package/src/pdf/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LocalInputSource } from "../input/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ExtractedPdfs } from "../pdf/extractedPdfs.js";
|
|
3
3
|
export declare class PdfExtractor {
|
|
4
4
|
/**
|
|
5
5
|
* Buffer containing the PDF data.
|
|
@@ -42,5 +42,5 @@ export declare class PdfExtractor {
|
|
|
42
42
|
* Extracts pages from the PDF.
|
|
43
43
|
* @param pageIndexes
|
|
44
44
|
*/
|
|
45
|
-
extractSubDocuments(pageIndexes: number[][]): Promise<
|
|
45
|
+
extractSubDocuments(pageIndexes: number[][]): Promise<ExtractedPdfs>;
|
|
46
46
|
}
|
package/src/pdf/pdfExtractor.js
CHANGED
|
@@ -121,7 +121,7 @@ export class PdfExtractor {
|
|
|
121
121
|
const endPage = String(pageRange[pageRange.length - 1] + 1).padStart(3, "0");
|
|
122
122
|
const fieldFilename = `${splitName}_page_${startPage}-${endPage}.pdf`;
|
|
123
123
|
const page = await extractPages(this.sourcePdf, pageOptions);
|
|
124
|
-
this.extractedPdfs.push(new ExtractedPdf(page.file, fieldFilename, pageRange
|
|
124
|
+
this.extractedPdfs.push(new ExtractedPdf(page.file, fieldFilename, pageRange));
|
|
125
125
|
}
|
|
126
126
|
return this.extractedPdfs;
|
|
127
127
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExtractedPdf } from "../../../pdf/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Wrapper class for extracted invoice pages.
|
|
4
4
|
*/
|
|
5
|
-
export declare class ExtractedInvoiceSplitterImage extends
|
|
5
|
+
export declare class ExtractedInvoiceSplitterImage extends ExtractedPdf {
|
|
6
6
|
readonly pageIdMin: number;
|
|
7
7
|
readonly pageIdMax: number;
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(bytes: Uint8Array, pageIndices: [number, number]);
|
|
9
9
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExtractedPdf } from "../../../pdf/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Wrapper class for extracted invoice pages.
|
|
4
4
|
*/
|
|
5
|
-
export class ExtractedInvoiceSplitterImage extends
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
5
|
+
export class ExtractedInvoiceSplitterImage extends ExtractedPdf {
|
|
6
|
+
constructor(bytes, pageIndices) {
|
|
7
|
+
super(Buffer.from(bytes), `invoice_p_${pageIndices[0]}-${pageIndices[1]}.pdf`, pageIndices);
|
|
8
8
|
this.pageIdMin = pageIndices[0];
|
|
9
9
|
this.pageIdMax = pageIndices[1];
|
|
10
10
|
}
|
|
@@ -4,7 +4,7 @@ import { ExtractedImage } from "../../../image/index.js";
|
|
|
4
4
|
*/
|
|
5
5
|
export class ExtractedMultiReceiptImage extends ExtractedImage {
|
|
6
6
|
constructor(buffer, pageId, receiptId) {
|
|
7
|
-
super(buffer, `receipt_p${pageId}_${receiptId}.pdf
|
|
7
|
+
super(buffer, `receipt_p${pageId}_${receiptId}.pdf`, pageId, receiptId);
|
|
8
8
|
this.pageId = pageId;
|
|
9
9
|
this.receiptId = receiptId;
|
|
10
10
|
}
|
package/src/v2/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Dispatcher } from "undici";
|
|
2
2
|
import { InputSource } from "../input/index.js";
|
|
3
3
|
import { JobResponse } from "./parsing/index.js";
|
|
4
|
+
import { SearchResponse } from "./parsing/search/index.js";
|
|
4
5
|
import { MindeeApiV2 } from "./http/mindeeApiV2.js";
|
|
5
6
|
import { PollingOptions, PollingOptionsConstructor } from "./clientOptions/index.js";
|
|
6
7
|
import { BaseProduct } from "../v2/product/baseProduct.js";
|
|
@@ -31,6 +32,13 @@ export declare class Client {
|
|
|
31
32
|
* @param {ClientOptions} options options for the initialization of a client.
|
|
32
33
|
*/
|
|
33
34
|
constructor({ apiKey, debug, dispatcher }?: ClientOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Search for models available to the account.
|
|
37
|
+
* @param name Optional name filter.
|
|
38
|
+
* @param modelType Optional model type filter.
|
|
39
|
+
* @returns a `Promise` containing the search response.
|
|
40
|
+
*/
|
|
41
|
+
searchModels(name?: string, modelType?: string): Promise<SearchResponse>;
|
|
34
42
|
enqueue<P extends typeof BaseProduct>(product: P, inputSource: InputSource, params: InstanceType<P["parametersClass"]> | ConstructorParameters<P["parametersClass"]>[0]): Promise<JobResponse>;
|
|
35
43
|
/**
|
|
36
44
|
* Retrieves the result of a previously enqueued request.
|
|
@@ -79,5 +87,5 @@ export declare class Client {
|
|
|
79
87
|
* until the maximum number of tries is reached.
|
|
80
88
|
* @protected
|
|
81
89
|
*/
|
|
82
|
-
protected pollForResult<P extends typeof BaseProduct>(product: typeof BaseProduct, pollingOptions: PollingOptions,
|
|
90
|
+
protected pollForResult<P extends typeof BaseProduct>(product: typeof BaseProduct, pollingOptions: PollingOptions, jobResponse: JobResponse): Promise<InstanceType<P["responseClass"]>>;
|
|
83
91
|
}
|
package/src/v2/client.js
CHANGED
|
@@ -25,6 +25,15 @@ export class Client {
|
|
|
25
25
|
: LOG_LEVELS["warn"];
|
|
26
26
|
logger.debug("Client V2 Initialized");
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Search for models available to the account.
|
|
30
|
+
* @param name Optional name filter.
|
|
31
|
+
* @param modelType Optional model type filter.
|
|
32
|
+
* @returns a `Promise` containing the search response.
|
|
33
|
+
*/
|
|
34
|
+
async searchModels(name, modelType) {
|
|
35
|
+
return await this.mindeeApi.reqGetSearchModel(name, modelType);
|
|
36
|
+
}
|
|
28
37
|
async enqueue(product, inputSource, params) {
|
|
29
38
|
if (inputSource === undefined) {
|
|
30
39
|
throw new MindeeError("An input document is required.");
|
|
@@ -33,7 +42,7 @@ export class Client {
|
|
|
33
42
|
? params
|
|
34
43
|
: new product.parametersClass(params);
|
|
35
44
|
await inputSource.init();
|
|
36
|
-
const jobResponse = await this.mindeeApi.
|
|
45
|
+
const jobResponse = await this.mindeeApi.reqPostProductEnqueue(product, inputSource, paramsInstance);
|
|
37
46
|
if (jobResponse.job.id === undefined || jobResponse.job.id.length === 0) {
|
|
38
47
|
logger.error(`Failed enqueueing:\n${jobResponse.getRawHttp()}`);
|
|
39
48
|
throw new MindeeError("Enqueueing of the document failed.");
|
|
@@ -51,7 +60,7 @@ export class Client {
|
|
|
51
60
|
*/
|
|
52
61
|
async getResult(product, inferenceId) {
|
|
53
62
|
logger.debug(`Attempting to get inference with ID: ${inferenceId} using response type: ${product.name}`);
|
|
54
|
-
return await this.mindeeApi.
|
|
63
|
+
return await this.mindeeApi.reqGetProductResultById(product, inferenceId);
|
|
55
64
|
}
|
|
56
65
|
/**
|
|
57
66
|
* Retrieves the result of a previously enqueued request.
|
|
@@ -64,7 +73,7 @@ export class Client {
|
|
|
64
73
|
*/
|
|
65
74
|
async getResultByUrl(product, url) {
|
|
66
75
|
logger.debug(`Attempting to get inference from: ${url} using response type: ${product.name}`);
|
|
67
|
-
return await this.mindeeApi.
|
|
76
|
+
return await this.mindeeApi.reqGetProductResultByUrl(product, url);
|
|
68
77
|
}
|
|
69
78
|
/**
|
|
70
79
|
* Get the processing status of a previously enqueued request.
|
|
@@ -76,7 +85,7 @@ export class Client {
|
|
|
76
85
|
* parsing is complete.
|
|
77
86
|
*/
|
|
78
87
|
async getJob(jobId) {
|
|
79
|
-
return await this.mindeeApi.
|
|
88
|
+
return await this.mindeeApi.reqGetJobById(jobId);
|
|
80
89
|
}
|
|
81
90
|
/**
|
|
82
91
|
* Enqueue a request and poll the server until the result is sent or
|
|
@@ -94,22 +103,22 @@ export class Client {
|
|
|
94
103
|
const paramsInstance = new product.parametersClass(params);
|
|
95
104
|
const pollingOptionsInstance = new PollingOptions(pollingOptions);
|
|
96
105
|
const jobResponse = await this.enqueue(product, inputSource, paramsInstance);
|
|
97
|
-
return await this.pollForResult(product, pollingOptionsInstance, jobResponse
|
|
106
|
+
return await this.pollForResult(product, pollingOptionsInstance, jobResponse);
|
|
98
107
|
}
|
|
99
108
|
/**
|
|
100
109
|
* Send a document to an endpoint and poll the server until the result is sent or
|
|
101
110
|
* until the maximum number of tries is reached.
|
|
102
111
|
* @protected
|
|
103
112
|
*/
|
|
104
|
-
async pollForResult(product, pollingOptions,
|
|
113
|
+
async pollForResult(product, pollingOptions, jobResponse) {
|
|
105
114
|
logger.debug(`Waiting ${pollingOptions.initialDelaySec} seconds before polling.`);
|
|
106
115
|
await setTimeout(pollingOptions.initialDelaySec * 1000, undefined, pollingOptions.initialTimerOptions);
|
|
107
|
-
logger.debug(`Start polling for inference using job ID: ${
|
|
116
|
+
logger.debug(`Start polling for inference using job ID: ${jobResponse.job.id}.`);
|
|
108
117
|
let retryCounter = 1;
|
|
109
118
|
let pollResults;
|
|
110
119
|
while (retryCounter < pollingOptions.maxRetries + 1) {
|
|
111
120
|
logger.debug(`Attempt ${retryCounter} of ${pollingOptions.maxRetries}`);
|
|
112
|
-
pollResults = await this.
|
|
121
|
+
pollResults = await this.mindeeApi.reqGetJobByUrl(jobResponse.job.pollingUrl);
|
|
113
122
|
const error = pollResults.job.error;
|
|
114
123
|
if (error) {
|
|
115
124
|
throw new MindeeHttpErrorV2(error);
|
|
@@ -28,8 +28,9 @@ export declare abstract class BaseParameters {
|
|
|
28
28
|
*/
|
|
29
29
|
modelId: string;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* Optional: a free-form string to tag the request with your own identifier.
|
|
32
|
+
* For example, an internal document ID, reference number, or database key.
|
|
33
|
+
* If set, it will be included in the job and result responses.
|
|
33
34
|
*/
|
|
34
35
|
alias?: string;
|
|
35
36
|
/**
|
|
@@ -51,6 +51,6 @@ export declare class PollingOptions {
|
|
|
51
51
|
/** Options passed to every recurring `setTimeout()`. */
|
|
52
52
|
recurringTimerOptions?: TimerOptions;
|
|
53
53
|
constructor(params?: PollingOptionsConstructor);
|
|
54
|
-
|
|
54
|
+
validateSettings(): void;
|
|
55
55
|
toString(): string;
|
|
56
56
|
}
|
|
@@ -62,10 +62,10 @@ export class PollingOptions {
|
|
|
62
62
|
if (params.recurringTimerOptions) {
|
|
63
63
|
this.recurringTimerOptions = params.recurringTimerOptions;
|
|
64
64
|
}
|
|
65
|
-
this.
|
|
65
|
+
this.validateSettings();
|
|
66
66
|
logger.debug(`Polling options initialized: ${this.toString()}`);
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
validateSettings() {
|
|
69
69
|
if (this.delaySec < minDelaySec) {
|
|
70
70
|
throw new MindeeConfigurationError(`Cannot set auto-parsing delay to less than ${minDelaySec} second(s).`);
|
|
71
71
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { LocalInputSource } from "../../input/index.js";
|
|
2
2
|
import { CropItem } from "../../v2/product/crop/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import { ExtractedImage } from "../../image/index.js";
|
|
3
|
+
import { ExtractedImage, ExtractedImages } from "../../image/index.js";
|
|
5
4
|
/**
|
|
6
5
|
* Extracts a single specified crop from a given input source.
|
|
7
6
|
* @param inputSource Local input source.
|
|
8
7
|
* @param crop Crop to extract.
|
|
8
|
+
* @param quality JPEG quality of extracted image.
|
|
9
9
|
*/
|
|
10
|
-
export declare function extractSingleCrop(inputSource: LocalInputSource, crop: CropItem): Promise<ExtractedImage>;
|
|
10
|
+
export declare function extractSingleCrop(inputSource: LocalInputSource, crop: CropItem, quality?: number): Promise<ExtractedImage>;
|
|
11
11
|
/**
|
|
12
12
|
* Extracts a list of crops from a document.
|
|
13
13
|
* @param inputSource Local input source.
|
|
@@ -15,4 +15,4 @@ export declare function extractSingleCrop(inputSource: LocalInputSource, crop: C
|
|
|
15
15
|
* @param quality JPEG quality of extracted images.
|
|
16
16
|
* @return a list of extracted files, as a CropFiles object.
|
|
17
17
|
*/
|
|
18
|
-
export declare function
|
|
18
|
+
export declare function extractMultipleCrops(inputSource: LocalInputSource, crops: CropItem[], quality?: number): Promise<ExtractedImages>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { MindeeError } from "../../errors/index.js";
|
|
2
2
|
import { extractImagesFromPolygon } from "../../image/imageExtractor.js";
|
|
3
|
-
import { CropFiles } from "../../v2/fileOperations/cropFiles.js";
|
|
4
3
|
import { logger } from "../../logger.js";
|
|
5
4
|
/**
|
|
6
5
|
* Extracts a single specified crop from a given input source.
|
|
7
6
|
* @param inputSource Local input source.
|
|
8
7
|
* @param crop Crop to extract.
|
|
8
|
+
* @param quality JPEG quality of extracted image.
|
|
9
9
|
*/
|
|
10
|
-
export async function extractSingleCrop(inputSource, crop) {
|
|
11
|
-
return (await
|
|
10
|
+
export async function extractSingleCrop(inputSource, crop, quality) {
|
|
11
|
+
return (await extractMultipleCrops(inputSource, [crop], quality))[0];
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Extracts a list of crops from a document.
|
|
@@ -17,7 +17,7 @@ export async function extractSingleCrop(inputSource, crop) {
|
|
|
17
17
|
* @param quality JPEG quality of extracted images.
|
|
18
18
|
* @return a list of extracted files, as a CropFiles object.
|
|
19
19
|
*/
|
|
20
|
-
export async function
|
|
20
|
+
export async function extractMultipleCrops(inputSource, crops, quality) {
|
|
21
21
|
if (crops.length === 0) {
|
|
22
22
|
throw new MindeeError("No crop indexes provided.");
|
|
23
23
|
}
|
|
@@ -31,6 +31,5 @@ export async function extractCrops(inputSource, crops, quality) {
|
|
|
31
31
|
}
|
|
32
32
|
polygonsByPage.get(pageId).push(crop.location.polygon);
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
return new CropFiles(...extractedCrops);
|
|
34
|
+
return await extractImagesFromPolygon(inputSource, polygonsByPage, quality);
|
|
36
35
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { LocalInputSource } from "../../input/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ExtractedPdfs } from "../../pdf/extractedPdfs.js";
|
|
3
3
|
/**
|
|
4
4
|
* Extracts a single specified split from a
|
|
5
5
|
* @param inputSource
|
|
6
6
|
* @param split
|
|
7
7
|
*/
|
|
8
|
-
export declare function extractSingleSplit(inputSource: LocalInputSource, split: number[]): Promise<
|
|
8
|
+
export declare function extractSingleSplit(inputSource: LocalInputSource, split: number[]): Promise<ExtractedPdfs>;
|
|
9
9
|
/**
|
|
10
10
|
* Extracts splits as complete PDFs from the document.
|
|
11
11
|
* @param inputSource Local input source.
|
|
@@ -13,7 +13,7 @@ export declare function extractSingleSplit(inputSource: LocalInputSource, split:
|
|
|
13
13
|
* @return a list of extracted files.
|
|
14
14
|
* @throws MindeeError if no indexes are provided.
|
|
15
15
|
*/
|
|
16
|
-
export declare function
|
|
16
|
+
export declare function extractMultipleSplits(inputSource: LocalInputSource, splits: number[][]): Promise<ExtractedPdfs>;
|
|
17
17
|
/**
|
|
18
18
|
* Expands a range of pages into a list of page indexes.
|
|
19
19
|
* @param range start and end of the page range
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { MindeeError } from "../../errors/index.js";
|
|
2
2
|
import { PdfExtractor } from "../../pdf/pdfExtractor.js";
|
|
3
|
-
import { SplitFiles } from "../../v2/fileOperations/splitFiles.js";
|
|
4
3
|
import { logger } from "../../logger.js";
|
|
5
4
|
import { ExtractedPdf } from "../../pdf/extractedPdf.js";
|
|
5
|
+
import { ExtractedPdfs } from "../../pdf/extractedPdfs.js";
|
|
6
6
|
/**
|
|
7
7
|
* Extracts a single specified split from a
|
|
8
8
|
* @param inputSource
|
|
9
9
|
* @param split
|
|
10
10
|
*/
|
|
11
11
|
export async function extractSingleSplit(inputSource, split) {
|
|
12
|
-
return await
|
|
12
|
+
return await extractMultipleSplits(inputSource, [split]);
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Extracts splits as complete PDFs from the document.
|
|
@@ -18,7 +18,7 @@ export async function extractSingleSplit(inputSource, split) {
|
|
|
18
18
|
* @return a list of extracted files.
|
|
19
19
|
* @throws MindeeError if no indexes are provided.
|
|
20
20
|
*/
|
|
21
|
-
export async function
|
|
21
|
+
export async function extractMultipleSplits(inputSource, splits) {
|
|
22
22
|
const pageGroups = splits.filter(e => e.length > 0);
|
|
23
23
|
if (pageGroups.length === 0) {
|
|
24
24
|
throw new MindeeError("No valid split indexes provided.");
|
|
@@ -28,14 +28,14 @@ export async function extractSplits(inputSource, splits) {
|
|
|
28
28
|
const pdfExtractor = new PdfExtractor(inputSource);
|
|
29
29
|
await pdfExtractor.init();
|
|
30
30
|
if (splits.length === 0) {
|
|
31
|
-
return new
|
|
31
|
+
return new ExtractedPdfs();
|
|
32
32
|
}
|
|
33
33
|
const pageCount = await pdfExtractor.getPageCount();
|
|
34
34
|
if (splits.length === 1 && splits[0].at(-1) === pageCount - 1) {
|
|
35
|
-
return new
|
|
35
|
+
return new ExtractedPdfs(new ExtractedPdf(inputSource.fileObject, inputSource.filename, splits[0]));
|
|
36
36
|
}
|
|
37
37
|
const subDocuments = await pdfExtractor.extractSubDocuments(pageGroups);
|
|
38
|
-
return new
|
|
38
|
+
return new ExtractedPdfs(...subDocuments);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Expands a range of pages into a list of page indexes.
|