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.js CHANGED
@@ -263,22 +263,31 @@ const config$4 = {
263
263
  let USE_COOKIES_FOR_AUTH = false;
264
264
  let SESSION_EXPIRATION = 365;
265
265
  let isConfigInitialized = false;
266
- const initializeAuthConfig = async configLogs => {
267
- if (isConfigInitialized) return;
268
- const baseURL = Url + 'getsettings';
269
- try {
270
- await serviceData(baseURL, {
271
- keys: 'type_session'
272
- }, config$4, value => {
273
- USE_COOKIES_FOR_AUTH = value === 'cookie';
266
+ let initPromise = null;
267
+ const initializeAuthConfig = configLogs => {
268
+ if (initPromise) return initPromise;
269
+ initPromise = (async () => {
270
+ if (isConfigInitialized) return;
271
+ const baseURL = Url + 'getsettings';
272
+ try {
273
+ await serviceData(baseURL, {
274
+ keys: 'type_session'
275
+ }, config$4, value => {
276
+ USE_COOKIES_FOR_AUTH = value === 'cookie';
277
+ isConfigInitialized = true;
278
+ }, configLogs);
279
+ } catch (error) {
280
+ logConsole(configLogs, 'error', 'Error loading authentication configuration:', error);
281
+ } finally {
274
282
  isConfigInitialized = true;
275
- }, configLogs);
276
- } catch (error) {
277
- logConsole(configLogs, 'error', 'Error loading authentication configuration:', error);
278
- isConfigInitialized = true;
279
- }
283
+ }
284
+ })();
285
+ return initPromise;
280
286
  };
281
287
  const authStorage = {
288
+ initialize(configLogs) {
289
+ return initializeAuthConfig(configLogs);
290
+ },
282
291
  setAuthToken(token, configLogs) {
283
292
  initializeAuthConfig(configLogs);
284
293
  if (USE_COOKIES_FOR_AUTH) {
@@ -291,9 +300,8 @@ const authStorage = {
291
300
  initializeAuthConfig(configLogs);
292
301
  if (USE_COOKIES_FOR_AUTH) {
293
302
  return this.getCookie('cxauthxc');
294
- } else {
295
- return localStorage.getItem('cxauthxc');
296
303
  }
304
+ return localStorage.getItem('cxauthxc');
297
305
  },
298
306
  setSessionId(sessionId, configLogs) {
299
307
  initializeAuthConfig(configLogs);
@@ -307,9 +315,8 @@ const authStorage = {
307
315
  initializeAuthConfig(configLogs);
308
316
  if (USE_COOKIES_FOR_AUTH) {
309
317
  return this.getCookie('cx_session');
310
- } else {
311
- return localStorage.getItem('cx_session');
312
318
  }
319
+ return localStorage.getItem('cx_session');
313
320
  },
314
321
  removeAuthData(configLogs) {
315
322
  initializeAuthConfig(configLogs);
@@ -325,7 +332,8 @@ const authStorage = {
325
332
  const date = new Date();
326
333
  date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
327
334
  const expires = `expires=${date.toUTCString()}`;
328
- document.cookie = `${name}=${value};${expires};path=/;SameSite=Strict;Secure`;
335
+ const secure = window.location.protocol === 'https:' ? ';Secure' : '';
336
+ document.cookie = `${name}=${value};${expires};path=/;SameSite=Strict${secure}`;
329
337
  },
330
338
  getCookie(name) {
331
339
  const nameEQ = `${name}=`;