export type CreateApiImportUrlArgs = {body: BodyInit}; export type CreateApiImportUrlOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Imports the json file provided by the posted url into the service * * POST /import/url */ export const createApiImportUrl = async (args: CreateApiImportUrlArgs, options: CreateApiImportUrlOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "text/plain") const url = `${baseUrl.replace(/\/+$/, '')}/import/url${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };