diff --git a/.eslintrc b/.eslintrc index 8b9ecc1e..7220472e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -44,4 +44,4 @@ "no-eval": "error", "no-unexpected-multiline": "off" } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 4ed0c1b7..e96ef47b 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ apiResponse.then((resp) => { console.log(resp.document.toString()); // individual pages (array) - console.log(res.document.pages); + console.log(res.document.inference.pages); }); ``` @@ -130,7 +130,7 @@ apiResponse.then((resp) => { #### Apply Cropping -To apply the `Cropper` tool provided by Mindee, set the `croper` param to `true`: +To apply the `Cropper` tool provided by Mindee, set the `cropper` param to `true`: ```js //... diff --git a/docs/code_samples/bank_account_details_v1.txt b/docs/code_samples/bank_account_details_v1.txt index ec046f3d..139db43c 100644 --- a/docs/code_samples/bank_account_details_v1.txt +++ b/docs/code_samples/bank_account_details_v1.txt @@ -16,7 +16,6 @@ const apiResponse = mindeeClient.parse( // Handle the response Promise apiResponse.then((resp) => { - // print a string summary console.log(resp.document.toString()); }); diff --git a/docs/code_samples/bank_account_details_v2.txt b/docs/code_samples/bank_account_details_v2.txt index 9646b149..7df671d6 100644 --- a/docs/code_samples/bank_account_details_v2.txt +++ b/docs/code_samples/bank_account_details_v2.txt @@ -16,7 +16,6 @@ const apiResponse = mindeeClient.parse( // Handle the response Promise apiResponse.then((resp) => { - // print a string summary console.log(resp.document.toString()); }); diff --git a/docs/code_samples/bank_check_v1.txt b/docs/code_samples/bank_check_v1.txt index e3b6545a..248ce46b 100644 --- a/docs/code_samples/bank_check_v1.txt +++ b/docs/code_samples/bank_check_v1.txt @@ -16,7 +16,6 @@ const apiResponse = mindeeClient.parse( // Handle the response Promise apiResponse.then((resp) => { - // print a string summary console.log(resp.document.toString()); }); diff --git a/docs/code_samples/carte_vitale_v1.txt b/docs/code_samples/carte_vitale_v1.txt index 68789436..2d485c5c 100644 --- a/docs/code_samples/carte_vitale_v1.txt +++ b/docs/code_samples/carte_vitale_v1.txt @@ -16,7 +16,6 @@ const apiResponse = mindeeClient.parse( // Handle the response Promise apiResponse.then((resp) => { - // print a string summary console.log(resp.document.toString()); }); diff --git a/docs/code_samples/expense_receipts_v5.txt b/docs/code_samples/expense_receipts_v5.txt index 27548333..034681d1 100644 --- a/docs/code_samples/expense_receipts_v5.txt +++ b/docs/code_samples/expense_receipts_v5.txt @@ -16,7 +16,6 @@ const apiResponse = mindeeClient.parse( // Handle the response Promise apiResponse.then((resp) => { - // print a string summary console.log(resp.document.toString()); }); diff --git a/docs/code_samples/financial_document_v1.txt b/docs/code_samples/financial_document_v1.txt index 9d5e6fcc..c588c73d 100644 --- a/docs/code_samples/financial_document_v1.txt +++ b/docs/code_samples/financial_document_v1.txt @@ -16,7 +16,6 @@ const apiResponse = mindeeClient.parse( // Handle the response Promise apiResponse.then((resp) => { - // print a string summary console.log(resp.document.toString()); }); diff --git a/docs/code_samples/idcard_fr_v1.txt b/docs/code_samples/idcard_fr_v1.txt index 6a2eddb4..22d939d9 100644 --- a/docs/code_samples/idcard_fr_v1.txt +++ b/docs/code_samples/idcard_fr_v1.txt @@ -16,7 +16,6 @@ const apiResponse = mindeeClient.parse( // Handle the response Promise apiResponse.then((resp) => { - // print a string summary console.log(resp.document.toString()); }); diff --git a/docs/code_samples/license_plates_v1.txt b/docs/code_samples/license_plates_v1.txt index 14815238..e936fd15 100644 --- a/docs/code_samples/license_plates_v1.txt +++ b/docs/code_samples/license_plates_v1.txt @@ -16,7 +16,6 @@ const apiResponse = mindeeClient.parse( // Handle the response Promise apiResponse.then((resp) => { - // print a string summary console.log(resp.document.toString()); }); diff --git a/docs/code_samples/passport_v1.txt b/docs/code_samples/passport_v1.txt index 9344eed0..ee7de04f 100644 --- a/docs/code_samples/passport_v1.txt +++ b/docs/code_samples/passport_v1.txt @@ -16,7 +16,6 @@ const apiResponse = mindeeClient.parse( // Handle the response Promise apiResponse.then((resp) => { - // print a string summary console.log(resp.document.toString()); }); diff --git a/docs/code_samples/proof_of_address_v1.txt b/docs/code_samples/proof_of_address_v1.txt index 4810a07b..34c5b52e 100644 --- a/docs/code_samples/proof_of_address_v1.txt +++ b/docs/code_samples/proof_of_address_v1.txt @@ -16,7 +16,6 @@ const apiResponse = mindeeClient.parse( // Handle the response Promise apiResponse.then((resp) => { - // print a string summary console.log(resp.document.toString()); }); diff --git a/docs/code_samples/us_driver_license_v1.txt b/docs/code_samples/us_driver_license_v1.txt deleted file mode 100644 index f53e91b9..00000000 --- a/docs/code_samples/us_driver_license_v1.txt +++ /dev/null @@ -1,22 +0,0 @@ -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.us.DriverLicenseV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - - // print a string summary - console.log(resp.document.toString()); -}); diff --git a/package-lock.json b/package-lock.json index 82f449c9..0d0944ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,10 +26,7 @@ "@typescript-eslint/parser": "^5.57.1", "chai": "^4.3.7", "eslint": "^8.32.0", - "eslint-config-prettier": "^8.6.0", - "eslint-plugin-prettier": "^4.2.1", "mocha": "^10.1.0", - "prettier": "^2.8.1", "ts-node": "^10.9.1", "typedoc": "~0.23", "typescript": "^5.0.4" @@ -996,39 +993,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint-config-prettier": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.6.0.tgz", - "integrity": "sha512-bAF0eLpLVqP5oEVUFKpMA+NnRFICwn9X8B5jrR9FcqnYBuPbqWEjTEspPWMj5ye6czoSLDweCzSo3Ko7gGrZaA==", - "dev": true, - "bin": { - "eslint-config-prettier": "bin/cli.js" - }, - "peerDependencies": { - "eslint": ">=7.0.0" - } - }, - "node_modules/eslint-plugin-prettier": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz", - "integrity": "sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ==", - "dev": true, - "dependencies": { - "prettier-linter-helpers": "^1.0.0" - }, - "engines": { - "node": ">=12.0.0" - }, - "peerDependencies": { - "eslint": ">=7.28.0", - "prettier": ">=2.0.0" - }, - "peerDependenciesMeta": { - "eslint-config-prettier": { - "optional": true - } - } - }, "node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -1159,12 +1123,6 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, - "node_modules/fast-diff": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", - "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", - "dev": true - }, "node_modules/fast-glob": { "version": "3.2.12", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", @@ -2071,33 +2029,6 @@ "node": ">= 0.8.0" } }, - "node_modules/prettier": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.1.tgz", - "integrity": "sha512-lqGoSJBQNJidqCHE80vqZJHWHRFoNYsSpP9AjFhlhi9ODCJA541svILes/+/1GM3VaL/abZi7cpFzOpdR9UPKg==", - "dev": true, - "bin": { - "prettier": "bin-prettier.js" - }, - "engines": { - "node": ">=10.13.0" - }, - "funding": { - "url": "https://github.com/prettier/prettier?sponsor=1" - } - }, - "node_modules/prettier-linter-helpers": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", - "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", - "dev": true, - "dependencies": { - "fast-diff": "^1.1.2" - }, - "engines": { - "node": ">=6.0.0" - } - }, "node_modules/punycode": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", @@ -3461,22 +3392,6 @@ } } }, - "eslint-config-prettier": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.6.0.tgz", - "integrity": "sha512-bAF0eLpLVqP5oEVUFKpMA+NnRFICwn9X8B5jrR9FcqnYBuPbqWEjTEspPWMj5ye6czoSLDweCzSo3Ko7gGrZaA==", - "dev": true, - "requires": {} - }, - "eslint-plugin-prettier": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz", - "integrity": "sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ==", - "dev": true, - "requires": { - "prettier-linter-helpers": "^1.0.0" - } - }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -3556,12 +3471,6 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, - "fast-diff": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", - "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", - "dev": true - }, "fast-glob": { "version": "3.2.12", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", @@ -4222,21 +4131,6 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, - "prettier": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.1.tgz", - "integrity": "sha512-lqGoSJBQNJidqCHE80vqZJHWHRFoNYsSpP9AjFhlhi9ODCJA541svILes/+/1GM3VaL/abZi7cpFzOpdR9UPKg==", - "dev": true - }, - "prettier-linter-helpers": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", - "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", - "dev": true, - "requires": { - "fast-diff": "^1.1.2" - } - }, "punycode": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", diff --git a/package.json b/package.json index 56171429..24d97081 100644 --- a/package.json +++ b/package.json @@ -46,10 +46,7 @@ "@typescript-eslint/parser": "^5.57.1", "chai": "^4.3.7", "eslint": "^8.32.0", - "eslint-config-prettier": "^8.6.0", - "eslint-plugin-prettier": "^4.2.1", "mocha": "^10.1.0", - "prettier": "^2.8.1", "ts-node": "^10.9.1", "typedoc": "~0.23", "typescript": "^5.0.4" diff --git a/src/cli.ts b/src/cli.ts index eb2edba8..02404de1 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -34,6 +34,16 @@ const CLI_COMMAND_CONFIG = new Map([ sync: true, }, ], + [ + "cropper", + { + displayName: "Cropper", + docClass: product.CropperV1, + fullText: false, + async: false, + sync: true, + }, + ], [ "invoice", { @@ -54,66 +64,66 @@ const CLI_COMMAND_CONFIG = new Map([ sync: false, }, ], - // [ - // "receipt", - // { - // displayName: "Expense Receipt", - // docClass: product.ReceiptV5, - // fullText: true, - // async: false, - // sync: true, - // }, - // ], - // [ - // "passport", - // { - // displayName: "Passport", - // docClass: product.PassportV1, - // fullText: false, - // async: false, - // sync: true, - // }, - // ], - // [ - // "financial", - // { - // displayName: "Financial Document", - // docClass: product.FinancialDocumentV1, - // fullText: true, - // async: false, - // sync: true, - // }, - // ], - // [ - // "fr-id-card", - // { - // displayName: "FR ID Card", - // docClass: product.IdCardV1, - // fullText: false, - // async: false, - // sync: true, - // }, - // ], - // [ - // "fr-bank-account-details", - // { - // displayName: "FR Bank Account Details", - // docClass: product.fr.BankAccountDetailsV1, - // fullText: false, - // async: false, - // sync: true, - // }, - // ], - // [ - // "fr-carte-vitale", - // { - // displayName: "FR Carte Vitale", - // docClass: product.fr.CarteVitaleV1, - // fullText: false, - // async: false, - // sync: true, - // }, - // ], + [ + "receipt", + { + displayName: "Expense Receipt", + docClass: product.ReceiptV5, + fullText: true, + async: false, + sync: true, + }, + ], + [ + "passport", + { + displayName: "Passport", + docClass: product.PassportV1, + fullText: false, + async: false, + sync: true, + }, + ], + [ + "financial", + { + displayName: "Financial Document", + docClass: product.FinancialDocumentV1, + fullText: true, + async: false, + sync: true, + }, + ], + [ + "fr-id-card", + { + displayName: "FR ID Card", + docClass: product.fr.IdCardV1, + fullText: false, + async: false, + sync: true, + }, + ], + [ + "fr-bank-account-details", + { + displayName: "FR Bank Account Details", + docClass: product.fr.BankAccountDetailsV2, + fullText: false, + async: false, + sync: true, + }, + ], + [ + "fr-carte-vitale", + { + displayName: "FR Carte Vitale", + docClass: product.fr.CarteVitaleV1, + fullText: false, + async: false, + sync: true, + }, + ], [ "eu-license-plate", { @@ -124,16 +134,16 @@ const CLI_COMMAND_CONFIG = new Map([ sync: true, }, ], - // [ - // "us-bank-check", - // { - // displayName: "US Bank Check", - // docClass: product.us.BankCheckV1, - // fullText: false, - // async: false, - // sync: true, - // }, - // ] + [ + "us-bank-check", + { + displayName: "US Bank Check", + docClass: product.us.BankCheckV1, + fullText: false, + async: false, + sync: true, + }, + ], ]); // @@ -183,7 +193,7 @@ async function callParse(command: string, inputPath: string, options: any) { const pageOptions = getPageOptions(options); const inputSource = mindeeClient.docFromPath(inputPath); let response; - if (COMMAND_CUSTOM) { + if (command === COMMAND_CUSTOM) { const customEndpoint = mindeeClient.createEndpoint( options.endpoint, options.account, @@ -213,7 +223,7 @@ async function callEnqueue(command: string, inputPath: string, options: any) { const inputSource = mindeeClient.docFromPath(inputPath); let response; - if (COMMAND_CUSTOM) { + if (command === COMMAND_CUSTOM) { const customEndpoint = mindeeClient.createEndpoint( options.endpoint, options.account, diff --git a/src/parsing/common/page.ts b/src/parsing/common/page.ts index 00798175..ef718e8a 100644 --- a/src/parsing/common/page.ts +++ b/src/parsing/common/page.ts @@ -5,15 +5,15 @@ import { Prediction } from "./prediction"; import { StringDict } from "./stringDict"; export class Page { - id?: number; + id: number; orientation?: OrientationField; prediction: T; extras?: Extras; constructor( - predictionType: new (rawPrediction: StringDict, pageId?: number) => T, + predictionType: new (rawPrediction: StringDict, pageId: number) => T, rawPrediction: StringDict, - pageId?: number, + pageId: number, orientation?: StringDict ) { if (pageId !== undefined && orientation !== undefined) { @@ -24,7 +24,7 @@ export class Page { } else { orientation = undefined; } - this.id = pageId ?? undefined; + this.id = pageId; this.prediction = new predictionType(rawPrediction["prediction"], pageId); if ( rawPrediction["extras"] && diff --git a/src/product/eu/licensePlate/licensePlateV1.ts b/src/product/eu/licensePlate/licensePlateV1.ts index 99980373..4c74943c 100644 --- a/src/product/eu/licensePlate/licensePlateV1.ts +++ b/src/product/eu/licensePlate/licensePlateV1.ts @@ -20,4 +20,4 @@ export class LicensePlateV1 extends Inference { ) ); } -} \ No newline at end of file +} diff --git a/src/product/financialDocument/financialDocumentV1.ts b/src/product/financialDocument/financialDocumentV1.ts index 72b253d2..158b9ff0 100644 --- a/src/product/financialDocument/financialDocumentV1.ts +++ b/src/product/financialDocument/financialDocumentV1.ts @@ -20,4 +20,4 @@ export class FinancialDocumentV1 extends Inference { ) ); } -} \ No newline at end of file +} diff --git a/src/product/financialDocument/financialDocumentV1Document.ts b/src/product/financialDocument/financialDocumentV1Document.ts index d572b47c..91c7eea6 100644 --- a/src/product/financialDocument/financialDocumentV1Document.ts +++ b/src/product/financialDocument/financialDocumentV1Document.ts @@ -5,14 +5,14 @@ import { } from "../../parsing/common"; import { FinancialDocumentV1LineItem } from "./financialDocumentV1LineItem"; import { - DateField, - StringField, + AmountField, + ClassificationField, CompanyRegistrationField, - Taxes, + DateField, LocaleField, PaymentDetailsField, - ClassificationField, - AmountField, + StringField, + Taxes, } from "../../parsing/standard"; /** diff --git a/src/product/fr/bankAccountDetails/bankAccountDetailsV1.ts b/src/product/fr/bankAccountDetails/bankAccountDetailsV1.ts index c55e1f12..a91145e3 100644 --- a/src/product/fr/bankAccountDetails/bankAccountDetailsV1.ts +++ b/src/product/fr/bankAccountDetails/bankAccountDetailsV1.ts @@ -20,4 +20,4 @@ export class BankAccountDetailsV1 extends Inference { ) ); } -} \ No newline at end of file +} diff --git a/src/product/fr/bankAccountDetails/bankAccountDetailsV2.ts b/src/product/fr/bankAccountDetails/bankAccountDetailsV2.ts index be09093c..637706f8 100644 --- a/src/product/fr/bankAccountDetails/bankAccountDetailsV2.ts +++ b/src/product/fr/bankAccountDetails/bankAccountDetailsV2.ts @@ -20,4 +20,4 @@ export class BankAccountDetailsV2 extends Inference { ) ); } -} \ No newline at end of file +} diff --git a/src/product/fr/carteVitale/carteVitaleV1.ts b/src/product/fr/carteVitale/carteVitaleV1.ts index 2ce488b2..dec86534 100644 --- a/src/product/fr/carteVitale/carteVitaleV1.ts +++ b/src/product/fr/carteVitale/carteVitaleV1.ts @@ -20,4 +20,4 @@ export class CarteVitaleV1 extends Inference { ) ); } -} \ No newline at end of file +} diff --git a/src/product/fr/carteVitale/carteVitaleV1Document.ts b/src/product/fr/carteVitale/carteVitaleV1Document.ts index baa8c045..819d4dd7 100644 --- a/src/product/fr/carteVitale/carteVitaleV1Document.ts +++ b/src/product/fr/carteVitale/carteVitaleV1Document.ts @@ -3,7 +3,7 @@ import { StringDict, cleanOutString, } from "../../../parsing/common"; -import { StringField, DateField } from "../../../parsing/standard"; +import { DateField, StringField } from "../../../parsing/standard"; /** * Document data for Carte Vitale, API version 1. diff --git a/src/product/fr/idCard/idCardV1.ts b/src/product/fr/idCard/idCardV1.ts index 4e0ff9dd..9a4197c6 100644 --- a/src/product/fr/idCard/idCardV1.ts +++ b/src/product/fr/idCard/idCardV1.ts @@ -21,4 +21,4 @@ export class IdCardV1 extends Inference { ) ); } -} \ No newline at end of file +} diff --git a/src/product/fr/idCard/idCardV1Document.ts b/src/product/fr/idCard/idCardV1Document.ts index 47663cda..e1acaf18 100644 --- a/src/product/fr/idCard/idCardV1Document.ts +++ b/src/product/fr/idCard/idCardV1Document.ts @@ -3,7 +3,7 @@ import { StringDict, cleanOutString, } from "../../../parsing/common"; -import { StringField, DateField } from "../../../parsing/standard"; +import { DateField, StringField } from "../../../parsing/standard"; /** * Document data for Carte Nationale d'Identité, API version 1. diff --git a/src/product/passport/passportV1.ts b/src/product/passport/passportV1.ts index 29c9ad66..13b1ac27 100644 --- a/src/product/passport/passportV1.ts +++ b/src/product/passport/passportV1.ts @@ -20,4 +20,4 @@ export class PassportV1 extends Inference { ) ); } -} \ No newline at end of file +} diff --git a/src/product/passport/passportV1Document.ts b/src/product/passport/passportV1Document.ts index 10841036..35cbd8e8 100644 --- a/src/product/passport/passportV1Document.ts +++ b/src/product/passport/passportV1Document.ts @@ -3,7 +3,7 @@ import { StringDict, cleanOutString, } from "../../parsing/common"; -import { StringField, DateField } from "../../parsing/standard"; +import { DateField, StringField } from "../../parsing/standard"; /** * Document data for Passport, API version 1. diff --git a/src/product/proofOfAddress/proofOfAddressV1.ts b/src/product/proofOfAddress/proofOfAddressV1.ts index 475e09df..55bacc04 100644 --- a/src/product/proofOfAddress/proofOfAddressV1.ts +++ b/src/product/proofOfAddress/proofOfAddressV1.ts @@ -20,4 +20,4 @@ export class ProofOfAddressV1 extends Inference { ) ); } -} \ No newline at end of file +} diff --git a/src/product/proofOfAddress/proofOfAddressV1Document.ts b/src/product/proofOfAddress/proofOfAddressV1Document.ts index 968d1ab2..f3f2d512 100644 --- a/src/product/proofOfAddress/proofOfAddressV1Document.ts +++ b/src/product/proofOfAddress/proofOfAddressV1Document.ts @@ -4,10 +4,10 @@ import { cleanOutString, } from "../../parsing/common"; import { - StringField, - LocaleField, - DateField, CompanyRegistrationField, + DateField, + LocaleField, + StringField, } from "../../parsing/standard"; /** diff --git a/src/product/receipt/receiptV5.ts b/src/product/receipt/receiptV5.ts index b96edc66..e040e6f1 100644 --- a/src/product/receipt/receiptV5.ts +++ b/src/product/receipt/receiptV5.ts @@ -20,4 +20,4 @@ export class ReceiptV5 extends Inference { ) ); } -} \ No newline at end of file +} diff --git a/src/product/receipt/receiptV5Document.ts b/src/product/receipt/receiptV5Document.ts index 12d2a904..a4fb6e26 100644 --- a/src/product/receipt/receiptV5Document.ts +++ b/src/product/receipt/receiptV5Document.ts @@ -5,13 +5,13 @@ import { } from "../../parsing/common"; import { ReceiptV5LineItem } from "./receiptV5LineItem"; import { + AmountField, + ClassificationField, + CompanyRegistrationField, DateField, + LocaleField, StringField, - CompanyRegistrationField, Taxes, - LocaleField, - ClassificationField, - AmountField, } from "../../parsing/standard"; /** diff --git a/src/product/us/bankCheck/bankCheckV1.ts b/src/product/us/bankCheck/bankCheckV1.ts index b7e7e4fb..4443219a 100644 --- a/src/product/us/bankCheck/bankCheckV1.ts +++ b/src/product/us/bankCheck/bankCheckV1.ts @@ -21,4 +21,4 @@ export class BankCheckV1 extends Inference { ) ); } -} \ No newline at end of file +} diff --git a/src/product/us/bankCheck/bankCheckV1Document.ts b/src/product/us/bankCheck/bankCheckV1Document.ts index ea616b36..e7f1bb56 100644 --- a/src/product/us/bankCheck/bankCheckV1Document.ts +++ b/src/product/us/bankCheck/bankCheckV1Document.ts @@ -4,9 +4,9 @@ import { cleanOutString, } from "../../../parsing/common"; import { - StringField, - DateField, AmountField, + DateField, + StringField, } from "../../../parsing/standard"; /** diff --git a/src/product/us/driverLicense/driverLicenseV1.ts b/src/product/us/driverLicense/driverLicenseV1.ts deleted file mode 100644 index da24a847..00000000 --- a/src/product/us/driverLicense/driverLicenseV1.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Inference, StringDict, Page } from "../../../parsing/common"; -import { DriverLicenseV1Document } from "./driverLicenseV1Document"; -import { DriverLicenseV1Page } from "./driverLicenseV1Page"; - -export class DriverLicenseV1 extends Inference { - endpointName = "us_driver_license"; - endpointVersion = "1"; - prediction: DriverLicenseV1Document; - pages: Page[] = []; - - constructor(rawPrediction: StringDict) { - super(rawPrediction); - this.prediction = new DriverLicenseV1Document(rawPrediction["prediction"]); - this.pages = rawPrediction["pages"].map( - (page: StringDict) => - new Page( - DriverLicenseV1Page, - page, - page["id"], - page["orientation"] - ) - ); - } -} \ No newline at end of file diff --git a/src/product/us/driverLicense/driverLicenseV1Document.ts b/src/product/us/driverLicense/driverLicenseV1Document.ts deleted file mode 100644 index c329bace..00000000 --- a/src/product/us/driverLicense/driverLicenseV1Document.ts +++ /dev/null @@ -1,138 +0,0 @@ -import { - Prediction, - StringDict, - cleanOutString, -} from "../../../parsing/common"; -import { StringField, DateField } from "../../../parsing/standard"; - -/** - * Document data for Driver License, API version 1. - */ -export class DriverLicenseV1Document implements Prediction { - /** US driver license holders address */ - address: StringField; - /** US driver license holders class */ - class: StringField; - /** US driver license holders date of birth */ - dateOfBirth: DateField; - /** Document Discriminator Number of the US Driver License */ - ddNumber: StringField; - /** ID number of the US Driver License. */ - driverLicenseId: StringField; - /** US driver license holders endorsements */ - endorsements: StringField; - /** Date on which the documents expires. */ - expiryDate: DateField; - /** US driver license holders eye colour */ - eyeColor: StringField; - /** US driver license holders first name(s) */ - firstName: StringField; - /** US driver license holders hair colour */ - hairColor: StringField; - /** US driver license holders hight */ - height: StringField; - /** Date on which the documents was issued. */ - issuedDate: DateField; - /** US driver license holders last name */ - lastName: StringField; - /** US driver license holders restrictions */ - restrictions: StringField; - /** US driver license holders gender */ - sex: StringField; - /** US State */ - state: StringField; - /** US driver license holders weight */ - weight: StringField; - - constructor(rawPrediction: StringDict, pageId?: number) { - this.address = new StringField({ - prediction: rawPrediction["address"], - pageId: pageId, - }); - this.class = new StringField({ - prediction: rawPrediction["class"], - pageId: pageId, - }); - this.dateOfBirth = new DateField({ - prediction: rawPrediction["date_of_birth"], - pageId: pageId, - }); - this.ddNumber = new StringField({ - prediction: rawPrediction["dd_number"], - pageId: pageId, - }); - this.driverLicenseId = new StringField({ - prediction: rawPrediction["driver_license_id"], - pageId: pageId, - }); - this.endorsements = new StringField({ - prediction: rawPrediction["endorsements"], - pageId: pageId, - }); - this.expiryDate = new DateField({ - prediction: rawPrediction["expiry_date"], - pageId: pageId, - }); - this.eyeColor = new StringField({ - prediction: rawPrediction["eye_color"], - pageId: pageId, - }); - this.firstName = new StringField({ - prediction: rawPrediction["first_name"], - pageId: pageId, - }); - this.hairColor = new StringField({ - prediction: rawPrediction["hair_color"], - pageId: pageId, - }); - this.height = new StringField({ - prediction: rawPrediction["height"], - pageId: pageId, - }); - this.issuedDate = new DateField({ - prediction: rawPrediction["issued_date"], - pageId: pageId, - }); - this.lastName = new StringField({ - prediction: rawPrediction["last_name"], - pageId: pageId, - }); - this.restrictions = new StringField({ - prediction: rawPrediction["restrictions"], - pageId: pageId, - }); - this.sex = new StringField({ - prediction: rawPrediction["sex"], - pageId: pageId, - }); - this.state = new StringField({ - prediction: rawPrediction["state"], - pageId: pageId, - }); - this.weight = new StringField({ - prediction: rawPrediction["weight"], - pageId: pageId, - }); - } - - toString(): string { - const outStr = `:State: ${this.state} -:Driver License ID: ${this.driverLicenseId} -:Expiry Date: ${this.expiryDate} -:Date Of Issue: ${this.issuedDate} -:Last Name: ${this.lastName} -:First Name: ${this.firstName} -:Address: ${this.address} -:Date Of Birth: ${this.dateOfBirth} -:Restrictions: ${this.restrictions} -:Endorsements: ${this.endorsements} -:Class: ${this.class} -:Sex: ${this.sex} -:Height: ${this.height} -:Weight: ${this.weight} -:Hair Color: ${this.hairColor} -:Eye Color: ${this.eyeColor} -:Document Discriminator: ${this.ddNumber}`.trimEnd(); - return cleanOutString(outStr); - } -} diff --git a/src/product/us/driverLicense/driverLicenseV1Page.ts b/src/product/us/driverLicense/driverLicenseV1Page.ts deleted file mode 100644 index 1ce48bde..00000000 --- a/src/product/us/driverLicense/driverLicenseV1Page.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { StringDict, cleanOutString } from "../../../parsing/common"; -import { PositionField } from "../../../parsing/standard"; - -import { DriverLicenseV1Document } from "./driverLicenseV1Document"; - -/** - * Page data for Driver License, API version 1. - */ -export class DriverLicenseV1Page extends DriverLicenseV1Document { - /** Has a photo of the US driver license holder */ - photo: PositionField; - /** Has a signature of the US driver license holder */ - signature: PositionField; - - constructor(rawPrediction: StringDict, pageId?: number) { - super(rawPrediction, pageId); - - this.photo = new PositionField({ - prediction: rawPrediction["photo"], - pageId: pageId, - }); - this.signature = new PositionField({ - prediction: rawPrediction["signature"], - pageId: pageId, - }); - } - - toString(): string { - let outStr = `:Photo: ${this.photo} -:Signature: ${this.signature}`.trimEnd(); - outStr += "\n" + super.toString(); - return cleanOutString(outStr); - } -} diff --git a/src/product/us/index.ts b/src/product/us/index.ts index a56a3afa..d9727452 100644 --- a/src/product/us/index.ts +++ b/src/product/us/index.ts @@ -1,2 +1 @@ export { BankCheckV1 } from "./bankCheck/bankCheckV1"; -export { DriverLicenseV1 } from "./driverLicense/driverLicenseV1"; diff --git a/tests/product/financialDocument/financialDocumentV1.spec.ts b/tests/product/financialDocument/financialDocumentV1.spec.ts index 2cb538eb..7eb33145 100644 --- a/tests/product/financialDocument/financialDocumentV1.spec.ts +++ b/tests/product/financialDocument/financialDocumentV1.spec.ts @@ -13,6 +13,10 @@ const dataPath = { "tests/data/financial_document/response_v1/summary_full_invoice.rst", receiptDocString: "tests/data/financial_document/response_v1/summary_full_receipt.rst", + page0InvoiceString: + "tests/data/financial_document/response_v1/summary_page0_invoice.rst", + page0ReceiptString: + "tests/data/financial_document/response_v1/summary_page0_receipt.rst", }; describe("Financial Document V1 Object initialization", async () => { @@ -61,4 +65,24 @@ describe("Financial Document V1 Object initialization", async () => { const docString = await fs.readFile(path.join(dataPath.receiptDocString)); expect(doc.toString()).to.be.equals(docString.toString()); }); -}); \ No newline at end of file + + it("should load a complete page 0 invoice prediction", async () => { + const jsonData = await fs.readFile(path.resolve(dataPath.invoiceComplete)); + const response = JSON.parse(jsonData.toString()); + const doc = new mindee.Document(mindee.product.FinancialDocumentV1, response.document); + const page0 = doc.inference.pages[0]; + const docString = await fs.readFile(path.join(dataPath.page0InvoiceString)); + expect(page0.orientation?.value).to.be.equals(0); + expect(page0.toString()).to.be.equals(docString.toString()); + }); + + it("should load a complete page 0 receipt prediction", async () => { + const jsonData = await fs.readFile(path.resolve(dataPath.receiptComplete)); + const response = JSON.parse(jsonData.toString()); + const doc = new mindee.Document(mindee.product.FinancialDocumentV1, response.document); + const page0 = doc.inference.pages[0]; + const docString = await fs.readFile(path.join(dataPath.page0ReceiptString)); + expect(page0.orientation?.value).to.be.equals(0); + expect(page0.toString()).to.be.equals(docString.toString()); + }); +}); diff --git a/tests/product/invoice/invoiceV4.spec.ts b/tests/product/invoice/invoiceV4.spec.ts index f8612cb6..3fe26165 100644 --- a/tests/product/invoice/invoiceV4.spec.ts +++ b/tests/product/invoice/invoiceV4.spec.ts @@ -24,7 +24,7 @@ describe("Invoice V4 Object initialization", async () => { it("should initialize from a N/A prediction object", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); - const doc = new Page(InvoiceV4Document, response.document.inference.pages[0]); + const doc = new Page(InvoiceV4Document, response.document.inference.pages[0], 0); expect(doc.prediction.locale.value).to.be.undefined; expect(doc.prediction.totalAmount.value).to.be.undefined; expect(doc.prediction.totalNet.value).to.be.undefined; diff --git a/tests/product/us/driverLicense/driverLicenseV1.spec.ts b/tests/product/us/driverLicense/driverLicenseV1.spec.ts deleted file mode 100644 index 255b1505..00000000 --- a/tests/product/us/driverLicense/driverLicenseV1.spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { promises as fs } from "fs"; -import * as path from "path"; -import { expect } from "chai"; -import * as mindee from "../../../../src"; - - -const dataPath = { - complete: "tests/data/us/driver_license/response_v1/complete.json", - empty: "tests/data/us/driver_license/response_v1/empty.json", - docString: "tests/data/us/driver_license/response_v1/summary_full.rst", - page0String: "tests/data/us/driver_license/response_v1/summary_page0.rst", -}; - -describe("DriverLicenseV1 Object initialization", async () => { - it("should load an empty document prediction", async () => { - const jsonData = await fs.readFile(path.resolve(dataPath.empty)); - const response = JSON.parse(jsonData.toString()); - const doc = new mindee.Document(mindee.product.us.DriverLicenseV1, response.document); - const docPrediction = doc.inference.prediction; - expect(docPrediction.state.value).to.be.undefined; - expect(docPrediction.driverLicenseId.value).to.be.undefined; - expect(docPrediction.expiryDate.value).to.be.undefined; - expect(docPrediction.issuedDate.value).to.be.undefined; - expect(docPrediction.lastName.value).to.be.undefined; - expect(docPrediction.firstName.value).to.be.undefined; - expect(docPrediction.address.value).to.be.undefined; - expect(docPrediction.dateOfBirth.value).to.be.undefined; - expect(docPrediction.restrictions.value).to.be.undefined; - expect(docPrediction.endorsements.value).to.be.undefined; - expect(docPrediction.class.value).to.be.undefined; - expect(docPrediction.sex.value).to.be.undefined; - expect(docPrediction.height.value).to.be.undefined; - expect(docPrediction.weight.value).to.be.undefined; - expect(docPrediction.hairColor.value).to.be.undefined; - expect(docPrediction.eyeColor.value).to.be.undefined; - expect(docPrediction.ddNumber.value).to.be.undefined; - }); - - it("should load a complete document prediction", async () => { - const jsonData = await fs.readFile(path.resolve(dataPath.complete)); - const response = JSON.parse(jsonData.toString()); - const doc = new mindee.Document(mindee.product.us.DriverLicenseV1, response.document); - const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); - }); - - it("should load a complete page 0 prediction", async () => { - const jsonData = await fs.readFile(path.resolve(dataPath.complete)); - const response = JSON.parse(jsonData.toString()); - const doc = new mindee.Document(mindee.product.us.DriverLicenseV1, response.document); - const page0 = doc.inference.pages[0]; - const docString = await fs.readFile(path.join(dataPath.page0String)); - expect(page0.orientation?.value).to.be.equals(0); - expect(page0.toString()).to.be.equals(docString.toString()); - }); -});