musora-content-services 1.0.155 → 1.0.156

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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.156](https://github.com/railroadmedia/musora-content-services/compare/v1.0.155...v1.0.156) (2024-11-06)
6
+
5
7
  ### [1.0.155](https://github.com/railroadmedia/musora-content-services/compare/v1.0.154...v1.0.155) (2024-11-05)
6
8
 
7
9
  ### [1.0.154](https://github.com/railroadmedia/musora-content-services/compare/v1.0.153...v1.0.154) (2024-11-05)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.155",
3
+ "version": "1.0.156",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.d.ts CHANGED
@@ -43,6 +43,7 @@ import {
43
43
  fetchPlaylistItems,
44
44
  fetchSongsInProgress,
45
45
  fetchUserAward,
46
+ fetchUserBadges,
46
47
  fetchUserChallengeProgress,
47
48
  fetchUserLikes,
48
49
  fetchUserPermissions,
@@ -183,6 +184,7 @@ declare module 'musora-content-services' {
183
184
  fetchTopLevelParentId,
184
185
  fetchUpcomingEvents,
185
186
  fetchUserAward,
187
+ fetchUserBadges,
186
188
  fetchUserChallengeProgress,
187
189
  fetchUserLikes,
188
190
  fetchUserPermissions,
package/src/index.js CHANGED
@@ -43,6 +43,7 @@ import {
43
43
  fetchPlaylistItems,
44
44
  fetchSongsInProgress,
45
45
  fetchUserAward,
46
+ fetchUserBadges,
46
47
  fetchUserChallengeProgress,
47
48
  fetchUserLikes,
48
49
  fetchUserPermissions,
@@ -182,6 +183,7 @@ export {
182
183
  fetchTopLevelParentId,
183
184
  fetchUpcomingEvents,
184
185
  fetchUserAward,
186
+ fetchUserBadges,
185
187
  fetchUserChallengeProgress,
186
188
  fetchUserLikes,
187
189
  fetchUserPermissions,
@@ -75,9 +75,9 @@ function completeStatusInLocalContext(contentId, localContext, hierarchy) {
75
75
  export async function contentStatusReset(contentId) {
76
76
  await dataContext.update(
77
77
  function (localContext) {
78
- const index = localContext.data.indexOf(contentId);
78
+ const index = Object.keys(localContext.data).indexOf(contentId);
79
79
  if (index > -1) { // only splice array when item is found
80
- localContext.data.splice(index, 1); // 2nd parameter means remove one item only
80
+ delete localContext.data[contentId];
81
81
  }
82
82
  },
83
83
  async function () {
@@ -34,7 +34,7 @@ export class DataContext {
34
34
  this.context = data;
35
35
  cache.setItem(this.localStorageKey, JSON.stringify(data));
36
36
  }
37
- cache.setItem(this.localStorageLastUpdatedKey, new Date().getTime());
37
+ cache.setItem(this.localStorageLastUpdatedKey, new Date().getTime()?.toString());
38
38
  }
39
39
  return this.context.data;
40
40
  }
@@ -83,10 +83,10 @@ export class DataContext {
83
83
  this.context.version++;
84
84
  let data = JSON.stringify(this.context);
85
85
  cache.setItem(this.localStorageKey, data);
86
- cache.setItem(this.localStorageLastUpdatedKey, new Date().getTime());
86
+ cache.setItem(this.localStorageLastUpdatedKey, new Date().getTime().toString());
87
87
  }
88
88
  let response = await serverUpdateFunction();
89
- if (response.version !== this.version()) {
89
+ if (response?.version !== this.version()) {
90
90
  this.clearCache();
91
91
  }
92
92
  }
@@ -265,11 +265,11 @@ export async function fetchHandler(url, method = "get", dataVersion = null, body
265
265
  }
266
266
  try {
267
267
  const response = await fetchAbsolute(url, options);
268
- const result = await response.json();
269
- if (result) {
270
- return result;
268
+ if (response.ok) {
269
+ return await response.json();
271
270
  } else {
272
- console.log('result not json');
271
+ console.log('fetch error:', response.status);
272
+ console.log(response);
273
273
  }
274
274
  } catch (error) {
275
275
  console.error('Fetch error:', error);
@@ -298,15 +298,15 @@ export async function fetchContentProgress(currentVersion) {
298
298
  }
299
299
 
300
300
  export async function postRecordWatchSession({
301
- mediaId,
302
- mediaType,
303
- mediaCategory,
304
- watchPosition,
305
- totalDuration,
306
- sessionToken,
307
- brand,
308
- contentId = null
309
- }) {
301
+ mediaId,
302
+ mediaType,
303
+ mediaCategory,
304
+ watchPosition,
305
+ totalDuration,
306
+ sessionToken,
307
+ brand,
308
+ contentId = null
309
+ }) {
310
310
  let url = `/railtracker/media-playback-session`;
311
311
  return postDataHandler(url, {
312
312
  mediaId,
@@ -365,7 +365,7 @@ export async function fetchUserAward(contentId) {
365
365
  }
366
366
 
367
367
  /**
368
- * Get challange duration, user progress, and status for the list of challenges
368
+ * Get challenge duration, user progress, and status for the list of challenges
369
369
  * Intended to be used on the index page for challenges
370
370
  *
371
371
  * @param {array} contentIds - arary of railcontent ids of the challenges
@@ -377,6 +377,18 @@ export async function fetchChallengeIndexMetadata(contentIds) {
377
377
  return await fetchHandler(url, 'get');
378
378
  }
379
379
 
380
+ /**
381
+ * Fetch all completed badges for the user ordered by completion date descending
382
+ *
383
+ * @param {string|null} brand -
384
+ * @returns {Promise<any|null>}
385
+ */
386
+ export async function fetchUserBadges(brand = null) {
387
+ let brandParam = brand ? `?brand=${brand}` : '';
388
+ let url = `/challenges/user_badges/get${brandParam}`;
389
+ return await fetchHandler(url, 'get');
390
+ }
391
+
380
392
  /**
381
393
  * Enroll a user in a challenge and set the start date of the challenge to the provided day.
382
394
  * Clears any existing progress data for this challenge
@@ -481,8 +493,8 @@ export async function fetchUserPlaylists(brand, {page, limit, sort, searchTerm}
481
493
  let url;
482
494
  const limitString = limit ? `&limit=${limit}` : '';
483
495
  const pageString = page ? `&page=${page}` : '';
484
- const sortString = sort ? `&sort=${sort}`:'';
485
- const searchFilter = searchTerm ? `&term=${searchTerm}`: '';
496
+ const sortString = sort ? `&sort=${sort}` : '';
497
+ const searchFilter = searchTerm ? `&term=${searchTerm}` : '';
486
498
  url = `/playlists/all?brand=${brand}${limitString}${pageString}${sortString}${searchFilter}`;
487
499
  return await fetchHandler(url);
488
500
  }
@@ -517,7 +529,7 @@ export async function fetchUserPlaylists(brand, {page, limit, sort, searchTerm}
517
529
  */
518
530
  export async function duplicatePlaylist(playlistId, playlistData) {
519
531
  let url = `/playlists/duplicate/${playlistId}`;
520
- return await fetchHandler(url, "post",null, playlistData);
532
+ return await fetchHandler(url, "post", null, playlistData);
521
533
  }
522
534
 
523
535
  /**
@@ -643,7 +655,7 @@ export async function createPlaylist(playlistData) {
643
655
  */
644
656
  export async function likePlaylist(playlistId) {
645
657
  const url = `/playlists/like`;
646
- const payload = { playlist_id: playlistId };
658
+ const payload = {playlist_id: playlistId};
647
659
  return await fetchHandler(url, "PUT", null, payload);
648
660
  }
649
661
 
@@ -670,7 +682,7 @@ export async function likePlaylist(playlistId) {
670
682
  */
671
683
  export async function deletePlaylistLike(playlistId) {
672
684
  const url = `/playlists/like`;
673
- const payload = { playlist_id: playlistId };
685
+ const payload = {playlist_id: playlistId};
674
686
  return await fetchHandler(url, "DELETE", null, payload);
675
687
  }
676
688