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.
Files changed (161) hide show
  1. package/CHANGELOG.md +47 -18
  2. package/README.md +43 -127
  3. package/bin/mindee +3 -0
  4. package/dist/package.json +70 -0
  5. package/dist/src/api/endpoint.d.ts +29 -0
  6. package/dist/src/api/endpoint.js +148 -0
  7. package/dist/src/api/index.d.ts +2 -0
  8. package/dist/src/api/index.js +18 -0
  9. package/dist/src/api/response.d.ts +52 -0
  10. package/dist/src/api/response.js +107 -0
  11. package/dist/src/cli.d.ts +1 -0
  12. package/dist/src/cli.js +117 -0
  13. package/dist/src/client.d.ts +48 -0
  14. package/dist/src/client.js +134 -0
  15. package/dist/src/constants.d.ts +13 -0
  16. package/dist/src/constants.js +54 -0
  17. package/dist/src/documents/custom.d.ts +14 -0
  18. package/dist/src/documents/custom.js +48 -0
  19. package/dist/src/documents/document.d.ts +38 -0
  20. package/dist/{documents → src/documents}/document.js +15 -35
  21. package/dist/src/documents/documentConfig.d.ts +44 -0
  22. package/dist/src/documents/documentConfig.js +121 -0
  23. package/dist/src/documents/financialDocument.d.ts +32 -0
  24. package/dist/src/documents/financialDocument.js +130 -0
  25. package/dist/src/documents/index.d.ts +12 -0
  26. package/dist/src/documents/index.js +20 -0
  27. package/dist/src/documents/invoice.d.ts +37 -0
  28. package/dist/src/documents/invoice.js +303 -0
  29. package/dist/src/documents/passport.d.ts +36 -0
  30. package/dist/src/documents/passport.js +218 -0
  31. package/dist/src/documents/receipt.d.ts +24 -0
  32. package/dist/src/documents/receipt.js +157 -0
  33. package/dist/src/errors/handler.d.ts +7 -0
  34. package/dist/{errors → src/errors}/handler.js +5 -4
  35. package/dist/src/fields/amount.d.ts +13 -0
  36. package/dist/{documents → src}/fields/amount.js +19 -6
  37. package/dist/src/fields/companyRegistration.d.ts +6 -0
  38. package/dist/src/fields/companyRegistration.js +11 -0
  39. package/dist/src/fields/customDocs.d.ts +42 -0
  40. package/dist/src/fields/customDocs.js +61 -0
  41. package/dist/src/fields/date.d.ts +12 -0
  42. package/dist/src/fields/date.js +25 -0
  43. package/dist/src/fields/field.d.ts +74 -0
  44. package/dist/{documents → src}/fields/field.js +48 -27
  45. package/dist/src/fields/fullText.d.ts +24 -0
  46. package/dist/src/fields/fullText.js +89 -0
  47. package/dist/src/fields/index.d.ts +11 -0
  48. package/dist/src/fields/index.js +27 -0
  49. package/dist/src/fields/locale.d.ts +13 -0
  50. package/dist/{documents → src}/fields/locale.js +20 -5
  51. package/dist/src/fields/orientation.d.ts +10 -0
  52. package/dist/{documents → src}/fields/orientation.js +5 -5
  53. package/dist/src/fields/paymentDetails.d.ts +31 -0
  54. package/dist/{documents → src}/fields/paymentDetails.js +14 -6
  55. package/dist/src/fields/tax.d.ts +30 -0
  56. package/dist/src/fields/tax.js +51 -0
  57. package/dist/src/geometry.d.ts +59 -0
  58. package/dist/src/geometry.js +113 -0
  59. package/dist/src/index.d.ts +2 -0
  60. package/dist/src/index.js +12 -0
  61. package/dist/src/inputs.d.ts +69 -0
  62. package/dist/src/inputs.js +223 -0
  63. package/dist/src/logger.d.ts +20 -0
  64. package/dist/src/logger.js +35 -0
  65. package/package.json +45 -26
  66. package/.eslintrc +0 -24
  67. package/.mocharc.yaml +0 -2
  68. package/.nyc_output/f57ba3bc-1777-4ecc-81e1-230327c2a401.json +0 -1
  69. package/.nyc_output/processinfo/f57ba3bc-1777-4ecc-81e1-230327c2a401.json +0 -1
  70. package/.nyc_output/processinfo/index.json +0 -1
  71. package/.prettierrc +0 -4
  72. package/.tool-versions +0 -1
  73. package/CODE_OF_CONDUCT.md +0 -63
  74. package/CONTRIBUTING.md +0 -84
  75. package/ISSUE_TEMPLATE.md +0 -45
  76. package/PULL_REQUEST_TEMPLATE.md +0 -45
  77. package/babel.config.json +0 -10
  78. package/coverage/coverage.json +0 -1
  79. package/coverage/lcov-report/base.css +0 -224
  80. package/coverage/lcov-report/block-navigation.js +0 -79
  81. package/coverage/lcov-report/favicon.png +0 -0
  82. package/coverage/lcov-report/index.html +0 -171
  83. package/coverage/lcov-report/prettify.css +0 -1
  84. package/coverage/lcov-report/prettify.js +0 -2
  85. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  86. package/coverage/lcov-report/sorter.js +0 -170
  87. package/coverage/lcov.info +0 -1595
  88. package/coverage.lcov +0 -1595
  89. package/dist/api/financialDocument.js +0 -51
  90. package/dist/api/index.js +0 -13
  91. package/dist/api/invoice.js +0 -59
  92. package/dist/api/object.js +0 -80
  93. package/dist/api/receipt.js +0 -45
  94. package/dist/api/request.js +0 -90
  95. package/dist/api/response.js +0 -91
  96. package/dist/documents/fields/date.js +0 -17
  97. package/dist/documents/fields/index.js +0 -17
  98. package/dist/documents/fields/tax.js +0 -42
  99. package/dist/documents/financialDocument.js +0 -216
  100. package/dist/documents/index.js +0 -13
  101. package/dist/documents/invoice.js +0 -361
  102. package/dist/documents/receipt.js +0 -231
  103. package/dist/index.js +0 -23
  104. package/dist/inputs.js +0 -208
  105. package/dist/logger.js +0 -34
  106. package/examples/.env.example +0 -2
  107. package/examples/documents/invoices/credit_note.pdf +0 -900
  108. package/examples/documents/invoices/invoice.pdf +0 -0
  109. package/examples/documents/invoices/invoice_6p.pdf +0 -0
  110. package/examples/documents/receipts/receipt.jpg +0 -0
  111. package/examples/financialDocument.js +0 -32
  112. package/examples/invoice.js +0 -74
  113. package/examples/receipt.js +0 -45
  114. package/lib/api/financialDocument.js +0 -59
  115. package/lib/api/index.js +0 -7
  116. package/lib/api/invoice.js +0 -73
  117. package/lib/api/object.js +0 -90
  118. package/lib/api/receipt.js +0 -58
  119. package/lib/api/request.js +0 -84
  120. package/lib/api/response.js +0 -92
  121. package/lib/documents/document.js +0 -97
  122. package/lib/documents/fields/amount.js +0 -35
  123. package/lib/documents/fields/date.js +0 -36
  124. package/lib/documents/fields/field.js +0 -102
  125. package/lib/documents/fields/index.js +0 -9
  126. package/lib/documents/fields/locale.js +0 -35
  127. package/lib/documents/fields/orientation.js +0 -33
  128. package/lib/documents/fields/paymentDetails.js +0 -71
  129. package/lib/documents/fields/tax.js +0 -57
  130. package/lib/documents/financialDocument.js +0 -280
  131. package/lib/documents/index.js +0 -7
  132. package/lib/documents/invoice.js +0 -451
  133. package/lib/documents/receipt.js +0 -332
  134. package/lib/errors/handler.js +0 -19
  135. package/lib/index.js +0 -40
  136. package/lib/inputs.js +0 -190
  137. package/lib/logger.js +0 -52
  138. package/mindee/api/financialDocument.js +0 -47
  139. package/mindee/api/index.js +0 -5
  140. package/mindee/api/invoice.js +0 -53
  141. package/mindee/api/object.js +0 -82
  142. package/mindee/api/receipt.js +0 -39
  143. package/mindee/api/request.js +0 -72
  144. package/mindee/api/response.js +0 -80
  145. package/mindee/documents/document.js +0 -69
  146. package/mindee/documents/fields/amount.js +0 -25
  147. package/mindee/documents/fields/date.js +0 -29
  148. package/mindee/documents/fields/field.js +0 -86
  149. package/mindee/documents/fields/index.js +0 -7
  150. package/mindee/documents/fields/locale.js +0 -30
  151. package/mindee/documents/fields/orientation.js +0 -24
  152. package/mindee/documents/fields/paymentDetails.js +0 -52
  153. package/mindee/documents/fields/tax.js +0 -47
  154. package/mindee/documents/financialDocument.js +0 -269
  155. package/mindee/documents/index.js +0 -5
  156. package/mindee/documents/invoice.js +0 -456
  157. package/mindee/documents/receipt.js +0 -287
  158. package/mindee/errors/handler.js +0 -16
  159. package/mindee/index.js +0 -36
  160. package/mindee/inputs.js +0 -158
  161. package/mindee/logger.js +0 -33
@@ -1,280 +0,0 @@
1
- "use strict";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
-
7
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
-
9
- function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
10
-
11
- var Document = require("./document");
12
-
13
- var Invoice = require("./invoice");
14
-
15
- var Receipt = require("./receipt");
16
-
17
- var Field = require("./fields").field;
18
-
19
- var Date = require("./fields").date;
20
-
21
- var Amount = require("./fields").amount;
22
-
23
- var Locale = require("./fields").locale;
24
-
25
- var Orientation = require("./fields").orientation;
26
-
27
- var Tax = require("./fields").tax;
28
-
29
- var _initFromScratch = new WeakSet();
30
-
31
- var _initFromApiPrediction = new WeakSet();
32
-
33
- var _checklist = new WeakSet();
34
-
35
- var _taxesMatchTotalIncl = new WeakSet();
36
-
37
- class FinancialDocument extends Document {
38
- /**
39
- * @param {Object} apiPrediction - Json parsed prediction from HTTP response
40
- * @param {Input} input - Input object
41
- * @param {Integer} pageNumber - Page number for multi pages pdf input
42
- * @param {Object} locale - locale value for creating FinancialDocument object from scratch
43
- * @param {Object} totalIncl - total tax included value for creating FinancialDocument object from scratch
44
- * @param {Object} totalExcl - total tax excluded value for creating FinancialDocument object from scratch
45
- * @param {Object} Date - date value for creating FinancialDocument object from scratch
46
- * @param {Object} InvoiceNumber - Invoice number value for creating FinancialDocument object from scratch
47
- * @param {Object} taxes - taxes value for creating FinancialDocument object from scratch
48
- * @param {Object} merchantName - merchant name value for creating FinancialDocument object from scratch
49
- * @param {Object} paymentDetails - payment details value for creating FinancialDocument object from scratch
50
- * @param {Object} companyNumber - company number value for creating FinancialDocument object from scratch
51
- * @param {Object} vatNumber - vat number value for creating FinancialDocument object from scratch
52
- * @param {Object} orientation - orientation value for creating FinancialDocument object from scratch
53
- * @param {Object} totalTax - total tax value for creating FinancialDocument object from scratch
54
- * @param {Object} time - time value for creating FinancialDocument object from scratch
55
- * @param {Object} pageNumber - pageNumber for multi pages pdf input
56
- * @param {String} level - specify whether object is built from "page" level or "document" level prediction
57
- */
58
- constructor(_ref) {
59
- var {
60
- apiPrediction: _apiPrediction = undefined,
61
- inputFile: _inputFile = undefined,
62
- locale: _locale = undefined,
63
- totalIncl: _totalIncl = undefined,
64
- totalExcl: _totalExcl = undefined,
65
- date: _date = undefined,
66
- invoiceNumber: _invoiceNumber = undefined,
67
- dueDate: _dueDate = undefined,
68
- taxes: _taxes = undefined,
69
- supplier: _supplier = undefined,
70
- paymentDetails: _paymentDetails = undefined,
71
- companyNumber: _companyNumber = undefined,
72
- vatNumber: _vatNumber = undefined,
73
- orientation: _orientation = undefined,
74
- totalTax: _totalTax = undefined,
75
- time: _time = undefined,
76
- pageNumber: _pageNumber = 0,
77
- level = "page"
78
- } = _ref;
79
- super(_inputFile);
80
-
81
- _taxesMatchTotalIncl.add(this);
82
-
83
- _checklist.add(this);
84
-
85
- _initFromApiPrediction.add(this);
86
-
87
- _initFromScratch.add(this);
88
-
89
- this.level = level;
90
-
91
- if (_apiPrediction === undefined) {
92
- _classPrivateMethodGet(this, _initFromScratch, _initFromScratch2).call(this, {
93
- locale: _locale,
94
- totalIncl: _totalIncl,
95
- totalExcl: _totalExcl,
96
- date: _date,
97
- invoiceNumber: _invoiceNumber,
98
- dueDate: _dueDate,
99
- taxes: _taxes,
100
- supplier: _supplier,
101
- paymentDetails: _paymentDetails,
102
- companyNumber: _companyNumber,
103
- vatNumber: _vatNumber,
104
- orientation: _orientation,
105
- pageNumber: _pageNumber,
106
- totalTax: _totalTax,
107
- time: _time
108
- });
109
- } else {
110
- _classPrivateMethodGet(this, _initFromApiPrediction, _initFromApiPrediction2).call(this, _apiPrediction, _inputFile, _pageNumber);
111
- }
112
-
113
- _classPrivateMethodGet(this, _checklist, _checklist2).call(this);
114
- }
115
-
116
- toString() {
117
- return "\n -----Financial document-----\n Filename: ".concat(this.filename, "\n Total amount: ").concat(this.totalIncl.value, "\n Date: ").concat(this.date.value, "\n Supplier: ").concat(this.supplier.value, "\n Total taxes: ").concat(this.totalTax.value, "\n ");
118
- }
119
-
120
- }
121
-
122
- var _initFromScratch2 = function _initFromScratch2(_ref2) {
123
- var {
124
- locale,
125
- totalIncl,
126
- totalExcl,
127
- totalTax,
128
- date,
129
- invoiceNumber,
130
- dueDate,
131
- taxes,
132
- paymentDetails,
133
- companyNumber,
134
- vatNumber,
135
- orientation,
136
- pageNumber,
137
- supplier,
138
- time
139
- } = _ref2;
140
-
141
- var constructPrediction = function constructPrediction(item) {
142
- return {
143
- prediction: {
144
- value: item
145
- },
146
- valueKey: "value",
147
- pageNumber
148
- };
149
- };
150
-
151
- this.locale = new Locale(constructPrediction(locale));
152
- this.totalIncl = new Amount(constructPrediction(totalIncl));
153
- this.totalExcl = new Amount(constructPrediction(totalExcl));
154
- this.totalTax = new Amount(constructPrediction(totalTax));
155
- this.date = new Date(constructPrediction(date));
156
- this.dueDate = new Date(constructPrediction(dueDate));
157
- this.supplier = new Field(constructPrediction(supplier));
158
- this.time = new Field(constructPrediction(time));
159
- this.orientation = new Orientation(constructPrediction(orientation));
160
- this.invoiceNumber = new Field(constructPrediction(invoiceNumber));
161
- this.paymentDetails = new Field(constructPrediction(paymentDetails));
162
- this.companyNumber = new Field(constructPrediction(companyNumber));
163
- this.vatNumber = new Field(constructPrediction(vatNumber));
164
-
165
- if (taxes !== undefined) {
166
- this.taxes = [];
167
-
168
- for (var t of taxes) {
169
- this.taxes.push(new Tax({
170
- prediction: {
171
- value: t[0],
172
- rate: t[1]
173
- },
174
- pageNumber,
175
- valueKey: "value",
176
- rateKey: "rate"
177
- }));
178
- }
179
- }
180
- };
181
-
182
- var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, inputFile, pageNumber) {
183
- if (Object.keys(apiPrediction).includes("invoice_number")) {
184
- var invoice = new Invoice({
185
- apiPrediction,
186
- inputFile,
187
- pageNumber,
188
- level: this.level
189
- });
190
- this.locale = invoice.locale;
191
- this.totalIncl = invoice.totalIncl;
192
- this.totalExcl = invoice.totalExcl;
193
- this.date = invoice.invoiceDate;
194
- this.invoiceNumber = invoice.invoiceNumber;
195
- this.dueDate = invoice.dueDate;
196
- this.taxes = invoice.taxes;
197
- this.supplier = invoice.supplier;
198
- this.paymentDetails = invoice.paymentDetails;
199
- this.companyNumber = invoice.companyNumber;
200
- this.orientation = invoice.orientation;
201
- this.totalTax = invoice.totalTax;
202
- this.time = new Field({
203
- prediction: {
204
- value: undefined,
205
- probability: 0.0
206
- }
207
- });
208
- } else {
209
- var receipt = new Receipt({
210
- apiPrediction,
211
- inputFile,
212
- pageNumber,
213
- level: this.level
214
- });
215
- this.orientation = receipt.orientation;
216
- this.date = receipt.date;
217
- this.dueDate = receipt.date;
218
- this.taxes = receipt.taxes;
219
- this.locale = receipt.locale;
220
- this.totalIncl = receipt.totalIncl;
221
- this.totalExcl = receipt.totalExcl;
222
- this.supplier = receipt.merchantName;
223
- this.time = receipt.time;
224
- this.totalTax = receipt.totalTax;
225
- this.invoiceNumber = new Field({
226
- prediction: {
227
- value: undefined,
228
- probability: 0.0
229
- }
230
- });
231
- this.paymentDetails = new Field({
232
- prediction: {
233
- value: undefined,
234
- probability: 0.0
235
- }
236
- });
237
- this.companyNumber = new Field({
238
- prediction: {
239
- value: undefined,
240
- probability: 0.0
241
- }
242
- });
243
- }
244
- };
245
-
246
- var _checklist2 = function _checklist2() {
247
- this.checklist = {
248
- taxesMatchTotalIncl: _classPrivateMethodGet(this, _taxesMatchTotalIncl, _taxesMatchTotalIncl2).call(this)
249
- };
250
- };
251
-
252
- var _taxesMatchTotalIncl2 = function _taxesMatchTotalIncl2() {
253
- // Check taxes and total include exist
254
- if (this.taxes.length === 0 || this.totalIncl.value === undefined) return false; // Reconstruct totalIncl from taxes
255
-
256
- var totalVat = 0;
257
- var reconstructedTotal = 0;
258
- this.taxes.forEach(tax => {
259
- if (tax.value === undefined || !tax.rate) return false;
260
- totalVat += tax.value;
261
- reconstructedTotal += tax.value + 100 * tax.value / tax.rate;
262
- }); // Sanity check
263
-
264
- if (totalVat <= 0) return false; // Crate epsilon
265
-
266
- var eps = 1 / (100 * totalVat);
267
-
268
- if (this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal && reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02) {
269
- this.taxes = this.taxes.map(tax => _objectSpread(_objectSpread({}, tax), {}, {
270
- probability: 1.0
271
- }));
272
- this.totalTax.probability = 1.0;
273
- this.totalIncl.probability = 1.0;
274
- return true;
275
- }
276
-
277
- return false;
278
- };
279
-
280
- module.exports = FinancialDocument;
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- exports.fields = require("./fields");
4
- exports.document = require("./document");
5
- exports.receipt = require("./receipt");
6
- exports.invoice = require("./invoice");
7
- exports.financialDocument = require("./financialDocument");