@ixiam/n8n-nodes-civicrm 0.3.8 → 0.3.9

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.
package/README.md CHANGED
@@ -9,4 +9,5 @@ Credentials:
9
9
  - Use the **Save** button to verify connectivity.
10
10
 
11
11
  Entities: Contact, Event, Case, Contribution, Membership → `get|getMany|create|update|delete`
12
- Form Processor: `execute` with `recordsJson`
12
+
13
+ Node developed by Ixiam Global Solution: `https://www.ixiam.com'
@@ -35,6 +35,21 @@ class CiviCrm {
35
35
  properties: [
36
36
  resources_1.resourceProp,
37
37
  resources_1.operationProp,
38
+ {
39
+ displayName: 'Contact Type',
40
+ name: 'contactType',
41
+ type: 'options',
42
+ default: 'Individual',
43
+ options: [
44
+ { name: 'Individual', value: 'Individual' },
45
+ { name: 'Organization', value: 'Organization' },
46
+ { name: 'Household', value: 'Household' },
47
+ ],
48
+ displayOptions: {
49
+ show: { resource: ['contact'] },
50
+ },
51
+ description: 'Filter or assign contact type',
52
+ },
38
53
  {
39
54
  displayName: 'ID',
40
55
  name: 'id',
@@ -83,28 +98,44 @@ class CiviCrm {
83
98
  // === GET ===
84
99
  if (operation === 'get') {
85
100
  const id = this.getNodeParameter('id', i);
86
- const params = {
87
- where: [['id', '=', id]],
88
- limit: 1,
89
- select: [
90
- 'id',
91
- 'display_name',
92
- 'first_name',
93
- 'last_name',
94
- 'contact_type',
95
- 'email.email',
96
- 'phone.phone',
97
- 'address.city',
98
- 'address.country_id:label',
99
- 'address.postal_code',
100
- 'address.street_address',
101
- ],
102
- join: [
103
- ['Email AS email', 'LEFT'],
104
- ['Phone AS phone', 'LEFT'],
105
- ['Address AS address', 'LEFT'],
106
- ],
107
- };
101
+ const contactType = this.getNodeParameter('contactType', i, '');
102
+ const where = [['id', '=', id]];
103
+ if (resource === 'contact' && contactType) {
104
+ where.push(['contact_type', '=', contactType]);
105
+ }
106
+ let params;
107
+ if (resource === 'contact') {
108
+ params = {
109
+ where,
110
+ limit: 1,
111
+ select: [
112
+ 'id',
113
+ 'display_name',
114
+ 'first_name',
115
+ 'last_name',
116
+ 'contact_type',
117
+ 'email.email',
118
+ 'phone.phone',
119
+ 'address.city',
120
+ 'address.country_id:label',
121
+ 'address.postal_code',
122
+ 'address.street_address',
123
+ ],
124
+ join: [
125
+ ['Email AS email', 'LEFT'],
126
+ ['Phone AS phone', 'LEFT'],
127
+ ['Address AS address', 'LEFT'],
128
+ ],
129
+ };
130
+ }
131
+ else {
132
+ // otras entidades: select básico
133
+ params = {
134
+ where,
135
+ limit: 1,
136
+ select: ['id', 'title', 'subject', 'display_name', 'name'],
137
+ };
138
+ }
108
139
  const res = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/${entity}/get`, params);
109
140
  out.push({ json: (res?.values?.[0] ?? {}) });
110
141
  }
@@ -113,28 +144,38 @@ class CiviCrm {
113
144
  const returnAll = this.getNodeParameter('returnAll', i, false);
114
145
  const limit = this.getNodeParameter('limit', i, 100);
115
146
  const whereJson = this.getNodeParameter('whereJson', i, '');
116
- const where = whereJson ? JSON.parse(whereJson) : undefined;
117
- const baseParams = {
118
- where,
119
- select: [
120
- 'id',
121
- 'display_name',
122
- 'first_name',
123
- 'last_name',
124
- 'contact_type',
125
- 'email.email',
126
- 'phone.phone',
127
- 'address.city',
128
- 'address.country_id:label',
129
- 'address.postal_code',
130
- 'address.street_address',
131
- ],
132
- join: [
133
- ['Email AS email', 'LEFT'],
134
- ['Phone AS phone', 'LEFT'],
135
- ['Address AS address', 'LEFT'],
136
- ],
137
- };
147
+ const contactType = this.getNodeParameter('contactType', i, '');
148
+ let where = whereJson ? JSON.parse(whereJson) : [];
149
+ if (resource === 'contact' && contactType) {
150
+ where.push(['contact_type', '=', contactType]);
151
+ }
152
+ let baseParams;
153
+ if (resource === 'contact') {
154
+ baseParams = {
155
+ where,
156
+ select: [
157
+ 'id',
158
+ 'display_name',
159
+ 'first_name',
160
+ 'last_name',
161
+ 'contact_type',
162
+ 'email.email',
163
+ 'phone.phone',
164
+ 'address.city',
165
+ 'address.country_id:label',
166
+ 'address.postal_code',
167
+ 'address.street_address',
168
+ ],
169
+ join: [
170
+ ['Email AS email', 'LEFT'],
171
+ ['Phone AS phone', 'LEFT'],
172
+ ['Address AS address', 'LEFT'],
173
+ ],
174
+ };
175
+ }
176
+ else {
177
+ baseParams = { where, select: ['id', 'title', 'subject', 'display_name', 'name'] };
178
+ }
138
179
  if (returnAll) {
139
180
  let offset = 0;
140
181
  const page = 500;
@@ -161,6 +202,10 @@ class CiviCrm {
161
202
  const values = Object.fromEntries(pairs
162
203
  .filter((p) => p.fieldName)
163
204
  .map((p) => [p.fieldName, convertValue(p.fieldValue)]));
205
+ const contactType = this.getNodeParameter('contactType', i, '');
206
+ if (resource === 'contact' && contactType) {
207
+ values.contact_type = contactType;
208
+ }
164
209
  const params = { values };
165
210
  const res = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/${entity}/create`, params);
166
211
  out.push({ json: res });
@@ -172,6 +217,10 @@ class CiviCrm {
172
217
  const values = Object.fromEntries(pairs
173
218
  .filter((p) => p.fieldName)
174
219
  .map((p) => [p.fieldName, convertValue(p.fieldValue)]));
220
+ const contactType = this.getNodeParameter('contactType', i, '');
221
+ if (resource === 'contact' && contactType) {
222
+ values.contact_type = contactType;
223
+ }
175
224
  const params = {
176
225
  values,
177
226
  where: [['id', '=', id]],
@@ -60,6 +60,21 @@ export class CiviCrm implements INodeType {
60
60
  properties: [
61
61
  resourceProp,
62
62
  operationProp,
63
+ {
64
+ displayName: 'Contact Type',
65
+ name: 'contactType',
66
+ type: 'options',
67
+ default: 'Individual',
68
+ options: [
69
+ { name: 'Individual', value: 'Individual' },
70
+ { name: 'Organization', value: 'Organization' },
71
+ { name: 'Household', value: 'Household' },
72
+ ],
73
+ displayOptions: {
74
+ show: { resource: ['contact'] },
75
+ },
76
+ description: 'Filter or assign contact type',
77
+ },
63
78
  {
64
79
  displayName: 'ID',
65
80
  name: 'id',
@@ -114,32 +129,50 @@ export class CiviCrm implements INodeType {
114
129
  const entity = ENTITY_MAP[resource];
115
130
 
116
131
  for (let i = 0; i < items.length; i++) {
117
- // === GET ===
132
+
133
+ // === GET ===
118
134
  if (operation === 'get') {
119
135
  const id = this.getNodeParameter('id', i) as number;
136
+ const contactType = this.getNodeParameter('contactType', i, '') as string;
137
+
138
+ const where = [['id', '=', id]];
139
+ if (resource === 'contact' && contactType) {
140
+ where.push(['contact_type', '=', contactType]);
141
+ }
120
142
 
121
- const params = {
122
- where: [['id', '=', id]],
123
- limit: 1,
124
- select: [
125
- 'id',
126
- 'display_name',
127
- 'first_name',
128
- 'last_name',
129
- 'contact_type',
130
- 'email.email',
131
- 'phone.phone',
132
- 'address.city',
133
- 'address.country_id:label',
134
- 'address.postal_code',
135
- 'address.street_address',
136
- ],
137
- join: [
138
- ['Email AS email', 'LEFT'],
139
- ['Phone AS phone', 'LEFT'],
140
- ['Address AS address', 'LEFT'],
141
- ],
142
- };
143
+ let params: Record<string, unknown>;
144
+
145
+ if (resource === 'contact') {
146
+ params = {
147
+ where,
148
+ limit: 1,
149
+ select: [
150
+ 'id',
151
+ 'display_name',
152
+ 'first_name',
153
+ 'last_name',
154
+ 'contact_type',
155
+ 'email.email',
156
+ 'phone.phone',
157
+ 'address.city',
158
+ 'address.country_id:label',
159
+ 'address.postal_code',
160
+ 'address.street_address',
161
+ ],
162
+ join: [
163
+ ['Email AS email', 'LEFT'],
164
+ ['Phone AS phone', 'LEFT'],
165
+ ['Address AS address', 'LEFT'],
166
+ ],
167
+ };
168
+ } else {
169
+ // otras entidades: select básico
170
+ params = {
171
+ where,
172
+ limit: 1,
173
+ select: ['id', 'title', 'subject', 'display_name', 'name'],
174
+ };
175
+ }
143
176
 
144
177
  const res = await civicrmApiRequest.call(
145
178
  this,
@@ -156,29 +189,40 @@ if (operation === 'getMany') {
156
189
  const returnAll = this.getNodeParameter('returnAll', i, false) as boolean;
157
190
  const limit = this.getNodeParameter('limit', i, 100) as number;
158
191
  const whereJson = this.getNodeParameter('whereJson', i, '') as string;
159
- const where = whereJson ? JSON.parse(whereJson) : undefined;
160
-
161
- const baseParams = {
162
- where,
163
- select: [
164
- 'id',
165
- 'display_name',
166
- 'first_name',
167
- 'last_name',
168
- 'contact_type',
169
- 'email.email',
170
- 'phone.phone',
171
- 'address.city',
172
- 'address.country_id:label',
173
- 'address.postal_code',
174
- 'address.street_address',
175
- ],
176
- join: [
177
- ['Email AS email', 'LEFT'],
178
- ['Phone AS phone', 'LEFT'],
179
- ['Address AS address', 'LEFT'],
180
- ],
181
- };
192
+ const contactType = this.getNodeParameter('contactType', i, '') as string;
193
+
194
+ let where = whereJson ? JSON.parse(whereJson) : [];
195
+ if (resource === 'contact' && contactType) {
196
+ where.push(['contact_type', '=', contactType]);
197
+ }
198
+
199
+ let baseParams: Record<string, unknown>;
200
+
201
+ if (resource === 'contact') {
202
+ baseParams = {
203
+ where,
204
+ select: [
205
+ 'id',
206
+ 'display_name',
207
+ 'first_name',
208
+ 'last_name',
209
+ 'contact_type',
210
+ 'email.email',
211
+ 'phone.phone',
212
+ 'address.city',
213
+ 'address.country_id:label',
214
+ 'address.postal_code',
215
+ 'address.street_address',
216
+ ],
217
+ join: [
218
+ ['Email AS email', 'LEFT'],
219
+ ['Phone AS phone', 'LEFT'],
220
+ ['Address AS address', 'LEFT'],
221
+ ],
222
+ };
223
+ } else {
224
+ baseParams = { where, select: ['id', 'title', 'subject', 'display_name', 'name'] };
225
+ }
182
226
 
183
227
  if (returnAll) {
184
228
  let offset = 0;
@@ -207,7 +251,6 @@ if (operation === 'getMany') {
207
251
  }
208
252
  }
209
253
 
210
-
211
254
  // === CREATE ===
212
255
  if (operation === 'create') {
213
256
  const pairs = this.getNodeParameter('fields.field', i, []) as Array<{
@@ -221,6 +264,11 @@ if (operation === 'getMany') {
221
264
  .map((p) => [p.fieldName, convertValue(p.fieldValue)]),
222
265
  );
223
266
 
267
+ const contactType = this.getNodeParameter('contactType', i, '') as string;
268
+ if (resource === 'contact' && contactType) {
269
+ values.contact_type = contactType;
270
+ }
271
+
224
272
  const params = { values };
225
273
 
226
274
  const res = await civicrmApiRequest.call(
@@ -246,6 +294,11 @@ if (operation === 'getMany') {
246
294
  .map((p) => [p.fieldName, convertValue(p.fieldValue)]),
247
295
  );
248
296
 
297
+ const contactType = this.getNodeParameter('contactType', i, '') as string;
298
+ if (resource === 'contact' && contactType) {
299
+ values.contact_type = contactType;
300
+ }
301
+
249
302
  const params = {
250
303
  values,
251
304
  where: [['id', '=', id]],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ixiam/n8n-nodes-civicrm",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "CiviCRM API v4",
5
5
  "license": "MIT",
6
6
  "keywords": [