@kaia-team/n8n-nodes-kaia
Version:
n8n nodes for Kaia LLM integration
445 lines • 15.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.feedsApiProperties = void 0;
exports.handleFeedsApi = handleFeedsApi;
const n8n_workflow_1 = require("n8n-workflow");
const utils_1 = require("../utils");
/**
* Feeds API Properties
* Properties specific to the feeds API resource (feed processing)
*/
exports.feedsApiProperties = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: ['feeds'],
},
},
options: [
{
name: 'Create',
value: 'create',
action: 'Create a feed',
},
{
name: 'Delete',
value: 'delete',
action: 'Delete a feed',
},
{
name: 'List',
value: 'list',
action: 'List feeds',
},
{
name: 'Process Feed',
value: 'processFeed',
action: 'Process a feed',
},
{
name: 'Read',
value: 'read',
action: 'Read a feed',
},
{
name: 'Try Source',
value: 'trySource',
action: 'Try feed source',
},
{
name: 'Try Step',
value: 'tryStep',
action: 'Try feed step',
},
{
name: 'Update',
value: 'update',
action: 'Update a feed',
},
],
default: 'list',
},
{
displayName: 'Feed ID',
name: 'feedId',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['feeds'],
operation: ['read', 'update', 'delete', 'processFeed', 'trySource', 'tryStep', 'contents'],
},
},
description: 'The ID of the feed',
required: true,
},
{
displayName: 'Step ID',
name: 'step_id',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['feeds'],
operation: ['tryStep'],
},
},
description: 'The ID of the step to try',
required: true,
},
{
displayName: 'Active',
name: 'active',
type: 'boolean',
default: true,
displayOptions: {
show: {
resource: ['feeds'],
operation: ['create', 'update'],
},
},
description: 'Whether the feed is active',
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
displayOptions: {
show: {
resource: ['feeds'],
operation: ['create', 'update'],
},
},
description: 'Name of the feed',
},
{
displayName: 'Processing Frequency',
name: 'processing_frequency',
type: 'options',
default: 'daily',
options: [
{
name: 'Hourly',
value: 'hourly',
},
{
name: 'Daily',
value: 'daily',
},
{
name: 'Weekly',
value: 'weekly',
},
],
displayOptions: {
show: {
resource: ['feeds'],
operation: ['create', 'update'],
},
},
description: 'Processing frequency for the feed',
},
{
displayName: 'Feed Source Attributes',
name: 'feed_source_attributes',
type: 'fixedCollection',
typeOptions: {
multipleValues: false,
},
default: {},
placeholder: 'Add Source Attributes',
displayOptions: {
show: {
resource: ['feeds'],
operation: ['create', 'update'],
},
},
options: [
{
name: 'source',
displayName: 'Source',
values: [
{
displayName: 'URL',
name: 'url',
type: 'string',
default: '',
description: 'Source URL',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
options: [
{
name: 'Atom',
value: 'atom',
},
{
name: 'RSS',
value: 'rss',
},
],
default: 'rss',
description: 'Source type',
},
],
},
],
},
{
displayName: 'Feed Steps Attributes',
name: 'feed_steps_attributes',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
placeholder: 'Add Step',
displayOptions: {
show: {
resource: ['feeds'],
operation: ['create', 'update'],
},
},
options: [
{
name: 'steps',
displayName: 'Steps',
values: [
{
displayName: 'Categories',
name: 'config_fields',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
placeholder: 'Add Config Field',
options: [
{
name: 'Categories',
value: 'categories',
type: 'string',
default: 'category',
description: 'Categories to filter for (comma-separated)',
},
],
},
{
displayName: 'Keywords',
name: 'config_fields',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
placeholder: 'Add Config Field',
options: [
{
name: 'Keywords',
value: 'keywords',
type: 'string',
default: '',
description: 'Keywords to filter for (comma-separated)',
},
{
name: 'Fields',
value: 'fields',
type: 'string',
default: 'title,description',
description: 'Fields to search for (comma-separated)',
},
],
},
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
description: 'Step name',
},
{
displayName: 'Position',
name: 'position',
type: 'number',
default: 1,
required: true,
description: 'Step position',
},
{
displayName: 'Type',
name: 'type',
type: 'options',
options: [
{
name: 'Create Content',
value: 'create_content',
},
{
name: 'Deduplication',
value: 'deduplication',
},
{
name: 'Filter by Category',
value: 'filter_by_category',
},
{
name: 'Filter by Keywords',
value: 'filter_by_keywords',
},
{
name: 'Jina Content Fetch',
value: 'jina_fetch',
},
{
name: 'Save GUID',
value: 'save_guid',
},
],
default: 'deduplication',
description: 'Step type',
},
],
},
],
},
];
/**
* Feeds API Handler
* Handles requests to the feeds API (feed processing)
*/
async function handleFeedsApi(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}/feeds.json`,
headers,
});
return executeFunctions.helpers.returnJsonArray(response);
}
else if (operation === 'read') {
let feedId = executeFunctions.getNodeParameter('feedId', itemIndex);
feedId = (0, utils_1.extractIdFromUrlOrId)(feedId, 'feeds');
const response = await executeFunctions.helpers.httpRequest({
method: 'GET',
url: `${adminUrl}/feeds/${feedId}.json`,
headers,
});
return response;
}
else if (operation === 'create' || operation === 'update') {
const payload = { feed: {} };
const addIfSet = (key, param, defaultVal = '') => {
const val = executeFunctions.getNodeParameter(param, itemIndex, defaultVal);
if (val !== defaultVal && (typeof val !== 'string' || val.trim() !== '')) {
payload.feed[key] = val;
}
};
// Always set active
payload.feed.active = executeFunctions.getNodeParameter('active', itemIndex, true);
addIfSet('name', 'name');
addIfSet('processing_frequency', 'processing_frequency');
const source = executeFunctions.getNodeParameter('feed_source_attributes.source', itemIndex, {});
if (Object.keys(source).length > 0) {
payload.feed.feed_source_attributes = {
url: source.url,
type: source.type,
};
}
const steps = executeFunctions.getNodeParameter('feed_steps_attributes.steps', itemIndex, []);
if (steps.length > 0) {
payload.feed.feed_steps_attributes = steps.map((step) => ({
type: step.type,
name: step.name,
position: step.position,
}));
}
const method = operation === 'create' ? 'post' : 'patch';
let url;
if (operation === 'create') {
url = `${adminUrl}/feeds.json`;
}
else {
let feedId = executeFunctions.getNodeParameter('feedId', itemIndex);
feedId = (0, utils_1.extractIdFromUrlOrId)(feedId, 'feeds');
url = `${adminUrl}/feeds/${feedId}.json`;
}
const response = await executeFunctions.helpers.httpRequest({
method: method.toUpperCase(),
url,
body: payload,
headers,
});
return response;
}
else if (operation === 'processFeed') {
let feedId = executeFunctions.getNodeParameter('feedId', itemIndex);
feedId = (0, utils_1.extractIdFromUrlOrId)(feedId, 'feeds');
const response = await executeFunctions.helpers.httpRequest({
method: 'POST',
url: `${adminUrl}/feeds/${feedId}/process_feed.json`,
body: {},
headers,
});
return response;
}
else if (operation === 'trySource') {
let feedId = executeFunctions.getNodeParameter('feedId', itemIndex);
feedId = (0, utils_1.extractIdFromUrlOrId)(feedId, 'feeds');
const response = await executeFunctions.helpers.httpRequest({
method: 'POST',
url: `${adminUrl}/feeds/${feedId}/try_source.json`,
body: {},
headers,
});
return response;
}
else if (operation === 'tryStep') {
let feedId = executeFunctions.getNodeParameter('feedId', itemIndex);
feedId = (0, utils_1.extractIdFromUrlOrId)(feedId, 'feeds');
const stepId = executeFunctions.getNodeParameter('step_id', itemIndex);
const qs = { step_id: stepId };
const response = await executeFunctions.helpers.httpRequest({
method: 'POST',
url: `${adminUrl}/feeds/${feedId}/try_step.json`,
body: {},
headers,
qs,
});
return response;
}
else if (operation === 'contents') {
const qs = {};
const feedIdParam = executeFunctions.getNodeParameter('feedId', itemIndex, ''); // optional
if (feedIdParam)
qs.feed_id = feedIdParam;
const response = await executeFunctions.helpers.httpRequest({
method: 'GET',
url: `${adminUrl}/contents.json`,
headers,
qs,
});
return executeFunctions.helpers.returnJsonArray(response);
}
else if (operation === 'delete') {
let feedId = executeFunctions.getNodeParameter('feedId', itemIndex);
feedId = (0, utils_1.extractIdFromUrlOrId)(feedId, 'feeds');
const response = await executeFunctions.helpers.httpRequest({
method: 'DELETE',
url: `${adminUrl}/feeds/${feedId}.json`,
headers,
});
return { success: true, deletedId: feedId };
}
throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), `Unknown feeds operation: ${operation}`);
}
//# sourceMappingURL=feedsApi.js.map