musora-content-services 1.0.207 → 1.0.209

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.209](https://github.com/railroadmedia/musora-content-services/compare/v1.0.208...v1.0.209) (2024-12-02)
6
+
7
+ ### [1.0.208](https://github.com/railroadmedia/musora-content-services/compare/v1.0.207...v1.0.208) (2024-12-02)
8
+
5
9
  ### [1.0.207](https://github.com/railroadmedia/musora-content-services/compare/v1.0.198...v1.0.207) (2024-12-02)
6
10
 
7
11
  ### [1.0.206](https://github.com/railroadmedia/musora-content-services/compare/v1.0.205...v1.0.206) (2024-12-01)
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.207",
3
+ "version": "1.0.209",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -61,10 +61,12 @@ export class FilterBuilder {
61
61
  if (this.availableContentStatuses.length === 0) {
62
62
  if (this.userData.isAdmin) {
63
63
  this.availableContentStatuses = [this.STATUS_DRAFT, this.STATUS_SCHEDULED, this.STATUS_PUBLISHED, this.STATUS_ARCHIVED, this.STATUS_UNLISTED];
64
+ this.getFutureScheduledContentsOnly = true;
64
65
  } else if(this.isSingle){
65
66
  this.availableContentStatuses = [this.STATUS_SCHEDULED, this.STATUS_PUBLISHED, this.STATUS_UNLISTED, this.STATUS_ARCHIVED];
66
67
  } else{
67
68
  this.availableContentStatuses = [this.STATUS_SCHEDULED, this.STATUS_PUBLISHED];
69
+ this.getFutureScheduledContentsOnly = true;
68
70
  }
69
71
  }
70
72
 
@@ -74,8 +76,8 @@ export class FilterBuilder {
74
76
  this.pullFutureContent = true;
75
77
  const now = new Date().toISOString();
76
78
  let statuses = [...this.availableContentStatuses];
77
- statuses.splice(statuses.indexOf(this.STATUS_SCHEDULED));
78
- this._andWhere(`(status in ${arrayToStringRepresentation(statuses)} || (status == '${this.STATUS_SCHEDULED}' && published_on >= '${now}'))`)
79
+ statuses.splice(statuses.indexOf(this.STATUS_SCHEDULED), 1);
80
+ this._andWhere(`(status in ${arrayToStringRepresentation(statuses)} || (status == '${this.STATUS_SCHEDULED}' && defined(published_on) && published_on >= '${now}'))`)
79
81
 
80
82
  } else {
81
83
  this._andWhere(`status in ${arrayToStringRepresentation(this.availableContentStatuses)}`);
@@ -86,8 +88,7 @@ export class FilterBuilder {
86
88
  _applyPermissions() {
87
89
  if (this.bypassPermissions || this.userData.isAdmin) return this;
88
90
  const requiredPermissions = this._getUserPermissions();
89
- if (requiredPermissions.length === 0) return this;
90
- this._andWhere(`references(*[_type == 'permission' && railcontent_id in ${arrayToRawRepresentation(requiredPermissions)}]._id)`);
91
+ this._andWhere(`(!defined(permission) || references(*[_type == 'permission' && railcontent_id in ${arrayToRawRepresentation(requiredPermissions)}]._id))`);
91
92
  return this;
92
93
  }
93
94
 
@@ -146,4 +147,4 @@ export function arrayToStringRepresentation(arr) {
146
147
 
147
148
  export function arrayToRawRepresentation(arr) {
148
149
  return '[' + arr.map(item => `${item}`).join(',') + ']';
149
- }
150
+ }
package/src/index.d.ts CHANGED
File without changes
package/src/index.js CHANGED
File without changes
File without changes
@@ -1160,7 +1160,7 @@ export async function fetchLessonContent(railContentId) {
1160
1160
  * @returns {Promise<Array<Object>|null>} - The fetched related lessons data or null if not found.
1161
1161
  */
1162
1162
  export async function fetchRelatedLessons(railContentId, brand) {
1163
- const query = `*[railcontent_id == ${railContentId} && brand == "${brand}" && references(*[_type=='permission']._id)]{
1163
+ const query = `*[railcontent_id == ${railContentId} && brand == "${brand}" && (!defined(permission) || references(*[_type=='permission']._id))]{
1164
1164
  _type, parent_type, railcontent_id,
1165
1165
  "related_lessons" : array::unique([
1166
1166
  ...(*[references(^._id)][0].child[]->{_id, "id":railcontent_id, published_on, "instructor": instructor[0]->name, title, "thumbnail_url":thumbnail.asset->url, length_in_seconds, web_url_path, "type": _type, difficulty, difficulty_string, railcontent_id, artist->,"permission_id": permission[]->railcontent_id,_type}),
@@ -683,16 +683,16 @@ describe('Filter Builder', function () {
683
683
  let finalFilter = await builder.buildFilter(filter);
684
684
  let clauses = spliceFilterForAnds(finalFilter);
685
685
  expect(clauses[0].phrase).toBe(filter);
686
- expect(clauses[1].field).toBe('status');
687
- expect(clauses[2].field).toBe('published_on');
686
+ expect(clauses[1].field).toBe('(status');
687
+ expect(clauses[3].field).toBe('published_on');
688
688
 
689
689
  builder = new FilterBuilder('', {bypassPermissions: true});
690
690
  finalFilter = await builder.buildFilter(filter);
691
691
  clauses = spliceFilterForAnds(finalFilter);
692
- expect(clauses[0].field).toBe('status');
692
+ expect(clauses[0].field).toBe('(status');
693
693
  expect(clauses[0].operator).toBe('in');
694
- expect(clauses[1].field).toBe('published_on');
695
- expect(clauses[1].operator).toBe('<=');
694
+ expect(clauses[2].field).toBe('published_on');
695
+ expect(clauses[2].operator).toBe('>=');
696
696
  });
697
697
 
698
698
  test('withOnlyFilterAvailableStatuses', async () => {
@@ -720,7 +720,7 @@ describe('Filter Builder', function () {
720
720
  expect(clauses[1].field).toBe('(status'); // extra ( because it's a multi part filter
721
721
  expect(clauses[1].operator).toBe('in');
722
722
  // getFutureScheduledContentsOnly doesn't make a filter that's splicable, so we match on the more static string
723
- const expected = "['published','unlisted'] || (status == 'scheduled' && published_on >=";
723
+ const expected = "['published','unlisted'] || (status == 'scheduled' && defined(published_on) && published_on >=";
724
724
  const isMatch = finalFilter.includes(expected);
725
725
  expect(isMatch).toBeTruthy();
726
726
  });
@@ -747,7 +747,8 @@ describe('Filter Builder', function () {
747
747
  const filter = 'railcontent_id = 111'
748
748
  const builder = new FilterBuilder(filter,
749
749
  {
750
- bypassPermissions: true
750
+ bypassPermissions: true,
751
+ pullFutureContent: false
751
752
  });
752
753
  const finalFilter = await builder.buildFilter();
753
754
  const expected = "references(*[_type == 'permission' && railcontent_id in [78,91,92]]._id)"
@@ -755,8 +756,8 @@ describe('Filter Builder', function () {
755
756
  expect(isMatch).toBeFalsy();
756
757
  const clauses = spliceFilterForAnds(finalFilter);
757
758
  expect(clauses[0].field).toBe('railcontent_id');
758
- expect(clauses[1].field).toBe('status');
759
- expect(clauses[2].field).toBe('published_on');
759
+ expect(clauses[1].field).toBe('(status');
760
+ expect(clauses[3].field).toBe('published_on');
760
761
 
761
762
  });
762
763
 
@@ -773,13 +774,10 @@ describe('Filter Builder', function () {
773
774
  let finalFilter = await builder.buildFilter();
774
775
  let clauses = spliceFilterForAnds(finalFilter);
775
776
  expect(clauses[0].phrase).toBe(filter);
776
- expect(clauses[1].field).toBe('status');
777
+ expect(clauses[1].field).toBe('(status');
777
778
  expect(clauses[1].operator).toBe('in');
778
- expect(clauses[2].field).toBe('published_on');
779
- expect(clauses[2].operator).toBe('<=');
780
- const restrictionDate = new Date(clauses[2].condition)
781
- const now = new Date();
782
- expect(now.getTime()).toBeLessThan(restrictionDate.getTime());
779
+ expect(clauses[2].phrase).toBe('defined(published_on)');
780
+ expect(clauses[3].field).toBe('published_on');
783
781
 
784
782
  builder = new FilterBuilder(filter,
785
783
  {
@@ -789,8 +787,8 @@ describe('Filter Builder', function () {
789
787
  finalFilter = await builder.buildFilter();
790
788
  clauses = spliceFilterForAnds(finalFilter);
791
789
  expect(clauses[0].phrase).toBe(filter);
792
- expect(clauses[2].field).toBe('published_on');
793
- expect(clauses[2].operator).toBe('>=');
790
+ expect(clauses[3].field).toBe('published_on');
791
+ expect(clauses[3].operator).toBe('>=');
794
792
  });
795
793
 
796
794
  function spliceFilterForAnds(filter) {