@evervault/sdk
Advanced tools
Comparing version 0.2.1 to 0.2.2
52
index.js
@@ -69,4 +69,27 @@ /** @format */ | ||
init: function(newUrls) { | ||
Object.assign(this.urls, newUrls); | ||
/** | ||
* @param {string} appId - the unique identifier for the application given by the evervault dashboard | ||
*/ | ||
init: function(appId, newUrls) { | ||
if (appId) { | ||
this.appId = appId; | ||
} else { | ||
throw new Error(`No appId provided to the evervault sdk`); | ||
} | ||
if (newUrls) { | ||
const urlRegex = /^(http){1}(s)?(:\/{2}){1}/; | ||
let filteredUrls = {}; | ||
Object.keys(newUrls).forEach((key) => { | ||
const givenUrl = newUrls[key]; | ||
if (urlRegex.test(givenUrl)) { | ||
filteredUrls[key] = givenUrl; | ||
} else if (givenUrl) { | ||
throw new Error( | ||
`Invalid URL received in evervault sdk for ${key} url (value: ${givenUrl})` | ||
); | ||
} | ||
}); | ||
Object.assign(this.urls, filteredUrls); | ||
} | ||
}, | ||
@@ -178,6 +201,6 @@ | ||
/** | ||
* delete a user's credentials and redirect them to evervault auth | ||
* @param {string} appId - the unique identifier for the application given by the evervault dashboard | ||
* delete a user's credentials and redirect them to evervault auth or to the give redirect url | ||
* @param {string} redirectUrl - An optional redirect url for redirecting the user after logout | ||
*/ | ||
logout: function(appId) { | ||
logout: function(redirectUrl) { | ||
localStorage.removeItem('evervault-privateKey'); | ||
@@ -187,3 +210,7 @@ localStorage.removeItem('evervault-accessToken'); | ||
localStorage.removeItem('evervault-haiku'); | ||
Utils.handleRedirect(`${this.urls.auth}/${appId}`); | ||
if (redirectUrl) { | ||
window.location.replace(redirectUrl); | ||
} else { | ||
Utils.handleRedirect(`${this.urls.auth}/${this.appId}`); | ||
} | ||
}, | ||
@@ -219,5 +246,4 @@ | ||
* will update their cached credentials | ||
* @param [string] appId - unique identifier for your app as given on the evervault dashboard | ||
*/ | ||
checkAuth: function(appId) { | ||
checkAuth: function() { | ||
const urlKey = window.location.hash.substring(2); | ||
@@ -229,12 +255,14 @@ window.location.hash = '/'; | ||
const hasStorageCredentials = | ||
accessToken && refreshToken && cachedPrivateKey; | ||
const hasStorageCredentials = Boolean( | ||
accessToken && refreshToken && cachedPrivateKey | ||
); | ||
if (!hasStorageCredentials && !urlKey) { | ||
Utils.handleRedirect(`${this.urls.auth}/${appId}`); | ||
Utils.handleRedirect(`${this.urls.auth}/${this.appId}`); | ||
} else if (urlKey) { | ||
//user has key in url but not stored in memory | ||
Utils.setUserKeysInStorage(urlKey); | ||
return true; | ||
} | ||
return hasStorageCredentials; | ||
}, | ||
}; |
{ | ||
"name": "@evervault/sdk", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "evervault Browser SDK", | ||
@@ -19,4 +19,2 @@ "repository": { | ||
"devDependencies": { | ||
"webpack": "^4.41.2", | ||
"webpack-cli": "^3.3.10", | ||
"@babel/core": "^7.6.2", | ||
@@ -26,4 +24,6 @@ "babel-preset-es2015": "^6.24.1", | ||
"chai": "^4.2.0", | ||
"mocha": "^7.0.1" | ||
"mocha": "^7.0.1", | ||
"webpack": "^4.41.2", | ||
"webpack-cli": "^3.3.11" | ||
} | ||
} |
@@ -128,3 +128,7 @@ /** @format */ | ||
.join('&'); | ||
window.location.replace(`${url}?${queryString}`); | ||
window.location.replace( | ||
`${url}${ | ||
queryString && queryString.length > 0 ? '?' + queryString : queryString | ||
}` | ||
); | ||
} | ||
@@ -131,0 +135,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
42054
622
2