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
package/src/client.d.ts CHANGED
@@ -1,68 +1,28 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { Readable } from "stream";
4
- import { InputSource, PageOptions } from "./inputs";
5
- import { Response, AsyncPredictResponse } from "./api";
6
- import { Document, DocumentSig } from "./documents";
7
- import { DocumentConfig } from "./documents/documentConfig";
8
- type DocConfigs = Map<string[], DocumentConfig<any>>;
4
+ import { InputSource, PageOptions } from "./input";
5
+ import { Endpoint } from "./http";
6
+ import { Inference, AsyncPredictResponse, StringDict, PredictResponse } from "./parsing/common";
9
7
  export interface PredictOptions {
10
- /**
11
- * For custom endpoints, the "API name" field in the "Settings" page of the API Builder.
12
- *
13
- * Do not set for standard (off the shelf) endpoints.
14
- */
15
8
  endpointName?: string;
16
- /**
17
- * For custom endpoints, your account or organization's username on the API Builder.
18
- * This is normally not required unless you have a custom endpoint which has the
19
- * same name as standard (off the shelf) endpoint.
20
- *
21
- * Do not set for standard (off the shelf) endpoints.
22
- */
23
9
  accountName?: string;
10
+ endpointVersion?: string;
11
+ endpoint?: Endpoint;
24
12
  /**
25
13
  * Whether to include the full text for each page.
26
14
  *
27
15
  * This performs a full OCR operation on the server and will increase response time.
28
16
  */
29
- fullText?: boolean;
17
+ allWords?: boolean;
30
18
  /**
31
19
  * Whether to include cropper results for each page.
32
20
  *
33
21
  * This performs a cropping operation on the server and will increase response time.
34
22
  */
35
23
  cropper?: boolean;
36
- /**
37
- * If set, remove pages from the document as specified.
38
- *
39
- * This is done before sending the file to the server and is useful to avoid page limitations.
40
- */
41
24
  pageOptions?: PageOptions;
42
25
  }
43
- export declare class DocumentClient {
44
- docConfigs: DocConfigs;
45
- inputSource?: InputSource;
46
- constructor(docConfigs: DocConfigs, inputSource?: InputSource);
47
- /**
48
- * Send a document to a synchronous endpoint and parse the predictions.
49
- * @param documentClass
50
- * @param params
51
- */
52
- parse<DocType extends Document>(documentClass: DocumentSig<DocType>, params?: PredictOptions): Promise<Response<DocType>>;
53
- /**
54
- * Send the document to an asynchronous endpoint and return its ID in the queue.
55
- * @param documentClass
56
- * @param params
57
- */
58
- enqueue<DocType extends Document>(documentClass: DocumentSig<DocType>, params?: PredictOptions): Promise<AsyncPredictResponse<DocType>>;
59
- parseQueued<DocType extends Document>(documentClass: DocumentSig<DocType>, queueId: string, params?: {
60
- endpointName?: string;
61
- accountName?: string;
62
- }): Promise<AsyncPredictResponse<DocType>>;
63
- protected getBooleanParam(param?: boolean): boolean;
64
- protected getDocConfig<DocType extends Document>(documentClass: DocumentSig<DocType>, endpointName?: string, accountName?: string): DocumentConfig<DocType>;
65
- }
66
26
  export interface CustomConfigParams {
67
27
  /** Your organization's username on the API Builder. */
68
28
  accountName: string;
@@ -86,57 +46,66 @@ export interface ClientOptions {
86
46
  * Mindee Client
87
47
  */
88
48
  export declare class Client {
89
- readonly docConfigs: DocConfigs;
49
+ #private;
90
50
  protected apiKey: string;
91
51
  /**
92
52
  * @param options
93
53
  */
94
- constructor({ apiKey, throwOnError, debug, }: ClientOptions);
95
- protected addStandardEndpoints(): void;
54
+ constructor({ apiKey, throwOnError, debug }?: ClientOptions);
96
55
  /**
97
- * Add a custom endpoint to the client.
98
- * @param accountName
99
- * @param endpointName
100
- * @param version
56
+ * Send a document to a synchronous endpoint and parse the predictions.
57
+ * @param productClass
58
+ * @param params
101
59
  */
102
- addEndpoint({ accountName, endpointName, version, }: CustomConfigParams): this;
60
+ parse<T extends Inference>(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, params?: PredictOptions): Promise<PredictResponse<T>>;
61
+ /**
62
+ * Send the document to an asynchronous endpoint and return its ID in the queue.
63
+ * @param productClass
64
+ * @param params
65
+ */
66
+ enqueue<T extends Inference>(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, params?: PredictOptions): Promise<AsyncPredictResponse<T>>;
67
+ parseQueued<T extends Inference>(productClass: new (httpResponse: StringDict) => T, queueId: string, params?: PredictOptions): Promise<AsyncPredictResponse<T>>;
68
+ protected getBooleanParam(param?: boolean): boolean;
69
+ /**
70
+ * Creates a custom endpoint with the given values. Raises an error if the endpoint is invalid.
71
+ * @param productClass Class of the product
72
+ * @param endpointName Name of a custom Endpoint
73
+ * @param accountName Name of the account tied to the active Endpoint
74
+ * @param version Version of a custom Endpoint
75
+ */
76
+ createEndpoint(endpointName: string, accountName: string, endpointVersion?: string): Endpoint;
103
77
  /**
104
78
  * Load an input document from a local path.
105
79
  * @param inputPath
106
80
  */
107
- docFromPath(inputPath: string): DocumentClient;
81
+ docFromPath(inputPath: string): InputSource;
108
82
  /**
109
83
  * Load an input document from a base64 encoded string.
110
84
  * @param inputString
111
85
  * @param filename
112
86
  */
113
- docFromBase64(inputString: string, filename: string): DocumentClient;
87
+ docFromBase64(inputString: string, filename: string): InputSource;
114
88
  /**
115
89
  * Load an input document from a `stream.Readable` object.
116
90
  * @param inputStream
117
91
  * @param filename
118
92
  */
119
- docFromStream(inputStream: Readable, filename: string): DocumentClient;
93
+ docFromStream(inputStream: Readable, filename: string): InputSource;
120
94
  /**
121
95
  * Load an input document from a bytes string.
122
96
  * @param inputBytes
123
97
  * @param filename
124
98
  */
125
- docFromBytes(inputBytes: string, filename: string): DocumentClient;
99
+ docFromBytes(inputBytes: string, filename: string): InputSource;
126
100
  /**
127
101
  * Load an input document from a URL.
128
102
  * @param url
129
103
  */
130
- docFromUrl(url: string): DocumentClient;
104
+ docFromUrl(url: string): InputSource;
131
105
  /**
132
106
  * Load an input document from a Buffer.
133
107
  * @param buffer
134
108
  * @param filename
135
109
  */
136
- docFromBuffer(buffer: Buffer, filename: string): DocumentClient;
137
- /**
138
- * Load an empty input document from an asynchronous call.
139
- */
140
- docForAsync(): DocumentClient;
110
+ docFromBuffer(buffer: Buffer, filename: string): InputSource;
141
111
  }
142
- export {};
package/src/client.js CHANGED
@@ -1,199 +1,119 @@
1
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 _Client_instances, _Client_buildEndpoint, _Client_initializeOTSEndpoint, _Client_cleanAccountName, _Client_getEndpoint;
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Client = exports.DocumentClient = void 0;
4
- const inputs_1 = require("./inputs");
5
- const api_1 = require("./api");
6
- const documents_1 = require("./documents");
7
- const documentConfig_1 = require("./documents/documentConfig");
9
+ exports.Client = void 0;
10
+ const input_1 = require("./input");
11
+ const http_1 = require("./http");
12
+ const common_1 = require("./parsing/common");
8
13
  const handler_1 = require("./errors/handler");
9
14
  const logger_1 = require("./logger");
10
- class DocumentClient {
11
- constructor(docConfigs, inputSource) {
12
- this.inputSource = inputSource;
13
- this.docConfigs = docConfigs;
15
+ const inference_1 = require("./parsing/common/inference");
16
+ const product_1 = require("./product");
17
+ /**
18
+ * Mindee Client
19
+ */
20
+ class Client {
21
+ /**
22
+ * @param options
23
+ */
24
+ constructor({ apiKey, throwOnError, debug } = {
25
+ apiKey: "",
26
+ throwOnError: true,
27
+ debug: false,
28
+ }) {
29
+ _Client_instances.add(this);
30
+ this.apiKey = apiKey ? apiKey : "";
31
+ handler_1.errorHandler.throwOnError = throwOnError ?? true;
32
+ logger_1.logger.level =
33
+ debug ?? process.env.MINDEE_DEBUG
34
+ ? logger_1.LOG_LEVELS["debug"]
35
+ : logger_1.LOG_LEVELS["warn"];
36
+ logger_1.logger.debug("Client initialized");
14
37
  }
15
38
  /**
16
39
  * Send a document to a synchronous endpoint and parse the predictions.
17
- * @param documentClass
40
+ * @param productClass
18
41
  * @param params
19
42
  */
20
- async parse(documentClass, params = {
21
- endpointName: "",
22
- accountName: "",
23
- fullText: false,
24
- cropper: false,
43
+ async parse(productClass, inputSource, params = {
44
+ endpoint: undefined,
45
+ allWords: undefined,
46
+ cropper: undefined,
25
47
  pageOptions: undefined,
26
48
  }) {
27
- const docConfig = this.getDocConfig(documentClass, params.endpointName, params.accountName);
28
- if (this.inputSource === undefined) {
49
+ const endpoint = params?.endpoint ?? __classPrivateFieldGet(this, _Client_instances, "m", _Client_initializeOTSEndpoint).call(this, productClass);
50
+ if (inputSource === undefined) {
29
51
  throw new Error("The 'parse' function requires an input document.");
30
52
  }
31
- return await docConfig.predict({
32
- inputDoc: this.inputSource,
33
- includeWords: this.getBooleanParam(params.fullText),
53
+ const rawPrediction = await endpoint.predict({
54
+ inputDoc: inputSource,
55
+ includeWords: this.getBooleanParam(params.allWords),
34
56
  pageOptions: params.pageOptions,
35
57
  cropper: this.getBooleanParam(params.cropper),
36
58
  });
59
+ return new common_1.PredictResponse(productClass, rawPrediction.data);
37
60
  }
38
61
  /**
39
62
  * Send the document to an asynchronous endpoint and return its ID in the queue.
40
- * @param documentClass
63
+ * @param productClass
41
64
  * @param params
42
65
  */
43
- async enqueue(documentClass, params = {
44
- endpointName: "",
45
- accountName: "",
46
- fullText: false,
47
- cropper: false,
48
- pageOptions: undefined,
49
- }) {
50
- const docConfig = this.getDocConfig(documentClass, params.endpointName, params.accountName);
51
- if (this.inputSource === undefined) {
52
- throw new Error("The 'enqueue' function requires an input document.");
66
+ async enqueue(productClass, inputSource, params = {}) {
67
+ const endpoint = params?.endpoint ?? __classPrivateFieldGet(this, _Client_instances, "m", _Client_initializeOTSEndpoint).call(this, productClass);
68
+ if (inputSource === undefined) {
69
+ throw new Error("The 'parse' function requires an input document.");
53
70
  }
54
- return await docConfig.predictAsync({
55
- inputDoc: this.inputSource,
56
- includeWords: this.getBooleanParam(params.fullText),
57
- pageOptions: params.pageOptions,
71
+ const rawResponse = await endpoint.predictAsync({
72
+ inputDoc: inputSource,
73
+ includeWords: this.getBooleanParam(params.allWords),
74
+ pageOptions: params?.pageOptions,
58
75
  cropper: this.getBooleanParam(params.cropper),
59
76
  });
77
+ return new common_1.AsyncPredictResponse(productClass, rawResponse.data);
60
78
  }
61
- async parseQueued(documentClass, queueId, params = {
62
- endpointName: "",
63
- accountName: "",
64
- }) {
65
- const docConfig = this.getDocConfig(documentClass, params.endpointName, params.accountName);
66
- return await docConfig.getQueuedDocument(queueId);
79
+ async parseQueued(productClass, queueId, params = {}) {
80
+ const endpoint = params?.endpoint ?? __classPrivateFieldGet(this, _Client_instances, "m", _Client_initializeOTSEndpoint).call(this, productClass);
81
+ const docResponse = await endpoint.getQueuedDocument(queueId);
82
+ return new common_1.AsyncPredictResponse(productClass, docResponse.data);
67
83
  }
68
84
  getBooleanParam(param) {
69
85
  return param !== undefined ? param : false;
70
86
  }
71
- getDocConfig(documentClass, endpointName, accountName) {
72
- const docType = endpointName === undefined || endpointName === ""
73
- ? documentClass.name
74
- : endpointName;
75
- const found = [];
76
- this.docConfigs.forEach((config, configKey) => {
77
- if (configKey[1] === docType) {
78
- found.push(configKey);
79
- }
80
- });
81
- if (found.length === 0) {
82
- throw `Document type not configured: '${docType}'`;
83
- }
84
- let configKey = [];
85
- if (found.length === 1) {
86
- configKey = found[0];
87
+ /**
88
+ * Creates a custom endpoint with the given values. Raises an error if the endpoint is invalid.
89
+ * @param productClass Class of the product
90
+ * @param endpointName Name of a custom Endpoint
91
+ * @param accountName Name of the account tied to the active Endpoint
92
+ * @param version Version of a custom Endpoint
93
+ */
94
+ createEndpoint(endpointName, accountName, endpointVersion) {
95
+ const cleanAccountName = __classPrivateFieldGet(this, _Client_instances, "m", _Client_cleanAccountName).call(this, product_1.CustomV1, accountName);
96
+ if (!endpointName || endpointName.length === 0) {
97
+ throw new Error("Missing parameter 'endpointName' for custom build!");
87
98
  }
88
- else if (accountName) {
89
- configKey = [accountName, docType];
99
+ let cleanEndpointVersion;
100
+ if (!endpointVersion || endpointVersion.length === 0) {
101
+ logger_1.logger.debug("Warning: No version provided for a custom build, will attempt to poll version 1 by default.");
102
+ cleanEndpointVersion = "1";
90
103
  }
91
- const docConfig = this.docConfigs.get(configKey);
92
- if (docConfig === undefined) {
93
- // TODO: raise error printing all usernames
94
- throw `Couldn't find the config '${configKey}'`;
104
+ else {
105
+ cleanEndpointVersion = endpointVersion;
95
106
  }
96
- return docConfig;
97
- }
98
- }
99
- exports.DocumentClient = DocumentClient;
100
- /**
101
- * Mindee Client
102
- */
103
- class Client {
104
- /**
105
- * @param options
106
- */
107
- constructor({ apiKey = "", throwOnError = true, debug = false, }) {
108
- this.docConfigs = new Map();
109
- this.apiKey = apiKey;
110
- handler_1.errorHandler.throwOnError = throwOnError;
111
- logger_1.logger.level =
112
- debug ?? process.env.MINDEE_DEBUG
113
- ? logger_1.LOG_LEVELS["debug"]
114
- : logger_1.LOG_LEVELS["warn"];
115
- logger_1.logger.debug("Client initialized");
116
- this.addStandardEndpoints();
117
- }
118
- // TODO: init only those endpoints we actually need.
119
- addStandardEndpoints() {
120
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.FinancialDocumentV0.name], new documentConfig_1.FinancialDocV0Config(this.apiKey));
121
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.FinancialDocumentV1.name], new documentConfig_1.DocumentConfig(documents_1.FinancialDocumentV1, [
122
- new api_1.StandardEndpoint("financial_document", "1", this.apiKey),
123
- ]));
124
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.InvoiceV3.name], new documentConfig_1.DocumentConfig(documents_1.InvoiceV3, [
125
- new api_1.StandardEndpoint("invoices", "3", this.apiKey),
126
- ]));
127
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.InvoiceV4.name], new documentConfig_1.DocumentConfig(documents_1.InvoiceV4, [
128
- new api_1.StandardEndpoint("invoices", "4", this.apiKey),
129
- ]));
130
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.InvoiceSplitterV1.name], new documentConfig_1.DocumentConfig(documents_1.InvoiceSplitterV1, [
131
- new api_1.StandardEndpoint("invoice_splitter", "1", this.apiKey),
132
- ]));
133
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ReceiptV3.name], new documentConfig_1.DocumentConfig(documents_1.ReceiptV3, [
134
- new api_1.StandardEndpoint("expense_receipts", "3", this.apiKey),
135
- ]));
136
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ReceiptV4.name], new documentConfig_1.DocumentConfig(documents_1.ReceiptV4, [
137
- new api_1.StandardEndpoint("expense_receipts", "4", this.apiKey),
138
- ]));
139
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ReceiptV5.name], new documentConfig_1.DocumentConfig(documents_1.ReceiptV5, [
140
- new api_1.StandardEndpoint("expense_receipts", "5", this.apiKey),
141
- ]));
142
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.PassportV1.name], new documentConfig_1.DocumentConfig(documents_1.PassportV1, [
143
- new api_1.StandardEndpoint("passport", "1", this.apiKey),
144
- ]));
145
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.CropperV1.name], new documentConfig_1.DocumentConfig(documents_1.CropperV1, [
146
- new api_1.StandardEndpoint("cropper", "1", this.apiKey),
147
- ]));
148
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.fr.IdCardV1.name], new documentConfig_1.DocumentConfig(documents_1.fr.IdCardV1, [
149
- new api_1.StandardEndpoint("idcard_fr", "1", this.apiKey),
150
- ]));
151
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.us.BankCheckV1.name], new documentConfig_1.DocumentConfig(documents_1.us.BankCheckV1, [
152
- new api_1.StandardEndpoint("bank_check", "1", this.apiKey),
153
- ]));
154
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.fr.BankAccountDetailsV1.name], new documentConfig_1.DocumentConfig(documents_1.fr.BankAccountDetailsV1, [
155
- new api_1.StandardEndpoint("bank_account_details", "1", this.apiKey),
156
- ]));
157
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.fr.BankAccountDetailsV2.name], new documentConfig_1.DocumentConfig(documents_1.fr.BankAccountDetailsV2, [
158
- new api_1.StandardEndpoint("bank_account_details", "2", this.apiKey),
159
- ]));
160
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.fr.CarteVitaleV1.name], new documentConfig_1.DocumentConfig(documents_1.fr.CarteVitaleV1, [
161
- new api_1.StandardEndpoint("carte_vitale", "1", this.apiKey),
162
- ]));
163
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.eu.LicensePlateV1.name], new documentConfig_1.DocumentConfig(documents_1.eu.LicensePlateV1, [
164
- new api_1.StandardEndpoint("license_plates", "1", this.apiKey),
165
- ]));
166
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.MindeeVisionV1.name], new documentConfig_1.DocumentConfig(documents_1.MindeeVisionV1, [
167
- new api_1.StandardEndpoint("mindee_vision", "1", this.apiKey),
168
- ]));
169
- this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ProofOfAddressV1.name], new documentConfig_1.DocumentConfig(documents_1.ProofOfAddressV1, [
170
- new api_1.StandardEndpoint("proof_of_address", "1", this.apiKey),
171
- ]));
172
- }
173
- /**
174
- * Add a custom endpoint to the client.
175
- * @param accountName
176
- * @param endpointName
177
- * @param version
178
- */
179
- addEndpoint({ accountName, endpointName, version = "1", }) {
180
- this.docConfigs.set([accountName, endpointName], new documentConfig_1.CustomDocConfig({
181
- accountName: accountName,
182
- endpointName: endpointName,
183
- version: version,
184
- apiKey: this.apiKey,
185
- }));
186
- return this;
107
+ return __classPrivateFieldGet(this, _Client_instances, "m", _Client_buildEndpoint).call(this, endpointName, cleanAccountName, cleanEndpointVersion);
187
108
  }
188
109
  /**
189
110
  * Load an input document from a local path.
190
111
  * @param inputPath
191
112
  */
192
113
  docFromPath(inputPath) {
193
- const doc = new inputs_1.PathInput({
114
+ return new input_1.PathInput({
194
115
  inputPath: inputPath,
195
116
  });
196
- return new DocumentClient(this.docConfigs, doc);
197
117
  }
198
118
  /**
199
119
  * Load an input document from a base64 encoded string.
@@ -201,11 +121,10 @@ class Client {
201
121
  * @param filename
202
122
  */
203
123
  docFromBase64(inputString, filename) {
204
- const doc = new inputs_1.Base64Input({
124
+ return new input_1.Base64Input({
205
125
  inputString: inputString,
206
126
  filename: filename,
207
127
  });
208
- return new DocumentClient(this.docConfigs, doc);
209
128
  }
210
129
  /**
211
130
  * Load an input document from a `stream.Readable` object.
@@ -213,11 +132,10 @@ class Client {
213
132
  * @param filename
214
133
  */
215
134
  docFromStream(inputStream, filename) {
216
- const doc = new inputs_1.StreamInput({
135
+ return new input_1.StreamInput({
217
136
  inputStream: inputStream,
218
137
  filename: filename,
219
138
  });
220
- return new DocumentClient(this.docConfigs, doc);
221
139
  }
222
140
  /**
223
141
  * Load an input document from a bytes string.
@@ -225,21 +143,19 @@ class Client {
225
143
  * @param filename
226
144
  */
227
145
  docFromBytes(inputBytes, filename) {
228
- const doc = new inputs_1.BytesInput({
146
+ return new input_1.BytesInput({
229
147
  inputBytes: inputBytes,
230
148
  filename: filename,
231
149
  });
232
- return new DocumentClient(this.docConfigs, doc);
233
150
  }
234
151
  /**
235
152
  * Load an input document from a URL.
236
153
  * @param url
237
154
  */
238
155
  docFromUrl(url) {
239
- const doc = new inputs_1.UrlInput({
156
+ return new input_1.UrlInput({
240
157
  url: url,
241
158
  });
242
- return new DocumentClient(this.docConfigs, doc);
243
159
  }
244
160
  /**
245
161
  * Load an input document from a Buffer.
@@ -247,17 +163,37 @@ class Client {
247
163
  * @param filename
248
164
  */
249
165
  docFromBuffer(buffer, filename) {
250
- const doc = new inputs_1.BufferInput({
166
+ return new input_1.BufferInput({
251
167
  buffer: buffer,
252
168
  filename: filename,
253
169
  });
254
- return new DocumentClient(this.docConfigs, doc);
255
- }
256
- /**
257
- * Load an empty input document from an asynchronous call.
258
- */
259
- docForAsync() {
260
- return new DocumentClient(this.docConfigs);
261
170
  }
262
171
  }
263
172
  exports.Client = Client;
173
+ _Client_instances = new WeakSet(), _Client_buildEndpoint = function _Client_buildEndpoint(endpointName, accountName, endpointVersion) {
174
+ const apiSettings = new http_1.MindeeApi({
175
+ apiKey: this.apiKey,
176
+ urlName: endpointName,
177
+ version: endpointVersion,
178
+ owner: accountName,
179
+ });
180
+ return new http_1.Endpoint(endpointName, accountName, endpointVersion, apiSettings);
181
+ }, _Client_initializeOTSEndpoint = function _Client_initializeOTSEndpoint(productClass) {
182
+ if (productClass.name === "CustomV1") {
183
+ throw new Error("Incorrect parameters for Custom build.");
184
+ }
185
+ const [endpointName, endpointVersion] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getEndpoint).call(this, productClass);
186
+ return __classPrivateFieldGet(this, _Client_instances, "m", _Client_buildEndpoint).call(this, endpointName, http_1.STANDARD_API_OWNER, endpointVersion);
187
+ }, _Client_cleanAccountName = function _Client_cleanAccountName(productClass, accountName) {
188
+ if (productClass.name === "CustomV1") {
189
+ if (!accountName || accountName.length === 0) {
190
+ logger_1.logger.debug(`Warning: no account name provided for custom build, ${http_1.STANDARD_API_OWNER} will be used by default`);
191
+ return http_1.STANDARD_API_OWNER;
192
+ }
193
+ return accountName;
194
+ }
195
+ return http_1.STANDARD_API_OWNER;
196
+ }, _Client_getEndpoint = function _Client_getEndpoint(productClass) {
197
+ const [endpointName, endpointVersion] = inference_1.InferenceFactory.getEndpoint(productClass);
198
+ return [endpointName, endpointVersion];
199
+ };
@@ -0,0 +1,5 @@
1
+ import { Point } from "./point";
2
+ /** A simple bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */
3
+ export type BBox = [number, number, number, number];
4
+ /** A bounding box defined by 4 points. */
5
+ export type BoundingBox = [Point, Point, Point, Point];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ import { BoundingBox, BBox } from "./boundingBox";
2
+ import { Polygon } from "./polygon";
3
+ /**
4
+ * Given a Polygon, calculate a polygon that encompasses all points.
5
+ */
6
+ export declare function getBoundingBox(polygon: Polygon): BoundingBox;
7
+ /**
8
+ * Given a BBox, generate the associated bounding box.
9
+ */
10
+ export declare function getBoundingBoxFromBBox(bbox: BBox): BoundingBox;
11
+ /**
12
+ * Given 2 bbox, merge them.
13
+ */
14
+ export declare function mergeBbox(bbox1: BBox, bbox2: BBox): BBox;
15
+ /**
16
+ * Given a Polygon, calculate a bounding box that encompasses all points.
17
+ */
18
+ export declare function getBbox(polygon: Polygon): BBox;
19
+ /**
20
+ * Given polygons, calculate a bounding box that encompasses all points.
21
+ */
22
+ export declare function getBBoxForPolygons(polygons: Polygon[]): BBox;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBBoxForPolygons = exports.getBbox = exports.mergeBbox = exports.getBoundingBoxFromBBox = exports.getBoundingBox = void 0;
4
+ /**
5
+ * Given a Polygon, calculate a polygon that encompasses all points.
6
+ */
7
+ function getBoundingBox(polygon) {
8
+ const bbox = getBbox(polygon);
9
+ return [
10
+ [bbox[0], bbox[1]],
11
+ [bbox[2], bbox[1]],
12
+ [bbox[2], bbox[3]],
13
+ [bbox[0], bbox[3]],
14
+ ];
15
+ }
16
+ exports.getBoundingBox = getBoundingBox;
17
+ /**
18
+ * Given a BBox, generate the associated bounding box.
19
+ */
20
+ function getBoundingBoxFromBBox(bbox) {
21
+ return [
22
+ [bbox[0], bbox[1]],
23
+ [bbox[2], bbox[1]],
24
+ [bbox[2], bbox[3]],
25
+ [bbox[0], bbox[3]],
26
+ ];
27
+ }
28
+ exports.getBoundingBoxFromBBox = getBoundingBoxFromBBox;
29
+ /**
30
+ * Given 2 bbox, merge them.
31
+ */
32
+ function mergeBbox(bbox1, bbox2) {
33
+ return [
34
+ Math.min(bbox1[0], bbox2[0]),
35
+ Math.min(bbox1[1], bbox2[1]),
36
+ Math.max(bbox1[2], bbox2[2]),
37
+ Math.max(bbox1[3], bbox2[3]),
38
+ ];
39
+ }
40
+ exports.mergeBbox = mergeBbox;
41
+ /**
42
+ * Given a Polygon, calculate a bounding box that encompasses all points.
43
+ */
44
+ function getBbox(polygon) {
45
+ const allY = polygon.map((point) => point[1]);
46
+ const allX = polygon.map((point) => point[0]);
47
+ const yMin = Math.min(...allY);
48
+ const yMax = Math.max(...allY);
49
+ const xMin = Math.min(...allX);
50
+ const xMax = Math.max(...allX);
51
+ return [xMin, yMin, xMax, yMax];
52
+ }
53
+ exports.getBbox = getBbox;
54
+ /**
55
+ * Given polygons, calculate a bounding box that encompasses all points.
56
+ */
57
+ function getBBoxForPolygons(polygons) {
58
+ const allY = polygons.flatMap((polygon) => polygon.map((point) => point[1]));
59
+ const allX = polygons.flatMap((polygon) => polygon.map((point) => point[0]));
60
+ const yMin = Math.min(...allY);
61
+ const yMax = Math.max(...allY);
62
+ const xMin = Math.min(...allX);
63
+ const xMax = Math.max(...allX);
64
+ return [xMin, yMin, xMax, yMax];
65
+ }
66
+ exports.getBBoxForPolygons = getBBoxForPolygons;
@@ -0,0 +1,6 @@
1
+ export { Polygon } from "./polygon";
2
+ export { compareOnX, compareOnY, getCentroid, isPointInPolygonX, isPointInPolygonY, relativeX, relativeY, getMinMaxX, getMinMaxY, } from "./polygonUtils";
3
+ export { BoundingBox, BBox } from "./boundingBox";
4
+ export { getBbox, getBBoxForPolygons, getBoundingBox, getBoundingBoxFromBBox, mergeBbox, } from "./boundingBoxUtils";
5
+ export { MinMax } from "./minMax";
6
+ export { Point } from "./point";
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeBbox = exports.getBoundingBoxFromBBox = exports.getBoundingBox = exports.getBBoxForPolygons = exports.getBbox = exports.getMinMaxY = exports.getMinMaxX = exports.relativeY = exports.relativeX = exports.isPointInPolygonY = exports.isPointInPolygonX = exports.getCentroid = exports.compareOnY = exports.compareOnX = exports.Polygon = void 0;
4
+ var polygon_1 = require("./polygon");
5
+ Object.defineProperty(exports, "Polygon", { enumerable: true, get: function () { return polygon_1.Polygon; } });
6
+ var polygonUtils_1 = require("./polygonUtils");
7
+ Object.defineProperty(exports, "compareOnX", { enumerable: true, get: function () { return polygonUtils_1.compareOnX; } });
8
+ Object.defineProperty(exports, "compareOnY", { enumerable: true, get: function () { return polygonUtils_1.compareOnY; } });
9
+ Object.defineProperty(exports, "getCentroid", { enumerable: true, get: function () { return polygonUtils_1.getCentroid; } });
10
+ Object.defineProperty(exports, "isPointInPolygonX", { enumerable: true, get: function () { return polygonUtils_1.isPointInPolygonX; } });
11
+ Object.defineProperty(exports, "isPointInPolygonY", { enumerable: true, get: function () { return polygonUtils_1.isPointInPolygonY; } });
12
+ Object.defineProperty(exports, "relativeX", { enumerable: true, get: function () { return polygonUtils_1.relativeX; } });
13
+ Object.defineProperty(exports, "relativeY", { enumerable: true, get: function () { return polygonUtils_1.relativeY; } });
14
+ Object.defineProperty(exports, "getMinMaxX", { enumerable: true, get: function () { return polygonUtils_1.getMinMaxX; } });
15
+ Object.defineProperty(exports, "getMinMaxY", { enumerable: true, get: function () { return polygonUtils_1.getMinMaxY; } });
16
+ var boundingBoxUtils_1 = require("./boundingBoxUtils");
17
+ Object.defineProperty(exports, "getBbox", { enumerable: true, get: function () { return boundingBoxUtils_1.getBbox; } });
18
+ Object.defineProperty(exports, "getBBoxForPolygons", { enumerable: true, get: function () { return boundingBoxUtils_1.getBBoxForPolygons; } });
19
+ Object.defineProperty(exports, "getBoundingBox", { enumerable: true, get: function () { return boundingBoxUtils_1.getBoundingBox; } });
20
+ Object.defineProperty(exports, "getBoundingBoxFromBBox", { enumerable: true, get: function () { return boundingBoxUtils_1.getBoundingBoxFromBBox; } });
21
+ Object.defineProperty(exports, "mergeBbox", { enumerable: true, get: function () { return boundingBoxUtils_1.mergeBbox; } });