import {z} from 'zod' export type CreateApiThreatFeedsClickfixDomainArgs = {domain: string}; export type CreateApiThreatFeedsClickfixDomainOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiThreatFeedsClickfixDomainResponse = z.object({data: z.object({_id: z.string().optional(), domain: z.string().optional(), url: z.string().optional(), timestamp: z.string().optional(), captchaFound: z.boolean().optional(), clipboardHijacked: z.boolean().optional(), malicious: z.boolean().optional(), isNsfw: z.boolean().optional(), isCompromised: z.boolean().optional(), clipboardContent: z.string().nullable().optional(), pageTitle: z.string().nullable().optional(), screenshots: z.object({before: z.string().nullable().optional(), after: z.string().nullable().optional()}).optional(), metadata: z.object({ip: z.string().nullable().optional(), country: z.string().nullable().optional(), asn: z.number().int().nullable().optional(), server: z.string().nullable().optional(), technologies: z.array(z.string()).optional(), tags: z.array(z.string()).optional(), urlscanLink: z.string().nullable().optional()}).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), compromised_data: z.object({domain: z.string().optional(), compromised_employees: z.number().int().optional(), last_employee_compromised: z.string().nullable().optional(), compromised_users: z.number().int().optional(), last_user_compromised: z.string().nullable().optional()}).optional()}).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 }; /** * ClickFix Domain Lookup * * POST /threat-feeds/clickfix/{domain} */ export const createApiThreatFeedsClickfixDomain = async (args: CreateApiThreatFeedsClickfixDomainArgs, options?: CreateApiThreatFeedsClickfixDomainOptions) => { const {baseUrl = "https://api.hudsonrock.com/json/v3", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/threat-feeds/clickfix/${encodeURIComponent(String(args.domain))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiThreatFeedsClickfixDomainResponse, await res.json()) };