@klauswuestefeld/jux-web 2024.2.7 → 2024.3.13

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