musora-content-services 2.3.6 → 2.3.8
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/.coderabbit.yaml +0 -0
- package/.editorconfig +0 -0
- package/.github/workflows/node.js.yml +0 -0
- package/.prettierignore +0 -0
- package/.prettierrc +0 -0
- package/.yarnrc.yml +1 -0
- package/CHANGELOG.md +9 -0
- package/README.md +0 -0
- package/babel.config.cjs +0 -0
- package/docs/Content-Organization.html +0 -0
- package/docs/ContentOrganization.html +0 -0
- package/docs/Gamification.html +0 -0
- package/docs/UserManagement.html +0 -0
- package/docs/UserManagementSystem.html +0 -0
- package/docs/api_types.js.html +0 -0
- package/docs/config.js.html +0 -0
- package/docs/content-org_content-org.js.html +0 -0
- package/docs/content-org_playlists-types.js.html +0 -0
- package/docs/content-org_playlists.js.html +0 -0
- package/docs/content.js.html +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/gamification_awards.js.html +0 -0
- package/docs/gamification_gamification.js.html +0 -0
- package/docs/gamification_types.js.html +0 -0
- package/docs/global.html +0 -0
- package/docs/global.html#User +0 -0
- package/docs/index.html +0 -0
- package/docs/module-Awards.html +0 -0
- package/docs/module-Config.html +0 -0
- package/docs/module-Content-Services-V2.html +0 -0
- package/docs/module-Content-Services.html +763 -0
- package/docs/module-Permissions.html +0 -0
- package/docs/module-Playlists.html +0 -0
- package/docs/module-Railcontent-Services.html +0 -0
- package/docs/module-Sanity-Services.html +0 -0
- package/docs/module-Session-Management.html +0 -0
- package/docs/module-Sessions.html +0 -0
- package/docs/module-User-Management.html +0 -0
- package/docs/module-User-Permissions.html +0 -0
- package/docs/module-UserManagement.html +0 -0
- package/docs/railcontent.js.html +0 -0
- package/docs/sanity.js.html +0 -0
- package/docs/scripts/collapse.js +0 -0
- package/docs/scripts/commonNav.js +0 -0
- package/docs/scripts/linenumber.js +0 -0
- package/docs/scripts/nav.js +0 -0
- package/docs/scripts/polyfill.js +0 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +0 -0
- package/docs/scripts/prettify/lang-css.js +0 -0
- package/docs/scripts/prettify/prettify.js +0 -0
- package/docs/scripts/search.js +0 -0
- package/docs/styles/jsdoc.css +0 -0
- package/docs/styles/prettify.css +0 -0
- package/docs/types.js.html +0 -0
- package/docs/user_management.js.html +0 -0
- package/docs/user_permissions.js.html +0 -0
- package/docs/user_sessions.js.html +0 -0
- package/docs/user_types.js.html +0 -0
- package/docs/user_user-management-system.js.html +0 -0
- package/docs/user_user-management.js.html +0 -0
- package/jest.config.js +0 -0
- package/jsdoc.json +0 -0
- package/link_mcs.sh +0 -0
- package/package.json +1 -1
- package/src/contentMetaData.js +0 -0
- package/src/filterBuilder.js +0 -0
- package/src/index.d.ts +13 -0
- package/src/index.js +13 -0
- package/src/lib/httpHelper.js +0 -0
- package/src/lib/lastUpdated.js +0 -0
- package/src/services/api/types.js +0 -0
- package/src/services/config.js +0 -0
- package/src/services/content-org/content-org.js +0 -0
- package/src/services/content-org/playlists-types.js +0 -0
- package/src/services/content-org/playlists.js +0 -0
- package/src/services/content.js +0 -0
- package/src/services/contentLikes.js +0 -0
- package/src/services/contentProgress.js +0 -0
- package/src/services/dataContext.js +0 -0
- package/src/services/dateUtils.js +55 -0
- package/src/services/forum.js +0 -0
- package/src/services/gamification/awards.js +0 -0
- package/src/services/gamification/gamification.js +0 -0
- package/src/services/gamification/types.js +0 -0
- package/src/services/imageSRCBuilder.js +0 -0
- package/src/services/imageSRCVerify.js +0 -0
- package/src/services/railcontent.js +30 -18
- package/src/services/recommendations.js +10 -9
- package/src/services/types.js +0 -0
- package/src/services/user/management.js +0 -0
- package/src/services/user/permissions.js +0 -0
- package/src/services/user/sessions.js +0 -0
- package/src/services/user/types.js +0 -0
- package/src/services/user/user-management-system.js +0 -0
- package/src/services/userActivity.js +289 -106
- package/test/content.test.js +0 -0
- package/test/contentLikes.test.js +0 -0
- package/test/contentProgress.test.js +0 -0
- package/test/dataContext.test.js +0 -0
- package/test/forum.test.js +0 -0
- package/test/imageSRCBuilder.test.js +0 -0
- package/test/imageSRCVerify.test.js +0 -0
- package/test/initializeTests.js +0 -0
- package/test/lib/lastUpdated.test.js +0 -0
- package/test/live/contentProgressLive.test.js +0 -0
- package/test/live/railcontentLive.test.js +0 -0
- package/test/localStorageMock.js +0 -0
- package/test/log.js +0 -0
- package/test/mockData/mockData_fetchByRailContentIds_one_content.json +0 -0
- package/test/mockData/mockData_user_practices.json +9 -0
- package/test/sanityQueryService.test.js +0 -0
- package/test/streakMessage.test.js +263 -0
- package/test/user/permissions.test.js +0 -0
- package/test/userActivity.test.js +6 -6
- package/tools/generate-index.cjs +0 -0
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/docs/railcontent.js.html
CHANGED
|
File without changes
|
package/docs/sanity.js.html
CHANGED
|
File without changes
|
package/docs/scripts/collapse.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/docs/scripts/nav.js
CHANGED
|
File without changes
|
package/docs/scripts/polyfill.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/docs/scripts/search.js
CHANGED
|
File without changes
|
package/docs/styles/jsdoc.css
CHANGED
|
File without changes
|
package/docs/styles/prettify.css
CHANGED
|
File without changes
|
package/docs/types.js.html
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/docs/user_types.js.html
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/jest.config.js
CHANGED
|
File without changes
|
package/jsdoc.json
CHANGED
|
File without changes
|
package/link_mcs.sh
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/src/contentMetaData.js
CHANGED
|
File without changes
|
package/src/filterBuilder.js
CHANGED
|
File without changes
|
package/src/index.d.ts
CHANGED
|
@@ -47,6 +47,14 @@ import {
|
|
|
47
47
|
verifyLocalDataContext
|
|
48
48
|
} from './services/dataContext.js';
|
|
49
49
|
|
|
50
|
+
import {
|
|
51
|
+
convertToTimeZone,
|
|
52
|
+
getMonday,
|
|
53
|
+
getWeekNumber,
|
|
54
|
+
isNextDay,
|
|
55
|
+
isSameDate
|
|
56
|
+
} from './services/dateUtils.js';
|
|
57
|
+
|
|
50
58
|
import {
|
|
51
59
|
getActiveDiscussions
|
|
52
60
|
} from './services/forum.js';
|
|
@@ -236,6 +244,7 @@ declare module 'musora-content-services' {
|
|
|
236
244
|
closeComment,
|
|
237
245
|
contentStatusCompleted,
|
|
238
246
|
contentStatusReset,
|
|
247
|
+
convertToTimeZone,
|
|
239
248
|
countAssignmentsAndLessons,
|
|
240
249
|
createComment,
|
|
241
250
|
createPlaylist,
|
|
@@ -332,6 +341,7 @@ declare module 'musora-content-services' {
|
|
|
332
341
|
getAllStartedOrCompleted,
|
|
333
342
|
getContentRows,
|
|
334
343
|
getLessonContentRows,
|
|
344
|
+
getMonday,
|
|
335
345
|
getNewAndUpcoming,
|
|
336
346
|
getPracticeSessions,
|
|
337
347
|
getProgressPercentage,
|
|
@@ -348,10 +358,13 @@ declare module 'musora-content-services' {
|
|
|
348
358
|
getUserMonthlyStats,
|
|
349
359
|
getUserPractices,
|
|
350
360
|
getUserWeeklyStats,
|
|
361
|
+
getWeekNumber,
|
|
351
362
|
globalConfig,
|
|
352
363
|
initializeService,
|
|
353
364
|
isBucketUrl,
|
|
354
365
|
isContentLiked,
|
|
366
|
+
isNextDay,
|
|
367
|
+
isSameDate,
|
|
355
368
|
jumpToContinueContent,
|
|
356
369
|
likeComment,
|
|
357
370
|
likeContent,
|
package/src/index.js
CHANGED
|
@@ -47,6 +47,14 @@ import {
|
|
|
47
47
|
verifyLocalDataContext
|
|
48
48
|
} from './services/dataContext.js';
|
|
49
49
|
|
|
50
|
+
import {
|
|
51
|
+
convertToTimeZone,
|
|
52
|
+
getMonday,
|
|
53
|
+
getWeekNumber,
|
|
54
|
+
isNextDay,
|
|
55
|
+
isSameDate
|
|
56
|
+
} from './services/dateUtils.js';
|
|
57
|
+
|
|
50
58
|
import {
|
|
51
59
|
getActiveDiscussions
|
|
52
60
|
} from './services/forum.js';
|
|
@@ -235,6 +243,7 @@ export {
|
|
|
235
243
|
closeComment,
|
|
236
244
|
contentStatusCompleted,
|
|
237
245
|
contentStatusReset,
|
|
246
|
+
convertToTimeZone,
|
|
238
247
|
countAssignmentsAndLessons,
|
|
239
248
|
createComment,
|
|
240
249
|
createPlaylist,
|
|
@@ -331,6 +340,7 @@ export {
|
|
|
331
340
|
getAllStartedOrCompleted,
|
|
332
341
|
getContentRows,
|
|
333
342
|
getLessonContentRows,
|
|
343
|
+
getMonday,
|
|
334
344
|
getNewAndUpcoming,
|
|
335
345
|
getPracticeSessions,
|
|
336
346
|
getProgressPercentage,
|
|
@@ -347,10 +357,13 @@ export {
|
|
|
347
357
|
getUserMonthlyStats,
|
|
348
358
|
getUserPractices,
|
|
349
359
|
getUserWeeklyStats,
|
|
360
|
+
getWeekNumber,
|
|
350
361
|
globalConfig,
|
|
351
362
|
initializeService,
|
|
352
363
|
isBucketUrl,
|
|
353
364
|
isContentLiked,
|
|
365
|
+
isNextDay,
|
|
366
|
+
isSameDate,
|
|
354
367
|
jumpToContinueContent,
|
|
355
368
|
likeComment,
|
|
356
369
|
likeContent,
|
package/src/lib/httpHelper.js
CHANGED
|
File without changes
|
package/src/lib/lastUpdated.js
CHANGED
|
File without changes
|
|
File without changes
|
package/src/services/config.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/services/content.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// dateUtils.js
|
|
2
|
+
|
|
3
|
+
export function convertToTimeZone(date, timeZone) {
|
|
4
|
+
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
5
|
+
timeZone,
|
|
6
|
+
year: 'numeric',
|
|
7
|
+
month: '2-digit',
|
|
8
|
+
day: '2-digit',
|
|
9
|
+
hour: '2-digit',
|
|
10
|
+
minute: '2-digit',
|
|
11
|
+
second: '2-digit',
|
|
12
|
+
hour12: false,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const parts = formatter.formatToParts(date).reduce((acc, part) => {
|
|
16
|
+
if (part.type !== 'literal') acc[part.type] = part.value;
|
|
17
|
+
return acc;
|
|
18
|
+
}, {});
|
|
19
|
+
|
|
20
|
+
return new Date(`${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}:${parts.second}`);
|
|
21
|
+
}
|
|
22
|
+
// Get start of the week (Monday)
|
|
23
|
+
export function getMonday(date) {
|
|
24
|
+
const d = new Date(date);
|
|
25
|
+
const day = d.getDay();
|
|
26
|
+
const diff = d.getDate() - day + (day === 0 ? -6 : 1);
|
|
27
|
+
return new Date(d.setDate(diff));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Get the week number
|
|
31
|
+
export function getWeekNumber(d) {
|
|
32
|
+
let newDate = new Date(d.getTime());
|
|
33
|
+
newDate.setUTCDate(newDate.getUTCDate() + 4 - (newDate.getUTCDay()||7));
|
|
34
|
+
var yearStart = new Date(Date.UTC(newDate.getUTCFullYear(),0,1));
|
|
35
|
+
var weekNo = Math.ceil(( ( (newDate - yearStart) / 86400000) + 1)/7);
|
|
36
|
+
return weekNo;
|
|
37
|
+
}
|
|
38
|
+
//Check if two dates are the same
|
|
39
|
+
export function isSameDate(date1, date2, method = '') {
|
|
40
|
+
return date1.toISOString().split('T')[0] === date2.toISOString().split('T')[0];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Check if two dates are consecutive days
|
|
44
|
+
export function isNextDay(prev, current) {
|
|
45
|
+
const prevDate = new Date(prev.getFullYear(), prev.getMonth(), prev.getDate());
|
|
46
|
+
const nextDate = new Date(prevDate);
|
|
47
|
+
nextDate.setDate(prevDate.getDate() + 1); // Add 1 day
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
nextDate.getFullYear() === current.getFullYear() &&
|
|
51
|
+
nextDate.getMonth() === current.getMonth() &&
|
|
52
|
+
nextDate.getDate() === current.getDate()
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
package/src/services/forum.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { globalConfig } from './config.js'
|
|
5
5
|
import { fetchJSONHandler } from '../lib/httpHelper.js'
|
|
6
|
+
import { convertToTimeZone } from './dateUtils.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Exported functions that are excluded from index generation.
|
|
@@ -1175,31 +1176,42 @@ export async function editComment(commentId, comment) {
|
|
|
1175
1176
|
}
|
|
1176
1177
|
|
|
1177
1178
|
export async function fetchUserPractices(currentVersion) {
|
|
1178
|
-
const url = `/api/user/practices/v1/practices
|
|
1179
|
-
const response = await fetchDataHandler(url, currentVersion)
|
|
1180
|
-
const { data, version } = response
|
|
1181
|
-
const userPractices = data
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1179
|
+
const url = `/api/user/practices/v1/practices`;
|
|
1180
|
+
const response = await fetchDataHandler(url, currentVersion);
|
|
1181
|
+
const { data, version } = response;
|
|
1182
|
+
const userPractices = data;
|
|
1183
|
+
|
|
1184
|
+
const userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
const formattedPractices = userPractices.reduce((acc, practice) => {
|
|
1188
|
+
// Convert UTC date to user's local date (still a Date object)
|
|
1189
|
+
const utcDate = new Date(practice.day);
|
|
1190
|
+
const localDate = convertToTimeZone(utcDate, userTimeZone);
|
|
1191
|
+
|
|
1192
|
+
const userTimeZoneDay =
|
|
1193
|
+
localDate.getFullYear() + '-' +
|
|
1194
|
+
String(localDate.getMonth() + 1).padStart(2, '0') + '-' +
|
|
1195
|
+
String(localDate.getDate()).padStart(2, '0');
|
|
1196
|
+
|
|
1197
|
+
if (!acc[userTimeZoneDay]) {
|
|
1198
|
+
acc[userTimeZoneDay] = [];
|
|
1187
1199
|
}
|
|
1188
1200
|
|
|
1189
|
-
|
|
1190
|
-
|
|
1201
|
+
acc[userTimeZoneDay].push({
|
|
1202
|
+
id: practice.id,
|
|
1203
|
+
duration_seconds: practice.duration_seconds,
|
|
1204
|
+
});
|
|
1191
1205
|
|
|
1192
|
-
return acc
|
|
1193
|
-
}, {})
|
|
1206
|
+
return acc;
|
|
1207
|
+
}, {});
|
|
1194
1208
|
|
|
1195
|
-
|
|
1209
|
+
return {
|
|
1196
1210
|
data: {
|
|
1197
1211
|
practices: formattedPractices,
|
|
1198
1212
|
},
|
|
1199
|
-
version
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
return json
|
|
1213
|
+
version,
|
|
1214
|
+
};
|
|
1203
1215
|
}
|
|
1204
1216
|
|
|
1205
1217
|
export async function logUserPractice(practiceDetails) {
|
|
@@ -113,16 +113,17 @@ export async function rankItems(brand, content_ids) {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
export async function recommendations(brand, {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
num_recommendations: limit,
|
|
121
|
-
}
|
|
122
|
-
const url = `/recommendations/`
|
|
116
|
+
export async function recommendations(brand, { section = ''} = {}) {
|
|
117
|
+
section = section.toUpperCase().replace('-', '_')
|
|
118
|
+
const sectionString = section ? `§ion=${section}` : '';
|
|
119
|
+
const url = `/api/content/v1/recommendations?brand=${brand}${sectionString}`
|
|
123
120
|
try {
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
return fetchJSONHandler(
|
|
122
|
+
url,
|
|
123
|
+
globalConfig.railcontentConfig.token,
|
|
124
|
+
globalConfig.railcontentConfig.baseUrl,
|
|
125
|
+
'get'
|
|
126
|
+
)
|
|
126
127
|
} catch (error) {
|
|
127
128
|
console.error('Fetch error:', error)
|
|
128
129
|
return null
|
package/src/services/types.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|