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