@nuskin/ns-util 4.7.0-td-341.2 → 4.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-util",
3
- "version": "4.7.0-td-341.2",
3
+ "version": "4.7.0",
4
4
  "baseURL": "/",
5
5
  "main": "src/util.js",
6
6
  "scripts": {
@@ -23,7 +23,6 @@
23
23
  "license": "ISC",
24
24
  "homepage": "https://code.tls.nuskin.io/ns-am/nu-skin-aem/wm/ns-util/blob/master/README.md",
25
25
  "dependencies": {
26
- "@ns/ns-contentstack-lib": "2.2.1",
27
26
  "@nuskin/events": "1.0.4",
28
27
  "@nuskin/ns-common-lib": "1.4.6",
29
28
  "@nuskin/nuskinjquery": "2.3.1",
package/src/storage.js CHANGED
@@ -47,7 +47,8 @@ if (!nuskin.storage) {
47
47
  ROUTER_CALLBACK_URL: "callbackUrl",
48
48
  SHOPPING_CONTEXT: "shoppingContext",
49
49
  SPONSOR_ID: "nuskin.account.sponsorId",
50
- TICKET_COOKIE:"ticketCookie"
50
+ TICKET_COOKIE:"ticketCookie",
51
+ UTM_INFO: "utmInfo"
51
52
  };
52
53
 
53
54
  const LOCAL_STORAGE = "localStorage",
@@ -472,6 +473,11 @@ if (!nuskin.storage) {
472
473
  key: 'skin-consultation-vuex-state',
473
474
  type: REQUIRED,
474
475
  storageType: LOCAL_STORAGE
476
+ },
477
+ UTM_INFO: {
478
+ key: 'utmInfo',
479
+ type: REQUIRED,
480
+ storageType: COOKIE
475
481
  }
476
482
  };
477
483
 
package/src/util.js CHANGED
@@ -22,7 +22,6 @@ export * from './stickyHeader.js';
22
22
  export { default as StickyHeaderStack } from './stickyHeader.js';
23
23
  export { default as storage } from './storage.js';
24
24
  export { default as StringService } from './stringService.js';
25
- export {default as csStringService} from './csStringsService.js';
26
25
  export { default as TdcStrings } from './tdcStrings.js';
27
26
  export { default as AgelocService } from './agelocService.js';
28
27
  export { default as PreferencesCookieService } from './preferencesCookieService.js';
@@ -1,157 +0,0 @@
1
- import { getStack } from '@ns/ns-contentstack-lib';
2
- import * as lodash from "lodash";
3
- import storage from "./storage.js";
4
- import RunConfigService from './runConfigService.js';
5
-
6
- const CONTENT_TYPE_UID = "shared_strings";
7
- const ENTRY_IDS = [
8
- "bltaff9c4bbcf2dfc3f",
9
- "blt715f143c0df06571",
10
- "blt4fc16a923dd994ac",
11
- "blt3cca085912f0ec8d",
12
- "bltaf7f8ce73702b4fe",
13
- "bltd049fc6b4153f131"
14
- ];
15
-
16
-
17
- let currentLocale = "";
18
- let currentStrings = {};
19
- let STRINGS_STORAGE_KEY = "cs-strings-";
20
- let EXPIRE_TIME = 1000 * 60 * 20; // 20 minutes
21
-
22
- /**
23
- * Gets string values for a list of requested strings
24
- *
25
- * @param stringInfos - [{key: value, dflt:value},{key:value, dflt:value}...]
26
- * @param locale - locale of the string
27
- */
28
- async function getStrings (stringsInfo,locale = getLocale().locale) {
29
- await refreshStrings(locale);
30
- return getRequestedStrings(stringsInfo);
31
- }
32
-
33
-
34
- function getLocale() {;
35
- let runConfig = RunConfigService.getRunConfig();
36
- let locale = `${runConfig.language}_${runConfig.country}`;
37
- return {
38
- locale,
39
- country: runConfig.country || 'US',
40
- language: runConfig.language || 'en'
41
- };
42
- };
43
-
44
- function getRequestedStrings(stringInfos) {
45
- let returnVal = {};
46
- stringInfos.forEach((stringInfo) => {
47
- const key = stringInfo.key;
48
- returnVal[key] = (currentStrings && currentStrings[key]) || stringInfo.dflt;
49
- });
50
- return returnVal;
51
- }
52
-
53
- function aemToCsLocale(aemLocale) {
54
- const [language, country] = aemLocale.split("_");
55
- return `${country.toUpperCase()}-${language}`;
56
- }
57
-
58
- async function refreshStrings(locale) {
59
- if (locale !== currentLocale || lodash.isEmpty(currentStrings)) {
60
- currentLocale = locale;
61
- currentStrings = await getStoredStrings(locale);
62
- if (!currentStrings) {
63
- await getServerStrings(locale);
64
- }
65
- }
66
- }
67
-
68
- /**
69
- * Loads the common strings from the cs
70
- *
71
- * @param locale
72
- * @returns {Promise<void>}
73
- */
74
- async function getServerStrings(locale) {
75
- try {
76
- let csLocale = aemToCsLocale(locale);
77
- switch (csLocale) {
78
- case 'ID-in':
79
- csLocale = 'ID-id'
80
- break
81
- default:
82
- }
83
-
84
- const Stack = await getStack();
85
- const allstrings = [];
86
- for(let entryId of ENTRY_IDS) {
87
- const response = await Stack.ContentType(CONTENT_TYPE_UID)
88
- .Entry(entryId)
89
- .only(['strings'])
90
- .language(csLocale)
91
- .includeFallback()
92
- .toJSON()
93
- .fetch()
94
-
95
- if(response && response.strings && Array.isArray(response.strings)){
96
- allstrings.push(...response.strings);
97
- }
98
- }
99
- parseAndSaveCSstrings(allstrings,locale);
100
- } catch (error) {
101
- console.log('Error in fetchStringsFromContentstack', error);
102
- }
103
- }
104
-
105
- function parseAndSaveCSstrings(allstrings,locale) {
106
- try{
107
- currentStrings = allstrings.reduce((acc, string) => {
108
- acc[string.key] = string.value;
109
- return acc;
110
- }, {});
111
- saveServerStrings(currentStrings,locale);
112
- }
113
- catch (error) {
114
- console.log('Error in parseAndSaveCSstrings', error);
115
- }
116
- }
117
-
118
- /**
119
- * Loads the common strings previously stored in sessionStorage
120
- * @param locale
121
- * @returns {*}
122
- */
123
- function getStoredStrings(locale) {
124
- let strings = null;
125
- if (storage) {
126
- strings = storage.getItem({
127
- storageType: "sessionStorage",
128
- key: `${STRINGS_STORAGE_KEY}${locale}`
129
- });
130
- }
131
- return strings;
132
- }
133
-
134
- /**
135
- * Saves the common strings to sessionStorage for the specified ttl
136
- *
137
- * @param strings
138
- * @param locale
139
- */
140
- function saveServerStrings(strings,locale) {
141
- storage.setItem(
142
- { storageType: "sessionStorage", key: `${STRINGS_STORAGE_KEY}${locale}` },
143
- strings,
144
- { ttl: EXPIRE_TIME }
145
- );
146
- }
147
-
148
- /**
149
- *
150
- * csStringService
151
- * Service to get common strings from contentstack
152
- *
153
- * @namespace csStringService
154
- */
155
- export default {
156
- getStrings
157
- }