n8n-nodes-warmr
Version:
n8n community node for Warmr integration
235 lines (234 loc) • 10.5 kB
JavaScript
"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.Pipelines = void 0;
const PipelinesService_1 = require("../services/PipelinesService");
class Pipelines {
constructor() {
this.description = {
displayName: "Warmr Pipelines",
name: "warmrPipelines",
group: ["transform"],
version: 1,
description: "Manage Warmr pipelines, stages, and stage contacts via the v1 API",
defaults: { name: "Warmr Pipelines", 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 Pipelines", value: "listPipelines" },
{ name: "Create Pipeline", value: "createPipeline" },
{ name: "Update Pipeline", value: "updatePipeline" },
{ name: "Delete Pipeline", value: "deletePipeline" },
{ name: "List Stages", value: "listStages" },
{ name: "Create Stage", value: "createStage" },
{ name: "Update Stage", value: "updateStage" },
{ name: "Delete Stage", value: "deleteStage" },
{ name: "Add Contacts to Stage", value: "addContacts" },
{ name: "Remove Contact from Stage", value: "removeContact" },
],
default: "listPipelines",
description: "Operation to perform",
},
// --- Pipeline UUID ---
{
displayName: "Pipeline UUID",
name: "pipelineUuid",
type: "string",
default: "",
required: true,
displayOptions: {
show: {
operation: [
"updatePipeline", "deletePipeline",
"listStages", "createStage",
],
},
},
description: "UUID of the pipeline",
},
// --- Pipeline fields ---
{
displayName: "Name",
name: "name",
type: "string",
default: "",
displayOptions: {
show: { operation: ["createPipeline", "updatePipeline", "createStage", "updateStage"] },
},
description: "Pipeline or stage name",
},
{
displayName: "Visibility",
name: "visibility",
type: "options",
options: [
{ name: "Private", value: "private" },
{ name: "Team", value: "team" },
],
default: "private",
displayOptions: { show: { operation: ["createPipeline", "updatePipeline"] } },
description: "Pipeline visibility",
},
{
displayName: "Icon",
name: "icon",
type: "string",
default: "",
displayOptions: {
show: { operation: ["createPipeline", "updatePipeline", "createStage", "updateStage"] },
},
},
// --- Stage UUID ---
{
displayName: "Stage UUID",
name: "stageUuid",
type: "string",
default: "",
required: true,
displayOptions: {
show: { operation: ["updateStage", "deleteStage", "addContacts", "removeContact"] },
},
description: "UUID of the pipeline stage",
},
// --- Stage order ---
{
displayName: "Order",
name: "order",
type: "number",
default: 0,
displayOptions: { show: { operation: ["createStage", "updateStage"] } },
description: "Position of the stage in the pipeline",
},
// --- Stage contacts ---
{
displayName: "Contact UUIDs",
name: "contactUuids",
type: "string",
default: "",
required: true,
displayOptions: { show: { operation: ["addContacts"] } },
description: "Comma-separated contact UUIDs to add to the stage",
},
{
displayName: "Contact UUID",
name: "contactUuid",
type: "string",
default: "",
required: true,
displayOptions: { show: { operation: ["removeContact"] } },
description: "UUID of the contact to remove from the stage",
},
],
};
}
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 {
const result = yield executePipelineOperation.call(this, i, operation, credentials.apiKey);
returnData.push({ json: result });
}
catch (error) {
returnData.push({ json: { error: error.message } });
}
}
return this.prepareOutputData(returnData);
});
}
}
exports.Pipelines = Pipelines;
function executePipelineOperation(i, operation, apiKey) {
return __awaiter(this, void 0, void 0, function* () {
if (operation === "listPipelines") {
const pipelines = yield PipelinesService_1.PipelinesService.listPipelines(apiKey);
return { data: pipelines };
}
if (operation === "createPipeline") {
return PipelinesService_1.PipelinesService.createPipeline(buildPipelineInput.call(this, i), apiKey);
}
if (operation === "updatePipeline") {
const uuid = this.getNodeParameter("pipelineUuid", i);
return PipelinesService_1.PipelinesService.updatePipeline(uuid, buildPipelineInput.call(this, i), apiKey);
}
if (operation === "deletePipeline") {
const uuid = this.getNodeParameter("pipelineUuid", i);
yield PipelinesService_1.PipelinesService.deletePipeline(uuid, apiKey);
return { success: true, uuid };
}
if (operation === "listStages") {
const uuid = this.getNodeParameter("pipelineUuid", i);
const stages = yield PipelinesService_1.PipelinesService.listStages(uuid, apiKey);
return { data: stages };
}
if (operation === "createStage") {
const uuid = this.getNodeParameter("pipelineUuid", i);
return PipelinesService_1.PipelinesService.createStage(uuid, buildStageInput.call(this, i), apiKey);
}
if (operation === "updateStage") {
const stageUuid = this.getNodeParameter("stageUuid", i);
return PipelinesService_1.PipelinesService.updateStage(stageUuid, buildStageInput.call(this, i), apiKey);
}
if (operation === "deleteStage") {
const stageUuid = this.getNodeParameter("stageUuid", i);
yield PipelinesService_1.PipelinesService.deleteStage(stageUuid, apiKey);
return { success: true, stageUuid };
}
if (operation === "addContacts") {
const stageUuid = this.getNodeParameter("stageUuid", i);
const raw = this.getNodeParameter("contactUuids", i);
const contactUuids = raw.split(",").map((s) => s.trim()).filter(Boolean);
return PipelinesService_1.PipelinesService.addContactsToStage(stageUuid, contactUuids, apiKey);
}
// removeContact
const stageUuid = this.getNodeParameter("stageUuid", i);
const contactUuid = this.getNodeParameter("contactUuid", i);
yield PipelinesService_1.PipelinesService.removeContactFromStage(stageUuid, contactUuid, apiKey);
return { success: true, stageUuid, contactUuid };
});
}
function buildPipelineInput(i) {
const name = this.getNodeParameter("name", i, "");
const visibility = this.getNodeParameter("visibility", i, "private");
const icon = this.getNodeParameter("icon", i, "");
const data = {};
if (name)
data.name = name;
if (visibility)
data.visibility = visibility;
if (icon)
data.icon = icon;
return data;
}
function buildStageInput(i) {
const name = this.getNodeParameter("name", i, "");
const icon = this.getNodeParameter("icon", i, "");
const order = this.getNodeParameter("order", i, 0);
const data = {};
if (name)
data.name = name;
if (icon)
data.icon = icon;
if (order)
data.order = order;
return data;
}
exports.default = Pipelines;