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