export type CreateApiCqactionsHtmlArgs = {authorizableId: string, changelog: string}; export type CreateApiCqactionsHtmlOptions = {baseUrl: string, aemAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * POST /.cqactions.html */ export const createApiCqactionsHtml = async (args: CreateApiCqactionsHtmlArgs, options: CreateApiCqactionsHtmlOptions) => { const {baseUrl, fetch: fetchFn = fetch, aemAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.authorizableId != null) query.append("authorizableId", String(args.authorizableId)) if (args.changelog != null) query.append("changelog", String(args.changelog)) if (aemAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${aemAuth.username}:${aemAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/.cqactions.html${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 undefined };