mindee 3.10.2 → 4.0.1

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 +24 -0
  2. package/README.md +103 -41
  3. package/package.json +4 -5
  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
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Document = void 0;
4
- const fields_1 = require("../fields");
5
- class Document {
6
- constructor({ orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, documentType, }) {
7
- this.filename = "";
8
- this.cropper = [];
9
- this.filepath = undefined;
10
- this.pageId = pageId;
11
- if (documentType === undefined || documentType === "") {
12
- this.docType = Object.getPrototypeOf(this).constructor.name;
13
- }
14
- else {
15
- this.docType = documentType;
16
- }
17
- if (pageId !== undefined && orientation !== undefined) {
18
- this.orientation = new fields_1.OrientationField({
19
- prediction: orientation,
20
- pageId: pageId,
21
- });
22
- }
23
- if (extras !== undefined) {
24
- if (extras.cropper !== undefined) {
25
- extras.cropper.cropping.forEach((crop) => {
26
- this.cropper.push(new fields_1.PositionField({
27
- prediction: crop,
28
- pageId: pageId,
29
- }));
30
- });
31
- }
32
- }
33
- if (inputSource !== undefined) {
34
- this.filepath = inputSource.filepath;
35
- this.filename = inputSource.filename;
36
- this.mimeType = inputSource.mimeType;
37
- }
38
- this.fullText = fullText;
39
- this.checklist = {};
40
- }
41
- clone() {
42
- return JSON.parse(JSON.stringify(this));
43
- }
44
- /** return true if all checklist of the document if true */
45
- checkAll() {
46
- return Object.values(this.checklist).every((item) => item);
47
- }
48
- /**
49
- * Takes a list of Documents and return one Document where
50
- * each field is set with the maximum probability field
51
- * @param {Array<Document>} documents - A list of Documents
52
- */
53
- static mergePages(documents) {
54
- const finalDocument = documents[0].clone();
55
- const attributes = Object.getOwnPropertyNames(finalDocument);
56
- for (const document of documents) {
57
- for (const attribute of attributes) {
58
- if (Array.isArray(document?.[attribute])) {
59
- finalDocument[attribute] = finalDocument[attribute]?.length
60
- ? finalDocument[attribute]
61
- : document?.[attribute];
62
- }
63
- else if (document?.[attribute]?.confidence >
64
- finalDocument[attribute].confidence) {
65
- finalDocument[attribute] = document?.[attribute];
66
- }
67
- }
68
- }
69
- return finalDocument;
70
- }
71
- static cleanOutString(outStr) {
72
- const lines = / \n/gm;
73
- return outStr.replace(lines, "\n");
74
- }
75
- }
76
- exports.Document = Document;
@@ -1,42 +0,0 @@
1
- import { InputSource } from "../inputs";
2
- import { Response, Endpoint, EndpointResponse, AsyncPredictResponse } from "../api";
3
- import { Document, FinancialDocumentV0, CustomV1, DocumentSig } from "./index";
4
- import { PageOptions } from "../inputs";
5
- interface CustomDocConstructor {
6
- endpointName: string;
7
- accountName: string;
8
- version: string;
9
- apiKey: string;
10
- }
11
- export declare class DocumentConfig<DocType extends Document> {
12
- readonly documentType: string | undefined;
13
- readonly endpoints: Array<Endpoint>;
14
- readonly documentClass: DocumentSig<DocType>;
15
- constructor(documentClass: DocumentSig<DocType>, endpoints: Array<Endpoint>, documentType?: string);
16
- predict(params: {
17
- inputDoc: InputSource;
18
- includeWords: boolean;
19
- pageOptions?: PageOptions;
20
- cropper: boolean;
21
- }): Promise<Response<DocType>>;
22
- predictAsync(params: {
23
- inputDoc: InputSource;
24
- includeWords: boolean;
25
- pageOptions?: PageOptions;
26
- cropper: boolean;
27
- }): Promise<AsyncPredictResponse<DocType>>;
28
- getQueuedDocument(queuId: string): Promise<AsyncPredictResponse<DocType>>;
29
- cutDocPages(inputDoc: InputSource, pageOptions: PageOptions): Promise<void>;
30
- protected predictRequest(inputDoc: InputSource, includeWords: boolean, cropping: boolean): Promise<EndpointResponse>;
31
- protected handleError(response: EndpointResponse, statusCode?: number): void;
32
- protected buildResult(response: EndpointResponse, inputFile?: InputSource): Response<DocType>;
33
- protected checkApiKeys(): void;
34
- }
35
- export declare class CustomDocConfig extends DocumentConfig<CustomV1> {
36
- constructor({ endpointName, accountName, version, apiKey, }: CustomDocConstructor);
37
- }
38
- export declare class FinancialDocV0Config extends DocumentConfig<FinancialDocumentV0> {
39
- constructor(apiKey: string);
40
- protected predictRequest(inputDoc: InputSource, includeWords: boolean, cropping: boolean): Promise<EndpointResponse>;
41
- }
42
- export {};
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FinancialDocV0Config = exports.CustomDocConfig = exports.DocumentConfig = void 0;
4
- const api_1 = require("../api");
5
- const index_1 = require("./index");
6
- const handler_1 = require("../errors/handler");
7
- class DocumentConfig {
8
- constructor(documentClass, endpoints, documentType) {
9
- this.documentType = documentType;
10
- this.endpoints = endpoints;
11
- this.documentClass = documentClass;
12
- }
13
- async predict(params) {
14
- this.checkApiKeys();
15
- await params.inputDoc.init();
16
- if (params.pageOptions !== undefined) {
17
- await this.cutDocPages(params.inputDoc, params.pageOptions);
18
- }
19
- const response = await this.predictRequest(params.inputDoc, params.includeWords, params.cropper);
20
- return this.buildResult(response, params.inputDoc);
21
- }
22
- async predictAsync(params) {
23
- this.checkApiKeys();
24
- await params.inputDoc.init();
25
- if (params.pageOptions !== undefined) {
26
- await this.cutDocPages(params.inputDoc, params.pageOptions);
27
- }
28
- const response = await this.endpoints[0].predictAsyncReqPost(params.inputDoc, params.includeWords, params.cropper);
29
- const statusCode = response.messageObj.statusCode;
30
- if (statusCode === undefined || statusCode >= 300) {
31
- this.handleError(response, statusCode);
32
- }
33
- return new api_1.AsyncPredictResponse(response.data);
34
- }
35
- async getQueuedDocument(queuId) {
36
- this.checkApiKeys();
37
- const queueResponse = await this.endpoints[0].documentQueueReqGet(queuId);
38
- const queueStatusCode = queueResponse.messageObj.statusCode;
39
- if (queueStatusCode === undefined ||
40
- queueStatusCode < 200 ||
41
- queueStatusCode >= 400) {
42
- this.handleError(queueResponse, queueStatusCode);
43
- }
44
- if (queueStatusCode === 302 &&
45
- queueResponse.messageObj.headers.location !== undefined) {
46
- const docId = queueResponse.messageObj.headers.location.split("/").pop();
47
- if (docId !== undefined) {
48
- const docResponse = await this.endpoints[0].documentGetReq(docId);
49
- const document = this.buildResult(docResponse);
50
- return new api_1.AsyncPredictResponse(docResponse.data, document);
51
- }
52
- }
53
- return new api_1.AsyncPredictResponse(queueResponse.data);
54
- }
55
- async cutDocPages(inputDoc, pageOptions) {
56
- if (inputDoc.isPdf()) {
57
- await inputDoc.cutPdf(pageOptions);
58
- }
59
- }
60
- // this is only a separate function because of financial docs
61
- async predictRequest(inputDoc, includeWords, cropping) {
62
- return await this.endpoints[0].predictReqPost(inputDoc, includeWords, cropping);
63
- }
64
- handleError(response, statusCode) {
65
- const errorMessage = JSON.stringify(response.data, null, 2);
66
- handler_1.errorHandler.throw(new Error(`${this.endpoints[0].urlName} API ${statusCode} HTTP error: ${errorMessage}`));
67
- }
68
- buildResult(response, inputFile) {
69
- const statusCode = response.messageObj.statusCode;
70
- if (statusCode === undefined || statusCode > 201) {
71
- this.handleError(response, statusCode);
72
- }
73
- return new api_1.Response(this.documentClass, {
74
- httpResponse: response,
75
- documentType: this.documentType,
76
- error: false,
77
- input: inputFile,
78
- });
79
- }
80
- checkApiKeys() {
81
- this.endpoints.forEach((endpoint) => {
82
- if (!endpoint.apiKey) {
83
- throw new Error(`Missing API key for '${endpoint.urlName} ${endpoint.version}', check your Client configuration.
84
- You can set this using the '${api_1.API_KEY_ENVVAR_NAME}' environment variable.\n`);
85
- }
86
- });
87
- }
88
- }
89
- exports.DocumentConfig = DocumentConfig;
90
- class CustomDocConfig extends DocumentConfig {
91
- constructor({ endpointName, accountName, version, apiKey, }) {
92
- const endpoints = [
93
- new api_1.CustomEndpoint(endpointName, accountName, version, apiKey),
94
- ];
95
- super(index_1.CustomV1, endpoints, endpointName);
96
- }
97
- }
98
- exports.CustomDocConfig = CustomDocConfig;
99
- class FinancialDocV0Config extends DocumentConfig {
100
- constructor(apiKey) {
101
- const endpoints = [
102
- new api_1.StandardEndpoint("invoices", "3", apiKey),
103
- new api_1.StandardEndpoint("expense_receipts", "3", apiKey),
104
- ];
105
- super(index_1.FinancialDocumentV0, endpoints);
106
- }
107
- async predictRequest(inputDoc, includeWords, cropping) {
108
- let endpoint;
109
- if (inputDoc.isPdf()) {
110
- endpoint = this.endpoints[0];
111
- }
112
- else {
113
- endpoint = this.endpoints[1];
114
- }
115
- return await endpoint.predictReqPost(inputDoc, includeWords, cropping);
116
- }
117
- }
118
- exports.FinancialDocV0Config = FinancialDocV0Config;
@@ -1,8 +0,0 @@
1
- import { Document, DocumentConstructorProps } from "../../document";
2
- import { TextField } from "../../../fields";
3
- export declare class LicensePlateV1 extends Document {
4
- /** A list of license plates. */
5
- licensePlates: TextField[];
6
- constructor({ prediction, orientation, extras, inputSource, pageId, }: DocumentConstructorProps);
7
- toString(): string;
8
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LicensePlateV1 = void 0;
4
- const document_1 = require("../../document");
5
- const fields_1 = require("../../../fields");
6
- class LicensePlateV1 extends document_1.Document {
7
- constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, pageId = undefined, }) {
8
- super({
9
- inputSource: inputSource,
10
- pageId: pageId,
11
- orientation: orientation,
12
- extras: extras,
13
- });
14
- /** A list of license plates. */
15
- this.licensePlates = [];
16
- prediction.license_plates.map((prediction) => this.licensePlates.push(new fields_1.TextField({
17
- prediction: prediction,
18
- pageId: pageId,
19
- })));
20
- }
21
- toString() {
22
- const outStr = `----- EU License Plate V1 -----
23
- Filename: ${this.filename}
24
- License Plates: ${this.licensePlates
25
- .map((plate) => plate.value)
26
- .join("\n ")}
27
- ----------------------
28
- `;
29
- return LicensePlateV1.cleanOutString(outStr);
30
- }
31
- }
32
- exports.LicensePlateV1 = LicensePlateV1;
@@ -1,28 +0,0 @@
1
- import { Document, DocumentConstructorProps } from "../document";
2
- import { TaxField, TextField, Amount, Locale, DateField as Date, CompanyRegistration } from "../../fields";
3
- /**
4
- * @deprecated You should use FinancialDocumentV1 instead.
5
- */
6
- export declare class FinancialDocumentV0 extends Document {
7
- #private;
8
- pageId: number | undefined;
9
- locale: Locale;
10
- totalIncl: Amount;
11
- date: Date;
12
- dueDate: Date;
13
- category: TextField;
14
- time: TextField;
15
- taxes: TaxField[];
16
- totalTax: Amount;
17
- totalExcl: Amount;
18
- supplier: TextField;
19
- supplierAddress: TextField;
20
- invoiceNumber: TextField;
21
- companyRegistration: CompanyRegistration[];
22
- customerName: TextField;
23
- customerAddress: TextField;
24
- paymentDetails: TextField[];
25
- customerCompanyRegistration: CompanyRegistration[];
26
- constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
27
- toString(): string;
28
- }
@@ -1,140 +0,0 @@
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 _FinancialDocumentV0_instances, _FinancialDocumentV0_initFromApiPrediction, _FinancialDocumentV0_checklist, _FinancialDocumentV0_taxesMatchTotalIncl;
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.FinancialDocumentV0 = void 0;
10
- const document_1 = require("../document");
11
- const invoiceV3_1 = require("../invoice/invoiceV3");
12
- const receiptV3_1 = require("../receipt/receiptV3");
13
- const fields_1 = require("../../fields");
14
- /**
15
- * @deprecated You should use FinancialDocumentV1 instead.
16
- */
17
- class FinancialDocumentV0 extends document_1.Document {
18
- constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {
19
- super({
20
- inputSource: inputSource,
21
- pageId: pageId,
22
- orientation: orientation,
23
- fullText: fullText,
24
- extras: extras,
25
- });
26
- _FinancialDocumentV0_instances.add(this);
27
- this.taxes = [];
28
- this.companyRegistration = [];
29
- this.paymentDetails = [];
30
- this.customerCompanyRegistration = [];
31
- __classPrivateFieldGet(this, _FinancialDocumentV0_instances, "m", _FinancialDocumentV0_initFromApiPrediction).call(this, prediction, inputSource, pageId, orientation, extras);
32
- __classPrivateFieldGet(this, _FinancialDocumentV0_instances, "m", _FinancialDocumentV0_checklist).call(this);
33
- }
34
- toString() {
35
- const outStr = `-----Financial document-----
36
- Filename: ${this.filename}
37
- Total amount: ${this.totalIncl.value}
38
- Date: ${this.date.value}
39
- Supplier: ${this.supplier.value}
40
- Total taxes: ${this.totalTax.value}
41
- ----------------------
42
- `;
43
- return FinancialDocumentV0.cleanOutString(outStr);
44
- }
45
- }
46
- exports.FinancialDocumentV0 = FinancialDocumentV0;
47
- _FinancialDocumentV0_instances = new WeakSet(), _FinancialDocumentV0_initFromApiPrediction = function _FinancialDocumentV0_initFromApiPrediction(prediction, inputFile, pageNumber, orientation, extras) {
48
- if (Object.keys(prediction).includes("invoice_number")) {
49
- const invoice = new invoiceV3_1.InvoiceV3({
50
- prediction: prediction,
51
- inputSource: inputFile,
52
- pageId: pageNumber,
53
- orientation: orientation,
54
- extras: extras,
55
- });
56
- this.locale = invoice.locale;
57
- this.totalIncl = invoice.totalIncl;
58
- this.totalExcl = invoice.totalExcl;
59
- this.date = invoice.date;
60
- this.invoiceNumber = invoice.invoiceNumber;
61
- this.dueDate = invoice.dueDate;
62
- this.taxes = invoice.taxes;
63
- this.supplier = invoice.supplier;
64
- this.supplierAddress = invoice.supplierAddress;
65
- this.paymentDetails = invoice.paymentDetails;
66
- this.companyRegistration = invoice.customerCompanyRegistration;
67
- this.orientation = invoice.orientation;
68
- this.totalTax = invoice.totalTax;
69
- this.time = new fields_1.TextField({
70
- prediction: { value: undefined, confidence: 0.0 },
71
- });
72
- this.customerName = invoice.customerName;
73
- this.customerAddress = invoice.customerAddress;
74
- this.customerCompanyRegistration = invoice.customerCompanyRegistration;
75
- }
76
- else {
77
- const receipt = new receiptV3_1.ReceiptV3({
78
- prediction: prediction,
79
- inputSource: inputFile,
80
- pageId: pageNumber,
81
- orientation: orientation,
82
- extras: extras,
83
- });
84
- this.orientation = receipt.orientation;
85
- this.date = receipt.date;
86
- this.dueDate = receipt.date;
87
- this.taxes = receipt.taxes;
88
- this.locale = receipt.locale;
89
- this.totalIncl = receipt.totalIncl;
90
- this.totalExcl = receipt.totalExcl;
91
- this.supplier = receipt.merchantName;
92
- this.supplierAddress = new fields_1.TextField({
93
- prediction: { value: undefined, confidence: 0.0 },
94
- });
95
- this.time = receipt.time;
96
- this.totalTax = receipt.totalTax;
97
- this.invoiceNumber = new fields_1.TextField({
98
- prediction: { value: undefined, confidence: 0.0 },
99
- });
100
- this.customerName = new fields_1.TextField({
101
- prediction: { value: undefined, confidence: 0.0 },
102
- });
103
- this.customerAddress = new fields_1.TextField({
104
- prediction: { value: undefined, confidence: 0.0 },
105
- });
106
- }
107
- }, _FinancialDocumentV0_checklist = function _FinancialDocumentV0_checklist() {
108
- this.checklist = {
109
- taxesMatchTotalIncl: __classPrivateFieldGet(this, _FinancialDocumentV0_instances, "m", _FinancialDocumentV0_taxesMatchTotalIncl).call(this),
110
- };
111
- }, _FinancialDocumentV0_taxesMatchTotalIncl = function _FinancialDocumentV0_taxesMatchTotalIncl() {
112
- // Check taxes and total include exist
113
- if (this.taxes.length === 0 || this.totalIncl.value === undefined)
114
- return false;
115
- // Reconstruct totalIncl from taxes
116
- let totalVat = 0;
117
- let reconstructedTotal = 0;
118
- this.taxes.forEach((tax) => {
119
- if (tax.value === undefined || !tax.rate)
120
- return false;
121
- totalVat += tax.value;
122
- reconstructedTotal += tax.value + (100 * tax.value) / tax.rate;
123
- });
124
- // Sanity check
125
- if (totalVat <= 0)
126
- return false;
127
- // Crate epsilon
128
- const eps = 1 / (100 * totalVat);
129
- if (this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal &&
130
- reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02) {
131
- this.taxes = this.taxes.map((tax) => ({
132
- ...tax,
133
- confidence: 1.0,
134
- }));
135
- this.totalTax.confidence = 1.0;
136
- this.totalIncl.confidence = 1.0;
137
- return true;
138
- }
139
- return false;
140
- };
@@ -1,197 +0,0 @@
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 _FinancialDocumentV1_instances, _FinancialDocumentV1_lineItemsSeparator, _FinancialDocumentV1_lineItemsToString;
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.FinancialDocumentV1 = void 0;
10
- const document_1 = require("../document");
11
- const fields_1 = require("../../fields");
12
- const financialDocumentV1LineItem_1 = require("./financialDocumentV1LineItem");
13
- /**
14
- * Document data for Financial Document, API version 1.
15
- */
16
- class FinancialDocumentV1 extends document_1.Document {
17
- constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {
18
- super({
19
- inputSource: inputSource,
20
- pageId: pageId,
21
- orientation: orientation,
22
- extras: extras,
23
- fullText: fullText,
24
- });
25
- _FinancialDocumentV1_instances.add(this);
26
- /** List of Reference numbers, including PO number. */
27
- this.referenceNumbers = [];
28
- /** List of payment details associated to the supplier. */
29
- this.supplierPaymentDetails = [];
30
- /** List of company registrations associated to the supplier. */
31
- this.supplierCompanyRegistrations = [];
32
- /** List of company registrations associated to the customer. */
33
- this.customerCompanyRegistrations = [];
34
- /** List of line item details. */
35
- this.lineItems = [];
36
- this.locale = new fields_1.Locale({
37
- prediction: prediction["locale"],
38
- valueKey: "language",
39
- });
40
- this.invoiceNumber = new fields_1.TextField({
41
- prediction: prediction["invoice_number"],
42
- pageId: pageId,
43
- });
44
- prediction["reference_numbers"].map((itemPrediction) => this.referenceNumbers.push(new fields_1.TextField({
45
- prediction: itemPrediction,
46
- pageId: pageId,
47
- })));
48
- this.date = new fields_1.DateField({
49
- prediction: prediction["date"],
50
- pageId: pageId,
51
- });
52
- this.dueDate = new fields_1.DateField({
53
- prediction: prediction["due_date"],
54
- pageId: pageId,
55
- });
56
- this.totalNet = new fields_1.Amount({
57
- prediction: prediction["total_net"],
58
- pageId: pageId,
59
- });
60
- this.totalAmount = new fields_1.Amount({
61
- prediction: prediction["total_amount"],
62
- pageId: pageId,
63
- });
64
- this.taxes = new fields_1.Taxes().init(prediction["taxes"], pageId);
65
- prediction["supplier_payment_details"].map((itemPrediction) => this.supplierPaymentDetails.push(new fields_1.PaymentDetails({
66
- prediction: itemPrediction,
67
- pageId: pageId,
68
- })));
69
- this.supplierName = new fields_1.TextField({
70
- prediction: prediction["supplier_name"],
71
- pageId: pageId,
72
- });
73
- prediction["supplier_company_registrations"].map((itemPrediction) => this.supplierCompanyRegistrations.push(new fields_1.CompanyRegistration({
74
- prediction: itemPrediction,
75
- pageId: pageId,
76
- })));
77
- this.supplierAddress = new fields_1.TextField({
78
- prediction: prediction["supplier_address"],
79
- pageId: pageId,
80
- });
81
- this.supplierPhoneNumber = new fields_1.TextField({
82
- prediction: prediction["supplier_phone_number"],
83
- pageId: pageId,
84
- });
85
- this.customerName = new fields_1.TextField({
86
- prediction: prediction["customer_name"],
87
- pageId: pageId,
88
- });
89
- prediction["customer_company_registrations"].map((itemPrediction) => this.customerCompanyRegistrations.push(new fields_1.CompanyRegistration({
90
- prediction: itemPrediction,
91
- pageId: pageId,
92
- })));
93
- this.customerAddress = new fields_1.TextField({
94
- prediction: prediction["customer_address"],
95
- pageId: pageId,
96
- });
97
- this.documentType = new fields_1.ClassificationField({
98
- prediction: prediction["document_type"],
99
- });
100
- this.subcategory = new fields_1.ClassificationField({
101
- prediction: prediction["subcategory"],
102
- });
103
- this.category = new fields_1.ClassificationField({
104
- prediction: prediction["category"],
105
- });
106
- this.totalTax = new fields_1.Amount({
107
- prediction: prediction["total_tax"],
108
- pageId: pageId,
109
- });
110
- this.tip = new fields_1.Amount({
111
- prediction: prediction["tip"],
112
- pageId: pageId,
113
- });
114
- this.time = new fields_1.TextField({
115
- prediction: prediction["time"],
116
- pageId: pageId,
117
- });
118
- prediction["line_items"].map((itemPrediction) => this.lineItems.push(new financialDocumentV1LineItem_1.FinancialDocumentV1LineItem({
119
- prediction: itemPrediction,
120
- pageId: pageId,
121
- })));
122
- }
123
- toString() {
124
- const referenceNumbers = this.referenceNumbers
125
- .map((item) => item.toString())
126
- .join(", ");
127
- const supplierPaymentDetails = this.supplierPaymentDetails
128
- .map((item) => item.toString())
129
- .join("\n ");
130
- const customerCompanyRegistrations = this.customerCompanyRegistrations
131
- .map((item) => item.toString())
132
- .join("; ");
133
- const supplierCompanyRegistrations = this.supplierCompanyRegistrations
134
- .map((item) => item.toString())
135
- .join("; ");
136
- const outStr = `Financial Document V1 Prediction
137
- ================================
138
- :Filename: ${this.filename}
139
- :Locale: ${this.locale}
140
- :Invoice Number: ${this.invoiceNumber}
141
- :Reference Numbers: ${referenceNumbers}
142
- :Purchase Date: ${this.date}
143
- :Due Date: ${this.dueDate}
144
- :Total Net: ${this.totalNet}
145
- :Total Amount: ${this.totalAmount}
146
- :Taxes: ${this.taxes}
147
- :Supplier Payment Details: ${supplierPaymentDetails}
148
- :Supplier name: ${this.supplierName}
149
- :Supplier Company Registrations: ${customerCompanyRegistrations}
150
- :Supplier Address: ${this.supplierAddress}
151
- :Supplier Phone Number: ${this.supplierPhoneNumber}
152
- :Customer name: ${this.customerName}
153
- :Customer Company Registrations: ${supplierCompanyRegistrations}
154
- :Customer Address: ${this.customerAddress}
155
- :Document Type: ${this.documentType}
156
- :Purchase Subcategory: ${this.subcategory}
157
- :Purchase Category: ${this.category}
158
- :Total Tax: ${this.totalTax}
159
- :Tip and Gratuity: ${this.tip}
160
- :Purchase Time: ${this.time}
161
- :Line Items: ${__classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_lineItemsToString).call(this)}
162
- `;
163
- return FinancialDocumentV1.cleanOutString(outStr);
164
- }
165
- }
166
- exports.FinancialDocumentV1 = FinancialDocumentV1;
167
- _FinancialDocumentV1_instances = new WeakSet(), _FinancialDocumentV1_lineItemsSeparator = function _FinancialDocumentV1_lineItemsSeparator(char) {
168
- let outStr = " ";
169
- outStr += `+${char.repeat(38)}`;
170
- outStr += `+${char.repeat(14)}`;
171
- outStr += `+${char.repeat(10)}`;
172
- outStr += `+${char.repeat(12)}`;
173
- outStr += `+${char.repeat(14)}`;
174
- outStr += `+${char.repeat(14)}`;
175
- outStr += `+${char.repeat(12)}`;
176
- return outStr + "+";
177
- }, _FinancialDocumentV1_lineItemsToString = function _FinancialDocumentV1_lineItemsToString() {
178
- if (this.lineItems.length === 0) {
179
- return "";
180
- }
181
- const lines = this.lineItems
182
- .map((item) => item.toTableLine())
183
- .join(`\n${__classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_lineItemsSeparator).call(this, "-")}\n `);
184
- let outStr = "";
185
- outStr += `\n${__classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_lineItemsSeparator).call(this, "-")}\n `;
186
- outStr += " | Description ";
187
- outStr += " | Product code";
188
- outStr += " | Quantity";
189
- outStr += " | Tax Amount";
190
- outStr += " | Tax Rate (%)";
191
- outStr += " | Total Amount";
192
- outStr += " | Unit Price";
193
- outStr += ` |\n${__classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_lineItemsSeparator).call(this, "=")}`;
194
- outStr += `\n ${lines}`;
195
- outStr += `\n${__classPrivateFieldGet(this, _FinancialDocumentV1_instances, "m", _FinancialDocumentV1_lineItemsSeparator).call(this, "-")}`;
196
- return outStr;
197
- };
@@ -1,13 +0,0 @@
1
- import { Document, DocumentConstructorProps } from "../../document";
2
- import { TextField } from "../../../fields";
3
- /** French bank account information (RIB) */
4
- export declare class BankAccountDetailsV1 extends Document {
5
- /** The account's IBAN. */
6
- iban: TextField;
7
- /** The account holder's name. */
8
- accountHolderName: TextField;
9
- /** The bank's SWIFT code. */
10
- swift: TextField;
11
- constructor({ prediction, orientation, extras, inputSource, pageId, }: DocumentConstructorProps);
12
- toString(): string;
13
- }