musora-content-services 2.104.0 โ 2.104.4
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/.claude/settings.local.json +2 -1
- package/CHANGELOG.md +13 -0
- package/check_content.js +30 -0
- package/check_content.mjs +32 -0
- package/package.json +1 -1
- package/src/contentTypeConfig.js +1 -1
- package/src/index.d.ts +3 -1
- package/src/index.js +3 -1
- package/src/lib/sanity/filter.ts +0 -0
- package/src/lib/sanity/query.ts +0 -0
- package/src/services/awards/award-callbacks.js +0 -0
- package/src/services/awards/award-query.js +13 -0
- package/src/services/awards/internal/award-manager.js +5 -0
- package/src/services/awards/types.d.ts +0 -0
- package/src/services/content/artist.ts +0 -0
- package/src/services/content/genre.ts +0 -0
- package/src/services/content/instructor.ts +0 -0
- package/src/services/content-org/learning-paths.ts +0 -0
- package/src/services/content-org/playlists.js +0 -0
- package/src/services/content.js +6 -1
- package/src/services/contentProgress.js +0 -0
- package/src/services/forums/forums.ts +0 -0
- package/src/services/forums/threads.ts +0 -0
- package/src/services/permissions/PermissionsV2Adapter.ts +0 -0
- package/src/services/railcontent.js +0 -0
- package/src/services/reporting/reporting.ts +0 -0
- package/src/services/sanity.js +2 -1
- package/src/services/sync/repositories/content-progress.ts +0 -0
- package/src/services/sync/repositories/user-award-progress.ts +26 -0
- package/src/services/user/sessions.js +0 -0
- package/test/awards/award-completion-flow.test.js +90 -0
- package/test/lib/__snapshots__/filter.test.ts.snap +0 -0
- package/test/lib/filter.test.ts +0 -0
- package/test/lib/query.test.ts +0 -0
- package/test_owned_navigate.js +74 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
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.104.4](https://github.com/railroadmedia/musora-content-services/compare/v2.104.3...v2.104.4) (2025-12-12)
|
|
6
|
+
|
|
7
|
+
### [2.104.3](https://github.com/railroadmedia/musora-content-services/compare/v2.104.0...v2.104.3) (2025-12-12)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **MU2-1309:** navigateTo missing on owned contents ([9b12213](https://github.com/railroadmedia/musora-content-services/commit/9b12213ad8061d60eada1603c0384d36b7a955f3))
|
|
13
|
+
|
|
14
|
+
### [2.104.2](https://github.com/railroadmedia/musora-content-services/compare/v2.104.1...v2.104.2) (2025-12-12)
|
|
15
|
+
|
|
16
|
+
### [2.104.1](https://github.com/railroadmedia/musora-content-services/compare/v2.104.0...v2.104.1) (2025-12-12)
|
|
17
|
+
|
|
5
18
|
## [2.104.0](https://github.com/railroadmedia/musora-content-services/compare/v2.100.3...v2.104.0) (2025-12-12)
|
|
6
19
|
|
|
7
20
|
|
package/check_content.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { initializeService } = require('./src/services/config.js');
|
|
2
|
+
const { fetchByRailContentIds } = require('./src/services/sanity.js');
|
|
3
|
+
require('dotenv/config');
|
|
4
|
+
|
|
5
|
+
async function checkContent() {
|
|
6
|
+
initializeService({
|
|
7
|
+
sanityConfig: {
|
|
8
|
+
token: process.env.SANITY_TOKEN,
|
|
9
|
+
projectId: process.env.SANITY_PROJECT_ID,
|
|
10
|
+
dataset: process.env.SANITY_DATASET,
|
|
11
|
+
version: process.env.SANITY_VERSION || '2021-06-07',
|
|
12
|
+
},
|
|
13
|
+
railcontentConfig: {
|
|
14
|
+
token: process.env.RAILCONTENT_TOKEN,
|
|
15
|
+
userId: process.env.RAILCONTENT_USER_ID,
|
|
16
|
+
baseUrl: process.env.RAILCONTENT_BASE_URL,
|
|
17
|
+
authToken: process.env.RAILCONTENT_AUTH_TOKEN,
|
|
18
|
+
},
|
|
19
|
+
baseUrl: process.env.RAILCONTENT_BASE_URL,
|
|
20
|
+
localStorage: null,
|
|
21
|
+
isMA: false,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
console.log('Checking railcontent_id: 421814');
|
|
25
|
+
const contents = await fetchByRailContentIds([421814]);
|
|
26
|
+
console.log('Results:', JSON.stringify(contents, null, 2));
|
|
27
|
+
console.log('Found:', contents.length, 'items');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
checkContent().catch(console.error);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { initializeService } from './src/services/config.js';
|
|
2
|
+
import { fetchByRailContentIds } from './src/services/sanity.js';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
4
|
+
|
|
5
|
+
dotenv.config();
|
|
6
|
+
|
|
7
|
+
async function checkContent() {
|
|
8
|
+
initializeService({
|
|
9
|
+
sanityConfig: {
|
|
10
|
+
token: process.env.SANITY_TOKEN,
|
|
11
|
+
projectId: process.env.SANITY_PROJECT_ID,
|
|
12
|
+
dataset: process.env.SANITY_DATASET,
|
|
13
|
+
version: process.env.SANITY_VERSION || '2021-06-07',
|
|
14
|
+
},
|
|
15
|
+
railcontentConfig: {
|
|
16
|
+
token: process.env.RAILCONTENT_TOKEN,
|
|
17
|
+
userId: process.env.RAILCONTENT_USER_ID,
|
|
18
|
+
baseUrl: process.env.RAILCONTENT_BASE_URL,
|
|
19
|
+
authToken: process.env.RAILCONTENT_AUTH_TOKEN,
|
|
20
|
+
},
|
|
21
|
+
baseUrl: process.env.RAILCONTENT_BASE_URL,
|
|
22
|
+
localStorage: null,
|
|
23
|
+
isMA: false,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log('Checking railcontent_id: 421814');
|
|
27
|
+
const contents = await fetchByRailContentIds([421814]);
|
|
28
|
+
console.log('Results:', JSON.stringify(contents, null, 2));
|
|
29
|
+
console.log('Found:', contents.length, 'items');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
checkContent().catch(console.error);
|
package/package.json
CHANGED
package/src/contentTypeConfig.js
CHANGED
|
@@ -862,7 +862,7 @@ export function getChildFieldsForContentType(contentType, asQueryString = true)
|
|
|
862
862
|
export function getFieldsForContentType(contentType, asQueryString = true) {
|
|
863
863
|
const fields = contentType
|
|
864
864
|
? DEFAULT_FIELDS.concat(contentTypeConfig?.[contentType]?.fields ?? [])
|
|
865
|
-
: DEFAULT_FIELDS
|
|
865
|
+
: DEFAULT_FIELDS.slice() // ensure copy, not original reference
|
|
866
866
|
return asQueryString ? fields.toString() + ',' : fields
|
|
867
867
|
}
|
|
868
868
|
|
package/src/index.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
getAwardStatistics,
|
|
10
10
|
getCompletedAwards,
|
|
11
11
|
getContentAwards,
|
|
12
|
-
getInProgressAwards
|
|
12
|
+
getInProgressAwards,
|
|
13
|
+
resetAllAwards
|
|
13
14
|
} from './services/awards/award-query.js';
|
|
14
15
|
|
|
15
16
|
import {
|
|
@@ -683,6 +684,7 @@ declare module 'musora-content-services' {
|
|
|
683
684
|
reportPlaylist,
|
|
684
685
|
requestEmailChange,
|
|
685
686
|
reset,
|
|
687
|
+
resetAllAwards,
|
|
686
688
|
resetAllLearningPaths,
|
|
687
689
|
resetPassword,
|
|
688
690
|
restoreComment,
|
package/src/index.js
CHANGED
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
getAwardStatistics,
|
|
14
14
|
getCompletedAwards,
|
|
15
15
|
getContentAwards,
|
|
16
|
-
getInProgressAwards
|
|
16
|
+
getInProgressAwards,
|
|
17
|
+
resetAllAwards
|
|
17
18
|
} from './services/awards/award-query.js';
|
|
18
19
|
|
|
19
20
|
import {
|
|
@@ -682,6 +683,7 @@ export {
|
|
|
682
683
|
reportPlaylist,
|
|
683
684
|
requestEmailChange,
|
|
684
685
|
reset,
|
|
686
|
+
resetAllAwards,
|
|
685
687
|
resetAllLearningPaths,
|
|
686
688
|
resetPassword,
|
|
687
689
|
restoreComment,
|
package/src/lib/sanity/filter.ts
CHANGED
|
File without changes
|
package/src/lib/sanity/query.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -493,3 +493,16 @@ export async function getAwardStatistics(brand = null) {
|
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* @returns {Promise<{ deletedCount: number }>}
|
|
499
|
+
*/
|
|
500
|
+
export async function resetAllAwards() {
|
|
501
|
+
try {
|
|
502
|
+
const result = await db.userAwardProgress.deleteAllAwards()
|
|
503
|
+
return result
|
|
504
|
+
} catch (error) {
|
|
505
|
+
console.error('Failed to reset awards:', error)
|
|
506
|
+
return { deletedCount: 0 }
|
|
507
|
+
}
|
|
508
|
+
}
|
|
@@ -129,6 +129,11 @@ export class AwardManager {
|
|
|
129
129
|
const completedCount = completedLessonIds.length
|
|
130
130
|
const progressPercentage = Math.round((completedCount / childIds.length) * 100)
|
|
131
131
|
|
|
132
|
+
if (progressPercentage === 100) {
|
|
133
|
+
await this.grantAward(award, collection)
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
132
137
|
const progressData = {
|
|
133
138
|
completedLessonIds,
|
|
134
139
|
totalLessons: childIds.length,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/services/content.js
CHANGED
|
@@ -527,5 +527,10 @@ export async function getOwnedContent(brand, {
|
|
|
527
527
|
};
|
|
528
528
|
}
|
|
529
529
|
|
|
530
|
-
return data
|
|
530
|
+
return await addContextToContent(() => data, {
|
|
531
|
+
dataField: 'entity',
|
|
532
|
+
addNavigateTo: true,
|
|
533
|
+
addProgressPercentage: true,
|
|
534
|
+
addProgressStatus: true,
|
|
535
|
+
});
|
|
531
536
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/services/sanity.js
CHANGED
|
@@ -2068,7 +2068,8 @@ export async function fetchOwnedContent(
|
|
|
2068
2068
|
showOnlyOwnedContent: true, // Key parameter: exclude membership content
|
|
2069
2069
|
}).buildFilter()
|
|
2070
2070
|
|
|
2071
|
-
|
|
2071
|
+
// Use 'tab-data' to include children field (needed for navigateTo calculation)
|
|
2072
|
+
const fieldsString = await getFieldsForContentTypeWithFilteredChildren('tab-data', true)
|
|
2072
2073
|
|
|
2073
2074
|
const query = buildEntityAndTotalQuery(filterWithRestrictions, fieldsString, {
|
|
2074
2075
|
sortOrder: sortOrder,
|
|
File without changes
|
|
@@ -130,4 +130,30 @@ export default class UserAwardProgressRepository extends SyncRepository<UserAwar
|
|
|
130
130
|
|
|
131
131
|
return { definitions, progress: progressMap }
|
|
132
132
|
}
|
|
133
|
+
|
|
134
|
+
async deleteAllAwards() {
|
|
135
|
+
const allProgress = await this.getAll()
|
|
136
|
+
const ids = allProgress.data.map(p => p.id)
|
|
137
|
+
|
|
138
|
+
if (ids.length === 0) {
|
|
139
|
+
return { deletedCount: 0 }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
await this.deleteSome(ids)
|
|
143
|
+
|
|
144
|
+
const response = await this.store.pushRecordIdsImpatiently(ids)
|
|
145
|
+
|
|
146
|
+
if (response && response.ok) {
|
|
147
|
+
await this.store.db.write(async () => {
|
|
148
|
+
const collection = this.store.db.get<UserAwardProgress>(UserAwardProgress.table)
|
|
149
|
+
const deletedRecords = await collection
|
|
150
|
+
.query(Q.where('id', Q.oneOf(ids)))
|
|
151
|
+
.fetch()
|
|
152
|
+
|
|
153
|
+
await Promise.all(deletedRecords.map(record => record.destroyPermanently()))
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return { deletedCount: ids.length }
|
|
158
|
+
}
|
|
133
159
|
}
|
|
File without changes
|
|
@@ -210,4 +210,94 @@ describe('Award Completion Flow - E2E Scenarios', () => {
|
|
|
210
210
|
expect(db.userAwardProgress.recordAwardProgress).not.toHaveBeenCalled()
|
|
211
211
|
})
|
|
212
212
|
})
|
|
213
|
+
|
|
214
|
+
describe('Scenario: Race condition - eligibility check fails but progress reaches 100%', () => {
|
|
215
|
+
const multiLessonAward = getAwardByContentId(417049)
|
|
216
|
+
const parentCourseId = 417049
|
|
217
|
+
|
|
218
|
+
test('grants award with completedAt when updateAwardProgress calculates 100%', async () => {
|
|
219
|
+
let callCount = 0
|
|
220
|
+
|
|
221
|
+
db.contentProgress.getSomeProgressByContentIds.mockImplementation((contentIds) => {
|
|
222
|
+
callCount++
|
|
223
|
+
|
|
224
|
+
if (callCount === 1) {
|
|
225
|
+
const partialRecords = contentIds
|
|
226
|
+
.filter(id => [417045, 417046, 417047].includes(id))
|
|
227
|
+
.map(id => ({
|
|
228
|
+
content_id: id,
|
|
229
|
+
state: 'completed',
|
|
230
|
+
created_at: Math.floor(Date.now() / 1000)
|
|
231
|
+
}))
|
|
232
|
+
return Promise.resolve({ data: partialRecords })
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const allRecords = contentIds.map(id => ({
|
|
236
|
+
content_id: id,
|
|
237
|
+
state: 'completed',
|
|
238
|
+
created_at: Math.floor(Date.now() / 1000)
|
|
239
|
+
}))
|
|
240
|
+
return Promise.resolve({ data: allRecords })
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
await awardManager.onContentCompleted(parentCourseId)
|
|
244
|
+
|
|
245
|
+
expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
|
|
246
|
+
multiLessonAward._id,
|
|
247
|
+
100,
|
|
248
|
+
expect.objectContaining({
|
|
249
|
+
completedAt: expect.any(Number),
|
|
250
|
+
completionData: expect.objectContaining({
|
|
251
|
+
completed_at: expect.any(String)
|
|
252
|
+
}),
|
|
253
|
+
immediate: true
|
|
254
|
+
})
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
expect(listeners.granted).toHaveBeenCalledTimes(1)
|
|
258
|
+
expect(listeners.progress).not.toHaveBeenCalled()
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
test('emits awardGranted event when race condition triggers completion', async () => {
|
|
262
|
+
let callCount = 0
|
|
263
|
+
|
|
264
|
+
db.contentProgress.getSomeProgressByContentIds.mockImplementation((contentIds) => {
|
|
265
|
+
callCount++
|
|
266
|
+
|
|
267
|
+
if (callCount === 1) {
|
|
268
|
+
const partialRecords = contentIds
|
|
269
|
+
.filter(id => [417045, 417046].includes(id))
|
|
270
|
+
.map(id => ({
|
|
271
|
+
content_id: id,
|
|
272
|
+
state: 'completed',
|
|
273
|
+
created_at: Math.floor(Date.now() / 1000)
|
|
274
|
+
}))
|
|
275
|
+
return Promise.resolve({ data: partialRecords })
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const allRecords = contentIds.map(id => ({
|
|
279
|
+
content_id: id,
|
|
280
|
+
state: 'completed',
|
|
281
|
+
created_at: Math.floor(Date.now() / 1000)
|
|
282
|
+
}))
|
|
283
|
+
return Promise.resolve({ data: allRecords })
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
await awardManager.onContentCompleted(parentCourseId)
|
|
287
|
+
|
|
288
|
+
expect(listeners.granted).toHaveBeenCalledTimes(1)
|
|
289
|
+
expect(listeners.granted).toHaveBeenCalledWith(
|
|
290
|
+
expect.objectContaining({
|
|
291
|
+
awardId: multiLessonAward._id,
|
|
292
|
+
definition: expect.objectContaining({
|
|
293
|
+
name: multiLessonAward.name
|
|
294
|
+
}),
|
|
295
|
+
completionData: expect.objectContaining({
|
|
296
|
+
completed_at: expect.any(String)
|
|
297
|
+
}),
|
|
298
|
+
timestamp: expect.any(Number)
|
|
299
|
+
})
|
|
300
|
+
)
|
|
301
|
+
})
|
|
302
|
+
})
|
|
213
303
|
})
|
|
File without changes
|
package/test/lib/filter.test.ts
CHANGED
|
File without changes
|
package/test/lib/query.test.ts
CHANGED
|
File without changes
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { initializeService } from './src/services/config.js'
|
|
2
|
+
import { getOwnedContent } from './src/services/content.js'
|
|
3
|
+
import dotenv from 'dotenv'
|
|
4
|
+
|
|
5
|
+
dotenv.config()
|
|
6
|
+
|
|
7
|
+
// Initialize service with credentials from .env
|
|
8
|
+
initializeService({
|
|
9
|
+
sanityConfig: {
|
|
10
|
+
token: process.env.SANITY_API_TOKEN,
|
|
11
|
+
projectId: process.env.SANITY_PROJECT_ID,
|
|
12
|
+
dataset: process.env.SANITY_DATASET,
|
|
13
|
+
version: '2023-01-01',
|
|
14
|
+
},
|
|
15
|
+
railcontentConfig: {
|
|
16
|
+
email: process.env.RAILCONTENT_EMAIL,
|
|
17
|
+
password: process.env.RAILCONTENT_PASSWORD,
|
|
18
|
+
userId: parseInt(process.env.RAILCONTENT_USER_ID),
|
|
19
|
+
baseUrl: process.env.RAILCONTENT_BASE_URL,
|
|
20
|
+
},
|
|
21
|
+
localStorage: null,
|
|
22
|
+
isMA: false,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
async function testOwnedContentNavigateTo() {
|
|
26
|
+
console.log('\n๐งช Testing owned content with navigateTo...\n')
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
// Test for drumeo lessons
|
|
30
|
+
const result = await getOwnedContent('drumeo', {
|
|
31
|
+
type: ['course', 'guided-course', 'pack'],
|
|
32
|
+
limit: 5,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
console.log('๐ Results:', {
|
|
36
|
+
total: result.total,
|
|
37
|
+
count: result.entity?.length || 0,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
if (result.entity && result.entity.length > 0) {
|
|
41
|
+
result.entity.forEach((item, index) => {
|
|
42
|
+
console.log(`\n๐ฆ Item ${index + 1}:`)
|
|
43
|
+
console.log(` - ID: ${item.id}`)
|
|
44
|
+
console.log(` - Title: ${item.title}`)
|
|
45
|
+
console.log(` - Type: ${item.type}`)
|
|
46
|
+
console.log(` - Has children: ${item.children ? 'โ
YES' : 'โ NO'}`)
|
|
47
|
+
console.log(` - Children count: ${item.children?.length || 0}`)
|
|
48
|
+
console.log(` - Has navigateTo: ${item.navigateTo ? 'โ
YES' : 'โ NO'}`)
|
|
49
|
+
|
|
50
|
+
if (item.navigateTo) {
|
|
51
|
+
console.log(` - NavigateTo ID: ${item.navigateTo.id}`)
|
|
52
|
+
console.log(` - NavigateTo Type: ${item.navigateTo.type}`)
|
|
53
|
+
console.log(` - NavigateTo Title: ${item.children?.find(c => c.id === item.navigateTo.id)?.title || 'N/A'}`)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (item.progressPercentage !== undefined) {
|
|
57
|
+
console.log(` - Progress: ${item.progressPercentage}%`)
|
|
58
|
+
}
|
|
59
|
+
if (item.progressStatus) {
|
|
60
|
+
console.log(` - Status: ${item.progressStatus}`)
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
} else {
|
|
64
|
+
console.log('\nโ ๏ธ No owned content found for this user')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
console.log('\nโ
Test completed successfully!')
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error('\nโ Test failed:', error.message)
|
|
70
|
+
console.error(error.stack)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
testOwnedContentNavigateTo()
|