musora-content-services 1.0.140 → 1.0.141

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
+ ### [1.0.141](https://github.com/railroadmedia/musora-content-services/compare/v1.0.140...v1.0.141) (2024-10-17)
6
+
5
7
  ### [1.0.140](https://github.com/railroadmedia/musora-content-services/compare/v1.0.139...v1.0.140) (2024-10-16)
6
8
 
7
9
  ### [1.0.139](https://github.com/railroadmedia/musora-content-services/compare/v1.0.137...v1.0.139) (2024-10-16)
package/link_mcs.sh CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.140",
3
+ "version": "1.0.141",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -5,7 +5,8 @@
5
5
  let globalConfig = {
6
6
  sanityConfig: {},
7
7
  railcontentConfig: {},
8
- localStorage: null
8
+ localStorage: null,
9
+ isMA: false,
9
10
  };
10
11
 
11
12
  /**
@@ -33,6 +34,7 @@ const excludeFromGeneratedIndex = [];
33
34
  * @param {string} config.railcontentConfig.userId - The user ID for fetching user-specific data.
34
35
  * @param {string} config.railcontentConfig.baseUrl - The url for the enviroment.
35
36
  * @param {Object} config.localStorage - Cache to use for localStorage
37
+ * @param {boolean} config.isMA - Variable that tells if the library is used by MA or FEW
36
38
 
37
39
  *
38
40
  * @example
@@ -51,13 +53,15 @@ const excludeFromGeneratedIndex = [];
51
53
  * userId: 'current-user-id',
52
54
  * baseUrl: 'https://web-staging-one.musora.com'
53
55
  * },
54
- * localStorage: localStorage
56
+ * localStorage: localStorage,
57
+ * isMA: false
55
58
  * });
56
59
  */
57
60
  function initializeService(config) {
58
61
  globalConfig.sanityConfig = config.sanityConfig;
59
62
  globalConfig.railcontentConfig = config.railcontentConfig;
60
63
  globalConfig.localStorage = config.localStorage;
64
+ globalConfig.isMA = config.isMA || false;
61
65
  }
62
66
 
63
67
  // Export both the initialization function and the config object
@@ -23,7 +23,7 @@ export class DataContext {
23
23
  }
24
24
 
25
25
  async getData() {
26
- this.ensureLocalContextLoaded();
26
+ await this.ensureLocalContextLoaded();
27
27
  if (!this.context || this.shouldVerifyServerVerions()) {
28
28
  let version = this.version();
29
29
  let data = await this.fetchData(version);
@@ -40,10 +40,10 @@ export class DataContext {
40
40
  return await this.fetchDataFunction(version);
41
41
  }
42
42
 
43
- ensureLocalContextLoaded() {
43
+ async ensureLocalContextLoaded() {
44
44
  if (this.context) return;
45
45
  this.verifyConfig();
46
- let localData = cache.getItem(this.localStorageKey);
46
+ let localData = globalConfig.isMA ? await cache.getItem(this.localStorageKey): cache.getItem(this.localStorageKey) ;
47
47
  if (localData) {
48
48
  this.context = JSON.parse(localData);
49
49
  }
@@ -56,8 +56,8 @@ export class DataContext {
56
56
  }
57
57
  }
58
58
 
59
- shouldVerifyServerVerions() {
60
- let lastUpdated = cache.getItem(this.localStorageLastUpdatedKey);
59
+ async shouldVerifyServerVerions() {
60
+ let lastUpdated = globalConfig.isMA ? await cache.getItem(this.localStorageLastUpdatedKey) : cache.getItem(this.localStorageLastUpdatedKey);
61
61
  if (!lastUpdated) return false;
62
62
  const verifyServerTime = 10000; //10 s
63
63
  return (new Date().getTime() - lastUpdated) > verifyServerTime;
@@ -74,7 +74,7 @@ export class DataContext {
74
74
  }
75
75
 
76
76
  async update(localUpdateFunction, serverUpdateFunction) {
77
- this.ensureLocalContextLoaded();
77
+ await this.ensureLocalContextLoaded();
78
78
  if (this.context) {
79
79
  localUpdateFunction(this.context);
80
80
  this.context.version++;