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
@@ -1,7 +1,9 @@
1
1
  import { PositionField } from "../../../../v1/parsing/standard/position.js";
2
2
  import { StringDict } from "../../../../parsing/stringDict.js";
3
3
  import { ExtraField } from "./extras.js";
4
+ /** Cropper extra payload returned by compatible APIs. */
4
5
  export declare class CropperExtra extends ExtraField {
6
+ /** Cropped regions detected on the page. */
5
7
  cropping: PositionField[];
6
8
  constructor(rawPrediction: StringDict, pageId?: number);
7
9
  /**
@@ -1,9 +1,12 @@
1
1
  import { PositionField } from "../../../../v1/parsing/standard/position.js";
2
+ // eslint-disable-next-line no-restricted-imports
2
3
  import { cleanOutString } from "../summaryHelper.js";
3
4
  import { ExtraField } from "./extras.js";
5
+ /** Cropper extra payload returned by compatible APIs. */
4
6
  export class CropperExtra extends ExtraField {
5
7
  constructor(rawPrediction, pageId) {
6
8
  super();
9
+ /** Cropped regions detected on the page. */
7
10
  this.cropping = [];
8
11
  if (rawPrediction["cropping"] !== undefined) {
9
12
  rawPrediction["cropping"].forEach((crop) => {
@@ -1,9 +1,12 @@
1
+ /** Base class for optional extras attached to predictions. */
1
2
  export declare abstract class ExtraField {
2
3
  }
3
4
  interface ExtraDict<T extends ExtraField> {
4
5
  [key: string]: T | (() => string);
5
6
  }
7
+ /** Dictionary-like container for extra fields. */
6
8
  export declare class Extras<ExtraT extends ExtraField = ExtraField> implements ExtraDict<ExtraT> {
9
+ /** Dynamic map of extra values keyed by extra name. */
7
10
  [key: string]: ExtraT | (() => string);
8
11
  constructor(fields: Record<string, ExtraT>);
9
12
  /**
@@ -1,5 +1,7 @@
1
+ /** Base class for optional extras attached to predictions. */
1
2
  export class ExtraField {
2
3
  }
4
+ /** Dictionary-like container for extra fields. */
3
5
  export class Extras {
4
6
  constructor(fields) {
5
7
  if (Object.keys(fields).length > 0) {
@@ -1,7 +1,10 @@
1
1
  import { StringDict } from "../../../../parsing/stringDict.js";
2
2
  import { ExtraField } from "./extras.js";
3
+ /** Full-text OCR extra payload returned by compatible APIs. */
3
4
  export declare class FullTextOcrExtra extends ExtraField {
5
+ /** Concatenated OCR content. */
4
6
  content?: string;
7
+ /** OCR language hints associated with the content. */
5
8
  languages?: string;
6
9
  constructor(rawPrediction: StringDict);
7
10
  /**
@@ -1,4 +1,5 @@
1
1
  import { ExtraField } from "./extras.js";
2
+ /** Full-text OCR extra payload returned by compatible APIs. */
2
3
  export class FullTextOcrExtra extends ExtraField {
3
4
  constructor(rawPrediction) {
4
5
  super();
@@ -1,5 +1,6 @@
1
1
  import { ExtraField } from "./extras.js";
2
2
  import { StringDict } from "../../../../parsing/stringDict.js";
3
+ /** RAG extra payload returned by compatible APIs. */
3
4
  export declare class RAGExtra extends ExtraField {
4
5
  /**
5
6
  * ID reference of the document matched by the Retrieval-Augmented Generation.
@@ -1,4 +1,5 @@
1
1
  import { ExtraField } from "./extras.js";
2
+ /** RAG extra payload returned by compatible APIs. */
2
3
  export class RAGExtra extends ExtraField {
3
4
  constructor(rawPrediction) {
4
5
  super();
@@ -1,3 +1,4 @@
1
+ // eslint-disable-next-line no-restricted-imports
1
2
  import { ApiResponse } from "../apiResponse.js";
2
3
  /**
3
4
  * Wrapper for feedback response.
@@ -10,7 +10,7 @@ export { AsyncPredictResponse } from "./asyncPredictResponse.js";
10
10
  export { PredictResponse } from "./predictResponse.js";
11
11
  export { Prediction } from "./prediction.js";
12
12
  export { Page } from "./page.js";
13
- export { cleanOutString, lineSeparator, floatToString, cleanSpecialChars } from "./summaryHelper.js";
13
+ export { cleanOutString, lineSeparator, floatToString, cleanSpecialChars, cleanAndTruncate } from "./summaryHelper.js";
14
14
  export * as extras from "./extras/index.js";
15
15
  export { parseDate } from "../../../parsing/dateParser.js";
16
16
  export { WorkflowResponse } from "./workflowResponse.js";
@@ -9,7 +9,7 @@ export { AsyncPredictResponse } from "./asyncPredictResponse.js";
9
9
  export { PredictResponse } from "./predictResponse.js";
10
10
  export { Prediction } from "./prediction.js";
11
11
  export { Page } from "./page.js";
12
- export { cleanOutString, lineSeparator, floatToString, cleanSpecialChars } from "./summaryHelper.js";
12
+ export { cleanOutString, lineSeparator, floatToString, cleanSpecialChars, cleanAndTruncate } from "./summaryHelper.js";
13
13
  export * as extras from "./extras/index.js";
14
14
  export { parseDate } from "../../../parsing/dateParser.js";
15
15
  export { WorkflowResponse } from "./workflowResponse.js";
@@ -4,6 +4,7 @@ import type { Prediction } from "./prediction.js";
4
4
  import { Product } from "./product.js";
5
5
  import { Extras } from "./extras/index.js";
6
6
  /**
7
+ * Generic base class for parsed v1 inference payloads.
7
8
  *
8
9
  * @typeParam DocT an extension of a `Prediction`. Is generic by default to
9
10
  * allow for easier optional `PageT` generic typing.
@@ -29,6 +30,7 @@ export declare abstract class Inference<DocT extends Prediction = Prediction, Pa
29
30
  /**
30
31
  * Default string representation.
31
32
  */
33
+ /** Returns a human-readable representation of the inference payload. */
32
34
  toString(): string;
33
35
  /**
34
36
  * Takes in an input string and replaces line breaks with `\n`.
@@ -1,6 +1,7 @@
1
1
  import { CropperExtra, FullTextOcrExtra, RAGExtra } from "./extras/index.js";
2
2
  import { MindeeConfigurationError } from "../../../errors/index.js";
3
3
  /**
4
+ * Generic base class for parsed v1 inference payloads.
4
5
  *
5
6
  * @typeParam DocT an extension of a `Prediction`. Is generic by default to
6
7
  * allow for easier optional `PageT` generic typing.
@@ -35,6 +36,7 @@ export class Inference {
35
36
  /**
36
37
  * Default string representation.
37
38
  */
39
+ /** Returns a human-readable representation of the inference payload. */
38
40
  toString() {
39
41
  let pages = "";
40
42
  if (this.pages.toString().length > 0) {
@@ -1,2 +1,3 @@
1
+ /** Marker base type for v1 prediction payload models. */
1
2
  export declare class Prediction {
2
3
  }
@@ -1,2 +1,3 @@
1
+ /** Marker base type for v1 prediction payload models. */
1
2
  export class Prediction {
2
3
  }
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Cleans a string by removing all new line characters.
3
+ * @param outStr Output string.
4
+ */
1
5
  export declare function cleanOutString(outStr: string): string;
2
6
  /**
3
7
  *
@@ -9,9 +13,16 @@ export declare function lineSeparator(columnSizes: number[], separator: string):
9
13
  /**
10
14
  * Replaces all special characters like \n, \r, \t, with an equivalent that can be displayed on a single line.
11
15
  * Also trims line breaks at the end of the string.
12
- * @param outStr
16
+ * @param outStr Output string.
13
17
  */
14
18
  export declare function cleanSpecialChars(outStr: string): string;
19
+ /**
20
+ * Cleans a string with `cleanSpecialChars` and truncates it to `maxLength` characters,
21
+ * appending "..." when truncation occurs. Returns an empty string for null/undefined/empty input.
22
+ * @param value String to clean and truncate.
23
+ * @param maxLength Maximum length of the returned string (including the "..." suffix when truncated).
24
+ */
25
+ export declare function cleanAndTruncate(value: string | null | undefined, maxLength: number): string;
15
26
  /**
16
27
  * Return a float as a string with at least 2 levels of precision.
17
28
  */
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Cleans a string by removing all new line characters.
3
+ * @param outStr Output string.
4
+ */
1
5
  export function cleanOutString(outStr) {
2
6
  const lines = / \n/gm;
3
7
  return outStr.replace(lines, "\n");
@@ -18,7 +22,7 @@ export function lineSeparator(columnSizes, separator) {
18
22
  /**
19
23
  * Replaces all special characters like \n, \r, \t, with an equivalent that can be displayed on a single line.
20
24
  * Also trims line breaks at the end of the string.
21
- * @param outStr
25
+ * @param outStr Output string.
22
26
  */
23
27
  export function cleanSpecialChars(outStr) {
24
28
  return outStr
@@ -26,6 +30,19 @@ export function cleanSpecialChars(outStr) {
26
30
  .replace(/\r/g, "\\r")
27
31
  .replace(/\t/g, "\\t");
28
32
  }
33
+ /**
34
+ * Cleans a string with `cleanSpecialChars` and truncates it to `maxLength` characters,
35
+ * appending "..." when truncation occurs. Returns an empty string for null/undefined/empty input.
36
+ * @param value String to clean and truncate.
37
+ * @param maxLength Maximum length of the returned string (including the "..." suffix when truncated).
38
+ */
39
+ export function cleanAndTruncate(value, maxLength) {
40
+ if (!value) {
41
+ return "";
42
+ }
43
+ const cleaned = cleanSpecialChars(value);
44
+ return cleaned.length <= maxLength ? cleaned : cleaned.slice(0, maxLength - 3) + "...";
45
+ }
29
46
  /**
30
47
  * Return a float as a string with at least 2 levels of precision.
31
48
  */
@@ -13,6 +13,10 @@ export declare class GeneratedObjectField {
13
13
  /** All potentially present fields. */
14
14
  [key: string]: string | number | boolean | object | undefined;
15
15
  constructor({ prediction, pageId, }: BaseFieldConstructor);
16
+ private static readonly positionFieldNames;
17
+ private static isPositionField;
18
+ private assignPositionField;
19
+ private assignScalarField;
16
20
  /**
17
21
  * ReSTructured-compliant string representation.
18
22
  Takes into account level of indentation & displays elements as list elements.
@@ -25,7 +29,9 @@ export declare class GeneratedObjectField {
25
29
  * @returns
26
30
  */
27
31
  private toNumberString;
32
+ /** Returns the default string representation. */
28
33
  toString(): string;
34
+ /** Returns a field value by key from this generated object. */
29
35
  get(fieldName: string): string | number | boolean | object | undefined;
30
36
  }
31
37
  /**
@@ -8,44 +8,50 @@ export class GeneratedObjectField {
8
8
  if (fieldName === "page_id") {
9
9
  itemPageId = fieldValue;
10
10
  }
11
- else if (["polygon", "rectangle", "quadrangle", "bounding_box"].includes(fieldName)) {
12
- Object.assign(this, {
13
- [fieldName]: new PositionField({
14
- prediction: { [fieldName]: fieldValue },
15
- valueKey: fieldName,
16
- pageId: pageId,
17
- }),
18
- });
19
- this.printableValues.push(fieldName);
20
- }
21
11
  else if (fieldName === "confidence") {
22
12
  this.confidence = fieldValue;
23
13
  }
24
14
  else if (fieldName === "raw_value") {
25
15
  this.rawValue = fieldValue;
26
16
  }
17
+ else if (GeneratedObjectField.isPositionField(fieldName)) {
18
+ this.assignPositionField(fieldName, fieldValue, pageId);
19
+ }
27
20
  else {
28
- if (fieldValue !== null &&
29
- fieldValue !== undefined &&
30
- typeof fieldValue === "number" &&
31
- !isNaN(fieldValue) &&
32
- fieldName !== "degrees") {
33
- Object.assign(this, { [fieldName]: this.toNumberString(fieldValue) });
34
- }
35
- else if (typeof fieldValue === "boolean") {
36
- Object.assign(this, { [fieldName]: fieldValue });
37
- }
38
- else {
39
- Object.assign(this, {
40
- [fieldName]: (fieldValue !== undefined && fieldValue !== null) ?
41
- String(fieldValue) : null,
42
- });
43
- }
44
- this.printableValues.push(fieldName);
21
+ this.assignScalarField(fieldName, fieldValue);
45
22
  }
46
23
  this.pageId = pageId ?? itemPageId;
47
24
  }
48
25
  }
26
+ static isPositionField(fieldName) {
27
+ return GeneratedObjectField.positionFieldNames.has(fieldName);
28
+ }
29
+ assignPositionField(fieldName, fieldValue, pageId) {
30
+ Object.assign(this, {
31
+ [fieldName]: new PositionField({
32
+ prediction: { [fieldName]: fieldValue },
33
+ valueKey: fieldName,
34
+ pageId: pageId,
35
+ }),
36
+ });
37
+ this.printableValues.push(fieldName);
38
+ }
39
+ assignScalarField(fieldName, fieldValue) {
40
+ if (typeof fieldValue === "number" &&
41
+ !isNaN(fieldValue) &&
42
+ fieldName !== "degrees") {
43
+ Object.assign(this, { [fieldName]: this.toNumberString(fieldValue) });
44
+ }
45
+ else if (typeof fieldValue === "boolean") {
46
+ Object.assign(this, { [fieldName]: fieldValue });
47
+ }
48
+ else {
49
+ Object.assign(this, {
50
+ [fieldName]: (fieldValue !== undefined && fieldValue !== null) ? String(fieldValue) : null,
51
+ });
52
+ }
53
+ this.printableValues.push(fieldName);
54
+ }
49
55
  /**
50
56
  * ReSTructured-compliant string representation.
51
57
  Takes into account level of indentation & displays elements as list elements.
@@ -71,13 +77,18 @@ export class GeneratedObjectField {
71
77
  }
72
78
  return n.toString();
73
79
  }
80
+ /** Returns the default string representation. */
74
81
  toString() {
75
82
  return this.toStringLevel();
76
83
  }
84
+ /** Returns a field value by key from this generated object. */
77
85
  get(fieldName) {
78
86
  return this[fieldName];
79
87
  }
80
88
  }
89
+ GeneratedObjectField.positionFieldNames = new Set([
90
+ "polygon", "rectangle", "quadrangle", "bounding_box",
91
+ ]);
81
92
  /**
82
93
  * Checks whether a field is a custom object or not.
83
94
  * @param strDict input dictionary to check.
@@ -6,5 +6,6 @@ import { StringDict } from "../../parsing/index.js";
6
6
  * Note: Has to be initialized through init() before use.
7
7
  */
8
8
  export declare class LocalResponse extends LocalResponseBase {
9
+ /** Loads a local JSON payload into a typed prediction response wrapper. */
9
10
  loadPrediction<T extends Inference>(productClass: new (httpResponse: StringDict) => T): Promise<AsyncPredictResponse<T> | PredictResponse<T>>;
10
11
  }
@@ -6,6 +6,7 @@ import { MindeeError } from "../../errors/index.js";
6
6
  * Note: Has to be initialized through init() before use.
7
7
  */
8
8
  export class LocalResponse extends LocalResponseBase {
9
+ /** Loads a local JSON payload into a typed prediction response wrapper. */
9
10
  async loadPrediction(productClass) {
10
11
  /**
11
12
  * Load a prediction.
@@ -5,10 +5,15 @@ import { StringDict } from "../../../parsing/stringDict.js";
5
5
  * @property {boolean} reconstructed - Is the object reconstructed (not extracted by the API).
6
6
  * @property {number} pageId - Page ID for multi-page document.
7
7
  */
8
+ /** Constructor payload shared by standard v1 fields. */
8
9
  export interface BaseFieldConstructor {
10
+ /** Raw field payload from API response. */
9
11
  prediction: StringDict;
12
+ /** Key to read from `prediction` as field value. */
10
13
  valueKey?: string;
14
+ /** Whether the field was reconstructed locally. */
11
15
  reconstructed?: boolean;
16
+ /** Optional page identifier for multi-page documents. */
12
17
  pageId?: number;
13
18
  }
14
19
  /**
@@ -25,6 +30,7 @@ export declare class BaseField {
25
30
  * @param {BaseFieldConstructor} constructor Constructor parameters.
26
31
  */
27
32
  constructor({ prediction, valueKey, reconstructed, pageId, }: BaseFieldConstructor);
33
+ /** Compares two field values for semantic equality. */
28
34
  compare(other: BaseField): boolean;
29
35
  /**
30
36
  * @param {BaseField[]} array - Array of Fields
@@ -17,6 +17,7 @@ export class BaseField {
17
17
  this.pageId = pageId !== undefined ? pageId : prediction["page_id"];
18
18
  }
19
19
  }
20
+ /** Compares two field values for semantic equality. */
20
21
  compare(other) {
21
22
  if (this.value === null && other.value === null)
22
23
  return true;
@@ -4,7 +4,7 @@ export interface FieldConstructor {
4
4
  prediction: StringDict;
5
5
  valueKey?: string;
6
6
  reconstructed?: boolean;
7
- pageId?: number | undefined;
7
+ pageId?: number;
8
8
  }
9
9
  /**
10
10
  * A field containing a text value.
@@ -9,6 +9,7 @@ export declare class CompanyRegistrationField extends Field {
9
9
  /** Type of company registration. */
10
10
  type: string;
11
11
  constructor({ prediction, valueKey, reconstructed, pageId, }: BaseFieldConstructor);
12
+ /** Returns a row-formatted representation for table output. */
12
13
  toTableLine(): string;
13
14
  toString(): string;
14
15
  private printableValues;
@@ -8,6 +8,7 @@ export class CompanyRegistrationField extends Field {
8
8
  super({ prediction, valueKey, reconstructed, pageId });
9
9
  this.type = prediction["type"];
10
10
  }
11
+ /** Returns a row-formatted representation for table output. */
11
12
  toTableLine() {
12
13
  const printable = this.printableValues();
13
14
  return `| ${printable["type"].padEnd(15)} | ${printable["value"].padEnd(20)} `;
@@ -14,5 +14,6 @@ export declare class DateField extends Field {
14
14
  * @param {BaseFieldConstructor} constructor Constructor parameters.
15
15
  */
16
16
  constructor({ prediction, valueKey, reconstructed, pageId, }: BaseFieldConstructor);
17
+ /** Compares two dates by calendar day (year/month/day). */
17
18
  static compareDates(date1: Date, date2: Date): boolean;
18
19
  }
@@ -23,6 +23,7 @@ export class DateField extends Field {
23
23
  }
24
24
  }
25
25
  }
26
+ /** Compares two dates by calendar day (year/month/day). */
26
27
  static compareDates(date1, date2) {
27
28
  return date1.getFullYear() === date2.getFullYear() &&
28
29
  date1.getMonth() === date2.getMonth() &&
@@ -26,15 +26,15 @@ interface PaymentDetailsConstructor {
26
26
  export declare class PaymentDetailsField extends Field {
27
27
  #private;
28
28
  /** Synonym for the `iban` property */
29
- value?: string | undefined;
29
+ value?: string;
30
30
  /** The account number. */
31
- accountNumber: string | undefined;
31
+ accountNumber?: string;
32
32
  /** The International Bank Account Number (IBAN). */
33
- iban: string | undefined;
33
+ iban?: string;
34
34
  /** The routing number. */
35
- routingNumber: string | undefined;
35
+ routingNumber?: string;
36
36
  /** The bank's SWIFT Business Identifier Code (BIC). */
37
- swift: string | undefined;
37
+ swift?: string;
38
38
  /**
39
39
  * @param {PaymentDetailsConstructor} constructor Constructor parameters.
40
40
  */
@@ -3,7 +3,7 @@ import { Polygon } from "../../../geometry/index.js";
3
3
  export interface PositionFieldConstructor {
4
4
  prediction: StringDict;
5
5
  valueKey?: string;
6
- pageId?: number | undefined;
6
+ pageId?: number;
7
7
  }
8
8
  /**
9
9
  * A field indicating a position or area on the document.
@@ -18,7 +18,7 @@ export declare class PositionField {
18
18
  /** Rectangle that may be oriented (can go beyond the canvas). */
19
19
  rectangle: Polygon;
20
20
  /** The document page on which the information was found. */
21
- pageId: number | undefined;
21
+ pageId?: number;
22
22
  constructor({ prediction, pageId }: PositionFieldConstructor);
23
23
  /**
24
24
  * Default string representation.
@@ -44,6 +44,7 @@ export declare class TaxField extends Field {
44
44
  */
45
45
  export declare class Taxes extends Array<TaxField> {
46
46
  #private;
47
+ /** Populates the taxes collection from raw prediction entries. */
47
48
  init(prediction: StringDict[] | undefined, pageId: number | undefined): this;
48
49
  /**
49
50
  * Default string representation.
@@ -86,6 +86,7 @@ export class Taxes extends Array {
86
86
  super(...arguments);
87
87
  _Taxes_instances.add(this);
88
88
  }
89
+ /** Populates the taxes collection from raw prediction entries. */
89
90
  init(prediction = [], pageId) {
90
91
  for (const entry of prediction) {
91
92
  this.push(new TaxField({
@@ -4,7 +4,7 @@ export interface FieldConstructor {
4
4
  prediction: StringDict;
5
5
  valueKey?: string;
6
6
  reconstructed?: boolean;
7
- pageId?: number | undefined;
7
+ pageId?: number;
8
8
  }
9
9
  /**
10
10
  * A field containing a text value.
@@ -1,12 +1,15 @@
1
1
  import { Polygon } from "../../../geometry/index.js";
2
2
  import { StringDict } from "../../../parsing/index.js";
3
+ /** OCR word item with text, confidence, and location polygon. */
3
4
  export declare class Word {
4
5
  /**
5
6
  * Contains the relative vertices coordinates (points) of a polygon containing
6
7
  * the field in the document.
7
8
  */
8
9
  polygon: Polygon;
10
+ /** OCR text content for the word. */
9
11
  text: string;
12
+ /** Confidence score for the OCR word. */
10
13
  confidence: number;
11
14
  constructor(rawPrediction: StringDict);
12
15
  }
@@ -1,4 +1,5 @@
1
1
  import { Polygon } from "../../../geometry/index.js";
2
+ /** OCR word item with text, confidence, and location polygon. */
2
3
  export class Word {
3
4
  constructor(rawPrediction) {
4
5
  this.polygon = new Polygon(...rawPrediction["polygon"]);
@@ -3,8 +3,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _FinancialDocumentV1LineItem_instances, _FinancialDocumentV1LineItem_printableValues;
7
- import { cleanSpecialChars, floatToString } from "../../../v1/parsing/common/index.js";
6
+ var _FinancialDocumentV1LineItem_instances, _a, _FinancialDocumentV1LineItem_parseNumber, _FinancialDocumentV1LineItem_printableValues;
7
+ import { cleanAndTruncate, floatToString } from "../../../v1/parsing/common/index.js";
8
8
  import { Polygon } from "../../../geometry/index.js";
9
9
  /**
10
10
  * List of line item present on the document.
@@ -21,47 +21,12 @@ export class FinancialDocumentV1LineItem {
21
21
  this.polygon = new Polygon();
22
22
  this.description = prediction["description"];
23
23
  this.productCode = prediction["product_code"];
24
- if (prediction["quantity"] !== undefined &&
25
- prediction["quantity"] !== null &&
26
- !isNaN(prediction["quantity"])) {
27
- this.quantity = +parseFloat(prediction["quantity"]);
28
- }
29
- else {
30
- this.quantity = null;
31
- }
32
- if (prediction["tax_amount"] !== undefined &&
33
- prediction["tax_amount"] !== null &&
34
- !isNaN(prediction["tax_amount"])) {
35
- this.taxAmount = +parseFloat(prediction["tax_amount"]);
36
- }
37
- else {
38
- this.taxAmount = null;
39
- }
40
- if (prediction["tax_rate"] !== undefined &&
41
- prediction["tax_rate"] !== null &&
42
- !isNaN(prediction["tax_rate"])) {
43
- this.taxRate = +parseFloat(prediction["tax_rate"]);
44
- }
45
- else {
46
- this.taxRate = null;
47
- }
48
- if (prediction["total_amount"] !== undefined &&
49
- prediction["total_amount"] !== null &&
50
- !isNaN(prediction["total_amount"])) {
51
- this.totalAmount = +parseFloat(prediction["total_amount"]);
52
- }
53
- else {
54
- this.totalAmount = null;
55
- }
24
+ this.quantity = __classPrivateFieldGet(_a, _a, "m", _FinancialDocumentV1LineItem_parseNumber).call(_a, prediction["quantity"]);
25
+ this.taxAmount = __classPrivateFieldGet(_a, _a, "m", _FinancialDocumentV1LineItem_parseNumber).call(_a, prediction["tax_amount"]);
26
+ this.taxRate = __classPrivateFieldGet(_a, _a, "m", _FinancialDocumentV1LineItem_parseNumber).call(_a, prediction["tax_rate"]);
27
+ this.totalAmount = __classPrivateFieldGet(_a, _a, "m", _FinancialDocumentV1LineItem_parseNumber).call(_a, prediction["total_amount"]);
56
28
  this.unitMeasure = prediction["unit_measure"];
57
- if (prediction["unit_price"] !== undefined &&
58
- prediction["unit_price"] !== null &&
59
- !isNaN(prediction["unit_price"])) {
60
- this.unitPrice = +parseFloat(prediction["unit_price"]);
61
- }
62
- else {
63
- this.unitPrice = null;
64
- }
29
+ this.unitPrice = __classPrivateFieldGet(_a, _a, "m", _FinancialDocumentV1LineItem_parseNumber).call(_a, prediction["unit_price"]);
65
30
  this.pageId = prediction["page_id"];
66
31
  this.confidence = prediction["confidence"] ? prediction.confidence : 0.0;
67
32
  if (prediction["polygon"]) {
@@ -114,27 +79,20 @@ export class FinancialDocumentV1LineItem {
114
79
  " |");
115
80
  }
116
81
  }
117
- _FinancialDocumentV1LineItem_instances = new WeakSet(), _FinancialDocumentV1LineItem_printableValues = function _FinancialDocumentV1LineItem_printableValues() {
82
+ _a = FinancialDocumentV1LineItem, _FinancialDocumentV1LineItem_instances = new WeakSet(), _FinancialDocumentV1LineItem_parseNumber = function _FinancialDocumentV1LineItem_parseNumber(value) {
83
+ if (value === undefined || value === null || isNaN(value)) {
84
+ return null;
85
+ }
86
+ return +parseFloat(value);
87
+ }, _FinancialDocumentV1LineItem_printableValues = function _FinancialDocumentV1LineItem_printableValues() {
118
88
  return {
119
- description: this.description ?
120
- this.description.length <= 36 ?
121
- cleanSpecialChars(this.description) :
122
- cleanSpecialChars(this.description).slice(0, 33) + "..." :
123
- "",
124
- productCode: this.productCode ?
125
- this.productCode.length <= 12 ?
126
- cleanSpecialChars(this.productCode) :
127
- cleanSpecialChars(this.productCode).slice(0, 9) + "..." :
128
- "",
89
+ description: cleanAndTruncate(this.description, 36),
90
+ productCode: cleanAndTruncate(this.productCode, 12),
129
91
  quantity: this.quantity !== undefined ? floatToString(this.quantity) : "",
130
92
  taxAmount: this.taxAmount !== undefined ? floatToString(this.taxAmount) : "",
131
93
  taxRate: this.taxRate !== undefined ? floatToString(this.taxRate) : "",
132
94
  totalAmount: this.totalAmount !== undefined ? floatToString(this.totalAmount) : "",
133
- unitMeasure: this.unitMeasure ?
134
- this.unitMeasure.length <= 15 ?
135
- cleanSpecialChars(this.unitMeasure) :
136
- cleanSpecialChars(this.unitMeasure).slice(0, 12) + "..." :
137
- "",
95
+ unitMeasure: cleanAndTruncate(this.unitMeasure, 15),
138
96
  unitPrice: this.unitPrice !== undefined ? floatToString(this.unitPrice) : "",
139
97
  };
140
98
  };
@@ -1,6 +1,7 @@
1
1
  import { Prediction } from "../../../v1/parsing/common/index.js";
2
2
  import { GeneratedListField } from "../../../v1/parsing/generated/index.js";
3
3
  import { StringField } from "../../../v1/parsing/standard/index.js";
4
+ /** Dynamic prediction container for generated v1 products. */
4
5
  export declare class GeneratedV1Prediction implements Prediction {
5
6
  /** Map of all fields in the document. */
6
7
  fields: Map<string, any>;