UNPKG

n8n-nodes-warmr

Version:
199 lines (198 loc) 9.26 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Lists = void 0; const ListsService_1 = require("../services/ListsService"); class Lists { constructor() { this.description = { displayName: "Warmr Lists", name: "warmrLists", group: ["transform"], version: 1, description: "Manage Warmr lists and list membership via the v1 API", defaults: { name: "Warmr Lists", color: "#e4d103" }, icon: "file:icon.png", inputs: ["main"], outputs: ["main"], credentials: [{ name: "warmrApi", required: true }], properties: [ { displayName: "Operation", name: "operation", type: "options", options: [ { name: "List All Lists", value: "listLists" }, { name: "Get List", value: "getList" }, { name: "Create List", value: "createList" }, { name: "Update List", value: "updateList" }, { name: "Delete List", value: "deleteList" }, { name: "Add Contacts to List", value: "addContacts" }, { name: "Remove Contact from List", value: "removeContact" }, ], default: "listLists", description: "Operation to perform", }, // --- Pagination --- { displayName: "Page", name: "page", type: "number", default: 1, displayOptions: { show: { operation: ["listLists"] } }, }, { displayName: "Per Page", name: "perPage", type: "number", default: 50, displayOptions: { show: { operation: ["listLists"] } }, description: "Results per page (max 100)", }, // --- List UUID --- { displayName: "List UUID", name: "listUuid", type: "string", default: "", required: true, displayOptions: { show: { operation: [ "getList", "updateList", "deleteList", "addContacts", "removeContact", ], }, }, description: "UUID of the list", }, // --- Create / Update fields --- { displayName: "Name", name: "name", type: "string", default: "", displayOptions: { show: { operation: ["createList", "updateList"] } }, description: "List name (required for create, 1-255 chars)", }, { displayName: "Description", name: "description", type: "string", default: "", displayOptions: { show: { operation: ["createList", "updateList"] } }, }, { displayName: "Icon", name: "icon", type: "string", default: "", displayOptions: { show: { operation: ["createList", "updateList"] } }, }, // --- Membership --- { displayName: "Contact UUIDs", name: "contactUuids", type: "string", default: "", required: true, displayOptions: { show: { operation: ["addContacts"] } }, description: "Comma-separated contact UUIDs to add", }, { displayName: "Contact UUID", name: "contactUuid", type: "string", default: "", required: true, displayOptions: { show: { operation: ["removeContact"] } }, description: "UUID of the contact to remove from the list", }, ], }; } execute() { return __awaiter(this, void 0, void 0, function* () { const items = this.getInputData(); const returnData = []; const credentials = (yield this.getCredentials("warmrApi")); for (let i = 0; i < items.length; i++) { const operation = this.getNodeParameter("operation", i); try { if (operation === "listLists") { const query = {}; const page = this.getNodeParameter("page", i); const perPage = this.getNodeParameter("perPage", i); if (page) query.page = page; if (perPage) query.per_page = perPage; const result = yield ListsService_1.ListsService.getLists(query, credentials.apiKey); returnData.push({ json: result }); } else if (operation === "getList") { const uuid = this.getNodeParameter("listUuid", i); const list = yield ListsService_1.ListsService.getList(uuid, credentials.apiKey); returnData.push({ json: list }); } else if (operation === "createList") { const data = buildListInput.call(this, i); const list = yield ListsService_1.ListsService.createList(data, credentials.apiKey); returnData.push({ json: list }); } else if (operation === "updateList") { const uuid = this.getNodeParameter("listUuid", i); const data = buildListInput.call(this, i); const list = yield ListsService_1.ListsService.updateList(uuid, data, credentials.apiKey); returnData.push({ json: list }); } else if (operation === "deleteList") { const uuid = this.getNodeParameter("listUuid", i); yield ListsService_1.ListsService.deleteList(uuid, credentials.apiKey); returnData.push({ json: { success: true, uuid } }); } else if (operation === "addContacts") { const listUuid = this.getNodeParameter("listUuid", i); const raw = this.getNodeParameter("contactUuids", i); const contactUuids = raw.split(",").map((s) => s.trim()).filter(Boolean); const result = yield ListsService_1.ListsService.addContacts(listUuid, contactUuids, credentials.apiKey); returnData.push({ json: result }); } else if (operation === "removeContact") { const listUuid = this.getNodeParameter("listUuid", i); const contactUuid = this.getNodeParameter("contactUuid", i); yield ListsService_1.ListsService.removeContact(listUuid, contactUuid, credentials.apiKey); returnData.push({ json: { success: true, listUuid, contactUuid } }); } } catch (error) { returnData.push({ json: { error: error.message } }); } } return this.prepareOutputData(returnData); }); } } exports.Lists = Lists; function buildListInput(i) { const name = this.getNodeParameter("name", i, ""); const description = this.getNodeParameter("description", i, ""); const icon = this.getNodeParameter("icon", i, ""); const data = {}; if (name) data.name = name; if (description) data.description = description; if (icon) data.icon = icon; return data; } exports.default = Lists;