export type HeadApiProvidersArgs = {subject?: string | undefined}; export type HeadApiProvidersOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Check providers availability. * * HEAD /providers */ export const headApiProviders = async (args: HeadApiProvidersArgs, options: HeadApiProvidersOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.subject != null) query.append("subject", String(args.subject)) const url = `${baseUrl.replace(/\/+$/, '')}/providers${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "HEAD", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };