multicloud_rule_manager 1.0.24 โ†’ 1.0.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.
@@ -27,50 +27,75 @@ export default {
27
27
  })
28
28
  });
29
29
 
30
- const loginData = await loginResp.json(); // leggi direttamente JSON
31
- const access_token = loginData.access_token;
30
+ const loginData = await loginResp.json(); // leggi direttamente JSON
31
+ const access_token = loginData.access_token;
32
32
 
33
- console.log("๐Ÿ”น Token response raw:", access_token);
33
+ console.log("๐Ÿ”น Token response raw:", access_token);
34
34
 
35
- if (!access_token) {
36
- throw new Error("Token non ricevuto nel campo 'access_token'");
37
- }
35
+ if (!access_token) {
36
+ throw new Error("Token non ricevuto nel campo 'access_token'");
37
+ }
38
38
 
39
39
 
40
40
 
41
41
  // --- SECONDA CHIAMATA: retrieve ---
42
42
  console.log("๐Ÿ”น Inizio richiesta dati API...");
43
- const apiResp = await fetch(
44
- "https://eon-dev-01.bit2win.cloud/api/data/v1/rules",
45
- {
46
- method: "GET",
47
- headers: {
48
- "Authorization": `Bearer ${access_token}`,
49
- "Accept": "application/json"
50
- },
51
- redirect: "manual"
52
- }
53
- );
43
+ const apiResp = await fetch(
44
+ "https://eon-dev-01.bit2win.cloud/api/data/v1/rules",
45
+ {
46
+ method: "GET",
47
+ headers: {
48
+ "Authorization": `Bearer ${access_token}`,
49
+ "Accept": "application/json"
50
+ },
51
+ redirect: "manual"
52
+ }
53
+ );
54
54
 
55
55
 
56
- console.log("๐Ÿ”น API token:", "Bearer "+access_token);
57
56
  console.log("๐Ÿ”น API status:", apiResp.status);
58
- const apiText = await apiResp.text();
59
- console.log("๐Ÿ”น API response raw:", apiText);
60
- const apiTeapixt = await apiResp.json();
61
- console.log("๐Ÿ”น API response rawjson:", apiTeapixt);
62
57
 
63
- let data;
58
+ if (!apiResp.ok) {
59
+ const errText = await apiResp.text();
60
+ throw new Error(`Errore API ${apiResp.status}: ${errText}`);
61
+ }
62
+
63
+ const data = await apiResp.json();
64
+
64
65
  console.log("๐Ÿ”น API final URL:", apiResp.url);
65
- try {
66
- data = JSON.parse(apiText);
67
- console.log("๐Ÿ”น API JSON parsed:", data);
68
- } catch (err) {
69
- throw new Error(`API JSON parsing failed: ${err.message}`);
66
+
67
+ // Se non รจ un array โ†’ errore
68
+ if (!Array.isArray(data)) {
69
+ throw new Error("La risposta API non รจ una lista di oggetti");
70
+ }
71
+
72
+ // Crea cartella rules se non esiste
73
+ const rulesDir = "./rules";
74
+ if (!fs.existsSync(rulesDir)) {
75
+ fs.mkdirSync(rulesDir, { recursive: true });
76
+ console.log("๐Ÿ“ Cartella 'rules' creata");
77
+ }
78
+
79
+ // Per ogni record crea/sovrascrive file
80
+ for (const record of data) {
81
+
82
+ if (!record.name || !record.guid) {
83
+ console.warn("โš ๏ธ Record saltato (name o guid mancanti):", record);
84
+ continue;
85
+ }
86
+
87
+ const safeName = record.name.replace(/[<>:"/\\|?*]+/g, "_");
88
+ const fileName = `${safeName}_${record.guid}.js`;
89
+ const filePath = `${rulesDir}/${fileName}`;
90
+
91
+ const content = record.dsl_internal || "";
92
+
93
+ fs.writeFileSync(filePath, content, "utf8");
94
+
95
+ console.log(`๐Ÿ“ File scritto: ${fileName}`);
70
96
  }
71
97
 
72
- fs.writeFileSync(argv.output, JSON.stringify(data, null, 2));
73
- console.log(`๐Ÿš€ Dati salvati in ${argv.output}`);
98
+ console.log("๐Ÿš€ Tutti i file sono stati generati correttamente");
74
99
 
75
100
  } catch (err) {
76
101
  console.error("โŒ Errore:", err.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multicloud_rule_manager",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "CLI interna per retrieve/upload con token",
5
5
  "main": "index.js",
6
6
  "type": "module",