multicloud_rule_manager 1.1.23 → 1.1.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multicloud_rule_manager",
3
- "version": "1.1.23",
3
+ "version": "1.1.25",
4
4
  "description": "CLI interna per retrieve/upload con token",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -11,10 +11,8 @@ export function validateRule(fileNameWithId, content) {
11
11
  let inThen = false;
12
12
  let thenStack = [];
13
13
 
14
- const match = fileNameWithId.match(/_(.+)\.js$/);
15
-
16
-
17
- const fileName = match[0];
14
+ const match = fileNameWithId.match(/^(.+?)_/);
15
+ const fileName = match ? match[1] : fileNameWithId;
18
16
 
19
17
  for (let i = 0; i < lines.length; i++) {
20
18
  const line = lines[i];
@@ -78,12 +76,24 @@ export function validateRule(fileNameWithId, content) {
78
76
  }
79
77
 
80
78
  function hasValidWhenThenBlock(content, fileName) {
81
- // [\s]* => spazi, tab, newline, carriage return
82
- // [\s\S]*? => qualunque carattere incluso newline
83
- const regex = /^[\s]*when[\s]*{[\s\S]*?}[\s]*then[\s]*{[\s\S]*?}[\s]*$/i;
79
+ // trova tutti i blocchi when{}then{}
80
+ const regex = /when[\s]*{[\s\S]*?}[\s]*then[\s]*{/gi;
81
+ const matches = content.match(regex);
82
+
83
+ if (!matches || matches.length === 0) {
84
+ console.error(`❌ Il file ${fileName} deve contenere un blocco "when {} then {}"`);
85
+ return false;
86
+ }
87
+
88
+ if (matches.length > 1) {
89
+ console.error(`❌ Il file ${fileName} contiene più blocchi "when {} then {}", è consentito solo uno`);
90
+ return false;
91
+ }
84
92
 
85
- if (!regex.test(content)) {
86
- console.error(`❌ Il file ${fileName} deve contenere un blocco "when {} then {}" valido`);
93
+ // opzionale: controlla se ci sono altre parole 'when' o 'then' nel file fuori dal blocco principale
94
+ const cleaned = content.replace(regex, ''); // rimuove il blocco valido
95
+ if (/when|then/.test(cleaned)) {
96
+ console.error(`❌ Il file ${fileName} contiene 'when' o 'then' extra fuori dal blocco principale`);
87
97
  return false;
88
98
  }
89
99