musora-content-services 2.0.2 → 2.0.6

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 (77) hide show
  1. package/.github/workflows/node.js.yml +0 -0
  2. package/.prettierignore +0 -0
  3. package/.prettierrc +0 -0
  4. package/CHANGELOG.md +8 -0
  5. package/README.md +0 -0
  6. package/babel.config.cjs +0 -0
  7. package/docs/Content-Organization.html +245 -0
  8. package/docs/Playlists.html +192 -0
  9. package/docs/config.js.html +2 -2
  10. package/docs/content-org_playlists-types.js.html +109 -0
  11. package/docs/content-org_playlists.js.html +194 -0
  12. package/docs/content-org_types.js.html +112 -0
  13. package/docs/content.js.html +22 -4
  14. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  15. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  16. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  17. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  18. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  19. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  20. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  21. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  22. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  23. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
  24. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  25. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  26. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  27. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  28. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
  29. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  30. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  31. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  32. package/docs/global.html +854 -2
  33. package/docs/index.html +2 -2
  34. package/docs/module-Config.html +2 -2
  35. package/docs/module-Content-Organization-Playlists.html +194 -0
  36. package/docs/module-Content-Organization.html +976 -0
  37. package/docs/module-Content-Services-V2.html +3 -3
  38. package/docs/module-Playlists.html +969 -0
  39. package/docs/module-Railcontent-Services.html +2074 -1533
  40. package/docs/module-Sanity-Services.html +14 -14
  41. package/docs/module-Session-Management.html +2 -2
  42. package/docs/module-User-Permissions.html +2 -2
  43. package/docs/module-playlists.html +1878 -0
  44. package/docs/module-playlists_.html +108 -0
  45. package/docs/railcontent.js.html +122 -122
  46. package/docs/sanity.js.html +9 -8
  47. package/docs/scripts/collapse.js +0 -0
  48. package/docs/scripts/commonNav.js +0 -0
  49. package/docs/scripts/linenumber.js +0 -0
  50. package/docs/scripts/nav.js +0 -0
  51. package/docs/scripts/polyfill.js +0 -0
  52. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -0
  53. package/docs/scripts/prettify/lang-css.js +0 -0
  54. package/docs/scripts/prettify/prettify.js +0 -0
  55. package/docs/scripts/search.js +0 -0
  56. package/docs/styles/jsdoc.css +0 -0
  57. package/docs/styles/prettify.css +0 -0
  58. package/docs/user_permissions.js.html +2 -2
  59. package/docs/user_sessions.js.html +2 -2
  60. package/docs/user_types.js.html +2 -2
  61. package/jest.config.js +0 -0
  62. package/jsdoc.json +1 -0
  63. package/package.json +1 -1
  64. package/src/index.d.ts +6 -3
  65. package/src/index.js +6 -3
  66. package/src/services/config.js +0 -0
  67. package/src/services/content-org/playlists-types.js +37 -0
  68. package/src/services/content-org/playlists.js +122 -0
  69. package/src/services/contentLikes.js +0 -0
  70. package/src/services/contentProgress.js +0 -0
  71. package/src/services/dataContext.js +0 -0
  72. package/src/services/railcontent.js +8 -121
  73. package/test/contentLikes.test.js +0 -0
  74. package/test/live/contentProgressLive.test.js +0 -0
  75. package/test/live/railcontentLive.test.js +0 -0
  76. package/test/localStorageMock.js +0 -0
  77. package/test/log.js +0 -0
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @namespace Content-Organization
3
+ * @property {module:Playlists} Playlists
4
+ */
5
+ /**
6
+ * @module Playlists
7
+ */
8
+ import { fetchHandler } from '../railcontent'
9
+ import { globalConfig } from '../config'
10
+ import './playlists-types'
11
+
12
+ /**
13
+ * Exported functions that are excluded from index generation.
14
+ *
15
+ * @type {string[]}
16
+ */
17
+ const excludeFromGeneratedIndex = []
18
+
19
+ const BASE_URL = `${globalConfig.railcontentConfig.baseUrl}/api/content-org`
20
+
21
+ /**
22
+ * Fetches user playlists for a specific brand.
23
+ *
24
+ * Allows optional pagination, sorting, and search parameters to control the result set.
25
+ *
26
+ * @param {string} brand - The brand identifier for which playlists are being fetched.
27
+ * @param {number} [params.limit=10] - The maximum number of playlists to return per page (default is 10).
28
+ * @param {number} [params.page=1] - The page number for pagination.
29
+ * @param {string} [params.sort='-created_at'] - The sorting order for the playlists (default is by created_at in descending order).
30
+ * @param {string} [params.searchTerm] - A search term to filter playlists by name.
31
+ * @param {int|string} [params.content_id] - If content_id exists, the endpoint checks in each playlist if we have the content in the items.
32
+ *
33
+ * @returns {Promise<Object|null>} - A promise that resolves to the response from the API, containing the user playlists data.
34
+ *
35
+ * @example
36
+ * fetchUserPlaylists('drumeo', { page: 1, sort: 'name', searchTerm: 'rock' })
37
+ * .then(playlists => console.log(playlists))
38
+ * .catch(error => console.error(error));
39
+ */
40
+ export async function fetchUserPlaylists(
41
+ brand,
42
+ { page, limit, sort, searchTerm, content_id, categories } = {}
43
+ ) {
44
+ let url
45
+ const limitString = limit ? `&limit=${limit}` : ''
46
+ const pageString = page ? `&page=${page}` : ''
47
+ const sortString = sort ? `&sort=${sort}` : ''
48
+ const searchFilter = searchTerm ? `&term=${searchTerm}` : ''
49
+ const content = content_id ? `&content_id=${content_id}` : ''
50
+ const categoryString =
51
+ categories && categories.length ? categories.map((cat) => `categories[]=${cat}`).join('&') : ''
52
+ url = `${BASE_URL}/v1/user/playlists?brand=${brand}${limitString}${pageString}${sortString}${searchFilter}${content}${categoryString ? `&${categoryString}` : ''}`
53
+ return await fetchHandler(url)
54
+ }
55
+
56
+ /**
57
+ * Creates a new user playlist by sending a POST request with playlist data to the API.
58
+ *
59
+ * This function calls the `/playlists/playlist` endpoint, where the server validates the incoming data and associates
60
+ * the new playlist with the authenticated user. The `name` field is required, while other fields are optional.
61
+ *
62
+ * @param {CreatePlaylistDTO} playlistData - An object containing data to create the playlist. The fields include:
63
+ * - `name` (string): The name of the new playlist (required, max 255 characters).
64
+ * - `description` (string): A description of the playlist (optional, max 1000 characters).
65
+ * - `category` (string): The category of the playlist.
66
+ * - `thumbnail_url` (string): The URL of the playlist thumbnail (optional, must be a valid URL).
67
+ * - `private` (boolean): Whether the playlist is private (optional, defaults to true).
68
+ * - `brand` (string): Brand identifier for the playlist.
69
+ *
70
+ * @returns {Promise<Playlist>} - A promise that resolves to the created playlist data if successful, or an error response if validation fails.
71
+ *
72
+ * The server response includes:
73
+ * - `message`: Success message indicating playlist creation (e.g., "Playlist created successfully").
74
+ * - `playlist`: The data for the created playlist, including the `user_id` of the authenticated user.
75
+ *
76
+ * @example
77
+ * createPlaylist({ name: "My Playlist", description: "A cool playlist", private: true })
78
+ * .then(response => console.log(response.message))
79
+ * .catch(error => console.error('Error creating playlist:', error));
80
+ */
81
+ export async function createPlaylist(playlistData) {
82
+ const url = `${BASE_URL}/v1/user/playlists`
83
+ return await fetchHandler(url, 'POST', null, playlistData)
84
+ }
85
+
86
+ /**
87
+ * Adds an item to one or more playlists by making a POST request to the `/playlists/add-item` endpoint.
88
+ *
89
+ * @param {AddItemToPlaylistDTO} payload - The request payload containing necessary parameters.
90
+ *
91
+ * @returns {Promise<Object|null>} - A promise that resolves to an object with the response data, including:
92
+ * - `success` (boolean): Indicates if the items were added successfully (`true` on success).
93
+ * - `limit_excedeed` (Array): A list of playlists where the item limit was exceeded, if any.
94
+ * - `successful` (Array): A list of successfully added items (empty if none).
95
+ *
96
+ * Resolves to `null` if the request fails.
97
+ * @throws {Error} - Throws an error if the request encounters issues during the operation.
98
+ *
99
+ * @example
100
+ * const payload = {
101
+ * content_id: 123,
102
+ * playlist_id: [1, 2, 3],
103
+ * import_all_assignments: true
104
+ * };
105
+ *
106
+ * addItemToPlaylist(payload)
107
+ * .then(response => {
108
+ * if (response?.success) {
109
+ * console.log("Item(s) added to playlist successfully");
110
+ * }
111
+ * if (response?.limit_excedeed) {
112
+ * console.warn("Some playlists exceeded the item limit:", response.limit_excedeed);
113
+ * }
114
+ * })
115
+ * .catch(error => {
116
+ * console.error("Error adding item to playlist:", error);
117
+ * });
118
+ */
119
+ export async function addItemToPlaylist(payload) {
120
+ const url = `${BASE_URL}/v1/user/playlists/items`
121
+ return await fetchHandler(url, 'POST', null, payload)
122
+ }
File without changes
File without changes
File without changes
@@ -294,6 +294,7 @@ async function deleteDataHandler(url, data) {
294
294
  return fetchHandler(url, 'delete')
295
295
  }
296
296
 
297
+ // TODO: this should be extracted to a utility file
297
298
  export async function fetchHandler(url, method = 'get', dataVersion = null, body = null) {
298
299
  let headers = {
299
300
  'Content-Type': 'application/json',
@@ -618,41 +619,6 @@ export async function postChallengesHideCompletedBanner(contentId) {
618
619
  return await fetchHandler(url, 'post')
619
620
  }
620
621
 
621
- /**
622
- * Fetches user playlists for a specific brand.
623
- *
624
- * Allows optional pagination, sorting, and search parameters to control the result set.
625
- *
626
- * @param {string} brand - The brand identifier for which playlists are being fetched.
627
- * @param {number} [params.limit=10] - The maximum number of playlists to return per page (default is 10).
628
- * @param {number} [params.page=1] - The page number for pagination.
629
- * @param {string} [params.sort='-created_at'] - The sorting order for the playlists (default is by created_at in descending order).
630
- * @param {string} [params.searchTerm] - A search term to filter playlists by name.
631
- * @param {int|string} [params.content_id] - If content_id exists, the endpoint checks in each playlist if we have the content in the items.
632
- *
633
- * @returns {Promise<Object|null>} - A promise that resolves to the response from the API, containing the user playlists data.
634
- *
635
- * @example
636
- * fetchUserPlaylists('drumeo', { page: 1, sort: 'name', searchTerm: 'rock' })
637
- * .then(playlists => console.log(playlists))
638
- * .catch(error => console.error(error));
639
- */
640
- export async function fetchUserPlaylists(
641
- brand,
642
- { page, limit, sort, searchTerm, content_id, categories } = {}
643
- ) {
644
- let url
645
- const limitString = limit ? `&limit=${limit}` : ''
646
- const pageString = page ? `&page=${page}` : ''
647
- const sortString = sort ? `&sort=${sort}` : ''
648
- const searchFilter = searchTerm ? `&term=${searchTerm}` : ''
649
- const content = content_id ? `&content_id=${content_id}` : ''
650
- const categoryString =
651
- categories && categories.length ? categories.map((cat) => `categories[]=${cat}`).join('&') : ''
652
- url = `/api/content/v1/user/playlists/all?brand=${brand}${limitString}${pageString}${sortString}${searchFilter}${content}${categoryString ? `&${categoryString}` : ''}`
653
- return await fetchHandler(url)
654
- }
655
-
656
622
  /**
657
623
  * Duplicates an existing playlist by sending a POST request to the API.
658
624
  *
@@ -749,36 +715,6 @@ export async function updatePlaylist(playlistId, updatedData) {
749
715
  return await fetchHandler(url, 'PUT', null, updatedData)
750
716
  }
751
717
 
752
- /**
753
- * Creates a new user playlist by sending a POST request with playlist data to the API.
754
- *
755
- * This function calls the `/playlists/playlist` endpoint, where the server validates the incoming data and associates
756
- * the new playlist with the authenticated user. The `name` field is required, while other fields are optional.
757
- *
758
- * @param {Object} playlistData - An object containing data to create the playlist. The fields include:
759
- * - `name` (string): The name of the new playlist (required, max 255 characters).
760
- * - `description` (string): A description of the playlist (optional, max 1000 characters).
761
- * - `category` (string): The category of the playlist.
762
- * - `thumbnail_url` (string): The URL of the playlist thumbnail (optional, must be a valid URL).
763
- * - `private` (boolean): Whether the playlist is private (optional, defaults to true).
764
- * - `brand` (string): Brand identifier for the playlist.
765
- *
766
- * @returns {Promise<Object>} - A promise that resolves to the created playlist data if successful, or an error response if validation fails.
767
- *
768
- * The server response includes:
769
- * - `message`: Success message indicating playlist creation (e.g., "Playlist created successfully").
770
- * - `playlist`: The data for the created playlist, including the `user_id` of the authenticated user.
771
- *
772
- * @example
773
- * createPlaylist({ name: "My Playlist", description: "A cool playlist", private: true })
774
- * .then(response => console.log(response.message))
775
- * .catch(error => console.error('Error creating playlist:', error));
776
- */
777
- export async function createPlaylist(playlistData) {
778
- const url = `/api/content/v1/user/playlists/playlist`
779
- return await fetchHandler(url, 'POST', null, playlistData)
780
- }
781
-
782
718
  /**
783
719
  * Sends a request to "like" a playlist on behalf of the authenticated user.
784
720
  *
@@ -1000,51 +936,6 @@ export async function postContentReset(contentId) {
1000
936
  return postDataHandler(url, { contentId: contentId })
1001
937
  }
1002
938
 
1003
- /**
1004
- * Adds an item to one or more playlists by making a POST request to the `/playlists/add-item` endpoint.
1005
- *
1006
- * @param {Object} payload - The request payload containing necessary parameters.
1007
- * @param {number} payload.content_id - The ID of the content to add to the playlist(s).
1008
- * @param {Array<number>} payload.playlist_id - An array of playlist IDs where the content should be added.
1009
- * @param {boolean} [payload.import_full_soundslice_assignment=false] - Flag to include full Soundslice assignments.
1010
- * @param {boolean} [payload.import_instrumentless_soundslice_assignment=false] - Flag to include instrumentless Soundslice assignments.
1011
- * @param {boolean} [payload.import_high_routine=false] - Flag to include high routine content.
1012
- * @param {boolean} [payload.import_low_routine=false] - Flag to include low routine content.
1013
- * @param {boolean} [payload.import_all_assignments=false] - Flag to include all Soundslice assignments if true.
1014
- *
1015
- * @returns {Promise<Object|null>} - A promise that resolves to an object with the response data, including:
1016
- * - `success` (boolean): Indicates if the items were added successfully (`true` on success).
1017
- * - `limit_excedeed` (Array): A list of playlists where the item limit was exceeded, if any.
1018
- * - `successful` (Array): A list of successfully added items (empty if none).
1019
- *
1020
- * Resolves to `null` if the request fails.
1021
- * @throws {Error} - Throws an error if the request encounters issues during the operation.
1022
- *
1023
- * @example
1024
- * const payload = {
1025
- * content_id: 123,
1026
- * playlist_id: [1, 2, 3],
1027
- * import_all_assignments: true
1028
- * };
1029
- *
1030
- * addItemToPlaylist(payload)
1031
- * .then(response => {
1032
- * if (response?.success) {
1033
- * console.log("Item(s) added to playlist successfully");
1034
- * }
1035
- * if (response?.limit_excedeed) {
1036
- * console.warn("Some playlists exceeded the item limit:", response.limit_excedeed);
1037
- * }
1038
- * })
1039
- * .catch(error => {
1040
- * console.error("Error adding item to playlist:", error);
1041
- * });
1042
- */
1043
- export async function addItemToPlaylist(payload) {
1044
- const url = `/api/content/v1/user/playlists/add-item`
1045
- return await fetchHandler(url, 'POST', null, payload)
1046
- }
1047
-
1048
939
  /**
1049
940
  * Retrieves the count of lessons and assignments associated with a specific content ID.
1050
941
  *
@@ -1202,7 +1093,6 @@ export async function setStudentViewForUser(userId, enable) {
1202
1093
  return await patchDataHandler(url, data)
1203
1094
  }
1204
1095
 
1205
-
1206
1096
  /**
1207
1097
  * Fetch the top comment for a given content
1208
1098
  *
@@ -1214,7 +1104,6 @@ export async function fetchTopComment(railcontentId) {
1214
1104
  return await fetchHandler(url)
1215
1105
  }
1216
1106
 
1217
-
1218
1107
  /**
1219
1108
  *
1220
1109
  * @param {int} railcontentId
@@ -1245,7 +1134,7 @@ export async function fetchCommentRelies(commentId, page = 1, limit = 20) {
1245
1134
  */
1246
1135
  export async function deleteComment(commentId) {
1247
1136
  const url = `/api/content/v1/comments/${commentId}`
1248
- return await fetchHandler(url, "DELETE")
1137
+ return await fetchHandler(url, 'DELETE')
1249
1138
  }
1250
1139
 
1251
1140
  /**
@@ -1254,7 +1143,7 @@ export async function deleteComment(commentId) {
1254
1143
  * @returns {Promise<*|null>}
1255
1144
  */
1256
1145
  export async function replyToComment(commentId, comment) {
1257
- const data = {'comment' : comment}
1146
+ const data = { comment: comment }
1258
1147
  const url = `/api/content/v1/comments/${commentId}/reply`
1259
1148
  return await postDataHandler(url, data)
1260
1149
  }
@@ -1266,8 +1155,8 @@ export async function replyToComment(commentId, comment) {
1266
1155
  */
1267
1156
  export async function createComment(railcontentId, comment) {
1268
1157
  const data = {
1269
- 'comment' : comment,
1270
- 'content_id' : railcontentId
1158
+ comment: comment,
1159
+ content_id: railcontentId,
1271
1160
  }
1272
1161
  const url = `/api/content/v1/comments/store`
1273
1162
  return await postDataHandler(url, data)
@@ -1316,7 +1205,7 @@ export async function unlikeComment(commentId) {
1316
1205
  export async function closeComment(commentId) {
1317
1206
  const url = `/api/content/v1/comments/${commentId}`
1318
1207
  const data = {
1319
- 'conversation_status' : 'closed'
1208
+ conversation_status: 'closed',
1320
1209
  }
1321
1210
  return await patchDataHandler(url, data)
1322
1211
  }
@@ -1328,7 +1217,7 @@ export async function closeComment(commentId) {
1328
1217
  export async function openComment(commentId) {
1329
1218
  const url = `/api/content/v1/comments/${commentId}`
1330
1219
  const data = {
1331
- 'conversation_status' : 'open'
1220
+ conversation_status: 'open',
1332
1221
  }
1333
1222
  return await patchDataHandler(url, data)
1334
1223
  }
@@ -1341,13 +1230,11 @@ export async function openComment(commentId) {
1341
1230
  export async function editComment(commentId, comment) {
1342
1231
  const url = `/api/content/v1/comments/${commentId}`
1343
1232
  const data = {
1344
- 'comment' : comment
1233
+ comment: comment,
1345
1234
  }
1346
1235
  return await patchDataHandler(url, data)
1347
1236
  }
1348
1237
 
1349
-
1350
-
1351
1238
  function fetchAbsolute(url, params) {
1352
1239
  if (globalConfig.railcontentConfig.authToken) {
1353
1240
  params.headers['Authorization'] = `Bearer ${globalConfig.railcontentConfig.authToken}`
File without changes
File without changes
File without changes
File without changes
package/test/log.js CHANGED
File without changes