mindee 2.0.0 → 2.1.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 (76) hide show
  1. package/CHANGELOG.md +11 -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 +4 -1
  7. package/{dist/src → src}/api/endpoint.js +20 -21
  8. package/src/api/index.d.ts +2 -0
  9. package/{dist/src → src}/api/index.js +3 -1
  10. package/{dist/src → src}/api/response.d.ts +5 -2
  11. package/{dist/src → src}/api/response.js +19 -5
  12. package/{dist/src → src}/cli.d.ts +0 -0
  13. package/src/cli.js +125 -0
  14. package/{dist/src → src}/client.d.ts +1 -0
  15. package/{dist/src → src}/client.js +39 -46
  16. package/{dist/src → src}/constants.d.ts +0 -0
  17. package/{dist/src → src}/constants.js +6 -0
  18. package/src/documents/cropper.d.ts +7 -0
  19. package/src/documents/cropper.js +31 -0
  20. package/{dist/src → src}/documents/custom.d.ts +2 -2
  21. package/{dist/src → src}/documents/custom.js +4 -4
  22. package/src/documents/document.d.ts +42 -0
  23. package/{dist/src → src}/documents/document.js +24 -14
  24. package/{dist/src → src}/documents/documentConfig.d.ts +6 -2
  25. package/{dist/src → src}/documents/documentConfig.js +29 -39
  26. package/{dist/src → src}/documents/financialDocument.d.ts +2 -9
  27. package/{dist/src → src}/documents/financialDocument.js +14 -13
  28. package/{dist/src → src}/documents/index.d.ts +3 -1
  29. package/{dist/src → src}/documents/index.js +4 -1
  30. package/{dist/src → src}/documents/invoice.d.ts +2 -9
  31. package/{dist/src → src}/documents/invoice.js +3 -15
  32. package/{dist/src → src}/documents/passport.d.ts +1 -7
  33. package/{dist/src → src}/documents/passport.js +13 -19
  34. package/src/documents/receipt.d.ts +17 -0
  35. package/{dist/src → src}/documents/receipt.js +4 -16
  36. package/{dist/src → src}/errors/handler.d.ts +0 -0
  37. package/{dist/src → src}/errors/handler.js +0 -0
  38. package/{dist/src → src}/fields/amount.d.ts +0 -0
  39. package/{dist/src → src}/fields/amount.js +0 -0
  40. package/{dist/src → src}/fields/companyRegistration.d.ts +0 -0
  41. package/{dist/src → src}/fields/companyRegistration.js +0 -0
  42. package/src/fields/cropper.d.ts +16 -0
  43. package/src/fields/cropper.js +18 -0
  44. package/{dist/src → src}/fields/customDocs.d.ts +2 -2
  45. package/{dist/src → src}/fields/customDocs.js +4 -4
  46. package/{dist/src → src}/fields/date.d.ts +0 -0
  47. package/{dist/src → src}/fields/date.js +0 -0
  48. package/{dist/src → src}/fields/field.d.ts +10 -11
  49. package/{dist/src → src}/fields/field.js +4 -3
  50. package/{dist/src → src}/fields/fullText.d.ts +0 -0
  51. package/{dist/src → src}/fields/fullText.js +0 -0
  52. package/{dist/src → src}/fields/index.d.ts +4 -4
  53. package/{dist/src → src}/fields/index.js +6 -5
  54. package/{dist/src → src}/fields/locale.d.ts +0 -0
  55. package/{dist/src → src}/fields/locale.js +0 -0
  56. package/{dist/src → src}/fields/orientation.d.ts +10 -3
  57. package/{dist/src → src}/fields/orientation.js +9 -7
  58. package/{dist/src → src}/fields/paymentDetails.d.ts +0 -0
  59. package/{dist/src → src}/fields/paymentDetails.js +0 -0
  60. package/{dist/src → src}/fields/tax.d.ts +0 -0
  61. package/{dist/src → src}/fields/tax.js +1 -2
  62. package/{dist/src → src}/geometry.d.ts +0 -0
  63. package/{dist/src → src}/geometry.js +0 -0
  64. package/{dist/src → src}/index.d.ts +1 -1
  65. package/{dist/src → src}/index.js +2 -1
  66. package/{dist/src → src}/inputs.d.ts +0 -0
  67. package/src/inputs.js +196 -0
  68. package/{dist/src → src}/logger.d.ts +0 -0
  69. package/{dist/src → src}/logger.js +0 -0
  70. package/bin/mindee +0 -3
  71. package/dist/package.json +0 -70
  72. package/dist/src/api/index.d.ts +0 -2
  73. package/dist/src/cli.js +0 -117
  74. package/dist/src/documents/document.d.ts +0 -38
  75. package/dist/src/documents/receipt.d.ts +0 -24
  76. package/dist/src/inputs.js +0 -223
package/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # CHANGELOG
2
2
 
3
- ## v2.0.0 (2022-08-26)
3
+ ## v2.1.0 - 2022-10-19
4
+ ### Changes
5
+ * :sparkles: add cropper support to predict requests
6
+ * :sparkles: add stand-alone cropper support
7
+
8
+
9
+ ## v2.0.1 - 2022-10-13
10
+ ### Fixes
11
+ * :bug: Fix for packaging and documentation related to commonJS imports
12
+
13
+ ## v2.0.0 - 2022-08-26
4
14
  ### Note
5
15
  This is a complete rewrite in TypeScript!
6
16
 
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.1.0",
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
  }
@@ -12,7 +12,7 @@ export declare class Endpoint {
12
12
  /**
13
13
  * Make a prediction request.
14
14
  */
15
- predictRequest(input: Input, includeWords?: boolean): Promise<unknown>;
15
+ predictRequest(input: Input, includeWords?: boolean, cropper?: boolean): Promise<unknown>;
16
16
  protected apiKeyFromEnv(): string;
17
17
  }
18
18
  export declare class InvoiceEndpoint extends Endpoint {
@@ -24,6 +24,9 @@ export declare class ReceiptEndpoint extends Endpoint {
24
24
  export declare class PassportEndpoint extends Endpoint {
25
25
  constructor(apiKey: string);
26
26
  }
27
+ export declare class CropperEndpoint extends Endpoint {
28
+ constructor(apiKey: string);
29
+ }
27
30
  export declare class CustomEndpoint extends Endpoint {
28
31
  constructor(documentType: string, accountName: string, version: string, apiKey: string);
29
32
  }
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.CustomEndpoint = exports.PassportEndpoint = exports.ReceiptEndpoint = exports.InvoiceEndpoint = exports.Endpoint = exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = void 0;
29
+ exports.CustomEndpoint = exports.CropperEndpoint = exports.PassportEndpoint = exports.ReceiptEndpoint = exports.InvoiceEndpoint = exports.Endpoint = exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = void 0;
30
30
  const https = __importStar(require("https"));
31
31
  const os = __importStar(require("os"));
32
32
  const package_json_1 = require("../../package.json");
@@ -49,7 +49,7 @@ class Endpoint {
49
49
  /**
50
50
  * Make a prediction request.
51
51
  */
52
- predictRequest(input, includeWords = false) {
52
+ predictRequest(input, includeWords = false, cropper = false) {
53
53
  return new Promise((resolve, reject) => {
54
54
  const form = new form_data_1.default();
55
55
  let body;
@@ -57,26 +57,16 @@ class Endpoint {
57
57
  "User-Agent": USER_AGENT,
58
58
  Authorization: `Token ${this.apiKey}`,
59
59
  };
60
- // TODO: redo this section given there should only
61
- // be a single way of reading the input doc
62
- if (["path", "stream"].includes(input.inputType)) {
63
- const fileParams = { filename: input.filename };
64
- form.append("document", input.fileObject, fileParams);
65
- if (includeWords) {
66
- form.append("include_mvision", "true");
67
- }
68
- headers = Object.assign(Object.assign({}, headers), form.getHeaders());
60
+ const uri = new url_1.URL(`${this.urlRoot}/predict`);
61
+ const fileParams = { filename: input.filename };
62
+ form.append("document", input.fileObject, fileParams);
63
+ if (includeWords) {
64
+ form.append("include_mvision", "true");
69
65
  }
70
- else if (input.inputType === "base64") {
71
- const bodyObj = { document: input.fileObject };
72
- if (includeWords) {
73
- bodyObj["include_mvision"] = "true";
74
- }
75
- body = JSON.stringify(bodyObj);
76
- headers["Content-Type"] = "application/json";
77
- headers["Content-Length"] = body.length;
66
+ if (cropper) {
67
+ uri.searchParams.append("cropper", "true");
78
68
  }
79
- const uri = new url_1.URL(`${this.urlRoot}/predict`);
69
+ headers = { ...headers, ...form.getHeaders() };
80
70
  const options = {
81
71
  method: "POST",
82
72
  headers: headers,
@@ -93,7 +83,10 @@ class Endpoint {
93
83
  });
94
84
  res.on("end", function () {
95
85
  try {
96
- resolve(Object.assign(Object.assign({}, res), { data: JSON.parse(responseBody) }));
86
+ resolve({
87
+ ...res,
88
+ data: JSON.parse(responseBody),
89
+ });
97
90
  }
98
91
  catch (error) {
99
92
  reject(error);
@@ -140,6 +133,12 @@ class PassportEndpoint extends Endpoint {
140
133
  }
141
134
  }
142
135
  exports.PassportEndpoint = PassportEndpoint;
136
+ class CropperEndpoint extends Endpoint {
137
+ constructor(apiKey) {
138
+ super(exports.STANDARD_API_OWNER, "cropper", "1", apiKey);
139
+ }
140
+ }
141
+ exports.CropperEndpoint = CropperEndpoint;
143
142
  class CustomEndpoint extends Endpoint {
144
143
  constructor(documentType, accountName, version, apiKey) {
145
144
  super(accountName, documentType, version, apiKey);
@@ -0,0 +1,2 @@
1
+ export { Response, InvoiceResponse, ReceiptResponse, FinancialDocResponse, PassportResponse, CustomResponse, CropperResponse, } from "./response";
2
+ export { Endpoint, InvoiceEndpoint, ReceiptEndpoint, PassportEndpoint, CustomEndpoint, CropperEndpoint, STANDARD_API_OWNER, API_KEY_ENVVAR_NAME, } from "./endpoint";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = exports.CustomEndpoint = exports.PassportEndpoint = exports.ReceiptEndpoint = exports.InvoiceEndpoint = exports.Endpoint = exports.CustomResponse = exports.PassportResponse = exports.FinancialDocResponse = exports.ReceiptResponse = exports.InvoiceResponse = exports.Response = void 0;
3
+ exports.API_KEY_ENVVAR_NAME = exports.STANDARD_API_OWNER = exports.CropperEndpoint = exports.CustomEndpoint = exports.PassportEndpoint = exports.ReceiptEndpoint = exports.InvoiceEndpoint = exports.Endpoint = exports.CropperResponse = exports.CustomResponse = exports.PassportResponse = exports.FinancialDocResponse = exports.ReceiptResponse = exports.InvoiceResponse = exports.Response = void 0;
4
4
  var response_1 = require("./response");
5
5
  Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return response_1.Response; } });
6
6
  Object.defineProperty(exports, "InvoiceResponse", { enumerable: true, get: function () { return response_1.InvoiceResponse; } });
@@ -8,11 +8,13 @@ Object.defineProperty(exports, "ReceiptResponse", { enumerable: true, get: funct
8
8
  Object.defineProperty(exports, "FinancialDocResponse", { enumerable: true, get: function () { return response_1.FinancialDocResponse; } });
9
9
  Object.defineProperty(exports, "PassportResponse", { enumerable: true, get: function () { return response_1.PassportResponse; } });
10
10
  Object.defineProperty(exports, "CustomResponse", { enumerable: true, get: function () { return response_1.CustomResponse; } });
11
+ Object.defineProperty(exports, "CropperResponse", { enumerable: true, get: function () { return response_1.CropperResponse; } });
11
12
  var endpoint_1 = require("./endpoint");
12
13
  Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return endpoint_1.Endpoint; } });
13
14
  Object.defineProperty(exports, "InvoiceEndpoint", { enumerable: true, get: function () { return endpoint_1.InvoiceEndpoint; } });
14
15
  Object.defineProperty(exports, "ReceiptEndpoint", { enumerable: true, get: function () { return endpoint_1.ReceiptEndpoint; } });
15
16
  Object.defineProperty(exports, "PassportEndpoint", { enumerable: true, get: function () { return endpoint_1.PassportEndpoint; } });
16
17
  Object.defineProperty(exports, "CustomEndpoint", { enumerable: true, get: function () { return endpoint_1.CustomEndpoint; } });
18
+ Object.defineProperty(exports, "CropperEndpoint", { enumerable: true, get: function () { return endpoint_1.CropperEndpoint; } });
17
19
  Object.defineProperty(exports, "STANDARD_API_OWNER", { enumerable: true, get: function () { return endpoint_1.STANDARD_API_OWNER; } });
18
20
  Object.defineProperty(exports, "API_KEY_ENVVAR_NAME", { enumerable: true, get: function () { return endpoint_1.API_KEY_ENVVAR_NAME; } });
@@ -1,4 +1,4 @@
1
- import { Document, Passport, Receipt, Invoice, FinancialDocument, CustomDocument, DocumentConstructorProps } from "../documents";
1
+ import { Document, Passport, Receipt, Invoice, FinancialDocument, CustomDocument, DocumentConstructorProps, Cropper } from "../documents";
2
2
  import { FullText } from "../fields";
3
3
  import { Input } from "../inputs";
4
4
  export interface ResponseProps {
@@ -27,7 +27,7 @@ export declare class CustomResponse extends Response<CustomDocument> {
27
27
  protected formatResponse(): void;
28
28
  }
29
29
  declare type StandardDocumentSig<DocType extends Document> = {
30
- new ({ apiPrediction, inputFile, pageId, fullText, }: DocumentConstructorProps): DocType;
30
+ new ({ prediction, inputFile, pageId, fullText, }: DocumentConstructorProps): DocType;
31
31
  };
32
32
  /**
33
33
  * Generic class for all standard (Off-the-Shelf) endpoint responses.
@@ -49,4 +49,7 @@ export declare class FinancialDocResponse extends StandardProductResponse<Financ
49
49
  export declare class PassportResponse extends StandardProductResponse<Passport> {
50
50
  constructor(params: ResponseProps);
51
51
  }
52
+ export declare class CropperResponse extends StandardProductResponse<Cropper> {
53
+ constructor(params: ResponseProps);
54
+ }
52
55
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PassportResponse = exports.FinancialDocResponse = exports.ReceiptResponse = exports.InvoiceResponse = exports.StandardProductResponse = exports.CustomResponse = exports.Response = void 0;
3
+ exports.CropperResponse = exports.PassportResponse = exports.FinancialDocResponse = exports.ReceiptResponse = exports.InvoiceResponse = exports.StandardProductResponse = exports.CustomResponse = exports.Response = void 0;
4
4
  const documents_1 = require("../documents");
5
5
  const fields_1 = require("../fields");
6
6
  /**
@@ -38,16 +38,20 @@ class CustomResponse extends Response {
38
38
  const httpDataDocument = this.httpResponse.data.document;
39
39
  httpDataDocument.inference.pages.forEach((apiPage) => {
40
40
  this.pages.push(new documents_1.CustomDocument({
41
- apiPrediction: apiPage.prediction,
41
+ prediction: apiPage.prediction,
42
+ orientation: apiPage.orientation,
43
+ extras: apiPage.extras,
42
44
  inputFile: this.inputFile,
43
45
  pageId: apiPage.id,
44
46
  documentType: this.documentType,
45
47
  }));
46
48
  });
47
49
  this.document = new documents_1.CustomDocument({
48
- apiPrediction: httpDataDocument.inference.prediction,
50
+ prediction: httpDataDocument.inference.prediction,
49
51
  inputFile: this.inputFile,
50
52
  documentType: this.documentType,
53
+ orientation: {},
54
+ extras: {},
51
55
  });
52
56
  }
53
57
  }
@@ -68,15 +72,19 @@ class StandardProductResponse extends Response {
68
72
  httpDataDocument.inference.pages.forEach((apiPage) => {
69
73
  const pageText = this.getPageText(httpDataDocument, apiPage.id);
70
74
  this.pages.push(new this.documentClass({
71
- apiPrediction: apiPage.prediction,
75
+ prediction: apiPage.prediction,
72
76
  inputFile: this.inputFile,
73
77
  pageId: apiPage.id,
78
+ orientation: apiPage.orientation,
79
+ extras: apiPage.extras,
74
80
  fullText: pageText,
75
81
  }));
76
82
  });
77
83
  this.document = new this.documentClass({
78
- apiPrediction: httpDataDocument.inference.prediction,
84
+ prediction: httpDataDocument.inference.prediction,
79
85
  inputFile: this.inputFile,
86
+ orientation: {},
87
+ extras: {},
80
88
  });
81
89
  }
82
90
  }
@@ -105,3 +113,9 @@ class PassportResponse extends StandardProductResponse {
105
113
  }
106
114
  }
107
115
  exports.PassportResponse = PassportResponse;
116
+ class CropperResponse extends StandardProductResponse {
117
+ constructor(params) {
118
+ super(documents_1.Cropper, params);
119
+ }
120
+ }
121
+ exports.CropperResponse = CropperResponse;
File without changes
package/src/cli.js ADDED
@@ -0,0 +1,125 @@
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 predictParams = {
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, predictParams);
54
+ break;
55
+ case COMMAND_RECEIPT:
56
+ response = await doc.parse(api_1.ReceiptResponse, predictParams);
57
+ break;
58
+ case COMMAND_FINANCIAL:
59
+ response = await doc.parse(api_1.FinancialDocResponse, predictParams);
60
+ break;
61
+ case COMMAND_PASSPORT:
62
+ response = await doc.parse(api_1.PassportResponse, predictParams);
63
+ break;
64
+ case COMMAND_CUSTOM:
65
+ response = await doc.parse(api_1.CustomResponse, predictParams);
66
+ break;
67
+ default:
68
+ throw `Unhandled command: ${command}`;
69
+ }
70
+ if (options.fullText) {
71
+ response.pages.forEach((page) => {
72
+ console.log(page.fullText?.toString());
73
+ });
74
+ }
75
+ if (options.pages) {
76
+ response.pages.forEach((page) => {
77
+ console.log(`\n${page}`);
78
+ });
79
+ }
80
+ if (response.document) {
81
+ console.log(`\n${response.document}`);
82
+ }
83
+ }
84
+ function cli() {
85
+ program.name("mindee");
86
+ program.option("-d, --debug", "high verbosity mode");
87
+ CLI_COMMAND_CONFIG.forEach((info, name) => {
88
+ const prog = program.command(name);
89
+ prog.description(info.description);
90
+ prog.option("-k, --api-key <api_key>", "API key for document endpoint");
91
+ prog.option("-C, --no-cut-pages", "Don't cut document pages");
92
+ prog.option("-p, --pages", "Show pages content");
93
+ if (info.fullText) {
94
+ prog.option("-t, --full-text", "Include full document text in response");
95
+ }
96
+ if (name === COMMAND_CUSTOM) {
97
+ prog.requiredOption("-u, --user <username>", "API account name for the endpoint");
98
+ prog.option("-v, --version <version>", "API account name for the endpoint");
99
+ prog.argument("<endpoint_name>", "API endpoint name");
100
+ }
101
+ prog.argument("<input_path>", "Full path to the file");
102
+ if (name === COMMAND_CUSTOM) {
103
+ prog.action((endpointName, inputPath, options, command) => {
104
+ const allOptions = {
105
+ ...program.opts(),
106
+ ...options,
107
+ documentType: endpointName,
108
+ };
109
+ predictCall(command.name(), inputPath, allOptions);
110
+ });
111
+ }
112
+ else {
113
+ prog.action((inputPath, options, command) => {
114
+ const allOptions = {
115
+ ...program.opts(),
116
+ ...options,
117
+ endpointName: undefined,
118
+ };
119
+ predictCall(command.name(), inputPath, allOptions);
120
+ });
121
+ }
122
+ });
123
+ program.parse(process.argv);
124
+ }
125
+ exports.cli = cli;
@@ -10,6 +10,7 @@ interface PredictOptions {
10
10
  username?: string;
11
11
  cutPages?: boolean;
12
12
  fullText?: boolean;
13
+ cropper?: boolean;
13
14
  }
14
15
  declare class DocumentClient {
15
16
  inputDoc: Input;