UNPKG

n8n-nodes-innotes

Version:

N8N node for InNotes CRM API integration

173 lines (171 loc) 4.95 kB
"use strict"; /** * Author: marco * Last updated: 2025-06-01 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.cleanObject = cleanObject; exports.buildQueryString = buildQueryString; exports.validateRequiredFields = validateRequiredFields; exports.formatDate = formatDate; exports.parsePaginationParams = parsePaginationParams; exports.buildRequestOptions = buildRequestOptions; exports.extractErrorMessage = extractErrorMessage; exports.transformContactData = transformContactData; exports.transformNoteData = transformNoteData; exports.transformJobData = transformJobData; /** * Utility functions for InNotes N8N node */ /** * Clean undefined values from an object */ function cleanObject(obj) { const cleaned = {}; for (const [key, value] of Object.entries(obj)) { if (value !== undefined && value !== null && value !== '') { cleaned[key] = value; } } return cleaned; } /** * Convert query parameters to URL search params */ function buildQueryString(params) { const cleanedParams = cleanObject(params); const searchParams = new URLSearchParams(); for (const [key, value] of Object.entries(cleanedParams)) { if (Array.isArray(value)) { value.forEach(item => searchParams.append(key, String(item))); } else { searchParams.append(key, String(value)); } } return searchParams.toString(); } /** * Validate required fields are present */ function validateRequiredFields(data, requiredFields) { const missingFields = requiredFields.filter(field => !data[field]); if (missingFields.length > 0) { throw new Error(`Missing required fields: ${missingFields.join(', ')}`); } } /** * Format date for API requests */ function formatDate(date) { if (typeof date === 'string') { date = new Date(date); } return date.toISOString(); } /** * Parse pagination parameters */ function parsePaginationParams(limit, offset) { return { limit: limit !== null && limit !== void 0 ? limit : 50, offset: offset !== null && offset !== void 0 ? offset : 0, }; } /** * Build request options for HTTP calls */ function buildRequestOptions(method, url, data, params) { const options = { method, url, headers: { 'Content-Type': 'application/json', }, }; if (data) { options.body = cleanObject(data); } if (params) { const queryString = buildQueryString(params); if (queryString) { options.url = `${url}?${queryString}`; } } return options; } /** * Extract error message from API response */ function extractErrorMessage(error) { var _a, _b, _c, _d; if ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.message) { return error.response.body.message; } if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.body) === null || _d === void 0 ? void 0 : _d.error) { return error.response.body.error; } if (error.message) { return error.message; } return 'Unknown error occurred'; } /** * Transform InNotes contact data for output */ function transformContactData(contact) { var _a, _b; return { id: contact.id, name: contact.name, email: contact.email, phone: contact.phone, linkedinUrl: contact.linkedinUrl, company: contact.company, position: contact.position, location: contact.location, tags: (_a = contact.tags) !== null && _a !== void 0 ? _a : [], status: contact.status, notes: (_b = contact.notes) !== null && _b !== void 0 ? _b : [], createdAt: contact.createdAt, updatedAt: contact.updatedAt, }; } /** * Transform InNotes note data for output */ function transformNoteData(note) { var _a, _b; return { id: note.id, contactId: note.contactId, content: note.content, type: note.type, tags: (_a = note.tags) !== null && _a !== void 0 ? _a : [], attachments: (_b = note.attachments) !== null && _b !== void 0 ? _b : [], createdAt: note.createdAt, updatedAt: note.updatedAt, }; } /** * Transform InNotes job data for output */ function transformJobData(job) { var _a, _b; return { id: job.id, title: job.title, company: job.company, description: job.description, url: job.url, status: job.status, salaryRange: job.salaryRange, location: job.location, type: job.type, contacts: (_a = job.contacts) !== null && _a !== void 0 ? _a : [], notes: (_b = job.notes) !== null && _b !== void 0 ? _b : [], createdAt: job.createdAt, updatedAt: job.updatedAt, }; } //# sourceMappingURL=helpers.js.map