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