multicloud_rule_manager 1.1.30 โ 1.1.32
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/retrievedatamap.js +161 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/utils/ruleValidator.js +1 -2
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { getAlias } from "../utils/aliasManager.js";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
command: "retrieve <alias> [output]",
|
|
6
|
+
describe: "Recupera dati API con token automatico",
|
|
7
|
+
builder: {
|
|
8
|
+
output: { type: "string", default: "retrieve.json", describe: "File di output" }
|
|
9
|
+
},
|
|
10
|
+
handler: async (argv) => {
|
|
11
|
+
try {
|
|
12
|
+
console.log("๐น Retrieve in corso..");
|
|
13
|
+
console.log("๐น Recupero credenziali per alias:", argv.alias);
|
|
14
|
+
const cred = getAlias(argv.alias);
|
|
15
|
+
|
|
16
|
+
// --- PRIMA CHIAMATA: token ---
|
|
17
|
+
console.log("๐น Inizio richiesta token...");
|
|
18
|
+
const loginResp = await fetch(`https://login-eon-no-prod.bit2win.cloud/auth/realms/${cred.realm}/protocol/openid-connect/token`, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
21
|
+
body: new URLSearchParams({
|
|
22
|
+
client_id: cred.clientId,
|
|
23
|
+
client_secret: cred.clientSecret,
|
|
24
|
+
username: cred.username,
|
|
25
|
+
password: cred.password,
|
|
26
|
+
grant_type: "password"
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const loginData = await loginResp.json(); // leggi direttamente JSON
|
|
31
|
+
const access_token = loginData.access_token;
|
|
32
|
+
|
|
33
|
+
if (!access_token) {
|
|
34
|
+
throw new Error("Token non ricevuto nel campo 'access_token'");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// --- SECONDA CHIAMATA: retrieve ---
|
|
40
|
+
console.log("๐น Inizio richiesta dati API...");
|
|
41
|
+
const apiResp = await fetch(
|
|
42
|
+
`https://${cred.realm}.bit2win.cloud/api/data/v1/maps`,
|
|
43
|
+
{
|
|
44
|
+
method: "GET",
|
|
45
|
+
headers: {
|
|
46
|
+
"Authorization": `Bearer ${access_token}`,
|
|
47
|
+
"Accept": "application/json"
|
|
48
|
+
},
|
|
49
|
+
redirect: "manual"
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const data = await apiResp.json();
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// Controlla che sia array
|
|
59
|
+
if (!Array.isArray(data)) {
|
|
60
|
+
throw new Error("La risposta API non รจ una lista di oggetti");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Crea cartella rules se non esiste
|
|
64
|
+
const rulesDir = "./datamaps";
|
|
65
|
+
if (!fs.existsSync(rulesDir)) {
|
|
66
|
+
fs.mkdirSync(rulesDir, { recursive: true });
|
|
67
|
+
console.log("๐ Cartella 'datamaps' creata");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Per ogni record genera file SOLO se dsl_internal esiste
|
|
71
|
+
for (const record of data) {
|
|
72
|
+
|
|
73
|
+
if (!record.name || !record.guid) {
|
|
74
|
+
console.warn("โ ๏ธ Record saltato (name o guid mancanti):", record);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const safeName = record.name.replace(/[<>:"/\\|?*]+/g, "_");
|
|
79
|
+
const fileName = `${safeName}_${record.guid}.json`;
|
|
80
|
+
const filePath = `${rulesDir}/${fileName}`;
|
|
81
|
+
|
|
82
|
+
console.log(`๐น Recupero dettaglio mappa ${record.guid}...`);
|
|
83
|
+
|
|
84
|
+
// --- CHIAMATA MAP/{guid} ---
|
|
85
|
+
const mapResp = await fetch(
|
|
86
|
+
`https://${cred.realm}.bit2win.cloud/api/data/v1/maps/${record.guid}`,
|
|
87
|
+
{
|
|
88
|
+
method: "GET",
|
|
89
|
+
headers: {
|
|
90
|
+
"Authorization": `Bearer ${access_token}`,
|
|
91
|
+
"Accept": "application/json"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const mapData = await mapResp.json();
|
|
97
|
+
|
|
98
|
+
const children = mapData?.map_j2j_published?._children;
|
|
99
|
+
|
|
100
|
+
if (!Array.isArray(children)) {
|
|
101
|
+
console.warn(`โ ๏ธ Nessun _children trovato per ${record.name}`);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// costruzione JSON finale
|
|
106
|
+
const result = {};
|
|
107
|
+
|
|
108
|
+
for (const child of children) {
|
|
109
|
+
if (child._key && child._attributes) {
|
|
110
|
+
result[child._key] = child._attributes;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (Object.keys(result).length === 0) {
|
|
115
|
+
console.warn(`โ ๏ธ Nessun dato valido per ${record.name}`);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fs.writeFileSync(filePath, JSON.stringify(result, null, 2), "utf8");
|
|
120
|
+
|
|
121
|
+
console.log(`๐ File scritto: ${fileName}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
console.log("๐ Tutti i file con contenuto valido sono stati generati");
|
|
156
|
+
|
|
157
|
+
} catch (err) {
|
|
158
|
+
console.error("โ Errore:", err.message);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
package/index.js
CHANGED
|
@@ -5,11 +5,13 @@ import { hideBin } from "yargs/helpers";
|
|
|
5
5
|
import aliasSet from "./commands/aliasSet.js";
|
|
6
6
|
import retrieve from "./commands/retrieve.js";
|
|
7
7
|
import deploy from "./commands/deploy.js";
|
|
8
|
+
import retrievedatamap from "./commands/retrievedatamap.js";
|
|
8
9
|
|
|
9
10
|
yargs(hideBin(process.argv))
|
|
10
11
|
.command(aliasSet)
|
|
11
12
|
.command(retrieve)
|
|
12
13
|
.command(deploy)
|
|
14
|
+
.command(retrievedatamap)
|
|
13
15
|
.demandCommand()
|
|
14
16
|
.help()
|
|
15
17
|
.parse();
|
package/package.json
CHANGED
package/utils/ruleValidator.js
CHANGED
|
@@ -17,7 +17,6 @@ export function validateRule(fileNameWithId, content) {
|
|
|
17
17
|
|
|
18
18
|
const result = hasValidWhenThenBlock(content, fileName);
|
|
19
19
|
if (!result.valid) {
|
|
20
|
-
console.error(result.message); // stampa dinamica dell'errore
|
|
21
20
|
return { valid: false, message: result.message };
|
|
22
21
|
}
|
|
23
22
|
|
|
@@ -95,6 +94,6 @@ function hasValidWhenThenBlock(content, fileName) {
|
|
|
95
94
|
return { valid: false, message: `โ Il file ${fileName} contiene 'when' o 'then' extra fuori dal blocco principale`};
|
|
96
95
|
|
|
97
96
|
}
|
|
98
|
-
|
|
97
|
+
|
|
99
98
|
return { valid: true};
|
|
100
99
|
}
|