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
@@ -1,25 +0,0 @@
1
- import { Document, DocumentSig } from "../documents";
2
- import { FullText } from "../fields";
3
- import { InputSource } from "../inputs";
4
- export interface ResponseProps {
5
- httpResponse: any;
6
- documentType?: string;
7
- input?: InputSource;
8
- error: boolean;
9
- }
10
- export type ResponseSig<DocType extends Document> = {
11
- new (documentClass: DocumentSig<DocType>, params: ResponseProps): Response<DocType>;
12
- };
13
- /**
14
- * Base class for all responses.
15
- */
16
- export declare class Response<DocType extends Document> {
17
- httpResponse: any;
18
- inputFile?: InputSource;
19
- document?: DocType;
20
- pages: Array<DocType>;
21
- readonly documentClass: DocumentSig<DocType>;
22
- constructor(documentClass: DocumentSig<DocType>, params: ResponseProps);
23
- protected formatResponse(documentType?: string): void;
24
- protected getPageText(httpDataDocument: any, pageId: number): FullText;
25
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Response = void 0;
4
- const fields_1 = require("../fields");
5
- /**
6
- * Base class for all responses.
7
- */
8
- class Response {
9
- constructor(documentClass, params) {
10
- this.pages = [];
11
- this.documentClass = documentClass;
12
- this.httpResponse = params.httpResponse;
13
- this.inputFile = params.input;
14
- if (!params.error) {
15
- this.formatResponse(params.documentType);
16
- }
17
- }
18
- formatResponse(documentType) {
19
- const httpDataDocument = this.httpResponse.data.document;
20
- httpDataDocument.inference.pages.forEach((apiPage) => {
21
- const pageText = this.getPageText(httpDataDocument, apiPage.id);
22
- this.pages.push(new this.documentClass({
23
- documentType: documentType,
24
- prediction: apiPage.prediction,
25
- inputSource: this.inputFile,
26
- pageId: apiPage.id,
27
- orientation: apiPage.orientation,
28
- extras: apiPage.extras,
29
- fullText: pageText,
30
- }));
31
- });
32
- this.document = new this.documentClass({
33
- documentType: documentType,
34
- prediction: httpDataDocument.inference.prediction,
35
- inputSource: this.inputFile,
36
- orientation: {},
37
- extras: {},
38
- });
39
- }
40
- getPageText(httpDataDocument, pageId) {
41
- const pageText = new fields_1.FullText();
42
- if ("ocr" in httpDataDocument &&
43
- Object.keys(httpDataDocument.ocr).length > 0) {
44
- pageText.words =
45
- httpDataDocument.ocr["mvision-v1"].pages[pageId].all_words;
46
- }
47
- return pageText;
48
- }
49
- }
50
- exports.Response = Response;
@@ -1,63 +0,0 @@
1
- /// <reference types="node" />
2
- import { InputSource } from "../inputs";
3
- import { IncomingMessage, RequestOptions, ClientRequest } from "http";
4
- export declare const STANDARD_API_OWNER = "mindee";
5
- export declare const API_KEY_ENVVAR_NAME = "MINDEE_API_KEY";
6
- export declare const API_HOST_ENVVAR_NAME = "MINDEE_API_HOST";
7
- export interface EndpointResponse {
8
- messageObj: IncomingMessage;
9
- data: {
10
- [key: string]: any;
11
- };
12
- }
13
- export declare class Endpoint {
14
- apiKey: string;
15
- urlName: string;
16
- owner: string;
17
- version: string;
18
- hostname: string;
19
- urlRoot: string;
20
- private readonly baseHeaders;
21
- constructor(owner: string, urlName: string, version: string, apiKey: string);
22
- /**
23
- * Make a request to POST a document for prediction.
24
- * @param input
25
- * @param includeWords
26
- * @param cropper
27
- */
28
- predictReqPost(input: InputSource, includeWords?: boolean, cropper?: boolean): Promise<EndpointResponse>;
29
- /**
30
- * Make a request to POST a document for async prediction.
31
- * @param input
32
- * @param includeWords
33
- * @param cropper
34
- */
35
- predictAsyncReqPost(input: InputSource, includeWords?: boolean, cropper?: boolean): Promise<EndpointResponse>;
36
- /**
37
- * Make a request to GET the status of a document in the queue.
38
- * @param queueId
39
- */
40
- documentQueueReqGet(queueId: string): Promise<EndpointResponse>;
41
- /**
42
- * Make a request to GET a document.
43
- * @param documentId
44
- */
45
- documentGetReq(documentId: string): Promise<EndpointResponse>;
46
- /**
47
- * Send a file to a prediction API.
48
- * @param input
49
- * @param predictUrl
50
- * @param includeWords
51
- * @param cropper
52
- */
53
- protected sendFileForPrediction(input: InputSource, predictUrl: string, includeWords?: boolean, cropper?: boolean): Promise<EndpointResponse>;
54
- protected readResponse(options: RequestOptions, resolve: (value: EndpointResponse | PromiseLike<EndpointResponse>) => void, reject: (reason?: any) => void): ClientRequest;
55
- protected apiKeyFromEnv(): string;
56
- protected hostnameFromEnv(): string;
57
- }
58
- export declare class StandardEndpoint extends Endpoint {
59
- constructor(endpointName: string, version: string, apiKey: string);
60
- }
61
- export declare class CustomEndpoint extends Endpoint {
62
- constructor(endpointName: string, accountName: string, version: string, apiKey: string);
63
- }
@@ -1,216 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.CustomEndpoint = exports.StandardEndpoint = exports.Endpoint = exports.API_HOST_ENVVAR_NAME = exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = void 0;
30
- const https = __importStar(require("https"));
31
- const os = __importStar(require("os"));
32
- const package_json_1 = require("../../package.json");
33
- const url_1 = require("url");
34
- const form_data_1 = __importDefault(require("form-data"));
35
- const logger_1 = require("../logger");
36
- const DEFAULT_MINDEE_API_HOST = "api.mindee.net";
37
- const USER_AGENT = `mindee-api-nodejs@v${package_json_1.version} nodejs-${process.version} ${os.type().toLowerCase()}`;
38
- exports.STANDARD_API_OWNER = "mindee";
39
- exports.API_KEY_ENVVAR_NAME = "MINDEE_API_KEY";
40
- exports.API_HOST_ENVVAR_NAME = "MINDEE_API_HOST";
41
- class Endpoint {
42
- constructor(owner, urlName, version, apiKey) {
43
- this.owner = owner;
44
- this.urlName = urlName;
45
- this.version = version;
46
- this.apiKey = apiKey || this.apiKeyFromEnv();
47
- this.hostname = this.hostnameFromEnv();
48
- this.urlRoot = `/v1/products/${owner}/${urlName}/v${version}`;
49
- this.baseHeaders = {
50
- "User-Agent": USER_AGENT,
51
- Authorization: `Token ${this.apiKey}`,
52
- };
53
- }
54
- /**
55
- * Make a request to POST a document for prediction.
56
- * @param input
57
- * @param includeWords
58
- * @param cropper
59
- */
60
- predictReqPost(input, includeWords = false, cropper = false) {
61
- return this.sendFileForPrediction(input, "predict", includeWords, cropper);
62
- }
63
- /**
64
- * Make a request to POST a document for async prediction.
65
- * @param input
66
- * @param includeWords
67
- * @param cropper
68
- */
69
- predictAsyncReqPost(input, includeWords = false, cropper = false) {
70
- return this.sendFileForPrediction(input, "predict_async", includeWords, cropper);
71
- }
72
- /**
73
- * Make a request to GET the status of a document in the queue.
74
- * @param queueId
75
- */
76
- documentQueueReqGet(queueId) {
77
- return new Promise((resolve, reject) => {
78
- const options = {
79
- method: "GET",
80
- headers: this.baseHeaders,
81
- hostname: this.hostname,
82
- path: `${this.urlRoot}/documents/queue/${queueId}`,
83
- };
84
- const req = this.readResponse(options, resolve, reject);
85
- // potential ECONNRESET if we don't end the request.
86
- req.end();
87
- });
88
- }
89
- /**
90
- * Make a request to GET a document.
91
- * @param documentId
92
- */
93
- documentGetReq(documentId) {
94
- return new Promise((resolve, reject) => {
95
- const options = {
96
- method: "GET",
97
- headers: this.baseHeaders,
98
- hostname: this.hostname,
99
- path: `${this.urlRoot}/documents/${documentId}`,
100
- };
101
- const req = this.readResponse(options, resolve, reject);
102
- // potential ECONNRESET if we don't end the request.
103
- req.end();
104
- });
105
- }
106
- /**
107
- * Send a file to a prediction API.
108
- * @param input
109
- * @param predictUrl
110
- * @param includeWords
111
- * @param cropper
112
- */
113
- sendFileForPrediction(input, predictUrl, includeWords = false, cropper = false) {
114
- return new Promise((resolve, reject) => {
115
- const searchParams = new url_1.URLSearchParams();
116
- if (cropper) {
117
- searchParams.append("cropper", "true");
118
- }
119
- const form = new form_data_1.default();
120
- if (input.fileObject instanceof Buffer) {
121
- form.append("document", input.fileObject, { filename: input.filename });
122
- }
123
- else {
124
- form.append("document", input.fileObject);
125
- }
126
- if (includeWords) {
127
- form.append("include_mvision", "true");
128
- }
129
- const headers = { ...this.baseHeaders, ...form.getHeaders() };
130
- let path = `${this.urlRoot}/${predictUrl}`;
131
- if (searchParams.keys.length > 0) {
132
- path += `?${searchParams}`;
133
- }
134
- const options = {
135
- method: "POST",
136
- headers: headers,
137
- hostname: this.hostname,
138
- path: path,
139
- };
140
- const req = this.readResponse(options, resolve, reject);
141
- form.pipe(req);
142
- // potential ECONNRESET if we don't end the request.
143
- req.end();
144
- });
145
- }
146
- readResponse(options, resolve, reject) {
147
- logger_1.logger.debug(`${options.method}: https://${options.hostname}${options.path}`);
148
- const req = https.request(options, function (res) {
149
- // when the encoding is set, data chunks will be strings
150
- res.setEncoding("utf-8");
151
- let responseBody = "";
152
- res.on("data", function (chunk) {
153
- logger_1.logger.debug("Receiving data ...");
154
- responseBody += chunk;
155
- });
156
- res.on("end", function () {
157
- logger_1.logger.debug("Parsing the response ...");
158
- // handle empty responses from server, for example in the case of redirects
159
- if (!responseBody) {
160
- responseBody = "{}";
161
- }
162
- try {
163
- const parsedResponse = JSON.parse(responseBody);
164
- try {
165
- resolve({
166
- messageObj: res,
167
- data: parsedResponse,
168
- });
169
- }
170
- catch (error) {
171
- logger_1.logger.error("Could not construct the return object.");
172
- reject(error);
173
- }
174
- }
175
- catch (error) {
176
- logger_1.logger.error("Could not parse the return as JSON.");
177
- logger_1.logger.debug(responseBody);
178
- reject(error);
179
- }
180
- });
181
- });
182
- req.on("error", (err) => {
183
- reject(err);
184
- });
185
- return req;
186
- }
187
- apiKeyFromEnv() {
188
- const envVarValue = process.env[exports.API_KEY_ENVVAR_NAME];
189
- if (envVarValue) {
190
- logger_1.logger.debug(`Set ${this.urlName} v${this.version} API key from environment: ${exports.API_KEY_ENVVAR_NAME}`);
191
- return envVarValue;
192
- }
193
- return "";
194
- }
195
- hostnameFromEnv() {
196
- const envVarValue = process.env[exports.API_HOST_ENVVAR_NAME];
197
- if (envVarValue) {
198
- logger_1.logger.debug(`Set the API hostname to ${envVarValue}`);
199
- return envVarValue;
200
- }
201
- return DEFAULT_MINDEE_API_HOST;
202
- }
203
- }
204
- exports.Endpoint = Endpoint;
205
- class StandardEndpoint extends Endpoint {
206
- constructor(endpointName, version, apiKey) {
207
- super(exports.STANDARD_API_OWNER, endpointName, version, apiKey);
208
- }
209
- }
210
- exports.StandardEndpoint = StandardEndpoint;
211
- class CustomEndpoint extends Endpoint {
212
- constructor(endpointName, accountName, version, apiKey) {
213
- super(accountName, endpointName, version, apiKey);
214
- }
215
- }
216
- exports.CustomEndpoint = CustomEndpoint;
@@ -1,3 +0,0 @@
1
- export { Response, ResponseSig } from "./documentResponse";
2
- export { Endpoint, CustomEndpoint, StandardEndpoint, EndpointResponse, STANDARD_API_OWNER, API_KEY_ENVVAR_NAME, } from "./endpoint";
3
- export { AsyncPredictResponse } from "./predictResponse";
package/src/api/index.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AsyncPredictResponse = exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = exports.StandardEndpoint = exports.CustomEndpoint = exports.Endpoint = exports.Response = void 0;
4
- var documentResponse_1 = require("./documentResponse");
5
- Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return documentResponse_1.Response; } });
6
- var endpoint_1 = require("./endpoint");
7
- Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return endpoint_1.Endpoint; } });
8
- Object.defineProperty(exports, "CustomEndpoint", { enumerable: true, get: function () { return endpoint_1.CustomEndpoint; } });
9
- Object.defineProperty(exports, "StandardEndpoint", { enumerable: true, get: function () { return endpoint_1.StandardEndpoint; } });
10
- Object.defineProperty(exports, "STANDARD_API_OWNER", { enumerable: true, get: function () { return endpoint_1.STANDARD_API_OWNER; } });
11
- Object.defineProperty(exports, "API_KEY_ENVVAR_NAME", { enumerable: true, get: function () { return endpoint_1.API_KEY_ENVVAR_NAME; } });
12
- var predictResponse_1 = require("./predictResponse");
13
- Object.defineProperty(exports, "AsyncPredictResponse", { enumerable: true, get: function () { return predictResponse_1.AsyncPredictResponse; } });
@@ -1,33 +0,0 @@
1
- import { StringDict } from "../fields";
2
- import { Document } from "../documents";
3
- import { Response } from "./documentResponse";
4
- export declare class Job {
5
- issuedAt: Date;
6
- availableAt?: Date;
7
- id?: string;
8
- status?: "waiting" | "processing" | "completed";
9
- /**
10
- * The time taken to process the job, in milliseconds.
11
- */
12
- milliSecsTaken?: number;
13
- constructor(jsonResponse: StringDict);
14
- protected datetimeWithTimezone(date: string): Date;
15
- }
16
- export declare class ApiRequest {
17
- error: StringDict;
18
- resources: string[];
19
- status: "failure" | "success";
20
- /** HTTP status code */
21
- statusCode: number;
22
- url: string;
23
- constructor(serverResponse: StringDict);
24
- }
25
- export declare class BasePredictResponse {
26
- apiRequest: ApiRequest;
27
- constructor(serverResponse: StringDict);
28
- }
29
- export declare class AsyncPredictResponse<DocType extends Document> extends BasePredictResponse {
30
- job: Job;
31
- document?: Response<DocType>;
32
- constructor(serverResponse: StringDict, document?: Response<DocType>);
33
- }
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AsyncPredictResponse = exports.BasePredictResponse = exports.ApiRequest = exports.Job = void 0;
4
- class Job {
5
- constructor(jsonResponse) {
6
- this.issuedAt = this.datetimeWithTimezone(jsonResponse["issued_at"]);
7
- if (jsonResponse["available_at"] !== undefined &&
8
- jsonResponse["available_at"] !== null) {
9
- this.availableAt = this.datetimeWithTimezone(jsonResponse["available_at"]);
10
- }
11
- this.id = jsonResponse["id"];
12
- this.status = jsonResponse["status"];
13
- if (this.availableAt !== undefined) {
14
- this.milliSecsTaken =
15
- this.availableAt.getTime() - this.issuedAt.getTime();
16
- }
17
- }
18
- // Hideous thing to make sure dates sent back by the server are parsed correctly in UTC.
19
- datetimeWithTimezone(date) {
20
- if (date.search(/\+[0-9]{2}:[0-9]{2}$/) === -1) {
21
- date += "+00:00";
22
- }
23
- return new Date(date);
24
- }
25
- }
26
- exports.Job = Job;
27
- class ApiRequest {
28
- constructor(serverResponse) {
29
- this.error = serverResponse["error"];
30
- this.resources = serverResponse["resources"];
31
- this.status = serverResponse["status"];
32
- this.statusCode = serverResponse["status_code"];
33
- this.url = serverResponse["url"];
34
- }
35
- }
36
- exports.ApiRequest = ApiRequest;
37
- // For upcoming v4, use this as the base for all responses.
38
- // To not break compatibility, in v3.x, we will only use it as the base for async responses.
39
- class BasePredictResponse {
40
- constructor(serverResponse) {
41
- this.apiRequest = new ApiRequest(serverResponse["api_request"]);
42
- }
43
- }
44
- exports.BasePredictResponse = BasePredictResponse;
45
- class AsyncPredictResponse extends BasePredictResponse {
46
- constructor(serverResponse, document) {
47
- super(serverResponse);
48
- this.job = new Job(serverResponse["job"]);
49
- this.document = document;
50
- }
51
- }
52
- exports.AsyncPredictResponse = AsyncPredictResponse;
@@ -1,7 +0,0 @@
1
- import { Document, DocumentConstructorProps } from "../document";
2
- import { PositionField } from "../../fields";
3
- export declare class CropperV1 extends Document {
4
- cropping: PositionField[];
5
- constructor({ prediction, orientation, inputSource, pageId, }: DocumentConstructorProps);
6
- toString(): string;
7
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CropperV1 = void 0;
4
- const document_1 = require("../document");
5
- const fields_1 = require("../../fields");
6
- class CropperV1 extends document_1.Document {
7
- constructor({ prediction, orientation = undefined, inputSource = undefined, pageId = undefined, }) {
8
- super({
9
- inputSource: inputSource,
10
- pageId: pageId,
11
- orientation: orientation,
12
- });
13
- this.cropping = [];
14
- if (pageId !== undefined) {
15
- prediction.cropping.forEach((crop) => {
16
- this.cropping.push(new fields_1.PositionField({
17
- prediction: crop,
18
- pageId: pageId,
19
- }));
20
- });
21
- }
22
- }
23
- toString() {
24
- const cropping = this.cropping
25
- .map((crop) => crop.toString())
26
- .join("\n ");
27
- const outStr = `----- Cropper Data -----
28
- Filename: ${this.filename}
29
- Cropping: ${cropping}
30
- ------------------------
31
- `;
32
- return CropperV1.cleanOutString(outStr);
33
- }
34
- }
35
- exports.CropperV1 = CropperV1;
@@ -1,10 +0,0 @@
1
- import { Document, DocumentConstructorProps } from "../document";
2
- import { ClassificationField, ListField } from "./fields";
3
- import { StringDict } from "../../fields";
4
- export declare class CustomV1 extends Document {
5
- fields: Map<string, ListField>;
6
- classifications: Map<string, ClassificationField>;
7
- constructor({ inputSource, prediction, extras, orientation, pageId, documentType, }: DocumentConstructorProps);
8
- protected setField(fieldName: string, apiPrediction: StringDict, pageId: number | undefined): void;
9
- toString(): string;
10
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CustomV1 = void 0;
4
- const document_1 = require("../document");
5
- const fields_1 = require("./fields");
6
- class CustomV1 extends document_1.Document {
7
- constructor({ inputSource, prediction, extras = undefined, orientation = undefined, pageId, documentType, }) {
8
- super({
9
- inputSource: inputSource,
10
- pageId: pageId,
11
- orientation: orientation,
12
- extras: extras,
13
- documentType: documentType,
14
- });
15
- this.fields = new Map();
16
- this.classifications = new Map();
17
- Object.keys(prediction).forEach((fieldName) => {
18
- this.setField(fieldName, prediction, pageId);
19
- });
20
- }
21
- setField(fieldName, apiPrediction, pageId) {
22
- // Currently, two types of fields possible in a custom API response:
23
- // fields having a list of values, and classification fields.
24
- const fieldPrediction = apiPrediction[fieldName];
25
- if (fieldPrediction["values"] !== undefined) {
26
- // Only value lists have the 'values' attribute.
27
- this.fields.set(fieldName, new fields_1.ListField({
28
- prediction: fieldPrediction,
29
- pageId: pageId,
30
- }));
31
- }
32
- else if (fieldPrediction["value"] !== undefined) {
33
- // Only classifications have the 'value' attribute.
34
- this.classifications.set(fieldName, new fields_1.ClassificationField({ prediction: fieldPrediction }));
35
- }
36
- else {
37
- throw "Unknown API field type";
38
- }
39
- }
40
- toString() {
41
- let outStr = `----- ${this.docType} -----`;
42
- outStr += `\nFilename: ${this.filename}`.trimEnd();
43
- this.classifications.forEach((fieldData, name) => {
44
- outStr += `\n${name}: ${fieldData}`.trimEnd();
45
- });
46
- this.fields.forEach((fieldData, name) => {
47
- outStr += `\n${name}: ${fieldData}`.trimEnd();
48
- });
49
- outStr += "\n----------------------\n";
50
- return outStr;
51
- }
52
- }
53
- exports.CustomV1 = CustomV1;
@@ -1,47 +0,0 @@
1
- import { InputSource } from "../inputs";
2
- import { PositionField, FullText, OrientationField, StringDict } from "../fields";
3
- export type DocumentSig<DocType extends Document> = {
4
- new ({ prediction, orientation, extras, pageId, fullText, documentType, inputSource, }: DocumentConstructorProps): DocType;
5
- };
6
- export interface DocumentConstructorProps extends BaseDocumentConstructorProps {
7
- /** JSON parsed prediction from HTTP response */
8
- prediction: StringDict;
9
- }
10
- interface BaseDocumentConstructorProps {
11
- /** Orientation JSON for page-level document */
12
- orientation?: StringDict;
13
- /** Extras JSON */
14
- extras?: StringDict;
15
- /** input file given to parse the document */
16
- inputSource?: InputSource;
17
- /** Page ID for page-level document */
18
- pageId?: number;
19
- /** full OCR extracted text */
20
- fullText?: FullText;
21
- documentType?: string;
22
- }
23
- export declare class Document {
24
- checklist: {
25
- [index: string]: boolean;
26
- };
27
- mimeType?: string;
28
- filename: string;
29
- filepath?: string;
30
- fullText?: FullText;
31
- pageId?: number | undefined;
32
- orientation?: OrientationField;
33
- cropper: PositionField[];
34
- readonly docType: string;
35
- constructor({ orientation, extras, inputSource, fullText, pageId, documentType, }: BaseDocumentConstructorProps);
36
- clone(): any;
37
- /** return true if all checklist of the document if true */
38
- checkAll(): boolean;
39
- /**
40
- * Takes a list of Documents and return one Document where
41
- * each field is set with the maximum probability field
42
- * @param {Array<Document>} documents - A list of Documents
43
- */
44
- static mergePages(documents: any): any;
45
- static cleanOutString(outStr: string): string;
46
- }
47
- export {};