@madie/madie-design-system 1.0.39 → 1.0.41
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/components/Modal/index.jsx +1 -5
- package/components/Popover/index.js +19 -0
- package/coverage/clover.xml +191 -371
- package/coverage/coverage-final.json +14 -23
- package/coverage/lcov-report/SvgComponents.jsx.html +1702 -0
- package/coverage/lcov-report/components/Accordion/index.html +116 -0
- package/coverage/lcov-report/components/Accordion/index.jsx.html +370 -0
- package/coverage/lcov-report/components/Button/index.html +116 -0
- package/coverage/lcov-report/components/Button/index.js.html +385 -0
- package/coverage/lcov-report/components/Error/Collapsible.jsx.html +364 -0
- package/coverage/lcov-report/components/Error/ErrorUI.jsx.html +178 -0
- package/coverage/lcov-report/components/Error/index.html +131 -0
- package/coverage/lcov-report/components/Footer/FooterUI.jsx.html +496 -0
- package/coverage/lcov-report/components/Footer/LegacyFooterUI.jsx.html +697 -0
- package/coverage/lcov-report/components/Footer/index.html +131 -0
- package/coverage/lcov-report/components/Infotip/Infotip.jsx.html +310 -0
- package/coverage/lcov-report/components/Infotip/InfotipIcon.jsx.html +208 -0
- package/coverage/lcov-report/components/Infotip/index.html +146 -0
- package/coverage/lcov-report/components/Infotip/index.js.html +94 -0
- package/coverage/lcov-report/components/InputLabel/index.html +116 -0
- package/coverage/lcov-report/components/InputLabel/index.jsx.html +244 -0
- package/coverage/lcov-report/components/MadieAlert/index.html +116 -0
- package/coverage/lcov-report/components/MadieAlert/index.jsx.html +304 -0
- package/coverage/lcov-report/components/MadieDeleteDialog/index.html +116 -0
- package/coverage/lcov-report/components/MadieDeleteDialog/index.jsx.html +244 -0
- package/coverage/lcov-report/components/MadieDialog/index.html +116 -0
- package/coverage/lcov-report/components/MadieDialog/index.jsx.html +856 -0
- package/coverage/lcov-report/components/MadieDiscardDialog/index.html +116 -0
- package/coverage/lcov-report/components/MadieDiscardDialog/index.jsx.html +232 -0
- package/coverage/lcov-report/components/MadieSpinner/index.html +116 -0
- package/coverage/lcov-report/components/MadieSpinner/index.jsx.html +190 -0
- package/coverage/lcov-report/components/Modal/LegacyModal.jsx.html +307 -0
- package/coverage/lcov-report/components/Modal/index.html +116 -0
- package/coverage/lcov-report/components/Pagination/index.html +116 -0
- package/coverage/lcov-report/components/Pagination/index.jsx.html +736 -0
- package/coverage/lcov-report/components/Popover/index.html +116 -0
- package/coverage/lcov-report/components/Popover/index.js.html +472 -0
- package/coverage/lcov-report/components/ReadOnlyTextField/index.html +116 -0
- package/coverage/lcov-report/components/ReadOnlyTextField/index.jsx.html +313 -0
- package/coverage/lcov-report/components/SanitizedContent/index.html +116 -0
- package/coverage/lcov-report/components/SanitizedContent/index.jsx.html +685 -0
- package/coverage/lcov-report/components/Select/index.html +116 -0
- package/coverage/lcov-report/components/Select/index.jsx.html +610 -0
- package/coverage/lcov-report/components/TextField/index.html +116 -0
- package/coverage/lcov-report/components/TextField/index.jsx.html +496 -0
- package/coverage/lcov-report/components/Toast/index.html +116 -0
- package/coverage/lcov-report/components/Toast/index.jsx.html +430 -0
- package/coverage/lcov-report/components/Tooltip/Tooltip.jsx.html +349 -0
- package/coverage/lcov-report/components/Tooltip/index.html +146 -0
- package/coverage/lcov-report/components/Tooltip/index.js.html +94 -0
- package/coverage/lcov-report/components/Tooltip/position.js.html +313 -0
- package/coverage/lcov-report/index.html +87 -132
- package/coverage/lcov-report/index.js.html +385 -0
- package/coverage/lcov-report/index.jsx.html +417 -129
- package/coverage/lcov-report/lib/Chevron.jsx.html +181 -0
- package/coverage/lcov-report/lib/SvgComponents.jsx.html +1702 -0
- package/coverage/lcov-report/lib/index.html +131 -0
- package/coverage/lcov-report/react/components/Accordion/index.html +21 -21
- package/coverage/lcov-report/react/components/Accordion/index.jsx.html +29 -29
- package/coverage/lcov-report/react/components/Button/index.html +19 -19
- package/coverage/lcov-report/react/components/Button/index.js.html +45 -36
- package/coverage/lcov-report/react/components/Error/Collapsible.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Error/ErrorUI.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Error/error.js.html +1 -1
- package/coverage/lcov-report/react/components/Error/index.html +1 -1
- package/coverage/lcov-report/react/components/Footer/FooterUI.jsx.html +3 -3
- package/coverage/lcov-report/react/components/Footer/LegacyFooterUI.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Footer/footer.js.html +1 -1
- package/coverage/lcov-report/react/components/Footer/index.html +1 -1
- package/coverage/lcov-report/react/components/Infotip/Infotip.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Infotip/InfotipIcon.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Infotip/index.html +1 -1
- package/coverage/lcov-report/react/components/Infotip/index.js.html +1 -1
- package/coverage/lcov-report/react/components/InputLabel/index.html +5 -5
- package/coverage/lcov-report/react/components/InputLabel/index.jsx.html +8 -8
- package/coverage/lcov-report/react/components/MadieAlert/index.html +3 -18
- package/coverage/lcov-report/react/components/MadieAlert/index.jsx.html +76 -43
- package/coverage/lcov-report/react/components/MadieDeleteDialog/index.html +116 -0
- package/coverage/lcov-report/react/components/MadieDeleteDialog/index.jsx.html +244 -0
- package/coverage/lcov-report/react/components/MadieDialog/Index.jsx.html +9 -9
- package/coverage/lcov-report/react/components/MadieDialog/index.html +1 -1
- package/coverage/lcov-report/react/components/MadieDiscardDialog/index.html +1 -1
- package/coverage/lcov-report/react/components/MadieDiscardDialog/index.jsx.html +1 -1
- package/coverage/lcov-report/react/components/MadieSpinner/index.html +1 -1
- package/coverage/lcov-report/react/components/MadieSpinner/index.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Modal/LegacyModal.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Modal/Modal.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Modal/index.html +18 -33
- package/coverage/lcov-report/react/components/Modal/index.jsx.html +9 -21
- package/coverage/lcov-report/react/components/Pagination/index.html +5 -5
- package/coverage/lcov-report/react/components/Pagination/index.jsx.html +62 -23
- package/coverage/lcov-report/react/components/Popover/index.html +116 -0
- package/coverage/lcov-report/react/components/Popover/index.js.html +472 -0
- package/coverage/lcov-report/react/components/ReadOnlyTextField/index.html +1 -1
- package/coverage/lcov-report/react/components/ReadOnlyTextField/index.jsx.html +1 -1
- package/coverage/lcov-report/react/components/SanitizedContent/index.html +1 -1
- package/coverage/lcov-report/react/components/SanitizedContent/index.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Select/index.html +3 -3
- package/coverage/lcov-report/react/components/Select/index.jsx.html +206 -23
- package/coverage/lcov-report/react/components/SessionDialog/index.html +1 -1
- package/coverage/lcov-report/react/components/SessionDialog/sessionDialog.js.html +1 -1
- package/coverage/lcov-report/react/components/SessionDialogUI.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Textfield/index.html +3 -3
- package/coverage/lcov-report/react/components/Textfield/index.jsx.html +198 -9
- package/coverage/lcov-report/react/components/Toast/index.html +9 -9
- package/coverage/lcov-report/react/components/Toast/index.jsx.html +80 -119
- package/coverage/lcov-report/react/components/Tooltip/Tooltip.jsx.html +1 -1
- package/coverage/lcov-report/react/components/Tooltip/index.html +1 -1
- package/coverage/lcov-report/react/components/Tooltip/index.js.html +1 -1
- package/coverage/lcov-report/react/components/Tooltip/position.js.html +1 -1
- package/coverage/lcov-report/react/components/index.html +1 -1
- package/coverage/lcov-report/react/index.html +13 -13
- package/coverage/lcov-report/react/index.js.html +7 -19
- package/coverage/lcov-report/react/lib/Chevron.jsx.html +2 -2
- package/coverage/lcov-report/react/lib/SvgComponents.jsx.html +158 -158
- package/coverage/lcov-report/react/lib/index.html +17 -17
- package/coverage/lcov-report/react/session/index.html +1 -1
- package/coverage/lcov-report/react/session/index.js.html +1 -1
- package/coverage/lcov-report/react/session/logout.js.html +1 -1
- package/coverage/lcov-report/react/session/refresh.js.html +1 -1
- package/coverage/lcov-report/react/session/ttl.js.html +1 -1
- package/coverage/lcov.info +377 -735
- package/dist/browser.js +1 -1
- package/dist/index.js +1 -1
- package/dist/react/index.js +12 -12
- package/dist/react/index.js.map +1 -1
- package/index.js +0 -4
- package/lib/SvgComponents.jsx +1 -1
- package/package.json +1 -1
- package/test/components/Accordion.test.js +21 -4
- package/test/components/Button.test.js +72 -0
- package/test/components/MadieAlert.test.js +1 -2
- package/test/components/MadieDeleteDialog.test.js +3 -1
- package/test/components/MadiePopover.test.js +9 -0
- package/test/components/Pagination.test.js +4 -0
- package/test/components/Select.test.js +37 -0
- package/test/components/TextField.test.js +36 -0
- package/test/lib/SvgComponents.test.js +212 -0
- package/components/Modal/LegacyModal.jsx +0 -74
- package/components/SessionDialog/sessionDialog.js +0 -26
- package/components/SessionDialogUI.jsx +0 -273
- package/session/index.js +0 -5
- package/session/logout.js +0 -65
- package/session/refresh.js +0 -49
- package/session/ttl.js +0 -37
- package/test/components/SessionDialogUI.test.js +0 -347
- package/test/session/session.test.js +0 -221
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import React, { Component } from "react";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
|
-
import cookie from "cookie";
|
|
4
|
-
import retry from "retry";
|
|
5
|
-
import jwtDecode from "jwt-decode";
|
|
6
|
-
|
|
7
|
-
import Modal from "./Modal";
|
|
8
|
-
import RefreshSession from "../session/refresh";
|
|
9
|
-
import LogoutSession from "../session/logout";
|
|
10
|
-
import fetchTtl from "../session/ttl";
|
|
11
|
-
|
|
12
|
-
const fetchTtlIntervalMs = 60000;
|
|
13
|
-
|
|
14
|
-
export default class SessionDialogUI extends Component {
|
|
15
|
-
/**
|
|
16
|
-
* Create a SessionDialogUI component.
|
|
17
|
-
* @param {object} props - Configuration options. See SessionDialog for more
|
|
18
|
-
*/
|
|
19
|
-
constructor(props) {
|
|
20
|
-
super(props);
|
|
21
|
-
|
|
22
|
-
this.handleOpenModal = this.handleOpenModal.bind(this);
|
|
23
|
-
this.handleCloseModal = this.handleCloseModal.bind(this);
|
|
24
|
-
this.refreshSession = this.refreshSession.bind(this);
|
|
25
|
-
this.signOut = this.signOut.bind(this);
|
|
26
|
-
this.startTimer = this.startTimer.bind(this);
|
|
27
|
-
this.shouldShowDialog = this.shouldShowDialog.bind(this);
|
|
28
|
-
this.shouldSignOut = this.shouldSignOut.bind(this);
|
|
29
|
-
this.minutesUntil = this.minutesUntil.bind(this);
|
|
30
|
-
this.checkExpiry = this.checkExpiry.bind(this);
|
|
31
|
-
this.onInterval = this.onInterval.bind(this);
|
|
32
|
-
|
|
33
|
-
if (props.showImmediate === true) {
|
|
34
|
-
this.state = {
|
|
35
|
-
showModal: true,
|
|
36
|
-
showError: false,
|
|
37
|
-
};
|
|
38
|
-
} else {
|
|
39
|
-
this.state = {
|
|
40
|
-
showModal: false,
|
|
41
|
-
showError: false,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
this.startTimer();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Extracts the token exp value as a JavaScript date.
|
|
50
|
-
* @param {Object} cookies - An object representation of the cookie store
|
|
51
|
-
* @returns {(date|null)} The token expiration date, if found
|
|
52
|
-
*/
|
|
53
|
-
getTokenExpiry(cookies) {
|
|
54
|
-
let expiry = null;
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
cookies.hasOwnProperty("qpp_auth_token") &&
|
|
58
|
-
cookies.qpp_auth_token
|
|
59
|
-
) {
|
|
60
|
-
// See https://tools.ietf.org/html/rfc7519
|
|
61
|
-
// `exp` is a NumericDate representing "seconds since the epoch"
|
|
62
|
-
// and it needs to be milliseconds to get a JavaScript date from it.
|
|
63
|
-
const { exp } = jwtDecode(cookies.qpp_auth_token);
|
|
64
|
-
expiry = new Date(exp * 1000);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return expiry;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
checkExpiry(expiry) {
|
|
71
|
-
if (expiry) {
|
|
72
|
-
if (this.shouldShowDialog(expiry)) {
|
|
73
|
-
this.handleOpenModal();
|
|
74
|
-
} else if (this.shouldSignOut(expiry)) {
|
|
75
|
-
this.signOut();
|
|
76
|
-
clearInterval(this.warningInterval);
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
clearInterval(this.warningInterval);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
onInterval() {
|
|
84
|
-
const cookies = cookie.parse(document.cookie);
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
cookies.hasOwnProperty("qpp_auth_token") &&
|
|
88
|
-
cookies.qpp_auth_token
|
|
89
|
-
) {
|
|
90
|
-
const operation = retry.operation({
|
|
91
|
-
retries: 5,
|
|
92
|
-
factor: 1,
|
|
93
|
-
minTimeout: 1000,
|
|
94
|
-
maxTimeout: 1000,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
operation.attempt(() => {
|
|
98
|
-
fetchTtl(cookies.qpp_auth_token)
|
|
99
|
-
.then(this.checkExpiry)
|
|
100
|
-
.catch((error) => {
|
|
101
|
-
if (operation.retry(error)) {
|
|
102
|
-
// try again before giving up
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
clearInterval(this.warningInterval);
|
|
106
|
-
// sign an inactive user out
|
|
107
|
-
this.forceTimeoutHandle = setTimeout(
|
|
108
|
-
this.signOut,
|
|
109
|
-
120 * 1000
|
|
110
|
-
);
|
|
111
|
-
this.setState({
|
|
112
|
-
showModal: false,
|
|
113
|
-
showError: true,
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Checks whether the user is within a specified number of minutes before
|
|
122
|
-
* their session token expires. If so, show a warning dialog. If the
|
|
123
|
-
* expiration has been reached, sign the user out.
|
|
124
|
-
*/
|
|
125
|
-
startTimer() {
|
|
126
|
-
clearInterval(this.warningInterval);
|
|
127
|
-
|
|
128
|
-
this.warningInterval = setInterval(this.onInterval, fetchTtlIntervalMs);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Returns whether the current time is within the timeout range of expiry.
|
|
133
|
-
* @param {date|number} expiry - Expiration date to check against
|
|
134
|
-
* @returns {boolean}
|
|
135
|
-
*/
|
|
136
|
-
shouldShowDialog(expiry) {
|
|
137
|
-
if (typeof expiry === "number") {
|
|
138
|
-
const minutesLeft = expiry / 60;
|
|
139
|
-
|
|
140
|
-
return (
|
|
141
|
-
!this.state.showModal &&
|
|
142
|
-
minutesLeft <= this.props.warningTimeout
|
|
143
|
-
);
|
|
144
|
-
} else {
|
|
145
|
-
return (
|
|
146
|
-
!this.state.showModal &&
|
|
147
|
-
this.minutesUntil(expiry) <= this.props.warningTimeout
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Returns whether the current time has reached the expiration date.
|
|
154
|
-
* @param {date|number} expiry - Expiration date to check against
|
|
155
|
-
* @returns {boolean}
|
|
156
|
-
*/
|
|
157
|
-
shouldSignOut(expiry) {
|
|
158
|
-
if (typeof expiry === "number") {
|
|
159
|
-
return expiry <= 1;
|
|
160
|
-
} else {
|
|
161
|
-
return this.minutesUntil(expiry) <= 0;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Returns number of minutes until the expiration date.
|
|
167
|
-
* @param {date} expiry - Expiration date to check against
|
|
168
|
-
* @returns {number}
|
|
169
|
-
*/
|
|
170
|
-
minutesUntil(expiry) {
|
|
171
|
-
return (expiry - new Date().getTime()) / 60000;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Sets the modal state to visible.
|
|
176
|
-
*/
|
|
177
|
-
handleOpenModal() {
|
|
178
|
-
this.setState({
|
|
179
|
-
showModal: true,
|
|
180
|
-
showError: false,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Sets the modal state to hidden.
|
|
186
|
-
*/
|
|
187
|
-
handleCloseModal() {
|
|
188
|
-
this.setState({
|
|
189
|
-
showModal: false,
|
|
190
|
-
showError: false,
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Handles the user requesting their session be extended.
|
|
196
|
-
*/
|
|
197
|
-
refreshSession() {
|
|
198
|
-
RefreshSession({
|
|
199
|
-
window,
|
|
200
|
-
onSuccess: () => {
|
|
201
|
-
this.startTimer();
|
|
202
|
-
},
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
this.handleCloseModal();
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Handles the user requesting their session be ended.
|
|
210
|
-
*/
|
|
211
|
-
signOut() {
|
|
212
|
-
if (this.forceTimeoutHandle) {
|
|
213
|
-
clearTimeout(this.forceTimeoutHandle);
|
|
214
|
-
}
|
|
215
|
-
LogoutSession(window);
|
|
216
|
-
this.handleCloseModal();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
render() {
|
|
220
|
-
return (
|
|
221
|
-
<React.Fragment>
|
|
222
|
-
<Modal
|
|
223
|
-
useDesignSystem
|
|
224
|
-
title="You will be signed out within two minutes"
|
|
225
|
-
isOpen={this.state.showModal}
|
|
226
|
-
primary={{
|
|
227
|
-
title: "Keep me signed in",
|
|
228
|
-
onClick: this.refreshSession,
|
|
229
|
-
}}
|
|
230
|
-
secondary={{
|
|
231
|
-
title: "Sign me out now",
|
|
232
|
-
onClick: this.signOut,
|
|
233
|
-
}}
|
|
234
|
-
onRequestClose={this.handleCloseModal}
|
|
235
|
-
>
|
|
236
|
-
<p>
|
|
237
|
-
You have been inactive for thirty minutes. For your
|
|
238
|
-
security, we will sign you out automatically.
|
|
239
|
-
</p>
|
|
240
|
-
</Modal>
|
|
241
|
-
|
|
242
|
-
<Modal
|
|
243
|
-
useDesignSystem
|
|
244
|
-
title="Technical Difficulties"
|
|
245
|
-
isOpen={this.state.showError}
|
|
246
|
-
primary={{
|
|
247
|
-
title: "Sign Out",
|
|
248
|
-
onClick: this.signOut,
|
|
249
|
-
}}
|
|
250
|
-
onRequestClose={this.signOut}
|
|
251
|
-
>
|
|
252
|
-
<p>
|
|
253
|
-
We’re experiencing technical difficulties. Please log in
|
|
254
|
-
again to continue. For your security, we will sign you
|
|
255
|
-
out automatically within two minutes.
|
|
256
|
-
</p>
|
|
257
|
-
</Modal>
|
|
258
|
-
</React.Fragment>
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
SessionDialogUI.propTypes = {
|
|
264
|
-
showImmediate: PropTypes.bool,
|
|
265
|
-
warningTimeout: PropTypes.number,
|
|
266
|
-
appElement: PropTypes.string,
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
SessionDialogUI.defaultProps = {
|
|
270
|
-
showImmediate: false,
|
|
271
|
-
warningTimeout: 2,
|
|
272
|
-
appElement: undefined,
|
|
273
|
-
};
|
package/session/index.js
DELETED
package/session/logout.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import cookie from 'cookie';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
|
|
4
|
-
export const deleteImpersonatedUser = (cookies) => {
|
|
5
|
-
const userHasApmPayments = localStorage.getItem('user_has_apm_payments');
|
|
6
|
-
if (
|
|
7
|
-
cookies.hasOwnProperty('qpp_impersonated_user', 'user_has_apm_payments')
|
|
8
|
-
) {
|
|
9
|
-
document.cookie = `user_has_apm_payments=${userHasApmPayments}; Path=/;`;
|
|
10
|
-
document.cookie =
|
|
11
|
-
'qpp_impersonated_user=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const revertQppHasAuthsCookie = () => {
|
|
16
|
-
const { qppHasAuthorizations, behindSSL } = JSON.parse(
|
|
17
|
-
localStorage.getItem('impersonatorAuthValues')
|
|
18
|
-
)
|
|
19
|
-
if (qppHasAuthorizations) {
|
|
20
|
-
document.cookie = `qpp_has_authorizations=${qppHasAuthorizations};path=/${
|
|
21
|
-
behindSSL ? ';secure' : ''
|
|
22
|
-
}`
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Makes an API request to end the user session.
|
|
28
|
-
* @param {Object} [_window] The DOM Window
|
|
29
|
-
* @return {Function} Returns a promise
|
|
30
|
-
*/
|
|
31
|
-
const LogoutSession = (_window) => {
|
|
32
|
-
let cookies = cookie.parse(_window.document.cookie);
|
|
33
|
-
let logoutDestination = '/logout-confirmation';
|
|
34
|
-
|
|
35
|
-
if (cookies.hasOwnProperty('qpp_auth_token')) {
|
|
36
|
-
let onSuccess = () => {
|
|
37
|
-
// redirect to login/logged out screen
|
|
38
|
-
deleteImpersonatedUser(cookies);
|
|
39
|
-
_window.location.pathname = logoutDestination;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
let onError = () => {
|
|
43
|
-
// delete cookie and redirect login/logged out screen
|
|
44
|
-
deleteImpersonatedUser(cookies);
|
|
45
|
-
_window.location.pathname = logoutDestination;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
return axios({
|
|
49
|
-
method: 'POST',
|
|
50
|
-
url: '/user/session-logout',
|
|
51
|
-
headers: {
|
|
52
|
-
'Content-Type': 'application/json',
|
|
53
|
-
Authorization: `Bearer ${cookies.qpp_auth_token}`,
|
|
54
|
-
},
|
|
55
|
-
})
|
|
56
|
-
.then(onSuccess, onError)
|
|
57
|
-
.catch(function (err) {
|
|
58
|
-
console.log(err);
|
|
59
|
-
});
|
|
60
|
-
} else {
|
|
61
|
-
_window.location.pathname = logoutDestination;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export default LogoutSession;
|
package/session/refresh.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import cookie from 'cookie';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import LogoutSession from './logout.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Makes an API request to refresh the session token cookie, if it exists.
|
|
7
|
-
* @param {Object} [options] - Optional configuration parameters.
|
|
8
|
-
* @param {function} [options.onSuccess] - An optional success callback.
|
|
9
|
-
* @param {function} [options.onError] - An optional error callback.
|
|
10
|
-
* @param {Object} [options.window] - The DOM window.
|
|
11
|
-
* @return {Function} Returns a promise
|
|
12
|
-
*/
|
|
13
|
-
const RefreshSession = (options = {}) => {
|
|
14
|
-
let cookies = cookie.parse(options.window.document.cookie);
|
|
15
|
-
|
|
16
|
-
if (cookies.hasOwnProperty('qpp_auth_token')) {
|
|
17
|
-
const requestOptions = {
|
|
18
|
-
method: 'POST',
|
|
19
|
-
url: '/api/auth/sessions/refresh',
|
|
20
|
-
headers: {
|
|
21
|
-
Accept: 'application/vnd.qpp.cms.gov.v1+json',
|
|
22
|
-
'Content-Type': 'application/json',
|
|
23
|
-
Authorization: `Bearer ${cookies.qpp_auth_token}`
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
let onSuccess = (/*response*/) => {
|
|
28
|
-
if (typeof options.onSuccess === 'function') {
|
|
29
|
-
options.onSuccess();
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
let onError = (/*response*/) => {
|
|
34
|
-
if (typeof options.onError === 'function') {
|
|
35
|
-
options.onError();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return LogoutSession(options.window); // eslint-disable-line new-cap
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
return axios(requestOptions)
|
|
42
|
-
.then(onSuccess, onError)
|
|
43
|
-
.catch(function(err) {
|
|
44
|
-
console.log(err);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export default RefreshSession;
|
package/session/ttl.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
const fetchTtl = token => {
|
|
4
|
-
const requestOptions = {
|
|
5
|
-
method: 'GET',
|
|
6
|
-
url: '/api/auth/sessions/ttl',
|
|
7
|
-
headers: {
|
|
8
|
-
Accept: 'application/vnd.qpp.cms.gov.v1+json',
|
|
9
|
-
'Content-Type': 'application/json',
|
|
10
|
-
Authorization: `Bearer ${token}`
|
|
11
|
-
},
|
|
12
|
-
transformResponse: [
|
|
13
|
-
function(response) {
|
|
14
|
-
return JSON.parse(response).data;
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
return axios(requestOptions).then(response => {
|
|
20
|
-
let expiry;
|
|
21
|
-
|
|
22
|
-
if (response && response.data) {
|
|
23
|
-
if (response.data.hasOwnProperty('time_remaining')) {
|
|
24
|
-
expiry = response.data.time_remaining;
|
|
25
|
-
} else {
|
|
26
|
-
// See https://tools.ietf.org/html/rfc7519
|
|
27
|
-
// `expiry` is a NumericDate representing "seconds since the epoch"
|
|
28
|
-
// and it needs to be milliseconds to get a JavaScript date from it.
|
|
29
|
-
expiry = new Date(response.data.ttl * 1000);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return expiry;
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default fetchTtl;
|