From 970b10f7659d6bd99d86eae3c3688c1306d6f8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Thu, 23 Oct 2025 16:53:28 +0200 Subject: [PATCH] :sparkles: add more details to errors --- docs/bank_account_details_v2.md | 144 ----- docs/bank_check_v1.md | 189 ------ docs/barcode_reader_v1.md | 111 ---- docs/bill_of_lading_v1.md | 254 -------- docs/business_card_v1.md | 172 ------ docs/carte_grise_v1.md | 461 -------------- docs/cropper_v1.md | 110 ---- docs/custom_v1.md | 159 ----- docs/delivery_notes_v1.md | 146 ----- docs/driver_license_v1.md | 190 ------ docs/energy_bill_fra_v1.md | 320 ---------- docs/expense_receipts_v5.md | 383 ------------ docs/financial_document_v1.md | 582 ------------------ docs/french_healthcard_v1.md | 120 ---- docs/generated_v1.md | 100 --- docs/getting_started.md | 299 --------- docs/idcard_fr_v2.md | 269 -------- docs/ind_passport_v1.md | 284 --------- docs/international_id_v2.md | 241 -------- docs/invoice_splitter_v1.md | 105 ---- docs/invoices_v4.md | 543 ---------------- docs/multi_receipts_detector_v1.md | 115 ---- docs/nutrition_facts_v1.md | 377 ------------ docs/passport_v1.md | 193 ------ docs/payslip_fra_v2.md | 297 --------- docs/payslip_fra_v3.md | 322 ---------- docs/resume_v1.md | 361 ----------- docs/us_healthcare_cards_v1.md | 236 ------- docs/us_mail_v3.md | 131 ---- src/clientV2.ts | 4 +- src/errors/mindeeError.ts | 19 +- src/http/mindeeApiV2.ts | 29 +- src/parsing/v2/errorItem.ts | 22 + src/parsing/v2/errorResponse.ts | 42 +- src/parsing/v2/index.ts | 3 +- .../api/invoiceSplitterReconstruction.spec.ts | 42 -- tests/api/multiReceiptsReconstruction.spec.ts | 29 - tests/data | 2 +- .../invoiceSplitter.integration.ts | 9 +- .../invoiceSplitterExtractor.spec.ts | 9 +- .../multiReceiptsExtractor.spec.ts | 25 +- tests/index.ts | 5 + tests/{inputs => input}/localResponse.spec.ts | 15 +- .../{inputs => input}/pageOperations.spec.ts | 7 +- tests/{inputs => input}/sources.spec.ts | 78 +-- .../{inputs => input}/urlInputSource.spec.ts | 0 tests/pdf/pdfOperation.spec.ts | 21 +- tests/pdf/pdfTypes.spec.ts | 16 +- tests/{ => v1}/api/asyncResponse.spec.ts | 21 +- tests/{ => v1}/api/endpoint.spec.ts | 20 +- tests/{ => v1}/api/feedbackResponse.spec.ts | 7 +- .../api/invoiceSplitterReconstruction.spec.ts | 42 ++ .../api/multiReceiptsReconstruction.spec.ts | 32 + tests/{ => v1}/api/response.spec.ts | 13 +- tests/{ => v1}/extras/extras.integration.ts | 15 +- tests/{ => v1}/extras/fullTextOcr.spec.ts | 13 +- .../input}/sources.integration.ts | 10 +- .../input}/urlInputSource.integration.ts | 8 +- .../{ => v1}/parsing/standard/amount.spec.ts | 2 +- .../parsing/standard/classification.spec.ts | 2 +- tests/{ => v1}/parsing/standard/date.spec.ts | 2 +- tests/{ => v1}/parsing/standard/field.spec.ts | 2 +- .../{ => v1}/parsing/standard/locale.spec.ts | 2 +- .../parsing/standard/orientation.spec.ts | 2 +- .../parsing/standard/paymentDetails.spec.ts | 2 +- .../parsing/standard/position.spec.ts | 2 +- tests/{ => v1}/parsing/standard/tax.spec.ts | 2 +- tests/{ => v1}/parsing/standard/text.spec.ts | 2 +- .../barcodeReader/barcodeReaderV1.spec.ts | 2 +- .../billOfLading/billOfLadingV1.spec.ts | 2 +- .../businessCard/businessCardV1.spec.ts | 2 +- .../product/cropper/cropperV1.spec.ts | 2 +- .../product/custom/customDocument.spec.ts | 10 +- .../{ => v1}/product/custom/lineItems.spec.ts | 4 +- .../deliveryNote/deliveryNoteV1.spec.ts | 2 +- .../driverLicense/driverLicenseV1.spec.ts | 2 +- .../financialDocumentV1.spec.ts | 2 +- .../bankAccountDetailsV1.spec.ts | 2 +- .../bankAccountDetailsV2.spec.ts | 2 +- .../fr/carteGrise/carteGriseV1.spec.ts | 2 +- .../fr/energyBill/energyBillV1.spec.ts | 2 +- .../fr/healthCard/healthCardV1.spec.ts | 2 +- .../product/fr/idCard/idCardV1.spec.ts | 2 +- .../product/fr/idCard/idCardV2.spec.ts | 2 +- .../product/fr/payslip/payslipV2.spec.ts | 2 +- .../product/fr/payslip/payslipV3.spec.ts | 2 +- .../product/generated/generatedList.spec.ts | 2 +- .../product/generated/generatedObject.spec.ts | 2 +- .../product/generated/generatedV1.spec.ts | 172 +++--- .../indianPassport/indianPassportV1.spec.ts | 2 +- .../internationalId/internationalIdV2.spec.ts | 2 +- .../product/invoice/invoiceV4.spec.ts | 2 +- .../invoiceSplitter/invoiceSplitterV1.spec.ts | 2 +- .../multiReceiptsDetectorV1.spec.ts | 2 +- .../nutritionFactsLabelV1.spec.ts | 2 +- tests/{ => v1}/product/ocr/ocr.spec.ts | 4 +- .../product/passport/passportV1.spec.ts | 2 +- .../product/receipt/receiptV5.spec.ts | 2 +- .../{ => v1}/product/resume/resumeV1.spec.ts | 2 +- .../product/us/bankCheck/bankCheckV1.spec.ts | 2 +- .../healthcareCard/healthcareCardV1.spec.ts | 2 +- .../product/us/usMail/usMailV3.spec.ts | 2 +- .../workflows/workflow.integration.ts | 18 +- tests/{ => v1}/workflows/workflow.spec.ts | 13 +- tests/v2/clientV2.integration.ts | 42 +- tests/v2/clientV2.spec.ts | 11 +- .../v2 => v2/parsing}/inference.spec.ts | 7 +- tests/v2/parsing/job.spec.ts | 37 ++ 108 files changed, 558 insertions(+), 7612 deletions(-) delete mode 100644 docs/bank_account_details_v2.md delete mode 100644 docs/bank_check_v1.md delete mode 100644 docs/barcode_reader_v1.md delete mode 100644 docs/bill_of_lading_v1.md delete mode 100644 docs/business_card_v1.md delete mode 100644 docs/carte_grise_v1.md delete mode 100644 docs/cropper_v1.md delete mode 100644 docs/custom_v1.md delete mode 100644 docs/delivery_notes_v1.md delete mode 100644 docs/driver_license_v1.md delete mode 100644 docs/energy_bill_fra_v1.md delete mode 100644 docs/expense_receipts_v5.md delete mode 100644 docs/financial_document_v1.md delete mode 100644 docs/french_healthcard_v1.md delete mode 100644 docs/generated_v1.md delete mode 100644 docs/getting_started.md delete mode 100644 docs/idcard_fr_v2.md delete mode 100644 docs/ind_passport_v1.md delete mode 100644 docs/international_id_v2.md delete mode 100644 docs/invoice_splitter_v1.md delete mode 100644 docs/invoices_v4.md delete mode 100644 docs/multi_receipts_detector_v1.md delete mode 100644 docs/nutrition_facts_v1.md delete mode 100644 docs/passport_v1.md delete mode 100644 docs/payslip_fra_v2.md delete mode 100644 docs/payslip_fra_v3.md delete mode 100644 docs/resume_v1.md delete mode 100644 docs/us_healthcare_cards_v1.md delete mode 100644 docs/us_mail_v3.md create mode 100644 src/parsing/v2/errorItem.ts delete mode 100644 tests/api/invoiceSplitterReconstruction.spec.ts delete mode 100644 tests/api/multiReceiptsReconstruction.spec.ts create mode 100644 tests/index.ts rename tests/{inputs => input}/localResponse.spec.ts (89%) rename tests/{inputs => input}/pageOperations.spec.ts (85%) rename tests/{inputs => input}/sources.spec.ts (82%) rename tests/{inputs => input}/urlInputSource.spec.ts (100%) rename tests/{ => v1}/api/asyncResponse.spec.ts (78%) rename tests/{ => v1}/api/endpoint.spec.ts (83%) rename tests/{ => v1}/api/feedbackResponse.spec.ts (64%) create mode 100644 tests/v1/api/invoiceSplitterReconstruction.spec.ts create mode 100644 tests/v1/api/multiReceiptsReconstruction.spec.ts rename tests/{ => v1}/api/response.spec.ts (80%) rename tests/{ => v1}/extras/extras.integration.ts (76%) rename tests/{ => v1}/extras/fullTextOcr.spec.ts (79%) rename tests/{inputs => v1/input}/sources.integration.ts (88%) rename tests/{inputs => v1/input}/urlInputSource.integration.ts (79%) rename tests/{ => v1}/parsing/standard/amount.spec.ts (93%) rename tests/{ => v1}/parsing/standard/classification.spec.ts (88%) rename tests/{ => v1}/parsing/standard/date.spec.ts (94%) rename tests/{ => v1}/parsing/standard/field.spec.ts (97%) rename tests/{ => v1}/parsing/standard/locale.spec.ts (95%) rename tests/{ => v1}/parsing/standard/orientation.spec.ts (92%) rename tests/{ => v1}/parsing/standard/paymentDetails.spec.ts (96%) rename tests/{ => v1}/parsing/standard/position.spec.ts (95%) rename tests/{ => v1}/parsing/standard/tax.spec.ts (95%) rename tests/{ => v1}/parsing/standard/text.spec.ts (94%) rename tests/{ => v1}/product/barcodeReader/barcodeReaderV1.spec.ts (96%) rename tests/{ => v1}/product/billOfLading/billOfLadingV1.spec.ts (98%) rename tests/{ => v1}/product/businessCard/businessCardV1.spec.ts (97%) rename tests/{ => v1}/product/cropper/cropperV1.spec.ts (97%) rename tests/{ => v1}/product/custom/customDocument.spec.ts (95%) rename tests/{ => v1}/product/custom/lineItems.spec.ts (97%) rename tests/{ => v1}/product/deliveryNote/deliveryNoteV1.spec.ts (97%) rename tests/{ => v1}/product/driverLicense/driverLicenseV1.spec.ts (97%) rename tests/{ => v1}/product/financialDocument/financialDocumentV1.spec.ts (99%) rename tests/{ => v1}/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts (96%) rename tests/{ => v1}/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts (97%) rename tests/{ => v1}/product/fr/carteGrise/carteGriseV1.spec.ts (98%) rename tests/{ => v1}/product/fr/energyBill/energyBillV1.spec.ts (98%) rename tests/{ => v1}/product/fr/healthCard/healthCardV1.spec.ts (97%) rename tests/{ => v1}/product/fr/idCard/idCardV1.spec.ts (98%) rename tests/{ => v1}/product/fr/idCard/idCardV2.spec.ts (98%) rename tests/{ => v1}/product/fr/payslip/payslipV2.spec.ts (98%) rename tests/{ => v1}/product/fr/payslip/payslipV3.spec.ts (98%) rename tests/{ => v1}/product/generated/generatedList.spec.ts (85%) rename tests/{ => v1}/product/generated/generatedObject.spec.ts (87%) rename tests/{ => v1}/product/generated/generatedV1.spec.ts (59%) rename tests/{ => v1}/product/ind/indianPassport/indianPassportV1.spec.ts (98%) rename tests/{ => v1}/product/internationalId/internationalIdV2.spec.ts (98%) rename tests/{ => v1}/product/invoice/invoiceV4.spec.ts (98%) rename tests/{ => v1}/product/invoiceSplitter/invoiceSplitterV1.spec.ts (96%) rename tests/{ => v1}/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts (96%) rename tests/{ => v1}/product/nutritionFactsLabel/nutritionFactsLabelV1.spec.ts (98%) rename tests/{ => v1}/product/ocr/ocr.spec.ts (92%) rename tests/{ => v1}/product/passport/passportV1.spec.ts (97%) rename tests/{ => v1}/product/receipt/receiptV5.spec.ts (97%) rename tests/{ => v1}/product/resume/resumeV1.spec.ts (98%) rename tests/{ => v1}/product/us/bankCheck/bankCheckV1.spec.ts (97%) rename tests/{ => v1}/product/us/healthcareCard/healthcareCardV1.spec.ts (97%) rename tests/{ => v1}/product/us/usMail/usMailV3.spec.ts (97%) rename tests/{ => v1}/workflows/workflow.integration.ts (83%) rename tests/{ => v1}/workflows/workflow.spec.ts (88%) rename tests/{parsing/v2 => v2/parsing}/inference.spec.ts (98%) create mode 100644 tests/v2/parsing/job.spec.ts diff --git a/docs/bank_account_details_v2.md b/docs/bank_account_details_v2.md deleted file mode 100644 index 20f46f82d..000000000 --- a/docs/bank_account_details_v2.md +++ /dev/null @@ -1,144 +0,0 @@ ---- -title: FR Bank Account Details OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-fr-bank-account-details-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Bank Account Details API](https://platform.mindee.com/mindee/bank_account_details). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_account_details/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Bank Account Details sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_account_details/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.fr.BankAccountDetailsV2, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: bc8f7265-8dab-49fe-810c-d50049605578 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/bank_account_details v2.0 -:Rotation applied: Yes - -Prediction -========== -:Account Holder's Names: MME HEGALALDIA L ENVOL -:Basic Bank Account Number: - :Bank Code: 13335 - :Branch Code: 00040 - :Key: 06 - :Account Number: 08932891361 -:IBAN: FR7613335000400893289136106 -:SWIFT Code: CEPAFRPP333 - -Page Predictions -================ - -Page 0 ------- -:Account Holder's Names: MME HEGALALDIA L ENVOL -:Basic Bank Account Number: - :Bank Code: 13335 - :Branch Code: 00040 - :Key: 06 - :Account Number: 08932891361 -:IBAN: FR7613335000400893289136106 -:SWIFT Code: CEPAFRPP333 -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Basic Bank Account Number Field -Full extraction of BBAN, including: branch code, bank code, account and key. - -A `BankAccountDetailsV2Bban` implements the following attributes: - -* `bbanBankCode` (string): The BBAN bank code outputted as a string. -* `bbanBranchCode` (string): The BBAN branch code outputted as a string. -* `bbanKey` (string): The BBAN key outputted as a string. -* `bbanNumber` (string): The BBAN Account number outputted as a string. - -# Attributes -The following fields are extracted for Bank Account Details V2: - -## Account Holder's Names -**accountHoldersNames** ([StringField](#string-field)): Full extraction of the account holders names. - -```js -console.log(result.document.inference.prediction.accountHoldersNames.value); -``` - -## Basic Bank Account Number -**bban** ([BankAccountDetailsV2Bban](#basic-bank-account-number-field)): Full extraction of BBAN, including: branch code, bank code, account and key. - -```js -console.log(result.document.inference.prediction.bban.value); -``` - -## IBAN -**iban** ([StringField](#string-field)): Full extraction of the IBAN number. - -```js -console.log(result.document.inference.prediction.iban.value); -``` - -## SWIFT Code -**swiftCode** ([StringField](#string-field)): Full extraction of the SWIFT code. - -```js -console.log(result.document.inference.prediction.swiftCode.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/bank_check_v1.md b/docs/bank_check_v1.md deleted file mode 100644 index cb3279193..000000000 --- a/docs/bank_check_v1.md +++ /dev/null @@ -1,189 +0,0 @@ ---- -title: US Bank Check OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-us-bank-check-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Bank Check API](https://platform.mindee.com/mindee/bank_check). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_check/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Bank Check sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bank_check/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.us.BankCheckV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: b9809586-57ae-4f84-a35d-a85b2be1f2a2 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/bank_check v1.0 -:Rotation applied: Yes - -Prediction -========== -:Check Issue Date: 2022-03-29 -:Amount: 15332.90 -:Payees: JOHN DOE - JANE DOE -:Routing Number: -:Account Number: 7789778136 -:Check Number: 0003401 - -Page Predictions -================ - -Page 0 ------- -:Check Position: Polygon with 21 points. -:Signature Positions: Polygon with 6 points. -:Check Issue Date: 2022-03-29 -:Amount: 15332.90 -:Payees: JOHN DOE - JANE DOE -:Routing Number: -:Account Number: 7789778136 -:Check Number: 0003401 -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### Amount Field -The amount field `AmountField` only has one constraint: its **value** is a `number` (or `undefined`). - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - - -### Position Field -The position field `PositionField` does not implement all the basic `Field` attributes, only **boundingBox**, **polygon** and **pageId**. On top of these, it has access to: - -* **rectangle** (`[Point, Point, Point, Point]`): a Polygon with four points that may be oriented (even beyond canvas). -* **quadrangle** (`[Point, Point, Point, Point]`): a free polygon made up of four points. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -## Page-Level Fields -Some fields are constrained to the page level, and so will not be retrievable at document level. - -# Attributes -The following fields are extracted for Bank Check V1: - -## Account Number -**accountNumber** ([StringField](#string-field)): The check payer's account number. - -```js -console.log(result.document.inference.prediction.accountNumber.value); -``` - -## Amount -**amount** ([AmountField](#amount-field)): The amount of the check. - -```js -console.log(result.document.inference.prediction.amount.value); -``` - -## Check Number -**checkNumber** ([StringField](#string-field)): The issuer's check number. - -```js -console.log(result.document.inference.prediction.checkNumber.value); -``` - -## Check Position -[๐Ÿ“„](#page-level-fields "This field is only present on individual pages.")**checkPosition** ([PositionField](#position-field)): The position of the check on the document. - -```js -for (const checkPositionElem of result.document.checkPosition) { - console.log(checkPositionElem.polygon); -} -``` - -## Check Issue Date -**date** ([DateField](#date-field)): The date the check was issued. - -```js -console.log(result.document.inference.prediction.date.value); -``` - -## Payees -**payees** ([StringField](#string-field)[]): List of the check's payees (recipients). - -```js -for (const payeesElem of result.document.inference.prediction.payees) { - console.log(payeesElem.value); -} -``` - -## Routing Number -**routingNumber** ([StringField](#string-field)): The check issuer's routing number. - -```js -console.log(result.document.inference.prediction.routingNumber.value); -``` - -## Signature Positions -[๐Ÿ“„](#page-level-fields "This field is only present on individual pages.")**signaturesPositions** ([PositionField](#position-field)[]): List of signature positions - -```js -for (const page of result.document.inference.pages) { - for (const signaturesPositionsElem of page.prediction.signaturesPositions) { - console.log(signaturesPositionsElem.polygon); - console.log(signaturesPositionsElem.quadrangle); - console.log(signaturesPositionsElem.rectangle); - console.log(signaturesPositionsElem.boundingBox); - } -} -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/barcode_reader_v1.md b/docs/barcode_reader_v1.md deleted file mode 100644 index 6b6cef631..000000000 --- a/docs/barcode_reader_v1.md +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: Barcode Reader OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-barcode-reader-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Barcode Reader API](https://platform.mindee.com/mindee/barcode_reader). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/barcode_reader/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Barcode Reader sample](https://github.com/mindee/client-lib-test-data/blob/main/products/barcode_reader/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.BarcodeReaderV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: f9c48da1-a306-4805-8da8-f7231fda2d88 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/barcode_reader v1.0 -:Rotation applied: Yes - -Prediction -========== -:Barcodes 1D: Mindee -:Barcodes 2D: https://developers.mindee.com/docs/barcode-reader-ocr - I love paperwork! - Said no one ever - -Page Predictions -================ - -Page 0 ------- -:Barcodes 1D: Mindee -:Barcodes 2D: https://developers.mindee.com/docs/barcode-reader-ocr - I love paperwork! - Said no one ever -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -# Attributes -The following fields are extracted for Barcode Reader V1: - -## Barcodes 1D -**codes1D** ([StringField](#string-field)[]): List of decoded 1D barcodes. - -```js -for (const codes1DElem of result.document.inference.prediction.codes1D) { - console.log(codes1DElem.value); -} -``` - -## Barcodes 2D -**codes2D** ([StringField](#string-field)[]): List of decoded 2D barcodes. - -```js -for (const codes2DElem of result.document.inference.prediction.codes2D) { - console.log(codes2DElem.value); -} -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/bill_of_lading_v1.md b/docs/bill_of_lading_v1.md deleted file mode 100644 index 41dd68630..000000000 --- a/docs/bill_of_lading_v1.md +++ /dev/null @@ -1,254 +0,0 @@ ---- -title: Bill of Lading OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-bill-of-lading-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Bill of Lading API](https://platform.mindee.com/mindee/bill_of_lading). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/bill_of_lading/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Bill of Lading sample](https://github.com/mindee/client-lib-test-data/blob/main/products/bill_of_lading/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.BillOfLadingV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 3b5250a1-b52c-4e0b-bc3e-2f0146b04e29 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/bill_of_lading v1.1 -:Rotation applied: No - -Prediction -========== -:Bill of Lading Number: XYZ123456 -:Shipper: - :Address: 123 OCEAN DRIVE, SHANGHAI, CHINA - :Email: - :Name: GLOBAL FREIGHT SOLUTIONS INC. - :Phone: 86-21-12345678 -:Consignee: - :Address: 789 TRADE STREET, SINGAPORE 567890, SINGAPORE - :Email: - :Name: PACIFIC TRADING CO. - :Phone: 65-65432100 -:Notify Party: - :Address: 789 TRADE STREET, SINGAPORE 567890, SINGAPORE - :Email: - :Name: PACIFIC TRADING CO. - :Phone: 65-65432100 -:Carrier: - :Name: GLOBAL SHIPPING CO.,LTD. - :Professional Number: - :SCAC: -:Items: - +--------------------------------------+--------------+-------------+------------------+----------+-------------+ - | Description | Gross Weight | Measurement | Measurement Unit | Quantity | Weight Unit | - +======================================+==============+=============+==================+==========+=============+ - | ELECTRONIC COMPONENTS\nP/N: 12345... | 500.00 | 1.50 | cbm | 1.00 | kgs | - +--------------------------------------+--------------+-------------+------------------+----------+-------------+ -:Port of Loading: SHANGHAI, CHINA -:Port of Discharge: LOS ANGELES, USA -:Place of Delivery: LOS ANGELES, USA -:Date of issue: 2022-09-30 -:Departure Date: -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Carrier Field -The shipping company responsible for transporting the goods. - -A `BillOfLadingV1Carrier` implements the following attributes: - -* `name` (string): The name of the carrier. -* `professionalNumber` (string): The professional number of the carrier. -* `scac` (string): The Standard Carrier Alpha Code (SCAC) of the carrier. -Fields which are specific to this product; they are not used in any other product. - -### Consignee Field -The party to whom the goods are being shipped. - -A `BillOfLadingV1Consignee` implements the following attributes: - -* `address` (string): The address of the consignee. -* `email` (string): The email of the shipper. -* `name` (string): The name of the consignee. -* `phone` (string): The phone number of the consignee. -Fields which are specific to this product; they are not used in any other product. - -### Items Field -The goods being shipped. - -A `BillOfLadingV1CarrierItem` implements the following attributes: - -* `description` (string): A description of the item. -* `grossWeight` (number): The gross weight of the item. -* `measurement` (number): The measurement of the item. -* `measurementUnit` (string): The unit of measurement for the measurement. -* `quantity` (number): The quantity of the item being shipped. -* `weightUnit` (string): The unit of measurement for weights. -Fields which are specific to this product; they are not used in any other product. - -### Notify Party Field -The party to be notified of the arrival of the goods. - -A `BillOfLadingV1NotifyParty` implements the following attributes: - -* `address` (string): The address of the notify party. -* `email` (string): The email of the shipper. -* `name` (string): The name of the notify party. -* `phone` (string): The phone number of the notify party. -Fields which are specific to this product; they are not used in any other product. - -### Shipper Field -The party responsible for shipping the goods. - -A `BillOfLadingV1Shipper` implements the following attributes: - -* `address` (string): The address of the shipper. -* `email` (string): The email of the shipper. -* `name` (string): The name of the shipper. -* `phone` (string): The phone number of the shipper. - -# Attributes -The following fields are extracted for Bill of Lading V1: - -## Bill of Lading Number -**billOfLadingNumber** ([StringField](#string-field)): A unique identifier assigned to a Bill of Lading document. - -```js -console.log(result.document.inference.prediction.billOfLadingNumber.value); -``` - -## Carrier -**carrier** ([BillOfLadingV1Carrier](#carrier-field)): The shipping company responsible for transporting the goods. - -```js -console.log(result.document.inference.prediction.carrier.value); -``` - -## Items -**carrierItems** ([BillOfLadingV1CarrierItem](#items-field)[]): The goods being shipped. - -```js -for (const carrierItemsElem of result.document.inference.prediction.carrierItems) { - console.log(carrierItemsElem.value); -} -``` - -## Consignee -**consignee** ([BillOfLadingV1Consignee](#consignee-field)): The party to whom the goods are being shipped. - -```js -console.log(result.document.inference.prediction.consignee.value); -``` - -## Date of issue -**dateOfIssue** ([DateField](#date-field)): The date when the bill of lading is issued. - -```js -console.log(result.document.inference.prediction.dateOfIssue.value); -``` - -## Departure Date -**departureDate** ([DateField](#date-field)): The date when the vessel departs from the port of loading. - -```js -console.log(result.document.inference.prediction.departureDate.value); -``` - -## Notify Party -**notifyParty** ([BillOfLadingV1NotifyParty](#notify-party-field)): The party to be notified of the arrival of the goods. - -```js -console.log(result.document.inference.prediction.notifyParty.value); -``` - -## Place of Delivery -**placeOfDelivery** ([StringField](#string-field)): The place where the goods are to be delivered. - -```js -console.log(result.document.inference.prediction.placeOfDelivery.value); -``` - -## Port of Discharge -**portOfDischarge** ([StringField](#string-field)): The port where the goods are unloaded from the vessel. - -```js -console.log(result.document.inference.prediction.portOfDischarge.value); -``` - -## Port of Loading -**portOfLoading** ([StringField](#string-field)): The port where the goods are loaded onto the vessel. - -```js -console.log(result.document.inference.prediction.portOfLoading.value); -``` - -## Shipper -**shipper** ([BillOfLadingV1Shipper](#shipper-field)): The party responsible for shipping the goods. - -```js -console.log(result.document.inference.prediction.shipper.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/business_card_v1.md b/docs/business_card_v1.md deleted file mode 100644 index dd09fe981..000000000 --- a/docs/business_card_v1.md +++ /dev/null @@ -1,172 +0,0 @@ ---- -title: Business Card OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-business-card-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Business Card API](https://platform.mindee.com/mindee/business_card). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/business_card/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Business Card sample](https://github.com/mindee/client-lib-test-data/blob/main/products/business_card/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.BusinessCardV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 6f9a261f-7609-4687-9af0-46a45156566e -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/business_card v1.0 -:Rotation applied: Yes - -Prediction -========== -:Firstname: Andrew -:Lastname: Morin -:Job Title: Founder & CEO -:Company: RemoteGlobal -:Email: amorin@remoteglobalconsulting.com -:Phone Number: +14015555555 -:Mobile Number: +13015555555 -:Fax Number: +14015555556 -:Address: 178 Main Avenue, Providence, RI 02111 -:Website: www.remoteglobalconsulting.com -:Social Media: https://www.linkedin.com/in/johndoe - https://twitter.com/johndoe -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -# Attributes -The following fields are extracted for Business Card V1: - -## Address -**address** ([StringField](#string-field)): The address of the person. - -```js -console.log(result.document.inference.prediction.address.value); -``` - -## Company -**company** ([StringField](#string-field)): The company the person works for. - -```js -console.log(result.document.inference.prediction.company.value); -``` - -## Email -**email** ([StringField](#string-field)): The email address of the person. - -```js -console.log(result.document.inference.prediction.email.value); -``` - -## Fax Number -**faxNumber** ([StringField](#string-field)): The Fax number of the person. - -```js -console.log(result.document.inference.prediction.faxNumber.value); -``` - -## Firstname -**firstname** ([StringField](#string-field)): The given name of the person. - -```js -console.log(result.document.inference.prediction.firstname.value); -``` - -## Job Title -**jobTitle** ([StringField](#string-field)): The job title of the person. - -```js -console.log(result.document.inference.prediction.jobTitle.value); -``` - -## Lastname -**lastname** ([StringField](#string-field)): The lastname of the person. - -```js -console.log(result.document.inference.prediction.lastname.value); -``` - -## Mobile Number -**mobileNumber** ([StringField](#string-field)): The mobile number of the person. - -```js -console.log(result.document.inference.prediction.mobileNumber.value); -``` - -## Phone Number -**phoneNumber** ([StringField](#string-field)): The phone number of the person. - -```js -console.log(result.document.inference.prediction.phoneNumber.value); -``` - -## Social Media -**socialMedia** ([StringField](#string-field)[]): The social media profiles of the person or company. - -```js -for (const socialMediaElem of result.document.inference.prediction.socialMedia) { - console.log(socialMediaElem.value); -} -``` - -## Website -**website** ([StringField](#string-field)): The website of the person or company. - -```js -console.log(result.document.inference.prediction.website.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/carte_grise_v1.md b/docs/carte_grise_v1.md deleted file mode 100644 index f204a10c0..000000000 --- a/docs/carte_grise_v1.md +++ /dev/null @@ -1,461 +0,0 @@ ---- -title: FR Carte Grise OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-fr-carte-grise-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Carte Grise API](https://platform.mindee.com/mindee/carte_grise). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/carte_grise/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Carte Grise sample](https://github.com/mindee/client-lib-test-data/blob/main/products/carte_grise/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.fr.CarteGriseV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 4443182b-57c1-4426-a288-01b94f226e84 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/carte_grise v1.1 -:Rotation applied: Yes - -Prediction -========== -:a: AB-123-CD -:b: 1998-01-05 -:c1: DUPONT YVES -:c3: 27 RUE DES ROITELETS 59169 FERIN LES BAINS FRANCE -:c41: 2 DELAROCHE -:c4a: EST LE PROPRIETAIRE DU VEHICULE -:d1: -:d3: MODELE -:e: VFS1V2009AS1V2009 -:f1: 1915 -:f2: 1915 -:f3: 1915 -:g: 3030 -:g1: 1307 -:i: 2009-12-04 -:j: N1 -:j1: VP -:j2: AA -:j3: CI -:p1: 1900 -:p2: 90 -:p3: GO -:p6: 6 -:q: 006 -:s1: 5 -:s2: -:u1: 77 -:u2: 3000 -:v7: 155 -:x1: 2011-07-06 -:y1: 17835 -:y2: -:y3: 0 -:y4: 4 -:y5: 2.5 -:y6: 178.35 -:Formula Number: 2009AS05284 -:Owner's First Name: YVES -:Owner's Surname: DUPONT -:MRZ Line 1: -:MRZ Line 2: CI< **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -# Attributes -The following fields are extracted for Carte Grise V1: - -## a -**a** ([StringField](#string-field)): The vehicle's license plate number. - -```js -console.log(result.document.inference.prediction.a.value); -``` - -## b -**b** ([DateField](#date-field)): The vehicle's first release date. - -```js -console.log(result.document.inference.prediction.b.value); -``` - -## c1 -**c1** ([StringField](#string-field)): The vehicle owner's full name including maiden name. - -```js -console.log(result.document.inference.prediction.c1.value); -``` - -## c3 -**c3** ([StringField](#string-field)): The vehicle owner's address. - -```js -console.log(result.document.inference.prediction.c3.value); -``` - -## c41 -**c41** ([StringField](#string-field)): Number of owners of the license certificate. - -```js -console.log(result.document.inference.prediction.c41.value); -``` - -## c4a -**c4A** ([StringField](#string-field)): Mentions about the ownership of the vehicle. - -```js -console.log(result.document.inference.prediction.c4A.value); -``` - -## d1 -**d1** ([StringField](#string-field)): The vehicle's brand. - -```js -console.log(result.document.inference.prediction.d1.value); -``` - -## d3 -**d3** ([StringField](#string-field)): The vehicle's commercial name. - -```js -console.log(result.document.inference.prediction.d3.value); -``` - -## e -**e** ([StringField](#string-field)): The Vehicle Identification Number (VIN). - -```js -console.log(result.document.inference.prediction.e.value); -``` - -## f1 -**f1** ([StringField](#string-field)): The vehicle's maximum admissible weight. - -```js -console.log(result.document.inference.prediction.f1.value); -``` - -## f2 -**f2** ([StringField](#string-field)): The vehicle's maximum admissible weight within the license's state. - -```js -console.log(result.document.inference.prediction.f2.value); -``` - -## f3 -**f3** ([StringField](#string-field)): The vehicle's maximum authorized weight with coupling. - -```js -console.log(result.document.inference.prediction.f3.value); -``` - -## Formula Number -**formulaNumber** ([StringField](#string-field)): The document's formula number. - -```js -console.log(result.document.inference.prediction.formulaNumber.value); -``` - -## g -**g** ([StringField](#string-field)): The vehicle's weight with coupling if tractor different than category M1. - -```js -console.log(result.document.inference.prediction.g.value); -``` - -## g1 -**g1** ([StringField](#string-field)): The vehicle's national empty weight. - -```js -console.log(result.document.inference.prediction.g1.value); -``` - -## i -**i** ([DateField](#date-field)): The car registration date of the given certificate. - -```js -console.log(result.document.inference.prediction.i.value); -``` - -## j -**j** ([StringField](#string-field)): The vehicle's category. - -```js -console.log(result.document.inference.prediction.j.value); -``` - -## j1 -**j1** ([StringField](#string-field)): The vehicle's national type. - -```js -console.log(result.document.inference.prediction.j1.value); -``` - -## j2 -**j2** ([StringField](#string-field)): The vehicle's body type (CE). - -```js -console.log(result.document.inference.prediction.j2.value); -``` - -## j3 -**j3** ([StringField](#string-field)): The vehicle's body type (National designation). - -```js -console.log(result.document.inference.prediction.j3.value); -``` - -## MRZ Line 1 -**mrz1** ([StringField](#string-field)): Machine Readable Zone, first line. - -```js -console.log(result.document.inference.prediction.mrz1.value); -``` - -## MRZ Line 2 -**mrz2** ([StringField](#string-field)): Machine Readable Zone, second line. - -```js -console.log(result.document.inference.prediction.mrz2.value); -``` - -## Owner's First Name -**ownerFirstName** ([StringField](#string-field)): The vehicle's owner first name. - -```js -console.log(result.document.inference.prediction.ownerFirstName.value); -``` - -## Owner's Surname -**ownerSurname** ([StringField](#string-field)): The vehicle's owner surname. - -```js -console.log(result.document.inference.prediction.ownerSurname.value); -``` - -## p1 -**p1** ([StringField](#string-field)): The vehicle engine's displacement (cm3). - -```js -console.log(result.document.inference.prediction.p1.value); -``` - -## p2 -**p2** ([StringField](#string-field)): The vehicle's maximum net power (kW). - -```js -console.log(result.document.inference.prediction.p2.value); -``` - -## p3 -**p3** ([StringField](#string-field)): The vehicle's fuel type or energy source. - -```js -console.log(result.document.inference.prediction.p3.value); -``` - -## p6 -**p6** ([StringField](#string-field)): The vehicle's administrative power (fiscal horsepower). - -```js -console.log(result.document.inference.prediction.p6.value); -``` - -## q -**q** ([StringField](#string-field)): The vehicle's power to weight ratio. - -```js -console.log(result.document.inference.prediction.q.value); -``` - -## s1 -**s1** ([StringField](#string-field)): The vehicle's number of seats. - -```js -console.log(result.document.inference.prediction.s1.value); -``` - -## s2 -**s2** ([StringField](#string-field)): The vehicle's number of standing rooms (person). - -```js -console.log(result.document.inference.prediction.s2.value); -``` - -## u1 -**u1** ([StringField](#string-field)): The vehicle's sound level (dB). - -```js -console.log(result.document.inference.prediction.u1.value); -``` - -## u2 -**u2** ([StringField](#string-field)): The vehicle engine's rotation speed (RPM). - -```js -console.log(result.document.inference.prediction.u2.value); -``` - -## v7 -**v7** ([StringField](#string-field)): The vehicle's CO2 emission (g/km). - -```js -console.log(result.document.inference.prediction.v7.value); -``` - -## x1 -**x1** ([StringField](#string-field)): Next technical control date. - -```js -console.log(result.document.inference.prediction.x1.value); -``` - -## y1 -**y1** ([StringField](#string-field)): Amount of the regional proportional tax of the registration (in euros). - -```js -console.log(result.document.inference.prediction.y1.value); -``` - -## y2 -**y2** ([StringField](#string-field)): Amount of the additional parafiscal tax of the registration (in euros). - -```js -console.log(result.document.inference.prediction.y2.value); -``` - -## y3 -**y3** ([StringField](#string-field)): Amount of the additional CO2 tax of the registration (in euros). - -```js -console.log(result.document.inference.prediction.y3.value); -``` - -## y4 -**y4** ([StringField](#string-field)): Amount of the fee for managing the registration (in euros). - -```js -console.log(result.document.inference.prediction.y4.value); -``` - -## y5 -**y5** ([StringField](#string-field)): Amount of the fee for delivery of the registration certificate in euros. - -```js -console.log(result.document.inference.prediction.y5.value); -``` - -## y6 -**y6** ([StringField](#string-field)): Total amount of registration fee to be paid in euros. - -```js -console.log(result.document.inference.prediction.y6.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/cropper_v1.md b/docs/cropper_v1.md deleted file mode 100644 index f70fcded2..000000000 --- a/docs/cropper_v1.md +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: Cropper OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-cropper-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Cropper API](https://platform.mindee.com/mindee/cropper). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/cropper/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Cropper sample](https://github.com/mindee/client-lib-test-data/blob/main/products/cropper/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.CropperV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 149ce775-8302-4798-8649-7eda9fb84a1a -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/cropper v1.0 -:Rotation applied: No - -Prediction -========== - -Page Predictions -================ - -Page 0 ------- -:Document Cropper: Polygon with 26 points. - Polygon with 25 points. -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### Position Field -The position field `PositionField` does not implement all the basic `Field` attributes, only **boundingBox**, **polygon** and **pageId**. On top of these, it has access to: - -* **rectangle** (`[Point, Point, Point, Point]`): a Polygon with four points that may be oriented (even beyond canvas). -* **quadrangle** (`[Point, Point, Point, Point]`): a free polygon made up of four points. - -## Page-Level Fields -Some fields are constrained to the page level, and so will not be retrievable at document level. - -# Attributes -The following fields are extracted for Cropper V1: - -## Document Cropper -[๐Ÿ“„](#page-level-fields "This field is only present on individual pages.")**cropping** ([PositionField](#position-field)[]): List of documents found in the image. - -```js -for (const page of result.document.inference.pages) { - for (const croppingElem of page.prediction.cropping) { - console.log(croppingElem.polygon); - console.log(croppingElem.quadrangle); - console.log(croppingElem.rectangle); - console.log(croppingElem.boundingBox); - } -} -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/custom_v1.md b/docs/custom_v1.md deleted file mode 100644 index 4dcb83ade..000000000 --- a/docs/custom_v1.md +++ /dev/null @@ -1,159 +0,0 @@ ---- -title: Custom API Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-api-builder -parentDoc: 609809574212d40077a040f1 ---- -> ๐Ÿšง This product is still supported, but is considered to be deprecated. If you are looking for the docTI API documentation, you can find it [here](https://developers.mindee.com/docs/nodejs-generated-ocr). - - -# Quick-Start - -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ - apiKey: "my-api-key" -}); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Create a custom endpoint for your product -const customEndpoint = mindeeClient.createEndpoint( - "my-endpoint", - "my-account", - // "my-version" // Optional: set the version, defaults to "1" -); - -// Parse it -const apiResponse = mindeeClient - .parse( - mindee.product.CustomV1, - inputSource, - { - endpoint: customEndpoint, - cropper: true - } - ); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -# Custom Endpoints - -You may have noticed in the previous step that in order to access a custom build, you will need to provide an account and an endpoint name at the very least. - -Although it is optional, the version number should match the latest version of your build in most use-cases. -If it is not set, it will default to "1". - - -# Field Types - -## Custom Fields - -### List Field - -A `ListField` is a special type of custom list that implements the following: - -* **confidence** (`number`): the confidence score of the field prediction. -* **reconstructed** (`boolean`): indicates whether or not an object was reconstructed (not extracted as the API gave it). -* **values** (`Array<`[ListFieldValue](#list-field-value)`>`): list of value fields - -Since the inner contents can vary, the value isn't accessed through a property, but rather through the following functions: -* **contentsList()** (`Array`): returns a list of values for each element. -* **contentsString(separator=" ")** (`string`): returns a list of concatenated values, with an optional **separator** `string` between them. -* **toString()**: returns a string representation of all values, with an empty space between each of them. - -#### List Field Value - -Values of `ListField`s are stored in a `ListFieldValue` structure, which is implemented as follows: -* **content** (`string`): extracted content of the prediction -* **confidence** (`number`): the confidence score of the prediction -* **bbox** (`BBox`): 4 relative vertices corrdinates of a rectangle containing the word in the document. -* **polygon** (`Polygon`): vertices of a polygon containing the word. -* **pageId** (`number`): the ID of the page, is `undefined` when at document-level. - -### Classification Field - -A `ClassificationField` is a special type of custom classification that implements the following: - -* **value** (`string`): the value of the classification. Corresponds to one of the values specified during training. -* **confidence** (`number`): the confidence score of the field prediction. -* **toString()**: returns a string representation of all values, with an empty space between each of them. - -# Attributes - -Custom builds always have access to at least two attributes: - -## Fields - -**fields** ({`string`: [ListField](#list-field)}): - -```js -console.log(result.document.inference.prediction.fields["my-field"].toString()); -``` - -## Classifications - -**classifications** ({`string`: [ClassificationField](#classification-field)}): The purchase category among predefined classes. - -```js -console.log(result.document.inference.prediction.classifications["my-classification"].toString()); -``` - -# ๐Ÿงช Custom Line Items - -> **โš ๏ธ Warning**: Custom Line Items are an **experimental** feature, results may vary. - - -Though not supported directly in the API, sometimes you might need to reconstitute line items by hand. -The library provides a tool for this very purpose: - -## columnsToLineItems() -The **columnsToLineItems()** function can be called from the document and page level prediction objects. - -It takes the following arguments: - -* **anchorNames** (`string[]`): a list of the names of possible anchor (field) candidate for the horizontal placement a line. If all provided anchors are invalid, the `LineItem` won't be built. -* **fieldNamesTargeted** (`string[]`): a list of fields to retrieve the values from -* **heightLineTolerance** (`number`): Optional, the height tolerance used to build the line. It helps when the height of a line can vary unexpectedly. - -Example use: - -```js -// document-level -response.document.inference.prediction.columnsToLineItems( - anchorNames, - fieldNamesToLineItems, - 0.011 // optional, defaults to 0.01 -); - -// page-level -response.document.pages[0].prediction.columnsToLineItems( - anchorNames, - fieldNamesToLineItems, - 0.011 // optional, defaults to 0.01 -); -``` - -It returns a list of [CustomLine](#Customline) objects. - -## Customline - -`Customline` represents a line as it has been read from column fields. It has the following attributes: - -* **rowNumber** (`number`): Number of a given line. Starts at 1. -* **fields** (`Map`[]): List of the fields associated with the line, indexed by their column name. -* **bbox** (`BBox`): Simple bounding box of the current line representing the 4 corners as `number` values. - -# Questions? - -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/delivery_notes_v1.md b/docs/delivery_notes_v1.md deleted file mode 100644 index fd904a532..000000000 --- a/docs/delivery_notes_v1.md +++ /dev/null @@ -1,146 +0,0 @@ ---- -title: Delivery note OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-delivery-note-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Delivery note API](https://platform.mindee.com/mindee/delivery_notes). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/delivery_notes/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Delivery note sample](https://github.com/mindee/client-lib-test-data/blob/main/products/delivery_notes/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.DeliveryNoteV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: d5ead821-edec-4d31-a69a-cf3998d9a506 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/delivery_notes v1.0 -:Rotation applied: Yes - -Prediction -========== -:Delivery Date: 2019-10-02 -:Delivery Number: INT-001 -:Supplier Name: John Smith -:Supplier Address: 4490 Oak Drive, Albany, NY 12210 -:Customer Name: Jessie M Horne -:Customer Address: 4312 Wood Road, New York, NY 10031 -:Total Amount: 204.75 -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### Amount Field -The amount field `AmountField` only has one constraint: its **value** is a `number` (or `undefined`). - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -# Attributes -The following fields are extracted for Delivery note V1: - -## Customer Address -**customerAddress** ([StringField](#string-field)): The address of the customer receiving the goods. - -```js -console.log(result.document.inference.prediction.customerAddress.value); -``` - -## Customer Name -**customerName** ([StringField](#string-field)): The name of the customer receiving the goods. - -```js -console.log(result.document.inference.prediction.customerName.value); -``` - -## Delivery Date -**deliveryDate** ([DateField](#date-field)): The date on which the delivery is scheduled to arrive. - -```js -console.log(result.document.inference.prediction.deliveryDate.value); -``` - -## Delivery Number -**deliveryNumber** ([StringField](#string-field)): A unique identifier for the delivery note. - -```js -console.log(result.document.inference.prediction.deliveryNumber.value); -``` - -## Supplier Address -**supplierAddress** ([StringField](#string-field)): The address of the supplier providing the goods. - -```js -console.log(result.document.inference.prediction.supplierAddress.value); -``` - -## Supplier Name -**supplierName** ([StringField](#string-field)): The name of the supplier providing the goods. - -```js -console.log(result.document.inference.prediction.supplierName.value); -``` - -## Total Amount -**totalAmount** ([AmountField](#amount-field)): The total monetary value of the goods being delivered. - -```js -console.log(result.document.inference.prediction.totalAmount.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/driver_license_v1.md b/docs/driver_license_v1.md deleted file mode 100644 index ebcd44766..000000000 --- a/docs/driver_license_v1.md +++ /dev/null @@ -1,190 +0,0 @@ ---- -title: Driver License OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-driver-license-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Driver License API](https://platform.mindee.com/mindee/driver_license). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Driver License sample](https://github.com/mindee/client-lib-test-data/blob/main/products/driver_license/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.DriverLicenseV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: fbdeae38-ada3-43ac-aa58-e01a3d47e474 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/driver_license v1.0 -:Rotation applied: Yes - -Prediction -========== -:Country Code: USA -:State: AZ -:ID: D12345678 -:Category: D -:Last Name: Sample -:First Name: Jelani -:Date of Birth: 1957-02-01 -:Place of Birth: -:Expiry Date: 2018-02-01 -:Issued Date: 2013-01-10 -:Issuing Authority: -:MRZ: -:DD Number: DD1234567890123456 -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -# Attributes -The following fields are extracted for Driver License V1: - -## Category -**category** ([StringField](#string-field)): The category or class of the driver license. - -```js -console.log(result.document.inference.prediction.category.value); -``` - -## Country Code -**countryCode** ([StringField](#string-field)): The alpha-3 ISO 3166 code of the country where the driver license was issued. - -```js -console.log(result.document.inference.prediction.countryCode.value); -``` - -## Date of Birth -**dateOfBirth** ([DateField](#date-field)): The date of birth of the driver license holder. - -```js -console.log(result.document.inference.prediction.dateOfBirth.value); -``` - -## DD Number -**ddNumber** ([StringField](#string-field)): The DD number of the driver license. - -```js -console.log(result.document.inference.prediction.ddNumber.value); -``` - -## Expiry Date -**expiryDate** ([DateField](#date-field)): The expiry date of the driver license. - -```js -console.log(result.document.inference.prediction.expiryDate.value); -``` - -## First Name -**firstName** ([StringField](#string-field)): The first name of the driver license holder. - -```js -console.log(result.document.inference.prediction.firstName.value); -``` - -## ID -**id** ([StringField](#string-field)): The unique identifier of the driver license. - -```js -console.log(result.document.inference.prediction.id.value); -``` - -## Issued Date -**issuedDate** ([DateField](#date-field)): The date when the driver license was issued. - -```js -console.log(result.document.inference.prediction.issuedDate.value); -``` - -## Issuing Authority -**issuingAuthority** ([StringField](#string-field)): The authority that issued the driver license. - -```js -console.log(result.document.inference.prediction.issuingAuthority.value); -``` - -## Last Name -**lastName** ([StringField](#string-field)): The last name of the driver license holder. - -```js -console.log(result.document.inference.prediction.lastName.value); -``` - -## MRZ -**mrz** ([StringField](#string-field)): The Machine Readable Zone (MRZ) of the driver license. - -```js -console.log(result.document.inference.prediction.mrz.value); -``` - -## Place of Birth -**placeOfBirth** ([StringField](#string-field)): The place of birth of the driver license holder. - -```js -console.log(result.document.inference.prediction.placeOfBirth.value); -``` - -## State -**state** ([StringField](#string-field)): Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. - -```js -console.log(result.document.inference.prediction.state.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/energy_bill_fra_v1.md b/docs/energy_bill_fra_v1.md deleted file mode 100644 index 675b537c8..000000000 --- a/docs/energy_bill_fra_v1.md +++ /dev/null @@ -1,320 +0,0 @@ ---- -title: FR Energy Bill OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-fr-energy-bill-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Energy Bill API](https://platform.mindee.com/mindee/energy_bill_fra). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/energy_bill_fra/default_sample.pdf), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Energy Bill sample](https://github.com/mindee/client-lib-test-data/blob/main/products/energy_bill_fra/default_sample.pdf?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.fr.EnergyBillV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: ff1f2ca8-4d29-44d8-a564-599a982a4ef7 -:Filename: default_sample.pdf - -Inference -######### -:Product: mindee/energy_bill_fra v1.2 -:Rotation applied: Yes - -Prediction -========== -:Invoice Number: 1234567890 -:Contract ID: 9876543210 -:Delivery Point: 98765432109876 -:Invoice Date: 2021-01-29 -:Due Date: 2021-02-15 -:Total Before Taxes: 1241.03 -:Total Taxes: 238.82 -:Total Amount: 1479.85 -:Energy Supplier: - :Address: TSA 12345, 12345 DEMOCITY CEDEX - :Name: EDF -:Energy Consumer: - :Address: 123 RUE DE L'IMAGINAIRE, 75001 PARIS - :Name: JOHN DOE -:Subscription: - +--------------------------------------+------------+------------+----------+-----------+------------+ - | Description | End Date | Start Date | Tax Rate | Total | Unit Price | - +======================================+============+============+==========+===========+============+ - | Abonnement รฉlectricitรฉ | 2021-02-28 | 2021-01-01 | 5.50 | 59.00 | 29.50 | - +--------------------------------------+------------+------------+----------+-----------+------------+ -:Energy Usage: - +-------------+--------------------------------------+------------+------------+----------+-----------+-----------------+------------+ - | Consumption | Description | End Date | Start Date | Tax Rate | Total | Unit of Measure | Unit Price | - +=============+======================================+============+============+==========+===========+=================+============+ - | 8581.00 | Consommation รฉlectricitรฉ | 2021-01-27 | 2020-11-28 | 20.00 | 898.43 | kWh | 0.1047 | - +-------------+--------------------------------------+------------+------------+----------+-----------+-----------------+------------+ -:Taxes and Contributions: - +--------------------------------------+------------+------------+----------+-----------+------------+ - | Description | End Date | Start Date | Tax Rate | Total | Unit Price | - +======================================+============+============+==========+===========+============+ - | Contribution au Service Public de... | 2021-01-27 | 2020-11-28 | 20.00 | 193.07 | 0.0225 | - +--------------------------------------+------------+------------+----------+-----------+------------+ - | Taxe Dรฉpartementale sur la Conso ... | 2021-01-27 | 2020-11-28 | 20.00 | 13.98 | 0.003315 | - +--------------------------------------+------------+------------+----------+-----------+------------+ - | Taxe Communale sur la Conso Final... | 2021-01-27 | 2020-11-28 | 20.00 | 28.56 | 0.006545 | - +--------------------------------------+------------+------------+----------+-----------+------------+ - | Taxe Communale sur la Conso Final... | 2021-01-27 | 2020-11-28 | 20.00 | 27.96 | 0.00663 | - +--------------------------------------+------------+------------+----------+-----------+------------+ -:Meter Details: - :Meter Number: 620 - :Meter Type: electricity - :Unit of Power: 36kVA -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### Amount Field -The amount field `AmountField` only has one constraint: its **value** is a `number` (or `undefined`). - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Energy Consumer Field -The entity that consumes the energy. - -A `EnergyBillV1EnergyConsumer` implements the following attributes: - -* `address` (string): The address of the energy consumer. -* `name` (string): The name of the energy consumer. -Fields which are specific to this product; they are not used in any other product. - -### Energy Supplier Field -The company that supplies the energy. - -A `EnergyBillV1EnergySupplier` implements the following attributes: - -* `address` (string): The address of the energy supplier. -* `name` (string): The name of the energy supplier. -Fields which are specific to this product; they are not used in any other product. - -### Energy Usage Field -Details of energy consumption. - -A `EnergyBillV1EnergyUsage` implements the following attributes: - -* `consumption` (number): The price per unit of energy consumed. -* `description` (string): Description or details of the energy usage. -* `endDate` (string): The end date of the energy usage. -* `startDate` (string): The start date of the energy usage. -* `taxRate` (number): The rate of tax applied to the total cost. -* `total` (number): The total cost of energy consumed. -* `unit` (string): The unit of measurement for energy consumption. - -#### Possible values include: - - kWh - - m3 - - L - -* `unitPrice` (number): The price per unit of energy consumed. -Fields which are specific to this product; they are not used in any other product. - -### Meter Details Field -Information about the energy meter. - -A `EnergyBillV1MeterDetail` implements the following attributes: - -* `meterNumber` (string): The unique identifier of the energy meter. -* `meterType` (string): The type of energy meter. - -#### Possible values include: - - electricity - - gas - - water - - `null` - -* `unit` (string): The unit of power for energy consumption. -Fields which are specific to this product; they are not used in any other product. - -### Subscription Field -The subscription details fee for the energy service. - -A `EnergyBillV1Subscription` implements the following attributes: - -* `description` (string): Description or details of the subscription. -* `endDate` (string): The end date of the subscription. -* `startDate` (string): The start date of the subscription. -* `taxRate` (number): The rate of tax applied to the total cost. -* `total` (number): The total cost of subscription. -* `unitPrice` (number): The price per unit of subscription. -Fields which are specific to this product; they are not used in any other product. - -### Taxes and Contributions Field -Details of Taxes and Contributions. - -A `EnergyBillV1TaxesAndContribution` implements the following attributes: - -* `description` (string): Description or details of the Taxes and Contributions. -* `endDate` (string): The end date of the Taxes and Contributions. -* `startDate` (string): The start date of the Taxes and Contributions. -* `taxRate` (number): The rate of tax applied to the total cost. -* `total` (number): The total cost of Taxes and Contributions. -* `unitPrice` (number): The price per unit of Taxes and Contributions. - -# Attributes -The following fields are extracted for Energy Bill V1: - -## Contract ID -**contractId** ([StringField](#string-field)): The unique identifier associated with a specific contract. - -```js -console.log(result.document.inference.prediction.contractId.value); -``` - -## Delivery Point -**deliveryPoint** ([StringField](#string-field)): The unique identifier assigned to each electricity or gas consumption point. It specifies the exact location where the energy is delivered. - -```js -console.log(result.document.inference.prediction.deliveryPoint.value); -``` - -## Due Date -**dueDate** ([DateField](#date-field)): The date by which the payment for the energy invoice is due. - -```js -console.log(result.document.inference.prediction.dueDate.value); -``` - -## Energy Consumer -**energyConsumer** ([EnergyBillV1EnergyConsumer](#energy-consumer-field)): The entity that consumes the energy. - -```js -console.log(result.document.inference.prediction.energyConsumer.value); -``` - -## Energy Supplier -**energySupplier** ([EnergyBillV1EnergySupplier](#energy-supplier-field)): The company that supplies the energy. - -```js -console.log(result.document.inference.prediction.energySupplier.value); -``` - -## Energy Usage -**energyUsage** ([EnergyBillV1EnergyUsage](#energy-usage-field)[]): Details of energy consumption. - -```js -for (const energyUsageElem of result.document.inference.prediction.energyUsage) { - console.log(energyUsageElem.value); -} -``` - -## Invoice Date -**invoiceDate** ([DateField](#date-field)): The date when the energy invoice was issued. - -```js -console.log(result.document.inference.prediction.invoiceDate.value); -``` - -## Invoice Number -**invoiceNumber** ([StringField](#string-field)): The unique identifier of the energy invoice. - -```js -console.log(result.document.inference.prediction.invoiceNumber.value); -``` - -## Meter Details -**meterDetails** ([EnergyBillV1MeterDetail](#meter-details-field)): Information about the energy meter. - -```js -console.log(result.document.inference.prediction.meterDetails.value); -``` - -## Subscription -**subscription** ([EnergyBillV1Subscription](#subscription-field)[]): The subscription details fee for the energy service. - -```js -for (const subscriptionElem of result.document.inference.prediction.subscription) { - console.log(subscriptionElem.value); -} -``` - -## Taxes and Contributions -**taxesAndContributions** ([EnergyBillV1TaxesAndContribution](#taxes-and-contributions-field)[]): Details of Taxes and Contributions. - -```js -for (const taxesAndContributionsElem of result.document.inference.prediction.taxesAndContributions) { - console.log(taxesAndContributionsElem.value); -} -``` - -## Total Amount -**totalAmount** ([AmountField](#amount-field)): The total amount to be paid for the energy invoice. - -```js -console.log(result.document.inference.prediction.totalAmount.value); -``` - -## Total Before Taxes -**totalBeforeTaxes** ([AmountField](#amount-field)): The total amount to be paid for the energy invoice before taxes. - -```js -console.log(result.document.inference.prediction.totalBeforeTaxes.value); -``` - -## Total Taxes -**totalTaxes** ([AmountField](#amount-field)): Total of taxes applied to the invoice. - -```js -console.log(result.document.inference.prediction.totalTaxes.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/expense_receipts_v5.md b/docs/expense_receipts_v5.md deleted file mode 100644 index 71fcc18ab..000000000 --- a/docs/expense_receipts_v5.md +++ /dev/null @@ -1,383 +0,0 @@ ---- -title: Receipt OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-receipt-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Receipt API](https://platform.mindee.com/mindee/expense_receipts). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/expense_receipts/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Receipt sample](https://github.com/mindee/client-lib-test-data/blob/main/products/expense_receipts/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.ReceiptV5, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -You can also call this product asynchronously: - -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.ReceiptV5, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: d96fb043-8fb8-4adc-820c-387aae83376d -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/expense_receipts v5.3 -:Rotation applied: Yes - -Prediction -========== -:Expense Locale: en-GB; en; GB; GBP; -:Purchase Category: food -:Purchase Subcategory: restaurant -:Document Type: EXPENSE RECEIPT -:Purchase Date: 2016-02-26 -:Purchase Time: 15:20 -:Total Amount: 10.20 -:Total Net: 8.50 -:Total Tax: 1.70 -:Tip and Gratuity: -:Taxes: - +---------------+--------+----------+---------------+ - | Base | Code | Rate (%) | Amount | - +===============+========+==========+===============+ - | 8.50 | VAT | 20.00 | 1.70 | - +---------------+--------+----------+---------------+ -:Supplier Name: Clachan -:Supplier Company Registrations: Type: VAT NUMBER, Value: 232153895 - Type: VAT NUMBER, Value: 232153895 -:Supplier Address: 34 Kingley Street W1B 50H -:Supplier Phone Number: 02074940834 -:Receipt Number: 54/7500 -:Line Items: - +--------------------------------------+----------+--------------+------------+ - | Description | Quantity | Total Amount | Unit Price | - +======================================+==========+==============+============+ - | Meantime Pale | 2.00 | 10.20 | | - +--------------------------------------+----------+--------------+------------+ - -Page Predictions -================ - -Page 0 ------- -:Expense Locale: en-GB; en; GB; GBP; -:Purchase Category: food -:Purchase Subcategory: restaurant -:Document Type: EXPENSE RECEIPT -:Purchase Date: 2016-02-26 -:Purchase Time: 15:20 -:Total Amount: 10.20 -:Total Net: 8.50 -:Total Tax: 1.70 -:Tip and Gratuity: -:Taxes: - +---------------+--------+----------+---------------+ - | Base | Code | Rate (%) | Amount | - +===============+========+==========+===============+ - | 8.50 | VAT | 20.00 | 1.70 | - +---------------+--------+----------+---------------+ -:Supplier Name: Clachan -:Supplier Company Registrations: Type: VAT NUMBER, Value: 232153895 - Type: VAT NUMBER, Value: 232153895 -:Supplier Address: 34 Kingley Street W1B 50H -:Supplier Phone Number: 02074940834 -:Receipt Number: 54/7500 -:Line Items: - +--------------------------------------+----------+--------------+------------+ - | Description | Quantity | Total Amount | Unit Price | - +======================================+==========+==============+============+ - | Meantime Pale | 2.00 | 10.20 | | - +--------------------------------------+----------+--------------+------------+ -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### Amount Field -The amount field `AmountField` only has one constraint: its **value** is a `number` (or `undefined`). - - -### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **pageId**. - -> Note: a classification field's `value is always a `string`. - - -### Company Registration Field -Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the following: - -* **type** (`string`): the type of company. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### Locale Field -The locale field `LocaleField` only implements the **value**, **confidence** and **pageId** base `Field` attributes, but it comes with its own: - -* **language** (`string`): ISO 639-1 language code (e.g.: `en` for English). Can be `undefined`. -* **country** (`string`): ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3 code for countries (e.g.: `GRB` or `GB` for "Great Britain"). Can be `undefined`. -* **currency** (`string`): ISO 4217 code for currencies (e.g.: `USD` for "US Dollars"). Can be `undefined`. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -### Taxes Field -#### Tax -Aside from the basic `Field` attributes, the tax field `TaxField` also implements the following: - -* **rate** (`number`): the tax rate applied to an item can be expressed as a percentage. Can be `undefined`. -* **code** (`string`): tax code (or equivalent, depending on the origin of the document). Can be `undefined`. -* **base** (`number`): base amount used for the tax. Can be `undefined`. -* **value** (`number`): the value of the tax. Can be `null`. - -> Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like structure. - -#### Taxes (Array) -The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several objects, it has access to a custom `toString()` method that can render a `TaxField` object as a table line. - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Line Items Field -List of all line items on the receipt. - -A `ReceiptV5LineItem` implements the following attributes: - -* `description` (string): The item description. -* `quantity` (number): The item quantity. -* `totalAmount` (number): The item total amount. -* `unitPrice` (number): The item unit price. - -# Attributes -The following fields are extracted for Receipt V5: - -## Purchase Category -**category** ([ClassificationField](#classification-field)): The purchase category of the receipt. - -#### Possible values include: - - 'toll' - - 'food' - - 'parking' - - 'transport' - - 'accommodation' - - 'gasoline' - - 'telecom' - - 'miscellaneous' - - 'software' - - 'shopping' - - 'energy' - -```js -console.log(result.document.inference.prediction.category.value); -``` - -## Purchase Date -**date** ([DateField](#date-field)): The date the purchase was made. - -```js -console.log(result.document.inference.prediction.date.value); -``` - -## Document Type -**documentType** ([ClassificationField](#classification-field)): The type of receipt: EXPENSE RECEIPT or CREDIT CARD RECEIPT. - -#### Possible values include: - - 'EXPENSE RECEIPT' - - 'CREDIT CARD RECEIPT' - -```js -console.log(result.document.inference.prediction.documentType.value); -``` - -## Line Items -**lineItems** ([ReceiptV5LineItem](#line-items-field)[]): List of all line items on the receipt. - -```js -for (const lineItemsElem of result.document.inference.prediction.lineItems) { - console.log(lineItemsElem.value); -} -``` - -## Expense Locale -**locale** ([LocaleField](#locale-field)): The locale of the document. - -```js -console.log(result.document.inference.prediction.locale.value); -``` - -## Receipt Number -**receiptNumber** ([StringField](#string-field)): The receipt number or identifier. - -```js -console.log(result.document.inference.prediction.receiptNumber.value); -``` - -## Purchase Subcategory -**subcategory** ([ClassificationField](#classification-field)): The purchase subcategory of the receipt for transport and food. - -#### Possible values include: - - 'plane' - - 'taxi' - - 'train' - - 'restaurant' - - 'shopping' - - 'other' - - 'groceries' - - 'cultural' - - 'electronics' - - 'office_supplies' - - 'micromobility' - - 'car_rental' - - 'public' - - 'delivery' - - null - -```js -console.log(result.document.inference.prediction.subcategory.value); -``` - -## Supplier Address -**supplierAddress** ([StringField](#string-field)): The address of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierAddress.value); -``` - -## Supplier Company Registrations -**supplierCompanyRegistrations** ([CompanyRegistrationField](#company-registration-field)[]): List of company registration numbers associated to the supplier. - -```js -for (const supplierCompanyRegistrationsElem of result.document.inference.prediction.supplierCompanyRegistrations) { - console.log(supplierCompanyRegistrationsElem.value); -} -``` - -## Supplier Name -**supplierName** ([StringField](#string-field)): The name of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierName.value); -``` - -## Supplier Phone Number -**supplierPhoneNumber** ([StringField](#string-field)): The phone number of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierPhoneNumber.value); -``` - -## Taxes -**taxes** ([TaxField](#taxes-field)[]): The list of taxes present on the receipt. - -```js -for (const taxesElem of result.document.inference.prediction.taxes) { - console.log(taxesElem.value); -} -``` - -## Purchase Time -**time** ([StringField](#string-field)): The time the purchase was made. - -```js -console.log(result.document.inference.prediction.time.value); -``` - -## Tip and Gratuity -**tip** ([AmountField](#amount-field)): The total amount of tip and gratuity. - -```js -console.log(result.document.inference.prediction.tip.value); -``` - -## Total Amount -**totalAmount** ([AmountField](#amount-field)): The total amount paid: includes taxes, discounts, fees, tips, and gratuity. - -```js -console.log(result.document.inference.prediction.totalAmount.value); -``` - -## Total Net -**totalNet** ([AmountField](#amount-field)): The net amount paid: does not include taxes, fees, and discounts. - -```js -console.log(result.document.inference.prediction.totalNet.value); -``` - -## Total Tax -**totalTax** ([AmountField](#amount-field)): The sum of all taxes. - -```js -console.log(result.document.inference.prediction.totalTax.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/financial_document_v1.md b/docs/financial_document_v1.md deleted file mode 100644 index c3549303c..000000000 --- a/docs/financial_document_v1.md +++ /dev/null @@ -1,582 +0,0 @@ ---- -title: Financial Document OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-financial-document-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Financial Document API](https://platform.mindee.com/mindee/financial_document). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/financial_document/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Financial Document sample](https://github.com/mindee/client-lib-test-data/blob/main/products/financial_document/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.FinancialDocumentV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -You can also call this product asynchronously: - -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.FinancialDocumentV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 6dd26385-719b-4527-bf6f-87d9da619de5 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/financial_document v1.14 -:Rotation applied: Yes - -Prediction -========== -:Locale: en-US; en; US; USD; -:Invoice Number: INT-001 -:Purchase Order Number: 2412/2019 -:Receipt Number: -:Document Number: INT-001 -:Reference Numbers: 2412/2019 -:Purchase Date: 2019-11-02 -:Due Date: 2019-11-17 -:Payment Date: 2019-11-17 -:Total Net: 195.00 -:Total Amount: 204.75 -:Taxes: - +---------------+--------+----------+---------------+ - | Base | Code | Rate (%) | Amount | - +===============+========+==========+===============+ - | 195.00 | | 5.00 | 9.75 | - +---------------+--------+----------+---------------+ -:Supplier Payment Details: -:Supplier Name: JOHN SMITH -:Supplier Company Registrations: -:Supplier Address: 4490 Oak Drive Albany, NY 12210 -:Supplier Phone Number: -:Customer Name: JESSIE M HORNE -:Supplier Website: -:Supplier Email: -:Customer Company Registrations: -:Customer Address: 2019 Redbud Drive New York, NY 10011 -:Customer ID: 1234567890 -:Shipping Address: 2019 Redbud Drive New York, NY 10011 -:Billing Address: 4312 Wood Road New York, NY 10031 -:Document Type: INVOICE -:Document Type Extended: INVOICE -:Purchase Subcategory: -:Purchase Category: miscellaneous -:Total Tax: 9.75 -:Tip and Gratuity: -:Purchase Time: -:Line Items: - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | Description | Product code | Quantity | Tax Amount | Tax Rate (%) | Total Amount | Unit of measure | Unit Price | - +======================================+==============+==========+============+==============+==============+=================+============+ - | Front and rear brake cables | | 1.00 | | | 100.00 | | 100.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | New set of pedal arms | | 2.00 | | | 50.00 | | 25.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | Labor 3hrs | | 3.00 | | | 45.00 | | 15.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - -Page Predictions -================ - -Page 0 ------- -:Locale: en-US; en; US; USD; -:Invoice Number: INT-001 -:Purchase Order Number: 2412/2019 -:Receipt Number: -:Document Number: INT-001 -:Reference Numbers: 2412/2019 -:Purchase Date: 2019-11-02 -:Due Date: 2019-11-17 -:Payment Date: 2019-11-17 -:Total Net: 195.00 -:Total Amount: 204.75 -:Taxes: - +---------------+--------+----------+---------------+ - | Base | Code | Rate (%) | Amount | - +===============+========+==========+===============+ - | 195.00 | | 5.00 | 9.75 | - +---------------+--------+----------+---------------+ -:Supplier Payment Details: -:Supplier Name: JOHN SMITH -:Supplier Company Registrations: -:Supplier Address: 4490 Oak Drive Albany, NY 12210 -:Supplier Phone Number: -:Customer Name: JESSIE M HORNE -:Supplier Website: -:Supplier Email: -:Customer Company Registrations: -:Customer Address: 2019 Redbud Drive New York, NY 10011 -:Customer ID: 1234567890 -:Shipping Address: 2019 Redbud Drive New York, NY 10011 -:Billing Address: 4312 Wood Road New York, NY 10031 -:Document Type: INVOICE -:Document Type Extended: INVOICE -:Purchase Subcategory: -:Purchase Category: miscellaneous -:Total Tax: 9.75 -:Tip and Gratuity: -:Purchase Time: -:Line Items: - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | Description | Product code | Quantity | Tax Amount | Tax Rate (%) | Total Amount | Unit of measure | Unit Price | - +======================================+==============+==========+============+==============+==============+=================+============+ - | Front and rear brake cables | | 1.00 | | | 100.00 | | 100.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | New set of pedal arms | | 2.00 | | | 50.00 | | 25.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | Labor 3hrs | | 3.00 | | | 45.00 | | 15.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### AddressField -Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following: - -* **streetNumber** (`string`): String representation of the street number. Can be `null`. -* **streetName** (`string`): Name of the street. Can be `null`. -* **poBox** (`string`): String representation of the PO Box number. Can be `null`. -* **addressComplement** (`string`): Address complement. Can be `null`. -* **city** (`string`): City name. Can be `null`. -* **postalCode** (`string`): String representation of the postal code. Can be `null`. -* **state** (`string`): State name. Can be `null`. -* **country** (`string`): Country name. Can be `null`. - -Note: The `value` field of an AddressField should be a concatenation of the rest of the values. - - -### Amount Field -The amount field `AmountField` only has one constraint: its **value** is a `number` (or `undefined`). - - -### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **pageId**. - -> Note: a classification field's `value is always a `string`. - - -### Company Registration Field -Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the following: - -* **type** (`string`): the type of company. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### Locale Field -The locale field `LocaleField` only implements the **value**, **confidence** and **pageId** base `Field` attributes, but it comes with its own: - -* **language** (`string`): ISO 639-1 language code (e.g.: `en` for English). Can be `undefined`. -* **country** (`string`): ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3 code for countries (e.g.: `GRB` or `GB` for "Great Britain"). Can be `undefined`. -* **currency** (`string`): ISO 4217 code for currencies (e.g.: `USD` for "US Dollars"). Can be `undefined`. - -### Payment Details Field -Aside from the basic `Field` attributes, the payment details field `PaymentDetailsField` also implements the following: - -* **accountNumber** (`string`): number of an account, expressed as a string. Can be `undefined`. -* **iban** (`string`): International Bank Account Number. Can be `undefined`. -* **routingNumber** (`string`): routing number of an account. Can be `undefined`. -* **swift** (`string`): the account holder's bank's SWIFT Business Identifier Code (BIC). Can be `undefined`. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -### Taxes Field -#### Tax -Aside from the basic `Field` attributes, the tax field `TaxField` also implements the following: - -* **rate** (`number`): the tax rate applied to an item can be expressed as a percentage. Can be `undefined`. -* **code** (`string`): tax code (or equivalent, depending on the origin of the document). Can be `undefined`. -* **base** (`number`): base amount used for the tax. Can be `undefined`. -* **value** (`number`): the value of the tax. Can be `null`. - -> Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like structure. - -#### Taxes (Array) -The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several objects, it has access to a custom `toString()` method that can render a `TaxField` object as a table line. - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Line Items Field -List of line item present on the document. - -A `FinancialDocumentV1LineItem` implements the following attributes: - -* `description` (string): The item description. -* `productCode` (string): The product code referring to the item. -* `quantity` (number): The item quantity -* `taxAmount` (number): The item tax amount. -* `taxRate` (number): The item tax rate in percentage. -* `totalAmount` (number): The item total amount. -* `unitMeasure` (string): The item unit of measure. -* `unitPrice` (number): The item unit price. - -# Attributes -The following fields are extracted for Financial Document V1: - -## Billing Address -**billingAddress** : The customer's address used for billing. - -```js -console.log(result.document.inference.prediction.billingAddress.value); -``` - -## Purchase Category -**category** ([ClassificationField](#classification-field)): The purchase category. - -#### Possible values include: - - 'toll' - - 'food' - - 'parking' - - 'transport' - - 'accommodation' - - 'gasoline' - - 'telecom' - - 'miscellaneous' - - 'software' - - 'shopping' - - 'energy' - -```js -console.log(result.document.inference.prediction.category.value); -``` - -## Customer Address -**customerAddress** : The address of the customer. - -```js -console.log(result.document.inference.prediction.customerAddress.value); -``` - -## Customer Company Registrations -**customerCompanyRegistrations** ([CompanyRegistrationField](#company-registration-field)[]): List of company registration numbers associated to the customer. - -```js -for (const customerCompanyRegistrationsElem of result.document.inference.prediction.customerCompanyRegistrations) { - console.log(customerCompanyRegistrationsElem.value); -} -``` - -## Customer ID -**customerId** ([StringField](#string-field)): The customer account number or identifier from the supplier. - -```js -console.log(result.document.inference.prediction.customerId.value); -``` - -## Customer Name -**customerName** ([StringField](#string-field)): The name of the customer. - -```js -console.log(result.document.inference.prediction.customerName.value); -``` - -## Purchase Date -**date** ([DateField](#date-field)): The date the purchase was made. - -```js -console.log(result.document.inference.prediction.date.value); -``` - -## Document Number -**documentNumber** ([StringField](#string-field)): The document number or identifier (invoice number or receipt number). - -```js -console.log(result.document.inference.prediction.documentNumber.value); -``` - -## Document Type -**documentType** ([ClassificationField](#classification-field)): The type of the document: INVOICE or CREDIT NOTE if it is an invoice, CREDIT CARD RECEIPT or EXPENSE RECEIPT if it is a receipt. - -#### Possible values include: - - 'INVOICE' - - 'CREDIT NOTE' - - 'CREDIT CARD RECEIPT' - - 'EXPENSE RECEIPT' - -```js -console.log(result.document.inference.prediction.documentType.value); -``` - -## Document Type Extended -**documentTypeExtended** ([ClassificationField](#classification-field)): Document type extended. - -#### Possible values include: - - 'CREDIT NOTE' - - 'INVOICE' - - 'OTHER' - - 'OTHER_FINANCIAL' - - 'PAYSLIP' - - 'PURCHASE ORDER' - - 'QUOTE' - - 'RECEIPT' - - 'STATEMENT' - -```js -console.log(result.document.inference.prediction.documentTypeExtended.value); -``` - -## Due Date -**dueDate** ([DateField](#date-field)): The date on which the payment is due. - -```js -console.log(result.document.inference.prediction.dueDate.value); -``` - -## Invoice Number -**invoiceNumber** ([StringField](#string-field)): The invoice number or identifier only if document is an invoice. - -```js -console.log(result.document.inference.prediction.invoiceNumber.value); -``` - -## Line Items -**lineItems** ([FinancialDocumentV1LineItem](#line-items-field)[]): List of line item present on the document. - -```js -for (const lineItemsElem of result.document.inference.prediction.lineItems) { - console.log(lineItemsElem.value); -} -``` - -## Locale -**locale** ([LocaleField](#locale-field)): The locale of the document. - -```js -console.log(result.document.inference.prediction.locale.value); -``` - -## Payment Date -**paymentDate** ([DateField](#date-field)): The date on which the payment is due / fullfilled. - -```js -console.log(result.document.inference.prediction.paymentDate.value); -``` - -## Purchase Order Number -**poNumber** ([StringField](#string-field)): The purchase order number, only if the document is an invoice. - -```js -console.log(result.document.inference.prediction.poNumber.value); -``` - -## Receipt Number -**receiptNumber** ([StringField](#string-field)): The receipt number or identifier only if document is a receipt. - -```js -console.log(result.document.inference.prediction.receiptNumber.value); -``` - -## Reference Numbers -**referenceNumbers** ([StringField](#string-field)[]): List of Reference numbers, including PO number, only if the document is an invoice. - -```js -for (const referenceNumbersElem of result.document.inference.prediction.referenceNumbers) { - console.log(referenceNumbersElem.value); -} -``` - -## Shipping Address -**shippingAddress** : The customer's address used for shipping. - -```js -console.log(result.document.inference.prediction.shippingAddress.value); -``` - -## Purchase Subcategory -**subcategory** ([ClassificationField](#classification-field)): The purchase subcategory for transport, food and shooping. - -#### Possible values include: - - 'plane' - - 'taxi' - - 'train' - - 'restaurant' - - 'shopping' - - 'other' - - 'groceries' - - 'cultural' - - 'electronics' - - 'office_supplies' - - 'micromobility' - - 'car_rental' - - 'public' - - 'delivery' - - null - -```js -console.log(result.document.inference.prediction.subcategory.value); -``` - -## Supplier Address -**supplierAddress** : The address of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierAddress.value); -``` - -## Supplier Company Registrations -**supplierCompanyRegistrations** ([CompanyRegistrationField](#company-registration-field)[]): List of company registration numbers associated to the supplier. - -```js -for (const supplierCompanyRegistrationsElem of result.document.inference.prediction.supplierCompanyRegistrations) { - console.log(supplierCompanyRegistrationsElem.value); -} -``` - -## Supplier Email -**supplierEmail** ([StringField](#string-field)): The email of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierEmail.value); -``` - -## Supplier Name -**supplierName** ([StringField](#string-field)): The name of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierName.value); -``` - -## Supplier Payment Details -**supplierPaymentDetails** ([PaymentDetailsField](#payment-details-field)[]): List of payment details associated to the supplier (only for invoices). - -```js -for (const supplierPaymentDetailsElem of result.document.inference.prediction.supplierPaymentDetails) { - console.log(supplierPaymentDetailsElem.value); - console.log(supplierPaymentDetailsElem.rate); - console.log(supplierPaymentDetailsElem.code); - console.log(supplierPaymentDetailsElem.basis); -} -``` - -## Supplier Phone Number -**supplierPhoneNumber** ([StringField](#string-field)): The phone number of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierPhoneNumber.value); -``` - -## Supplier Website -**supplierWebsite** ([StringField](#string-field)): The website URL of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierWebsite.value); -``` - -## Taxes -**taxes** ([TaxField](#taxes-field)[]): List of all taxes on the document. - -```js -for (const taxesElem of result.document.inference.prediction.taxes) { - console.log(taxesElem.value); -} -``` - -## Purchase Time -**time** ([StringField](#string-field)): The time the purchase was made (only for receipts). - -```js -console.log(result.document.inference.prediction.time.value); -``` - -## Tip and Gratuity -**tip** ([AmountField](#amount-field)): The total amount of tip and gratuity - -```js -console.log(result.document.inference.prediction.tip.value); -``` - -## Total Amount -**totalAmount** ([AmountField](#amount-field)): The total amount paid: includes taxes, tips, fees, and other charges. - -```js -console.log(result.document.inference.prediction.totalAmount.value); -``` - -## Total Net -**totalNet** ([AmountField](#amount-field)): The net amount paid: does not include taxes, fees, and discounts. - -```js -console.log(result.document.inference.prediction.totalNet.value); -``` - -## Total Tax -**totalTax** ([AmountField](#amount-field)): The sum of all taxes present on the document. - -```js -console.log(result.document.inference.prediction.totalTax.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/french_healthcard_v1.md b/docs/french_healthcard_v1.md deleted file mode 100644 index 971366e31..000000000 --- a/docs/french_healthcard_v1.md +++ /dev/null @@ -1,120 +0,0 @@ ---- -title: FR Health Card OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-fr-health-card-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Health Card API](https://platform.mindee.com/mindee/french_healthcard). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/french_healthcard/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Health Card sample](https://github.com/mindee/client-lib-test-data/blob/main/products/french_healthcard/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.fr.HealthCardV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 9ee2733d-933a-4dcd-a73a-a31395e3b288 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/french_healthcard v1.0 -:Rotation applied: Yes - -Prediction -========== -:Given Name(s): NATHALIE -:Surname: DURAND -:Social Security Number: 2 69 05 49 588 157 80 -:Issuance Date: 2007-01-01 -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -# Attributes -The following fields are extracted for Health Card V1: - -## Given Name(s) -**givenNames** ([StringField](#string-field)[]): The given names of the card holder. - -```js -for (const givenNamesElem of result.document.inference.prediction.givenNames) { - console.log(givenNamesElem.value); -} -``` - -## Issuance Date -**issuanceDate** ([DateField](#date-field)): The date when the carte vitale document was issued. - -```js -console.log(result.document.inference.prediction.issuanceDate.value); -``` - -## Social Security Number -**socialSecurity** ([StringField](#string-field)): The social security number of the card holder. - -```js -console.log(result.document.inference.prediction.socialSecurity.value); -``` - -## Surname -**surname** ([StringField](#string-field)): The surname of the card holder. - -```js -console.log(result.document.inference.prediction.surname.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/generated_v1.md b/docs/generated_v1.md deleted file mode 100644 index 560fbb7cf..000000000 --- a/docs/generated_v1.md +++ /dev/null @@ -1,100 +0,0 @@ ---- -title: Generated OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-generated-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports generated APIs. -Generated APIs can theoretically support all APIs in a catch-all generic format. - -# Quick-Start - -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Create a custom endpoint for your product -const customEndpoint = mindeeClient.createEndpoint( - "my-endpoint", - "my-account", - "my-version" // Defaults to "1" -); - -// Parse the file asynchronously. -const asyncApiResponse = mindeeClient.enqueueAndParse( - mindee.product.GenneratedV1, - inputSource, - { endpoint: customEndpoint } -); - -// Handle the response Promise -asyncApiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -# Generated Endpoints - -You may have noticed in the previous step that in order to access a custom build, you will need to provide an account and an endpoint name at the very least. - -Although it is optional, the version number should match the latest version of your build in most use-cases. -If it is not set, it will default to "1". - -# Field Types - -## Generated Fields - -### Generated List Field - -A `GeneratedListField` is a special type of custom list that implements the following: - -- **values** (`Array`): the confidence score of the field prediction. -- **pageId** (`number`): only available for some documents ATM. - -Since the inner contents can vary, the value isn't accessed through a property, but rather through the following functions: - -- **contentsList()** (`: Array`): returns a list of values for each element. -- **contentsString(separator=" ")** (`: string`): returns a list of concatenated values, with an optional **separator** `string` between them. -> **Note:** the `toString()` method returns a string representation of all values of this object, with an empty space between each of them. - -### Generated Object Field - -Unrecognized structures and sometimes values of `ListField`s are stored in a `GeneratedObjectField` structure, which is implemented dynamically depending on the object's structure. - -- **pageId** (`number?`): the ID of the page, is `null` when at document-level. -- **rawValue** (`string?`): an optional field for when some post-processing has been done on fields (e.g. amounts). `null` in most instances. -- **confidence** (`number`): the confidence score of the field prediction. Warning: support isn't guaranteed on all APIs. - - -> **Other fields**:No matter what, other fields will be stored in a dictionary-like structure with a `key: value` pair where `key` is a string and `value` is a nullable string. They can be accessed like any other regular value, but won't be suggested by your IDE. - - -### StringField -The text field `StringField` only has one constraint: its **value** is an `string?`. - - -# Attributes - -Generated builds always have access to at least two attributes: - -## Fields - -**fields** (`Map)`): - -```js -console.log(result.document.inference.prediction.fields.get("my-field").value); -``` - -> Note: while technically defined as `any`, the results of the fields can be type narrowed to `Map` using TypeScript. - -# Questions? - -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/getting_started.md b/docs/getting_started.md deleted file mode 100644 index c2b3498d8..000000000 --- a/docs/getting_started.md +++ /dev/null @@ -1,299 +0,0 @@ ---- -title: Getting Started Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-getting-started -parentDoc: 609809574212d40077a040f1 ---- -This guide will help you get the most out of the Mindee Node.js client library to easily extract data from your documents. - -> ๐Ÿ“˜ **Info** -> -> The library is written in TypeScript for your coding pleasure and is officially supported on all current LTS versions of Node.js. -> All examples shown in this guide should work in both TypeScript and JavaScript. - -## Installation - -### Prerequisites - -You'll need [npm and Node.js](https://nodejs.dev/download/package-manager/). - -**Note**: When installing a Node.js instance, [nvm](https://github.com/nvm-sh/nvm) will also install a compatible npm version. - -### Standard Installation - -The easiest way to install the Mindee client library for your project is by using npm: - -```shell -npm install mindee -``` - -### Development Installation - -If you'll be modifying the source code, you'll need to follow these steps to get started. - -1. First clone the repo. - -```shell -git clone git@github.com:mindee/mindee-api-nodejs.git -``` - -2. Navigate to the cloned directory and install all required libraries. - -```shell -cd mindee-api-node.js -npm install -``` - -## Updating the Library - -It is important to always check the version of the Mindee client library you are using, as new and updated features wonโ€™t work on older versions. - -To get the latest version: - -```shell -npm update mindee -``` - -To install a specific version of Mindee: - -```shell -npm install mindee@ -``` - -## Usage - -Using Mindee's APIs can be broken down into the following steps: - -1. [Import the required classes](#importing-requirements) in your program -2. [Initialize a `Client`](#initializing-the-client) -3. [Load a file](#loading-a-document-file) -4. [Send the file](#sending-a-document) to Mindee's API -5. [Retrieve the response](#retrieving-the-response) -6. [Process the response](#processing-the-response) in some way - -Let's take a deep dive into how this works. - -### Importing Requirements - -In most cases, you'll just need to `require` the `mindee` module: - -```js -const mindee = require("mindee"); -``` - -If you're building your own module, or using TypeScript, the equivalent would be: - -```ts -import * as mindee from "mindee"; -``` - -### Initializing the Client - -The `Client` centralizes document configurations in a single object. - -The `Client` requires your [API key](https://developers.mindee.com/docs/make-your-first-request#create-an-api-key). - -You can either pass these directly to the constructor or through environment variables. - -#### Pass the API key directly - -```ts -// Init a new client and passing the key directly -const mindeeClient = new mindee.Client({apiKey: "my-api-key"}); -``` - -#### Set the API key in the environment - -API keys should be set as environment variables, especially for any production deployment. - -The following environment variable will set the global API key: - -```shell -MINDEE_API_KEY="my-api-key" -``` - -Then in your code: - -```ts -// Init a new client without an API key -const mindeeClient = new Client(); -``` - -## Loading a Document File - -Before being able to send a document to the API, it must first be loaded. - -You don't need to worry about different MIME types, the library will take care of handling -all supported types automatically. - -Once a document is loaded, interacting with it is done in exactly the same way, regardless -of how it was loaded. - -There are a few different ways of loading a document file, depending on your use case: - -- [Path](#path) -- [File Object](#stream-object) -- [Base64](#base64) -- [URL](#url) - -### Path - -Load from a file directly from disk. Requires an absolute path, as a string. - -```ts -const inputSource = mindeeClient.docFromPath("/path/to/the/document.pdf"); -``` - -### Stream Object - -Load a standard readable stream object, for example as returned by the `fs.createReadStream()` function. - -**Note**: The original filename is required when calling the method. - -```ts -const stream = fs.createReadStream("/path/to/the/document.jpg"); -const inputSource = mindeeClient.docFromStream(stream, "document.jpg"); -``` - -### Base64 - -Load file contents from a base64-encoded string. - -**Note**: The original filename is required when calling the method. - -```ts -const b64String = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLD...." -const inputSource = mindeeClient.docFromBase64(b64String, "document.jpg"); -``` - -### URL - -Specify a URL to send to the Mindee API. - -**Note**: The URL will not be downloaded locally, so checks (i.e. MIME type) and transformations (i.e. remove pages from a PDF) will not be possible. - -```ts -const inputSource = mindeeClient.docFromUrl("https://example.com/image.jpg"); -``` - -## Sending a Document - -To send a file to the API, we need to specify how to process the document. -This will determine which API endpoint is used and how the API return will be handled internally by the library. - -More specifically, we need to set a `Product` class as the first parameter of the `parse` method. - -This is because the `parse` method is [generic](https://www.typescriptlang.org/docs/handbook/2/generics.html#generic-classes), and its return type depends on its first argument. - -Each document type available in the library has its corresponding class, which inherit from the base `Document` class. -This is detailed in each document-specific guide. - -### Off-the-Shelf Documents - -Simply setting the correct class and passing the document is enough: - -```ts -const respPromise = mindeeClient.parse(mindee.InvoiceV4, inputSource); -``` - -### Custom Documents (docTI) - -The endpoint to use must also be set in third argument of the `enqueueAndParse` method. This argument is an object: - -```ts -const customEndpoint = mindeeClient.createEndpoint( - "my-endpoint", - "my-account", - // "my-version" // Optional: set the version, defaults to "1" -); -const respPromise = mindeeClient.enqueueAndParse( - mindee.GeneratedV1, - inputSource, - { - endpoint: customEndpoint - } -); -``` - -This is because the `GeneratedV1` class is enough to handle the return processing, but the actual endpoint needs to be specified. - -## Retrieving the Response - -The return of the `parse` method is a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves to a `Response` object. - -More technically, the return object is instantiated depending on the specific `Document` class passed as the first argument to `parse`. - -Handling the return is done like any other Promise: - -```ts -respPromise.then((resp) => { - console.log(resp.document); -}); -``` - -Some other styles: - -```ts -// One-liner -mindeeClient.parse(mindee.InvoiceV4, inputSource).then((resp) => { - console.log(resp.document); -}); - -// Async function -async function parseInvoice() { - const inputSource = mindeeClient.docFromPath("/path/to/the/invoice.pdf"); - const response = await mindeeClient.parse(mindee.InvoiceV4, inputSource); -} -``` - -## Processing the Response - -The `Response` objects all have the following attributes: - -- `document` โ€” [Document level prediction](#document-level-prediction) -- `pages` โ€” [Page level prediction](#page-level-prediction) - -### Document Level Prediction - -The `document` attribute is an object specific to the type of document being processed. -It is an instance of the `Document` class, to which a generic type is given. - -It contains the data extracted from the entire document, all pages combined. -It's possible to have the same field in various pages, but at the document level only the highest confidence field data will be shown (this is all done automatically at the API level). - - -```ts -// print a summary of the document-level info - console.log(resp.document.toString()); -// or -console.log(`${resp.document}`); -``` - -A `document`'s fields (attributes) can be accessed through it's `prediction` attribute, which have types that can vary from one product to another. -These attributes are detailed in each product's respective guide. - -### Page Level Prediction - -The `pages` attribute is an array of `Page` objects. `Page` is a wrapper around elements that extend the [`Document` class](#Document-level-prediction). -The `prediction` of a `Page` inherits from the product's own `Document`, and adds all page-specific fields to it. - -The order of the elements in the array matches the order of the pages in the document. - -All response objects have a `pages` property, regardless of the number of pages. -Single-page documents will have a single entry. - -Iteration over `pages` is done like with any JavaScript array, for example: - -```ts -resp.pages.forEach((page) => { - // as object, complete - console.log(page.toString()); - - // as string, summary - console.log(`${page}`); -}); -``` - -# Questions? - -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/idcard_fr_v2.md b/docs/idcard_fr_v2.md deleted file mode 100644 index d0014b7d5..000000000 --- a/docs/idcard_fr_v2.md +++ /dev/null @@ -1,269 +0,0 @@ ---- -title: FR Carte Nationale d'Identitรฉ OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-fr-carte-nationale-didentite-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Carte Nationale d'Identitรฉ API](https://platform.mindee.com/mindee/idcard_fr). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/idcard_fr/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Carte Nationale d'Identitรฉ sample](https://github.com/mindee/client-lib-test-data/blob/main/products/idcard_fr/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.fr.IdCardV2, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: d33828f1-ef7e-4984-b9df-a2bfaa38a78d -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/idcard_fr v2.0 -:Rotation applied: Yes - -Prediction -========== -:Nationality: -:Card Access Number: 175775H55790 -:Document Number: -:Given Name(s): Victor - Marie -:Surname: DAMBARD -:Alternate Name: -:Date of Birth: 1994-04-24 -:Place of Birth: LYON 4E ARRONDISSEM -:Gender: M -:Expiry Date: 2030-04-02 -:Mrz Line 1: IDFRADAMBARD<<<<<<<<<<<<<<<<<<075025 -:Mrz Line 2: 170775H557903VICTOR< **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **pageId**. - -> Note: a classification field's `value is always a `string`. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -## Page-Level Fields -Some fields are constrained to the page level, and so will not be retrievable at document level. - -# Attributes -The following fields are extracted for Carte Nationale d'Identitรฉ V2: - -## Alternate Name -**alternateName** ([StringField](#string-field)): The alternate name of the card holder. - -```js -console.log(result.document.inference.prediction.alternateName.value); -``` - -## Issuing Authority -**authority** ([StringField](#string-field)): The name of the issuing authority. - -```js -console.log(result.document.inference.prediction.authority.value); -``` - -## Date of Birth -**birthDate** ([DateField](#date-field)): The date of birth of the card holder. - -```js -console.log(result.document.inference.prediction.birthDate.value); -``` - -## Place of Birth -**birthPlace** ([StringField](#string-field)): The place of birth of the card holder. - -```js -console.log(result.document.inference.prediction.birthPlace.value); -``` - -## Card Access Number -**cardAccessNumber** ([StringField](#string-field)): The card access number (CAN). - -```js -console.log(result.document.inference.prediction.cardAccessNumber.value); -``` - -## Document Number -**documentNumber** ([StringField](#string-field)): The document number. - -```js -console.log(result.document.inference.prediction.documentNumber.value); -``` - -## Document Sides -[๐Ÿ“„](#page-level-fields "This field is only present on individual pages.")**documentSide** ([ClassificationField](#classification-field)): The sides of the document which are visible. - -#### Possible values include: - - 'RECTO' - - 'VERSO' - - 'RECTO & VERSO' - -```js -for (const documentSideElem of result.document.documentSide) { - console.log(documentSideElem.value); -} -``` - -## Document Type -[๐Ÿ“„](#page-level-fields "This field is only present on individual pages.")**documentType** ([ClassificationField](#classification-field)): The document type or format. - -#### Possible values include: - - 'NEW' - - 'OLD' - -```js -for (const documentTypeElem of result.document.documentType) { - console.log(documentTypeElem.value); -} -``` - -## Expiry Date -**expiryDate** ([DateField](#date-field)): The expiry date of the identification card. - -```js -console.log(result.document.inference.prediction.expiryDate.value); -``` - -## Gender -**gender** ([StringField](#string-field)): The gender of the card holder. - -```js -console.log(result.document.inference.prediction.gender.value); -``` - -## Given Name(s) -**givenNames** ([StringField](#string-field)[]): The given name(s) of the card holder. - -```js -for (const givenNamesElem of result.document.inference.prediction.givenNames) { - console.log(givenNamesElem.value); -} -``` - -## Date of Issue -**issueDate** ([DateField](#date-field)): The date of issue of the identification card. - -```js -console.log(result.document.inference.prediction.issueDate.value); -``` - -## Mrz Line 1 -**mrz1** ([StringField](#string-field)): The Machine Readable Zone, first line. - -```js -console.log(result.document.inference.prediction.mrz1.value); -``` - -## Mrz Line 2 -**mrz2** ([StringField](#string-field)): The Machine Readable Zone, second line. - -```js -console.log(result.document.inference.prediction.mrz2.value); -``` - -## Mrz Line 3 -**mrz3** ([StringField](#string-field)): The Machine Readable Zone, third line. - -```js -console.log(result.document.inference.prediction.mrz3.value); -``` - -## Nationality -**nationality** ([StringField](#string-field)): The nationality of the card holder. - -```js -console.log(result.document.inference.prediction.nationality.value); -``` - -## Surname -**surname** ([StringField](#string-field)): The surname of the card holder. - -```js -console.log(result.document.inference.prediction.surname.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/ind_passport_v1.md b/docs/ind_passport_v1.md deleted file mode 100644 index 2babfc971..000000000 --- a/docs/ind_passport_v1.md +++ /dev/null @@ -1,284 +0,0 @@ ---- -title: IND Passport - India OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-ind-passport---india-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Passport - India API](https://platform.mindee.com/mindee/ind_passport). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/ind_passport/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Passport - India sample](https://github.com/mindee/client-lib-test-data/blob/main/products/ind_passport/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.ind.IndianPassportV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: cf88fd43-eaa1-497a-ba29-a9569a4edaa7 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/ind_passport v1.2 -:Rotation applied: Yes - -Prediction -========== -:Page Number: 1 -:Country: IND -:ID Number: J8369854 -:Given Names: JOCELYN MICHELLE -:Surname: DOE -:Birth Date: 1959-09-23 -:Birth Place: GUNDUGOLANU -:Issuance Place: HYDERABAD -:Gender: F -:Issuance Date: 2011-10-11 -:Expiry Date: 2021-10-10 -:MRZ Line 1: P **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **pageId**. - -> Note: a classification field's `value is always a `string`. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -# Attributes -The following fields are extracted for Passport - India V1: - -## Address Line 1 -**address1** ([StringField](#string-field)): The first line of the address of the passport holder. - -```js -console.log(result.document.inference.prediction.address1.value); -``` - -## Address Line 2 -**address2** ([StringField](#string-field)): The second line of the address of the passport holder. - -```js -console.log(result.document.inference.prediction.address2.value); -``` - -## Address Line 3 -**address3** ([StringField](#string-field)): The third line of the address of the passport holder. - -```js -console.log(result.document.inference.prediction.address3.value); -``` - -## Birth Date -**birthDate** ([DateField](#date-field)): The birth date of the passport holder, ISO format: YYYY-MM-DD. - -```js -console.log(result.document.inference.prediction.birthDate.value); -``` - -## Birth Place -**birthPlace** ([StringField](#string-field)): The birth place of the passport holder. - -```js -console.log(result.document.inference.prediction.birthPlace.value); -``` - -## Country -**country** ([StringField](#string-field)): ISO 3166-1 alpha-3 country code (3 letters format). - -```js -console.log(result.document.inference.prediction.country.value); -``` - -## Expiry Date -**expiryDate** ([DateField](#date-field)): The date when the passport will expire, ISO format: YYYY-MM-DD. - -```js -console.log(result.document.inference.prediction.expiryDate.value); -``` - -## File Number -**fileNumber** ([StringField](#string-field)): The file number of the passport document. - -```js -console.log(result.document.inference.prediction.fileNumber.value); -``` - -## Gender -**gender** ([ClassificationField](#classification-field)): The gender of the passport holder. - -#### Possible values include: - - 'M' - - 'F' - -```js -console.log(result.document.inference.prediction.gender.value); -``` - -## Given Names -**givenNames** ([StringField](#string-field)): The given names of the passport holder. - -```js -console.log(result.document.inference.prediction.givenNames.value); -``` - -## ID Number -**idNumber** ([StringField](#string-field)): The identification number of the passport document. - -```js -console.log(result.document.inference.prediction.idNumber.value); -``` - -## Issuance Date -**issuanceDate** ([DateField](#date-field)): The date when the passport was issued, ISO format: YYYY-MM-DD. - -```js -console.log(result.document.inference.prediction.issuanceDate.value); -``` - -## Issuance Place -**issuancePlace** ([StringField](#string-field)): The place where the passport was issued. - -```js -console.log(result.document.inference.prediction.issuancePlace.value); -``` - -## Legal Guardian -**legalGuardian** ([StringField](#string-field)): The name of the legal guardian of the passport holder (if applicable). - -```js -console.log(result.document.inference.prediction.legalGuardian.value); -``` - -## MRZ Line 1 -**mrz1** ([StringField](#string-field)): The first line of the machine-readable zone (MRZ) of the passport document. - -```js -console.log(result.document.inference.prediction.mrz1.value); -``` - -## MRZ Line 2 -**mrz2** ([StringField](#string-field)): The second line of the machine-readable zone (MRZ) of the passport document. - -```js -console.log(result.document.inference.prediction.mrz2.value); -``` - -## Name of Mother -**nameOfMother** ([StringField](#string-field)): The name of the mother of the passport holder. - -```js -console.log(result.document.inference.prediction.nameOfMother.value); -``` - -## Name of Spouse -**nameOfSpouse** ([StringField](#string-field)): The name of the spouse of the passport holder (if applicable). - -```js -console.log(result.document.inference.prediction.nameOfSpouse.value); -``` - -## Old Passport Date of Issue -**oldPassportDateOfIssue** ([DateField](#date-field)): The date of issue of the old passport (if applicable), ISO format: YYYY-MM-DD. - -```js -console.log(result.document.inference.prediction.oldPassportDateOfIssue.value); -``` - -## Old Passport Number -**oldPassportNumber** ([StringField](#string-field)): The number of the old passport (if applicable). - -```js -console.log(result.document.inference.prediction.oldPassportNumber.value); -``` - -## Old Passport Place of Issue -**oldPassportPlaceOfIssue** ([StringField](#string-field)): The place of issue of the old passport (if applicable). - -```js -console.log(result.document.inference.prediction.oldPassportPlaceOfIssue.value); -``` - -## Page Number -**pageNumber** ([ClassificationField](#classification-field)): The page number of the passport document. - -#### Possible values include: - - '1' - - '2' - -```js -console.log(result.document.inference.prediction.pageNumber.value); -``` - -## Surname -**surname** ([StringField](#string-field)): The surname of the passport holder. - -```js -console.log(result.document.inference.prediction.surname.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/international_id_v2.md b/docs/international_id_v2.md deleted file mode 100644 index f64beb61e..000000000 --- a/docs/international_id_v2.md +++ /dev/null @@ -1,241 +0,0 @@ ---- -title: International ID OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-international-id-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [International ID API](https://platform.mindee.com/mindee/international_id). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/international_id/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![International ID sample](https://github.com/mindee/client-lib-test-data/blob/main/products/international_id/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.InternationalIdV2, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: cfa20a58-20cf-43b6-8cec-9505fa69d1c2 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/international_id v2.0 -:Rotation applied: No - -Prediction -========== -:Document Type: IDENTIFICATION_CARD -:Document Number: 12345678A -:Surnames: MUESTRA - MUESTRA -:Given Names: CARMEN -:Sex: F -:Birth Date: 1980-01-01 -:Birth Place: CAMPO DE CRIPTANA CIUDAD REAL ESPANA -:Nationality: ESP -:Personal Number: BAB1834284<44282767Q0 -:Country of Issue: ESP -:State of Issue: MADRID -:Issue Date: -:Expiration Date: 2030-01-01 -:Address: C/REAL N13, 1 DCHA COLLADO VILLALBA MADRID MADRID MADRID -:MRZ Line 1: IDESPBAB1834284<44282767Q0<<<< -:MRZ Line 2: 8001010F1301017ESP<<<<<<<<<<<3 -:MRZ Line 3: MUESTRA **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **pageId**. - -> Note: a classification field's `value is always a `string`. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -# Attributes -The following fields are extracted for International ID V2: - -## Address -**address** ([StringField](#string-field)): The physical address of the document holder. - -```js -console.log(result.document.inference.prediction.address.value); -``` - -## Birth Date -**birthDate** ([DateField](#date-field)): The date of birth of the document holder. - -```js -console.log(result.document.inference.prediction.birthDate.value); -``` - -## Birth Place -**birthPlace** ([StringField](#string-field)): The place of birth of the document holder. - -```js -console.log(result.document.inference.prediction.birthPlace.value); -``` - -## Country of Issue -**countryOfIssue** ([StringField](#string-field)): The country where the document was issued. - -```js -console.log(result.document.inference.prediction.countryOfIssue.value); -``` - -## Document Number -**documentNumber** ([StringField](#string-field)): The unique identifier assigned to the document. - -```js -console.log(result.document.inference.prediction.documentNumber.value); -``` - -## Document Type -**documentType** ([ClassificationField](#classification-field)): The type of personal identification document. - -#### Possible values include: - - 'IDENTIFICATION_CARD' - - 'PASSPORT' - - 'DRIVER_LICENSE' - - 'VISA' - - 'RESIDENCY_CARD' - - 'VOTER_REGISTRATION' - -```js -console.log(result.document.inference.prediction.documentType.value); -``` - -## Expiration Date -**expiryDate** ([DateField](#date-field)): The date when the document becomes invalid. - -```js -console.log(result.document.inference.prediction.expiryDate.value); -``` - -## Given Names -**givenNames** ([StringField](#string-field)[]): The list of the document holder's given names. - -```js -for (const givenNamesElem of result.document.inference.prediction.givenNames) { - console.log(givenNamesElem.value); -} -``` - -## Issue Date -**issueDate** ([DateField](#date-field)): The date when the document was issued. - -```js -console.log(result.document.inference.prediction.issueDate.value); -``` - -## MRZ Line 1 -**mrzLine1** ([StringField](#string-field)): The Machine Readable Zone, first line. - -```js -console.log(result.document.inference.prediction.mrzLine1.value); -``` - -## MRZ Line 2 -**mrzLine2** ([StringField](#string-field)): The Machine Readable Zone, second line. - -```js -console.log(result.document.inference.prediction.mrzLine2.value); -``` - -## MRZ Line 3 -**mrzLine3** ([StringField](#string-field)): The Machine Readable Zone, third line. - -```js -console.log(result.document.inference.prediction.mrzLine3.value); -``` - -## Nationality -**nationality** ([StringField](#string-field)): The country of citizenship of the document holder. - -```js -console.log(result.document.inference.prediction.nationality.value); -``` - -## Personal Number -**personalNumber** ([StringField](#string-field)): The unique identifier assigned to the document holder. - -```js -console.log(result.document.inference.prediction.personalNumber.value); -``` - -## Sex -**sex** ([StringField](#string-field)): The biological sex of the document holder. - -```js -console.log(result.document.inference.prediction.sex.value); -``` - -## State of Issue -**stateOfIssue** ([StringField](#string-field)): The state or territory where the document was issued. - -```js -console.log(result.document.inference.prediction.stateOfIssue.value); -``` - -## Surnames -**surnames** ([StringField](#string-field)[]): The list of the document holder's family names. - -```js -for (const surnamesElem of result.document.inference.prediction.surnames) { - console.log(surnamesElem.value); -} -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/invoice_splitter_v1.md b/docs/invoice_splitter_v1.md deleted file mode 100644 index 5e20d1b55..000000000 --- a/docs/invoice_splitter_v1.md +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: Invoice Splitter OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-invoice-splitter-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Invoice Splitter API](https://platform.mindee.com/mindee/invoice_splitter). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/default_sample.pdf), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Invoice Splitter sample](https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/default_sample.pdf?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.InvoiceSplitterV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 15ad7a19-7b75-43d0-b0c6-9a641a12b49b -:Filename: default_sample.pdf - -Inference -######### -:Product: mindee/invoice_splitter v1.2 -:Rotation applied: No - -Prediction -========== -:Invoice Page Groups: - +--------------------------------------------------------------------------+ - | Page Indexes | - +==========================================================================+ - | 0 | - +--------------------------------------------------------------------------+ - | 1 | - +--------------------------------------------------------------------------+ -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Invoice Page Groups Field -List of page groups. Each group represents a single invoice within a multi-invoice document. - -A `InvoiceSplitterV1InvoicePageGroup` implements the following attributes: - -* `pageIndexes` (Array): List of page indexes that belong to the same invoice (group). - -# Attributes -The following fields are extracted for Invoice Splitter V1: - -## Invoice Page Groups -**invoicePageGroups** ([InvoiceSplitterV1InvoicePageGroup](#invoice-page-groups-field)[]): List of page groups. Each group represents a single invoice within a multi-invoice document. - -```js -for (const invoicePageGroupsElem of result.document.inference.prediction.invoicePageGroups) { - console.log(invoicePageGroupsElem.value); -} -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/invoices_v4.md b/docs/invoices_v4.md deleted file mode 100644 index bdf269e5a..000000000 --- a/docs/invoices_v4.md +++ /dev/null @@ -1,543 +0,0 @@ ---- -title: Invoice OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-invoice-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Invoice API](https://platform.mindee.com/mindee/invoices). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/invoices/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Invoice sample](https://github.com/mindee/client-lib-test-data/blob/main/products/invoices/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.InvoiceV4, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -You can also call this product asynchronously: - -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.InvoiceV4, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 744748d5-9051-461c-b70c-bbf81f5ff943 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/invoices v4.11 -:Rotation applied: Yes - -Prediction -========== -:Locale: en-CA; en; CA; CAD; -:Invoice Number: 14 -:Purchase Order Number: AD29094 -:Reference Numbers: AD29094 -:Purchase Date: 2018-09-25 -:Due Date: -:Payment Date: -:Total Net: 2145.00 -:Total Amount: 2608.20 -:Total Tax: 193.20 -:Taxes: - +---------------+--------+----------+---------------+ - | Base | Code | Rate (%) | Amount | - +===============+========+==========+===============+ - | 2145.00 | | 8.00 | 193.20 | - +---------------+--------+----------+---------------+ -:Supplier Payment Details: -:Supplier Name: TURNPIKE DESIGNS -:Supplier Company Registrations: -:Supplier Address: 156 University Ave, Toronto ON, Canada, M5H 2H7 -:Supplier Phone Number: 4165551212 -:Supplier Website: -:Supplier Email: j_coi@example.com -:Customer Name: JIRO DOI -:Customer Company Registrations: -:Customer Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada -:Customer ID: -:Shipping Address: -:Billing Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada -:Document Type: INVOICE -:Document Type Extended: INVOICE -:Purchase Subcategory: -:Purchase Category: miscellaneous -:Line Items: - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | Description | Product code | Quantity | Tax Amount | Tax Rate (%) | Total Amount | Unit of measure | Unit Price | - +======================================+==============+==========+============+==============+==============+=================+============+ - | Platinum web hosting package Down... | | 1.00 | | | 65.00 | | 65.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | 2 page website design Includes ba... | | 3.00 | | | 2100.00 | | 2100.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | Mobile designs Includes responsiv... | | 1.00 | | | 250.00 | 1 | 250.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - -Page Predictions -================ - -Page 0 ------- -:Locale: en-CA; en; CA; CAD; -:Invoice Number: 14 -:Purchase Order Number: AD29094 -:Reference Numbers: AD29094 -:Purchase Date: 2018-09-25 -:Due Date: -:Payment Date: -:Total Net: 2145.00 -:Total Amount: 2608.20 -:Total Tax: 193.20 -:Taxes: - +---------------+--------+----------+---------------+ - | Base | Code | Rate (%) | Amount | - +===============+========+==========+===============+ - | 2145.00 | | 8.00 | 193.20 | - +---------------+--------+----------+---------------+ -:Supplier Payment Details: -:Supplier Name: TURNPIKE DESIGNS -:Supplier Company Registrations: -:Supplier Address: 156 University Ave, Toronto ON, Canada, M5H 2H7 -:Supplier Phone Number: 4165551212 -:Supplier Website: -:Supplier Email: j_coi@example.com -:Customer Name: JIRO DOI -:Customer Company Registrations: -:Customer Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada -:Customer ID: -:Shipping Address: -:Billing Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada -:Document Type: INVOICE -:Document Type Extended: INVOICE -:Purchase Subcategory: -:Purchase Category: miscellaneous -:Line Items: - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | Description | Product code | Quantity | Tax Amount | Tax Rate (%) | Total Amount | Unit of measure | Unit Price | - +======================================+==============+==========+============+==============+==============+=================+============+ - | Platinum web hosting package Down... | | 1.00 | | | 65.00 | | 65.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | 2 page website design Includes ba... | | 3.00 | | | 2100.00 | | 2100.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ - | Mobile designs Includes responsiv... | | 1.00 | | | 250.00 | 1 | 250.00 | - +--------------------------------------+--------------+----------+------------+--------------+--------------+-----------------+------------+ -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### AddressField -Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following: - -* **streetNumber** (`string`): String representation of the street number. Can be `null`. -* **streetName** (`string`): Name of the street. Can be `null`. -* **poBox** (`string`): String representation of the PO Box number. Can be `null`. -* **addressComplement** (`string`): Address complement. Can be `null`. -* **city** (`string`): City name. Can be `null`. -* **postalCode** (`string`): String representation of the postal code. Can be `null`. -* **state** (`string`): State name. Can be `null`. -* **country** (`string`): Country name. Can be `null`. - -Note: The `value` field of an AddressField should be a concatenation of the rest of the values. - - -### Amount Field -The amount field `AmountField` only has one constraint: its **value** is a `number` (or `undefined`). - - -### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **pageId**. - -> Note: a classification field's `value is always a `string`. - - -### Company Registration Field -Aside from the basic `Field` attributes, the company registration field `CompanyRegistrationField` also implements the following: - -* **type** (`string`): the type of company. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### Locale Field -The locale field `LocaleField` only implements the **value**, **confidence** and **pageId** base `Field` attributes, but it comes with its own: - -* **language** (`string`): ISO 639-1 language code (e.g.: `en` for English). Can be `undefined`. -* **country** (`string`): ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3 code for countries (e.g.: `GRB` or `GB` for "Great Britain"). Can be `undefined`. -* **currency** (`string`): ISO 4217 code for currencies (e.g.: `USD` for "US Dollars"). Can be `undefined`. - -### Payment Details Field -Aside from the basic `Field` attributes, the payment details field `PaymentDetailsField` also implements the following: - -* **accountNumber** (`string`): number of an account, expressed as a string. Can be `undefined`. -* **iban** (`string`): International Bank Account Number. Can be `undefined`. -* **routingNumber** (`string`): routing number of an account. Can be `undefined`. -* **swift** (`string`): the account holder's bank's SWIFT Business Identifier Code (BIC). Can be `undefined`. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -### Taxes Field -#### Tax -Aside from the basic `Field` attributes, the tax field `TaxField` also implements the following: - -* **rate** (`number`): the tax rate applied to an item can be expressed as a percentage. Can be `undefined`. -* **code** (`string`): tax code (or equivalent, depending on the origin of the document). Can be `undefined`. -* **base** (`number`): base amount used for the tax. Can be `undefined`. -* **value** (`number`): the value of the tax. Can be `null`. - -> Note: currently `TaxField` is not used on its own, and is accessed through a parent `Taxes` object, an array-like structure. - -#### Taxes (Array) -The `Taxes` field represents an array-like collection of `TaxField` objects. As it is the representation of several objects, it has access to a custom `toString()` method that can render a `TaxField` object as a table line. - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Line Items Field -List of all the line items present on the invoice. - -A `InvoiceV4LineItem` implements the following attributes: - -* `description` (string): The item description. -* `productCode` (string): The product code of the item. -* `quantity` (number): The item quantity -* `taxAmount` (number): The item tax amount. -* `taxRate` (number): The item tax rate in percentage. -* `totalAmount` (number): The item total amount. -* `unitMeasure` (string): The item unit of measure. -* `unitPrice` (number): The item unit price. - -# Attributes -The following fields are extracted for Invoice V4: - -## Billing Address -**billingAddress** : The customer billing address. - -```js -console.log(result.document.inference.prediction.billingAddress.value); -``` - -## Purchase Category -**category** ([ClassificationField](#classification-field)): The purchase category. - -#### Possible values include: - - 'toll' - - 'food' - - 'parking' - - 'transport' - - 'accommodation' - - 'telecom' - - 'miscellaneous' - - 'software' - - 'shopping' - - 'energy' - -```js -console.log(result.document.inference.prediction.category.value); -``` - -## Customer Address -**customerAddress** : The address of the customer. - -```js -console.log(result.document.inference.prediction.customerAddress.value); -``` - -## Customer Company Registrations -**customerCompanyRegistrations** ([CompanyRegistrationField](#company-registration-field)[]): List of company registration numbers associated to the customer. - -```js -for (const customerCompanyRegistrationsElem of result.document.inference.prediction.customerCompanyRegistrations) { - console.log(customerCompanyRegistrationsElem.value); -} -``` - -## Customer ID -**customerId** ([StringField](#string-field)): The customer account number or identifier from the supplier. - -```js -console.log(result.document.inference.prediction.customerId.value); -``` - -## Customer Name -**customerName** ([StringField](#string-field)): The name of the customer or client. - -```js -console.log(result.document.inference.prediction.customerName.value); -``` - -## Purchase Date -**date** ([DateField](#date-field)): The date the purchase was made. - -```js -console.log(result.document.inference.prediction.date.value); -``` - -## Document Type -**documentType** ([ClassificationField](#classification-field)): Document type: INVOICE or CREDIT NOTE. - -#### Possible values include: - - 'INVOICE' - - 'CREDIT NOTE' - -```js -console.log(result.document.inference.prediction.documentType.value); -``` - -## Document Type Extended -**documentTypeExtended** ([ClassificationField](#classification-field)): Document type extended. - -#### Possible values include: - - 'CREDIT NOTE' - - 'INVOICE' - - 'OTHER' - - 'OTHER_FINANCIAL' - - 'PAYSLIP' - - 'PURCHASE ORDER' - - 'QUOTE' - - 'RECEIPT' - - 'STATEMENT' - -```js -console.log(result.document.inference.prediction.documentTypeExtended.value); -``` - -## Due Date -**dueDate** ([DateField](#date-field)): The date on which the payment is due. - -```js -console.log(result.document.inference.prediction.dueDate.value); -``` - -## Invoice Number -**invoiceNumber** ([StringField](#string-field)): The invoice number or identifier. - -```js -console.log(result.document.inference.prediction.invoiceNumber.value); -``` - -## Line Items -**lineItems** ([InvoiceV4LineItem](#line-items-field)[]): List of all the line items present on the invoice. - -```js -for (const lineItemsElem of result.document.inference.prediction.lineItems) { - console.log(lineItemsElem.value); -} -``` - -## Locale -**locale** ([LocaleField](#locale-field)): The locale of the document. - -```js -console.log(result.document.inference.prediction.locale.value); -``` - -## Payment Date -**paymentDate** ([DateField](#date-field)): The date on which the payment is due / was full-filled. - -```js -console.log(result.document.inference.prediction.paymentDate.value); -``` - -## Purchase Order Number -**poNumber** ([StringField](#string-field)): The purchase order number. - -```js -console.log(result.document.inference.prediction.poNumber.value); -``` - -## Reference Numbers -**referenceNumbers** ([StringField](#string-field)[]): List of all reference numbers on the invoice, including the purchase order number. - -```js -for (const referenceNumbersElem of result.document.inference.prediction.referenceNumbers) { - console.log(referenceNumbersElem.value); -} -``` - -## Shipping Address -**shippingAddress** : Customer's delivery address. - -```js -console.log(result.document.inference.prediction.shippingAddress.value); -``` - -## Purchase Subcategory -**subcategory** ([ClassificationField](#classification-field)): The purchase subcategory for transport, food and shopping. - -#### Possible values include: - - 'plane' - - 'taxi' - - 'train' - - 'restaurant' - - 'shopping' - - 'other' - - 'groceries' - - 'cultural' - - 'electronics' - - 'office_supplies' - - 'micromobility' - - 'car_rental' - - 'public' - - 'delivery' - - null - -```js -console.log(result.document.inference.prediction.subcategory.value); -``` - -## Supplier Address -**supplierAddress** : The address of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierAddress.value); -``` - -## Supplier Company Registrations -**supplierCompanyRegistrations** ([CompanyRegistrationField](#company-registration-field)[]): List of company registration numbers associated to the supplier. - -```js -for (const supplierCompanyRegistrationsElem of result.document.inference.prediction.supplierCompanyRegistrations) { - console.log(supplierCompanyRegistrationsElem.value); -} -``` - -## Supplier Email -**supplierEmail** ([StringField](#string-field)): The email address of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierEmail.value); -``` - -## Supplier Name -**supplierName** ([StringField](#string-field)): The name of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierName.value); -``` - -## Supplier Payment Details -**supplierPaymentDetails** ([PaymentDetailsField](#payment-details-field)[]): List of payment details associated to the supplier of the invoice. - -```js -for (const supplierPaymentDetailsElem of result.document.inference.prediction.supplierPaymentDetails) { - console.log(supplierPaymentDetailsElem.value); - console.log(supplierPaymentDetailsElem.rate); - console.log(supplierPaymentDetailsElem.code); - console.log(supplierPaymentDetailsElem.basis); -} -``` - -## Supplier Phone Number -**supplierPhoneNumber** ([StringField](#string-field)): The phone number of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierPhoneNumber.value); -``` - -## Supplier Website -**supplierWebsite** ([StringField](#string-field)): The website URL of the supplier or merchant. - -```js -console.log(result.document.inference.prediction.supplierWebsite.value); -``` - -## Taxes -**taxes** ([TaxField](#taxes-field)[]): List of taxes. Each item contains the detail of the tax. - -```js -for (const taxesElem of result.document.inference.prediction.taxes) { - console.log(taxesElem.value); -} -``` - -## Total Amount -**totalAmount** ([AmountField](#amount-field)): The total amount of the invoice: includes taxes, tips, fees, and other charges. - -```js -console.log(result.document.inference.prediction.totalAmount.value); -``` - -## Total Net -**totalNet** ([AmountField](#amount-field)): The net amount of the invoice: does not include taxes, fees, and discounts. - -```js -console.log(result.document.inference.prediction.totalNet.value); -``` - -## Total Tax -**totalTax** ([AmountField](#amount-field)): The total tax: the sum of all the taxes for this invoice. - -```js -console.log(result.document.inference.prediction.totalTax.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/multi_receipts_detector_v1.md b/docs/multi_receipts_detector_v1.md deleted file mode 100644 index 75cbfad7b..000000000 --- a/docs/multi_receipts_detector_v1.md +++ /dev/null @@ -1,115 +0,0 @@ ---- -title: Multi Receipts Detector OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-multi-receipts-detector-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Multi Receipts Detector API](https://platform.mindee.com/mindee/multi_receipts_detector). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/multi_receipts_detector/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Multi Receipts Detector sample](https://github.com/mindee/client-lib-test-data/blob/main/products/multi_receipts_detector/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.MultiReceiptsDetectorV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: d7c5b25f-e0d3-4491-af54-6183afa1aaab -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/multi_receipts_detector v1.0 -:Rotation applied: Yes - -Prediction -========== -:List of Receipts: Polygon with 4 points. - Polygon with 4 points. - Polygon with 4 points. - Polygon with 4 points. - Polygon with 4 points. - Polygon with 4 points. - -Page Predictions -================ - -Page 0 ------- -:List of Receipts: Polygon with 4 points. - Polygon with 4 points. - Polygon with 4 points. - Polygon with 4 points. - Polygon with 4 points. - Polygon with 4 points. -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### Position Field -The position field `PositionField` does not implement all the basic `Field` attributes, only **boundingBox**, **polygon** and **pageId**. On top of these, it has access to: - -* **rectangle** (`[Point, Point, Point, Point]`): a Polygon with four points that may be oriented (even beyond canvas). -* **quadrangle** (`[Point, Point, Point, Point]`): a free polygon made up of four points. - -# Attributes -The following fields are extracted for Multi Receipts Detector V1: - -## List of Receipts -**receipts** ([PositionField](#position-field)[]): Positions of the receipts on the document. - -```js -for (const receiptsElem of result.document.inference.prediction.receipts) { - console.log(receiptsElem.polygon); - console.log(receiptsElem.quadrangle); - console.log(receiptsElem.rectangle); - console.log(receiptsElem.boundingBox); -} -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/nutrition_facts_v1.md b/docs/nutrition_facts_v1.md deleted file mode 100644 index 15c6a6571..000000000 --- a/docs/nutrition_facts_v1.md +++ /dev/null @@ -1,377 +0,0 @@ ---- -title: Nutrition Facts Label OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-nutrition-facts-label-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Nutrition Facts Label API](https://platform.mindee.com/mindee/nutrition_facts). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/nutrition_facts/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Nutrition Facts Label sample](https://github.com/mindee/client-lib-test-data/blob/main/products/nutrition_facts/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.NutritionFactsLabelV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 38a12fe0-5d69-4ca4-9b30-12f1b659311c -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/nutrition_facts v1.0 -:Rotation applied: No - -Prediction -========== -:Serving per Box: 2.00 -:Serving Size: - :Amount: 228.00 - :Unit: g -:Calories: - :Daily Value: - :Per 100g: - :Per Serving: 250.00 -:Total Fat: - :Daily Value: - :Per 100g: - :Per Serving: 12.00 -:Saturated Fat: - :Daily Value: 15.00 - :Per 100g: - :Per Serving: 3.00 -:Trans Fat: - :Daily Value: - :Per 100g: - :Per Serving: 3.00 -:Cholesterol: - :Daily Value: 10.00 - :Per 100g: - :Per Serving: 30.00 -:Total Carbohydrate: - :Daily Value: 10.00 - :Per 100g: - :Per Serving: 31.00 -:Dietary Fiber: - :Daily Value: 0.00 - :Per 100g: - :Per Serving: 0.00 -:Total Sugars: - :Daily Value: - :Per 100g: - :Per Serving: 5.00 -:Added Sugars: - :Daily Value: - :Per 100g: - :Per Serving: -:Protein: - :Daily Value: - :Per 100g: - :Per Serving: 5.00 -:sodium: - :Daily Value: 20.00 - :Per 100g: - :Per Serving: 470.00 - :Unit: mg -:nutrients: - +-------------+----------------------+----------+-------------+------+ - | Daily Value | Name | Per 100g | Per Serving | Unit | - +=============+======================+==========+=============+======+ - | 12.00 | Vitamin A | | 4.00 | mcg | - +-------------+----------------------+----------+-------------+------+ - | 12.00 | Vitamin C | | 2.00 | mg | - +-------------+----------------------+----------+-------------+------+ - | 12.00 | Calcium | | 45.60 | mg | - +-------------+----------------------+----------+-------------+------+ - | 12.00 | Iron | | 0.90 | mg | - +-------------+----------------------+----------+-------------+------+ -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### Amount Field -The amount field `AmountField` only has one constraint: its **value** is a `number` (or `undefined`). - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Added Sugars Field -The amount of added sugars in the product. - -A `NutritionFactsLabelV1AddedSugar` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of added sugars to consume or not to exceed each day. -* `per100G` (number): The amount of added sugars per 100g of the product. -* `perServing` (number): The amount of added sugars per serving of the product. -Fields which are specific to this product; they are not used in any other product. - -### Calories Field -The amount of calories in the product. - -A `NutritionFactsLabelV1Calorie` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of calories to consume or not to exceed each day. -* `per100G` (number): The amount of calories per 100g of the product. -* `perServing` (number): The amount of calories per serving of the product. -Fields which are specific to this product; they are not used in any other product. - -### Cholesterol Field -The amount of cholesterol in the product. - -A `NutritionFactsLabelV1Cholesterol` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of cholesterol to consume or not to exceed each day. -* `per100G` (number): The amount of cholesterol per 100g of the product. -* `perServing` (number): The amount of cholesterol per serving of the product. -Fields which are specific to this product; they are not used in any other product. - -### Dietary Fiber Field -The amount of dietary fiber in the product. - -A `NutritionFactsLabelV1DietaryFiber` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of dietary fiber to consume or not to exceed each day. -* `per100G` (number): The amount of dietary fiber per 100g of the product. -* `perServing` (number): The amount of dietary fiber per serving of the product. -Fields which are specific to this product; they are not used in any other product. - -### nutrients Field -The amount of nutrients in the product. - -A `NutritionFactsLabelV1Nutrient` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of nutrients to consume or not to exceed each day. -* `name` (string): The name of nutrients of the product. -* `per100G` (number): The amount of nutrients per 100g of the product. -* `perServing` (number): The amount of nutrients per serving of the product. -* `unit` (string): The unit of measurement for the amount of nutrients. -Fields which are specific to this product; they are not used in any other product. - -### Protein Field -The amount of protein in the product. - -A `NutritionFactsLabelV1Protein` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of protein to consume or not to exceed each day. -* `per100G` (number): The amount of protein per 100g of the product. -* `perServing` (number): The amount of protein per serving of the product. -Fields which are specific to this product; they are not used in any other product. - -### Saturated Fat Field -The amount of saturated fat in the product. - -A `NutritionFactsLabelV1SaturatedFat` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of saturated fat to consume or not to exceed each day. -* `per100G` (number): The amount of saturated fat per 100g of the product. -* `perServing` (number): The amount of saturated fat per serving of the product. -Fields which are specific to this product; they are not used in any other product. - -### Serving Size Field -The size of a single serving of the product. - -A `NutritionFactsLabelV1ServingSize` implements the following attributes: - -* `amount` (number): The amount of a single serving. -* `unit` (string): The unit for the amount of a single serving. -Fields which are specific to this product; they are not used in any other product. - -### sodium Field -The amount of sodium in the product. - -A `NutritionFactsLabelV1Sodium` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of sodium to consume or not to exceed each day. -* `per100G` (number): The amount of sodium per 100g of the product. -* `perServing` (number): The amount of sodium per serving of the product. -* `unit` (string): The unit of measurement for the amount of sodium. -Fields which are specific to this product; they are not used in any other product. - -### Total Carbohydrate Field -The total amount of carbohydrates in the product. - -A `NutritionFactsLabelV1TotalCarbohydrate` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of total carbohydrates to consume or not to exceed each day. -* `per100G` (number): The amount of total carbohydrates per 100g of the product. -* `perServing` (number): The amount of total carbohydrates per serving of the product. -Fields which are specific to this product; they are not used in any other product. - -### Total Fat Field -The total amount of fat in the product. - -A `NutritionFactsLabelV1TotalFat` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of total fat to consume or not to exceed each day. -* `per100G` (number): The amount of total fat per 100g of the product. -* `perServing` (number): The amount of total fat per serving of the product. -Fields which are specific to this product; they are not used in any other product. - -### Total Sugars Field -The total amount of sugars in the product. - -A `NutritionFactsLabelV1TotalSugar` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of total sugars to consume or not to exceed each day. -* `per100G` (number): The amount of total sugars per 100g of the product. -* `perServing` (number): The amount of total sugars per serving of the product. -Fields which are specific to this product; they are not used in any other product. - -### Trans Fat Field -The amount of trans fat in the product. - -A `NutritionFactsLabelV1TransFat` implements the following attributes: - -* `dailyValue` (number): DVs are the recommended amounts of trans fat to consume or not to exceed each day. -* `per100G` (number): The amount of trans fat per 100g of the product. -* `perServing` (number): The amount of trans fat per serving of the product. - -# Attributes -The following fields are extracted for Nutrition Facts Label V1: - -## Added Sugars -**addedSugars** ([NutritionFactsLabelV1AddedSugar](#added-sugars-field)): The amount of added sugars in the product. - -```js -console.log(result.document.inference.prediction.addedSugars.value); -``` - -## Calories -**calories** ([NutritionFactsLabelV1Calorie](#calories-field)): The amount of calories in the product. - -```js -console.log(result.document.inference.prediction.calories.value); -``` - -## Cholesterol -**cholesterol** ([NutritionFactsLabelV1Cholesterol](#cholesterol-field)): The amount of cholesterol in the product. - -```js -console.log(result.document.inference.prediction.cholesterol.value); -``` - -## Dietary Fiber -**dietaryFiber** ([NutritionFactsLabelV1DietaryFiber](#dietary-fiber-field)): The amount of dietary fiber in the product. - -```js -console.log(result.document.inference.prediction.dietaryFiber.value); -``` - -## nutrients -**nutrients** ([NutritionFactsLabelV1Nutrient](#nutrients-field)[]): The amount of nutrients in the product. - -```js -for (const nutrientsElem of result.document.inference.prediction.nutrients) { - console.log(nutrientsElem.value); -} -``` - -## Protein -**protein** ([NutritionFactsLabelV1Protein](#protein-field)): The amount of protein in the product. - -```js -console.log(result.document.inference.prediction.protein.value); -``` - -## Saturated Fat -**saturatedFat** ([NutritionFactsLabelV1SaturatedFat](#saturated-fat-field)): The amount of saturated fat in the product. - -```js -console.log(result.document.inference.prediction.saturatedFat.value); -``` - -## Serving per Box -**servingPerBox** ([AmountField](#amount-field)): The number of servings in each box of the product. - -```js -console.log(result.document.inference.prediction.servingPerBox.value); -``` - -## Serving Size -**servingSize** ([NutritionFactsLabelV1ServingSize](#serving-size-field)): The size of a single serving of the product. - -```js -console.log(result.document.inference.prediction.servingSize.value); -``` - -## sodium -**sodium** ([NutritionFactsLabelV1Sodium](#sodium-field)): The amount of sodium in the product. - -```js -console.log(result.document.inference.prediction.sodium.value); -``` - -## Total Carbohydrate -**totalCarbohydrate** ([NutritionFactsLabelV1TotalCarbohydrate](#total-carbohydrate-field)): The total amount of carbohydrates in the product. - -```js -console.log(result.document.inference.prediction.totalCarbohydrate.value); -``` - -## Total Fat -**totalFat** ([NutritionFactsLabelV1TotalFat](#total-fat-field)): The total amount of fat in the product. - -```js -console.log(result.document.inference.prediction.totalFat.value); -``` - -## Total Sugars -**totalSugars** ([NutritionFactsLabelV1TotalSugar](#total-sugars-field)): The total amount of sugars in the product. - -```js -console.log(result.document.inference.prediction.totalSugars.value); -``` - -## Trans Fat -**transFat** ([NutritionFactsLabelV1TransFat](#trans-fat-field)): The amount of trans fat in the product. - -```js -console.log(result.document.inference.prediction.transFat.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/passport_v1.md b/docs/passport_v1.md deleted file mode 100644 index 40290c0ae..000000000 --- a/docs/passport_v1.md +++ /dev/null @@ -1,193 +0,0 @@ ---- -title: Passport OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-passport-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Passport API](https://platform.mindee.com/mindee/passport). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/passport/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Passport sample](https://github.com/mindee/client-lib-test-data/blob/main/products/passport/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.parse( - mindee.product.PassportV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 18e41f6c-16cd-4f8e-8cd2-00ca02a35764 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/passport v1.0 -:Rotation applied: Yes - -Prediction -========== -:Country Code: GBR -:ID Number: 707797979 -:Given Name(s): HENERT -:Surname: PUDARSAN -:Date of Birth: 1995-05-20 -:Place of Birth: CAMTETH -:Gender: M -:Date of Issue: 2012-04-22 -:Expiry Date: 2017-04-22 -:MRZ Line 1: P **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -# Attributes -The following fields are extracted for Passport V1: - -## Date of Birth -**birthDate** ([DateField](#date-field)): The date of birth of the passport holder. - -```js -console.log(result.document.inference.prediction.birthDate.value); -``` - -## Place of Birth -**birthPlace** ([StringField](#string-field)): The place of birth of the passport holder. - -```js -console.log(result.document.inference.prediction.birthPlace.value); -``` - -## Country Code -**country** ([StringField](#string-field)): The country's 3 letter code (ISO 3166-1 alpha-3). - -```js -console.log(result.document.inference.prediction.country.value); -``` - -## Expiry Date -**expiryDate** ([DateField](#date-field)): The expiry date of the passport. - -```js -console.log(result.document.inference.prediction.expiryDate.value); -``` - -## Gender -**gender** ([StringField](#string-field)): The gender of the passport holder. - -```js -console.log(result.document.inference.prediction.gender.value); -``` - -## Given Name(s) -**givenNames** ([StringField](#string-field)[]): The given name(s) of the passport holder. - -```js -for (const givenNamesElem of result.document.inference.prediction.givenNames) { - console.log(givenNamesElem.value); -} -``` - -## ID Number -**idNumber** ([StringField](#string-field)): The passport's identification number. - -```js -console.log(result.document.inference.prediction.idNumber.value); -``` - -## Date of Issue -**issuanceDate** ([DateField](#date-field)): The date the passport was issued. - -```js -console.log(result.document.inference.prediction.issuanceDate.value); -``` - -## MRZ Line 1 -**mrz1** ([StringField](#string-field)): Machine Readable Zone, first line - -```js -console.log(result.document.inference.prediction.mrz1.value); -``` - -## MRZ Line 2 -**mrz2** ([StringField](#string-field)): Machine Readable Zone, second line - -```js -console.log(result.document.inference.prediction.mrz2.value); -``` - -## Surname -**surname** ([StringField](#string-field)): The surname of the passport holder. - -```js -console.log(result.document.inference.prediction.surname.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/payslip_fra_v2.md b/docs/payslip_fra_v2.md deleted file mode 100644 index ed2ae86b2..000000000 --- a/docs/payslip_fra_v2.md +++ /dev/null @@ -1,297 +0,0 @@ ---- -title: FR Payslip OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-fr-payslip-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Payslip API](https://platform.mindee.com/mindee/payslip_fra). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Payslip sample](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.fr.PayslipV2, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 972edba5-25aa-49d0-8431-e2557ddd788e -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/payslip_fra v2.0 -:Rotation applied: No - -Prediction -========== -:Employee: - :Address: 52 RUE DES FLEURS 33500 LIBOURNE FRANCE - :Date of Birth: - :First Name: Jean Luc - :Last Name: Picard - :Phone Number: - :Registration Number: - :Social Security Number: 123456789012345 -:Employer: - :Address: 1 RUE DU TONNOT 25210 DOUBS - :Company ID: 12345678901234 - :Company Site: - :NAF Code: 1234A - :Name: DEMO COMPANY - :Phone Number: - :URSSAF Number: -:Bank Account Details: - :Bank Name: - :IBAN: - :SWIFT: -:Employment: - :Category: Cadre - :Coefficient: 600.00 - :Collective Agreement: Construction -- Promotion - :Job Title: Directeur Rรฉgional du Dรฉveloppement - :Position Level: - :Start Date: 2022-05-01 -:Salary Details: - +--------------+-----------+--------------------------------------+-----------+ - | Amount | Base | Description | Rate | - +==============+===========+======================================+===========+ - | 6666.67 | | Salaire de base | | - +--------------+-----------+--------------------------------------+-----------+ - | 9.30 | | Part patronale Mutuelle NR | | - +--------------+-----------+--------------------------------------+-----------+ - | 508.30 | | Avantages en nature voiture | | - +--------------+-----------+--------------------------------------+-----------+ -:Pay Detail: - :Gross Salary: 7184.27 - :Gross Salary YTD: 18074.81 - :Income Tax Rate: 17.60 - :Income Tax Withheld: 1030.99 - :Net Paid: 3868.32 - :Net Paid Before Tax: 4899.31 - :Net Taxable: 5857.90 - :Net Taxable YTD: 14752.73 - :Total Cost Employer: 10486.94 - :Total Taxes and Deductions: 1650.36 -:PTO: - :Accrued This Period: 6.17 - :Balance End of Period: 6.17 - :Used This Period: -:Pay Period: - :End Date: 2023-03-31 - :Month: 03 - :Payment Date: 2023-03-29 - :Start Date: 2023-03-01 - :Year: 2023 -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Bank Account Details Field -Information about the employee's bank account. - -A `PayslipV2BankAccountDetail` implements the following attributes: - -* `bankName` (string): The name of the bank. -* `iban` (string): The IBAN of the bank account. -* `swift` (string): The SWIFT code of the bank. -Fields which are specific to this product; they are not used in any other product. - -### Employee Field -Information about the employee. - -A `PayslipV2Employee` implements the following attributes: - -* `address` (string): The address of the employee. -* `dateOfBirth` (string): The date of birth of the employee. -* `firstName` (string): The first name of the employee. -* `lastName` (string): The last name of the employee. -* `phoneNumber` (string): The phone number of the employee. -* `registrationNumber` (string): The registration number of the employee. -* `socialSecurityNumber` (string): The social security number of the employee. -Fields which are specific to this product; they are not used in any other product. - -### Employer Field -Information about the employer. - -A `PayslipV2Employer` implements the following attributes: - -* `address` (string): The address of the employer. -* `companyId` (string): The company ID of the employer. -* `companySite` (string): The site of the company. -* `nafCode` (string): The NAF code of the employer. -* `name` (string): The name of the employer. -* `phoneNumber` (string): The phone number of the employer. -* `urssafNumber` (string): The URSSAF number of the employer. -Fields which are specific to this product; they are not used in any other product. - -### Employment Field -Information about the employment. - -A `PayslipV2Employment` implements the following attributes: - -* `category` (string): The category of the employment. -* `coefficient` (number): The coefficient of the employment. -* `collectiveAgreement` (string): The collective agreement of the employment. -* `jobTitle` (string): The job title of the employee. -* `positionLevel` (string): The position level of the employment. -* `startDate` (string): The start date of the employment. -Fields which are specific to this product; they are not used in any other product. - -### Pay Detail Field -Detailed information about the pay. - -A `PayslipV2PayDetail` implements the following attributes: - -* `grossSalary` (number): The gross salary of the employee. -* `grossSalaryYtd` (number): The year-to-date gross salary of the employee. -* `incomeTaxRate` (number): The income tax rate of the employee. -* `incomeTaxWithheld` (number): The income tax withheld from the employee's pay. -* `netPaid` (number): The net paid amount of the employee. -* `netPaidBeforeTax` (number): The net paid amount before tax of the employee. -* `netTaxable` (number): The net taxable amount of the employee. -* `netTaxableYtd` (number): The year-to-date net taxable amount of the employee. -* `totalCostEmployer` (number): The total cost to the employer. -* `totalTaxesAndDeductions` (number): The total taxes and deductions of the employee. -Fields which are specific to this product; they are not used in any other product. - -### Pay Period Field -Information about the pay period. - -A `PayslipV2PayPeriod` implements the following attributes: - -* `endDate` (string): The end date of the pay period. -* `month` (string): The month of the pay period. -* `paymentDate` (string): The date of payment for the pay period. -* `startDate` (string): The start date of the pay period. -* `year` (string): The year of the pay period. -Fields which are specific to this product; they are not used in any other product. - -### PTO Field -Information about paid time off. - -A `PayslipV2Pto` implements the following attributes: - -* `accruedThisPeriod` (number): The amount of paid time off accrued in this period. -* `balanceEndOfPeriod` (number): The balance of paid time off at the end of the period. -* `usedThisPeriod` (number): The amount of paid time off used in this period. -Fields which are specific to this product; they are not used in any other product. - -### Salary Details Field -Detailed information about the earnings. - -A `PayslipV2SalaryDetail` implements the following attributes: - -* `amount` (number): The amount of the earnings. -* `base` (number): The base value of the earnings. -* `description` (string): The description of the earnings. -* `rate` (number): The rate of the earnings. - -# Attributes -The following fields are extracted for Payslip V2: - -## Bank Account Details -**bankAccountDetails** ([PayslipV2BankAccountDetail](#bank-account-details-field)): Information about the employee's bank account. - -```js -console.log(result.document.inference.prediction.bankAccountDetails.value); -``` - -## Employee -**employee** ([PayslipV2Employee](#employee-field)): Information about the employee. - -```js -console.log(result.document.inference.prediction.employee.value); -``` - -## Employer -**employer** ([PayslipV2Employer](#employer-field)): Information about the employer. - -```js -console.log(result.document.inference.prediction.employer.value); -``` - -## Employment -**employment** ([PayslipV2Employment](#employment-field)): Information about the employment. - -```js -console.log(result.document.inference.prediction.employment.value); -``` - -## Pay Detail -**payDetail** ([PayslipV2PayDetail](#pay-detail-field)): Detailed information about the pay. - -```js -console.log(result.document.inference.prediction.payDetail.value); -``` - -## Pay Period -**payPeriod** ([PayslipV2PayPeriod](#pay-period-field)): Information about the pay period. - -```js -console.log(result.document.inference.prediction.payPeriod.value); -``` - -## PTO -**pto** ([PayslipV2Pto](#pto-field)): Information about paid time off. - -```js -console.log(result.document.inference.prediction.pto.value); -``` - -## Salary Details -**salaryDetails** ([PayslipV2SalaryDetail](#salary-details-field)[]): Detailed information about the earnings. - -```js -for (const salaryDetailsElem of result.document.inference.prediction.salaryDetails) { - console.log(salaryDetailsElem.value); -} -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/payslip_fra_v3.md b/docs/payslip_fra_v3.md deleted file mode 100644 index 7a92873b2..000000000 --- a/docs/payslip_fra_v3.md +++ /dev/null @@ -1,322 +0,0 @@ ---- -title: FR Payslip OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-fr-payslip-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Payslip API](https://platform.mindee.com/mindee/payslip_fra). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Payslip sample](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.fr.PayslipV3, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: a479e3e7-6838-4e82-9a7d-99289f34ec7f -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/payslip_fra v3.0 -:Rotation applied: Yes - -Prediction -========== -:Pay Period: - :End Date: 2023-03-31 - :Month: 03 - :Payment Date: 2023-03-29 - :Start Date: 2023-03-01 - :Year: 2023 -:Employee: - :Address: 52 RUE DES FLEURS 33500 LIBOURNE FRANCE - :Date of Birth: - :First Name: Jean Luc - :Last Name: Picard - :Phone Number: - :Registration Number: - :Social Security Number: 123456789012345 -:Employer: - :Address: 1 RUE DU TONNOT 25210 DOUBS - :Company ID: 12345678901234 - :Company Site: - :NAF Code: 1234A - :Name: DEMO COMPANY - :Phone Number: - :URSSAF Number: -:Bank Account Details: - :Bank Name: - :IBAN: - :SWIFT: -:Employment: - :Category: Cadre - :Coefficient: 600,000 - :Collective Agreement: Construction -- Promotion - :Job Title: Directeur Rรฉgional du Dรฉveloppement - :Position Level: Niveau 5 Echelon 3 - :Seniority Date: - :Start Date: 2022-05-01 -:Salary Details: - +--------------+-----------+--------------------------------------+--------+-----------+ - | Amount | Base | Description | Number | Rate | - +==============+===========+======================================+========+===========+ - | 6666.67 | | Salaire de base | | | - +--------------+-----------+--------------------------------------+--------+-----------+ - | 9.30 | | Part patronale Mutuelle NR | | | - +--------------+-----------+--------------------------------------+--------+-----------+ - | 508.30 | | Avantages en nature voiture | | | - +--------------+-----------+--------------------------------------+--------+-----------+ -:Pay Detail: - :Gross Salary: 7184.27 - :Gross Salary YTD: 18074.81 - :Income Tax Rate: 17.60 - :Income Tax Withheld: 1030.99 - :Net Paid: 3868.32 - :Net Paid Before Tax: 4899.31 - :Net Taxable: 5857.90 - :Net Taxable YTD: 14752.73 - :Total Cost Employer: 10486.94 - :Total Taxes and Deductions: 1650.36 -:Paid Time Off: - +-----------+--------+-------------+-----------+-----------+ - | Accrued | Period | Type | Remaining | Used | - +===========+========+=============+===========+===========+ - | | N-1 | VACATION | | | - +-----------+--------+-------------+-----------+-----------+ - | 6.17 | N | VACATION | 6.17 | | - +-----------+--------+-------------+-----------+-----------+ - | 2.01 | N | RTT | 2.01 | | - +-----------+--------+-------------+-----------+-----------+ -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Bank Account Details Field -Information about the employee's bank account. - -A `PayslipV3BankAccountDetail` implements the following attributes: - -* `bankName` (string): The name of the bank. -* `iban` (string): The IBAN of the bank account. -* `swift` (string): The SWIFT code of the bank. -Fields which are specific to this product; they are not used in any other product. - -### Employee Field -Information about the employee. - -A `PayslipV3Employee` implements the following attributes: - -* `address` (string): The address of the employee. -* `dateOfBirth` (string): The date of birth of the employee. -* `firstName` (string): The first name of the employee. -* `lastName` (string): The last name of the employee. -* `phoneNumber` (string): The phone number of the employee. -* `registrationNumber` (string): The registration number of the employee. -* `socialSecurityNumber` (string): The social security number of the employee. -Fields which are specific to this product; they are not used in any other product. - -### Employer Field -Information about the employer. - -A `PayslipV3Employer` implements the following attributes: - -* `address` (string): The address of the employer. -* `companyId` (string): The company ID of the employer. -* `companySite` (string): The site of the company. -* `nafCode` (string): The NAF code of the employer. -* `name` (string): The name of the employer. -* `phoneNumber` (string): The phone number of the employer. -* `urssafNumber` (string): The URSSAF number of the employer. -Fields which are specific to this product; they are not used in any other product. - -### Employment Field -Information about the employment. - -A `PayslipV3Employment` implements the following attributes: - -* `category` (string): The category of the employment. -* `coefficient` (string): The coefficient of the employment. -* `collectiveAgreement` (string): The collective agreement of the employment. -* `jobTitle` (string): The job title of the employee. -* `positionLevel` (string): The position level of the employment. -* `seniorityDate` (string): The seniority date of the employment. -* `startDate` (string): The start date of the employment. -Fields which are specific to this product; they are not used in any other product. - -### Paid Time Off Field -Information about paid time off. - -A `PayslipV3PaidTimeOff` implements the following attributes: - -* `accrued` (number): The amount of paid time off accrued in the period. -* `period` (string): The paid time off period. - -#### Possible values include: - - N - - N-1 - - N-2 - -* `ptoType` (string): The type of paid time off. - -#### Possible values include: - - VACATION - - RTT - - COMPENSATORY - -* `remaining` (number): The remaining amount of paid time off at the end of the period. -* `used` (number): The amount of paid time off used in the period. -Fields which are specific to this product; they are not used in any other product. - -### Pay Detail Field -Detailed information about the pay. - -A `PayslipV3PayDetail` implements the following attributes: - -* `grossSalary` (number): The gross salary of the employee. -* `grossSalaryYtd` (number): The year-to-date gross salary of the employee. -* `incomeTaxRate` (number): The income tax rate of the employee. -* `incomeTaxWithheld` (number): The income tax withheld from the employee's pay. -* `netPaid` (number): The net paid amount of the employee. -* `netPaidBeforeTax` (number): The net paid amount before tax of the employee. -* `netTaxable` (number): The net taxable amount of the employee. -* `netTaxableYtd` (number): The year-to-date net taxable amount of the employee. -* `totalCostEmployer` (number): The total cost to the employer. -* `totalTaxesAndDeductions` (number): The total taxes and deductions of the employee. -Fields which are specific to this product; they are not used in any other product. - -### Pay Period Field -Information about the pay period. - -A `PayslipV3PayPeriod` implements the following attributes: - -* `endDate` (string): The end date of the pay period. -* `month` (string): The month of the pay period. -* `paymentDate` (string): The date of payment for the pay period. -* `startDate` (string): The start date of the pay period. -* `year` (string): The year of the pay period. -Fields which are specific to this product; they are not used in any other product. - -### Salary Details Field -Detailed information about the earnings. - -A `PayslipV3SalaryDetail` implements the following attributes: - -* `amount` (number): The amount of the earning. -* `base` (number): The base rate value of the earning. -* `description` (string): The description of the earnings. -* `number` (number): The number of units in the earning. -* `rate` (number): The rate of the earning. - -# Attributes -The following fields are extracted for Payslip V3: - -## Bank Account Details -**bankAccountDetails** ([PayslipV3BankAccountDetail](#bank-account-details-field)): Information about the employee's bank account. - -```js -console.log(result.document.inference.prediction.bankAccountDetails.value); -``` - -## Employee -**employee** ([PayslipV3Employee](#employee-field)): Information about the employee. - -```js -console.log(result.document.inference.prediction.employee.value); -``` - -## Employer -**employer** ([PayslipV3Employer](#employer-field)): Information about the employer. - -```js -console.log(result.document.inference.prediction.employer.value); -``` - -## Employment -**employment** ([PayslipV3Employment](#employment-field)): Information about the employment. - -```js -console.log(result.document.inference.prediction.employment.value); -``` - -## Paid Time Off -**paidTimeOff** ([PayslipV3PaidTimeOff](#paid-time-off-field)[]): Information about paid time off. - -```js -for (const paidTimeOffElem of result.document.inference.prediction.paidTimeOff) { - console.log(paidTimeOffElem.value); -} -``` - -## Pay Detail -**payDetail** ([PayslipV3PayDetail](#pay-detail-field)): Detailed information about the pay. - -```js -console.log(result.document.inference.prediction.payDetail.value); -``` - -## Pay Period -**payPeriod** ([PayslipV3PayPeriod](#pay-period-field)): Information about the pay period. - -```js -console.log(result.document.inference.prediction.payPeriod.value); -``` - -## Salary Details -**salaryDetails** ([PayslipV3SalaryDetail](#salary-details-field)[]): Detailed information about the earnings. - -```js -for (const salaryDetailsElem of result.document.inference.prediction.salaryDetails) { - console.log(salaryDetailsElem.value); -} -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/resume_v1.md b/docs/resume_v1.md deleted file mode 100644 index 1975770fc..000000000 --- a/docs/resume_v1.md +++ /dev/null @@ -1,361 +0,0 @@ ---- -title: Resume OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-resume-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Resume API](https://platform.mindee.com/mindee/resume). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/resume/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Resume sample](https://github.com/mindee/client-lib-test-data/blob/main/products/resume/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.ResumeV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 9daa3085-152c-454e-9245-636f13fc9dc3 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/resume v1.1 -:Rotation applied: Yes - -Prediction -========== -:Document Language: ENG -:Document Type: RESUME -:Given Names: Christopher -:Surnames: Morgan -:Nationality: -:Email Address: christoper.m@gmail.com -:Phone Number: +44 (0)20 7666 8555 -:Address: 177 Great Portland Street, London, W5W 6PQ -:Social Networks: - +----------------------+----------------------------------------------------+ - | Name | URL | - +======================+====================================================+ - | LinkedIn | linkedin.com/christopher.morgan | - +----------------------+----------------------------------------------------+ -:Profession: Senior Web Developer -:Job Applied: -:Languages: - +----------+----------------------+ - | Language | Level | - +==========+======================+ - | SPA | Fluent | - +----------+----------------------+ - | ZHO | Beginner | - +----------+----------------------+ - | DEU | Beginner | - +----------+----------------------+ -:Hard Skills: HTML5 - PHP OOP - JavaScript - CSS - MySQL - SQL -:Soft Skills: Project management - Creative design - Strong decision maker - Innovative - Complex problem solver - Service-focused -:Education: - +-----------------+---------------------------+-----------+----------+---------------------------+-------------+------------+ - | Domain | Degree | End Month | End Year | School | Start Month | Start Year | - +=================+===========================+===========+==========+===========================+=============+============+ - | Computer Inf... | Bachelor | | 2014 | Columbia University, NY | | | - +-----------------+---------------------------+-----------+----------+---------------------------+-------------+------------+ -:Professional Experiences: - +-----------------+------------+--------------------------------------+---------------------------+-----------+----------+----------------------+-------------+------------+ - | Contract Type | Department | Description | Employer | End Month | End Year | Role | Start Month | Start Year | - +=================+============+======================================+===========================+===========+==========+======================+=============+============+ - | | | Cooperate with designers to creat... | Luna Web Design, New York | 05 | 2019 | Web Developer | 09 | 2015 | - +-----------------+------------+--------------------------------------+---------------------------+-----------+----------+----------------------+-------------+------------+ -:Certificates: - +------------+--------------------------------+---------------------------+------+ - | Grade | Name | Provider | Year | - +============+================================+===========================+======+ - | | PHP Framework (certificate)... | | | - +------------+--------------------------------+---------------------------+------+ -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - - -### Classification Field -The classification field `ClassificationField` does not implement all the basic `Field` attributes. It only implements **value**, **confidence** and **pageId**. - -> Note: a classification field's `value is always a `string`. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Certificates Field -The list of certificates obtained by the candidate. - -A `ResumeV1Certificate` implements the following attributes: - -* `grade` (string): The grade obtained for the certificate. -* `name` (string): The name of certification. -* `provider` (string): The organization or institution that issued the certificate. -* `year` (string): The year when a certificate was issued or received. -Fields which are specific to this product; they are not used in any other product. - -### Education Field -The list of the candidate's educational background. - -A `ResumeV1Education` implements the following attributes: - -* `degreeDomain` (string): The area of study or specialization. -* `degreeType` (string): The type of degree obtained, such as Bachelor's, Master's, or Doctorate. -* `endMonth` (string): The month when the education program or course was completed. -* `endYear` (string): The year when the education program or course was completed. -* `school` (string): The name of the school. -* `startMonth` (string): The month when the education program or course began. -* `startYear` (string): The year when the education program or course began. -Fields which are specific to this product; they are not used in any other product. - -### Languages Field -The list of languages that the candidate is proficient in. - -A `ResumeV1Language` implements the following attributes: - -* `language` (string): The language's ISO 639 code. -* `level` (string): The candidate's level for the language. - -#### Possible values include: - - Native - - Fluent - - Proficient - - Intermediate - - Beginner - -Fields which are specific to this product; they are not used in any other product. - -### Professional Experiences Field -The list of the candidate's professional experiences. - -A `ResumeV1ProfessionalExperience` implements the following attributes: - -* `contractType` (string): The type of contract for the professional experience. - -#### Possible values include: - - Full-Time - - Part-Time - - Internship - - Freelance - -* `department` (string): The specific department or division within the company. -* `description` (string): The description of the professional experience as written in the document. -* `employer` (string): The name of the company or organization. -* `endMonth` (string): The month when the professional experience ended. -* `endYear` (string): The year when the professional experience ended. -* `role` (string): The position or job title held by the candidate. -* `startMonth` (string): The month when the professional experience began. -* `startYear` (string): The year when the professional experience began. -Fields which are specific to this product; they are not used in any other product. - -### Social Networks Field -The list of social network profiles of the candidate. - -A `ResumeV1SocialNetworksUrl` implements the following attributes: - -* `name` (string): The name of the social network. -* `url` (string): The URL of the social network. - -# Attributes -The following fields are extracted for Resume V1: - -## Address -**address** ([StringField](#string-field)): The location information of the candidate, including city, state, and country. - -```js -console.log(result.document.inference.prediction.address.value); -``` - -## Certificates -**certificates** ([ResumeV1Certificate](#certificates-field)[]): The list of certificates obtained by the candidate. - -```js -for (const certificatesElem of result.document.inference.prediction.certificates) { - console.log(certificatesElem.value); -} -``` - -## Document Language -**documentLanguage** ([StringField](#string-field)): The ISO 639 code of the language in which the document is written. - -```js -console.log(result.document.inference.prediction.documentLanguage.value); -``` - -## Document Type -**documentType** ([ClassificationField](#classification-field)): The type of the document sent. - -#### Possible values include: - - 'RESUME' - - 'MOTIVATION_LETTER' - - 'RECOMMENDATION_LETTER' - -```js -console.log(result.document.inference.prediction.documentType.value); -``` - -## Education -**education** ([ResumeV1Education](#education-field)[]): The list of the candidate's educational background. - -```js -for (const educationElem of result.document.inference.prediction.education) { - console.log(educationElem.value); -} -``` - -## Email Address -**emailAddress** ([StringField](#string-field)): The email address of the candidate. - -```js -console.log(result.document.inference.prediction.emailAddress.value); -``` - -## Given Names -**givenNames** ([StringField](#string-field)[]): The candidate's first or given names. - -```js -for (const givenNamesElem of result.document.inference.prediction.givenNames) { - console.log(givenNamesElem.value); -} -``` - -## Hard Skills -**hardSkills** ([StringField](#string-field)[]): The list of the candidate's technical abilities and knowledge. - -```js -for (const hardSkillsElem of result.document.inference.prediction.hardSkills) { - console.log(hardSkillsElem.value); -} -``` - -## Job Applied -**jobApplied** ([StringField](#string-field)): The position that the candidate is applying for. - -```js -console.log(result.document.inference.prediction.jobApplied.value); -``` - -## Languages -**languages** ([ResumeV1Language](#languages-field)[]): The list of languages that the candidate is proficient in. - -```js -for (const languagesElem of result.document.inference.prediction.languages) { - console.log(languagesElem.value); -} -``` - -## Nationality -**nationality** ([StringField](#string-field)): The ISO 3166 code for the country of citizenship of the candidate. - -```js -console.log(result.document.inference.prediction.nationality.value); -``` - -## Phone Number -**phoneNumber** ([StringField](#string-field)): The phone number of the candidate. - -```js -console.log(result.document.inference.prediction.phoneNumber.value); -``` - -## Profession -**profession** ([StringField](#string-field)): The candidate's current profession. - -```js -console.log(result.document.inference.prediction.profession.value); -``` - -## Professional Experiences -**professionalExperiences** ([ResumeV1ProfessionalExperience](#professional-experiences-field)[]): The list of the candidate's professional experiences. - -```js -for (const professionalExperiencesElem of result.document.inference.prediction.professionalExperiences) { - console.log(professionalExperiencesElem.value); -} -``` - -## Social Networks -**socialNetworksUrls** ([ResumeV1SocialNetworksUrl](#social-networks-field)[]): The list of social network profiles of the candidate. - -```js -for (const socialNetworksUrlsElem of result.document.inference.prediction.socialNetworksUrls) { - console.log(socialNetworksUrlsElem.value); -} -``` - -## Soft Skills -**softSkills** ([StringField](#string-field)[]): The list of the candidate's interpersonal and communication abilities. - -```js -for (const softSkillsElem of result.document.inference.prediction.softSkills) { - console.log(softSkillsElem.value); -} -``` - -## Surnames -**surnames** ([StringField](#string-field)[]): The candidate's last names. - -```js -for (const surnamesElem of result.document.inference.prediction.surnames) { - console.log(surnamesElem.value); -} -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/us_healthcare_cards_v1.md b/docs/us_healthcare_cards_v1.md deleted file mode 100644 index 254a480e1..000000000 --- a/docs/us_healthcare_cards_v1.md +++ /dev/null @@ -1,236 +0,0 @@ ---- -title: US Healthcare Card OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-us-healthcare-card-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [Healthcare Card API](https://platform.mindee.com/mindee/us_healthcare_cards). - -Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/us_healthcare_cards/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK. -![Healthcare Card sample](https://github.com/mindee/client-lib-test-data/blob/main/products/us_healthcare_cards/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.us.HealthcareCardV1, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` - -**Output (RST):** -```rst -######## -Document -######## -:Mindee ID: 5e917fc8-5c13-42b2-967f-954f4eed9959 -:Filename: default_sample.jpg - -Inference -######### -:Product: mindee/us_healthcare_cards v1.3 -:Rotation applied: Yes - -Prediction -========== -:Company Name: UnitedHealthcare -:Plan Name: Choice Plus -:Member Name: SUBSCRIBER SMITH -:Member ID: 123456789 -:Issuer 80840: -:Dependents: SPOUSE SMITH - CHILD1 SMITH - CHILD2 SMITH - CHILD3 SMITH -:Group Number: 98765 -:Payer ID: 87726 -:RX BIN: 610279 -:RX ID: -:RX GRP: UHEALTH -:RX PCN: 9999 -:Copays: - +--------------+----------------------+ - | Service Fees | Service Name | - +==============+======================+ - | 20.00 | office_visit | - +--------------+----------------------+ - | 300.00 | emergency_room | - +--------------+----------------------+ - | 75.00 | urgent_care | - +--------------+----------------------+ - | 30.00 | specialist | - +--------------+----------------------+ -:Enrollment Date: -``` - -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -### Date Field -Aside from the basic `Field` attributes, the date field `DateField` also implements the following: - -* **dateObject** (`Date`): an accessible representation of the value as a JavaScript object. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Copays Field -Copayments for covered services. - -A `HealthcareCardV1Copay` implements the following attributes: - -* `serviceFees` (number): The price of the service. -* `serviceName` (string): The name of the service. - -#### Possible values include: - - primary_care - - emergency_room - - urgent_care - - specialist - - office_visit - - prescription - - -# Attributes -The following fields are extracted for Healthcare Card V1: - -## Company Name -**companyName** ([StringField](#string-field)): The name of the company that provides the healthcare plan. - -```js -console.log(result.document.inference.prediction.companyName.value); -``` - -## Copays -**copays** ([HealthcareCardV1Copay](#copays-field)[]): Copayments for covered services. - -```js -for (const copaysElem of result.document.inference.prediction.copays) { - console.log(copaysElem.value); -} -``` - -## Dependents -**dependents** ([StringField](#string-field)[]): The list of dependents covered by the healthcare plan. - -```js -for (const dependentsElem of result.document.inference.prediction.dependents) { - console.log(dependentsElem.value); -} -``` - -## Enrollment Date -**enrollmentDate** ([DateField](#date-field)): The date when the member enrolled in the healthcare plan. - -```js -console.log(result.document.inference.prediction.enrollmentDate.value); -``` - -## Group Number -**groupNumber** ([StringField](#string-field)): The group number associated with the healthcare plan. - -```js -console.log(result.document.inference.prediction.groupNumber.value); -``` - -## Issuer 80840 -**issuer80840** ([StringField](#string-field)): The organization that issued the healthcare plan. - -```js -console.log(result.document.inference.prediction.issuer80840.value); -``` - -## Member ID -**memberId** ([StringField](#string-field)): The unique identifier for the member in the healthcare system. - -```js -console.log(result.document.inference.prediction.memberId.value); -``` - -## Member Name -**memberName** ([StringField](#string-field)): The name of the member covered by the healthcare plan. - -```js -console.log(result.document.inference.prediction.memberName.value); -``` - -## Payer ID -**payerId** ([StringField](#string-field)): The unique identifier for the payer in the healthcare system. - -```js -console.log(result.document.inference.prediction.payerId.value); -``` - -## Plan Name -**planName** ([StringField](#string-field)): The name of the healthcare plan. - -```js -console.log(result.document.inference.prediction.planName.value); -``` - -## RX BIN -**rxBin** ([StringField](#string-field)): The BIN number for prescription drug coverage. - -```js -console.log(result.document.inference.prediction.rxBin.value); -``` - -## RX GRP -**rxGrp** ([StringField](#string-field)): The group number for prescription drug coverage. - -```js -console.log(result.document.inference.prediction.rxGrp.value); -``` - -## RX ID -**rxId** ([StringField](#string-field)): The ID number for prescription drug coverage. - -```js -console.log(result.document.inference.prediction.rxId.value); -``` - -## RX PCN -**rxPcn** ([StringField](#string-field)): The PCN number for prescription drug coverage. - -```js -console.log(result.document.inference.prediction.rxPcn.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/docs/us_mail_v3.md b/docs/us_mail_v3.md deleted file mode 100644 index c9d05fe1b..000000000 --- a/docs/us_mail_v3.md +++ /dev/null @@ -1,131 +0,0 @@ ---- -title: US US Mail OCR Node.js -category: 622b805aaec68102ea7fcbc2 -slug: nodejs-us-us-mail-ocr -parentDoc: 609809574212d40077a040f1 ---- -The Node.js OCR SDK supports the [US Mail API](https://platform.mindee.com/mindee/us_mail). - -The [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/us_mail/default_sample.jpg) can be used for testing purposes. -![US Mail sample](https://github.com/mindee/client-lib-test-data/blob/main/products/us_mail/default_sample.jpg?raw=true) - -# Quick-Start -```js -const mindee = require("mindee"); -// for TS or modules: -// import * as mindee from "mindee"; - -// Init a new client -const mindeeClient = new mindee.Client({ apiKey: "my-api-key" }); - -// Load a file from disk -const inputSource = mindeeClient.docFromPath("/path/to/the/file.ext"); - -// Parse the file -const apiResponse = mindeeClient.enqueueAndParse( - mindee.product.us.UsMailV3, - inputSource -); - -// Handle the response Promise -apiResponse.then((resp) => { - // print a string summary - console.log(resp.document.toString()); -}); -``` -# Field Types -## Standard Fields -These fields are generic and used in several products. - -### Basic Field -Each prediction object contains a set of fields that inherit from the generic `Field` class. -A typical `Field` object will have the following attributes: - -* **value** (`number | string`): corresponds to the field value. Can be `undefined` if no value was extracted. -* **confidence** (`number`): the confidence score of the field prediction. -* **boundingBox** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document. -* **polygon** (`Point[]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image. -* **pageId** (`number`): the ID of the page, always `undefined` when at document-level. -* **reconstructed** (`boolean`): indicates whether an object was reconstructed (not extracted as the API gave it). - -> **Note:** A `Point` simply refers to an array of two numbers (`[number, number]`). - - -Aside from the previous attributes, all basic fields have access to a `toString()` method that can be used to print their value as a string. - -### String Field -The text field `StringField` only has one constraint: its **value** is a `string` (or `undefined`). - -## Specific Fields -Fields which are specific to this product; they are not used in any other product. - -### Recipient Addresses Field -The addresses of the recipients. - -A `UsMailV3RecipientAddress` implements the following attributes: - -* `city` (string): The city of the recipient's address. -* `complete` (string): The complete address of the recipient. -* `isAddressChange` (boolean): Indicates if the recipient's address is a change of address. -* `postalCode` (string): The postal code of the recipient's address. -* `privateMailboxNumber` (string): The private mailbox number of the recipient's address. -* `state` (string): Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. -* `street` (string): The street of the recipient's address. -* `unit` (string): The unit number of the recipient's address. -Fields which are specific to this product; they are not used in any other product. - -### Sender Address Field -The address of the sender. - -A `UsMailV3SenderAddress` implements the following attributes: - -* `city` (string): The city of the sender's address. -* `complete` (string): The complete address of the sender. -* `postalCode` (string): The postal code of the sender's address. -* `state` (string): Second part of the ISO 3166-2 code, consisting of two letters indicating the US State. -* `street` (string): The street of the sender's address. - -# Attributes -The following fields are extracted for US Mail V3: - -## Return to Sender -**isReturnToSender** : Whether the mailing is marked as return to sender. - -```js -console.log(result.document.inference.prediction.isReturnToSender.value); -``` - -## Recipient Addresses -**recipientAddresses** ([UsMailV3RecipientAddress](#recipient-addresses-field)[]): The addresses of the recipients. - -```js -for (const recipientAddressesElem of result.document.inference.prediction.recipientAddresses) { - console.log(recipientAddressesElem.value); -} -``` - -## Recipient Names -**recipientNames** ([StringField](#string-field)[]): The names of the recipients. - -```js -for (const recipientNamesElem of result.document.inference.prediction.recipientNames) { - console.log(recipientNamesElem.value); -} -``` - -## Sender Address -**senderAddress** ([UsMailV3SenderAddress](#sender-address-field)): The address of the sender. - -```js -console.log(result.document.inference.prediction.senderAddress.value); -``` - -## Sender Name -**senderName** ([StringField](#string-field)): The name of the sender. - -```js -console.log(result.document.inference.prediction.senderName.value); -``` - -# Questions? -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) diff --git a/src/clientV2.ts b/src/clientV2.ts index 36ae9588e..621a44493 100644 --- a/src/clientV2.ts +++ b/src/clientV2.ts @@ -270,7 +270,7 @@ export class ClientV2 { } logger.debug( `Polling server for parsing result with queueId: ${queueId}. -Attempt nยฐ${retryCounter}/${validatedAsyncParams.maxRetries}. +Attempt no. ${retryCounter} of ${validatedAsyncParams.maxRetries}. Job status: ${pollResults.job.status}.` ); await setTimeout(validatedAsyncParams.delaySec * 1000, undefined, validatedAsyncParams.recurringTimerOptions); @@ -279,7 +279,7 @@ Job status: ${pollResults.job.status}.` } const error: ErrorResponse | undefined = pollResults.job.error; if (error) { - throw new MindeeHttpErrorV2(error.status, error.detail); + throw new MindeeHttpErrorV2(error); } throw Error( "Asynchronous parsing request timed out after " + diff --git a/src/errors/mindeeError.ts b/src/errors/mindeeError.ts index 1ed773c71..b70e43857 100644 --- a/src/errors/mindeeError.ts +++ b/src/errors/mindeeError.ts @@ -1,3 +1,5 @@ +import { ErrorDetails, ErrorResponse } from "../parsing/v2"; + /** * Main Mindee Error custom class. */ @@ -40,15 +42,18 @@ export class MindeeApiV2Error extends MindeeError { } } -export class MindeeHttpErrorV2 extends MindeeError { +export class MindeeHttpErrorV2 extends MindeeError implements ErrorDetails { public status: number; public detail: string; - constructor(status: number, detail: string) { - super(`HTTP ${status} - ${detail}`); - this.status = status; - this.detail = detail; + public title: string; + public code: string; + + constructor(error: ErrorResponse) { + super(`HTTP ${error.status} :: ${error.title} - ${error.detail}`); + this.status = error.status; + this.detail = error.detail; + this.title = error.title; + this.code = error.code; this.name = "MindeeHttpErrorV2"; } } - - diff --git a/src/http/mindeeApiV2.ts b/src/http/mindeeApiV2.ts index 5350cec83..e990bb618 100644 --- a/src/http/mindeeApiV2.ts +++ b/src/http/mindeeApiV2.ts @@ -1,6 +1,6 @@ import { ApiSettingsV2 } from "./apiSettingsV2"; import { InferenceParameters } from "../clientV2"; -import { InferenceResponse, JobResponse } from "../parsing/v2"; +import { ErrorResponse, InferenceResponse, JobResponse } from "../parsing/v2"; import FormData from "form-data"; import { RequestOptions } from "https"; import { BaseEndpoint, EndpointResponse } from "./baseEndpoint"; @@ -29,11 +29,8 @@ export class MindeeApiV2 { throw new Error("Model ID must be provided"); } const result: EndpointResponse = await this.#documentEnqueuePost(inputSource, params); - if (result.data.error?.code !== undefined) { - throw new MindeeHttpErrorV2( - result.data.error.code, - result.data.error.message ?? "Unknown error." - ); + if (result.data.error !== undefined) { + throw new MindeeHttpErrorV2(result.data.error); } return this.#processResponse(result, JobResponse); } @@ -56,7 +53,7 @@ export class MindeeApiV2 { * Throws an error if the server's response contains one. * @param jobId The document's ID in the queue. * @category Asynchronous - * @returns a `Promise` containing either the parsed result, or information on the queue. + * @returns a `Promise` containing information on the queue. */ async reqGetJob(jobId: string): Promise { const queueResponse: EndpointResponse = await this.#inferenceResultReqGet(jobId, "jobs"); @@ -67,12 +64,17 @@ export class MindeeApiV2 { (result: EndpointResponse, responseType: new (data: { [key: string]: any; }) => T): T { if (result.messageObj?.statusCode && (result.messageObj?.statusCode > 399 || result.messageObj?.statusCode < 200)) { if (result.data?.status !== null) { - throw new MindeeHttpErrorV2( - result.data?.status, result.data?.detail ?? "Unknown error." - ); + throw new MindeeHttpErrorV2(new ErrorResponse(result.data)); } throw new MindeeHttpErrorV2( - result.messageObj?.statusCode ?? -1, result.data?.statusMessage ?? "Unknown error." + new ErrorResponse( + { + status: result.messageObj?.statusCode ?? -1, + title: "Unknown Error", + detail: result.data?.detail ?? "The server returned an Unknown error.", + code: `${result.messageObj?.statusCode ?? -1}-000`, + } + ) ); } try { @@ -89,7 +91,10 @@ export class MindeeApiV2 { * @param inputSource Local or remote file as an input. * @param params {InferenceParameters} parameters relating to the enqueueing options. */ - #documentEnqueuePost(inputSource: InputSource, params: InferenceParameters): Promise { + #documentEnqueuePost( + inputSource: InputSource, + params: InferenceParameters + ): Promise { const form = new FormData(); form.append("model_id", params.modelId); diff --git a/src/parsing/v2/errorItem.ts b/src/parsing/v2/errorItem.ts new file mode 100644 index 000000000..4063dfb7a --- /dev/null +++ b/src/parsing/v2/errorItem.ts @@ -0,0 +1,22 @@ +import { StringDict } from "../common"; + +export class ErrorItem { + /** + * The HTTP status code returned by the server. + */ + public pointer?: string; + /** + * Explicit information on the issue. + */ + public detail: string; + + /** + * @param serverResponse JSON response from the server. + */ + constructor(serverResponse: StringDict) { + if (serverResponse["pointer"] !== undefined) { + this.pointer = serverResponse["pointer"]; + } + this.detail = serverResponse["detail"]; + } +} diff --git a/src/parsing/v2/errorResponse.ts b/src/parsing/v2/errorResponse.ts index f205e59ac..38ca33463 100644 --- a/src/parsing/v2/errorResponse.ts +++ b/src/parsing/v2/errorResponse.ts @@ -1,14 +1,37 @@ import { StringDict } from "../common"; +import { ErrorItem } from "./errorItem"; -export class ErrorResponse { +export interface ErrorDetails { /** - * The HTTP code status. + * The HTTP status code returned by the server. */ - public status: number; + status: number; /** - * The detail on the error. + * A human-readable explanation specific to the occurrence of the problem. */ - public detail: string; + detail: string; + /** + * A short, human-readable summary of the problem. + */ + title: string; + /** + * A machine-readable code specific to the occurrence of the problem. + */ + code: string; +} + +/** + * Error response detailing a problem. The format adheres to RFC 9457. + */ +export class ErrorResponse implements ErrorDetails { + status: number; + detail: string; + title: string; + code: string; + /** + * A machine-readable code specific to the occurrence of the problem. + */ + public errors: ErrorItem[]; /** * @param serverResponse JSON response from the server. @@ -16,5 +39,14 @@ export class ErrorResponse { constructor(serverResponse: StringDict) { this.status = serverResponse["status"]; this.detail = serverResponse["detail"]; + this.title = serverResponse["title"]; + this.code = serverResponse["code"]; + if (serverResponse["errors"] !== undefined) { + this.errors = serverResponse["errors"].map( + (error: StringDict) => new ErrorItem(error) + ); + } else { + this.errors = []; + } } } diff --git a/src/parsing/v2/index.ts b/src/parsing/v2/index.ts index a8548a66b..2ddc5302e 100644 --- a/src/parsing/v2/index.ts +++ b/src/parsing/v2/index.ts @@ -1,5 +1,6 @@ export { CommonResponse } from "./commonResponse"; -export { ErrorResponse } from "./errorResponse"; +export { ErrorResponse, ErrorDetails } from "./errorResponse"; +export { ErrorItem } from "./errorItem"; export { Inference } from "./inference"; export { InferenceActiveOptions } from "./inferenceActiveOptions"; export { InferenceFile } from "./inferenceFile"; diff --git a/tests/api/invoiceSplitterReconstruction.spec.ts b/tests/api/invoiceSplitterReconstruction.spec.ts deleted file mode 100644 index 8466c81c1..000000000 --- a/tests/api/invoiceSplitterReconstruction.spec.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { expect } from "chai"; -import { promises as fs } from "fs"; -import * as path from "path"; -import { Document } from "../../src/parsing/common"; -import { InvoiceSplitterV1 } from "../../src/product"; -import { extractInvoices } from "../../src/imageOperations"; -import { PathInput } from "../../src/input"; - -describe("A Multipage Invoice Document", () => { - it("should be split into the proper invoices", async () => { - const jsonData = await fs.readFile( - path.resolve("tests/data/products/invoice_splitter/response_v1/complete.json") - ); - const sourceDoc = new PathInput({ inputPath: path.resolve("tests/data/products/invoice_splitter/invoice_5p.pdf") }); - await sourceDoc.init(); - const response = JSON.parse(jsonData.toString()); - const doc = new Document(InvoiceSplitterV1, response.document); - const extractedInvoices = await extractInvoices(sourceDoc, doc.inference, false); - expect(extractedInvoices.length).to.be.equals(3); - expect(extractedInvoices[0].pageIdMin).to.be.equal(0); - expect(extractedInvoices[0].pageIdMax).to.be.equal(0); - expect(extractedInvoices[1].pageIdMin).to.be.equal(1); - expect(extractedInvoices[1].pageIdMax).to.be.equal(3); - expect(extractedInvoices[2].pageIdMin).to.be.equal(4); - expect(extractedInvoices[2].pageIdMax).to.be.equal(4); - for (const extractedInvoice of extractedInvoices) { - expect(Buffer.byteLength(extractedInvoice.asSource().fileObject)).to.be.lessThan(10485760); - expect(Buffer.byteLength(extractedInvoice.asSource().fileObject)).to.be.greaterThan(100000); - } - }); - it("should be split differently if confidences are taken into account.", async () => { - const jsonData = await fs.readFile( - path.resolve("tests/data/products/invoice_splitter/response_v1/complete.json") - ); - const sourceDoc = new PathInput({ inputPath: path.resolve("tests/data/products/invoice_splitter/invoice_5p.pdf") }); - await sourceDoc.init(); - const response = JSON.parse(jsonData.toString()); - const doc = new Document(InvoiceSplitterV1, response.document); - const extractedConfidentInvoices = await extractInvoices(sourceDoc, doc.inference, true); - expect(extractedConfidentInvoices.length).to.be.equals(2); - }); -}); diff --git a/tests/api/multiReceiptsReconstruction.spec.ts b/tests/api/multiReceiptsReconstruction.spec.ts deleted file mode 100644 index edbc717bd..000000000 --- a/tests/api/multiReceiptsReconstruction.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { expect } from "chai"; -import { promises as fs } from "fs"; -import * as path from "path"; -import { Document } from "../../src/parsing/common"; -import { MultiReceiptsDetectorV1 } from "../../src/product"; -import { extractReceipts } from "../../src/imageOperations"; -import { PathInput } from "../../src/input"; - -describe("A Multi-Receipt Document", () => { - it("should be split into the proper receipts", async () => { - const jsonData = await fs.readFile( - path.resolve("tests/data/products/multi_receipts_detector/response_v1/complete.json") - ); - const sourceDoc = new PathInput({ inputPath: path.resolve("tests/data/products/multi_receipts_detector/default_sample.jpg") }); - await sourceDoc.init(); - const response = JSON.parse(jsonData.toString()); - const doc = new Document(MultiReceiptsDetectorV1, response.document); - const extractedReceipts = await extractReceipts(sourceDoc, doc.inference); - expect(extractedReceipts.length).to.be.equals(6); - let i = 0; - for (const extractedReceipt of extractedReceipts) { - expect(extractedReceipt.pageId).to.be.equal(0); - expect(extractedReceipt.receiptId).to.be.equal(i); - expect(Buffer.byteLength(extractedReceipt.asSource().fileObject)).to.be.lessThan(10485760); - expect(Buffer.byteLength(extractedReceipt.asSource().fileObject)).to.be.greaterThan(100000); - i++; - } - }); -}); diff --git a/tests/data b/tests/data index bc8356c1c..5038d188b 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit bc8356c1ce52d60351ed3430d336f33366025012 +Subproject commit 5038d188b670a7a9a874189df1c08b6720907f89 diff --git a/tests/imageOperations/invoiceSplitter.integration.ts b/tests/imageOperations/invoiceSplitter.integration.ts index e5c53014a..93141de21 100644 --- a/tests/imageOperations/invoiceSplitter.integration.ts +++ b/tests/imageOperations/invoiceSplitter.integration.ts @@ -4,6 +4,7 @@ import { expect } from "chai"; import { levenshteinRatio } from "../testingUtilities"; import { promises as fs } from "fs"; import path from "path"; +import { RESOURCE_PATH } from "../index"; describe("Given a PDF", async () => { let client: mindee.Client; @@ -14,11 +15,13 @@ describe("Given a PDF", async () => { it("should extract invoices in strict mode.", async () => { const sample = client.docFromPath( - "tests/data/products/invoice_splitter/default_sample.pdf" + path.join(RESOURCE_PATH, "products/invoice_splitter/default_sample.pdf") ); await sample.init(); - const response = await client.enqueueAndParse(mindee.product.InvoiceSplitterV1, sample); + const response = await client.enqueueAndParse( + mindee.product.InvoiceSplitterV1, sample + ); const invoiceSplitterInference = response.document?.inference; expect(invoiceSplitterInference).to.be.an.instanceof(InvoiceSplitterV1); const invoices = await mindee.imageOperations.extractInvoices( @@ -31,7 +34,7 @@ describe("Given a PDF", async () => { const invoiceResult = await client.parse(mindee.product.InvoiceV4, invoices[0].asSource()); const testStringRstInvoice = await fs.readFile( - path.join("tests/data/products/invoices/response_v4/summary_full_invoice_p1.rst") + path.join(RESOURCE_PATH, "products/invoices/response_v4/summary_full_invoice_p1.rst") ); expect( diff --git a/tests/imageOperations/invoiceSplitterExtractor.spec.ts b/tests/imageOperations/invoiceSplitterExtractor.spec.ts index f9a085eb4..a8149b546 100644 --- a/tests/imageOperations/invoiceSplitterExtractor.spec.ts +++ b/tests/imageOperations/invoiceSplitterExtractor.spec.ts @@ -3,12 +3,13 @@ import { promises as fs } from "fs"; import path from "path"; import { InvoiceSplitterV1 } from "../../src/product"; import { extractInvoices } from "../../src/imageOperations"; -import { PathInput } from "../../src/input"; +import { PathInput } from "../../src"; +import { RESOURCE_PATH } from "../index"; const dataPath = { - complete: "tests/data/products/invoice_splitter/response_v1/complete.json", - fileSample: "tests/data/products/invoice_splitter/invoice_5p.pdf" -} + complete: path.join(RESOURCE_PATH, "products/invoice_splitter/response_v1/complete.json"), + fileSample: path.join(RESOURCE_PATH, "products/invoice_splitter/invoice_5p.pdf"), +}; describe("A multi-page invoice document", () => { it("should be split properly.", async () => { diff --git a/tests/imageOperations/multiReceiptsExtractor.spec.ts b/tests/imageOperations/multiReceiptsExtractor.spec.ts index f98cb7c84..3bd9df9b0 100644 --- a/tests/imageOperations/multiReceiptsExtractor.spec.ts +++ b/tests/imageOperations/multiReceiptsExtractor.spec.ts @@ -1,23 +1,24 @@ -import {expect} from "chai"; -import {promises as fs} from "fs"; +import { expect } from "chai"; +import { promises as fs } from "fs"; import path from "path"; -import {MultiReceiptsDetectorV1} from "../../src/product"; -import {extractReceipts} from "../../src/imageOperations"; -import {PathInput} from "../../src/input"; +import { MultiReceiptsDetectorV1 } from "../../src/product"; +import { extractReceipts } from "../../src/imageOperations"; +import { PathInput } from "../../src"; +import { RESOURCE_PATH } from "../index"; const dataPath = { - complete: "tests/data/products/multi_receipts_detector/response_v1/complete.json", - fileSample: "tests/data/products/multi_receipts_detector/default_sample.jpg", - completeMultiPage: "tests/data/products/multi_receipts_detector/response_v1/multipage_sample.json", - multiPageSample: "tests/data/products/multi_receipts_detector/multipage_sample.pdf" -} + complete: path.join(RESOURCE_PATH, "products/multi_receipts_detector/response_v1/complete.json"), + fileSample: path.join(RESOURCE_PATH, "products/multi_receipts_detector/default_sample.jpg"), + completeMultiPage: path.join(RESOURCE_PATH, "products/multi_receipts_detector/response_v1/multipage_sample.json"), + multiPageSample: path.join(RESOURCE_PATH, "products/multi_receipts_detector/multipage_sample.pdf"), +}; describe("A single-page multi-receipts document", () => { it("should be split properly.", async () => { const jsonDataNA = await fs.readFile(path.resolve(dataPath.complete)); const response = JSON.parse(jsonDataNA.toString()); const doc = new MultiReceiptsDetectorV1(response.document.inference); - const inputSample = new PathInput({inputPath: dataPath.fileSample}); + const inputSample = new PathInput({ inputPath: dataPath.fileSample }); await inputSample.init(); const extractedReceipts = await extractReceipts(inputSample, doc); expect(extractedReceipts.length).to.be.equals(6); @@ -33,7 +34,7 @@ describe("A multi-page multi-receipts document", () => { const jsonDataNA = await fs.readFile(path.resolve(dataPath.completeMultiPage)); const response = JSON.parse(jsonDataNA.toString()); const doc = new MultiReceiptsDetectorV1(response.document.inference); - const inputSample = new PathInput({inputPath: dataPath.multiPageSample}); + const inputSample = new PathInput({ inputPath: dataPath.multiPageSample }); await inputSample.init(); const extractedReceipts = await extractReceipts(inputSample, doc); expect(extractedReceipts.length).to.be.equals(5); diff --git a/tests/index.ts b/tests/index.ts new file mode 100644 index 000000000..782d5e1e7 --- /dev/null +++ b/tests/index.ts @@ -0,0 +1,5 @@ +import path from "node:path"; + +export const RESOURCE_PATH = path.join(__dirname, "data"); +export const V1_RESOURCE_PATH = path.join(RESOURCE_PATH, "v1"); +export const V2_RESOURCE_PATH = path.join(RESOURCE_PATH, "v2"); diff --git a/tests/inputs/localResponse.spec.ts b/tests/input/localResponse.spec.ts similarity index 89% rename from tests/inputs/localResponse.spec.ts rename to tests/input/localResponse.spec.ts index 0b85f3f70..3add0fe2b 100644 --- a/tests/inputs/localResponse.spec.ts +++ b/tests/input/localResponse.spec.ts @@ -3,14 +3,19 @@ import * as fs from "node:fs/promises"; import { expect } from "chai"; import { Client, PredictResponse, AsyncPredictResponse, InferenceResponse } from "../../src"; import { InternationalIdV2, InvoiceV4, MultiReceiptsDetectorV1 } from "../../src/product"; +import path from "path"; +import { RESOURCE_PATH } from "../index"; const signature: string = "5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0"; const dummySecretKey: string = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"; -const filePath: string = "tests/data/async/get_completed_empty.json"; -const multiReceiptsDetectorPath: string = "tests/data/products/multi_receipts_detector/response_v1/complete.json"; -const failedPath: string = "tests/data/async/get_failed_job_error.json"; -const internationalIdPath: string = "tests/data/products/international_id/response_v2/complete.json"; - +const filePath: string = path.join(RESOURCE_PATH, "/async/get_completed_empty.json"); +const multiReceiptsDetectorPath: string = path.join( + RESOURCE_PATH, "products/multi_receipts_detector/response_v1/complete.json" +); +const failedPath: string = path.join(RESOURCE_PATH, "async/get_failed_job_error.json"); +const internationalIdPath: string = path.join( + RESOURCE_PATH, "products/international_id/response_v2/complete.json" +); describe("A valid local response", () => { it("should load a string properly.", async () => { diff --git a/tests/inputs/pageOperations.spec.ts b/tests/input/pageOperations.spec.ts similarity index 85% rename from tests/inputs/pageOperations.spec.ts rename to tests/input/pageOperations.spec.ts index f322d4f2c..d8839a071 100644 --- a/tests/inputs/pageOperations.spec.ts +++ b/tests/input/pageOperations.spec.ts @@ -6,11 +6,12 @@ import { import * as fs from "fs"; import * as path from "path"; import { expect } from "chai"; +import { RESOURCE_PATH } from "../index"; describe("High level multi-page operations", () => { it("should cut a PDF", async () => { const input = new PathInput({ - inputPath: path.join(__dirname, "../data/file_types/pdf/multipage.pdf"), + inputPath: path.join(RESOURCE_PATH, "file_types/pdf/multipage.pdf"), }); await input.applyPageOptions({ operation: PageOptionsOperation.KeepOnly, @@ -26,7 +27,7 @@ describe("High level multi-page operations", () => { const lengthRE = /(?<=\/FlateDecode[\s\S]\/Length )\d{1,3}/gm; const expectedResult = await fs.promises.readFile( - path.join(__dirname, "../data/file_types/pdf/multipage_cut-3.pdf"), + path.join(RESOURCE_PATH, "file_types/pdf/multipage_cut-3.pdf"), "utf-8" ); @@ -37,7 +38,7 @@ describe("High level multi-page operations", () => { }); it("should not cut the PDF", async () => { - const filePath = path.join(__dirname, "../data/file_types/pdf/multipage.pdf"); + const filePath = path.join(RESOURCE_PATH, "file_types/pdf/multipage.pdf"); const input = new PathInput({ inputPath: filePath, }); diff --git a/tests/inputs/sources.spec.ts b/tests/input/sources.spec.ts similarity index 82% rename from tests/inputs/sources.spec.ts rename to tests/input/sources.spec.ts index c98743698..2104fe826 100644 --- a/tests/inputs/sources.spec.ts +++ b/tests/input/sources.spec.ts @@ -19,17 +19,17 @@ import { compressImage } from "../../src/imageOperations"; import { compressPdf } from "../../src/pdf"; import { extractTextFromPdf } from "../../src/pdf/pdfUtils"; import { logger } from "../../src/logger"; +import { RESOURCE_PATH } from "../index"; describe("Test different types of input", () => { - const resourcesPath = path.join(__dirname, "../data"); - const outputPath = path.join(resourcesPath, "output"); + const outputPath = path.join(RESOURCE_PATH, "output"); before(async () => { await fs.promises.mkdir(outputPath, { recursive: true }); }); it("should accept base64 inputs", async () => { const b64Input = await fs.promises.readFile( - path.join(__dirname, "../data/file_types/receipt.txt") + path.join(RESOURCE_PATH, "file_types/receipt.txt") ); const b64String = b64Input.toString(); // don't provide an extension to see if we can detect MIME @@ -55,12 +55,12 @@ describe("Test different types of input", () => { it("should accept JPEG files from a path", async () => { const inputSource = new PathInput({ - inputPath: path.join(__dirname, "../data/products/expense_receipts/default_sample.jpg"), + inputPath: path.join(RESOURCE_PATH, "products/expense_receipts/default_sample.jpg"), }); await inputSource.init(); const expectedResult = await fs.promises.readFile( - path.join(__dirname, "../data/products/expense_receipts/default_sample.jpg") + path.join(RESOURCE_PATH, "products/expense_receipts/default_sample.jpg") ); expect(inputSource.inputType).to.equals(INPUT_TYPE_PATH); expect(inputSource.filename).to.equals("default_sample.jpg"); @@ -72,11 +72,11 @@ describe("Test different types of input", () => { it("should accept TIFF from a path", async () => { const inputSource = new PathInput({ - inputPath: path.join(__dirname, "../data/file_types/receipt.tif"), + inputPath: path.join(RESOURCE_PATH, "file_types/receipt.tif"), }); await inputSource.init(); const expectedResult = await fs.promises.readFile( - path.join(__dirname, "../data/file_types/receipt.tif") + path.join(RESOURCE_PATH, "file_types/receipt.tif") ); expect(inputSource.inputType).to.equals(INPUT_TYPE_PATH); expect(inputSource.filename).to.equals("receipt.tif"); @@ -88,11 +88,11 @@ describe("Test different types of input", () => { it("should accept HEIC from a path", async () => { const inputSource = new PathInput({ - inputPath: path.join(__dirname, "../data/file_types/receipt.heic"), + inputPath: path.join(RESOURCE_PATH, "file_types/receipt.heic"), }); await inputSource.init(); const expectedResult = await fs.promises.readFile( - path.join(__dirname, "../data/file_types/receipt.heic") + path.join(RESOURCE_PATH, "file_types/receipt.heic") ); expect(inputSource.inputType).to.equals(INPUT_TYPE_PATH); expect(inputSource.filename).to.equals("receipt.heic"); @@ -103,7 +103,7 @@ describe("Test different types of input", () => { }); it("should accept read streams", async () => { - const filePath = path.join(__dirname, "../data/products/expense_receipts/default_sample.jpg"); + const filePath = path.join(RESOURCE_PATH, "products/expense_receipts/default_sample.jpg"); const stream = fs.createReadStream(filePath); const filename = "default_sample.jpg"; const inputSource = new StreamInput({ @@ -121,7 +121,7 @@ describe("Test different types of input", () => { }); it("should accept raw bytes", async () => { - const filePath = path.join(__dirname, "../data/products/expense_receipts/default_sample.jpg"); + const filePath = path.join(RESOURCE_PATH, "products/expense_receipts/default_sample.jpg"); const inputBytes = await fs.promises.readFile(filePath); // don't provide an extension to see if we can detect MIME // type based on contents @@ -144,7 +144,7 @@ describe("Test different types of input", () => { const filename = "invoice_01.pdf"; const buffer = Buffer.from( await fs.promises.readFile( - path.join(__dirname, "../data/products/invoices/invoice_10p.pdf") + path.join(RESOURCE_PATH, "products/invoices/invoice_10p.pdf") ) ); const inputSource = new BufferInput({ @@ -161,17 +161,17 @@ describe("Test different types of input", () => { it("Image Quality Compress From Input Source", async () => { - const receiptInput = new PathInput({ inputPath: path.join(resourcesPath, "file_types/receipt.jpg") }); + const receiptInput = new PathInput({ inputPath: path.join(RESOURCE_PATH, "file_types/receipt.jpg") }); await receiptInput.compress(40); await fs.promises.writeFile(path.join(outputPath, "compress_indirect.jpg"), receiptInput.fileObject); - const initialFileStats = await fs.promises.stat(path.join(resourcesPath, "file_types/receipt.jpg")); + const initialFileStats = await fs.promises.stat(path.join(RESOURCE_PATH, "file_types/receipt.jpg")); const renderedFileStats = await fs.promises.stat(path.join(outputPath, "compress_indirect.jpg")); expect(renderedFileStats.size).to.be.lessThan(initialFileStats.size); }); it("Image Quality Compresses From Compressor", async () => { - const receiptInput = new PathInput({ inputPath: path.join(resourcesPath, "file_types/receipt.jpg") }); + const receiptInput = new PathInput({ inputPath: path.join(RESOURCE_PATH, "file_types/receipt.jpg") }); await receiptInput.init(); const compresses = [ await compressImage(receiptInput.fileObject, 100), @@ -186,7 +186,7 @@ describe("Test different types of input", () => { await fs.promises.writeFile(path.join(outputPath, fileNames[i]), compresses[i]); } - const initialFileStats = await fs.promises.stat(path.join(resourcesPath, "file_types/receipt.jpg")); + const initialFileStats = await fs.promises.stat(path.join(RESOURCE_PATH, "file_types/receipt.jpg")); const renderedFileStats = await Promise.all( fileNames.map(fileName => fs.promises.stat(path.join(outputPath, fileName))) ); @@ -199,13 +199,13 @@ describe("Test different types of input", () => { }); it("Image Resize From InputSource", async () => { - const imageResizeInput = new PathInput({ inputPath: path.join(resourcesPath, "file_types/receipt.jpg") }); + const imageResizeInput = new PathInput({ inputPath: path.join(RESOURCE_PATH, "file_types/receipt.jpg") }); await imageResizeInput.init(); await imageResizeInput.compress(75, 250, 1000); await fs.promises.writeFile(path.join(outputPath, "resize_indirect.jpg"), imageResizeInput.fileObject); - const initialFileStats = await fs.promises.stat(path.join(resourcesPath, "file_types/receipt.jpg")); + const initialFileStats = await fs.promises.stat(path.join(RESOURCE_PATH, "file_types/receipt.jpg")); const renderedFileStats = await fs.promises.stat(path.join(outputPath, "resize_indirect.jpg")); expect(renderedFileStats.size).to.be.lessThan(initialFileStats.size); const metadata = await sharp(imageResizeInput.fileObject).metadata(); @@ -214,7 +214,7 @@ describe("Test different types of input", () => { }); it("Image Resize From Compressor", async () => { - const imageResizeInput = new PathInput({ inputPath: path.join(resourcesPath, "file_types/receipt.jpg") }); + const imageResizeInput = new PathInput({ inputPath: path.join(RESOURCE_PATH, "file_types/receipt.jpg") }); await imageResizeInput.init(); const resizes = [ @@ -229,7 +229,7 @@ describe("Test different types of input", () => { await fs.promises.writeFile(path.join(outputPath, fileNames[i]), resizes[i]); } - const initialFileStats = await fs.promises.stat(path.join(resourcesPath, "file_types/receipt.jpg")); + const initialFileStats = await fs.promises.stat(path.join(RESOURCE_PATH, "file_types/receipt.jpg")); const renderedFileStats = await Promise.all( fileNames.map(fileName => fs.promises.stat(path.join(outputPath, fileName))) ); @@ -242,9 +242,9 @@ describe("Test different types of input", () => { it("PDF Input Has Text", async () => { - const hasSourceTextPath = path.join(resourcesPath, "file_types/pdf/multipage.pdf"); - const hasNoSourceTextPath = path.join(resourcesPath, "file_types/pdf/blank_1.pdf"); - const hasNoSourceTextSinceItsImagePath = path.join(resourcesPath, "file_types/receipt.jpg"); + const hasSourceTextPath = path.join(RESOURCE_PATH, "file_types/pdf/multipage.pdf"); + const hasNoSourceTextPath = path.join(RESOURCE_PATH, "file_types/pdf/blank_1.pdf"); + const hasNoSourceTextSinceItsImagePath = path.join(RESOURCE_PATH, "file_types/receipt.jpg"); const hasSourceTextInput = new PathInput({ inputPath: hasSourceTextPath }); const hasNoSourceTextInput = new PathInput({ inputPath: hasNoSourceTextPath }); @@ -257,27 +257,30 @@ describe("Test different types of input", () => { it("PDF Compress From InputSource", async () => { const pdfResizeInput = new PathInput( - { inputPath: path.join(resourcesPath, "products/invoice_splitter/default_sample.pdf") } + { inputPath: path.join(RESOURCE_PATH, "products/invoice_splitter/default_sample.pdf") } ); await pdfResizeInput.init(); - const compressedPdf = await compressPdf(pdfResizeInput.fileObject, 75, true); + const compressedPdf = await compressPdf( + pdfResizeInput.fileObject, 75, true + ); await fs.promises.writeFile(path.join(outputPath, "resize_indirect.pdf"), compressedPdf); const initialFileStats = await fs.promises.stat( path.join( - resourcesPath, + RESOURCE_PATH, "products/invoice_splitter/default_sample.pdf" ) ); - const renderedFileStats = await fs.promises.stat(path.join(outputPath, "resize_indirect.pdf")); - + const renderedFileStats = await fs.promises.stat( + path.join(outputPath, "resize_indirect.pdf") + ); expect(renderedFileStats.size).to.be.lessThan(initialFileStats.size); }).timeout(10000); it("PDF Compress From Compressor", async () => { const pdfResizeInput = new PathInput( - { inputPath: path.join(resourcesPath, "products/invoice_splitter/default_sample.pdf") } + { inputPath: path.join(RESOURCE_PATH, "products/invoice_splitter/default_sample.pdf") } ); await pdfResizeInput.init(); @@ -294,7 +297,7 @@ describe("Test different types of input", () => { } const initialFileStats = await fs.promises.stat( - path.join(resourcesPath, "products/invoice_splitter/default_sample.pdf") + path.join(RESOURCE_PATH, "products/invoice_splitter/default_sample.pdf") ); const renderedFileStats = await Promise.all( fileNames.map(fileName => fs.promises.stat(path.join(outputPath, fileName))) @@ -307,11 +310,14 @@ describe("Test different types of input", () => { }).timeout(20000); it("PDF Compress With Text Keeps Text", async () => { - const initialWithText = new PathInput({ inputPath: path.join(resourcesPath, "file_types/pdf/multipage.pdf") }); + const initialWithText = new PathInput( + { inputPath: path.join(RESOURCE_PATH, "file_types/pdf/multipage.pdf") } + ); await initialWithText.init(); - const compressedWithText = await compressPdf(initialWithText.fileObject, 100, true, false); - + const compressedWithText = await compressPdf( + initialWithText.fileObject, 100, true, false + ); const originalText = (await extractTextFromPdf(initialWithText.fileObject)).getConcatenatedText(); const compressedText = (await extractTextFromPdf(compressedWithText)).getConcatenatedText(); @@ -319,7 +325,9 @@ describe("Test different types of input", () => { }).timeout(60000); it("PDF Compress With Text Does Not Compress", async () => { - const initialWithText = new PathInput({ inputPath: path.join(resourcesPath, "file_types/pdf/multipage.pdf") }); + const initialWithText = new PathInput( + { inputPath: path.join(RESOURCE_PATH, "file_types/pdf/multipage.pdf") } + ); await initialWithText.init(); const compressedWithText = await compressPdf(initialWithText.fileObject, 50); @@ -349,7 +357,7 @@ describe("Test different types of input", () => { for (const filePath of createdFiles) { try { - await fs.promises.unlink(path.join(resourcesPath, "output", filePath)); + await fs.promises.unlink(path.join(RESOURCE_PATH, "output", filePath)); } catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") { logger.warn(`Could not delete file '${filePath}': ${(error as Error).message}`); diff --git a/tests/inputs/urlInputSource.spec.ts b/tests/input/urlInputSource.spec.ts similarity index 100% rename from tests/inputs/urlInputSource.spec.ts rename to tests/input/urlInputSource.spec.ts diff --git a/tests/pdf/pdfOperation.spec.ts b/tests/pdf/pdfOperation.spec.ts index 90eaf31a8..16cb99669 100644 --- a/tests/pdf/pdfOperation.spec.ts +++ b/tests/pdf/pdfOperation.spec.ts @@ -3,12 +3,13 @@ import * as path from "path"; import * as fs from "fs"; import { expect } from "chai"; import { PageOptions, PageOptionsOperation } from "../../src"; -import { PathInput } from "../../src/input"; +import { PathInput } from "../../src"; +import { RESOURCE_PATH } from "../index"; describe("Test pdf operation", () => { it("should cut a PDF to get 2 pages", async () => { const inputSource = new PathInput({ - inputPath: path.join(__dirname, "../data/file_types/pdf/multipage.pdf"), + inputPath: path.join(RESOURCE_PATH, "file_types/pdf/multipage.pdf"), }); await inputSource.init(); @@ -24,7 +25,7 @@ describe("Test pdf operation", () => { it("should cut a PDF to get only the first page", async () => { const inputSource = new PathInput({ - inputPath: path.join(__dirname, "../data/file_types/pdf/multipage.pdf"), + inputPath: path.join(RESOURCE_PATH, "file_types/pdf/multipage.pdf"), }); await inputSource.init(); @@ -40,7 +41,7 @@ describe("Test pdf operation", () => { it("should not cut a PDF but throw exception because index page out of range", async () => { const inputSource = new PathInput({ - inputPath: path.join(__dirname, "../data/file_types/pdf/multipage_cut-1.pdf"), + inputPath: path.join(RESOURCE_PATH, "file_types/pdf/multipage_cut-1.pdf"), }); await inputSource.init(); @@ -59,7 +60,7 @@ describe("Test pdf operation", () => { it("should not cut a PDF but throw exception because too many indexes compare to the total of pages", async () => { const inputSource = new PathInput({ - inputPath: path.join(__dirname, "../data/file_types/pdf/multipage_cut-1.pdf"), + inputPath: path.join(RESOURCE_PATH, "file_types/pdf/multipage_cut-1.pdf"), }); await inputSource.init(); @@ -79,7 +80,7 @@ describe("Test pdf operation", () => { it("should remove pages from a PDF", async () => { const inputSource = new PathInput({ - inputPath: path.join(__dirname, "../data/file_types/pdf/multipage.pdf"), + inputPath: path.join(RESOURCE_PATH, "file_types/pdf/multipage.pdf"), }); await inputSource.init(); @@ -97,7 +98,7 @@ describe("Test pdf operation", () => { it("should not remove pages from a PDF because min pages are not met", async () => { const inputSource = new PathInput({ - inputPath: path.join(__dirname, "../data/file_types/pdf/multipage_cut-2.pdf"), + inputPath: path.join(RESOURCE_PATH, "file_types/pdf/multipage_cut-2.pdf"), }); await inputSource.init(); @@ -113,7 +114,7 @@ describe("Test pdf operation", () => { it("should not cut pages from a PDF because min pages are not met", async () => { const inputSource = new PathInput({ - inputPath: path.join(__dirname, "../data/file_types/pdf/multipage_cut-2.pdf"), + inputPath: path.join(RESOURCE_PATH, "file_types/pdf/multipage_cut-2.pdf"), }); await inputSource.init(); @@ -129,7 +130,7 @@ describe("Test pdf operation", () => { it("should cut the first and the 2 last pages from a PDF", async () => { const inputSource = new PathInput({ - inputPath: path.join(__dirname, "../data/file_types/pdf/multipage.pdf"), + inputPath: path.join(RESOURCE_PATH, "file_types/pdf/multipage.pdf"), }); await inputSource.init(); @@ -147,7 +148,7 @@ describe("Test pdf operation", () => { const lengthRE = /(?<=\/FlateDecode[\s\S]\/Length )\d{1,3}/gm; const expectedResult = await fs.promises.readFile( - path.join(__dirname, "../data/file_types/pdf/multipage_cut-3.pdf"), + path.join(RESOURCE_PATH, "file_types/pdf/multipage_cut-3.pdf"), "utf-8" ); diff --git a/tests/pdf/pdfTypes.spec.ts b/tests/pdf/pdfTypes.spec.ts index 4b7dba183..aec23ac51 100644 --- a/tests/pdf/pdfTypes.spec.ts +++ b/tests/pdf/pdfTypes.spec.ts @@ -5,6 +5,7 @@ import * as pdf from "../../src/pdf"; import { PageOptions } from "../../src/input"; import { PageOptionsOperation } from "../../src"; import * as fs from "node:fs"; +import {RESOURCE_PATH} from "../index"; describe("Test pdf lib", () => { let client: mindee.Client; @@ -12,23 +13,26 @@ describe("Test pdf lib", () => { client = new mindee.Client(); }); it("should open a simple XFA form PDF.", async () => { - const inputDoc = client.docFromPath(path.join(__dirname, "../data/file_types/pdf/XfaForm.pdf")); - + const inputDoc = client.docFromPath( + path.join(RESOURCE_PATH, "file_types/pdf/XfaForm.pdf") + ); await inputDoc.init(); expect(await pdf.countPages(inputDoc.fileObject)).to.eq(1); }); it("should open an encrypted XFA form PDF.", async () => { - const inputDoc = client.docFromPath(path.join(__dirname, "../data/file_types/pdf/XfaForm_15p_encrypted.pdf")); - + const inputDoc = client.docFromPath( + path.join(RESOURCE_PATH, "file_types/pdf/XfaForm_15p_encrypted.pdf") + ); await inputDoc.init(); expect(await pdf.countPages(inputDoc.fileObject)).to.eq(15); }); it("should be able to perform page operations on an encrypted XFA form PDF.", async () => { - const inputDoc = client.docFromPath(path.join(__dirname, "../data/file_types/pdf/XfaForm_15p_encrypted.pdf")); - + const inputDoc = client.docFromPath( + path.join(RESOURCE_PATH, "file_types/pdf/XfaForm_15p_encrypted.pdf") + ); await inputDoc.init(); const pageOptions: PageOptions = { diff --git a/tests/api/asyncResponse.spec.ts b/tests/v1/api/asyncResponse.spec.ts similarity index 78% rename from tests/api/asyncResponse.spec.ts rename to tests/v1/api/asyncResponse.spec.ts index 066e59197..026dbfdaf 100644 --- a/tests/api/asyncResponse.spec.ts +++ b/tests/v1/api/asyncResponse.spec.ts @@ -1,15 +1,16 @@ import { expect } from "chai"; -import { AsyncPredictResponse } from "../../src"; +import { AsyncPredictResponse } from "../../../src"; import { promises as fs } from "fs"; import * as path from "path"; -import { StringDict } from "../../src/parsing/common"; -import { InvoiceSplitterV1 } from "../../src/product"; -import { cleanRequestData, isValidAsyncResponse } from "../../src/http"; +import { StringDict } from "../../../src/parsing/common"; +import { InvoiceSplitterV1 } from "../../../src/product"; +import { cleanRequestData, isValidAsyncResponse } from "../../../src/http"; +import { RESOURCE_PATH } from "../../index"; -describe("Asynchronous API predict response", () => { +describe("MindeeV1 - Asynchronous API predict response", () => { it("should parse a successful enqueue", async () => { const jsonData = await fs.readFile( - path.resolve("tests/data/async/post_success.json") + path.join(RESOURCE_PATH, "async/post_success.json") ); const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), @@ -25,7 +26,7 @@ describe("Asynchronous API predict response", () => { it("should parse a failed enqueue", async () => { const jsonData = await fs.readFile( - path.resolve("tests/data/async/post_fail_forbidden.json") + path.join(RESOURCE_PATH, "async/post_fail_forbidden.json") ); const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), @@ -35,7 +36,7 @@ describe("Asynchronous API predict response", () => { it("should parse a failed job", async () => { const jsonData = await fs.readFile( - path.resolve("tests/data/async/get_failed_job_error.json") + path.join(RESOURCE_PATH, "async/get_failed_job_error.json") ); const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), @@ -45,7 +46,7 @@ describe("Asynchronous API predict response", () => { it("should parse a job in progress", async () => { const jsonData = await fs.readFile( - path.resolve("tests/data/async/get_processing.json") + path.join(RESOURCE_PATH, "async/get_processing.json") ); const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), @@ -61,7 +62,7 @@ describe("Asynchronous API predict response", () => { it("should parse a completed job", async () => { const jsonData = await fs.readFile( - path.resolve("tests/data/async/get_completed.json") + path.join(RESOURCE_PATH, "async/get_completed.json") ); const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), diff --git a/tests/api/endpoint.spec.ts b/tests/v1/api/endpoint.spec.ts similarity index 83% rename from tests/api/endpoint.spec.ts rename to tests/v1/api/endpoint.spec.ts index 224b9a652..fb7902073 100644 --- a/tests/api/endpoint.spec.ts +++ b/tests/v1/api/endpoint.spec.ts @@ -1,9 +1,10 @@ import nock from "nock"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../src/"; +import * as mindee from "../../../src"; +import { RESOURCE_PATH } from "../../index"; -describe("HTTP calls", () => { +describe("MindeeV1 - HTTP calls", () => { before(function() { process.env.MINDEE_API_HOST = "local.mindee.net"; }); @@ -22,14 +23,15 @@ describe("HTTP calls", () => { .replyWithFile(httpCode, path.resolve(httpResultFile)); const mindeeClient = new mindee.Client({ apiKey: "my-api-key", debug: true }); - const doc = mindeeClient.docFromPath(path.resolve("tests/data/file_types/pdf/blank_1.pdf")); - + const doc = mindeeClient.docFromPath( + path.join(RESOURCE_PATH, "file_types/pdf/blank_1.pdf") + ); return await mindeeClient.parse(mindee.product.InvoiceV4, doc); } it("should fail on 400 response with object", async () => { try { - await sendRequest(400, path.resolve("tests/data/errors/error_400_with_object_in_detail.json")); + await sendRequest(400, path.join(RESOURCE_PATH, "errors/error_400_with_object_in_detail.json")); } catch (error: any) { expect(error.name).to.be.equals("MindeeHttp400Error"); expect(error.code).to.be.equals(400); @@ -40,7 +42,7 @@ describe("HTTP calls", () => { it("should fail on 401 response", async () => { try { - await sendRequest(401, path.resolve("tests/data/errors/error_401_no_token.json")); + await sendRequest(401, path.join(RESOURCE_PATH, "errors/error_401_no_token.json")); } catch (error: any) { expect(error.name).to.be.equals("MindeeHttp401Error"); expect(error.code).to.be.equals(401); @@ -51,7 +53,7 @@ describe("HTTP calls", () => { it("should fail on 429 response", async () => { try { - await sendRequest(429, path.resolve("tests/data/errors/error_429_too_many_requests.json")); + await sendRequest(429, path.join(RESOURCE_PATH, "errors/error_429_too_many_requests.json")); } catch (error: any) { expect(error.name).to.be.equals("MindeeHttp429Error"); expect(error.code).to.be.equals(429); @@ -61,7 +63,7 @@ describe("HTTP calls", () => { }); it("should fail on 500 response", async () => { try { - await sendRequest(500, path.resolve("tests/data/errors/error_500_inference_fail.json")); + await sendRequest(500, path.join(RESOURCE_PATH, "errors/error_500_inference_fail.json")); } catch (error: any) { expect(error.name).to.be.equals("MindeeHttp500Error"); expect(error.code).to.be.equals(500); @@ -72,7 +74,7 @@ describe("HTTP calls", () => { it("should fail on HTML response", async () => { try { - await sendRequest(500, path.resolve("tests/data/errors/error_50x.html")); + await sendRequest(500, path.join(RESOURCE_PATH, "errors/error_50x.html")); } catch (error: any) { expect(error.name).to.be.equals("MindeeHttp500Error"); expect(error.code).to.be.equals(500); diff --git a/tests/api/feedbackResponse.spec.ts b/tests/v1/api/feedbackResponse.spec.ts similarity index 64% rename from tests/api/feedbackResponse.spec.ts rename to tests/v1/api/feedbackResponse.spec.ts index 927f52e8a..e5303accd 100644 --- a/tests/api/feedbackResponse.spec.ts +++ b/tests/v1/api/feedbackResponse.spec.ts @@ -1,12 +1,13 @@ import path from "path"; import { expect } from "chai"; import { promises as fs } from "fs"; -import { FeedbackResponse } from "../../src/parsing/common"; +import { FeedbackResponse } from "../../../src/parsing/common"; +import { RESOURCE_PATH } from "../../index"; -describe("Feedback response", () => { +describe("MindeeV1 - Feedback response", () => { it("should load an empty feedback response", async () => { const jsonData = await fs.readFile( - path.resolve("tests/data/products/invoices/feedback_response/empty.json") + path.join(RESOURCE_PATH, "products/invoices/feedback_response/empty.json") ); const feedbackResponse: FeedbackResponse = new FeedbackResponse(JSON.parse(jsonData.toString())); expect(feedbackResponse.feedback).to.not.be.undefined; diff --git a/tests/v1/api/invoiceSplitterReconstruction.spec.ts b/tests/v1/api/invoiceSplitterReconstruction.spec.ts new file mode 100644 index 000000000..09d019c15 --- /dev/null +++ b/tests/v1/api/invoiceSplitterReconstruction.spec.ts @@ -0,0 +1,42 @@ +import { expect } from "chai"; +import { promises as fs } from "fs"; +import * as path from "path"; +import { Document } from "../../../src"; +import { InvoiceSplitterV1 } from "../../../src/product"; +import { extractInvoices } from "../../../src/imageOperations"; +import { PathInput } from "../../../src"; + +describe("MindeeV1 - A Multipage Invoice Document", () => { + it("should be split into the proper invoices", async () => { + const jsonData = await fs.readFile( + path.resolve("tests/data/products/invoice_splitter/response_v1/complete.json") + ); + const sourceDoc = new PathInput({ inputPath: path.resolve("tests/data/products/invoice_splitter/invoice_5p.pdf") }); + await sourceDoc.init(); + const response = JSON.parse(jsonData.toString()); + const doc = new Document(InvoiceSplitterV1, response.document); + const extractedInvoices = await extractInvoices(sourceDoc, doc.inference, false); + expect(extractedInvoices.length).to.be.equals(3); + expect(extractedInvoices[0].pageIdMin).to.be.equal(0); + expect(extractedInvoices[0].pageIdMax).to.be.equal(0); + expect(extractedInvoices[1].pageIdMin).to.be.equal(1); + expect(extractedInvoices[1].pageIdMax).to.be.equal(3); + expect(extractedInvoices[2].pageIdMin).to.be.equal(4); + expect(extractedInvoices[2].pageIdMax).to.be.equal(4); + for (const extractedInvoice of extractedInvoices) { + expect(Buffer.byteLength(extractedInvoice.asSource().fileObject)).to.be.lessThan(10485760); + expect(Buffer.byteLength(extractedInvoice.asSource().fileObject)).to.be.greaterThan(100000); + } + }); + it("should be split differently if confidences are taken into account.", async () => { + const jsonData = await fs.readFile( + path.resolve("tests/data/products/invoice_splitter/response_v1/complete.json") + ); + const sourceDoc = new PathInput({ inputPath: path.resolve("tests/data/products/invoice_splitter/invoice_5p.pdf") }); + await sourceDoc.init(); + const response = JSON.parse(jsonData.toString()); + const doc = new Document(InvoiceSplitterV1, response.document); + const extractedConfidentInvoices = await extractInvoices(sourceDoc, doc.inference, true); + expect(extractedConfidentInvoices.length).to.be.equals(2); + }); +}); diff --git a/tests/v1/api/multiReceiptsReconstruction.spec.ts b/tests/v1/api/multiReceiptsReconstruction.spec.ts new file mode 100644 index 000000000..b23b11e6e --- /dev/null +++ b/tests/v1/api/multiReceiptsReconstruction.spec.ts @@ -0,0 +1,32 @@ +import { expect } from "chai"; +import { promises as fs } from "fs"; +import * as path from "path"; +import { Document } from "../../../src"; +import { MultiReceiptsDetectorV1 } from "../../../src/product"; +import { extractReceipts } from "../../../src/imageOperations"; +import { PathInput } from "../../../src"; +import { RESOURCE_PATH } from "../../index"; + +describe("MindeeV1 - A Multi-Receipt Document", () => { + it("should be split into the proper receipts", async () => { + const jsonData = await fs.readFile( + path.resolve("tests/data/products/multi_receipts_detector/response_v1/complete.json") + ); + const sourceDoc = new PathInput( + { inputPath: path.join(RESOURCE_PATH, "products/multi_receipts_detector/default_sample.jpg") } + ); + await sourceDoc.init(); + const response = JSON.parse(jsonData.toString()); + const doc = new Document(MultiReceiptsDetectorV1, response.document); + const extractedReceipts = await extractReceipts(sourceDoc, doc.inference); + expect(extractedReceipts.length).to.be.equals(6); + let i = 0; + for (const extractedReceipt of extractedReceipts) { + expect(extractedReceipt.pageId).to.be.equal(0); + expect(extractedReceipt.receiptId).to.be.equal(i); + expect(Buffer.byteLength(extractedReceipt.asSource().fileObject)).to.be.lessThan(10485760); + expect(Buffer.byteLength(extractedReceipt.asSource().fileObject)).to.be.greaterThan(100000); + i++; + } + }); +}); diff --git a/tests/api/response.spec.ts b/tests/v1/api/response.spec.ts similarity index 80% rename from tests/api/response.spec.ts rename to tests/v1/api/response.spec.ts index c8683d487..293f502d3 100644 --- a/tests/api/response.spec.ts +++ b/tests/v1/api/response.spec.ts @@ -1,16 +1,17 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import { PredictResponse } from "../../src"; -import { CustomV1, InvoiceV4, ReceiptV5 } from "../../src/product"; +import { PredictResponse } from "../../../src"; +import { CustomV1, InvoiceV4, ReceiptV5 } from "../../../src/product"; +import { RESOURCE_PATH } from "../../index"; const dataPath = { - receiptV5: "tests/data/products/expense_receipts/response_v5/complete.json", - invoiceV4: "tests/data/products/invoices/response_v4/complete.json", - customV1: "tests/data/products/custom/response_v1/complete.json", + receiptV5: path.join(RESOURCE_PATH, "products/expense_receipts/response_v5/complete.json"), + invoiceV4: path.join(RESOURCE_PATH, "products/invoices/response_v4/complete.json"), + customV1: path.join(RESOURCE_PATH, "products/custom/response_v1/complete.json"), }; -describe("Synchronous API predict response", () => { +describe("MindeeV1 - Synchronous API predict response", () => { it("should build a Receipt response", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.receiptV5)); const httpResponse = JSON.parse(jsonData.toString()); diff --git a/tests/extras/extras.integration.ts b/tests/v1/extras/extras.integration.ts similarity index 76% rename from tests/extras/extras.integration.ts rename to tests/v1/extras/extras.integration.ts index be5ddd8e8..36eade9f2 100644 --- a/tests/extras/extras.integration.ts +++ b/tests/v1/extras/extras.integration.ts @@ -1,9 +1,10 @@ import { expect } from "chai"; -import * as mindee from "../../src/"; +import * as mindee from "../../../src"; +import path from "path"; +import { RESOURCE_PATH } from "../../index"; - -describe("Mindee Client Integration Tests", async () => { +describe("MindeeV1 - Extras Integration Tests", async () => { let client: mindee.Client; beforeEach(() => { @@ -12,7 +13,7 @@ describe("Mindee Client Integration Tests", async () => { it("should send cropper extra", async () => { const sample = client.docFromPath( - "tests/data/products/invoices/default_sample.jpg" + path.join(RESOURCE_PATH, "products/invoices/default_sample.jpg") ); await sample.init(); const response = await client.parse( @@ -23,7 +24,7 @@ describe("Mindee Client Integration Tests", async () => { it("should send full text OCR extra", async () => { const sample = client.docFromPath( - "tests/data/products/international_id/default_sample.jpg" + path.join(RESOURCE_PATH, "products/international_id/default_sample.jpg") ); await sample.init(); const response = await client.enqueueAndParse( @@ -35,7 +36,7 @@ describe("Mindee Client Integration Tests", async () => { it("should send OCR words synchronously", async () => { const sample = client.docFromPath( - "tests/data/products/financial_document/default_sample.jpg" + path.join(RESOURCE_PATH, "products/financial_document/default_sample.jpg") ); await sample.init(); const response = await client.parse( @@ -48,7 +49,7 @@ describe("Mindee Client Integration Tests", async () => { it("should send OCR words asynchronously", async () => { const sample = client.docFromPath( - "tests/data/products/financial_document/default_sample.jpg" + path.join(RESOURCE_PATH, "products/financial_document/default_sample.jpg") ); await sample.init(); const response = await client.enqueueAndParse( diff --git a/tests/extras/fullTextOcr.spec.ts b/tests/v1/extras/fullTextOcr.spec.ts similarity index 79% rename from tests/extras/fullTextOcr.spec.ts rename to tests/v1/extras/fullTextOcr.spec.ts index 61a83a2a3..138e59a01 100644 --- a/tests/extras/fullTextOcr.spec.ts +++ b/tests/v1/extras/fullTextOcr.spec.ts @@ -1,10 +1,11 @@ -import {promises as fs} from "fs"; +import { promises as fs } from "fs"; import path from "path"; -import {expect} from "chai"; -import {AsyncPredictResponse} from "../../src"; -import {InternationalIdV2} from "../../src/product"; +import { expect } from "chai"; +import { AsyncPredictResponse } from "../../../src"; +import { InternationalIdV2 } from "../../../src/product"; +import { RESOURCE_PATH } from "../../index"; -const fullTextOcrDir = "tests/data/extras/full_text_ocr"; +const fullTextOcrDir = path.join(RESOURCE_PATH, "extras/full_text_ocr"); async function loadDocument() { const jsonData = await fs.readFile(path.resolve(fullTextOcrDir, "complete.json")); @@ -20,7 +21,7 @@ async function loadPage() { )?.document?.inference.pages[0]?.extras?.fullTextOcr.toString(); } -describe("Full Text Ocr", async () => { +describe("MindeeV1 - Full Text Ocr", async () => { it("should load a Full Text OCR prediction at document level", async () => { const expectedText = (await fs.readFile(path.resolve(fullTextOcrDir, "full_text_ocr.txt"))).toString(); const fullTextOcr = await loadDocument(); diff --git a/tests/inputs/sources.integration.ts b/tests/v1/input/sources.integration.ts similarity index 88% rename from tests/inputs/sources.integration.ts rename to tests/v1/input/sources.integration.ts index b8780d7fa..7eed70502 100644 --- a/tests/inputs/sources.integration.ts +++ b/tests/v1/input/sources.integration.ts @@ -1,16 +1,18 @@ -import * as mindee from "../../src/"; -import { InvoiceV4 } from "../../src/product"; +import * as mindee from "../../../src"; +import { InvoiceV4 } from "../../../src/product"; import { expect } from "chai"; import { promises as fs } from "fs"; import { createReadStream } from "node:fs"; +import path from "path"; +import { RESOURCE_PATH } from "../../index"; -describe("Given a client", async () => { +describe("MindeeV1 - File Input Integration Tests", async () => { let client: mindee.Client; let filePath: string; beforeEach(() => { client = new mindee.Client(); - filePath = "tests/data/products/invoices/default_sample.jpg"; + filePath = path.join(RESOURCE_PATH, "products/invoices/default_sample.jpg"); }); it("should send a document from a direct path.", async () => { diff --git a/tests/inputs/urlInputSource.integration.ts b/tests/v1/input/urlInputSource.integration.ts similarity index 79% rename from tests/inputs/urlInputSource.integration.ts rename to tests/v1/input/urlInputSource.integration.ts index 1b85d309c..06c535279 100644 --- a/tests/inputs/urlInputSource.integration.ts +++ b/tests/v1/input/urlInputSource.integration.ts @@ -1,9 +1,9 @@ import { expect } from "chai"; -import { UrlInput } from "../../src/input"; -import { Client } from "../../src"; -import { InvoiceV4 } from "../../src/product"; +import { UrlInput } from "../../../src"; +import { Client } from "../../../src"; +import { InvoiceV4 } from "../../../src/product"; -describe("UrlInput Integration Test", async () => { +describe("MindeeV1 - URL Input Integration Test", async () => { it("should retrieve and parse a remote file", async () => { const apiKey = process.env.MINDEE_API_KEY; if (!apiKey) { diff --git a/tests/parsing/standard/amount.spec.ts b/tests/v1/parsing/standard/amount.spec.ts similarity index 93% rename from tests/parsing/standard/amount.spec.ts rename to tests/v1/parsing/standard/amount.spec.ts index 25d66c79d..b21452cb5 100644 --- a/tests/parsing/standard/amount.spec.ts +++ b/tests/v1/parsing/standard/amount.spec.ts @@ -1,4 +1,4 @@ -import { AmountField } from "../../../src/parsing/standard"; +import { AmountField } from "../../../../src/parsing/standard"; import { expect } from "chai"; describe("Test AmountField field", () => { diff --git a/tests/parsing/standard/classification.spec.ts b/tests/v1/parsing/standard/classification.spec.ts similarity index 88% rename from tests/parsing/standard/classification.spec.ts rename to tests/v1/parsing/standard/classification.spec.ts index d56db0e90..f0073a4b2 100644 --- a/tests/parsing/standard/classification.spec.ts +++ b/tests/v1/parsing/standard/classification.spec.ts @@ -1,4 +1,4 @@ -import { ClassificationField } from "../../../src/parsing/standard"; +import { ClassificationField } from "../../../../src/parsing/standard"; import { expect } from "chai"; describe("Test Classification field", () => { diff --git a/tests/parsing/standard/date.spec.ts b/tests/v1/parsing/standard/date.spec.ts similarity index 94% rename from tests/parsing/standard/date.spec.ts rename to tests/v1/parsing/standard/date.spec.ts index 433a7ff58..ef120f24d 100644 --- a/tests/parsing/standard/date.spec.ts +++ b/tests/v1/parsing/standard/date.spec.ts @@ -1,4 +1,4 @@ -import { DateField } from "../../../src/parsing/standard"; +import { DateField } from "../../../../src/parsing/standard"; import { expect } from "chai"; describe("Test Date field", () => { diff --git a/tests/parsing/standard/field.spec.ts b/tests/v1/parsing/standard/field.spec.ts similarity index 97% rename from tests/parsing/standard/field.spec.ts rename to tests/v1/parsing/standard/field.spec.ts index 642617750..e68cd2fdb 100644 --- a/tests/parsing/standard/field.spec.ts +++ b/tests/v1/parsing/standard/field.spec.ts @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { Field } from "../../../src/parsing/standard"; +import { Field } from "../../../../src/parsing/standard"; describe("Test different inits of Field", () => { it("Should create a Field", () => { diff --git a/tests/parsing/standard/locale.spec.ts b/tests/v1/parsing/standard/locale.spec.ts similarity index 95% rename from tests/parsing/standard/locale.spec.ts rename to tests/v1/parsing/standard/locale.spec.ts index 0f1c66890..0aa8d786b 100644 --- a/tests/parsing/standard/locale.spec.ts +++ b/tests/v1/parsing/standard/locale.spec.ts @@ -1,4 +1,4 @@ -import { LocaleField } from "../../../src/parsing/standard"; +import { LocaleField } from "../../../../src/parsing/standard"; import { expect } from "chai"; describe("Test LocaleField field", () => { diff --git a/tests/parsing/standard/orientation.spec.ts b/tests/v1/parsing/standard/orientation.spec.ts similarity index 92% rename from tests/parsing/standard/orientation.spec.ts rename to tests/v1/parsing/standard/orientation.spec.ts index 2ebee99c2..97d95a4a8 100644 --- a/tests/parsing/standard/orientation.spec.ts +++ b/tests/v1/parsing/standard/orientation.spec.ts @@ -1,4 +1,4 @@ -import { OrientationField } from "../../../src/parsing/common"; +import { OrientationField } from "../../../../src/parsing/common"; import { expect } from "chai"; describe("Test Orientation field", () => { diff --git a/tests/parsing/standard/paymentDetails.spec.ts b/tests/v1/parsing/standard/paymentDetails.spec.ts similarity index 96% rename from tests/parsing/standard/paymentDetails.spec.ts rename to tests/v1/parsing/standard/paymentDetails.spec.ts index ff5601dad..0f2e723b1 100644 --- a/tests/parsing/standard/paymentDetails.spec.ts +++ b/tests/v1/parsing/standard/paymentDetails.spec.ts @@ -1,4 +1,4 @@ -import { PaymentDetailsField } from "../../../src/parsing/standard"; +import { PaymentDetailsField } from "../../../../src/parsing/standard"; import { expect } from "chai"; describe("Test PaymentDetailsField field", () => { diff --git a/tests/parsing/standard/position.spec.ts b/tests/v1/parsing/standard/position.spec.ts similarity index 95% rename from tests/parsing/standard/position.spec.ts rename to tests/v1/parsing/standard/position.spec.ts index ff00813eb..eee669132 100644 --- a/tests/parsing/standard/position.spec.ts +++ b/tests/v1/parsing/standard/position.spec.ts @@ -1,4 +1,4 @@ -import { PositionField } from "../../../src/parsing/standard"; +import { PositionField } from "../../../../src/parsing/standard"; import { expect } from "chai"; describe("Test Position field", () => { diff --git a/tests/parsing/standard/tax.spec.ts b/tests/v1/parsing/standard/tax.spec.ts similarity index 95% rename from tests/parsing/standard/tax.spec.ts rename to tests/v1/parsing/standard/tax.spec.ts index b0156faec..62e9c703a 100644 --- a/tests/parsing/standard/tax.spec.ts +++ b/tests/v1/parsing/standard/tax.spec.ts @@ -1,4 +1,4 @@ -import { TaxField } from "../../../src/parsing/standard"; +import { TaxField } from "../../../../src/parsing/standard"; import { expect } from "chai"; describe("Test Tax field", () => { diff --git a/tests/parsing/standard/text.spec.ts b/tests/v1/parsing/standard/text.spec.ts similarity index 94% rename from tests/parsing/standard/text.spec.ts rename to tests/v1/parsing/standard/text.spec.ts index 1c05b3477..23c62d8e3 100644 --- a/tests/parsing/standard/text.spec.ts +++ b/tests/v1/parsing/standard/text.spec.ts @@ -1,4 +1,4 @@ -import { StringField } from "../../../src/parsing/standard"; +import { StringField } from "../../../../src/parsing/standard"; import { expect } from "chai"; describe("Test String field", () => { diff --git a/tests/product/barcodeReader/barcodeReaderV1.spec.ts b/tests/v1/product/barcodeReader/barcodeReaderV1.spec.ts similarity index 96% rename from tests/product/barcodeReader/barcodeReaderV1.spec.ts rename to tests/v1/product/barcodeReader/barcodeReaderV1.spec.ts index e60577309..b8f79865f 100644 --- a/tests/product/barcodeReader/barcodeReaderV1.spec.ts +++ b/tests/v1/product/barcodeReader/barcodeReaderV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/billOfLading/billOfLadingV1.spec.ts b/tests/v1/product/billOfLading/billOfLadingV1.spec.ts similarity index 98% rename from tests/product/billOfLading/billOfLadingV1.spec.ts rename to tests/v1/product/billOfLading/billOfLadingV1.spec.ts index 20bb68b40..0daada930 100644 --- a/tests/product/billOfLading/billOfLadingV1.spec.ts +++ b/tests/v1/product/billOfLading/billOfLadingV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/businessCard/businessCardV1.spec.ts b/tests/v1/product/businessCard/businessCardV1.spec.ts similarity index 97% rename from tests/product/businessCard/businessCardV1.spec.ts rename to tests/v1/product/businessCard/businessCardV1.spec.ts index db57f5dce..166ff9400 100644 --- a/tests/product/businessCard/businessCardV1.spec.ts +++ b/tests/v1/product/businessCard/businessCardV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/cropper/cropperV1.spec.ts b/tests/v1/product/cropper/cropperV1.spec.ts similarity index 97% rename from tests/product/cropper/cropperV1.spec.ts rename to tests/v1/product/cropper/cropperV1.spec.ts index 8f4ca54d7..cbf6b98c6 100644 --- a/tests/product/cropper/cropperV1.spec.ts +++ b/tests/v1/product/cropper/cropperV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/custom/customDocument.spec.ts b/tests/v1/product/custom/customDocument.spec.ts similarity index 95% rename from tests/product/custom/customDocument.spec.ts rename to tests/v1/product/custom/customDocument.spec.ts index 9378f6635..8b40024ae 100644 --- a/tests/product/custom/customDocument.spec.ts +++ b/tests/v1/product/custom/customDocument.spec.ts @@ -1,11 +1,11 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; -import { CustomV1Document } from "../../../src/product/custom/customV1Document"; -import { Page } from "../../../src/parsing/common"; -import { CropperExtra } from "../../../src/parsing/common/extras/cropperExtra"; -import { CustomV1 } from "../../../src/product"; +import * as mindee from "../../../../src"; +import { CustomV1Document } from "../../../../src/product/custom/customV1Document"; +import { Page } from "../../../../src/parsing/common"; +import { CropperExtra } from "../../../../src/parsing/common/extras/cropperExtra"; +import { CustomV1 } from "../../../../src/product"; const dataPath = { complete: "tests/data/products/custom/response_v1/complete.json", diff --git a/tests/product/custom/lineItems.spec.ts b/tests/v1/product/custom/lineItems.spec.ts similarity index 97% rename from tests/product/custom/lineItems.spec.ts rename to tests/v1/product/custom/lineItems.spec.ts index 128690f54..f767e118e 100644 --- a/tests/product/custom/lineItems.spec.ts +++ b/tests/v1/product/custom/lineItems.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import { expect } from "chai"; -import { CustomV1 } from "../../../src/product"; -import { CustomLine } from "../../../src/parsing/custom"; +import { CustomV1 } from "../../../../src/product"; +import { CustomLine } from "../../../../src/parsing/custom"; const dataPath = { singleTable01: diff --git a/tests/product/deliveryNote/deliveryNoteV1.spec.ts b/tests/v1/product/deliveryNote/deliveryNoteV1.spec.ts similarity index 97% rename from tests/product/deliveryNote/deliveryNoteV1.spec.ts rename to tests/v1/product/deliveryNote/deliveryNoteV1.spec.ts index 453d3de81..ef6f66e85 100644 --- a/tests/product/deliveryNote/deliveryNoteV1.spec.ts +++ b/tests/v1/product/deliveryNote/deliveryNoteV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/driverLicense/driverLicenseV1.spec.ts b/tests/v1/product/driverLicense/driverLicenseV1.spec.ts similarity index 97% rename from tests/product/driverLicense/driverLicenseV1.spec.ts rename to tests/v1/product/driverLicense/driverLicenseV1.spec.ts index 9703b5765..eb6921105 100644 --- a/tests/product/driverLicense/driverLicenseV1.spec.ts +++ b/tests/v1/product/driverLicense/driverLicenseV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/financialDocument/financialDocumentV1.spec.ts b/tests/v1/product/financialDocument/financialDocumentV1.spec.ts similarity index 99% rename from tests/product/financialDocument/financialDocumentV1.spec.ts rename to tests/v1/product/financialDocument/financialDocumentV1.spec.ts index de93c07a0..e44c4b6c1 100644 --- a/tests/product/financialDocument/financialDocumentV1.spec.ts +++ b/tests/v1/product/financialDocument/financialDocumentV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { receiptComplete: diff --git a/tests/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts similarity index 96% rename from tests/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts rename to tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts index 68a4d684d..184696e92 100644 --- a/tests/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts +++ b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts similarity index 97% rename from tests/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts rename to tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts index d8f34cfac..850d80f4e 100644 --- a/tests/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts +++ b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/fr/carteGrise/carteGriseV1.spec.ts b/tests/v1/product/fr/carteGrise/carteGriseV1.spec.ts similarity index 98% rename from tests/product/fr/carteGrise/carteGriseV1.spec.ts rename to tests/v1/product/fr/carteGrise/carteGriseV1.spec.ts index d970e9435..4cdebba04 100644 --- a/tests/product/fr/carteGrise/carteGriseV1.spec.ts +++ b/tests/v1/product/fr/carteGrise/carteGriseV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/fr/energyBill/energyBillV1.spec.ts b/tests/v1/product/fr/energyBill/energyBillV1.spec.ts similarity index 98% rename from tests/product/fr/energyBill/energyBillV1.spec.ts rename to tests/v1/product/fr/energyBill/energyBillV1.spec.ts index e9053ac43..38fb11a12 100644 --- a/tests/product/fr/energyBill/energyBillV1.spec.ts +++ b/tests/v1/product/fr/energyBill/energyBillV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/fr/healthCard/healthCardV1.spec.ts b/tests/v1/product/fr/healthCard/healthCardV1.spec.ts similarity index 97% rename from tests/product/fr/healthCard/healthCardV1.spec.ts rename to tests/v1/product/fr/healthCard/healthCardV1.spec.ts index 0bef8af1b..b09312ff1 100644 --- a/tests/product/fr/healthCard/healthCardV1.spec.ts +++ b/tests/v1/product/fr/healthCard/healthCardV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/fr/idCard/idCardV1.spec.ts b/tests/v1/product/fr/idCard/idCardV1.spec.ts similarity index 98% rename from tests/product/fr/idCard/idCardV1.spec.ts rename to tests/v1/product/fr/idCard/idCardV1.spec.ts index 3227d044a..74c02a32e 100644 --- a/tests/product/fr/idCard/idCardV1.spec.ts +++ b/tests/v1/product/fr/idCard/idCardV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/fr/idCard/idCardV2.spec.ts b/tests/v1/product/fr/idCard/idCardV2.spec.ts similarity index 98% rename from tests/product/fr/idCard/idCardV2.spec.ts rename to tests/v1/product/fr/idCard/idCardV2.spec.ts index 573914dfa..a43271a08 100644 --- a/tests/product/fr/idCard/idCardV2.spec.ts +++ b/tests/v1/product/fr/idCard/idCardV2.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/fr/payslip/payslipV2.spec.ts b/tests/v1/product/fr/payslip/payslipV2.spec.ts similarity index 98% rename from tests/product/fr/payslip/payslipV2.spec.ts rename to tests/v1/product/fr/payslip/payslipV2.spec.ts index 4394d4a50..c431a3b4a 100644 --- a/tests/product/fr/payslip/payslipV2.spec.ts +++ b/tests/v1/product/fr/payslip/payslipV2.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/fr/payslip/payslipV3.spec.ts b/tests/v1/product/fr/payslip/payslipV3.spec.ts similarity index 98% rename from tests/product/fr/payslip/payslipV3.spec.ts rename to tests/v1/product/fr/payslip/payslipV3.spec.ts index 6b0a7a95a..1fcb2a4f0 100644 --- a/tests/product/fr/payslip/payslipV3.spec.ts +++ b/tests/v1/product/fr/payslip/payslipV3.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/generated/generatedList.spec.ts b/tests/v1/product/generated/generatedList.spec.ts similarity index 85% rename from tests/product/generated/generatedList.spec.ts rename to tests/v1/product/generated/generatedList.spec.ts index d0b1e33c5..b8ce62f84 100644 --- a/tests/product/generated/generatedList.spec.ts +++ b/tests/v1/product/generated/generatedList.spec.ts @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { GeneratedListField } from "../../../src/parsing/generated"; +import { GeneratedListField } from "../../../../src/parsing/generated"; describe("Generated List Field Objects", async () => { it("should properly format floats.", async () => { diff --git a/tests/product/generated/generatedObject.spec.ts b/tests/v1/product/generated/generatedObject.spec.ts similarity index 87% rename from tests/product/generated/generatedObject.spec.ts rename to tests/v1/product/generated/generatedObject.spec.ts index 921996365..7b9b06ec3 100644 --- a/tests/product/generated/generatedObject.spec.ts +++ b/tests/v1/product/generated/generatedObject.spec.ts @@ -1,5 +1,5 @@ import { expect } from "chai"; -import {GeneratedObjectField} from "../../../src/parsing/generated"; +import { GeneratedObjectField } from "../../../../src/parsing/generated"; describe("Generated Object Field", async () => { it("should properly format booleans.", async () => { diff --git a/tests/product/generated/generatedV1.spec.ts b/tests/v1/product/generated/generatedV1.spec.ts similarity index 59% rename from tests/product/generated/generatedV1.spec.ts rename to tests/v1/product/generated/generatedV1.spec.ts index 49f3318f8..4746f78e1 100644 --- a/tests/product/generated/generatedV1.spec.ts +++ b/tests/v1/product/generated/generatedV1.spec.ts @@ -1,12 +1,12 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; -import { Page } from "../../../src"; -import { GeneratedV1 } from "../../../src/product"; -import { GeneratedListField, GeneratedObjectField } from "../../../src/parsing/generated"; -import { GeneratedV1Page } from "../../../src/product/generated/generatedV1Page"; -import { StringField } from "../../../src/parsing/standard"; +import * as mindee from "../../../../src"; +import { Page } from "../../../../src"; +import { GeneratedV1 } from "../../../../src/product"; +import { GeneratedListField, GeneratedObjectField } from "../../../../src/parsing/generated"; +import { GeneratedV1Page } from "../../../../src/product/generated/generatedV1Page"; +import { StringField } from "../../../../src/parsing/standard"; const dataPathInternationalId = { complete: "tests/data/products/generated/response_v1/complete_international_id_v1.json", @@ -30,26 +30,26 @@ describe("Generated Document Object initialization on an OTS invoice", async () const jsonDataNA = await fs.readFile(path.resolve(dataPathInvoice.empty)); const response = JSON.parse(jsonDataNA.toString()); const doc = new mindee.Document(GeneratedV1, response.document); - expect(doc.inference.prediction.fields.get('customer_address').value).to.be.undefined; - expect(doc.inference.prediction.fields.get('customer_company_registrations').values.length).to.equals(0); - expect(doc.inference.prediction.fields.get('customer_name').value).to.be.undefined; - expect(doc.inference.prediction.fields.get('date').value).to.be.undefined; - expect(doc.inference.prediction.fields.get('document_type').value).to.equals("INVOICE"); - expect(doc.inference.prediction.fields.get('due_date').value).be.undefined; - expect(doc.inference.prediction.fields.get('invoice_number').value).be.undefined; - expect(doc.inference.prediction.fields.get('line_items')).to.be.an.instanceOf(GeneratedListField) - expect(doc.inference.prediction.fields.get('line_items').values.length).to.equals(0); - expect(doc.inference.prediction.fields.get('locale')).to.be.an.instanceOf(GeneratedObjectField); - expect(doc.inference.prediction.fields.get('locale').currency).to.be.null; - expect(doc.inference.prediction.fields.get('locale').language).to.be.null; - expect(doc.inference.prediction.fields.get('reference_numbers').values.length).to.equals(0); - expect(doc.inference.prediction.fields.get('supplier_address').value).to.be.undefined; - expect(doc.inference.prediction.fields.get('supplier_company_registrations').values.length).to.equals(0); - expect(doc.inference.prediction.fields.get('supplier_name').value).to.be.undefined; - expect(doc.inference.prediction.fields.get('supplier_payment_details').values.length).to.equals(0); - expect(doc.inference.prediction.fields.get('taxes').values.length).to.equals(0); - expect(doc.inference.prediction.fields.get('total_amount').value).to.be.undefined; - expect(doc.inference.prediction.fields.get('total_net').value).to.be.undefined; + expect(doc.inference.prediction.fields.get("customer_address").value).to.be.undefined; + expect(doc.inference.prediction.fields.get("customer_company_registrations").values.length).to.equals(0); + expect(doc.inference.prediction.fields.get("customer_name").value).to.be.undefined; + expect(doc.inference.prediction.fields.get("date").value).to.be.undefined; + expect(doc.inference.prediction.fields.get("document_type").value).to.equals("INVOICE"); + expect(doc.inference.prediction.fields.get("due_date").value).be.undefined; + expect(doc.inference.prediction.fields.get("invoice_number").value).be.undefined; + expect(doc.inference.prediction.fields.get("line_items")).to.be.an.instanceOf(GeneratedListField); + expect(doc.inference.prediction.fields.get("line_items").values.length).to.equals(0); + expect(doc.inference.prediction.fields.get("locale")).to.be.an.instanceOf(GeneratedObjectField); + expect(doc.inference.prediction.fields.get("locale").currency).to.be.null; + expect(doc.inference.prediction.fields.get("locale").language).to.be.null; + expect(doc.inference.prediction.fields.get("reference_numbers").values.length).to.equals(0); + expect(doc.inference.prediction.fields.get("supplier_address").value).to.be.undefined; + expect(doc.inference.prediction.fields.get("supplier_company_registrations").values.length).to.equals(0); + expect(doc.inference.prediction.fields.get("supplier_name").value).to.be.undefined; + expect(doc.inference.prediction.fields.get("supplier_payment_details").values.length).to.equals(0); + expect(doc.inference.prediction.fields.get("taxes").values.length).to.equals(0); + expect(doc.inference.prediction.fields.get("total_amount").value).to.be.undefined; + expect(doc.inference.prediction.fields.get("total_net").value).to.be.undefined; const docString = await fs.readFile(path.join(dataPathInvoice.emptyDocString)); expect(doc.toString()).to.equals(docString.toString()); }); @@ -58,35 +58,35 @@ describe("Generated Document Object initialization on an OTS invoice", async () const jsonDataNA = await fs.readFile(path.resolve(dataPathInvoice.complete)); const response = JSON.parse(jsonDataNA.toString()); const page = new Page(GeneratedV1Page, response.document.inference.pages[0], 0); - expect(page.prediction.fields.get('customer_address').value).to.be.undefined; - expect(page.prediction.fields.get('customer_company_registrations').values.length).to.equals(0); - expect(page.prediction.fields.get('customer_name').value).to.be.undefined; - expect(page.prediction.fields.get('date').value).to.equals('2020-02-17'); - expect(page.prediction.fields.get('document_type').value).to.equals('INVOICE'); - expect(page.prediction.fields.get('due_date').value).to.equals('2020-02-17'); - expect(page.prediction.fields.get('invoice_number').value).to.equals('0042004801351'); - expect(page.prediction.fields.get('line_items')).to.be.an.instanceOf(GeneratedListField) - expect(page.prediction.fields.get('line_items').values[0]).to.be.an.instanceOf(GeneratedObjectField) - expect(page.prediction.fields.get('line_items').values[0].description).to.equals('S)BOIE 5X500 FEUILLES A4'); - expect(page.prediction.fields.get('line_items').values[0].product_code).to.be.null; - expect(page.prediction.fields.get('line_items').values[0].quantity).to.be.null; - expect(page.prediction.fields.get('line_items').values[0].tax_amount).to.be.null; - expect(page.prediction.fields.get('line_items').values[0].tax_rate).to.be.null; - expect(page.prediction.fields.get('line_items').values[0].total_amount).to.equals("2.63"); - expect(page.prediction.fields.get('line_items').values[0].unit_price).to.be.null; - expect(page.prediction.fields.get('locale')).to.be.an.instanceOf(GeneratedObjectField); - expect(page.prediction.fields.get('locale').currency).to.equals('EUR'); - expect(page.prediction.fields.get('locale').language).to.equals('fr'); - expect(page.prediction.fields.get('reference_numbers').values.length).to.equals(0); - expect(page.prediction.fields.get('supplier_address').value).to.be.undefined; - expect(page.prediction.fields.get('supplier_company_registrations').values.length).to.equals(0); - expect(page.prediction.fields.get('supplier_name').value).to.be.undefined; - expect(page.prediction.fields.get('supplier_payment_details').values[0].iban).to.equals('FR7640254025476501124705368'); - expect(page.prediction.fields.get('taxes').values[0].polygon.polygon).to.have.deep.members([[0.292, 0.749], [0.543, 0.749], [0.543, 0.763], [0.292, 0.763]]); - expect(page.prediction.fields.get('taxes').values[0].rate).to.equals('20.0'); - expect(page.prediction.fields.get('taxes').values[0].value).to.equals('97.98'); - expect(page.prediction.fields.get('total_amount').value).to.equals('587.95'); - expect(page.prediction.fields.get('total_net').value).to.equals('489.97'); + expect(page.prediction.fields.get("customer_address").value).to.be.undefined; + expect(page.prediction.fields.get("customer_company_registrations").values.length).to.equals(0); + expect(page.prediction.fields.get("customer_name").value).to.be.undefined; + expect(page.prediction.fields.get("date").value).to.equals("2020-02-17"); + expect(page.prediction.fields.get("document_type").value).to.equals("INVOICE"); + expect(page.prediction.fields.get("due_date").value).to.equals("2020-02-17"); + expect(page.prediction.fields.get("invoice_number").value).to.equals("0042004801351"); + expect(page.prediction.fields.get("line_items")).to.be.an.instanceOf(GeneratedListField); + expect(page.prediction.fields.get("line_items").values[0]).to.be.an.instanceOf(GeneratedObjectField); + expect(page.prediction.fields.get("line_items").values[0].description).to.equals("S)BOIE 5X500 FEUILLES A4"); + expect(page.prediction.fields.get("line_items").values[0].product_code).to.be.null; + expect(page.prediction.fields.get("line_items").values[0].quantity).to.be.null; + expect(page.prediction.fields.get("line_items").values[0].tax_amount).to.be.null; + expect(page.prediction.fields.get("line_items").values[0].tax_rate).to.be.null; + expect(page.prediction.fields.get("line_items").values[0].total_amount).to.equals("2.63"); + expect(page.prediction.fields.get("line_items").values[0].unit_price).to.be.null; + expect(page.prediction.fields.get("locale")).to.be.an.instanceOf(GeneratedObjectField); + expect(page.prediction.fields.get("locale").currency).to.equals("EUR"); + expect(page.prediction.fields.get("locale").language).to.equals("fr"); + expect(page.prediction.fields.get("reference_numbers").values.length).to.equals(0); + expect(page.prediction.fields.get("supplier_address").value).to.be.undefined; + expect(page.prediction.fields.get("supplier_company_registrations").values.length).to.equals(0); + expect(page.prediction.fields.get("supplier_name").value).to.be.undefined; + expect(page.prediction.fields.get("supplier_payment_details").values[0].iban).to.equals("FR7640254025476501124705368"); + expect(page.prediction.fields.get("taxes").values[0].polygon.polygon).to.have.deep.members([[0.292, 0.749], [0.543, 0.749], [0.543, 0.763], [0.292, 0.763]]); + expect(page.prediction.fields.get("taxes").values[0].rate).to.equals("20.0"); + expect(page.prediction.fields.get("taxes").values[0].value).to.equals("97.98"); + expect(page.prediction.fields.get("total_amount").value).to.equals("587.95"); + expect(page.prediction.fields.get("total_net").value).to.equals("489.97"); const page0String = await fs.readFile(path.join(dataPathInvoice.page0String)); expect(page.toString()).to.equals(page0String.toString()); }); @@ -95,37 +95,37 @@ describe("Generated Document Object initialization on an OTS invoice", async () const jsonDataNA = await fs.readFile(path.resolve(dataPathInvoice.complete)); const response = JSON.parse(jsonDataNA.toString()); const doc = new mindee.Document(GeneratedV1, response.document); - expect(doc.inference.prediction.fields.get('customer_address').value).to.equals('1954 Bloon Street West Toronto, ON, M6P 3K9 Canada'); - expect(doc.inference.prediction.fields.get('customer_company_registrations').values.length).to.equals(0); - expect(doc.inference.prediction.fields.get('customer_name').value).to.equals('JIRO DOI'); - expect(doc.inference.prediction.fields.get('date').value).to.equals('2020-02-17'); - expect(doc.inference.prediction.fields.get('document_type').value).to.equals('INVOICE'); - expect(doc.inference.prediction.fields.get('due_date').value).to.equals('2020-02-17'); - expect(doc.inference.prediction.fields.get('invoice_number').value).to.equals('0042004801351'); - expect(doc.inference.prediction.fields.get('line_items')).to.be.an.instanceOf(GeneratedListField) - expect(doc.inference.prediction.fields.get('line_items').values[0]).to.be.an.instanceOf(GeneratedObjectField) - expect(doc.inference.prediction.fields.get('line_items').values[0].description).to.equals('S)BOIE 5X500 FEUILLES A4'); - expect(doc.inference.prediction.fields.get('line_items').values[0].product_code).to.be.null; - expect(doc.inference.prediction.fields.get('line_items').values[0].quantity).to.be.null; - expect(doc.inference.prediction.fields.get('line_items').values[0].tax_amount).to.be.null; - expect(doc.inference.prediction.fields.get('line_items').values[0].tax_rate).to.be.null; - expect(doc.inference.prediction.fields.get('line_items').values[0].total_amount).to.equals("2.63"); - expect(doc.inference.prediction.fields.get('line_items').values[0].unit_price).to.be.null; - expect(doc.inference.prediction.fields.get('line_items').values[6].unit_price).to.equals("65.0"); - expect(doc.inference.prediction.fields.get('line_items').values[6].quantity).to.equals('1.0'); - expect(doc.inference.prediction.fields.get('locale')).to.be.an.instanceOf(GeneratedObjectField); - expect(doc.inference.prediction.fields.get('locale').currency).to.equals('EUR'); - expect(doc.inference.prediction.fields.get('locale').language).to.equals('fr'); - expect(doc.inference.prediction.fields.get('reference_numbers').values[0].value).to.equals('AD29094'); - expect(doc.inference.prediction.fields.get('supplier_address').value).to.equals('156 University Ave, Toronto ON, Canada M5H 2H7'); - expect(doc.inference.prediction.fields.get('supplier_company_registrations').values.length).to.equals(0); - expect(doc.inference.prediction.fields.get('supplier_name').value).to.equals('TURNPIKE DESIGNS CO.'); - expect(doc.inference.prediction.fields.get('supplier_payment_details').values[0].iban).to.equals('FR7640254025476501124705368'); - expect(doc.inference.prediction.fields.get('taxes').values[0].polygon.polygon).to.have.deep.members([[0.292, 0.749], [0.543, 0.749], [0.543, 0.763], [0.292, 0.763]]); - expect(doc.inference.prediction.fields.get('taxes').values[0].rate).to.equals('20.0'); - expect(doc.inference.prediction.fields.get('taxes').values[0].value).to.equals('97.98'); - expect(doc.inference.prediction.fields.get('total_amount').value).to.equals('587.95'); - expect(doc.inference.prediction.fields.get('total_net').value).to.equals('489.97'); + expect(doc.inference.prediction.fields.get("customer_address").value).to.equals("1954 Bloon Street West Toronto, ON, M6P 3K9 Canada"); + expect(doc.inference.prediction.fields.get("customer_company_registrations").values.length).to.equals(0); + expect(doc.inference.prediction.fields.get("customer_name").value).to.equals("JIRO DOI"); + expect(doc.inference.prediction.fields.get("date").value).to.equals("2020-02-17"); + expect(doc.inference.prediction.fields.get("document_type").value).to.equals("INVOICE"); + expect(doc.inference.prediction.fields.get("due_date").value).to.equals("2020-02-17"); + expect(doc.inference.prediction.fields.get("invoice_number").value).to.equals("0042004801351"); + expect(doc.inference.prediction.fields.get("line_items")).to.be.an.instanceOf(GeneratedListField); + expect(doc.inference.prediction.fields.get("line_items").values[0]).to.be.an.instanceOf(GeneratedObjectField); + expect(doc.inference.prediction.fields.get("line_items").values[0].description).to.equals("S)BOIE 5X500 FEUILLES A4"); + expect(doc.inference.prediction.fields.get("line_items").values[0].product_code).to.be.null; + expect(doc.inference.prediction.fields.get("line_items").values[0].quantity).to.be.null; + expect(doc.inference.prediction.fields.get("line_items").values[0].tax_amount).to.be.null; + expect(doc.inference.prediction.fields.get("line_items").values[0].tax_rate).to.be.null; + expect(doc.inference.prediction.fields.get("line_items").values[0].total_amount).to.equals("2.63"); + expect(doc.inference.prediction.fields.get("line_items").values[0].unit_price).to.be.null; + expect(doc.inference.prediction.fields.get("line_items").values[6].unit_price).to.equals("65.0"); + expect(doc.inference.prediction.fields.get("line_items").values[6].quantity).to.equals("1.0"); + expect(doc.inference.prediction.fields.get("locale")).to.be.an.instanceOf(GeneratedObjectField); + expect(doc.inference.prediction.fields.get("locale").currency).to.equals("EUR"); + expect(doc.inference.prediction.fields.get("locale").language).to.equals("fr"); + expect(doc.inference.prediction.fields.get("reference_numbers").values[0].value).to.equals("AD29094"); + expect(doc.inference.prediction.fields.get("supplier_address").value).to.equals("156 University Ave, Toronto ON, Canada M5H 2H7"); + expect(doc.inference.prediction.fields.get("supplier_company_registrations").values.length).to.equals(0); + expect(doc.inference.prediction.fields.get("supplier_name").value).to.equals("TURNPIKE DESIGNS CO."); + expect(doc.inference.prediction.fields.get("supplier_payment_details").values[0].iban).to.equals("FR7640254025476501124705368"); + expect(doc.inference.prediction.fields.get("taxes").values[0].polygon.polygon).to.have.deep.members([[0.292, 0.749], [0.543, 0.749], [0.543, 0.763], [0.292, 0.763]]); + expect(doc.inference.prediction.fields.get("taxes").values[0].rate).to.equals("20.0"); + expect(doc.inference.prediction.fields.get("taxes").values[0].value).to.equals("97.98"); + expect(doc.inference.prediction.fields.get("total_amount").value).to.equals("587.95"); + expect(doc.inference.prediction.fields.get("total_net").value).to.equals("489.97"); const docString = await fs.readFile(path.join(dataPathInvoice.docString)); expect(doc.toString()).to.equals(docString.toString()); }); diff --git a/tests/product/ind/indianPassport/indianPassportV1.spec.ts b/tests/v1/product/ind/indianPassport/indianPassportV1.spec.ts similarity index 98% rename from tests/product/ind/indianPassport/indianPassportV1.spec.ts rename to tests/v1/product/ind/indianPassport/indianPassportV1.spec.ts index d8cffa939..2a77a7ca4 100644 --- a/tests/product/ind/indianPassport/indianPassportV1.spec.ts +++ b/tests/v1/product/ind/indianPassport/indianPassportV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/internationalId/internationalIdV2.spec.ts b/tests/v1/product/internationalId/internationalIdV2.spec.ts similarity index 98% rename from tests/product/internationalId/internationalIdV2.spec.ts rename to tests/v1/product/internationalId/internationalIdV2.spec.ts index 021c167de..402b107fe 100644 --- a/tests/product/internationalId/internationalIdV2.spec.ts +++ b/tests/v1/product/internationalId/internationalIdV2.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/invoice/invoiceV4.spec.ts b/tests/v1/product/invoice/invoiceV4.spec.ts similarity index 98% rename from tests/product/invoice/invoiceV4.spec.ts rename to tests/v1/product/invoice/invoiceV4.spec.ts index e1f4e4798..d4488466c 100644 --- a/tests/product/invoice/invoiceV4.spec.ts +++ b/tests/v1/product/invoice/invoiceV4.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/invoiceSplitter/invoiceSplitterV1.spec.ts b/tests/v1/product/invoiceSplitter/invoiceSplitterV1.spec.ts similarity index 96% rename from tests/product/invoiceSplitter/invoiceSplitterV1.spec.ts rename to tests/v1/product/invoiceSplitter/invoiceSplitterV1.spec.ts index ceb47d960..da8417731 100644 --- a/tests/product/invoiceSplitter/invoiceSplitterV1.spec.ts +++ b/tests/v1/product/invoiceSplitter/invoiceSplitterV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts b/tests/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts similarity index 96% rename from tests/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts rename to tests/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts index 22ba1e686..e1c4d1ee9 100644 --- a/tests/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts +++ b/tests/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/nutritionFactsLabel/nutritionFactsLabelV1.spec.ts b/tests/v1/product/nutritionFactsLabel/nutritionFactsLabelV1.spec.ts similarity index 98% rename from tests/product/nutritionFactsLabel/nutritionFactsLabelV1.spec.ts rename to tests/v1/product/nutritionFactsLabel/nutritionFactsLabelV1.spec.ts index f883cdf44..12200d39e 100644 --- a/tests/product/nutritionFactsLabel/nutritionFactsLabelV1.spec.ts +++ b/tests/v1/product/nutritionFactsLabel/nutritionFactsLabelV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/ocr/ocr.spec.ts b/tests/v1/product/ocr/ocr.spec.ts similarity index 92% rename from tests/product/ocr/ocr.spec.ts rename to tests/v1/product/ocr/ocr.spec.ts index f305a5a2f..9462ba1a9 100644 --- a/tests/product/ocr/ocr.spec.ts +++ b/tests/v1/product/ocr/ocr.spec.ts @@ -1,8 +1,8 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import { ReceiptV5 } from "../../../src/product"; -import { Document } from "../../../src"; +import { ReceiptV5 } from "../../../../src/product"; +import { Document } from "../../../../src"; const dataPath = { complete: "tests/data/extras/ocr/complete.json", diff --git a/tests/product/passport/passportV1.spec.ts b/tests/v1/product/passport/passportV1.spec.ts similarity index 97% rename from tests/product/passport/passportV1.spec.ts rename to tests/v1/product/passport/passportV1.spec.ts index caee28c2b..3c8f9febc 100644 --- a/tests/product/passport/passportV1.spec.ts +++ b/tests/v1/product/passport/passportV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/receipt/receiptV5.spec.ts b/tests/v1/product/receipt/receiptV5.spec.ts similarity index 97% rename from tests/product/receipt/receiptV5.spec.ts rename to tests/v1/product/receipt/receiptV5.spec.ts index 98a8582d2..73596b5cb 100644 --- a/tests/product/receipt/receiptV5.spec.ts +++ b/tests/v1/product/receipt/receiptV5.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/resume/resumeV1.spec.ts b/tests/v1/product/resume/resumeV1.spec.ts similarity index 98% rename from tests/product/resume/resumeV1.spec.ts rename to tests/v1/product/resume/resumeV1.spec.ts index c1e6a2e42..912da1713 100644 --- a/tests/product/resume/resumeV1.spec.ts +++ b/tests/v1/product/resume/resumeV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../src"; +import * as mindee from "../../../../src"; const dataPath = { diff --git a/tests/product/us/bankCheck/bankCheckV1.spec.ts b/tests/v1/product/us/bankCheck/bankCheckV1.spec.ts similarity index 97% rename from tests/product/us/bankCheck/bankCheckV1.spec.ts rename to tests/v1/product/us/bankCheck/bankCheckV1.spec.ts index 33c0f33e5..f2a03ee6b 100644 --- a/tests/product/us/bankCheck/bankCheckV1.spec.ts +++ b/tests/v1/product/us/bankCheck/bankCheckV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/us/healthcareCard/healthcareCardV1.spec.ts b/tests/v1/product/us/healthcareCard/healthcareCardV1.spec.ts similarity index 97% rename from tests/product/us/healthcareCard/healthcareCardV1.spec.ts rename to tests/v1/product/us/healthcareCard/healthcareCardV1.spec.ts index 7e6976865..15435656f 100644 --- a/tests/product/us/healthcareCard/healthcareCardV1.spec.ts +++ b/tests/v1/product/us/healthcareCard/healthcareCardV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/product/us/usMail/usMailV3.spec.ts b/tests/v1/product/us/usMail/usMailV3.spec.ts similarity index 97% rename from tests/product/us/usMail/usMailV3.spec.ts rename to tests/v1/product/us/usMail/usMailV3.spec.ts index bb6917066..22b206a05 100644 --- a/tests/product/us/usMail/usMailV3.spec.ts +++ b/tests/v1/product/us/usMail/usMailV3.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import * as mindee from "../../../../src"; +import * as mindee from "../../../../../src"; const dataPath = { diff --git a/tests/workflows/workflow.integration.ts b/tests/v1/workflows/workflow.integration.ts similarity index 83% rename from tests/workflows/workflow.integration.ts rename to tests/v1/workflows/workflow.integration.ts index c3cb7666c..83bbf3d71 100644 --- a/tests/workflows/workflow.integration.ts +++ b/tests/v1/workflows/workflow.integration.ts @@ -1,12 +1,14 @@ -import * as mindee from "../../src"; -import { ExecutionPriority } from "../../src/parsing/common"; +import * as mindee from "../../../src"; +import { ExecutionPriority } from "../../../src/parsing/common"; import { expect } from "chai"; -import { LocalInputSource } from "../../src/input"; -import { OptionalAsyncOptions } from "../../src/client"; -import { FinancialDocumentV1 } from "../../src/product"; -import { RAGExtra } from "../../src/parsing/common/extras/ragExtra"; +import { LocalInputSource } from "../../../src/input"; +import { OptionalAsyncOptions } from "../../../src/client"; +import { FinancialDocumentV1 } from "../../../src/product"; +import { RAGExtra } from "../../../src/parsing/common/extras/ragExtra"; +import path from "path"; +import { RESOURCE_PATH } from "../../index"; -describe("Workflow calls", () => { +describe("MindeeV1 - Workflow calls", () => { let client: mindee.Client; let sample: LocalInputSource; let workflowId: string; @@ -15,7 +17,7 @@ describe("Workflow calls", () => { client = new mindee.Client(); workflowId = process.env["WORKFLOW_ID"] ?? ""; sample = client.docFromPath( - "tests/data/products/financial_document/default_sample.jpg" + path.join(RESOURCE_PATH, "products/financial_document/default_sample.jpg") ); await sample.init(); }); diff --git a/tests/workflows/workflow.spec.ts b/tests/v1/workflows/workflow.spec.ts similarity index 88% rename from tests/workflows/workflow.spec.ts rename to tests/v1/workflows/workflow.spec.ts index 4373f85f3..de698df8f 100644 --- a/tests/workflows/workflow.spec.ts +++ b/tests/v1/workflows/workflow.spec.ts @@ -2,14 +2,13 @@ import { expect } from "chai"; import nock from "nock"; import { promises as fs } from "fs"; import path from "path"; -import { GeneratedV1 } from "../../src/product"; -import { WorkflowResponse } from "../../src/parsing/common/workflowResponse"; +import { GeneratedV1 } from "../../../src/product"; +import { WorkflowResponse } from "../../../src/parsing/common/workflowResponse"; +import { V1_RESOURCE_PATH } from "../../index"; -const DATA_DIR = path.resolve(__dirname, "..", "data"); - -describe("Workflow executions", () => { +describe("MindeeV1 - Workflow executions", () => { it("should deserialize response correctly when sending a document to an execution", async () => { - const jsonFilePath = path.join(DATA_DIR, "workflows", "success.json"); + const jsonFilePath = path.join(V1_RESOURCE_PATH, "workflows", "success.json"); const mockResponse = JSON.parse(await fs.readFile(jsonFilePath, "utf-8")); nock("https://api.mindee.net") @@ -40,7 +39,7 @@ describe("Workflow executions", () => { it("should deserialize response correctly when sending a document to an execution with priority and alias", async () => { - const jsonFilePath = path.join(DATA_DIR, "workflows", "success_low_priority.json"); + const jsonFilePath = path.join(V1_RESOURCE_PATH, "workflows", "success_low_priority.json"); const mockResponse = JSON.parse(await fs.readFile(jsonFilePath, "utf-8")); nock("https://api.mindee.net") diff --git a/tests/v2/clientV2.integration.ts b/tests/v2/clientV2.integration.ts index c0c89d553..5a5b7571a 100644 --- a/tests/v2/clientV2.integration.ts +++ b/tests/v2/clientV2.integration.ts @@ -1,12 +1,20 @@ import { expect } from "chai"; import path from "node:path"; -import { ClientV2, InferenceParameters, PathInput, UrlInput, Base64Input } from "../../src"; +import { + ClientV2, + InferenceParameters, + PathInput, + UrlInput, + Base64Input, + InferenceResponse, +} from "../../src"; +import { Inference } from "../../src/parsing/v2"; import { SimpleField } from "../../src/parsing/v2/field"; import { MindeeHttpErrorV2 } from "../../src/errors/mindeeError"; import * as fs from "node:fs"; -describe("MindeeClientV2 โ€“ integration tests (V2)", () => { +describe("MindeeV2 โ€“ Client Integration Tests", () => { let client: ClientV2; let modelId: string; @@ -51,8 +59,8 @@ describe("MindeeClientV2 โ€“ integration tests (V2)", () => { const response = await client.enqueueAndGetInference(source, params); expect(response).to.exist; - const inference = response.inference; - expect(inference).to.exist; + expect(response.inference).to.be.instanceOf(Inference); + const inference: Inference = response.inference; expect(inference.file?.name).to.equal("multipage_cut-2.pdf"); expect(inference.file.pageCount).to.equal(2); @@ -81,7 +89,8 @@ describe("MindeeClientV2 โ€“ integration tests (V2)", () => { const response = await client.enqueueAndGetInference(source, params); - const inference = response.inference; + expect(response.inference).to.be.instanceOf(Inference); + const inference: Inference = response.inference; expect(inference.file?.name).to.equal("default_sample.jpg"); expect(inference.model?.id).to.equal(modelId); @@ -117,7 +126,8 @@ describe("MindeeClientV2 โ€“ integration tests (V2)", () => { const response = await client.enqueueAndGetInference(source, params); - const inference = response.inference; + expect(response.inference).to.be.instanceOf(Inference); + const inference: Inference = response.inference; expect(inference.file?.name).to.equal("receipt.jpg"); expect(inference.model?.id).to.equal(modelId); @@ -137,24 +147,32 @@ describe("MindeeClientV2 โ€“ integration tests (V2)", () => { it("Invalid model ID โ€“ enqueue must raise 422", async () => { const source = new PathInput({ inputPath: emptyPdfPath }); - const badParams: InferenceParameters = { modelId: "INVALID MODEL ID" }; + const badParams: InferenceParameters = { modelId: "00000000-0000-0000-0000-000000000000" }; try { await client.enqueueInference(source, badParams); expect.fail("Expected the call to throw, but it succeeded."); } catch (err) { expect(err).to.be.instanceOf(MindeeHttpErrorV2); - expect((err as MindeeHttpErrorV2).status).to.equal(422); + const errObj = err as MindeeHttpErrorV2; + expect(errObj.status).to.equal(422); + expect(errObj.code.startsWith("422-")).to.be.true; + expect(errObj.title).to.be.a("string"); + expect(errObj.detail).to.be.a("string"); } }).timeout(60000); - it("Invalid job ID โ€“ getInference must raise 404", async () => { + it("Invalid job ID โ€“ getInference must raise 422", async () => { try { await client.getInference("00000000-0000-0000-0000-000000000000"); expect.fail("Expected the call to throw, but it succeeded."); } catch (err) { expect(err).to.be.instanceOf(MindeeHttpErrorV2); - expect((err as MindeeHttpErrorV2).status).to.equal(422); + const errObj = err as MindeeHttpErrorV2; + expect(errObj.status).to.equal(422); + expect(errObj.code.startsWith("422-")).to.be.true; + expect(errObj.title).to.be.a("string"); + expect(errObj.detail).to.be.a("string"); } }).timeout(60000); @@ -171,10 +189,10 @@ describe("MindeeClientV2 โ€“ integration tests (V2)", () => { alias: "ts_integration_url_source" }; - const response = await client.enqueueAndGetInference(source, params); + const response: InferenceResponse = await client.enqueueAndGetInference(source, params); expect(response).to.exist; - expect(response.inference).to.exist; + expect(response.inference).to.be.instanceOf(Inference); }).timeout(60000); }); diff --git a/tests/v2/clientV2.spec.ts b/tests/v2/clientV2.spec.ts index 48897a2c4..edba4bc48 100644 --- a/tests/v2/clientV2.spec.ts +++ b/tests/v2/clientV2.spec.ts @@ -5,6 +5,7 @@ import path from "node:path"; import { ClientV2, LocalResponse, PathInput, InferenceResponse } from "../../src"; import { MindeeHttpErrorV2 } from "../../src/errors/mindeeError"; import assert from "node:assert/strict"; +import { RESOURCE_PATH, V2_RESOURCE_PATH } from "../index"; /** * Injects a minimal set of environment variables so that the SDK behaves @@ -41,11 +42,9 @@ function setNockInterceptors(): void { }); } -const resourcesPath = path.join(__dirname, "..", "data"); -const fileTypesDir = path.join(resourcesPath, "file_types"); -const v2DataDir = path.join(resourcesPath, "v2"); +const fileTypesDir = path.join(RESOURCE_PATH, "file_types"); -describe("ClientV2", () => { +describe("MindeeV2 - ClientV2", () => { before(() => { setNockInterceptors(); dummyEnvvars(); @@ -96,7 +95,7 @@ describe("ClientV2", () => { it("loading an inference works on stored JSON fixtures", async () => { const jsonPath = path.join( - v2DataDir, + V2_RESOURCE_PATH, "products", "financial_document", "complete.json" @@ -113,7 +112,7 @@ describe("ClientV2", () => { it("bubble-up HTTP errors with details", async () => { const input = new PathInput({ inputPath: path.join( - v2DataDir, + V2_RESOURCE_PATH, "products", "financial_document", "default_sample.jpg" diff --git a/tests/parsing/v2/inference.spec.ts b/tests/v2/parsing/inference.spec.ts similarity index 98% rename from tests/parsing/v2/inference.spec.ts rename to tests/v2/parsing/inference.spec.ts index f4cdc2dfd..766472c92 100644 --- a/tests/parsing/v2/inference.spec.ts +++ b/tests/v2/parsing/inference.spec.ts @@ -4,11 +4,10 @@ import { LocalResponse, InferenceResponse, RawText } from "../../../src"; import { FieldConfidence, ListField, ObjectField, SimpleField } from "../../../src/parsing/v2/field"; import { promises as fs } from "node:fs"; import { Polygon } from "../../../src/geometry"; +import { V2_RESOURCE_PATH } from "../../index"; -const resourcesPath = path.join(__dirname, "..", "..", "data"); -const v2DataDir = path.join(resourcesPath, "v2"); -const findocPath = path.join(v2DataDir, "products", "financial_document"); -const inferencePath = path.join(v2DataDir, "inference"); +const findocPath = path.join(V2_RESOURCE_PATH, "products", "financial_document"); +const inferencePath = path.join(V2_RESOURCE_PATH, "inference"); const deepNestedFieldPath = path.join(inferencePath, "deep_nested_fields.json"); const standardFieldPath = path.join(inferencePath, "standard_field_types.json"); const standardFieldRstPath = path.join(inferencePath, "standard_field_types.rst"); diff --git a/tests/v2/parsing/job.spec.ts b/tests/v2/parsing/job.spec.ts new file mode 100644 index 000000000..5bd327a19 --- /dev/null +++ b/tests/v2/parsing/job.spec.ts @@ -0,0 +1,37 @@ +import { JobResponse, LocalResponse } from "../../../src"; +import path from "node:path"; +import { V2_RESOURCE_PATH } from "../../index"; +import { expect } from "chai"; +import { ErrorResponse } from "../../../src/parsing/v2"; + +const jobPath = path.join(V2_RESOURCE_PATH, "job"); + +async function loadV2Job(resourcePath: string): Promise { + const localResponse = new LocalResponse(resourcePath); + await localResponse.init(); + return localResponse.deserializeResponse(JobResponse); +} + +describe("job", async () => { + describe("OK", async () => { + it("should load when status is Processing", async () => { + const response = await loadV2Job( + path.join(jobPath, "ok_processing.json") + ); + expect(response.job).to.be.not.empty; + expect(response.job.error).to.be.undefined; + }); + }); + describe("Fail", async () => { + it("should load with 422 error", async () => { + const response = await loadV2Job( + path.join(jobPath, "fail_422.json") + ); + expect(response.job).to.be.not.empty; + expect(response.job.error).to.be.instanceOf(ErrorResponse); + expect(response.job.error?.status).to.eq(422); + expect(response.job.error?.code.startsWith("422-")).to.be.true; + expect(response.job.error?.errors).to.be.instanceOf(Array); + }); + }); +});