musora-content-services 1.0.41 → 1.0.43

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,10 @@
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.43](https://github.com/railroadmedia/musora-content-services/compare/v1.0.42...v1.0.43) (2024-08-20)
6
+
7
+ ### [1.0.42](https://github.com/railroadmedia/musora-content-services/compare/v1.0.41...v1.0.42) (2024-08-20)
8
+
5
9
  ### [1.0.41](https://github.com/railroadmedia/musora-content-services/compare/v1.0.40...v1.0.41) (2024-08-20)
6
10
 
7
11
  ### [1.0.40](https://github.com/railroadmedia/musora-content-services/compare/v1.0.39...v1.0.40) (2024-08-20)
package/README.md CHANGED
@@ -55,6 +55,7 @@ https://railroadmedia.github.io/musora-content-services/
55
55
  ## Run tests
56
56
  Copy .env file from 1Password "musora-content-services .env"
57
57
  Run the following to execute the tests
58
+ You may need to install jest (npm install --save-dev jest)
58
59
  ```
59
60
  npm test
60
61
  ```
@@ -111,7 +111,7 @@ module.exports = {
111
111
  <br class="clear">
112
112
 
113
113
  <footer>
114
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 19:53:05 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
114
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 20:28:18 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
115
115
  </footer>
116
116
 
117
117
  <script>prettyPrint();</script>
package/docs/index.html CHANGED
@@ -110,7 +110,7 @@ Run the following to execute the tests</p>
110
110
  <br class="clear">
111
111
 
112
112
  <footer>
113
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 19:53:05 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
113
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 20:28:18 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
114
114
  </footer>
115
115
 
116
116
  <script>prettyPrint();</script>
@@ -656,7 +656,7 @@ initializeService({
656
656
  <br class="clear">
657
657
 
658
658
  <footer>
659
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 19:53:05 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
659
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 20:28:18 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
660
660
  </footer>
661
661
 
662
662
  <script>prettyPrint();</script>
@@ -783,7 +783,7 @@
783
783
  <br class="clear">
784
784
 
785
785
  <footer>
786
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 19:53:05 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
786
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 20:28:18 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
787
787
  </footer>
788
788
 
789
789
  <script>prettyPrint();</script>
@@ -100,7 +100,7 @@
100
100
 
101
101
  <dt class="tag-source">Source:</dt>
102
102
  <dd class="tag-source"><ul class="dummy"><li>
103
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line465">line 465</a>
103
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line414">line 414</a>
104
104
  </li></ul></dd>
105
105
 
106
106
 
@@ -593,7 +593,7 @@ The filter options are dynamically generated based on the provided filters, styl
593
593
 
594
594
  <dt class="tag-source">Source:</dt>
595
595
  <dd class="tag-source"><ul class="dummy"><li>
596
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line607">line 607</a>
596
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line556">line 556</a>
597
597
  </li></ul></dd>
598
598
 
599
599
 
@@ -1566,7 +1566,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
1566
1566
 
1567
1567
  <dt class="tag-source">Source:</dt>
1568
1568
  <dd class="tag-source"><ul class="dummy"><li>
1569
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line398">line 398</a>
1569
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line347">line 347</a>
1570
1570
  </li></ul></dd>
1571
1571
 
1572
1572
 
@@ -1731,7 +1731,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
1731
1731
 
1732
1732
  <dt class="tag-source">Source:</dt>
1733
1733
  <dd class="tag-source"><ul class="dummy"><li>
1734
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line424">line 424</a>
1734
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line373">line 373</a>
1735
1735
  </li></ul></dd>
1736
1736
 
1737
1737
 
@@ -1896,7 +1896,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
1896
1896
 
1897
1897
  <dt class="tag-source">Source:</dt>
1898
1898
  <dd class="tag-source"><ul class="dummy"><li>
1899
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line647">line 647</a>
1899
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line596">line 596</a>
1900
1900
  </li></ul></dd>
1901
1901
 
1902
1902
 
@@ -2054,7 +2054,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
2054
2054
 
2055
2055
  <dt class="tag-source">Source:</dt>
2056
2056
  <dd class="tag-source"><ul class="dummy"><li>
2057
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line819">line 819</a>
2057
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line768">line 768</a>
2058
2058
  </li></ul></dd>
2059
2059
 
2060
2060
 
@@ -2219,7 +2219,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
2219
2219
 
2220
2220
  <dt class="tag-source">Source:</dt>
2221
2221
  <dd class="tag-source"><ul class="dummy"><li>
2222
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line725">line 725</a>
2222
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line674">line 674</a>
2223
2223
  </li></ul></dd>
2224
2224
 
2225
2225
 
@@ -2384,7 +2384,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
2384
2384
 
2385
2385
  <dt class="tag-source">Source:</dt>
2386
2386
  <dd class="tag-source"><ul class="dummy"><li>
2387
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line689">line 689</a>
2387
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line638">line 638</a>
2388
2388
  </li></ul></dd>
2389
2389
 
2390
2390
 
@@ -2542,7 +2542,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
2542
2542
 
2543
2543
  <dt class="tag-source">Source:</dt>
2544
2544
  <dd class="tag-source"><ul class="dummy"><li>
2545
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line668">line 668</a>
2545
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line617">line 617</a>
2546
2546
  </li></ul></dd>
2547
2547
 
2548
2548
 
@@ -2700,7 +2700,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
2700
2700
 
2701
2701
  <dt class="tag-source">Source:</dt>
2702
2702
  <dd class="tag-source"><ul class="dummy"><li>
2703
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line322">line 322</a>
2703
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line271">line 271</a>
2704
2704
  </li></ul></dd>
2705
2705
 
2706
2706
 
@@ -2858,7 +2858,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
2858
2858
 
2859
2859
  <dt class="tag-source">Source:</dt>
2860
2860
  <dd class="tag-source"><ul class="dummy"><li>
2861
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line699">line 699</a>
2861
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line648">line 648</a>
2862
2862
  </li></ul></dd>
2863
2863
 
2864
2864
 
@@ -3016,7 +3016,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
3016
3016
 
3017
3017
  <dt class="tag-source">Source:</dt>
3018
3018
  <dd class="tag-source"><ul class="dummy"><li>
3019
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line779">line 779</a>
3019
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line728">line 728</a>
3020
3020
  </li></ul></dd>
3021
3021
 
3022
3022
 
@@ -3174,7 +3174,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
3174
3174
 
3175
3175
  <dt class="tag-source">Source:</dt>
3176
3176
  <dd class="tag-source"><ul class="dummy"><li>
3177
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line805">line 805</a>
3177
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line754">line 754</a>
3178
3178
  </li></ul></dd>
3179
3179
 
3180
3180
 
@@ -3339,7 +3339,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
3339
3339
 
3340
3340
  <dt class="tag-source">Source:</dt>
3341
3341
  <dd class="tag-source"><ul class="dummy"><li>
3342
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line758">line 758</a>
3342
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line707">line 707</a>
3343
3343
  </li></ul></dd>
3344
3344
 
3345
3345
 
@@ -3710,7 +3710,7 @@ fetchAllFilterOptions('myBrand', '', 'Rock', 'John Doe', 'song', 'Love')
3710
3710
 
3711
3711
  <dt class="tag-source">Source:</dt>
3712
3712
  <dd class="tag-source"><ul class="dummy"><li>
3713
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line860">line 860</a>
3713
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line809">line 809</a>
3714
3714
  </li></ul></dd>
3715
3715
 
3716
3716
 
@@ -4546,7 +4546,7 @@ fetchSanity(query, true)
4546
4546
 
4547
4547
  <dt class="tag-source">Source:</dt>
4548
4548
  <dd class="tag-source"><ul class="dummy"><li>
4549
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line359">line 359</a>
4549
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line308">line 308</a>
4550
4550
  </li></ul></dd>
4551
4551
 
4552
4552
 
@@ -4713,7 +4713,7 @@ It also includes completion status and progress percentage for each workout by f
4713
4713
 
4714
4714
  <dt class="tag-source">Source:</dt>
4715
4715
  <dd class="tag-source"><ul class="dummy"><li>
4716
- <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line250">line 250</a>
4716
+ <a href="sanity.js.html">sanity.js</a>, <a href="sanity.js.html#line249">line 249</a>
4717
4717
  </li></ul></dd>
4718
4718
 
4719
4719
 
@@ -4877,7 +4877,7 @@ It also includes completion status and progress percentage for each workout by f
4877
4877
  <br class="clear">
4878
4878
 
4879
4879
  <footer>
4880
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 19:53:05 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
4880
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 20:28:18 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
4881
4881
  </footer>
4882
4882
 
4883
4883
  <script>prettyPrint();</script>
@@ -201,7 +201,7 @@ export async function fetchContentInProgress(type="all", brand) {
201
201
  <br class="clear">
202
202
 
203
203
  <footer>
204
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 19:53:05 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
204
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 20:28:18 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
205
205
  </footer>
206
206
 
207
207
  <script>prettyPrint();</script>
@@ -293,74 +293,23 @@ export async function fetchSongCount(brand) {
293
293
  * .then(workouts => console.log(workouts))
294
294
  * .catch(error => console.error(error));
295
295
  */
296
-
297
296
  export async function fetchWorkouts(brand) {
298
- const query = `*[_type == 'workout' &amp;&amp; brand == '${brand}'] [0...5] {
299
- "id": railcontent_id,
300
- title,
301
- "image": thumbnail.asset->url,
302
- "artist_name": instructor[0]->name,
303
- "artists": instructor[]->name,
304
- difficulty,
305
- difficulty_string,
306
- length_in_seconds,
307
- published_on,
308
- "type": _type,
309
- web_url_path,
310
- } | order(published_on desc)[0...5]`;
311
-
312
- try {
313
- // Fetch the workouts
314
- const workouts = await fetchSanity(query, true);
315
-
316
- if (!workouts || workouts.length === 0) {
317
- return [];
318
- }
319
-
320
- // Extract content IDs
321
- const contentIds = workouts.map(workout => workout.id);
322
-
323
- // Fetch completion states using the existing function
324
- const completedStatesObject = await fetchAllCompletedStates(contentIds);
325
-
326
- // Check if completedStatesObject is an object and convert to array if necessary
327
- if (typeof completedStatesObject !== 'object' || completedStatesObject === null) {
328
- console.error('Completed states are not an object:', completedStatesObject);
329
- return workouts;
330
- }
331
-
332
- // Convert object to array and create a map for fast lookup
333
- const completedStatesArray = Object.entries(completedStatesObject).map(([content_id, state]) => ({
334
- content_id: parseInt(content_id, 10), // Convert key to integer if necessary
335
- ...state
336
- }));
337
-
338
- const completedStatesMap = completedStatesArray.reduce((map, state) => {
339
- map[state.content_id] = state;
340
- return map;
341
- }, {});
342
-
343
- // Add completion status and progress percentage to each workout
344
- return workouts.map(workout => {
345
- const state = completedStatesMap[workout.id];
346
- if (state) {
347
- workout.completed = state.state !== "not started";
348
- workout.progress_percent = state.percent.toString();
349
- } else {
350
- workout.completed = false;
351
- workout.progress_percent = "0";
352
- }
353
- //console.log(workout)
354
- return workout;
355
- });
356
-
357
- } catch (error) {
358
- console.error('Error fetching workouts with completion:', error);
359
- return [];
360
- }
297
+ const query = `*[_type == 'workout' &amp;&amp; brand == '${brand}'] [0...5] {
298
+ "id": railcontent_id,
299
+ title,
300
+ "image": thumbnail.asset->url,
301
+ "artist_name": instructor[0]->name,
302
+ "artists": instructor[]->name,
303
+ difficulty,
304
+ difficulty_string,
305
+ length_in_seconds,
306
+ published_on,
307
+ "type": _type,
308
+ web_url_path,
309
+ } | order(published_on desc)[0...5]`
310
+ return fetchSanity(query, true);
361
311
  }
362
312
 
363
-
364
313
  /**
365
314
  * Fetch the latest new releases for a specific brand.
366
315
  * @param {string} brand - The brand for which to fetch new releases.
@@ -986,7 +935,7 @@ function checkSanityConfig(config) {
986
935
  <br class="clear">
987
936
 
988
937
  <footer>
989
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 19:53:05 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
938
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.3</a> on Tue Aug 20 2024 20:28:18 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
990
939
  </footer>
991
940
 
992
941
  <script>prettyPrint();</script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -28,9 +28,14 @@ let contentTypeConfig = {
28
28
  '"instructors": instructor[]->name'
29
29
  ]
30
30
  },
31
+ 'student-focus': {
32
+ 'fields': [
33
+ '"instructors": instructor[]->name',
34
+ ]
35
+ },
31
36
  }
32
37
 
33
38
 
34
39
  module.exports = {
35
40
  contentTypeConfig
36
- }
41
+ }
@@ -246,74 +246,23 @@ export async function fetchSongCount(brand) {
246
246
  * .then(workouts => console.log(workouts))
247
247
  * .catch(error => console.error(error));
248
248
  */
249
-
250
249
  export async function fetchWorkouts(brand) {
251
- const query = `*[_type == 'workout' && brand == '${brand}'] [0...5] {
252
- "id": railcontent_id,
253
- title,
254
- "image": thumbnail.asset->url,
255
- "artist_name": instructor[0]->name,
256
- "artists": instructor[]->name,
257
- difficulty,
258
- difficulty_string,
259
- length_in_seconds,
260
- published_on,
261
- "type": _type,
262
- web_url_path,
263
- } | order(published_on desc)[0...5]`;
264
-
265
- try {
266
- // Fetch the workouts
267
- const workouts = await fetchSanity(query, true);
268
-
269
- if (!workouts || workouts.length === 0) {
270
- return [];
271
- }
272
-
273
- // Extract content IDs
274
- const contentIds = workouts.map(workout => workout.id);
275
-
276
- // Fetch completion states using the existing function
277
- const completedStatesObject = await fetchAllCompletedStates(contentIds);
278
-
279
- // Check if completedStatesObject is an object and convert to array if necessary
280
- if (typeof completedStatesObject !== 'object' || completedStatesObject === null) {
281
- console.error('Completed states are not an object:', completedStatesObject);
282
- return workouts;
283
- }
284
-
285
- // Convert object to array and create a map for fast lookup
286
- const completedStatesArray = Object.entries(completedStatesObject).map(([content_id, state]) => ({
287
- content_id: parseInt(content_id, 10), // Convert key to integer if necessary
288
- ...state
289
- }));
290
-
291
- const completedStatesMap = completedStatesArray.reduce((map, state) => {
292
- map[state.content_id] = state;
293
- return map;
294
- }, {});
295
-
296
- // Add completion status and progress percentage to each workout
297
- return workouts.map(workout => {
298
- const state = completedStatesMap[workout.id];
299
- if (state) {
300
- workout.completed = state.state !== "not started";
301
- workout.progress_percent = state.percent.toString();
302
- } else {
303
- workout.completed = false;
304
- workout.progress_percent = "0";
305
- }
306
- //console.log(workout)
307
- return workout;
308
- });
309
-
310
- } catch (error) {
311
- console.error('Error fetching workouts with completion:', error);
312
- return [];
313
- }
250
+ const query = `*[_type == 'workout' && brand == '${brand}'] [0...5] {
251
+ "id": railcontent_id,
252
+ title,
253
+ "image": thumbnail.asset->url,
254
+ "artist_name": instructor[0]->name,
255
+ "artists": instructor[]->name,
256
+ difficulty,
257
+ difficulty_string,
258
+ length_in_seconds,
259
+ published_on,
260
+ "type": _type,
261
+ web_url_path,
262
+ } | order(published_on desc)[0...5]`
263
+ return fetchSanity(query, true);
314
264
  }
315
265
 
316
-
317
266
  /**
318
267
  * Fetch the latest new releases for a specific brand.
319
268
  * @param {string} brand - The brand for which to fetch new releases.
@@ -612,27 +561,29 @@ export async function fetchAllFilterOptions(
612
561
  contentType,
613
562
  term
614
563
  ) {
615
- const query = `
616
- {
617
- "meta": {
618
- "totalResults": count(*[_type == '${contentType}' && brand == "${brand}"${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''}${filters}
619
- ${term ? ` && (title match "${term}" || album match "${term}" || artist->name match "${term}" || genre[]->name match "${term}")` : ''}]),
620
- "filterOptions": {
621
- "difficulty": [
622
- {"type": "Introductory", "count": count(*[_type == '${contentType}' && brand == '${brand}'${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''} && difficulty_string == "Introductory"${filters}])},
623
- {"type": "Beginner", "count": count(*[_type == '${contentType}' && brand == '${brand}'${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''} && difficulty_string == "Beginner"${filters}])},
624
- {"type": "Intermediate", "count": count(*[_type == '${contentType}' && brand == '${brand}'${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''} && difficulty_string == "Intermediate"${filters}])},
625
- {"type": "Advanced", "count": count(*[_type == '${contentType}' && brand == '${brand}'${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''} && difficulty_string == "Advanced"${filters}])},
626
- {"type": "Expert", "count": count(*[_type == '${contentType}' && brand == '${brand}'${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''} && difficulty_string == "Expert"${filters}])}
627
- ][count > 0],
628
- "instrumentless": [
629
- {"type": "Full Song Only", "count": count(*[_type == '${contentType}' && brand == '${brand}'${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''} && instrumentless == false${filters}])},
630
- {"type": "Instrument Removed", "count": count(*[_type == '${contentType}' && brand == '${brand}'${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''} && instrumentless == true${filters}])}
631
- ][count > 0],
632
- "genre": *[_type == 'genre' && '${contentType}' in filter_types] {
633
- "type": name,
634
- "count": count(*[_type == '${contentType}' && brand == "${brand}"${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''} && references(^._id)])
635
- }[count > 0]
564
+ const commonFilter = `_type == '${contentType}' && brand == "${brand}"${style ? ` && '${style}' in genre[]->name` : ''}${artist ? ` && artist->name == '${artist}'` : ''} ${filters ? filters : ''}`;
565
+ const query = `
566
+ {
567
+ "meta": {
568
+ "totalResults": count(*[${commonFilter}
569
+ ${term ? ` && (title match "${term}" || album match "${term}" || artist->name match "${term}" || genre[]->name match "${term}")` : ''}]),
570
+ "filterOptions": {
571
+ "difficulty": [
572
+ {"type": "Introductory", "count": count(*[${commonFilter} && difficulty_string == "Introductory"])},
573
+ {"type": "Beginner", "count": count(*[${commonFilter} && difficulty_string == "Beginner"])},
574
+ {"type": "Intermediate", "count": count(*[${commonFilter} && difficulty_string == "Intermediate" ])},
575
+ {"type": "Advanced", "count": count(*[${commonFilter} && difficulty_string == "Advanced" ])},
576
+ {"type": "Expert", "count": count(*[${commonFilter} && difficulty_string == "Expert" ])}
577
+ ][count > 0],
578
+ "instrumentless": [
579
+ {"type": "Full Song Only", "count": count(*[${commonFilter} && instrumentless == false ])},
580
+ {"type": "Instrument Removed", "count": count(*[${commonFilter} && instrumentless == true ])}
581
+ ][count > 0],
582
+ "genre": *[_type == 'genre' && '${contentType}' in filter_types] {
583
+ "type": name,
584
+ "count": count(*[${commonFilter} && references(^._id)])
585
+ }[count > 0]
586
+ }
636
587
  }
637
588
  }
638
589
  }`;
@@ -866,10 +817,10 @@ export async function fetchSanity(query, isList) {
866
817
  if (globalConfig.sanityConfig.debug) {
867
818
  console.log("fetchSanity Query:", query);
868
819
  }
869
-
820
+ const perspective = globalConfig.sanityConfig.perspective ?? 'published';
870
821
  const encodedQuery = encodeURIComponent(query);
871
822
  const api = globalConfig.sanityConfig.useCachedAPI ? 'apicdn' : 'api';
872
- const url = `https://${globalConfig.sanityConfig.projectId}.${api}.sanity.io/v${globalConfig.sanityConfig.version}/data/query/${globalConfig.sanityConfig.dataset}?query=${encodedQuery}`;
823
+ const url = `https://${globalConfig.sanityConfig.projectId}.${api}.sanity.io/v${globalConfig.sanityConfig.version}/data/query/${globalConfig.sanityConfig.dataset}?perspective=${perspective}&query=${encodedQuery}`;
873
824
  const headers = {
874
825
  'Authorization': `Bearer ${globalConfig.sanityConfig.token}`,
875
826
  'Content-Type': 'application/json'