export type HeadApiCArgs = {type?: string | undefined, mode?: string | undefined, label?: string | undefined, language?: string | undefined, sort?: string | undefined, 'providers.ids'?: string | undefined, 'providers.subject'?: string | undefined}; export type HeadApiCOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Check concepts or collections availability. * * HEAD /c */ export const headApiC = async (args: HeadApiCArgs, options: HeadApiCOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.type != null) query.append("type", String(args.type)) if (args.mode != null) query.append("mode", String(args.mode)) if (args.label != null) query.append("label", String(args.label)) if (args.language != null) query.append("language", String(args.language)) if (args.sort != null) query.append("sort", String(args.sort)) if (args['providers.ids'] != null) query.append("providers.ids", String(args['providers.ids'])) if (args['providers.subject'] != null) query.append("providers.subject", String(args['providers.subject'])) const url = `${baseUrl.replace(/\/+$/, '')}/c${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 };