Skip to content

Commit

Permalink
export integrated cookie functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Nov 14, 2023
1 parent efea671 commit 082e6b3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
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
}
2 changes: 2 additions & 0 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ module.exports = fastifyCookie
module.exports.default = fastifyCookie // supersedes fastifyCookie.default = fastifyCookie
module.exports.fastifyCookie = fastifyCookie // supersedes fastifyCookie.fastifyCookie = fastifyCookie

module.exports.cookie = cookie

module.exports.signerFactory = Signer
module.exports.Signer = Signer
module.exports.sign = sign
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);

0 comments on commit 082e6b3

Please sign in to comment.