musora-content-services 2.99.4 → 2.99.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/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.99.8](https://github.com/railroadmedia/musora-content-services/compare/v2.99.7...v2.99.8) (2025-12-09)
6
+
7
+ ### [2.99.7](https://github.com/railroadmedia/musora-content-services/compare/v2.99.6...v2.99.7) (2025-12-09)
8
+
9
+ ### [2.99.6](https://github.com/railroadmedia/musora-content-services/compare/v2.99.5...v2.99.6) (2025-12-09)
10
+
11
+ ### [2.99.5](https://github.com/railroadmedia/musora-content-services/compare/v2.99.4...v2.99.5) (2025-12-09)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * daily session created when method intro video completed ([#636](https://github.com/railroadmedia/musora-content-services/issues/636)) ([fdfbb62](https://github.com/railroadmedia/musora-content-services/commit/fdfbb6287348307920ec50b798a0f14520fe4f10))
17
+
5
18
  ### [2.99.4](https://github.com/railroadmedia/musora-content-services/compare/v2.99.3...v2.99.4) (2025-12-09)
6
19
 
7
20
  ### [2.99.3](https://github.com/railroadmedia/musora-content-services/compare/v2.99.2...v2.99.3) (2025-12-09)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "2.99.4",
3
+ "version": "2.99.8",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1,12 +1,37 @@
1
1
  import { globalConfig } from '../services/config.js'
2
2
 
3
+ async function message(response) {
4
+ const contentType = response.headers.get('content-type')
5
+ if (
6
+ contentType &&
7
+ contentType.indexOf('application/json') !== -1 &&
8
+ response.status !== 204
9
+ ) {
10
+ return await response.json()
11
+ } else {
12
+ return await response.text()
13
+ }
14
+ }
15
+
16
+ async function handleError(response, method, url) {
17
+ console.error(`Fetch error: ${method} ${url} ${response.status} ${response.statusText}`)
18
+ console.log(response)
19
+ const contentType = response.headers.get('content-type')
20
+ if (contentType && contentType.indexOf('json') !== -1) {
21
+ const data = await response.json()
22
+ console.log(data)
23
+ }
24
+ }
25
+
3
26
  export async function fetchJSONHandler(
4
27
  url,
5
28
  token,
6
29
  baseUrl,
7
30
  method = 'get',
8
31
  dataVersion = null,
9
- body = null
32
+ body = null,
33
+ fullResponse = false,
34
+ logError = true
10
35
  ) {
11
36
  const headers = {
12
37
  'Content-Type': 'application/json',
@@ -23,23 +48,13 @@ export async function fetchJSONHandler(
23
48
  const response = await fetchHandler(url, token, baseUrl, method, headers, dataVersion, body)
24
49
 
25
50
  if (response.ok) {
26
- const contentType = response.headers.get('content-type')
27
- if (
28
- contentType &&
29
- contentType.indexOf('application/json') !== -1 &&
30
- response.status !== 204
31
- ) {
32
- return await response.json()
33
- } else {
34
- return await response.text()
51
+ if (fullResponse) {
52
+ return response
35
53
  }
54
+ return await message(response)
36
55
  } else {
37
- console.error(`Fetch error: ${method} ${url} ${response.status} ${response.statusText}`)
38
- console.log(response)
39
- const contentType = response.headers.get('content-type')
40
- if (contentType && contentType.indexOf('json') !== -1) {
41
- const data = await response.json()
42
- console.log(data)
56
+ if (logError) {
57
+ await handleError(response, method, url)
43
58
  }
44
59
  }
45
60
  } catch (error) {
@@ -2,7 +2,7 @@
2
2
  * @module LearningPaths
3
3
  */
4
4
 
5
- import { fetchHandler } from '../railcontent.js'
5
+ import { fetchHandler, fetchResponseHandler } from '../railcontent.js'
6
6
  import { fetchByRailContentId, fetchByRailContentIds, fetchMethodV2Structure } from '../sanity.js'
7
7
  import { addContextToLearningPaths } from '../contentAggregator.js'
8
8
  import {
@@ -16,6 +16,7 @@ import { COLLECTION_TYPE, STATE } from '../sync/models/ContentProgress'
16
16
  import { SyncWriteDTO } from '../sync'
17
17
  import { ContentProgress } from '../sync/models'
18
18
  import { CollectionParameter } from '../sync/repositories/content-progress'
19
+ import { getToday } from "../dateUtils.js";
19
20
 
20
21
  const BASE_PATH: string = `/api/content-org`
21
22
  const LEARNING_PATHS_PATH = `${BASE_PATH}/v1/user/learning-paths`
@@ -47,13 +48,19 @@ interface CollectionObject {
47
48
 
48
49
  /**
49
50
  * Gets today's daily session for the user.
51
+ * If the daily session doesn't exist, it will be created.
50
52
  * @param brand
51
53
  * @param userDate
52
54
  */
53
55
  export async function getDailySession(brand: string, userDate: Date) {
54
56
  const stringDate = userDate.toISOString().split('T')[0]
55
57
  const url: string = `${LEARNING_PATHS_PATH}/daily-session/get?brand=${brand}&userDate=${stringDate}`
56
- return (await fetchHandler(url, 'GET', null, null)) as DailySessionResponse
58
+ let options = {dataVersion: null, body: null, fullResponse: true, logError: true}
59
+ const response = await fetchResponseHandler(url, 'GET', options)
60
+ if (response.status === 204) {
61
+ return await updateDailySession(brand, userDate, false)
62
+ }
63
+ return await response.json() as DailySessionResponse
57
64
  }
58
65
 
59
66
  /**
@@ -81,7 +88,6 @@ export async function getActivePath(brand: string) {
81
88
  const url: string = `${LEARNING_PATHS_PATH}/active-path/get?brand=${brand}`
82
89
  return (await fetchHandler(url, 'GET', null, null)) as ActiveLearningPathResponse
83
90
  }
84
-
85
91
  /**
86
92
  * Sets a new learning path as the user's active learning path.
87
93
  * @param brand
@@ -315,13 +321,22 @@ export async function completeMethodIntroVideo(
315
321
  response.intro_video_response = await completeIfNotCompleted(introVideoId)
316
322
 
317
323
  const methodStructure = await fetchMethodV2Structure(brand)
318
- const learningPathId = methodStructure.learning_paths[0].id
324
+ const firstLearningPathId = methodStructure.learning_paths[0].id
319
325
 
320
- response.active_path_response = await startLearningPath(brand, learningPathId)
326
+ response.active_path_response = await methodIntroVideoCompleteActions(brand, firstLearningPathId, getToday())
321
327
 
322
328
  return response
323
329
  }
324
330
 
331
+ async function methodIntroVideoCompleteActions(brand: string, learningPathId: number, userDate: Date) {
332
+ const stringDate = userDate.toISOString().split('T')[0]
333
+ const url: string = `${LEARNING_PATHS_PATH}/method-intro-video-complete-actions`
334
+ const body = { brand: brand, learningPathId: learningPathId, userDate: stringDate }
335
+ return (await fetchHandler(url, 'POST', null, body)) as DailySessionResponse
336
+ }
337
+
338
+
339
+
325
340
  interface completeLearningPathIntroVideo {
326
341
  intro_video_response: SyncWriteDTO<ContentProgress, any> | null
327
342
  learning_path_reset_response: SyncWriteDTO<ContentProgress, any> | null
@@ -649,4 +649,16 @@ export async function fetchHandler(url, method = 'get', dataVersion = null, body
649
649
  dataVersion,
650
650
  body
651
651
  )
652
+ }
653
+ export async function fetchResponseHandler(url, method = 'get', {dataVersion = null, body = null, fullResponse = true, logError = true}) {
654
+ return fetchJSONHandler(
655
+ url,
656
+ globalConfig.sessionConfig.token,
657
+ globalConfig.baseUrl,
658
+ method,
659
+ dataVersion,
660
+ body,
661
+ fullResponse,
662
+ logError,
663
+ )
652
664
  }