{"version":3,"sources":["../../../../src/core/utils/request/getRequestCookies.ts"],"sourcesContent":["import cookieUtils from '@bundled-es-modules/cookie'\nimport { cookieStore } from '../cookieStore'\n\nfunction getAllDocumentCookies() {\n return cookieUtils.parse(document.cookie)\n}\n\nfunction getDocumentCookies(request: Request): Record {\n if (typeof document === 'undefined' || typeof location === 'undefined') {\n return {}\n }\n\n switch (request.credentials) {\n case 'same-origin': {\n const requestUrl = new URL(request.url)\n\n // Return document cookies only when requested a resource\n // from the same origin as the current document.\n return location.origin === requestUrl.origin\n ? getAllDocumentCookies()\n : {}\n }\n\n case 'include': {\n // Return all document cookies.\n return getAllDocumentCookies()\n }\n\n default: {\n return {}\n }\n }\n}\n\nexport function getAllRequestCookies(request: Request): Record {\n /**\n * @note While the \"cookie\" header is a forbidden header field\n * in the browser, you can read it in Node.js. We need to respect\n * it for mocking in Node.js.\n */\n const requestCookieHeader = request.headers.get('cookie')\n const cookiesFromHeaders = requestCookieHeader\n ? cookieUtils.parse(requestCookieHeader)\n : {}\n\n const cookiesFromDocument = getDocumentCookies(request)\n\n // Forward the document cookies to the request headers.\n for (const name in cookiesFromDocument) {\n request.headers.append(\n 'cookie',\n cookieUtils.serialize(name, cookiesFromDocument[name]),\n )\n }\n\n const cookiesFromStore = cookieStore.getCookiesSync(request.url)\n const storedCookiesObject = Object.fromEntries(\n cookiesFromStore.map((cookie) => [cookie.key, cookie.value]),\n )\n\n // Forward the raw stored cookies to request headers\n // so they contain metadata like \"expires\", \"secure\", etc.\n for (const cookie of cookiesFromStore) {\n request.headers.append('cookie', cookie.toString())\n }\n\n return {\n ...cookiesFromDocument,\n ...storedCookiesObject,\n ...cookiesFromHeaders,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAwB;AACxB,yBAA4B;AAE5B,SAAS,wBAAwB;AAC/B,SAAO,cAAAA,QAAY,MAAM,SAAS,MAAM;AAC1C;AAEA,SAA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