UNPKG

n8n-nodes-warmr

Version:
114 lines (113 loc) 5.02 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.Companies = void 0; const CompaniesService_1 = require("../services/CompaniesService"); class Companies { constructor() { this.description = { displayName: "Warmr Companies", name: "warmrCompanies", group: ["transform"], version: 1, description: "Browse Warmr companies via the v1 API", defaults: { name: "Warmr Companies", 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 Companies", value: "listCompanies" }, { name: "Get Company", value: "getCompany" }, ], default: "listCompanies", description: "Operation to perform", }, // --- List Companies filters --- { displayName: "Page", name: "page", type: "number", default: 1, displayOptions: { show: { operation: ["listCompanies"] } }, }, { displayName: "Per Page", name: "perPage", type: "number", default: 50, displayOptions: { show: { operation: ["listCompanies"] } }, description: "Results per page (max 100)", }, { displayName: "Search", name: "search", type: "string", default: "", displayOptions: { show: { operation: ["listCompanies"] } }, description: "Search by company name", }, // --- Get Company --- { displayName: "Company UUID", name: "uuid", type: "string", default: "", required: true, displayOptions: { show: { operation: ["getCompany"] } }, description: "UUID of the company", }, ], }; } 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 === "listCompanies") { const query = {}; const page = this.getNodeParameter("page", i); const perPage = this.getNodeParameter("perPage", i); const search = this.getNodeParameter("search", i); if (page) query.page = page; if (perPage) query.per_page = perPage; if (search) query.search = search; const result = yield CompaniesService_1.CompaniesService.getCompanies(query, credentials.apiKey); returnData.push({ json: result }); } else if (operation === "getCompany") { const uuid = this.getNodeParameter("uuid", i); const company = yield CompaniesService_1.CompaniesService.getCompany(uuid, credentials.apiKey); returnData.push({ json: company }); } } catch (error) { returnData.push({ json: { error: error.message } }); } } return this.prepareOutputData(returnData); }); } } exports.Companies = Companies; exports.default = Companies;