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.
Files changed (230) hide show
  1. package/CHANGELOG.md +24 -2
  2. package/package.json +26 -14
  3. package/src/geometry/bbox.d.ts +5 -0
  4. package/src/geometry/bbox.js +1 -0
  5. package/src/geometry/minMax.d.ts +3 -0
  6. package/src/geometry/polygonUtils.d.ts +23 -0
  7. package/src/geometry/polygonUtils.js +23 -0
  8. package/src/http/apiCore.d.ts +1 -0
  9. package/src/http/apiCore.js +21 -3
  10. package/src/http/baseSettings.d.ts +5 -0
  11. package/src/http/baseSettings.js +2 -0
  12. package/src/image/extractedImage.d.ts +9 -5
  13. package/src/image/extractedImage.js +2 -2
  14. package/src/image/extractedImages.d.ts +1 -0
  15. package/src/image/extractedImages.js +1 -0
  16. package/src/image/imageCompressor.d.ts +1 -1
  17. package/src/image/imageExtractor.d.ts +7 -8
  18. package/src/image/imageExtractor.js +74 -75
  19. package/src/input/base64Input.d.ts +3 -0
  20. package/src/input/base64Input.js +3 -0
  21. package/src/input/bufferInput.d.ts +2 -0
  22. package/src/input/bufferInput.js +2 -0
  23. package/src/input/bytesInput.d.ts +3 -0
  24. package/src/input/bytesInput.js +3 -0
  25. package/src/input/inputSource.d.ts +15 -0
  26. package/src/input/inputSource.js +15 -0
  27. package/src/input/localInputSource.d.ts +6 -0
  28. package/src/input/localInputSource.js +3 -0
  29. package/src/input/pathInput.d.ts +4 -0
  30. package/src/input/pathInput.js +3 -0
  31. package/src/input/streamInput.d.ts +4 -0
  32. package/src/input/streamInput.js +4 -0
  33. package/src/input/urlInput.d.ts +12 -0
  34. package/src/input/urlInput.js +52 -10
  35. package/src/logger.js +1 -1
  36. package/src/parsing/dateParser.d.ts +4 -0
  37. package/src/parsing/dateParser.js +5 -1
  38. package/src/parsing/localResponseBase.d.ts +2 -0
  39. package/src/parsing/localResponseBase.js +2 -0
  40. package/src/parsing/stringDict.d.ts +1 -0
  41. package/src/pdf/extractedPdf.d.ts +8 -2
  42. package/src/pdf/extractedPdf.js +5 -3
  43. package/src/pdf/extractedPdfs.d.ts +1 -0
  44. package/src/pdf/extractedPdfs.js +1 -0
  45. package/src/pdf/pdfCompressor.js +12 -0
  46. package/src/pdf/pdfExtractor.d.ts +2 -2
  47. package/src/pdf/pdfExtractor.js +4 -1
  48. package/src/pdf/pdfOperation.d.ts +3 -0
  49. package/src/pdf/pdfOperation.js +3 -0
  50. package/src/pdf/pdfUtils.js +5 -0
  51. package/src/v1/cli.d.ts +3 -0
  52. package/src/v1/cli.js +84 -26
  53. package/src/v1/client.d.ts +16 -16
  54. package/src/v1/extraction/invoiceSplitterExtractor/extractedInvoiceSplitterImage.d.ts +5 -3
  55. package/src/v1/extraction/invoiceSplitterExtractor/extractedInvoiceSplitterImage.js +4 -4
  56. package/src/v1/extraction/invoiceSplitterExtractor/invoiceSplitterExtractor.js +14 -0
  57. package/src/v1/extraction/multiReceiptsExtractor/extractedMultiReceiptImage.d.ts +2 -0
  58. package/src/v1/extraction/multiReceiptsExtractor/extractedMultiReceiptImage.js +1 -1
  59. package/src/v1/extraction/multiReceiptsExtractor/multiReceiptsExtractor.js +3 -0
  60. package/src/v1/http/apiSettingsV1.d.ts +5 -0
  61. package/src/v1/http/apiSettingsV1.js +4 -0
  62. package/src/v1/http/errors.d.ts +7 -1
  63. package/src/v1/http/errors.js +65 -86
  64. package/src/v1/http/httpParams.d.ts +12 -0
  65. package/src/v1/parsing/common/asyncPredictResponse.d.ts +4 -0
  66. package/src/v1/parsing/common/asyncPredictResponse.js +5 -2
  67. package/src/v1/parsing/common/executionPriority.d.ts +4 -0
  68. package/src/v1/parsing/common/executionPriority.js +4 -0
  69. package/src/v1/parsing/common/extras/cropperExtra.d.ts +2 -0
  70. package/src/v1/parsing/common/extras/cropperExtra.js +3 -0
  71. package/src/v1/parsing/common/extras/extras.d.ts +3 -0
  72. package/src/v1/parsing/common/extras/extras.js +2 -0
  73. package/src/v1/parsing/common/extras/fullTextOcrExtra.d.ts +3 -0
  74. package/src/v1/parsing/common/extras/fullTextOcrExtra.js +1 -0
  75. package/src/v1/parsing/common/extras/ragExtra.d.ts +1 -0
  76. package/src/v1/parsing/common/extras/ragExtra.js +1 -0
  77. package/src/v1/parsing/common/feedback/feedbackResponse.js +1 -0
  78. package/src/v1/parsing/common/index.d.ts +1 -1
  79. package/src/v1/parsing/common/index.js +1 -1
  80. package/src/v1/parsing/common/inference.d.ts +2 -0
  81. package/src/v1/parsing/common/inference.js +2 -0
  82. package/src/v1/parsing/common/prediction.d.ts +1 -0
  83. package/src/v1/parsing/common/prediction.js +1 -0
  84. package/src/v1/parsing/common/summaryHelper.d.ts +12 -1
  85. package/src/v1/parsing/common/summaryHelper.js +18 -1
  86. package/src/v1/parsing/generated/generatedObject.d.ts +6 -0
  87. package/src/v1/parsing/generated/generatedObject.js +38 -27
  88. package/src/v1/parsing/localResponse.d.ts +1 -0
  89. package/src/v1/parsing/localResponse.js +1 -0
  90. package/src/v1/parsing/standard/base.d.ts +6 -0
  91. package/src/v1/parsing/standard/base.js +1 -0
  92. package/src/v1/parsing/standard/boolean.d.ts +1 -1
  93. package/src/v1/parsing/standard/companyRegistration.d.ts +1 -0
  94. package/src/v1/parsing/standard/companyRegistration.js +1 -0
  95. package/src/v1/parsing/standard/date.d.ts +1 -0
  96. package/src/v1/parsing/standard/date.js +1 -0
  97. package/src/v1/parsing/standard/paymentDetails.d.ts +5 -5
  98. package/src/v1/parsing/standard/position.d.ts +2 -2
  99. package/src/v1/parsing/standard/tax.d.ts +1 -0
  100. package/src/v1/parsing/standard/tax.js +1 -0
  101. package/src/v1/parsing/standard/text.d.ts +1 -1
  102. package/src/v1/parsing/standard/word.d.ts +3 -0
  103. package/src/v1/parsing/standard/word.js +1 -0
  104. package/src/v1/product/financialDocument/financialDocumentV1LineItem.js +16 -58
  105. package/src/v1/product/generated/generatedV1Prediction.d.ts +1 -0
  106. package/src/v1/product/generated/generatedV1Prediction.js +2 -1
  107. package/src/v1/product/invoice/invoiceV4LineItem.js +5 -16
  108. package/src/v1/product/receipt/receiptV5LineItem.js +2 -6
  109. package/src/v1/product/resume/resumeV1Certificate.js +5 -21
  110. package/src/v1/product/resume/resumeV1Education.js +8 -36
  111. package/src/v1/product/resume/resumeV1Language.js +3 -11
  112. package/src/v1/product/resume/resumeV1ProfessionalExperience.js +10 -46
  113. package/src/v1/product/resume/resumeV1SocialNetworksUrl.js +3 -11
  114. package/src/v2/cli.d.ts +3 -0
  115. package/src/v2/cli.js +21 -0
  116. package/src/v2/client.d.ts +10 -1
  117. package/src/v2/client.js +18 -8
  118. package/src/v2/clientOptions/baseParameters.d.ts +3 -2
  119. package/src/v2/clientOptions/pollingOptions.d.ts +6 -1
  120. package/src/v2/clientOptions/pollingOptions.js +4 -2
  121. package/src/v2/fileOperations/crop.js +1 -3
  122. package/src/v2/fileOperations/split.js +1 -1
  123. package/src/v2/http/mindeeApiV2.d.ts +23 -10
  124. package/src/v2/http/mindeeApiV2.js +79 -68
  125. package/src/v2/parsing/baseResponse.d.ts +2 -0
  126. package/src/v2/parsing/baseResponse.js +1 -0
  127. package/src/v2/parsing/error/errorDetails.d.ts +1 -0
  128. package/src/v2/parsing/index.d.ts +1 -1
  129. package/src/v2/parsing/index.js +1 -1
  130. package/src/v2/parsing/inference/baseInference.d.ts +2 -0
  131. package/src/v2/parsing/inference/baseInference.js +2 -0
  132. package/src/v2/parsing/inference/failedInferenceResponse.d.ts +33 -0
  133. package/src/v2/parsing/inference/failedInferenceResponse.js +17 -0
  134. package/src/v2/parsing/inference/field/baseField.d.ts +3 -0
  135. package/src/v2/parsing/inference/field/fieldConfidence.d.ts +4 -0
  136. package/src/v2/parsing/inference/field/fieldConfidence.js +4 -0
  137. package/src/v2/parsing/inference/field/fieldFactory.d.ts +5 -0
  138. package/src/v2/parsing/inference/field/fieldFactory.js +5 -0
  139. package/src/v2/parsing/inference/field/fieldLocation.d.ts +1 -0
  140. package/src/v2/parsing/inference/field/fieldLocation.js +1 -0
  141. package/src/v2/parsing/inference/field/inferenceFields.d.ts +5 -0
  142. package/src/v2/parsing/inference/field/inferenceFields.js +4 -0
  143. package/src/v2/parsing/inference/field/listField.d.ts +2 -0
  144. package/src/v2/parsing/inference/field/listField.js +2 -0
  145. package/src/v2/parsing/inference/field/objectField.d.ts +4 -0
  146. package/src/v2/parsing/inference/field/objectField.js +3 -0
  147. package/src/v2/parsing/inference/field/ragMetadata.d.ts +1 -0
  148. package/src/v2/parsing/inference/field/ragMetadata.js +1 -0
  149. package/src/v2/parsing/inference/field/rawText.d.ts +2 -0
  150. package/src/v2/parsing/inference/field/rawText.js +2 -0
  151. package/src/v2/parsing/inference/field/simpleField.d.ts +2 -0
  152. package/src/v2/parsing/inference/field/simpleField.js +2 -0
  153. package/src/v2/parsing/inference/inferenceFile.d.ts +2 -0
  154. package/src/v2/parsing/inference/inferenceFile.js +2 -0
  155. package/src/v2/parsing/inference/inferenceModel.d.ts +2 -0
  156. package/src/v2/parsing/inference/inferenceModel.js +2 -0
  157. package/src/v2/parsing/job/job.d.ts +1 -1
  158. package/src/v2/parsing/job/job.js +1 -3
  159. package/src/v2/parsing/job/jobResponse.d.ts +3 -0
  160. package/src/v2/parsing/job/jobResponse.js +3 -0
  161. package/src/v2/parsing/search/index.d.ts +4 -0
  162. package/src/v2/parsing/search/index.js +4 -0
  163. package/src/v2/parsing/search/modelWebhook.d.ts +19 -0
  164. package/src/v2/parsing/search/modelWebhook.js +10 -0
  165. package/src/v2/parsing/search/paginationMetadata.d.ts +24 -0
  166. package/src/v2/parsing/search/paginationMetadata.js +19 -0
  167. package/src/v2/parsing/search/searchModel.d.ts +25 -0
  168. package/src/v2/parsing/search/searchModel.js +19 -0
  169. package/src/v2/parsing/search/searchResponse.d.ts +19 -0
  170. package/src/v2/parsing/search/searchResponse.js +24 -0
  171. package/src/v2/product/classification/classification.d.ts +3 -0
  172. package/src/v2/product/classification/classification.js +3 -0
  173. package/src/v2/product/classification/classificationClassifier.d.ts +2 -0
  174. package/src/v2/product/classification/classificationClassifier.js +2 -0
  175. package/src/v2/product/classification/classificationInference.d.ts +2 -0
  176. package/src/v2/product/classification/classificationInference.js +2 -0
  177. package/src/v2/product/classification/classificationResponse.d.ts +1 -0
  178. package/src/v2/product/classification/classificationResponse.js +1 -0
  179. package/src/v2/product/classification/classificationResult.d.ts +2 -0
  180. package/src/v2/product/classification/classificationResult.js +2 -0
  181. package/src/v2/product/crop/crop.d.ts +3 -0
  182. package/src/v2/product/crop/crop.js +3 -0
  183. package/src/v2/product/crop/cropInference.d.ts +2 -0
  184. package/src/v2/product/crop/cropInference.js +2 -0
  185. package/src/v2/product/crop/cropItem.d.ts +2 -0
  186. package/src/v2/product/crop/cropItem.js +2 -0
  187. package/src/v2/product/crop/cropResponse.d.ts +1 -0
  188. package/src/v2/product/crop/cropResponse.js +1 -0
  189. package/src/v2/product/crop/cropResult.d.ts +2 -0
  190. package/src/v2/product/crop/cropResult.js +2 -0
  191. package/src/v2/product/extraction/dataSchemaActiveOption.d.ts +1 -0
  192. package/src/v2/product/extraction/dataSchemaActiveOption.js +1 -0
  193. package/src/v2/product/extraction/extraction.d.ts +3 -0
  194. package/src/v2/product/extraction/extraction.js +3 -0
  195. package/src/v2/product/extraction/extractionActiveOptions.d.ts +2 -0
  196. package/src/v2/product/extraction/extractionActiveOptions.js +2 -0
  197. package/src/v2/product/extraction/extractionInference.d.ts +2 -0
  198. package/src/v2/product/extraction/extractionInference.js +2 -0
  199. package/src/v2/product/extraction/extractionResponse.d.ts +1 -0
  200. package/src/v2/product/extraction/extractionResponse.js +1 -0
  201. package/src/v2/product/extraction/extractionResult.d.ts +2 -0
  202. package/src/v2/product/extraction/extractionResult.js +2 -0
  203. package/src/v2/product/extraction/params/dataSchema.d.ts +9 -6
  204. package/src/v2/product/extraction/params/dataSchema.js +2 -0
  205. package/src/v2/product/extraction/params/dataSchemaField.d.ts +25 -1
  206. package/src/v2/product/extraction/params/dataSchemaField.js +3 -0
  207. package/src/v2/product/extraction/params/dataSchemaReplace.d.ts +9 -4
  208. package/src/v2/product/extraction/params/dataSchemaReplace.js +2 -0
  209. package/src/v2/product/ocr/ocr.d.ts +3 -0
  210. package/src/v2/product/ocr/ocr.js +3 -0
  211. package/src/v2/product/ocr/ocrInference.d.ts +2 -0
  212. package/src/v2/product/ocr/ocrInference.js +2 -0
  213. package/src/v2/product/ocr/ocrPage.d.ts +2 -0
  214. package/src/v2/product/ocr/ocrPage.js +2 -0
  215. package/src/v2/product/ocr/ocrResponse.d.ts +1 -0
  216. package/src/v2/product/ocr/ocrResponse.js +1 -0
  217. package/src/v2/product/ocr/ocrResult.d.ts +1 -0
  218. package/src/v2/product/ocr/ocrResult.js +1 -0
  219. package/src/v2/product/ocr/ocrWord.d.ts +2 -0
  220. package/src/v2/product/ocr/ocrWord.js +2 -0
  221. package/src/v2/product/split/split.d.ts +3 -0
  222. package/src/v2/product/split/split.js +3 -0
  223. package/src/v2/product/split/splitInference.d.ts +2 -0
  224. package/src/v2/product/split/splitInference.js +2 -0
  225. package/src/v2/product/split/splitRange.d.ts +1 -0
  226. package/src/v2/product/split/splitRange.js +1 -0
  227. package/src/v2/product/split/splitResponse.d.ts +1 -0
  228. package/src/v2/product/split/splitResponse.js +1 -0
  229. package/src/v2/product/split/splitResult.d.ts +1 -0
  230. 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
- ### :boom: :recycle: base for v5
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.4.0",
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-for-dist": "tsc --build && tsc-alias && cp LICENSE README.md CHANGELOG.md ./dist",
27
+ "build:dist": "tsc --build && tsc-alias && cp LICENSE README.md CHANGELOG.md ./dist",
28
28
  "clean": "rm -rf ./dist ./docs/_build",
29
- "test": "mocha --grep '#OptionalDepsRemoved' --invert 'tests/**/*.spec.ts'",
30
- "test-light": "mocha --grep '#OptionalDepsRequired' --invert 'tests/**/*.spec.ts'",
31
- "test-integration": "mocha --grep '#OptionalDepsRemoved' --invert 'tests/**/*.integration.ts'",
32
- "test-integration-light": "mocha --grep '#OptionalDepsRequired' --invert 'tests/**/*.integration.ts'",
33
- "test-v2": "tsc --noEmit && node --import tsx --test 'tests/v2/**/*.spec.ts'",
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-fix": "tsc --noEmit && eslint --fix --report-unused-disable-directives './src/**/*.ts' './tests/**/*.ts'",
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-for-dist": "typedoc --out docs/_build ./src/index.ts && cp -r ./docs/code_samples ./docs/_build/"
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": "~0.34.5"
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
- "@types/mocha": "^10.0.10",
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.3",
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
- "mocha": "^11.7.5",
73
- "tsc-alias": "^1.8.16",
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",
@@ -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
  }
@@ -7,6 +7,7 @@ export class BBox {
7
7
  this.xMax = xMax;
8
8
  this.yMax = yMax;
9
9
  }
10
+ /** Returns a bounding box that contains this box and another one. */
10
11
  mergeBbox(bbox) {
11
12
  return mergeBbox(this, bbox);
12
13
  }
@@ -1,4 +1,7 @@
1
+ /** Numeric range boundaries. */
1
2
  export type MinMax = {
3
+ /** Lower bound. */
2
4
  min: number;
5
+ /** Upper bound. */
3
6
  max: number;
4
7
  };
@@ -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]);
@@ -8,6 +8,7 @@ export interface RequestOptions {
8
8
  timeoutSecs: number;
9
9
  headers: any;
10
10
  body?: FormData | string;
11
+ queryParams?: Record<string, string>;
11
12
  }
12
13
  export interface BaseHttpResponse {
13
14
  messageObj: any;
@@ -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
- url ?? (url = `https://${options.hostname}${options.path}`);
24
- const response = await request(url, {
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;
@@ -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
- pageId?: number;
10
- elementId?: number;
11
- constructor(buffer: Uint8Array, fileName: string, pageId?: number, elementId?: number);
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
- asSource(): BufferInput;
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
- asSource() {
95
+ asInputSource() {
96
96
  return new BufferInput({
97
97
  buffer: this.buffer,
98
98
  filename: this.filename,
@@ -1,4 +1,5 @@
1
1
  import { ExtractedImage } from "../image/index.js";
2
+ /** Collection of extracted image artifacts. */
2
3
  export declare class ExtractedImages extends Array<ExtractedImage> {
3
4
  constructor(...items: ExtractedImage[]);
4
5
  }
@@ -1,3 +1,4 @@
1
+ /** Collection of extracted image artifacts. */
1
2
  export class ExtractedImages extends Array {
2
3
  constructor(...items) {
3
4
  super(...items);
@@ -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<ArrayBufferLike>>;
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 { ExtractedImage } from "../image/extractedImage.js";
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<ExtractedImage[]>;
11
+ export declare function extractImagesFromPolygon(inputSource: LocalInputSource, polygonsPerPage: Map<number, Polygon[]>, quality?: number): Promise<ExtractedImages>;
12
12
  /**
13
- * Extracts elements from a page based off of a list of bounding boxes.
14
- *
15
- * @param pdfPage PDF Page to extract from.
16
- * @param polygons List of coordinates to pull the elements from.
17
- * @param asImage Whether to return the extracted elements as images.
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 = (await extractFromPage(pdfPage, polygons, true, quality));
30
- const extractedImages = extractions.map((v, i) => new ExtractedImage(v, inputSource.filename + `_page${pageId}-${i}.jpg`, pageId, i));
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
- * Extracts elements from a page based off of a list of bounding boxes.
37
- *
38
- * @param pdfPage PDF Page to extract from.
39
- * @param polygons List of coordinates to pull the elements from.
40
- * @param asImage Whether to return the extracted elements as images.
41
- * @param quality JPEG quality of extracted images, given as number between 0 and 1.
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 && (quality < 0)) {
48
- throw new MindeeImageError("Quality must be a number between 0 and 1");
49
- }
50
- if (quality && quality > 1) {
51
- logger.warn("Quality is greater than 1, this operation will apply a manual upscale on the output." +
52
- " Use only if you know what you are doing.");
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 newWidth = width * (getMinMaxX(polygon).max - getMinMaxX(polygon).min);
64
- const newHeight = height * (getMinMaxY(polygon).max - getMinMaxY(polygon).min);
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: getMinMaxX(polygon).min * width,
67
- right: getMinMaxX(polygon).max * width,
68
- top: height - (getMinMaxY(polygon).min * height),
69
- bottom: height - (getMinMaxY(polygon).max * height),
113
+ left: minX * width,
114
+ right: maxX * width,
115
+ top: height - (minY * height),
116
+ bottom: height - (maxY * height),
70
117
  });
71
- let finalWidth;
72
- let finalHeight;
73
- if (orientation === 90 || orientation === 270) {
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
- if (orientation === 0) {
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
- if (asImage) {
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 {};
@@ -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;