versacall-core-library-react 2.0.66 → 2.0.67

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.
Files changed (121) hide show
  1. package/dist/components/CoreAlert/CoreAlert.js +43 -107
  2. package/dist/components/CoreAlert/index.js +2 -4
  3. package/dist/components/CoreAppBar/CoreAppBar.js +275 -418
  4. package/dist/components/CoreAppBar/CoreAppBarDrawer.js +88 -171
  5. package/dist/components/CoreAppBar/index.js +2 -4
  6. package/dist/components/CoreAppSelector/AppLink.js +36 -60
  7. package/dist/components/CoreAppSelector/CoreAppSelector.js +109 -200
  8. package/dist/components/CoreAppSelector/index.js +2 -4
  9. package/dist/components/CoreDialogueToolBar/CoreDialogueToolBar.js +43 -69
  10. package/dist/components/CoreDialogueToolBar/index.js +2 -4
  11. package/dist/components/CoreDrawer/CoreDrawer.js +168 -286
  12. package/dist/components/CoreDrawer/index.js +2 -4
  13. package/dist/components/CoreDropDownTextfield/CoreDropDownTextfield.js +57 -121
  14. package/dist/components/CoreDropDownTextfield/index.js +2 -4
  15. package/dist/components/CoreElapsedTime/CoreElapsedTime.js +38 -97
  16. package/dist/components/CoreElapsedTime/index.js +2 -4
  17. package/dist/components/CoreFrame/CoreFrame.js +17 -28
  18. package/dist/components/CoreFrame/index.js +2 -4
  19. package/dist/components/CoreImportDialog/CoreImportDialog.js +87 -189
  20. package/dist/components/CoreImportDialog/index.js +2 -4
  21. package/dist/components/CoreImportResultsDialog/CoreImportResultsDialog.js +19 -45
  22. package/dist/components/CoreImportResultsDialog/index.js +2 -4
  23. package/dist/components/CoreImporting/CoreImporting.js +23 -39
  24. package/dist/components/CoreImporting/index.js +2 -4
  25. package/dist/components/CorePlugin/CorePlugin.js +83 -160
  26. package/dist/components/CorePlugin/OldCorePlugin.js +73 -149
  27. package/dist/components/CorePlugin/index.js +2 -4
  28. package/dist/components/CoreSaveChangesDialog/CoreSaveChangesDialog.js +10 -32
  29. package/dist/components/CoreSaveChangesDialog/index.js +2 -4
  30. package/dist/components/CoreShiftTagFilter/CoreShiftTagFilter.js +288 -408
  31. package/dist/components/CoreShiftTagFilter/OldCoreShiftTagFilter.js +161 -257
  32. package/dist/components/CoreShiftTagFilter/index.js +2 -4
  33. package/dist/components/CoreSideBar/CoreSideBar.js +578 -737
  34. package/dist/components/CoreSideBar/CoreSideBarDrawer.js +122 -212
  35. package/dist/components/CoreSideBar/index.js +2 -4
  36. package/dist/components/CoreSnackBar/CoreSnackBar.js +76 -143
  37. package/dist/components/CoreSnackBar/index.js +2 -4
  38. package/dist/components/CoreTable/CoreTable.js +219 -337
  39. package/dist/components/CoreTable/CoreTableChips.js +11 -19
  40. package/dist/components/CoreTable/CoreTableHead.js +125 -205
  41. package/dist/components/CoreTable/CoreTableToolbar.js +34 -56
  42. package/dist/components/CoreTable/index.js +2 -4
  43. package/dist/components/CoreTagFilter/CoreTagFilter.js +212 -319
  44. package/dist/components/CoreTagFilter/OldCoreTagFilter.js +270 -402
  45. package/dist/components/CoreTagFilter/OldTagChip.js +10 -20
  46. package/dist/components/CoreTagFilter/OldTagFilterSelector.js +77 -148
  47. package/dist/components/CoreTagFilter/OldTagOption.js +21 -47
  48. package/dist/components/CoreTagFilter/TagFilterBuilder.js +114 -274
  49. package/dist/components/CoreTagFilter/index.js +2 -4
  50. package/dist/components/CoreTextField/CoreTextField.js +69 -132
  51. package/dist/components/CoreTextField/index.js +2 -4
  52. package/dist/components/CoreTheme/CoreTheme.js +13 -27
  53. package/dist/components/CoreTheme/index.js +2 -4
  54. package/dist/components/CoreTile/CoreTile.js +21 -34
  55. package/dist/components/CoreTile/CoreTileToolbar.js +21 -36
  56. package/dist/components/CoreTile/index.js +2 -4
  57. package/dist/components/CoreTimerInput/CoreTimerInput.js +36 -60
  58. package/dist/components/CoreTimerInput/CoreTimerInputOld.js +29 -47
  59. package/dist/components/CoreTimerInput/index.js +2 -4
  60. package/dist/components/CoreToolbar/CoreToolbar.js +65 -95
  61. package/dist/components/CoreToolbar/index.js +2 -4
  62. package/dist/components/CoreTracker/CoreTracker.js +32 -91
  63. package/dist/components/CoreTracker/index.js +2 -4
  64. package/dist/components/CoreTranslate/CoreTranslate.js +17 -48
  65. package/dist/components/CoreTranslate/index.js +2 -4
  66. package/dist/components/CoreTranslateWrapper/CoreTranslateWrapper.js +7 -15
  67. package/dist/components/CoreTranslateWrapper/index.js +2 -4
  68. package/dist/components/CoreWidget/CoreWidget.js +81 -149
  69. package/dist/components/CoreWidget/index.js +2 -4
  70. package/dist/components/CoreWrapper/CoreWrapper.js +8 -16
  71. package/dist/components/CoreWrapper/index.js +2 -4
  72. package/dist/components/index.js +29 -58
  73. package/dist/constants/index.js +3 -6
  74. package/dist/constants/testOrganization.js +2 -3
  75. package/dist/constants/testToken.js +2 -3
  76. package/dist/context/Authentication/AuthenticationContext.js +3 -8
  77. package/dist/context/Authentication/AuthenticationProvider.js +153 -268
  78. package/dist/context/Authentication/index.js +4 -8
  79. package/dist/context/Authentication/withAuthentication.js +5 -14
  80. package/dist/context/Channels/ChannelsConsumer.js +14 -70
  81. package/dist/context/Channels/ChannelsContext.js +3 -8
  82. package/dist/context/Channels/ChannelsProvider.js +132 -278
  83. package/dist/context/Channels/DataChannel.js +39 -103
  84. package/dist/context/Channels/EntityChannel.js +40 -104
  85. package/dist/context/Channels/EveryoneChannel.js +32 -92
  86. package/dist/context/Channels/OrganizationChannel.js +40 -104
  87. package/dist/context/Channels/UserChannel.js +37 -99
  88. package/dist/context/Channels/index.js +10 -20
  89. package/dist/context/Channels/withChannels.js +5 -14
  90. package/dist/context/Core/CoreContext.js +3 -8
  91. package/dist/context/Core/CoreProvider.js +68 -132
  92. package/dist/context/Core/index.js +4 -8
  93. package/dist/context/Core/withCore.js +5 -14
  94. package/dist/context/Organization/OrganizationContext.js +3 -8
  95. package/dist/context/Organization/OrganizationProvider.js +48 -120
  96. package/dist/context/Organization/index.js +4 -8
  97. package/dist/context/Organization/withOrganization.js +5 -14
  98. package/dist/context/Plugin/PluginContext.js +3 -8
  99. package/dist/context/Plugin/PluginProvider.js +55 -112
  100. package/dist/context/Plugin/index.js +4 -8
  101. package/dist/context/Plugin/withPlugin.js +5 -14
  102. package/dist/context/index.js +5 -15
  103. package/dist/css/index.js +3 -6
  104. package/dist/functions/TagEvaluator.js +107 -156
  105. package/dist/functions/compareObjects.js +0 -7
  106. package/dist/functions/formatElapsedTime.js +5 -6
  107. package/dist/functions/formatNameFileSafe.js +3 -4
  108. package/dist/functions/getIconUrl.js +0 -3
  109. package/dist/functions/getParameterByName.js +9 -12
  110. package/dist/functions/getProperty.js +4 -8
  111. package/dist/functions/getUrl.js +0 -3
  112. package/dist/functions/index.js +9 -18
  113. package/dist/icons/CopyIcon.js +11 -22
  114. package/dist/icons/DeleteIcon.js +11 -22
  115. package/dist/icons/DuplicateIcon.js +11 -22
  116. package/dist/icons/EditIcon.js +11 -22
  117. package/dist/icons/FabAddIcon.js +19 -35
  118. package/dist/icons/PasteIcon.js +11 -22
  119. package/dist/icons/index.js +7 -14
  120. package/dist/index.js +6 -18
  121. package/package.json +89 -79
@@ -1,332 +1,220 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.default = void 0;
9
-
10
7
  var _react = _interopRequireWildcard(require("react"));
11
-
12
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
9
  var _axios = _interopRequireDefault(require("axios"));
15
-
16
10
  var _AuthenticationContext = _interopRequireDefault(require("./AuthenticationContext"));
17
-
18
11
  var _functions = require("../../functions");
19
-
20
12
  var _constants = require("../../constants");
21
-
22
13
  var _Core = require("../Core");
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
-
28
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
30
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
31
-
32
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
33
-
34
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
35
-
36
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
37
-
38
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
39
-
40
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
41
-
42
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
43
-
44
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
45
-
46
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
47
-
48
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
49
-
50
- var namespace = 'AuthenticationProvider';
51
- var authenticationTokenLocalStorage = 'authenticationTokenLocalStorage';
52
-
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
+ const namespace = 'AuthenticationProvider';
18
+ const authenticationTokenLocalStorage = 'authenticationTokenLocalStorage';
53
19
  function getToken() {
54
- var token = localStorage.getItem(authenticationTokenLocalStorage);
20
+ const token = localStorage.getItem(authenticationTokenLocalStorage);
55
21
  return token ? JSON.parse(token) : null;
56
22
  }
57
-
58
23
  function setToken(token) {
59
24
  localStorage.setItem(authenticationTokenLocalStorage, JSON.stringify(token));
60
25
  }
61
-
62
26
  function deleteToken() {
63
27
  localStorage.removeItem(authenticationTokenLocalStorage);
64
28
  }
65
-
66
29
  function compareTokens(tr1, tr2) {
67
30
  if (tr1 === null || tr2 === null) {
68
31
  return tr1 === tr2;
69
32
  }
70
-
71
33
  return tr1.id === tr2.id;
72
34
  }
73
-
74
- function _checkRight(right, value) {
35
+ function checkRight(right, value) {
75
36
  if (right !== undefined) {
76
- var valuesArray = right.split('-');
77
- var found = valuesArray.find(function (x) {
78
- return x === value;
79
- });
80
-
37
+ const valuesArray = right.split('-');
38
+ const found = valuesArray.find(x => x === value);
81
39
  if (found !== undefined) {
82
40
  return true;
83
41
  }
84
42
  }
85
-
86
43
  return false;
87
44
  }
88
-
89
- var AuthenticationProvider = /*#__PURE__*/function (_Component) {
90
- _inherits(AuthenticationProvider, _Component);
91
-
92
- var _super = _createSuper(AuthenticationProvider);
93
-
94
- function AuthenticationProvider(props) {
95
- var _this;
96
-
97
- _classCallCheck(this, AuthenticationProvider);
98
-
99
- _this = _super.call(this, props);
100
- _this.state = {
45
+ class AuthenticationProvider extends _react.Component {
46
+ constructor(props) {
47
+ super(props);
48
+ this.state = {
101
49
  authenticated: false,
102
50
  token: null,
103
51
  apiKey: null
104
52
  };
105
-
106
53
  if (props.test) {
107
- _this.state.authenticated = true;
108
- _this.state.token = _constants.testToken;
54
+ this.state.authenticated = true;
55
+ this.state.token = _constants.testToken;
109
56
  } else {
110
- var token = getToken();
111
- var apiKey = (0, _functions.getParameterByName)('apiKey');
112
-
57
+ const token = getToken();
58
+ const apiKey = (0, _functions.getParameterByName)('apiKey');
113
59
  if (token !== null) {
114
- _this.state.authenticated = true;
115
- _this.state.token = token;
60
+ this.state.authenticated = true;
61
+ this.state.token = token;
116
62
  } else if (process.env.NODE_ENV === 'development') {
117
- var param = (0, _functions.getParameterByName)('authentication');
118
-
63
+ let param = (0, _functions.getParameterByName)('authentication');
119
64
  if (param !== null && param !== undefined && param.length > 0) {
120
65
  param = JSON.parse(param.replace(/%22/g, '"').replace(/%20/g, ' '));
121
- _this.state.authenticated = param.authenticated;
122
- _this.state.token = param.token;
66
+ this.state.authenticated = param.authenticated;
67
+ this.state.token = param.token;
123
68
  }
124
69
  } else if (apiKey && apiKey.length > 0) {
125
- _this.state.apiKey = apiKey; // TODO - Make call to get token from Api Key...
70
+ this.state.apiKey = apiKey;
71
+ // TODO - Make call to get token from Api Key...
126
72
  } else {
127
- _this.redirectToLogin();
73
+ this.redirectToLogin();
128
74
  }
129
75
  }
130
-
131
- return _this;
132
76
  }
133
-
134
- _createClass(AuthenticationProvider, [{
135
- key: "componentDidMount",
136
- value: function componentDidMount() {
137
- this.onReceiveMessageBinded = this.onReceiveMessage.bind(this);
138
- this.onLocalStorageChangeBinded = this.onLocalStorageChange.bind(this);
139
- window.addEventListener('message', this.onReceiveMessageBinded);
140
- window.addEventListener('storage', this.onLocalStorageChangeBinded);
141
- }
142
- }, {
143
- key: "componentWillUnmount",
144
- value: function componentWillUnmount() {
145
- window.removeEventListener('message', this.onReceiveMessageBinded);
146
- window.removeEventListener('storage', this.onLocalStorageChangeBinded);
77
+ componentDidMount() {
78
+ this.onReceiveMessageBinded = this.onReceiveMessage.bind(this);
79
+ this.onLocalStorageChangeBinded = this.onLocalStorageChange.bind(this);
80
+ window.addEventListener('message', this.onReceiveMessageBinded);
81
+ window.addEventListener('storage', this.onLocalStorageChangeBinded);
82
+ }
83
+ componentWillUnmount() {
84
+ window.removeEventListener('message', this.onReceiveMessageBinded);
85
+ window.removeEventListener('storage', this.onLocalStorageChangeBinded);
86
+ }
87
+ onReceiveMessage(event) {
88
+ if (event.data && event.data.shellAuthentication) {
89
+ this.setState({
90
+ authenticated: event.data.shellAuthentication.authenticated,
91
+ token: event.data.shellAuthentication.token
92
+ });
147
93
  }
148
- }, {
149
- key: "onReceiveMessage",
150
- value: function onReceiveMessage(event) {
151
- if (event.data && event.data.shellAuthentication) {
94
+ }
95
+ onLocalStorageChange(event) {
96
+ if (event.key === authenticationTokenLocalStorage) {
97
+ const value = event.newValue;
98
+ // console.log('authentication changed', value);
99
+ if (value) {
152
100
  this.setState({
153
- authenticated: event.data.shellAuthentication.authenticated,
154
- token: event.data.shellAuthentication.token
101
+ authenticated: true,
102
+ token: JSON.parse(value)
155
103
  });
104
+ } else {
105
+ // this.setState({ authenticated: false, token: null });
106
+ this.logout();
156
107
  }
157
108
  }
158
- }, {
159
- key: "onLocalStorageChange",
160
- value: function onLocalStorageChange(event) {
161
- if (event.key === authenticationTokenLocalStorage) {
162
- var value = event.newValue; // console.log('authentication changed', value);
163
-
164
- if (value) {
165
- this.setState({
166
- authenticated: true,
167
- token: JSON.parse(value)
168
- });
169
- } else {
170
- // this.setState({ authenticated: false, token: null });
171
- this.logout();
172
- }
109
+ }
110
+ getRight(objectId, key) {
111
+ if (this.state.token !== null && this.state.token.permissions !== undefined) {
112
+ const permission = this.state.token.permissions.find(x => x.objectIds.indexOf(objectId) > -1);
113
+ if (permission !== undefined) {
114
+ const right = permission.rights[key];
115
+ return right;
173
116
  }
174
117
  }
175
- }, {
176
- key: "getRight",
177
- value: function getRight(objectId, key) {
178
- if (this.state.token !== null && this.state.token.permissions !== undefined) {
179
- var permission = this.state.token.permissions.find(function (x) {
180
- return x.objectIds.indexOf(objectId) > -1;
181
- });
182
-
183
- if (permission !== undefined) {
184
- var right = permission.rights[key];
185
- return right;
118
+ return undefined;
119
+ }
120
+ didChange(prevContext) {
121
+ // NOTE: Might also need to check apiKey...
122
+ return !compareTokens(this.state.token, prevContext.token);
123
+ }
124
+ logout() {
125
+ this.setState({
126
+ authenticated: false,
127
+ token: null
128
+ });
129
+ deleteToken();
130
+ this.redirectToLogin();
131
+ }
132
+ http(configuration) {
133
+ const methodName = 'http()';
134
+ if (!this.state.authenticated) {
135
+ return Promise.reject(new Error({
136
+ response: {
137
+ status: 401
186
138
  }
187
- }
188
-
189
- return undefined;
190
- }
191
- }, {
192
- key: "didChange",
193
- value: function didChange(prevContext) {
194
- // NOTE: Might also need to check apiKey...
195
- return !compareTokens(this.state.token, prevContext.token);
196
- }
197
- }, {
198
- key: "logout",
199
- value: function logout() {
200
- this.setState({
201
- authenticated: false,
202
- token: null
203
- });
204
- deleteToken();
205
- this.redirectToLogin();
139
+ }));
206
140
  }
207
- }, {
208
- key: "http",
209
- value: function http(configuration) {
210
- var _this2 = this;
211
-
212
- var methodName = 'http()';
213
-
214
- if (!this.state.authenticated) {
215
- return Promise.reject(new Error({
216
- response: {
217
- status: 401
218
- }
219
- }));
220
- }
221
-
222
- var configurationCombined = Object.assign(configuration, {
223
- headers: {
224
- Authorization: "Bearer ".concat(this.state.token.token)
225
- }
226
- }); // NOTE: If we have an ApiKey, might want to include a "X-API-Key" header...
227
-
228
- if (this.state.apiKey) {
229
- configurationCombined.headers['X-API-Key'] = this.state.apiKey;
141
+ let configurationCombined = Object.assign(configuration, {
142
+ headers: {
143
+ Authorization: "Bearer ".concat(this.state.token.token)
230
144
  }
231
-
232
- return new Promise(function (resolve, reject) {
233
- (0, _axios.default)(configurationCombined).then(function (results) {
234
- resolve(results);
235
- }).catch(function (error) {
236
- if (error.response !== undefined && error.response.status === 401) {
237
- _this2.props.core.log('debug', namespace, methodName, 'Attempting to Renew Token');
238
-
239
- _axios.default.post("".concat(_this2.props.core.urlServer, "/api/authentication/renew"), JSON.stringify(_this2.state.token.token), {
145
+ });
146
+ // NOTE: If we have an ApiKey, might want to include a "X-API-Key" header...
147
+ if (this.state.apiKey) {
148
+ configurationCombined.headers['X-API-Key'] = this.state.apiKey;
149
+ }
150
+ return new Promise((resolve, reject) => {
151
+ (0, _axios.default)(configurationCombined).then(results => {
152
+ resolve(results);
153
+ }).catch(error => {
154
+ if (error.response !== undefined && error.response.status === 401) {
155
+ this.props.core.log('debug', namespace, methodName, 'Attempting to Renew Token');
156
+ _axios.default.post("".concat(this.props.core.urlServer, "/api/authentication/renew"), JSON.stringify(this.state.token.token), {
157
+ headers: {
158
+ 'Content-Type': 'application/json'
159
+ }
160
+ }).then(results => {
161
+ setToken(results.data);
162
+ this.setState({
163
+ authenticated: true,
164
+ token: results.data
165
+ });
166
+ configurationCombined = Object.assign(configuration, {
240
167
  headers: {
241
- 'Content-Type': 'application/json'
168
+ Authorization: "Bearer ".concat(results.data.token)
242
169
  }
243
- }).then(function (results) {
244
- setToken(results.data);
245
-
246
- _this2.setState({
247
- authenticated: true,
248
- token: results.data
249
- });
250
-
251
- configurationCombined = Object.assign(configuration, {
252
- headers: {
253
- Authorization: "Bearer ".concat(results.data.token)
254
- }
255
- });
256
- (0, _axios.default)(configurationCombined).then(function (resultsSecond) {
257
- resolve(resultsSecond);
258
- }).catch(function (errorSecond) {
259
- _this2.props.core.log('warning', namespace, 'Second error', errorSecond);
260
-
261
- reject(errorSecond);
262
- });
263
- }).catch(function (errorRenew) {
264
- _this2.props.core.log('warning', namespace, 'Renew Error', errorRenew);
265
-
266
- _this2.logout();
267
170
  });
268
- } else {
269
- reject(error);
270
- }
271
- });
272
- });
273
- }
274
- }, {
275
- key: "checkPermission",
276
- value: function checkPermission(objectId, key, value) {
277
- var right = this.getRight(objectId, key);
278
- return _checkRight(right, value);
279
- }
280
- }, {
281
- key: "redirectToLogin",
282
- value: function redirectToLogin() {
283
- // Need to encode the redirect URL since we are passing it as a parameter
284
- var redirect = encodeURIComponent(window.location);
285
- window.location = "".concat(this.props.core.baseUrl, "/login?redirect=").concat(redirect);
286
- }
287
- }, {
288
- key: "render",
289
- value: function render() {
290
- var _this3 = this;
291
-
292
- var _this$state = this.state,
293
- authenticated = _this$state.authenticated,
294
- token = _this$state.token,
295
- apiKey = _this$state.apiKey;
296
- return /*#__PURE__*/_react.default.createElement(_AuthenticationContext.default.Provider, {
297
- value: {
298
- authenticated: authenticated,
299
- token: token,
300
- apiKey: apiKey,
301
- logout: function logout() {
302
- return _this3.logout();
303
- },
304
- http: function http(config) {
305
- return _this3.http(config);
306
- },
307
- httpRequest: function httpRequest(config) {
308
- return _this3.http(config);
309
- },
310
- didChange: function didChange(prevContext) {
311
- return _this3.didChange(prevContext);
312
- },
313
- checkRight: function checkRight(right, value) {
314
- return _checkRight(right, value);
315
- },
316
- getRight: function getRight(objectId, key) {
317
- return _this3.getRight(objectId, key);
318
- },
319
- checkPermission: function checkPermission(objectId, key, value) {
320
- return _this3.checkPermission(objectId, key, value);
321
- }
171
+ (0, _axios.default)(configurationCombined).then(resultsSecond => {
172
+ resolve(resultsSecond);
173
+ }).catch(errorSecond => {
174
+ this.props.core.log('warning', namespace, 'Second error', errorSecond);
175
+ reject(errorSecond);
176
+ });
177
+ }).catch(errorRenew => {
178
+ this.props.core.log('warning', namespace, 'Renew Error', errorRenew);
179
+ this.logout();
180
+ });
181
+ } else {
182
+ reject(error);
322
183
  }
323
- }, authenticated && this.props.children);
324
- }
325
- }]);
326
-
327
- return AuthenticationProvider;
328
- }(_react.Component);
329
-
184
+ });
185
+ });
186
+ }
187
+ checkPermission(objectId, key, value) {
188
+ const right = this.getRight(objectId, key);
189
+ return checkRight(right, value);
190
+ }
191
+ redirectToLogin() {
192
+ // Need to encode the redirect URL since we are passing it as a parameter
193
+ const redirect = encodeURIComponent(window.location);
194
+ window.location = "".concat(this.props.core.baseUrl, "/login?redirect=").concat(redirect);
195
+ }
196
+ render() {
197
+ const {
198
+ authenticated,
199
+ token,
200
+ apiKey
201
+ } = this.state;
202
+ return /*#__PURE__*/_react.default.createElement(_AuthenticationContext.default.Provider, {
203
+ value: {
204
+ authenticated: authenticated,
205
+ token: token,
206
+ apiKey: apiKey,
207
+ logout: () => this.logout(),
208
+ http: config => this.http(config),
209
+ httpRequest: config => this.http(config),
210
+ didChange: prevContext => this.didChange(prevContext),
211
+ checkRight: (right, value) => checkRight(right, value),
212
+ getRight: (objectId, key) => this.getRight(objectId, key),
213
+ checkPermission: (objectId, key, value) => this.checkPermission(objectId, key, value)
214
+ }
215
+ }, authenticated && this.props.children);
216
+ }
217
+ }
330
218
  AuthenticationProvider.propTypes = {
331
219
  test: _propTypes.default.bool,
332
220
  core: _propTypes.default.shape().isRequired,
@@ -335,7 +223,4 @@ AuthenticationProvider.propTypes = {
335
223
  AuthenticationProvider.defaultProps = {
336
224
  test: false
337
225
  };
338
-
339
- var _default = (0, _Core.withCore)(AuthenticationProvider);
340
-
341
- exports.default = _default;
226
+ var _default = exports.default = (0, _Core.withCore)(AuthenticationProvider);
@@ -5,27 +5,23 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  Object.defineProperty(exports, "AuthenticationContext", {
7
7
  enumerable: true,
8
- get: function get() {
8
+ get: function () {
9
9
  return _AuthenticationContext.default;
10
10
  }
11
11
  });
12
12
  Object.defineProperty(exports, "AuthenticationProvider", {
13
13
  enumerable: true,
14
- get: function get() {
14
+ get: function () {
15
15
  return _AuthenticationProvider.default;
16
16
  }
17
17
  });
18
18
  Object.defineProperty(exports, "withAuthentication", {
19
19
  enumerable: true,
20
- get: function get() {
20
+ get: function () {
21
21
  return _withAuthentication.default;
22
22
  }
23
23
  });
24
-
25
24
  var _AuthenticationProvider = _interopRequireDefault(require("./AuthenticationProvider"));
26
-
27
25
  var _AuthenticationContext = _interopRequireDefault(require("./AuthenticationContext"));
28
-
29
26
  var _withAuthentication = _interopRequireDefault(require("./withAuthentication"));
30
-
31
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -4,21 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = withAuthentication;
7
-
8
7
  var _react = _interopRequireDefault(require("react"));
9
-
10
8
  var _AuthenticationContext = _interopRequireDefault(require("./AuthenticationContext"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
15
-
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
16
11
  function withAuthentication(Component) {
17
- return function (props) {
18
- return /*#__PURE__*/_react.default.createElement(_AuthenticationContext.default.Consumer, null, function (authentication) {
19
- return /*#__PURE__*/_react.default.createElement(Component, _extends({}, props, {
20
- authentication: authentication
21
- }));
22
- });
23
- };
12
+ return props => /*#__PURE__*/_react.default.createElement(_AuthenticationContext.default.Consumer, null, authentication => /*#__PURE__*/_react.default.createElement(Component, _extends({}, props, {
13
+ authentication: authentication
14
+ })));
24
15
  }