@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.
Files changed (47) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/cjs/api/ApiTypes.js.map +1 -1
  3. package/cjs/api/ThemeApi.js +132 -40
  4. package/cjs/api/ThemeApi.js.map +1 -1
  5. package/cjs/api/ThemeApi.test.js.map +1 -0
  6. package/cjs/index.js +5 -1
  7. package/cjs/index.js.map +1 -1
  8. package/cjs/ops/JourneyOps.js +260 -237
  9. package/cjs/ops/JourneyOps.js.map +1 -1
  10. package/cjs/ops/ThemeOps.js +103 -84
  11. package/cjs/ops/ThemeOps.js.map +1 -1
  12. package/cjs/ops/utils/Console.js +21 -5
  13. package/cjs/ops/utils/Console.js.map +1 -1
  14. package/cjs/storage/SessionStorage.js +6 -0
  15. package/cjs/storage/SessionStorage.js.map +1 -1
  16. package/cjs/test/mocks/ForgeRockApiMockEngine.js +2 -1
  17. package/cjs/test/mocks/ForgeRockApiMockEngine.js.map +1 -1
  18. package/cjs/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm-encore.json +77 -0
  19. package/cjs/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm-putThemes.json +665 -0
  20. package/cjs/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm.json +1 -1
  21. package/esm/api/ThemeApi.mjs +129 -41
  22. package/esm/api/ThemeApi.test.mjs +903 -0
  23. package/esm/index.mjs +2 -1
  24. package/esm/ops/JourneyOps.mjs +259 -236
  25. package/esm/ops/ThemeOps.mjs +44 -34
  26. package/esm/ops/utils/Console.mjs +18 -4
  27. package/esm/storage/SessionStorage.mjs +6 -0
  28. package/esm/test/mocks/ForgeRockApiMockEngine.mjs +2 -2
  29. package/esm/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm-encore.json +77 -0
  30. package/esm/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm-putThemes.json +665 -0
  31. package/esm/test/mocks/IdmConfigApi/getConfigEntity/ui/themerealm.json +1 -1
  32. package/package.json +1 -1
  33. package/types/api/ApiTypes.d.ts +5 -1
  34. package/types/api/ApiTypes.d.ts.map +1 -1
  35. package/types/api/ThemeApi.d.ts +28 -26
  36. package/types/api/ThemeApi.d.ts.map +1 -1
  37. package/types/index.d.ts +1 -0
  38. package/types/index.d.ts.map +1 -1
  39. package/types/ops/JourneyOps.d.ts.map +1 -1
  40. package/types/ops/ThemeOps.d.ts +5 -0
  41. package/types/ops/ThemeOps.d.ts.map +1 -1
  42. package/types/ops/utils/Console.d.ts +11 -4
  43. package/types/ops/utils/Console.d.ts.map +1 -1
  44. package/types/storage/SessionStorage.d.ts +6 -0
  45. package/types/storage/SessionStorage.d.ts.map +1 -1
  46. package/types/test/mocks/ForgeRockApiMockEngine.d.ts +1 -1
  47. package/types/test/mocks/ForgeRockApiMockEngine.d.ts.map +1 -1
@@ -1648,7 +1648,7 @@
1648
1648
  "topBarTextColor": "#69788b"
1649
1649
  },
1650
1650
  {
1651
- "_id": "2c23505e-e10c-4f09-be73-13307f615298",
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": {
@@ -1,18 +1,23 @@
1
1
  import { getConfigEntity, putConfigEntity } from './IdmConfigApi';
2
2
  import { getCurrentRealmName } from './utils/ApiUtils';
3
- const THEMEREALM_ID = 'ui/themerealm';
3
+ import { debug } from '../ops/utils/Console';
4
+ export const THEMEREALM_ID = 'ui/themerealm';
4
5
  /**
5
6
  * Get realm themes
6
- * @param {Object} themes object containing themes
7
- * @returns {Object} array of theme pertaining to the current realm
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
- return themes.realm[getCurrentRealmName()] ? themes.realm[getCurrentRealmName()] : [];
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 {String} themeId theme id
26
- * @returns {Promise} a promise that resolves to an array of themes
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
- return getRealmThemes(themes).filter(theme => theme._id === themeId);
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 {String} themeName theme name
36
- * @returns {Promise} a promise that resolves to an array of themes
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
- return getRealmThemes(themes).filter(theme => theme.name === themeName);
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 {String} themeId theme id
46
- * @param {Object} themeData theme object
47
- * @returns {Promise} a promise that resolves to a themes object
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
- return putConfigEntity(THEMEREALM_ID, themes);
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 {Object} themeData theme object
77
- * @returns {Promise} a promise that resolves to a themes object
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
- return putConfigEntity(THEMEREALM_ID, themes);
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 {Object} allThemesData themes object containing all themes for all realms
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(allThemesData) {
110
- const data = allThemesData;
154
+ export async function putThemes(themeMap) {
155
+ debug(`ThemeApi.putThemes: start`);
111
156
  const themes = await getConfigEntity(THEMEREALM_ID);
112
- const allThemeIDs = Object.keys(data);
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 (data[theme._id]) {
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 (data[theme._id].isDefault) defaultThemeId = theme._id;
121
- return data[theme._id];
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
- if (data[themeId].isDefault) defaultThemeId = themeId;
131
- realmThemes.push(data[themeId]);
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
- return putConfigEntity(THEMEREALM_ID, themes);
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 {String} themeId theme id
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 finalThemes = realmThemes.filter(theme => theme._id !== themeId);
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
- return putConfigEntity(THEMEREALM_ID, themes);
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 {String} themeName theme name
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 finalThemes = realmThemes.filter(theme => theme.name !== themeName);
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
- return putConfigEntity(THEMEREALM_ID, themes);
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
- return putConfigEntity(THEMEREALM_ID, themes);
268
+ await putConfigEntity(THEMEREALM_ID, themes);
269
+ return deletedThemes;
182
270
  }
183
271
  //# sourceMappingURL=ThemeApi.js.map