export type GetApiMethodGetDatasetListArgs = {ResultFormat?: ('JSON' | 'XML') | undefined}; export type GetApiMethodGetDatasetListOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * List all available datasets * * GET /?Method=GetDatasetList */ export const getApiMethodGetDatasetList = async (args: GetApiMethodGetDatasetListArgs, options?: GetApiMethodGetDatasetListOptions) => { const {baseUrl = "https://apps.bea.gov/api/data", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.ResultFormat != null) query.append("ResultFormat", String(args.ResultFormat)) if (ApiKey !== undefined) query.set("UserID", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/?Method=GetDatasetList${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 };