mindee 4.0.1 → 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.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/client.d.ts +58 -32
- package/src/client.js +50 -19
- package/src/http/endpoint.js +9 -11
- package/src/index.d.ts +1 -1
- package/src/input/base.d.ts +1 -0
- package/src/input/base.js +3 -0
- package/src/input/pageOptions.d.ts +4 -0
- package/src/input/pageOptions.js +3 -0
- package/src/input/sources.d.ts +2 -3
- package/src/input/sources.js +2 -1
- package/src/parsing/common/apiRequest.d.ts +9 -0
- package/src/parsing/common/apiRequest.js +5 -0
- package/src/parsing/common/apiResponse.d.ts +9 -0
- package/src/parsing/common/apiResponse.js +8 -0
- package/src/parsing/common/asyncPredictResponse.d.ts +24 -3
- package/src/parsing/common/asyncPredictResponse.js +15 -0
- package/src/parsing/common/document.d.ts +17 -0
- package/src/parsing/common/document.js +16 -4
- package/src/parsing/common/extras/cropperExtra.d.ts +3 -0
- package/src/parsing/common/extras/cropperExtra.js +3 -0
- package/src/parsing/common/extras/extras.d.ts +3 -0
- package/src/parsing/common/extras/extras.js +3 -0
- package/src/parsing/common/inference.d.ts +26 -0
- package/src/parsing/common/inference.js +23 -2
- package/src/parsing/common/mvisionV1.d.ts +3 -0
- package/src/parsing/common/mvisionV1.js +3 -0
- package/src/parsing/common/ocr.d.ts +3 -0
- package/src/parsing/common/ocr.js +3 -0
- package/src/parsing/common/ocrPage.d.ts +3 -0
- package/src/parsing/common/ocrPage.js +3 -0
- package/src/parsing/common/orientation.d.ts +3 -0
- package/src/parsing/common/orientation.js +3 -0
- package/src/parsing/common/page.d.ts +19 -0
- package/src/parsing/common/page.js +15 -0
- package/src/parsing/common/predictResponse.d.ts +11 -0
- package/src/parsing/common/predictResponse.js +10 -0
- package/src/parsing/custom/classificationField.d.ts +3 -0
- package/src/parsing/custom/classificationField.js +3 -0
- package/src/parsing/custom/listField.d.ts +6 -0
- package/src/parsing/custom/listField.js +6 -0
- package/src/parsing/standard/amount.d.ts +3 -0
- package/src/parsing/standard/amount.js +3 -0
- package/src/parsing/standard/base.d.ts +3 -0
- package/src/parsing/standard/base.js +3 -0
- package/src/parsing/standard/locale.d.ts +3 -0
- package/src/parsing/standard/locale.js +3 -0
- package/src/parsing/standard/paymentDetails.d.ts +3 -0
- package/src/parsing/standard/paymentDetails.js +3 -0
- package/src/parsing/standard/position.d.ts +3 -0
- package/src/parsing/standard/position.js +3 -0
- package/src/parsing/standard/tax.d.ts +3 -0
- package/src/parsing/standard/tax.js +3 -0
- package/src/product/cropper/cropperV1.d.ts +7 -0
- package/src/product/cropper/cropperV1.js +6 -0
- package/src/product/cropper/cropperV1Document.d.ts +6 -0
- package/src/product/cropper/cropperV1Document.js +6 -0
- package/src/product/custom/customV1.d.ts +7 -0
- package/src/product/custom/customV1.js +6 -0
- package/src/product/custom/customV1Document.d.ts +16 -0
- package/src/product/custom/customV1Document.js +16 -2
- package/src/product/custom/customV1Page.d.ts +7 -0
- package/src/product/custom/customV1Page.js +7 -0
- package/src/product/eu/licensePlate/licensePlateV1.d.ts +7 -0
- package/src/product/eu/licensePlate/licensePlateV1.js +6 -0
- package/src/product/eu/licensePlate/licensePlateV1Document.d.ts +3 -0
- package/src/product/eu/licensePlate/licensePlateV1Document.js +3 -0
- package/src/product/financialDocument/financialDocumentV1.d.ts +7 -0
- package/src/product/financialDocument/financialDocumentV1.js +6 -0
- package/src/product/financialDocument/financialDocumentV1Document.d.ts +3 -0
- package/src/product/financialDocument/financialDocumentV1Document.js +3 -0
- package/src/product/fr/bankAccountDetails/bankAccountDetailsV1.d.ts +7 -0
- package/src/product/fr/bankAccountDetails/bankAccountDetailsV1.js +6 -0
- package/src/product/fr/bankAccountDetails/bankAccountDetailsV1Document.d.ts +3 -0
- package/src/product/fr/bankAccountDetails/bankAccountDetailsV1Document.js +3 -0
- package/src/product/fr/bankAccountDetails/bankAccountDetailsV2.d.ts +7 -0
- package/src/product/fr/bankAccountDetails/bankAccountDetailsV2.js +6 -0
- package/src/product/fr/bankAccountDetails/bankAccountDetailsV2Document.d.ts +3 -0
- package/src/product/fr/bankAccountDetails/bankAccountDetailsV2Document.js +3 -0
- package/src/product/fr/carteVitale/carteVitaleV1.d.ts +7 -0
- package/src/product/fr/carteVitale/carteVitaleV1.js +6 -0
- package/src/product/fr/carteVitale/carteVitaleV1Document.d.ts +3 -0
- package/src/product/fr/carteVitale/carteVitaleV1Document.js +3 -0
- package/src/product/fr/idCard/idCardV1.d.ts +7 -0
- package/src/product/fr/idCard/idCardV1.js +6 -0
- package/src/product/fr/idCard/idCardV1Document.d.ts +3 -0
- package/src/product/fr/idCard/idCardV1Document.js +3 -0
- package/src/product/invoice/invoiceV4.d.ts +7 -0
- package/src/product/invoice/invoiceV4.js +6 -0
- package/src/product/invoice/invoiceV4Document.d.ts +3 -1
- package/src/product/invoice/invoiceV4Document.js +3 -1
- package/src/product/invoice/invoiceV4LineItem.d.ts +9 -0
- package/src/product/invoice/invoiceV4LineItem.js +9 -0
- package/src/product/invoiceSplitter/invoiceSplitterV1.d.ts +7 -0
- package/src/product/invoiceSplitter/invoiceSplitterV1.js +6 -0
- package/src/product/invoiceSplitter/invoiceSplitterV1Document.d.ts +6 -0
- package/src/product/invoiceSplitter/invoiceSplitterV1Document.js +6 -0
- package/src/product/invoiceSplitter/invoiceSplitterV1PageGroup.d.ts +8 -0
- package/src/product/invoiceSplitter/invoiceSplitterV1PageGroup.js +7 -0
- package/src/product/passport/passportV1.d.ts +7 -0
- package/src/product/passport/passportV1.js +6 -0
- package/src/product/passport/passportV1Document.d.ts +3 -0
- package/src/product/passport/passportV1Document.js +3 -0
- package/src/product/proofOfAddress/proofOfAddressV1.d.ts +7 -0
- package/src/product/proofOfAddress/proofOfAddressV1.js +6 -0
- package/src/product/proofOfAddress/proofOfAddressV1Document.d.ts +3 -0
- package/src/product/proofOfAddress/proofOfAddressV1Document.js +3 -0
- package/src/product/receipt/receiptV4.d.ts +7 -0
- package/src/product/receipt/receiptV4.js +5 -0
- package/src/product/receipt/receiptV4Document.d.ts +6 -0
- package/src/product/receipt/receiptV4Document.js +6 -0
- package/src/product/receipt/receiptV5.d.ts +7 -0
- package/src/product/receipt/receiptV5.js +6 -0
- package/src/product/receipt/receiptV5Document.d.ts +3 -0
- package/src/product/receipt/receiptV5Document.js +3 -0
- package/src/product/us/bankCheck/bankCheckV1.d.ts +7 -0
- package/src/product/us/bankCheck/bankCheckV1.js +6 -0
- package/src/product/us/bankCheck/bankCheckV1Document.d.ts +3 -0
- package/src/product/us/bankCheck/bankCheckV1Document.js +3 -0
- package/src/product/us/driverLicense/driverLicenseV1.d.ts +7 -0
- package/src/product/us/driverLicense/driverLicenseV1.js +6 -0
- package/src/product/us/driverLicense/driverLicenseV1Document.d.ts +3 -0
- package/src/product/us/driverLicense/driverLicenseV1Document.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
3
11
|
## v4.0.1 - 2023-08-22
|
|
4
12
|
### Fixes
|
|
5
13
|
* :bug: fixed pre-commit dependency script blocking installs
|
package/package.json
CHANGED
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
|
-
|
|
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,
|
|
33
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
58
|
-
* @param
|
|
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
|
|
72
|
-
* @param endpointName Name of
|
|
73
|
-
* @param accountName Name of the account tied to the
|
|
74
|
-
* @param version Version of
|
|
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
|
-
*
|
|
41
|
-
* @param
|
|
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
|
|
90
|
-
* @param endpointName Name of
|
|
91
|
-
* @param accountName Name of the account tied to the
|
|
92
|
-
* @param version Version of
|
|
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({
|
package/src/http/endpoint.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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,
|
|
2
|
+
export { Client, PredictOptions } from "./client";
|
|
3
3
|
export { AsyncPredictResponse, PredictResponse, Document, Page, } from "./parsing/common";
|
|
4
4
|
export { InputSource, PageOptionsOperation } from "./input";
|
package/src/input/base.d.ts
CHANGED
|
@@ -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
|
@@ -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
|
}
|
package/src/input/pageOptions.js
CHANGED
|
@@ -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 = {}));
|
package/src/input/sources.d.ts
CHANGED
|
@@ -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
|
});
|
package/src/input/sources.js
CHANGED
|
@@ -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
|
}
|
|
@@ -3,14 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Document = void 0;
|
|
4
4
|
const cropperExtra_1 = require("./extras/cropperExtra");
|
|
5
5
|
const extras_1 = require("./extras/extras");
|
|
6
|
+
/**
|
|
7
|
+
* Document prediction wrapper class. Holds the results of a parsed document.
|
|
8
|
+
* @typeParam T an extension of an `Inference`. Mandatory in order to properly create an inference.
|
|
9
|
+
*/
|
|
6
10
|
class Document {
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param inferenceClass constructor signature for an inference.
|
|
14
|
+
* @param httpResponse raw http response.
|
|
15
|
+
*/
|
|
7
16
|
constructor(inferenceClass, httpResponse) {
|
|
8
|
-
this.id = httpResponse
|
|
9
|
-
this.filename = httpResponse
|
|
10
|
-
this.ocr = httpResponse
|
|
17
|
+
this.id = httpResponse?.id ?? "";
|
|
18
|
+
this.filename = httpResponse?.name ?? "";
|
|
19
|
+
this.ocr = httpResponse?.ocr ?? undefined;
|
|
11
20
|
this.inference = new inferenceClass(httpResponse["inference"]);
|
|
12
21
|
// Note: this is a convoluted but functional way of being able to implement/use Extras fields
|
|
13
|
-
// as an extension of a Map object (like having an adapted toString() method, for instance)
|
|
22
|
+
// as an extension of a Map object (like having an adapted toString() method, for instance).
|
|
14
23
|
if (httpResponse["extras"] &&
|
|
15
24
|
Object.keys(httpResponse["extras"].length > 0)) {
|
|
16
25
|
const extras = {};
|
|
@@ -23,6 +32,9 @@ class Document {
|
|
|
23
32
|
this.extras = new extras_1.Extras(extras);
|
|
24
33
|
}
|
|
25
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Default string representation.
|
|
37
|
+
*/
|
|
26
38
|
toString() {
|
|
27
39
|
return `########\nDocument\n########
|
|
28
40
|
:Mindee ID: ${this.id}
|