From 4f604f3a7c9b30e1d555eb73489e7e0f7c97cb99 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 26 Jan 2025 13:16:03 -0500 Subject: [PATCH 01/11] upgrade to cookie@^1.0.2 --- packages/kit/package.json | 2 +- pnpm-lock.yaml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/kit/package.json b/packages/kit/package.json index c361f509f320..c68444dbf974 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -19,7 +19,7 @@ "type": "module", "dependencies": { "@types/cookie": "^0.6.0", - "cookie": "^0.6.0", + "cookie": "^1.0.2", "devalue": "^5.1.0", "esm-env": "^1.2.2", "import-meta-resolve": "^4.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e918a1764f38..5d605d76483a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -346,8 +346,8 @@ importers: specifier: ^0.6.0 version: 0.6.0 cookie: - specifier: ^0.6.0 - version: 0.6.0 + specifier: ^1.0.2 + version: 1.0.2 devalue: specifier: ^5.1.0 version: 5.1.0 @@ -2272,9 +2272,9 @@ packages: resolution: {integrity: sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==} engines: {node: '>= 0.6'} - cookie@0.6.0: - resolution: {integrity: sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==} - engines: {node: '>= 0.6'} + cookie@1.0.2: + resolution: {integrity: sha512-9Kr/j4O16ISv8zBBhJoi4bXOYNTkFLOqSL3UDB0njXxCXNezjeyVrJyGOWtgfs/q2km1gwBcfH8q1yEGoMYunA==} + engines: {node: '>=18'} cross-env@7.0.3: resolution: {integrity: sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==} @@ -4721,7 +4721,7 @@ snapshots: cookie@0.5.0: {} - cookie@0.6.0: {} + cookie@1.0.2: {} cross-env@7.0.3: dependencies: From b80350ef85b94f957b848774966a7db7a0c620a7 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 26 Jan 2025 13:16:47 -0500 Subject: [PATCH 02/11] add changeset --- .changeset/chilly-berries-press.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chilly-berries-press.md diff --git a/.changeset/chilly-berries-press.md b/.changeset/chilly-berries-press.md new file mode 100644 index 000000000000..fb53f51a060a --- /dev/null +++ b/.changeset/chilly-berries-press.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +chore: upgrade to cookie 1.0.2 From 126aa9877ebe0bb316d8a361effa550d49350752 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 26 Jan 2025 13:28:41 -0500 Subject: [PATCH 03/11] CookieSerializeOptions -> SerializeOptions --- packages/kit/src/exports/public.d.ts | 6 +++--- packages/kit/src/runtime/server/cookie.js | 2 +- packages/kit/src/runtime/server/fetch.js | 2 +- .../kit/src/runtime/server/page/types.d.ts | 4 ++-- packages/kit/types/index.d.ts | 18 +++++++++--------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 0d5888be0699..14cf4f983ecf 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -236,7 +236,7 @@ export interface Cookies { set: ( name: string, value: string, - opts: import('cookie').CookieSerializeOptions & { path: string } + opts: import('cookie').SerializeOptions & { path: string } ) => void; /** @@ -246,7 +246,7 @@ export interface Cookies { * @param name the name of the cookie * @param opts the options, passed directly to `cookie.serialize`. The `path` must match the path of the cookie you want to delete. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options) */ - delete: (name: string, opts: import('cookie').CookieSerializeOptions & { path: string }) => void; + delete: (name: string, opts: import('cookie').SerializeOptions & { path: string }) => void; /** * Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response. @@ -262,7 +262,7 @@ export interface Cookies { serialize: ( name: string, value: string, - opts: import('cookie').CookieSerializeOptions & { path: string } + opts: import('cookie').SerializeOptions & { path: string } ) => string; } diff --git a/packages/kit/src/runtime/server/cookie.js b/packages/kit/src/runtime/server/cookie.js index 0dc74f5a613b..517d72f39872 100644 --- a/packages/kit/src/runtime/server/cookie.js +++ b/packages/kit/src/runtime/server/cookie.js @@ -39,7 +39,7 @@ export function get_cookies(request, url, trailing_slash) { /** @type {Record} */ const new_cookies = {}; - /** @type {import('cookie').CookieSerializeOptions} */ + /** @type {import('cookie').SerializeOptions} */ const defaults = { httpOnly: true, sameSite: 'lax', diff --git a/packages/kit/src/runtime/server/fetch.js b/packages/kit/src/runtime/server/fetch.js index 417b59c93063..107e04d10542 100644 --- a/packages/kit/src/runtime/server/fetch.js +++ b/packages/kit/src/runtime/server/fetch.js @@ -153,7 +153,7 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade set_internal(name, value, { path, encode: (value) => value, - .../** @type {import('cookie').CookieSerializeOptions} */ (options) + .../** @type {import('cookie').SerializeOptions} */ (options) }); } } diff --git a/packages/kit/src/runtime/server/page/types.d.ts b/packages/kit/src/runtime/server/page/types.d.ts index 7e501b1ab418..cabe33fd60c3 100644 --- a/packages/kit/src/runtime/server/page/types.d.ts +++ b/packages/kit/src/runtime/server/page/types.d.ts @@ -1,4 +1,4 @@ -import { CookieSerializeOptions } from 'cookie'; +import { SerializeOptions } from 'cookie'; import { SSRNode, CspDirectives, ServerDataNode } from 'types'; export interface Fetched { @@ -32,5 +32,5 @@ export interface CspOpts { export interface Cookie { name: string; value: string; - options: CookieSerializeOptions & { path: string }; + options: SerializeOptions & { path: string }; } diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index a7b9cf1e4a09..8c41cb13102f 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -218,7 +218,7 @@ declare module '@sveltejs/kit' { set: ( name: string, value: string, - opts: import('cookie').CookieSerializeOptions & { path: string } + opts: import('cookie').SerializeOptions & { path: string } ) => void; /** @@ -228,7 +228,7 @@ declare module '@sveltejs/kit' { * @param name the name of the cookie * @param opts the options, passed directly to `cookie.serialize`. The `path` must match the path of the cookie you want to delete. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options) */ - delete: (name: string, opts: import('cookie').CookieSerializeOptions & { path: string }) => void; + delete: (name: string, opts: import('cookie').SerializeOptions & { path: string }) => void; /** * Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response. @@ -244,7 +244,7 @@ declare module '@sveltejs/kit' { serialize: ( name: string, value: string, - opts: import('cookie').CookieSerializeOptions & { path: string } + opts: import('cookie').SerializeOptions & { path: string } ) => string; } @@ -1952,7 +1952,7 @@ declare module '@sveltejs/kit' { export type NumericRange = Exclude, LessThan>; export const VERSION: string; class HttpError_1 { - + constructor(status: number, body: { message: string; } extends App.Error ? (App.Error | string | undefined) : App.Error); @@ -1961,7 +1961,7 @@ declare module '@sveltejs/kit' { toString(): string; } class Redirect_1 { - + constructor(status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308, location: string); status: 301 | 302 | 303 | 307 | 308 | 300 | 304 | 305 | 306; location: string; @@ -2396,11 +2396,11 @@ declare module '$app/state' { declare module '$app/stores' { export function getStores(): { - + page: typeof page; - + navigating: typeof navigating; - + updated: typeof updated; }; /** @@ -2515,4 +2515,4 @@ declare module '$service-worker' { export const version: string; } -//# sourceMappingURL=index.d.ts.map \ No newline at end of file +//# sourceMappingURL=index.d.ts.map From 4e77ead665f39c1a236135e6bfd4674ebb8b557b Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 26 Jan 2025 13:34:01 -0500 Subject: [PATCH 04/11] CookieParseOptions -> ParseOptions --- packages/kit/src/exports/public.d.ts | 4 ++-- packages/kit/src/runtime/server/cookie.js | 4 ++-- packages/kit/types/index.d.ts | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 14cf4f983ecf..c54ff9f984b0 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -215,13 +215,13 @@ export interface Cookies { * @param name the name of the cookie * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options) */ - get: (name: string, opts?: import('cookie').CookieParseOptions) => string | undefined; + get: (name: string, opts?: import('cookie').ParseOptions) => string | undefined; /** * Gets all cookies that were previously set with `cookies.set`, or from the request headers. * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options) */ - getAll: (opts?: import('cookie').CookieParseOptions) => Array<{ name: string; value: string }>; + getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>; /** * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request. diff --git a/packages/kit/src/runtime/server/cookie.js b/packages/kit/src/runtime/server/cookie.js index 517d72f39872..600716532e1c 100644 --- a/packages/kit/src/runtime/server/cookie.js +++ b/packages/kit/src/runtime/server/cookie.js @@ -55,7 +55,7 @@ export function get_cookies(request, url, trailing_slash) { /** * @param {string} name - * @param {import('cookie').CookieParseOptions} [opts] + * @param {import('cookie').ParseOptions} [opts] */ get(name, opts) { const c = new_cookies[name]; @@ -91,7 +91,7 @@ export function get_cookies(request, url, trailing_slash) { }, /** - * @param {import('cookie').CookieParseOptions} [opts] + * @param {import('cookie').ParseOptions} [opts] */ getAll(opts) { const cookies = parse(header, { decode: opts?.decode }); diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 8c41cb13102f..4dcdc32c5544 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -197,13 +197,13 @@ declare module '@sveltejs/kit' { * @param name the name of the cookie * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options) */ - get: (name: string, opts?: import('cookie').CookieParseOptions) => string | undefined; + get: (name: string, opts?: import('cookie').ParseOptions) => string | undefined; /** * Gets all cookies that were previously set with `cookies.set`, or from the request headers. * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options) */ - getAll: (opts?: import('cookie').CookieParseOptions) => Array<{ name: string; value: string }>; + getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>; /** * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request. @@ -1952,7 +1952,7 @@ declare module '@sveltejs/kit' { export type NumericRange = Exclude, LessThan>; export const VERSION: string; class HttpError_1 { - + constructor(status: number, body: { message: string; } extends App.Error ? (App.Error | string | undefined) : App.Error); @@ -1961,7 +1961,7 @@ declare module '@sveltejs/kit' { toString(): string; } class Redirect_1 { - + constructor(status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308, location: string); status: 301 | 302 | 303 | 307 | 308 | 300 | 304 | 305 | 306; location: string; @@ -2396,11 +2396,11 @@ declare module '$app/state' { declare module '$app/stores' { export function getStores(): { - + page: typeof page; - + navigating: typeof navigating; - + updated: typeof updated; }; /** @@ -2515,4 +2515,4 @@ declare module '$service-worker' { export const version: string; } -//# sourceMappingURL=index.d.ts.map +//# sourceMappingURL=index.d.ts.map \ No newline at end of file From bbab116043dc0abcba54ff3d925092ce9a4ecb5f Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 26 Jan 2025 13:38:30 -0500 Subject: [PATCH 05/11] use string | undefined where necessary --- packages/kit/src/exports/public.d.ts | 2 +- packages/kit/src/runtime/server/cookie.js | 2 +- packages/kit/types/index.d.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index c54ff9f984b0..2680e276208e 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -221,7 +221,7 @@ export interface Cookies { * Gets all cookies that were previously set with `cookies.set`, or from the request headers. * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options) */ - getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>; + getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string | undefined }>; /** * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request. diff --git a/packages/kit/src/runtime/server/cookie.js b/packages/kit/src/runtime/server/cookie.js index 600716532e1c..a5e4737f54a4 100644 --- a/packages/kit/src/runtime/server/cookie.js +++ b/packages/kit/src/runtime/server/cookie.js @@ -160,7 +160,7 @@ export function get_cookies(request, url, trailing_slash) { * @param {string | null} header */ function get_cookie_header(destination, header) { - /** @type {Record} */ + /** @type {Record} */ const combined_cookies = { // cookies sent by the user agent have lowest precedence ...initial_cookies diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 4dcdc32c5544..682d08192201 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -203,7 +203,7 @@ declare module '@sveltejs/kit' { * Gets all cookies that were previously set with `cookies.set`, or from the request headers. * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options) */ - getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>; + getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string | undefined }>; /** * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request. From 37026bddbfd27b41da3749cd87412b4a6ffef4c1 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 26 Jan 2025 13:40:34 -0500 Subject: [PATCH 06/11] prettier --- packages/kit/src/exports/public.d.ts | 4 +++- packages/kit/types/index.d.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 2680e276208e..7f42a13183d8 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -221,7 +221,9 @@ export interface Cookies { * Gets all cookies that were previously set with `cookies.set`, or from the request headers. * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options) */ - getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string | undefined }>; + getAll: ( + opts?: import('cookie').ParseOptions + ) => Array<{ name: string; value: string | undefined }>; /** * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request. diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 682d08192201..7ab61a872eb9 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -203,7 +203,9 @@ declare module '@sveltejs/kit' { * Gets all cookies that were previously set with `cookies.set`, or from the request headers. * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options) */ - getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string | undefined }>; + getAll: ( + opts?: import('cookie').ParseOptions + ) => Array<{ name: string; value: string | undefined }>; /** * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request. From cf296826effa04572e18b5ad9f824f247f757b18 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Mon, 27 Jan 2025 16:47:55 -0500 Subject: [PATCH 07/11] remove @types/cookie --- packages/kit/package.json | 1 - pnpm-lock.yaml | 8 -------- 2 files changed, 9 deletions(-) diff --git a/packages/kit/package.json b/packages/kit/package.json index c68444dbf974..a56d231fe521 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -18,7 +18,6 @@ "homepage": "https://svelte.dev", "type": "module", "dependencies": { - "@types/cookie": "^0.6.0", "cookie": "^1.0.2", "devalue": "^5.1.0", "esm-env": "^1.2.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5d605d76483a..0bc7e9d54b43 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -342,9 +342,6 @@ importers: packages/kit: dependencies: - '@types/cookie': - specifier: ^0.6.0 - version: 0.6.0 cookie: specifier: ^1.0.2 version: 1.0.2 @@ -1972,9 +1969,6 @@ packages: '@types/connect@3.4.38': resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==} - '@types/cookie@0.6.0': - resolution: {integrity: sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==} - '@types/eslint@8.56.12': resolution: {integrity: sha512-03ruubjWyOHlmljCVoxSuNDdmfZDzsrrz0P2LeJsOXr+ZwFQ+0yQIwNCwt/GYhV7Z31fgtXJTAEs+FYlEL851g==} @@ -4402,8 +4396,6 @@ snapshots: dependencies: '@types/node': 18.19.50 - '@types/cookie@0.6.0': {} - '@types/eslint@8.56.12': dependencies: '@types/estree': 1.0.6 From 79503f958a145130e989dcae63a95e1447cb4880 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 29 Jan 2025 08:37:29 -0500 Subject: [PATCH 08/11] filter out nullish values in getAll() --- packages/kit/src/runtime/server/cookie.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/kit/src/runtime/server/cookie.js b/packages/kit/src/runtime/server/cookie.js index a5e4737f54a4..966a8604639f 100644 --- a/packages/kit/src/runtime/server/cookie.js +++ b/packages/kit/src/runtime/server/cookie.js @@ -105,7 +105,11 @@ export function get_cookies(request, url, trailing_slash) { } } - return Object.entries(cookies).map(([name, value]) => ({ name, value })); + return /** @type {Array<{ name: string; value: string }>} */ ( + Object.entries(cookies) + .filter(([, value]) => value != null) + .map(([name, value]) => ({ name, value })) + ); }, /** From 832d4dad8be400f3f397b4d454987c0b80b4dd24 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 29 Jan 2025 08:40:10 -0500 Subject: [PATCH 09/11] remove invalid cookie warning --- packages/kit/src/runtime/server/cookie.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/packages/kit/src/runtime/server/cookie.js b/packages/kit/src/runtime/server/cookie.js index 966a8604639f..158dd4c1d524 100644 --- a/packages/kit/src/runtime/server/cookie.js +++ b/packages/kit/src/runtime/server/cookie.js @@ -1,9 +1,6 @@ import { parse, serialize } from 'cookie'; import { add_data_suffix, normalize_path, resolve } from '../../utils/url.js'; -// eslint-disable-next-line no-control-regex -- control characters are invalid in cookie names -const INVALID_COOKIE_CHARACTER_REGEX = /[\x00-\x1F\x7F()<>@,;:"/[\]?={} \t]/; - /** * Tracks all cookies set during dev mode so we can emit warnings * when we detect that there's likely cookie misusage due to wrong paths @@ -118,16 +115,6 @@ export function get_cookies(request, url, trailing_slash) { * @param {import('./page/types.js').Cookie['options']} options */ set(name, value, options) { - // TODO: remove this check in 3.0 - const illegal_characters = name.match(INVALID_COOKIE_CHARACTER_REGEX); - if (illegal_characters) { - console.warn( - `The cookie name "${name}" will be invalid in SvelteKit 3.0 as it contains ${illegal_characters.join( - ' and ' - )}. See RFC 2616 for more details https://datatracker.ietf.org/doc/html/rfc2616#section-2.2` - ); - } - validate_options(options); set_internal(name, value, { ...defaults, ...options }); }, From 4b35912e9e2f6ac90d55567ce0dd51bcbe50e1a6 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 29 Jan 2025 08:40:28 -0500 Subject: [PATCH 10/11] revert type changes --- packages/kit/src/exports/public.d.ts | 4 +--- packages/kit/types/index.d.ts | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 7f42a13183d8..c54ff9f984b0 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -221,9 +221,7 @@ export interface Cookies { * Gets all cookies that were previously set with `cookies.set`, or from the request headers. * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options) */ - getAll: ( - opts?: import('cookie').ParseOptions - ) => Array<{ name: string; value: string | undefined }>; + getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>; /** * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request. diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 7ab61a872eb9..4dcdc32c5544 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -203,9 +203,7 @@ declare module '@sveltejs/kit' { * Gets all cookies that were previously set with `cookies.set`, or from the request headers. * @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options) */ - getAll: ( - opts?: import('cookie').ParseOptions - ) => Array<{ name: string; value: string | undefined }>; + getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>; /** * Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request. From ef525b3a900695ad7add18eaba6d77e6cd936d28 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 29 Jan 2025 08:51:12 -0500 Subject: [PATCH 11/11] clean up assertions where we are passing an explicit decode callback --- packages/kit/src/runtime/server/cookie.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/kit/src/runtime/server/cookie.js b/packages/kit/src/runtime/server/cookie.js index 158dd4c1d524..4221966b41d9 100644 --- a/packages/kit/src/runtime/server/cookie.js +++ b/packages/kit/src/runtime/server/cookie.js @@ -29,7 +29,9 @@ function validate_options(options) { */ export function get_cookies(request, url, trailing_slash) { const header = request.headers.get('cookie') ?? ''; - const initial_cookies = parse(header, { decode: (value) => value }); + const initial_cookies = /** @type {Record} */ ( + parse(header, { decode: (value) => value }) + ); const normalized_url = normalize_path(url.pathname, trailing_slash); @@ -151,7 +153,7 @@ export function get_cookies(request, url, trailing_slash) { * @param {string | null} header */ function get_cookie_header(destination, header) { - /** @type {Record} */ + /** @type {Record} */ const combined_cookies = { // cookies sent by the user agent have lowest precedence ...initial_cookies @@ -169,7 +171,9 @@ export function get_cookies(request, url, trailing_slash) { // explicit header has highest precedence if (header) { - const parsed = parse(header, { decode: (value) => value }); + const parsed = /** @type {Record} */ ( + parse(header, { decode: (value) => value }) + ); for (const name in parsed) { combined_cookies[name] = parsed[name]; }