musora-content-services 2.5.1 → 2.6.0

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 (48) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/docs/ContentOrganization.html +2 -2
  3. package/docs/Gamification.html +2 -2
  4. package/docs/UserManagementSystem.html +2 -2
  5. package/docs/api_types.js.html +2 -2
  6. package/docs/config.js.html +2 -2
  7. package/docs/content-org_content-org.js.html +2 -2
  8. package/docs/content-org_playlists-types.js.html +2 -2
  9. package/docs/content-org_playlists.js.html +2 -2
  10. package/docs/content.js.html +2 -4
  11. package/docs/gamification_awards.js.html +2 -2
  12. package/docs/gamification_gamification.js.html +2 -2
  13. package/docs/gamification_types.js.html +2 -2
  14. package/docs/global.html +448 -2
  15. package/docs/index.html +2 -2
  16. package/docs/module-Awards.html +2 -2
  17. package/docs/module-Config.html +2 -2
  18. package/docs/module-Content-Services-V2.html +8 -8
  19. package/docs/module-Interests.html +2 -2
  20. package/docs/module-Permissions.html +2 -2
  21. package/docs/module-Playlists.html +2 -2
  22. package/docs/module-Railcontent-Services.html +754 -44
  23. package/docs/module-Sanity-Services.html +2 -2
  24. package/docs/module-Sessions.html +2 -2
  25. package/docs/module-User-Activity.html +525 -16
  26. package/docs/module-UserManagement.html +2 -2
  27. package/docs/module-UserProfile.html +266 -0
  28. package/docs/railcontent.js.html +41 -2
  29. package/docs/sanity.js.html +2 -2
  30. package/docs/userActivity.js.html +348 -263
  31. package/docs/user_interests.js.html +2 -2
  32. package/docs/user_management.js.html +2 -2
  33. package/docs/user_permissions.js.html +2 -2
  34. package/docs/user_profile.js.html +105 -0
  35. package/docs/user_sessions.js.html +2 -2
  36. package/docs/user_types.js.html +22 -2
  37. package/docs/user_user-management-system.js.html +2 -2
  38. package/package.json +1 -1
  39. package/src/contentMetaData.js +14 -0
  40. package/src/index.d.ts +15 -0
  41. package/src/index.js +15 -0
  42. package/src/services/content.js +0 -2
  43. package/src/services/railcontent.js +39 -0
  44. package/src/services/user/profile.js +33 -0
  45. package/src/services/user/types.js +20 -0
  46. package/src/services/userActivity.js +346 -261
  47. package/test/content.test.js +8 -6
  48. package/test/sanityQueryService.test.js +6 -0
@@ -848,6 +848,45 @@ export async function fetchLastInteractedChild(content_ids) {
848
848
  return await fetchHandler(url, 'GET', null)
849
849
  }
850
850
 
851
+ /**
852
+ * @typedef {Object} Activity
853
+ * @property {string} id - Unique identifier for the activity.
854
+ * @property {string} type - Type of activity (e.g., "lesson_completed").
855
+ * @property {string} timestamp - ISO 8601 string of when the activity occurred.
856
+ * @property {Object} meta - Additional metadata related to the activity.
857
+ */
858
+
859
+ /**
860
+ * @typedef {Object} PaginatedActivities
861
+ * @property {number} currentPage
862
+ * @property {number} totalPages
863
+ * @property {Activity[]} data
864
+ */
865
+
866
+ /**
867
+ * Fetches a paginated list of recent user activities.
868
+ * @param {Object} [params={}] - Optional parameters.
869
+ * @param {number} [params.page=1] - The page number for pagination.
870
+ * @param {number} [params.limit=10] - The number of results per page.
871
+ * @param {string|null} [params.tabName=null] - Optional filter for activity type/tab.
872
+ * @returns {Promise<PaginatedActivities>} - A promise that resolves to a paginated object of user activities.
873
+ *
874
+ * @example
875
+ * fetchRecentUserActivities({ page: 2, limit: 5 })
876
+ * .then(activities => console.log(activities))
877
+ * .catch(error => console.error(error));
878
+ */
879
+ export async function fetchRecentUserActivities({
880
+ page = 1,
881
+ limit = 5,
882
+ tabName = null
883
+ } = {}) {
884
+ let pageAndLimit = `?page=${page}&limit=${limit}`
885
+ let tabParam = tabName ? `&tabName=${tabName}` : ''
886
+ const url = `/api/user-management-system/v1/activities/all${pageAndLimit}${tabParam}`
887
+ return await fetchHandler(url, 'GET', null)
888
+ }
889
+
851
890
 
852
891
  function fetchAbsolute(url, params) {
853
892
  if (globalConfig.sessionConfig.authToken) {
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @module UserProfile
3
+ */
4
+ import { fetchJSONHandler } from '../../lib/httpHelper.js'
5
+ import { globalConfig } from '../config.js'
6
+ import { calculateLongestStreaks } from '../userActivity.js'
7
+ import './types.js'
8
+
9
+ const baseUrl = `/api/user-management-system`
10
+
11
+ /**
12
+ * @param {number|null} userId - The user ID to reset permissions for.
13
+ * @returns {Promise<OtherStatsDTO>}
14
+ */
15
+ export async function otherStats(userId = globalConfig.sessionConfig.userId) {
16
+ const [otherStats, longestStreaks] = await Promise.all([
17
+ fetchJSONHandler(`${baseUrl}/v1/users/${userId}/permissions`, 'delete'),
18
+ calculateLongestStreaks(userId),
19
+ ])
20
+
21
+ return {
22
+ ...otherStats,
23
+ longest_day_streak: {
24
+ type: 'day',
25
+ length: longestStreaks.longestDailyStreak,
26
+ },
27
+ longest_week_streak: {
28
+ type: 'week',
29
+ length: longestStreaks.longestWeeklyStreak,
30
+ },
31
+ total_practice_time: longestStreaks.totalPracticeSeconds,
32
+ }
33
+ }
@@ -114,3 +114,23 @@
114
114
  * @property {boolean} isAdmin
115
115
  * @property {boolean} isABasicMember
116
116
  */
117
+
118
+ /**
119
+ * @typedef {Object} StreakDTO
120
+ *
121
+ * @property {string} type - week or day
122
+ * @property {number} length
123
+ * @property {Date|null} start_date
124
+ * @property {Date|null} end_date
125
+ */
126
+
127
+ /**
128
+ * @typedef {Object} OtherStatsDTO
129
+ *
130
+ * @property {StreakDTO} longest_day_streak
131
+ * @property {StreakDTO} longest_week_streak
132
+ * @property {number} total_practice_time
133
+ * @property {number} comment_likes
134
+ * @property {number} forum_post_likes
135
+ * @property {number} experience_points
136
+ */