@entur-partner/app-shell 2.2.1 → 2.4.0
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/AppShell.d.ts +3 -1
- package/dist/EnvironmentBanner.d.ts +6 -0
- package/dist/app-shell.cjs.development.js +97 -25
- package/dist/app-shell.cjs.development.js.map +1 -1
- package/dist/app-shell.cjs.production.min.js +1 -1
- package/dist/app-shell.cjs.production.min.js.map +1 -1
- package/dist/app-shell.esm.js +97 -25
- package/dist/app-shell.esm.js.map +1 -1
- package/package.json +5 -5
- package/CHANGELOG.md +0 -172
package/dist/AppShell.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { GetTokenSilentlyOptions } from '@auth0/auth0-spa-js';
|
|
3
3
|
import { User } from '@entur-partner/micro-frontend';
|
|
4
|
+
import { Environment } from '@entur-partner/common';
|
|
4
5
|
import { DecorateUserFn } from './UserTypes';
|
|
5
6
|
export interface AppShellValues {
|
|
6
7
|
logout: () => void;
|
|
@@ -14,5 +15,6 @@ export interface AppShellProps {
|
|
|
14
15
|
clientId: string;
|
|
15
16
|
decorateUser: DecorateUserFn;
|
|
16
17
|
redirectUri?: string;
|
|
18
|
+
environment?: Environment;
|
|
17
19
|
}
|
|
18
|
-
export declare const AppShell: ({ children, audience, domain, clientId, redirectUri, decorateUser, }: AppShellProps) => JSX.Element;
|
|
20
|
+
export declare const AppShell: ({ children, audience, domain, clientId, redirectUri, decorateUser, environment, }: AppShellProps) => JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Environment } from '@entur-partner/common';
|
|
2
|
+
declare type EnvironmentBannerProps = {
|
|
3
|
+
environment: Exclude<Environment, Environment.Production>;
|
|
4
|
+
};
|
|
5
|
+
export declare const EnvironmentBanner: ({ environment }: EnvironmentBannerProps) => JSX.Element;
|
|
6
|
+
export {};
|
|
@@ -6,9 +6,10 @@ var React = require('react');
|
|
|
6
6
|
var loader = require('@entur/loader');
|
|
7
7
|
var alert = require('@entur/alert');
|
|
8
8
|
var tokens = require('@entur/tokens');
|
|
9
|
+
var typography = require('@entur/typography');
|
|
9
10
|
var util = require('@entur-partner/util');
|
|
10
|
-
var createAuth0Client = require('@auth0/auth0-spa-js');
|
|
11
11
|
var common = require('@entur-partner/common');
|
|
12
|
+
var createAuth0Client = require('@auth0/auth0-spa-js');
|
|
12
13
|
|
|
13
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
15
|
|
|
@@ -846,6 +847,7 @@ function authReducer(state, event) {
|
|
|
846
847
|
|
|
847
848
|
var _excluded$2 = ["children", "decorateUser"];
|
|
848
849
|
var POST_LOGIN_ROUTE_KEY = '@entur-partner:post-login-route';
|
|
850
|
+
var LOGIN_LAST_RETRY = '@entur-partner:last-login-retry';
|
|
849
851
|
|
|
850
852
|
var redirect = function redirect(pathname) {
|
|
851
853
|
if (pathname === void 0) {
|
|
@@ -961,12 +963,61 @@ var AuthProvider = function AuthProvider(_ref) {
|
|
|
961
963
|
};
|
|
962
964
|
}();
|
|
963
965
|
|
|
964
|
-
initAuth0()["catch"](function (
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
966
|
+
initAuth0()["catch"]( /*#__PURE__*/function () {
|
|
967
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(error) {
|
|
968
|
+
var _localStorage$getItem, lastRetryEpochSeconds, nowEpochSeconds, timeSinceLastRetry, minimumTimeForRetry;
|
|
969
|
+
|
|
970
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
971
|
+
while (1) {
|
|
972
|
+
switch (_context2.prev = _context2.next) {
|
|
973
|
+
case 0:
|
|
974
|
+
_context2.prev = 0;
|
|
975
|
+
lastRetryEpochSeconds = parseInt((_localStorage$getItem = localStorage.getItem(LOGIN_LAST_RETRY)) != null ? _localStorage$getItem : '0');
|
|
976
|
+
nowEpochSeconds = Math.floor(Date.now() / 1000);
|
|
977
|
+
timeSinceLastRetry = nowEpochSeconds - lastRetryEpochSeconds;
|
|
978
|
+
minimumTimeForRetry = 120; // Has there been more than x seconds since last retry?
|
|
979
|
+
|
|
980
|
+
if (!(timeSinceLastRetry >= minimumTimeForRetry)) {
|
|
981
|
+
_context2.next = 12;
|
|
982
|
+
break;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
localStorage.setItem(LOGIN_LAST_RETRY, nowEpochSeconds.toString());
|
|
986
|
+
redirect('/');
|
|
987
|
+
_context2.next = 10;
|
|
988
|
+
return initAuth0();
|
|
989
|
+
|
|
990
|
+
case 10:
|
|
991
|
+
_context2.next = 13;
|
|
992
|
+
break;
|
|
993
|
+
|
|
994
|
+
case 12:
|
|
995
|
+
throw error;
|
|
996
|
+
|
|
997
|
+
case 13:
|
|
998
|
+
_context2.next = 18;
|
|
999
|
+
break;
|
|
1000
|
+
|
|
1001
|
+
case 15:
|
|
1002
|
+
_context2.prev = 15;
|
|
1003
|
+
_context2.t0 = _context2["catch"](0);
|
|
1004
|
+
dispatch({
|
|
1005
|
+
type: 'ERROR',
|
|
1006
|
+
error: error
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
case 18:
|
|
1010
|
+
case "end":
|
|
1011
|
+
return _context2.stop();
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}, _callee2, null, [[0, 15]]);
|
|
1015
|
+
}));
|
|
1016
|
+
|
|
1017
|
+
return function (_x) {
|
|
1018
|
+
return _ref3.apply(this, arguments);
|
|
1019
|
+
};
|
|
1020
|
+
}()); // eslint-disable-next-line
|
|
970
1021
|
}, []);
|
|
971
1022
|
|
|
972
1023
|
var logout = function logout() {
|
|
@@ -981,12 +1032,12 @@ var AuthProvider = function AuthProvider(_ref) {
|
|
|
981
1032
|
};
|
|
982
1033
|
|
|
983
1034
|
var login = /*#__PURE__*/function () {
|
|
984
|
-
var
|
|
1035
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(redirectUri) {
|
|
985
1036
|
var _window, location;
|
|
986
1037
|
|
|
987
|
-
return _regeneratorRuntime.wrap(function
|
|
1038
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
988
1039
|
while (1) {
|
|
989
|
-
switch (
|
|
1040
|
+
switch (_context3.prev = _context3.next) {
|
|
990
1041
|
case 0:
|
|
991
1042
|
if (redirectUri === void 0) {
|
|
992
1043
|
redirectUri = window.location.origin;
|
|
@@ -1001,36 +1052,36 @@ var AuthProvider = function AuthProvider(_ref) {
|
|
|
1001
1052
|
|
|
1002
1053
|
case 5:
|
|
1003
1054
|
case "end":
|
|
1004
|
-
return
|
|
1055
|
+
return _context3.stop();
|
|
1005
1056
|
}
|
|
1006
1057
|
}
|
|
1007
|
-
},
|
|
1058
|
+
}, _callee3);
|
|
1008
1059
|
}));
|
|
1009
1060
|
|
|
1010
|
-
return function login(
|
|
1011
|
-
return
|
|
1061
|
+
return function login(_x2) {
|
|
1062
|
+
return _ref4.apply(this, arguments);
|
|
1012
1063
|
};
|
|
1013
1064
|
}();
|
|
1014
1065
|
|
|
1015
1066
|
var getToken = /*#__PURE__*/function () {
|
|
1016
|
-
var
|
|
1017
|
-
return _regeneratorRuntime.wrap(function
|
|
1067
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(options) {
|
|
1068
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
1018
1069
|
while (1) {
|
|
1019
|
-
switch (
|
|
1070
|
+
switch (_context4.prev = _context4.next) {
|
|
1020
1071
|
case 0:
|
|
1021
1072
|
util.assertIsDefined(auth0Client);
|
|
1022
|
-
return
|
|
1073
|
+
return _context4.abrupt("return", auth0Client.getTokenSilently(options));
|
|
1023
1074
|
|
|
1024
1075
|
case 2:
|
|
1025
1076
|
case "end":
|
|
1026
|
-
return
|
|
1077
|
+
return _context4.stop();
|
|
1027
1078
|
}
|
|
1028
1079
|
}
|
|
1029
|
-
},
|
|
1080
|
+
}, _callee4);
|
|
1030
1081
|
}));
|
|
1031
1082
|
|
|
1032
|
-
return function getToken(
|
|
1033
|
-
return
|
|
1083
|
+
return function getToken(_x3) {
|
|
1084
|
+
return _ref5.apply(this, arguments);
|
|
1034
1085
|
};
|
|
1035
1086
|
}();
|
|
1036
1087
|
|
|
@@ -1044,6 +1095,22 @@ var AuthProvider = function AuthProvider(_ref) {
|
|
|
1044
1095
|
}, children);
|
|
1045
1096
|
};
|
|
1046
1097
|
|
|
1098
|
+
var EnvironmentBanner = function EnvironmentBanner(_ref) {
|
|
1099
|
+
var environment = _ref.environment;
|
|
1100
|
+
return React__default["default"].createElement("div", {
|
|
1101
|
+
style: {
|
|
1102
|
+
position: 'fixed',
|
|
1103
|
+
zIndex: 9999,
|
|
1104
|
+
top: 0,
|
|
1105
|
+
left: 0,
|
|
1106
|
+
right: 0,
|
|
1107
|
+
width: '100vw',
|
|
1108
|
+
height: '16px',
|
|
1109
|
+
backgroundColor: common.getColorForEnvironment(environment)
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1047
1114
|
var Login = function Login(_ref) {
|
|
1048
1115
|
var redirectUri = _ref.redirectUri;
|
|
1049
1116
|
|
|
@@ -1097,7 +1164,9 @@ var Authenticate = function Authenticate(_ref2) {
|
|
|
1097
1164
|
maxWidth: '600px',
|
|
1098
1165
|
margin: '0 auto'
|
|
1099
1166
|
}
|
|
1100
|
-
}, "
|
|
1167
|
+
}, React__default["default"].createElement(typography.Paragraph, null, "Something went wrong while trying to authenticate you. If the problem persists you should contact", ' ', React__default["default"].createElement(typography.Link, {
|
|
1168
|
+
href: "mailto:support@entur.org"
|
|
1169
|
+
}, "support@entur.org"), " to get it resolved."), React__default["default"].createElement(typography.Paragraph, null, "Authentication failed with: ", React__default["default"].createElement(typography.CodeText, null, error == null ? void 0 : error.toString())));
|
|
1101
1170
|
|
|
1102
1171
|
default:
|
|
1103
1172
|
return null;
|
|
@@ -1110,7 +1179,8 @@ var AppShell = function AppShell(_ref3) {
|
|
|
1110
1179
|
domain = _ref3.domain,
|
|
1111
1180
|
clientId = _ref3.clientId,
|
|
1112
1181
|
redirectUri = _ref3.redirectUri,
|
|
1113
|
-
decorateUser = _ref3.decorateUser
|
|
1182
|
+
decorateUser = _ref3.decorateUser,
|
|
1183
|
+
environment = _ref3.environment;
|
|
1114
1184
|
return React__default["default"].createElement(AuthProvider, {
|
|
1115
1185
|
audience: audience,
|
|
1116
1186
|
domain: domain,
|
|
@@ -1119,7 +1189,9 @@ var AppShell = function AppShell(_ref3) {
|
|
|
1119
1189
|
}, React__default["default"].createElement(Authenticate, {
|
|
1120
1190
|
redirectUri: redirectUri
|
|
1121
1191
|
}, function (params) {
|
|
1122
|
-
return
|
|
1192
|
+
return React__default["default"].createElement(React__default["default"].Fragment, null, environment && environment !== common.Environment.Production && React__default["default"].createElement(EnvironmentBanner, {
|
|
1193
|
+
environment: environment
|
|
1194
|
+
}), children(params));
|
|
1123
1195
|
}));
|
|
1124
1196
|
};
|
|
1125
1197
|
|