vinext 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/config-matchers.d.ts.map +1 -1
- package/dist/config/config-matchers.js +5 -1
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/server/app-dev-server.js +1 -1
- package/dist/server/app-dev-server.js.map +1 -1
- package/dist/shims/headers.d.ts.map +1 -1
- package/dist/shims/headers.js +4 -1
- package/dist/shims/headers.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/shims/headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,UAAU,cAAc;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAiCD;;;;GAIG;AAGH;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAK7C;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,GAAG,IAAI,CA4BlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EACrC,GAAG,EAAE,cAAc,EACnB,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAShB;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,yBAAyB,EAAE,OAAO,GACjC,IAAI,CAyBN;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"headers.d.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AEjB;IAED,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAchF,QAAQ,IAAI,MAAM;CAOnB;AAGD,YAAY,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/shims/headers.js
CHANGED
|
@@ -156,7 +156,10 @@ export function headersContextFromRequest(request) {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
return {
|
|
159
|
-
|
|
159
|
+
// Copy into a mutable Headers instance. In Cloudflare Workers the original
|
|
160
|
+
// Request.headers is immutable; applyMiddlewareRequestHeaders() needs to
|
|
161
|
+
// call .set() on this object after middleware runs.
|
|
162
|
+
headers: new Headers(request.headers),
|
|
160
163
|
cookies,
|
|
161
164
|
};
|
|
162
165
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/shims/headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAkBrD,QAAQ;AACR,uEAAuE;AACvE,sEAAsE;AACtE,2EAA2E;AAC3E,oCAAoC;AACpC,6EAA6E;AAC7E,yCAAyC;AACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAC1D,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AACpE,MAAM,EAAE,GAAG,UAAqD,CAAC;AACjE,MAAM,IAAI,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,IAAI,iBAAiB,EAA0B,CAA8C,CAAC;AAE7H,MAAM,cAAc,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK;IAC5C,cAAc,EAAE,IAAI;IACpB,oBAAoB,EAAE,KAAK;IAC3B,iBAAiB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AQ,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;YACpC,IAAI;gBACF,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;gBACvC,IAAI,IAAI;oBAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;gBAClD,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC;gBAC1B,OAAO,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;YAC9D,CAAC;SACF,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ;QACN,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1C,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF","sourcesContent":["/**\n * next/headers shim\n *\n * Provides cookies() and headers() functions for App Router Server Components.\n * These read from a request context set by the RSC handler before rendering.\n *\n * In Next.js 15+, cookies() and headers() return Promises (async).\n * We support both the sync (legacy) and async patterns.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\n\n// ---------------------------------------------------------------------------\n// Request context\n// ---------------------------------------------------------------------------\n\ninterface HeadersContext {\n headers: Headers;\n cookies: Map<string, string>;\n}\n\ntype VinextHeadersShimState = {\n headersContext: HeadersContext | null;\n dynamicUsageDetected: boolean;\n pendingSetCookies: string[];\n draftModeCookieHeader: string | null;\n};\n\n// NOTE:\n// - This shim can be loaded under multiple module specifiers in Vite's\n// multi-environment setup (RSC/SSR). Store the AsyncLocalStorage on\n// globalThis so `connection()` (next/server) and `consumeDynamicUsage()`\n// (next/headers) always share it.\n// - We use AsyncLocalStorage so concurrent requests don't stomp each other's\n// headers/cookies/dynamic-usage state.\nconst _ALS_KEY = Symbol.for(\"vinext.nextHeadersShim.als\");\nconst _FALLBACK_KEY = Symbol.for(\"vinext.nextHeadersShim.fallback\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\nconst _als = (_g[_ALS_KEY] ??= new AsyncLocalStorage<VinextHeadersShimState>()) as AsyncLocalStorage<VinextHeadersShimState>;\n\nconst _fallbackState = (_g[_FALLBACK_KEY] ??= {\n headersContext: null,\n dynamicUsageDetected: false,\n pendingSetCookies: [],\n draftModeCookieHeader: null,\n} satisfies VinextHeadersShimState) as VinextHeadersShimState;\n\nfunction _getState(): VinextHeadersShimState {\n const state = _als.getStore();\n return state ?? _fallbackState;\n}\n\n/**\n * Dynamic usage flag — set when a component calls connection(), cookies(),\n * headers(), or noStore() during rendering. When true, ISR caching is\n * bypassed and the response gets Cache-Control: no-store.\n */\n// (stored on _state)\n\n/**\n * Mark the current render as requiring dynamic (uncached) rendering.\n * Called by connection(), cookies(), headers(), and noStore().\n */\nexport function markDynamicUsage(): void {\n _getState().dynamicUsageDetected = true;\n}\n\n/**\n * Check and reset the dynamic usage flag.\n * Called by the server after rendering to decide on caching.\n */\nexport function consumeDynamicUsage(): boolean {\n const state = _getState();\n const used = state.dynamicUsageDetected;\n state.dynamicUsageDetected = false;\n return used;\n}\n\n/**\n * Set the headers/cookies context for the current RSC render.\n * Called by the framework's RSC entry before rendering each request.\n *\n * @deprecated Prefer runWithHeadersContext() which uses als.run() for\n * proper per-request isolation. This function mutates the ALS store\n * in-place and is only safe for cleanup (ctx=null) within an existing\n * als.run() scope.\n */\nexport function setHeadersContext(ctx: HeadersContext | null): void {\n if (ctx !== null) {\n // For backward compatibility, set context on the current ALS store\n // if one exists, otherwise update the fallback. Callers should\n // migrate to runWithHeadersContext() for new-request setup.\n const existing = _als.getStore();\n if (existing) {\n existing.headersContext = ctx;\n existing.dynamicUsageDetected = false;\n existing.pendingSetCookies = [];\n existing.draftModeCookieHeader = null;\n } else {\n _fallbackState.headersContext = ctx;\n _fallbackState.dynamicUsageDetected = false;\n _fallbackState.pendingSetCookies = [];\n _fallbackState.draftModeCookieHeader = null;\n }\n return;\n }\n\n // End of request cleanup: keep the store (so consumeDynamicUsage and\n // cookie flushing can still run), but clear the request headers/cookies.\n const state = _als.getStore();\n if (state) {\n state.headersContext = null;\n } else {\n _fallbackState.headersContext = null;\n }\n}\n\n/**\n * Run a function with headers context, ensuring the context propagates\n * through all async operations (including RSC streaming).\n *\n * Uses AsyncLocalStorage.run() to guarantee per-request isolation.\n * The ALS store propagates through all async continuations including\n * ReadableStream consumption, setTimeout callbacks, and Promise chains,\n * so RSC streaming works correctly — components that render when the\n * stream is consumed still see the correct request's context.\n */\nexport function runWithHeadersContext<T>(\n ctx: HeadersContext,\n fn: () => T | Promise<T>,\n): T | Promise<T> {\n const state: VinextHeadersShimState = {\n headersContext: ctx,\n dynamicUsageDetected: false,\n pendingSetCookies: [],\n draftModeCookieHeader: null,\n };\n\n return _als.run(state, fn);\n}\n\n/**\n * Apply middleware-forwarded request headers to the current headers context.\n *\n * When Next.js middleware calls `NextResponse.next({ request: { headers } })`,\n * the modified headers are encoded as `x-middleware-request-<name>` on the\n * middleware response. This function unpacks those prefixed headers and\n * replaces the corresponding entries on the live `HeadersContext` so that\n * subsequent calls to `headers()` / `cookies()` see the middleware changes.\n */\nexport function applyMiddlewareRequestHeaders(\n middlewareResponseHeaders: Headers,\n): void {\n const state = _getState();\n if (!state.headersContext) return;\n\n const ctx = state.headersContext;\n const PREFIX = \"x-middleware-request-\";\n\n for (const [key, value] of middlewareResponseHeaders) {\n if (key.startsWith(PREFIX)) {\n const realName = key.slice(PREFIX.length);\n ctx.headers.set(realName, value);\n }\n }\n\n // If middleware modified the cookie header, rebuild the cookies map.\n const newCookieHeader = ctx.headers.get(\"cookie\");\n if (newCookieHeader !== null) {\n ctx.cookies.clear();\n for (const part of newCookieHeader.split(\";\")) {\n const [k, ...rest] = part.split(\"=\");\n if (k) {\n ctx.cookies.set(k.trim(), rest.join(\"=\").trim());\n }\n }\n }\n}\n\n/**\n * Create a HeadersContext from a standard Request object.\n */\nexport function headersContextFromRequest(request: Request): HeadersContext {\n const cookies = new Map<string, string>();\n const cookieHeader = request.headers.get(\"cookie\") || \"\";\n for (const part of cookieHeader.split(\";\")) {\n const [key, ...rest] = part.split(\"=\");\n if (key) {\n cookies.set(key.trim(), rest.join(\"=\").trim());\n }\n }\n return {\n headers: request.headers,\n cookies,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Read-only Headers instance from the incoming request.\n * Returns a Promise in Next.js 15+ style (but resolves synchronously since\n * the context is already available).\n */\nexport async function headers(): Promise<Headers> {\n const state = _getState();\n if (!state.headersContext) {\n throw new Error(\n \"headers() can only be called from a Server Component, Route Handler, \" +\n \"or Server Action. Make sure you're not calling it from a Client Component.\",\n );\n }\n markDynamicUsage();\n return state.headersContext.headers;\n}\n\n/**\n * Cookie jar from the incoming request.\n * Returns a ReadonlyRequestCookies-like object.\n */\nexport async function cookies(): Promise<RequestCookies> {\n const state = _getState();\n if (!state.headersContext) {\n throw new Error(\n \"cookies() can only be called from a Server Component, Route Handler, \" +\n \"or Server Action.\",\n );\n }\n markDynamicUsage();\n return new RequestCookies(state.headersContext.cookies);\n}\n\n// ---------------------------------------------------------------------------\n// Writable cookie accumulator for Route Handlers / Server Actions\n// ---------------------------------------------------------------------------\n\n/** Accumulated Set-Cookie headers from cookies().set() / .delete() calls */\n// (stored on _state)\n\n/**\n * Get and clear all pending Set-Cookie headers generated by cookies().set()/delete().\n * Called by the framework after rendering to attach headers to the response.\n */\nexport function getAndClearPendingCookies(): string[] {\n const state = _getState();\n const cookies = state.pendingSetCookies;\n state.pendingSetCookies = [];\n return cookies;\n}\n\n// Draft mode cookie name (matches Next.js convention)\nconst DRAFT_MODE_COOKIE = \"__prerender_bypass\";\n\n// Draft mode secret — generated once at build time via Vite `define` so the\n// __prerender_bypass cookie is consistent across all server instances (e.g.\n// multiple Cloudflare Workers isolates).\nfunction getDraftSecret(): string {\n const secret = process.env.__VINEXT_DRAFT_SECRET;\n if (!secret) {\n throw new Error(\n \"[vinext] __VINEXT_DRAFT_SECRET is not defined. \" +\n \"This should be set by the Vite plugin at build time.\",\n );\n }\n return secret;\n}\n\n// Store for Set-Cookie headers generated by draftMode().enable()/disable()\n// (stored on _state)\n\n/**\n * Get any Set-Cookie header generated by draftMode().enable()/disable().\n * Called by the framework after rendering to attach the header to the response.\n */\nexport function getDraftModeCookieHeader(): string | null {\n const state = _getState();\n const header = state.draftModeCookieHeader;\n state.draftModeCookieHeader = null;\n return header;\n}\n\ninterface DraftModeResult {\n isEnabled: boolean;\n enable(): void;\n disable(): void;\n}\n\n/**\n * Draft mode — check/toggle via a `__prerender_bypass` cookie.\n *\n * - `isEnabled`: true if the bypass cookie is present in the request\n * - `enable()`: sets the bypass cookie (for Route Handlers)\n * - `disable()`: clears the bypass cookie\n */\nexport async function draftMode(): Promise<DraftModeResult> {\n const state = _getState();\n const secret = getDraftSecret();\n const isEnabled = state.headersContext\n ? state.headersContext.cookies.get(DRAFT_MODE_COOKIE) === secret\n : false;\n\n return {\n isEnabled,\n enable(): void {\n if (state.headersContext) {\n state.headersContext.cookies.set(DRAFT_MODE_COOKIE, secret);\n }\n const secure = typeof process !== \"undefined\" && process.env?.NODE_ENV === \"production\" ? \"; Secure\" : \"\";\n state.draftModeCookieHeader =\n `${DRAFT_MODE_COOKIE}=${secret}; Path=/; HttpOnly; SameSite=Lax${secure}`;\n },\n disable(): void {\n if (state.headersContext) {\n state.headersContext.cookies.delete(DRAFT_MODE_COOKIE);\n }\n const secure = typeof process !== \"undefined\" && process.env?.NODE_ENV === \"production\" ? \"; Secure\" : \"\";\n state.draftModeCookieHeader =\n `${DRAFT_MODE_COOKIE}=; Path=/; HttpOnly; SameSite=Lax${secure}; Max-Age=0`;\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Cookie name/value validation (RFC 6265)\n// ---------------------------------------------------------------------------\n\n/**\n * RFC 6265 §4.1.1: cookie-name is a token (RFC 2616 §2.2).\n * Allowed: any visible ASCII (0x21-0x7E) except separators: ()<>@,;:\\\"/[]?={}\n */\nconst VALID_COOKIE_NAME_RE = /^[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2E\\x30-\\x39\\x41-\\x5A\\x5E-\\x7A\\x7C\\x7E]+$/;\n\nfunction validateCookieName(name: string): void {\n if (!name || !VALID_COOKIE_NAME_RE.test(name)) {\n throw new Error(`Invalid cookie name: ${JSON.stringify(name)}`);\n }\n}\n\n/**\n * Validate cookie attribute values (path, domain) to prevent injection\n * via semicolons, newlines, or other control characters.\n */\nfunction validateCookieAttributeValue(value: string, attributeName: string): void {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i);\n if (code <= 0x1F || code === 0x7F || value[i] === \";\") {\n throw new Error(`Invalid cookie ${attributeName} value: ${JSON.stringify(value)}`);\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// RequestCookies implementation\n// ---------------------------------------------------------------------------\n\nclass RequestCookies {\n private _cookies: Map<string, string>;\n\n constructor(cookies: Map<string, string>) {\n this._cookies = cookies;\n }\n\n get(name: string): { name: string; value: string } | undefined {\n const value = this._cookies.get(name);\n if (value === undefined) return undefined;\n return { name, value };\n }\n\n getAll(): Array<{ name: string; value: string }> {\n const result: Array<{ name: string; value: string }> = [];\n for (const [name, value] of this._cookies) {\n result.push({ name, value });\n }\n return result;\n }\n\n has(name: string): boolean {\n return this._cookies.has(name);\n }\n\n /**\n * Set a cookie. In Route Handlers and Server Actions, this produces\n * a Set-Cookie header on the response.\n */\n set(\n nameOrOptions: string | { name: string; value: string; path?: string; domain?: string; maxAge?: number; expires?: Date; httpOnly?: boolean; secure?: boolean; sameSite?: \"Strict\" | \"Lax\" | \"None\" },\n value?: string,\n options?: { path?: string; domain?: string; maxAge?: number; expires?: Date; httpOnly?: boolean; secure?: boolean; sameSite?: \"Strict\" | \"Lax\" | \"None\" },\n ): this {\n let cookieName: string;\n let cookieValue: string;\n let opts: typeof options;\n\n if (typeof nameOrOptions === \"string\") {\n cookieName = nameOrOptions;\n cookieValue = value ?? \"\";\n opts = options;\n } else {\n cookieName = nameOrOptions.name;\n cookieValue = nameOrOptions.value;\n opts = nameOrOptions;\n }\n\n validateCookieName(cookieName);\n\n // Update the local cookie map\n this._cookies.set(cookieName, cookieValue);\n\n // Build Set-Cookie header string\n const parts = [`${cookieName}=${encodeURIComponent(cookieValue)}`];\n if (opts?.path) {\n validateCookieAttributeValue(opts.path, \"Path\");\n parts.push(`Path=${opts.path}`);\n }\n if (opts?.domain) {\n validateCookieAttributeValue(opts.domain, \"Domain\");\n parts.push(`Domain=${opts.domain}`);\n }\n if (opts?.maxAge !== undefined) parts.push(`Max-Age=${opts.maxAge}`);\n if (opts?.expires) parts.push(`Expires=${opts.expires.toUTCString()}`);\n if (opts?.httpOnly) parts.push(\"HttpOnly\");\n if (opts?.secure) parts.push(\"Secure\");\n if (opts?.sameSite) parts.push(`SameSite=${opts.sameSite}`);\n\n _getState().pendingSetCookies.push(parts.join(\"; \"));\n return this;\n }\n\n /**\n * Delete a cookie by setting it with Max-Age=0.\n */\n delete(name: string): this {\n validateCookieName(name);\n this._cookies.delete(name);\n _getState().pendingSetCookies.push(`${name}=; Path=/; Max-Age=0`);\n return this;\n }\n\n get size(): number {\n return this._cookies.size;\n }\n\n [Symbol.iterator](): IterableIterator<[string, { name: string; value: string }]> {\n const entries = this._cookies.entries();\n const iter: IterableIterator<[string, { name: string; value: string }]> = {\n [Symbol.iterator]() { return iter; },\n next() {\n const { value, done } = entries.next();\n if (done) return { value: undefined, done: true };\n const [name, val] = value;\n return { value: [name, { name, value: val }], done: false };\n },\n };\n return iter;\n }\n\n toString(): string {\n const parts: string[] = [];\n for (const [name, value] of this._cookies) {\n parts.push(`${name}=${value}`);\n }\n return parts.join(\"; \");\n }\n}\n\n// Re-export types\nexport type { RequestCookies };\n"]}
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/shims/headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAkBrD,QAAQ;AACR,uEAAuE;AACvE,sEAAsE;AACtE,2EAA2E;AAC3E,oCAAoC;AACpC,6EAA6E;AAC7E,yCAAyC;AACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAC1D,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;AACpE,MAAM,EAAE,GAAG,UAAqD,CAAC;AACjE,MAAM,IAAI,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,IAAI,iBAAiB,EAA0B,CAA8C,CAAC;AAE7H,MAAM,cAAc,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK;IAC5C,cAAc,EAAE,IAAI;IACpB,oBAAoB,EAAE,KAAK;IAC3B,iBAAiB,EAAE,EAAE;IACrB,qBAAqB,EAAE,IAAI;CACK,CAA2B,CAAC;AAE9D,SAAS,SAAS;IAChB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC9B,OAAO,KAAK,IAAI,cAAc,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,qBAAqB;AAErB;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,SAAS,EAAE,CAAC,oBAAoB,GAAG,IAAI,CAAC;AAC1C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,oBAAoB,CAAC;IACxC,KAAK,CAAC,oBAAoB,GAAG,KAAK,C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E,CAAC;YAC9D,CAAC;SACF,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ;QACN,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1C,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF","sourcesContent":["/**\n * next/headers shim\n *\n * Provides cookies() and headers() functions for App Router Server Components.\n * These read from a request context set by the RSC handler before rendering.\n *\n * In Next.js 15+, cookies() and headers() return Promises (async).\n * We support both the sync (legacy) and async patterns.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\n\n// ---------------------------------------------------------------------------\n// Request context\n// ---------------------------------------------------------------------------\n\ninterface HeadersContext {\n headers: Headers;\n cookies: Map<string, string>;\n}\n\ntype VinextHeadersShimState = {\n headersContext: HeadersContext | null;\n dynamicUsageDetected: boolean;\n pendingSetCookies: string[];\n draftModeCookieHeader: string | null;\n};\n\n// NOTE:\n// - This shim can be loaded under multiple module specifiers in Vite's\n// multi-environment setup (RSC/SSR). Store the AsyncLocalStorage on\n// globalThis so `connection()` (next/server) and `consumeDynamicUsage()`\n// (next/headers) always share it.\n// - We use AsyncLocalStorage so concurrent requests don't stomp each other's\n// headers/cookies/dynamic-usage state.\nconst _ALS_KEY = Symbol.for(\"vinext.nextHeadersShim.als\");\nconst _FALLBACK_KEY = Symbol.for(\"vinext.nextHeadersShim.fallback\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\nconst _als = (_g[_ALS_KEY] ??= new AsyncLocalStorage<VinextHeadersShimState>()) as AsyncLocalStorage<VinextHeadersShimState>;\n\nconst _fallbackState = (_g[_FALLBACK_KEY] ??= {\n headersContext: null,\n dynamicUsageDetected: false,\n pendingSetCookies: [],\n draftModeCookieHeader: null,\n} satisfies VinextHeadersShimState) as VinextHeadersShimState;\n\nfunction _getState(): VinextHeadersShimState {\n const state = _als.getStore();\n return state ?? _fallbackState;\n}\n\n/**\n * Dynamic usage flag — set when a component calls connection(), cookies(),\n * headers(), or noStore() during rendering. When true, ISR caching is\n * bypassed and the response gets Cache-Control: no-store.\n */\n// (stored on _state)\n\n/**\n * Mark the current render as requiring dynamic (uncached) rendering.\n * Called by connection(), cookies(), headers(), and noStore().\n */\nexport function markDynamicUsage(): void {\n _getState().dynamicUsageDetected = true;\n}\n\n/**\n * Check and reset the dynamic usage flag.\n * Called by the server after rendering to decide on caching.\n */\nexport function consumeDynamicUsage(): boolean {\n const state = _getState();\n const used = state.dynamicUsageDetected;\n state.dynamicUsageDetected = false;\n return used;\n}\n\n/**\n * Set the headers/cookies context for the current RSC render.\n * Called by the framework's RSC entry before rendering each request.\n *\n * @deprecated Prefer runWithHeadersContext() which uses als.run() for\n * proper per-request isolation. This function mutates the ALS store\n * in-place and is only safe for cleanup (ctx=null) within an existing\n * als.run() scope.\n */\nexport function setHeadersContext(ctx: HeadersContext | null): void {\n if (ctx !== null) {\n // For backward compatibility, set context on the current ALS store\n // if one exists, otherwise update the fallback. Callers should\n // migrate to runWithHeadersContext() for new-request setup.\n const existing = _als.getStore();\n if (existing) {\n existing.headersContext = ctx;\n existing.dynamicUsageDetected = false;\n existing.pendingSetCookies = [];\n existing.draftModeCookieHeader = null;\n } else {\n _fallbackState.headersContext = ctx;\n _fallbackState.dynamicUsageDetected = false;\n _fallbackState.pendingSetCookies = [];\n _fallbackState.draftModeCookieHeader = null;\n }\n return;\n }\n\n // End of request cleanup: keep the store (so consumeDynamicUsage and\n // cookie flushing can still run), but clear the request headers/cookies.\n const state = _als.getStore();\n if (state) {\n state.headersContext = null;\n } else {\n _fallbackState.headersContext = null;\n }\n}\n\n/**\n * Run a function with headers context, ensuring the context propagates\n * through all async operations (including RSC streaming).\n *\n * Uses AsyncLocalStorage.run() to guarantee per-request isolation.\n * The ALS store propagates through all async continuations including\n * ReadableStream consumption, setTimeout callbacks, and Promise chains,\n * so RSC streaming works correctly — components that render when the\n * stream is consumed still see the correct request's context.\n */\nexport function runWithHeadersContext<T>(\n ctx: HeadersContext,\n fn: () => T | Promise<T>,\n): T | Promise<T> {\n const state: VinextHeadersShimState = {\n headersContext: ctx,\n dynamicUsageDetected: false,\n pendingSetCookies: [],\n draftModeCookieHeader: null,\n };\n\n return _als.run(state, fn);\n}\n\n/**\n * Apply middleware-forwarded request headers to the current headers context.\n *\n * When Next.js middleware calls `NextResponse.next({ request: { headers } })`,\n * the modified headers are encoded as `x-middleware-request-<name>` on the\n * middleware response. This function unpacks those prefixed headers and\n * replaces the corresponding entries on the live `HeadersContext` so that\n * subsequent calls to `headers()` / `cookies()` see the middleware changes.\n */\nexport function applyMiddlewareRequestHeaders(\n middlewareResponseHeaders: Headers,\n): void {\n const state = _getState();\n if (!state.headersContext) return;\n\n const ctx = state.headersContext;\n const PREFIX = \"x-middleware-request-\";\n\n for (const [key, value] of middlewareResponseHeaders) {\n if (key.startsWith(PREFIX)) {\n const realName = key.slice(PREFIX.length);\n ctx.headers.set(realName, value);\n }\n }\n\n // If middleware modified the cookie header, rebuild the cookies map.\n const newCookieHeader = ctx.headers.get(\"cookie\");\n if (newCookieHeader !== null) {\n ctx.cookies.clear();\n for (const part of newCookieHeader.split(\";\")) {\n const [k, ...rest] = part.split(\"=\");\n if (k) {\n ctx.cookies.set(k.trim(), rest.join(\"=\").trim());\n }\n }\n }\n}\n\n/**\n * Create a HeadersContext from a standard Request object.\n */\nexport function headersContextFromRequest(request: Request): HeadersContext {\n const cookies = new Map<string, string>();\n const cookieHeader = request.headers.get(\"cookie\") || \"\";\n for (const part of cookieHeader.split(\";\")) {\n const [key, ...rest] = part.split(\"=\");\n if (key) {\n cookies.set(key.trim(), rest.join(\"=\").trim());\n }\n }\n return {\n // Copy into a mutable Headers instance. In Cloudflare Workers the original\n // Request.headers is immutable; applyMiddlewareRequestHeaders() needs to\n // call .set() on this object after middleware runs.\n headers: new Headers(request.headers),\n cookies,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Read-only Headers instance from the incoming request.\n * Returns a Promise in Next.js 15+ style (but resolves synchronously since\n * the context is already available).\n */\nexport async function headers(): Promise<Headers> {\n const state = _getState();\n if (!state.headersContext) {\n throw new Error(\n \"headers() can only be called from a Server Component, Route Handler, \" +\n \"or Server Action. Make sure you're not calling it from a Client Component.\",\n );\n }\n markDynamicUsage();\n return state.headersContext.headers;\n}\n\n/**\n * Cookie jar from the incoming request.\n * Returns a ReadonlyRequestCookies-like object.\n */\nexport async function cookies(): Promise<RequestCookies> {\n const state = _getState();\n if (!state.headersContext) {\n throw new Error(\n \"cookies() can only be called from a Server Component, Route Handler, \" +\n \"or Server Action.\",\n );\n }\n markDynamicUsage();\n return new RequestCookies(state.headersContext.cookies);\n}\n\n// ---------------------------------------------------------------------------\n// Writable cookie accumulator for Route Handlers / Server Actions\n// ---------------------------------------------------------------------------\n\n/** Accumulated Set-Cookie headers from cookies().set() / .delete() calls */\n// (stored on _state)\n\n/**\n * Get and clear all pending Set-Cookie headers generated by cookies().set()/delete().\n * Called by the framework after rendering to attach headers to the response.\n */\nexport function getAndClearPendingCookies(): string[] {\n const state = _getState();\n const cookies = state.pendingSetCookies;\n state.pendingSetCookies = [];\n return cookies;\n}\n\n// Draft mode cookie name (matches Next.js convention)\nconst DRAFT_MODE_COOKIE = \"__prerender_bypass\";\n\n// Draft mode secret — generated once at build time via Vite `define` so the\n// __prerender_bypass cookie is consistent across all server instances (e.g.\n// multiple Cloudflare Workers isolates).\nfunction getDraftSecret(): string {\n const secret = process.env.__VINEXT_DRAFT_SECRET;\n if (!secret) {\n throw new Error(\n \"[vinext] __VINEXT_DRAFT_SECRET is not defined. \" +\n \"This should be set by the Vite plugin at build time.\",\n );\n }\n return secret;\n}\n\n// Store for Set-Cookie headers generated by draftMode().enable()/disable()\n// (stored on _state)\n\n/**\n * Get any Set-Cookie header generated by draftMode().enable()/disable().\n * Called by the framework after rendering to attach the header to the response.\n */\nexport function getDraftModeCookieHeader(): string | null {\n const state = _getState();\n const header = state.draftModeCookieHeader;\n state.draftModeCookieHeader = null;\n return header;\n}\n\ninterface DraftModeResult {\n isEnabled: boolean;\n enable(): void;\n disable(): void;\n}\n\n/**\n * Draft mode — check/toggle via a `__prerender_bypass` cookie.\n *\n * - `isEnabled`: true if the bypass cookie is present in the request\n * - `enable()`: sets the bypass cookie (for Route Handlers)\n * - `disable()`: clears the bypass cookie\n */\nexport async function draftMode(): Promise<DraftModeResult> {\n const state = _getState();\n const secret = getDraftSecret();\n const isEnabled = state.headersContext\n ? state.headersContext.cookies.get(DRAFT_MODE_COOKIE) === secret\n : false;\n\n return {\n isEnabled,\n enable(): void {\n if (state.headersContext) {\n state.headersContext.cookies.set(DRAFT_MODE_COOKIE, secret);\n }\n const secure = typeof process !== \"undefined\" && process.env?.NODE_ENV === \"production\" ? \"; Secure\" : \"\";\n state.draftModeCookieHeader =\n `${DRAFT_MODE_COOKIE}=${secret}; Path=/; HttpOnly; SameSite=Lax${secure}`;\n },\n disable(): void {\n if (state.headersContext) {\n state.headersContext.cookies.delete(DRAFT_MODE_COOKIE);\n }\n const secure = typeof process !== \"undefined\" && process.env?.NODE_ENV === \"production\" ? \"; Secure\" : \"\";\n state.draftModeCookieHeader =\n `${DRAFT_MODE_COOKIE}=; Path=/; HttpOnly; SameSite=Lax${secure}; Max-Age=0`;\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Cookie name/value validation (RFC 6265)\n// ---------------------------------------------------------------------------\n\n/**\n * RFC 6265 §4.1.1: cookie-name is a token (RFC 2616 §2.2).\n * Allowed: any visible ASCII (0x21-0x7E) except separators: ()<>@,;:\\\"/[]?={}\n */\nconst VALID_COOKIE_NAME_RE = /^[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2E\\x30-\\x39\\x41-\\x5A\\x5E-\\x7A\\x7C\\x7E]+$/;\n\nfunction validateCookieName(name: string): void {\n if (!name || !VALID_COOKIE_NAME_RE.test(name)) {\n throw new Error(`Invalid cookie name: ${JSON.stringify(name)}`);\n }\n}\n\n/**\n * Validate cookie attribute values (path, domain) to prevent injection\n * via semicolons, newlines, or other control characters.\n */\nfunction validateCookieAttributeValue(value: string, attributeName: string): void {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i);\n if (code <= 0x1F || code === 0x7F || value[i] === \";\") {\n throw new Error(`Invalid cookie ${attributeName} value: ${JSON.stringify(value)}`);\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// RequestCookies implementation\n// ---------------------------------------------------------------------------\n\nclass RequestCookies {\n private _cookies: Map<string, string>;\n\n constructor(cookies: Map<string, string>) {\n this._cookies = cookies;\n }\n\n get(name: string): { name: string; value: string } | undefined {\n const value = this._cookies.get(name);\n if (value === undefined) return undefined;\n return { name, value };\n }\n\n getAll(): Array<{ name: string; value: string }> {\n const result: Array<{ name: string; value: string }> = [];\n for (const [name, value] of this._cookies) {\n result.push({ name, value });\n }\n return result;\n }\n\n has(name: string): boolean {\n return this._cookies.has(name);\n }\n\n /**\n * Set a cookie. In Route Handlers and Server Actions, this produces\n * a Set-Cookie header on the response.\n */\n set(\n nameOrOptions: string | { name: string; value: string; path?: string; domain?: string; maxAge?: number; expires?: Date; httpOnly?: boolean; secure?: boolean; sameSite?: \"Strict\" | \"Lax\" | \"None\" },\n value?: string,\n options?: { path?: string; domain?: string; maxAge?: number; expires?: Date; httpOnly?: boolean; secure?: boolean; sameSite?: \"Strict\" | \"Lax\" | \"None\" },\n ): this {\n let cookieName: string;\n let cookieValue: string;\n let opts: typeof options;\n\n if (typeof nameOrOptions === \"string\") {\n cookieName = nameOrOptions;\n cookieValue = value ?? \"\";\n opts = options;\n } else {\n cookieName = nameOrOptions.name;\n cookieValue = nameOrOptions.value;\n opts = nameOrOptions;\n }\n\n validateCookieName(cookieName);\n\n // Update the local cookie map\n this._cookies.set(cookieName, cookieValue);\n\n // Build Set-Cookie header string\n const parts = [`${cookieName}=${encodeURIComponent(cookieValue)}`];\n if (opts?.path) {\n validateCookieAttributeValue(opts.path, \"Path\");\n parts.push(`Path=${opts.path}`);\n }\n if (opts?.domain) {\n validateCookieAttributeValue(opts.domain, \"Domain\");\n parts.push(`Domain=${opts.domain}`);\n }\n if (opts?.maxAge !== undefined) parts.push(`Max-Age=${opts.maxAge}`);\n if (opts?.expires) parts.push(`Expires=${opts.expires.toUTCString()}`);\n if (opts?.httpOnly) parts.push(\"HttpOnly\");\n if (opts?.secure) parts.push(\"Secure\");\n if (opts?.sameSite) parts.push(`SameSite=${opts.sameSite}`);\n\n _getState().pendingSetCookies.push(parts.join(\"; \"));\n return this;\n }\n\n /**\n * Delete a cookie by setting it with Max-Age=0.\n */\n delete(name: string): this {\n validateCookieName(name);\n this._cookies.delete(name);\n _getState().pendingSetCookies.push(`${name}=; Path=/; Max-Age=0`);\n return this;\n }\n\n get size(): number {\n return this._cookies.size;\n }\n\n [Symbol.iterator](): IterableIterator<[string, { name: string; value: string }]> {\n const entries = this._cookies.entries();\n const iter: IterableIterator<[string, { name: string; value: string }]> = {\n [Symbol.iterator]() { return iter; },\n next() {\n const { value, done } = entries.next();\n if (done) return { value: undefined, done: true };\n const [name, val] = value;\n return { value: [name, { name, value: val }], done: false };\n },\n };\n return iter;\n }\n\n toString(): string {\n const parts: string[] = [];\n for (const [name, value] of this._cookies) {\n parts.push(`${name}=${value}`);\n }\n return parts.join(\"; \");\n }\n}\n\n// Re-export types\nexport type { RequestCookies };\n"]}
|