mindee 4.0.0 → 4.0.2

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 (124) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/package.json +3 -4
  3. package/src/client.d.ts +58 -32
  4. package/src/client.js +50 -19
  5. package/src/http/endpoint.js +9 -11
  6. package/src/index.d.ts +1 -1
  7. package/src/input/base.d.ts +1 -0
  8. package/src/input/base.js +3 -0
  9. package/src/input/pageOptions.d.ts +4 -0
  10. package/src/input/pageOptions.js +3 -0
  11. package/src/input/sources.d.ts +2 -3
  12. package/src/input/sources.js +2 -1
  13. package/src/parsing/common/apiRequest.d.ts +9 -0
  14. package/src/parsing/common/apiRequest.js +5 -0
  15. package/src/parsing/common/apiResponse.d.ts +9 -0
  16. package/src/parsing/common/apiResponse.js +8 -0
  17. package/src/parsing/common/asyncPredictResponse.d.ts +24 -3
  18. package/src/parsing/common/asyncPredictResponse.js +15 -0
  19. package/src/parsing/common/document.d.ts +17 -0
  20. package/src/parsing/common/document.js +16 -4
  21. package/src/parsing/common/extras/cropperExtra.d.ts +3 -0
  22. package/src/parsing/common/extras/cropperExtra.js +3 -0
  23. package/src/parsing/common/extras/extras.d.ts +3 -0
  24. package/src/parsing/common/extras/extras.js +3 -0
  25. package/src/parsing/common/inference.d.ts +26 -0
  26. package/src/parsing/common/inference.js +23 -2
  27. package/src/parsing/common/mvisionV1.d.ts +3 -0
  28. package/src/parsing/common/mvisionV1.js +3 -0
  29. package/src/parsing/common/ocr.d.ts +3 -0
  30. package/src/parsing/common/ocr.js +3 -0
  31. package/src/parsing/common/ocrPage.d.ts +3 -0
  32. package/src/parsing/common/ocrPage.js +3 -0
  33. package/src/parsing/common/orientation.d.ts +3 -0
  34. package/src/parsing/common/orientation.js +3 -0
  35. package/src/parsing/common/page.d.ts +19 -0
  36. package/src/parsing/common/page.js +15 -0
  37. package/src/parsing/common/predictResponse.d.ts +11 -0
  38. package/src/parsing/common/predictResponse.js +10 -0
  39. package/src/parsing/custom/classificationField.d.ts +3 -0
  40. package/src/parsing/custom/classificationField.js +3 -0
  41. package/src/parsing/custom/listField.d.ts +6 -0
  42. package/src/parsing/custom/listField.js +6 -0
  43. package/src/parsing/standard/amount.d.ts +3 -0
  44. package/src/parsing/standard/amount.js +3 -0
  45. package/src/parsing/standard/base.d.ts +3 -0
  46. package/src/parsing/standard/base.js +3 -0
  47. package/src/parsing/standard/locale.d.ts +3 -0
  48. package/src/parsing/standard/locale.js +3 -0
  49. package/src/parsing/standard/paymentDetails.d.ts +3 -0
  50. package/src/parsing/standard/paymentDetails.js +3 -0
  51. package/src/parsing/standard/position.d.ts +3 -0
  52. package/src/parsing/standard/position.js +3 -0
  53. package/src/parsing/standard/tax.d.ts +3 -0
  54. package/src/parsing/standard/tax.js +3 -0
  55. package/src/product/cropper/cropperV1.d.ts +7 -0
  56. package/src/product/cropper/cropperV1.js +6 -0
  57. package/src/product/cropper/cropperV1Document.d.ts +6 -0
  58. package/src/product/cropper/cropperV1Document.js +6 -0
  59. package/src/product/custom/customV1.d.ts +7 -0
  60. package/src/product/custom/customV1.js +6 -0
  61. package/src/product/custom/customV1Document.d.ts +16 -0
  62. package/src/product/custom/customV1Document.js +16 -2
  63. package/src/product/custom/customV1Page.d.ts +7 -0
  64. package/src/product/custom/customV1Page.js +7 -0
  65. package/src/product/eu/licensePlate/licensePlateV1.d.ts +7 -0
  66. package/src/product/eu/licensePlate/licensePlateV1.js +6 -0
  67. package/src/product/eu/licensePlate/licensePlateV1Document.d.ts +3 -0
  68. package/src/product/eu/licensePlate/licensePlateV1Document.js +3 -0
  69. package/src/product/financialDocument/financialDocumentV1.d.ts +7 -0
  70. package/src/product/financialDocument/financialDocumentV1.js +6 -0
  71. package/src/product/financialDocument/financialDocumentV1Document.d.ts +3 -0
  72. package/src/product/financialDocument/financialDocumentV1Document.js +3 -0
  73. package/src/product/fr/bankAccountDetails/bankAccountDetailsV1.d.ts +7 -0
  74. package/src/product/fr/bankAccountDetails/bankAccountDetailsV1.js +6 -0
  75. package/src/product/fr/bankAccountDetails/bankAccountDetailsV1Document.d.ts +3 -0
  76. package/src/product/fr/bankAccountDetails/bankAccountDetailsV1Document.js +3 -0
  77. package/src/product/fr/bankAccountDetails/bankAccountDetailsV2.d.ts +7 -0
  78. package/src/product/fr/bankAccountDetails/bankAccountDetailsV2.js +6 -0
  79. package/src/product/fr/bankAccountDetails/bankAccountDetailsV2Document.d.ts +3 -0
  80. package/src/product/fr/bankAccountDetails/bankAccountDetailsV2Document.js +3 -0
  81. package/src/product/fr/carteVitale/carteVitaleV1.d.ts +7 -0
  82. package/src/product/fr/carteVitale/carteVitaleV1.js +6 -0
  83. package/src/product/fr/carteVitale/carteVitaleV1Document.d.ts +3 -0
  84. package/src/product/fr/carteVitale/carteVitaleV1Document.js +3 -0
  85. package/src/product/fr/idCard/idCardV1.d.ts +7 -0
  86. package/src/product/fr/idCard/idCardV1.js +6 -0
  87. package/src/product/fr/idCard/idCardV1Document.d.ts +3 -0
  88. package/src/product/fr/idCard/idCardV1Document.js +3 -0
  89. package/src/product/invoice/invoiceV4.d.ts +7 -0
  90. package/src/product/invoice/invoiceV4.js +6 -0
  91. package/src/product/invoice/invoiceV4Document.d.ts +3 -1
  92. package/src/product/invoice/invoiceV4Document.js +3 -1
  93. package/src/product/invoice/invoiceV4LineItem.d.ts +9 -0
  94. package/src/product/invoice/invoiceV4LineItem.js +9 -0
  95. package/src/product/invoiceSplitter/invoiceSplitterV1.d.ts +7 -0
  96. package/src/product/invoiceSplitter/invoiceSplitterV1.js +6 -0
  97. package/src/product/invoiceSplitter/invoiceSplitterV1Document.d.ts +6 -0
  98. package/src/product/invoiceSplitter/invoiceSplitterV1Document.js +6 -0
  99. package/src/product/invoiceSplitter/invoiceSplitterV1PageGroup.d.ts +8 -0
  100. package/src/product/invoiceSplitter/invoiceSplitterV1PageGroup.js +7 -0
  101. package/src/product/passport/passportV1.d.ts +7 -0
  102. package/src/product/passport/passportV1.js +6 -0
  103. package/src/product/passport/passportV1Document.d.ts +3 -0
  104. package/src/product/passport/passportV1Document.js +3 -0
  105. package/src/product/proofOfAddress/proofOfAddressV1.d.ts +7 -0
  106. package/src/product/proofOfAddress/proofOfAddressV1.js +6 -0
  107. package/src/product/proofOfAddress/proofOfAddressV1Document.d.ts +3 -0
  108. package/src/product/proofOfAddress/proofOfAddressV1Document.js +3 -0
  109. package/src/product/receipt/receiptV4.d.ts +7 -0
  110. package/src/product/receipt/receiptV4.js +5 -0
  111. package/src/product/receipt/receiptV4Document.d.ts +6 -0
  112. package/src/product/receipt/receiptV4Document.js +6 -0
  113. package/src/product/receipt/receiptV5.d.ts +7 -0
  114. package/src/product/receipt/receiptV5.js +6 -0
  115. package/src/product/receipt/receiptV5Document.d.ts +3 -0
  116. package/src/product/receipt/receiptV5Document.js +3 -0
  117. package/src/product/us/bankCheck/bankCheckV1.d.ts +7 -0
  118. package/src/product/us/bankCheck/bankCheckV1.js +6 -0
  119. package/src/product/us/bankCheck/bankCheckV1Document.d.ts +3 -0
  120. package/src/product/us/bankCheck/bankCheckV1Document.js +3 -0
  121. package/src/product/us/driverLicense/driverLicenseV1.d.ts +7 -0
  122. package/src/product/us/driverLicense/driverLicenseV1.js +6 -0
  123. package/src/product/us/driverLicense/driverLicenseV1Document.d.ts +3 -0
  124. package/src/product/us/driverLicense/driverLicenseV1Document.js +3 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v4.0.2 - 2023-08-24
4
+ ### Changes
5
+ * :recycle: updated technical documentation
6
+
7
+ ### Fixes
8
+ * :bug: fix url source document not being sent properly
9
+
10
+
11
+ ## v4.0.1 - 2023-08-22
12
+ ### Fixes
13
+ * :bug: fixed pre-commit dependency script blocking installs
14
+
15
+
3
16
  ## v4.0.0 - 2023-08-14
4
17
  ### ¡Breaking Changes!
5
18
  * :art: :boom: harmonize response types with other libraries
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Mindee Client Library for Node.js",
5
5
  "main": "src/index.js",
6
6
  "bin": "bin/mindee.js",
@@ -11,9 +11,9 @@
11
11
  "clean": "rm -rf ./dist ./docs/_build",
12
12
  "test": "mocha 'tests/**/*.spec.ts'",
13
13
  "lint": "eslint './src/**/*.ts' --report-unused-disable-directives && echo 'Your .ts files look good.'",
14
+ "lint-fix": "eslint './src/**/*.ts' --fix",
14
15
  "docs": "typedoc --out docs/_build ./src/index.ts",
15
- "docs-for-dist": "typedoc --out docs/_build ./src/index.ts && cp -r ./docs/code_samples ./docs/_build/",
16
- "postinstall": "husky install"
16
+ "docs-for-dist": "typedoc --out docs/_build ./src/index.ts && cp -r ./docs/code_samples ./docs/_build/"
17
17
  },
18
18
  "files": [
19
19
  "src/*",
@@ -47,7 +47,6 @@
47
47
  "@typescript-eslint/parser": "^5.57.1",
48
48
  "chai": "^4.3.7",
49
49
  "eslint": "^8.32.0",
50
- "husky": "^8.0.3",
51
50
  "lint-staged": "^13.2.3",
52
51
  "mocha": "^10.1.0",
53
52
  "ts-node": "^10.9.1",
package/src/client.d.ts CHANGED
@@ -4,10 +4,11 @@ import { Readable } from "stream";
4
4
  import { InputSource, PageOptions } from "./input";
5
5
  import { Endpoint } from "./http";
6
6
  import { Inference, AsyncPredictResponse, StringDict, PredictResponse } from "./parsing/common";
7
+ /**
8
+ * Options relating to predictions.
9
+ */
7
10
  export interface PredictOptions {
8
- endpointName?: string;
9
- accountName?: string;
10
- endpointVersion?: string;
11
+ /** A custom endpoint. */
11
12
  endpoint?: Endpoint;
12
13
  /**
13
14
  * Whether to include the full text for each page.
@@ -21,18 +22,11 @@ export interface PredictOptions {
21
22
  * This performs a cropping operation on the server and will increase response time.
22
23
  */
23
24
  cropper?: boolean;
24
- pageOptions?: PageOptions;
25
- }
26
- export interface CustomConfigParams {
27
- /** Your organization's username on the API Builder. */
28
- accountName: string;
29
- /** The "API name" field in the "Settings" page of the API Builder. */
30
- endpointName: string;
31
25
  /**
32
- * If set, locks the version of the model to use.
33
- * If not set, use the latest version of the model.
26
+ * If set, remove pages from the document as specified.
27
+ * This is done before sending the file to the server and is useful to avoid page limitations.
34
28
  */
35
- version?: string;
29
+ pageOptions?: PageOptions;
36
30
  }
37
31
  export interface ClientOptions {
38
32
  /** Your API key for all endpoints. */
@@ -43,35 +37,67 @@ export interface ClientOptions {
43
37
  debug?: boolean;
44
38
  }
45
39
  /**
46
- * Mindee Client
40
+ * Mindee Client class that centralizes most basic operations.
41
+ *
42
+ * @category Client
47
43
  */
48
44
  export declare class Client {
49
45
  #private;
46
+ /** Key of the API. */
50
47
  protected apiKey: string;
51
48
  /**
52
- * @param options
49
+ * @param options options for the initialization of a client.
53
50
  */
54
51
  constructor({ apiKey, throwOnError, debug }?: ClientOptions);
55
52
  /**
56
53
  * Send a document to a synchronous endpoint and parse the predictions.
57
- * @param productClass
58
- * @param params
54
+ *
55
+ * @param productClass product class to use for calling the API and parsing the response.
56
+ * @param inputSource document to parse.
57
+ * @param params parameters relating to prediction options.
58
+ *
59
+ * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`.
60
+ * @category Synchronous
61
+ * @returns a `Promise` containing parsing results.
59
62
  */
60
63
  parse<T extends Inference>(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, params?: PredictOptions): Promise<PredictResponse<T>>;
61
64
  /**
62
65
  * Send the document to an asynchronous endpoint and return its ID in the queue.
63
- * @param productClass
64
- * @param params
66
+ * @param productClass product class to use for calling the API and parsing the response.
67
+ * @param params parameters relating to prediction options.
68
+ * @category Asynchronous
69
+ *
70
+ * @returns a `Promise` containing the job (queue) corresponding to a document.
65
71
  */
66
72
  enqueue<T extends Inference>(productClass: new (httpResponse: StringDict) => T, inputSource: InputSource, params?: PredictOptions): Promise<AsyncPredictResponse<T>>;
73
+ /**
74
+ * Polls a queue and returns its status as well as the prediction results if the parsing is done.
75
+ *
76
+ * @param productClass product class to use for calling the API and parsing the response.
77
+ * @param queueId id of the queue to poll.
78
+ * @param params parameters relating to prediction options.
79
+ * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`.
80
+ * @category Asynchronous
81
+ *
82
+ * @returns a `Promise` containing a `Job`, which also contains a `Document` if the
83
+ * parsing is complete.
84
+ */
67
85
  parseQueued<T extends Inference>(productClass: new (httpResponse: StringDict) => T, queueId: string, params?: PredictOptions): Promise<AsyncPredictResponse<T>>;
86
+ /**
87
+ * Forces boolean coercion on truthy/falsy parameters.
88
+ * @param param input parameter to check.
89
+ * @returns a strict boolean value.
90
+ */
68
91
  protected getBooleanParam(param?: boolean): boolean;
69
92
  /**
70
93
  * 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
94
+ * @param productClass product class to use for calling the API and parsing the response.
95
+ * @param endpointName Name of the custom Endpoint.
96
+ * @param accountName Name of the account tied to the Endpoint.
97
+ * @param version Version of the custom Endpoint.
98
+ * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`.
99
+ *
100
+ * @returns a new endpoint
75
101
  */
76
102
  createEndpoint(endpointName: string, accountName: string, endpointVersion?: string): Endpoint;
77
103
  /**
@@ -81,31 +107,31 @@ export declare class Client {
81
107
  docFromPath(inputPath: string): InputSource;
82
108
  /**
83
109
  * Load an input document from a base64 encoded string.
84
- * @param inputString
85
- * @param filename
110
+ * @param inputString input content, as a string.
111
+ * @param filename file name.
86
112
  */
87
113
  docFromBase64(inputString: string, filename: string): InputSource;
88
114
  /**
89
115
  * Load an input document from a `stream.Readable` object.
90
- * @param inputStream
91
- * @param filename
116
+ * @param inputStream input content, as a readable stream.
117
+ * @param filename file name.
92
118
  */
93
119
  docFromStream(inputStream: Readable, filename: string): InputSource;
94
120
  /**
95
121
  * Load an input document from a bytes string.
96
- * @param inputBytes
97
- * @param filename
122
+ * @param inputBytes input content, as readable bytes.
123
+ * @param filename file name.
98
124
  */
99
125
  docFromBytes(inputBytes: string, filename: string): InputSource;
100
126
  /**
101
127
  * Load an input document from a URL.
102
- * @param url
128
+ * @param url input url. Must be HTTPS.
103
129
  */
104
130
  docFromUrl(url: string): InputSource;
105
131
  /**
106
132
  * Load an input document from a Buffer.
107
- * @param buffer
108
- * @param filename
133
+ * @param buffer input content, as a buffer.
134
+ * @param filename file name.
109
135
  */
110
136
  docFromBuffer(buffer: Buffer, filename: string): InputSource;
111
137
  }
package/src/client.js CHANGED
@@ -15,11 +15,13 @@ const logger_1 = require("./logger");
15
15
  const inference_1 = require("./parsing/common/inference");
16
16
  const product_1 = require("./product");
17
17
  /**
18
- * Mindee Client
18
+ * Mindee Client class that centralizes most basic operations.
19
+ *
20
+ * @category Client
19
21
  */
20
22
  class Client {
21
23
  /**
22
- * @param options
24
+ * @param options options for the initialization of a client.
23
25
  */
24
26
  constructor({ apiKey, throwOnError, debug } = {
25
27
  apiKey: "",
@@ -37,8 +39,14 @@ class Client {
37
39
  }
38
40
  /**
39
41
  * Send a document to a synchronous endpoint and parse the predictions.
40
- * @param productClass
41
- * @param params
42
+ *
43
+ * @param productClass product class to use for calling the API and parsing the response.
44
+ * @param inputSource document to parse.
45
+ * @param params parameters relating to prediction options.
46
+ *
47
+ * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`.
48
+ * @category Synchronous
49
+ * @returns a `Promise` containing parsing results.
42
50
  */
43
51
  async parse(productClass, inputSource, params = {
44
52
  endpoint: undefined,
@@ -60,8 +68,11 @@ class Client {
60
68
  }
61
69
  /**
62
70
  * Send the document to an asynchronous endpoint and return its ID in the queue.
63
- * @param productClass
64
- * @param params
71
+ * @param productClass product class to use for calling the API and parsing the response.
72
+ * @param params parameters relating to prediction options.
73
+ * @category Asynchronous
74
+ *
75
+ * @returns a `Promise` containing the job (queue) corresponding to a document.
65
76
  */
66
77
  async enqueue(productClass, inputSource, params = {}) {
67
78
  const endpoint = params?.endpoint ?? __classPrivateFieldGet(this, _Client_instances, "m", _Client_initializeOTSEndpoint).call(this, productClass);
@@ -76,20 +87,40 @@ class Client {
76
87
  });
77
88
  return new common_1.AsyncPredictResponse(productClass, rawResponse.data);
78
89
  }
90
+ /**
91
+ * Polls a queue and returns its status as well as the prediction results if the parsing is done.
92
+ *
93
+ * @param productClass product class to use for calling the API and parsing the response.
94
+ * @param queueId id of the queue to poll.
95
+ * @param params parameters relating to prediction options.
96
+ * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`.
97
+ * @category Asynchronous
98
+ *
99
+ * @returns a `Promise` containing a `Job`, which also contains a `Document` if the
100
+ * parsing is complete.
101
+ */
79
102
  async parseQueued(productClass, queueId, params = {}) {
80
103
  const endpoint = params?.endpoint ?? __classPrivateFieldGet(this, _Client_instances, "m", _Client_initializeOTSEndpoint).call(this, productClass);
81
104
  const docResponse = await endpoint.getQueuedDocument(queueId);
82
105
  return new common_1.AsyncPredictResponse(productClass, docResponse.data);
83
106
  }
107
+ /**
108
+ * Forces boolean coercion on truthy/falsy parameters.
109
+ * @param param input parameter to check.
110
+ * @returns a strict boolean value.
111
+ */
84
112
  getBooleanParam(param) {
85
113
  return param !== undefined ? param : false;
86
114
  }
87
115
  /**
88
116
  * 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
117
+ * @param productClass product class to use for calling the API and parsing the response.
118
+ * @param endpointName Name of the custom Endpoint.
119
+ * @param accountName Name of the account tied to the Endpoint.
120
+ * @param version Version of the custom Endpoint.
121
+ * @typeParam T an extension of an `Inference`. Can be omitted as it will be inferred from the `productClass`.
122
+ *
123
+ * @returns a new endpoint
93
124
  */
94
125
  createEndpoint(endpointName, accountName, endpointVersion) {
95
126
  const cleanAccountName = __classPrivateFieldGet(this, _Client_instances, "m", _Client_cleanAccountName).call(this, product_1.CustomV1, accountName);
@@ -117,8 +148,8 @@ class Client {
117
148
  }
118
149
  /**
119
150
  * Load an input document from a base64 encoded string.
120
- * @param inputString
121
- * @param filename
151
+ * @param inputString input content, as a string.
152
+ * @param filename file name.
122
153
  */
123
154
  docFromBase64(inputString, filename) {
124
155
  return new input_1.Base64Input({
@@ -128,8 +159,8 @@ class Client {
128
159
  }
129
160
  /**
130
161
  * Load an input document from a `stream.Readable` object.
131
- * @param inputStream
132
- * @param filename
162
+ * @param inputStream input content, as a readable stream.
163
+ * @param filename file name.
133
164
  */
134
165
  docFromStream(inputStream, filename) {
135
166
  return new input_1.StreamInput({
@@ -139,8 +170,8 @@ class Client {
139
170
  }
140
171
  /**
141
172
  * Load an input document from a bytes string.
142
- * @param inputBytes
143
- * @param filename
173
+ * @param inputBytes input content, as readable bytes.
174
+ * @param filename file name.
144
175
  */
145
176
  docFromBytes(inputBytes, filename) {
146
177
  return new input_1.BytesInput({
@@ -150,7 +181,7 @@ class Client {
150
181
  }
151
182
  /**
152
183
  * Load an input document from a URL.
153
- * @param url
184
+ * @param url input url. Must be HTTPS.
154
185
  */
155
186
  docFromUrl(url) {
156
187
  return new input_1.UrlInput({
@@ -159,8 +190,8 @@ class Client {
159
190
  }
160
191
  /**
161
192
  * Load an input document from a Buffer.
162
- * @param buffer
163
- * @param filename
193
+ * @param buffer input content, as a buffer.
194
+ * @param filename file name.
164
195
  */
165
196
  docFromBuffer(buffer, filename) {
166
197
  return new input_1.BufferInput({
@@ -32,7 +32,7 @@ class Endpoint {
32
32
  }
33
33
  const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictReqPost).call(this, params.inputDoc, params.includeWords, params.cropper);
34
34
  const statusCode = response.messageObj.statusCode;
35
- if (statusCode === undefined || statusCode > 400) {
35
+ if (statusCode === undefined || statusCode >= 400) {
36
36
  (0, error_1.handleError)(this.urlName, response, statusCode);
37
37
  }
38
38
  return response;
@@ -44,7 +44,7 @@ class Endpoint {
44
44
  }
45
45
  const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictAsyncReqPost).call(this, params.inputDoc, params.includeWords, params.cropper);
46
46
  const statusCode = response.messageObj.statusCode;
47
- if (statusCode === undefined || statusCode > 400) {
47
+ if (statusCode === undefined || statusCode >= 400) {
48
48
  (0, error_1.handleError)(this.urlName, response, statusCode);
49
49
  }
50
50
  return response;
@@ -80,15 +80,13 @@ class Endpoint {
80
80
  searchParams.append("cropper", "true");
81
81
  }
82
82
  const form = new form_data_1.default();
83
- if (input instanceof base_1.LocalInputSource) {
84
- if (input.fileObject instanceof Buffer) {
85
- form.append("document", input.fileObject, {
86
- filename: input.filename,
87
- });
88
- }
89
- else {
90
- form.append("document", input.fileObject);
91
- }
83
+ if (input instanceof base_1.LocalInputSource && input.fileObject instanceof Buffer) {
84
+ form.append("document", input.fileObject, {
85
+ filename: input.filename,
86
+ });
87
+ }
88
+ else {
89
+ form.append("document", input.fileObject);
92
90
  }
93
91
  if (includeWords) {
94
92
  form.append("include_mvision", "true");
package/src/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * as product from "./product";
2
- export { Client, CustomConfigParams, PredictOptions } from "./client";
2
+ export { Client, PredictOptions } from "./client";
3
3
  export { AsyncPredictResponse, PredictResponse, Document, Page, } from "./parsing/common";
4
4
  export { InputSource, PageOptionsOperation } from "./input";
@@ -9,6 +9,7 @@ export declare const INPUT_TYPE_BYTES = "bytes";
9
9
  export declare const INPUT_TYPE_PATH = "path";
10
10
  export declare const INPUT_TYPE_BUFFER = "buffer";
11
11
  export declare abstract class InputSource {
12
+ fileObject: Buffer | string;
12
13
  init(): Promise<void>;
13
14
  }
14
15
  export declare abstract class LocalInputSource extends InputSource {
package/src/input/base.js CHANGED
@@ -52,6 +52,9 @@ const ALLOWED_INPUT_TYPES = [
52
52
  exports.INPUT_TYPE_BUFFER,
53
53
  ];
54
54
  class InputSource {
55
+ constructor() {
56
+ this.fileObject = "";
57
+ }
55
58
  async init() {
56
59
  throw new Error("not Implemented");
57
60
  }
@@ -1,3 +1,4 @@
1
+ /** Options to pass to the `parse` method for cutting multi-page documents. */
1
2
  export interface PageOptions {
2
3
  /**
3
4
  * Zero-based list of page indexes.
@@ -14,7 +15,10 @@ export interface PageOptions {
14
15
  */
15
16
  onMinPages: number;
16
17
  }
18
+ /** Operation to apply on the document, given the page indexes specified. */
17
19
  export declare enum PageOptionsOperation {
20
+ /** Only keep pages matching the provided indexes. */
18
21
  KeepOnly = "KEEP_ONLY",
22
+ /** Remove pages matching the provided indexes. */
19
23
  Remove = "REMOVE"
20
24
  }
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PageOptionsOperation = void 0;
4
+ /** Operation to apply on the document, given the page indexes specified. */
4
5
  var PageOptionsOperation;
5
6
  (function (PageOptionsOperation) {
7
+ /** Only keep pages matching the provided indexes. */
6
8
  PageOptionsOperation["KeepOnly"] = "KEEP_ONLY";
9
+ /** Remove pages matching the provided indexes. */
7
10
  PageOptionsOperation["Remove"] = "REMOVE";
8
11
  })(PageOptionsOperation = exports.PageOptionsOperation || (exports.PageOptionsOperation = {}));
@@ -2,7 +2,7 @@
2
2
  /// <reference types="node" />
3
3
  import { Readable } from "stream";
4
4
  import { Buffer } from "buffer";
5
- import { LocalInputSource } from "./base";
5
+ import { LocalInputSource, InputSource } from "./base";
6
6
  interface PathInputProps {
7
7
  inputPath: string;
8
8
  }
@@ -43,9 +43,8 @@ export declare class BytesInput extends LocalInputSource {
43
43
  constructor({ inputBytes, filename }: BytesInputProps);
44
44
  init(): Promise<void>;
45
45
  }
46
- export declare class UrlInput {
46
+ export declare class UrlInput extends InputSource {
47
47
  private readonly url;
48
- fileObject: string;
49
48
  constructor({ url }: {
50
49
  url: string;
51
50
  });
@@ -106,8 +106,9 @@ exports.BytesInput = BytesInput;
106
106
  //
107
107
  // URL
108
108
  //
109
- class UrlInput {
109
+ class UrlInput extends base_1.InputSource {
110
110
  constructor({ url }) {
111
+ super();
111
112
  this.url = url;
112
113
  }
113
114
  async init() {
@@ -1,10 +1,19 @@
1
1
  import { StringDict } from "./stringDict";
2
+ /**
3
+ * Holds the information relating to an API HTTP request.
4
+ *
5
+ * @category API Response
6
+ */
2
7
  export declare class ApiRequest {
8
+ /** An object detailing the error. */
3
9
  error: StringDict;
10
+ /** Target of the request. */
4
11
  resources: string[];
12
+ /** Status of the request. Either "failure" or "success". */
5
13
  status: "failure" | "success";
6
14
  /** HTTP status code */
7
15
  statusCode: number;
16
+ /** URL of the request. */
8
17
  url: string;
9
18
  constructor(serverResponse: StringDict);
10
19
  }
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiRequest = void 0;
4
+ /**
5
+ * Holds the information relating to an API HTTP request.
6
+ *
7
+ * @category API Response
8
+ */
4
9
  class ApiRequest {
5
10
  constructor(serverResponse) {
6
11
  this.error = serverResponse["error"];
@@ -1,6 +1,15 @@
1
1
  import { ApiRequest } from "./apiRequest";
2
2
  import { StringDict } from "./stringDict";
3
+ /** Base wrapper for API requests.
4
+ *
5
+ * @category API Response
6
+ */
3
7
  export declare abstract class ApiResponse {
8
+ /** Initial request sent to the API. */
4
9
  apiRequest: ApiRequest;
10
+ /**
11
+ *
12
+ * @param serverResponse JSON response from the server.
13
+ */
5
14
  constructor(serverResponse: StringDict);
6
15
  }
@@ -2,7 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiResponse = void 0;
4
4
  const apiRequest_1 = require("./apiRequest");
5
+ /** Base wrapper for API requests.
6
+ *
7
+ * @category API Response
8
+ */
5
9
  class ApiResponse {
10
+ /**
11
+ *
12
+ * @param serverResponse JSON response from the server.
13
+ */
6
14
  constructor(serverResponse) {
7
15
  this.apiRequest = new apiRequest_1.ApiRequest(serverResponse["api_request"]);
8
16
  }
@@ -2,20 +2,41 @@ import { ApiResponse } from "./apiResponse";
2
2
  import { StringDict } from "./stringDict";
3
3
  import { Inference } from "./inference";
4
4
  import { Document } from "./document";
5
+ /** Wrapper for asynchronous request queues. Holds information regarding a job (queue).
6
+ *
7
+ * @category API Response
8
+ * @category Asynchronous
9
+ */
5
10
  export declare class Job {
11
+ /** Timestamp noting the enqueueing of a document. */
6
12
  issuedAt: Date;
13
+ /** Timestamp noting the availability of a prediction for an enqueued document. */
7
14
  availableAt?: Date;
15
+ /** ID of the job. */
8
16
  id: string;
17
+ /** Status of the job. */
9
18
  status?: "waiting" | "processing" | "completed";
10
- /**
11
- * The time taken to process the job, in milliseconds.
12
- */
19
+ /** The time taken to process the job, in milliseconds. */
13
20
  milliSecsTaken?: number;
14
21
  constructor(jsonResponse: StringDict);
15
22
  protected datetimeWithTimezone(date: string): Date;
16
23
  }
24
+ /** Wrapper for asynchronous jobs and parsing results.
25
+ *
26
+ * @category API Response
27
+ * @category Asynchronous
28
+ */
17
29
  export declare class AsyncPredictResponse<T extends Inference> extends ApiResponse {
30
+ /** Job for a queue. */
18
31
  job: Job;
32
+ /** Prediction for an asynchronous request. Will not be available so long as the job is not
33
+ * `completed`.
34
+ */
19
35
  document?: Document<T>;
36
+ /**
37
+ *
38
+ * @param inferenceClass constructor signature for an inference.
39
+ * @param httpResponse raw http response.
40
+ */
20
41
  constructor(inferenceClass: new (httpResponse: StringDict) => T, httpResponse: StringDict);
21
42
  }
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AsyncPredictResponse = exports.Job = void 0;
4
4
  const apiResponse_1 = require("./apiResponse");
5
5
  const document_1 = require("./document");
6
+ /** Wrapper for asynchronous request queues. Holds information regarding a job (queue).
7
+ *
8
+ * @category API Response
9
+ * @category Asynchronous
10
+ */
6
11
  class Job {
7
12
  constructor(jsonResponse) {
8
13
  this.issuedAt = this.datetimeWithTimezone(jsonResponse["issued_at"]);
@@ -26,7 +31,17 @@ class Job {
26
31
  }
27
32
  }
28
33
  exports.Job = Job;
34
+ /** Wrapper for asynchronous jobs and parsing results.
35
+ *
36
+ * @category API Response
37
+ * @category Asynchronous
38
+ */
29
39
  class AsyncPredictResponse extends apiResponse_1.ApiResponse {
40
+ /**
41
+ *
42
+ * @param inferenceClass constructor signature for an inference.
43
+ * @param httpResponse raw http response.
44
+ */
30
45
  constructor(inferenceClass, httpResponse) {
31
46
  super(httpResponse);
32
47
  this.job = new Job(httpResponse["job"]);
@@ -2,12 +2,29 @@ import { Extras } from "./extras/extras";
2
2
  import { Inference } from "./inference";
3
3
  import { Ocr } from "./ocr";
4
4
  import { StringDict } from "./stringDict";
5
+ /**
6
+ * Document prediction wrapper class. Holds the results of a parsed document.
7
+ * @typeParam T an extension of an `Inference`. Mandatory in order to properly create an inference.
8
+ */
5
9
  export declare class Document<T extends Inference> {
10
+ /** File name as sent back by the server. */
6
11
  filename: string;
12
+ /** Result of the base inference. */
7
13
  inference: T;
14
+ /** Id of the document as sent back by the server. */
8
15
  id: string;
16
+ /** Potential `Extras` fields sent back along the prediction. */
9
17
  extras?: Extras;
18
+ /** Raw-text response for `allWords` parsing. */
10
19
  ocr?: Ocr;
20
+ /**
21
+ *
22
+ * @param inferenceClass constructor signature for an inference.
23
+ * @param httpResponse raw http response.
24
+ */
11
25
  constructor(inferenceClass: new (httpResponse: StringDict) => T, httpResponse: StringDict);
26
+ /**
27
+ * Default string representation.
28
+ */
12
29
  toString(): string;
13
30
  }