import {z} from 'zod' export type AllQuietApiPublicServiceMaintenanceServiceMaintenanceResourceCreateRequest = {displayName?: (string | null) | undefined, serviceIds?: (Array | null) | undefined, timeZoneId?: (string | null) | undefined, publicDescription?: (string | null) | undefined, start?: (string | null) | undefined, end?: (string | null) | undefined}; export type CreateApiApiPublicV1ServiceMaintenanceArgs = {organizationId?: string | undefined, provision?: boolean | undefined, body: AllQuietApiPublicServiceMaintenanceServiceMaintenanceResourceCreateRequest}; export type CreateApiApiPublicV1ServiceMaintenanceOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const allQuietApiPublicServiceMaintenanceServiceMaintenanceResourceResponse = z.object({id: z.string().optional(), displayName: z.string().nullable().optional(), organizationId: z.string().optional(), serviceIds: z.array(z.string()).nullable().optional(), timeZoneId: z.string().nullable().optional(), start: z.string().nullable().optional(), end: z.string().nullable().optional(), publicDescription: z.string().nullable().optional(), isProvisioned: 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 }; /** * Create a service maintenance window * * POST /api/public/v1/service-maintenance */ export const createApiApiPublicV1ServiceMaintenance = async (args: CreateApiApiPublicV1ServiceMaintenanceArgs, options: CreateApiApiPublicV1ServiceMaintenanceOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.organizationId != null) query.append("organizationId", String(args.organizationId)) if (args.provision != null) query.append("provision", String(args.provision)) if (ApiKey !== undefined) headers.set("Authorization", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v1/service-maintenance${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(allQuietApiPublicServiceMaintenanceServiceMaintenanceResourceResponse, await res.json()) };