musora-content-services 1.0.87 → 1.0.88

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.88](https://github.com/railroadmedia/musora-content-services/compare/v1.0.87...v1.0.88) (2024-09-11)
6
+
5
7
  ### [1.0.87](https://github.com/railroadmedia/musora-content-services/compare/v1.0.86...v1.0.87) (2024-09-09)
6
8
 
7
9
  ### [1.0.86](https://github.com/railroadmedia/musora-content-services/compare/v1.0.85...v1.0.86) (2024-09-09)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.87",
3
+ "version": "1.0.88",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -22,6 +22,8 @@ let globalConfig = {
22
22
  * @param {Object} config.railcontentConfig - Configuration for user services.
23
23
  * @param {string} config.railcontentConfig.token - The token for authenticating user-specific requests.
24
24
  * @param {string} config.railcontentConfig.userId - The user ID for fetching user-specific data.
25
+ * @param {string} config.railcontentConfig.baseUrl - The url for the enviroment.
26
+
25
27
  *
26
28
  * @example
27
29
  * // Initialize the service in your app.js
@@ -36,7 +38,8 @@ let globalConfig = {
36
38
  * },
37
39
  * railcontentConfig: {
38
40
  * token: 'your-user-api-token',
39
- * userId: 'current-user-id'
41
+ * userId: 'current-user-id',
42
+ * baseUrl: 'https://web-staging-one.musora.com'
40
43
  * }
41
44
  * });
42
45
  */
@@ -24,7 +24,7 @@ export async function fetchCompletedState(content_id) {
24
24
  };
25
25
 
26
26
  try {
27
- const response = await fetch(url, { headers });
27
+ const response = await fetchAbsolute(url, { headers });
28
28
  const result = await response.json();
29
29
 
30
30
  if (result && result[content_id]) { return result[content_id]; // Return the correct object
@@ -56,7 +56,7 @@ export async function fetchVimeoData(vimeo_id) {
56
56
  };
57
57
 
58
58
  try {
59
- const response = await fetch(url, { headers });
59
+ const response = await fetchAbsolute(url, { headers });
60
60
  const result = await response.json();
61
61
 
62
62
  if (result) {
@@ -91,7 +91,7 @@ export async function fetchAllCompletedStates(contentIds) {
91
91
  };
92
92
 
93
93
  try {
94
- const response = await fetch(url, { headers });
94
+ const response = await fetchAbsolute(url, { headers });
95
95
  const result = await response.json();
96
96
  if(result){
97
97
  return result;
@@ -123,7 +123,7 @@ export async function fetchSongsInProgress(brand) {
123
123
  };
124
124
 
125
125
  try {
126
- const response = await fetch(url, { headers });
126
+ const response = await fetchAbsolute(url, { headers });
127
127
  const result = await response.json();
128
128
  if(result){
129
129
  console.log('fetchSongsInProgress', result);
@@ -160,7 +160,7 @@ export async function fetchContentInProgress(type="all", brand) {
160
160
  'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
161
161
  };
162
162
  try {
163
- const response = await fetch(url, { headers });
163
+ const response = await fetchAbsolute(url, { headers });
164
164
  const result = await response.json();
165
165
  if(result){
166
166
  console.log('contentInProgress', result);
@@ -191,8 +191,9 @@ export async function fetchContentPageUserData(contentId) {
191
191
  'Content-Type': 'application/json',
192
192
  'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
193
193
  };
194
+
194
195
  try {
195
- const response = await fetch(url, { headers });
196
+ const response = await fetchAbsolute(url, { headers });
196
197
  const result = await response.json();
197
198
  if(result){
198
199
  console.log('fetchContentPageUserData', result);
@@ -204,4 +205,12 @@ export async function fetchContentPageUserData(contentId) {
204
205
  console.error('Fetch error:', error);
205
206
  return null;
206
207
  }
208
+ }
209
+
210
+ function fetchAbsolute(url, params) {
211
+ if (url.startsWith('/')) {
212
+ return fetch(globalConfig.railcontentConfig.baseUrl + url, params)
213
+ } else {
214
+ return fetch(url, params);
215
+ }
207
216
  }
@@ -224,7 +224,7 @@ export async function fetchSongFilterOptions(brand) {
224
224
  */
225
225
  export async function fetchSongCount(brand) {
226
226
  const query = `count(*[_type == 'song' && brand == "${brand}"])`;
227
- return fetchSanity(query, false);
227
+ return fetchSanity(query, true);
228
228
  }
229
229
 
230
230
  /**
@@ -812,7 +812,9 @@ export async function fetchLessonContent(railContentId) {
812
812
  "instructors":instructor[]->name,
813
813
  instructor[]->,
814
814
  ${assignmentsField}
815
- video}`
815
+ video,
816
+ length_in_seconds
817
+ }`
816
818
  return fetchSanity(query, false);
817
819
  }
818
820
 
@@ -838,6 +840,22 @@ export async function fetchRelatedLessons(railContentId, brand) {
838
840
  return fetchSanity(query, false);
839
841
  }
840
842
 
843
+ /**
844
+ * Fetch all packs.
845
+ * @param {string} brand - The brand for which to fetch packs.
846
+ * @param {string} [searchTerm=""] - The search term to filter packs.
847
+ * @param {string} [sort="-published_on"] - The field to sort the packs by.
848
+ * @returns {Promise<Array<Object>|null>} - The fetched pack content data or null if not found.
849
+ */
850
+ export async function fetchAllPacks(brand, sort = "-published_on", searchTerm = "") {
851
+ const sortOrder = getSortOrder(sort);
852
+
853
+ const query = `*[_type == 'pack' && brand == '${brand}' && title match "${searchTerm}*"]{
854
+ ${getFieldsForContentType('pack')}
855
+ } | order(${sortOrder})`
856
+ return fetchSanity(query, true);
857
+ }
858
+
841
859
  /**
842
860
  * Fetch all content for a specific pack by Railcontent ID.
843
861
  * @param {string} railcontentId - The Railcontent ID of the pack.
@@ -846,18 +864,9 @@ export async function fetchRelatedLessons(railContentId, brand) {
846
864
  export async function fetchPackAll(railcontentId) {
847
865
  //TODO: Implement getPacks
848
866
  const query = `*[railcontent_id == ${railcontentId}]{
849
- railcontent_id,
850
- "id": railcontent_id,
851
- title,
852
- "image": thumbnail.asset->url,
853
- "artist_name": artist->name,
854
- artist,
855
- difficulty,
856
- difficulty_string,
857
- web_url_path,
858
- published_on
859
- } | order(published_on asc)[0...5]`
860
- return fetchSanity(query, true);
867
+ ${getFieldsForContentType('pack')}
868
+ } | order(published_on asc)[0...1]`
869
+ return fetchSanity(query, false);
861
870
  }
862
871
 
863
872
  export async function fetchLiveEvent(brand) {