import {z} from 'zod' export type ScheduledReport = {pk?: number | undefined, url?: string | undefined, sla_report?: (string | null) | undefined, recipient_users?: Array | undefined, created_at?: string | undefined, name: string, file_type?: ('PDF' | 'XLS') | undefined, recurrence?: ('DAILY' | 'WEEKLY' | 'MONTHLY' | 'QUARTERLY' | 'YEARLY') | undefined, default_date_range_override?: ('TODAY' | 'YESTERDAY' | 'LAST_7D' | 'LAST_30D' | 'THIS_WEEK' | 'LAST_WEEK' | 'THIS_MONTH' | 'LAST_MONTH' | 'THIS_QUARTER' | 'LAST_QUARTER' | 'THIS_YEAR' | 'LAST_YEAR') | undefined, on_weekday?: (1 | 2 | 3 | 4 | 5 | 6 | 7) | undefined, at_time?: (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23) | undefined, is_enabled?: boolean | undefined, recipient_emails?: Record | undefined}; export type PatchApiApiV1ScheduledReportsPkArgs = {pk: string, body: ScheduledReport}; export type PatchApiApiV1ScheduledReportsPkOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const scheduledReport = z.object({pk: z.number().int().optional(), url: z.string().optional(), sla_report: z.string().nullable().optional(), recipient_users: z.array(z.string()).optional(), created_at: z.string().optional(), name: z.string().max(100), file_type: z.enum(["PDF", "XLS"]).optional(), recurrence: z.enum(["DAILY", "WEEKLY", "MONTHLY", "QUARTERLY", "YEARLY"]).optional(), default_date_range_override: z.enum(["TODAY", "YESTERDAY", "LAST_7D", "LAST_30D", "THIS_WEEK", "LAST_WEEK", "THIS_MONTH", "LAST_MONTH", "THIS_QUARTER", "LAST_QUARTER", "THIS_YEAR", "LAST_YEAR"]).optional(), on_weekday: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7)]).optional(), at_time: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11), z.literal(12), z.literal(13), z.literal(14), z.literal(15), z.literal(16), z.literal(17), z.literal(18), z.literal(19), z.literal(20), z.literal(21), z.literal(22), z.literal(23)]).optional(), is_enabled: z.boolean().optional(), recipient_emails: 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 }; /** * Partially update a scheduled report * * PATCH /api/v1/scheduled-reports/{pk}/ */ export const patchApiApiV1ScheduledReportsPk = async (args: PatchApiApiV1ScheduledReportsPkArgs, options: PatchApiApiV1ScheduledReportsPkOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/scheduled-reports/${encodeURIComponent(String(args.pk))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(scheduledReport, await res.json()) };