mindee 5.4.0 → 5.6.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 +24 -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/apiCore.d.ts +1 -0
- package/src/http/apiCore.js +21 -3
- package/src/http/baseSettings.d.ts +5 -0
- package/src/http/baseSettings.js +2 -0
- package/src/image/extractedImage.d.ts +9 -5
- package/src/image/extractedImage.js +2 -2
- 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 +7 -8
- package/src/image/imageExtractor.js +74 -75
- 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 +8 -2
- package/src/pdf/extractedPdf.js +5 -3
- 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.d.ts +2 -2
- package/src/pdf/pdfExtractor.js +4 -1
- 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 +5 -3
- package/src/v1/extraction/invoiceSplitterExtractor/extractedInvoiceSplitterImage.js +4 -4
- package/src/v1/extraction/invoiceSplitterExtractor/invoiceSplitterExtractor.js +14 -0
- package/src/v1/extraction/multiReceiptsExtractor/extractedMultiReceiptImage.d.ts +2 -0
- package/src/v1/extraction/multiReceiptsExtractor/extractedMultiReceiptImage.js +1 -1
- 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 +10 -1
- package/src/v2/client.js +18 -8
- package/src/v2/clientOptions/baseParameters.d.ts +3 -2
- package/src/v2/clientOptions/pollingOptions.d.ts +6 -1
- package/src/v2/clientOptions/pollingOptions.js +4 -2
- package/src/v2/fileOperations/crop.js +1 -3
- package/src/v2/fileOperations/split.js +1 -1
- package/src/v2/http/mindeeApiV2.d.ts +23 -10
- package/src/v2/http/mindeeApiV2.js +79 -68
- 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/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/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,26 @@
|
|
|
1
1
|
# Mindee Node.js API Library Changelog
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
## v5.6.0 - 2026-07-21
|
|
5
|
+
### Changes
|
|
6
|
+
* :sparkles: add support for webhook errors
|
|
7
|
+
* :arrow_up: add husky
|
|
8
|
+
* :arrow_up: add eslint rules
|
|
9
|
+
* :arrow_up: add direct license checker
|
|
10
|
+
* :recycle: replace dashes with colons in package.json script commands
|
|
11
|
+
* :wrench: add secretlint
|
|
12
|
+
* :wrench: :coffin: remove support for mocha
|
|
13
|
+
### Fixes
|
|
14
|
+
* :arrow_up: bump dependencies
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## v5.5.0 - 2026-07-01
|
|
18
|
+
### Fixes
|
|
19
|
+
* :memo: minor tweak to SKILL file
|
|
20
|
+
* :bug: retry once on connection error
|
|
21
|
+
* :recycle: rework and fix extractors (:boom: some **undocumented** functions break)
|
|
22
|
+
|
|
23
|
+
|
|
3
24
|
## v5.4.0 - 2026-06-22
|
|
4
25
|
### Fixes
|
|
5
26
|
* :bug: :boom: harmonize Crop and Split extraction (now ready for public use)
|
|
@@ -78,7 +99,7 @@
|
|
|
78
99
|
|
|
79
100
|
|
|
80
101
|
## v5.0.0-rc1 - 2026-02-17
|
|
81
|
-
### Changes
|
|
102
|
+
### ¡Breaking Changes!
|
|
82
103
|
* :boom: drop support for node.js 18
|
|
83
104
|
* :boom: :recycle: separate polling options
|
|
84
105
|
|
|
@@ -92,7 +113,8 @@
|
|
|
92
113
|
|
|
93
114
|
|
|
94
115
|
## v5.0.0-alpha1 - 2026-02-13
|
|
95
|
-
###
|
|
116
|
+
### ¡Breaking Changes!
|
|
117
|
+
* :boom: :recycle: base for v5
|
|
96
118
|
* :arrow_up: update file-type
|
|
97
119
|
* :recycle: migrate to ES modules (node18)
|
|
98
120
|
* :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.0",
|
|
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]);
|
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
|
|
@@ -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")) {
|
|
@@ -1,14 +1,18 @@
|
|
|
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
|
+
/** Raw file bytes for the extracted image artifact. */
|
|
7
8
|
buffer: Buffer;
|
|
9
|
+
/** Filename used when exporting the extracted image. */
|
|
8
10
|
filename: string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/** 1-based source page identifier. */
|
|
12
|
+
readonly pageId: number;
|
|
13
|
+
/** Identifier of the extracted element on the page. */
|
|
14
|
+
readonly elementId: number;
|
|
15
|
+
constructor(buffer: Uint8Array, fileName: string, pageId: number, elementId: number);
|
|
12
16
|
/**
|
|
13
17
|
* Saves the document to a file.
|
|
14
18
|
*
|
|
@@ -27,5 +31,5 @@ export declare class ExtractedImage {
|
|
|
27
31
|
*
|
|
28
32
|
* @returns A BufferInput source.
|
|
29
33
|
*/
|
|
30
|
-
|
|
34
|
+
asInputSource(): BufferInput;
|
|
31
35
|
}
|
|
@@ -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,
|
|
@@ -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>>;
|
|
@@ -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,13 +8,12 @@ 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
|
-
*
|
|
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>[]>;
|
|
@@ -3,10 +3,14 @@ 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";
|
|
9
10
|
let pdfLib = null;
|
|
11
|
+
/**
|
|
12
|
+
* Load the PDF library if not already loaded.
|
|
13
|
+
*/
|
|
10
14
|
async function getPdfLib() {
|
|
11
15
|
if (!pdfLib) {
|
|
12
16
|
const pdfLibImport = await loadOptionalDependency("@cantoo/pdf-lib", "Image Extraction");
|
|
@@ -21,35 +25,74 @@ async function getPdfLib() {
|
|
|
21
25
|
* @param quality JPEG quality of extracted images.
|
|
22
26
|
*/
|
|
23
27
|
export async function extractImagesFromPolygon(inputSource, polygonsPerPage, quality) {
|
|
24
|
-
const allExtractedImages =
|
|
28
|
+
const allExtractedImages = new ExtractedImages();
|
|
25
29
|
const pdfDoc = await createPdfFromInputSource(inputSource);
|
|
26
30
|
for (const [pageId, polygons] of polygonsPerPage) {
|
|
27
31
|
logger.debug(`Extracting images from page ${pageId}`);
|
|
28
32
|
const pdfPage = pdfDoc.getPage(pageId);
|
|
29
|
-
const extractions =
|
|
30
|
-
const extractedImages = extractions.map((
|
|
33
|
+
const extractions = await extractFromPage(pdfPage, polygons, true, quality);
|
|
34
|
+
const extractedImages = extractions.map((buffer, elementId) => new ExtractedImage(buffer, inputSource.filename + `_page${pageId}-${elementId}.jpg`, pageId, elementId));
|
|
31
35
|
allExtractedImages.push(...extractedImages);
|
|
32
36
|
}
|
|
33
37
|
return allExtractedImages;
|
|
34
38
|
}
|
|
35
39
|
/**
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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.
|
|
42
83
|
*/
|
|
43
84
|
export async function extractFromPage(pdfPage, polygons, asImage = false, quality) {
|
|
44
85
|
const pdfLib = await getPdfLib();
|
|
45
86
|
const { width, height } = pdfPage.getSize();
|
|
46
87
|
const extractedElements = [];
|
|
47
|
-
if (quality
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
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
|
+
}
|
|
53
96
|
}
|
|
54
97
|
const qualityScale = quality ?? 1;
|
|
55
98
|
const orientation = pdfPage.getRotation().angle;
|
|
@@ -60,72 +103,28 @@ export async function extractFromPage(pdfPage, polygons, asImage = false, qualit
|
|
|
60
103
|
const tempPdf = await pdfLib.PDFDocument.create();
|
|
61
104
|
const [copiedPage] = await tempPdf.copyPages(sourceDoc, [pageIndex]);
|
|
62
105
|
const polygon = adjustForRotation(origPolygon, orientation);
|
|
63
|
-
const
|
|
64
|
-
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);
|
|
65
112
|
const cropped = await tempPdf.embedPage(copiedPage, {
|
|
66
|
-
left:
|
|
67
|
-
right:
|
|
68
|
-
top: height - (
|
|
69
|
-
bottom: height - (
|
|
113
|
+
left: minX * width,
|
|
114
|
+
right: maxX * width,
|
|
115
|
+
top: height - (minY * height),
|
|
116
|
+
bottom: height - (maxY * height),
|
|
70
117
|
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
finalWidth = newHeight * qualityScale;
|
|
75
|
-
finalHeight = newWidth * qualityScale;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
finalWidth = newWidth * qualityScale;
|
|
79
|
-
finalHeight = newHeight * qualityScale;
|
|
80
|
-
}
|
|
118
|
+
const isVertical = orientation === 90 || orientation === 270;
|
|
119
|
+
const finalWidth = (isVertical ? newHeight : newWidth) * qualityScale;
|
|
120
|
+
const finalHeight = (isVertical ? newWidth : newHeight) * qualityScale;
|
|
81
121
|
const samplePage = tempPdf.addPage([finalWidth, finalHeight]);
|
|
82
122
|
samplePage.drawRectangle({
|
|
83
|
-
x: 0,
|
|
84
|
-
y: 0,
|
|
85
|
-
width: finalWidth,
|
|
86
|
-
height: finalHeight,
|
|
87
|
-
color: pdfLib.rgb(1, 1, 1),
|
|
123
|
+
x: 0, y: 0, width: finalWidth, height: finalHeight, color: pdfLib.rgb(1, 1, 1),
|
|
88
124
|
});
|
|
89
|
-
|
|
90
|
-
samplePage.drawPage(cropped, {
|
|
91
|
-
width: newWidth * qualityScale,
|
|
92
|
-
height: newHeight * qualityScale,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
else if (orientation === 90) {
|
|
96
|
-
samplePage.drawPage(cropped, {
|
|
97
|
-
x: 0,
|
|
98
|
-
y: finalHeight,
|
|
99
|
-
width: newWidth * qualityScale,
|
|
100
|
-
height: newHeight * qualityScale,
|
|
101
|
-
rotate: pdfLib.degrees(270),
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
else if (orientation === 180) {
|
|
105
|
-
samplePage.drawPage(cropped, {
|
|
106
|
-
x: finalWidth,
|
|
107
|
-
y: finalHeight,
|
|
108
|
-
width: newWidth * qualityScale,
|
|
109
|
-
height: newHeight * qualityScale,
|
|
110
|
-
rotate: pdfLib.degrees(180),
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
else if (orientation === 270) {
|
|
114
|
-
samplePage.drawPage(cropped, {
|
|
115
|
-
x: finalWidth,
|
|
116
|
-
y: 0,
|
|
117
|
-
width: newWidth * qualityScale,
|
|
118
|
-
height: newHeight * qualityScale,
|
|
119
|
-
rotate: pdfLib.degrees(90),
|
|
120
|
-
});
|
|
121
|
-
}
|
|
125
|
+
drawOrientedPage(pdfLib, samplePage, cropped, orientation, finalWidth, finalHeight, newWidth * qualityScale, newHeight * qualityScale);
|
|
122
126
|
const pdfBuffer = Buffer.from(await tempPdf.save());
|
|
123
|
-
|
|
124
|
-
extractedElements.push(await rasterizePage(pdfBuffer, 0, 100));
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
extractedElements.push(pdfBuffer);
|
|
128
|
-
}
|
|
127
|
+
extractedElements.push(asImage ? await rasterizePage(pdfBuffer, 0, 100) : pdfBuffer);
|
|
129
128
|
}
|
|
130
129
|
return extractedElements;
|
|
131
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;
|