mindee 4.14.1 → 4.16.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 (163) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/package.json +2 -1
  3. package/src/client.d.ts +5 -3
  4. package/src/client.js +7 -1
  5. package/src/http/endpoint.d.ts +3 -1
  6. package/src/http/endpoint.js +12 -8
  7. package/src/http/responseValidation.js +11 -4
  8. package/src/imageOperations/invoiceSplitterExtractor/invoiceSplitterExtractor.d.ts +2 -1
  9. package/src/imageOperations/invoiceSplitterExtractor/invoiceSplitterExtractor.js +2 -1
  10. package/src/imageOperations/multiReceiptsExtractor/multiReceiptsExtractor.js +3 -1
  11. package/src/input/localResponse.d.ts +1 -0
  12. package/src/input/localResponse.js +1 -0
  13. package/src/parsing/common/document.d.ts +1 -0
  14. package/src/parsing/common/document.js +27 -6
  15. package/src/parsing/common/extras/fullTextOcrExtra.d.ts +11 -0
  16. package/src/parsing/common/extras/fullTextOcrExtra.js +20 -0
  17. package/src/parsing/common/extras/index.d.ts +3 -0
  18. package/src/parsing/common/extras/index.js +9 -0
  19. package/src/parsing/common/index.d.ts +2 -0
  20. package/src/parsing/common/index.js +28 -1
  21. package/src/parsing/common/page.d.ts +1 -0
  22. package/src/parsing/common/page.js +30 -7
  23. package/src/parsing/common/summaryHelper.d.ts +10 -0
  24. package/src/parsing/common/summaryHelper.js +27 -1
  25. package/src/parsing/generated/generatedObject.d.ts +3 -3
  26. package/src/parsing/generated/generatedObject.js +14 -5
  27. package/src/parsing/standard/amount.d.ts +0 -1
  28. package/src/parsing/standard/amount.js +4 -11
  29. package/src/parsing/standard/index.d.ts +1 -1
  30. package/src/parsing/standard/index.js +1 -2
  31. package/src/parsing/standard/tax.js +4 -4
  32. package/src/pdf/pdfOperation.d.ts +1 -1
  33. package/src/pdf/pdfOperation.js +12 -7
  34. package/src/product/billOfLading/billOfLadingV1.d.ts +16 -0
  35. package/src/product/billOfLading/billOfLadingV1.js +27 -0
  36. package/src/product/billOfLading/billOfLadingV1Carrier.d.ts +32 -0
  37. package/src/product/billOfLading/billOfLadingV1Carrier.js +62 -0
  38. package/src/product/billOfLading/billOfLadingV1CarrierItem.d.ts +38 -0
  39. package/src/product/billOfLading/billOfLadingV1CarrierItem.js +117 -0
  40. package/src/product/billOfLading/billOfLadingV1Consignee.d.ts +34 -0
  41. package/src/product/billOfLading/billOfLadingV1Consignee.js +67 -0
  42. package/src/product/billOfLading/billOfLadingV1Document.d.ts +39 -0
  43. package/src/product/billOfLading/billOfLadingV1Document.js +95 -0
  44. package/src/product/billOfLading/billOfLadingV1NotifyParty.d.ts +34 -0
  45. package/src/product/billOfLading/billOfLadingV1NotifyParty.js +67 -0
  46. package/src/product/billOfLading/billOfLadingV1Shipper.d.ts +34 -0
  47. package/src/product/billOfLading/billOfLadingV1Shipper.js +67 -0
  48. package/src/product/billOfLading/index.d.ts +1 -0
  49. package/src/product/billOfLading/index.js +5 -0
  50. package/src/product/billOfLading/internal.d.ts +7 -0
  51. package/src/product/billOfLading/internal.js +17 -0
  52. package/src/product/financialDocument/financialDocumentV1LineItem.d.ts +8 -8
  53. package/src/product/financialDocument/financialDocumentV1LineItem.js +47 -22
  54. package/src/product/fr/bankAccountDetails/bankAccountDetailsV2Bban.d.ts +4 -4
  55. package/src/product/fr/energyBill/energyBillV1.d.ts +16 -0
  56. package/src/product/fr/energyBill/energyBillV1.js +27 -0
  57. package/src/product/fr/energyBill/energyBillV1Document.d.ts +49 -0
  58. package/src/product/fr/energyBill/energyBillV1Document.js +143 -0
  59. package/src/product/fr/energyBill/energyBillV1EnergyConsumer.d.ts +30 -0
  60. package/src/product/fr/energyBill/energyBillV1EnergyConsumer.js +57 -0
  61. package/src/product/fr/energyBill/energyBillV1EnergySupplier.d.ts +30 -0
  62. package/src/product/fr/energyBill/energyBillV1EnergySupplier.js +57 -0
  63. package/src/product/fr/energyBill/energyBillV1EnergyUsage.d.ts +38 -0
  64. package/src/product/fr/energyBill/energyBillV1EnergyUsage.js +117 -0
  65. package/src/product/fr/energyBill/energyBillV1MeterDetail.d.ts +32 -0
  66. package/src/product/fr/energyBill/energyBillV1MeterDetail.js +62 -0
  67. package/src/product/fr/energyBill/energyBillV1Subscription.d.ts +38 -0
  68. package/src/product/fr/energyBill/energyBillV1Subscription.js +117 -0
  69. package/src/product/fr/energyBill/energyBillV1TaxesAndContribution.d.ts +38 -0
  70. package/src/product/fr/energyBill/energyBillV1TaxesAndContribution.js +117 -0
  71. package/src/product/fr/energyBill/index.d.ts +1 -0
  72. package/src/product/fr/energyBill/index.js +5 -0
  73. package/src/product/fr/energyBill/internal.d.ts +8 -0
  74. package/src/product/fr/energyBill/internal.js +19 -0
  75. package/src/product/fr/index.d.ts +2 -0
  76. package/src/product/fr/index.js +5 -1
  77. package/src/product/fr/internal.d.ts +2 -0
  78. package/src/product/fr/internal.js +3 -1
  79. package/src/product/fr/payslip/index.d.ts +1 -0
  80. package/src/product/fr/payslip/index.js +5 -0
  81. package/src/product/fr/payslip/internal.d.ts +10 -0
  82. package/src/product/fr/payslip/internal.js +23 -0
  83. package/src/product/fr/payslip/payslipV2.d.ts +16 -0
  84. package/src/product/fr/payslip/payslipV2.js +27 -0
  85. package/src/product/fr/payslip/payslipV2BankAccountDetail.d.ts +32 -0
  86. package/src/product/fr/payslip/payslipV2BankAccountDetail.js +62 -0
  87. package/src/product/fr/payslip/payslipV2Document.d.ts +35 -0
  88. package/src/product/fr/payslip/payslipV2Document.js +80 -0
  89. package/src/product/fr/payslip/payslipV2Employee.d.ts +40 -0
  90. package/src/product/fr/payslip/payslipV2Employee.js +82 -0
  91. package/src/product/fr/payslip/payslipV2Employer.d.ts +40 -0
  92. package/src/product/fr/payslip/payslipV2Employer.js +82 -0
  93. package/src/product/fr/payslip/payslipV2Employment.d.ts +38 -0
  94. package/src/product/fr/payslip/payslipV2Employment.js +85 -0
  95. package/src/product/fr/payslip/payslipV2PayDetail.d.ts +46 -0
  96. package/src/product/fr/payslip/payslipV2PayDetail.js +168 -0
  97. package/src/product/fr/payslip/payslipV2PayPeriod.d.ts +36 -0
  98. package/src/product/fr/payslip/payslipV2PayPeriod.js +72 -0
  99. package/src/product/fr/payslip/payslipV2Pto.d.ts +32 -0
  100. package/src/product/fr/payslip/payslipV2Pto.js +84 -0
  101. package/src/product/fr/payslip/payslipV2SalaryDetail.d.ts +34 -0
  102. package/src/product/fr/payslip/payslipV2SalaryDetail.js +97 -0
  103. package/src/product/generated/generatedV1.js +2 -1
  104. package/src/product/index.d.ts +2 -0
  105. package/src/product/index.js +5 -1
  106. package/src/product/internal.d.ts +2 -0
  107. package/src/product/internal.js +3 -1
  108. package/src/product/invoice/invoiceV4LineItem.d.ts +8 -8
  109. package/src/product/invoice/invoiceV4LineItem.js +47 -22
  110. package/src/product/nutritionFactsLabel/index.d.ts +1 -0
  111. package/src/product/nutritionFactsLabel/index.js +5 -0
  112. package/src/product/nutritionFactsLabel/internal.d.ts +15 -0
  113. package/src/product/nutritionFactsLabel/internal.js +33 -0
  114. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1.d.ts +16 -0
  115. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1.js +27 -0
  116. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1AddedSugar.d.ts +32 -0
  117. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1AddedSugar.js +84 -0
  118. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Calorie.d.ts +32 -0
  119. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Calorie.js +84 -0
  120. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Cholesterol.d.ts +32 -0
  121. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Cholesterol.js +84 -0
  122. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1DietaryFiber.d.ts +32 -0
  123. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1DietaryFiber.js +84 -0
  124. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Document.d.ts +53 -0
  125. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Document.js +117 -0
  126. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Nutrient.d.ts +36 -0
  127. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Nutrient.js +107 -0
  128. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Protein.d.ts +32 -0
  129. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Protein.js +84 -0
  130. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1SaturatedFat.d.ts +32 -0
  131. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1SaturatedFat.js +84 -0
  132. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1ServingSize.d.ts +30 -0
  133. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1ServingSize.js +65 -0
  134. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Sodium.d.ts +34 -0
  135. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Sodium.js +89 -0
  136. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TotalCarbohydrate.d.ts +32 -0
  137. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TotalCarbohydrate.js +84 -0
  138. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TotalFat.d.ts +32 -0
  139. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TotalFat.js +84 -0
  140. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TotalSugar.d.ts +32 -0
  141. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TotalSugar.js +84 -0
  142. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TransFat.d.ts +32 -0
  143. package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TransFat.js +84 -0
  144. package/src/product/receipt/receiptV5LineItem.d.ts +4 -4
  145. package/src/product/receipt/receiptV5LineItem.js +27 -12
  146. package/src/product/resume/resumeV1Certificate.d.ts +4 -4
  147. package/src/product/resume/resumeV1Certificate.js +9 -8
  148. package/src/product/resume/resumeV1Education.d.ts +7 -7
  149. package/src/product/resume/resumeV1Education.js +15 -14
  150. package/src/product/resume/resumeV1Language.d.ts +2 -2
  151. package/src/product/resume/resumeV1Language.js +5 -4
  152. package/src/product/resume/resumeV1ProfessionalExperience.d.ts +8 -8
  153. package/src/product/resume/resumeV1ProfessionalExperience.js +17 -16
  154. package/src/product/resume/resumeV1SocialNetworksUrl.d.ts +2 -2
  155. package/src/product/resume/resumeV1SocialNetworksUrl.js +5 -4
  156. package/src/product/us/healthcareCard/healthcareCardV1Copay.d.ts +2 -2
  157. package/src/product/us/healthcareCard/healthcareCardV1Copay.js +11 -6
  158. package/src/product/us/usMail/index.d.ts +1 -0
  159. package/src/product/us/usMail/index.js +5 -0
  160. package/src/product/us/usMail/usMailV2RecipientAddress.d.ts +7 -7
  161. package/src/product/us/usMail/usMailV2RecipientAddress.js +17 -15
  162. package/src/product/us/usMail/usMailV2SenderAddress.d.ts +5 -5
  163. package/src/product/us/usMail/usMailV2SenderAddress.js +5 -25
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # CHANGELOG
2
2
 
3
+ # v4.16.0 - 2024-09-17
4
+ ### Changes
5
+ * :sparkles: add support for US Mail V2
6
+ * :sparkles: add support for Bill of Lading V1
7
+ * :sparkles: add support for FR Energy Bill V1
8
+ * :sparkles: add support for FR Payslips V1
9
+ * :sparkles: add support for Nutrition Facts Label V1
10
+ * :recycle: refactor internals to accommodate for new changes
11
+
12
+ ### Fixes
13
+ * :bug: fix float numbers not containing more 3 decimals in some instances
14
+ * :bug: fix boolean field display issues
15
+ * :bug: fix values being extracted as `undefined` instead of `null`, as is present in the initial prediction.
16
+
17
+
18
+ ## v4.15.0 - 2024-09-12
19
+ ### Changes
20
+ * :sparkles: add support for full text OCR extraction
21
+ * :wrench: add stricter linting rules
22
+ * :recycle: add integration tests
23
+ ### Fixes
24
+ * :bug: fix page operations not taking minimum threshold into account.
25
+
26
+
3
27
  ## v4.14.1 - 2024-09-03
4
28
  ### Changes
5
29
  * :memo: add classification detail to guide documentation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "4.14.1",
3
+ "version": "4.16.0",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
@@ -10,6 +10,7 @@
10
10
  "build-for-dist": "tsc --build && cp LICENSE README.md CHANGELOG.md ./dist",
11
11
  "clean": "rm -rf ./dist ./docs/_build",
12
12
  "test": "mocha 'tests/**/*.spec.ts'",
13
+ "test-integration": "mocha 'tests/**/*.integration.ts'",
13
14
  "lint": "eslint './src/**/*.ts' --report-unused-disable-directives && echo 'Your .ts files look good.'",
14
15
  "lint-fix": "eslint './src/**/*.ts' --fix",
15
16
  "docs": "typedoc --out docs/_build ./src/index.ts",
package/src/client.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
4
  import { Readable } from "stream";
5
- import { Base64Input, BytesInput, InputSource, PathInput, StreamInput, PageOptions, UrlInput, BufferInput, LocalResponse } from "./input";
5
+ import { Base64Input, BufferInput, BytesInput, InputSource, LocalResponse, PageOptions, PathInput, StreamInput, UrlInput } from "./input";
6
6
  import { Endpoint } from "./http";
7
7
  import { AsyncPredictResponse, FeedbackResponse, Inference, PredictResponse, StringDict } from "./parsing/common";
8
8
  /**
@@ -17,10 +17,12 @@ export interface PredictOptions {
17
17
  * This performs a full OCR operation on the server and will increase response time.
18
18
  */
19
19
  allWords?: boolean;
20
+ /**
21
+ * Whether to include the full ocr text. Only available on compatible APIs.
22
+ */
23
+ fullText?: boolean;
20
24
  /**
21
25
  * Whether to include cropper results for each page.
22
- *
23
- * This performs a cropping operation on the server and will increase response time.
24
26
  */
25
27
  cropper?: boolean;
26
28
  /**
package/src/client.js CHANGED
@@ -52,6 +52,7 @@ class Client {
52
52
  async parse(productClass, inputSource, params = {
53
53
  endpoint: undefined,
54
54
  allWords: undefined,
55
+ fullText: undefined,
55
56
  cropper: undefined,
56
57
  pageOptions: undefined,
57
58
  }) {
@@ -62,6 +63,7 @@ class Client {
62
63
  const rawPrediction = await endpoint.predict({
63
64
  inputDoc: inputSource,
64
65
  includeWords: this.getBooleanParam(params.allWords),
66
+ fullText: this.getBooleanParam(params.fullText),
65
67
  pageOptions: params.pageOptions,
66
68
  cropper: this.getBooleanParam(params.cropper),
67
69
  });
@@ -83,6 +85,7 @@ class Client {
83
85
  const rawResponse = await endpoint.predictAsync({
84
86
  inputDoc: inputSource,
85
87
  includeWords: this.getBooleanParam(params.allWords),
88
+ fullText: this.getBooleanParam(params.fullText),
86
89
  pageOptions: params?.pageOptions,
87
90
  cropper: this.getBooleanParam(params.cropper),
88
91
  });
@@ -171,6 +174,7 @@ class Client {
171
174
  async enqueueAndParse(productClass, inputSource, asyncParams = {
172
175
  endpoint: undefined,
173
176
  allWords: undefined,
177
+ fullText: undefined,
174
178
  cropper: undefined,
175
179
  pageOptions: undefined,
176
180
  initialDelaySec: 4,
@@ -202,7 +206,9 @@ Job status: ${pollResults.job.status}.`);
202
206
  retryCounter++;
203
207
  }
204
208
  if (pollResults.job.status !== "completed") {
205
- throw Error(`Asynchronous parsing request timed out after ${validatedAsyncParams.delaySec * retryCounter} seconds`);
209
+ throw Error("Asynchronous parsing request timed out after " +
210
+ validatedAsyncParams.delaySec * retryCounter +
211
+ " seconds");
206
212
  }
207
213
  return pollResults;
208
214
  }
@@ -6,6 +6,7 @@ import { StringDict } from "../parsing/common";
6
6
  export interface PredictParams {
7
7
  inputDoc: InputSource;
8
8
  includeWords: boolean;
9
+ fullText: boolean;
9
10
  pageOptions?: PageOptions;
10
11
  cropper: boolean;
11
12
  }
@@ -63,7 +64,8 @@ export declare class Endpoint extends BaseEndpoint {
63
64
  * @param input
64
65
  * @param predictUrl
65
66
  * @param includeWords
67
+ * @param fullText
66
68
  * @param cropper
67
69
  */
68
- protected sendFileForPrediction(input: InputSource, predictUrl: string, includeWords?: boolean, cropper?: boolean): Promise<EndpointResponse>;
70
+ protected sendFileForPrediction(input: InputSource, predictUrl: string, includeWords?: boolean, fullText?: boolean, cropper?: boolean): Promise<EndpointResponse>;
69
71
  }
@@ -40,7 +40,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
40
40
  if (params.pageOptions !== undefined) {
41
41
  await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_cutDocPages).call(this, params.inputDoc, params.pageOptions);
42
42
  }
43
- const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictReqPost).call(this, params.inputDoc, params.includeWords, params.cropper);
43
+ const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper);
44
44
  if (!(0, responseValidation_1.isValidSyncResponse)(response)) {
45
45
  (0, error_1.handleError)(this.urlName, response, response.messageObj?.statusMessage);
46
46
  }
@@ -58,7 +58,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
58
58
  if (params.pageOptions !== undefined) {
59
59
  await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_cutDocPages).call(this, params.inputDoc, params.pageOptions);
60
60
  }
61
- const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictAsyncReqPost).call(this, params.inputDoc, params.includeWords, params.cropper);
61
+ const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictAsyncReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper);
62
62
  if (!(0, responseValidation_1.isValidAsyncResponse)(response)) {
63
63
  (0, error_1.handleError)(this.urlName, response, response.messageObj?.statusMessage);
64
64
  }
@@ -114,14 +114,18 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
114
114
  * @param input
115
115
  * @param predictUrl
116
116
  * @param includeWords
117
+ * @param fullText
117
118
  * @param cropper
118
119
  */
119
- sendFileForPrediction(input, predictUrl, includeWords = false, cropper = false) {
120
+ sendFileForPrediction(input, predictUrl, includeWords = false, fullText = false, cropper = false) {
120
121
  return new Promise((resolve, reject) => {
121
122
  const searchParams = new url_1.URLSearchParams();
122
123
  if (cropper) {
123
124
  searchParams.append("cropper", "true");
124
125
  }
126
+ if (fullText) {
127
+ searchParams.append("full_text_ocr", "true");
128
+ }
125
129
  const form = new form_data_1.default();
126
130
  if (input instanceof base_1.LocalInputSource && input.fileObject instanceof Buffer) {
127
131
  form.append("document", input.fileObject, {
@@ -136,7 +140,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
136
140
  }
137
141
  const headers = { ...this.settings.baseHeaders, ...form.getHeaders() };
138
142
  let path = `${this.urlRoot}/${predictUrl}`;
139
- if (searchParams.keys.length > 0) {
143
+ if (searchParams.toString().length > 0) {
140
144
  path += `?${searchParams}`;
141
145
  }
142
146
  const options = {
@@ -163,10 +167,10 @@ async function _Endpoint_cutDocPages(inputDoc, pageOptions) {
163
167
  if (inputDoc instanceof base_1.LocalInputSource && inputDoc.isPdf()) {
164
168
  await inputDoc.cutPdf(pageOptions);
165
169
  }
166
- }, _Endpoint_predictReqPost = function _Endpoint_predictReqPost(input, includeWords = false, cropper = false) {
167
- return this.sendFileForPrediction(input, "predict", includeWords, cropper);
168
- }, _Endpoint_predictAsyncReqPost = function _Endpoint_predictAsyncReqPost(input, includeWords = false, cropper = false) {
169
- return this.sendFileForPrediction(input, "predict_async", includeWords, cropper);
170
+ }, _Endpoint_predictReqPost = function _Endpoint_predictReqPost(input, includeWords = false, fullText = false, cropper = false) {
171
+ return this.sendFileForPrediction(input, "predict", includeWords, fullText, cropper);
172
+ }, _Endpoint_predictAsyncReqPost = function _Endpoint_predictAsyncReqPost(input, includeWords = false, fullText = false, cropper = false) {
173
+ return this.sendFileForPrediction(input, "predict_async", includeWords, fullText, cropper);
170
174
  }, _Endpoint_documentQueueReqGet = function _Endpoint_documentQueueReqGet(queueId) {
171
175
  return new Promise((resolve, reject) => {
172
176
  const options = {
@@ -11,7 +11,9 @@ function isValidSyncResponse(response) {
11
11
  if (!response.messageObj || !response.messageObj.statusCode) {
12
12
  return false;
13
13
  }
14
- return !(isNaN(response.messageObj.statusCode) || parseInt(response.messageObj.statusCode.toString()) < 200 || parseInt(response.messageObj.statusCode.toString()) > 302);
14
+ return !(isNaN(response.messageObj.statusCode) ||
15
+ parseInt(response.messageObj.statusCode.toString()) < 200 ||
16
+ parseInt(response.messageObj.statusCode.toString()) > 302);
15
17
  }
16
18
  exports.isValidSyncResponse = isValidSyncResponse;
17
19
  /**
@@ -37,7 +39,9 @@ function isValidAsyncResponse(response) {
37
39
  if (!response.data["job"]) {
38
40
  return false;
39
41
  }
40
- return !(response.data["job"] && response.data["job"]["error"] && Object.keys(response.data["job"]["error"]).length > 0);
42
+ return !(response.data["job"] &&
43
+ response.data["job"]["error"] &&
44
+ Object.keys(response.data["job"]["error"]).length > 0);
41
45
  }
42
46
  exports.isValidAsyncResponse = isValidAsyncResponse;
43
47
  /**
@@ -54,10 +58,13 @@ function cleanRequestData(response) {
54
58
  return response;
55
59
  }
56
60
  if (response.data) {
57
- if (response.data["api_request"] && response.data["api_request"]["status_code"] && parseInt(response.data["api_request"]["status_code"].toString()) > 399) {
61
+ if (response.data["api_request"] &&
62
+ response.data["api_request"]["status_code"] &&
63
+ parseInt(response.data["api_request"]["status_code"].toString()) > 399) {
58
64
  response.messageObj.statusCode = parseInt(response.data["api_request"]["status_code"].toString());
59
65
  }
60
- if (response.data["job"] && response.data["job"]["error"] && Object.keys(response.data["job"]["error"]).length > 0) {
66
+ if (response.data["job"] && response.data["job"]["error"] &&
67
+ Object.keys(response.data["job"]["error"]).length > 0) {
61
68
  response.messageObj.statusCode = 500;
62
69
  }
63
70
  }
@@ -5,7 +5,8 @@ import { ExtractedInvoiceSplitterImage } from "./extractedInvoiceSplitterImage";
5
5
  * Extracts & cuts the pages of a main document invoice according to the provided indexes.
6
6
  *
7
7
  * @param inputFile File to extract sub-invoices from.
8
- * @param indexes List of indexes to cut the document according to. Can be provided either as a InvoiceSplitterV1 inference, or a direct list of splits.
8
+ * @param indexes List of indexes to cut the document according to.
9
+ * Can be provided either as a InvoiceSplitterV1 inference, or a direct list of splits.
9
10
  * @param strict If set to true, doesn't cut pages where the API isn't 100% confident.
10
11
  * @returns A promise of extracted images, as an array of ExtractedInvoiceSplitterImage.
11
12
  */
@@ -40,7 +40,8 @@ async function getPdfDoc(inputFile) {
40
40
  * Extracts & cuts the pages of a main document invoice according to the provided indexes.
41
41
  *
42
42
  * @param inputFile File to extract sub-invoices from.
43
- * @param indexes List of indexes to cut the document according to. Can be provided either as a InvoiceSplitterV1 inference, or a direct list of splits.
43
+ * @param indexes List of indexes to cut the document according to.
44
+ * Can be provided either as a InvoiceSplitterV1 inference, or a direct list of splits.
44
45
  * @param strict If set to true, doesn't cut pages where the API isn't 100% confident.
45
46
  * @returns A promise of extracted images, as an array of ExtractedInvoiceSplitterImage.
46
47
  */
@@ -25,7 +25,9 @@ async function extractReceiptsFromPage(pdfPage, boundingBoxes, pageId) {
25
25
  async function loadPdfDoc(inputFile) {
26
26
  let pdfDoc;
27
27
  if (!["image/jpeg", "image/jpg", "image/png", "application/pdf"].includes(inputFile.mimeType)) {
28
- throw new errors_1.MindeeMimeTypeError(`Unsupported file type "${inputFile.mimeType}" Currently supported types are .png, .jpg and .pdf`);
28
+ throw new errors_1.MindeeMimeTypeError('Unsupported file type "' +
29
+ inputFile.mimeType +
30
+ '" Currently supported types are .png, .jpg and .pdf');
29
31
  }
30
32
  else if (inputFile.isPdf()) {
31
33
  pdfDoc = await pdf_lib_1.PDFDocument.load(inputFile.fileObject);
@@ -3,6 +3,7 @@ import { StringDict } from "../parsing/common";
3
3
  import { Buffer } from "buffer";
4
4
  /**
5
5
  * Local response loaded from a file.
6
+ * Note: Has to be initialized through init() before use.
6
7
  */
7
8
  export declare class LocalResponse {
8
9
  private file;
@@ -30,6 +30,7 @@ const errors_1 = require("../errors");
30
30
  const buffer_1 = require("buffer");
31
31
  /**
32
32
  * Local response loaded from a file.
33
+ * Note: Has to be initialized through init() before use.
33
34
  */
34
35
  class LocalResponse {
35
36
  /**
@@ -29,4 +29,5 @@ export declare class Document<T extends Inference> {
29
29
  * Default string representation.
30
30
  */
31
31
  toString(): string;
32
+ private injectFullTextOcr;
32
33
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Document = void 0;
4
- const cropperExtra_1 = require("./extras/cropperExtra");
5
- const extras_1 = require("./extras/extras");
4
+ const extras_1 = require("./extras");
5
+ const extras_2 = require("./extras/extras");
6
6
  const ocr_1 = require("./ocr");
7
7
  /**
8
8
  * Document prediction wrapper class. Holds the results of a parsed document.
@@ -19,18 +19,23 @@ class Document {
19
19
  this.filename = httpResponse?.name ?? "";
20
20
  this.ocr = httpResponse.ocr && Object.keys(httpResponse.ocr).length > 0 ? new ocr_1.Ocr(httpResponse.ocr) : undefined;
21
21
  this.inference = new inferenceClass(httpResponse["inference"]);
22
- // Note: this is a convoluted but functional way of being able to implement/use Extras fields
23
- // as an extension of a Map object (like having an adapted toString() method, for instance).
24
22
  if (httpResponse["extras"] &&
25
23
  Object.keys(httpResponse["extras"].length > 0)) {
26
24
  const extras = {};
27
25
  Object.entries(httpResponse["extras"]).forEach(([extraKey, extraValue]) => {
28
26
  switch (extraKey) {
29
27
  case "cropper":
30
- extras["cropper"] = new cropperExtra_1.CropperExtra(extraValue);
28
+ extras["cropper"] = new extras_1.CropperExtra(extraValue);
29
+ break;
30
+ case "full_text_ocr":
31
+ extras["fullTextOcr"] = new extras_1.FullTextOcrExtra(extraValue);
32
+ break;
31
33
  }
32
34
  });
33
- this.extras = new extras_1.Extras(extras);
35
+ this.extras = new extras_2.Extras(extras);
36
+ }
37
+ if (!this.extras || !("fullTextOcr" in this.extras) || this.extras["full_text_ocr"].toString().length === 0) {
38
+ this.injectFullTextOcr(httpResponse);
34
39
  }
35
40
  this.nPages = httpResponse["n_pages"];
36
41
  }
@@ -44,5 +49,21 @@ class Document {
44
49
 
45
50
  ${this.inference?.toString()}`;
46
51
  }
52
+ injectFullTextOcr(rawPrediction) {
53
+ if (rawPrediction["inference"]["pages"].length < 1 ||
54
+ rawPrediction["inference"]["pages"][0]["extras"].length < 1 ||
55
+ !("full_text_ocr" in rawPrediction["inference"]["pages"][0]["extras"])) {
56
+ return;
57
+ }
58
+ const fullTextOcr = rawPrediction["inference"]["pages"].filter((e) => "extras" in e).map((e) => e["extras"]["full_text_ocr"]["content"]).join("\n");
59
+ // eslint-disable-next-line @typescript-eslint/naming-convention
60
+ const artificialTextObj = { "full_text_ocr": { "content": fullTextOcr.length > 0 ? fullTextOcr : "" } };
61
+ if (!this.extras) {
62
+ this.extras = new extras_2.Extras({ "fullTextOcr": new extras_1.FullTextOcrExtra(artificialTextObj) });
63
+ }
64
+ else {
65
+ this.extras["fullTextOcr"] = new extras_1.FullTextOcrExtra(artificialTextObj);
66
+ }
67
+ }
47
68
  }
48
69
  exports.Document = Document;
@@ -0,0 +1,11 @@
1
+ import { StringDict } from "../stringDict";
2
+ import { ExtraField } from "./extras";
3
+ export declare class FullTextOcrExtra extends ExtraField {
4
+ content?: string;
5
+ languages?: string;
6
+ constructor(rawPrediction: StringDict);
7
+ /**
8
+ * Default string representation.
9
+ */
10
+ toString(): string;
11
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FullTextOcrExtra = void 0;
4
+ const extras_1 = require("./extras");
5
+ class FullTextOcrExtra extends extras_1.ExtraField {
6
+ constructor(rawPrediction) {
7
+ super();
8
+ if (rawPrediction["full_text_ocr"] !== undefined && rawPrediction["full_text_ocr"]["content"]) {
9
+ this.content = "content" in rawPrediction["full_text_ocr"] ? rawPrediction["full_text_ocr"]["content"] : "";
10
+ this.languages = "languages" in rawPrediction["full_text_ocr"] ? rawPrediction["full_text_ocr"]["languages"] : "";
11
+ }
12
+ }
13
+ /**
14
+ * Default string representation.
15
+ */
16
+ toString() {
17
+ return this.content !== undefined ? this.content : "";
18
+ }
19
+ }
20
+ exports.FullTextOcrExtra = FullTextOcrExtra;
@@ -0,0 +1,3 @@
1
+ export { CropperExtra } from "./cropperExtra";
2
+ export { Extras } from "./extras";
3
+ export { FullTextOcrExtra } from "./fullTextOcrExtra";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FullTextOcrExtra = exports.Extras = exports.CropperExtra = void 0;
4
+ var cropperExtra_1 = require("./cropperExtra");
5
+ Object.defineProperty(exports, "CropperExtra", { enumerable: true, get: function () { return cropperExtra_1.CropperExtra; } });
6
+ var extras_1 = require("./extras");
7
+ Object.defineProperty(exports, "Extras", { enumerable: true, get: function () { return extras_1.Extras; } });
8
+ var fullTextOcrExtra_1 = require("./fullTextOcrExtra");
9
+ Object.defineProperty(exports, "FullTextOcrExtra", { enumerable: true, get: function () { return fullTextOcrExtra_1.FullTextOcrExtra; } });
@@ -8,3 +8,5 @@ export { PredictResponse } from "./predictResponse";
8
8
  export { Prediction } from "./prediction";
9
9
  export { Page } from "./page";
10
10
  export { cleanOutString, lineSeparator } from "./summaryHelper";
11
+ export * as extras from "./extras";
12
+ export { floatToString, cleanSpecialChars } from "./summaryHelper";
@@ -1,6 +1,29 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lineSeparator = exports.cleanOutString = exports.Page = exports.Prediction = exports.PredictResponse = exports.AsyncPredictResponse = exports.Inference = exports.OrientationField = exports.FeedbackResponse = exports.Document = void 0;
26
+ exports.cleanSpecialChars = exports.floatToString = exports.extras = exports.lineSeparator = exports.cleanOutString = exports.Page = exports.Prediction = exports.PredictResponse = exports.AsyncPredictResponse = exports.Inference = exports.OrientationField = exports.FeedbackResponse = exports.Document = void 0;
4
27
  var document_1 = require("./document");
5
28
  Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
6
29
  var feedbackResponse_1 = require("./feedback/feedbackResponse");
@@ -20,3 +43,7 @@ Object.defineProperty(exports, "Page", { enumerable: true, get: function () { re
20
43
  var summaryHelper_1 = require("./summaryHelper");
21
44
  Object.defineProperty(exports, "cleanOutString", { enumerable: true, get: function () { return summaryHelper_1.cleanOutString; } });
22
45
  Object.defineProperty(exports, "lineSeparator", { enumerable: true, get: function () { return summaryHelper_1.lineSeparator; } });
46
+ exports.extras = __importStar(require("./extras"));
47
+ var summaryHelper_2 = require("./summaryHelper");
48
+ Object.defineProperty(exports, "floatToString", { enumerable: true, get: function () { return summaryHelper_2.floatToString; } });
49
+ Object.defineProperty(exports, "cleanSpecialChars", { enumerable: true, get: function () { return summaryHelper_2.cleanSpecialChars; } });
@@ -27,4 +27,5 @@ export declare class Page<T extends Prediction> {
27
27
  * Default string representation.
28
28
  */
29
29
  toString(): string;
30
+ private injectFullTextOcr;
30
31
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Page = void 0;
4
- const cropperExtra_1 = require("./extras/cropperExtra");
5
- const extras_1 = require("./extras/extras");
4
+ const extras_1 = require("./extras");
5
+ const extras_2 = require("./extras/extras");
6
6
  const orientation_1 = require("./orientation");
7
7
  /**
8
8
  * Page prediction wrapper class. Holds the results of a parsed document's page.
@@ -23,9 +23,6 @@ class Page {
23
23
  pageId: pageId,
24
24
  });
25
25
  }
26
- else {
27
- orientation = undefined;
28
- }
29
26
  this.id = pageId;
30
27
  this.prediction = new predictionType(rawPrediction["prediction"], pageId);
31
28
  if (rawPrediction["extras"] &&
@@ -34,10 +31,17 @@ class Page {
34
31
  Object.entries(rawPrediction["extras"]).forEach(([extraKey, extraValue]) => {
35
32
  switch (extraKey) {
36
33
  case "cropper":
37
- extras["cropper"] = new cropperExtra_1.CropperExtra(extraValue);
34
+ extras["cropper"] = new extras_1.CropperExtra(extraValue);
35
+ break;
36
+ case "full_text_ocr":
37
+ extras["fullTextOcr"] = new extras_1.FullTextOcrExtra(extraValue);
38
+ break;
38
39
  }
39
40
  });
40
- this.extras = new extras_1.Extras(extras);
41
+ this.extras = new extras_2.Extras(extras);
42
+ }
43
+ if (!this.extras || !("fullTextOcr" in this.extras) || this.extras["fullTextOcr"].toString().length === 0) {
44
+ this.injectFullTextOcr(rawPrediction);
41
45
  }
42
46
  }
43
47
  /**
@@ -50,5 +54,24 @@ ${"-".repeat(title.length)}
50
54
  ${this.prediction.toString()}
51
55
  `;
52
56
  }
57
+ injectFullTextOcr(rawPrediction) {
58
+ if (!("extras" in rawPrediction) || !("full_text_ocr" in rawPrediction["extras"])) {
59
+ return;
60
+ }
61
+ const fullTextOcr = rawPrediction.map((e) => e["extras"]["full_text_ocr"]["content"]).join("\n");
62
+ const artificialTextObj = {
63
+ // eslint-disable-next-line @typescript-eslint/naming-convention
64
+ "full_text_ocr": {
65
+ "content": fullTextOcr.length > 0 ? fullTextOcr : "",
66
+ },
67
+ };
68
+ if (!this.extras) {
69
+ // eslint-disable-next-line @typescript-eslint/naming-convention
70
+ this.extras = new extras_2.Extras({ "full_text_ocr": new extras_1.FullTextOcrExtra(artificialTextObj) });
71
+ }
72
+ else {
73
+ this.extras["fullTextOcr"] = new extras_1.FullTextOcrExtra(artificialTextObj);
74
+ }
75
+ }
53
76
  }
54
77
  exports.Page = Page;
@@ -6,3 +6,13 @@ export declare function cleanOutString(outStr: string): string;
6
6
  * @returns A separator for table lines
7
7
  */
8
8
  export declare function lineSeparator(columnSizes: number[], separator: string): string;
9
+ /**
10
+ * Replaces all special characters like \n, \r, \t, with an equivalent that can be displayed on a single line.
11
+ * Also trims line breaks at the end of the string.
12
+ * @param outStr
13
+ */
14
+ export declare function cleanSpecialChars(outStr: string): string;
15
+ /**
16
+ * Return a float as a string with at least 2 levels of precision.
17
+ */
18
+ export declare function floatToString(value: number | null): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lineSeparator = exports.cleanOutString = void 0;
3
+ exports.floatToString = exports.cleanSpecialChars = exports.lineSeparator = exports.cleanOutString = void 0;
4
4
  function cleanOutString(outStr) {
5
5
  const lines = / \n/gm;
6
6
  return outStr.replace(lines, "\n");
@@ -20,3 +20,29 @@ function lineSeparator(columnSizes, separator) {
20
20
  return outStr;
21
21
  }
22
22
  exports.lineSeparator = lineSeparator;
23
+ /**
24
+ * Replaces all special characters like \n, \r, \t, with an equivalent that can be displayed on a single line.
25
+ * Also trims line breaks at the end of the string.
26
+ * @param outStr
27
+ */
28
+ function cleanSpecialChars(outStr) {
29
+ return outStr
30
+ .replace(/\n/g, "\\n")
31
+ .replace(/\r/g, "\\r")
32
+ .replace(/\t/g, "\\t");
33
+ }
34
+ exports.cleanSpecialChars = cleanSpecialChars;
35
+ /**
36
+ * Return a float as a string with at least 2 levels of precision.
37
+ */
38
+ function floatToString(value) {
39
+ if (value === null) {
40
+ return "";
41
+ }
42
+ return value.toLocaleString(undefined, {
43
+ minimumFractionDigits: 2,
44
+ maximumFractionDigits: 5,
45
+ useGrouping: false,
46
+ });
47
+ }
48
+ exports.floatToString = floatToString;
@@ -13,8 +13,8 @@ export declare class GeneratedObjectField {
13
13
  constructor({ prediction, pageId, }: BaseFieldConstructor);
14
14
  /**
15
15
  * ReSTructured-compliant string representation.
16
- Takes into account level of indentation & displays elements as list elements.
17
- * @param level Lvel of indentation. 0 by default.
16
+ Takes into account level of indentation & displays elements as list elements.
17
+ * @param level Level of indentation. 0 by default.
18
18
  */
19
19
  toStringLevel(level?: number): string;
20
20
  /**
@@ -26,7 +26,7 @@ export declare class GeneratedObjectField {
26
26
  toString(): string;
27
27
  }
28
28
  /**
29
- * Checks whether an field is a custom object or not.
29
+ * Checks whether a field is a custom object or not.
30
30
  * @param strDict input dictionary to check.
31
31
  */
32
32
  export declare function isGeneratedObject(strDict: StringDict): boolean;
@@ -12,7 +12,13 @@ class GeneratedObjectField {
12
12
  itemPageId = fieldValue;
13
13
  }
14
14
  else if (["polygon", "rectangle", "quadrangle", "bounding_box"].includes(fieldName)) {
15
- Object.assign(this, { [fieldName]: new standard_1.PositionField({ prediction: { [fieldName]: fieldValue }, valueKey: fieldName, pageId: pageId }) });
15
+ Object.assign(this, {
16
+ [fieldName]: new standard_1.PositionField({
17
+ prediction: { [fieldName]: fieldValue },
18
+ valueKey: fieldName,
19
+ pageId: pageId,
20
+ }),
21
+ });
16
22
  this.printableValues.push(fieldName);
17
23
  }
18
24
  else if (fieldName === "confidence") {
@@ -26,7 +32,10 @@ class GeneratedObjectField {
26
32
  Object.assign(this, { [fieldName]: this.toNumberString(fieldValue) });
27
33
  }
28
34
  else {
29
- Object.assign(this, { [fieldName]: (fieldValue !== undefined && fieldValue !== null) ? String(fieldValue) : null });
35
+ Object.assign(this, {
36
+ [fieldName]: (fieldValue !== undefined && fieldValue !== null) ?
37
+ String(fieldValue) : null,
38
+ });
30
39
  }
31
40
  this.printableValues.push(fieldName);
32
41
  }
@@ -35,8 +44,8 @@ class GeneratedObjectField {
35
44
  }
36
45
  /**
37
46
  * ReSTructured-compliant string representation.
38
- Takes into account level of indentation & displays elements as list elements.
39
- * @param level Lvel of indentation. 0 by default.
47
+ Takes into account level of indentation & displays elements as list elements.
48
+ * @param level Level of indentation. 0 by default.
40
49
  */
41
50
  toStringLevel(level = 0) {
42
51
  const indent = " " + " ".repeat(level);
@@ -64,7 +73,7 @@ class GeneratedObjectField {
64
73
  }
65
74
  exports.GeneratedObjectField = GeneratedObjectField;
66
75
  /**
67
- * Checks whether an field is a custom object or not.
76
+ * Checks whether a field is a custom object or not.
68
77
  * @param strDict input dictionary to check.
69
78
  */
70
79
  function isGeneratedObject(strDict) {