Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

module.exports = require('neostandard')({
ignores: require('neostandard').resolveIgnoresFromGitignore(),
ts: true
})
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
38 changes: 19 additions & 19 deletions types/plugin.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// <reference types='node' />

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
Expand Down Expand Up @@ -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.
Expand All @@ -55,7 +55,7 @@ declare module "fastify" {
name: string,
value: string,
options?: fastifyCookie.CookieSerializeOptions
) => FastifyReply;
) => FastifyReply

interface FastifyReply {
/**
Expand Down Expand Up @@ -96,7 +96,7 @@ declare module "fastify" {

type FastifyCookiePlugin = FastifyPluginCallback<
NonNullable<fastifyCookie.FastifyCookieOptions>
>;
>

declare namespace fastifyCookie {
interface SignerBase {
Expand All @@ -106,8 +106,8 @@ declare namespace fastifyCookie {

export class Signer implements SignerBase {
constructor (secrets: string | Array<string> | Buffer | Array<Buffer>, algorithm?: string)
sign: (value: string) => string;
unsign: (input: string) => UnsignResult;
sign: (value: string) => string
unsign: (input: string) => UnsignResult
}

export interface SerializeOptions {
Expand Down Expand Up @@ -143,17 +143,17 @@ 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;
hook?: HookType | false;
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;
Expand All @@ -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 };
Expand All @@ -178,19 +178,19 @@ declare namespace fastifyCookie {
unsign: Unsign;
}

export const fastifyCookie: FastifyCookie;
export const fastifyCookie: FastifyCookie

export interface FastifyCookieOptions {
secret?: string | string[] | Buffer | Buffer[] | SignerBase;
algorithm?: string;
parseOptions?: CookieSerializeOptions;
}

export { fastifyCookie as default };
export { fastifyCookie as default }
}

declare function fastifyCookie(
declare function fastifyCookie (
...params: Parameters<FastifyCookiePlugin>
): ReturnType<FastifyCookiePlugin>;
): ReturnType<FastifyCookiePlugin>

export = fastifyCookie;
export = fastifyCookie
Loading