export type CreateApiDiscoverBulkArgs = {body: Array}; export type CreateApiDiscoverBulkOptions = {baseUrl: string, DiscoveryAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Add servers in bulk * * POST /discover/bulk */ export const createApiDiscoverBulk = async (args: CreateApiDiscoverBulkArgs, options: CreateApiDiscoverBulkOptions) => { const {baseUrl, fetch: fetchFn = fetch, DiscoveryAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (DiscoveryAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${DiscoveryAuth.username}:${DiscoveryAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/discover/bulk${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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 };