musora-content-services 1.0.20 → 1.0.21
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 +124 -0
- package/docs/index.html +2 -2
- package/docs/module-Config.html +669 -0
- package/docs/module-Railcontent-Services.html +751 -0
- package/docs/{global.html → module-Sanity-Services.html} +52 -501
- package/docs/railcontent.js.html +178 -0
- package/docs/sanity.js.html +994 -0
- package/jsdoc.json +1 -1
- package/package.json +1 -1
- package/publish.sh +0 -0
- package/src/index.d.ts +2 -2
- package/src/index.js +32 -909
- package/src/services/config.js +52 -0
- package/src/services/railcontent.js +106 -0
- package/src/services/sanity.js +922 -0
- package/test/sanityQueryService.test.js +2 -2
- package/docs/data/search.json +0 -1
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Semibold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Semibold-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-Semibold-webfont.ttf +0 -0
- package/docs/fonts/OpenSans-Semibold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
- package/docs/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/index.js.html +0 -1122
- package/docs/scripts/core.js +0 -726
- package/docs/scripts/core.min.js +0 -23
- package/docs/scripts/resize.js +0 -90
- package/docs/scripts/search.min.js +0 -6
- package/docs/scripts/third-party/Apache-License-2.0.txt +0 -202
- package/docs/scripts/third-party/fuse.js +0 -9
- package/docs/scripts/third-party/hljs-line-num-original.js +0 -369
- package/docs/scripts/third-party/hljs-line-num.js +0 -1
- package/docs/scripts/third-party/hljs-original.js +0 -5171
- package/docs/scripts/third-party/hljs.js +0 -1
- package/docs/scripts/third-party/popper.js +0 -5
- package/docs/scripts/third-party/tippy.js +0 -1
- package/docs/scripts/third-party/tocbot.js +0 -672
- package/docs/scripts/third-party/tocbot.min.js +0 -1
- package/docs/styles/clean-jsdoc-theme-base.css +0 -1159
- package/docs/styles/clean-jsdoc-theme-dark.css +0 -412
- package/docs/styles/clean-jsdoc-theme-light.css +0 -482
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +0 -30
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -1
- package/docs/styles/clean-jsdoc-theme.min.css +0 -1
- package/docs/styles/jsdoc-default.css +0 -692
- package/docs/styles/prettify-jsdoc.css +0 -111
- package/docs/styles/prettify-tomorrow.css +0 -132
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Config
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
let globalConfig = {
|
|
6
|
+
sanityConfig: {},
|
|
7
|
+
railcontentConfig: {}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Initializes the service with the given configuration.
|
|
12
|
+
* This function must be called before using any other functions in this library.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} config - Configuration object containing API settings.
|
|
15
|
+
* @param {Object} config.sanityConfig - Configuration for Sanity API.
|
|
16
|
+
* @param {string} config.sanityConfig.token - The API token for authenticating with Sanity.
|
|
17
|
+
* @param {string} config.sanityConfig.projectId - The project ID in Sanity.
|
|
18
|
+
* @param {string} config.sanityConfig.dataset - The dataset name in Sanity.
|
|
19
|
+
* @param {string} config.sanityConfig.version - The API version to use.
|
|
20
|
+
* @param {boolean} [config.sanityConfig.debug=false] - Optional flag to enable debug mode.
|
|
21
|
+
* @param {boolean} [config.sanityConfig.useCachedAPI=true] - Optional flag to enable or disable the use of the cached API.
|
|
22
|
+
* @param {Object} config.railcontentConfig - Configuration for user services.
|
|
23
|
+
* @param {string} config.railcontentConfig.token - The token for authenticating user-specific requests.
|
|
24
|
+
* @param {string} config.railcontentConfig.userId - The user ID for fetching user-specific data.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Initialize the service in your app.js
|
|
28
|
+
* initializeService({
|
|
29
|
+
* sanityConfig: {
|
|
30
|
+
* token: 'your-sanity-api-token',
|
|
31
|
+
* projectId: 'your-sanity-project-id',
|
|
32
|
+
* dataset: 'your-dataset-name',
|
|
33
|
+
* version: '2021-06-07',
|
|
34
|
+
* debug: true,
|
|
35
|
+
* useCachedAPI: false
|
|
36
|
+
* },
|
|
37
|
+
* railcontentConfig: {
|
|
38
|
+
* token: 'your-user-api-token',
|
|
39
|
+
* userId: 'current-user-id'
|
|
40
|
+
* }
|
|
41
|
+
* });
|
|
42
|
+
*/
|
|
43
|
+
function initializeService(config) {
|
|
44
|
+
globalConfig.sanityConfig = config.sanityConfig;
|
|
45
|
+
globalConfig.railcontentConfig = config.railcontentConfig;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Export both the initialization function and the config object
|
|
49
|
+
module.exports = {
|
|
50
|
+
initializeService,
|
|
51
|
+
globalConfig
|
|
52
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Railcontent-Services
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const { globalConfig } = require('./config');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Fetches the completion status of a specific song for the current user.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} userId - The ID of the current user.
|
|
11
|
+
* @param {string} content_id - The ID of the song content to check.
|
|
12
|
+
* @param {string} token - The CSRF token for authentication.
|
|
13
|
+
* @returns {Promise<Object|null>} - Returns the completion status object if found, otherwise null.
|
|
14
|
+
* @example
|
|
15
|
+
* fetchCurrentSongComplete('user123', 'song456', 'csrf-token')
|
|
16
|
+
* .then(status => console.log(status))
|
|
17
|
+
* .catch(error => console.error(error));
|
|
18
|
+
*/
|
|
19
|
+
export async function fetchCurrentSongComplete(content_id) {
|
|
20
|
+
const url = `/content/user_progress/${globalConfig.railcontentConfig.userId}?content_ids[]=${content_id}`;
|
|
21
|
+
|
|
22
|
+
const headers = {
|
|
23
|
+
'Content-Type': 'application/json',
|
|
24
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const response = await fetch(url, { headers });
|
|
29
|
+
const result = await response.json();
|
|
30
|
+
if(result){
|
|
31
|
+
return result[globalConfig.railcontentConfig.userId];
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error('Fetch error:', error);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Fetches the completion status for multiple songs for the current user.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} userId - The ID of the current user.
|
|
43
|
+
* @param {Array<string>} contentIds - An array of content IDs to check.
|
|
44
|
+
* @param {string} token - The CSRF token for authentication.
|
|
45
|
+
* @returns {Promise<Object|null>} - Returns an object containing completion statuses keyed by content ID, or null if an error occurs.
|
|
46
|
+
* @example
|
|
47
|
+
* fetchAllCompletedStates('user123', ['song456', 'song789'], 'csrf-token')
|
|
48
|
+
* .then(statuses => console.log(statuses))
|
|
49
|
+
* .catch(error => console.error(error));
|
|
50
|
+
*/
|
|
51
|
+
export async function fetchAllCompletedStates(contentIds) {
|
|
52
|
+
const url = `/content/user_progress/${globalConfig.railcontentConfig.userId}?${contentIds.map(id => `content_ids[]=${id}`).join('&')}`;
|
|
53
|
+
|
|
54
|
+
const headers = {
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const response = await fetch(url, { headers });
|
|
61
|
+
const result = await response.json();
|
|
62
|
+
if(result){
|
|
63
|
+
return result;
|
|
64
|
+
} else {
|
|
65
|
+
console.log('result not json');
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('Fetch error:', error);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Fetches a list of songs that are currently in progress for the current user.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} userId - The ID of the current user.
|
|
77
|
+
* @param {string} brand - The brand associated with the songs.
|
|
78
|
+
* @param {string} token - The CSRF token for authentication.
|
|
79
|
+
* @returns {Promise<Object|null>} - Returns an object containing in-progress songs if found, otherwise null.
|
|
80
|
+
* @example
|
|
81
|
+
* fetchSongsInProgress('user123', 'drumeo', 'csrf-token')
|
|
82
|
+
* .then(songs => console.log(songs))
|
|
83
|
+
* .catch(error => console.error(error));
|
|
84
|
+
*/
|
|
85
|
+
export async function fetchSongsInProgress(brand) {
|
|
86
|
+
const url = `/content/in_progress/${globalConfig.railcontentConfig.userId}?content_type=song&brand=${brand}`;
|
|
87
|
+
|
|
88
|
+
const headers = {
|
|
89
|
+
'Content-Type': 'application/json',
|
|
90
|
+
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const response = await fetch(url, { headers });
|
|
95
|
+
const result = await response.json();
|
|
96
|
+
if(result){
|
|
97
|
+
console.log('fetchSongsInProgress', result);
|
|
98
|
+
return result;
|
|
99
|
+
} else {
|
|
100
|
+
console.log('result not json');
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error('Fetch error:', error);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|