UNPKG

n8n-nodes-rd-station-crm

Version:

n8n community node for RD Station CRM: API v1 (private token) and API v2 (OAuth2) — contacts, deals, organizations, tasks, notes, pipelines, stages, products, custom fields, sources, campaigns, loss reasons, users, teams and a real webhook trigger.

357 lines 15.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.contactDescription = void 0; exports.executeContact = executeContact; const transport_1 = require("../../transport"); // --------------------------------------------------------------------------- // TEMPLATE RESOURCE — every other resource mirrors this file's structure: // 1. `<resource>Description` = operations dropdown + fields (INodeProperties[]) // 2. `execute<Resource>(operation, i)` = programmatic dispatch using the transport helpers // Keep displayNames Title Case, descriptions/actions Sentence case, // options alphabetically sorted, loadOptions fields suffixed "Name or ID". // --------------------------------------------------------------------------- const showOnlyForContacts = { resource: ['contact'], }; exports.contactDescription = [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: showOnlyForContacts }, options: [ { name: 'Create', value: 'create', action: 'Create a contact', description: 'Create a new contact (person or lead) in RD Station CRM and return the created record including its ID', }, { name: 'Get', value: 'get', action: 'Get a contact', description: 'Retrieve a single contact from RD Station CRM by its unique ID', }, { name: 'Get Many', value: 'getMany', action: 'Get many contacts', description: 'Retrieve a paginated list of contacts from RD Station CRM, with optional filters and sorting', }, { name: 'Update', value: 'update', action: 'Update a contact', description: 'Update an existing RD Station CRM contact identified by its ID and return the updated record', }, ], default: 'create', }, // ----- ID field (get / update) ----- { displayName: 'Contact ID', name: 'contactId', type: 'string', required: true, default: '', displayOptions: { show: { ...showOnlyForContacts, operation: ['get', 'update'] } }, description: 'Unique ID of the contact to retrieve or update, as returned by a Create or Get Many contact operation', }, // ----- name (create) ----- { displayName: 'Name', name: 'name', type: 'string', required: true, default: '', displayOptions: { show: { ...showOnlyForContacts, operation: ['create'] } }, description: 'Full name of the contact (person or lead), for example Maria Silva', }, // ----- Emails / Phones / Custom Fields (create + update) ----- { displayName: 'Emails', name: 'emailsUi', type: 'fixedCollection', typeOptions: { multipleValues: true }, placeholder: 'Add Email', default: {}, displayOptions: { show: { ...showOnlyForContacts, operation: ['create', 'update'] } }, options: [ { name: 'email', displayName: 'Email', values: [ { displayName: 'Email', name: 'email', type: 'string', placeholder: 'e.g. name@example.com', default: '', description: 'Email address of the contact, e.g. maria@empresa.com', }, ], }, ], }, { displayName: 'Phones', name: 'phonesUi', type: 'fixedCollection', typeOptions: { multipleValues: true }, placeholder: 'Add Phone', default: {}, displayOptions: { show: { ...showOnlyForContacts, operation: ['create', 'update'] } }, options: [ { name: 'phone', displayName: 'Phone', values: [ { displayName: 'Phone', name: 'phone', type: 'string', default: '', description: 'Phone number of the contact including country and area code, e.g. +55 11 99999-9999', }, { displayName: 'Type', name: 'type', type: 'options', options: [ { name: 'Cellphone', value: 'cellphone' }, { name: 'Fax', value: 'fax' }, { name: 'Home', value: 'home' }, { name: 'Work', value: 'work' }, ], default: 'work', description: 'Category of the phone number. One of: cellphone, fax, home, work', }, ], }, ], }, { displayName: 'Custom Fields', name: 'customFieldsUi', type: 'fixedCollection', typeOptions: { multipleValues: true }, placeholder: 'Add Custom Field', default: {}, displayOptions: { show: { ...showOnlyForContacts, operation: ['create', 'update'] } }, options: [ { name: 'field', displayName: 'Field', values: [ { displayName: 'Field Name or ID', name: 'fieldId', type: 'options', description: 'Contact custom field to set, referenced by its custom field ID. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>', typeOptions: { loadOptionsMethod: 'getContactCustomFields' }, default: '', }, { displayName: 'Value', name: 'value', type: 'string', default: '', description: 'Value to set for the selected custom field, as plain text, e.g. Gold tier', }, ], }, ], }, // ----- Additional / Update fields ----- { displayName: 'Additional Fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', default: {}, displayOptions: { show: { ...showOnlyForContacts, operation: ['create'] } }, options: [ { displayName: 'Birthday', name: 'birthday', type: 'dateTime', default: '', description: 'Date of birth in ISO 8601 format YYYY-MM-DD, e.g. 1990-05-21' }, { displayName: 'Deal IDs', name: 'dealIds', type: 'string', default: '', description: 'Comma-separated list of deal IDs to link to this contact, for example 123,456' }, { displayName: 'Facebook', name: 'facebook', type: 'string', default: '', description: 'Facebook profile handle or URL of the contact, e.g. facebook.com/maria.silva' }, { displayName: 'LinkedIn', name: 'linkedin', type: 'string', default: '', description: 'LinkedIn profile handle or URL of the contact, e.g. linkedin.com/in/maria-silva' }, { displayName: 'Organization Name or ID', name: 'organizationId', type: 'options', description: 'Organization (company) this contact belongs to, referenced by its ID. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>', typeOptions: { loadOptionsMethod: 'getOrganizations' }, default: '', }, { displayName: 'Skype', name: 'skype', type: 'string', default: '', description: 'Skype username of the contact' }, { displayName: 'Title', name: 'title', type: 'string', default: '', description: 'Job title of the contact, e.g. Marketing Manager' }, ], }, { displayName: 'Update Fields', name: 'updateFields', type: 'collection', placeholder: 'Add Field', default: {}, displayOptions: { show: { ...showOnlyForContacts, operation: ['update'] } }, options: [ { displayName: 'Birthday', name: 'birthday', type: 'dateTime', default: '', description: 'Date of birth in ISO 8601 format YYYY-MM-DD, e.g. 1990-05-21' }, { displayName: 'Facebook', name: 'facebook', type: 'string', default: '', description: 'Facebook profile handle or URL of the contact, e.g. facebook.com/maria.silva' }, { displayName: 'LinkedIn', name: 'linkedin', type: 'string', default: '', description: 'LinkedIn profile handle or URL of the contact, e.g. linkedin.com/in/maria-silva' }, { displayName: 'Name', name: 'name', type: 'string', default: '', description: 'Full name of the contact (person or lead), e.g. Maria Silva' }, { displayName: 'Organization Name or ID', name: 'organizationId', type: 'options', description: 'Organization (company) this contact belongs to, referenced by its ID. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>', typeOptions: { loadOptionsMethod: 'getOrganizations' }, default: '', }, { displayName: 'Skype', name: 'skype', type: 'string', default: '', description: 'Skype username of the contact' }, { displayName: 'Title', name: 'title', type: 'string', default: '', description: 'Job title of the contact, e.g. Marketing Manager' }, ], }, // ----- Get Many controls ----- { displayName: 'Return All', name: 'returnAll', type: 'boolean', default: false, description: 'Whether to return all results or only up to a given limit', displayOptions: { show: { ...showOnlyForContacts, operation: ['getMany'] } }, }, { displayName: 'Limit', name: 'limit', type: 'number', default: 50, typeOptions: { minValue: 1 }, description: 'Max number of results to return', displayOptions: { show: { ...showOnlyForContacts, operation: ['getMany'], returnAll: [false] }, }, }, { displayName: 'Filters', name: 'filters', type: 'collection', placeholder: 'Add Filter', default: {}, displayOptions: { show: { ...showOnlyForContacts, operation: ['getMany'] } }, options: [ { displayName: 'Email', name: 'email', type: 'string', placeholder: 'e.g. name@example.com', default: '', description: 'Email address to filter contacts by, e.g. maria@empresa.com' }, { displayName: 'Phone', name: 'phone', type: 'string', default: '', description: 'Phone number to filter contacts by, including country and area code, e.g. +55 11 99999-9999' }, { displayName: 'Search', name: 'q', type: 'string', default: '', description: 'Filter contacts by name, returning those whose name matches the given text' }, { displayName: 'Title', name: 'title', type: 'string', default: '', description: 'Job title of the contact, e.g. Marketing Manager' }, ], }, { displayName: 'Options', name: 'options', type: 'collection', placeholder: 'Add Option', default: {}, displayOptions: { show: { ...showOnlyForContacts, operation: ['getMany'] } }, options: [ { displayName: 'Sort By', name: 'order', type: 'options', options: [ { name: 'Created At', value: 'created_at' }, { name: 'Name', value: 'name' }, { name: 'Updated At', value: 'updated_at' }, ], default: 'name', description: 'Field to sort the results by. One of: created_at, name, updated_at', }, { displayName: 'Sort Direction', name: 'direction', type: 'options', options: [ { name: 'Ascending', value: 'asc' }, { name: 'Descending', value: 'desc' }, ], default: 'asc', description: 'Sort direction. One of: asc, desc', }, ], }, ]; function buildContactBody(i, fields) { const contact = {}; if (fields.name) contact.name = fields.name; if (fields.title) contact.title = fields.title; if (fields.organizationId) contact.organization_id = fields.organizationId; for (const key of ['facebook', 'linkedin', 'skype']) { if (fields[key]) contact[key] = fields[key]; } if (fields.dealIds) { contact.deal_ids = fields.dealIds .split(',') .map((s) => s.trim()) .filter(Boolean); } if (fields.birthday) { const d = new Date(fields.birthday); contact.birthday = { day: d.getUTCDate(), month: d.getUTCMonth() + 1, year: d.getUTCFullYear(), }; } const emailsUi = this.getNodeParameter('emailsUi', i, {}); if (Array.isArray(emailsUi.email)) { contact.emails = emailsUi.email.map((e) => ({ email: e.email })); } const phonesUi = this.getNodeParameter('phonesUi', i, {}); if (Array.isArray(phonesUi.phone)) { contact.phones = phonesUi.phone.map((p) => ({ phone: p.phone, type: p.type })); } const customFieldsUi = this.getNodeParameter('customFieldsUi', i, {}); if (Array.isArray(customFieldsUi.field)) { contact.contact_custom_fields = customFieldsUi.field.map((f) => ({ custom_field_id: f.fieldId, value: f.value, })); } return contact; } async function executeContact(operation, i) { if (operation === 'create') { const name = this.getNodeParameter('name', i); const additionalFields = this.getNodeParameter('additionalFields', i, {}); const contact = buildContactBody.call(this, i, { name, ...additionalFields }); return transport_1.rdCrmApiRequest.call(this, 'POST', '/contacts', { contact }); } if (operation === 'get') { const contactId = this.getNodeParameter('contactId', i); return transport_1.rdCrmApiRequest.call(this, 'GET', `/contacts/${contactId}`); } if (operation === 'getMany') { const returnAll = this.getNodeParameter('returnAll', i); const filters = this.getNodeParameter('filters', i, {}); const options = this.getNodeParameter('options', i, {}); const qs = { ...filters, ...options }; if (returnAll) { return transport_1.rdCrmApiRequestAllItems.call(this, 'contacts', 'GET', '/contacts', {}, qs); } qs.limit = this.getNodeParameter('limit', i); const response = await transport_1.rdCrmApiRequest.call(this, 'GET', '/contacts', {}, qs); return response.contacts ?? response; } if (operation === 'update') { const contactId = this.getNodeParameter('contactId', i); const updateFields = this.getNodeParameter('updateFields', i, {}); const contact = buildContactBody.call(this, i, updateFields); return transport_1.rdCrmApiRequest.call(this, 'PUT', `/contacts/${contactId}`, { contact }); } return {}; } //# sourceMappingURL=Contact.js.map