UNPKG

n8n-nodes-warmr

Version:
68 lines (67 loc) 3.21 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.ContactsService = void 0; const request_1 = require("../utils/request"); const BASE_URL = "https://api.warmr.app"; // Updated to production API URL class ContactsService { static getContacts(filters, apiKey) { return __awaiter(this, void 0, void 0, function* () { const filtered = {}; Object.entries(filters).forEach(([k, v]) => { if (typeof v === "string") filtered[k] = v; }); const params = new URLSearchParams(filtered); const response = yield (0, request_1.apiRequest)(`${BASE_URL}/contacts?${params.toString()}`, {}, apiKey); // Handle different possible response structures if (Array.isArray(response)) { return response; } if (response && Array.isArray(response.data)) { return response.data; } // If response is not in expected format, throw error with details throw new Error(`Unexpected response format: ${JSON.stringify(response)}`); }); } static createContact(data, apiKey) { return __awaiter(this, void 0, void 0, function* () { return (0, request_1.apiRequest)(`${BASE_URL}/contacts`, { method: "POST", body: JSON.stringify(data), }, apiKey); }); } static updateContact(identifier, data, apiKey) { return __awaiter(this, void 0, void 0, function* () { // Prefer uuid, then linkedin_id, then email const id = identifier.uuid || identifier.linkedin_id || identifier.email; if (!id) throw new Error("Identifier required (uuid, linkedin_id, or email)"); return (0, request_1.apiRequest)(`${BASE_URL}/contacts/${id}`, { method: "PATCH", body: JSON.stringify(data), }, apiKey); }); } static deleteContact(identifier, apiKey) { return __awaiter(this, void 0, void 0, function* () { const id = identifier.uuid || identifier.linkedin_id || identifier.email; if (!id) throw new Error("Identifier required (uuid, linkedin_id, or email)"); yield (0, request_1.apiRequest)(`${BASE_URL}/contacts/${id}`, { method: "DELETE", }, apiKey); }); } } exports.ContactsService = ContactsService;