UNPKG

@kadam-net/n8n-nodes-kadam

Version:

Kadam node for n8n to manage campaigns, creatives, and more.

195 lines 11.9 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeStatsOperation = executeStatsOperation; exports.executeCampaignOperation = executeCampaignOperation; exports.executeTargetingOperation = executeTargetingOperation; exports.executeClientOperation = executeClientOperation; exports.executeCreativeOperation = executeCreativeOperation; exports.getApiVersion = getApiVersion; const n8n_workflow_1 = require("n8n-workflow"); const axios_1 = __importDefault(require("axios")); const stats_1 = require("./operations/stats"); const campaigns_1 = require("./operations/campaigns"); const targeting_1 = require("./operations/targeting"); const clients_1 = require("./operations/clients"); const creatives_1 = require("./operations/creatives"); async function executeStatsOperation(operation, context) { const { execFns, itemIndex, baseUrl, headers, appId } = context; try { execFns.logger.debug(`Executing stats operation: ${operation}`); switch (operation) { case 'getCampaignStats': return await stats_1.getCampaignStats.call(execFns, itemIndex, baseUrl, headers, appId); case 'getPlacementStats': return await stats_1.getPlacementStats.call(execFns, itemIndex, baseUrl, headers, appId); case 'getCreativeStatsByCampaignIds': return await stats_1.getCreativeStatsByCampaignIds.call(execFns, itemIndex, baseUrl, headers, appId); case 'getCreativeStatsByCreativeIds': return await stats_1.getCreativeStatsByCreativeIds.call(execFns, itemIndex, baseUrl, headers, appId); default: throw new n8n_workflow_1.NodeOperationError(execFns.getNode(), `Unsupported stats operation: ${operation}`, { description: 'Please check available operations in the node documentation' }); } } catch (error) { throw new n8n_workflow_1.NodeOperationError(execFns.getNode(), `Error executing stats operation [${operation}]: ${error.message}`, { itemIndex }); } } async function executeCampaignOperation(operation, context) { const { execFns, itemIndex, baseUrl, headers, appId } = context; try { execFns.logger.debug(`Executing campaign operation: ${operation}`); switch (operation) { case 'createCampaign': execFns.logger.debug(`executeCampaignOperation: Calling createCampaign for item ${itemIndex}`); return await campaigns_1.createCampaign.call(execFns); case 'updateCampaign': return await campaigns_1.updateCampaign.call(execFns); case 'getCampaigns': execFns.logger.debug(`executeCampaignOperation: Calling getCampaigns for item ${itemIndex}`); return await campaigns_1.getCampaigns.call(execFns, itemIndex, baseUrl, headers, appId); case 'deleteCampaign': return await campaigns_1.deleteCampaign.call(execFns); case 'getCampaignCategories': return await campaigns_1.getCampaignCategories.call(execFns, itemIndex, baseUrl, headers, appId); case 'getAdFormats': return await campaigns_1.getAdFormats.call(execFns, itemIndex, baseUrl, headers, appId); case 'updatePlacementMultiplier': return await campaigns_1.updatePlacementMultiplier.call(execFns, itemIndex, baseUrl, headers, appId); default: throw new n8n_workflow_1.NodeOperationError(execFns.getNode(), `Unsupported campaign operation: ${operation}`, { description: 'Please check available operations in the node documentation' }); } } catch (error) { throw new n8n_workflow_1.NodeOperationError(execFns.getNode(), `Error executing campaign operation [${operation}]: ${error.message}`, { itemIndex }); } } async function executeTargetingOperation(operation, context) { const { execFns, itemIndex, baseUrl, headers, appId } = context; try { execFns.logger.debug(`Executing targeting operation: ${operation}`); switch (operation) { case 'getPlatforms': const platformsFieldsStr = execFns.getNodeParameter('includeFields', itemIndex, ''); const platformsFilterFields = platformsFieldsStr ? platformsFieldsStr.split(',').map(field => field.trim()).filter(Boolean) : []; return await targeting_1.getPlatforms.call(execFns, itemIndex, baseUrl, headers, appId, platformsFilterFields); case 'getBrowsers': const browsersFieldsStr = execFns.getNodeParameter('includeFields', itemIndex, ''); const browsersFilterFields = browsersFieldsStr ? browsersFieldsStr.split(',').map(field => field.trim()).filter(Boolean) : []; return await targeting_1.getBrowsers.call(execFns, itemIndex, baseUrl, headers, appId, browsersFilterFields); case 'getCpaModes': return await targeting_1.getCpaModes.call(execFns, itemIndex, baseUrl, headers, appId); case 'getAges': return await targeting_1.getAges.call(execFns, itemIndex, baseUrl, headers, appId); case 'getCountries': const includeFieldsStr = execFns.getNodeParameter('includeFields', itemIndex, ''); const filterFields = includeFieldsStr ? includeFieldsStr.split(',').map(field => field.trim()).filter(Boolean) : []; return await targeting_1.getCountries.call(execFns, itemIndex, baseUrl, headers, appId, filterFields); case 'getRegions': return await targeting_1.getRegions.call(execFns, itemIndex, baseUrl, headers, appId); case 'getCities': return await targeting_1.getCities.call(execFns, itemIndex, baseUrl, headers, appId); case 'getDevices': const devicesFieldsStr = execFns.getNodeParameter('includeFields', itemIndex, ''); const devicesFilterFields = devicesFieldsStr ? devicesFieldsStr.split(',').map(field => field.trim()).filter(Boolean) : []; return await targeting_1.getDevices.call(execFns, itemIndex, baseUrl, headers, appId, devicesFilterFields); case 'getLanguages': const languagesFieldsStr = execFns.getNodeParameter('includeFields', itemIndex, ''); const languagesFilterFields = languagesFieldsStr ? languagesFieldsStr.split(',').map(field => field.trim()).filter(Boolean) : []; return await targeting_1.getLanguages.call(execFns, itemIndex, baseUrl, headers, appId, languagesFilterFields); case 'getServerTime': return await targeting_1.getServerTime.call(execFns, itemIndex, baseUrl, headers, appId); case 'getPaymentSystems': return await targeting_1.getPaymentSystems.call(execFns, itemIndex, baseUrl, headers, appId); case 'getGeoCountries': const geoCountriesFieldsStr = execFns.getNodeParameter('includeFields', itemIndex, ''); const geoCountriesFilterFields = geoCountriesFieldsStr ? geoCountriesFieldsStr.split(',').map(field => field.trim()).filter(Boolean) : []; return await targeting_1.getGeoCountries.call(execFns, itemIndex, baseUrl, headers, appId, geoCountriesFilterFields); case 'getGeoRegions': return await axios_1.default.get(`${baseUrl}/data.geo.regions.get`, { headers, params: { app_id: appId, country_id: execFns.getNodeParameter('countryId', itemIndex) }, }); default: throw new n8n_workflow_1.NodeOperationError(execFns.getNode(), `Unsupported targeting operation: ${operation}`, { description: 'Please check available operations in the node documentation' }); } } catch (error) { throw new n8n_workflow_1.NodeOperationError(execFns.getNode(), `Error executing targeting operation [${operation}]: ${error.message}`, { itemIndex }); } } async function executeClientOperation(operation, context) { const { execFns, itemIndex, baseUrl, headers, appId } = context; try { execFns.logger.debug(`Executing client operation: ${operation}`); switch (operation) { case 'createClient': return await clients_1.createClient.call(execFns, itemIndex, baseUrl, headers, appId); case 'updateClient': return await clients_1.updateClient.call(execFns, itemIndex, baseUrl, headers, appId); case 'getClients': return await clients_1.getClients.call(execFns, itemIndex, baseUrl, headers, appId); case 'deleteClient': return await clients_1.deleteClient.call(execFns, itemIndex, baseUrl, headers, appId); case 'bindClient': return await clients_1.bindClient.call(execFns, itemIndex, baseUrl, headers, appId); case 'unbindClient': return await clients_1.unbindClient.call(execFns, itemIndex, baseUrl, headers, appId); case 'depositClientBalance': return await clients_1.depositClientBalance.call(execFns, itemIndex, baseUrl, headers, appId); case 'transferFunds': return await clients_1.transferFunds.call(execFns, itemIndex, baseUrl, headers, appId); default: throw new n8n_workflow_1.NodeOperationError(execFns.getNode(), `Unsupported client operation: ${operation}`, { description: 'Please check available operations in the node documentation' }); } } catch (error) { throw new n8n_workflow_1.NodeOperationError(execFns.getNode(), `Error executing client operation [${operation}]: ${error.message}`, { itemIndex }); } } async function executeCreativeOperation(operation, context) { const { execFns, itemIndex, baseUrl, headers, appId } = context; try { execFns.logger.debug(`Executing creative operation: ${operation}`); switch (operation) { case 'createCreative': return await creatives_1.createCreative.call(execFns, itemIndex, baseUrl, headers, appId); case 'updateCreative': return await creatives_1.updateCreative.call(execFns, itemIndex, baseUrl, headers, appId); case 'deleteCreative': return await creatives_1.deleteCreative.call(execFns, itemIndex, baseUrl, headers, appId); case 'getCreatives': return await creatives_1.getCreatives.call(execFns, itemIndex, baseUrl, headers, appId); case 'getBannerSizes': return await creatives_1.getBannerSizes.call(execFns, itemIndex, baseUrl, headers, appId); case 'uploadMedia': return await creatives_1.uploadMedia.call(execFns, itemIndex, baseUrl, headers, appId); default: throw new n8n_workflow_1.NodeOperationError(execFns.getNode(), `Unsupported creative operation: ${operation}`, { description: 'Please check available operations in the node documentation' }); } } catch (error) { throw new n8n_workflow_1.NodeOperationError(execFns.getNode(), `Error executing creative operation [${operation}]: ${error.message}`, { itemIndex }); } } function getApiVersion() { return 'v1.4.x'; } //# sourceMappingURL=handlers.js.map