mindee 5.5.0 → 5.6.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 +21 -2
- package/package.json +26 -14
- package/src/geometry/bbox.d.ts +5 -0
- package/src/geometry/bbox.js +1 -0
- package/src/geometry/minMax.d.ts +3 -0
- package/src/geometry/polygonUtils.d.ts +23 -0
- package/src/geometry/polygonUtils.js +23 -0
- package/src/http/baseSettings.d.ts +5 -0
- package/src/http/baseSettings.js +2 -0
- package/src/image/extractedImage.d.ts +4 -0
- package/src/image/extractedImages.d.ts +1 -0
- package/src/image/extractedImages.js +1 -0
- package/src/image/imageCompressor.d.ts +1 -1
- package/src/image/imageExtractor.d.ts +5 -6
- package/src/image/imageExtractor.js +71 -73
- package/src/input/base64Input.d.ts +3 -0
- package/src/input/base64Input.js +3 -0
- package/src/input/bufferInput.d.ts +2 -0
- package/src/input/bufferInput.js +2 -0
- package/src/input/bytesInput.d.ts +3 -0
- package/src/input/bytesInput.js +3 -0
- package/src/input/inputSource.d.ts +15 -0
- package/src/input/inputSource.js +15 -0
- package/src/input/localInputSource.d.ts +6 -0
- package/src/input/localInputSource.js +3 -0
- package/src/input/pathInput.d.ts +4 -0
- package/src/input/pathInput.js +3 -0
- package/src/input/streamInput.d.ts +4 -0
- package/src/input/streamInput.js +4 -0
- package/src/input/urlInput.d.ts +12 -0
- package/src/input/urlInput.js +52 -10
- package/src/logger.js +1 -1
- package/src/parsing/dateParser.d.ts +4 -0
- package/src/parsing/dateParser.js +5 -1
- package/src/parsing/localResponseBase.d.ts +2 -0
- package/src/parsing/localResponseBase.js +2 -0
- package/src/parsing/stringDict.d.ts +1 -0
- package/src/pdf/extractedPdf.d.ts +5 -0
- package/src/pdf/extractedPdf.js +1 -0
- package/src/pdf/extractedPdfs.d.ts +1 -0
- package/src/pdf/extractedPdfs.js +1 -0
- package/src/pdf/pdfCompressor.js +12 -0
- package/src/pdf/pdfExtractor.js +3 -0
- package/src/pdf/pdfOperation.d.ts +3 -0
- package/src/pdf/pdfOperation.js +3 -0
- package/src/pdf/pdfUtils.js +5 -0
- package/src/v1/cli.d.ts +3 -0
- package/src/v1/cli.js +84 -26
- package/src/v1/client.d.ts +16 -16
- package/src/v1/extraction/invoiceSplitterExtractor/extractedInvoiceSplitterImage.d.ts +2 -0
- package/src/v1/extraction/invoiceSplitterExtractor/invoiceSplitterExtractor.js +14 -0
- package/src/v1/extraction/multiReceiptsExtractor/extractedMultiReceiptImage.d.ts +2 -0
- package/src/v1/extraction/multiReceiptsExtractor/multiReceiptsExtractor.js +3 -0
- package/src/v1/http/apiSettingsV1.d.ts +5 -0
- package/src/v1/http/apiSettingsV1.js +4 -0
- package/src/v1/http/errors.d.ts +7 -1
- package/src/v1/http/errors.js +65 -86
- package/src/v1/http/httpParams.d.ts +12 -0
- package/src/v1/parsing/common/asyncPredictResponse.d.ts +4 -0
- package/src/v1/parsing/common/asyncPredictResponse.js +5 -2
- package/src/v1/parsing/common/executionPriority.d.ts +4 -0
- package/src/v1/parsing/common/executionPriority.js +4 -0
- package/src/v1/parsing/common/extras/cropperExtra.d.ts +2 -0
- package/src/v1/parsing/common/extras/cropperExtra.js +3 -0
- package/src/v1/parsing/common/extras/extras.d.ts +3 -0
- package/src/v1/parsing/common/extras/extras.js +2 -0
- package/src/v1/parsing/common/extras/fullTextOcrExtra.d.ts +3 -0
- package/src/v1/parsing/common/extras/fullTextOcrExtra.js +1 -0
- package/src/v1/parsing/common/extras/ragExtra.d.ts +1 -0
- package/src/v1/parsing/common/extras/ragExtra.js +1 -0
- package/src/v1/parsing/common/feedback/feedbackResponse.js +1 -0
- package/src/v1/parsing/common/index.d.ts +1 -1
- package/src/v1/parsing/common/index.js +1 -1
- package/src/v1/parsing/common/inference.d.ts +2 -0
- package/src/v1/parsing/common/inference.js +2 -0
- package/src/v1/parsing/common/prediction.d.ts +1 -0
- package/src/v1/parsing/common/prediction.js +1 -0
- package/src/v1/parsing/common/summaryHelper.d.ts +12 -1
- package/src/v1/parsing/common/summaryHelper.js +18 -1
- package/src/v1/parsing/generated/generatedObject.d.ts +6 -0
- package/src/v1/parsing/generated/generatedObject.js +38 -27
- package/src/v1/parsing/localResponse.d.ts +1 -0
- package/src/v1/parsing/localResponse.js +1 -0
- package/src/v1/parsing/standard/base.d.ts +6 -0
- package/src/v1/parsing/standard/base.js +1 -0
- package/src/v1/parsing/standard/boolean.d.ts +1 -1
- package/src/v1/parsing/standard/companyRegistration.d.ts +1 -0
- package/src/v1/parsing/standard/companyRegistration.js +1 -0
- package/src/v1/parsing/standard/date.d.ts +1 -0
- package/src/v1/parsing/standard/date.js +1 -0
- package/src/v1/parsing/standard/paymentDetails.d.ts +5 -5
- package/src/v1/parsing/standard/position.d.ts +2 -2
- package/src/v1/parsing/standard/tax.d.ts +1 -0
- package/src/v1/parsing/standard/tax.js +1 -0
- package/src/v1/parsing/standard/text.d.ts +1 -1
- package/src/v1/parsing/standard/word.d.ts +3 -0
- package/src/v1/parsing/standard/word.js +1 -0
- package/src/v1/product/financialDocument/financialDocumentV1LineItem.js +16 -58
- package/src/v1/product/generated/generatedV1Prediction.d.ts +1 -0
- package/src/v1/product/generated/generatedV1Prediction.js +2 -1
- package/src/v1/product/invoice/invoiceV4LineItem.js +5 -16
- package/src/v1/product/receipt/receiptV5LineItem.js +2 -6
- package/src/v1/product/resume/resumeV1Certificate.js +5 -21
- package/src/v1/product/resume/resumeV1Education.js +8 -36
- package/src/v1/product/resume/resumeV1Language.js +3 -11
- package/src/v1/product/resume/resumeV1ProfessionalExperience.js +10 -46
- package/src/v1/product/resume/resumeV1SocialNetworksUrl.js +3 -11
- package/src/v2/cli.d.ts +3 -0
- package/src/v2/cli.js +21 -0
- package/src/v2/client.d.ts +1 -0
- package/src/v2/client.js +1 -0
- package/src/v2/clientOptions/pollingOptions.d.ts +5 -0
- package/src/v2/clientOptions/pollingOptions.js +2 -0
- package/src/v2/parsing/baseResponse.d.ts +2 -0
- package/src/v2/parsing/baseResponse.js +1 -0
- package/src/v2/parsing/error/errorDetails.d.ts +1 -0
- package/src/v2/parsing/index.d.ts +1 -1
- package/src/v2/parsing/index.js +1 -1
- package/src/v2/parsing/inference/baseInference.d.ts +2 -0
- package/src/v2/parsing/inference/baseInference.js +2 -0
- package/src/v2/parsing/inference/failedInferenceResponse.d.ts +33 -0
- package/src/v2/parsing/inference/failedInferenceResponse.js +17 -0
- package/src/v2/parsing/inference/field/baseField.d.ts +3 -0
- package/src/v2/parsing/inference/field/fieldConfidence.d.ts +4 -0
- package/src/v2/parsing/inference/field/fieldConfidence.js +4 -0
- package/src/v2/parsing/inference/field/fieldFactory.d.ts +5 -0
- package/src/v2/parsing/inference/field/fieldFactory.js +5 -0
- package/src/v2/parsing/inference/field/fieldLocation.d.ts +1 -0
- package/src/v2/parsing/inference/field/fieldLocation.js +1 -0
- package/src/v2/parsing/inference/field/inferenceFields.d.ts +5 -0
- package/src/v2/parsing/inference/field/inferenceFields.js +4 -0
- package/src/v2/parsing/inference/field/listField.d.ts +2 -0
- package/src/v2/parsing/inference/field/listField.js +2 -0
- package/src/v2/parsing/inference/field/objectField.d.ts +4 -0
- package/src/v2/parsing/inference/field/objectField.js +3 -0
- package/src/v2/parsing/inference/field/ragMetadata.d.ts +1 -0
- package/src/v2/parsing/inference/field/ragMetadata.js +1 -0
- package/src/v2/parsing/inference/field/rawText.d.ts +2 -0
- package/src/v2/parsing/inference/field/rawText.js +2 -0
- package/src/v2/parsing/inference/field/simpleField.d.ts +2 -0
- package/src/v2/parsing/inference/field/simpleField.js +2 -0
- package/src/v2/parsing/inference/inferenceFile.d.ts +2 -0
- package/src/v2/parsing/inference/inferenceFile.js +2 -0
- package/src/v2/parsing/inference/inferenceModel.d.ts +2 -0
- package/src/v2/parsing/inference/inferenceModel.js +2 -0
- package/src/v2/parsing/job/job.d.ts +1 -1
- package/src/v2/parsing/job/job.js +1 -3
- package/src/v2/parsing/job/jobResponse.d.ts +3 -0
- package/src/v2/parsing/job/jobResponse.js +3 -0
- package/src/v2/product/classification/classification.d.ts +3 -0
- package/src/v2/product/classification/classification.js +3 -0
- package/src/v2/product/classification/classificationClassifier.d.ts +2 -0
- package/src/v2/product/classification/classificationClassifier.js +2 -0
- package/src/v2/product/classification/classificationInference.d.ts +2 -0
- package/src/v2/product/classification/classificationInference.js +2 -0
- package/src/v2/product/classification/classificationResponse.d.ts +1 -0
- package/src/v2/product/classification/classificationResponse.js +1 -0
- package/src/v2/product/classification/classificationResult.d.ts +2 -0
- package/src/v2/product/classification/classificationResult.js +2 -0
- package/src/v2/product/crop/crop.d.ts +3 -0
- package/src/v2/product/crop/crop.js +3 -0
- package/src/v2/product/crop/cropInference.d.ts +2 -0
- package/src/v2/product/crop/cropInference.js +2 -0
- package/src/v2/product/crop/cropItem.d.ts +2 -0
- package/src/v2/product/crop/cropItem.js +2 -0
- package/src/v2/product/crop/cropResponse.d.ts +1 -0
- package/src/v2/product/crop/cropResponse.js +1 -0
- package/src/v2/product/crop/cropResult.d.ts +2 -0
- package/src/v2/product/crop/cropResult.js +2 -0
- package/src/v2/product/extraction/dataSchemaActiveOption.d.ts +1 -0
- package/src/v2/product/extraction/dataSchemaActiveOption.js +1 -0
- package/src/v2/product/extraction/extraction.d.ts +3 -0
- package/src/v2/product/extraction/extraction.js +3 -0
- package/src/v2/product/extraction/extractionActiveOptions.d.ts +2 -0
- package/src/v2/product/extraction/extractionActiveOptions.js +2 -0
- package/src/v2/product/extraction/extractionInference.d.ts +2 -0
- package/src/v2/product/extraction/extractionInference.js +2 -0
- package/src/v2/product/extraction/extractionResponse.d.ts +1 -0
- package/src/v2/product/extraction/extractionResponse.js +1 -0
- package/src/v2/product/extraction/extractionResult.d.ts +2 -0
- package/src/v2/product/extraction/extractionResult.js +2 -0
- package/src/v2/product/extraction/params/dataSchema.d.ts +9 -6
- package/src/v2/product/extraction/params/dataSchema.js +2 -0
- package/src/v2/product/extraction/params/dataSchemaField.d.ts +25 -1
- package/src/v2/product/extraction/params/dataSchemaField.js +3 -0
- package/src/v2/product/extraction/params/dataSchemaReplace.d.ts +9 -4
- package/src/v2/product/extraction/params/dataSchemaReplace.js +2 -0
- package/src/v2/product/ocr/ocr.d.ts +3 -0
- package/src/v2/product/ocr/ocr.js +3 -0
- package/src/v2/product/ocr/ocrInference.d.ts +2 -0
- package/src/v2/product/ocr/ocrInference.js +2 -0
- package/src/v2/product/ocr/ocrPage.d.ts +2 -0
- package/src/v2/product/ocr/ocrPage.js +2 -0
- package/src/v2/product/ocr/ocrResponse.d.ts +1 -0
- package/src/v2/product/ocr/ocrResponse.js +1 -0
- package/src/v2/product/ocr/ocrResult.d.ts +1 -0
- package/src/v2/product/ocr/ocrResult.js +1 -0
- package/src/v2/product/ocr/ocrWord.d.ts +2 -0
- package/src/v2/product/ocr/ocrWord.js +2 -0
- package/src/v2/product/split/split.d.ts +3 -0
- package/src/v2/product/split/split.js +3 -0
- package/src/v2/product/split/splitInference.d.ts +2 -0
- package/src/v2/product/split/splitInference.js +2 -0
- package/src/v2/product/split/splitRange.d.ts +1 -0
- package/src/v2/product/split/splitRange.js +1 -0
- package/src/v2/product/split/splitResponse.d.ts +1 -0
- package/src/v2/product/split/splitResponse.js +1 -0
- package/src/v2/product/split/splitResult.d.ts +1 -0
- package/src/v2/product/split/splitResult.js +1 -0
package/src/v1/cli.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { PageOptionsOperation, PathInput, } from "../input/index.js";
|
|
1
|
+
import { PageOptionsOperation, PathInput } from "../input/index.js";
|
|
2
|
+
import { Command, Option } from "commander";
|
|
4
3
|
import * as console from "console";
|
|
5
|
-
import {
|
|
4
|
+
import { Client } from "./client.js";
|
|
5
|
+
import { CLI_COMMAND_CONFIG, COMMAND_GENERATED } from "./product/cliProducts.js";
|
|
6
6
|
const program = new Command();
|
|
7
7
|
//
|
|
8
8
|
// EXECUTE THE COMMANDS
|
|
9
9
|
//
|
|
10
|
+
/**
|
|
11
|
+
* Load the client with the given options.
|
|
12
|
+
* @param options Command options.
|
|
13
|
+
*/
|
|
10
14
|
function initClient(options) {
|
|
11
15
|
return new Client({
|
|
12
16
|
apiKey: options.apiKey,
|
|
13
17
|
debug: options.debug,
|
|
14
18
|
});
|
|
15
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Load the product configuration for the given command.
|
|
22
|
+
* @param command Command name.
|
|
23
|
+
*/
|
|
16
24
|
function getConfig(command) {
|
|
17
25
|
const conf = CLI_COMMAND_CONFIG.get(command);
|
|
18
26
|
if (conf === undefined) {
|
|
@@ -20,6 +28,10 @@ function getConfig(command) {
|
|
|
20
28
|
}
|
|
21
29
|
return conf;
|
|
22
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Load the page options for the given command.
|
|
33
|
+
* @param options Command options.
|
|
34
|
+
*/
|
|
23
35
|
function getPageOptions(options) {
|
|
24
36
|
let pageOptions = undefined;
|
|
25
37
|
if (options.cutPages) {
|
|
@@ -31,12 +43,23 @@ function getPageOptions(options) {
|
|
|
31
43
|
}
|
|
32
44
|
return pageOptions;
|
|
33
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Load the prediction parameters for the given command.
|
|
48
|
+
* @param options Command options.
|
|
49
|
+
*/
|
|
34
50
|
function getPredictParams(options) {
|
|
35
51
|
return {
|
|
36
52
|
allWords: options.allWords,
|
|
37
53
|
cropper: options.cropper,
|
|
38
54
|
};
|
|
39
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Call the parse endpoint for the given command.
|
|
58
|
+
* @param productClass Product class.
|
|
59
|
+
* @param command Command name.
|
|
60
|
+
* @param inputPath Input path.
|
|
61
|
+
* @param options Command options.
|
|
62
|
+
*/
|
|
40
63
|
async function callParse(productClass, command, inputPath, options) {
|
|
41
64
|
const mindeeClient = initClient(options);
|
|
42
65
|
const predictParams = getPredictParams(options);
|
|
@@ -61,6 +84,13 @@ async function callParse(productClass, command, inputPath, options) {
|
|
|
61
84
|
}
|
|
62
85
|
printResponse(response.document, options);
|
|
63
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Call the enqueue and parse endpoint for the given command.
|
|
89
|
+
* @param productClass Product class.
|
|
90
|
+
* @param command Command name.
|
|
91
|
+
* @param inputPath Input path.
|
|
92
|
+
* @param options Command options.
|
|
93
|
+
*/
|
|
64
94
|
async function callEnqueueAndParse(productClass, command, inputPath, options) {
|
|
65
95
|
const mindeeClient = initClient(options);
|
|
66
96
|
const predictParams = getPredictParams(options);
|
|
@@ -84,11 +114,22 @@ async function callEnqueueAndParse(productClass, command, inputPath, options) {
|
|
|
84
114
|
}
|
|
85
115
|
printResponse(response.document, options);
|
|
86
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Call the get document endpoint for the given command.
|
|
119
|
+
* @param productClass Product class.
|
|
120
|
+
* @param documentId Document ID.
|
|
121
|
+
* @param options Command options.
|
|
122
|
+
*/
|
|
87
123
|
async function callGetDocument(productClass, documentId, options) {
|
|
88
124
|
const mindeeClient = initClient(options);
|
|
89
125
|
const response = await mindeeClient.getDocument(productClass, documentId);
|
|
90
126
|
printResponse(response.document, options);
|
|
91
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Print the response for the given command.
|
|
130
|
+
* @param document Document.
|
|
131
|
+
* @param options Command options.
|
|
132
|
+
*/
|
|
92
133
|
function printResponse(document, options) {
|
|
93
134
|
if (options.allWords) {
|
|
94
135
|
document.ocr?.mVisionV1.pages.forEach((page) => {
|
|
@@ -107,9 +148,18 @@ function printResponse(document, options) {
|
|
|
107
148
|
//
|
|
108
149
|
// BUILD THE COMMANDS
|
|
109
150
|
//
|
|
151
|
+
/**
|
|
152
|
+
* Add the main options to the given command.
|
|
153
|
+
* @param prog Command.
|
|
154
|
+
*/
|
|
110
155
|
function addMainOptions(prog) {
|
|
111
156
|
prog.option("-k, --api-key <api_key>", "API key for document endpoint");
|
|
112
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Add the post options to the given command.
|
|
160
|
+
* @param prog Command.
|
|
161
|
+
* @param info Product configuration.
|
|
162
|
+
*/
|
|
113
163
|
function addPostOptions(prog, info) {
|
|
114
164
|
prog.option("-c, --cut-pages", "keep only the first 5 pages of the document");
|
|
115
165
|
if (info.allWords) {
|
|
@@ -117,14 +167,28 @@ function addPostOptions(prog, info) {
|
|
|
117
167
|
}
|
|
118
168
|
prog.argument("<input_path>", "full path to the file");
|
|
119
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Add the custom post options to the given command.
|
|
172
|
+
* @param prog Command.
|
|
173
|
+
*/
|
|
120
174
|
function addCustomPostOptions(prog) {
|
|
121
175
|
prog.requiredOption("-e, --endpoint <endpoint_name>", "API endpoint name (required)");
|
|
122
176
|
prog.requiredOption("-a, --account <account_name>", "API account name for the endpoint (required)");
|
|
123
177
|
prog.option("-v, --version <version>", "version for the endpoint, use the latest version if not specified");
|
|
124
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Add the display options to the given command.
|
|
181
|
+
* @param prog Command.
|
|
182
|
+
*/
|
|
125
183
|
function addDisplayOptions(prog) {
|
|
126
184
|
prog.option("-p, --pages", "show content of individual pages");
|
|
127
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Route the command to the appropriate action.
|
|
188
|
+
* @param command Command.
|
|
189
|
+
* @param inputPath Input path.
|
|
190
|
+
* @param allOptions All options.
|
|
191
|
+
*/
|
|
128
192
|
function routeSwitchboard(command, inputPath, allOptions) {
|
|
129
193
|
if (command.parent === null || command.parent === undefined) {
|
|
130
194
|
throw new Error(`Improperly configured command: ${command.name()}`);
|
|
@@ -135,30 +199,24 @@ function routeSwitchboard(command, inputPath, allOptions) {
|
|
|
135
199
|
}
|
|
136
200
|
return callParse(docClass, command.name(), inputPath, allOptions);
|
|
137
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Add the predict action to the given command.
|
|
204
|
+
* @param prog Command.
|
|
205
|
+
*/
|
|
138
206
|
function addPredictAction(prog) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
prog.action(function (inputPath, options, command) {
|
|
152
|
-
const allOptions = {
|
|
153
|
-
...prog.parent?.parent?.opts(),
|
|
154
|
-
...prog.parent?.opts(),
|
|
155
|
-
...prog.opts(),
|
|
156
|
-
...options,
|
|
157
|
-
};
|
|
158
|
-
return routeSwitchboard(command, inputPath, allOptions);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
207
|
+
prog.action(function (inputPath, options, command) {
|
|
208
|
+
const allOptions = {
|
|
209
|
+
...prog.parent?.parent?.opts(),
|
|
210
|
+
...prog.parent?.opts(),
|
|
211
|
+
...prog.opts(),
|
|
212
|
+
...options,
|
|
213
|
+
};
|
|
214
|
+
return routeSwitchboard(command, inputPath, allOptions);
|
|
215
|
+
});
|
|
161
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Add the main CLI action.
|
|
219
|
+
*/
|
|
162
220
|
export function cli() {
|
|
163
221
|
program.name("mindee")
|
|
164
222
|
.description("Command line interface for Mindee products.")
|
package/src/v1/client.d.ts
CHANGED
|
@@ -60,34 +60,34 @@ export interface WorkflowOptions extends BaseOptions {
|
|
|
60
60
|
*/
|
|
61
61
|
publicUrl?: string;
|
|
62
62
|
}
|
|
63
|
+
/** Timer options forwarded to `setTimeout` in polling loops. */
|
|
64
|
+
export interface TimerOptions {
|
|
65
|
+
/** Whether the timer should keep the event loop active. */
|
|
66
|
+
ref?: boolean;
|
|
67
|
+
/** Optional signal used to abort timer waits. */
|
|
68
|
+
signal?: AbortSignal;
|
|
69
|
+
}
|
|
63
70
|
/**
|
|
64
71
|
* Asynchronous polling parameters.
|
|
65
72
|
*/
|
|
66
73
|
export interface OptionalAsyncOptions extends PredictOptions {
|
|
74
|
+
/** Delay in seconds before the first polling attempt. */
|
|
67
75
|
initialDelaySec?: number;
|
|
76
|
+
/** Delay in seconds between polling attempts. */
|
|
68
77
|
delaySec?: number;
|
|
78
|
+
/** Maximum number of polling attempts. */
|
|
69
79
|
maxRetries?: number;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
recurringTimerOptions?: {
|
|
75
|
-
ref?: boolean;
|
|
76
|
-
signal?: AbortSignal;
|
|
77
|
-
};
|
|
80
|
+
/** Timer options used for the first delay. */
|
|
81
|
+
initialTimerOptions?: TimerOptions;
|
|
82
|
+
/** Timer options used for recurring polling delays. */
|
|
83
|
+
recurringTimerOptions?: TimerOptions;
|
|
78
84
|
}
|
|
79
85
|
export interface AsyncOptions extends PredictOptions {
|
|
80
86
|
initialDelaySec: number;
|
|
81
87
|
delaySec: number;
|
|
82
88
|
maxRetries: number;
|
|
83
|
-
initialTimerOptions?:
|
|
84
|
-
|
|
85
|
-
signal?: AbortSignal;
|
|
86
|
-
};
|
|
87
|
-
recurringTimerOptions?: {
|
|
88
|
-
ref?: boolean;
|
|
89
|
-
signal?: AbortSignal;
|
|
90
|
-
};
|
|
89
|
+
initialTimerOptions?: TimerOptions;
|
|
90
|
+
recurringTimerOptions?: TimerOptions;
|
|
91
91
|
}
|
|
92
92
|
export interface ClientOptions {
|
|
93
93
|
/** Your API key for all endpoints. */
|
|
@@ -3,7 +3,9 @@ import { ExtractedPdf } from "../../../pdf/index.js";
|
|
|
3
3
|
* Wrapper class for extracted invoice pages.
|
|
4
4
|
*/
|
|
5
5
|
export declare class ExtractedInvoiceSplitterImage extends ExtractedPdf {
|
|
6
|
+
/** Start page index of the extracted invoice segment. */
|
|
6
7
|
readonly pageIdMin: number;
|
|
8
|
+
/** End page index of the extracted invoice segment. */
|
|
7
9
|
readonly pageIdMax: number;
|
|
8
10
|
constructor(bytes: Uint8Array, pageIndices: [number, number]);
|
|
9
11
|
}
|
|
@@ -3,6 +3,9 @@ import { InvoiceSplitterV1 } from "../../../v1/product/index.js";
|
|
|
3
3
|
import { ExtractedInvoiceSplitterImage } from "../../../v1/extraction/index.js";
|
|
4
4
|
import { loadOptionalDependency } from "../../../dependency/index.js";
|
|
5
5
|
let pdfLib = null;
|
|
6
|
+
/**
|
|
7
|
+
* Load the pdf-lib dependency.
|
|
8
|
+
*/
|
|
6
9
|
async function getPdfLib() {
|
|
7
10
|
if (!pdfLib) {
|
|
8
11
|
const pdfLibImport = await loadOptionalDependency("@cantoo/pdf-lib", "Text Embedding");
|
|
@@ -10,6 +13,12 @@ async function getPdfLib() {
|
|
|
10
13
|
}
|
|
11
14
|
return pdfLib;
|
|
12
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Split the given PDF document into multiple PDF documents.
|
|
18
|
+
* @param pdfDoc PDF document.
|
|
19
|
+
* @param invoicePageGroups Page groups.
|
|
20
|
+
* @returns Extracted invoice splitter images.
|
|
21
|
+
*/
|
|
13
22
|
async function splitPdf(pdfDoc, invoicePageGroups) {
|
|
14
23
|
const pdfLib = await getPdfLib();
|
|
15
24
|
if (invoicePageGroups.length === 0) {
|
|
@@ -31,6 +40,11 @@ async function splitPdf(pdfDoc, invoicePageGroups) {
|
|
|
31
40
|
}
|
|
32
41
|
return generatedPdfs;
|
|
33
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Load the PDF document from the given input file.
|
|
45
|
+
* @param inputFile Input file.
|
|
46
|
+
* @returns PDF document.
|
|
47
|
+
*/
|
|
34
48
|
async function getPdfDoc(inputFile) {
|
|
35
49
|
const pdfLib = await getPdfLib();
|
|
36
50
|
await inputFile.init();
|
|
@@ -3,7 +3,9 @@ import { ExtractedImage } from "../../../image/index.js";
|
|
|
3
3
|
* Wrapper class for extracted multiple-receipts images.
|
|
4
4
|
*/
|
|
5
5
|
export declare class ExtractedMultiReceiptImage extends ExtractedImage {
|
|
6
|
+
/** Receipt index within the source page. */
|
|
6
7
|
readonly receiptId: number;
|
|
8
|
+
/** Source page identifier. */
|
|
7
9
|
readonly pageId: number;
|
|
8
10
|
constructor(buffer: Uint8Array, pageId: number, receiptId: number);
|
|
9
11
|
}
|
|
@@ -4,6 +4,9 @@ import { ExtractedMultiReceiptImage } from "../../../v1/extraction/index.js";
|
|
|
4
4
|
import { extractFromPage } from "../../../image/index.js";
|
|
5
5
|
import { loadOptionalDependency } from "../../../dependency/index.js";
|
|
6
6
|
let pdfLib = null;
|
|
7
|
+
/**
|
|
8
|
+
* Load the pdf-lib dependency.
|
|
9
|
+
*/
|
|
7
10
|
async function getPdfLib() {
|
|
8
11
|
if (!pdfLib) {
|
|
9
12
|
const pdfLibImport = await loadOptionalDependency("@cantoo/pdf-lib", "Text Embedding");
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { BaseSettings, MindeeApiConstructorProps } from "../../http/baseSettings.js";
|
|
2
|
+
/** Default account owner for built-in v1 APIs. */
|
|
2
3
|
export declare const STANDARD_API_OWNER: string;
|
|
4
|
+
/** Runtime settings container for v1 API calls. */
|
|
3
5
|
export declare class ApiSettingsV1 extends BaseSettings {
|
|
6
|
+
/** Default headers sent with each v1 API request. */
|
|
4
7
|
baseHeaders: Record<string, string>;
|
|
5
8
|
constructor({ apiKey, dispatcher, }: MindeeApiConstructorProps);
|
|
9
|
+
/** Resolves the API key from environment variables. */
|
|
6
10
|
protected apiKeyFromEnv(): string;
|
|
11
|
+
/** Resolves the API hostname from environment variables. */
|
|
7
12
|
protected hostnameFromEnv(): string;
|
|
8
13
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { logger } from "../../logger.js";
|
|
2
2
|
import { BaseSettings } from "../../http/baseSettings.js";
|
|
3
3
|
import { MindeeConfigurationError } from "../../errors/index.js";
|
|
4
|
+
/** Default account owner for built-in v1 APIs. */
|
|
4
5
|
export const STANDARD_API_OWNER = "mindee";
|
|
5
6
|
const API_V1_KEY_ENVVAR_NAME = "MINDEE_API_KEY";
|
|
6
7
|
const API_V1_HOST_ENVVAR_NAME = "MINDEE_API_HOST";
|
|
7
8
|
const DEFAULT_MINDEE_API_HOST = "api.mindee.net";
|
|
9
|
+
/** Runtime settings container for v1 API calls. */
|
|
8
10
|
export class ApiSettingsV1 extends BaseSettings {
|
|
9
11
|
constructor({ apiKey, dispatcher, }) {
|
|
10
12
|
super(apiKey, dispatcher);
|
|
@@ -18,6 +20,7 @@ export class ApiSettingsV1 extends BaseSettings {
|
|
|
18
20
|
Authorization: `Token ${this.apiKey}`,
|
|
19
21
|
};
|
|
20
22
|
}
|
|
23
|
+
/** Resolves the API key from environment variables. */
|
|
21
24
|
apiKeyFromEnv() {
|
|
22
25
|
const envVarValue = process.env[API_V1_KEY_ENVVAR_NAME];
|
|
23
26
|
if (envVarValue) {
|
|
@@ -26,6 +29,7 @@ export class ApiSettingsV1 extends BaseSettings {
|
|
|
26
29
|
}
|
|
27
30
|
return "";
|
|
28
31
|
}
|
|
32
|
+
/** Resolves the API hostname from environment variables. */
|
|
29
33
|
hostnameFromEnv() {
|
|
30
34
|
const envVarValue = process.env[API_V1_HOST_ENVVAR_NAME];
|
|
31
35
|
if (envVarValue) {
|
package/src/v1/http/errors.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { MindeeError } from "../../errors/index.js";
|
|
2
2
|
import { StringDict } from "../../parsing/stringDict.js";
|
|
3
|
-
import { BaseHttpResponse } from "../../http/
|
|
3
|
+
import { BaseHttpResponse } from "../../http/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Handle the given error.
|
|
6
|
+
* @param urlName URL name.
|
|
7
|
+
* @param response Response.
|
|
8
|
+
* @param serverError Server error.
|
|
9
|
+
*/
|
|
4
10
|
export declare function handleError(urlName: string, response: BaseHttpResponse, serverError?: string): void;
|
|
5
11
|
/**
|
|
6
12
|
* `Error` wrapper for server (HTTP) errors.
|
package/src/v1/http/errors.js
CHANGED
|
@@ -1,109 +1,80 @@
|
|
|
1
1
|
import { MindeeError } from "../../errors/index.js";
|
|
2
2
|
import { errorHandler } from "../../errors/handler.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const HTML_ERROR_PATTERNS = [
|
|
4
|
+
["Maximum pdf pages", { message: "TooManyPages", details: "Maximum amount of pdf pages reached." }],
|
|
5
|
+
["Max file size is", { message: "FileTooLarge", details: "Maximum file size reached." }],
|
|
6
|
+
["Invalid file type", { message: "InvalidFiletype", details: "Invalid file type." }],
|
|
7
|
+
["Gateway timeout", { message: "RequestTimeout", details: "Request timed out." }],
|
|
8
|
+
["Bad gateway", { message: "BadRequest", details: "Bad Gateway" }],
|
|
9
|
+
["Too Many Requests", { message: "TooManyRequests", details: "Too Many Requests." }],
|
|
10
|
+
];
|
|
11
|
+
const ERROR_CLASSES_BY_CODE = new Map();
|
|
12
|
+
/**
|
|
13
|
+
* Extract the status code from the given response.
|
|
14
|
+
* @param response Response.
|
|
15
|
+
* @returns Status code.
|
|
16
|
+
*/
|
|
17
|
+
function extractStatusCode(response) {
|
|
5
18
|
try {
|
|
6
19
|
if (response.data.api_request["status_code"] === 200 && response.data?.job?.error?.code) {
|
|
7
|
-
code = 500;
|
|
8
20
|
response.data.api_request.error = response.data.job.error;
|
|
21
|
+
return 500;
|
|
9
22
|
}
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
if (response.data) {
|
|
24
|
+
return response.data.api_request["status_code"];
|
|
12
25
|
}
|
|
13
26
|
}
|
|
14
27
|
catch {
|
|
15
|
-
|
|
28
|
+
return 500;
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Extract the error object from an HTML error response body.
|
|
34
|
+
* @param reconstructed Reconstructed response body.
|
|
35
|
+
* @returns Error object.
|
|
36
|
+
*/
|
|
37
|
+
function errorObjFromHtml(reconstructed) {
|
|
38
|
+
for (const [needle, obj] of HTML_ERROR_PATTERNS) {
|
|
39
|
+
if (reconstructed.includes(needle)) {
|
|
40
|
+
return { ...obj };
|
|
41
|
+
}
|
|
16
42
|
}
|
|
17
|
-
|
|
43
|
+
return { message: "Unknown Server Error.", details: reconstructed };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Extract the error object from the given response.
|
|
47
|
+
* @param response Response.
|
|
48
|
+
* @returns Error object.
|
|
49
|
+
*/
|
|
50
|
+
function extractErrorObj(response) {
|
|
18
51
|
try {
|
|
19
|
-
//Regular instances where the returned error is in JSON format.
|
|
20
|
-
|
|
52
|
+
// Regular instances where the returned error is in JSON format.
|
|
53
|
+
return response.data.api_request.error;
|
|
21
54
|
}
|
|
22
55
|
catch {
|
|
23
|
-
//Rare instances where errors are returned as HTML instead of JSON.
|
|
56
|
+
// Rare instances where errors are returned as HTML instead of JSON.
|
|
24
57
|
if (!("reconstructedResponse" in response.data)) {
|
|
25
58
|
response.data.reconstructedResponse = "";
|
|
26
59
|
}
|
|
27
|
-
|
|
28
|
-
errorObj = {
|
|
29
|
-
message: "TooManyPages",
|
|
30
|
-
details: "Maximum amount of pdf pages reached.",
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
else if (response.data.reconstructedResponse.includes("Max file size is")) {
|
|
34
|
-
errorObj = {
|
|
35
|
-
message: "FileTooLarge",
|
|
36
|
-
details: "Maximum file size reached.",
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
else if (response.data.reconstructedResponse.includes("Invalid file type")) {
|
|
40
|
-
errorObj = {
|
|
41
|
-
message: "InvalidFiletype",
|
|
42
|
-
details: "Invalid file type.",
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
else if (response.data.reconstructedResponse.includes("Gateway timeout")) {
|
|
46
|
-
errorObj = {
|
|
47
|
-
message: "RequestTimeout",
|
|
48
|
-
details: "Request timed out.",
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
else if (response.data.reconstructedResponse.includes("Bad gateway")) {
|
|
52
|
-
errorObj = {
|
|
53
|
-
message: "BadRequest",
|
|
54
|
-
details: "Bad Gateway",
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
else if (response.data.reconstructedResponse.includes("Too Many Requests")) {
|
|
58
|
-
errorObj = {
|
|
59
|
-
message: "TooManyRequests",
|
|
60
|
-
details: "Too Many Requests.",
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
errorObj = {
|
|
65
|
-
message: "Unknown Server Error.",
|
|
66
|
-
details: response.data.reconstructedResponse,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
60
|
+
return errorObjFromHtml(response.data.reconstructedResponse);
|
|
69
61
|
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Handle the given error.
|
|
65
|
+
* @param urlName URL name.
|
|
66
|
+
* @param response Response.
|
|
67
|
+
* @param serverError Server error.
|
|
68
|
+
*/
|
|
69
|
+
export function handleError(urlName, response, serverError) {
|
|
70
|
+
const code = extractStatusCode(response);
|
|
71
|
+
const errorObj = extractErrorObj(response);
|
|
70
72
|
if (serverError !== undefined &&
|
|
71
|
-
(!("message" in errorObj) ||
|
|
72
|
-
!errorObj.message ||
|
|
73
|
-
errorObj.message.length === 0)) {
|
|
73
|
+
(!("message" in errorObj) || !errorObj.message || errorObj.message.length === 0)) {
|
|
74
74
|
errorObj.message = serverError;
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
case 400:
|
|
79
|
-
errorToThrow = new MindeeHttp400Error(errorObj, urlName, code);
|
|
80
|
-
break;
|
|
81
|
-
case 401:
|
|
82
|
-
errorToThrow = new MindeeHttp401Error(errorObj, urlName, code);
|
|
83
|
-
break;
|
|
84
|
-
case 403:
|
|
85
|
-
errorToThrow = new MindeeHttp403Error(errorObj, urlName, code);
|
|
86
|
-
break;
|
|
87
|
-
case 404:
|
|
88
|
-
errorToThrow = new MindeeHttp404Error(errorObj, urlName, code);
|
|
89
|
-
break;
|
|
90
|
-
case 413:
|
|
91
|
-
errorToThrow = new MindeeHttp413Error(errorObj, urlName, code);
|
|
92
|
-
break;
|
|
93
|
-
case 429:
|
|
94
|
-
errorToThrow = new MindeeHttp429Error(errorObj, urlName, code);
|
|
95
|
-
break;
|
|
96
|
-
case 500:
|
|
97
|
-
errorToThrow = new MindeeHttp500Error(errorObj, urlName, code);
|
|
98
|
-
break;
|
|
99
|
-
case 504:
|
|
100
|
-
errorToThrow = new MindeeHttp504Error(errorObj, urlName, code);
|
|
101
|
-
break;
|
|
102
|
-
default:
|
|
103
|
-
errorToThrow = new MindeeHttpErrorV1(errorObj, urlName, code);
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
errorHandler.throw(errorToThrow);
|
|
76
|
+
const errorClass = (code !== undefined && ERROR_CLASSES_BY_CODE.get(code)) || MindeeHttpErrorV1;
|
|
77
|
+
errorHandler.throw(new errorClass(errorObj, urlName, code));
|
|
107
78
|
}
|
|
108
79
|
/**
|
|
109
80
|
* `Error` wrapper for server (HTTP) errors.
|
|
@@ -196,3 +167,11 @@ export class MindeeHttp504Error extends MindeeHttpErrorV1 {
|
|
|
196
167
|
this.name = "MindeeHttp504Error";
|
|
197
168
|
}
|
|
198
169
|
}
|
|
170
|
+
ERROR_CLASSES_BY_CODE.set(400, MindeeHttp400Error);
|
|
171
|
+
ERROR_CLASSES_BY_CODE.set(401, MindeeHttp401Error);
|
|
172
|
+
ERROR_CLASSES_BY_CODE.set(403, MindeeHttp403Error);
|
|
173
|
+
ERROR_CLASSES_BY_CODE.set(404, MindeeHttp404Error);
|
|
174
|
+
ERROR_CLASSES_BY_CODE.set(413, MindeeHttp413Error);
|
|
175
|
+
ERROR_CLASSES_BY_CODE.set(429, MindeeHttp429Error);
|
|
176
|
+
ERROR_CLASSES_BY_CODE.set(500, MindeeHttp500Error);
|
|
177
|
+
ERROR_CLASSES_BY_CODE.set(504, MindeeHttp504Error);
|
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
import { InputSource, PageOptions } from "../../input/index.js";
|
|
2
2
|
import { ExecutionPriority } from "../../v1/parsing/common/index.js";
|
|
3
3
|
interface HTTPParams {
|
|
4
|
+
/** Input source to submit to the API. */
|
|
4
5
|
inputDoc: InputSource;
|
|
6
|
+
/** Enables full-text OCR output when supported. */
|
|
5
7
|
fullText: boolean;
|
|
8
|
+
/** Optional local page filtering options applied before upload. */
|
|
6
9
|
pageOptions?: PageOptions;
|
|
10
|
+
/** Enables Retrieval-Augmented Generation when supported. */
|
|
7
11
|
rag?: boolean;
|
|
8
12
|
}
|
|
13
|
+
/** Parameters sent to synchronous/asynchronous prediction endpoints. */
|
|
9
14
|
export interface PredictParams extends HTTPParams {
|
|
15
|
+
/** Enables word-level OCR details in the response. */
|
|
10
16
|
includeWords: boolean;
|
|
17
|
+
/** Enables cropper extras in the response. */
|
|
11
18
|
cropper: boolean;
|
|
19
|
+
/** Optional workflow ID used for workflow-backed inference. */
|
|
12
20
|
workflowId?: string;
|
|
13
21
|
}
|
|
22
|
+
/** Parameters sent to workflow execution endpoints. */
|
|
14
23
|
export interface WorkflowParams extends HTTPParams {
|
|
24
|
+
/** Custom alias assigned to the submitted file. */
|
|
15
25
|
alias?: string;
|
|
26
|
+
/** Processing priority of the workflow execution. */
|
|
16
27
|
priority?: ExecutionPriority;
|
|
28
|
+
/** Whether to request a public validation URL. */
|
|
17
29
|
publicUrl?: string;
|
|
18
30
|
}
|
|
19
31
|
export {};
|
|
@@ -22,6 +22,10 @@ export declare class Job {
|
|
|
22
22
|
milliSecsTaken?: number;
|
|
23
23
|
constructor(jsonResponse: StringDict);
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse a date string into UTC.
|
|
27
|
+
* @param date Date string.
|
|
28
|
+
*/
|
|
25
29
|
export declare function datetimeWithTimezone(date: string): Date;
|
|
26
30
|
/** Wrapper for asynchronous jobs and parsing results.
|
|
27
31
|
*
|
|
@@ -20,9 +20,12 @@ export class Job {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Parse a date string into UTC.
|
|
25
|
+
* @param date Date string.
|
|
26
|
+
*/
|
|
24
27
|
export function datetimeWithTimezone(date) {
|
|
25
|
-
if (date.search(
|
|
28
|
+
if (date.search(/\+\d{2}:\d{2}$/) === -1) {
|
|
26
29
|
date += "+00:00";
|
|
27
30
|
}
|
|
28
31
|
return new Date(date);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
/** Execution priority levels available for workflow requests. */
|
|
1
2
|
export declare enum ExecutionPriority {
|
|
3
|
+
/** Low-priority background processing. */
|
|
2
4
|
low = "low",
|
|
5
|
+
/** Standard processing priority. */
|
|
3
6
|
medium = "medium",
|
|
7
|
+
/** High-priority processing. */
|
|
4
8
|
high = "high"
|
|
5
9
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
/** Execution priority levels available for workflow requests. */
|
|
1
2
|
export var ExecutionPriority;
|
|
2
3
|
(function (ExecutionPriority) {
|
|
4
|
+
/** Low-priority background processing. */
|
|
3
5
|
ExecutionPriority["low"] = "low";
|
|
6
|
+
/** Standard processing priority. */
|
|
4
7
|
ExecutionPriority["medium"] = "medium";
|
|
8
|
+
/** High-priority processing. */
|
|
5
9
|
ExecutionPriority["high"] = "high";
|
|
6
10
|
})(ExecutionPriority || (ExecutionPriority = {}));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { PositionField } from "../../../../v1/parsing/standard/position.js";
|
|
2
2
|
import { StringDict } from "../../../../parsing/stringDict.js";
|
|
3
3
|
import { ExtraField } from "./extras.js";
|
|
4
|
+
/** Cropper extra payload returned by compatible APIs. */
|
|
4
5
|
export declare class CropperExtra extends ExtraField {
|
|
6
|
+
/** Cropped regions detected on the page. */
|
|
5
7
|
cropping: PositionField[];
|
|
6
8
|
constructor(rawPrediction: StringDict, pageId?: number);
|
|
7
9
|
/**
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { PositionField } from "../../../../v1/parsing/standard/position.js";
|
|
2
|
+
// eslint-disable-next-line no-restricted-imports
|
|
2
3
|
import { cleanOutString } from "../summaryHelper.js";
|
|
3
4
|
import { ExtraField } from "./extras.js";
|
|
5
|
+
/** Cropper extra payload returned by compatible APIs. */
|
|
4
6
|
export class CropperExtra extends ExtraField {
|
|
5
7
|
constructor(rawPrediction, pageId) {
|
|
6
8
|
super();
|
|
9
|
+
/** Cropped regions detected on the page. */
|
|
7
10
|
this.cropping = [];
|
|
8
11
|
if (rawPrediction["cropping"] !== undefined) {
|
|
9
12
|
rawPrediction["cropping"].forEach((crop) => {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
/** Base class for optional extras attached to predictions. */
|
|
1
2
|
export declare abstract class ExtraField {
|
|
2
3
|
}
|
|
3
4
|
interface ExtraDict<T extends ExtraField> {
|
|
4
5
|
[key: string]: T | (() => string);
|
|
5
6
|
}
|
|
7
|
+
/** Dictionary-like container for extra fields. */
|
|
6
8
|
export declare class Extras<ExtraT extends ExtraField = ExtraField> implements ExtraDict<ExtraT> {
|
|
9
|
+
/** Dynamic map of extra values keyed by extra name. */
|
|
7
10
|
[key: string]: ExtraT | (() => string);
|
|
8
11
|
constructor(fields: Record<string, ExtraT>);
|
|
9
12
|
/**
|