export type GetApiFredSnapshotUrlArgs = {url?: string | undefined, info?: string | undefined, f?: ('json' | 'csv' | 'html') | undefined}; export type GetApiFredSnapshotUrlOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * GET /fred/snapshot/url */ export const getApiFredSnapshotUrl = async (args: GetApiFredSnapshotUrlArgs, options: GetApiFredSnapshotUrlOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.url != null) query.append("url", String(args.url)) if (args.info != null) query.append("info", String(args.info)) if (args.f != null) query.append("f", String(args.f)) if (OAuth2 !== undefined) query.set("c", OAuth2) const url = `${baseUrl.replace(/\/+$/, '')}/fred/snapshot/url${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 };