n8n-nodes-warmr
Version:
n8n community node for Warmr integration
204 lines (203 loc) • 9.48 kB
JavaScript
;
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.Contacts = void 0;
const ContactsService_1 = require("../services/ContactsService");
class Contacts {
constructor() {
this.description = {
displayName: "Warmr Contacts",
name: "contacts",
group: ["transform"],
version: 1,
description: "Manage Warmr contacts",
defaults: {
name: "Warmr Contacts",
color: "#e4d103",
},
icon: "file:icon.png",
inputs: ["main"],
outputs: ["main"],
credentials: [
{
name: "warmrApi",
required: true,
},
],
properties: [
{
displayName: "Operation",
name: "operation",
type: "options",
options: [
{ name: "Get Contacts", value: "getContacts" },
{ name: "Create Contact", value: "createContact" },
{ name: "Update Contact", value: "updateContact" },
{ name: "Delete Contact", value: "deleteContact" },
],
default: "getContacts",
description: "Operation to perform",
},
// Add additional fields for each operation below
{
displayName: "List UUID",
name: "listUuid",
type: "string",
default: "",
displayOptions: {
show: { operation: ["getContacts"] },
},
description: "Filter contacts by list UUID",
},
{
displayName: "UUID",
name: "uuid",
type: "string",
default: "",
displayOptions: {
show: { operation: ["getContacts"] },
},
description: "Filter by contact UUID",
},
{
displayName: "Sort Key",
name: "sortKey",
type: "string",
default: "",
displayOptions: {
show: { operation: ["getContacts"] },
},
description: "Field to sort by",
},
{
displayName: "Sort Direction",
name: "sortDirection",
type: "options",
options: [
{ name: "Ascending", value: "asc" },
{ name: "Descending", value: "desc" },
],
default: "asc",
displayOptions: {
show: { operation: ["getContacts"] },
},
description: "Sort direction",
},
{
displayName: "Filters (Advanced)",
name: "filters",
type: "string",
default: "",
displayOptions: {
show: { operation: ["getContacts"] },
},
description: "Advanced filter string",
},
{
displayName: "Contact Data",
name: "contactData",
type: "json",
default: "{}",
displayOptions: {
show: { operation: ["createContact", "updateContact"] },
},
description: "Contact data as JSON",
},
{
displayName: "Identifier",
name: "identifier",
type: "json",
default: "{}",
displayOptions: {
show: { operation: ["updateContact", "deleteContact"] },
},
description: "Identifier (uuid, linkedin_id, or email) as JSON",
},
],
};
}
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 === "getContacts") {
const filters = {};
// Build filters object from individual fields
const listUuid = this.getNodeParameter("listUuid", i);
if (listUuid)
filters.listUuid = listUuid;
const pipelineStageUuid = this.getNodeParameter("pipelineStageUuid", i);
if (pipelineStageUuid)
filters.pipelineStageUuid = pipelineStageUuid;
const uuid = this.getNodeParameter("uuid", i);
if (uuid)
filters.uuid = uuid;
const entityUrn = this.getNodeParameter("entityUrn", i);
if (entityUrn)
filters.entityUrn = entityUrn;
const objectUrn = this.getNodeParameter("objectUrn", i);
if (objectUrn)
filters.objectUrn = objectUrn;
const archived = this.getNodeParameter("archived", i);
filters.archived = archived;
const sortKey = this.getNodeParameter("sortKey", i);
if (sortKey)
filters.sortKey = sortKey;
const sortDirection = this.getNodeParameter("sortDirection", i);
if (sortDirection)
filters.sortDirection = sortDirection;
const advancedFilters = this.getNodeParameter("filters", i, "");
if (advancedFilters)
filters.filters = advancedFilters;
const raw = this.getNodeParameter("raw", i);
filters.raw = raw;
const contacts = yield ContactsService_1.ContactsService.getContacts(filters, credentials.apiKey);
// Debug: Check what we actually got back
if (!Array.isArray(contacts)) {
throw new Error(`Expected array but got: ${typeof contacts}. Value: ${JSON.stringify(contacts)}`);
}
returnData.push(...contacts.map((c) => ({ json: c })));
}
else if (operation === "createContact") {
const data = JSON.parse(this.getNodeParameter("contactData", i));
if (!data.linkedin_id)
throw new Error("linkedin_id is required");
const contact = yield ContactsService_1.ContactsService.createContact(data, credentials.apiKey);
returnData.push({ json: contact });
}
else if (operation === "updateContact") {
const identifier = JSON.parse(this.getNodeParameter("identifier", i));
const data = JSON.parse(this.getNodeParameter("contactData", i));
const contact = yield ContactsService_1.ContactsService.updateContact(identifier, data, credentials.apiKey);
returnData.push({ json: contact });
}
else if (operation === "deleteContact") {
const identifier = JSON.parse(this.getNodeParameter("identifier", i));
yield ContactsService_1.ContactsService.deleteContact(identifier, credentials.apiKey);
returnData.push({
json: Object.assign({ success: true }, identifier),
});
}
}
catch (error) {
returnData.push({ json: { error: error.message } });
}
}
return this.prepareOutputData(returnData);
});
}
}
exports.Contacts = Contacts;
exports.default = Contacts;