import {z} from 'zod' export type StatusPageExternalUser = {pk?: number | undefined, email: string, first_name: string, last_name: string, is_active: boolean}; export type UpdateApiApiV1StatuspagesStatuspageIdUsersPkArgs = {statuspage_id: string, pk: string, body: StatusPageExternalUser}; export type UpdateApiApiV1StatuspagesStatuspageIdUsersPkOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const statusPageExternalUser = z.object({pk: z.number().int().optional(), email: z.string().max(150), first_name: z.string().max(150), last_name: z.string().max(150), is_active: z.boolean()}); 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 external user * * PUT /api/v1/statuspages/{statuspage_id}/users/{pk}/ */ export const updateApiApiV1StatuspagesStatuspageIdUsersPk = async (args: UpdateApiApiV1StatuspagesStatuspageIdUsersPkArgs, options: UpdateApiApiV1StatuspagesStatuspageIdUsersPkOptions) => { 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/statuspages/${encodeURIComponent(String(args.statuspage_id))}/users/${encodeURIComponent(String(args.pk))}/${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(statusPageExternalUser, await res.json()) };