n8n-nodes-idb2b 3.2.4 → 3.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ exports.IDB2B = void 0;
4
4
  const n8n_workflow_1 = require("n8n-workflow");
5
5
  const contactProperties_1 = require("./descriptions/contactProperties");
6
6
  const companyProperties_1 = require("./descriptions/companyProperties");
7
+ const activityProperties_1 = require("./descriptions/activityProperties");
7
8
  // Import new utility modules
8
9
  const validators_1 = require("./utils/validators");
9
10
  const errorHandler_1 = require("./utils/errorHandler");
@@ -39,6 +40,10 @@ class IDB2B {
39
40
  type: "options",
40
41
  noDataExpression: true,
41
42
  options: [
43
+ {
44
+ name: "Activity",
45
+ value: "activity",
46
+ },
42
47
  {
43
48
  name: "Contact",
44
49
  value: "contact",
@@ -50,8 +55,10 @@ class IDB2B {
50
55
  ],
51
56
  default: "contact",
52
57
  },
58
+ activityProperties_1.activityOperations,
53
59
  contactProperties_1.contactOperations,
54
60
  companyProperties_1.companyOperations,
61
+ ...activityProperties_1.activityFields,
55
62
  ...contactProperties_1.contactFields,
56
63
  ...companyProperties_1.companyFields,
57
64
  ],
@@ -144,6 +151,60 @@ class IDB2B {
144
151
  endpoint = `${constants_1.ENDPOINTS.CONTACTS}/${(0, common_1.sanitizeId)(contactId)}`;
145
152
  }
146
153
  }
154
+ else if (resource === "activity") {
155
+ if (operation === "getAll") {
156
+ method = "GET";
157
+ const companyId = this.getNodeParameter("companyId", i);
158
+ const limit = this.getNodeParameter("limit", i, constants_1.PAGINATION.DEFAULT_LIMIT);
159
+ const page = this.getNodeParameter("page", i, constants_1.PAGINATION.DEFAULT_PAGE);
160
+ endpoint = `/leads/${(0, common_1.sanitizeId)(companyId)}/activities`;
161
+ qs.limit = limit;
162
+ qs.page = page;
163
+ }
164
+ else if (operation === "get") {
165
+ method = "GET";
166
+ const activityId = this.getNodeParameter("activityId", i);
167
+ endpoint = `${constants_1.ENDPOINTS.ACTIVITIES}/${(0, common_1.sanitizeId)(activityId)}`;
168
+ }
169
+ else if (operation === "create") {
170
+ method = "POST";
171
+ endpoint = constants_1.ENDPOINTS.ACTIVITIES;
172
+ const subject = this.getNodeParameter("subject", i);
173
+ const associateWith = this.getNodeParameter("associateWith", i);
174
+ const additionalFields = this.getNodeParameter("additionalFields", i, {});
175
+ if (!subject || !subject.trim()) {
176
+ throw new Error("Subject is required to create an activity");
177
+ }
178
+ body = Object.assign({ subject: subject.trim() }, additionalFields);
179
+ if (associateWith === "company") {
180
+ const companyId = this.getNodeParameter("activityCompanyId", i);
181
+ body.company_id = companyId;
182
+ }
183
+ else {
184
+ const contactId = this.getNodeParameter("activityContactId", i);
185
+ body.contact_id = contactId;
186
+ }
187
+ initialBody = body;
188
+ }
189
+ else if (operation === "update") {
190
+ method = "PATCH";
191
+ const activityId = this.getNodeParameter("activityId", i);
192
+ endpoint = `${constants_1.ENDPOINTS.ACTIVITIES}/${(0, common_1.sanitizeId)(activityId)}`;
193
+ const additionalFields = this.getNodeParameter("additionalFields", i, {});
194
+ body = {};
195
+ Object.entries(additionalFields).forEach(([key, value]) => {
196
+ if (value !== undefined && value !== "") {
197
+ body[key] = value;
198
+ }
199
+ });
200
+ initialBody = body;
201
+ }
202
+ else if (operation === "delete") {
203
+ method = "DELETE";
204
+ const activityId = this.getNodeParameter("activityId", i);
205
+ endpoint = `${constants_1.ENDPOINTS.ACTIVITIES}/${(0, common_1.sanitizeId)(activityId)}`;
206
+ }
207
+ }
147
208
  else if (resource === "company") {
148
209
  if (operation === "getAll") {
149
210
  method = "GET";
@@ -48,6 +48,7 @@ export declare const ENDPOINTS: {
48
48
  LOGIN: string;
49
49
  CONTACTS: string;
50
50
  COMPANIES: string;
51
+ ACTIVITIES: string;
51
52
  };
52
53
  export declare const RESPONSE: {
53
54
  SUCCESS_MESSAGE: string;
@@ -65,6 +65,7 @@ exports.ENDPOINTS = {
65
65
  LOGIN: "/login",
66
66
  CONTACTS: "/contacts",
67
67
  COMPANIES: "/companies",
68
+ ACTIVITIES: "/activities",
68
69
  };
69
70
  // Response Processing
70
71
  exports.RESPONSE = {
@@ -0,0 +1,3 @@
1
+ import { INodeProperties } from 'n8n-workflow';
2
+ export declare const activityOperations: INodeProperties;
3
+ export declare const activityFields: INodeProperties[];
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.activityFields = exports.activityOperations = void 0;
4
+ exports.activityOperations = {
5
+ displayName: 'Operation',
6
+ name: 'operation',
7
+ type: 'options',
8
+ noDataExpression: true,
9
+ displayOptions: {
10
+ show: {
11
+ resource: ['activity'],
12
+ },
13
+ },
14
+ options: [
15
+ {
16
+ name: 'Get All',
17
+ value: 'getAll',
18
+ action: 'Get all activities for a company',
19
+ description: 'Retrieve all activities for a specific company/lead',
20
+ },
21
+ {
22
+ name: 'Get',
23
+ value: 'get',
24
+ action: 'Get an activity',
25
+ description: 'Get a single activity by ID',
26
+ },
27
+ {
28
+ name: 'Create',
29
+ value: 'create',
30
+ action: 'Create an activity',
31
+ description: 'Create a new activity for a company or contact',
32
+ },
33
+ {
34
+ name: 'Update',
35
+ value: 'update',
36
+ action: 'Update an activity',
37
+ description: 'Update an existing activity',
38
+ },
39
+ {
40
+ name: 'Delete',
41
+ value: 'delete',
42
+ action: 'Delete an activity',
43
+ description: 'Delete an activity by ID',
44
+ },
45
+ ],
46
+ default: 'getAll',
47
+ };
48
+ exports.activityFields = [
49
+ // Activity ID — required for get, update, delete
50
+ {
51
+ displayName: 'Activity ID',
52
+ name: 'activityId',
53
+ type: 'string',
54
+ default: '',
55
+ required: true,
56
+ displayOptions: {
57
+ show: {
58
+ resource: ['activity'],
59
+ operation: ['get', 'update', 'delete'],
60
+ },
61
+ },
62
+ description: 'ID of the activity',
63
+ },
64
+ // Company ID — required for getAll (scoped to company), optional for create
65
+ {
66
+ displayName: 'Company ID',
67
+ name: 'companyId',
68
+ type: 'string',
69
+ default: '',
70
+ required: true,
71
+ displayOptions: {
72
+ show: {
73
+ resource: ['activity'],
74
+ operation: ['getAll'],
75
+ },
76
+ },
77
+ description: 'ID of the company/lead to list activities for',
78
+ },
79
+ // Subject — required for create
80
+ {
81
+ displayName: 'Subject',
82
+ name: 'subject',
83
+ type: 'string',
84
+ default: '',
85
+ required: true,
86
+ displayOptions: {
87
+ show: {
88
+ resource: ['activity'],
89
+ operation: ['create'],
90
+ },
91
+ },
92
+ description: 'Subject of the activity',
93
+ },
94
+ // Association — required for create (company OR contact)
95
+ {
96
+ displayName: 'Associate With',
97
+ name: 'associateWith',
98
+ type: 'options',
99
+ default: 'company',
100
+ required: true,
101
+ displayOptions: {
102
+ show: {
103
+ resource: ['activity'],
104
+ operation: ['create'],
105
+ },
106
+ },
107
+ options: [
108
+ { name: 'Company', value: 'company' },
109
+ { name: 'Contact', value: 'contact' },
110
+ ],
111
+ description: 'Whether to link this activity to a company or a contact',
112
+ },
113
+ {
114
+ displayName: 'Company ID',
115
+ name: 'activityCompanyId',
116
+ type: 'string',
117
+ default: '',
118
+ required: true,
119
+ displayOptions: {
120
+ show: {
121
+ resource: ['activity'],
122
+ operation: ['create'],
123
+ associateWith: ['company'],
124
+ },
125
+ },
126
+ description: 'ID of the company/lead to associate this activity with',
127
+ },
128
+ {
129
+ displayName: 'Contact ID',
130
+ name: 'activityContactId',
131
+ type: 'string',
132
+ default: '',
133
+ required: true,
134
+ displayOptions: {
135
+ show: {
136
+ resource: ['activity'],
137
+ operation: ['create'],
138
+ associateWith: ['contact'],
139
+ },
140
+ },
141
+ description: 'ID of the contact to associate this activity with',
142
+ },
143
+ // Additional fields for create/update
144
+ {
145
+ displayName: 'Additional Fields',
146
+ name: 'additionalFields',
147
+ type: 'collection',
148
+ placeholder: 'Add Field',
149
+ default: {},
150
+ displayOptions: {
151
+ show: {
152
+ resource: ['activity'],
153
+ operation: ['create', 'update'],
154
+ },
155
+ },
156
+ options: [
157
+ {
158
+ displayName: 'Subject',
159
+ name: 'subject',
160
+ type: 'string',
161
+ default: '',
162
+ description: 'Subject of the activity (for update)',
163
+ },
164
+ {
165
+ displayName: 'Description',
166
+ name: 'description',
167
+ type: 'string',
168
+ typeOptions: {
169
+ rows: 4,
170
+ },
171
+ default: '',
172
+ description: 'Description or notes for the activity',
173
+ },
174
+ {
175
+ displayName: 'Date & Time',
176
+ name: 'datetime',
177
+ type: 'dateTime',
178
+ default: '',
179
+ description: 'Date and time of the activity (ISO 8601)',
180
+ },
181
+ {
182
+ displayName: 'Icon',
183
+ name: 'icon',
184
+ type: 'string',
185
+ default: '',
186
+ description: 'Icon identifier for the activity',
187
+ },
188
+ {
189
+ displayName: 'User ID',
190
+ name: 'user_id',
191
+ type: 'string',
192
+ default: '',
193
+ description: 'UUID of the user to associate with the activity',
194
+ },
195
+ ],
196
+ },
197
+ // Pagination for getAll
198
+ {
199
+ displayName: 'Limit',
200
+ name: 'limit',
201
+ type: 'number',
202
+ default: 50,
203
+ description: 'Maximum number of activities to return',
204
+ displayOptions: {
205
+ show: {
206
+ resource: ['activity'],
207
+ operation: ['getAll'],
208
+ },
209
+ },
210
+ },
211
+ {
212
+ displayName: 'Page',
213
+ name: 'page',
214
+ type: 'number',
215
+ default: 1,
216
+ description: 'Page number to retrieve',
217
+ displayOptions: {
218
+ show: {
219
+ resource: ['activity'],
220
+ operation: ['getAll'],
221
+ },
222
+ },
223
+ },
224
+ ];
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Activity resource handler
3
+ * Implements CRUD operations for lead/contact activities
4
+ */
5
+ import { HttpClient } from "../utils/httpClient";
6
+ import { DataValidator } from "../utils/validators";
7
+ import { ErrorHandler } from "../utils/errorHandler";
8
+ import { IResourceHandler, GetAllParams, GetParams, CreateParams, UpdateParams, DeleteParams } from "./handlerFactory";
9
+ export interface ActivityGetAllParams extends GetAllParams {
10
+ companyId: string;
11
+ }
12
+ export interface ActivityCreateParams extends CreateParams {
13
+ }
14
+ export declare class ActivityHandler implements IResourceHandler {
15
+ private httpClient;
16
+ private validator;
17
+ private errorHandler;
18
+ constructor(httpClient: HttpClient, validator: DataValidator, errorHandler: ErrorHandler);
19
+ /**
20
+ * Get all activities for a specific company/lead
21
+ */
22
+ getAll(params: ActivityGetAllParams): Promise<any>;
23
+ /**
24
+ * Get single activity by ID
25
+ */
26
+ get(params: GetParams): Promise<any>;
27
+ /**
28
+ * Create a new activity (linked to a company or contact)
29
+ */
30
+ create(params: CreateParams): Promise<any>;
31
+ /**
32
+ * Update an existing activity
33
+ */
34
+ update(params: UpdateParams): Promise<any>;
35
+ /**
36
+ * Delete an activity
37
+ */
38
+ delete(params: DeleteParams): Promise<any>;
39
+ }
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /**
3
+ * Activity resource handler
4
+ * Implements CRUD operations for lead/contact activities
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ActivityHandler = void 0;
8
+ const constants_1 = require("../config/constants");
9
+ const common_1 = require("../utils/common");
10
+ class ActivityHandler {
11
+ constructor(httpClient, validator, errorHandler) {
12
+ this.httpClient = httpClient;
13
+ this.validator = validator;
14
+ this.errorHandler = errorHandler;
15
+ }
16
+ /**
17
+ * Get all activities for a specific company/lead
18
+ */
19
+ async getAll(params) {
20
+ var _a, _b;
21
+ const limit = (_a = params.limit) !== null && _a !== void 0 ? _a : constants_1.PAGINATION.DEFAULT_LIMIT;
22
+ const page = (_b = params.page) !== null && _b !== void 0 ? _b : constants_1.PAGINATION.DEFAULT_PAGE;
23
+ const qs = { limit, page };
24
+ if (params.queryParameters) {
25
+ Object.assign(qs, params.queryParameters);
26
+ }
27
+ const options = {
28
+ method: "GET",
29
+ url: `${params.baseUrl}/leads/${(0, common_1.sanitizeId)(params.companyId)}/activities`,
30
+ headers: {
31
+ Authorization: `Bearer ${params.accessToken}`,
32
+ },
33
+ qs,
34
+ json: true,
35
+ };
36
+ return this.httpClient.makeRequest(options);
37
+ }
38
+ /**
39
+ * Get single activity by ID
40
+ */
41
+ async get(params) {
42
+ const options = {
43
+ method: "GET",
44
+ url: `${params.baseUrl}${constants_1.ENDPOINTS.ACTIVITIES}/${(0, common_1.sanitizeId)(params.id)}`,
45
+ headers: {
46
+ Authorization: `Bearer ${params.accessToken}`,
47
+ },
48
+ json: true,
49
+ };
50
+ return this.httpClient.makeRequest(options);
51
+ }
52
+ /**
53
+ * Create a new activity (linked to a company or contact)
54
+ */
55
+ async create(params) {
56
+ const { company_id, contact_id, subject, description, datetime, icon, user_id } = params.data;
57
+ if (!subject || !subject.trim()) {
58
+ throw new Error("Subject is required to create an activity");
59
+ }
60
+ if (!company_id && !contact_id) {
61
+ throw new Error("Either company_id or contact_id is required");
62
+ }
63
+ const body = {
64
+ subject: subject.trim(),
65
+ };
66
+ if (company_id)
67
+ body.company_id = company_id;
68
+ if (contact_id)
69
+ body.contact_id = contact_id;
70
+ if (description)
71
+ body.description = description;
72
+ if (datetime)
73
+ body.datetime = datetime;
74
+ if (icon)
75
+ body.icon = icon;
76
+ if (user_id)
77
+ body.user_id = user_id;
78
+ const options = {
79
+ method: "POST",
80
+ url: `${params.baseUrl}${constants_1.ENDPOINTS.ACTIVITIES}`,
81
+ headers: {
82
+ Authorization: `Bearer ${params.accessToken}`,
83
+ },
84
+ body,
85
+ json: true,
86
+ };
87
+ return this.httpClient.makeRequest(options);
88
+ }
89
+ /**
90
+ * Update an existing activity
91
+ */
92
+ async update(params) {
93
+ const { subject, description, datetime, icon, user_id } = params.data;
94
+ const body = {};
95
+ if (subject)
96
+ body.subject = subject.trim();
97
+ if (description !== undefined && description !== "")
98
+ body.description = description;
99
+ if (datetime)
100
+ body.datetime = datetime;
101
+ if (icon)
102
+ body.icon = icon;
103
+ if (user_id)
104
+ body.user_id = user_id;
105
+ const options = {
106
+ method: "PATCH",
107
+ url: `${params.baseUrl}${constants_1.ENDPOINTS.ACTIVITIES}/${(0, common_1.sanitizeId)(params.id)}`,
108
+ headers: {
109
+ Authorization: `Bearer ${params.accessToken}`,
110
+ },
111
+ body,
112
+ json: true,
113
+ };
114
+ return this.httpClient.makeRequest(options);
115
+ }
116
+ /**
117
+ * Delete an activity
118
+ */
119
+ async delete(params) {
120
+ const options = {
121
+ method: "DELETE",
122
+ url: `${params.baseUrl}${constants_1.ENDPOINTS.ACTIVITIES}/${(0, common_1.sanitizeId)(params.id)}`,
123
+ headers: {
124
+ Authorization: `Bearer ${params.accessToken}`,
125
+ },
126
+ json: true,
127
+ };
128
+ return this.httpClient.makeRequest(options);
129
+ }
130
+ }
131
+ exports.ActivityHandler = ActivityHandler;
@@ -69,6 +69,7 @@ export declare class HandlerFactory {
69
69
  private errorHandler;
70
70
  private contactHandler;
71
71
  private companyHandler;
72
+ private activityHandler;
72
73
  constructor(executeFunctions: IExecuteFunctions, httpClient: HttpClient, validator: DataValidator, errorHandler: ErrorHandler);
73
74
  /**
74
75
  * Get handler for specified resource
@@ -8,6 +8,7 @@ exports.HandlerFactory = void 0;
8
8
  exports.createHandlerFactory = createHandlerFactory;
9
9
  const ContactHandler_1 = require("./ContactHandler");
10
10
  const CompanyHandler_1 = require("./CompanyHandler");
11
+ const ActivityHandler_1 = require("./ActivityHandler");
11
12
  /**
12
13
  * Handler factory class for creating handlers
13
14
  */
@@ -19,6 +20,7 @@ class HandlerFactory {
19
20
  this.errorHandler = errorHandler;
20
21
  this.contactHandler = new ContactHandler_1.ContactHandler(httpClient, validator, errorHandler);
21
22
  this.companyHandler = new CompanyHandler_1.CompanyHandler(httpClient, validator, errorHandler);
23
+ this.activityHandler = new ActivityHandler_1.ActivityHandler(httpClient, validator, errorHandler);
22
24
  }
23
25
  /**
24
26
  * Get handler for specified resource
@@ -29,6 +31,8 @@ class HandlerFactory {
29
31
  return this.contactHandler;
30
32
  case "company":
31
33
  return this.companyHandler;
34
+ case "activity":
35
+ return this.activityHandler;
32
36
  default:
33
37
  throw new Error(`Unknown resource: ${resource}`);
34
38
  }
@@ -37,13 +41,13 @@ class HandlerFactory {
37
41
  * Check if resource is supported
38
42
  */
39
43
  isResourceSupported(resource) {
40
- return ["contact", "company"].includes(resource);
44
+ return ["contact", "company", "activity"].includes(resource);
41
45
  }
42
46
  /**
43
47
  * Get list of supported resources
44
48
  */
45
49
  getSupportedResources() {
46
- return ["contact", "company"];
50
+ return ["contact", "company", "activity"];
47
51
  }
48
52
  }
49
53
  exports.HandlerFactory = HandlerFactory;
@@ -0,0 +1,14 @@
1
+ export interface IDB2BActivity {
2
+ id: string;
3
+ company_id: string | null;
4
+ contact_id: string | null;
5
+ user_id: string | null;
6
+ organization_id: string;
7
+ icon: string | null;
8
+ subject: string;
9
+ description: string | null;
10
+ datetime: string | null;
11
+ type: string | null;
12
+ created_at: string | null;
13
+ updated_at: string | null;
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { INodeType, INodeTypeDescription, INodeExecutionData, IPollFunctions } from "n8n-workflow";
2
+ export declare class IDB2BTrigger implements INodeType {
3
+ description: INodeTypeDescription;
4
+ poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null>;
5
+ }
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IDB2BTrigger = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const httpClient_1 = require("../IDB2B/utils/httpClient");
6
+ const tokenCache_1 = require("../IDB2B/utils/tokenCache");
7
+ const common_1 = require("../IDB2B/utils/common");
8
+ const constants_1 = require("../IDB2B/config/constants");
9
+ class IDB2BTrigger {
10
+ constructor() {
11
+ this.description = {
12
+ displayName: "IDB2B Trigger",
13
+ name: "idb2bTrigger",
14
+ icon: "file:../IDB2B/Icon.svg",
15
+ group: ["trigger"],
16
+ version: 1,
17
+ subtitle: '={{$parameter["event"]}}',
18
+ description: "Polls IDB2B for new or updated contacts, companies, and activities",
19
+ defaults: {
20
+ name: "IDB2B Trigger",
21
+ },
22
+ polling: true,
23
+ inputs: [],
24
+ outputs: ["main"],
25
+ credentials: [
26
+ {
27
+ name: "idb2bApi",
28
+ required: true,
29
+ },
30
+ ],
31
+ properties: [
32
+ {
33
+ displayName: "Event",
34
+ name: "event",
35
+ type: "options",
36
+ noDataExpression: true,
37
+ options: [
38
+ {
39
+ name: "Contact Created",
40
+ value: "contactCreated",
41
+ description: "Triggers when a new contact is created",
42
+ },
43
+ {
44
+ name: "Contact Updated",
45
+ value: "contactUpdated",
46
+ description: "Triggers when a contact is updated",
47
+ },
48
+ {
49
+ name: "Company Created",
50
+ value: "companyCreated",
51
+ description: "Triggers when a new company is created",
52
+ },
53
+ {
54
+ name: "Company Updated",
55
+ value: "companyUpdated",
56
+ description: "Triggers when a company is updated",
57
+ },
58
+ {
59
+ name: "Activity Created (Under Company)",
60
+ value: "activityCreated",
61
+ description: "Triggers when a new activity is created for a specific company",
62
+ },
63
+ ],
64
+ default: "contactCreated",
65
+ },
66
+ // Company ID required for activity trigger
67
+ {
68
+ displayName: "Company ID",
69
+ name: "companyId",
70
+ type: "string",
71
+ default: "",
72
+ required: true,
73
+ displayOptions: {
74
+ show: {
75
+ event: ["activityCreated"],
76
+ },
77
+ },
78
+ description: "ID of the company/lead to watch for new activities",
79
+ },
80
+ {
81
+ displayName: "Limit",
82
+ name: "limit",
83
+ type: "number",
84
+ default: constants_1.PAGINATION.DEFAULT_LIMIT,
85
+ description: "Maximum number of records to fetch per poll cycle",
86
+ },
87
+ ],
88
+ };
89
+ }
90
+ async poll() {
91
+ const webhookData = this.getWorkflowStaticData("node");
92
+ const event = this.getNodeParameter("event");
93
+ const limit = this.getNodeParameter("limit", constants_1.PAGINATION.DEFAULT_LIMIT);
94
+ const credentials = await this.getCredentials("idb2bApi");
95
+ const baseUrl = credentials.baseUrl;
96
+ tokenCache_1.secureTokenCache.cleanupIfNeeded();
97
+ const accessToken = await (0, httpClient_1.getAccessToken)(this, credentials);
98
+ const httpClient = new httpClient_1.HttpClient(this);
99
+ // Determine the timestamp field and endpoint for this event
100
+ const isUpdate = event === "contactUpdated" || event === "companyUpdated";
101
+ const timestampField = isUpdate ? "updated_at" : "created_at";
102
+ // On first run, use now minus 1 minute as the baseline
103
+ const now = new Date();
104
+ const lastCheck = webhookData.lastCheck;
105
+ const since = lastCheck !== null && lastCheck !== void 0 ? lastCheck : new Date(now.getTime() - 60000).toISOString();
106
+ let endpoint;
107
+ if (event === "contactCreated" || event === "contactUpdated") {
108
+ endpoint = constants_1.ENDPOINTS.CONTACTS;
109
+ }
110
+ else if (event === "companyCreated" || event === "companyUpdated") {
111
+ endpoint = constants_1.ENDPOINTS.COMPANIES;
112
+ }
113
+ else {
114
+ // activityCreated
115
+ const companyId = this.getNodeParameter("companyId");
116
+ if (!companyId) {
117
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), "Company ID is required for the Activity Created trigger");
118
+ }
119
+ endpoint = `/leads/${(0, common_1.sanitizeId)(companyId)}/activities`;
120
+ }
121
+ let response;
122
+ try {
123
+ response = await httpClient.makeRequest({
124
+ method: "GET",
125
+ url: `${baseUrl}${endpoint}`,
126
+ headers: {
127
+ Authorization: `Bearer ${accessToken}`,
128
+ },
129
+ qs: {
130
+ limit,
131
+ page: 1,
132
+ sort_by: timestampField,
133
+ sort_order: "desc",
134
+ },
135
+ json: true,
136
+ });
137
+ }
138
+ catch (error) {
139
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error);
140
+ }
141
+ // Update the last check timestamp
142
+ webhookData.lastCheck = now.toISOString();
143
+ const records = Array.isArray(response === null || response === void 0 ? void 0 : response.data)
144
+ ? response.data
145
+ : Array.isArray(response)
146
+ ? response
147
+ : [];
148
+ // Filter to only records newer than our last check
149
+ const newRecords = records.filter((record) => {
150
+ const ts = record[timestampField];
151
+ if (!ts)
152
+ return false;
153
+ return new Date(ts) > new Date(since);
154
+ });
155
+ if (newRecords.length === 0) {
156
+ return null;
157
+ }
158
+ return [
159
+ newRecords.map((record) => ({
160
+ json: record,
161
+ })),
162
+ ];
163
+ }
164
+ }
165
+ exports.IDB2BTrigger = IDB2BTrigger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-idb2b",
3
- "version": "3.2.4",
3
+ "version": "3.2.5",
4
4
  "description": "n8n community node for IDB2B - WhatsApp AI Agents",
5
5
  "main": "index.js",
6
6
  "scripts": {