import {z} from 'zod' export type GetApi1SwissBackupsSwissBackupIdSlotsSlotIdArgs = {swiss_backup_id: number, slot_id: number}; export type GetApi1SwissBackupsSwissBackupIdSlotsSlotIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const daf7713cTag = z.object({id: z.number().int(), name: z.string(), color: z.number().int(), product_count: z.number().int().optional()}); export const daf7713cSwissBackupSlot = z.object({id: z.number().int(), customer_name: z.string(), type: z.string(), subtype: z.string(), connection_type: z.string(), size: z.number().int(), storage_used: z.number().int(), usage_last_check: z.number().int(), created_at: z.number().int(), locked_at: z.number().int(), locked: z.boolean(), tags: z.array(daf7713cTag), lang: z.number().int(), activate_notifications: z.boolean(), unit_admin: z.boolean(), username: z.string(), endpoint: z.string(), IPS_key: z.string().optional(), email: z.string().optional(), slot_name: z.string().optional(), tenant_name: z.string().optional(), domain_name: z.string().optional(), container_name: z.string().optional(), directory: z.string().optional(), config: z.string().optional(), parent: z.object({}).optional()}); export const getApi1SwissBackupsSwissBackupIdSlotsSlotIdResponse = z.object({result: z.enum(["success", "error", "asynchronous"]), data: daf7713cSwissBackupSlot.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 }; /** * Slot information * * GET /1/swiss_backups/{swiss_backup_id}/slots/{slot_id} */ export const getApi1SwissBackupsSwissBackupIdSlotsSlotId = async (args: GetApi1SwissBackupsSwissBackupIdSlotsSlotIdArgs, options?: GetApi1SwissBackupsSwissBackupIdSlotsSlotIdOptions) => { const {baseUrl = "https://api.infomaniak.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/1/swiss_backups/${encodeURIComponent(String(args.swiss_backup_id))}/slots/${encodeURIComponent(String(args.slot_id))}${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(getApi1SwissBackupsSwissBackupIdSlotsSlotIdResponse, await res.json()) };