import {z} from 'zod' export type GetApiEnvironmentEnvironmentIdLogsArgs = {environmentId: string, version?: string | undefined}; export type GetApiEnvironmentEnvironmentIdLogsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const environmentLogs = z.object({type: z.string(), timestamp: z.string(), details: z.object({organization_id: z.string().optional(), cluster_id: z.string().optional(), execution_id: z.string().optional(), transmitter: z.object({id: z.string().optional(), name: z.string().optional(), type: z.string().optional()}).optional(), stage: z.object({step: z.string().optional(), id: z.string().nullable().optional(), name: z.string().nullable().optional()}).optional()}), error: z.object({tag: z.string().optional(), user_log_message: z.string().optional(), link: z.string().optional(), hint_message: z.string().optional(), underlying_error: z.object({message: z.string().optional(), full_details: z.string().optional()}).optional()}).nullable().optional(), message: z.object({safe_message: z.string().optional(), full_details: z.string().optional()}).nullable().optional()}); export const environmentLogsResponseList = z.array(environmentLogs); 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 deployment logs v2 * * GET /environment/{environmentId}/logs * * Also accepts auth: bearerAuth */ export const getApiEnvironmentEnvironmentIdLogs = async (args: GetApiEnvironmentEnvironmentIdLogsArgs, options?: GetApiEnvironmentEnvironmentIdLogsOptions) => { 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 (args.version != null) query.append("version", String(args.version)) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/environment/${encodeURIComponent(String(args.environmentId))}/logs${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(environmentLogsResponseList, await res.json()) };