mindee 1.3.3 → 1.4.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 (85) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/mindee/errors/handler.js +1 -1
  3. package/mindee/index.js +5 -2
  4. package/mindee/inputs.js +45 -22
  5. package/mindee/logger.js +8 -7
  6. package/package.json +13 -4
  7. package/.eslintrc +0 -24
  8. package/.mocharc.yaml +0 -2
  9. package/.nyc_output/f57ba3bc-1777-4ecc-81e1-230327c2a401.json +0 -1
  10. package/.nyc_output/processinfo/f57ba3bc-1777-4ecc-81e1-230327c2a401.json +0 -1
  11. package/.nyc_output/processinfo/index.json +0 -1
  12. package/.prettierrc +0 -4
  13. package/.tool-versions +0 -1
  14. package/CODE_OF_CONDUCT.md +0 -63
  15. package/CONTRIBUTING.md +0 -84
  16. package/ISSUE_TEMPLATE.md +0 -45
  17. package/PULL_REQUEST_TEMPLATE.md +0 -45
  18. package/babel.config.json +0 -10
  19. package/coverage/coverage.json +0 -1
  20. package/coverage/lcov-report/base.css +0 -224
  21. package/coverage/lcov-report/block-navigation.js +0 -79
  22. package/coverage/lcov-report/favicon.png +0 -0
  23. package/coverage/lcov-report/index.html +0 -171
  24. package/coverage/lcov-report/prettify.css +0 -1
  25. package/coverage/lcov-report/prettify.js +0 -2
  26. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  27. package/coverage/lcov-report/sorter.js +0 -170
  28. package/coverage/lcov.info +0 -1595
  29. package/coverage.lcov +0 -1595
  30. package/dist/api/financialDocument.js +0 -51
  31. package/dist/api/index.js +0 -13
  32. package/dist/api/invoice.js +0 -59
  33. package/dist/api/object.js +0 -80
  34. package/dist/api/receipt.js +0 -45
  35. package/dist/api/request.js +0 -90
  36. package/dist/api/response.js +0 -91
  37. package/dist/documents/document.js +0 -80
  38. package/dist/documents/fields/amount.js +0 -21
  39. package/dist/documents/fields/date.js +0 -17
  40. package/dist/documents/fields/field.js +0 -85
  41. package/dist/documents/fields/index.js +0 -17
  42. package/dist/documents/fields/locale.js +0 -25
  43. package/dist/documents/fields/orientation.js +0 -22
  44. package/dist/documents/fields/paymentDetails.js +0 -50
  45. package/dist/documents/fields/tax.js +0 -42
  46. package/dist/documents/financialDocument.js +0 -216
  47. package/dist/documents/index.js +0 -13
  48. package/dist/documents/invoice.js +0 -361
  49. package/dist/documents/receipt.js +0 -231
  50. package/dist/errors/handler.js +0 -17
  51. package/dist/index.js +0 -23
  52. package/dist/inputs.js +0 -208
  53. package/dist/logger.js +0 -34
  54. package/examples/.env.example +0 -2
  55. package/examples/documents/invoices/credit_note.pdf +0 -900
  56. package/examples/documents/invoices/invoice.pdf +0 -0
  57. package/examples/documents/invoices/invoice_6p.pdf +0 -0
  58. package/examples/documents/receipts/receipt.jpg +0 -0
  59. package/examples/financialDocument.js +0 -32
  60. package/examples/invoice.js +0 -74
  61. package/examples/receipt.js +0 -45
  62. package/lib/api/financialDocument.js +0 -59
  63. package/lib/api/index.js +0 -7
  64. package/lib/api/invoice.js +0 -73
  65. package/lib/api/object.js +0 -90
  66. package/lib/api/receipt.js +0 -58
  67. package/lib/api/request.js +0 -84
  68. package/lib/api/response.js +0 -92
  69. package/lib/documents/document.js +0 -97
  70. package/lib/documents/fields/amount.js +0 -35
  71. package/lib/documents/fields/date.js +0 -36
  72. package/lib/documents/fields/field.js +0 -102
  73. package/lib/documents/fields/index.js +0 -9
  74. package/lib/documents/fields/locale.js +0 -35
  75. package/lib/documents/fields/orientation.js +0 -33
  76. package/lib/documents/fields/paymentDetails.js +0 -71
  77. package/lib/documents/fields/tax.js +0 -57
  78. package/lib/documents/financialDocument.js +0 -280
  79. package/lib/documents/index.js +0 -7
  80. package/lib/documents/invoice.js +0 -451
  81. package/lib/documents/receipt.js +0 -332
  82. package/lib/errors/handler.js +0 -19
  83. package/lib/index.js +0 -40
  84. package/lib/inputs.js +0 -190
  85. package/lib/logger.js +0 -52
@@ -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");