UNPKG

@kadam-net/n8n-nodes-kadam

Version:

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

67 lines 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractResponseItems = extractResponseItems; exports.getValueByPath = getValueByPath; exports.setValueByPath = setValueByPath; exports.processOutputFields = processOutputFields; function extractResponseItems(response) { var _a; if (Array.isArray(response)) { return response; } if (((_a = response === null || response === void 0 ? void 0 : response.response) === null || _a === void 0 ? void 0 : _a.items) && Array.isArray(response.response.items)) { return response.response.items; } if ((response === null || response === void 0 ? void 0 : response.items) && Array.isArray(response.items)) { return response.items; } if (response && typeof response === 'object' && !Array.isArray(response)) { return [response]; } return []; } function getValueByPath(obj, path) { const keys = path.split('.'); let current = obj; for (const key of keys) { if (current === null || typeof current !== 'object' || !Object.prototype.hasOwnProperty.call(current, key)) { return undefined; } current = current[key]; } return current; } function setValueByPath(obj, path, value) { const keys = path.split('.'); let current = obj; for (let i = 0; i < keys.length - 1; i++) { const key = keys[i]; if (current[key] === undefined || typeof current[key] !== 'object' || current[key] === null) { current[key] = {}; } current = current[key]; } const finalKey = keys[keys.length - 1]; current[finalKey] = value; } function processOutputFields(dataItems, outputFieldsRaw) { const fieldsToKeep = outputFieldsRaw .split(',') .map((f) => f.trim()) .filter((f) => f); if (fieldsToKeep.length > 0) { const filteredItems = dataItems.map((item) => { const filteredItem = {}; for (const path of fieldsToKeep) { const value = getValueByPath(item, path); if (value !== undefined) { setValueByPath(filteredItem, path, value); } } return filteredItem; }); return filteredItems.map((item) => ({ json: item })); } return dataItems.map((item) => ({ json: item })); } //# sourceMappingURL=utils.helpers.js.map