@klauswuestefeld/jux-web 2024.2.8 → 2024.3.28
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 +11 -11
- package/dist/captcha/google-captcha.d.ts +1 -1
- package/dist/contact-us/contact-field.d.ts +1 -1
- package/dist/contact-us/contact-us-modal.d.ts +1 -1
- package/dist/jux/jux-event.d.ts +12 -10
- package/dist/jux/language.d.ts +4 -4
- package/dist/jux-modal.d.ts +1 -1
- package/dist/jux-web.js +1227 -1180
- package/dist/login/auth.d.ts +2 -2
- package/dist/login/base-page.d.ts +1 -1
- package/dist/login/login-button.d.ts +1 -1
- package/dist/login/login-page.d.ts +1 -1
- package/dist/login/magic-email-field.d.ts +2 -2
- package/dist/login/magic-link-modal.d.ts +1 -1
- package/dist/login/magic-link-requested-page.d.ts +1 -1
- package/dist/login/session.d.ts +6 -6
- package/dist/login/social-login.d.ts +1 -1
- package/dist/login/unauthorized-magic-link-request-page.d.ts +1 -1
- package/dist/login/utils/constants.d.ts +1 -1
- package/dist/login/utils/cookies.d.ts +1 -1
- package/dist/login/utils/layout-changes.d.ts +2 -2
- package/dist/login/utils/string.d.ts +1 -1
- package/dist/login/utils/token.d.ts +1 -1
- package/dist/main.d.ts +12 -12
- package/dist/main.esm.js +1227 -1180
- package/dist/main.js +1227 -1180
- package/dist/style-constants.d.ts +6 -6
- package/package.json +2 -2
package/dist/jux-web.js
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
1
|
var juxWeb = (function (exports) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const getBrowserLanguage = () => {
|
|
5
|
-
const result = (navigator.languages && navigator.languages.length)
|
|
6
|
-
? navigator.languages[0]
|
|
7
|
-
: navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en';
|
|
8
|
-
return result.substring(0, 2);
|
|
9
|
-
};
|
|
10
|
-
const OVERRIDE_KEY = 'jux.language.override';
|
|
11
|
-
let translations = {};
|
|
12
|
-
const chosenLanguage = localStorage.getItem(OVERRIDE_KEY) || getBrowserLanguage();
|
|
13
|
-
const reloadWithLanguageOverride = (lang) => {
|
|
14
|
-
localStorage.setItem(OVERRIDE_KEY, lang);
|
|
15
|
-
location.reload();
|
|
16
|
-
};
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
const getTranslation = (k) => translations[k] || k;
|
|
19
|
-
const initLanguage = (translations_, defaultLanguage = 'en') => {
|
|
20
|
-
translations = translations_[chosenLanguage] || translations_[defaultLanguage];
|
|
21
|
-
document.title = getTranslation('title');
|
|
22
|
-
document.documentElement.lang = translations_[chosenLanguage] ? chosenLanguage : defaultLanguage;
|
|
4
|
+
const getBrowserLanguage = () => {
|
|
5
|
+
const result = (navigator.languages && navigator.languages.length)
|
|
6
|
+
? navigator.languages[0]
|
|
7
|
+
: navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en';
|
|
8
|
+
return result.substring(0, 2);
|
|
9
|
+
};
|
|
10
|
+
const OVERRIDE_KEY = 'jux.language.override';
|
|
11
|
+
let translations = {};
|
|
12
|
+
const chosenLanguage = localStorage.getItem(OVERRIDE_KEY) || getBrowserLanguage();
|
|
13
|
+
const reloadWithLanguageOverride = (lang) => {
|
|
14
|
+
localStorage.setItem(OVERRIDE_KEY, lang);
|
|
15
|
+
location.reload();
|
|
16
|
+
};
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const getTranslation = (k) => translations[k] || k;
|
|
19
|
+
const initLanguage = (translations_, defaultLanguage = 'en') => {
|
|
20
|
+
translations = translations_[chosenLanguage] || translations_[defaultLanguage];
|
|
21
|
+
document.title = getTranslation('title');
|
|
22
|
+
document.documentElement.lang = translations_[chosenLanguage] ? chosenLanguage : defaultLanguage;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const THRESHOLD_WIDTH = 640;
|
|
26
26
|
|
|
27
|
-
const 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
|
-
const applyComponentStyle = (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
|
-
const applyLabelStyle = (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
|
-
const loginButton = (type, fn) => {
|
|
59
|
-
const loweredCasedType = type.toLowerCase();
|
|
60
|
-
const result = document.createElement('login-button');
|
|
61
|
-
applyComponentStyle(result);
|
|
62
|
-
result.tabIndex = 0;
|
|
63
|
-
result.setAttribute('data-cy', `${loweredCasedType}-button`);
|
|
64
|
-
const 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
|
-
const label = document.createElement('login-label');
|
|
75
|
-
label.textContent = window.innerWidth <= THRESHOLD_WIDTH ? type : getTranslation(`${loweredCasedType}-label`);
|
|
76
|
-
applyLabelStyle(label);
|
|
77
|
-
result.append(icon, label);
|
|
78
|
-
result.addEventListener('click', fn);
|
|
79
|
-
result.addEventListener('mouseenter', () => {
|
|
80
|
-
result.style.cursor = 'pointer';
|
|
81
|
-
result.style.boxShadow = '0 0 6px #808080';
|
|
82
|
-
});
|
|
83
|
-
result.addEventListener('mouseleave', () => {
|
|
84
|
-
result.style.cursor = 'auto';
|
|
85
|
-
result.style.boxShadow = '1px 1px 1px grey';
|
|
86
|
-
});
|
|
87
|
-
return result;
|
|
27
|
+
const 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
|
+
const applyComponentStyle = (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
|
+
const applyLabelStyle = (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
|
+
const loginButton = (type, fn) => {
|
|
59
|
+
const loweredCasedType = type.toLowerCase();
|
|
60
|
+
const result = document.createElement('login-button');
|
|
61
|
+
applyComponentStyle(result);
|
|
62
|
+
result.tabIndex = 0;
|
|
63
|
+
result.setAttribute('data-cy', `${loweredCasedType}-button`);
|
|
64
|
+
const 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
|
+
const label = document.createElement('login-label');
|
|
75
|
+
label.textContent = window.innerWidth <= THRESHOLD_WIDTH ? type : getTranslation(`${loweredCasedType}-label`);
|
|
76
|
+
applyLabelStyle(label);
|
|
77
|
+
result.append(icon, label);
|
|
78
|
+
result.addEventListener('click', fn);
|
|
79
|
+
result.addEventListener('mouseenter', () => {
|
|
80
|
+
result.style.cursor = 'pointer';
|
|
81
|
+
result.style.boxShadow = '0 0 6px #808080';
|
|
82
|
+
});
|
|
83
|
+
result.addEventListener('mouseleave', () => {
|
|
84
|
+
result.style.cursor = 'auto';
|
|
85
|
+
result.style.boxShadow = '1px 1px 1px grey';
|
|
86
|
+
});
|
|
87
|
+
return result;
|
|
88
88
|
};
|
|
89
89
|
|
|
90
90
|
/******************************************************************************
|
|
@@ -112,200 +112,245 @@ var juxWeb = (function (exports) {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
const extractTokenFromWindowLocation = (tokenParam, additionalParam = '') => {
|
|
116
|
-
if (!tokenParam)
|
|
117
|
-
return;
|
|
118
|
-
let token = '';
|
|
119
|
-
const tokenParameterName = `${tokenParam}=`;
|
|
120
|
-
const search = window.location.search;
|
|
121
|
-
const tokenParameterIndex = search.indexOf(tokenParameterName);
|
|
122
|
-
if (tokenParameterIndex !== -1) {
|
|
123
|
-
const tokenParameterNameLength = tokenParameterName.length;
|
|
124
|
-
const leadingAmpersandIndex = search.indexOf('&', tokenParameterIndex);
|
|
125
|
-
let searchWithoutToken = search;
|
|
126
|
-
token = search.substring(tokenParameterIndex + tokenParameterNameLength);
|
|
127
|
-
if (leadingAmpersandIndex !== -1) {
|
|
128
|
-
token = search.substring(tokenParameterIndex + tokenParameterNameLength, leadingAmpersandIndex);
|
|
129
|
-
searchWithoutToken = searchWithoutToken.slice(0, leadingAmpersandIndex) + searchWithoutToken.slice(leadingAmpersandIndex + 1);
|
|
130
|
-
}
|
|
131
|
-
searchWithoutToken = searchWithoutToken.replace(`${tokenParam}=` + token, '')
|
|
132
|
-
.replace(additionalParam, '')
|
|
133
|
-
.replace('\&cypress=true', '');
|
|
134
|
-
if (searchWithoutToken === '?') {
|
|
135
|
-
searchWithoutToken = '';
|
|
136
|
-
}
|
|
137
|
-
window.history.replaceState({}, document.title, window.location.pathname + searchWithoutToken);
|
|
138
|
-
}
|
|
139
|
-
return token;
|
|
115
|
+
const extractTokenFromWindowLocation = (tokenParam, additionalParam = '') => {
|
|
116
|
+
if (!tokenParam)
|
|
117
|
+
return;
|
|
118
|
+
let token = '';
|
|
119
|
+
const tokenParameterName = `${tokenParam}=`;
|
|
120
|
+
const search = window.location.search;
|
|
121
|
+
const tokenParameterIndex = search.indexOf(tokenParameterName);
|
|
122
|
+
if (tokenParameterIndex !== -1) {
|
|
123
|
+
const tokenParameterNameLength = tokenParameterName.length;
|
|
124
|
+
const leadingAmpersandIndex = search.indexOf('&', tokenParameterIndex);
|
|
125
|
+
let searchWithoutToken = search;
|
|
126
|
+
token = search.substring(tokenParameterIndex + tokenParameterNameLength);
|
|
127
|
+
if (leadingAmpersandIndex !== -1) {
|
|
128
|
+
token = search.substring(tokenParameterIndex + tokenParameterNameLength, leadingAmpersandIndex);
|
|
129
|
+
searchWithoutToken = searchWithoutToken.slice(0, leadingAmpersandIndex) + searchWithoutToken.slice(leadingAmpersandIndex + 1);
|
|
130
|
+
}
|
|
131
|
+
searchWithoutToken = searchWithoutToken.replace(`${tokenParam}=` + token, '')
|
|
132
|
+
.replace(additionalParam, '')
|
|
133
|
+
.replace('\&cypress=true', '');
|
|
134
|
+
if (searchWithoutToken === '?') {
|
|
135
|
+
searchWithoutToken = '';
|
|
136
|
+
}
|
|
137
|
+
window.history.replaceState({}, document.title, window.location.pathname + searchWithoutToken);
|
|
138
|
+
}
|
|
139
|
+
return token;
|
|
140
140
|
};
|
|
141
141
|
|
|
142
|
-
const setBackendUrl = (backendUrl) => localStorage.setItem('backend-url', backendUrl);
|
|
143
|
-
//@ts-ignore
|
|
144
|
-
const getBackendUrl = () => process.env.BACKEND_URL || localStorage.getItem('backend-url');
|
|
145
|
-
//@ts-ignore
|
|
146
|
-
const getSecondaryBackendUrl = () => process.env.STAGING_BACKEND_URL || getBackendUrl();
|
|
147
|
-
const getApiUrl = () => getBackendUrl() + 'api/';
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
spinner.style.
|
|
173
|
-
spinner.style.
|
|
174
|
-
spinner.style.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
spinner
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
document.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
if (requestType === '
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
142
|
+
const setBackendUrl = (backendUrl) => localStorage.setItem('backend-url', backendUrl);
|
|
143
|
+
//@ts-ignore
|
|
144
|
+
const getBackendUrl = () => process.env.BACKEND_URL || localStorage.getItem('backend-url');
|
|
145
|
+
//@ts-ignore
|
|
146
|
+
const getSecondaryBackendUrl = () => process.env.STAGING_BACKEND_URL || getBackendUrl();
|
|
147
|
+
const getApiUrl = () => getBackendUrl() + 'api/';
|
|
148
|
+
const getMagicAuthUrl = () => {
|
|
149
|
+
var _a;
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === null || _a === void 0 ? void 0 : _a.magicLinkAuthEndpoint) || 'auth-magic';
|
|
152
|
+
return getBackendUrl() + endpoint + '?token=';
|
|
153
|
+
};
|
|
154
|
+
const getMagicAuthReqUrl = () => {
|
|
155
|
+
var _a;
|
|
156
|
+
// @ts-ignore
|
|
157
|
+
const endpoint = ((_a = window === null || window === void 0 ? void 0 : window.store) === null || _a === void 0 ? void 0 : _a.magicLinkRequestEndpoint) || 'magic-link-request';
|
|
158
|
+
return getBackendUrl() + endpoint + '?email=';
|
|
159
|
+
};
|
|
160
|
+
// TODO: use jux-events to call commands and queries inside jux-web library
|
|
161
|
+
const handleJuxEvent = (ev) => {
|
|
162
|
+
const { requestType, endpoint, onResult, params, onError, onRedirect } = ev;
|
|
163
|
+
const onJsonResponse = (res) => onResult ? onResult(res) : null;
|
|
164
|
+
const onHelpMessage = (err) => onError ? onError(err) : null;
|
|
165
|
+
post(endpoint, params, onJsonResponse, onHelpMessage, onRedirect, requestType);
|
|
166
|
+
};
|
|
167
|
+
const applySpinnerStyle = (spinner) => {
|
|
168
|
+
spinner.style.position = 'fixed';
|
|
169
|
+
spinner.style.top = '50%';
|
|
170
|
+
spinner.style.zIndex = '2147483647';
|
|
171
|
+
spinner.style.border = '8px solid #bababa';
|
|
172
|
+
spinner.style.borderTopColor = '#171f1c';
|
|
173
|
+
spinner.style.height = '80px';
|
|
174
|
+
spinner.style.width = '80px';
|
|
175
|
+
};
|
|
176
|
+
const renderOverlay = () => {
|
|
177
|
+
const overlay = document.createElement('reconnect-overlay');
|
|
178
|
+
const spinner = document.createElement('loading-spinner');
|
|
179
|
+
spinner.className = 'reconnect-spinner';
|
|
180
|
+
applySpinnerStyle(spinner);
|
|
181
|
+
document.body.append(overlay, spinner);
|
|
182
|
+
};
|
|
183
|
+
const removeOverlay = () => {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
(_a = document.querySelector('reconnect-overlay')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
186
|
+
(_b = document.querySelector('.reconnect-spinner')) === null || _b === void 0 ? void 0 : _b.remove();
|
|
187
|
+
};
|
|
188
|
+
const defaultHandleUnauthorized = () => {
|
|
189
|
+
localStorage.removeItem('token');
|
|
190
|
+
alert(getTranslation('session-expired-msg'));
|
|
191
|
+
location.reload();
|
|
192
|
+
// googleAuthSignOut(); TODO
|
|
193
|
+
};
|
|
194
|
+
let requestRunning = false;
|
|
195
|
+
const maxRetries = 20;
|
|
196
|
+
const backendRequest = (url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1) => __awaiter$2(void 0, [url_1, options_1, onSuccess_1, onError_1, onRedirect_1, ...args_1], void 0, function* (url, options, onSuccess, onError, onRedirect, requestType = 'query', handleUnauthorized = defaultHandleUnauthorized, retrial = false, retrialNum = 0) {
|
|
197
|
+
if (requestRunning && !retrial) { // only allow one request at a time
|
|
198
|
+
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, false), 300);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
// @ts-ignore
|
|
202
|
+
const backendToken = window.store.backendToken;
|
|
203
|
+
if (backendToken) {
|
|
204
|
+
if (!options.headers)
|
|
205
|
+
options.headers = {};
|
|
206
|
+
options.headers.auth = backendToken;
|
|
207
|
+
}
|
|
208
|
+
let response;
|
|
209
|
+
requestRunning = true;
|
|
210
|
+
const requestInit = Object.assign({}, options);
|
|
211
|
+
if (requestType === 'query') {
|
|
212
|
+
requestInit.signal = AbortSignal.timeout(6000);
|
|
213
|
+
}
|
|
214
|
+
if (onRedirect)
|
|
215
|
+
requestInit.redirect = 'manual'; // Treat redirects manually instead of following them automatically.
|
|
216
|
+
try {
|
|
217
|
+
response = yield fetch(url, requestInit);
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
// network errors
|
|
221
|
+
if (requestType === 'command') {
|
|
222
|
+
// Do not retry applying command if it fails for the first time.
|
|
223
|
+
onError('There was an error performing your request. Please try again later.');
|
|
224
|
+
requestRunning = false;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (retrialNum > maxRetries) {
|
|
228
|
+
removeOverlay();
|
|
229
|
+
requestRunning = false;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const retryRequest = () => {
|
|
233
|
+
retrialNum++;
|
|
234
|
+
if (!document.querySelector('reconnect-overlay')) {
|
|
235
|
+
renderOverlay();
|
|
236
|
+
}
|
|
237
|
+
if (url.includes(getBackendUrl())) {
|
|
238
|
+
url = url.replace(getBackendUrl(), getSecondaryBackendUrl());
|
|
239
|
+
}
|
|
240
|
+
else if (url.includes(getSecondaryBackendUrl())) {
|
|
241
|
+
url = url.replace(getSecondaryBackendUrl(), getBackendUrl());
|
|
242
|
+
}
|
|
243
|
+
setTimeout(() => backendRequest(url, options, onSuccess, onError, onRedirect, requestType, handleUnauthorized, true, retrialNum), 2000);
|
|
244
|
+
};
|
|
245
|
+
retryRequest();
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
requestRunning = false;
|
|
250
|
+
}
|
|
251
|
+
removeOverlay();
|
|
252
|
+
if (onRedirect)
|
|
253
|
+
onRedirect(response);
|
|
254
|
+
if (response.status === 401) {
|
|
255
|
+
handleUnauthorized();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
const jsonResponse = yield response.json();
|
|
260
|
+
if (response.ok) {
|
|
261
|
+
if (onSuccess) {
|
|
262
|
+
onSuccess(jsonResponse);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
return jsonResponse;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
// backend predicted exceptions
|
|
270
|
+
onError(jsonResponse.error);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
// json conversion error / json response dealing errors
|
|
275
|
+
onError(err);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
const post = (endpoint, body, onSuccess, onError, onRedirect, requestType = "query") => {
|
|
279
|
+
const options = {
|
|
280
|
+
method: 'POST',
|
|
281
|
+
headers: {
|
|
282
|
+
'Accept': 'application/json',
|
|
283
|
+
'Content-Type': 'application/json',
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
if (body) {
|
|
287
|
+
// @ts-ignore
|
|
288
|
+
options.body = JSON.stringify(body);
|
|
289
|
+
}
|
|
290
|
+
return backendRequest(getApiUrl() + endpoint, options, onSuccess, onError, onRedirect, requestType);
|
|
291
|
+
};
|
|
292
|
+
const get = (endpoint, onSuccess, onError, onRedirect) => {
|
|
293
|
+
const options = {
|
|
294
|
+
method: 'GET',
|
|
295
|
+
headers: {
|
|
296
|
+
'Accept': 'application/json',
|
|
297
|
+
'Content-Type': 'application/json',
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
return backendRequest(getApiUrl() + endpoint, options, onSuccess, onError, onRedirect);
|
|
301
|
+
};
|
|
302
|
+
const backendPost = (endpoint, postContent, onJsonResponse, onHelpMessage) => {
|
|
303
|
+
post(endpoint, postContent, onJsonResponse, onHelpMessage);
|
|
304
|
+
};
|
|
305
|
+
const backendGet = (endpoint, params, onJsonResponse, onHelpMessage) => {
|
|
306
|
+
if (params) {
|
|
307
|
+
endpoint += '?';
|
|
308
|
+
Object.keys(params).forEach((k, i) => {
|
|
309
|
+
if (i > 0)
|
|
310
|
+
endpoint += '&';
|
|
311
|
+
endpoint += `${k}=${params[k]}`;
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
get(endpoint, onJsonResponse, onHelpMessage);
|
|
315
|
+
};
|
|
316
|
+
const requestMagicLink = (data, onJsonResponse, onUnauthorized) => {
|
|
317
|
+
const { email, token } = data;
|
|
318
|
+
const url = getMagicAuthReqUrl() + encodeURIComponent(email) + '&destination=' + extractTokenFromWindowLocation('destination') + '&token=' + token;
|
|
319
|
+
const options = {};
|
|
320
|
+
backendRequest(url, options, onJsonResponse, console.error, null, 'query', onUnauthorized);
|
|
321
|
+
};
|
|
322
|
+
const openMagicLink = (magicToken, onJsonResponse, onHelpMessage) => {
|
|
323
|
+
backendRequest(getMagicAuthUrl() + magicToken, {}, onJsonResponse, onHelpMessage);
|
|
324
|
+
};
|
|
325
|
+
const googleLogin = (token, onLogin, onLoginError) => {
|
|
326
|
+
const url = getBackendUrl() + 'auth-google?google-id-token=' + token;
|
|
327
|
+
backendRequest(url, {}, onLogin, onLoginError);
|
|
328
|
+
};
|
|
329
|
+
const microsoftLogin = (token, onLogin, onLoginError) => {
|
|
330
|
+
const url = getBackendUrl() + 'auth-microsoft?access-token=' + token;
|
|
331
|
+
backendRequest(url, {}, onLogin, onLoginError);
|
|
332
|
+
};
|
|
333
|
+
const getMXData = (domainName) => __awaiter$2(void 0, void 0, void 0, function* () {
|
|
334
|
+
try {
|
|
335
|
+
const records = yield fetch(`https://dns.google.com/resolve?name=${domainName}&type=MX`, {
|
|
336
|
+
method: 'GET',
|
|
337
|
+
mode: 'cors'
|
|
338
|
+
});
|
|
339
|
+
if (!records.ok) {
|
|
340
|
+
console.log('response was not ok');
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
const recordsJson = yield records.json();
|
|
344
|
+
const answer = recordsJson.Answer;
|
|
345
|
+
if (!answer) {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
return Array.from(answer).map((a) => a.data);
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
console.error('Fetch failed: ', error);
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
309
354
|
});
|
|
310
355
|
|
|
311
356
|
/*! @azure/msal-browser v2.21.0 2022-01-04 */
|
|
@@ -13627,956 +13672,958 @@ var juxWeb = (function (exports) {
|
|
|
13627
13672
|
return PublicClientApplication;
|
|
13628
13673
|
}(ClientApplication));
|
|
13629
13674
|
|
|
13630
|
-
let cleared = false;
|
|
13631
|
-
const clearCookieValidation = () => {
|
|
13632
|
-
var _a;
|
|
13633
|
-
(_a = document.querySelector('#cookie-test-iframe')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
13634
|
-
cleared = true;
|
|
13635
|
-
};
|
|
13636
|
-
const checkCookiesEnable = (ev, onEnabled, onDisabled) => {
|
|
13637
|
-
if (ev.data === 'MM:3PCunsupported') {
|
|
13638
|
-
clearCookieValidation();
|
|
13639
|
-
if (onDisabled) {
|
|
13640
|
-
onDisabled();
|
|
13641
|
-
}
|
|
13642
|
-
}
|
|
13643
|
-
else if (ev.data === 'MM:3PCsupported') {
|
|
13644
|
-
clearCookieValidation();
|
|
13645
|
-
onEnabled();
|
|
13646
|
-
}
|
|
13647
|
-
};
|
|
13648
|
-
const cookieTest = () => {
|
|
13649
|
-
const frame = document.createElement('iframe');
|
|
13650
|
-
frame.id = 'cookie-test-iframe';
|
|
13651
|
-
frame.src = 'https://mindmup.github.io/3rdpartycookiecheck/start.html';
|
|
13652
|
-
frame.style.display = 'none';
|
|
13653
|
-
document.body.appendChild(frame);
|
|
13654
|
-
};
|
|
13655
|
-
const validateThirdPartyCookies = (onEnabled, onDisabled) => {
|
|
13656
|
-
cleared = false;
|
|
13657
|
-
const listener = (ev) => checkCookiesEnable(ev, onEnabled, onDisabled);
|
|
13658
|
-
window.addEventListener('message', listener);
|
|
13659
|
-
const timer = setInterval(() => {
|
|
13660
|
-
if (cleared) {
|
|
13661
|
-
window.removeEventListener('message', listener);
|
|
13662
|
-
clearInterval(timer);
|
|
13663
|
-
}
|
|
13664
|
-
}, 50);
|
|
13665
|
-
cookieTest();
|
|
13675
|
+
let cleared = false;
|
|
13676
|
+
const clearCookieValidation = () => {
|
|
13677
|
+
var _a;
|
|
13678
|
+
(_a = document.querySelector('#cookie-test-iframe')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
13679
|
+
cleared = true;
|
|
13680
|
+
};
|
|
13681
|
+
const checkCookiesEnable = (ev, onEnabled, onDisabled) => {
|
|
13682
|
+
if (ev.data === 'MM:3PCunsupported') {
|
|
13683
|
+
clearCookieValidation();
|
|
13684
|
+
if (onDisabled) {
|
|
13685
|
+
onDisabled();
|
|
13686
|
+
}
|
|
13687
|
+
}
|
|
13688
|
+
else if (ev.data === 'MM:3PCsupported') {
|
|
13689
|
+
clearCookieValidation();
|
|
13690
|
+
onEnabled();
|
|
13691
|
+
}
|
|
13692
|
+
};
|
|
13693
|
+
const cookieTest = () => {
|
|
13694
|
+
const frame = document.createElement('iframe');
|
|
13695
|
+
frame.id = 'cookie-test-iframe';
|
|
13696
|
+
frame.src = 'https://mindmup.github.io/3rdpartycookiecheck/start.html';
|
|
13697
|
+
frame.style.display = 'none';
|
|
13698
|
+
document.body.appendChild(frame);
|
|
13699
|
+
};
|
|
13700
|
+
const validateThirdPartyCookies = (onEnabled, onDisabled) => {
|
|
13701
|
+
cleared = false;
|
|
13702
|
+
const listener = (ev) => checkCookiesEnable(ev, onEnabled, onDisabled);
|
|
13703
|
+
window.addEventListener('message', listener);
|
|
13704
|
+
const timer = setInterval(() => {
|
|
13705
|
+
if (cleared) {
|
|
13706
|
+
window.removeEventListener('message', listener);
|
|
13707
|
+
clearInterval(timer);
|
|
13708
|
+
}
|
|
13709
|
+
}, 50);
|
|
13710
|
+
cookieTest();
|
|
13666
13711
|
};
|
|
13667
13712
|
|
|
13668
|
-
const enableSignInLayout = () => {
|
|
13669
|
-
document.documentElement.style.cursor = 'progress';
|
|
13670
|
-
document.body.style.opacity = '0.5';
|
|
13671
|
-
document.body.style.pointerEvents = 'none';
|
|
13672
|
-
};
|
|
13673
|
-
const disableSignInLayout = () => {
|
|
13674
|
-
document.documentElement.style.cursor = 'default';
|
|
13675
|
-
document.body.style.opacity = '1';
|
|
13676
|
-
document.body.style.pointerEvents = 'auto';
|
|
13713
|
+
const enableSignInLayout = () => {
|
|
13714
|
+
document.documentElement.style.cursor = 'progress';
|
|
13715
|
+
document.body.style.opacity = '0.5';
|
|
13716
|
+
document.body.style.pointerEvents = 'none';
|
|
13717
|
+
};
|
|
13718
|
+
const disableSignInLayout = () => {
|
|
13719
|
+
document.documentElement.style.cursor = 'default';
|
|
13720
|
+
document.body.style.opacity = '1';
|
|
13721
|
+
document.body.style.pointerEvents = 'auto';
|
|
13677
13722
|
};
|
|
13678
13723
|
|
|
13679
|
-
// TODO: find a better way to import external scripts
|
|
13680
|
-
const script$1 = document.createElement('script');
|
|
13681
|
-
script$1.type = 'text/javascript';
|
|
13682
|
-
script$1.src = 'https://apis.google.com/js/api.js';
|
|
13683
|
-
document.head.appendChild(script$1);
|
|
13684
|
-
let authStatus;
|
|
13685
|
-
let authError;
|
|
13686
|
-
const highLevelUser = (gUser) => {
|
|
13687
|
-
const profile = gUser.getBasicProfile();
|
|
13688
|
-
return {
|
|
13689
|
-
name: profile.getName(),
|
|
13690
|
-
email: profile.getEmail(),
|
|
13691
|
-
picture: profile.getImageUrl(),
|
|
13692
|
-
googletoken: gUser.getAuthResponse().id_token
|
|
13693
|
-
};
|
|
13694
|
-
};
|
|
13695
|
-
const onUserChanged = (googleUser, onUserLogin) => {
|
|
13696
|
-
document.documentElement.classList.remove('progress');
|
|
13697
|
-
document.body.classList.remove('disabled');
|
|
13698
|
-
if (googleUser) {
|
|
13699
|
-
// mixpanelIdentify(googleUser); TODO
|
|
13700
|
-
const onSuccess = (res) => {
|
|
13701
|
-
const { token } = res;
|
|
13702
|
-
// @ts-ignore
|
|
13703
|
-
window.store.currentUser = res;
|
|
13704
|
-
onTokenAcquired(token, onUserLogin);
|
|
13705
|
-
};
|
|
13706
|
-
const onError = (err) => {
|
|
13707
|
-
console.error(err);
|
|
13708
|
-
// logError(error); TODO
|
|
13709
|
-
// checkMixpanel(() => mixpanel.track('Login Error', { 'Login Type': 'Google', 'Error': error })); TODO
|
|
13710
|
-
};
|
|
13711
|
-
googleLogin(googleUser.googletoken, onSuccess, onError);
|
|
13712
|
-
// checkMixpanel(() => mixpanel.track('Login', { 'Login Type': 'Google' })); TODO
|
|
13713
|
-
}
|
|
13714
|
-
else {
|
|
13715
|
-
setBackendToken('');
|
|
13716
|
-
// checkMixpanel(() => mixpanel.reset()); TODO
|
|
13717
|
-
// displayPage(Page.LOGIN); TODO
|
|
13718
|
-
}
|
|
13719
|
-
};
|
|
13720
|
-
const onGoogleUserChanged = (gUser, onUserLogin) => {
|
|
13721
|
-
onUserChanged(gUser.isSignedIn() ? highLevelUser(gUser) : null, onUserLogin);
|
|
13722
|
-
};
|
|
13723
|
-
const initGapiClient = (callbackFn, onUserLogin) => {
|
|
13724
|
-
// @ts-ignore
|
|
13725
|
-
const clientId = process.env.GOOGLE_CLIENT_ID;
|
|
13726
|
-
gapi.auth2.init({ client_id: clientId, prompt: 'select_account' }).then(() => {
|
|
13727
|
-
authStatus = 'LOADED';
|
|
13728
|
-
const currentUser = getAuth().currentUser;
|
|
13729
|
-
currentUser.listen(onGoogleUserChanged);
|
|
13730
|
-
callbackFn ? callbackFn(clientId) : onGoogleUserChanged(currentUser.get(), onUserLogin);
|
|
13731
|
-
}, onAuthError);
|
|
13732
|
-
};
|
|
13733
|
-
const onAuthError = (error) => {
|
|
13734
|
-
authError = error;
|
|
13735
|
-
console.error(error);
|
|
13736
|
-
// logError(error, authError); // TODO
|
|
13737
|
-
};
|
|
13738
|
-
const initGapi = (callbackFn = null, onUserLogin) => {
|
|
13739
|
-
if (!window.location.protocol.startsWith('http')) {
|
|
13740
|
-
onAuthError('To use Google Auth you must access this page using http(s), not ' + window.location.protocol);
|
|
13741
|
-
return;
|
|
13742
|
-
}
|
|
13743
|
-
if (typeof gapi === 'undefined') {
|
|
13744
|
-
onAuthError('Unable to load the Google API');
|
|
13745
|
-
return;
|
|
13746
|
-
}
|
|
13747
|
-
authStatus = 'LOADING';
|
|
13748
|
-
gapi.load('auth2', {
|
|
13749
|
-
callback: () => initGapiClient(callbackFn, onUserLogin),
|
|
13750
|
-
onerror: onAuthError,
|
|
13751
|
-
ontimeout: onAuthError,
|
|
13752
|
-
timeout: 5000
|
|
13753
|
-
});
|
|
13754
|
-
};
|
|
13755
|
-
const authAlert = (error) => {
|
|
13756
|
-
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));
|
|
13757
|
-
location.reload();
|
|
13758
|
-
};
|
|
13759
|
-
const onSignInError = (error) => {
|
|
13760
|
-
disableSignInLayout();
|
|
13761
|
-
console.error(error);
|
|
13762
|
-
// logError(error); TODO
|
|
13763
|
-
if (error && error.error === 'popup_closed_by_user') {
|
|
13764
|
-
onUserChanged(null, () => { });
|
|
13765
|
-
return;
|
|
13766
|
-
}
|
|
13767
|
-
authAlert(error);
|
|
13768
|
-
};
|
|
13769
|
-
const getAuth = () => {
|
|
13770
|
-
if (typeof gapi === 'undefined') {
|
|
13771
|
-
console.error('gapi is undefined');
|
|
13772
|
-
// logError('gapi is undefined'); TODO
|
|
13773
|
-
return null;
|
|
13774
|
-
}
|
|
13775
|
-
return gapi.auth2 && gapi.auth2.getAuthInstance();
|
|
13776
|
-
};
|
|
13777
|
-
const googleSignIn = () => getAuth().signIn().catch(onSignInError);
|
|
13778
|
-
const authSignIn = (onUserLogin) => {
|
|
13779
|
-
if (authError) {
|
|
13780
|
-
authAlert(authError);
|
|
13781
|
-
return;
|
|
13782
|
-
}
|
|
13783
|
-
if (authStatus === 'LOADING') {
|
|
13784
|
-
setTimeout(authSignIn, 400);
|
|
13785
|
-
}
|
|
13786
|
-
else {
|
|
13787
|
-
try {
|
|
13788
|
-
googleSignIn();
|
|
13789
|
-
}
|
|
13790
|
-
catch (err) {
|
|
13791
|
-
try {
|
|
13792
|
-
initGapi(() => googleSignIn(), onUserLogin);
|
|
13793
|
-
}
|
|
13794
|
-
catch (error) {
|
|
13795
|
-
onSignInError(error);
|
|
13796
|
-
}
|
|
13797
|
-
}
|
|
13798
|
-
}
|
|
13724
|
+
// TODO: find a better way to import external scripts
|
|
13725
|
+
const script$1 = document.createElement('script');
|
|
13726
|
+
script$1.type = 'text/javascript';
|
|
13727
|
+
script$1.src = 'https://apis.google.com/js/api.js';
|
|
13728
|
+
document.head.appendChild(script$1);
|
|
13729
|
+
let authStatus;
|
|
13730
|
+
let authError;
|
|
13731
|
+
const highLevelUser = (gUser) => {
|
|
13732
|
+
const profile = gUser.getBasicProfile();
|
|
13733
|
+
return {
|
|
13734
|
+
name: profile.getName(),
|
|
13735
|
+
email: profile.getEmail(),
|
|
13736
|
+
picture: profile.getImageUrl(),
|
|
13737
|
+
googletoken: gUser.getAuthResponse().id_token
|
|
13738
|
+
};
|
|
13739
|
+
};
|
|
13740
|
+
const onUserChanged = (googleUser, onUserLogin) => {
|
|
13741
|
+
document.documentElement.classList.remove('progress');
|
|
13742
|
+
document.body.classList.remove('disabled');
|
|
13743
|
+
if (googleUser) {
|
|
13744
|
+
// mixpanelIdentify(googleUser); TODO
|
|
13745
|
+
const onSuccess = (res) => {
|
|
13746
|
+
const { token } = res;
|
|
13747
|
+
// @ts-ignore
|
|
13748
|
+
window.store.currentUser = res;
|
|
13749
|
+
onTokenAcquired(token, onUserLogin);
|
|
13750
|
+
};
|
|
13751
|
+
const onError = (err) => {
|
|
13752
|
+
console.error(err);
|
|
13753
|
+
// logError(error); TODO
|
|
13754
|
+
// checkMixpanel(() => mixpanel.track('Login Error', { 'Login Type': 'Google', 'Error': error })); TODO
|
|
13755
|
+
};
|
|
13756
|
+
googleLogin(googleUser.googletoken, onSuccess, onError);
|
|
13757
|
+
// checkMixpanel(() => mixpanel.track('Login', { 'Login Type': 'Google' })); TODO
|
|
13758
|
+
}
|
|
13759
|
+
else {
|
|
13760
|
+
setBackendToken('');
|
|
13761
|
+
// checkMixpanel(() => mixpanel.reset()); TODO
|
|
13762
|
+
// displayPage(Page.LOGIN); TODO
|
|
13763
|
+
}
|
|
13764
|
+
};
|
|
13765
|
+
const onGoogleUserChanged = (gUser, onUserLogin) => {
|
|
13766
|
+
onUserChanged(gUser.isSignedIn() ? highLevelUser(gUser) : null, onUserLogin);
|
|
13767
|
+
};
|
|
13768
|
+
const initGapiClient = (callbackFn, onUserLogin) => {
|
|
13769
|
+
// @ts-ignore
|
|
13770
|
+
const clientId = process.env.GOOGLE_CLIENT_ID;
|
|
13771
|
+
gapi.auth2.init({ client_id: clientId, prompt: 'select_account' }).then(() => {
|
|
13772
|
+
authStatus = 'LOADED';
|
|
13773
|
+
const currentUser = getAuth().currentUser;
|
|
13774
|
+
currentUser.listen(onGoogleUserChanged);
|
|
13775
|
+
callbackFn ? callbackFn(clientId) : onGoogleUserChanged(currentUser.get(), onUserLogin);
|
|
13776
|
+
}, onAuthError);
|
|
13777
|
+
};
|
|
13778
|
+
const onAuthError = (error) => {
|
|
13779
|
+
authError = error;
|
|
13780
|
+
console.error(error);
|
|
13781
|
+
// logError(error, authError); // TODO
|
|
13782
|
+
};
|
|
13783
|
+
const initGapi = (callbackFn = null, onUserLogin) => {
|
|
13784
|
+
if (!window.location.protocol.startsWith('http')) {
|
|
13785
|
+
onAuthError('To use Google Auth you must access this page using http(s), not ' + window.location.protocol);
|
|
13786
|
+
return;
|
|
13787
|
+
}
|
|
13788
|
+
if (typeof gapi === 'undefined') {
|
|
13789
|
+
onAuthError('Unable to load the Google API');
|
|
13790
|
+
return;
|
|
13791
|
+
}
|
|
13792
|
+
authStatus = 'LOADING';
|
|
13793
|
+
gapi.load('auth2', {
|
|
13794
|
+
callback: () => initGapiClient(callbackFn, onUserLogin),
|
|
13795
|
+
onerror: onAuthError,
|
|
13796
|
+
ontimeout: onAuthError,
|
|
13797
|
+
timeout: 5000
|
|
13798
|
+
});
|
|
13799
|
+
};
|
|
13800
|
+
const authAlert = (error) => {
|
|
13801
|
+
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));
|
|
13802
|
+
location.reload();
|
|
13803
|
+
};
|
|
13804
|
+
const onSignInError = (error) => {
|
|
13805
|
+
disableSignInLayout();
|
|
13806
|
+
console.error(error);
|
|
13807
|
+
// logError(error); TODO
|
|
13808
|
+
if (error && error.error === 'popup_closed_by_user') {
|
|
13809
|
+
onUserChanged(null, () => { });
|
|
13810
|
+
return;
|
|
13811
|
+
}
|
|
13812
|
+
authAlert(error);
|
|
13813
|
+
};
|
|
13814
|
+
const getAuth = () => {
|
|
13815
|
+
if (typeof gapi === 'undefined') {
|
|
13816
|
+
console.error('gapi is undefined');
|
|
13817
|
+
// logError('gapi is undefined'); TODO
|
|
13818
|
+
return null;
|
|
13819
|
+
}
|
|
13820
|
+
return gapi.auth2 && gapi.auth2.getAuthInstance();
|
|
13821
|
+
};
|
|
13822
|
+
const googleSignIn = () => getAuth().signIn().catch(onSignInError);
|
|
13823
|
+
const authSignIn = (onUserLogin) => {
|
|
13824
|
+
if (authError) {
|
|
13825
|
+
authAlert(authError);
|
|
13826
|
+
return;
|
|
13827
|
+
}
|
|
13828
|
+
if (authStatus === 'LOADING') {
|
|
13829
|
+
setTimeout(authSignIn, 400);
|
|
13830
|
+
}
|
|
13831
|
+
else {
|
|
13832
|
+
try {
|
|
13833
|
+
googleSignIn();
|
|
13834
|
+
}
|
|
13835
|
+
catch (err) {
|
|
13836
|
+
try {
|
|
13837
|
+
initGapi(() => googleSignIn(), onUserLogin);
|
|
13838
|
+
}
|
|
13839
|
+
catch (error) {
|
|
13840
|
+
onSignInError(error);
|
|
13841
|
+
}
|
|
13842
|
+
}
|
|
13843
|
+
}
|
|
13799
13844
|
};
|
|
13800
13845
|
|
|
13801
|
-
// TODO: find a better way to import external scripts
|
|
13802
|
-
const script = document.createElement('script');
|
|
13803
|
-
script.type = 'text/javascript';
|
|
13804
|
-
script.src = 'https://www.google.com/recaptcha/api.js';
|
|
13805
|
-
document.head.appendChild(script);
|
|
13806
|
-
const googleCaptcha = () => {
|
|
13807
|
-
const result = document.createElement('google-captcha');
|
|
13808
|
-
window.submitCaptcha = (token) => result.setAttribute('token', token);
|
|
13809
|
-
result.className = 'g-recaptcha';
|
|
13810
|
-
// @ts-ignore
|
|
13811
|
-
result.setAttribute('data-sitekey', process.env.GOOGLE_CAPTCHA_KEY);
|
|
13812
|
-
result.setAttribute('data-callback', 'submitCaptcha');
|
|
13813
|
-
grecaptcha.render(result);
|
|
13814
|
-
return result;
|
|
13846
|
+
// TODO: find a better way to import external scripts
|
|
13847
|
+
const script = document.createElement('script');
|
|
13848
|
+
script.type = 'text/javascript';
|
|
13849
|
+
script.src = 'https://www.google.com/recaptcha/api.js';
|
|
13850
|
+
document.head.appendChild(script);
|
|
13851
|
+
const googleCaptcha = () => {
|
|
13852
|
+
const result = document.createElement('google-captcha');
|
|
13853
|
+
window.submitCaptcha = (token) => result.setAttribute('token', token);
|
|
13854
|
+
result.className = 'g-recaptcha';
|
|
13855
|
+
// @ts-ignore
|
|
13856
|
+
result.setAttribute('data-sitekey', process.env.GOOGLE_CAPTCHA_KEY);
|
|
13857
|
+
result.setAttribute('data-callback', 'submitCaptcha');
|
|
13858
|
+
grecaptcha.render(result);
|
|
13859
|
+
return result;
|
|
13815
13860
|
};
|
|
13816
13861
|
|
|
13817
|
-
const juxWhite = '#FFF';
|
|
13818
|
-
const juxDarkGrey = '#282828';
|
|
13819
|
-
const juxDimmedDarkGrey = '#28282822';
|
|
13820
|
-
const juxDimmedBlack = '#00000088';
|
|
13821
|
-
const juxLightGreen = '#20B03D';
|
|
13862
|
+
const juxWhite = '#FFF';
|
|
13863
|
+
const juxDarkGrey = '#282828';
|
|
13864
|
+
const juxDimmedDarkGrey = '#28282822';
|
|
13865
|
+
const juxDimmedBlack = '#00000088';
|
|
13866
|
+
const juxLightGreen = '#20B03D';
|
|
13822
13867
|
const juxMediumGreen = '#0D631E';
|
|
13823
13868
|
|
|
13824
|
-
const onKeyDown = (ev, el, persitent, onClose) => {
|
|
13825
|
-
if (ev.key === 'Escape') {
|
|
13826
|
-
if (persitent) {
|
|
13827
|
-
return;
|
|
13828
|
-
}
|
|
13829
|
-
close(el, onClose);
|
|
13830
|
-
}
|
|
13831
|
-
else if (ev.key === 'Enter') {
|
|
13832
|
-
if (ev.target.id === 'members-textarea') {
|
|
13833
|
-
return;
|
|
13834
|
-
}
|
|
13835
|
-
el.dispatchEvent(new CustomEvent('ok'));
|
|
13836
|
-
}
|
|
13837
|
-
};
|
|
13838
|
-
const close = (el, onClose) => {
|
|
13839
|
-
el.remove();
|
|
13840
|
-
if (onClose) {
|
|
13841
|
-
onClose();
|
|
13842
|
-
}
|
|
13843
|
-
};
|
|
13844
|
-
const attachEventHandlers = (el, persitent, onClose) => {
|
|
13845
|
-
const cancelButton = el.querySelector('.cancel');
|
|
13846
|
-
cancelButton === null || cancelButton === void 0 ? void 0 : cancelButton.addEventListener('click', (_e) => {
|
|
13847
|
-
el.dispatchEvent(new CustomEvent('cancel'));
|
|
13848
|
-
if (el.hasAttribute('dont-remove')) {
|
|
13849
|
-
return;
|
|
13850
|
-
}
|
|
13851
|
-
close(el, onClose);
|
|
13852
|
-
});
|
|
13853
|
-
const closeButton = el.querySelector('.close');
|
|
13854
|
-
if (closeButton) {
|
|
13855
|
-
closeButton.addEventListener('click', (_e) => {
|
|
13856
|
-
close(el, onClose);
|
|
13857
|
-
});
|
|
13858
|
-
}
|
|
13859
|
-
const okButton = el.querySelector('.ok');
|
|
13860
|
-
okButton === null || okButton === void 0 ? void 0 : okButton.addEventListener('click', (_e) => {
|
|
13861
|
-
el.dispatchEvent(new CustomEvent('ok'));
|
|
13862
|
-
});
|
|
13863
|
-
el.removeEventListener('keydown', (ev) => onKeyDown(ev, el, persitent, () => onClose));
|
|
13864
|
-
el.addEventListener('keydown', (ev) => onKeyDown(ev, el, persitent, () => onClose));
|
|
13865
|
-
el === null || el === void 0 ? void 0 : el.addEventListener('click', (e) => {
|
|
13866
|
-
if (e.target === el) {
|
|
13867
|
-
if (persitent) {
|
|
13868
|
-
return;
|
|
13869
|
-
}
|
|
13870
|
-
close(el, onClose);
|
|
13871
|
-
}
|
|
13872
|
-
});
|
|
13873
|
-
};
|
|
13874
|
-
// TODO: Mudar construtor para usar essa interface
|
|
13875
|
-
// interface JuxModalOptions {
|
|
13876
|
-
// title?: string,
|
|
13877
|
-
// btns?: string[],
|
|
13878
|
-
// content?: string,
|
|
13879
|
-
// isPersistent?: boolean,
|
|
13880
|
-
// isBusy?: boolean,
|
|
13881
|
-
// body?: HTMLElement,
|
|
13882
|
-
// okTxt?: string,
|
|
13883
|
-
// cancelTxt?: string,
|
|
13884
|
-
// onClose?: any,
|
|
13885
|
-
// titleStyle?: string,
|
|
13886
|
-
// }
|
|
13887
|
-
const applyWrapperStyle = (wrapper) => {
|
|
13888
|
-
wrapper.style.alignItems = 'center';
|
|
13889
|
-
wrapper.style.backgroundColor = juxWhite;
|
|
13890
|
-
wrapper.style.borderRadius = '.3125rem';
|
|
13891
|
-
wrapper.style.boxShadow = `0 0 1.33rem ${juxDimmedBlack}`;
|
|
13892
|
-
wrapper.style.boxSizing = 'content-box';
|
|
13893
|
-
wrapper.style.display = 'flex';
|
|
13894
|
-
wrapper.style.flexDirection = 'column';
|
|
13895
|
-
wrapper.style.justifyContent = 'flex-start';
|
|
13896
|
-
wrapper.style.margin = '0';
|
|
13897
|
-
wrapper.style.maxHeight = '88%';
|
|
13898
|
-
wrapper.style.maxWidth = '40%';
|
|
13899
|
-
wrapper.style.minWidth = '20%';
|
|
13900
|
-
wrapper.style.padding = '1.33rem';
|
|
13901
|
-
wrapper.style.position = 'relative';
|
|
13902
|
-
};
|
|
13903
|
-
const applyModalStyle = (modal) => {
|
|
13904
|
-
modal.style.alignItems = 'center';
|
|
13905
|
-
modal.style.backgroundColor = juxDimmedBlack;
|
|
13906
|
-
modal.style.display = 'flex';
|
|
13907
|
-
modal.style.height = '100vh';
|
|
13908
|
-
modal.style.justifyContent = 'center';
|
|
13909
|
-
modal.style.left = '0';
|
|
13910
|
-
modal.style.overflow = 'hidden';
|
|
13911
|
-
modal.style.position = 'fixed';
|
|
13912
|
-
modal.style.top = '0';
|
|
13913
|
-
modal.style.width = '100%';
|
|
13914
|
-
modal.style.zIndex = '9999';
|
|
13915
|
-
};
|
|
13916
|
-
const applyHeaderStyle = (header) => {
|
|
13917
|
-
header.style.alignItems = 'center';
|
|
13918
|
-
header.style.color = juxMediumGreen;
|
|
13919
|
-
header.style.flexDirection = 'row';
|
|
13920
|
-
header.style.fontSize = '16px';
|
|
13921
|
-
header.style.fontWeight = '700';
|
|
13922
|
-
header.style.justifyContent = 'space-between';
|
|
13923
|
-
header.style.margin = '0';
|
|
13924
|
-
header.style.display = 'flex';
|
|
13925
|
-
header.style.position = 'relative';
|
|
13926
|
-
header.style.width = '100%';
|
|
13927
|
-
};
|
|
13928
|
-
const applyJuxModalContentStyle = (el) => {
|
|
13929
|
-
el.style.display = 'flex';
|
|
13930
|
-
el.style.position = 'relative';
|
|
13931
|
-
el.style.width = '100%';
|
|
13932
|
-
el.style.flexFlow = 'column';
|
|
13933
|
-
el.style.marginTop = '1.33rem';
|
|
13934
|
-
el.style.rowGap = '8px';
|
|
13935
|
-
};
|
|
13936
|
-
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) => {
|
|
13937
|
-
const result = document.createElement('jux-modal');
|
|
13938
|
-
applyModalStyle(result);
|
|
13939
|
-
const wrapper = document.createElement('modal-wrapper');
|
|
13940
|
-
applyWrapperStyle(wrapper);
|
|
13941
|
-
// START close
|
|
13942
|
-
const closeBtn = document.createElement('button');
|
|
13943
|
-
if (!persistent) {
|
|
13944
|
-
closeBtn.className = 'close';
|
|
13945
|
-
closeBtn.setAttribute('aria-label', getTranslation('close'));
|
|
13946
|
-
}
|
|
13947
|
-
// END close
|
|
13948
|
-
// START header
|
|
13949
|
-
const header = document.createElement('modal-header');
|
|
13950
|
-
applyHeaderStyle(header);
|
|
13951
|
-
if (title) {
|
|
13952
|
-
if (titleStyle) {
|
|
13953
|
-
header.classList.add(titleStyle);
|
|
13954
|
-
}
|
|
13955
|
-
const h3 = document.createElement('h3');
|
|
13956
|
-
h3.textContent = title;
|
|
13957
|
-
header.appendChild(h3);
|
|
13958
|
-
}
|
|
13959
|
-
// END header
|
|
13960
|
-
// START content
|
|
13961
|
-
const modalContent = document.createElement('jux-modal-content');
|
|
13962
|
-
applyJuxModalContentStyle(modalContent);
|
|
13963
|
-
if (content) {
|
|
13964
|
-
modalContent.innerHTML = content;
|
|
13965
|
-
}
|
|
13966
|
-
else if (body) {
|
|
13967
|
-
modalContent.appendChild(body);
|
|
13968
|
-
}
|
|
13969
|
-
// END content
|
|
13970
|
-
// START footer
|
|
13971
|
-
const footer = document.createElement('modal-footer');
|
|
13972
|
-
if (btns.includes('cancel')) {
|
|
13973
|
-
const cancelBtn = document.createElement('button');
|
|
13974
|
-
cancelBtn.classList.add('secondary-button', 'modal-button', 'action', 'cancel-btn', 'cancel');
|
|
13975
|
-
const cancelText = document.createElement('button-text');
|
|
13976
|
-
cancelText.textContent = cancelTxt;
|
|
13977
|
-
const cancelSpinner = document.createElement('loading-spinner');
|
|
13978
|
-
cancelBtn.append(cancelText, cancelSpinner);
|
|
13979
|
-
footer.appendChild(cancelBtn);
|
|
13980
|
-
}
|
|
13981
|
-
if (btns.includes('ok')) {
|
|
13982
|
-
const okBtn = document.createElement('button');
|
|
13983
|
-
okBtn.classList.add('primary-button', 'modal-button', 'action', 'ok');
|
|
13984
|
-
const okText = document.createElement('button-text');
|
|
13985
|
-
okText.textContent = okTxt;
|
|
13986
|
-
const okSpinner = document.createElement('loading-spinner');
|
|
13987
|
-
okBtn.append(okText, okSpinner);
|
|
13988
|
-
footer.appendChild(okBtn);
|
|
13989
|
-
}
|
|
13990
|
-
// END footer
|
|
13991
|
-
if (footer.hasChildNodes()) {
|
|
13992
|
-
wrapper.append(closeBtn, header, modalContent, footer);
|
|
13993
|
-
}
|
|
13994
|
-
else {
|
|
13995
|
-
wrapper.append(closeBtn, header, modalContent);
|
|
13996
|
-
}
|
|
13997
|
-
result.appendChild(wrapper);
|
|
13998
|
-
if (!persistent) {
|
|
13999
|
-
result.querySelector('.close').focus();
|
|
14000
|
-
}
|
|
14001
|
-
else {
|
|
14002
|
-
if (btns.includes('ok')) {
|
|
14003
|
-
result.querySelector('.ok').focus();
|
|
14004
|
-
}
|
|
14005
|
-
}
|
|
14006
|
-
attachEventHandlers(result, persistent, onClose);
|
|
14007
|
-
return result;
|
|
13869
|
+
const onKeyDown = (ev, el, persitent, onClose) => {
|
|
13870
|
+
if (ev.key === 'Escape') {
|
|
13871
|
+
if (persitent) {
|
|
13872
|
+
return;
|
|
13873
|
+
}
|
|
13874
|
+
close(el, onClose);
|
|
13875
|
+
}
|
|
13876
|
+
else if (ev.key === 'Enter') {
|
|
13877
|
+
if (ev.target.id === 'members-textarea') {
|
|
13878
|
+
return;
|
|
13879
|
+
}
|
|
13880
|
+
el.dispatchEvent(new CustomEvent('ok'));
|
|
13881
|
+
}
|
|
13882
|
+
};
|
|
13883
|
+
const close = (el, onClose) => {
|
|
13884
|
+
el.remove();
|
|
13885
|
+
if (onClose) {
|
|
13886
|
+
onClose();
|
|
13887
|
+
}
|
|
13888
|
+
};
|
|
13889
|
+
const attachEventHandlers = (el, persitent, onClose) => {
|
|
13890
|
+
const cancelButton = el.querySelector('.cancel');
|
|
13891
|
+
cancelButton === null || cancelButton === void 0 ? void 0 : cancelButton.addEventListener('click', (_e) => {
|
|
13892
|
+
el.dispatchEvent(new CustomEvent('cancel'));
|
|
13893
|
+
if (el.hasAttribute('dont-remove')) {
|
|
13894
|
+
return;
|
|
13895
|
+
}
|
|
13896
|
+
close(el, onClose);
|
|
13897
|
+
});
|
|
13898
|
+
const closeButton = el.querySelector('.close');
|
|
13899
|
+
if (closeButton) {
|
|
13900
|
+
closeButton.addEventListener('click', (_e) => {
|
|
13901
|
+
close(el, onClose);
|
|
13902
|
+
});
|
|
13903
|
+
}
|
|
13904
|
+
const okButton = el.querySelector('.ok');
|
|
13905
|
+
okButton === null || okButton === void 0 ? void 0 : okButton.addEventListener('click', (_e) => {
|
|
13906
|
+
el.dispatchEvent(new CustomEvent('ok'));
|
|
13907
|
+
});
|
|
13908
|
+
el.removeEventListener('keydown', (ev) => onKeyDown(ev, el, persitent, () => onClose));
|
|
13909
|
+
el.addEventListener('keydown', (ev) => onKeyDown(ev, el, persitent, () => onClose));
|
|
13910
|
+
el === null || el === void 0 ? void 0 : el.addEventListener('click', (e) => {
|
|
13911
|
+
if (e.target === el) {
|
|
13912
|
+
if (persitent) {
|
|
13913
|
+
return;
|
|
13914
|
+
}
|
|
13915
|
+
close(el, onClose);
|
|
13916
|
+
}
|
|
13917
|
+
});
|
|
13918
|
+
};
|
|
13919
|
+
// TODO: Mudar construtor para usar essa interface
|
|
13920
|
+
// interface JuxModalOptions {
|
|
13921
|
+
// title?: string,
|
|
13922
|
+
// btns?: string[],
|
|
13923
|
+
// content?: string,
|
|
13924
|
+
// isPersistent?: boolean,
|
|
13925
|
+
// isBusy?: boolean,
|
|
13926
|
+
// body?: HTMLElement,
|
|
13927
|
+
// okTxt?: string,
|
|
13928
|
+
// cancelTxt?: string,
|
|
13929
|
+
// onClose?: any,
|
|
13930
|
+
// titleStyle?: string,
|
|
13931
|
+
// }
|
|
13932
|
+
const applyWrapperStyle = (wrapper) => {
|
|
13933
|
+
wrapper.style.alignItems = 'center';
|
|
13934
|
+
wrapper.style.backgroundColor = juxWhite;
|
|
13935
|
+
wrapper.style.borderRadius = '.3125rem';
|
|
13936
|
+
wrapper.style.boxShadow = `0 0 1.33rem ${juxDimmedBlack}`;
|
|
13937
|
+
wrapper.style.boxSizing = 'content-box';
|
|
13938
|
+
wrapper.style.display = 'flex';
|
|
13939
|
+
wrapper.style.flexDirection = 'column';
|
|
13940
|
+
wrapper.style.justifyContent = 'flex-start';
|
|
13941
|
+
wrapper.style.margin = '0';
|
|
13942
|
+
wrapper.style.maxHeight = '88%';
|
|
13943
|
+
wrapper.style.maxWidth = '40%';
|
|
13944
|
+
wrapper.style.minWidth = '20%';
|
|
13945
|
+
wrapper.style.padding = '1.33rem';
|
|
13946
|
+
wrapper.style.position = 'relative';
|
|
13947
|
+
};
|
|
13948
|
+
const applyModalStyle = (modal) => {
|
|
13949
|
+
modal.style.alignItems = 'center';
|
|
13950
|
+
modal.style.backgroundColor = juxDimmedBlack;
|
|
13951
|
+
modal.style.display = 'flex';
|
|
13952
|
+
modal.style.height = '100vh';
|
|
13953
|
+
modal.style.justifyContent = 'center';
|
|
13954
|
+
modal.style.left = '0';
|
|
13955
|
+
modal.style.overflow = 'hidden';
|
|
13956
|
+
modal.style.position = 'fixed';
|
|
13957
|
+
modal.style.top = '0';
|
|
13958
|
+
modal.style.width = '100%';
|
|
13959
|
+
modal.style.zIndex = '9999';
|
|
13960
|
+
};
|
|
13961
|
+
const applyHeaderStyle = (header) => {
|
|
13962
|
+
header.style.alignItems = 'center';
|
|
13963
|
+
header.style.color = juxMediumGreen;
|
|
13964
|
+
header.style.flexDirection = 'row';
|
|
13965
|
+
header.style.fontSize = '16px';
|
|
13966
|
+
header.style.fontWeight = '700';
|
|
13967
|
+
header.style.justifyContent = 'space-between';
|
|
13968
|
+
header.style.margin = '0';
|
|
13969
|
+
header.style.display = 'flex';
|
|
13970
|
+
header.style.position = 'relative';
|
|
13971
|
+
header.style.width = '100%';
|
|
13972
|
+
};
|
|
13973
|
+
const applyJuxModalContentStyle = (el) => {
|
|
13974
|
+
el.style.display = 'flex';
|
|
13975
|
+
el.style.position = 'relative';
|
|
13976
|
+
el.style.width = '100%';
|
|
13977
|
+
el.style.flexFlow = 'column';
|
|
13978
|
+
el.style.marginTop = '1.33rem';
|
|
13979
|
+
el.style.rowGap = '8px';
|
|
13980
|
+
};
|
|
13981
|
+
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) => {
|
|
13982
|
+
const result = document.createElement('jux-modal');
|
|
13983
|
+
applyModalStyle(result);
|
|
13984
|
+
const wrapper = document.createElement('modal-wrapper');
|
|
13985
|
+
applyWrapperStyle(wrapper);
|
|
13986
|
+
// START close
|
|
13987
|
+
const closeBtn = document.createElement('button');
|
|
13988
|
+
if (!persistent) {
|
|
13989
|
+
closeBtn.className = 'close';
|
|
13990
|
+
closeBtn.setAttribute('aria-label', getTranslation('close'));
|
|
13991
|
+
}
|
|
13992
|
+
// END close
|
|
13993
|
+
// START header
|
|
13994
|
+
const header = document.createElement('modal-header');
|
|
13995
|
+
applyHeaderStyle(header);
|
|
13996
|
+
if (title) {
|
|
13997
|
+
if (titleStyle) {
|
|
13998
|
+
header.classList.add(titleStyle);
|
|
13999
|
+
}
|
|
14000
|
+
const h3 = document.createElement('h3');
|
|
14001
|
+
h3.textContent = title;
|
|
14002
|
+
header.appendChild(h3);
|
|
14003
|
+
}
|
|
14004
|
+
// END header
|
|
14005
|
+
// START content
|
|
14006
|
+
const modalContent = document.createElement('jux-modal-content');
|
|
14007
|
+
applyJuxModalContentStyle(modalContent);
|
|
14008
|
+
if (content) {
|
|
14009
|
+
modalContent.innerHTML = content;
|
|
14010
|
+
}
|
|
14011
|
+
else if (body) {
|
|
14012
|
+
modalContent.appendChild(body);
|
|
14013
|
+
}
|
|
14014
|
+
// END content
|
|
14015
|
+
// START footer
|
|
14016
|
+
const footer = document.createElement('modal-footer');
|
|
14017
|
+
if (btns.includes('cancel')) {
|
|
14018
|
+
const cancelBtn = document.createElement('button');
|
|
14019
|
+
cancelBtn.classList.add('secondary-button', 'modal-button', 'action', 'cancel-btn', 'cancel');
|
|
14020
|
+
const cancelText = document.createElement('button-text');
|
|
14021
|
+
cancelText.textContent = cancelTxt;
|
|
14022
|
+
const cancelSpinner = document.createElement('loading-spinner');
|
|
14023
|
+
cancelBtn.append(cancelText, cancelSpinner);
|
|
14024
|
+
footer.appendChild(cancelBtn);
|
|
14025
|
+
}
|
|
14026
|
+
if (btns.includes('ok')) {
|
|
14027
|
+
const okBtn = document.createElement('button');
|
|
14028
|
+
okBtn.classList.add('primary-button', 'modal-button', 'action', 'ok');
|
|
14029
|
+
const okText = document.createElement('button-text');
|
|
14030
|
+
okText.textContent = okTxt;
|
|
14031
|
+
const okSpinner = document.createElement('loading-spinner');
|
|
14032
|
+
okBtn.append(okText, okSpinner);
|
|
14033
|
+
footer.appendChild(okBtn);
|
|
14034
|
+
}
|
|
14035
|
+
// END footer
|
|
14036
|
+
if (footer.hasChildNodes()) {
|
|
14037
|
+
wrapper.append(closeBtn, header, modalContent, footer);
|
|
14038
|
+
}
|
|
14039
|
+
else {
|
|
14040
|
+
wrapper.append(closeBtn, header, modalContent);
|
|
14041
|
+
}
|
|
14042
|
+
result.appendChild(wrapper);
|
|
14043
|
+
if (!persistent) {
|
|
14044
|
+
result.querySelector('.close').focus();
|
|
14045
|
+
}
|
|
14046
|
+
else {
|
|
14047
|
+
if (btns.includes('ok')) {
|
|
14048
|
+
result.querySelector('.ok').focus();
|
|
14049
|
+
}
|
|
14050
|
+
}
|
|
14051
|
+
attachEventHandlers(result, persistent, onClose);
|
|
14052
|
+
return result;
|
|
14008
14053
|
};
|
|
14009
14054
|
|
|
14010
|
-
const contactField = (tag = 'input', elType, elName, required = true, value) => {
|
|
14011
|
-
const result = document.createElement('contact-field');
|
|
14012
|
-
const elId = 'contact-' + elName;
|
|
14013
|
-
const label = document.createElement('label');
|
|
14014
|
-
label.textContent = getTranslation(elId + '-label');
|
|
14015
|
-
label.htmlFor = elId;
|
|
14016
|
-
const el = document.createElement(tag);
|
|
14017
|
-
el.id = elId;
|
|
14018
|
-
el.setAttribute('name', elName);
|
|
14019
|
-
el.setAttribute('placeholder', getTranslation(elId + '-placeholder'));
|
|
14020
|
-
if (tag === 'input') {
|
|
14021
|
-
el.setAttribute('type', elType);
|
|
14022
|
-
}
|
|
14023
|
-
if (required) {
|
|
14024
|
-
el.setAttribute('required', 'true');
|
|
14025
|
-
}
|
|
14026
|
-
if (value) {
|
|
14027
|
-
el.setAttribute('value', value);
|
|
14028
|
-
}
|
|
14029
|
-
result.append(label, el);
|
|
14030
|
-
return result;
|
|
14055
|
+
const contactField = (tag = 'input', elType, elName, required = true, value) => {
|
|
14056
|
+
const result = document.createElement('contact-field');
|
|
14057
|
+
const elId = 'contact-' + elName;
|
|
14058
|
+
const label = document.createElement('label');
|
|
14059
|
+
label.textContent = getTranslation(elId + '-label');
|
|
14060
|
+
label.htmlFor = elId;
|
|
14061
|
+
const el = document.createElement(tag);
|
|
14062
|
+
el.id = elId;
|
|
14063
|
+
el.setAttribute('name', elName);
|
|
14064
|
+
el.setAttribute('placeholder', getTranslation(elId + '-placeholder'));
|
|
14065
|
+
if (tag === 'input') {
|
|
14066
|
+
el.setAttribute('type', elType);
|
|
14067
|
+
}
|
|
14068
|
+
if (required) {
|
|
14069
|
+
el.setAttribute('required', 'true');
|
|
14070
|
+
}
|
|
14071
|
+
if (value) {
|
|
14072
|
+
el.setAttribute('value', value);
|
|
14073
|
+
}
|
|
14074
|
+
result.append(label, el);
|
|
14075
|
+
return result;
|
|
14031
14076
|
};
|
|
14032
14077
|
|
|
14033
|
-
const getNestedElValue = (el, nestedTag) => {
|
|
14034
|
-
const nestedEl = el.querySelector(nestedTag);
|
|
14035
|
-
return nestedEl.value;
|
|
14036
|
-
};
|
|
14037
|
-
const sendInquiry = (name, email, msg, whatsapp, subject, token) => {
|
|
14038
|
-
const inquiryPayload = {
|
|
14039
|
-
subject: `[${subject.charAt(0).toUpperCase()}${subject.slice(1)}] ${getNestedElValue(name, 'input')}`,
|
|
14078
|
+
const getNestedElValue = (el, nestedTag) => {
|
|
14079
|
+
const nestedEl = el.querySelector(nestedTag);
|
|
14080
|
+
return nestedEl.value;
|
|
14081
|
+
};
|
|
14082
|
+
const sendInquiry = (name, email, msg, whatsapp, subject, token) => {
|
|
14083
|
+
const inquiryPayload = {
|
|
14084
|
+
subject: `[${subject.charAt(0).toUpperCase()}${subject.slice(1)}] ${getNestedElValue(name, 'input')}`,
|
|
14040
14085
|
body: `<strong>Name</strong>: ${getNestedElValue(name, 'input')}<br><br>
|
|
14041
14086
|
<strong>E-mail</strong>: ${getNestedElValue(email, 'input')}<br><br>
|
|
14042
14087
|
<strong>Whatsapp</strong>: ${getNestedElValue(whatsapp, 'input')}<br><br>
|
|
14043
|
-
<strong>Message</strong>: ${getNestedElValue(msg, 'textarea')}`,
|
|
14044
|
-
token,
|
|
14045
|
-
};
|
|
14046
|
-
backendPost('contact-us', inquiryPayload, (_res) => {
|
|
14047
|
-
var _a;
|
|
14048
|
-
// success(getTranslation('form-success'), Length.long);
|
|
14049
|
-
(_a = document.querySelector('#contact-us-modal')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
14050
|
-
}, () => { } // TODO: change it to be an error handling fn provided by the client
|
|
14051
|
-
);
|
|
14052
|
-
// checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
|
|
14053
|
-
};
|
|
14054
|
-
const contactUsModal = (subject) => {
|
|
14055
|
-
var _a, _b, _c, _d, _e;
|
|
14056
|
-
const result = document.createElement('contact-us-modal');
|
|
14057
|
-
// @ts-ignore
|
|
14058
|
-
const currentName = window.store.currentUser ? window.store.currentUser.name : '';
|
|
14059
|
-
// @ts-ignore
|
|
14060
|
-
const currentEmail = window.store.currentUser ? window.store.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
|
|
14061
|
-
const modalBody = document.createElement('modal-body');
|
|
14062
|
-
const form = document.createElement('form');
|
|
14063
|
-
form.id = 'contact-form';
|
|
14064
|
-
const nameField = contactField('input', 'text', 'name', true, currentName);
|
|
14065
|
-
const emailField = contactField('input', 'email', 'email', true, currentEmail);
|
|
14066
|
-
const messageField = contactField('textarea', 'text', 'message', true);
|
|
14067
|
-
const whatsappField = contactField('input', 'tel', 'whatsapp', false);
|
|
14068
|
-
const btn = document.createElement('button');
|
|
14069
|
-
btn.textContent = getTranslation('contact-submit');
|
|
14070
|
-
btn.className = 'primary-button';
|
|
14071
|
-
form.append(nameField, emailField, whatsappField, messageField, btn);
|
|
14072
|
-
modalBody.appendChild(form);
|
|
14073
|
-
const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
|
|
14074
|
-
modal.id = 'contact-us-modal';
|
|
14075
|
-
document.body.appendChild(modal);
|
|
14076
|
-
(_b = modal.querySelector('modal-wrapper')) === null || _b === void 0 ? void 0 : _b.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
|
|
14077
|
-
const captcha = googleCaptcha();
|
|
14078
|
-
if (subject !== 'email-not-sent') {
|
|
14079
|
-
// @ts-ignore
|
|
14080
|
-
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;
|
|
14081
|
-
backendGet('credits-balance-for', { admin }, (res) => {
|
|
14082
|
-
const balance = res;
|
|
14083
|
-
if (balance <= 0) {
|
|
14084
|
-
form.insertBefore(captcha, btn);
|
|
14085
|
-
}
|
|
14086
|
-
}, () => { } // TODO: change it to be an error handling fn provided by the client
|
|
14087
|
-
);
|
|
14088
|
-
}
|
|
14089
|
-
else {
|
|
14090
|
-
form.insertBefore(captcha, btn);
|
|
14091
|
-
}
|
|
14092
|
-
(_e = nameField.querySelector('input')) === null || _e === void 0 ? void 0 : _e.select();
|
|
14093
|
-
form.addEventListener('submit', (event) => {
|
|
14094
|
-
event.preventDefault();
|
|
14095
|
-
sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
|
|
14096
|
-
});
|
|
14097
|
-
return result;
|
|
14088
|
+
<strong>Message</strong>: ${getNestedElValue(msg, 'textarea')}`,
|
|
14089
|
+
token,
|
|
14090
|
+
};
|
|
14091
|
+
backendPost('contact-us', inquiryPayload, (_res) => {
|
|
14092
|
+
var _a;
|
|
14093
|
+
// success(getTranslation('form-success'), Length.long);
|
|
14094
|
+
(_a = document.querySelector('#contact-us-modal')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
14095
|
+
}, () => { } // TODO: change it to be an error handling fn provided by the client
|
|
14096
|
+
);
|
|
14097
|
+
// checkMixpanel(() => mixpanel.track('Sent Contact Inquiry', {}));
|
|
14098
|
+
};
|
|
14099
|
+
const contactUsModal = (subject) => {
|
|
14100
|
+
var _a, _b, _c, _d, _e;
|
|
14101
|
+
const result = document.createElement('contact-us-modal');
|
|
14102
|
+
// @ts-ignore
|
|
14103
|
+
const currentName = window.store.currentUser ? window.store.currentUser.name : '';
|
|
14104
|
+
// @ts-ignore
|
|
14105
|
+
const currentEmail = window.store.currentUser ? window.store.currentUser.email : (_a = document.querySelector('#magic-link-email')) === null || _a === void 0 ? void 0 : _a.textContent;
|
|
14106
|
+
const modalBody = document.createElement('modal-body');
|
|
14107
|
+
const form = document.createElement('form');
|
|
14108
|
+
form.id = 'contact-form';
|
|
14109
|
+
const nameField = contactField('input', 'text', 'name', true, currentName);
|
|
14110
|
+
const emailField = contactField('input', 'email', 'email', true, currentEmail);
|
|
14111
|
+
const messageField = contactField('textarea', 'text', 'message', true);
|
|
14112
|
+
const whatsappField = contactField('input', 'tel', 'whatsapp', false);
|
|
14113
|
+
const btn = document.createElement('button');
|
|
14114
|
+
btn.textContent = getTranslation('contact-submit');
|
|
14115
|
+
btn.className = 'primary-button';
|
|
14116
|
+
form.append(nameField, emailField, whatsappField, messageField, btn);
|
|
14117
|
+
modalBody.appendChild(form);
|
|
14118
|
+
const modal = juxModal(getTranslation('contact-page'), [], '', false, false, modalBody, '', '', () => result.remove());
|
|
14119
|
+
modal.id = 'contact-us-modal';
|
|
14120
|
+
document.body.appendChild(modal);
|
|
14121
|
+
(_b = modal.querySelector('modal-wrapper')) === null || _b === void 0 ? void 0 : _b.setAttribute('style', 'max-width: 680px; width: 100%; overflow-y: auto;');
|
|
14122
|
+
const captcha = googleCaptcha();
|
|
14123
|
+
if (subject !== 'email-not-sent') {
|
|
14124
|
+
// @ts-ignore
|
|
14125
|
+
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;
|
|
14126
|
+
backendGet('credits-balance-for', { admin }, (res) => {
|
|
14127
|
+
const balance = res;
|
|
14128
|
+
if (balance <= 0) {
|
|
14129
|
+
form.insertBefore(captcha, btn);
|
|
14130
|
+
}
|
|
14131
|
+
}, () => { } // TODO: change it to be an error handling fn provided by the client
|
|
14132
|
+
);
|
|
14133
|
+
}
|
|
14134
|
+
else {
|
|
14135
|
+
form.insertBefore(captcha, btn);
|
|
14136
|
+
}
|
|
14137
|
+
(_e = nameField.querySelector('input')) === null || _e === void 0 ? void 0 : _e.select();
|
|
14138
|
+
form.addEventListener('submit', (event) => {
|
|
14139
|
+
event.preventDefault();
|
|
14140
|
+
sendInquiry(nameField, emailField, messageField, whatsappField, subject, captcha.getAttribute('token'));
|
|
14141
|
+
});
|
|
14142
|
+
return result;
|
|
14098
14143
|
};
|
|
14099
14144
|
|
|
14100
|
-
const applyContainerStyles = (container) => {
|
|
14101
|
-
container.style.backgroundColor = '#ffffffdd';
|
|
14102
|
-
container.style.borderRadius = '16px';
|
|
14103
|
-
container.style.inset = '50% 50% 50% 0';
|
|
14104
|
-
container.style.position = 'relative';
|
|
14105
|
-
container.style.transform = 'translateY(-50%)';
|
|
14106
|
-
container.style.width = '620px';
|
|
14107
|
-
container.style.alignItems = 'center';
|
|
14108
|
-
container.style.display = 'flex';
|
|
14109
|
-
container.style.flexDirection = 'column';
|
|
14110
|
-
container.style.fontSize = '16px';
|
|
14111
|
-
container.style.height = '100%';
|
|
14112
|
-
container.style.justifyContent = 'center';
|
|
14113
|
-
container.style.margin = '0 auto';
|
|
14114
|
-
container.style.paddingTop = '0';
|
|
14115
|
-
};
|
|
14116
|
-
const applyPageStyles = (page, backgroundImg) => {
|
|
14117
|
-
page.style.backgroundImage = `url(${backgroundImg})`;
|
|
14118
|
-
page.style.backgroundPosition = '50%';
|
|
14119
|
-
page.style.backgroundSize = 'cover';
|
|
14120
|
-
page.style.display = 'block';
|
|
14121
|
-
page.style.height = '100%';
|
|
14122
|
-
};
|
|
14123
|
-
const basePage = (pageName, backgroundImg, content) => {
|
|
14124
|
-
const result = document.createElement(pageName);
|
|
14125
|
-
result.className = 'base-login-page';
|
|
14126
|
-
applyPageStyles(result, backgroundImg);
|
|
14127
|
-
const section = document.createElement('section');
|
|
14128
|
-
applyContainerStyles(section);
|
|
14129
|
-
content.forEach(element => section.appendChild(element));
|
|
14130
|
-
result.appendChild(section);
|
|
14131
|
-
return result;
|
|
14145
|
+
const applyContainerStyles = (container) => {
|
|
14146
|
+
container.style.backgroundColor = '#ffffffdd';
|
|
14147
|
+
container.style.borderRadius = '16px';
|
|
14148
|
+
container.style.inset = '50% 50% 50% 0';
|
|
14149
|
+
container.style.position = 'relative';
|
|
14150
|
+
container.style.transform = 'translateY(-50%)';
|
|
14151
|
+
container.style.width = '620px';
|
|
14152
|
+
container.style.alignItems = 'center';
|
|
14153
|
+
container.style.display = 'flex';
|
|
14154
|
+
container.style.flexDirection = 'column';
|
|
14155
|
+
container.style.fontSize = '16px';
|
|
14156
|
+
container.style.height = '100%';
|
|
14157
|
+
container.style.justifyContent = 'center';
|
|
14158
|
+
container.style.margin = '0 auto';
|
|
14159
|
+
container.style.paddingTop = '0';
|
|
14160
|
+
};
|
|
14161
|
+
const applyPageStyles = (page, backgroundImg) => {
|
|
14162
|
+
page.style.backgroundImage = `url(${backgroundImg})`;
|
|
14163
|
+
page.style.backgroundPosition = '50%';
|
|
14164
|
+
page.style.backgroundSize = 'cover';
|
|
14165
|
+
page.style.display = 'block';
|
|
14166
|
+
page.style.height = '100%';
|
|
14167
|
+
};
|
|
14168
|
+
const basePage = (pageName, backgroundImg, content) => {
|
|
14169
|
+
const result = document.createElement(pageName);
|
|
14170
|
+
result.className = 'base-login-page';
|
|
14171
|
+
applyPageStyles(result, backgroundImg);
|
|
14172
|
+
const section = document.createElement('section');
|
|
14173
|
+
applyContainerStyles(section);
|
|
14174
|
+
content.forEach(element => section.appendChild(element));
|
|
14175
|
+
result.appendChild(section);
|
|
14176
|
+
return result;
|
|
14132
14177
|
};
|
|
14133
14178
|
|
|
14134
|
-
const applyBtnStyles = (btn) => {
|
|
14135
|
-
btn.style.cursor = 'pointer';
|
|
14136
|
-
btn.style.textDecoration = 'underline';
|
|
14137
|
-
btn.style.border = 'none';
|
|
14138
|
-
btn.style.backgroundColor = '';
|
|
14139
|
-
btn.style.background = 'none';
|
|
14140
|
-
btn.style.boxSizing = 'border-box';
|
|
14141
|
-
btn.style.margin = '0';
|
|
14142
|
-
btn.style.outline = 'none';
|
|
14143
|
-
btn.style.padding = '0';
|
|
14144
|
-
btn.style.whiteSpace = 'normal';
|
|
14145
|
-
btn.style.font = 'inherit';
|
|
14146
|
-
};
|
|
14147
|
-
const magicLinkRequestedPage = (backgroundImg, onReturn) => {
|
|
14148
|
-
const content = [];
|
|
14149
|
-
const sent = document.createElement('p');
|
|
14150
|
-
sent.id = 'magic-link-sent';
|
|
14151
|
-
sent.textContent = getTranslation(sent.id);
|
|
14152
|
-
sent.style.marginBottom = '10px';
|
|
14153
|
-
const email = document.createElement('p');
|
|
14154
|
-
email.id = 'magic-link-email';
|
|
14155
|
-
email.style.fontWeight = '700';
|
|
14156
|
-
email.style.marginBottom = '10px';
|
|
14157
|
-
const howTo = document.createElement('p');
|
|
14158
|
-
howTo.id = 'magic-link-how-to';
|
|
14159
|
-
howTo.innerHTML = getTranslation(howTo.id);
|
|
14160
|
-
howTo.style.padding = '0 30px';
|
|
14161
|
-
howTo.style.textAlign = 'center';
|
|
14162
|
-
const btn = document.createElement('button');
|
|
14163
|
-
btn.id = 'email-not-received-btn';
|
|
14164
|
-
btn.addEventListener('click', () => document.body.appendChild(contactUsModal('email-not-sent')));
|
|
14165
|
-
btn.textContent = getTranslation('magic-link-let-us-know');
|
|
14166
|
-
applyBtnStyles(btn);
|
|
14167
|
-
const returnLink = document.createElement('a');
|
|
14168
|
-
returnLink.textContent = getTranslation('return-link');
|
|
14169
|
-
returnLink.onclick = () => {
|
|
14170
|
-
result.remove();
|
|
14171
|
-
onReturn();
|
|
14172
|
-
};
|
|
14173
|
-
returnLink.style.marginTop = '32px';
|
|
14174
|
-
returnLink.style.cursor = 'pointer';
|
|
14175
|
-
returnLink.style.fontWeight = '700';
|
|
14176
|
-
returnLink.style.textDecoration = 'underline';
|
|
14177
|
-
content.push(sent, email, howTo, btn, returnLink);
|
|
14178
|
-
const result = basePage('magic-link-requested-page', backgroundImg, content);
|
|
14179
|
-
return result;
|
|
14179
|
+
const applyBtnStyles = (btn) => {
|
|
14180
|
+
btn.style.cursor = 'pointer';
|
|
14181
|
+
btn.style.textDecoration = 'underline';
|
|
14182
|
+
btn.style.border = 'none';
|
|
14183
|
+
btn.style.backgroundColor = '';
|
|
14184
|
+
btn.style.background = 'none';
|
|
14185
|
+
btn.style.boxSizing = 'border-box';
|
|
14186
|
+
btn.style.margin = '0';
|
|
14187
|
+
btn.style.outline = 'none';
|
|
14188
|
+
btn.style.padding = '0';
|
|
14189
|
+
btn.style.whiteSpace = 'normal';
|
|
14190
|
+
btn.style.font = 'inherit';
|
|
14191
|
+
};
|
|
14192
|
+
const magicLinkRequestedPage = (backgroundImg, onReturn) => {
|
|
14193
|
+
const content = [];
|
|
14194
|
+
const sent = document.createElement('p');
|
|
14195
|
+
sent.id = 'magic-link-sent';
|
|
14196
|
+
sent.textContent = getTranslation(sent.id);
|
|
14197
|
+
sent.style.marginBottom = '10px';
|
|
14198
|
+
const email = document.createElement('p');
|
|
14199
|
+
email.id = 'magic-link-email';
|
|
14200
|
+
email.style.fontWeight = '700';
|
|
14201
|
+
email.style.marginBottom = '10px';
|
|
14202
|
+
const howTo = document.createElement('p');
|
|
14203
|
+
howTo.id = 'magic-link-how-to';
|
|
14204
|
+
howTo.innerHTML = getTranslation(howTo.id);
|
|
14205
|
+
howTo.style.padding = '0 30px';
|
|
14206
|
+
howTo.style.textAlign = 'center';
|
|
14207
|
+
const btn = document.createElement('button');
|
|
14208
|
+
btn.id = 'email-not-received-btn';
|
|
14209
|
+
btn.addEventListener('click', () => document.body.appendChild(contactUsModal('email-not-sent')));
|
|
14210
|
+
btn.textContent = getTranslation('magic-link-let-us-know');
|
|
14211
|
+
applyBtnStyles(btn);
|
|
14212
|
+
const returnLink = document.createElement('a');
|
|
14213
|
+
returnLink.textContent = getTranslation('return-link');
|
|
14214
|
+
returnLink.onclick = () => {
|
|
14215
|
+
result.remove();
|
|
14216
|
+
onReturn();
|
|
14217
|
+
};
|
|
14218
|
+
returnLink.style.marginTop = '32px';
|
|
14219
|
+
returnLink.style.cursor = 'pointer';
|
|
14220
|
+
returnLink.style.fontWeight = '700';
|
|
14221
|
+
returnLink.style.textDecoration = 'underline';
|
|
14222
|
+
content.push(sent, email, howTo, btn, returnLink);
|
|
14223
|
+
const result = basePage('magic-link-requested-page', backgroundImg, content);
|
|
14224
|
+
return result;
|
|
14180
14225
|
};
|
|
14181
14226
|
|
|
14182
|
-
const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn) => {
|
|
14183
|
-
const content = [];
|
|
14184
|
-
const notSent = document.createElement('p');
|
|
14185
|
-
notSent.id = 'magic-link-not-sent';
|
|
14186
|
-
notSent.textContent = getTranslation(notSent.id);
|
|
14187
|
-
notSent.style.marginBottom = '10px';
|
|
14188
|
-
const email = document.createElement('p');
|
|
14189
|
-
email.id = 'magic-link-email';
|
|
14190
|
-
email.style.fontWeight = '700';
|
|
14191
|
-
email.style.marginBottom = '10px';
|
|
14192
|
-
const info = document.createElement('p');
|
|
14193
|
-
info.id = 'magic-link-fail-info';
|
|
14194
|
-
info.innerHTML = getTranslation(info.id);
|
|
14195
|
-
info.style.padding = '0 30px';
|
|
14196
|
-
info.style.textAlign = 'center';
|
|
14197
|
-
const back = document.createElement('a');
|
|
14198
|
-
back.textContent = getTranslation('return-link');
|
|
14199
|
-
back.onclick = () => {
|
|
14200
|
-
result.remove();
|
|
14201
|
-
onReturn();
|
|
14202
|
-
};
|
|
14203
|
-
back.style.marginTop = '32px';
|
|
14204
|
-
back.style.cursor = 'pointer';
|
|
14205
|
-
back.style.fontWeight = '700';
|
|
14206
|
-
back.style.textDecoration = 'underline';
|
|
14207
|
-
content.push(notSent, email, info, back);
|
|
14208
|
-
const result = basePage('unauthorized-magic-link-request-page', backgroundImg, content);
|
|
14209
|
-
return result;
|
|
14227
|
+
const unauthorizedMagicLinkRequestPage = (backgroundImg, onReturn) => {
|
|
14228
|
+
const content = [];
|
|
14229
|
+
const notSent = document.createElement('p');
|
|
14230
|
+
notSent.id = 'magic-link-not-sent';
|
|
14231
|
+
notSent.textContent = getTranslation(notSent.id);
|
|
14232
|
+
notSent.style.marginBottom = '10px';
|
|
14233
|
+
const email = document.createElement('p');
|
|
14234
|
+
email.id = 'magic-link-email';
|
|
14235
|
+
email.style.fontWeight = '700';
|
|
14236
|
+
email.style.marginBottom = '10px';
|
|
14237
|
+
const info = document.createElement('p');
|
|
14238
|
+
info.id = 'magic-link-fail-info';
|
|
14239
|
+
info.innerHTML = getTranslation(info.id);
|
|
14240
|
+
info.style.padding = '0 30px';
|
|
14241
|
+
info.style.textAlign = 'center';
|
|
14242
|
+
const back = document.createElement('a');
|
|
14243
|
+
back.textContent = getTranslation('return-link');
|
|
14244
|
+
back.onclick = () => {
|
|
14245
|
+
result.remove();
|
|
14246
|
+
onReturn();
|
|
14247
|
+
};
|
|
14248
|
+
back.style.marginTop = '32px';
|
|
14249
|
+
back.style.cursor = 'pointer';
|
|
14250
|
+
back.style.fontWeight = '700';
|
|
14251
|
+
back.style.textDecoration = 'underline';
|
|
14252
|
+
content.push(notSent, email, info, back);
|
|
14253
|
+
const result = basePage('unauthorized-magic-link-request-page', backgroundImg, content);
|
|
14254
|
+
return result;
|
|
14210
14255
|
};
|
|
14211
14256
|
|
|
14212
|
-
const setBackendToken = (token) => {
|
|
14213
|
-
// @ts-ignore
|
|
14214
|
-
window.store.backendToken = token;
|
|
14215
|
-
if (token) {
|
|
14216
|
-
localStorage.setItem('token', token);
|
|
14217
|
-
}
|
|
14218
|
-
};
|
|
14219
|
-
const getBackendToken = () => {
|
|
14220
|
-
var _a;
|
|
14221
|
-
const token = (_a = localStorage.getItem('token')) !== null && _a !== void 0 ? _a : '';
|
|
14222
|
-
// @ts-ignore
|
|
14223
|
-
window.store.backendToken = token;
|
|
14224
|
-
return token;
|
|
14225
|
-
};
|
|
14226
|
-
const onTokenAcquired = (token, onUserLogin) => {
|
|
14227
|
-
setBackendToken(token);
|
|
14228
|
-
// setSuperToken();
|
|
14229
|
-
onUserLogin();
|
|
14230
|
-
};
|
|
14231
|
-
const clearSession = () => {
|
|
14232
|
-
// onUserChanged(null);
|
|
14233
|
-
// TODO: find a better way to preserve backend-url
|
|
14234
|
-
const backendUrl = getBackendUrl(); // Preserve backend, since the authentication was succcessfull
|
|
14235
|
-
localStorage.clear();
|
|
14236
|
-
setBackendUrl(backendUrl);
|
|
14237
|
-
// @ts-ignore
|
|
14238
|
-
window.store = {};
|
|
14239
|
-
};
|
|
14240
|
-
const onAuthenticationFailure = (msg) => {
|
|
14241
|
-
localStorage.removeItem('token');
|
|
14242
|
-
// displayPage(Page.LOGIN);
|
|
14243
|
-
alert(getTranslation(msg));
|
|
14244
|
-
};
|
|
14245
|
-
const onAuthentication = (onUserLogin, user, type) => {
|
|
14246
|
-
if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
|
|
14247
|
-
clearSession();
|
|
14248
|
-
}
|
|
14249
|
-
// @ts-ignore
|
|
14250
|
-
window.store.currentUser = user;
|
|
14251
|
-
if (type === 'Token Authentication') {
|
|
14252
|
-
user.token = localStorage.getItem('token');
|
|
14253
|
-
}
|
|
14254
|
-
onTokenAcquired(user.token, onUserLogin);
|
|
14255
|
-
// mixpanelIdentify(user);
|
|
14256
|
-
// checkMixpanel(() => mixpanel.track('Login', { 'Login Type': type }));
|
|
14257
|
-
};
|
|
14258
|
-
const displayPage = (clientApp, page) => {
|
|
14259
|
-
Array.from(clientApp.children).forEach(el => el.remove());
|
|
14260
|
-
clientApp.appendChild(page);
|
|
14261
|
-
};
|
|
14262
|
-
const initSession = (clientApp, supportedLoginTypes, onUserLogin, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint) => {
|
|
14263
|
-
// if (startNewDemo()) {
|
|
14264
|
-
// initDemo(setBackendToken, onAuthentication);
|
|
14265
|
-
// return;
|
|
14266
|
-
// }
|
|
14267
|
-
// @ts-ignore
|
|
14268
|
-
if (!window.store) {
|
|
14269
|
-
// @ts-ignore
|
|
14270
|
-
window.store = {};
|
|
14271
|
-
}
|
|
14272
|
-
// @ts-ignore
|
|
14273
|
-
window.store.fetchUserBackendUrl = fetchUserBackendUrl;
|
|
14274
|
-
// @ts-ignore
|
|
14275
|
-
window.store.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
|
|
14276
|
-
// @ts-ignore
|
|
14277
|
-
window.store.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
|
|
14278
|
-
const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
|
|
14279
|
-
if (signInToken) {
|
|
14280
|
-
const onOpenMagicLink = () => {
|
|
14281
|
-
openMagicLink(signInToken, (res) => onAuthentication(onUserLogin, res, 'Magic Link'), () => onAuthenticationFailure('unable-magic-login'));
|
|
14282
|
-
};
|
|
14283
|
-
const host = extractTokenFromWindowLocation('host');
|
|
14284
|
-
if (host) {
|
|
14285
|
-
// @ts-ignore
|
|
14286
|
-
window.store.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
14287
|
-
setBackendUrl(backendUrl);
|
|
14288
|
-
onOpenMagicLink();
|
|
14289
|
-
});
|
|
14290
|
-
return;
|
|
14291
|
-
}
|
|
14292
|
-
onOpenMagicLink();
|
|
14293
|
-
return;
|
|
14294
|
-
}
|
|
14295
|
-
if (getBackendToken()) {
|
|
14296
|
-
backendGet('profile', null, (res) => onAuthentication(onUserLogin, res, 'Token Authentication'), (_err) => onAuthenticationFailure('login-failed'));
|
|
14297
|
-
return;
|
|
14298
|
-
}
|
|
14299
|
-
displayPage(clientApp, loginPage(clientApp, backgroundImage, onUserLogin, supportedLoginTypes));
|
|
14300
|
-
// const linkedinToken = extractTokenFromWindowLocation('code', '\&state=9893849343');
|
|
14301
|
-
// if (linkedinToken) {
|
|
14302
|
-
// openLinkedinSession(
|
|
14303
|
-
// linkedinToken,
|
|
14304
|
-
// (res) => onAuthentication(res, 'Linkedin Authentication'),
|
|
14305
|
-
// () => onAuthenticationFailure('unable-linkedin-login')
|
|
14306
|
-
// );
|
|
14307
|
-
// return;
|
|
14308
|
-
// }
|
|
14309
|
-
// validateThirdPartyCookies(initGapi, () => displayPage(Page.LOGIN));
|
|
14310
|
-
// checkMixpanel(() => mixpanel.track('View Login Page'));
|
|
14311
|
-
};
|
|
14312
|
-
const onMicrosoftSignIn = (onUserLogin) => __awaiter$2(void 0, void 0, void 0, function* () {
|
|
14313
|
-
const msalConfig = { auth: { clientId: process.env.MICROSOFT_CLIENT_ID } };
|
|
14314
|
-
const msalInstance = new PublicClientApplication(msalConfig);
|
|
14315
|
-
const loginRequest = { scopes: ['user.read'] };
|
|
14316
|
-
enableSignInLayout();
|
|
14317
|
-
try {
|
|
14318
|
-
const loginResponse = yield msalInstance.loginPopup(loginRequest);
|
|
14319
|
-
const { accessToken } = loginResponse;
|
|
14320
|
-
const onSuccess = (res) => {
|
|
14321
|
-
const { token } = res;
|
|
14322
|
-
// @ts-ignore
|
|
14323
|
-
window.store.currentUser = res;
|
|
14324
|
-
onTokenAcquired(token, onUserLogin);
|
|
14325
|
-
disableSignInLayout();
|
|
14326
|
-
};
|
|
14327
|
-
const onError = (err) => {
|
|
14328
|
-
console.error(err);
|
|
14329
|
-
reportError(err);
|
|
14330
|
-
disableSignInLayout();
|
|
14331
|
-
};
|
|
14332
|
-
microsoftLogin(accessToken, onSuccess, onError);
|
|
14333
|
-
}
|
|
14334
|
-
catch (err) {
|
|
14335
|
-
reportError(err);
|
|
14336
|
-
disableSignInLayout();
|
|
14337
|
-
}
|
|
14338
|
-
});
|
|
14339
|
-
const onCookieError = () => {
|
|
14340
|
-
disableSignInLayout();
|
|
14341
|
-
// warning('cookie-error'); TODO
|
|
14342
|
-
return;
|
|
14343
|
-
};
|
|
14344
|
-
const onGoogleSignIn = (onUserLogin) => {
|
|
14345
|
-
validateThirdPartyCookies(() => {
|
|
14346
|
-
enableSignInLayout();
|
|
14347
|
-
authSignIn(onUserLogin);
|
|
14348
|
-
}, onCookieError);
|
|
14349
|
-
};
|
|
14350
|
-
const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
|
|
14351
|
-
if (!email) {
|
|
14352
|
-
const mailMagic = document.querySelector('#mail-magic');
|
|
14353
|
-
email = mailMagic.value;
|
|
14354
|
-
}
|
|
14355
|
-
const payload = { email, token };
|
|
14356
|
-
const onRequestMagicLink = () => {
|
|
14357
|
-
const onResponse = (page) => {
|
|
14358
|
-
currentPage.remove();
|
|
14359
|
-
clientBody.appendChild(page);
|
|
14360
|
-
const magicLinkEmail = page.querySelector('#magic-link-email');
|
|
14361
|
-
magicLinkEmail.textContent = email;
|
|
14362
|
-
};
|
|
14363
|
-
const onSuccess = () => onResponse(magicLinkRequestedPage(backgroundImage, onReturn));
|
|
14364
|
-
const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
|
|
14365
|
-
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
14366
|
-
};
|
|
14367
|
-
// @ts-ignore
|
|
14368
|
-
if (window.store.fetchUserBackendUrl) {
|
|
14369
|
-
// @ts-ignore
|
|
14370
|
-
window.store.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
14371
|
-
setBackendUrl(backendUrl);
|
|
14372
|
-
onRequestMagicLink();
|
|
14373
|
-
});
|
|
14374
|
-
return;
|
|
14375
|
-
}
|
|
14376
|
-
onRequestMagicLink();
|
|
14257
|
+
const setBackendToken = (token) => {
|
|
14258
|
+
// @ts-ignore
|
|
14259
|
+
window.store.backendToken = token;
|
|
14260
|
+
if (token) {
|
|
14261
|
+
localStorage.setItem('token', token);
|
|
14262
|
+
}
|
|
14263
|
+
};
|
|
14264
|
+
const getBackendToken = () => {
|
|
14265
|
+
var _a;
|
|
14266
|
+
const token = (_a = localStorage.getItem('token')) !== null && _a !== void 0 ? _a : '';
|
|
14267
|
+
// @ts-ignore
|
|
14268
|
+
window.store.backendToken = token;
|
|
14269
|
+
return token;
|
|
14270
|
+
};
|
|
14271
|
+
const onTokenAcquired = (token, onUserLogin) => {
|
|
14272
|
+
setBackendToken(token);
|
|
14273
|
+
// setSuperToken();
|
|
14274
|
+
onUserLogin();
|
|
14275
|
+
};
|
|
14276
|
+
const clearSession = () => {
|
|
14277
|
+
// onUserChanged(null);
|
|
14278
|
+
// TODO: find a better way to preserve backend-url
|
|
14279
|
+
const backendUrl = getBackendUrl(); // Preserve backend, since the authentication was succcessfull
|
|
14280
|
+
localStorage.clear();
|
|
14281
|
+
setBackendUrl(backendUrl);
|
|
14282
|
+
// @ts-ignore
|
|
14283
|
+
window.store = {};
|
|
14284
|
+
};
|
|
14285
|
+
const onAuthenticationFailure = (msg) => {
|
|
14286
|
+
localStorage.removeItem('token');
|
|
14287
|
+
// displayPage(Page.LOGIN);
|
|
14288
|
+
alert(getTranslation(msg));
|
|
14289
|
+
};
|
|
14290
|
+
const onAuthentication = (onUserLogin, user, type) => {
|
|
14291
|
+
if ((user.token && getBackendToken()) && getBackendToken() !== user.token) {
|
|
14292
|
+
clearSession();
|
|
14293
|
+
}
|
|
14294
|
+
// @ts-ignore
|
|
14295
|
+
window.store.currentUser = user;
|
|
14296
|
+
if (type === 'Token Authentication') {
|
|
14297
|
+
user.token = localStorage.getItem('token');
|
|
14298
|
+
}
|
|
14299
|
+
onTokenAcquired(user.token, onUserLogin);
|
|
14300
|
+
// mixpanelIdentify(user);
|
|
14301
|
+
// checkMixpanel(() => mixpanel.track('Login', { 'Login Type': type }));
|
|
14302
|
+
};
|
|
14303
|
+
const displayPage = (clientApp, page) => {
|
|
14304
|
+
Array.from(clientApp.children).forEach(el => el.remove());
|
|
14305
|
+
clientApp.appendChild(page);
|
|
14306
|
+
};
|
|
14307
|
+
const initSession = (clientApp, supportedLoginTypes, onUserLogin, backgroundImage, fetchUserBackendUrl, magicLinkRequestEndpoint, magicLinkAuthEndpoint) => {
|
|
14308
|
+
// if (startNewDemo()) {
|
|
14309
|
+
// initDemo(setBackendToken, onAuthentication);
|
|
14310
|
+
// return;
|
|
14311
|
+
// }
|
|
14312
|
+
// @ts-ignore
|
|
14313
|
+
if (!window.store) {
|
|
14314
|
+
// @ts-ignore
|
|
14315
|
+
window.store = {};
|
|
14316
|
+
}
|
|
14317
|
+
// @ts-ignore
|
|
14318
|
+
window.store.fetchUserBackendUrl = fetchUserBackendUrl;
|
|
14319
|
+
// @ts-ignore
|
|
14320
|
+
window.store.magicLinkRequestEndpoint = magicLinkRequestEndpoint;
|
|
14321
|
+
// @ts-ignore
|
|
14322
|
+
window.store.magicLinkAuthEndpoint = magicLinkAuthEndpoint;
|
|
14323
|
+
const signInToken = extractTokenFromWindowLocation('sign-in') || extractTokenFromWindowLocation('magic-link');
|
|
14324
|
+
if (signInToken) {
|
|
14325
|
+
const onOpenMagicLink = () => {
|
|
14326
|
+
openMagicLink(signInToken, (res) => onAuthentication(onUserLogin, res, 'Magic Link'), () => onAuthenticationFailure('unable-magic-login'));
|
|
14327
|
+
};
|
|
14328
|
+
const host = extractTokenFromWindowLocation('host');
|
|
14329
|
+
if (host) {
|
|
14330
|
+
// @ts-ignore
|
|
14331
|
+
window.store.fetchUserBackendUrl({ host }, (backendUrl) => {
|
|
14332
|
+
setBackendUrl(backendUrl);
|
|
14333
|
+
onOpenMagicLink();
|
|
14334
|
+
});
|
|
14335
|
+
return;
|
|
14336
|
+
}
|
|
14337
|
+
onOpenMagicLink();
|
|
14338
|
+
return;
|
|
14339
|
+
}
|
|
14340
|
+
if (getBackendToken()) {
|
|
14341
|
+
backendGet('profile', null, (res) => onAuthentication(onUserLogin, res, 'Token Authentication'), (_err) => onAuthenticationFailure('login-failed'));
|
|
14342
|
+
return;
|
|
14343
|
+
}
|
|
14344
|
+
displayPage(clientApp, loginPage(clientApp, backgroundImage, onUserLogin, supportedLoginTypes));
|
|
14345
|
+
// const linkedinToken = extractTokenFromWindowLocation('code', '\&state=9893849343');
|
|
14346
|
+
// if (linkedinToken) {
|
|
14347
|
+
// openLinkedinSession(
|
|
14348
|
+
// linkedinToken,
|
|
14349
|
+
// (res) => onAuthentication(res, 'Linkedin Authentication'),
|
|
14350
|
+
// () => onAuthenticationFailure('unable-linkedin-login')
|
|
14351
|
+
// );
|
|
14352
|
+
// return;
|
|
14353
|
+
// }
|
|
14354
|
+
// validateThirdPartyCookies(initGapi, () => displayPage(Page.LOGIN));
|
|
14355
|
+
// checkMixpanel(() => mixpanel.track('View Login Page'));
|
|
14356
|
+
};
|
|
14357
|
+
const onMicrosoftSignIn = (onUserLogin) => __awaiter$2(void 0, void 0, void 0, function* () {
|
|
14358
|
+
const msalConfig = { auth: { clientId: process.env.MICROSOFT_CLIENT_ID } };
|
|
14359
|
+
const msalInstance = new PublicClientApplication(msalConfig);
|
|
14360
|
+
const loginRequest = { scopes: ['user.read'] };
|
|
14361
|
+
enableSignInLayout();
|
|
14362
|
+
try {
|
|
14363
|
+
const loginResponse = yield msalInstance.loginPopup(loginRequest);
|
|
14364
|
+
const { accessToken } = loginResponse;
|
|
14365
|
+
const onSuccess = (res) => {
|
|
14366
|
+
const { token } = res;
|
|
14367
|
+
// @ts-ignore
|
|
14368
|
+
window.store.currentUser = res;
|
|
14369
|
+
onTokenAcquired(token, onUserLogin);
|
|
14370
|
+
disableSignInLayout();
|
|
14371
|
+
};
|
|
14372
|
+
const onError = (err) => {
|
|
14373
|
+
console.error(err);
|
|
14374
|
+
reportError(err);
|
|
14375
|
+
disableSignInLayout();
|
|
14376
|
+
};
|
|
14377
|
+
microsoftLogin(accessToken, onSuccess, onError);
|
|
14378
|
+
}
|
|
14379
|
+
catch (err) {
|
|
14380
|
+
reportError(err);
|
|
14381
|
+
disableSignInLayout();
|
|
14382
|
+
}
|
|
14383
|
+
});
|
|
14384
|
+
const onCookieError = () => {
|
|
14385
|
+
disableSignInLayout();
|
|
14386
|
+
// warning('cookie-error'); TODO
|
|
14387
|
+
return;
|
|
14388
|
+
};
|
|
14389
|
+
const onGoogleSignIn = (onUserLogin) => {
|
|
14390
|
+
validateThirdPartyCookies(() => {
|
|
14391
|
+
enableSignInLayout();
|
|
14392
|
+
authSignIn(onUserLogin);
|
|
14393
|
+
}, onCookieError);
|
|
14394
|
+
};
|
|
14395
|
+
const handleMagicLinkRequest = (token, onReturn, backgroundImage, currentPage, clientBody, email = '') => {
|
|
14396
|
+
if (!email) {
|
|
14397
|
+
const mailMagic = document.querySelector('#mail-magic');
|
|
14398
|
+
email = mailMagic.value;
|
|
14399
|
+
}
|
|
14400
|
+
const payload = { email, token };
|
|
14401
|
+
const onRequestMagicLink = () => {
|
|
14402
|
+
const onResponse = (page) => {
|
|
14403
|
+
currentPage.remove();
|
|
14404
|
+
clientBody.appendChild(page);
|
|
14405
|
+
const magicLinkEmail = page.querySelector('#magic-link-email');
|
|
14406
|
+
magicLinkEmail.textContent = email;
|
|
14407
|
+
};
|
|
14408
|
+
const onSuccess = () => onResponse(magicLinkRequestedPage(backgroundImage, onReturn));
|
|
14409
|
+
const onUnauthorized = () => onResponse(unauthorizedMagicLinkRequestPage(backgroundImage, onReturn));
|
|
14410
|
+
requestMagicLink(payload, onSuccess, onUnauthorized);
|
|
14411
|
+
};
|
|
14412
|
+
// @ts-ignore
|
|
14413
|
+
if (window.store.fetchUserBackendUrl) {
|
|
14414
|
+
// @ts-ignore
|
|
14415
|
+
window.store.fetchUserBackendUrl({ email }, (backendUrl) => {
|
|
14416
|
+
setBackendUrl(backendUrl);
|
|
14417
|
+
onRequestMagicLink();
|
|
14418
|
+
});
|
|
14419
|
+
return;
|
|
14420
|
+
}
|
|
14421
|
+
onRequestMagicLink();
|
|
14377
14422
|
};
|
|
14378
14423
|
|
|
14379
|
-
const socialLoginModal = (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) => {
|
|
14380
|
-
const result = document.createElement('social-login-modal');
|
|
14381
|
-
const email = document.createElement('p');
|
|
14382
|
-
email.textContent = `"${userEmail}"`;
|
|
14383
|
-
const msg = document.createElement('social-login-msg');
|
|
14384
|
-
msg.textContent = getTranslation('social-login-recommendation') + mailExchanger + '.' + getTranslation('social-login-advantage');
|
|
14385
|
-
const body = document.createElement('social-login-body');
|
|
14386
|
-
const socialLoginBtn = mailExchanger === 'Microsoft' ?
|
|
14387
|
-
loginButton('Microsoft', () => onMicrosoftSignIn(onUserLogin)) :
|
|
14388
|
-
loginButton('Google', () => onGoogleSignIn(onUserLogin));
|
|
14389
|
-
const proceedMagicLinkRequest = document.createElement('a');
|
|
14390
|
-
proceedMagicLinkRequest.textContent = getTranslation('proceed-magic-link-request');
|
|
14391
|
-
proceedMagicLinkRequest.addEventListener('click', () => {
|
|
14392
|
-
handleMagicLinkRequest(token, onReturn, backgroundImage, currentPage, clientBody, userEmail);
|
|
14393
|
-
closeMagicLinkModal();
|
|
14394
|
-
result.remove();
|
|
14395
|
-
});
|
|
14396
|
-
body.append(email, msg, socialLoginBtn, proceedMagicLinkRequest);
|
|
14397
|
-
const modal = juxModal(getTranslation(`using-${mailExchanger.toLowerCase()}-email`), [], '', false, false, body, '', '', () => result.remove());
|
|
14398
|
-
modal.setAttribute('data-cy', 'social-login-modal');
|
|
14399
|
-
result.appendChild(modal);
|
|
14400
|
-
const wrapper = modal.querySelector('modal-wrapper');
|
|
14401
|
-
wrapper.style.maxWidth = '360px';
|
|
14402
|
-
wrapper.style.width = '100%';
|
|
14403
|
-
return result;
|
|
14424
|
+
const socialLoginModal = (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) => {
|
|
14425
|
+
const result = document.createElement('social-login-modal');
|
|
14426
|
+
const email = document.createElement('p');
|
|
14427
|
+
email.textContent = `"${userEmail}"`;
|
|
14428
|
+
const msg = document.createElement('social-login-msg');
|
|
14429
|
+
msg.textContent = getTranslation('social-login-recommendation') + mailExchanger + '.' + getTranslation('social-login-advantage');
|
|
14430
|
+
const body = document.createElement('social-login-body');
|
|
14431
|
+
const socialLoginBtn = mailExchanger === 'Microsoft' ?
|
|
14432
|
+
loginButton('Microsoft', () => onMicrosoftSignIn(onUserLogin)) :
|
|
14433
|
+
loginButton('Google', () => onGoogleSignIn(onUserLogin));
|
|
14434
|
+
const proceedMagicLinkRequest = document.createElement('a');
|
|
14435
|
+
proceedMagicLinkRequest.textContent = getTranslation('proceed-magic-link-request');
|
|
14436
|
+
proceedMagicLinkRequest.addEventListener('click', () => {
|
|
14437
|
+
handleMagicLinkRequest(token, onReturn, backgroundImage, currentPage, clientBody, userEmail);
|
|
14438
|
+
closeMagicLinkModal();
|
|
14439
|
+
result.remove();
|
|
14440
|
+
});
|
|
14441
|
+
body.append(email, msg, socialLoginBtn, proceedMagicLinkRequest);
|
|
14442
|
+
const modal = juxModal(getTranslation(`using-${mailExchanger.toLowerCase()}-email`), [], '', false, false, body, '', '', () => result.remove());
|
|
14443
|
+
modal.setAttribute('data-cy', 'social-login-modal');
|
|
14444
|
+
result.appendChild(modal);
|
|
14445
|
+
const wrapper = modal.querySelector('modal-wrapper');
|
|
14446
|
+
wrapper.style.maxWidth = '360px';
|
|
14447
|
+
wrapper.style.width = '100%';
|
|
14448
|
+
return result;
|
|
14404
14449
|
};
|
|
14405
14450
|
|
|
14406
|
-
const isValidEmail = (email) => {
|
|
14407
|
-
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,}))$/;
|
|
14408
|
-
return re.test(email);
|
|
14451
|
+
const isValidEmail = (email) => {
|
|
14452
|
+
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,}))$/;
|
|
14453
|
+
return re.test(email);
|
|
14409
14454
|
};
|
|
14410
14455
|
|
|
14411
|
-
const recommendSocialLogin = (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) => {
|
|
14412
|
-
var _a;
|
|
14413
|
-
(_a = document.querySelector('magic-link-modal')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
14414
|
-
document.body.appendChild(socialLoginModal(userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal));
|
|
14415
|
-
};
|
|
14416
|
-
const hasProvider = (data, provider) => {
|
|
14417
|
-
return data.some((entry) => entry.includes(provider));
|
|
14418
|
-
};
|
|
14419
|
-
const getMailExchanger = (domainName) => __awaiter$2(void 0, void 0, void 0, function* () {
|
|
14420
|
-
const data = yield getMXData(domainName);
|
|
14421
|
-
if (!data) {
|
|
14422
|
-
return null;
|
|
14423
|
-
}
|
|
14424
|
-
if (hasProvider(data, 'outlook.com')) {
|
|
14425
|
-
return 'Microsoft';
|
|
14426
|
-
}
|
|
14427
|
-
if (hasProvider(data, 'google.com')) {
|
|
14428
|
-
return 'Google';
|
|
14429
|
-
}
|
|
14430
|
-
return null;
|
|
14431
|
-
});
|
|
14432
|
-
const onMagicLinkRequest = (token, input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) => __awaiter$2(void 0, void 0, void 0, function* () {
|
|
14433
|
-
const email = input.value;
|
|
14434
|
-
if (!email.includes('-test@') && !token) {
|
|
14435
|
-
console.error('invalid-captcha-response');
|
|
14436
|
-
// logError('invalid-captcha-response');
|
|
14437
|
-
return;
|
|
14438
|
-
}
|
|
14439
|
-
if (isValidEmail(email)) {
|
|
14440
|
-
const domain = email.split('@')[1] || '';
|
|
14441
|
-
const mailExchanger = yield getMailExchanger(domain);
|
|
14442
|
-
const supportedMailExchanger = mailExchanger !== null;
|
|
14443
|
-
if (supportedMailExchanger && loginTypes.includes(mailExchanger)) {
|
|
14444
|
-
recommendSocialLogin(email, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal);
|
|
14445
|
-
return;
|
|
14446
|
-
}
|
|
14447
|
-
}
|
|
14448
|
-
handleMagicLinkRequest(token, onReturn, backgroundImage, currentPage, clientBody);
|
|
14449
|
-
closeMagicLinkModal();
|
|
14450
|
-
});
|
|
14451
|
-
const applyMagicEmailFieldStyle = (el) => {
|
|
14452
|
-
el.style.display = 'flex';
|
|
14453
|
-
el.style.flexFlow = 'column';
|
|
14454
|
-
el.style.marginTop = '8px';
|
|
14455
|
-
el.style.rowGap = '8px';
|
|
14456
|
-
el.style.width = '100%';
|
|
14457
|
-
};
|
|
14458
|
-
const applyInputStyle = (input) => {
|
|
14459
|
-
input.style.border = `1px solid ${juxDarkGrey}`;
|
|
14460
|
-
input.style.maxWidth = '390px';
|
|
14461
|
-
input.style.padding = '10px';
|
|
14462
|
-
input.style.width = '100%';
|
|
14463
|
-
input.style.backgroundColor = juxWhite;
|
|
14464
|
-
input.style.borderRadius = '8px';
|
|
14465
|
-
input.style.boxShadow = `inset 0 2px 3px ${juxDimmedDarkGrey}`;
|
|
14466
|
-
input.style.height = '40px';
|
|
14467
|
-
input.style.whiteSpace = 'pre-line';
|
|
14468
|
-
input.style.boxSizing = 'border-box';
|
|
14469
|
-
};
|
|
14470
|
-
const applyBtnStyle = (btn) => {
|
|
14471
|
-
btn.style.alignSelf = 'flex-end';
|
|
14472
|
-
btn.style.backgroundColor = juxLightGreen;
|
|
14473
|
-
btn.style.border = `2px solid ${juxLightGreen}`;
|
|
14474
|
-
btn.style.borderRadius = '8px';
|
|
14475
|
-
btn.style.color = juxWhite;
|
|
14476
|
-
btn.style.cursor = 'pointer';
|
|
14477
|
-
btn.style.display = 'inline-block';
|
|
14478
|
-
btn.style.fontWeight = '700';
|
|
14479
|
-
btn.style.height = '40px';
|
|
14480
|
-
btn.style.lineHeight = '1';
|
|
14481
|
-
btn.style.marginLeft = '10px';
|
|
14482
|
-
btn.style.padding = '10px 16px';
|
|
14483
|
-
btn.style.position = 'relative';
|
|
14484
|
-
};
|
|
14485
|
-
const magicEmailField = (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) => {
|
|
14486
|
-
const result = document.createElement('magic-email-field');
|
|
14487
|
-
applyMagicEmailFieldStyle(result);
|
|
14488
|
-
const captcha = googleCaptcha();
|
|
14489
|
-
const input = document.createElement('input');
|
|
14490
|
-
input.id = 'mail-magic';
|
|
14491
|
-
input.type = 'text';
|
|
14492
|
-
input.className = 'textfield';
|
|
14493
|
-
input.placeholder = 'e-mail';
|
|
14494
|
-
applyInputStyle(input);
|
|
14495
|
-
input.addEventListener('keydown', (ev) => {
|
|
14496
|
-
if (ev.key === 'Enter') {
|
|
14497
|
-
onMagicLinkRequest(captcha.getAttribute('token'), input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes);
|
|
14498
|
-
}
|
|
14499
|
-
});
|
|
14500
|
-
const btn = document.createElement('button');
|
|
14501
|
-
applyBtnStyle(btn);
|
|
14502
|
-
btn.id = 'send-magic';
|
|
14503
|
-
btn.className = 'primary-button';
|
|
14504
|
-
btn.addEventListener('click', (_ev) => onMagicLinkRequest(captcha.getAttribute('token'), input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes));
|
|
14505
|
-
btn.textContent = getTranslation('send-magic');
|
|
14506
|
-
result.append(input, captcha, btn);
|
|
14507
|
-
return result;
|
|
14456
|
+
const recommendSocialLogin = (userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal) => {
|
|
14457
|
+
var _a;
|
|
14458
|
+
(_a = document.querySelector('magic-link-modal')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
14459
|
+
document.body.appendChild(socialLoginModal(userEmail, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal));
|
|
14460
|
+
};
|
|
14461
|
+
const hasProvider = (data, provider) => {
|
|
14462
|
+
return data.some((entry) => entry.includes(provider));
|
|
14463
|
+
};
|
|
14464
|
+
const getMailExchanger = (domainName) => __awaiter$2(void 0, void 0, void 0, function* () {
|
|
14465
|
+
const data = yield getMXData(domainName);
|
|
14466
|
+
if (!data) {
|
|
14467
|
+
return null;
|
|
14468
|
+
}
|
|
14469
|
+
if (hasProvider(data, 'outlook.com')) {
|
|
14470
|
+
return 'Microsoft';
|
|
14471
|
+
}
|
|
14472
|
+
if (hasProvider(data, 'google.com')) {
|
|
14473
|
+
return 'Google';
|
|
14474
|
+
}
|
|
14475
|
+
return null;
|
|
14476
|
+
});
|
|
14477
|
+
const onMagicLinkRequest = (token, input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) => __awaiter$2(void 0, void 0, void 0, function* () {
|
|
14478
|
+
const email = input.value;
|
|
14479
|
+
if (!email.includes('-test@') && !token) {
|
|
14480
|
+
console.error('invalid-captcha-response');
|
|
14481
|
+
// logError('invalid-captcha-response');
|
|
14482
|
+
return;
|
|
14483
|
+
}
|
|
14484
|
+
if (isValidEmail(email)) {
|
|
14485
|
+
const domain = email.split('@')[1] || '';
|
|
14486
|
+
const mailExchanger = yield getMailExchanger(domain);
|
|
14487
|
+
const supportedMailExchanger = mailExchanger !== null;
|
|
14488
|
+
if (supportedMailExchanger && loginTypes.includes(mailExchanger)) {
|
|
14489
|
+
recommendSocialLogin(email, mailExchanger, token, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal);
|
|
14490
|
+
return;
|
|
14491
|
+
}
|
|
14492
|
+
}
|
|
14493
|
+
handleMagicLinkRequest(token, onReturn, backgroundImage, currentPage, clientBody);
|
|
14494
|
+
closeMagicLinkModal();
|
|
14495
|
+
});
|
|
14496
|
+
const applyMagicEmailFieldStyle = (el) => {
|
|
14497
|
+
el.style.display = 'flex';
|
|
14498
|
+
el.style.flexFlow = 'column';
|
|
14499
|
+
el.style.marginTop = '8px';
|
|
14500
|
+
el.style.rowGap = '8px';
|
|
14501
|
+
el.style.width = '100%';
|
|
14502
|
+
};
|
|
14503
|
+
const applyInputStyle = (input) => {
|
|
14504
|
+
input.style.border = `1px solid ${juxDarkGrey}`;
|
|
14505
|
+
input.style.maxWidth = '390px';
|
|
14506
|
+
input.style.padding = '10px';
|
|
14507
|
+
input.style.width = '100%';
|
|
14508
|
+
input.style.backgroundColor = juxWhite;
|
|
14509
|
+
input.style.borderRadius = '8px';
|
|
14510
|
+
input.style.boxShadow = `inset 0 2px 3px ${juxDimmedDarkGrey}`;
|
|
14511
|
+
input.style.height = '40px';
|
|
14512
|
+
input.style.whiteSpace = 'pre-line';
|
|
14513
|
+
input.style.boxSizing = 'border-box';
|
|
14514
|
+
};
|
|
14515
|
+
const applyBtnStyle = (btn) => {
|
|
14516
|
+
btn.style.alignSelf = 'flex-end';
|
|
14517
|
+
btn.style.backgroundColor = juxLightGreen;
|
|
14518
|
+
btn.style.border = `2px solid ${juxLightGreen}`;
|
|
14519
|
+
btn.style.borderRadius = '8px';
|
|
14520
|
+
btn.style.color = juxWhite;
|
|
14521
|
+
btn.style.cursor = 'pointer';
|
|
14522
|
+
btn.style.display = 'inline-block';
|
|
14523
|
+
btn.style.fontWeight = '700';
|
|
14524
|
+
btn.style.height = '40px';
|
|
14525
|
+
btn.style.lineHeight = '1';
|
|
14526
|
+
btn.style.marginLeft = '10px';
|
|
14527
|
+
btn.style.padding = '10px 16px';
|
|
14528
|
+
btn.style.position = 'relative';
|
|
14529
|
+
};
|
|
14530
|
+
const magicEmailField = (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes) => {
|
|
14531
|
+
const result = document.createElement('magic-email-field');
|
|
14532
|
+
applyMagicEmailFieldStyle(result);
|
|
14533
|
+
const captcha = googleCaptcha();
|
|
14534
|
+
const input = document.createElement('input');
|
|
14535
|
+
input.id = 'mail-magic';
|
|
14536
|
+
input.type = 'text';
|
|
14537
|
+
input.className = 'textfield';
|
|
14538
|
+
input.placeholder = 'e-mail';
|
|
14539
|
+
applyInputStyle(input);
|
|
14540
|
+
input.addEventListener('keydown', (ev) => {
|
|
14541
|
+
if (ev.key === 'Enter') {
|
|
14542
|
+
onMagicLinkRequest(captcha.getAttribute('token'), input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes);
|
|
14543
|
+
}
|
|
14544
|
+
});
|
|
14545
|
+
const btn = document.createElement('button');
|
|
14546
|
+
applyBtnStyle(btn);
|
|
14547
|
+
btn.id = 'send-magic';
|
|
14548
|
+
btn.className = 'primary-button';
|
|
14549
|
+
btn.addEventListener('click', (_ev) => onMagicLinkRequest(captcha.getAttribute('token'), input, onUserLogin, onReturn, backgroundImage, currentPage, clientBody, closeMagicLinkModal, loginTypes));
|
|
14550
|
+
btn.textContent = getTranslation('send-magic');
|
|
14551
|
+
result.append(input, captcha, btn);
|
|
14552
|
+
return result;
|
|
14508
14553
|
};
|
|
14509
14554
|
|
|
14510
|
-
const magicLinkModal = (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, loginTypes) => {
|
|
14511
|
-
const result = document.createElement('magic-link-modal');
|
|
14512
|
-
const subtitle = document.createElement('magic-link-request-subtitle');
|
|
14513
|
-
subtitle.style.fontSize = '14px';
|
|
14514
|
-
subtitle.textContent = getTranslation('magic-link-request-subtitle');
|
|
14515
|
-
const body = document.createElement('magic-link-request-body');
|
|
14516
|
-
body.append(subtitle, magicEmailField(onUserLogin, onReturn, backgroundImage, currentPage, clientBody, () => result.remove(), loginTypes));
|
|
14517
|
-
const modal = juxModal(getTranslation('magic-link-request-title'), [], '', false, false, body, '', '', () => result.remove());
|
|
14518
|
-
modal.setAttribute('data-cy', 'magic-link-modal');
|
|
14519
|
-
result.appendChild(modal);
|
|
14520
|
-
const wrapper = modal.querySelector('modal-wrapper');
|
|
14521
|
-
wrapper.style.maxWidth = '360px';
|
|
14522
|
-
wrapper.style.width = '100%';
|
|
14523
|
-
return result;
|
|
14555
|
+
const magicLinkModal = (onUserLogin, onReturn, backgroundImage, currentPage, clientBody, loginTypes) => {
|
|
14556
|
+
const result = document.createElement('magic-link-modal');
|
|
14557
|
+
const subtitle = document.createElement('magic-link-request-subtitle');
|
|
14558
|
+
subtitle.style.fontSize = '14px';
|
|
14559
|
+
subtitle.textContent = getTranslation('magic-link-request-subtitle');
|
|
14560
|
+
const body = document.createElement('magic-link-request-body');
|
|
14561
|
+
body.append(subtitle, magicEmailField(onUserLogin, onReturn, backgroundImage, currentPage, clientBody, () => result.remove(), loginTypes));
|
|
14562
|
+
const modal = juxModal(getTranslation('magic-link-request-title'), [], '', false, false, body, '', '', () => result.remove());
|
|
14563
|
+
modal.setAttribute('data-cy', 'magic-link-modal');
|
|
14564
|
+
result.appendChild(modal);
|
|
14565
|
+
const wrapper = modal.querySelector('modal-wrapper');
|
|
14566
|
+
wrapper.style.maxWidth = '360px';
|
|
14567
|
+
wrapper.style.width = '100%';
|
|
14568
|
+
return result;
|
|
14524
14569
|
};
|
|
14525
14570
|
|
|
14526
|
-
const onEmailLoginRequest = (clientApp, loginPage, onUserLogin, backgroundImage, loginTypes) => {
|
|
14527
|
-
const onReturn = () => clientApp.appendChild(loginPage);
|
|
14528
|
-
loginPage.appendChild(magicLinkModal(onUserLogin, onReturn, backgroundImage, loginPage, clientApp, loginTypes));
|
|
14529
|
-
};
|
|
14530
|
-
const appendLoginTypes = (loginPage, section, clientApp, onUserLogin, loginTypes, backgroundImg) => {
|
|
14531
|
-
if (loginTypes.includes('Google')) {
|
|
14532
|
-
section.appendChild(loginButton('Google', () => onGoogleSignIn(onUserLogin)));
|
|
14533
|
-
}
|
|
14534
|
-
if (loginTypes.includes('Microsoft')) {
|
|
14535
|
-
section.appendChild(loginButton('Microsoft', () => onMicrosoftSignIn(onUserLogin)));
|
|
14536
|
-
}
|
|
14537
|
-
if (loginTypes.includes('Linkedin')) {
|
|
14538
|
-
section.appendChild(loginButton('LinkedIn', () => console.log('login with Linkedin')));
|
|
14539
|
-
}
|
|
14540
|
-
if (loginTypes.includes('Email')) {
|
|
14541
|
-
section.appendChild(loginButton('Email', () => onEmailLoginRequest(clientApp, loginPage, onUserLogin, backgroundImg, loginTypes)));
|
|
14542
|
-
}
|
|
14543
|
-
};
|
|
14544
|
-
const loginPage = (clientApp, backgroundImg, onUserLogin, loginTypes) => {
|
|
14545
|
-
const content = [];
|
|
14546
|
-
const salutation = document.createElement('sign-in-salutation');
|
|
14547
|
-
salutation.textContent = getTranslation('sign-in-salutation');
|
|
14548
|
-
const explanation = document.createElement('sign-in-explanation');
|
|
14549
|
-
explanation.textContent = getTranslation('sign-in-explanation');
|
|
14550
|
-
const msg = document.createElement('sign-in-msg');
|
|
14551
|
-
msg.textContent = getTranslation('sign-in-msg-general');
|
|
14552
|
-
content.push(salutation, explanation, msg);
|
|
14553
|
-
const result = basePage('login-page', backgroundImg, content);
|
|
14554
|
-
const section = result.querySelector('section');
|
|
14555
|
-
appendLoginTypes(result, section, clientApp, onUserLogin, loginTypes, backgroundImg);
|
|
14556
|
-
return result;
|
|
14571
|
+
const onEmailLoginRequest = (clientApp, loginPage, onUserLogin, backgroundImage, loginTypes) => {
|
|
14572
|
+
const onReturn = () => clientApp.appendChild(loginPage);
|
|
14573
|
+
loginPage.appendChild(magicLinkModal(onUserLogin, onReturn, backgroundImage, loginPage, clientApp, loginTypes));
|
|
14574
|
+
};
|
|
14575
|
+
const appendLoginTypes = (loginPage, section, clientApp, onUserLogin, loginTypes, backgroundImg) => {
|
|
14576
|
+
if (loginTypes.includes('Google')) {
|
|
14577
|
+
section.appendChild(loginButton('Google', () => onGoogleSignIn(onUserLogin)));
|
|
14578
|
+
}
|
|
14579
|
+
if (loginTypes.includes('Microsoft')) {
|
|
14580
|
+
section.appendChild(loginButton('Microsoft', () => onMicrosoftSignIn(onUserLogin)));
|
|
14581
|
+
}
|
|
14582
|
+
if (loginTypes.includes('Linkedin')) {
|
|
14583
|
+
section.appendChild(loginButton('LinkedIn', () => console.log('login with Linkedin')));
|
|
14584
|
+
}
|
|
14585
|
+
if (loginTypes.includes('Email')) {
|
|
14586
|
+
section.appendChild(loginButton('Email', () => onEmailLoginRequest(clientApp, loginPage, onUserLogin, backgroundImg, loginTypes)));
|
|
14587
|
+
}
|
|
14588
|
+
};
|
|
14589
|
+
const loginPage = (clientApp, backgroundImg, onUserLogin, loginTypes) => {
|
|
14590
|
+
const content = [];
|
|
14591
|
+
const salutation = document.createElement('sign-in-salutation');
|
|
14592
|
+
salutation.textContent = getTranslation('sign-in-salutation');
|
|
14593
|
+
const explanation = document.createElement('sign-in-explanation');
|
|
14594
|
+
explanation.textContent = getTranslation('sign-in-explanation');
|
|
14595
|
+
const msg = document.createElement('sign-in-msg');
|
|
14596
|
+
msg.textContent = getTranslation('sign-in-msg-general');
|
|
14597
|
+
content.push(salutation, explanation, msg);
|
|
14598
|
+
const result = basePage('login-page', backgroundImg, content);
|
|
14599
|
+
const section = result.querySelector('section');
|
|
14600
|
+
appendLoginTypes(result, section, clientApp, onUserLogin, loginTypes, backgroundImg);
|
|
14601
|
+
return result;
|
|
14557
14602
|
};
|
|
14558
14603
|
|
|
14559
|
-
class JuxEvent extends Event {
|
|
14560
|
-
constructor(method, endpoint, onResult, params, onError) {
|
|
14561
|
-
super('jux-event', { bubbles: true, cancelable: true, composed: true });
|
|
14562
|
-
this.
|
|
14563
|
-
this.
|
|
14564
|
-
this.
|
|
14565
|
-
this.
|
|
14566
|
-
this.
|
|
14567
|
-
|
|
14568
|
-
|
|
14569
|
-
|
|
14570
|
-
|
|
14571
|
-
|
|
14572
|
-
|
|
14573
|
-
|
|
14604
|
+
class JuxEvent extends Event {
|
|
14605
|
+
constructor(type, method, endpoint, onResult, params, onError, onRedirect) {
|
|
14606
|
+
super('jux-event', { bubbles: true, cancelable: true, composed: true });
|
|
14607
|
+
this.requestType = type;
|
|
14608
|
+
this.method = method;
|
|
14609
|
+
this.endpoint = endpoint;
|
|
14610
|
+
this.onResult = onResult;
|
|
14611
|
+
this.params = params;
|
|
14612
|
+
this.onError = onError;
|
|
14613
|
+
this.onRedirect = onRedirect;
|
|
14614
|
+
}
|
|
14615
|
+
}
|
|
14616
|
+
const query = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
14617
|
+
element.dispatchEvent(new JuxEvent('query', 'POST', endpoint, onResult, params, onError, onRedirect));
|
|
14618
|
+
};
|
|
14619
|
+
const command = (element, endpoint, onResult, params, onError, onRedirect) => {
|
|
14620
|
+
element.dispatchEvent(new JuxEvent('command', 'POST', endpoint, onResult, params, onError, onRedirect));
|
|
14574
14621
|
};
|
|
14575
14622
|
|
|
14576
14623
|
exports.chosenLanguage = chosenLanguage;
|
|
14577
14624
|
exports.command = command;
|
|
14578
14625
|
exports.getTranslation = getTranslation;
|
|
14579
|
-
exports.
|
|
14626
|
+
exports.handleJuxEvent = handleJuxEvent;
|
|
14580
14627
|
exports.handleMagicLinkRequest = handleMagicLinkRequest;
|
|
14581
14628
|
exports.initLanguage = initLanguage;
|
|
14582
14629
|
exports.initSession = initSession;
|