mindee 1.1.2 → 1.3.1

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 (46) hide show
  1. package/CHANGELOG.md +47 -26
  2. package/LICENSE +21 -202
  3. package/README.md +15 -2
  4. package/coverage.lcov +0 -0
  5. package/dist/api/financialDocument.js +51 -0
  6. package/dist/api/index.js +13 -0
  7. package/dist/api/invoice.js +59 -0
  8. package/dist/api/object.js +80 -0
  9. package/dist/api/receipt.js +45 -0
  10. package/dist/api/request.js +90 -0
  11. package/dist/api/response.js +91 -0
  12. package/dist/documents/document.js +80 -0
  13. package/dist/documents/fields/amount.js +21 -0
  14. package/dist/documents/fields/date.js +17 -0
  15. package/dist/documents/fields/field.js +85 -0
  16. package/dist/documents/fields/index.js +17 -0
  17. package/dist/documents/fields/locale.js +25 -0
  18. package/dist/documents/fields/orientation.js +22 -0
  19. package/dist/documents/fields/paymentDetails.js +50 -0
  20. package/dist/documents/fields/tax.js +42 -0
  21. package/dist/documents/financialDocument.js +216 -0
  22. package/dist/documents/index.js +13 -0
  23. package/dist/documents/invoice.js +361 -0
  24. package/dist/documents/receipt.js +231 -0
  25. package/dist/errors/handler.js +17 -0
  26. package/dist/index.js +23 -0
  27. package/dist/inputs.js +208 -0
  28. package/dist/logger.js +34 -0
  29. package/lib/api/financialDocument.js +1 -1
  30. package/lib/api/invoice.js +1 -1
  31. package/lib/api/response.js +1 -1
  32. package/lib/documents/fields/field.js +4 -2
  33. package/lib/documents/financialDocument.js +8 -51
  34. package/lib/documents/invoice.js +9 -48
  35. package/lib/documents/receipt.js +5 -5
  36. package/lib/index.js +29 -30
  37. package/lib/inputs.js +2 -0
  38. package/mindee/api/financialDocument.js +3 -3
  39. package/mindee/api/object.js +1 -1
  40. package/mindee/api/request.js +17 -15
  41. package/mindee/api/response.js +19 -3
  42. package/mindee/documents/financialDocument.js +7 -2
  43. package/mindee/documents/invoice.js +4 -5
  44. package/mindee/documents/receipt.js +4 -4
  45. package/mindee/inputs.js +14 -8
  46. package/package.json +5 -5
@@ -50,6 +50,7 @@ class Invoice extends Document {
50
50
  customerName = undefined,
51
51
  customerAddress = undefined,
52
52
  customerCompanyRegistration = undefined,
53
+ words = undefined,
53
54
  pageNumber = 0,
54
55
  level = "page",
55
56
  }) {
@@ -80,7 +81,7 @@ class Invoice extends Document {
80
81
  customerCompanyRegistration,
81
82
  });
82
83
  } else {
83
- this.#initFromApiPrediction(apiPrediction, pageNumber);
84
+ this.#initFromApiPrediction(apiPrediction, pageNumber, words);
84
85
  }
85
86
  this.#checklist();
86
87
  this.#reconstruct();
@@ -142,8 +143,7 @@ class Invoice extends Document {
142
143
  }
143
144
  }
144
145
 
145
- #initFromApiPrediction(apiPrediction, pageNumber) {
146
- this.words = [];
146
+ #initFromApiPrediction(apiPrediction, pageNumber, words) {
147
147
  this.locale = new Locale({ prediction: apiPrediction.locale, pageNumber });
148
148
  this.totalIncl = new Amount({
149
149
  prediction: apiPrediction.total_incl,
@@ -243,8 +243,7 @@ class Invoice extends Document {
243
243
  })
244
244
  );
245
245
  }
246
- // document.inference.ocr
247
- if ("mvision" in apiPrediction) this.words = apiPrediction.mvision;
246
+ if (words && words.length > 0) this.words = words;
248
247
  }
249
248
 
250
249
  toString() {
@@ -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,
@@ -171,7 +171,7 @@ class Receipt extends Document {
171
171
  })
172
172
  );
173
173
  }
174
- if ("mvision" in apiPrediction) this.words = apiPrediction.mvision;
174
+ if (words && words.length > 0) this.words = words;
175
175
  }
176
176
 
177
177
  toString() {
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.allowCutPdf == true) {
58
- const typeOfFile = await fileType.fromBuffer(
56
+ if (this.filename === undefined) {
57
+ const mimeType = await fileType.fromBuffer(
59
58
  Buffer.from(this.fileObject, "base64")
60
59
  );
61
-
62
- if (typeOfFile === undefined) {
63
- console.error(`Cannot detect mime type of: ${this.fileObject}`);
64
- } else if (typeOfFile.mime === "application/pdf") {
65
- await this.cutPdf();
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
 
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "mindee",
3
- "version": "1.1.2",
4
- "description": "Mindee API SDK for Node.js",
3
+ "version": "1.3.1",
4
+ "description": "Mindee Client Library for Node.js",
5
5
  "main": "mindee/index.js",
6
- "license": "Apache-2.0",
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.1",
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.13.0"
42
+ "pdf-lib": "^1.17.1"
43
43
  },
44
44
  "keywords": [
45
45
  "javascript",