/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { SDKOptions } from "./config.js"; export interface Env { APIDECK_API_KEY?: string | undefined; /** * Sets the consumerId parameter for all supported operations */ APIDECK_CONSUMER_ID?: string | undefined; /** * Sets the appId parameter for all supported operations */ APIDECK_APP_ID?: string | undefined; APIDECK_DEBUG?: boolean | undefined; } export const envSchema: z.ZodType = z.object({ APIDECK_API_KEY: z.string().optional(), APIDECK_CONSUMER_ID: z.string().optional(), APIDECK_APP_ID: z.string().optional(), APIDECK_DEBUG: z.unknown().transform(parseEnvFlag).optional(), }); function parseEnvFlag(value: unknown): boolean { return ["true", "1", "yes", "on"].includes( String(value).trim().toLowerCase(), ); } /** * Checks for the existence of the Deno global object to determine the environment. * @returns {boolean} True if the runtime is Deno, false otherwise. */ function isDeno() { if ("Deno" in globalThis) { return true; } return false; } let envMemo: Env | undefined = undefined; /** * Reads and validates environment variables. */ export function env(): Env { if (envMemo) { return envMemo; } const globals = globalThis as { Deno?: { env?: { toObject?: () => Record } }; process?: { env?: Record }; }; let envObject: Record = {}; if (isDeno()) { envObject = globals.Deno?.env?.toObject?.() ?? {}; } else { envObject = globals.process?.env ?? {}; } envMemo = envSchema.parse(envObject); return envMemo; } /** * Clears the cached env object. Useful for testing with a fresh environment. */ export function resetEnv() { envMemo = undefined; } /** * Populates global parameters with environment variables. */ export function fillGlobals(options: SDKOptions): SDKOptions { const clone = { ...options }; const envVars = env(); if (typeof envVars.APIDECK_CONSUMER_ID !== "undefined") { clone.consumerId ??= envVars.APIDECK_CONSUMER_ID; } if (typeof envVars.APIDECK_APP_ID !== "undefined") { clone.appId ??= envVars.APIDECK_APP_ID; } return clone; }