export type ResourceKindName = 'repositoryName' | 'repositoryURL' | 'organizationName' | 'userAlias'; export type HeadApiCheckAvailabilityResourceKindArgs = {resourceKind: ResourceKindName, v: string}; export type HeadApiCheckAvailabilityResourceKindOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Check the availability of a given value for the provided resource kind * * HEAD /check-availability/{resourceKind} */ export const headApiCheckAvailabilityResourceKind = async (args: HeadApiCheckAvailabilityResourceKindArgs, options: HeadApiCheckAvailabilityResourceKindOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.v != null) query.append("v", String(args.v)) const url = `${baseUrl.replace(/\/+$/, '')}/check-availability/${encodeURIComponent(String(args.resourceKind))}${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 };