export type CreateApiToolsExecuteScriptArgs = {body: BodyInit}; export type CreateApiToolsExecuteScriptOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Execute Lua script * * POST /tools/execute-script */ export const createApiToolsExecuteScript = async (args: CreateApiToolsExecuteScriptArgs, options?: CreateApiToolsExecuteScriptOptions) => { const {baseUrl = "https://orthanc.uclouvain.be/demo", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "text/plain") headers.set('accept', "text/plain") const url = `${baseUrl.replace(/\/+$/, '')}/tools/execute-script${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 res.text() };