2.1.1 • Published 5 years ago

servie-cookie-store v2.1.1

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
5 years ago

Servie Cookie Store

NPM version NPM downloads Build status Test coverage

Cookie storage and manipulation for Servie.

Installation

npm install servie-cookie-store --save

Usage

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 by key name, returning undefined when not found or invalid
  • set(res, key, data, options?) sets the cookie with optional cookie options
  • delete(res, key, options?) deletes the cookie by setting maxAge into past with optional cookie options
  • stringify(key, data, options?) creates a Set-Cookie header with optional cookie options
  • encode(value) stringifies a JavaScript value
  • decode(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

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago