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