multicloud_rule_manager 1.1.66 → 1.1.68

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.
@@ -7,7 +7,7 @@ export default {
7
7
  describe: "Recupera struttura prodotto e genera Excel",
8
8
  handler: async (argv) => {
9
9
  try {
10
- console.log("🔹 Retrieve in corso..");
10
+ console.log("🔹 Retrieve in corso..");
11
11
  console.log("🔹 Recupero credenziali per alias:", argv.alias);
12
12
  const cred = getAlias(argv.alias);
13
13
 
@@ -25,6 +25,7 @@ export default {
25
25
  })
26
26
  });
27
27
 
28
+
28
29
  const loginData = await loginResp.json(); // leggi direttamente JSON
29
30
  const access_token = loginData.access_token;
30
31
 
@@ -32,21 +33,25 @@ export default {
32
33
  throw new Error("Token non ricevuto nel campo 'access_token'");
33
34
  }
34
35
 
35
- const headers = {
36
- Authorization: `Bearer ${access_token}`,
37
- Accept: "application/json"
38
- };
36
+
37
+
39
38
 
40
39
  // =========================
41
40
  // 📦 PRODUCTS
42
41
  // =========================
43
- console.log(" Chiamo products");
42
+ console.log(" Chiamo products");
44
43
  const productsResp = await fetch(
45
44
  `https://${cred.realm}.bit2win.cloud/api/data/v1/products/`,
46
- { headers }
45
+ {
46
+ method: "GET",
47
+ headers: {
48
+ "Authorization": `Bearer ${access_token}`,
49
+ "Accept": "application/json"
50
+ },
51
+ redirect: "manual"
52
+ }
47
53
  );
48
-
49
- const products = await productsResp.json();
54
+ const products = await safeJson(productsResp, "products");
50
55
 
51
56
  const product = products.find(p => p.name === argv.productName);
52
57
 
@@ -56,17 +61,28 @@ export default {
56
61
 
57
62
  const rootGuid = product.guid;
58
63
 
64
+
65
+
66
+
59
67
  // =========================
60
68
  // 🌳 STRUCTURE
61
69
  // =========================
62
-
63
- console.log(" Chiamo products structure");
70
+
71
+ console.log("Chiamo products structure");
72
+
64
73
  const structResp = await fetch(
65
74
  `https://${cred.realm}.bit2win.cloud/api/data/v1/products_structure/`,
66
- { headers }
75
+ {
76
+ method: "GET",
77
+ headers: {
78
+ "Authorization": `Bearer ${access_token}`,
79
+ "Accept": "application/json"
80
+ },
81
+ redirect: "manual"
82
+ }
67
83
  );
68
84
 
69
- const structure = await structResp.json();
85
+ const structure = await safeJson(structResp, "products_structure");
70
86
 
71
87
  // =========================
72
88
  // 📂 HELPERS
@@ -89,39 +105,47 @@ export default {
89
105
  // =========================
90
106
  // 📡 FAMILIES
91
107
  // =========================
92
-
93
- console.log(" Chiamo famili per product");
108
+
109
+ console.log("Chiamo families");
110
+
94
111
  const getFamilies = async (productId) => {
95
112
  const resp = await fetch(
96
113
  `https://${cred.realm}.bit2win.cloud/api/catalog/v1/products/${productId}/families`,
97
- { headers }
114
+ {
115
+ method: "GET",
116
+ headers: {
117
+ "Authorization": `Bearer ${access_token}`,
118
+ "Accept": "application/json"
119
+ },
120
+ redirect: "manual"
121
+ }
98
122
  );
99
123
 
100
- const data = await resp.json();
124
+ const data = await safeJson(resp, `families:${productId}`);
101
125
 
102
- return sortByName(
103
- (data || []).map(f => ({
126
+ return (data || [])
127
+ .sort((a, b) => a.name.localeCompare(b.name))
128
+ .map(f => ({
104
129
  name: f.name,
105
130
  visible: f.visible,
106
131
  visible_web: f.visible_web,
107
- attributes: sortByName(
108
- (f.attributes || []).map(a => ({
132
+ attributes: (f.attributes || [])
133
+ .sort((a, b) => a.name.localeCompare(b.name))
134
+ .map(a => ({
109
135
  name: a.name,
110
136
  value_default: a.value_default,
111
137
  read_only: a.read_only,
112
138
  required: a.required,
113
139
  visible: a.visible,
114
- domains: sortByName(
115
- (a.domains || []).map(d => ({
140
+ domains: (a.domains || [])
141
+ .sort((a, b) => (a.value || "").localeCompare(b.value || ""))
142
+ .map(d => ({
116
143
  value: d.value,
117
144
  visible: d.visible,
118
145
  default: d.default
119
146
  }))
120
- )
121
147
  }))
122
- )
123
- }))
124
- );
148
+ }));
125
149
  };
126
150
 
127
151
  // =========================
@@ -217,5 +241,28 @@ export default {
217
241
  } catch (err) {
218
242
  console.error("❌ Errore:", err.message);
219
243
  }
244
+
245
+
246
+
247
+ async function safeJson(resp, label) {
248
+ const text = await resp.text();
249
+ console.log("RAW products:", text);
250
+
251
+ if (!resp.ok) {
252
+ throw new Error(`${label} HTTP ${resp.status}: ${text.slice(0, 200)}`);
253
+ }
254
+
255
+ if (!text) {
256
+ throw new Error(`${label} risposta vuota`);
257
+ }
258
+
259
+ try {
260
+ return JSON.parse(text);
261
+ } catch (e) {
262
+ throw new Error(`${label} NON JSON valido: ${text.slice(0, 200)}`);
263
+ }
264
+ }
265
+
266
+
220
267
  }
221
268
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multicloud_rule_manager",
3
- "version": "1.1.66",
3
+ "version": "1.1.68",
4
4
  "description": "CLI interna per retrieve/upload con token",
5
5
  "main": "index.js",
6
6
  "type": "module",