Comparing version 1.0.9 to 1.1.0
# CHANGELOG | ||
## v1.1.0 (2022-01-03) | ||
### new | ||
- chg: :sparkles: New Mindee API V2 support | ||
- chg: :zap: Server side invoice reconstruction from multi-page pdfs | ||
- new: :sparkles: Added OS in User-Agent headers | ||
## v1.0.9 (2021-12-09) | ||
@@ -4,0 +13,0 @@ |
@@ -47,5 +47,5 @@ "use strict"; | ||
}); | ||
_this.apiToken = inputFile.fileExtension === "pdf" ? _this.invoiceToken : _this.receiptToken; | ||
yield inputFile.init(); | ||
var url = inputFile.fileExtension === "pdf" ? "/invoices/v1/predict" : "/expense_receipts/v3/predict"; | ||
_this.apiToken = inputFile.fileExtension === "application/pdf" ? _this.invoiceToken : _this.receiptToken; | ||
var url = inputFile.fileExtension === "application/pdf" ? "/invoices/v2/predict" : "/expense_receipts/v3/predict"; | ||
@@ -52,0 +52,0 @@ _superprop_getParse().call(_this); |
@@ -24,3 +24,3 @@ "use strict"; | ||
this.apiToken = apiToken; | ||
this.baseUrl = "https://api.mindee.net/products"; | ||
this.baseUrl = "https://api.mindee.net/v1/products/mindee/"; | ||
this.apiName = apiName; | ||
@@ -69,3 +69,3 @@ } | ||
wrapResponse(inputFile, response, documentType) { | ||
if (response.statusCode != 200) { | ||
if (response.statusCode > 201) { | ||
var errorMessage = JSON.stringify(response.data, null, 4); | ||
@@ -72,0 +72,0 @@ errorHandler.throw(new Error("".concat(this.apiName, " API ").concat(response.statusCode, " HTTP error: ").concat(errorMessage)), false); |
@@ -21,2 +21,4 @@ "use strict"; | ||
var os = require("os"); | ||
var request = function request(url, method, headers, input) { | ||
@@ -27,3 +29,3 @@ var includeWords = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; | ||
var body; | ||
headers["User-Agent"] = "mindee-node/".concat(sdkVersion, " node/").concat(process.version); | ||
headers["User-Agent"] = "mindee-api-nodejs@v".concat(sdkVersion, " nodejs-").concat(process.version, " ").concat(os.type().toLowerCase()); | ||
@@ -34,3 +36,3 @@ if (["path", "stream"].includes(input.inputType)) { | ||
}; | ||
form.append("file", input.fileObject, fileParams); | ||
form.append("document", input.fileObject, fileParams); | ||
if (includeWords) form.append("include_mvision", "true"); | ||
@@ -40,3 +42,3 @@ headers = _objectSpread(_objectSpread({}, headers), form.getHeaders()); | ||
var body_obj = { | ||
file: input.fileObject | ||
document: input.fileObject | ||
}; | ||
@@ -67,3 +69,3 @@ if (includeWords) body_obj["include_mvision"] = "true"; | ||
} catch (error) { | ||
console.log(responseBody); | ||
console.log("error"); | ||
} | ||
@@ -70,0 +72,0 @@ }); |
@@ -72,3 +72,3 @@ "use strict"; | ||
}; | ||
var predictions = this.httpResponse.data.predictions.entries(); | ||
var predictions = this.httpResponse.data.document.inference.pages.entries(); | ||
this["".concat(this.documentType, "s")] = []; // Create a list of Document (Receipt, Invoice...) for each page of the input document | ||
@@ -78,3 +78,3 @@ | ||
this["".concat(this.documentType, "s")].push(constructors[this.documentType]({ | ||
apiPrediction: prediction, | ||
apiPrediction: prediction.prediction, | ||
inputFile: this.input, | ||
@@ -86,3 +86,8 @@ pageNumber: pageNumber | ||
this[this.documentType] = Document.mergePages(this["".concat(this.documentType, "s")]); | ||
this[this.documentType] = constructors[this.documentType]({ | ||
apiPrediction: this.httpResponse.data.document.inference.prediction, | ||
inputFile: this.input, | ||
pageNumber: -1, | ||
level: "document" | ||
}); | ||
} | ||
@@ -89,0 +94,0 @@ |
@@ -82,3 +82,7 @@ "use strict"; | ||
if ((document === null || document === void 0 ? void 0 : (_document$attribute = document[attribute]) === null || _document$attribute === void 0 ? void 0 : _document$attribute.probability) > finalDocument[attribute].probability) { | ||
if (Array.isArray(document === null || document === void 0 ? void 0 : document[attribute])) { | ||
var _finalDocument$attrib; | ||
finalDocument[attribute] = (_finalDocument$attrib = finalDocument[attribute]) !== null && _finalDocument$attrib !== void 0 && _finalDocument$attrib.length ? finalDocument[attribute] : document === null || document === void 0 ? void 0 : document[attribute]; | ||
} else if ((document === null || document === void 0 ? void 0 : (_document$attribute = document[attribute]) === null || _document$attribute === void 0 ? void 0 : _document$attribute.probability) > finalDocument[attribute].probability) { | ||
finalDocument[attribute] = document === null || document === void 0 ? void 0 : document[attribute]; | ||
@@ -85,0 +89,0 @@ } |
@@ -25,3 +25,3 @@ "use strict"; | ||
if (valueKey in prediction && prediction[valueKey] !== "N/A") { | ||
if (valueKey in prediction && prediction[valueKey] !== null) { | ||
this.value = prediction[valueKey]; | ||
@@ -28,0 +28,0 @@ if (prediction.probability) this.probability = prediction.probability; |
@@ -56,2 +56,3 @@ "use strict"; | ||
* @param {Object} pageNumber - pageNumber for multi pages pdf input | ||
* @param {String} level - specify whether object is built from "page" level or "document" level prediction | ||
*/ | ||
@@ -69,3 +70,3 @@ constructor(_ref) { | ||
taxes: _taxes = undefined, | ||
merchantName: _merchantName = undefined, | ||
merchantName = undefined, | ||
paymentDetails: _paymentDetails = undefined, | ||
@@ -77,3 +78,4 @@ companyNumber: _companyNumber = undefined, | ||
time: _time = undefined, | ||
pageNumber: _pageNumber = 0 | ||
pageNumber: _pageNumber = 0, | ||
level = "page" | ||
} = _ref; | ||
@@ -90,2 +92,4 @@ super(_inputFile); | ||
this.level = level; | ||
if (_apiPrediction === undefined) { | ||
@@ -100,3 +104,3 @@ _classPrivateMethodGet(this, _initFromScratch, _initFromScratch2).call(this, { | ||
taxes: _taxes, | ||
merchantName: _merchantName, | ||
supplier, | ||
paymentDetails: _paymentDetails, | ||
@@ -118,3 +122,3 @@ companyNumber: _companyNumber, | ||
toString() { | ||
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 "); | ||
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 "); | ||
} | ||
@@ -139,3 +143,3 @@ | ||
pageNumber, | ||
merchantName, | ||
supplier, | ||
time | ||
@@ -160,3 +164,3 @@ } = _ref2; | ||
this.dueDate = new Date(constructPrediction(dueDate)); | ||
this.merchantName = new Field(constructPrediction(merchantName)); | ||
this.supplier = new Field(constructPrediction(supplier)); | ||
this.time = new Field(constructPrediction(time)); | ||
@@ -191,5 +195,17 @@ this.orientation = new Orientation(constructPrediction(orientation)); | ||
inputFile, | ||
pageNumber | ||
pageNumber, | ||
level: this.level | ||
}); | ||
Object.assign(this, invoice); | ||
this.locale = invoice.locale; | ||
this.totalIncl = invoice.totalIncl; | ||
this.totalExcl = invoice.totalExcl; | ||
this.date = invoice.invoiceDate; | ||
this.invoiceNumber = invoice.invoiceNumber; | ||
this.dueDate = invoice.dueDate; | ||
this.taxes = invoice.taxes; | ||
this.supplier = invoice.supplier; | ||
this.paymentDetails = invoice.paymentDetails; | ||
this.companyNumber = invoice.companyNumber; | ||
this.orientation = invoice.orientation; | ||
this.totalTax = invoice.totalTax; | ||
this.time = new Field({ | ||
@@ -201,8 +217,2 @@ prediction: { | ||
}); | ||
this.merchantName = new Field({ | ||
prediction: { | ||
value: undefined, | ||
probability: 0.0 | ||
} | ||
}); | ||
} else { | ||
@@ -212,11 +222,15 @@ var receipt = new Receipt({ | ||
inputFile, | ||
pageNumber | ||
pageNumber, | ||
level: this.level | ||
}); | ||
Object.assign(this, receipt); | ||
this.invoiceDate = new Field({ | ||
prediction: { | ||
value: undefined, | ||
probability: 0.0 | ||
} | ||
}); | ||
this.orientation = receipt.orientation; | ||
this.date = receipt.date; | ||
this.dueDate = receipt.date; | ||
this.taxes = receipt.taxes; | ||
this.locale = receipt.locale; | ||
this.totalIncl = receipt.totalIncl; | ||
this.totalExcl = receipt.totalExcl; | ||
this.supplier = receipt.merchantName; | ||
this.time = receipt.time; | ||
this.totalTax = receipt.totalTax; | ||
this.invoiceNumber = new Field({ | ||
@@ -228,8 +242,2 @@ prediction: { | ||
}); | ||
this.dueDate = new Field({ | ||
prediction: { | ||
value: undefined, | ||
probability: 0.0 | ||
} | ||
}); | ||
this.paymentDetails = new Field({ | ||
@@ -236,0 +244,0 @@ prediction: { |
@@ -53,3 +53,2 @@ "use strict"; | ||
* @param {Input} input - Input object | ||
* @param {Integer} pageNumber - Page number for multi pages pdf input | ||
* @param {Object} locale - locale value for creating Invoice object from scratch | ||
@@ -67,3 +66,4 @@ * @param {Object} totalIncl - total tax included value for creating Invoice object from scratch | ||
* @param {Object} totalTax - total tax value for creating Invoice object from scratch | ||
* @param {Object} pageNumber - pageNumber for multi pages pdf input | ||
* @param {Number} pageNumber - pageNumber for multi pages pdf input | ||
* @param {String} level - specify whether object is built from "page" level or "document" level prediction | ||
*/ | ||
@@ -87,3 +87,4 @@ constructor(_ref) { | ||
totalTax: _totalTax = undefined, | ||
pageNumber: _pageNumber = 0 | ||
pageNumber: _pageNumber = 0, | ||
level = "page" | ||
} = _ref; | ||
@@ -114,2 +115,14 @@ super(inputFile); | ||
this.level = level; | ||
this.constructPrediction = function (item) { | ||
return { | ||
prediction: { | ||
value: item | ||
}, | ||
valueKey: "value", | ||
pageNumber: _pageNumber | ||
}; | ||
}; | ||
if (_apiPrediction === undefined) { | ||
@@ -164,27 +177,15 @@ _classPrivateMethodGet(this, _initFromScratch, _initFromScratch2).call(this, { | ||
} = _ref2; | ||
this.locale = new Locale(this.constructPrediction(locale)); | ||
this.totalIncl = new Amount(this.constructPrediction(totalIncl)); | ||
this.totalExcl = new Amount(this.constructPrediction(totalExcl)); | ||
this.totalTax = new Amount(this.constructPrediction(totalTax)); | ||
this.date = new Date(this.constructPrediction(invoiceDate)); | ||
this.invoiceDate = new Date(this.constructPrediction(invoiceDate)); | ||
this.dueDate = new Date(this.constructPrediction(dueDate)); | ||
this.supplier = new Field(this.constructPrediction(supplier)); | ||
this.invoiceNumber = new Field(this.constructPrediction(invoiceNumber)); | ||
this.paymentDetails = new Field(this.constructPrediction(paymentDetails)); | ||
this.companyNumber = new Field(this.constructPrediction(companyNumber)); | ||
this.vatNumber = new Field(this.constructPrediction(vatNumber)); | ||
var constructPrediction = function constructPrediction(item) { | ||
return { | ||
prediction: { | ||
value: item | ||
}, | ||
valueKey: "value", | ||
pageNumber | ||
}; | ||
}; | ||
this.locale = new Locale(constructPrediction(locale)); | ||
this.totalIncl = new Amount(constructPrediction(totalIncl)); | ||
this.totalExcl = new Amount(constructPrediction(totalExcl)); | ||
this.totalTax = new Amount(constructPrediction(totalTax)); | ||
this.date = new Date(constructPrediction(invoiceDate)); | ||
this.invoiceDate = new Date(constructPrediction(invoiceDate)); | ||
this.dueDate = new Date(constructPrediction(dueDate)); | ||
this.supplier = new Field(constructPrediction(supplier)); | ||
this.orientation = new Orientation(constructPrediction(orientation)); | ||
this.invoiceNumber = new Field(constructPrediction(invoiceNumber)); | ||
this.paymentDetails = new Field(constructPrediction(paymentDetails)); | ||
this.companyNumber = new Field(constructPrediction(companyNumber)); | ||
this.vatNumber = new Field(constructPrediction(vatNumber)); | ||
if (taxes !== undefined) { | ||
@@ -205,2 +206,6 @@ this.taxes = []; | ||
} | ||
if (this.level === "page") { | ||
this.orientation = new Orientation(this.constructPrediction(orientation)); | ||
} | ||
}; | ||
@@ -251,6 +256,2 @@ | ||
}); | ||
this.orientation = new Orientation({ | ||
prediction: apiPrediction.orientation, | ||
pageNumber | ||
}); | ||
this.companyNumber = apiPrediction.company_registration.map(function (companyNumber) { | ||
@@ -282,2 +283,19 @@ return new Field({ | ||
}); | ||
if (this.level === "page") { | ||
this.orientation = new Orientation({ | ||
prediction: apiPrediction.orientation, | ||
pageNumber | ||
}); | ||
} else { | ||
this.orientation = new Orientation(this.constructPrediction({ | ||
prediction: { | ||
value: undefined, | ||
probability: 0.0, | ||
degrees: undefined | ||
} | ||
})); | ||
} // document.inference.ocr | ||
if ("mvision" in apiPrediction) this.words = apiPrediction.mvision; | ||
@@ -284,0 +302,0 @@ }; |
@@ -60,2 +60,3 @@ "use strict"; | ||
* @param {Object} totalExcl - total taxes excluded value for creating Receipt object from scratch | ||
* @param {String} level - specify whether object is built from "page" level or "document" level prediction | ||
*/ | ||
@@ -76,3 +77,4 @@ constructor(_ref) { | ||
totalExcl: _totalExcl = undefined, | ||
pageNumber: _pageNumber = 0 | ||
pageNumber: _pageNumber = 0, | ||
level = "page" | ||
} = _ref; | ||
@@ -95,2 +97,14 @@ super(inputFile); | ||
this.level = level; | ||
this.constructPrediction = function (item) { | ||
return { | ||
prediction: { | ||
value: item | ||
}, | ||
valueKey: "value", | ||
pageNumber: _pageNumber | ||
}; | ||
}; | ||
if (_apiPrediction === undefined) { | ||
@@ -153,20 +167,9 @@ _classPrivateMethodGet(this, _initFromScratch, _initFromScratch2).call(this, { | ||
} = _ref2; | ||
this.locale = new Locale(this.constructPrediction(locale)); | ||
this.totalIncl = new Amount(this.constructPrediction(totalIncl)); | ||
this.date = new Date(this.constructPrediction(date)); | ||
this.category = new Field(this.constructPrediction(category)); | ||
this.merchantName = new Field(this.constructPrediction(merchantName)); | ||
this.time = new Field(this.constructPrediction(time)); | ||
var constructPrediction = function constructPrediction(item) { | ||
return { | ||
prediction: { | ||
value: item | ||
}, | ||
valueKey: "value", | ||
pageNumber | ||
}; | ||
}; | ||
this.locale = new Locale(constructPrediction(locale)); | ||
this.totalIncl = new Amount(constructPrediction(totalIncl)); | ||
this.date = new Date(constructPrediction(date)); | ||
this.category = new Field(constructPrediction(category)); | ||
this.merchantName = new Field(constructPrediction(merchantName)); | ||
this.time = new Field(constructPrediction(time)); | ||
if (taxes !== undefined) { | ||
@@ -188,5 +191,5 @@ this.taxes = []; | ||
this.orientation = new Orientation(constructPrediction(orientation)); | ||
this.totalTax = new Amount(constructPrediction(totalTax)); | ||
this.totalExcl = new Amount(constructPrediction(totalExcl)); | ||
this.orientation = new Orientation(this.constructPrediction(orientation)); | ||
this.totalTax = new Amount(this.constructPrediction(totalTax)); | ||
this.totalExcl = new Amount(this.constructPrediction(totalExcl)); | ||
}; | ||
@@ -231,6 +234,2 @@ | ||
})); | ||
this.orientation = new Orientation({ | ||
prediction: apiPrediction.orientation, | ||
pageNumber | ||
}); | ||
this.totalTax = new Amount({ | ||
@@ -252,2 +251,18 @@ prediction: { | ||
}); | ||
if (this.level === "page") { | ||
this.orientation = new Orientation({ | ||
prediction: apiPrediction.orientation, | ||
pageNumber | ||
}); | ||
} else { | ||
this.orientation = new Orientation(this.constructPrediction({ | ||
prediction: { | ||
value: undefined, | ||
probability: 0.0, | ||
degrees: undefined | ||
} | ||
})); | ||
} | ||
if ("mvision" in apiPrediction) this.words = apiPrediction.mvision; | ||
@@ -254,0 +269,0 @@ }; |
@@ -33,8 +33,10 @@ const APIObject = require("./object"); | ||
}); | ||
await inputFile.init(); | ||
this.apiToken = | ||
inputFile.fileExtension === "pdf" ? this.invoiceToken : this.receiptToken; | ||
await inputFile.init(); | ||
inputFile.fileExtension === "application/pdf" | ||
? this.invoiceToken | ||
: this.receiptToken; | ||
const url = | ||
inputFile.fileExtension === "pdf" | ||
? "/invoices/v1/predict" | ||
inputFile.fileExtension === "application/pdf" | ||
? "/invoices/v2/predict" | ||
: "/expense_receipts/v3/predict"; | ||
@@ -41,0 +43,0 @@ super.parse(); |
@@ -13,3 +13,3 @@ const Response = require("./response"); | ||
this.apiToken = apiToken; | ||
this.baseUrl = "https://api.mindee.net/products"; | ||
this.baseUrl = "https://api.mindee.net/v1/products/mindee/"; | ||
this.apiName = apiName; | ||
@@ -58,3 +58,3 @@ } | ||
wrapResponse(inputFile, response, documentType) { | ||
if (response.statusCode != 200) { | ||
if (response.statusCode > 201) { | ||
const errorMessage = JSON.stringify(response.data, null, 4); | ||
@@ -61,0 +61,0 @@ errorHandler.throw( |
@@ -5,2 +5,3 @@ const https = require("https"); | ||
const FormData = require("form-data"); | ||
const os = require("os"); | ||
@@ -11,11 +12,13 @@ const request = (url, method, headers, input, includeWords = false) => { | ||
let body; | ||
headers["User-Agent"] = `mindee-node/${sdkVersion} node/${process.version}`; | ||
headers["User-Agent"] = `mindee-api-nodejs@v${sdkVersion} nodejs-${ | ||
process.version | ||
} ${os.type().toLowerCase()}`; | ||
if (["path", "stream"].includes(input.inputType)) { | ||
const fileParams = { filename: input.filename }; | ||
form.append("file", input.fileObject, fileParams); | ||
form.append("document", input.fileObject, fileParams); | ||
if (includeWords) form.append("include_mvision", "true"); | ||
headers = { ...headers, ...form.getHeaders() }; | ||
} else if (input.inputType === "base64") { | ||
let body_obj = { file: input.fileObject }; | ||
let body_obj = { document: input.fileObject }; | ||
if (includeWords) body_obj["include_mvision"] = "true"; | ||
@@ -49,3 +52,3 @@ body = JSON.stringify(body_obj); | ||
} catch (error) { | ||
console.log(responseBody); | ||
console.log(responseBody, error); | ||
} | ||
@@ -52,0 +55,0 @@ }); |
@@ -41,3 +41,3 @@ const Document = require("../documents").document; | ||
}; | ||
const predictions = this.httpResponse.data.predictions.entries(); | ||
const predictions = this.httpResponse.data.document.inference.pages.entries(); | ||
this[`${this.documentType}s`] = []; | ||
@@ -49,3 +49,3 @@ | ||
constructors[this.documentType]({ | ||
apiPrediction: prediction, | ||
apiPrediction: prediction.prediction, | ||
inputFile: this.input, | ||
@@ -58,5 +58,8 @@ pageNumber: pageNumber, | ||
// Merge the list of Document into a unique Document | ||
this[this.documentType] = Document.mergePages( | ||
this[`${this.documentType}s`] | ||
); | ||
this[this.documentType] = constructors[this.documentType]({ | ||
apiPrediction: this.httpResponse.data.document.inference.prediction, | ||
inputFile: this.input, | ||
pageNumber: -1, | ||
level: "document", | ||
}); | ||
} | ||
@@ -63,0 +66,0 @@ } |
@@ -21,3 +21,3 @@ class Field { | ||
this.bbox = []; | ||
if (valueKey in prediction && prediction[valueKey] !== "N/A") { | ||
if (valueKey in prediction && prediction[valueKey] !== null) { | ||
this.value = prediction[valueKey]; | ||
@@ -24,0 +24,0 @@ if (prediction.probability) this.probability = prediction.probability; |
@@ -30,2 +30,3 @@ const Document = require("./document"); | ||
* @param {Object} pageNumber - pageNumber for multi pages pdf input | ||
* @param {String} level - specify whether object is built from "page" level or "document" level prediction | ||
*/ | ||
@@ -50,4 +51,6 @@ constructor({ | ||
pageNumber = 0, | ||
level = "page", | ||
}) { | ||
super(inputFile); | ||
this.level = level; | ||
if (apiPrediction === undefined) { | ||
@@ -62,3 +65,3 @@ this.#initFromScratch({ | ||
taxes, | ||
merchantName, | ||
supplier, | ||
paymentDetails, | ||
@@ -92,3 +95,3 @@ companyNumber, | ||
pageNumber, | ||
merchantName, | ||
supplier, | ||
time, | ||
@@ -105,3 +108,3 @@ }) { | ||
this.dueDate = new Date(constructPrediction(dueDate)); | ||
this.merchantName = new Field(constructPrediction(merchantName)); | ||
this.supplier = new Field(constructPrediction(supplier)); | ||
this.time = new Field(constructPrediction(time)); | ||
@@ -130,22 +133,43 @@ this.orientation = new Orientation(constructPrediction(orientation)); | ||
if (Object.keys(apiPrediction).includes("invoice_number")) { | ||
const invoice = new Invoice({ apiPrediction, inputFile, pageNumber }); | ||
Object.assign(this, invoice); | ||
const invoice = new Invoice({ | ||
apiPrediction, | ||
inputFile, | ||
pageNumber, | ||
level: this.level, | ||
}); | ||
this.locale = invoice.locale; | ||
this.totalIncl = invoice.totalIncl; | ||
this.totalExcl = invoice.totalExcl; | ||
this.date = invoice.invoiceDate; | ||
this.invoiceNumber = invoice.invoiceNumber; | ||
this.dueDate = invoice.dueDate; | ||
this.taxes = invoice.taxes; | ||
this.supplier = invoice.supplier; | ||
this.paymentDetails = invoice.paymentDetails; | ||
this.companyNumber = invoice.companyNumber; | ||
this.orientation = invoice.orientation; | ||
this.totalTax = invoice.totalTax; | ||
this.time = new Field({ | ||
prediction: { value: undefined, probability: 0.0 }, | ||
}); | ||
this.merchantName = new Field({ | ||
prediction: { value: undefined, probability: 0.0 }, | ||
}); | ||
} else { | ||
const receipt = new Receipt({ apiPrediction, inputFile, pageNumber }); | ||
Object.assign(this, receipt); | ||
this.invoiceDate = new Field({ | ||
prediction: { value: undefined, probability: 0.0 }, | ||
const receipt = new Receipt({ | ||
apiPrediction, | ||
inputFile, | ||
pageNumber, | ||
level: this.level, | ||
}); | ||
this.orientation = receipt.orientation; | ||
this.date = receipt.date; | ||
this.dueDate = receipt.date; | ||
this.taxes = receipt.taxes; | ||
this.locale = receipt.locale; | ||
this.totalIncl = receipt.totalIncl; | ||
this.totalExcl = receipt.totalExcl; | ||
this.supplier = receipt.merchantName; | ||
this.time = receipt.time; | ||
this.totalTax = receipt.totalTax; | ||
this.invoiceNumber = new Field({ | ||
prediction: { value: undefined, probability: 0.0 }, | ||
}); | ||
this.dueDate = new Field({ | ||
prediction: { value: undefined, probability: 0.0 }, | ||
}); | ||
this.paymentDetails = new Field({ | ||
@@ -166,3 +190,3 @@ prediction: { value: undefined, probability: 0.0 }, | ||
Date: ${this.date.value} | ||
Merchant name: ${this.merchantName.value} | ||
Supplier: ${this.supplier.value} | ||
Total taxes: ${this.totalTax.value} | ||
@@ -169,0 +193,0 @@ `; |
@@ -14,3 +14,2 @@ const Document = require("./document"); | ||
* @param {Input} input - Input object | ||
* @param {Integer} pageNumber - Page number for multi pages pdf input | ||
* @param {Object} locale - locale value for creating Invoice object from scratch | ||
@@ -28,3 +27,4 @@ * @param {Object} totalIncl - total tax included value for creating Invoice object from scratch | ||
* @param {Object} totalTax - total tax value for creating Invoice object from scratch | ||
* @param {Object} pageNumber - pageNumber for multi pages pdf input | ||
* @param {Number} pageNumber - pageNumber for multi pages pdf input | ||
* @param {String} level - specify whether object is built from "page" level or "document" level prediction | ||
*/ | ||
@@ -48,4 +48,9 @@ constructor({ | ||
pageNumber = 0, | ||
level = "page", | ||
}) { | ||
super(inputFile); | ||
this.level = level; | ||
this.constructPrediction = function (item) { | ||
return { prediction: { value: item }, valueKey: "value", pageNumber }; | ||
}; | ||
if (apiPrediction === undefined) { | ||
@@ -91,18 +96,14 @@ this.#initFromScratch({ | ||
}) { | ||
const constructPrediction = function (item) { | ||
return { prediction: { value: item }, valueKey: "value", pageNumber }; | ||
}; | ||
this.locale = new Locale(constructPrediction(locale)); | ||
this.totalIncl = new Amount(constructPrediction(totalIncl)); | ||
this.totalExcl = new Amount(constructPrediction(totalExcl)); | ||
this.totalTax = new Amount(constructPrediction(totalTax)); | ||
this.date = new Date(constructPrediction(invoiceDate)); | ||
this.invoiceDate = new Date(constructPrediction(invoiceDate)); | ||
this.dueDate = new Date(constructPrediction(dueDate)); | ||
this.supplier = new Field(constructPrediction(supplier)); | ||
this.orientation = new Orientation(constructPrediction(orientation)); | ||
this.invoiceNumber = new Field(constructPrediction(invoiceNumber)); | ||
this.paymentDetails = new Field(constructPrediction(paymentDetails)); | ||
this.companyNumber = new Field(constructPrediction(companyNumber)); | ||
this.vatNumber = new Field(constructPrediction(vatNumber)); | ||
this.locale = new Locale(this.constructPrediction(locale)); | ||
this.totalIncl = new Amount(this.constructPrediction(totalIncl)); | ||
this.totalExcl = new Amount(this.constructPrediction(totalExcl)); | ||
this.totalTax = new Amount(this.constructPrediction(totalTax)); | ||
this.date = new Date(this.constructPrediction(invoiceDate)); | ||
this.invoiceDate = new Date(this.constructPrediction(invoiceDate)); | ||
this.dueDate = new Date(this.constructPrediction(dueDate)); | ||
this.supplier = new Field(this.constructPrediction(supplier)); | ||
this.invoiceNumber = new Field(this.constructPrediction(invoiceNumber)); | ||
this.paymentDetails = new Field(this.constructPrediction(paymentDetails)); | ||
this.companyNumber = new Field(this.constructPrediction(companyNumber)); | ||
this.vatNumber = new Field(this.constructPrediction(vatNumber)); | ||
if (taxes !== undefined) { | ||
@@ -121,2 +122,5 @@ this.taxes = []; | ||
} | ||
if (this.level === "page") { | ||
this.orientation = new Orientation(this.constructPrediction(orientation)); | ||
} | ||
} | ||
@@ -161,6 +165,2 @@ | ||
}); | ||
this.orientation = new Orientation({ | ||
prediction: apiPrediction.orientation, | ||
pageNumber, | ||
}); | ||
this.companyNumber = apiPrediction.company_registration.map(function ( | ||
@@ -193,3 +193,19 @@ companyNumber | ||
}); | ||
if (this.level === "page") { | ||
this.orientation = new Orientation({ | ||
prediction: apiPrediction.orientation, | ||
pageNumber, | ||
}); | ||
} else { | ||
this.orientation = new Orientation( | ||
this.constructPrediction({ | ||
prediction: { | ||
value: undefined, | ||
probability: 0.0, | ||
degrees: undefined, | ||
}, | ||
}) | ||
); | ||
} | ||
// document.inference.ocr | ||
if ("mvision" in apiPrediction) this.words = apiPrediction.mvision; | ||
@@ -196,0 +212,0 @@ } |
@@ -25,2 +25,3 @@ const Document = require("./document"); | ||
* @param {Object} totalExcl - total taxes excluded value for creating Receipt object from scratch | ||
* @param {String} level - specify whether object is built from "page" level or "document" level prediction | ||
*/ | ||
@@ -41,4 +42,9 @@ constructor({ | ||
pageNumber = 0, | ||
level = "page", | ||
}) { | ||
super(inputFile); | ||
this.level = level; | ||
this.constructPrediction = function (item) { | ||
return { prediction: { value: item }, valueKey: "value", pageNumber }; | ||
}; | ||
if (apiPrediction === undefined) { | ||
@@ -78,11 +84,8 @@ this.#initFromScratch({ | ||
}) { | ||
const constructPrediction = function (item) { | ||
return { prediction: { value: item }, valueKey: "value", pageNumber }; | ||
}; | ||
this.locale = new Locale(constructPrediction(locale)); | ||
this.totalIncl = new Amount(constructPrediction(totalIncl)); | ||
this.date = new Date(constructPrediction(date)); | ||
this.category = new Field(constructPrediction(category)); | ||
this.merchantName = new Field(constructPrediction(merchantName)); | ||
this.time = new Field(constructPrediction(time)); | ||
this.locale = new Locale(this.constructPrediction(locale)); | ||
this.totalIncl = new Amount(this.constructPrediction(totalIncl)); | ||
this.date = new Date(this.constructPrediction(date)); | ||
this.category = new Field(this.constructPrediction(category)); | ||
this.merchantName = new Field(this.constructPrediction(merchantName)); | ||
this.time = new Field(this.constructPrediction(time)); | ||
if (taxes !== undefined) { | ||
@@ -101,5 +104,5 @@ this.taxes = []; | ||
} | ||
this.orientation = new Orientation(constructPrediction(orientation)); | ||
this.totalTax = new Amount(constructPrediction(totalTax)); | ||
this.totalExcl = new Amount(constructPrediction(totalExcl)); | ||
this.orientation = new Orientation(this.constructPrediction(orientation)); | ||
this.totalTax = new Amount(this.constructPrediction(totalTax)); | ||
this.totalExcl = new Amount(this.constructPrediction(totalExcl)); | ||
} | ||
@@ -149,6 +152,2 @@ | ||
); | ||
this.orientation = new Orientation({ | ||
prediction: apiPrediction.orientation, | ||
pageNumber, | ||
}); | ||
this.totalTax = new Amount({ | ||
@@ -164,2 +163,18 @@ prediction: { value: undefined, probability: 0 }, | ||
}); | ||
if (this.level === "page") { | ||
this.orientation = new Orientation({ | ||
prediction: apiPrediction.orientation, | ||
pageNumber, | ||
}); | ||
} else { | ||
this.orientation = new Orientation( | ||
this.constructPrediction({ | ||
prediction: { | ||
value: undefined, | ||
probability: 0.0, | ||
degrees: undefined, | ||
}, | ||
}) | ||
); | ||
} | ||
if ("mvision" in apiPrediction) this.words = apiPrediction.mvision; | ||
@@ -166,0 +181,0 @@ } |
@@ -77,2 +77,3 @@ const fs = require("fs").promises; | ||
const filetype = this.filename.split(".").pop(); | ||
console.log(this.filename.split(".")); | ||
if (!(filetype in this.MIMETYPES)) { | ||
@@ -79,0 +80,0 @@ errorHandler.throw( |
{ | ||
"name": "mindee", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"description": "Mindee API SDK for Node.js", | ||
@@ -41,3 +41,3 @@ "main": "mindee/index.js", | ||
"file-type": "^16.5.3", | ||
"form-data": "^3.0.0", | ||
"form-data": "^3.0.1", | ||
"pdf-lib": "^1.13.0" | ||
@@ -44,0 +44,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
4303
2117070
Updatedform-data@^3.0.1