mindee 5.5.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 (209) hide show
  1. package/CHANGELOG.md +17 -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/baseSettings.d.ts +5 -0
  9. package/src/http/baseSettings.js +2 -0
  10. package/src/image/extractedImage.d.ts +4 -0
  11. package/src/image/extractedImages.d.ts +1 -0
  12. package/src/image/extractedImages.js +1 -0
  13. package/src/image/imageCompressor.d.ts +1 -1
  14. package/src/image/imageExtractor.d.ts +5 -6
  15. package/src/image/imageExtractor.js +71 -73
  16. package/src/input/base64Input.d.ts +3 -0
  17. package/src/input/base64Input.js +3 -0
  18. package/src/input/bufferInput.d.ts +2 -0
  19. package/src/input/bufferInput.js +2 -0
  20. package/src/input/bytesInput.d.ts +3 -0
  21. package/src/input/bytesInput.js +3 -0
  22. package/src/input/inputSource.d.ts +15 -0
  23. package/src/input/inputSource.js +15 -0
  24. package/src/input/localInputSource.d.ts +6 -0
  25. package/src/input/localInputSource.js +3 -0
  26. package/src/input/pathInput.d.ts +4 -0
  27. package/src/input/pathInput.js +3 -0
  28. package/src/input/streamInput.d.ts +4 -0
  29. package/src/input/streamInput.js +4 -0
  30. package/src/input/urlInput.d.ts +12 -0
  31. package/src/input/urlInput.js +52 -10
  32. package/src/logger.js +1 -1
  33. package/src/parsing/dateParser.d.ts +4 -0
  34. package/src/parsing/dateParser.js +5 -1
  35. package/src/parsing/localResponseBase.d.ts +2 -0
  36. package/src/parsing/localResponseBase.js +2 -0
  37. package/src/parsing/stringDict.d.ts +1 -0
  38. package/src/pdf/extractedPdf.d.ts +5 -0
  39. package/src/pdf/extractedPdf.js +1 -0
  40. package/src/pdf/extractedPdfs.d.ts +1 -0
  41. package/src/pdf/extractedPdfs.js +1 -0
  42. package/src/pdf/pdfCompressor.js +12 -0
  43. package/src/pdf/pdfExtractor.js +3 -0
  44. package/src/pdf/pdfOperation.d.ts +3 -0
  45. package/src/pdf/pdfOperation.js +3 -0
  46. package/src/pdf/pdfUtils.js +5 -0
  47. package/src/v1/cli.d.ts +3 -0
  48. package/src/v1/cli.js +84 -26
  49. package/src/v1/client.d.ts +16 -16
  50. package/src/v1/extraction/invoiceSplitterExtractor/extractedInvoiceSplitterImage.d.ts +2 -0
  51. package/src/v1/extraction/invoiceSplitterExtractor/invoiceSplitterExtractor.js +14 -0
  52. package/src/v1/extraction/multiReceiptsExtractor/extractedMultiReceiptImage.d.ts +2 -0
  53. package/src/v1/extraction/multiReceiptsExtractor/multiReceiptsExtractor.js +3 -0
  54. package/src/v1/http/apiSettingsV1.d.ts +5 -0
  55. package/src/v1/http/apiSettingsV1.js +4 -0
  56. package/src/v1/http/errors.d.ts +7 -1
  57. package/src/v1/http/errors.js +65 -86
  58. package/src/v1/http/httpParams.d.ts +12 -0
  59. package/src/v1/parsing/common/asyncPredictResponse.d.ts +4 -0
  60. package/src/v1/parsing/common/asyncPredictResponse.js +5 -2
  61. package/src/v1/parsing/common/executionPriority.d.ts +4 -0
  62. package/src/v1/parsing/common/executionPriority.js +4 -0
  63. package/src/v1/parsing/common/extras/cropperExtra.d.ts +2 -0
  64. package/src/v1/parsing/common/extras/cropperExtra.js +3 -0
  65. package/src/v1/parsing/common/extras/extras.d.ts +3 -0
  66. package/src/v1/parsing/common/extras/extras.js +2 -0
  67. package/src/v1/parsing/common/extras/fullTextOcrExtra.d.ts +3 -0
  68. package/src/v1/parsing/common/extras/fullTextOcrExtra.js +1 -0
  69. package/src/v1/parsing/common/extras/ragExtra.d.ts +1 -0
  70. package/src/v1/parsing/common/extras/ragExtra.js +1 -0
  71. package/src/v1/parsing/common/feedback/feedbackResponse.js +1 -0
  72. package/src/v1/parsing/common/index.d.ts +1 -1
  73. package/src/v1/parsing/common/index.js +1 -1
  74. package/src/v1/parsing/common/inference.d.ts +2 -0
  75. package/src/v1/parsing/common/inference.js +2 -0
  76. package/src/v1/parsing/common/prediction.d.ts +1 -0
  77. package/src/v1/parsing/common/prediction.js +1 -0
  78. package/src/v1/parsing/common/summaryHelper.d.ts +12 -1
  79. package/src/v1/parsing/common/summaryHelper.js +18 -1
  80. package/src/v1/parsing/generated/generatedObject.d.ts +6 -0
  81. package/src/v1/parsing/generated/generatedObject.js +38 -27
  82. package/src/v1/parsing/localResponse.d.ts +1 -0
  83. package/src/v1/parsing/localResponse.js +1 -0
  84. package/src/v1/parsing/standard/base.d.ts +6 -0
  85. package/src/v1/parsing/standard/base.js +1 -0
  86. package/src/v1/parsing/standard/boolean.d.ts +1 -1
  87. package/src/v1/parsing/standard/companyRegistration.d.ts +1 -0
  88. package/src/v1/parsing/standard/companyRegistration.js +1 -0
  89. package/src/v1/parsing/standard/date.d.ts +1 -0
  90. package/src/v1/parsing/standard/date.js +1 -0
  91. package/src/v1/parsing/standard/paymentDetails.d.ts +5 -5
  92. package/src/v1/parsing/standard/position.d.ts +2 -2
  93. package/src/v1/parsing/standard/tax.d.ts +1 -0
  94. package/src/v1/parsing/standard/tax.js +1 -0
  95. package/src/v1/parsing/standard/text.d.ts +1 -1
  96. package/src/v1/parsing/standard/word.d.ts +3 -0
  97. package/src/v1/parsing/standard/word.js +1 -0
  98. package/src/v1/product/financialDocument/financialDocumentV1LineItem.js +16 -58
  99. package/src/v1/product/generated/generatedV1Prediction.d.ts +1 -0
  100. package/src/v1/product/generated/generatedV1Prediction.js +2 -1
  101. package/src/v1/product/invoice/invoiceV4LineItem.js +5 -16
  102. package/src/v1/product/receipt/receiptV5LineItem.js +2 -6
  103. package/src/v1/product/resume/resumeV1Certificate.js +5 -21
  104. package/src/v1/product/resume/resumeV1Education.js +8 -36
  105. package/src/v1/product/resume/resumeV1Language.js +3 -11
  106. package/src/v1/product/resume/resumeV1ProfessionalExperience.js +10 -46
  107. package/src/v1/product/resume/resumeV1SocialNetworksUrl.js +3 -11
  108. package/src/v2/cli.d.ts +3 -0
  109. package/src/v2/cli.js +21 -0
  110. package/src/v2/client.d.ts +1 -0
  111. package/src/v2/client.js +1 -0
  112. package/src/v2/clientOptions/pollingOptions.d.ts +5 -0
  113. package/src/v2/clientOptions/pollingOptions.js +2 -0
  114. package/src/v2/parsing/baseResponse.d.ts +2 -0
  115. package/src/v2/parsing/baseResponse.js +1 -0
  116. package/src/v2/parsing/error/errorDetails.d.ts +1 -0
  117. package/src/v2/parsing/index.d.ts +1 -1
  118. package/src/v2/parsing/index.js +1 -1
  119. package/src/v2/parsing/inference/baseInference.d.ts +2 -0
  120. package/src/v2/parsing/inference/baseInference.js +2 -0
  121. package/src/v2/parsing/inference/failedInferenceResponse.d.ts +33 -0
  122. package/src/v2/parsing/inference/failedInferenceResponse.js +17 -0
  123. package/src/v2/parsing/inference/field/baseField.d.ts +3 -0
  124. package/src/v2/parsing/inference/field/fieldConfidence.d.ts +4 -0
  125. package/src/v2/parsing/inference/field/fieldConfidence.js +4 -0
  126. package/src/v2/parsing/inference/field/fieldFactory.d.ts +5 -0
  127. package/src/v2/parsing/inference/field/fieldFactory.js +5 -0
  128. package/src/v2/parsing/inference/field/fieldLocation.d.ts +1 -0
  129. package/src/v2/parsing/inference/field/fieldLocation.js +1 -0
  130. package/src/v2/parsing/inference/field/inferenceFields.d.ts +5 -0
  131. package/src/v2/parsing/inference/field/inferenceFields.js +4 -0
  132. package/src/v2/parsing/inference/field/listField.d.ts +2 -0
  133. package/src/v2/parsing/inference/field/listField.js +2 -0
  134. package/src/v2/parsing/inference/field/objectField.d.ts +4 -0
  135. package/src/v2/parsing/inference/field/objectField.js +3 -0
  136. package/src/v2/parsing/inference/field/ragMetadata.d.ts +1 -0
  137. package/src/v2/parsing/inference/field/ragMetadata.js +1 -0
  138. package/src/v2/parsing/inference/field/rawText.d.ts +2 -0
  139. package/src/v2/parsing/inference/field/rawText.js +2 -0
  140. package/src/v2/parsing/inference/field/simpleField.d.ts +2 -0
  141. package/src/v2/parsing/inference/field/simpleField.js +2 -0
  142. package/src/v2/parsing/inference/inferenceFile.d.ts +2 -0
  143. package/src/v2/parsing/inference/inferenceFile.js +2 -0
  144. package/src/v2/parsing/inference/inferenceModel.d.ts +2 -0
  145. package/src/v2/parsing/inference/inferenceModel.js +2 -0
  146. package/src/v2/parsing/job/job.d.ts +1 -1
  147. package/src/v2/parsing/job/job.js +1 -3
  148. package/src/v2/parsing/job/jobResponse.d.ts +3 -0
  149. package/src/v2/parsing/job/jobResponse.js +3 -0
  150. package/src/v2/product/classification/classification.d.ts +3 -0
  151. package/src/v2/product/classification/classification.js +3 -0
  152. package/src/v2/product/classification/classificationClassifier.d.ts +2 -0
  153. package/src/v2/product/classification/classificationClassifier.js +2 -0
  154. package/src/v2/product/classification/classificationInference.d.ts +2 -0
  155. package/src/v2/product/classification/classificationInference.js +2 -0
  156. package/src/v2/product/classification/classificationResponse.d.ts +1 -0
  157. package/src/v2/product/classification/classificationResponse.js +1 -0
  158. package/src/v2/product/classification/classificationResult.d.ts +2 -0
  159. package/src/v2/product/classification/classificationResult.js +2 -0
  160. package/src/v2/product/crop/crop.d.ts +3 -0
  161. package/src/v2/product/crop/crop.js +3 -0
  162. package/src/v2/product/crop/cropInference.d.ts +2 -0
  163. package/src/v2/product/crop/cropInference.js +2 -0
  164. package/src/v2/product/crop/cropItem.d.ts +2 -0
  165. package/src/v2/product/crop/cropItem.js +2 -0
  166. package/src/v2/product/crop/cropResponse.d.ts +1 -0
  167. package/src/v2/product/crop/cropResponse.js +1 -0
  168. package/src/v2/product/crop/cropResult.d.ts +2 -0
  169. package/src/v2/product/crop/cropResult.js +2 -0
  170. package/src/v2/product/extraction/dataSchemaActiveOption.d.ts +1 -0
  171. package/src/v2/product/extraction/dataSchemaActiveOption.js +1 -0
  172. package/src/v2/product/extraction/extraction.d.ts +3 -0
  173. package/src/v2/product/extraction/extraction.js +3 -0
  174. package/src/v2/product/extraction/extractionActiveOptions.d.ts +2 -0
  175. package/src/v2/product/extraction/extractionActiveOptions.js +2 -0
  176. package/src/v2/product/extraction/extractionInference.d.ts +2 -0
  177. package/src/v2/product/extraction/extractionInference.js +2 -0
  178. package/src/v2/product/extraction/extractionResponse.d.ts +1 -0
  179. package/src/v2/product/extraction/extractionResponse.js +1 -0
  180. package/src/v2/product/extraction/extractionResult.d.ts +2 -0
  181. package/src/v2/product/extraction/extractionResult.js +2 -0
  182. package/src/v2/product/extraction/params/dataSchema.d.ts +9 -6
  183. package/src/v2/product/extraction/params/dataSchema.js +2 -0
  184. package/src/v2/product/extraction/params/dataSchemaField.d.ts +25 -1
  185. package/src/v2/product/extraction/params/dataSchemaField.js +3 -0
  186. package/src/v2/product/extraction/params/dataSchemaReplace.d.ts +9 -4
  187. package/src/v2/product/extraction/params/dataSchemaReplace.js +2 -0
  188. package/src/v2/product/ocr/ocr.d.ts +3 -0
  189. package/src/v2/product/ocr/ocr.js +3 -0
  190. package/src/v2/product/ocr/ocrInference.d.ts +2 -0
  191. package/src/v2/product/ocr/ocrInference.js +2 -0
  192. package/src/v2/product/ocr/ocrPage.d.ts +2 -0
  193. package/src/v2/product/ocr/ocrPage.js +2 -0
  194. package/src/v2/product/ocr/ocrResponse.d.ts +1 -0
  195. package/src/v2/product/ocr/ocrResponse.js +1 -0
  196. package/src/v2/product/ocr/ocrResult.d.ts +1 -0
  197. package/src/v2/product/ocr/ocrResult.js +1 -0
  198. package/src/v2/product/ocr/ocrWord.d.ts +2 -0
  199. package/src/v2/product/ocr/ocrWord.js +2 -0
  200. package/src/v2/product/split/split.d.ts +3 -0
  201. package/src/v2/product/split/split.js +3 -0
  202. package/src/v2/product/split/splitInference.d.ts +2 -0
  203. package/src/v2/product/split/splitInference.js +2 -0
  204. package/src/v2/product/split/splitRange.d.ts +1 -0
  205. package/src/v2/product/split/splitRange.js +1 -0
  206. package/src/v2/product/split/splitResponse.d.ts +1 -0
  207. package/src/v2/product/split/splitResponse.js +1 -0
  208. package/src/v2/product/split/splitResult.d.ts +1 -0
  209. package/src/v2/product/split/splitResult.js +1 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
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
+
3
17
  ## v5.5.0 - 2026-07-01
4
18
  ### Fixes
5
19
  * :memo: minor tweak to SKILL file
@@ -85,7 +99,7 @@
85
99
 
86
100
 
87
101
  ## v5.0.0-rc1 - 2026-02-17
88
- ### Changes
102
+ ### ¡Breaking Changes!
89
103
  * :boom: drop support for node.js 18
90
104
  * :boom: :recycle: separate polling options
91
105
 
@@ -99,7 +113,8 @@
99
113
 
100
114
 
101
115
  ## v5.0.0-alpha1 - 2026-02-13
102
- ### :boom: :recycle: base for v5
116
+ ### ¡Breaking Changes!
117
+ * :boom: :recycle: base for v5
103
118
  * :arrow_up: update file-type
104
119
  * :recycle: migrate to ES modules (node18)
105
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.5.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]);
@@ -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")) {
@@ -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
  /**
@@ -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>>;
@@ -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
- * 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>[]>;
@@ -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-${pageId}-item-${elementId}.jpg`, pageId, elementId));
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
- * Extracts elements from a page based off of a list of bounding boxes.
38
- *
39
- * @param pdfPage PDF Page to extract from.
40
- * @param polygons List of coordinates to pull the elements from.
41
- * @param asImage Whether to return the extracted elements as images.
42
- * @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.
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 && (quality < 0)) {
49
- throw new MindeeImageError("Quality must be a number between 0 and 1");
50
- }
51
- if (quality && quality > 1) {
52
- logger.warn("Quality is greater than 1, this operation will apply a manual upscale on the output." +
53
- " 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
+ }
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 newWidth = width * (getMinMaxX(polygon).max - getMinMaxX(polygon).min);
65
- 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);
66
112
  const cropped = await tempPdf.embedPage(copiedPage, {
67
- left: getMinMaxX(polygon).min * width,
68
- right: getMinMaxX(polygon).max * width,
69
- top: height - (getMinMaxY(polygon).min * height),
70
- bottom: height - (getMinMaxY(polygon).max * height),
113
+ left: minX * width,
114
+ right: maxX * width,
115
+ top: height - (minY * height),
116
+ bottom: height - (maxY * height),
71
117
  });
72
- let finalWidth;
73
- let finalHeight;
74
- if (orientation === 90 || orientation === 270) {
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
- if (orientation === 0) {
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
- if (asImage) {
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 {};
@@ -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 {};
@@ -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 {};
@@ -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
  }
@@ -4,14 +4,29 @@ export const INPUT_TYPE_BASE64 = "base64";
4
4
  export const INPUT_TYPE_BYTES = "bytes";
5
5
  export const INPUT_TYPE_PATH = "path";
6
6
  export const INPUT_TYPE_BUFFER = "buffer";
7
+ /**
8
+ * Abstract class for input sources.
9
+ */
7
10
  export class InputSource {
8
11
  constructor() {
12
+ /**
13
+ * The file object used by the input source.
14
+ */
9
15
  this.fileObject = "";
16
+ /**
17
+ * Whether the input source has been initialized.
18
+ * @protected
19
+ */
20
+ /** Whether the source has already been initialized. */
10
21
  this.initialized = false;
11
22
  }
23
+ /** Initializes the input source and populates its file object. */
12
24
  async init() {
13
25
  throw new MindeeInputSourceError("not Implemented");
14
26
  }
27
+ /**
28
+ * Returns whether the input source has been initialized.
29
+ */
15
30
  isInitialized() {
16
31
  return this.initialized;
17
32
  }