/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { SDKOptions } from "./config.js"; import { dlv } from "./dlv.js"; export interface Env { LOQATE_API_KEY?: string | undefined; /** * Sets the source parameter for all supported operations */ LOQATE_SOURCE?: string | undefined; LOQATE_DEBUG?: boolean | undefined; } export const envSchema: z.ZodType = z.object({ LOQATE_API_KEY: z.string().optional(), LOQATE_SOURCE: z.string().default("loqate-core-sdk-typescript"), LOQATE_DEBUG: z.coerce.boolean().optional(), }); /** * 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; } let envObject: Record = {}; if (isDeno()) { envObject = (globalThis as any).Deno?.env?.toObject?.() ?? {}; } else { envObject = dlv(globalThis, "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.LOQATE_SOURCE !== "undefined") { clone.source ??= envVars.LOQATE_SOURCE; } return clone; }