UNPKG

@kaia-team/n8n-nodes-kaia

Version:
129 lines 4.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.documentShardsApiProperties = void 0; exports.handleDocumentShardsApi = handleDocumentShardsApi; const n8n_workflow_1 = require("n8n-workflow"); const utils_1 = require("../utils"); /** * Document Shards API Properties * Properties specific to the documentShards API resource */ exports.documentShardsApiProperties = [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['documentShards'], }, }, options: [ { name: 'List', value: 'list', action: 'List document shards', }, { name: 'Read', value: 'read', action: 'Read a document shard', }, ], default: 'list', }, { displayName: 'Document ID', name: 'document_id', type: 'string', default: '', displayOptions: { show: { resource: ['documentShards'], operation: ['list'], }, }, description: 'Filter shards by document ID', }, { displayName: 'Page', name: 'page', type: 'number', default: 1, displayOptions: { show: { resource: ['documentShards'], operation: ['list'], }, }, description: 'Page number for pagination', }, { displayName: 'Per Page', name: 'per_page', type: 'number', default: 100, displayOptions: { show: { resource: ['documentShards'], operation: ['list'], }, }, description: 'Number of items per page', }, { displayName: 'Document Shard ID', name: 'document_shard_id', type: 'string', default: '', displayOptions: { show: { resource: ['documentShards'], operation: ['read'], }, }, description: 'The ID of the document shard', required: true, }, ]; /** * Document Shards API Handler * Handles requests to the documentShards API */ async function handleDocumentShardsApi(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 qs = {}; const documentId = executeFunctions.getNodeParameter('document_id', itemIndex, ''); if (documentId) qs.document_id = documentId; const page = executeFunctions.getNodeParameter('page', itemIndex, 1); if (page) qs.page = page; const perPage = executeFunctions.getNodeParameter('per_page', itemIndex, 100); if (perPage) qs.per_page = perPage; const response = await executeFunctions.helpers.httpRequest({ method: 'GET', url: `${adminUrl}/document_shards.json`, headers, qs, }); return executeFunctions.helpers.returnJsonArray(response); } else if (operation === 'read') { let documentShardId = executeFunctions.getNodeParameter('document_shard_id', itemIndex); documentShardId = (0, utils_1.extractIdFromUrlOrId)(documentShardId, 'document_shards'); const response = await executeFunctions.helpers.httpRequest({ method: 'GET', url: `${adminUrl}/document_shards/${documentShardId}.json`, headers, }); return response; } throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), `Unknown document shards operation: ${operation}`); } //# sourceMappingURL=documentShardsApi.js.map