export type GetApiWellKnownOauthProtectedResourcePathArgs = {path: string}; export type GetApiWellKnownOauthProtectedResourcePathOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * GET /.well-known/oauth-protected-resource/{path} */ export const getApiWellKnownOauthProtectedResourcePath = async (args: GetApiWellKnownOauthProtectedResourcePathArgs, options: GetApiWellKnownOauthProtectedResourcePathOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (ApiKey !== undefined) headers.set("X-Api-Key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/.well-known/oauth-protected-resource/${encodeURIComponent(String(args.path))}${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 };