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
@@ -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>;
@@ -1,13 +1,14 @@
1
1
  import { cleanOutString } from "../../../v1/parsing/common/index.js";
2
2
  import { GeneratedListField, GeneratedObjectField } 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 class GeneratedV1Prediction {
5
6
  constructor() {
6
7
  this.fields = new Map();
7
8
  }
8
9
  toString() {
9
10
  let outStr = "";
10
- const pattern = /^(\n*[ ]*)( {2}):/;
11
+ const pattern = /^(\n* *)( {2}):/;
11
12
  this.fields.forEach((fieldValue, fieldName) => {
12
13
  let strValue = "";
13
14
  if (fieldValue instanceof GeneratedListField &&
@@ -4,12 +4,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _InvoiceV4LineItem_instances, _InvoiceV4LineItem_printableValues;
7
- import { cleanSpecialChars, floatToString } from "../../../v1/parsing/common/index.js";
7
+ import { cleanAndTruncate, floatToString } from "../../../v1/parsing/common/index.js";
8
8
  import { Polygon } from "../../../geometry/index.js";
9
9
  /**
10
10
  * List of all the line items present on the invoice.
11
11
  */
12
12
  export class InvoiceV4LineItem {
13
+ // eslint-disable-next-line sonarjs/cognitive-complexity
13
14
  constructor({ prediction = {} }) {
14
15
  _InvoiceV4LineItem_instances.add(this);
15
16
  /** Confidence score */
@@ -116,25 +117,13 @@ export class InvoiceV4LineItem {
116
117
  }
117
118
  _InvoiceV4LineItem_instances = new WeakSet(), _InvoiceV4LineItem_printableValues = function _InvoiceV4LineItem_printableValues() {
118
119
  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
- "",
120
+ description: cleanAndTruncate(this.description, 36),
121
+ productCode: cleanAndTruncate(this.productCode, 12),
129
122
  quantity: this.quantity !== undefined ? floatToString(this.quantity) : "",
130
123
  taxAmount: this.taxAmount !== undefined ? floatToString(this.taxAmount) : "",
131
124
  taxRate: this.taxRate !== undefined ? floatToString(this.taxRate) : "",
132
125
  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
- "",
126
+ unitMeasure: cleanAndTruncate(this.unitMeasure, 15),
138
127
  unitPrice: this.unitPrice !== undefined ? floatToString(this.unitPrice) : "",
139
128
  };
140
129
  };
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _ReceiptV5LineItem_instances, _ReceiptV5LineItem_printableValues;
7
- import { cleanSpecialChars, floatToString } from "../../../v1/parsing/common/index.js";
7
+ import { cleanAndTruncate, floatToString } from "../../../v1/parsing/common/index.js";
8
8
  import { Polygon } from "../../../geometry/index.js";
9
9
  /**
10
10
  * List of all line items on the receipt.
@@ -82,11 +82,7 @@ export class ReceiptV5LineItem {
82
82
  }
83
83
  _ReceiptV5LineItem_instances = new WeakSet(), _ReceiptV5LineItem_printableValues = function _ReceiptV5LineItem_printableValues() {
84
84
  return {
85
- description: this.description ?
86
- this.description.length <= 36 ?
87
- cleanSpecialChars(this.description) :
88
- cleanSpecialChars(this.description).slice(0, 33) + "..." :
89
- "",
85
+ description: cleanAndTruncate(this.description, 36),
90
86
  quantity: this.quantity !== undefined ? floatToString(this.quantity) : "",
91
87
  totalAmount: this.totalAmount !== undefined ? floatToString(this.totalAmount) : "",
92
88
  unitPrice: this.unitPrice !== undefined ? floatToString(this.unitPrice) : "",
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _ResumeV1Certificate_instances, _ResumeV1Certificate_printableValues;
7
- import { cleanSpecialChars } from "../../../v1/parsing/common/index.js";
7
+ import { cleanAndTruncate } from "../../../v1/parsing/common/index.js";
8
8
  import { Polygon } from "../../../geometry/index.js";
9
9
  /**
10
10
  * The list of certificates obtained by the candidate.
@@ -61,25 +61,9 @@ export class ResumeV1Certificate {
61
61
  }
62
62
  _ResumeV1Certificate_instances = new WeakSet(), _ResumeV1Certificate_printableValues = function _ResumeV1Certificate_printableValues() {
63
63
  return {
64
- grade: this.grade ?
65
- this.grade.length <= 10 ?
66
- cleanSpecialChars(this.grade) :
67
- cleanSpecialChars(this.grade).slice(0, 7) + "..." :
68
- "",
69
- name: this.name ?
70
- this.name.length <= 30 ?
71
- cleanSpecialChars(this.name) :
72
- cleanSpecialChars(this.name).slice(0, 27) + "..." :
73
- "",
74
- provider: this.provider ?
75
- this.provider.length <= 25 ?
76
- cleanSpecialChars(this.provider) :
77
- cleanSpecialChars(this.provider).slice(0, 22) + "..." :
78
- "",
79
- year: this.year ?
80
- this.year.length <= 4 ?
81
- cleanSpecialChars(this.year) :
82
- cleanSpecialChars(this.year).slice(0, 1) + "..." :
83
- "",
64
+ grade: cleanAndTruncate(this.grade, 10),
65
+ name: cleanAndTruncate(this.name, 30),
66
+ provider: cleanAndTruncate(this.provider, 25),
67
+ year: cleanAndTruncate(this.year, 4),
84
68
  };
85
69
  };
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _ResumeV1Education_instances, _ResumeV1Education_printableValues;
7
- import { cleanSpecialChars } from "../../../v1/parsing/common/index.js";
7
+ import { cleanAndTruncate } from "../../../v1/parsing/common/index.js";
8
8
  import { Polygon } from "../../../geometry/index.js";
9
9
  /**
10
10
  * The list of the candidate's educational background.
@@ -76,40 +76,12 @@ export class ResumeV1Education {
76
76
  }
77
77
  _ResumeV1Education_instances = new WeakSet(), _ResumeV1Education_printableValues = function _ResumeV1Education_printableValues() {
78
78
  return {
79
- degreeDomain: this.degreeDomain ?
80
- this.degreeDomain.length <= 15 ?
81
- cleanSpecialChars(this.degreeDomain) :
82
- cleanSpecialChars(this.degreeDomain).slice(0, 12) + "..." :
83
- "",
84
- degreeType: this.degreeType ?
85
- this.degreeType.length <= 25 ?
86
- cleanSpecialChars(this.degreeType) :
87
- cleanSpecialChars(this.degreeType).slice(0, 22) + "..." :
88
- "",
89
- endMonth: this.endMonth ?
90
- this.endMonth.length <= 9 ?
91
- cleanSpecialChars(this.endMonth) :
92
- cleanSpecialChars(this.endMonth).slice(0, 6) + "..." :
93
- "",
94
- endYear: this.endYear ?
95
- this.endYear.length <= 8 ?
96
- cleanSpecialChars(this.endYear) :
97
- cleanSpecialChars(this.endYear).slice(0, 5) + "..." :
98
- "",
99
- school: this.school ?
100
- this.school.length <= 25 ?
101
- cleanSpecialChars(this.school) :
102
- cleanSpecialChars(this.school).slice(0, 22) + "..." :
103
- "",
104
- startMonth: this.startMonth ?
105
- this.startMonth.length <= 11 ?
106
- cleanSpecialChars(this.startMonth) :
107
- cleanSpecialChars(this.startMonth).slice(0, 8) + "..." :
108
- "",
109
- startYear: this.startYear ?
110
- this.startYear.length <= 10 ?
111
- cleanSpecialChars(this.startYear) :
112
- cleanSpecialChars(this.startYear).slice(0, 7) + "..." :
113
- "",
79
+ degreeDomain: cleanAndTruncate(this.degreeDomain, 15),
80
+ degreeType: cleanAndTruncate(this.degreeType, 25),
81
+ endMonth: cleanAndTruncate(this.endMonth, 9),
82
+ endYear: cleanAndTruncate(this.endYear, 8),
83
+ school: cleanAndTruncate(this.school, 25),
84
+ startMonth: cleanAndTruncate(this.startMonth, 11),
85
+ startYear: cleanAndTruncate(this.startYear, 10),
114
86
  };
115
87
  };
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _ResumeV1Language_instances, _ResumeV1Language_printableValues;
7
- import { cleanSpecialChars } from "../../../v1/parsing/common/index.js";
7
+ import { cleanAndTruncate } from "../../../v1/parsing/common/index.js";
8
8
  import { Polygon } from "../../../geometry/index.js";
9
9
  /**
10
10
  * The list of languages that the candidate is proficient in.
@@ -51,15 +51,7 @@ export class ResumeV1Language {
51
51
  }
52
52
  _ResumeV1Language_instances = new WeakSet(), _ResumeV1Language_printableValues = function _ResumeV1Language_printableValues() {
53
53
  return {
54
- language: this.language ?
55
- this.language.length <= 8 ?
56
- cleanSpecialChars(this.language) :
57
- cleanSpecialChars(this.language).slice(0, 5) + "..." :
58
- "",
59
- level: this.level ?
60
- this.level.length <= 20 ?
61
- cleanSpecialChars(this.level) :
62
- cleanSpecialChars(this.level).slice(0, 17) + "..." :
63
- "",
54
+ language: cleanAndTruncate(this.language, 8),
55
+ level: cleanAndTruncate(this.level, 20),
64
56
  };
65
57
  };