musora-content-services 1.0.222 → 1.0.224

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 (60) 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 +201 -43
  27. package/docs/module-Sanity-Services.html +214 -49
  28. package/docs/railcontent.js.html +56 -5
  29. package/docs/sanity.js.html +63 -20
  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/contentTypeConfig.js +17 -3
  46. package/src/index.d.ts +7 -1
  47. package/src/index.js +7 -3
  48. package/src/services/config.js +0 -0
  49. package/src/services/contentLikes.js +0 -0
  50. package/src/services/lastUpdated.js +0 -0
  51. package/src/services/railcontent.js +37 -0
  52. package/src/services/sanity.js +24 -3
  53. package/src/services/userPermissions.js +0 -0
  54. package/test/contentLikes.test.js +0 -0
  55. package/test/initializeTests.js +0 -0
  56. package/test/lastUpdated.test.js +0 -0
  57. package/test/localStorageMock.js +0 -0
  58. package/test/log.js +0 -0
  59. package/test/userPermissions.test.js +0 -0
  60. package/tools/generate-index.js +0 -0
package/src/index.js CHANGED
@@ -48,6 +48,7 @@ import {
48
48
  fetchContentPageUserData,
49
49
  fetchContentProgress,
50
50
  fetchHandler,
51
+ fetchNextContentDataForParent,
51
52
  fetchOwnedChallenges,
52
53
  fetchPinnedPlaylists,
53
54
  fetchPlaylist,
@@ -117,13 +118,13 @@ import {
117
118
  fetchPackData,
118
119
  fetchParentByRailContentId,
119
120
  fetchParentForDownload,
121
+ fetchPlayAlongsCount,
120
122
  fetchRelatedLessons,
121
123
  fetchRelatedMethodLessons,
122
124
  fetchRelatedSongs,
123
125
  fetchSanity,
124
126
  fetchScheduledReleases,
125
127
  fetchShowsData,
126
- fetchPlayAlongsCount,
127
128
  fetchSongArtistCount,
128
129
  fetchSongById,
129
130
  fetchSongCount,
@@ -131,7 +132,8 @@ import {
131
132
  fetchTopLevelParentId,
132
133
  fetchUpcomingEvents,
133
134
  fetchWorkouts,
134
- getSortOrder
135
+ getSortOrder,
136
+ jumpToContinueContent
135
137
  } from './services/sanity.js';
136
138
 
137
139
  import {
@@ -193,6 +195,7 @@ export {
193
195
  fetchMethodPreviousNextLesson,
194
196
  fetchMethods,
195
197
  fetchNewReleases,
198
+ fetchNextContentDataForParent,
196
199
  fetchNextPreviousLesson,
197
200
  fetchOwnedChallenges,
198
201
  fetchPackAll,
@@ -201,6 +204,7 @@ export {
201
204
  fetchParentByRailContentId,
202
205
  fetchParentForDownload,
203
206
  fetchPinnedPlaylists,
207
+ fetchPlayAlongsCount,
204
208
  fetchPlaylist,
205
209
  fetchPlaylistItem,
206
210
  fetchPlaylistItems,
@@ -211,7 +215,6 @@ export {
211
215
  fetchScheduledReleases,
212
216
  fetchShowsData,
213
217
  fetchSongArtistCount,
214
- fetchPlayAlongsCount,
215
218
  fetchSongById,
216
219
  fetchSongCount,
217
220
  fetchSongFilterOptions,
@@ -238,6 +241,7 @@ export {
238
241
  globalConfig,
239
242
  initializeService,
240
243
  isContentLiked,
244
+ jumpToContinueContent,
241
245
  likeContent,
242
246
  likePlaylist,
243
247
  pinPlaylist,
File without changes
File without changes
File without changes
@@ -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
 
@@ -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
 
@@ -828,17 +830,18 @@ export async function fetchAllFilterOptions(
828
830
 
829
831
  const includedFieldsFilter = filters?.length ? filtersToGroq(filters) : undefined;
830
832
  const progressFilter = progressIds ? `&& railcontent_id in [${progressIds.join(',')}]` : "";
833
+ const isAdmin = (await fetchUserPermissions()).isAdmin;
831
834
 
832
835
  const constructCommonFilter = (excludeFilter) => {
833
836
  const filterWithoutOption = excludeFilter ? filtersToGroq(filters, excludeFilter) : includedFieldsFilter;
834
837
  const statusFilter = ' && status == "published"';
835
- const includeStatusFilter = !['instructor','artist','genre'].includes(contentType);
838
+ const includeStatusFilter = !isAdmin && !['instructor','artist','genre'].includes(contentType);
836
839
 
837
840
  return coachId
838
841
  ? `brand == '${brand}' && status == "published" && references(*[_type=='instructor' && railcontent_id == ${coachId}]._id) ${filterWithoutOption || ''}`
839
842
  : `_type == '${contentType}' && brand == "${brand}"${includeStatusFilter ? statusFilter : ''}${style && excludeFilter !== "style" ? ` && '${style}' in genre[]->name` : ''}${artist && excludeFilter !== "artist" ? ` && artist->name == '${artist}'` : ''} ${progressFilter} ${filterWithoutOption || ''}`;
840
843
  };
841
-
844
+
842
845
  const metaData = processMetadata(brand, contentType, true);
843
846
  const allowableFilters = metaData?.allowableFilters || [];
844
847
  const tabs = metaData?.tabs || [];
@@ -1102,6 +1105,24 @@ export async function fetchNextPreviousLesson(railcontentId) {
1102
1105
  return await fetchSanity(query, true);
1103
1106
  }
1104
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
+
1105
1126
  /**
1106
1127
  * Fetch the page data for a specific lesson by Railcontent ID.
1107
1128
  * @param {string} railContentId - The Railcontent ID of the current lesson.
File without changes
File without changes
File without changes
File without changes
File without changes
package/test/log.js CHANGED
File without changes
File without changes
File without changes