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

adonis-framework

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adonis-framework - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

3

package.json
{
"name": "adonis-framework",
"version": "1.1.1",
"version": "1.1.2",
"description": "Adonis framework a loosely coupled http server for adonis application, it does all the required hard work to setup a managable http server with depdendency injection in place.",

@@ -45,2 +45,3 @@ "main": "index.js",

"coveralls": "^2.11.4",
"cz-conventional-changelog": "^1.1.2",
"formidable": "^1.0.17",

@@ -47,0 +48,0 @@ "hippie": "^0.3.0",

@@ -7,2 +7,3 @@

[![Coverage Status](https://coveralls.io/repos/adonisjs/adonis-framework/badge.svg?branch=master&service=github)](https://coveralls.io/github/adonisjs/adonis-framework?branch=master)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

@@ -9,0 +10,0 @@ Adonis is a NodeJs MVC framework for humans, it is built on solid foundations making it easier to write server applications.

@@ -22,3 +22,4 @@ 'use strict'

/**
* parses cookie header and returns an object
* @function parse
* @description parses cookie header and returns an object
* @param {String} cookieHeader

@@ -25,0 +26,0 @@ * @return {Object}

@@ -17,3 +17,3 @@ 'use strict'

new winston.transports.Console({
handleExceptions: true,
handleExceptions: false,
json: false,

@@ -20,0 +20,0 @@ prefixes: 'adonis',

@@ -16,12 +16,16 @@ 'use strict'

constructor (Helpers, Config){
const sessionDir = Config.get('sessions.file.directory') || 'sessions/'
this.storagePath = Helpers.storagePath(sessionDir)
this.config = Config
}
*read (sessionId) {
/**
* @description reading session values from file for a
* given session id
* @method read
* @param {String} sessionId
* @return {Object}
*/
* read (sessionId) {
const sessionFile = path.join(this.storagePath,sessionId)

@@ -33,10 +37,14 @@ try{

}
}
*write (sessionId,data) {
/**
* writing session value to a file with sessionid
* @method write
* @param {String} sessionId
* @param {Object} data
* @return {void}
*/
* write (sessionId,data) {
const sessionFile = path.join(this.storagePath,sessionId)
return yield coFs.writeJson(sessionFile,data)
}

@@ -43,0 +51,0 @@

@@ -0,3 +1,11 @@

'use strict'
/**
* adonis-framework
* Copyright(c) 2015-2015 Harminder Virk
* MIT Licensed
*/
module.exports = {
file: require('./File/')
}

@@ -10,2 +10,3 @@ 'use strict'

const crypto = require('crypto')
const _ = require('lodash')

@@ -86,2 +87,54 @@ let helpers = exports = module.exports = {}

return sha.digest('hex')
}
/**
* @function pushToSession
* @description here we update values on session object
* which is supposed to be saved with a given driver
* also making sure we replace the existing session
* with new value if same key is used.
* @param {Object} existingSession
* @param {*} value
* @return {void}
* @public
*/
helpers.pushToSession = function (existingSession, value) {
/**
* storing whether key/value pair already exists on session
* object or not.
* @type {Boolean}
*/
let matchFound = false
/**
* if existing session is empty, simply push values
* on it.
*/
if(_.size(existingSession) === 0){
existingSession.push(value)
return
}
_.each(existingSession, function (item, index) {
/**
* if key/value pair already exists on session, update
* it's value with new value and set matchFound to
* true.
*/
if(value.d.key === item.d.key){
item = value
matchFound = true
}
existingSession[index] = item
})
/**
* if key/value pair does not exists on session. Push
* values to it.
*/
if(!matchFound){
existingSession.push(value)
}
}

@@ -24,4 +24,11 @@ 'use strict'

/**
* @description create session string to be saved with
* active driver.
* @method _makeBody
* @param {String} key
* @param {*} value
* @return {Object}
*/
_makeBody(key, value) {
/**

@@ -44,3 +51,3 @@ * getting typeof value , required to format

* body to save to session, it is the final
* format save by all drivers
* format saved by all drivers
* @type {Object}

@@ -52,8 +59,22 @@ */

}
return body
}
*put (key, value) {
/**
* @function put
* @description adding key/value pair to session
* object
* @param {String} key
* @param {*} value
* @return {void}
* @public
*/
* put (key, value) {
/**
* throwing error when key/value pair or object is not
* passed while saving cookies
*/
if(key && !value && typeof(key) !== 'object'){
throw new Error('session requires key/value pair of an object')
}

@@ -66,5 +87,5 @@ /**

/**
* session id for session , by default
* session id for session , by default
* it is null
* @type {[type]}
* @type {String}
*/

@@ -74,2 +95,10 @@ let sessionId = null

/**
* initializing existing session with an empty array.
* If existing session exists it will be replaced
* with session object.
* @type {Array}
*/
let existingSession = []
/**
* parsing existing cookies to read

@@ -82,19 +111,28 @@ * adonis-session if exists.

/**
* setting existing session if there , otherwise
* setting up existing session as an array.
* @type {Array}
* here we read session id from cookie. It will be actual
* session object if cookie driver is in use. Otherwise
* it will be the unique session id.
* @type {String}
* @encrypted false
*/
let existingSession = []
try{
existingSession = JSON.parse(cookies['adonis-session'])
}catch(e){
// ignoring error
}
sessionId = cookies['adonis-session']
if(key && !value && typeof(key) !== 'object'){
throw new Error('session requires key/value pair of an object')
/**
* we will get session information if session id
* exists otherwise we create a fresh instance
* of session
*/
if(sessionId){
if(this.constructor.driver === 'cookie'){
try{
existingSession = JSON.parse(sessionId)
}catch(e){
// ignoring error
}
}else{
existingSession = yield this.constructor.driver.read(sessionId)
}
}
if(!value && typeof(key) === 'object'){
/**

@@ -105,7 +143,5 @@ * if user has passed an object , containing multiple session

_.each(key, function (item,index) {
existingSession.push(self._makeBody(index,item))
helpers.pushToSession(existingSession,self._makeBody(index,item))
})
}else{
/**

@@ -115,13 +151,12 @@ * otherwise push original key/value pair

*/
existingSession.push(this._makeBody(key,value))
helpers.pushToSession(existingSession,self._makeBody(key,value))
}
/**
* pushing new value to existing session
* array.
* converting session back to string to be saved inside
* cookie
* @type {String}
*/
existingSession = JSON.stringify(existingSession)
if(this.constructor.driver === 'cookie'){

@@ -136,3 +171,2 @@

sessionId = existingSession
}else{

@@ -145,8 +179,6 @@

*/
sessionId = helpers.generateSessionId()
sessionId = sessionId || helpers.generateSessionId()
yield this.constructor.driver.write(sessionId,existingSession)
}
/**

@@ -175,7 +207,35 @@ * generating cookie string to push to cookies

/**
* @function get
* @description fetching session value for a given
* key
* @param {String} key
* @return {*}
* @public
*/
* get (key) {
/**
* pairs will be built by iterating over the session
* object and transforming values back to their
* original type.
* @type {Object}
*/
let pairs = {}
/**
* reading cookies from request
*/
const cookies = Cookies.parse(this.request)
/**
* looking for adonis-session key inside cookies
* @type {Object}
*/
let session = cookies['adonis-session']
let pairs = {}
/**
* if session key does not exists inside cookie
* return null
*/
if(!session){

@@ -185,2 +245,6 @@ return null

/**
* if driver is not cookie , we need to fetch values using sessionId
* from active driver
*/
if(this.constructor.driver !== 'cookie'){

@@ -190,2 +254,6 @@ session = yield this.constructor.driver.read(session)

/**
* parsing it back to object.
* @type {Object}
*/
session = JSON.parse(session)

@@ -192,0 +260,0 @@

Sorry, the diff of this file is not supported yet

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