import {z} from 'zod' export type GetApiPlaceVersionHistoryApiV1PlaceIdHistoryArgs = {placeId: number, cursor?: string | undefined, isPublished?: boolean | undefined, hasNotes?: boolean | undefined, saveType?: number | undefined, searchTerm?: string | undefined, contributor?: number | undefined, startTime?: string | undefined, endTime?: string | undefined, pageSize?: number | undefined}; export type GetApiPlaceVersionHistoryApiV1PlaceIdHistoryOptions = {baseUrl?: string | undefined, robloxLegacyCookie?: string | undefined, fetch?: typeof fetch | undefined}; export const saveType = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const publishStatus = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const placeVersion = z.object({version: z.string().nullable().optional(), title: z.string().nullable().optional(), description: z.string().nullable().optional(), contributors: z.array(z.number().int()).nullable().optional(), saveType: saveType.optional(), isPublished: z.boolean().optional(), publishStatus: publishStatus.optional(), hasNotes: z.boolean().optional(), createdTime: z.string().optional(), createdBy: z.number().int().nullable().optional()}); export const getPlaceVersionHistoryResponse = z.object({nextCursor: z.string().nullable().optional(), hasMore: z.boolean().optional(), placeVersions: z.array(placeVersion).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 }; /** * Endpoint used to get place versions, using various filters * * GET /place-version-history-api/v1/{placeId}/history * * Also accepts auth: roblox-api-key */ export const getApiPlaceVersionHistoryApiV1PlaceIdHistory = async (args: GetApiPlaceVersionHistoryApiV1PlaceIdHistoryArgs, options?: GetApiPlaceVersionHistoryApiV1PlaceIdHistoryOptions) => { const {baseUrl = "https://apis.roblox.com", fetch: fetchFn = fetch, robloxLegacyCookie} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.isPublished != null) query.append("isPublished", String(args.isPublished)) if (args.hasNotes != null) query.append("hasNotes", String(args.hasNotes)) if (args.saveType != null) query.append("saveType", String(args.saveType)) if (args.searchTerm != null) query.append("searchTerm", String(args.searchTerm)) if (args.contributor != null) query.append("contributor", String(args.contributor)) if (args.startTime != null) query.append("startTime", String(args.startTime)) if (args.endTime != null) query.append("endTime", String(args.endTime)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (robloxLegacyCookie !== undefined) cookies.push(".ROBLOSECURITY=" + encodeURIComponent(robloxLegacyCookie)) const url = `${baseUrl.replace(/\/+$/, '')}/place-version-history-api/v1/${encodeURIComponent(String(args.placeId))}/history${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(getPlaceVersionHistoryResponse, await res.json()) };