import {z} from 'zod' export type GetApiApiV1OrgsOrgIdClustersIdSchedulesArgs = {orgId: number, id: number}; export type GetApiApiV1OrgsOrgIdClustersIdSchedulesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const labels = z.object({"backup-type": z.string().optional()}); export const backupOptions = z.object({includedNamespaces: z.array(z.string()).optional(), includedResources: z.array(z.string()).optional(), excludedNamespaces: z.array(z.string()).optional(), excludedResources: z.array(z.string()).optional(), snapshotVolumes: z.boolean().optional(), includeClusterResources: z.boolean().optional()}); export const scheduleResponse = z.object({uid: z.string().optional(), name: z.string().optional(), schedule: z.string().optional(), ttl: z.string().optional(), labels: labels.optional(), options: backupOptions.optional(), status: z.string().optional(), lastBackup: z.string().optional()}); export const listSchedulesResponse = z.array(scheduleResponse); 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 ARK schedules * * GET /api/v1/orgs/{orgId}/clusters/{id}/schedules */ export const getApiApiV1OrgsOrgIdClustersIdSchedules = async (args: GetApiApiV1OrgsOrgIdClustersIdSchedulesArgs, options?: GetApiApiV1OrgsOrgIdClustersIdSchedulesOptions) => { const {baseUrl = "http://localhost:9090", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/orgs/${encodeURIComponent(String(args.orgId))}/clusters/${encodeURIComponent(String(args.id))}/schedules${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(listSchedulesResponse, await res.json()) };