import {z} from 'zod' export type GetApiBackupAndDrSnapshotsSnapshotIdResourcesArgs = {snapshot_id: string, page?: number | undefined, page_size?: number | undefined, search?: string | undefined, asset_type?: Array | undefined, region?: Array | undefined}; export type GetApiBackupAndDrSnapshotsSnapshotIdResourcesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const snapshotResource = z.object({snapshot_id: z.string(), account_id: z.string(), integration_id: z.string(), frn: z.string(), resource_id: z.string(), asset_id: z.string().optional(), arn: z.string().optional(), provider: z.string(), service: z.string().optional(), asset_type: z.string(), region: z.string(), name: z.string().optional(), tf_object: z.string(), console_url: z.string().optional(), account_name: z.string().optional(), provider_id: z.string().optional(), delete_command: z.string().optional(), inventory_update_time: z.string().optional(), resource_creation_date: z.string().optional(), first_seen: z.string().optional(), resource_status: z.string().optional(), tagging_status: z.string().optional(), provider_type: z.string().optional(), provider_sub_type: z.string().optional(), stack_id: z.string().optional(), stack_name: z.string().optional(), vcs_repo: z.string().optional(), vcs_provider: z.string().optional(), vcs_code_link: z.string().optional(), state: z.string().optional(), iac_type: z.string().optional(), prev_state: z.string().optional(), last_resource_state_change: z.string().optional(), is_excluded: z.boolean().optional(), is_locked: z.boolean().optional(), is_out_of_sync: z.boolean().optional(), is_event_driven: z.boolean().optional(), ignored_drift: z.boolean().optional(), drift: z.array(z.unknown()).optional(), tags: z.string().optional(), tags_list: z.array(z.string()).optional(), classifications: z.array(z.string()).optional(), monthly_cloud_cost_usd: z.number().optional(), monthly_state_cost_usd: z.number().optional(), discovery_type: z.enum(["scope", "dependency"]).optional(), parent_frn: z.string().nullable().optional()}); export const pagination = z.object({page: z.number().int(), page_size: z.number().int(), total: z.number().int(), has_next: z.boolean(), has_prev: z.boolean()}); export const facetValue = z.object({value: z.string().optional(), count: z.number().int().optional()}); export const facet = z.object({field: z.string(), size: z.number().int(), pagination: pagination, values: z.array(facetValue)}); export const resourceListResponse = z.object({data: z.array(snapshotResource).optional(), pagination: pagination.optional(), summary: z.object({total_resources: z.number().int().optional(), by_type: z.object({}).optional(), by_region: z.object({}).optional()}).optional(), facets: z.array(facet).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 resources * * GET /backup-and-dr/snapshots/{snapshot_id}/resources */ export const getApiBackupAndDrSnapshotsSnapshotIdResources = async (args: GetApiBackupAndDrSnapshotsSnapshotIdResourcesArgs, options?: GetApiBackupAndDrSnapshotsSnapshotIdResourcesOptions) => { const {baseUrl = "https://api.firefly.ai/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.search != null) query.append("search", String(args.search)) for (const item of args.asset_type ?? []) query.append("asset_type", String(item)) for (const item of args.region ?? []) query.append("region", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/backup-and-dr/snapshots/${encodeURIComponent(String(args.snapshot_id))}/resources${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(resourceListResponse, await res.json()) };