@ixiam/n8n-nodes-civicrm 0.2.2 → 0.2.4

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,33 +30,6 @@ 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
- },
60
33
  {
61
34
  displayName: 'ID',
62
35
  name: 'id',
@@ -111,7 +84,15 @@ class CiviCrm {
111
84
  const returnAll = this.getNodeParameter('returnAll', i, false);
112
85
  const limit = this.getNodeParameter('limit', i, 100);
113
86
  const whereJson = this.getNodeParameter('whereJson', i, '');
114
- let where = whereJson ? JSON.parse(whereJson) : undefined;
87
+ let where;
88
+ if (whereJson) {
89
+ try {
90
+ where = JSON.parse(whereJson);
91
+ }
92
+ catch (e) {
93
+ throw new Error('Where (JSON) debe ser JSON válido: usa un objeto o un array de condiciones.');
94
+ }
95
+ }
115
96
  // Normalize where: allow object or array; API4 accepts both
116
97
  if (where && typeof where === 'object' && !Array.isArray(where)) {
117
98
  where = where;
@@ -135,8 +116,11 @@ class CiviCrm {
135
116
  }
136
117
  }
137
118
  else {
138
- const res = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/${entity}/get`, (0, GenericFunctions_1.api4)(entity, 'get', { where, limit: cappedLimit }));
139
- const vals = (res?.values ?? []);
119
+ const res = await GenericFunctions_1.civicrmApiRequest.call(this, 'POST', `/civicrm/ajax/api4/${entity}/get`, (0, GenericFunctions_1.api4)(entity, 'get', { where, limit: cappedLimit, offset: 0 }));
120
+ let vals = (res?.values ?? []);
121
+ if (vals.length > cappedLimit) {
122
+ vals = vals.slice(0, cappedLimit);
123
+ }
140
124
  for (const v of vals)
141
125
  out.push({ json: v });
142
126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ixiam/n8n-nodes-civicrm",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "CiviCRM API v4 for n8n",
5
5
  "license": "MIT",
6
6
  "keywords": [