@klauswuestefeld/jux-web 2025.6.30 → 2025.9.5

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.
@@ -1,11 +1,3 @@
1
- export {};
2
- declare global {
3
- interface Window {
4
- store: {
5
- backendToken?: string;
6
- };
7
- }
8
- }
9
1
  export declare const setBackendUrl: (backendUrl: string) => void;
10
2
  export declare const getBackendUrl: () => string;
11
3
  export declare const handleJuxEvent: (ev: Event) => void;
@@ -1 +1 @@
1
- export declare const contactField: (tag: string | undefined, elType: string, elName: string, required?: boolean, value?: string) => HTMLElement;
1
+ export declare const contactField: (tag: string | undefined, elType: string, elName: string, required?: boolean, value?: string | null) => HTMLElement;
@@ -0,0 +1,3 @@
1
+ import { CurrentUser } from '../jux-web-global';
2
+ export declare const resetJuxWebGlobal: () => void;
3
+ export declare const getCurrentUser: () => CurrentUser | undefined;
@@ -0,0 +1,22 @@
1
+ export declare class SelectedTeam {
2
+ admin?: string;
3
+ }
4
+ export declare class CurrentUser {
5
+ token: string;
6
+ admin?: boolean;
7
+ email: string;
8
+ name?: string;
9
+ constructor(token: string, admin: boolean, email: string);
10
+ }
11
+ export declare class JuxWebGlobal {
12
+ private _currentUser?;
13
+ private _backendToken?;
14
+ selectedTeam?: SelectedTeam;
15
+ fetchUserBackendUrl?: any;
16
+ magicLinkAuthEndpoint?: string;
17
+ magicLinkRequestEndpoint?: string;
18
+ setCurrentUser(newUser: CurrentUser): void;
19
+ getCurrentUser(): CurrentUser | undefined;
20
+ setBackendToken(token: string): void;
21
+ getBackendToken(): string | undefined;
22
+ }
package/dist/jux-web.js CHANGED
@@ -163,14 +163,12 @@ var juxWeb = (function (exports) {
163
163
  const getApiUrl = () => getBackendUrl() + 'api/';
164
164
  const getMagicAuthUrl = () => {
165
165
  var _a;
166
- // @ts-ignore
167
- const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
166
+ const endpoint = ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
168
167
  return getBackendUrl() + endpoint + '?token=';
169
168
  };
170
169
  const getMagicAuthReqUrl = () => {
171
170
  var _a;
172
- // @ts-ignore
173
- const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
171
+ const endpoint = ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
174
172
  return getBackendUrl() + endpoint + '?email=';
175
173
  };
176
174
  // TODO: use jux-events to call commands and queries inside jux-web library
@@ -226,13 +224,13 @@ var juxWeb = (function (exports) {
226
224
  backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, retrial, retrialNum, extras);
227
225
  });
228
226
  const uploadRequest = (url, file, onSuccess, onError, extras) => {
229
- var _a, _b;
227
+ var _a;
230
228
  requestRunning = true;
231
229
  const xhr = new XMLHttpRequest();
232
230
  xhr.open('POST', url);
233
- if ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.backendToken) {
234
- xhr.setRequestHeader('auth', (_b = window.juxwebGlobal) === null || _b === void 0 ? void 0 : _b.backendToken);
235
- }
231
+ const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
232
+ if (backendToken)
233
+ xhr.setRequestHeader('auth', backendToken);
236
234
  xhr.upload.onprogress = (e) => {
237
235
  if (e.lengthComputable && (extras === null || extras === void 0 ? void 0 : extras.onProgress)) {
238
236
  extras.onProgress(Math.round((e.loaded / e.total) * 100));
@@ -268,11 +266,10 @@ var juxWeb = (function (exports) {
268
266
  setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false, retrialNum), 300);
269
267
  return;
270
268
  }
271
- // @ts-ignore
272
269
  const headers = new Headers(options.headers);
273
- if ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.backendToken) {
274
- headers.set('auth', window.juxwebGlobal.backendToken);
275
- }
270
+ const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
271
+ if (backendToken)
272
+ headers.set('auth', backendToken);
276
273
  let response;
277
274
  requestRunning = true;
278
275
  const controller = new AbortController();
@@ -346,7 +343,14 @@ var juxWeb = (function (exports) {
346
343
  return;
347
344
  }
348
345
  try {
349
- const jsonResponse = yield response.json();
346
+ let jsonResponse = {};
347
+ try {
348
+ jsonResponse = yield response.json();
349
+ }
350
+ catch (e) {
351
+ jsonResponse = { error: 'Unexpected response', expected: false };
352
+ console.error('Unexpected response', e, response);
353
+ }
350
354
  if (response.ok) {
351
355
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(jsonResponse);
352
356
  return;
@@ -14044,9 +14048,9 @@ var juxWeb = (function (exports) {
14044
14048
  if (googleUser) {
14045
14049
  // mixpanelIdentify(googleUser); TODO
14046
14050
  const onSuccess = (res) => {
14051
+ var _a;
14047
14052
  const { token } = res;
14048
- // @ts-ignore
14049
- window.juxwebGlobal.currentUser = res;
14053
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
14050
14054
  onTokenAcquired(token, onUserLogin);
14051
14055
  };
14052
14056
  const onError = (err) => {
@@ -14398,12 +14402,11 @@ var juxWeb = (function (exports) {
14398
14402
  // checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
14399
14403
  };
14400
14404
  const contactUsModal = (subject) => {
14401
- var _a, _b, _c, _d, _e;
14405
+ var _a, _b, _c, _d, _e, _f, _g, _h;
14402
14406
  const result = document.createElement('contact-us-modal');
14403
- // @ts-ignore
14404
- const currentName = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.name : '';
14405
- // @ts-ignore
14406
- const currentEmail = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
14407
+ const currentUser = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
14408
+ const currentName = currentUser ? currentUser.name : '';
14409
+ const currentEmail = currentUser ? currentUser.email : (_b = document.querySelector('#magic-link-email')) === null || _b === void 0 ? void 0 : _b.textContent;
14407
14410
  const modalBody = document.createElement('modal-body');
14408
14411
  const form = document.createElement('form');
14409
14412
  form.id = 'contact-form';
@@ -14419,11 +14422,10 @@ var juxWeb = (function (exports) {
14419
14422
  const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
14420
14423
  modal.id = 'contact-us-modal';
14421
14424
  document.body.appendChild(modal);
14422
- (_b = modal.querySelector('modal-wrapper')) === null || _b === void 0 ? void 0 : _b.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
14425
+ (_c = modal.querySelector('modal-wrapper')) === null || _c === void 0 ? void 0 : _c.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
14423
14426
  const captcha = googleCaptcha();
14424
14427
  if (subject !== 'email-not-sent') {
14425
- // @ts-ignore
14426
- const admin = ((_d = (_c = window.juxwebGlobal) === null || _c === void 0 ? void 0 : _c.selectedTeam) === null || _d === void 0 ? void 0 : _d.admin) || window.juxwebGlobal.currentUser.email;
14428
+ const admin = ((_e = (_d = window.juxWebGlobal) === null || _d === void 0 ? void 0 : _d.selectedTeam) === null || _e === void 0 ? void 0 : _e.admin) || ((_g = (_f = window.juxWebGlobal) === null || _f === void 0 ? void 0 : _f.getCurrentUser()) === null || _g === void 0 ? void 0 : _g.email);
14427
14429
  backendGet('credits-balance-for', { admin }, (res) => {
14428
14430
  const balance = res;
14429
14431
  if (balance <= 0) {
@@ -14435,7 +14437,7 @@ var juxWeb = (function (exports) {
14435
14437
  else {
14436
14438
  form.insertBefore(captcha, btn);
14437
14439
  }
14438
- (_e = nameField.querySelector('input')) === null || _e === void 0 ? void 0 : _e.select();
14440
+ (_h = nameField.querySelector('input')) === null || _h === void 0 ? void 0 : _h.select();
14439
14441
  form.addEventListener('submit', (event) => {
14440
14442
  event.preventDefault();
14441
14443
  sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
@@ -14555,18 +14557,39 @@ var juxWeb = (function (exports) {
14555
14557
  return result;
14556
14558
  };
14557
14559
 
14560
+ class JuxWebGlobal {
14561
+ setCurrentUser(newUser) {
14562
+ this._currentUser = newUser;
14563
+ }
14564
+ getCurrentUser() {
14565
+ return this._currentUser;
14566
+ }
14567
+ setBackendToken(token) {
14568
+ this._backendToken = token;
14569
+ }
14570
+ getBackendToken() {
14571
+ return this._backendToken;
14572
+ }
14573
+ }
14574
+
14575
+ const resetJuxWebGlobal = () => {
14576
+ window.juxWebGlobal = new JuxWebGlobal();
14577
+ };
14578
+ const getCurrentUser = () => {
14579
+ var _a;
14580
+ return (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
14581
+ };
14582
+
14558
14583
  const setBackendToken = (token) => {
14559
- // @ts-ignore
14560
- window.juxwebGlobal.backendToken = token;
14561
- if (token) {
14584
+ var _a;
14585
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setBackendToken(token);
14586
+ if (token)
14562
14587
  setLocalStorageItem('token', token);
14563
- }
14564
14588
  };
14565
14589
  const getBackendToken = () => {
14566
- var _a;
14590
+ var _a, _b;
14567
14591
  const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
14568
- // @ts-ignore
14569
- window.juxwebGlobal.backendToken = token;
14592
+ (_b = window.juxWebGlobal) === null || _b === void 0 ? void 0 : _b.setBackendToken(token);
14570
14593
  return token;
14571
14594
  };
14572
14595
  const onTokenAcquired = (token, onUserLogin) => {
@@ -14576,8 +14599,7 @@ var juxWeb = (function (exports) {
14576
14599
  };
14577
14600
  const clearSession = () => {
14578
14601
  removeLocalStorageItem('token');
14579
- // @ts-ignore
14580
- window.juxwebGlobal = {};
14602
+ resetJuxWebGlobal();
14581
14603
  };
14582
14604
  const onAuthenticationFailure = (msg) => {
14583
14605
  removeLocalStorageItem('token');
@@ -14585,11 +14607,11 @@ var juxWeb = (function (exports) {
14585
14607
  alert(getTranslation(msg));
14586
14608
  };
14587
14609
  const onAuthentication = (onUserLogin, user, type) => {
14610
+ var _a;
14588
14611
  if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
14589
14612
  clearSession();
14590
14613
  }
14591
- // @ts-ignore
14592
- window.juxwebGlobal.currentUser = user;
14614
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(user);
14593
14615
  if (type === 'Token Authentication') {
14594
14616
  user.token = getLocalStorageItem('token');
14595
14617
  }
@@ -14628,17 +14650,11 @@ var juxWeb = (function (exports) {
14628
14650
  // initDemo(setBackendToken, onAuthentication);
14629
14651
  // return;
14630
14652
  // }
14631
- // @ts-ignore
14632
- if (!window.juxwebGlobal) {
14633
- // @ts-ignore
14634
- window.juxwebGlobal = {};
14635
- }
14636
- // @ts-ignore
14637
- window.juxwebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
14638
- // @ts-ignore
14639
- window.juxwebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
14640
- // @ts-ignore
14641
- window.juxwebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
14653
+ if (!window.juxWebGlobal)
14654
+ window.juxWebGlobal = new JuxWebGlobal();
14655
+ window.juxWebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
14656
+ window.juxWebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
14657
+ window.juxWebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
14642
14658
  if (urlPrefix)
14643
14659
  setUrlPrefix(urlPrefix);
14644
14660
  const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
@@ -14648,8 +14664,7 @@ var juxWeb = (function (exports) {
14648
14664
  };
14649
14665
  const host = extractTokenFromWindowLocation('host');
14650
14666
  if (host) {
14651
- // @ts-ignore
14652
- window.juxwebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
14667
+ window.juxWebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
14653
14668
  setBackendUrl(backendUrl);
14654
14669
  onOpenMagicLink();
14655
14670
  });
@@ -14692,9 +14707,9 @@ var juxWeb = (function (exports) {
14692
14707
  const loginResponse = yield msalInstance.loginPopup(loginRequest);
14693
14708
  const { accessToken } = loginResponse;
14694
14709
  const onSuccess = (res) => {
14710
+ var _a;
14695
14711
  const { token } = res;
14696
- // @ts-ignore
14697
- window.juxwebGlobal.currentUser = res;
14712
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
14698
14713
  onTokenAcquired(token, onUserLogin);
14699
14714
  disableSignInLayout();
14700
14715
  };
@@ -14725,9 +14740,9 @@ var juxWeb = (function (exports) {
14725
14740
  const { email } = credentials;
14726
14741
  enableSignInLayout();
14727
14742
  const onSuccess = (res) => {
14743
+ var _a;
14728
14744
  const { token } = res;
14729
- // @ts-ignore
14730
- window.juxwebGlobal.currentUser = res;
14745
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
14731
14746
  onTokenAcquired(token, onUserLogin);
14732
14747
  disableSignInLayout();
14733
14748
  };
@@ -14745,6 +14760,7 @@ var juxWeb = (function (exports) {
14745
14760
  authPasswordLogin(credentials, onSuccess, onError, onUnauthorized);
14746
14761
  };
14747
14762
  const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
14763
+ var _a;
14748
14764
  if (!email) {
14749
14765
  const mailMagic = document.querySelector('#mail-magic');
14750
14766
  email = mailMagic.value;
@@ -14761,10 +14777,8 @@ var juxWeb = (function (exports) {
14761
14777
  const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
14762
14778
  requestMagicLink(payload, onSuccess, onUnauthorized);
14763
14779
  };
14764
- // @ts-ignore
14765
- if (window.juxwebGlobal.fetchUserBackendUrl) {
14766
- // @ts-ignore
14767
- window.juxwebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
14780
+ if ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.fetchUserBackendUrl) {
14781
+ window.juxWebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
14768
14782
  setBackendUrl(backendUrl);
14769
14783
  onRequestMagicLink();
14770
14784
  });
@@ -15019,6 +15033,7 @@ var juxWeb = (function (exports) {
15019
15033
  exports.chosenLanguage = chosenLanguage;
15020
15034
  exports.clearSession = clearSession;
15021
15035
  exports.command = command;
15036
+ exports.getCurrentUser = getCurrentUser;
15022
15037
  exports.getTranslation = getTranslation;
15023
15038
  exports.handleJuxEvent = handleJuxEvent;
15024
15039
  exports.handleMagicLinkRequest = handleMagicLinkRequest;
@@ -15031,6 +15046,7 @@ var juxWeb = (function (exports) {
15031
15046
  exports.query = query;
15032
15047
  exports.reloadWithLanguageOverride = reloadWithLanguageOverride;
15033
15048
  exports.requestMagicLink = requestMagicLink;
15049
+ exports.resetJuxWebGlobal = resetJuxWebGlobal;
15034
15050
  exports.upload = upload;
15035
15051
 
15036
15052
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -8,8 +8,8 @@ interface InitSessionParams {
8
8
  onLoginError: any;
9
9
  backgroundImage: string;
10
10
  fetchUserBackendUrl: any;
11
- magicLinkRequestEndpoint: string | null;
12
- magicLinkAuthEndpoint: string | null;
11
+ magicLinkRequestEndpoint?: string;
12
+ magicLinkAuthEndpoint?: string;
13
13
  urlPrefix: string;
14
14
  }
15
15
  export declare const initSession: ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint, urlPrefix }: InitSessionParams) => void;
package/dist/main.d.ts CHANGED
@@ -5,6 +5,7 @@ export { handleMagicLinkRequest, initSession, onMicrosoftSignIn, clearSession }
5
5
  export { handleJuxEvent, requestMagicLink, upload } from './api-client';
6
6
  export { magicLinkModal } from './login/magic-link-modal';
7
7
  export { command, query } from './jux/jux-event';
8
+ export { getCurrentUser, resetJuxWebGlobal } from './jux/jux-web-global/utils';
8
9
  declare global {
9
10
  interface Window {
10
11
  submitCaptcha: any;
package/dist/main.esm.js CHANGED
@@ -162,14 +162,12 @@ const getSecondaryBackendUrl = () => process.env.STAGING_BACKEND_URL || getBacke
162
162
  const getApiUrl = () => getBackendUrl() + 'api/';
163
163
  const getMagicAuthUrl = () => {
164
164
  var _a;
165
- // @ts-ignore
166
- const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
165
+ const endpoint = ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
167
166
  return getBackendUrl() + endpoint + '?token=';
168
167
  };
169
168
  const getMagicAuthReqUrl = () => {
170
169
  var _a;
171
- // @ts-ignore
172
- const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
170
+ const endpoint = ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
173
171
  return getBackendUrl() + endpoint + '?email=';
174
172
  };
175
173
  // TODO: use jux-events to call commands and queries inside jux-web library
@@ -225,13 +223,13 @@ const apiRequest = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1], v
225
223
  backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, retrial, retrialNum, extras);
226
224
  });
227
225
  const uploadRequest = (url, file, onSuccess, onError, extras) => {
228
- var _a, _b;
226
+ var _a;
229
227
  requestRunning = true;
230
228
  const xhr = new XMLHttpRequest();
231
229
  xhr.open('POST', url);
232
- if ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.backendToken) {
233
- xhr.setRequestHeader('auth', (_b = window.juxwebGlobal) === null || _b === void 0 ? void 0 : _b.backendToken);
234
- }
230
+ const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
231
+ if (backendToken)
232
+ xhr.setRequestHeader('auth', backendToken);
235
233
  xhr.upload.onprogress = (e) => {
236
234
  if (e.lengthComputable && (extras === null || extras === void 0 ? void 0 : extras.onProgress)) {
237
235
  extras.onProgress(Math.round((e.loaded / e.total) * 100));
@@ -267,11 +265,10 @@ const backendRequest = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1
267
265
  setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false, retrialNum), 300);
268
266
  return;
269
267
  }
270
- // @ts-ignore
271
268
  const headers = new Headers(options.headers);
272
- if ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.backendToken) {
273
- headers.set('auth', window.juxwebGlobal.backendToken);
274
- }
269
+ const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
270
+ if (backendToken)
271
+ headers.set('auth', backendToken);
275
272
  let response;
276
273
  requestRunning = true;
277
274
  const controller = new AbortController();
@@ -345,7 +342,14 @@ const backendRequest = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1
345
342
  return;
346
343
  }
347
344
  try {
348
- const jsonResponse = yield response.json();
345
+ let jsonResponse = {};
346
+ try {
347
+ jsonResponse = yield response.json();
348
+ }
349
+ catch (e) {
350
+ jsonResponse = { error: 'Unexpected response', expected: false };
351
+ console.error('Unexpected response', e, response);
352
+ }
349
353
  if (response.ok) {
350
354
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(jsonResponse);
351
355
  return;
@@ -529,9 +533,9 @@ const onUserChanged = (googleUser, onUserLogin) => {
529
533
  if (googleUser) {
530
534
  // mixpanelIdentify(googleUser); TODO
531
535
  const onSuccess = (res) => {
536
+ var _a;
532
537
  const { token } = res;
533
- // @ts-ignore
534
- window.juxwebGlobal.currentUser = res;
538
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
535
539
  onTokenAcquired(token, onUserLogin);
536
540
  };
537
541
  const onError = (err) => {
@@ -883,12 +887,11 @@ const sendInquiry = (name, email, msg, whatsapp, subject, token) => {
883
887
  // checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
884
888
  };
885
889
  const contactUsModal = (subject) => {
886
- var _a, _b, _c, _d, _e;
890
+ var _a, _b, _c, _d, _e, _f, _g, _h;
887
891
  const result = document.createElement('contact-us-modal');
888
- // @ts-ignore
889
- const currentName = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.name : '';
890
- // @ts-ignore
891
- const currentEmail = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
892
+ const currentUser = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
893
+ const currentName = currentUser ? currentUser.name : '';
894
+ const currentEmail = currentUser ? currentUser.email : (_b = document.querySelector('#magic-link-email')) === null || _b === void 0 ? void 0 : _b.textContent;
892
895
  const modalBody = document.createElement('modal-body');
893
896
  const form = document.createElement('form');
894
897
  form.id = 'contact-form';
@@ -904,11 +907,10 @@ const contactUsModal = (subject) => {
904
907
  const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
905
908
  modal.id = 'contact-us-modal';
906
909
  document.body.appendChild(modal);
907
- (_b = modal.querySelector('modal-wrapper')) === null || _b === void 0 ? void 0 : _b.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
910
+ (_c = modal.querySelector('modal-wrapper')) === null || _c === void 0 ? void 0 : _c.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
908
911
  const captcha = googleCaptcha();
909
912
  if (subject !== 'email-not-sent') {
910
- // @ts-ignore
911
- const admin = ((_d = (_c = window.juxwebGlobal) === null || _c === void 0 ? void 0 : _c.selectedTeam) === null || _d === void 0 ? void 0 : _d.admin) || window.juxwebGlobal.currentUser.email;
913
+ const admin = ((_e = (_d = window.juxWebGlobal) === null || _d === void 0 ? void 0 : _d.selectedTeam) === null || _e === void 0 ? void 0 : _e.admin) || ((_g = (_f = window.juxWebGlobal) === null || _f === void 0 ? void 0 : _f.getCurrentUser()) === null || _g === void 0 ? void 0 : _g.email);
912
914
  backendGet('credits-balance-for', { admin }, (res) => {
913
915
  const balance = res;
914
916
  if (balance <= 0) {
@@ -920,7 +922,7 @@ const contactUsModal = (subject) => {
920
922
  else {
921
923
  form.insertBefore(captcha, btn);
922
924
  }
923
- (_e = nameField.querySelector('input')) === null || _e === void 0 ? void 0 : _e.select();
925
+ (_h = nameField.querySelector('input')) === null || _h === void 0 ? void 0 : _h.select();
924
926
  form.addEventListener('submit', (event) => {
925
927
  event.preventDefault();
926
928
  sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
@@ -1040,18 +1042,39 @@ const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn, failInfo) =>
1040
1042
  return result;
1041
1043
  };
1042
1044
 
1045
+ class JuxWebGlobal {
1046
+ setCurrentUser(newUser) {
1047
+ this._currentUser = newUser;
1048
+ }
1049
+ getCurrentUser() {
1050
+ return this._currentUser;
1051
+ }
1052
+ setBackendToken(token) {
1053
+ this._backendToken = token;
1054
+ }
1055
+ getBackendToken() {
1056
+ return this._backendToken;
1057
+ }
1058
+ }
1059
+
1060
+ const resetJuxWebGlobal = () => {
1061
+ window.juxWebGlobal = new JuxWebGlobal();
1062
+ };
1063
+ const getCurrentUser = () => {
1064
+ var _a;
1065
+ return (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
1066
+ };
1067
+
1043
1068
  const setBackendToken = (token) => {
1044
- // @ts-ignore
1045
- window.juxwebGlobal.backendToken = token;
1046
- if (token) {
1069
+ var _a;
1070
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setBackendToken(token);
1071
+ if (token)
1047
1072
  setLocalStorageItem('token', token);
1048
- }
1049
1073
  };
1050
1074
  const getBackendToken = () => {
1051
- var _a;
1075
+ var _a, _b;
1052
1076
  const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
1053
- // @ts-ignore
1054
- window.juxwebGlobal.backendToken = token;
1077
+ (_b = window.juxWebGlobal) === null || _b === void 0 ? void 0 : _b.setBackendToken(token);
1055
1078
  return token;
1056
1079
  };
1057
1080
  const onTokenAcquired = (token, onUserLogin) => {
@@ -1061,8 +1084,7 @@ const onTokenAcquired = (token, onUserLogin) => {
1061
1084
  };
1062
1085
  const clearSession = () => {
1063
1086
  removeLocalStorageItem('token');
1064
- // @ts-ignore
1065
- window.juxwebGlobal = {};
1087
+ resetJuxWebGlobal();
1066
1088
  };
1067
1089
  const onAuthenticationFailure = (msg) => {
1068
1090
  removeLocalStorageItem('token');
@@ -1070,11 +1092,11 @@ const onAuthenticationFailure = (msg) => {
1070
1092
  alert(getTranslation(msg));
1071
1093
  };
1072
1094
  const onAuthentication = (onUserLogin, user, type) => {
1095
+ var _a;
1073
1096
  if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
1074
1097
  clearSession();
1075
1098
  }
1076
- // @ts-ignore
1077
- window.juxwebGlobal.currentUser = user;
1099
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(user);
1078
1100
  if (type === 'Token Authentication') {
1079
1101
  user.token = getLocalStorageItem('token');
1080
1102
  }
@@ -1113,17 +1135,11 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
1113
1135
  // initDemo(setBackendToken, onAuthentication);
1114
1136
  // return;
1115
1137
  // }
1116
- // @ts-ignore
1117
- if (!window.juxwebGlobal) {
1118
- // @ts-ignore
1119
- window.juxwebGlobal = {};
1120
- }
1121
- // @ts-ignore
1122
- window.juxwebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
1123
- // @ts-ignore
1124
- window.juxwebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
1125
- // @ts-ignore
1126
- window.juxwebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
1138
+ if (!window.juxWebGlobal)
1139
+ window.juxWebGlobal = new JuxWebGlobal();
1140
+ window.juxWebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
1141
+ window.juxWebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
1142
+ window.juxWebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
1127
1143
  if (urlPrefix)
1128
1144
  setUrlPrefix(urlPrefix);
1129
1145
  const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
@@ -1133,8 +1149,7 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
1133
1149
  };
1134
1150
  const host = extractTokenFromWindowLocation('host');
1135
1151
  if (host) {
1136
- // @ts-ignore
1137
- window.juxwebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
1152
+ window.juxWebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
1138
1153
  setBackendUrl(backendUrl);
1139
1154
  onOpenMagicLink();
1140
1155
  });
@@ -1177,9 +1192,9 @@ const onMicrosoftSignIn = (onUserLogin) => __awaiter(void 0, void 0, void 0, fun
1177
1192
  const loginResponse = yield msalInstance.loginPopup(loginRequest);
1178
1193
  const { accessToken } = loginResponse;
1179
1194
  const onSuccess = (res) => {
1195
+ var _a;
1180
1196
  const { token } = res;
1181
- // @ts-ignore
1182
- window.juxwebGlobal.currentUser = res;
1197
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
1183
1198
  onTokenAcquired(token, onUserLogin);
1184
1199
  disableSignInLayout();
1185
1200
  };
@@ -1210,9 +1225,9 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
1210
1225
  const { email } = credentials;
1211
1226
  enableSignInLayout();
1212
1227
  const onSuccess = (res) => {
1228
+ var _a;
1213
1229
  const { token } = res;
1214
- // @ts-ignore
1215
- window.juxwebGlobal.currentUser = res;
1230
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
1216
1231
  onTokenAcquired(token, onUserLogin);
1217
1232
  disableSignInLayout();
1218
1233
  };
@@ -1230,6 +1245,7 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
1230
1245
  authPasswordLogin(credentials, onSuccess, onError, onUnauthorized);
1231
1246
  };
1232
1247
  const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
1248
+ var _a;
1233
1249
  if (!email) {
1234
1250
  const mailMagic = document.querySelector('#mail-magic');
1235
1251
  email = mailMagic.value;
@@ -1246,10 +1262,8 @@ const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, c
1246
1262
  const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
1247
1263
  requestMagicLink(payload, onSuccess, onUnauthorized);
1248
1264
  };
1249
- // @ts-ignore
1250
- if (window.juxwebGlobal.fetchUserBackendUrl) {
1251
- // @ts-ignore
1252
- window.juxwebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
1265
+ if ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.fetchUserBackendUrl) {
1266
+ window.juxWebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
1253
1267
  setBackendUrl(backendUrl);
1254
1268
  onRequestMagicLink();
1255
1269
  });
@@ -1501,4 +1515,4 @@ const command = (element, endpoint, onResult, params, onError, onRedirect) => {
1501
1515
  element.dispatchEvent(new JuxEvent('command', 'POST', endpoint, onResult, params, onError, onRedirect));
1502
1516
  };
1503
1517
 
1504
- export { chosenLanguage, clearSession, command, getTranslation, handleJuxEvent, handleMagicLinkRequest, initLanguage, initSession, loginButton, loginPage, magicLinkModal, onMicrosoftSignIn, query, reloadWithLanguageOverride, requestMagicLink, upload };
1518
+ export { chosenLanguage, clearSession, command, getCurrentUser, getTranslation, handleJuxEvent, handleMagicLinkRequest, initLanguage, initSession, loginButton, loginPage, magicLinkModal, onMicrosoftSignIn, query, reloadWithLanguageOverride, requestMagicLink, resetJuxWebGlobal, upload };
package/dist/main.js CHANGED
@@ -186,14 +186,12 @@ const getSecondaryBackendUrl = () => process.env.STAGING_BACKEND_URL || getBacke
186
186
  const getApiUrl = () => getBackendUrl() + 'api/';
187
187
  const getMagicAuthUrl = () => {
188
188
  var _a;
189
- // @ts-ignore
190
- const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
189
+ const endpoint = ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
191
190
  return getBackendUrl() + endpoint + '?token=';
192
191
  };
193
192
  const getMagicAuthReqUrl = () => {
194
193
  var _a;
195
- // @ts-ignore
196
- const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
194
+ const endpoint = ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
197
195
  return getBackendUrl() + endpoint + '?email=';
198
196
  };
199
197
  // TODO: use jux-events to call commands and queries inside jux-web library
@@ -249,13 +247,13 @@ const apiRequest = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1], v
249
247
  backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, retrial, retrialNum, extras);
250
248
  });
251
249
  const uploadRequest = (url, file, onSuccess, onError, extras) => {
252
- var _a, _b;
250
+ var _a;
253
251
  requestRunning = true;
254
252
  const xhr = new XMLHttpRequest();
255
253
  xhr.open('POST', url);
256
- if ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.backendToken) {
257
- xhr.setRequestHeader('auth', (_b = window.juxwebGlobal) === null || _b === void 0 ? void 0 : _b.backendToken);
258
- }
254
+ const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
255
+ if (backendToken)
256
+ xhr.setRequestHeader('auth', backendToken);
259
257
  xhr.upload.onprogress = (e) => {
260
258
  if (e.lengthComputable && (extras === null || extras === void 0 ? void 0 : extras.onProgress)) {
261
259
  extras.onProgress(Math.round((e.loaded / e.total) * 100));
@@ -291,11 +289,10 @@ const backendRequest = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1
291
289
  setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false, retrialNum), 300);
292
290
  return;
293
291
  }
294
- // @ts-ignore
295
292
  const headers = new Headers(options.headers);
296
- if ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.backendToken) {
297
- headers.set('auth', window.juxwebGlobal.backendToken);
298
- }
293
+ const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
294
+ if (backendToken)
295
+ headers.set('auth', backendToken);
299
296
  let response;
300
297
  requestRunning = true;
301
298
  const controller = new AbortController();
@@ -369,7 +366,14 @@ const backendRequest = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1
369
366
  return;
370
367
  }
371
368
  try {
372
- const jsonResponse = yield response.json();
369
+ let jsonResponse = {};
370
+ try {
371
+ jsonResponse = yield response.json();
372
+ }
373
+ catch (e) {
374
+ jsonResponse = { error: 'Unexpected response', expected: false };
375
+ console.error('Unexpected response', e, response);
376
+ }
373
377
  if (response.ok) {
374
378
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(jsonResponse);
375
379
  return;
@@ -553,9 +557,9 @@ const onUserChanged = (googleUser, onUserLogin) => {
553
557
  if (googleUser) {
554
558
  // mixpanelIdentify(googleUser); TODO
555
559
  const onSuccess = (res) => {
560
+ var _a;
556
561
  const { token } = res;
557
- // @ts-ignore
558
- window.juxwebGlobal.currentUser = res;
562
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
559
563
  onTokenAcquired(token, onUserLogin);
560
564
  };
561
565
  const onError = (err) => {
@@ -907,12 +911,11 @@ const sendInquiry = (name, email, msg, whatsapp, subject, token) => {
907
911
  // checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
908
912
  };
909
913
  const contactUsModal = (subject) => {
910
- var _a, _b, _c, _d, _e;
914
+ var _a, _b, _c, _d, _e, _f, _g, _h;
911
915
  const result = document.createElement('contact-us-modal');
912
- // @ts-ignore
913
- const currentName = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.name : '';
914
- // @ts-ignore
915
- const currentEmail = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
916
+ const currentUser = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
917
+ const currentName = currentUser ? currentUser.name : '';
918
+ const currentEmail = currentUser ? currentUser.email : (_b = document.querySelector('#magic-link-email')) === null || _b === void 0 ? void 0 : _b.textContent;
916
919
  const modalBody = document.createElement('modal-body');
917
920
  const form = document.createElement('form');
918
921
  form.id = 'contact-form';
@@ -928,11 +931,10 @@ const contactUsModal = (subject) => {
928
931
  const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
929
932
  modal.id = 'contact-us-modal';
930
933
  document.body.appendChild(modal);
931
- (_b = modal.querySelector('modal-wrapper')) === null || _b === void 0 ? void 0 : _b.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
934
+ (_c = modal.querySelector('modal-wrapper')) === null || _c === void 0 ? void 0 : _c.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
932
935
  const captcha = googleCaptcha();
933
936
  if (subject !== 'email-not-sent') {
934
- // @ts-ignore
935
- const admin = ((_d = (_c = window.juxwebGlobal) === null || _c === void 0 ? void 0 : _c.selectedTeam) === null || _d === void 0 ? void 0 : _d.admin) || window.juxwebGlobal.currentUser.email;
937
+ const admin = ((_e = (_d = window.juxWebGlobal) === null || _d === void 0 ? void 0 : _d.selectedTeam) === null || _e === void 0 ? void 0 : _e.admin) || ((_g = (_f = window.juxWebGlobal) === null || _f === void 0 ? void 0 : _f.getCurrentUser()) === null || _g === void 0 ? void 0 : _g.email);
936
938
  backendGet('credits-balance-for', { admin }, (res) => {
937
939
  const balance = res;
938
940
  if (balance <= 0) {
@@ -944,7 +946,7 @@ const contactUsModal = (subject) => {
944
946
  else {
945
947
  form.insertBefore(captcha, btn);
946
948
  }
947
- (_e = nameField.querySelector('input')) === null || _e === void 0 ? void 0 : _e.select();
949
+ (_h = nameField.querySelector('input')) === null || _h === void 0 ? void 0 : _h.select();
948
950
  form.addEventListener('submit', (event) => {
949
951
  event.preventDefault();
950
952
  sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
@@ -1064,18 +1066,39 @@ const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn, failInfo) =>
1064
1066
  return result;
1065
1067
  };
1066
1068
 
1069
+ class JuxWebGlobal {
1070
+ setCurrentUser(newUser) {
1071
+ this._currentUser = newUser;
1072
+ }
1073
+ getCurrentUser() {
1074
+ return this._currentUser;
1075
+ }
1076
+ setBackendToken(token) {
1077
+ this._backendToken = token;
1078
+ }
1079
+ getBackendToken() {
1080
+ return this._backendToken;
1081
+ }
1082
+ }
1083
+
1084
+ const resetJuxWebGlobal = () => {
1085
+ window.juxWebGlobal = new JuxWebGlobal();
1086
+ };
1087
+ const getCurrentUser = () => {
1088
+ var _a;
1089
+ return (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
1090
+ };
1091
+
1067
1092
  const setBackendToken = (token) => {
1068
- // @ts-ignore
1069
- window.juxwebGlobal.backendToken = token;
1070
- if (token) {
1093
+ var _a;
1094
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setBackendToken(token);
1095
+ if (token)
1071
1096
  setLocalStorageItem('token', token);
1072
- }
1073
1097
  };
1074
1098
  const getBackendToken = () => {
1075
- var _a;
1099
+ var _a, _b;
1076
1100
  const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
1077
- // @ts-ignore
1078
- window.juxwebGlobal.backendToken = token;
1101
+ (_b = window.juxWebGlobal) === null || _b === void 0 ? void 0 : _b.setBackendToken(token);
1079
1102
  return token;
1080
1103
  };
1081
1104
  const onTokenAcquired = (token, onUserLogin) => {
@@ -1085,8 +1108,7 @@ const onTokenAcquired = (token, onUserLogin) => {
1085
1108
  };
1086
1109
  const clearSession = () => {
1087
1110
  removeLocalStorageItem('token');
1088
- // @ts-ignore
1089
- window.juxwebGlobal = {};
1111
+ resetJuxWebGlobal();
1090
1112
  };
1091
1113
  const onAuthenticationFailure = (msg) => {
1092
1114
  removeLocalStorageItem('token');
@@ -1094,11 +1116,11 @@ const onAuthenticationFailure = (msg) => {
1094
1116
  alert(getTranslation(msg));
1095
1117
  };
1096
1118
  const onAuthentication = (onUserLogin, user, type) => {
1119
+ var _a;
1097
1120
  if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
1098
1121
  clearSession();
1099
1122
  }
1100
- // @ts-ignore
1101
- window.juxwebGlobal.currentUser = user;
1123
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(user);
1102
1124
  if (type === 'Token Authentication') {
1103
1125
  user.token = getLocalStorageItem('token');
1104
1126
  }
@@ -1137,17 +1159,11 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
1137
1159
  // initDemo(setBackendToken, onAuthentication);
1138
1160
  // return;
1139
1161
  // }
1140
- // @ts-ignore
1141
- if (!window.juxwebGlobal) {
1142
- // @ts-ignore
1143
- window.juxwebGlobal = {};
1144
- }
1145
- // @ts-ignore
1146
- window.juxwebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
1147
- // @ts-ignore
1148
- window.juxwebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
1149
- // @ts-ignore
1150
- window.juxwebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
1162
+ if (!window.juxWebGlobal)
1163
+ window.juxWebGlobal = new JuxWebGlobal();
1164
+ window.juxWebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
1165
+ window.juxWebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
1166
+ window.juxWebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
1151
1167
  if (urlPrefix)
1152
1168
  setUrlPrefix(urlPrefix);
1153
1169
  const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
@@ -1157,8 +1173,7 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
1157
1173
  };
1158
1174
  const host = extractTokenFromWindowLocation('host');
1159
1175
  if (host) {
1160
- // @ts-ignore
1161
- window.juxwebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
1176
+ window.juxWebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
1162
1177
  setBackendUrl(backendUrl);
1163
1178
  onOpenMagicLink();
1164
1179
  });
@@ -1201,9 +1216,9 @@ const onMicrosoftSignIn = (onUserLogin) => __awaiter(void 0, void 0, void 0, fun
1201
1216
  const loginResponse = yield msalInstance.loginPopup(loginRequest);
1202
1217
  const { accessToken } = loginResponse;
1203
1218
  const onSuccess = (res) => {
1219
+ var _a;
1204
1220
  const { token } = res;
1205
- // @ts-ignore
1206
- window.juxwebGlobal.currentUser = res;
1221
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
1207
1222
  onTokenAcquired(token, onUserLogin);
1208
1223
  disableSignInLayout();
1209
1224
  };
@@ -1234,9 +1249,9 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
1234
1249
  const { email } = credentials;
1235
1250
  enableSignInLayout();
1236
1251
  const onSuccess = (res) => {
1252
+ var _a;
1237
1253
  const { token } = res;
1238
- // @ts-ignore
1239
- window.juxwebGlobal.currentUser = res;
1254
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
1240
1255
  onTokenAcquired(token, onUserLogin);
1241
1256
  disableSignInLayout();
1242
1257
  };
@@ -1254,6 +1269,7 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
1254
1269
  authPasswordLogin(credentials, onSuccess, onError, onUnauthorized);
1255
1270
  };
1256
1271
  const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
1272
+ var _a;
1257
1273
  if (!email) {
1258
1274
  const mailMagic = document.querySelector('#mail-magic');
1259
1275
  email = mailMagic.value;
@@ -1270,10 +1286,8 @@ const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, c
1270
1286
  const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
1271
1287
  requestMagicLink(payload, onSuccess, onUnauthorized);
1272
1288
  };
1273
- // @ts-ignore
1274
- if (window.juxwebGlobal.fetchUserBackendUrl) {
1275
- // @ts-ignore
1276
- window.juxwebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
1289
+ if ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.fetchUserBackendUrl) {
1290
+ window.juxWebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
1277
1291
  setBackendUrl(backendUrl);
1278
1292
  onRequestMagicLink();
1279
1293
  });
@@ -1528,6 +1542,7 @@ const command = (element, endpoint, onResult, params, onError, onRedirect) => {
1528
1542
  exports.chosenLanguage = chosenLanguage;
1529
1543
  exports.clearSession = clearSession;
1530
1544
  exports.command = command;
1545
+ exports.getCurrentUser = getCurrentUser;
1531
1546
  exports.getTranslation = getTranslation;
1532
1547
  exports.handleJuxEvent = handleJuxEvent;
1533
1548
  exports.handleMagicLinkRequest = handleMagicLinkRequest;
@@ -1540,4 +1555,5 @@ exports.onMicrosoftSignIn = onMicrosoftSignIn;
1540
1555
  exports.query = query;
1541
1556
  exports.reloadWithLanguageOverride = reloadWithLanguageOverride;
1542
1557
  exports.requestMagicLink = requestMagicLink;
1558
+ exports.resetJuxWebGlobal = resetJuxWebGlobal;
1543
1559
  exports.upload = upload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@klauswuestefeld/jux-web",
3
- "version": "2025.6.30",
3
+ "version": "2025.9.5",
4
4
  "author": "Jux.House",
5
5
  "license": "Copyrighted",
6
6
  "description": "",