musora-content-services 1.0.138 → 1.0.139

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 (59) hide show
  1. package/.github/workflows/node.js.yml +0 -0
  2. package/CHANGELOG.md +2 -0
  3. package/README.md +0 -0
  4. package/babel.config.js +0 -0
  5. package/docs/config.js.html +0 -0
  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 +0 -0
  25. package/docs/module-Config.html +0 -0
  26. package/docs/module-Railcontent-Services.html +0 -0
  27. package/docs/module-Sanity-Services.html +0 -0
  28. package/docs/railcontent.js.html +0 -0
  29. package/docs/sanity.js.html +0 -0
  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/contentMetaData.js +0 -0
  46. package/src/contentTypeConfig.js +0 -0
  47. package/src/filterBuilder.js +0 -0
  48. package/src/index.d.ts +0 -0
  49. package/src/index.js +0 -0
  50. package/src/services/config.js +0 -0
  51. package/src/services/contentLikes.js +0 -0
  52. package/src/services/dataContext.js +0 -0
  53. package/src/services/railcontent.js +0 -0
  54. package/src/services/sanity.js +36 -20
  55. package/test/contentLikes.test.js +0 -0
  56. package/test/localStorageMock.js +0 -0
  57. package/test/log.js +0 -0
  58. package/test/sanityQueryService.test.js +38 -1
  59. package/tools/generate-index.js +0 -0
File without changes
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.139](https://github.com/railroadmedia/musora-content-services/compare/v1.0.137...v1.0.139) (2024-10-16)
6
+
5
7
  ### [1.0.138](https://github.com/railroadmedia/musora-content-services/compare/v1.0.137...v1.0.138) (2024-10-15)
6
8
 
7
9
  ### [1.0.137](https://github.com/railroadmedia/musora-content-services/compare/v1.0.136...v1.0.137) (2024-10-14)
package/README.md CHANGED
File without changes
package/babel.config.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/docs/index.html CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/jest.config.js CHANGED
File without changes
package/jsdoc.json CHANGED
File without changes
package/link_mcs.sh CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.138",
3
+ "version": "1.0.139",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
File without changes
File without changes
File without changes
package/src/index.d.ts CHANGED
File without changes
package/src/index.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -832,7 +832,7 @@ export async function fetchMethodNextLesson(railcontentId, methodId) {
832
832
  */
833
833
  export async function fetchMethodPreviousNextLesson(railcontentId, methodId) {
834
834
  const sortedChildren = await fetchMethodChildrenIds(methodId);
835
- const index = sortedChildren.indexOf(railcontentId);
835
+ const index = sortedChildren.indexOf(Number(railcontentId));
836
836
  let nextId = sortedChildren[index + 1];
837
837
  let previousId = sortedChildren[index -1];
838
838
  let nextPrev = await fetchByRailContentIds([nextId, previousId]);
@@ -847,13 +847,16 @@ export async function fetchMethodPreviousNextLesson(railcontentId, methodId) {
847
847
  * @returns {Promise<Array<Object>|null>} - The fetched children data or null if not found.
848
848
  */
849
849
  export async function fetchMethodChildrenIds(railcontentId) {
850
- const query = `*[_type == 'learning-path' && railcontent_id == ${railcontentId}]{
850
+ const query = `*[ railcontent_id == ${railcontentId}]{
851
851
  'children': child[]-> {
852
852
  'id': railcontent_id,
853
+ 'type' : _type,
853
854
  'children': child[]-> {
854
- 'id': railcontent_id,
855
- 'children': child[]-> {
856
855
  'id': railcontent_id,
856
+ 'type' : _type,
857
+ 'children': child[]-> {
858
+ 'id': railcontent_id,
859
+ 'type' : _type,
857
860
  }
858
861
  }
859
862
  }
@@ -865,9 +868,11 @@ export async function fetchMethodChildrenIds(railcontentId) {
865
868
  function getChildrenToDepth(parent, depth = 1)
866
869
  {
867
870
  let allChildrenIds = [];
868
- if (parent['children']) {
871
+ if (parent && parent['children'] && depth > 0) {
869
872
  parent['children'].forEach((child) => {
870
- allChildrenIds.push(child['id']);
873
+ if(!child['children']) {
874
+ allChildrenIds.push(child['id']);
875
+ }
871
876
  allChildrenIds = allChildrenIds.concat(getChildrenToDepth(child, depth-1));
872
877
  })
873
878
  }
@@ -880,19 +885,27 @@ function getChildrenToDepth(parent, depth = 1)
880
885
  * @returns {Promise<Object|null>} - The fetched next and previous lesson data or null if found.
881
886
  */
882
887
  export async function fetchNextPreviousLesson(railcontentId) {
883
- //TODO: Implement getTypeNeighbouringSiblings/getNextAndPreviousLessons
884
- const query = `*[_railcontent_id == ${railcontentId}]{
885
- railcontent_id,
886
- title,
887
- "image": thumbnail.asset->url,
888
- "artist_name": artist->name,
889
- artist,
890
- difficulty,
891
- difficulty_string,
892
- web_url_path,
893
- published_on
894
- }`
895
- return fetchSanity(query, false);
888
+ const document = await fetchLessonContent(railcontentId);
889
+ if (document.parent_content_data && document.parent_content_data.length > 0) {
890
+ const lastElement = document.parent_content_data[document.parent_content_data.length - 1];
891
+ const results = await fetchMethodPreviousNextLesson(railcontentId, lastElement.id);
892
+ return results;
893
+ }
894
+ const processedData = processMetadata(document.brand, document.type, true);
895
+ let sortBy = processedData?.sortBy ?? 'published_on';
896
+ const isDesc = sortBy.startsWith('-');
897
+ sortBy = isDesc ? sortBy.substring(1) : sortBy;
898
+ const sortValue = document[sortBy];
899
+ const isNumeric = !isNaN(sortValue);
900
+ let prevComparison = isNumeric ? `${sortBy} <= ${sortValue}` : `${sortBy} <= "${sortValue}"`;
901
+ let nextComparison = isNumeric ? `${sortBy} >= ${sortValue}` : `${sortBy} >= "${sortValue}"`;
902
+ const fields = getFieldsForContentType(document.type);
903
+ const query = `{
904
+ "prevLesson": *[brand == "${document.brand}" && status == "${document.status}" && _type == "${document.type}" && ${prevComparison} && railcontent_id != ${railcontentId}] | order(${sortBy} desc){${fields}}[0...1][0],
905
+ "nextLesson": *[brand == "${document.brand}" && status == "${document.status}" && _type == "${document.type}" && ${nextComparison} && railcontent_id != ${railcontentId}] | order(${sortBy} asc){${fields}}[0...1][0]
906
+ }`;
907
+
908
+ return await fetchSanity(query, true);
896
909
  }
897
910
 
898
911
  /**
@@ -914,6 +927,7 @@ export async function fetchLessonContent(railContentId) {
914
927
  difficulty,
915
928
  difficulty_string,
916
929
  brand,
930
+ status,
917
931
  soundslice,
918
932
  instrumentless,
919
933
  railcontent_id,
@@ -945,7 +959,9 @@ export async function fetchLessonContent(railContentId) {
945
959
  mp3_no_drums_yes_click_url,
946
960
  mp3_yes_drums_no_click_url,
947
961
  mp3_yes_drums_yes_click_url,
948
- "permission_id": permission[]->railcontent_id,`;
962
+ "permission_id": permission[]->railcontent_id,
963
+ parent_content_data,
964
+ sort`;
949
965
  const query = buildQuery(
950
966
  `railcontent_id == ${railContentId}`,
951
967
  filterParams,
File without changes
File without changes
package/test/log.js CHANGED
File without changes
@@ -35,7 +35,8 @@ const {
35
35
  fetchScheduledReleases,
36
36
  getSortOrder,
37
37
  fetchShowsData,
38
- fetchMetadata
38
+ fetchMetadata,
39
+ fetchNextPreviousLesson
39
40
  } = require('../src/services/sanity.js');
40
41
 
41
42
  const {
@@ -520,6 +521,42 @@ describe('Sanity Queries', function () {
520
521
  expect(response).toBeDefined();
521
522
  });
522
523
 
524
+ test('fetchNextPreviousLesson-Show-With-Episodes', async () => {
525
+ const id = 227136;
526
+ const document = await fetchByRailContentId(id, 'behind-the-scenes');
527
+ const response = await fetchNextPreviousLesson(id);
528
+ log(response);
529
+ expect(response.prevLesson).toBeDefined();
530
+ expect(response.prevLesson.sort).toBeLessThanOrEqual(document.sort);
531
+ expect(response.nextLesson).toBeDefined();
532
+ expect(response.nextLesson.sort).toBeGreaterThanOrEqual(document.sort);
533
+ });
534
+
535
+ test('fetchNextPreviousLesson-Method-Lesson', async () => {
536
+ const id = 241265;
537
+ const response = await fetchNextPreviousLesson(id);
538
+ log(response);
539
+ expect(response.prevLesson).toBeDefined();
540
+ expect(response.prevLesson.id).toBe(241264);
541
+ expect(response.prevLesson.type).toBe('learning-path-lesson');
542
+ expect(response.nextLesson).toBeDefined();
543
+ expect(response.nextLesson.id).toBe(241267);
544
+ expect(response.nextLesson.type).toBe('learning-path-lesson');
545
+ });
546
+
547
+ test('fetchNextPreviousLesson-Quick-Tips', async () => {
548
+ const id = 412277;
549
+ const response = await fetchNextPreviousLesson(id);
550
+ const document = await fetchByRailContentId(id, 'quick-tips');
551
+ const documentPublishedOn = new Date(document.published_on);
552
+ const prevDocumentPublishedOn = new Date(response.prevLesson.published_on);
553
+ const nextDocumentPublishedOn = new Date(response.nextLesson.published_on);
554
+ expect(response.prevLesson).toBeDefined();
555
+ expect(prevDocumentPublishedOn.getTime()).toBeLessThan(documentPublishedOn.getTime());
556
+ expect(response.nextLesson).toBeDefined();
557
+ expect(documentPublishedOn.getTime()).toBeLessThan(nextDocumentPublishedOn.getTime());
558
+ });
559
+
523
560
  });
524
561
 
525
562
  describe('Filter Builder', function () {
File without changes