1// Alchemy modifications are licensed under Apache-2.0.
2// This file includes third-party code; see /THIRD_PARTY_LICENSES.md.
3/**
4 * Vendored from `@astrojs/cloudflare` v14.1.3 (`src/utils/cf.ts`).
5 *
6 * Re-exports all pure helpers from `cf-helpers.ts` and adds
7 * `injectSessionBinding` which depends on the virtual module.
8 */
9import { sessionKVBindingName } from "virtual:astro-cloudflare:config";
10import type { ManifestLike } from "./cf-helpers.ts";
11
12export type { ManifestLike, Runtime } from "./cf-helpers.ts";
13export {
14 createErrorPageFetch,
15 createLocals,
16 fallbackToAssets,
17 getClientAddress,
18 matchStaticAsset,
19} from "./cf-helpers.ts";
20
21/**
22 * Injects the SESSION KV binding into the app manifest's session config.
23 * Idempotent — safe to call on every request.
24 */
25export function injectSessionBinding(manifest: ManifestLike, env: Env): void {
26 if (env[sessionKVBindingName]) {
27 const sessionConfigOptions = manifest.sessionConfig?.options ?? {};
28 Object.assign(sessionConfigOptions, {
29 binding: env[sessionKVBindingName],
30 });
31 }
32}