mindee 2.1.1 → 3.0.1
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 -0
- package/README.md +30 -9
- package/package.json +3 -2
- package/src/api/endpoint.d.ts +19 -17
- package/src/api/endpoint.js +27 -39
- package/src/api/index.d.ts +2 -2
- package/src/api/index.js +2 -11
- package/src/api/response.d.ts +8 -41
- package/src/api/response.js +18 -89
- package/src/cli.js +46 -12
- package/src/client.d.ts +47 -13
- package/src/client.js +73 -27
- package/src/documents/cropper/cropperV1.d.ts +7 -0
- package/src/documents/{cropper.js → cropper/cropperV1.js} +12 -8
- package/src/documents/custom.d.ts +2 -6
- package/src/documents/custom.js +12 -7
- package/src/documents/document.d.ts +8 -3
- package/src/documents/document.js +11 -5
- package/src/documents/documentConfig.d.ts +20 -34
- package/src/documents/documentConfig.js +33 -57
- package/src/documents/{financialDocument.d.ts → financialDocument/financialDocumentV1.d.ts} +4 -4
- package/src/documents/{financialDocument.js → financialDocument/financialDocumentV1.js} +28 -22
- package/src/documents/fr/idCard/idCardV1.d.ts +3 -0
- package/src/documents/fr/idCard/idCardV1.js +7 -0
- package/src/documents/index.d.ts +15 -13
- package/src/documents/index.js +21 -18
- package/src/documents/{invoice.d.ts → invoice/invoiceV3.d.ts} +4 -4
- package/src/documents/{invoice.js → invoice/invoiceV3.js} +30 -24
- package/src/documents/{passport.d.ts → passport/passportV1.d.ts} +4 -4
- package/src/documents/{passport.js → passport/passportV1.js} +19 -14
- package/src/documents/receipt/receiptV3.d.ts +17 -0
- package/src/documents/{receipt.js → receipt/receiptV3.js} +28 -22
- package/src/documents/receipt/receiptV4.d.ts +27 -0
- package/src/documents/receipt/receiptV4.js +96 -0
- package/src/documents/receipt/tax.d.ts +25 -0
- package/src/documents/receipt/tax.js +40 -0
- package/src/documents/us/bankCheck/bankCheckV1.d.ts +3 -0
- package/src/documents/us/bankCheck/bankCheckV1.js +7 -0
- package/src/errors/MindeeError.d.ts +3 -0
- package/src/errors/MindeeError.js +10 -0
- package/src/errors/index.d.ts +1 -0
- package/src/errors/index.js +5 -0
- package/src/fields/{customDocs.d.ts → apiBuilder.d.ts} +5 -1
- package/src/fields/{customDocs.js → apiBuilder.js} +0 -0
- package/src/fields/index.d.ts +1 -1
- package/src/fields/index.js +4 -4
- package/src/index.d.ts +2 -1
- package/src/index.js +11 -9
- package/src/inputs/base.d.ts +33 -0
- package/src/inputs/base.js +116 -0
- package/src/inputs/index.d.ts +3 -0
- package/src/inputs/index.js +18 -0
- package/src/inputs/pageOptions.d.ts +20 -0
- package/src/inputs/pageOptions.js +8 -0
- package/src/inputs/sources.d.ts +55 -0
- package/src/inputs/sources.js +121 -0
- package/src/pdf/index.d.ts +1 -0
- package/src/pdf/index.js +6 -0
- package/src/pdf/pdfOperation.d.ts +14 -0
- package/src/pdf/pdfOperation.js +69 -0
- package/src/constants.d.ts +0 -13
- package/src/constants.js +0 -60
- package/src/documents/cropper.d.ts +0 -7
- package/src/documents/receipt.d.ts +0 -17
- package/src/inputs.d.ts +0 -69
- package/src/inputs.js +0 -196
package/src/client.d.ts
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { InputSource, PageOptions } from "./inputs";
|
|
3
3
|
import { Response } from "./api";
|
|
4
|
-
import { Document } from "./documents";
|
|
5
|
-
import { DocumentConfig
|
|
4
|
+
import { Document, DocumentSig } from "./documents";
|
|
5
|
+
import { DocumentConfig } from "./documents/documentConfig";
|
|
6
6
|
import { ReadStream } from "fs";
|
|
7
|
-
declare type DocConfigs = Map<string[], DocumentConfig
|
|
7
|
+
declare type DocConfigs = Map<string[], DocumentConfig<any>>;
|
|
8
8
|
interface PredictOptions {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
cutPages?: boolean;
|
|
9
|
+
endpointName?: string;
|
|
10
|
+
accountName?: string;
|
|
12
11
|
fullText?: boolean;
|
|
13
12
|
cropper?: boolean;
|
|
13
|
+
pageOptions?: PageOptions;
|
|
14
14
|
}
|
|
15
15
|
declare class DocumentClient {
|
|
16
|
-
|
|
16
|
+
inputSource: InputSource;
|
|
17
17
|
docConfigs: DocConfigs;
|
|
18
|
-
constructor(
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
constructor(inputSource: InputSource, docConfigs: DocConfigs);
|
|
19
|
+
/**
|
|
20
|
+
* Send a document to an endpoint and parse the predictions.
|
|
21
|
+
* @param documentClass
|
|
22
|
+
* @param params
|
|
23
|
+
*/
|
|
24
|
+
parse<DocType extends Document>(documentClass: DocumentSig<DocType>, params?: PredictOptions): Promise<Response<DocType>>;
|
|
21
25
|
}
|
|
22
26
|
interface customConfigParams {
|
|
23
27
|
accountName: string;
|
|
24
|
-
|
|
28
|
+
endpointName: string;
|
|
25
29
|
version?: string;
|
|
26
30
|
}
|
|
27
31
|
interface ClientOptions {
|
|
@@ -40,10 +44,40 @@ export declare class Client {
|
|
|
40
44
|
*/
|
|
41
45
|
constructor(options?: ClientOptions);
|
|
42
46
|
protected addStandardEndpoints(): void;
|
|
43
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Add a custom endpoint to the client.
|
|
49
|
+
* @param accountName
|
|
50
|
+
* @param endpointName
|
|
51
|
+
* @param version
|
|
52
|
+
*/
|
|
53
|
+
addEndpoint({ accountName, endpointName, version, }: customConfigParams): this;
|
|
54
|
+
/**
|
|
55
|
+
* Load an input document from a local path.
|
|
56
|
+
* @param inputPath
|
|
57
|
+
*/
|
|
44
58
|
docFromPath(inputPath: string): DocumentClient;
|
|
59
|
+
/**
|
|
60
|
+
* Load an input document from a base64 encoded string.
|
|
61
|
+
* @param inputString
|
|
62
|
+
* @param filename
|
|
63
|
+
*/
|
|
45
64
|
docFromBase64(inputString: string, filename: string): DocumentClient;
|
|
65
|
+
/**
|
|
66
|
+
* Load an input document from a `ReadStream`.
|
|
67
|
+
* @param inputStream
|
|
68
|
+
* @param filename
|
|
69
|
+
*/
|
|
46
70
|
docFromStream(inputStream: ReadStream, filename: string): DocumentClient;
|
|
71
|
+
/**
|
|
72
|
+
* Load an input document from a bytes string.
|
|
73
|
+
* @param inputBytes
|
|
74
|
+
* @param filename
|
|
75
|
+
*/
|
|
47
76
|
docFromBytes(inputBytes: string, filename: string): DocumentClient;
|
|
77
|
+
/**
|
|
78
|
+
* Load an input document from a URL.
|
|
79
|
+
* @param url
|
|
80
|
+
*/
|
|
81
|
+
docFromUrl(url: string): DocumentClient;
|
|
48
82
|
}
|
|
49
83
|
export {};
|
package/src/client.js
CHANGED
|
@@ -7,26 +7,29 @@ const documents_1 = require("./documents");
|
|
|
7
7
|
const documentConfig_1 = require("./documents/documentConfig");
|
|
8
8
|
const handler_1 = require("./errors/handler");
|
|
9
9
|
const logger_1 = require("./logger");
|
|
10
|
-
const constants_1 = require("./constants");
|
|
11
10
|
class DocumentClient {
|
|
12
|
-
constructor(
|
|
13
|
-
this.
|
|
11
|
+
constructor(inputSource, docConfigs) {
|
|
12
|
+
this.inputSource = inputSource;
|
|
14
13
|
this.docConfigs = docConfigs;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Send a document to an endpoint and parse the predictions.
|
|
17
|
+
* @param documentClass
|
|
18
|
+
* @param params
|
|
19
|
+
*/
|
|
20
|
+
async parse(documentClass, params = {
|
|
21
|
+
endpointName: "",
|
|
22
|
+
accountName: "",
|
|
20
23
|
fullText: false,
|
|
21
24
|
cropper: false,
|
|
25
|
+
pageOptions: undefined,
|
|
22
26
|
}) {
|
|
23
27
|
// seems like there should be a better way of doing this
|
|
24
28
|
const fullText = params?.fullText !== undefined ? params.fullText : false;
|
|
25
29
|
const cropper = params?.cropper !== undefined ? params.cropper : false;
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
: params.docType;
|
|
30
|
+
const docType = params.endpointName === undefined || params.endpointName === ""
|
|
31
|
+
? documentClass.name
|
|
32
|
+
: params.endpointName;
|
|
30
33
|
const found = [];
|
|
31
34
|
this.docConfigs.forEach((config, configKey) => {
|
|
32
35
|
if (configKey[1] === docType) {
|
|
@@ -40,24 +43,21 @@ class DocumentClient {
|
|
|
40
43
|
if (found.length === 1) {
|
|
41
44
|
configKey = found[0];
|
|
42
45
|
}
|
|
43
|
-
else if (params.
|
|
44
|
-
configKey = [params.
|
|
46
|
+
else if (params.accountName) {
|
|
47
|
+
configKey = [params.accountName, docType];
|
|
45
48
|
}
|
|
46
49
|
const docConfig = this.docConfigs.get(configKey);
|
|
47
50
|
if (docConfig === undefined) {
|
|
48
51
|
// TODO: raise error printing all usernames
|
|
49
52
|
throw `Couldn't find the config '${configKey}'`;
|
|
50
53
|
}
|
|
51
|
-
return await docConfig.predict(
|
|
52
|
-
inputDoc: this.
|
|
54
|
+
return await docConfig.predict({
|
|
55
|
+
inputDoc: this.inputSource,
|
|
53
56
|
includeWords: fullText,
|
|
54
|
-
|
|
57
|
+
pageOptions: params.pageOptions,
|
|
55
58
|
cropper: cropper,
|
|
56
59
|
});
|
|
57
60
|
}
|
|
58
|
-
getDocType(responseClass) {
|
|
59
|
-
return constants_1.ProductConfigs.getByResponseClassName(responseClass).docType;
|
|
60
|
-
}
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Mindee Client
|
|
@@ -81,27 +81,53 @@ class Client {
|
|
|
81
81
|
}
|
|
82
82
|
// TODO: init only those endpoints we actually need.
|
|
83
83
|
addStandardEndpoints() {
|
|
84
|
-
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.
|
|
85
|
-
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.
|
|
84
|
+
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.FinancialDocumentV1.name], new documentConfig_1.FinancialDocV1Config(this.apiKey));
|
|
85
|
+
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.InvoiceV3.name], new documentConfig_1.DocumentConfig(documents_1.InvoiceV3, [
|
|
86
|
+
new api_1.StandardEndpoint("invoices", "3", this.apiKey),
|
|
87
|
+
]));
|
|
88
|
+
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ReceiptV3.name], new documentConfig_1.DocumentConfig(documents_1.ReceiptV3, [
|
|
89
|
+
new api_1.StandardEndpoint("expense_receipts", "3", this.apiKey),
|
|
90
|
+
]));
|
|
91
|
+
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ReceiptV4.name], new documentConfig_1.DocumentConfig(documents_1.ReceiptV4, [
|
|
92
|
+
new api_1.StandardEndpoint("expense_receipts", "4", this.apiKey),
|
|
93
|
+
]));
|
|
94
|
+
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.PassportV1.name], new documentConfig_1.DocumentConfig(documents_1.PassportV1, [
|
|
95
|
+
new api_1.StandardEndpoint("passport", "1", this.apiKey),
|
|
96
|
+
]));
|
|
97
|
+
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.CropperV1.name], new documentConfig_1.DocumentConfig(documents_1.CropperV1, [
|
|
98
|
+
new api_1.StandardEndpoint("cropper", "1", this.apiKey),
|
|
99
|
+
]));
|
|
89
100
|
}
|
|
90
|
-
|
|
91
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Add a custom endpoint to the client.
|
|
103
|
+
* @param accountName
|
|
104
|
+
* @param endpointName
|
|
105
|
+
* @param version
|
|
106
|
+
*/
|
|
107
|
+
addEndpoint({ accountName, endpointName, version = "1", }) {
|
|
108
|
+
this.docConfigs.set([accountName, endpointName], new documentConfig_1.CustomDocConfig({
|
|
92
109
|
accountName: accountName,
|
|
93
|
-
|
|
110
|
+
endpointName: endpointName,
|
|
94
111
|
version: version,
|
|
95
112
|
apiKey: this.apiKey,
|
|
96
113
|
}));
|
|
97
114
|
return this;
|
|
98
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Load an input document from a local path.
|
|
118
|
+
* @param inputPath
|
|
119
|
+
*/
|
|
99
120
|
docFromPath(inputPath) {
|
|
100
121
|
const doc = new inputs_1.PathInput({
|
|
101
122
|
inputPath: inputPath,
|
|
102
123
|
});
|
|
103
124
|
return new DocumentClient(doc, this.docConfigs);
|
|
104
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Load an input document from a base64 encoded string.
|
|
128
|
+
* @param inputString
|
|
129
|
+
* @param filename
|
|
130
|
+
*/
|
|
105
131
|
docFromBase64(inputString, filename) {
|
|
106
132
|
const doc = new inputs_1.Base64Input({
|
|
107
133
|
inputString: inputString,
|
|
@@ -109,6 +135,11 @@ class Client {
|
|
|
109
135
|
});
|
|
110
136
|
return new DocumentClient(doc, this.docConfigs);
|
|
111
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Load an input document from a `ReadStream`.
|
|
140
|
+
* @param inputStream
|
|
141
|
+
* @param filename
|
|
142
|
+
*/
|
|
112
143
|
docFromStream(inputStream, filename) {
|
|
113
144
|
const doc = new inputs_1.StreamInput({
|
|
114
145
|
inputStream: inputStream,
|
|
@@ -116,6 +147,11 @@ class Client {
|
|
|
116
147
|
});
|
|
117
148
|
return new DocumentClient(doc, this.docConfigs);
|
|
118
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Load an input document from a bytes string.
|
|
152
|
+
* @param inputBytes
|
|
153
|
+
* @param filename
|
|
154
|
+
*/
|
|
119
155
|
docFromBytes(inputBytes, filename) {
|
|
120
156
|
const doc = new inputs_1.BytesInput({
|
|
121
157
|
inputBytes: inputBytes,
|
|
@@ -123,5 +159,15 @@ class Client {
|
|
|
123
159
|
});
|
|
124
160
|
return new DocumentClient(doc, this.docConfigs);
|
|
125
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Load an input document from a URL.
|
|
164
|
+
* @param url
|
|
165
|
+
*/
|
|
166
|
+
docFromUrl(url) {
|
|
167
|
+
const doc = new inputs_1.UrlInput({
|
|
168
|
+
url: url,
|
|
169
|
+
});
|
|
170
|
+
return new DocumentClient(doc, this.docConfigs);
|
|
171
|
+
}
|
|
126
172
|
}
|
|
127
173
|
exports.Client = Client;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Document, DocumentConstructorProps } from "../document";
|
|
2
|
+
import { CropperField } from "../../fields";
|
|
3
|
+
export declare class CropperV1 extends Document {
|
|
4
|
+
cropping: CropperField[];
|
|
5
|
+
constructor({ prediction, orientation, inputSource, pageId, }: DocumentConstructorProps);
|
|
6
|
+
toString(): string;
|
|
7
|
+
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const document_1 = require("
|
|
5
|
-
const fields_1 = require("
|
|
6
|
-
class
|
|
7
|
-
constructor({ prediction, orientation = undefined,
|
|
8
|
-
super({
|
|
3
|
+
exports.CropperV1 = void 0;
|
|
4
|
+
const document_1 = require("../document");
|
|
5
|
+
const fields_1 = require("../../fields");
|
|
6
|
+
class CropperV1 extends document_1.Document {
|
|
7
|
+
constructor({ prediction, orientation = undefined, inputSource = undefined, pageId = undefined, }) {
|
|
8
|
+
super({
|
|
9
|
+
inputSource: inputSource,
|
|
10
|
+
pageId: pageId,
|
|
11
|
+
orientation: orientation,
|
|
12
|
+
});
|
|
9
13
|
this.cropping = [];
|
|
10
14
|
if (pageId !== undefined) {
|
|
11
15
|
prediction.cropping.forEach((crop) => {
|
|
@@ -25,7 +29,7 @@ Filename: ${this.filename}
|
|
|
25
29
|
Cropping: ${cropping}
|
|
26
30
|
------------------------
|
|
27
31
|
`;
|
|
28
|
-
return
|
|
32
|
+
return CropperV1.cleanOutString(outStr);
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
|
-
exports.
|
|
35
|
+
exports.CropperV1 = CropperV1;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { Document, DocumentConstructorProps } from "./document";
|
|
2
2
|
import { ClassificationField, ListField } from "../fields";
|
|
3
3
|
import { stringDict } from "../fields";
|
|
4
|
-
export
|
|
5
|
-
documentType: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class CustomDocument extends Document {
|
|
4
|
+
export declare class CustomV1 extends Document {
|
|
8
5
|
fields: Map<string, ListField>;
|
|
9
6
|
classifications: Map<string, ClassificationField>;
|
|
10
|
-
|
|
11
|
-
constructor({ inputFile, prediction, extras, orientation, pageId, documentType, }: CustomDocConstructorProps);
|
|
7
|
+
constructor({ inputSource, prediction, extras, orientation, pageId, documentType, }: DocumentConstructorProps);
|
|
12
8
|
protected setField(fieldName: string, apiPrediction: stringDict, pageId: number | undefined): void;
|
|
13
9
|
toString(): string;
|
|
14
10
|
}
|
package/src/documents/custom.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CustomV1 = void 0;
|
|
4
4
|
const document_1 = require("./document");
|
|
5
5
|
const fields_1 = require("../fields");
|
|
6
|
-
class
|
|
7
|
-
constructor({
|
|
8
|
-
super({
|
|
6
|
+
class CustomV1 extends document_1.Document {
|
|
7
|
+
constructor({ inputSource, prediction, extras = undefined, orientation = undefined, pageId, documentType, }) {
|
|
8
|
+
super({
|
|
9
|
+
inputSource: inputSource,
|
|
10
|
+
pageId: pageId,
|
|
11
|
+
orientation: orientation,
|
|
12
|
+
extras: extras,
|
|
13
|
+
documentType: documentType,
|
|
14
|
+
});
|
|
9
15
|
this.fields = new Map();
|
|
10
16
|
this.classifications = new Map();
|
|
11
|
-
this.documentType = documentType;
|
|
12
17
|
Object.keys(prediction).forEach((fieldName) => {
|
|
13
18
|
this.setField(fieldName, prediction, pageId);
|
|
14
19
|
});
|
|
@@ -33,7 +38,7 @@ class CustomDocument extends document_1.Document {
|
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
toString() {
|
|
36
|
-
let outStr = `----- ${this.
|
|
41
|
+
let outStr = `----- ${this.docType} -----`;
|
|
37
42
|
outStr += `\nFilename: ${this.filename}`.trimEnd();
|
|
38
43
|
this.classifications.forEach((fieldData, name) => {
|
|
39
44
|
outStr += `\n${name}: ${fieldData}`.trimEnd();
|
|
@@ -45,4 +50,4 @@ class CustomDocument extends document_1.Document {
|
|
|
45
50
|
return outStr;
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
|
-
exports.
|
|
53
|
+
exports.CustomV1 = CustomV1;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InputSource } from "../inputs";
|
|
2
2
|
import { CropperField, FullText, OrientationField, stringDict } from "../fields";
|
|
3
|
+
export declare type DocumentSig<DocType extends Document> = {
|
|
4
|
+
new ({ prediction, orientation, extras, inputSource, pageId, fullText, documentType, }: DocumentConstructorProps): DocType;
|
|
5
|
+
};
|
|
3
6
|
export interface DocumentConstructorProps extends BaseDocumentConstructorProps {
|
|
4
7
|
/** JSON parsed prediction from HTTP response */
|
|
5
8
|
prediction: stringDict;
|
|
@@ -10,11 +13,12 @@ interface BaseDocumentConstructorProps {
|
|
|
10
13
|
/** Extras JSON */
|
|
11
14
|
extras?: stringDict;
|
|
12
15
|
/** input file given to parse the document */
|
|
13
|
-
|
|
16
|
+
inputSource?: InputSource;
|
|
14
17
|
/** Page ID for page-level document */
|
|
15
18
|
pageId?: number;
|
|
16
19
|
/** full OCR extracted text */
|
|
17
20
|
fullText?: FullText;
|
|
21
|
+
documentType?: string;
|
|
18
22
|
}
|
|
19
23
|
export declare class Document {
|
|
20
24
|
checklist: {
|
|
@@ -27,7 +31,8 @@ export declare class Document {
|
|
|
27
31
|
pageId?: number | undefined;
|
|
28
32
|
orientation?: OrientationField;
|
|
29
33
|
cropper: CropperField[];
|
|
30
|
-
|
|
34
|
+
readonly docType: string;
|
|
35
|
+
constructor({ orientation, extras, inputSource, fullText, pageId, documentType, }: BaseDocumentConstructorProps);
|
|
31
36
|
clone(): any;
|
|
32
37
|
/** return true if all checklist of the document if true */
|
|
33
38
|
checkAll(): boolean;
|
|
@@ -3,11 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Document = void 0;
|
|
4
4
|
const fields_1 = require("../fields");
|
|
5
5
|
class Document {
|
|
6
|
-
constructor({ orientation = undefined, extras = undefined,
|
|
6
|
+
constructor({ orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, documentType, }) {
|
|
7
7
|
this.filename = "";
|
|
8
8
|
this.cropper = [];
|
|
9
9
|
this.filepath = undefined;
|
|
10
10
|
this.pageId = pageId;
|
|
11
|
+
if (documentType === undefined || documentType === "") {
|
|
12
|
+
this.docType = Object.getPrototypeOf(this).constructor.name;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
this.docType = documentType;
|
|
16
|
+
}
|
|
11
17
|
if (pageId !== undefined && orientation !== undefined) {
|
|
12
18
|
this.orientation = new fields_1.OrientationField({
|
|
13
19
|
prediction: orientation,
|
|
@@ -24,10 +30,10 @@ class Document {
|
|
|
24
30
|
});
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
|
-
if (
|
|
28
|
-
this.filepath =
|
|
29
|
-
this.filename =
|
|
30
|
-
this.mimeType =
|
|
33
|
+
if (inputSource !== undefined) {
|
|
34
|
+
this.filepath = inputSource.filepath;
|
|
35
|
+
this.filename = inputSource.filename;
|
|
36
|
+
this.mimeType = inputSource.mimeType;
|
|
31
37
|
}
|
|
32
38
|
this.fullText = fullText;
|
|
33
39
|
this.checklist = {};
|
|
@@ -1,48 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Response, Endpoint } from "../api";
|
|
3
|
-
import { Document } from "./index";
|
|
4
|
-
import {
|
|
1
|
+
import { InputSource } from "../inputs";
|
|
2
|
+
import { Response, Endpoint, predictResponse } from "../api";
|
|
3
|
+
import { Document, FinancialDocumentV1, CustomV1, DocumentSig } from "./index";
|
|
4
|
+
import { PageOptions } from "../inputs";
|
|
5
5
|
interface CustomDocConstructor {
|
|
6
|
-
|
|
6
|
+
endpointName: string;
|
|
7
7
|
accountName: string;
|
|
8
8
|
version: string;
|
|
9
9
|
apiKey: string;
|
|
10
10
|
}
|
|
11
|
-
export declare
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
export declare class DocumentConfig {
|
|
15
|
-
readonly documentType: string;
|
|
11
|
+
export declare class DocumentConfig<DocType extends Document> {
|
|
12
|
+
readonly documentType: string | undefined;
|
|
16
13
|
readonly endpoints: Array<Endpoint>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
readonly documentClass: DocumentSig<DocType>;
|
|
15
|
+
constructor(documentClass: DocumentSig<DocType>, endpoints: Array<Endpoint>, documentType?: string);
|
|
16
|
+
protected predictRequest(inputDoc: InputSource, includeWords: boolean, cropping: boolean): Promise<predictResponse>;
|
|
17
|
+
buildResult(inputFile: InputSource, response: predictResponse): Response<DocType>;
|
|
18
|
+
predict(params: {
|
|
19
|
+
inputDoc: InputSource;
|
|
22
20
|
includeWords: boolean;
|
|
23
|
-
|
|
21
|
+
pageOptions?: PageOptions;
|
|
24
22
|
cropper: boolean;
|
|
25
|
-
}): Promise<
|
|
26
|
-
cutDocPages(inputDoc:
|
|
23
|
+
}): Promise<Response<DocType>>;
|
|
24
|
+
cutDocPages(inputDoc: InputSource, pageOptions: PageOptions): Promise<void>;
|
|
27
25
|
protected checkApiKeys(): void;
|
|
28
26
|
}
|
|
29
|
-
export declare class
|
|
30
|
-
constructor(apiKey:
|
|
31
|
-
}
|
|
32
|
-
export declare class ReceiptConfig extends DocumentConfig {
|
|
33
|
-
constructor(apiKey: string);
|
|
34
|
-
}
|
|
35
|
-
export declare class FinancialDocConfig extends DocumentConfig {
|
|
36
|
-
constructor(apiKey: string);
|
|
37
|
-
predictRequest(inputDoc: Input, includeWords: boolean, cropping: boolean): Promise<unknown>;
|
|
38
|
-
}
|
|
39
|
-
export declare class PassportConfig extends DocumentConfig {
|
|
40
|
-
constructor(apiKey: string);
|
|
27
|
+
export declare class CustomDocConfig extends DocumentConfig<CustomV1> {
|
|
28
|
+
constructor({ endpointName, accountName, version, apiKey, }: CustomDocConstructor);
|
|
41
29
|
}
|
|
42
|
-
export declare class
|
|
30
|
+
export declare class FinancialDocV1Config extends DocumentConfig<FinancialDocumentV1> {
|
|
43
31
|
constructor(apiKey: string);
|
|
44
|
-
|
|
45
|
-
export declare class CustomDocConfig extends DocumentConfig {
|
|
46
|
-
constructor({ documentType, accountName, version, apiKey, }: CustomDocConstructor);
|
|
32
|
+
protected predictRequest(inputDoc: InputSource, includeWords: boolean, cropping: boolean): Promise<predictResponse>;
|
|
47
33
|
}
|
|
48
34
|
export {};
|
|
@@ -1,78 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FinancialDocV1Config = exports.CustomDocConfig = exports.DocumentConfig = void 0;
|
|
4
4
|
const api_1 = require("../api");
|
|
5
5
|
const index_1 = require("./index");
|
|
6
6
|
const handler_1 = require("../errors/handler");
|
|
7
7
|
class DocumentConfig {
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(documentClass, endpoints, documentType) {
|
|
9
9
|
this.documentType = documentType;
|
|
10
10
|
this.endpoints = endpoints;
|
|
11
|
+
this.documentClass = documentClass;
|
|
11
12
|
}
|
|
12
13
|
async predictRequest(inputDoc, includeWords, cropping) {
|
|
13
|
-
return await this.endpoints[0].
|
|
14
|
+
return await this.endpoints[0].predictReqPost(inputDoc, includeWords, cropping);
|
|
14
15
|
}
|
|
15
|
-
buildResult(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
buildResult(inputFile, response) {
|
|
17
|
+
const statusCode = response.messageObj.statusCode;
|
|
18
|
+
if (statusCode === undefined || statusCode > 201) {
|
|
19
|
+
const errorMessage = JSON.stringify(response.data, null, 2);
|
|
20
|
+
handler_1.errorHandler.throw(new Error(`${this.endpoints[0].urlName} API ${statusCode} HTTP error: ${errorMessage}`));
|
|
21
|
+
return new api_1.Response(this.documentClass, {
|
|
20
22
|
httpResponse: response,
|
|
21
23
|
documentType: this.documentType,
|
|
22
24
|
input: inputFile,
|
|
23
25
|
error: true,
|
|
24
26
|
});
|
|
25
27
|
}
|
|
26
|
-
return new
|
|
28
|
+
return new api_1.Response(this.documentClass, {
|
|
27
29
|
httpResponse: response,
|
|
28
30
|
documentType: this.documentType,
|
|
29
31
|
input: inputFile,
|
|
30
32
|
error: false,
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
|
-
async predict(
|
|
35
|
+
async predict(params) {
|
|
34
36
|
this.checkApiKeys();
|
|
35
37
|
await params.inputDoc.init();
|
|
36
|
-
|
|
38
|
+
if (params.pageOptions !== undefined) {
|
|
39
|
+
await this.cutDocPages(params.inputDoc, params.pageOptions);
|
|
40
|
+
}
|
|
37
41
|
const response = await this.predictRequest(params.inputDoc, params.includeWords, params.cropper);
|
|
38
|
-
return this.buildResult(
|
|
42
|
+
return this.buildResult(params.inputDoc, response);
|
|
39
43
|
}
|
|
40
|
-
async cutDocPages(inputDoc,
|
|
41
|
-
if (
|
|
42
|
-
await inputDoc.cutPdf();
|
|
44
|
+
async cutDocPages(inputDoc, pageOptions) {
|
|
45
|
+
if (inputDoc.isPdf()) {
|
|
46
|
+
await inputDoc.cutPdf(pageOptions);
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
checkApiKeys() {
|
|
46
50
|
this.endpoints.forEach((endpoint) => {
|
|
47
51
|
if (!endpoint.apiKey) {
|
|
48
|
-
throw new Error(`Missing API key for '${
|
|
52
|
+
throw new Error(`Missing API key for '${this.documentType}', check your Client configuration.
|
|
49
53
|
You can set this using the '${api_1.API_KEY_ENVVAR_NAME}' environment variable.\n`);
|
|
50
54
|
}
|
|
51
55
|
});
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
exports.DocumentConfig = DocumentConfig;
|
|
55
|
-
class
|
|
56
|
-
constructor(apiKey) {
|
|
57
|
-
const endpoints = [
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
exports.InvoiceConfig = InvoiceConfig;
|
|
62
|
-
class ReceiptConfig extends DocumentConfig {
|
|
63
|
-
constructor(apiKey) {
|
|
64
|
-
const endpoints = [new api_1.ReceiptEndpoint(apiKey)];
|
|
65
|
-
super(index_1.DOC_TYPE_RECEIPT, endpoints);
|
|
59
|
+
class CustomDocConfig extends DocumentConfig {
|
|
60
|
+
constructor({ endpointName, accountName, version, apiKey, }) {
|
|
61
|
+
const endpoints = [
|
|
62
|
+
new api_1.CustomEndpoint(endpointName, accountName, version, apiKey),
|
|
63
|
+
];
|
|
64
|
+
super(index_1.CustomV1, endpoints, endpointName);
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
|
-
exports.
|
|
69
|
-
class
|
|
67
|
+
exports.CustomDocConfig = CustomDocConfig;
|
|
68
|
+
class FinancialDocV1Config extends DocumentConfig {
|
|
70
69
|
constructor(apiKey) {
|
|
71
70
|
const endpoints = [
|
|
72
|
-
new api_1.
|
|
73
|
-
new api_1.
|
|
71
|
+
new api_1.StandardEndpoint("invoices", "3", apiKey),
|
|
72
|
+
new api_1.StandardEndpoint("expense_receipts", "3", apiKey),
|
|
74
73
|
];
|
|
75
|
-
super(index_1.
|
|
74
|
+
super(index_1.FinancialDocumentV1, endpoints);
|
|
76
75
|
}
|
|
77
76
|
async predictRequest(inputDoc, includeWords, cropping) {
|
|
78
77
|
let endpoint;
|
|
@@ -82,30 +81,7 @@ class FinancialDocConfig extends DocumentConfig {
|
|
|
82
81
|
else {
|
|
83
82
|
endpoint = this.endpoints[1];
|
|
84
83
|
}
|
|
85
|
-
return await endpoint.
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.FinancialDocConfig = FinancialDocConfig;
|
|
89
|
-
class PassportConfig extends DocumentConfig {
|
|
90
|
-
constructor(apiKey) {
|
|
91
|
-
const endpoints = [new api_1.PassportEndpoint(apiKey)];
|
|
92
|
-
super(index_1.DOC_TYPE_PASSPORT, endpoints);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.PassportConfig = PassportConfig;
|
|
96
|
-
class CropperConfig extends DocumentConfig {
|
|
97
|
-
constructor(apiKey) {
|
|
98
|
-
const endpoints = [new api_1.CropperEndpoint(apiKey)];
|
|
99
|
-
super(index_1.DOC_TYPE_CROPPER, endpoints);
|
|
84
|
+
return await endpoint.predictReqPost(inputDoc, includeWords, cropping);
|
|
100
85
|
}
|
|
101
86
|
}
|
|
102
|
-
exports.
|
|
103
|
-
class CustomDocConfig extends DocumentConfig {
|
|
104
|
-
constructor({ documentType, accountName, version, apiKey, }) {
|
|
105
|
-
const endpoints = [
|
|
106
|
-
new api_1.CustomEndpoint(documentType, accountName, version, apiKey),
|
|
107
|
-
];
|
|
108
|
-
super(documentType, endpoints);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
exports.CustomDocConfig = CustomDocConfig;
|
|
87
|
+
exports.FinancialDocV1Config = FinancialDocV1Config;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Document, DocumentConstructorProps } from "
|
|
2
|
-
import { TaxField, Field, Amount, Locale, DateField as Date, CompanyRegistration } from "
|
|
3
|
-
export declare class
|
|
1
|
+
import { Document, DocumentConstructorProps } from "../document";
|
|
2
|
+
import { TaxField, Field, Amount, Locale, DateField as Date, CompanyRegistration } from "../../fields";
|
|
3
|
+
export declare class FinancialDocumentV1 extends Document {
|
|
4
4
|
#private;
|
|
5
5
|
pageId: number | undefined;
|
|
6
6
|
locale: Locale;
|
|
@@ -20,6 +20,6 @@ export declare class FinancialDocument extends Document {
|
|
|
20
20
|
customerAddress: Field;
|
|
21
21
|
paymentDetails: Field[];
|
|
22
22
|
customerCompanyRegistration: CompanyRegistration[];
|
|
23
|
-
constructor({ prediction, orientation, extras,
|
|
23
|
+
constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
|
|
24
24
|
toString(): string;
|
|
25
25
|
}
|