multicloud_rule_manager 1.1.53 → 1.1.55
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/deploy.js +35 -3
- package/commands/retrievedatamap.js +9 -3
- package/commands/verifyorphan.js +93 -0
- package/index.js +6 -4
- package/package.json +2 -2
package/commands/deploy.js
CHANGED
|
@@ -72,16 +72,48 @@ export default {
|
|
|
72
72
|
|
|
73
73
|
if (!resp.ok) {
|
|
74
74
|
const text = await resp.text();
|
|
75
|
-
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if (resp.status === 404) {
|
|
79
|
+
if (
|
|
80
|
+
text.includes("in rules not found")
|
|
81
|
+
) {
|
|
82
|
+
console.warn(`⚠️ Rule ${guid} non trovata, provo creazione...`);
|
|
83
|
+
|
|
84
|
+
const resp = await fetch(`https://${cred.realm}.bit2win.cloud/api/data/v1/rules/`, {
|
|
85
|
+
method: "POST",
|
|
86
|
+
headers: {
|
|
87
|
+
"Authorization": `Bearer ${accessToken}`,
|
|
88
|
+
"Content-Type": "application/json"
|
|
89
|
+
},
|
|
90
|
+
body: JSON.stringify({
|
|
91
|
+
|
|
92
|
+
dsl_internal: content
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (!resp.ok) {
|
|
97
|
+
const text = await resp.text();
|
|
98
|
+
|
|
99
|
+
console.error(`❌ Errore deploy ${file}: ${resp.status} ${text}`);
|
|
100
|
+
} else {
|
|
101
|
+
console.log(`✅ Deploy riuscito per ${file}`);
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
console.error(`❌ Errore deploy ${file}: ${resp.status} ${text}`);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
console.error(`❌ Errore deploy ${file}: ${resp.status} ${text}`);
|
|
108
|
+
}
|
|
76
109
|
} else {
|
|
77
110
|
console.log(`✅ Deploy riuscito per ${file}`);
|
|
78
111
|
}
|
|
112
|
+
|
|
79
113
|
} catch (err) {
|
|
80
114
|
console.error(`❌ Errore rete deploy ${file}:`, err.message);
|
|
81
115
|
}
|
|
82
116
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
117
|
} catch (err) {
|
|
86
118
|
console.error("❌ Errore:", err.message);
|
|
87
119
|
}
|
|
@@ -9,7 +9,7 @@ export default {
|
|
|
9
9
|
},
|
|
10
10
|
handler: async (argv) => {
|
|
11
11
|
function buildMapObject(children) {
|
|
12
|
-
if (!Array.isArray(children) || children.length === 0
|
|
12
|
+
if (!Array.isArray(children) || children.length === 0) return [];
|
|
13
13
|
|
|
14
14
|
return children
|
|
15
15
|
.map(child => {
|
|
@@ -124,8 +124,14 @@ export default {
|
|
|
124
124
|
// Per ogni record genera file SOLO se dsl_internal esiste
|
|
125
125
|
for (const record of data) {
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
const skipNames = new Set([
|
|
128
|
+
"GenericItem2OrderItem",
|
|
129
|
+
"PriceListItem",
|
|
130
|
+
"PriceList"
|
|
131
|
+
]);
|
|
132
|
+
|
|
133
|
+
if (!record.name || !record.guid || skipNames.has(record.name)) {
|
|
134
|
+
console.warn("⚠️ Record saltato:", record.name);
|
|
129
135
|
continue;
|
|
130
136
|
}
|
|
131
137
|
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { getAlias } from "../utils/aliasManager.js";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
command: "verifyorphan <alias> [output]",
|
|
6
|
+
describe: "Recupera datamaps",
|
|
7
|
+
builder: {
|
|
8
|
+
output: { type: "string", default: "retrieve.json", describe: "File di output" }
|
|
9
|
+
},
|
|
10
|
+
handler: async (argv) => {
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
console.log("🔹 Retrieve Data in corso..");
|
|
15
|
+
console.log("🔹 Recupero credenziali per alias:", argv.alias);
|
|
16
|
+
const cred = getAlias(argv.alias);
|
|
17
|
+
|
|
18
|
+
// --- PRIMA CHIAMATA: token ---
|
|
19
|
+
console.log("🔹 Inizio richiesta token...");
|
|
20
|
+
const loginResp = await fetch(`https://login-eon-no-prod.bit2win.cloud/auth/realms/${cred.realm}/protocol/openid-connect/token`, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
23
|
+
body: new URLSearchParams({
|
|
24
|
+
client_id: cred.clientId,
|
|
25
|
+
client_secret: cred.clientSecret,
|
|
26
|
+
username: cred.username,
|
|
27
|
+
password: cred.password,
|
|
28
|
+
grant_type: "password"
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const loginData = await loginResp.json(); // leggi direttamente JSON
|
|
33
|
+
const access_token = loginData.access_token;
|
|
34
|
+
|
|
35
|
+
if (!access_token) {
|
|
36
|
+
throw new Error("Token non ricevuto nel campo 'access_token'");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// --- SECONDA CHIAMATA: retrieve ---
|
|
42
|
+
console.log("🔹 Inizio richiesta dati API...");
|
|
43
|
+
const overrideResp = await fetch(
|
|
44
|
+
`https://${cred.realm}.bit2win.cloud/api/datamap/v1/maps`,
|
|
45
|
+
{
|
|
46
|
+
method: "GET",
|
|
47
|
+
headers: {
|
|
48
|
+
"Authorization": `Bearer ${access_token}`,
|
|
49
|
+
"Accept": "application/json"
|
|
50
|
+
},
|
|
51
|
+
redirect: "manual"
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
const data = await overrideResp.json();
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// Controlla che sia array
|
|
61
|
+
if (!Array.isArray(data)) {
|
|
62
|
+
throw new Error("La risposta API non è una lista di oggetti");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
for (const record of data) {
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
// --- CHIAMATA MAP/{guid} ---
|
|
74
|
+
const mapResp = await fetch(
|
|
75
|
+
`https://${cred.realm}.bit2win.cloud/api/datamap/v1/maps/${record.guid}`,
|
|
76
|
+
{
|
|
77
|
+
method: "GET",
|
|
78
|
+
headers: {
|
|
79
|
+
"Authorization": `Bearer ${access_token}`,
|
|
80
|
+
"Accept": "application/json"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const mapData = await mapResp.json();
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
} catch (err) {
|
|
90
|
+
console.error("❌ Errore:", err.message);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
package/index.js
CHANGED
|
@@ -3,15 +3,17 @@ import yargs from "yargs";
|
|
|
3
3
|
import { hideBin } from "yargs/helpers";
|
|
4
4
|
|
|
5
5
|
import aliasSet from "./commands/aliasSet.js";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import retrieverule from "./commands/retrieve.js";
|
|
7
|
+
import deployrule from "./commands/deploy.js";
|
|
8
8
|
import retrievedatamap from "./commands/retrievedatamap.js";
|
|
9
|
+
import verifyorphan from "./commands/verifyorphan.js";
|
|
9
10
|
|
|
10
11
|
yargs(hideBin(process.argv))
|
|
11
12
|
.command(aliasSet)
|
|
12
|
-
.command(
|
|
13
|
-
.command(
|
|
13
|
+
.command(retrieverule)
|
|
14
|
+
.command(deployrule)
|
|
14
15
|
.command(retrievedatamap)
|
|
16
|
+
.command(verifyorphan)
|
|
15
17
|
.demandCommand()
|
|
16
18
|
.help()
|
|
17
19
|
.parse();
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "multicloud_rule_manager",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.55",
|
|
4
4
|
"description": "CLI interna per retrieve/upload con token",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"
|
|
8
|
+
"multi": "index.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|