diff --git a/README.md b/README.md
index 8ae8802..43ff896 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
[![CI](https://github.com/fastify/fastify-cookie/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-cookie/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/cookie.svg?style=flat)](https://www.npmjs.com/package/@fastify/cookie)
-[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
+[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
A plugin for [Fastify](http://fastify.dev/) that adds support for reading and
setting cookies.
diff --git a/package.json b/package.json
index 11062d0..b07c8fd 100644
--- a/package.json
+++ b/package.json
@@ -7,9 +7,8 @@
"types": "types/plugin.d.ts",
"scripts": {
"coverage": "npm run test:unit -- --coverage-report=html",
- "lint": "standard | snazzy",
- "lint:ci": "standard",
- "lint:fix": "standard --fix",
+ "lint": "eslint",
+ "lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
"test:unit": "tap",
@@ -44,9 +43,8 @@
"@types/node": "^22.0.0",
"benchmark": "^2.1.4",
"fastify": "^5.0.0",
+ "neostandard": "^0.11.9",
"sinon": "^19.0.2",
- "snazzy": "^9.0.0",
- "standard": "^17.1.0",
"tap": "^18.6.1",
"tsd": "^0.31.1"
},
diff --git a/types/plugin.d.ts b/types/plugin.d.ts
index ef4af4f..fdba3fb 100644
--- a/types/plugin.d.ts
+++ b/types/plugin.d.ts
@@ -1,8 +1,8 @@
///
-import { FastifyPluginCallback } from "fastify";
+import { FastifyPluginCallback } from 'fastify'
-declare module "fastify" {
+declare module 'fastify' {
interface FastifyInstance extends SignerMethods {
/**
* Serialize a cookie name-value pair into a Set-Cookie header string
@@ -42,7 +42,7 @@ declare module "fastify" {
* Signs the specified cookie using the secret/signer provided.
* @param value cookie value
*/
- signCookie(value: string): string;
+ signCookie(value: string): string;
/**
* Unsigns the specified cookie using the secret/signer provided.
@@ -55,7 +55,7 @@ declare module "fastify" {
name: string,
value: string,
options?: fastifyCookie.CookieSerializeOptions
- ) => FastifyReply;
+ ) => FastifyReply
interface FastifyReply {
/**
@@ -96,7 +96,7 @@ declare module "fastify" {
type FastifyCookiePlugin = FastifyPluginCallback<
NonNullable
->;
+>
declare namespace fastifyCookie {
interface SignerBase {
@@ -106,8 +106,8 @@ declare namespace fastifyCookie {
export class Signer implements SignerBase {
constructor (secrets: string | Array | Buffer | Array, algorithm?: string)
- sign: (value: string) => string;
- unsign: (input: string) => UnsignResult;
+ sign: (value: string) => string
+ unsign: (input: string) => UnsignResult
}
export interface SerializeOptions {
@@ -143,7 +143,7 @@ declare namespace fastifyCookie {
decode?: (encodedURIComponent: string) => string;
}
- type HookType = 'onRequest' | 'preParsing' | 'preValidation' | 'preHandler' | 'preSerialization';
+ type HookType = 'onRequest' | 'preParsing' | 'preValidation' | 'preHandler' | 'preSerialization'
export interface FastifyCookieOptions {
secret?: string | string[] | Buffer | Buffer[] | Signer;
@@ -151,9 +151,9 @@ declare namespace fastifyCookie {
parseOptions?: fastifyCookie.CookieSerializeOptions;
}
- export type Sign = (value: string, secret: string | Buffer, algorithm?: string) => string;
- export type Unsign = (input: string, secret: string | Buffer, algorithm?: string) => UnsignResult;
- export type SignerFactory = (secrets: string | string[] | Buffer | Buffer[], algorithm?: string) => SignerBase;
+ export type Sign = (value: string, secret: string | Buffer, algorithm?: string) => string
+ export type Unsign = (input: string, secret: string | Buffer, algorithm?: string) => UnsignResult
+ export type SignerFactory = (secrets: string | string[] | Buffer | Buffer[], algorithm?: string) => SignerBase
export type UnsignResult = {
valid: true;
@@ -165,9 +165,9 @@ declare namespace fastifyCookie {
value: null;
}
- export const signerFactory: SignerFactory;
- export const sign: Sign;
- export const unsign: Unsign;
+ export const signerFactory: SignerFactory
+ export const sign: Sign
+ export const unsign: Unsign
export interface FastifyCookie extends FastifyCookiePlugin {
parse: (cookieHeader: string, opts?: ParseOptions) => { [key: string]: string };
@@ -178,7 +178,7 @@ declare namespace fastifyCookie {
unsign: Unsign;
}
- export const fastifyCookie: FastifyCookie;
+ export const fastifyCookie: FastifyCookie
export interface FastifyCookieOptions {
secret?: string | string[] | Buffer | Buffer[] | SignerBase;
@@ -186,11 +186,11 @@ declare namespace fastifyCookie {
parseOptions?: CookieSerializeOptions;
}
- export { fastifyCookie as default };
+ export { fastifyCookie as default }
}
-declare function fastifyCookie(
+declare function fastifyCookie (
...params: Parameters
-): ReturnType;
+): ReturnType
-export = fastifyCookie;
+export = fastifyCookie
diff --git a/types/plugin.test-d.ts b/types/plugin.test-d.ts
index 2174356..0d70ad1 100644
--- a/types/plugin.test-d.ts
+++ b/types/plugin.test-d.ts
@@ -1,67 +1,67 @@
-import cookie from '..';
-import { expectError, expectType } from 'tsd';
-import * as fastifyCookieStar from '..';
-import fastifyCookieCjsImport = require('..');
-import fastifyCookieDefault, { fastifyCookie as fastifyCookieNamed } from '..';
-import fastify, { FastifyInstance, FastifyReply, setCookieWrapper } from 'fastify';
-
-const fastifyCookieCjs = require('..');
-
-const app: FastifyInstance = fastify();
-app.register(fastifyCookieNamed);
-app.register(fastifyCookieDefault);
-app.register(fastifyCookieCjs);
-app.register(fastifyCookieCjsImport.default);
-app.register(fastifyCookieCjsImport.fastifyCookie);
-app.register(fastifyCookieStar.default);
-app.register(fastifyCookieStar.fastifyCookie);
-
-expectType(fastifyCookieNamed);
-expectType(fastifyCookieDefault);
-expectType(fastifyCookieCjsImport.default);
-expectType(fastifyCookieCjsImport.fastifyCookie);
-expectType(fastifyCookieStar.default);
+import cookie from '..'
+import { expectError, expectType } from 'tsd'
+import * as fastifyCookieStar from '..'
+import fastifyCookieCjsImport = require('..')
+import fastifyCookieDefault, { fastifyCookie as fastifyCookieNamed } from '..'
+import fastify, { FastifyInstance, FastifyReply, setCookieWrapper } from 'fastify'
+
+const fastifyCookieCjs = require('..')
+
+const app: FastifyInstance = fastify()
+app.register(fastifyCookieNamed)
+app.register(fastifyCookieDefault)
+app.register(fastifyCookieCjs)
+app.register(fastifyCookieCjsImport.default)
+app.register(fastifyCookieCjsImport.fastifyCookie)
+app.register(fastifyCookieStar.default)
+app.register(fastifyCookieStar.fastifyCookie)
+
+expectType(fastifyCookieNamed)
+expectType(fastifyCookieDefault)
+expectType(fastifyCookieCjsImport.default)
+expectType(fastifyCookieCjsImport.fastifyCookie)
+expectType(fastifyCookieStar.default)
expectType(
fastifyCookieStar.fastifyCookie
-);
-expectType(fastifyCookieCjs);
+)
+expectType(fastifyCookieCjs)
-expectType(fastifyCookieDefault.sign);
-expectType(fastifyCookieDefault.unsign);
-expectType(fastifyCookieDefault.signerFactory );
+expectType(fastifyCookieDefault.sign)
+expectType(fastifyCookieDefault.unsign)
+expectType(fastifyCookieDefault.signerFactory)
-expectType(fastifyCookieNamed.sign);
-expectType(fastifyCookieNamed.unsign);
-expectType(fastifyCookieNamed.signerFactory );
+expectType(fastifyCookieNamed.sign)
+expectType(fastifyCookieNamed.unsign)
+expectType(fastifyCookieNamed.signerFactory)
-const server = fastify();
+const server = fastify()
-server.register(cookie);
+server.register(cookie)
server.after((_err) => {
expectType< string >(
server.serializeCookie('sessionId', 'aYb4uTIhdBXC')
- );
+ )
expectType<{ [key: string]: string }>(
// See https://github.com/fastify/fastify-cookie#manual-cookie-parsing
server.parseCookie('sessionId=aYb4uTIhdBXC')
- );
+ )
server.get('/', (request, reply) => {
- const test = request.cookies.test;
- expectType(test);
+ const test = request.cookies.test
+ expectType(test)
- expectType(reply.cookie);
- expectType(reply.setCookie);
+ expectType(reply.cookie)
+ expectType(reply.setCookie)
expectType(
reply
.setCookie('test', test!, { domain: 'example.com', path: '/' })
.clearCookie('foo')
.send({ hello: 'world' })
- );
- });
+ )
+ })
expectType<(value: string) => string>(server.signCookie)
expectType<(value: string) => fastifyCookieStar.UnsignResult>(server.unsignCookie)
@@ -71,100 +71,100 @@ server.after((_err) => {
expectType<(value: string) => string>(reply.signCookie)
expectType<(value: string) => fastifyCookieStar.UnsignResult>(request.unsignCookie)
expectType<(value: string) => fastifyCookieStar.UnsignResult>(reply.unsignCookie)
- });
-});
+ })
+})
-const serverWithHttp2 = fastify({ http2: true });
+const serverWithHttp2 = fastify({ http2: true })
-serverWithHttp2.register(cookie);
+serverWithHttp2.register(cookie)
serverWithHttp2.after(() => {
serverWithHttp2.get('/', (request, reply) => {
- const test = request.cookies.test;
+ const test = request.cookies.test
reply
.setCookie('test', test!, { domain: 'example.com', path: '/' })
.clearCookie('foo')
- .send({ hello: 'world' });
- });
-});
+ .send({ hello: 'world' })
+ })
+})
-const testSamesiteOptionsApp = fastify();
+const testSamesiteOptionsApp = fastify()
-testSamesiteOptionsApp.register(cookie);
+testSamesiteOptionsApp.register(cookie)
testSamesiteOptionsApp.after(() => {
server.get('/test-samesite-option-true', (request, reply) => {
- const test = request.cookies.test;
- reply.setCookie('test', test!, { sameSite: true }).send({ hello: 'world' });
- });
+ const test = request.cookies.test
+ reply.setCookie('test', test!, { sameSite: true }).send({ hello: 'world' })
+ })
server.get('/test-samesite-option-false', (request, reply) => {
- const test = request.cookies.test;
- reply.setCookie('test', test!, { sameSite: false }).send({ hello: 'world' });
- });
+ const test = request.cookies.test
+ reply.setCookie('test', test!, { sameSite: false }).send({ hello: 'world' })
+ })
server.get('/test-samesite-option-lax', (request, reply) => {
- const test = request.cookies.test;
- reply.setCookie('test', test!, { sameSite: 'lax' }).send({ hello: 'world' });
- });
+ const test = request.cookies.test
+ reply.setCookie('test', test!, { sameSite: 'lax' }).send({ hello: 'world' })
+ })
server.get('/test-samesite-option-strict', (request, reply) => {
- const test = request.cookies.test;
+ const test = request.cookies.test
reply
.setCookie('test', test!, { sameSite: 'strict' })
- .send({ hello: 'world' });
- });
+ .send({ hello: 'world' })
+ })
server.get('/test-samesite-option-none', (request, reply) => {
- const test = request.cookies.test;
+ const test = request.cookies.test
reply
.setCookie('test', test!, { sameSite: 'none' })
- .send({ hello: 'world' });
- });
-});
+ .send({ hello: 'world' })
+ })
+})
-const appWithImplicitHttpSigned = fastify();
+const appWithImplicitHttpSigned = fastify()
appWithImplicitHttpSigned.register(cookie, {
secret: 'testsecret',
-});
+})
appWithImplicitHttpSigned.register(cookie, {
secret: 'testsecret',
algorithm: 'sha512'
-});
+})
appWithImplicitHttpSigned.after(() => {
server.get('/', (request, reply) => {
- appWithImplicitHttpSigned.unsignCookie(request.cookies.test!);
- appWithImplicitHttpSigned.unsignCookie('test');
+ appWithImplicitHttpSigned.unsignCookie(request.cookies.test!)
+ appWithImplicitHttpSigned.unsignCookie('test')
- reply.unsignCookie(request.cookies.test!);
- reply.unsignCookie('test');
+ reply.unsignCookie(request.cookies.test!)
+ reply.unsignCookie('test')
- request.unsignCookie(request.cookies.anotherTest!);
- request.unsignCookie('anotherTest');
+ request.unsignCookie(request.cookies.anotherTest!)
+ request.unsignCookie('anotherTest')
- reply.send({ hello: 'world' });
- });
-});
+ reply.send({ hello: 'world' })
+ })
+})
-const appWithRotationSecret = fastify();
+const appWithRotationSecret = fastify()
appWithRotationSecret.register(cookie, {
secret: ['testsecret'],
-});
+})
appWithRotationSecret.after(() => {
server.get('/', (request, reply) => {
- reply.unsignCookie(request.cookies.test!);
- const unsigned = reply.unsignCookie('test');
+ reply.unsignCookie(request.cookies.test!)
+ const unsigned = reply.unsignCookie('test')
- expectType(unsigned.valid);
+ expectType(unsigned.valid)
if (unsigned.valid) {
- expectType(unsigned.value);
+ expectType(unsigned.value)
} else {
- expectType(unsigned.value);
+ expectType(unsigned.value)
}
- expectType(unsigned.renew);
+ expectType(unsigned.renew)
- reply.send({ hello: 'world' });
- });
-});
+ reply.send({ hello: 'world' })
+ })
+})
-const appWithParseOptions = fastify();
+const appWithParseOptions = fastify()
const parseOptions: fastifyCookieStar.CookieSerializeOptions = {
domain: 'example.com',
@@ -177,26 +177,26 @@ const parseOptions: fastifyCookieStar.CookieSerializeOptions = {
secure: true,
signed: true,
partitioned: false,
-};
-expectType(parseOptions);
+}
+expectType(parseOptions)
appWithParseOptions.register(cookie, {
secret: 'testsecret',
parseOptions,
-});
+})
appWithParseOptions.after(() => {
server.get('/', (request, reply) => {
- const unsigned = reply.unsignCookie(request.cookies.test!);
+ const unsigned = reply.unsignCookie(request.cookies.test!)
- expectType(unsigned.valid);
+ expectType(unsigned.valid)
if (unsigned.valid) {
- expectType(unsigned.value);
+ expectType(unsigned.value)
} else {
- expectType(unsigned.value);
+ expectType(unsigned.value)
}
- expectType(unsigned.renew);
- });
-});
+ expectType(unsigned.renew)
+ })
+})
const appWithCustomSigner = fastify()
@@ -214,13 +214,13 @@ appWithCustomSigner.after(() => {
reply.unsignCookie(request.cookies.test!)
const unsigned = reply.unsignCookie('test')
- expectType(unsigned.valid);
+ expectType(unsigned.valid)
if (unsigned.valid) {
- expectType(unsigned.value);
+ expectType(unsigned.value)
} else {
- expectType(unsigned.value);
+ expectType(unsigned.value)
}
- expectType(unsigned.renew);
+ expectType(unsigned.renew)
reply.send({ hello: 'world' })
})
@@ -234,16 +234,16 @@ const signer = new fastifyCookieStar.Signer(['secretStringInArray'], 'sha256')
signer.sign('Lorem Ipsum')
signer.unsign('Lorem Ipsum')
-const appWithHook: FastifyInstance = fastify();
+const appWithHook: FastifyInstance = fastify()
-appWithHook.register(cookie, { hook: false });
-appWithHook.register(cookie, { hook: 'onRequest' });
-appWithHook.register(cookie, { hook: 'preHandler' });
-appWithHook.register(cookie, { hook: 'preParsing' });
-appWithHook.register(cookie, { hook: 'preSerialization' });
-appWithHook.register(cookie, { hook: 'preValidation' });
-expectError(appWithHook.register(cookie, { hook: true }));
-expectError(appWithHook.register(cookie, { hook: 'false' }));
+appWithHook.register(cookie, { hook: false })
+appWithHook.register(cookie, { hook: 'onRequest' })
+appWithHook.register(cookie, { hook: 'preHandler' })
+appWithHook.register(cookie, { hook: 'preParsing' })
+appWithHook.register(cookie, { hook: 'preSerialization' })
+appWithHook.register(cookie, { hook: 'preValidation' })
+expectError(appWithHook.register(cookie, { hook: true }))
+expectError(appWithHook.register(cookie, { hook: 'false' }))
-expectType<(cookieHeader: string, opts?: fastifyCookieStar.ParseOptions) => { [key: string]: string }>(fastifyCookieDefault.parse);
-expectType<(name: string, value: string, opts?: fastifyCookieStar.SerializeOptions) => string>(fastifyCookieDefault.serialize);
+expectType<(cookieHeader: string, opts?: fastifyCookieStar.ParseOptions) => { [key: string]: string }>(fastifyCookieDefault.parse)
+expectType<(name: string, value: string, opts?: fastifyCookieStar.SerializeOptions) => string>(fastifyCookieDefault.serialize)