export type GetApiDomainsDomainArgs = {domain: string, 'x-apikey': string}; export type GetApiDomainsDomainOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get a domain report * * GET /domains/{domain} */ export const getApiDomainsDomain = async (args: GetApiDomainsDomainArgs, options?: GetApiDomainsDomainOptions) => { const {baseUrl = "https://www.virustotal.com/api/v3", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-apikey'] != null) headers.set("x-apikey", String(args['x-apikey'])) const url = `${baseUrl.replace(/\/+$/, '')}/domains/${encodeURIComponent(String(args.domain))}${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 (await res.json()) as unknown };