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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Mindee Node.js API Library Changelog
|
|
2
2
|
|
|
3
|
+
## v5.6.1 - 2026-08-19
|
|
4
|
+
### Changes
|
|
5
|
+
* :arrow_up: security updates
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## v5.6.0 - 2026-07-21
|
|
9
|
+
### Changes
|
|
10
|
+
* :sparkles: add support for webhook errors
|
|
11
|
+
* :arrow_up: add husky
|
|
12
|
+
* :arrow_up: add eslint rules
|
|
13
|
+
* :arrow_up: add direct license checker
|
|
14
|
+
* :recycle: replace dashes with colons in package.json script commands
|
|
15
|
+
* :wrench: add secretlint
|
|
16
|
+
* :wrench: :coffin: remove support for mocha
|
|
17
|
+
### Fixes
|
|
18
|
+
* :arrow_up: bump dependencies
|
|
19
|
+
|
|
20
|
+
|
|
3
21
|
## v5.5.0 - 2026-07-01
|
|
4
22
|
### Fixes
|
|
5
23
|
* :memo: minor tweak to SKILL file
|
|
@@ -85,7 +103,7 @@
|
|
|
85
103
|
|
|
86
104
|
|
|
87
105
|
## v5.0.0-rc1 - 2026-02-17
|
|
88
|
-
### Changes
|
|
106
|
+
### ¡Breaking Changes!
|
|
89
107
|
* :boom: drop support for node.js 18
|
|
90
108
|
* :boom: :recycle: separate polling options
|
|
91
109
|
|
|
@@ -99,7 +117,8 @@
|
|
|
99
117
|
|
|
100
118
|
|
|
101
119
|
## v5.0.0-alpha1 - 2026-02-13
|
|
102
|
-
###
|
|
120
|
+
### ¡Breaking Changes!
|
|
121
|
+
* :boom: :recycle: base for v5
|
|
103
122
|
* :arrow_up: update file-type
|
|
104
123
|
* :recycle: migrate to ES modules (node18)
|
|
105
124
|
* :coffin: remove support for obsolete/unused products:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.1",
|
|
4
4
|
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Mindee",
|
|
@@ -24,17 +24,23 @@
|
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsc --build && tsc-alias",
|
|
27
|
-
"build
|
|
27
|
+
"build:dist": "tsc --build && tsc-alias && cp LICENSE README.md CHANGELOG.md ./dist",
|
|
28
28
|
"clean": "rm -rf ./dist ./docs/_build",
|
|
29
|
-
"test": "
|
|
30
|
-
"test
|
|
31
|
-
"test
|
|
32
|
-
"test
|
|
33
|
-
"test
|
|
29
|
+
"test": "node tests/runner.mjs spec",
|
|
30
|
+
"test:light": "node tests/runner.mjs spec",
|
|
31
|
+
"test:integration": "node tests/runner.mjs integration",
|
|
32
|
+
"test:integration:light": "node tests/runner.mjs integration",
|
|
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
|
|
35
|
+
"lint:check": "npm run lint",
|
|
36
|
+
"lint:fix": "tsc --noEmit && eslint --fix --report-unused-disable-directives './src/**/*.ts' './tests/**/*.ts'",
|
|
37
|
+
"lint:package": "npm run build:dist && publint ./dist && attw --pack ./dist --profile esm-only",
|
|
38
|
+
"lint:secrets": "secretlint '**/*'",
|
|
39
|
+
"lint:full": "npm run lint:check && npm run lint:package && npm run lint:secrets",
|
|
40
|
+
"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\"",
|
|
36
41
|
"docs": "typedoc --out docs/_build ./src/index.ts",
|
|
37
|
-
"docs
|
|
42
|
+
"docs:dist": "typedoc --out docs/_build ./src/index.ts && cp -r ./docs/code_samples ./docs/_build/",
|
|
43
|
+
"prepare": "husky"
|
|
38
44
|
},
|
|
39
45
|
"files": [
|
|
40
46
|
"src/*",
|
|
@@ -56,21 +62,27 @@
|
|
|
56
62
|
"@cantoo/pdf-lib": "^2.5.3",
|
|
57
63
|
"node-poppler": "^9.1.1",
|
|
58
64
|
"pdf.js-extract": "~0.2.1",
|
|
59
|
-
"sharp": "
|
|
65
|
+
"sharp": "^0.35.3"
|
|
60
66
|
},
|
|
61
67
|
"devDependencies": {
|
|
68
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
62
69
|
"@eslint/eslintrc": "^3.3.5",
|
|
63
70
|
"@eslint/js": "^10.0.1",
|
|
64
|
-
"@
|
|
71
|
+
"@secretlint/secretlint-rule-preset-recommend": "^13.0.4",
|
|
65
72
|
"@types/node": "^20.19.37",
|
|
66
73
|
"@types/tmp": "^0.2.6",
|
|
67
74
|
"@typescript-eslint/eslint-plugin": "^8.57.0",
|
|
68
75
|
"@typescript-eslint/parser": "^8.58.1",
|
|
69
|
-
"eslint": "^10.0
|
|
76
|
+
"eslint": "^10.6.0",
|
|
70
77
|
"eslint-plugin-jsdoc": "^62.7.1",
|
|
78
|
+
"eslint-plugin-security": "^4.0.1",
|
|
79
|
+
"eslint-plugin-sonarjs": "^4.2.0",
|
|
71
80
|
"globals": "^17.4.0",
|
|
72
|
-
"
|
|
73
|
-
"
|
|
81
|
+
"husky": "^9.1.7",
|
|
82
|
+
"license-checker-rseidelsohn": "^4.4.2",
|
|
83
|
+
"publint": "^0.3.22",
|
|
84
|
+
"secretlint": "^13.0.4",
|
|
85
|
+
"tsc-alias": "^1.8.17",
|
|
74
86
|
"tslib": "^2.8.1",
|
|
75
87
|
"tsx": "^4.21.0",
|
|
76
88
|
"typedoc": "^0.28.18",
|
package/src/geometry/bbox.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/** A simple bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */
|
|
2
2
|
export declare class BBox {
|
|
3
|
+
/** Minimum X coordinate. */
|
|
3
4
|
xMin: number;
|
|
5
|
+
/** Minimum Y coordinate. */
|
|
4
6
|
yMin: number;
|
|
7
|
+
/** Maximum X coordinate. */
|
|
5
8
|
xMax: number;
|
|
9
|
+
/** Maximum Y coordinate. */
|
|
6
10
|
yMax: number;
|
|
7
11
|
constructor(xMin: number, yMin: number, xMax: number, yMax: number);
|
|
12
|
+
/** Returns a bounding box that contains this box and another one. */
|
|
8
13
|
mergeBbox(bbox: BBox): BBox;
|
|
9
14
|
}
|
package/src/geometry/bbox.js
CHANGED
package/src/geometry/minMax.d.ts
CHANGED
|
@@ -40,8 +40,31 @@ export declare function isPointInPolygonX(centroid: Point, polygon: Array<Point>
|
|
|
40
40
|
* Can be used to order (sort) words in the same line.
|
|
41
41
|
*/
|
|
42
42
|
export declare function relativeX(polygon: Array<Point>): number;
|
|
43
|
+
/**
|
|
44
|
+
* Get the minimum Y coordinate in a given list of Points.
|
|
45
|
+
* @param polygon An array of points or polygon.
|
|
46
|
+
*/
|
|
43
47
|
export declare function getMinYCoordinate(polygon: Array<Point>): number;
|
|
48
|
+
/**
|
|
49
|
+
* Get the minimum X coordinate in a given list of Points.
|
|
50
|
+
* @param polygon An array of points or polygon.
|
|
51
|
+
*/
|
|
44
52
|
export declare function getMinXCoordinate(polygon: Array<Point>): number;
|
|
53
|
+
/**
|
|
54
|
+
* Compare two polygons on their minimum Y coordinate.
|
|
55
|
+
* @param polygon1 An array of points or polygon.
|
|
56
|
+
* @param polygon2 An array of points or polygon.
|
|
57
|
+
*/
|
|
45
58
|
export declare function compareOnY(polygon1: Array<Point>, polygon2: Array<Point>): number;
|
|
59
|
+
/**
|
|
60
|
+
* Compare two polygons on their minimum X coordinate.
|
|
61
|
+
* @param polygon1 An array of points or polygon.
|
|
62
|
+
* @param polygon2 An array of points or polygon.
|
|
63
|
+
*/
|
|
46
64
|
export declare function compareOnX(polygon1: Array<Point>, polygon2: Array<Point>): number;
|
|
65
|
+
/**
|
|
66
|
+
* Adjust a polygon for a given rotation.
|
|
67
|
+
* @param polygon An array of points or polygon.
|
|
68
|
+
* @param orientation The rotation angle in degrees.
|
|
69
|
+
*/
|
|
47
70
|
export declare function adjustForRotation(polygon: Array<Point>, orientation: number): Array<Point>;
|
|
@@ -73,6 +73,10 @@ export function relativeX(polygon) {
|
|
|
73
73
|
.reduce((prev, cur) => prev + cur);
|
|
74
74
|
return polygon.length * sum;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the minimum Y coordinate in a given list of Points.
|
|
78
|
+
* @param polygon An array of points or polygon.
|
|
79
|
+
*/
|
|
76
80
|
export function getMinYCoordinate(polygon) {
|
|
77
81
|
return polygon.sort((point1, point2) => {
|
|
78
82
|
if (point1[1] < point2[1]) {
|
|
@@ -84,6 +88,10 @@ export function getMinYCoordinate(polygon) {
|
|
|
84
88
|
return 0;
|
|
85
89
|
})[0][1];
|
|
86
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the minimum X coordinate in a given list of Points.
|
|
93
|
+
* @param polygon An array of points or polygon.
|
|
94
|
+
*/
|
|
87
95
|
export function getMinXCoordinate(polygon) {
|
|
88
96
|
return polygon.sort((point1, point2) => {
|
|
89
97
|
if (point1[0] < point2[0]) {
|
|
@@ -95,6 +103,11 @@ export function getMinXCoordinate(polygon) {
|
|
|
95
103
|
return 0;
|
|
96
104
|
})[0][0];
|
|
97
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Compare two polygons on their minimum Y coordinate.
|
|
108
|
+
* @param polygon1 An array of points or polygon.
|
|
109
|
+
* @param polygon2 An array of points or polygon.
|
|
110
|
+
*/
|
|
98
111
|
export function compareOnY(polygon1, polygon2) {
|
|
99
112
|
const sort = getMinYCoordinate(polygon1) - getMinYCoordinate(polygon2);
|
|
100
113
|
if (sort === 0) {
|
|
@@ -102,6 +115,11 @@ export function compareOnY(polygon1, polygon2) {
|
|
|
102
115
|
}
|
|
103
116
|
return sort < 0 ? -1 : 1;
|
|
104
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Compare two polygons on their minimum X coordinate.
|
|
120
|
+
* @param polygon1 An array of points or polygon.
|
|
121
|
+
* @param polygon2 An array of points or polygon.
|
|
122
|
+
*/
|
|
105
123
|
export function compareOnX(polygon1, polygon2) {
|
|
106
124
|
const sort = getMinXCoordinate(polygon1) - getMinXCoordinate(polygon2);
|
|
107
125
|
if (sort === 0) {
|
|
@@ -109,6 +127,11 @@ export function compareOnX(polygon1, polygon2) {
|
|
|
109
127
|
}
|
|
110
128
|
return sort < 0 ? -1 : 1;
|
|
111
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Adjust a polygon for a given rotation.
|
|
132
|
+
* @param polygon An array of points or polygon.
|
|
133
|
+
* @param orientation The rotation angle in degrees.
|
|
134
|
+
*/
|
|
112
135
|
export function adjustForRotation(polygon, orientation) {
|
|
113
136
|
if (orientation === 90) {
|
|
114
137
|
return polygon.map(([x, y]) => [y, 1 - x]);
|
|
@@ -4,11 +4,16 @@ export interface MindeeApiConstructorProps {
|
|
|
4
4
|
dispatcher?: Dispatcher;
|
|
5
5
|
}
|
|
6
6
|
export declare abstract class BaseSettings {
|
|
7
|
+
/** API key used for authenticated requests. */
|
|
7
8
|
apiKey: string;
|
|
9
|
+
/** API hostname used for requests. */
|
|
8
10
|
hostname: string;
|
|
11
|
+
/** Request timeout in seconds. */
|
|
9
12
|
timeoutSecs: number;
|
|
13
|
+
/** HTTP dispatcher used by undici. */
|
|
10
14
|
dispatcher: Dispatcher;
|
|
11
15
|
protected constructor(apiKey?: string, dispatcher?: Dispatcher);
|
|
16
|
+
/** Builds a default user-agent string for outgoing requests. */
|
|
12
17
|
protected getUserAgent(): string;
|
|
13
18
|
protected abstract apiKeyFromEnv(): string;
|
|
14
19
|
protected abstract hostnameFromEnv(): string;
|
package/src/http/baseSettings.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getGlobalDispatcher } from "undici";
|
|
2
|
+
// eslint-disable-next-line no-restricted-imports
|
|
2
3
|
import packageJson from "../../package.json" with { type: "json" };
|
|
3
4
|
import * as os from "os";
|
|
4
5
|
import { TIMEOUT_SECS_DEFAULT } from "./apiCore.js";
|
|
@@ -16,6 +17,7 @@ export class BaseSettings {
|
|
|
16
17
|
? parseInt(process.env.MINDEE_REQUEST_TIMEOUT)
|
|
17
18
|
: TIMEOUT_SECS_DEFAULT;
|
|
18
19
|
}
|
|
20
|
+
/** Builds a default user-agent string for outgoing requests. */
|
|
19
21
|
getUserAgent() {
|
|
20
22
|
let platform = os.type().toLowerCase();
|
|
21
23
|
if (platform.includes("darwin")) {
|
|
@@ -4,9 +4,13 @@ import { BufferInput } from "../input/index.js";
|
|
|
4
4
|
* Generic class for image extraction.
|
|
5
5
|
*/
|
|
6
6
|
export declare class ExtractedImage {
|
|
7
|
+
/** Raw file bytes for the extracted image artifact. */
|
|
7
8
|
buffer: Buffer;
|
|
9
|
+
/** Filename used when exporting the extracted image. */
|
|
8
10
|
filename: string;
|
|
11
|
+
/** 1-based source page identifier. */
|
|
9
12
|
readonly pageId: number;
|
|
13
|
+
/** Identifier of the extracted element on the page. */
|
|
10
14
|
readonly elementId: number;
|
|
11
15
|
constructor(buffer: Uint8Array, fileName: string, pageId: number, elementId: number);
|
|
12
16
|
/**
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* @param maxWidth Maximum bound for width.
|
|
7
7
|
* @param maxHeight Maximum bound for height.
|
|
8
8
|
*/
|
|
9
|
-
export declare function compressImage(imageBuffer: Buffer, quality?: number, maxWidth?: number | null, maxHeight?: number | null): Promise<Buffer<
|
|
9
|
+
export declare function compressImage(imageBuffer: Buffer, quality?: number, maxWidth?: number | null, maxHeight?: number | null): Promise<Buffer<ArrayBuffer>>;
|
|
@@ -10,11 +10,10 @@ import type * as pdfLibTypes from "@cantoo/pdf-lib";
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function extractImagesFromPolygon(inputSource: LocalInputSource, polygonsPerPage: Map<number, Polygon[]>, quality?: number): Promise<ExtractedImages>;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param quality JPEG quality of extracted images, given as number between 0 and 1.
|
|
13
|
+
* Extract images from a PDF page.
|
|
14
|
+
* @param pdfPage The PDF page to extract images from.
|
|
15
|
+
* @param polygons The polygons to extract images from.
|
|
16
|
+
* @param asImage Whether to return the extracted images as images or as raw data.
|
|
17
|
+
* @param quality The quality of the extracted images.
|
|
19
18
|
*/
|
|
20
19
|
export declare function extractFromPage(pdfPage: pdfLibTypes.PDFPage, polygons: Polygon[], asImage?: boolean, quality?: number): Promise<Uint8Array<ArrayBufferLike>[]>;
|
|
@@ -8,6 +8,9 @@ import { logger } from "../logger.js";
|
|
|
8
8
|
import { createPdfFromInputSource } from "../pdf/pdfOperation.js";
|
|
9
9
|
import { rasterizePage } from "../pdf/pdfUtils.js";
|
|
10
10
|
let pdfLib = null;
|
|
11
|
+
/**
|
|
12
|
+
* Load the PDF library if not already loaded.
|
|
13
|
+
*/
|
|
11
14
|
async function getPdfLib() {
|
|
12
15
|
if (!pdfLib) {
|
|
13
16
|
const pdfLibImport = await loadOptionalDependency("@cantoo/pdf-lib", "Image Extraction");
|
|
@@ -28,29 +31,68 @@ export async function extractImagesFromPolygon(inputSource, polygonsPerPage, qua
|
|
|
28
31
|
logger.debug(`Extracting images from page ${pageId}`);
|
|
29
32
|
const pdfPage = pdfDoc.getPage(pageId);
|
|
30
33
|
const extractions = await extractFromPage(pdfPage, polygons, true, quality);
|
|
31
|
-
const extractedImages = extractions.map((buffer, elementId) => new ExtractedImage(buffer, inputSource.filename + `_page
|
|
34
|
+
const extractedImages = extractions.map((buffer, elementId) => new ExtractedImage(buffer, inputSource.filename + `_page${pageId}-${elementId}.jpg`, pageId, elementId));
|
|
32
35
|
allExtractedImages.push(...extractedImages);
|
|
33
36
|
}
|
|
34
37
|
return allExtractedImages;
|
|
35
38
|
}
|
|
36
39
|
/**
|
|
37
|
-
*
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
* Helper function to handle the drawing math and orientation.
|
|
41
|
+
*/
|
|
42
|
+
function drawOrientedPage(pdfLib, samplePage, cropped, orientation, finalWidth, finalHeight, scaledWidth, scaledHeight) {
|
|
43
|
+
if (orientation === 0) {
|
|
44
|
+
samplePage.drawPage(cropped, {
|
|
45
|
+
width: scaledWidth,
|
|
46
|
+
height: scaledHeight,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else if (orientation === 90) {
|
|
50
|
+
samplePage.drawPage(cropped, {
|
|
51
|
+
x: 0,
|
|
52
|
+
y: finalHeight,
|
|
53
|
+
width: scaledWidth,
|
|
54
|
+
height: scaledHeight,
|
|
55
|
+
rotate: pdfLib.degrees(270),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else if (orientation === 180) {
|
|
59
|
+
samplePage.drawPage(cropped, {
|
|
60
|
+
x: finalWidth,
|
|
61
|
+
y: finalHeight,
|
|
62
|
+
width: scaledWidth,
|
|
63
|
+
height: scaledHeight,
|
|
64
|
+
rotate: pdfLib.degrees(180),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else if (orientation === 270) {
|
|
68
|
+
samplePage.drawPage(cropped, {
|
|
69
|
+
x: finalWidth,
|
|
70
|
+
y: 0,
|
|
71
|
+
width: scaledWidth,
|
|
72
|
+
height: scaledHeight,
|
|
73
|
+
rotate: pdfLib.degrees(90),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Extract images from a PDF page.
|
|
79
|
+
* @param pdfPage The PDF page to extract images from.
|
|
80
|
+
* @param polygons The polygons to extract images from.
|
|
81
|
+
* @param asImage Whether to return the extracted images as images or as raw data.
|
|
82
|
+
* @param quality The quality of the extracted images.
|
|
43
83
|
*/
|
|
44
84
|
export async function extractFromPage(pdfPage, polygons, asImage = false, quality) {
|
|
45
85
|
const pdfLib = await getPdfLib();
|
|
46
86
|
const { width, height } = pdfPage.getSize();
|
|
47
87
|
const extractedElements = [];
|
|
48
|
-
if (quality
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
88
|
+
if (quality !== undefined) {
|
|
89
|
+
if (quality < 0) {
|
|
90
|
+
throw new MindeeImageError("Quality must be a number between 0 and 1");
|
|
91
|
+
}
|
|
92
|
+
if (quality > 1) {
|
|
93
|
+
logger.warn("Quality is greater than 1, this operation will apply a manual upscale on the output." +
|
|
94
|
+
" Use only if you know what you are doing.");
|
|
95
|
+
}
|
|
54
96
|
}
|
|
55
97
|
const qualityScale = quality ?? 1;
|
|
56
98
|
const orientation = pdfPage.getRotation().angle;
|
|
@@ -61,72 +103,28 @@ export async function extractFromPage(pdfPage, polygons, asImage = false, qualit
|
|
|
61
103
|
const tempPdf = await pdfLib.PDFDocument.create();
|
|
62
104
|
const [copiedPage] = await tempPdf.copyPages(sourceDoc, [pageIndex]);
|
|
63
105
|
const polygon = adjustForRotation(origPolygon, orientation);
|
|
64
|
-
const
|
|
65
|
-
const
|
|
106
|
+
const minX = getMinMaxX(polygon).min;
|
|
107
|
+
const maxX = getMinMaxX(polygon).max;
|
|
108
|
+
const minY = getMinMaxY(polygon).min;
|
|
109
|
+
const maxY = getMinMaxY(polygon).max;
|
|
110
|
+
const newWidth = width * (maxX - minX);
|
|
111
|
+
const newHeight = height * (maxY - minY);
|
|
66
112
|
const cropped = await tempPdf.embedPage(copiedPage, {
|
|
67
|
-
left:
|
|
68
|
-
right:
|
|
69
|
-
top: height - (
|
|
70
|
-
bottom: height - (
|
|
113
|
+
left: minX * width,
|
|
114
|
+
right: maxX * width,
|
|
115
|
+
top: height - (minY * height),
|
|
116
|
+
bottom: height - (maxY * height),
|
|
71
117
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
finalWidth = newHeight * qualityScale;
|
|
76
|
-
finalHeight = newWidth * qualityScale;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
finalWidth = newWidth * qualityScale;
|
|
80
|
-
finalHeight = newHeight * qualityScale;
|
|
81
|
-
}
|
|
118
|
+
const isVertical = orientation === 90 || orientation === 270;
|
|
119
|
+
const finalWidth = (isVertical ? newHeight : newWidth) * qualityScale;
|
|
120
|
+
const finalHeight = (isVertical ? newWidth : newHeight) * qualityScale;
|
|
82
121
|
const samplePage = tempPdf.addPage([finalWidth, finalHeight]);
|
|
83
122
|
samplePage.drawRectangle({
|
|
84
|
-
x: 0,
|
|
85
|
-
y: 0,
|
|
86
|
-
width: finalWidth,
|
|
87
|
-
height: finalHeight,
|
|
88
|
-
color: pdfLib.rgb(1, 1, 1),
|
|
123
|
+
x: 0, y: 0, width: finalWidth, height: finalHeight, color: pdfLib.rgb(1, 1, 1),
|
|
89
124
|
});
|
|
90
|
-
|
|
91
|
-
samplePage.drawPage(cropped, {
|
|
92
|
-
width: newWidth * qualityScale,
|
|
93
|
-
height: newHeight * qualityScale,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
else if (orientation === 90) {
|
|
97
|
-
samplePage.drawPage(cropped, {
|
|
98
|
-
x: 0,
|
|
99
|
-
y: finalHeight,
|
|
100
|
-
width: newWidth * qualityScale,
|
|
101
|
-
height: newHeight * qualityScale,
|
|
102
|
-
rotate: pdfLib.degrees(270),
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
else if (orientation === 180) {
|
|
106
|
-
samplePage.drawPage(cropped, {
|
|
107
|
-
x: finalWidth,
|
|
108
|
-
y: finalHeight,
|
|
109
|
-
width: newWidth * qualityScale,
|
|
110
|
-
height: newHeight * qualityScale,
|
|
111
|
-
rotate: pdfLib.degrees(180),
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
else if (orientation === 270) {
|
|
115
|
-
samplePage.drawPage(cropped, {
|
|
116
|
-
x: finalWidth,
|
|
117
|
-
y: 0,
|
|
118
|
-
width: newWidth * qualityScale,
|
|
119
|
-
height: newHeight * qualityScale,
|
|
120
|
-
rotate: pdfLib.degrees(90),
|
|
121
|
-
});
|
|
122
|
-
}
|
|
125
|
+
drawOrientedPage(pdfLib, samplePage, cropped, orientation, finalWidth, finalHeight, newWidth * qualityScale, newHeight * qualityScale);
|
|
123
126
|
const pdfBuffer = Buffer.from(await tempPdf.save());
|
|
124
|
-
|
|
125
|
-
extractedElements.push(await rasterizePage(pdfBuffer, 0, 100));
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
extractedElements.push(pdfBuffer);
|
|
129
|
-
}
|
|
127
|
+
extractedElements.push(asImage ? await rasterizePage(pdfBuffer, 0, 100) : pdfBuffer);
|
|
130
128
|
}
|
|
131
129
|
return extractedElements;
|
|
132
130
|
}
|
|
@@ -3,10 +3,13 @@ interface Base64InputProps {
|
|
|
3
3
|
inputString: string;
|
|
4
4
|
filename: string;
|
|
5
5
|
}
|
|
6
|
+
/** Local input source backed by a base64-encoded payload. */
|
|
6
7
|
export declare class Base64Input extends LocalInputSource {
|
|
7
8
|
private inputString;
|
|
9
|
+
/** Decoded binary payload built from the base64 input. */
|
|
8
10
|
fileObject: Buffer;
|
|
9
11
|
constructor({ inputString, filename }: Base64InputProps);
|
|
12
|
+
/** Decodes and validates the provided base64 content. */
|
|
10
13
|
init(): Promise<void>;
|
|
11
14
|
}
|
|
12
15
|
export {};
|
package/src/input/base64Input.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { LocalInputSource } from "./localInputSource.js";
|
|
2
2
|
import { INPUT_TYPE_BASE64 } from "./inputSource.js";
|
|
3
3
|
import { logger } from "../logger.js";
|
|
4
|
+
/** Local input source backed by a base64-encoded payload. */
|
|
4
5
|
export class Base64Input extends LocalInputSource {
|
|
5
6
|
constructor({ inputString, filename }) {
|
|
6
7
|
super({
|
|
7
8
|
inputType: INPUT_TYPE_BASE64,
|
|
8
9
|
});
|
|
10
|
+
/** Decoded binary payload built from the base64 input. */
|
|
9
11
|
this.fileObject = Buffer.alloc(0);
|
|
10
12
|
this.filename = filename;
|
|
11
13
|
this.inputString = inputString;
|
|
12
14
|
}
|
|
15
|
+
/** Decodes and validates the provided base64 content. */
|
|
13
16
|
async init() {
|
|
14
17
|
if (this.initialized) {
|
|
15
18
|
return;
|
|
@@ -3,8 +3,10 @@ interface BufferInputProps {
|
|
|
3
3
|
buffer: Buffer;
|
|
4
4
|
filename: string;
|
|
5
5
|
}
|
|
6
|
+
/** Local input source backed by an in-memory `Buffer`. */
|
|
6
7
|
export declare class BufferInput extends LocalInputSource {
|
|
7
8
|
constructor({ buffer, filename }: BufferInputProps);
|
|
9
|
+
/** Validates and initializes the in-memory buffer input. */
|
|
8
10
|
init(): Promise<void>;
|
|
9
11
|
}
|
|
10
12
|
export {};
|
package/src/input/bufferInput.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LocalInputSource } from "./localInputSource.js";
|
|
2
2
|
import { INPUT_TYPE_BUFFER } from "./inputSource.js";
|
|
3
3
|
import { logger } from "../logger.js";
|
|
4
|
+
/** Local input source backed by an in-memory `Buffer`. */
|
|
4
5
|
export class BufferInput extends LocalInputSource {
|
|
5
6
|
constructor({ buffer, filename }) {
|
|
6
7
|
super({
|
|
@@ -9,6 +10,7 @@ export class BufferInput extends LocalInputSource {
|
|
|
9
10
|
this.fileObject = buffer;
|
|
10
11
|
this.filename = filename;
|
|
11
12
|
}
|
|
13
|
+
/** Validates and initializes the in-memory buffer input. */
|
|
12
14
|
async init() {
|
|
13
15
|
if (this.initialized) {
|
|
14
16
|
return;
|
|
@@ -3,10 +3,13 @@ interface BytesInputProps {
|
|
|
3
3
|
inputBytes: Uint8Array;
|
|
4
4
|
filename: string;
|
|
5
5
|
}
|
|
6
|
+
/** Local input source backed by a `Uint8Array`. */
|
|
6
7
|
export declare class BytesInput extends LocalInputSource {
|
|
7
8
|
private inputBytes;
|
|
9
|
+
/** Binary payload built from the byte array. */
|
|
8
10
|
fileObject: Buffer;
|
|
9
11
|
constructor({ inputBytes, filename }: BytesInputProps);
|
|
12
|
+
/** Converts bytes to a buffer and validates MIME type. */
|
|
10
13
|
init(): Promise<void>;
|
|
11
14
|
}
|
|
12
15
|
export {};
|
package/src/input/bytesInput.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { INPUT_TYPE_BYTES } from "./inputSource.js";
|
|
2
2
|
import { LocalInputSource } from "./localInputSource.js";
|
|
3
3
|
import { logger } from "../logger.js";
|
|
4
|
+
/** Local input source backed by a `Uint8Array`. */
|
|
4
5
|
export class BytesInput extends LocalInputSource {
|
|
5
6
|
constructor({ inputBytes, filename }) {
|
|
6
7
|
super({
|
|
7
8
|
inputType: INPUT_TYPE_BYTES,
|
|
8
9
|
});
|
|
10
|
+
/** Binary payload built from the byte array. */
|
|
9
11
|
this.fileObject = Buffer.alloc(0);
|
|
10
12
|
this.filename = filename;
|
|
11
13
|
this.inputBytes = inputBytes;
|
|
12
14
|
}
|
|
15
|
+
/** Converts bytes to a buffer and validates MIME type. */
|
|
13
16
|
async init() {
|
|
14
17
|
if (this.initialized) {
|
|
15
18
|
return;
|
|
@@ -10,9 +10,24 @@ export declare const INPUT_TYPE_BASE64 = "base64";
|
|
|
10
10
|
export declare const INPUT_TYPE_BYTES = "bytes";
|
|
11
11
|
export declare const INPUT_TYPE_PATH = "path";
|
|
12
12
|
export declare const INPUT_TYPE_BUFFER = "buffer";
|
|
13
|
+
/**
|
|
14
|
+
* Abstract class for input sources.
|
|
15
|
+
*/
|
|
13
16
|
export declare abstract class InputSource {
|
|
17
|
+
/**
|
|
18
|
+
* The file object used by the input source.
|
|
19
|
+
*/
|
|
14
20
|
fileObject: Buffer | string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the input source has been initialized.
|
|
23
|
+
* @protected
|
|
24
|
+
*/
|
|
25
|
+
/** Whether the source has already been initialized. */
|
|
15
26
|
protected initialized: boolean;
|
|
27
|
+
/** Initializes the input source and populates its file object. */
|
|
16
28
|
init(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns whether the input source has been initialized.
|
|
31
|
+
*/
|
|
17
32
|
isInitialized(): boolean;
|
|
18
33
|
}
|