@rockcarver/frodo-lib 0.13.2-0 → 0.14.1
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/CHANGELOG.md +33 -1
- package/cjs/api/ApiTypes.js.map +1 -1
- package/cjs/api/ThemeApi.js +132 -40
- package/cjs/api/ThemeApi.js.map +1 -1
- package/cjs/api/ThemeApi.test.js.map +1 -0
- package/cjs/index.js +5 -1
- package/cjs/index.js.map +1 -1
- package/cjs/ops/JourneyOps.js +260 -237
- package/cjs/ops/JourneyOps.js.map +1 -1
- package/cjs/ops/ThemeOps.js +103 -84
- package/cjs/ops/ThemeOps.js.map +1 -1
- package/cjs/ops/utils/Console.js +21 -5
- package/cjs/ops/utils/Console.js.map +1 -1
- package/cjs/storage/SessionStorage.js +6 -0
- package/cjs/storage/SessionStorage.js.map +1 -1
- package/cjs/test/mocks/ForgeRockApiMockEngine.js +2 -1
- package/cjs/test/mocks/ForgeRockApiMockEngine.js.map +1 -1
- package/cjs/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm-encore.json +77 -0
- package/cjs/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm-putThemes.json +665 -0
- package/cjs/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm.json +1 -1
- package/esm/api/ThemeApi.mjs +129 -41
- package/esm/api/ThemeApi.test.mjs +903 -0
- package/esm/index.mjs +2 -1
- package/esm/ops/JourneyOps.mjs +259 -236
- package/esm/ops/ThemeOps.mjs +44 -34
- package/esm/ops/utils/Console.mjs +18 -4
- package/esm/storage/SessionStorage.mjs +6 -0
- package/esm/test/mocks/ForgeRockApiMockEngine.mjs +2 -2
- package/esm/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm-encore.json +77 -0
- package/esm/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm-putThemes.json +665 -0
- package/esm/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm.json +1 -1
- package/package.json +1 -1
- package/types/api/ApiTypes.d.ts +5 -1
- package/types/api/ApiTypes.d.ts.map +1 -1
- package/types/api/ThemeApi.d.ts +28 -26
- package/types/api/ThemeApi.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/ops/JourneyOps.d.ts.map +1 -1
- package/types/ops/ThemeOps.d.ts +5 -0
- package/types/ops/ThemeOps.d.ts.map +1 -1
- package/types/ops/utils/Console.d.ts +11 -4
- package/types/ops/utils/Console.d.ts.map +1 -1
- package/types/storage/SessionStorage.d.ts +6 -0
- package/types/storage/SessionStorage.d.ts.map +1 -1
- package/types/test/mocks/ForgeRockApiMockEngine.d.ts +1 -1
- package/types/test/mocks/ForgeRockApiMockEngine.d.ts.map +1 -1
|
@@ -1648,7 +1648,7 @@
|
|
|
1648
1648
|
"topBarTextColor": "#69788b"
|
|
1649
1649
|
},
|
|
1650
1650
|
{
|
|
1651
|
-
"_id": "
|
|
1651
|
+
"_id": "d6636b33-111b-40f2-870d-f4dcb7281e43",
|
|
1652
1652
|
"accountFooter": "<div class=\"d-flex justify-content-center py-4 w-100\"><span class=\"pr-1\">© 2021</span>\n<a href=\"#\"target=\"_blank\"class=\"text-body\">My Company, Inc</a><a href=\"#\"target=\"_blank\"style=\"color:#0000ee\"class=\"pl-3 text-body\">Privacy Policy</a><a href=\"#\"target=\"_blank\"style=\"color:#0000ee\"class=\"pl-3 text-body\">Terms & Conditions</a></div>",
|
|
1653
1653
|
"accountFooterEnabled": false,
|
|
1654
1654
|
"accountPageSections": {
|
package/esm/api/ThemeApi.mjs
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { getConfigEntity, putConfigEntity } from './IdmConfigApi';
|
|
2
2
|
import { getCurrentRealmName } from './utils/ApiUtils';
|
|
3
|
-
|
|
3
|
+
import { debug } from '../ops/utils/Console';
|
|
4
|
+
export const THEMEREALM_ID = 'ui/themerealm';
|
|
4
5
|
/**
|
|
5
6
|
* Get realm themes
|
|
6
|
-
* @param {
|
|
7
|
-
* @returns {
|
|
7
|
+
* @param {UiThemeRealmObject} themes object containing themes
|
|
8
|
+
* @returns {ThemeSkeleton[]} array of theme pertaining to the current realm
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
11
|
function getRealmThemes(themes) {
|
|
11
|
-
|
|
12
|
+
if (themes.realm && themes.realm[getCurrentRealmName()]) {
|
|
13
|
+
return themes.realm[getCurrentRealmName()];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return [];
|
|
12
17
|
}
|
|
13
18
|
/**
|
|
14
19
|
* Get all themes
|
|
15
|
-
* @returns {Promise} a promise that resolves to an array of themes
|
|
20
|
+
* @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes
|
|
16
21
|
*/
|
|
17
22
|
|
|
18
23
|
|
|
@@ -22,29 +27,49 @@ export async function getThemes() {
|
|
|
22
27
|
}
|
|
23
28
|
/**
|
|
24
29
|
* Get theme by id
|
|
25
|
-
* @param {
|
|
26
|
-
* @returns {Promise} a promise that resolves to
|
|
30
|
+
* @param {string} themeId theme id
|
|
31
|
+
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object
|
|
27
32
|
*/
|
|
28
33
|
|
|
29
34
|
export async function getTheme(themeId) {
|
|
30
35
|
const themes = await getConfigEntity(THEMEREALM_ID);
|
|
31
|
-
|
|
36
|
+
const found = getRealmThemes(themes).filter(theme => theme._id === themeId);
|
|
37
|
+
|
|
38
|
+
if (found.length === 1) {
|
|
39
|
+
return found[0];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (found.length > 1) {
|
|
43
|
+
throw new Error(`Multiple themes with id "${themeId}" found!`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
throw new Error(`Theme with id "${themeId}" not found!`);
|
|
32
47
|
}
|
|
33
48
|
/**
|
|
34
49
|
* Get theme by name
|
|
35
|
-
* @param {
|
|
36
|
-
* @returns {Promise} a promise that resolves to
|
|
50
|
+
* @param {string} themeName theme name
|
|
51
|
+
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object
|
|
37
52
|
*/
|
|
38
53
|
|
|
39
54
|
export async function getThemeByName(themeName) {
|
|
40
55
|
const themes = await getConfigEntity(THEMEREALM_ID);
|
|
41
|
-
|
|
56
|
+
const found = getRealmThemes(themes).filter(theme => theme.name === themeName);
|
|
57
|
+
|
|
58
|
+
if (found.length === 1) {
|
|
59
|
+
return found[0];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (found.length > 1) {
|
|
63
|
+
throw new Error(`Multiple themes with the name "${themeName}" found!`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
throw new Error(`Theme "${themeName}" not found!`);
|
|
42
67
|
}
|
|
43
68
|
/**
|
|
44
69
|
* Put theme by id
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {
|
|
47
|
-
* @returns {Promise} a promise that resolves to a
|
|
70
|
+
* @param {string} themeId theme id
|
|
71
|
+
* @param {ThemeSkeleton} themeData theme object
|
|
72
|
+
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object
|
|
48
73
|
*/
|
|
49
74
|
|
|
50
75
|
export async function putTheme(themeId, themeData) {
|
|
@@ -68,13 +93,23 @@ export async function putTheme(themeId, themeData) {
|
|
|
68
93
|
}
|
|
69
94
|
|
|
70
95
|
themes.realm[getCurrentRealmName()] = realmThemes;
|
|
71
|
-
|
|
96
|
+
const found = getRealmThemes(await putConfigEntity(THEMEREALM_ID, themes)).filter(theme => theme._id === themeId);
|
|
97
|
+
|
|
98
|
+
if (found.length === 1) {
|
|
99
|
+
return found[0];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (found.length > 1) {
|
|
103
|
+
throw new Error(`Multiple themes with id "${themeId}" found!`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
throw new Error(`Theme with id "${themeId}" not saved!`);
|
|
72
107
|
}
|
|
73
108
|
/**
|
|
74
109
|
* Put theme by name
|
|
75
110
|
* @param {String} themeName theme name
|
|
76
|
-
* @param {
|
|
77
|
-
* @returns {Promise} a promise that resolves to a
|
|
111
|
+
* @param {ThemeSkeleton} themeData theme object
|
|
112
|
+
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a theme object
|
|
78
113
|
*/
|
|
79
114
|
|
|
80
115
|
export async function putThemeByName(themeName, themeData) {
|
|
@@ -98,27 +133,38 @@ export async function putThemeByName(themeName, themeData) {
|
|
|
98
133
|
}
|
|
99
134
|
|
|
100
135
|
themes['realm'][getCurrentRealmName()] = realmThemes;
|
|
101
|
-
|
|
136
|
+
const found = getRealmThemes(await putConfigEntity(THEMEREALM_ID, themes)).filter(theme => theme.name === themeName);
|
|
137
|
+
|
|
138
|
+
if (found.length === 1) {
|
|
139
|
+
return found[0];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (found.length > 1) {
|
|
143
|
+
throw new Error(`Multiple themes "${themeName}" found!`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
throw new Error(`Theme "${themeName}" not saved!`);
|
|
102
147
|
}
|
|
103
148
|
/**
|
|
104
149
|
* Put all themes
|
|
105
|
-
* @param {
|
|
106
|
-
* @returns {Promise} a promise that resolves to a themes object
|
|
150
|
+
* @param {Map<string, ThemeSkeleton>} allThemesData themes object containing all themes for all realms
|
|
151
|
+
* @returns {Promise<Map<string, ThemeSkeleton>>} a promise that resolves to a themes object
|
|
107
152
|
*/
|
|
108
153
|
|
|
109
|
-
export async function putThemes(
|
|
110
|
-
|
|
154
|
+
export async function putThemes(themeMap) {
|
|
155
|
+
debug(`ThemeApi.putThemes: start`);
|
|
111
156
|
const themes = await getConfigEntity(THEMEREALM_ID);
|
|
112
|
-
const allThemeIDs = Object.keys(
|
|
157
|
+
const allThemeIDs = Object.keys(themeMap);
|
|
113
158
|
const existingThemeIDs = [];
|
|
114
159
|
let defaultThemeId = null; // update existing themes
|
|
115
160
|
|
|
116
161
|
let realmThemes = getRealmThemes(themes).map(theme => {
|
|
117
|
-
if (
|
|
162
|
+
if (themeMap[theme._id]) {
|
|
163
|
+
debug(`Update theme: ${theme._id} - ${theme.name}`);
|
|
118
164
|
existingThemeIDs.push(theme._id); // remember the id of the last default theme
|
|
119
165
|
|
|
120
|
-
if (
|
|
121
|
-
return
|
|
166
|
+
if (themeMap[theme._id].isDefault) defaultThemeId = theme._id;
|
|
167
|
+
return themeMap[theme._id];
|
|
122
168
|
}
|
|
123
169
|
|
|
124
170
|
return theme;
|
|
@@ -126,9 +172,10 @@ export async function putThemes(allThemesData) {
|
|
|
126
172
|
const newThemeIDs = allThemeIDs.filter(id => !existingThemeIDs.includes(id)); // add new themes
|
|
127
173
|
|
|
128
174
|
newThemeIDs.forEach(themeId => {
|
|
129
|
-
// remember the id of the last default theme
|
|
130
|
-
|
|
131
|
-
|
|
175
|
+
debug(`Add theme: ${themeMap[themeId]._id} - ${themeMap[themeId].name}`); // remember the id of the last default theme
|
|
176
|
+
|
|
177
|
+
if (themeMap[themeId].isDefault) defaultThemeId = themeId;
|
|
178
|
+
realmThemes.push(themeMap[themeId]);
|
|
132
179
|
}); // if we imported a default theme, flag all the other themes as not default
|
|
133
180
|
|
|
134
181
|
if (defaultThemeId) {
|
|
@@ -140,44 +187,85 @@ export async function putThemes(allThemesData) {
|
|
|
140
187
|
}
|
|
141
188
|
|
|
142
189
|
themes.realm[getCurrentRealmName()] = realmThemes;
|
|
143
|
-
|
|
190
|
+
const updatedThemes = new Map(getRealmThemes(await putConfigEntity(THEMEREALM_ID, themes)).map(theme => [theme._id, theme]));
|
|
191
|
+
debug(updatedThemes);
|
|
192
|
+
debug(`ThemeApi.putThemes: finished`);
|
|
193
|
+
return updatedThemes;
|
|
144
194
|
}
|
|
145
195
|
/**
|
|
146
196
|
* Delete theme by id
|
|
147
|
-
* @param {
|
|
148
|
-
* @returns {Promise} a promise that resolves to a themes object
|
|
197
|
+
* @param {string} themeId theme id
|
|
198
|
+
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object
|
|
149
199
|
*/
|
|
150
200
|
|
|
151
201
|
export async function deleteTheme(themeId) {
|
|
152
202
|
const themes = await getConfigEntity(THEMEREALM_ID);
|
|
153
203
|
const realmThemes = getRealmThemes(themes);
|
|
154
|
-
const
|
|
204
|
+
const deletedThemes = [];
|
|
205
|
+
const finalThemes = realmThemes.filter(theme => {
|
|
206
|
+
if (theme._id !== themeId) {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
deletedThemes.push(theme);
|
|
211
|
+
return false;
|
|
212
|
+
});
|
|
155
213
|
if (realmThemes.length === finalThemes.length) throw new Error(`${themeId} not found`);
|
|
156
214
|
themes.realm[getCurrentRealmName()] = realmThemes;
|
|
157
|
-
|
|
215
|
+
const undeletedThemes = getRealmThemes(await putConfigEntity(THEMEREALM_ID, themes)).filter(theme => deletedThemes.includes(theme));
|
|
216
|
+
|
|
217
|
+
if (deletedThemes.length > 0 && undeletedThemes.length === 0) {
|
|
218
|
+
return deletedThemes[0];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
throw new Error(`Theme(s) with id(s) "${undeletedThemes.map(theme => theme._id)}" not deleted!`);
|
|
158
222
|
}
|
|
159
223
|
/**
|
|
160
224
|
* Delete theme by name
|
|
161
|
-
* @param {
|
|
162
|
-
* @returns {Promise} a promise that resolves to a themes object
|
|
225
|
+
* @param {string} themeName theme name
|
|
226
|
+
* @returns {Promise<ThemeSkeleton>} a promise that resolves to a themes object
|
|
163
227
|
*/
|
|
164
228
|
|
|
165
229
|
export async function deleteThemeByName(themeName) {
|
|
166
230
|
const themes = await getConfigEntity(THEMEREALM_ID);
|
|
167
231
|
const realmThemes = getRealmThemes(themes);
|
|
168
|
-
const
|
|
232
|
+
const deletedThemes = [];
|
|
233
|
+
const finalThemes = realmThemes.filter(theme => {
|
|
234
|
+
if (theme.name !== themeName) {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
deletedThemes.push(theme);
|
|
239
|
+
return false;
|
|
240
|
+
});
|
|
169
241
|
if (realmThemes.length === finalThemes.length) throw new Error(`${themeName} not found`);
|
|
170
|
-
themes.realm[getCurrentRealmName()] = finalThemes;
|
|
171
|
-
|
|
242
|
+
themes.realm[getCurrentRealmName()] = finalThemes; // return putConfigEntity(THEMEREALM_ID, themes);
|
|
243
|
+
|
|
244
|
+
const undeletedThemes = getRealmThemes(await putConfigEntity(THEMEREALM_ID, themes)).filter(theme => deletedThemes.includes(theme));
|
|
245
|
+
|
|
246
|
+
if (deletedThemes.length > 0 && undeletedThemes.length === 0) {
|
|
247
|
+
return deletedThemes[0];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
throw new Error(`Theme(s) with id(s) "${undeletedThemes.map(theme => theme._id)}" not deleted!`);
|
|
172
251
|
}
|
|
173
252
|
/**
|
|
174
253
|
* Delete all themes
|
|
175
|
-
* @returns {Promise} a promise that resolves to an array of themes
|
|
254
|
+
* @returns {Promise<ThemeSkeleton[]>} a promise that resolves to an array of themes
|
|
176
255
|
*/
|
|
177
256
|
|
|
178
257
|
export async function deleteThemes() {
|
|
179
258
|
const themes = await getConfigEntity(THEMEREALM_ID);
|
|
259
|
+
const realmThemes = themes.realm[getCurrentRealmName()];
|
|
260
|
+
if (!realmThemes) throw new Error(`No theme configuration found for realm "${getCurrentRealmName()}"`);
|
|
261
|
+
const deletedThemes = [];
|
|
262
|
+
|
|
263
|
+
for (const theme of realmThemes) {
|
|
264
|
+
deletedThemes.push(theme);
|
|
265
|
+
}
|
|
266
|
+
|
|
180
267
|
themes.realm[getCurrentRealmName()] = [];
|
|
181
|
-
|
|
268
|
+
await putConfigEntity(THEMEREALM_ID, themes);
|
|
269
|
+
return deletedThemes;
|
|
182
270
|
}
|
|
183
271
|
//# sourceMappingURL=ThemeApi.js.map
|