@kaia-team/n8n-nodes-kaia
Version:
n8n nodes for Kaia LLM integration
728 lines • 22.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.widgetsApiProperties = void 0;
exports.handleWidgetsApi = handleWidgetsApi;
const n8n_workflow_1 = require("n8n-workflow");
const utils_1 = require("../utils");
/**
* Widgets API Properties
* Properties specific to the widgets API resource (widget configs)
*/
exports.widgetsApiProperties = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['widgets'],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a widget config',
action: 'Create a widget config',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a widget config',
action: 'Delete a widget config',
},
{
name: 'List',
value: 'list',
description: 'List all widget configs',
action: 'List widget configs',
},
{
name: 'Read',
value: 'read',
description: 'Read a widget config',
action: 'Read a widget config',
},
{
name: 'Update',
value: 'update',
description: 'Update a widget config',
action: 'Update a widget config',
},
],
default: 'list',
},
{
displayName: 'Widget ID',
name: 'widgetId',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['read', 'update', 'delete'],
},
},
description: 'The ID of the widget config',
required: true,
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
description: 'Name of the widget',
},
{
displayName: 'Question Timeline',
name: 'question_timeline',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Voice',
name: 'voice',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Initial Status',
name: 'initial_status',
type: 'options',
options: [
{ name: 'Collapsed', value: 'collapsed' },
{ name: 'Full Screen', value: 'full-screen' },
{ name: 'Open', value: 'open' },
],
default: 'collapsed',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Available Assistants',
name: 'available_assistants',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
description: 'Comma-separated list of assistant UUIDs',
},
{
displayName: 'Assistant ID',
name: 'assistant_id',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
description: 'Active assistant ID',
},
{
displayName: 'Vec DB IDs',
name: 'vec_db_ids',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
placeholder: 'Add Vec DB',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
options: [
{
name: 'vecDbItems',
displayName: 'Vec DB Items',
values: [
{
displayName: 'ID',
name: 'id',
type: 'string',
default: '',
},
{
displayName: 'Weight',
name: 'weight',
type: 'number',
default: 1,
},
],
},
],
},
{
displayName: 'Widget Headline Font Color',
name: 'widget_headline_font_color',
type: 'color',
default: '#000000',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Transcript Color',
name: 'transcript_color',
type: 'color',
default: '#000000',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Bubble Background Color',
name: 'bubble_background_color',
type: 'color',
default: '#ffffff',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Bubble Font Color',
name: 'bubble_font_color',
type: 'color',
default: '#000000',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Button List Color',
name: 'button_list_color',
type: 'color',
default: '#ffffff',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Button List Font Color',
name: 'button_list_font_color',
type: 'color',
default: '#000000',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Radiobox Border Color',
name: 'radiobox_border_color',
type: 'color',
default: '#000000',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Active Radiobox Color',
name: 'active_radiobox_color',
type: 'color',
default: '#000000',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Checkbox Border Color',
name: 'checkbox_border_color',
type: 'color',
default: '#000000',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Active Checkbox Color',
name: 'active_checkbox_color',
type: 'color',
default: '#000000',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Tile Button Background Color',
name: 'tile_button_background_color',
type: 'color',
default: '#ffffff',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Tile Button Font Color',
name: 'tile_button_font_color',
type: 'color',
default: '#000000',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Link Text Color',
name: 'link_text_color',
type: 'color',
default: '#0000ff',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Font Color',
name: 'font_color',
type: 'color',
default: '#000000',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Links Color',
name: 'links_color',
type: 'color',
default: '#0000ff',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Buttons Color',
name: 'buttons_color',
type: 'color',
default: '#ffffff',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Buttons Font Color',
name: 'buttons_font_color',
type: 'color',
default: '#000000',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Font',
name: 'font',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
description: 'Path to font file or base64 data',
},
{
displayName: 'Headline Font Size',
name: 'headline_font_size',
type: 'number',
default: 16,
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Headline Mobile Font Size',
name: 'headline_mobile_font_size',
type: 'number',
default: 14,
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Bubble Font Size',
name: 'bubble_font_size',
type: 'number',
default: 14,
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Headline Text',
name: 'headline_text',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Widget Placeholder',
name: 'widget_placeholder',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Widget Terms of Use',
name: 'widget_terms_of_use',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Terms of Service Link',
name: 'terms_of_service_link',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Widget Headline',
name: 'widget_headline',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Chat History Text',
name: 'chat_history_text',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Background',
name: 'background',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
description: 'Path to background file or base64 data',
},
{
displayName: 'Icon',
name: 'icon',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
description: 'Path to icon file or base64 data',
},
{
displayName: 'Remove Icon',
name: 'remove_icon',
type: 'boolean',
default: false,
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
{
displayName: 'Remove Background',
name: 'remove_background',
type: 'boolean',
default: false,
displayOptions: {
show: {
resource: ['widgets'],
operation: ['create', 'update'],
},
},
},
];
/**
* Widgets API Handler
* Handles requests to the widgets API (widget configs)
*/
async function handleWidgetsApi(executeFunctions, itemIndex, adminUrl, adminToken) {
const operation = executeFunctions.getNodeParameter('operation', itemIndex);
const additionalFields = executeFunctions.getNodeParameter('additionalFields', itemIndex, {});
const headers = (0, utils_1.createHeaders)(adminToken, additionalFields);
if (operation === 'list') {
const response = await executeFunctions.helpers.httpRequest({
method: 'GET',
url: `${adminUrl}/widget_configs.json`,
headers,
});
return executeFunctions.helpers.returnJsonArray(response);
}
else if (operation === 'read') {
const widgetId = executeFunctions.getNodeParameter('widgetId', itemIndex);
const response = await executeFunctions.helpers.httpRequest({
method: 'GET',
url: `${adminUrl}/widget_configs/${widgetId}.json`,
headers,
});
return response;
}
else if (operation === 'create' || operation === 'update') {
const payload = { widget_config: {} };
// Helper to add if not empty
const addIfSet = (key, param, defaultVal = '') => {
const val = executeFunctions.getNodeParameter(param, itemIndex, defaultVal);
if (val !== defaultVal && (typeof val !== 'string' || val.trim() !== '')) {
payload.widget_config[key] = val;
}
};
// Mandatory for create
if (operation === 'create') {
const name = executeFunctions.getNodeParameter('name', itemIndex, '');
const availableAssistants = executeFunctions.getNodeParameter('available_assistants', itemIndex, '');
const assistantId = executeFunctions.getNodeParameter('assistant_id', itemIndex, '');
if (!name || !availableAssistants || !assistantId) {
throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), 'Missing mandatory fields for create: name, available_assistants, assistant_id');
}
}
addIfSet('name', 'name');
addIfSet('question_timeline', 'question_timeline');
addIfSet('voice', 'voice');
addIfSet('initial_status', 'initial_status');
// For arrays
const availableAssistantsStr = executeFunctions.getNodeParameter('available_assistants', itemIndex, '');
if (availableAssistantsStr.trim() !== '') {
payload.widget_config.available_assistants =
availableAssistantsStr.split(',').map(s => s.trim());
}
addIfSet('assistant_id', 'assistant_id');
const vecDbItems = executeFunctions.getNodeParameter('vec_db_ids.vecDbItems', itemIndex, []);
if (vecDbItems.length > 0) {
payload.widget_config.vec_db_ids = vecDbItems.map(item => ({
id: item.id,
weight: item.weight,
}));
}
addIfSet('theme', 'theme');
addIfSet('theme_color', 'theme_color');
addIfSet('widget_headline_font_color', 'widget_headline_font_color');
addIfSet('transcript_color', 'transcript_color');
addIfSet('bubble_background_color', 'bubble_background_color');
addIfSet('bubble_font_color', 'bubble_font_color');
addIfSet('button_list_color', 'button_list_color');
addIfSet('button_list_font_color', 'button_list_font_color');
addIfSet('radiobox_border_color', 'radiobox_border_color');
addIfSet('active_radiobox_color', 'active_radiobox_color');
addIfSet('checkbox_border_color', 'checkbox_border_color');
addIfSet('active_checkbox_color', 'active_checkbox_color');
addIfSet('tile_button_background_color', 'tile_button_background_color');
addIfSet('tile_button_font_color', 'tile_button_font_color');
addIfSet('link_text_color', 'link_text_color');
addIfSet('loading_color', 'loading_color');
addIfSet('font_color', 'font_color');
addIfSet('links_color', 'links_color');
addIfSet('buttons_color', 'buttons_color');
addIfSet('buttons_font_color', 'buttons_font_color');
addIfSet('font', 'font');
addIfSet('headline_font_size', 'headline_font_size', 0);
addIfSet('headline_mobile_font_size', 'headline_mobile_font_size', 0);
addIfSet('bubble_font_size', 'bubble_font_size', 0);
addIfSet('headline_text', 'headline_text');
addIfSet('widget_placeholder', 'widget_placeholder');
addIfSet('widget_terms_of_use', 'widget_terms_of_use');
addIfSet('terms_of_service_link', 'terms_of_service_link');
addIfSet('widget_headline', 'widget_headline');
addIfSet('chat_history_text', 'chat_history_text');
addIfSet('icon', 'icon');
const removeIcon = executeFunctions.getNodeParameter('remove_icon', itemIndex, false);
if (removeIcon) {
payload.widget_config.remove_icon = 1;
}
addIfSet('background', 'background');
const removeBackground = executeFunctions.getNodeParameter('remove_background', itemIndex, false);
if (removeBackground) {
payload.widget_config.remove_background = 1;
}
// Handle files with FormData if any file set
const icon = executeFunctions.getNodeParameter('icon', itemIndex, '');
const background = executeFunctions.getNodeParameter('background', itemIndex, '');
const font = executeFunctions.getNodeParameter('font', itemIndex, '');
const hasFiles = icon || background || font;
if (hasFiles) {
const formData = new FormData();
// Append non-file fields
Object.keys(payload.widget_config).forEach(key => {
formData.append(`widget_config[${key}]`, payload.widget_config[key]);
});
if (icon)
formData.append('widget_config[icon]', icon);
if (background)
formData.append('widget_config[background]', background);
if (font)
formData.append('widget_config[font]', font);
// Use formData as body - n8n will automatically set content-type
const method = operation === 'create' ? 'POST' : 'PATCH';
let url;
if (operation === 'create') {
url = `${adminUrl}/widget_configs.json`;
}
else {
const widgetId = executeFunctions.getNodeParameter('widgetId', itemIndex);
url = `${adminUrl}/widget_configs/${widgetId}.json`;
}
const response = await executeFunctions.helpers.httpRequest({
method,
url,
body: formData,
headers,
});
return response;
}
else {
const method = operation === 'create' ? 'POST' : 'PATCH';
let url;
if (operation === 'create') {
url = `${adminUrl}/widget_configs.json`;
}
else {
const widgetId = executeFunctions.getNodeParameter('widgetId', itemIndex);
url = `${adminUrl}/widget_configs/${widgetId}.json`;
}
const response = await executeFunctions.helpers.httpRequest({
method,
url,
body: payload,
headers,
});
return response;
}
}
else if (operation === 'delete') {
const widgetId = executeFunctions.getNodeParameter('widgetId', itemIndex);
const response = await executeFunctions.helpers.httpRequest({
method: 'DELETE',
url: `${adminUrl}/widget_configs/${widgetId}.json`,
headers,
});
return { success: true, deletedId: widgetId };
}
throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), `Unknown widgets operation: ${operation}`);
}
//# sourceMappingURL=widgetsApi.js.map