data-primals-engine 1.5.2 → 1.6.1

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.
Files changed (70) hide show
  1. package/README.md +938 -915
  2. package/client/README.md +136 -136
  3. package/client/index.js +0 -1
  4. package/client/public/doc/API.postman_collection.json +213 -213
  5. package/client/public/react.svg +9 -9
  6. package/client/src/AddWidgetTypeModal.jsx +47 -47
  7. package/client/src/App.css +42 -42
  8. package/client/src/App.jsx +92 -150
  9. package/client/src/App.scss +6 -0
  10. package/client/src/AssistantChat.jsx +362 -363
  11. package/client/src/Button.jsx +12 -12
  12. package/client/src/Dashboard.jsx +480 -480
  13. package/client/src/DashboardHtmlViewItem.jsx +146 -146
  14. package/client/src/DashboardView.jsx +654 -654
  15. package/client/src/DataEditor.jsx +383 -383
  16. package/client/src/DataLayout.jsx +779 -808
  17. package/client/src/DataTable.jsx +782 -822
  18. package/client/src/DataTable.scss +186 -186
  19. package/client/src/GeolocationField.jsx +93 -93
  20. package/client/src/HistoryDialog.jsx +307 -307
  21. package/client/src/HistoryDialog.scss +319 -319
  22. package/client/src/HtmlViewBuilderModal.jsx +90 -90
  23. package/client/src/HtmlViewBuilderModal.scss +17 -17
  24. package/client/src/HtmlViewCard.jsx +43 -43
  25. package/client/src/ModelCreator.jsx +683 -686
  26. package/client/src/ModelCreator.scss +1 -1
  27. package/client/src/ModelCreatorField.jsx +950 -950
  28. package/client/src/ModelImporter.jsx +3 -0
  29. package/client/src/ModelList.jsx +280 -280
  30. package/client/src/Notification.jsx +136 -136
  31. package/client/src/PackGallery.jsx +391 -391
  32. package/client/src/PackGallery.scss +231 -231
  33. package/client/src/Pagination.jsx +143 -143
  34. package/client/src/RelationField.jsx +354 -354
  35. package/client/src/RelationSelectorWidget.jsx +172 -172
  36. package/client/src/RelationValue.jsx +2 -1
  37. package/client/src/contexts/CommandContext.jsx +260 -0
  38. package/client/src/contexts/ModelContext.jsx +4 -1
  39. package/client/src/contexts/UIContext.jsx +72 -72
  40. package/client/src/filter.js +263 -263
  41. package/client/src/index.css +90 -90
  42. package/package.json +6 -5
  43. package/perf/artillery-hooks.js +37 -37
  44. package/perf/setup.yml +25 -25
  45. package/src/constants.js +4 -0
  46. package/src/defaultModels.js +7 -0
  47. package/src/engine.js +335 -335
  48. package/src/events.js +232 -137
  49. package/src/filter.js +274 -274
  50. package/src/index.js +1 -0
  51. package/src/modules/assistant/assistant.js +225 -83
  52. package/src/modules/auth-google/index.js +50 -50
  53. package/src/modules/auth-microsoft/index.js +81 -81
  54. package/src/modules/data/data.core.js +118 -118
  55. package/src/modules/data/data.history.js +555 -555
  56. package/src/modules/data/data.operations.js +112 -9
  57. package/src/modules/data/data.relations.js +686 -686
  58. package/src/modules/data/data.routes.js +1879 -1879
  59. package/src/modules/data/data.validation.js +2 -2
  60. package/src/modules/file.js +247 -247
  61. package/src/modules/user.js +14 -9
  62. package/src/packs.js +2 -2
  63. package/src/providers.js +2 -2
  64. package/src/services/stripe.js +196 -196
  65. package/src/sso.js +193 -193
  66. package/test/data.history.integration.test.js +264 -264
  67. package/test/data.integration.test.js +1281 -1206
  68. package/test/events.test.js +108 -10
  69. package/test/model.integration.test.js +377 -377
  70. package/test/user.test.js +106 -1
package/src/filter.js CHANGED
@@ -1,275 +1,275 @@
1
-
2
- let safeRegex = null; // Par défaut, aucune fonction de validation n'est définie.
3
-
4
- /**
5
- * Permet d'injecter une fonction de validation de regex (côté serveur).
6
- * @param {function} validator - La fonction qui valide une regex, ex: la fonction du module 'safe-regex'.
7
- */
8
- export function setSafeRegex(validator) {
9
- safeRegex = validator;
10
- }
11
-
12
- /**
13
- * Evaluates a single condition against form data.
14
- * @param {object} currentModelDef - The definition of the current model.
15
- * @param {object} condition - The condition to evaluate.
16
- * @param {object} formData - The form data.
17
- * @param {object[]} allModels - An array of all model definitions.
18
- * @param {object} user - The current user.
19
- * @returns {boolean} - True if the condition is met, false otherwise.
20
- */
21
- const evaluateSingleCondition = (currentModelDef, condition, formData, allModels, user, checkRegex =true) => {
22
- // Condition est directement un filtre MongoDB, donc on l'applique
23
- // en utilisant les opérateurs et les valeurs qu'il contient.
24
-
25
- if (!condition || typeof condition !== 'object') {
26
- console.warn("[Client Eval] Condition is not an object:", condition);
27
- return true; // Permissive default
28
- }
29
-
30
- // Si la condition est de la forme {field: value}, on la transforme en {$eq: value}
31
- if (!Object.keys(condition)[0].startsWith('$') && typeof condition[Object.keys(condition)[0]] !== 'object') {
32
- const fieldName = Object.keys(condition)[0];
33
- const value = condition[fieldName];
34
- return evaluateSingleCondition(currentModelDef, {[fieldName]: {$eq: value}}, formData, allModels, user);
35
- }
36
-
37
- // Gestion des opérateurs d'agrégation (commencent par $)
38
- const operator = Object.keys(condition)[0];
39
- if ((operator === '$eq' || operator === '$ne') && Array.isArray(condition[operator])) {
40
- // Cas spécial pour {$op: ['$field', value]}
41
- const [fieldPath, expectedValue] = condition[operator];
42
- if (typeof fieldPath === 'string' && fieldPath.startsWith('$')) {
43
- const fieldName = fieldPath.substring(1); // Enlève le $ devant
44
- const actualValue = formData[fieldName];
45
- if (operator === '$eq') return actualValue == expectedValue;
46
- if (operator === '$ne') return actualValue != expectedValue;
47
- }
48
- }
49
-
50
- // Si la condition contient des opérateurs logiques, on les gère ici
51
- if (condition.$and || condition.$or || condition.$not || condition.$nor) {
52
- console.warn("[Client Eval] Condition logique détectée dans evaluateSingleCondition, ce n'est pas attendu. Devrait être géré par isConditionMet.");
53
- return true; // Permissive default
54
- }
55
-
56
- if (condition.$find) {
57
- const fieldName = Object.keys(condition)[0];
58
- const fieldValue = formData[fieldName];
59
- const findCondition = condition.$find;
60
-
61
- if (!Array.isArray(fieldValue)) return false;
62
-
63
- return fieldValue.some(item => {
64
- // Gestion spéciale pour la syntaxe $eq: ["$$this.field", value]
65
- if (findCondition.$eq && Array.isArray(findCondition.$eq)) {
66
- const [fieldPath, value] = findCondition.$eq;
67
- if (fieldPath.startsWith("$$this.")) {
68
- const fieldToCheck = fieldPath.replace("$$this.", "");
69
- return item[fieldToCheck] == value;
70
- }
71
- }
72
-
73
- // Sinon, évaluation normale
74
- const tempData = { ...item };
75
- return evaluateSingleCondition(currentModelDef, findCondition, tempData, allModels, user);
76
- });
77
- }
78
-
79
- // Si la condition contient un opérateur $exists, on le gère ici
80
- if (condition.$exists !== undefined) {
81
- const fieldName = Object.keys(condition)[0]; // Récupérer le nom du champ
82
- const shouldExist = condition.$exists; // Récupérer la valeur de $exists (true ou false)
83
- const exists = Object.prototype.hasOwnProperty.call(formData, fieldName) && formData[fieldName] !== undefined && formData[fieldName] !== null;
84
- return exists === shouldExist;
85
- }
86
-
87
- // Si la condition contient un opérateur $find, on le gère ici
88
- if (condition.$find) {
89
- // Récupérer le nom du champ
90
- const fieldName = Object.keys(condition)[0];
91
- const fieldValue = formData[fieldName];
92
- try {
93
- // Assuming evaluateSingleCondition handles $find
94
- return evaluateSingleCondition(currentModelDef, condition.$find, formData, allModels, user);
95
- } catch (error) {
96
- console.error("Error evaluating $find condition:", condition, error);
97
- return false;
98
- }
99
- }
100
-
101
- // Récupérer le nom du champ et la condition
102
- const fieldName = Object.keys(condition)[0];
103
- const fieldValue = condition[fieldName];
104
-
105
- // Récupérer la définition du champ
106
- const fieldDef = currentModelDef?.fields.find(f => f.name === fieldName);
107
-
108
- // Si la définition du champ n'est pas trouvée, on retourne true
109
- if (!fieldDef) {
110
- console.warn(`[Client Eval] Field definition not found for field: ${fieldName}`);
111
- return true; // Permissive default
112
- }
113
-
114
- let targetValue = formData[fieldName];
115
- let processedConditionValue = fieldValue;
116
-
117
- // 1. Handle $exists (on the first field)
118
- // 2. Convert condition value based on operator's expected input type
119
- const fieldType = fieldDef?.type; // Type of the first field
120
-
121
- try {
122
- processedConditionValue = convertValueType(fieldValue, fieldType);
123
- } catch (e) {
124
- logClientEvalWarning(`Error converting value type: ${e.message}`, condition);
125
- return false;
126
- }
127
-
128
- return evaluateComparison(fieldValue, targetValue, processedConditionValue, condition);
129
-
130
- function logClientEvalWarning(message, details) {
131
- console.warn(`[Client Eval] ${message}:`, details);
132
- }
133
-
134
- function convertValueType(value, inputType) {
135
- switch (inputType) {
136
- case 'number':
137
- const numValue = parseFloat(value);
138
- if (isNaN(numValue)) {
139
- throw new Error(`Invalid number value: ${value}`);
140
- }
141
- return numValue;
142
- case 'boolean':
143
- return String(value).toLowerCase() === 'true';
144
- case 'csv':
145
- return String(value).split(',').map(item => item.trim()).filter(Boolean);
146
- case 'text':
147
- default:
148
- return String(value);
149
- }
150
- }
151
-
152
- function evaluateComparison(operator, targetValue, processedConditionValue, condition) {
153
- try {
154
- switch (typeof operator === 'object' ? Object.keys(operator)[0] : null) {
155
- case '$eq': return targetValue === processedConditionValue;
156
- case '$ne': return targetValue !== processedConditionValue;
157
- case '$gt': return targetValue > processedConditionValue;
158
- case '$lt': return targetValue < processedConditionValue;
159
- case '$gte': return targetValue >= processedConditionValue;
160
- case '$lte': return targetValue <= processedConditionValue;
161
- case '$regex':
162
- if (typeof targetValue !== 'string') return false;
163
- if (typeof processedConditionValue !== 'string') return false;
164
- try {
165
- // On vérifie si la fonction a été injectée ET si la regex est sûre.
166
- // Côté client, `safeRegex` sera null, donc la vérification est simplement ignorée.
167
- if( checkRegex && safeRegex && safeRegex(processedConditionValue)) {
168
- const regex = new RegExp(processedConditionValue, 'i');
169
- return regex.test(targetValue);
170
- }
171
- return false;
172
- } catch (e) {
173
- logClientEvalWarning(`Invalid regex pattern: ${processedConditionValue}`, condition);
174
- return false;
175
- }
176
- case '$in':
177
- return Array.isArray(processedConditionValue) && processedConditionValue.includes(String(targetValue));
178
- case '$nin':
179
- return !Array.isArray(processedConditionValue) || !processedConditionValue.includes(String(targetValue));
180
- default:
181
- logClientEvalWarning(`Unhandled operator in client evaluation logic: ${operator}`, condition);
182
- return true; // Permissive default
183
- }
184
- } catch (evalError) {
185
- logClientEvalWarning(`Error during client condition evaluation: ${operator}, targetValue=${targetValue}, processedConditionValue=${processedConditionValue}`, condition);
186
- return false;
187
- }
188
- }
189
- };
190
-
191
- export const isConditionMet = (model, cond, formData, allModels, user,checkRegex=true) => {
192
- const condition = cond;
193
-
194
- if (!condition) return true;
195
-
196
- if (typeof condition !== 'object' || condition === null) {
197
- return true;
198
- }
199
-
200
- // Cas spécial: Évaluation sans modèle (ex: pour les webhooks où la condition est déjà résolue)
201
- // Dans ce mode, la condition doit être un objet avec un seul opérateur.
202
- if (!model) {
203
- const keys = Object.keys(condition);
204
- if (keys.length !== 1 || !keys[0].startsWith('$')) {
205
- console.warn('[isConditionMet] Condition invalide pour une évaluation sans modèle. Attendu : { "$opérateur": [...] }. Reçu :', condition);
206
- return false; // Plus sûr que true pour éviter les faux positifs
207
- }
208
-
209
- const operator = keys[0];
210
- const operands = condition[operator];
211
-
212
- switch (operator) {
213
- // Opérateurs logiques (récursifs)
214
- case '$and':
215
- return Array.isArray(operands) && operands.every(sub => isConditionMet(null, sub, formData, allModels, user,checkRegex));
216
- case '$or':
217
- return Array.isArray(operands) && operands.some(sub => isConditionMet(null, sub, formData, allModels, user,checkRegex));
218
- case '$not':
219
- return !isConditionMet(null, operands, formData, allModels, user);
220
- case '$nor':
221
- return Array.isArray(operands) && !operands.some(sub => isConditionMet(null, sub, formData, allModels, user,checkRegex));
222
-
223
- // Opérateurs de comparaison (terminaux)
224
- case '$eq':
225
- return Array.isArray(operands) && operands[0] === operands[1];
226
- case '$ne':
227
- return Array.isArray(operands) && operands[0] !== operands[1];
228
- case '$in':
229
- return Array.isArray(operands) && Array.isArray(operands[1]) && operands[1].includes(operands[0]);
230
- case '$nin':
231
- return Array.isArray(operands) && Array.isArray(operands[1]) && !operands[1].includes(operands[0]);
232
- case '$gt':
233
- return Array.isArray(operands) && operands[0] > operands[1];
234
- case '$gte':
235
- return Array.isArray(operands) && operands[0] >= operands[1];
236
- case '$lt':
237
- return Array.isArray(operands) && operands[0] < operands[1];
238
- case '$lte':
239
- return Array.isArray(operands) && operands[0] <= operands[1];
240
-
241
- default:
242
- console.warn(`[isConditionMet] Opérateur non supporté '${operator}' pour une évaluation sans modèle.`);
243
- return false;
244
- }
245
- }
246
-
247
- // --- Logique existante pour l'évaluation AVEC modèle ---
248
-
249
- if (condition.$and && Array.isArray(condition.$and)) {
250
- if (condition.$and.length === 0) return true;
251
- return condition.$and.every(sub => isConditionMet(model, sub, formData, allModels, user,checkRegex));
252
- }
253
- if (condition.$or && Array.isArray(condition.$or)) {
254
- if (condition.$or.length === 0) return false;
255
- return condition.$or.some(sub => isConditionMet(model, sub, formData, allModels, user,checkRegex));
256
- }
257
- if (condition.$not) {
258
- return !isConditionMet(model, condition.$not, formData, allModels, user,checkRegex);
259
- }
260
- if (condition.$nor && Array.isArray(condition.$nor)) {
261
- if (condition.$nor.length === 0) return true;
262
- return !condition.$nor.some(sub => isConditionMet(model, sub, formData, allModels, user,checkRegex));
263
- }
264
-
265
- // Cas 3: Syntaxe d'agrégation {$eq: ['$field', value]}
266
- if (Object.keys(condition).length === 1) {
267
- const operator = Object.keys(condition)[0];
268
- if (operator.startsWith('$') && operator !== '$find' &&
269
- Array.isArray(condition[operator])) {
270
- return evaluateSingleCondition(model, condition, formData, allModels, user,checkRegex);
271
- }
272
- }
273
-
274
- return evaluateSingleCondition(model, condition, formData, allModels, user, checkRegex);
1
+
2
+ let safeRegex = null; // Par défaut, aucune fonction de validation n'est définie.
3
+
4
+ /**
5
+ * Permet d'injecter une fonction de validation de regex (côté serveur).
6
+ * @param {function} validator - La fonction qui valide une regex, ex: la fonction du module 'safe-regex'.
7
+ */
8
+ export function setSafeRegex(validator) {
9
+ safeRegex = validator;
10
+ }
11
+
12
+ /**
13
+ * Evaluates a single condition against form data.
14
+ * @param {object} currentModelDef - The definition of the current model.
15
+ * @param {object} condition - The condition to evaluate.
16
+ * @param {object} formData - The form data.
17
+ * @param {object[]} allModels - An array of all model definitions.
18
+ * @param {object} user - The current user.
19
+ * @returns {boolean} - True if the condition is met, false otherwise.
20
+ */
21
+ const evaluateSingleCondition = (currentModelDef, condition, formData, allModels, user, checkRegex =true) => {
22
+ // Condition est directement un filtre MongoDB, donc on l'applique
23
+ // en utilisant les opérateurs et les valeurs qu'il contient.
24
+
25
+ if (!condition || typeof condition !== 'object') {
26
+ console.warn("[Client Eval] Condition is not an object:", condition);
27
+ return true; // Permissive default
28
+ }
29
+
30
+ // Si la condition est de la forme {field: value}, on la transforme en {$eq: value}
31
+ if (!Object.keys(condition)[0].startsWith('$') && typeof condition[Object.keys(condition)[0]] !== 'object') {
32
+ const fieldName = Object.keys(condition)[0];
33
+ const value = condition[fieldName];
34
+ return evaluateSingleCondition(currentModelDef, {[fieldName]: {$eq: value}}, formData, allModels, user);
35
+ }
36
+
37
+ // Gestion des opérateurs d'agrégation (commencent par $)
38
+ const operator = Object.keys(condition)[0];
39
+ if ((operator === '$eq' || operator === '$ne') && Array.isArray(condition[operator])) {
40
+ // Cas spécial pour {$op: ['$field', value]}
41
+ const [fieldPath, expectedValue] = condition[operator];
42
+ if (typeof fieldPath === 'string' && fieldPath.startsWith('$')) {
43
+ const fieldName = fieldPath.substring(1); // Enlève le $ devant
44
+ const actualValue = formData[fieldName];
45
+ if (operator === '$eq') return actualValue == expectedValue;
46
+ if (operator === '$ne') return actualValue != expectedValue;
47
+ }
48
+ }
49
+
50
+ // Si la condition contient des opérateurs logiques, on les gère ici
51
+ if (condition.$and || condition.$or || condition.$not || condition.$nor) {
52
+ console.warn("[Client Eval] Condition logique détectée dans evaluateSingleCondition, ce n'est pas attendu. Devrait être géré par isConditionMet.");
53
+ return true; // Permissive default
54
+ }
55
+
56
+ if (condition.$find) {
57
+ const fieldName = Object.keys(condition)[0];
58
+ const fieldValue = formData[fieldName];
59
+ const findCondition = condition.$find;
60
+
61
+ if (!Array.isArray(fieldValue)) return false;
62
+
63
+ return fieldValue.some(item => {
64
+ // Gestion spéciale pour la syntaxe $eq: ["$$this.field", value]
65
+ if (findCondition.$eq && Array.isArray(findCondition.$eq)) {
66
+ const [fieldPath, value] = findCondition.$eq;
67
+ if (fieldPath.startsWith("$$this.")) {
68
+ const fieldToCheck = fieldPath.replace("$$this.", "");
69
+ return item[fieldToCheck] == value;
70
+ }
71
+ }
72
+
73
+ // Sinon, évaluation normale
74
+ const tempData = { ...item };
75
+ return evaluateSingleCondition(currentModelDef, findCondition, tempData, allModels, user);
76
+ });
77
+ }
78
+
79
+ // Si la condition contient un opérateur $exists, on le gère ici
80
+ if (condition.$exists !== undefined) {
81
+ const fieldName = Object.keys(condition)[0]; // Récupérer le nom du champ
82
+ const shouldExist = condition.$exists; // Récupérer la valeur de $exists (true ou false)
83
+ const exists = Object.prototype.hasOwnProperty.call(formData, fieldName) && formData[fieldName] !== undefined && formData[fieldName] !== null;
84
+ return exists === shouldExist;
85
+ }
86
+
87
+ // Si la condition contient un opérateur $find, on le gère ici
88
+ if (condition.$find) {
89
+ // Récupérer le nom du champ
90
+ const fieldName = Object.keys(condition)[0];
91
+ const fieldValue = formData[fieldName];
92
+ try {
93
+ // Assuming evaluateSingleCondition handles $find
94
+ return evaluateSingleCondition(currentModelDef, condition.$find, formData, allModels, user);
95
+ } catch (error) {
96
+ console.error("Error evaluating $find condition:", condition, error);
97
+ return false;
98
+ }
99
+ }
100
+
101
+ // Récupérer le nom du champ et la condition
102
+ const fieldName = Object.keys(condition)[0];
103
+ const fieldValue = condition[fieldName];
104
+
105
+ // Récupérer la définition du champ
106
+ const fieldDef = currentModelDef?.fields.find(f => f.name === fieldName);
107
+
108
+ // Si la définition du champ n'est pas trouvée, on retourne true
109
+ if (!fieldDef) {
110
+ console.warn(`[Client Eval] Field definition not found for field: ${fieldName}`);
111
+ return true; // Permissive default
112
+ }
113
+
114
+ let targetValue = formData[fieldName];
115
+ let processedConditionValue = fieldValue;
116
+
117
+ // 1. Handle $exists (on the first field)
118
+ // 2. Convert condition value based on operator's expected input type
119
+ const fieldType = fieldDef?.type; // Type of the first field
120
+
121
+ try {
122
+ processedConditionValue = convertValueType(fieldValue, fieldType);
123
+ } catch (e) {
124
+ logClientEvalWarning(`Error converting value type: ${e.message}`, condition);
125
+ return false;
126
+ }
127
+
128
+ return evaluateComparison(fieldValue, targetValue, processedConditionValue, condition);
129
+
130
+ function logClientEvalWarning(message, details) {
131
+ console.warn(`[Client Eval] ${message}:`, details);
132
+ }
133
+
134
+ function convertValueType(value, inputType) {
135
+ switch (inputType) {
136
+ case 'number':
137
+ const numValue = parseFloat(value);
138
+ if (isNaN(numValue)) {
139
+ throw new Error(`Invalid number value: ${value}`);
140
+ }
141
+ return numValue;
142
+ case 'boolean':
143
+ return String(value).toLowerCase() === 'true';
144
+ case 'csv':
145
+ return String(value).split(',').map(item => item.trim()).filter(Boolean);
146
+ case 'text':
147
+ default:
148
+ return String(value);
149
+ }
150
+ }
151
+
152
+ function evaluateComparison(operator, targetValue, processedConditionValue, condition) {
153
+ try {
154
+ switch (typeof operator === 'object' ? Object.keys(operator)[0] : null) {
155
+ case '$eq': return targetValue === processedConditionValue;
156
+ case '$ne': return targetValue !== processedConditionValue;
157
+ case '$gt': return targetValue > processedConditionValue;
158
+ case '$lt': return targetValue < processedConditionValue;
159
+ case '$gte': return targetValue >= processedConditionValue;
160
+ case '$lte': return targetValue <= processedConditionValue;
161
+ case '$regex':
162
+ if (typeof targetValue !== 'string') return false;
163
+ if (typeof processedConditionValue !== 'string') return false;
164
+ try {
165
+ // On vérifie si la fonction a été injectée ET si la regex est sûre.
166
+ // Côté client, `safeRegex` sera null, donc la vérification est simplement ignorée.
167
+ if( checkRegex && safeRegex && safeRegex(processedConditionValue)) {
168
+ const regex = new RegExp(processedConditionValue, 'i');
169
+ return regex.test(targetValue);
170
+ }
171
+ return false;
172
+ } catch (e) {
173
+ logClientEvalWarning(`Invalid regex pattern: ${processedConditionValue}`, condition);
174
+ return false;
175
+ }
176
+ case '$in':
177
+ return Array.isArray(processedConditionValue) && processedConditionValue.includes(String(targetValue));
178
+ case '$nin':
179
+ return !Array.isArray(processedConditionValue) || !processedConditionValue.includes(String(targetValue));
180
+ default:
181
+ logClientEvalWarning(`Unhandled operator in client evaluation logic: ${operator}`, condition);
182
+ return true; // Permissive default
183
+ }
184
+ } catch (evalError) {
185
+ logClientEvalWarning(`Error during client condition evaluation: ${operator}, targetValue=${targetValue}, processedConditionValue=${processedConditionValue}`, condition);
186
+ return false;
187
+ }
188
+ }
189
+ };
190
+
191
+ export const isConditionMet = (model, cond, formData, allModels, user,checkRegex=true) => {
192
+ const condition = cond;
193
+
194
+ if (!condition) return true;
195
+
196
+ if (typeof condition !== 'object' || condition === null) {
197
+ return true;
198
+ }
199
+
200
+ // Cas spécial: Évaluation sans modèle (ex: pour les webhooks où la condition est déjà résolue)
201
+ // Dans ce mode, la condition doit être un objet avec un seul opérateur.
202
+ if (!model) {
203
+ const keys = Object.keys(condition);
204
+ if (keys.length !== 1 || !keys[0].startsWith('$')) {
205
+ console.warn('[isConditionMet] Condition invalide pour une évaluation sans modèle. Attendu : { "$opérateur": [...] }. Reçu :', condition);
206
+ return false; // Plus sûr que true pour éviter les faux positifs
207
+ }
208
+
209
+ const operator = keys[0];
210
+ const operands = condition[operator];
211
+
212
+ switch (operator) {
213
+ // Opérateurs logiques (récursifs)
214
+ case '$and':
215
+ return Array.isArray(operands) && operands.every(sub => isConditionMet(null, sub, formData, allModels, user,checkRegex));
216
+ case '$or':
217
+ return Array.isArray(operands) && operands.some(sub => isConditionMet(null, sub, formData, allModels, user,checkRegex));
218
+ case '$not':
219
+ return !isConditionMet(null, operands, formData, allModels, user);
220
+ case '$nor':
221
+ return Array.isArray(operands) && !operands.some(sub => isConditionMet(null, sub, formData, allModels, user,checkRegex));
222
+
223
+ // Opérateurs de comparaison (terminaux)
224
+ case '$eq':
225
+ return Array.isArray(operands) && operands[0] === operands[1];
226
+ case '$ne':
227
+ return Array.isArray(operands) && operands[0] !== operands[1];
228
+ case '$in':
229
+ return Array.isArray(operands) && Array.isArray(operands[1]) && operands[1].includes(operands[0]);
230
+ case '$nin':
231
+ return Array.isArray(operands) && Array.isArray(operands[1]) && !operands[1].includes(operands[0]);
232
+ case '$gt':
233
+ return Array.isArray(operands) && operands[0] > operands[1];
234
+ case '$gte':
235
+ return Array.isArray(operands) && operands[0] >= operands[1];
236
+ case '$lt':
237
+ return Array.isArray(operands) && operands[0] < operands[1];
238
+ case '$lte':
239
+ return Array.isArray(operands) && operands[0] <= operands[1];
240
+
241
+ default:
242
+ console.warn(`[isConditionMet] Opérateur non supporté '${operator}' pour une évaluation sans modèle.`);
243
+ return false;
244
+ }
245
+ }
246
+
247
+ // --- Logique existante pour l'évaluation AVEC modèle ---
248
+
249
+ if (condition.$and && Array.isArray(condition.$and)) {
250
+ if (condition.$and.length === 0) return true;
251
+ return condition.$and.every(sub => isConditionMet(model, sub, formData, allModels, user,checkRegex));
252
+ }
253
+ if (condition.$or && Array.isArray(condition.$or)) {
254
+ if (condition.$or.length === 0) return false;
255
+ return condition.$or.some(sub => isConditionMet(model, sub, formData, allModels, user,checkRegex));
256
+ }
257
+ if (condition.$not) {
258
+ return !isConditionMet(model, condition.$not, formData, allModels, user,checkRegex);
259
+ }
260
+ if (condition.$nor && Array.isArray(condition.$nor)) {
261
+ if (condition.$nor.length === 0) return true;
262
+ return !condition.$nor.some(sub => isConditionMet(model, sub, formData, allModels, user,checkRegex));
263
+ }
264
+
265
+ // Cas 3: Syntaxe d'agrégation {$eq: ['$field', value]}
266
+ if (Object.keys(condition).length === 1) {
267
+ const operator = Object.keys(condition)[0];
268
+ if (operator.startsWith('$') && operator !== '$find' &&
269
+ Array.isArray(condition[operator])) {
270
+ return evaluateSingleCondition(model, condition, formData, allModels, user,checkRegex);
271
+ }
272
+ }
273
+
274
+ return evaluateSingleCondition(model, condition, formData, allModels, user, checkRegex);
275
275
  };
package/src/index.js CHANGED
@@ -7,6 +7,7 @@ export { Config } from './config.js';
7
7
  export { event_on, event_trigger, event_off } from './core.js';
8
8
  export { Event } from './events.js';
9
9
 
10
+ export { hasPermission, middlewareAuthenticator, getEnv, getSmtpConfig } from "./modules/user.js"
10
11
  export { sendSseToUser } from './modules/data/data.routes.js';
11
12
 
12
13
  export { UserProvider } from './providers.js';