musora-content-services 2.1.0 → 2.1.1
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,8 @@
|
|
|
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.1.1](https://github.com/railroadmedia/musora-content-services/compare/v2.1.0...v2.1.1) (2025-03-26)
|
|
6
|
+
|
|
5
7
|
## [2.1.0](https://github.com/railroadmedia/musora-content-services/compare/v2.0.8...v2.1.0) (2025-03-26)
|
|
6
8
|
|
|
7
9
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { globalConfig } from '../services/config.js'
|
|
2
|
+
|
|
3
|
+
export async function fetchJSONHandler(url, token, baseUrl, method = 'get', dataVersion = null, body = null) {
|
|
4
|
+
let headers = {
|
|
5
|
+
'Content-Type': 'application/json',
|
|
6
|
+
Accept: 'application/json',
|
|
7
|
+
'X-CSRF-TOKEN': token,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (!globalConfig.isMA) {
|
|
11
|
+
const params = new URLSearchParams(window.location.search)
|
|
12
|
+
if (params.get('testNow')) {
|
|
13
|
+
headers['testNow'] = params.get('testNow')
|
|
14
|
+
}
|
|
15
|
+
if (params.get('timezone')) {
|
|
16
|
+
headers['M-Client-Timezone'] = params.get('timezone')
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (globalConfig.localTimezoneString) headers['M-Client-Timezone'] = globalConfig.localTimezoneString
|
|
21
|
+
if (dataVersion) headers['Data-Version'] = dataVersion
|
|
22
|
+
const options = {
|
|
23
|
+
method,
|
|
24
|
+
headers,
|
|
25
|
+
}
|
|
26
|
+
if (body) options.body = JSON.stringify(body)
|
|
27
|
+
if (token) options.headers['Authorization'] = `Bearer ${token}`
|
|
28
|
+
if (baseUrl && url.startsWith('/')) url = baseUrl + url
|
|
29
|
+
try {
|
|
30
|
+
const response = await fetch(url, options)
|
|
31
|
+
if (response.ok) {
|
|
32
|
+
const contentType = response.headers.get("content-type");
|
|
33
|
+
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
34
|
+
return await response.json()
|
|
35
|
+
} else {
|
|
36
|
+
return await response.text()
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
console.error(`Fetch error: ${method} ${url} ${response.status} ${response.statusText}`)
|
|
40
|
+
console.log(response)
|
|
41
|
+
}
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error('Fetch error:', error)
|
|
44
|
+
}
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { contentStatusCompleted } from './contentProgress.js'
|
|
5
5
|
|
|
6
6
|
import { globalConfig } from './config.js'
|
|
7
|
+
import { fetchJSONHandler } from '../lib/httpHelper.js'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Exported functions that are excluded from index generation.
|
|
@@ -294,54 +295,6 @@ async function deleteDataHandler(url, data) {
|
|
|
294
295
|
return fetchHandler(url, 'delete')
|
|
295
296
|
}
|
|
296
297
|
|
|
297
|
-
// TODO: this should be extracted to a utility file
|
|
298
|
-
export async function fetchHandler(url, method = 'get', dataVersion = null, body = null) {
|
|
299
|
-
let headers = {
|
|
300
|
-
'Content-Type': 'application/json',
|
|
301
|
-
Accept: 'application/json',
|
|
302
|
-
'X-CSRF-TOKEN': globalConfig.railcontentConfig.token,
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (!globalConfig.isMA) {
|
|
306
|
-
const params = new URLSearchParams(window.location.search)
|
|
307
|
-
if (params.get('testNow')) {
|
|
308
|
-
headers['testNow'] = params.get('testNow')
|
|
309
|
-
}
|
|
310
|
-
if (params.get('timezone')) {
|
|
311
|
-
headers['M-Client-Timezone'] = params.get('timezone')
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (globalConfig.localTimezoneString) {
|
|
316
|
-
headers['M-Client-Timezone'] = globalConfig.localTimezoneString
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (globalConfig.railcontentConfig.authToken) {
|
|
320
|
-
headers['Authorization'] = `Bearer ${globalConfig.railcontentConfig.authToken}`
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
if (dataVersion) headers['Data-Version'] = dataVersion
|
|
324
|
-
const options = {
|
|
325
|
-
method,
|
|
326
|
-
headers,
|
|
327
|
-
}
|
|
328
|
-
if (body) {
|
|
329
|
-
options.body = JSON.stringify(body)
|
|
330
|
-
}
|
|
331
|
-
try {
|
|
332
|
-
const response = await fetchAbsolute(url, options)
|
|
333
|
-
if (response.ok) {
|
|
334
|
-
return await response.json()
|
|
335
|
-
} else {
|
|
336
|
-
console.error(`Fetch error: ${method} ${url} ${response.status} ${response.statusText}`)
|
|
337
|
-
console.log(response)
|
|
338
|
-
}
|
|
339
|
-
} catch (error) {
|
|
340
|
-
console.error('Fetch error:', error)
|
|
341
|
-
}
|
|
342
|
-
return null
|
|
343
|
-
}
|
|
344
|
-
|
|
345
298
|
export async function fetchUserLikes(currentVersion) {
|
|
346
299
|
let url = `/api/content/v1/user/likes`
|
|
347
300
|
return fetchDataHandler(url, currentVersion)
|
|
@@ -1223,15 +1176,12 @@ export async function editComment(commentId, comment) {
|
|
|
1223
1176
|
return await patchDataHandler(url, data)
|
|
1224
1177
|
}
|
|
1225
1178
|
|
|
1226
|
-
function
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
return fetch(url, params)
|
|
1179
|
+
export async function fetchHandler(url, method = 'get', dataVersion = null, body = null) {
|
|
1180
|
+
return fetchJSONHandler(
|
|
1181
|
+
url,
|
|
1182
|
+
globalConfig.railcontentConfig.token,
|
|
1183
|
+
globalConfig.railcontentConfig.baseUrl,
|
|
1184
|
+
method,
|
|
1185
|
+
dataVersion,
|
|
1186
|
+
body)
|
|
1237
1187
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { globalConfig } from './config.js'
|
|
6
|
+
import { fetchJSONHandler} from '../lib/httpHelper.js'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Exported functions that are excluded from index generation.
|
|
@@ -129,44 +130,12 @@ export async function recommendations(brand, {
|
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
async function fetchHandler(url, method = 'get', body = null) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
'X-CSRF-TOKEN': globalConfig.recommendationsConfig.token,
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const options = {
|
|
133
|
+
return fetchJSONHandler(
|
|
134
|
+
url,
|
|
135
|
+
globalConfig.recommendationsConfig.token,
|
|
136
|
+
globalConfig.recommendationsConfig.baseUrl,
|
|
140
137
|
method,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (body) {
|
|
145
|
-
options.body = JSON.stringify(body)
|
|
146
|
-
}
|
|
147
|
-
try {
|
|
148
|
-
const response = await fetchAbsolute(url, options)
|
|
149
|
-
if (response.ok) {
|
|
150
|
-
return await response.json()
|
|
151
|
-
} else {
|
|
152
|
-
console.error(`Fetch error: ${method} ${url} ${response.status} ${response.statusText}`)
|
|
153
|
-
console.log(response)
|
|
154
|
-
}
|
|
155
|
-
} catch (error) {
|
|
156
|
-
console.error('Fetch error:', error)
|
|
157
|
-
}
|
|
158
|
-
return null
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
function fetchAbsolute(url, params) {
|
|
163
|
-
if (globalConfig.recommendationsConfig.token) {
|
|
164
|
-
params.headers['Authorization'] = `Bearer ${globalConfig.recommendationsConfig.token}`
|
|
165
|
-
}
|
|
166
|
-
if (globalConfig.recommendationsConfig.baseUrl) {
|
|
167
|
-
if (url.startsWith('/')) {
|
|
168
|
-
return fetch(globalConfig.recommendationsConfig.baseUrl + url, params)
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return fetch(url, params)
|
|
138
|
+
null,
|
|
139
|
+
body
|
|
140
|
+
)
|
|
172
141
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module User-Management
|
|
3
|
+
*/
|
|
4
|
+
import { fetchHandler } from '../railcontent.js'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Exported functions that are excluded from index generation.
|
|
10
|
+
*
|
|
11
|
+
* @type {string[]}
|
|
12
|
+
*/
|
|
13
|
+
const excludeFromGeneratedIndex = []
|
|
14
|
+
|
|
15
|
+
const baseUrl = `/api/user-management-system`
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Block the provided user
|
|
19
|
+
* @param userId
|
|
20
|
+
* @returns {Promise<any|string|null>}
|
|
21
|
+
*/
|
|
22
|
+
export async function blockUser(userId) {
|
|
23
|
+
const url = `${baseUrl}/v1/block/${userId}`
|
|
24
|
+
return fetchHandler(url, 'post')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Unblock the provided user. Returns a 422 if the user wasn't blocked
|
|
29
|
+
* @param userId
|
|
30
|
+
* @returns {Promise<any|string|null>}
|
|
31
|
+
*/
|
|
32
|
+
export async function unblockUser(userId) {
|
|
33
|
+
const url = `${baseUrl}/v1/unblock/${userId}`
|
|
34
|
+
return fetchHandler(url, 'post')
|
|
35
|
+
}
|