multicloud_rule_manager 1.1.67 → 1.1.69
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.
|
@@ -65,7 +65,7 @@ export default {
|
|
|
65
65
|
try {
|
|
66
66
|
console.log("🔹 Retrieve Datamap in corso..");
|
|
67
67
|
console.log("🔹 Recupero credenziali per alias:", argv.alias);
|
|
68
|
-
|
|
68
|
+
const cred = getAlias(argv.alias);
|
|
69
69
|
|
|
70
70
|
// --- PRIMA CHIAMATA: token ---
|
|
71
71
|
console.log("🔹 Inizio richiesta token...");
|
|
@@ -7,14 +7,14 @@ export default {
|
|
|
7
7
|
describe: "Recupera struttura prodotto e genera Excel",
|
|
8
8
|
handler: async (argv) => {
|
|
9
9
|
try {
|
|
10
|
-
|
|
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
|
|
|
14
14
|
// --- PRIMA CHIAMATA: token ---
|
|
15
15
|
console.log("🔹 Inizio richiesta token...");
|
|
16
16
|
const loginResp = await fetch(`https://login-eon-no-prod.bit2win.cloud/auth/realms/${cred.realm}/protocol/openid-connect/token`, {
|
|
17
|
-
|
|
17
|
+
method: "POST",
|
|
18
18
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
19
19
|
body: new URLSearchParams({
|
|
20
20
|
client_id: cred.clientId,
|
|
@@ -35,24 +35,22 @@ export default {
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
// =========================
|
|
40
40
|
// 📦 PRODUCTS
|
|
41
41
|
// =========================
|
|
42
|
-
|
|
42
|
+
console.log(" Chiamo products");
|
|
43
43
|
const productsResp = await fetch(
|
|
44
44
|
`https://${cred.realm}.bit2win.cloud/api/data/v1/products/`,
|
|
45
|
-
|
|
45
|
+
{
|
|
46
46
|
method: "GET",
|
|
47
47
|
headers: {
|
|
48
|
-
"Authorization": `Bearer ${access_token}
|
|
49
|
-
"Accept": "application/json"
|
|
48
|
+
"Authorization": `Bearer ${access_token}`
|
|
50
49
|
},
|
|
51
50
|
redirect: "manual"
|
|
52
51
|
}
|
|
53
52
|
);
|
|
54
|
-
|
|
55
|
-
const products = await productsResp.json();
|
|
53
|
+
const products = await safeJson(productsResp, "products");
|
|
56
54
|
|
|
57
55
|
const product = products.find(p => p.name === argv.productName);
|
|
58
56
|
|
|
@@ -62,24 +60,27 @@ export default {
|
|
|
62
60
|
|
|
63
61
|
const rootGuid = product.guid;
|
|
64
62
|
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
65
66
|
// =========================
|
|
66
67
|
// 🌳 STRUCTURE
|
|
67
68
|
// =========================
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
|
|
70
|
+
console.log("Chiamo products structure");
|
|
71
|
+
|
|
70
72
|
const structResp = await fetch(
|
|
71
73
|
`https://${cred.realm}.bit2win.cloud/api/data/v1/products_structure/`,
|
|
72
|
-
|
|
74
|
+
{
|
|
73
75
|
method: "GET",
|
|
74
76
|
headers: {
|
|
75
|
-
"Authorization": `Bearer ${access_token}
|
|
76
|
-
"Accept": "application/json"
|
|
77
|
+
"Authorization": `Bearer ${access_token}`
|
|
77
78
|
},
|
|
78
79
|
redirect: "manual"
|
|
79
80
|
}
|
|
80
81
|
);
|
|
81
82
|
|
|
82
|
-
const structure = await structResp
|
|
83
|
+
const structure = await safeJson(structResp, "products_structure");
|
|
83
84
|
|
|
84
85
|
// =========================
|
|
85
86
|
// 📂 HELPERS
|
|
@@ -102,46 +103,47 @@ export default {
|
|
|
102
103
|
// =========================
|
|
103
104
|
// 📡 FAMILIES
|
|
104
105
|
// =========================
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
|
|
107
|
+
console.log("Chiamo families");
|
|
108
|
+
|
|
107
109
|
const getFamilies = async (productId) => {
|
|
108
110
|
const resp = await fetch(
|
|
109
111
|
`https://${cred.realm}.bit2win.cloud/api/catalog/v1/products/${productId}/families`,
|
|
110
112
|
{
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
method: "GET",
|
|
114
|
+
headers: {
|
|
115
|
+
"Authorization": `Bearer ${access_token}`,
|
|
116
|
+
"Accept": "application/json"
|
|
117
|
+
},
|
|
118
|
+
redirect: "manual"
|
|
119
|
+
}
|
|
120
|
+
);
|
|
119
121
|
|
|
120
|
-
const data = await resp
|
|
122
|
+
const data = await safeJson(resp, `families:${productId}`);
|
|
121
123
|
|
|
122
|
-
return
|
|
123
|
-
(
|
|
124
|
+
return (data || [])
|
|
125
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
126
|
+
.map(f => ({
|
|
124
127
|
name: f.name,
|
|
125
128
|
visible: f.visible,
|
|
126
129
|
visible_web: f.visible_web,
|
|
127
|
-
attributes:
|
|
128
|
-
|
|
130
|
+
attributes: (f.attributes || [])
|
|
131
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
132
|
+
.map(a => ({
|
|
129
133
|
name: a.name,
|
|
130
134
|
value_default: a.value_default,
|
|
131
135
|
read_only: a.read_only,
|
|
132
136
|
required: a.required,
|
|
133
137
|
visible: a.visible,
|
|
134
|
-
domains:
|
|
135
|
-
(a.
|
|
138
|
+
domains: (a.domains || [])
|
|
139
|
+
.sort((a, b) => (a.value || "").localeCompare(b.value || ""))
|
|
140
|
+
.map(d => ({
|
|
136
141
|
value: d.value,
|
|
137
142
|
visible: d.visible,
|
|
138
143
|
default: d.default
|
|
139
144
|
}))
|
|
140
|
-
)
|
|
141
145
|
}))
|
|
142
|
-
|
|
143
|
-
}))
|
|
144
|
-
);
|
|
146
|
+
}));
|
|
145
147
|
};
|
|
146
148
|
|
|
147
149
|
// =========================
|
|
@@ -237,5 +239,28 @@ export default {
|
|
|
237
239
|
} catch (err) {
|
|
238
240
|
console.error("❌ Errore:", err.message);
|
|
239
241
|
}
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
async function safeJson(resp, label) {
|
|
246
|
+
const text = await resp.text();
|
|
247
|
+
console.log("RAW products:", text);
|
|
248
|
+
|
|
249
|
+
if (!resp.ok) {
|
|
250
|
+
throw new Error(`${label} HTTP ${resp.status}: ${text.slice(0, 200)}`);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (!text) {
|
|
254
|
+
throw new Error(`${label} risposta vuota`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
try {
|
|
258
|
+
return JSON.parse(text);
|
|
259
|
+
} catch (e) {
|
|
260
|
+
throw new Error(`${label} NON JSON valido: ${text.slice(0, 200)}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
|
|
240
265
|
}
|
|
241
266
|
};
|