import {z} from 'zod' export type GetApiApplicationApplicationIdEnvironmentVariableArgs = {applicationId: string}; export type GetApiApplicationApplicationIdEnvironmentVariableOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const aPIVariableScopeEnum = z.enum(["APPLICATION", "BUILT_IN", "ENVIRONMENT", "PROJECT", "CONTAINER", "JOB", "HELM", "TERRAFORM"]); export const aPIVariableTypeEnum = z.enum(["VALUE", "ALIAS", "OVERRIDE", "BUILT_IN", "FILE"]); export const environmentVariableOverride = z.object({id: z.string(), key: z.string(), value: z.string(), mount_path: z.string(), scope: aPIVariableScopeEnum, variable_type: aPIVariableTypeEnum}); export const environmentVariableAlias = z.object({id: z.string(), key: z.string(), value: z.string(), mount_path: z.string(), scope: aPIVariableScopeEnum, variable_type: aPIVariableTypeEnum}); export const linkedServiceTypeEnum = z.enum(["APPLICATION", "CONTAINER", "DATABASE", "JOB", "HELM", "TERRAFORM"]); export const environmentVariable = z.object({id: z.string(), created_at: z.string(), updated_at: z.string().optional(), key: z.string(), value: z.string().optional(), mount_path: z.string().nullable().optional(), description: z.string().max(255).nullable().optional(), enable_interpolation_in_file: z.boolean().nullable().optional(), overridden_variable: environmentVariableOverride.optional(), aliased_variable: environmentVariableAlias.optional(), scope: aPIVariableScopeEnum, variable_type: aPIVariableTypeEnum, service_id: z.string().optional(), service_name: z.string().optional(), service_type: linkedServiceTypeEnum.optional(), owned_by: z.string().optional()}); export const environmentVariableResponseList = z.object({results: z.array(environmentVariable).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List environment variables * * GET /application/{applicationId}/environmentVariable * * Also accepts auth: bearerAuth */ export const getApiApplicationApplicationIdEnvironmentVariable = async (args: GetApiApplicationApplicationIdEnvironmentVariableArgs, options?: GetApiApplicationApplicationIdEnvironmentVariableOptions) => { const {baseUrl = "https://api.qovery.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/application/${encodeURIComponent(String(args.applicationId))}/environmentVariable${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(environmentVariableResponseList, await res.json()) };