-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy paththemes.js
224 lines (183 loc) · 6.82 KB
/
themes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* webMethods.io CLI
* Copyright 2022 Software AG
* Apache-2.0
*/
const request = require('./rest-fetch.js');
var domainName, username, password, timeout;
var prettyprint = false;
var url;
function debug(message) {
logger.debug("<THEMES> " + message);
}
function help() {
return `
\x1b[4mThemes\x1b[0m
\x1b[32mLists whitelabel themes\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
theme [theme-uid]
The theme settings returned can be use as a way to create the theme.
You can use jq to retrieve the theme settings by piping the output to jq, e.g.
node wmiocli.js -d env -u user -p pass theme fl40018d9a1a273bb8aa92bf | jq -c .output.settings.theme > ~/dracula-theme.txt
\x1b[32mDeletes a whitelabel theme\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
theme-delete [theme-uid]
\x1b[32mCreates a new whitelabel theme\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
theme-create dracula 'desc' [theme-settings] "Footer Text" "About Page"
Theme settings can be used from the list example above, e.g.
node wmiocli.js -d env -u user -p pass theme-create dracula7 'updated' "\`cat ~/dracula-theme.txt\`" 'Footer' 'About'
\x1b[32mUpdates a whitelabel theme\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
theme-update themeid dracula 'desc' [theme-settings] "Footer Text" "About Page"
Theme settings can be used from the list example above, e.g.
node wmiocli.js -d env -u user -p pass theme-update themeid dracula7 'updated' "\`cat ~/dracula-theme.txt\`" 'Footer' 'About'
\x1b[32mActivates a whitelabel theme\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
theme-activate [theme-uid]
\x1b[32mDeactivates a whitelabel theme\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
theme-deactivate [theme-uid]
`;
}
function checkForErrors(inBody) {
//Error Codes
//Any error response
}
function init(inDomainName, inUsername, inPassword, inTimeout, inPrettyprint) {
domainName = inDomainName;
username = inUsername;
password = inPassword;
timeout = inTimeout;
prettyprint = inPrettyprint;
url = "https://" + domainName + "/apis/v1/rest/themes";
debug("Username [" + username + "]");
debug("URL [" + url + "]");
debug("Timeout [" + timeout + "]");
}
/**
* Call back function to process REST response
* @param {return data from REST request} data
* @param {status} status
*/
function processResponse(restEndPointUrl, err, data, response) {
let status = response.status;
if (prettyprint == true) {
console.log(JSON.stringify(data, null, 4));
}
else {
console.log(JSON.stringify(data));
}
if (status != 0) {
process.exit(status);
}
}
function list(themeUid) {
debug("List themeUid[" + themeUid + "]")
if (themeUid) url += "/" + themeUid;
request.get(url, username, password, timeout, processResponse);
}
function create(themeName, themeDescription, theme, footerContent, aboutPageContent) {
debug("Create Name [" + themeName + "] Desc [" + themeDescription + "]");
debug("Theme [" + theme + "]");
debug("Footer [" + footerContent + "]");
debug("About Page [" + aboutPageContent + "]");
themeObj = JSON.parse(theme);
var footer;
var about;
//If footer is not specified get it from the theme
if (footerContent !== undefined && footerContent !== null) footer = footerContent
else footer = themeObj.footerContent;
//If about is not specified get it from the theme
if (aboutPageContent !== undefined && aboutPageContent !== null) about = aboutPageContent
else about = themeObj.aboutPageContent;
//Remove footer/about page from the theme
themeObj.footerContent = undefined;
themeObj.aboutPageContent = undefined;
//Remove default favIcon - causes issues
if (themeObj.favIconFileName == "default-favicon.svg") {
themeObj.favIconFileName = undefined;
themeObj.favIconImage = undefined;
}
theme = JSON.stringify(themeObj);
var jsonStr = "{";
jsonStr += '"name":' + '"' + themeName + '",';
jsonStr += '"description":' + '"' + themeDescription + '",';
jsonStr += '"theme":' + theme;
jsonStr += ',';
jsonStr += '"footerContent":' + '"' + footerContent + '",';
jsonStr += '"aboutPageContent":' + '"' + aboutPageContent + '"';
jsonStr += "}";
data = JSON.parse(jsonStr);
request.post(url, username, password, timeout, data, processResponse);
}
function update(themeUid, themeName, themeDescription, theme, footerContent, aboutPageContent) {
debug("Update Theme UID [" + themeUid + "]");
url += "/" + themeUid;
themeObj = JSON.parse(theme);
var footer;
var about;
//If footer is not specified get it from the theme
if (footerContent !== undefined && footerContent !== null) footer = footerContent
else footer = themeObj.footerContent;
//If about is not specified get it from the theme
if (aboutPageContent !== undefined && aboutPageContent !== null) about = aboutPageContent
else about = themeObj.aboutPageContent;
//Remove footer/about page from the theme
themeObj.footerContent = undefined;
themeObj.aboutPageContent = undefined;
//Remove default favIcon - causes issues
if (themeObj.favIconFileName == "default-favicon.svg") {
themeObj.favIconFileName = undefined;
themeObj.favIconImage = undefined;
}
theme = JSON.stringify(themeObj);
var jsonStr = "{";
jsonStr += '"name":' + '"' + themeName + '",';
jsonStr += '"description":' + '"' + themeDescription + '",';
jsonStr += '"theme":' + theme;
jsonStr += ',';
jsonStr += '"footerContent":' + '"' + footerContent + '",';
jsonStr += '"aboutPageContent":' + '"' + aboutPageContent + '"';
jsonStr += "}";
data = JSON.parse(jsonStr);
request.put(url, username, password, timeout, data, processResponse);
}
function del(themeUid) {
debug("Delete Theme UID [" + themeUid + "]");
url += "/" + themeUid;
var data = {};
request.httpDelete(url, username, password, timeout, data, processResponse);
}
function activate(themeUid) {
debug("Activate Theme UID [" + themeUid + "]");
url += "/" + themeUid + "/activate";
var data = {};
request.put(url, username, password, timeout, data, processResponse);
}
function deactivate(themeUid) {
debug("Deactivate Theme UID [" + themeUid + "]");
url += "/" + themeUid + "/deactivate";
var data = {};
request.put(url, username, password, timeout, data, processResponse);
}
//, update, del, default, activate, deactivate
module.exports = { help, init, list, create, update, del, activate, deactivate };