mindee 1.3.2 → 2.0.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 +47 -18
- package/README.md +43 -127
- package/bin/mindee +3 -0
- package/dist/package.json +70 -0
- package/dist/src/api/endpoint.d.ts +29 -0
- package/dist/src/api/endpoint.js +148 -0
- package/dist/src/api/index.d.ts +2 -0
- package/dist/src/api/index.js +18 -0
- package/dist/src/api/response.d.ts +52 -0
- package/dist/src/api/response.js +107 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/cli.js +117 -0
- package/dist/src/client.d.ts +48 -0
- package/dist/src/client.js +134 -0
- package/dist/src/constants.d.ts +13 -0
- package/dist/src/constants.js +54 -0
- package/dist/src/documents/custom.d.ts +14 -0
- package/dist/src/documents/custom.js +48 -0
- package/dist/src/documents/document.d.ts +38 -0
- package/dist/{documents → src/documents}/document.js +15 -35
- package/dist/src/documents/documentConfig.d.ts +44 -0
- package/dist/src/documents/documentConfig.js +121 -0
- package/dist/src/documents/financialDocument.d.ts +32 -0
- package/dist/src/documents/financialDocument.js +130 -0
- package/dist/src/documents/index.d.ts +12 -0
- package/dist/src/documents/index.js +20 -0
- package/dist/src/documents/invoice.d.ts +37 -0
- package/dist/src/documents/invoice.js +303 -0
- package/dist/src/documents/passport.d.ts +36 -0
- package/dist/src/documents/passport.js +218 -0
- package/dist/src/documents/receipt.d.ts +24 -0
- package/dist/src/documents/receipt.js +157 -0
- package/dist/src/errors/handler.d.ts +7 -0
- package/dist/{errors → src/errors}/handler.js +5 -4
- package/dist/src/fields/amount.d.ts +13 -0
- package/dist/{documents → src}/fields/amount.js +19 -6
- package/dist/src/fields/companyRegistration.d.ts +6 -0
- package/dist/src/fields/companyRegistration.js +11 -0
- package/dist/src/fields/customDocs.d.ts +42 -0
- package/dist/src/fields/customDocs.js +61 -0
- package/dist/src/fields/date.d.ts +12 -0
- package/dist/src/fields/date.js +25 -0
- package/dist/src/fields/field.d.ts +74 -0
- package/dist/{documents → src}/fields/field.js +48 -27
- package/dist/src/fields/fullText.d.ts +24 -0
- package/dist/src/fields/fullText.js +89 -0
- package/dist/src/fields/index.d.ts +11 -0
- package/dist/src/fields/index.js +27 -0
- package/dist/src/fields/locale.d.ts +13 -0
- package/dist/{documents → src}/fields/locale.js +20 -5
- package/dist/src/fields/orientation.d.ts +10 -0
- package/dist/{documents → src}/fields/orientation.js +5 -5
- package/dist/src/fields/paymentDetails.d.ts +31 -0
- package/dist/{documents → src}/fields/paymentDetails.js +14 -6
- package/dist/src/fields/tax.d.ts +30 -0
- package/dist/src/fields/tax.js +51 -0
- package/dist/src/geometry.d.ts +59 -0
- package/dist/src/geometry.js +113 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +12 -0
- package/dist/src/inputs.d.ts +69 -0
- package/dist/src/inputs.js +223 -0
- package/dist/src/logger.d.ts +20 -0
- package/dist/src/logger.js +35 -0
- package/package.json +45 -26
- package/.eslintrc +0 -24
- package/.mocharc.yaml +0 -2
- package/.nyc_output/f57ba3bc-1777-4ecc-81e1-230327c2a401.json +0 -1
- package/.nyc_output/processinfo/f57ba3bc-1777-4ecc-81e1-230327c2a401.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/.prettierrc +0 -4
- package/.tool-versions +0 -1
- package/CODE_OF_CONDUCT.md +0 -63
- package/CONTRIBUTING.md +0 -84
- package/ISSUE_TEMPLATE.md +0 -45
- package/PULL_REQUEST_TEMPLATE.md +0 -45
- package/babel.config.json +0 -10
- package/coverage/coverage.json +0 -1
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -171
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov.info +0 -1595
- package/coverage.lcov +0 -1595
- package/dist/api/financialDocument.js +0 -51
- package/dist/api/index.js +0 -13
- package/dist/api/invoice.js +0 -59
- package/dist/api/object.js +0 -80
- package/dist/api/receipt.js +0 -45
- package/dist/api/request.js +0 -90
- package/dist/api/response.js +0 -91
- package/dist/documents/fields/date.js +0 -17
- package/dist/documents/fields/index.js +0 -17
- package/dist/documents/fields/tax.js +0 -42
- package/dist/documents/financialDocument.js +0 -216
- package/dist/documents/index.js +0 -13
- package/dist/documents/invoice.js +0 -361
- package/dist/documents/receipt.js +0 -231
- package/dist/index.js +0 -23
- package/dist/inputs.js +0 -208
- package/dist/logger.js +0 -34
- package/examples/.env.example +0 -2
- package/examples/documents/invoices/credit_note.pdf +0 -900
- package/examples/documents/invoices/invoice.pdf +0 -0
- package/examples/documents/invoices/invoice_6p.pdf +0 -0
- package/examples/documents/receipts/receipt.jpg +0 -0
- package/examples/financialDocument.js +0 -32
- package/examples/invoice.js +0 -74
- package/examples/receipt.js +0 -45
- package/lib/api/financialDocument.js +0 -59
- package/lib/api/index.js +0 -7
- package/lib/api/invoice.js +0 -73
- package/lib/api/object.js +0 -90
- package/lib/api/receipt.js +0 -58
- package/lib/api/request.js +0 -84
- package/lib/api/response.js +0 -92
- package/lib/documents/document.js +0 -97
- package/lib/documents/fields/amount.js +0 -35
- package/lib/documents/fields/date.js +0 -36
- package/lib/documents/fields/field.js +0 -102
- package/lib/documents/fields/index.js +0 -9
- package/lib/documents/fields/locale.js +0 -35
- package/lib/documents/fields/orientation.js +0 -33
- package/lib/documents/fields/paymentDetails.js +0 -71
- package/lib/documents/fields/tax.js +0 -57
- package/lib/documents/financialDocument.js +0 -280
- package/lib/documents/index.js +0 -7
- package/lib/documents/invoice.js +0 -451
- package/lib/documents/receipt.js +0 -332
- package/lib/errors/handler.js +0 -19
- package/lib/index.js +0 -40
- package/lib/inputs.js +0 -190
- package/lib/logger.js +0 -52
- package/mindee/api/financialDocument.js +0 -47
- package/mindee/api/index.js +0 -5
- package/mindee/api/invoice.js +0 -53
- package/mindee/api/object.js +0 -82
- package/mindee/api/receipt.js +0 -39
- package/mindee/api/request.js +0 -72
- package/mindee/api/response.js +0 -80
- package/mindee/documents/document.js +0 -69
- package/mindee/documents/fields/amount.js +0 -25
- package/mindee/documents/fields/date.js +0 -29
- package/mindee/documents/fields/field.js +0 -86
- package/mindee/documents/fields/index.js +0 -7
- package/mindee/documents/fields/locale.js +0 -30
- package/mindee/documents/fields/orientation.js +0 -24
- package/mindee/documents/fields/paymentDetails.js +0 -52
- package/mindee/documents/fields/tax.js +0 -47
- package/mindee/documents/financialDocument.js +0 -269
- package/mindee/documents/index.js +0 -5
- package/mindee/documents/invoice.js +0 -456
- package/mindee/documents/receipt.js +0 -287
- package/mindee/errors/handler.js +0 -16
- package/mindee/index.js +0 -36
- package/mindee/inputs.js +0 -158
- package/mindee/logger.js +0 -33
package/CHANGELOG.md
CHANGED
|
@@ -1,21 +1,50 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v2.0.0 (2022-08-26)
|
|
4
|
+
### Note
|
|
5
|
+
This is a complete rewrite in TypeScript!
|
|
6
|
+
|
|
7
|
+
It's **not** backwards compatible with previous versions.
|
|
8
|
+
|
|
9
|
+
### Changes
|
|
10
|
+
* :sparkles: Add Passport API support
|
|
11
|
+
* :sparkles: Add custom document support (API builder)
|
|
12
|
+
* :sparkles: Add basic geometry functions
|
|
13
|
+
* :label: everything is typed, in particular response objects.
|
|
14
|
+
Allows for much easier auto-completion in your IDE.
|
|
15
|
+
* :arrow_up: all major dependencies updated
|
|
16
|
+
|
|
17
|
+
## v1.4.0
|
|
18
|
+
### Fixes
|
|
19
|
+
* :bug: cut/merge pages of an encrypted PDF leads to unexpected results
|
|
20
|
+
* :bug: logger not activating in some cases
|
|
21
|
+
* :bug: align PDF cut/merge with other client libs
|
|
22
|
+
|
|
23
|
+
### Changes
|
|
24
|
+
* :sparkles: Add TIFF and HEIC support
|
|
25
|
+
* :white_check_mark: fully test PDF cut function
|
|
26
|
+
|
|
27
|
+
## v1.3.3
|
|
28
|
+
|
|
29
|
+
### Fixes
|
|
30
|
+
* :bug: reject errors instead of printing them only to the console
|
|
31
|
+
|
|
3
32
|
## v1.3.2
|
|
4
33
|
|
|
5
34
|
### Fixes
|
|
6
|
-
*
|
|
35
|
+
* :bug: use PDF length instead of cut PDF size limit
|
|
7
36
|
|
|
8
37
|
## v1.3.1
|
|
9
38
|
|
|
10
39
|
### Fixes
|
|
11
|
-
*
|
|
40
|
+
* :bug: forward api error to stderr instead of stdout
|
|
12
41
|
|
|
13
42
|
## v1.3.0
|
|
14
43
|
|
|
15
44
|
### Changes
|
|
16
45
|
|
|
17
46
|
* :sparkles: allow sending the filename for streams and base64
|
|
18
|
-
*
|
|
47
|
+
* :bug: not able to specify MIME type
|
|
19
48
|
* :page_facing_up: change license to MIT
|
|
20
49
|
* :white_check_mark: add node18 to tests
|
|
21
50
|
* various package updates
|
|
@@ -24,43 +53,43 @@
|
|
|
24
53
|
|
|
25
54
|
### Fixes
|
|
26
55
|
|
|
27
|
-
*
|
|
56
|
+
* :bug: Get `words` values when `includeWords` parameter is `true`
|
|
28
57
|
|
|
29
58
|
## v1.1.2
|
|
30
59
|
|
|
31
60
|
### Fixes
|
|
32
61
|
|
|
33
|
-
*
|
|
34
|
-
*
|
|
62
|
+
* :bug: Fix returned probability value
|
|
63
|
+
* :bug: Fix returned bbox value
|
|
35
64
|
|
|
36
65
|
### new
|
|
37
66
|
|
|
38
|
-
*
|
|
39
|
-
*
|
|
67
|
+
* :sparkles: New Mindee Invoice API V3 support
|
|
68
|
+
* :sparkles: Add new supplier and customer fields
|
|
40
69
|
|
|
41
70
|
## v1.1.0 (2022-01-03)
|
|
42
71
|
|
|
43
72
|
### new
|
|
44
73
|
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
74
|
+
* :sparkles: New Mindee API V2 support
|
|
75
|
+
* :zap: Server side invoice reconstruction from multi-page pdfs
|
|
76
|
+
* :sparkles: Added OS in User-Agent headers
|
|
48
77
|
|
|
49
78
|
|
|
50
79
|
## v1.0.9 (2021-12-09)
|
|
51
80
|
|
|
52
81
|
### Fixes
|
|
53
82
|
|
|
54
|
-
*
|
|
83
|
+
* :bug: handle attribute of type array when merging pages
|
|
55
84
|
|
|
56
85
|
## v1.0.8 (2021-11-29)
|
|
57
86
|
|
|
58
87
|
### Fixes
|
|
59
88
|
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
89
|
+
* :bug: fix cutPDF for ReadableStream + add it for base64 file string
|
|
90
|
+
* :bug: Updated api Input initialization to specifically declare parameters
|
|
91
|
+
* :bug: prevent error when the mime type isn't detectable
|
|
92
|
+
* :bug: raise proper error when the APi doesn't return a valid JSON
|
|
64
93
|
|
|
65
94
|
### new
|
|
66
95
|
|
|
@@ -70,7 +99,7 @@
|
|
|
70
99
|
|
|
71
100
|
### New
|
|
72
101
|
|
|
73
|
-
*
|
|
102
|
+
* :sparkles: Added pdf page number parameter for multi-pages pdfs with file
|
|
74
103
|
|
|
75
104
|
### Changes
|
|
76
105
|
|
|
@@ -109,4 +138,4 @@
|
|
|
109
138
|
|
|
110
139
|
## v1.0.1 (2021-01-11)
|
|
111
140
|
|
|
112
|
-
*
|
|
141
|
+
* :tada: First release
|
package/README.md
CHANGED
|
@@ -1,150 +1,66 @@
|
|
|
1
|
-
# Mindee
|
|
1
|
+
# Mindee API Helper Library for Node.js
|
|
2
|
+
Quickly and easily connect to Mindee's API services using Node.js.
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
## Quick Start
|
|
5
|
+
Here's the TL;DR of getting started.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
First, get an [API Key](https://developers.mindee.com/docs/create-api-key)
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## From source code
|
|
11
|
-
|
|
12
|
-
Download and decompress or clone the source code from GitHub and then do in your Node.js project:
|
|
13
|
-
|
|
14
|
-
```sh
|
|
9
|
+
Then, install this library:
|
|
10
|
+
```shell
|
|
15
11
|
npm install mindee
|
|
16
12
|
```
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
You can use the SDK easily by creating a Client like this:
|
|
21
|
-
|
|
22
|
-
```js
|
|
23
|
-
const { Client } = require("mindee");
|
|
14
|
+
Finally, Node.js away!
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
invoiceToken: "invoiceApiToken",
|
|
27
|
-
receiptToken: "receiptExpenseApiToken",
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
mindeeClient.invoice.parse({ input: "path/to/file", inputType: "file" });
|
|
31
|
-
mindeeClient.receipt.parse({ input: base64String, inputType: "base64" });
|
|
32
|
-
mindeeClient.financialDocument.parse({
|
|
33
|
-
input: base64String,
|
|
34
|
-
inputType: "base64",
|
|
35
|
-
});
|
|
36
|
-
```
|
|
16
|
+
### Off-the-Shelf Document
|
|
37
17
|
|
|
38
|
-
|
|
18
|
+
```ts
|
|
19
|
+
import { Client, InvoiceResponse } from "mindee";
|
|
39
20
|
|
|
40
|
-
|
|
21
|
+
// Init a new client
|
|
22
|
+
const mindeeClient = new Client({apiKey: "my-api-key"});
|
|
41
23
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
// Load a file from disk and parse it
|
|
25
|
+
const invoiceResponse = mindeeClient.docFromPath("/path/to/the/invoice.pdf")
|
|
26
|
+
.parse(InvoiceResponse);
|
|
45
27
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
input: base64String,
|
|
50
|
-
inputType: "base64",
|
|
51
|
-
filename: "myfile.pdf",
|
|
28
|
+
// Print a brief summary of the parsed data
|
|
29
|
+
invoiceResponse.then((resp) => {
|
|
30
|
+
console.log(resp.document);
|
|
52
31
|
});
|
|
53
32
|
```
|
|
54
33
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
The Mindee client can take multiple parameters to be initialize.
|
|
58
|
-
Some this parameters can also be set with env variables.
|
|
59
|
-
If the env variable and the parameter are both set, the parameter will be the one chosen by the client.
|
|
60
|
-
This is a list of them:
|
|
61
|
-
|
|
62
|
-
- invoiceToken (env variable : `MINDEE_INVOICE_TOKEN`) The expense api token
|
|
63
|
-
- receiptToken (env variable : `MINDEE_RECEIPT_TOKEN`) The invoice api token
|
|
64
|
-
- throwOnError (`true` by default) If `true`, the SDK will throw on error
|
|
65
|
-
- debug (env variable : `MINDEE_DEBUG`, `false` by default) If `true`, logging will be in debug mode
|
|
66
|
-
|
|
67
|
-
Depending on what type of document you want to parse, you need to add specifics auth token for each endpoint.
|
|
68
|
-
We suggest storing your credentials as environment variables for security reasons.
|
|
69
|
-
|
|
70
|
-
## Parsing Invoices
|
|
71
|
-
|
|
72
|
-
```js
|
|
73
|
-
const { Client } = require("mindee");
|
|
74
|
-
const fs = require("fs");
|
|
75
|
-
|
|
76
|
-
// Invoice token can be set by Env (MINDEE_INVOICE_TOKEN) or via params (Client({invoiceToken: "token"}))
|
|
77
|
-
const mindeeClient = new Client();
|
|
78
|
-
|
|
79
|
-
// parsing invoice from pdf
|
|
80
|
-
mindeeClient.invoice
|
|
81
|
-
.parse({ input: "./documents/invoices/invoice.pdf" }) // see examples for more input types
|
|
82
|
-
.then((res) => {
|
|
83
|
-
console.log("Success !");
|
|
84
|
-
console.log(res.invoices);
|
|
85
|
-
console.log(res.invoice);
|
|
86
|
-
})
|
|
87
|
-
.catch((err) => {
|
|
88
|
-
console.error(err);
|
|
89
|
-
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## Parsing receipts
|
|
93
|
-
|
|
94
|
-
```js
|
|
95
|
-
const { Client } = require("mindee");
|
|
96
|
-
const fs = require("fs");
|
|
97
|
-
|
|
98
|
-
// Receipt token can be set by Env (MINDEE_RECEIPT_TOKEN) or via params (Client({receiptToken: "token"}))
|
|
99
|
-
const mindeeClient = new Client();
|
|
100
|
-
|
|
101
|
-
// parsing receipt from picture
|
|
102
|
-
mindeeClient.receipt
|
|
103
|
-
.parse({ input: "./documents/receipts/receipt.jpg" }) // see examples for more input types
|
|
104
|
-
.then((res) => {
|
|
105
|
-
console.log("Success !");
|
|
106
|
-
console.log(res.receipts);
|
|
107
|
-
console.log(res.receipt);
|
|
108
|
-
})
|
|
109
|
-
.catch((err) => {
|
|
110
|
-
console.error(err);
|
|
111
|
-
});
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
## Parsing a mix of invoices and receipts: Financial document
|
|
34
|
+
### Custom Document (API Builder)
|
|
115
35
|
|
|
116
|
-
|
|
36
|
+
```ts
|
|
37
|
+
import { Client, CustomResponse } from "mindee";
|
|
117
38
|
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
39
|
+
// Init a new client and add your document endpoint
|
|
40
|
+
const mindeeClient = new Client({apiKey: "my-api-key"})
|
|
41
|
+
.addEndpoint({
|
|
42
|
+
accountName: "john",
|
|
43
|
+
documentType: "wsnine",
|
|
44
|
+
});
|
|
124
45
|
|
|
125
|
-
|
|
46
|
+
// Load a file from disk and parse it
|
|
47
|
+
const customResponse = mindeeClient.docFromPath("/path/to/the/wsnine.jpg")
|
|
48
|
+
.parse(CustomResponse, {docType: "wsnine"});
|
|
126
49
|
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
.
|
|
130
|
-
|
|
131
|
-
console.log("Success !");
|
|
132
|
-
console.log(res.financialDocuments);
|
|
133
|
-
console.log(res.financialDocument);
|
|
134
|
-
})
|
|
135
|
-
.catch((err) => {
|
|
136
|
-
console.error(err);
|
|
137
|
-
});
|
|
50
|
+
// Print a brief summary of the parsed data
|
|
51
|
+
customResponse.then((resp) => {
|
|
52
|
+
console.log(resp.document);
|
|
53
|
+
});
|
|
138
54
|
```
|
|
139
55
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
56
|
+
## Further Reading
|
|
57
|
+
There's more to it than that for those that need more features, or want to
|
|
58
|
+
customize the experience.
|
|
143
59
|
|
|
144
|
-
|
|
60
|
+
All the juicy details are described in the
|
|
61
|
+
**[Official Documentation](https://developers.mindee.com/docs/nodejs-sdk)**.
|
|
145
62
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
A folder `docs` will be created with generated documentation.
|
|
149
|
-
Open the `index.html` in your browser to read the documentation.
|
|
63
|
+
## License
|
|
64
|
+
Copyright © Mindee
|
|
150
65
|
|
|
66
|
+
Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
package/bin/mindee
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mindee",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Mindee Client Library for Node.js",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc --build",
|
|
9
|
+
"clean": "rm -rf ./dist",
|
|
10
|
+
"test": "mocha 'tests/**/*.spec.ts'",
|
|
11
|
+
"lint-fix": "eslint 'src/**/*.ts' --fix",
|
|
12
|
+
"lint": "eslint 'src/**/*.ts' --report-unused-disable-directives && echo 'Your .ts files look good.'",
|
|
13
|
+
"docs": "jsdoc -r src -d docs"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/",
|
|
17
|
+
"bin/",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README.md",
|
|
20
|
+
"CHANGELOG.md"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">= 14.0.0"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/mindee/mindee-api-nodejs.git"
|
|
28
|
+
},
|
|
29
|
+
"author": {
|
|
30
|
+
"name": "Mindee",
|
|
31
|
+
"email": "devrel@mindee.com",
|
|
32
|
+
"url": "https://mindee.com/"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/mindee/mindee-api-nodejs/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://mindee.com/",
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@tsconfig/node16": "^1.0.3",
|
|
40
|
+
"@types/chai": "^4.3.1",
|
|
41
|
+
"@types/mocha": "^9.1.1",
|
|
42
|
+
"@types/node": "^17.0.38",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^5.30.0",
|
|
44
|
+
"@typescript-eslint/parser": "^5.30.0",
|
|
45
|
+
"chai": "^4.3.6",
|
|
46
|
+
"eslint": "^8.18.0",
|
|
47
|
+
"eslint-config-prettier": "^8.5.0",
|
|
48
|
+
"eslint-plugin-prettier": "^4.1.0",
|
|
49
|
+
"jsdoc": "^3.6.10",
|
|
50
|
+
"mocha": "^10.0.0",
|
|
51
|
+
"prettier": "^2.7.1",
|
|
52
|
+
"ts-node": "^10.8.1",
|
|
53
|
+
"typescript": "^4.7.4"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"commander": "^9.4.0",
|
|
57
|
+
"file-type": "^16.5.4",
|
|
58
|
+
"form-data": "^3.0.1",
|
|
59
|
+
"mrz": "^3.1.4",
|
|
60
|
+
"pdf-lib": "^1.17.1"
|
|
61
|
+
},
|
|
62
|
+
"keywords": [
|
|
63
|
+
"typescript",
|
|
64
|
+
"mindee",
|
|
65
|
+
"api",
|
|
66
|
+
"client",
|
|
67
|
+
"client library",
|
|
68
|
+
"nodejs"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Input } from "../inputs";
|
|
2
|
+
export declare const STANDARD_API_OWNER = "mindee";
|
|
3
|
+
export declare const API_KEY_ENVVAR_NAME = "MINDEE_API_KEY";
|
|
4
|
+
export declare class Endpoint {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
urlName: string;
|
|
7
|
+
keyName: string;
|
|
8
|
+
owner: string;
|
|
9
|
+
version: string;
|
|
10
|
+
urlRoot: string;
|
|
11
|
+
constructor(owner: string, urlName: string, version: string, apiKey: string, keyName?: string);
|
|
12
|
+
/**
|
|
13
|
+
* Make a prediction request.
|
|
14
|
+
*/
|
|
15
|
+
predictRequest(input: Input, includeWords?: boolean): Promise<unknown>;
|
|
16
|
+
protected apiKeyFromEnv(): string;
|
|
17
|
+
}
|
|
18
|
+
export declare class InvoiceEndpoint extends Endpoint {
|
|
19
|
+
constructor(apiKey: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class ReceiptEndpoint extends Endpoint {
|
|
22
|
+
constructor(apiKey: string);
|
|
23
|
+
}
|
|
24
|
+
export declare class PassportEndpoint extends Endpoint {
|
|
25
|
+
constructor(apiKey: string);
|
|
26
|
+
}
|
|
27
|
+
export declare class CustomEndpoint extends Endpoint {
|
|
28
|
+
constructor(documentType: string, accountName: string, version: string, apiKey: string);
|
|
29
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.CustomEndpoint = exports.PassportEndpoint = exports.ReceiptEndpoint = exports.InvoiceEndpoint = exports.Endpoint = exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = void 0;
|
|
30
|
+
const https = __importStar(require("https"));
|
|
31
|
+
const os = __importStar(require("os"));
|
|
32
|
+
const package_json_1 = require("../../package.json");
|
|
33
|
+
const url_1 = require("url");
|
|
34
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
35
|
+
const logger_1 = require("../logger");
|
|
36
|
+
const MINDEE_API_URL = "https://api.mindee.net/v1";
|
|
37
|
+
const USER_AGENT = `mindee-api-nodejs@v${package_json_1.version} nodejs-${process.version} ${os.type().toLowerCase()}`;
|
|
38
|
+
exports.STANDARD_API_OWNER = "mindee";
|
|
39
|
+
exports.API_KEY_ENVVAR_NAME = "MINDEE_API_KEY";
|
|
40
|
+
class Endpoint {
|
|
41
|
+
constructor(owner, urlName, version, apiKey, keyName) {
|
|
42
|
+
this.owner = owner;
|
|
43
|
+
this.urlName = urlName;
|
|
44
|
+
this.version = version;
|
|
45
|
+
this.keyName = keyName || urlName;
|
|
46
|
+
this.apiKey = apiKey || this.apiKeyFromEnv();
|
|
47
|
+
this.urlRoot = `${MINDEE_API_URL}/products/${owner}/${urlName}/v${version}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Make a prediction request.
|
|
51
|
+
*/
|
|
52
|
+
predictRequest(input, includeWords = false) {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const form = new form_data_1.default();
|
|
55
|
+
let body;
|
|
56
|
+
let headers = {
|
|
57
|
+
"User-Agent": USER_AGENT,
|
|
58
|
+
Authorization: `Token ${this.apiKey}`,
|
|
59
|
+
};
|
|
60
|
+
// TODO: redo this section given there should only
|
|
61
|
+
// be a single way of reading the input doc
|
|
62
|
+
if (["path", "stream"].includes(input.inputType)) {
|
|
63
|
+
const fileParams = { filename: input.filename };
|
|
64
|
+
form.append("document", input.fileObject, fileParams);
|
|
65
|
+
if (includeWords) {
|
|
66
|
+
form.append("include_mvision", "true");
|
|
67
|
+
}
|
|
68
|
+
headers = Object.assign(Object.assign({}, headers), form.getHeaders());
|
|
69
|
+
}
|
|
70
|
+
else if (input.inputType === "base64") {
|
|
71
|
+
const bodyObj = { document: input.fileObject };
|
|
72
|
+
if (includeWords) {
|
|
73
|
+
bodyObj["include_mvision"] = "true";
|
|
74
|
+
}
|
|
75
|
+
body = JSON.stringify(bodyObj);
|
|
76
|
+
headers["Content-Type"] = "application/json";
|
|
77
|
+
headers["Content-Length"] = body.length;
|
|
78
|
+
}
|
|
79
|
+
const uri = new url_1.URL(`${this.urlRoot}/predict`);
|
|
80
|
+
const options = {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: headers,
|
|
83
|
+
hostname: uri.hostname,
|
|
84
|
+
path: `${uri.pathname}${uri.search}`,
|
|
85
|
+
};
|
|
86
|
+
logger_1.logger.debug(`Prediction request: ${uri}`);
|
|
87
|
+
const req = https.request(options, function (res) {
|
|
88
|
+
// when the encoding is set, data chunks will be strings
|
|
89
|
+
res.setEncoding("utf-8");
|
|
90
|
+
let responseBody = "";
|
|
91
|
+
res.on("data", function (chunk) {
|
|
92
|
+
responseBody += chunk;
|
|
93
|
+
});
|
|
94
|
+
res.on("end", function () {
|
|
95
|
+
try {
|
|
96
|
+
resolve(Object.assign(Object.assign({}, res), { data: JSON.parse(responseBody) }));
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
reject(error);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
req.on("error", (err) => {
|
|
104
|
+
reject(err);
|
|
105
|
+
});
|
|
106
|
+
if (["path", "stream"].includes(input.inputType)) {
|
|
107
|
+
form.pipe(req);
|
|
108
|
+
}
|
|
109
|
+
if (input.inputType === "base64") {
|
|
110
|
+
req.write(body);
|
|
111
|
+
req.end();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
apiKeyFromEnv() {
|
|
116
|
+
const envVarValue = process.env[exports.API_KEY_ENVVAR_NAME];
|
|
117
|
+
if (envVarValue) {
|
|
118
|
+
logger_1.logger.debug(`Set '${this.keyName}' API key from environment: ${exports.API_KEY_ENVVAR_NAME}`);
|
|
119
|
+
return envVarValue;
|
|
120
|
+
}
|
|
121
|
+
return "";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.Endpoint = Endpoint;
|
|
125
|
+
class InvoiceEndpoint extends Endpoint {
|
|
126
|
+
constructor(apiKey) {
|
|
127
|
+
super(exports.STANDARD_API_OWNER, "invoices", "3", apiKey, "invoice");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.InvoiceEndpoint = InvoiceEndpoint;
|
|
131
|
+
class ReceiptEndpoint extends Endpoint {
|
|
132
|
+
constructor(apiKey) {
|
|
133
|
+
super(exports.STANDARD_API_OWNER, "expense_receipts", "3", apiKey, "receipt");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.ReceiptEndpoint = ReceiptEndpoint;
|
|
137
|
+
class PassportEndpoint extends Endpoint {
|
|
138
|
+
constructor(apiKey) {
|
|
139
|
+
super(exports.STANDARD_API_OWNER, "passport", "1", apiKey);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.PassportEndpoint = PassportEndpoint;
|
|
143
|
+
class CustomEndpoint extends Endpoint {
|
|
144
|
+
constructor(documentType, accountName, version, apiKey) {
|
|
145
|
+
super(accountName, documentType, version, apiKey);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.CustomEndpoint = CustomEndpoint;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { Response, InvoiceResponse, ReceiptResponse, FinancialDocResponse, PassportResponse, CustomResponse, } from "./response";
|
|
2
|
+
export { Endpoint, InvoiceEndpoint, ReceiptEndpoint, PassportEndpoint, CustomEndpoint, STANDARD_API_OWNER, API_KEY_ENVVAR_NAME, } from "./endpoint";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = exports.CustomEndpoint = exports.PassportEndpoint = exports.ReceiptEndpoint = exports.InvoiceEndpoint = exports.Endpoint = exports.CustomResponse = exports.PassportResponse = exports.FinancialDocResponse = exports.ReceiptResponse = exports.InvoiceResponse = exports.Response = void 0;
|
|
4
|
+
var response_1 = require("./response");
|
|
5
|
+
Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return response_1.Response; } });
|
|
6
|
+
Object.defineProperty(exports, "InvoiceResponse", { enumerable: true, get: function () { return response_1.InvoiceResponse; } });
|
|
7
|
+
Object.defineProperty(exports, "ReceiptResponse", { enumerable: true, get: function () { return response_1.ReceiptResponse; } });
|
|
8
|
+
Object.defineProperty(exports, "FinancialDocResponse", { enumerable: true, get: function () { return response_1.FinancialDocResponse; } });
|
|
9
|
+
Object.defineProperty(exports, "PassportResponse", { enumerable: true, get: function () { return response_1.PassportResponse; } });
|
|
10
|
+
Object.defineProperty(exports, "CustomResponse", { enumerable: true, get: function () { return response_1.CustomResponse; } });
|
|
11
|
+
var endpoint_1 = require("./endpoint");
|
|
12
|
+
Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return endpoint_1.Endpoint; } });
|
|
13
|
+
Object.defineProperty(exports, "InvoiceEndpoint", { enumerable: true, get: function () { return endpoint_1.InvoiceEndpoint; } });
|
|
14
|
+
Object.defineProperty(exports, "ReceiptEndpoint", { enumerable: true, get: function () { return endpoint_1.ReceiptEndpoint; } });
|
|
15
|
+
Object.defineProperty(exports, "PassportEndpoint", { enumerable: true, get: function () { return endpoint_1.PassportEndpoint; } });
|
|
16
|
+
Object.defineProperty(exports, "CustomEndpoint", { enumerable: true, get: function () { return endpoint_1.CustomEndpoint; } });
|
|
17
|
+
Object.defineProperty(exports, "STANDARD_API_OWNER", { enumerable: true, get: function () { return endpoint_1.STANDARD_API_OWNER; } });
|
|
18
|
+
Object.defineProperty(exports, "API_KEY_ENVVAR_NAME", { enumerable: true, get: function () { return endpoint_1.API_KEY_ENVVAR_NAME; } });
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Document, Passport, Receipt, Invoice, FinancialDocument, CustomDocument, DocumentConstructorProps } from "../documents";
|
|
2
|
+
import { FullText } from "../fields";
|
|
3
|
+
import { Input } from "../inputs";
|
|
4
|
+
export interface ResponseProps {
|
|
5
|
+
httpResponse: any;
|
|
6
|
+
documentType: string;
|
|
7
|
+
input: Input;
|
|
8
|
+
error: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Base class for all responses.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Response<DocType extends Document> {
|
|
14
|
+
httpResponse: any;
|
|
15
|
+
readonly documentType: string;
|
|
16
|
+
inputFile: Input;
|
|
17
|
+
document?: DocType;
|
|
18
|
+
pages: Array<DocType>;
|
|
19
|
+
constructor(params: ResponseProps);
|
|
20
|
+
protected getPageText(httpDataDocument: any, pageId: number): FullText;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Class for all constructed (API Builder) endpoint responses.
|
|
24
|
+
*/
|
|
25
|
+
export declare class CustomResponse extends Response<CustomDocument> {
|
|
26
|
+
constructor(params: ResponseProps);
|
|
27
|
+
protected formatResponse(): void;
|
|
28
|
+
}
|
|
29
|
+
declare type StandardDocumentSig<DocType extends Document> = {
|
|
30
|
+
new ({ apiPrediction, inputFile, pageId, fullText, }: DocumentConstructorProps): DocType;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Generic class for all standard (Off-the-Shelf) endpoint responses.
|
|
34
|
+
*/
|
|
35
|
+
export declare class StandardProductResponse<DocType extends Document> extends Response<DocType> {
|
|
36
|
+
documentClass: StandardDocumentSig<DocType>;
|
|
37
|
+
constructor(documentClass: StandardDocumentSig<DocType>, params: ResponseProps);
|
|
38
|
+
protected formatResponse(): void;
|
|
39
|
+
}
|
|
40
|
+
export declare class InvoiceResponse extends StandardProductResponse<Invoice> {
|
|
41
|
+
constructor(params: ResponseProps);
|
|
42
|
+
}
|
|
43
|
+
export declare class ReceiptResponse extends StandardProductResponse<Receipt> {
|
|
44
|
+
constructor(params: ResponseProps);
|
|
45
|
+
}
|
|
46
|
+
export declare class FinancialDocResponse extends StandardProductResponse<FinancialDocument> {
|
|
47
|
+
constructor(params: ResponseProps);
|
|
48
|
+
}
|
|
49
|
+
export declare class PassportResponse extends StandardProductResponse<Passport> {
|
|
50
|
+
constructor(params: ResponseProps);
|
|
51
|
+
}
|
|
52
|
+
export {};
|