Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mindee

Package Overview
Dependencies
Maintainers
8
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mindee - npm Package Compare versions

Comparing version 3.2.0 to 3.3.0

src/documents/invoice/checks.d.ts

5

CHANGELOG.md
# CHANGELOG
## v3.3.0 - 2022-12-01
### Changes
* :sparkles: Add Invoice V4 with line items
* :sparkles: An env variable can be used to change the Mindee base API url
## v3.2.0 - 2022-11-14

@@ -4,0 +9,0 @@ ### Changes

2

package.json
{
"name": "mindee",
"version": "3.2.0",
"version": "3.3.0",
"description": "Mindee Client Library for Node.js",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -69,7 +69,7 @@ # Mindee API Helper Library for Node.js

```js
// Print a brief summary of the parsed data
// Handle the response Promise
apiResponse.then((resp) => {
// The document property can be undefined:
// * TypeScript will throw an error without this guard clause
// The `document` property can be undefined:
// * TypeScript will not compile without this guard clause
// (or consider using the '?' notation)

@@ -76,0 +76,0 @@ // * JavaScript will be very happy to produce subtle bugs

@@ -6,2 +6,3 @@ /// <reference types="node" />

export declare const API_KEY_ENVVAR_NAME = "MINDEE_API_KEY";
export declare const API_BASE_URL_ENVVAR_NAME = "MINDEE_BASE_URL";
export interface predictResponse {

@@ -29,2 +30,3 @@ messageObj: IncomingMessage;

protected apiKeyFromEnv(): string;
protected baseUrlFromEnv(): string;
}

@@ -31,0 +33,0 @@ export declare class StandardEndpoint extends Endpoint {

@@ -29,3 +29,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomEndpoint = exports.StandardEndpoint = exports.Endpoint = exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = void 0;
exports.CustomEndpoint = exports.StandardEndpoint = exports.Endpoint = exports.API_BASE_URL_ENVVAR_NAME = exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = void 0;
const https = __importStar(require("https"));

@@ -37,6 +37,7 @@ const os = __importStar(require("os"));

const logger_1 = require("../logger");
const MINDEE_API_URL = "https://api.mindee.net/v1";
const DEFAULT_MINDEE_API_URL = "https://api.mindee.net/v1";
const USER_AGENT = `mindee-api-nodejs@v${package_json_1.version} nodejs-${process.version} ${os.type().toLowerCase()}`;
exports.STANDARD_API_OWNER = "mindee";
exports.API_KEY_ENVVAR_NAME = "MINDEE_API_KEY";
exports.API_BASE_URL_ENVVAR_NAME = "MINDEE_BASE_URL";
class Endpoint {

@@ -48,3 +49,3 @@ constructor(owner, urlName, version, apiKey) {

this.apiKey = apiKey || this.apiKeyFromEnv();
this.urlRoot = `${MINDEE_API_URL}/products/${owner}/${urlName}/v${version}`;
this.urlRoot = `${this.baseUrlFromEnv()}/products/${owner}/${urlName}/v${version}`;
this.baseHeaders = {

@@ -118,2 +119,10 @@ "User-Agent": USER_AGENT,

}
baseUrlFromEnv() {
const envVarValue = process.env[exports.API_BASE_URL_ENVVAR_NAME];
if (envVarValue) {
logger_1.logger.debug(`Set the API base URL to ${envVarValue}`);
return envVarValue;
}
return DEFAULT_MINDEE_API_URL;
}
}

@@ -120,0 +129,0 @@ exports.Endpoint = Endpoint;

@@ -25,4 +25,4 @@ "use strict";

{
description: "Invoice V3",
docClass: documents_1.InvoiceV3,
description: "Invoice V4",
docClass: documents_1.InvoiceV4,
fullText: true,

@@ -29,0 +29,0 @@ },

@@ -17,3 +17,3 @@ /// <reference types="node" />

/**
* For custom endpoints, your organization's username on the API Builder.
* For custom endpoints, your account or organization's username on the API Builder.
* This is normally not required unless you have a custom endpoint which has the

@@ -20,0 +20,0 @@ * same name as standard (off the shelf) endpoint.

@@ -86,2 +86,5 @@ "use strict";

]));
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.InvoiceV4.name], new documentConfig_1.DocumentConfig(documents_1.InvoiceV4, [
new api_1.StandardEndpoint("invoices", "4", this.apiKey),
]));
this.docConfigs.set([api_1.STANDARD_API_OWNER, documents_1.ReceiptV3.name], new documentConfig_1.DocumentConfig(documents_1.ReceiptV3, [

@@ -88,0 +91,0 @@ new api_1.StandardEndpoint("expense_receipts", "3", this.apiKey),

export { InvoiceV3 } from "./invoice/invoiceV3";
export { InvoiceV4 } from "./invoice/invoiceV4";
export { ReceiptV3 } from "./receipt/receiptV3";

@@ -3,0 +4,0 @@ export { ReceiptV4 } from "./receipt/receiptV4";

@@ -26,5 +26,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.eu = exports.us = exports.fr = exports.Document = exports.ShippingContainerV1 = exports.CropperV1 = exports.CustomV1 = exports.FinancialDocumentV1 = exports.PassportV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.InvoiceV3 = void 0;
exports.eu = exports.us = exports.fr = exports.Document = exports.ShippingContainerV1 = exports.CropperV1 = exports.CustomV1 = exports.FinancialDocumentV1 = exports.PassportV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.InvoiceV4 = exports.InvoiceV3 = void 0;
var invoiceV3_1 = require("./invoice/invoiceV3");
Object.defineProperty(exports, "InvoiceV3", { enumerable: true, get: function () { return invoiceV3_1.InvoiceV3; } });
var invoiceV4_1 = require("./invoice/invoiceV4");
Object.defineProperty(exports, "InvoiceV4", { enumerable: true, get: function () { return invoiceV4_1.InvoiceV4; } });
var receiptV3_1 = require("./receipt/receiptV3");

@@ -31,0 +33,0 @@ Object.defineProperty(exports, "ReceiptV3", { enumerable: true, get: function () { return receiptV3_1.ReceiptV3; } });

@@ -9,4 +9,4 @@ import { Document, DocumentConstructorProps } from "../document";

documentType: BaseField;
/** The total amount with tax included. */
totalIncl: Amount;
/** The total amount with tax included. Same as totalIncl. */
totalAmount: Amount;
/** The creation date of the invoice. */

@@ -20,4 +20,4 @@ date: DateField;

totalTax: Amount;
/** The total amount without the tax value. */
totalExcl: Amount;
/** The total amount without the tax value. Same as totalExcl. */
totalNet: Amount;
/** The supplier name. */

@@ -41,10 +41,12 @@ supplier: Field;

customerCompanyRegistration: CompanyRegistration[];
/** The total amount without the tax value. */
get totalExcl(): Amount;
/** The total amount without the tax value. */
set totalExcl(value: Amount);
/** The total amount with tax included. */
get totalIncl(): Amount;
/** The total amount with tax included. */
set totalIncl(value: Amount);
constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
toString(): string;
private taxesMatchTotalIncl;
/**
*
*/
private taxesMatchTotalExcl;
private taxesAndTotalExclMatchTotalIncl;
}

@@ -7,3 +7,3 @@ "use strict";

};
var _InvoiceV3_instances, _InvoiceV3_initFromApiPrediction, _InvoiceV3_checklist, _InvoiceV3_reconstruct, _InvoiceV3_reconstructTotalTax, _InvoiceV3_reconstructTotalTaxFromTotals, _InvoiceV3_reconstructTotalExcl, _InvoiceV3_reconstructTotalIncl;
var _InvoiceV3_instances, _InvoiceV3_initFromApiPrediction, _InvoiceV3_checklist, _InvoiceV3_reconstruct;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -13,2 +13,4 @@ exports.InvoiceV3 = void 0;

const fields_1 = require("../../fields");
const checks_1 = require("./checks");
const reconstruction_1 = require("./reconstruction");
class InvoiceV3 extends document_1.Document {

@@ -36,2 +38,18 @@ constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {

}
/** The total amount without the tax value. */
get totalExcl() {
return this.totalNet;
}
/** The total amount without the tax value. */
set totalExcl(value) {
this.totalNet = value;
}
/** The total amount with tax included. */
get totalIncl() {
return this.totalAmount;
}
/** The total amount with tax included. */
set totalIncl(value) {
this.totalAmount = value;
}
toString() {

@@ -48,3 +66,3 @@ const taxes = this.taxes.map((item) => item.toString()).join("\n ");

.join("; ");
const outStr = `-----Invoice data-----
const outStr = `----- Invoice V3 -----
Filename: ${this.filename}

@@ -70,86 +88,2 @@ Invoice number: ${this.invoiceNumber}

}
taxesMatchTotalIncl() {
// Check taxes and total include exist
if (this.taxes.length === 0 || this.totalIncl.value === undefined)
return false;
// Reconstruct totalIncl from taxes
let totalVat = 0;
let reconstructedTotal = 0;
this.taxes.forEach((tax) => {
if (tax.value === undefined || !tax.rate)
return false;
totalVat += tax.value;
reconstructedTotal += tax.value + (100 * tax.value) / tax.rate;
});
// Sanity check
if (totalVat <= 0)
return false;
// Crate epsilon
const eps = 1 / (100 * totalVat);
if (this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal &&
reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02) {
this.taxes.forEach((tax) => {
tax.confidence = 1.0;
});
this.totalTax.confidence = 1.0;
this.totalIncl.confidence = 1.0;
return true;
}
return false;
}
/**
*
*/
taxesMatchTotalExcl() {
// Check taxes and total amount exist
if (this.taxes.length === 0 || this.totalExcl.value === undefined) {
return false;
}
// Reconstruct total_incl from taxes
let totalVat = 0;
let reconstructedTotal = 0;
this.taxes.forEach((tax) => {
if (tax.value === undefined || !tax.rate) {
return false;
}
totalVat += tax.value;
reconstructedTotal += (100 * tax.value) / tax.rate;
});
// Sanity check
if (totalVat <= 0)
return false;
// Crate epsilon
const eps = 1 / (100 * totalVat);
if (this.totalExcl.value * (1 - eps) - 0.02 <= reconstructedTotal &&
reconstructedTotal <= this.totalExcl.value * (1 + eps) + 0.02) {
this.taxes.forEach((tax) => {
tax.confidence = 1.0;
});
this.totalTax.confidence = 1.0;
this.totalExcl.confidence = 1.0;
return true;
}
return false;
}
taxesAndTotalExclMatchTotalIncl() {
if (this.totalExcl.value === undefined ||
this.taxes.length === 0 ||
this.totalIncl.value === undefined)
return false;
let totalVat = 0;
this.taxes.forEach((tax) => (totalVat += tax.value || 0));
const reconstructedTotal = totalVat + this.totalExcl.value;
if (totalVat <= 0)
return false;
if (this.totalIncl.value - 0.01 <= reconstructedTotal &&
reconstructedTotal <= this.totalIncl.value + 0.01) {
this.taxes.forEach((tax) => {
tax.confidence = 1.0;
});
this.totalTax.confidence = 1.0;
this.totalIncl.confidence = 1.0;
return true;
}
return false;
}
}

@@ -171,2 +105,3 @@ exports.InvoiceV3 = InvoiceV3;

});
this.totalAmount = this.totalIncl;
this.totalTax = new fields_1.Amount({

@@ -177,3 +112,3 @@ prediction: { value: undefined, confidence: 0.0 },

});
this.totalExcl = new fields_1.Amount({
this.totalNet = new fields_1.Amount({
prediction: apiPrediction.total_excl,

@@ -234,76 +169,11 @@ valueKey: "value",

this.checklist = {
taxesMatchTotalIncl: this.taxesMatchTotalIncl(),
taxesMatchTotalExcl: this.taxesMatchTotalExcl(),
taxesAndTotalExclMatchTotalIncl: this.taxesAndTotalExclMatchTotalIncl(),
taxesMatchTotalIncl: (0, checks_1.taxesMatchTotalIncl)(this),
taxesMatchTotalExcl: (0, checks_1.taxesMatchTotalExcl)(this),
taxesAndTotalExclMatchTotalIncl: (0, checks_1.taxesAndTotalExclMatchTotalIncl)(this),
};
}, _InvoiceV3_reconstruct = function _InvoiceV3_reconstruct() {
__classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_reconstructTotalTax).call(this);
__classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_reconstructTotalExcl).call(this);
__classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_reconstructTotalIncl).call(this);
__classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_reconstructTotalTaxFromTotals).call(this);
}, _InvoiceV3_reconstructTotalTax = function _InvoiceV3_reconstructTotalTax() {
if (this.taxes.length > 0) {
const totalTax = {
value: this.taxes.reduce((acc, tax) => {
return tax.value !== undefined ? acc + tax.value : acc;
}, 0),
confidence: fields_1.Field.arrayConfidence(this.taxes),
};
if (totalTax.value > 0)
this.totalTax = new fields_1.Amount({
prediction: totalTax,
valueKey: "value",
reconstructed: true,
});
}
}, _InvoiceV3_reconstructTotalTaxFromTotals = function _InvoiceV3_reconstructTotalTaxFromTotals() {
if (this.totalTax.value !== undefined ||
this.totalExcl.value === undefined ||
this.totalIncl.value === undefined) {
return;
}
const totalTax = {
value: this.totalIncl.value - this.totalExcl.value,
confidence: this.totalIncl.confidence * this.totalExcl.confidence,
};
if (totalTax.value >= 0) {
this.totalTax = new fields_1.Amount({
prediction: totalTax,
valueKey: "value",
reconstructed: true,
});
}
}, _InvoiceV3_reconstructTotalExcl = function _InvoiceV3_reconstructTotalExcl() {
if (this.totalIncl.value === undefined ||
this.taxes.length === 0 ||
this.totalExcl.value !== undefined) {
return;
}
const totalExcl = {
value: this.totalIncl.value - fields_1.Field.arraySum(this.taxes),
confidence: fields_1.Field.arrayConfidence(this.taxes) *
this.totalIncl.confidence,
};
this.totalExcl = new fields_1.Amount({
prediction: totalExcl,
valueKey: "value",
reconstructed: true,
});
}, _InvoiceV3_reconstructTotalIncl = function _InvoiceV3_reconstructTotalIncl() {
if (!(this.totalExcl.value === undefined ||
this.taxes.length === 0 ||
this.totalIncl.value !== undefined)) {
const totalIncl = {
value: this.totalExcl.value +
this.taxes.reduce((acc, tax) => {
return tax.value ? acc + tax.value : acc;
}, 0.0),
confidence: fields_1.Field.arrayConfidence(this.taxes) * this.totalExcl.confidence,
};
this.totalIncl = new fields_1.Amount({
prediction: totalIncl,
valueKey: "value",
reconstructed: true,
});
}
(0, reconstruction_1.reconstructTotalTax)(this);
(0, reconstruction_1.reconstructTotalExcl)(this);
(0, reconstruction_1.reconstructTotalIncl)(this);
(0, reconstruction_1.reconstructTotalTaxFromTotals)(this);
};

@@ -1,3 +0,3 @@

export { CustomV1, FinancialDocumentV1, InvoiceV3, PassportV1, ReceiptV3, ReceiptV4, CropperV1, ShippingContainerV1, fr, us, eu, } from "./documents";
export { CustomV1, FinancialDocumentV1, InvoiceV3, InvoiceV4, PassportV1, ReceiptV3, ReceiptV4, CropperV1, ShippingContainerV1, fr, us, eu, } from "./documents";
export { Client } from "./client";
export { PageOptionsOperation } from "./inputs";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PageOptionsOperation = exports.Client = exports.eu = exports.us = exports.fr = exports.ShippingContainerV1 = exports.CropperV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.CustomV1 = void 0;
exports.PageOptionsOperation = exports.Client = exports.eu = exports.us = exports.fr = exports.ShippingContainerV1 = exports.CropperV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.PassportV1 = exports.InvoiceV4 = exports.InvoiceV3 = exports.FinancialDocumentV1 = exports.CustomV1 = void 0;
var documents_1 = require("./documents");

@@ -8,2 +8,3 @@ Object.defineProperty(exports, "CustomV1", { enumerable: true, get: function () { return documents_1.CustomV1; } });

Object.defineProperty(exports, "InvoiceV3", { enumerable: true, get: function () { return documents_1.InvoiceV3; } });
Object.defineProperty(exports, "InvoiceV4", { enumerable: true, get: function () { return documents_1.InvoiceV4; } });
Object.defineProperty(exports, "PassportV1", { enumerable: true, get: function () { return documents_1.PassportV1; } });

@@ -10,0 +11,0 @@ Object.defineProperty(exports, "ReceiptV3", { enumerable: true, get: function () { return documents_1.ReceiptV3; } });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc