From b26863d94a44bc03470407dce109c59025eb5ecb Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Thu, 17 Aug 2017 15:28:52 +0200 Subject: [PATCH] [cookies] update typings to v0.7 --- types/cookies/cookies-tests.ts | 26 ++++++++++++++++++++++---- types/cookies/index.d.ts | 21 +++++++++++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/types/cookies/cookies-tests.ts b/types/cookies/cookies-tests.ts index c65bcbd4aa..2cdbfa51fe 100644 --- a/types/cookies/cookies-tests.ts +++ b/types/cookies/cookies-tests.ts @@ -1,23 +1,35 @@ import * as Cookies from 'cookies'; import * as http from 'http'; +import * as Keygrip from 'keygrip'; +import * as express from 'express'; +import * as connect from 'connect'; const server = http.createServer((req, res) => { const cookies = new Cookies(req, res); + new Cookies(req, res, {keys: []}); + new Cookies(req, res, {keys: new Keygrip([])}); + new Cookies(req, res, {secure: true}); + let unsigned: string; let signed: string; let tampered: string; if (req.url === "/set") { cookies - // set a regular cookie + // set a regular cookie .set("unsigned", "foo", { httpOnly: false }) - // set a signed cookie + // set a signed cookie .set("signed", "bar", { signed: true }) - // mimic a signed cookie, but with a bogus signature + // mimic a signed cookie, but with a bogus signature .set("tampered", "baz") - .set("tampered.sig", "bogus"); + .set("tampered.sig", "bogus") + + // sameSite option + .set("samesite", "same", {sameSite: 'lax'}) + .set("samesite", "same", {sameSite: 'strict'}) + .set("samesite", "same", {sameSite: false}); res.writeHead(302, { Location: "/" }); return res.end("Now let's check."); @@ -37,3 +49,9 @@ const server = http.createServer((req, res) => { "tampered: " + tampered + "\n\n" ); }); + +const eApp = express(); +eApp.use(Cookies.express([])); + +const cApp = connect(); +cApp.use(Cookies.connect([])); diff --git a/types/cookies/index.d.ts b/types/cookies/index.d.ts index 55feb7ec7d..ce9ed05eb5 100644 --- a/types/cookies/index.d.ts +++ b/types/cookies/index.d.ts @@ -1,11 +1,15 @@ -// Type definitions for cookies 0.6 +// Type definitions for cookies 0.7 // Project: https://github.com/pillarjs/cookies -// Definitions by: Wang Zishi , jKey Lu +// Definitions by: Wang Zishi +// jKey Lu +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// import { IncomingMessage, ServerResponse } from 'http'; import * as Keygrip from 'keygrip'; +import * as express from 'express'; +import * as connect from 'connect'; interface Cookies { secure: boolean; @@ -38,7 +42,7 @@ declare namespace Cookies { type IOptions = SetOption; interface Option { - keys: string[] | Keygrip; + keys?: string[] | Keygrip; secure?: boolean; } @@ -78,6 +82,11 @@ declare namespace Cookies { * and not made available to client JavaScript (true by default). */ httpOnly?: boolean; + /** + * a boolean or string indicating whether the cookie is a "same site" cookie (false by default). + * This can be set to 'strict', 'lax', or true (which maps to 'strict'). + */ + sameSite?: 'strict' | 'lax' | boolean; /** * a boolean indicating whether the cookie is to be signed (false by default). * If this is true, another cookie of the same name with the .sig suffix @@ -102,7 +111,7 @@ declare namespace Cookies { name: string; value: string; /** - * "maxage"" is deprecated, use "maxAge" instead + * "maxage" is deprecated, use "maxAge" instead */ maxage: number; maxAge: number; @@ -111,6 +120,7 @@ declare namespace Cookies { domain: string; secure: boolean; httpOnly: boolean; + sameSite: boolean; overwrite: boolean; toString(): string; @@ -146,6 +156,9 @@ interface CookiesFunction { Cookie: { new (name: string, value?: string, attrs?: Cookies.CookieAttr): Cookies.Cookie; }; + + express(keys: string[] | Keygrip): express.Handler; + connect(keys: string[] | Keygrip): connect.NextHandleFunction; } declare const Cookies: CookiesFunction;