import {z} from 'zod' export type GetApiV1GameLocalizationStatusGameIdTranslationCountsArgs = {gameId: number}; export type GetApiV1GameLocalizationStatusGameIdTranslationCountsOptions = {baseUrl?: string | undefined, robloxLegacyCookie?: string | undefined, fetch?: typeof fetch | undefined}; export const robloxGameInternationalizationApiTranslationCount = z.object({count: z.number().int().optional(), translationStatus: z.literal("Approved").optional(), translatorType: z.enum(["Automation", "User"]).optional()}); export const robloxGameInternationalizationApiTranslationCountCategoryInfoResponse = z.object({category: z.literal("InGameContent").optional(), translationCounts: z.array(robloxGameInternationalizationApiTranslationCount).optional(), totalTranslatableItemCount: z.number().int().optional()}); export const robloxGameInternationalizationApiTranslationCountLanguageOrLocaleResponse = z.object({status: z.enum(["Success", "LanguageOrLocaleNotSupportedForGame"]).optional(), categories: z.array(robloxGameInternationalizationApiTranslationCountCategoryInfoResponse).optional(), name: z.string().optional(), languageCodeType: z.enum(["Language", "Locale"]).optional(), languageCode: z.string().optional()}); export const robloxGameInternationalizationApiGetTranslationCountsForGameResponse = z.object({gameId: z.number().int().optional(), languagesOrLocales: z.array(robloxGameInternationalizationApiTranslationCountLanguageOrLocaleResponse).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 the language translation counts for all languages of a game * * GET /v1/game-localization-status/{gameId}/translation-counts */ export const getApiV1GameLocalizationStatusGameIdTranslationCounts = async (args: GetApiV1GameLocalizationStatusGameIdTranslationCountsArgs, options?: GetApiV1GameLocalizationStatusGameIdTranslationCountsOptions) => { const {baseUrl = "https://gameinternationalization.roblox.com", fetch: fetchFn = fetch, robloxLegacyCookie} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (robloxLegacyCookie !== undefined) cookies.push(".ROBLOSECURITY=" + encodeURIComponent(robloxLegacyCookie)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/game-localization-status/${encodeURIComponent(String(args.gameId))}/translation-counts${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(robloxGameInternationalizationApiGetTranslationCountsForGameResponse, await res.json()) };