From b82cc89b383410e2a8fad6dc978584e66a2f9dca Mon Sep 17 00:00:00 2001 From: Zeeshan Mehboob Date: Wed, 4 Dec 2024 23:58:25 +0530 Subject: [PATCH 1/2] [MODIFIED] all number to string, default number values also Signed-off-by: Zeeshan Mehboob --- .../package.json | 4 +- .../utility/sbiservice.js | 82 ++++++++++++++----- 2 files changed, 62 insertions(+), 24 deletions(-) diff --git a/secure-biometric-interface-integrator/package.json b/secure-biometric-interface-integrator/package.json index b7e92ff..ba070fc 100644 --- a/secure-biometric-interface-integrator/package.json +++ b/secure-biometric-interface-integrator/package.json @@ -1,7 +1,7 @@ { "name": "secure-biometric-interface-integrator", "description": "A vanillaJs library for integrating Secure Biometric Devices", - "version": "0.9.1", + "version": "0.9.2", "license": "MPL-2.0", "main": "dist/cjs/index.js", "module": "dist/es/index.js", @@ -11,7 +11,7 @@ ], "repository": { "type": "git", - "url": "git+https://github.com/mosip/mosip-plugins" + "url": "git+https://github.com/mosip/mosip-sdk" }, "keywords": [ "mosip", diff --git a/secure-biometric-interface-integrator/utility/sbiservice.js b/secure-biometric-interface-integrator/utility/sbiservice.js index db7eec5..8e01d77 100644 --- a/secure-biometric-interface-integrator/utility/sbiservice.js +++ b/secure-biometric-interface-integrator/utility/sbiservice.js @@ -51,27 +51,65 @@ const BioType = { class SbiService { sbiConfig; - constructor( - sbiConfig = { - env: "Staging", - captureTimeout: 30, - irisBioSubtypes: "UNKNOWN", - fingerBioSubtypes: "UNKNOWN", - faceCaptureCount: 1, - faceCaptureScore: 70, - fingerCaptureCount: 1, - fingerCaptureScore: 70, - irisCaptureCount: 1, - irisCaptureScore: 70, - portRange: "4501-4600", - discTimeout: 15, - dinfoTimeout: 30, - domainUri: `${window.origin}`, + constructor(sbiConfig) { + this.sbiConfig = { + env: this.nullCheckStr(sbiConfig.env,"Staging"), + irisBioSubtypes: this.nullCheckStr(sbiConfig.irisBioSubtypes, "UNKNOWN"), + fingerBioSubtypes: this.nullCheckStr(sbiConfig.fingerBioSubtypes, "UNKNOWN"), + faceCaptureCount: this.nullCheckNum(sbiConfig.faceCaptureCount, "1"), + faceCaptureScore: this.nullCheckNum(sbiConfig.faceCaptureScore, "70"), + fingerCaptureCount: this.nullCheckNum(sbiConfig.fingerCaptureCount, "1"), + fingerCaptureScore: this.nullCheckNum(sbiConfig.fingerCaptureScore, "70"), + irisCaptureCount: this.nullCheckNum(sbiConfig.irisCaptureCount, "1"), + irisCaptureScore: this.nullCheckNum(sbiConfig.irisCaptureScore, "70"), + portRange: this.nullCheckStr(sbiConfig.portRange, "4501-4600"), + captureTimeout: this.convertToMs(sbiConfig.captureTimeout, "30000"), + discTimeout: this.convertToMs(sbiConfig.discTimeout, "15000"), + dinfoTimeout: this.convertToMs(sbiConfig.dinfoTimeout, "30000"), + domainUri: this.nullCheckStr(sbiConfig.domainUri, window.origin), + }; + } + + /** + * Convert sec to millisecond + * @param {string | number | undefined | null} current + * @param {string} default + * @returns {string} converted millisecond + */ + convertToMs = (current, defaultVal) => { + if (current === null || current === undefined || current === "" || isNaN(current)) { + return defaultVal; } - ) { - this.sbiConfig = sbiConfig; + return (current * 1000).toString(); } + /** + * Null check & string conversion of number + * @param {string | number | undefined | null} str + * @param {string} defaultVal + * @returns {string} string value + */ + nullCheckNum = (current, defaultVal) => { + if (current === null || current === undefined || current === "" || isNaN(current)) { + return defaultVal; + } + return current.toString(); + } + + /** + * Null check for string + * @param {string | undefined | null} str + * @param {string} defaultVal + * @returns {string} string value + */ + nullCheckStr = (current, defaultVal) => { + if (current === null || current === undefined || current === "") { + return defaultVal; + } + return current.toString(); + } + + /** * Triggers capture request of SBI for auth capture * @param {url} host SBI is hosted on given host @@ -119,7 +157,7 @@ class SbiService { env: this.sbiConfig.env, purpose, specVersion, - timeout: this.sbiConfig.captureTimeout * 1000, + timeout: this.sbiConfig.captureTimeout, captureTime: new Date().toISOString(), domainUri: this.sbiConfig.domainUri, transactionId, @@ -130,7 +168,7 @@ class SbiService { bioSubType, requestedScore, // from configuration deviceId, // from discovery - deviceSubId: 0, //Set as 0, not required for Auth capture. + deviceSubId: "0", //Set as 0, not required for Auth capture. previousHash: "", // empty string }, ], @@ -214,7 +252,7 @@ const discoverRequestBuilder = async ( method: mosip_DiscoverMethod, url: endpoint, data: request, - timeout: discTimeout * 1000, + timeout: discTimeout, }) .then(async (response) => { if (response?.data !== null) { @@ -239,7 +277,7 @@ const mosipdinfo_DeviceInfo = async (host, port, dinfoTimeout) => { await axios({ method: mosip_DeviceInfoMethod, url: endpoint, - timeout: dinfoTimeout * 1000, + timeout: dinfoTimeout, }) .then(async (response) => { if (response?.data !== null) { From bdbce4f5b6a98ebd811be8e3d3c9dbabd36b2c00 Mon Sep 17 00:00:00 2001 From: Zeeshan Mehboob Date: Thu, 5 Dec 2024 15:04:38 +0530 Subject: [PATCH 2/2] [VERSION] reduce version to 0.9.2-beta.0 Signed-off-by: Zeeshan Mehboob --- secure-biometric-interface-integrator/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/secure-biometric-interface-integrator/package.json b/secure-biometric-interface-integrator/package.json index ba070fc..b1aa230 100644 --- a/secure-biometric-interface-integrator/package.json +++ b/secure-biometric-interface-integrator/package.json @@ -1,7 +1,7 @@ { "name": "secure-biometric-interface-integrator", "description": "A vanillaJs library for integrating Secure Biometric Devices", - "version": "0.9.2", + "version": "0.9.2-beta.0", "license": "MPL-2.0", "main": "dist/cjs/index.js", "module": "dist/es/index.js",