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.
80 lines • 3.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadOptionsV2 = void 0;
const v2_1 = require("../transport/v2");
function toOptionsV2(items, labelKey = 'name') {
return items
.filter(Boolean)
.map((item) => ({
name: (item[labelKey] ?? item.name ?? item.email ?? item.id),
value: (item.id ?? item._id),
}));
}
async function loadCustomFieldsV2(entity) {
const fields = await v2_1.rdCrmV2RequestAllItems.call(this, '/custom_fields', {
filter: `entity:${entity}`,
});
// v2 custom_fields are addressed by slug, not id.
return fields
.filter(Boolean)
.map((f) => ({ name: (f.name ?? f.slug), value: (f.slug ?? f.id) }));
}
exports.loadOptionsV2 = {
async getUsersV2() {
return toOptionsV2(await v2_1.rdCrmV2RequestAllItems.call(this, '/users'));
},
async getOrganizationsV2() {
return toOptionsV2(await v2_1.rdCrmV2RequestAllItems.call(this, '/organizations'));
},
async getSourcesV2() {
return toOptionsV2(await v2_1.rdCrmV2RequestAllItems.call(this, '/sources'));
},
async getCampaignsV2() {
return toOptionsV2(await v2_1.rdCrmV2RequestAllItems.call(this, '/campaigns'));
},
async getLossReasonsV2() {
return toOptionsV2(await v2_1.rdCrmV2RequestAllItems.call(this, '/lost_reasons'));
},
async getSegmentsV2() {
return toOptionsV2(await v2_1.rdCrmV2RequestAllItems.call(this, '/segments'));
},
async getPipelinesV2() {
return toOptionsV2(await v2_1.rdCrmV2RequestAllItems.call(this, '/pipelines'));
},
// Stages are nested under pipelines. When a pipeline is selected upstream, list only its
// stages; otherwise list every pipeline's stages labeled "Pipeline › Stage".
async getStagesV2() {
let pipelineId = '';
try {
pipelineId = this.getNodeParameter('pipeline_id', '');
}
catch {
pipelineId = '';
}
if (pipelineId) {
const stages = await v2_1.rdCrmV2RequestAllItems.call(this, `/pipelines/${pipelineId}/stages`);
return stages
.filter(Boolean)
.map((stage) => ({ name: stage.name, value: stage.id }));
}
const pipelines = await v2_1.rdCrmV2RequestAllItems.call(this, '/pipelines');
const out = [];
for (const pipeline of pipelines) {
const stages = await v2_1.rdCrmV2RequestAllItems.call(this, `/pipelines/${pipeline.id}/stages`);
for (const stage of stages) {
out.push({ name: `${pipeline.name} › ${stage.name}`, value: stage.id });
}
}
return out;
},
async getContactCustomFieldsV2() {
return loadCustomFieldsV2.call(this, 'contact');
},
async getDealCustomFieldsV2() {
return loadCustomFieldsV2.call(this, 'deal');
},
async getOrganizationCustomFieldsV2() {
return loadCustomFieldsV2.call(this, 'organization');
},
};
//# sourceMappingURL=loadOptionsV2.js.map