mindee 1.1.0 → 1.3.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 +28 -0
- package/LICENSE +21 -202
- package/README.md +28 -15
- package/lib/api/request.js +1 -1
- package/lib/api/response.js +0 -2
- package/lib/documents/financialDocument.js +2 -2
- package/lib/inputs.js +2 -0
- package/mindee/api/financialDocument.js +3 -3
- package/mindee/api/invoice.js +1 -1
- package/mindee/api/object.js +1 -1
- package/mindee/api/request.js +16 -14
- package/mindee/api/response.js +19 -4
- package/mindee/documents/fields/field.js +2 -5
- package/mindee/documents/financialDocument.js +50 -9
- package/mindee/documents/invoice.js +56 -11
- package/mindee/documents/receipt.js +9 -9
- package/mindee/inputs.js +14 -9
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v1.3.0
|
|
4
|
+
|
|
5
|
+
### Changes
|
|
6
|
+
|
|
7
|
+
- :sparkles: allow sending the filename for streams and base64
|
|
8
|
+
- fixes :bug: not able to specify MIME type
|
|
9
|
+
- :page_facing_up: change license to MIT
|
|
10
|
+
- :white_check_mark: add node18 to tests
|
|
11
|
+
- various package updates
|
|
12
|
+
|
|
13
|
+
## v1.2.0
|
|
14
|
+
|
|
15
|
+
### Fixes
|
|
16
|
+
|
|
17
|
+
- fix: 🐛 Get `words` values when `includeWords` parameter is `true`
|
|
18
|
+
|
|
19
|
+
## v1.1.2
|
|
20
|
+
|
|
21
|
+
### Fixes
|
|
22
|
+
|
|
23
|
+
- fix: 🐛 Fix returned probability value
|
|
24
|
+
- fix: 🐛 Fix returned bbox value
|
|
25
|
+
|
|
26
|
+
### new
|
|
27
|
+
|
|
28
|
+
- new: ✨ New Mindee Invoice API V3 support
|
|
29
|
+
- new: ✨ Add new supplier and customer fields
|
|
30
|
+
|
|
3
31
|
## v1.1.0 (2022-01-03)
|
|
4
32
|
|
|
5
33
|
### new
|
package/LICENSE
CHANGED
|
@@ -1,202 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright [yyyy] [name of copyright owner]
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
202
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-Present Mindee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Mindee Client Library for Node.js
|
|
2
2
|
|
|
3
3
|
# Installation
|
|
4
4
|
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
The SDK is officially supported on Node.js LTS _active_ and _maintenance_
|
|
8
|
+
[versions](https://nodejs.org/en/about/releases/).
|
|
9
|
+
|
|
5
10
|
## From source code
|
|
6
11
|
|
|
7
|
-
Download and decompress or clone the source code from
|
|
12
|
+
Download and decompress or clone the source code from GitHub and then do in your Node.js project:
|
|
8
13
|
|
|
9
14
|
```sh
|
|
10
15
|
npm install mindee
|
|
@@ -12,7 +17,7 @@ npm install mindee
|
|
|
12
17
|
|
|
13
18
|
# Usage
|
|
14
19
|
|
|
15
|
-
You can use the SDK easily by creating a Client like this
|
|
20
|
+
You can use the SDK easily by creating a Client like this:
|
|
16
21
|
|
|
17
22
|
```js
|
|
18
23
|
const { Client } = require("mindee");
|
|
@@ -30,13 +35,29 @@ mindeeClient.financialDocument.parse({
|
|
|
30
35
|
});
|
|
31
36
|
```
|
|
32
37
|
|
|
33
|
-
Three
|
|
38
|
+
Three APIs are actually supported: invoice (`ìnvoice`), receipt (`receipt`) and financial document (`financialDocument`)
|
|
39
|
+
|
|
40
|
+
You can find more examples on how to use the SDK into the folder `examples`.
|
|
41
|
+
|
|
42
|
+
## MIME Types
|
|
43
|
+
When using `stream` or `base64` inputs, the MIME type is guessed using magic numbers.
|
|
44
|
+
In some cases, for example with non-standard files, it will not be possible to detect the MIME type in this way.
|
|
34
45
|
|
|
35
|
-
|
|
46
|
+
If you are getting MIME type errors, you will need to specify a file name having the correct extension, for example:
|
|
47
|
+
```js
|
|
48
|
+
mindeeClient.invoice.parse({
|
|
49
|
+
input: base64String,
|
|
50
|
+
inputType: "base64",
|
|
51
|
+
filename: "myfile.pdf",
|
|
52
|
+
});
|
|
53
|
+
```
|
|
36
54
|
|
|
37
55
|
## Client
|
|
38
56
|
|
|
39
|
-
The
|
|
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:
|
|
40
61
|
|
|
41
62
|
- invoiceToken (env variable : `MINDEE_INVOICE_TOKEN`) The expense api token
|
|
42
63
|
- receiptToken (env variable : `MINDEE_RECEIPT_TOKEN`) The invoice api token
|
|
@@ -118,15 +139,6 @@ mindeeClient.financialDocument
|
|
|
118
139
|
|
|
119
140
|
# Tests
|
|
120
141
|
|
|
121
|
-
First, link your package to the test repository by linking the node package to the tests :
|
|
122
|
-
|
|
123
|
-
```sh
|
|
124
|
-
cd mindee-api-nodejs/
|
|
125
|
-
npm link
|
|
126
|
-
cd tests/
|
|
127
|
-
npm link mindee
|
|
128
|
-
```
|
|
129
|
-
|
|
130
142
|
To run the tests, use the command `npm run test`
|
|
131
143
|
|
|
132
144
|
# Documentation
|
|
@@ -135,3 +147,4 @@ A basic documentation of the sdk has been done with the help of JSDoc.
|
|
|
135
147
|
If you want to generate it, you can use the command `npm run documentation`.
|
|
136
148
|
A folder `docs` will be created with generated documentation.
|
|
137
149
|
Open the `index.html` in your browser to read the documentation.
|
|
150
|
+
|
package/lib/api/request.js
CHANGED
package/lib/api/response.js
CHANGED
|
@@ -14,8 +14,6 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
14
14
|
|
|
15
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
16
|
|
|
17
|
-
var Document = require("../documents").document;
|
|
18
|
-
|
|
19
17
|
var Receipt = require("../documents").receipt;
|
|
20
18
|
|
|
21
19
|
var Invoice = require("../documents").invoice;
|
|
@@ -66,7 +66,7 @@ class FinancialDocument extends Document {
|
|
|
66
66
|
invoiceNumber: _invoiceNumber = undefined,
|
|
67
67
|
dueDate: _dueDate = undefined,
|
|
68
68
|
taxes: _taxes = undefined,
|
|
69
|
-
|
|
69
|
+
supplier: _supplier = undefined,
|
|
70
70
|
paymentDetails: _paymentDetails = undefined,
|
|
71
71
|
companyNumber: _companyNumber = undefined,
|
|
72
72
|
vatNumber: _vatNumber = undefined,
|
|
@@ -97,7 +97,7 @@ class FinancialDocument extends Document {
|
|
|
97
97
|
invoiceNumber: _invoiceNumber,
|
|
98
98
|
dueDate: _dueDate,
|
|
99
99
|
taxes: _taxes,
|
|
100
|
-
supplier,
|
|
100
|
+
supplier: _supplier,
|
|
101
101
|
paymentDetails: _paymentDetails,
|
|
102
102
|
companyNumber: _companyNumber,
|
|
103
103
|
vatNumber: _vatNumber,
|
package/lib/inputs.js
CHANGED
|
@@ -104,6 +104,8 @@ class Input {
|
|
|
104
104
|
|
|
105
105
|
var filetype = _this3.filename.split(".").pop();
|
|
106
106
|
|
|
107
|
+
console.log(_this3.filename.split("."));
|
|
108
|
+
|
|
107
109
|
if (!(filetype in _this3.MIMETYPES)) {
|
|
108
110
|
errorHandler.throw(new Error("File type is not allowed. It must be ".concat(Object.keys(_this3.MIMETYPES).toString())));
|
|
109
111
|
}
|
|
@@ -37,10 +37,10 @@ class APIFinancialDocument extends APIObject {
|
|
|
37
37
|
: this.receiptToken;
|
|
38
38
|
const url =
|
|
39
39
|
inputFile.fileExtension === "application/pdf"
|
|
40
|
-
?
|
|
41
|
-
:
|
|
40
|
+
? `/invoices/v${version}/predict`
|
|
41
|
+
: `/expense_receipts/v${version}/predict`;
|
|
42
42
|
super.parse();
|
|
43
|
-
return
|
|
43
|
+
return super._request(url, inputFile, includeWords);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
package/mindee/api/invoice.js
CHANGED
package/mindee/api/object.js
CHANGED
|
@@ -10,7 +10,7 @@ const request = require("./request");
|
|
|
10
10
|
class APIObject {
|
|
11
11
|
constructor(apiToken = undefined, apiName = "") {
|
|
12
12
|
this.apiToken = apiToken;
|
|
13
|
-
this.baseUrl = "https://api.mindee.net/v1/products/mindee
|
|
13
|
+
this.baseUrl = "https://api.mindee.net/v1/products/mindee";
|
|
14
14
|
this.apiName = apiName;
|
|
15
15
|
}
|
|
16
16
|
|
package/mindee/api/request.js
CHANGED
|
@@ -6,24 +6,27 @@ const os = require("os");
|
|
|
6
6
|
|
|
7
7
|
const request = (url, method, headers, input, includeWords = false) => {
|
|
8
8
|
return new Promise(function (resolve, reject) {
|
|
9
|
-
|
|
10
|
-
let body;
|
|
9
|
+
let form = new FormData();
|
|
11
10
|
|
|
12
11
|
headers["User-Agent"] = `mindee-api-nodejs@v${sdkVersion} nodejs-${
|
|
13
12
|
process.version
|
|
14
13
|
} ${os.type().toLowerCase()}`;
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
|
|
15
|
+
const fileParams = { filename: input.filename };
|
|
16
|
+
|
|
17
|
+
if (input.inputType === "base64") {
|
|
18
|
+
form.append(
|
|
19
|
+
"document",
|
|
20
|
+
Buffer.from(input.fileObject, "base64"),
|
|
21
|
+
fileParams
|
|
22
|
+
);
|
|
23
|
+
} else {
|
|
17
24
|
form.append("document", input.fileObject, fileParams);
|
|
18
|
-
if (includeWords) form.append("include_mvision", "true");
|
|
19
|
-
headers = { ...headers, ...form.getHeaders() };
|
|
20
|
-
} else if (input.inputType === "base64") {
|
|
21
|
-
let body_obj = { document: input.fileObject };
|
|
22
|
-
if (includeWords) body_obj["include_mvision"] = "true";
|
|
23
|
-
body = JSON.stringify(body_obj);
|
|
24
|
-
headers["Content-Type"] = "application/json";
|
|
25
|
-
headers["Content-Length"] = body.length;
|
|
26
25
|
}
|
|
26
|
+
if (includeWords) {
|
|
27
|
+
form.append("include_mvision", "true");
|
|
28
|
+
}
|
|
29
|
+
headers = { ...headers, ...form.getHeaders() };
|
|
27
30
|
|
|
28
31
|
const uri = new URL(url);
|
|
29
32
|
const options = {
|
|
@@ -61,8 +64,7 @@ const request = (url, method, headers, input, includeWords = false) => {
|
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
if (input.inputType === "base64") {
|
|
64
|
-
|
|
65
|
-
req.end();
|
|
67
|
+
form.pipe(req);
|
|
66
68
|
}
|
|
67
69
|
});
|
|
68
70
|
};
|
package/mindee/api/response.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const Document = require("../documents").document;
|
|
2
1
|
const Receipt = require("../documents").receipt;
|
|
3
2
|
const Invoice = require("../documents").invoice;
|
|
4
3
|
const FinancialDocument = require("../documents").financialDocument;
|
|
@@ -33,31 +32,47 @@ class Response {
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
formatResponse() {
|
|
35
|
+
let http_data_document = this.httpResponse.data.document;
|
|
36
36
|
const constructors = {
|
|
37
37
|
receipt: (params) => new Receipt(params),
|
|
38
38
|
invoice: (params) => new Invoice(params),
|
|
39
39
|
financialDocument: (params) => new FinancialDocument(params),
|
|
40
40
|
};
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
const predictions = http_data_document.inference.pages.entries();
|
|
42
43
|
this[`${this.documentType}s`] = [];
|
|
44
|
+
let document_words_content = [];
|
|
43
45
|
|
|
44
46
|
// Create a list of Document (Receipt, Invoice...) for each page of the input document
|
|
45
47
|
for (const [pageNumber, prediction] of predictions) {
|
|
48
|
+
let page_words_content = [];
|
|
49
|
+
if (
|
|
50
|
+
"ocr" in http_data_document &&
|
|
51
|
+
Object.keys(http_data_document.ocr).length > 0
|
|
52
|
+
) {
|
|
53
|
+
page_words_content =
|
|
54
|
+
http_data_document.ocr["mvision-v1"].pages[pageNumber].all_words;
|
|
55
|
+
document_words_content.push(
|
|
56
|
+
...http_data_document.ocr["mvision-v1"].pages[pageNumber].all_words
|
|
57
|
+
);
|
|
58
|
+
}
|
|
46
59
|
this[`${this.documentType}s`].push(
|
|
47
60
|
constructors[this.documentType]({
|
|
48
61
|
apiPrediction: prediction.prediction,
|
|
49
62
|
inputFile: this.input,
|
|
50
63
|
pageNumber: pageNumber,
|
|
64
|
+
words: page_words_content,
|
|
51
65
|
})
|
|
52
66
|
);
|
|
53
67
|
}
|
|
54
68
|
|
|
55
69
|
// Merge the list of Document into a unique Document
|
|
56
70
|
this[this.documentType] = constructors[this.documentType]({
|
|
57
|
-
apiPrediction:
|
|
71
|
+
apiPrediction: http_data_document.inference.prediction,
|
|
58
72
|
inputFile: this.input,
|
|
59
|
-
pageNumber:
|
|
73
|
+
pageNumber: http_data_document.n_pages,
|
|
60
74
|
level: "document",
|
|
75
|
+
words: document_words_content,
|
|
61
76
|
});
|
|
62
77
|
}
|
|
63
78
|
}
|
|
@@ -16,13 +16,10 @@ class Field {
|
|
|
16
16
|
this.pageNumber = pageNumber;
|
|
17
17
|
this.reconstructed = reconstructed;
|
|
18
18
|
this.value = undefined;
|
|
19
|
-
this.probability = 0.0;
|
|
20
|
-
this.bbox = [];
|
|
19
|
+
this.probability = prediction.confidence ? prediction.confidence : 0.0;
|
|
20
|
+
this.bbox = prediction.polygon ? prediction.polygon : [];
|
|
21
21
|
if (valueKey in prediction && prediction[valueKey] !== null) {
|
|
22
22
|
this.value = prediction[valueKey];
|
|
23
|
-
if (prediction.probability) this.probability = prediction.probability;
|
|
24
|
-
if (prediction.segmentation)
|
|
25
|
-
this.bbox = prediction.segmentation.bounding_box || [];
|
|
26
23
|
if (extraFields) {
|
|
27
24
|
for (const fieldName of extraFields) {
|
|
28
25
|
this[fieldName] = prediction[fieldName];
|
|
@@ -19,13 +19,17 @@ class FinancialDocument extends Document {
|
|
|
19
19
|
* @param {Object} Date - date value for creating FinancialDocument object from scratch
|
|
20
20
|
* @param {Object} InvoiceNumber - Invoice number value for creating FinancialDocument object from scratch
|
|
21
21
|
* @param {Object} taxes - taxes value for creating FinancialDocument object from scratch
|
|
22
|
-
* @param {Object}
|
|
22
|
+
* @param {Object} supplier - supplier value for creating FinancialDocument object from scratch
|
|
23
|
+
* @param {Object} supplierAddress - supplier address value for creating FinancialDocument object from scratch
|
|
23
24
|
* @param {Object} paymentDetails - payment details value for creating FinancialDocument object from scratch
|
|
24
25
|
* @param {Object} companyNumber - company number value for creating FinancialDocument object from scratch
|
|
25
26
|
* @param {Object} vatNumber - vat number value for creating FinancialDocument object from scratch
|
|
26
27
|
* @param {Object} orientation - orientation value for creating FinancialDocument object from scratch
|
|
27
28
|
* @param {Object} totalTax - total tax value for creating FinancialDocument object from scratch
|
|
28
29
|
* @param {Object} time - time value for creating FinancialDocument object from scratch
|
|
30
|
+
* @param {Object} customerName - customer name value for creating FinancialDocument object from scratch
|
|
31
|
+
* @param {Object} customerAddress - customer address value for creating FinancialDocument object from scratch
|
|
32
|
+
* @param {Object} customerCompanyRegistration - customer company registration value for creating FinancialDocument object from scratch
|
|
29
33
|
* @param {Object} pageNumber - pageNumber for multi pages pdf input
|
|
30
34
|
* @param {String} level - specify whether object is built from "page" level or "document" level prediction
|
|
31
35
|
*/
|
|
@@ -39,13 +43,18 @@ class FinancialDocument extends Document {
|
|
|
39
43
|
invoiceNumber = undefined,
|
|
40
44
|
dueDate = undefined,
|
|
41
45
|
taxes = undefined,
|
|
42
|
-
|
|
46
|
+
supplier = undefined,
|
|
47
|
+
supplierAddress = undefined,
|
|
43
48
|
paymentDetails = undefined,
|
|
44
49
|
companyNumber = undefined,
|
|
45
50
|
vatNumber = undefined,
|
|
46
51
|
orientation = undefined,
|
|
47
52
|
totalTax = undefined,
|
|
48
53
|
time = undefined,
|
|
54
|
+
customerName = undefined,
|
|
55
|
+
customerAddress = undefined,
|
|
56
|
+
customerCompanyRegistration = undefined,
|
|
57
|
+
words = undefined,
|
|
49
58
|
pageNumber = 0,
|
|
50
59
|
level = "page",
|
|
51
60
|
}) {
|
|
@@ -61,6 +70,7 @@ class FinancialDocument extends Document {
|
|
|
61
70
|
dueDate,
|
|
62
71
|
taxes,
|
|
63
72
|
supplier,
|
|
73
|
+
supplierAddress,
|
|
64
74
|
paymentDetails,
|
|
65
75
|
companyNumber,
|
|
66
76
|
vatNumber,
|
|
@@ -68,9 +78,12 @@ class FinancialDocument extends Document {
|
|
|
68
78
|
pageNumber,
|
|
69
79
|
totalTax,
|
|
70
80
|
time,
|
|
81
|
+
customerName,
|
|
82
|
+
customerAddress,
|
|
83
|
+
customerCompanyRegistration,
|
|
71
84
|
});
|
|
72
85
|
} else {
|
|
73
|
-
this.#initFromApiPrediction(apiPrediction, inputFile, pageNumber);
|
|
86
|
+
this.#initFromApiPrediction(apiPrediction, inputFile, pageNumber, words);
|
|
74
87
|
}
|
|
75
88
|
this.#checklist();
|
|
76
89
|
}
|
|
@@ -90,7 +103,11 @@ class FinancialDocument extends Document {
|
|
|
90
103
|
orientation,
|
|
91
104
|
pageNumber,
|
|
92
105
|
supplier,
|
|
106
|
+
supplierAddress,
|
|
93
107
|
time,
|
|
108
|
+
customerName,
|
|
109
|
+
customerAddress,
|
|
110
|
+
customerCompanyRegistration,
|
|
94
111
|
}) {
|
|
95
112
|
const constructPrediction = function (item) {
|
|
96
113
|
return { prediction: { value: item }, valueKey: "value", pageNumber };
|
|
@@ -102,12 +119,18 @@ class FinancialDocument extends Document {
|
|
|
102
119
|
this.date = new Date(constructPrediction(date));
|
|
103
120
|
this.dueDate = new Date(constructPrediction(dueDate));
|
|
104
121
|
this.supplier = new Field(constructPrediction(supplier));
|
|
122
|
+
this.supplierAddress = new Field(this.constructPrediction(supplierAddress));
|
|
105
123
|
this.time = new Field(constructPrediction(time));
|
|
106
124
|
this.orientation = new Orientation(constructPrediction(orientation));
|
|
107
125
|
this.invoiceNumber = new Field(constructPrediction(invoiceNumber));
|
|
108
126
|
this.paymentDetails = new Field(constructPrediction(paymentDetails));
|
|
109
127
|
this.companyNumber = new Field(constructPrediction(companyNumber));
|
|
110
128
|
this.vatNumber = new Field(constructPrediction(vatNumber));
|
|
129
|
+
this.customerName = new Field(this.constructPrediction(customerName));
|
|
130
|
+
this.customerAddress = new Field(this.constructPrediction(customerAddress));
|
|
131
|
+
this.customerCompanyRegistration = new Field(
|
|
132
|
+
this.constructPrediction(customerCompanyRegistration)
|
|
133
|
+
);
|
|
111
134
|
if (taxes !== undefined) {
|
|
112
135
|
this.taxes = [];
|
|
113
136
|
for (const t of taxes) {
|
|
@@ -123,13 +146,14 @@ class FinancialDocument extends Document {
|
|
|
123
146
|
}
|
|
124
147
|
}
|
|
125
148
|
|
|
126
|
-
#initFromApiPrediction(apiPrediction, inputFile, pageNumber) {
|
|
149
|
+
#initFromApiPrediction(apiPrediction, inputFile, pageNumber, words) {
|
|
127
150
|
if (Object.keys(apiPrediction).includes("invoice_number")) {
|
|
128
151
|
const invoice = new Invoice({
|
|
129
152
|
apiPrediction,
|
|
130
153
|
inputFile,
|
|
131
154
|
pageNumber,
|
|
132
155
|
level: this.level,
|
|
156
|
+
words: words,
|
|
133
157
|
});
|
|
134
158
|
this.locale = invoice.locale;
|
|
135
159
|
this.totalIncl = invoice.totalIncl;
|
|
@@ -139,19 +163,25 @@ class FinancialDocument extends Document {
|
|
|
139
163
|
this.dueDate = invoice.dueDate;
|
|
140
164
|
this.taxes = invoice.taxes;
|
|
141
165
|
this.supplier = invoice.supplier;
|
|
166
|
+
this.supplierAddress = invoice.supplierAddress;
|
|
142
167
|
this.paymentDetails = invoice.paymentDetails;
|
|
143
168
|
this.companyNumber = invoice.companyNumber;
|
|
144
169
|
this.orientation = invoice.orientation;
|
|
145
170
|
this.totalTax = invoice.totalTax;
|
|
171
|
+
if (invoice.words) this.words = invoice.words;
|
|
146
172
|
this.time = new Field({
|
|
147
|
-
prediction: { value: undefined,
|
|
173
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
148
174
|
});
|
|
175
|
+
this.customerName = invoice.customerName;
|
|
176
|
+
this.customerAddress = invoice.customerAddress;
|
|
177
|
+
this.customerCompanyRegistration = invoice.customerCompanyRegistration;
|
|
149
178
|
} else {
|
|
150
179
|
const receipt = new Receipt({
|
|
151
180
|
apiPrediction,
|
|
152
181
|
inputFile,
|
|
153
182
|
pageNumber,
|
|
154
183
|
level: this.level,
|
|
184
|
+
words: words,
|
|
155
185
|
});
|
|
156
186
|
this.orientation = receipt.orientation;
|
|
157
187
|
this.date = receipt.date;
|
|
@@ -161,17 +191,28 @@ class FinancialDocument extends Document {
|
|
|
161
191
|
this.totalIncl = receipt.totalIncl;
|
|
162
192
|
this.totalExcl = receipt.totalExcl;
|
|
163
193
|
this.supplier = receipt.merchantName;
|
|
194
|
+
this.supplierAddress = new Field({
|
|
195
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
196
|
+
});
|
|
164
197
|
this.time = receipt.time;
|
|
165
198
|
this.totalTax = receipt.totalTax;
|
|
166
199
|
this.invoiceNumber = new Field({
|
|
167
|
-
prediction: { value: undefined,
|
|
200
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
168
201
|
});
|
|
169
202
|
this.paymentDetails = new Field({
|
|
170
|
-
prediction: { value: undefined,
|
|
203
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
171
204
|
});
|
|
172
205
|
this.companyNumber = new Field({
|
|
173
|
-
prediction: { value: undefined,
|
|
206
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
207
|
+
});
|
|
208
|
+
this.customerName = new Field({
|
|
209
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
210
|
+
});
|
|
211
|
+
this.customerAddress = new Field({
|
|
212
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
174
213
|
});
|
|
214
|
+
this.customerCompanyRegistration = [];
|
|
215
|
+
if (receipt.words) this.words = receipt.words;
|
|
175
216
|
}
|
|
176
217
|
}
|
|
177
218
|
|
|
@@ -216,7 +257,7 @@ class FinancialDocument extends Document {
|
|
|
216
257
|
this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal &&
|
|
217
258
|
reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02
|
|
218
259
|
) {
|
|
219
|
-
this.taxes = this.taxes.map((tax) => ({ ...tax,
|
|
260
|
+
this.taxes = this.taxes.map((tax) => ({ ...tax, confidence: 1.0 }));
|
|
220
261
|
this.totalTax.probability = 1.0;
|
|
221
262
|
this.totalIncl.probability = 1.0;
|
|
222
263
|
return true;
|
|
@@ -18,11 +18,15 @@ class Invoice extends Document {
|
|
|
18
18
|
* @param {Object} invoiceNumber - invoice number value for creating Invoice object from scratch
|
|
19
19
|
* @param {Object} taxes - taxes value for creating Invoice object from scratch
|
|
20
20
|
* @param {Object} supplier - supplier value for creating Invoice object from scratch
|
|
21
|
+
* @param {Object} supplierAddress - supplier address value for creating Invoice object from scratch
|
|
21
22
|
* @param {Object} paymentDetails - payment details value for creating Invoice object from scratch
|
|
22
23
|
* @param {Object} companyNumber - company number value for creating Invoice object from scratch
|
|
23
24
|
* @param {Object} vatNumber - vat number value for creating Invoice object from scratch
|
|
24
25
|
* @param {Object} orientation - orientation value for creating Invoice object from scratch
|
|
25
26
|
* @param {Object} totalTax - total tax value for creating Invoice object from scratch
|
|
27
|
+
* @param {Object} customerName - customer name value for creating Invoice object from scratch
|
|
28
|
+
* @param {Object} customerAddress - customer address value for creating Invoice object from scratch
|
|
29
|
+
* @param {Object} customerCompanyRegistration - customer company registration value for creating Invoice object from scratch
|
|
26
30
|
* @param {Number} pageNumber - pageNumber for multi pages pdf input
|
|
27
31
|
* @param {String} level - specify whether object is built from "page" level or "document" level prediction
|
|
28
32
|
*/
|
|
@@ -37,11 +41,16 @@ class Invoice extends Document {
|
|
|
37
41
|
dueDate = undefined,
|
|
38
42
|
taxes = undefined,
|
|
39
43
|
supplier = undefined,
|
|
44
|
+
supplierAddress = undefined,
|
|
40
45
|
paymentDetails = undefined,
|
|
41
46
|
companyNumber = undefined,
|
|
42
47
|
vatNumber = undefined,
|
|
43
48
|
orientation = undefined,
|
|
44
49
|
totalTax = undefined,
|
|
50
|
+
customerName = undefined,
|
|
51
|
+
customerAddress = undefined,
|
|
52
|
+
customerCompanyRegistration = undefined,
|
|
53
|
+
words = undefined,
|
|
45
54
|
pageNumber = 0,
|
|
46
55
|
level = "page",
|
|
47
56
|
}) {
|
|
@@ -60,15 +69,19 @@ class Invoice extends Document {
|
|
|
60
69
|
dueDate,
|
|
61
70
|
taxes,
|
|
62
71
|
supplier,
|
|
72
|
+
supplierAddress,
|
|
63
73
|
paymentDetails,
|
|
64
74
|
companyNumber,
|
|
65
75
|
vatNumber,
|
|
66
76
|
orientation,
|
|
67
77
|
pageNumber,
|
|
68
78
|
totalTax,
|
|
79
|
+
customerName,
|
|
80
|
+
customerAddress,
|
|
81
|
+
customerCompanyRegistration,
|
|
69
82
|
});
|
|
70
83
|
} else {
|
|
71
|
-
this.#initFromApiPrediction(apiPrediction, pageNumber);
|
|
84
|
+
this.#initFromApiPrediction(apiPrediction, pageNumber, words);
|
|
72
85
|
}
|
|
73
86
|
this.#checklist();
|
|
74
87
|
this.#reconstruct();
|
|
@@ -84,11 +97,15 @@ class Invoice extends Document {
|
|
|
84
97
|
dueDate,
|
|
85
98
|
taxes,
|
|
86
99
|
supplier,
|
|
100
|
+
supplierAddress,
|
|
87
101
|
paymentDetails,
|
|
88
102
|
companyNumber,
|
|
89
103
|
vatNumber,
|
|
90
104
|
orientation,
|
|
91
105
|
pageNumber,
|
|
106
|
+
customerName,
|
|
107
|
+
customerAddress,
|
|
108
|
+
customerCompanyRegistration,
|
|
92
109
|
}) {
|
|
93
110
|
this.locale = new Locale(this.constructPrediction(locale));
|
|
94
111
|
this.totalIncl = new Amount(this.constructPrediction(totalIncl));
|
|
@@ -98,10 +115,16 @@ class Invoice extends Document {
|
|
|
98
115
|
this.invoiceDate = new Date(this.constructPrediction(invoiceDate));
|
|
99
116
|
this.dueDate = new Date(this.constructPrediction(dueDate));
|
|
100
117
|
this.supplier = new Field(this.constructPrediction(supplier));
|
|
118
|
+
this.supplierAddress = new Field(this.constructPrediction(supplierAddress));
|
|
101
119
|
this.invoiceNumber = new Field(this.constructPrediction(invoiceNumber));
|
|
102
120
|
this.paymentDetails = new Field(this.constructPrediction(paymentDetails));
|
|
103
121
|
this.companyNumber = new Field(this.constructPrediction(companyNumber));
|
|
104
122
|
this.vatNumber = new Field(this.constructPrediction(vatNumber));
|
|
123
|
+
this.customerName = new Field(this.constructPrediction(customerName));
|
|
124
|
+
this.customerAddress = new Field(this.constructPrediction(customerAddress));
|
|
125
|
+
this.customerCompanyRegistration = new Field(
|
|
126
|
+
this.constructPrediction(customerCompanyRegistration)
|
|
127
|
+
);
|
|
105
128
|
if (taxes !== undefined) {
|
|
106
129
|
this.taxes = [];
|
|
107
130
|
for (const t of taxes) {
|
|
@@ -120,8 +143,7 @@ class Invoice extends Document {
|
|
|
120
143
|
}
|
|
121
144
|
}
|
|
122
145
|
|
|
123
|
-
#initFromApiPrediction(apiPrediction, pageNumber) {
|
|
124
|
-
this.words = [];
|
|
146
|
+
#initFromApiPrediction(apiPrediction, pageNumber, words) {
|
|
125
147
|
this.locale = new Locale({ prediction: apiPrediction.locale, pageNumber });
|
|
126
148
|
this.totalIncl = new Amount({
|
|
127
149
|
prediction: apiPrediction.total_incl,
|
|
@@ -129,7 +151,7 @@ class Invoice extends Document {
|
|
|
129
151
|
pageNumber,
|
|
130
152
|
});
|
|
131
153
|
this.totalTax = new Amount({
|
|
132
|
-
prediction: { value: undefined,
|
|
154
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
133
155
|
valueKey: "value",
|
|
134
156
|
pageNumber,
|
|
135
157
|
});
|
|
@@ -179,6 +201,27 @@ class Invoice extends Document {
|
|
|
179
201
|
prediction: apiPrediction.supplier,
|
|
180
202
|
pageNumber,
|
|
181
203
|
});
|
|
204
|
+
this.supplierAddress = new Field({
|
|
205
|
+
prediction: apiPrediction.supplier_address,
|
|
206
|
+
pageNumber,
|
|
207
|
+
});
|
|
208
|
+
this.customerName = new Field({
|
|
209
|
+
prediction: apiPrediction.customer,
|
|
210
|
+
pageNumber,
|
|
211
|
+
});
|
|
212
|
+
this.customerAddress = new Field({
|
|
213
|
+
prediction: apiPrediction.customer_address,
|
|
214
|
+
pageNumber,
|
|
215
|
+
});
|
|
216
|
+
this.customerCompanyRegistration = apiPrediction.customer_company_registration.map(
|
|
217
|
+
function (customerCompanyRegistration) {
|
|
218
|
+
return new Field({
|
|
219
|
+
prediction: customerCompanyRegistration,
|
|
220
|
+
pageNumber,
|
|
221
|
+
extraFields: ["type"],
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
);
|
|
182
225
|
this.paymentDetails = apiPrediction.payment_details.map(function (
|
|
183
226
|
paymentDetail
|
|
184
227
|
) {
|
|
@@ -194,14 +237,13 @@ class Invoice extends Document {
|
|
|
194
237
|
this.constructPrediction({
|
|
195
238
|
prediction: {
|
|
196
239
|
value: undefined,
|
|
197
|
-
|
|
240
|
+
confidence: 0.0,
|
|
198
241
|
degrees: undefined,
|
|
199
242
|
},
|
|
200
243
|
})
|
|
201
244
|
);
|
|
202
245
|
}
|
|
203
|
-
|
|
204
|
-
if ("mvision" in apiPrediction) this.words = apiPrediction.mvision;
|
|
246
|
+
if (words && words.length > 0) this.words = words;
|
|
205
247
|
}
|
|
206
248
|
|
|
207
249
|
toString() {
|
|
@@ -213,6 +255,9 @@ class Invoice extends Document {
|
|
|
213
255
|
Total amount excluding taxes: ${this.totalExcl.value}
|
|
214
256
|
Invoice Date: ${this.invoiceDate.value}
|
|
215
257
|
Supplier name: ${this.supplier.value}
|
|
258
|
+
Supplier address: ${this.supplierAddress.value}
|
|
259
|
+
Customer name: ${this.customerName.value}
|
|
260
|
+
Customer address: ${this.customerAddress.value}
|
|
216
261
|
Taxes: ${this.taxes.map((tax) => tax.toString()).join(" - ")}
|
|
217
262
|
Total taxes: ${this.totalTax.value}
|
|
218
263
|
`;
|
|
@@ -330,7 +375,7 @@ class Invoice extends Document {
|
|
|
330
375
|
value: this.taxes.reduce((acc, tax) => {
|
|
331
376
|
return tax.value !== undefined ? acc + tax.value : acc;
|
|
332
377
|
}, 0),
|
|
333
|
-
|
|
378
|
+
confidence: Field.arrayProbability(this.taxes),
|
|
334
379
|
};
|
|
335
380
|
if (totalTax.value > 0)
|
|
336
381
|
this.totalTax = new Amount({
|
|
@@ -350,7 +395,7 @@ class Invoice extends Document {
|
|
|
350
395
|
) {
|
|
351
396
|
const totalTax = {
|
|
352
397
|
value: this.totalIncl.value - this.totalExcl.value,
|
|
353
|
-
|
|
398
|
+
confidence: this.totalIncl.probability * this.totalExcl.probability,
|
|
354
399
|
};
|
|
355
400
|
if (totalTax.value > 0)
|
|
356
401
|
this.totalTax = new Amount({
|
|
@@ -373,7 +418,7 @@ class Invoice extends Document {
|
|
|
373
418
|
this.taxes.reduce((acc, tax) => {
|
|
374
419
|
return tax.value !== undefined ? acc + tax.value : acc;
|
|
375
420
|
}, 0),
|
|
376
|
-
|
|
421
|
+
confidence:
|
|
377
422
|
Field.arrayProbability(this.taxes) * this.totalIncl.probability,
|
|
378
423
|
};
|
|
379
424
|
this.totalExcl = new Amount({
|
|
@@ -396,7 +441,7 @@ class Invoice extends Document {
|
|
|
396
441
|
this.taxes.reduce((acc, tax) => {
|
|
397
442
|
return tax.value ? acc + tax.value : acc;
|
|
398
443
|
}, 0.0),
|
|
399
|
-
|
|
444
|
+
confidence:
|
|
400
445
|
Field.arrayProbability(this.taxes) * this.totalExcl.probability,
|
|
401
446
|
};
|
|
402
447
|
this.totalIncl = new Amount({
|
|
@@ -37,6 +37,7 @@ class Receipt extends Document {
|
|
|
37
37
|
orientation = undefined,
|
|
38
38
|
totalTax = undefined,
|
|
39
39
|
totalExcl = undefined,
|
|
40
|
+
words = undefined,
|
|
40
41
|
pageNumber = 0,
|
|
41
42
|
level = "page",
|
|
42
43
|
}) {
|
|
@@ -60,7 +61,7 @@ class Receipt extends Document {
|
|
|
60
61
|
pageNumber,
|
|
61
62
|
});
|
|
62
63
|
} else {
|
|
63
|
-
this.#initFromApiPrediction(apiPrediction, pageNumber);
|
|
64
|
+
this.#initFromApiPrediction(apiPrediction, pageNumber, words);
|
|
64
65
|
}
|
|
65
66
|
this.#checklist();
|
|
66
67
|
this.#reconstruct();
|
|
@@ -108,8 +109,7 @@ class Receipt extends Document {
|
|
|
108
109
|
@param apiPrediction: Raw prediction from HTTP response
|
|
109
110
|
@param pageNumber: Page number for multi pages pdf input
|
|
110
111
|
*/
|
|
111
|
-
#initFromApiPrediction(apiPrediction, pageNumber) {
|
|
112
|
-
this.words = [];
|
|
112
|
+
#initFromApiPrediction(apiPrediction, pageNumber, words) {
|
|
113
113
|
this.locale = new Locale({ prediction: apiPrediction.locale, pageNumber });
|
|
114
114
|
this.totalIncl = new Amount({
|
|
115
115
|
prediction: apiPrediction.total_incl,
|
|
@@ -146,12 +146,12 @@ class Receipt extends Document {
|
|
|
146
146
|
})
|
|
147
147
|
);
|
|
148
148
|
this.totalTax = new Amount({
|
|
149
|
-
prediction: { value: undefined,
|
|
149
|
+
prediction: { value: undefined, confidence: 0 },
|
|
150
150
|
valueKey: "value",
|
|
151
151
|
pageNumber,
|
|
152
152
|
});
|
|
153
153
|
this.totalExcl = new Amount({
|
|
154
|
-
prediction: { value: undefined,
|
|
154
|
+
prediction: { value: undefined, confidence: 0 },
|
|
155
155
|
valueKey: "value",
|
|
156
156
|
pageNumber,
|
|
157
157
|
});
|
|
@@ -165,13 +165,13 @@ class Receipt extends Document {
|
|
|
165
165
|
this.constructPrediction({
|
|
166
166
|
prediction: {
|
|
167
167
|
value: undefined,
|
|
168
|
-
|
|
168
|
+
confidence: 0.0,
|
|
169
169
|
degrees: undefined,
|
|
170
170
|
},
|
|
171
171
|
})
|
|
172
172
|
);
|
|
173
173
|
}
|
|
174
|
-
if (
|
|
174
|
+
if (words && words.length > 0) this.words = words;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
toString() {
|
|
@@ -250,7 +250,7 @@ class Receipt extends Document {
|
|
|
250
250
|
if (this.taxes.length && this.totalIncl.value != null) {
|
|
251
251
|
const totalExcl = {
|
|
252
252
|
value: this.totalIncl.value - Field.arraySum(this.taxes),
|
|
253
|
-
|
|
253
|
+
confidence:
|
|
254
254
|
Field.arrayProbability(this.taxes) * this.totalIncl.probability,
|
|
255
255
|
};
|
|
256
256
|
this.totalExcl = new Amount({
|
|
@@ -272,7 +272,7 @@ class Receipt extends Document {
|
|
|
272
272
|
value: this.taxes
|
|
273
273
|
.map((tax) => tax.value || 0)
|
|
274
274
|
.reduce((a, b) => a + b, 0),
|
|
275
|
-
|
|
275
|
+
confidence: Field.arrayProbability(this.taxes),
|
|
276
276
|
};
|
|
277
277
|
if (totalTax.value > 0)
|
|
278
278
|
this.totalTax = new Amount({
|
package/mindee/inputs.js
CHANGED
|
@@ -52,18 +52,24 @@ class Input {
|
|
|
52
52
|
async initBase64() {
|
|
53
53
|
this.fileObject = this.file;
|
|
54
54
|
this.filepath = undefined;
|
|
55
|
-
this.fileExtension = undefined;
|
|
56
55
|
|
|
57
|
-
if (this.
|
|
58
|
-
const
|
|
56
|
+
if (this.filename === undefined) {
|
|
57
|
+
const mimeType = await fileType.fromBuffer(
|
|
59
58
|
Buffer.from(this.fileObject, "base64")
|
|
60
59
|
);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} else
|
|
65
|
-
|
|
60
|
+
if (mimeType !== undefined) {
|
|
61
|
+
this.fileExtension = mimeType.mime;
|
|
62
|
+
this.filename = `from_${this.inputType}.${mimeType.ext}`;
|
|
63
|
+
} else {
|
|
64
|
+
throw "Could not determine the MIME type. Please specify the 'filename' option.";
|
|
66
65
|
}
|
|
66
|
+
} else {
|
|
67
|
+
const filetype = this.filename.split(".").pop();
|
|
68
|
+
this.fileExtension = this.MIMETYPES[filetype];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (this.fileExtension === "application/pdf" && this.allowCutPdf == true) {
|
|
72
|
+
await this.cutPdf();
|
|
67
73
|
}
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -74,7 +80,6 @@ class Input {
|
|
|
74
80
|
|
|
75
81
|
// Check if file type is valid
|
|
76
82
|
const filetype = this.filename.split(".").pop();
|
|
77
|
-
console.log(this.filename.split("."));
|
|
78
83
|
if (!(filetype in this.MIMETYPES)) {
|
|
79
84
|
errorHandler.throw(
|
|
80
85
|
new Error(
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Mindee
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Mindee Client Library for Node.js",
|
|
5
5
|
"main": "mindee/index.js",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "babel mindee -d lib",
|
|
9
9
|
"test": "npm run build && mocha tests/**/*.js",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"prettier": "^2.2.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"base64-arraybuffer": "^1.0.
|
|
37
|
+
"base64-arraybuffer": "^1.0.2",
|
|
38
38
|
"base64-stream": "^1.0.0",
|
|
39
39
|
"concat-stream": "^2.0.0",
|
|
40
40
|
"file-type": "^16.5.3",
|
|
41
41
|
"form-data": "^3.0.1",
|
|
42
|
-
"pdf-lib": "^1.
|
|
42
|
+
"pdf-lib": "^1.17.1"
|
|
43
43
|
},
|
|
44
44
|
"keywords": [
|
|
45
45
|
"javascript",
|