data-primals-engine 1.3.3-rc.1 → 1.3.3

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.
@@ -1121,6 +1121,8 @@ h2.shadow {
1121
1121
  text-align: left;
1122
1122
  font-size: 75%;
1123
1123
  direction: ltr;
1124
+ max-height: 480px;
1125
+ overflow-y: scroll;
1124
1126
  }
1125
1127
 
1126
1128
  .react-tooltip{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-primals-engine",
3
- "version": "1.3.3-rc.1",
3
+ "version": "1.3.3",
4
4
  "description": "data-primals-engine is a package responsible from handling large amount of data using MongoDB in a practical and performant way. It can also get workflow models working (for automation), and fully supports internationalisation. It also has integrated AI assistant.",
5
5
  "main": "src/engine.js",
6
6
  "type": "module",
package/src/filter.js CHANGED
@@ -1,251 +1,257 @@
1
- /**
2
- * Evaluates a single condition against form data.
3
- * @param {object} currentModelDef - The definition of the current model.
4
- * @param {object} condition - The condition to evaluate.
5
- * @param {object} formData - The form data.
6
- * @param {object[]} allModels - An array of all model definitions.
7
- * @param {object} user - The current user.
8
- * @returns {boolean} - True if the condition is met, false otherwise.
9
- */
10
- const evaluateSingleCondition = (currentModelDef, condition, formData, allModels, user) => {
11
- // Condition est directement un filtre MongoDB, donc on l'applique
12
- // en utilisant les opérateurs et les valeurs qu'il contient.
13
-
14
- if (!condition || typeof condition !== 'object') {
15
- console.warn("[Client Eval] Condition is not an object:", condition);
16
- return true; // Permissive default
17
- }
18
-
19
- // Si la condition est de la forme {field: value}, on la transforme en {$eq: value}
20
- if (!Object.keys(condition)[0].startsWith('$') && typeof condition[Object.keys(condition)[0]] !== 'object') {
21
- const fieldName = Object.keys(condition)[0];
22
- const value = condition[fieldName];
23
- return evaluateSingleCondition(currentModelDef, {[fieldName]: {$eq: value}}, formData, allModels, user);
24
- }
25
-
26
- // Gestion des opérateurs d'agrégation (commencent par $)
27
- const operator = Object.keys(condition)[0];
28
- if (operator === '$eq' && Array.isArray(condition[operator])) {
29
- // Cas spécial pour {$eq: ['$field', value]}
30
- const [fieldPath, expectedValue] = condition[operator];
31
- if (typeof fieldPath === 'string' && fieldPath.startsWith('$')) {
32
- const fieldName = fieldPath.substring(1); // Enlève le $ devant
33
- return formData[fieldName] == expectedValue;
34
- }
35
- }
36
-
37
- // Si la condition contient des opérateurs logiques, on les gère ici
38
- if (condition.$and || condition.$or || condition.$not || condition.$nor) {
39
- console.warn("[Client Eval] Condition logique détectée dans evaluateSingleCondition, ce n'est pas attendu. Devrait être géré par isConditionMet.");
40
- return true; // Permissive default
41
- }
42
-
43
- if (condition.$find) {
44
- const fieldName = Object.keys(condition)[0];
45
- const fieldValue = formData[fieldName];
46
- const findCondition = condition.$find;
47
-
48
- if (!Array.isArray(fieldValue)) return false;
49
-
50
- return fieldValue.some(item => {
51
- // Gestion spéciale pour la syntaxe $eq: ["$$this.field", value]
52
- if (findCondition.$eq && Array.isArray(findCondition.$eq)) {
53
- const [fieldPath, value] = findCondition.$eq;
54
- if (fieldPath.startsWith("$$this.")) {
55
- const fieldToCheck = fieldPath.replace("$$this.", "");
56
- return item[fieldToCheck] == value;
57
- }
58
- }
59
-
60
- // Sinon, évaluation normale
61
- const tempData = { ...item };
62
- return evaluateSingleCondition(currentModelDef, findCondition, tempData, allModels, user);
63
- });
64
- }
65
-
66
- // Si la condition contient un opérateur $exists, on le gère ici
67
- if (condition.$exists !== undefined) {
68
- const fieldName = Object.keys(condition)[0]; // Récupérer le nom du champ
69
- const shouldExist = condition.$exists; // Récupérer la valeur de $exists (true ou false)
70
- const exists = Object.prototype.hasOwnProperty.call(formData, fieldName) && formData[fieldName] !== undefined && formData[fieldName] !== null;
71
- return exists === shouldExist;
72
- }
73
-
74
- // Si la condition contient un opérateur $find, on le gère ici
75
- if (condition.$find) {
76
- // Récupérer le nom du champ
77
- const fieldName = Object.keys(condition)[0];
78
- const fieldValue = formData[fieldName];
79
- try {
80
- // Assuming evaluateSingleCondition handles $find
81
- return evaluateSingleCondition(currentModelDef, condition.$find, formData, allModels, user);
82
- } catch (error) {
83
- console.error("Error evaluating $find condition:", condition, error);
84
- return false;
85
- }
86
- }
87
-
88
- // Récupérer le nom du champ et la condition
89
- const fieldName = Object.keys(condition)[0];
90
- const fieldValue = condition[fieldName];
91
-
92
- // Récupérer la définition du champ
93
- const fieldDef = currentModelDef?.fields.find(f => f.name === fieldName);
94
-
95
- // Si la définition du champ n'est pas trouvée, on retourne true
96
- if (!fieldDef) {
97
- console.warn(`[Client Eval] Field definition not found for field: ${fieldName}`);
98
- return true; // Permissive default
99
- }
100
-
101
- let targetValue = formData[fieldName];
102
- let processedConditionValue = fieldValue;
103
-
104
- // 1. Handle $exists (on the first field)
105
- // 2. Convert condition value based on operator's expected input type
106
- const fieldType = fieldDef?.type; // Type of the first field
107
-
108
- try {
109
- processedConditionValue = convertValueType(fieldValue, fieldType);
110
- } catch (e) {
111
- logClientEvalWarning(`Error converting value type: ${e.message}`, condition);
112
- return false;
113
- }
114
-
115
- return evaluateComparison(fieldValue, targetValue, processedConditionValue, condition);
116
-
117
- function logClientEvalWarning(message, details) {
118
- console.warn(`[Client Eval] ${message}:`, details);
119
- }
120
-
121
- function convertValueType(value, inputType) {
122
- switch (inputType) {
123
- case 'number':
124
- const numValue = parseFloat(value);
125
- if (isNaN(numValue)) {
126
- throw new Error(`Invalid number value: ${value}`);
127
- }
128
- return numValue;
129
- case 'boolean':
130
- return String(value).toLowerCase() === 'true';
131
- case 'csv':
132
- return String(value).split(',').map(item => item.trim()).filter(Boolean);
133
- case 'text':
134
- default:
135
- return String(value);
136
- }
137
- }
138
-
139
- function evaluateComparison(operator, targetValue, processedConditionValue, condition) {
140
- try {
141
- switch (typeof operator === 'object' ? Object.keys(operator)[0] : null) {
142
- case '$eq': return targetValue == processedConditionValue;
143
- case '$ne': return targetValue != processedConditionValue;
144
- case '$gt': return targetValue > processedConditionValue;
145
- case '$lt': return targetValue < processedConditionValue;
146
- case '$gte': return targetValue >= processedConditionValue;
147
- case '$lte': return targetValue <= processedConditionValue;
148
- case '$regex':
149
- if (typeof targetValue !== 'string') return false;
150
- if (typeof processedConditionValue !== 'string') return false;
151
- try {
152
- const regex = new RegExp(processedConditionValue, 'i');
153
- return regex.test(targetValue);
154
- } catch (e) {
155
- logClientEvalWarning(`Invalid regex pattern: ${processedConditionValue}`, condition);
156
- return false;
157
- }
158
- case '$in':
159
- return Array.isArray(processedConditionValue) && processedConditionValue.includes(String(targetValue));
160
- case '$nin':
161
- return !Array.isArray(processedConditionValue) || !processedConditionValue.includes(String(targetValue));
162
- default:
163
- logClientEvalWarning(`Unhandled operator in client evaluation logic: ${operator}`, condition);
164
- return true; // Permissive default
165
- }
166
- } catch (evalError) {
167
- logClientEvalWarning(`Error during client condition evaluation: ${operator}, targetValue=${targetValue}, processedConditionValue=${processedConditionValue}`, condition);
168
- return false;
169
- }
170
- }
171
- };
172
-
173
- export const isConditionMet = (model, cond, formData, allModels, user) => {
174
- const condition = cond;
175
-
176
- if (!condition) return true;
177
-
178
- // Cas 0: Condition est une valeur primitive (string, number, boolean)
179
- // On la considère comme toujours vraie (comportement de searchData)
180
- if (typeof condition !== 'object' || condition === null) {
181
- return true;
182
- }
183
-
184
- // Cas 1: Condition simple {field: value} → transformée en {field: {$eq: value}}
185
- if (typeof condition === 'object' && !Array.isArray(condition)) {
186
- const keys = Object.keys(condition);
187
-
188
- // Cas spécial pour les conditions de type {field: value} (pas d'opérateur $)
189
- if (keys.length === 1 && !keys[0].startsWith('$') &&
190
- typeof condition[keys[0]] !== 'object') {
191
- const fieldName = keys[0];
192
- const value = condition[fieldName];
193
-
194
- // Si la valeur est null/undefined, on vérifie simplement l'existence
195
- if (value === null || value === undefined) {
196
- return formData[fieldName] === value;
197
- }
198
-
199
- // Sinon on fait une comparaison d'égalité simple
200
- return formData[fieldName] == value;
201
- }
202
-
203
- // Cas spécial pour les tableaux - vérifie si la valeur est incluse
204
- if (keys.length === 1 && !keys[0].startsWith('$') &&
205
- Array.isArray(condition[keys[0]])) {
206
- const fieldName = keys[0];
207
- const values = condition[fieldName];
208
- const fieldValue = formData[fieldName];
209
-
210
- // Si le champ est aussi un tableau, vérifie l'intersection
211
- if (Array.isArray(fieldValue)) {
212
- return fieldValue.some(v => values.includes(v));
213
- }
214
-
215
- // Sinon vérifie si la valeur est dans le tableau
216
- return values.includes(fieldValue);
217
- }
218
- }
219
-
220
- // Cas 2: Opérateurs logiques ($and, $or, $not, $nor)
221
- if (condition.$and && Array.isArray(condition.$and)) {
222
- if (condition.$and.length === 0) return true;
223
- return condition.$and.every(sub => isConditionMet(model, sub, formData, allModels, user));
224
- }
225
-
226
- if (condition.$or && Array.isArray(condition.$or)) {
227
- if (condition.$or.length === 0) return false;
228
- return condition.$or.some(sub => isConditionMet(model, sub, formData, allModels, user));
229
- }
230
-
231
- if (condition.$not) {
232
- return !isConditionMet(model, condition.$not, formData, allModels, user);
233
- }
234
-
235
- if (condition.$nor && Array.isArray(condition.$nor)) {
236
- if (condition.$nor.length === 0) return true;
237
- return !condition.$nor.some(sub => isConditionMet(model, sub, formData, allModels, user));
238
- }
239
-
240
- // Cas 3: Syntaxe d'agrégation {$eq: ['$field', value]}
241
- if (Object.keys(condition).length === 1) {
242
- const operator = Object.keys(condition)[0];
243
- if (operator.startsWith('$') && operator !== '$find' &&
244
- Array.isArray(condition[operator])) {
245
- return evaluateSingleCondition(model, condition, formData, allModels, user);
246
- }
247
- }
248
-
249
- // Cas 4: Tous les autres cas (conditions normales avec opérateurs)
250
- return evaluateSingleCondition(model, condition, formData, allModels, user);
1
+ /**
2
+ * Evaluates a single condition against form data.
3
+ * @param {object} currentModelDef - The definition of the current model.
4
+ * @param {object} condition - The condition to evaluate.
5
+ * @param {object} formData - The form data.
6
+ * @param {object[]} allModels - An array of all model definitions.
7
+ * @param {object} user - The current user.
8
+ * @returns {boolean} - True if the condition is met, false otherwise.
9
+ */
10
+ const evaluateSingleCondition = (currentModelDef, condition, formData, allModels, user) => {
11
+ // Condition est directement un filtre MongoDB, donc on l'applique
12
+ // en utilisant les opérateurs et les valeurs qu'il contient.
13
+
14
+ if (!condition || typeof condition !== 'object') {
15
+ console.warn("[Client Eval] Condition is not an object:", condition);
16
+ return true; // Permissive default
17
+ }
18
+
19
+ // Si la condition est de la forme {field: value}, on la transforme en {$eq: value}
20
+ if (!Object.keys(condition)[0].startsWith('$') && typeof condition[Object.keys(condition)[0]] !== 'object') {
21
+ const fieldName = Object.keys(condition)[0];
22
+ const value = condition[fieldName];
23
+ return evaluateSingleCondition(currentModelDef, {[fieldName]: {$eq: value}}, formData, allModels, user);
24
+ }
25
+
26
+ // Gestion des opérateurs d'agrégation (commencent par $)
27
+ const operator = Object.keys(condition)[0];
28
+ if (operator === '$eq' && Array.isArray(condition[operator])) {
29
+ // Cas spécial pour {$eq: ['$field', value]}
30
+ const [fieldPath, expectedValue] = condition[operator];
31
+ if (typeof fieldPath === 'string' && fieldPath.startsWith('$')) {
32
+ const fieldName = fieldPath.substring(1); // Enlève le $ devant
33
+ return formData[fieldName] == expectedValue;
34
+ }
35
+ }
36
+
37
+ // Si la condition contient des opérateurs logiques, on les gère ici
38
+ if (condition.$and || condition.$or || condition.$not || condition.$nor) {
39
+ console.warn("[Client Eval] Condition logique détectée dans evaluateSingleCondition, ce n'est pas attendu. Devrait être géré par isConditionMet.");
40
+ return true; // Permissive default
41
+ }
42
+
43
+ if (condition.$find) {
44
+ const fieldName = Object.keys(condition)[0];
45
+ const fieldValue = formData[fieldName];
46
+ const findCondition = condition.$find;
47
+
48
+ if (!Array.isArray(fieldValue)) return false;
49
+
50
+ return fieldValue.some(item => {
51
+ // Gestion spéciale pour la syntaxe $eq: ["$$this.field", value]
52
+ if (findCondition.$eq && Array.isArray(findCondition.$eq)) {
53
+ const [fieldPath, value] = findCondition.$eq;
54
+ if (fieldPath.startsWith("$$this.")) {
55
+ const fieldToCheck = fieldPath.replace("$$this.", "");
56
+ return item[fieldToCheck] == value;
57
+ }
58
+ }
59
+
60
+ // Sinon, évaluation normale
61
+ const tempData = { ...item };
62
+ return evaluateSingleCondition(currentModelDef, findCondition, tempData, allModels, user);
63
+ });
64
+ }
65
+
66
+ // Si la condition contient un opérateur $exists, on le gère ici
67
+ if (condition.$exists !== undefined) {
68
+ const fieldName = Object.keys(condition)[0]; // Récupérer le nom du champ
69
+ const shouldExist = condition.$exists; // Récupérer la valeur de $exists (true ou false)
70
+ const exists = Object.prototype.hasOwnProperty.call(formData, fieldName) && formData[fieldName] !== undefined && formData[fieldName] !== null;
71
+ return exists === shouldExist;
72
+ }
73
+
74
+ // Si la condition contient un opérateur $find, on le gère ici
75
+ if (condition.$find) {
76
+ // Récupérer le nom du champ
77
+ const fieldName = Object.keys(condition)[0];
78
+ const fieldValue = formData[fieldName];
79
+ try {
80
+ // Assuming evaluateSingleCondition handles $find
81
+ return evaluateSingleCondition(currentModelDef, condition.$find, formData, allModels, user);
82
+ } catch (error) {
83
+ console.error("Error evaluating $find condition:", condition, error);
84
+ return false;
85
+ }
86
+ }
87
+
88
+ // Récupérer le nom du champ et la condition
89
+ const fieldName = Object.keys(condition)[0];
90
+ const fieldValue = condition[fieldName];
91
+
92
+ // Récupérer la définition du champ
93
+ const fieldDef = currentModelDef?.fields.find(f => f.name === fieldName);
94
+
95
+ // Si la définition du champ n'est pas trouvée, on retourne true
96
+ if (!fieldDef) {
97
+ console.warn(`[Client Eval] Field definition not found for field: ${fieldName}`);
98
+ return true; // Permissive default
99
+ }
100
+
101
+ let targetValue = formData[fieldName];
102
+ let processedConditionValue = fieldValue;
103
+
104
+ // 1. Handle $exists (on the first field)
105
+ // 2. Convert condition value based on operator's expected input type
106
+ const fieldType = fieldDef?.type; // Type of the first field
107
+
108
+ try {
109
+ processedConditionValue = convertValueType(fieldValue, fieldType);
110
+ } catch (e) {
111
+ logClientEvalWarning(`Error converting value type: ${e.message}`, condition);
112
+ return false;
113
+ }
114
+
115
+ return evaluateComparison(fieldValue, targetValue, processedConditionValue, condition);
116
+
117
+ function logClientEvalWarning(message, details) {
118
+ console.warn(`[Client Eval] ${message}:`, details);
119
+ }
120
+
121
+ function convertValueType(value, inputType) {
122
+ switch (inputType) {
123
+ case 'number':
124
+ const numValue = parseFloat(value);
125
+ if (isNaN(numValue)) {
126
+ throw new Error(`Invalid number value: ${value}`);
127
+ }
128
+ return numValue;
129
+ case 'boolean':
130
+ return String(value).toLowerCase() === 'true';
131
+ case 'csv':
132
+ return String(value).split(',').map(item => item.trim()).filter(Boolean);
133
+ case 'text':
134
+ default:
135
+ return String(value);
136
+ }
137
+ }
138
+
139
+ function evaluateComparison(operator, targetValue, processedConditionValue, condition) {
140
+ try {
141
+ switch (typeof operator === 'object' ? Object.keys(operator)[0] : null) {
142
+ case '$eq': return targetValue === processedConditionValue;
143
+ case '$ne': return targetValue !== processedConditionValue;
144
+ case '$gt': return targetValue > processedConditionValue;
145
+ case '$lt': return targetValue < processedConditionValue;
146
+ case '$gte': return targetValue >= processedConditionValue;
147
+ case '$lte': return targetValue <= processedConditionValue;
148
+ case '$regex':
149
+ if (typeof targetValue !== 'string') return false;
150
+ if (typeof processedConditionValue !== 'string') return false;
151
+ try {
152
+ const regex = new RegExp(processedConditionValue, 'i');
153
+ return regex.test(targetValue);
154
+ } catch (e) {
155
+ logClientEvalWarning(`Invalid regex pattern: ${processedConditionValue}`, condition);
156
+ return false;
157
+ }
158
+ case '$in':
159
+ return Array.isArray(processedConditionValue) && processedConditionValue.includes(String(targetValue));
160
+ case '$nin':
161
+ return !Array.isArray(processedConditionValue) || !processedConditionValue.includes(String(targetValue));
162
+ default:
163
+ logClientEvalWarning(`Unhandled operator in client evaluation logic: ${operator}`, condition);
164
+ return true; // Permissive default
165
+ }
166
+ } catch (evalError) {
167
+ logClientEvalWarning(`Error during client condition evaluation: ${operator}, targetValue=${targetValue}, processedConditionValue=${processedConditionValue}`, condition);
168
+ return false;
169
+ }
170
+ }
171
+ };
172
+
173
+ export const isConditionMet = (model, cond, formData, allModels, user) => {
174
+ const condition = cond;
175
+
176
+ if (!condition) return true;
177
+
178
+ if (typeof condition !== 'object' || condition === null) {
179
+ return true;
180
+ }
181
+
182
+ // Cas spécial: Évaluation sans modèle (ex: pour les webhooks où la condition est déjà résolue)
183
+ // Dans ce mode, la condition doit être un objet avec un seul opérateur.
184
+ if (!model) {
185
+ const keys = Object.keys(condition);
186
+ if (keys.length !== 1 || !keys[0].startsWith('$')) {
187
+ console.warn('[isConditionMet] Condition invalide pour une évaluation sans modèle. Attendu : { "$opérateur": [...] }. Reçu :', condition);
188
+ return false; // Plus sûr que true pour éviter les faux positifs
189
+ }
190
+
191
+ const operator = keys[0];
192
+ const operands = condition[operator];
193
+
194
+ switch (operator) {
195
+ // Opérateurs logiques (récursifs)
196
+ case '$and':
197
+ return Array.isArray(operands) && operands.every(sub => isConditionMet(null, sub, formData, allModels, user));
198
+ case '$or':
199
+ return Array.isArray(operands) && operands.some(sub => isConditionMet(null, sub, formData, allModels, user));
200
+ case '$not':
201
+ return !isConditionMet(null, operands, formData, allModels, user);
202
+ case '$nor':
203
+ return Array.isArray(operands) && !operands.some(sub => isConditionMet(null, sub, formData, allModels, user));
204
+
205
+ // Opérateurs de comparaison (terminaux)
206
+ case '$eq':
207
+ return Array.isArray(operands) && operands[0] === operands[1];
208
+ case '$ne':
209
+ return Array.isArray(operands) && operands[0] !== operands[1];
210
+ case '$in':
211
+ return Array.isArray(operands) && Array.isArray(operands[1]) && operands[1].includes(operands[0]);
212
+ case '$nin':
213
+ return Array.isArray(operands) && Array.isArray(operands[1]) && !operands[1].includes(operands[0]);
214
+ case '$gt':
215
+ return Array.isArray(operands) && operands[0] > operands[1];
216
+ case '$gte':
217
+ return Array.isArray(operands) && operands[0] >= operands[1];
218
+ case '$lt':
219
+ return Array.isArray(operands) && operands[0] < operands[1];
220
+ case '$lte':
221
+ return Array.isArray(operands) && operands[0] <= operands[1];
222
+
223
+ default:
224
+ console.warn(`[isConditionMet] Opérateur non supporté '${operator}' pour une évaluation sans modèle.`);
225
+ return false;
226
+ }
227
+ }
228
+
229
+ // --- Logique existante pour l'évaluation AVEC modèle ---
230
+
231
+ if (condition.$and && Array.isArray(condition.$and)) {
232
+ if (condition.$and.length === 0) return true;
233
+ return condition.$and.every(sub => isConditionMet(model, sub, formData, allModels, user));
234
+ }
235
+ if (condition.$or && Array.isArray(condition.$or)) {
236
+ if (condition.$or.length === 0) return false;
237
+ return condition.$or.some(sub => isConditionMet(model, sub, formData, allModels, user));
238
+ }
239
+ if (condition.$not) {
240
+ return !isConditionMet(model, condition.$not, formData, allModels, user);
241
+ }
242
+ if (condition.$nor && Array.isArray(condition.$nor)) {
243
+ if (condition.$nor.length === 0) return true;
244
+ return !condition.$nor.some(sub => isConditionMet(model, sub, formData, allModels, user));
245
+ }
246
+
247
+ // Cas 3: Syntaxe d'agrégation {$eq: ['$field', value]}
248
+ if (Object.keys(condition).length === 1) {
249
+ const operator = Object.keys(condition)[0];
250
+ if (operator.startsWith('$') && operator !== '$find' &&
251
+ Array.isArray(condition[operator])) {
252
+ return evaluateSingleCondition(model, condition, formData, allModels, user);
253
+ }
254
+ }
255
+
256
+ return evaluateSingleCondition(model, condition, formData, allModels, user);
251
257
  };
@@ -1075,7 +1075,8 @@ export const editModel = async (user, id, data) => {
1075
1075
  export async function middlewareEndpointAuthenticator(req, res, next) {
1076
1076
  const { path } = req.params;
1077
1077
  const method = req.method.toUpperCase();
1078
- const datasCollection = getCollection('datas');
1078
+ const user = await engine.userProvider.findUserByUsername(req.query._user || req.params.user || req.me.username);
1079
+ const datasCollection = await getCollectionForUser(user);
1079
1080
 
1080
1081
  try {
1081
1082
  const endpointDef = await datasCollection.findOne({
@@ -1137,7 +1138,9 @@ export async function handleCustomEndpointRequest(req, res) {
1137
1138
  // 2. Préparer le contexte pour le script
1138
1139
  const contextData = {
1139
1140
  request: {
1140
- body: req.fields,
1141
+ // MODIFICATION: Utiliser req.body si disponible (pour les requêtes JSON comme les webhooks Stripe),
1142
+ // sinon, utiliser req.fields (pour les données de formulaire).
1143
+ body: (req.body && Object.keys(req.body).length > 0) ? req.body : (req.fields || {}),
1141
1144
  query: req.query,
1142
1145
  params: req.params,
1143
1146
  headers: req.headers
@@ -161,7 +161,8 @@ export async function registerRoutes(engine){
161
161
 
162
162
  logger = engine.getComponent(Logger);
163
163
 
164
- engine.all('/api/actions/:path', [middlewareEndpointAuthenticator, userInitiator], handleCustomEndpointRequest);
164
+ engine.all('/api/actions/:user/:path', [middlewareEndpointAuthenticator, userInitiator], handleCustomEndpointRequest);
165
+ engine.all('/api/actions/:path', [middlewareAuthenticator, middlewareEndpointAuthenticator, userInitiator], handleCustomEndpointRequest);
165
166
  engine.post('/api/demo/initialize', [middlewareAuthenticator, userInitiator], handleDemoInitialization);
166
167
 
167
168
  engine.post('/api/magnets', [middlewareAuthenticator, userInitiator], async (req, res) => {