import {z} from 'zod' export type GetApiEnvironmentEnvironmentIdLifecycleTemplateLifecycleTemplateIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const cloudProviderEnum = z.enum(["AWS", "SCW", "GCP", "ON_PREMISE", "AZURE"]); export const lifecycleTemplateResponse = z.object({id: z.string(), name: z.string(), description: z.string(), sourceUrl: z.string(), cloud_provider: cloudProviderEnum, events: z.array(z.object({name: z.string(), entrypoint: z.string().optional(), command: z.array(z.string())})), max_duration_in_sec: z.number().int(), resources: z.object({cpu_milli: z.number().int(), ram_mib: z.number().int()}), variables: z.array(z.object({name: z.string(), description: z.string(), default: z.string(), is_secret: z.boolean(), file: z.object({path: z.string(), enable_interpolation: z.boolean().optional()}).optional()})), dockerfile: z.string()}); 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 }; /** * Get specific lifecycle template * * GET /environment/{environmentId}/lifecycleTemplate/{lifecycleTemplateId} * * Also accepts auth: bearerAuth */ export const getApiEnvironmentEnvironmentIdLifecycleTemplateLifecycleTemplateId = async (options?: GetApiEnvironmentEnvironmentIdLifecycleTemplateLifecycleTemplateIdOptions) => { 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(/\/+$/, '')}/environment/${encodeURIComponent(String(args.environmentId))}/lifecycleTemplate/${encodeURIComponent(String(args.lifecycleTemplateId))}${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(lifecycleTemplateResponse, await res.json()) };