musora-content-services 1.0.9 → 1.0.11

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 (32) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  3. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  4. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  5. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  6. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  7. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  8. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  9. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  10. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  11. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  12. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  13. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  14. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  15. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  16. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  17. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  18. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  19. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  20. package/docs/global.html +947 -933
  21. package/docs/index.html +27 -9
  22. package/docs/index.js.html +147 -51
  23. package/docs/scripts/collapse.js +39 -0
  24. package/docs/scripts/commonNav.js +28 -0
  25. package/docs/scripts/nav.js +12 -0
  26. package/docs/scripts/polyfill.js +4 -0
  27. package/docs/scripts/search.js +99 -265
  28. package/docs/styles/jsdoc.css +776 -0
  29. package/docs/styles/prettify.css +80 -0
  30. package/jsdoc.json +1 -1
  31. package/package.json +5 -4
  32. package/src/index.js +127 -43
@@ -0,0 +1,80 @@
1
+ .pln {
2
+ color: #ddd;
3
+ }
4
+
5
+ /* string content */
6
+ .str {
7
+ color: #61ce3c;
8
+ }
9
+
10
+ /* a keyword */
11
+ .kwd {
12
+ color: #fbde2d;
13
+ }
14
+
15
+ /* a comment */
16
+ .com {
17
+ color: #aeaeae;
18
+ }
19
+
20
+ /* a type name */
21
+ .typ {
22
+ color: #8da6ce;
23
+ }
24
+
25
+ /* a literal value */
26
+ .lit {
27
+ color: #fbde2d;
28
+ }
29
+
30
+ /* punctuation */
31
+ .pun {
32
+ color: #ddd;
33
+ }
34
+
35
+ /* lisp open bracket */
36
+ .opn {
37
+ color: #000000;
38
+ }
39
+
40
+ /* lisp close bracket */
41
+ .clo {
42
+ color: #000000;
43
+ }
44
+
45
+ /* a markup tag name */
46
+ .tag {
47
+ color: #8da6ce;
48
+ }
49
+
50
+ /* a markup attribute name */
51
+ .atn {
52
+ color: #fbde2d;
53
+ }
54
+
55
+ /* a markup attribute value */
56
+ .atv {
57
+ color: #ddd;
58
+ }
59
+
60
+ /* a declaration */
61
+ .dec {
62
+ color: #EF5050;
63
+ }
64
+
65
+ /* a variable name */
66
+ .var {
67
+ color: #c82829;
68
+ }
69
+
70
+ /* a function name */
71
+ .fun {
72
+ color: #4271ae;
73
+ }
74
+
75
+ /* Specify class=linenums on a pre to get line numbering */
76
+ ol.linenums {
77
+ margin-top: 0;
78
+ margin-bottom: 0;
79
+ padding-bottom: 2px;
80
+ }
package/jsdoc.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "opts": {
8
8
  "destination": "./docs",
9
9
  "recurse": true,
10
- "template": "node_modules/minami",
10
+ "template": "node_modules/docdash",
11
11
  "readme": "./README.md"
12
12
  }
13
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -22,8 +22,9 @@
22
22
  "dotenv": "^16.4.5",
23
23
  "jest": "^29.7.0",
24
24
  "jsdoc": "^4.0.3",
25
- "minami": "^1.2.3",
26
- "standard-version": "^9.5.0",
27
- "taffydb": "^2.7.3"
25
+ "standard-version": "^9.5.0"
26
+ },
27
+ "dependencies": {
28
+ "docdash": "^2.0.2"
28
29
  }
29
30
  }
package/src/index.js CHANGED
@@ -10,7 +10,8 @@ let globalConfig = {};
10
10
  * @param {string} config.dataset - The dataset name in Sanity.
11
11
  * @param {string} config.version - The API version to use.
12
12
  * @param {boolean} [config.debug=false] - Optional flag to enable debug mode, which logs the query and results.
13
- * @param {boolean} [config.useCachedAPI=true] - Optional flag to disable cached API. *
13
+ * @param {boolean} [config.useCachedAPI=true] - Optional flag to disable cached API.
14
+ *
14
15
  * @example
15
16
  * // Initialize the Sanity service in your app.js
16
17
  * initializeSanityService({
@@ -18,7 +19,7 @@ let globalConfig = {};
18
19
  * projectId: 'your-sanity-project-id',
19
20
  * dataset: 'your-dataset-name',
20
21
  * version: '2021-06-07',
21
- * debug: true // Optional: Enable debug mode
22
+ * debug: true, // Optional: Enable debug mode
22
23
  * useCachedAPI: true // Optional: Use cached API
23
24
  * });
24
25
  */
@@ -28,8 +29,14 @@ function initializeSanityService(config) {
28
29
 
29
30
  /**
30
31
  * Fetch a song by its document ID from Sanity.
32
+ *
31
33
  * @param {string} documentId - The ID of the document to fetch.
32
- * @returns {Promise<Object|null>} - The fetched song data or null if not found.
34
+ * @returns {Promise<Object|null>} - A promise that resolves to an object containing the song data or null if not found.
35
+ *
36
+ * @example
37
+ * fetchSongById('abc123')
38
+ * .then(song => console.log(song))
39
+ * .catch(error => console.error(error));
33
40
  */
34
41
  async function fetchSongById(documentId) {
35
42
  const fields = [
@@ -53,8 +60,14 @@ async function fetchSongById(documentId) {
53
60
 
54
61
  /**
55
62
  * Fetch all artists with lessons available for a specific brand.
63
+ *
56
64
  * @param {string} brand - The brand for which to fetch artists.
57
- * @returns {Promise<Object|null>} - The fetched artist data or null if not found.
65
+ * @returns {Promise<Object|null>} - A promise that resolves to an array of artist objects or null if not found.
66
+ *
67
+ * @example
68
+ * fetchArtists('drumeo')
69
+ * .then(artists => console.log(artists))
70
+ * .catch(error => console.error(error));
58
71
  */
59
72
  async function fetchArtists(brand) {
60
73
  const query = `
@@ -77,9 +90,15 @@ async function fetchSongArtistCount(brand) {
77
90
 
78
91
  /**
79
92
  * Fetch related songs for a specific brand and song ID.
93
+ *
80
94
  * @param {string} brand - The brand for which to fetch related songs.
81
95
  * @param {string} songId - The ID of the song to find related songs for.
82
- * @returns {Promise<Object|null>} - The fetched related songs data or null if not found.
96
+ * @returns {Promise<Object|null>} - A promise that resolves to an array of related song objects or null if not found.
97
+ *
98
+ * @example
99
+ * fetchRelatedSongs('drumeo', '12345')
100
+ * .then(relatedSongs => console.log(relatedSongs))
101
+ * .catch(error => console.error(error));
83
102
  */
84
103
  async function fetchRelatedSongs(brand, songId) {
85
104
  const query = `
@@ -160,6 +179,18 @@ async function fetchRelatedSongs(brand, songId) {
160
179
  * @param {Array<string>} [params.includedFields=[]] - The fields to include in the query.
161
180
  * @param {string} [params.groupBy=""] - The field to group the results by.
162
181
  * @returns {Promise<Object|null>} - The fetched song data or null if not found.
182
+ *
183
+ * @example
184
+ * fetchAllSongs('drumeo', {
185
+ * page: 2,
186
+ * limit: 20,
187
+ * searchTerm: 'rock',
188
+ * sort: 'published_on',
189
+ * includedFields: ['difficulty', 'style'],
190
+ * groupBy: 'artist'
191
+ * })
192
+ * .then(result => console.log(result))
193
+ * .catch(error => console.error(error));
163
194
  */
164
195
  async function fetchAllSongs(brand, {
165
196
  page = 1,
@@ -291,8 +322,14 @@ async function fetchAllSongs(brand, {
291
322
 
292
323
  /**
293
324
  * Fetch filter options for a specific brand.
325
+ *
294
326
  * @param {string} brand - The brand for which to fetch filter options.
295
- * @returns {Promise<Object|null>} - The fetched filter options or null if not found.
327
+ * @returns {Promise<Object|null>} - A promise that resolves to an object containing filter options or null if not found.
328
+ *
329
+ * @example
330
+ * fetchSongFilterOptions('drumeo')
331
+ * .then(options => console.log(options))
332
+ * .catch(error => console.error(error));
296
333
  */
297
334
  async function fetchSongFilterOptions(brand) {
298
335
  const query = `
@@ -378,8 +415,14 @@ async function fetchNewReleases(brand) {
378
415
 
379
416
  /**
380
417
  * Fetch upcoming events for a specific brand.
418
+ *
381
419
  * @param {string} brand - The brand for which to fetch upcoming events.
382
- * @returns {Promise<Object|null>} - The fetched upcoming events data or null if not found.
420
+ * @returns {Promise<Object|null>} - A promise that resolves to an array of upcoming event objects or null if not found.
421
+ *
422
+ * @example
423
+ * fetchUpcomingEvents('drumeo')
424
+ * .then(events => console.log(events))
425
+ * .catch(error => console.error(error));
383
426
  */
384
427
  async function fetchUpcomingEvents(brand) {
385
428
  const liveTypes = {
@@ -408,8 +451,14 @@ async function fetchUpcomingEvents(brand) {
408
451
 
409
452
  /**
410
453
  * Fetch content by a specific Railcontent ID.
454
+ *
411
455
  * @param {string} id - The Railcontent ID of the content to fetch.
412
- * @returns {Promise<Object|null>} - The fetched content data or null if not found.
456
+ * @returns {Promise<Object|null>} - A promise that resolves to the content object or null if not found.
457
+ *
458
+ * @example
459
+ * fetchByRailContentId('abc123')
460
+ * .then(content => console.log(content))
461
+ * .catch(error => console.error(error));
413
462
  */
414
463
  async function fetchByRailContentId(id) {
415
464
  const query = `*[railcontent_id == ${id}]{
@@ -428,8 +477,14 @@ async function fetchByRailContentId(id) {
428
477
 
429
478
  /**
430
479
  * Fetch content by an array of Railcontent IDs.
480
+ *
431
481
  * @param {Array<string>} ids - The array of Railcontent IDs of the content to fetch.
432
- * @returns {Promise<Array<Object>|null>} - The fetched content data or null if not found.
482
+ * @returns {Promise<Array<Object>|null>} - A promise that resolves to an array of content objects or null if not found.
483
+ *
484
+ * @example
485
+ * fetchByRailContentIds(['abc123', 'def456', 'ghi789'])
486
+ * .then(contents => console.log(contents))
487
+ * .catch(error => console.error(error));
433
488
  */
434
489
  async function fetchByRailContentIds(ids) {
435
490
  const idsString = ids.join(',');
@@ -459,6 +514,18 @@ async function fetchByRailContentIds(ids) {
459
514
  * @param {Array<string>} [params.includedFields=[]] - The fields to include in the query.
460
515
  * @param {string} [params.groupBy=""] - The field to group the results by (e.g., 'artist', 'genre').
461
516
  * @returns {Promise<Object|null>} - The fetched content data or null if not found.
517
+ *
518
+ * @example
519
+ * fetchAll('drumeo', 'song', {
520
+ * page: 2,
521
+ * limit: 20,
522
+ * searchTerm: 'jazz',
523
+ * sort: '-popularity',
524
+ * includedFields: ['difficulty,Intermediate'],
525
+ * groupBy: 'artist'
526
+ * })
527
+ * .then(content => console.log(content))
528
+ * .catch(error => console.error(error));
462
529
  */
463
530
  async function fetchAll(brand, type, {
464
531
  page = 1,
@@ -718,6 +785,11 @@ async function fetchNextPreviousLesson(railcontentId) {
718
785
  * Fetch the page data for a specific lesson by Railcontent ID.
719
786
  * @param {string} railContentId - The Railcontent ID of the current lesson.
720
787
  * @returns {Promise<Object|null>} - The fetched page data or null if found.
788
+ *
789
+ * @example
790
+ * fetchLessonContent('lesson123')
791
+ * .then(data => console.log(data))
792
+ * .catch(error => console.error(error));
721
793
  */
722
794
  async function fetchLessonContent(railContentId) {
723
795
  const query = `*[railcontent_id == ${railContentId} ]
@@ -793,6 +865,11 @@ async function fetchPackAll(railcontentId) {
793
865
  * Fetch all children of a specific pack by Railcontent ID.
794
866
  * @param {string} railcontentId - The Railcontent ID of the pack.
795
867
  * @returns {Promise<Array<Object>|null>} - The fetched pack children data or null if not found.
868
+ *
869
+ * @example
870
+ * fetchPackChildren('pack123')
871
+ * .then(children => console.log(children))
872
+ * .catch(error => console.error(error));
796
873
  */
797
874
  async function fetchPackChildren(railcontentId) {
798
875
  return fetchChildren(railcontentId, 'pack');
@@ -800,43 +877,50 @@ async function fetchPackChildren(railcontentId) {
800
877
 
801
878
  /**
802
879
  * Fetch data from the Sanity API based on a provided query.
880
+ *
803
881
  * @param {string} query - The GROQ query to execute against the Sanity API.
804
- * @param {boolean} isList - Whether to return an array or single result
805
- * @returns {Promise<Object|null>} - The first result from the query, or null if an error occurs or no results are found.
882
+ * @param {boolean} isList - Whether to return an array or a single result.
883
+ * @returns {Promise<Object|null>} - A promise that resolves to the fetched data or null if an error occurs or no results are found.
884
+ *
885
+ * @example
886
+ * const query = `*[_type == "song"]{title, artist->name}`;
887
+ * fetchSanity(query, true)
888
+ * .then(data => console.log(data))
889
+ * .catch(error => console.error(error));
806
890
  */
807
891
  async function fetchSanity(query, isList) {
808
- // Check the config object before proceeding
809
- if (!checkConfig(globalConfig)) {
810
- return null;
811
- }
812
-
813
- if (globalConfig.debug) {
814
- console.log("fetchSanity Query:", query);
815
- }
816
-
817
- const encodedQuery = encodeURIComponent(query);
818
- const api = globalConfig.useCachedAPI ? 'apicdn' : 'api'
819
- const url = `https://${globalConfig.projectId}.${api}.sanity.io/v${globalConfig.version}/data/query/${globalConfig.dataset}?query=${encodedQuery}`;
820
- const headers = {
821
- 'Authorization': `Bearer ${globalConfig.token}`,
822
- 'Content-Type': 'application/json'
823
- };
824
-
825
- try {
826
- const response = await fetch(url, {headers});
827
- const result = await response.json();
828
- if (result.result) {
829
- if (globalConfig.debug) {
830
- console.log("fetchSanity Results:", result);
831
- }
832
- return isList ? result.result : result.result[0];
833
- } else {
834
- throw new Error('No results found');
835
- }
836
- } catch (error) {
837
- console.error('fetchSanity: Fetch error:', error);
838
- return null;
839
- }
892
+ // Check the config object before proceeding
893
+ if (!checkConfig(globalConfig)) {
894
+ return null;
895
+ }
896
+
897
+ if (globalConfig.debug) {
898
+ console.log("fetchSanity Query:", query);
899
+ }
900
+
901
+ const encodedQuery = encodeURIComponent(query);
902
+ const api = globalConfig.useCachedAPI ? 'apicdn' : 'api'
903
+ const url = `https://${globalConfig.projectId}.${api}.sanity.io/v${globalConfig.version}/data/query/${globalConfig.dataset}?query=${encodedQuery}`;
904
+ const headers = {
905
+ 'Authorization': `Bearer ${globalConfig.token}`,
906
+ 'Content-Type': 'application/json'
907
+ };
908
+
909
+ try {
910
+ const response = await fetch(url, {headers});
911
+ const result = await response.json();
912
+ if (result.result) {
913
+ if (globalConfig.debug) {
914
+ console.log("fetchSanity Results:", result);
915
+ }
916
+ return isList ? result.result : result.result[0];
917
+ } else {
918
+ throw new Error('No results found');
919
+ }
920
+ } catch (error) {
921
+ console.error('fetchSanity: Fetch error:', error);
922
+ return null;
923
+ }
840
924
  }
841
925
 
842
926