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