import {z} from 'zod' export type GetApiCabinetAdminServersServerIdArgs = {server_id: number}; export type GetApiCabinetAdminServersServerIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const appCabinetSchemasServersPromoGroupInfo = z.object({id: z.number().int(), name: z.string(), is_selected: z.boolean().optional()}); export const serverDetailResponse = z.object({id: z.number().int(), squad_uuid: z.string(), display_name: z.string(), original_name: z.string().nullable().optional(), country_code: z.string().nullable().optional(), description: z.string().nullable().optional(), is_available: z.boolean(), is_trial_eligible: z.boolean(), price_kopeks: z.number().int(), price_rubles: z.number(), max_users: z.number().int().nullable().optional(), current_users: z.number().int(), sort_order: z.number().int(), is_full: z.boolean(), availability_status: z.string(), promo_groups: z.array(appCabinetSchemasServersPromoGroupInfo), active_subscriptions: z.number().int(), tariffs_using: z.array(z.string()), created_at: z.string(), updated_at: z.string().nullable().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 }; /** * Get Server * * GET /cabinet/admin/servers/{server_id} */ export const getApiCabinetAdminServersServerId = async (args: GetApiCabinetAdminServersServerIdArgs, options: GetApiCabinetAdminServersServerIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/cabinet/admin/servers/${encodeURIComponent(String(args.server_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(serverDetailResponse, await res.json()) };