musora-content-services 2.21.1 → 2.21.3

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,21 @@
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
+ ### [2.21.3](https://github.com/railroadmedia/musora-content-services/compare/v2.21.1...v2.21.3) (2025-07-15)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * MU2-787 Leaving Soon and Returning should only be set in the future ([4bb48c9](https://github.com/railroadmedia/musora-content-services/commit/4bb48c93afa7b2167d94c306830a4db3e7dab810))
11
+ * **systest:** patch contentAggregator ([#342](https://github.com/railroadmedia/musora-content-services/issues/342)) ([4a1906e](https://github.com/railroadmedia/musora-content-services/commit/4a1906ed8e5cfc3cebf3e044d4eb35213d18ebe1))
12
+
13
+ ### [2.21.2](https://github.com/railroadmedia/musora-content-services/compare/v2.21.1...v2.21.2) (2025-07-14)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * **systest:** patch contentAggregator ([#342](https://github.com/railroadmedia/musora-content-services/issues/342)) ([4a1906e](https://github.com/railroadmedia/musora-content-services/commit/4a1906ed8e5cfc3cebf3e044d4eb35213d18ebe1))
19
+
5
20
  ### [2.21.1](https://github.com/railroadmedia/musora-content-services/compare/v2.21.0...v2.21.1) (2025-07-14)
6
21
 
7
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "2.21.1",
3
+ "version": "2.21.3",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -571,6 +571,12 @@ export let contentTypeConfig = {
571
571
  `quarter_published`,
572
572
  '"thumbnail": thumbnail.asset->url',
573
573
  ]
574
+ },
575
+ leaving: {
576
+ fields: [
577
+ `quarter_removed`,
578
+ '"thumbnail": thumbnail.asset->url',
579
+ ]
574
580
  }
575
581
  }
576
582
 
package/src/index.d.ts CHANGED
File without changes
package/src/index.js CHANGED
File without changes
File without changes
File without changes
@@ -33,15 +33,14 @@ export async function addContextToContent(dataPromise, ...dataArgs)
33
33
  if(!data) return false
34
34
 
35
35
  let items = []
36
- let dataMap = []
37
36
 
38
37
  if (dataField && (data?.[dataField] || iterateDataFieldOnEachArrayElement)) {
39
38
  if (iterateDataFieldOnEachArrayElement && Array.isArray(data)) {
40
39
  for(const parent of data) {
41
- ids = [...ids, ...parent[dataField].map(item => item?.id).filter(Boolean)]
40
+ items = [...items, ...parent[dataField]]
42
41
  }
43
42
  } else {
44
- ids = data[dataField].map(item => item?.id).filter(Boolean);
43
+ items = data[dataField]
45
44
  }
46
45
  } else if (Array.isArray(data)) {
47
46
  items = data;
@@ -51,19 +50,6 @@ export async function addContextToContent(dataPromise, ...dataArgs)
51
50
 
52
51
  const ids = items.map(item => item?.id).filter(Boolean)
53
52
 
54
- //create data structure for common use by functions
55
- if (addNextLesson) {
56
- items.forEach((item) => {
57
- if (item?.id) {
58
- dataMap.push({
59
- 'children': item.children?.map(child => child.id) ?? [],
60
- 'type': item.type,
61
- 'id': item.id,
62
- })
63
- }
64
- })
65
- }
66
-
67
53
  if(ids.length === 0) return false
68
54
 
69
55
  const [progressPercentageData, progressStatusData, isLikedData, resumeTimeData, lastInteractedChildData, nextLessonData] = await Promise.all([
@@ -72,7 +58,7 @@ export async function addContextToContent(dataPromise, ...dataArgs)
72
58
  addIsLiked ? isContentLikedByIds(ids) : Promise.resolve(null),
73
59
  addResumeTimeSeconds ? getResumeTimeSecondsByIds(ids) : Promise.resolve(null),
74
60
  addLastInteractedChild ? fetchLastInteractedChild(ids) : Promise.resolve(null),
75
- (addNextLesson || addLastInteractedParent) ? getNextLesson(dataMap) : Promise.resolve(null),
61
+ (addNextLesson || addLastInteractedParent) ? getNextLesson(items) : Promise.resolve(null),
76
62
  ])
77
63
 
78
64
  const addContext = async (item) => ({
@@ -44,12 +44,12 @@ export async function getResumeTimeSecondsByIds(contentIds) {
44
44
  return getByIds(contentIds, DATA_KEY_RESUME_TIME, 0)
45
45
  }
46
46
 
47
- export async function getNextLesson(dataMap)
47
+ export async function getNextLesson(data)
48
48
  {
49
49
  let nextLessonData = {}
50
50
 
51
- for (const content of dataMap) {
52
-
51
+ for (const content of data) {
52
+ const children = content.children?.map(child => child.id) ?? []
53
53
  //only calculate nextLesson if needed, based on content type
54
54
  if (!getNextLessonLessonParentTypes.includes(content.type)) {
55
55
  nextLessonData[content.id] = null
@@ -58,15 +58,15 @@ export async function getNextLesson(dataMap)
58
58
  //return first child if parent-content is complete or no progress
59
59
  const contentState = await getProgressState(content.id)
60
60
  if (contentState !== STATE_STARTED) {
61
- nextLessonData[content.id] = content.children[0]
61
+ nextLessonData[content.id] = children[0]
62
62
 
63
63
  } else {
64
64
  //if content in progress
65
65
 
66
- const childrenStates = await getProgressStateByIds(content.children)
66
+ const childrenStates = await getProgressStateByIds(children)
67
67
 
68
68
  //calculate last_engaged
69
- const lastInteracted = await getLastInteractedOf(content.children)
69
+ const lastInteracted = await getLastInteractedOf(children)
70
70
  const lastInteractedStatus = childrenStates[lastInteracted]
71
71
 
72
72
  //different nextLesson behaviour for different content types
File without changes
@@ -73,18 +73,19 @@ export async function fetchSongById(documentId) {
73
73
  * @returns {Promise<Object|null>}
74
74
  */
75
75
  export async function fetchLeaving(brand, { pageNumber = 1, contentPerPage = 20 } = {}) {
76
- const nextQuarter = getNextAndPreviousQuarterDates()['next']
77
- const filterString = `brand == '${brand}' && quarter_removed == '${nextQuarter}'`
76
+ const today = new Date()
77
+ const isoDateOnly = today.toISOString().split('T')[0]
78
+ const filterString = `brand == '${brand}' && quarter_removed > '${isoDateOnly}'`
78
79
  const startEndOrder = getQueryFromPage(pageNumber, contentPerPage)
79
80
  const sortOrder = {
80
- sortOrder: 'published_on desc, id desc',
81
+ sortOrder: 'quarter_removed asc, published_on desc, id desc',
81
82
  start: startEndOrder['start'],
82
83
  end: startEndOrder['end'],
83
84
  }
84
85
  const query = await buildQuery(
85
86
  filterString,
86
87
  { pullFutureContent: false, availableContentStatuses: ['published'] },
87
- getFieldsForContentType(),
88
+ getFieldsForContentType('leaving'),
88
89
  sortOrder
89
90
  )
90
91
  return fetchSanity(query, true)
@@ -99,11 +100,12 @@ export async function fetchLeaving(brand, { pageNumber = 1, contentPerPage = 20
99
100
  * @returns {Promise<Object|null>}
100
101
  */
101
102
  export async function fetchReturning(brand, { pageNumber = 1, contentPerPage = 20 } = {}) {
102
- const nextQuarter = getNextAndPreviousQuarterDates()['next']
103
- const filterString = `brand == '${brand}' && quarter_published == '${nextQuarter}'`
103
+ const today = new Date()
104
+ const isoDateOnly = today.toISOString().split('T')[0]
105
+ const filterString = `brand == '${brand}' && quarter_published >= '${isoDateOnly}'`
104
106
  const startEndOrder = getQueryFromPage(pageNumber, contentPerPage)
105
107
  const sortOrder = {
106
- sortOrder: 'published_on desc, id desc',
108
+ sortOrder: 'quarter_published asc, published_on desc, id desc',
107
109
  start: startEndOrder['start'],
108
110
  end: startEndOrder['end'],
109
111
  }
File without changes