UNPKG

@kaia-team/n8n-nodes-kaia

Version:
85 lines 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.statisticsApiProperties = void 0; exports.handleStatisticsApi = handleStatisticsApi; const n8n_workflow_1 = require("n8n-workflow"); const utils_1 = require("../utils"); /** * Statistics API Properties * Properties specific to the statistics API resource */ exports.statisticsApiProperties = [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['statistics'], }, }, options: [ { name: 'Read', value: 'read', description: 'Get statistics', action: 'Get statistics', }, ], default: 'read', }, { displayName: 'Start Date', name: 'start_date', type: 'dateTime', default: '', displayOptions: { show: { resource: ['statistics'], operation: ['read'], }, }, description: 'Start date (e.g., 2025-06-01)', }, { displayName: 'End Date', name: 'end_date', type: 'dateTime', default: '', displayOptions: { show: { resource: ['statistics'], operation: ['read'], }, }, description: 'End date (e.g., 2025-07-10)', }, ]; /** * Statistics API Handler * Handles requests to the statistics API */ async function handleStatisticsApi(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 === 'read') { const qs = {}; const startDate = executeFunctions.getNodeParameter('start_date', itemIndex, ''); if (startDate) qs.start_date = startDate; const endDate = executeFunctions.getNodeParameter('end_date', itemIndex, ''); if (endDate) qs.end_date = endDate; const response = await executeFunctions.helpers.httpRequest({ method: 'GET', url: `${adminUrl}/statistics.json`, headers, qs, }); return executeFunctions.helpers.returnJsonArray(response); } throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), `Unknown statistics operation: ${operation}`); } //# sourceMappingURL=statisticsApi.js.map