musora-content-services 2.167.1 → 2.167.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.
Files changed (136) hide show
  1. package/.agent/decisions/2026-07-17-onboarding-statuses.md +21 -0
  2. package/.agent/decisions/2026-07-20-mu2-1724-songs-lessons-counts.md +33 -0
  3. package/.agent/decisions/2026-07-20-query-builder-tostring.md +37 -0
  4. package/CHANGELOG.md +15 -0
  5. package/package.json +2 -1
  6. package/src/contentTypeConfig.js +2 -0
  7. package/src/index.d.ts +2 -0
  8. package/src/index.js +2 -0
  9. package/src/lib/sanity/query.ts +5 -0
  10. package/src/services/config.js +15 -0
  11. package/src/services/content/artist.ts +1 -3
  12. package/src/services/content/counts.ts +47 -0
  13. package/src/services/content/genre.ts +1 -3
  14. package/src/services/content/instructor.ts +1 -3
  15. package/src/services/contentProgress.js +1 -1
  16. package/src/services/eventsAPI.js +49 -7
  17. package/src/services/user/onboarding.ts +22 -0
  18. package/src/services/userActivity.js +2 -0
  19. package/src/version-info.js +1 -0
  20. package/.claude/settings.local.json +0 -52
  21. package/test/initializeTests.js +0 -60
  22. package/test/integration/awards/award-exclusion-handling.test.ts +0 -275
  23. package/test/integration/awards/internal/image-utils.test.ts +0 -86
  24. package/test/integration/content-progress/__mocks__/mocks.ts +0 -104
  25. package/test/integration/content-progress/contentProgress.test.ts +0 -335
  26. package/test/integration/content-progress/e2eOfflineProgress.test.ts +0 -352
  27. package/test/integration/content-progress/e2eProgress.test.ts +0 -612
  28. package/test/integration/content-progress/getters.test.ts +0 -334
  29. package/test/integration/content-progress/helpers.test.ts +0 -263
  30. package/test/integration/content-progress/offlineContentProgress.test.ts +0 -226
  31. package/test/integration/forums.test.ts +0 -209
  32. package/test/integration/infrastructure/FetchRequestExecutor.test.ts +0 -88
  33. package/test/integration/initializeTestDB.ts +0 -80
  34. package/test/integration/learning-paths.test.ts +0 -854
  35. package/test/integration/notifications.test.ts +0 -178
  36. package/test/integration/progress-row/content-card.test.ts +0 -283
  37. package/test/integration/sync/adapters/idb-errors.test.ts +0 -144
  38. package/test/integration/sync/adapters/sqlite-errors.test.ts +0 -173
  39. package/test/integration/sync/fetch.test.ts +0 -224
  40. package/test/integration/sync/repositories/content-likes.test.ts +0 -99
  41. package/test/integration/sync/repositories/practices.test.ts +0 -179
  42. package/test/integration/sync/repositories/progress.test.ts +0 -245
  43. package/test/integration/sync/repositories/user-award-progress.static.test.ts +0 -68
  44. package/test/integration/sync/repositories/user-award-progress.test.ts +0 -387
  45. package/test/integration/sync/store/cross-user-protection.test.ts +0 -217
  46. package/test/integration/sync/store/store-idb.test.ts +0 -180
  47. package/test/integration/sync/store/store.test.ts +0 -361
  48. package/test/integration/user/permissions.test.js +0 -20
  49. package/test/integration/userActivity.test.ts +0 -102
  50. package/test/live/README.md +0 -29
  51. package/test/live/content.test.js +0 -116
  52. package/test/localStorageMock.js +0 -21
  53. package/test/log.js +0 -5
  54. package/test/mockData/award-definitions.js +0 -171
  55. package/test/mockData/mockData_fetchByRailContentIds_one_content.json +0 -35
  56. package/test/mockData/mockData_progress_content.json +0 -182
  57. package/test/mockData/mockData_sanity_progress_content.json +0 -1451
  58. package/test/mockData/mockData_user_practices.json +0 -9
  59. package/test/setupConsole.js +0 -6
  60. package/test/setupNetworkGuard.js +0 -3
  61. package/test/setupTimers.js +0 -13
  62. package/test/unit/HttpClient.test.ts +0 -267
  63. package/test/unit/awards/award-alacarte-observer.test.ts +0 -199
  64. package/test/unit/awards/award-auto-refresh.test.ts +0 -84
  65. package/test/unit/awards/award-calculations.test.ts +0 -34
  66. package/test/unit/awards/award-callbacks.test.ts +0 -144
  67. package/test/unit/awards/award-certificate-display.test.ts +0 -330
  68. package/test/unit/awards/award-collection-edge-cases.test.ts +0 -212
  69. package/test/unit/awards/award-collection-filtering.test.ts +0 -287
  70. package/test/unit/awards/award-completion-flow.test.ts +0 -306
  71. package/test/unit/awards/award-multi-lesson.test.ts +0 -243
  72. package/test/unit/awards/award-observer-integration.test.ts +0 -327
  73. package/test/unit/awards/award-query-messages.test.ts +0 -448
  74. package/test/unit/awards/award-user-collection.test.ts +0 -416
  75. package/test/unit/awards/duplicate-prevention.test.ts +0 -120
  76. package/test/unit/awards/helpers/completion-mock.ts +0 -56
  77. package/test/unit/awards/helpers/index.ts +0 -3
  78. package/test/unit/awards/helpers/mock-setup.ts +0 -79
  79. package/test/unit/awards/helpers/progress-emitter.ts +0 -45
  80. package/test/unit/awards/message-generator.test.ts +0 -162
  81. package/test/unit/content-progress/bubbleTrickle.test.ts +0 -322
  82. package/test/unit/content-progress/helpers.test.ts +0 -329
  83. package/test/unit/content-progress/navigateTo.test.ts +0 -381
  84. package/test/unit/contentLikes.test.ts +0 -62
  85. package/test/unit/contentMetaData.test.ts +0 -58
  86. package/test/unit/dataContext.test.ts +0 -38
  87. package/test/unit/dateUtils.test.ts +0 -188
  88. package/test/unit/endScreen.test.js +0 -712
  89. package/test/unit/imageSRCBuilder.test.ts +0 -37
  90. package/test/unit/imageSRCVerify.test.ts +0 -155
  91. package/test/unit/infrastructure/DefaultHeaderProvider.test.ts +0 -39
  92. package/test/unit/infrastructure/sanity/ContentClient.test.ts +0 -168
  93. package/test/unit/infrastructure/sanity/DefaultConfigProvider.test.ts +0 -93
  94. package/test/unit/infrastructure/sanity/FetchQueryExecutor.test.ts +0 -174
  95. package/test/unit/infrastructure/sanity/SanityClient.test.ts +0 -140
  96. package/test/unit/lib/__snapshots__/filter.test.ts.snap +0 -5
  97. package/test/unit/lib/filter.test.ts +0 -1154
  98. package/test/unit/lib/lastUpdated.test.ts +0 -21
  99. package/test/unit/lib/query.test.ts +0 -1469
  100. package/test/unit/lib/sanity/decorators/base.test.ts +0 -368
  101. package/test/unit/lib/sanity/decorators/navigate-to.test.ts +0 -361
  102. package/test/unit/lib/sanity/decorators/need-access.test.ts +0 -89
  103. package/test/unit/lib/sanity/decorators/need-lifetime-upgrade.test.ts +0 -85
  104. package/test/unit/lib/sanity/decorators/page-type.test.ts +0 -81
  105. package/test/unit/playerSettings.test.ts +0 -73
  106. package/test/unit/progress-row/content-card.test.ts +0 -314
  107. package/test/unit/progress-row/playlist-card.test.ts +0 -104
  108. package/test/unit/progressRows.test.ts +0 -243
  109. package/test/unit/recommendations.test.js +0 -47
  110. package/test/unit/sanityQueryService.test.ts +0 -200
  111. package/test/unit/search.test.ts +0 -44
  112. package/test/unit/sentry.test.ts +0 -62
  113. package/test/unit/services/progress-internal/bubble.test.ts +0 -279
  114. package/test/unit/services/progress.test.ts +0 -396
  115. package/test/unit/streakMessage.test.ts +0 -251
  116. package/test/unit/sync/context.test.ts +0 -51
  117. package/test/unit/sync/effects/logout-warning.test.ts +0 -158
  118. package/test/unit/sync/effects/push-failure-notification.test.ts +0 -196
  119. package/test/unit/sync/errors/sync-errors.test.ts +0 -106
  120. package/test/unit/sync/errors/validators.test.ts +0 -61
  121. package/test/unit/sync/helpers/TestModel.ts +0 -44
  122. package/test/unit/sync/helpers/index.ts +0 -172
  123. package/test/unit/sync/manager.test.ts +0 -303
  124. package/test/unit/sync/models/user-award-progress.test.ts +0 -82
  125. package/test/unit/sync/resolver.test.ts +0 -229
  126. package/test/unit/sync/retry.test.ts +0 -314
  127. package/test/unit/sync/run-scope.test.ts +0 -23
  128. package/test/unit/sync/stale-record-cleanup.test.ts +0 -107
  129. package/test/unit/sync/store/push-coalescer.test.ts +0 -156
  130. package/test/unit/sync/store-configs.test.ts +0 -37
  131. package/test/unit/sync/telemetry/sync-telemetry.test.ts +0 -118
  132. package/test/unit/sync/utils/event-emitter.test.ts +0 -64
  133. package/test/unit/sync/utils/throttle.test.ts +0 -245
  134. package/test/unit/url-builder.test.ts +0 -72
  135. package/test/unit/user/account.test.ts +0 -66
  136. package/test/unit/user/permissions.test.js +0 -191
@@ -0,0 +1,21 @@
1
+ ---
2
+ date: 2026-07-17
3
+ branch: chore/onboarding-statuses
4
+ pr: https://github.com/railroadmedia/musora-content-services/pull/1011
5
+ status: open
6
+ tags: [[feature]]
7
+ ---
8
+
9
+ # Add cross-brand onboarding status endpoint
10
+
11
+ ## Context
12
+ `userOnboardingForBrand(brand)` only returns onboarding state for one brand at a time. Callers that need to know onboarding completion across all brands (e.g. Drumeo, Pianote, Guitareo, Singeo) for a user had no single call to get that.
13
+
14
+ ## Decision
15
+ Added `getOnboardingStatus()` in `src/services/user/onboarding.ts`, hitting `GET /api/user-management-system/v1/users/{userId}/onboardings/status`. Returns `OnboardingStatus`: `has_completed_onboarding` plus a `brands: OnboardingBrandStatus[]` array (`brand`, `is_completed`, `completed_flow`, `completed_at`). Ran `npm run build-index` to regenerate `index.js`/`index.d.ts` so the new function is exported from the package.
16
+
17
+ ## Alternatives Considered
18
+ No alternatives considered — this is additive to the existing per-brand `userOnboardingForBrand` function, not a replacement.
19
+
20
+ ## Consequences
21
+ Consumers (musora-platform-frontend, MusoraApp) can now fetch all-brand onboarding status in a single request instead of looping `userOnboardingForBrand` per brand.
@@ -0,0 +1,33 @@
1
+ ---
2
+ date: 2026-07-20
3
+ branch: chore/MU2-1724-songs-lessons-counts
4
+ pr: https://github.com/railroadmedia/musora-content-services/pull/1012
5
+ status: open
6
+ tags: [[chore]]
7
+ ---
8
+
9
+ # Song and lesson counts query
10
+
11
+ ## Context
12
+ Needed a way to get the total number of songs vs. individual playable lessons in Sanity, globally or scoped to a brand. Content types don't map 1:1 onto "song" vs "lesson" — songs include `song`, `play-along`, `jam-track`, `song-tutorial-lesson` per `SONG_TYPES` in `contentTypeConfig.js`, and a "lesson" is any published, top-level (no `parent_type` / empty `parent_content_reference`) document with a `railcontent_id`, regardless of `_type`. The final filter definitions came out of a discussion with teammates, converging on `status == 'published' && defined(railcontent_id)` plus the parent-less check for lessons.
13
+
14
+ ## Decision
15
+ Added `fetchSongAndLessonCounts(brand?)` in `src/services/content/counts.ts`, returning `{ songs, lessons, total }`.
16
+ - Filter logic built with the `Filters` helper (`src/lib/sanity/filter.ts`) and `query()` builder (`src/lib/sanity/query.ts`) instead of hand-interpolated GROQ strings, for consistency with `artist.ts`/`genre.ts`/`instructor.ts`.
17
+ - Query executed via `SanityClient.executeQuery` (`src/infrastructure/sanity/SanityClient.ts`) rather than the legacy `fetchSanity` in `sanity.js` — `executeQuery` returns the raw object result directly, which fits an object-shaped `{songs, lessons}` GROQ query better than `fetchSanity`'s array-oriented `isList` handling.
18
+ - `total` is computed in application code (`songs + lessons`) after the query resolves, not inside GROQ, keeping the query itself to two independent counts.
19
+ - Kept `content.ts` as a types-only file (its original purpose) — the new function and its `SongAndLessonCounts` interface live in the new `counts.ts` file instead, matching the one-file-per-concern convention in `src/services/content/`.
20
+
21
+ ## Alternatives Considered
22
+ - Hand-built GROQ query with `${brand}` string interpolation (the version worked out iteratively with the Sanity MCP) — rejected in favor of the `Filters`/`query` builder for composability and to match existing code style.
23
+ - A fluent `.then().then()` chain for the `total` calculation — tried during review, rejected as unnecessary indirection versus a plain `await` + object literal; reverted to match house style (`artist.ts`, `sanity.js` use plain `await` throughout).
24
+ - Putting the function directly in `content.ts` — rejected once it became clear that file is types-only elsewhere in the codebase; moved to a dedicated `counts.ts`.
25
+
26
+ ## Process Notes
27
+ - `course` vs `course-lesson`: `course` is the parent course entity, `course-lesson` is the individual playable video inside it — easy to conflate when first scoping "lesson" types.
28
+ - Lesson types span several groupings in `contentTypeConfig.js` (`individualLessonsTypes`, `entertainmentLessonTypes`, `skill-pack-lesson`, `guided-course-lesson`, `pack-bundle-lesson`, live/student archive types) — rather than enumerate all `_type` values, the final query avoids the type-list entirely and instead filters on the structural "no parent" condition, which is more robust to new content types being added later.
29
+ - `pack-bundle-lesson` appears in `SINGLE_PARENT_TYPES` but nowhere else in `contentTypeConfig.js` — possibly legacy/unused; not specifically verified against the live Sanity schema.
30
+
31
+ ## Consequences
32
+ - New public function `fetchSongAndLessonCounts` exported from `src/services/content/counts.ts`; needs `npm run build-index` to surface in the generated package index/types.
33
+ - Introduces the first consumer of `SanityClient.executeQuery` outside `src/infrastructure/sanity/` — establishes a pattern for future count/aggregate-style queries to use the client class over `fetchSanity`.
@@ -0,0 +1,37 @@
1
+ ---
2
+ date: 2026-07-20
3
+ branch: chore/query-builder-tostring
4
+ pr: https://github.com/railroadmedia/musora-content-services/pull/1013
5
+ status: open
6
+ tags: [[chore]]
7
+ related: [[2026-07-20-mu2-1724-songs-lessons-counts]]
8
+ ---
9
+
10
+ # QueryBuilder toString()
11
+
12
+ ## Context
13
+ `fetchSongAndLessonCounts` (added in `chore/MU2-1724-songs-lessons-counts`) interpolates `query().and(filter)` builders directly into a GROQ template literal, e.g. `` count(${query().and(songsFilter).build()}) ``. The trailing `.build()` at each interpolation site is boilerplate — the same pattern repeats in `artist.ts`, `genre.ts`, and `instructor.ts` wherever a builder's output lands inside a template literal.
14
+
15
+ ## Decision
16
+ Added `toString(): string` to `QueryBuilder` (`src/lib/sanity/query.ts`), implemented as `return builder.build()`. JS automatically calls `toString()` during string coercion — template literals, `+` concat, `String(x)` — so a builder can now be interpolated directly: `` count(${query().and(filter)}) ``. This mirrors PHP's `Stringable` interface / Java's `toString()` override.
17
+
18
+ Swept the existing call sites to drop the now-redundant `.build()`:
19
+ - `counts.ts`: both `count(${...})` interpolations.
20
+ - `artist.ts`, `genre.ts`, `instructor.ts`: the `data`/`total` variables that are built once and interpolated later into a `q` template literal.
21
+
22
+ Left `.build()` in place at the one call shape that isn't string interpolation: `fetchArtistBySlug`/`fetchGenreBySlug`/`fetchInstructorBySlug` build `q` and pass it directly as `fetchSanity(q, ...)`'s first argument. Runtime-wise this would also work fine without `.build()` (`encodeURIComponent` inside `fetchSanity` coerces via `ToString` too), but keeping the explicit call there reads clearer for a variable that's a function argument rather than a string-interpolation target.
23
+
24
+ `.build()` itself was not removed or deprecated — this is purely additive, both call styles remain valid.
25
+
26
+ ## Alternatives Considered
27
+ - Removing `.build()` everywhere unconditionally, including the `fetchArtistBySlug`-style direct-argument calls — rejected to keep those call sites' typing/intent explicit (a `q` meant to be "the query string" reads oddly as a `QueryBuilder` object until it's coerced at the call boundary).
28
+ - `Symbol.toPrimitive` instead of plain `toString()` — unnecessary; nothing here needs numeric coercion, and plain `toString()` fully covers the template-literal/`String()`/concat cases that matter.
29
+
30
+ ## Process Notes
31
+ - Caveat surfaced during review: `JSON.stringify(builder)` does NOT trigger `toString()` — it serializes the object's own enumerable properties instead. Anywhere a builder might end up inside `JSON.stringify`, this would silently produce the wrong output. Not currently a problem (no such call site exists), but worth remembering if a future call site does this.
32
+ - Equality checks (`===`) never coerce, so comparing two builders directly still won't compare their query strings.
33
+ - This PR is stacked on `chore/MU2-1724-songs-lessons-counts` (PR #1012, unmerged) rather than targeting `main` directly, since it builds on that branch's `counts.ts`. PR base should be retargeted to `main` once #1012 merges.
34
+
35
+ ## Consequences
36
+ - `QueryBuilder` consumers can now interpolate a builder directly into a template literal without remembering to call `.build()` — reduces boilerplate at future call sites.
37
+ - No behavior change: verified via the full test suite (70 suites) after the sweep, plus an intentional break-and-revert of both `toString()` and the `counts.ts` total-summation logic to confirm the new tests actually catch regressions.
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.167.3](https://github.com/railroadmedia/musora-content-services/compare/v2.167.2...v2.167.3) (2026-07-22)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * add gen-version script ([#1015](https://github.com/railroadmedia/musora-content-services/issues/1015)) ([c047e38](https://github.com/railroadmedia/musora-content-services/commit/c047e38f5a20d34dc9a69e2eb3cf3f31861aa8f1))
11
+ * **BR-819:** add learning path id for learning path intro in recent a… ([#1008](https://github.com/railroadmedia/musora-content-services/issues/1008)) ([267423f](https://github.com/railroadmedia/musora-content-services/commit/267423f525ee12824acfe45e771fd2271d566ed6))
12
+
13
+ ### [2.167.2](https://github.com/railroadmedia/musora-content-services/compare/v2.167.1...v2.167.2) (2026-07-17)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * **BEHLTP-210:** add non-destructive notification polling pause ([#1009](https://github.com/railroadmedia/musora-content-services/issues/1009)) ([3c0d783](https://github.com/railroadmedia/musora-content-services/commit/3c0d783ee7ae4f54c77f9d37299ba182eaa3ebb5))
19
+
5
20
  ### [2.167.1](https://github.com/railroadmedia/musora-content-services/compare/v2.167.0...v2.167.1) (2026-07-13)
6
21
 
7
22
 
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "2.167.1",
3
+ "version": "2.167.3",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
+ "prepare": "node scripts/gen-version.cjs",
8
9
  "build-index": "node tools/generate-index.cjs",
9
10
  "release": "standard-version",
10
11
  "doc": "jsdoc -c jsdoc.json --verbose",
@@ -315,6 +315,7 @@ export const getNextLessonLessonParentTypes = [
315
315
  'song-tutorial',
316
316
  'learning-path-v2',
317
317
  'skill-pack',
318
+ 'documentary',
318
319
  ]
319
320
 
320
321
  export const progressTypesMapping = {
@@ -432,6 +433,7 @@ export let contentTypeConfig = {
432
433
  `"badge" : ${contentAwardField}.badge.asset->url`,
433
434
  `"badge_rear" : ${contentAwardField}.badge_rear.asset->url`,
434
435
  `"badge_logo" : ${contentAwardField}.logo.asset->url`,
436
+ '"learning_path_id": *[_type == "learning-path-v2" && references(^._id)][0].railcontent_id',
435
437
  ],
436
438
  includeChildFields: true,
437
439
  },
package/src/index.d.ts CHANGED
@@ -451,6 +451,7 @@ import {
451
451
 
452
452
  import {
453
453
  getOnboardingRecommendedContent,
454
+ getOnboardingStatus,
454
455
  initializeOnboardingFlow,
455
456
  startOnboarding,
456
457
  updateOnboarding,
@@ -707,6 +708,7 @@ declare module 'musora-content-services' {
707
708
  getNavigateToForPlaylists,
708
709
  getNewAndUpcoming,
709
710
  getOnboardingRecommendedContent,
711
+ getOnboardingStatus,
710
712
  getOwnedContent,
711
713
  getPermissionsAdapter,
712
714
  getPermissionsVersion,
package/src/index.js CHANGED
@@ -455,6 +455,7 @@ import {
455
455
 
456
456
  import {
457
457
  getOnboardingRecommendedContent,
458
+ getOnboardingStatus,
458
459
  initializeOnboardingFlow,
459
460
  startOnboarding,
460
461
  updateOnboarding,
@@ -706,6 +707,7 @@ export {
706
707
  getNavigateToForPlaylists,
707
708
  getNewAndUpcoming,
708
709
  getOnboardingRecommendedContent,
710
+ getOnboardingStatus,
709
711
  getOwnedContent,
710
712
  getPermissionsAdapter,
711
713
  getPermissionsVersion,
@@ -32,6 +32,7 @@ export interface QueryBuilder {
32
32
  dereference(): QueryBuilder
33
33
  postFilter(expr: string): QueryBuilder
34
34
  build(): string
35
+ toString(): string
35
36
 
36
37
  _state(): QueryBuilderState
37
38
  }
@@ -148,6 +149,10 @@ export const query = (selector?: string): QueryBuilder => {
148
149
  `.trim()
149
150
  },
150
151
 
152
+ toString() {
153
+ return builder.build()
154
+ },
155
+
151
156
  _state() {
152
157
  return state
153
158
  },
@@ -72,6 +72,21 @@ const excludeFromGeneratedIndex = []
72
72
  * appEnv: 'local'
73
73
  * });
74
74
  */
75
+ export async function getMCSVersion() {
76
+ try {
77
+ const { MCS_VERSION } = await import('../version-info.js')
78
+ return MCS_VERSION
79
+ } catch {
80
+ return null
81
+ }
82
+ }
83
+
84
+ if (process.env.NODE_ENV === 'development') {
85
+ getMCSVersion().then(v => v && console.log('[MCS] last tagged version:', v))
86
+ } else {
87
+ getMCSVersion().then(v => v && console.log('[MCS] version:', v))
88
+ }
89
+
75
90
  export function initializeService(config) {
76
91
  globalConfig.sanityConfig = config.sanityConfig
77
92
  globalConfig.railcontentConfig = config.railcontentConfig
@@ -50,7 +50,6 @@ export async function fetchArtists(
50
50
  `"lesson_count": ${await f.lessonCount(brand)}`
51
51
  )
52
52
  .postFilter(postFilter)
53
- .build()
54
53
 
55
54
  const q = `{
56
55
  "data": ${data},
@@ -152,9 +151,8 @@ export async function fetchArtistLessons(
152
151
  .order(sort)
153
152
  .slice(offset, limit)
154
153
  .select((await getFieldsForContentTypeWithFilteredChildren(contentType, true)) as string)
155
- .build()
156
154
 
157
- const total = query().and(restrictions).build()
155
+ const total = query().and(restrictions)
158
156
 
159
157
  const q = `{
160
158
  "data": ${data},
@@ -0,0 +1,47 @@
1
+ import { SONG_TYPES } from '../../contentTypeConfig.js'
2
+ import { SanityClient } from '../../infrastructure/sanity/SanityClient'
3
+ import { Brands } from '../../lib/brands'
4
+ import { Filters as f } from '../../lib/sanity/filter'
5
+ import { query } from '../../lib/sanity/query'
6
+
7
+ const sanityClient = new SanityClient()
8
+
9
+ export interface SongAndLessonCounts {
10
+ songs: number
11
+ lessons: number
12
+ total: number
13
+ }
14
+
15
+ /**
16
+ * @param {Brands|string} [brand] - Filters by brand; omit for a global count.
17
+ * @returns {Promise<SongAndLessonCounts>}
18
+ */
19
+ export async function fetchSongAndLessonCounts(
20
+ brand?: Brands | string
21
+ ): Promise<SongAndLessonCounts> {
22
+ const songsFilter = await f.combineAsync(
23
+ f.typeIn(SONG_TYPES),
24
+ f.statusIn(['published']),
25
+ f.defined('railcontent_id'),
26
+ brand ? f.brand(brand) : f.empty
27
+ )
28
+
29
+ const lessonsFilter = await f.combineAsync(
30
+ f.defined('railcontent_id'),
31
+ f.statusIn(['published']),
32
+ f.combineOr(f.notDefined('parent_type'), 'count(parent_content_reference) == 0'),
33
+ brand ? f.brand(brand) : f.empty
34
+ )
35
+
36
+ const q = `{
37
+ "songs": count(${query().and(songsFilter)}),
38
+ "lessons": count(${query().and(lessonsFilter)})
39
+ }`
40
+
41
+ const counts = (await sanityClient.executeQuery<Omit<SongAndLessonCounts, 'total'>>(q)) ?? {
42
+ songs: 0,
43
+ lessons: 0,
44
+ }
45
+
46
+ return { ...counts, total: counts.songs + counts.lessons }
47
+ }
@@ -50,7 +50,6 @@ export async function fetchGenres(
50
50
  `"lesson_count": ${await f.lessonCount(brand)}`
51
51
  )
52
52
  .postFilter(postFilter)
53
- .build()
54
53
 
55
54
  const q = `{
56
55
  "data": ${data},
@@ -151,9 +150,8 @@ export async function fetchGenreLessons(
151
150
  .order(sort)
152
151
  .slice(offset, limit)
153
152
  .select((await getFieldsForContentTypeWithFilteredChildren(contentType, true)) as string)
154
- .build()
155
153
 
156
- const total = query().and(restrictions).build()
154
+ const total = query().and(restrictions)
157
155
 
158
156
  const q = `{
159
157
  "data": ${data},
@@ -51,7 +51,6 @@ export async function fetchInstructors(
51
51
  `"lesson_count": ${await f.lessonCount(brand)}`
52
52
  )
53
53
  .postFilter(postFilter)
54
- .build()
55
54
 
56
55
  const q = `{
57
56
  "data": ${data},
@@ -151,9 +150,8 @@ export async function fetchInstructorLessons(
151
150
  .order(sort)
152
151
  .slice(offset, limit)
153
152
  .select((await getFieldsForContentTypeWithFilteredChildren(contentType, true)) as string)
154
- .build()
155
153
 
156
- const total = query().and(restrictions).build()
154
+ const total = query().and(restrictions)
157
155
 
158
156
  const q = `{
159
157
  "data": ${data},
@@ -173,7 +173,7 @@ export async function getNavigateTo(data) {
173
173
  const lastInteracted = await getLastInteractedOf(childrenIds)
174
174
  const lastInteractedStatus = childrenStates.get(lastInteracted)
175
175
 
176
- if (['course', 'skill-pack', 'song-tutorial'].includes(content.type)) {
176
+ if (['course', 'skill-pack', 'song-tutorial', 'documentary'].includes(content.type)) {
177
177
  // todo(BEHSTP-325): remove if/else and make findIncompleteLesson able to return current lesson if `started`
178
178
  if (lastInteractedStatus === STATE_STARTED) {
179
179
  // send to last interacted
@@ -3,6 +3,7 @@ import {fetchLiveEvent} from "./sanity"
3
3
  import { DataContext, PollingStateVersionKey } from './dataContext'
4
4
 
5
5
  const pollingStateContext = new DataContext(PollingStateVersionKey, fetchLiveEventPollingState)
6
+ const NOTIFICATION_POLLING_INTERVAL_MS = 60_000
6
7
 
7
8
  /**
8
9
  * API for managing notifications and live event polling.
@@ -12,6 +13,7 @@ class EventsAPI {
12
13
  this.brand = 'drumeo'
13
14
  this.onNotificationStateUpdated = []
14
15
  this.pollingInterval = null
16
+ this.isNotificationPollingPaused = false
15
17
  this.isLiveEventPollingActive = true
16
18
  this.resumeLiveEventTimeout = null
17
19
  }
@@ -27,6 +29,7 @@ class EventsAPI {
27
29
  */
28
30
  async initialize({ brand = 'drumeo' } = {}) {
29
31
  this.brand = brand;
32
+ this.isNotificationPollingPaused = false;
30
33
  await this.setupAutoEvents();
31
34
  await this.checkNotifications();
32
35
  }
@@ -80,15 +83,56 @@ class EventsAPI {
80
83
  const ttlMs = pauseUntil - now;
81
84
  await this.pauseLiveEventCheck(ttlMs);
82
85
  }
83
- this.pollingInterval = setInterval(() => {
84
- this.checkNotifications();
85
- }, 60000);
86
+ this.startNotificationInterval();
86
87
  } catch (error) {
87
88
  console.error('EventsApi: Failed to setup auto events:', error);
88
89
  this.checkNotifications();
89
90
  }
90
91
  }
91
92
 
93
+ /**
94
+ * Starts notification polling unless it is already active or explicitly paused.
95
+ */
96
+ startNotificationInterval() {
97
+ if (this.pollingInterval || this.isNotificationPollingPaused) {
98
+ return;
99
+ }
100
+
101
+ this.pollingInterval = setInterval(() => {
102
+ this.checkNotifications();
103
+ }, NOTIFICATION_POLLING_INTERVAL_MS);
104
+ }
105
+
106
+ /**
107
+ * Stops notification polling without removing notification subscribers.
108
+ */
109
+ stopNotificationInterval() {
110
+ if (!this.pollingInterval) {
111
+ return;
112
+ }
113
+
114
+ clearInterval(this.pollingInterval);
115
+ this.pollingInterval = null;
116
+ }
117
+
118
+ /**
119
+ * Pauses notification polling without resetting initialized state or subscribers.
120
+ */
121
+ pauseNotificationPolling() {
122
+ this.isNotificationPollingPaused = true;
123
+ this.stopNotificationInterval();
124
+ }
125
+
126
+ /**
127
+ * Resumes notification polling and immediately refreshes notification state.
128
+ * @returns {Promise<void>}
129
+ */
130
+ resumeNotificationPolling() {
131
+ this.isNotificationPollingPaused = false;
132
+ this.startNotificationInterval();
133
+ return this.checkNotifications();
134
+ }
135
+
92
136
 
93
137
  /**
94
138
  * Checks for unread notifications and triggers callbacks.
@@ -149,10 +193,8 @@ class EventsAPI {
149
193
  }
150
194
 
151
195
  destroy() {
152
- if (this.pollingInterval) {
153
- clearInterval(this.pollingInterval);
154
- this.pollingInterval = null;
155
- }
196
+ this.isNotificationPollingPaused = true;
197
+ this.stopNotificationInterval();
156
198
 
157
199
  if (this.resumeLiveEventTimeout) {
158
200
  clearTimeout(this.resumeLiveEventTimeout);
@@ -117,6 +117,28 @@ export async function userOnboardingForBrand(brand: string): Promise<Onboarding>
117
117
  )
118
118
  }
119
119
 
120
+ export interface OnboardingBrandStatus {
121
+ brand: string
122
+ is_completed: boolean
123
+ completed_flow: string | null
124
+ completed_at: Date | null
125
+ }
126
+
127
+ export interface OnboardingStatus {
128
+ has_completed_onboarding: boolean
129
+ brands: OnboardingBrandStatus[]
130
+ }
131
+
132
+ /**
133
+ * Fetches the current user's onboarding completion status across all brands.
134
+ *
135
+ * @returns {Promise<OnboardingStatus>} - A promise that resolves with the cross-brand onboarding status.
136
+ * @throws {HttpError} - If the HTTP request fails.
137
+ */
138
+ export async function getOnboardingStatus(): Promise<OnboardingStatus> {
139
+ return GET(`/api/user-management-system/v1/users/${globalConfig.sessionConfig.userId}/onboardings/status`)
140
+ }
141
+
120
142
  export interface OnboardingRecommendedContent {
121
143
  id: number
122
144
  title: string
@@ -526,6 +526,7 @@ export async function getRecentActivity({ page = 1, limit = 5, tabName = null }
526
526
  thumbnail: content.thumbnail || null,
527
527
  title: content.title || practice.title,
528
528
  parent_id: content.parent_id || null,
529
+ learningPathId: content.learning_path_id || null,
529
530
  navigateTo: content.navigateTo || null,
530
531
  sanityType: content.type || null,
531
532
  artist_name: content.artist_name || null,
@@ -820,6 +821,7 @@ async function formatPracticeMeta(practices = []) {
820
821
  sanity_type: content?.type || null,
821
822
  content_slug: content?.slug || null,
822
823
  parent_id: content?.parent_id || null,
824
+ learningPathId: content?.learning_path_id || null,
823
825
  navigateTo: content?.navigateTo || null,
824
826
  artist_name: content?.artist_name || null,
825
827
  }
@@ -0,0 +1 @@
1
+ export const MCS_VERSION = '2.167.3'
@@ -1,52 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npx jest *)",
5
- "Bash(npx tsc *)",
6
- "Skill(counselors)",
7
- "Bash(counselors ls *)",
8
- "Bash(counselors groups *)",
9
- "Bash(counselors run *)",
10
- "Bash(npm test *)",
11
- "Bash(gh pr *)",
12
- "Bash(gh api *)",
13
- "Bash(mkdir -p /tmp/pr-review-v2)",
14
- "Read(//tmp/pr-review-v2/**)",
15
- "Bash(cat /home/alesevero/railenvironment/applications/musora-content-services/AGENTS.md)",
16
- "Bash(echo \"no AGENTS.md\")",
17
- "Bash(echo \"exit=$?\")",
18
- "Bash(git checkout *)",
19
- "Skill(pr)",
20
- "Skill(create-decision)",
21
- "mcp__github__pull_request_read",
22
- "mcp__github__push_files",
23
- "Bash(git push *)",
24
- "mcp__github__create_pull_request",
25
- "mcp__github__search_pull_requests",
26
- "Bash(git commit *)",
27
- "Bash(git add *)"
28
- ]
29
- },
30
- "model": "sonnet",
31
- "enabledMcpjsonServers": [
32
- "atlassian",
33
- "figma",
34
- "google-workspace",
35
- "snowflake",
36
- "aws",
37
- "hex",
38
- "sanity",
39
- "mysql",
40
- "slack",
41
- "langfuse",
42
- "chrome-devtools",
43
- "railway",
44
- "github",
45
- "asana"
46
- ],
47
- "disabledMcpjsonServers": [
48
- "nightwatch",
49
- "1password"
50
- ],
51
- "effortLevel": "medium"
52
- }
@@ -1,60 +0,0 @@
1
- import { globalConfig, initializeService } from '../src'
2
- import { LocalStorageMock } from './localStorageMock'
3
- const railContentModule = require('../src/services/railcontent.js')
4
- const awardDefsModule = require('../src/services/awards/internal/award-definitions.js')
5
- let token = null
6
- let userId = process.env.RAILCONTENT_USER_ID ?? null
7
-
8
- export async function initializeTestService(useLive = false, isAdmin = false) {
9
- let token, userId
10
- if (useLive && !token && process.env.RAILCONTENT_BASE_URL) {
11
- const baseUrl = `${process.env.RAILCONTENT_BASE_URL}/api/user-management-system`
12
- const response = await fetch(`${baseUrl}/v1/sessions`, {
13
- method: 'POST',
14
- headers: {
15
- 'X-Client-Platform': 'mobile',
16
- 'Content-Type': 'application/json',
17
- Authorization: null,
18
- },
19
- body: JSON.stringify({
20
- email: process.env.RAILCONTENT_EMAIL,
21
- password: process.env.RAILCONTENT_PASSWORD,
22
- device_name: 'test',
23
- device_token: '',
24
- platform: '',
25
- }),
26
- })
27
-
28
- let data = await response.json() // Parse the JSON body
29
- token = data['token']
30
- userId = data['user']['id']
31
- }
32
-
33
- const config = {
34
- sanityConfig: {
35
- token: process.env.SANITY_API_TOKEN,
36
- projectId: process.env.SANITY_PROJECT_ID,
37
- dataset: process.env.SANITY_DATASET,
38
- useCachedAPI: process.env.SANITY_USE_CACHED_API === 'true' || true,
39
- version: '2021-06-07',
40
- debug: process.env.DEBUG === 'true' || false,
41
- useDummyRailContentMethods: true,
42
- },
43
- railcontentConfig: {
44
- baseUrl: process.env.RAILCONTENT_BASE_URL || 'https://test.musora.com',
45
- token: token,
46
- userId: userId,
47
- authToken: token,
48
- },
49
- sessionConfig: { token: token, userId: userId, authToken: token },
50
- baseUrl: process.env.RAILCONTENT_BASE_URL,
51
- localStorage: new LocalStorageMock(),
52
- isMA: true,
53
- }
54
- jest.spyOn(awardDefsModule.awardDefinitions, 'initialize').mockResolvedValue()
55
- initializeService(config)
56
- // Mock user permissions
57
- let permissionsMock = jest.spyOn(railContentModule, 'fetchUserPermissionsData')
58
- let permissionsData = { permissions: [108, 91, 92], isAdmin: isAdmin }
59
- permissionsMock.mockImplementation(() => permissionsData)
60
- }