import {z} from 'zod' export type CreateApiV2ZonesIdArgs = {'x-customer-api-key'?: string | undefined, body: {suspended: boolean}}; export type CreateApiV2ZonesIdOptions = {baseUrl: string, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2ZonesIdResponse = z.object({data: z.object({id: z.number().int().optional(), account_id: z.number().int().optional(), account_name: z.string().optional(), code: z.string().optional(), uuid: z.string().optional(), name: z.string().optional(), store_id: z.number().int().optional(), storage_info: z.object({available: z.string().optional(), required: z.string().optional(), is_critical: z.boolean().optional()}).optional(), volume: z.number().int().optional(), has_volume_change_pending: z.boolean().optional(), send_logs: z.boolean().optional(), reset_state: z.boolean().optional(), fudo_integration_id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).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 }; /** * Handle zone suspension status * * POST /v2/zones/{id} */ export const createApiV2ZonesId = async (args: CreateApiV2ZonesIdArgs, options: CreateApiV2ZonesIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, defaultValue} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-customer-api-key'] != null) headers.set("x-customer-api-key", String(args['x-customer-api-key'])) if (defaultValue !== undefined) headers.set("x-customer-api-key", defaultValue) const url = `${baseUrl.replace(/\/+$/, '')}/v2/zones/${encodeURIComponent(String(args.id))}${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(createApiV2ZonesIdResponse, await res.json()) };