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,451 +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 Field = require("./fields").field;
14
-
15
- var Date = require("./fields").date;
16
-
17
- var Amount = require("./fields").amount;
18
-
19
- var Locale = require("./fields").locale;
20
-
21
- var Orientation = require("./fields").orientation;
22
-
23
- var PaymentDetails = require("./fields").paymentDetails;
24
-
25
- var Tax = require("./fields").tax;
26
-
27
- var _initFromScratch = new WeakSet();
28
-
29
- var _initFromApiPrediction = new WeakSet();
30
-
31
- var _checklist = new WeakSet();
32
-
33
- var _reconstruct = new WeakSet();
34
-
35
- var _taxesMatchTotalIncl = new WeakSet();
36
-
37
- var _taxesMatchTotalExcl = new WeakSet();
38
-
39
- var _taxesPlusTotalExclMatchTotalIncl = new WeakSet();
40
-
41
- var _reconstructTotalTax = new WeakSet();
42
-
43
- var _reconstructTotalTaxFromTotals = new WeakSet();
44
-
45
- var _reconstructTotalExcl = new WeakSet();
46
-
47
- var _reconstructTotalIncl = new WeakSet();
48
-
49
- class Invoice extends Document {
50
- /**
51
- * @param {Object} apiPrediction - Json parsed prediction from HTTP response
52
- * @param {Input} input - Input object
53
- * @param {Object} locale - locale value for creating Invoice object from scratch
54
- * @param {Object} totalIncl - total tax included value for creating Invoice object from scratch
55
- * @param {Object} totalExcl - total tax excluded value for creating Invoice object from scratch
56
- * @param {Object} invoiceDate - invoice date value for creating Invoice object from scratch
57
- * @param {Object} invoiceNumber - invoice number value for creating Invoice object from scratch
58
- * @param {Object} taxes - taxes value for creating Invoice object from scratch
59
- * @param {Object} supplier - supplier value for creating Invoice object from scratch
60
- * @param {Object} paymentDetails - payment details value for creating Invoice object from scratch
61
- * @param {Object} companyNumber - company number value for creating Invoice object from scratch
62
- * @param {Object} vatNumber - vat number value for creating Invoice object from scratch
63
- * @param {Object} orientation - orientation value for creating Invoice object from scratch
64
- * @param {Object} totalTax - total tax value for creating Invoice object from scratch
65
- * @param {Number} pageNumber - pageNumber for multi pages pdf input
66
- * @param {String} level - specify whether object is built from "page" level or "document" level prediction
67
- */
68
- constructor(_ref) {
69
- var {
70
- apiPrediction: _apiPrediction = undefined,
71
- inputFile = undefined,
72
- locale: _locale = undefined,
73
- totalIncl: _totalIncl = undefined,
74
- totalExcl: _totalExcl = undefined,
75
- invoiceDate: _invoiceDate = undefined,
76
- invoiceNumber: _invoiceNumber = undefined,
77
- dueDate: _dueDate = undefined,
78
- taxes: _taxes = undefined,
79
- supplier: _supplier = undefined,
80
- paymentDetails: _paymentDetails = undefined,
81
- companyNumber: _companyNumber = undefined,
82
- vatNumber: _vatNumber = undefined,
83
- orientation: _orientation = undefined,
84
- totalTax: _totalTax = undefined,
85
- pageNumber: _pageNumber = 0,
86
- level = "page"
87
- } = _ref;
88
- super(inputFile);
89
-
90
- _reconstructTotalIncl.add(this);
91
-
92
- _reconstructTotalExcl.add(this);
93
-
94
- _reconstructTotalTaxFromTotals.add(this);
95
-
96
- _reconstructTotalTax.add(this);
97
-
98
- _taxesPlusTotalExclMatchTotalIncl.add(this);
99
-
100
- _taxesMatchTotalExcl.add(this);
101
-
102
- _taxesMatchTotalIncl.add(this);
103
-
104
- _reconstruct.add(this);
105
-
106
- _checklist.add(this);
107
-
108
- _initFromApiPrediction.add(this);
109
-
110
- _initFromScratch.add(this);
111
-
112
- this.level = level;
113
-
114
- this.constructPrediction = function (item) {
115
- return {
116
- prediction: {
117
- value: item
118
- },
119
- valueKey: "value",
120
- pageNumber: _pageNumber
121
- };
122
- };
123
-
124
- if (_apiPrediction === undefined) {
125
- _classPrivateMethodGet(this, _initFromScratch, _initFromScratch2).call(this, {
126
- locale: _locale,
127
- totalIncl: _totalIncl,
128
- totalExcl: _totalExcl,
129
- invoiceDate: _invoiceDate,
130
- invoiceNumber: _invoiceNumber,
131
- dueDate: _dueDate,
132
- taxes: _taxes,
133
- supplier: _supplier,
134
- paymentDetails: _paymentDetails,
135
- companyNumber: _companyNumber,
136
- vatNumber: _vatNumber,
137
- orientation: _orientation,
138
- pageNumber: _pageNumber,
139
- totalTax: _totalTax
140
- });
141
- } else {
142
- _classPrivateMethodGet(this, _initFromApiPrediction, _initFromApiPrediction2).call(this, _apiPrediction, _pageNumber);
143
- }
144
-
145
- _classPrivateMethodGet(this, _checklist, _checklist2).call(this);
146
-
147
- _classPrivateMethodGet(this, _reconstruct, _reconstruct2).call(this);
148
- }
149
-
150
- toString() {
151
- return "\n -----Invoice data-----\n Filename: ".concat(this.filename, "\n Invoice number: ").concat(this.invoiceNumber.value, "\n Total amount including taxes: ").concat(this.totalIncl.value, "\n Total amount excluding taxes: ").concat(this.totalExcl.value, "\n Invoice Date: ").concat(this.invoiceDate.value, "\n Supplier name: ").concat(this.supplier.value, "\n Taxes: ").concat(this.taxes.map(tax => tax.toString()).join(" - "), "\n Total taxes: ").concat(this.totalTax.value, "\n ");
152
- }
153
-
154
- }
155
-
156
- var _initFromScratch2 = function _initFromScratch2(_ref2) {
157
- var {
158
- locale,
159
- totalIncl,
160
- totalExcl,
161
- totalTax,
162
- invoiceDate,
163
- invoiceNumber,
164
- dueDate,
165
- taxes,
166
- supplier,
167
- paymentDetails,
168
- companyNumber,
169
- vatNumber,
170
- orientation,
171
- pageNumber
172
- } = _ref2;
173
- this.locale = new Locale(this.constructPrediction(locale));
174
- this.totalIncl = new Amount(this.constructPrediction(totalIncl));
175
- this.totalExcl = new Amount(this.constructPrediction(totalExcl));
176
- this.totalTax = new Amount(this.constructPrediction(totalTax));
177
- this.date = new Date(this.constructPrediction(invoiceDate));
178
- this.invoiceDate = new Date(this.constructPrediction(invoiceDate));
179
- this.dueDate = new Date(this.constructPrediction(dueDate));
180
- this.supplier = new Field(this.constructPrediction(supplier));
181
- this.invoiceNumber = new Field(this.constructPrediction(invoiceNumber));
182
- this.paymentDetails = new Field(this.constructPrediction(paymentDetails));
183
- this.companyNumber = new Field(this.constructPrediction(companyNumber));
184
- this.vatNumber = new Field(this.constructPrediction(vatNumber));
185
-
186
- if (taxes !== undefined) {
187
- this.taxes = [];
188
-
189
- for (var t of taxes) {
190
- this.taxes.push(new Tax({
191
- prediction: {
192
- value: t[0],
193
- rate: t[1]
194
- },
195
- pageNumber,
196
- valueKey: "value",
197
- rateKey: "rate"
198
- }));
199
- }
200
- }
201
-
202
- if (this.level === "page") {
203
- this.orientation = new Orientation(this.constructPrediction(orientation));
204
- }
205
- };
206
-
207
- var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pageNumber) {
208
- this.words = [];
209
- this.locale = new Locale({
210
- prediction: apiPrediction.locale,
211
- pageNumber
212
- });
213
- this.totalIncl = new Amount({
214
- prediction: apiPrediction.total_incl,
215
- valueKey: "value",
216
- pageNumber
217
- });
218
- this.totalTax = new Amount({
219
- prediction: {
220
- value: undefined,
221
- probability: 0.0
222
- },
223
- valueKey: "value",
224
- pageNumber
225
- });
226
- this.totalExcl = new Amount({
227
- prediction: apiPrediction.total_excl,
228
- valueKey: "value",
229
- pageNumber
230
- });
231
- this.date = new Date({
232
- prediction: apiPrediction.date,
233
- valueKey: "value",
234
- pageNumber
235
- });
236
- this.invoiceDate = new Date({
237
- prediction: apiPrediction.date,
238
- valueKey: "value",
239
- pageNumber
240
- });
241
- this.taxes = apiPrediction.taxes.map(function (taxPrediction) {
242
- return new Tax({
243
- prediction: taxPrediction,
244
- pageNumber,
245
- valueKey: "value",
246
- rateKey: "rate",
247
- codeKey: "code"
248
- });
249
- });
250
- this.companyNumber = apiPrediction.company_registration.map(function (companyNumber) {
251
- return new Field({
252
- prediction: companyNumber,
253
- pageNumber,
254
- extraFields: ["type"]
255
- });
256
- });
257
- this.dueDate = new Date({
258
- prediction: apiPrediction.due_date,
259
- valueKey: "value",
260
- pageNumber
261
- });
262
- this.invoiceNumber = new Field({
263
- prediction: apiPrediction.invoice_number,
264
- pageNumber
265
- });
266
- this.supplier = new Field({
267
- prediction: apiPrediction.supplier,
268
- pageNumber
269
- });
270
- this.paymentDetails = apiPrediction.payment_details.map(function (paymentDetail) {
271
- return new PaymentDetails({
272
- prediction: paymentDetail,
273
- pageNumber
274
- });
275
- });
276
-
277
- if (this.level === "page") {
278
- this.orientation = new Orientation({
279
- prediction: apiPrediction.orientation,
280
- pageNumber
281
- });
282
- } else {
283
- this.orientation = new Orientation(this.constructPrediction({
284
- prediction: {
285
- value: undefined,
286
- probability: 0.0,
287
- degrees: undefined
288
- }
289
- }));
290
- } // document.inference.ocr
291
-
292
-
293
- if ("mvision" in apiPrediction) this.words = apiPrediction.mvision;
294
- };
295
-
296
- var _checklist2 = function _checklist2() {
297
- this.checklist = {
298
- taxesMatchTotalIncl: _classPrivateMethodGet(this, _taxesMatchTotalIncl, _taxesMatchTotalIncl2).call(this),
299
- taxesMatchTotalExcl: _classPrivateMethodGet(this, _taxesMatchTotalExcl, _taxesMatchTotalExcl2).call(this),
300
- taxesPlusTotalExclMatchTotalIncl: _classPrivateMethodGet(this, _taxesPlusTotalExclMatchTotalIncl, _taxesPlusTotalExclMatchTotalIncl2).call(this)
301
- };
302
- };
303
-
304
- var _reconstruct2 = function _reconstruct2() {
305
- _classPrivateMethodGet(this, _reconstructTotalTax, _reconstructTotalTax2).call(this);
306
-
307
- _classPrivateMethodGet(this, _reconstructTotalExcl, _reconstructTotalExcl2).call(this);
308
-
309
- _classPrivateMethodGet(this, _reconstructTotalIncl, _reconstructTotalIncl2).call(this);
310
-
311
- _classPrivateMethodGet(this, _reconstructTotalTaxFromTotals, _reconstructTotalTaxFromTotals2).call(this);
312
- };
313
-
314
- var _taxesMatchTotalIncl2 = function _taxesMatchTotalIncl2() {
315
- // Check taxes and total include exist
316
- if (this.taxes.length === 0 || this.totalIncl.value === undefined) return false; // Reconstruct totalIncl from taxes
317
-
318
- var totalVat = 0;
319
- var reconstructedTotal = 0;
320
- this.taxes.forEach(tax => {
321
- if (tax.value === undefined || !tax.rate) return false;
322
- totalVat += tax.value;
323
- reconstructedTotal += tax.value + 100 * tax.value / tax.rate;
324
- }); // Sanity check
325
-
326
- if (totalVat <= 0) return false; // Crate epsilon
327
-
328
- var eps = 1 / (100 * totalVat);
329
-
330
- if (this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal && reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02) {
331
- this.taxes = this.taxes.map(tax => _objectSpread(_objectSpread({}, tax), {}, {
332
- probability: 1.0
333
- }));
334
- this.totalTax.probability = 1.0;
335
- this.totalIncl.probability = 1.0;
336
- return true;
337
- }
338
-
339
- return false;
340
- };
341
-
342
- var _taxesMatchTotalExcl2 = function _taxesMatchTotalExcl2() {
343
- // Check taxes and total amount exist
344
- if (this.taxes.length === 0 || this.totalExcl.value == null) return false; // Reconstruct total_incl from taxes
345
-
346
- var totalVat = 0;
347
- var reconstructedTotal = 0;
348
- this.taxes.forEach(tax => {
349
- if (tax.value == null || !tax.rate) return false;
350
- totalVat += tax.value;
351
- reconstructedTotal += 100 * tax.value / tax.rate;
352
- }); // Sanity check
353
-
354
- if (totalVat <= 0) return false; // Crate epsilon
355
-
356
- var eps = 1 / (100 * totalVat);
357
-
358
- if (this.totalExcl.value * (1 - eps) - 0.02 <= reconstructedTotal && reconstructedTotal <= this.totalExcl.value * (1 + eps) + 0.02) {
359
- this.taxes = this.taxes.map(tax => _objectSpread(_objectSpread({}, tax), {}, {
360
- probability: 1.0
361
- }));
362
- this.totalTax.probability = 1.0;
363
- this.totalExcl.probability = 1.0;
364
- return true;
365
- }
366
-
367
- return false;
368
- };
369
-
370
- var _taxesPlusTotalExclMatchTotalIncl2 = function _taxesPlusTotalExclMatchTotalIncl2() {
371
- if (this.totalExcl.value === undefined || this.taxes.length == 0 || this.totalIncl === undefined) return false;
372
- var totalVat = 0;
373
- this.taxes.forEach(tax => totalVat += tax.value);
374
- var reconstructedTotal = totalVat + this.totalExcl.value;
375
- if (totalVat <= 0) return false;
376
-
377
- if (this.totalIncl.value - 0.01 <= reconstructedTotal && reconstructedTotal <= this.totalIncl.value + 0.01) {
378
- this.taxes = this.taxes.map(tax => _objectSpread(_objectSpread({}, tax), {}, {
379
- probability: 1.0
380
- }));
381
- this.totalTax.probability = 1.0;
382
- this.totalIncl.probability = 1.0;
383
- return true;
384
- }
385
-
386
- return false;
387
- };
388
-
389
- var _reconstructTotalTax2 = function _reconstructTotalTax2() {
390
- if (this.taxes.length > 0) {
391
- var totalTax = {
392
- value: this.taxes.reduce((acc, tax) => {
393
- return tax.value !== undefined ? acc + tax.value : acc;
394
- }, 0),
395
- probability: Field.arrayProbability(this.taxes)
396
- };
397
- if (totalTax.value > 0) this.totalTax = new Amount({
398
- prediction: totalTax,
399
- valueKey: "value",
400
- reconstructed: true
401
- });
402
- }
403
- };
404
-
405
- var _reconstructTotalTaxFromTotals2 = function _reconstructTotalTaxFromTotals2() {
406
- if (this.totalTax.value === undefined && this.totalIncl.value > 0 && this.totalExcl.value > 0 && this.totalExcl.value <= this.totalIncl.value) {
407
- var totalTax = {
408
- value: this.totalIncl.value - this.totalExcl.value,
409
- probability: this.totalIncl.probability * this.totalExcl.probability
410
- };
411
- if (totalTax.value > 0) this.totalTax = new Amount({
412
- prediction: totalTax,
413
- valueKey: "value",
414
- reconstructed: true
415
- });
416
- }
417
- };
418
-
419
- var _reconstructTotalExcl2 = function _reconstructTotalExcl2() {
420
- if (this.taxes.length && this.totalIncl.value != null && this.totalExcl.value === undefined) {
421
- var totalExcl = {
422
- value: this.totalIncl.value - this.taxes.reduce((acc, tax) => {
423
- return tax.value !== undefined ? acc + tax.value : acc;
424
- }, 0),
425
- probability: Field.arrayProbability(this.taxes) * this.totalIncl.probability
426
- };
427
- this.totalExcl = new Amount({
428
- prediction: totalExcl,
429
- valueKey: "value",
430
- reconstructed: true
431
- });
432
- }
433
- };
434
-
435
- var _reconstructTotalIncl2 = function _reconstructTotalIncl2() {
436
- if (this.taxes.length && this.totalExcl.value != null && this.totalIncl.value === undefined) {
437
- var totalIncl = {
438
- value: this.totalExcl.value + this.taxes.reduce((acc, tax) => {
439
- return tax.value ? acc + tax.value : acc;
440
- }, 0.0),
441
- probability: Field.arrayProbability(this.taxes) * this.totalExcl.probability
442
- };
443
- this.totalIncl = new Amount({
444
- prediction: totalIncl,
445
- valueKey: "value",
446
- reconstructed: true
447
- });
448
- }
449
- };
450
-
451
- module.exports = Invoice;