New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

redisess

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redisess - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

125

lib/SessionManager.js

@@ -74,2 +74,3 @@ const crypto = require('crypto');

*
* @class
*/

@@ -148,3 +149,3 @@ class SessionManager {

return session.update().then(() => session);
return session.freshen().then(() => session);
}

@@ -163,3 +164,3 @@

const session = new Session(this, {sessionId});
return session.refresh().then(() => {
return session.read().then(() => {
if (!session.valid)

@@ -169,3 +170,3 @@ return undefined;

return session;
return session.update().then(() => session);
return session.freshen().then(() => session);
});

@@ -293,3 +294,3 @@ }

/**
*
* Stops wipe timer
*/

@@ -356,2 +357,7 @@ quit() {

/**
* Retrieves the SessionManager instance
*
* @return {number}
*/
get manager() {

@@ -361,2 +367,7 @@ return this._manager;

/**
* Retrieves session id value
*
* @return {number}
*/
get sessionId() {

@@ -366,2 +377,7 @@ return this._sessionId;

/**
* Retrieves user id value
*
* @return {number}
*/
get userId() {

@@ -371,2 +387,7 @@ return this._userId;

/**
* Retrieves Time-To-Live value
*
* @return {number}
*/
get ttl() {

@@ -376,2 +397,7 @@ return this._ttl;

/**
* Retrieves the time (unix) of last access
*
* @return {number}
*/
get lastAccess() {

@@ -381,2 +407,7 @@ return this._lastAccess;

/**
* Retrieves the time (unix) that session be expired.
*
* @return {number}
*/
get expires() {

@@ -386,2 +417,7 @@ return this._expires;

/**
* Retrieves duration that session be expired.
*
* @return {number}
*/
get expiresIn() {

@@ -396,2 +432,7 @@ return this._expires ?

/**
* Retrieves idle duration in seconds
*
* @return {number}
*/
get idle() {

@@ -401,3 +442,8 @@ return this.manager._now() - this.lastAccess;

refresh() {
/**
* Reads session info from redis server
*
* @return {Promise}
*/
read() {
const manager = this._manager;

@@ -416,3 +462,8 @@ const sessKey = manager._ns + ':' + manager._appName +

update() {
/**
* Updates last access time and resets idle timer
*
* @return {Promise}
*/
freshen() {
const manager = this._manager;

@@ -432,3 +483,2 @@ return manager._getClient().then(client => {

throw new Error('Unable to store session due to an unknown error');
return true;
});

@@ -439,2 +489,3 @@ });

/**
* Retrieves user data from session
*

@@ -502,2 +553,9 @@ * @param {string|Array<String>|Object<String,*>} key

/**
* Stores user data to session
*
* @param {string|Object} key
* @param {*} [value]
* @return {Promise<number>}
*/
set(key, value) {

@@ -507,21 +565,5 @@ const manager = this._manager;

':sess_' + this.sessionId;
const makeTyped = (v) => {
if (v instanceof Buffer)
return 'b' + v.toString('base64');
if (v instanceof Date)
return 'd' + v.toISOString();
if (typeof v === 'number')
return 'n' + String(v);
if (typeof v === 'object')
return 'o' + zlib.deflateSync(JSON.stringify(v)).toString('base64');
return 's' + String(v);
};
return manager._getClient().then(client => {
let values = [];
if (typeof key === 'object') {
for (const k of Object.keys(key)) {
values.push('$' + k);
values.push(makeTyped(key[k]));
}
} else values = ['$' + key, makeTyped(value)];
const values = this._prepareUserData(key, value);
return client.hmset(sessKey, values).then(resp => {

@@ -538,4 +580,5 @@ /* istanbul ignore next */

/**
* Kills the session
*
* @return {Promise<Boolean>}
* @return {Promise}
*/

@@ -552,3 +595,2 @@ kill() {

throw new Error('Unable to store session due to an unknown error');
return true;
});

@@ -558,2 +600,31 @@ });

/**
*
* @param {string|Object} key
* @param {*} [value]
* @return {Array<String>}
* @private
*/
_prepareUserData(key, value) {
const makeTyped = (v) => {
if (v instanceof Buffer)
return 'b' + v.toString('base64');
if (v instanceof Date)
return 'd' + v.toISOString();
if (typeof v === 'number')
return 'n' + String(v);
if (typeof v === 'object')
return 'o' + zlib.deflateSync(JSON.stringify(v)).toString('base64');
return 's' + String(v);
};
let values = [];
if (typeof key === 'object') {
for (const k of Object.keys(key)) {
values.push('$' + k);
values.push(makeTyped(key[k]));
}
} else values = ['$' + key, makeTyped(value)];
return values;
}
}

@@ -560,0 +631,0 @@

{
"name": "redisess",
"description": "Powerful redis session manager for NodeJS",
"version": "0.2.0",
"version": "0.3.0",
"author": "Panates Ltd.",

@@ -6,0 +6,0 @@ "contributors": [

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