diff --git a/examples/auth/client/IR.jpg b/examples/auth/client/IR.jpg deleted file mode 100644 index 9efda5c6..00000000 Binary files a/examples/auth/client/IR.jpg and /dev/null differ diff --git a/examples/auth/client/UV.jpg b/examples/auth/client/UV.jpg deleted file mode 100644 index b7aeb6cf..00000000 Binary files a/examples/auth/client/UV.jpg and /dev/null differ diff --git a/examples/auth/client/index.js b/examples/auth/client/index.js index a9c728cf..302e2406 100755 --- a/examples/auth/client/index.js +++ b/examples/auth/client/index.js @@ -1,22 +1,16 @@ import * as fs from 'fs'; import { DocumentReaderApi, - Result, Scenario, Source, - TextFieldType, GraphicFieldType, Light, - SecurityFeatureType, } from '@regulaforensics/document-reader-webclient'; import axios from 'axios'; import qs from 'qs'; const GATEWAY_BASE_URL = 'http://localhost:8080'; -const { PORTRAIT, DOCUMENT_FRONT } = GraphicFieldType; -const { DOCUMENT_NUMBER } = TextFieldType; - async function get_authorization_token() { let data = qs.stringify({ grant_type: 'password', @@ -45,116 +39,59 @@ async function get_authorization_token() { }); } -(async () => { - const apiBasePath = process.env.API_BASE_PATH || 'http://localhost:4333'; - let license = process.env.TEST_LICENSE; // optional, used here only for smoke test purposes +const apiBasePath = process.env.API_BASE_PATH || 'http://localhost:4333'; +let license = process.env.TEST_LICENSE; - if (fs.existsSync('regula.license')) { - license = fs.readFileSync('regula.license'); - } - const token = await get_authorization_token(); +if (fs.existsSync('regula.license')) { + license = fs.readFileSync('regula.license'); +} +const token = await get_authorization_token(); - const api = new DocumentReaderApi({ - basePath: apiBasePath, - baseOptions: { headers: { Authorization: `Bearer ${token}` } }, - }); +const api = new DocumentReaderApi({ + basePath: apiBasePath, + baseOptions: { headers: { Authorization: `Bearer ${token}` } }, +}); - api.setLicense(license); +// Uncomment the line below if you want to transfer the license with each request +// api.setLicense(license); - const serverInfo = await api.ping(); +const serverInfo = await api.ping(); - const white_page_0 = fs.readFileSync('WHITE.jpg').buffer; - const ir_page_0 = fs.readFileSync('IR.jpg').buffer; - const uv_page_0 = fs.readFileSync('UV.jpg').buffer; +const white_page_0 = fs.readFileSync('WHITE.jpg').buffer; - const request = { - images: [ - { - ImageData: white_page_0, - light: Light.WHITE, - page_idx: 0, - }, - { - ImageData: ir_page_0, - light: Light.IR, - page_idx: 0, - }, - { - ImageData: uv_page_0, - light: Light.UV, - page_idx: 0, - }, - ], - processParam: { - scenario: Scenario.FULL_AUTH, - resultTypeOutput: [ - // actual results - Result.STATUS, - Result.AUTHENTICITY, - Result.TEXT, - Result.IMAGES, - Result.DOCUMENT_TYPE, - Result.DOCUMENT_TYPE_CANDIDATES, - Result.IMAGE_QUALITY, - // legacy results - Result.MRZ_TEXT, - Result.VISUAL_TEXT, - Result.BARCODE_TEXT, - Result.RFID_TEXT, - Result.VISUAL_GRAPHICS, - Result.BARCODE_GRAPHICS, - Result.RFID_GRAPHICS, - Result.LEXICAL_ANALYSIS, - ], +const request = { + images: [ + { + ImageData: white_page_0, + light: Light.WHITE, + page_idx: 0, }, - }; - - const response = await api.process(request); - - const requestJson = JSON.stringify(request); - const responseJson = response.json(); - - const docOverallStatus = response.status.overallStatus; - const docOpticalTextStatus = response.status.detailsOptical.text; - - // text fields example - const docNumberField = response.text.getField(DOCUMENT_NUMBER); - const docNumberFieldByName = response.text.getFieldByName('Document Number'); - - const docNumberVisual = docNumberField.getValue(Source.VISUAL); - const docNumberMrz = docNumberField.getValue(Source.MRZ); - const docNumberVisualValidity = docNumberField.sourceValidity(Source.VISUAL); - const docNumberMrzValidity = docNumberField.sourceValidity(Source.MRZ); - const docNumberMrzVisualMatching = docNumberField.crossSourceComparison(Source.MRZ, Source.VISUAL); - - const docAuthenticity = response.authenticity(); - - const docIrB900 = docAuthenticity.irB900Checks(); - const docIrB900BlankChecks = docIrB900.checksByElement(SecurityFeatureType.BLANK); - - const docImagePattern = docAuthenticity.imagePatternChecks(); - const docImagePatternBlankChecks = docImagePattern.checksByElement(SecurityFeatureType.BLANK); - - // images example - const documentImage = response.images.getField(DOCUMENT_FRONT).getValue(); - const portraitField = response.images.getField(PORTRAIT); - const portraitFromVisual = portraitField.getValue(Source.VISUAL); - fs.appendFileSync('portrait.jpg', Buffer.from(portraitFromVisual)); - fs.appendFileSync('document-image.jpg', Buffer.from(documentImage)); - - const docImageQuality = response.imageQualityChecks(); - - console.log('-----------------------------------------------------------------'); - console.log(` Web API version: ${serverInfo.version}`); - console.log('-----------------------------------------------------------------'); - console.log(` Document Overall Status: ${docOverallStatus}`); - console.log(` Document Number Visual: ${docNumberVisual}`); - console.log(` Document Number MRZ: ${docNumberMrz}`); - console.log(`Validity Of Document Number Visual: ${docNumberVisualValidity}`); - console.log(` Validity Of Document Number MRZ: ${docNumberMrzValidity}`); - console.log(` MRZ-Visual values comparison: ${docNumberMrzVisualMatching}`); - console.log('-----------------------------------------------------------------'); - - // how to get low lvl individual results - const lexResult = response.lowLvlResponse.resultByType(Result.LEXICAL_ANALYSIS); -})(); + ], + processParam: { + scenario: Scenario.FULL_PROCESS, + alreadyCropped: true, + }, +}; + +const response = await api.process(request); + +// images example +const documentImage = response.images.getField(GraphicFieldType.DOCUMENT_FRONT).getValue(); +const portraitField = response.images.getField(GraphicFieldType.PORTRAIT); +const portraitFromVisual = portraitField.getValue(Source.VISUAL); +fs.appendFileSync('portrait.jpg', Buffer.from(portraitFromVisual)); +fs.appendFileSync('document-image.jpg', Buffer.from(documentImage)); + +console.log('---------------------------------------------------------------'); +console.log(`Document name: ${response.documentType().DocumentName}`); +console.log('---------------------------------------------------------------'); + +response.text.fieldList.forEach((field) => { + console.log(`\n[${field.fieldName}]`); + field.valueList.forEach(({ source, value }) => { + console.log(` - Source: ${source}`); + console.log(` Value : ${value}`); + }); + console.log('---------------------------------------------------------------'); +}); +console.log(` -Web API version: ${serverInfo.version}-`); diff --git a/examples/auth/client/license.txt b/examples/auth/client/license.txt deleted file mode 100644 index 4225f850..00000000 --- a/examples/auth/client/license.txt +++ /dev/null @@ -1 +0,0 @@ -AAEAAK/WKOtEs17ikF4B/IKdpwmj9p0KTx2OS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AMCR2E6dBMT8E95BGSV8tEo5LzYK4nfSYJk8LDGVU4dvtxrLhbLeLr9OmNigVImKDKrZrIQLOJtCcb4q3V8HDQ5XeGsJ2pPRHDOJL7RjUEEbhb0w8ewTpJdDec2BUvZXMTwVLk4CED8mZwMssO6HEcnjy2JqVHU47sVwhpfKJIT+9deAzybEkTi+Mibs4MLBcaO6iaoQsaORvk87ERwXe4F/5JUz0uMoSoEbIPrR4s+MakfFsEDNSOBEl5LCmM2BvIFkqoVnzV5Ft+1mLhvYNgnkrwntnCf0Nt81ragY83Jumvs3QvSBw7M4WW1ANlKJfrGfgwwroISK0Ma5mXc40oKUIb7Jmgp+uwxr+Nka3DNBGG3qUUI/lM3N4ZkmPAOTbNwVHv+TDo62nFaCtCeaK31owNYKojWbc5Gf+FL8K34j01DzIJiUO+3wHs2pH39ePDregf8uvx/kTvvA8oqEZWMzjmYdMkV1o43/nvnlHiwl8Pyq4O2F5NX9LVxcQpw6nMPWlKe6zrluztm/gYO7h2Rt1ualZbO4DQvt8OuTwXvzxR1X9XWJ6qNZjYbMmnZp+tPpL+iO3St6sWWGEc5nelcCPOIBOoXwYo1SZxUa0ex//aiExfoaEL1aJO95ARWnKwXnVBJyEiRume5j/qFeFkwo5/XFiBt9bRluOMdWuNTOc5A25eFmuNr0n8eeE458Huyg7DiKQ== \ No newline at end of file diff --git a/examples/auth/server/package-lock.json b/examples/auth/server/package-lock.json index fe3ccc1e..76757841 100644 --- a/examples/auth/server/package-lock.json +++ b/examples/auth/server/package-lock.json @@ -293,9 +293,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/elliptic": { - "version": "6.5.7", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.7.tgz", - "integrity": "sha512-ESVCtTwiA+XhY3wyh24QqRGBoP3rEdDUl3EDUUo9tft074fi19IrdpH7hLCMMP3CIj7jb3W96rn8lt/BqIlt5Q==", + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.6.0.tgz", + "integrity": "sha512-dpwoQcLc/2WLQvJvLRHKZ+f9FgOdjnq11rurqwekGQygGPsYSK29OMMD2WalatiqQ+XGFDglTNixpPfI+lpaAA==", "dependencies": { "bn.js": "^4.11.9", "brorand": "^1.1.0", diff --git a/examples/basic/IR.jpg b/examples/basic/IR.jpg deleted file mode 100644 index 9efda5c6..00000000 Binary files a/examples/basic/IR.jpg and /dev/null differ diff --git a/examples/basic/UV.jpg b/examples/basic/UV.jpg deleted file mode 100644 index b7aeb6cf..00000000 Binary files a/examples/basic/UV.jpg and /dev/null differ diff --git a/examples/basic/index.js b/examples/basic/index.js index 5b44423e..fb1c2eae 100755 --- a/examples/basic/index.js +++ b/examples/basic/index.js @@ -1,124 +1,61 @@ import * as fs from 'fs'; import { DocumentReaderApi, - Result, Scenario, + Light, Source, - TextFieldType, GraphicFieldType, - Light, - SecurityFeatureType, } from '@regulaforensics/document-reader-webclient'; -const { PORTRAIT, DOCUMENT_FRONT } = GraphicFieldType; -const { DOCUMENT_NUMBER } = TextFieldType; +const apiBasePath = process.env.API_BASE_PATH || 'https://api.regulaforensics.com'; +let license = process.env.TEST_LICENSE; -(async () => { - const apiBasePath = process.env.API_BASE_PATH || 'https://api.regulaforensics.com'; - let license = process.env.TEST_LICENSE; // optional, used here only for smoke test purposes +if (fs.existsSync('regula.license')) { + license = fs.readFileSync('regula.license'); +} - if (fs.existsSync('regula.license')) { - license = fs.readFileSync('regula.license'); - } +const api = new DocumentReaderApi({ basePath: apiBasePath }); - const api = new DocumentReaderApi({ basePath: apiBasePath }); +// Uncomment the line below if you want to transfer the license with each request +// api.setLicense(license); - api.setLicense(license); +const serverInfo = await api.ping(); - const serverInfo = await api.ping(); +const white_page_0 = fs.readFileSync('WHITE.jpg').buffer; - const white_page_0 = fs.readFileSync('WHITE.jpg').buffer; - const ir_page_0 = fs.readFileSync('IR.jpg').buffer; - const uv_page_0 = fs.readFileSync('UV.jpg').buffer; - - const request = { - images: [ - { - ImageData: white_page_0, - light: Light.WHITE, - page_idx: 0, - }, - { - ImageData: ir_page_0, - light: Light.IR, - page_idx: 0, - }, - { - ImageData: uv_page_0, - light: Light.UV, - page_idx: 0, - }, - ], - processParam: { - scenario: Scenario.FULL_AUTH, - resultTypeOutput: [ - // actual results - Result.STATUS, - Result.AUTHENTICITY, - Result.TEXT, - Result.IMAGES, - Result.DOCUMENT_TYPE, - Result.DOCUMENT_TYPE_CANDIDATES, - Result.IMAGE_QUALITY, - // legacy results - Result.MRZ_TEXT, - Result.VISUAL_TEXT, - Result.BARCODE_TEXT, - Result.RFID_TEXT, - Result.VISUAL_GRAPHICS, - Result.BARCODE_GRAPHICS, - Result.RFID_GRAPHICS, - Result.LEXICAL_ANALYSIS, - ], +const request = { + images: [ + { + ImageData: white_page_0, + light: Light.WHITE, + page_idx: 0, }, - }; - - const response = await api.process(request); - - const requestJson = JSON.stringify(request); - const responseJson = response.json(); - - const docOverallStatus = response.status.overallStatus; - const docOpticalTextStatus = response.status.detailsOptical.text; - - // text fields example - const docNumberField = response.text.getField(DOCUMENT_NUMBER); - const docNumberFieldByName = response.text.getFieldByName('Document Number'); - - const docNumberVisual = docNumberField.getValue(Source.VISUAL); - const docNumberMrz = docNumberField.getValue(Source.MRZ); - const docNumberVisualValidity = docNumberField.sourceValidity(Source.VISUAL); - const docNumberMrzValidity = docNumberField.sourceValidity(Source.MRZ); - const docNumberMrzVisualMatching = docNumberField.crossSourceComparison(Source.MRZ, Source.VISUAL); - - const docAuthenticity = response.authenticity(); - - const docIrB900 = docAuthenticity.irB900Checks(); - const docIrB900BlankChecks = docIrB900.checksByElement(SecurityFeatureType.BLANK); - - const docImagePattern = docAuthenticity.imagePatternChecks(); - const docImagePatternBlankChecks = docImagePattern.checksByElement(SecurityFeatureType.BLANK); - - // images example - const documentImage = response.images.getField(DOCUMENT_FRONT).getValue(); - const portraitField = response.images.getField(PORTRAIT); - const portraitFromVisual = portraitField.getValue(Source.VISUAL); - fs.appendFileSync('portrait.jpg', Buffer.from(portraitFromVisual)); - fs.appendFileSync('document-image.jpg', Buffer.from(documentImage)); - - const docImageQuality = response.imageQualityChecks(); - - console.log('-----------------------------------------------------------------'); - console.log(` Web API version: ${serverInfo.version}`); - console.log('-----------------------------------------------------------------'); - console.log(` Document Overall Status: ${docOverallStatus}`); - console.log(` Document Number Visual: ${docNumberVisual}`); - console.log(` Document Number MRZ: ${docNumberMrz}`); - console.log(`Validity Of Document Number Visual: ${docNumberVisualValidity}`); - console.log(` Validity Of Document Number MRZ: ${docNumberMrzValidity}`); - console.log(` MRZ-Visual values comparison: ${docNumberMrzVisualMatching}`); - console.log('-----------------------------------------------------------------'); - - // how to get low lvl individual results - const lexResult = response.lowLvlResponse.resultByType(Result.LEXICAL_ANALYSIS); -})(); + ], + processParam: { + scenario: Scenario.FULL_PROCESS, + alreadyCropped: true, + }, +}; + +const response = await api.process(request); + +// images example +const documentImage = response.images.getField(GraphicFieldType.DOCUMENT_FRONT).getValue(); +const portraitField = response.images.getField(GraphicFieldType.PORTRAIT); +const portraitFromVisual = portraitField.getValue(Source.VISUAL); +fs.appendFileSync('portrait.jpg', Buffer.from(portraitFromVisual)); +fs.appendFileSync('document-image.jpg', Buffer.from(documentImage)); + +console.log('---------------------------------------------------------------'); +console.log(`Document name: ${response.documentType().DocumentName}`); +console.log('---------------------------------------------------------------'); + +response.text.fieldList.forEach((field) => { + console.log(`\n[${field.fieldName}]`); + field.valueList.forEach(({ source, value }) => { + console.log(` - Source: ${source}`); + console.log(` Value : ${value}`); + }); + console.log('---------------------------------------------------------------'); +}); +console.log(` -Web API version: ${serverInfo.version}-`); diff --git a/examples/basic/package-lock.json b/examples/basic/package-lock.json index f0c7e6b7..6b219c72 100644 --- a/examples/basic/package-lock.json +++ b/examples/basic/package-lock.json @@ -38,27 +38,27 @@ }, "../..": { "name": "@regulaforensics/document-reader-webclient", - "version": "6.6.0", + "version": "0.0.0", "license": "MIT", "dependencies": { - "@swc/helpers": "^0.5.3", - "axios": "^1.6.1", + "@swc/helpers": "^0.5.13", + "axios": "^1.7.7", "base64-arraybuffer": "^1.0.2", "pako": "^2.1.0" }, "devDependencies": { - "@parcel/packager-ts": "^2.10.3", - "@parcel/transformer-typescript-types": "^2.10.3", - "@types/pako": "^2.0.1", + "@parcel/packager-ts": "^2.12.0", + "@parcel/transformer-typescript-types": "^2.12.0", + "@types/pako": "^2.0.3", "@typescript-eslint/eslint-plugin": "^6.8.0", "@typescript-eslint/parser": "^6.8.0", "eslint": "^8.51.0", - "eslint-config-prettier": "^9.0.0", - "eslint-plugin-prettier": "^5.0.1", - "husky": "^8.0.3", - "lint-staged": "^15.0.1", - "parcel": "^2.10.3", - "prettier": "^3.0.3", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1", + "husky": "^9.1.5", + "lint-staged": "^15.2.10", + "parcel": "^2.12.0", + "prettier": "^3.3.3", "typescript": "^5.3.2" } },