conexys-elements 1.1.1 → 1.1.3

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/dist/index.esm.js CHANGED
@@ -243,22 +243,31 @@ const config$4 = {
243
243
  let USE_COOKIES_FOR_AUTH = false;
244
244
  let SESSION_EXPIRATION = 365;
245
245
  let isConfigInitialized = false;
246
- const initializeAuthConfig = async configLogs => {
247
- if (isConfigInitialized) return;
248
- const baseURL = Url + 'getsettings';
249
- try {
250
- await serviceData(baseURL, {
251
- keys: 'type_session'
252
- }, config$4, value => {
253
- USE_COOKIES_FOR_AUTH = value === 'cookie';
246
+ let initPromise = null;
247
+ const initializeAuthConfig = configLogs => {
248
+ if (initPromise) return initPromise;
249
+ initPromise = (async () => {
250
+ if (isConfigInitialized) return;
251
+ const baseURL = Url + 'getsettings';
252
+ try {
253
+ await serviceData(baseURL, {
254
+ keys: 'type_session'
255
+ }, config$4, value => {
256
+ USE_COOKIES_FOR_AUTH = value === 'cookie';
257
+ isConfigInitialized = true;
258
+ }, configLogs);
259
+ } catch (error) {
260
+ logConsole(configLogs, 'error', 'Error loading authentication configuration:', error);
261
+ } finally {
254
262
  isConfigInitialized = true;
255
- }, configLogs);
256
- } catch (error) {
257
- logConsole(configLogs, 'error', 'Error loading authentication configuration:', error);
258
- isConfigInitialized = true;
259
- }
263
+ }
264
+ })();
265
+ return initPromise;
260
266
  };
261
267
  const authStorage = {
268
+ initialize(configLogs) {
269
+ return initializeAuthConfig(configLogs);
270
+ },
262
271
  setAuthToken(token, configLogs) {
263
272
  initializeAuthConfig(configLogs);
264
273
  if (USE_COOKIES_FOR_AUTH) {
@@ -271,9 +280,10 @@ const authStorage = {
271
280
  initializeAuthConfig(configLogs);
272
281
  if (USE_COOKIES_FOR_AUTH) {
273
282
  return this.getCookie('cxauthxc');
274
- } else {
275
- return localStorage.getItem('cxauthxc');
276
283
  }
284
+ const local = localStorage.getItem('cxauthxc');
285
+ if (local !== null) return local;
286
+ return this.getCookie('cxauthxc');
277
287
  },
278
288
  setSessionId(sessionId, configLogs) {
279
289
  initializeAuthConfig(configLogs);
@@ -287,9 +297,10 @@ const authStorage = {
287
297
  initializeAuthConfig(configLogs);
288
298
  if (USE_COOKIES_FOR_AUTH) {
289
299
  return this.getCookie('cx_session');
290
- } else {
291
- return localStorage.getItem('cx_session');
292
300
  }
301
+ const local = localStorage.getItem('cx_session');
302
+ if (local !== null) return local;
303
+ return this.getCookie('cx_session');
293
304
  },
294
305
  removeAuthData(configLogs) {
295
306
  initializeAuthConfig(configLogs);
@@ -305,7 +316,8 @@ const authStorage = {
305
316
  const date = new Date();
306
317
  date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
307
318
  const expires = `expires=${date.toUTCString()}`;
308
- document.cookie = `${name}=${value};${expires};path=/;SameSite=Strict;Secure`;
319
+ const secure = window.location.protocol === 'https:' ? ';Secure' : '';
320
+ document.cookie = `${name}=${value};${expires};path=/;SameSite=Strict${secure}`;
309
321
  },
310
322
  getCookie(name) {
311
323
  const nameEQ = `${name}=`;
@@ -10127,8 +10139,8 @@ const initializeSharedServices = () => {
10127
10139
  },
10128
10140
  getAuthData: () => {
10129
10141
  return {
10130
- sessionID: localStorage.getItem('cx_session'),
10131
- authToken: localStorage.getItem('cxauthxc')
10142
+ sessionID: authStorage.getSessionId(configLogs),
10143
+ authToken: authStorage.getAuthToken(configLogs)
10132
10144
  };
10133
10145
  }
10134
10146
  };