import { randomUUID } from 'crypto'; import { z } from 'zod'; /** The UUID of this overlay app instance */ const instanceUUID = randomUUID(); /** * OverlayEnvSchema provides a zod schema for typing the common * environment variables used to configure an Overlay worker. */ export const OverlayEnvSchema = z.object({ /** * The prefix to use for the overlay instance name, which is transformed * (by appending a UUID) into a name that's unique to this running * instance of the overlay app. */ OVERLAY_APP_NAME: z.string().transform((val) => `${val}-${instanceUUID}`), /** The user to use when connecting to NATS */ OVERLAY_NATS_USER: z.string().optional(), /** The password to use when connecting to NATS */ OVERLAY_NATS_PASSWORD: z.string().optional(), /** The servers to use when connecting to NATS */ OVERLAY_NATS_SERVERS: z.preprocess( (csvStr) => String(csvStr).split(','), z.array(z.string().url()) ), }); /** * OverlayEnvType is the typescript type described by OverlayEnvSchema. */ export type OverlayEnvType = z.infer; /** * OVERLAY_ENV is the type-safe Overlay configuration parsed from the environment. */ export const OVERLAY_ENV = OverlayEnvSchema.parse(process.env);