multicloud_rule_manager 1.1.64 → 1.1.66
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/commands/retrieveproduct.js +24 -22
- package/package.json +1 -1
|
@@ -7,32 +7,29 @@ export default {
|
|
|
7
7
|
describe: "Recupera struttura prodotto e genera Excel",
|
|
8
8
|
handler: async (argv) => {
|
|
9
9
|
try {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
console.log("🔹 Retrieve in corso..");
|
|
11
|
+
console.log("🔹 Recupero credenziali per alias:", argv.alias);
|
|
12
12
|
const cred = getAlias(argv.alias);
|
|
13
13
|
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const { access_token } = await loginResp.json();
|
|
14
|
+
// --- PRIMA CHIAMATA: token ---
|
|
15
|
+
console.log("🔹 Inizio richiesta token...");
|
|
16
|
+
const loginResp = await fetch(`https://login-eon-no-prod.bit2win.cloud/auth/realms/${cred.realm}/protocol/openid-connect/token`, {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
19
|
+
body: new URLSearchParams({
|
|
20
|
+
client_id: cred.clientId,
|
|
21
|
+
client_secret: cred.clientSecret,
|
|
22
|
+
username: cred.username,
|
|
23
|
+
password: cred.password,
|
|
24
|
+
grant_type: "password"
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const loginData = await loginResp.json(); // leggi direttamente JSON
|
|
29
|
+
const access_token = loginData.access_token;
|
|
33
30
|
|
|
34
31
|
if (!access_token) {
|
|
35
|
-
throw new Error("Token non ricevuto");
|
|
32
|
+
throw new Error("Token non ricevuto nel campo 'access_token'");
|
|
36
33
|
}
|
|
37
34
|
|
|
38
35
|
const headers = {
|
|
@@ -43,6 +40,7 @@ export default {
|
|
|
43
40
|
// =========================
|
|
44
41
|
// 📦 PRODUCTS
|
|
45
42
|
// =========================
|
|
43
|
+
console.log(" Chiamo products");
|
|
46
44
|
const productsResp = await fetch(
|
|
47
45
|
`https://${cred.realm}.bit2win.cloud/api/data/v1/products/`,
|
|
48
46
|
{ headers }
|
|
@@ -61,6 +59,8 @@ export default {
|
|
|
61
59
|
// =========================
|
|
62
60
|
// 🌳 STRUCTURE
|
|
63
61
|
// =========================
|
|
62
|
+
|
|
63
|
+
console.log(" Chiamo products structure");
|
|
64
64
|
const structResp = await fetch(
|
|
65
65
|
`https://${cred.realm}.bit2win.cloud/api/data/v1/products_structure/`,
|
|
66
66
|
{ headers }
|
|
@@ -89,6 +89,8 @@ export default {
|
|
|
89
89
|
// =========================
|
|
90
90
|
// 📡 FAMILIES
|
|
91
91
|
// =========================
|
|
92
|
+
|
|
93
|
+
console.log(" Chiamo famili per product");
|
|
92
94
|
const getFamilies = async (productId) => {
|
|
93
95
|
const resp = await fetch(
|
|
94
96
|
`https://${cred.realm}.bit2win.cloud/api/catalog/v1/products/${productId}/families`,
|