musora-content-services 1.0.76 → 1.0.78
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 +2 -0
- package/docs/config.js.html +2 -2
- package/docs/index.html +2 -2
- package/docs/module-Config.html +2 -2
- package/docs/module-Railcontent-Services.html +2 -2
- package/docs/module-Sanity-Services.html +193 -28
- package/docs/railcontent.js.html +2 -2
- package/docs/sanity.js.html +127 -42
- package/link_mcs.sh +0 -0
- package/package.json +1 -1
- package/publish.sh +0 -0
- package/src/contentTypeConfig.js +76 -130
- package/src/index.d.ts +13 -3
- package/src/index.js +7 -3
- package/src/services/railcontent.js +71 -7
- package/src/services/sanity.js +31 -1
- package/test/sanityQueryService.test.js +16 -1
package/src/index.js
CHANGED
|
@@ -30,12 +30,14 @@ import {
|
|
|
30
30
|
fetchParentByRailContentId,
|
|
31
31
|
fetchMethodPreviousNextLesson,
|
|
32
32
|
fetchLiveEvent,
|
|
33
|
+
fetchChallengeOverview,
|
|
33
34
|
} from './services/sanity.js';
|
|
34
35
|
|
|
35
36
|
import {
|
|
36
|
-
|
|
37
|
+
fetchCompletedState,
|
|
37
38
|
fetchAllCompletedStates,
|
|
38
|
-
fetchContentInProgress
|
|
39
|
+
fetchContentInProgress,
|
|
40
|
+
fetchVimeoData,
|
|
39
41
|
} from './services/railcontent.js';
|
|
40
42
|
|
|
41
43
|
|
|
@@ -65,7 +67,7 @@ export {
|
|
|
65
67
|
fetchPackAll,
|
|
66
68
|
fetchPackChildren,
|
|
67
69
|
fetchLessonContent,
|
|
68
|
-
|
|
70
|
+
fetchCompletedState,
|
|
69
71
|
fetchAllCompletedStates,
|
|
70
72
|
fetchContentInProgress,
|
|
71
73
|
fetchCourseOverview,
|
|
@@ -73,4 +75,6 @@ export {
|
|
|
73
75
|
fetchParentByRailContentId,
|
|
74
76
|
fetchMethodPreviousNextLesson,
|
|
75
77
|
fetchLiveEvent,
|
|
78
|
+
fetchChallengeOverview,
|
|
79
|
+
fetchVimeoData,
|
|
76
80
|
}
|
|
@@ -4,17 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
const { globalConfig } = require('./config');
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
/**
|
|
8
|
-
* Fetches the completion status of a specific
|
|
9
|
+
* Fetches the completion status of a specific lesson for the current user.
|
|
9
10
|
*
|
|
10
|
-
* @param {string} content_id - The ID of the
|
|
11
|
+
* @param {string} content_id - The ID of the lesson content to check.
|
|
11
12
|
* @returns {Promise<Object|null>} - Returns the completion status object if found, otherwise null.
|
|
12
13
|
* @example
|
|
13
|
-
* fetchCurrentSongComplete('user123', '
|
|
14
|
+
* fetchCurrentSongComplete('user123', 'lesson456', 'csrf-token')
|
|
14
15
|
* .then(status => console.log(status))
|
|
15
16
|
* .catch(error => console.error(error));
|
|
16
17
|
*/
|
|
17
|
-
export async function
|
|
18
|
+
export async function fetchCompletedState(content_id) {
|
|
18
19
|
const url = `/content/user_progress/${globalConfig.railcontentConfig.userId}?content_ids[]=${content_id}`;
|
|
19
20
|
|
|
20
21
|
const headers = {
|
|
@@ -26,9 +27,40 @@ export async function fetchCurrentSongComplete(content_id) {
|
|
|
26
27
|
const response = await fetch(url, { headers });
|
|
27
28
|
const result = await response.json();
|
|
28
29
|
|
|
29
|
-
if (result && result[content_id]) {
|
|
30
|
-
|
|
31
|
-
return
|
|
30
|
+
if (result && result[content_id]) { return result[content_id]; // Return the correct object
|
|
31
|
+
} else {
|
|
32
|
+
return null; // Handle unexpected structure
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error('Fetch error:', error);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Fetches the vimeo meta-data
|
|
42
|
+
*
|
|
43
|
+
* @param {string} vimeo_id - The vimeo id, found in the <document>.video.external_id field for lessons
|
|
44
|
+
* @returns {Promise<Object|null>} - Returns the
|
|
45
|
+
* @example
|
|
46
|
+
* fetchVimeoData('642900215')
|
|
47
|
+
* .then(vimeoData => console.log(vimeoData))
|
|
48
|
+
* .catch(error => console.error(error));
|
|
49
|
+
*/
|
|
50
|
+
export async function fetchVimeoData(vimeo_id) {
|
|
51
|
+
const url = `/content/vimeo-data/${vimeo_id}`;
|
|
52
|
+
|
|
53
|
+
const headers = {
|
|
54
|
+
'Content-Type': 'application/json',
|
|
55
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const response = await fetch(url, { headers });
|
|
60
|
+
const result = await response.json();
|
|
61
|
+
|
|
62
|
+
if (result) {
|
|
63
|
+
return result; // Return the correct object
|
|
32
64
|
} else {
|
|
33
65
|
console.log('Invalid result structure', result);
|
|
34
66
|
return null; // Handle unexpected structure
|
|
@@ -140,4 +172,36 @@ export async function fetchContentInProgress(type="all", brand) {
|
|
|
140
172
|
console.error('Fetch error:', error);
|
|
141
173
|
return null;
|
|
142
174
|
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Fetches user context data for a specific piece of content.
|
|
180
|
+
*
|
|
181
|
+
* @param {int} contentId - The content id.
|
|
182
|
+
* @returns {Promise<Object|null>} - Returns an object containing user context data if found, otherwise null.
|
|
183
|
+
* @example
|
|
184
|
+
* fetchContentPageUserData(406548)
|
|
185
|
+
* .then(data => console.log(data))
|
|
186
|
+
* .catch(error => console.error(error));
|
|
187
|
+
*/
|
|
188
|
+
export async function fetchContentPageUserData(contentId) {
|
|
189
|
+
let url = `/content/${contentId}/user_data/${globalConfig.railcontentConfig.userId}`;
|
|
190
|
+
const headers = {
|
|
191
|
+
'Content-Type': 'application/json',
|
|
192
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
193
|
+
};
|
|
194
|
+
try {
|
|
195
|
+
const response = await fetch(url, { headers });
|
|
196
|
+
const result = await response.json();
|
|
197
|
+
if(result){
|
|
198
|
+
console.log('fetchContentPageUserData', result);
|
|
199
|
+
return result;
|
|
200
|
+
} else {
|
|
201
|
+
console.log('result not json');
|
|
202
|
+
}
|
|
203
|
+
} catch (error) {
|
|
204
|
+
console.error('Fetch error:', error);
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
143
207
|
}
|
package/src/services/sanity.js
CHANGED
|
@@ -639,6 +639,7 @@ return fetchSanity(query, false);
|
|
|
639
639
|
export async function fetchMethodChildren(railcontentId) {
|
|
640
640
|
const query = `*[railcontent_id == ${railcontentId}]{
|
|
641
641
|
child_count,
|
|
642
|
+
"id": railcontent_id,
|
|
642
643
|
"description": ${descriptionField},
|
|
643
644
|
title,
|
|
644
645
|
xp,
|
|
@@ -815,8 +816,9 @@ export async function fetchRelatedLessons(railContentId, brand) {
|
|
|
815
816
|
*/
|
|
816
817
|
export async function fetchPackAll(railcontentId) {
|
|
817
818
|
//TODO: Implement getPacks
|
|
818
|
-
const query = `*[
|
|
819
|
+
const query = `*[railcontent_id == ${railcontentId}]{
|
|
819
820
|
railcontent_id,
|
|
821
|
+
"id": railcontent_id,
|
|
820
822
|
title,
|
|
821
823
|
"image": thumbnail.asset->url,
|
|
822
824
|
"artist_name": artist->name,
|
|
@@ -886,6 +888,34 @@ export async function fetchPackChildren(railcontentId) {
|
|
|
886
888
|
return fetchChildren(railcontentId, 'pack');
|
|
887
889
|
}
|
|
888
890
|
|
|
891
|
+
/**
|
|
892
|
+
* Fetch the data needed for the Challenge Overview screen.
|
|
893
|
+
* @param {string} id - The Railcontent ID of the course
|
|
894
|
+
* @returns {Promise<Object|null>} - The challenge information and lessons or null if not found.
|
|
895
|
+
*
|
|
896
|
+
* @example
|
|
897
|
+
* fetchChallengeOverview('challenge123')
|
|
898
|
+
* .then(challenge => console.log(challenge))
|
|
899
|
+
* .catch(error => console.error(error));
|
|
900
|
+
*/
|
|
901
|
+
export async function fetchChallengeOverview(id) {
|
|
902
|
+
// WIP
|
|
903
|
+
const query = `*[railcontent_id == ${id}]{
|
|
904
|
+
${getFieldsForContentType("challenge", true)}
|
|
905
|
+
"lessons": child[]->{
|
|
906
|
+
"id": railcontent_id,
|
|
907
|
+
title,
|
|
908
|
+
"image": thumbnail.asset->url,
|
|
909
|
+
"instructors": instructor[]->name,
|
|
910
|
+
length_in_seconds,
|
|
911
|
+
difficulty_string,
|
|
912
|
+
difficulty,
|
|
913
|
+
"type": _type,
|
|
914
|
+
}
|
|
915
|
+
}`;
|
|
916
|
+
return fetchSanity(query, false);
|
|
917
|
+
}
|
|
918
|
+
|
|
889
919
|
/**
|
|
890
920
|
* Fetch the data needed for the Course Overview screen.
|
|
891
921
|
* @param {string} id - The Railcontent ID of the course
|
|
@@ -56,7 +56,7 @@ describe('Sanity Queries', function () {
|
|
|
56
56
|
const artistNames = response.map((x) => x.name);
|
|
57
57
|
expect(artistNames).toContain("Arctic Monkeys");
|
|
58
58
|
|
|
59
|
-
});
|
|
59
|
+
}, 10000);
|
|
60
60
|
|
|
61
61
|
test('fetchSongArtistCount', async () => {
|
|
62
62
|
const response = await fetchSongArtistCount('drumeo');
|
|
@@ -109,6 +109,21 @@ describe('Sanity Queries', function () {
|
|
|
109
109
|
expect(response.entity[0].id).toBeDefined();
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
+
test('fetchAllInstructorField', async () => {
|
|
113
|
+
const response = await fetchAll('drumeo', 'quick-tips',{searchTerm: 'Domino Santantonio'});
|
|
114
|
+
console.log(response);
|
|
115
|
+
expect(response.entity[0].id).toBeDefined();
|
|
116
|
+
expect(response.entity[0].instructors).toBeTruthy();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('fetchAllSortField', async () => {
|
|
120
|
+
const response = await fetchAll('drumeo', 'rhythmic-adventures-of-captain-carson',{});
|
|
121
|
+
console.log(response);
|
|
122
|
+
expect(response.entity[0].id).toBeDefined();
|
|
123
|
+
expect(response.entity[0].sort).toBeDefined();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
|
|
112
127
|
test('fetchAllChallenges', async () => {
|
|
113
128
|
const response = await fetchAll('drumeo', 'challenge',{});
|
|
114
129
|
console.log(response);
|