import {z} from 'zod' export type GetApiSecurityFspmFindingsIdArgs = {id: string}; export type GetApiSecurityFspmFindingsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const findingInfo = z.record(z.string(), z.unknown()); export const complianceRequirement = z.object({id: z.string(), standard: z.string(), criteria: z.string(), description: z.string().optional()}); export const securityFindingDetailed = z.object({id: z.string(), status: z.enum(["OPEN", "ACCEPTED", "RESOLVED"]), severity: z.enum(["INFO", "LOW", "MEDIUM", "HIGH"]), category: z.enum(["USER_MANAGEMENT", "APPROVAL_GROUP_MANAGEMENT", "POLICY_ENGINE_UTILIZATION", "WORKSPACE_CONFIGURATION", "DEFI_ACCESS", "FLEET_MANAGEMENT"]), createdAt: z.string(), title: z.string(), statusUpdatedAt: z.string().optional(), statusUpdatedByUserId: z.string().optional(), statusUpdatedReason: z.string().optional(), info: findingInfo, complianceReqs: z.array(complianceRequirement), riskExplanation: z.string(), mitigationGuidance: 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 }; /** * Get a FSPM security finding by ID * * GET /security/fspm/findings/{id} */ export const getApiSecurityFspmFindingsId = async (args: GetApiSecurityFspmFindingsIdArgs, options?: GetApiSecurityFspmFindingsIdOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/security/fspm/findings/${encodeURIComponent(String(args.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(securityFindingDetailed, await res.json()) };