@klauswuestefeld/jux-web 2025.5.28 → 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.
- package/dist/api-client.d.ts +9 -1
- package/dist/contact-us/contact-field.d.ts +1 -1
- package/dist/jux/jux-event.d.ts +2 -1
- package/dist/jux/jux-web-global/utils.d.ts +3 -0
- package/dist/jux/jux-web-global.d.ts +22 -0
- package/dist/jux-web.js +135 -74
- package/dist/login/session.d.ts +2 -2
- package/dist/main.d.ts +2 -1
- package/dist/main.esm.js +133 -75
- package/dist/main.js +135 -74
- package/package.json +1 -1
package/dist/api-client.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
export declare const setBackendUrl: (backendUrl: string) => void;
|
|
2
2
|
export declare const getBackendUrl: () => string;
|
|
3
3
|
export declare const handleJuxEvent: (ev: Event) => void;
|
|
4
|
-
export
|
|
4
|
+
export interface BackendRequestOptions extends RequestInit {
|
|
5
|
+
file?: File;
|
|
6
|
+
onProgress?: (percent: number) => void;
|
|
7
|
+
}
|
|
8
|
+
export type RequestType = 'query' | 'command' | 'upload';
|
|
9
|
+
export declare const upload: (endpoint: string, file: File, onResult?: (result: any) => any, onError?: (error: any) => void, extras?: {
|
|
10
|
+
onProgress?: (percent: number) => void;
|
|
11
|
+
onStart?: () => void;
|
|
12
|
+
}) => void;
|
|
5
13
|
export declare const backendPost: (endpoint: string, postContent: any, onJsonResponse: (response: any) => any, onHelpMessage: (message: string) => any, handleUnauthorized?: any) => void;
|
|
6
14
|
export declare const backendGet: (endpoint: string, params: any, onJsonResponse: (response: any) => any, onHelpMessage: (message: string) => any, handleUnauthorized?: any) => void;
|
|
7
15
|
export declare const requestMagicLink: (data: any, onJsonResponse: (response: any) => any, onUnauthorized: () => void) => 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;
|
package/dist/jux/jux-event.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ export declare class JuxEvent extends Event {
|
|
|
6
6
|
params: any;
|
|
7
7
|
onError?: (error: any) => void;
|
|
8
8
|
onRedirect?: (result: any) => any;
|
|
9
|
-
|
|
9
|
+
extras?: any;
|
|
10
|
+
constructor(type: string, method: string, endpoint: string, onResult?: (result: any) => any, params?: any, onError?: (error: any) => void, onRedirect?: (result: any) => any, extras?: {});
|
|
10
11
|
}
|
|
11
12
|
export declare const query: (element: HTMLElement, endpoint: string, onResult: (result: any) => any, params?: any, onError?: (error: any) => void, onRedirect?: (result: any) => any) => void;
|
|
12
13
|
export declare const command: (element: HTMLElement, endpoint: string, onResult?: (result: any) => any, params?: any, onError?: (error: any) => void, onRedirect?: (result: any) => any) => void;
|
|
@@ -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
|
-
|
|
167
|
-
const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === 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
|
-
|
|
173
|
-
const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === 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
|
|
@@ -213,18 +211,65 @@ var juxWeb = (function (exports) {
|
|
|
213
211
|
const slowRequestTimeout = 2000;
|
|
214
212
|
// @ts-ignore
|
|
215
213
|
window.setRequestTimeout = (newTimeout) => timeout = newTimeout;
|
|
216
|
-
const
|
|
214
|
+
const upload = (endpoint, file, onResult, onError, extras) => {
|
|
215
|
+
apiRequest(endpoint, {
|
|
216
|
+
file,
|
|
217
|
+
onProgress: (pct) => { var _a; return (_a = extras === null || extras === void 0 ? void 0 : extras.onProgress) === null || _a === void 0 ? void 0 : _a.call(extras, pct); }
|
|
218
|
+
}, (text) => onResult === null || onResult === void 0 ? void 0 : onResult(text), (err) => onError === null || onError === void 0 ? void 0 : onError(err), undefined, // no redirect handler
|
|
219
|
+
'upload', // requestType
|
|
220
|
+
undefined, undefined, undefined, extras);
|
|
221
|
+
};
|
|
222
|
+
const apiRequest = (url_1, ...args_1) => __awaiter$2(void 0, [url_1, ...args_1], void 0, function* (url, options = {}, onSuccess, onError, onRedirect, requestType = 'query', handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0, extras) {
|
|
223
|
+
url = getApiUrl() + url;
|
|
224
|
+
backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, retrial, retrialNum, extras);
|
|
225
|
+
});
|
|
226
|
+
const uploadRequest = (url, file, onSuccess, onError, extras) => {
|
|
227
|
+
var _a;
|
|
228
|
+
requestRunning = true;
|
|
229
|
+
const xhr = new XMLHttpRequest();
|
|
230
|
+
xhr.open('POST', url);
|
|
231
|
+
const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
|
|
232
|
+
if (backendToken)
|
|
233
|
+
xhr.setRequestHeader('auth', backendToken);
|
|
234
|
+
xhr.upload.onprogress = (e) => {
|
|
235
|
+
if (e.lengthComputable && (extras === null || extras === void 0 ? void 0 : extras.onProgress)) {
|
|
236
|
+
extras.onProgress(Math.round((e.loaded / e.total) * 100));
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
xhr.onload = () => {
|
|
240
|
+
requestRunning = false;
|
|
241
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
242
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(xhr.responseText);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
onError === null || onError === void 0 ? void 0 : onError(xhr.responseText);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
xhr.onerror = () => {
|
|
249
|
+
requestRunning = false;
|
|
250
|
+
onError === null || onError === void 0 ? void 0 : onError('Error sending file. Please try again.');
|
|
251
|
+
};
|
|
252
|
+
xhr.send(file);
|
|
253
|
+
if (extras === null || extras === void 0 ? void 0 : extras.onStart) {
|
|
254
|
+
extras.onStart({
|
|
255
|
+
abortUpload: () => {
|
|
256
|
+
console.log('Aborting upload');
|
|
257
|
+
xhr.abort();
|
|
258
|
+
requestRunning = false;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const backendRequest = (url_1, ...args_1) => __awaiter$2(void 0, [url_1, ...args_1], void 0, function* (url, options = {}, onSuccess, onError, onRedirect, requestType = 'query', handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0, extras) {
|
|
264
|
+
var _a;
|
|
217
265
|
if (requestRunning && !retrial) { // only allow one request at a time
|
|
218
|
-
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false), 300);
|
|
266
|
+
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false, retrialNum), 300);
|
|
219
267
|
return;
|
|
220
268
|
}
|
|
221
|
-
|
|
222
|
-
const backendToken = window.
|
|
223
|
-
if (backendToken)
|
|
224
|
-
|
|
225
|
-
options.headers = {};
|
|
226
|
-
options.headers.auth = backendToken;
|
|
227
|
-
}
|
|
269
|
+
const headers = new Headers(options.headers);
|
|
270
|
+
const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
|
|
271
|
+
if (backendToken)
|
|
272
|
+
headers.set('auth', backendToken);
|
|
228
273
|
let response;
|
|
229
274
|
requestRunning = true;
|
|
230
275
|
const controller = new AbortController();
|
|
@@ -239,17 +284,19 @@ var juxWeb = (function (exports) {
|
|
|
239
284
|
const event = new CustomEvent('slow-request', { detail: requestUrl.pathname, bubbles: true });
|
|
240
285
|
window.dispatchEvent(event);
|
|
241
286
|
}, slowRequestTimeout);
|
|
242
|
-
const requestInit = Object.assign(Object.assign({}, options), { signal: controller.signal });
|
|
287
|
+
const requestInit = Object.assign(Object.assign({}, options), { headers, signal: controller.signal });
|
|
243
288
|
if (onRedirect)
|
|
244
289
|
requestInit.redirect = 'manual'; // Treat redirects manually instead of following them automatically.
|
|
290
|
+
if (requestType === 'upload') {
|
|
291
|
+
uploadRequest(url, options.file, onSuccess, onError, extras);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
245
294
|
try {
|
|
246
295
|
response = yield fetch(url, requestInit);
|
|
247
296
|
}
|
|
248
297
|
catch (err) {
|
|
249
|
-
// network errors
|
|
250
298
|
if (requestType === 'command') {
|
|
251
|
-
|
|
252
|
-
onError('There was an error performing your request. Please try again later.');
|
|
299
|
+
onError === null || onError === void 0 ? void 0 : onError('There was an error performing your request. Please try again later.');
|
|
253
300
|
requestRunning = false;
|
|
254
301
|
return;
|
|
255
302
|
}
|
|
@@ -298,20 +345,14 @@ var juxWeb = (function (exports) {
|
|
|
298
345
|
try {
|
|
299
346
|
const jsonResponse = yield response.json();
|
|
300
347
|
if (response.ok) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
return jsonResponse;
|
|
306
|
-
}
|
|
348
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(jsonResponse);
|
|
349
|
+
return;
|
|
307
350
|
}
|
|
308
351
|
else {
|
|
309
|
-
|
|
310
|
-
onError(jsonResponse);
|
|
352
|
+
onError === null || onError === void 0 ? void 0 : onError(jsonResponse);
|
|
311
353
|
}
|
|
312
354
|
}
|
|
313
355
|
catch (err) {
|
|
314
|
-
// json conversion error / json response dealing errors / onSuccess errors
|
|
315
356
|
console.error(err);
|
|
316
357
|
}
|
|
317
358
|
finally {
|
|
@@ -334,7 +375,7 @@ var juxWeb = (function (exports) {
|
|
|
334
375
|
// @ts-ignore
|
|
335
376
|
options.body = content;
|
|
336
377
|
}
|
|
337
|
-
return
|
|
378
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized);
|
|
338
379
|
};
|
|
339
380
|
const get = (endpoint, onSuccess, onError, onRedirect, handleUnauthorized) => {
|
|
340
381
|
const options = {
|
|
@@ -344,7 +385,7 @@ var juxWeb = (function (exports) {
|
|
|
344
385
|
'Content-Type': 'application/json',
|
|
345
386
|
}
|
|
346
387
|
};
|
|
347
|
-
return
|
|
388
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, 'query', handleUnauthorized);
|
|
348
389
|
};
|
|
349
390
|
const backendPost = (endpoint, postContent, onJsonResponse, onHelpMessage, handleUnauthorized) => {
|
|
350
391
|
post(endpoint, postContent, onJsonResponse, onHelpMessage, null, 'command', handleUnauthorized);
|
|
@@ -362,9 +403,15 @@ var juxWeb = (function (exports) {
|
|
|
362
403
|
};
|
|
363
404
|
const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
|
|
364
405
|
const { email, token } = data;
|
|
365
|
-
const url = getMagicAuthReqUrl() +
|
|
406
|
+
const url = getMagicAuthReqUrl() +
|
|
407
|
+
encodeURIComponent(email) +
|
|
408
|
+
'&destination=' +
|
|
409
|
+
extractTokenFromWindowLocation('destination') +
|
|
410
|
+
'&token=' +
|
|
411
|
+
token;
|
|
366
412
|
const options = {};
|
|
367
|
-
backendRequest(url, options, onJsonResponse, console.error,
|
|
413
|
+
backendRequest(url, options, onJsonResponse, console.error, undefined, // ← use undefined instead of null
|
|
414
|
+
'query', onUnauthorized);
|
|
368
415
|
};
|
|
369
416
|
const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
|
|
370
417
|
backendRequest(getMagicAuthUrl() + magicToken, {}, onJsonResponse, onHelpMessage);
|
|
@@ -13994,9 +14041,9 @@ var juxWeb = (function (exports) {
|
|
|
13994
14041
|
if (googleUser) {
|
|
13995
14042
|
// mixpanelIdentify(googleUser); TODO
|
|
13996
14043
|
const onSuccess = (res) => {
|
|
14044
|
+
var _a;
|
|
13997
14045
|
const { token } = res;
|
|
13998
|
-
|
|
13999
|
-
window.store.currentUser = res;
|
|
14046
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
|
|
14000
14047
|
onTokenAcquired(token, onUserLogin);
|
|
14001
14048
|
};
|
|
14002
14049
|
const onError = (err) => {
|
|
@@ -14348,12 +14395,11 @@ var juxWeb = (function (exports) {
|
|
|
14348
14395
|
// checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
|
|
14349
14396
|
};
|
|
14350
14397
|
const contactUsModal = (subject) => {
|
|
14351
|
-
var _a, _b, _c, _d, _e;
|
|
14398
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
14352
14399
|
const result = document.createElement('contact-us-modal');
|
|
14353
|
-
|
|
14354
|
-
const currentName =
|
|
14355
|
-
|
|
14356
|
-
const currentEmail = window.store.currentUser ? window.store.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;
|
|
14357
14403
|
const modalBody = document.createElement('modal-body');
|
|
14358
14404
|
const form = document.createElement('form');
|
|
14359
14405
|
form.id = 'contact-form';
|
|
@@ -14369,11 +14415,10 @@ var juxWeb = (function (exports) {
|
|
|
14369
14415
|
const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
|
|
14370
14416
|
modal.id = 'contact-us-modal';
|
|
14371
14417
|
document.body.appendChild(modal);
|
|
14372
|
-
(
|
|
14418
|
+
(_c = modal.querySelector('modal-wrapper')) === null || _c === void 0 ? void 0 : _c.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
|
|
14373
14419
|
const captcha = googleCaptcha();
|
|
14374
14420
|
if (subject !== 'email-not-sent') {
|
|
14375
|
-
|
|
14376
|
-
const admin = ((_d = (_c = window.store) === null || _c === void 0 ? void 0 : _c.selectedTeam) === null || _d === void 0 ? void 0 : _d.admin) || window.store.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);
|
|
14377
14422
|
backendGet('credits-balance-for', { admin }, (res) => {
|
|
14378
14423
|
const balance = res;
|
|
14379
14424
|
if (balance <= 0) {
|
|
@@ -14385,7 +14430,7 @@ var juxWeb = (function (exports) {
|
|
|
14385
14430
|
else {
|
|
14386
14431
|
form.insertBefore(captcha, btn);
|
|
14387
14432
|
}
|
|
14388
|
-
(
|
|
14433
|
+
(_h = nameField.querySelector('input')) === null || _h === void 0 ? void 0 : _h.select();
|
|
14389
14434
|
form.addEventListener('submit', (event) => {
|
|
14390
14435
|
event.preventDefault();
|
|
14391
14436
|
sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
|
|
@@ -14505,18 +14550,39 @@ var juxWeb = (function (exports) {
|
|
|
14505
14550
|
return result;
|
|
14506
14551
|
};
|
|
14507
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
|
+
|
|
14508
14576
|
const setBackendToken = (token) => {
|
|
14509
|
-
|
|
14510
|
-
window.
|
|
14511
|
-
if (token)
|
|
14577
|
+
var _a;
|
|
14578
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setBackendToken(token);
|
|
14579
|
+
if (token)
|
|
14512
14580
|
setLocalStorageItem('token', token);
|
|
14513
|
-
}
|
|
14514
14581
|
};
|
|
14515
14582
|
const getBackendToken = () => {
|
|
14516
|
-
var _a;
|
|
14583
|
+
var _a, _b;
|
|
14517
14584
|
const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
|
|
14518
|
-
|
|
14519
|
-
window.store.backendToken = token;
|
|
14585
|
+
(_b = window.juxWebGlobal) === null || _b === void 0 ? void 0 : _b.setBackendToken(token);
|
|
14520
14586
|
return token;
|
|
14521
14587
|
};
|
|
14522
14588
|
const onTokenAcquired = (token, onUserLogin) => {
|
|
@@ -14526,8 +14592,7 @@ var juxWeb = (function (exports) {
|
|
|
14526
14592
|
};
|
|
14527
14593
|
const clearSession = () => {
|
|
14528
14594
|
removeLocalStorageItem('token');
|
|
14529
|
-
|
|
14530
|
-
window.store = {};
|
|
14595
|
+
resetJuxWebGlobal();
|
|
14531
14596
|
};
|
|
14532
14597
|
const onAuthenticationFailure = (msg) => {
|
|
14533
14598
|
removeLocalStorageItem('token');
|
|
@@ -14535,11 +14600,11 @@ var juxWeb = (function (exports) {
|
|
|
14535
14600
|
alert(getTranslation(msg));
|
|
14536
14601
|
};
|
|
14537
14602
|
const onAuthentication = (onUserLogin, user, type) => {
|
|
14603
|
+
var _a;
|
|
14538
14604
|
if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
|
|
14539
14605
|
clearSession();
|
|
14540
14606
|
}
|
|
14541
|
-
|
|
14542
|
-
window.store.currentUser = user;
|
|
14607
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(user);
|
|
14543
14608
|
if (type === 'Token Authentication') {
|
|
14544
14609
|
user.token = getLocalStorageItem('token');
|
|
14545
14610
|
}
|
|
@@ -14578,17 +14643,11 @@ var juxWeb = (function (exports) {
|
|
|
14578
14643
|
// initDemo(setBackendToken, onAuthentication);
|
|
14579
14644
|
// return;
|
|
14580
14645
|
// }
|
|
14581
|
-
|
|
14582
|
-
|
|
14583
|
-
|
|
14584
|
-
|
|
14585
|
-
|
|
14586
|
-
// @ts-ignore
|
|
14587
|
-
window.store.fetchUserBackendUrl = fetchUserBackendUrl;
|
|
14588
|
-
// @ts-ignore
|
|
14589
|
-
window.store.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
|
|
14590
|
-
// @ts-ignore
|
|
14591
|
-
window.store.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;
|
|
14592
14651
|
if (urlPrefix)
|
|
14593
14652
|
setUrlPrefix(urlPrefix);
|
|
14594
14653
|
const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
|
|
@@ -14598,8 +14657,7 @@ var juxWeb = (function (exports) {
|
|
|
14598
14657
|
};
|
|
14599
14658
|
const host = extractTokenFromWindowLocation('host');
|
|
14600
14659
|
if (host) {
|
|
14601
|
-
|
|
14602
|
-
window.store.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
14660
|
+
window.juxWebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
14603
14661
|
setBackendUrl(backendUrl);
|
|
14604
14662
|
onOpenMagicLink();
|
|
14605
14663
|
});
|
|
@@ -14642,9 +14700,9 @@ var juxWeb = (function (exports) {
|
|
|
14642
14700
|
const loginResponse = yield msalInstance.loginPopup(loginRequest);
|
|
14643
14701
|
const { accessToken } = loginResponse;
|
|
14644
14702
|
const onSuccess = (res) => {
|
|
14703
|
+
var _a;
|
|
14645
14704
|
const { token } = res;
|
|
14646
|
-
|
|
14647
|
-
window.store.currentUser = res;
|
|
14705
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
|
|
14648
14706
|
onTokenAcquired(token, onUserLogin);
|
|
14649
14707
|
disableSignInLayout();
|
|
14650
14708
|
};
|
|
@@ -14675,9 +14733,9 @@ var juxWeb = (function (exports) {
|
|
|
14675
14733
|
const { email } = credentials;
|
|
14676
14734
|
enableSignInLayout();
|
|
14677
14735
|
const onSuccess = (res) => {
|
|
14736
|
+
var _a;
|
|
14678
14737
|
const { token } = res;
|
|
14679
|
-
|
|
14680
|
-
window.store.currentUser = res;
|
|
14738
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
|
|
14681
14739
|
onTokenAcquired(token, onUserLogin);
|
|
14682
14740
|
disableSignInLayout();
|
|
14683
14741
|
};
|
|
@@ -14695,6 +14753,7 @@ var juxWeb = (function (exports) {
|
|
|
14695
14753
|
authPasswordLogin(credentials, onSuccess, onError, onUnauthorized);
|
|
14696
14754
|
};
|
|
14697
14755
|
const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
|
|
14756
|
+
var _a;
|
|
14698
14757
|
if (!email) {
|
|
14699
14758
|
const mailMagic = document.querySelector('#mail-magic');
|
|
14700
14759
|
email = mailMagic.value;
|
|
@@ -14711,10 +14770,8 @@ var juxWeb = (function (exports) {
|
|
|
14711
14770
|
const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
|
|
14712
14771
|
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
14713
14772
|
};
|
|
14714
|
-
|
|
14715
|
-
|
|
14716
|
-
// @ts-ignore
|
|
14717
|
-
window.store.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
14773
|
+
if ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.fetchUserBackendUrl) {
|
|
14774
|
+
window.juxWebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
14718
14775
|
setBackendUrl(backendUrl);
|
|
14719
14776
|
onRequestMagicLink();
|
|
14720
14777
|
});
|
|
@@ -14947,7 +15004,7 @@ var juxWeb = (function (exports) {
|
|
|
14947
15004
|
};
|
|
14948
15005
|
|
|
14949
15006
|
class JuxEvent extends Event {
|
|
14950
|
-
constructor(type, method, endpoint, onResult, params, onError, onRedirect) {
|
|
15007
|
+
constructor(type, method, endpoint, onResult, params, onError, onRedirect, extras) {
|
|
14951
15008
|
super('jux-event', { bubbles: true, cancelable: true, composed: true });
|
|
14952
15009
|
this.requestType = type;
|
|
14953
15010
|
this.method = method;
|
|
@@ -14956,6 +15013,7 @@ var juxWeb = (function (exports) {
|
|
|
14956
15013
|
this.params = params;
|
|
14957
15014
|
this.onError = onError;
|
|
14958
15015
|
this.onRedirect = onRedirect;
|
|
15016
|
+
this.extras = extras;
|
|
14959
15017
|
}
|
|
14960
15018
|
}
|
|
14961
15019
|
const query = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
@@ -14968,6 +15026,7 @@ var juxWeb = (function (exports) {
|
|
|
14968
15026
|
exports.chosenLanguage = chosenLanguage;
|
|
14969
15027
|
exports.clearSession = clearSession;
|
|
14970
15028
|
exports.command = command;
|
|
15029
|
+
exports.getCurrentUser = getCurrentUser;
|
|
14971
15030
|
exports.getTranslation = getTranslation;
|
|
14972
15031
|
exports.handleJuxEvent = handleJuxEvent;
|
|
14973
15032
|
exports.handleMagicLinkRequest = handleMagicLinkRequest;
|
|
@@ -14980,6 +15039,8 @@ var juxWeb = (function (exports) {
|
|
|
14980
15039
|
exports.query = query;
|
|
14981
15040
|
exports.reloadWithLanguageOverride = reloadWithLanguageOverride;
|
|
14982
15041
|
exports.requestMagicLink = requestMagicLink;
|
|
15042
|
+
exports.resetJuxWebGlobal = resetJuxWebGlobal;
|
|
15043
|
+
exports.upload = upload;
|
|
14983
15044
|
|
|
14984
15045
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14985
15046
|
|
package/dist/login/session.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ interface InitSessionParams {
|
|
|
8
8
|
onLoginError: any;
|
|
9
9
|
backgroundImage: string;
|
|
10
10
|
fetchUserBackendUrl: any;
|
|
11
|
-
magicLinkRequestEndpoint
|
|
12
|
-
magicLinkAuthEndpoint
|
|
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
|
@@ -2,9 +2,10 @@ export { chosenLanguage, reloadWithLanguageOverride, initLanguage, getTranslatio
|
|
|
2
2
|
export { loginButton } from './login/login-button';
|
|
3
3
|
export { loginPage } from './login/login-page';
|
|
4
4
|
export { handleMagicLinkRequest, initSession, onMicrosoftSignIn, clearSession } from './login/session';
|
|
5
|
-
export { handleJuxEvent, requestMagicLink } from './api-client';
|
|
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
|
-
|
|
166
|
-
const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === 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
|
-
|
|
172
|
-
const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === 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
|
|
@@ -212,18 +210,65 @@ let timeout = 20000;
|
|
|
212
210
|
const slowRequestTimeout = 2000;
|
|
213
211
|
// @ts-ignore
|
|
214
212
|
window.setRequestTimeout = (newTimeout) => timeout = newTimeout;
|
|
215
|
-
const
|
|
213
|
+
const upload = (endpoint, file, onResult, onError, extras) => {
|
|
214
|
+
apiRequest(endpoint, {
|
|
215
|
+
file,
|
|
216
|
+
onProgress: (pct) => { var _a; return (_a = extras === null || extras === void 0 ? void 0 : extras.onProgress) === null || _a === void 0 ? void 0 : _a.call(extras, pct); }
|
|
217
|
+
}, (text) => onResult === null || onResult === void 0 ? void 0 : onResult(text), (err) => onError === null || onError === void 0 ? void 0 : onError(err), undefined, // no redirect handler
|
|
218
|
+
'upload', // requestType
|
|
219
|
+
undefined, undefined, undefined, extras);
|
|
220
|
+
};
|
|
221
|
+
const apiRequest = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1], void 0, function* (url, options = {}, onSuccess, onError, onRedirect, requestType = 'query', handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0, extras) {
|
|
222
|
+
url = getApiUrl() + url;
|
|
223
|
+
backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, retrial, retrialNum, extras);
|
|
224
|
+
});
|
|
225
|
+
const uploadRequest = (url, file, onSuccess, onError, extras) => {
|
|
226
|
+
var _a;
|
|
227
|
+
requestRunning = true;
|
|
228
|
+
const xhr = new XMLHttpRequest();
|
|
229
|
+
xhr.open('POST', url);
|
|
230
|
+
const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
|
|
231
|
+
if (backendToken)
|
|
232
|
+
xhr.setRequestHeader('auth', backendToken);
|
|
233
|
+
xhr.upload.onprogress = (e) => {
|
|
234
|
+
if (e.lengthComputable && (extras === null || extras === void 0 ? void 0 : extras.onProgress)) {
|
|
235
|
+
extras.onProgress(Math.round((e.loaded / e.total) * 100));
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
xhr.onload = () => {
|
|
239
|
+
requestRunning = false;
|
|
240
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
241
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(xhr.responseText);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
onError === null || onError === void 0 ? void 0 : onError(xhr.responseText);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
xhr.onerror = () => {
|
|
248
|
+
requestRunning = false;
|
|
249
|
+
onError === null || onError === void 0 ? void 0 : onError('Error sending file. Please try again.');
|
|
250
|
+
};
|
|
251
|
+
xhr.send(file);
|
|
252
|
+
if (extras === null || extras === void 0 ? void 0 : extras.onStart) {
|
|
253
|
+
extras.onStart({
|
|
254
|
+
abortUpload: () => {
|
|
255
|
+
console.log('Aborting upload');
|
|
256
|
+
xhr.abort();
|
|
257
|
+
requestRunning = false;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
const backendRequest = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1], void 0, function* (url, options = {}, onSuccess, onError, onRedirect, requestType = 'query', handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0, extras) {
|
|
263
|
+
var _a;
|
|
216
264
|
if (requestRunning && !retrial) { // only allow one request at a time
|
|
217
|
-
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false), 300);
|
|
265
|
+
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false, retrialNum), 300);
|
|
218
266
|
return;
|
|
219
267
|
}
|
|
220
|
-
|
|
221
|
-
const backendToken = window.
|
|
222
|
-
if (backendToken)
|
|
223
|
-
|
|
224
|
-
options.headers = {};
|
|
225
|
-
options.headers.auth = backendToken;
|
|
226
|
-
}
|
|
268
|
+
const headers = new Headers(options.headers);
|
|
269
|
+
const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
|
|
270
|
+
if (backendToken)
|
|
271
|
+
headers.set('auth', backendToken);
|
|
227
272
|
let response;
|
|
228
273
|
requestRunning = true;
|
|
229
274
|
const controller = new AbortController();
|
|
@@ -238,17 +283,19 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
|
|
|
238
283
|
const event = new CustomEvent('slow-request', { detail: requestUrl.pathname, bubbles: true });
|
|
239
284
|
window.dispatchEvent(event);
|
|
240
285
|
}, slowRequestTimeout);
|
|
241
|
-
const requestInit = Object.assign(Object.assign({}, options), { signal: controller.signal });
|
|
286
|
+
const requestInit = Object.assign(Object.assign({}, options), { headers, signal: controller.signal });
|
|
242
287
|
if (onRedirect)
|
|
243
288
|
requestInit.redirect = 'manual'; // Treat redirects manually instead of following them automatically.
|
|
289
|
+
if (requestType === 'upload') {
|
|
290
|
+
uploadRequest(url, options.file, onSuccess, onError, extras);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
244
293
|
try {
|
|
245
294
|
response = yield fetch(url, requestInit);
|
|
246
295
|
}
|
|
247
296
|
catch (err) {
|
|
248
|
-
// network errors
|
|
249
297
|
if (requestType === 'command') {
|
|
250
|
-
|
|
251
|
-
onError('There was an error performing your request. Please try again later.');
|
|
298
|
+
onError === null || onError === void 0 ? void 0 : onError('There was an error performing your request. Please try again later.');
|
|
252
299
|
requestRunning = false;
|
|
253
300
|
return;
|
|
254
301
|
}
|
|
@@ -297,20 +344,14 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
|
|
|
297
344
|
try {
|
|
298
345
|
const jsonResponse = yield response.json();
|
|
299
346
|
if (response.ok) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
return jsonResponse;
|
|
305
|
-
}
|
|
347
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(jsonResponse);
|
|
348
|
+
return;
|
|
306
349
|
}
|
|
307
350
|
else {
|
|
308
|
-
|
|
309
|
-
onError(jsonResponse);
|
|
351
|
+
onError === null || onError === void 0 ? void 0 : onError(jsonResponse);
|
|
310
352
|
}
|
|
311
353
|
}
|
|
312
354
|
catch (err) {
|
|
313
|
-
// json conversion error / json response dealing errors / onSuccess errors
|
|
314
355
|
console.error(err);
|
|
315
356
|
}
|
|
316
357
|
finally {
|
|
@@ -333,7 +374,7 @@ const post = (endpoint, params, onSuccess, onError, onRedirect, requestType = "q
|
|
|
333
374
|
// @ts-ignore
|
|
334
375
|
options.body = content;
|
|
335
376
|
}
|
|
336
|
-
return
|
|
377
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized);
|
|
337
378
|
};
|
|
338
379
|
const get = (endpoint, onSuccess, onError, onRedirect, handleUnauthorized) => {
|
|
339
380
|
const options = {
|
|
@@ -343,7 +384,7 @@ const get = (endpoint, onSuccess, onError, onRedirect, handleUnauthorized) => {
|
|
|
343
384
|
'Content-Type': 'application/json',
|
|
344
385
|
}
|
|
345
386
|
};
|
|
346
|
-
return
|
|
387
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, 'query', handleUnauthorized);
|
|
347
388
|
};
|
|
348
389
|
const backendPost = (endpoint, postContent, onJsonResponse, onHelpMessage, handleUnauthorized) => {
|
|
349
390
|
post(endpoint, postContent, onJsonResponse, onHelpMessage, null, 'command', handleUnauthorized);
|
|
@@ -361,9 +402,15 @@ const backendGet = (endpoint, params, onJsonResponse, onHelpMessage, handleUnaut
|
|
|
361
402
|
};
|
|
362
403
|
const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
|
|
363
404
|
const { email, token } = data;
|
|
364
|
-
const url = getMagicAuthReqUrl() +
|
|
405
|
+
const url = getMagicAuthReqUrl() +
|
|
406
|
+
encodeURIComponent(email) +
|
|
407
|
+
'&destination=' +
|
|
408
|
+
extractTokenFromWindowLocation('destination') +
|
|
409
|
+
'&token=' +
|
|
410
|
+
token;
|
|
365
411
|
const options = {};
|
|
366
|
-
backendRequest(url, options, onJsonResponse, console.error,
|
|
412
|
+
backendRequest(url, options, onJsonResponse, console.error, undefined, // ← use undefined instead of null
|
|
413
|
+
'query', onUnauthorized);
|
|
367
414
|
};
|
|
368
415
|
const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
|
|
369
416
|
backendRequest(getMagicAuthUrl() + magicToken, {}, onJsonResponse, onHelpMessage);
|
|
@@ -479,9 +526,9 @@ const onUserChanged = (googleUser, onUserLogin) => {
|
|
|
479
526
|
if (googleUser) {
|
|
480
527
|
// mixpanelIdentify(googleUser); TODO
|
|
481
528
|
const onSuccess = (res) => {
|
|
529
|
+
var _a;
|
|
482
530
|
const { token } = res;
|
|
483
|
-
|
|
484
|
-
window.store.currentUser = res;
|
|
531
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
|
|
485
532
|
onTokenAcquired(token, onUserLogin);
|
|
486
533
|
};
|
|
487
534
|
const onError = (err) => {
|
|
@@ -833,12 +880,11 @@ const sendInquiry = (name, email, msg, whatsapp, subject, token) => {
|
|
|
833
880
|
// checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
|
|
834
881
|
};
|
|
835
882
|
const contactUsModal = (subject) => {
|
|
836
|
-
var _a, _b, _c, _d, _e;
|
|
883
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
837
884
|
const result = document.createElement('contact-us-modal');
|
|
838
|
-
|
|
839
|
-
const currentName =
|
|
840
|
-
|
|
841
|
-
const currentEmail = window.store.currentUser ? window.store.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;
|
|
842
888
|
const modalBody = document.createElement('modal-body');
|
|
843
889
|
const form = document.createElement('form');
|
|
844
890
|
form.id = 'contact-form';
|
|
@@ -854,11 +900,10 @@ const contactUsModal = (subject) => {
|
|
|
854
900
|
const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
|
|
855
901
|
modal.id = 'contact-us-modal';
|
|
856
902
|
document.body.appendChild(modal);
|
|
857
|
-
(
|
|
903
|
+
(_c = modal.querySelector('modal-wrapper')) === null || _c === void 0 ? void 0 : _c.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
|
|
858
904
|
const captcha = googleCaptcha();
|
|
859
905
|
if (subject !== 'email-not-sent') {
|
|
860
|
-
|
|
861
|
-
const admin = ((_d = (_c = window.store) === null || _c === void 0 ? void 0 : _c.selectedTeam) === null || _d === void 0 ? void 0 : _d.admin) || window.store.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);
|
|
862
907
|
backendGet('credits-balance-for', { admin }, (res) => {
|
|
863
908
|
const balance = res;
|
|
864
909
|
if (balance <= 0) {
|
|
@@ -870,7 +915,7 @@ const contactUsModal = (subject) => {
|
|
|
870
915
|
else {
|
|
871
916
|
form.insertBefore(captcha, btn);
|
|
872
917
|
}
|
|
873
|
-
(
|
|
918
|
+
(_h = nameField.querySelector('input')) === null || _h === void 0 ? void 0 : _h.select();
|
|
874
919
|
form.addEventListener('submit', (event) => {
|
|
875
920
|
event.preventDefault();
|
|
876
921
|
sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
|
|
@@ -990,18 +1035,39 @@ const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn, failInfo) =>
|
|
|
990
1035
|
return result;
|
|
991
1036
|
};
|
|
992
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
|
+
|
|
993
1061
|
const setBackendToken = (token) => {
|
|
994
|
-
|
|
995
|
-
window.
|
|
996
|
-
if (token)
|
|
1062
|
+
var _a;
|
|
1063
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setBackendToken(token);
|
|
1064
|
+
if (token)
|
|
997
1065
|
setLocalStorageItem('token', token);
|
|
998
|
-
}
|
|
999
1066
|
};
|
|
1000
1067
|
const getBackendToken = () => {
|
|
1001
|
-
var _a;
|
|
1068
|
+
var _a, _b;
|
|
1002
1069
|
const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
|
|
1003
|
-
|
|
1004
|
-
window.store.backendToken = token;
|
|
1070
|
+
(_b = window.juxWebGlobal) === null || _b === void 0 ? void 0 : _b.setBackendToken(token);
|
|
1005
1071
|
return token;
|
|
1006
1072
|
};
|
|
1007
1073
|
const onTokenAcquired = (token, onUserLogin) => {
|
|
@@ -1011,8 +1077,7 @@ const onTokenAcquired = (token, onUserLogin) => {
|
|
|
1011
1077
|
};
|
|
1012
1078
|
const clearSession = () => {
|
|
1013
1079
|
removeLocalStorageItem('token');
|
|
1014
|
-
|
|
1015
|
-
window.store = {};
|
|
1080
|
+
resetJuxWebGlobal();
|
|
1016
1081
|
};
|
|
1017
1082
|
const onAuthenticationFailure = (msg) => {
|
|
1018
1083
|
removeLocalStorageItem('token');
|
|
@@ -1020,11 +1085,11 @@ const onAuthenticationFailure = (msg) => {
|
|
|
1020
1085
|
alert(getTranslation(msg));
|
|
1021
1086
|
};
|
|
1022
1087
|
const onAuthentication = (onUserLogin, user, type) => {
|
|
1088
|
+
var _a;
|
|
1023
1089
|
if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
|
|
1024
1090
|
clearSession();
|
|
1025
1091
|
}
|
|
1026
|
-
|
|
1027
|
-
window.store.currentUser = user;
|
|
1092
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(user);
|
|
1028
1093
|
if (type === 'Token Authentication') {
|
|
1029
1094
|
user.token = getLocalStorageItem('token');
|
|
1030
1095
|
}
|
|
@@ -1063,17 +1128,11 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
|
|
|
1063
1128
|
// initDemo(setBackendToken, onAuthentication);
|
|
1064
1129
|
// return;
|
|
1065
1130
|
// }
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
// @ts-ignore
|
|
1072
|
-
window.store.fetchUserBackendUrl = fetchUserBackendUrl;
|
|
1073
|
-
// @ts-ignore
|
|
1074
|
-
window.store.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
|
|
1075
|
-
// @ts-ignore
|
|
1076
|
-
window.store.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;
|
|
1077
1136
|
if (urlPrefix)
|
|
1078
1137
|
setUrlPrefix(urlPrefix);
|
|
1079
1138
|
const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
|
|
@@ -1083,8 +1142,7 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
|
|
|
1083
1142
|
};
|
|
1084
1143
|
const host = extractTokenFromWindowLocation('host');
|
|
1085
1144
|
if (host) {
|
|
1086
|
-
|
|
1087
|
-
window.store.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
1145
|
+
window.juxWebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
1088
1146
|
setBackendUrl(backendUrl);
|
|
1089
1147
|
onOpenMagicLink();
|
|
1090
1148
|
});
|
|
@@ -1127,9 +1185,9 @@ const onMicrosoftSignIn = (onUserLogin) => __awaiter(void 0, void 0, void 0, fun
|
|
|
1127
1185
|
const loginResponse = yield msalInstance.loginPopup(loginRequest);
|
|
1128
1186
|
const { accessToken } = loginResponse;
|
|
1129
1187
|
const onSuccess = (res) => {
|
|
1188
|
+
var _a;
|
|
1130
1189
|
const { token } = res;
|
|
1131
|
-
|
|
1132
|
-
window.store.currentUser = res;
|
|
1190
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
|
|
1133
1191
|
onTokenAcquired(token, onUserLogin);
|
|
1134
1192
|
disableSignInLayout();
|
|
1135
1193
|
};
|
|
@@ -1160,9 +1218,9 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
|
|
|
1160
1218
|
const { email } = credentials;
|
|
1161
1219
|
enableSignInLayout();
|
|
1162
1220
|
const onSuccess = (res) => {
|
|
1221
|
+
var _a;
|
|
1163
1222
|
const { token } = res;
|
|
1164
|
-
|
|
1165
|
-
window.store.currentUser = res;
|
|
1223
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
|
|
1166
1224
|
onTokenAcquired(token, onUserLogin);
|
|
1167
1225
|
disableSignInLayout();
|
|
1168
1226
|
};
|
|
@@ -1180,6 +1238,7 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
|
|
|
1180
1238
|
authPasswordLogin(credentials, onSuccess, onError, onUnauthorized);
|
|
1181
1239
|
};
|
|
1182
1240
|
const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
|
|
1241
|
+
var _a;
|
|
1183
1242
|
if (!email) {
|
|
1184
1243
|
const mailMagic = document.querySelector('#mail-magic');
|
|
1185
1244
|
email = mailMagic.value;
|
|
@@ -1196,10 +1255,8 @@ const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, c
|
|
|
1196
1255
|
const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
|
|
1197
1256
|
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
1198
1257
|
};
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
// @ts-ignore
|
|
1202
|
-
window.store.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
1258
|
+
if ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.fetchUserBackendUrl) {
|
|
1259
|
+
window.juxWebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
1203
1260
|
setBackendUrl(backendUrl);
|
|
1204
1261
|
onRequestMagicLink();
|
|
1205
1262
|
});
|
|
@@ -1432,7 +1489,7 @@ const loginPage = (clientApp, backgroundImg, onUserLogin, onLoginError, loginTyp
|
|
|
1432
1489
|
};
|
|
1433
1490
|
|
|
1434
1491
|
class JuxEvent extends Event {
|
|
1435
|
-
constructor(type, method, endpoint, onResult, params, onError, onRedirect) {
|
|
1492
|
+
constructor(type, method, endpoint, onResult, params, onError, onRedirect, extras) {
|
|
1436
1493
|
super('jux-event', { bubbles: true, cancelable: true, composed: true });
|
|
1437
1494
|
this.requestType = type;
|
|
1438
1495
|
this.method = method;
|
|
@@ -1441,6 +1498,7 @@ class JuxEvent extends Event {
|
|
|
1441
1498
|
this.params = params;
|
|
1442
1499
|
this.onError = onError;
|
|
1443
1500
|
this.onRedirect = onRedirect;
|
|
1501
|
+
this.extras = extras;
|
|
1444
1502
|
}
|
|
1445
1503
|
}
|
|
1446
1504
|
const query = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
@@ -1450,4 +1508,4 @@ const command = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
|
1450
1508
|
element.dispatchEvent(new JuxEvent('command', 'POST', endpoint, onResult, params, onError, onRedirect));
|
|
1451
1509
|
};
|
|
1452
1510
|
|
|
1453
|
-
export { chosenLanguage, clearSession, command, getTranslation, handleJuxEvent, handleMagicLinkRequest, initLanguage, initSession, loginButton, loginPage, magicLinkModal, onMicrosoftSignIn, query, reloadWithLanguageOverride, requestMagicLink };
|
|
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
|
-
|
|
190
|
-
const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === 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
|
-
|
|
196
|
-
const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === 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
|
|
@@ -236,18 +234,65 @@ let timeout = 20000;
|
|
|
236
234
|
const slowRequestTimeout = 2000;
|
|
237
235
|
// @ts-ignore
|
|
238
236
|
window.setRequestTimeout = (newTimeout) => timeout = newTimeout;
|
|
239
|
-
const
|
|
237
|
+
const upload = (endpoint, file, onResult, onError, extras) => {
|
|
238
|
+
apiRequest(endpoint, {
|
|
239
|
+
file,
|
|
240
|
+
onProgress: (pct) => { var _a; return (_a = extras === null || extras === void 0 ? void 0 : extras.onProgress) === null || _a === void 0 ? void 0 : _a.call(extras, pct); }
|
|
241
|
+
}, (text) => onResult === null || onResult === void 0 ? void 0 : onResult(text), (err) => onError === null || onError === void 0 ? void 0 : onError(err), undefined, // no redirect handler
|
|
242
|
+
'upload', // requestType
|
|
243
|
+
undefined, undefined, undefined, extras);
|
|
244
|
+
};
|
|
245
|
+
const apiRequest = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1], void 0, function* (url, options = {}, onSuccess, onError, onRedirect, requestType = 'query', handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0, extras) {
|
|
246
|
+
url = getApiUrl() + url;
|
|
247
|
+
backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, retrial, retrialNum, extras);
|
|
248
|
+
});
|
|
249
|
+
const uploadRequest = (url, file, onSuccess, onError, extras) => {
|
|
250
|
+
var _a;
|
|
251
|
+
requestRunning = true;
|
|
252
|
+
const xhr = new XMLHttpRequest();
|
|
253
|
+
xhr.open('POST', url);
|
|
254
|
+
const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
|
|
255
|
+
if (backendToken)
|
|
256
|
+
xhr.setRequestHeader('auth', backendToken);
|
|
257
|
+
xhr.upload.onprogress = (e) => {
|
|
258
|
+
if (e.lengthComputable && (extras === null || extras === void 0 ? void 0 : extras.onProgress)) {
|
|
259
|
+
extras.onProgress(Math.round((e.loaded / e.total) * 100));
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
xhr.onload = () => {
|
|
263
|
+
requestRunning = false;
|
|
264
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
265
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(xhr.responseText);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
onError === null || onError === void 0 ? void 0 : onError(xhr.responseText);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
xhr.onerror = () => {
|
|
272
|
+
requestRunning = false;
|
|
273
|
+
onError === null || onError === void 0 ? void 0 : onError('Error sending file. Please try again.');
|
|
274
|
+
};
|
|
275
|
+
xhr.send(file);
|
|
276
|
+
if (extras === null || extras === void 0 ? void 0 : extras.onStart) {
|
|
277
|
+
extras.onStart({
|
|
278
|
+
abortUpload: () => {
|
|
279
|
+
console.log('Aborting upload');
|
|
280
|
+
xhr.abort();
|
|
281
|
+
requestRunning = false;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
const backendRequest = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1], void 0, function* (url, options = {}, onSuccess, onError, onRedirect, requestType = 'query', handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0, extras) {
|
|
287
|
+
var _a;
|
|
240
288
|
if (requestRunning && !retrial) { // only allow one request at a time
|
|
241
|
-
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false), 300);
|
|
289
|
+
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false, retrialNum), 300);
|
|
242
290
|
return;
|
|
243
291
|
}
|
|
244
|
-
|
|
245
|
-
const backendToken = window.
|
|
246
|
-
if (backendToken)
|
|
247
|
-
|
|
248
|
-
options.headers = {};
|
|
249
|
-
options.headers.auth = backendToken;
|
|
250
|
-
}
|
|
292
|
+
const headers = new Headers(options.headers);
|
|
293
|
+
const backendToken = (_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.getBackendToken();
|
|
294
|
+
if (backendToken)
|
|
295
|
+
headers.set('auth', backendToken);
|
|
251
296
|
let response;
|
|
252
297
|
requestRunning = true;
|
|
253
298
|
const controller = new AbortController();
|
|
@@ -262,17 +307,19 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
|
|
|
262
307
|
const event = new CustomEvent('slow-request', { detail: requestUrl.pathname, bubbles: true });
|
|
263
308
|
window.dispatchEvent(event);
|
|
264
309
|
}, slowRequestTimeout);
|
|
265
|
-
const requestInit = Object.assign(Object.assign({}, options), { signal: controller.signal });
|
|
310
|
+
const requestInit = Object.assign(Object.assign({}, options), { headers, signal: controller.signal });
|
|
266
311
|
if (onRedirect)
|
|
267
312
|
requestInit.redirect = 'manual'; // Treat redirects manually instead of following them automatically.
|
|
313
|
+
if (requestType === 'upload') {
|
|
314
|
+
uploadRequest(url, options.file, onSuccess, onError, extras);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
268
317
|
try {
|
|
269
318
|
response = yield fetch(url, requestInit);
|
|
270
319
|
}
|
|
271
320
|
catch (err) {
|
|
272
|
-
// network errors
|
|
273
321
|
if (requestType === 'command') {
|
|
274
|
-
|
|
275
|
-
onError('There was an error performing your request. Please try again later.');
|
|
322
|
+
onError === null || onError === void 0 ? void 0 : onError('There was an error performing your request. Please try again later.');
|
|
276
323
|
requestRunning = false;
|
|
277
324
|
return;
|
|
278
325
|
}
|
|
@@ -321,20 +368,14 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
|
|
|
321
368
|
try {
|
|
322
369
|
const jsonResponse = yield response.json();
|
|
323
370
|
if (response.ok) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
return jsonResponse;
|
|
329
|
-
}
|
|
371
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(jsonResponse);
|
|
372
|
+
return;
|
|
330
373
|
}
|
|
331
374
|
else {
|
|
332
|
-
|
|
333
|
-
onError(jsonResponse);
|
|
375
|
+
onError === null || onError === void 0 ? void 0 : onError(jsonResponse);
|
|
334
376
|
}
|
|
335
377
|
}
|
|
336
378
|
catch (err) {
|
|
337
|
-
// json conversion error / json response dealing errors / onSuccess errors
|
|
338
379
|
console.error(err);
|
|
339
380
|
}
|
|
340
381
|
finally {
|
|
@@ -357,7 +398,7 @@ const post = (endpoint, params, onSuccess, onError, onRedirect, requestType = "q
|
|
|
357
398
|
// @ts-ignore
|
|
358
399
|
options.body = content;
|
|
359
400
|
}
|
|
360
|
-
return
|
|
401
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized);
|
|
361
402
|
};
|
|
362
403
|
const get = (endpoint, onSuccess, onError, onRedirect, handleUnauthorized) => {
|
|
363
404
|
const options = {
|
|
@@ -367,7 +408,7 @@ const get = (endpoint, onSuccess, onError, onRedirect, handleUnauthorized) => {
|
|
|
367
408
|
'Content-Type': 'application/json',
|
|
368
409
|
}
|
|
369
410
|
};
|
|
370
|
-
return
|
|
411
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, 'query', handleUnauthorized);
|
|
371
412
|
};
|
|
372
413
|
const backendPost = (endpoint, postContent, onJsonResponse, onHelpMessage, handleUnauthorized) => {
|
|
373
414
|
post(endpoint, postContent, onJsonResponse, onHelpMessage, null, 'command', handleUnauthorized);
|
|
@@ -385,9 +426,15 @@ const backendGet = (endpoint, params, onJsonResponse, onHelpMessage, handleUnaut
|
|
|
385
426
|
};
|
|
386
427
|
const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
|
|
387
428
|
const { email, token } = data;
|
|
388
|
-
const url = getMagicAuthReqUrl() +
|
|
429
|
+
const url = getMagicAuthReqUrl() +
|
|
430
|
+
encodeURIComponent(email) +
|
|
431
|
+
'&destination=' +
|
|
432
|
+
extractTokenFromWindowLocation('destination') +
|
|
433
|
+
'&token=' +
|
|
434
|
+
token;
|
|
389
435
|
const options = {};
|
|
390
|
-
backendRequest(url, options, onJsonResponse, console.error,
|
|
436
|
+
backendRequest(url, options, onJsonResponse, console.error, undefined, // ← use undefined instead of null
|
|
437
|
+
'query', onUnauthorized);
|
|
391
438
|
};
|
|
392
439
|
const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
|
|
393
440
|
backendRequest(getMagicAuthUrl() + magicToken, {}, onJsonResponse, onHelpMessage);
|
|
@@ -503,9 +550,9 @@ const onUserChanged = (googleUser, onUserLogin) => {
|
|
|
503
550
|
if (googleUser) {
|
|
504
551
|
// mixpanelIdentify(googleUser); TODO
|
|
505
552
|
const onSuccess = (res) => {
|
|
553
|
+
var _a;
|
|
506
554
|
const { token } = res;
|
|
507
|
-
|
|
508
|
-
window.store.currentUser = res;
|
|
555
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
|
|
509
556
|
onTokenAcquired(token, onUserLogin);
|
|
510
557
|
};
|
|
511
558
|
const onError = (err) => {
|
|
@@ -857,12 +904,11 @@ const sendInquiry = (name, email, msg, whatsapp, subject, token) => {
|
|
|
857
904
|
// checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
|
|
858
905
|
};
|
|
859
906
|
const contactUsModal = (subject) => {
|
|
860
|
-
var _a, _b, _c, _d, _e;
|
|
907
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
861
908
|
const result = document.createElement('contact-us-modal');
|
|
862
|
-
|
|
863
|
-
const currentName =
|
|
864
|
-
|
|
865
|
-
const currentEmail = window.store.currentUser ? window.store.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;
|
|
866
912
|
const modalBody = document.createElement('modal-body');
|
|
867
913
|
const form = document.createElement('form');
|
|
868
914
|
form.id = 'contact-form';
|
|
@@ -878,11 +924,10 @@ const contactUsModal = (subject) => {
|
|
|
878
924
|
const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
|
|
879
925
|
modal.id = 'contact-us-modal';
|
|
880
926
|
document.body.appendChild(modal);
|
|
881
|
-
(
|
|
927
|
+
(_c = modal.querySelector('modal-wrapper')) === null || _c === void 0 ? void 0 : _c.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
|
|
882
928
|
const captcha = googleCaptcha();
|
|
883
929
|
if (subject !== 'email-not-sent') {
|
|
884
|
-
|
|
885
|
-
const admin = ((_d = (_c = window.store) === null || _c === void 0 ? void 0 : _c.selectedTeam) === null || _d === void 0 ? void 0 : _d.admin) || window.store.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);
|
|
886
931
|
backendGet('credits-balance-for', { admin }, (res) => {
|
|
887
932
|
const balance = res;
|
|
888
933
|
if (balance <= 0) {
|
|
@@ -894,7 +939,7 @@ const contactUsModal = (subject) => {
|
|
|
894
939
|
else {
|
|
895
940
|
form.insertBefore(captcha, btn);
|
|
896
941
|
}
|
|
897
|
-
(
|
|
942
|
+
(_h = nameField.querySelector('input')) === null || _h === void 0 ? void 0 : _h.select();
|
|
898
943
|
form.addEventListener('submit', (event) => {
|
|
899
944
|
event.preventDefault();
|
|
900
945
|
sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
|
|
@@ -1014,18 +1059,39 @@ const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn, failInfo) =>
|
|
|
1014
1059
|
return result;
|
|
1015
1060
|
};
|
|
1016
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
|
+
|
|
1017
1085
|
const setBackendToken = (token) => {
|
|
1018
|
-
|
|
1019
|
-
window.
|
|
1020
|
-
if (token)
|
|
1086
|
+
var _a;
|
|
1087
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setBackendToken(token);
|
|
1088
|
+
if (token)
|
|
1021
1089
|
setLocalStorageItem('token', token);
|
|
1022
|
-
}
|
|
1023
1090
|
};
|
|
1024
1091
|
const getBackendToken = () => {
|
|
1025
|
-
var _a;
|
|
1092
|
+
var _a, _b;
|
|
1026
1093
|
const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
|
|
1027
|
-
|
|
1028
|
-
window.store.backendToken = token;
|
|
1094
|
+
(_b = window.juxWebGlobal) === null || _b === void 0 ? void 0 : _b.setBackendToken(token);
|
|
1029
1095
|
return token;
|
|
1030
1096
|
};
|
|
1031
1097
|
const onTokenAcquired = (token, onUserLogin) => {
|
|
@@ -1035,8 +1101,7 @@ const onTokenAcquired = (token, onUserLogin) => {
|
|
|
1035
1101
|
};
|
|
1036
1102
|
const clearSession = () => {
|
|
1037
1103
|
removeLocalStorageItem('token');
|
|
1038
|
-
|
|
1039
|
-
window.store = {};
|
|
1104
|
+
resetJuxWebGlobal();
|
|
1040
1105
|
};
|
|
1041
1106
|
const onAuthenticationFailure = (msg) => {
|
|
1042
1107
|
removeLocalStorageItem('token');
|
|
@@ -1044,11 +1109,11 @@ const onAuthenticationFailure = (msg) => {
|
|
|
1044
1109
|
alert(getTranslation(msg));
|
|
1045
1110
|
};
|
|
1046
1111
|
const onAuthentication = (onUserLogin, user, type) => {
|
|
1112
|
+
var _a;
|
|
1047
1113
|
if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
|
|
1048
1114
|
clearSession();
|
|
1049
1115
|
}
|
|
1050
|
-
|
|
1051
|
-
window.store.currentUser = user;
|
|
1116
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(user);
|
|
1052
1117
|
if (type === 'Token Authentication') {
|
|
1053
1118
|
user.token = getLocalStorageItem('token');
|
|
1054
1119
|
}
|
|
@@ -1087,17 +1152,11 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
|
|
|
1087
1152
|
// initDemo(setBackendToken, onAuthentication);
|
|
1088
1153
|
// return;
|
|
1089
1154
|
// }
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
// @ts-ignore
|
|
1096
|
-
window.store.fetchUserBackendUrl = fetchUserBackendUrl;
|
|
1097
|
-
// @ts-ignore
|
|
1098
|
-
window.store.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
|
|
1099
|
-
// @ts-ignore
|
|
1100
|
-
window.store.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;
|
|
1101
1160
|
if (urlPrefix)
|
|
1102
1161
|
setUrlPrefix(urlPrefix);
|
|
1103
1162
|
const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
|
|
@@ -1107,8 +1166,7 @@ const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError
|
|
|
1107
1166
|
};
|
|
1108
1167
|
const host = extractTokenFromWindowLocation('host');
|
|
1109
1168
|
if (host) {
|
|
1110
|
-
|
|
1111
|
-
window.store.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
1169
|
+
window.juxWebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
1112
1170
|
setBackendUrl(backendUrl);
|
|
1113
1171
|
onOpenMagicLink();
|
|
1114
1172
|
});
|
|
@@ -1151,9 +1209,9 @@ const onMicrosoftSignIn = (onUserLogin) => __awaiter(void 0, void 0, void 0, fun
|
|
|
1151
1209
|
const loginResponse = yield msalInstance.loginPopup(loginRequest);
|
|
1152
1210
|
const { accessToken } = loginResponse;
|
|
1153
1211
|
const onSuccess = (res) => {
|
|
1212
|
+
var _a;
|
|
1154
1213
|
const { token } = res;
|
|
1155
|
-
|
|
1156
|
-
window.store.currentUser = res;
|
|
1214
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
|
|
1157
1215
|
onTokenAcquired(token, onUserLogin);
|
|
1158
1216
|
disableSignInLayout();
|
|
1159
1217
|
};
|
|
@@ -1184,9 +1242,9 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
|
|
|
1184
1242
|
const { email } = credentials;
|
|
1185
1243
|
enableSignInLayout();
|
|
1186
1244
|
const onSuccess = (res) => {
|
|
1245
|
+
var _a;
|
|
1187
1246
|
const { token } = res;
|
|
1188
|
-
|
|
1189
|
-
window.store.currentUser = res;
|
|
1247
|
+
(_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.setCurrentUser(res);
|
|
1190
1248
|
onTokenAcquired(token, onUserLogin);
|
|
1191
1249
|
disableSignInLayout();
|
|
1192
1250
|
};
|
|
@@ -1204,6 +1262,7 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
|
|
|
1204
1262
|
authPasswordLogin(credentials, onSuccess, onError, onUnauthorized);
|
|
1205
1263
|
};
|
|
1206
1264
|
const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
|
|
1265
|
+
var _a;
|
|
1207
1266
|
if (!email) {
|
|
1208
1267
|
const mailMagic = document.querySelector('#mail-magic');
|
|
1209
1268
|
email = mailMagic.value;
|
|
@@ -1220,10 +1279,8 @@ const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, c
|
|
|
1220
1279
|
const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
|
|
1221
1280
|
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
1222
1281
|
};
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
// @ts-ignore
|
|
1226
|
-
window.store.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
1282
|
+
if ((_a = window.juxWebGlobal) === null || _a === void 0 ? void 0 : _a.fetchUserBackendUrl) {
|
|
1283
|
+
window.juxWebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
1227
1284
|
setBackendUrl(backendUrl);
|
|
1228
1285
|
onRequestMagicLink();
|
|
1229
1286
|
});
|
|
@@ -1456,7 +1513,7 @@ const loginPage = (clientApp, backgroundImg, onUserLogin, onLoginError, loginTyp
|
|
|
1456
1513
|
};
|
|
1457
1514
|
|
|
1458
1515
|
class JuxEvent extends Event {
|
|
1459
|
-
constructor(type, method, endpoint, onResult, params, onError, onRedirect) {
|
|
1516
|
+
constructor(type, method, endpoint, onResult, params, onError, onRedirect, extras) {
|
|
1460
1517
|
super('jux-event', { bubbles: true, cancelable: true, composed: true });
|
|
1461
1518
|
this.requestType = type;
|
|
1462
1519
|
this.method = method;
|
|
@@ -1465,6 +1522,7 @@ class JuxEvent extends Event {
|
|
|
1465
1522
|
this.params = params;
|
|
1466
1523
|
this.onError = onError;
|
|
1467
1524
|
this.onRedirect = onRedirect;
|
|
1525
|
+
this.extras = extras;
|
|
1468
1526
|
}
|
|
1469
1527
|
}
|
|
1470
1528
|
const query = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
@@ -1477,6 +1535,7 @@ const command = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
|
1477
1535
|
exports.chosenLanguage = chosenLanguage;
|
|
1478
1536
|
exports.clearSession = clearSession;
|
|
1479
1537
|
exports.command = command;
|
|
1538
|
+
exports.getCurrentUser = getCurrentUser;
|
|
1480
1539
|
exports.getTranslation = getTranslation;
|
|
1481
1540
|
exports.handleJuxEvent = handleJuxEvent;
|
|
1482
1541
|
exports.handleMagicLinkRequest = handleMagicLinkRequest;
|
|
@@ -1489,3 +1548,5 @@ exports.onMicrosoftSignIn = onMicrosoftSignIn;
|
|
|
1489
1548
|
exports.query = query;
|
|
1490
1549
|
exports.reloadWithLanguageOverride = reloadWithLanguageOverride;
|
|
1491
1550
|
exports.requestMagicLink = requestMagicLink;
|
|
1551
|
+
exports.resetJuxWebGlobal = resetJuxWebGlobal;
|
|
1552
|
+
exports.upload = upload;
|