import {z} from 'zod' export type PatchRiskConfigRequest = {category_overrides?: ({[key: string]: number | null}) | undefined, verdict_overrides?: ({warning?: (number | null) | undefined, high_risk?: (number | null) | undefined, malicious?: (number | null) | undefined}) | undefined}; export type PatchApiV0PlatformOrganizationConfigurationRiskExposureArgs = {body: PatchRiskConfigRequest}; export type PatchApiV0PlatformOrganizationConfigurationRiskExposureOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const organizationCategoryRiskView = z.object({category: z.string(), default_risk_score: z.number(), override_risk_score: z.number().nullable()}); export const verdictThresholdView = z.object({level: z.enum(["warning", "high_risk", "malicious"]), default_threshold: z.number(), override_threshold: z.number().nullable()}); export const organizationRiskConfigView = z.object({categories: z.array(organizationCategoryRiskView), verdicts: z.array(verdictThresholdView)}); 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 }; /** * Update organization risk configuration * * PATCH /v0/platform/organization/configuration/risk-exposure * * Also accepts auth: ClientID, JWT */ export const patchApiV0PlatformOrganizationConfigurationRiskExposure = async (args: PatchApiV0PlatformOrganizationConfigurationRiskExposureArgs, options?: PatchApiV0PlatformOrganizationConfigurationRiskExposureOptions) => { const {baseUrl = "https://api.blockaid.io", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKey !== undefined) headers.set("X-API-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/v0/platform/organization/configuration/risk-exposure${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(organizationRiskConfigView, await res.json()) };