@klauswuestefeld/jux-web 2024.2.7 → 2024.3.13

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