Configuration, environment, and session context.

System settings are stored encrypted in the database and accessed through a caching layer. Environment variables provide runtime configuration for the edge deployment.

Functions

f
buildFlashCookie(
id: string,
message: string,
succeeded: boolean,
result?: string
): string

Build a flash cookie containing a success or error message, keyed by ID

f
clearFlashCookie(id: string): string

Clear a keyed flash cookie (set after reading)

f
createTypeGuard<T extends string>(values: readonly T[])

Create a type guard from a readonly array of string literal values

f
getBookingFee(): number

Get booking fee percentage from database. Returns 0 if not set.

f
getBunnyApiKey(): string

Get the Bunny CDN API key from environment

f
getBunnyDnsSubdomainSuffix(): string

Get the Bunny DNS subdomain suffix (e.g. ".tickets") from environment

f
getBunnyDnsZoneId(): string

Get the Bunny DNS zone ID from environment

f
getBunnyScriptId(): string

Get the Bunny Edge Script ID from environment

f
getCachedSession(): AuthSession | null | undefined

Return the cached session if already resolved, or undefined if not yet resolved

f
getEffectiveDomain(): string

Get the effective domain synchronously (must call loadEffectiveDomain first).

f
getEmbedHosts(): Promise<string[]>

Get allowed embed hosts from database (encrypted, parsed to array) Returns empty array if not configured (embedding allowed from anywhere)

f
getEnv(key: string): string | undefined

Get an environment variable value Checks process.env first (Bunny Edge), falls back to Deno.env (local dev)

f
getReadOnlyCutoffIso(): string | null

Get the READ_ONLY_FROM cutoff ISO string, or null if not set

f
getRenewalUrl(): string | null

Get the RENEWAL_URL, or null if not set

f
isBunnyCdnEnabled(): boolean

Check if Bunny CDN pull zone management is enabled Requires both BUNNY_API_KEY and BUNNY_SCRIPT_ID to be set

f
isBunnyDnsEnabled(): boolean

Check if Bunny DNS subdomain feature is enabled. Requires BUNNY_API_KEY and BUNNY_DNS_ZONE_ID to be set.

f
isInWarningWindow(
now: number,
cutoff: string,
warnDays: number
): boolean

Pure helper: is the current time within the warning window before cutoff?

f
isPaidEvent(event: Pick<Event, "unit_price" | "can_pay_more">): boolean

Whether an event can accept payments (has a price or allows pay-what-you-want)

f
isPaymentsEnabled(): boolean

Check if payments are enabled (any provider configured with valid keys)

f
isReadOnly(): boolean

Check if the system is in read-only mode based on the READ_ONLY_FROM cutoff

f
isReadOnlyFromCutoff(
now: number,
cutoff: string
): boolean

Pure helper: is the site read-only based on a cutoff timestamp?

f
isReadOnlyWarning(): boolean

Check if the site should show a pre-expiry warning banner

f
loadEffectiveDomain(requestUrl: string): string

Load the effective domain from DB, falling back to the request URL hostname.

f
normalizeDurationDays(value: number): number

The single definition of "a valid booking duration": a whole number of days in [1, MAX_DURATION_DAYS], with non-finite input degrading to 1.

f
parseFlashValue(value: string): { success?: string; error?: string; result?: string; }

Parse a flash cookie value into type, message, and optional result

f
parseWarnDays(
raw: string | undefined,
defaultVal?: number
): number

Parse a string into a positive integer for warning days. Returns defaultVal on bad input.

f
requireEnv(key: string): string

Get a required environment variable, throwing if not set. Use this instead of getEnv(key) as string when the variable must exist.

f
resetEffectiveDomain(): void

Reset effective domain cache (for testing).

f
runWithSessionContext<T>(fn: () => T): T

Run a function within a session-memoization scope

f
seedEffectiveDomainHost(requestUrl: string): void

Seed the effective domain from the request's own hostname.

f
setCachedSession(session: AuthSession | null): void

Store the resolved session in the current request scope

f
setEffectiveDomainForTest(domain: string): void

Set effective domain directly (for testing).

Interfaces

Type Aliases

T
AdminEvent = Omit<EventWithCount, "slug_index">

Admin API event shape — all event fields except internal indices. Used by both admin JSON API and admin templates to ensure consistent field exposure. Snake_case keys match the DB schema.

T
ContactFields =
Pick<ContactInfo, "name" | "email">
& Partial<
Pick<ContactInfo, "phone" | "address" | "special_instructions">
>

Required name+email with optional phone/address/special_instructions from ContactInfo

T
EventFields = string

Contact fields setting for an event (comma-separated ContactField names, or empty for name-only). Alias kept for documentation; runtime enforcement happens in parseEventFields.

T
EventType = "standard" | "daily"

Event type: standard (one-time) or daily (date-based booking)

T
NagId =
"payment-provider"
| "business-email"
| "domain"
| "superuser"

Unique identifiers for settings nags that prompt the admin to complete required or recommended configuration.

T
NagItem = { id: NagId; label: string; href: string; }

A single settings nag item presented to the admin.

T
PaymentProviderSetting = PaymentProviderType | "none"

Persisted payment-provider setting: an explicit provider, "none" (admin saved payments-disabled), or absent (never saved — drives the settings nag).

T
PaymentProviderType = "stripe" | "square" | "sumup"

Supported payment provider identifiers

Variables

v
CONTACT_FIELDS: readonly ContactField[]

All valid contact field names (runtime array matching the ContactField union)

v
isAdminLevel

Type guard: check if a string is a valid AdminLevel

v
isContactField

Type guard: check if an arbitrary string is a valid ContactField

v
isEventType

Type guard: check if an arbitrary string is a valid EventType

v
isPaymentProvider

Type guard: check if a string is a valid PaymentProviderType

v
isPaymentProviderSetting

Type guard: check if a string is a valid PaymentProviderSetting

v
MAX_DURATION_DAYS: 90

Upper bound on multi-day booking duration. Each day in a booking range adds a per-day clause to the atomic capacity SQL, so the cap keeps that statement bounded regardless of which write path set the value.