Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

castle-api-client

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

castle-api-client - npm Package Compare versions

Comparing version 5.1.2 to 6.0.0

77

CastleApiClient.js

@@ -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 @@

2

package.json
{
"name": "castle-api-client",
"version": "5.1.2",
"version": "6.0.0",
"description": "Castle API Client",

@@ -5,0 +5,0 @@ "main": "CastleApiClient.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc