import {z} from 'zod' export type CreateApiV2CrosshairsIdDownloadArgs = {id: string}; export type CreateApiV2CrosshairsIdDownloadOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2CrosshairsIdDownloadResponse = z.object({id: z.string(), userId: z.string(), userName: z.string().nullable(), userImage: z.string().nullable(), name: z.string(), description: z.string().nullable(), config: z.object({gap: z.number().gte(-20).lte(50).multipleOf(1), width: z.number().gte(0).lte(100).multipleOf(0.1), height: z.number().gte(0).lte(100).multipleOf(0.1), pipOpacity: z.number().gte(0).lte(1).multipleOf(0.1), dotOpacity: z.number().gte(0).lte(1).multipleOf(0.1), dotOutlineOpacity: z.number().gte(0).lte(1).multipleOf(0.1), color: z.object({r: z.number().gte(0).lte(255), g: z.number().gte(0).lte(255), b: z.number().gte(0).lte(255)}), pipBorder: z.boolean(), pipGapStatic: z.boolean(), hero: z.union([z.literal("Default"), z.enum(["Abrams", "Apollo", "Baba", "Bebop", "Billy", "Calico", "Celeste", "Deadman Danny", "Doorman", "Drifter", "Dynamo", "Graves", "Grey Talon", "Haze", "Holliday", "Infernus", "Ivy", "Kelvin", "Lady Geist", "Lash", "McGinnis", "Mina", "Mirage", "Mo & Krill", "Nurse Harrow", "Paige", "Paradox", "Pocket", "Rat King", "Rem", "Seven", "Shiv", "Silver", "Sinclair", "Solomon", "Venator", "Victor", "Vindicta", "Violet", "Viscous", "Vyper", "Warden", "Wraith", "Wrecker", "Yamato"])])}), tags: z.array(z.string()), heroes: z.array(z.string()), likes: z.number().int().gte(-9007199254740991).lte(9007199254740991), downloads: z.number().int().gte(-9007199254740991).lte(9007199254740991), hasLiked: z.boolean().optional(), createdAt: z.string(), updatedAt: z.string()}); 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 }; /** * POST /v2/crosshairs/{id}/download */ export const createApiV2CrosshairsIdDownload = async (args: CreateApiV2CrosshairsIdDownloadArgs, options?: CreateApiV2CrosshairsIdDownloadOptions) => { const {baseUrl = "https://api.deadlockmods.app/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/crosshairs/${encodeURIComponent(String(args.id))}/download${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV2CrosshairsIdDownloadResponse, await res.json()) };