2.1.1 • Published 6 years ago
servie-cookie-store v2.1.1
Servie Cookie Store
Cookie storage and manipulation for Servie.
Installation
npm install servie-cookie-store --saveUsage
import { Cookie } from "servie-cookie-store";Constructor
The Cookie constructor accepts the Servie Request and Response objects. It optionally accepts a keys object for signing the cookie payloads. This object MUST have encode(data) and decode(data) methods, compatible with keysign and keycrypt. You SHOULD sign cookies when you want to avoid client-side tampering of requests.
const keys = new Keysign(["SEKRIT2", "SEKRIT1"]);
function handler(req) {
const cookie = new Cookie(req, keys);
const session = cookie.get("session");
const res = new Response();
cookie.set(res, "session", Object.assign({}, session, { demo: true }));
}Methods
get(key)retrieves the cookie bykeyname, returningundefinedwhen not found or invalidset(res, key, data, options?)sets the cookie with optional cookie optionsdelete(res, key, options?)deletes the cookie by settingmaxAgeinto past with optional cookie optionsstringify(key, data, options?)creates aSet-Cookieheader with optional cookie optionsencode(value)stringifies a JavaScript valuedecode(value)parses the cookie string into JavaScript
TypeScript
This project is written using TypeScript and publishes the definitions directly to NPM.
License
Apache 2.0