mindee 3.10.2 → 4.0.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 (265) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +103 -41
  3. package/package.json +6 -6
  4. package/src/cli.js +96 -70
  5. package/src/client.d.ts +34 -65
  6. package/src/client.js +108 -172
  7. package/src/geometry/boundingBox.d.ts +5 -0
  8. package/src/geometry/boundingBox.js +2 -0
  9. package/src/geometry/boundingBoxUtils.d.ts +22 -0
  10. package/src/geometry/boundingBoxUtils.js +66 -0
  11. package/src/geometry/index.d.ts +6 -0
  12. package/src/geometry/index.js +21 -0
  13. package/src/geometry/minMax.d.ts +4 -0
  14. package/src/geometry/minMax.js +2 -0
  15. package/src/geometry/point.d.ts +2 -0
  16. package/src/geometry/point.js +2 -0
  17. package/src/geometry/polygon.d.ts +4 -0
  18. package/src/geometry/polygon.js +7 -0
  19. package/src/{geometry.d.ts → geometry/polygonUtils.d.ts} +7 -32
  20. package/src/{geometry.js → geometry/polygonUtils.js} +41 -64
  21. package/src/http/endpoint.d.ts +44 -0
  22. package/src/http/endpoint.js +188 -0
  23. package/src/http/error.d.ts +2 -0
  24. package/src/http/error.js +9 -0
  25. package/src/http/index.d.ts +3 -0
  26. package/src/http/index.js +11 -0
  27. package/src/http/mindeeApi.d.ts +20 -0
  28. package/src/http/mindeeApi.js +73 -0
  29. package/src/index.d.ts +4 -4
  30. package/src/index.js +33 -26
  31. package/src/{inputs → input}/base.d.ts +4 -3
  32. package/src/{inputs → input}/base.js +9 -7
  33. package/src/{inputs → input}/index.d.ts +1 -1
  34. package/src/{inputs → input}/index.js +1 -2
  35. package/src/{inputs → input}/sources.d.ts +10 -11
  36. package/src/{inputs → input}/sources.js +9 -9
  37. package/src/parsing/common/apiRequest.d.ts +10 -0
  38. package/src/parsing/common/apiRequest.js +13 -0
  39. package/src/parsing/common/apiResponse.d.ts +6 -0
  40. package/src/parsing/common/apiResponse.js +10 -0
  41. package/src/parsing/common/asyncPredictResponse.d.ts +21 -0
  42. package/src/parsing/common/asyncPredictResponse.js +39 -0
  43. package/src/parsing/common/document.d.ts +13 -0
  44. package/src/parsing/common/document.js +34 -0
  45. package/src/parsing/common/extras/cropperExtra.d.ts +8 -0
  46. package/src/parsing/common/extras/cropperExtra.js +26 -0
  47. package/src/parsing/common/extras/extras.d.ts +11 -0
  48. package/src/parsing/common/extras/extras.js +18 -0
  49. package/src/parsing/common/index.d.ts +9 -0
  50. package/src/parsing/common/index.js +20 -0
  51. package/src/parsing/common/inference.d.ts +26 -0
  52. package/src/parsing/common/inference.js +56 -0
  53. package/src/parsing/common/mvisionV1.d.ts +8 -0
  54. package/src/parsing/common/mvisionV1.js +17 -0
  55. package/src/parsing/common/ocr.d.ts +8 -0
  56. package/src/parsing/common/ocr.js +13 -0
  57. package/src/parsing/common/ocrPage.d.ts +16 -0
  58. package/src/parsing/common/ocrPage.js +66 -0
  59. package/src/{fields → parsing/common}/orientation.d.ts +2 -2
  60. package/src/{fields → parsing/common}/orientation.js +4 -4
  61. package/src/parsing/common/page.d.ts +12 -0
  62. package/src/parsing/common/page.js +40 -0
  63. package/src/parsing/common/predictResponse.d.ts +6 -0
  64. package/src/parsing/common/predictResponse.js +12 -0
  65. package/src/parsing/common/prediction.d.ts +2 -0
  66. package/src/parsing/common/prediction.js +6 -0
  67. package/src/parsing/common/product.d.ts +4 -0
  68. package/src/parsing/common/product.js +2 -0
  69. package/src/parsing/common/stringDict.d.ts +3 -0
  70. package/src/parsing/common/stringDict.js +2 -0
  71. package/src/parsing/common/summaryHelper.d.ts +8 -0
  72. package/src/parsing/common/summaryHelper.js +22 -0
  73. package/src/parsing/custom/classificationField.d.ts +16 -0
  74. package/src/parsing/custom/classificationField.js +14 -0
  75. package/src/parsing/custom/index.d.ts +3 -0
  76. package/src/parsing/custom/index.js +12 -0
  77. package/src/{documents/custom/lineitems.d.ts → parsing/custom/lineItems.d.ts} +4 -4
  78. package/src/{documents/custom/lineitems.js → parsing/custom/lineItems.js} +11 -9
  79. package/src/{documents/custom/fields.d.ts → parsing/custom/listField.d.ts} +3 -16
  80. package/src/{documents/custom/fields.js → parsing/custom/listField.js} +4 -14
  81. package/src/parsing/index.d.ts +3 -0
  82. package/src/parsing/index.js +29 -0
  83. package/src/{fields → parsing/standard}/amount.d.ts +2 -2
  84. package/src/{fields → parsing/standard}/amount.js +5 -5
  85. package/src/{fields → parsing/standard}/base.d.ts +5 -5
  86. package/src/{fields → parsing/standard}/base.js +3 -2
  87. package/src/{fields → parsing/standard}/classification.d.ts +1 -1
  88. package/src/{fields → parsing/standard}/classification.js +3 -3
  89. package/src/{fields → parsing/standard}/companyRegistration.d.ts +1 -1
  90. package/src/parsing/standard/companyRegistration.js +14 -0
  91. package/src/{fields → parsing/standard}/date.d.ts +1 -1
  92. package/src/{fields → parsing/standard}/date.js +2 -2
  93. package/src/{fields → parsing/standard}/field.d.ts +3 -4
  94. package/src/{fields → parsing/standard}/field.js +6 -7
  95. package/src/parsing/standard/index.d.ts +12 -0
  96. package/src/parsing/standard/index.js +27 -0
  97. package/src/{fields → parsing/standard}/locale.d.ts +4 -4
  98. package/src/parsing/standard/locale.js +42 -0
  99. package/src/{fields → parsing/standard}/paymentDetails.d.ts +3 -3
  100. package/src/{fields → parsing/standard}/paymentDetails.js +11 -11
  101. package/src/{fields → parsing/standard}/position.d.ts +2 -2
  102. package/src/{fields → parsing/standard}/position.js +5 -5
  103. package/src/{fields → parsing/standard}/tax.d.ts +3 -3
  104. package/src/{fields → parsing/standard}/tax.js +3 -3
  105. package/src/{fields → parsing/standard}/text.d.ts +2 -2
  106. package/src/{fields → parsing/standard}/text.js +4 -4
  107. package/src/parsing/standard/word.d.ts +10 -0
  108. package/src/parsing/standard/word.js +2 -0
  109. package/src/pdf/pdfOperation.d.ts +1 -1
  110. package/src/pdf/pdfOperation.js +3 -3
  111. package/src/product/cropper/cropperV1.d.ts +9 -0
  112. package/src/product/cropper/cropperV1.js +16 -0
  113. package/src/product/cropper/cropperV1Document.d.ts +8 -0
  114. package/src/product/cropper/cropperV1Document.js +26 -0
  115. package/src/product/custom/customV1.d.ts +10 -0
  116. package/src/product/custom/customV1.js +17 -0
  117. package/src/product/custom/customV1Document.d.ts +9 -0
  118. package/src/product/custom/customV1Document.js +43 -0
  119. package/src/product/custom/customV1Page.d.ts +7 -0
  120. package/src/product/custom/customV1Page.js +24 -0
  121. package/src/product/eu/licensePlate/licensePlateV1.d.ts +9 -0
  122. package/src/product/eu/licensePlate/licensePlateV1.js +16 -0
  123. package/src/product/eu/licensePlate/licensePlateV1Document.d.ts +11 -0
  124. package/src/product/eu/licensePlate/licensePlateV1Document.js +25 -0
  125. package/src/product/financialDocument/financialDocumentV1.d.ts +9 -0
  126. package/src/product/financialDocument/financialDocumentV1.js +16 -0
  127. package/src/{documents/financialDocument/financialDocumentV1.d.ts → product/financialDocument/financialDocumentV1Document.d.ts} +43 -44
  128. package/src/product/financialDocument/financialDocumentV1Document.js +158 -0
  129. package/src/{documents → product}/financialDocument/financialDocumentV1LineItem.d.ts +8 -8
  130. package/src/{documents → product}/financialDocument/financialDocumentV1LineItem.js +35 -34
  131. package/src/product/fr/bankAccountDetails/bankAccountDetailsV1.d.ts +9 -0
  132. package/src/product/fr/bankAccountDetails/bankAccountDetailsV1.js +16 -0
  133. package/src/product/fr/bankAccountDetails/bankAccountDetailsV1Document.d.ts +15 -0
  134. package/src/product/fr/bankAccountDetails/bankAccountDetailsV1Document.js +31 -0
  135. package/src/product/fr/bankAccountDetails/bankAccountDetailsV2.d.ts +9 -0
  136. package/src/product/fr/bankAccountDetails/bankAccountDetailsV2.js +16 -0
  137. package/src/{documents → product}/fr/bankAccountDetails/bankAccountDetailsV2Bban.d.ts +5 -5
  138. package/src/{documents → product}/fr/bankAccountDetails/bankAccountDetailsV2Bban.js +1 -1
  139. package/src/{documents/fr/bankAccountDetails/bankAccountDetailsV2.d.ts → product/fr/bankAccountDetails/bankAccountDetailsV2Document.d.ts} +7 -7
  140. package/src/product/fr/bankAccountDetails/bankAccountDetailsV2Document.js +37 -0
  141. package/src/product/fr/carteVitale/carteVitaleV1.d.ts +9 -0
  142. package/src/product/fr/carteVitale/carteVitaleV1.js +16 -0
  143. package/src/product/fr/carteVitale/carteVitaleV1Document.d.ts +17 -0
  144. package/src/product/fr/carteVitale/carteVitaleV1Document.js +40 -0
  145. package/src/product/fr/idCard/idCardV1.d.ts +10 -0
  146. package/src/product/fr/idCard/idCardV1.js +17 -0
  147. package/src/product/fr/idCard/idCardV1Document.d.ts +29 -0
  148. package/src/product/fr/idCard/idCardV1Document.js +70 -0
  149. package/src/product/fr/idCard/idCardV1Page.d.ts +12 -0
  150. package/src/product/fr/idCard/idCardV1Page.js +23 -0
  151. package/src/{documents → product}/index.d.ts +2 -7
  152. package/src/{documents → product}/index.js +3 -14
  153. package/src/product/invoice/invoiceV4.d.ts +9 -0
  154. package/src/product/invoice/invoiceV4.js +16 -0
  155. package/src/product/invoice/invoiceV4Document.d.ts +44 -0
  156. package/src/product/invoice/invoiceV4Document.js +146 -0
  157. package/src/{documents/invoice/invoiceLineItem.d.ts → product/invoice/invoiceV4LineItem.d.ts} +10 -8
  158. package/src/product/invoice/invoiceV4LineItem.js +101 -0
  159. package/src/product/invoiceSplitter/invoiceSplitterV1.d.ts +9 -0
  160. package/src/product/invoiceSplitter/invoiceSplitterV1.js +16 -0
  161. package/src/product/invoiceSplitter/invoiceSplitterV1Document.d.ts +8 -0
  162. package/src/product/invoiceSplitter/invoiceSplitterV1Document.js +23 -0
  163. package/src/product/invoiceSplitter/invoiceSplitterV1PageGroup.d.ts +7 -0
  164. package/src/product/invoiceSplitter/invoiceSplitterV1PageGroup.js +14 -0
  165. package/src/product/passport/passportV1.d.ts +9 -0
  166. package/src/product/passport/passportV1.js +16 -0
  167. package/src/product/passport/passportV1Document.d.ts +31 -0
  168. package/src/product/passport/passportV1Document.js +75 -0
  169. package/src/product/proofOfAddress/proofOfAddressV1.d.ts +9 -0
  170. package/src/product/proofOfAddress/proofOfAddressV1.js +16 -0
  171. package/src/product/proofOfAddress/proofOfAddressV1Document.d.ts +27 -0
  172. package/src/product/proofOfAddress/proofOfAddressV1Document.js +72 -0
  173. package/src/product/receipt/receiptV4.d.ts +9 -0
  174. package/src/product/receipt/receiptV4.js +15 -0
  175. package/src/{documents/receipt/receiptV4.d.ts → product/receipt/receiptV4Document.d.ts} +12 -12
  176. package/src/product/receipt/receiptV4Document.js +67 -0
  177. package/src/product/receipt/receiptV5.d.ts +9 -0
  178. package/src/product/receipt/receiptV5.js +16 -0
  179. package/src/{documents/receipt/receiptV5.d.ts → product/receipt/receiptV5Document.d.ts} +16 -17
  180. package/src/product/receipt/receiptV5Document.js +108 -0
  181. package/src/{documents → product}/receipt/receiptV5LineItem.d.ts +5 -5
  182. package/src/{documents → product}/receipt/receiptV5LineItem.js +20 -19
  183. package/src/product/us/bankCheck/bankCheckV1.d.ts +10 -0
  184. package/src/product/us/bankCheck/bankCheckV1.js +17 -0
  185. package/src/product/us/bankCheck/bankCheckV1Document.d.ts +21 -0
  186. package/src/product/us/bankCheck/bankCheckV1Document.js +50 -0
  187. package/src/product/us/bankCheck/bankCheckV1Page.d.ts +14 -0
  188. package/src/product/us/bankCheck/bankCheckV1Page.js +32 -0
  189. package/src/product/us/driverLicense/driverLicenseV1.d.ts +10 -0
  190. package/src/product/us/driverLicense/driverLicenseV1.js +17 -0
  191. package/src/product/us/driverLicense/driverLicenseV1Document.d.ts +43 -0
  192. package/src/product/us/driverLicense/driverLicenseV1Document.js +101 -0
  193. package/src/product/us/driverLicense/driverLicenseV1Page.d.ts +14 -0
  194. package/src/product/us/driverLicense/driverLicenseV1Page.js +29 -0
  195. package/src/product/us/index.d.ts +2 -0
  196. package/src/product/us/index.js +7 -0
  197. package/src/api/documentResponse.d.ts +0 -25
  198. package/src/api/documentResponse.js +0 -50
  199. package/src/api/endpoint.d.ts +0 -63
  200. package/src/api/endpoint.js +0 -216
  201. package/src/api/index.d.ts +0 -3
  202. package/src/api/index.js +0 -13
  203. package/src/api/predictResponse.d.ts +0 -33
  204. package/src/api/predictResponse.js +0 -52
  205. package/src/documents/cropper/cropperV1.d.ts +0 -7
  206. package/src/documents/cropper/cropperV1.js +0 -35
  207. package/src/documents/custom/customV1.d.ts +0 -10
  208. package/src/documents/custom/customV1.js +0 -53
  209. package/src/documents/document.d.ts +0 -47
  210. package/src/documents/document.js +0 -76
  211. package/src/documents/documentConfig.d.ts +0 -42
  212. package/src/documents/documentConfig.js +0 -118
  213. package/src/documents/eu/licensePlate/licensePlateV1.d.ts +0 -8
  214. package/src/documents/eu/licensePlate/licensePlateV1.js +0 -32
  215. package/src/documents/financialDocument/financialDocumentV0.d.ts +0 -28
  216. package/src/documents/financialDocument/financialDocumentV0.js +0 -140
  217. package/src/documents/financialDocument/financialDocumentV1.js +0 -197
  218. package/src/documents/fr/bankAccountDetails/bankAccountDetailsV1.d.ts +0 -13
  219. package/src/documents/fr/bankAccountDetails/bankAccountDetailsV1.js +0 -39
  220. package/src/documents/fr/bankAccountDetails/bankAccountDetailsV2.js +0 -48
  221. package/src/documents/fr/carteVitale/carteVitaleV1.d.ts +0 -14
  222. package/src/documents/fr/carteVitale/carteVitaleV1.js +0 -45
  223. package/src/documents/fr/idCard/idCardV1.d.ts +0 -28
  224. package/src/documents/fr/idCard/idCardV1.js +0 -79
  225. package/src/documents/invoice/checks.d.ts +0 -5
  226. package/src/documents/invoice/checks.js +0 -87
  227. package/src/documents/invoice/invoiceLineItem.js +0 -66
  228. package/src/documents/invoice/invoiceV3.d.ts +0 -49
  229. package/src/documents/invoice/invoiceV3.js +0 -156
  230. package/src/documents/invoice/invoiceV4.d.ts +0 -45
  231. package/src/documents/invoice/invoiceV4.js +0 -166
  232. package/src/documents/invoice/reconstruction.d.ts +0 -6
  233. package/src/documents/invoice/reconstruction.js +0 -78
  234. package/src/documents/invoiceSplitter/invoiceSplitterV1.d.ts +0 -14
  235. package/src/documents/invoiceSplitter/invoiceSplitterV1.js +0 -47
  236. package/src/documents/mindeeVision/mindeeVisionV1.d.ts +0 -8
  237. package/src/documents/mindeeVision/mindeeVisionV1.js +0 -29
  238. package/src/documents/passport/passportV1.d.ts +0 -43
  239. package/src/documents/passport/passportV1.js +0 -220
  240. package/src/documents/proofOfAddress/proofOfAddressV1.d.ts +0 -24
  241. package/src/documents/proofOfAddress/proofOfAddressV1.js +0 -77
  242. package/src/documents/receipt/receiptV3.d.ts +0 -25
  243. package/src/documents/receipt/receiptV3.js +0 -136
  244. package/src/documents/receipt/receiptV4.js +0 -78
  245. package/src/documents/receipt/receiptV5.js +0 -137
  246. package/src/documents/us/bankCheck/bankCheckV1.d.ts +0 -22
  247. package/src/documents/us/bankCheck/bankCheckV1.js +0 -63
  248. package/src/documents/us/index.d.ts +0 -1
  249. package/src/documents/us/index.js +0 -5
  250. package/src/fields/companyRegistration.js +0 -14
  251. package/src/fields/fullText.d.ts +0 -27
  252. package/src/fields/fullText.js +0 -92
  253. package/src/fields/index.d.ts +0 -12
  254. package/src/fields/index.js +0 -28
  255. package/src/fields/locale.js +0 -45
  256. package/src/math/index.d.ts +0 -1
  257. package/src/math/index.js +0 -5
  258. package/src/math/precision.d.ts +0 -1
  259. package/src/math/precision.js +0 -13
  260. /package/src/{inputs → input}/pageOptions.d.ts +0 -0
  261. /package/src/{inputs → input}/pageOptions.js +0 -0
  262. /package/src/{documents → product}/eu/index.d.ts +0 -0
  263. /package/src/{documents → product}/eu/index.js +0 -0
  264. /package/src/{documents → product}/fr/index.d.ts +0 -0
  265. /package/src/{documents → product}/fr/index.js +0 -0
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _OcrPage_instances, _OcrPage_areWordsOnSameLine, _OcrPage_toLines;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.OcrPage = void 0;
10
+ const geometry_1 = require("../../geometry");
11
+ class OcrPage {
12
+ constructor(rawPrediction) {
13
+ _OcrPage_instances.add(this);
14
+ /** Flat list of all words read */
15
+ this.allWords = [];
16
+ /** List of words by which line they are on */
17
+ this.allLines = [];
18
+ const allWords = [];
19
+ rawPrediction["all_words"] &&
20
+ rawPrediction["all_words"].forEach((word) => {
21
+ allWords.push(word);
22
+ });
23
+ this.allWords = allWords.sort((word1, word2) => (0, geometry_1.compareOnY)(word1.polygon, word2.polygon));
24
+ }
25
+ /**
26
+ * Get all words on the page as ordered lines
27
+ * @returns Sorted lines on the pages
28
+ */
29
+ getAllLines() {
30
+ if (!this.allLines || this.allLines.length === 0) {
31
+ this.allLines = __classPrivateFieldGet(this, _OcrPage_instances, "m", _OcrPage_toLines).call(this);
32
+ }
33
+ return this.allLines;
34
+ }
35
+ toString() {
36
+ return this.getAllLines()
37
+ .map((line) => line.map((word) => word.text).join(" "))
38
+ .join("\n");
39
+ }
40
+ }
41
+ exports.OcrPage = OcrPage;
42
+ _OcrPage_instances = new WeakSet(), _OcrPage_areWordsOnSameLine = function _OcrPage_areWordsOnSameLine(currentWord, nextWord) {
43
+ const currentInNext = (0, geometry_1.isPointInPolygonY)((0, geometry_1.getCentroid)(currentWord.polygon), nextWord.polygon);
44
+ const nextInCurrent = (0, geometry_1.isPointInPolygonY)((0, geometry_1.getCentroid)(nextWord.polygon), currentWord.polygon);
45
+ return nextInCurrent || currentInNext;
46
+ }, _OcrPage_toLines = function _OcrPage_toLines() {
47
+ const lines = [];
48
+ const lineIdx = [];
49
+ this.allWords.forEach((current, idxCurrent) => {
50
+ if (!lineIdx.includes(idxCurrent)) {
51
+ lines.push([current]);
52
+ lineIdx.push(idxCurrent);
53
+ }
54
+ this.allWords.forEach((next, idxNext) => {
55
+ if (idxCurrent === idxNext || lineIdx.includes(idxNext)) {
56
+ return;
57
+ }
58
+ if (__classPrivateFieldGet(this, _OcrPage_instances, "m", _OcrPage_areWordsOnSameLine).call(this, current, next)) {
59
+ lineIdx.push(idxNext);
60
+ lines[lines.length - 1].push(next);
61
+ }
62
+ });
63
+ });
64
+ lines.forEach((line) => line.sort((word1, word2) => (0, geometry_1.compareOnX)(word1.polygon, word2.polygon)));
65
+ return lines;
66
+ };
@@ -1,4 +1,4 @@
1
- import { BaseField, BaseFieldConstructor } from "./base";
1
+ import { BaseField, BaseFieldConstructor } from "../standard";
2
2
  interface OrientationFieldConstructor extends BaseFieldConstructor {
3
3
  pageId: number;
4
4
  }
@@ -13,7 +13,7 @@ export declare class OrientationField extends BaseField {
13
13
  /**
14
14
  * @param {Object} prediction - Prediction object from HTTP response
15
15
  * @param {String} valueKey - Key to use in the prediction dict
16
- * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
16
+ * @param {Boolean} reconstructed - Is the object reconstructed (not extracted by the API)
17
17
  * @param {Integer} pageId - Page ID for multi-page document
18
18
  */
19
19
  constructor({ prediction, valueKey, reconstructed, pageId, }: OrientationFieldConstructor);
@@ -1,18 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OrientationField = void 0;
4
- const base_1 = require("./base");
4
+ const standard_1 = require("../standard");
5
5
  /**
6
6
  * The clockwise rotation to apply (in degrees) to make the image upright.
7
7
  */
8
- class OrientationField extends base_1.BaseField {
8
+ class OrientationField extends standard_1.BaseField {
9
9
  /**
10
10
  * @param {Object} prediction - Prediction object from HTTP response
11
11
  * @param {String} valueKey - Key to use in the prediction dict
12
- * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
12
+ * @param {Boolean} reconstructed - Is the object reconstructed (not extracted by the API)
13
13
  * @param {Integer} pageId - Page ID for multi-page document
14
14
  */
15
- constructor({ prediction, valueKey = "value", reconstructed = false, pageId, }) {
15
+ constructor({ prediction = {}, valueKey = "value", reconstructed = false, pageId, }) {
16
16
  super({ prediction, valueKey, reconstructed });
17
17
  const orientations = [0, 90, 180, 270];
18
18
  this.pageId = pageId;
@@ -0,0 +1,12 @@
1
+ import { Extras } from "./extras/extras";
2
+ import { OrientationField } from "./orientation";
3
+ import { Prediction } from "./prediction";
4
+ import { StringDict } from "./stringDict";
5
+ export declare class Page<T extends Prediction> {
6
+ id: number;
7
+ orientation?: OrientationField;
8
+ prediction: T;
9
+ extras?: Extras;
10
+ constructor(predictionType: new (rawPrediction: StringDict, pageId: number) => T, rawPrediction: StringDict, pageId: number, orientation?: StringDict);
11
+ toString(): string;
12
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Page = void 0;
4
+ const cropperExtra_1 = require("./extras/cropperExtra");
5
+ const extras_1 = require("./extras/extras");
6
+ const orientation_1 = require("./orientation");
7
+ class Page {
8
+ constructor(predictionType, rawPrediction, pageId, orientation) {
9
+ if (pageId !== undefined && orientation !== undefined) {
10
+ this.orientation = new orientation_1.OrientationField({
11
+ prediction: orientation,
12
+ pageId: pageId,
13
+ });
14
+ }
15
+ else {
16
+ orientation = undefined;
17
+ }
18
+ this.id = pageId;
19
+ this.prediction = new predictionType(rawPrediction["prediction"], pageId);
20
+ if (rawPrediction["extras"] &&
21
+ Object.keys(rawPrediction["extras"].length > 0)) {
22
+ const extras = {};
23
+ Object.entries(rawPrediction["extras"]).forEach(([extraKey, extraValue]) => {
24
+ switch (extraKey) {
25
+ case "cropper":
26
+ extras["cropper"] = new cropperExtra_1.CropperExtra(extraValue);
27
+ }
28
+ });
29
+ this.extras = new extras_1.Extras(extras);
30
+ }
31
+ }
32
+ toString() {
33
+ const title = `Page ${this.id}`;
34
+ return `${title}
35
+ ${"-".repeat(title.length)}
36
+ ${this.prediction.toString()}
37
+ `;
38
+ }
39
+ }
40
+ exports.Page = Page;
@@ -0,0 +1,6 @@
1
+ import { ApiResponse } from "./apiResponse";
2
+ import { Document, Inference, StringDict } from ".";
3
+ export declare class PredictResponse<T extends Inference> extends ApiResponse {
4
+ document: Document<T>;
5
+ constructor(inferenceClass: new (rawPrediction: StringDict) => T, rawPrediction: StringDict);
6
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PredictResponse = void 0;
4
+ const apiResponse_1 = require("./apiResponse");
5
+ const _1 = require(".");
6
+ class PredictResponse extends apiResponse_1.ApiResponse {
7
+ constructor(inferenceClass, rawPrediction) {
8
+ super(rawPrediction);
9
+ this.document = new _1.Document(inferenceClass, rawPrediction["document"]);
10
+ }
11
+ }
12
+ exports.PredictResponse = PredictResponse;
@@ -0,0 +1,2 @@
1
+ export declare class Prediction {
2
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Prediction = void 0;
4
+ class Prediction {
5
+ }
6
+ exports.Prediction = Prediction;
@@ -0,0 +1,4 @@
1
+ export interface Product {
2
+ name?: string;
3
+ version?: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export type StringDict = {
2
+ [index: string]: any;
3
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export declare function cleanOutString(outStr: string): string;
2
+ /**
3
+ *
4
+ * @param columnSizes Size of each column in the table
5
+ * @param separator character for a separator
6
+ * @returns A separator for table lines
7
+ */
8
+ export declare function lineSeparator(columnSizes: number[], separator: string): string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lineSeparator = exports.cleanOutString = void 0;
4
+ function cleanOutString(outStr) {
5
+ const lines = / \n/gm;
6
+ return outStr.replace(lines, "\n");
7
+ }
8
+ exports.cleanOutString = cleanOutString;
9
+ /**
10
+ *
11
+ * @param columnSizes Size of each column in the table
12
+ * @param separator character for a separator
13
+ * @returns A separator for table lines
14
+ */
15
+ function lineSeparator(columnSizes, separator) {
16
+ let outStr = " +";
17
+ columnSizes.forEach((size) => {
18
+ outStr += separator.repeat(size) + "+";
19
+ });
20
+ return outStr;
21
+ }
22
+ exports.lineSeparator = lineSeparator;
@@ -0,0 +1,16 @@
1
+ import { StringDict } from "../common";
2
+ export declare class ClassificationField {
3
+ /** The value for the classification. */
4
+ value: string;
5
+ /**
6
+ * The confidence score of the prediction.
7
+ * Note: Score is calculated on **word selection**, not its textual content (OCR).
8
+ */
9
+ confidence: number;
10
+ pageId?: number;
11
+ constructor({ prediction, pageId, }: {
12
+ prediction: StringDict;
13
+ pageId?: number;
14
+ });
15
+ toString(): string;
16
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClassificationField = void 0;
4
+ class ClassificationField {
5
+ constructor({ prediction, pageId, }) {
6
+ this.value = prediction["value"];
7
+ this.confidence = prediction["confidence"];
8
+ this.pageId ?? (this.pageId = pageId);
9
+ }
10
+ toString() {
11
+ return `${this.value}`;
12
+ }
13
+ }
14
+ exports.ClassificationField = ClassificationField;
@@ -0,0 +1,3 @@
1
+ export { Line, LineItems, getLineItems } from "./lineItems";
2
+ export { ClassificationField } from "./classificationField";
3
+ export { ListField, ListFieldValue } from "./listField";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListFieldValue = exports.ListField = exports.ClassificationField = exports.getLineItems = exports.LineItems = exports.Line = void 0;
4
+ var lineItems_1 = require("./lineItems");
5
+ Object.defineProperty(exports, "Line", { enumerable: true, get: function () { return lineItems_1.Line; } });
6
+ Object.defineProperty(exports, "LineItems", { enumerable: true, get: function () { return lineItems_1.LineItems; } });
7
+ Object.defineProperty(exports, "getLineItems", { enumerable: true, get: function () { return lineItems_1.getLineItems; } });
8
+ var classificationField_1 = require("./classificationField");
9
+ Object.defineProperty(exports, "ClassificationField", { enumerable: true, get: function () { return classificationField_1.ClassificationField; } });
10
+ var listField_1 = require("./listField");
11
+ Object.defineProperty(exports, "ListField", { enumerable: true, get: function () { return listField_1.ListField; } });
12
+ Object.defineProperty(exports, "ListFieldValue", { enumerable: true, get: function () { return listField_1.ListFieldValue; } });
@@ -1,9 +1,9 @@
1
1
  import { BBox, Polygon } from "../../geometry";
2
- import { ListField, ListFieldValue } from "./fields";
2
+ import { ListField, ListFieldValue } from "./listField";
3
3
  export declare class Line {
4
4
  /**
5
5
  * Number of the current line.
6
- * Starts to 1.
6
+ * Starts at 1.
7
7
  */
8
8
  rowNumber: number;
9
9
  /**
@@ -16,7 +16,7 @@ export declare class Line {
16
16
  bbox: BBox;
17
17
  /**
18
18
  * The height tolerance used to build the line.
19
- * It helps when the height of an expected line can vary.
19
+ * It helps when the height of a line can vary unexpectedly.
20
20
  */
21
21
  heightTolerance: number;
22
22
  constructor(rowNumber: number, heightTolerance: number);
@@ -38,4 +38,4 @@ export declare class LineItems {
38
38
  rows: Line[];
39
39
  constructor(lines: Line[]);
40
40
  }
41
- export declare function getLineItems(anchorNames: string[], heigthLineTolerance: number, fieldNamesTargeted: string[], fields: Map<string, ListField>): LineItems;
41
+ export declare function getLineItems(anchorNames: string[], heightLineTolerance: number, fieldNamesTargeted: string[], fields: Map<string, ListField>): LineItems;
@@ -4,8 +4,7 @@ exports.getLineItems = exports.LineItems = exports.Line = void 0;
4
4
  const handler_1 = require("../../errors/handler");
5
5
  const errors_1 = require("../../errors");
6
6
  const geometry_1 = require("../../geometry");
7
- const fields_1 = require("./fields");
8
- const math_1 = require("../../math");
7
+ const listField_1 = require("./listField");
9
8
  class Line {
10
9
  constructor(rowNumber, heightTolerance) {
11
10
  this.rowNumber = rowNumber;
@@ -29,7 +28,10 @@ class Line {
29
28
  * Check if the bbox fits the current line.
30
29
  */
31
30
  contains(bbox) {
32
- return (0, math_1.precisionEquals)(this.bbox[1], bbox[1], this.heightTolerance);
31
+ if (Math.abs(bbox[1] - this.bbox[1]) <= this.heightTolerance) {
32
+ return true;
33
+ }
34
+ return Math.abs(this.bbox[1] - bbox[1]) <= this.heightTolerance;
33
35
  }
34
36
  updateField(name, fieldValue) {
35
37
  if (!this.fields.has(name)) {
@@ -48,7 +50,7 @@ class Line {
48
50
  existingField.polygon,
49
51
  fieldValue.polygon,
50
52
  ]);
51
- this.fields.set(name, new fields_1.ListFieldValue({
53
+ this.fields.set(name, new listField_1.ListFieldValue({
52
54
  content: mergedContent,
53
55
  confidence: existingField.confidence * fieldValue.confidence,
54
56
  polygon: (0, geometry_1.getBoundingBoxFromBBox)(mergedBbox),
@@ -64,10 +66,10 @@ class LineItems {
64
66
  }
65
67
  }
66
68
  exports.LineItems = LineItems;
67
- function getLineItems(anchorNames, heigthLineTolerance, fieldNamesTargeted, fields) {
69
+ function getLineItems(anchorNames, heightLineTolerance, fieldNamesTargeted, fields) {
68
70
  const fieldsToTransformIntoLines = new Map([...fields].filter(([k]) => fieldNamesTargeted.includes(k)));
69
71
  const anchorName = findBestAnchor(anchorNames, fieldsToTransformIntoLines);
70
- const lineItemsPrepared = prepare(anchorName, fieldsToTransformIntoLines, heigthLineTolerance);
72
+ const lineItemsPrepared = prepare(anchorName, fieldsToTransformIntoLines, heightLineTolerance);
71
73
  lineItemsPrepared.rows.forEach((currentLine) => {
72
74
  fieldsToTransformIntoLines.forEach((field, fieldName) => {
73
75
  field.values.forEach((listFieldValue) => {
@@ -97,14 +99,14 @@ function findBestAnchor(possibleAnchorNames, fields) {
97
99
  }
98
100
  return anchorName;
99
101
  }
100
- function prepare(anchorName, fields, heigthLineTolerance) {
102
+ function prepare(anchorName, fields, heightLineTolerance) {
101
103
  const lineItemsPrepared = [];
102
104
  const anchorField = fields.get(anchorName);
103
105
  if (anchorField === undefined || anchorField.values.length === 0) {
104
106
  handler_1.errorHandler.throw(new errors_1.MindeeError("No lines have been detected."));
105
107
  }
106
108
  let currentLineNumber = 1;
107
- let currentLine = new Line(currentLineNumber, heigthLineTolerance);
109
+ let currentLine = new Line(currentLineNumber, heightLineTolerance);
108
110
  if (anchorField !== undefined) {
109
111
  let currentValue = anchorField.values[0];
110
112
  currentLine.extendWith(currentValue.polygon);
@@ -114,7 +116,7 @@ function prepare(anchorName, fields, heigthLineTolerance) {
114
116
  if (!currentLine.contains(currentFieldBbox)) {
115
117
  lineItemsPrepared.push(currentLine);
116
118
  currentLineNumber++;
117
- currentLine = new Line(currentLineNumber, heigthLineTolerance);
119
+ currentLine = new Line(currentLineNumber, heightLineTolerance);
118
120
  }
119
121
  currentLine.extendWithBbox(currentFieldBbox);
120
122
  }
@@ -1,19 +1,6 @@
1
- import { StringDict } from "../../fields/base";
2
- import { FieldConstructor } from "../../fields/field";
1
+ import { FieldConstructor } from "../standard";
3
2
  import { Polygon } from "../../geometry";
4
- export declare class ClassificationField {
5
- /** The value for the classification. */
6
- value: string;
7
- /**
8
- * The confidence score of the prediction.
9
- * Note: Score is calculated on **word selection**, not its textual content (OCR).
10
- */
11
- confidence: number;
12
- constructor({ prediction }: {
13
- prediction: StringDict;
14
- });
15
- toString(): string;
16
- }
3
+ import { StringDict } from "../common";
17
4
  export declare class ListFieldValue {
18
5
  /** Extracted content of the prediction */
19
6
  content: string | number;
@@ -42,7 +29,7 @@ export declare class ListField {
42
29
  reconstructed: boolean;
43
30
  /** The document page on which the information was found. */
44
31
  pageId: number;
45
- constructor({ prediction, reconstructed, pageId }: FieldConstructor);
32
+ constructor({ prediction, reconstructed, pageId, }: FieldConstructor);
46
33
  contentsList(): Array<string | number>;
47
34
  contentsString(separator?: string): string;
48
35
  toString(): string;
@@ -1,17 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ListField = exports.ListFieldValue = exports.ClassificationField = void 0;
3
+ exports.ListField = exports.ListFieldValue = void 0;
4
4
  const geometry_1 = require("../../geometry");
5
- class ClassificationField {
6
- constructor({ prediction }) {
7
- this.value = prediction["value"];
8
- this.confidence = prediction["confidence"];
9
- }
10
- toString() {
11
- return `${this.value}`;
12
- }
13
- }
14
- exports.ClassificationField = ClassificationField;
15
5
  class ListFieldValue {
16
6
  constructor(prediction) {
17
7
  /**
@@ -28,7 +18,7 @@ class ListFieldValue {
28
18
  this.confidence = prediction["confidence"];
29
19
  if (prediction["polygon"]) {
30
20
  this.polygon = prediction["polygon"];
31
- this.bbox = (0, geometry_1.getBoundingBox)(prediction.polygon);
21
+ this.bbox = (0, geometry_1.getBoundingBox)(prediction["polygon"]);
32
22
  }
33
23
  }
34
24
  toString() {
@@ -37,12 +27,12 @@ class ListFieldValue {
37
27
  }
38
28
  exports.ListFieldValue = ListFieldValue;
39
29
  class ListField {
40
- constructor({ prediction, reconstructed = false, pageId }) {
30
+ constructor({ prediction = {}, reconstructed = false, pageId, }) {
41
31
  this.values = [];
42
32
  this.confidence = prediction["confidence"];
43
33
  this.reconstructed = reconstructed;
44
34
  this.pageId = pageId !== undefined ? pageId : prediction["page_id"];
45
- if (Object.prototype.hasOwnProperty.call(prediction, "values")) {
35
+ if (prediction["values"] !== undefined) {
46
36
  prediction["values"].forEach((field) => {
47
37
  this.values.push(new ListFieldValue(field));
48
38
  });
@@ -0,0 +1,3 @@
1
+ export * as common from "./common";
2
+ export * as custom from "./custom";
3
+ export * as standard from "./standard";
@@ -0,0 +1,29 @@
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
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.standard = exports.custom = exports.common = void 0;
27
+ exports.common = __importStar(require("./common"));
28
+ exports.custom = __importStar(require("./custom"));
29
+ exports.standard = __importStar(require("./standard"));
@@ -3,13 +3,13 @@ export declare function floatToString(value: number): string;
3
3
  /**
4
4
  * A field containing an amount value.
5
5
  */
6
- export declare class Amount extends Field {
6
+ export declare class AmountField extends Field {
7
7
  /** The value. */
8
8
  value?: number;
9
9
  /**
10
10
  * @param {Object} prediction - Prediction object from HTTP response
11
11
  * @param {String} valueKey - Key to use in the prediction dict
12
- * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
12
+ * @param {Boolean} reconstructed - Is the object reconstructed (not extracted by the API)
13
13
  * @param {Integer} pageId - Page ID for multi-page document
14
14
  */
15
15
  constructor({ prediction, valueKey, reconstructed, pageId, }: FieldConstructor);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Amount = exports.floatToString = void 0;
3
+ exports.AmountField = exports.floatToString = void 0;
4
4
  const field_1 = require("./field");
5
5
  function floatToString(value) {
6
6
  return value.toLocaleString(undefined, {
@@ -13,14 +13,14 @@ exports.floatToString = floatToString;
13
13
  /**
14
14
  * A field containing an amount value.
15
15
  */
16
- class Amount extends field_1.Field {
16
+ class AmountField extends field_1.Field {
17
17
  /**
18
18
  * @param {Object} prediction - Prediction object from HTTP response
19
19
  * @param {String} valueKey - Key to use in the prediction dict
20
- * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
20
+ * @param {Boolean} reconstructed - Is the object reconstructed (not extracted by the API)
21
21
  * @param {Integer} pageId - Page ID for multi-page document
22
22
  */
23
- constructor({ prediction, valueKey = "value", reconstructed = false, pageId = undefined, }) {
23
+ constructor({ prediction = {}, valueKey = "value", reconstructed = false, pageId = undefined, }) {
24
24
  super({ prediction, valueKey, reconstructed, pageId });
25
25
  /** The value. */
26
26
  this.value = undefined;
@@ -37,4 +37,4 @@ class Amount extends field_1.Field {
37
37
  return "";
38
38
  }
39
39
  }
40
- exports.Amount = Amount;
40
+ exports.AmountField = AmountField;
@@ -1,10 +1,9 @@
1
- export type StringDict = {
2
- [index: string]: any;
3
- };
1
+ import { StringDict } from "../common";
4
2
  export interface BaseFieldConstructor {
5
3
  prediction: StringDict;
6
4
  valueKey?: string;
7
5
  reconstructed?: boolean;
6
+ pageId?: number;
8
7
  }
9
8
  /**
10
9
  * Base class for most fields.
@@ -14,12 +13,13 @@ export declare class BaseField {
14
13
  value?: string | number;
15
14
  /** `true` when the field was reconstructed or computed using other fields. */
16
15
  reconstructed: boolean;
16
+ pageId?: number;
17
17
  /**
18
18
  * @param {Object} prediction - Prediction object from HTTP response
19
19
  * @param {String} valueKey - Key to use in the prediction dict
20
- * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
20
+ * @param {Boolean} reconstructed - Is the object reconstructed (not extracted by the API)
21
21
  */
22
- constructor({ prediction, valueKey, reconstructed, }: BaseFieldConstructor);
22
+ constructor({ prediction, valueKey, reconstructed, pageId, }: BaseFieldConstructor);
23
23
  compare(other: BaseField): boolean;
24
24
  /**
25
25
  * @param {BaseField[]} array - Array of Fields
@@ -8,9 +8,9 @@ class BaseField {
8
8
  /**
9
9
  * @param {Object} prediction - Prediction object from HTTP response
10
10
  * @param {String} valueKey - Key to use in the prediction dict
11
- * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
11
+ * @param {Boolean} reconstructed - Is the object reconstructed (not extracted by the API)
12
12
  */
13
- constructor({ prediction, valueKey = "value", reconstructed = false, }) {
13
+ constructor({ prediction = {}, valueKey = "value", reconstructed = false, pageId = undefined, }) {
14
14
  /** The value. */
15
15
  this.value = undefined;
16
16
  this.reconstructed = reconstructed;
@@ -19,6 +19,7 @@ class BaseField {
19
19
  valueKey in prediction &&
20
20
  prediction[valueKey] !== null) {
21
21
  this.value = prediction[valueKey];
22
+ this.pageId = pageId !== undefined ? pageId : prediction["page_id"];
22
23
  }
23
24
  }
24
25
  compare(other) {
@@ -7,5 +7,5 @@ export declare class ClassificationField extends BaseField {
7
7
  confidence: number;
8
8
  /** The classification. */
9
9
  value?: string;
10
- constructor({ prediction, valueKey, reconstructed, }: BaseFieldConstructor);
10
+ constructor({ prediction, valueKey, reconstructed, pageId, }: BaseFieldConstructor);
11
11
  }
@@ -6,9 +6,9 @@ const base_1 = require("./base");
6
6
  * Represents a classifier value.
7
7
  */
8
8
  class ClassificationField extends base_1.BaseField {
9
- constructor({ prediction, valueKey = "value", reconstructed = false, }) {
10
- super({ prediction, valueKey, reconstructed });
11
- this.confidence = prediction.confidence ? prediction.confidence : 0.0;
9
+ constructor({ prediction = {}, valueKey = "value", reconstructed = false, pageId = undefined, }) {
10
+ super({ prediction, valueKey, reconstructed, pageId });
11
+ this.confidence = prediction["confidence"] ? prediction["confidence"] : 0.0;
12
12
  }
13
13
  }
14
14
  exports.ClassificationField = ClassificationField;
@@ -2,7 +2,7 @@ import { Field, FieldConstructor } from "./field";
2
2
  /**
3
3
  * A company registration item.
4
4
  */
5
- export declare class CompanyRegistration extends Field {
5
+ export declare class CompanyRegistrationField extends Field {
6
6
  /** Registration identifier. */
7
7
  value?: string;
8
8
  /** Type of company registration. */