import {z} from 'zod' export type CreateApiApiV2ThreatFeedSearchesArgs = {body: {GenericSearchText?: string | undefined, EventTypes?: (Array<'Data Breach' | 'Ransomware' | 'Vulnerability' | 'Advisory' | 'Hacktivist' | 'Social' | 'Incident' | 'Credential Exposure' | 'Data Leak' | 'Threat Actor Activity' | 'Research Report'> | null) | undefined, Severities?: (Array<'Informational' | 'Low' | 'Medium' | 'High' | 'Critical'> | null) | undefined, LifecycleStates?: (Array<'Active' | 'Merged' | 'Retracted' | 'Superseded'> | null) | undefined, CompanyDomains?: (Array | null) | undefined, CompanyNames?: (Array | null) | undefined, CompanyRoles?: (Array<'Affected' | 'Producer' | 'Publisher' | 'Mentioned'> | null) | undefined, CountryCodes?: (Array | null) | undefined, NaicsCodes?: (Array | null) | undefined, CompanyIds?: (Array | null) | undefined, ProductNames?: (Array | null) | undefined, Cpes?: (Array | null) | undefined, Cves?: (Array | null) | undefined, ProductIds?: (Array | null) | undefined, VulnerabilityIds?: (Array | null) | undefined, FocusTags?: (Array | null) | undefined, ThreatActors?: (Array | null) | undefined, EventStartDate?: string | undefined, EventEndDate?: string | undefined, UpdatedSince?: string | undefined, SortBy?: ('EventDate' | 'UpdateDate' | 'FeedMentionCount' | 'Severity') | undefined, SortOrder?: ('Ascending' | 'Descending') | undefined}}; export type CreateApiApiV2ThreatFeedSearchesOptions = {baseUrl?: string | undefined, OAuthv2?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV2ThreatFeedSearchesResponse = z.object({Key: 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 }; /** * Search through the Cyber Threat Feed events. * * POST /api/v2/threat-feed-searches */ export const createApiApiV2ThreatFeedSearches = async (args: CreateApiApiV2ThreatFeedSearchesArgs, options?: CreateApiApiV2ThreatFeedSearchesOptions) => { const {baseUrl = "https://app.blackkitetech.com", fetch: fetchFn = fetch, OAuthv2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuthv2 !== undefined) headers.set('authorization', `Bearer ${OAuthv2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/threat-feed-searches${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiApiV2ThreatFeedSearchesResponse, await res.json()) };