als-session
Version:
Flexible and secure session management library for Node.js using encrypted cookies.
24 lines (20 loc) • 812 B
JavaScript
const Schema = require('als-schema')
const { number, isFunction, isObject, isArray, string, list, lowercase,optional } = Schema
const optionsSchema = new Schema({
maxAge: [60 * 60 * 24 * 30, number(1)],
logger: [isFunction(console.log)],
name: ['session', string(1)],
methods: [
isArray(['GET', 'PUT', 'POST', 'PATCH', 'DELETE']),
(v) => { if (v.length === 0) throw new Error('At lease one method required'); return v },
(v) => v.map(m => m.toUpperCase())
],
sameSite: [String, lowercase, list(['lax', 'none', 'strict'],'lax')],
prefix:[optional,string()],
cryptOptions:[optional,isObject()],
})
function validateOptions(options) {
options = isObject({})(options)
return optionsSchema.validate(options)
}
module.exports = validateOptions