n8n-nodes-inflow-crm
Version:
Official Inflow CRM integration for n8n. Create, update, search records and handle webhooks with dynamic field support.
113 lines (112 loc) • 4.62 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InflowCrmTriggers = void 0;
const helpers_1 = require("../lib/helpers");
const api_1 = require("../lib/api");
const endpoints_1 = require("../lib/endpoints");
class InflowCrmTriggers {
constructor() {
this.description = {
displayName: 'Inflow CRM Trigger',
name: 'inflowCrmTriggers',
icon: 'file:inflowCrm.png',
group: ['trigger'],
version: 1,
subtitle: '={{$parameter["triggerType"] + ": " + $parameter["moduleName"]}}',
description: 'Triggers when events occur in Inflow CRM',
defaults: {
name: 'Inflow CRM Trigger',
},
inputs: [],
outputs: ["main" /* NodeConnectionType.Main */],
credentials: [{ name: 'inflowCrmApi', required: true }],
webhooks: [
{
name: 'default',
httpMethod: 'POST',
responseMode: 'onReceived',
path: 'webhook',
},
],
properties: [
{
displayName: 'Trigger Type',
name: 'triggerType',
type: 'options',
noDataExpression: true,
required: true,
default: 'created',
options: [
{ name: '🆕 Record Created', value: 'created' },
{ name: '📝 Record Updated', value: 'updated' },
{ name: '🗑️ Record Deleted', value: 'deleted' },
],
},
{
displayName: '📦 Module',
name: 'moduleName',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getModules',
},
required: true,
default: '',
description: 'Select the module to monitor for events.',
},
],
};
this.methods = {
loadOptions: {
getModules: helpers_1.getModules,
},
};
this.webhookMethods = {
default: {
async checkExists() {
const staticData = this.getWorkflowStaticData('node');
if (!staticData.subscriptionId)
return false;
try {
const response = await (0, api_1.inflowApiRequest)(this, 'GET', endpoints_1.Endpoints.WEBHOOK(String(staticData.subscriptionId)), {}, {});
return !!(response && response.data && response.data.subscriptionId);
}
catch (error) {
return false;
}
},
async create() {
const triggerType = this.getNodeParameter('triggerType');
const hookUrl = this.getNodeWebhookUrl('default');
const moduleName = this.getNodeParameter('moduleName');
const event = (0, helpers_1.mapTriggerTypeToEvent)(triggerType);
const response = await (0, api_1.inflowApiRequest)(this, 'POST', endpoints_1.Endpoints.WEBHOOK_SUBSCRIBE, { hookUrl, event, module: moduleName }, {});
if (response && response.data && response.data.id) {
this.getWorkflowStaticData('node').subscriptionId = response.data.id;
return true;
}
return false;
},
async delete() {
const staticData = this.getWorkflowStaticData('node');
if (!staticData.subscriptionId)
return true;
try {
await (0, api_1.inflowApiRequest)(this, 'DELETE', endpoints_1.Endpoints.WEBHOOK(String(staticData.subscriptionId)), {}, {});
}
catch (error) {
return false;
}
delete staticData.subscriptionId;
return true;
},
},
};
}
async webhook() {
const body = this.getBodyData();
return {
workflowData: [this.helpers.returnJsonArray([body])],
};
}
}
exports.InflowCrmTriggers = InflowCrmTriggers;