castle-api-client
Advanced tools
Comparing version 5.1.2 to 6.0.0
@@ -62,17 +62,9 @@ let apolloFetch = require('apollo-fetch'); | ||
_makeClientId() { | ||
let alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'; | ||
let t = 'cid:'; | ||
for (let i = 0; i < 16; i++) { | ||
t += alphabet[Math.floor(Math.random() * alphabet.length)]; | ||
} | ||
return t; | ||
async setTokenAsync(token) { | ||
await this._storage.setAsync('token', token); | ||
} | ||
async getClientIdAsync() { | ||
let clientId = await this._storage.getAsync('clientId'); | ||
if (!clientId) { | ||
clientId = await this.newSessionAsync(); | ||
} | ||
return clientId; | ||
// used in mobile project still | ||
async forgetAllSessionsAsync() { | ||
this.setTokenAsync(null); | ||
} | ||
@@ -82,3 +74,6 @@ | ||
let headers = {}; | ||
headers['X-ClientId'] = await this.getClientIdAsync(); | ||
let token = await this._storage.getAsync('token'); | ||
if (token) { | ||
headers['X-Auth-Token'] = token; | ||
} | ||
return headers; | ||
@@ -90,56 +85,2 @@ } | ||
} | ||
async _getSessionsAsync() { | ||
let sessions = await this._storage.getAsync('sessions'); | ||
if (typeof sessions !== 'object' || Array.isArray(sessions)) { | ||
sessions = {}; | ||
} | ||
return sessions; | ||
} | ||
async newSessionAsync() { | ||
let clientId = this._makeClientId(); | ||
await this.setSessionAsync(clientId); | ||
return clientId; | ||
} | ||
async rememberSessionAsync(clientId) { | ||
let sessions = await this._getSessionsAsync(); | ||
sessions[clientId] = true; | ||
await this._storage.setAsync('sessions', sessions); | ||
return Object.keys(sessions); | ||
} | ||
async forgetSessionAsync(clientId) { | ||
let sessions = await this._getSessionsAsync(); | ||
delete sessions[clientId]; | ||
await this._storage.setAsync('sessions', sessions); | ||
// If this is our current clientId, then stop using it | ||
// if we are trying to forget it | ||
if (clientId === (await this.getClientIdAsync())) { | ||
await this._storage.deleteAsync('clientId'); | ||
} | ||
return Object.keys(sessions); | ||
} | ||
async forgetAllSessionsAsync() { | ||
await this._storage.deleteAsync('sessions'); | ||
await this._storage.deleteAsync('clientId'); | ||
return []; | ||
} | ||
async getAllSessionsAsync() { | ||
let sessions = await this._getSessionsAsync(); | ||
return Object.keys(sessions); | ||
} | ||
async setSessionAsync(clientId) { | ||
// Don't try to do these in parallel because there are | ||
// race conditions in some of the Storage implementations | ||
// (ex. the FileSystemStorage especially) | ||
await this.rememberSessionAsync(clientId); | ||
await this._storage.setAsync('clientId', clientId); | ||
} | ||
} | ||
@@ -146,0 +87,0 @@ |
{ | ||
"name": "castle-api-client", | ||
"version": "5.1.2", | ||
"version": "6.0.0", | ||
"description": "Castle API Client", | ||
@@ -5,0 +5,0 @@ "main": "CastleApiClient.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
179294
273
2