import {z} from 'zod' export type UpdateApiV2ProfileBackupsArgs = {body: {name: string, deviceName: string, contentHash: string, payload: {version: '1', profile: {version: '3', payload: {mods: Array<{remoteId: string, selectedDownload?: {remoteId: string, file: string, url: string, size: number} | undefined, selectedDownloads?: Array<{remoteId: string, file: string, url: string, size: number}> | undefined, fileTree?: {files: Array<{name: string, path: string, size: number, is_selected: boolean, archive_name: string}>, total_files: number, has_multiple_files: boolean} | undefined, submissionType: 'mod' | 'sound'}>, loadOrder: Array}}, disabledModCount?: number | undefined, disabledModIds?: Array | undefined, modGroups: Array<{id: string, name: string, modIds: Array, collapsed: boolean, randomize?: boolean | undefined}>, description?: string | undefined, modNames?: {[key: string]: string} | undefined, skippedLocalModCount: number}, id: string, expectedRevision: number} | {name: string, deviceName: string, contentHash: string, payload: {version: '1', profile: {version: '3', payload: {mods: Array<{remoteId: string, selectedDownload?: {remoteId: string, file: string, url: string, size: number} | undefined, selectedDownloads?: Array<{remoteId: string, file: string, url: string, size: number}> | undefined, fileTree?: {files: Array<{name: string, path: string, size: number, is_selected: boolean, archive_name: string}>, total_files: number, has_multiple_files: boolean} | undefined, submissionType: 'mod' | 'sound'}>, loadOrder: Array}}, disabledModCount?: number | undefined, disabledModIds?: Array | undefined, modGroups: Array<{id: string, name: string, modIds: Array, collapsed: boolean, randomize?: boolean | undefined}>, description?: string | undefined, modNames?: {[key: string]: string} | undefined, skippedLocalModCount: number}}}; export type UpdateApiV2ProfileBackupsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV2ProfileBackupsResponse = z.object({id: z.string(), name: z.string(), deviceName: z.string(), modCount: z.number().int().gte(-9007199254740991).lte(9007199254740991), skippedLocalModCount: z.number().int().gte(-9007199254740991).lte(9007199254740991), contentHash: z.string(), revision: z.number().int().gte(-9007199254740991).lte(9007199254740991), 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 }; /** * PUT /v2/profile-backups */ export const updateApiV2ProfileBackups = async (args: UpdateApiV2ProfileBackupsArgs, options?: UpdateApiV2ProfileBackupsOptions) => { const {baseUrl = "https://api.deadlockmods.app/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/profile-backups${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiV2ProfileBackupsResponse, await res.json()) };