├── .editorconfig ├── .gitmodules ├── .mocharc.json ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── bin └── mindee.ts ├── docs ├── bank_account_details_v2.md ├── bank_check_v1.md ├── barcode_reader_v1.md ├── bill_of_lading_v1.md ├── business_card_v1.md ├── carte_grise_v1.md ├── code_samples │ ├── bank_account_details_v1.txt │ ├── bank_account_details_v2.txt │ ├── bank_check_v1.txt │ ├── barcode_reader_v1.txt │ ├── bill_of_lading_v1_async.txt │ ├── business_card_v1_async.txt │ ├── carte_grise_v1.txt │ ├── cropper_v1.txt │ ├── custom_v1.txt │ ├── default.txt │ ├── default_async.txt │ ├── delivery_notes_v1_async.txt │ ├── driver_license_v1_async.txt │ ├── energy_bill_fra_v1_async.txt │ ├── expense_receipts_v5.txt │ ├── expense_receipts_v5_async.txt │ ├── financial_document_v1.txt │ ├── financial_document_v1_async.txt │ ├── french_healthcard_v1_async.txt │ ├── idcard_fr_v1.txt │ ├── idcard_fr_v2.txt │ ├── ind_passport_v1_async.txt │ ├── international_id_v2_async.txt │ ├── invoice_splitter_v1_async.txt │ ├── invoices_v4.txt │ ├── invoices_v4_async.txt │ ├── multi_receipts_detector_v1.txt │ ├── nutrition_facts_v1_async.txt │ ├── passport_v1.txt │ ├── payslip_fra_v2_async.txt │ ├── payslip_fra_v3_async.txt │ ├── resume_v1_async.txt │ ├── us_healthcare_cards_v1_async.txt │ ├── us_mail_v2_async.txt │ ├── us_mail_v3_async.txt │ ├── workflow_execution.txt │ ├── workflow_ots_rag.txt │ └── workflow_polling.txt ├── cropper_v1.md ├── custom_v1.md ├── delivery_notes_v1.md ├── driver_license_v1.md ├── energy_bill_fra_v1.md ├── expense_receipts_v5.md ├── financial_document_v1.md ├── french_healthcard_v1.md ├── generated_v1.md ├── getting_started.md ├── idcard_fr_v2.md ├── ind_passport_v1.md ├── international_id_v2.md ├── invoice_splitter_v1.md ├── invoices_v4.md ├── multi_receipts_detector_v1.md ├── nutrition_facts_v1.md ├── passport_v1.md ├── payslip_fra_v2.md ├── payslip_fra_v3.md ├── resume_v1.md ├── us_healthcare_cards_v1.md └── us_mail_v3.md ├── eslint.config.mjs ├── example ├── invoiceSplitterCustomSplitsTutorial.js ├── invoiceSplitterTutorial.js └── multiReceiptsTutorial.js ├── package-lock.json ├── package.json ├── src ├── cli.ts ├── cliProducts.ts ├── client.ts ├── errors │ ├── handler.ts │ ├── index.ts │ └── mindeeError.ts ├── geometry │ ├── boundingBox.ts │ ├── boundingBoxUtils.ts │ ├── index.ts │ ├── minMax.ts │ ├── point.ts │ ├── polygon.ts │ └── polygonUtils.ts ├── http │ ├── apiSettings.ts │ ├── baseEndpoint.ts │ ├── endpoint.ts │ ├── error.ts │ ├── httpParams.ts │ ├── index.ts │ ├── responseValidation.ts │ └── workflowEndpoint.ts ├── imageOperations │ ├── common │ │ ├── extractedImage.ts │ │ ├── imageExtractor.ts │ │ └── index.ts │ ├── imageCompressor.ts │ ├── index.ts │ ├── internal.ts │ ├── invoiceSplitterExtractor │ │ ├── extractedInvoiceSplitterImage.ts │ │ ├── index.ts │ │ └── invoiceSplitterExtractor.ts │ └── multiReceiptsExtractor │ │ ├── extractedMultiReceiptImage.ts │ │ ├── index.ts │ │ └── multiReceiptsExtractor.ts ├── index.ts ├── input │ ├── index.ts │ ├── localResponse.ts │ ├── pageOptions.ts │ └── sources │ │ ├── base64Input.ts │ │ ├── bufferInput.ts │ │ ├── bytesInput.ts │ │ ├── index.ts │ │ ├── inputSource.ts │ │ ├── localInputSource.ts │ │ ├── pathInput.ts │ │ ├── streamInput.ts │ │ └── urlInput.ts ├── internal.ts ├── logger.ts ├── parsing │ ├── common │ │ ├── apiRequest.ts │ │ ├── apiResponse.ts │ │ ├── asyncPredictResponse.ts │ │ ├── document.ts │ │ ├── execution.ts │ │ ├── executionFile.ts │ │ ├── executionPriority.ts │ │ ├── extras │ │ │ ├── cropperExtra.ts │ │ │ ├── extras.ts │ │ │ ├── fullTextOcrExtra.ts │ │ │ ├── index.ts │ │ │ └── ragExtra.ts │ │ ├── feedback │ │ │ └── feedbackResponse.ts │ │ ├── index.ts │ │ ├── inference.ts │ │ ├── mvisionV1.ts │ │ ├── ocr.ts │ │ ├── ocrPage.ts │ │ ├── orientation.ts │ │ ├── page.ts │ │ ├── predictResponse.ts │ │ ├── prediction.ts │ │ ├── product.ts │ │ ├── stringDict.ts │ │ ├── summaryHelper.ts │ │ └── workflowResponse.ts │ ├── custom │ │ ├── classificationField.ts │ │ ├── index.ts │ │ ├── lineItems.ts │ │ └── listField.ts │ ├── generated │ │ ├── generatedList.ts │ │ ├── generatedObject.ts │ │ └── index.ts │ ├── index.ts │ └── standard │ │ ├── addressField.ts │ │ ├── amount.ts │ │ ├── base.ts │ │ ├── boolean.ts │ │ ├── classification.ts │ │ ├── companyRegistration.ts │ │ ├── date.ts │ │ ├── field.ts │ │ ├── index.ts │ │ ├── locale.ts │ │ ├── paymentDetails.ts │ │ ├── position.ts │ │ ├── tax.ts │ │ ├── text.ts │ │ └── word.ts ├── pdf │ ├── index.ts │ ├── pdfCompressor.ts │ ├── pdfOperation.ts │ └── pdfUtils.ts └── product │ ├── barcodeReader │ ├── barcodeReaderV1.ts │ ├── barcodeReaderV1Document.ts │ ├── index.ts │ └── internal.ts │ ├── billOfLading │ ├── billOfLadingV1.ts │ ├── billOfLadingV1Carrier.ts │ ├── billOfLadingV1CarrierItem.ts │ ├── billOfLadingV1Consignee.ts │ ├── billOfLadingV1Document.ts │ ├── billOfLadingV1NotifyParty.ts │ ├── billOfLadingV1Shipper.ts │ ├── index.ts │ └── internal.ts │ ├── businessCard │ ├── businessCardV1.ts │ ├── businessCardV1Document.ts │ ├── index.ts │ └── internal.ts │ ├── cropper │ ├── cropperV1.ts │ ├── cropperV1Document.ts │ ├── cropperV1Page.ts │ ├── index.ts │ └── internal.ts │ ├── custom │ ├── customV1.ts │ ├── customV1Document.ts │ ├── customV1Page.ts │ └── internal.ts │ ├── deliveryNote │ ├── deliveryNoteV1.ts │ ├── deliveryNoteV1Document.ts │ ├── index.ts │ └── internal.ts │ ├── driverLicense │ ├── driverLicenseV1.ts │ ├── driverLicenseV1Document.ts │ ├── index.ts │ └── internal.ts │ ├── financialDocument │ ├── financialDocumentV1.ts │ ├── financialDocumentV1Document.ts │ ├── financialDocumentV1LineItem.ts │ ├── index.ts │ └── internal.ts │ ├── fr │ ├── bankAccountDetails │ │ ├── bankAccountDetailsV1.ts │ │ ├── bankAccountDetailsV1Document.ts │ │ ├── bankAccountDetailsV2.ts │ │ ├── bankAccountDetailsV2Bban.ts │ │ ├── bankAccountDetailsV2Document.ts │ │ ├── index.ts │ │ └── internal.ts │ ├── carteGrise │ │ ├── carteGriseV1.ts │ │ ├── carteGriseV1Document.ts │ │ ├── index.ts │ │ └── internal.ts │ ├── energyBill │ │ ├── energyBillV1.ts │ │ ├── energyBillV1Document.ts │ │ ├── energyBillV1EnergyConsumer.ts │ │ ├── energyBillV1EnergySupplier.ts │ │ ├── energyBillV1EnergyUsage.ts │ │ ├── energyBillV1MeterDetail.ts │ │ ├── energyBillV1Subscription.ts │ │ ├── energyBillV1TaxesAndContribution.ts │ │ ├── index.ts │ │ └── internal.ts │ ├── healthCard │ │ ├── healthCardV1.ts │ │ ├── healthCardV1Document.ts │ │ ├── index.ts │ │ └── internal.ts │ ├── idCard │ │ ├── idCardV1.ts │ │ ├── idCardV1Document.ts │ │ ├── idCardV1Page.ts │ │ ├── idCardV2.ts │ │ ├── idCardV2Document.ts │ │ ├── idCardV2Page.ts │ │ ├── index.ts │ │ └── internal.ts │ ├── index.ts │ ├── internal.ts │ └── payslip │ │ ├── index.ts │ │ ├── internal.ts │ │ ├── payslipV2.ts │ │ ├── payslipV2BankAccountDetail.ts │ │ ├── payslipV2Document.ts │ │ ├── payslipV2Employee.ts │ │ ├── payslipV2Employer.ts │ │ ├── payslipV2Employment.ts │ │ ├── payslipV2PayDetail.ts │ │ ├── payslipV2PayPeriod.ts │ │ ├── payslipV2Pto.ts │ │ ├── payslipV2SalaryDetail.ts │ │ ├── payslipV3.ts │ │ ├── payslipV3BankAccountDetail.ts │ │ ├── payslipV3Document.ts │ │ ├── payslipV3Employee.ts │ │ ├── payslipV3Employer.ts │ │ ├── payslipV3Employment.ts │ │ ├── payslipV3PaidTimeOff.ts │ │ ├── payslipV3PayDetail.ts │ │ ├── payslipV3PayPeriod.ts │ │ └── payslipV3SalaryDetail.ts │ ├── generated │ ├── generatedV1.ts │ ├── generatedV1Document.ts │ ├── generatedV1Page.ts │ ├── generatedV1Prediction.ts │ └── internal.ts │ ├── ind │ ├── index.ts │ ├── indianPassport │ │ ├── index.ts │ │ ├── indianPassportV1.ts │ │ ├── indianPassportV1Document.ts │ │ └── internal.ts │ └── internal.ts │ ├── index.ts │ ├── internal.ts │ ├── internationalId │ ├── index.ts │ ├── internal.ts │ ├── internationalIdV2.ts │ └── internationalIdV2Document.ts │ ├── invoice │ ├── index.ts │ ├── internal.ts │ ├── invoiceV4.ts │ ├── invoiceV4Document.ts │ └── invoiceV4LineItem.ts │ ├── invoiceSplitter │ ├── index.ts │ ├── internal.ts │ ├── invoiceSplitterV1.ts │ ├── invoiceSplitterV1Document.ts │ └── invoiceSplitterV1InvoicePageGroup.ts │ ├── multiReceiptsDetector │ ├── index.ts │ ├── internal.ts │ ├── multiReceiptsDetectorV1.ts │ └── multiReceiptsDetectorV1Document.ts │ ├── nutritionFactsLabel │ ├── index.ts │ ├── internal.ts │ ├── nutritionFactsLabelV1.ts │ ├── nutritionFactsLabelV1AddedSugar.ts │ ├── nutritionFactsLabelV1Calorie.ts │ ├── nutritionFactsLabelV1Cholesterol.ts │ ├── nutritionFactsLabelV1DietaryFiber.ts │ ├── nutritionFactsLabelV1Document.ts │ ├── nutritionFactsLabelV1Nutrient.ts │ ├── nutritionFactsLabelV1Protein.ts │ ├── nutritionFactsLabelV1SaturatedFat.ts │ ├── nutritionFactsLabelV1ServingSize.ts │ ├── nutritionFactsLabelV1Sodium.ts │ ├── nutritionFactsLabelV1TotalCarbohydrate.ts │ ├── nutritionFactsLabelV1TotalFat.ts │ ├── nutritionFactsLabelV1TotalSugar.ts │ └── nutritionFactsLabelV1TransFat.ts │ ├── passport │ ├── index.ts │ ├── internal.ts │ ├── passportV1.ts │ └── passportV1Document.ts │ ├── receipt │ ├── index.ts │ ├── internal.ts │ ├── receiptV5.ts │ ├── receiptV5Document.ts │ └── receiptV5LineItem.ts │ ├── resume │ ├── index.ts │ ├── internal.ts │ ├── resumeV1.ts │ ├── resumeV1Certificate.ts │ ├── resumeV1Document.ts │ ├── resumeV1Education.ts │ ├── resumeV1Language.ts │ ├── resumeV1ProfessionalExperience.ts │ └── resumeV1SocialNetworksUrl.ts │ └── us │ ├── bankCheck │ ├── bankCheckV1.ts │ ├── bankCheckV1Document.ts │ ├── bankCheckV1Page.ts │ ├── index.ts │ └── internal.ts │ ├── healthcareCard │ ├── healthcareCardV1.ts │ ├── healthcareCardV1Copay.ts │ ├── healthcareCardV1Document.ts │ ├── index.ts │ └── internal.ts │ ├── index.ts │ ├── internal.ts │ └── usMail │ ├── index.ts │ ├── internal.ts │ ├── usMailV2.ts │ ├── usMailV2Document.ts │ ├── usMailV2RecipientAddress.ts │ ├── usMailV2SenderAddress.ts │ ├── usMailV3.ts │ ├── usMailV3Document.ts │ ├── usMailV3RecipientAddress.ts │ └── usMailV3SenderAddress.ts ├── tsconfig.json └── typedoc.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | trim_trailing_whitespace = true 8 | 9 | [*.{js,json,ts,tsx}] 10 | indent_style = space 11 | indent_size = 2 12 | 13 | [*.{md,markdown}] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tests/data"] 2 | path = tests/data 3 | url = https://github.com/mindee/client-lib-test-data 4 | -------------------------------------------------------------------------------- /.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/mocharc", 3 | "extension": ["ts"], 4 | "require": "ts-node/register", 5 | "spec": ["tests"] 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-Present Mindee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bin/mindee.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { cli } from "../src/cli"; 4 | 5 | cli(); 6 | -------------------------------------------------------------------------------- /docs/code_samples/bank_account_details_v1.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.fr.BankAccountDetailsV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/bank_account_details_v2.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.fr.BankAccountDetailsV2, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/bank_check_v1.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.us.BankCheckV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/barcode_reader_v1.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.BarcodeReaderV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/bill_of_lading_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.BillOfLadingV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/business_card_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.BusinessCardV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/carte_grise_v1.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.fr.CarteGriseV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/cropper_v1.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.CropperV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/custom_v1.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Create a custom endpoint for your product 12 | const customEndpoint = mindeeClient.createEndpoint( 13 | "my-endpoint", 14 | "my-account", 15 | // "my-version" // Optional: set the version, defaults to "1" 16 | ); 17 | 18 | // Parse it 19 | const apiResponse = mindeeClient 20 | .parse( 21 | mindee.product.CustomV1, 22 | inputSource, 23 | { endpoint: customEndpoint } 24 | ); 25 | 26 | // Handle the response Promise 27 | apiResponse.then((resp) => { 28 | // print a string summary 29 | console.log(resp.document.toString()); 30 | }); 31 | -------------------------------------------------------------------------------- /docs/code_samples/default.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Create a custom endpoint for your product 12 | const customEndpoint = mindeeClient.createEndpoint( 13 | "my-endpoint", 14 | "my-account", 15 | "my-version" // Defaults to "1". 16 | ); 17 | 18 | // Parse the file. 19 | const apiResponse = mindeeClient 20 | .parse( 21 | mindee.product.GeneratedV1, 22 | inputSource, 23 | { endpoint: customEndpoint } 24 | ); 25 | 26 | // Handle the response Promise 27 | apiResponse.then((resp) => { 28 | // print a string summary 29 | console.log(resp.document.toString()); 30 | }); 31 | -------------------------------------------------------------------------------- /docs/code_samples/default_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Create a custom endpoint for your product 12 | const customEndpoint = mindeeClient.createEndpoint( 13 | "my-endpoint", 14 | "my-account", 15 | "my-version" // Defaults to "1" 16 | ); 17 | 18 | // Parse the file asynchronously. 19 | const asyncApiResponse = mindeeClient.enqueueAndParse( 20 | mindee.product.GeneratedV1, 21 | inputSource, 22 | { endpoint: customEndpoint } 23 | ); 24 | 25 | // Handle the response Promise 26 | asyncApiResponse.then((resp) => { 27 | // print a string summary 28 | console.log(resp.document.toString()); 29 | }); -------------------------------------------------------------------------------- /docs/code_samples/delivery_notes_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.DeliveryNoteV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/driver_license_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.DriverLicenseV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/energy_bill_fra_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.fr.EnergyBillV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/expense_receipts_v5.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.ReceiptV5, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/expense_receipts_v5_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.ReceiptV5, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/financial_document_v1.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.FinancialDocumentV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/financial_document_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.FinancialDocumentV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/french_healthcard_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.fr.HealthCardV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/idcard_fr_v1.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.fr.IdCardV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/idcard_fr_v2.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.fr.IdCardV2, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/ind_passport_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.ind.IndianPassportV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/international_id_v2_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.InternationalIdV2, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/invoice_splitter_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.InvoiceSplitterV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/invoices_v4.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.InvoiceV4, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/invoices_v4_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.InvoiceV4, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/multi_receipts_detector_v1.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.MultiReceiptsDetectorV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/nutrition_facts_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.NutritionFactsLabelV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/passport_v1.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.parse( 13 | mindee.product.PassportV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/payslip_fra_v2_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.fr.PayslipV2, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/payslip_fra_v3_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.fr.PayslipV3, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/resume_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.ResumeV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/us_healthcare_cards_v1_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.us.HealthcareCardV1, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/us_mail_v2_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.us.UsMailV2, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/us_mail_v3_async.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | // Init a new client 6 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 7 | 8 | // Load a file from disk 9 | const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); 10 | 11 | // Parse the file 12 | const apiResponse = mindeeClient.enqueueAndParse( 13 | mindee.product.us.UsMailV3, 14 | inputSource 15 | ); 16 | 17 | // Handle the response Promise 18 | apiResponse.then((resp) => { 19 | // print a string summary 20 | console.log(resp.document.toString()); 21 | }); 22 | -------------------------------------------------------------------------------- /docs/code_samples/workflow_execution.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | const workflowId: string = "workflow-id"; 6 | 7 | // Init a new client 8 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 9 | 10 | // Load a file from disk 11 | const inputSource = mindeeClient.docFromPath( 12 | "/path/to/the/file.ext" 13 | ); 14 | 15 | // Parse the file asynchronously. 16 | const asyncApiResponse = mindeeClient.executeWorkflow( 17 | inputSource, 18 | workflowId, 19 | // Optionally: send an alias & priority 20 | // { alias: "my-alias", priority: ExecutionPriority.low } 21 | ); 22 | 23 | // Handle the response Promise 24 | asyncApiResponse.then((resp) => { 25 | // print the execution id to make sure the request worked 26 | console.log(resp.execution.id); 27 | }); 28 | -------------------------------------------------------------------------------- /docs/code_samples/workflow_ots_rag.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | const workflowId: string = "workflow-id"; 6 | 7 | // Init a new client 8 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 9 | 10 | // Load a file from disk 11 | const inputSource = mindeeClient.docFromPath( 12 | "/path/to/the/file.ext" 13 | ); 14 | 15 | // Configure the RAG-enabled workflow 16 | const workflowParams = { 17 | rag: true, 18 | workflowId: workflowId 19 | }; 20 | 21 | // Parse the file asynchronously on a workflow queue 22 | const asyncApiResponse = mindeeClient.enqueueAndParse( 23 | mindee.product.FinancialDocumentV1, 24 | inputSource, 25 | workflowParams 26 | ); 27 | 28 | // Handle the response Promise 29 | asyncApiResponse.then((resp) => { 30 | // print a string summary 31 | console.log(resp.document?.toString()); 32 | }); 33 | -------------------------------------------------------------------------------- /docs/code_samples/workflow_polling.txt: -------------------------------------------------------------------------------- 1 | const mindee = require("mindee"); 2 | // for TS or modules: 3 | // import * as mindee from "mindee"; 4 | 5 | const workflowId: string = "workflow-id"; 6 | 7 | // Init a new client 8 | const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); 9 | 10 | // Load a file from disk 11 | const inputSource = mindeeClient.docFromPath( 12 | "/path/to/the/file.ext" 13 | ); 14 | 15 | const customEndpoint = mindeeClient.createEndpoint( 16 | "my-endpoint", 17 | "my-account", 18 | "my-version" // Defaults to "1" 19 | ); 20 | 21 | // Configure the RAG-enabled workflow 22 | const workflowParams = { 23 | rag: true, 24 | workflowId: workflowId, 25 | endpoint: customEndpoint 26 | }; 27 | 28 | // Parse the file asynchronously on a workflow queue 29 | const asyncApiResponse = mindeeClient.enqueueAndParse( 30 | mindee.product.GeneratedV1, 31 | inputSource, 32 | workflowParams 33 | ); 34 | 35 | // Handle the response Promise 36 | asyncApiResponse.then((resp) => { 37 | // print a string summary 38 | console.log(resp.document?.toString()); 39 | }); 40 | -------------------------------------------------------------------------------- /example/invoiceSplitterCustomSplitsTutorial.js: -------------------------------------------------------------------------------- 1 | const { Client, product, imageOperations } = require("mindee"); 2 | const { setTimeout } = require("node:timers/promises"); 3 | 4 | async function parseInvoicesWithCustomSplitsThreshold(customSplits) { 5 | // fill in your API key or add it as an environment variable 6 | const mindeeClient = new Client(); 7 | 8 | const invoiceFile = mindeeClient.docFromPath("path/to/your/file.ext"); 9 | let invoices = await imageOperations.extractInvoices(invoiceFile, customSplits); 10 | for (const invoice of invoices) { 11 | // optional: save the documents locally 12 | invoice.saveToFile(`/tmp/invoice_p_${invoice.pageIdMin}-${invoice.pageIdMax}.pdf`); 13 | const respInvoice = await mindeeClient.parse(product.InvoiceV4, invoice.asSource()); 14 | console.log(respInvoice.document.toString()); 15 | await setTimeout(1000); // wait some time between requests as to not overload the server 16 | } 17 | 18 | } 19 | 20 | const customSplits = [[0, 1], [1, 2]]; 21 | 22 | parseInvoicesWithCustomSplitsThreshold(customSplits); 23 | -------------------------------------------------------------------------------- /example/invoiceSplitterTutorial.js: -------------------------------------------------------------------------------- 1 | const { Client, product, imageOperations } = require("mindee"); 2 | const { setTimeout } = require("node:timers/promises"); 3 | 4 | async function parseInvoices() { 5 | // fill in your API key or add it as an environment variable 6 | const mindeeClient = new Client(); 7 | 8 | const invoiceFile = mindeeClient.docFromPath("path/to/your/file.ext"); 9 | const resp = await mindeeClient.enqueueAndParse(product.InvoiceSplitterV1, invoiceFile); 10 | let invoices = await imageOperations.extractInvoices(invoiceFile, resp.document.inference); 11 | for (const invoice of invoices) { 12 | // optional: save the documents locally 13 | invoice.saveToFile(`/tmp/invoice_p_${invoice.pageIdMin}-${invoice.pageIdMax}.pdf`); 14 | const respInvoice = await mindeeClient.parse(product.InvoiceV4, invoice.asSource()); 15 | console.log(respInvoice.document.toString()); 16 | await setTimeout(1000); // wait some time between requests as to not overload the server 17 | } 18 | 19 | } 20 | 21 | parseInvoices(); 22 | -------------------------------------------------------------------------------- /example/multiReceiptsTutorial.js: -------------------------------------------------------------------------------- 1 | const { Client, product, imageOperations } = require("mindee"); 2 | const { setTimeout } = require("node:timers/promises"); 3 | 4 | async function parseReceipts() { 5 | // fill in your API key or add it as an environment variable 6 | const mindeeClient = new Client(); 7 | 8 | const multiReceiptsFile = mindeeClient.docFromPath("path/to/your/file.ext"); 9 | const resp = await mindeeClient.parse(product.MultiReceiptsDetectorV1, multiReceiptsFile); 10 | let receipts = await imageOperations.extractReceipts(multiReceiptsFile, resp.document.inference); 11 | for (const receipt of receipts) { 12 | const respReceipt = await mindeeClient.parse(product.ReceiptV5, receipt.asSource()); 13 | console.log(respReceipt.document.toString()); 14 | receipt.saveToFile(`/tmp/receipt_p${receipt.pageId}_${receipt.receiptId}.pdf`); //optional: save to a file 15 | await setTimeout(1000); // wait some time between requests as to not overload the server 16 | } 17 | 18 | } 19 | 20 | parseReceipts(); 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mindee", 3 | "version": "4.28.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", 10 | "build-for-dist": "tsc --build && cp LICENSE README.md CHANGELOG.md ./dist", 11 | "clean": "rm -rf ./dist ./docs/_build", 12 | "test": "mocha 'tests/**/*.spec.ts' --config .mocharc.json", 13 | "test-integration": "mocha 'tests/**/*.integration.ts'", 14 | "lint": "eslint './src/**/*.ts' --report-unused-disable-directives && echo 'Your .ts files look good.'", 15 | "lint-fix": "eslint './src/**/*.ts' --fix", 16 | "docs": "typedoc --out docs/_build ./src/index.ts", 17 | "docs-for-dist": "typedoc --out docs/_build ./src/index.ts && cp -r ./docs/code_samples ./docs/_build/" 18 | }, 19 | "files": [ 20 | "src/*", 21 | "bin/*", 22 | "LICENSE", 23 | "README.md", 24 | "CHANGELOG.md" 25 | ], 26 | "engines": { 27 | "node": ">= 16" 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "git+https://github.com/mindee/mindee-api-nodejs.git" 32 | }, 33 | "author": { 34 | "name": "Mindee", 35 | "email": "opensource@mindee.com", 36 | "url": "https://mindee.com/" 37 | }, 38 | "bugs": { 39 | "url": "https://github.com/mindee/mindee-api-nodejs/issues" 40 | }, 41 | "homepage": "https://mindee.com/", 42 | "devDependencies": { 43 | "@types/chai": "^4.3.4", 44 | "@types/mocha": "^10.0.10", 45 | "@types/node": "^18.15.11", 46 | "@types/tmp": "^0.2.6", 47 | "@typescript-eslint/eslint-plugin": "^8.15.0", 48 | "@typescript-eslint/parser": "^8.15.0", 49 | "chai": "^4.3.10", 50 | "eslint": "^9.15.0", 51 | "eslint-plugin-jsdoc": "^50.5.0", 52 | "mocha": "^11.1.0", 53 | "nock": "^13.5.6", 54 | "ts-node": "^10.9.2", 55 | "typedoc": "~0.26.11", 56 | "typescript": "^5.6.3" 57 | }, 58 | "dependencies": { 59 | "@cantoo/pdf-lib": "^2.3.2", 60 | "commander": "~9.4.1", 61 | "file-type": "~16.5.4", 62 | "form-data": "~3.0.1", 63 | "node-poppler": "^7.2.2", 64 | "pdf.js-extract": "^0.2.1", 65 | "sharp": "^0.33.5", 66 | "tmp": "^0.2.3", 67 | "tslib": "^2.8.1" 68 | }, 69 | "keywords": [ 70 | "typescript", 71 | "mindee", 72 | "api", 73 | "client", 74 | "client library", 75 | "nodejs" 76 | ] 77 | } 78 | -------------------------------------------------------------------------------- /src/errors/handler.ts: -------------------------------------------------------------------------------- 1 | import { logger } from "../logger"; 2 | 3 | /** 4 | * Custom Error handling class. 5 | * @deprecated Clashes with current implementation of some errors, which may cause unexpected behaviors. 6 | */ 7 | export class ErrorHandler { 8 | public throwOnError: boolean; 9 | 10 | constructor(throwOnError: boolean = true) { 11 | this.throwOnError = throwOnError; 12 | } 13 | 14 | throw(error: Error) { 15 | if (this.throwOnError) { 16 | throw error; 17 | } else { 18 | logger.error(error.message); 19 | } 20 | } 21 | } 22 | 23 | export const errorHandler = new ErrorHandler(); 24 | -------------------------------------------------------------------------------- /src/errors/index.ts: -------------------------------------------------------------------------------- 1 | export { MindeeError, MindeeMimeTypeError } from "./mindeeError"; 2 | -------------------------------------------------------------------------------- /src/errors/mindeeError.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Main Mindee Error custom class. 3 | */ 4 | export class MindeeError extends Error { 5 | constructor(message: string) { 6 | super(message); 7 | this.name = "MindeeError"; 8 | } 9 | } 10 | 11 | /** 12 | * Custom Mindee error relating to improper mimetypes in inputs. 13 | */ 14 | export class MindeeMimeTypeError extends MindeeError { 15 | constructor(message: string) { 16 | super(message); 17 | this.name = "MindeeMimeTypeError"; 18 | } 19 | } 20 | 21 | 22 | export class MindeeImageError extends MindeeError { 23 | constructor(message: string) { 24 | super(message); 25 | this.name = "MindeeImageError"; 26 | } 27 | } 28 | 29 | export class MindeePdfError extends MindeeError { 30 | constructor(message: string) { 31 | super(message); 32 | this.name = "MindeePdfError"; 33 | } 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/geometry/boundingBox.ts: -------------------------------------------------------------------------------- 1 | import { Point } from "./point"; 2 | 3 | /** A simple bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */ 4 | export class BBox { 5 | xMin: number; 6 | yMin: number; 7 | xMax: number; 8 | yMax: number; 9 | 10 | constructor(xMin: number, yMin: number, xMax: number, yMax: number) { 11 | this.xMin = xMin; 12 | this.yMin = yMin; 13 | this.xMax = xMax; 14 | this.yMax = yMax; 15 | } 16 | } 17 | 18 | /** A bounding box defined by 4 points. */ 19 | export type BoundingBox = [Point, Point, Point, Point]; 20 | -------------------------------------------------------------------------------- /src/geometry/boundingBoxUtils.ts: -------------------------------------------------------------------------------- 1 | import { BoundingBox, BBox } from "./boundingBox"; 2 | import { Polygon } from "./polygon"; 3 | 4 | /** 5 | * Given a Polygon, calculate a polygon that encompasses all points. 6 | */ 7 | export function getBoundingBox(polygon: Polygon): BoundingBox { 8 | const bbox = getBbox(polygon); 9 | return getBoundingBoxFromBBox(bbox); 10 | } 11 | 12 | /** 13 | * Given a BBox, generate the associated bounding box. 14 | */ 15 | export function getBoundingBoxFromBBox(bbox: BBox): BoundingBox { 16 | return [ 17 | [bbox.xMin, bbox.yMin], 18 | [bbox.xMax, bbox.yMin], 19 | [bbox.xMax, bbox.yMax], 20 | [bbox.xMin, bbox.yMax], 21 | ]; 22 | } 23 | 24 | /** 25 | * Given 2 bbox, merge them. 26 | */ 27 | export function mergeBbox(bbox1: BBox, bbox2: BBox): BBox { 28 | return new BBox( 29 | Math.min(bbox1.xMin, bbox2.xMin), 30 | Math.min(bbox1.yMin, bbox2.yMin), 31 | Math.max(bbox1.xMax, bbox2.xMax), 32 | Math.max(bbox1.yMax, bbox2.yMax), 33 | ); 34 | } 35 | 36 | /** 37 | * Given a Polygon, calculate a BBox that encompasses all points. 38 | */ 39 | export function getBbox(polygon: Polygon): BBox { 40 | const allY: number[] = polygon.map((point) => point[1]); 41 | const allX: number[] = polygon.map((point) => point[0]); 42 | return new BBox( 43 | Math.min(...allX), 44 | Math.min(...allY), 45 | Math.max(...allX), 46 | Math.max(...allY), 47 | ); 48 | } 49 | 50 | /** 51 | * Given polygons, calculate a BBox that encompasses all points. 52 | */ 53 | export function getBBoxForPolygons(polygons: Polygon[]): BBox { 54 | const allY = polygons.flatMap((polygon) => polygon.map((point) => point[1])); 55 | const allX = polygons.flatMap((polygon) => polygon.map((point) => point[0])); 56 | return new BBox( 57 | Math.min(...allX), 58 | Math.min(...allY), 59 | Math.max(...allX), 60 | Math.max(...allY), 61 | ); 62 | } 63 | -------------------------------------------------------------------------------- /src/geometry/index.ts: -------------------------------------------------------------------------------- 1 | export { Polygon } from "./polygon"; 2 | export { 3 | compareOnX, 4 | compareOnY, 5 | getCentroid, 6 | isPointInPolygonX, 7 | isPointInPolygonY, 8 | relativeX, 9 | relativeY, 10 | getMinMaxX, 11 | getMinMaxY, 12 | } from "./polygonUtils"; 13 | export { BoundingBox, BBox } from "./boundingBox"; 14 | export { 15 | getBbox, 16 | getBBoxForPolygons, 17 | getBoundingBox, 18 | getBoundingBoxFromBBox, 19 | mergeBbox, 20 | } from "./boundingBoxUtils"; 21 | export { MinMax } from "./minMax"; 22 | export { Point } from "./point"; 23 | -------------------------------------------------------------------------------- /src/geometry/minMax.ts: -------------------------------------------------------------------------------- 1 | export type MinMax = { min: number; max: number }; 2 | -------------------------------------------------------------------------------- /src/geometry/point.ts: -------------------------------------------------------------------------------- 1 | /** A point on the document defined by 2 coordinates: X, Y */ 2 | export type Point = [number, number]; 3 | -------------------------------------------------------------------------------- /src/geometry/polygon.ts: -------------------------------------------------------------------------------- 1 | import { Point } from "./point"; 2 | 3 | /** A polygon, composed of several Points. */ 4 | export class Polygon extends Array {} 5 | -------------------------------------------------------------------------------- /src/http/httpParams.ts: -------------------------------------------------------------------------------- 1 | import { InputSource, PageOptions } from "../input"; 2 | import { ExecutionPriority } from "../parsing/common"; 3 | 4 | interface HTTPParams { 5 | inputDoc: InputSource; 6 | fullText: boolean; 7 | pageOptions?: PageOptions; 8 | rag?: boolean; 9 | } 10 | 11 | export interface PredictParams extends HTTPParams { 12 | includeWords: boolean; 13 | cropper: boolean; 14 | workflowId?: string; 15 | } 16 | 17 | export interface WorkflowParams extends HTTPParams { 18 | alias?: string; 19 | priority?: ExecutionPriority; 20 | publicUrl?: string; 21 | } 22 | -------------------------------------------------------------------------------- /src/http/index.ts: -------------------------------------------------------------------------------- 1 | export { Endpoint } from "./endpoint"; 2 | export { EndpointResponse } from "./baseEndpoint"; 3 | export { 4 | STANDARD_API_OWNER, 5 | API_KEY_ENVVAR_NAME, 6 | ApiSettings, 7 | } from "./apiSettings"; 8 | export { 9 | MindeeHttpError, 10 | MindeeHttp400Error, 11 | MindeeHttp401Error, 12 | MindeeHttp403Error, 13 | MindeeHttp404Error, 14 | MindeeHttp413Error, 15 | MindeeHttp429Error, 16 | MindeeHttp500Error, 17 | MindeeHttp504Error, 18 | handleError, 19 | } from "./error"; 20 | export { 21 | isValidSyncResponse, 22 | isValidAsyncResponse, 23 | cleanRequestData, 24 | } from "./responseValidation"; 25 | export { PredictParams, WorkflowParams } from "./httpParams"; 26 | -------------------------------------------------------------------------------- /src/imageOperations/common/extractedImage.ts: -------------------------------------------------------------------------------- 1 | import { Buffer } from "node:buffer"; 2 | import { MindeeError } from "../../errors"; 3 | import { writeFileSync } from "node:fs"; 4 | import path from "node:path"; 5 | import { logger } from "../../logger"; 6 | import { BufferInput } from "../../input"; 7 | 8 | /** 9 | * Generic class for image extraction 10 | */ 11 | export class ExtractedImage { 12 | public buffer: Buffer; 13 | protected internalFileName: string; 14 | 15 | 16 | protected constructor(buffer: Uint8Array, fileName: string) { 17 | this.buffer = Buffer.from(buffer); 18 | this.internalFileName = fileName; 19 | } 20 | 21 | /** 22 | * Saves the document to a file. 23 | * 24 | * @param outputPath Path to save the file to. 25 | */ 26 | saveToFile(outputPath: string) { 27 | try { 28 | writeFileSync(path.resolve(outputPath), this.buffer); 29 | logger.info(`File saved successfully to ${path.resolve(outputPath)}.`); 30 | } catch (e) { 31 | if (e instanceof TypeError) { 32 | throw new MindeeError("Invalid path/filename provided."); 33 | } else { 34 | throw e; 35 | } 36 | } 37 | } 38 | 39 | 40 | /** 41 | * Return the file as a Mindee-compatible BufferInput source. 42 | * 43 | * @returns A BufferInput source. 44 | */ 45 | asSource(): BufferInput { 46 | return new BufferInput({ 47 | buffer: this.buffer, 48 | filename: this.internalFileName, 49 | }); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/imageOperations/common/imageExtractor.ts: -------------------------------------------------------------------------------- 1 | import { PDFDocument, PDFPage } from "@cantoo/pdf-lib"; 2 | import { getMinMaxX, getMinMaxY, Polygon } from "../../geometry"; 3 | 4 | /** 5 | * Extracts elements from a page based off of a list of bounding boxes. 6 | * 7 | * @param pdfPage PDF Page to extract from. 8 | * @param polygons List of coordinates to pull the elements from. 9 | */ 10 | export async function extractFromPage( 11 | pdfPage: PDFPage, 12 | polygons: Polygon[]) { 13 | const { width, height } = pdfPage.getSize(); 14 | const extractedElements :Uint8Array[] = []; 15 | for (const polygon of polygons) { 16 | const tempPdf = await PDFDocument.create(); 17 | 18 | const newWidth = width * (getMinMaxX(polygon).max - getMinMaxX(polygon).min); 19 | const newHeight = height * (getMinMaxY(polygon).max - getMinMaxY(polygon).min); 20 | const cropped = await tempPdf.embedPage(pdfPage, { 21 | left: getMinMaxX(polygon).min * width, 22 | right: getMinMaxX(polygon).max * width, 23 | top: height - (getMinMaxY(polygon).min * height), 24 | bottom: height - (getMinMaxY(polygon).max * height), 25 | }); 26 | const samplePage = tempPdf.addPage([newWidth, newHeight]); 27 | samplePage.drawPage(cropped, 28 | { 29 | width: newWidth, 30 | height: newHeight, 31 | }); 32 | extractedElements.push(await tempPdf.save()); 33 | } 34 | return extractedElements; 35 | } 36 | -------------------------------------------------------------------------------- /src/imageOperations/common/index.ts: -------------------------------------------------------------------------------- 1 | export { ExtractedImage } from "./extractedImage"; 2 | export { extractFromPage } from "./imageExtractor"; 3 | -------------------------------------------------------------------------------- /src/imageOperations/imageCompressor.ts: -------------------------------------------------------------------------------- 1 | import sharp from "sharp"; 2 | import { Sharp, Metadata } from "sharp"; 3 | import { MindeeImageError } from "../errors/mindeeError"; 4 | 5 | /** 6 | * Compresses an image with the given parameters. 7 | * 8 | * @param imageBuffer Buffer representation of an image. 9 | * @param quality Quality to apply to the image (JPEG). 10 | * @param maxWidth Maximum bound for width. 11 | * @param maxHeight Maximum bound for height. 12 | */ 13 | export async function compressImage( 14 | imageBuffer: Buffer, 15 | quality:number = 85, 16 | maxWidth:number|null = null, 17 | maxHeight:number|null = null, 18 | ) { 19 | let sharpImage: Sharp = sharp(imageBuffer); 20 | 21 | const metadata: Metadata = await sharpImage.metadata(); 22 | if (metadata.width === undefined || metadata.height === undefined){ 23 | throw new MindeeImageError("Source image has invalid dimensions."); 24 | } 25 | maxWidth ??= metadata.width; 26 | maxHeight ??= metadata.height; 27 | if (maxWidth || maxHeight) { 28 | sharpImage = sharpImage.resize({ 29 | width: maxWidth, 30 | height: maxHeight, 31 | fit: "inside", 32 | withoutEnlargement: true, 33 | }); 34 | } 35 | 36 | return await sharpImage 37 | .jpeg({ quality: quality }) 38 | .toBuffer(); 39 | } 40 | -------------------------------------------------------------------------------- /src/imageOperations/index.ts: -------------------------------------------------------------------------------- 1 | export { extractReceipts, ExtractedMultiReceiptImage } from "./multiReceiptsExtractor"; 2 | export { extractInvoices, ExtractedInvoiceSplitterImage } from "./invoiceSplitterExtractor"; 3 | export { compressImage } from "./imageCompressor"; 4 | -------------------------------------------------------------------------------- /src/imageOperations/internal.ts: -------------------------------------------------------------------------------- 1 | export { extractReceipts, ExtractedMultiReceiptImage } from "./multiReceiptsExtractor"; 2 | export { extractInvoices, ExtractedInvoiceSplitterImage } from "./invoiceSplitterExtractor"; 3 | export { ExtractedImage } from "./common"; 4 | -------------------------------------------------------------------------------- /src/imageOperations/invoiceSplitterExtractor/extractedInvoiceSplitterImage.ts: -------------------------------------------------------------------------------- 1 | import { ExtractedImage } from "../common/extractedImage"; 2 | 3 | /** 4 | * Wrapper class for extracted invoice pages. 5 | */ 6 | export class ExtractedInvoiceSplitterImage extends ExtractedImage { 7 | readonly pageIdMin: number; 8 | readonly pageIdMax: number; 9 | 10 | constructor(buffer: Uint8Array, pageIndices: [number, number]) { 11 | super(buffer, `invoice_p_${pageIndices[0]}-${pageIndices[1]}.pdf`); 12 | this.pageIdMin = pageIndices[0]; 13 | this.pageIdMax = pageIndices[1]; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/imageOperations/invoiceSplitterExtractor/index.ts: -------------------------------------------------------------------------------- 1 | export { extractInvoices } from "./invoiceSplitterExtractor"; 2 | export { ExtractedInvoiceSplitterImage } from "./extractedInvoiceSplitterImage"; 3 | -------------------------------------------------------------------------------- /src/imageOperations/multiReceiptsExtractor/extractedMultiReceiptImage.ts: -------------------------------------------------------------------------------- 1 | import { ExtractedImage } from "../common"; 2 | 3 | /** 4 | * Wrapper class for extracted multiple-receipts images. 5 | */ 6 | export class ExtractedMultiReceiptImage extends ExtractedImage { 7 | readonly receiptId: number; 8 | readonly pageId: number; 9 | 10 | constructor(buffer: Uint8Array, pageId: number, receiptId: number) { 11 | super(buffer, `receipt_p${pageId}_${receiptId}.pdf`); 12 | this.pageId = pageId; 13 | this.receiptId = receiptId; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/imageOperations/multiReceiptsExtractor/index.ts: -------------------------------------------------------------------------------- 1 | export { extractReceipts } from "./multiReceiptsExtractor"; 2 | export { ExtractedMultiReceiptImage } from "./extractedMultiReceiptImage"; 3 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * as product from "./product"; 2 | export { Client, PredictOptions } from "./client"; 3 | export { 4 | AsyncPredictResponse, 5 | PredictResponse, 6 | Inference, 7 | Prediction, 8 | Document, 9 | Page, 10 | } from "./parsing/common"; 11 | export { InputSource, PageOptionsOperation, LocalResponse } from "./input"; 12 | export * as internal from "./internal"; 13 | export * as imageOperations from "./imageOperations"; 14 | -------------------------------------------------------------------------------- /src/input/index.ts: -------------------------------------------------------------------------------- 1 | export { PageOptions, PageOptionsOperation } from "./pageOptions"; 2 | export * from "./sources"; 3 | export { LocalResponse } from "./localResponse"; 4 | -------------------------------------------------------------------------------- /src/input/pageOptions.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/naming-convention */ 2 | /** 3 | * Options to pass to the `parse` method for cutting multi-page documents. 4 | */ 5 | export interface PageOptions { 6 | /** 7 | * Zero-based list of page indexes. 8 | * 9 | * A negative index can be used, indicating an offset from the end of the document. 10 | * 11 | * [0, -1] represents the fist and last pages of the document. 12 | */ 13 | pageIndexes: number[]; 14 | /** Operation to apply on the document, given the `pageIndexes` specified. */ 15 | operation: PageOptionsOperation; 16 | /** 17 | * Apply the operation only if document has at least this many pages. 18 | */ 19 | onMinPages: number; 20 | } 21 | 22 | /** 23 | * Operation to apply on the document, given the page indexes specified. 24 | */ 25 | export enum PageOptionsOperation { 26 | /** Only keep pages matching the provided indexes. */ 27 | KeepOnly = "KEEP_ONLY", 28 | /** Remove pages matching the provided indexes. */ 29 | Remove = "REMOVE", 30 | } 31 | -------------------------------------------------------------------------------- /src/input/sources/base64Input.ts: -------------------------------------------------------------------------------- 1 | import { LocalInputSource } from "./localInputSource"; 2 | import { INPUT_TYPE_BASE64 } from "./inputSource"; 3 | 4 | interface Base64InputProps { 5 | inputString: string; 6 | filename: string; 7 | } 8 | 9 | export class Base64Input extends LocalInputSource { 10 | private inputString: string; 11 | fileObject: Buffer = Buffer.alloc(0); 12 | 13 | constructor({ inputString, filename }: Base64InputProps) { 14 | super({ 15 | inputType: INPUT_TYPE_BASE64, 16 | }); 17 | this.filename = filename; 18 | this.inputString = inputString; 19 | } 20 | 21 | async init() { 22 | this.fileObject = Buffer.from(this.inputString, "base64"); 23 | this.mimeType = await this.checkMimetype(); 24 | // clear out the string 25 | this.inputString = ""; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/input/sources/bufferInput.ts: -------------------------------------------------------------------------------- 1 | import { LocalInputSource } from "./localInputSource"; 2 | import { INPUT_TYPE_BUFFER } from "./inputSource"; 3 | 4 | interface BufferInputProps { 5 | buffer: Buffer; 6 | filename: string; 7 | } 8 | 9 | export class BufferInput extends LocalInputSource { 10 | constructor({ buffer, filename }: BufferInputProps) { 11 | super({ 12 | inputType: INPUT_TYPE_BUFFER, 13 | }); 14 | this.fileObject = buffer; 15 | this.filename = filename; 16 | } 17 | 18 | async init(): Promise { 19 | this.mimeType = await this.checkMimetype(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/input/sources/bytesInput.ts: -------------------------------------------------------------------------------- 1 | import { INPUT_TYPE_BYTES } from "./inputSource"; 2 | import { LocalInputSource } from "./localInputSource"; 3 | 4 | interface BytesInputProps { 5 | inputBytes: Uint8Array; 6 | filename: string; 7 | } 8 | 9 | export class BytesInput extends LocalInputSource { 10 | private inputBytes: Uint8Array; 11 | fileObject: Buffer = Buffer.alloc(0); 12 | 13 | constructor({ inputBytes, filename }: BytesInputProps) { 14 | super({ 15 | inputType: INPUT_TYPE_BYTES, 16 | }); 17 | this.filename = filename; 18 | this.inputBytes = inputBytes; 19 | } 20 | 21 | async init() { 22 | this.fileObject = Buffer.from(this.inputBytes); 23 | this.mimeType = await this.checkMimetype(); 24 | this.inputBytes = new Uint8Array(0); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/input/sources/index.ts: -------------------------------------------------------------------------------- 1 | export { Base64Input } from "./base64Input"; 2 | export { BufferInput } from "./bufferInput"; 3 | export { BytesInput } from "./bytesInput"; 4 | export { 5 | InputSource, 6 | INPUT_TYPE_PATH, 7 | INPUT_TYPE_STREAM, 8 | InputConstructor, 9 | INPUT_TYPE_BUFFER, 10 | INPUT_TYPE_BASE64, 11 | INPUT_TYPE_BYTES 12 | } from "./inputSource"; 13 | export { LocalInputSource } from "./localInputSource"; 14 | export { PathInput } from "./pathInput"; 15 | export { StreamInput } from "./streamInput"; 16 | export { UrlInput } from "./urlInput"; 17 | -------------------------------------------------------------------------------- /src/input/sources/inputSource.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {string} inputType - the type of input used in file ("base64", "path", "dummy"). 3 | * NB: dummy is only used for tests purposes 4 | */ 5 | export interface InputConstructor { 6 | inputType: string; 7 | } 8 | 9 | export const INPUT_TYPE_STREAM = "stream"; 10 | export const INPUT_TYPE_BASE64 = "base64"; 11 | export const INPUT_TYPE_BYTES = "bytes"; 12 | export const INPUT_TYPE_PATH = "path"; 13 | export const INPUT_TYPE_BUFFER = "buffer"; 14 | 15 | export abstract class InputSource { 16 | fileObject: Buffer | string = ""; 17 | 18 | async init() { 19 | throw new Error("not Implemented"); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/input/sources/pathInput.ts: -------------------------------------------------------------------------------- 1 | import { INPUT_TYPE_PATH } from "./inputSource"; 2 | import { LocalInputSource } from "./localInputSource"; 3 | import path from "path"; 4 | import { logger } from "../../logger"; 5 | import { promises as fs } from "fs"; 6 | 7 | interface PathInputProps { 8 | inputPath: string; 9 | } 10 | 11 | export class PathInput extends LocalInputSource { 12 | readonly inputPath: string; 13 | fileObject: Buffer = Buffer.alloc(0); 14 | 15 | constructor({ inputPath }: PathInputProps) { 16 | super({ 17 | inputType: INPUT_TYPE_PATH, 18 | }); 19 | this.inputPath = inputPath; 20 | this.filename = path.basename(this.inputPath); 21 | } 22 | 23 | async init() { 24 | logger.debug(`Loading from: ${this.inputPath}`); 25 | this.fileObject = Buffer.from(await fs.readFile(this.inputPath)); 26 | this.mimeType = await this.checkMimetype(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/input/sources/streamInput.ts: -------------------------------------------------------------------------------- 1 | import { Readable } from "stream"; 2 | import { LocalInputSource } from "./localInputSource"; 3 | import { INPUT_TYPE_STREAM } from "./inputSource"; 4 | 5 | interface StreamInputProps { 6 | inputStream: Readable; 7 | filename: string; 8 | } 9 | 10 | export class StreamInput extends LocalInputSource { 11 | private readonly inputStream: Readable; 12 | fileObject: Buffer = Buffer.alloc(0); 13 | 14 | constructor({ inputStream, filename }: StreamInputProps) { 15 | super({ 16 | inputType: INPUT_TYPE_STREAM, 17 | }); 18 | this.filename = filename; 19 | this.inputStream = inputStream; 20 | } 21 | 22 | async init() { 23 | this.fileObject = await this.stream2buffer(this.inputStream); 24 | this.mimeType = await this.checkMimetype(); 25 | } 26 | 27 | async stream2buffer(stream: Readable): Promise { 28 | return new Promise((resolve, reject) => { 29 | const _buf = Array(); 30 | stream.on("data", (chunk) => _buf.push(chunk)); 31 | stream.on("end", () => resolve(Buffer.concat(_buf))); 32 | stream.on("error", (err) => reject(`Error converting stream - ${err}`)); 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/internal.ts: -------------------------------------------------------------------------------- 1 | export * as input from "./input"; 2 | export * as geometry from "./geometry"; 3 | export * as http from "./http"; 4 | export * as imageOperations from "./imageOperations/internal"; 5 | export * as parsing from "./parsing"; 6 | export * as pdf from "./pdf"; 7 | export * as product from "./product/internal"; 8 | -------------------------------------------------------------------------------- /src/logger.ts: -------------------------------------------------------------------------------- 1 | interface LoggerLevels { 2 | [index: string]: number; 3 | } 4 | 5 | interface LoggerInterface { 6 | debug(level: any[]): void; 7 | info(level: any[]): void; 8 | warn(level: any[]): void; 9 | error(level: any[]): void; 10 | } 11 | 12 | export const LOG_LEVELS: LoggerLevels = { 13 | debug: 0, 14 | info: 1, 15 | warn: 2, 16 | error: 3, 17 | }; 18 | 19 | class Logger implements LoggerInterface { 20 | level: number; 21 | 22 | constructor(public levelToSet: string = "warn") { 23 | if (!(levelToSet in LOG_LEVELS)) { 24 | this.level = LOG_LEVELS["debug"]; 25 | } 26 | this.level = LOG_LEVELS[levelToSet]; 27 | } 28 | 29 | debug(...args: any[]) { 30 | if (this.level <= LOG_LEVELS["debug"]) console.debug(args); 31 | } 32 | 33 | info(...args: any[]) { 34 | if (this.level <= LOG_LEVELS["info"]) console.info(args); 35 | } 36 | 37 | warn(...args: any[]) { 38 | if (this.level <= LOG_LEVELS["warn"]) console.warn(args); 39 | } 40 | 41 | error(...args: any[]) { 42 | if (this.level <= LOG_LEVELS["error"]) console.error(args); 43 | } 44 | } 45 | 46 | export const logger = new Logger(); 47 | -------------------------------------------------------------------------------- /src/parsing/common/apiRequest.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "./stringDict"; 2 | /** 3 | * Holds the information relating to an API HTTP request. 4 | * 5 | * @category API Response 6 | */ 7 | export class ApiRequest { 8 | /** An object detailing the error. */ 9 | error: StringDict; 10 | /** Target of the request. */ 11 | resources: string[]; 12 | /** Status of the request. Either "failure" or "success". */ 13 | status: "failure" | "success"; 14 | /** HTTP status code */ 15 | statusCode: number; 16 | /** URL of the request. */ 17 | url: string; 18 | 19 | constructor(serverResponse: StringDict) { 20 | this.error = serverResponse["error"]; 21 | this.resources = serverResponse["resources"]; 22 | this.status = serverResponse["status"]; 23 | this.statusCode = serverResponse["status_code"]; 24 | this.url = serverResponse["url"]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/parsing/common/apiResponse.ts: -------------------------------------------------------------------------------- 1 | import { ApiRequest } from "./apiRequest"; 2 | import { StringDict } from "./stringDict"; 3 | 4 | 5 | /** Base wrapper for API requests. 6 | * 7 | * @category API Response 8 | */ 9 | export abstract class ApiResponse { 10 | /** Initial request sent to the API. */ 11 | apiRequest: ApiRequest; 12 | /** Raw text representation of the API's response. */ 13 | private readonly rawHttp: StringDict; 14 | 15 | /** 16 | * @param serverResponse JSON response from the server. 17 | */ 18 | constructor(serverResponse: StringDict) { 19 | this.apiRequest = new ApiRequest(serverResponse["api_request"]); 20 | this.rawHttp = serverResponse; 21 | } 22 | 23 | /** 24 | * Raw HTTP request sent from server, as a JSON-like structure 25 | * @returns The HTTP request 26 | */ 27 | getRawHttp():StringDict { 28 | return this.rawHttp; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/parsing/common/executionFile.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "./stringDict"; 2 | 3 | /** 4 | * Representation of an execution's file info. 5 | * @category Workflow 6 | */ 7 | export class ExecutionFile { 8 | 9 | /** File name. */ 10 | name: string|null; 11 | 12 | /** Optional alias for the fil. */ 13 | alias: string|null; 14 | 15 | constructor(jsonResponse: StringDict) { 16 | this.name = jsonResponse["name"]; 17 | this.alias = jsonResponse["alias"]; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/parsing/common/executionPriority.ts: -------------------------------------------------------------------------------- 1 | export enum ExecutionPriority { 2 | low = "low", 3 | medium = "medium", 4 | high = "high" 5 | } 6 | -------------------------------------------------------------------------------- /src/parsing/common/extras/cropperExtra.ts: -------------------------------------------------------------------------------- 1 | import { PositionField } from "../../standard"; 2 | import { StringDict } from "../stringDict"; 3 | import { cleanOutString } from "../summaryHelper"; 4 | import { ExtraField } from "./extras"; 5 | 6 | export class CropperExtra extends ExtraField { 7 | cropping: PositionField[] = []; 8 | constructor(rawPrediction: StringDict, pageId?: number) { 9 | super(); 10 | rawPrediction["cropping"] !== undefined && 11 | rawPrediction["cropping"].forEach((crop: any) => { 12 | this.cropping.push( 13 | new PositionField({ 14 | prediction: crop, 15 | pageId: pageId, 16 | }) 17 | ); 18 | }); 19 | } 20 | 21 | /** 22 | * Default string representation. 23 | */ 24 | toString() { 25 | const cropping = this.cropping 26 | .map((crop) => crop.toString()) 27 | .join("\n "); 28 | return cleanOutString(cropping); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/parsing/common/extras/extras.ts: -------------------------------------------------------------------------------- 1 | export abstract class ExtraField { 2 | } 3 | 4 | interface ExtraDict { 5 | [key: string]: T | (() => string); 6 | } 7 | 8 | export class Extras 9 | implements ExtraDict { 10 | [key: string]: ExtraT | (() => string); 11 | 12 | constructor(fields: Record) { 13 | Object.keys(fields).length > 0 && 14 | Object.keys(fields).forEach( 15 | (name: string) => (this[name] = fields[name]) 16 | ); 17 | } 18 | 19 | /** 20 | * Default string representation. 21 | */ 22 | toString(): string { 23 | return ( 24 | Object.entries(this) 25 | .map(([name, extraField]) => name + ":\n" + extraField.toString()) 26 | .join("\n") + "\n" 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/parsing/common/extras/fullTextOcrExtra.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../stringDict"; 2 | import { ExtraField } from "./extras"; 3 | 4 | export class FullTextOcrExtra extends ExtraField { 5 | content?: string; 6 | languages?: string; 7 | 8 | constructor(rawPrediction: StringDict) { 9 | super(); 10 | if (rawPrediction["content"]) { 11 | this.content = "content" in rawPrediction ? rawPrediction["content"] : ""; 12 | this.languages = "languages" in rawPrediction ? rawPrediction["languages"] : ""; 13 | } 14 | } 15 | 16 | /** 17 | * Default string representation. 18 | */ 19 | toString() { 20 | return this.content !== undefined ? this.content : ""; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/parsing/common/extras/index.ts: -------------------------------------------------------------------------------- 1 | export { CropperExtra } from "./cropperExtra"; 2 | export { Extras } from "./extras"; 3 | export { FullTextOcrExtra } from "./fullTextOcrExtra"; 4 | -------------------------------------------------------------------------------- /src/parsing/common/extras/ragExtra.ts: -------------------------------------------------------------------------------- 1 | import { ExtraField } from "./extras"; 2 | import { StringDict } from "../stringDict"; 3 | 4 | export class RAGExtra extends ExtraField { 5 | /** 6 | * ID reference of the document matched by the Retrieval-Augmented Generation. 7 | */ 8 | matchingDocumentId?: string; 9 | 10 | constructor(rawPrediction: StringDict) { 11 | super(); 12 | if (rawPrediction["matching_document_id"]) { 13 | this.matchingDocumentId = rawPrediction["matching_document_id"]; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/parsing/common/feedback/feedbackResponse.ts: -------------------------------------------------------------------------------- 1 | import { ApiResponse } from "../apiResponse"; 2 | import { StringDict } from "../stringDict"; 3 | 4 | /** 5 | * Wrapper for feedback response. 6 | * @category API Response 7 | * @category Synchronous 8 | */ 9 | export class FeedbackResponse extends ApiResponse { 10 | /** A document feedback response. */ 11 | feedback: StringDict; 12 | 13 | /** 14 | * @param serverResponse JSON response from the server. 15 | */ 16 | constructor( 17 | serverResponse: StringDict 18 | ) { 19 | super(serverResponse); 20 | this.feedback = serverResponse["feedback"]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/parsing/common/index.ts: -------------------------------------------------------------------------------- 1 | export { Document } from "./document"; 2 | export { Execution } from "./execution"; 3 | export { ExecutionFile } from "./executionFile"; 4 | export { ExecutionPriority } from "./executionPriority"; 5 | export { Inference } from "./inference"; 6 | export { FeedbackResponse } from "./feedback/feedbackResponse"; 7 | export { OrientationField } from "./orientation"; 8 | export { StringDict } from "./stringDict"; 9 | export { AsyncPredictResponse } from "./asyncPredictResponse"; 10 | export { PredictResponse } from "./predictResponse"; 11 | export { Prediction } from "./prediction"; 12 | export { Page } from "./page"; 13 | export { cleanOutString, lineSeparator } from "./summaryHelper"; 14 | export * as extras from "./extras"; 15 | export { floatToString, cleanSpecialChars } from "./summaryHelper"; 16 | -------------------------------------------------------------------------------- /src/parsing/common/mvisionV1.ts: -------------------------------------------------------------------------------- 1 | import { Word } from "../standard"; 2 | import { StringDict } from "./stringDict"; 3 | import { OcrPage } from "./ocrPage"; 4 | 5 | export class MvisionV1 { 6 | /** List of words found on the page. */ 7 | pages: OcrPage[] = []; 8 | 9 | constructor(rawPrediction: StringDict) { 10 | rawPrediction["pages"].map((page: Word) => { 11 | this.pages.push(new OcrPage(page)); 12 | }); 13 | } 14 | /** 15 | * Default string representation. 16 | */ 17 | toString(): string { 18 | return this.pages.map((page: OcrPage) => page.toString()).join("\n") + "\n"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/parsing/common/ocr.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "./stringDict"; 2 | import { MvisionV1 } from "./mvisionV1"; 3 | 4 | export class Ocr { 5 | /** Default Mindee OCR */ 6 | mVisionV1: MvisionV1; 7 | 8 | constructor(rawPrediction: StringDict) { 9 | this.mVisionV1 = new MvisionV1(rawPrediction["mvision-v1"]); 10 | } 11 | 12 | /** 13 | * Default string representation. 14 | */ 15 | toString() { 16 | return this.mVisionV1.toString(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/parsing/common/orientation.ts: -------------------------------------------------------------------------------- 1 | import { BaseField, BaseFieldConstructor } from "../standard"; 2 | 3 | interface OrientationFieldConstructor extends BaseFieldConstructor { 4 | pageId: number; 5 | } 6 | 7 | /** 8 | * The clockwise rotation to apply (in degrees) to make the image upright. 9 | */ 10 | export class OrientationField extends BaseField { 11 | /** Degrees of the rotation. */ 12 | value: number; 13 | /** Page id. */ 14 | pageId!: number; 15 | 16 | /** 17 | * @param {OrientationFieldConstructor} constructor Constructor parameters. 18 | */ 19 | constructor({ 20 | prediction = {}, 21 | valueKey = "value", 22 | reconstructed = false, 23 | pageId, 24 | }: OrientationFieldConstructor) { 25 | super({ prediction, valueKey, reconstructed }); 26 | const orientations = [0, 90, 180, 270]; 27 | this.pageId = pageId; 28 | this.value = parseInt(prediction[valueKey]); 29 | if (!orientations.includes(this.value)) this.value = 0; 30 | } 31 | 32 | /** 33 | * Default string representation. 34 | */ 35 | toString() { 36 | return `${this.value} degrees`; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/parsing/common/predictResponse.ts: -------------------------------------------------------------------------------- 1 | import { ApiResponse } from "./apiResponse"; 2 | import { Document, Inference, StringDict } from "."; 3 | 4 | /** Wrapper for synchronous prediction response. 5 | * 6 | * @category API Response 7 | * @category Synchronous 8 | */ 9 | export class PredictResponse extends ApiResponse { 10 | /** A document prediction response. */ 11 | document: Document; 12 | 13 | /** 14 | * 15 | * @param inferenceClass constructor signature for an inference. 16 | * @param serverResponse raw http response. 17 | */ 18 | constructor( 19 | inferenceClass: new (serverResponse: StringDict) => T, 20 | serverResponse: StringDict 21 | ) { 22 | super(serverResponse); 23 | this.document = new Document(inferenceClass, serverResponse["document"]); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/parsing/common/prediction.ts: -------------------------------------------------------------------------------- 1 | export class Prediction {} 2 | -------------------------------------------------------------------------------- /src/parsing/common/product.ts: -------------------------------------------------------------------------------- 1 | export interface Product { 2 | name?: string; 3 | version?: string; 4 | } 5 | -------------------------------------------------------------------------------- /src/parsing/common/stringDict.ts: -------------------------------------------------------------------------------- 1 | export type StringDict = { [index: string]: any }; 2 | -------------------------------------------------------------------------------- /src/parsing/common/summaryHelper.ts: -------------------------------------------------------------------------------- 1 | export function cleanOutString(outStr: string): string { 2 | const lines = / \n/gm; 3 | return outStr.replace(lines, "\n"); 4 | } 5 | 6 | /** 7 | * 8 | * @param columnSizes Size of each column in the table 9 | * @param separator character for a separator 10 | * @returns A separator for table lines 11 | */ 12 | export function lineSeparator(columnSizes: number[], separator: string) { 13 | let outStr: string = " +"; 14 | columnSizes.forEach((size: number) => { 15 | outStr += separator.repeat(size) + "+"; 16 | }); 17 | return outStr; 18 | } 19 | 20 | /** 21 | * Replaces all special characters like \n, \r, \t, with an equivalent that can be displayed on a single line. 22 | * Also trims line breaks at the end of the string. 23 | * @param outStr 24 | */ 25 | export function cleanSpecialChars(outStr: string) { 26 | return outStr 27 | .replace(/\n/g, "\\n") 28 | .replace(/\r/g, "\\r") 29 | .replace(/\t/g, "\\t"); 30 | } 31 | 32 | /** 33 | * Return a float as a string with at least 2 levels of precision. 34 | */ 35 | export function floatToString(value: number|null) { 36 | if (value === null){ 37 | return ""; 38 | } 39 | return value.toLocaleString(undefined, { 40 | minimumFractionDigits: 2, 41 | maximumFractionDigits: 5, 42 | useGrouping: false, 43 | }); 44 | } 45 | -------------------------------------------------------------------------------- /src/parsing/common/workflowResponse.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "./stringDict"; 2 | import { ApiResponse } from "./apiResponse"; 3 | import { Execution } from "./execution"; 4 | import { Inference } from "./inference"; 5 | 6 | 7 | /** Wrapper for workflow requests. 8 | * 9 | * @category API Response 10 | * @category Workflow 11 | */ 12 | export class WorkflowResponse extends ApiResponse { 13 | /** 14 | * Set the prediction model used to parse the document. 15 | * The response object will be instantiated based on this parameter. 16 | */ 17 | execution: Execution; 18 | 19 | constructor(inferenceClass: new (serverResponse: StringDict) => T, serverResponse: StringDict) { 20 | super(serverResponse); 21 | this.execution = new Execution(inferenceClass, serverResponse["execution"]); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/parsing/custom/classificationField.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../common"; 2 | 3 | export class ClassificationField { 4 | /** The value for the classification. */ 5 | value: string; 6 | /** 7 | * The confidence score of the prediction. 8 | * Note: Score is calculated on **word selection**, not its textual content (OCR). 9 | */ 10 | confidence: number; 11 | pageId?: number; 12 | constructor({ 13 | prediction, 14 | pageId, 15 | }: { 16 | prediction: StringDict; 17 | pageId?: number; 18 | }) { 19 | this.value = prediction["value"]; 20 | this.confidence = prediction["confidence"]; 21 | this.pageId ??= pageId; 22 | } 23 | 24 | /** 25 | * Default string representation. 26 | */ 27 | toString(): string { 28 | return `${this.value}`; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/parsing/custom/index.ts: -------------------------------------------------------------------------------- 1 | export { CustomLine, CustomLines, getLineItems } from "./lineItems"; 2 | export { ClassificationField } from "./classificationField"; 3 | export { ListField, ListFieldValue } from "./listField"; 4 | -------------------------------------------------------------------------------- /src/parsing/generated/generatedList.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../common"; 2 | import { StringField } from "../standard"; 3 | import { GeneratedObjectField, isGeneratedObject } from "./generatedObject"; 4 | 5 | export interface GeneratedListFieldConstructor { 6 | prediction: StringDict[]; 7 | pageId?: number; 8 | } 9 | 10 | /** 11 | * A list of values or objects, used in generated APIs. 12 | */ 13 | export class GeneratedListField { 14 | /** Id of the page the object was found on. */ 15 | pageId?: number; 16 | /** List of word values. */ 17 | values: Array; 18 | 19 | constructor({ 20 | prediction = [], 21 | pageId = undefined, 22 | }: GeneratedListFieldConstructor) { 23 | this.values = []; 24 | 25 | for (const value of prediction) { 26 | if (value["page_id"] !== undefined && value["page_id"] !== null) { 27 | this.pageId = value["page_id"]; 28 | } 29 | if (isGeneratedObject(value)) { 30 | this.values.push(new GeneratedObjectField({ prediction: value, pageId })); 31 | } 32 | else { 33 | const valueStr: StringDict = { ...value }; 34 | if (valueStr["value"] !== null && valueStr["value"] !== undefined) { 35 | valueStr["value"] = value["value"].toString(); 36 | } 37 | this.values.push(new StringField({ prediction: valueStr, pageId: pageId })); 38 | } 39 | } 40 | } 41 | /** 42 | * Returns an array of the contents of all values. 43 | */ 44 | contentsList(): string[] { 45 | return this.values.map((item) => item.toString()); 46 | } 47 | 48 | /** 49 | * Return a string representation of all values. 50 | * @param separator Character(s) to use when concatenating fields. 51 | * @returns string representation. 52 | */ 53 | contentsString(separator: string = " "): string { 54 | return this.contentsList().map((item) => `${item.toString()}`).join(separator); 55 | } 56 | 57 | /** 58 | * Default string representation. 59 | */ 60 | toString(): string { 61 | return this.contentsString(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/parsing/generated/index.ts: -------------------------------------------------------------------------------- 1 | export { GeneratedObjectField, isGeneratedObject } from "./generatedObject"; 2 | export { GeneratedListField } from "./generatedList"; 3 | -------------------------------------------------------------------------------- /src/parsing/index.ts: -------------------------------------------------------------------------------- 1 | export * as common from "./common"; 2 | export * as custom from "./custom"; 3 | export * as standard from "./standard"; 4 | export * as generated from "./generated"; 5 | -------------------------------------------------------------------------------- /src/parsing/standard/addressField.ts: -------------------------------------------------------------------------------- 1 | import { StringField, FieldConstructor } from "./text"; 2 | 3 | /** 4 | * A field containing a detailed address value broken down into components 5 | * (street number, city, postal code, …) while still exposing the full 6 | * address string through {@link StringField.value}. 7 | */ 8 | export class AddressField extends StringField { 9 | /** Street number. */ 10 | streetNumber?: string; 11 | /** Street name. */ 12 | streetName?: string; 13 | /** PO-box number. */ 14 | poBox?: string; 15 | /** Additional address complement. */ 16 | addressComplement?: string; 17 | /** City or locality. */ 18 | city?: string; 19 | /** Postal / ZIP code. */ 20 | postalCode?: string; 21 | /** State, province or region. */ 22 | state?: string; 23 | /** Country. */ 24 | country?: string; 25 | 26 | constructor({ 27 | prediction = {}, 28 | valueKey = "value", 29 | reconstructed = false, 30 | pageId, 31 | }: FieldConstructor) { 32 | super({ prediction, valueKey, reconstructed, pageId }); 33 | 34 | // Populate the sub-components if they exist in the prediction object 35 | if (prediction["street_number"]) { 36 | this.streetNumber = prediction["street_number"] as string; 37 | } 38 | if (prediction["street_name"]) { 39 | this.streetName = prediction["street_name"] as string; 40 | } 41 | if (prediction["po_box"]) { 42 | this.poBox = prediction["po_box"] as string; 43 | } 44 | if (prediction["address_complement"]) { 45 | this.addressComplement = prediction["address_complement"] as string; 46 | } 47 | if (prediction["city"]) { 48 | this.city = prediction["city"] as string; 49 | } 50 | if (prediction["postal_code"]) { 51 | this.postalCode = prediction["postal_code"] as string; 52 | } 53 | if (prediction["state"]) { 54 | this.state = prediction["state"] as string; 55 | } 56 | if (prediction["country"]) { 57 | this.country = prediction["country"] as string; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/parsing/standard/amount.ts: -------------------------------------------------------------------------------- 1 | import { Field } from "./field"; 2 | import { BaseFieldConstructor } from "./base"; 3 | import { floatToString } from "../common"; 4 | 5 | /** 6 | * A field containing an amount value. 7 | */ 8 | export class AmountField extends Field { 9 | /** The value. */ 10 | value?: number = undefined; 11 | 12 | /** 13 | * @param {BaseFieldConstructor} constructor Constructor parameters. 14 | */ 15 | constructor({ 16 | prediction = {}, 17 | valueKey = "value", 18 | reconstructed = false, 19 | pageId = undefined, 20 | }: BaseFieldConstructor) { 21 | super({ prediction, valueKey, reconstructed, pageId }); 22 | this.value = +parseFloat(prediction[valueKey]); 23 | if (isNaN(this.value)) { 24 | this.value = undefined; 25 | this.confidence = 0.0; 26 | } 27 | } 28 | 29 | /** 30 | * Default string representation. 31 | */ 32 | toString(): string { 33 | if (this.value !== undefined) { 34 | return floatToString(this.value); 35 | } 36 | return ""; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/parsing/standard/base.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../common"; 2 | 3 | /** 4 | * @property {object} prediction - Prediction object from HTTP response. 5 | * @property {string} valueKey - Key to use in the prediction dict. 6 | * @property {boolean} reconstructed - Is the object reconstructed (not extracted by the API). 7 | * @property {number} pageId - Page ID for multi-page document. 8 | */ 9 | export interface BaseFieldConstructor { 10 | prediction: StringDict; 11 | valueKey?: string; 12 | reconstructed?: boolean; 13 | pageId?: number; 14 | } 15 | 16 | /** 17 | * Base class for most fields. 18 | */ 19 | export class BaseField { 20 | /** The value. */ 21 | value?: string | number | boolean = undefined; 22 | /** `true` when the field was reconstructed or computed using other fields. */ 23 | reconstructed: boolean; 24 | /** Page ID for multi-page document. */ 25 | pageId?: number; 26 | 27 | /** 28 | * @param {BaseFieldConstructor} constructor Constructor parameters. 29 | */ 30 | constructor({ 31 | prediction = {}, 32 | valueKey = "value", 33 | reconstructed = false, 34 | pageId=undefined, 35 | }: BaseFieldConstructor) { 36 | this.reconstructed = reconstructed; 37 | if ( 38 | prediction !== undefined && 39 | prediction !== null && 40 | valueKey in prediction && 41 | prediction[valueKey] !== null 42 | ) { 43 | this.value = prediction[valueKey]; 44 | this.pageId = pageId !== undefined ? pageId : prediction["page_id"]; 45 | } 46 | } 47 | 48 | compare(other: BaseField) { 49 | if (this.value === null && other.value === null) return true; 50 | if (this.value === null || other.value === null) return false; 51 | if (typeof this.value === "string" && typeof other.value === "string") { 52 | return this.value.toLowerCase() === other.value.toLowerCase(); 53 | } 54 | return this.value === other.value; 55 | } 56 | 57 | /** 58 | * @param {BaseField[]} array - Array of Fields 59 | * @returns {number} Sum of all the Fields values in the array 60 | */ 61 | static arraySum(array: BaseField[]): number { 62 | let total = 0.0; 63 | for (const field of array) { 64 | if (typeof field.value !== "number") return 0.0; 65 | total += field.value; 66 | if (isNaN(total)) return 0.0; 67 | } 68 | return total; 69 | } 70 | 71 | /** 72 | * Default string representation. 73 | */ 74 | toString(): string { 75 | if (this.value !== undefined) { 76 | return `${this.value}`; 77 | } 78 | return ""; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/parsing/standard/boolean.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../common"; 2 | import { Field } from "./field"; 3 | 4 | export interface FieldConstructor { 5 | prediction: StringDict; 6 | valueKey?: string; 7 | reconstructed?: boolean; 8 | pageId?: number | undefined; 9 | } 10 | 11 | /** 12 | * A field containing a text value. 13 | */ 14 | export class BooleanField extends Field { 15 | /** The value. */ 16 | value?: boolean; 17 | 18 | constructor({ 19 | prediction = {}, 20 | valueKey = "value", 21 | reconstructed = false, 22 | pageId, 23 | }: FieldConstructor) { 24 | super({ prediction, valueKey, reconstructed, pageId }); 25 | } 26 | 27 | toString(): string { 28 | if (this.value === true) { 29 | return "True"; 30 | } else if (this.value === false) { 31 | return "False"; 32 | } 33 | return ""; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/parsing/standard/classification.ts: -------------------------------------------------------------------------------- 1 | import { BaseField, BaseFieldConstructor } from "./base"; 2 | 3 | /** 4 | * Represents a classifier value. 5 | */ 6 | export class ClassificationField extends BaseField { 7 | /** The confidence score of the prediction. */ 8 | confidence: number; 9 | /** The classification. */ 10 | value?: string; 11 | 12 | constructor({ 13 | prediction = {}, 14 | valueKey = "value", 15 | reconstructed = false, 16 | pageId=undefined, 17 | }: BaseFieldConstructor) { 18 | super({ prediction, valueKey, reconstructed, pageId }); 19 | this.confidence = prediction["confidence"] ? prediction["confidence"] : 0.0; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/parsing/standard/companyRegistration.ts: -------------------------------------------------------------------------------- 1 | import { Field } from "./field"; 2 | import { BaseFieldConstructor } from "./base"; 3 | import { cleanOutString } from "../common"; 4 | 5 | /** 6 | * A company registration item. 7 | */ 8 | export class CompanyRegistrationField extends Field { 9 | /** Registration identifier. */ 10 | value?: string; 11 | /** Type of company registration. */ 12 | type: string; 13 | 14 | constructor({ 15 | prediction = {}, 16 | valueKey = "value", 17 | reconstructed = false, 18 | pageId, 19 | }: BaseFieldConstructor) { 20 | super({ prediction, valueKey, reconstructed, pageId }); 21 | this.type = prediction["type"]; 22 | } 23 | toTableLine(): string { 24 | const printable = this.printableValues(); 25 | return `| ${printable["type"].padEnd(15)} | ${printable["value"].padEnd(20)} `; 26 | } 27 | toString(): string { 28 | const printable = this.printableValues(); 29 | return `Type: ${printable["type"]}, Value: ${printable["value"]}`; 30 | } 31 | private printableValues(): { [key: string]: string } { 32 | const printable: { [key: string]: string } = {}; 33 | printable["type"] = cleanOutString(this.type); 34 | printable["value"] = cleanOutString((this.value ?? "").toString()); 35 | return printable; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/parsing/standard/date.ts: -------------------------------------------------------------------------------- 1 | import { Field } from "./field"; 2 | import { BaseFieldConstructor } from "./base"; 3 | 4 | /** 5 | * A field containing a date value. 6 | */ 7 | export class DateField extends Field { 8 | /** Date string in ISO format. */ 9 | value?: string; 10 | /** Date as a standard JavaScript `Date` object. */ 11 | public dateObject?: Date; 12 | /** Whether the field was computed or retrieved directly from the document. */ 13 | public isComputed?: boolean; 14 | 15 | /** 16 | * @param {BaseFieldConstructor} constructor Constructor parameters. 17 | */ 18 | constructor({ 19 | prediction = {}, 20 | valueKey = "value", 21 | reconstructed = false, 22 | pageId, 23 | }: BaseFieldConstructor) { 24 | super({ prediction, valueKey, reconstructed, pageId }); 25 | if ("is_computed" in prediction) 26 | { 27 | this.isComputed = prediction["is_computed"]; 28 | } 29 | if (typeof this.value === "string") { 30 | this.dateObject = new Date(this.value); 31 | if (isNaN(this.dateObject.valueOf())) { 32 | this.dateObject = undefined; 33 | this.confidence = 0.0; 34 | this.value = undefined; 35 | } else { 36 | this.dateObject.setUTCHours(0, 0, 0, 0); 37 | } 38 | } 39 | } 40 | 41 | static compareDates(date1: Date, date2: Date): boolean { 42 | return date1.getFullYear() === date2.getFullYear() && 43 | date1.getMonth() === date2.getMonth() && 44 | date1.getDate() === date2.getDate(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/parsing/standard/field.ts: -------------------------------------------------------------------------------- 1 | import { BaseField, BaseFieldConstructor } from "./base"; 2 | import { Polygon, BoundingBox, getBoundingBox } from "../../geometry"; 3 | 4 | /** 5 | * A basic field with position and page information. 6 | */ 7 | export class Field extends BaseField { 8 | /** 9 | * Contains exactly 4 relative vertices coordinates (points) of a right 10 | * rectangle containing the field in the document. 11 | */ 12 | boundingBox: BoundingBox; 13 | /** 14 | * Contains the relative vertices coordinates (points) of a polygon containing 15 | * the field in the document. 16 | */ 17 | polygon: Polygon = []; 18 | /** The confidence score of the prediction. */ 19 | confidence: number; 20 | 21 | /** 22 | * @param {BaseFieldConstructor} constructor Constructor parameters. 23 | */ 24 | constructor({ 25 | prediction = {}, 26 | valueKey = "value", 27 | reconstructed = false, 28 | pageId, 29 | }: BaseFieldConstructor) { 30 | super({ prediction, valueKey, reconstructed, pageId }); 31 | 32 | this.confidence = prediction["confidence"] ? prediction["confidence"] : 0.0; 33 | if (prediction["polygon"]) { 34 | this.polygon = prediction["polygon"]; 35 | } 36 | this.boundingBox = getBoundingBox(this.polygon); 37 | } 38 | 39 | /** 40 | @param array1 first Array of Fields 41 | @param array2 second Array of Fields 42 | @param attr Attribute to compare 43 | @returns true if all elements in array1 exist in array2 and vice-versa, false otherwise 44 | */ 45 | static compareArrays( 46 | array1: Field[], 47 | array2: Field[], 48 | attr: string = "value" 49 | ): boolean { 50 | const list1 = array1.map((item: any) => item[attr]); 51 | const list2 = array2.map((item: any) => item[attr]); 52 | if (list1.length !== list2.length) return false; 53 | for (const item1 of list1) { 54 | if (!list2.includes(item1)) return false; 55 | } 56 | return true; 57 | } 58 | 59 | /** 60 | * @param {Field[]} array - Array of Fields 61 | * @returns {number} product of all the fields probability 62 | */ 63 | static arrayConfidence(array: Field[]): number { 64 | let total = 1.0; 65 | for (const field of array) { 66 | total *= field.confidence; 67 | if (isNaN(total)) return 0.0; 68 | } 69 | return total; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/parsing/standard/index.ts: -------------------------------------------------------------------------------- 1 | export { AddressField } from "./addressField"; 2 | export { AmountField } from "./amount"; 3 | export { BaseField, BaseFieldConstructor } from "./base"; 4 | export { BooleanField } from "./boolean"; 5 | export { ClassificationField } from "./classification"; 6 | export { CompanyRegistrationField } from "./companyRegistration"; 7 | export { DateField } from "./date"; 8 | export { LocaleField } from "./locale"; 9 | export { Field } from "./field"; 10 | export { Taxes, TaxField } from "./tax"; 11 | export { StringField } from "./text"; 12 | export { PaymentDetailsField } from "./paymentDetails"; 13 | export { PositionField } from "./position"; 14 | export { Word } from "./word"; 15 | -------------------------------------------------------------------------------- /src/parsing/standard/locale.ts: -------------------------------------------------------------------------------- 1 | import { BaseField, BaseFieldConstructor } from "./base"; 2 | 3 | /** 4 | * The locale detected on the document. 5 | */ 6 | export class LocaleField extends BaseField { 7 | /** Locale in ISO format. */ 8 | value?: string; 9 | /** The confidence score of the prediction. */ 10 | confidence: number; 11 | /** ISO 639-1 language code */ 12 | language?: string; 13 | /** ISO 3166-1 alpha-2 (or alpha-3) country code */ 14 | country?: string; 15 | /** ISO 4217 currency code */ 16 | currency?: string; 17 | 18 | /** 19 | * @param {BaseFieldConstructor} constructor Constructor parameters. 20 | */ 21 | constructor({ 22 | prediction = {}, 23 | reconstructed = false, 24 | pageId=undefined, 25 | }: BaseFieldConstructor) { 26 | const valueKey = prediction["value"] ? "value" : "language"; 27 | super({ prediction, valueKey, reconstructed, pageId }); 28 | 29 | this.confidence = prediction["confidence"] ? prediction["confidence"] : 0.0; 30 | this.language = 31 | prediction["language"] !== undefined ? prediction["language"] : undefined; 32 | this.country = 33 | prediction["country"] !== undefined ? prediction["country"] : undefined; 34 | this.currency = 35 | prediction["currency"] !== undefined ? prediction["currency"] : undefined; 36 | } 37 | 38 | /** 39 | * Default string representation. 40 | */ 41 | toString(): string { 42 | let outStr = ""; 43 | if (this.value) { 44 | outStr += `${this.value}; `; 45 | } 46 | if (this.language) { 47 | outStr += `${this.language}; `; 48 | } 49 | if (this.country) { 50 | outStr += `${this.country}; `; 51 | } 52 | if (this.currency) { 53 | outStr += `${this.currency};`; 54 | } 55 | return outStr.trimEnd(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/parsing/standard/position.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../common"; 2 | import { Polygon } from "../../geometry"; 3 | 4 | export interface PositionFieldConstructor { 5 | prediction: StringDict; 6 | valueKey?: string; 7 | pageId?: number | undefined; 8 | } 9 | 10 | /** 11 | * A field indicating a position or area on the document. 12 | */ 13 | export class PositionField { 14 | /** Straight rectangle. */ 15 | boundingBox: Polygon; 16 | /** Free polygon with up to 30 vertices. */ 17 | polygon: Polygon; 18 | /** Free polygon with 4 vertices. */ 19 | quadrangle: Polygon; 20 | /** Rectangle that may be oriented (can go beyond the canvas). */ 21 | rectangle: Polygon; 22 | /** The document page on which the information was found. */ 23 | pageId: number | undefined; 24 | 25 | constructor({ prediction = {}, pageId }: PositionFieldConstructor) { 26 | this.pageId = pageId; 27 | this.boundingBox = "bounding_box" in prediction ? prediction["bounding_box"] : []; 28 | this.polygon = "polygon" in prediction ? prediction["polygon"] : []; 29 | this.quadrangle = "quadrangle" in prediction ? prediction["quadrangle"] : []; 30 | this.rectangle = "rectangle" in prediction ? prediction["rectangle"] : []; 31 | } 32 | 33 | /** 34 | * Default string representation. 35 | */ 36 | toString(): string { 37 | if (this.polygon && this.polygon.length > 0) 38 | return `Polygon with ${this.polygon.length} points.`; 39 | if (this.boundingBox && this.boundingBox.length > 0) { 40 | return `Polygon with ${this.boundingBox.length} points.`; 41 | } 42 | if (this.rectangle && this.rectangle.length > 0) { 43 | return `Polygon with ${this.rectangle.length} points.`; 44 | } 45 | if (this.quadrangle && this.quadrangle.length > 0) { 46 | return `Polygon with ${this.quadrangle.length} points.`; 47 | } 48 | return ""; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/parsing/standard/text.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../common"; 2 | import { Field } from "./field"; 3 | 4 | export interface FieldConstructor { 5 | prediction: StringDict; 6 | valueKey?: string; 7 | reconstructed?: boolean; 8 | pageId?: number | undefined; 9 | } 10 | 11 | /** 12 | * A field containing a text value. 13 | */ 14 | export class StringField extends Field { 15 | /** The value. */ 16 | value?: string; 17 | /** Value as it appears on the document. */ 18 | rawValue?: string; 19 | 20 | constructor({ 21 | prediction = {}, 22 | valueKey = "value", 23 | reconstructed = false, 24 | pageId, 25 | }: FieldConstructor) { 26 | super({ prediction, valueKey, reconstructed, pageId }); 27 | if (prediction["raw_value"]) { 28 | this.rawValue = prediction["raw_value"]; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/parsing/standard/word.ts: -------------------------------------------------------------------------------- 1 | import * as geometry from "../../geometry"; 2 | 3 | export type Word = { 4 | /** 5 | * Contains the relative vertices coordinates (points) of a polygon containing 6 | * the field in the document. 7 | */ 8 | polygon: geometry.Polygon; 9 | text: string; 10 | confidence: number; 11 | }; 12 | -------------------------------------------------------------------------------- /src/pdf/index.ts: -------------------------------------------------------------------------------- 1 | export { extractPages, countPages, SplitPdf } from "./pdfOperation"; 2 | export { compressPdf } from "./pdfCompressor"; 3 | export { hasSourceText } from "./pdfUtils"; 4 | -------------------------------------------------------------------------------- /src/pdf/pdfUtils.ts: -------------------------------------------------------------------------------- 1 | import { PDFExtract, PDFExtractOptions, PDFExtractResult } from "pdf.js-extract"; 2 | import { MindeePdfError } from "../errors/mindeeError"; 3 | 4 | 5 | export interface PageTextInfo { 6 | pageNumber: number; 7 | content: Array<{ 8 | str: string; 9 | x: number; 10 | y: number; 11 | width: number; 12 | height: number; 13 | fontName: string; 14 | }>; 15 | } 16 | 17 | export interface ExtractedPdfInfo { 18 | pages: PageTextInfo[]; 19 | getConcatenatedText: () => string; 20 | } 21 | 22 | 23 | function getConcatenatedText(pages: PageTextInfo[]): string { 24 | return pages.flatMap( 25 | page => page.content.map( 26 | item => item.str) 27 | ).join(" "); 28 | } 29 | 30 | /** 31 | * Extracts text from a full PDF document. 32 | * 33 | * @returns A Promise containing the extracted text as a string. 34 | * @param pdfBuffer PDF handle, as a buffer. 35 | */ 36 | export async function extractTextFromPdf(pdfBuffer: Buffer): Promise { 37 | const pdfExtract = new PDFExtract(); 38 | const options: PDFExtractOptions = {}; 39 | 40 | const pdf = await new Promise((resolve, reject) => { 41 | pdfExtract.extractBuffer(pdfBuffer, options, (err, result) => { 42 | if (err) reject(err); 43 | if (result === undefined) 44 | reject(new MindeePdfError("Couldn't process result.")); 45 | else resolve(result); 46 | }); 47 | }); 48 | 49 | const pages = pdf.pages.map((page, index) => ({ 50 | pageNumber: index + 1, 51 | content: page.content.map(item => ({ 52 | str: item.str, 53 | x: item.x, 54 | y: item.y, 55 | width: item.width, 56 | height: item.height, 57 | fontName: item.fontName, 58 | })), 59 | })); 60 | 61 | return { 62 | pages, 63 | getConcatenatedText: () => getConcatenatedText(pages), 64 | }; 65 | } 66 | 67 | 68 | 69 | 70 | 71 | /** 72 | * Checks if a PDF contains source text. 73 | * 74 | * @param pdfData Buffer representing the content of the PDF file. 75 | * 76 | * @returns A Promise containing a boolean indicating if the PDF has source text. 77 | */ 78 | export async function hasSourceText(pdfData: Buffer): Promise { 79 | const text = await extractTextFromPdf(pdfData); 80 | return text.getConcatenatedText().trim().length > 0; 81 | } 82 | -------------------------------------------------------------------------------- /src/product/barcodeReader/barcodeReaderV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { BarcodeReaderV1Document } from "./barcodeReaderV1Document"; 3 | 4 | /** 5 | * Barcode Reader API version 1 inference prediction. 6 | */ 7 | export class BarcodeReaderV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "barcode_reader"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: BarcodeReaderV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new BarcodeReaderV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | BarcodeReaderV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/barcodeReader/barcodeReaderV1Document.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Prediction, 3 | StringDict, 4 | cleanOutString, 5 | } from "../../parsing/common"; 6 | import { StringField } from "../../parsing/standard"; 7 | 8 | /** 9 | * Barcode Reader API version 1.0 document data. 10 | */ 11 | export class BarcodeReaderV1Document implements Prediction { 12 | /** List of decoded 1D barcodes. */ 13 | codes1D: StringField[] = []; 14 | /** List of decoded 2D barcodes. */ 15 | codes2D: StringField[] = []; 16 | 17 | constructor(rawPrediction: StringDict, pageId?: number) { 18 | rawPrediction["codes_1d"] && 19 | rawPrediction["codes_1d"].map( 20 | (itemPrediction: StringDict) => 21 | this.codes1D.push( 22 | new StringField({ 23 | prediction: itemPrediction, 24 | pageId: pageId, 25 | }) 26 | ) 27 | ); 28 | rawPrediction["codes_2d"] && 29 | rawPrediction["codes_2d"].map( 30 | (itemPrediction: StringDict) => 31 | this.codes2D.push( 32 | new StringField({ 33 | prediction: itemPrediction, 34 | pageId: pageId, 35 | }) 36 | ) 37 | ); 38 | } 39 | 40 | /** 41 | * Default string representation. 42 | */ 43 | toString(): string { 44 | const codes1D = this.codes1D.join("\n "); 45 | const codes2D = this.codes2D.join("\n "); 46 | const outStr = `:Barcodes 1D: ${codes1D} 47 | :Barcodes 2D: ${codes2D}`.trimEnd(); 48 | return cleanOutString(outStr); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/product/barcodeReader/index.ts: -------------------------------------------------------------------------------- 1 | export { BarcodeReaderV1 } from "./barcodeReaderV1"; 2 | -------------------------------------------------------------------------------- /src/product/barcodeReader/internal.ts: -------------------------------------------------------------------------------- 1 | export { BarcodeReaderV1 } from "./barcodeReaderV1"; 2 | export { BarcodeReaderV1Document } from "./barcodeReaderV1Document"; 3 | -------------------------------------------------------------------------------- /src/product/billOfLading/billOfLadingV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { BillOfLadingV1Document } from "./billOfLadingV1Document"; 3 | 4 | /** 5 | * Bill of Lading API version 1 inference prediction. 6 | */ 7 | export class BillOfLadingV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "bill_of_lading"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: BillOfLadingV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new BillOfLadingV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | BillOfLadingV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/billOfLading/billOfLadingV1Carrier.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../parsing/common"; 2 | import { Polygon } from "../../geometry"; 3 | 4 | /** 5 | * The shipping company responsible for transporting the goods. 6 | */ 7 | export class BillOfLadingV1Carrier { 8 | /** The name of the carrier. */ 9 | name: string | null; 10 | /** The professional number of the carrier. */ 11 | professionalNumber: string | null; 12 | /** The Standard Carrier Alpha Code (SCAC) of the carrier. */ 13 | scac: string | null; 14 | /** Confidence score */ 15 | confidence: number = 0.0; 16 | /** The document page on which the information was found. */ 17 | pageId: number; 18 | /** 19 | * Contains the relative vertices coordinates (points) of a polygon containing 20 | * the field in the document. 21 | */ 22 | polygon: Polygon = []; 23 | 24 | constructor({ prediction = {} }: StringDict) { 25 | this.name = prediction["name"]; 26 | this.professionalNumber = prediction["professional_number"]; 27 | this.scac = prediction["scac"]; 28 | this.pageId = prediction["page_id"]; 29 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 30 | if (prediction["polygon"]) { 31 | this.polygon = prediction.polygon; 32 | } 33 | } 34 | 35 | /** 36 | * Collection of fields as representable strings. 37 | */ 38 | #printableValues() { 39 | return { 40 | name: this.name ?? "", 41 | professionalNumber: this.professionalNumber ?? "", 42 | scac: this.scac ?? "", 43 | }; 44 | } 45 | 46 | /** 47 | * Default string representation. 48 | */ 49 | toString(): string { 50 | const printable = this.#printableValues(); 51 | return ( 52 | "Name: " + 53 | printable.name + 54 | ", Professional Number: " + 55 | printable.professionalNumber + 56 | ", SCAC: " + 57 | printable.scac 58 | ); 59 | } 60 | 61 | /** 62 | * Output in a format suitable for inclusion in a field list. 63 | */ 64 | toFieldList(): string { 65 | const printable = this.#printableValues(); 66 | return ` 67 | :Name: ${printable.name} 68 | :Professional Number: ${printable.professionalNumber} 69 | :SCAC: ${printable.scac}`.trimEnd(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/product/billOfLading/billOfLadingV1Consignee.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../parsing/common"; 2 | import { Polygon } from "../../geometry"; 3 | 4 | /** 5 | * The party to whom the goods are being shipped. 6 | */ 7 | export class BillOfLadingV1Consignee { 8 | /** The address of the consignee. */ 9 | address: string | null; 10 | /** The email of the shipper. */ 11 | email: string | null; 12 | /** The name of the consignee. */ 13 | name: string | null; 14 | /** The phone number of the consignee. */ 15 | phone: string | null; 16 | /** Confidence score */ 17 | confidence: number = 0.0; 18 | /** The document page on which the information was found. */ 19 | pageId: number; 20 | /** 21 | * Contains the relative vertices coordinates (points) of a polygon containing 22 | * the field in the document. 23 | */ 24 | polygon: Polygon = []; 25 | 26 | constructor({ prediction = {} }: StringDict) { 27 | this.address = prediction["address"]; 28 | this.email = prediction["email"]; 29 | this.name = prediction["name"]; 30 | this.phone = prediction["phone"]; 31 | this.pageId = prediction["page_id"]; 32 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 33 | if (prediction["polygon"]) { 34 | this.polygon = prediction.polygon; 35 | } 36 | } 37 | 38 | /** 39 | * Collection of fields as representable strings. 40 | */ 41 | #printableValues() { 42 | return { 43 | address: this.address ?? "", 44 | email: this.email ?? "", 45 | name: this.name ?? "", 46 | phone: this.phone ?? "", 47 | }; 48 | } 49 | 50 | /** 51 | * Default string representation. 52 | */ 53 | toString(): string { 54 | const printable = this.#printableValues(); 55 | return ( 56 | "Address: " + 57 | printable.address + 58 | ", Email: " + 59 | printable.email + 60 | ", Name: " + 61 | printable.name + 62 | ", Phone: " + 63 | printable.phone 64 | ); 65 | } 66 | 67 | /** 68 | * Output in a format suitable for inclusion in a field list. 69 | */ 70 | toFieldList(): string { 71 | const printable = this.#printableValues(); 72 | return ` 73 | :Address: ${printable.address} 74 | :Email: ${printable.email} 75 | :Name: ${printable.name} 76 | :Phone: ${printable.phone}`.trimEnd(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/product/billOfLading/billOfLadingV1NotifyParty.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../parsing/common"; 2 | import { Polygon } from "../../geometry"; 3 | 4 | /** 5 | * The party to be notified of the arrival of the goods. 6 | */ 7 | export class BillOfLadingV1NotifyParty { 8 | /** The address of the notify party. */ 9 | address: string | null; 10 | /** The email of the shipper. */ 11 | email: string | null; 12 | /** The name of the notify party. */ 13 | name: string | null; 14 | /** The phone number of the notify party. */ 15 | phone: string | null; 16 | /** Confidence score */ 17 | confidence: number = 0.0; 18 | /** The document page on which the information was found. */ 19 | pageId: number; 20 | /** 21 | * Contains the relative vertices coordinates (points) of a polygon containing 22 | * the field in the document. 23 | */ 24 | polygon: Polygon = []; 25 | 26 | constructor({ prediction = {} }: StringDict) { 27 | this.address = prediction["address"]; 28 | this.email = prediction["email"]; 29 | this.name = prediction["name"]; 30 | this.phone = prediction["phone"]; 31 | this.pageId = prediction["page_id"]; 32 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 33 | if (prediction["polygon"]) { 34 | this.polygon = prediction.polygon; 35 | } 36 | } 37 | 38 | /** 39 | * Collection of fields as representable strings. 40 | */ 41 | #printableValues() { 42 | return { 43 | address: this.address ?? "", 44 | email: this.email ?? "", 45 | name: this.name ?? "", 46 | phone: this.phone ?? "", 47 | }; 48 | } 49 | 50 | /** 51 | * Default string representation. 52 | */ 53 | toString(): string { 54 | const printable = this.#printableValues(); 55 | return ( 56 | "Address: " + 57 | printable.address + 58 | ", Email: " + 59 | printable.email + 60 | ", Name: " + 61 | printable.name + 62 | ", Phone: " + 63 | printable.phone 64 | ); 65 | } 66 | 67 | /** 68 | * Output in a format suitable for inclusion in a field list. 69 | */ 70 | toFieldList(): string { 71 | const printable = this.#printableValues(); 72 | return ` 73 | :Address: ${printable.address} 74 | :Email: ${printable.email} 75 | :Name: ${printable.name} 76 | :Phone: ${printable.phone}`.trimEnd(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/product/billOfLading/billOfLadingV1Shipper.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../parsing/common"; 2 | import { Polygon } from "../../geometry"; 3 | 4 | /** 5 | * The party responsible for shipping the goods. 6 | */ 7 | export class BillOfLadingV1Shipper { 8 | /** The address of the shipper. */ 9 | address: string | null; 10 | /** The email of the shipper. */ 11 | email: string | null; 12 | /** The name of the shipper. */ 13 | name: string | null; 14 | /** The phone number of the shipper. */ 15 | phone: string | null; 16 | /** Confidence score */ 17 | confidence: number = 0.0; 18 | /** The document page on which the information was found. */ 19 | pageId: number; 20 | /** 21 | * Contains the relative vertices coordinates (points) of a polygon containing 22 | * the field in the document. 23 | */ 24 | polygon: Polygon = []; 25 | 26 | constructor({ prediction = {} }: StringDict) { 27 | this.address = prediction["address"]; 28 | this.email = prediction["email"]; 29 | this.name = prediction["name"]; 30 | this.phone = prediction["phone"]; 31 | this.pageId = prediction["page_id"]; 32 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 33 | if (prediction["polygon"]) { 34 | this.polygon = prediction.polygon; 35 | } 36 | } 37 | 38 | /** 39 | * Collection of fields as representable strings. 40 | */ 41 | #printableValues() { 42 | return { 43 | address: this.address ?? "", 44 | email: this.email ?? "", 45 | name: this.name ?? "", 46 | phone: this.phone ?? "", 47 | }; 48 | } 49 | 50 | /** 51 | * Default string representation. 52 | */ 53 | toString(): string { 54 | const printable = this.#printableValues(); 55 | return ( 56 | "Address: " + 57 | printable.address + 58 | ", Email: " + 59 | printable.email + 60 | ", Name: " + 61 | printable.name + 62 | ", Phone: " + 63 | printable.phone 64 | ); 65 | } 66 | 67 | /** 68 | * Output in a format suitable for inclusion in a field list. 69 | */ 70 | toFieldList(): string { 71 | const printable = this.#printableValues(); 72 | return ` 73 | :Address: ${printable.address} 74 | :Email: ${printable.email} 75 | :Name: ${printable.name} 76 | :Phone: ${printable.phone}`.trimEnd(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/product/billOfLading/index.ts: -------------------------------------------------------------------------------- 1 | export { BillOfLadingV1 } from "./billOfLadingV1"; 2 | -------------------------------------------------------------------------------- /src/product/billOfLading/internal.ts: -------------------------------------------------------------------------------- 1 | export { BillOfLadingV1 } from "./billOfLadingV1"; 2 | export { BillOfLadingV1Carrier } from "./billOfLadingV1Carrier"; 3 | export { BillOfLadingV1CarrierItem } from "./billOfLadingV1CarrierItem"; 4 | export { BillOfLadingV1Consignee } from "./billOfLadingV1Consignee"; 5 | export { BillOfLadingV1Document } from "./billOfLadingV1Document"; 6 | export { BillOfLadingV1NotifyParty } from "./billOfLadingV1NotifyParty"; 7 | export { BillOfLadingV1Shipper } from "./billOfLadingV1Shipper"; 8 | -------------------------------------------------------------------------------- /src/product/businessCard/businessCardV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { BusinessCardV1Document } from "./businessCardV1Document"; 3 | 4 | /** 5 | * Business Card API version 1 inference prediction. 6 | */ 7 | export class BusinessCardV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "business_card"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: BusinessCardV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new BusinessCardV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | BusinessCardV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/businessCard/index.ts: -------------------------------------------------------------------------------- 1 | export { BusinessCardV1 } from "./businessCardV1"; 2 | -------------------------------------------------------------------------------- /src/product/businessCard/internal.ts: -------------------------------------------------------------------------------- 1 | export { BusinessCardV1 } from "./businessCardV1"; 2 | export { BusinessCardV1Document } from "./businessCardV1Document"; 3 | -------------------------------------------------------------------------------- /src/product/cropper/cropperV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { CropperV1Document } from "./cropperV1Document"; 3 | import { CropperV1Page } from "./cropperV1Page"; 4 | 5 | /** 6 | * Cropper API version 1 inference prediction. 7 | */ 8 | export class CropperV1 extends Inference { 9 | /** The endpoint's name. */ 10 | endpointName = "cropper"; 11 | /** The endpoint's version. */ 12 | endpointVersion = "1"; 13 | /** The document-level prediction. */ 14 | prediction: CropperV1Document; 15 | /** The document's pages. */ 16 | pages: Page[] = []; 17 | 18 | constructor(rawPrediction: StringDict) { 19 | super(rawPrediction); 20 | this.prediction = new CropperV1Document(); 21 | rawPrediction["pages"].forEach( 22 | (page: StringDict) => { 23 | if (page.prediction !== undefined && page.prediction !== null && 24 | Object.keys(page.prediction).length > 0) { 25 | this.pages.push(new Page( 26 | CropperV1Page, 27 | page, 28 | page["id"], 29 | page["orientation"] 30 | )); 31 | } 32 | } 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/product/cropper/cropperV1Document.ts: -------------------------------------------------------------------------------- 1 | import { Prediction } from "../../parsing/common"; 2 | 3 | 4 | /** 5 | * Cropper API version 1.1 document data. 6 | */ 7 | export class CropperV1Document implements Prediction { 8 | /** 9 | * Default string representation. 10 | */ 11 | toString(): string { 12 | return ""; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/product/cropper/cropperV1Page.ts: -------------------------------------------------------------------------------- 1 | import { StringDict, cleanOutString } from "../../parsing/common"; 2 | import { PositionField } from "../../parsing/standard"; 3 | 4 | import { CropperV1Document } from "./cropperV1Document"; 5 | 6 | /** 7 | * Cropper API version 1.1 page data. 8 | */ 9 | export class CropperV1Page extends CropperV1Document { 10 | /** List of documents found in the image. */ 11 | cropping: PositionField[] = []; 12 | 13 | constructor(rawPrediction: StringDict, pageId?: number) { 14 | super(); 15 | 16 | rawPrediction["cropping"].map( 17 | (itemPrediction: StringDict) => 18 | this.cropping.push( 19 | new PositionField({ 20 | prediction: itemPrediction, 21 | pageId: pageId, 22 | }) 23 | ) 24 | ); 25 | } 26 | 27 | toString(): string { 28 | const cropping = this.cropping.join("\n "); 29 | const outStr = `:Document Cropper: ${cropping}`.trimEnd(); 30 | return cleanOutString(outStr); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/product/cropper/index.ts: -------------------------------------------------------------------------------- 1 | export { CropperV1 } from "./cropperV1"; 2 | -------------------------------------------------------------------------------- /src/product/cropper/internal.ts: -------------------------------------------------------------------------------- 1 | export { CropperV1 } from "./cropperV1"; 2 | export { CropperV1Document } from "./cropperV1Document"; 3 | export { CropperV1Page } from "./cropperV1Page"; 4 | -------------------------------------------------------------------------------- /src/product/custom/customV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, Page, StringDict } from "../../parsing/common"; 2 | import { CustomV1Document } from "./customV1Document"; 3 | import { CustomV1Page } from "./customV1Page"; 4 | 5 | /** 6 | * Inference prediction for Custom builds. 7 | */ 8 | export class CustomV1 extends Inference { 9 | /** The endpoint's name. Note: placeholder for custom APIs. */ 10 | endpointName = "custom"; 11 | /** The endpoint's version. Note: placeholder for custom APIs. */ 12 | endpointVersion = "1"; 13 | /** The document-level prediction. */ 14 | prediction: CustomV1Document; 15 | /** The document's pages. */ 16 | pages: Page[] = []; 17 | 18 | constructor(rawPrediction: StringDict) { 19 | super(rawPrediction); 20 | this.prediction = new CustomV1Document(rawPrediction["prediction"]); 21 | this.pages = rawPrediction["pages"].map( 22 | (page: StringDict) => 23 | new Page(CustomV1Page, page, page["id"], page["orientation"]) 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/product/custom/customV1Page.ts: -------------------------------------------------------------------------------- 1 | import { cleanOutString } from "../../parsing/common"; 2 | import { StringDict, Prediction } from "../../parsing/common"; 3 | import { ListField, CustomLines, getLineItems } from "../../parsing/custom"; 4 | 5 | /** 6 | * Page data for Custom builds. 7 | */ 8 | export class CustomV1Page implements Prediction { 9 | /** Map of page-specific fields for a Custom build. Cannot include Classification fields. */ 10 | fields: Map = new Map(); 11 | 12 | constructor(rawPrediction: StringDict, pageId?: number) { 13 | Object.entries(rawPrediction).forEach( 14 | ([fieldName, fieldValue]: [string, any]) => { 15 | this.fields.set( 16 | fieldName, 17 | new ListField({ 18 | prediction: fieldValue as StringDict, 19 | pageId: pageId, 20 | }) 21 | ); 22 | } 23 | ); 24 | } 25 | 26 | /** 27 | * Order column fields into line items. 28 | * @param anchorNames list of possible anchor fields. 29 | * @param fieldNames list of all column fields. 30 | * @param heightTolerance height tolerance to apply to lines. 31 | */ 32 | columnsToLineItems(anchorNames: string[], fieldNames: string[], heightTolerance: number = 0.01): CustomLines { 33 | return getLineItems( 34 | anchorNames, 35 | fieldNames, 36 | this.fields, 37 | heightTolerance 38 | ); 39 | } 40 | 41 | /** 42 | * Default string representation. 43 | */ 44 | toString(): string { 45 | let outStr = ""; 46 | this.fields.forEach((fieldData, name) => { 47 | outStr += `:${name}: ${fieldData}\n`; 48 | }); 49 | return cleanOutString(outStr).trimEnd(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/product/custom/internal.ts: -------------------------------------------------------------------------------- 1 | export { CustomV1 } from "./customV1"; 2 | export { CustomV1Document } from "./customV1Document"; 3 | export { CustomV1Page } from "./customV1Page"; 4 | -------------------------------------------------------------------------------- /src/product/deliveryNote/deliveryNoteV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { DeliveryNoteV1Document } from "./deliveryNoteV1Document"; 3 | 4 | /** 5 | * Delivery note API version 1 inference prediction. 6 | */ 7 | export class DeliveryNoteV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "delivery_notes"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: DeliveryNoteV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new DeliveryNoteV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | DeliveryNoteV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/deliveryNote/deliveryNoteV1Document.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Prediction, 3 | StringDict, 4 | cleanOutString, 5 | } from "../../parsing/common"; 6 | import { 7 | AmountField, 8 | DateField, 9 | StringField, 10 | } from "../../parsing/standard"; 11 | 12 | /** 13 | * Delivery note API version 1.2 document data. 14 | */ 15 | export class DeliveryNoteV1Document implements Prediction { 16 | /** The address of the customer receiving the goods. */ 17 | customerAddress: StringField; 18 | /** The name of the customer receiving the goods. */ 19 | customerName: StringField; 20 | /** The date on which the delivery is scheduled to arrive. */ 21 | deliveryDate: DateField; 22 | /** A unique identifier for the delivery note. */ 23 | deliveryNumber: StringField; 24 | /** The address of the supplier providing the goods. */ 25 | supplierAddress: StringField; 26 | /** The name of the supplier providing the goods. */ 27 | supplierName: StringField; 28 | /** The total monetary value of the goods being delivered. */ 29 | totalAmount: AmountField; 30 | 31 | constructor(rawPrediction: StringDict, pageId?: number) { 32 | this.customerAddress = new StringField({ 33 | prediction: rawPrediction["customer_address"], 34 | pageId: pageId, 35 | }); 36 | this.customerName = new StringField({ 37 | prediction: rawPrediction["customer_name"], 38 | pageId: pageId, 39 | }); 40 | this.deliveryDate = new DateField({ 41 | prediction: rawPrediction["delivery_date"], 42 | pageId: pageId, 43 | }); 44 | this.deliveryNumber = new StringField({ 45 | prediction: rawPrediction["delivery_number"], 46 | pageId: pageId, 47 | }); 48 | this.supplierAddress = new StringField({ 49 | prediction: rawPrediction["supplier_address"], 50 | pageId: pageId, 51 | }); 52 | this.supplierName = new StringField({ 53 | prediction: rawPrediction["supplier_name"], 54 | pageId: pageId, 55 | }); 56 | this.totalAmount = new AmountField({ 57 | prediction: rawPrediction["total_amount"], 58 | pageId: pageId, 59 | }); 60 | } 61 | 62 | /** 63 | * Default string representation. 64 | */ 65 | toString(): string { 66 | const outStr = `:Delivery Date: ${this.deliveryDate} 67 | :Delivery Number: ${this.deliveryNumber} 68 | :Supplier Name: ${this.supplierName} 69 | :Supplier Address: ${this.supplierAddress} 70 | :Customer Name: ${this.customerName} 71 | :Customer Address: ${this.customerAddress} 72 | :Total Amount: ${this.totalAmount}`.trimEnd(); 73 | return cleanOutString(outStr); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/product/deliveryNote/index.ts: -------------------------------------------------------------------------------- 1 | export { DeliveryNoteV1 } from "./deliveryNoteV1"; 2 | -------------------------------------------------------------------------------- /src/product/deliveryNote/internal.ts: -------------------------------------------------------------------------------- 1 | export { DeliveryNoteV1 } from "./deliveryNoteV1"; 2 | export { DeliveryNoteV1Document } from "./deliveryNoteV1Document"; 3 | -------------------------------------------------------------------------------- /src/product/driverLicense/driverLicenseV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { DriverLicenseV1Document } from "./driverLicenseV1Document"; 3 | 4 | /** 5 | * Driver License API version 1 inference prediction. 6 | */ 7 | export class DriverLicenseV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "driver_license"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: DriverLicenseV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new DriverLicenseV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | DriverLicenseV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/driverLicense/index.ts: -------------------------------------------------------------------------------- 1 | export { DriverLicenseV1 } from "./driverLicenseV1"; 2 | -------------------------------------------------------------------------------- /src/product/driverLicense/internal.ts: -------------------------------------------------------------------------------- 1 | export { DriverLicenseV1 } from "./driverLicenseV1"; 2 | export { DriverLicenseV1Document } from "./driverLicenseV1Document"; 3 | -------------------------------------------------------------------------------- /src/product/financialDocument/financialDocumentV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { FinancialDocumentV1Document } from "./financialDocumentV1Document"; 3 | 4 | /** 5 | * Financial Document API version 1 inference prediction. 6 | */ 7 | export class FinancialDocumentV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "financial_document"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: FinancialDocumentV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new FinancialDocumentV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | FinancialDocumentV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/financialDocument/index.ts: -------------------------------------------------------------------------------- 1 | export { FinancialDocumentV1 } from "./financialDocumentV1"; 2 | -------------------------------------------------------------------------------- /src/product/financialDocument/internal.ts: -------------------------------------------------------------------------------- 1 | export { FinancialDocumentV1 } from "./financialDocumentV1"; 2 | export { FinancialDocumentV1Document } from "./financialDocumentV1Document"; 3 | export { FinancialDocumentV1LineItem } from "./financialDocumentV1LineItem"; 4 | -------------------------------------------------------------------------------- /src/product/fr/bankAccountDetails/bankAccountDetailsV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { BankAccountDetailsV1Document } from "./bankAccountDetailsV1Document"; 3 | 4 | /** 5 | * Bank Account Details API version 1 inference prediction. 6 | */ 7 | export class BankAccountDetailsV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "bank_account_details"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: BankAccountDetailsV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new BankAccountDetailsV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | BankAccountDetailsV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/fr/bankAccountDetails/bankAccountDetailsV1Document.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Prediction, 3 | StringDict, 4 | cleanOutString, 5 | } from "../../../parsing/common"; 6 | import { StringField } from "../../../parsing/standard"; 7 | 8 | /** 9 | * Bank Account Details API version 1.0 document data. 10 | */ 11 | export class BankAccountDetailsV1Document implements Prediction { 12 | /** The name of the account holder as seen on the document. */ 13 | accountHolderName: StringField; 14 | /** The International Bank Account Number (IBAN). */ 15 | iban: StringField; 16 | /** The bank's SWIFT Business Identifier Code (BIC). */ 17 | swift: StringField; 18 | 19 | constructor(rawPrediction: StringDict, pageId?: number) { 20 | this.accountHolderName = new StringField({ 21 | prediction: rawPrediction["account_holder_name"], 22 | pageId: pageId, 23 | }); 24 | this.iban = new StringField({ 25 | prediction: rawPrediction["iban"], 26 | pageId: pageId, 27 | }); 28 | this.swift = new StringField({ 29 | prediction: rawPrediction["swift"], 30 | pageId: pageId, 31 | }); 32 | } 33 | 34 | /** 35 | * Default string representation. 36 | */ 37 | toString(): string { 38 | const outStr = `:IBAN: ${this.iban} 39 | :Account Holder's Name: ${this.accountHolderName} 40 | :SWIFT Code: ${this.swift}`.trimEnd(); 41 | return cleanOutString(outStr); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/product/fr/bankAccountDetails/bankAccountDetailsV2.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { BankAccountDetailsV2Document } from "./bankAccountDetailsV2Document"; 3 | 4 | /** 5 | * Bank Account Details API version 2 inference prediction. 6 | */ 7 | export class BankAccountDetailsV2 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "bank_account_details"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "2"; 12 | /** The document-level prediction. */ 13 | prediction: BankAccountDetailsV2Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new BankAccountDetailsV2Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | BankAccountDetailsV2Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/fr/bankAccountDetails/bankAccountDetailsV2Document.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Prediction, 3 | StringDict, 4 | cleanOutString, 5 | } from "../../../parsing/common"; 6 | import { BankAccountDetailsV2Bban } from "./bankAccountDetailsV2Bban"; 7 | import { StringField } from "../../../parsing/standard"; 8 | 9 | /** 10 | * Bank Account Details API version 2.0 document data. 11 | */ 12 | export class BankAccountDetailsV2Document implements Prediction { 13 | /** Full extraction of the account holders names. */ 14 | accountHoldersNames: StringField; 15 | /** Full extraction of BBAN, including: branch code, bank code, account and key. */ 16 | bban: BankAccountDetailsV2Bban; 17 | /** Full extraction of the IBAN number. */ 18 | iban: StringField; 19 | /** Full extraction of the SWIFT code. */ 20 | swiftCode: StringField; 21 | 22 | constructor(rawPrediction: StringDict, pageId?: number) { 23 | this.accountHoldersNames = new StringField({ 24 | prediction: rawPrediction["account_holders_names"], 25 | pageId: pageId, 26 | }); 27 | this.bban = new BankAccountDetailsV2Bban({ 28 | prediction: rawPrediction["bban"], 29 | pageId: pageId, 30 | }); 31 | this.iban = new StringField({ 32 | prediction: rawPrediction["iban"], 33 | pageId: pageId, 34 | }); 35 | this.swiftCode = new StringField({ 36 | prediction: rawPrediction["swift_code"], 37 | pageId: pageId, 38 | }); 39 | } 40 | 41 | /** 42 | * Default string representation. 43 | */ 44 | toString(): string { 45 | const outStr = `:Account Holder's Names: ${this.accountHoldersNames} 46 | :Basic Bank Account Number: ${this.bban.toFieldList()} 47 | :IBAN: ${this.iban} 48 | :SWIFT Code: ${this.swiftCode}`.trimEnd(); 49 | return cleanOutString(outStr); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/product/fr/bankAccountDetails/index.ts: -------------------------------------------------------------------------------- 1 | export { BankAccountDetailsV1 } from "./bankAccountDetailsV1"; 2 | export { BankAccountDetailsV2 } from "./bankAccountDetailsV2"; 3 | -------------------------------------------------------------------------------- /src/product/fr/bankAccountDetails/internal.ts: -------------------------------------------------------------------------------- 1 | export { BankAccountDetailsV1 } from "./bankAccountDetailsV1"; 2 | export { BankAccountDetailsV1Document } from "./bankAccountDetailsV1Document"; 3 | export { BankAccountDetailsV2 } from "./bankAccountDetailsV2"; 4 | export { BankAccountDetailsV2Bban } from "./bankAccountDetailsV2Bban"; 5 | export { BankAccountDetailsV2Document } from "./bankAccountDetailsV2Document"; 6 | -------------------------------------------------------------------------------- /src/product/fr/carteGrise/carteGriseV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { CarteGriseV1Document } from "./carteGriseV1Document"; 3 | 4 | /** 5 | * Carte Grise API version 1 inference prediction. 6 | */ 7 | export class CarteGriseV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "carte_grise"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: CarteGriseV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new CarteGriseV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | CarteGriseV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/fr/carteGrise/index.ts: -------------------------------------------------------------------------------- 1 | export { CarteGriseV1 } from "./carteGriseV1"; 2 | -------------------------------------------------------------------------------- /src/product/fr/carteGrise/internal.ts: -------------------------------------------------------------------------------- 1 | export { CarteGriseV1 } from "./carteGriseV1"; 2 | export { CarteGriseV1Document } from "./carteGriseV1Document"; 3 | -------------------------------------------------------------------------------- /src/product/fr/energyBill/energyBillV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { EnergyBillV1Document } from "./energyBillV1Document"; 3 | 4 | /** 5 | * Energy Bill API version 1 inference prediction. 6 | */ 7 | export class EnergyBillV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "energy_bill_fra"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: EnergyBillV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new EnergyBillV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | EnergyBillV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/fr/energyBill/energyBillV1EnergyConsumer.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../../parsing/common"; 2 | import { Polygon } from "../../../geometry"; 3 | 4 | /** 5 | * The entity that consumes the energy. 6 | */ 7 | export class EnergyBillV1EnergyConsumer { 8 | /** The address of the energy consumer. */ 9 | address: string | null; 10 | /** The name of the energy consumer. */ 11 | name: string | null; 12 | /** Confidence score */ 13 | confidence: number = 0.0; 14 | /** The document page on which the information was found. */ 15 | pageId: number; 16 | /** 17 | * Contains the relative vertices coordinates (points) of a polygon containing 18 | * the field in the document. 19 | */ 20 | polygon: Polygon = []; 21 | 22 | constructor({ prediction = {} }: StringDict) { 23 | this.address = prediction["address"]; 24 | this.name = prediction["name"]; 25 | this.pageId = prediction["page_id"]; 26 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 27 | if (prediction["polygon"]) { 28 | this.polygon = prediction.polygon; 29 | } 30 | } 31 | 32 | /** 33 | * Collection of fields as representable strings. 34 | */ 35 | #printableValues() { 36 | return { 37 | address: this.address ?? "", 38 | name: this.name ?? "", 39 | }; 40 | } 41 | 42 | /** 43 | * Default string representation. 44 | */ 45 | toString(): string { 46 | const printable = this.#printableValues(); 47 | return ( 48 | "Address: " + 49 | printable.address + 50 | ", Name: " + 51 | printable.name 52 | ); 53 | } 54 | 55 | /** 56 | * Output in a format suitable for inclusion in a field list. 57 | */ 58 | toFieldList(): string { 59 | const printable = this.#printableValues(); 60 | return ` 61 | :Address: ${printable.address} 62 | :Name: ${printable.name}`.trimEnd(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/product/fr/energyBill/energyBillV1EnergySupplier.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../../parsing/common"; 2 | import { Polygon } from "../../../geometry"; 3 | 4 | /** 5 | * The company that supplies the energy. 6 | */ 7 | export class EnergyBillV1EnergySupplier { 8 | /** The address of the energy supplier. */ 9 | address: string | null; 10 | /** The name of the energy supplier. */ 11 | name: string | null; 12 | /** Confidence score */ 13 | confidence: number = 0.0; 14 | /** The document page on which the information was found. */ 15 | pageId: number; 16 | /** 17 | * Contains the relative vertices coordinates (points) of a polygon containing 18 | * the field in the document. 19 | */ 20 | polygon: Polygon = []; 21 | 22 | constructor({ prediction = {} }: StringDict) { 23 | this.address = prediction["address"]; 24 | this.name = prediction["name"]; 25 | this.pageId = prediction["page_id"]; 26 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 27 | if (prediction["polygon"]) { 28 | this.polygon = prediction.polygon; 29 | } 30 | } 31 | 32 | /** 33 | * Collection of fields as representable strings. 34 | */ 35 | #printableValues() { 36 | return { 37 | address: this.address ?? "", 38 | name: this.name ?? "", 39 | }; 40 | } 41 | 42 | /** 43 | * Default string representation. 44 | */ 45 | toString(): string { 46 | const printable = this.#printableValues(); 47 | return ( 48 | "Address: " + 49 | printable.address + 50 | ", Name: " + 51 | printable.name 52 | ); 53 | } 54 | 55 | /** 56 | * Output in a format suitable for inclusion in a field list. 57 | */ 58 | toFieldList(): string { 59 | const printable = this.#printableValues(); 60 | return ` 61 | :Address: ${printable.address} 62 | :Name: ${printable.name}`.trimEnd(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/product/fr/energyBill/energyBillV1MeterDetail.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../../parsing/common"; 2 | import { Polygon } from "../../../geometry"; 3 | 4 | /** 5 | * Information about the energy meter. 6 | */ 7 | export class EnergyBillV1MeterDetail { 8 | /** The unique identifier of the energy meter. */ 9 | meterNumber: string | null; 10 | /** The type of energy meter. */ 11 | meterType: string | null; 12 | /** The unit of power for energy consumption. */ 13 | unit: string | null; 14 | /** Confidence score */ 15 | confidence: number = 0.0; 16 | /** The document page on which the information was found. */ 17 | pageId: number; 18 | /** 19 | * Contains the relative vertices coordinates (points) of a polygon containing 20 | * the field in the document. 21 | */ 22 | polygon: Polygon = []; 23 | 24 | constructor({ prediction = {} }: StringDict) { 25 | this.meterNumber = prediction["meter_number"]; 26 | this.meterType = prediction["meter_type"]; 27 | this.unit = prediction["unit"]; 28 | this.pageId = prediction["page_id"]; 29 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 30 | if (prediction["polygon"]) { 31 | this.polygon = prediction.polygon; 32 | } 33 | } 34 | 35 | /** 36 | * Collection of fields as representable strings. 37 | */ 38 | #printableValues() { 39 | return { 40 | meterNumber: this.meterNumber ?? "", 41 | meterType: this.meterType ?? "", 42 | unit: this.unit ?? "", 43 | }; 44 | } 45 | 46 | /** 47 | * Default string representation. 48 | */ 49 | toString(): string { 50 | const printable = this.#printableValues(); 51 | return ( 52 | "Meter Number: " + 53 | printable.meterNumber + 54 | ", Meter Type: " + 55 | printable.meterType + 56 | ", Unit of Power: " + 57 | printable.unit 58 | ); 59 | } 60 | 61 | /** 62 | * Output in a format suitable for inclusion in a field list. 63 | */ 64 | toFieldList(): string { 65 | const printable = this.#printableValues(); 66 | return ` 67 | :Meter Number: ${printable.meterNumber} 68 | :Meter Type: ${printable.meterType} 69 | :Unit of Power: ${printable.unit}`.trimEnd(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/product/fr/energyBill/index.ts: -------------------------------------------------------------------------------- 1 | export { EnergyBillV1 } from "./energyBillV1"; 2 | -------------------------------------------------------------------------------- /src/product/fr/energyBill/internal.ts: -------------------------------------------------------------------------------- 1 | export { EnergyBillV1 } from "./energyBillV1"; 2 | export { EnergyBillV1Document } from "./energyBillV1Document"; 3 | export { EnergyBillV1EnergyConsumer } from "./energyBillV1EnergyConsumer"; 4 | export { EnergyBillV1EnergySupplier } from "./energyBillV1EnergySupplier"; 5 | export { EnergyBillV1EnergyUsage } from "./energyBillV1EnergyUsage"; 6 | export { EnergyBillV1MeterDetail } from "./energyBillV1MeterDetail"; 7 | export { EnergyBillV1Subscription } from "./energyBillV1Subscription"; 8 | export { EnergyBillV1TaxesAndContribution } from "./energyBillV1TaxesAndContribution"; 9 | -------------------------------------------------------------------------------- /src/product/fr/healthCard/healthCardV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { HealthCardV1Document } from "./healthCardV1Document"; 3 | 4 | /** 5 | * Health Card API version 1 inference prediction. 6 | */ 7 | export class HealthCardV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "french_healthcard"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: HealthCardV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new HealthCardV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | HealthCardV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/fr/healthCard/healthCardV1Document.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Prediction, 3 | StringDict, 4 | cleanOutString, 5 | } from "../../../parsing/common"; 6 | import { DateField, StringField } from "../../../parsing/standard"; 7 | 8 | /** 9 | * Health Card API version 1.0 document data. 10 | */ 11 | export class HealthCardV1Document implements Prediction { 12 | /** The given names of the card holder. */ 13 | givenNames: StringField[] = []; 14 | /** The date when the carte vitale document was issued. */ 15 | issuanceDate: DateField; 16 | /** The social security number of the card holder. */ 17 | socialSecurity: StringField; 18 | /** The surname of the card holder. */ 19 | surname: StringField; 20 | 21 | constructor(rawPrediction: StringDict, pageId?: number) { 22 | rawPrediction["given_names"] && 23 | rawPrediction["given_names"].map( 24 | (itemPrediction: StringDict) => 25 | this.givenNames.push( 26 | new StringField({ 27 | prediction: itemPrediction, 28 | pageId: pageId, 29 | }) 30 | ) 31 | ); 32 | this.issuanceDate = new DateField({ 33 | prediction: rawPrediction["issuance_date"], 34 | pageId: pageId, 35 | }); 36 | this.socialSecurity = new StringField({ 37 | prediction: rawPrediction["social_security"], 38 | pageId: pageId, 39 | }); 40 | this.surname = new StringField({ 41 | prediction: rawPrediction["surname"], 42 | pageId: pageId, 43 | }); 44 | } 45 | 46 | /** 47 | * Default string representation. 48 | */ 49 | toString(): string { 50 | const givenNames = this.givenNames.join("\n "); 51 | const outStr = `:Given Name(s): ${givenNames} 52 | :Surname: ${this.surname} 53 | :Social Security Number: ${this.socialSecurity} 54 | :Issuance Date: ${this.issuanceDate}`.trimEnd(); 55 | return cleanOutString(outStr); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/product/fr/healthCard/index.ts: -------------------------------------------------------------------------------- 1 | export { HealthCardV1 } from "./healthCardV1"; 2 | -------------------------------------------------------------------------------- /src/product/fr/healthCard/internal.ts: -------------------------------------------------------------------------------- 1 | export { HealthCardV1 } from "./healthCardV1"; 2 | export { HealthCardV1Document } from "./healthCardV1Document"; 3 | -------------------------------------------------------------------------------- /src/product/fr/idCard/idCardV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { IdCardV1Document } from "./idCardV1Document"; 3 | import { IdCardV1Page } from "./idCardV1Page"; 4 | 5 | /** 6 | * Carte Nationale d'Identité API version 1 inference prediction. 7 | */ 8 | export class IdCardV1 extends Inference { 9 | /** The endpoint's name. */ 10 | endpointName = "idcard_fr"; 11 | /** The endpoint's version. */ 12 | endpointVersion = "1"; 13 | /** The document-level prediction. */ 14 | prediction: IdCardV1Document; 15 | /** The document's pages. */ 16 | pages: Page[] = []; 17 | 18 | constructor(rawPrediction: StringDict) { 19 | super(rawPrediction); 20 | this.prediction = new IdCardV1Document(rawPrediction["prediction"]); 21 | rawPrediction["pages"].forEach( 22 | (page: StringDict) => { 23 | if (page.prediction !== undefined && page.prediction !== null && 24 | Object.keys(page.prediction).length > 0) { 25 | this.pages.push(new Page( 26 | IdCardV1Page, 27 | page, 28 | page["id"], 29 | page["orientation"] 30 | )); 31 | } 32 | } 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/product/fr/idCard/idCardV1Page.ts: -------------------------------------------------------------------------------- 1 | import { StringDict, cleanOutString } from "../../../parsing/common"; 2 | import { ClassificationField } from "../../../parsing/standard"; 3 | 4 | import { IdCardV1Document } from "./idCardV1Document"; 5 | 6 | /** 7 | * Carte Nationale d'Identité API version 1.1 page data. 8 | */ 9 | export class IdCardV1Page extends IdCardV1Document { 10 | /** The side of the document which is visible. */ 11 | documentSide: ClassificationField; 12 | 13 | constructor(rawPrediction: StringDict, pageId?: number) { 14 | super(rawPrediction, pageId); 15 | 16 | this.documentSide = new ClassificationField({ 17 | prediction: rawPrediction["document_side"], 18 | }); 19 | } 20 | 21 | toString(): string { 22 | let outStr = `:Document Side: ${this.documentSide}`.trimEnd(); 23 | outStr += "\n" + super.toString(); 24 | return cleanOutString(outStr); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/product/fr/idCard/idCardV2.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { IdCardV2Document } from "./idCardV2Document"; 3 | import { IdCardV2Page } from "./idCardV2Page"; 4 | 5 | /** 6 | * Carte Nationale d'Identité API version 2 inference prediction. 7 | */ 8 | export class IdCardV2 extends Inference { 9 | /** The endpoint's name. */ 10 | endpointName = "idcard_fr"; 11 | /** The endpoint's version. */ 12 | endpointVersion = "2"; 13 | /** The document-level prediction. */ 14 | prediction: IdCardV2Document; 15 | /** The document's pages. */ 16 | pages: Page[] = []; 17 | 18 | constructor(rawPrediction: StringDict) { 19 | super(rawPrediction); 20 | this.prediction = new IdCardV2Document(rawPrediction["prediction"]); 21 | rawPrediction["pages"].forEach( 22 | (page: StringDict) => { 23 | if (page.prediction !== undefined && page.prediction !== null && 24 | Object.keys(page.prediction).length > 0) { 25 | this.pages.push(new Page( 26 | IdCardV2Page, 27 | page, 28 | page["id"], 29 | page["orientation"] 30 | )); 31 | } 32 | } 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/product/fr/idCard/idCardV2Page.ts: -------------------------------------------------------------------------------- 1 | import { StringDict, cleanOutString } from "../../../parsing/common"; 2 | import { ClassificationField } from "../../../parsing/standard"; 3 | 4 | import { IdCardV2Document } from "./idCardV2Document"; 5 | 6 | /** 7 | * Carte Nationale d'Identité API version 2.0 page data. 8 | */ 9 | export class IdCardV2Page extends IdCardV2Document { 10 | /** The sides of the document which are visible. */ 11 | documentSide: ClassificationField; 12 | /** The document type or format. */ 13 | documentType: ClassificationField; 14 | 15 | constructor(rawPrediction: StringDict, pageId?: number) { 16 | super(rawPrediction, pageId); 17 | 18 | this.documentSide = new ClassificationField({ 19 | prediction: rawPrediction["document_side"], 20 | }); 21 | this.documentType = new ClassificationField({ 22 | prediction: rawPrediction["document_type"], 23 | }); 24 | } 25 | 26 | toString(): string { 27 | let outStr = `:Document Type: ${this.documentType} 28 | :Document Sides: ${this.documentSide}`.trimEnd(); 29 | outStr += "\n" + super.toString(); 30 | return cleanOutString(outStr); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/product/fr/idCard/index.ts: -------------------------------------------------------------------------------- 1 | export { IdCardV1 } from "./idCardV1"; 2 | export { IdCardV2 } from "./idCardV2"; 3 | -------------------------------------------------------------------------------- /src/product/fr/idCard/internal.ts: -------------------------------------------------------------------------------- 1 | export { IdCardV1 } from "./idCardV1"; 2 | export { IdCardV1Document } from "./idCardV1Document"; 3 | export { IdCardV1Page } from "./idCardV1Page"; 4 | export { IdCardV2 } from "./idCardV2"; 5 | export { IdCardV2Document } from "./idCardV2Document"; 6 | export { IdCardV2Page } from "./idCardV2Page"; 7 | -------------------------------------------------------------------------------- /src/product/fr/index.ts: -------------------------------------------------------------------------------- 1 | export { BankAccountDetailsV1 } from "./bankAccountDetails/bankAccountDetailsV1"; 2 | export { BankAccountDetailsV2 } from "./bankAccountDetails/bankAccountDetailsV2"; 3 | export { CarteGriseV1 } from "./carteGrise/carteGriseV1"; 4 | export { EnergyBillV1 } from "./energyBill/energyBillV1"; 5 | export { HealthCardV1 } from "./healthCard/healthCardV1"; 6 | export { IdCardV1 } from "./idCard/idCardV1"; 7 | export { IdCardV2 } from "./idCard/idCardV2"; 8 | export { PayslipV2 } from "./payslip/payslipV2"; 9 | export { PayslipV3 } from "./payslip/payslipV3"; 10 | -------------------------------------------------------------------------------- /src/product/fr/internal.ts: -------------------------------------------------------------------------------- 1 | export * as bankAccountDetails from "./bankAccountDetails/internal"; 2 | export * as carteGrise from "./carteGrise/internal"; 3 | export * as energyBill from "./energyBill/internal"; 4 | export * as healthCard from "./healthCard/internal"; 5 | export * as idCard from "./idCard/internal"; 6 | export * as payslip from "./payslip/internal"; 7 | -------------------------------------------------------------------------------- /src/product/fr/payslip/index.ts: -------------------------------------------------------------------------------- 1 | export { PayslipV2 } from "./payslipV2"; 2 | export { PayslipV3 } from "./payslipV3"; 3 | -------------------------------------------------------------------------------- /src/product/fr/payslip/internal.ts: -------------------------------------------------------------------------------- 1 | export { PayslipV2 } from "./payslipV2"; 2 | export { PayslipV2BankAccountDetail } from "./payslipV2BankAccountDetail"; 3 | export { PayslipV2Document } from "./payslipV2Document"; 4 | export { PayslipV2Employee } from "./payslipV2Employee"; 5 | export { PayslipV2Employer } from "./payslipV2Employer"; 6 | export { PayslipV2Employment } from "./payslipV2Employment"; 7 | export { PayslipV2PayDetail } from "./payslipV2PayDetail"; 8 | export { PayslipV2PayPeriod } from "./payslipV2PayPeriod"; 9 | export { PayslipV2Pto } from "./payslipV2Pto"; 10 | export { PayslipV2SalaryDetail } from "./payslipV2SalaryDetail"; 11 | export { PayslipV3 } from "./payslipV3"; 12 | export { PayslipV3BankAccountDetail } from "./payslipV3BankAccountDetail"; 13 | export { PayslipV3Document } from "./payslipV3Document"; 14 | export { PayslipV3Employee } from "./payslipV3Employee"; 15 | export { PayslipV3Employer } from "./payslipV3Employer"; 16 | export { PayslipV3Employment } from "./payslipV3Employment"; 17 | export { PayslipV3PaidTimeOff } from "./payslipV3PaidTimeOff"; 18 | export { PayslipV3PayDetail } from "./payslipV3PayDetail"; 19 | export { PayslipV3PayPeriod } from "./payslipV3PayPeriod"; 20 | export { PayslipV3SalaryDetail } from "./payslipV3SalaryDetail"; 21 | -------------------------------------------------------------------------------- /src/product/fr/payslip/payslipV2.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { PayslipV2Document } from "./payslipV2Document"; 3 | 4 | /** 5 | * Payslip API version 2 inference prediction. 6 | */ 7 | export class PayslipV2 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "payslip_fra"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "2"; 12 | /** The document-level prediction. */ 13 | prediction: PayslipV2Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new PayslipV2Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | PayslipV2Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/fr/payslip/payslipV2BankAccountDetail.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../../parsing/common"; 2 | import { Polygon } from "../../../geometry"; 3 | 4 | /** 5 | * Information about the employee's bank account. 6 | */ 7 | export class PayslipV2BankAccountDetail { 8 | /** The name of the bank. */ 9 | bankName: string | null; 10 | /** The IBAN of the bank account. */ 11 | iban: string | null; 12 | /** The SWIFT code of the bank. */ 13 | swift: string | null; 14 | /** Confidence score */ 15 | confidence: number = 0.0; 16 | /** The document page on which the information was found. */ 17 | pageId: number; 18 | /** 19 | * Contains the relative vertices coordinates (points) of a polygon containing 20 | * the field in the document. 21 | */ 22 | polygon: Polygon = []; 23 | 24 | constructor({ prediction = {} }: StringDict) { 25 | this.bankName = prediction["bank_name"]; 26 | this.iban = prediction["iban"]; 27 | this.swift = prediction["swift"]; 28 | this.pageId = prediction["page_id"]; 29 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 30 | if (prediction["polygon"]) { 31 | this.polygon = prediction.polygon; 32 | } 33 | } 34 | 35 | /** 36 | * Collection of fields as representable strings. 37 | */ 38 | #printableValues() { 39 | return { 40 | bankName: this.bankName ?? "", 41 | iban: this.iban ?? "", 42 | swift: this.swift ?? "", 43 | }; 44 | } 45 | 46 | /** 47 | * Default string representation. 48 | */ 49 | toString(): string { 50 | const printable = this.#printableValues(); 51 | return ( 52 | "Bank Name: " + 53 | printable.bankName + 54 | ", IBAN: " + 55 | printable.iban + 56 | ", SWIFT: " + 57 | printable.swift 58 | ); 59 | } 60 | 61 | /** 62 | * Output in a format suitable for inclusion in a field list. 63 | */ 64 | toFieldList(): string { 65 | const printable = this.#printableValues(); 66 | return ` 67 | :Bank Name: ${printable.bankName} 68 | :IBAN: ${printable.iban} 69 | :SWIFT: ${printable.swift}`.trimEnd(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/product/fr/payslip/payslipV3.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { PayslipV3Document } from "./payslipV3Document"; 3 | 4 | /** 5 | * Payslip API version 3 inference prediction. 6 | */ 7 | export class PayslipV3 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "payslip_fra"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "3"; 12 | /** The document-level prediction. */ 13 | prediction: PayslipV3Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new PayslipV3Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | PayslipV3Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/fr/payslip/payslipV3BankAccountDetail.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../../parsing/common"; 2 | import { Polygon } from "../../../geometry"; 3 | 4 | /** 5 | * Information about the employee's bank account. 6 | */ 7 | export class PayslipV3BankAccountDetail { 8 | /** The name of the bank. */ 9 | bankName: string | null; 10 | /** The IBAN of the bank account. */ 11 | iban: string | null; 12 | /** The SWIFT code of the bank. */ 13 | swift: string | null; 14 | /** Confidence score */ 15 | confidence: number = 0.0; 16 | /** The document page on which the information was found. */ 17 | pageId: number; 18 | /** 19 | * Contains the relative vertices coordinates (points) of a polygon containing 20 | * the field in the document. 21 | */ 22 | polygon: Polygon = []; 23 | 24 | constructor({ prediction = {} }: StringDict) { 25 | this.bankName = prediction["bank_name"]; 26 | this.iban = prediction["iban"]; 27 | this.swift = prediction["swift"]; 28 | this.pageId = prediction["page_id"]; 29 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 30 | if (prediction["polygon"]) { 31 | this.polygon = prediction.polygon; 32 | } 33 | } 34 | 35 | /** 36 | * Collection of fields as representable strings. 37 | */ 38 | #printableValues() { 39 | return { 40 | bankName: this.bankName ?? "", 41 | iban: this.iban ?? "", 42 | swift: this.swift ?? "", 43 | }; 44 | } 45 | 46 | /** 47 | * Default string representation. 48 | */ 49 | toString(): string { 50 | const printable = this.#printableValues(); 51 | return ( 52 | "Bank Name: " + 53 | printable.bankName + 54 | ", IBAN: " + 55 | printable.iban + 56 | ", SWIFT: " + 57 | printable.swift 58 | ); 59 | } 60 | 61 | /** 62 | * Output in a format suitable for inclusion in a field list. 63 | */ 64 | toFieldList(): string { 65 | const printable = this.#printableValues(); 66 | return ` 67 | :Bank Name: ${printable.bankName} 68 | :IBAN: ${printable.iban} 69 | :SWIFT: ${printable.swift}`.trimEnd(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/product/generated/generatedV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, Page, StringDict } from "../../../src/parsing/common"; 2 | import { GeneratedV1Document } from "./generatedV1Document"; 3 | import { GeneratedV1Page } from "./generatedV1Page"; 4 | 5 | /** 6 | * Generated API V1 inference results. 7 | */ 8 | export class GeneratedV1 extends Inference { 9 | /** The endpoint's name. Note: placeholder for custom APIs. */ 10 | endpointName = "custom"; 11 | /** The endpoint's version. Note: placeholder for custom APIs. */ 12 | endpointVersion = "1"; 13 | /** The document-level prediction. */ 14 | prediction: GeneratedV1Document; 15 | /** The document's pages. */ 16 | pages: Page[] = []; 17 | 18 | constructor(rawPrediction: StringDict) { 19 | super(rawPrediction); 20 | this.prediction = new GeneratedV1Document(rawPrediction["prediction"]); 21 | this.pages = rawPrediction["pages"].length > 0 && Object.keys( 22 | rawPrediction["pages"][0]["prediction"]).length > 0 ? 23 | rawPrediction["pages"].map( 24 | (page: StringDict) => 25 | new Page(GeneratedV1Page, page, 26 | page["id"]) 27 | ) : []; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/product/generated/generatedV1Document.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../../src/parsing/common"; 2 | import { GeneratedListField, GeneratedObjectField, isGeneratedObject } from "../../../src/parsing/generated"; 3 | import { StringField } from "../../../src/parsing/standard"; 4 | import { GeneratedV1Prediction } from "./generatedV1Prediction"; 5 | 6 | /** 7 | * Generated V1 document prediction results. 8 | */ 9 | export class GeneratedV1Document extends GeneratedV1Prediction { 10 | constructor(rawPrediction: StringDict) { 11 | super(); 12 | Object.entries(rawPrediction).forEach(([fieldName, fieldValue]: [string, any]) => { 13 | if (Array.isArray(fieldValue)) { 14 | this.fields.set(fieldName, new GeneratedListField({ prediction: fieldValue })); 15 | } 16 | else if (typeof fieldValue === "object" && fieldValue !== null && isGeneratedObject(fieldValue)) { 17 | this.fields.set(fieldName, new GeneratedObjectField({ prediction: fieldValue })); 18 | } else { 19 | const fieldValueStr = fieldValue; 20 | if (Object.prototype.hasOwnProperty.call(fieldValueStr, "value") && fieldValueStr["value"] !== null) { 21 | fieldValueStr["value"] = fieldValueStr["value"].toString(); 22 | } 23 | this.fields.set(fieldName, new StringField({ prediction: fieldValueStr })); 24 | } 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/product/generated/generatedV1Page.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../../src/parsing/common"; 2 | import { GeneratedListField, GeneratedObjectField, isGeneratedObject } from "../../../src/parsing/generated"; 3 | import { StringField } from "../../../src/parsing/standard"; 4 | import { GeneratedV1Prediction } from "./generatedV1Prediction"; 5 | 6 | /** 7 | * Generated V1 page prediction results. 8 | */ 9 | export class GeneratedV1Page extends GeneratedV1Prediction { 10 | constructor(rawPrediction: StringDict, pageId?: number) { 11 | super(); 12 | Object.entries(rawPrediction).forEach(([fieldName, fieldValue]: [string, any]) => { 13 | if (Array.isArray(fieldValue)) { 14 | this.fields.set(fieldName, new GeneratedListField({ prediction: fieldValue, pageId: pageId })); 15 | } 16 | else if (typeof fieldValue === "object" && fieldValue !== null && isGeneratedObject(fieldValue)) { 17 | this.fields.set(fieldName, new GeneratedObjectField({ prediction: fieldValue, pageId: pageId })); 18 | } else { 19 | const fieldValueStr = fieldValue; 20 | if (Object.prototype.hasOwnProperty.call(fieldValueStr, "value") && fieldValueStr["value"] !== null) { 21 | fieldValueStr["value"] = fieldValueStr["value"].toString(); 22 | } 23 | this.fields.set(fieldName, new StringField({ prediction: fieldValueStr, pageId: pageId })); 24 | } 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/product/generated/internal.ts: -------------------------------------------------------------------------------- 1 | export { GeneratedV1 } from "./generatedV1"; 2 | export { GeneratedV1Document } from "./generatedV1Document"; 3 | export { GeneratedV1Page } from "./generatedV1Page"; 4 | export { GeneratedV1Prediction } from "./generatedV1Prediction"; 5 | -------------------------------------------------------------------------------- /src/product/ind/index.ts: -------------------------------------------------------------------------------- 1 | export { IndianPassportV1 } from "./indianPassport/indianPassportV1"; 2 | -------------------------------------------------------------------------------- /src/product/ind/indianPassport/index.ts: -------------------------------------------------------------------------------- 1 | export { IndianPassportV1 } from "./indianPassportV1"; 2 | -------------------------------------------------------------------------------- /src/product/ind/indianPassport/indianPassportV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { IndianPassportV1Document } from "./indianPassportV1Document"; 3 | 4 | /** 5 | * Passport - India API version 1 inference prediction. 6 | */ 7 | export class IndianPassportV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "ind_passport"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: IndianPassportV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new IndianPassportV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | IndianPassportV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/ind/indianPassport/internal.ts: -------------------------------------------------------------------------------- 1 | export { IndianPassportV1 } from "./indianPassportV1"; 2 | export { IndianPassportV1Document } from "./indianPassportV1Document"; 3 | -------------------------------------------------------------------------------- /src/product/ind/internal.ts: -------------------------------------------------------------------------------- 1 | export * as indianPassport from "./indianPassport/internal"; 2 | -------------------------------------------------------------------------------- /src/product/index.ts: -------------------------------------------------------------------------------- 1 | export * as fr from "./fr"; 2 | export * as ind from "./ind"; 3 | export * as us from "./us"; 4 | export { BarcodeReaderV1 } from "./barcodeReader/barcodeReaderV1"; 5 | export { BillOfLadingV1 } from "./billOfLading/billOfLadingV1"; 6 | export { BusinessCardV1 } from "./businessCard/businessCardV1"; 7 | export { CropperV1 } from "./cropper/cropperV1"; 8 | export { CustomV1 } from "./custom/customV1"; 9 | export { DeliveryNoteV1 } from "./deliveryNote/deliveryNoteV1"; 10 | export { DriverLicenseV1 } from "./driverLicense/driverLicenseV1"; 11 | export { FinancialDocumentV1 } from "./financialDocument/financialDocumentV1"; 12 | export { GeneratedV1 } from "./generated/generatedV1"; 13 | export { InternationalIdV2 } from "./internationalId/internationalIdV2"; 14 | export { InvoiceSplitterV1 } from "./invoiceSplitter/invoiceSplitterV1"; 15 | export { InvoiceV4 } from "./invoice/invoiceV4"; 16 | export { MultiReceiptsDetectorV1 } from "./multiReceiptsDetector/multiReceiptsDetectorV1"; 17 | export { NutritionFactsLabelV1 } from "./nutritionFactsLabel/nutritionFactsLabelV1"; 18 | export { PassportV1 } from "./passport/passportV1"; 19 | export { ReceiptV5 } from "./receipt/receiptV5"; 20 | export { ResumeV1 } from "./resume/resumeV1"; 21 | -------------------------------------------------------------------------------- /src/product/internal.ts: -------------------------------------------------------------------------------- 1 | export * as barcodeReader from "./barcodeReader/internal"; 2 | export * as billOfLading from "./billOfLading/internal"; 3 | export * as businessCard from "./businessCard/internal"; 4 | export * as cropper from "./cropper/internal"; 5 | export * as custom from "./custom/internal"; 6 | export * as deliveryNote from "./deliveryNote/internal"; 7 | export * as driverLicense from "./driverLicense/internal"; 8 | export * as financialDocument from "./financialDocument/internal"; 9 | export * as fr from "./fr/internal"; 10 | export * as generated from "./generated/internal"; 11 | export * as ind from "./ind/internal"; 12 | export * as internationalId from "./internationalId/internal"; 13 | export * as invoice from "./invoice/internal"; 14 | export * as invoiceSplitter from "./invoiceSplitter/internal"; 15 | export * as multiReceiptsDetector from "./multiReceiptsDetector/internal"; 16 | export * as nutritionFactsLabel from "./nutritionFactsLabel/internal"; 17 | export * as passport from "./passport/internal"; 18 | export * as receipt from "./receipt/internal"; 19 | export * as resume from "./resume/internal"; 20 | export * as us from "./us/internal"; 21 | -------------------------------------------------------------------------------- /src/product/internationalId/index.ts: -------------------------------------------------------------------------------- 1 | export { InternationalIdV2 } from "./internationalIdV2"; 2 | -------------------------------------------------------------------------------- /src/product/internationalId/internal.ts: -------------------------------------------------------------------------------- 1 | export { InternationalIdV2 } from "./internationalIdV2"; 2 | export { InternationalIdV2Document } from "./internationalIdV2Document"; 3 | -------------------------------------------------------------------------------- /src/product/internationalId/internationalIdV2.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { InternationalIdV2Document } from "./internationalIdV2Document"; 3 | 4 | /** 5 | * International ID API version 2 inference prediction. 6 | */ 7 | export class InternationalIdV2 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "international_id"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "2"; 12 | /** The document-level prediction. */ 13 | prediction: InternationalIdV2Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new InternationalIdV2Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | InternationalIdV2Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/invoice/index.ts: -------------------------------------------------------------------------------- 1 | export { InvoiceV4 } from "./invoiceV4"; 2 | -------------------------------------------------------------------------------- /src/product/invoice/internal.ts: -------------------------------------------------------------------------------- 1 | export { InvoiceV4 } from "./invoiceV4"; 2 | export { InvoiceV4Document } from "./invoiceV4Document"; 3 | export { InvoiceV4LineItem } from "./invoiceV4LineItem"; 4 | -------------------------------------------------------------------------------- /src/product/invoice/invoiceV4.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { InvoiceV4Document } from "./invoiceV4Document"; 3 | 4 | /** 5 | * Invoice API version 4 inference prediction. 6 | */ 7 | export class InvoiceV4 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "invoices"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "4"; 12 | /** The document-level prediction. */ 13 | prediction: InvoiceV4Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new InvoiceV4Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | InvoiceV4Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/invoiceSplitter/index.ts: -------------------------------------------------------------------------------- 1 | export { InvoiceSplitterV1 } from "./invoiceSplitterV1"; 2 | -------------------------------------------------------------------------------- /src/product/invoiceSplitter/internal.ts: -------------------------------------------------------------------------------- 1 | export { InvoiceSplitterV1 } from "./invoiceSplitterV1"; 2 | export { InvoiceSplitterV1Document } from "./invoiceSplitterV1Document"; 3 | export { InvoiceSplitterV1InvoicePageGroup } from "./invoiceSplitterV1InvoicePageGroup"; 4 | -------------------------------------------------------------------------------- /src/product/invoiceSplitter/invoiceSplitterV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { InvoiceSplitterV1Document } from "./invoiceSplitterV1Document"; 3 | 4 | /** 5 | * Invoice Splitter API version 1 inference prediction. 6 | */ 7 | export class InvoiceSplitterV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "invoice_splitter"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: InvoiceSplitterV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new InvoiceSplitterV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | InvoiceSplitterV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/invoiceSplitter/invoiceSplitterV1Document.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Prediction, 3 | StringDict, 4 | cleanOutString,lineSeparator, 5 | } from "../../parsing/common"; 6 | import { InvoiceSplitterV1InvoicePageGroup } from "./invoiceSplitterV1InvoicePageGroup"; 7 | 8 | 9 | /** 10 | * Invoice Splitter API version 1.4 document data. 11 | */ 12 | export class InvoiceSplitterV1Document implements Prediction { 13 | /** List of page groups. Each group represents a single invoice within a multi-invoice document. */ 14 | invoicePageGroups: InvoiceSplitterV1InvoicePageGroup[] = []; 15 | 16 | constructor(rawPrediction: StringDict, pageId?: number) { 17 | rawPrediction["invoice_page_groups"] && 18 | rawPrediction["invoice_page_groups"].map( 19 | (itemPrediction: StringDict) => 20 | this.invoicePageGroups.push( 21 | new InvoiceSplitterV1InvoicePageGroup({ 22 | prediction: itemPrediction, 23 | pageId: pageId, 24 | }) 25 | ) 26 | ); 27 | } 28 | 29 | /** 30 | * Default string representation. 31 | */ 32 | toString(): string { 33 | let invoicePageGroupsSummary:string = ""; 34 | if (this.invoicePageGroups && this.invoicePageGroups.length > 0) { 35 | const invoicePageGroupsColSizes:number[] = [74]; 36 | invoicePageGroupsSummary += "\n" + lineSeparator(invoicePageGroupsColSizes, "-") + "\n "; 37 | invoicePageGroupsSummary += "| Page Indexes "; 38 | invoicePageGroupsSummary += "|\n" + lineSeparator(invoicePageGroupsColSizes, "="); 39 | invoicePageGroupsSummary += this.invoicePageGroups.map( 40 | (item) => 41 | "\n " + item.toTableLine() + "\n" + lineSeparator(invoicePageGroupsColSizes, "-") 42 | ).join(""); 43 | } 44 | const outStr = `:Invoice Page Groups: ${invoicePageGroupsSummary}`.trimEnd(); 45 | return cleanOutString(outStr); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/product/invoiceSplitter/invoiceSplitterV1InvoicePageGroup.ts: -------------------------------------------------------------------------------- 1 | import { StringDict } from "../../parsing/common"; 2 | import { Polygon } from "../../geometry"; 3 | 4 | /** 5 | * List of page groups. Each group represents a single invoice within a multi-invoice document. 6 | */ 7 | export class InvoiceSplitterV1InvoicePageGroup { 8 | /** List of page indexes that belong to the same invoice (group). */ 9 | pageIndexes: Array | null; 10 | /** Confidence score */ 11 | confidence: number = 0.0; 12 | /** The document page on which the information was found. */ 13 | pageId: number; 14 | /** 15 | * Contains the relative vertices coordinates (points) of a polygon containing 16 | * the field in the document. 17 | */ 18 | polygon: Polygon = []; 19 | 20 | constructor({ prediction = {} }: StringDict) { 21 | this.pageIndexes = prediction["page_indexes"]; 22 | this.pageId = prediction["page_id"]; 23 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 24 | if (prediction["polygon"]) { 25 | this.polygon = prediction.polygon; 26 | } 27 | } 28 | 29 | /** 30 | * Collection of fields as representable strings. 31 | */ 32 | #printableValues() { 33 | return { 34 | pageIndexes: this.pageIndexes?.join(", ") ?? "", 35 | }; 36 | } 37 | 38 | /** 39 | * Default string representation. 40 | */ 41 | toString(): string { 42 | const printable = this.#printableValues(); 43 | return ( 44 | "Page Indexes: " + 45 | printable.pageIndexes 46 | ); 47 | } 48 | 49 | /** 50 | * Output in a format suitable for inclusion in an rST table. 51 | */ 52 | toTableLine(): string { 53 | const printable = this.#printableValues(); 54 | return ( 55 | "| " + 56 | printable.pageIndexes.padEnd(72) + 57 | " |" 58 | ); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/product/multiReceiptsDetector/index.ts: -------------------------------------------------------------------------------- 1 | export { MultiReceiptsDetectorV1 } from "./multiReceiptsDetectorV1"; 2 | -------------------------------------------------------------------------------- /src/product/multiReceiptsDetector/internal.ts: -------------------------------------------------------------------------------- 1 | export { MultiReceiptsDetectorV1 } from "./multiReceiptsDetectorV1"; 2 | export { MultiReceiptsDetectorV1Document } from "./multiReceiptsDetectorV1Document"; 3 | -------------------------------------------------------------------------------- /src/product/multiReceiptsDetector/multiReceiptsDetectorV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { MultiReceiptsDetectorV1Document } from "./multiReceiptsDetectorV1Document"; 3 | 4 | /** 5 | * Multi Receipts Detector API version 1 inference prediction. 6 | */ 7 | export class MultiReceiptsDetectorV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "multi_receipts_detector"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: MultiReceiptsDetectorV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new MultiReceiptsDetectorV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | MultiReceiptsDetectorV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/multiReceiptsDetector/multiReceiptsDetectorV1Document.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Prediction, 3 | StringDict, 4 | cleanOutString, 5 | } from "../../parsing/common"; 6 | import { PositionField } from "../../parsing/standard"; 7 | 8 | /** 9 | * Multi Receipts Detector API version 1.1 document data. 10 | */ 11 | export class MultiReceiptsDetectorV1Document implements Prediction { 12 | /** Positions of the receipts on the document. */ 13 | receipts: PositionField[] = []; 14 | 15 | constructor(rawPrediction: StringDict, pageId?: number) { 16 | rawPrediction["receipts"] && 17 | rawPrediction["receipts"].map( 18 | (itemPrediction: StringDict) => 19 | this.receipts.push( 20 | new PositionField({ 21 | prediction: itemPrediction, 22 | pageId: pageId, 23 | }) 24 | ) 25 | ); 26 | } 27 | 28 | /** 29 | * Default string representation. 30 | */ 31 | toString(): string { 32 | const receipts = this.receipts.join("\n "); 33 | const outStr = `:List of Receipts: ${receipts}`.trimEnd(); 34 | return cleanOutString(outStr); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/product/nutritionFactsLabel/index.ts: -------------------------------------------------------------------------------- 1 | export { NutritionFactsLabelV1 } from "./nutritionFactsLabelV1"; 2 | -------------------------------------------------------------------------------- /src/product/nutritionFactsLabel/internal.ts: -------------------------------------------------------------------------------- 1 | export { NutritionFactsLabelV1 } from "./nutritionFactsLabelV1"; 2 | export { NutritionFactsLabelV1AddedSugar } from "./nutritionFactsLabelV1AddedSugar"; 3 | export { NutritionFactsLabelV1Calorie } from "./nutritionFactsLabelV1Calorie"; 4 | export { NutritionFactsLabelV1Cholesterol } from "./nutritionFactsLabelV1Cholesterol"; 5 | export { NutritionFactsLabelV1DietaryFiber } from "./nutritionFactsLabelV1DietaryFiber"; 6 | export { NutritionFactsLabelV1Document } from "./nutritionFactsLabelV1Document"; 7 | export { NutritionFactsLabelV1Nutrient } from "./nutritionFactsLabelV1Nutrient"; 8 | export { NutritionFactsLabelV1Protein } from "./nutritionFactsLabelV1Protein"; 9 | export { NutritionFactsLabelV1SaturatedFat } from "./nutritionFactsLabelV1SaturatedFat"; 10 | export { NutritionFactsLabelV1ServingSize } from "./nutritionFactsLabelV1ServingSize"; 11 | export { NutritionFactsLabelV1Sodium } from "./nutritionFactsLabelV1Sodium"; 12 | export { NutritionFactsLabelV1TotalCarbohydrate } from "./nutritionFactsLabelV1TotalCarbohydrate"; 13 | export { NutritionFactsLabelV1TotalFat } from "./nutritionFactsLabelV1TotalFat"; 14 | export { NutritionFactsLabelV1TotalSugar } from "./nutritionFactsLabelV1TotalSugar"; 15 | export { NutritionFactsLabelV1TransFat } from "./nutritionFactsLabelV1TransFat"; 16 | -------------------------------------------------------------------------------- /src/product/nutritionFactsLabel/nutritionFactsLabelV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { NutritionFactsLabelV1Document } from "./nutritionFactsLabelV1Document"; 3 | 4 | /** 5 | * Nutrition Facts Label API version 1 inference prediction. 6 | */ 7 | export class NutritionFactsLabelV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "nutrition_facts"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: NutritionFactsLabelV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new NutritionFactsLabelV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | NutritionFactsLabelV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/nutritionFactsLabel/nutritionFactsLabelV1ServingSize.ts: -------------------------------------------------------------------------------- 1 | 2 | import { floatToString } from "../../parsing/common"; 3 | import { StringDict } from "../../parsing/common"; 4 | import { Polygon } from "../../geometry"; 5 | 6 | /** 7 | * The size of a single serving of the product. 8 | */ 9 | export class NutritionFactsLabelV1ServingSize { 10 | /** The amount of a single serving. */ 11 | amount: number | null; 12 | /** The unit for the amount of a single serving. */ 13 | unit: string | null; 14 | /** Confidence score */ 15 | confidence: number = 0.0; 16 | /** The document page on which the information was found. */ 17 | pageId: number; 18 | /** 19 | * Contains the relative vertices coordinates (points) of a polygon containing 20 | * the field in the document. 21 | */ 22 | polygon: Polygon = []; 23 | 24 | constructor({ prediction = {} }: StringDict) { 25 | if ( 26 | prediction["amount"] !== undefined && 27 | prediction["amount"] !== null && 28 | !isNaN(prediction["amount"]) 29 | ) { 30 | this.amount = +parseFloat(prediction["amount"]); 31 | } else { 32 | this.amount = null; 33 | } 34 | this.unit = prediction["unit"]; 35 | this.pageId = prediction["page_id"]; 36 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 37 | if (prediction["polygon"]) { 38 | this.polygon = prediction.polygon; 39 | } 40 | } 41 | 42 | /** 43 | * Collection of fields as representable strings. 44 | */ 45 | #printableValues() { 46 | return { 47 | amount: this.amount !== undefined ? floatToString(this.amount) : "", 48 | unit: this.unit ?? "", 49 | }; 50 | } 51 | 52 | /** 53 | * Default string representation. 54 | */ 55 | toString(): string { 56 | const printable = this.#printableValues(); 57 | return ( 58 | "Amount: " + 59 | printable.amount + 60 | ", Unit: " + 61 | printable.unit 62 | ); 63 | } 64 | 65 | /** 66 | * Output in a format suitable for inclusion in a field list. 67 | */ 68 | toFieldList(): string { 69 | const printable = this.#printableValues(); 70 | return ` 71 | :Amount: ${printable.amount} 72 | :Unit: ${printable.unit}`.trimEnd(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/product/passport/index.ts: -------------------------------------------------------------------------------- 1 | export { PassportV1 } from "./passportV1"; 2 | -------------------------------------------------------------------------------- /src/product/passport/internal.ts: -------------------------------------------------------------------------------- 1 | export { PassportV1 } from "./passportV1"; 2 | export { PassportV1Document } from "./passportV1Document"; 3 | -------------------------------------------------------------------------------- /src/product/passport/passportV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { PassportV1Document } from "./passportV1Document"; 3 | 4 | /** 5 | * Passport API version 1 inference prediction. 6 | */ 7 | export class PassportV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "passport"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: PassportV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new PassportV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | PassportV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/receipt/index.ts: -------------------------------------------------------------------------------- 1 | export { ReceiptV5 } from "./receiptV5"; 2 | -------------------------------------------------------------------------------- /src/product/receipt/internal.ts: -------------------------------------------------------------------------------- 1 | export { ReceiptV5 } from "./receiptV5"; 2 | export { ReceiptV5Document } from "./receiptV5Document"; 3 | export { ReceiptV5LineItem } from "./receiptV5LineItem"; 4 | -------------------------------------------------------------------------------- /src/product/receipt/receiptV5.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { ReceiptV5Document } from "./receiptV5Document"; 3 | 4 | /** 5 | * Receipt API version 5 inference prediction. 6 | */ 7 | export class ReceiptV5 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "expense_receipts"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "5"; 12 | /** The document-level prediction. */ 13 | prediction: ReceiptV5Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new ReceiptV5Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | ReceiptV5Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/resume/index.ts: -------------------------------------------------------------------------------- 1 | export { ResumeV1 } from "./resumeV1"; 2 | -------------------------------------------------------------------------------- /src/product/resume/internal.ts: -------------------------------------------------------------------------------- 1 | export { ResumeV1 } from "./resumeV1"; 2 | export { ResumeV1Certificate } from "./resumeV1Certificate"; 3 | export { ResumeV1Document } from "./resumeV1Document"; 4 | export { ResumeV1Education } from "./resumeV1Education"; 5 | export { ResumeV1Language } from "./resumeV1Language"; 6 | export { ResumeV1ProfessionalExperience } from "./resumeV1ProfessionalExperience"; 7 | export { ResumeV1SocialNetworksUrl } from "./resumeV1SocialNetworksUrl"; 8 | -------------------------------------------------------------------------------- /src/product/resume/resumeV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../parsing/common"; 2 | import { ResumeV1Document } from "./resumeV1Document"; 3 | 4 | /** 5 | * Resume API version 1 inference prediction. 6 | */ 7 | export class ResumeV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "resume"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: ResumeV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new ResumeV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | ResumeV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/resume/resumeV1Language.ts: -------------------------------------------------------------------------------- 1 | 2 | import { cleanSpecialChars } from "../../parsing/common"; 3 | import { StringDict } from "../../parsing/common"; 4 | import { Polygon } from "../../geometry"; 5 | 6 | /** 7 | * The list of languages that the candidate is proficient in. 8 | */ 9 | export class ResumeV1Language { 10 | /** The language's ISO 639 code. */ 11 | language: string | null; 12 | /** The candidate's level for the language. */ 13 | level: string | null; 14 | /** Confidence score */ 15 | confidence: number = 0.0; 16 | /** The document page on which the information was found. */ 17 | pageId: number; 18 | /** 19 | * Contains the relative vertices coordinates (points) of a polygon containing 20 | * the field in the document. 21 | */ 22 | polygon: Polygon = []; 23 | 24 | constructor({ prediction = {} }: StringDict) { 25 | this.language = prediction["language"]; 26 | this.level = prediction["level"]; 27 | this.pageId = prediction["page_id"]; 28 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 29 | if (prediction["polygon"]) { 30 | this.polygon = prediction.polygon; 31 | } 32 | } 33 | 34 | /** 35 | * Collection of fields as representable strings. 36 | */ 37 | #printableValues() { 38 | return { 39 | language: this.language ? 40 | this.language.length <= 8 ? 41 | cleanSpecialChars(this.language) : 42 | cleanSpecialChars(this.language).slice(0, 5) + "..." : 43 | "", 44 | level: this.level ? 45 | this.level.length <= 20 ? 46 | cleanSpecialChars(this.level) : 47 | cleanSpecialChars(this.level).slice(0, 17) + "..." : 48 | "", 49 | }; 50 | } 51 | 52 | /** 53 | * Default string representation. 54 | */ 55 | toString(): string { 56 | const printable = this.#printableValues(); 57 | return ( 58 | "Language: " + 59 | printable.language + 60 | ", Level: " + 61 | printable.level 62 | ); 63 | } 64 | 65 | /** 66 | * Output in a format suitable for inclusion in an rST table. 67 | */ 68 | toTableLine(): string { 69 | const printable = this.#printableValues(); 70 | return ( 71 | "| " + 72 | printable.language.padEnd(8) + 73 | " | " + 74 | printable.level.padEnd(20) + 75 | " |" 76 | ); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/product/resume/resumeV1SocialNetworksUrl.ts: -------------------------------------------------------------------------------- 1 | 2 | import { cleanSpecialChars } from "../../parsing/common"; 3 | import { StringDict } from "../../parsing/common"; 4 | import { Polygon } from "../../geometry"; 5 | 6 | /** 7 | * The list of social network profiles of the candidate. 8 | */ 9 | export class ResumeV1SocialNetworksUrl { 10 | /** The name of the social network. */ 11 | name: string | null; 12 | /** The URL of the social network. */ 13 | url: string | null; 14 | /** Confidence score */ 15 | confidence: number = 0.0; 16 | /** The document page on which the information was found. */ 17 | pageId: number; 18 | /** 19 | * Contains the relative vertices coordinates (points) of a polygon containing 20 | * the field in the document. 21 | */ 22 | polygon: Polygon = []; 23 | 24 | constructor({ prediction = {} }: StringDict) { 25 | this.name = prediction["name"]; 26 | this.url = prediction["url"]; 27 | this.pageId = prediction["page_id"]; 28 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 29 | if (prediction["polygon"]) { 30 | this.polygon = prediction.polygon; 31 | } 32 | } 33 | 34 | /** 35 | * Collection of fields as representable strings. 36 | */ 37 | #printableValues() { 38 | return { 39 | name: this.name ? 40 | this.name.length <= 20 ? 41 | cleanSpecialChars(this.name) : 42 | cleanSpecialChars(this.name).slice(0, 17) + "..." : 43 | "", 44 | url: this.url ? 45 | this.url.length <= 50 ? 46 | cleanSpecialChars(this.url) : 47 | cleanSpecialChars(this.url).slice(0, 47) + "..." : 48 | "", 49 | }; 50 | } 51 | 52 | /** 53 | * Default string representation. 54 | */ 55 | toString(): string { 56 | const printable = this.#printableValues(); 57 | return ( 58 | "Name: " + 59 | printable.name + 60 | ", URL: " + 61 | printable.url 62 | ); 63 | } 64 | 65 | /** 66 | * Output in a format suitable for inclusion in an rST table. 67 | */ 68 | toTableLine(): string { 69 | const printable = this.#printableValues(); 70 | return ( 71 | "| " + 72 | printable.name.padEnd(20) + 73 | " | " + 74 | printable.url.padEnd(50) + 75 | " |" 76 | ); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/product/us/bankCheck/bankCheckV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { BankCheckV1Document } from "./bankCheckV1Document"; 3 | import { BankCheckV1Page } from "./bankCheckV1Page"; 4 | 5 | /** 6 | * Bank Check API version 1 inference prediction. 7 | */ 8 | export class BankCheckV1 extends Inference { 9 | /** The endpoint's name. */ 10 | endpointName = "bank_check"; 11 | /** The endpoint's version. */ 12 | endpointVersion = "1"; 13 | /** The document-level prediction. */ 14 | prediction: BankCheckV1Document; 15 | /** The document's pages. */ 16 | pages: Page[] = []; 17 | 18 | constructor(rawPrediction: StringDict) { 19 | super(rawPrediction); 20 | this.prediction = new BankCheckV1Document(rawPrediction["prediction"]); 21 | rawPrediction["pages"].forEach( 22 | (page: StringDict) => { 23 | if (page.prediction !== undefined && page.prediction !== null && 24 | Object.keys(page.prediction).length > 0) { 25 | this.pages.push(new Page( 26 | BankCheckV1Page, 27 | page, 28 | page["id"], 29 | page["orientation"] 30 | )); 31 | } 32 | } 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/product/us/bankCheck/bankCheckV1Document.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Prediction, 3 | StringDict, 4 | cleanOutString, 5 | } from "../../../parsing/common"; 6 | import { 7 | AmountField, 8 | DateField, 9 | StringField, 10 | } from "../../../parsing/standard"; 11 | 12 | /** 13 | * Bank Check API version 1.1 document data. 14 | */ 15 | export class BankCheckV1Document implements Prediction { 16 | /** The check payer's account number. */ 17 | accountNumber: StringField; 18 | /** The amount of the check. */ 19 | amount: AmountField; 20 | /** The issuer's check number. */ 21 | checkNumber: StringField; 22 | /** The date the check was issued. */ 23 | date: DateField; 24 | /** List of the check's payees (recipients). */ 25 | payees: StringField[] = []; 26 | /** The check issuer's routing number. */ 27 | routingNumber: StringField; 28 | 29 | constructor(rawPrediction: StringDict, pageId?: number) { 30 | this.accountNumber = new StringField({ 31 | prediction: rawPrediction["account_number"], 32 | pageId: pageId, 33 | }); 34 | this.amount = new AmountField({ 35 | prediction: rawPrediction["amount"], 36 | pageId: pageId, 37 | }); 38 | this.checkNumber = new StringField({ 39 | prediction: rawPrediction["check_number"], 40 | pageId: pageId, 41 | }); 42 | this.date = new DateField({ 43 | prediction: rawPrediction["date"], 44 | pageId: pageId, 45 | }); 46 | rawPrediction["payees"] && 47 | rawPrediction["payees"].map( 48 | (itemPrediction: StringDict) => 49 | this.payees.push( 50 | new StringField({ 51 | prediction: itemPrediction, 52 | pageId: pageId, 53 | }) 54 | ) 55 | ); 56 | this.routingNumber = new StringField({ 57 | prediction: rawPrediction["routing_number"], 58 | pageId: pageId, 59 | }); 60 | } 61 | 62 | /** 63 | * Default string representation. 64 | */ 65 | toString(): string { 66 | const payees = this.payees.join("\n "); 67 | const outStr = `:Check Issue Date: ${this.date} 68 | :Amount: ${this.amount} 69 | :Payees: ${payees} 70 | :Routing Number: ${this.routingNumber} 71 | :Account Number: ${this.accountNumber} 72 | :Check Number: ${this.checkNumber}`.trimEnd(); 73 | return cleanOutString(outStr); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/product/us/bankCheck/bankCheckV1Page.ts: -------------------------------------------------------------------------------- 1 | import { StringDict, cleanOutString } from "../../../parsing/common"; 2 | import { PositionField } from "../../../parsing/standard"; 3 | 4 | import { BankCheckV1Document } from "./bankCheckV1Document"; 5 | 6 | /** 7 | * Bank Check API version 1.1 page data. 8 | */ 9 | export class BankCheckV1Page extends BankCheckV1Document { 10 | /** The position of the check on the document. */ 11 | checkPosition: PositionField; 12 | /** List of signature positions */ 13 | signaturesPositions: PositionField[] = []; 14 | 15 | constructor(rawPrediction: StringDict, pageId?: number) { 16 | super(rawPrediction, pageId); 17 | 18 | this.checkPosition = new PositionField({ 19 | prediction: rawPrediction["check_position"], 20 | pageId: pageId, 21 | }); 22 | rawPrediction["signatures_positions"].map( 23 | (itemPrediction: StringDict) => 24 | this.signaturesPositions.push( 25 | new PositionField({ 26 | prediction: itemPrediction, 27 | pageId: pageId, 28 | }) 29 | ) 30 | ); 31 | } 32 | 33 | toString(): string { 34 | const signaturesPositions = this.signaturesPositions.join("\n "); 35 | let outStr = `:Check Position: ${this.checkPosition} 36 | :Signature Positions: ${signaturesPositions}`.trimEnd(); 37 | outStr += "\n" + super.toString(); 38 | return cleanOutString(outStr); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/product/us/bankCheck/index.ts: -------------------------------------------------------------------------------- 1 | export { BankCheckV1 } from "./bankCheckV1"; 2 | -------------------------------------------------------------------------------- /src/product/us/bankCheck/internal.ts: -------------------------------------------------------------------------------- 1 | export { BankCheckV1 } from "./bankCheckV1"; 2 | export { BankCheckV1Document } from "./bankCheckV1Document"; 3 | export { BankCheckV1Page } from "./bankCheckV1Page"; 4 | -------------------------------------------------------------------------------- /src/product/us/healthcareCard/healthcareCardV1.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { HealthcareCardV1Document } from "./healthcareCardV1Document"; 3 | 4 | /** 5 | * Healthcare Card API version 1 inference prediction. 6 | */ 7 | export class HealthcareCardV1 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "us_healthcare_cards"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "1"; 12 | /** The document-level prediction. */ 13 | prediction: HealthcareCardV1Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new HealthcareCardV1Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | HealthcareCardV1Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/us/healthcareCard/healthcareCardV1Copay.ts: -------------------------------------------------------------------------------- 1 | import { cleanSpecialChars, floatToString } from "../../../parsing/common"; 2 | import { StringDict } from "../../../parsing/common"; 3 | import { Polygon } from "../../../geometry"; 4 | 5 | /** 6 | * Copayments for covered services. 7 | */ 8 | export class HealthcareCardV1Copay { 9 | /** The price of the service. */ 10 | serviceFees: number | null; 11 | /** The name of the service. */ 12 | serviceName: string | null; 13 | /** Confidence score */ 14 | confidence: number = 0.0; 15 | /** The document page on which the information was found. */ 16 | pageId: number; 17 | /** 18 | * Contains the relative vertices coordinates (points) of a polygon containing 19 | * the field in the document. 20 | */ 21 | polygon: Polygon = []; 22 | 23 | constructor({ prediction = {} }: StringDict) { 24 | if ( 25 | prediction["service_fees"] !== undefined && 26 | prediction["service_fees"] !== null && 27 | !isNaN(prediction["service_fees"]) 28 | ) { 29 | this.serviceFees = +parseFloat(prediction["service_fees"]); 30 | } else { 31 | this.serviceFees = null; 32 | } 33 | this.serviceName = prediction["service_name"]; 34 | this.pageId = prediction["page_id"]; 35 | this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; 36 | if (prediction["polygon"]) { 37 | this.polygon = prediction.polygon; 38 | } 39 | } 40 | 41 | /** 42 | * Collection of fields as representable strings. 43 | */ 44 | #printableValues() { 45 | return { 46 | serviceFees: 47 | this.serviceFees !== undefined ? floatToString(this.serviceFees) : "", 48 | serviceName: this.serviceName ? 49 | this.serviceName.length <= 20 ? 50 | cleanSpecialChars(this.serviceName) : 51 | cleanSpecialChars(this.serviceName).slice(0, 17) + "..." : 52 | "", 53 | }; 54 | } 55 | 56 | /** 57 | * Default string representation. 58 | */ 59 | toString(): string { 60 | const printable = this.#printableValues(); 61 | return ( 62 | "Service Fees: " + 63 | printable.serviceFees + 64 | ", Service Name: " + 65 | printable.serviceName 66 | ); 67 | } 68 | 69 | /** 70 | * Output in a format suitable for inclusion in an rST table. 71 | */ 72 | toTableLine(): string { 73 | const printable = this.#printableValues(); 74 | return ( 75 | "| " + 76 | printable.serviceFees.padEnd(12) + 77 | " | " + 78 | printable.serviceName.padEnd(20) + 79 | " |" 80 | ); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/product/us/healthcareCard/index.ts: -------------------------------------------------------------------------------- 1 | export { HealthcareCardV1 } from "./healthcareCardV1"; 2 | -------------------------------------------------------------------------------- /src/product/us/healthcareCard/internal.ts: -------------------------------------------------------------------------------- 1 | export { HealthcareCardV1 } from "./healthcareCardV1"; 2 | export { HealthcareCardV1Copay } from "./healthcareCardV1Copay"; 3 | export { HealthcareCardV1Document } from "./healthcareCardV1Document"; 4 | -------------------------------------------------------------------------------- /src/product/us/index.ts: -------------------------------------------------------------------------------- 1 | export { BankCheckV1 } from "./bankCheck/bankCheckV1"; 2 | export { HealthcareCardV1 } from "./healthcareCard/healthcareCardV1"; 3 | export { UsMailV2 } from "./usMail/usMailV2"; 4 | export { UsMailV3 } from "./usMail/usMailV3"; 5 | -------------------------------------------------------------------------------- /src/product/us/internal.ts: -------------------------------------------------------------------------------- 1 | export * as bankCheck from "./bankCheck/internal"; 2 | export * as healthcareCard from "./healthcareCard/internal"; 3 | export * as usMail from "./usMail/internal"; 4 | -------------------------------------------------------------------------------- /src/product/us/usMail/index.ts: -------------------------------------------------------------------------------- 1 | export { UsMailV2 } from "./usMailV2"; 2 | export { UsMailV3 } from "./usMailV3"; 3 | -------------------------------------------------------------------------------- /src/product/us/usMail/internal.ts: -------------------------------------------------------------------------------- 1 | export { UsMailV2 } from "./usMailV2"; 2 | export { UsMailV2Document } from "./usMailV2Document"; 3 | export { UsMailV2RecipientAddress } from "./usMailV2RecipientAddress"; 4 | export { UsMailV2SenderAddress } from "./usMailV2SenderAddress"; 5 | export { UsMailV3 } from "./usMailV3"; 6 | export { UsMailV3Document } from "./usMailV3Document"; 7 | export { UsMailV3RecipientAddress } from "./usMailV3RecipientAddress"; 8 | export { UsMailV3SenderAddress } from "./usMailV3SenderAddress"; 9 | -------------------------------------------------------------------------------- /src/product/us/usMail/usMailV2.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { UsMailV2Document } from "./usMailV2Document"; 3 | 4 | /** 5 | * US Mail API version 2 inference prediction. 6 | */ 7 | export class UsMailV2 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "us_mail"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "2"; 12 | /** The document-level prediction. */ 13 | prediction: UsMailV2Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new UsMailV2Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | UsMailV2Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/product/us/usMail/usMailV3.ts: -------------------------------------------------------------------------------- 1 | import { Inference, StringDict, Page } from "../../../parsing/common"; 2 | import { UsMailV3Document } from "./usMailV3Document"; 3 | 4 | /** 5 | * US Mail API version 3 inference prediction. 6 | */ 7 | export class UsMailV3 extends Inference { 8 | /** The endpoint's name. */ 9 | endpointName = "us_mail"; 10 | /** The endpoint's version. */ 11 | endpointVersion = "3"; 12 | /** The document-level prediction. */ 13 | prediction: UsMailV3Document; 14 | /** The document's pages. */ 15 | pages: Page[] = []; 16 | 17 | constructor(rawPrediction: StringDict) { 18 | super(rawPrediction); 19 | this.prediction = new UsMailV3Document(rawPrediction["prediction"]); 20 | rawPrediction["pages"].forEach( 21 | (page: StringDict) => { 22 | if (page.prediction !== undefined && page.prediction !== null && 23 | Object.keys(page.prediction).length > 0) { 24 | this.pages.push(new Page( 25 | UsMailV3Document, 26 | page, 27 | page["id"], 28 | page["orientation"] 29 | )); 30 | } 31 | } 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["ES2020"], 4 | "module": "commonjs", 5 | "target": "ES2020", 6 | 7 | "strict": true, 8 | "esModuleInterop": true, 9 | "skipLibCheck": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "moduleResolution": "node", 12 | 13 | "resolveJsonModule": true, 14 | "declaration": true, 15 | "outDir": "dist", 16 | "baseUrl": "./", 17 | "sourceMap": false, 18 | "newLine": "lf", 19 | }, 20 | "include": ["./src/**/*", "./bin/**/*", "LICENSE"], 21 | "exclude": ["./node_modules/", "./dist/", "./tests/"] 22 | } 23 | -------------------------------------------------------------------------------- /typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "validation": { 3 | "notExported": false, 4 | "invalidLink": true, 5 | "notDocumented": true, 6 | } 7 | } 8 | --------------------------------------------------------------------------------