export type GetApiDomainOrTokenArgs = {domainOrToken: string}; export type GetApiDomainOrTokenOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get Domain metadata * * GET /{domainOrToken} */ export const getApiDomainOrToken = async (args: GetApiDomainOrTokenArgs, options?: GetApiDomainOrTokenOptions) => { 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") const url = `${baseUrl.replace(/\/+$/, '')}/${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() };