import {z} from 'zod' export type UpdatePageRequest = {accent_color?: (string | null) | undefined, brand_name?: (string | null) | undefined, confirm_after_secs?: (number | null) | undefined, confirm_failures?: (number | null) | undefined, confirm_recovery?: (number | null) | undefined, description?: (string | null) | undefined, favicon_img?: (string | null) | undefined, logo_img?: (string | null) | undefined, name?: (string | null) | undefined, noindex?: (boolean | null) | undefined, password?: (string | null) | undefined, show_response_time?: (boolean | null) | undefined, show_timeline_bars?: (boolean | null) | undefined, show_uptime_percent?: (boolean | null) | undefined, visibility?: (number | null) | undefined}; export type UpdateApiApiOrgIdStatusPagesIdArgs = {org_id: string, id: string, body: UpdatePageRequest}; export type UpdateApiApiOrgIdStatusPagesIdOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const componentView = z.object({check_ids: z.array(z.string()), description: z.string().nullable().optional(), id: z.string(), name: z.string()}); export const componentStatus = z.enum(["operational", "no_data", "maintenance", "degraded", "partial_outage", "major_outage"]); export const pageAdminView = z.object({accent_color: z.string().nullable().optional(), brand_name: z.string().nullable().optional(), component_count: z.number().int(), components: z.array(componentView).nullable().optional(), confirm_after_secs: z.number().int().nullable().optional(), confirm_failures: z.number().int(), confirm_recovery: z.number().int(), created_at: z.number().int(), description: z.string().nullable().optional(), favicon_img: z.string().nullable().optional(), health: componentStatus.nullable().optional(), id: z.string(), logo_img: z.string().nullable().optional(), name: z.string(), noindex: z.boolean(), owner: z.string().nullable().optional(), password_set: z.boolean(), show_response_time: z.boolean(), show_timeline_bars: z.boolean(), show_uptime_percent: z.boolean(), slug: z.string(), tracking_since: z.number().int().nullable().optional(), updated_at: z.number().int(), visibility: z.number().int()}); 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 }; /** * Update a status page * * PUT /api/{org_id}/status_pages/{id} */ export const updateApiApiOrgIdStatusPagesId = async (args: UpdateApiApiOrgIdStatusPagesIdArgs, options: UpdateApiApiOrgIdStatusPagesIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/status_pages/${encodeURIComponent(String(args.id))}${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(pageAdminView, await res.json()) };