musora-content-services 1.4.13 → 1.6.0
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 +14 -0
- package/docs/algolia.js.html +137 -0
- package/docs/config.js.html +29 -5
- package/docs/index.html +2 -2
- package/docs/module-Config.html +108 -7
- package/docs/module-Railcontent-Services.html +551 -31
- package/docs/module-Sanity-Services.html +1999 -73
- package/docs/module-Search-Engine-Services.html +354 -0
- package/docs/railcontent.js.html +41 -4
- package/docs/sanity.js.html +265 -82
- package/jsdoc.json +1 -0
- package/package.json +4 -2
- package/src/index.d.ts +5 -0
- package/src/index.js +5 -0
- package/src/services/algolia.js +64 -0
- package/src/services/config.js +5 -1
- package/src/services/imageSRCVerify.js +0 -0
- package/src/services/sanity.js +4 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Search-Engine-Services
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { globalConfig } from './config'
|
|
6
|
+
import { algoliasearch } from 'algoliasearch'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Sends an event through the search engine API (as of now, algolia)
|
|
10
|
+
*
|
|
11
|
+
* @param {string} index - The index to which the event will be sent.
|
|
12
|
+
* @param {string} queryId - The unique identifier for the search query.
|
|
13
|
+
* @param {string[]} objectIDs - An array of object IDs that were clicked.
|
|
14
|
+
* @param {number[]} positions - An array of positions corresponding to the object IDs clicked.
|
|
15
|
+
*
|
|
16
|
+
* @returns {Promise<void>} - A promise that resolves when the event is sent.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```
|
|
20
|
+
* sendAlgoliaClickEvent(
|
|
21
|
+
* 'production_sanity_all',
|
|
22
|
+
* '43b15df305339e827f0ac0bdc5ebcaa7',
|
|
23
|
+
* ['9780545139700', '9780439784542'],
|
|
24
|
+
* [7, 6]
|
|
25
|
+
* );
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export async function sendAlgoliaClickEvent(index, queryId, objectIDs, positions) {
|
|
29
|
+
if (!queryId || !objectIDs || !positions) {
|
|
30
|
+
throw new Error('queryId, objectIDs, and positions are required parameters.')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (objectIDs.length !== positions.length) {
|
|
34
|
+
throw new Error('objectIDs and positions must have the same length.')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const searchEngine = algoliasearch(
|
|
38
|
+
globalConfig.searchEngineConfig.applicationId,
|
|
39
|
+
globalConfig.searchEngineConfig.apiKey
|
|
40
|
+
).initInsights({
|
|
41
|
+
region: 'us',
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
await searchEngine.pushEvents({
|
|
46
|
+
events: [
|
|
47
|
+
{
|
|
48
|
+
eventType: 'click',
|
|
49
|
+
eventName: 'Content Clicked',
|
|
50
|
+
index: index,
|
|
51
|
+
userToken: globalConfig.railcontentConfig.userId.toString(),
|
|
52
|
+
authenticatedUserToken: globalConfig.railcontentConfig.authToken,
|
|
53
|
+
timestamp: new Date().getTime(),
|
|
54
|
+
objectIDs: objectIDs,
|
|
55
|
+
queryID: queryId,
|
|
56
|
+
positions: positions,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
})
|
|
60
|
+
} catch (error) {
|
|
61
|
+
// Don't throw as it is not a blocker
|
|
62
|
+
console.error('Error sending search event:', error)
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/services/config.js
CHANGED
|
@@ -8,6 +8,7 @@ export let globalConfig = {
|
|
|
8
8
|
sanityConfig: {},
|
|
9
9
|
railcontentConfig: {},
|
|
10
10
|
recommendationsConfig: {},
|
|
11
|
+
searchEngineConfig: {},
|
|
11
12
|
localStorage: null,
|
|
12
13
|
isMA: false,
|
|
13
14
|
localTimezoneString: null, // In format: America/Vancouver
|
|
@@ -40,6 +41,8 @@ const excludeFromGeneratedIndex = []
|
|
|
40
41
|
* @param {string} config.railcontentConfig.authToken - The bearer authorization token.
|
|
41
42
|
* @param {string} config.recommendationsConfig.token - The token for authenticating recommendation requests.
|
|
42
43
|
* @param {string} config.recommendationsConfig.baseUrl - The url for the recommendation server.
|
|
44
|
+
* @param {string} config.searchEngineConfig.applicationId - The application ID for the search engine (e.g., Algolia).
|
|
45
|
+
* @param {string} config.searchEngineConfig.apiKey - The API key for the search engine.
|
|
43
46
|
* @param {Object} config.localStorage - Cache to use for localStorage
|
|
44
47
|
* @param {boolean} config.isMA - Variable that tells if the library is used by MA or FEW
|
|
45
48
|
* @param {string} config.localTimezoneString - The local timezone string in format: America/Vancouver
|
|
@@ -60,7 +63,7 @@ const excludeFromGeneratedIndex = []
|
|
|
60
63
|
* token: 'your-user-api-token',
|
|
61
64
|
* userId: 'current-user-id',
|
|
62
65
|
* baseUrl: 'https://web-staging-one.musora.com',
|
|
63
|
-
* authToken 'your-auth-token',
|
|
66
|
+
* authToken: 'your-auth-token',
|
|
64
67
|
* },
|
|
65
68
|
* recommendationsConfig: {
|
|
66
69
|
* token: 'your-user-api-token',
|
|
@@ -77,6 +80,7 @@ export function initializeService(config) {
|
|
|
77
80
|
globalConfig.isMA = config.isMA || false
|
|
78
81
|
globalConfig.localTimezoneString = config.localTimezoneString || null
|
|
79
82
|
globalConfig.recommendationsConfig = config.recommendationsConfig
|
|
83
|
+
globalConfig.searchEngineConfig = config.searchEngineConfig
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
export function setUserMetadata(userMetaData) {
|
|
File without changes
|
package/src/services/sanity.js
CHANGED
|
@@ -1225,7 +1225,10 @@ export async function fetchLessonContent(railContentId) {
|
|
|
1225
1225
|
"id":railcontent_id,
|
|
1226
1226
|
slug, artist->,
|
|
1227
1227
|
"thumbnail_url":thumbnail.asset->url,
|
|
1228
|
-
"url": web_url_path,
|
|
1228
|
+
"url": web_url_path,
|
|
1229
|
+
"logo_image_url": logo_image_url.asset->url,
|
|
1230
|
+
"dark_logo": dark_mode_logo_url.asset->url,
|
|
1231
|
+
"light_logo": light_mode_logo_url.asset->url,
|
|
1229
1232
|
soundslice_slug,
|
|
1230
1233
|
"description": description[0].children[0].text,
|
|
1231
1234
|
"chapters": chapter[]{
|