musora-content-services 1.0.223 → 1.0.225

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.
@@ -38,6 +38,7 @@ export async function fetchCompletedState(content_id) {
38
38
 
39
39
  const headers = {
40
40
  'Content-Type': 'application/json',
41
+ 'Accept': 'application/json',
41
42
  'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
42
43
  };
43
44
 
@@ -72,6 +73,7 @@ export async function fetchAllCompletedStates(contentIds) {
72
73
 
73
74
  const headers = {
74
75
  'Content-Type': 'application/json',
76
+ 'Accept': 'application/json',
75
77
  'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
76
78
  };
77
79
 
@@ -104,6 +106,7 @@ export async function fetchSongsInProgress(brand) {
104
106
 
105
107
  const headers = {
106
108
  'Content-Type': 'application/json',
109
+ 'Accept': 'application/json',
107
110
  'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
108
111
  };
109
112
 
@@ -147,6 +150,7 @@ export async function fetchContentInProgress(type = "all", brand, {page, limit}
147
150
  }
148
151
  const headers = {
149
152
  'Content-Type': 'application/json',
153
+ 'Accept': 'application/json',
150
154
  'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
151
155
  };
152
156
  try {
@@ -189,6 +193,7 @@ export async function fetchCompletedContent(type = "all", brand, {page, limit} =
189
193
  }
190
194
  const headers = {
191
195
  'Content-Type': 'application/json',
196
+ 'Accept': 'application/json',
192
197
  'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
193
198
  };
194
199
  try {
@@ -221,6 +226,7 @@ export async function fetchContentPageUserData(contentId) {
221
226
  let url = `/content/${contentId}/user_data/${globalConfig.railcontentConfig.userId}`;
222
227
  const headers = {
223
228
  'Content-Type': 'application/json',
229
+ 'Accept': 'application/json',
224
230
  'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
225
231
  };
226
232
 
@@ -239,6 +245,36 @@ export async function fetchContentPageUserData(contentId) {
239
245
  }
240
246
  }
241
247
 
248
+ /**
249
+ * Fetches the ID and Type of the piece of content that would be the next one for the user
250
+ *
251
+ * @param {int} contentId - The id of the parent (method, level, or course) piece of content.
252
+ * @returns {Promise<Object|null>} - Returns and Object with the id and type of the next piece of content if found, otherwise null.
253
+ */
254
+ export async function fetchNextContentDataForParent(contentId) {
255
+ let url = `/content/${contentId}/next/${globalConfig.railcontentConfig.userId}`;
256
+ const headers = {
257
+ 'Content-Type': 'application/json',
258
+ 'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
259
+ };
260
+
261
+ try {
262
+ const response = await fetchAbsolute(url, {headers});
263
+ const result = await response.json();
264
+ if (result) {
265
+ // console.log('fetchNextContentDataForParent', result);
266
+ return result.next;
267
+ } else {
268
+ console.log('fetchNextContentDataForParent result not json');
269
+ return null;
270
+ }
271
+ } catch (error) {
272
+ console.error('Fetch error:', error);
273
+ return null;
274
+ }
275
+ }
276
+
277
+
242
278
  export async function fetchUserPermissionsData() {
243
279
  let url = `/content/user/permissions`;
244
280
  // in the case of an unauthorized user, we return empty permissions
@@ -256,6 +292,7 @@ async function postDataHandler(url, data) {
256
292
  export async function fetchHandler(url, method = "get", dataVersion = null, body = null) {
257
293
  let headers = {
258
294
  'Content-Type': 'application/json',
295
+ 'Accept': 'application/json',
259
296
  'X-CSRF-TOKEN': globalConfig.railcontentConfig.token,
260
297
  };
261
298
 
@@ -269,6 +306,10 @@ export async function fetchHandler(url, method = "get", dataVersion = null, body
269
306
  }
270
307
  }
271
308
 
309
+ if (globalConfig.localTimezoneString) {
310
+ headers['M-Client-Timezone'] = globalConfig.localTimezoneString;
311
+ }
312
+
272
313
  if (globalConfig.railcontentConfig.authToken) {
273
314
  headers['Authorization'] = `Bearer ${globalConfig.railcontentConfig.authToken}`;
274
315
  }
@@ -27,7 +27,8 @@ import {
27
27
  fetchAllCompletedStates,
28
28
  fetchCompletedChallenges,
29
29
  fetchCurrentSongComplete,
30
- fetchOwnedChallenges
30
+ fetchOwnedChallenges,
31
+ fetchNextContentDataForParent
31
32
  } from './railcontent.js';
32
33
  import {arrayToStringRepresentation, FilterBuilder} from "../filterBuilder";
33
34
  import {fetchUserPermissions} from "./userPermissions";
@@ -608,6 +609,7 @@ export async function fetchAll(brand, type, {
608
609
  start: start,
609
610
  end: end,
610
611
  });
612
+
611
613
  return fetchSanity(query, true);
612
614
  }
613
615
 
@@ -839,7 +841,7 @@ export async function fetchAllFilterOptions(
839
841
  ? `brand == '${brand}' && status == "published" && references(*[_type=='instructor' && railcontent_id == ${coachId}]._id) ${filterWithoutOption || ''}`
840
842
  : `_type == '${contentType}' && brand == "${brand}"${includeStatusFilter ? statusFilter : ''}${style && excludeFilter !== "style" ? ` && '${style}' in genre[]->name` : ''}${artist && excludeFilter !== "artist" ? ` && artist->name == '${artist}'` : ''} ${progressFilter} ${filterWithoutOption || ''}`;
841
843
  };
842
-
844
+
843
845
  const metaData = processMetadata(brand, contentType, true);
844
846
  const allowableFilters = metaData?.allowableFilters || [];
845
847
  const tabs = metaData?.tabs || [];
@@ -1103,6 +1105,24 @@ export async function fetchNextPreviousLesson(railcontentId) {
1103
1105
  return await fetchSanity(query, true);
1104
1106
  }
1105
1107
 
1108
+ /**
1109
+ * Fetch the next piece of content under a parent by Railcontent ID
1110
+ * @param {int} railcontentId - The Railcontent ID of the parent content
1111
+ * @returns {Promise<{next: (Object|null)}|null>} - object with 'next' attribute
1112
+ * @example
1113
+ * jumpToContinueContent(296693)
1114
+ * then.(data => { console.log('next', data.next);})
1115
+ * .catch(error => console.error(error));
1116
+ */
1117
+ export async function jumpToContinueContent(railcontentId) {
1118
+ const nextContent = await fetchNextContentDataForParent(railcontentId);
1119
+ if (!nextContent) {
1120
+ return null;
1121
+ }
1122
+ let next = await fetchByRailContentId(nextContent.id, nextContent.type);
1123
+ return {next};
1124
+ }
1125
+
1106
1126
  /**
1107
1127
  * Fetch the page data for a specific lesson by Railcontent ID.
1108
1128
  * @param {string} railContentId - The Railcontent ID of the current lesson.
File without changes
File without changes