mindee 4.3.1 → 4.3.3
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 +15 -0
- package/package.json +5 -4
- package/src/cli.js +52 -16
- package/src/client.d.ts +35 -6
- package/src/client.js +47 -16
- package/src/http/apiSettings.d.ts +15 -0
- package/src/http/{mindeeApi.js → apiSettings.js} +10 -13
- package/src/http/baseEndpoint.d.ts +27 -0
- package/src/http/baseEndpoint.js +65 -0
- package/src/http/endpoint.d.ts +27 -38
- package/src/http/endpoint.js +46 -60
- package/src/http/error.d.ts +11 -11
- package/src/http/error.js +29 -29
- package/src/http/index.d.ts +3 -2
- package/src/http/index.js +5 -5
- package/src/input/base.d.ts +7 -6
- package/src/input/base.js +1 -4
- package/src/parsing/common/apiResponse.d.ts +1 -1
- package/src/parsing/common/apiResponse.js +1 -1
- package/src/parsing/common/asyncPredictResponse.d.ts +4 -4
- package/src/parsing/common/asyncPredictResponse.js +8 -8
- package/src/parsing/common/extras/cropperExtra.js +1 -1
- package/src/parsing/common/feedback/feedbackResponse.d.ts +15 -0
- package/src/parsing/common/feedback/feedbackResponse.js +19 -0
- package/src/parsing/common/index.d.ts +1 -0
- package/src/parsing/common/index.js +3 -1
- package/src/parsing/common/inference.js +9 -5
- package/src/parsing/common/orientation.d.ts +1 -4
- package/src/parsing/common/orientation.js +1 -4
- package/src/parsing/common/page.d.ts +2 -3
- package/src/parsing/common/page.js +2 -3
- package/src/parsing/common/predictResponse.d.ts +3 -3
- package/src/parsing/common/predictResponse.js +5 -5
- package/src/parsing/custom/listField.d.ts +6 -3
- package/src/parsing/custom/listField.js +3 -0
- package/src/parsing/standard/amount.d.ts +4 -6
- package/src/parsing/standard/amount.js +1 -4
- package/src/parsing/standard/base.d.ts +9 -4
- package/src/parsing/standard/base.js +2 -4
- package/src/parsing/standard/companyRegistration.d.ts +3 -2
- package/src/parsing/standard/date.d.ts +4 -6
- package/src/parsing/standard/date.js +1 -4
- package/src/parsing/standard/field.d.ts +4 -15
- package/src/parsing/standard/field.js +2 -6
- package/src/parsing/standard/index.d.ts +1 -1
- package/src/parsing/standard/locale.d.ts +1 -3
- package/src/parsing/standard/locale.js +1 -3
- package/src/parsing/standard/paymentDetails.d.ts +11 -8
- package/src/parsing/standard/paymentDetails.js +1 -8
- package/src/parsing/standard/tax.d.ts +8 -12
- package/src/parsing/standard/tax.js +1 -7
- package/src/product/financialDocument/financialDocumentV1Document.js +2 -2
- package/src/product/invoice/invoiceV4Document.d.ts +33 -32
- package/src/product/invoice/invoiceV4Document.js +89 -104
- package/src/product/invoice/invoiceV4LineItem.d.ts +16 -16
- package/src/product/invoice/invoiceV4LineItem.js +58 -60
- package/src/product/invoiceSplitter/invoiceSplitterV1Document.d.ts +2 -2
- package/src/product/invoiceSplitter/invoiceSplitterV1Document.js +1 -2
- package/src/product/invoiceSplitter/invoiceSplitterV1PageGroup.d.ts +1 -1
- package/src/product/invoiceSplitter/invoiceSplitterV1PageGroup.js +1 -1
- package/src/product/us/w9/w9V1.d.ts +1 -1
- package/src/product/us/w9/w9V1.js +1 -1
- package/src/product/us/w9/w9V1Document.d.ts +1 -1
- package/src/product/us/w9/w9V1Document.js +1 -1
- package/src/product/us/w9/w9V1Page.d.ts +1 -1
- package/src/product/us/w9/w9V1Page.js +1 -1
- package/src/http/mindeeApi.d.ts +0 -20
package/src/http/endpoint.js
CHANGED
|
@@ -7,31 +7,30 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
7
7
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
9
|
};
|
|
10
|
-
var _Endpoint_instances, _Endpoint_cutDocPages, _Endpoint_predictReqPost, _Endpoint_predictAsyncReqPost, _Endpoint_documentQueueReqGet, _Endpoint_documentGetReq;
|
|
10
|
+
var _Endpoint_instances, _Endpoint_cutDocPages, _Endpoint_predictReqPost, _Endpoint_predictAsyncReqPost, _Endpoint_documentQueueReqGet, _Endpoint_documentGetReq, _Endpoint_documentFeedbackPutReq;
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Endpoint = void 0;
|
|
13
|
-
const https_1 = require("https");
|
|
14
13
|
const url_1 = require("url");
|
|
15
14
|
const form_data_1 = __importDefault(require("form-data"));
|
|
16
|
-
const logger_1 = require("../logger");
|
|
17
15
|
const base_1 = require("../input/base");
|
|
18
16
|
const error_1 = require("./error");
|
|
17
|
+
const baseEndpoint_1 = require("./baseEndpoint");
|
|
19
18
|
/**
|
|
20
|
-
* Endpoint
|
|
19
|
+
* Endpoint for a product (OTS or Custom).
|
|
21
20
|
*/
|
|
22
|
-
class Endpoint {
|
|
21
|
+
class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
23
22
|
constructor(urlName, owner, version, settings) {
|
|
23
|
+
super(settings);
|
|
24
24
|
_Endpoint_instances.add(this);
|
|
25
25
|
this.owner = owner;
|
|
26
26
|
this.urlName = urlName;
|
|
27
27
|
this.version = version;
|
|
28
|
-
this.settings = settings;
|
|
29
28
|
this.urlRoot = `/v1/products/${owner}/${urlName}/v${version}`;
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
31
|
* Sends a prediction to the API and parses out the result.
|
|
33
32
|
* Throws an error if the server's response contains one.
|
|
34
|
-
* @param params parameters relating to prediction options.
|
|
33
|
+
* @param {PredictParams} params parameters relating to prediction options.
|
|
35
34
|
* @category Synchronous
|
|
36
35
|
* @returns a `Promise` containing parsing results.
|
|
37
36
|
*/
|
|
@@ -50,7 +49,7 @@ class Endpoint {
|
|
|
50
49
|
/**
|
|
51
50
|
* Enqueues a prediction to the API.
|
|
52
51
|
* Throws an error if the server's response contains one.
|
|
53
|
-
* @param params parameters relating to prediction options.
|
|
52
|
+
* @param {PredictParams} params parameters relating to prediction options.
|
|
54
53
|
* @category Asynchronous
|
|
55
54
|
* @returns a `Promise` containing queue data.
|
|
56
55
|
*/
|
|
@@ -69,7 +68,7 @@ class Endpoint {
|
|
|
69
68
|
/**
|
|
70
69
|
* Requests the results of a queued document from the API.
|
|
71
70
|
* Throws an error if the server's response contains one.
|
|
72
|
-
* @param
|
|
71
|
+
* @param queueId The document's ID in the queue.
|
|
73
72
|
* @category Asynchronous
|
|
74
73
|
* @returns a `Promise` containing the parsed result.
|
|
75
74
|
*/
|
|
@@ -90,6 +89,31 @@ class Endpoint {
|
|
|
90
89
|
}
|
|
91
90
|
return queueResponse;
|
|
92
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Send a feedback
|
|
94
|
+
* @param {string} documentId
|
|
95
|
+
*/
|
|
96
|
+
async getDocument(documentId) {
|
|
97
|
+
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_documentGetReq).call(this, documentId);
|
|
98
|
+
const statusCode = response.messageObj.statusCode;
|
|
99
|
+
if (statusCode === undefined || statusCode >= 400) {
|
|
100
|
+
(0, error_1.handleError)("document", response, statusCode, response.messageObj?.statusMessage);
|
|
101
|
+
}
|
|
102
|
+
return response;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Send a feedback
|
|
106
|
+
* @param {string} documentId - ID of the document to send feedback to.
|
|
107
|
+
* @param {StringDict} feedback - Feedback object to send.
|
|
108
|
+
*/
|
|
109
|
+
async sendFeedback(documentId, feedback) {
|
|
110
|
+
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_documentFeedbackPutReq).call(this, documentId, feedback);
|
|
111
|
+
const statusCode = response.messageObj.statusCode;
|
|
112
|
+
if (statusCode === undefined || statusCode >= 400) {
|
|
113
|
+
(0, error_1.handleError)("feedback", response, statusCode, response.messageObj?.statusMessage);
|
|
114
|
+
}
|
|
115
|
+
return response;
|
|
116
|
+
}
|
|
93
117
|
/**
|
|
94
118
|
* Send a file to a prediction API.
|
|
95
119
|
* @param input
|
|
@@ -132,57 +156,6 @@ class Endpoint {
|
|
|
132
156
|
req.end();
|
|
133
157
|
});
|
|
134
158
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Reads a response from the API and processes it.
|
|
137
|
-
* @param options options related to the request itself.
|
|
138
|
-
* @param resolve the resolved response
|
|
139
|
-
* @param reject promise rejection reason.
|
|
140
|
-
* @returns the processed request.
|
|
141
|
-
*/
|
|
142
|
-
readResponse(options, resolve, reject) {
|
|
143
|
-
logger_1.logger.debug(`${options.method}: https://${options.hostname}${options.path}`);
|
|
144
|
-
const req = (0, https_1.request)(options, function (res) {
|
|
145
|
-
// when the encoding is set, data chunks will be strings
|
|
146
|
-
res.setEncoding("utf-8");
|
|
147
|
-
let responseBody = "";
|
|
148
|
-
res.on("data", function (chunk) {
|
|
149
|
-
logger_1.logger.debug("Receiving data ...");
|
|
150
|
-
responseBody += chunk;
|
|
151
|
-
});
|
|
152
|
-
res.on("end", function () {
|
|
153
|
-
logger_1.logger.debug("Parsing the response ...");
|
|
154
|
-
// handle empty responses from server, for example in the case of redirects
|
|
155
|
-
if (!responseBody) {
|
|
156
|
-
responseBody = "{}";
|
|
157
|
-
}
|
|
158
|
-
try {
|
|
159
|
-
const parsedResponse = JSON.parse(responseBody);
|
|
160
|
-
try {
|
|
161
|
-
resolve({
|
|
162
|
-
messageObj: res,
|
|
163
|
-
data: parsedResponse,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
logger_1.logger.error("Could not construct the return object.");
|
|
168
|
-
reject(error);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch (error) {
|
|
172
|
-
logger_1.logger.error("Could not parse the return as JSON.");
|
|
173
|
-
logger_1.logger.debug(responseBody);
|
|
174
|
-
resolve({
|
|
175
|
-
messageObj: res,
|
|
176
|
-
data: { reconstructedResponse: responseBody },
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
req.on("error", (err) => {
|
|
182
|
-
reject(err);
|
|
183
|
-
});
|
|
184
|
-
return req;
|
|
185
|
-
}
|
|
186
159
|
}
|
|
187
160
|
exports.Endpoint = Endpoint;
|
|
188
161
|
_Endpoint_instances = new WeakSet(), _Endpoint_cutDocPages =
|
|
@@ -223,4 +196,17 @@ async function _Endpoint_cutDocPages(inputDoc, pageOptions) {
|
|
|
223
196
|
// potential ECONNRESET if we don't end the request.
|
|
224
197
|
req.end();
|
|
225
198
|
});
|
|
199
|
+
}, _Endpoint_documentFeedbackPutReq = function _Endpoint_documentFeedbackPutReq(documentId, feedback) {
|
|
200
|
+
return new Promise((resolve, reject) => {
|
|
201
|
+
const options = {
|
|
202
|
+
method: "PUT",
|
|
203
|
+
headers: this.settings.baseHeaders,
|
|
204
|
+
hostname: this.settings.hostname,
|
|
205
|
+
path: `/v1/documents/${documentId}/feedback`,
|
|
206
|
+
};
|
|
207
|
+
const req = this.readResponse(options, resolve, reject);
|
|
208
|
+
req.write(JSON.stringify(feedback));
|
|
209
|
+
// potential ECONNRESET if we don't end the request.
|
|
210
|
+
req.end();
|
|
211
|
+
});
|
|
226
212
|
};
|
package/src/http/error.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MindeeError } from "../errors";
|
|
2
2
|
import { StringDict } from "../parsing/common";
|
|
3
|
-
import { EndpointResponse } from "./
|
|
4
|
-
export declare function handleError(
|
|
3
|
+
import { EndpointResponse } from "./baseEndpoint";
|
|
4
|
+
export declare function handleError(urlName: string, response: EndpointResponse, code?: number, serverError?: string): void;
|
|
5
5
|
/**
|
|
6
6
|
* `Error` wrapper for server (HTTP) errors.
|
|
7
7
|
* Is used when an error is lacking a handled error code.
|
|
@@ -13,55 +13,55 @@ export declare class MindeeHttpError extends MindeeError {
|
|
|
13
13
|
details: string | StringDict;
|
|
14
14
|
/** Standard HTTP error code. */
|
|
15
15
|
code?: number;
|
|
16
|
-
constructor(httpError: StringDict,
|
|
16
|
+
constructor(httpError: StringDict, urlName: string, code?: number);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Generic client errors.
|
|
20
20
|
* Can include errors like InvalidQuery.
|
|
21
21
|
*/
|
|
22
22
|
export declare class MindeeHttp400Error extends MindeeHttpError {
|
|
23
|
-
constructor(httpError: StringDict,
|
|
23
|
+
constructor(httpError: StringDict, urlName: string, code?: number);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Can include errors like NoTokenSet or InvalidToken.
|
|
27
27
|
*/
|
|
28
28
|
export declare class MindeeHttp401Error extends MindeeHttpError {
|
|
29
|
-
constructor(httpError: StringDict,
|
|
29
|
+
constructor(httpError: StringDict, urlName: string, code?: number);
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Regular AccessForbidden error.
|
|
33
33
|
* Can also include errors like PlanLimitReached, AsyncRequestDisallowed or SyncRequestDisallowed.
|
|
34
34
|
*/
|
|
35
35
|
export declare class MindeeHttp403Error extends MindeeHttpError {
|
|
36
|
-
constructor(httpError: StringDict,
|
|
36
|
+
constructor(httpError: StringDict, urlName: string, code?: number);
|
|
37
37
|
}
|
|
38
38
|
export declare class MindeeHttp404Error extends MindeeHttpError {
|
|
39
|
-
constructor(httpError: StringDict,
|
|
39
|
+
constructor(httpError: StringDict, urlName: string, code?: number);
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Rare error.
|
|
43
43
|
* Can occasionally happen when unusually large documents are passed.
|
|
44
44
|
*/
|
|
45
45
|
export declare class MindeeHttp413Error extends MindeeHttpError {
|
|
46
|
-
constructor(httpError: StringDict,
|
|
46
|
+
constructor(httpError: StringDict, urlName: string, code?: number);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Usually corresponds to TooManyRequests errors.
|
|
50
50
|
* Arises whenever too many calls to the API are made in quick succession.
|
|
51
51
|
*/
|
|
52
52
|
export declare class MindeeHttp429Error extends MindeeHttpError {
|
|
53
|
-
constructor(httpError: StringDict,
|
|
53
|
+
constructor(httpError: StringDict, urlName: string, code?: number);
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* Generic server errors.
|
|
57
57
|
*/
|
|
58
58
|
export declare class MindeeHttp500Error extends MindeeHttpError {
|
|
59
|
-
constructor(httpError: StringDict,
|
|
59
|
+
constructor(httpError: StringDict, urlName: string, code?: number);
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* Miscellaneous server errors.
|
|
63
63
|
* Can include errors like RequestTimeout or GatewayTimeout.
|
|
64
64
|
*/
|
|
65
65
|
export declare class MindeeHttp504Error extends MindeeHttpError {
|
|
66
|
-
constructor(httpError: StringDict,
|
|
66
|
+
constructor(httpError: StringDict, urlName: string, code?: number);
|
|
67
67
|
}
|
package/src/http/error.js
CHANGED
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MindeeHttp504Error = exports.MindeeHttp500Error = exports.MindeeHttp429Error = exports.MindeeHttp413Error = exports.MindeeHttp404Error = exports.MindeeHttp403Error = exports.MindeeHttp401Error = exports.MindeeHttp400Error = exports.MindeeHttpError = exports.handleError = void 0;
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
5
|
const handler_1 = require("../errors/handler");
|
|
6
|
-
function handleError(
|
|
6
|
+
function handleError(urlName, response, code, serverError) {
|
|
7
7
|
if (code === undefined) {
|
|
8
|
-
throw new MindeeHttpError({ message: "Missing HTTP Error code.", details: response.data, undefined },
|
|
8
|
+
throw new MindeeHttpError({ message: "Missing HTTP Error code.", details: response.data, undefined }, urlName);
|
|
9
9
|
}
|
|
10
10
|
let errorObj;
|
|
11
11
|
try {
|
|
@@ -69,31 +69,31 @@ function handleError(url, response, code, serverError) {
|
|
|
69
69
|
let errorToThrow;
|
|
70
70
|
switch (code) {
|
|
71
71
|
case 400:
|
|
72
|
-
errorToThrow = new MindeeHttp400Error(errorObj,
|
|
72
|
+
errorToThrow = new MindeeHttp400Error(errorObj, urlName, code);
|
|
73
73
|
break;
|
|
74
74
|
case 401:
|
|
75
|
-
errorToThrow = new MindeeHttp401Error(errorObj,
|
|
75
|
+
errorToThrow = new MindeeHttp401Error(errorObj, urlName, code);
|
|
76
76
|
break;
|
|
77
77
|
case 403:
|
|
78
|
-
errorToThrow = new MindeeHttp403Error(errorObj,
|
|
78
|
+
errorToThrow = new MindeeHttp403Error(errorObj, urlName, code);
|
|
79
79
|
break;
|
|
80
80
|
case 404:
|
|
81
|
-
errorToThrow = new MindeeHttp404Error(errorObj,
|
|
81
|
+
errorToThrow = new MindeeHttp404Error(errorObj, urlName, code);
|
|
82
82
|
break;
|
|
83
83
|
case 413:
|
|
84
|
-
errorToThrow = new MindeeHttp413Error(errorObj,
|
|
84
|
+
errorToThrow = new MindeeHttp413Error(errorObj, urlName, code);
|
|
85
85
|
break;
|
|
86
86
|
case 429:
|
|
87
|
-
errorToThrow = new MindeeHttp429Error(errorObj,
|
|
87
|
+
errorToThrow = new MindeeHttp429Error(errorObj, urlName, code);
|
|
88
88
|
break;
|
|
89
89
|
case 500:
|
|
90
|
-
errorToThrow = new MindeeHttp500Error(errorObj,
|
|
90
|
+
errorToThrow = new MindeeHttp500Error(errorObj, urlName, code);
|
|
91
91
|
break;
|
|
92
92
|
case 504:
|
|
93
|
-
errorToThrow = new MindeeHttp504Error(errorObj,
|
|
93
|
+
errorToThrow = new MindeeHttp504Error(errorObj, urlName, code);
|
|
94
94
|
break;
|
|
95
95
|
default:
|
|
96
|
-
errorToThrow = new MindeeHttpError(errorObj,
|
|
96
|
+
errorToThrow = new MindeeHttpError(errorObj, urlName, code);
|
|
97
97
|
break;
|
|
98
98
|
}
|
|
99
99
|
handler_1.errorHandler.throw(errorToThrow);
|
|
@@ -104,8 +104,8 @@ exports.handleError = handleError;
|
|
|
104
104
|
* Is used when an error is lacking a handled error code.
|
|
105
105
|
*/
|
|
106
106
|
class MindeeHttpError extends errors_1.MindeeError {
|
|
107
|
-
constructor(httpError,
|
|
108
|
-
super(`${
|
|
107
|
+
constructor(httpError, urlName, code) {
|
|
108
|
+
super(`${urlName} API ${code} HTTP error: ${httpError.message}`);
|
|
109
109
|
/** Description of the error. */
|
|
110
110
|
this.message = "";
|
|
111
111
|
/** Additional details on the error. */
|
|
@@ -122,8 +122,8 @@ exports.MindeeHttpError = MindeeHttpError;
|
|
|
122
122
|
* Can include errors like InvalidQuery.
|
|
123
123
|
*/
|
|
124
124
|
class MindeeHttp400Error extends MindeeHttpError {
|
|
125
|
-
constructor(httpError,
|
|
126
|
-
super(httpError,
|
|
125
|
+
constructor(httpError, urlName, code) {
|
|
126
|
+
super(httpError, urlName, code);
|
|
127
127
|
this.name = "MindeeHttp400Error";
|
|
128
128
|
}
|
|
129
129
|
}
|
|
@@ -132,8 +132,8 @@ exports.MindeeHttp400Error = MindeeHttp400Error;
|
|
|
132
132
|
* Can include errors like NoTokenSet or InvalidToken.
|
|
133
133
|
*/
|
|
134
134
|
class MindeeHttp401Error extends MindeeHttpError {
|
|
135
|
-
constructor(httpError,
|
|
136
|
-
super(httpError,
|
|
135
|
+
constructor(httpError, urlName, code) {
|
|
136
|
+
super(httpError, urlName, code);
|
|
137
137
|
this.name = "MindeeHttp401Error";
|
|
138
138
|
}
|
|
139
139
|
}
|
|
@@ -143,15 +143,15 @@ exports.MindeeHttp401Error = MindeeHttp401Error;
|
|
|
143
143
|
* Can also include errors like PlanLimitReached, AsyncRequestDisallowed or SyncRequestDisallowed.
|
|
144
144
|
*/
|
|
145
145
|
class MindeeHttp403Error extends MindeeHttpError {
|
|
146
|
-
constructor(httpError,
|
|
147
|
-
super(httpError,
|
|
146
|
+
constructor(httpError, urlName, code) {
|
|
147
|
+
super(httpError, urlName, code);
|
|
148
148
|
this.name = "MindeeHttp403Error";
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
exports.MindeeHttp403Error = MindeeHttp403Error;
|
|
152
152
|
class MindeeHttp404Error extends MindeeHttpError {
|
|
153
|
-
constructor(httpError,
|
|
154
|
-
super(httpError,
|
|
153
|
+
constructor(httpError, urlName, code) {
|
|
154
|
+
super(httpError, urlName, code);
|
|
155
155
|
this.name = "MindeeHttp404Error";
|
|
156
156
|
}
|
|
157
157
|
}
|
|
@@ -161,8 +161,8 @@ exports.MindeeHttp404Error = MindeeHttp404Error;
|
|
|
161
161
|
* Can occasionally happen when unusually large documents are passed.
|
|
162
162
|
*/
|
|
163
163
|
class MindeeHttp413Error extends MindeeHttpError {
|
|
164
|
-
constructor(httpError,
|
|
165
|
-
super(httpError,
|
|
164
|
+
constructor(httpError, urlName, code) {
|
|
165
|
+
super(httpError, urlName, code);
|
|
166
166
|
this.name = "MindeeHttp413Error";
|
|
167
167
|
}
|
|
168
168
|
}
|
|
@@ -172,8 +172,8 @@ exports.MindeeHttp413Error = MindeeHttp413Error;
|
|
|
172
172
|
* Arises whenever too many calls to the API are made in quick succession.
|
|
173
173
|
*/
|
|
174
174
|
class MindeeHttp429Error extends MindeeHttpError {
|
|
175
|
-
constructor(httpError,
|
|
176
|
-
super(httpError,
|
|
175
|
+
constructor(httpError, urlName, code) {
|
|
176
|
+
super(httpError, urlName, code);
|
|
177
177
|
this.name = "MindeeHttp429Error";
|
|
178
178
|
}
|
|
179
179
|
}
|
|
@@ -182,8 +182,8 @@ exports.MindeeHttp429Error = MindeeHttp429Error;
|
|
|
182
182
|
* Generic server errors.
|
|
183
183
|
*/
|
|
184
184
|
class MindeeHttp500Error extends MindeeHttpError {
|
|
185
|
-
constructor(httpError,
|
|
186
|
-
super(httpError,
|
|
185
|
+
constructor(httpError, urlName, code) {
|
|
186
|
+
super(httpError, urlName, code);
|
|
187
187
|
this.name = "MindeeHttp500Error";
|
|
188
188
|
}
|
|
189
189
|
}
|
|
@@ -193,8 +193,8 @@ exports.MindeeHttp500Error = MindeeHttp500Error;
|
|
|
193
193
|
* Can include errors like RequestTimeout or GatewayTimeout.
|
|
194
194
|
*/
|
|
195
195
|
class MindeeHttp504Error extends MindeeHttpError {
|
|
196
|
-
constructor(httpError,
|
|
197
|
-
super(httpError,
|
|
196
|
+
constructor(httpError, urlName, code) {
|
|
197
|
+
super(httpError, urlName, code);
|
|
198
198
|
this.name = "MindeeHttp504Error";
|
|
199
199
|
}
|
|
200
200
|
}
|
package/src/http/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { Endpoint
|
|
2
|
-
export {
|
|
1
|
+
export { Endpoint } from "./endpoint";
|
|
2
|
+
export { EndpointResponse } from "./baseEndpoint";
|
|
3
|
+
export { STANDARD_API_OWNER, API_KEY_ENVVAR_NAME, ApiSettings, } from "./apiSettings";
|
|
3
4
|
export { MindeeHttpError, MindeeHttp400Error, MindeeHttp401Error, MindeeHttp403Error, MindeeHttp404Error, MindeeHttp413Error, MindeeHttp429Error, MindeeHttp500Error, MindeeHttp504Error, handleError, } from "./error";
|
package/src/http/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleError = exports.MindeeHttp504Error = exports.MindeeHttp500Error = exports.MindeeHttp429Error = exports.MindeeHttp413Error = exports.MindeeHttp404Error = exports.MindeeHttp403Error = exports.MindeeHttp401Error = exports.MindeeHttp400Error = exports.MindeeHttpError = exports.
|
|
3
|
+
exports.handleError = exports.MindeeHttp504Error = exports.MindeeHttp500Error = exports.MindeeHttp429Error = exports.MindeeHttp413Error = exports.MindeeHttp404Error = exports.MindeeHttp403Error = exports.MindeeHttp401Error = exports.MindeeHttp400Error = exports.MindeeHttpError = exports.ApiSettings = exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = exports.Endpoint = void 0;
|
|
4
4
|
var endpoint_1 = require("./endpoint");
|
|
5
5
|
Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return endpoint_1.Endpoint; } });
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "STANDARD_API_OWNER", { enumerable: true, get: function () { return
|
|
8
|
-
Object.defineProperty(exports, "API_KEY_ENVVAR_NAME", { enumerable: true, get: function () { return
|
|
9
|
-
Object.defineProperty(exports, "
|
|
6
|
+
var apiSettings_1 = require("./apiSettings");
|
|
7
|
+
Object.defineProperty(exports, "STANDARD_API_OWNER", { enumerable: true, get: function () { return apiSettings_1.STANDARD_API_OWNER; } });
|
|
8
|
+
Object.defineProperty(exports, "API_KEY_ENVVAR_NAME", { enumerable: true, get: function () { return apiSettings_1.API_KEY_ENVVAR_NAME; } });
|
|
9
|
+
Object.defineProperty(exports, "ApiSettings", { enumerable: true, get: function () { return apiSettings_1.ApiSettings; } });
|
|
10
10
|
var error_1 = require("./error");
|
|
11
11
|
Object.defineProperty(exports, "MindeeHttpError", { enumerable: true, get: function () { return error_1.MindeeHttpError; } });
|
|
12
12
|
Object.defineProperty(exports, "MindeeHttp400Error", { enumerable: true, get: function () { return error_1.MindeeHttp400Error; } });
|
package/src/input/base.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { PageOptions } from "./pageOptions";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} inputType - the type of input used in file ("base64", "path", "dummy").
|
|
5
|
+
* NB: dummy is only used for tests purposes
|
|
6
|
+
*/
|
|
7
|
+
interface InputConstructor {
|
|
4
8
|
inputType: string;
|
|
5
9
|
}
|
|
6
10
|
export declare const INPUT_TYPE_STREAM = "stream";
|
|
@@ -19,12 +23,9 @@ export declare abstract class LocalInputSource extends InputSource {
|
|
|
19
23
|
mimeType: string;
|
|
20
24
|
fileObject: Buffer | string;
|
|
21
25
|
/**
|
|
22
|
-
* @param {
|
|
23
|
-
* NB: dummy is only used for tests purposes
|
|
24
|
-
* @param {Boolean} cutPages
|
|
25
|
-
* NB: Because of async calls, init() should be called after creating the object
|
|
26
|
+
* @param {InputConstructor} constructor Constructor parameters.
|
|
26
27
|
*/
|
|
27
|
-
constructor({ inputType }:
|
|
28
|
+
protected constructor({ inputType }: InputConstructor);
|
|
28
29
|
isPdf(): boolean;
|
|
29
30
|
checkMimetype(): Promise<string>;
|
|
30
31
|
/**
|
package/src/input/base.js
CHANGED
|
@@ -62,10 +62,7 @@ class InputSource {
|
|
|
62
62
|
exports.InputSource = InputSource;
|
|
63
63
|
class LocalInputSource extends InputSource {
|
|
64
64
|
/**
|
|
65
|
-
* @param {
|
|
66
|
-
* NB: dummy is only used for tests purposes
|
|
67
|
-
* @param {Boolean} cutPages
|
|
68
|
-
* NB: Because of async calls, init() should be called after creating the object
|
|
65
|
+
* @param {InputConstructor} constructor Constructor parameters.
|
|
69
66
|
*/
|
|
70
67
|
constructor({ inputType }) {
|
|
71
68
|
super();
|
|
@@ -6,7 +6,7 @@ import { Document } from "./document";
|
|
|
6
6
|
*
|
|
7
7
|
* @category API Response
|
|
8
8
|
* @category Asynchronous
|
|
9
|
-
*/
|
|
9
|
+
*/
|
|
10
10
|
export declare class Job {
|
|
11
11
|
/** Timestamp noting the enqueueing of a document. */
|
|
12
12
|
issuedAt: Date;
|
|
@@ -25,7 +25,7 @@ export declare class Job {
|
|
|
25
25
|
*
|
|
26
26
|
* @category API Response
|
|
27
27
|
* @category Asynchronous
|
|
28
|
-
*/
|
|
28
|
+
*/
|
|
29
29
|
export declare class AsyncPredictResponse<T extends Inference> extends ApiResponse {
|
|
30
30
|
/** Job for a queue. */
|
|
31
31
|
job: Job;
|
|
@@ -36,7 +36,7 @@ export declare class AsyncPredictResponse<T extends Inference> extends ApiRespon
|
|
|
36
36
|
/**
|
|
37
37
|
*
|
|
38
38
|
* @param inferenceClass constructor signature for an inference.
|
|
39
|
-
* @param
|
|
39
|
+
* @param serverResponse raw http response.
|
|
40
40
|
*/
|
|
41
|
-
constructor(inferenceClass: new (httpResponse: StringDict) => T,
|
|
41
|
+
constructor(inferenceClass: new (httpResponse: StringDict) => T, serverResponse: StringDict);
|
|
42
42
|
}
|
|
@@ -7,7 +7,7 @@ const document_1 = require("./document");
|
|
|
7
7
|
*
|
|
8
8
|
* @category API Response
|
|
9
9
|
* @category Asynchronous
|
|
10
|
-
*/
|
|
10
|
+
*/
|
|
11
11
|
class Job {
|
|
12
12
|
constructor(jsonResponse) {
|
|
13
13
|
this.issuedAt = this.datetimeWithTimezone(jsonResponse["issued_at"]);
|
|
@@ -35,19 +35,19 @@ exports.Job = Job;
|
|
|
35
35
|
*
|
|
36
36
|
* @category API Response
|
|
37
37
|
* @category Asynchronous
|
|
38
|
-
*/
|
|
38
|
+
*/
|
|
39
39
|
class AsyncPredictResponse extends apiResponse_1.ApiResponse {
|
|
40
40
|
/**
|
|
41
41
|
*
|
|
42
42
|
* @param inferenceClass constructor signature for an inference.
|
|
43
|
-
* @param
|
|
43
|
+
* @param serverResponse raw http response.
|
|
44
44
|
*/
|
|
45
|
-
constructor(inferenceClass,
|
|
46
|
-
super(
|
|
47
|
-
this.job = new Job(
|
|
45
|
+
constructor(inferenceClass, serverResponse) {
|
|
46
|
+
super(serverResponse);
|
|
47
|
+
this.job = new Job(serverResponse["job"]);
|
|
48
48
|
this.document =
|
|
49
|
-
|
|
50
|
-
? new document_1.Document(inferenceClass,
|
|
49
|
+
serverResponse["document"] !== undefined
|
|
50
|
+
? new document_1.Document(inferenceClass, serverResponse["document"])
|
|
51
51
|
: undefined;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiResponse } from "../apiResponse";
|
|
2
|
+
import { StringDict } from "../stringDict";
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper for feedback response.
|
|
5
|
+
* @category API Response
|
|
6
|
+
* @category Synchronous
|
|
7
|
+
*/
|
|
8
|
+
export declare class FeedbackResponse extends ApiResponse {
|
|
9
|
+
/** A document feedback response. */
|
|
10
|
+
feedback: StringDict;
|
|
11
|
+
/**
|
|
12
|
+
* @param serverResponse JSON response from the server.
|
|
13
|
+
*/
|
|
14
|
+
constructor(serverResponse: StringDict);
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FeedbackResponse = void 0;
|
|
4
|
+
const apiResponse_1 = require("../apiResponse");
|
|
5
|
+
/**
|
|
6
|
+
* Wrapper for feedback response.
|
|
7
|
+
* @category API Response
|
|
8
|
+
* @category Synchronous
|
|
9
|
+
*/
|
|
10
|
+
class FeedbackResponse extends apiResponse_1.ApiResponse {
|
|
11
|
+
/**
|
|
12
|
+
* @param serverResponse JSON response from the server.
|
|
13
|
+
*/
|
|
14
|
+
constructor(serverResponse) {
|
|
15
|
+
super(serverResponse);
|
|
16
|
+
this.feedback = serverResponse["feedback"];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.FeedbackResponse = FeedbackResponse;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lineSeparator = exports.cleanOutString = exports.Page = exports.Prediction = exports.PredictResponse = exports.AsyncPredictResponse = exports.Inference = exports.OrientationField = exports.Document = void 0;
|
|
3
|
+
exports.lineSeparator = exports.cleanOutString = exports.Page = exports.Prediction = exports.PredictResponse = exports.AsyncPredictResponse = exports.Inference = exports.OrientationField = exports.FeedbackResponse = exports.Document = void 0;
|
|
4
4
|
var document_1 = require("./document");
|
|
5
5
|
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
|
|
6
|
+
var feedbackResponse_1 = require("./feedback/feedbackResponse");
|
|
7
|
+
Object.defineProperty(exports, "FeedbackResponse", { enumerable: true, get: function () { return feedbackResponse_1.FeedbackResponse; } });
|
|
6
8
|
var orientation_1 = require("./orientation");
|
|
7
9
|
Object.defineProperty(exports, "OrientationField", { enumerable: true, get: function () { return orientation_1.OrientationField; } });
|
|
8
10
|
var inference_1 = require("./inference");
|
|
@@ -21,6 +21,14 @@ class Inference {
|
|
|
21
21
|
* Default string representation.
|
|
22
22
|
*/
|
|
23
23
|
toString() {
|
|
24
|
+
let pages = "";
|
|
25
|
+
if (this.pages.toString().length > 0) {
|
|
26
|
+
pages = `
|
|
27
|
+
Page Predictions
|
|
28
|
+
================
|
|
29
|
+
|
|
30
|
+
${this.pages.map((e) => e.toString() || "").join("\n")}`;
|
|
31
|
+
}
|
|
24
32
|
return `Inference
|
|
25
33
|
#########
|
|
26
34
|
:Product: ${this.product.name} v${this.product.version}
|
|
@@ -28,11 +36,7 @@ class Inference {
|
|
|
28
36
|
|
|
29
37
|
Prediction
|
|
30
38
|
==========
|
|
31
|
-
${this.prediction.toString().length === 0 ? "" : this.prediction.toString() + "\n"}
|
|
32
|
-
Page Predictions
|
|
33
|
-
================
|
|
34
|
-
|
|
35
|
-
${this.pages.map((e) => e.toString() || "").join("\n")}`;
|
|
39
|
+
${this.prediction.toString().length === 0 ? "" : this.prediction.toString() + "\n"}${pages}`;
|
|
36
40
|
}
|
|
37
41
|
/**
|
|
38
42
|
* Takes in an input string and replaces line breaks with `\n`.
|
|
@@ -11,10 +11,7 @@ export declare class OrientationField extends BaseField {
|
|
|
11
11
|
/** Page id. */
|
|
12
12
|
pageId: number;
|
|
13
13
|
/**
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {String} valueKey - Key to use in the prediction dict
|
|
16
|
-
* @param {Boolean} reconstructed - Is the object reconstructed (not extracted by the API)
|
|
17
|
-
* @param {Integer} pageId - Page ID for multi-page document
|
|
14
|
+
* @param {OrientationFieldConstructor} constructor Constructor parameters.
|
|
18
15
|
*/
|
|
19
16
|
constructor({ prediction, valueKey, reconstructed, pageId, }: OrientationFieldConstructor);
|
|
20
17
|
/**
|
|
@@ -7,10 +7,7 @@ const standard_1 = require("../standard");
|
|
|
7
7
|
*/
|
|
8
8
|
class OrientationField extends standard_1.BaseField {
|
|
9
9
|
/**
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {String} valueKey - Key to use in the prediction dict
|
|
12
|
-
* @param {Boolean} reconstructed - Is the object reconstructed (not extracted by the API)
|
|
13
|
-
* @param {Integer} pageId - Page ID for multi-page document
|
|
10
|
+
* @param {OrientationFieldConstructor} constructor Constructor parameters.
|
|
14
11
|
*/
|
|
15
12
|
constructor({ prediction = {}, valueKey = "value", reconstructed = false, pageId, }) {
|
|
16
13
|
super({ prediction, valueKey, reconstructed });
|