mindee 1.0.8 → 1.1.2

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.
@@ -45,14 +45,19 @@ class FinancialDocument extends Document {
45
45
  * @param {Object} Date - date value for creating FinancialDocument object from scratch
46
46
  * @param {Object} InvoiceNumber - Invoice number value for creating FinancialDocument object from scratch
47
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
48
+ * @param {Object} supplier - supplier value for creating FinancialDocument object from scratch
49
+ * @param {Object} supplierAddress - supplier address value for creating FinancialDocument object from scratch
49
50
  * @param {Object} paymentDetails - payment details value for creating FinancialDocument object from scratch
50
51
  * @param {Object} companyNumber - company number value for creating FinancialDocument object from scratch
51
52
  * @param {Object} vatNumber - vat number value for creating FinancialDocument object from scratch
52
53
  * @param {Object} orientation - orientation value for creating FinancialDocument object from scratch
53
54
  * @param {Object} totalTax - total tax value for creating FinancialDocument object from scratch
54
55
  * @param {Object} time - time value for creating FinancialDocument object from scratch
56
+ * @param {Object} customerName - customer name value for creating FinancialDocument object from scratch
57
+ * @param {Object} customerAddress - customer address value for creating FinancialDocument object from scratch
58
+ * @param {Object} customerCompanyRegistration - customer company registration value for creating FinancialDocument object from scratch
55
59
  * @param {Object} pageNumber - pageNumber for multi pages pdf input
60
+ * @param {String} level - specify whether object is built from "page" level or "document" level prediction
56
61
  */
57
62
  constructor(_ref) {
58
63
  var {
@@ -65,14 +70,19 @@ class FinancialDocument extends Document {
65
70
  invoiceNumber: _invoiceNumber = undefined,
66
71
  dueDate: _dueDate = undefined,
67
72
  taxes: _taxes = undefined,
68
- merchantName: _merchantName = undefined,
73
+ supplier: _supplier = undefined,
74
+ supplierAddress: _supplierAddress = undefined,
69
75
  paymentDetails: _paymentDetails = undefined,
70
76
  companyNumber: _companyNumber = undefined,
71
77
  vatNumber: _vatNumber = undefined,
72
78
  orientation: _orientation = undefined,
73
79
  totalTax: _totalTax = undefined,
74
80
  time: _time = undefined,
75
- pageNumber: _pageNumber = 0
81
+ customerName: _customerName = undefined,
82
+ customerAddress: _customerAddress = undefined,
83
+ customerCompanyRegistration: _customerCompanyRegistration = undefined,
84
+ pageNumber: _pageNumber = 0,
85
+ level = "page"
76
86
  } = _ref;
77
87
  super(_inputFile);
78
88
 
@@ -84,6 +94,8 @@ class FinancialDocument extends Document {
84
94
 
85
95
  _initFromScratch.add(this);
86
96
 
97
+ this.level = level;
98
+
87
99
  if (_apiPrediction === undefined) {
88
100
  _classPrivateMethodGet(this, _initFromScratch, _initFromScratch2).call(this, {
89
101
  locale: _locale,
@@ -93,14 +105,18 @@ class FinancialDocument extends Document {
93
105
  invoiceNumber: _invoiceNumber,
94
106
  dueDate: _dueDate,
95
107
  taxes: _taxes,
96
- merchantName: _merchantName,
108
+ supplier: _supplier,
109
+ supplierAddress: _supplierAddress,
97
110
  paymentDetails: _paymentDetails,
98
111
  companyNumber: _companyNumber,
99
112
  vatNumber: _vatNumber,
100
113
  orientation: _orientation,
101
114
  pageNumber: _pageNumber,
102
115
  totalTax: _totalTax,
103
- time: _time
116
+ time: _time,
117
+ customerName: _customerName,
118
+ customerAddress: _customerAddress,
119
+ customerCompanyRegistration: _customerCompanyRegistration
104
120
  });
105
121
  } else {
106
122
  _classPrivateMethodGet(this, _initFromApiPrediction, _initFromApiPrediction2).call(this, _apiPrediction, _inputFile, _pageNumber);
@@ -110,7 +126,7 @@ class FinancialDocument extends Document {
110
126
  }
111
127
 
112
128
  toString() {
113
- return "\n -----Financial document-----\n Filename: ".concat(this.filename, "\n Total amount: ").concat(this.totalIncl.value, "\n Date: ").concat(this.date.value, "\n Merchant name: ").concat(this.merchantName.value, "\n Total taxes: ").concat(this.totalTax.value, "\n ");
129
+ 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 ");
114
130
  }
115
131
 
116
132
  }
@@ -130,8 +146,12 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
130
146
  vatNumber,
131
147
  orientation,
132
148
  pageNumber,
133
- merchantName,
134
- time
149
+ supplier,
150
+ supplierAddress,
151
+ time,
152
+ customerName,
153
+ customerAddress,
154
+ customerCompanyRegistration
135
155
  } = _ref2;
136
156
 
137
157
  var constructPrediction = function constructPrediction(item) {
@@ -150,13 +170,17 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
150
170
  this.totalTax = new Amount(constructPrediction(totalTax));
151
171
  this.date = new Date(constructPrediction(date));
152
172
  this.dueDate = new Date(constructPrediction(dueDate));
153
- this.merchantName = new Field(constructPrediction(merchantName));
173
+ this.supplier = new Field(constructPrediction(supplier));
174
+ this.supplierAddress = new Field(this.constructPrediction(supplierAddress));
154
175
  this.time = new Field(constructPrediction(time));
155
176
  this.orientation = new Orientation(constructPrediction(orientation));
156
177
  this.invoiceNumber = new Field(constructPrediction(invoiceNumber));
157
178
  this.paymentDetails = new Field(constructPrediction(paymentDetails));
158
179
  this.companyNumber = new Field(constructPrediction(companyNumber));
159
180
  this.vatNumber = new Field(constructPrediction(vatNumber));
181
+ this.customerName = new Field(this.constructPrediction(customerName));
182
+ this.customerAddress = new Field(this.constructPrediction(customerAddress));
183
+ this.customerCompanyRegistration = new Field(this.constructPrediction(customerCompanyRegistration));
160
184
 
161
185
  if (taxes !== undefined) {
162
186
  this.taxes = [];
@@ -180,58 +204,85 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, in
180
204
  var invoice = new Invoice({
181
205
  apiPrediction,
182
206
  inputFile,
183
- pageNumber
207
+ pageNumber,
208
+ level: this.level
184
209
  });
185
- Object.assign(this, invoice);
210
+ this.locale = invoice.locale;
211
+ this.totalIncl = invoice.totalIncl;
212
+ this.totalExcl = invoice.totalExcl;
213
+ this.date = invoice.invoiceDate;
214
+ this.invoiceNumber = invoice.invoiceNumber;
215
+ this.dueDate = invoice.dueDate;
216
+ this.taxes = invoice.taxes;
217
+ this.supplier = invoice.supplier;
218
+ this.supplierAddress = invoice.supplierAddress;
219
+ this.paymentDetails = invoice.paymentDetails;
220
+ this.companyNumber = invoice.companyNumber;
221
+ this.orientation = invoice.orientation;
222
+ this.totalTax = invoice.totalTax;
186
223
  this.time = new Field({
187
224
  prediction: {
188
225
  value: undefined,
189
- probability: 0.0
190
- }
191
- });
192
- this.merchantName = new Field({
193
- prediction: {
194
- value: undefined,
195
- probability: 0.0
226
+ confidence: 0.0
196
227
  }
197
228
  });
229
+ this.customerName = invoice.customerName;
230
+ this.customerAddress = invoice.customerAddress;
231
+ this.customerCompanyRegistration = invoice.customerCompanyRegistration;
198
232
  } else {
199
233
  var receipt = new Receipt({
200
234
  apiPrediction,
201
235
  inputFile,
202
- pageNumber
236
+ pageNumber,
237
+ level: this.level
203
238
  });
204
- Object.assign(this, receipt);
205
- this.invoiceDate = new Field({
239
+ this.orientation = receipt.orientation;
240
+ this.date = receipt.date;
241
+ this.dueDate = receipt.date;
242
+ this.taxes = receipt.taxes;
243
+ this.locale = receipt.locale;
244
+ this.totalIncl = receipt.totalIncl;
245
+ this.totalExcl = receipt.totalExcl;
246
+ this.supplier = receipt.merchantName;
247
+ this.supplierAddress = new Field({
206
248
  prediction: {
207
249
  value: undefined,
208
- probability: 0.0
250
+ confidence: 0.0
209
251
  }
210
252
  });
253
+ this.time = receipt.time;
254
+ this.totalTax = receipt.totalTax;
211
255
  this.invoiceNumber = new Field({
212
256
  prediction: {
213
257
  value: undefined,
214
- probability: 0.0
258
+ confidence: 0.0
215
259
  }
216
260
  });
217
- this.dueDate = new Field({
261
+ this.paymentDetails = new Field({
218
262
  prediction: {
219
263
  value: undefined,
220
- probability: 0.0
264
+ confidence: 0.0
221
265
  }
222
266
  });
223
- this.paymentDetails = new Field({
267
+ this.companyNumber = new Field({
224
268
  prediction: {
225
269
  value: undefined,
226
- probability: 0.0
270
+ confidence: 0.0
227
271
  }
228
272
  });
229
- this.companyNumber = new Field({
273
+ this.customerName = new Field({
274
+ prediction: {
275
+ value: undefined,
276
+ confidence: 0.0
277
+ }
278
+ });
279
+ this.customerAddress = new Field({
230
280
  prediction: {
231
281
  value: undefined,
232
- probability: 0.0
282
+ confidence: 0.0
233
283
  }
234
284
  });
285
+ this.customerCompanyRegistration = [];
235
286
  }
236
287
  };
237
288
 
@@ -259,7 +310,7 @@ var _taxesMatchTotalIncl2 = function _taxesMatchTotalIncl2() {
259
310
 
260
311
  if (this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal && reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02) {
261
312
  this.taxes = this.taxes.map(tax => _objectSpread(_objectSpread({}, tax), {}, {
262
- probability: 1.0
313
+ confidence: 1.0
263
314
  }));
264
315
  this.totalTax.probability = 1.0;
265
316
  this.totalIncl.probability = 1.0;
@@ -50,7 +50,6 @@ class Invoice extends Document {
50
50
  /**
51
51
  * @param {Object} apiPrediction - Json parsed prediction from HTTP response
52
52
  * @param {Input} input - Input object
53
- * @param {Integer} pageNumber - Page number for multi pages pdf input
54
53
  * @param {Object} locale - locale value for creating Invoice object from scratch
55
54
  * @param {Object} totalIncl - total tax included value for creating Invoice object from scratch
56
55
  * @param {Object} totalExcl - total tax excluded value for creating Invoice object from scratch
@@ -58,12 +57,17 @@ class Invoice extends Document {
58
57
  * @param {Object} invoiceNumber - invoice number value for creating Invoice object from scratch
59
58
  * @param {Object} taxes - taxes value for creating Invoice object from scratch
60
59
  * @param {Object} supplier - supplier value for creating Invoice object from scratch
60
+ * @param {Object} supplierAddress - supplier address value for creating Invoice object from scratch
61
61
  * @param {Object} paymentDetails - payment details value for creating Invoice object from scratch
62
62
  * @param {Object} companyNumber - company number value for creating Invoice object from scratch
63
63
  * @param {Object} vatNumber - vat number value for creating Invoice object from scratch
64
64
  * @param {Object} orientation - orientation value for creating Invoice object from scratch
65
65
  * @param {Object} totalTax - total tax value for creating Invoice object from scratch
66
- * @param {Object} pageNumber - pageNumber for multi pages pdf input
66
+ * @param {Object} customerName - customer name value for creating Invoice object from scratch
67
+ * @param {Object} customerAddress - customer address value for creating Invoice object from scratch
68
+ * @param {Object} customerCompanyRegistration - customer company registration value for creating Invoice object from scratch
69
+ * @param {Number} pageNumber - pageNumber for multi pages pdf input
70
+ * @param {String} level - specify whether object is built from "page" level or "document" level prediction
67
71
  */
68
72
  constructor(_ref) {
69
73
  var {
@@ -77,12 +81,17 @@ class Invoice extends Document {
77
81
  dueDate: _dueDate = undefined,
78
82
  taxes: _taxes = undefined,
79
83
  supplier: _supplier = undefined,
84
+ supplierAddress: _supplierAddress = undefined,
80
85
  paymentDetails: _paymentDetails = undefined,
81
86
  companyNumber: _companyNumber = undefined,
82
87
  vatNumber: _vatNumber = undefined,
83
88
  orientation: _orientation = undefined,
84
89
  totalTax: _totalTax = undefined,
85
- pageNumber: _pageNumber = 0
90
+ customerName: _customerName = undefined,
91
+ customerAddress: _customerAddress = undefined,
92
+ customerCompanyRegistration: _customerCompanyRegistration = undefined,
93
+ pageNumber: _pageNumber = 0,
94
+ level = "page"
86
95
  } = _ref;
87
96
  super(inputFile);
88
97
 
@@ -108,6 +117,18 @@ class Invoice extends Document {
108
117
 
109
118
  _initFromScratch.add(this);
110
119
 
120
+ this.level = level;
121
+
122
+ this.constructPrediction = function (item) {
123
+ return {
124
+ prediction: {
125
+ value: item
126
+ },
127
+ valueKey: "value",
128
+ pageNumber: _pageNumber
129
+ };
130
+ };
131
+
111
132
  if (_apiPrediction === undefined) {
112
133
  _classPrivateMethodGet(this, _initFromScratch, _initFromScratch2).call(this, {
113
134
  locale: _locale,
@@ -118,12 +139,16 @@ class Invoice extends Document {
118
139
  dueDate: _dueDate,
119
140
  taxes: _taxes,
120
141
  supplier: _supplier,
142
+ supplierAddress: _supplierAddress,
121
143
  paymentDetails: _paymentDetails,
122
144
  companyNumber: _companyNumber,
123
145
  vatNumber: _vatNumber,
124
146
  orientation: _orientation,
125
147
  pageNumber: _pageNumber,
126
- totalTax: _totalTax
148
+ totalTax: _totalTax,
149
+ customerName: _customerName,
150
+ customerAddress: _customerAddress,
151
+ customerCompanyRegistration: _customerCompanyRegistration
127
152
  });
128
153
  } else {
129
154
  _classPrivateMethodGet(this, _initFromApiPrediction, _initFromApiPrediction2).call(this, _apiPrediction, _pageNumber);
@@ -135,7 +160,7 @@ class Invoice extends Document {
135
160
  }
136
161
 
137
162
  toString() {
138
- 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 ");
163
+ 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 Supplier address: ").concat(this.supplierAddress.value, "\n Customer name: ").concat(this.customerName.value, "\n Customer address: ").concat(this.customerAddress.value, "\n Taxes: ").concat(this.taxes.map(tax => tax.toString()).join(" - "), "\n Total taxes: ").concat(this.totalTax.value, "\n ");
139
164
  }
140
165
 
141
166
  }
@@ -151,36 +176,32 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
151
176
  dueDate,
152
177
  taxes,
153
178
  supplier,
179
+ supplierAddress,
154
180
  paymentDetails,
155
181
  companyNumber,
156
182
  vatNumber,
157
183
  orientation,
158
- pageNumber
184
+ pageNumber,
185
+ customerName,
186
+ customerAddress,
187
+ customerCompanyRegistration
159
188
  } = _ref2;
160
-
161
- var constructPrediction = function constructPrediction(item) {
162
- return {
163
- prediction: {
164
- value: item
165
- },
166
- valueKey: "value",
167
- pageNumber
168
- };
169
- };
170
-
171
- this.locale = new Locale(constructPrediction(locale));
172
- this.totalIncl = new Amount(constructPrediction(totalIncl));
173
- this.totalExcl = new Amount(constructPrediction(totalExcl));
174
- this.totalTax = new Amount(constructPrediction(totalTax));
175
- this.date = new Date(constructPrediction(invoiceDate));
176
- this.invoiceDate = new Date(constructPrediction(invoiceDate));
177
- this.dueDate = new Date(constructPrediction(dueDate));
178
- this.supplier = new Field(constructPrediction(supplier));
179
- this.orientation = new Orientation(constructPrediction(orientation));
180
- this.invoiceNumber = new Field(constructPrediction(invoiceNumber));
181
- this.paymentDetails = new Field(constructPrediction(paymentDetails));
182
- this.companyNumber = new Field(constructPrediction(companyNumber));
183
- this.vatNumber = new Field(constructPrediction(vatNumber));
189
+ this.locale = new Locale(this.constructPrediction(locale));
190
+ this.totalIncl = new Amount(this.constructPrediction(totalIncl));
191
+ this.totalExcl = new Amount(this.constructPrediction(totalExcl));
192
+ this.totalTax = new Amount(this.constructPrediction(totalTax));
193
+ this.date = new Date(this.constructPrediction(invoiceDate));
194
+ this.invoiceDate = new Date(this.constructPrediction(invoiceDate));
195
+ this.dueDate = new Date(this.constructPrediction(dueDate));
196
+ this.supplier = new Field(this.constructPrediction(supplier));
197
+ this.supplierAddress = new Field(this.constructPrediction(supplierAddress));
198
+ this.invoiceNumber = new Field(this.constructPrediction(invoiceNumber));
199
+ this.paymentDetails = new Field(this.constructPrediction(paymentDetails));
200
+ this.companyNumber = new Field(this.constructPrediction(companyNumber));
201
+ this.vatNumber = new Field(this.constructPrediction(vatNumber));
202
+ this.customerName = new Field(this.constructPrediction(customerName));
203
+ this.customerAddress = new Field(this.constructPrediction(customerAddress));
204
+ this.customerCompanyRegistration = new Field(this.constructPrediction(customerCompanyRegistration));
184
205
 
185
206
  if (taxes !== undefined) {
186
207
  this.taxes = [];
@@ -197,6 +218,10 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
197
218
  }));
198
219
  }
199
220
  }
221
+
222
+ if (this.level === "page") {
223
+ this.orientation = new Orientation(this.constructPrediction(orientation));
224
+ }
200
225
  };
201
226
 
202
227
  var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pageNumber) {
@@ -213,7 +238,7 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
213
238
  this.totalTax = new Amount({
214
239
  prediction: {
215
240
  value: undefined,
216
- probability: 0.0
241
+ confidence: 0.0
217
242
  },
218
243
  valueKey: "value",
219
244
  pageNumber
@@ -242,10 +267,6 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
242
267
  codeKey: "code"
243
268
  });
244
269
  });
245
- this.orientation = new Orientation({
246
- prediction: apiPrediction.orientation,
247
- pageNumber
248
- });
249
270
  this.companyNumber = apiPrediction.company_registration.map(function (companyNumber) {
250
271
  return new Field({
251
272
  prediction: companyNumber,
@@ -266,12 +287,48 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
266
287
  prediction: apiPrediction.supplier,
267
288
  pageNumber
268
289
  });
290
+ this.supplierAddress = new Field({
291
+ prediction: apiPrediction.supplier_address,
292
+ pageNumber
293
+ });
294
+ this.customerName = new Field({
295
+ prediction: apiPrediction.customer,
296
+ pageNumber
297
+ });
298
+ this.customerAddress = new Field({
299
+ prediction: apiPrediction.customer_address,
300
+ pageNumber
301
+ });
302
+ this.customerCompanyRegistration = apiPrediction.customer_company_registration.map(function (customerCompanyRegistration) {
303
+ return new Field({
304
+ prediction: customerCompanyRegistration,
305
+ pageNumber,
306
+ extraFields: ["type"]
307
+ });
308
+ });
269
309
  this.paymentDetails = apiPrediction.payment_details.map(function (paymentDetail) {
270
310
  return new PaymentDetails({
271
311
  prediction: paymentDetail,
272
312
  pageNumber
273
313
  });
274
314
  });
315
+
316
+ if (this.level === "page") {
317
+ this.orientation = new Orientation({
318
+ prediction: apiPrediction.orientation,
319
+ pageNumber
320
+ });
321
+ } else {
322
+ this.orientation = new Orientation(this.constructPrediction({
323
+ prediction: {
324
+ value: undefined,
325
+ confidence: 0.0,
326
+ degrees: undefined
327
+ }
328
+ }));
329
+ } // document.inference.ocr
330
+
331
+
275
332
  if ("mvision" in apiPrediction) this.words = apiPrediction.mvision;
276
333
  };
277
334
 
@@ -374,7 +431,7 @@ var _reconstructTotalTax2 = function _reconstructTotalTax2() {
374
431
  value: this.taxes.reduce((acc, tax) => {
375
432
  return tax.value !== undefined ? acc + tax.value : acc;
376
433
  }, 0),
377
- probability: Field.arrayProbability(this.taxes)
434
+ confidence: Field.arrayProbability(this.taxes)
378
435
  };
379
436
  if (totalTax.value > 0) this.totalTax = new Amount({
380
437
  prediction: totalTax,
@@ -388,7 +445,7 @@ var _reconstructTotalTaxFromTotals2 = function _reconstructTotalTaxFromTotals2()
388
445
  if (this.totalTax.value === undefined && this.totalIncl.value > 0 && this.totalExcl.value > 0 && this.totalExcl.value <= this.totalIncl.value) {
389
446
  var totalTax = {
390
447
  value: this.totalIncl.value - this.totalExcl.value,
391
- probability: this.totalIncl.probability * this.totalExcl.probability
448
+ confidence: this.totalIncl.probability * this.totalExcl.probability
392
449
  };
393
450
  if (totalTax.value > 0) this.totalTax = new Amount({
394
451
  prediction: totalTax,
@@ -404,7 +461,7 @@ var _reconstructTotalExcl2 = function _reconstructTotalExcl2() {
404
461
  value: this.totalIncl.value - this.taxes.reduce((acc, tax) => {
405
462
  return tax.value !== undefined ? acc + tax.value : acc;
406
463
  }, 0),
407
- probability: Field.arrayProbability(this.taxes) * this.totalIncl.probability
464
+ confidence: Field.arrayProbability(this.taxes) * this.totalIncl.probability
408
465
  };
409
466
  this.totalExcl = new Amount({
410
467
  prediction: totalExcl,
@@ -420,7 +477,7 @@ var _reconstructTotalIncl2 = function _reconstructTotalIncl2() {
420
477
  value: this.totalExcl.value + this.taxes.reduce((acc, tax) => {
421
478
  return tax.value ? acc + tax.value : acc;
422
479
  }, 0.0),
423
- probability: Field.arrayProbability(this.taxes) * this.totalExcl.probability
480
+ confidence: Field.arrayProbability(this.taxes) * this.totalExcl.probability
424
481
  };
425
482
  this.totalIncl = new Amount({
426
483
  prediction: totalIncl,
@@ -57,6 +57,7 @@ class Receipt extends Document {
57
57
  * @param {Object} orientation - orientation value for creating Receipt object from scratch
58
58
  * @param {Object} totalTax - total taxes value for creating Receipt object from scratch
59
59
  * @param {Object} totalExcl - total taxes excluded value for creating Receipt object from scratch
60
+ * @param {String} level - specify whether object is built from "page" level or "document" level prediction
60
61
  */
61
62
  constructor(_ref) {
62
63
  var {
@@ -72,7 +73,8 @@ class Receipt extends Document {
72
73
  orientation: _orientation = undefined,
73
74
  totalTax: _totalTax = undefined,
74
75
  totalExcl: _totalExcl = undefined,
75
- pageNumber: _pageNumber = 0
76
+ pageNumber: _pageNumber = 0,
77
+ level = "page"
76
78
  } = _ref;
77
79
  super(inputFile);
78
80
 
@@ -90,6 +92,18 @@ class Receipt extends Document {
90
92
 
91
93
  _initFromScratch.add(this);
92
94
 
95
+ this.level = level;
96
+
97
+ this.constructPrediction = function (item) {
98
+ return {
99
+ prediction: {
100
+ value: item
101
+ },
102
+ valueKey: "value",
103
+ pageNumber: _pageNumber
104
+ };
105
+ };
106
+
93
107
  if (_apiPrediction === undefined) {
94
108
  _classPrivateMethodGet(this, _initFromScratch, _initFromScratch2).call(this, {
95
109
  locale: _locale,
@@ -147,23 +161,12 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
147
161
  totalTax,
148
162
  pageNumber
149
163
  } = _ref2;
150
-
151
- var constructPrediction = function constructPrediction(item) {
152
- return {
153
- prediction: {
154
- value: item
155
- },
156
- valueKey: "value",
157
- pageNumber
158
- };
159
- };
160
-
161
- this.locale = new Locale(constructPrediction(locale));
162
- this.totalIncl = new Amount(constructPrediction(totalIncl));
163
- this.date = new Date(constructPrediction(date));
164
- this.category = new Field(constructPrediction(category));
165
- this.merchantName = new Field(constructPrediction(merchantName));
166
- this.time = new Field(constructPrediction(time));
164
+ this.locale = new Locale(this.constructPrediction(locale));
165
+ this.totalIncl = new Amount(this.constructPrediction(totalIncl));
166
+ this.date = new Date(this.constructPrediction(date));
167
+ this.category = new Field(this.constructPrediction(category));
168
+ this.merchantName = new Field(this.constructPrediction(merchantName));
169
+ this.time = new Field(this.constructPrediction(time));
167
170
 
168
171
  if (taxes !== undefined) {
169
172
  this.taxes = [];
@@ -181,9 +184,9 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
181
184
  }
182
185
  }
183
186
 
184
- this.orientation = new Orientation(constructPrediction(orientation));
185
- this.totalTax = new Amount(constructPrediction(totalTax));
186
- this.totalExcl = new Amount(constructPrediction(totalExcl));
187
+ this.orientation = new Orientation(this.constructPrediction(orientation));
188
+ this.totalTax = new Amount(this.constructPrediction(totalTax));
189
+ this.totalExcl = new Amount(this.constructPrediction(totalExcl));
187
190
  };
188
191
 
189
192
  var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pageNumber) {
@@ -223,14 +226,10 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
223
226
  rateKey: "rate",
224
227
  codeKey: "code"
225
228
  }));
226
- this.orientation = new Orientation({
227
- prediction: apiPrediction.orientation,
228
- pageNumber
229
- });
230
229
  this.totalTax = new Amount({
231
230
  prediction: {
232
231
  value: undefined,
233
- probability: 0
232
+ confidence: 0
234
233
  },
235
234
  valueKey: "value",
236
235
  pageNumber
@@ -238,11 +237,27 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
238
237
  this.totalExcl = new Amount({
239
238
  prediction: {
240
239
  value: undefined,
241
- probability: 0
240
+ confidence: 0
242
241
  },
243
242
  valueKey: "value",
244
243
  pageNumber
245
244
  });
245
+
246
+ if (this.level === "page") {
247
+ this.orientation = new Orientation({
248
+ prediction: apiPrediction.orientation,
249
+ pageNumber
250
+ });
251
+ } else {
252
+ this.orientation = new Orientation(this.constructPrediction({
253
+ prediction: {
254
+ value: undefined,
255
+ confidence: 0.0,
256
+ degrees: undefined
257
+ }
258
+ }));
259
+ }
260
+
246
261
  if ("mvision" in apiPrediction) this.words = apiPrediction.mvision;
247
262
  };
248
263
 
@@ -290,7 +305,7 @@ var _reconstructTotalExclFromTCCAndTaxes2 = function _reconstructTotalExclFromTC
290
305
  if (this.taxes.length && this.totalIncl.value != null) {
291
306
  var totalExcl = {
292
307
  value: this.totalIncl.value - Field.arraySum(this.taxes),
293
- probability: Field.arrayProbability(this.taxes) * this.totalIncl.probability
308
+ confidence: Field.arrayProbability(this.taxes) * this.totalIncl.probability
294
309
  };
295
310
  this.totalExcl = new Amount({
296
311
  prediction: totalExcl,
@@ -304,7 +319,7 @@ var _reconstructTotalTax2 = function _reconstructTotalTax2() {
304
319
  if (this.taxes.length && this.totalTax.value == null) {
305
320
  var totalTax = {
306
321
  value: this.taxes.map(tax => tax.value || 0).reduce((a, b) => a + b, 0),
307
- probability: Field.arrayProbability(this.taxes)
322
+ confidence: Field.arrayProbability(this.taxes)
308
323
  };
309
324
  if (totalTax.value > 0) this.totalTax = new Amount({
310
325
  prediction: totalTax,
@@ -30,12 +30,14 @@ class APIFinancialDocument extends APIObject {
30
30
  filename: filename,
31
31
  allowCutPdf: cutPdf,
32
32
  });
33
- this.apiToken =
34
- inputFile.fileExtension === "pdf" ? this.invoiceToken : this.receiptToken;
35
33
  await inputFile.init();
34
+ this.apiToken =
35
+ inputFile.fileExtension === "application/pdf"
36
+ ? this.invoiceToken
37
+ : this.receiptToken;
36
38
  const url =
37
- inputFile.fileExtension === "pdf"
38
- ? "/invoices/v1/predict"
39
+ inputFile.fileExtension === "application/pdf"
40
+ ? "/invoices/v3/predict"
39
41
  : "/expense_receipts/v3/predict";
40
42
  super.parse();
41
43
  return await super._request(url, inputFile, version, includeWords);
@@ -19,7 +19,7 @@ class APIInvoice extends APIObject {
19
19
  input,
20
20
  inputType = "path",
21
21
  filename = undefined,
22
- version = "2",
22
+ version = "3",
23
23
  cutPdf = true,
24
24
  includeWords = false,
25
25
  }) {
@@ -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/products";
13
+ this.baseUrl = "https://api.mindee.net/v1/products/mindee/";
14
14
  this.apiName = apiName;
15
15
  }
16
16
 
@@ -54,7 +54,7 @@ class APIObject {
54
54
  @returns {Response}
55
55
  */
56
56
  wrapResponse(inputFile, response, documentType) {
57
- if (response.statusCode != 200) {
57
+ if (response.statusCode > 201) {
58
58
  const errorMessage = JSON.stringify(response.data, null, 4);
59
59
  errorHandler.throw(
60
60
  new Error(