export type WidgetPbxSimulationInput = {cssCode?: string | undefined, jsCode: string}; export type FormFieldIO = {elementId: string, id: string, isDeprecated?: boolean | undefined, name: string, parentId?: string | undefined, valueType: 'BOOLEAN' | 'NUMBER' | 'STRING' | 'STRING_ARRAY' | 'DATE' | 'TIME'}; export type CustomData = {adobeAnalyticsVariableName?: string | undefined, advancedProposedValues?: string | undefined, createdById?: number | undefined, customEvalCode?: string | undefined, dateCreated?: string | undefined, dateModified?: string | undefined, description?: string | undefined, format?: ('BOOLEAN' | 'NUMBER' | 'STRING') | undefined, gtmVariableName?: string | undefined, id?: number | undefined, index?: number | undefined, isConstant?: boolean | undefined, isFiltrableVentilable?: boolean | undefined, isLearnable?: boolean | undefined, isLocalOnly?: boolean | undefined, method: 'ADOBE_ANALYTICS' | 'CLIENT' | 'CUSTOM_CODE' | 'GTM' | 'SDK' | 'TC' | 'TEALIUM', modificationDate?: string | undefined, name: string, siteCode?: string | undefined, siteId: number, tags?: string | undefined, tcVariableName?: string | undefined, tealiumVariableName?: string | undefined, type?: ('COUNT_LIST' | 'LIST' | 'UNIQUE') | undefined}; export type RequestHeaderDataTypeIO = {customData?: CustomData | undefined, id: string, name: string, type: 'CUSTOM_DATA' | 'CUSTOM_TEXT' | 'LOCAL_STORAGE' | 'COOKIES', value: string}; export type RequestSettingsIO = {headers?: Array | undefined, type: 'GET' | 'POST', url: string}; export type TriggerSettingsIO = {type: 'CLICK' | 'CLOSE' | 'ANSWER', value?: string | undefined}; export type SurveyDataConfigIO = {fields: Array, isCollectData: boolean, methodTypes: Array<'KAMELEOON' | 'HTTP_REQUEST' | 'CUSTOM_JS_CODE'>, requestSettings?: RequestSettingsIO | undefined, triggerSettings: TriggerSettingsIO}; export type WidgetTemplateInput = {displayPluginConfiguration: string, domElementSelector?: string | undefined, locales?: string | undefined, position: 'INPAGE' | 'ABOVE', positionSelectorRelative?: string | undefined, shadowDom: boolean, surveyDataConfig?: SurveyDataConfigIO | undefined, widgetEditorTemplate?: string | undefined, widgetFonts?: string | undefined}; export type TemplateSimulationInput = {widgetPbxSimulationInput?: WidgetPbxSimulationInput | undefined, widgetTemplateInput: WidgetTemplateInput}; export type CreateApiTemplatesSimulateWidgetIdArgs = {widgetId: number, body: TemplateSimulationInput}; export type CreateApiTemplatesSimulateWidgetIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Simulate widget * * POST /templates/simulate/{widgetId} */ export const createApiTemplatesSimulateWidgetId = async (args: CreateApiTemplatesSimulateWidgetIdArgs, options?: CreateApiTemplatesSimulateWidgetIdOptions) => { 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/simulate/${encodeURIComponent(String(args.widgetId))}${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() };