import {z} from 'zod' export type PrivateServersTab = 'MyPrivateServers' | 'OtherPrivateServers'; export type GetApiV1VipServersMyPrivateServersArgs = {privateServersTab?: PrivateServersTab | undefined, itemsPerPage?: number | undefined, cursor?: string | undefined}; export type GetApiV1VipServersMyPrivateServersOptions = {baseUrl?: string | undefined, robloxLegacyCookie?: string | undefined, fetch?: typeof fetch | undefined}; export const privateServerSubscriptionTag = z.enum(["Invalid", "RobloxSubscription", "RobloxSubscriptionActiveBenefit"]); export const privateServerSubscriptionMetadata = z.object({privateServerSubscriptionTags: z.array(privateServerSubscriptionTag).nullable().optional()}); export const myPrivateServersData = z.object({active: z.boolean().optional(), universeId: z.number().int().optional(), placeId: z.number().int().nullable().optional(), name: z.string().nullable().optional(), ownerId: z.number().int().optional(), ownerName: z.string().nullable().optional(), priceInRobux: z.number().int().nullable().optional(), privateServerId: z.number().int().optional(), expirationDate: z.string().optional(), willRenew: z.boolean().optional(), universeName: z.string().nullable().optional(), purchaseScheduleId: z.number().int().nullable().optional(), totalDiscountAmountInRobux: z.number().int().nullable().optional(), metadata: privateServerSubscriptionMetadata.nullable().optional()}); export const myPrivateServersResponse = z.object({nextPageCursor: z.string().nullable().optional(), previousPageCursor: z.string().nullable().optional(), data: z.array(myPrivateServersData).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 /v1/vip-servers/my-private-servers */ export const getApiV1VipServersMyPrivateServers = async (args: GetApiV1VipServersMyPrivateServersArgs, options?: GetApiV1VipServersMyPrivateServersOptions) => { const {baseUrl = "https://games.roblox.com", fetch: fetchFn = fetch, robloxLegacyCookie} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.privateServersTab != null) query.append("privateServersTab", String(args.privateServersTab)) if (args.itemsPerPage != null) query.append("itemsPerPage", String(args.itemsPerPage)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (robloxLegacyCookie !== undefined) cookies.push(".ROBLOSECURITY=" + encodeURIComponent(robloxLegacyCookie)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/vip-servers/my-private-servers${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(myPrivateServersResponse, await res.json()) };