export type GetApiResolveArgs = {url: string}; export type GetApiResolveOptions = {baseUrl?: string | undefined, AuthHeader?: string | undefined, fetch?: typeof fetch | undefined}; /** * Resolves soundcloud.com and on.soundcloud.com URLs to Resource URLs to use with the API. * * GET /resolve * * Also accepts auth: oAuth2_1 */ export const getApiResolve = async (args: GetApiResolveArgs, options?: GetApiResolveOptions) => { const {baseUrl = "https://api.soundcloud.com", fetch: fetchFn = fetch, AuthHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.url != null) query.append("url", String(args.url)) if (AuthHeader !== undefined) headers.set("Authorization", AuthHeader) const url = `${baseUrl.replace(/\/+$/, '')}/resolve${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 };