import {z} from 'zod' export type GetApiV2AssetsAssetIdOwnersArgs = {assetId: number, limit?: (10 | 25 | 50 | 100) | undefined, cursor?: string | undefined, sortOrder?: ('Asc' | 'Desc') | undefined}; export type GetApiV2AssetsAssetIdOwnersOptions = {baseUrl?: string | undefined, robloxLegacyCookie?: string | undefined, fetch?: typeof fetch | undefined}; export const robloxWebResponsesRelatedEntityTypeResponseRobloxUsersClientAssociatedEntityType = z.object({id: z.number().int().optional(), type: z.union([z.literal(1), z.literal(2)]).optional(), name: z.string().optional()}); export const robloxInventoryApiV2AssetOwnerResponse = z.object({id: z.number().int().optional(), collectibleItemInstanceId: z.string().optional(), serialNumber: z.number().int().optional(), owner: robloxWebResponsesRelatedEntityTypeResponseRobloxUsersClientAssociatedEntityType.optional(), created: z.string().optional(), updated: z.string().optional()}); export const robloxWebWebAPIModelsApiPageResponseRobloxInventoryApiV2AssetOwnerResponse = z.object({previousPageCursor: z.string().optional(), nextPageCursor: z.string().optional(), data: z.array(robloxInventoryApiV2AssetOwnerResponse).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 a list of owners of an asset. * * GET /v2/assets/{assetId}/owners */ export const getApiV2AssetsAssetIdOwners = async (args: GetApiV2AssetsAssetIdOwnersArgs, options?: GetApiV2AssetsAssetIdOwnersOptions) => { 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.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(/\/+$/, '')}/v2/assets/${encodeURIComponent(String(args.assetId))}/owners${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(robloxWebWebAPIModelsApiPageResponseRobloxInventoryApiV2AssetOwnerResponse, await res.json()) };