import {z} from 'zod' export type GetApiBackupAndDrPathArgs = {path: string, search?: string | undefined, page_size?: (25 | 50 | 100) | undefined, page?: number | undefined, status?: (Array<'Active' | 'Inactive' | 'Pending' | 'In Progress' | 'Success' | 'Failed'>) | undefined, integration_id?: Array | undefined, asset_type?: Array | undefined, region?: Array | undefined, policy_id?: Array | undefined, from_date?: string | undefined, to_date?: string | undefined, provider_type?: Array | undefined, sort_by?: 'status' | undefined, sort_order?: ('asc' | 'desc') | undefined}; export type GetApiBackupAndDrPathOptions = {baseUrl?: string | undefined, JWTAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiBackupAndDrPathResponse = z.object({}); 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 }; /** * Proxy GET requests to Backup and DR * * GET /backup-and-dr/{path} */ export const getApiBackupAndDrPath = async (args: GetApiBackupAndDrPathArgs, options?: GetApiBackupAndDrPathOptions) => { const {baseUrl = "https://api.firefly.ai/v2", fetch: fetchFn = fetch, JWTAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.search != null) query.append("search", String(args.search)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page != null) query.append("page", String(args.page)) for (const item of args.status ?? []) query.append("status", String(item)) for (const item of args.integration_id ?? []) query.append("integration_id", String(item)) for (const item of args.asset_type ?? []) query.append("asset_type", String(item)) for (const item of args.region ?? []) query.append("region", String(item)) for (const item of args.policy_id ?? []) query.append("policy_id", String(item)) if (args.from_date != null) query.append("from_date", String(args.from_date)) if (args.to_date != null) query.append("to_date", String(args.to_date)) for (const item of args.provider_type ?? []) query.append("provider_type", String(item)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (JWTAuth !== undefined) headers.set('authorization', `Bearer ${JWTAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/backup-and-dr/${encodeURIComponent(String(args.path))}${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(getApiBackupAndDrPathResponse, await res.json()) };