conexys-elements 1.1.1 → 1.1.2

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,8 @@ 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
+ return localStorage.getItem('cxauthxc');
277
285
  },
278
286
  setSessionId(sessionId, configLogs) {
279
287
  initializeAuthConfig(configLogs);
@@ -287,9 +295,8 @@ const authStorage = {
287
295
  initializeAuthConfig(configLogs);
288
296
  if (USE_COOKIES_FOR_AUTH) {
289
297
  return this.getCookie('cx_session');
290
- } else {
291
- return localStorage.getItem('cx_session');
292
298
  }
299
+ return localStorage.getItem('cx_session');
293
300
  },
294
301
  removeAuthData(configLogs) {
295
302
  initializeAuthConfig(configLogs);
@@ -305,7 +312,8 @@ const authStorage = {
305
312
  const date = new Date();
306
313
  date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
307
314
  const expires = `expires=${date.toUTCString()}`;
308
- document.cookie = `${name}=${value};${expires};path=/;SameSite=Strict;Secure`;
315
+ const secure = window.location.protocol === 'https:' ? ';Secure' : '';
316
+ document.cookie = `${name}=${value};${expires};path=/;SameSite=Strict${secure}`;
309
317
  },
310
318
  getCookie(name) {
311
319
  const nameEQ = `${name}=`;