mindee 2.0.0 → 2.0.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 (69) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/README.md +15 -11
  3. package/bin/mindee.d.ts +2 -0
  4. package/bin/mindee.js +5 -0
  5. package/package.json +68 -68
  6. package/{dist/src → src}/api/endpoint.d.ts +0 -0
  7. package/{dist/src → src}/api/endpoint.js +5 -2
  8. package/{dist/src → src}/api/index.d.ts +0 -0
  9. package/{dist/src → src}/api/index.js +0 -0
  10. package/{dist/src → src}/api/response.d.ts +0 -0
  11. package/{dist/src → src}/api/response.js +0 -0
  12. package/{dist/src → src}/cli.d.ts +0 -0
  13. package/src/cli.js +114 -0
  14. package/{dist/src → src}/client.d.ts +0 -0
  15. package/{dist/src → src}/client.js +35 -46
  16. package/{dist/src → src}/constants.d.ts +0 -0
  17. package/{dist/src → src}/constants.js +0 -0
  18. package/{dist/src → src}/documents/custom.d.ts +0 -0
  19. package/{dist/src → src}/documents/custom.js +0 -0
  20. package/{dist/src → src}/documents/document.d.ts +0 -0
  21. package/{dist/src → src}/documents/document.js +5 -6
  22. package/{dist/src → src}/documents/documentConfig.d.ts +0 -0
  23. package/{dist/src → src}/documents/documentConfig.js +21 -38
  24. package/{dist/src → src}/documents/financialDocument.d.ts +0 -0
  25. package/{dist/src → src}/documents/financialDocument.js +4 -1
  26. package/{dist/src → src}/documents/index.d.ts +0 -0
  27. package/{dist/src → src}/documents/index.js +0 -0
  28. package/{dist/src → src}/documents/invoice.d.ts +0 -0
  29. package/{dist/src → src}/documents/invoice.js +0 -0
  30. package/{dist/src → src}/documents/passport.d.ts +0 -0
  31. package/{dist/src → src}/documents/passport.js +0 -0
  32. package/{dist/src → src}/documents/receipt.d.ts +0 -0
  33. package/{dist/src → src}/documents/receipt.js +0 -0
  34. package/{dist/src → src}/errors/handler.d.ts +0 -0
  35. package/{dist/src → src}/errors/handler.js +0 -0
  36. package/{dist/src → src}/fields/amount.d.ts +0 -0
  37. package/{dist/src → src}/fields/amount.js +0 -0
  38. package/{dist/src → src}/fields/companyRegistration.d.ts +0 -0
  39. package/{dist/src → src}/fields/companyRegistration.js +0 -0
  40. package/{dist/src → src}/fields/customDocs.d.ts +2 -2
  41. package/{dist/src → src}/fields/customDocs.js +4 -4
  42. package/{dist/src → src}/fields/date.d.ts +0 -0
  43. package/{dist/src → src}/fields/date.js +0 -0
  44. package/{dist/src → src}/fields/field.d.ts +0 -0
  45. package/{dist/src → src}/fields/field.js +0 -0
  46. package/{dist/src → src}/fields/fullText.d.ts +0 -0
  47. package/{dist/src → src}/fields/fullText.js +0 -0
  48. package/{dist/src → src}/fields/index.d.ts +1 -1
  49. package/{dist/src → src}/fields/index.js +2 -2
  50. package/{dist/src → src}/fields/locale.d.ts +0 -0
  51. package/{dist/src → src}/fields/locale.js +0 -0
  52. package/{dist/src → src}/fields/orientation.d.ts +0 -0
  53. package/{dist/src → src}/fields/orientation.js +0 -0
  54. package/{dist/src → src}/fields/paymentDetails.d.ts +0 -0
  55. package/{dist/src → src}/fields/paymentDetails.js +0 -0
  56. package/{dist/src → src}/fields/tax.d.ts +0 -0
  57. package/{dist/src → src}/fields/tax.js +1 -2
  58. package/{dist/src → src}/geometry.d.ts +0 -0
  59. package/{dist/src → src}/geometry.js +0 -0
  60. package/{dist/src → src}/index.d.ts +0 -0
  61. package/{dist/src → src}/index.js +0 -0
  62. package/{dist/src → src}/inputs.d.ts +0 -0
  63. package/src/inputs.js +196 -0
  64. package/{dist/src → src}/logger.d.ts +0 -0
  65. package/{dist/src → src}/logger.js +0 -0
  66. package/bin/mindee +0 -3
  67. package/dist/package.json +0 -70
  68. package/dist/src/cli.js +0 -117
  69. package/dist/src/inputs.js +0 -223
package/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
- ## v2.0.0 (2022-08-26)
3
+ ## v2.0.1 - 2022-10-13
4
+ ### Fixes
5
+ * :bug: Fix for packaging and documentation related to commonJS imports
6
+
7
+ ## v2.0.0 - 2022-08-26
4
8
  ### Note
5
9
  This is a complete rewrite in TypeScript!
6
10
 
package/README.md CHANGED
@@ -13,31 +13,35 @@ npm install mindee
13
13
 
14
14
  Finally, Node.js away!
15
15
 
16
- ### Off-the-Shelf Document
16
+ ### Off-the-Shelf Documents
17
17
 
18
- ```ts
19
- import { Client, InvoiceResponse } from "mindee";
18
+ ```js
19
+ const mindee = require("mindee");
20
+ // for TS or modules:
21
+ // import * as mindee from "mindee";
20
22
 
21
23
  // Init a new client
22
- const mindeeClient = new Client({apiKey: "my-api-key"});
24
+ const mindeeClient = new mindee.Client({apiKey: "my-api-key"});
23
25
 
24
26
  // Load a file from disk and parse it
25
27
  const invoiceResponse = mindeeClient.docFromPath("/path/to/the/invoice.pdf")
26
- .parse(InvoiceResponse);
28
+ .parse(mindee.InvoiceResponse);
27
29
 
28
30
  // Print a brief summary of the parsed data
29
31
  invoiceResponse.then((resp) => {
30
- console.log(resp.document);
32
+ console.log(resp.document);
31
33
  });
32
34
  ```
33
35
 
34
- ### Custom Document (API Builder)
36
+ ### Custom Documents (API Builder)
35
37
 
36
- ```ts
37
- import { Client, CustomResponse } from "mindee";
38
+ ```js
39
+ const mindee = require("mindee");
40
+ // for TS or modules:
41
+ // import * as mindee from "mindee";
38
42
 
39
43
  // Init a new client and add your document endpoint
40
- const mindeeClient = new Client({apiKey: "my-api-key"})
44
+ const mindeeClient = new mindee.Client({apiKey: "my-api-key"})
41
45
  .addEndpoint({
42
46
  accountName: "john",
43
47
  documentType: "wsnine",
@@ -45,7 +49,7 @@ const mindeeClient = new Client({apiKey: "my-api-key"})
45
49
 
46
50
  // Load a file from disk and parse it
47
51
  const customResponse = mindeeClient.docFromPath("/path/to/the/wsnine.jpg")
48
- .parse(CustomResponse, {docType: "wsnine"});
52
+ .parse(mindee.CustomResponse, {docType: "wsnine"});
49
53
 
50
54
  // Print a brief summary of the parsed data
51
55
  customResponse.then((resp) => {
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/bin/mindee.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const cli_1 = require("../src/cli");
5
+ (0, cli_1.cli)();
package/package.json CHANGED
@@ -1,70 +1,70 @@
1
1
  {
2
- "name": "mindee",
3
- "version": "2.0.0",
4
- "description": "Mindee Client Library for Node.js",
5
- "main": "src/index.js",
6
- "license": "MIT",
7
- "scripts": {
8
- "build": "tsc --build",
9
- "clean": "rm -rf ./dist",
10
- "test": "mocha 'tests/**/*.spec.ts'",
11
- "lint-fix": "eslint 'src/**/*.ts' --fix",
12
- "lint": "eslint 'src/**/*.ts' --report-unused-disable-directives && echo 'Your .ts files look good.'",
13
- "docs": "jsdoc -r src -d docs"
14
- },
15
- "files": [
16
- "dist/",
17
- "bin/",
18
- "LICENSE",
19
- "README.md",
20
- "CHANGELOG.md"
21
- ],
22
- "engines": {
23
- "node": ">= 14.0.0"
24
- },
25
- "repository": {
26
- "type": "git",
27
- "url": "git+https://github.com/mindee/mindee-api-nodejs.git"
28
- },
29
- "author": {
30
- "name": "Mindee",
31
- "email": "devrel@mindee.com",
32
- "url": "https://mindee.com/"
33
- },
34
- "bugs": {
35
- "url": "https://github.com/mindee/mindee-api-nodejs/issues"
36
- },
37
- "homepage": "https://mindee.com/",
38
- "devDependencies": {
39
- "@tsconfig/node16": "^1.0.3",
40
- "@types/chai": "^4.3.1",
41
- "@types/mocha": "^9.1.1",
42
- "@types/node": "^17.0.38",
43
- "@typescript-eslint/eslint-plugin": "^5.30.0",
44
- "@typescript-eslint/parser": "^5.30.0",
45
- "chai": "^4.3.6",
46
- "eslint": "^8.18.0",
47
- "eslint-config-prettier": "^8.5.0",
48
- "eslint-plugin-prettier": "^4.1.0",
49
- "jsdoc": "^3.6.10",
50
- "mocha": "^10.0.0",
51
- "prettier": "^2.7.1",
52
- "ts-node": "^10.8.1",
53
- "typescript": "^4.7.4"
54
- },
55
- "dependencies": {
56
- "commander": "^9.4.0",
57
- "file-type": "^16.5.4",
58
- "form-data": "^3.0.1",
59
- "mrz": "^3.1.4",
60
- "pdf-lib": "^1.17.1"
61
- },
62
- "keywords": [
63
- "typescript",
64
- "mindee",
65
- "api",
66
- "client",
67
- "client library",
68
- "nodejs"
69
- ]
2
+ "name": "mindee",
3
+ "version": "2.0.1",
4
+ "description": "Mindee Client Library for Node.js",
5
+ "main": "src/index.js",
6
+ "bin": "bin/mindee.js",
7
+ "license": "MIT",
8
+ "scripts": {
9
+ "build": "tsc --build && cp LICENSE README.md CHANGELOG.md ./dist",
10
+ "clean": "rm -rf ./dist",
11
+ "test": "mocha 'tests/**/*.spec.ts'",
12
+ "lint-fix": "eslint '**/*.ts' --fix",
13
+ "lint": "eslint '**/*.ts' --report-unused-disable-directives && echo 'Your .ts files look good.'",
14
+ "docs": "jsdoc -r src -d docs"
15
+ },
16
+ "files": [
17
+ "src/*",
18
+ "bin/*",
19
+ "LICENSE",
20
+ "README.md",
21
+ "CHANGELOG.md"
22
+ ],
23
+ "engines": {
24
+ "node": ">= 14"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/mindee/mindee-api-nodejs.git"
29
+ },
30
+ "author": {
31
+ "name": "Mindee",
32
+ "email": "devrel@mindee.com",
33
+ "url": "https://mindee.com/"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/mindee/mindee-api-nodejs/issues"
37
+ },
38
+ "homepage": "https://mindee.com/",
39
+ "devDependencies": {
40
+ "@types/chai": "^4.3.1",
41
+ "@types/mocha": "^9.1.1",
42
+ "@types/node": "^17.0.38",
43
+ "@typescript-eslint/eslint-plugin": "^5.30.0",
44
+ "@typescript-eslint/parser": "^5.30.0",
45
+ "chai": "^4.3.6",
46
+ "eslint": "^8.18.0",
47
+ "eslint-config-prettier": "^8.5.0",
48
+ "eslint-plugin-prettier": "^4.1.0",
49
+ "jsdoc": "^3.6.10",
50
+ "mocha": "^10.0.0",
51
+ "prettier": "^2.7.1",
52
+ "ts-node": "^10.8.1",
53
+ "typescript": "^4.7.4"
54
+ },
55
+ "dependencies": {
56
+ "commander": "^9.4.0",
57
+ "file-type": "^16.5.4",
58
+ "form-data": "^3.0.1",
59
+ "mrz": "^3.1.4",
60
+ "pdf-lib": "^1.17.1"
61
+ },
62
+ "keywords": [
63
+ "typescript",
64
+ "mindee",
65
+ "api",
66
+ "client",
67
+ "client library",
68
+ "nodejs"
69
+ ]
70
70
  }
File without changes
@@ -65,7 +65,7 @@ class Endpoint {
65
65
  if (includeWords) {
66
66
  form.append("include_mvision", "true");
67
67
  }
68
- headers = Object.assign(Object.assign({}, headers), form.getHeaders());
68
+ headers = { ...headers, ...form.getHeaders() };
69
69
  }
70
70
  else if (input.inputType === "base64") {
71
71
  const bodyObj = { document: input.fileObject };
@@ -93,7 +93,10 @@ class Endpoint {
93
93
  });
94
94
  res.on("end", function () {
95
95
  try {
96
- resolve(Object.assign(Object.assign({}, res), { data: JSON.parse(responseBody) }));
96
+ resolve({
97
+ ...res,
98
+ data: JSON.parse(responseBody),
99
+ });
97
100
  }
98
101
  catch (error) {
99
102
  reject(error);
File without changes
File without changes
File without changes
File without changes
File without changes
package/src/cli.js ADDED
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cli = void 0;
4
+ const commander_1 = require("commander");
5
+ const documents_1 = require("./documents");
6
+ const api_1 = require("./api");
7
+ const client_1 = require("./client");
8
+ const constants_1 = require("./constants");
9
+ const program = new commander_1.Command();
10
+ const COMMAND_INVOICE = "invoice";
11
+ const COMMAND_RECEIPT = "receipt";
12
+ const COMMAND_PASSPORT = "passport";
13
+ const COMMAND_FINANCIAL = "financial";
14
+ const COMMAND_CUSTOM = "custom";
15
+ const CLI_COMMAND_CONFIG = new Map([
16
+ [COMMAND_INVOICE, constants_1.ProductConfigs.getByDocType(documents_1.DOC_TYPE_INVOICE)],
17
+ [COMMAND_RECEIPT, constants_1.ProductConfigs.getByDocType(documents_1.DOC_TYPE_RECEIPT)],
18
+ [COMMAND_PASSPORT, constants_1.ProductConfigs.getByDocType(documents_1.DOC_TYPE_PASSPORT)],
19
+ [COMMAND_FINANCIAL, constants_1.ProductConfigs.getByDocType(documents_1.DOC_TYPE_FINANCIAL)],
20
+ [COMMAND_CUSTOM, constants_1.ProductConfigs.getByDocType(documents_1.DOC_TYPE_CUSTOM)],
21
+ ]);
22
+ async function predictCall(command, inputPath, options) {
23
+ const conf = CLI_COMMAND_CONFIG.get(command);
24
+ if (conf === undefined) {
25
+ throw new Error(`Invalid document type ${command}`);
26
+ }
27
+ const mindeeClient = new client_1.Client({
28
+ apiKey: options.apiKey,
29
+ debug: options.debug,
30
+ });
31
+ if (command === COMMAND_CUSTOM) {
32
+ mindeeClient.addEndpoint({
33
+ accountName: options.user,
34
+ documentType: options.documentType,
35
+ });
36
+ }
37
+ const doc = mindeeClient.docFromPath(inputPath);
38
+ const params = {
39
+ docType: command === COMMAND_CUSTOM ? options.documentType : conf.docType,
40
+ username: command === COMMAND_CUSTOM ? options.user : api_1.STANDARD_API_OWNER,
41
+ cutPages: options.cutPages,
42
+ fullText: options.fullText,
43
+ };
44
+ // Tried setting the response by using the responseClass property in constants.PRODUCTS_CONFIG
45
+ // This compiled, but threw an exception:
46
+ // TypeError: responseType is not a constructor
47
+ //
48
+ // So using a switch to explicitly set the response class parameter. Ugly, but works.
49
+ // Improvements welcome!
50
+ let response;
51
+ switch (command) {
52
+ case COMMAND_INVOICE:
53
+ response = await doc.parse(api_1.InvoiceResponse, params);
54
+ break;
55
+ case COMMAND_RECEIPT:
56
+ response = await doc.parse(api_1.ReceiptResponse, params);
57
+ break;
58
+ case COMMAND_FINANCIAL:
59
+ response = await doc.parse(api_1.FinancialDocResponse, params);
60
+ break;
61
+ case COMMAND_PASSPORT:
62
+ response = await doc.parse(api_1.PassportResponse, params);
63
+ break;
64
+ case COMMAND_CUSTOM:
65
+ response = await doc.parse(api_1.CustomResponse, params);
66
+ break;
67
+ default:
68
+ throw `Unhandled command: ${command}`;
69
+ }
70
+ if (response.document) {
71
+ console.log(`\n${response.document}`);
72
+ }
73
+ }
74
+ function cli() {
75
+ program.name("mindee");
76
+ program.option("-d, --debug", "high verbosity mode");
77
+ CLI_COMMAND_CONFIG.forEach((info, name) => {
78
+ const prog = program.command(name);
79
+ prog.description(info.description);
80
+ prog.option("-k, --api-key <api_key>", "API key for document endpoint");
81
+ prog.option("-C, --no-cut-pages", "Don't cut document pages");
82
+ if (info.fullText) {
83
+ prog.option("-t, --full-text", "Include full document text in response");
84
+ }
85
+ if (name === COMMAND_CUSTOM) {
86
+ prog.requiredOption("-u, --user <username>", "API account name for the endpoint");
87
+ prog.option("-v, --version <version>", "API account name for the endpoint");
88
+ prog.argument("<endpoint_name>", "API endpoint name");
89
+ }
90
+ prog.argument("<input_path>", "Full path to the file");
91
+ if (name === COMMAND_CUSTOM) {
92
+ prog.action((endpointName, inputPath, options, command) => {
93
+ const allOptions = {
94
+ ...program.opts(),
95
+ ...options,
96
+ documentType: endpointName,
97
+ };
98
+ predictCall(command.name(), inputPath, allOptions);
99
+ });
100
+ }
101
+ else {
102
+ prog.action((inputPath, options, command) => {
103
+ const allOptions = {
104
+ ...program.opts(),
105
+ ...options,
106
+ endpointName: undefined,
107
+ };
108
+ predictCall(command.name(), inputPath, allOptions);
109
+ });
110
+ }
111
+ });
112
+ program.parse(process.argv);
113
+ }
114
+ exports.cli = cli;
File without changes
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.Client = void 0;
13
4
  const inputs_1 = require("./inputs");
@@ -22,45 +13,43 @@ class DocumentClient {
22
13
  this.inputDoc = inputDoc;
23
14
  this.docConfigs = docConfigs;
24
15
  }
25
- parse(responseClass, params = {
16
+ async parse(responseClass, params = {
26
17
  docType: "",
27
18
  username: "",
28
19
  cutPages: true,
29
20
  fullText: false,
30
21
  }) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- // seems like there should be a better way of doing this
33
- const fullText = (params === null || params === void 0 ? void 0 : params.fullText) !== undefined ? params.fullText : false;
34
- const cutPages = (params === null || params === void 0 ? void 0 : params.cutPages) !== undefined ? params.cutPages : true;
35
- const docType = params.docType === undefined || params.docType === ""
36
- ? this.getDocType(responseClass.name)
37
- : params.docType;
38
- const found = [];
39
- this.docConfigs.forEach((config, configKey) => {
40
- if (configKey[1] === docType) {
41
- found.push(configKey);
42
- }
43
- });
44
- if (found.length === 0) {
45
- throw `Document type not configured: '${docType}'`;
22
+ // seems like there should be a better way of doing this
23
+ const fullText = params?.fullText !== undefined ? params.fullText : false;
24
+ const cutPages = params?.cutPages !== undefined ? params.cutPages : true;
25
+ const docType = params.docType === undefined || params.docType === ""
26
+ ? this.getDocType(responseClass.name)
27
+ : params.docType;
28
+ const found = [];
29
+ this.docConfigs.forEach((config, configKey) => {
30
+ if (configKey[1] === docType) {
31
+ found.push(configKey);
46
32
  }
47
- let configKey = [];
48
- if (found.length === 1) {
49
- configKey = found[0];
50
- }
51
- else if (params.username) {
52
- configKey = [params.username, docType];
53
- }
54
- const docConfig = this.docConfigs.get(configKey);
55
- if (docConfig === undefined) {
56
- // TODO: raise error printing all usernames
57
- throw `Couldn't find the config '${configKey}'`;
58
- }
59
- return yield docConfig.predict(responseClass, {
60
- inputDoc: this.inputDoc,
61
- includeWords: fullText,
62
- cutPages: cutPages,
63
- });
33
+ });
34
+ if (found.length === 0) {
35
+ throw `Document type not configured: '${docType}'`;
36
+ }
37
+ let configKey = [];
38
+ if (found.length === 1) {
39
+ configKey = found[0];
40
+ }
41
+ else if (params.username) {
42
+ configKey = [params.username, docType];
43
+ }
44
+ const docConfig = this.docConfigs.get(configKey);
45
+ if (docConfig === undefined) {
46
+ // TODO: raise error printing all usernames
47
+ throw `Couldn't find the config '${configKey}'`;
48
+ }
49
+ return await docConfig.predict(responseClass, {
50
+ inputDoc: this.inputDoc,
51
+ includeWords: fullText,
52
+ cutPages: cutPages,
64
53
  });
65
54
  }
66
55
  getDocType(responseClass) {
@@ -75,13 +64,13 @@ class Client {
75
64
  * @param options
76
65
  */
77
66
  constructor(options) {
78
- const throwOnError = (options === null || options === void 0 ? void 0 : options.throwOnError) === undefined ? true : options.throwOnError;
79
- const debug = (options === null || options === void 0 ? void 0 : options.debug) === undefined ? false : options.debug;
80
- this.apiKey = (options === null || options === void 0 ? void 0 : options.apiKey) === undefined ? "" : options.apiKey;
67
+ const throwOnError = options?.throwOnError === undefined ? true : options.throwOnError;
68
+ const debug = options?.debug === undefined ? false : options.debug;
69
+ this.apiKey = options?.apiKey === undefined ? "" : options.apiKey;
81
70
  this.docConfigs = new Map();
82
71
  handler_1.errorHandler.throwOnError = throwOnError;
83
72
  logger_1.logger.level =
84
- (debug !== null && debug !== void 0 ? debug : process.env.MINDEE_DEBUG)
73
+ debug ?? process.env.MINDEE_DEBUG
85
74
  ? logger_1.LOG_LEVELS["debug"]
86
75
  : logger_1.LOG_LEVELS["warn"];
87
76
  logger_1.logger.debug("Client initialized");
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -34,19 +34,18 @@ class Document {
34
34
  * @param {Array<Document>} documents - A list of Documents
35
35
  */
36
36
  static mergePages(documents) {
37
- var _a, _b;
38
37
  const finalDocument = documents[0].clone();
39
38
  const attributes = Object.getOwnPropertyNames(finalDocument);
40
39
  for (const document of documents) {
41
40
  for (const attribute of attributes) {
42
- if (Array.isArray(document === null || document === void 0 ? void 0 : document[attribute])) {
43
- finalDocument[attribute] = ((_a = finalDocument[attribute]) === null || _a === void 0 ? void 0 : _a.length)
41
+ if (Array.isArray(document?.[attribute])) {
42
+ finalDocument[attribute] = finalDocument[attribute]?.length
44
43
  ? finalDocument[attribute]
45
- : document === null || document === void 0 ? void 0 : document[attribute];
44
+ : document?.[attribute];
46
45
  }
47
- else if (((_b = document === null || document === void 0 ? void 0 : document[attribute]) === null || _b === void 0 ? void 0 : _b.confidence) >
46
+ else if (document?.[attribute]?.confidence >
48
47
  finalDocument[attribute].confidence) {
49
- finalDocument[attribute] = document === null || document === void 0 ? void 0 : document[attribute];
48
+ finalDocument[attribute] = document?.[attribute];
50
49
  }
51
50
  }
52
51
  }
File without changes
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.CustomDocConfig = exports.PassportConfig = exports.FinancialDocConfig = exports.ReceiptConfig = exports.InvoiceConfig = exports.DocumentConfig = void 0;
13
4
  const api_1 = require("../api");
@@ -18,10 +9,8 @@ class DocumentConfig {
18
9
  this.documentType = documentType;
19
10
  this.endpoints = endpoints;
20
11
  }
21
- predictRequest(inputDoc, includeWords = false) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- return yield this.endpoints[0].predictRequest(inputDoc, includeWords);
24
- });
12
+ async predictRequest(inputDoc, includeWords = false) {
13
+ return await this.endpoints[0].predictRequest(inputDoc, includeWords);
25
14
  }
26
15
  buildResult(responseType, inputFile, response) {
27
16
  if (response.statusCode > 201) {
@@ -41,21 +30,17 @@ class DocumentConfig {
41
30
  error: false,
42
31
  });
43
32
  }
44
- predict(responseType, params) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- this.checkApiKeys();
47
- yield params.inputDoc.init();
48
- yield this.cutDocPages(params.inputDoc, params.cutPages);
49
- const response = yield this.predictRequest(params.inputDoc, params.includeWords);
50
- return this.buildResult(responseType, params.inputDoc, response);
51
- });
33
+ async predict(responseType, params) {
34
+ this.checkApiKeys();
35
+ await params.inputDoc.init();
36
+ await this.cutDocPages(params.inputDoc, params.cutPages);
37
+ const response = await this.predictRequest(params.inputDoc, params.includeWords);
38
+ return this.buildResult(responseType, params.inputDoc, response);
52
39
  }
53
- cutDocPages(inputDoc, cutPages) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- if (cutPages && inputDoc.isPdf()) {
56
- yield inputDoc.cutPdf();
57
- }
58
- });
40
+ async cutDocPages(inputDoc, cutPages) {
41
+ if (cutPages && inputDoc.isPdf()) {
42
+ await inputDoc.cutPdf();
43
+ }
59
44
  }
60
45
  checkApiKeys() {
61
46
  this.endpoints.forEach((endpoint) => {
@@ -89,17 +74,15 @@ class FinancialDocConfig extends DocumentConfig {
89
74
  ];
90
75
  super(index_1.DOC_TYPE_FINANCIAL, endpoints);
91
76
  }
92
- predictRequest(inputDoc, includeWords = false) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- let endpoint;
95
- if (inputDoc.isPdf()) {
96
- endpoint = this.endpoints[0];
97
- }
98
- else {
99
- endpoint = this.endpoints[1];
100
- }
101
- return yield endpoint.predictRequest(inputDoc, includeWords);
102
- });
77
+ async predictRequest(inputDoc, includeWords = false) {
78
+ let endpoint;
79
+ if (inputDoc.isPdf()) {
80
+ endpoint = this.endpoints[0];
81
+ }
82
+ else {
83
+ endpoint = this.endpoints[1];
84
+ }
85
+ return await endpoint.predictRequest(inputDoc, includeWords);
103
86
  }
104
87
  }
105
88
  exports.FinancialDocConfig = FinancialDocConfig;
@@ -121,7 +121,10 @@ _FinancialDocument_instances = new WeakSet(), _FinancialDocument_initFromApiPred
121
121
  const eps = 1 / (100 * totalVat);
122
122
  if (this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal &&
123
123
  reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02) {
124
- this.taxes = this.taxes.map((tax) => (Object.assign(Object.assign({}, tax), { confidence: 1.0 })));
124
+ this.taxes = this.taxes.map((tax) => ({
125
+ ...tax,
126
+ confidence: 1.0,
127
+ }));
125
128
  this.totalTax.confidence = 1.0;
126
129
  this.totalIncl.confidence = 1.0;
127
130
  return true;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes