import {z} from 'zod' export type GetApiDriftDetectionSchedulesDriftDetectionScheduleArgs = {drift_detection_schedule: string}; export type GetApiDriftDetectionSchedulesDriftDetectionScheduleOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const driftDetectionSchedule = z.object({attributes: z.object({"run-mode": z.enum(["refresh-only", "plan"]).optional(), schedule: z.enum(["daily", "weekly"]), "time-window": z.enum(["00:00-04:00", "04:00-08:00", "08:00-12:00", "12:00-16:00", "16:00-20:00", "20:00-24:00"]).nullable().optional(), "workspace-filters": z.object({"environment-types": z.array(z.enum(["production", "staging", "testing", "development", "unmapped"])).optional(), "name-patterns": z.array(z.string()).optional(), tags: z.array(z.string()).optional()}).optional()}), id: z.string().optional(), links: z.record(z.string(), z.string()).optional(), relationships: z.object({environment: z.object({data: z.object({id: z.string(), type: z.enum(["environments", ""])})})}), type: z.literal("drift-detection-schedule")}); export const driftDetectionScheduleDocument = z.object({data: driftDetectionSchedule.optional(), included: z.array(z.object({})).optional(), meta: z.object({}).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 }; /** * Get a drift detection schedule * * GET /drift-detection-schedules/{drift_detection_schedule} */ export const getApiDriftDetectionSchedulesDriftDetectionSchedule = async (args: GetApiDriftDetectionSchedulesDriftDetectionScheduleArgs, options?: GetApiDriftDetectionSchedulesDriftDetectionScheduleOptions) => { const {baseUrl = "https://example.scalr.io/api/iacp/v3", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.api+json") if (APIKey !== undefined) headers.set('authorization', `Bearer ${APIKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/drift-detection-schedules/${encodeURIComponent(String(args.drift_detection_schedule))}${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(driftDetectionScheduleDocument, await res.json()) };