diff --git a/packages/astro/package.json b/packages/astro/package.json index 115437ec5..81bf00221 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -31,12 +31,10 @@ }, "dependencies": { "@babel/runtime": "^7.18.3", - "@types/react": "^19.0.8", - "set-cookie-parser": "^2.5.1" + "@types/react": "^19.0.8" }, "devDependencies": { "@keystatic/core": "workspace:^", - "@types/set-cookie-parser": "^2.4.2", "astro": "^5.2.5", "react": "^19.0.0", "react-dom": "^19.0.0" diff --git a/packages/astro/src/api.tsx b/packages/astro/src/api.tsx index 3330c98a2..e353ba32b 100644 --- a/packages/astro/src/api.tsx +++ b/packages/astro/src/api.tsx @@ -3,7 +3,6 @@ import { makeGenericAPIRouteHandler, } from '@keystatic/core/api/generic'; import type { APIContext } from 'astro'; -import { parseString } from 'set-cookie-parser'; export function makeHandler(_config: APIRouteConfig) { return async function keystaticAPIRoute(context: APIContext) { @@ -35,62 +34,7 @@ export function makeHandler(_config: APIRouteConfig) { } ); const { body, headers, status } = await handler(context.request); - // all this stuff should be able to go away when astro is using a version of undici with getSetCookie - let headersInADifferentStructure = new Map(); - if (headers) { - if (Array.isArray(headers)) { - for (const [key, value] of headers) { - if (!headersInADifferentStructure.has(key.toLowerCase())) { - headersInADifferentStructure.set(key.toLowerCase(), []); - } - headersInADifferentStructure.get(key.toLowerCase())!.push(value); - } - } else if (typeof headers.entries === 'function') { - for (const [key, value] of headers.entries()) { - headersInADifferentStructure.set(key.toLowerCase(), [value]); - } - if ( - 'getSetCookie' in headers && - typeof headers.getSetCookie === 'function' - ) { - const setCookieHeaders = (headers as any).getSetCookie(); - if (setCookieHeaders?.length) { - headersInADifferentStructure.set('set-cookie', setCookieHeaders); - } - } - } else { - for (const [key, value] of Object.entries(headers)) { - headersInADifferentStructure.set(key.toLowerCase(), [value]); - } - } - } - - const setCookieHeaders = headersInADifferentStructure.get('set-cookie'); - headersInADifferentStructure.delete('set-cookie'); - if (setCookieHeaders) { - for (const setCookieValue of setCookieHeaders) { - const { name, value, ...options } = parseString(setCookieValue); - const sameSite = options.sameSite?.toLowerCase(); - context.cookies.set(name, value, { - domain: options.domain, - expires: options.expires, - httpOnly: options.httpOnly, - maxAge: options.maxAge, - path: options.path, - sameSite: - sameSite === 'lax' || sameSite === 'strict' || sameSite === 'none' - ? sameSite - : undefined, - }); - } - } - - return new Response(body, { - status, - headers: [...headersInADifferentStructure.entries()].flatMap( - ([key, val]) => val.map((x): [string, string] => [key, x]) - ), - }); + return new Response(body, { status, headers }); }; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 12224912b..640ba9e35 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1062,16 +1062,10 @@ importers: '@types/react': specifier: ^19.0.8 version: 19.0.8 - set-cookie-parser: - specifier: ^2.5.1 - version: 2.6.0 devDependencies: '@keystatic/core': specifier: workspace:^ version: link:../keystatic - '@types/set-cookie-parser': - specifier: ^2.4.2 - version: 2.4.3 astro: specifier: ^5.2.5 version: 5.2.5(@types/node@22.13.1)(idb-keyval@6.2.1)(rollup@4.34.6)(terser@5.19.4)(tsx@4.8.2)(typescript@5.5.3) @@ -6364,9 +6358,6 @@ packages: '@types/serve-static@1.15.2': resolution: {integrity: sha512-J2LqtvFYCzaj8pVYKw8klQXrLLk7TBZmQ4ShlcdkELFKGwGMfevMLneMMRkMgZxotOD9wg497LpC7O8PcvAmfw==} - '@types/set-cookie-parser@2.4.3': - resolution: {integrity: sha512-7QhnH7bi+6KAhBB+Auejz1uV9DHiopZqu7LfR/5gZZTkejJV5nYeZZpgfFoE0N8aDsXuiYpfKyfyMatCwQhyTQ==} - '@types/signal-exit@3.0.1': resolution: {integrity: sha512-OSitN9PP9E/c4tlt1Qdj3CAz5uHD9Da5rhUqlaKyQRCX1T7Zdpbk6YdeZbR2eiE2ce+NMBgVnMxGqpaPSNQDUQ==} @@ -21419,10 +21410,6 @@ snapshots: '@types/mime': 3.0.1 '@types/node': 22.13.1 - '@types/set-cookie-parser@2.4.3': - dependencies: - '@types/node': 22.13.1 - '@types/signal-exit@3.0.1': {} '@types/sockjs@0.3.33':