import {z} from 'zod' export type GetApiV0PlatformEcosystemIncidentsSubscriptionsIdArgs = {id: string}; export type GetApiV0PlatformEcosystemIncidentsSubscriptionsIdOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const severity = z.enum(["info", "low", "medium", "high", "critical"]); export const emailAction = z.object({type: z.literal("email"), severity: z.array(severity).optional(), to: z.array(z.string()), cc: z.array(z.string()).optional(), bcc: z.array(z.string()).optional(), body: z.string().optional()}); export const slackAction = z.object({type: z.literal("slack"), severity: z.array(severity).optional(), integration_instance_id: z.string(), channels: z.array(z.string()), message_format: z.string().optional()}); export const telegramAction = z.object({type: z.literal("telegram"), severity: z.array(severity).optional(), integration_instance_id: z.string(), chats: z.array(z.object({chat_id: z.string(), topic_ids: z.array(z.number().int()).optional()})), message_format: z.string().optional()}); export const hMACAuthentication = z.object({type: z.literal("hmac"), hmac_secret: z.string()}); export const authorizationHeaderAuthentication = z.object({type: z.literal("authorization_header"), value: z.string()}); export const aPIKeyAuthorization = z.object({type: z.literal("api_key"), header_name: z.string(), api_key: z.string()}); export const basicAuth = z.object({type: z.literal("basic_auth"), username: z.string(), password: z.string()}); export const authentication = z.union([hMACAuthentication, authorizationHeaderAuthentication, aPIKeyAuthorization, basicAuth]); export const webhookAction = z.object({type: z.literal("webhook"), severity: z.array(severity).optional(), url: z.string(), authentication: authentication.optional(), custom_headers: z.array(z.object({name: z.string(), value: z.string()})).optional(), custom_payload_fields: z.array(z.object({key: z.string(), value: z.string()})).optional()}); export const ecosystemIncidentSubscriptionMatch = z.object({monitor_type: z.array(z.enum(["monitored_contract_was_exploited", "frontend_attack", "compromised_private_key", "stablecoin_depeg"])).optional(), chains: z.array(z.string()).optional(), funds_lost_min: z.number().optional()}); export const ecosystemIncidentSubscriptionAction = z.object({action: z.union([emailAction, slackAction, telegramAction, webhookAction]), match: ecosystemIncidentSubscriptionMatch.optional()}); export const ecosystemIncidentSubscription = z.object({id: z.string(), name: z.string(), actions: z.array(ecosystemIncidentSubscriptionAction), created_by: z.string(), updated_by: z.string(), created_at: z.string(), updated_at: 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 Ecosystem Incident Subscription * * GET /v0/platform/ecosystem-incidents/subscriptions/{id} * * Also accepts auth: ClientID, JWT */ export const getApiV0PlatformEcosystemIncidentsSubscriptionsId = async (args: GetApiV0PlatformEcosystemIncidentsSubscriptionsIdArgs, options?: GetApiV0PlatformEcosystemIncidentsSubscriptionsIdOptions) => { const {baseUrl = "https://api.blockaid.io", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKey !== undefined) headers.set("X-API-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/v0/platform/ecosystem-incidents/subscriptions/${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(ecosystemIncidentSubscription, await res.json()) };