import {z} from 'zod' export type UserRestrictionGameJoinRestriction = {active?: boolean | undefined, startTime?: string | undefined, duration?: unknown | undefined, privateReason?: string | undefined, displayReason?: string | undefined, excludeAltAccounts?: boolean | undefined, inherited?: boolean | undefined}; export type UserRestriction = {path?: string | undefined, updateTime?: string | undefined, user?: string | undefined, gameJoinRestriction?: UserRestrictionGameJoinRestriction | undefined}; export type PatchApiCloudV2UniversesUniverseIdUserRestrictionsUserRestrictionIdArgs = {universe_id: string, user_restriction_id: string, updateMask?: unknown | undefined, 'idempotencyKey.key'?: string | undefined, 'idempotencyKey.firstSent'?: string | undefined, body: UserRestriction}; export type PatchApiCloudV2UniversesUniverseIdUserRestrictionsUserRestrictionIdOptions = {baseUrl?: string | undefined, robloxApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const userRestrictionGameJoinRestriction = z.object({active: z.boolean().optional(), startTime: z.string().optional(), duration: z.string().optional(), privateReason: z.string().optional(), displayReason: z.string().optional(), excludeAltAccounts: z.boolean().optional(), inherited: z.boolean().optional()}); export const userRestriction = z.object({path: z.string().optional(), updateTime: z.string().optional(), user: z.string().optional(), gameJoinRestriction: userRestrictionGameJoinRestriction.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 }; /** * Update User Restriction * * PATCH /cloud/v2/universes/{universe_id}/user-restrictions/{user_restriction_id} * * Also accepts auth: roblox-oauth2 */ export const patchApiCloudV2UniversesUniverseIdUserRestrictionsUserRestrictionId = async (args: PatchApiCloudV2UniversesUniverseIdUserRestrictionsUserRestrictionIdArgs, options?: PatchApiCloudV2UniversesUniverseIdUserRestrictionsUserRestrictionIdOptions) => { const {baseUrl = "https://apis.roblox.com", fetch: fetchFn = fetch, robloxApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.updateMask != null) query.append("updateMask", String(args.updateMask)) if (args['idempotencyKey.key'] != null) query.append("idempotencyKey.key", String(args['idempotencyKey.key'])) if (args['idempotencyKey.firstSent'] != null) query.append("idempotencyKey.firstSent", String(args['idempotencyKey.firstSent'])) if (robloxApiKey !== undefined) headers.set("x-api-key", robloxApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/cloud/v2/universes/${encodeURIComponent(String(args.universe_id))}/user-restrictions/${encodeURIComponent(String(args.user_restriction_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(userRestriction, await res.json()) };