flowstate
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -1,12 +0,4 @@ | ||
exports.Manager = require('./manager'); | ||
exports.SessionStore = require('./stores/session'); | ||
exports = module.exports = require('./middleware/state'); | ||
exports.clean = require('./middleware/clean'); | ||
exports.middleware = {}; | ||
exports.middleware.load = require('./middleware/load'); | ||
exports.middleware.complete = require('./middleware/complete'); | ||
exports.middleware.completeError = require('./middleware/completeError'); | ||
exports.middleware.clean = require('./middleware/clean'); | ||
exports.ExpiredStateError = require('./errors/expiredstateerror'); | ||
exports.MissingStateError = require('./errors/missingstateerror'); | ||
exports.SessionStore = require('./store/session'); |
@@ -1,12 +0,11 @@ | ||
var SessionStore = require('../stores/session'); | ||
var SessionStore = require('../store/session'); | ||
module.exports = function(store, options) { | ||
module.exports = function(options) { | ||
options = options || {}; | ||
var ttl = options.ttl || undefined; | ||
var store = options.store || new SessionStore(options); | ||
var limit = options.limit || undefined; | ||
return function cleanState(req, res, next) { | ||
return function clean(req, res, next) { | ||
store.all(req, function(err, states) { | ||
@@ -16,4 +15,10 @@ if (err) { return next(err); } | ||
var evict = 0; | ||
if (limit) { evict = states.length - limit; } | ||
var sorted = states.sort(function(s1, s2) { | ||
return s1.initiatedAt - s2.initiatedAt; | ||
if (s1.expires && !s2.expires) { return -1; } | ||
if (!s1.expires && !s2.expires) { return 0; } | ||
if (!s1.expires && s2.expires) { return 1; } | ||
return s1.expires.valueOf() - s2.expires.valueOf(); | ||
}); | ||
@@ -23,16 +28,11 @@ | ||
, i = 0; | ||
(function iter(err) { | ||
if (err) { return next(err); } | ||
state = states[i++]; | ||
state = sorted[i++]; | ||
if (!state) { return next(); } // done | ||
var age = Date.now() - state.initiatedAt; | ||
if (limit && (states.length - i) >= limit) { | ||
var ttl = state.expires ? state.expires.valueOf() - Date.now() : 1; | ||
if (ttl <= 0 || evict-- > 0) { | ||
store.destroy(req, state.handle, iter); | ||
} else if (ttl && age > ttl) { | ||
store.expire(req, state.handle, iter); | ||
} else { | ||
@@ -39,0 +39,0 @@ iter(); |
@@ -1,25 +0,40 @@ | ||
exports.dispatch = function(stack) { | ||
return function(err, req, res, next) { | ||
var i = 0; | ||
var uri = require('url'); | ||
function callbacks(err) { | ||
var fn = stack[i++]; | ||
try { | ||
if ('route' == err) { | ||
next('route'); | ||
} else if (err && fn) { | ||
if (fn.length < 4) return callbacks(err); | ||
fn(err, req, res, callbacks); | ||
} else if (fn) { | ||
if (fn.length < 4) return fn(req, res, callbacks); | ||
callbacks(); | ||
} else { | ||
next(err); | ||
} | ||
} catch (err) { | ||
callbacks(err); | ||
} | ||
} | ||
callbacks(err); | ||
/** | ||
* Reconstructs the original URL of the request. | ||
* | ||
* This function builds a URL that corresponds the original URL requested by the | ||
* client, including the protocol (http or https) and host. | ||
* | ||
* If the request passed through any proxies that terminate SSL, the | ||
* `X-Forwarded-Proto` header is used to detect if the request was encrypted to | ||
* the proxy, assuming that the proxy has been flagged as trusted. | ||
* | ||
* @param {http.IncomingMessage} req | ||
* @param {Object} [options] | ||
* @return {String} | ||
* @api private | ||
*/ | ||
exports.originalURL = function(req, options) { | ||
options = options || {}; | ||
var app = req.app; | ||
if (app && app.get && app.get('trust proxy')) { | ||
options.proxy = true; | ||
} | ||
} | ||
var trustProxy = options.proxy; | ||
var proto = (req.headers['x-forwarded-proto'] || '').toLowerCase() | ||
, tls = req.connection.encrypted || (trustProxy && 'https' == proto.split(/\s*,\s*/)[0]) | ||
, host = (trustProxy && req.headers['x-forwarded-host']) || req.headers.host | ||
, protocol = tls ? 'https' : 'http' | ||
, path = req.originalUrl || req.url || ''; | ||
return protocol + '://' + host + path; | ||
}; | ||
exports.originalURLWithoutQuery = function(req, options) { | ||
var loc = uri.parse(exports.originalURL(req, options), false); | ||
delete loc.search; | ||
delete loc.query; | ||
return uri.format(loc); | ||
}; |
{ | ||
"name": "flowstate", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Stateful, transactional flows using page-based navigation.", | ||
"keywords": [ | ||
"express", | ||
"connect", | ||
"state" | ||
], | ||
"author": { | ||
"name": "Jared Hanson", | ||
"email": "jaredhanson@gmail.com", | ||
"url": "http://www.jaredhanson.net/" | ||
"url": "https://www.jaredhanson.me/" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jaredhanson/statefulness.git" | ||
"url": "git://github.com/jaredhanson/flowstate.git" | ||
}, | ||
"bugs": { | ||
"url": "http://github.com/jaredhanson/statefulness/issues" | ||
"url": "https://github.com/jaredhanson/flowstate/issues" | ||
}, | ||
"funding": { | ||
"type": "github", | ||
"url": "https://github.com/sponsors/jaredhanson" | ||
}, | ||
"license": "MIT", | ||
@@ -21,21 +30,24 @@ "licenses": [ | ||
"type": "MIT", | ||
"url": "http://opensource.org/licenses/MIT" | ||
"url": "https://opensource.org/licenses/MIT" | ||
} | ||
], | ||
"main": "./lib", | ||
"dependencies": { | ||
"clone": "^1.0.2", | ||
"crc": "^3.8.0", | ||
"debug": "^3.2.7", | ||
"uid2": "^1.0.0", | ||
"utils-merge": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.0.0", | ||
"chai-express-handler": "^0.1.1", | ||
"make-node": "^0.3.0", | ||
"mocha": "^2.0.0", | ||
"chai": "^3.0.0", | ||
"sinon-chai": "^2.8.0", | ||
"chai-connect-middleware": "0.3.x" | ||
"mocha": "^2.5.3", | ||
"sinon": "^1.17.7", | ||
"sinon-chai": "^2.8.0" | ||
}, | ||
"scripts": { | ||
"test": "node_modules/.bin/mocha test/*.test.js" | ||
}, | ||
"dependencies": { | ||
"clone": "^1.0.2", | ||
"uid-safe": "^2.1.0", | ||
"utils-flatten": "^1.0.0" | ||
"test": "node_modules/.bin/mocha test/*.test.js test/**/*.test.js --require ./test/bootstrap/node" | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
# statefulness | ||
# flowstate |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
22685
16
626
0
1
5
6
1
+ Addedcrc@^3.8.0
+ Addeddebug@^3.2.7
+ Addeduid2@^1.0.0
+ Addedutils-merge@^1.0.1
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedcrc@3.8.0(transitive)
+ Addeddebug@3.2.7(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedms@2.1.3(transitive)
+ Addeduid2@1.0.0(transitive)
+ Addedutils-merge@1.0.1(transitive)
- Removeduid-safe@^2.1.0
- Removedutils-flatten@^1.0.0
- Removedrandom-bytes@1.0.0(transitive)
- Removeduid-safe@2.1.5(transitive)
- Removedutils-flatten@1.0.0(transitive)