diff --git a/cookie.js b/cookie.js index 349db26..5b55a4c 100644 --- a/cookie.js +++ b/cookie.js @@ -28,14 +28,6 @@ 'use strict' -/** - * Module exports. - * @public - */ - -exports.parse = parse -exports.serialize = serialize - /** * Module variables. * @private @@ -223,3 +215,13 @@ function tryDecode (str, decode) { return str } } + +/** + * Module exports. + * @public + */ + +module.exports = { + parse, + serialize +} diff --git a/plugin.js b/plugin.js index 81e7432..0953e88 100644 --- a/plugin.js +++ b/plugin.js @@ -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 diff --git a/types/plugin.d.ts b/types/plugin.d.ts index 23e7500..fcd79ab 100644 --- a/types/plugin.d.ts +++ b/types/plugin.d.ts @@ -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 { @@ -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; diff --git a/types/plugin.test-d.ts b/types/plugin.test-d.ts index 12ac223..048c6e9 100644 --- a/types/plugin.test-d.ts +++ b/types/plugin.test-d.ts @@ -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);