import {z} from 'zod' export type CreatePrivateServerRequest = {name?: (string | null) | undefined, expectedPrice?: number | undefined, isPurchaseConfirmed?: (boolean | null) | undefined, idempotencyKey?: (string | null) | undefined}; export type CreateApiV1GamesVipServersUniverseIdArgs = {universeId: number, body: CreatePrivateServerRequest}; export type CreateApiV1GamesVipServersUniverseIdOptions = {baseUrl?: string | undefined, robloxLegacyCookie?: string | undefined, fetch?: typeof fetch | undefined}; export const privateServerPlayerResponse = z.object({id: z.number().int().optional(), name: z.string().nullable().optional(), displayName: z.string().nullable().optional(), playerToken: z.string().nullable().optional()}); export const verifiedBadgeUserResponse = z.object({id: z.number().int().optional(), name: z.string().nullable().optional(), displayName: z.string().nullable().optional(), hasVerifiedBadge: z.boolean().optional()}); export const gameServerResponse = z.object({id: z.string().nullable().optional(), maxPlayers: z.number().int().optional(), playing: z.number().int().optional(), playerTokens: z.array(z.string()).nullable().optional(), players: z.array(privateServerPlayerResponse).nullable().optional(), fps: z.number().optional(), ping: z.number().int().optional(), name: z.string().nullable().optional(), vipServerId: z.number().int().nullable().optional(), accessCode: z.string().nullable().optional(), owner: verifiedBadgeUserResponse.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 }; /** * POST /v1/games/vip-servers/{universeId} */ export const createApiV1GamesVipServersUniverseId = async (args: CreateApiV1GamesVipServersUniverseIdArgs, options?: CreateApiV1GamesVipServersUniverseIdOptions) => { const {baseUrl = "https://games.roblox.com", fetch: fetchFn = fetch, robloxLegacyCookie} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (robloxLegacyCookie !== undefined) cookies.push(".ROBLOSECURITY=" + encodeURIComponent(robloxLegacyCookie)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/games/vip-servers/${encodeURIComponent(String(args.universeId))}${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(gameServerResponse, await res.json()) };