import {z} from 'zod' export type Key = {key: string, description?: (string | null) | undefined, enable_interpolation_in_file?: (boolean | null) | undefined}; export type CreateApiApplicationApplicationIdEnvironmentVariableEnvironmentVariableIdAliasArgs = {applicationId: string, environmentVariableId: string, body: Key}; export type CreateApiApplicationApplicationIdEnvironmentVariableEnvironmentVariableIdAliasOptions = {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 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 }; /** * Create an environment variable alias at the application level * * POST /application/{applicationId}/environmentVariable/{environmentVariableId}/alias * * Also accepts auth: bearerAuth */ export const createApiApplicationApplicationIdEnvironmentVariableEnvironmentVariableIdAlias = async (args: CreateApiApplicationApplicationIdEnvironmentVariableEnvironmentVariableIdAliasArgs, options?: CreateApiApplicationApplicationIdEnvironmentVariableEnvironmentVariableIdAliasOptions) => { const {baseUrl = "https://api.qovery.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/application/${encodeURIComponent(String(args.applicationId))}/environmentVariable/${encodeURIComponent(String(args.environmentVariableId))}/alias${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(environmentVariable, await res.json()) };