export type GetApiImageSrcDomainOrTokenArgs = {domainOrToken: string, withOverlay?: boolean | undefined, theme?: ('light' | 'dark') | undefined}; export type GetApiImageSrcDomainOrTokenOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get Domain image source * * GET /image-src/{domainOrToken} */ export const getApiImageSrcDomainOrToken = async (args: GetApiImageSrcDomainOrTokenArgs, options?: GetApiImageSrcDomainOrTokenOptions) => { const {baseUrl = "https://api.unstoppabledomains.com/metadata", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/html; charset=utf-8") if (args.withOverlay != null) query.append("withOverlay", String(args.withOverlay)) if (args.theme != null) query.append("theme", String(args.theme)) const url = `${baseUrl.replace(/\/+$/, '')}/image-src/${encodeURIComponent(String(args.domainOrToken))}${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 res.text() };