import {z} from 'zod' export type GetApiV1UsersUserIdAssetsCollectiblesArgs = {userId: number, assetType?: (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96) | undefined, limit?: (10 | 25 | 50 | 100) | undefined, cursor?: string | undefined, sortOrder?: ('Asc' | 'Desc') | undefined}; export type GetApiV1UsersUserIdAssetsCollectiblesOptions = {baseUrl?: string | undefined, robloxLegacyCookie?: string | undefined, fetch?: typeof fetch | undefined}; export const robloxInventoryApiModelsCollectibleUserAssetModel = z.object({userAssetId: z.number().int().optional(), serialNumber: z.number().int().optional(), assetId: z.number().int().optional(), name: z.string().optional(), recentAveragePrice: z.number().int().optional(), originalPrice: z.number().int().optional(), assetStock: z.number().int().optional(), buildersClubMembershipType: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).optional(), isOnHold: z.boolean().optional()}); export const robloxWebWebAPIModelsApiPageResponseRobloxInventoryApiModelsCollectibleUserAssetModel = z.object({previousPageCursor: z.string().optional(), nextPageCursor: z.string().optional(), data: z.array(robloxInventoryApiModelsCollectibleUserAssetModel).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 }; /** * Gets all collectible assets owned by the specified user. * * GET /v1/users/{userId}/assets/collectibles */ export const getApiV1UsersUserIdAssetsCollectibles = async (args: GetApiV1UsersUserIdAssetsCollectiblesArgs, options?: GetApiV1UsersUserIdAssetsCollectiblesOptions) => { const {baseUrl = "https://inventory.roblox.com", fetch: fetchFn = fetch, robloxLegacyCookie} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.assetType != null) query.append("assetType", String(args.assetType)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) if (robloxLegacyCookie !== undefined) cookies.push(".ROBLOSECURITY=" + encodeURIComponent(robloxLegacyCookie)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/users/${encodeURIComponent(String(args.userId))}/assets/collectibles${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(robloxWebWebAPIModelsApiPageResponseRobloxInventoryApiModelsCollectibleUserAssetModel, await res.json()) };