import {z} from 'zod' export type IdentifierString = string; export type GenericString = string; export type IPv4Address = string; export type ApexDomainList = string; export type EmailAddress = string; export type ApexDomain = string; export type Fqdn = string; export type Hostname = string; export type OrgNameString = string; export type SearchHashToken = string; export type BasicString = string; export type Sha1HexString = string; export type SslSubjectDnString = string; export type WebsiteTitleString = string; export type DateOperatorsFilter = string; export type MaxDaysSince = number; export type DateFilter = string; export type TimestampFilter = number | string; export type TimeWindowSeconds = number; export type CommaSeparatedTags = string; export type TopLevelDomain = string; export type BooleanOptInFlag = boolean; export type ResponseFormat = 'html' | 'json' | 'xml'; export type PositionToken = string; export type InvestigateRequestParameters = {adsense?: IdentifierString | undefined, baidu_analytics?: IdentifierString | undefined, contact_name?: GenericString | undefined, contact_phone?: GenericString | undefined, contact_street?: GenericString | undefined, ip?: IPv4Address | undefined, domain?: ApexDomainList | undefined, email?: EmailAddress | undefined, email_dns_soa?: EmailAddress | undefined, email_domain?: ApexDomain | undefined, historical_free_text?: GenericString | undefined, facebook?: IdentifierString | undefined, ga4?: IdentifierString | undefined, google_analytics?: IdentifierString | undefined, google_tag_manager?: IdentifierString | undefined, hotjar?: IdentifierString | undefined, iana_id?: IdentifierString | undefined, mailserver_domain?: ApexDomain | undefined, mailserver_host?: Fqdn | undefined, mailserver_ip?: IPv4Address | undefined, matomo?: IdentifierString | undefined, nameserver_domain?: Hostname | undefined, nameserver_host?: Hostname | undefined, nameserver_ip?: IPv4Address | undefined, redirect_domain?: GenericString | undefined, registrant?: OrgNameString | undefined, historical_registrant?: OrgNameString | undefined, registrant_org?: OrgNameString | undefined, registrar?: OrgNameString | undefined, search_hash?: SearchHashToken | undefined, server_type?: BasicString | undefined, ssl_alt_names?: GenericString | undefined, ssl_common_name?: GenericString | undefined, ssl_duration?: number | undefined, ssl_email?: EmailAddress | undefined, ssl_hash?: Sha1HexString | undefined, ssl_org?: OrgNameString | undefined, ssl_subject?: SslSubjectDnString | undefined, ssl_issuer_common_name?: GenericString | undefined, statcounter_project?: IdentifierString | undefined, statcounter_security?: IdentifierString | undefined, tagged_with_all?: GenericString | undefined, tagged_with_any?: GenericString | undefined, website_title?: WebsiteTitleString | undefined, whois?: GenericString | undefined, yandex_metrica?: IdentifierString | undefined, active?: boolean | undefined, create_date?: DateOperatorsFilter | undefined, create_date_within?: MaxDaysSince | undefined, expiration_date?: DateFilter | undefined, first_seen_since?: TimestampFilter | undefined, first_seen_within?: TimeWindowSeconds | undefined, ip_country_code?: string | undefined, rank?: number | undefined, risk_score?: number | undefined, ssl_not_after?: DateFilter | undefined, ssl_not_before?: DateFilter | undefined, not_tagged_with_all?: CommaSeparatedTags | undefined, not_tagged_with_any?: CommaSeparatedTags | undefined, tld?: TopLevelDomain | undefined, parsed_domain_rdap?: BooleanOptInFlag | undefined, parsed_whois?: BooleanOptInFlag | undefined, next?: BooleanOptInFlag | undefined, format?: ResponseFormat | undefined, page_size?: number | undefined, position?: PositionToken | undefined, sort_by?: ('first_seen_since' | 'create_date' | 'domain' | 'risk_score') | undefined, sort_direction?: ('asc' | 'dsc') | undefined, app_name?: IdentifierString | undefined, app_partner?: IdentifierString | undefined, app_version?: IdentifierString | undefined}; export type CreateApiV1IrisInvestigateArgs = {body: InvestigateRequestParameters}; export type CreateApiV1IrisInvestigateOptions = {baseUrl?: string | undefined, headerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const baseContact = z.object({name: z.unknown(), org: z.unknown(), street: z.unknown(), city: z.unknown(), state: z.unknown(), postal: z.unknown(), country: z.unknown(), phone: z.unknown(), fax: z.unknown(), email: z.array(z.unknown()).optional()}); export const riskScoreValue = z.number().int().gte(0).lte(100); export const proximity = z.object({name: z.literal("proximity"), risk_score: riskScoreValue, evidence: z.array(z.string()).optional()}); export const threatProfile = z.object({name: z.literal("threat_profile"), risk_score: riskScoreValue, evidence: z.array(z.string()).optional()}); export const threatProfileMalware = z.object({name: z.literal("threat_profile_malware"), risk_score: riskScoreValue, evidence: z.array(z.string()).optional()}); export const threatProfilePhishing = z.object({name: z.literal("threat_profile_phishing"), risk_score: riskScoreValue, evidence: z.array(z.string()).optional()}); export const threatProfileSpam = z.object({name: z.literal("threat_profile_spam"), risk_score: riskScoreValue, evidence: z.array(z.string()).optional()}); export const zeroListedScore = z.object({name: z.literal("zerolist"), risk_score: z.literal(0)}); export const domainRiskComponent = z.discriminatedUnion("name", [proximity, threatProfile, threatProfileMalware, threatProfilePhishing, threatProfileSpam, zeroListedScore]); export const domainRisk = z.object({risk_score: riskScoreValue.optional(), components: z.array(domainRiskComponent).optional()}); export const baseSslInfo = z.object({hash: z.unknown(), subject: z.unknown(), organization: z.unknown(), email: z.array(z.string()).optional(), alt_names: z.array(z.unknown()).optional(), sources: z.object({active: z.number().int().optional(), passive: z.number().int().optional()}).optional(), common_name: z.unknown(), issuer_common_name: z.unknown(), not_after: z.unknown(), not_before: z.unknown(), duration: z.unknown()}); export const pivotedValue = z.object({value: z.union([z.string(), z.number().int()]).optional(), count: z.number().int().optional()}); export const whoisContact = z.object({name: pivotedValue.optional(), org: pivotedValue.optional(), street: pivotedValue.optional(), city: pivotedValue.optional(), state: pivotedValue.optional(), postal: pivotedValue.optional(), country: pivotedValue.optional(), phone: pivotedValue.optional(), fax: pivotedValue.optional(), email: z.array(pivotedValue).optional()}); export const parsedWhois = z.object({technical_contact: whoisContact.optional(), registrant_contact: whoisContact.optional(), admin_contact: whoisContact.optional(), additional_whois_email: z.array(pivotedValue).optional(), registrar: pivotedValue.optional(), create_date: pivotedValue.optional(), expiration_date: pivotedValue.optional(), registrant_name: pivotedValue.optional(), registrant_org: pivotedValue.optional(), registrar_status: z.array(pivotedValue).optional()}); export const rdapContact = z.object({name: pivotedValue.optional(), org: pivotedValue.optional(), street: pivotedValue.optional(), city: pivotedValue.optional(), state: pivotedValue.optional(), postal: pivotedValue.optional(), country: pivotedValue.optional(), phone: pivotedValue.optional(), fax: pivotedValue.optional(), email: z.array(pivotedValue).optional()}); export const parsedDomainRdap = z.object({registrant_contact: rdapContact.optional(), admin_contact: rdapContact.optional(), technical_contact: rdapContact.optional(), registrant_name: pivotedValue.optional(), registrar_iana_id: pivotedValue.optional(), additional_whois_email: z.array(pivotedValue).optional(), registrar: pivotedValue.optional(), create_date: pivotedValue.optional(), expiration_date: pivotedValue.optional(), registrar_status: z.array(pivotedValue).optional(), email_domain: z.array(pivotedValue).optional()}); export const investigateResult = z.object({domain: z.string().optional(), whois_url: z.string().optional(), adsense: z.unknown(), alexa: z.number().int().optional(), popularity_rank: z.number().optional(), active: z.boolean().optional(), google_analytics: z.unknown(), ga4: z.array(z.unknown()).optional(), gtm_codes: z.array(z.unknown()).optional(), fb_codes: z.array(z.unknown()).optional(), hotjar_codes: z.array(z.unknown()).optional(), baidu_codes: z.array(z.unknown()).optional(), yandex_codes: z.array(z.unknown()).optional(), matomo_codes: z.array(z.unknown()).optional(), statcounter_project_codes: z.array(z.unknown()).optional(), statcounter_security_codes: z.array(z.unknown()).optional(), admin_contact: baseContact.optional(), billing_contact: baseContact.optional(), registrant_contact: baseContact.optional(), technical_contact: baseContact.optional(), create_date: z.unknown(), expiration_date: z.unknown(), email_domain: z.array(z.unknown()).optional(), soa_email: z.array(z.unknown()).optional(), ssl_email: z.array(z.unknown()).optional(), additional_whois_email: z.array(z.unknown()).optional(), ip: z.array(z.object({address: z.unknown(), asn: z.array(z.unknown()).optional(), country_code: z.unknown(), isp: z.unknown()})).optional(), mx: z.array(z.object({host: z.unknown(), domain: z.unknown(), ip: z.array(z.unknown()).optional(), priority: z.number().optional()})).optional(), name_server: z.array(z.object({host: z.unknown(), domain: z.unknown(), ip: z.array(z.unknown()).optional()})).optional(), domain_risk: domainRisk.optional(), redirect: z.unknown(), redirect_domain: z.unknown(), registrant_name: z.unknown(), registrant_org: z.unknown(), registrar: z.unknown(), registrar_status: z.array(z.string()).optional(), spf_info: z.string().optional(), ssl_info: z.array(baseSslInfo).optional(), tld: z.string().optional(), website_response: z.number().optional(), data_updated_timestamp: z.string().optional(), website_title: z.unknown(), server_type: z.unknown(), first_seen: z.unknown(), tags: z.array(z.object({label: z.string().optional(), scope: z.string().optional(), tagged_at: z.string().optional()})).optional(), parsed_whois: parsedWhois.optional(), parsed_domain_rdap: parsedDomainRdap.optional()}); export const apexDomain = z.string(); export const createApiV1IrisInvestigateResponse = z.object({response: z.object({limit_exceeded: z.boolean().optional(), has_more_results: z.boolean().optional(), message: z.string().optional(), results_count: z.number().int().optional(), total_count: z.number().int().optional(), results: z.array(investigateResult).optional(), missing_domains: z.array(apexDomain).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 }; /** * Returns data from a POST request. * * POST /v1/iris-investigate/ * * Also accepts auth: open_key_auth, hmac_auth */ export const createApiV1IrisInvestigate = async (args: CreateApiV1IrisInvestigateArgs, options?: CreateApiV1IrisInvestigateOptions) => { const {baseUrl = "https://api.domaintools.com", fetch: fetchFn = fetch, headerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "application/json") if (headerAuth !== undefined) headers.set("X-Api-Key", headerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/iris-investigate/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV1IrisInvestigateResponse, await res.json()) };