@klauswuestefeld/jux-web 2024.2.6 → 2024.2.7

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/main.esm.js CHANGED
@@ -1,36 +1,35 @@
1
1
  import * as msal from '@azure/msal-browser';
2
2
 
3
- var getBrowserLanguage = function () {
4
- var result = (navigator.languages && navigator.languages.length)
3
+ const getBrowserLanguage = () => {
4
+ const result = (navigator.languages && navigator.languages.length)
5
5
  ? navigator.languages[0]
6
6
  : navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en';
7
7
  return result.substring(0, 2);
8
8
  };
9
- var OVERRIDE_KEY = 'jux.language.override';
10
- var translations = {};
11
- var chosenLanguage = localStorage.getItem(OVERRIDE_KEY) || getBrowserLanguage();
12
- var reloadWithLanguageOverride = function (lang) {
9
+ const OVERRIDE_KEY = 'jux.language.override';
10
+ let translations = {};
11
+ const chosenLanguage = localStorage.getItem(OVERRIDE_KEY) || getBrowserLanguage();
12
+ const reloadWithLanguageOverride = (lang) => {
13
13
  localStorage.setItem(OVERRIDE_KEY, lang);
14
14
  location.reload();
15
15
  };
16
16
  // @ts-ignore
17
- var getTranslation = function (k) { return translations[k] || k; };
18
- var initLanguage = function (translations_, defaultLanguage) {
19
- if (defaultLanguage === void 0) { defaultLanguage = 'en'; }
17
+ const getTranslation = (k) => translations[k] || k;
18
+ const initLanguage = (translations_, defaultLanguage = 'en') => {
20
19
  translations = translations_[chosenLanguage] || translations_[defaultLanguage];
21
20
  document.title = getTranslation('title');
22
21
  document.documentElement.lang = translations_[chosenLanguage] ? chosenLanguage : defaultLanguage;
23
22
  };
24
23
 
25
- var THRESHOLD_WIDTH = 640;
24
+ const THRESHOLD_WIDTH = 640;
26
25
 
27
- var icons = {
26
+ const icons = {
28
27
  email: '<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 64.000000 48.000000" preserveAspectRatio="xMidYMid meet"> <g transform="translate(0.000000,48.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none"> <path d="M44 468 c-38 -18 -44 -51 -44 -228 0 -180 6 -210 47 -229 33 -15 513 -15 546 0 41 19 47 49 47 229 0 180 -6 210 -47 229 -31 14 -519 14 -549 -1z m516 -33 c0 -7 -232 -205 -240 -205 -8 0 -240 198 -240 205 0 3 108 5 240 5 132 0 240 -2 240 -5z m-406 -118 l59 -53 -87 -97 -86 -97 0 170 0 171 28 -20 c15 -11 54 -44 86 -74z m446 -77 l0 -170 -85 95 c-47 53 -85 98 -85 99 0 5 162 146 167 146 1 0 3 -77 3 -170z m-319 -31 l39 -31 40 32 39 31 33 -37 c18 -21 57 -65 87 -99 l53 -60 -126 -3 c-69 -1 -183 -1 -252 0 l-126 3 84 97 c46 53 85 97 87 97 2 1 21 -13 42 -30z"/> </g> </svg>',
29
28
  google: '<svg viewBox="0 0 24 24" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><g transform="matrix(1, 0, 0, 1, 27.009001, -39.238998)"><path fill="#4285F4" d="M -3.264 51.509 C -3.264 50.719 -3.334 49.969 -3.454 49.239 L -14.754 49.239 L -14.754 53.749 L -8.284 53.749 C -8.574 55.229 -9.424 56.479 -10.684 57.329 L -10.684 60.329 L -6.824 60.329 C -4.564 58.239 -3.264 55.159 -3.264 51.509 Z"/><path fill="#34A853" d="M -14.754 63.239 C -11.514 63.239 -8.804 62.159 -6.824 60.329 L -10.684 57.329 C -11.764 58.049 -13.134 58.489 -14.754 58.489 C -17.884 58.489 -20.534 56.379 -21.484 53.529 L -25.464 53.529 L -25.464 56.619 C -23.494 60.539 -19.444 63.239 -14.754 63.239 Z"/><path fill="#FBBC05" d="M -21.484 53.529 C -21.734 52.809 -21.864 52.039 -21.864 51.239 C -21.864 50.439 -21.724 49.669 -21.484 48.949 L -21.484 45.859 L -25.464 45.859 C -26.284 47.479 -26.754 49.299 -26.754 51.239 C -26.754 53.179 -26.284 54.999 -25.464 56.619 L -21.484 53.529 Z"/><path fill="#EA4335" d="M -14.754 43.989 C -12.984 43.989 -11.404 44.599 -10.154 45.789 L -6.734 42.369 C -8.804 40.429 -11.514 39.239 -14.754 39.239 C -19.444 39.239 -23.494 41.939 -25.464 45.859 L -21.484 48.949 C -20.534 46.099 -17.884 43.989 -14.754 43.989 Z"/></g></svg>',
30
29
  linkedin: '<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="100%" height="100%" viewBox="1.786 1.783 76.226652 76.248" version="1.1" id="svg72" sodipodi:docname="linkedin.svg" inkscape:version="0.92.4 (5da689c313, 2019-01-14)"> <metadata id="metadata78"> <rdf:RDF> <cc:Work rdf:about=""> <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> <dc:title></dc:title> </cc:Work> </rdf:RDF> </metadata> <defs id="defs76" /> <sodipodi:namedview pagecolor="#ffffff" bordercolor="#666666" borderopacity="1" objecttolerance="10" gridtolerance="10" guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:window-width="1916" inkscape:window-height="1036" id="namedview74" showgrid="false" inkscape:zoom="0.79365665" inkscape:cx="428.70379" inkscape:cy="325.16058" inkscape:window-x="0" inkscape:window-y="20" inkscape:window-maximized="0" inkscape:current-layer="svg72" inkscape:pagecheckerboard="false" /> <path d="m 2.10821,7.2952417 c 0,-3.015 2.508,-5.462 5.6,-5.462 h 64.568 c 3.093,0 5.6,2.447 5.6,5.462 V 72.620242 c 0,3.016 -2.507,5.461 -5.6,5.461 h -64.568 c -3.092,0 -5.6,-2.445 -5.6,-5.46 V 7.2942417 Z" id="path64" inkscape:connector-curvature="0" style="fill:#0b78b7;fill-opacity:1" /> <path d="m 25.07621,65.660242 v -34.43 h -11.444 v 34.43 h 11.445 z m -5.72,-39.13 c 3.99,0 6.474,-2.644 6.474,-5.948 -0.075,-3.379 -2.484,-5.949 -6.398,-5.949 -3.917,0 -6.475,2.57 -6.475,5.949 0,3.304 2.483,5.948 6.324,5.948 h 0.074 z m 12.054,39.13 h 11.443 v -19.225 c 0,-1.028 0.075,-2.058 0.377,-2.792 0.827,-2.057 2.71,-4.186 5.872,-4.186 4.14,0 5.797,3.157 5.797,7.786 v 18.417 h 11.443 v -19.741 c 0,-10.575 -5.645,-15.496 -13.174,-15.496 -6.173,0 -8.884,3.45 -10.39,5.8 h 0.076 v -4.992 h -11.443 c 0.149,3.23 -0.001,34.43 -0.001,34.43 z" id="path70" inkscape:connector-curvature="0" style="fill:#ffffff" /> </svg>',
31
30
  microsoft: '<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 21 21"><title>MS-SymbolLockup</title><rect x="1" y="1" width="9" height="9" fill="#f25022"/><rect x="1" y="11" width="9" height="9" fill="#00a4ef"/><rect x="11" y="1" width="9" height="9" fill="#7fba00"/><rect x="11" y="11" width="9" height="9" fill="#ffb900"/></svg>',
32
31
  };
33
- var applyComponentStyle = function (component) {
32
+ const applyComponentStyle = (component) => {
34
33
  component.style.alignItems = 'center';
35
34
  component.style.background = '#fff';
36
35
  component.style.border = 'thin solid #888';
@@ -47,7 +46,7 @@ var applyComponentStyle = function (component) {
47
46
  component.style.width = '276px';
48
47
  component.style.boxSizing = 'content-box';
49
48
  };
50
- var applyLabelStyle = function (label) {
49
+ const applyLabelStyle = (label) => {
51
50
  label.style.display = 'inline-block';
52
51
  label.style.fontSize = '14px';
53
52
  label.style.fontWeight = '500';
@@ -55,13 +54,13 @@ var applyLabelStyle = function (label) {
55
54
  label.style.marginRight = '34px';
56
55
  label.style.paddingLeft = '20px';
57
56
  };
58
- var loginButton = function (type, fn) {
59
- var loweredCasedType = type.toLowerCase();
60
- var result = document.createElement('login-button');
57
+ const loginButton = (type, fn) => {
58
+ const loweredCasedType = type.toLowerCase();
59
+ const result = document.createElement('login-button');
61
60
  applyComponentStyle(result);
62
61
  result.tabIndex = 0;
63
- result.setAttribute('data-cy', "".concat(loweredCasedType, "-button"));
64
- var icon = document.createElement('login-icon');
62
+ result.setAttribute('data-cy', `${loweredCasedType}-button`);
63
+ const icon = document.createElement('login-icon');
65
64
  icon.style.gridColumnStart = '2';
66
65
  icon.style.width = '28px';
67
66
  icon.style.height = '28px';
@@ -71,16 +70,16 @@ var loginButton = function (type, fn) {
71
70
  icon.className = 'ico';
72
71
  // @ts-ignore
73
72
  icon.innerHTML = icons[loweredCasedType];
74
- var label = document.createElement('login-label');
75
- label.textContent = window.innerWidth <= THRESHOLD_WIDTH ? type : getTranslation("".concat(loweredCasedType, "-label"));
73
+ const label = document.createElement('login-label');
74
+ label.textContent = window.innerWidth <= THRESHOLD_WIDTH ? type : getTranslation(`${loweredCasedType}-label`);
76
75
  applyLabelStyle(label);
77
76
  result.append(icon, label);
78
77
  result.addEventListener('click', fn);
79
- result.addEventListener('mouseenter', function () {
78
+ result.addEventListener('mouseenter', () => {
80
79
  result.style.cursor = 'pointer';
81
80
  result.style.boxShadow = '0 0 6px #808080';
82
81
  });
83
- result.addEventListener('mouseleave', function () {
82
+ result.addEventListener('mouseleave', () => {
84
83
  result.style.cursor = 'auto';
85
84
  result.style.boxShadow = '1px 1px 1px grey';
86
85
  });
@@ -101,22 +100,6 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
101
100
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
102
101
  PERFORMANCE OF THIS SOFTWARE.
103
102
  ***************************************************************************** */
104
- /* global Reflect, Promise */
105
-
106
- var extendStatics = function(d, b) {
107
- extendStatics = Object.setPrototypeOf ||
108
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
109
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
110
- return extendStatics(d, b);
111
- };
112
-
113
- function __extends(d, b) {
114
- if (typeof b !== "function" && b !== null)
115
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
116
- extendStatics(d, b);
117
- function __() { this.constructor = d; }
118
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
119
- }
120
103
 
121
104
  function __awaiter(thisArg, _arguments, P, generator) {
122
105
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -126,54 +109,25 @@ function __awaiter(thisArg, _arguments, P, generator) {
126
109
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
127
110
  step((generator = generator.apply(thisArg, _arguments || [])).next());
128
111
  });
129
- }
130
-
131
- function __generator(thisArg, body) {
132
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
133
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
134
- function verb(n) { return function (v) { return step([n, v]); }; }
135
- function step(op) {
136
- if (f) throw new TypeError("Generator is already executing.");
137
- while (_) try {
138
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
139
- if (y = 0, t) op = [op[0] & 2, t.value];
140
- switch (op[0]) {
141
- case 0: case 1: t = op; break;
142
- case 4: _.label++; return { value: op[1], done: false };
143
- case 5: _.label++; y = op[1]; op = [0]; continue;
144
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
145
- default:
146
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
147
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
148
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
149
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
150
- if (t[2]) _.ops.pop();
151
- _.trys.pop(); continue;
152
- }
153
- op = body.call(thisArg, _);
154
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
155
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
156
- }
157
112
  }
158
113
 
159
- var extractTokenFromWindowLocation = function (tokenParam, additionalParam) {
160
- if (additionalParam === void 0) { additionalParam = ''; }
114
+ const extractTokenFromWindowLocation = (tokenParam, additionalParam = '') => {
161
115
  if (!tokenParam)
162
116
  return;
163
- var token = '';
164
- var tokenParameterName = "".concat(tokenParam, "=");
165
- var search = window.location.search;
166
- var tokenParameterIndex = search.indexOf(tokenParameterName);
117
+ let token = '';
118
+ const tokenParameterName = `${tokenParam}=`;
119
+ const search = window.location.search;
120
+ const tokenParameterIndex = search.indexOf(tokenParameterName);
167
121
  if (tokenParameterIndex !== -1) {
168
- var tokenParameterNameLength = tokenParameterName.length;
169
- var leadingAmpersandIndex = search.indexOf('&', tokenParameterIndex);
170
- var searchWithoutToken = search;
122
+ const tokenParameterNameLength = tokenParameterName.length;
123
+ const leadingAmpersandIndex = search.indexOf('&', tokenParameterIndex);
124
+ let searchWithoutToken = search;
171
125
  token = search.substring(tokenParameterIndex + tokenParameterNameLength);
172
126
  if (leadingAmpersandIndex !== -1) {
173
127
  token = search.substring(tokenParameterIndex + tokenParameterNameLength, leadingAmpersandIndex);
174
128
  searchWithoutToken = searchWithoutToken.slice(0, leadingAmpersandIndex) + searchWithoutToken.slice(leadingAmpersandIndex + 1);
175
129
  }
176
- searchWithoutToken = searchWithoutToken.replace("".concat(tokenParam, "=") + token, '')
130
+ searchWithoutToken = searchWithoutToken.replace(`${tokenParam}=` + token, '')
177
131
  .replace(additionalParam, '')
178
132
  .replace('\&cypress=true', '');
179
133
  if (searchWithoutToken === '?') {
@@ -184,31 +138,40 @@ var extractTokenFromWindowLocation = function (tokenParam, additionalParam) {
184
138
  return token;
185
139
  };
186
140
 
187
- var setBackendUrl = function (backendUrl) { return localStorage.setItem('backend-url', backendUrl); };
141
+ const setBackendUrl = (backendUrl) => localStorage.setItem('backend-url', backendUrl);
188
142
  //@ts-ignore
189
- var getBackendUrl = function () { return process.env.BACKEND_URL || localStorage.getItem('backend-url'); };
143
+ const getBackendUrl = () => process.env.BACKEND_URL || localStorage.getItem('backend-url');
190
144
  //@ts-ignore
191
- var getSecondaryBackendUrl = function () { return process.env.STAGING_BACKEND_URL || getBackendUrl(); };
192
- var getBackendUrlToTry = function () { return getBackendUrl(); };
193
- var getApiUrl = function () { return getBackendUrl() + 'api/'; };
194
- var getGoogleAuthUrl = function () { return getBackendUrl() + 'auth-google?google-id-token='; };
195
- var getMicrosoftAuthUrl = function () { return getBackendUrl() + 'auth-microsoft?access-token='; };
196
- var getMagicAuthUrl = function () {
145
+ const getSecondaryBackendUrl = () => process.env.STAGING_BACKEND_URL || getBackendUrl();
146
+ const getApiUrl = () => getBackendUrl() + 'api/';
147
+ let getBackendUrlToTry = () => getBackendUrl();
148
+ const getMagicAuthUrl = () => {
197
149
  var _a;
198
150
  // @ts-ignore
199
- var endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
151
+ const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
200
152
  return getBackendUrl() + endpoint + '?token=';
201
153
  };
202
- var getMagicAuthReqUrl = function () {
154
+ const getMagicAuthReqUrl = () => {
203
155
  var _a;
204
156
  // @ts-ignore
205
- var endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
157
+ const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
206
158
  return getBackendUrl() + endpoint + '?email=';
207
159
  };
208
- var timeout;
209
- var maxRetries = 20;
210
- var retries = 0;
211
- var applySpinnerStyle = function (spinner) {
160
+ const handleJuxEvents = (ev) => {
161
+ const { method, endpoint, onResult, params, onError } = ev;
162
+ const onJsonResponse = (res) => onResult ? onResult(res) : null;
163
+ const onHelpMessage = (err) => onError ? onError(err) : null;
164
+ if (method === 'GET') {
165
+ backendGet(endpoint, params, onJsonResponse, onHelpMessage);
166
+ }
167
+ if (method === 'POST') {
168
+ backendPost(endpoint, params, onJsonResponse, onHelpMessage);
169
+ }
170
+ };
171
+ let timeout;
172
+ const maxRetries = 20;
173
+ let retries = 0;
174
+ const applySpinnerStyle = (spinner) => {
212
175
  spinner.style.position = 'fixed';
213
176
  spinner.style.top = '50%';
214
177
  spinner.style.zIndex = '2147483647';
@@ -217,44 +180,51 @@ var applySpinnerStyle = function (spinner) {
217
180
  spinner.style.height = '80px';
218
181
  spinner.style.width = '80px';
219
182
  };
220
- var renderOverlay = function () {
221
- var overlay = document.createElement('reconnect-overlay');
222
- var spinner = document.createElement('loading-spinner');
183
+ const renderOverlay = () => {
184
+ const overlay = document.createElement('reconnect-overlay');
185
+ const spinner = document.createElement('loading-spinner');
223
186
  spinner.className = 'reconnect-spinner';
224
187
  applySpinnerStyle(spinner);
225
188
  document.body.append(overlay, spinner);
226
189
  };
227
- var removeOverlay = function () {
190
+ const removeOverlay = () => {
228
191
  var _a, _b;
229
192
  (_a = document.querySelector('reconnect-overlay')) === null || _a === void 0 ? void 0 : _a.remove();
230
193
  (_b = document.querySelector('.reconnect-spinner')) === null || _b === void 0 ? void 0 : _b.remove();
231
194
  };
232
- var backendHelpMessage = function (req) {
195
+ const backendHelpMessage = (req) => {
233
196
  return req.response && req.response.error || req.response || req;
234
197
  };
235
- var backendRequest = function (requestType, url, postContent, onJsonResponse, onHelpMessage) {
236
- if (url.includes(getBackendUrl())) {
237
- url = url.replace(getBackendUrl(), getBackendUrlToTry());
198
+ const defaultHandleUnauthorized = () => {
199
+ localStorage.removeItem('token');
200
+ alert(getTranslation('session-expired-msg'));
201
+ location.reload();
202
+ // googleAuthSignOut(); TODO
203
+ };
204
+ const backendRequest = (requestType, urlString, params, onJsonResponse, onHelpMessage, handleUnauthorized = defaultHandleUnauthorized) => {
205
+ if (urlString.includes(getBackendUrl())) {
206
+ urlString = urlString.replace(getBackendUrl(), getBackendUrlToTry());
238
207
  }
239
- else if (url.includes(getSecondaryBackendUrl())) {
240
- url = url.replace(getSecondaryBackendUrl(), getBackendUrlToTry());
208
+ else if (urlString.includes(getSecondaryBackendUrl())) {
209
+ urlString = urlString.replace(getSecondaryBackendUrl(), getBackendUrlToTry());
241
210
  }
242
211
  clearInterval(timeout);
243
- var req = new XMLHttpRequest();
212
+ const req = new XMLHttpRequest();
213
+ const url = new URL(urlString);
214
+ if (requestType === 'GET' && params) {
215
+ Object.keys(params).forEach(k => url.searchParams.set(k, params[k]));
216
+ }
244
217
  req.open(requestType, url, true);
245
218
  // @ts-ignore
246
- var backendToken = window.store.backendToken;
219
+ const backendToken = window.store.backendToken;
247
220
  if (backendToken) {
248
221
  req.setRequestHeader('auth', backendToken);
249
222
  }
250
223
  req.setRequestHeader('Content-Type', 'application/json');
251
224
  req.responseType = 'json';
252
- req.onerror = req.ontimeout = function () {
225
+ req.onerror = req.ontimeout = () => {
253
226
  if (req.status === 401) {
254
- localStorage.removeItem('token');
255
- alert(getTranslation('session-expired-msg'));
256
- location.reload();
257
- // googleAuthSignOut(); TODO
227
+ handleUnauthorized();
258
228
  }
259
229
  else if (req.status === 0) {
260
230
  if (retries >= maxRetries) {
@@ -266,20 +236,20 @@ var backendRequest = function (requestType, url, postContent, onJsonResponse, on
266
236
  if (!document.querySelector('reconnect-overlay')) {
267
237
  renderOverlay();
268
238
  }
269
- var backupBackendUrl_1 = getBackendUrlToTry() === getBackendUrl()
239
+ const backupBackendUrl = getBackendUrlToTry() === getBackendUrl()
270
240
  ? getSecondaryBackendUrl()
271
241
  : getBackendUrl();
272
- url = url.replace(getBackendUrlToTry(), backupBackendUrl_1);
273
- getBackendUrlToTry = function () { return backupBackendUrl_1; };
274
- timeout = setTimeout(function () {
275
- backendRequest(requestType, url, postContent, onJsonResponse, onHelpMessage);
242
+ urlString = urlString.replace(getBackendUrlToTry(), backupBackendUrl);
243
+ getBackendUrlToTry = () => backupBackendUrl;
244
+ timeout = setTimeout(() => {
245
+ backendRequest(requestType, urlString, params, onJsonResponse, onHelpMessage);
276
246
  }, 2000);
277
247
  }
278
248
  else {
279
249
  onHelpMessage(backendHelpMessage(req));
280
250
  }
281
251
  };
282
- req.onload = function () {
252
+ req.onload = () => {
283
253
  retries = 0;
284
254
  removeOverlay();
285
255
  if (req.status === 200 || req.status === 202) {
@@ -293,67 +263,60 @@ var backendRequest = function (requestType, url, postContent, onJsonResponse, on
293
263
  }
294
264
  };
295
265
  req.timeout = 25000;
296
- req.send(postContent);
266
+ req.send(params);
297
267
  };
298
- var backendPost = function (endpoint, postContent, onJsonResponse, onHelpMessage) {
268
+ const backendPost = (endpoint, postContent, onJsonResponse, onHelpMessage) => {
299
269
  backendRequest('POST', getApiUrl() + endpoint, postContent, onJsonResponse, onHelpMessage);
300
270
  };
301
- var backendGet = function (endpoint, onJsonResponse, onHelpMessage) {
302
- var api = getApiUrl() + endpoint;
303
- if (endpoint.includes(getGoogleAuthUrl()) || endpoint.includes(getMicrosoftAuthUrl())) {
304
- api = endpoint;
305
- }
306
- backendRequest('GET', api, undefined, onJsonResponse, onHelpMessage);
307
- };
308
- var backendGetPromise = function (endpoint) { return new Promise(function (resolve, reject) {
309
- return backendGet(endpoint, resolve, reject);
310
- }); };
311
- var requestMagicLink = function (data, onJsonResponse) {
312
- backendRequest('GET', getMagicAuthReqUrl() + encodeURIComponent(data.email) + '&destination=' + extractTokenFromWindowLocation('destination') + '&token=' + data.token, undefined, onJsonResponse, function () { });
313
- };
314
- var openMagicLink = function (magicToken, onJsonResponse, onHelpMessage) {
315
- backendRequest('GET', getMagicAuthUrl() + magicToken, undefined, onJsonResponse, onHelpMessage);
316
- };
317
- var getMXData = function (domainName) { return __awaiter(void 0, void 0, void 0, function () {
318
- var records, recordsJson, answer, error_1;
319
- return __generator(this, function (_a) {
320
- switch (_a.label) {
321
- case 0:
322
- _a.trys.push([0, 3, , 4]);
323
- return [4 /*yield*/, fetch("https://dns.google.com/resolve?name=".concat(domainName, "&type=MX"), {
324
- method: 'GET',
325
- mode: 'cors'
326
- })];
327
- case 1:
328
- records = _a.sent();
329
- if (!records.ok) {
330
- console.log('response was not ok');
331
- return [2 /*return*/, null];
332
- }
333
- return [4 /*yield*/, records.json()];
334
- case 2:
335
- recordsJson = _a.sent();
336
- answer = recordsJson.Answer;
337
- if (!answer) {
338
- return [2 /*return*/, null];
339
- }
340
- return [2 /*return*/, Array.from(answer).map(function (a) { return a.data; })];
341
- case 3:
342
- error_1 = _a.sent();
343
- console.error('Fetch failed: ', error_1);
344
- return [2 /*return*/, null];
345
- case 4: return [2 /*return*/];
271
+ const backendGet = (endpoint, params, onJsonResponse, onHelpMessage) => {
272
+ backendRequest('GET', getApiUrl() + endpoint, params, onJsonResponse, onHelpMessage);
273
+ };
274
+ const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
275
+ const { email, token } = data;
276
+ const url = getMagicAuthReqUrl() + encodeURIComponent(email) + '&destination=' + extractTokenFromWindowLocation('destination') + '&token=' + token;
277
+ backendRequest('GET', url, null, onJsonResponse, console.error, onUnauthorized);
278
+ };
279
+ const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
280
+ backendRequest('GET', getMagicAuthUrl() + magicToken, null, onJsonResponse, onHelpMessage);
281
+ };
282
+ const googleLogin = (token, onLogin, onLoginError) => {
283
+ const url = getBackendUrl() + 'auth-google?google-id-token=' + token;
284
+ backendRequest('GET', url, null, onLogin, onLoginError);
285
+ };
286
+ const microsoftLogin = (token, onLogin, onLoginError) => {
287
+ const url = getBackendUrl() + 'auth-microsoft?access-token=' + token;
288
+ backendRequest('GET', url, null, onLogin, onLoginError);
289
+ };
290
+ const getMXData = (domainName) => __awaiter(void 0, void 0, void 0, function* () {
291
+ try {
292
+ const records = yield fetch(`https://dns.google.com/resolve?name=${domainName}&type=MX`, {
293
+ method: 'GET',
294
+ mode: 'cors'
295
+ });
296
+ if (!records.ok) {
297
+ console.log('response was not ok');
298
+ return null;
346
299
  }
347
- });
348
- }); };
300
+ const recordsJson = yield records.json();
301
+ const answer = recordsJson.Answer;
302
+ if (!answer) {
303
+ return null;
304
+ }
305
+ return Array.from(answer).map((a) => a.data);
306
+ }
307
+ catch (error) {
308
+ console.error('Fetch failed: ', error);
309
+ return null;
310
+ }
311
+ });
349
312
 
350
- var cleared = false;
351
- var clearCookieValidation = function () {
313
+ let cleared = false;
314
+ const clearCookieValidation = () => {
352
315
  var _a;
353
316
  (_a = document.querySelector('#cookie-test-iframe')) === null || _a === void 0 ? void 0 : _a.remove();
354
317
  cleared = true;
355
318
  };
356
- var checkCookiesEnable = function (ev, onEnabled, onDisabled) {
319
+ const checkCookiesEnable = (ev, onEnabled, onDisabled) => {
357
320
  if (ev.data === 'MM:3PCunsupported') {
358
321
  clearCookieValidation();
359
322
  if (onDisabled) {
@@ -365,18 +328,18 @@ var checkCookiesEnable = function (ev, onEnabled, onDisabled) {
365
328
  onEnabled();
366
329
  }
367
330
  };
368
- var cookieTest = function () {
369
- var frame = document.createElement('iframe');
331
+ const cookieTest = () => {
332
+ const frame = document.createElement('iframe');
370
333
  frame.id = 'cookie-test-iframe';
371
334
  frame.src = 'https://mindmup.github.io/3rdpartycookiecheck/start.html';
372
335
  frame.style.display = 'none';
373
336
  document.body.appendChild(frame);
374
337
  };
375
- var validateThirdPartyCookies = function (onEnabled, onDisabled) {
338
+ const validateThirdPartyCookies = (onEnabled, onDisabled) => {
376
339
  cleared = false;
377
- var listener = function (ev) { return checkCookiesEnable(ev, onEnabled, onDisabled); };
340
+ const listener = (ev) => checkCookiesEnable(ev, onEnabled, onDisabled);
378
341
  window.addEventListener('message', listener);
379
- var timer = setInterval(function () {
342
+ const timer = setInterval(() => {
380
343
  if (cleared) {
381
344
  window.removeEventListener('message', listener);
382
345
  clearInterval(timer);
@@ -385,26 +348,26 @@ var validateThirdPartyCookies = function (onEnabled, onDisabled) {
385
348
  cookieTest();
386
349
  };
387
350
 
388
- var enableSignInLayout = function () {
351
+ const enableSignInLayout = () => {
389
352
  document.documentElement.style.cursor = 'progress';
390
353
  document.body.style.opacity = '0.5';
391
354
  document.body.style.pointerEvents = 'none';
392
355
  };
393
- var disableSignInLayout = function () {
356
+ const disableSignInLayout = () => {
394
357
  document.documentElement.style.cursor = 'default';
395
358
  document.body.style.opacity = '1';
396
359
  document.body.style.pointerEvents = 'auto';
397
360
  };
398
361
 
399
362
  // TODO: find a better way to import external scripts
400
- var script$1 = document.createElement('script');
363
+ const script$1 = document.createElement('script');
401
364
  script$1.type = 'text/javascript';
402
365
  script$1.src = 'https://apis.google.com/js/api.js';
403
366
  document.head.appendChild(script$1);
404
- var authStatus;
405
- var authError;
406
- var highLevelUser = function (gUser) {
407
- var profile = gUser.getBasicProfile();
367
+ let authStatus;
368
+ let authError;
369
+ const highLevelUser = (gUser) => {
370
+ const profile = gUser.getBasicProfile();
408
371
  return {
409
372
  name: profile.getName(),
410
373
  email: profile.getEmail(),
@@ -412,62 +375,50 @@ var highLevelUser = function (gUser) {
412
375
  googletoken: gUser.getAuthResponse().id_token
413
376
  };
414
377
  };
415
- var onUserChanged = function (googleUser, onUserLogin) { return __awaiter(void 0, void 0, void 0, function () {
416
- var error_1;
417
- return __generator(this, function (_a) {
418
- switch (_a.label) {
419
- case 0:
420
- document.documentElement.classList.remove('progress');
421
- document.body.classList.remove('disabled');
422
- if (!googleUser) return [3 /*break*/, 5];
423
- _a.label = 1;
424
- case 1:
425
- _a.trys.push([1, 3, , 4]);
426
- return [4 /*yield*/, backendGetPromise(getGoogleAuthUrl() + googleUser.googletoken)
427
- .then(function (res) {
428
- var token = res.token;
429
- // @ts-ignore
430
- window.store.currentUser = res;
431
- onTokenAcquired(token, onUserLogin);
432
- })
433
- .catch(function (error) { throw Error(error); })];
434
- case 2:
435
- _a.sent();
436
- return [3 /*break*/, 4];
437
- case 3:
438
- error_1 = _a.sent();
439
- console.error(error_1);
440
- // logError(error); TODO
441
- // checkMixpanel(() => mixpanel.track('Login Error', { 'Login Type': 'Google', 'Error': error })); TODO
442
- return [2 /*return*/];
443
- case 4: return [3 /*break*/, 6];
444
- case 5:
445
- setBackendToken('');
446
- _a.label = 6;
447
- case 6: return [2 /*return*/];
448
- }
449
- });
450
- }); };
451
- var onGoogleUserChanged = function (gUser, onUserLogin) {
378
+ const onUserChanged = (googleUser, onUserLogin) => {
379
+ document.documentElement.classList.remove('progress');
380
+ document.body.classList.remove('disabled');
381
+ if (googleUser) {
382
+ // mixpanelIdentify(googleUser); TODO
383
+ const onSuccess = (res) => {
384
+ const { token } = res;
385
+ // @ts-ignore
386
+ window.store.currentUser = res;
387
+ onTokenAcquired(token, onUserLogin);
388
+ };
389
+ const onError = (err) => {
390
+ console.error(err);
391
+ // logError(error); TODO
392
+ // checkMixpanel(() => mixpanel.track('Login Error', { 'Login Type': 'Google', 'Error': error })); TODO
393
+ };
394
+ googleLogin(googleUser.googletoken, onSuccess, onError);
395
+ // checkMixpanel(() => mixpanel.track('Login', { 'Login Type': 'Google' })); TODO
396
+ }
397
+ else {
398
+ setBackendToken('');
399
+ // checkMixpanel(() => mixpanel.reset()); TODO
400
+ // displayPage(Page.LOGIN); TODO
401
+ }
402
+ };
403
+ const onGoogleUserChanged = (gUser, onUserLogin) => {
452
404
  onUserChanged(gUser.isSignedIn() ? highLevelUser(gUser) : null, onUserLogin);
453
405
  };
454
- var initGapiClient = function (callbackFn, onUserLogin) {
406
+ const initGapiClient = (callbackFn, onUserLogin) => {
455
407
  // @ts-ignore
456
- var clientId = process.env.GOOGLE_CLIENT_ID;
457
- gapi.auth2.init({ client_id: clientId, prompt: 'select_account' }).then(function () {
408
+ const clientId = process.env.GOOGLE_CLIENT_ID;
409
+ gapi.auth2.init({ client_id: clientId, prompt: 'select_account' }).then(() => {
458
410
  authStatus = 'LOADED';
459
- var currentUser = getAuth().currentUser;
411
+ const currentUser = getAuth().currentUser;
460
412
  currentUser.listen(onGoogleUserChanged);
461
413
  callbackFn ? callbackFn(clientId) : onGoogleUserChanged(currentUser.get(), onUserLogin);
462
414
  }, onAuthError);
463
415
  };
464
- var onAuthError = function (error) {
416
+ const onAuthError = (error) => {
465
417
  authError = error;
466
418
  console.error(error);
467
419
  // logError(error, authError); // TODO
468
420
  };
469
- var initGapi = function (callbackFn, onUserLogin) {
470
- if (callbackFn === void 0) { callbackFn = null; }
421
+ const initGapi = (callbackFn = null, onUserLogin) => {
471
422
  if (!window.location.protocol.startsWith('http')) {
472
423
  onAuthError('To use Google Auth you must access this page using http(s), not ' + window.location.protocol);
473
424
  return;
@@ -478,27 +429,27 @@ var initGapi = function (callbackFn, onUserLogin) {
478
429
  }
479
430
  authStatus = 'LOADING';
480
431
  gapi.load('auth2', {
481
- callback: function () { return initGapiClient(callbackFn, onUserLogin); },
432
+ callback: () => initGapiClient(callbackFn, onUserLogin),
482
433
  onerror: onAuthError,
483
434
  ontimeout: onAuthError,
484
435
  timeout: 5000
485
436
  });
486
437
  };
487
- var authAlert = function (error) {
438
+ const authAlert = (error) => {
488
439
  alert('Google authentication is not working at this moment.\n\nPlease try again later or use a magic sign-in link.\n\nError: ' + JSON.stringify(error));
489
440
  location.reload();
490
441
  };
491
- var onSignInError = function (error) {
442
+ const onSignInError = (error) => {
492
443
  disableSignInLayout();
493
444
  console.error(error);
494
445
  // logError(error); TODO
495
446
  if (error && error.error === 'popup_closed_by_user') {
496
- onUserChanged(null, function () { });
447
+ onUserChanged(null, () => { });
497
448
  return;
498
449
  }
499
450
  authAlert(error);
500
451
  };
501
- var getAuth = function () {
452
+ const getAuth = () => {
502
453
  if (typeof gapi === 'undefined') {
503
454
  console.error('gapi is undefined');
504
455
  // logError('gapi is undefined'); TODO
@@ -506,8 +457,8 @@ var getAuth = function () {
506
457
  }
507
458
  return gapi.auth2 && gapi.auth2.getAuthInstance();
508
459
  };
509
- var googleSignIn = function () { return getAuth().signIn().catch(onSignInError); };
510
- var authSignIn = function (onUserLogin) {
460
+ const googleSignIn = () => getAuth().signIn().catch(onSignInError);
461
+ const authSignIn = (onUserLogin) => {
511
462
  if (authError) {
512
463
  authAlert(authError);
513
464
  return;
@@ -521,7 +472,7 @@ var authSignIn = function (onUserLogin) {
521
472
  }
522
473
  catch (err) {
523
474
  try {
524
- initGapi(function () { return googleSignIn(); }, onUserLogin);
475
+ initGapi(() => googleSignIn(), onUserLogin);
525
476
  }
526
477
  catch (error) {
527
478
  onSignInError(error);
@@ -531,13 +482,13 @@ var authSignIn = function (onUserLogin) {
531
482
  };
532
483
 
533
484
  // TODO: find a better way to import external scripts
534
- var script = document.createElement('script');
485
+ const script = document.createElement('script');
535
486
  script.type = 'text/javascript';
536
487
  script.src = 'https://www.google.com/recaptcha/api.js';
537
488
  document.head.appendChild(script);
538
- var googleCaptcha = function () {
539
- var result = document.createElement('google-captcha');
540
- window.submitCaptcha = function (token) { return result.setAttribute('token', token); };
489
+ const googleCaptcha = () => {
490
+ const result = document.createElement('google-captcha');
491
+ window.submitCaptcha = (token) => result.setAttribute('token', token);
541
492
  result.className = 'g-recaptcha';
542
493
  // @ts-ignore
543
494
  result.setAttribute('data-sitekey', process.env.GOOGLE_CAPTCHA_KEY);
@@ -546,14 +497,14 @@ var googleCaptcha = function () {
546
497
  return result;
547
498
  };
548
499
 
549
- var juxWhite = '#FFF';
550
- var juxDarkGrey = '#282828';
551
- var juxDimmedDarkGrey = '#28282822';
552
- var juxDimmedBlack = '#00000088';
553
- var juxLightGreen = '#20B03D';
554
- var juxMediumGreen = '#0D631E';
500
+ const juxWhite = '#FFF';
501
+ const juxDarkGrey = '#282828';
502
+ const juxDimmedDarkGrey = '#28282822';
503
+ const juxDimmedBlack = '#00000088';
504
+ const juxLightGreen = '#20B03D';
505
+ const juxMediumGreen = '#0D631E';
555
506
 
556
- var onKeyDown = function (ev, el, persitent, onClose) {
507
+ const onKeyDown = (ev, el, persitent, onClose) => {
557
508
  if (ev.key === 'Escape') {
558
509
  if (persitent) {
559
510
  return;
@@ -567,34 +518,34 @@ var onKeyDown = function (ev, el, persitent, onClose) {
567
518
  el.dispatchEvent(new CustomEvent('ok'));
568
519
  }
569
520
  };
570
- var close = function (el, onClose) {
521
+ const close = (el, onClose) => {
571
522
  el.remove();
572
523
  if (onClose) {
573
524
  onClose();
574
525
  }
575
526
  };
576
- var attachEventHandlers = function (el, persitent, onClose) {
577
- var cancelButton = el.querySelector('.cancel');
578
- cancelButton === null || cancelButton === void 0 ? void 0 : cancelButton.addEventListener('click', function (_e) {
527
+ const attachEventHandlers = (el, persitent, onClose) => {
528
+ const cancelButton = el.querySelector('.cancel');
529
+ cancelButton === null || cancelButton === void 0 ? void 0 : cancelButton.addEventListener('click', (_e) => {
579
530
  el.dispatchEvent(new CustomEvent('cancel'));
580
531
  if (el.hasAttribute('dont-remove')) {
581
532
  return;
582
533
  }
583
534
  close(el, onClose);
584
535
  });
585
- var closeButton = el.querySelector('.close');
536
+ const closeButton = el.querySelector('.close');
586
537
  if (closeButton) {
587
- closeButton.addEventListener('click', function (_e) {
538
+ closeButton.addEventListener('click', (_e) => {
588
539
  close(el, onClose);
589
540
  });
590
541
  }
591
- var okButton = el.querySelector('.ok');
592
- okButton === null || okButton === void 0 ? void 0 : okButton.addEventListener('click', function (_e) {
542
+ const okButton = el.querySelector('.ok');
543
+ okButton === null || okButton === void 0 ? void 0 : okButton.addEventListener('click', (_e) => {
593
544
  el.dispatchEvent(new CustomEvent('ok'));
594
545
  });
595
- el.removeEventListener('keydown', function (ev) { return onKeyDown(ev, el, persitent, function () { return onClose; }); });
596
- el.addEventListener('keydown', function (ev) { return onKeyDown(ev, el, persitent, function () { return onClose; }); });
597
- el === null || el === void 0 ? void 0 : el.addEventListener('click', function (e) {
546
+ el.removeEventListener('keydown', (ev) => onKeyDown(ev, el, persitent, () => onClose));
547
+ el.addEventListener('keydown', (ev) => onKeyDown(ev, el, persitent, () => onClose));
548
+ el === null || el === void 0 ? void 0 : el.addEventListener('click', (e) => {
598
549
  if (e.target === el) {
599
550
  if (persitent) {
600
551
  return;
@@ -616,11 +567,11 @@ var attachEventHandlers = function (el, persitent, onClose) {
616
567
  // onClose?: any,
617
568
  // titleStyle?: string,
618
569
  // }
619
- var applyWrapperStyle = function (wrapper) {
570
+ const applyWrapperStyle = (wrapper) => {
620
571
  wrapper.style.alignItems = 'center';
621
572
  wrapper.style.backgroundColor = juxWhite;
622
573
  wrapper.style.borderRadius = '.3125rem';
623
- wrapper.style.boxShadow = "0 0 1.33rem ".concat(juxDimmedBlack);
574
+ wrapper.style.boxShadow = `0 0 1.33rem ${juxDimmedBlack}`;
624
575
  wrapper.style.boxSizing = 'content-box';
625
576
  wrapper.style.display = 'flex';
626
577
  wrapper.style.flexDirection = 'column';
@@ -632,7 +583,7 @@ var applyWrapperStyle = function (wrapper) {
632
583
  wrapper.style.padding = '1.33rem';
633
584
  wrapper.style.position = 'relative';
634
585
  };
635
- var applyModalStyle = function (modal) {
586
+ const applyModalStyle = (modal) => {
636
587
  modal.style.alignItems = 'center';
637
588
  modal.style.backgroundColor = juxDimmedBlack;
638
589
  modal.style.display = 'flex';
@@ -645,7 +596,7 @@ var applyModalStyle = function (modal) {
645
596
  modal.style.width = '100%';
646
597
  modal.style.zIndex = '9999';
647
598
  };
648
- var applyHeaderStyle = function (header) {
599
+ const applyHeaderStyle = (header) => {
649
600
  header.style.alignItems = 'center';
650
601
  header.style.color = juxMediumGreen;
651
602
  header.style.flexDirection = 'row';
@@ -657,7 +608,7 @@ var applyHeaderStyle = function (header) {
657
608
  header.style.position = 'relative';
658
609
  header.style.width = '100%';
659
610
  };
660
- var applyJuxModalContentStyle = function (el) {
611
+ const applyJuxModalContentStyle = (el) => {
661
612
  el.style.display = 'flex';
662
613
  el.style.position = 'relative';
663
614
  el.style.width = '100%';
@@ -665,37 +616,32 @@ var applyJuxModalContentStyle = function (el) {
665
616
  el.style.marginTop = '1.33rem';
666
617
  el.style.rowGap = '8px';
667
618
  };
668
- var juxModal = function (title, btns, content, persistent, _busy, body, okTxt, cancelTxt, onClose, titleStyle) {
669
- if (btns === void 0) { btns = ['ok', 'cancel']; }
670
- if (content === void 0) { content = ''; }
671
- if (persistent === void 0) { persistent = false; }
672
- if (okTxt === void 0) { okTxt = getTranslation('alert-ok-btn-txt'); }
673
- if (cancelTxt === void 0) { cancelTxt = getTranslation('alert-cancel-btn-txt'); }
674
- var result = document.createElement('jux-modal');
619
+ const juxModal = (title, btns = ['ok', 'cancel'], content = '', persistent = false, _busy = false, body, okTxt = getTranslation('alert-ok-btn-txt'), cancelTxt = getTranslation('alert-cancel-btn-txt'), onClose, titleStyle) => {
620
+ const result = document.createElement('jux-modal');
675
621
  applyModalStyle(result);
676
- var wrapper = document.createElement('modal-wrapper');
622
+ const wrapper = document.createElement('modal-wrapper');
677
623
  applyWrapperStyle(wrapper);
678
624
  // START close
679
- var closeBtn = document.createElement('button');
625
+ const closeBtn = document.createElement('button');
680
626
  if (!persistent) {
681
627
  closeBtn.className = 'close';
682
628
  closeBtn.setAttribute('aria-label', getTranslation('close'));
683
629
  }
684
630
  // END close
685
631
  // START header
686
- var header = document.createElement('modal-header');
632
+ const header = document.createElement('modal-header');
687
633
  applyHeaderStyle(header);
688
634
  if (title) {
689
635
  if (titleStyle) {
690
636
  header.classList.add(titleStyle);
691
637
  }
692
- var h3 = document.createElement('h3');
638
+ const h3 = document.createElement('h3');
693
639
  h3.textContent = title;
694
640
  header.appendChild(h3);
695
641
  }
696
642
  // END header
697
643
  // START content
698
- var modalContent = document.createElement('jux-modal-content');
644
+ const modalContent = document.createElement('jux-modal-content');
699
645
  applyJuxModalContentStyle(modalContent);
700
646
  if (content) {
701
647
  modalContent.innerHTML = content;
@@ -705,22 +651,22 @@ var juxModal = function (title, btns, content, persistent, _busy, body, okTxt, c
705
651
  }
706
652
  // END content
707
653
  // START footer
708
- var footer = document.createElement('modal-footer');
654
+ const footer = document.createElement('modal-footer');
709
655
  if (btns.includes('cancel')) {
710
- var cancelBtn = document.createElement('button');
656
+ const cancelBtn = document.createElement('button');
711
657
  cancelBtn.classList.add('secondary-button', 'modal-button', 'action', 'cancel-btn', 'cancel');
712
- var cancelText = document.createElement('button-text');
658
+ const cancelText = document.createElement('button-text');
713
659
  cancelText.textContent = cancelTxt;
714
- var cancelSpinner = document.createElement('loading-spinner');
660
+ const cancelSpinner = document.createElement('loading-spinner');
715
661
  cancelBtn.append(cancelText, cancelSpinner);
716
662
  footer.appendChild(cancelBtn);
717
663
  }
718
664
  if (btns.includes('ok')) {
719
- var okBtn = document.createElement('button');
665
+ const okBtn = document.createElement('button');
720
666
  okBtn.classList.add('primary-button', 'modal-button', 'action', 'ok');
721
- var okText = document.createElement('button-text');
667
+ const okText = document.createElement('button-text');
722
668
  okText.textContent = okTxt;
723
- var okSpinner = document.createElement('loading-spinner');
669
+ const okSpinner = document.createElement('loading-spinner');
724
670
  okBtn.append(okText, okSpinner);
725
671
  footer.appendChild(okBtn);
726
672
  }
@@ -744,15 +690,13 @@ var juxModal = function (title, btns, content, persistent, _busy, body, okTxt, c
744
690
  return result;
745
691
  };
746
692
 
747
- var contactField = function (tag, elType, elName, required, value) {
748
- if (tag === void 0) { tag = 'input'; }
749
- if (required === void 0) { required = true; }
750
- var result = document.createElement('contact-field');
751
- var elId = 'contact-' + elName;
752
- var label = document.createElement('label');
693
+ const contactField = (tag = 'input', elType, elName, required = true, value) => {
694
+ const result = document.createElement('contact-field');
695
+ const elId = 'contact-' + elName;
696
+ const label = document.createElement('label');
753
697
  label.textContent = getTranslation(elId + '-label');
754
698
  label.htmlFor = elId;
755
- var el = document.createElement(tag);
699
+ const el = document.createElement(tag);
756
700
  el.id = elId;
757
701
  el.setAttribute('name', elName);
758
702
  el.setAttribute('placeholder', getTranslation(elId + '-placeholder'));
@@ -769,80 +713,74 @@ var contactField = function (tag, elType, elName, required, value) {
769
713
  return result;
770
714
  };
771
715
 
772
- var getNestedElValue = function (el, nestedTag) {
773
- var nestedEl = el.querySelector(nestedTag);
716
+ const getNestedElValue = (el, nestedTag) => {
717
+ const nestedEl = el.querySelector(nestedTag);
774
718
  return nestedEl.value;
775
719
  };
776
- var sendInquiry = function (name, email, msg, whatsapp, subject, token) {
777
- var inquiryPayload = {
778
- subject: "[".concat(subject.charAt(0).toUpperCase()).concat(subject.slice(1), "] ").concat(getNestedElValue(name, 'input')),
779
- body: "<strong>Name</strong>: ".concat(getNestedElValue(name, 'input'), "<br><br>\n<strong>E-mail</strong>: ").concat(getNestedElValue(email, 'input'), "<br><br>\n<strong>Whatsapp</strong>: ").concat(getNestedElValue(whatsapp, 'input'), "<br><br>\n<strong>Message</strong>: ").concat(getNestedElValue(msg, 'textarea')),
780
- token: token,
720
+ const sendInquiry = (name, email, msg, whatsapp, subject, token) => {
721
+ const inquiryPayload = {
722
+ subject: `[${subject.charAt(0).toUpperCase()}${subject.slice(1)}] ${getNestedElValue(name, 'input')}`,
723
+ body: `<strong>Name</strong>: ${getNestedElValue(name, 'input')}<br><br>
724
+ <strong>E-mail</strong>: ${getNestedElValue(email, 'input')}<br><br>
725
+ <strong>Whatsapp</strong>: ${getNestedElValue(whatsapp, 'input')}<br><br>
726
+ <strong>Message</strong>: ${getNestedElValue(msg, 'textarea')}`,
727
+ token,
781
728
  };
782
- backendPost('contact-us', JSON.stringify(inquiryPayload), function (_res) {
729
+ backendPost('contact-us', JSON.stringify(inquiryPayload), (_res) => {
783
730
  var _a;
784
731
  // success(getTranslation('form-success'), Length.long);
785
732
  (_a = document.querySelector('#contact-us-modal')) === null || _a === void 0 ? void 0 : _a.remove();
786
- }, function () { } // TODO: change it to be an error handling fn provided by the client
733
+ }, () => { } // TODO: change it to be an error handling fn provided by the client
787
734
  );
788
735
  // checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
789
736
  };
790
- var contactUsModal = function (subject) {
737
+ const contactUsModal = (subject) => {
791
738
  var _a, _b, _c, _d, _e;
792
- var result = document.createElement('contact-us-modal');
739
+ const result = document.createElement('contact-us-modal');
793
740
  // @ts-ignore
794
- var currentName = window.store.currentUser ? window.store.currentUser.name : '';
741
+ const currentName = window.store.currentUser ? window.store.currentUser.name : '';
795
742
  // @ts-ignore
796
- var currentEmail = window.store.currentUser ? window.store.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
797
- var modalBody = document.createElement('modal-body');
798
- var form = document.createElement('form');
743
+ const currentEmail = window.store.currentUser ? window.store.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
744
+ const modalBody = document.createElement('modal-body');
745
+ const form = document.createElement('form');
799
746
  form.id = 'contact-form';
800
- var nameField = contactField('input', 'text', 'name', true, currentName);
801
- var emailField = contactField('input', 'email', 'email', true, currentEmail);
802
- var messageField = contactField('textarea', 'text', 'message', true);
803
- var whatsappField = contactField('input', 'tel', 'whatsapp', false);
804
- var btn = document.createElement('button');
747
+ const nameField = contactField('input', 'text', 'name', true, currentName);
748
+ const emailField = contactField('input', 'email', 'email', true, currentEmail);
749
+ const messageField = contactField('textarea', 'text', 'message', true);
750
+ const whatsappField = contactField('input', 'tel', 'whatsapp', false);
751
+ const btn = document.createElement('button');
805
752
  btn.textContent = getTranslation('contact-submit');
806
753
  btn.className = 'primary-button';
807
754
  form.append(nameField, emailField, whatsappField, messageField, btn);
808
755
  modalBody.appendChild(form);
809
- var modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', function () { return result.remove(); });
756
+ const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
810
757
  modal.id = 'contact-us-modal';
811
758
  document.body.appendChild(modal);
812
759
  (_b = modal.querySelector('modal-wrapper')) === null || _b === void 0 ? void 0 : _b.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
813
- var captcha = googleCaptcha();
760
+ const captcha = googleCaptcha();
814
761
  if (subject !== 'email-not-sent') {
815
762
  // @ts-ignore
816
- var 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;
817
- backendGet("credits-balance-for?admin=".concat(admin), function (res) {
818
- var balance = res;
763
+ 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;
764
+ backendGet(`credits-balance-for?admin=${admin}`, null, (res) => {
765
+ const balance = res;
819
766
  if (balance <= 0) {
820
767
  form.insertBefore(captcha, btn);
821
768
  }
822
- }, function () { } // TODO: change it to be an error handling fn provided by the client
769
+ }, () => { } // TODO: change it to be an error handling fn provided by the client
823
770
  );
824
771
  }
825
772
  else {
826
773
  form.insertBefore(captcha, btn);
827
774
  }
828
775
  (_e = nameField.querySelector('input')) === null || _e === void 0 ? void 0 : _e.select();
829
- form.addEventListener('submit', function (event) {
776
+ form.addEventListener('submit', (event) => {
830
777
  event.preventDefault();
831
778
  sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
832
779
  });
833
780
  return result;
834
781
  };
835
782
 
836
- var applyPageStyles$1 = function (page, backgroundImg) {
837
- page.style.backgroundImage = "url(".concat(backgroundImg, ")");
838
- page.style.display = 'block';
839
- page.style.width = '100%';
840
- page.style.height = '100%';
841
- page.style.backgroundPosition = '50%';
842
- page.style.backgroundSize = 'cover';
843
- page.style.display = 'block';
844
- };
845
- var applyContainerStyles$1 = function (container) {
783
+ const applyContainerStyles = (container) => {
846
784
  container.style.backgroundColor = '#ffffffdd';
847
785
  container.style.borderRadius = '16px';
848
786
  container.style.inset = '50% 50% 50% 0';
@@ -858,7 +796,25 @@ var applyContainerStyles$1 = function (container) {
858
796
  container.style.margin = '0 auto';
859
797
  container.style.paddingTop = '0';
860
798
  };
861
- var applyBtnStyles = function (btn) {
799
+ const applyPageStyles = (page, backgroundImg) => {
800
+ page.style.backgroundImage = `url(${backgroundImg})`;
801
+ page.style.backgroundPosition = '50%';
802
+ page.style.backgroundSize = 'cover';
803
+ page.style.display = 'block';
804
+ page.style.height = '100%';
805
+ };
806
+ const basePage = (pageName, backgroundImg, content) => {
807
+ const result = document.createElement(pageName);
808
+ result.className = 'base-login-page';
809
+ applyPageStyles(result, backgroundImg);
810
+ const section = document.createElement('section');
811
+ applyContainerStyles(section);
812
+ content.forEach(element => section.appendChild(element));
813
+ result.appendChild(section);
814
+ return result;
815
+ };
816
+
817
+ const applyBtnStyles = (btn) => {
862
818
  btn.style.cursor = 'pointer';
863
819
  btn.style.textDecoration = 'underline';
864
820
  btn.style.border = 'none';
@@ -871,31 +827,29 @@ var applyBtnStyles = function (btn) {
871
827
  btn.style.whiteSpace = 'normal';
872
828
  btn.style.font = 'inherit';
873
829
  };
874
- var magicLinkRequestedPage = function (backgroundImg, onReturn) {
875
- var result = document.createElement('magic-link-requested-page');
876
- var section = document.createElement('section');
877
- applyContainerStyles$1(section);
878
- var magicLinkSent = document.createElement('p');
879
- magicLinkSent.id = 'magic-link-sent';
880
- magicLinkSent.textContent = getTranslation(magicLinkSent.id);
881
- magicLinkSent.style.marginBottom = '10px';
882
- var magicLinkEmail = document.createElement('p');
883
- magicLinkEmail.id = 'magic-link-email';
884
- magicLinkEmail.style.fontWeight = '700';
885
- magicLinkEmail.style.marginBottom = '10px';
886
- var magicLinkHowTo = document.createElement('p');
887
- magicLinkHowTo.id = 'magic-link-how-to';
888
- magicLinkHowTo.innerHTML = getTranslation(magicLinkHowTo.id);
889
- magicLinkHowTo.style.padding = '0 30px';
890
- magicLinkHowTo.style.textAlign = 'center';
891
- var btn = document.createElement('button');
830
+ const magicLinkRequestedPage = (backgroundImg, onReturn) => {
831
+ const content = [];
832
+ const sent = document.createElement('p');
833
+ sent.id = 'magic-link-sent';
834
+ sent.textContent = getTranslation(sent.id);
835
+ sent.style.marginBottom = '10px';
836
+ const email = document.createElement('p');
837
+ email.id = 'magic-link-email';
838
+ email.style.fontWeight = '700';
839
+ email.style.marginBottom = '10px';
840
+ const howTo = document.createElement('p');
841
+ howTo.id = 'magic-link-how-to';
842
+ howTo.innerHTML = getTranslation(howTo.id);
843
+ howTo.style.padding = '0 30px';
844
+ howTo.style.textAlign = 'center';
845
+ const btn = document.createElement('button');
892
846
  btn.id = 'email-not-received-btn';
893
- btn.addEventListener('click', function () { return document.body.appendChild(contactUsModal('email-not-sent')); });
847
+ btn.addEventListener('click', () => document.body.appendChild(contactUsModal('email-not-sent')));
894
848
  btn.textContent = getTranslation('magic-link-let-us-know');
895
849
  applyBtnStyles(btn);
896
- var returnLink = document.createElement('a');
850
+ const returnLink = document.createElement('a');
897
851
  returnLink.textContent = getTranslation('return-link');
898
- returnLink.onclick = function () {
852
+ returnLink.onclick = () => {
899
853
  result.remove();
900
854
  onReturn();
901
855
  };
@@ -903,43 +857,72 @@ var magicLinkRequestedPage = function (backgroundImg, onReturn) {
903
857
  returnLink.style.cursor = 'pointer';
904
858
  returnLink.style.fontWeight = '700';
905
859
  returnLink.style.textDecoration = 'underline';
906
- section.append(magicLinkSent, magicLinkEmail, magicLinkHowTo, btn, returnLink);
907
- applyPageStyles$1(result, backgroundImg);
908
- result.appendChild(section);
860
+ content.push(sent, email, howTo, btn, returnLink);
861
+ const result = basePage('magic-link-requested-page', backgroundImg, content);
909
862
  return result;
910
863
  };
911
864
 
912
- var setBackendToken = function (token) {
865
+ const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn) => {
866
+ const content = [];
867
+ const notSent = document.createElement('p');
868
+ notSent.id = 'magic-link-not-sent';
869
+ notSent.textContent = getTranslation(notSent.id);
870
+ notSent.style.marginBottom = '10px';
871
+ const email = document.createElement('p');
872
+ email.id = 'magic-link-email';
873
+ email.style.fontWeight = '700';
874
+ email.style.marginBottom = '10px';
875
+ const info = document.createElement('p');
876
+ info.id = 'magic-link-fail-info';
877
+ info.innerHTML = getTranslation(info.id);
878
+ info.style.padding = '0 30px';
879
+ info.style.textAlign = 'center';
880
+ const back = document.createElement('a');
881
+ back.textContent = getTranslation('return-link');
882
+ back.onclick = () => {
883
+ result.remove();
884
+ onReturn();
885
+ };
886
+ back.style.marginTop = '32px';
887
+ back.style.cursor = 'pointer';
888
+ back.style.fontWeight = '700';
889
+ back.style.textDecoration = 'underline';
890
+ content.push(notSent, email, info, back);
891
+ const result = basePage('unauthorized-magic-link-request-page', backgroundImg, content);
892
+ return result;
893
+ };
894
+
895
+ const setBackendToken = (token) => {
913
896
  // @ts-ignore
914
897
  window.store.backendToken = token;
915
898
  if (token) {
916
899
  localStorage.setItem('token', token);
917
900
  }
918
901
  };
919
- var getBackendToken = function () {
902
+ const getBackendToken = () => {
920
903
  var _a;
921
- var token = (_a = localStorage.getItem('token')) !== null && _a !== void 0 ? _a : '';
904
+ const token = (_a = localStorage.getItem('token')) !== null && _a !== void 0 ? _a : '';
922
905
  // @ts-ignore
923
906
  window.store.backendToken = token;
924
907
  return token;
925
908
  };
926
- var onTokenAcquired = function (token, onUserLogin) {
909
+ const onTokenAcquired = (token, onUserLogin) => {
927
910
  setBackendToken(token);
928
911
  // setSuperToken();
929
912
  onUserLogin();
930
913
  };
931
- var clearSession = function () {
914
+ const clearSession = () => {
932
915
  // onUserChanged(null);
933
916
  localStorage.clear();
934
917
  // @ts-ignore
935
918
  window.store = {};
936
919
  };
937
- var onAuthenticationFailure = function (msg) {
920
+ const onAuthenticationFailure = (msg) => {
938
921
  localStorage.removeItem('token');
939
922
  // displayPage(Page.LOGIN);
940
923
  alert(getTranslation(msg));
941
924
  };
942
- var onAuthentication = function (onUserLogin, user, type) {
925
+ const onAuthentication = (onUserLogin, user, type) => {
943
926
  if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
944
927
  clearSession();
945
928
  }
@@ -952,11 +935,15 @@ var onAuthentication = function (onUserLogin, user, type) {
952
935
  // mixpanelIdentify(user);
953
936
  // checkMixpanel(() => mixpanel.track('Login', { 'Login Type': type }));
954
937
  };
955
- var displayPage = function (clientApp, page) {
956
- Array.from(clientApp.children).forEach(function (el) { return el.remove(); });
938
+ const displayPage = (clientApp, page) => {
939
+ Array.from(clientApp.children).forEach(el => el.remove());
957
940
  clientApp.appendChild(page);
958
941
  };
959
- var initSession = function (clientApp, supportedLoginTypes, onUserLogin, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint) {
942
+ const setJuxEventHandler = () => {
943
+ document.removeEventListener('jux-event', handleJuxEvents);
944
+ document.addEventListener('jux-event', handleJuxEvents);
945
+ };
946
+ const initSession = (clientApp, supportedLoginTypes, onUserLogin, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint) => {
960
947
  // if (startNewDemo()) {
961
948
  // initDemo(setBackendToken, onAuthentication);
962
949
  // return;
@@ -972,25 +959,27 @@ var initSession = function (clientApp, supportedLoginTypes, onUserLogin, backgro
972
959
  window.store.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
973
960
  // @ts-ignore
974
961
  window.store.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
975
- var magicToken = extractTokenFromWindowLocation('magic-link');
976
- if (magicToken) {
977
- var onOpenMagicLink_1 = function () {
978
- openMagicLink(magicToken, function (res) { return onAuthentication(onUserLogin, res, 'Magic Link'); }, function () { return onAuthenticationFailure('unable-magic-login'); });
962
+ // TODO: use jux-events to call commands and queries
963
+ setJuxEventHandler();
964
+ const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
965
+ if (signInToken) {
966
+ const onOpenMagicLink = () => {
967
+ openMagicLink(signInToken, (res) => onAuthentication(onUserLogin, res, 'Magic Link'), () => onAuthenticationFailure('unable-magic-login'));
979
968
  };
980
- var host = extractTokenFromWindowLocation('host');
969
+ const host = extractTokenFromWindowLocation('host');
981
970
  if (host) {
982
971
  // @ts-ignore
983
- window.store.fetchUserBackendUrl({ host: host }, function (backendUrl) {
972
+ window.store.fetchUserBackendUrl({ host }, (backendUrl) => {
984
973
  setBackendUrl(backendUrl);
985
- onOpenMagicLink_1();
974
+ onOpenMagicLink();
986
975
  });
987
976
  return;
988
977
  }
989
- onOpenMagicLink_1();
978
+ onOpenMagicLink();
990
979
  return;
991
980
  }
992
981
  if (getBackendToken()) {
993
- backendGet('profile', function (res) { return onAuthentication(onUserLogin, res, 'Token Authentication'); }, function (_err) { return onAuthenticationFailure('login-failed'); });
982
+ backendGet('profile', null, (res) => onAuthentication(onUserLogin, res, 'Token Authentication'), (_err) => onAuthenticationFailure('login-failed'));
994
983
  return;
995
984
  }
996
985
  displayPage(clientApp, loginPage(clientApp, backgroundImage, onUserLogin, supportedLoginTypes));
@@ -1006,73 +995,65 @@ var initSession = function (clientApp, supportedLoginTypes, onUserLogin, backgro
1006
995
  // validateThirdPartyCookies(initGapi, () => displayPage(Page.LOGIN));
1007
996
  // checkMixpanel(() => mixpanel.track('View Login Page'));
1008
997
  };
1009
- var onMicrosoftSignIn = function (onUserLogin) { return __awaiter(void 0, void 0, void 0, function () {
1010
- var msalConfig, msalInstance, loginRequest, loginResponse, accessToken, err_1;
1011
- return __generator(this, function (_a) {
1012
- switch (_a.label) {
1013
- case 0:
1014
- msalConfig = { auth: { clientId: process.env.MICROSOFT_CLIENT_ID } };
1015
- msalInstance = new msal.PublicClientApplication(msalConfig);
1016
- loginRequest = { scopes: ['user.read'] };
1017
- enableSignInLayout();
1018
- _a.label = 1;
1019
- case 1:
1020
- _a.trys.push([1, 4, , 5]);
1021
- return [4 /*yield*/, msalInstance.loginPopup(loginRequest)];
1022
- case 2:
1023
- loginResponse = _a.sent();
1024
- accessToken = loginResponse.accessToken;
1025
- return [4 /*yield*/, backendGetPromise(getMicrosoftAuthUrl() + accessToken)
1026
- .then(function (res) {
1027
- var token = res.token;
1028
- // @ts-ignore
1029
- window.store.currentUser = res;
1030
- onTokenAcquired(token, onUserLogin);
1031
- })
1032
- .catch(console.error)
1033
- .finally(function () { return disableSignInLayout(); })];
1034
- case 3:
1035
- _a.sent();
1036
- return [3 /*break*/, 5];
1037
- case 4:
1038
- err_1 = _a.sent();
1039
- reportError(err_1);
1040
- disableSignInLayout();
1041
- return [3 /*break*/, 5];
1042
- case 5: return [2 /*return*/];
1043
- }
1044
- });
1045
- }); };
1046
- var onCookieError = function () {
998
+ const onMicrosoftSignIn = (onUserLogin) => __awaiter(void 0, void 0, void 0, function* () {
999
+ const msalConfig = { auth: { clientId: process.env.MICROSOFT_CLIENT_ID } };
1000
+ const msalInstance = new msal.PublicClientApplication(msalConfig);
1001
+ const loginRequest = { scopes: ['user.read'] };
1002
+ enableSignInLayout();
1003
+ try {
1004
+ const loginResponse = yield msalInstance.loginPopup(loginRequest);
1005
+ const { accessToken } = loginResponse;
1006
+ const onSuccess = (res) => {
1007
+ const { token } = res;
1008
+ // @ts-ignore
1009
+ window.store.currentUser = res;
1010
+ onTokenAcquired(token, onUserLogin);
1011
+ disableSignInLayout();
1012
+ };
1013
+ const onError = (err) => {
1014
+ console.error(err);
1015
+ reportError(err);
1016
+ disableSignInLayout();
1017
+ };
1018
+ microsoftLogin(accessToken, onSuccess, onError);
1019
+ }
1020
+ catch (err) {
1021
+ reportError(err);
1022
+ disableSignInLayout();
1023
+ }
1024
+ });
1025
+ const onCookieError = () => {
1047
1026
  disableSignInLayout();
1048
1027
  // warning('cookie-error'); TODO
1049
1028
  return;
1050
1029
  };
1051
- var onGoogleSignIn = function (onUserLogin) {
1052
- validateThirdPartyCookies(function () {
1030
+ const onGoogleSignIn = (onUserLogin) => {
1031
+ validateThirdPartyCookies(() => {
1053
1032
  enableSignInLayout();
1054
1033
  authSignIn(onUserLogin);
1055
1034
  }, onCookieError);
1056
1035
  };
1057
- var handleMagicLinkRequest = function (token, onReturn, backgroundImage, currentPage, clientBody, email) {
1058
- if (email === void 0) { email = ''; }
1036
+ const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
1059
1037
  if (!email) {
1060
- var mailMagic = document.querySelector('#mail-magic');
1038
+ const mailMagic = document.querySelector('#mail-magic');
1061
1039
  email = mailMagic.value;
1062
1040
  }
1063
- var payload = { email: email, token: token };
1064
- var onRequestMagicLink = function () {
1065
- requestMagicLink(payload, function (_res) {
1041
+ const payload = { email, token };
1042
+ const onRequestMagicLink = () => {
1043
+ const onResponse = (page) => {
1066
1044
  currentPage.remove();
1067
- clientBody.appendChild(magicLinkRequestedPage(backgroundImage, onReturn));
1068
- var magicLinkEmail = document.querySelector('#magic-link-email');
1045
+ clientBody.appendChild(page);
1046
+ const magicLinkEmail = page.querySelector('#magic-link-email');
1069
1047
  magicLinkEmail.textContent = email;
1070
- });
1048
+ };
1049
+ const onSuccess = () => onResponse(magicLinkRequestedPage(backgroundImage, onReturn));
1050
+ const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
1051
+ requestMagicLink(payload, onSuccess, onUnauthorized);
1071
1052
  };
1072
1053
  // @ts-ignore
1073
1054
  if (window.store.fetchUserBackendUrl) {
1074
1055
  // @ts-ignore
1075
- window.store.fetchUserBackendUrl({ email: email }, function (backendUrl) {
1056
+ window.store.fetchUserBackendUrl({ email }, (backendUrl) => {
1076
1057
  setBackendUrl(backendUrl);
1077
1058
  onRequestMagicLink();
1078
1059
  });
@@ -1081,118 +1062,101 @@ var handleMagicLinkRequest = function (token, onReturn, backgroundImage, current
1081
1062
  onRequestMagicLink();
1082
1063
  };
1083
1064
 
1084
- var socialLoginModal = function (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) {
1085
- var result = document.createElement('social-login-modal');
1086
- var email = document.createElement('p');
1087
- email.textContent = "\"".concat(userEmail, "\"");
1088
- var msg = document.createElement('social-login-msg');
1065
+ const socialLoginModal = (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) => {
1066
+ const result = document.createElement('social-login-modal');
1067
+ const email = document.createElement('p');
1068
+ email.textContent = `"${userEmail}"`;
1069
+ const msg = document.createElement('social-login-msg');
1089
1070
  msg.textContent = getTranslation('social-login-recommendation') + mailExchanger + '.' + getTranslation('social-login-advantage');
1090
- var body = document.createElement('social-login-body');
1091
- var socialLoginBtn = mailExchanger === 'Microsoft' ?
1092
- loginButton('Microsoft', function () { return onMicrosoftSignIn(onUserLogin); }) :
1093
- loginButton('Google', function () { return onGoogleSignIn(onUserLogin); });
1094
- var proceedMagicLinkRequest = document.createElement('a');
1071
+ const body = document.createElement('social-login-body');
1072
+ const socialLoginBtn = mailExchanger === 'Microsoft' ?
1073
+ loginButton('Microsoft', () => onMicrosoftSignIn(onUserLogin)) :
1074
+ loginButton('Google', () => onGoogleSignIn(onUserLogin));
1075
+ const proceedMagicLinkRequest = document.createElement('a');
1095
1076
  proceedMagicLinkRequest.textContent = getTranslation('proceed-magic-link-request');
1096
- proceedMagicLinkRequest.addEventListener('click', function () {
1077
+ proceedMagicLinkRequest.addEventListener('click', () => {
1097
1078
  handleMagicLinkRequest(token, onReturn, backgroundImage, currentPage, clientBody, userEmail);
1098
1079
  closeMagicLinkModal();
1099
1080
  result.remove();
1100
1081
  });
1101
1082
  body.append(email, msg, socialLoginBtn, proceedMagicLinkRequest);
1102
- var modal = juxModal(getTranslation("using-".concat(mailExchanger.toLowerCase(), "-email")), [], '', false, false, body, '', '', function () { return result.remove(); });
1083
+ const modal = juxModal(getTranslation(`using-${mailExchanger.toLowerCase()}-email`), [], '', false, false, body, '', '', () => result.remove());
1103
1084
  modal.setAttribute('data-cy', 'social-login-modal');
1104
1085
  result.appendChild(modal);
1105
- var wrapper = modal.querySelector('modal-wrapper');
1086
+ const wrapper = modal.querySelector('modal-wrapper');
1106
1087
  wrapper.style.maxWidth = '360px';
1107
1088
  wrapper.style.width = '100%';
1108
1089
  return result;
1109
1090
  };
1110
1091
 
1111
- var isValidEmail = function (email) {
1112
- var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
1092
+ const isValidEmail = (email) => {
1093
+ const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
1113
1094
  return re.test(email);
1114
1095
  };
1115
1096
 
1116
- var recommendSocialLogin = function (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) {
1097
+ const recommendSocialLogin = (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) => {
1117
1098
  var _a;
1118
1099
  (_a = document.querySelector('magic-link-modal')) === null || _a === void 0 ? void 0 : _a.remove();
1119
1100
  document.body.appendChild(socialLoginModal(userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal));
1120
1101
  };
1121
- var hasProvider = function (data, provider) {
1122
- return data.some(function (entry) { return entry.includes(provider); });
1123
- };
1124
- var getMailExchanger = function (domainName) { return __awaiter(void 0, void 0, void 0, function () {
1125
- var data;
1126
- return __generator(this, function (_a) {
1127
- switch (_a.label) {
1128
- case 0: return [4 /*yield*/, getMXData(domainName)];
1129
- case 1:
1130
- data = _a.sent();
1131
- if (!data) {
1132
- return [2 /*return*/, null];
1133
- }
1134
- if (hasProvider(data, 'outlook.com')) {
1135
- return [2 /*return*/, 'Microsoft'];
1136
- }
1137
- if (hasProvider(data, 'google.com')) {
1138
- return [2 /*return*/, 'Google'];
1139
- }
1140
- return [2 /*return*/, null];
1141
- }
1142
- });
1143
- }); };
1144
- var onMagicLinkRequest = function (token, input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) { return __awaiter(void 0, void 0, void 0, function () {
1145
- var email, domain, mailExchanger, supportedMailExchanger;
1146
- return __generator(this, function (_a) {
1147
- switch (_a.label) {
1148
- case 0:
1149
- email = input.value;
1150
- if (!email.includes('-test@') && !token) {
1151
- console.error('invalid-captcha-response');
1152
- // logError('invalid-captcha-response');
1153
- return [2 /*return*/];
1154
- }
1155
- if (!isValidEmail(email)) return [3 /*break*/, 2];
1156
- domain = email.split('@')[1] || '';
1157
- return [4 /*yield*/, getMailExchanger(domain)];
1158
- case 1:
1159
- mailExchanger = _a.sent();
1160
- supportedMailExchanger = mailExchanger !== null;
1161
- if (supportedMailExchanger && loginTypes.includes(mailExchanger)) {
1162
- recommendSocialLogin(email, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal);
1163
- return [2 /*return*/];
1164
- }
1165
- _a.label = 2;
1166
- case 2:
1167
- handleMagicLinkRequest(token, onReturn, backgroundImage, currentPage, clientBody);
1168
- closeMagicLinkModal();
1169
- return [2 /*return*/];
1102
+ const hasProvider = (data, provider) => {
1103
+ return data.some((entry) => entry.includes(provider));
1104
+ };
1105
+ const getMailExchanger = (domainName) => __awaiter(void 0, void 0, void 0, function* () {
1106
+ const data = yield getMXData(domainName);
1107
+ if (!data) {
1108
+ return null;
1109
+ }
1110
+ if (hasProvider(data, 'outlook.com')) {
1111
+ return 'Microsoft';
1112
+ }
1113
+ if (hasProvider(data, 'google.com')) {
1114
+ return 'Google';
1115
+ }
1116
+ return null;
1117
+ });
1118
+ const onMagicLinkRequest = (token, input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) => __awaiter(void 0, void 0, void 0, function* () {
1119
+ const email = input.value;
1120
+ if (!email.includes('-test@') && !token) {
1121
+ console.error('invalid-captcha-response');
1122
+ // logError('invalid-captcha-response');
1123
+ return;
1124
+ }
1125
+ if (isValidEmail(email)) {
1126
+ const domain = email.split('@')[1] || '';
1127
+ const mailExchanger = yield getMailExchanger(domain);
1128
+ const supportedMailExchanger = mailExchanger !== null;
1129
+ if (supportedMailExchanger && loginTypes.includes(mailExchanger)) {
1130
+ recommendSocialLogin(email, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal);
1131
+ return;
1170
1132
  }
1171
- });
1172
- }); };
1173
- var applyMagicEmailFieldStyle = function (el) {
1133
+ }
1134
+ handleMagicLinkRequest(token, onReturn, backgroundImage, currentPage, clientBody);
1135
+ closeMagicLinkModal();
1136
+ });
1137
+ const applyMagicEmailFieldStyle = (el) => {
1174
1138
  el.style.display = 'flex';
1175
1139
  el.style.flexFlow = 'column';
1176
1140
  el.style.marginTop = '8px';
1177
1141
  el.style.rowGap = '8px';
1178
1142
  el.style.width = '100%';
1179
1143
  };
1180
- var applyInputStyle = function (input) {
1181
- input.style.border = "1px solid ".concat(juxDarkGrey);
1144
+ const applyInputStyle = (input) => {
1145
+ input.style.border = `1px solid ${juxDarkGrey}`;
1182
1146
  input.style.maxWidth = '390px';
1183
1147
  input.style.padding = '10px';
1184
1148
  input.style.width = '100%';
1185
1149
  input.style.backgroundColor = juxWhite;
1186
1150
  input.style.borderRadius = '8px';
1187
- input.style.boxShadow = "inset 0 2px 3px ".concat(juxDimmedDarkGrey);
1151
+ input.style.boxShadow = `inset 0 2px 3px ${juxDimmedDarkGrey}`;
1188
1152
  input.style.height = '40px';
1189
1153
  input.style.whiteSpace = 'pre-line';
1190
1154
  input.style.boxSizing = 'border-box';
1191
1155
  };
1192
- var applyBtnStyle = function (btn) {
1156
+ const applyBtnStyle = (btn) => {
1193
1157
  btn.style.alignSelf = 'flex-end';
1194
1158
  btn.style.backgroundColor = juxLightGreen;
1195
- btn.style.border = "2px solid ".concat(juxLightGreen);
1159
+ btn.style.border = `2px solid ${juxLightGreen}`;
1196
1160
  btn.style.borderRadius = '8px';
1197
1161
  btn.style.color = juxWhite;
1198
1162
  btn.style.cursor = 'pointer';
@@ -1204,118 +1168,95 @@ var applyBtnStyle = function (btn) {
1204
1168
  btn.style.padding = '10px 16px';
1205
1169
  btn.style.position = 'relative';
1206
1170
  };
1207
- var magicEmailField = function (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) {
1208
- var result = document.createElement('magic-email-field');
1171
+ const magicEmailField = (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) => {
1172
+ const result = document.createElement('magic-email-field');
1209
1173
  applyMagicEmailFieldStyle(result);
1210
- var captcha = googleCaptcha();
1211
- var input = document.createElement('input');
1174
+ const captcha = googleCaptcha();
1175
+ const input = document.createElement('input');
1212
1176
  input.id = 'mail-magic';
1213
1177
  input.type = 'text';
1214
1178
  input.className = 'textfield';
1215
1179
  input.placeholder = 'e-mail';
1216
1180
  applyInputStyle(input);
1217
- input.addEventListener('keydown', function (ev) {
1181
+ input.addEventListener('keydown', (ev) => {
1218
1182
  if (ev.key === 'Enter') {
1219
1183
  onMagicLinkRequest(captcha.getAttribute('token'), input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes);
1220
1184
  }
1221
1185
  });
1222
- var btn = document.createElement('button');
1186
+ const btn = document.createElement('button');
1223
1187
  applyBtnStyle(btn);
1224
1188
  btn.id = 'send-magic';
1225
1189
  btn.className = 'primary-button';
1226
- btn.addEventListener('click', function (_ev) { return onMagicLinkRequest(captcha.getAttribute('token'), input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes); });
1190
+ btn.addEventListener('click', (_ev) => onMagicLinkRequest(captcha.getAttribute('token'), input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes));
1227
1191
  btn.textContent = getTranslation('send-magic');
1228
1192
  result.append(input, captcha, btn);
1229
1193
  return result;
1230
1194
  };
1231
1195
 
1232
- var magicLinkModal = function (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, loginTypes) {
1233
- var result = document.createElement('magic-link-modal');
1234
- var subtitle = document.createElement('magic-link-request-subtitle');
1196
+ const magicLinkModal = (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, loginTypes) => {
1197
+ const result = document.createElement('magic-link-modal');
1198
+ const subtitle = document.createElement('magic-link-request-subtitle');
1235
1199
  subtitle.style.fontSize = '14px';
1236
1200
  subtitle.textContent = getTranslation('magic-link-request-subtitle');
1237
- var body = document.createElement('magic-link-request-body');
1238
- body.append(subtitle, magicEmailField(onUserLogin, onReturn, backgroundImage, currentPage, clientBody, function () { return result.remove(); }, loginTypes));
1239
- var modal = juxModal(getTranslation('magic-link-request-title'), [], '', false, false, body, '', '', function () { return result.remove(); });
1201
+ const body = document.createElement('magic-link-request-body');
1202
+ body.append(subtitle, magicEmailField(onUserLogin, onReturn, backgroundImage, currentPage, clientBody, () => result.remove(), loginTypes));
1203
+ const modal = juxModal(getTranslation('magic-link-request-title'), [], '', false, false, body, '', '', () => result.remove());
1240
1204
  modal.setAttribute('data-cy', 'magic-link-modal');
1241
1205
  result.appendChild(modal);
1242
- var wrapper = modal.querySelector('modal-wrapper');
1206
+ const wrapper = modal.querySelector('modal-wrapper');
1243
1207
  wrapper.style.maxWidth = '360px';
1244
1208
  wrapper.style.width = '100%';
1245
1209
  return result;
1246
1210
  };
1247
1211
 
1248
- var applyContainerStyles = function (container) {
1249
- container.style.backgroundColor = '#ffffffdd';
1250
- container.style.borderRadius = '16px';
1251
- container.style.inset = '50% 50% 50% 0';
1252
- container.style.position = 'relative';
1253
- container.style.transform = 'translateY(-50%)';
1254
- container.style.width = '620px';
1255
- container.style.alignItems = 'center';
1256
- container.style.display = 'flex';
1257
- container.style.flexDirection = 'column';
1258
- container.style.fontSize = '16px';
1259
- container.style.height = '100%';
1260
- container.style.justifyContent = 'center';
1261
- container.style.margin = '0 auto';
1262
- container.style.paddingTop = '0';
1263
- };
1264
- var applyPageStyles = function (page) {
1265
- page.style.backgroundPosition = '50%';
1266
- page.style.backgroundSize = 'cover';
1267
- page.style.display = 'block';
1268
- page.style.height = '100%';
1269
- };
1270
- var onEmailLoginRequest = function (clientApp, loginPage, onUserLogin, backgroundImage, loginTypes) {
1271
- var onReturn = function () { return clientApp.appendChild(loginPage); };
1212
+ const onEmailLoginRequest = (clientApp, loginPage, onUserLogin, backgroundImage, loginTypes) => {
1213
+ const onReturn = () => clientApp.appendChild(loginPage);
1272
1214
  loginPage.appendChild(magicLinkModal(onUserLogin, onReturn, backgroundImage, loginPage, clientApp, loginTypes));
1273
1215
  };
1274
- var appendLoginTypes = function (loginPage, section, clientApp, onUserLogin, loginTypes, backgroundImg) {
1216
+ const appendLoginTypes = (loginPage, section, clientApp, onUserLogin, loginTypes, backgroundImg) => {
1275
1217
  if (loginTypes.includes('Google')) {
1276
- section.appendChild(loginButton('Google', function () { return onGoogleSignIn(onUserLogin); }));
1218
+ section.appendChild(loginButton('Google', () => onGoogleSignIn(onUserLogin)));
1277
1219
  }
1278
1220
  if (loginTypes.includes('Microsoft')) {
1279
- section.appendChild(loginButton('Microsoft', function () { return onMicrosoftSignIn(onUserLogin); }));
1221
+ section.appendChild(loginButton('Microsoft', () => onMicrosoftSignIn(onUserLogin)));
1280
1222
  }
1281
1223
  if (loginTypes.includes('Linkedin')) {
1282
- section.appendChild(loginButton('LinkedIn', function () { return console.log('login with Linkedin'); }));
1224
+ section.appendChild(loginButton('LinkedIn', () => console.log('login with Linkedin')));
1283
1225
  }
1284
1226
  if (loginTypes.includes('Email')) {
1285
- section.appendChild(loginButton('Email', function () { return onEmailLoginRequest(clientApp, loginPage, onUserLogin, backgroundImg, loginTypes); }));
1227
+ section.appendChild(loginButton('Email', () => onEmailLoginRequest(clientApp, loginPage, onUserLogin, backgroundImg, loginTypes)));
1286
1228
  }
1287
1229
  };
1288
- var loginPage = function (clientApp, backgroundImg, onUserLogin, loginTypes) {
1289
- var result = document.createElement('login-page');
1290
- applyPageStyles(result);
1291
- var section = document.createElement('section');
1292
- applyContainerStyles(section);
1293
- var salutation = document.createElement('sign-in-salutation');
1230
+ const loginPage = (clientApp, backgroundImg, onUserLogin, loginTypes) => {
1231
+ const content = [];
1232
+ const salutation = document.createElement('sign-in-salutation');
1294
1233
  salutation.textContent = getTranslation('sign-in-salutation');
1295
- var explanation = document.createElement('sign-in-explanation');
1234
+ const explanation = document.createElement('sign-in-explanation');
1296
1235
  explanation.textContent = getTranslation('sign-in-explanation');
1297
- var msg = document.createElement('sign-in-msg');
1236
+ const msg = document.createElement('sign-in-msg');
1298
1237
  msg.textContent = getTranslation('sign-in-msg-general');
1299
- result.style.backgroundImage = "url(".concat(backgroundImg, ")");
1300
- section.append(salutation, explanation, msg);
1238
+ content.push(salutation, explanation, msg);
1239
+ const result = basePage('login-page', backgroundImg, content);
1240
+ const section = result.querySelector('section');
1301
1241
  appendLoginTypes(result, section, clientApp, onUserLogin, loginTypes, backgroundImg);
1302
- result.appendChild(section);
1303
1242
  return result;
1304
1243
  };
1305
1244
 
1306
- var Query = /** @class */ (function (_super) {
1307
- __extends(Query, _super);
1308
- function Query(endpoint, onResult, params, onError) {
1309
- var _this = _super.call(this, endpoint) || this;
1310
- _this.params = params;
1311
- _this.onResult = onResult;
1312
- _this.onError = onError;
1313
- return _this;
1245
+ class JuxEvent extends Event {
1246
+ constructor(method, endpoint, onResult, params, onError) {
1247
+ super('jux-event', { bubbles: true, cancelable: true, composed: true });
1248
+ this.method = method;
1249
+ this.endpoint = endpoint;
1250
+ this.onResult = onResult;
1251
+ this.params = params;
1252
+ this.onError = onError;
1314
1253
  }
1315
- return Query;
1316
- }(Event));
1317
- var query = function (element, endpoint, onResult, params, onError) {
1318
- element.dispatchEvent(new Query(endpoint, onResult, params, onError));
1254
+ }
1255
+ const query = (element, endpoint, onResult, params, onError) => {
1256
+ element.dispatchEvent(new JuxEvent('GET', endpoint, onResult, params, onError));
1257
+ };
1258
+ const command = (element, endpoint, onResult, params, onError) => {
1259
+ element.dispatchEvent(new JuxEvent('POST', endpoint, onResult, params, onError));
1319
1260
  };
1320
1261
 
1321
- export { chosenLanguage, getTranslation, handleMagicLinkRequest, initLanguage, initSession, loginButton, loginPage, magicLinkModal, onMicrosoftSignIn, query, reloadWithLanguageOverride, requestMagicLink };
1262
+ export { chosenLanguage, command, getTranslation, handleMagicLinkRequest, initLanguage, initSession, loginButton, loginPage, magicLinkModal, onMicrosoftSignIn, query, reloadWithLanguageOverride, requestMagicLink };