mindee 4.29.0-rc5 → 4.29.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 +17 -24
- package/package.json +5 -5
- package/src/client.js +4 -3
- package/src/clientV2.d.ts +3 -38
- package/src/clientV2.js +6 -66
- package/src/geometry/boundingBox.d.ts +4 -1
- package/src/geometry/boundingBox.js +9 -1
- package/src/geometry/boundingBoxUtils.js +1 -6
- package/src/geometry/index.js +2 -1
- package/src/geometry/polygon.d.ts +22 -0
- package/src/geometry/polygon.js +36 -0
- package/src/geometry/polygonUtils.d.ts +8 -9
- package/src/index.d.ts +2 -1
- package/src/index.js +6 -1
- package/src/input/localResponse.d.ts +5 -5
- package/src/input/localResponse.js +17 -7
- package/src/input/sources/base64Input.js +1 -0
- package/src/input/sources/bufferInput.js +1 -0
- package/src/input/sources/bytesInput.js +1 -0
- package/src/input/sources/inputSource.d.ts +2 -0
- package/src/input/sources/inputSource.js +4 -0
- package/src/input/sources/localInputSource.d.ts +2 -2
- package/src/input/sources/localInputSource.js +16 -4
- package/src/input/sources/pathInput.js +1 -0
- package/src/input/sources/streamInput.js +1 -0
- package/src/input/sources/urlInput.js +1 -0
- package/src/parsing/custom/listField.d.ts +2 -2
- package/src/parsing/custom/listField.js +1 -6
- package/src/parsing/standard/field.js +1 -1
- package/src/parsing/v2/field/baseField.d.ts +2 -0
- package/src/parsing/v2/field/baseField.js +7 -1
- package/src/parsing/v2/field/fieldConfidence.d.ts +4 -4
- package/src/parsing/v2/field/fieldConfidence.js +5 -4
- package/src/parsing/v2/field/fieldFactory.d.ts +1 -1
- package/src/parsing/v2/field/fieldLocation.js +2 -4
- package/src/parsing/v2/field/inferenceFields.d.ts +3 -0
- package/src/parsing/v2/field/inferenceFields.js +30 -0
- package/src/parsing/v2/field/listField.d.ts +8 -0
- package/src/parsing/v2/field/listField.js +31 -0
- package/src/parsing/v2/field/objectField.d.ts +4 -2
- package/src/parsing/v2/field/objectField.js +14 -2
- package/src/parsing/v2/field/simpleField.d.ts +14 -2
- package/src/parsing/v2/field/simpleField.js +29 -2
- package/src/parsing/v2/index.d.ts +0 -1
- package/src/parsing/v2/index.js +1 -3
- package/src/parsing/v2/inferenceResult.d.ts +4 -4
- package/src/parsing/v2/inferenceResult.js +5 -8
- package/src/parsing/v2/rawText.d.ts +3 -9
- package/src/parsing/v2/rawText.js +2 -5
- package/src/parsing/v2/rawTextPage.d.ts +11 -0
- package/src/parsing/v2/rawTextPage.js +12 -0
- package/src/product/billOfLading/billOfLadingV1Carrier.js +2 -1
- package/src/product/billOfLading/billOfLadingV1CarrierItem.js +2 -1
- package/src/product/billOfLading/billOfLadingV1Consignee.js +2 -1
- package/src/product/billOfLading/billOfLadingV1NotifyParty.js +2 -1
- package/src/product/billOfLading/billOfLadingV1Shipper.js +2 -1
- package/src/product/financialDocument/financialDocumentV1LineItem.js +2 -1
- package/src/product/fr/bankAccountDetails/bankAccountDetailsV2Bban.js +2 -1
- package/src/product/fr/energyBill/energyBillV1EnergyConsumer.js +2 -1
- package/src/product/fr/energyBill/energyBillV1EnergySupplier.js +2 -1
- package/src/product/fr/energyBill/energyBillV1EnergyUsage.js +2 -1
- package/src/product/fr/energyBill/energyBillV1MeterDetail.js +2 -1
- package/src/product/fr/energyBill/energyBillV1Subscription.js +2 -1
- package/src/product/fr/energyBill/energyBillV1TaxesAndContribution.js +2 -1
- package/src/product/fr/payslip/payslipV2BankAccountDetail.js +2 -1
- package/src/product/fr/payslip/payslipV2Employee.js +2 -1
- package/src/product/fr/payslip/payslipV2Employer.js +2 -1
- package/src/product/fr/payslip/payslipV2Employment.js +2 -1
- package/src/product/fr/payslip/payslipV2PayDetail.js +2 -1
- package/src/product/fr/payslip/payslipV2PayPeriod.js +2 -1
- package/src/product/fr/payslip/payslipV2Pto.js +2 -1
- package/src/product/fr/payslip/payslipV2SalaryDetail.js +2 -1
- package/src/product/fr/payslip/payslipV3BankAccountDetail.js +2 -1
- package/src/product/fr/payslip/payslipV3Employee.js +2 -1
- package/src/product/fr/payslip/payslipV3Employer.js +2 -1
- package/src/product/fr/payslip/payslipV3Employment.js +2 -1
- package/src/product/fr/payslip/payslipV3PaidTimeOff.js +2 -1
- package/src/product/fr/payslip/payslipV3PayDetail.js +2 -1
- package/src/product/fr/payslip/payslipV3PayPeriod.js +2 -1
- package/src/product/fr/payslip/payslipV3SalaryDetail.js +2 -1
- package/src/product/invoice/invoiceV4LineItem.js +2 -1
- package/src/product/invoiceSplitter/invoiceSplitterV1InvoicePageGroup.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1AddedSugar.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Calorie.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Cholesterol.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1DietaryFiber.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Nutrient.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Protein.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1SaturatedFat.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1ServingSize.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1Sodium.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TotalCarbohydrate.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TotalFat.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TotalSugar.js +2 -1
- package/src/product/nutritionFactsLabel/nutritionFactsLabelV1TransFat.js +2 -1
- package/src/product/receipt/receiptV5LineItem.js +2 -1
- package/src/product/resume/resumeV1Certificate.js +2 -1
- package/src/product/resume/resumeV1Education.js +2 -1
- package/src/product/resume/resumeV1Language.js +2 -1
- package/src/product/resume/resumeV1ProfessionalExperience.js +2 -1
- package/src/product/resume/resumeV1SocialNetworksUrl.js +2 -1
- package/src/product/us/healthcareCard/healthcareCardV1Copay.js +2 -1
- package/src/product/us/usMail/usMailV2RecipientAddress.js +2 -1
- package/src/product/us/usMail/usMailV2SenderAddress.js +2 -1
- package/src/product/us/usMail/usMailV3RecipientAddress.js +2 -1
- package/src/product/us/usMail/usMailV3SenderAddress.js +2 -1
- package/src/parsing/v2/field/dynamicField.d.ts +0 -7
- package/src/parsing/v2/field/dynamicField.js +0 -16
- package/src/parsing/v2/inferenceResultOptions.d.ts +0 -9
- package/src/parsing/v2/inferenceResultOptions.js +0 -10
|
@@ -47,6 +47,7 @@ class LocalResponse {
|
|
|
47
47
|
* Creates an instance of LocalResponse.
|
|
48
48
|
*/
|
|
49
49
|
constructor(inputFile) {
|
|
50
|
+
this.initialized = false;
|
|
50
51
|
this.file = buffer_1.Buffer.alloc(0);
|
|
51
52
|
this.inputHandle = inputFile;
|
|
52
53
|
}
|
|
@@ -71,12 +72,16 @@ class LocalResponse {
|
|
|
71
72
|
else {
|
|
72
73
|
throw new errors_1.MindeeError("Incompatible type for input.");
|
|
73
74
|
}
|
|
75
|
+
this.initialized = true;
|
|
74
76
|
}
|
|
75
77
|
/**
|
|
76
78
|
* Returns the dictionary representation of the file.
|
|
77
79
|
* @returns A JSON-like object.
|
|
78
80
|
*/
|
|
79
|
-
asDict() {
|
|
81
|
+
async asDict() {
|
|
82
|
+
if (!this.initialized) {
|
|
83
|
+
await this.init();
|
|
84
|
+
}
|
|
80
85
|
try {
|
|
81
86
|
const content = this.file.toString("utf-8");
|
|
82
87
|
return JSON.parse(content);
|
|
@@ -91,6 +96,9 @@ class LocalResponse {
|
|
|
91
96
|
* @returns The HMAC signature of the local response.
|
|
92
97
|
*/
|
|
93
98
|
getHmacSignature(secretKey) {
|
|
99
|
+
if (!this.initialized) {
|
|
100
|
+
throw new Error("The `init()` method must be called before calling `getHmacSignature()`.");
|
|
101
|
+
}
|
|
94
102
|
const algorithm = "sha256";
|
|
95
103
|
try {
|
|
96
104
|
const hmac = crypto.createHmac(algorithm, secretKey);
|
|
@@ -108,25 +116,27 @@ class LocalResponse {
|
|
|
108
116
|
* @returns True if the HMAC signature is valid.
|
|
109
117
|
*/
|
|
110
118
|
isValidHmacSignature(secretKey, signature) {
|
|
119
|
+
if (!this.initialized) {
|
|
120
|
+
throw new Error("The `init()` method must be called before calling `isValidHmacSignature()`.");
|
|
121
|
+
}
|
|
111
122
|
return signature === this.getHmacSignature(secretKey);
|
|
112
123
|
}
|
|
113
124
|
/**
|
|
114
|
-
* Deserialize the loaded local response into the requested CommonResponse
|
|
125
|
+
* Deserialize the loaded local response into the requested CommonResponse-derived class.
|
|
115
126
|
*
|
|
116
127
|
* Typically used when dealing with V2 webhook callbacks.
|
|
117
128
|
*
|
|
118
129
|
* @typeParam ResponseT - A class that extends `CommonResponse`.
|
|
119
|
-
* @param responseClass - The constructor of the class into which
|
|
120
|
-
* the payload should be deserialized.
|
|
130
|
+
* @param responseClass - The constructor of the class into which the payload should be deserialized.
|
|
121
131
|
* @returns An instance of `responseClass` populated with the file content.
|
|
122
132
|
* @throws MindeeError If the provided class cannot be instantiated.
|
|
123
133
|
*/
|
|
124
|
-
deserializeResponse(responseClass) {
|
|
134
|
+
async deserializeResponse(responseClass) {
|
|
125
135
|
try {
|
|
126
|
-
return new responseClass(this.asDict());
|
|
136
|
+
return new responseClass(await this.asDict());
|
|
127
137
|
}
|
|
128
138
|
catch {
|
|
129
|
-
throw new errors_1.MindeeError("Invalid
|
|
139
|
+
throw new errors_1.MindeeError("Invalid response provided.");
|
|
130
140
|
}
|
|
131
141
|
}
|
|
132
142
|
}
|
|
@@ -16,6 +16,7 @@ class BytesInput extends localInputSource_1.LocalInputSource {
|
|
|
16
16
|
this.fileObject = Buffer.from(this.inputBytes);
|
|
17
17
|
this.mimeType = await this.checkMimetype();
|
|
18
18
|
this.inputBytes = new Uint8Array(0);
|
|
19
|
+
this.initialized = true;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
exports.BytesInput = BytesInput;
|
|
@@ -12,5 +12,7 @@ export declare const INPUT_TYPE_PATH = "path";
|
|
|
12
12
|
export declare const INPUT_TYPE_BUFFER = "buffer";
|
|
13
13
|
export declare abstract class InputSource {
|
|
14
14
|
fileObject: Buffer | string;
|
|
15
|
+
protected initialized: boolean;
|
|
15
16
|
init(): Promise<void>;
|
|
17
|
+
isInitialized(): boolean;
|
|
16
18
|
}
|
|
@@ -9,9 +9,13 @@ exports.INPUT_TYPE_BUFFER = "buffer";
|
|
|
9
9
|
class InputSource {
|
|
10
10
|
constructor() {
|
|
11
11
|
this.fileObject = "";
|
|
12
|
+
this.initialized = false;
|
|
12
13
|
}
|
|
13
14
|
async init() {
|
|
14
15
|
throw new Error("not Implemented");
|
|
15
16
|
}
|
|
17
|
+
isInitialized() {
|
|
18
|
+
return this.initialized;
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
21
|
exports.InputSource = InputSource;
|
|
@@ -10,8 +10,8 @@ export declare abstract class LocalInputSource extends InputSource {
|
|
|
10
10
|
* @param {InputConstructor} constructor Constructor parameters.
|
|
11
11
|
*/
|
|
12
12
|
protected constructor({ inputType }: InputConstructor);
|
|
13
|
+
protected checkMimetype(): Promise<string>;
|
|
13
14
|
isPdf(): boolean;
|
|
14
|
-
checkMimetype(): Promise<string>;
|
|
15
15
|
/**
|
|
16
16
|
* Cut PDF pages.
|
|
17
17
|
* @param pageOptions
|
|
@@ -20,7 +20,7 @@ export declare abstract class LocalInputSource extends InputSource {
|
|
|
20
20
|
/**
|
|
21
21
|
* Cut PDF pages.
|
|
22
22
|
* @param pageOptions
|
|
23
|
-
* @deprecated Deprecated in favor of {@link LocalInputSource.applyPageOptions
|
|
23
|
+
* @deprecated Deprecated in favor of {@link LocalInputSource.applyPageOptions}.
|
|
24
24
|
*/
|
|
25
25
|
cutPdf(pageOptions: PageOptions): Promise<void>;
|
|
26
26
|
/**
|
|
@@ -78,9 +78,6 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
78
78
|
this.inputType = inputType;
|
|
79
79
|
logger_1.logger.debug(`Loading file from: ${inputType}`);
|
|
80
80
|
}
|
|
81
|
-
isPdf() {
|
|
82
|
-
return this.mimeType === "application/pdf";
|
|
83
|
-
}
|
|
84
81
|
async checkMimetype() {
|
|
85
82
|
if (!(this.fileObject instanceof Buffer)) {
|
|
86
83
|
throw new Error(`MIME type cannot be verified on input source of type ${this.inputType}.`);
|
|
@@ -107,11 +104,20 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
107
104
|
logger_1.logger.debug(`File is of type: ${mimeType}`);
|
|
108
105
|
return mimeType;
|
|
109
106
|
}
|
|
107
|
+
isPdf() {
|
|
108
|
+
if (!this.initialized) {
|
|
109
|
+
throw new Error("The `init()` method must be called before calling `isPdf()`.");
|
|
110
|
+
}
|
|
111
|
+
return this.mimeType === "application/pdf";
|
|
112
|
+
}
|
|
110
113
|
/**
|
|
111
114
|
* Cut PDF pages.
|
|
112
115
|
* @param pageOptions
|
|
113
116
|
*/
|
|
114
117
|
async applyPageOptions(pageOptions) {
|
|
118
|
+
if (!this.initialized) {
|
|
119
|
+
await this.init();
|
|
120
|
+
}
|
|
115
121
|
if (!(this.fileObject instanceof Buffer)) {
|
|
116
122
|
throw new Error(`Cannot modify an input source of type ${this.inputType}.`);
|
|
117
123
|
}
|
|
@@ -121,7 +127,7 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
121
127
|
/**
|
|
122
128
|
* Cut PDF pages.
|
|
123
129
|
* @param pageOptions
|
|
124
|
-
* @deprecated Deprecated in favor of {@link LocalInputSource.applyPageOptions
|
|
130
|
+
* @deprecated Deprecated in favor of {@link LocalInputSource.applyPageOptions}.
|
|
125
131
|
*/
|
|
126
132
|
async cutPdf(pageOptions) {
|
|
127
133
|
return this.applyPageOptions(pageOptions);
|
|
@@ -139,6 +145,9 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
139
145
|
* @returns A Promise that resolves when the compression is complete.
|
|
140
146
|
*/
|
|
141
147
|
async compress(quality = 85, maxWidth = null, maxHeight = null, forceSourceText = false, disableSourceText = true) {
|
|
148
|
+
if (!this.initialized) {
|
|
149
|
+
await this.init();
|
|
150
|
+
}
|
|
142
151
|
let buffer;
|
|
143
152
|
if (typeof this.fileObject === "string") {
|
|
144
153
|
buffer = Buffer.from(this.fileObject);
|
|
@@ -158,6 +167,9 @@ class LocalInputSource extends inputSource_1.InputSource {
|
|
|
158
167
|
* @return boolean
|
|
159
168
|
*/
|
|
160
169
|
async hasSourceText() {
|
|
170
|
+
if (!this.initialized) {
|
|
171
|
+
await this.init();
|
|
172
|
+
}
|
|
161
173
|
if (!this.isPdf()) {
|
|
162
174
|
return false;
|
|
163
175
|
}
|
|
@@ -22,6 +22,7 @@ class PathInput extends localInputSource_1.LocalInputSource {
|
|
|
22
22
|
logger_1.logger.debug(`Loading from: ${this.inputPath}`);
|
|
23
23
|
this.fileObject = Buffer.from(await fs_1.promises.readFile(this.inputPath));
|
|
24
24
|
this.mimeType = await this.checkMimetype();
|
|
25
|
+
this.initialized = true;
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
exports.PathInput = PathInput;
|
|
@@ -15,6 +15,7 @@ class StreamInput extends localInputSource_1.LocalInputSource {
|
|
|
15
15
|
async init() {
|
|
16
16
|
this.fileObject = await this.stream2buffer(this.inputStream);
|
|
17
17
|
this.mimeType = await this.checkMimetype();
|
|
18
|
+
this.initialized = true;
|
|
18
19
|
}
|
|
19
20
|
async stream2buffer(stream) {
|
|
20
21
|
return new Promise((resolve, reject) => {
|
|
@@ -18,6 +18,7 @@ class UrlInput extends inputSource_1.InputSource {
|
|
|
18
18
|
throw new Error("URL must be HTTPS");
|
|
19
19
|
}
|
|
20
20
|
this.fileObject = this.url;
|
|
21
|
+
this.initialized = true;
|
|
21
22
|
}
|
|
22
23
|
async fetchFileContent(options) {
|
|
23
24
|
const { username, password, token, headers = {}, maxRedirects = 3 } = options;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseFieldConstructor } from "../standard";
|
|
2
|
-
import { Polygon } from "../../geometry";
|
|
2
|
+
import { Polygon, BoundingBox } from "../../geometry";
|
|
3
3
|
import { StringDict } from "../common";
|
|
4
4
|
export declare class ListFieldValue {
|
|
5
5
|
/** Extracted content of the prediction */
|
|
@@ -13,7 +13,7 @@ export declare class ListFieldValue {
|
|
|
13
13
|
* Contains exactly 4 relative vertices coordinates (points) of a right
|
|
14
14
|
* rectangle containing the word in the document.
|
|
15
15
|
*/
|
|
16
|
-
bbox
|
|
16
|
+
bbox?: BoundingBox;
|
|
17
17
|
/**
|
|
18
18
|
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
19
19
|
* the word in the document.
|
|
@@ -4,16 +4,11 @@ exports.ListField = exports.ListFieldValue = void 0;
|
|
|
4
4
|
const geometry_1 = require("../../geometry");
|
|
5
5
|
class ListFieldValue {
|
|
6
6
|
constructor(prediction, pageId) {
|
|
7
|
-
/**
|
|
8
|
-
* Contains exactly 4 relative vertices coordinates (points) of a right
|
|
9
|
-
* rectangle containing the word in the document.
|
|
10
|
-
*/
|
|
11
|
-
this.bbox = [];
|
|
12
7
|
/**
|
|
13
8
|
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
14
9
|
* the word in the document.
|
|
15
10
|
*/
|
|
16
|
-
this.polygon =
|
|
11
|
+
this.polygon = new geometry_1.Polygon();
|
|
17
12
|
this.content = prediction["content"];
|
|
18
13
|
this.confidence = prediction["confidence"];
|
|
19
14
|
if (prediction["polygon"]) {
|
|
@@ -16,7 +16,7 @@ class Field extends base_1.BaseField {
|
|
|
16
16
|
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
17
17
|
* the field in the document.
|
|
18
18
|
*/
|
|
19
|
-
this.polygon =
|
|
19
|
+
this.polygon = new geometry_1.Polygon();
|
|
20
20
|
this.confidence = prediction["confidence"] ? prediction["confidence"] : 0.0;
|
|
21
21
|
if (prediction["polygon"]) {
|
|
22
22
|
this.polygon = prediction["polygon"];
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { FieldConfidence } from "./fieldConfidence";
|
|
2
2
|
import { StringDict } from "../../common";
|
|
3
|
+
import { FieldLocation } from "./fieldLocation";
|
|
3
4
|
export declare abstract class BaseField {
|
|
4
5
|
protected _indentLevel: number;
|
|
5
6
|
confidence: FieldConfidence | undefined;
|
|
7
|
+
locations: Array<FieldLocation> | undefined;
|
|
6
8
|
protected constructor(rawResponse: StringDict, indentLevel?: number);
|
|
7
9
|
}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseField = void 0;
|
|
4
|
+
const fieldLocation_1 = require("./fieldLocation");
|
|
4
5
|
class BaseField {
|
|
5
6
|
constructor(rawResponse, indentLevel = 0) {
|
|
6
7
|
this._indentLevel = indentLevel;
|
|
7
|
-
if (rawResponse["confidence"] !==
|
|
8
|
+
if ("confidence" in rawResponse && rawResponse["confidence"] !== null) {
|
|
8
9
|
this.confidence = rawResponse["confidence"];
|
|
9
10
|
}
|
|
11
|
+
if ("locations" in rawResponse && rawResponse["locations"]) {
|
|
12
|
+
this.locations = rawResponse["locations"].map((location) => {
|
|
13
|
+
return location ? new fieldLocation_1.FieldLocation(location) : "";
|
|
14
|
+
});
|
|
15
|
+
}
|
|
10
16
|
}
|
|
11
17
|
}
|
|
12
18
|
exports.BaseField = BaseField;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.FieldConfidence = void 0;
|
|
4
5
|
/**
|
|
@@ -6,8 +7,8 @@ exports.FieldConfidence = void 0;
|
|
|
6
7
|
*/
|
|
7
8
|
var FieldConfidence;
|
|
8
9
|
(function (FieldConfidence) {
|
|
9
|
-
FieldConfidence["
|
|
10
|
-
FieldConfidence["
|
|
11
|
-
FieldConfidence["
|
|
12
|
-
FieldConfidence["
|
|
10
|
+
FieldConfidence["Certain"] = "Certain";
|
|
11
|
+
FieldConfidence["High"] = "High";
|
|
12
|
+
FieldConfidence["Medium"] = "Medium";
|
|
13
|
+
FieldConfidence["Low"] = "Low";
|
|
13
14
|
})(FieldConfidence || (exports.FieldConfidence = FieldConfidence = {}));
|
|
@@ -5,4 +5,4 @@ import { StringDict } from "../../common";
|
|
|
5
5
|
import { ListField } from "./listField";
|
|
6
6
|
import { ObjectField } from "./objectField";
|
|
7
7
|
import { SimpleField } from "./simpleField";
|
|
8
|
-
export declare function createField(serverResponse: StringDict, indentLevel?: number):
|
|
8
|
+
export declare function createField(serverResponse: StringDict, indentLevel?: number): SimpleField | ObjectField | ListField;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FieldLocation = void 0;
|
|
4
|
-
const geometry_1 = require("../../../geometry");
|
|
5
4
|
/**
|
|
6
5
|
* Location of a field.
|
|
7
6
|
*/
|
|
8
7
|
class FieldLocation {
|
|
9
8
|
constructor(serverResponse) {
|
|
10
|
-
this.polygon =
|
|
11
|
-
this.page = "
|
|
12
|
-
typeof serverResponse["page"] === "number" ? serverResponse["page"] : undefined;
|
|
9
|
+
this.polygon = serverResponse["polygon"];
|
|
10
|
+
this.page = "page" in serverResponse ? serverResponse["page"] : undefined;
|
|
13
11
|
}
|
|
14
12
|
toString() {
|
|
15
13
|
return this.polygon?.toString() ?? "";
|
|
@@ -5,5 +5,8 @@ import type { SimpleField } from "./simpleField";
|
|
|
5
5
|
export declare class InferenceFields extends Map<string, SimpleField | ObjectField | ListField> {
|
|
6
6
|
protected _indentLevel: number;
|
|
7
7
|
constructor(serverResponse: StringDict, indentLevel?: number);
|
|
8
|
+
getSimpleField(fieldName: string): SimpleField;
|
|
9
|
+
getObjectField(fieldName: string): ObjectField;
|
|
10
|
+
getListField(fieldName: string): ListField;
|
|
8
11
|
toString(indent?: number): string;
|
|
9
12
|
}
|
|
@@ -9,6 +9,36 @@ class InferenceFields extends Map {
|
|
|
9
9
|
}));
|
|
10
10
|
this._indentLevel = indentLevel;
|
|
11
11
|
}
|
|
12
|
+
getSimpleField(fieldName) {
|
|
13
|
+
const field = this.get(fieldName);
|
|
14
|
+
if (field === undefined) {
|
|
15
|
+
throw new Error(`The field '${fieldName}' was not found.`);
|
|
16
|
+
}
|
|
17
|
+
if (field.constructor.name !== "SimpleField") {
|
|
18
|
+
throw new Error(`The field '${fieldName}' is not a SimpleField.`);
|
|
19
|
+
}
|
|
20
|
+
return field;
|
|
21
|
+
}
|
|
22
|
+
getObjectField(fieldName) {
|
|
23
|
+
const field = this.get(fieldName);
|
|
24
|
+
if (field === undefined) {
|
|
25
|
+
throw new Error(`The field '${fieldName}' was not found.`);
|
|
26
|
+
}
|
|
27
|
+
if (field.constructor.name !== "ObjectField") {
|
|
28
|
+
throw new Error(`The field '${fieldName}' is not an ObjectField.`);
|
|
29
|
+
}
|
|
30
|
+
return field;
|
|
31
|
+
}
|
|
32
|
+
getListField(fieldName) {
|
|
33
|
+
const field = this.get(fieldName);
|
|
34
|
+
if (field === undefined) {
|
|
35
|
+
throw new Error(`The field '${fieldName}' was not found.`);
|
|
36
|
+
}
|
|
37
|
+
if (field.constructor.name !== "ListField") {
|
|
38
|
+
throw new Error(`The field '${fieldName}' is not a ListField.`);
|
|
39
|
+
}
|
|
40
|
+
return field;
|
|
41
|
+
}
|
|
12
42
|
toString(indent = this._indentLevel) {
|
|
13
43
|
if (this.size === 0) {
|
|
14
44
|
return "";
|
|
@@ -7,6 +7,14 @@ export declare class ListField extends BaseField {
|
|
|
7
7
|
* Items contained in the list.
|
|
8
8
|
*/
|
|
9
9
|
items: Array<ListField | ObjectField | SimpleField>;
|
|
10
|
+
/**
|
|
11
|
+
* SimpleField items from the list.
|
|
12
|
+
*/
|
|
13
|
+
get simpleItems(): Array<SimpleField>;
|
|
14
|
+
/**
|
|
15
|
+
* SimpleField items from the list.
|
|
16
|
+
*/
|
|
17
|
+
get objectItems(): Array<ObjectField>;
|
|
10
18
|
constructor(serverResponse: StringDict, indentLevel?: number);
|
|
11
19
|
toString(): string;
|
|
12
20
|
}
|
|
@@ -4,8 +4,39 @@ exports.ListField = void 0;
|
|
|
4
4
|
const mindeeError_1 = require("../../../errors/mindeeError");
|
|
5
5
|
const baseField_1 = require("./baseField");
|
|
6
6
|
const objectField_1 = require("./objectField");
|
|
7
|
+
const simpleField_1 = require("./simpleField");
|
|
7
8
|
const fieldFactory_1 = require("./fieldFactory");
|
|
8
9
|
class ListField extends baseField_1.BaseField {
|
|
10
|
+
/**
|
|
11
|
+
* SimpleField items from the list.
|
|
12
|
+
*/
|
|
13
|
+
get simpleItems() {
|
|
14
|
+
const result = [];
|
|
15
|
+
for (const item of this.items) {
|
|
16
|
+
if (item instanceof simpleField_1.SimpleField) {
|
|
17
|
+
result.push(item);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
throw new mindeeError_1.MindeeApiV2Error(`All items must be SimpleField, found item of type ${item.constructor.name}.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* SimpleField items from the list.
|
|
27
|
+
*/
|
|
28
|
+
get objectItems() {
|
|
29
|
+
const result = [];
|
|
30
|
+
for (const item of this.items) {
|
|
31
|
+
if (item instanceof objectField_1.ObjectField) {
|
|
32
|
+
result.push(item);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new mindeeError_1.MindeeApiV2Error(`All items must be ObjectField, found item of type ${item.constructor.name}.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
9
40
|
constructor(serverResponse, indentLevel = 0) {
|
|
10
41
|
super(serverResponse, indentLevel);
|
|
11
42
|
if (!Array.isArray(serverResponse["items"])) {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { InferenceFields } from "./inferenceFields";
|
|
2
2
|
import { StringDict } from "../../common";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { BaseField } from "./baseField";
|
|
4
|
+
import type { SimpleField } from "./simpleField";
|
|
5
|
+
export declare class ObjectField extends BaseField {
|
|
5
6
|
readonly fields: InferenceFields;
|
|
7
|
+
get simpleFields(): Map<string, SimpleField>;
|
|
6
8
|
constructor(serverResponse: StringDict, indentLevel?: number);
|
|
7
9
|
toString(): string;
|
|
8
10
|
toStringFromList(): string;
|
|
@@ -2,8 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObjectField = void 0;
|
|
4
4
|
const inferenceFields_1 = require("./inferenceFields");
|
|
5
|
-
const
|
|
6
|
-
class ObjectField extends
|
|
5
|
+
const baseField_1 = require("./baseField");
|
|
6
|
+
class ObjectField extends baseField_1.BaseField {
|
|
7
|
+
get simpleFields() {
|
|
8
|
+
const result = new Map();
|
|
9
|
+
for (const [fieldName, fieldValue] of this.fields) {
|
|
10
|
+
if (fieldValue.constructor.name === "SimpleField") {
|
|
11
|
+
result.set(fieldName, fieldValue);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
throw new Error(`The field '${fieldName}' is not a SimpleField.`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
7
19
|
constructor(serverResponse, indentLevel = 0) {
|
|
8
20
|
super(serverResponse, indentLevel);
|
|
9
21
|
this.fields = new inferenceFields_1.InferenceFields(serverResponse["fields"], this._indentLevel + 1);
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { StringDict } from "../../common";
|
|
2
|
-
import {
|
|
3
|
-
export declare class SimpleField extends
|
|
2
|
+
import { BaseField } from "./baseField";
|
|
3
|
+
export declare class SimpleField extends BaseField {
|
|
4
4
|
readonly value: string | number | boolean | null;
|
|
5
5
|
constructor(serverResponse: StringDict, indentLevel?: number);
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves a string field value as a string.
|
|
8
|
+
*/
|
|
9
|
+
get stringValue(): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves a number field value as a number.
|
|
12
|
+
*/
|
|
13
|
+
get numberValue(): number | null;
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves a boolean field value as a boolean.
|
|
16
|
+
*/
|
|
17
|
+
get booleanValue(): boolean | null;
|
|
6
18
|
toString(): string;
|
|
7
19
|
}
|
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SimpleField = void 0;
|
|
4
|
-
const
|
|
5
|
-
class SimpleField extends
|
|
4
|
+
const baseField_1 = require("./baseField");
|
|
5
|
+
class SimpleField extends baseField_1.BaseField {
|
|
6
6
|
constructor(serverResponse, indentLevel = 0) {
|
|
7
7
|
super(serverResponse, indentLevel);
|
|
8
8
|
this.value =
|
|
9
9
|
serverResponse["value"] !== undefined ? serverResponse["value"] : null;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves a string field value as a string.
|
|
13
|
+
*/
|
|
14
|
+
get stringValue() {
|
|
15
|
+
if (this.value !== null && typeof this.value !== "string") {
|
|
16
|
+
throw new Error("Value is not a string");
|
|
17
|
+
}
|
|
18
|
+
return this.value;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves a number field value as a number.
|
|
22
|
+
*/
|
|
23
|
+
get numberValue() {
|
|
24
|
+
if (this.value !== null && typeof this.value !== "number") {
|
|
25
|
+
throw new Error("Value is not a number");
|
|
26
|
+
}
|
|
27
|
+
return this.value;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves a boolean field value as a boolean.
|
|
31
|
+
*/
|
|
32
|
+
get booleanValue() {
|
|
33
|
+
if (this.value !== null && typeof this.value !== "boolean") {
|
|
34
|
+
throw new Error("Value is not a boolean");
|
|
35
|
+
}
|
|
36
|
+
return this.value;
|
|
37
|
+
}
|
|
11
38
|
toString() {
|
|
12
39
|
if (this.value === null) {
|
|
13
40
|
return "";
|
|
@@ -3,7 +3,6 @@ export { ErrorResponse } from "./errorResponse";
|
|
|
3
3
|
export { Inference } from "./inference";
|
|
4
4
|
export { InferenceFile } from "./inferenceFile";
|
|
5
5
|
export { InferenceModel } from "./inferenceModel";
|
|
6
|
-
export { InferenceResultOptions } from "./inferenceResultOptions";
|
|
7
6
|
export { InferenceResponse } from "./inferenceResponse";
|
|
8
7
|
export { InferenceResult } from "./inferenceResult";
|
|
9
8
|
export { Job } from "./job";
|
package/src/parsing/v2/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JobWebhook = exports.RawText = exports.JobResponse = exports.Job = exports.InferenceResult = exports.InferenceResponse = exports.
|
|
3
|
+
exports.JobWebhook = exports.RawText = exports.JobResponse = exports.Job = exports.InferenceResult = exports.InferenceResponse = exports.InferenceModel = exports.InferenceFile = exports.Inference = exports.ErrorResponse = exports.CommonResponse = void 0;
|
|
4
4
|
var commonResponse_1 = require("./commonResponse");
|
|
5
5
|
Object.defineProperty(exports, "CommonResponse", { enumerable: true, get: function () { return commonResponse_1.CommonResponse; } });
|
|
6
6
|
var errorResponse_1 = require("./errorResponse");
|
|
@@ -11,8 +11,6 @@ var inferenceFile_1 = require("./inferenceFile");
|
|
|
11
11
|
Object.defineProperty(exports, "InferenceFile", { enumerable: true, get: function () { return inferenceFile_1.InferenceFile; } });
|
|
12
12
|
var inferenceModel_1 = require("./inferenceModel");
|
|
13
13
|
Object.defineProperty(exports, "InferenceModel", { enumerable: true, get: function () { return inferenceModel_1.InferenceModel; } });
|
|
14
|
-
var inferenceResultOptions_1 = require("./inferenceResultOptions");
|
|
15
|
-
Object.defineProperty(exports, "InferenceResultOptions", { enumerable: true, get: function () { return inferenceResultOptions_1.InferenceResultOptions; } });
|
|
16
14
|
var inferenceResponse_1 = require("./inferenceResponse");
|
|
17
15
|
Object.defineProperty(exports, "InferenceResponse", { enumerable: true, get: function () { return inferenceResponse_1.InferenceResponse; } });
|
|
18
16
|
var inferenceResult_1 = require("./inferenceResult");
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { InferenceFields } from "./field
|
|
2
|
-
import { InferenceResultOptions } from "./inferenceResultOptions";
|
|
1
|
+
import { InferenceFields } from "./field";
|
|
3
2
|
import { StringDict } from "../common";
|
|
3
|
+
import { RawText } from "./rawText";
|
|
4
4
|
export declare class InferenceResult {
|
|
5
5
|
/**
|
|
6
6
|
* Fields contained in the inference.
|
|
7
7
|
*/
|
|
8
8
|
fields: InferenceFields;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Raw text extracted from all pages.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
rawText?: RawText;
|
|
13
13
|
constructor(serverResponse: StringDict);
|
|
14
14
|
toString(): string;
|
|
15
15
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InferenceResult = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const field_1 = require("./field");
|
|
5
|
+
const rawText_1 = require("./rawText");
|
|
6
6
|
class InferenceResult {
|
|
7
7
|
constructor(serverResponse) {
|
|
8
|
-
this.fields = new
|
|
9
|
-
if (serverResponse["
|
|
10
|
-
this.
|
|
8
|
+
this.fields = new field_1.InferenceFields(serverResponse["fields"]);
|
|
9
|
+
if (serverResponse["raw_text"]) {
|
|
10
|
+
this.rawText = new rawText_1.RawText(serverResponse["raw_text"]);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
toString() {
|
|
@@ -16,9 +16,6 @@ class InferenceResult {
|
|
|
16
16
|
"======",
|
|
17
17
|
this.fields.toString(),
|
|
18
18
|
];
|
|
19
|
-
if (this.options) {
|
|
20
|
-
parts.push("Options", "=======", this.options.toString());
|
|
21
|
-
}
|
|
22
19
|
return parts.join("\n");
|
|
23
20
|
}
|
|
24
21
|
}
|