export type GetApiDataPackagesArgs = {name?: string | undefined}; export type GetApiDataPackagesOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * GET /data-packages */ export const getApiDataPackages = async (args: GetApiDataPackagesArgs, options?: GetApiDataPackagesOptions) => { const {baseUrl = "https://aggregator.smartcumulus.org", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.name != null) query.append("name", String(args.name)) if (apiKey !== undefined) headers.set("x-api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/data-packages${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 };