export type RemoteSettings = {host: string, connectionKey: string, blockLogsFetchByRemote?: boolean | undefined}; export type UpdateApiRemoteArgs = {body: RemoteSettings}; export type UpdateApiRemoteOptions = {baseUrl: string, adminAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Connect to remote server with given remote settings. * * PUT /remote */ export const updateApiRemote = async (args: UpdateApiRemoteArgs, options: UpdateApiRemoteOptions) => { const {baseUrl, fetch: fetchFn = fetch, adminAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (adminAuth !== undefined) headers.set("authentication", adminAuth) const url = `${baseUrl.replace(/\/+$/, '')}/remote${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };