import {z} from 'zod' export type GetApiThreatmonitoringThreatCountArgs = {module?: ('dark_web' | 'open_web' | 'social_media') | undefined, date_period?: ('last_twenty_four_hours' | 'last_seven_days' | 'last_thirty_days' | 'last_three_months' | 'last_six_months' | 'last_twelve_months' | 'all_time') | undefined, date_period_timezone?: string | undefined, date_field?: ('date_occurred' | 'date_detected' | 'date_alerted' | 'date_updated' | 'date_closed') | undefined, transforms?: Array | undefined, severities?: (Array<'critical' | 'high' | 'medium' | 'low' | 'info'>) | undefined, threat_types?: (Array<'exposed_credentials' | 'exposed_credentials_site' | 'exposed_credentials_user' | 'exposed_pii' | 'malware' | 'keyword_mention' | 'confidential_business' | 'brand_impersonation' | 'denial_of_service' | 'planned_intrusion' | 'network_access_for_sale' | 'data_for_sale' | 'possible_data_breach' | 'planned_attack' | 'planned_violent_threat' | 'planned_protest_activism' | 'account_compromise' | 'fraud_or_loss' | 'complaint'>) | undefined, source_types?: (Array<'stealer_logs' | 'forum' | 'marketplace' | 'ransomware_blog' | 'icq' | 'openbazaar' | 'paste' | 'blogs' | 'news' | 'social_media' | 'code_repository' | 'issue_tracker' | 'package_repository' | 'messaging' | 'owned_domain' | 'education_research' | 'business_commercial' | 'cloud_storage' | 'cloud_services' | 'community' | 'conferences_events' | 'cms' | 'documentation' | 'domain_tools' | 'fin_services' | 'govt_legal' | 'healthcare' | 'industrial_manufacture' | 'job_board' | 'media_entertainment' | 'network_tool' | 'personal_web' | 'search_engine' | 'sec_tools' | 'software' | 'sports' | 'tech' | 'vibe_coding_tool' | 'mcp_registries' | 'data_dump' | 'exposed_service'>) | undefined, auto_dismissed?: boolean | undefined, closed_status?: (Array<'dismissed' | 'dismissed_by_rule' | 'smart_filtered' | 'remediated' | 'waived'>) | undefined, threat_status?: ('open' | 'investigating' | 'remediating' | 'closed') | undefined}; export type GetApiThreatmonitoringThreatCountOptions = {baseUrl?: string | undefined, APIKeyInHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const getThreatMonitoringResultsCountResponsePayloadBody = z.object({total_results: z.number().int().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 }; /** * Count threats * * GET /threatmonitoring/threat/count */ export const getApiThreatmonitoringThreatCount = async (args: GetApiThreatmonitoringThreatCountArgs, options?: GetApiThreatmonitoringThreatCountOptions) => { const {baseUrl = "https://cyber-risk.upguard.com/api/public", fetch: fetchFn = fetch, APIKeyInHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.module != null) query.append("module", String(args.module)) if (args.date_period != null) query.append("date_period", String(args.date_period)) if (args.date_period_timezone != null) query.append("date_period_timezone", String(args.date_period_timezone)) if (args.date_field != null) query.append("date_field", String(args.date_field)) for (const item of args.transforms ?? []) query.append("transforms", String(item)) for (const item of args.severities ?? []) query.append("severities", String(item)) for (const item of args.threat_types ?? []) query.append("threat_types", String(item)) for (const item of args.source_types ?? []) query.append("source_types", String(item)) if (args.auto_dismissed != null) query.append("auto_dismissed", String(args.auto_dismissed)) for (const item of args.closed_status ?? []) query.append("closed_status", String(item)) if (args.threat_status != null) query.append("threat_status", String(args.threat_status)) if (APIKeyInHeader !== undefined) headers.set("Authorization", APIKeyInHeader) const url = `${baseUrl.replace(/\/+$/, '')}/threatmonitoring/threat/count${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(getThreatMonitoringResultsCountResponsePayloadBody, await res.json()) };