mindee 4.18.0 → 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 +16 -1
- package/package.json +12 -12
- package/src/cli.js +1 -2
- package/src/client.d.ts +44 -12
- package/src/client.js +25 -1
- package/src/geometry/boundingBoxUtils.js +5 -6
- package/src/geometry/polygonUtils.js +13 -14
- package/src/http/apiSettings.d.ts +2 -0
- package/src/http/apiSettings.js +3 -1
- package/src/http/baseEndpoint.d.ts +10 -3
- package/src/http/baseEndpoint.js +14 -2
- package/src/http/endpoint.d.ts +3 -11
- package/src/http/endpoint.js +26 -22
- package/src/http/error.js +5 -5
- 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 +9 -4
- package/src/http/workflowEndpoint.d.ts +29 -0
- package/src/http/workflowEndpoint.js +99 -0
- package/src/imageOperations/common/extractedImage.d.ts +0 -1
- package/src/imageOperations/common/imageExtractor.js +1 -2
- package/src/imageOperations/invoiceSplitterExtractor/invoiceSplitterExtractor.js +1 -2
- package/src/imageOperations/multiReceiptsExtractor/multiReceiptsExtractor.js +1 -2
- package/src/input/base.d.ts +0 -1
- package/src/input/localResponse.d.ts +0 -1
- package/src/input/localResponse.js +2 -2
- package/src/input/pageOptions.js +1 -1
- package/src/input/sources.d.ts +0 -2
- 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/page.js +1 -1
- package/src/parsing/common/summaryHelper.js +4 -5
- package/src/parsing/common/workflowResponse.d.ts +17 -0
- package/src/parsing/common/workflowResponse.js +17 -0
- package/src/parsing/custom/lineItems.js +2 -2
- package/src/parsing/generated/generatedObject.js +2 -2
- package/src/parsing/standard/paymentDetails.js +4 -4
- package/src/pdf/pdfOperation.d.ts +0 -1
- package/src/pdf/pdfOperation.js +2 -3
- 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/src/http/error.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MindeeHttp504Error = exports.MindeeHttp500Error = exports.MindeeHttp429Error = exports.MindeeHttp413Error = exports.MindeeHttp404Error = exports.MindeeHttp403Error = exports.MindeeHttp401Error = exports.MindeeHttp400Error = exports.MindeeHttpError =
|
|
3
|
+
exports.MindeeHttp504Error = exports.MindeeHttp500Error = exports.MindeeHttp429Error = exports.MindeeHttp413Error = exports.MindeeHttp404Error = exports.MindeeHttp403Error = exports.MindeeHttp401Error = exports.MindeeHttp400Error = exports.MindeeHttpError = void 0;
|
|
4
|
+
exports.handleError = handleError;
|
|
4
5
|
const errors_1 = require("../errors");
|
|
5
6
|
const handler_1 = require("../errors/handler");
|
|
6
7
|
function handleError(urlName, response, serverError) {
|
|
@@ -10,11 +11,11 @@ function handleError(urlName, response, serverError) {
|
|
|
10
11
|
code = 500;
|
|
11
12
|
response.data.api_request.error = response.data.job.error;
|
|
12
13
|
}
|
|
13
|
-
else {
|
|
14
|
+
else if (response.data) {
|
|
14
15
|
code = response.data.api_request["status_code"];
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
catch
|
|
18
|
+
catch {
|
|
18
19
|
code = 500;
|
|
19
20
|
}
|
|
20
21
|
let errorObj;
|
|
@@ -22,7 +23,7 @@ function handleError(urlName, response, serverError) {
|
|
|
22
23
|
//Regular instances where the returned error is in JSON format.
|
|
23
24
|
errorObj = response.data.api_request.error;
|
|
24
25
|
}
|
|
25
|
-
catch
|
|
26
|
+
catch {
|
|
26
27
|
//Rare instances where errors are returned as HTML instead of JSON.
|
|
27
28
|
if (!("reconstructedResponse" in response.data)) {
|
|
28
29
|
response.data.reconstructedResponse = "";
|
|
@@ -108,7 +109,6 @@ function handleError(urlName, response, serverError) {
|
|
|
108
109
|
}
|
|
109
110
|
handler_1.errorHandler.throw(errorToThrow);
|
|
110
111
|
}
|
|
111
|
-
exports.handleError = handleError;
|
|
112
112
|
/**
|
|
113
113
|
* `Error` wrapper for server (HTTP) errors.
|
|
114
114
|
* Is used when an error is lacking a handled error code.
|
|
@@ -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";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isValidSyncResponse = isValidSyncResponse;
|
|
4
|
+
exports.isValidAsyncResponse = isValidAsyncResponse;
|
|
5
|
+
exports.cleanRequestData = cleanRequestData;
|
|
4
6
|
/**
|
|
5
7
|
* Checks if the synchronous response is valid. Returns True if the response is valid.
|
|
6
8
|
*
|
|
@@ -11,11 +13,16 @@ function isValidSyncResponse(response) {
|
|
|
11
13
|
if (!response.messageObj || !response.messageObj.statusCode) {
|
|
12
14
|
return false;
|
|
13
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
|
+
}
|
|
14
22
|
return !(isNaN(response.messageObj.statusCode) ||
|
|
15
23
|
parseInt(response.messageObj.statusCode.toString()) < 200 ||
|
|
16
24
|
parseInt(response.messageObj.statusCode.toString()) > 302);
|
|
17
25
|
}
|
|
18
|
-
exports.isValidSyncResponse = isValidSyncResponse;
|
|
19
26
|
/**
|
|
20
27
|
* Checks if the asynchronous response is valid. Also checks if it is a valid synchronous response.
|
|
21
28
|
* Returns True if the response is valid.
|
|
@@ -43,7 +50,6 @@ function isValidAsyncResponse(response) {
|
|
|
43
50
|
response.data["job"]["error"] &&
|
|
44
51
|
Object.keys(response.data["job"]["error"]).length > 0);
|
|
45
52
|
}
|
|
46
|
-
exports.isValidAsyncResponse = isValidAsyncResponse;
|
|
47
53
|
/**
|
|
48
54
|
* Checks and correct the response object depending on the possible kinds of returns.
|
|
49
55
|
*
|
|
@@ -70,4 +76,3 @@ function cleanRequestData(response) {
|
|
|
70
76
|
}
|
|
71
77
|
return response;
|
|
72
78
|
}
|
|
73
|
-
exports.cleanRequestData = cleanRequestData;
|
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractFromPage =
|
|
3
|
+
exports.extractFromPage = extractFromPage;
|
|
4
4
|
const pdf_lib_1 = require("pdf-lib");
|
|
5
5
|
const geometry_1 = require("../../geometry");
|
|
6
6
|
/**
|
|
@@ -31,4 +31,3 @@ async function extractFromPage(pdfPage, polygons) {
|
|
|
31
31
|
}
|
|
32
32
|
return extractedElements;
|
|
33
33
|
}
|
|
34
|
-
exports.extractFromPage = extractFromPage;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractInvoices =
|
|
3
|
+
exports.extractInvoices = extractInvoices;
|
|
4
4
|
const pdf_lib_1 = require("pdf-lib");
|
|
5
5
|
const errors_1 = require("../../errors");
|
|
6
6
|
const product_1 = require("../../product");
|
|
@@ -71,4 +71,3 @@ async function extractInvoices(inputFile, indexes, strict = false) {
|
|
|
71
71
|
});
|
|
72
72
|
return await splitPdf(pdfDoc, customIndexes);
|
|
73
73
|
}
|
|
74
|
-
exports.extractInvoices = extractInvoices;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractReceipts =
|
|
3
|
+
exports.extractReceipts = extractReceipts;
|
|
4
4
|
const pdf_lib_1 = require("pdf-lib");
|
|
5
5
|
const errors_1 = require("../../errors");
|
|
6
6
|
const extractedMultiReceiptImage_1 = require("./extractedMultiReceiptImage");
|
|
@@ -68,4 +68,3 @@ async function extractReceipts(inputFile, inference) {
|
|
|
68
68
|
}
|
|
69
69
|
return images;
|
|
70
70
|
}
|
|
71
|
-
exports.extractReceipts = extractReceipts;
|
package/src/input/base.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ class LocalResponse {
|
|
|
71
71
|
const content = this.file.toString("utf-8");
|
|
72
72
|
return JSON.parse(content);
|
|
73
73
|
}
|
|
74
|
-
catch
|
|
74
|
+
catch {
|
|
75
75
|
throw new errors_1.MindeeError("File is not a valid dictionary.");
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -87,7 +87,7 @@ class LocalResponse {
|
|
|
87
87
|
hmac.update(this.file);
|
|
88
88
|
return hmac.digest("hex");
|
|
89
89
|
}
|
|
90
|
-
catch
|
|
90
|
+
catch {
|
|
91
91
|
throw new errors_1.MindeeError("Could not get HMAC signature from payload.");
|
|
92
92
|
}
|
|
93
93
|
}
|
package/src/input/pageOptions.js
CHANGED
|
@@ -10,4 +10,4 @@ var PageOptionsOperation;
|
|
|
10
10
|
PageOptionsOperation["KeepOnly"] = "KEEP_ONLY";
|
|
11
11
|
/** Remove pages matching the provided indexes. */
|
|
12
12
|
PageOptionsOperation["Remove"] = "REMOVE";
|
|
13
|
-
})(PageOptionsOperation
|
|
13
|
+
})(PageOptionsOperation || (exports.PageOptionsOperation = PageOptionsOperation = {}));
|
package/src/input/sources.d.ts
CHANGED
|
@@ -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");
|
|
@@ -58,7 +58,7 @@ ${this.prediction.toString()}
|
|
|
58
58
|
if (!("extras" in rawPrediction) || !("full_text_ocr" in rawPrediction["extras"])) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
-
const fullTextOcr = rawPrediction
|
|
61
|
+
const fullTextOcr = rawPrediction["extras"]["full_text_ocr"]["content"];
|
|
62
62
|
const artificialTextObj = {
|
|
63
63
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
64
64
|
"full_text_ocr": {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.cleanOutString = cleanOutString;
|
|
4
|
+
exports.lineSeparator = lineSeparator;
|
|
5
|
+
exports.cleanSpecialChars = cleanSpecialChars;
|
|
6
|
+
exports.floatToString = floatToString;
|
|
4
7
|
function cleanOutString(outStr) {
|
|
5
8
|
const lines = / \n/gm;
|
|
6
9
|
return outStr.replace(lines, "\n");
|
|
7
10
|
}
|
|
8
|
-
exports.cleanOutString = cleanOutString;
|
|
9
11
|
/**
|
|
10
12
|
*
|
|
11
13
|
* @param columnSizes Size of each column in the table
|
|
@@ -19,7 +21,6 @@ function lineSeparator(columnSizes, separator) {
|
|
|
19
21
|
});
|
|
20
22
|
return outStr;
|
|
21
23
|
}
|
|
22
|
-
exports.lineSeparator = lineSeparator;
|
|
23
24
|
/**
|
|
24
25
|
* Replaces all special characters like \n, \r, \t, with an equivalent that can be displayed on a single line.
|
|
25
26
|
* Also trims line breaks at the end of the string.
|
|
@@ -31,7 +32,6 @@ function cleanSpecialChars(outStr) {
|
|
|
31
32
|
.replace(/\r/g, "\\r")
|
|
32
33
|
.replace(/\t/g, "\\t");
|
|
33
34
|
}
|
|
34
|
-
exports.cleanSpecialChars = cleanSpecialChars;
|
|
35
35
|
/**
|
|
36
36
|
* Return a float as a string with at least 2 levels of precision.
|
|
37
37
|
*/
|
|
@@ -45,4 +45,3 @@ function floatToString(value) {
|
|
|
45
45
|
useGrouping: false,
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
exports.floatToString = floatToString;
|
|
@@ -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;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CustomLines = exports.CustomLine = void 0;
|
|
4
|
+
exports.getLineItems = getLineItems;
|
|
4
5
|
const handler_1 = require("../../errors/handler");
|
|
5
6
|
const errors_1 = require("../../errors");
|
|
6
7
|
const geometry_1 = require("../../geometry");
|
|
@@ -72,7 +73,6 @@ function getLineItems(anchorNames, fieldNames, fields, heightLineTolerance) {
|
|
|
72
73
|
});
|
|
73
74
|
return linesPrepared;
|
|
74
75
|
}
|
|
75
|
-
exports.getLineItems = getLineItems;
|
|
76
76
|
/**
|
|
77
77
|
* Loop through the possible anchor fields and find the one with the most values.
|
|
78
78
|
*/
|