@klauswuestefeld/jux-web 2025.6.30 → 2025.7.9

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();
@@ -14044,9 +14041,9 @@ var juxWeb = (function (exports) {
14044
14041
  if (googleUser) {
14045
14042
  // mixpanelIdentify(googleUser); TODO
14046
14043
  const onSuccess = (res) => {
14044
+ var _a;
14047
14045
  const { token } = res;
14048
- // @ts-ignore
14049
- window.juxwebGlobal.currentUser = res;
14046
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
14050
14047
  onTokenAcquired(token, onUserLogin);
14051
14048
  };
14052
14049
  const onError = (err) => {
@@ -14398,12 +14395,11 @@ var juxWeb = (function (exports) {
14398
14395
  // checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
14399
14396
  };
14400
14397
  const contactUsModal = (subject) => {
14401
- var _a, _b, _c, _d, _e;
14398
+ var _a, _b, _c, _d, _e, _f, _g, _h;
14402
14399
  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;
14400
+ const currentUser = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
14401
+ const currentName = currentUser ? currentUser.name : '';
14402
+ const currentEmail = currentUser ? currentUser.email : (_b = document.querySelector('#magic-link-email')) === null || _b === void 0 ? void 0 : _b.textContent;
14407
14403
  const modalBody = document.createElement('modal-body');
14408
14404
  const form = document.createElement('form');
14409
14405
  form.id = 'contact-form';
@@ -14419,11 +14415,10 @@ var juxWeb = (function (exports) {
14419
14415
  const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
14420
14416
  modal.id = 'contact-us-modal';
14421
14417
  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;');
14418
+ (_c = modal.querySelector('modal-wrapper')) === null || _c === void 0 ? void 0 : _c.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
14423
14419
  const captcha = googleCaptcha();
14424
14420
  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;
14421
+ 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
14422
  backendGet('credits-balance-for', { admin }, (res) => {
14428
14423
  const balance = res;
14429
14424
  if (balance <= 0) {
@@ -14435,7 +14430,7 @@ var juxWeb = (function (exports) {
14435
14430
  else {
14436
14431
  form.insertBefore(captcha, btn);
14437
14432
  }
14438
- (_e = nameField.querySelector('input')) === null || _e === void 0 ? void 0 : _e.select();
14433
+ (_h = nameField.querySelector('input')) === null || _h === void 0 ? void 0 : _h.select();
14439
14434
  form.addEventListener('submit', (event) => {
14440
14435
  event.preventDefault();
14441
14436
  sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
@@ -14555,18 +14550,39 @@ var juxWeb = (function (exports) {
14555
14550
  return result;
14556
14551
  };
14557
14552
 
14553
+ class JuxWebGlobal {
14554
+ setCurrentUser(newUser) {
14555
+ this._currentUser = newUser;
14556
+ }
14557
+ getCurrentUser() {
14558
+ return this._currentUser;
14559
+ }
14560
+ setBackendToken(token) {
14561
+ this._backendToken = token;
14562
+ }
14563
+ getBackendToken() {
14564
+ return this._backendToken;
14565
+ }
14566
+ }
14567
+
14568
+ const resetJuxWebGlobal = () => {
14569
+ window.juxWebGlobal = new JuxWebGlobal();
14570
+ };
14571
+ const getCurrentUser = () => {
14572
+ var _a;
14573
+ return (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
14574
+ };
14575
+
14558
14576
  const setBackendToken = (token) => {
14559
- // @ts-ignore
14560
- window.juxwebGlobal.backendToken = token;
14561
- if (token) {
14577
+ var _a;
14578
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setBackendToken(token);
14579
+ if (token)
14562
14580
  setLocalStorageItem('token', token);
14563
- }
14564
14581
  };
14565
14582
  const getBackendToken = () => {
14566
- var _a;
14583
+ var _a, _b;
14567
14584
  const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
14568
- // @ts-ignore
14569
- window.juxwebGlobal.backendToken = token;
14585
+ (_b = window.juxWebGlobal) === null || _b === void 0 ? void 0 : _b.setBackendToken(token);
14570
14586
  return token;
14571
14587
  };
14572
14588
  const onTokenAcquired = (token, onUserLogin) => {
@@ -14576,8 +14592,7 @@ var juxWeb = (function (exports) {
14576
14592
  };
14577
14593
  const clearSession = () => {
14578
14594
  removeLocalStorageItem('token');
14579
- // @ts-ignore
14580
- window.juxwebGlobal = {};
14595
+ resetJuxWebGlobal();
14581
14596
  };
14582
14597
  const onAuthenticationFailure = (msg) => {
14583
14598
  removeLocalStorageItem('token');
@@ -14585,11 +14600,11 @@ var juxWeb = (function (exports) {
14585
14600
  alert(getTranslation(msg));
14586
14601
  };
14587
14602
  const onAuthentication = (onUserLogin, user, type) => {
14603
+ var _a;
14588
14604
  if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
14589
14605
  clearSession();
14590
14606
  }
14591
- // @ts-ignore
14592
- window.juxwebGlobal.currentUser = user;
14607
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(user);
14593
14608
  if (type === 'Token Authentication') {
14594
14609
  user.token = getLocalStorageItem('token');
14595
14610
  }
@@ -14628,17 +14643,11 @@ var juxWeb = (function (exports) {
14628
14643
  // initDemo(setBackendToken, onAuthentication);
14629
14644
  // return;
14630
14645
  // }
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;
14646
+ if (!window.juxWebGlobal)
14647
+ window.juxWebGlobal = new JuxWebGlobal();
14648
+ window.juxWebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
14649
+ window.juxWebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
14650
+ window.juxWebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
14642
14651
  if (urlPrefix)
14643
14652
  setUrlPrefix(urlPrefix);
14644
14653
  const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
@@ -14648,8 +14657,7 @@ var juxWeb = (function (exports) {
14648
14657
  };
14649
14658
  const host = extractTokenFromWindowLocation('host');
14650
14659
  if (host) {
14651
- // @ts-ignore
14652
- window.juxwebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
14660
+ window.juxWebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
14653
14661
  setBackendUrl(backendUrl);
14654
14662
  onOpenMagicLink();
14655
14663
  });
@@ -14692,9 +14700,9 @@ var juxWeb = (function (exports) {
14692
14700
  const loginResponse = yield msalInstance.loginPopup(loginRequest);
14693
14701
  const { accessToken } = loginResponse;
14694
14702
  const onSuccess = (res) => {
14703
+ var _a;
14695
14704
  const { token } = res;
14696
- // @ts-ignore
14697
- window.juxwebGlobal.currentUser = res;
14705
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
14698
14706
  onTokenAcquired(token, onUserLogin);
14699
14707
  disableSignInLayout();
14700
14708
  };
@@ -14725,9 +14733,9 @@ var juxWeb = (function (exports) {
14725
14733
  const { email } = credentials;
14726
14734
  enableSignInLayout();
14727
14735
  const onSuccess = (res) => {
14736
+ var _a;
14728
14737
  const { token } = res;
14729
- // @ts-ignore
14730
- window.juxwebGlobal.currentUser = res;
14738
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
14731
14739
  onTokenAcquired(token, onUserLogin);
14732
14740
  disableSignInLayout();
14733
14741
  };
@@ -14745,6 +14753,7 @@ var juxWeb = (function (exports) {
14745
14753
  authPasswordLogin(credentials, onSuccess, onError, onUnauthorized);
14746
14754
  };
14747
14755
  const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
14756
+ var _a;
14748
14757
  if (!email) {
14749
14758
  const mailMagic = document.querySelector('#mail-magic');
14750
14759
  email = mailMagic.value;
@@ -14761,10 +14770,8 @@ var juxWeb = (function (exports) {
14761
14770
  const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
14762
14771
  requestMagicLink(payload, onSuccess, onUnauthorized);
14763
14772
  };
14764
- // @ts-ignore
14765
- if (window.juxwebGlobal.fetchUserBackendUrl) {
14766
- // @ts-ignore
14767
- window.juxwebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
14773
+ if ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.fetchUserBackendUrl) {
14774
+ window.juxWebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
14768
14775
  setBackendUrl(backendUrl);
14769
14776
  onRequestMagicLink();
14770
14777
  });
@@ -15019,6 +15026,7 @@ var juxWeb = (function (exports) {
15019
15026
  exports.chosenLanguage = chosenLanguage;
15020
15027
  exports.clearSession = clearSession;
15021
15028
  exports.command = command;
15029
+ exports.getCurrentUser = getCurrentUser;
15022
15030
  exports.getTranslation = getTranslation;
15023
15031
  exports.handleJuxEvent = handleJuxEvent;
15024
15032
  exports.handleMagicLinkRequest = handleMagicLinkRequest;
@@ -15031,6 +15039,7 @@ var juxWeb = (function (exports) {
15031
15039
  exports.query = query;
15032
15040
  exports.reloadWithLanguageOverride = reloadWithLanguageOverride;
15033
15041
  exports.requestMagicLink = requestMagicLink;
15042
+ exports.resetJuxWebGlobal = resetJuxWebGlobal;
15034
15043
  exports.upload = upload;
15035
15044
 
15036
15045
  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();
@@ -529,9 +526,9 @@ const onUserChanged = (googleUser, onUserLogin) => {
529
526
  if (googleUser) {
530
527
  // mixpanelIdentify(googleUser); TODO
531
528
  const onSuccess = (res) => {
529
+ var _a;
532
530
  const { token } = res;
533
- // @ts-ignore
534
- window.juxwebGlobal.currentUser = res;
531
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
535
532
  onTokenAcquired(token, onUserLogin);
536
533
  };
537
534
  const onError = (err) => {
@@ -883,12 +880,11 @@ const sendInquiry = (name, email, msg, whatsapp, subject, token) => {
883
880
  // checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
884
881
  };
885
882
  const contactUsModal = (subject) => {
886
- var _a, _b, _c, _d, _e;
883
+ var _a, _b, _c, _d, _e, _f, _g, _h;
887
884
  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;
885
+ const currentUser = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
886
+ const currentName = currentUser ? currentUser.name : '';
887
+ const currentEmail = currentUser ? currentUser.email : (_b = document.querySelector('#magic-link-email')) === null || _b === void 0 ? void 0 : _b.textContent;
892
888
  const modalBody = document.createElement('modal-body');
893
889
  const form = document.createElement('form');
894
890
  form.id = 'contact-form';
@@ -904,11 +900,10 @@ const contactUsModal = (subject) => {
904
900
  const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
905
901
  modal.id = 'contact-us-modal';
906
902
  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;');
903
+ (_c = modal.querySelector('modal-wrapper')) === null || _c === void 0 ? void 0 : _c.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
908
904
  const captcha = googleCaptcha();
909
905
  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;
906
+ 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
907
  backendGet('credits-balance-for', { admin }, (res) => {
913
908
  const balance = res;
914
909
  if (balance <= 0) {
@@ -920,7 +915,7 @@ const contactUsModal = (subject) => {
920
915
  else {
921
916
  form.insertBefore(captcha, btn);
922
917
  }
923
- (_e = nameField.querySelector('input')) === null || _e === void 0 ? void 0 : _e.select();
918
+ (_h = nameField.querySelector('input')) === null || _h === void 0 ? void 0 : _h.select();
924
919
  form.addEventListener('submit', (event) => {
925
920
  event.preventDefault();
926
921
  sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
@@ -1040,18 +1035,39 @@ const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn, failInfo) =>
1040
1035
  return result;
1041
1036
  };
1042
1037
 
1038
+ class JuxWebGlobal {
1039
+ setCurrentUser(newUser) {
1040
+ this._currentUser = newUser;
1041
+ }
1042
+ getCurrentUser() {
1043
+ return this._currentUser;
1044
+ }
1045
+ setBackendToken(token) {
1046
+ this._backendToken = token;
1047
+ }
1048
+ getBackendToken() {
1049
+ return this._backendToken;
1050
+ }
1051
+ }
1052
+
1053
+ const resetJuxWebGlobal = () => {
1054
+ window.juxWebGlobal = new JuxWebGlobal();
1055
+ };
1056
+ const getCurrentUser = () => {
1057
+ var _a;
1058
+ return (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
1059
+ };
1060
+
1043
1061
  const setBackendToken = (token) => {
1044
- // @ts-ignore
1045
- window.juxwebGlobal.backendToken = token;
1046
- if (token) {
1062
+ var _a;
1063
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setBackendToken(token);
1064
+ if (token)
1047
1065
  setLocalStorageItem('token', token);
1048
- }
1049
1066
  };
1050
1067
  const getBackendToken = () => {
1051
- var _a;
1068
+ var _a, _b;
1052
1069
  const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
1053
- // @ts-ignore
1054
- window.juxwebGlobal.backendToken = token;
1070
+ (_b = window.juxWebGlobal) === null || _b === void 0 ? void 0 : _b.setBackendToken(token);
1055
1071
  return token;
1056
1072
  };
1057
1073
  const onTokenAcquired = (token, onUserLogin) => {
@@ -1061,8 +1077,7 @@ const onTokenAcquired = (token, onUserLogin) => {
1061
1077
  };
1062
1078
  const clearSession = () => {
1063
1079
  removeLocalStorageItem('token');
1064
- // @ts-ignore
1065
- window.juxwebGlobal = {};
1080
+ resetJuxWebGlobal();
1066
1081
  };
1067
1082
  const onAuthenticationFailure = (msg) => {
1068
1083
  removeLocalStorageItem('token');
@@ -1070,11 +1085,11 @@ const onAuthenticationFailure = (msg) => {
1070
1085
  alert(getTranslation(msg));
1071
1086
  };
1072
1087
  const onAuthentication = (onUserLogin, user, type) => {
1088
+ var _a;
1073
1089
  if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
1074
1090
  clearSession();
1075
1091
  }
1076
- // @ts-ignore
1077
- window.juxwebGlobal.currentUser = user;
1092
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(user);
1078
1093
  if (type === 'Token Authentication') {
1079
1094
  user.token = getLocalStorageItem('token');
1080
1095
  }
@@ -1113,17 +1128,11 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
1113
1128
  // initDemo(setBackendToken, onAuthentication);
1114
1129
  // return;
1115
1130
  // }
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;
1131
+ if (!window.juxWebGlobal)
1132
+ window.juxWebGlobal = new JuxWebGlobal();
1133
+ window.juxWebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
1134
+ window.juxWebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
1135
+ window.juxWebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
1127
1136
  if (urlPrefix)
1128
1137
  setUrlPrefix(urlPrefix);
1129
1138
  const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
@@ -1133,8 +1142,7 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
1133
1142
  };
1134
1143
  const host = extractTokenFromWindowLocation('host');
1135
1144
  if (host) {
1136
- // @ts-ignore
1137
- window.juxwebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
1145
+ window.juxWebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
1138
1146
  setBackendUrl(backendUrl);
1139
1147
  onOpenMagicLink();
1140
1148
  });
@@ -1177,9 +1185,9 @@ const onMicrosoftSignIn = (onUserLogin) => __awaiter(void 0, void 0, void 0, fun
1177
1185
  const loginResponse = yield msalInstance.loginPopup(loginRequest);
1178
1186
  const { accessToken } = loginResponse;
1179
1187
  const onSuccess = (res) => {
1188
+ var _a;
1180
1189
  const { token } = res;
1181
- // @ts-ignore
1182
- window.juxwebGlobal.currentUser = res;
1190
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
1183
1191
  onTokenAcquired(token, onUserLogin);
1184
1192
  disableSignInLayout();
1185
1193
  };
@@ -1210,9 +1218,9 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
1210
1218
  const { email } = credentials;
1211
1219
  enableSignInLayout();
1212
1220
  const onSuccess = (res) => {
1221
+ var _a;
1213
1222
  const { token } = res;
1214
- // @ts-ignore
1215
- window.juxwebGlobal.currentUser = res;
1223
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
1216
1224
  onTokenAcquired(token, onUserLogin);
1217
1225
  disableSignInLayout();
1218
1226
  };
@@ -1230,6 +1238,7 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
1230
1238
  authPasswordLogin(credentials, onSuccess, onError, onUnauthorized);
1231
1239
  };
1232
1240
  const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
1241
+ var _a;
1233
1242
  if (!email) {
1234
1243
  const mailMagic = document.querySelector('#mail-magic');
1235
1244
  email = mailMagic.value;
@@ -1246,10 +1255,8 @@ const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, c
1246
1255
  const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
1247
1256
  requestMagicLink(payload, onSuccess, onUnauthorized);
1248
1257
  };
1249
- // @ts-ignore
1250
- if (window.juxwebGlobal.fetchUserBackendUrl) {
1251
- // @ts-ignore
1252
- window.juxwebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
1258
+ if ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.fetchUserBackendUrl) {
1259
+ window.juxWebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
1253
1260
  setBackendUrl(backendUrl);
1254
1261
  onRequestMagicLink();
1255
1262
  });
@@ -1501,4 +1508,4 @@ const command = (element, endpoint, onResult, params, onError, onRedirect) => {
1501
1508
  element.dispatchEvent(new JuxEvent('command', 'POST', endpoint, onResult, params, onError, onRedirect));
1502
1509
  };
1503
1510
 
1504
- export { chosenLanguage, clearSession, command, getTranslation, handleJuxEvent, handleMagicLinkRequest, initLanguage, initSession, loginButton, loginPage, magicLinkModal, onMicrosoftSignIn, query, reloadWithLanguageOverride, requestMagicLink, upload };
1511
+ 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();
@@ -553,9 +550,9 @@ const onUserChanged = (googleUser, onUserLogin) => {
553
550
  if (googleUser) {
554
551
  // mixpanelIdentify(googleUser); TODO
555
552
  const onSuccess = (res) => {
553
+ var _a;
556
554
  const { token } = res;
557
- // @ts-ignore
558
- window.juxwebGlobal.currentUser = res;
555
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
559
556
  onTokenAcquired(token, onUserLogin);
560
557
  };
561
558
  const onError = (err) => {
@@ -907,12 +904,11 @@ const sendInquiry = (name, email, msg, whatsapp, subject, token) => {
907
904
  // checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
908
905
  };
909
906
  const contactUsModal = (subject) => {
910
- var _a, _b, _c, _d, _e;
907
+ var _a, _b, _c, _d, _e, _f, _g, _h;
911
908
  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;
909
+ const currentUser = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
910
+ const currentName = currentUser ? currentUser.name : '';
911
+ const currentEmail = currentUser ? currentUser.email : (_b = document.querySelector('#magic-link-email')) === null || _b === void 0 ? void 0 : _b.textContent;
916
912
  const modalBody = document.createElement('modal-body');
917
913
  const form = document.createElement('form');
918
914
  form.id = 'contact-form';
@@ -928,11 +924,10 @@ const contactUsModal = (subject) => {
928
924
  const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
929
925
  modal.id = 'contact-us-modal';
930
926
  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;');
927
+ (_c = modal.querySelector('modal-wrapper')) === null || _c === void 0 ? void 0 : _c.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
932
928
  const captcha = googleCaptcha();
933
929
  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;
930
+ 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
931
  backendGet('credits-balance-for', { admin }, (res) => {
937
932
  const balance = res;
938
933
  if (balance <= 0) {
@@ -944,7 +939,7 @@ const contactUsModal = (subject) => {
944
939
  else {
945
940
  form.insertBefore(captcha, btn);
946
941
  }
947
- (_e = nameField.querySelector('input')) === null || _e === void 0 ? void 0 : _e.select();
942
+ (_h = nameField.querySelector('input')) === null || _h === void 0 ? void 0 : _h.select();
948
943
  form.addEventListener('submit', (event) => {
949
944
  event.preventDefault();
950
945
  sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
@@ -1064,18 +1059,39 @@ const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn, failInfo) =>
1064
1059
  return result;
1065
1060
  };
1066
1061
 
1062
+ class JuxWebGlobal {
1063
+ setCurrentUser(newUser) {
1064
+ this._currentUser = newUser;
1065
+ }
1066
+ getCurrentUser() {
1067
+ return this._currentUser;
1068
+ }
1069
+ setBackendToken(token) {
1070
+ this._backendToken = token;
1071
+ }
1072
+ getBackendToken() {
1073
+ return this._backendToken;
1074
+ }
1075
+ }
1076
+
1077
+ const resetJuxWebGlobal = () => {
1078
+ window.juxWebGlobal = new JuxWebGlobal();
1079
+ };
1080
+ const getCurrentUser = () => {
1081
+ var _a;
1082
+ return (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getCurrentUser();
1083
+ };
1084
+
1067
1085
  const setBackendToken = (token) => {
1068
- // @ts-ignore
1069
- window.juxwebGlobal.backendToken = token;
1070
- if (token) {
1086
+ var _a;
1087
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setBackendToken(token);
1088
+ if (token)
1071
1089
  setLocalStorageItem('token', token);
1072
- }
1073
1090
  };
1074
1091
  const getBackendToken = () => {
1075
- var _a;
1092
+ var _a, _b;
1076
1093
  const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
1077
- // @ts-ignore
1078
- window.juxwebGlobal.backendToken = token;
1094
+ (_b = window.juxWebGlobal) === null || _b === void 0 ? void 0 : _b.setBackendToken(token);
1079
1095
  return token;
1080
1096
  };
1081
1097
  const onTokenAcquired = (token, onUserLogin) => {
@@ -1085,8 +1101,7 @@ const onTokenAcquired = (token, onUserLogin) => {
1085
1101
  };
1086
1102
  const clearSession = () => {
1087
1103
  removeLocalStorageItem('token');
1088
- // @ts-ignore
1089
- window.juxwebGlobal = {};
1104
+ resetJuxWebGlobal();
1090
1105
  };
1091
1106
  const onAuthenticationFailure = (msg) => {
1092
1107
  removeLocalStorageItem('token');
@@ -1094,11 +1109,11 @@ const onAuthenticationFailure = (msg) => {
1094
1109
  alert(getTranslation(msg));
1095
1110
  };
1096
1111
  const onAuthentication = (onUserLogin, user, type) => {
1112
+ var _a;
1097
1113
  if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
1098
1114
  clearSession();
1099
1115
  }
1100
- // @ts-ignore
1101
- window.juxwebGlobal.currentUser = user;
1116
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(user);
1102
1117
  if (type === 'Token Authentication') {
1103
1118
  user.token = getLocalStorageItem('token');
1104
1119
  }
@@ -1137,17 +1152,11 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
1137
1152
  // initDemo(setBackendToken, onAuthentication);
1138
1153
  // return;
1139
1154
  // }
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;
1155
+ if (!window.juxWebGlobal)
1156
+ window.juxWebGlobal = new JuxWebGlobal();
1157
+ window.juxWebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
1158
+ window.juxWebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
1159
+ window.juxWebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
1151
1160
  if (urlPrefix)
1152
1161
  setUrlPrefix(urlPrefix);
1153
1162
  const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
@@ -1157,8 +1166,7 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
1157
1166
  };
1158
1167
  const host = extractTokenFromWindowLocation('host');
1159
1168
  if (host) {
1160
- // @ts-ignore
1161
- window.juxwebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
1169
+ window.juxWebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
1162
1170
  setBackendUrl(backendUrl);
1163
1171
  onOpenMagicLink();
1164
1172
  });
@@ -1201,9 +1209,9 @@ const onMicrosoftSignIn = (onUserLogin) => __awaiter(void 0, void 0, void 0, fun
1201
1209
  const loginResponse = yield msalInstance.loginPopup(loginRequest);
1202
1210
  const { accessToken } = loginResponse;
1203
1211
  const onSuccess = (res) => {
1212
+ var _a;
1204
1213
  const { token } = res;
1205
- // @ts-ignore
1206
- window.juxwebGlobal.currentUser = res;
1214
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
1207
1215
  onTokenAcquired(token, onUserLogin);
1208
1216
  disableSignInLayout();
1209
1217
  };
@@ -1234,9 +1242,9 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
1234
1242
  const { email } = credentials;
1235
1243
  enableSignInLayout();
1236
1244
  const onSuccess = (res) => {
1245
+ var _a;
1237
1246
  const { token } = res;
1238
- // @ts-ignore
1239
- window.juxwebGlobal.currentUser = res;
1247
+ (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
1240
1248
  onTokenAcquired(token, onUserLogin);
1241
1249
  disableSignInLayout();
1242
1250
  };
@@ -1254,6 +1262,7 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
1254
1262
  authPasswordLogin(credentials, onSuccess, onError, onUnauthorized);
1255
1263
  };
1256
1264
  const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
1265
+ var _a;
1257
1266
  if (!email) {
1258
1267
  const mailMagic = document.querySelector('#mail-magic');
1259
1268
  email = mailMagic.value;
@@ -1270,10 +1279,8 @@ const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, c
1270
1279
  const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
1271
1280
  requestMagicLink(payload, onSuccess, onUnauthorized);
1272
1281
  };
1273
- // @ts-ignore
1274
- if (window.juxwebGlobal.fetchUserBackendUrl) {
1275
- // @ts-ignore
1276
- window.juxwebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
1282
+ if ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.fetchUserBackendUrl) {
1283
+ window.juxWebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
1277
1284
  setBackendUrl(backendUrl);
1278
1285
  onRequestMagicLink();
1279
1286
  });
@@ -1528,6 +1535,7 @@ const command = (element, endpoint, onResult, params, onError, onRedirect) => {
1528
1535
  exports.chosenLanguage = chosenLanguage;
1529
1536
  exports.clearSession = clearSession;
1530
1537
  exports.command = command;
1538
+ exports.getCurrentUser = getCurrentUser;
1531
1539
  exports.getTranslation = getTranslation;
1532
1540
  exports.handleJuxEvent = handleJuxEvent;
1533
1541
  exports.handleMagicLinkRequest = handleMagicLinkRequest;
@@ -1540,4 +1548,5 @@ exports.onMicrosoftSignIn = onMicrosoftSignIn;
1540
1548
  exports.query = query;
1541
1549
  exports.reloadWithLanguageOverride = reloadWithLanguageOverride;
1542
1550
  exports.requestMagicLink = requestMagicLink;
1551
+ exports.resetJuxWebGlobal = resetJuxWebGlobal;
1543
1552
  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.7.09",
4
4
  "author": "Jux.House",
5
5
  "license": "Copyrighted",
6
6
  "description": "",