export type GetApiV1DomainSearchArgs = {domain: string, emailServiceProvider: 'Google' | 'Microsoft' | 'Azure', tld?: Array | undefined, page?: number | undefined}; export type GetApiV1DomainSearchOptions = {baseUrl: string, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Search available domain names * * GET /v1/domain/search */ export const getApiV1DomainSearch = async (args: GetApiV1DomainSearchArgs, options: GetApiV1DomainSearchOptions) => { const {baseUrl, fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.domain != null) query.append("domain", String(args.domain)) if (args.emailServiceProvider != null) query.append("emailServiceProvider", String(args.emailServiceProvider)) for (const item of args.tld ?? []) query.append("tld", String(item)) if (args.page != null) query.append("page", String(args.page)) if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/domain/search${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 undefined };