mindee 4.18.1 → 4.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/package.json +1 -1
- package/src/client.d.ts +44 -9
- package/src/client.js +24 -0
- package/src/http/apiSettings.d.ts +2 -0
- package/src/http/apiSettings.js +3 -1
- package/src/http/baseEndpoint.d.ts +10 -1
- package/src/http/baseEndpoint.js +13 -1
- package/src/http/endpoint.d.ts +3 -11
- package/src/http/endpoint.js +26 -22
- package/src/http/error.js +1 -1
- package/src/http/httpParams.d.ts +17 -0
- package/src/http/httpParams.js +2 -0
- package/src/http/index.d.ts +1 -0
- package/src/http/responseValidation.js +6 -0
- package/src/http/workflowEndpoint.d.ts +29 -0
- package/src/http/workflowEndpoint.js +99 -0
- package/src/parsing/common/asyncPredictResponse.d.ts +1 -1
- package/src/parsing/common/asyncPredictResponse.js +10 -9
- package/src/parsing/common/execution.d.ts +39 -0
- package/src/parsing/common/execution.js +32 -0
- package/src/parsing/common/executionFile.d.ts +12 -0
- package/src/parsing/common/executionFile.js +14 -0
- package/src/parsing/common/executionPriority.d.ts +5 -0
- package/src/parsing/common/executionPriority.js +9 -0
- package/src/parsing/common/index.d.ts +4 -1
- package/src/parsing/common/index.js +9 -3
- package/src/parsing/common/workflowResponse.d.ts +17 -0
- package/src/parsing/common/workflowResponse.js +17 -0
- package/src/product/index.d.ts +0 -1
- package/src/product/index.js +1 -3
- package/src/product/internationalId/internal.d.ts +0 -2
- package/src/product/internationalId/internal.js +1 -5
- package/src/product/internationalId/internationalIdV1.d.ts +0 -16
- package/src/product/internationalId/internationalIdV1.js +0 -27
- package/src/product/internationalId/internationalIdV1Document.d.ts +0 -42
- package/src/product/internationalId/internationalIdV1Document.js +0 -101
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v4.19.0 - 2024-11-27
|
|
4
|
+
### Changes
|
|
5
|
+
* :coffin: remove support for international ID V1
|
|
6
|
+
* :sparkles: add support for workflows
|
|
7
|
+
* :sparkles: add configurable http request timeout
|
|
8
|
+
### Fixes
|
|
9
|
+
* :bug: fix http errors improperly showing as 500 in rare instances
|
|
10
|
+
|
|
11
|
+
|
|
3
12
|
## v4.18.1 - 2024-11-19
|
|
4
13
|
### Fixes
|
|
5
14
|
* :bug: fix composed API server response not properly filling full_text_ocr in pages
|
package/package.json
CHANGED
package/src/client.d.ts
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import { Readable } from "stream";
|
|
2
2
|
import { Base64Input, BufferInput, BytesInput, InputSource, LocalResponse, PageOptions, PathInput, StreamInput, UrlInput } from "./input";
|
|
3
3
|
import { Endpoint } from "./http";
|
|
4
|
-
import { AsyncPredictResponse, FeedbackResponse, Inference, PredictResponse, StringDict } from "./parsing/common";
|
|
4
|
+
import { AsyncPredictResponse, ExecutionPriority, FeedbackResponse, Inference, PredictResponse, StringDict } from "./parsing/common";
|
|
5
|
+
import { GeneratedV1 } from "./product";
|
|
6
|
+
import { WorkflowResponse } from "./parsing/common/workflowResponse";
|
|
7
|
+
/**
|
|
8
|
+
* Common options for workflows & predictions.
|
|
9
|
+
*/
|
|
10
|
+
interface BaseOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Whether to include the full ocr text. Only available on compatible APIs.
|
|
13
|
+
*/
|
|
14
|
+
fullText?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* If set, remove pages from the document as specified.
|
|
17
|
+
* This is done before sending the file to the server and is useful to avoid page limitations.
|
|
18
|
+
*/
|
|
19
|
+
pageOptions?: PageOptions;
|
|
20
|
+
}
|
|
5
21
|
/**
|
|
6
22
|
* Options relating to predictions.
|
|
7
23
|
*/
|
|
8
|
-
export interface PredictOptions {
|
|
24
|
+
export interface PredictOptions extends BaseOptions {
|
|
9
25
|
/** A custom endpoint. */
|
|
10
26
|
endpoint?: Endpoint;
|
|
11
27
|
/**
|
|
@@ -14,19 +30,28 @@ export interface PredictOptions {
|
|
|
14
30
|
* This performs a full OCR operation on the server and will increase response time.
|
|
15
31
|
*/
|
|
16
32
|
allWords?: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Whether to include the full ocr text. Only available on compatible APIs.
|
|
19
|
-
*/
|
|
20
|
-
fullText?: boolean;
|
|
21
33
|
/**
|
|
22
34
|
* Whether to include cropper results for each page.
|
|
23
35
|
*/
|
|
24
36
|
cropper?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Options relating to workflows.
|
|
40
|
+
* @category Workflow
|
|
41
|
+
*/
|
|
42
|
+
export interface WorkflowOptions extends BaseOptions {
|
|
25
43
|
/**
|
|
26
|
-
*
|
|
27
|
-
* This is done before sending the file to the server and is useful to avoid page limitations.
|
|
44
|
+
* Alias to give to the document.
|
|
28
45
|
*/
|
|
29
|
-
|
|
46
|
+
alias?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Priority to give to the document.
|
|
49
|
+
*/
|
|
50
|
+
priority?: ExecutionPriority;
|
|
51
|
+
/**
|
|
52
|
+
* A unique, encrypted URL for accessing the document validation interface without requiring authentication.
|
|
53
|
+
*/
|
|
54
|
+
publicUrl?: string;
|
|
30
55
|
}
|
|
31
56
|
/**
|
|
32
57
|
* Asynchronous polling parameters.
|
|
@@ -111,6 +136,15 @@ export declare class Client {
|
|
|
111
136
|
*/
|
|
112
137
|
parseQueued<T extends Inference>(productClass: new (httpResponse: StringDict) => T, queueId: string, params?: PredictOptions): Promise<AsyncPredictResponse<T>>;
|
|
113
138
|
loadPrediction<T extends Inference>(productClass: new (httpResponse: StringDict) => T, localResponse: LocalResponse): Promise<AsyncPredictResponse<T> | PredictResponse<T>>;
|
|
139
|
+
/**
|
|
140
|
+
* Send the document to an asynchronous endpoint and return its ID in the queue.
|
|
141
|
+
* @param inputSource file to send to the API.
|
|
142
|
+
* @param workflowId ID of the workflow.
|
|
143
|
+
* @param params parameters relating to prediction options.
|
|
144
|
+
* @category Workflow
|
|
145
|
+
* @returns a `Promise` containing the job (queue) corresponding to a document.
|
|
146
|
+
*/
|
|
147
|
+
executeWorkflow(inputSource: InputSource, workflowId: string, params?: WorkflowOptions): Promise<WorkflowResponse<GeneratedV1>>;
|
|
114
148
|
/**
|
|
115
149
|
* Fetch prediction results from a document already processed.
|
|
116
150
|
*
|
|
@@ -204,3 +238,4 @@ export declare class Client {
|
|
|
204
238
|
*/
|
|
205
239
|
docFromBuffer(buffer: Buffer, filename: string): BufferInput;
|
|
206
240
|
}
|
|
241
|
+
export {};
|
package/src/client.js
CHANGED
|
@@ -16,6 +16,8 @@ const inference_1 = require("./parsing/common/inference");
|
|
|
16
16
|
const product_1 = require("./product");
|
|
17
17
|
const promises_1 = require("node:timers/promises");
|
|
18
18
|
const errors_1 = require("./errors");
|
|
19
|
+
const workflowResponse_1 = require("./parsing/common/workflowResponse");
|
|
20
|
+
const workflowEndpoint_1 = require("./http/workflowEndpoint");
|
|
19
21
|
/**
|
|
20
22
|
* Mindee Client class that centralizes most basic operations.
|
|
21
23
|
*
|
|
@@ -126,6 +128,28 @@ class Client {
|
|
|
126
128
|
throw new errors_1.MindeeError("No prediction found in local response.");
|
|
127
129
|
}
|
|
128
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Send the document to an asynchronous endpoint and return its ID in the queue.
|
|
133
|
+
* @param inputSource file to send to the API.
|
|
134
|
+
* @param workflowId ID of the workflow.
|
|
135
|
+
* @param params parameters relating to prediction options.
|
|
136
|
+
* @category Workflow
|
|
137
|
+
* @returns a `Promise` containing the job (queue) corresponding to a document.
|
|
138
|
+
*/
|
|
139
|
+
async executeWorkflow(inputSource, workflowId, params = {}) {
|
|
140
|
+
const workflowEndpoint = new workflowEndpoint_1.WorkflowEndpoint(__classPrivateFieldGet(this, _Client_instances, "m", _Client_buildApiSettings).call(this), workflowId);
|
|
141
|
+
if (inputSource === undefined) {
|
|
142
|
+
throw new Error("The 'parse' function requires an input document.");
|
|
143
|
+
}
|
|
144
|
+
const rawResponse = await workflowEndpoint.executeWorkflow({
|
|
145
|
+
inputDoc: inputSource,
|
|
146
|
+
alias: params.alias,
|
|
147
|
+
priority: params.priority,
|
|
148
|
+
pageOptions: params?.pageOptions,
|
|
149
|
+
fullText: this.getBooleanParam(params.fullText),
|
|
150
|
+
});
|
|
151
|
+
return new workflowResponse_1.WorkflowResponse(product_1.GeneratedV1, rawResponse.data);
|
|
152
|
+
}
|
|
129
153
|
/**
|
|
130
154
|
* Fetch prediction results from a document already processed.
|
|
131
155
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const API_KEY_ENVVAR_NAME: string;
|
|
2
2
|
export declare const API_HOST_ENVVAR_NAME: string;
|
|
3
3
|
export declare const STANDARD_API_OWNER: string;
|
|
4
|
+
export declare const TIMEOUT_DEFAULT: number;
|
|
4
5
|
interface MindeeApiConstructorProps {
|
|
5
6
|
apiKey: string;
|
|
6
7
|
}
|
|
@@ -8,6 +9,7 @@ export declare class ApiSettings {
|
|
|
8
9
|
apiKey: string;
|
|
9
10
|
baseHeaders: Record<string, string>;
|
|
10
11
|
hostname: string;
|
|
12
|
+
timeout: number;
|
|
11
13
|
constructor({ apiKey, }: MindeeApiConstructorProps);
|
|
12
14
|
protected apiKeyFromEnv(): string;
|
|
13
15
|
protected hostnameFromEnv(): string;
|
package/src/http/apiSettings.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ApiSettings = exports.STANDARD_API_OWNER = exports.API_HOST_ENVVAR_NAME = exports.API_KEY_ENVVAR_NAME = void 0;
|
|
26
|
+
exports.ApiSettings = exports.TIMEOUT_DEFAULT = exports.STANDARD_API_OWNER = exports.API_HOST_ENVVAR_NAME = exports.API_KEY_ENVVAR_NAME = void 0;
|
|
27
27
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
28
28
|
const logger_1 = require("../logger");
|
|
29
29
|
const package_json_1 = require("../../package.json");
|
|
@@ -31,6 +31,7 @@ const os = __importStar(require("os"));
|
|
|
31
31
|
exports.API_KEY_ENVVAR_NAME = "MINDEE_API_KEY";
|
|
32
32
|
exports.API_HOST_ENVVAR_NAME = "MINDEE_API_HOST";
|
|
33
33
|
exports.STANDARD_API_OWNER = "mindee";
|
|
34
|
+
exports.TIMEOUT_DEFAULT = 120;
|
|
34
35
|
const DEFAULT_MINDEE_API_HOST = "api.mindee.net";
|
|
35
36
|
const USER_AGENT = `mindee-api-nodejs@v${package_json_1.version} nodejs-${process.version} ${os.type().toLowerCase()}`;
|
|
36
37
|
class ApiSettings {
|
|
@@ -50,6 +51,7 @@ class ApiSettings {
|
|
|
50
51
|
Authorization: `Token ${this.apiKey}`,
|
|
51
52
|
};
|
|
52
53
|
this.hostname = this.hostnameFromEnv();
|
|
54
|
+
this.timeout = process.env.MINDEE_REQUEST_TIMEOUT ? parseInt(process.env.MINDEE_REQUEST_TIMEOUT) : exports.TIMEOUT_DEFAULT;
|
|
53
55
|
}
|
|
54
56
|
apiKeyFromEnv() {
|
|
55
57
|
const envVarValue = process.env[exports.API_KEY_ENVVAR_NAME];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ApiSettings } from "./apiSettings";
|
|
2
2
|
import { IncomingMessage, ClientRequest } from "http";
|
|
3
3
|
import { RequestOptions } from "https";
|
|
4
|
+
import { InputSource, PageOptions } from "../input";
|
|
4
5
|
export interface EndpointResponse {
|
|
5
6
|
messageObj: IncomingMessage;
|
|
6
7
|
data: {
|
|
@@ -13,7 +14,15 @@ export interface EndpointResponse {
|
|
|
13
14
|
export declare abstract class BaseEndpoint {
|
|
14
15
|
/** Settings relating to the API. */
|
|
15
16
|
settings: ApiSettings;
|
|
16
|
-
|
|
17
|
+
/** Entire root of the URL for API calls. */
|
|
18
|
+
urlRoot: string;
|
|
19
|
+
protected constructor(settings: ApiSettings, urlRoot: string);
|
|
20
|
+
/**
|
|
21
|
+
* Cuts a document's pages according to the given options.
|
|
22
|
+
* @param inputDoc input document.
|
|
23
|
+
* @param pageOptions page cutting options.
|
|
24
|
+
*/
|
|
25
|
+
protected cutDocPages(inputDoc: InputSource, pageOptions: PageOptions): Promise<void>;
|
|
17
26
|
/**
|
|
18
27
|
* Reads a response from the API and processes it.
|
|
19
28
|
* @param options options related to the request itself.
|
package/src/http/baseEndpoint.js
CHANGED
|
@@ -3,12 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseEndpoint = void 0;
|
|
4
4
|
const logger_1 = require("../logger");
|
|
5
5
|
const https_1 = require("https");
|
|
6
|
+
const base_1 = require("../input/base");
|
|
6
7
|
/**
|
|
7
8
|
* Base endpoint for the Mindee API.
|
|
8
9
|
*/
|
|
9
10
|
class BaseEndpoint {
|
|
10
|
-
constructor(settings) {
|
|
11
|
+
constructor(settings, urlRoot) {
|
|
11
12
|
this.settings = settings;
|
|
13
|
+
this.urlRoot = urlRoot;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Cuts a document's pages according to the given options.
|
|
17
|
+
* @param inputDoc input document.
|
|
18
|
+
* @param pageOptions page cutting options.
|
|
19
|
+
*/
|
|
20
|
+
async cutDocPages(inputDoc, pageOptions) {
|
|
21
|
+
if (inputDoc instanceof base_1.LocalInputSource && inputDoc.isPdf()) {
|
|
22
|
+
await inputDoc.cutPdf(pageOptions);
|
|
23
|
+
}
|
|
12
24
|
}
|
|
13
25
|
/**
|
|
14
26
|
* Reads a response from the API and processes it.
|
package/src/http/endpoint.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { InputSource } from "../input";
|
|
2
|
-
import { PageOptions } from "../input";
|
|
3
2
|
import { ApiSettings } from "./apiSettings";
|
|
4
3
|
import { BaseEndpoint, EndpointResponse } from "./baseEndpoint";
|
|
5
4
|
import { StringDict } from "../parsing/common";
|
|
6
|
-
|
|
7
|
-
inputDoc: InputSource;
|
|
8
|
-
includeWords: boolean;
|
|
9
|
-
fullText: boolean;
|
|
10
|
-
pageOptions?: PageOptions;
|
|
11
|
-
cropper: boolean;
|
|
12
|
-
}
|
|
5
|
+
import { PredictParams } from "./httpParams";
|
|
13
6
|
/**
|
|
14
7
|
* Endpoint for a product (OTS or Custom).
|
|
15
8
|
*/
|
|
@@ -21,11 +14,9 @@ export declare class Endpoint extends BaseEndpoint {
|
|
|
21
14
|
owner: string;
|
|
22
15
|
/** Product's version, as a string. */
|
|
23
16
|
version: string;
|
|
24
|
-
/** Entire root of the URL for API calls. */
|
|
25
|
-
urlRoot: string;
|
|
26
17
|
constructor(urlName: string, owner: string, version: string, settings: ApiSettings);
|
|
27
18
|
/**
|
|
28
|
-
* Sends a
|
|
19
|
+
* Sends a document to the API and parses out the result.
|
|
29
20
|
* Throws an error if the server's response contains one.
|
|
30
21
|
* @param {PredictParams} params parameters relating to prediction options.
|
|
31
22
|
* @category Synchronous
|
|
@@ -40,6 +31,7 @@ export declare class Endpoint extends BaseEndpoint {
|
|
|
40
31
|
* @returns a `Promise` containing queue data.
|
|
41
32
|
*/
|
|
42
33
|
predictAsync(params: PredictParams): Promise<EndpointResponse>;
|
|
34
|
+
private extractStatusMessage;
|
|
43
35
|
/**
|
|
44
36
|
* Requests the results of a queued document from the API.
|
|
45
37
|
* Throws an error if the server's response contains one.
|
package/src/http/endpoint.js
CHANGED
|
@@ -7,7 +7,7 @@ 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,
|
|
10
|
+
var _Endpoint_instances, _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
13
|
const url_1 = require("url");
|
|
@@ -21,15 +21,14 @@ const responseValidation_1 = require("./responseValidation");
|
|
|
21
21
|
*/
|
|
22
22
|
class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
23
23
|
constructor(urlName, owner, version, settings) {
|
|
24
|
-
super(settings);
|
|
24
|
+
super(settings, `/v1/products/${owner}/${urlName}/v${version}`);
|
|
25
25
|
_Endpoint_instances.add(this);
|
|
26
26
|
this.owner = owner;
|
|
27
27
|
this.urlName = urlName;
|
|
28
28
|
this.version = version;
|
|
29
|
-
this.urlRoot = `/v1/products/${owner}/${urlName}/v${version}`;
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
|
-
* Sends a
|
|
31
|
+
* Sends a document to the API and parses out the result.
|
|
33
32
|
* Throws an error if the server's response contains one.
|
|
34
33
|
* @param {PredictParams} params parameters relating to prediction options.
|
|
35
34
|
* @category Synchronous
|
|
@@ -38,11 +37,11 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
38
37
|
async predict(params) {
|
|
39
38
|
await params.inputDoc.init();
|
|
40
39
|
if (params.pageOptions !== undefined) {
|
|
41
|
-
await
|
|
40
|
+
await super.cutDocPages(params.inputDoc, params.pageOptions);
|
|
42
41
|
}
|
|
43
42
|
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper);
|
|
44
43
|
if (!(0, responseValidation_1.isValidSyncResponse)(response)) {
|
|
45
|
-
(0, error_1.handleError)(this.urlName, response, response
|
|
44
|
+
(0, error_1.handleError)(this.urlName, response, this.extractStatusMessage(response));
|
|
46
45
|
}
|
|
47
46
|
return response;
|
|
48
47
|
}
|
|
@@ -56,14 +55,28 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
56
55
|
async predictAsync(params) {
|
|
57
56
|
await params.inputDoc.init();
|
|
58
57
|
if (params.pageOptions !== undefined) {
|
|
59
|
-
await
|
|
58
|
+
await super.cutDocPages(params.inputDoc, params.pageOptions);
|
|
60
59
|
}
|
|
61
60
|
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_predictAsyncReqPost).call(this, params.inputDoc, params.includeWords, params.fullText, params.cropper);
|
|
62
61
|
if (!(0, responseValidation_1.isValidAsyncResponse)(response)) {
|
|
63
|
-
(0, error_1.handleError)(this.urlName, response, response
|
|
62
|
+
(0, error_1.handleError)(this.urlName, response, this.extractStatusMessage(response));
|
|
64
63
|
}
|
|
65
64
|
return response;
|
|
66
65
|
}
|
|
66
|
+
extractStatusMessage(response) {
|
|
67
|
+
if (response.messageObj?.statusMessage !== undefined && response.messageObj?.statusMessage !== null) {
|
|
68
|
+
return response.messageObj?.statusMessage;
|
|
69
|
+
}
|
|
70
|
+
const errorDetail = response.data?.api_request?.error?.detail;
|
|
71
|
+
if (errorDetail) {
|
|
72
|
+
return JSON.stringify(errorDetail);
|
|
73
|
+
}
|
|
74
|
+
const errorMessage = response.data?.api_request?.error?.message;
|
|
75
|
+
if (errorMessage) {
|
|
76
|
+
return JSON.stringify(errorMessage);
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
67
80
|
/**
|
|
68
81
|
* Requests the results of a queued document from the API.
|
|
69
82
|
* Throws an error if the server's response contains one.
|
|
@@ -75,7 +88,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
75
88
|
const queueResponse = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_documentQueueReqGet).call(this, queueId);
|
|
76
89
|
const queueStatusCode = queueResponse.messageObj.statusCode;
|
|
77
90
|
if (!(0, responseValidation_1.isValidAsyncResponse)(queueResponse)) {
|
|
78
|
-
(0, error_1.handleError)(this.urlName, queueResponse, queueResponse
|
|
91
|
+
(0, error_1.handleError)(this.urlName, queueResponse, this.extractStatusMessage(queueResponse));
|
|
79
92
|
}
|
|
80
93
|
if (queueStatusCode === 302 &&
|
|
81
94
|
queueResponse.messageObj.headers.location !== undefined) {
|
|
@@ -93,7 +106,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
93
106
|
async getDocument(documentId) {
|
|
94
107
|
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_documentGetReq).call(this, documentId);
|
|
95
108
|
if (!(0, responseValidation_1.isValidAsyncResponse)(response)) {
|
|
96
|
-
(0, error_1.handleError)("document", response, response
|
|
109
|
+
(0, error_1.handleError)("document", response, this.extractStatusMessage(response));
|
|
97
110
|
}
|
|
98
111
|
return response;
|
|
99
112
|
}
|
|
@@ -105,7 +118,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
105
118
|
async sendFeedback(documentId, feedback) {
|
|
106
119
|
const response = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_documentFeedbackPutReq).call(this, documentId, feedback);
|
|
107
120
|
if (!(0, responseValidation_1.isValidSyncResponse)(response)) {
|
|
108
|
-
(0, error_1.handleError)("feedback", response, response
|
|
121
|
+
(0, error_1.handleError)("feedback", response, this.extractStatusMessage(response));
|
|
109
122
|
}
|
|
110
123
|
return response;
|
|
111
124
|
}
|
|
@@ -148,6 +161,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
148
161
|
headers: headers,
|
|
149
162
|
hostname: this.settings.hostname,
|
|
150
163
|
path: path,
|
|
164
|
+
timeout: this.settings.timeout,
|
|
151
165
|
};
|
|
152
166
|
const req = this.readResponse(options, resolve, reject);
|
|
153
167
|
form.pipe(req);
|
|
@@ -157,17 +171,7 @@ class Endpoint extends baseEndpoint_1.BaseEndpoint {
|
|
|
157
171
|
}
|
|
158
172
|
}
|
|
159
173
|
exports.Endpoint = Endpoint;
|
|
160
|
-
_Endpoint_instances = new WeakSet(),
|
|
161
|
-
/**
|
|
162
|
-
* Cuts a document's pages according to the given options.
|
|
163
|
-
* @param inputDoc input document.
|
|
164
|
-
* @param pageOptions page cutting options.
|
|
165
|
-
*/
|
|
166
|
-
async function _Endpoint_cutDocPages(inputDoc, pageOptions) {
|
|
167
|
-
if (inputDoc instanceof base_1.LocalInputSource && inputDoc.isPdf()) {
|
|
168
|
-
await inputDoc.cutPdf(pageOptions);
|
|
169
|
-
}
|
|
170
|
-
}, _Endpoint_predictReqPost = function _Endpoint_predictReqPost(input, includeWords = false, fullText = false, cropper = false) {
|
|
174
|
+
_Endpoint_instances = new WeakSet(), _Endpoint_predictReqPost = function _Endpoint_predictReqPost(input, includeWords = false, fullText = false, cropper = false) {
|
|
171
175
|
return this.sendFileForPrediction(input, "predict", includeWords, fullText, cropper);
|
|
172
176
|
}, _Endpoint_predictAsyncReqPost = function _Endpoint_predictAsyncReqPost(input, includeWords = false, fullText = false, cropper = false) {
|
|
173
177
|
return this.sendFileForPrediction(input, "predict_async", includeWords, fullText, cropper);
|
package/src/http/error.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { InputSource, PageOptions } from "../input";
|
|
2
|
+
import { ExecutionPriority } from "../parsing/common";
|
|
3
|
+
interface HTTPParams {
|
|
4
|
+
inputDoc: InputSource;
|
|
5
|
+
fullText: boolean;
|
|
6
|
+
pageOptions?: PageOptions;
|
|
7
|
+
}
|
|
8
|
+
export interface PredictParams extends HTTPParams {
|
|
9
|
+
includeWords: boolean;
|
|
10
|
+
cropper: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface WorkflowParams extends HTTPParams {
|
|
13
|
+
alias?: string;
|
|
14
|
+
priority?: ExecutionPriority;
|
|
15
|
+
publicUrl?: string;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
package/src/http/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { EndpointResponse } from "./baseEndpoint";
|
|
|
3
3
|
export { STANDARD_API_OWNER, API_KEY_ENVVAR_NAME, ApiSettings, } from "./apiSettings";
|
|
4
4
|
export { MindeeHttpError, MindeeHttp400Error, MindeeHttp401Error, MindeeHttp403Error, MindeeHttp404Error, MindeeHttp413Error, MindeeHttp429Error, MindeeHttp500Error, MindeeHttp504Error, handleError, } from "./error";
|
|
5
5
|
export { isValidSyncResponse, isValidAsyncResponse, cleanRequestData, } from "./responseValidation";
|
|
6
|
+
export { PredictParams, WorkflowParams } from "./httpParams";
|
|
@@ -13,6 +13,12 @@ function isValidSyncResponse(response) {
|
|
|
13
13
|
if (!response.messageObj || !response.messageObj.statusCode) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
+
if (response.data &&
|
|
17
|
+
response.data["api_request"] &&
|
|
18
|
+
response.data["api_request"]["status_code"] &&
|
|
19
|
+
response.data["api_request"]["status_code"] > 399) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
16
22
|
return !(isNaN(response.messageObj.statusCode) ||
|
|
17
23
|
parseInt(response.messageObj.statusCode.toString()) < 200 ||
|
|
18
24
|
parseInt(response.messageObj.statusCode.toString()) > 302);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseEndpoint, EndpointResponse } from "./baseEndpoint";
|
|
2
|
+
import { ApiSettings } from "./apiSettings";
|
|
3
|
+
import { InputSource } from "../input";
|
|
4
|
+
import { WorkflowParams } from "./httpParams";
|
|
5
|
+
import { ExecutionPriority } from "../parsing/common";
|
|
6
|
+
/**
|
|
7
|
+
* Endpoint for a workflow.
|
|
8
|
+
*/
|
|
9
|
+
export declare class WorkflowEndpoint extends BaseEndpoint {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(settings: ApiSettings, workflowId: string);
|
|
12
|
+
/**
|
|
13
|
+
* Sends a document to a workflow execution.
|
|
14
|
+
* Throws an error if the server's response contains one.
|
|
15
|
+
* @param {WorkflowParams} params parameters relating to prediction options.
|
|
16
|
+
* @category Synchronous
|
|
17
|
+
* @returns a `Promise` containing parsing results.
|
|
18
|
+
*/
|
|
19
|
+
executeWorkflow(params: WorkflowParams): Promise<EndpointResponse>;
|
|
20
|
+
/**
|
|
21
|
+
* Send a file to a prediction API.
|
|
22
|
+
* @param input
|
|
23
|
+
* @param alias
|
|
24
|
+
* @param priority
|
|
25
|
+
* @param fullText
|
|
26
|
+
* @param publicUrl
|
|
27
|
+
*/
|
|
28
|
+
protected sendFileForPrediction(input: InputSource, alias?: string | null, priority?: ExecutionPriority | null, fullText?: boolean, publicUrl?: string | null): Promise<EndpointResponse>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
var _WorkflowEndpoint_instances, _WorkflowEndpoint_workflowReqPost;
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.WorkflowEndpoint = void 0;
|
|
13
|
+
const baseEndpoint_1 = require("./baseEndpoint");
|
|
14
|
+
const url_1 = require("url");
|
|
15
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
16
|
+
const base_1 = require("../input/base");
|
|
17
|
+
const responseValidation_1 = require("./responseValidation");
|
|
18
|
+
const error_1 = require("./error");
|
|
19
|
+
/**
|
|
20
|
+
* Endpoint for a workflow.
|
|
21
|
+
*/
|
|
22
|
+
class WorkflowEndpoint extends baseEndpoint_1.BaseEndpoint {
|
|
23
|
+
constructor(settings, workflowId) {
|
|
24
|
+
super(settings, `/v1/workflows/${workflowId}/executions`);
|
|
25
|
+
_WorkflowEndpoint_instances.add(this);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Sends a document to a workflow execution.
|
|
29
|
+
* Throws an error if the server's response contains one.
|
|
30
|
+
* @param {WorkflowParams} params parameters relating to prediction options.
|
|
31
|
+
* @category Synchronous
|
|
32
|
+
* @returns a `Promise` containing parsing results.
|
|
33
|
+
*/
|
|
34
|
+
async executeWorkflow(params) {
|
|
35
|
+
await params.inputDoc.init();
|
|
36
|
+
if (params.pageOptions !== undefined) {
|
|
37
|
+
await super.cutDocPages(params.inputDoc, params.pageOptions);
|
|
38
|
+
}
|
|
39
|
+
const response = await __classPrivateFieldGet(this, _WorkflowEndpoint_instances, "m", _WorkflowEndpoint_workflowReqPost).call(this, params.inputDoc, params.alias, params.priority, params.fullText, params.publicUrl);
|
|
40
|
+
if (!(0, responseValidation_1.isValidSyncResponse)(response)) {
|
|
41
|
+
(0, error_1.handleError)(this.urlRoot, response, response.messageObj?.statusMessage);
|
|
42
|
+
}
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Send a file to a prediction API.
|
|
47
|
+
* @param input
|
|
48
|
+
* @param alias
|
|
49
|
+
* @param priority
|
|
50
|
+
* @param fullText
|
|
51
|
+
* @param publicUrl
|
|
52
|
+
*/
|
|
53
|
+
sendFileForPrediction(input, alias = null, priority = null, fullText = false, publicUrl = null) {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
const searchParams = new url_1.URLSearchParams();
|
|
56
|
+
if (fullText) {
|
|
57
|
+
searchParams.append("full_text_ocr", "true");
|
|
58
|
+
}
|
|
59
|
+
const form = new form_data_1.default();
|
|
60
|
+
if (input instanceof base_1.LocalInputSource && input.fileObject instanceof Buffer) {
|
|
61
|
+
form.append("document", input.fileObject, {
|
|
62
|
+
filename: input.filename,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
form.append("document", input.fileObject);
|
|
67
|
+
}
|
|
68
|
+
if (alias) {
|
|
69
|
+
form.append("alias", alias);
|
|
70
|
+
}
|
|
71
|
+
if (publicUrl) {
|
|
72
|
+
form.append("public_url", publicUrl);
|
|
73
|
+
}
|
|
74
|
+
if (priority) {
|
|
75
|
+
form.append("priority", priority.toString());
|
|
76
|
+
}
|
|
77
|
+
const headers = { ...this.settings.baseHeaders, ...form.getHeaders() };
|
|
78
|
+
let path = this.urlRoot;
|
|
79
|
+
if (searchParams.toString().length > 0) {
|
|
80
|
+
path += `?${searchParams}`;
|
|
81
|
+
}
|
|
82
|
+
const options = {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: headers,
|
|
85
|
+
hostname: this.settings.hostname,
|
|
86
|
+
path: path,
|
|
87
|
+
timeout: this.settings.timeout,
|
|
88
|
+
};
|
|
89
|
+
const req = this.readResponse(options, resolve, reject);
|
|
90
|
+
form.pipe(req);
|
|
91
|
+
// potential ECONNRESET if we don't end the request.
|
|
92
|
+
req.end();
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.WorkflowEndpoint = WorkflowEndpoint;
|
|
97
|
+
_WorkflowEndpoint_instances = new WeakSet(), _WorkflowEndpoint_workflowReqPost = function _WorkflowEndpoint_workflowReqPost(input, alias = null, priority = null, fullText = false, publicUrl = null) {
|
|
98
|
+
return this.sendFileForPrediction(input, alias, priority, fullText, publicUrl);
|
|
99
|
+
};
|
|
@@ -21,8 +21,8 @@ export declare class Job {
|
|
|
21
21
|
/** The time taken to process the job, in milliseconds. */
|
|
22
22
|
milliSecsTaken?: number;
|
|
23
23
|
constructor(jsonResponse: StringDict);
|
|
24
|
-
protected datetimeWithTimezone(date: string): Date;
|
|
25
24
|
}
|
|
25
|
+
export declare function datetimeWithTimezone(date: string): Date;
|
|
26
26
|
/** Wrapper for asynchronous jobs and parsing results.
|
|
27
27
|
*
|
|
28
28
|
* @category API Response
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AsyncPredictResponse = exports.Job = void 0;
|
|
4
|
+
exports.datetimeWithTimezone = datetimeWithTimezone;
|
|
4
5
|
const apiResponse_1 = require("./apiResponse");
|
|
5
6
|
const document_1 = require("./document");
|
|
6
7
|
/** Wrapper for asynchronous request queues. Holds information regarding a job (queue).
|
|
@@ -10,10 +11,10 @@ const document_1 = require("./document");
|
|
|
10
11
|
*/
|
|
11
12
|
class Job {
|
|
12
13
|
constructor(jsonResponse) {
|
|
13
|
-
this.issuedAt =
|
|
14
|
+
this.issuedAt = datetimeWithTimezone(jsonResponse["issued_at"]);
|
|
14
15
|
if (jsonResponse["available_at"] !== undefined &&
|
|
15
16
|
jsonResponse["available_at"] !== null) {
|
|
16
|
-
this.availableAt =
|
|
17
|
+
this.availableAt = datetimeWithTimezone(jsonResponse["available_at"]);
|
|
17
18
|
}
|
|
18
19
|
this.id = jsonResponse["id"];
|
|
19
20
|
this.status = jsonResponse["status"];
|
|
@@ -22,15 +23,15 @@ class Job {
|
|
|
22
23
|
this.availableAt.getTime() - this.issuedAt.getTime();
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
// Hideous thing to make sure dates sent back by the server are parsed correctly in UTC.
|
|
26
|
-
datetimeWithTimezone(date) {
|
|
27
|
-
if (date.search(/\+[0-9]{2}:[0-9]{2}$/) === -1) {
|
|
28
|
-
date += "+00:00";
|
|
29
|
-
}
|
|
30
|
-
return new Date(date);
|
|
31
|
-
}
|
|
32
26
|
}
|
|
33
27
|
exports.Job = Job;
|
|
28
|
+
// Hideous thing to make sure dates sent back by the server are parsed correctly in UTC.
|
|
29
|
+
function datetimeWithTimezone(date) {
|
|
30
|
+
if (date.search(/\+[0-9]{2}:[0-9]{2}$/) === -1) {
|
|
31
|
+
date += "+00:00";
|
|
32
|
+
}
|
|
33
|
+
return new Date(date);
|
|
34
|
+
}
|
|
34
35
|
/** Wrapper for asynchronous jobs and parsing results.
|
|
35
36
|
*
|
|
36
37
|
* @category API Response
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Inference } from "./inference";
|
|
2
|
+
import { GeneratedV1Document } from "../../product/generated/generatedV1Document";
|
|
3
|
+
import { ExecutionFile } from "./executionFile";
|
|
4
|
+
import { StringDict } from "./stringDict";
|
|
5
|
+
import { ExecutionPriority } from "./executionPriority";
|
|
6
|
+
/**
|
|
7
|
+
* Representation of an execution for a workflow.
|
|
8
|
+
* @category Workflow
|
|
9
|
+
*/
|
|
10
|
+
export declare class Execution<T extends Inference> {
|
|
11
|
+
/** Identifier for the batch to which the execution belongs. */
|
|
12
|
+
batchName: string;
|
|
13
|
+
/** The time at which the execution started. */
|
|
14
|
+
createdAt: Date | null;
|
|
15
|
+
/** File representation within a workflow execution. */
|
|
16
|
+
file: ExecutionFile;
|
|
17
|
+
/** Identifier for the execution. */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Deserialized inference object. */
|
|
20
|
+
inference: T | null;
|
|
21
|
+
/** Priority of the execution. */
|
|
22
|
+
priority: ExecutionPriority | null;
|
|
23
|
+
/** The time at which the file was tagged as reviewed. */
|
|
24
|
+
reviewedAt: Date | null;
|
|
25
|
+
/** The time at which the file was uploaded to a workflow. */
|
|
26
|
+
availableAt: Date | null;
|
|
27
|
+
/** Reviewed fields and values. */
|
|
28
|
+
reviewedPrediction: GeneratedV1Document | null;
|
|
29
|
+
/** Execution Status. */
|
|
30
|
+
status: string;
|
|
31
|
+
/** Execution type. */
|
|
32
|
+
type: string | null;
|
|
33
|
+
/** The time at which the file was uploaded to a workflow. */
|
|
34
|
+
uploadedAt: Date | null;
|
|
35
|
+
/** Identifier for the workflow. */
|
|
36
|
+
workflowId: string;
|
|
37
|
+
constructor(inferenceClass: new (serverResponse: StringDict) => T, jsonResponse: StringDict);
|
|
38
|
+
private parseDate;
|
|
39
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Execution = void 0;
|
|
4
|
+
const generatedV1Document_1 = require("../../product/generated/generatedV1Document");
|
|
5
|
+
/**
|
|
6
|
+
* Representation of an execution for a workflow.
|
|
7
|
+
* @category Workflow
|
|
8
|
+
*/
|
|
9
|
+
class Execution {
|
|
10
|
+
constructor(inferenceClass, jsonResponse) {
|
|
11
|
+
this.batchName = jsonResponse["batch_name"];
|
|
12
|
+
this.createdAt = jsonResponse["created_at"] ? this.parseDate(jsonResponse["created_at"]) : null;
|
|
13
|
+
this.file = jsonResponse["file"];
|
|
14
|
+
this.id = jsonResponse["id"];
|
|
15
|
+
this.inference = jsonResponse["inference"] ? new inferenceClass(jsonResponse["inference"]) : null;
|
|
16
|
+
this.priority = jsonResponse["priority"];
|
|
17
|
+
this.reviewedAt = this.parseDate(jsonResponse["reviewed_at"]);
|
|
18
|
+
this.availableAt = this.parseDate(jsonResponse["available_at"]);
|
|
19
|
+
this.reviewedPrediction = jsonResponse["reviewed_prediction"] ?
|
|
20
|
+
new generatedV1Document_1.GeneratedV1Document(jsonResponse["reviewed_prediction"]) : null;
|
|
21
|
+
this.status = jsonResponse["status"];
|
|
22
|
+
this.type = jsonResponse["type"];
|
|
23
|
+
this.uploadedAt = this.parseDate(jsonResponse["uploaded_at"]);
|
|
24
|
+
this.workflowId = jsonResponse["workflow_id"];
|
|
25
|
+
}
|
|
26
|
+
parseDate(dateString) {
|
|
27
|
+
if (!dateString)
|
|
28
|
+
return null;
|
|
29
|
+
return new Date(dateString);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Execution = Execution;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StringDict } from "./stringDict";
|
|
2
|
+
/**
|
|
3
|
+
* Representation of an execution's file info.
|
|
4
|
+
* @category Workflow
|
|
5
|
+
*/
|
|
6
|
+
export declare class ExecutionFile {
|
|
7
|
+
/** File name. */
|
|
8
|
+
name: string | null;
|
|
9
|
+
/** Optional alias for the fil. */
|
|
10
|
+
alias: string | null;
|
|
11
|
+
constructor(jsonResponse: StringDict);
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecutionFile = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Representation of an execution's file info.
|
|
6
|
+
* @category Workflow
|
|
7
|
+
*/
|
|
8
|
+
class ExecutionFile {
|
|
9
|
+
constructor(jsonResponse) {
|
|
10
|
+
this.name = jsonResponse["name"];
|
|
11
|
+
this.alias = jsonResponse["alias"];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ExecutionFile = ExecutionFile;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecutionPriority = void 0;
|
|
4
|
+
var ExecutionPriority;
|
|
5
|
+
(function (ExecutionPriority) {
|
|
6
|
+
ExecutionPriority["low"] = "low";
|
|
7
|
+
ExecutionPriority["medium"] = "medium";
|
|
8
|
+
ExecutionPriority["high"] = "high";
|
|
9
|
+
})(ExecutionPriority || (exports.ExecutionPriority = ExecutionPriority = {}));
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export { Document } from "./document";
|
|
2
|
+
export { Execution } from "./execution";
|
|
3
|
+
export { ExecutionFile } from "./executionFile";
|
|
4
|
+
export { ExecutionPriority } from "./executionPriority";
|
|
5
|
+
export { Inference } from "./inference";
|
|
2
6
|
export { FeedbackResponse } from "./feedback/feedbackResponse";
|
|
3
7
|
export { OrientationField } from "./orientation";
|
|
4
8
|
export { StringDict } from "./stringDict";
|
|
5
|
-
export { Inference } from "./inference";
|
|
6
9
|
export { AsyncPredictResponse } from "./asyncPredictResponse";
|
|
7
10
|
export { PredictResponse } from "./predictResponse";
|
|
8
11
|
export { Prediction } from "./prediction";
|
|
@@ -23,15 +23,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.cleanSpecialChars = exports.floatToString = exports.extras = exports.lineSeparator = exports.cleanOutString = exports.Page = exports.Prediction = exports.PredictResponse = exports.AsyncPredictResponse = exports.Inference = exports.
|
|
26
|
+
exports.cleanSpecialChars = exports.floatToString = exports.extras = exports.lineSeparator = exports.cleanOutString = exports.Page = exports.Prediction = exports.PredictResponse = exports.AsyncPredictResponse = exports.OrientationField = exports.FeedbackResponse = exports.Inference = exports.ExecutionPriority = exports.ExecutionFile = exports.Execution = exports.Document = void 0;
|
|
27
27
|
var document_1 = require("./document");
|
|
28
28
|
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
|
|
29
|
+
var execution_1 = require("./execution");
|
|
30
|
+
Object.defineProperty(exports, "Execution", { enumerable: true, get: function () { return execution_1.Execution; } });
|
|
31
|
+
var executionFile_1 = require("./executionFile");
|
|
32
|
+
Object.defineProperty(exports, "ExecutionFile", { enumerable: true, get: function () { return executionFile_1.ExecutionFile; } });
|
|
33
|
+
var executionPriority_1 = require("./executionPriority");
|
|
34
|
+
Object.defineProperty(exports, "ExecutionPriority", { enumerable: true, get: function () { return executionPriority_1.ExecutionPriority; } });
|
|
35
|
+
var inference_1 = require("./inference");
|
|
36
|
+
Object.defineProperty(exports, "Inference", { enumerable: true, get: function () { return inference_1.Inference; } });
|
|
29
37
|
var feedbackResponse_1 = require("./feedback/feedbackResponse");
|
|
30
38
|
Object.defineProperty(exports, "FeedbackResponse", { enumerable: true, get: function () { return feedbackResponse_1.FeedbackResponse; } });
|
|
31
39
|
var orientation_1 = require("./orientation");
|
|
32
40
|
Object.defineProperty(exports, "OrientationField", { enumerable: true, get: function () { return orientation_1.OrientationField; } });
|
|
33
|
-
var inference_1 = require("./inference");
|
|
34
|
-
Object.defineProperty(exports, "Inference", { enumerable: true, get: function () { return inference_1.Inference; } });
|
|
35
41
|
var asyncPredictResponse_1 = require("./asyncPredictResponse");
|
|
36
42
|
Object.defineProperty(exports, "AsyncPredictResponse", { enumerable: true, get: function () { return asyncPredictResponse_1.AsyncPredictResponse; } });
|
|
37
43
|
var predictResponse_1 = require("./predictResponse");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StringDict } from "./stringDict";
|
|
2
|
+
import { ApiResponse } from "./apiResponse";
|
|
3
|
+
import { Execution } from "./execution";
|
|
4
|
+
import { Inference } from "./inference";
|
|
5
|
+
/** Wrapper for workflow requests.
|
|
6
|
+
*
|
|
7
|
+
* @category API Response
|
|
8
|
+
* @category Workflow
|
|
9
|
+
*/
|
|
10
|
+
export declare class WorkflowResponse<T extends Inference> extends ApiResponse {
|
|
11
|
+
/**
|
|
12
|
+
* Set the prediction model used to parse the document.
|
|
13
|
+
* The response object will be instantiated based on this parameter.
|
|
14
|
+
*/
|
|
15
|
+
execution: Execution<T>;
|
|
16
|
+
constructor(inferenceClass: new (serverResponse: StringDict) => T, serverResponse: StringDict);
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkflowResponse = void 0;
|
|
4
|
+
const apiResponse_1 = require("./apiResponse");
|
|
5
|
+
const execution_1 = require("./execution");
|
|
6
|
+
/** Wrapper for workflow requests.
|
|
7
|
+
*
|
|
8
|
+
* @category API Response
|
|
9
|
+
* @category Workflow
|
|
10
|
+
*/
|
|
11
|
+
class WorkflowResponse extends apiResponse_1.ApiResponse {
|
|
12
|
+
constructor(inferenceClass, serverResponse) {
|
|
13
|
+
super(serverResponse);
|
|
14
|
+
this.execution = new execution_1.Execution(inferenceClass, serverResponse["execution"]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.WorkflowResponse = WorkflowResponse;
|
package/src/product/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export { CustomV1 } from "./custom/customV1";
|
|
|
6
6
|
export { DeliveryNoteV1 } from "./deliveryNote/deliveryNoteV1";
|
|
7
7
|
export { FinancialDocumentV1 } from "./financialDocument/financialDocumentV1";
|
|
8
8
|
export { GeneratedV1 } from "./generated/generatedV1";
|
|
9
|
-
export { InternationalIdV1 } from "./internationalId/internationalIdV1";
|
|
10
9
|
export { InternationalIdV2 } from "./internationalId/internationalIdV2";
|
|
11
10
|
export { InvoiceV4 } from "./invoice/invoiceV4";
|
|
12
11
|
export { InvoiceSplitterV1 } from "./invoiceSplitter/invoiceSplitterV1";
|
package/src/product/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.us = exports.ind = exports.fr = exports.eu = exports.ResumeV1 = exports.ReceiptV5 = exports.ReceiptV4 = exports.ProofOfAddressV1 = exports.PassportV1 = exports.NutritionFactsLabelV1 = exports.MultiReceiptsDetectorV1 = exports.InvoiceSplitterV1 = exports.InvoiceV4 = exports.InternationalIdV2 = exports.
|
|
26
|
+
exports.us = exports.ind = exports.fr = exports.eu = exports.ResumeV1 = exports.ReceiptV5 = exports.ReceiptV4 = exports.ProofOfAddressV1 = exports.PassportV1 = exports.NutritionFactsLabelV1 = exports.MultiReceiptsDetectorV1 = exports.InvoiceSplitterV1 = exports.InvoiceV4 = exports.InternationalIdV2 = exports.GeneratedV1 = exports.FinancialDocumentV1 = exports.DeliveryNoteV1 = exports.CustomV1 = exports.CropperV1 = exports.BusinessCardV1 = exports.BillOfLadingV1 = exports.BarcodeReaderV1 = void 0;
|
|
27
27
|
var barcodeReaderV1_1 = require("./barcodeReader/barcodeReaderV1");
|
|
28
28
|
Object.defineProperty(exports, "BarcodeReaderV1", { enumerable: true, get: function () { return barcodeReaderV1_1.BarcodeReaderV1; } });
|
|
29
29
|
var billOfLadingV1_1 = require("./billOfLading/billOfLadingV1");
|
|
@@ -40,8 +40,6 @@ var financialDocumentV1_1 = require("./financialDocument/financialDocumentV1");
|
|
|
40
40
|
Object.defineProperty(exports, "FinancialDocumentV1", { enumerable: true, get: function () { return financialDocumentV1_1.FinancialDocumentV1; } });
|
|
41
41
|
var generatedV1_1 = require("./generated/generatedV1");
|
|
42
42
|
Object.defineProperty(exports, "GeneratedV1", { enumerable: true, get: function () { return generatedV1_1.GeneratedV1; } });
|
|
43
|
-
var internationalIdV1_1 = require("./internationalId/internationalIdV1");
|
|
44
|
-
Object.defineProperty(exports, "InternationalIdV1", { enumerable: true, get: function () { return internationalIdV1_1.InternationalIdV1; } });
|
|
45
43
|
var internationalIdV2_1 = require("./internationalId/internationalIdV2");
|
|
46
44
|
Object.defineProperty(exports, "InternationalIdV2", { enumerable: true, get: function () { return internationalIdV2_1.InternationalIdV2; } });
|
|
47
45
|
var invoiceV4_1 = require("./invoice/invoiceV4");
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InternationalIdV2Document = exports.InternationalIdV2 =
|
|
4
|
-
var internationalIdV1_1 = require("./internationalIdV1");
|
|
5
|
-
Object.defineProperty(exports, "InternationalIdV1", { enumerable: true, get: function () { return internationalIdV1_1.InternationalIdV1; } });
|
|
6
|
-
var internationalIdV1Document_1 = require("./internationalIdV1Document");
|
|
7
|
-
Object.defineProperty(exports, "InternationalIdV1Document", { enumerable: true, get: function () { return internationalIdV1Document_1.InternationalIdV1Document; } });
|
|
3
|
+
exports.InternationalIdV2Document = exports.InternationalIdV2 = void 0;
|
|
8
4
|
var internationalIdV2_1 = require("./internationalIdV2");
|
|
9
5
|
Object.defineProperty(exports, "InternationalIdV2", { enumerable: true, get: function () { return internationalIdV2_1.InternationalIdV2; } });
|
|
10
6
|
var internationalIdV2Document_1 = require("./internationalIdV2Document");
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Inference, StringDict, Page } from "../../parsing/common";
|
|
2
|
-
import { InternationalIdV1Document } from "./internationalIdV1Document";
|
|
3
|
-
/**
|
|
4
|
-
* Inference prediction for International ID, API version 1.
|
|
5
|
-
*/
|
|
6
|
-
export declare class InternationalIdV1 extends Inference {
|
|
7
|
-
/** The endpoint's name. */
|
|
8
|
-
endpointName: string;
|
|
9
|
-
/** The endpoint's version. */
|
|
10
|
-
endpointVersion: string;
|
|
11
|
-
/** The document-level prediction. */
|
|
12
|
-
prediction: InternationalIdV1Document;
|
|
13
|
-
/** The document's pages. */
|
|
14
|
-
pages: Page<InternationalIdV1Document>[];
|
|
15
|
-
constructor(rawPrediction: StringDict);
|
|
16
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InternationalIdV1 = void 0;
|
|
4
|
-
const common_1 = require("../../parsing/common");
|
|
5
|
-
const internationalIdV1Document_1 = require("./internationalIdV1Document");
|
|
6
|
-
/**
|
|
7
|
-
* Inference prediction for International ID, API version 1.
|
|
8
|
-
*/
|
|
9
|
-
class InternationalIdV1 extends common_1.Inference {
|
|
10
|
-
constructor(rawPrediction) {
|
|
11
|
-
super(rawPrediction);
|
|
12
|
-
/** The endpoint's name. */
|
|
13
|
-
this.endpointName = "international_id";
|
|
14
|
-
/** The endpoint's version. */
|
|
15
|
-
this.endpointVersion = "1";
|
|
16
|
-
/** The document's pages. */
|
|
17
|
-
this.pages = [];
|
|
18
|
-
this.prediction = new internationalIdV1Document_1.InternationalIdV1Document(rawPrediction["prediction"]);
|
|
19
|
-
rawPrediction["pages"].forEach((page) => {
|
|
20
|
-
if (page.prediction !== undefined && page.prediction !== null &&
|
|
21
|
-
Object.keys(page.prediction).length > 0) {
|
|
22
|
-
this.pages.push(new common_1.Page(internationalIdV1Document_1.InternationalIdV1Document, page, page["id"], page["orientation"]));
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.InternationalIdV1 = InternationalIdV1;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Prediction, StringDict } from "../../parsing/common";
|
|
2
|
-
import { ClassificationField, DateField, StringField } from "../../parsing/standard";
|
|
3
|
-
/**
|
|
4
|
-
* Document data for International ID, API version 1.
|
|
5
|
-
*/
|
|
6
|
-
export declare class InternationalIdV1Document implements Prediction {
|
|
7
|
-
/** The physical location of the document holder's residence. */
|
|
8
|
-
address: StringField;
|
|
9
|
-
/** The date of birth of the document holder. */
|
|
10
|
-
birthDate: DateField;
|
|
11
|
-
/** The location where the document holder was born. */
|
|
12
|
-
birthPlace: StringField;
|
|
13
|
-
/** The country that issued the identification document. */
|
|
14
|
-
countryOfIssue: StringField;
|
|
15
|
-
/** The unique identifier assigned to the identification document. */
|
|
16
|
-
documentNumber: StringField;
|
|
17
|
-
/** The type of identification document being used. */
|
|
18
|
-
documentType: ClassificationField;
|
|
19
|
-
/** The date when the document will no longer be valid for use. */
|
|
20
|
-
expiryDate: DateField;
|
|
21
|
-
/** The first names or given names of the document holder. */
|
|
22
|
-
givenNames: StringField[];
|
|
23
|
-
/** The date when the document was issued. */
|
|
24
|
-
issueDate: DateField;
|
|
25
|
-
/** First line of information in a standardized format for easy machine reading and processing. */
|
|
26
|
-
mrz1: StringField;
|
|
27
|
-
/** Second line of information in a standardized format for easy machine reading and processing. */
|
|
28
|
-
mrz2: StringField;
|
|
29
|
-
/** Third line of information in a standardized format for easy machine reading and processing. */
|
|
30
|
-
mrz3: StringField;
|
|
31
|
-
/** Indicates the country of citizenship or nationality of the document holder. */
|
|
32
|
-
nationality: StringField;
|
|
33
|
-
/** The document holder's biological sex, such as male or female. */
|
|
34
|
-
sex: StringField;
|
|
35
|
-
/** The surnames of the document holder. */
|
|
36
|
-
surnames: StringField[];
|
|
37
|
-
constructor(rawPrediction: StringDict, pageId?: number);
|
|
38
|
-
/**
|
|
39
|
-
* Default string representation.
|
|
40
|
-
*/
|
|
41
|
-
toString(): string;
|
|
42
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InternationalIdV1Document = void 0;
|
|
4
|
-
const common_1 = require("../../parsing/common");
|
|
5
|
-
const standard_1 = require("../../parsing/standard");
|
|
6
|
-
/**
|
|
7
|
-
* Document data for International ID, API version 1.
|
|
8
|
-
*/
|
|
9
|
-
class InternationalIdV1Document {
|
|
10
|
-
constructor(rawPrediction, pageId) {
|
|
11
|
-
/** The first names or given names of the document holder. */
|
|
12
|
-
this.givenNames = [];
|
|
13
|
-
/** The surnames of the document holder. */
|
|
14
|
-
this.surnames = [];
|
|
15
|
-
this.address = new standard_1.StringField({
|
|
16
|
-
prediction: rawPrediction["address"],
|
|
17
|
-
pageId: pageId,
|
|
18
|
-
});
|
|
19
|
-
this.birthDate = new standard_1.DateField({
|
|
20
|
-
prediction: rawPrediction["birth_date"],
|
|
21
|
-
pageId: pageId,
|
|
22
|
-
});
|
|
23
|
-
this.birthPlace = new standard_1.StringField({
|
|
24
|
-
prediction: rawPrediction["birth_place"],
|
|
25
|
-
pageId: pageId,
|
|
26
|
-
});
|
|
27
|
-
this.countryOfIssue = new standard_1.StringField({
|
|
28
|
-
prediction: rawPrediction["country_of_issue"],
|
|
29
|
-
pageId: pageId,
|
|
30
|
-
});
|
|
31
|
-
this.documentNumber = new standard_1.StringField({
|
|
32
|
-
prediction: rawPrediction["document_number"],
|
|
33
|
-
pageId: pageId,
|
|
34
|
-
});
|
|
35
|
-
this.documentType = new standard_1.ClassificationField({
|
|
36
|
-
prediction: rawPrediction["document_type"],
|
|
37
|
-
});
|
|
38
|
-
this.expiryDate = new standard_1.DateField({
|
|
39
|
-
prediction: rawPrediction["expiry_date"],
|
|
40
|
-
pageId: pageId,
|
|
41
|
-
});
|
|
42
|
-
rawPrediction["given_names"] &&
|
|
43
|
-
rawPrediction["given_names"].map((itemPrediction) => this.givenNames.push(new standard_1.StringField({
|
|
44
|
-
prediction: itemPrediction,
|
|
45
|
-
pageId: pageId,
|
|
46
|
-
})));
|
|
47
|
-
this.issueDate = new standard_1.DateField({
|
|
48
|
-
prediction: rawPrediction["issue_date"],
|
|
49
|
-
pageId: pageId,
|
|
50
|
-
});
|
|
51
|
-
this.mrz1 = new standard_1.StringField({
|
|
52
|
-
prediction: rawPrediction["mrz1"],
|
|
53
|
-
pageId: pageId,
|
|
54
|
-
});
|
|
55
|
-
this.mrz2 = new standard_1.StringField({
|
|
56
|
-
prediction: rawPrediction["mrz2"],
|
|
57
|
-
pageId: pageId,
|
|
58
|
-
});
|
|
59
|
-
this.mrz3 = new standard_1.StringField({
|
|
60
|
-
prediction: rawPrediction["mrz3"],
|
|
61
|
-
pageId: pageId,
|
|
62
|
-
});
|
|
63
|
-
this.nationality = new standard_1.StringField({
|
|
64
|
-
prediction: rawPrediction["nationality"],
|
|
65
|
-
pageId: pageId,
|
|
66
|
-
});
|
|
67
|
-
this.sex = new standard_1.StringField({
|
|
68
|
-
prediction: rawPrediction["sex"],
|
|
69
|
-
pageId: pageId,
|
|
70
|
-
});
|
|
71
|
-
rawPrediction["surnames"] &&
|
|
72
|
-
rawPrediction["surnames"].map((itemPrediction) => this.surnames.push(new standard_1.StringField({
|
|
73
|
-
prediction: itemPrediction,
|
|
74
|
-
pageId: pageId,
|
|
75
|
-
})));
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Default string representation.
|
|
79
|
-
*/
|
|
80
|
-
toString() {
|
|
81
|
-
const surnames = this.surnames.join("\n ");
|
|
82
|
-
const givenNames = this.givenNames.join("\n ");
|
|
83
|
-
const outStr = `:Document Type: ${this.documentType}
|
|
84
|
-
:Document Number: ${this.documentNumber}
|
|
85
|
-
:Country of Issue: ${this.countryOfIssue}
|
|
86
|
-
:Surnames: ${surnames}
|
|
87
|
-
:Given Names: ${givenNames}
|
|
88
|
-
:Gender: ${this.sex}
|
|
89
|
-
:Birth date: ${this.birthDate}
|
|
90
|
-
:Birth Place: ${this.birthPlace}
|
|
91
|
-
:Nationality: ${this.nationality}
|
|
92
|
-
:Issue Date: ${this.issueDate}
|
|
93
|
-
:Expiry Date: ${this.expiryDate}
|
|
94
|
-
:Address: ${this.address}
|
|
95
|
-
:Machine Readable Zone Line 1: ${this.mrz1}
|
|
96
|
-
:Machine Readable Zone Line 2: ${this.mrz2}
|
|
97
|
-
:Machine Readable Zone Line 3: ${this.mrz3}`.trimEnd();
|
|
98
|
-
return (0, common_1.cleanOutString)(outStr);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.InternationalIdV1Document = InternationalIdV1Document;
|