export type Template = {config?: string | undefined, cssCode?: string | undefined, dateActivated?: string | undefined, dateCreated?: string | undefined, dateModified?: string | undefined, description?: string | undefined, htmlCode?: string | undefined, id?: number | undefined, isCustomTemplate?: boolean | undefined, name?: string | undefined, siteId: number, status?: ('DRAFT' | 'ACTIVE' | 'PAUSED') | undefined, tags?: Array | undefined, templateCssCode?: string | undefined, templateHtmlCode?: string | undefined, templateJavaScriptCode?: string | undefined, themeId?: number | undefined, type?: ('TEMPLATE' | 'EDITOR' | 'PBX') | undefined, url?: string | undefined, useCustomData?: boolean | undefined, widgetEditorTemplate?: string | undefined}; export type CreateApiTemplatesArgs = {body: Template}; export type CreateApiTemplatesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new template * * POST /templates */ export const createApiTemplates = async (args: CreateApiTemplatesArgs, options?: CreateApiTemplatesOptions) => { const {baseUrl = "https://api.kameleoon.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/templates${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 res.blob() };