@klauswuestefeld/jux-web 2025.5.24 → 2025.6.30
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 +17 -1
- package/dist/jux/jux-event.d.ts +2 -1
- package/dist/jux-web.js +118 -63
- package/dist/local-storage/utils.d.ts +4 -0
- package/dist/login/session.d.ts +14 -2
- package/dist/main.d.ts +1 -1
- package/dist/main.esm.js +118 -64
- package/dist/main.js +118 -63
- package/package.json +1 -1
package/dist/api-client.d.ts
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
store: {
|
|
5
|
+
backendToken?: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
}
|
|
1
9
|
export declare const setBackendUrl: (backendUrl: string) => void;
|
|
2
10
|
export declare const getBackendUrl: () => string;
|
|
3
11
|
export declare const handleJuxEvent: (ev: Event) => void;
|
|
4
|
-
export
|
|
12
|
+
export interface BackendRequestOptions extends RequestInit {
|
|
13
|
+
file?: File;
|
|
14
|
+
onProgress?: (percent: number) => void;
|
|
15
|
+
}
|
|
16
|
+
export type RequestType = 'query' | 'command' | 'upload';
|
|
17
|
+
export declare const upload: (endpoint: string, file: File, onResult?: (result: any) => any, onError?: (error: any) => void, extras?: {
|
|
18
|
+
onProgress?: (percent: number) => void;
|
|
19
|
+
onStart?: () => void;
|
|
20
|
+
}) => void;
|
|
5
21
|
export declare const backendPost: (endpoint: string, postContent: any, onJsonResponse: (response: any) => any, onHelpMessage: (message: string) => any, handleUnauthorized?: any) => void;
|
|
6
22
|
export declare const backendGet: (endpoint: string, params: any, onJsonResponse: (response: any) => any, onHelpMessage: (message: string) => any, handleUnauthorized?: any) => void;
|
|
7
23
|
export declare const requestMagicLink: (data: any, onJsonResponse: (response: any) => any, onUnauthorized: () => void) => void;
|
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;
|
package/dist/jux-web.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
var juxWeb = (function (exports) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
let urlPrefix;
|
|
5
|
+
const setUrlPrefix = (s) => urlPrefix = s;
|
|
6
|
+
const getLocalStorageKey = (k) => urlPrefix ? `${urlPrefix}_${k}` : k;
|
|
7
|
+
const getLocalStorageItem = (k) => localStorage.getItem(getLocalStorageKey(k));
|
|
8
|
+
const setLocalStorageItem = (k, v) => localStorage.setItem(getLocalStorageKey(k), v);
|
|
9
|
+
const removeLocalStorageItem = (k) => localStorage.removeItem(getLocalStorageKey(k));
|
|
10
|
+
|
|
4
11
|
const getBrowserLanguage = () => {
|
|
5
12
|
const result = (navigator.languages && navigator.languages.length)
|
|
6
13
|
? navigator.languages[0]
|
|
@@ -9,9 +16,9 @@ var juxWeb = (function (exports) {
|
|
|
9
16
|
};
|
|
10
17
|
const OVERRIDE_KEY = 'jux.language.override';
|
|
11
18
|
let translations = {};
|
|
12
|
-
const chosenLanguage =
|
|
19
|
+
const chosenLanguage = getLocalStorageItem(OVERRIDE_KEY) || getBrowserLanguage();
|
|
13
20
|
const reloadWithLanguageOverride = (lang) => {
|
|
14
|
-
|
|
21
|
+
setLocalStorageItem(OVERRIDE_KEY, lang);
|
|
15
22
|
location.reload();
|
|
16
23
|
};
|
|
17
24
|
// @ts-ignore
|
|
@@ -148,22 +155,22 @@ var juxWeb = (function (exports) {
|
|
|
148
155
|
return token;
|
|
149
156
|
};
|
|
150
157
|
|
|
151
|
-
const setBackendUrl = (backendUrl) =>
|
|
158
|
+
const setBackendUrl = (backendUrl) => setLocalStorageItem('backend-url', backendUrl);
|
|
152
159
|
//@ts-ignore
|
|
153
|
-
const getBackendUrl = () => process.env.BACKEND_URL ||
|
|
160
|
+
const getBackendUrl = () => process.env.BACKEND_URL || getLocalStorageItem('backend-url');
|
|
154
161
|
//@ts-ignore
|
|
155
162
|
const getSecondaryBackendUrl = () => process.env.STAGING_BACKEND_URL || getBackendUrl();
|
|
156
163
|
const getApiUrl = () => getBackendUrl() + 'api/';
|
|
157
164
|
const getMagicAuthUrl = () => {
|
|
158
165
|
var _a;
|
|
159
166
|
// @ts-ignore
|
|
160
|
-
const endpoint = ((_a = window
|
|
167
|
+
const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
|
|
161
168
|
return getBackendUrl() + endpoint + '?token=';
|
|
162
169
|
};
|
|
163
170
|
const getMagicAuthReqUrl = () => {
|
|
164
171
|
var _a;
|
|
165
172
|
// @ts-ignore
|
|
166
|
-
const endpoint = ((_a = window
|
|
173
|
+
const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
|
|
167
174
|
return getBackendUrl() + endpoint + '?email=';
|
|
168
175
|
};
|
|
169
176
|
// TODO: use jux-events to call commands and queries inside jux-web library
|
|
@@ -195,7 +202,7 @@ var juxWeb = (function (exports) {
|
|
|
195
202
|
(_b = document.querySelector('.reconnect-spinner')) === null || _b === void 0 ? void 0 : _b.remove();
|
|
196
203
|
};
|
|
197
204
|
const defaultHandleUnauthorized = () => {
|
|
198
|
-
|
|
205
|
+
removeLocalStorageItem('token');
|
|
199
206
|
alert(getTranslation('session-expired-msg'));
|
|
200
207
|
location.reload();
|
|
201
208
|
// googleAuthSignOut(); TODO
|
|
@@ -206,17 +213,65 @@ var juxWeb = (function (exports) {
|
|
|
206
213
|
const slowRequestTimeout = 2000;
|
|
207
214
|
// @ts-ignore
|
|
208
215
|
window.setRequestTimeout = (newTimeout) => timeout = newTimeout;
|
|
209
|
-
const
|
|
216
|
+
const upload = (endpoint, file, onResult, onError, extras) => {
|
|
217
|
+
apiRequest(endpoint, {
|
|
218
|
+
file,
|
|
219
|
+
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); }
|
|
220
|
+
}, (text) => onResult === null || onResult === void 0 ? void 0 : onResult(text), (err) => onError === null || onError === void 0 ? void 0 : onError(err), undefined, // no redirect handler
|
|
221
|
+
'upload', // requestType
|
|
222
|
+
undefined, undefined, undefined, extras);
|
|
223
|
+
};
|
|
224
|
+
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) {
|
|
225
|
+
url = getApiUrl() + url;
|
|
226
|
+
backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, retrial, retrialNum, extras);
|
|
227
|
+
});
|
|
228
|
+
const uploadRequest = (url, file, onSuccess, onError, extras) => {
|
|
229
|
+
var _a, _b;
|
|
230
|
+
requestRunning = true;
|
|
231
|
+
const xhr = new XMLHttpRequest();
|
|
232
|
+
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
|
+
}
|
|
236
|
+
xhr.upload.onprogress = (e) => {
|
|
237
|
+
if (e.lengthComputable && (extras === null || extras === void 0 ? void 0 : extras.onProgress)) {
|
|
238
|
+
extras.onProgress(Math.round((e.loaded / e.total) * 100));
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
xhr.onload = () => {
|
|
242
|
+
requestRunning = false;
|
|
243
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
244
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(xhr.responseText);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
onError === null || onError === void 0 ? void 0 : onError(xhr.responseText);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
xhr.onerror = () => {
|
|
251
|
+
requestRunning = false;
|
|
252
|
+
onError === null || onError === void 0 ? void 0 : onError('Error sending file. Please try again.');
|
|
253
|
+
};
|
|
254
|
+
xhr.send(file);
|
|
255
|
+
if (extras === null || extras === void 0 ? void 0 : extras.onStart) {
|
|
256
|
+
extras.onStart({
|
|
257
|
+
abortUpload: () => {
|
|
258
|
+
console.log('Aborting upload');
|
|
259
|
+
xhr.abort();
|
|
260
|
+
requestRunning = false;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
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) {
|
|
266
|
+
var _a;
|
|
210
267
|
if (requestRunning && !retrial) { // only allow one request at a time
|
|
211
|
-
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false), 300);
|
|
268
|
+
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false, retrialNum), 300);
|
|
212
269
|
return;
|
|
213
270
|
}
|
|
214
271
|
// @ts-ignore
|
|
215
|
-
const
|
|
216
|
-
if (backendToken) {
|
|
217
|
-
|
|
218
|
-
options.headers = {};
|
|
219
|
-
options.headers.auth = backendToken;
|
|
272
|
+
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);
|
|
220
275
|
}
|
|
221
276
|
let response;
|
|
222
277
|
requestRunning = true;
|
|
@@ -232,17 +287,19 @@ var juxWeb = (function (exports) {
|
|
|
232
287
|
const event = new CustomEvent('slow-request', { detail: requestUrl.pathname, bubbles: true });
|
|
233
288
|
window.dispatchEvent(event);
|
|
234
289
|
}, slowRequestTimeout);
|
|
235
|
-
const requestInit = Object.assign(Object.assign({}, options), { signal: controller.signal });
|
|
290
|
+
const requestInit = Object.assign(Object.assign({}, options), { headers, signal: controller.signal });
|
|
236
291
|
if (onRedirect)
|
|
237
292
|
requestInit.redirect = 'manual'; // Treat redirects manually instead of following them automatically.
|
|
293
|
+
if (requestType === 'upload') {
|
|
294
|
+
uploadRequest(url, options.file, onSuccess, onError, extras);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
238
297
|
try {
|
|
239
298
|
response = yield fetch(url, requestInit);
|
|
240
299
|
}
|
|
241
300
|
catch (err) {
|
|
242
|
-
// network errors
|
|
243
301
|
if (requestType === 'command') {
|
|
244
|
-
|
|
245
|
-
onError('There was an error performing your request. Please try again later.');
|
|
302
|
+
onError === null || onError === void 0 ? void 0 : onError('There was an error performing your request. Please try again later.');
|
|
246
303
|
requestRunning = false;
|
|
247
304
|
return;
|
|
248
305
|
}
|
|
@@ -291,20 +348,14 @@ var juxWeb = (function (exports) {
|
|
|
291
348
|
try {
|
|
292
349
|
const jsonResponse = yield response.json();
|
|
293
350
|
if (response.ok) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
return jsonResponse;
|
|
299
|
-
}
|
|
351
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(jsonResponse);
|
|
352
|
+
return;
|
|
300
353
|
}
|
|
301
354
|
else {
|
|
302
|
-
|
|
303
|
-
onError(jsonResponse);
|
|
355
|
+
onError === null || onError === void 0 ? void 0 : onError(jsonResponse);
|
|
304
356
|
}
|
|
305
357
|
}
|
|
306
358
|
catch (err) {
|
|
307
|
-
// json conversion error / json response dealing errors / onSuccess errors
|
|
308
359
|
console.error(err);
|
|
309
360
|
}
|
|
310
361
|
finally {
|
|
@@ -327,7 +378,7 @@ var juxWeb = (function (exports) {
|
|
|
327
378
|
// @ts-ignore
|
|
328
379
|
options.body = content;
|
|
329
380
|
}
|
|
330
|
-
return
|
|
381
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized);
|
|
331
382
|
};
|
|
332
383
|
const get = (endpoint, onSuccess, onError, onRedirect, handleUnauthorized) => {
|
|
333
384
|
const options = {
|
|
@@ -337,7 +388,7 @@ var juxWeb = (function (exports) {
|
|
|
337
388
|
'Content-Type': 'application/json',
|
|
338
389
|
}
|
|
339
390
|
};
|
|
340
|
-
return
|
|
391
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, 'query', handleUnauthorized);
|
|
341
392
|
};
|
|
342
393
|
const backendPost = (endpoint, postContent, onJsonResponse, onHelpMessage, handleUnauthorized) => {
|
|
343
394
|
post(endpoint, postContent, onJsonResponse, onHelpMessage, null, 'command', handleUnauthorized);
|
|
@@ -355,9 +406,15 @@ var juxWeb = (function (exports) {
|
|
|
355
406
|
};
|
|
356
407
|
const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
|
|
357
408
|
const { email, token } = data;
|
|
358
|
-
const url = getMagicAuthReqUrl() +
|
|
409
|
+
const url = getMagicAuthReqUrl() +
|
|
410
|
+
encodeURIComponent(email) +
|
|
411
|
+
'&destination=' +
|
|
412
|
+
extractTokenFromWindowLocation('destination') +
|
|
413
|
+
'&token=' +
|
|
414
|
+
token;
|
|
359
415
|
const options = {};
|
|
360
|
-
backendRequest(url, options, onJsonResponse, console.error,
|
|
416
|
+
backendRequest(url, options, onJsonResponse, console.error, undefined, // ← use undefined instead of null
|
|
417
|
+
'query', onUnauthorized);
|
|
361
418
|
};
|
|
362
419
|
const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
|
|
363
420
|
backendRequest(getMagicAuthUrl() + magicToken, {}, onJsonResponse, onHelpMessage);
|
|
@@ -13989,7 +14046,7 @@ var juxWeb = (function (exports) {
|
|
|
13989
14046
|
const onSuccess = (res) => {
|
|
13990
14047
|
const { token } = res;
|
|
13991
14048
|
// @ts-ignore
|
|
13992
|
-
window.
|
|
14049
|
+
window.juxwebGlobal.currentUser = res;
|
|
13993
14050
|
onTokenAcquired(token, onUserLogin);
|
|
13994
14051
|
};
|
|
13995
14052
|
const onError = (err) => {
|
|
@@ -14344,9 +14401,9 @@ var juxWeb = (function (exports) {
|
|
|
14344
14401
|
var _a, _b, _c, _d, _e;
|
|
14345
14402
|
const result = document.createElement('contact-us-modal');
|
|
14346
14403
|
// @ts-ignore
|
|
14347
|
-
const currentName = window.
|
|
14404
|
+
const currentName = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.name : '';
|
|
14348
14405
|
// @ts-ignore
|
|
14349
|
-
const currentEmail = window.
|
|
14406
|
+
const currentEmail = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
|
|
14350
14407
|
const modalBody = document.createElement('modal-body');
|
|
14351
14408
|
const form = document.createElement('form');
|
|
14352
14409
|
form.id = 'contact-form';
|
|
@@ -14366,7 +14423,7 @@ var juxWeb = (function (exports) {
|
|
|
14366
14423
|
const captcha = googleCaptcha();
|
|
14367
14424
|
if (subject !== 'email-not-sent') {
|
|
14368
14425
|
// @ts-ignore
|
|
14369
|
-
const admin = ((_d = (_c = window.
|
|
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;
|
|
14370
14427
|
backendGet('credits-balance-for', { admin }, (res) => {
|
|
14371
14428
|
const balance = res;
|
|
14372
14429
|
if (balance <= 0) {
|
|
@@ -14500,16 +14557,16 @@ var juxWeb = (function (exports) {
|
|
|
14500
14557
|
|
|
14501
14558
|
const setBackendToken = (token) => {
|
|
14502
14559
|
// @ts-ignore
|
|
14503
|
-
window.
|
|
14560
|
+
window.juxwebGlobal.backendToken = token;
|
|
14504
14561
|
if (token) {
|
|
14505
|
-
|
|
14562
|
+
setLocalStorageItem('token', token);
|
|
14506
14563
|
}
|
|
14507
14564
|
};
|
|
14508
14565
|
const getBackendToken = () => {
|
|
14509
14566
|
var _a;
|
|
14510
|
-
const token = (_a =
|
|
14567
|
+
const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
|
|
14511
14568
|
// @ts-ignore
|
|
14512
|
-
window.
|
|
14569
|
+
window.juxwebGlobal.backendToken = token;
|
|
14513
14570
|
return token;
|
|
14514
14571
|
};
|
|
14515
14572
|
const onTokenAcquired = (token, onUserLogin) => {
|
|
@@ -14517,19 +14574,13 @@ var juxWeb = (function (exports) {
|
|
|
14517
14574
|
// setSuperToken();
|
|
14518
14575
|
onUserLogin();
|
|
14519
14576
|
};
|
|
14520
|
-
const clearSession = (
|
|
14521
|
-
|
|
14522
|
-
// TODO: find a better way to preserve backend-url
|
|
14523
|
-
const backendUrl = getBackendUrl(); // Preserve backend, since the authentication was succcessfull
|
|
14524
|
-
const savedItems = itemsToSave === null || itemsToSave === void 0 ? void 0 : itemsToSave.map((item) => ({ key: item, value: localStorage.getItem(item) }));
|
|
14525
|
-
localStorage.clear();
|
|
14526
|
-
savedItems === null || savedItems === void 0 ? void 0 : savedItems.forEach((item) => localStorage.setItem(item.key, item.value));
|
|
14527
|
-
setBackendUrl(backendUrl);
|
|
14577
|
+
const clearSession = () => {
|
|
14578
|
+
removeLocalStorageItem('token');
|
|
14528
14579
|
// @ts-ignore
|
|
14529
|
-
window.
|
|
14580
|
+
window.juxwebGlobal = {};
|
|
14530
14581
|
};
|
|
14531
14582
|
const onAuthenticationFailure = (msg) => {
|
|
14532
|
-
|
|
14583
|
+
removeLocalStorageItem('token');
|
|
14533
14584
|
// displayPage(Page.LOGIN);
|
|
14534
14585
|
alert(getTranslation(msg));
|
|
14535
14586
|
};
|
|
@@ -14538,9 +14589,9 @@ var juxWeb = (function (exports) {
|
|
|
14538
14589
|
clearSession();
|
|
14539
14590
|
}
|
|
14540
14591
|
// @ts-ignore
|
|
14541
|
-
window.
|
|
14592
|
+
window.juxwebGlobal.currentUser = user;
|
|
14542
14593
|
if (type === 'Token Authentication') {
|
|
14543
|
-
user.token =
|
|
14594
|
+
user.token = getLocalStorageItem('token');
|
|
14544
14595
|
}
|
|
14545
14596
|
onTokenAcquired(user.token, onUserLogin);
|
|
14546
14597
|
// mixpanelIdentify(user);
|
|
@@ -14572,22 +14623,24 @@ var juxWeb = (function (exports) {
|
|
|
14572
14623
|
const onError = () => onAuthenticationFailure('login-failed');
|
|
14573
14624
|
getSSOAuthorizationEndpoint(onSuccess, onError);
|
|
14574
14625
|
};
|
|
14575
|
-
const initSession = (clientApp, supportedLoginTypes, onUserLogin, onLoginError, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint) => {
|
|
14626
|
+
const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint, urlPrefix }) => {
|
|
14576
14627
|
// if (startNewDemo()) {
|
|
14577
14628
|
// initDemo(setBackendToken, onAuthentication);
|
|
14578
14629
|
// return;
|
|
14579
14630
|
// }
|
|
14580
14631
|
// @ts-ignore
|
|
14581
|
-
if (!window.
|
|
14632
|
+
if (!window.juxwebGlobal) {
|
|
14582
14633
|
// @ts-ignore
|
|
14583
|
-
window.
|
|
14634
|
+
window.juxwebGlobal = {};
|
|
14584
14635
|
}
|
|
14585
14636
|
// @ts-ignore
|
|
14586
|
-
window.
|
|
14637
|
+
window.juxwebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
|
|
14587
14638
|
// @ts-ignore
|
|
14588
|
-
window.
|
|
14639
|
+
window.juxwebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
|
|
14589
14640
|
// @ts-ignore
|
|
14590
|
-
window.
|
|
14641
|
+
window.juxwebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
|
|
14642
|
+
if (urlPrefix)
|
|
14643
|
+
setUrlPrefix(urlPrefix);
|
|
14591
14644
|
const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
|
|
14592
14645
|
if (signInToken) {
|
|
14593
14646
|
const onOpenMagicLink = () => {
|
|
@@ -14596,7 +14649,7 @@ var juxWeb = (function (exports) {
|
|
|
14596
14649
|
const host = extractTokenFromWindowLocation('host');
|
|
14597
14650
|
if (host) {
|
|
14598
14651
|
// @ts-ignore
|
|
14599
|
-
window.
|
|
14652
|
+
window.juxwebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
14600
14653
|
setBackendUrl(backendUrl);
|
|
14601
14654
|
onOpenMagicLink();
|
|
14602
14655
|
});
|
|
@@ -14641,7 +14694,7 @@ var juxWeb = (function (exports) {
|
|
|
14641
14694
|
const onSuccess = (res) => {
|
|
14642
14695
|
const { token } = res;
|
|
14643
14696
|
// @ts-ignore
|
|
14644
|
-
window.
|
|
14697
|
+
window.juxwebGlobal.currentUser = res;
|
|
14645
14698
|
onTokenAcquired(token, onUserLogin);
|
|
14646
14699
|
disableSignInLayout();
|
|
14647
14700
|
};
|
|
@@ -14674,7 +14727,7 @@ var juxWeb = (function (exports) {
|
|
|
14674
14727
|
const onSuccess = (res) => {
|
|
14675
14728
|
const { token } = res;
|
|
14676
14729
|
// @ts-ignore
|
|
14677
|
-
window.
|
|
14730
|
+
window.juxwebGlobal.currentUser = res;
|
|
14678
14731
|
onTokenAcquired(token, onUserLogin);
|
|
14679
14732
|
disableSignInLayout();
|
|
14680
14733
|
};
|
|
@@ -14709,9 +14762,9 @@ var juxWeb = (function (exports) {
|
|
|
14709
14762
|
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
14710
14763
|
};
|
|
14711
14764
|
// @ts-ignore
|
|
14712
|
-
if (window.
|
|
14765
|
+
if (window.juxwebGlobal.fetchUserBackendUrl) {
|
|
14713
14766
|
// @ts-ignore
|
|
14714
|
-
window.
|
|
14767
|
+
window.juxwebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
14715
14768
|
setBackendUrl(backendUrl);
|
|
14716
14769
|
onRequestMagicLink();
|
|
14717
14770
|
});
|
|
@@ -14944,7 +14997,7 @@ var juxWeb = (function (exports) {
|
|
|
14944
14997
|
};
|
|
14945
14998
|
|
|
14946
14999
|
class JuxEvent extends Event {
|
|
14947
|
-
constructor(type, method, endpoint, onResult, params, onError, onRedirect) {
|
|
15000
|
+
constructor(type, method, endpoint, onResult, params, onError, onRedirect, extras) {
|
|
14948
15001
|
super('jux-event', { bubbles: true, cancelable: true, composed: true });
|
|
14949
15002
|
this.requestType = type;
|
|
14950
15003
|
this.method = method;
|
|
@@ -14953,6 +15006,7 @@ var juxWeb = (function (exports) {
|
|
|
14953
15006
|
this.params = params;
|
|
14954
15007
|
this.onError = onError;
|
|
14955
15008
|
this.onRedirect = onRedirect;
|
|
15009
|
+
this.extras = extras;
|
|
14956
15010
|
}
|
|
14957
15011
|
}
|
|
14958
15012
|
const query = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
@@ -14977,6 +15031,7 @@ var juxWeb = (function (exports) {
|
|
|
14977
15031
|
exports.query = query;
|
|
14978
15032
|
exports.reloadWithLanguageOverride = reloadWithLanguageOverride;
|
|
14979
15033
|
exports.requestMagicLink = requestMagicLink;
|
|
15034
|
+
exports.upload = upload;
|
|
14980
15035
|
|
|
14981
15036
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14982
15037
|
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const setUrlPrefix: (s: string) => string;
|
|
2
|
+
export declare const getLocalStorageItem: (k: string) => string | null;
|
|
3
|
+
export declare const setLocalStorageItem: (k: string, v: string) => void;
|
|
4
|
+
export declare const removeLocalStorageItem: (k: string) => void;
|
package/dist/login/session.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
export declare const setBackendToken: (token: string) => void;
|
|
2
2
|
export declare const onTokenAcquired: (token: string, onUserLogin: any) => void;
|
|
3
|
-
export declare const clearSession: (
|
|
4
|
-
|
|
3
|
+
export declare const clearSession: () => void;
|
|
4
|
+
interface InitSessionParams {
|
|
5
|
+
clientApp: HTMLElement;
|
|
6
|
+
supportedLoginTypes: string[];
|
|
7
|
+
onUserLogin: any;
|
|
8
|
+
onLoginError: any;
|
|
9
|
+
backgroundImage: string;
|
|
10
|
+
fetchUserBackendUrl: any;
|
|
11
|
+
magicLinkRequestEndpoint: string | null;
|
|
12
|
+
magicLinkAuthEndpoint: string | null;
|
|
13
|
+
urlPrefix: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const initSession: ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint, urlPrefix }: InitSessionParams) => void;
|
|
5
16
|
export declare const onMicrosoftSignIn: (onUserLogin: any) => Promise<void>;
|
|
6
17
|
export declare const onGoogleSignIn: (onUserLogin: any) => void;
|
|
7
18
|
export declare const onAuthPasswordLogin: (credentials: any, onUserLogin: any, onLoginError: any, onReturn: any, clientApp: HTMLElement, backgroundImg: string) => void;
|
|
8
19
|
export declare const handleMagicLinkRequest: (token: string | null, onReturn: any, backgroundImage: string, currentPage: HTMLElement, clientBody: HTMLElement, email?: string) => void;
|
|
20
|
+
export {};
|
package/dist/main.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ 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
8
|
declare global {
|
package/dist/main.esm.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import * as msal from '@azure/msal-browser';
|
|
2
2
|
|
|
3
|
+
let urlPrefix;
|
|
4
|
+
const setUrlPrefix = (s) => urlPrefix = s;
|
|
5
|
+
const getLocalStorageKey = (k) => urlPrefix ? `${urlPrefix}_${k}` : k;
|
|
6
|
+
const getLocalStorageItem = (k) => localStorage.getItem(getLocalStorageKey(k));
|
|
7
|
+
const setLocalStorageItem = (k, v) => localStorage.setItem(getLocalStorageKey(k), v);
|
|
8
|
+
const removeLocalStorageItem = (k) => localStorage.removeItem(getLocalStorageKey(k));
|
|
9
|
+
|
|
3
10
|
const getBrowserLanguage = () => {
|
|
4
11
|
const result = (navigator.languages && navigator.languages.length)
|
|
5
12
|
? navigator.languages[0]
|
|
@@ -8,9 +15,9 @@ const getBrowserLanguage = () => {
|
|
|
8
15
|
};
|
|
9
16
|
const OVERRIDE_KEY = 'jux.language.override';
|
|
10
17
|
let translations = {};
|
|
11
|
-
const chosenLanguage =
|
|
18
|
+
const chosenLanguage = getLocalStorageItem(OVERRIDE_KEY) || getBrowserLanguage();
|
|
12
19
|
const reloadWithLanguageOverride = (lang) => {
|
|
13
|
-
|
|
20
|
+
setLocalStorageItem(OVERRIDE_KEY, lang);
|
|
14
21
|
location.reload();
|
|
15
22
|
};
|
|
16
23
|
// @ts-ignore
|
|
@@ -147,22 +154,22 @@ const extractTokenFromWindowLocation = (tokenParam, additionalParam = '') => {
|
|
|
147
154
|
return token;
|
|
148
155
|
};
|
|
149
156
|
|
|
150
|
-
const setBackendUrl = (backendUrl) =>
|
|
157
|
+
const setBackendUrl = (backendUrl) => setLocalStorageItem('backend-url', backendUrl);
|
|
151
158
|
//@ts-ignore
|
|
152
|
-
const getBackendUrl = () => process.env.BACKEND_URL ||
|
|
159
|
+
const getBackendUrl = () => process.env.BACKEND_URL || getLocalStorageItem('backend-url');
|
|
153
160
|
//@ts-ignore
|
|
154
161
|
const getSecondaryBackendUrl = () => process.env.STAGING_BACKEND_URL || getBackendUrl();
|
|
155
162
|
const getApiUrl = () => getBackendUrl() + 'api/';
|
|
156
163
|
const getMagicAuthUrl = () => {
|
|
157
164
|
var _a;
|
|
158
165
|
// @ts-ignore
|
|
159
|
-
const endpoint = ((_a = window
|
|
166
|
+
const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
|
|
160
167
|
return getBackendUrl() + endpoint + '?token=';
|
|
161
168
|
};
|
|
162
169
|
const getMagicAuthReqUrl = () => {
|
|
163
170
|
var _a;
|
|
164
171
|
// @ts-ignore
|
|
165
|
-
const endpoint = ((_a = window
|
|
172
|
+
const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
|
|
166
173
|
return getBackendUrl() + endpoint + '?email=';
|
|
167
174
|
};
|
|
168
175
|
// TODO: use jux-events to call commands and queries inside jux-web library
|
|
@@ -194,7 +201,7 @@ const removeOverlay = () => {
|
|
|
194
201
|
(_b = document.querySelector('.reconnect-spinner')) === null || _b === void 0 ? void 0 : _b.remove();
|
|
195
202
|
};
|
|
196
203
|
const defaultHandleUnauthorized = () => {
|
|
197
|
-
|
|
204
|
+
removeLocalStorageItem('token');
|
|
198
205
|
alert(getTranslation('session-expired-msg'));
|
|
199
206
|
location.reload();
|
|
200
207
|
// googleAuthSignOut(); TODO
|
|
@@ -205,17 +212,65 @@ let timeout = 20000;
|
|
|
205
212
|
const slowRequestTimeout = 2000;
|
|
206
213
|
// @ts-ignore
|
|
207
214
|
window.setRequestTimeout = (newTimeout) => timeout = newTimeout;
|
|
208
|
-
const
|
|
215
|
+
const upload = (endpoint, file, onResult, onError, extras) => {
|
|
216
|
+
apiRequest(endpoint, {
|
|
217
|
+
file,
|
|
218
|
+
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); }
|
|
219
|
+
}, (text) => onResult === null || onResult === void 0 ? void 0 : onResult(text), (err) => onError === null || onError === void 0 ? void 0 : onError(err), undefined, // no redirect handler
|
|
220
|
+
'upload', // requestType
|
|
221
|
+
undefined, undefined, undefined, extras);
|
|
222
|
+
};
|
|
223
|
+
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) {
|
|
224
|
+
url = getApiUrl() + url;
|
|
225
|
+
backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, retrial, retrialNum, extras);
|
|
226
|
+
});
|
|
227
|
+
const uploadRequest = (url, file, onSuccess, onError, extras) => {
|
|
228
|
+
var _a, _b;
|
|
229
|
+
requestRunning = true;
|
|
230
|
+
const xhr = new XMLHttpRequest();
|
|
231
|
+
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
|
+
}
|
|
235
|
+
xhr.upload.onprogress = (e) => {
|
|
236
|
+
if (e.lengthComputable && (extras === null || extras === void 0 ? void 0 : extras.onProgress)) {
|
|
237
|
+
extras.onProgress(Math.round((e.loaded / e.total) * 100));
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
xhr.onload = () => {
|
|
241
|
+
requestRunning = false;
|
|
242
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
243
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(xhr.responseText);
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
onError === null || onError === void 0 ? void 0 : onError(xhr.responseText);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
xhr.onerror = () => {
|
|
250
|
+
requestRunning = false;
|
|
251
|
+
onError === null || onError === void 0 ? void 0 : onError('Error sending file. Please try again.');
|
|
252
|
+
};
|
|
253
|
+
xhr.send(file);
|
|
254
|
+
if (extras === null || extras === void 0 ? void 0 : extras.onStart) {
|
|
255
|
+
extras.onStart({
|
|
256
|
+
abortUpload: () => {
|
|
257
|
+
console.log('Aborting upload');
|
|
258
|
+
xhr.abort();
|
|
259
|
+
requestRunning = false;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
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) {
|
|
265
|
+
var _a;
|
|
209
266
|
if (requestRunning && !retrial) { // only allow one request at a time
|
|
210
|
-
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false), 300);
|
|
267
|
+
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false, retrialNum), 300);
|
|
211
268
|
return;
|
|
212
269
|
}
|
|
213
270
|
// @ts-ignore
|
|
214
|
-
const
|
|
215
|
-
if (backendToken) {
|
|
216
|
-
|
|
217
|
-
options.headers = {};
|
|
218
|
-
options.headers.auth = backendToken;
|
|
271
|
+
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);
|
|
219
274
|
}
|
|
220
275
|
let response;
|
|
221
276
|
requestRunning = true;
|
|
@@ -231,17 +286,19 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
|
|
|
231
286
|
const event = new CustomEvent('slow-request', { detail: requestUrl.pathname, bubbles: true });
|
|
232
287
|
window.dispatchEvent(event);
|
|
233
288
|
}, slowRequestTimeout);
|
|
234
|
-
const requestInit = Object.assign(Object.assign({}, options), { signal: controller.signal });
|
|
289
|
+
const requestInit = Object.assign(Object.assign({}, options), { headers, signal: controller.signal });
|
|
235
290
|
if (onRedirect)
|
|
236
291
|
requestInit.redirect = 'manual'; // Treat redirects manually instead of following them automatically.
|
|
292
|
+
if (requestType === 'upload') {
|
|
293
|
+
uploadRequest(url, options.file, onSuccess, onError, extras);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
237
296
|
try {
|
|
238
297
|
response = yield fetch(url, requestInit);
|
|
239
298
|
}
|
|
240
299
|
catch (err) {
|
|
241
|
-
// network errors
|
|
242
300
|
if (requestType === 'command') {
|
|
243
|
-
|
|
244
|
-
onError('There was an error performing your request. Please try again later.');
|
|
301
|
+
onError === null || onError === void 0 ? void 0 : onError('There was an error performing your request. Please try again later.');
|
|
245
302
|
requestRunning = false;
|
|
246
303
|
return;
|
|
247
304
|
}
|
|
@@ -290,20 +347,14 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
|
|
|
290
347
|
try {
|
|
291
348
|
const jsonResponse = yield response.json();
|
|
292
349
|
if (response.ok) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
return jsonResponse;
|
|
298
|
-
}
|
|
350
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(jsonResponse);
|
|
351
|
+
return;
|
|
299
352
|
}
|
|
300
353
|
else {
|
|
301
|
-
|
|
302
|
-
onError(jsonResponse);
|
|
354
|
+
onError === null || onError === void 0 ? void 0 : onError(jsonResponse);
|
|
303
355
|
}
|
|
304
356
|
}
|
|
305
357
|
catch (err) {
|
|
306
|
-
// json conversion error / json response dealing errors / onSuccess errors
|
|
307
358
|
console.error(err);
|
|
308
359
|
}
|
|
309
360
|
finally {
|
|
@@ -326,7 +377,7 @@ const post = (endpoint, params, onSuccess, onError, onRedirect, requestType = "q
|
|
|
326
377
|
// @ts-ignore
|
|
327
378
|
options.body = content;
|
|
328
379
|
}
|
|
329
|
-
return
|
|
380
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized);
|
|
330
381
|
};
|
|
331
382
|
const get = (endpoint, onSuccess, onError, onRedirect, handleUnauthorized) => {
|
|
332
383
|
const options = {
|
|
@@ -336,7 +387,7 @@ const get = (endpoint, onSuccess, onError, onRedirect, handleUnauthorized) => {
|
|
|
336
387
|
'Content-Type': 'application/json',
|
|
337
388
|
}
|
|
338
389
|
};
|
|
339
|
-
return
|
|
390
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, 'query', handleUnauthorized);
|
|
340
391
|
};
|
|
341
392
|
const backendPost = (endpoint, postContent, onJsonResponse, onHelpMessage, handleUnauthorized) => {
|
|
342
393
|
post(endpoint, postContent, onJsonResponse, onHelpMessage, null, 'command', handleUnauthorized);
|
|
@@ -354,9 +405,15 @@ const backendGet = (endpoint, params, onJsonResponse, onHelpMessage, handleUnaut
|
|
|
354
405
|
};
|
|
355
406
|
const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
|
|
356
407
|
const { email, token } = data;
|
|
357
|
-
const url = getMagicAuthReqUrl() +
|
|
408
|
+
const url = getMagicAuthReqUrl() +
|
|
409
|
+
encodeURIComponent(email) +
|
|
410
|
+
'&destination=' +
|
|
411
|
+
extractTokenFromWindowLocation('destination') +
|
|
412
|
+
'&token=' +
|
|
413
|
+
token;
|
|
358
414
|
const options = {};
|
|
359
|
-
backendRequest(url, options, onJsonResponse, console.error,
|
|
415
|
+
backendRequest(url, options, onJsonResponse, console.error, undefined, // ← use undefined instead of null
|
|
416
|
+
'query', onUnauthorized);
|
|
360
417
|
};
|
|
361
418
|
const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
|
|
362
419
|
backendRequest(getMagicAuthUrl() + magicToken, {}, onJsonResponse, onHelpMessage);
|
|
@@ -474,7 +531,7 @@ const onUserChanged = (googleUser, onUserLogin) => {
|
|
|
474
531
|
const onSuccess = (res) => {
|
|
475
532
|
const { token } = res;
|
|
476
533
|
// @ts-ignore
|
|
477
|
-
window.
|
|
534
|
+
window.juxwebGlobal.currentUser = res;
|
|
478
535
|
onTokenAcquired(token, onUserLogin);
|
|
479
536
|
};
|
|
480
537
|
const onError = (err) => {
|
|
@@ -829,9 +886,9 @@ const contactUsModal = (subject) => {
|
|
|
829
886
|
var _a, _b, _c, _d, _e;
|
|
830
887
|
const result = document.createElement('contact-us-modal');
|
|
831
888
|
// @ts-ignore
|
|
832
|
-
const currentName = window.
|
|
889
|
+
const currentName = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.name : '';
|
|
833
890
|
// @ts-ignore
|
|
834
|
-
const currentEmail = window.
|
|
891
|
+
const currentEmail = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
|
|
835
892
|
const modalBody = document.createElement('modal-body');
|
|
836
893
|
const form = document.createElement('form');
|
|
837
894
|
form.id = 'contact-form';
|
|
@@ -851,7 +908,7 @@ const contactUsModal = (subject) => {
|
|
|
851
908
|
const captcha = googleCaptcha();
|
|
852
909
|
if (subject !== 'email-not-sent') {
|
|
853
910
|
// @ts-ignore
|
|
854
|
-
const admin = ((_d = (_c = window.
|
|
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;
|
|
855
912
|
backendGet('credits-balance-for', { admin }, (res) => {
|
|
856
913
|
const balance = res;
|
|
857
914
|
if (balance <= 0) {
|
|
@@ -985,16 +1042,16 @@ const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn, failInfo) =>
|
|
|
985
1042
|
|
|
986
1043
|
const setBackendToken = (token) => {
|
|
987
1044
|
// @ts-ignore
|
|
988
|
-
window.
|
|
1045
|
+
window.juxwebGlobal.backendToken = token;
|
|
989
1046
|
if (token) {
|
|
990
|
-
|
|
1047
|
+
setLocalStorageItem('token', token);
|
|
991
1048
|
}
|
|
992
1049
|
};
|
|
993
1050
|
const getBackendToken = () => {
|
|
994
1051
|
var _a;
|
|
995
|
-
const token = (_a =
|
|
1052
|
+
const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
|
|
996
1053
|
// @ts-ignore
|
|
997
|
-
window.
|
|
1054
|
+
window.juxwebGlobal.backendToken = token;
|
|
998
1055
|
return token;
|
|
999
1056
|
};
|
|
1000
1057
|
const onTokenAcquired = (token, onUserLogin) => {
|
|
@@ -1002,19 +1059,13 @@ const onTokenAcquired = (token, onUserLogin) => {
|
|
|
1002
1059
|
// setSuperToken();
|
|
1003
1060
|
onUserLogin();
|
|
1004
1061
|
};
|
|
1005
|
-
const clearSession = (
|
|
1006
|
-
|
|
1007
|
-
// TODO: find a better way to preserve backend-url
|
|
1008
|
-
const backendUrl = getBackendUrl(); // Preserve backend, since the authentication was succcessfull
|
|
1009
|
-
const savedItems = itemsToSave === null || itemsToSave === void 0 ? void 0 : itemsToSave.map((item) => ({ key: item, value: localStorage.getItem(item) }));
|
|
1010
|
-
localStorage.clear();
|
|
1011
|
-
savedItems === null || savedItems === void 0 ? void 0 : savedItems.forEach((item) => localStorage.setItem(item.key, item.value));
|
|
1012
|
-
setBackendUrl(backendUrl);
|
|
1062
|
+
const clearSession = () => {
|
|
1063
|
+
removeLocalStorageItem('token');
|
|
1013
1064
|
// @ts-ignore
|
|
1014
|
-
window.
|
|
1065
|
+
window.juxwebGlobal = {};
|
|
1015
1066
|
};
|
|
1016
1067
|
const onAuthenticationFailure = (msg) => {
|
|
1017
|
-
|
|
1068
|
+
removeLocalStorageItem('token');
|
|
1018
1069
|
// displayPage(Page.LOGIN);
|
|
1019
1070
|
alert(getTranslation(msg));
|
|
1020
1071
|
};
|
|
@@ -1023,9 +1074,9 @@ const onAuthentication = (onUserLogin, user, type) => {
|
|
|
1023
1074
|
clearSession();
|
|
1024
1075
|
}
|
|
1025
1076
|
// @ts-ignore
|
|
1026
|
-
window.
|
|
1077
|
+
window.juxwebGlobal.currentUser = user;
|
|
1027
1078
|
if (type === 'Token Authentication') {
|
|
1028
|
-
user.token =
|
|
1079
|
+
user.token = getLocalStorageItem('token');
|
|
1029
1080
|
}
|
|
1030
1081
|
onTokenAcquired(user.token, onUserLogin);
|
|
1031
1082
|
// mixpanelIdentify(user);
|
|
@@ -1057,22 +1108,24 @@ const handleSSOLogin = () => {
|
|
|
1057
1108
|
const onError = () => onAuthenticationFailure('login-failed');
|
|
1058
1109
|
getSSOAuthorizationEndpoint(onSuccess, onError);
|
|
1059
1110
|
};
|
|
1060
|
-
const initSession = (clientApp, supportedLoginTypes, onUserLogin, onLoginError, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint) => {
|
|
1111
|
+
const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint, urlPrefix }) => {
|
|
1061
1112
|
// if (startNewDemo()) {
|
|
1062
1113
|
// initDemo(setBackendToken, onAuthentication);
|
|
1063
1114
|
// return;
|
|
1064
1115
|
// }
|
|
1065
1116
|
// @ts-ignore
|
|
1066
|
-
if (!window.
|
|
1117
|
+
if (!window.juxwebGlobal) {
|
|
1067
1118
|
// @ts-ignore
|
|
1068
|
-
window.
|
|
1119
|
+
window.juxwebGlobal = {};
|
|
1069
1120
|
}
|
|
1070
1121
|
// @ts-ignore
|
|
1071
|
-
window.
|
|
1122
|
+
window.juxwebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
|
|
1072
1123
|
// @ts-ignore
|
|
1073
|
-
window.
|
|
1124
|
+
window.juxwebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
|
|
1074
1125
|
// @ts-ignore
|
|
1075
|
-
window.
|
|
1126
|
+
window.juxwebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
|
|
1127
|
+
if (urlPrefix)
|
|
1128
|
+
setUrlPrefix(urlPrefix);
|
|
1076
1129
|
const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
|
|
1077
1130
|
if (signInToken) {
|
|
1078
1131
|
const onOpenMagicLink = () => {
|
|
@@ -1081,7 +1134,7 @@ const initSession = (clientApp, supportedLoginTypes, onUserLogin, onLoginError,
|
|
|
1081
1134
|
const host = extractTokenFromWindowLocation('host');
|
|
1082
1135
|
if (host) {
|
|
1083
1136
|
// @ts-ignore
|
|
1084
|
-
window.
|
|
1137
|
+
window.juxwebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
1085
1138
|
setBackendUrl(backendUrl);
|
|
1086
1139
|
onOpenMagicLink();
|
|
1087
1140
|
});
|
|
@@ -1126,7 +1179,7 @@ const onMicrosoftSignIn = (onUserLogin) => __awaiter(void 0, void 0, void 0, fun
|
|
|
1126
1179
|
const onSuccess = (res) => {
|
|
1127
1180
|
const { token } = res;
|
|
1128
1181
|
// @ts-ignore
|
|
1129
|
-
window.
|
|
1182
|
+
window.juxwebGlobal.currentUser = res;
|
|
1130
1183
|
onTokenAcquired(token, onUserLogin);
|
|
1131
1184
|
disableSignInLayout();
|
|
1132
1185
|
};
|
|
@@ -1159,7 +1212,7 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
|
|
|
1159
1212
|
const onSuccess = (res) => {
|
|
1160
1213
|
const { token } = res;
|
|
1161
1214
|
// @ts-ignore
|
|
1162
|
-
window.
|
|
1215
|
+
window.juxwebGlobal.currentUser = res;
|
|
1163
1216
|
onTokenAcquired(token, onUserLogin);
|
|
1164
1217
|
disableSignInLayout();
|
|
1165
1218
|
};
|
|
@@ -1194,9 +1247,9 @@ const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, c
|
|
|
1194
1247
|
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
1195
1248
|
};
|
|
1196
1249
|
// @ts-ignore
|
|
1197
|
-
if (window.
|
|
1250
|
+
if (window.juxwebGlobal.fetchUserBackendUrl) {
|
|
1198
1251
|
// @ts-ignore
|
|
1199
|
-
window.
|
|
1252
|
+
window.juxwebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
1200
1253
|
setBackendUrl(backendUrl);
|
|
1201
1254
|
onRequestMagicLink();
|
|
1202
1255
|
});
|
|
@@ -1429,7 +1482,7 @@ const loginPage = (clientApp, backgroundImg, onUserLogin, onLoginError, loginTyp
|
|
|
1429
1482
|
};
|
|
1430
1483
|
|
|
1431
1484
|
class JuxEvent extends Event {
|
|
1432
|
-
constructor(type, method, endpoint, onResult, params, onError, onRedirect) {
|
|
1485
|
+
constructor(type, method, endpoint, onResult, params, onError, onRedirect, extras) {
|
|
1433
1486
|
super('jux-event', { bubbles: true, cancelable: true, composed: true });
|
|
1434
1487
|
this.requestType = type;
|
|
1435
1488
|
this.method = method;
|
|
@@ -1438,6 +1491,7 @@ class JuxEvent extends Event {
|
|
|
1438
1491
|
this.params = params;
|
|
1439
1492
|
this.onError = onError;
|
|
1440
1493
|
this.onRedirect = onRedirect;
|
|
1494
|
+
this.extras = extras;
|
|
1441
1495
|
}
|
|
1442
1496
|
}
|
|
1443
1497
|
const query = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
@@ -1447,4 +1501,4 @@ const command = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
|
1447
1501
|
element.dispatchEvent(new JuxEvent('command', 'POST', endpoint, onResult, params, onError, onRedirect));
|
|
1448
1502
|
};
|
|
1449
1503
|
|
|
1450
|
-
export { chosenLanguage, clearSession, command, getTranslation, handleJuxEvent, handleMagicLinkRequest, initLanguage, initSession, loginButton, loginPage, magicLinkModal, onMicrosoftSignIn, query, reloadWithLanguageOverride, requestMagicLink };
|
|
1504
|
+
export { chosenLanguage, clearSession, command, getTranslation, handleJuxEvent, handleMagicLinkRequest, initLanguage, initSession, loginButton, loginPage, magicLinkModal, onMicrosoftSignIn, query, reloadWithLanguageOverride, requestMagicLink, upload };
|
package/dist/main.js
CHANGED
|
@@ -24,6 +24,13 @@ function _interopNamespace(e) {
|
|
|
24
24
|
|
|
25
25
|
var msal__namespace = /*#__PURE__*/_interopNamespace(msal);
|
|
26
26
|
|
|
27
|
+
let urlPrefix;
|
|
28
|
+
const setUrlPrefix = (s) => urlPrefix = s;
|
|
29
|
+
const getLocalStorageKey = (k) => urlPrefix ? `${urlPrefix}_${k}` : k;
|
|
30
|
+
const getLocalStorageItem = (k) => localStorage.getItem(getLocalStorageKey(k));
|
|
31
|
+
const setLocalStorageItem = (k, v) => localStorage.setItem(getLocalStorageKey(k), v);
|
|
32
|
+
const removeLocalStorageItem = (k) => localStorage.removeItem(getLocalStorageKey(k));
|
|
33
|
+
|
|
27
34
|
const getBrowserLanguage = () => {
|
|
28
35
|
const result = (navigator.languages && navigator.languages.length)
|
|
29
36
|
? navigator.languages[0]
|
|
@@ -32,9 +39,9 @@ const getBrowserLanguage = () => {
|
|
|
32
39
|
};
|
|
33
40
|
const OVERRIDE_KEY = 'jux.language.override';
|
|
34
41
|
let translations = {};
|
|
35
|
-
const chosenLanguage =
|
|
42
|
+
const chosenLanguage = getLocalStorageItem(OVERRIDE_KEY) || getBrowserLanguage();
|
|
36
43
|
const reloadWithLanguageOverride = (lang) => {
|
|
37
|
-
|
|
44
|
+
setLocalStorageItem(OVERRIDE_KEY, lang);
|
|
38
45
|
location.reload();
|
|
39
46
|
};
|
|
40
47
|
// @ts-ignore
|
|
@@ -171,22 +178,22 @@ const extractTokenFromWindowLocation = (tokenParam, additionalParam = '') => {
|
|
|
171
178
|
return token;
|
|
172
179
|
};
|
|
173
180
|
|
|
174
|
-
const setBackendUrl = (backendUrl) =>
|
|
181
|
+
const setBackendUrl = (backendUrl) => setLocalStorageItem('backend-url', backendUrl);
|
|
175
182
|
//@ts-ignore
|
|
176
|
-
const getBackendUrl = () => process.env.BACKEND_URL ||
|
|
183
|
+
const getBackendUrl = () => process.env.BACKEND_URL || getLocalStorageItem('backend-url');
|
|
177
184
|
//@ts-ignore
|
|
178
185
|
const getSecondaryBackendUrl = () => process.env.STAGING_BACKEND_URL || getBackendUrl();
|
|
179
186
|
const getApiUrl = () => getBackendUrl() + 'api/';
|
|
180
187
|
const getMagicAuthUrl = () => {
|
|
181
188
|
var _a;
|
|
182
189
|
// @ts-ignore
|
|
183
|
-
const endpoint = ((_a = window
|
|
190
|
+
const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
|
|
184
191
|
return getBackendUrl() + endpoint + '?token=';
|
|
185
192
|
};
|
|
186
193
|
const getMagicAuthReqUrl = () => {
|
|
187
194
|
var _a;
|
|
188
195
|
// @ts-ignore
|
|
189
|
-
const endpoint = ((_a = window
|
|
196
|
+
const endpoint = ((_a = window.juxwebGlobal) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
|
|
190
197
|
return getBackendUrl() + endpoint + '?email=';
|
|
191
198
|
};
|
|
192
199
|
// TODO: use jux-events to call commands and queries inside jux-web library
|
|
@@ -218,7 +225,7 @@ const removeOverlay = () => {
|
|
|
218
225
|
(_b = document.querySelector('.reconnect-spinner')) === null || _b === void 0 ? void 0 : _b.remove();
|
|
219
226
|
};
|
|
220
227
|
const defaultHandleUnauthorized = () => {
|
|
221
|
-
|
|
228
|
+
removeLocalStorageItem('token');
|
|
222
229
|
alert(getTranslation('session-expired-msg'));
|
|
223
230
|
location.reload();
|
|
224
231
|
// googleAuthSignOut(); TODO
|
|
@@ -229,17 +236,65 @@ let timeout = 20000;
|
|
|
229
236
|
const slowRequestTimeout = 2000;
|
|
230
237
|
// @ts-ignore
|
|
231
238
|
window.setRequestTimeout = (newTimeout) => timeout = newTimeout;
|
|
232
|
-
const
|
|
239
|
+
const upload = (endpoint, file, onResult, onError, extras) => {
|
|
240
|
+
apiRequest(endpoint, {
|
|
241
|
+
file,
|
|
242
|
+
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); }
|
|
243
|
+
}, (text) => onResult === null || onResult === void 0 ? void 0 : onResult(text), (err) => onError === null || onError === void 0 ? void 0 : onError(err), undefined, // no redirect handler
|
|
244
|
+
'upload', // requestType
|
|
245
|
+
undefined, undefined, undefined, extras);
|
|
246
|
+
};
|
|
247
|
+
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) {
|
|
248
|
+
url = getApiUrl() + url;
|
|
249
|
+
backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, retrial, retrialNum, extras);
|
|
250
|
+
});
|
|
251
|
+
const uploadRequest = (url, file, onSuccess, onError, extras) => {
|
|
252
|
+
var _a, _b;
|
|
253
|
+
requestRunning = true;
|
|
254
|
+
const xhr = new XMLHttpRequest();
|
|
255
|
+
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
|
+
}
|
|
259
|
+
xhr.upload.onprogress = (e) => {
|
|
260
|
+
if (e.lengthComputable && (extras === null || extras === void 0 ? void 0 : extras.onProgress)) {
|
|
261
|
+
extras.onProgress(Math.round((e.loaded / e.total) * 100));
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
xhr.onload = () => {
|
|
265
|
+
requestRunning = false;
|
|
266
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
267
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(xhr.responseText);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
onError === null || onError === void 0 ? void 0 : onError(xhr.responseText);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
xhr.onerror = () => {
|
|
274
|
+
requestRunning = false;
|
|
275
|
+
onError === null || onError === void 0 ? void 0 : onError('Error sending file. Please try again.');
|
|
276
|
+
};
|
|
277
|
+
xhr.send(file);
|
|
278
|
+
if (extras === null || extras === void 0 ? void 0 : extras.onStart) {
|
|
279
|
+
extras.onStart({
|
|
280
|
+
abortUpload: () => {
|
|
281
|
+
console.log('Aborting upload');
|
|
282
|
+
xhr.abort();
|
|
283
|
+
requestRunning = false;
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
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) {
|
|
289
|
+
var _a;
|
|
233
290
|
if (requestRunning && !retrial) { // only allow one request at a time
|
|
234
|
-
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false), 300);
|
|
291
|
+
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false, retrialNum), 300);
|
|
235
292
|
return;
|
|
236
293
|
}
|
|
237
294
|
// @ts-ignore
|
|
238
|
-
const
|
|
239
|
-
if (backendToken) {
|
|
240
|
-
|
|
241
|
-
options.headers = {};
|
|
242
|
-
options.headers.auth = backendToken;
|
|
295
|
+
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);
|
|
243
298
|
}
|
|
244
299
|
let response;
|
|
245
300
|
requestRunning = true;
|
|
@@ -255,17 +310,19 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
|
|
|
255
310
|
const event = new CustomEvent('slow-request', { detail: requestUrl.pathname, bubbles: true });
|
|
256
311
|
window.dispatchEvent(event);
|
|
257
312
|
}, slowRequestTimeout);
|
|
258
|
-
const requestInit = Object.assign(Object.assign({}, options), { signal: controller.signal });
|
|
313
|
+
const requestInit = Object.assign(Object.assign({}, options), { headers, signal: controller.signal });
|
|
259
314
|
if (onRedirect)
|
|
260
315
|
requestInit.redirect = 'manual'; // Treat redirects manually instead of following them automatically.
|
|
316
|
+
if (requestType === 'upload') {
|
|
317
|
+
uploadRequest(url, options.file, onSuccess, onError, extras);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
261
320
|
try {
|
|
262
321
|
response = yield fetch(url, requestInit);
|
|
263
322
|
}
|
|
264
323
|
catch (err) {
|
|
265
|
-
// network errors
|
|
266
324
|
if (requestType === 'command') {
|
|
267
|
-
|
|
268
|
-
onError('There was an error performing your request. Please try again later.');
|
|
325
|
+
onError === null || onError === void 0 ? void 0 : onError('There was an error performing your request. Please try again later.');
|
|
269
326
|
requestRunning = false;
|
|
270
327
|
return;
|
|
271
328
|
}
|
|
@@ -314,20 +371,14 @@ const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1,
|
|
|
314
371
|
try {
|
|
315
372
|
const jsonResponse = yield response.json();
|
|
316
373
|
if (response.ok) {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
return jsonResponse;
|
|
322
|
-
}
|
|
374
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(jsonResponse);
|
|
375
|
+
return;
|
|
323
376
|
}
|
|
324
377
|
else {
|
|
325
|
-
|
|
326
|
-
onError(jsonResponse);
|
|
378
|
+
onError === null || onError === void 0 ? void 0 : onError(jsonResponse);
|
|
327
379
|
}
|
|
328
380
|
}
|
|
329
381
|
catch (err) {
|
|
330
|
-
// json conversion error / json response dealing errors / onSuccess errors
|
|
331
382
|
console.error(err);
|
|
332
383
|
}
|
|
333
384
|
finally {
|
|
@@ -350,7 +401,7 @@ const post = (endpoint, params, onSuccess, onError, onRedirect, requestType = "q
|
|
|
350
401
|
// @ts-ignore
|
|
351
402
|
options.body = content;
|
|
352
403
|
}
|
|
353
|
-
return
|
|
404
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized);
|
|
354
405
|
};
|
|
355
406
|
const get = (endpoint, onSuccess, onError, onRedirect, handleUnauthorized) => {
|
|
356
407
|
const options = {
|
|
@@ -360,7 +411,7 @@ const get = (endpoint, onSuccess, onError, onRedirect, handleUnauthorized) => {
|
|
|
360
411
|
'Content-Type': 'application/json',
|
|
361
412
|
}
|
|
362
413
|
};
|
|
363
|
-
return
|
|
414
|
+
return apiRequest(endpoint, options, onSuccess, onError, onRedirect, 'query', handleUnauthorized);
|
|
364
415
|
};
|
|
365
416
|
const backendPost = (endpoint, postContent, onJsonResponse, onHelpMessage, handleUnauthorized) => {
|
|
366
417
|
post(endpoint, postContent, onJsonResponse, onHelpMessage, null, 'command', handleUnauthorized);
|
|
@@ -378,9 +429,15 @@ const backendGet = (endpoint, params, onJsonResponse, onHelpMessage, handleUnaut
|
|
|
378
429
|
};
|
|
379
430
|
const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
|
|
380
431
|
const { email, token } = data;
|
|
381
|
-
const url = getMagicAuthReqUrl() +
|
|
432
|
+
const url = getMagicAuthReqUrl() +
|
|
433
|
+
encodeURIComponent(email) +
|
|
434
|
+
'&destination=' +
|
|
435
|
+
extractTokenFromWindowLocation('destination') +
|
|
436
|
+
'&token=' +
|
|
437
|
+
token;
|
|
382
438
|
const options = {};
|
|
383
|
-
backendRequest(url, options, onJsonResponse, console.error,
|
|
439
|
+
backendRequest(url, options, onJsonResponse, console.error, undefined, // ← use undefined instead of null
|
|
440
|
+
'query', onUnauthorized);
|
|
384
441
|
};
|
|
385
442
|
const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
|
|
386
443
|
backendRequest(getMagicAuthUrl() + magicToken, {}, onJsonResponse, onHelpMessage);
|
|
@@ -498,7 +555,7 @@ const onUserChanged = (googleUser, onUserLogin) => {
|
|
|
498
555
|
const onSuccess = (res) => {
|
|
499
556
|
const { token } = res;
|
|
500
557
|
// @ts-ignore
|
|
501
|
-
window.
|
|
558
|
+
window.juxwebGlobal.currentUser = res;
|
|
502
559
|
onTokenAcquired(token, onUserLogin);
|
|
503
560
|
};
|
|
504
561
|
const onError = (err) => {
|
|
@@ -853,9 +910,9 @@ const contactUsModal = (subject) => {
|
|
|
853
910
|
var _a, _b, _c, _d, _e;
|
|
854
911
|
const result = document.createElement('contact-us-modal');
|
|
855
912
|
// @ts-ignore
|
|
856
|
-
const currentName = window.
|
|
913
|
+
const currentName = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.name : '';
|
|
857
914
|
// @ts-ignore
|
|
858
|
-
const currentEmail = window.
|
|
915
|
+
const currentEmail = window.juxwebGlobal.currentUser ? window.juxwebGlobal.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
|
|
859
916
|
const modalBody = document.createElement('modal-body');
|
|
860
917
|
const form = document.createElement('form');
|
|
861
918
|
form.id = 'contact-form';
|
|
@@ -875,7 +932,7 @@ const contactUsModal = (subject) => {
|
|
|
875
932
|
const captcha = googleCaptcha();
|
|
876
933
|
if (subject !== 'email-not-sent') {
|
|
877
934
|
// @ts-ignore
|
|
878
|
-
const admin = ((_d = (_c = window.
|
|
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;
|
|
879
936
|
backendGet('credits-balance-for', { admin }, (res) => {
|
|
880
937
|
const balance = res;
|
|
881
938
|
if (balance <= 0) {
|
|
@@ -1009,16 +1066,16 @@ const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn, failInfo) =>
|
|
|
1009
1066
|
|
|
1010
1067
|
const setBackendToken = (token) => {
|
|
1011
1068
|
// @ts-ignore
|
|
1012
|
-
window.
|
|
1069
|
+
window.juxwebGlobal.backendToken = token;
|
|
1013
1070
|
if (token) {
|
|
1014
|
-
|
|
1071
|
+
setLocalStorageItem('token', token);
|
|
1015
1072
|
}
|
|
1016
1073
|
};
|
|
1017
1074
|
const getBackendToken = () => {
|
|
1018
1075
|
var _a;
|
|
1019
|
-
const token = (_a =
|
|
1076
|
+
const token = (_a = getLocalStorageItem('token')) !== null && _a !== void 0 ? _a : '';
|
|
1020
1077
|
// @ts-ignore
|
|
1021
|
-
window.
|
|
1078
|
+
window.juxwebGlobal.backendToken = token;
|
|
1022
1079
|
return token;
|
|
1023
1080
|
};
|
|
1024
1081
|
const onTokenAcquired = (token, onUserLogin) => {
|
|
@@ -1026,19 +1083,13 @@ const onTokenAcquired = (token, onUserLogin) => {
|
|
|
1026
1083
|
// setSuperToken();
|
|
1027
1084
|
onUserLogin();
|
|
1028
1085
|
};
|
|
1029
|
-
const clearSession = (
|
|
1030
|
-
|
|
1031
|
-
// TODO: find a better way to preserve backend-url
|
|
1032
|
-
const backendUrl = getBackendUrl(); // Preserve backend, since the authentication was succcessfull
|
|
1033
|
-
const savedItems = itemsToSave === null || itemsToSave === void 0 ? void 0 : itemsToSave.map((item) => ({ key: item, value: localStorage.getItem(item) }));
|
|
1034
|
-
localStorage.clear();
|
|
1035
|
-
savedItems === null || savedItems === void 0 ? void 0 : savedItems.forEach((item) => localStorage.setItem(item.key, item.value));
|
|
1036
|
-
setBackendUrl(backendUrl);
|
|
1086
|
+
const clearSession = () => {
|
|
1087
|
+
removeLocalStorageItem('token');
|
|
1037
1088
|
// @ts-ignore
|
|
1038
|
-
window.
|
|
1089
|
+
window.juxwebGlobal = {};
|
|
1039
1090
|
};
|
|
1040
1091
|
const onAuthenticationFailure = (msg) => {
|
|
1041
|
-
|
|
1092
|
+
removeLocalStorageItem('token');
|
|
1042
1093
|
// displayPage(Page.LOGIN);
|
|
1043
1094
|
alert(getTranslation(msg));
|
|
1044
1095
|
};
|
|
@@ -1047,9 +1098,9 @@ const onAuthentication = (onUserLogin, user, type) => {
|
|
|
1047
1098
|
clearSession();
|
|
1048
1099
|
}
|
|
1049
1100
|
// @ts-ignore
|
|
1050
|
-
window.
|
|
1101
|
+
window.juxwebGlobal.currentUser = user;
|
|
1051
1102
|
if (type === 'Token Authentication') {
|
|
1052
|
-
user.token =
|
|
1103
|
+
user.token = getLocalStorageItem('token');
|
|
1053
1104
|
}
|
|
1054
1105
|
onTokenAcquired(user.token, onUserLogin);
|
|
1055
1106
|
// mixpanelIdentify(user);
|
|
@@ -1081,22 +1132,24 @@ const handleSSOLogin = () => {
|
|
|
1081
1132
|
const onError = () => onAuthenticationFailure('login-failed');
|
|
1082
1133
|
getSSOAuthorizationEndpoint(onSuccess, onError);
|
|
1083
1134
|
};
|
|
1084
|
-
const initSession = (clientApp, supportedLoginTypes, onUserLogin, onLoginError, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint) => {
|
|
1135
|
+
const initSession = ({ clientApp, supportedLoginTypes, onUserLogin, onLoginError, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint, urlPrefix }) => {
|
|
1085
1136
|
// if (startNewDemo()) {
|
|
1086
1137
|
// initDemo(setBackendToken, onAuthentication);
|
|
1087
1138
|
// return;
|
|
1088
1139
|
// }
|
|
1089
1140
|
// @ts-ignore
|
|
1090
|
-
if (!window.
|
|
1141
|
+
if (!window.juxwebGlobal) {
|
|
1091
1142
|
// @ts-ignore
|
|
1092
|
-
window.
|
|
1143
|
+
window.juxwebGlobal = {};
|
|
1093
1144
|
}
|
|
1094
1145
|
// @ts-ignore
|
|
1095
|
-
window.
|
|
1146
|
+
window.juxwebGlobal.fetchUserBackendUrl = fetchUserBackendUrl;
|
|
1096
1147
|
// @ts-ignore
|
|
1097
|
-
window.
|
|
1148
|
+
window.juxwebGlobal.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
|
|
1098
1149
|
// @ts-ignore
|
|
1099
|
-
window.
|
|
1150
|
+
window.juxwebGlobal.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
|
|
1151
|
+
if (urlPrefix)
|
|
1152
|
+
setUrlPrefix(urlPrefix);
|
|
1100
1153
|
const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
|
|
1101
1154
|
if (signInToken) {
|
|
1102
1155
|
const onOpenMagicLink = () => {
|
|
@@ -1105,7 +1158,7 @@ const initSession = (clientApp, supportedLoginTypes, onUserLogin, onLoginError,
|
|
|
1105
1158
|
const host = extractTokenFromWindowLocation('host');
|
|
1106
1159
|
if (host) {
|
|
1107
1160
|
// @ts-ignore
|
|
1108
|
-
window.
|
|
1161
|
+
window.juxwebGlobal.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
1109
1162
|
setBackendUrl(backendUrl);
|
|
1110
1163
|
onOpenMagicLink();
|
|
1111
1164
|
});
|
|
@@ -1150,7 +1203,7 @@ const onMicrosoftSignIn = (onUserLogin) => __awaiter(void 0, void 0, void 0, fun
|
|
|
1150
1203
|
const onSuccess = (res) => {
|
|
1151
1204
|
const { token } = res;
|
|
1152
1205
|
// @ts-ignore
|
|
1153
|
-
window.
|
|
1206
|
+
window.juxwebGlobal.currentUser = res;
|
|
1154
1207
|
onTokenAcquired(token, onUserLogin);
|
|
1155
1208
|
disableSignInLayout();
|
|
1156
1209
|
};
|
|
@@ -1183,7 +1236,7 @@ const onAuthPasswordLogin = (credentials, onUserLogin, onLoginError, onReturn, c
|
|
|
1183
1236
|
const onSuccess = (res) => {
|
|
1184
1237
|
const { token } = res;
|
|
1185
1238
|
// @ts-ignore
|
|
1186
|
-
window.
|
|
1239
|
+
window.juxwebGlobal.currentUser = res;
|
|
1187
1240
|
onTokenAcquired(token, onUserLogin);
|
|
1188
1241
|
disableSignInLayout();
|
|
1189
1242
|
};
|
|
@@ -1218,9 +1271,9 @@ const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, c
|
|
|
1218
1271
|
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
1219
1272
|
};
|
|
1220
1273
|
// @ts-ignore
|
|
1221
|
-
if (window.
|
|
1274
|
+
if (window.juxwebGlobal.fetchUserBackendUrl) {
|
|
1222
1275
|
// @ts-ignore
|
|
1223
|
-
window.
|
|
1276
|
+
window.juxwebGlobal.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
1224
1277
|
setBackendUrl(backendUrl);
|
|
1225
1278
|
onRequestMagicLink();
|
|
1226
1279
|
});
|
|
@@ -1453,7 +1506,7 @@ const loginPage = (clientApp, backgroundImg, onUserLogin, onLoginError, loginTyp
|
|
|
1453
1506
|
};
|
|
1454
1507
|
|
|
1455
1508
|
class JuxEvent extends Event {
|
|
1456
|
-
constructor(type, method, endpoint, onResult, params, onError, onRedirect) {
|
|
1509
|
+
constructor(type, method, endpoint, onResult, params, onError, onRedirect, extras) {
|
|
1457
1510
|
super('jux-event', { bubbles: true, cancelable: true, composed: true });
|
|
1458
1511
|
this.requestType = type;
|
|
1459
1512
|
this.method = method;
|
|
@@ -1462,6 +1515,7 @@ class JuxEvent extends Event {
|
|
|
1462
1515
|
this.params = params;
|
|
1463
1516
|
this.onError = onError;
|
|
1464
1517
|
this.onRedirect = onRedirect;
|
|
1518
|
+
this.extras = extras;
|
|
1465
1519
|
}
|
|
1466
1520
|
}
|
|
1467
1521
|
const query = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
@@ -1486,3 +1540,4 @@ exports.onMicrosoftSignIn = onMicrosoftSignIn;
|
|
|
1486
1540
|
exports.query = query;
|
|
1487
1541
|
exports.reloadWithLanguageOverride = reloadWithLanguageOverride;
|
|
1488
1542
|
exports.requestMagicLink = requestMagicLink;
|
|
1543
|
+
exports.upload = upload;
|