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