mindee 1.4.0 → 2.0.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 (89) hide show
  1. package/CHANGELOG.md +33 -19
  2. package/README.md +43 -127
  3. package/bin/mindee +3 -0
  4. package/dist/package.json +70 -0
  5. package/dist/src/api/endpoint.d.ts +29 -0
  6. package/dist/src/api/endpoint.js +148 -0
  7. package/dist/src/api/index.d.ts +2 -0
  8. package/dist/src/api/index.js +18 -0
  9. package/dist/src/api/response.d.ts +52 -0
  10. package/dist/src/api/response.js +107 -0
  11. package/dist/src/cli.d.ts +1 -0
  12. package/dist/src/cli.js +117 -0
  13. package/dist/src/client.d.ts +48 -0
  14. package/dist/src/client.js +134 -0
  15. package/dist/src/constants.d.ts +13 -0
  16. package/dist/src/constants.js +54 -0
  17. package/dist/src/documents/custom.d.ts +14 -0
  18. package/dist/src/documents/custom.js +48 -0
  19. package/dist/src/documents/document.d.ts +38 -0
  20. package/dist/src/documents/document.js +60 -0
  21. package/dist/src/documents/documentConfig.d.ts +44 -0
  22. package/dist/src/documents/documentConfig.js +121 -0
  23. package/dist/src/documents/financialDocument.d.ts +32 -0
  24. package/dist/src/documents/financialDocument.js +130 -0
  25. package/dist/src/documents/index.d.ts +12 -0
  26. package/dist/src/documents/index.js +20 -0
  27. package/dist/src/documents/invoice.d.ts +37 -0
  28. package/dist/src/documents/invoice.js +303 -0
  29. package/dist/src/documents/passport.d.ts +36 -0
  30. package/dist/src/documents/passport.js +218 -0
  31. package/dist/src/documents/receipt.d.ts +24 -0
  32. package/dist/src/documents/receipt.js +157 -0
  33. package/dist/src/errors/handler.d.ts +7 -0
  34. package/dist/src/errors/handler.js +18 -0
  35. package/dist/src/fields/amount.d.ts +13 -0
  36. package/dist/src/fields/amount.js +34 -0
  37. package/dist/src/fields/companyRegistration.d.ts +6 -0
  38. package/dist/src/fields/companyRegistration.js +11 -0
  39. package/dist/src/fields/customDocs.d.ts +42 -0
  40. package/dist/src/fields/customDocs.js +61 -0
  41. package/dist/src/fields/date.d.ts +12 -0
  42. package/dist/src/fields/date.js +25 -0
  43. package/dist/src/fields/field.d.ts +74 -0
  44. package/dist/src/fields/field.js +106 -0
  45. package/dist/src/fields/fullText.d.ts +24 -0
  46. package/dist/src/fields/fullText.js +89 -0
  47. package/dist/src/fields/index.d.ts +11 -0
  48. package/dist/src/fields/index.js +27 -0
  49. package/dist/src/fields/locale.d.ts +13 -0
  50. package/dist/src/fields/locale.js +40 -0
  51. package/dist/src/fields/orientation.d.ts +10 -0
  52. package/dist/src/fields/orientation.js +22 -0
  53. package/dist/src/fields/paymentDetails.d.ts +31 -0
  54. package/dist/src/fields/paymentDetails.js +58 -0
  55. package/dist/src/fields/tax.d.ts +30 -0
  56. package/dist/src/fields/tax.js +51 -0
  57. package/dist/src/geometry.d.ts +59 -0
  58. package/dist/src/geometry.js +113 -0
  59. package/dist/src/index.d.ts +2 -0
  60. package/dist/src/index.js +12 -0
  61. package/dist/src/inputs.d.ts +69 -0
  62. package/dist/src/inputs.js +223 -0
  63. package/dist/src/logger.d.ts +20 -0
  64. package/dist/src/logger.js +35 -0
  65. package/package.json +38 -28
  66. package/mindee/api/financialDocument.js +0 -47
  67. package/mindee/api/index.js +0 -5
  68. package/mindee/api/invoice.js +0 -53
  69. package/mindee/api/object.js +0 -82
  70. package/mindee/api/receipt.js +0 -39
  71. package/mindee/api/request.js +0 -72
  72. package/mindee/api/response.js +0 -80
  73. package/mindee/documents/document.js +0 -69
  74. package/mindee/documents/fields/amount.js +0 -25
  75. package/mindee/documents/fields/date.js +0 -29
  76. package/mindee/documents/fields/field.js +0 -86
  77. package/mindee/documents/fields/index.js +0 -7
  78. package/mindee/documents/fields/locale.js +0 -30
  79. package/mindee/documents/fields/orientation.js +0 -24
  80. package/mindee/documents/fields/paymentDetails.js +0 -52
  81. package/mindee/documents/fields/tax.js +0 -47
  82. package/mindee/documents/financialDocument.js +0 -269
  83. package/mindee/documents/index.js +0 -5
  84. package/mindee/documents/invoice.js +0 -456
  85. package/mindee/documents/receipt.js +0 -287
  86. package/mindee/errors/handler.js +0 -16
  87. package/mindee/index.js +0 -39
  88. package/mindee/inputs.js +0 -181
  89. package/mindee/logger.js +0 -34
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.FullText = void 0;
27
+ const geometry = __importStar(require("../geometry"));
28
+ function orderLines(fullText) {
29
+ const lines = [];
30
+ const idxs = [];
31
+ let current = undefined;
32
+ fullText.forEach(() => {
33
+ let line = [];
34
+ fullText.forEach((word, idx) => {
35
+ if (!idxs.includes(idx)) {
36
+ if (current === undefined) {
37
+ current = word;
38
+ idxs.push(idx);
39
+ line = [current];
40
+ }
41
+ else {
42
+ const centroid = geometry.getCentroid(word.polygon);
43
+ if (geometry.isPointInPolygonY(centroid, current.polygon)) {
44
+ line.push(word);
45
+ idxs.push(idx);
46
+ }
47
+ }
48
+ }
49
+ });
50
+ current = undefined;
51
+ if (line.length > 0) {
52
+ lines.push(line);
53
+ }
54
+ });
55
+ const orderedLines = [];
56
+ lines.forEach((line) => {
57
+ const sortedLine = line.sort((a, b) => {
58
+ return geometry.relativeX(a.polygon) - geometry.relativeX(b.polygon);
59
+ });
60
+ orderedLines.push(sortedLine);
61
+ });
62
+ orderedLines.reverse();
63
+ return orderedLines;
64
+ }
65
+ class FullText {
66
+ constructor() {
67
+ this.words = [];
68
+ }
69
+ /**
70
+ * Order all text on a page into lines.
71
+ * WARNING: This feature is experimental.
72
+ */
73
+ toLines() {
74
+ return orderLines(this.words);
75
+ }
76
+ /**
77
+ * WARNING: This feature is experimental.
78
+ */
79
+ toString() {
80
+ let outStr = "";
81
+ const lines = this.toLines();
82
+ lines.forEach((line) => {
83
+ const lineStr = line.map((word) => word.text).join(" ");
84
+ outStr += `${lineStr}\n`;
85
+ });
86
+ return outStr;
87
+ }
88
+ }
89
+ exports.FullText = FullText;
@@ -0,0 +1,11 @@
1
+ export { TaxField } from "./tax";
2
+ export { PaymentDetails } from "./paymentDetails";
3
+ export { Orientation } from "./orientation";
4
+ export { Locale } from "./locale";
5
+ export { Amount } from "./amount";
6
+ export { DateField } from "./date";
7
+ export { BaseField } from "./field";
8
+ export { Field } from "./field";
9
+ export { ListField, ListFieldItem, ClassificationField } from "./customDocs";
10
+ export { FullText } from "./fullText";
11
+ export { CompanyRegistration } from "./companyRegistration";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CompanyRegistration = exports.FullText = exports.ClassificationField = exports.ListFieldItem = exports.ListField = exports.Field = exports.BaseField = exports.DateField = exports.Amount = exports.Locale = exports.Orientation = exports.PaymentDetails = exports.TaxField = void 0;
4
+ var tax_1 = require("./tax");
5
+ Object.defineProperty(exports, "TaxField", { enumerable: true, get: function () { return tax_1.TaxField; } });
6
+ var paymentDetails_1 = require("./paymentDetails");
7
+ Object.defineProperty(exports, "PaymentDetails", { enumerable: true, get: function () { return paymentDetails_1.PaymentDetails; } });
8
+ var orientation_1 = require("./orientation");
9
+ Object.defineProperty(exports, "Orientation", { enumerable: true, get: function () { return orientation_1.Orientation; } });
10
+ var locale_1 = require("./locale");
11
+ Object.defineProperty(exports, "Locale", { enumerable: true, get: function () { return locale_1.Locale; } });
12
+ var amount_1 = require("./amount");
13
+ Object.defineProperty(exports, "Amount", { enumerable: true, get: function () { return amount_1.Amount; } });
14
+ var date_1 = require("./date");
15
+ Object.defineProperty(exports, "DateField", { enumerable: true, get: function () { return date_1.DateField; } });
16
+ var field_1 = require("./field");
17
+ Object.defineProperty(exports, "BaseField", { enumerable: true, get: function () { return field_1.BaseField; } });
18
+ var field_2 = require("./field");
19
+ Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return field_2.Field; } });
20
+ var customDocs_1 = require("./customDocs");
21
+ Object.defineProperty(exports, "ListField", { enumerable: true, get: function () { return customDocs_1.ListField; } });
22
+ Object.defineProperty(exports, "ListFieldItem", { enumerable: true, get: function () { return customDocs_1.ListFieldItem; } });
23
+ Object.defineProperty(exports, "ClassificationField", { enumerable: true, get: function () { return customDocs_1.ClassificationField; } });
24
+ var fullText_1 = require("./fullText");
25
+ Object.defineProperty(exports, "FullText", { enumerable: true, get: function () { return fullText_1.FullText; } });
26
+ var companyRegistration_1 = require("./companyRegistration");
27
+ Object.defineProperty(exports, "CompanyRegistration", { enumerable: true, get: function () { return companyRegistration_1.CompanyRegistration; } });
@@ -0,0 +1,13 @@
1
+ import { Field } from "./field";
2
+ export declare class Locale extends Field {
3
+ language: string | undefined;
4
+ country: string | undefined;
5
+ currency: string | undefined;
6
+ /**
7
+ * @param {Object} prediction - Prediction object from HTTP response
8
+ * @param {String} valueKey - Key to use in the prediction dict
9
+ * @param {boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
10
+ */
11
+ constructor({ prediction, reconstructed, valueKey }: any);
12
+ toString(): string;
13
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Locale = void 0;
4
+ const field_1 = require("./field");
5
+ class Locale extends field_1.Field {
6
+ /**
7
+ * @param {Object} prediction - Prediction object from HTTP response
8
+ * @param {String} valueKey - Key to use in the prediction dict
9
+ * @param {boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
10
+ */
11
+ constructor({ prediction, reconstructed = false, valueKey = "value" }) {
12
+ super({ prediction, valueKey, reconstructed });
13
+ this.language = undefined;
14
+ this.country = undefined;
15
+ this.currency = undefined;
16
+ if ("language" in prediction && prediction.language !== "N/A")
17
+ this.language = prediction.language;
18
+ if ("country" in prediction && prediction.country !== "N/A")
19
+ this.country = prediction.country;
20
+ if ("currency" in prediction && prediction.currency !== "N/A")
21
+ this.currency = prediction.currency;
22
+ }
23
+ toString() {
24
+ let outStr = "";
25
+ if (this.value) {
26
+ outStr += `${this.value}; `;
27
+ }
28
+ if (this.language) {
29
+ outStr += `${this.language}; `;
30
+ }
31
+ if (this.country) {
32
+ outStr += `${this.country}; `;
33
+ }
34
+ if (this.currency) {
35
+ outStr += `${this.currency};`;
36
+ }
37
+ return outStr.trimEnd();
38
+ }
39
+ }
40
+ exports.Locale = Locale;
@@ -0,0 +1,10 @@
1
+ import { Field } from "./field";
2
+ export declare class Orientation extends Field {
3
+ /**
4
+ * @param {Object} prediction - Prediction object from HTTP response
5
+ * @param {String} valueKey - Key to use in the prediction dict
6
+ * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
7
+ * @param {Integer} pageId - Page ID for multi-page document
8
+ */
9
+ constructor({ prediction, valueKey, reconstructed, pageId, }: any);
10
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Orientation = void 0;
4
+ const field_1 = require("./field");
5
+ class Orientation extends field_1.Field {
6
+ /**
7
+ * @param {Object} prediction - Prediction object from HTTP response
8
+ * @param {String} valueKey - Key to use in the prediction dict
9
+ * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
10
+ * @param {Integer} pageId - Page ID for multi-page document
11
+ */
12
+ constructor({ prediction, valueKey = "degrees", reconstructed = false, pageId, }) {
13
+ const orientations = [0, 90, 180, 270];
14
+ super({ prediction, valueKey, reconstructed, pageId });
15
+ this.value = parseInt(prediction[valueKey]);
16
+ if (isNaN(this.value))
17
+ this.confidence = 0.0;
18
+ if (!orientations.includes(this.value))
19
+ this.value = 0;
20
+ }
21
+ }
22
+ exports.Orientation = Orientation;
@@ -0,0 +1,31 @@
1
+ import { Field } from "./field";
2
+ interface PaymentDetailsConstructor {
3
+ prediction: any;
4
+ valueKey?: string;
5
+ accountNumberKey?: string;
6
+ ibanKey?: string;
7
+ routingNumberKey?: string;
8
+ swiftKey?: string;
9
+ reconstructed?: boolean;
10
+ pageId?: number;
11
+ }
12
+ export declare class PaymentDetails extends Field {
13
+ #private;
14
+ accountNumber: number | undefined;
15
+ iban: string | undefined;
16
+ routingNumber: number | undefined;
17
+ swift: number | undefined;
18
+ /**
19
+ * @param {Object} prediction - Prediction object from HTTP response
20
+ * @param {String} valueKey - Key to use in the prediction dict to get the iban
21
+ * @param {String} accountNumberKey - Key to use to get the account number in the prediction dict
22
+ * @param {String} ibanKey - Key to use to get the IBAN in the prediction dict
23
+ * @param {String} routingNumberKey - Key to use to get the routing number in the prediction dict
24
+ * @param {String} swiftKey - Key to use to get the SWIFT in the prediction dict
25
+ * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
26
+ * @param {Integer} pageId - Page ID for multi-page document
27
+ */
28
+ constructor({ prediction, valueKey, accountNumberKey, ibanKey, routingNumberKey, swiftKey, reconstructed, pageId, }: PaymentDetailsConstructor);
29
+ toString(): string;
30
+ }
31
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _PaymentDetails_instances, _PaymentDetails_setKey;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PaymentDetails = void 0;
10
+ const field_1 = require("./field");
11
+ class PaymentDetails extends field_1.Field {
12
+ /**
13
+ * @param {Object} prediction - Prediction object from HTTP response
14
+ * @param {String} valueKey - Key to use in the prediction dict to get the iban
15
+ * @param {String} accountNumberKey - Key to use to get the account number in the prediction dict
16
+ * @param {String} ibanKey - Key to use to get the IBAN in the prediction dict
17
+ * @param {String} routingNumberKey - Key to use to get the routing number in the prediction dict
18
+ * @param {String} swiftKey - Key to use to get the SWIFT in the prediction dict
19
+ * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
20
+ * @param {Integer} pageId - Page ID for multi-page document
21
+ */
22
+ constructor({ prediction, valueKey = "iban", accountNumberKey = "account_number", ibanKey = "iban", routingNumberKey = "routing_number", swiftKey = "swift", reconstructed = false, pageId = undefined, }) {
23
+ super({ prediction, valueKey, reconstructed, pageId });
24
+ _PaymentDetails_instances.add(this);
25
+ this.accountNumber = undefined;
26
+ this.iban = undefined;
27
+ this.routingNumber = undefined;
28
+ this.swift = undefined;
29
+ __classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[accountNumberKey], "accountNumber");
30
+ __classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[ibanKey], "iban");
31
+ __classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[routingNumberKey], "routingNumber");
32
+ __classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[swiftKey], "swift");
33
+ }
34
+ toString() {
35
+ let str = "";
36
+ const keys = ["accountNumber", "iban", "routingNumber", "swift"];
37
+ for (const key of keys) {
38
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
39
+ // @ts-ignore
40
+ if (this[key])
41
+ str += `${this[key]}; `;
42
+ }
43
+ return str;
44
+ }
45
+ }
46
+ exports.PaymentDetails = PaymentDetails;
47
+ _PaymentDetails_instances = new WeakSet(), _PaymentDetails_setKey = function _PaymentDetails_setKey(value, key) {
48
+ if (typeof value === "string" && value !== "N/A") {
49
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
50
+ // @ts-ignore
51
+ this[key] = value;
52
+ }
53
+ else {
54
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
55
+ // @ts-ignore
56
+ this[key] = undefined;
57
+ }
58
+ };
@@ -0,0 +1,30 @@
1
+ import { Field } from "./field";
2
+ interface TaxConstructor {
3
+ prediction: any;
4
+ valueKey?: string;
5
+ rateKey?: string;
6
+ codeKey?: string;
7
+ reconstructed?: boolean;
8
+ pageId?: number;
9
+ }
10
+ export declare class TaxField extends Field {
11
+ /** The tax amount. */
12
+ value?: number;
13
+ /** The tax code (HST, GST... for Canadian; City Tax, State tax for US, etc..). */
14
+ rate?: number;
15
+ /** The tax rate. */
16
+ code?: string;
17
+ /** The document page on which the information was found. */
18
+ pageId: number;
19
+ /**
20
+ * @param {Object} prediction - Prediction object from HTTP response
21
+ * @param {String} valueKey - Key to use in the prediction dict to get the tax value
22
+ * @param {String} rateKey - Key to use to get the tax rate in the prediction dict
23
+ * @param {String} codeKey - Key to use to get the tax code in the prediction dict
24
+ * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
25
+ * @param {Integer} pageNumber - Page ID for multi-page document
26
+ */
27
+ constructor({ prediction, valueKey, rateKey, codeKey, reconstructed, pageId, }: TaxConstructor);
28
+ toString(): string;
29
+ }
30
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaxField = void 0;
4
+ const field_1 = require("./field");
5
+ const amount_1 = require("./amount");
6
+ class TaxField extends field_1.Field {
7
+ /**
8
+ * @param {Object} prediction - Prediction object from HTTP response
9
+ * @param {String} valueKey - Key to use in the prediction dict to get the tax value
10
+ * @param {String} rateKey - Key to use to get the tax rate in the prediction dict
11
+ * @param {String} codeKey - Key to use to get the tax code in the prediction dict
12
+ * @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
13
+ * @param {Integer} pageNumber - Page ID for multi-page document
14
+ */
15
+ constructor({ prediction, valueKey = "value", rateKey = "rate", codeKey = "code", reconstructed = false, pageId = undefined, }) {
16
+ var _a;
17
+ super({ prediction, valueKey, reconstructed, pageId });
18
+ /** The tax amount. */
19
+ this.value = undefined;
20
+ /** The tax code (HST, GST... for Canadian; City Tax, State tax for US, etc..). */
21
+ this.rate = undefined;
22
+ /** The tax rate. */
23
+ this.code = undefined;
24
+ this.rate = +parseFloat(prediction[rateKey]);
25
+ if (isNaN(this.rate))
26
+ this.rate = undefined;
27
+ this.code = (_a = prediction[codeKey]) === null || _a === void 0 ? void 0 : _a.toString();
28
+ if (this.code === "N/A" || this.code === "None") {
29
+ this.code = undefined;
30
+ }
31
+ this.value = parseFloat(prediction[valueKey]);
32
+ if (isNaN(this.value)) {
33
+ this.value = undefined;
34
+ this.confidence = 0.0;
35
+ }
36
+ }
37
+ toString() {
38
+ let outStr = "";
39
+ if (this.value !== undefined) {
40
+ outStr += `${(0, amount_1.floatToString)(this.value)}`;
41
+ }
42
+ if (this.rate !== undefined) {
43
+ outStr += ` ${(0, amount_1.floatToString)(this.rate)}%`;
44
+ }
45
+ if (this.code !== undefined) {
46
+ outStr += ` ${this.code}`;
47
+ }
48
+ return outStr.trim();
49
+ }
50
+ }
51
+ exports.TaxField = TaxField;
@@ -0,0 +1,59 @@
1
+ declare type MinMax = {
2
+ min: number;
3
+ max: number;
4
+ };
5
+ /** A point on the document defined by 2 coordinates: X, Y */
6
+ export declare type Point = [number, number];
7
+ /** A bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */
8
+ export declare type BoundingBox = [number, number, number, number];
9
+ /** A polygon, composed of several Points. */
10
+ export declare type Polygon = Array<Point>;
11
+ /**
12
+ * Given a Polygon, calculate a polygon that encompasses all points.
13
+ */
14
+ export declare function getBboxAsPolygon(polygon: Polygon): Polygon;
15
+ /**
16
+ * Given a Polygon, calculate a bounding box that encompasses all points.
17
+ */
18
+ export declare function getBbox(polygon: Polygon): BoundingBox;
19
+ /**
20
+ * Get the central point (centroid) given a list of points.
21
+ */
22
+ export declare function getCentroid(vertices: Array<Point>): Point;
23
+ /**
24
+ * Determine if a Point is within two Y coordinates.
25
+ */
26
+ export declare function isPointInY(centroid: Point, yMin: number, yMax: number): boolean;
27
+ /**
28
+ * Get the maximum and minimum Y coordinates in a given list of Points.
29
+ */
30
+ export declare function getMinMaxY(vertices: Array<Point>): MinMax;
31
+ /**
32
+ * Determine if a Point is within a Polygon's Y axis.
33
+ */
34
+ export declare function isPointInPolygonY(centroid: Point, polygon: Polygon): boolean;
35
+ /**
36
+ * Calculate the relative Y position of a Polygon.
37
+ *
38
+ * Can be used to order (sort) words in the same column.
39
+ */
40
+ export declare function relativeY(polygon: Polygon): number;
41
+ /**
42
+ * Determine if a Point is within two X coordinates.
43
+ */
44
+ export declare function isPointInX(centroid: Point, xMin: number, xMax: number): boolean;
45
+ /**
46
+ * Get the maximum and minimum X coordinates in a given list of Points.
47
+ */
48
+ export declare function getMinMaxX(vertices: Array<Point>): MinMax;
49
+ /**
50
+ * Determine if a Point is within a Polygon's X axis.
51
+ */
52
+ export declare function isPointInPolygonX(centroid: Point, polygon: Polygon): boolean;
53
+ /**
54
+ * Calculate the relative X position of a Polygon.
55
+ *
56
+ * Can be used to order (sort) words in the same line.
57
+ */
58
+ export declare function relativeX(polygon: Polygon): number;
59
+ export {};
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.relativeX = exports.isPointInPolygonX = exports.getMinMaxX = exports.isPointInX = exports.relativeY = exports.isPointInPolygonY = exports.getMinMaxY = exports.isPointInY = exports.getCentroid = exports.getBbox = exports.getBboxAsPolygon = void 0;
4
+ /**
5
+ * Given a Polygon, calculate a polygon that encompasses all points.
6
+ */
7
+ function getBboxAsPolygon(polygon) {
8
+ const bbox = getBbox(polygon);
9
+ return [
10
+ [bbox[0], bbox[1]],
11
+ [bbox[2], bbox[1]],
12
+ [bbox[2], bbox[3]],
13
+ [bbox[0], bbox[3]],
14
+ ];
15
+ }
16
+ exports.getBboxAsPolygon = getBboxAsPolygon;
17
+ /**
18
+ * Given a Polygon, calculate a bounding box that encompasses all points.
19
+ */
20
+ function getBbox(polygon) {
21
+ const allY = polygon.map((point) => point[1]);
22
+ const allX = polygon.map((point) => point[0]);
23
+ const yMin = Math.min(...allY);
24
+ const yMax = Math.max(...allY);
25
+ const xMin = Math.min(...allX);
26
+ const xMax = Math.max(...allX);
27
+ return [xMin, yMin, xMax, yMax];
28
+ }
29
+ exports.getBbox = getBbox;
30
+ /**
31
+ * Get the central point (centroid) given a list of points.
32
+ */
33
+ function getCentroid(vertices) {
34
+ const numbVertices = vertices.length;
35
+ const xSum = vertices
36
+ .map((point) => point[0])
37
+ .reduce((prev, cur) => prev + cur);
38
+ const ySum = vertices
39
+ .map((point) => point[1])
40
+ .reduce((prev, cur) => prev + cur);
41
+ return [xSum / numbVertices, ySum / numbVertices];
42
+ }
43
+ exports.getCentroid = getCentroid;
44
+ /**
45
+ * Determine if a Point is within two Y coordinates.
46
+ */
47
+ function isPointInY(centroid, yMin, yMax) {
48
+ return yMin <= centroid[1] && centroid[1] <= yMax;
49
+ }
50
+ exports.isPointInY = isPointInY;
51
+ /**
52
+ * Get the maximum and minimum Y coordinates in a given list of Points.
53
+ */
54
+ function getMinMaxY(vertices) {
55
+ const points = vertices.map((point) => point[1]);
56
+ return { min: Math.min(...points), max: Math.max(...points) };
57
+ }
58
+ exports.getMinMaxY = getMinMaxY;
59
+ /**
60
+ * Determine if a Point is within a Polygon's Y axis.
61
+ */
62
+ function isPointInPolygonY(centroid, polygon) {
63
+ const yCoords = getMinMaxY(polygon);
64
+ return isPointInY(centroid, yCoords.min, yCoords.max);
65
+ }
66
+ exports.isPointInPolygonY = isPointInPolygonY;
67
+ /**
68
+ * Calculate the relative Y position of a Polygon.
69
+ *
70
+ * Can be used to order (sort) words in the same column.
71
+ */
72
+ function relativeY(polygon) {
73
+ const sum = polygon
74
+ .map((point) => point[1])
75
+ .reduce((prev, cur) => prev + cur);
76
+ return polygon.length * sum;
77
+ }
78
+ exports.relativeY = relativeY;
79
+ /**
80
+ * Determine if a Point is within two X coordinates.
81
+ */
82
+ function isPointInX(centroid, xMin, xMax) {
83
+ return xMin <= centroid[0] && centroid[0] <= xMax;
84
+ }
85
+ exports.isPointInX = isPointInX;
86
+ /**
87
+ * Get the maximum and minimum X coordinates in a given list of Points.
88
+ */
89
+ function getMinMaxX(vertices) {
90
+ const points = vertices.map((point) => point[0]);
91
+ return { min: Math.min(...points), max: Math.max(...points) };
92
+ }
93
+ exports.getMinMaxX = getMinMaxX;
94
+ /**
95
+ * Determine if a Point is within a Polygon's X axis.
96
+ */
97
+ function isPointInPolygonX(centroid, polygon) {
98
+ const xCoords = getMinMaxX(polygon);
99
+ return isPointInX(centroid, xCoords.min, xCoords.max);
100
+ }
101
+ exports.isPointInPolygonX = isPointInPolygonX;
102
+ /**
103
+ * Calculate the relative X position of a Polygon.
104
+ *
105
+ * Can be used to order (sort) words in the same line.
106
+ */
107
+ function relativeX(polygon) {
108
+ const sum = polygon
109
+ .map((point) => point[0])
110
+ .reduce((prev, cur) => prev + cur);
111
+ return polygon.length * sum;
112
+ }
113
+ exports.relativeX = relativeX;
@@ -0,0 +1,2 @@
1
+ export { Response, FinancialDocResponse, InvoiceResponse, PassportResponse, ReceiptResponse, CustomResponse, } from "./api";
2
+ export { Client } from "./client";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Client = exports.CustomResponse = exports.ReceiptResponse = exports.PassportResponse = exports.InvoiceResponse = exports.FinancialDocResponse = exports.Response = void 0;
4
+ var api_1 = require("./api");
5
+ Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return api_1.Response; } });
6
+ Object.defineProperty(exports, "FinancialDocResponse", { enumerable: true, get: function () { return api_1.FinancialDocResponse; } });
7
+ Object.defineProperty(exports, "InvoiceResponse", { enumerable: true, get: function () { return api_1.InvoiceResponse; } });
8
+ Object.defineProperty(exports, "PassportResponse", { enumerable: true, get: function () { return api_1.PassportResponse; } });
9
+ Object.defineProperty(exports, "ReceiptResponse", { enumerable: true, get: function () { return api_1.ReceiptResponse; } });
10
+ Object.defineProperty(exports, "CustomResponse", { enumerable: true, get: function () { return api_1.CustomResponse; } });
11
+ var client_1 = require("./client");
12
+ Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
@@ -0,0 +1,69 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { ReadStream } from "fs";
4
+ import { Buffer } from "node:buffer";
5
+ interface InputProps {
6
+ inputType: string;
7
+ }
8
+ export declare const INPUT_TYPE_STREAM = "stream";
9
+ export declare const INPUT_TYPE_BASE64 = "base64";
10
+ export declare const INPUT_TYPE_BYTES = "bytes";
11
+ export declare const INPUT_TYPE_PATH = "path";
12
+ export declare class Input {
13
+ MAX_DOC_PAGES: number;
14
+ inputType: string;
15
+ filename: string;
16
+ filepath?: string;
17
+ mimeType: string;
18
+ fileObject: Buffer;
19
+ /**
20
+ * @param {String} inputType - the type of input used in file ("base64", "path", "dummy").
21
+ * NB: dummy is only used for tests purposes
22
+ * @param {Boolean} cutPages
23
+ * NB: Because of async calls, init() should be called after creating the object
24
+ */
25
+ constructor({ inputType }: InputProps);
26
+ init(): Promise<void>;
27
+ isPdf(): boolean;
28
+ checkMimetype(): Promise<string>;
29
+ countPages(): Promise<number>;
30
+ /** Merge PDF pages */
31
+ cutPdf(): Promise<void>;
32
+ }
33
+ interface PathInputProps {
34
+ inputPath: string;
35
+ }
36
+ export declare class PathInput extends Input {
37
+ readonly inputPath: string;
38
+ constructor({ inputPath }: PathInputProps);
39
+ init(): Promise<void>;
40
+ }
41
+ interface Base64InputProps {
42
+ inputString: string;
43
+ filename: string;
44
+ }
45
+ export declare class Base64Input extends Input {
46
+ private inputString;
47
+ constructor({ inputString, filename }: Base64InputProps);
48
+ init(): Promise<void>;
49
+ }
50
+ interface StreamInputProps {
51
+ inputStream: ReadStream;
52
+ filename: string;
53
+ }
54
+ export declare class StreamInput extends Input {
55
+ private inputStream;
56
+ constructor({ inputStream, filename }: StreamInputProps);
57
+ init(): Promise<void>;
58
+ stream2buffer(stream: ReadStream): Promise<Buffer>;
59
+ }
60
+ interface BytesInputProps {
61
+ inputBytes: string;
62
+ filename: string;
63
+ }
64
+ export declare class BytesInput extends Input {
65
+ private inputBytes;
66
+ constructor({ inputBytes, filename }: BytesInputProps);
67
+ init(): Promise<void>;
68
+ }
69
+ export {};