musora-content-services 2.99.5 → 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,12 @@
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
+
5
11
  ### [2.99.5](https://github.com/railroadmedia/musora-content-services/compare/v2.99.4...v2.99.5) (2025-12-09)
6
12
 
7
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "2.99.5",
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 {
@@ -48,13 +48,19 @@ interface CollectionObject {
48
48
 
49
49
  /**
50
50
  * Gets today's daily session for the user.
51
+ * If the daily session doesn't exist, it will be created.
51
52
  * @param brand
52
53
  * @param userDate
53
54
  */
54
55
  export async function getDailySession(brand: string, userDate: Date) {
55
56
  const stringDate = userDate.toISOString().split('T')[0]
56
57
  const url: string = `${LEARNING_PATHS_PATH}/daily-session/get?brand=${brand}&userDate=${stringDate}`
57
- 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
58
64
  }
59
65
 
60
66
  /**
@@ -82,7 +88,6 @@ export async function getActivePath(brand: string) {
82
88
  const url: string = `${LEARNING_PATHS_PATH}/active-path/get?brand=${brand}`
83
89
  return (await fetchHandler(url, 'GET', null, null)) as ActiveLearningPathResponse
84
90
  }
85
-
86
91
  /**
87
92
  * Sets a new learning path as the user's active learning path.
88
93
  * @param brand
@@ -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
  }
@@ -1,9 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(rg:*)",
5
- "Bash(npm run lint:*)"
6
- ],
7
- "deny": []
8
- }
9
- }