musora-content-services 1.0.150 → 1.0.152

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 (53) hide show
  1. package/.github/workflows/node.js.yml +0 -0
  2. package/CHANGELOG.md +4 -0
  3. package/README.md +0 -0
  4. package/babel.config.js +0 -0
  5. package/docs/config.js.html +2 -2
  6. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  7. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  8. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  9. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  10. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  11. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  12. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  13. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  14. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  15. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
  16. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  17. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  18. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  19. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  20. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
  21. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  22. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  23. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  24. package/docs/index.html +2 -2
  25. package/docs/module-Config.html +2 -2
  26. package/docs/module-Railcontent-Services.html +567 -13
  27. package/docs/module-Sanity-Services.html +2 -2
  28. package/docs/railcontent.js.html +68 -3
  29. package/docs/sanity.js.html +2 -2
  30. package/docs/scripts/collapse.js +0 -0
  31. package/docs/scripts/commonNav.js +0 -0
  32. package/docs/scripts/linenumber.js +0 -0
  33. package/docs/scripts/nav.js +0 -0
  34. package/docs/scripts/polyfill.js +0 -0
  35. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -0
  36. package/docs/scripts/prettify/lang-css.js +0 -0
  37. package/docs/scripts/prettify/prettify.js +0 -0
  38. package/docs/scripts/search.js +0 -0
  39. package/docs/styles/jsdoc.css +0 -0
  40. package/docs/styles/prettify.css +0 -0
  41. package/jest.config.js +0 -0
  42. package/jsdoc.json +0 -0
  43. package/link_mcs.sh +0 -0
  44. package/package.json +1 -1
  45. package/src/contentMetaData.js +0 -0
  46. package/src/filterBuilder.js +0 -0
  47. package/src/index.d.ts +8 -0
  48. package/src/index.js +8 -0
  49. package/src/services/config.js +0 -0
  50. package/src/services/railcontent.js +163 -6
  51. package/test/localStorageMock.js +0 -0
  52. package/test/log.js +0 -0
  53. package/tools/generate-index.js +0 -0
@@ -320,56 +320,145 @@ export async function postRecordWatchSession({
320
320
  });
321
321
  }
322
322
 
323
+ /**
324
+ * Fetch enrolled user data for a given challenge. Intended to be used in the enrolled modal
325
+ *
326
+ * @param contentId - railcontent id of the challenge
327
+ * @returns {Promise<any|null>}
328
+ */
323
329
  export async function fetchChallengeMetadata(contentId) {
324
330
  let url = `/challenges/${contentId}`;
325
331
  return await fetchHandler(url, 'get');
326
332
  }
327
333
 
334
+ /**
335
+ * Fetch lesson, user, and challenge data for a given lesson
336
+ *
337
+ * @param contentId - railcontent id of the lesson
338
+ * @returns {Promise<any|null>}
339
+ */
328
340
  export async function fetchChallengeLessonData(contentId) {
329
341
  let url = `/challenges/lessons/${contentId}`;
330
342
  return await fetchHandler(url, 'get');
331
343
  }
332
344
 
345
+ /**
346
+ * Fetch challenge, lesson, and user metadata for a given challenge
347
+ *
348
+ * @param contentId - railcontent id of the challenge
349
+ * @returns {Promise<any|null>}
350
+ */
333
351
  export async function fetchUserChallengeProgress(contentId) {
334
352
  let url = `/challenges/user_data/${contentId}`;
335
353
  return await fetchHandler(url, 'get');
336
354
  }
337
355
 
356
+ /**
357
+ * Fetch the user's best award for this challenge
358
+ *
359
+ * @param contentId - railcontent id of the challenge
360
+ * @returns {Promise<any|null>} - streamed PDF
361
+ */
338
362
  export async function fetchUserAward(contentId) {
339
363
  let url = `/challenges/download_award/${contentId}`;
340
364
  return await fetchHandler(url, 'get');
341
365
  }
342
366
 
367
+ /**
368
+ * Get challange duration, user progress, and status for the list of challenges
369
+ * Intended to be used on the index page for challenges
370
+ *
371
+ * @param {array} contentIds - arary of railcontent ids of the challenges
372
+ * @returns {Promise<any|null>}
373
+ */
374
+ export async function fetchChallengeIndexMetadata(contentIds) {
375
+ let idsString = contentIds.toString();
376
+ let url = `/challenges/user_progress_for_index_page/get?content_ids=${idsString}`;
377
+ return await fetchHandler(url, 'get');
378
+ }
379
+
380
+ /**
381
+ * Enroll a user in a challenge and set the start date of the challenge to the provided day.
382
+ * Clears any existing progress data for this challenge
383
+ *
384
+ * @param {int|string} contentId - railcontent id of the challenge
385
+ * @param {string} startDate - prefered format YYYYMMDD, but any Carbon parsable string will do.
386
+ * @returns {Promise<any|null>}
387
+ */
343
388
  export async function postChallengesSetStartDate(contentId, startDate) {
344
389
  let url = `/challenges/set_start_date/${contentId}?start_date=${startDate}`;
345
390
  return await fetchHandler(url, 'post');
346
391
  }
347
392
 
393
+ /**
394
+ * Enroll the user in the provided challenge and set to unlocked
395
+ * Clears any current progress data for this challenge
396
+ *
397
+ * @param {int|string} contentId - railcontent id of the challenge
398
+ * @returns {Promise<any|null>}
399
+ */
348
400
  export async function postChallengesUnlock(contentId) {
349
401
  let url = `/challenges/unlock/${contentId}`;
350
402
  return await fetchHandler(url, 'post');
351
403
  }
352
404
 
405
+ /**
406
+ * Enroll the user in the given challenge on the challenge published_on date
407
+ * Clears any current progress data for this challenge
408
+ *
409
+ * @param {int|string} contentId - railcontent id of the challenge
410
+ * @returns {Promise<any|null>}
411
+ */
353
412
  export async function postChallengesEnroll(contentId) {
354
413
  let url = `/challenges/enroll/${contentId}`;
355
414
  return await fetchHandler(url, 'post');
356
415
  }
357
416
 
417
+ /**
418
+ * Remove the user from the provided challenge
419
+ * Clears any current progress data for this challenge
420
+ *
421
+ * @param {int|string} contentId - railcontent id of the challenge
422
+ * @returns {Promise<any|null>}
423
+ */
358
424
  export async function postChallengesLeave(contentId) {
359
425
  let url = `/challenges/leave/${contentId}`;
360
426
  return await fetchHandler(url, 'post');
361
427
  }
362
428
 
429
+ /**
430
+ * Enable enrollment notifications for the provided challenge
431
+ *
432
+ * @param {int|string} contentId - railcontent id of the challenge
433
+ * @returns {Promise<any|null>}
434
+ */
363
435
  export async function postChallengesEnrollmentNotification(contentId) {
364
436
  let url = `/challenges/notifications/enrollment_open/${contentId}`;
365
437
  return await fetchHandler(url, 'post');
366
438
  }
367
439
 
440
+ /**
441
+ * Enable community notifications for the provided challenge
442
+ *
443
+ * @param {int|string} contentId - railcontent id of the challenge
444
+ * @returns {Promise<any|null>}
445
+ */
368
446
  export async function postChallengesCommunityNotification(contentId) {
369
447
  let url = `/challenges/notifications/community_reminders/${contentId}`;
370
448
  return await fetchHandler(url, 'post');
371
449
  }
372
450
 
451
+ /**
452
+ * Complete the challenge lesson and update challenge progress
453
+ *
454
+ * @param {int|string} contentId - railcontent id of the challenge
455
+ * @returns {Promise<any|null>} - Modal data to display
456
+ */
457
+ export async function postCompleteLesson(contentId) {
458
+ let url = `/challenges/complete_lesson/${contentId}`;
459
+ return await fetchHandler(url, 'post');
460
+ }
461
+
373
462
  /**
374
463
  * Fetches user playlists for a specific brand.
375
464
  *
@@ -455,9 +544,8 @@ export async function duplicatePlaylist(playlistId, playlistData) {
455
544
  * .catch(error => console.error('Error deleting playlist:', error));
456
545
  */
457
546
  export async function deletePlaylist(playlistId) {
458
- let url = `/playlists/playlist`;
459
- const payload = { playlist_id: playlistId };
460
- return await fetchHandler(url, "delete", null, payload);
547
+ let url = `/playlists/playlist/${playlistId}`;
548
+ return await fetchHandler(url, "delete");
461
549
  }
462
550
 
463
551
  /**
@@ -603,7 +691,7 @@ export async function deletePlaylistLike(playlistId) {
603
691
  * .catch(error => console.error('Error fetching playlist:', error));
604
692
  */
605
693
  export async function fetchPlaylist(playlistId) {
606
- const url = `/playlists/playlist?playlist_id=${playlistId}`;
694
+ const url = `/playlists/playlist/${playlistId}`;
607
695
  return await fetchHandler(url, "GET");
608
696
  }
609
697
 
@@ -635,6 +723,7 @@ export async function fetchPlaylistItems(playlistId) {
635
723
  * @param {number} [updatedData.start_second] - (Optional) The start time in seconds for the item.
636
724
  * @param {number} [updatedData.end_second] - (Optional) The end time in seconds for the item.
637
725
  * @param {string} [updatedData.playlist_item_name] - (Optional) The new name for the playlist item.
726
+ * @param {number} [updatedData.position] - (Optional) The new position for the playlist item within the playlist.
638
727
  * @returns {Promise<Object|null>} - A promise that resolves to an object containing:
639
728
  * - `success` (boolean): Indicates if the update was successful (`true` for success).
640
729
  * - `data` (Object): The updated playlist item data.
@@ -647,7 +736,8 @@ export async function fetchPlaylistItems(playlistId) {
647
736
  * user_playlist_item_id: 123,
648
737
  * start_second: 30,
649
738
  * end_second: 120,
650
- * playlist_item_name: "Updated Playlist Item Name"
739
+ * playlist_item_name: "Updated Playlist Item Name",
740
+ * position: 2
651
741
  * };
652
742
  *
653
743
  * updatePlaylistItem(updatedData)
@@ -665,6 +755,74 @@ export async function updatePlaylistItem(updatedData) {
665
755
  return await fetchHandler(url, "POST", null, updatedData);
666
756
  }
667
757
 
758
+ /**
759
+ * Deletes a playlist item and repositions other items in the playlist if necessary.
760
+ *
761
+ * @param {Object} payload - The data required to delete the playlist item.
762
+ * @param {number} payload.user_playlist_item_id - The ID of the playlist item to delete.
763
+ * @returns {Promise<Object|null>} - A promise that resolves to an object containing:
764
+ * - `success` (boolean): Indicates if the deletion was successful (`true` for success).
765
+ * - `message` (string): A success message if the item is deleted successfully.
766
+ * - `error` (string): An error message if the deletion fails.
767
+ *
768
+ * Resolves to `null` if the request fails.
769
+ * @throws {Error} - Throws an error if the request fails.
770
+ *
771
+ * @example
772
+ * const payload = {
773
+ * user_playlist_item_id: 123
774
+ * };
775
+ *
776
+ * deletePlaylistItem(payload)
777
+ * .then(response => {
778
+ * if (response.success) {
779
+ * console.log("Playlist item deleted successfully:", response.message);
780
+ * } else {
781
+ * console.error("Error:", response.error);
782
+ * }
783
+ * })
784
+ * .catch(error => {
785
+ * console.error("Error deleting playlist item:", error);
786
+ * });
787
+ */
788
+ export async function deletePlaylistItem(payload) {
789
+ const url = `/playlists/item`;
790
+ return await fetchHandler(url, "DELETE", null, payload);
791
+ }
792
+
793
+ /**
794
+ * Fetches detailed data for a specific playlist item, including associated Sanity and Assignment information if available.
795
+ *
796
+ * @param {Object} payload - The request payload containing necessary parameters.
797
+ * @param {number} payload.user_playlist_item_id - The unique ID of the playlist item to fetch.
798
+ * @returns {Promise<Object|null>} - A promise that resolves to an object with the fetched playlist item data, including:
799
+ * - `success` (boolean): Indicates if the data retrieval was successful (`true` on success).
800
+ * - `data` (Object): Contains the detailed playlist item data enriched with Sanity and Assignment details, if available.
801
+ *
802
+ * Resolves to `null` if the request fails.
803
+ * @throws {Error} - Throws an error if the request encounters issues during retrieval.
804
+ *
805
+ * @example
806
+ * const payload = { user_playlist_item_id: 123 };
807
+ *
808
+ * fetchPlaylistItem(payload)
809
+ * .then(response => {
810
+ * if (response?.success) {
811
+ * console.log("Fetched playlist item data:", response.data);
812
+ * } else {
813
+ * console.log("Failed to fetch playlist item data.");
814
+ * }
815
+ * })
816
+ * .catch(error => {
817
+ * console.error("Error fetching playlist item:", error);
818
+ * });
819
+ */
820
+ export async function fetchPlaylistItem(payload) {
821
+ const playlistItemId = payload.user_playlist_item_id;
822
+ const url = `/playlists/item/${playlistItemId}`;
823
+ return await fetchHandler(url);
824
+ }
825
+
668
826
  export async function postContentStarted(contentId) {
669
827
  let url = `/content/${contentId}/started`;
670
828
  return postDataHandler(url);
@@ -681,7 +839,6 @@ export async function postContentReset(contentId) {
681
839
  }
682
840
 
683
841
 
684
-
685
842
  function fetchAbsolute(url, params) {
686
843
  if (globalConfig.railcontentConfig.baseUrl) {
687
844
  if (url.startsWith('/')) {
File without changes
package/test/log.js CHANGED
File without changes
File without changes