import {z} from 'zod' export type NotificationTargetDTO = {featureId?: string | undefined, recipient?: string | undefined}; export type CalendarAlertDTO = {accountId?: string | undefined, createdAt?: string | undefined, createdByEmail?: string | undefined, eventId?: string | undefined, eventTimeUtc?: string | undefined, eventTitle?: string | undefined, featureId?: string | undefined, fireAtUtc?: string | undefined, id?: string | undefined, kind?: ('BELL' | 'RULE' | 'FILTER_WARNING' | 'AGENDA') | undefined, leadMinutes?: number | undefined, notificationTargets?: Array | undefined, projectId?: string | undefined, ruleId?: string | undefined, sent?: boolean | undefined}; export type UpdateApiRestApiV1ProjectsProjectIdCalendarAlertsAlertIdArgs = {projectId: string, alertId: string, body: CalendarAlertDTO}; export type UpdateApiRestApiV1ProjectsProjectIdCalendarAlertsAlertIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const notificationTargetDTO = z.object({featureId: z.string().optional(), recipient: z.string().optional()}); export const calendarAlertDTO = z.object({accountId: z.string().optional(), createdAt: z.string().optional(), createdByEmail: z.string().optional(), eventId: z.string().optional(), eventTimeUtc: z.string().optional(), eventTitle: z.string().optional(), featureId: z.string().optional(), fireAtUtc: z.string().optional(), id: z.string().optional(), kind: z.enum(["BELL", "RULE", "FILTER_WARNING", "AGENDA"]).optional(), leadMinutes: z.number().int().optional(), notificationTargets: z.array(notificationTargetDTO).optional(), projectId: z.string().optional(), ruleId: z.string().optional(), sent: z.boolean().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 }; /** * Change the lead time or the channels of a pending reminder * * PUT /rest/api/v1/projects/{projectId}/calendarAlerts/{alertId} */ export const updateApiRestApiV1ProjectsProjectIdCalendarAlertsAlertId = async (args: UpdateApiRestApiV1ProjectsProjectIdCalendarAlertsAlertIdArgs, options?: UpdateApiRestApiV1ProjectsProjectIdCalendarAlertsAlertIdOptions) => { const {baseUrl = "https://api.metacopier.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/rest/api/v1/projects/${encodeURIComponent(String(args.projectId))}/calendarAlerts/${encodeURIComponent(String(args.alertId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(calendarAlertDTO, await res.json()) };