@ixiam/n8n-nodes-civicrm 0.2.0 → 0.2.2
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.
|
@@ -30,6 +30,33 @@ class CiviCrm {
|
|
|
30
30
|
properties: [
|
|
31
31
|
resources_1.resourceProp,
|
|
32
32
|
resources_1.operationProp,
|
|
33
|
+
// GET MANY controls
|
|
34
|
+
{
|
|
35
|
+
displayName: 'Return All',
|
|
36
|
+
name: 'returnAll',
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
default: false,
|
|
39
|
+
description: 'Whether to return all results (ignores Limit)',
|
|
40
|
+
displayOptions: { show: { operation: ['getMany'] } },
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
displayName: 'Limit',
|
|
44
|
+
name: 'limit',
|
|
45
|
+
type: 'number',
|
|
46
|
+
default: 100,
|
|
47
|
+
description: 'Max number of records to return',
|
|
48
|
+
typeOptions: { minValue: 1, maxValue: 500 },
|
|
49
|
+
displayOptions: { show: { operation: ['getMany'], returnAll: [false] } },
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
displayName: 'Where (JSON)',
|
|
53
|
+
name: 'whereJson',
|
|
54
|
+
type: 'string',
|
|
55
|
+
default: '',
|
|
56
|
+
placeholder: '[["first_name","=","Alice"]] or {"contact_type":"Individual"}',
|
|
57
|
+
description: 'API4 where clause as JSON (array of conditions or simple object)',
|
|
58
|
+
displayOptions: { show: { operation: ['getMany'] } },
|
|
59
|
+
},
|
|
33
60
|
{
|
|
34
61
|
displayName: 'ID',
|
|
35
62
|
name: 'id',
|
|
@@ -40,23 +67,6 @@ class CiviCrm {
|
|
|
40
67
|
},
|
|
41
68
|
...generic_1.genericFields,
|
|
42
69
|
...generic_1.upsertFields,
|
|
43
|
-
{
|
|
44
|
-
displayName: 'Processor Name',
|
|
45
|
-
name: 'processor',
|
|
46
|
-
type: 'string',
|
|
47
|
-
default: '',
|
|
48
|
-
placeholder: 'fp_volunteer_registration',
|
|
49
|
-
description: 'Technical name after FormProcessor_',
|
|
50
|
-
displayOptions: { show: { resource: ['formProcessor'], operation: ['execute'] } },
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
displayName: 'Records (JSON)',
|
|
54
|
-
name: 'recordsJson',
|
|
55
|
-
type: 'string',
|
|
56
|
-
default: '',
|
|
57
|
-
placeholder: `[{"first_name":"Alice"}]`,
|
|
58
|
-
displayOptions: { show: { resource: ['formProcessor'], operation: ['execute'] } },
|
|
59
|
-
},
|
|
60
70
|
],
|
|
61
71
|
};
|
|
62
72
|
this.methods = {
|
|
@@ -89,15 +99,6 @@ class CiviCrm {
|
|
|
89
99
|
const resource = this.getNodeParameter('resource', 0);
|
|
90
100
|
const operation = this.getNodeParameter('operation', 0);
|
|
91
101
|
for (let i = 0; i < items.length; i++) {
|
|
92
|
-
// FORM PROCESSOR
|
|
93
|
-
if (resource === 'formProcessor' && operation === 'execute') {
|
|
94
|
-
const processor = this.getNodeParameter('processor', i);
|
|
95
|
-
const recordsJson = this.getNodeParameter('recordsJson', i, '');
|
|
96
|
-
const records = recordsJson ? JSON.parse(recordsJson) : [];
|
|
97
|
-
const res = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/FormProcessor_${processor}/save`, { params: { records } });
|
|
98
|
-
out.push({ json: res });
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
102
|
const entity = ENTITY_MAP[resource];
|
|
102
103
|
// GET
|
|
103
104
|
if (operation === 'get') {
|
|
@@ -110,7 +111,16 @@ class CiviCrm {
|
|
|
110
111
|
const returnAll = this.getNodeParameter('returnAll', i, false);
|
|
111
112
|
const limit = this.getNodeParameter('limit', i, 100);
|
|
112
113
|
const whereJson = this.getNodeParameter('whereJson', i, '');
|
|
113
|
-
|
|
114
|
+
let where = whereJson ? JSON.parse(whereJson) : undefined;
|
|
115
|
+
// Normalize where: allow object or array; API4 accepts both
|
|
116
|
+
if (where && typeof where === 'object' && !Array.isArray(where)) {
|
|
117
|
+
where = where;
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(where)) {
|
|
120
|
+
// leave as-is; expected [[field, op, value], ...]
|
|
121
|
+
}
|
|
122
|
+
// Cap limit to a reasonable page size
|
|
123
|
+
const cappedLimit = Math.max(1, Math.min(limit, 500));
|
|
114
124
|
if (returnAll) {
|
|
115
125
|
let offset = 0;
|
|
116
126
|
const page = 500;
|
|
@@ -125,7 +135,7 @@ class CiviCrm {
|
|
|
125
135
|
}
|
|
126
136
|
}
|
|
127
137
|
else {
|
|
128
|
-
const res = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/${entity}/get`, (0, GenericFunctions_1.api4)(entity, 'get', { where, limit }));
|
|
138
|
+
const res = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/${entity}/get`, (0, GenericFunctions_1.api4)(entity, 'get', { where, limit: cappedLimit }));
|
|
129
139
|
const vals = (res?.values ?? []);
|
|
130
140
|
for (const v of vals)
|
|
131
141
|
out.push({ json: v });
|
|
@@ -7,7 +7,6 @@ const RESOURCE_OPTIONS = [
|
|
|
7
7
|
{ name: 'Case', value: 'case' },
|
|
8
8
|
{ name: 'Contribution', value: 'contribution' },
|
|
9
9
|
{ name: 'Membership', value: 'membership' },
|
|
10
|
-
{ name: 'Form Processor', value: 'formProcessor' },
|
|
11
10
|
];
|
|
12
11
|
exports.resourceProp = {
|
|
13
12
|
displayName: 'Resource',
|
|
@@ -21,7 +20,7 @@ exports.operationProp = {
|
|
|
21
20
|
name: 'operation',
|
|
22
21
|
type: 'options',
|
|
23
22
|
displayOptions: {
|
|
24
|
-
show: { resource: ['contact', 'event', 'case', 'contribution', 'membership'
|
|
23
|
+
show: { resource: ['contact', 'event', 'case', 'contribution', 'membership'] },
|
|
25
24
|
},
|
|
26
25
|
default: 'get',
|
|
27
26
|
options: [
|
|
@@ -30,7 +29,5 @@ exports.operationProp = {
|
|
|
30
29
|
{ name: 'Create', value: 'create' },
|
|
31
30
|
{ name: 'Update', value: 'update' },
|
|
32
31
|
{ name: 'Delete', value: 'delete' },
|
|
33
|
-
// Solo para formProcessor
|
|
34
|
-
{ name: 'Execute', value: 'execute', action: 'Execute FormProcessor', description: 'Run a FormProcessor', },
|
|
35
32
|
], // tipo mutable
|
|
36
33
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ixiam/n8n-nodes-civicrm",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "CiviCRM API v4 for n8n",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
"README.md",
|
|
17
17
|
"LICENSE"
|
|
18
18
|
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "n8n-node dev",
|
|
21
|
+
"build": "n8n-node build",
|
|
22
|
+
"lint": "n8n-node lint",
|
|
23
|
+
"release": "n8n-node release"
|
|
24
|
+
},
|
|
19
25
|
"n8n": {
|
|
20
26
|
"nodes": [
|
|
21
27
|
"dist/nodes/CiviCrm/CiviCrm.node.js"
|
|
@@ -46,10 +52,13 @@
|
|
|
46
52
|
"n8n-workflow": "^1",
|
|
47
53
|
"typescript": "5.3.3"
|
|
48
54
|
},
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
55
|
+
"pnpm": {
|
|
56
|
+
"overrides": {
|
|
57
|
+
"eslint": "8.57.0",
|
|
58
|
+
"@typescript-eslint/parser": "6.21.0",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "6.21.0",
|
|
60
|
+
"change-case": "4.1.2"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"packageManager": "pnpm@10.18.2+sha512.9fb969fa749b3ade6035e0f109f0b8a60b5d08a1a87fdf72e337da90dcc93336e2280ca4e44f2358a649b83c17959e9993e777c2080879f3801e6f0d999ad3dd"
|
|
64
|
+
}
|