musora-content-services 2.3.6 → 2.3.8

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 (132) hide show
  1. package/.coderabbit.yaml +0 -0
  2. package/.editorconfig +0 -0
  3. package/.github/workflows/node.js.yml +0 -0
  4. package/.prettierignore +0 -0
  5. package/.prettierrc +0 -0
  6. package/.yarnrc.yml +1 -0
  7. package/CHANGELOG.md +9 -0
  8. package/README.md +0 -0
  9. package/babel.config.cjs +0 -0
  10. package/docs/Content-Organization.html +0 -0
  11. package/docs/ContentOrganization.html +0 -0
  12. package/docs/Gamification.html +0 -0
  13. package/docs/UserManagement.html +0 -0
  14. package/docs/UserManagementSystem.html +0 -0
  15. package/docs/api_types.js.html +0 -0
  16. package/docs/config.js.html +0 -0
  17. package/docs/content-org_content-org.js.html +0 -0
  18. package/docs/content-org_playlists-types.js.html +0 -0
  19. package/docs/content-org_playlists.js.html +0 -0
  20. package/docs/content.js.html +0 -0
  21. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  22. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  23. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  24. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  25. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  26. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  27. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  28. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  29. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  30. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
  31. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  32. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  33. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  34. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  35. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
  36. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  37. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  38. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  39. package/docs/gamification_awards.js.html +0 -0
  40. package/docs/gamification_gamification.js.html +0 -0
  41. package/docs/gamification_types.js.html +0 -0
  42. package/docs/global.html +0 -0
  43. package/docs/global.html#User +0 -0
  44. package/docs/index.html +0 -0
  45. package/docs/module-Awards.html +0 -0
  46. package/docs/module-Config.html +0 -0
  47. package/docs/module-Content-Services-V2.html +0 -0
  48. package/docs/module-Content-Services.html +763 -0
  49. package/docs/module-Permissions.html +0 -0
  50. package/docs/module-Playlists.html +0 -0
  51. package/docs/module-Railcontent-Services.html +0 -0
  52. package/docs/module-Sanity-Services.html +0 -0
  53. package/docs/module-Session-Management.html +0 -0
  54. package/docs/module-Sessions.html +0 -0
  55. package/docs/module-User-Management.html +0 -0
  56. package/docs/module-User-Permissions.html +0 -0
  57. package/docs/module-UserManagement.html +0 -0
  58. package/docs/railcontent.js.html +0 -0
  59. package/docs/sanity.js.html +0 -0
  60. package/docs/scripts/collapse.js +0 -0
  61. package/docs/scripts/commonNav.js +0 -0
  62. package/docs/scripts/linenumber.js +0 -0
  63. package/docs/scripts/nav.js +0 -0
  64. package/docs/scripts/polyfill.js +0 -0
  65. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -0
  66. package/docs/scripts/prettify/lang-css.js +0 -0
  67. package/docs/scripts/prettify/prettify.js +0 -0
  68. package/docs/scripts/search.js +0 -0
  69. package/docs/styles/jsdoc.css +0 -0
  70. package/docs/styles/prettify.css +0 -0
  71. package/docs/types.js.html +0 -0
  72. package/docs/user_management.js.html +0 -0
  73. package/docs/user_permissions.js.html +0 -0
  74. package/docs/user_sessions.js.html +0 -0
  75. package/docs/user_types.js.html +0 -0
  76. package/docs/user_user-management-system.js.html +0 -0
  77. package/docs/user_user-management.js.html +0 -0
  78. package/jest.config.js +0 -0
  79. package/jsdoc.json +0 -0
  80. package/link_mcs.sh +0 -0
  81. package/package.json +1 -1
  82. package/src/contentMetaData.js +0 -0
  83. package/src/filterBuilder.js +0 -0
  84. package/src/index.d.ts +13 -0
  85. package/src/index.js +13 -0
  86. package/src/lib/httpHelper.js +0 -0
  87. package/src/lib/lastUpdated.js +0 -0
  88. package/src/services/api/types.js +0 -0
  89. package/src/services/config.js +0 -0
  90. package/src/services/content-org/content-org.js +0 -0
  91. package/src/services/content-org/playlists-types.js +0 -0
  92. package/src/services/content-org/playlists.js +0 -0
  93. package/src/services/content.js +0 -0
  94. package/src/services/contentLikes.js +0 -0
  95. package/src/services/contentProgress.js +0 -0
  96. package/src/services/dataContext.js +0 -0
  97. package/src/services/dateUtils.js +55 -0
  98. package/src/services/forum.js +0 -0
  99. package/src/services/gamification/awards.js +0 -0
  100. package/src/services/gamification/gamification.js +0 -0
  101. package/src/services/gamification/types.js +0 -0
  102. package/src/services/imageSRCBuilder.js +0 -0
  103. package/src/services/imageSRCVerify.js +0 -0
  104. package/src/services/railcontent.js +30 -18
  105. package/src/services/recommendations.js +10 -9
  106. package/src/services/types.js +0 -0
  107. package/src/services/user/management.js +0 -0
  108. package/src/services/user/permissions.js +0 -0
  109. package/src/services/user/sessions.js +0 -0
  110. package/src/services/user/types.js +0 -0
  111. package/src/services/user/user-management-system.js +0 -0
  112. package/src/services/userActivity.js +289 -106
  113. package/test/content.test.js +0 -0
  114. package/test/contentLikes.test.js +0 -0
  115. package/test/contentProgress.test.js +0 -0
  116. package/test/dataContext.test.js +0 -0
  117. package/test/forum.test.js +0 -0
  118. package/test/imageSRCBuilder.test.js +0 -0
  119. package/test/imageSRCVerify.test.js +0 -0
  120. package/test/initializeTests.js +0 -0
  121. package/test/lib/lastUpdated.test.js +0 -0
  122. package/test/live/contentProgressLive.test.js +0 -0
  123. package/test/live/railcontentLive.test.js +0 -0
  124. package/test/localStorageMock.js +0 -0
  125. package/test/log.js +0 -0
  126. package/test/mockData/mockData_fetchByRailContentIds_one_content.json +0 -0
  127. package/test/mockData/mockData_user_practices.json +9 -0
  128. package/test/sanityQueryService.test.js +0 -0
  129. package/test/streakMessage.test.js +263 -0
  130. package/test/user/permissions.test.js +0 -0
  131. package/test/userActivity.test.js +6 -6
  132. package/tools/generate-index.cjs +0 -0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/jest.config.js CHANGED
File without changes
package/jsdoc.json CHANGED
File without changes
package/link_mcs.sh CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "2.3.6",
3
+ "version": "2.3.8",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
File without changes
File without changes
package/src/index.d.ts CHANGED
@@ -47,6 +47,14 @@ import {
47
47
  verifyLocalDataContext
48
48
  } from './services/dataContext.js';
49
49
 
50
+ import {
51
+ convertToTimeZone,
52
+ getMonday,
53
+ getWeekNumber,
54
+ isNextDay,
55
+ isSameDate
56
+ } from './services/dateUtils.js';
57
+
50
58
  import {
51
59
  getActiveDiscussions
52
60
  } from './services/forum.js';
@@ -236,6 +244,7 @@ declare module 'musora-content-services' {
236
244
  closeComment,
237
245
  contentStatusCompleted,
238
246
  contentStatusReset,
247
+ convertToTimeZone,
239
248
  countAssignmentsAndLessons,
240
249
  createComment,
241
250
  createPlaylist,
@@ -332,6 +341,7 @@ declare module 'musora-content-services' {
332
341
  getAllStartedOrCompleted,
333
342
  getContentRows,
334
343
  getLessonContentRows,
344
+ getMonday,
335
345
  getNewAndUpcoming,
336
346
  getPracticeSessions,
337
347
  getProgressPercentage,
@@ -348,10 +358,13 @@ declare module 'musora-content-services' {
348
358
  getUserMonthlyStats,
349
359
  getUserPractices,
350
360
  getUserWeeklyStats,
361
+ getWeekNumber,
351
362
  globalConfig,
352
363
  initializeService,
353
364
  isBucketUrl,
354
365
  isContentLiked,
366
+ isNextDay,
367
+ isSameDate,
355
368
  jumpToContinueContent,
356
369
  likeComment,
357
370
  likeContent,
package/src/index.js CHANGED
@@ -47,6 +47,14 @@ import {
47
47
  verifyLocalDataContext
48
48
  } from './services/dataContext.js';
49
49
 
50
+ import {
51
+ convertToTimeZone,
52
+ getMonday,
53
+ getWeekNumber,
54
+ isNextDay,
55
+ isSameDate
56
+ } from './services/dateUtils.js';
57
+
50
58
  import {
51
59
  getActiveDiscussions
52
60
  } from './services/forum.js';
@@ -235,6 +243,7 @@ export {
235
243
  closeComment,
236
244
  contentStatusCompleted,
237
245
  contentStatusReset,
246
+ convertToTimeZone,
238
247
  countAssignmentsAndLessons,
239
248
  createComment,
240
249
  createPlaylist,
@@ -331,6 +340,7 @@ export {
331
340
  getAllStartedOrCompleted,
332
341
  getContentRows,
333
342
  getLessonContentRows,
343
+ getMonday,
334
344
  getNewAndUpcoming,
335
345
  getPracticeSessions,
336
346
  getProgressPercentage,
@@ -347,10 +357,13 @@ export {
347
357
  getUserMonthlyStats,
348
358
  getUserPractices,
349
359
  getUserWeeklyStats,
360
+ getWeekNumber,
350
361
  globalConfig,
351
362
  initializeService,
352
363
  isBucketUrl,
353
364
  isContentLiked,
365
+ isNextDay,
366
+ isSameDate,
354
367
  jumpToContinueContent,
355
368
  likeComment,
356
369
  likeContent,
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,55 @@
1
+ // dateUtils.js
2
+
3
+ export function convertToTimeZone(date, timeZone) {
4
+ const formatter = new Intl.DateTimeFormat('en-US', {
5
+ timeZone,
6
+ year: 'numeric',
7
+ month: '2-digit',
8
+ day: '2-digit',
9
+ hour: '2-digit',
10
+ minute: '2-digit',
11
+ second: '2-digit',
12
+ hour12: false,
13
+ });
14
+
15
+ const parts = formatter.formatToParts(date).reduce((acc, part) => {
16
+ if (part.type !== 'literal') acc[part.type] = part.value;
17
+ return acc;
18
+ }, {});
19
+
20
+ return new Date(`${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}:${parts.second}`);
21
+ }
22
+ // Get start of the week (Monday)
23
+ export function getMonday(date) {
24
+ const d = new Date(date);
25
+ const day = d.getDay();
26
+ const diff = d.getDate() - day + (day === 0 ? -6 : 1);
27
+ return new Date(d.setDate(diff));
28
+ }
29
+
30
+ // Get the week number
31
+ export function getWeekNumber(d) {
32
+ let newDate = new Date(d.getTime());
33
+ newDate.setUTCDate(newDate.getUTCDate() + 4 - (newDate.getUTCDay()||7));
34
+ var yearStart = new Date(Date.UTC(newDate.getUTCFullYear(),0,1));
35
+ var weekNo = Math.ceil(( ( (newDate - yearStart) / 86400000) + 1)/7);
36
+ return weekNo;
37
+ }
38
+ //Check if two dates are the same
39
+ export function isSameDate(date1, date2, method = '') {
40
+ return date1.toISOString().split('T')[0] === date2.toISOString().split('T')[0];
41
+ }
42
+
43
+ // Check if two dates are consecutive days
44
+ export function isNextDay(prev, current) {
45
+ const prevDate = new Date(prev.getFullYear(), prev.getMonth(), prev.getDate());
46
+ const nextDate = new Date(prevDate);
47
+ nextDate.setDate(prevDate.getDate() + 1); // Add 1 day
48
+
49
+ return (
50
+ nextDate.getFullYear() === current.getFullYear() &&
51
+ nextDate.getMonth() === current.getMonth() &&
52
+ nextDate.getDate() === current.getDate()
53
+ );
54
+ }
55
+
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import { globalConfig } from './config.js'
5
5
  import { fetchJSONHandler } from '../lib/httpHelper.js'
6
+ import { convertToTimeZone } from './dateUtils.js';
6
7
 
7
8
  /**
8
9
  * Exported functions that are excluded from index generation.
@@ -1175,31 +1176,42 @@ export async function editComment(commentId, comment) {
1175
1176
  }
1176
1177
 
1177
1178
  export async function fetchUserPractices(currentVersion) {
1178
- const url = `/api/user/practices/v1/practices`
1179
- const response = await fetchDataHandler(url, currentVersion)
1180
- const { data, version } = response
1181
- const userPractices = data
1182
-
1183
- let formattedPractices = userPractices.reduce((acc, practice) => {
1184
- // Initialize the array if the day does not exist
1185
- if (!acc[practice.day]) {
1186
- acc[practice.day] = []
1179
+ const url = `/api/user/practices/v1/practices`;
1180
+ const response = await fetchDataHandler(url, currentVersion);
1181
+ const { data, version } = response;
1182
+ const userPractices = data;
1183
+
1184
+ const userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
1185
+
1186
+
1187
+ const formattedPractices = userPractices.reduce((acc, practice) => {
1188
+ // Convert UTC date to user's local date (still a Date object)
1189
+ const utcDate = new Date(practice.day);
1190
+ const localDate = convertToTimeZone(utcDate, userTimeZone);
1191
+
1192
+ const userTimeZoneDay =
1193
+ localDate.getFullYear() + '-' +
1194
+ String(localDate.getMonth() + 1).padStart(2, '0') + '-' +
1195
+ String(localDate.getDate()).padStart(2, '0');
1196
+
1197
+ if (!acc[userTimeZoneDay]) {
1198
+ acc[userTimeZoneDay] = [];
1187
1199
  }
1188
1200
 
1189
- // Push the practice entry into the array
1190
- acc[practice.day].push({ id: practice.id, duration_seconds: practice.duration_seconds })
1201
+ acc[userTimeZoneDay].push({
1202
+ id: practice.id,
1203
+ duration_seconds: practice.duration_seconds,
1204
+ });
1191
1205
 
1192
- return acc
1193
- }, {})
1206
+ return acc;
1207
+ }, {});
1194
1208
 
1195
- let json = {
1209
+ return {
1196
1210
  data: {
1197
1211
  practices: formattedPractices,
1198
1212
  },
1199
- version: version,
1200
- }
1201
-
1202
- return json
1213
+ version,
1214
+ };
1203
1215
  }
1204
1216
 
1205
1217
  export async function logUserPractice(practiceDetails) {
@@ -113,16 +113,17 @@ export async function rankItems(brand, content_ids) {
113
113
  }
114
114
  }
115
115
 
116
- export async function recommendations(brand, { page = 1, limit = 10 } = {}) {
117
- let data = {
118
- brand: brand,
119
- user_id: globalConfig.sessionConfig.userId,
120
- num_recommendations: limit,
121
- }
122
- const url = `/recommendations/`
116
+ export async function recommendations(brand, { section = ''} = {}) {
117
+ section = section.toUpperCase().replace('-', '_')
118
+ const sectionString = section ? `&section=${section}` : '';
119
+ const url = `/api/content/v1/recommendations?brand=${brand}${sectionString}`
123
120
  try {
124
- const response = await fetchHandler(url, 'POST', data)
125
- return response['recommendations']
121
+ return fetchJSONHandler(
122
+ url,
123
+ globalConfig.railcontentConfig.token,
124
+ globalConfig.railcontentConfig.baseUrl,
125
+ 'get'
126
+ )
126
127
  } catch (error) {
127
128
  console.error('Fetch error:', error)
128
129
  return null
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes