import {z} from 'zod' export type GetApiBackupAndDrSnapshotsSnapshotIdArgs = {snapshot_id: string}; export type GetApiBackupAndDrSnapshotsSnapshotIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const scopeConfig = z.object({type: z.enum(["tags", "resource_group", "asset_types", "exclude_asset_types", "selected_resources"]), value: z.array(z.string())}); export const applicationScope = z.array(scopeConfig); export const snapshotStatus = z.enum(["Pending", "In Progress", "Success", "Failed"]); export const changedATR = z.object({integration_id: z.string(), asset_type: z.string(), regions: z.array(z.string())}); export const snapshot = z.object({account_id: z.string(), snapshot_id: z.string(), snapshot_time: z.string().optional(), policy_id: z.string(), provider_type: z.string().max(50).optional(), integration_id: z.string().optional(), region: z.string().optional(), trigger: z.object({type: z.enum(["scheduled", "on-demand"]).optional(), initiated_by: z.string().optional()}).optional(), scope: applicationScope.optional(), status: snapshotStatus.optional(), is_latest: z.boolean().optional(), created_at: z.string().optional(), asset_types: z.array(z.string()).optional(), changed_atrs: z.array(changedATR).optional(), error_code: z.enum(["SCOPE_EMPTY", "INTERNAL_ERROR"]).nullable().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 }; /** * Get snapshot details * * GET /backup-and-dr/snapshots/{snapshot_id} */ export const getApiBackupAndDrSnapshotsSnapshotId = async (args: GetApiBackupAndDrSnapshotsSnapshotIdArgs, options?: GetApiBackupAndDrSnapshotsSnapshotIdOptions) => { const {baseUrl = "https://api.firefly.ai/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/backup-and-dr/snapshots/${encodeURIComponent(String(args.snapshot_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(snapshot, await res.json()) };