export type CreateApiCrxPackmgrServiceJspArgs = {cmd: string}; export type CreateApiCrxPackmgrServiceJspOptions = {baseUrl: string, aemAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * POST /crx/packmgr/service.jsp */ export const createApiCrxPackmgrServiceJsp = async (args: CreateApiCrxPackmgrServiceJspArgs, options: CreateApiCrxPackmgrServiceJspOptions) => { const {baseUrl, fetch: fetchFn = fetch, aemAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/xml") if (args.cmd != null) query.append("cmd", String(args.cmd)) if (aemAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${aemAuth.username}:${aemAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/crx/packmgr/service.jsp${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };