export type GetApiRandomSourceIDArgs = {sourceID?: unknown}; export type GetApiRandomSourceIDOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Retrieve a random Shabad * * GET /random/{sourceID} */ export const getApiRandomSourceID = async (args: GetApiRandomSourceIDArgs, options: GetApiRandomSourceIDOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() const url = `${baseUrl.replace(/\/+$/, '')}/random/${encodeURIComponent(String(args.sourceID))}${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 };