export type GetApiConfigSpreadArgs = {catalog_path?: string | undefined}; export type GetApiConfigSpreadOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Get spread.conf file from the local host. * * GET /config/spread */ export const getApiConfigSpread = async (args: GetApiConfigSpreadArgs, options: GetApiConfigSpreadOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.catalog_path != null) query.append("catalog_path", String(args.catalog_path)) const url = `${baseUrl.replace(/\/+$/, '')}/config/spread${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 };