Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export integrated cookie functionality #263

Merged
merged 5 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 10 additions & 8 deletions cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@

'use strict'

/**
* Module exports.
* @public
*/

exports.parse = parse
exports.serialize = serialize

/**
* Module variables.
* @private
Expand Down Expand Up @@ -223,3 +215,13 @@ function tryDecode (str, decode) {
return str
}
}

/**
* Module exports.
* @public
*/

module.exports = {
parse,
serialize
}
mcollina marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ module.exports = fastifyCookie
module.exports.default = fastifyCookie // supersedes fastifyCookie.default = fastifyCookie
module.exports.fastifyCookie = fastifyCookie // supersedes fastifyCookie.fastifyCookie = fastifyCookie

module.exports.serialize = cookie.serialize
module.exports.parse = cookie.parse

module.exports.signerFactory = Signer
module.exports.Signer = Signer
module.exports.sign = sign
Expand Down
2 changes: 1 addition & 1 deletion test/cookie-module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const tap = require('tap')
const test = tap.test

const cookie = require('../cookie')
const cookie = require('..')

test('parse: argument validation', (t) => {
t.plan(2)
Expand Down
6 changes: 6 additions & 0 deletions types/plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ declare namespace fastifyCookie {
signed?: boolean;
}

export interface ParseOptions {
decode?: (encodedURIComponent: string) => string;
}

type HookType = 'onRequest' | 'preParsing' | 'preValidation' | 'preHandler' | 'preSerialization';

export interface FastifyCookieOptions {
Expand All @@ -162,6 +166,8 @@ declare namespace fastifyCookie {
export const unsign: Unsign;

export interface FastifyCookie extends FastifyCookiePlugin {
parse: (cookieHeader: string, opts?: ParseOptions) => { [key: string]: string };
serialize: (name: string, value: string, opts?: SerializeOptions) => string;
signerFactory: SignerFactory;
Signer: Signer;
sign: Sign;
Expand Down
3 changes: 3 additions & 0 deletions types/plugin.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,6 @@ 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);
Loading