export type GetApiV2LearnCodeBaseTargetArgs = {Authorization: string, code: string, base: string, target: string}; export type GetApiV2LearnCodeBaseTargetOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Get learn with code, base and target * * GET /v2/learn/{code}/{base}/{target} */ export const getApiV2LearnCodeBaseTarget = async (args: GetApiV2LearnCodeBaseTargetArgs, options: GetApiV2LearnCodeBaseTargetOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/learn/${encodeURIComponent(String(args.code))}/${encodeURIComponent(String(args.base))}/${encodeURIComponent(String(args.target))}${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 };