Skip to content

Commit

Permalink
Merge pull request #84 from Infosys/bug/sbi_issue
Browse files Browse the repository at this point in the history
[ES-1984] modified all number to string, default number values also
  • Loading branch information
Prafulrakhade authored Dec 6, 2024
2 parents a61fab8 + bdbce4f commit 98f0c47
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 24 deletions.
4 changes: 2 additions & 2 deletions secure-biometric-interface-integrator/package.json
Original file line number Diff line number Diff line change
@@ -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-beta.0",
"license": "MPL-2.0",
"main": "dist/cjs/index.js",
"module": "dist/es/index.js",
Expand All @@ -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",
Expand Down
82 changes: 60 additions & 22 deletions secure-biometric-interface-integrator/utility/sbiservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
},
],
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 98f0c47

Please sign in to comment.