musora-content-services 2.3.17 → 2.3.18

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.
@@ -23,7 +23,6 @@ const BASE_PATH = `/api/content-org`
23
23
  * @param {number} [params.limit=10] - The maximum number of playlists to return per page (default is 10).
24
24
  * @param {number} [params.page=1] - The page number for pagination.
25
25
  * @param {string} [params.sort='-created_at'] - The sorting order for the playlists (default is by created_at in descending order).
26
- * @param {string} [params.searchTerm] - A search term to filter playlists by name.
27
26
  * @param {int|string} [params.content_id] - If content_id exists, the endpoint checks in each playlist if we have the content in the items.
28
27
  *
29
28
  * @returns {Promise<Object|null>} - A promise that resolves to the response from the API, containing the user playlists data.
@@ -35,18 +34,14 @@ const BASE_PATH = `/api/content-org`
35
34
  */
36
35
  export async function fetchUserPlaylists(
37
36
  brand,
38
- { page, limit, sort, searchTerm, content_id, categories } = {}
37
+ { page, limit, sort, content_id } = {}
39
38
  ) {
40
- let url
41
- console.log({ config: globalConfig.baseUrl })
39
+ const pageString = page ? `?page=${page}` : '?page=1'
42
40
  const limitString = limit ? `&limit=${limit}` : ''
43
- const pageString = page ? `&page=${page}` : ''
44
41
  const sortString = sort ? `&sort=${sort}` : ''
45
- const searchFilter = searchTerm ? `&term=${searchTerm}` : ''
46
42
  const content = content_id ? `&content_id=${content_id}` : ''
47
- const categoryString =
48
- categories && categories.length ? categories.map((cat) => `categories[]=${cat}`).join('&') : ''
49
- url = `${BASE_PATH}/v1/user/playlists?brand=${brand}${limitString}${pageString}${sortString}${searchFilter}${content}${categoryString ? `&${categoryString}` : ''}`
43
+ const brandString = brand ? `&brand=${brand}` : ''
44
+ const url = `${BASE_PATH}/v1/user/playlists${pageString}${brandString}${limitString}${sortString}${content}`
50
45
  return await fetchHandler(url)
51
46
  }
52
47
 
@@ -60,19 +55,14 @@ export async function fetchUserPlaylists(
60
55
  * - `name` (string): The name of the new playlist (required, max 255 characters).
61
56
  * - `description` (string): A description of the playlist (optional, max 1000 characters).
62
57
  * - `category` (string): The category of the playlist.
63
- * - `thumbnail_url` (string): The URL of the playlist thumbnail (optional, must be a valid URL).
64
- * - `private` (boolean): Whether the playlist is private (optional, defaults to true).
58
+ * - `private` (boolean): Whether the playlist is private (optional, defaults to false).
65
59
  * - `brand` (string): Brand identifier for the playlist.
66
60
  *
67
61
  * @returns {Promise<Playlist>} - A promise that resolves to the created playlist data if successful, or an error response if validation fails.
68
62
  *
69
- * The server response includes:
70
- * - `message`: Success message indicating playlist creation (e.g., "Playlist created successfully").
71
- * - `playlist`: The data for the created playlist, including the `user_id` of the authenticated user.
72
- *
73
63
  * @example
74
64
  * createPlaylist({ name: "My Playlist", description: "A cool playlist", private: true })
75
- * .then(response => console.log(response.message))
65
+ * .then(response => console.log(response))
76
66
  * .catch(error => console.error('Error creating playlist:', error));
77
67
  */
78
68
  export async function createPlaylist(playlistData) {
@@ -117,3 +107,366 @@ export async function addItemToPlaylist(payload) {
117
107
  const url = `${BASE_PATH}/v1/user/playlists/items`
118
108
  return await fetchHandler(url, 'POST', null, payload)
119
109
  }
110
+
111
+ /**
112
+ * Updates a playlist's privacy setting by toggling its public/private status.
113
+
114
+ *
115
+ * @async
116
+ * @function togglePlaylistPrivate
117
+ * @param {string|number} playlistId - The unique identifier of the playlist to update.
118
+ * @param {boolean} [is_private=true] - is public flag
119
+ *
120
+ * @returns {Promise<Object>}
121
+ *
122
+ * @example
123
+ * // Make playlist with ID '81111' public
124
+ * try {
125
+ * const response = await togglePublic(81111, true);
126
+ * console.log('Playlist is now private:', response);
127
+ * } catch (error) {
128
+ * console.error('Failed to update playlist visibility:', error);
129
+ * }
130
+ */
131
+ export async function togglePlaylistPrivate(playlistId, is_private = true) {
132
+ const url = `${BASE_PATH}/v1/user/playlists/update/${playlistId}`
133
+ const payload = {
134
+ private: is_private,
135
+ }
136
+ return await fetchHandler(url, 'POST', null, payload)
137
+ }
138
+
139
+ /**
140
+ * Likes a playlist for the current user.
141
+ *
142
+ * @async
143
+ * @function likePlaylist
144
+ * @param {string|number} playlistId - The unique identifier of the playlist to like.
145
+ *
146
+ * @returns {Promise<Object>}
147
+ *
148
+ * @example
149
+ * // Like playlist with ID '123'
150
+ * try {
151
+ * const response = await likePlaylist('123');
152
+ * console.log('Playlist liked successfully:', response);
153
+ * } catch (error) {
154
+ * console.error('Failed to like playlist:', error);
155
+ * }
156
+ */
157
+ export async function likePlaylist(playlistId) {
158
+ const url = `${BASE_PATH}/v1/user/playlists/like/${playlistId}`
159
+ return await fetchHandler(url, 'PUT')
160
+ }
161
+
162
+ /**
163
+ * Unlikes a previously liked playlist.
164
+ * @async
165
+ * @function unlikePlaylist
166
+ * @param {string|number} playlistId - The unique identifier of the playlist to unlike.
167
+ *
168
+ * @returns {Promise<Object>}
169
+ *
170
+ *
171
+ * @example
172
+ * // Unlike playlist with ID '123'
173
+ * try {
174
+ * const response = await unlikePlaylist('123');
175
+ * console.log('Playlist unliked successfully:', response);
176
+ * } catch (error) {
177
+ * console.error('Failed to unlike playlist:', error);
178
+ * }
179
+ */
180
+ export async function unlikePlaylist(playlistId) {
181
+ const url = `${BASE_PATH}/v1/user/playlists/like/${playlistId}`
182
+ return await fetchHandler(url, 'DELETE')
183
+ }
184
+
185
+ /**
186
+ * Reports a playlist
187
+ *
188
+ * @async
189
+ * @function reportPlaylist
190
+ * @param {string|number} playlistId - The unique identifier of the playlist to report.
191
+ *
192
+ * @returns {Promise<Object>}
193
+ *
194
+ * @example
195
+ * // Report playlist with ID '123'
196
+ * try {
197
+ * const response = await reportPlaylist('123');
198
+ * console.log('Playlist reported successfully:', response);
199
+ * } catch (error) {
200
+ * console.error('Failed to report playlist:', error);
201
+ * }
202
+ */
203
+ export async function reportPlaylist(playlistId) {
204
+ const url = `${BASE_PATH}/v1/user/playlists/report/${playlistId}`
205
+ return await fetchHandler(url, 'POST')
206
+ }
207
+
208
+ /**
209
+ * Reorders items within a playlist.
210
+ * @async
211
+ * @function reorderPlaylistItems
212
+ * @param {string|number} playlistId - The unique identifier of the playlist to reorder.
213
+ * @param {Array<string|number>} playlistItemIds - An array of playlist item IDs (not content ids) in the desired order.
214
+ * All items in the playlist must present in this list for the BE to handle the reorder.
215
+ *
216
+ * @returns {Promise<Object>}
217
+ * @example
218
+ * // Reorder items in playlist with ID '123'
219
+ * try {
220
+ * const newOrder = [5, 2, 1, 4, 3]; // Representing playlist item IDs in the desired order
221
+ * const response = await reorderPlaylistItems('123', newOrder);
222
+ * console.log('Playlist items reordered successfully:', response);
223
+ * } catch (error) {
224
+ * console.error('Failed to reorder playlist items:', error);
225
+ * }
226
+ */
227
+ export async function reorderPlaylistItems(playlistId, playlistItemIds){
228
+ const url = `${BASE_PATH}/v1/user/playlists/reorder/${playlistId}`
229
+ const payload = {
230
+ items: playlistItemIds,
231
+ }
232
+ return await fetchHandler(url, 'POST')
233
+ }
234
+
235
+ /**
236
+ * Duplicates a playlist and playlist items for the provided playlistID for the authorized user
237
+ *
238
+ * @param {string|number} playlistId
239
+ * @param {CreatePlaylistDTO} playlistData - An object containing data to create the playlist. The fields include:
240
+ * - `name` (string): The name of the new playlist (required, max 255 characters).
241
+ * - `description` (string): A description of the playlist (optional, max 1000 characters).
242
+ * - `category` (string): The category of the playlist.
243
+ * - `private` (boolean): Whether the playlist is private (optional, defaults to false).
244
+ * - `brand` (string): Brand identifier for the playlist.
245
+ *
246
+ * @returns {Promise<Playlist>}
247
+ * @example
248
+ * duplicatePlaylist(81167, { name: "My Playlist (Duplicate)", description: "A cool playlist", private: true })
249
+ * .then(response => console.log(response))
250
+ * .catch(error => console.error('Error creating playlist:', error));
251
+ */
252
+ export async function duplicatePlaylist(playlistId, playlistData) {
253
+ const url = `${BASE_PATH}/v1/user/playlists/duplicate/${playlistId}`
254
+ return await fetchHandler(url, 'POST', null, playlistData)
255
+ }
256
+
257
+ // Unsupported playlist endpoints are here and will need to be implemented one by one
258
+ //
259
+ //
260
+ // /**
261
+ // * Deletes a user’s playlist along with all associated items by sending a DELETE request to the API.
262
+ // *
263
+ // * This function calls the `/playlists/playlist` endpoint, where the server verifies the user’s ownership of the specified playlist.
264
+ // * If the user is authorized, it deletes both the playlist and its associated items.
265
+ // *
266
+ // * @param {string|number} playlistId - The unique identifier of the playlist to be deleted.
267
+ // *
268
+ // * @returns {Promise<Object>} - A promise that resolves to an object containing:
269
+ // * - `success` (boolean): Indicates if the deletion was successful (`true` for success).
270
+ // * - `message` (string): Success confirmation message (e.g., "Playlist and associated items deleted successfully").
271
+ // *
272
+ // * If the user is unauthorized or the playlist does not exist, the promise rejects with an error.
273
+ // *
274
+ // * @example
275
+ // * deletePlaylist(12345)
276
+ // * .then(response => {
277
+ // * if (response.success) {
278
+ // * console.log(response.message);
279
+ // * }
280
+ // * })
281
+ // * .catch(error => console.error('Error deleting playlist:', error));
282
+ // */
283
+ // export async function deletePlaylist(playlistId) {
284
+ // let url = `/playlists/playlist/${playlistId}`
285
+ // return await fetchHandler(url, 'delete')
286
+ // }
287
+ //
288
+ // /**
289
+ // * Updates a user’s playlist by sending a PUT request with updated data to the API.
290
+ // *
291
+ // * This function calls the `/playlists/playlist/{playlistId}` endpoint, where the server validates the incoming data
292
+ // * and verifies that the authenticated user is the playlist owner. If authorized, it updates the playlist details with the provided data.
293
+ // *
294
+ // * @param {string|number} playlistId - The unique identifier of the playlist to be updated.
295
+ // * @param {Object} updatedData - An object containing the playlist data to update. The possible fields include:
296
+ // * - `name` (string): The new name of the playlist (max 255 characters).
297
+ // * - `description` (string): A new description for the playlist (max 1000 characters).
298
+ // * - `category` (string): The updated category of the playlist (max 255 characters).
299
+ // * - `private` (boolean): Whether the playlist is private.
300
+ // * - `thumbnail_url` (string): The URL of the playlist thumbnail.
301
+ // *
302
+ // * @returns {Promise<Object>} - A promise that resolves to an object containing:
303
+ // * - `success` (boolean): Indicates if the update was successful (`true` for success).
304
+ // * - `message` (string): Success confirmation message if the update is successful.
305
+ // * - Other fields containing the updated playlist data.
306
+ // *
307
+ // * If the user is unauthorized or the data validation fails, the promise rejects with an error.
308
+ // *
309
+ // * @example
310
+ // * updatePlaylist(12345, { name: "My New Playlist Name", description: "Updated description" })
311
+ // * .then(response => {
312
+ // * if (response.success) {
313
+ // * console.log(response.message);
314
+ // * }
315
+ // * })
316
+ // * .catch(error => console.error('Error updating playlist:', error));
317
+ // */
318
+ // export async function updatePlaylist(playlistId, updatedData) {
319
+ // const url = `/playlists/playlist/${playlistId}`
320
+ // return await fetchHandler(url, 'PUT', null, updatedData)
321
+ // }
322
+ //
323
+ //
324
+ // /**
325
+ // * Retrieves details of a specific playlist by its ID.
326
+ // *
327
+ // * This function sends a GET request to the `/playlists/playlist` endpoint with a specified playlist ID.
328
+ // * The server validates the user's access to the playlist and returns playlist details if the user is authorized.
329
+ // *
330
+ // * @param {string|number} playlistId - The unique identifier of the playlist to retrieve.
331
+ // *
332
+ // * @returns {Promise<Object>} - A promise that resolves to the response from the API, containing:
333
+ // * - `data` (Object): The playlist details, or an error message if access is denied or the playlist is not found.
334
+ // *
335
+ // * @example
336
+ // * fetchPlaylist(12345)
337
+ // * .then(response => console.log(response.data))
338
+ // * .catch(error => console.error('Error fetching playlist:', error));
339
+ // */
340
+ // export async function fetchPlaylist(playlistId) {
341
+ // const url = `/playlists/playlist/${playlistId}`
342
+ // return await fetchHandler(url, 'GET')
343
+ // }
344
+ //
345
+ // /**
346
+ // * Retrieves items within a specified playlist by playlist ID.
347
+ // *
348
+ // * This function sends a GET request to the `/playlists/playlist-lessons` endpoint to fetch items in the given playlist.
349
+ // * The server combines data from the playlist and additional metadata from Sanity to enhance item details.
350
+ // *
351
+ // * @param {string|number} playlistId - The unique identifier of the playlist whose items are to be fetched.
352
+ // *
353
+ // * @returns {Promise<Array<Object>>} - A promise that resolves to an array of playlist items
354
+ // *
355
+ // * @example
356
+ // * fetchPlaylistItems(12345)
357
+ // * .then(items => console.log(items))
358
+ // * .catch(error => console.error('Error fetching playlist items:', error));
359
+ // */
360
+ // export async function fetchPlaylistItems(playlistId, { sort } = {}) {
361
+ // const sortString = sort ? `&sort=${sort}` : ''
362
+ // const url = `/playlists/playlist-lessons?playlist_id=${playlistId}${sortString}`
363
+ // return await fetchHandler(url, 'GET')
364
+ // }
365
+ //
366
+ // /**
367
+ // * Updates a playlist item with the provided data.
368
+ // *
369
+ // * @param {Object} updatedData - The data to update the playlist item with.
370
+ // * @param {number} updatedData.user_playlist_item_id - The ID of the playlist item to update.
371
+ // * @param {number} [updatedData.start_second] - (Optional) The start time in seconds for the item.
372
+ // * @param {number} [updatedData.end_second] - (Optional) The end time in seconds for the item.
373
+ // * @param {string} [updatedData.playlist_item_name] - (Optional) The new name for the playlist item.
374
+ // * @param {number} [updatedData.position] - (Optional) The new position for the playlist item within the playlist.
375
+ // * @returns {Promise<Object|null>} - A promise that resolves to an object containing:
376
+ // * - `success` (boolean): Indicates if the update was successful (`true` for success).
377
+ // * - `data` (Object): The updated playlist item data.
378
+ // *
379
+ // * Resolves to `null` if the request fails.
380
+ // * @throws {Error} - Throws an error if the request fails.
381
+ // *
382
+ // * @example
383
+ // * const updatedData = {
384
+ // * user_playlist_item_id: 123,
385
+ // * start_second: 30,
386
+ // * end_second: 120,
387
+ // * playlist_item_name: "Updated Playlist Item Name",
388
+ // * position: 2
389
+ // * };
390
+ // *
391
+ // * updatePlaylistItem(updatedData)
392
+ // * .then(response => {
393
+ // * if (response.success) {
394
+ // * console.log("Playlist item updated successfully:", response.data);
395
+ // * }
396
+ // * })
397
+ // * .catch(error => {
398
+ // * console.error("Error updating playlist item:", error);
399
+ // * });
400
+ // */
401
+ // export async function updatePlaylistItem(updatedData) {
402
+ // const url = `/playlists/item`
403
+ // return await fetchHandler(url, 'POST', null, updatedData)
404
+ // }
405
+ //
406
+ // /**
407
+ // * Deletes a playlist item and repositions other items in the playlist if necessary.
408
+ // *
409
+ // * @param {Object} payload - The data required to delete the playlist item.
410
+ // * @param {number} payload.user_playlist_item_id - The ID of the playlist item to delete.
411
+ // * @returns {Promise<Object|null>} - A promise that resolves to an object containing:
412
+ // * - `success` (boolean): Indicates if the deletion was successful (`true` for success).
413
+ // * - `message` (string): A success message if the item is deleted successfully.
414
+ // * - `error` (string): An error message if the deletion fails.
415
+ // *
416
+ // * Resolves to `null` if the request fails.
417
+ // * @throws {Error} - Throws an error if the request fails.
418
+ // *
419
+ // * @example
420
+ // * const payload = {
421
+ // * user_playlist_item_id: 123
422
+ // * };
423
+ // *
424
+ // * deletePlaylistItem(payload)
425
+ // * .then(response => {
426
+ // * if (response.success) {
427
+ // * console.log("Playlist item deleted successfully:", response.message);
428
+ // * } else {
429
+ // * console.error("Error:", response.error);
430
+ // * }
431
+ // * })
432
+ // * .catch(error => {
433
+ // * console.error("Error deleting playlist item:", error);
434
+ // * });
435
+ // */
436
+ // export async function deletePlaylistItem(payload) {
437
+ // const url = `/playlists/item`
438
+ // return await fetchHandler(url, 'DELETE', null, payload)
439
+ // }
440
+ //
441
+ // /**
442
+ // * Fetches detailed data for a specific playlist item, including associated Sanity and Assignment information if available.
443
+ // *
444
+ // * @param {Object} payload - The request payload containing necessary parameters.
445
+ // * @param {number} payload.user_playlist_item_id - The unique ID of the playlist item to fetch.
446
+ // * @returns {Promise<Object|null>} - A promise that resolves to an object with the fetched playlist item data, including:
447
+ // * - `success` (boolean): Indicates if the data retrieval was successful (`true` on success).
448
+ // * - `data` (Object): Contains the detailed playlist item data enriched with Sanity and Assignment details, if available.
449
+ // *
450
+ // * Resolves to `null` if the request fails.
451
+ // * @throws {Error} - Throws an error if the request encounters issues during retrieval.
452
+ // *
453
+ // * @example
454
+ // * const payload = { user_playlist_item_id: 123 };
455
+ // *
456
+ // * fetchPlaylistItem(payload)
457
+ // * .then(response => {
458
+ // * if (response?.success) {
459
+ // * console.log("Fetched playlist item data:", response.data);
460
+ // * } else {
461
+ // * console.log("Failed to fetch playlist item data.");
462
+ // * }
463
+ // * })
464
+ // * .catch(error => {
465
+ // * console.error("Error fetching playlist item:", error);
466
+ // * });
467
+ // */
468
+ // export async function fetchPlaylistItem(payload) {
469
+ // const playlistItemId = payload.user_playlist_item_id
470
+ // const url = `/playlists/item/${playlistItemId}`
471
+ // return await fetchHandler(url)
472
+ // }