@edx/frontend-platform 2.0.0 → 2.2.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/analytics/MockAnalyticsService.js.map +1 -1
- package/analytics/SegmentAnalyticsService.js.map +1 -1
- package/analytics/index.js.map +1 -1
- package/analytics/interface.js.map +1 -1
- package/auth/AxiosCsrfTokenService.js.map +1 -1
- package/auth/AxiosJwtAuthService.js +32 -7
- package/auth/AxiosJwtAuthService.js.map +1 -1
- package/auth/AxiosJwtTokenService.js.map +1 -1
- package/auth/LocalForageCache.js.map +1 -1
- package/auth/MockAuthService.js +136 -107
- package/auth/MockAuthService.js.map +1 -1
- package/auth/index.js.map +1 -1
- package/auth/interceptors/createCsrfTokenProviderInterceptor.js.map +1 -1
- package/auth/interceptors/createJwtTokenProviderInterceptor.js.map +1 -1
- package/auth/interceptors/createProcessAxiosRequestErrorInterceptor.js.map +1 -1
- package/auth/interceptors/createRetryInterceptor.js.map +1 -1
- package/auth/interface.js.map +1 -1
- package/auth/utils.js.map +1 -1
- package/config.js.map +1 -1
- package/constants.js.map +1 -1
- package/i18n/countries.js.map +1 -1
- package/i18n/index.js.map +1 -1
- package/i18n/injectIntlWithShim.js.map +1 -1
- package/i18n/languages.js.map +1 -1
- package/i18n/lib.js.map +1 -1
- package/i18n/scripts/README.md +25 -0
- package/i18n/scripts/transifex-utils.js.map +1 -1
- package/index.js.map +1 -1
- package/initialize.js +5 -3
- package/initialize.js.map +1 -1
- package/logging/MockLoggingService.js.map +1 -1
- package/logging/NewRelicLoggingService.js.map +1 -1
- package/logging/index.js.map +1 -1
- package/logging/interface.js.map +1 -1
- package/package.json +4 -5
- package/pubSub.js.map +1 -1
- package/react/AppContext.js.map +1 -1
- package/react/AppProvider.js.map +1 -1
- package/react/AuthenticatedPageRoute.js.map +1 -1
- package/react/ErrorBoundary.js.map +1 -1
- package/react/ErrorPage.js.map +1 -1
- package/react/LoginRedirect.js.map +1 -1
- package/react/OptionalReduxProvider.js.map +1 -1
- package/react/PageRoute.js.map +1 -1
- package/react/hooks.js.map +1 -1
- package/react/index.js.map +1 -1
- package/testing/index.js.map +1 -1
- package/testing/initializeMockApp.js.map +1 -1
- package/testing/mockMessages.js.map +1 -1
- package/utils.js.map +1 -1
- package/i18n/scripts/Makefile +0 -39
package/auth/MockAuthService.js
CHANGED
|
@@ -2,12 +2,12 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
2
2
|
|
|
3
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
4
|
|
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
+
|
|
5
7
|
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); } }
|
|
6
8
|
|
|
7
9
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
10
|
|
|
9
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
-
|
|
11
11
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
12
|
|
|
13
13
|
import axios from 'axios';
|
|
@@ -84,112 +84,141 @@ var optionsPropTypes = {
|
|
|
84
84
|
* @memberof module:Auth
|
|
85
85
|
*/
|
|
86
86
|
|
|
87
|
-
var MockAuthService = /*#__PURE__*/
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
function MockAuthService(options) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
87
|
+
var MockAuthService = /*#__PURE__*/function () {
|
|
88
|
+
/**
|
|
89
|
+
* @param {Object} options
|
|
90
|
+
* @param {Object} options.config
|
|
91
|
+
* @param {string} options.config.BASE_URL
|
|
92
|
+
* @param {string} options.config.LMS_BASE_URL
|
|
93
|
+
* @param {string} options.config.LOGIN_URL
|
|
94
|
+
* @param {string} options.config.LOGOUT_URL
|
|
95
|
+
* @param {string} options.config.REFRESH_ACCESS_TOKEN_ENDPOINT
|
|
96
|
+
* @param {string} options.config.ACCESS_TOKEN_COOKIE_NAME
|
|
97
|
+
* @param {string} options.config.CSRF_TOKEN_API_PATH
|
|
98
|
+
* @param {Object} options.config.hydratedAuthenticatedUser
|
|
99
|
+
* @param {Object} options.config.authenticatedUser
|
|
100
|
+
* @param {Object} options.loggingService requires logError and logInfo methods
|
|
101
|
+
*/
|
|
102
|
+
function MockAuthService(options) {
|
|
103
|
+
var _this = this;
|
|
104
|
+
|
|
105
|
+
_classCallCheck(this, MockAuthService);
|
|
106
|
+
|
|
107
|
+
_defineProperty(this, "getAuthenticatedHttpClient", jest.fn(function () {
|
|
108
|
+
return _this.authenticatedHttpClient;
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
_defineProperty(this, "getHttpClient", jest.fn(function () {
|
|
112
|
+
return _this.httpClient;
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
_defineProperty(this, "getLoginRedirectUrl", jest.fn(function () {
|
|
116
|
+
var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.config.BASE_URL;
|
|
117
|
+
return "".concat(_this.config.LOGIN_URL, "?next=").concat(encodeURIComponent(redirectUrl));
|
|
118
|
+
}));
|
|
119
|
+
|
|
120
|
+
_defineProperty(this, "redirectToLogin", jest.fn(function () {
|
|
121
|
+
var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.config.BASE_URL;
|
|
122
|
+
|
|
123
|
+
// Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.
|
|
124
|
+
_this.getLoginRedirectUrl(redirectUrl);
|
|
125
|
+
}));
|
|
126
|
+
|
|
127
|
+
_defineProperty(this, "getLogoutRedirectUrl", jest.fn(function () {
|
|
128
|
+
var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.config.BASE_URL;
|
|
129
|
+
return "".concat(_this.config.LOGOUT_URL, "?redirect_url=").concat(encodeURIComponent(redirectUrl));
|
|
130
|
+
}));
|
|
131
|
+
|
|
132
|
+
_defineProperty(this, "redirectToLogout", jest.fn(function () {
|
|
133
|
+
var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.config.BASE_URL;
|
|
134
|
+
|
|
135
|
+
// Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.
|
|
136
|
+
_this.getLogoutRedirectUrl(redirectUrl);
|
|
137
|
+
}));
|
|
138
|
+
|
|
139
|
+
_defineProperty(this, "getAuthenticatedUser", jest.fn(function () {
|
|
140
|
+
return _this.authenticatedUser;
|
|
141
|
+
}));
|
|
142
|
+
|
|
143
|
+
_defineProperty(this, "setAuthenticatedUser", jest.fn(function (authUser) {
|
|
144
|
+
_this.authenticatedUser = authUser;
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
_defineProperty(this, "fetchAuthenticatedUser", jest.fn(function () {
|
|
148
|
+
return _this.getAuthenticatedUser();
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
_defineProperty(this, "ensureAuthenticatedUser", jest.fn(function () {
|
|
152
|
+
var redirectUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.config.BASE_URL;
|
|
153
|
+
|
|
154
|
+
_this.fetchAuthenticatedUser();
|
|
155
|
+
|
|
156
|
+
if (_this.getAuthenticatedUser() === null) {
|
|
157
|
+
// The user is not authenticated, send them to the login page.
|
|
158
|
+
_this.redirectToLogin(redirectUrl);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return _this.getAuthenticatedUser();
|
|
162
|
+
}));
|
|
163
|
+
|
|
164
|
+
_defineProperty(this, "hydrateAuthenticatedUser", jest.fn(function () {
|
|
165
|
+
var user = _this.getAuthenticatedUser();
|
|
166
|
+
|
|
167
|
+
if (user !== null) {
|
|
168
|
+
_this.setAuthenticatedUser(_objectSpread(_objectSpread({}, user), _this.hydratedAuthenticatedUser));
|
|
169
|
+
}
|
|
170
|
+
}));
|
|
171
|
+
|
|
172
|
+
this.authenticatedHttpClient = null;
|
|
173
|
+
this.httpClient = null;
|
|
174
|
+
ensureDefinedConfig(options, 'AuthService');
|
|
175
|
+
PropTypes.checkPropTypes(optionsPropTypes, options, 'options', 'AuthService');
|
|
176
|
+
this.config = options.config;
|
|
177
|
+
this.loggingService = options.loggingService; // Mock user
|
|
178
|
+
|
|
179
|
+
this.authenticatedUser = this.config.authenticatedUser ? this.config.authenticatedUser : null;
|
|
180
|
+
this.hydratedAuthenticatedUser = this.config.hydratedAuthenticatedUser ? this.config.hydratedAuthenticatedUser : {};
|
|
181
|
+
this.authenticatedHttpClient = axios.create();
|
|
182
|
+
this.httpClient = axios.create();
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* A Jest mock function (jest.fn())
|
|
186
|
+
*
|
|
187
|
+
* Applies middleware to the axios instances in this service.
|
|
188
|
+
*
|
|
189
|
+
* @param {Array} middleware Middleware to apply.
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
_createClass(MockAuthService, [{
|
|
194
|
+
key: "applyMiddleware",
|
|
195
|
+
value: function applyMiddleware() {
|
|
196
|
+
var middleware = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
197
|
+
var clients = [this.authenticatedHttpClient, this.httpClient, this.cachedAuthenticatedHttpClient, this.cachedHttpClient];
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
middleware.forEach(function (middlewareFn) {
|
|
201
|
+
clients.forEach(function (client) {
|
|
202
|
+
return client && middlewareFn(client);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
} catch (error) {
|
|
206
|
+
throw new Error("Failed to apply middleware: ".concat(error.message, "."));
|
|
207
|
+
}
|
|
169
208
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* A Jest mock function (jest.fn())
|
|
186
|
-
*
|
|
187
|
-
* Gets the authenticated HTTP client instance, which is an axios client wrapped in
|
|
188
|
-
* MockAdapter from axios-mock-adapter.
|
|
189
|
-
*
|
|
190
|
-
* @returns {HttpClient} An HttpClient wrapped in MockAdapter.
|
|
191
|
-
*/
|
|
192
|
-
);
|
|
209
|
+
/**
|
|
210
|
+
* A Jest mock function (jest.fn())
|
|
211
|
+
*
|
|
212
|
+
* Gets the authenticated HTTP client instance, which is an axios client wrapped in
|
|
213
|
+
* MockAdapter from axios-mock-adapter.
|
|
214
|
+
*
|
|
215
|
+
* @returns {HttpClient} An HttpClient wrapped in MockAdapter.
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
}]);
|
|
219
|
+
|
|
220
|
+
return MockAuthService;
|
|
221
|
+
}();
|
|
193
222
|
|
|
194
223
|
export default MockAuthService;
|
|
195
224
|
//# sourceMappingURL=MockAuthService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/MockAuthService.js"],"names":["axios","PropTypes","ensureDefinedConfig","userPropTypes","shape","userId","string","isRequired","username","roles","arrayOf","administrator","optionsPropTypes","config","BASE_URL","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","ACCESS_TOKEN_COOKIE_NAME","CSRF_TOKEN_API_PATH","loggingService","logError","func","logInfo","authenticatedUser","hydratedAuthenticatedUser","MockAuthService","options","jest","fn","authenticatedHttpClient","httpClient","redirectUrl","encodeURIComponent","getLoginRedirectUrl","getLogoutRedirectUrl","authUser","getAuthenticatedUser","fetchAuthenticat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ApD,EAA+D,aAA/D;AAEA,OAAKf,MAAL,GAAce,OAAO,CAACf,MAAtB;AACA,OAAKQ,cAAL,GAAsBO,OAAO,CAACP,cAA9B,CARmB,CAUnB;;AACA,OAAKI,iBAAL,GAAyB,KAAKZ,MAAL,CAAYY,iBAAZ,GAAgC,KAAKZ,MAAL,CAAYY,iBAA5C,GAAgE,IAAzF;AACA,OAAKC,yBAAL,GAAiC,KAAKb,MAAL,CAAYa,yBAAZ,GAC7B,KAAKb,MAAL,CAAYa,yBADiB,GAE7B,EAFJ;AAIA,OAAKK,uBAAL,GAA+B/B,KAAK,CAAC4C,MAAN,EAA/B;AACA,OAAKZ,UAAL,GAAkBhC,KAAK,CAAC4C,MAAN,EAAlB;AACD;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;;;AAiJA,eAAejB,eAAf","sourcesContent":["import axios from 'axios';\nimport PropTypes from 'prop-types';\nimport { ensureDefinedConfig } from '../utils';\n\nconst userPropTypes = PropTypes.shape({\n userId: PropTypes.string.isRequired,\n username: PropTypes.string.isRequired,\n roles: PropTypes.arrayOf(PropTypes.string),\n administrator: PropTypes.boolean,\n});\n\nconst optionsPropTypes = {\n config: PropTypes.shape({\n BASE_URL: PropTypes.string.isRequired,\n LMS_BASE_URL: PropTypes.string.isRequired,\n LOGIN_URL: PropTypes.string.isRequired,\n LOGOUT_URL: PropTypes.string.isRequired,\n REFRESH_ACCESS_TOKEN_ENDPOINT: PropTypes.string.isRequired,\n ACCESS_TOKEN_COOKIE_NAME: PropTypes.string.isRequired,\n CSRF_TOKEN_API_PATH: PropTypes.string.isRequired,\n }).isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n logInfo: PropTypes.func.isRequired,\n }).isRequired,\n // The absence of authenticatedUser means the user is anonymous.\n authenticatedUser: userPropTypes,\n // Must be at least a valid user, but may have other fields.\n hydratedAuthenticatedUser: userPropTypes,\n};\n\n/**\n * The MockAuthService class mocks authenticated user-fetching logic and allows for manually\n * setting user data. It is compatible with axios-mock-adapter to wrap its HttpClients so that\n * they can be mocked for testing.\n *\n * It wraps all methods of the service with Jest mock functions (jest.fn()). This allows test code\n * to assert expectations on all functions of the service while preserving sensible behaviors. For\n * instance, the login/logout methods related to redirecting maintain their real behavior.\n *\n * This service is NOT suitable for use in an application itself - only tests. It depends on Jest,\n * which should only be a dev dependency of your project. You don't want to pull the entire suite\n * of test dependencies into your application at runtime, probably even in your dev server.\n *\n * In a test where you would like to mock out API requests - perhaps from a redux-thunk function -\n * you could do the following to set up a MockAuthService for your test:\n *\n * ```\n * import { getConfig, mergeConfig } from '@edx/frontend-platform';\n * import { configure, MockAuthService } from '@edx/frontend-platform/auth';\n * import MockAdapter from 'axios-mock-adapter';\n *\n * const mockLoggingService = {\n * logInfo: jest.fn(),\n * logError: jest.fn(),\n * };\n * mergeConfig({\n * authenticatedUser: {\n * userId: 'abc123',\n * username: 'Mock User',\n * roles: [],\n * administrator: false,\n * },\n * });\n * configure(MockAuthService, { config: getConfig(), loggingService: mockLoggingService });\n * const mockAdapter = new MockAdapter(getAuthenticatedHttpClient());\n * // Mock calls for your tests. This configuration can be done in any sort of test setup.\n * mockAdapter.onGet(...);\n * ```\n *\n * Also see the `initializeMockApp` function which also automatically uses mock services for\n * Logging and Analytics.\n *\n * @implements {AuthService}\n * @memberof module:Auth\n */\nclass MockAuthService {\n /**\n * @param {Object} options\n * @param {Object} options.config\n * @param {string} options.config.BASE_URL\n * @param {string} options.config.LMS_BASE_URL\n * @param {string} options.config.LOGIN_URL\n * @param {string} options.config.LOGOUT_URL\n * @param {string} options.config.REFRESH_ACCESS_TOKEN_ENDPOINT\n * @param {string} options.config.ACCESS_TOKEN_COOKIE_NAME\n * @param {string} options.config.CSRF_TOKEN_API_PATH\n * @param {Object} options.config.hydratedAuthenticatedUser\n * @param {Object} options.config.authenticatedUser\n * @param {Object} options.loggingService requires logError and logInfo methods\n */\n constructor(options) {\n this.authenticatedHttpClient = null;\n this.httpClient = null;\n\n ensureDefinedConfig(options, 'AuthService');\n PropTypes.checkPropTypes(optionsPropTypes, options, 'options', 'AuthService');\n\n this.config = options.config;\n this.loggingService = options.loggingService;\n\n // Mock user\n this.authenticatedUser = this.config.authenticatedUser ? this.config.authenticatedUser : null;\n this.hydratedAuthenticatedUser = this.config.hydratedAuthenticatedUser\n ? this.config.hydratedAuthenticatedUser\n : {};\n\n this.authenticatedHttpClient = axios.create();\n this.httpClient = axios.create();\n }\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Gets the authenticated HTTP client instance, which is an axios client wrapped in\n * MockAdapter from axios-mock-adapter.\n *\n * @returns {HttpClient} An HttpClient wrapped in MockAdapter.\n */\n getAuthenticatedHttpClient = jest.fn(() => this.authenticatedHttpClient);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Gets the unauthenticated HTTP client instance, which is an axios client wrapped in\n * MockAdapter from axios-mock-adapter.\n *\n * @returns {HttpClient} An HttpClient wrapped in MockAdapter.\n */\n getHttpClient = jest.fn(() => this.httpClient);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Builds a URL to the login page with a post-login redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLoginRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/login?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\n getLoginRedirectUrl = jest.fn(\n (redirectUrl = this.config.BASE_URL) => `${this.config.LOGIN_URL}?next=${encodeURIComponent(redirectUrl)}`,\n );\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Redirects the user to the logout page in the real implementation. Is a no-op here.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\n redirectToLogin = jest.fn((redirectUrl = this.config.BASE_URL) => {\n // Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.\n this.getLoginRedirectUrl(redirectUrl);\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Builds a URL to the logout page with a post-logout redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLogoutRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/logout?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\n getLogoutRedirectUrl = jest.fn((redirectUrl = this.config.BASE_URL) => `${this.config.LOGOUT_URL}?redirect_url=${encodeURIComponent(redirectUrl)}`);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Redirects the user to the logout page in the real implementation. Is a no-op here.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\n redirectToLogout = jest.fn((redirectUrl = this.config.BASE_URL) => {\n // Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.\n this.getLogoutRedirectUrl(redirectUrl);\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * If it exists, returns the user data representing the currently authenticated user. If the\n * user is anonymous, returns null.\n *\n * @returns {UserData|null}\n */\n getAuthenticatedUser = jest.fn(() => this.authenticatedUser);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Sets the authenticated user to the provided value.\n *\n * @param {UserData} authUser\n */\n setAuthenticatedUser = jest.fn((authUser) => {\n this.authenticatedUser = authUser;\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Returns the current authenticated user details, as supplied in the `authenticatedUser` field\n * of the config options. Resolves to null if the user is unauthenticated / the config option\n * has not been set.\n *\n * @returns {UserData|null} Resolves to the user's access token if they are\n * logged in.\n */\n fetchAuthenticatedUser = jest.fn(() => this.getAuthenticatedUser());\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Ensures a user is authenticated. It will redirect to login when not authenticated.\n *\n * @param {string} [redirectUrl=config.BASE_URL] to return user after login when not\n * authenticated.\n * @returns {UserData|null} Resolves to the user's access token if they are\n * logged in.\n */\n ensureAuthenticatedUser = jest.fn((redirectUrl = this.config.BASE_URL) => {\n this.fetchAuthenticatedUser();\n\n if (this.getAuthenticatedUser() === null) {\n // The user is not authenticated, send them to the login page.\n this.redirectToLogin(redirectUrl);\n }\n\n return this.getAuthenticatedUser();\n })\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Adds the user data supplied in the `hydratedAuthenticatedUser` config option into the object\n * returned by `getAuthenticatedUser`. This emulates the behavior of a real auth service which\n * would make a request to fetch this data prior to merging it in.\n *\n * ```\n * console.log(authenticatedUser); // Will be sparse and only contain basic information.\n * await hydrateAuthenticatedUser()\n * const authenticatedUser = getAuthenticatedUser();\n * console.log(authenticatedUser); // Will contain additional user information\n * ```\n *\n * @returns {Promise<null>}\n */\n hydrateAuthenticatedUser = jest.fn(() => {\n const user = this.getAuthenticatedUser();\n if (user !== null) {\n this.setAuthenticatedUser({ ...user, ...this.hydratedAuthenticatedUser });\n }\n });\n}\n\nexport default MockAuthService;\n"],"file":"MockAuthService.js"}
|
|
1
|
+
{"version":3,"file":"MockAuthService.js","names":["axios","PropTypes","ensureDefinedConfig","userPropTypes","shape","userId","string","isRequired","username","roles","arrayOf","administrator","optionsPropTypes","config","BASE_URL","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","ACCESS_TOKEN_COOKIE_NAME","CSRF_TOKEN_API_PATH","loggingService","logError","func","logInfo","authenticatedUser","hydratedAuthenticatedUser","MockAuthService","options","jest","fn","authenticatedHttpClient","httpClient","redirectUrl","encodeURIComponent","getLoginRedirectUrl","getLogoutRedirectUrl","authUser","getAuthenticatedUser","fetchAuthenticatedUser","redirectToLogin","user","setAuthenticatedUser","checkPropTypes","create","middleware","clients","cachedAuthenticatedHttpClient","cachedHttpClient","forEach","middlewareFn","client","error","Error","message"],"sources":["../../src/auth/MockAuthService.js"],"sourcesContent":["import axios from 'axios';\nimport PropTypes from 'prop-types';\nimport { ensureDefinedConfig } from '../utils';\n\nconst userPropTypes = PropTypes.shape({\n userId: PropTypes.string.isRequired,\n username: PropTypes.string.isRequired,\n roles: PropTypes.arrayOf(PropTypes.string),\n administrator: PropTypes.boolean,\n});\n\nconst optionsPropTypes = {\n config: PropTypes.shape({\n BASE_URL: PropTypes.string.isRequired,\n LMS_BASE_URL: PropTypes.string.isRequired,\n LOGIN_URL: PropTypes.string.isRequired,\n LOGOUT_URL: PropTypes.string.isRequired,\n REFRESH_ACCESS_TOKEN_ENDPOINT: PropTypes.string.isRequired,\n ACCESS_TOKEN_COOKIE_NAME: PropTypes.string.isRequired,\n CSRF_TOKEN_API_PATH: PropTypes.string.isRequired,\n }).isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n logInfo: PropTypes.func.isRequired,\n }).isRequired,\n // The absence of authenticatedUser means the user is anonymous.\n authenticatedUser: userPropTypes,\n // Must be at least a valid user, but may have other fields.\n hydratedAuthenticatedUser: userPropTypes,\n};\n\n/**\n * The MockAuthService class mocks authenticated user-fetching logic and allows for manually\n * setting user data. It is compatible with axios-mock-adapter to wrap its HttpClients so that\n * they can be mocked for testing.\n *\n * It wraps all methods of the service with Jest mock functions (jest.fn()). This allows test code\n * to assert expectations on all functions of the service while preserving sensible behaviors. For\n * instance, the login/logout methods related to redirecting maintain their real behavior.\n *\n * This service is NOT suitable for use in an application itself - only tests. It depends on Jest,\n * which should only be a dev dependency of your project. You don't want to pull the entire suite\n * of test dependencies into your application at runtime, probably even in your dev server.\n *\n * In a test where you would like to mock out API requests - perhaps from a redux-thunk function -\n * you could do the following to set up a MockAuthService for your test:\n *\n * ```\n * import { getConfig, mergeConfig } from '@edx/frontend-platform';\n * import { configure, MockAuthService } from '@edx/frontend-platform/auth';\n * import MockAdapter from 'axios-mock-adapter';\n *\n * const mockLoggingService = {\n * logInfo: jest.fn(),\n * logError: jest.fn(),\n * };\n * mergeConfig({\n * authenticatedUser: {\n * userId: 'abc123',\n * username: 'Mock User',\n * roles: [],\n * administrator: false,\n * },\n * });\n * configure(MockAuthService, { config: getConfig(), loggingService: mockLoggingService });\n * const mockAdapter = new MockAdapter(getAuthenticatedHttpClient());\n * // Mock calls for your tests. This configuration can be done in any sort of test setup.\n * mockAdapter.onGet(...);\n * ```\n *\n * Also see the `initializeMockApp` function which also automatically uses mock services for\n * Logging and Analytics.\n *\n * @implements {AuthService}\n * @memberof module:Auth\n */\nclass MockAuthService {\n /**\n * @param {Object} options\n * @param {Object} options.config\n * @param {string} options.config.BASE_URL\n * @param {string} options.config.LMS_BASE_URL\n * @param {string} options.config.LOGIN_URL\n * @param {string} options.config.LOGOUT_URL\n * @param {string} options.config.REFRESH_ACCESS_TOKEN_ENDPOINT\n * @param {string} options.config.ACCESS_TOKEN_COOKIE_NAME\n * @param {string} options.config.CSRF_TOKEN_API_PATH\n * @param {Object} options.config.hydratedAuthenticatedUser\n * @param {Object} options.config.authenticatedUser\n * @param {Object} options.loggingService requires logError and logInfo methods\n */\n constructor(options) {\n this.authenticatedHttpClient = null;\n this.httpClient = null;\n\n ensureDefinedConfig(options, 'AuthService');\n PropTypes.checkPropTypes(optionsPropTypes, options, 'options', 'AuthService');\n\n this.config = options.config;\n this.loggingService = options.loggingService;\n\n // Mock user\n this.authenticatedUser = this.config.authenticatedUser ? this.config.authenticatedUser : null;\n this.hydratedAuthenticatedUser = this.config.hydratedAuthenticatedUser\n ? this.config.hydratedAuthenticatedUser\n : {};\n\n this.authenticatedHttpClient = axios.create();\n this.httpClient = axios.create();\n }\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Applies middleware to the axios instances in this service.\n *\n * @param {Array} middleware Middleware to apply.\n */\n applyMiddleware(middleware = []) {\n const clients = [\n this.authenticatedHttpClient, this.httpClient,\n this.cachedAuthenticatedHttpClient, this.cachedHttpClient,\n ];\n try {\n (middleware).forEach((middlewareFn) => {\n clients.forEach((client) => client && middlewareFn(client));\n });\n } catch (error) {\n throw new Error(`Failed to apply middleware: ${error.message}.`);\n }\n }\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Gets the authenticated HTTP client instance, which is an axios client wrapped in\n * MockAdapter from axios-mock-adapter.\n *\n * @returns {HttpClient} An HttpClient wrapped in MockAdapter.\n */\n getAuthenticatedHttpClient = jest.fn(() => this.authenticatedHttpClient);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Gets the unauthenticated HTTP client instance, which is an axios client wrapped in\n * MockAdapter from axios-mock-adapter.\n *\n * @returns {HttpClient} An HttpClient wrapped in MockAdapter.\n */\n getHttpClient = jest.fn(() => this.httpClient);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Builds a URL to the login page with a post-login redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLoginRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/login?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\n getLoginRedirectUrl = jest.fn(\n (redirectUrl = this.config.BASE_URL) => `${this.config.LOGIN_URL}?next=${encodeURIComponent(redirectUrl)}`,\n );\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Redirects the user to the logout page in the real implementation. Is a no-op here.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\n redirectToLogin = jest.fn((redirectUrl = this.config.BASE_URL) => {\n // Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.\n this.getLoginRedirectUrl(redirectUrl);\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Builds a URL to the logout page with a post-logout redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLogoutRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/logout?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\n getLogoutRedirectUrl = jest.fn((redirectUrl = this.config.BASE_URL) => `${this.config.LOGOUT_URL}?redirect_url=${encodeURIComponent(redirectUrl)}`);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Redirects the user to the logout page in the real implementation. Is a no-op here.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\n redirectToLogout = jest.fn((redirectUrl = this.config.BASE_URL) => {\n // Do nothing after getting the URL - this preserves the calls properly, but doesn't redirect.\n this.getLogoutRedirectUrl(redirectUrl);\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * If it exists, returns the user data representing the currently authenticated user. If the\n * user is anonymous, returns null.\n *\n * @returns {UserData|null}\n */\n getAuthenticatedUser = jest.fn(() => this.authenticatedUser);\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Sets the authenticated user to the provided value.\n *\n * @param {UserData} authUser\n */\n setAuthenticatedUser = jest.fn((authUser) => {\n this.authenticatedUser = authUser;\n });\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Returns the current authenticated user details, as supplied in the `authenticatedUser` field\n * of the config options. Resolves to null if the user is unauthenticated / the config option\n * has not been set.\n *\n * @returns {UserData|null} Resolves to the user's access token if they are\n * logged in.\n */\n fetchAuthenticatedUser = jest.fn(() => this.getAuthenticatedUser());\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Ensures a user is authenticated. It will redirect to login when not authenticated.\n *\n * @param {string} [redirectUrl=config.BASE_URL] to return user after login when not\n * authenticated.\n * @returns {UserData|null} Resolves to the user's access token if they are\n * logged in.\n */\n ensureAuthenticatedUser = jest.fn((redirectUrl = this.config.BASE_URL) => {\n this.fetchAuthenticatedUser();\n\n if (this.getAuthenticatedUser() === null) {\n // The user is not authenticated, send them to the login page.\n this.redirectToLogin(redirectUrl);\n }\n\n return this.getAuthenticatedUser();\n })\n\n /**\n * A Jest mock function (jest.fn())\n *\n * Adds the user data supplied in the `hydratedAuthenticatedUser` config option into the object\n * returned by `getAuthenticatedUser`. This emulates the behavior of a real auth service which\n * would make a request to fetch this data prior to merging it in.\n *\n * ```\n * console.log(authenticatedUser); // Will be sparse and only contain basic information.\n * await hydrateAuthenticatedUser()\n * const authenticatedUser = getAuthenticatedUser();\n * console.log(authenticatedUser); // Will contain additional user information\n * ```\n *\n * @returns {Promise<null>}\n */\n hydrateAuthenticatedUser = jest.fn(() => {\n const user = this.getAuthenticatedUser();\n if (user !== null) {\n this.setAuthenticatedUser({ ...user, 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AYY,iBAAZ,GAAgC,KAAKZ,MAAL,CAAYY,iBAA5C,GAAgE,IAAzF;IACA,KAAKC,yBAAL,GAAiC,KAAKb,MAAL,CAAYa,yBAAZ,GAC7B,KAAKb,MAAL,CAAYa,yBADiB,GAE7B,EAFJ;IAIA,KAAKK,uBAAL,GAA+B/B,KAAK,CAAC4C,MAAN,EAA/B;IACA,KAAKZ,UAAL,GAAkBhC,KAAK,CAAC4C,MAAN,EAAlB;EACD;EAED;AACF;AACA;AACA;AACA;AACA;AACA;;;;;WACE,2BAAiC;MAAA,IAAjBC,UAAiB,uEAAJ,EAAI;MAC/B,IAAMC,OAAO,GAAG,CACd,KAAKf,uBADS,EACgB,KAAKC,UADrB,EAEd,KAAKe,6BAFS,EAEsB,KAAKC,gBAF3B,CAAhB;;MAIA,IAAI;QACDH,UAAD,CAAaI,OAAb,CAAqB,UAACC,YAAD,EAAkB;UACrCJ,OAAO,CAACG,OAAR,CAAgB,UAACE,MAAD;YAAA,OAAYA,MAAM,IAAID,YAAY,CAACC,MAAD,CAAlC;UAAA,CAAhB;QACD,CAFD;MAGD,CAJD,CAIE,OAAOC,KAAP,EAAc;QACd,MAAM,IAAIC,KAAJ,uCAAyCD,KAAK,CAACE,OAA/C,OAAN;MACD;IACF;IAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;AAiJA,eAAe3B,eAAf"}
|
package/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["AUTHENTICATED_USER_TOPIC","AUTHENTICATED_USER_CHANGED","configure","getAuthenticatedHttpClient","getAuthService","getHttpClient","getLoginRedirectUrl","redirectToLogin","getLogoutRedirectUrl","redirectToLogout","getAuthenticatedUser","setAuthenticatedUser","fetchAuthenticatedUser","ensureAuthenticatedUser","hydrateAuthenticatedUser","default","AxiosJwtAuthService","MockAuthService"],"sources":["../../src/auth/index.js"],"sourcesContent":["export {\n AUTHENTICATED_USER_TOPIC,\n AUTHENTICATED_USER_CHANGED,\n configure,\n getAuthenticatedHttpClient,\n getAuthService,\n getHttpClient,\n getLoginRedirectUrl,\n redirectToLogin,\n getLogoutRedirectUrl,\n redirectToLogout,\n getAuthenticatedUser,\n setAuthenticatedUser,\n fetchAuthenticatedUser,\n ensureAuthenticatedUser,\n hydrateAuthenticatedUser,\n} from './interface';\nexport { default as AxiosJwtAuthService } from './AxiosJwtAuthService';\nexport { default as MockAuthService } from './MockAuthService';\n"],"mappings":"AAAA,SACEA,wBADF,EAEEC,0BAFF,EAGEC,SAHF,EAIEC,0BAJF,EAKEC,cALF,EAMEC,aANF,EAOEC,mBAPF,EAQEC,eARF,EASEC,oBATF,EAUEC,gBAVF,EAWEC,oBAXF,EAYEC,oBAZF,EAaEC,sBAbF,EAcEC,uBAdF,EAeEC,wBAfF,QAgBO,aAhBP;AAiBA,SAASC,OAAO,IAAIC,mBAApB,QAA+C,uBAA/C;AACA,SAASD,OAAO,IAAIE,eAApB,QAA2C,mBAA3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createCsrfTokenProviderInterceptor.js","names":["createCsrfTokenProviderInterceptor","options","csrfTokenService","CSRF_TOKEN_API_PATH","shouldSkip","interceptor","axiosRequestConfig","url","getCsrfToken","csrfToken","requestError","Object","create","message","config","Promise","reject","CSRF_HEADER_NAME","headers"],"sources":["../../../src/auth/interceptors/createCsrfTokenProviderInterceptor.js"],"sourcesContent":["const createCsrfTokenProviderInterceptor = (options) => {\n const { csrfTokenService, CSRF_TOKEN_API_PATH, shouldSkip } = options;\n\n // Creating the interceptor inside this closure to\n // maintain reference to the options supplied.\n const interceptor = async (axiosRequestConfig) => {\n if (shouldSkip(axiosRequestConfig)) {\n return axiosRequestConfig;\n }\n const { url } = axiosRequestConfig;\n let csrfToken;\n\n // Important: the job of this interceptor is to get a csrf token and update\n // the original request configuration. Errors thrown getting the csrf token\n // should contain the original request config. This allows other interceptors\n // (namely our retry request interceptor below) to access the original request\n // and handle it appropriately\n try {\n csrfToken = await csrfTokenService.getCsrfToken(url, CSRF_TOKEN_API_PATH);\n } catch (error) {\n const requestError = Object.create(error);\n requestError.message = `[getCsrfToken] ${requestError.message}`;\n // Important: return the original axios request config\n requestError.config = axiosRequestConfig;\n return Promise.reject(requestError);\n }\n\n const CSRF_HEADER_NAME = 'X-CSRFToken';\n // eslint-disable-next-line no-param-reassign\n axiosRequestConfig.headers[CSRF_HEADER_NAME] = csrfToken;\n return axiosRequestConfig;\n };\n\n return interceptor;\n};\n\nexport default createCsrfTokenProviderInterceptor;\n"],"mappings":";;;;AAAA,IAAMA,kCAAkC,GAAG,SAArCA,kCAAqC,CAACC,OAAD,EAAa;EACtD,IAAQC,gBAAR,GAA8DD,OAA9D,CAAQC,gBAAR;EAAA,IAA0BC,mBAA1B,GAA8DF,OAA9D,CAA0BE,mBAA1B;EAAA,IAA+CC,UAA/C,GAA8DH,OAA9D,CAA+CG,UAA/C,CADsD,CAGtD;EACA;;EACA,IAAMC,WAAW;IAAA,mEAAG,iBAAOC,kBAAP;MAAA;MAAA;QAAA;UAAA;YAAA;cAAA,KACdF,UAAU,CAACE,kBAAD,CADI;gBAAA;gBAAA;cAAA;;cAAA,iCAETA,kBAFS;;YAAA;cAIVC,GAJU,GAIFD,kBAJE,CAIVC,GAJU;cAAA;cAAA;cAAA,OAaEL,gBAAgB,CAACM,YAAjB,CAA8BD,GAA9B,EAAmCJ,mBAAnC,CAbF;;YAAA;cAahBM,SAbgB;cAAA;cAAA;;YAAA;cAAA;cAAA;cAeVC,YAfU,GAeKC,MAAM,CAACC,MAAP,aAfL;cAgBhBF,YAAY,CAACG,OAAb,4BAAyCH,YAAY,CAACG,OAAtD,EAhBgB,CAiBhB;;cACAH,YAAY,CAACI,MAAb,GAAsBR,kBAAtB;cAlBgB,iCAmBTS,OAAO,CAACC,MAAR,CAAeN,YAAf,CAnBS;;YAAA;cAsBZO,gBAtBY,GAsBO,aAtBP,EAuBlB;;cACAX,kBAAkB,CAACY,OAAnB,CAA2BD,gBAA3B,IAA+CR,SAA/C;cAxBkB,iCAyBXH,kBAzBW;;YAAA;YAAA;cAAA;UAAA;QAAA;MAAA;IAAA,CAAH;;IAAA,gBAAXD,WAAW;MAAA;IAAA;EAAA,GAAjB;;EA4BA,OAAOA,WAAP;AACD,CAlCD;;AAoCA,eAAeL,kCAAf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createJwtTokenProviderInterceptor.js","names":["createJwtTokenProviderInterceptor","options","jwtTokenService","shouldSkip","interceptor","axiosRequestConfig","getJwtToken","requestError","Object","create","message","config","Promise","reject","headers","common"],"sources":["../../../src/auth/interceptors/createJwtTokenProviderInterceptor.js"],"sourcesContent":["const createJwtTokenProviderInterceptor = (options) => {\n const {\n jwtTokenService,\n shouldSkip,\n } = options;\n\n // Creating the interceptor inside this closure to\n // maintain reference to the options supplied.\n const interceptor = async (axiosRequestConfig) => {\n if (shouldSkip(axiosRequestConfig)) {\n return axiosRequestConfig;\n }\n\n // Important: the job of this interceptor is to refresh a jwt token and update\n // the original request configuration. Errors thrown from fetching the jwt\n // should contain the original request config. This allows other interceptors\n // (namely our retry request interceptor below) to access the original request\n // and handle it appropriately\n try {\n await jwtTokenService.getJwtToken();\n } catch (error) {\n const requestError = Object.create(error);\n requestError.message = `[getJwtToken] ${requestError.message}`;\n // Important: return the original axios request config\n requestError.config = axiosRequestConfig;\n return Promise.reject(requestError);\n }\n\n // Add the proper headers to tell the server to look for the jwt cookie\n // eslint-disable-next-line no-param-reassign\n axiosRequestConfig.headers.common['USE-JWT-COOKIE'] = true;\n return axiosRequestConfig;\n };\n\n return interceptor;\n};\n\nexport default createJwtTokenProviderInterceptor;\n"],"mappings":";;;;AAAA,IAAMA,iCAAiC,GAAG,SAApCA,iCAAoC,CAACC,OAAD,EAAa;EACrD,IACEC,eADF,GAGID,OAHJ,CACEC,eADF;EAAA,IAEEC,UAFF,GAGIF,OAHJ,CAEEE,UAFF,CADqD,CAMrD;EACA;;EACA,IAAMC,WAAW;IAAA,mEAAG,iBAAOC,kBAAP;MAAA;MAAA;QAAA;UAAA;YAAA;cAAA,KACdF,UAAU,CAACE,kBAAD,CADI;gBAAA;gBAAA;cAAA;;cAAA,iCAETA,kBAFS;;YAAA;cAAA;cAAA;cAAA,OAWVH,eAAe,CAACI,WAAhB,EAXU;;YAAA;cAAA;cAAA;;YAAA;cAAA;cAAA;cAaVC,YAbU,GAaKC,MAAM,CAACC,MAAP,aAbL;cAchBF,YAAY,CAACG,OAAb,2BAAwCH,YAAY,CAACG,OAArD,EAdgB,CAehB;;cACAH,YAAY,CAACI,MAAb,GAAsBN,kBAAtB;cAhBgB,iCAiBTO,OAAO,CAACC,MAAR,CAAeN,YAAf,CAjBS;;YAAA;cAoBlB;cACA;cACAF,kBAAkB,CAACS,OAAnB,CAA2BC,MAA3B,CAAkC,gBAAlC,IAAsD,IAAtD;cAtBkB,iCAuBXV,kBAvBW;;YAAA;YAAA;cAAA;UAAA;QAAA;MAAA;IAAA,CAAH;;IAAA,gBAAXD,WAAW;MAAA;IAAA;EAAA,GAAjB;;EA0BA,OAAOA,WAAP;AACD,CAnCD;;AAqCA,eAAeJ,iCAAf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createProcessAxiosRequestErrorInterceptor.js","names":["processAxiosError","createProcessAxiosRequestErrorInterceptor","options","loggingService","interceptor","error","processedError","httpErrorStatus","customAttributes","logInfo","message","Promise","reject"],"sources":["../../../src/auth/interceptors/createProcessAxiosRequestErrorInterceptor.js"],"sourcesContent":["import { processAxiosError } from '../utils';\n\nconst createProcessAxiosRequestErrorInterceptor = (options) => {\n const { loggingService } = options;\n\n // Creating the interceptor inside this closure to\n // maintain reference to the options supplied.\n const interceptor = async (error) => {\n const processedError = processAxiosError(error);\n const { httpErrorStatus } = processedError.customAttributes;\n if (httpErrorStatus === 401 || httpErrorStatus === 403) {\n loggingService.logInfo(processedError.message, processedError.customAttributes);\n }\n return Promise.reject(processedError);\n };\n\n return interceptor;\n};\n\nexport default createProcessAxiosRequestErrorInterceptor;\n"],"mappings":";;;;AAAA,SAASA,iBAAT,QAAkC,UAAlC;;AAEA,IAAMC,yCAAyC,GAAG,SAA5CA,yCAA4C,CAACC,OAAD,EAAa;EAC7D,IAAQC,cAAR,GAA2BD,OAA3B,CAAQC,cAAR,CAD6D,CAG7D;EACA;;EACA,IAAMC,WAAW;IAAA,mEAAG,iBAAOC,KAAP;MAAA;MAAA;QAAA;UAAA;YAAA;cACZC,cADY,GACKN,iBAAiB,CAACK,KAAD,CADtB;cAEVE,eAFU,GAEUD,cAAc,CAACE,gBAFzB,CAEVD,eAFU;;cAGlB,IAAIA,eAAe,KAAK,GAApB,IAA2BA,eAAe,KAAK,GAAnD,EAAwD;gBACtDJ,cAAc,CAACM,OAAf,CAAuBH,cAAc,CAACI,OAAtC,EAA+CJ,cAAc,CAACE,gBAA9D;cACD;;cALiB,iCAMXG,OAAO,CAACC,MAAR,CAAeN,cAAf,CANW;;YAAA;YAAA;cAAA;UAAA;QAAA;MAAA;IAAA,CAAH;;IAAA,gBAAXF,WAAW;MAAA;IAAA;EAAA,GAAjB;;EASA,OAAOA,WAAP;AACD,CAfD;;AAiBA,eAAeH,yCAAf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createRetryInterceptor.js","names":["axios","defaultGetBackoffMilliseconds","nthRetry","maximumBackoffMilliseconds","exponentialBackoffSeconds","randomFractionOfASecond","Math","random","backoffSeconds","backoffMilliseconds","round","min","createRetryInterceptor","options","httpClient","create","getBackoffMilliseconds","shouldRetry","error","isRequestError","response","config","defaultMaxRetries","interceptor","Promise","reject","maxRetries","retryRequest","backoffDelay","resolve","setTimeout","request","retryResponse"],"sources":["../../../src/auth/interceptors/createRetryInterceptor.js"],"sourcesContent":["import axios from 'axios';\n\n// This default algorithm is a recreation of what is documented here\n// https://cloud.google.com/storage/docs/exponential-backoff\nconst defaultGetBackoffMilliseconds = (nthRetry, maximumBackoffMilliseconds = 16000) => {\n // Retry at exponential intervals (2, 4, 8, 16...)\n const exponentialBackoffSeconds = 2 ** nthRetry;\n // Add some randomness to avoid sending retries from separate requests all at once\n const randomFractionOfASecond = Math.random();\n const backoffSeconds = exponentialBackoffSeconds + randomFractionOfASecond;\n const backoffMilliseconds = Math.round(backoffSeconds * 1000);\n return Math.min(backoffMilliseconds, maximumBackoffMilliseconds);\n};\n\nconst createRetryInterceptor = (options = {}) => {\n const {\n httpClient = axios.create(),\n getBackoffMilliseconds = defaultGetBackoffMilliseconds,\n // By default only retry outbound request failures (not responses)\n shouldRetry = (error) => {\n const isRequestError = !error.response && error.config;\n return isRequestError;\n },\n // A per-request maxRetries can be specified in request config.\n defaultMaxRetries = 2,\n } = options;\n\n const interceptor = async (error) => {\n const { config } = error;\n\n // If no config exists there was some other error setting up the request\n if (!config) {\n return Promise.reject(error);\n }\n\n if (!shouldRetry(error)) {\n return Promise.reject(error);\n }\n\n const {\n maxRetries = defaultMaxRetries,\n } = config;\n\n const retryRequest = async (nthRetry) => {\n if (nthRetry > maxRetries) {\n // Reject with the original error\n return Promise.reject(error);\n }\n\n let retryResponse;\n\n try {\n const backoffDelay = getBackoffMilliseconds(nthRetry);\n // Delay (wrapped in a promise so we can await the setTimeout)\n await new Promise(resolve => setTimeout(resolve, backoffDelay));\n // Make retry request\n retryResponse = await httpClient.request(config);\n } catch (e) {\n return retryRequest(nthRetry + 1);\n }\n\n return retryResponse;\n };\n\n return retryRequest(1);\n };\n\n return interceptor;\n};\n\nexport default createRetryInterceptor;\nexport { defaultGetBackoffMilliseconds };\n"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB,C,CAEA;AACA;;AACA,IAAMC,6BAA6B,GAAG,SAAhCA,6BAAgC,CAACC,QAAD,EAAkD;EAAA,IAAvCC,0BAAuC,uEA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AbG;;cAgBZK,YAhBY;gBAAA,oEAgBG,iBAAOzB,QAAP;kBAAA;kBAAA;oBAAA;sBAAA;wBAAA;0BAAA,MACfA,QAAQ,GAAGwB,UADI;4BAAA;4BAAA;0BAAA;;0BAAA,iCAGVF,OAAO,CAACC,MAAR,CAAeP,KAAf,CAHU;;wBAAA;0BAAA;0BASXU,YATW,GASIZ,sBAAsB,CAACd,QAAD,CAT1B,EAUjB;;0BAViB;0BAAA,OAWX,IAAIsB,OAAJ,CAAY,UAAAK,OAAO;4BAAA,OAAIC,UAAU,CAACD,OAAD,EAAUD,YAAV,CAAd;0BAAA,CAAnB,CAXW;;wBAAA;0BAAA;0BAAA,OAaKd,UAAU,CAACiB,OAAX,CAAmBV,MAAnB,CAbL;;wBAAA;0BAajBW,aAbiB;0BAAA;0BAAA;;wBAAA;0BAAA;0BAAA;0BAAA,iCAeVL,YAAY,CAACzB,QAAQ,GAAG,CAAZ,CAfF;;wBAAA;0BAAA,iCAkBZ8B,aAlBY;;wBAAA;wBAAA;0BAAA;sBAAA;oBAAA;kBAAA;gBAAA,CAhBH;;gBAAA,gBAgBZL,YAhBY;kBAAA;gBAAA;cAAA;;cAAA,kCAqCXA,YAAY,CAAC,CAAD,CArCD;;YAAA;YAAA;cAAA;UAAA;QAAA;MAAA;IAAA,CAAH;;IAAA,gBAAXJ,WAAW;MAAA;IAAA;EAAA,GAAjB;;EAwCA,OAAOA,WAAP;AACD,CAtDD;;AAwDA,eAAeX,sBAAf;AACA,SAASX,6BAAT"}
|
package/auth/interface.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/interface.js"],"names":["PropTypes","publish","AUTHENTICATED_USER_TOPIC","AUTHENTICATED_USER_CHANGED","optionsShape","config","shape","BASE_URL","string","isRequired","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","ACCESS_TOKEN_COOKIE_NAME","CSRF_TOKEN_API_PATH","loggingService","logError","func","logInfo","serviceShape","getAuthenticatedHttpClient","getHttpClient","getLoginRedirectUrl","redirectToLogin","getLogoutRedirectUrl","redirectToLogout","getAuthenticatedUser","setAuthenticatedUser","fetchAuthenticatedUser","ensureAuthenticatedUser","hydrateAuthenticatedUser","service","configure","AuthService","options","checkPropTypes","getAuthService","Error","resetAuthService","redirectUrl","authUser"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,YAAtB;AACA,SAASC,OAAT,QAAwB,WAAxB;AAEA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,wBAAwB,GAAG,oBAAjC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,0BAA0B,aAAMD,wBAAN,aAAhC;AAEP,IAAME,YAAY,GAAG;AACnBC,EAAAA,MAAM,EAAEL,SAAS,CAACM,KAAV,CAAgB;AACtBC,IAAAA,QAAQ,EAAEP,SAAS,CAACQ,MAAV,CAAiBC,UADL;AAEtBC,IAAAA,YAAY,EAAEV,SAAS,CAACQ,MAAV,CAAiBC,UAFT;AAGtBE,IAAAA,SAAS,EAAEX,SAAS,CAACQ,MAAV,CAAiBC,UAHN;AAItBG,IAAAA,UAAU,EAAEZ,SAAS,CAACQ,MAAV,CAAiBC,UAJP;AAKtBI,IAAAA,6BAA6B,EAAEb,SAAS,CAACQ,MAAV,CAAiBC,UAL1B;AAMtBK,IAAAA,wBAAwB,EAAEd,SAAS,CAACQ,MAAV,CAAiBC,UANrB;AAOtBM,IAAAA,mBAAmB,EAAEf,SAAS,CAACQ,MAAV,CAAiBC;AAPhB,GAAhB,EAQLA,UATgB;AAUnBO,EAAAA,cAAc,EAAEhB,SAAS,CAACM,KAAV,CAAg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AACA;;AACA,OAAO,SAASb,oBAAT,GAAgC;AACrC,SAAOK,OAAO,CAACL,oBAAR,EAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,oBAAT,CAA8Ba,QAA9B,EAAwC;AAC7CT,EAAAA,OAAO,CAACJ,oBAAR,CAA6Ba,QAA7B;AACAxC,EAAAA,OAAO,CAACE,0BAAD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,gBAAsB0B,sBAAtB;AAAA;AAAA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;oFAXO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAsCM,YAAAA,OAAtC,2DAAgD,EAAhD;AAAA,6CACEH,OAAO,CAACH,sBAAR,CAA+BM,OAA/B,CADF;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G;;;;AAYP,gBAAsBL,uBAAtB;AAAA;AAAA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;qFAhBO,kBAAuCU,WAAvC;AAAA;AAAA;AAAA;AAAA;AAAA,8CACER,OAAO,CAACF,uBAAR,CAAgCU,WAAhC,CADF;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G;;;;AAiBP,gBAAsBT,wBAAtB;AAAA;AAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;sFA5DO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBACCC,OAAO,CAACD,wBAAR,EADD;;AAAA;AAEL9B,YAAAA,OAAO,CAACE,0BAAD,CAAP;;AAFK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G","sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform/auth**\n *\n * Simplifies the process of making authenticated API requests to backend edX services by providing\n * common authN/authZ client code that enables the login/logout flow and handles ensuring the\n * presence of a valid [JWT cookie](https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/oauth_dispatch/docs/decisions/0009-jwt-in-session-cookie.rst).\n *\n * The `initialize` function performs much of the auth configuration for you. If, however, you're\n * not using the `initialize` function, an authenticated API client can be created via:\n *\n * ```\n * import {\n * configure,\n * fetchAuthenticatedUser,\n * getAuthenticatedHttpClient\n * } from '@edx/frontend-platform/auth';\n * import { getConfig } from '@edx/frontend-platform';\n * import { getLoggingService } from '@edx/frontend-platform/logging';\n *\n * configure({\n * loggingService: getLoggingService(),\n * config: getConfig(),\n * });\n *\n * const authenticatedUser = await fetchAuthenticatedUser(); // validates and decodes JWT token\n * const authenticatedHttpClient = getAuthenticatedHttpClient();\n * const response = await getAuthenticatedHttpClient().get(`https://example.com/api/user/data/${authenticatedUser.username}`); // fetching from an authenticated API using user data\n * ```\n *\n * As shown in this example, auth depends on the configuration document and logging.\n *\n * NOTE: The documentation for AxiosJwtAuthService is nearly the same as that for the top-level\n * auth interface, except that it contains some Axios-specific details.\n *\n * @module Auth\n */\nimport PropTypes from 'prop-types';\nimport { publish } from '../pubSub';\n\n/**\n * @constant\n * @private\n */\nexport const AUTHENTICATED_USER_TOPIC = 'AUTHENTICATED_USER';\n\n/**\n * Published when the authenticated user data changes. This can happen when the authentication\n * service determines that the user is authenticated or anonymous, as well as when we fetch\n * additional user account data if the `hydrateAuthenticatedUser` flag has been set in the\n * `initialize` function.\n *\n * @event\n * @see {@link module:Initialization~initialize}\n */\nexport const AUTHENTICATED_USER_CHANGED = `${AUTHENTICATED_USER_TOPIC}.CHANGED`;\n\nconst optionsShape = {\n config: PropTypes.shape({\n BASE_URL: PropTypes.string.isRequired,\n LMS_BASE_URL: PropTypes.string.isRequired,\n LOGIN_URL: PropTypes.string.isRequired,\n LOGOUT_URL: PropTypes.string.isRequired,\n REFRESH_ACCESS_TOKEN_ENDPOINT: PropTypes.string.isRequired,\n ACCESS_TOKEN_COOKIE_NAME: PropTypes.string.isRequired,\n CSRF_TOKEN_API_PATH: PropTypes.string.isRequired,\n }).isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n logInfo: PropTypes.func.isRequired,\n }).isRequired,\n};\n\nconst serviceShape = {\n getAuthenticatedHttpClient: PropTypes.func.isRequired,\n getHttpClient: PropTypes.func.isRequired,\n getLoginRedirectUrl: PropTypes.func.isRequired,\n redirectToLogin: PropTypes.func.isRequired,\n getLogoutRedirectUrl: PropTypes.func.isRequired,\n redirectToLogout: PropTypes.func.isRequired,\n getAuthenticatedUser: PropTypes.func.isRequired,\n setAuthenticatedUser: PropTypes.func.isRequired,\n fetchAuthenticatedUser: PropTypes.func.isRequired,\n ensureAuthenticatedUser: PropTypes.func.isRequired,\n hydrateAuthenticatedUser: PropTypes.func.isRequired,\n};\n\nlet service;\n\n/**\n *\n * @param {class} AuthService\n * @param {*} options\n * @returns {AuthService}\n */\nexport function configure(AuthService, options) {\n PropTypes.checkPropTypes(optionsShape, options, 'property', 'Auth');\n service = new AuthService(options);\n PropTypes.checkPropTypes(serviceShape, service, 'property', 'AuthService');\n return service;\n}\n\n/**\n *\n *\n * @returns {AuthService}\n */\nexport function getAuthService() {\n if (!service) {\n throw Error('You must first configure the auth service.');\n }\n\n return service;\n}\n\n/**\n *\n */\nexport function resetAuthService() {\n service = null;\n}\n\n/**\n * Gets the authenticated HTTP client for the service.\n *\n * @param {Object} [options] Optional options for how to configure the authenticated HTTP client\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made with the returned client\n *\n * @returns {HttpClient}\n */\nexport function getAuthenticatedHttpClient(options = {}) {\n return service.getAuthenticatedHttpClient(options);\n}\n\n/**\n * Gets the unauthenticated HTTP client for the service.\n *\n * @param {Object} [options] Optional options for how to configure the authenticated HTTP client\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made with the returned client\n *\n * @returns {HttpClient}\n */\nexport function getHttpClient(options = {}) {\n return service.getHttpClient(options);\n}\n\n/**\n * Builds a URL to the login page with a post-login redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLoginRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/login?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\nexport function getLoginRedirectUrl(redirectUrl) {\n return service.getLoginRedirectUrl(redirectUrl);\n}\n\n/**\n * Redirects the user to the login page.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\nexport function redirectToLogin(redirectUrl) {\n return service.redirectToLogin(redirectUrl);\n}\n\n/**\n * Builds a URL to the logout page with a post-logout redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLogoutRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/logout?redirect_url=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\nexport function getLogoutRedirectUrl(redirectUrl) {\n return service.getLogoutRedirectUrl(redirectUrl);\n}\n\n/**\n * Redirects the user to the logout page.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\nexport function redirectToLogout(redirectUrl) {\n return service.redirectToLogout(redirectUrl);\n}\n\n/**\n * If it exists, returns the user data representing the currently authenticated user. If the\n * user is anonymous, returns null.\n *\n * @returns {UserData|null}\n */\nexport function getAuthenticatedUser() {\n return service.getAuthenticatedUser();\n}\n\n/**\n * Sets the authenticated user to the provided value.\n *\n * @param {UserData} authUser\n * @emits AUTHENTICATED_USER_CHANGED\n */\nexport function setAuthenticatedUser(authUser) {\n service.setAuthenticatedUser(authUser);\n publish(AUTHENTICATED_USER_CHANGED);\n}\n\n/**\n * Reads the authenticated user's access token. Resolves to null if the user is\n * unauthenticated.\n *\n * @returns {Promise<UserData>|Promise<null>} Resolves to the user's access token if they are\n * logged in.\n */\nexport async function fetchAuthenticatedUser(options = {}) {\n return service.fetchAuthenticatedUser(options);\n}\n\n/**\n * Ensures a user is authenticated. It will redirect to login when not\n * authenticated.\n *\n * @param {string} [redirectUrl=config.BASE_URL] to return user after login when not\n * authenticated.\n * @returns {Promise<UserData>}\n */\nexport async function ensureAuthenticatedUser(redirectUrl) {\n return service.ensureAuthenticatedUser(redirectUrl);\n}\n\n/**\n * Fetches additional user account information for the authenticated user and merges it into the\n * existing authenticatedUser object, available via getAuthenticatedUser().\n *\n * ```\n * console.log(authenticatedUser); // Will be sparse and only contain basic information.\n * await hydrateAuthenticatedUser()\n * const authenticatedUser = getAuthenticatedUser();\n * console.log(authenticatedUser); // Will contain additional user information\n * ```\n *\n * @emits AUTHENTICATED_USER_CHANGED\n */\nexport async function hydrateAuthenticatedUser() {\n await service.hydrateAuthenticatedUser();\n publish(AUTHENTICATED_USER_CHANGED);\n}\n\n/**\n * @name AuthService\n * @interface\n * @memberof module:Auth\n * @property {function} getAuthenticatedHttpClient\n * @property {function} getHttpClient\n * @property {function} getLoginRedirectUrl\n * @property {function} redirectToLogin\n * @property {function} getLogoutRedirectUrl\n * @property {function} redirectToLogout\n * @property {function} getAuthenticatedUser\n * @property {function} setAuthenticatedUser\n * @property {function} fetchAuthenticatedUser\n * @property {function} ensureAuthenticatedUser\n * @property {function} hydrateAuthenticatedUser\n */\n\n/**\n * A configured axios client. See axios docs for more\n * info https://github.com/axios/axios. All the functions\n * below accept isPublic and isCsrfExempt in the request\n * config options. Setting these to true will prevent this\n * client from attempting to refresh the jwt access token\n * or a csrf token respectively.\n *\n * ```\n * // A public endpoint (no jwt token refresh)\n * apiClient.get('/path/to/endpoint', { isPublic: true });\n * ```\n *\n * ```\n * // A csrf exempt endpoint\n * apiClient.post('/path/to/endpoint', { data }, { isCsrfExempt: true });\n * ```\n *\n * @name HttpClient\n * @interface\n * @memberof module:Auth\n * @property {function} get\n * @property {function} head\n * @property {function} options\n * @property {function} delete (csrf protected)\n * @property {function} post (csrf protected)\n * @property {function} put (csrf protected)\n * @property {function} patch (csrf protected)\n */\n\n/**\n * @name UserData\n * @interface\n * @memberof module:Auth\n * @property {string} userId\n * @property {string} username\n * @property {Array} roles\n * @property {boolean} administrator\n */\n"],"file":"interface.js"}
|
|
1
|
+
{"version":3,"file":"interface.js","names":["PropTypes","publish","AUTHENTICATED_USER_TOPIC","AUTHENTICATED_USER_CHANGED","optionsShape","config","shape","BASE_URL","string","isRequired","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","ACCESS_TOKEN_COOKIE_NAME","CSRF_TOKEN_API_PATH","loggingService","logError","func","logInfo","serviceShape","getAuthenticatedHttpClient","getHttpClient","getLoginRedirectUrl","redirectToLogin","getLogoutRedirectUrl","redirectToLogout","getAuthenticatedUser","setAuthenticatedUser","fetchAuthenticatedUser","ensureAuthenticatedUser","hydrateAuthenticatedUser","service","configure","AuthService","options","checkPropTypes","getAuthService","Error","resetAuthService","redirectUrl","authUser"],"sources":["../../src/auth/interface.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform/auth**\n *\n * Simplifies the process of making authenticated API requests to backend edX services by providing\n * common authN/authZ client code that enables the login/logout flow and handles ensuring the\n * presence of a valid [JWT cookie](https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/oauth_dispatch/docs/decisions/0009-jwt-in-session-cookie.rst).\n *\n * The `initialize` function performs much of the auth configuration for you. If, however, you're\n * not using the `initialize` function, an authenticated API client can be created via:\n *\n * ```\n * import {\n * configure,\n * fetchAuthenticatedUser,\n * getAuthenticatedHttpClient\n * } from '@edx/frontend-platform/auth';\n * import { getConfig } from '@edx/frontend-platform';\n * import { getLoggingService } from '@edx/frontend-platform/logging';\n *\n * configure({\n * loggingService: getLoggingService(),\n * config: getConfig(),\n * });\n *\n * const authenticatedUser = await fetchAuthenticatedUser(); // validates and decodes JWT token\n * const authenticatedHttpClient = getAuthenticatedHttpClient();\n * const response = await getAuthenticatedHttpClient().get(`https://example.com/api/user/data/${authenticatedUser.username}`); // fetching from an authenticated API using user data\n * ```\n *\n * As shown in this example, auth depends on the configuration document and logging.\n *\n * NOTE: The documentation for AxiosJwtAuthService is nearly the same as that for the top-level\n * auth interface, except that it contains some Axios-specific details.\n *\n * @module Auth\n */\nimport PropTypes from 'prop-types';\nimport { publish } from '../pubSub';\n\n/**\n * @constant\n * @private\n */\nexport const AUTHENTICATED_USER_TOPIC = 'AUTHENTICATED_USER';\n\n/**\n * Published when the authenticated user data changes. This can happen when the authentication\n * service determines that the user is authenticated or anonymous, as well as when we fetch\n * additional user account data if the `hydrateAuthenticatedUser` flag has been set in the\n * `initialize` function.\n *\n * @event\n * @see {@link module:Initialization~initialize}\n */\nexport const AUTHENTICATED_USER_CHANGED = `${AUTHENTICATED_USER_TOPIC}.CHANGED`;\n\nconst optionsShape = {\n config: PropTypes.shape({\n BASE_URL: PropTypes.string.isRequired,\n LMS_BASE_URL: PropTypes.string.isRequired,\n LOGIN_URL: PropTypes.string.isRequired,\n LOGOUT_URL: PropTypes.string.isRequired,\n REFRESH_ACCESS_TOKEN_ENDPOINT: PropTypes.string.isRequired,\n ACCESS_TOKEN_COOKIE_NAME: PropTypes.string.isRequired,\n CSRF_TOKEN_API_PATH: PropTypes.string.isRequired,\n }).isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n logInfo: PropTypes.func.isRequired,\n }).isRequired,\n};\n\nconst serviceShape = {\n getAuthenticatedHttpClient: PropTypes.func.isRequired,\n getHttpClient: PropTypes.func.isRequired,\n getLoginRedirectUrl: PropTypes.func.isRequired,\n redirectToLogin: PropTypes.func.isRequired,\n getLogoutRedirectUrl: PropTypes.func.isRequired,\n redirectToLogout: PropTypes.func.isRequired,\n getAuthenticatedUser: PropTypes.func.isRequired,\n setAuthenticatedUser: PropTypes.func.isRequired,\n fetchAuthenticatedUser: PropTypes.func.isRequired,\n ensureAuthenticatedUser: PropTypes.func.isRequired,\n hydrateAuthenticatedUser: PropTypes.func.isRequired,\n};\n\nlet service;\n\n/**\n *\n * @param {class} AuthService\n * @param {*} options\n * @returns {AuthService}\n */\nexport function configure(AuthService, options) {\n PropTypes.checkPropTypes(optionsShape, options, 'property', 'Auth');\n service = new AuthService(options);\n PropTypes.checkPropTypes(serviceShape, service, 'property', 'AuthService');\n return service;\n}\n\n/**\n *\n *\n * @returns {AuthService}\n */\nexport function getAuthService() {\n if (!service) {\n throw Error('You must first configure the auth service.');\n }\n\n return service;\n}\n\n/**\n *\n */\nexport function resetAuthService() {\n service = null;\n}\n\n/**\n * Gets the authenticated HTTP client for the service.\n *\n * @param {Object} [options] Optional options for how to configure the authenticated HTTP client\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made with the returned client\n *\n * @returns {HttpClient}\n */\nexport function getAuthenticatedHttpClient(options = {}) {\n return service.getAuthenticatedHttpClient(options);\n}\n\n/**\n * Gets the unauthenticated HTTP client for the service.\n *\n * @param {Object} [options] Optional options for how to configure the authenticated HTTP client\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made with the returned client\n *\n * @returns {HttpClient}\n */\nexport function getHttpClient(options = {}) {\n return service.getHttpClient(options);\n}\n\n/**\n * Builds a URL to the login page with a post-login redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLoginRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/login?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\nexport function getLoginRedirectUrl(redirectUrl) {\n return service.getLoginRedirectUrl(redirectUrl);\n}\n\n/**\n * Redirects the user to the login page.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\nexport function redirectToLogin(redirectUrl) {\n return service.redirectToLogin(redirectUrl);\n}\n\n/**\n * Builds a URL to the logout page with a post-logout redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLogoutRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/logout?redirect_url=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\nexport function getLogoutRedirectUrl(redirectUrl) {\n return service.getLogoutRedirectUrl(redirectUrl);\n}\n\n/**\n * Redirects the user to the logout page.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\nexport function redirectToLogout(redirectUrl) {\n return service.redirectToLogout(redirectUrl);\n}\n\n/**\n * If it exists, returns the user data representing the currently authenticated user. If the\n * user is anonymous, returns null.\n *\n * @returns {UserData|null}\n */\nexport function getAuthenticatedUser() {\n return service.getAuthenticatedUser();\n}\n\n/**\n * Sets the authenticated user to the provided value.\n *\n * @param {UserData} authUser\n * @emits AUTHENTICATED_USER_CHANGED\n */\nexport function setAuthenticatedUser(authUser) {\n service.setAuthenticatedUser(authUser);\n publish(AUTHENTICATED_USER_CHANGED);\n}\n\n/**\n * Reads the authenticated user's access token. Resolves to null if the user is\n * unauthenticated.\n *\n * @returns {Promise<UserData>|Promise<null>} Resolves to the user's access token if they are\n * logged in.\n */\nexport async function fetchAuthenticatedUser(options = {}) {\n return service.fetchAuthenticatedUser(options);\n}\n\n/**\n * Ensures a user is authenticated. It will redirect to login when not\n * authenticated.\n *\n * @param {string} [redirectUrl=config.BASE_URL] to return user after login when not\n * authenticated.\n * @returns {Promise<UserData>}\n */\nexport async function ensureAuthenticatedUser(redirectUrl) {\n return service.ensureAuthenticatedUser(redirectUrl);\n}\n\n/**\n * Fetches additional user account information for the authenticated user and merges it into the\n * existing authenticatedUser object, available via getAuthenticatedUser().\n *\n * ```\n * console.log(authenticatedUser); // Will be sparse and only contain basic information.\n * await hydrateAuthenticatedUser()\n * const authenticatedUser = getAuthenticatedUser();\n * console.log(authenticatedUser); // Will contain additional user information\n * ```\n *\n * @emits AUTHENTICATED_USER_CHANGED\n */\nexport async function hydrateAuthenticatedUser() {\n await service.hydrateAuthenticatedUser();\n publish(AUTHENTICATED_USER_CHANGED);\n}\n\n/**\n * @name AuthService\n * @interface\n * @memberof module:Auth\n * @property {function} getAuthenticatedHttpClient\n * @property {function} getHttpClient\n * @property {function} getLoginRedirectUrl\n * @property {function} redirectToLogin\n * @property {function} getLogoutRedirectUrl\n * @property {function} redirectToLogout\n * @property {function} getAuthenticatedUser\n * @property {function} setAuthenticatedUser\n * @property {function} fetchAuthenticatedUser\n * @property {function} ensureAuthenticatedUser\n * @property {function} hydrateAuthenticatedUser\n */\n\n/**\n * A configured axios client. See axios docs for more\n * info https://github.com/axios/axios. All the functions\n * below accept isPublic and isCsrfExempt in the request\n * config options. Setting these to true will prevent this\n * client from attempting to refresh the jwt access token\n * or a csrf token respectively.\n *\n * ```\n * // A public endpoint (no jwt token refresh)\n * apiClient.get('/path/to/endpoint', { isPublic: true });\n * ```\n *\n * ```\n * // A csrf exempt endpoint\n * apiClient.post('/path/to/endpoint', { data }, { isCsrfExempt: true });\n * ```\n *\n * @name HttpClient\n * @interface\n * @memberof module:Auth\n * @property {function} get\n * @property {function} head\n * @property {function} options\n * @property {function} delete (csrf protected)\n * @property {function} post (csrf protected)\n * @property {function} put (csrf protected)\n * @property {function} patch (csrf protected)\n */\n\n/**\n * @name UserData\n * @interface\n * @memberof module:Auth\n * @property {string} userId\n * @property {string} username\n * @property {Array} roles\n * @property {boolean} administrator\n */\n"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,YAAtB;AACA,SAASC,OAAT,QAAwB,WAAxB;AAEA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,wBAAwB,GAAG,oBAAjC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,0BAA0B,aA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AAtB;EAAA;AAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;sFA5DO;IAAA;MAAA;QAAA;UAAA;YAAA;YAAA,OACCC,OAAO,CAACD,wBAAR,EADD;;UAAA;YAEL9B,OAAO,CAACE,0BAAD,CAAP;;UAFK;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,C"}
|
package/auth/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils.js","names":["urlRegex","getUrlParts","url","found","match","fullUrl","protocol","domain","path","endFilename","endFileExtension","query","hash","e","Error","logFrontendAuthError","loggingService","error","prefixedMessageError","Object","create","message","logError","customAttributes","processAxiosError","axiosErrorObject","request","response","config","httpErrorType","httpErrorRequestUrl","httpErrorRequestMethod","method","status","data","stringifiedData","JSON","stringify","responseIsHTML","includes","httpErrorResponseData","httpErrorStatus","httpErrorMessage","processAxiosErrorAndThrow"],"sources":["../../src/auth/utils.js"],"sourcesContent":["// Lifted from here: https://regexr.com/3ok5o\nconst urlRegex = /([a-z]{1,2}tps?):\\/\\/((?:(?!(?:\\/|#|\\?|&)).)+)(?:(\\/(?:(?:(?:(?!(?:#|\\?|&)).)+\\/))?))?(?:((?:(?!(?:\\.|$|\\?|#)).)+))?(?:(\\.(?:(?!(?:\\?|$|#)).)+))?(?:(\\?(?:(?!(?:$|#)).)+))?(?:(#.+))?/;\nconst getUrlParts = (url) => {\n const found = url.match(urlRegex);\n try {\n const [\n fullUrl,\n protocol,\n domain,\n path,\n endFilename,\n endFileExtension,\n query,\n hash,\n ] = found;\n\n return {\n fullUrl,\n protocol,\n domain,\n path,\n endFilename,\n endFileExtension,\n query,\n hash,\n };\n } catch (e) {\n throw new Error(`Could not find url parts from ${url}.`);\n }\n};\n\nconst logFrontendAuthError = (loggingService, error) => {\n const prefixedMessageError = Object.create(error);\n prefixedMessageError.message = `[frontend-auth] ${error.message}`;\n loggingService.logError(prefixedMessageError, prefixedMessageError.customAttributes);\n};\n\nconst processAxiosError = (axiosErrorObject) => {\n const error = Object.create(axiosErrorObject);\n const { request, response, config } = error;\n\n if (!config) {\n error.customAttributes = {\n ...error.customAttributes,\n httpErrorType: 'unknown-api-request-error',\n };\n return error;\n }\n\n const {\n url: httpErrorRequestUrl,\n method: httpErrorRequestMethod,\n } = config;\n /* istanbul ignore else: difficult to enter the request-only error case in a unit test */\n if (response) {\n const { status, data } = response;\n const stringifiedData = JSON.stringify(data) || '(empty response)';\n const responseIsHTML = stringifiedData.includes('<!DOCTYPE html>');\n // Don't include data if it is just an HTML document, like a 500 error page.\n /* istanbul ignore next */\n const httpErrorResponseData = responseIsHTML ? '<Response is HTML>' : stringifiedData;\n error.customAttributes = {\n ...error.customAttributes,\n httpErrorType: 'api-response-error',\n httpErrorStatus: status,\n httpErrorResponseData,\n httpErrorRequestUrl,\n httpErrorRequestMethod,\n };\n error.message = `Axios Error (Response): ${status} ${httpErrorRequestUrl} ${httpErrorResponseData}`;\n } else if (request) {\n error.customAttributes = {\n ...error.customAttributes,\n httpErrorType: 'api-request-error',\n httpErrorMessage: error.message,\n httpErrorRequestUrl,\n httpErrorRequestMethod,\n };\n // This case occurs most likely because of intermittent internet connection issues\n // but it also, though less often, catches CORS or server configuration problems.\n error.message = `Axios Error (Request): ${error.message} (possible local connectivity issue) ${httpErrorRequestMethod} ${httpErrorRequestUrl}`;\n } else {\n error.customAttributes = {\n ...error.customAttributes,\n httpErrorType: 'api-request-config-error',\n httpErrorMessage: error.message,\n httpErrorRequestUrl,\n httpErrorRequestMethod,\n };\n error.message = `Axios Error (Config): ${error.message} ${httpErrorRequestMethod} ${httpErrorRequestUrl}`;\n }\n\n return error;\n};\n\nconst processAxiosErrorAndThrow = (axiosErrorObject) => {\n throw processAxiosError(axiosErrorObject);\n};\n\nexport {\n getUrlParts,\n logFrontendAuthError,\n processAxiosError,\n processAxiosErrorAndThrow,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA,IAAMA,QAAQ,GAAG,uLAAjB;;AACA,IAAMC,WAAW,GAAG,SAAdA,WAAc,CAACC,GAAD,EAAS;EAC3B,IAAMC,KAAK,GAAGD,GAAG,CAACE,KAAJ,CAAUJ,QAAV,CAAd;;EACA,IAAI;IACF,4BASIG,KATJ;IAAA,IACEE,OADF;IAAA,IAEEC,QAFF;IAAA,IAGEC,MAHF;IAAA,IAIEC,IAJF;IAAA,IAKEC,WALF;IAAA,IAMEC,gBANF;IAAA,IAOEC,KAPF;IAAA,IAQEC,IARF;;IAWA,OAAO;MACLP,OAAO,EAAPA,OADK;MAELC,QAAQ,EAARA,QAFK;MAGLC,MAAM,EAANA,MAHK;MAILC,IAAI,EAAJA,IAJK;MAKLC,WAAW,EAAXA,WALK;MAMLC,gBAAgB,EAAhBA,gBANK;MAOLC,KAAK,EAALA,KAPK;MAQLC,IAAI,EAAJA;IARK,CAAP;EAUD,CAtBD,CAsBE,OAAOC,CAAP,EAAU;IACV,MAAM,IAAIC,KAAJ,yCAA2CZ,GAA3C,OAAN;EACD;AACF,CA3BD;;AA6BA,IAAMa,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,cAAD,EAAiBC,KAAjB,EAA2B;EACtD,IAAMC,oBAAoB,GAAGC,MAAM,CAACC,MAAP,CAAcH,KAAd,CAA7B;EACAC,oBAAoB,CAACG,OAArB,6BAAkDJ,KAAK,CAACI,OAAxD;EACAL,cAAc,CAACM,QAAf,CAAwBJ,oBAAxB,EAA8CA,oBAAoB,CAACK,gBAAnE;AACD,CAJD;;AAMA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,gBAAD,E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OAH1B;MAIES,mBAAmB,EAAnBA,mBAJF;MAKEC,sBAAsB,EAAtBA;IALF,GADkB,CAQlB;IACA;;IACAd,KAAK,CAACI,OAAN,oCAA0CJ,KAAK,CAACI,OAAhD,kDAA+FU,sBAA/F,cAAyHD,mBAAzH;EACD,CAXM,MAWA;IACLb,KAAK,CAACM,gBAAN,mCACKN,KAAK,CAACM,gBADX;MAEEM,aAAa,EAAE,0BAFjB;MAGEa,gBAAgB,EAAEzB,KAAK,CAACI,OAH1B;MAIES,mBAAmB,EAAnBA,mBAJF;MAKEC,sBAAsB,EAAtBA;IALF;IAOAd,KAAK,CAACI,OAAN,mCAAyCJ,KAAK,CAACI,OAA/C,cAA0DU,sBAA1D,cAAoFD,mBAApF;EACD;;EAED,OAAOb,KAAP;AACD,CAxDD;;AA0DA,IAAM0B,yBAAyB,GAAG,SAA5BA,yBAA4B,CAAClB,gBAAD,EAAsB;EACtD,MAAMD,iBAAiB,CAACC,gBAAD,CAAvB;AACD,CAFD;;AAIA,SACExB,WADF,EAEEc,oBAFF,EAGES,iBAHF,EAIEmB,yBAJF"}
|
package/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config.js"],"names":["APP_CONFIG_INITIALIZED","CONFIG_CHANGED","publish","subscribe","ensureDefinedConfig","extractRegex","envVar","trim","RegExp","undefined","ENVIRONMENT","process","env","NODE_ENV","config","ACCESS_TOKEN_COOKIE_NAME","BASE_URL","PUBLIC_PATH","CREDENTIALS_BASE_URL","CSRF_TOKEN_API_PATH","DISCOVERY_API_BASE_URL","PUBLISHER_BASE_URL","ECOMMERCE_BASE_URL","IGNORED_ERROR_REGEX","LANGUAGE_PREFERENCE_COOKIE_NAME","LEARNING_BASE_URL","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","STUDIO_BASE_URL","MARKETING_SITE_BASE_URL","ORDER_HISTORY_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","SECURE_COOKIES","SEGMENT_KEY","SITE_NAME","USER_INFO_COOKIE_NAME","LOGO_URL","LOGO_TRADEMARK_URL","LOGO_WHITE_URL","FAVICON_URL","getConfig","setConfig","newConfig","mergeConfig","Object","assign","ensureConfig","keys","requester","forEach","key","console","warn"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,sBAAT,EAAiCC,cAAjC,QAAuD,aAAvD;AAEA,SAASC,OAAT,EAAkBC,SAAlB,QAAmC,UAAnC;AACA,SAASC,mBAAT,QAAoC,SAApC;;AAEA,SAASC,YAAT,CAAsBC,MAAtB,EAA8B;AAC5B;AACA;AACA,MAAI,OAAOA,MAAP,KAAkB,QAAlB,IAA8BA,MAAM,CAACC,IAAP,OAAkB,EAApD,EAAwD;AACtD,WAAO,IAAIC,MAAJ,CAAWF,MAAX,CAAP;AACD;;AACD,SAAOG,SAAP;AACD;;AAED,IAAMC,WAAW,GAAGC,OAAO,CAACC,GAAR,CAAYC,QAAhC;AACA,IAAIC,MAAM,GAAG;AACXC,EAAAA,wBAAwB,EAAEJ,OAAO,CAACC,GAAR,CAAYG,wBAD3B;AAEXC,EAAAA,QAAQ,EAAEL,OAAO,CAACC,GAAR,CAAYI,QAFX;AAGXC,EAAAA,WAAW,EAAEN,OAAO,CAACC,GAAR,CAAYK,WAAZ,IAA2B,GAH7B;AAIXC,EAAAA,oBAAoB,EAAEP,OAAO,CAACC,GAAR,CAAYM,oBAJvB;AAKXC,EAAAA,mBAAmB,EAAER,OAAO,CAACC,GAAR,CAAYO,mBALtB;AAMXC,EAAAA,sBAAsB,EAAET,OAAO,CAACC,GAAR,CAAYQ,sBANzB;AAOXC,EAAAA,kBAAkB,EAAEV,OAAO,CAACC,GAAR,CAAYS,kBAPrB;AAQXC,EAAAA,kBAAkB,EAAEX,OAAO,CAACC,GAAR,CAAYU,kBARrB;AASXZ,EAAAA,W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,OAAO,SAASC,SAAT,GAAqB;AAC1B,SAAO3B,MAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS4B,SAAT,CAAmBC,SAAnB,EAA8B;AACnCvC,EAAAA,mBAAmB,CAACU,MAAD,EAAS,QAAT,CAAnB;AACAA,EAAAA,MAAM,GAAG6B,SAAT;AACAzC,EAAAA,OAAO,CAACD,cAAD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS2C,WAAT,CAAqBD,SAArB,EAAgC;AACrCvC,EAAAA,mBAAmB,CAACuC,SAAD,EAAY,yBAAZ,CAAnB;AACA7B,EAAAA,MAAM,GAAG+B,MAAM,CAACC,MAAP,CAAchC,MAAd,EAAsB6B,SAAtB,CAAT;AACAzC,EAAAA,OAAO,CAACD,cAAD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS8C,YAAT,CAAsBC,IAAtB,EAAwE;AAAA,MAA5CC,SAA4C,uEAAhC,8BAAgC;AAC7E9C,EAAAA,SAAS,CAACH,sBAAD,EAAyB,YAAM;AACtCgD,IAAAA,IAAI,CAACE,OAAL,CAAa,UAACC,GAAD,EAAS;AACpB,UAAIrC,MAAM,CAACqC,GAAD,CAAN,KAAgB1C,SAApB,EAA+B;AAC7B;AACA2C,QAAAA,OAAO,CAACC,IAAR,oCAAyCF,GAAzC,6BAA+DF,SAA/D;AACD;AACF,KALD;AAMD,GAPQ,CAAT;AAQD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform**\n *\n * The configuration module provides utilities for working with an application's configuration\n * document (ConfigDocument). This module uses `process.env` to import configuration variables\n * from the command-line build process. It can be dynamically extended at run-time using a\n * `config` initialization handler. Please see the Initialization documentation for more\n * information on handlers and initialization phases.\n *\n * ```\n * import { getConfig } from '@edx/frontend-platform';\n *\n * const {\n * BASE_URL,\n * LMS_BASE_URL,\n * LOGIN_URL,\n * LOGIN_URL,\n * REFRESH_ACCESS_TOKEN_ENDPOINT,\n * ACCESS_TOKEN_COOKIE_NAME,\n * CSRF_TOKEN_API_PATH,\n * } = getConfig();\n * ```\n *\n * @module Config\n */\n\nimport { APP_CONFIG_INITIALIZED, CONFIG_CHANGED } from './constants';\n\nimport { publish, subscribe } from './pubSub';\nimport { ensureDefinedConfig } from './utils';\n\nfunction extractRegex(envVar) {\n // Convert the environment variable string to a regex, while guarding\n // against a non-string and an empty/whitespace-only string.\n if (typeof envVar === 'string' && envVar.trim() !== '') {\n return new RegExp(envVar);\n }\n return undefined;\n}\n\nconst ENVIRONMENT = process.env.NODE_ENV;\nlet config = {\n ACCESS_TOKEN_COOKIE_NAME: process.env.ACCESS_TOKEN_COOKIE_NAME,\n BASE_URL: process.env.BASE_URL,\n PUBLIC_PATH: process.env.PUBLIC_PATH || '/',\n CREDENTIALS_BASE_URL: process.env.CREDENTIALS_BASE_URL,\n CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH,\n DISCOVERY_API_BASE_URL: process.env.DISCOVERY_API_BASE_URL,\n PUBLISHER_BASE_URL: process.env.PUBLISHER_BASE_URL,\n ECOMMERCE_BASE_URL: process.env.ECOMMERCE_BASE_URL,\n ENVIRONMENT,\n IGNORED_ERROR_REGEX: extractRegex(process.env.IGNORED_ERROR_REGEX),\n LANGUAGE_PREFERENCE_COOKIE_NAME: process.env.LANGUAGE_PREFERENCE_COOKIE_NAME,\n LEARNING_BASE_URL: process.env.LEARNING_BASE_URL,\n LMS_BASE_URL: process.env.LMS_BASE_URL,\n LOGIN_URL: process.env.LOGIN_URL,\n LOGOUT_URL: process.env.LOGOUT_URL,\n STUDIO_BASE_URL: process.env.STUDIO_BASE_URL,\n MARKETING_SITE_BASE_URL: process.env.MARKETING_SITE_BASE_URL,\n ORDER_HISTORY_URL: process.env.ORDER_HISTORY_URL,\n REFRESH_ACCESS_TOKEN_ENDPOINT: process.env.REFRESH_ACCESS_TOKEN_ENDPOINT,\n SECURE_COOKIES: ENVIRONMENT !== 'development',\n SEGMENT_KEY: process.env.SEGMENT_KEY,\n SITE_NAME: process.env.SITE_NAME,\n USER_INFO_COOKIE_NAME: process.env.USER_INFO_COOKIE_NAME,\n LOGO_URL: process.env.LOGO_URL,\n LOGO_TRADEMARK_URL: process.env.LOGO_TRADEMARK_URL,\n LOGO_WHITE_URL: process.env.LOGO_WHITE_URL,\n FAVICON_URL: process.env.FAVICON_URL,\n};\n\n/**\n * Getter for the application configuration document. This is synchronous and merely returns a\n * reference to an existing object, and is thus safe to call as often as desired. The document\n * should have the following keys at a minimum:\n *\n * @returns {ConfigDocument}\n */\nexport function getConfig() {\n return config;\n}\n\n/**\n * Replaces the existing ConfigDocument. This is not commonly used, but can be helpful for tests.\n *\n * The supplied config document will be tested with `ensureDefinedConfig` to ensure it does not\n * have any `undefined` keys.\n *\n * @param {ConfigDocument} newConfig\n */\nexport function setConfig(newConfig) {\n ensureDefinedConfig(config, 'config');\n config = newConfig;\n publish(CONFIG_CHANGED);\n}\n\n/**\n * Merges additional configuration values into the ConfigDocument returned by `getConfig`. Will\n * override any values that exist with the same keys.\n *\n * ```\n * mergeConfig({\n * NEW_KEY: 'new value',\n * OTHER_NEW_KEY: 'other new value',\n * });\n *\n * If any of the key values are `undefined`, an error will be logged to 'warn'.\n *\n * @param {Object} newConfig\n */\nexport function mergeConfig(newConfig) {\n ensureDefinedConfig(newConfig, 'ProcessEnvConfigService');\n config = Object.assign(config, newConfig);\n publish(CONFIG_CHANGED);\n}\n\n/**\n * A method allowing application code to indicate that particular ConfigDocument keys are required\n * for them to function. This is useful for diagnosing development/deployment issues, primarily,\n * by surfacing misconfigurations early. For instance, if the build process fails to supply an\n * environment variable on the command-line, it's possible that one of the `process.env` variables\n * will be undefined. Should be used in conjunction with `mergeConfig` for custom `ConfigDocument`\n * properties. Requester is for informational/error reporting purposes only.\n *\n * ```\n * ensureConfig(['LMS_BASE_URL', 'LOGIN_URL'], 'MySpecialComponent');\n *\n * // Will log a warning with:\n * // \"App configuration error: LOGIN_URL is required by MySpecialComponent.\"\n * // if LOGIN_URL is undefined, for example.\n * ```\n *\n * *NOTE*: `ensureConfig` waits until `APP_CONFIG_INITIALIZED` is published to verify the existence\n * of the specified properties. This means that this function is compatible with custom `config`\n * phase handlers responsible for loading additional configuration data in the initialization\n * sequence.\n *\n * @param {Array} keys\n * @param {string} [requester='unspecified application code']\n */\nexport function ensureConfig(keys, requester = 'unspecified application code') {\n subscribe(APP_CONFIG_INITIALIZED, () => {\n keys.forEach((key) => {\n if (config[key] === undefined) {\n // eslint-disable-next-line no-console\n console.warn(`App configuration error: ${key} is required by ${requester}.`);\n }\n });\n });\n}\n\n/**\n * An object describing the current application configuration.\n *\n * The implementation loads this document via `process.env` variables.\n *\n * ```\n * {\n * BASE_URL: process.env.BASE_URL,\n * // ... other vars\n * }\n * ```\n *\n * When using Webpack (i.e., normal usage), the build process is responsible for supplying these\n * variables via command-line environment variables. That means they must be supplied at build\n * time.\n *\n * @name ConfigDocument\n * @memberof module:Config\n * @property {string} ACCESS_TOKEN_COOKIE_NAME\n * @property {string} BASE_URL The URL of the current application.\n * @property {string} CREDENTIALS_BASE_URL\n * @property {string} CSRF_TOKEN_API_PATH\n * @property {string} DISCOVERY_API_BASE_URL\n * @property {string} PUBLISHER_BASE_URL\n * @property {string} ECOMMERCE_BASE_URL\n * @property {string} ENVIRONMENT This is one of: development, production, or test.\n * @property {string} IGNORED_ERROR_REGEX\n * @property {string} LANGUAGE_PREFERENCE_COOKIE_NAME\n * @property {string} LEARNING_BASE_URL\n * @property {string} LMS_BASE_URL\n * @property {string} LOGIN_URL\n * @property {string} LOGOUT_URL\n * @property {string} STUDIO_BASE_URL\n * @property {string} MARKETING_SITE_BASE_URL\n * @property {string} ORDER_HISTORY_URL\n * @property {string} REFRESH_ACCESS_TOKEN_ENDPOINT\n * @property {boolean} SECURE_COOKIES\n * @property {string} SEGMENT_KEY\n * @property {string} SITE_NAME\n * @property {string} USER_INFO_COOKIE_NAME\n * @property {string} LOGO_URL\n * @property {string} LOGO_TRADEMARK_URL\n * @property {string} LOGO_WHITE_URL\n * @property {string} FAVICON_URL\n */\n"],"file":"config.js"}
|
|
1
|
+
{"version":3,"file":"config.js","names":["APP_CONFIG_INITIALIZED","CONFIG_CHANGED","publish","subscribe","ensureDefinedConfig","extractRegex","envVar","trim","RegExp","undefined","ENVIRONMENT","process","env","NODE_ENV","config","ACCESS_TOKEN_COOKIE_NAME","BASE_URL","PUBLIC_PATH","CREDENTIALS_BASE_URL","CSRF_TOKEN_API_PATH","DISCOVERY_API_BASE_URL","PUBLISHER_BASE_URL","ECOMMERCE_BASE_URL","IGNORED_ERROR_REGEX","LANGUAGE_PREFERENCE_COOKIE_NAME","LEARNING_BASE_URL","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","STUDIO_BASE_URL","MARKETING_SITE_BASE_URL","ORDER_HISTORY_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","SECURE_COOKIES","SEGMENT_KEY","SITE_NAME","USER_INFO_COOKIE_NAME","LOGO_URL","LOGO_TRADEMARK_URL","LOGO_WHITE_URL","FAVICON_URL","getConfig","setConfig","newConfig","mergeConfig","Object","assign","ensureConfig","keys","requester","forEach","key","console","warn"],"sources":["../src/config.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform**\n *\n * The configuration module provides utilities for working with an application's configuration\n * document (ConfigDocument). This module uses `process.env` to import configuration variables\n * from the command-line build process. It can be dynamically extended at run-time using a\n * `config` initialization handler. Please see the Initialization documentation for more\n * information on handlers and initialization phases.\n *\n * ```\n * import { getConfig } from '@edx/frontend-platform';\n *\n * const {\n * BASE_URL,\n * LMS_BASE_URL,\n * LOGIN_URL,\n * LOGIN_URL,\n * REFRESH_ACCESS_TOKEN_ENDPOINT,\n * ACCESS_TOKEN_COOKIE_NAME,\n * CSRF_TOKEN_API_PATH,\n * } = getConfig();\n * ```\n *\n * @module Config\n */\n\nimport { APP_CONFIG_INITIALIZED, CONFIG_CHANGED } from './constants';\n\nimport { publish, subscribe } from './pubSub';\nimport { ensureDefinedConfig } from './utils';\n\nfunction extractRegex(envVar) {\n // Convert the environment variable string to a regex, while guarding\n // against a non-string and an empty/whitespace-only string.\n if (typeof envVar === 'string' && envVar.trim() !== '') {\n return new RegExp(envVar);\n }\n return undefined;\n}\n\nconst ENVIRONMENT = process.env.NODE_ENV;\nlet config = {\n ACCESS_TOKEN_COOKIE_NAME: process.env.ACCESS_TOKEN_COOKIE_NAME,\n BASE_URL: process.env.BASE_URL,\n PUBLIC_PATH: process.env.PUBLIC_PATH || '/',\n CREDENTIALS_BASE_URL: process.env.CREDENTIALS_BASE_URL,\n CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH,\n DISCOVERY_API_BASE_URL: process.env.DISCOVERY_API_BASE_URL,\n PUBLISHER_BASE_URL: process.env.PUBLISHER_BASE_URL,\n ECOMMERCE_BASE_URL: process.env.ECOMMERCE_BASE_URL,\n ENVIRONMENT,\n IGNORED_ERROR_REGEX: extractRegex(process.env.IGNORED_ERROR_REGEX),\n LANGUAGE_PREFERENCE_COOKIE_NAME: process.env.LANGUAGE_PREFERENCE_COOKIE_NAME,\n LEARNING_BASE_URL: process.env.LEARNING_BASE_URL,\n LMS_BASE_URL: process.env.LMS_BASE_URL,\n LOGIN_URL: process.env.LOGIN_URL,\n LOGOUT_URL: process.env.LOGOUT_URL,\n STUDIO_BASE_URL: process.env.STUDIO_BASE_URL,\n MARKETING_SITE_BASE_URL: process.env.MARKETING_SITE_BASE_URL,\n ORDER_HISTORY_URL: process.env.ORDER_HISTORY_URL,\n REFRESH_ACCESS_TOKEN_ENDPOINT: process.env.REFRESH_ACCESS_TOKEN_ENDPOINT,\n SECURE_COOKIES: ENVIRONMENT !== 'development',\n SEGMENT_KEY: process.env.SEGMENT_KEY,\n SITE_NAME: process.env.SITE_NAME,\n USER_INFO_COOKIE_NAME: process.env.USER_INFO_COOKIE_NAME,\n LOGO_URL: process.env.LOGO_URL,\n LOGO_TRADEMARK_URL: process.env.LOGO_TRADEMARK_URL,\n LOGO_WHITE_URL: process.env.LOGO_WHITE_URL,\n FAVICON_URL: process.env.FAVICON_URL,\n};\n\n/**\n * Getter for the application configuration document. This is synchronous and merely returns a\n * reference to an existing object, and is thus safe to call as often as desired. The document\n * should have the following keys at a minimum:\n *\n * @returns {ConfigDocument}\n */\nexport function getConfig() {\n return config;\n}\n\n/**\n * Replaces the existing ConfigDocument. This is not commonly used, but can be helpful for tests.\n *\n * The supplied config document will be tested with `ensureDefinedConfig` to ensure it does not\n * have any `undefined` keys.\n *\n * @param {ConfigDocument} newConfig\n */\nexport function setConfig(newConfig) {\n ensureDefinedConfig(config, 'config');\n config = newConfig;\n publish(CONFIG_CHANGED);\n}\n\n/**\n * Merges additional configuration values into the ConfigDocument returned by `getConfig`. Will\n * override any values that exist with the same keys.\n *\n * ```\n * mergeConfig({\n * NEW_KEY: 'new value',\n * OTHER_NEW_KEY: 'other new value',\n * });\n *\n * If any of the key values are `undefined`, an error will be logged to 'warn'.\n *\n * @param {Object} newConfig\n */\nexport function mergeConfig(newConfig) {\n ensureDefinedConfig(newConfig, 'ProcessEnvConfigService');\n config = Object.assign(config, newConfig);\n publish(CONFIG_CHANGED);\n}\n\n/**\n * A method allowing application code to indicate that particular ConfigDocument keys are required\n * for them to function. This is useful for diagnosing development/deployment issues, primarily,\n * by surfacing misconfigurations early. For instance, if the build process fails to supply an\n * environment variable on the command-line, it's possible that one of the `process.env` variables\n * will be undefined. Should be used in conjunction with `mergeConfig` for custom `ConfigDocument`\n * properties. Requester is for informational/error reporting purposes only.\n *\n * ```\n * ensureConfig(['LMS_BASE_URL', 'LOGIN_URL'], 'MySpecialComponent');\n *\n * // Will log a warning with:\n * // \"App configuration error: LOGIN_URL is required by MySpecialComponent.\"\n * // if LOGIN_URL is undefined, for example.\n * ```\n *\n * *NOTE*: `ensureConfig` waits until `APP_CONFIG_INITIALIZED` is published to verify the existence\n * of the specified properties. This means that this function is compatible with custom `config`\n * phase handlers responsible for loading additional configuration data in the initialization\n * sequence.\n *\n * @param {Array} keys\n * @param {string} [requester='unspecified application code']\n */\nexport function ensureConfig(keys, requester = 'unspecified application code') {\n subscribe(APP_CONFIG_INITIALIZED, () => {\n keys.forEach((key) => {\n if (config[key] === undefined) {\n // eslint-disable-next-line no-console\n console.warn(`App configuration error: ${key} is required by ${requester}.`);\n }\n });\n });\n}\n\n/**\n * An object describing the current application configuration.\n *\n * The implementation loads this document via `process.env` variables.\n *\n * ```\n * {\n * BASE_URL: process.env.BASE_URL,\n * // ... other vars\n * }\n * ```\n *\n * When using Webpack (i.e., normal usage), the build process is responsible for supplying these\n * variables via command-line environment variables. That means they must be supplied at build\n * time.\n *\n * @name ConfigDocument\n * @memberof module:Config\n * @property {string} ACCESS_TOKEN_COOKIE_NAME\n * @property {string} BASE_URL The URL of the current application.\n * @property {string} CREDENTIALS_BASE_URL\n * @property {string} CSRF_TOKEN_API_PATH\n * @property {string} DISCOVERY_API_BASE_URL\n * @property {string} PUBLISHER_BASE_URL\n * @property {string} ECOMMERCE_BASE_URL\n * @property {string} ENVIRONMENT This is one of: development, production, or test.\n * @property {string} IGNORED_ERROR_REGEX\n * @property {string} LANGUAGE_PREFERENCE_COOKIE_NAME\n * @property {string} LEARNING_BASE_URL\n * @property {string} LMS_BASE_URL\n * @property {string} LOGIN_URL\n * @property {string} LOGOUT_URL\n * @property {string} STUDIO_BASE_URL\n * @property {string} MARKETING_SITE_BASE_URL\n * @property {string} ORDER_HISTORY_URL\n * @property {string} REFRESH_ACCESS_TOKEN_ENDPOINT\n * @property {boolean} SECURE_COOKIES\n * @property {string} SEGMENT_KEY\n * @property {string} SITE_NAME\n * @property {string} USER_INFO_COOKIE_NAME\n * @property {string} LOGO_URL\n * @property {string} LOGO_TRADEMARK_URL\n * @property {string} LOGO_WHITE_URL\n * @property {string} FAVICON_URL\n */\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,sBAAT,EAAiCC,cAAjC,QAAuD,aAAvD;AAEA,SAASC,OAAT,EAAkBC,SAAlB,QAAmC,UAAnC;AACA,SAASC,mBAAT,QAAoC,SAApC;;AAEA,SAASC,YAAT,CAAsBC,MAAtB,EAA8B;EAC5B;EACA;EACA,IAAI,OAAOA,MAAP,KAAkB,QAAlB,IAA8BA,MAAM,CAACC,IAAP,OAAkB,EAApD,EAAwD;IACtD,OAAO,IAAIC,MAAJ,CAAWF,MAAX,CAAP;EACD;;EACD,OAAOG,SAAP;AACD;;AAED,IAAMC,WAAW,GAAGC,OAAO,CAACC,GAAR,CAAYC,QAAhC;AACA,IAAIC,MAAM,GAAG;EACXC,wBAAwB,EAAEJ,OAAO,CAACC,GAAR,CAAYG,wBAD3B;EAEXC,QAAQ,EAAEL,OAAO,CAACC,GAAR,CAAYI,QAFX;EAGXC,WAAW,EAAEN,OAAO,CAACC,GAAR,CAAYK,WAAZ,IAA2B,GAH7B;EAIXC,oBAAoB,EAAEP,OAAO,CAACC,GAAR,CAAYM,oBAJvB;EAKXC,mBAAmB,EAAER,OAAO,CAACC,GAAR,CAAYO,mBALtB;EAMXC,sBAAsB,EAAET,OAAO,CAACC,GAAR,CAAYQ,sBANzB;EAOXC,kBAAkB,EAAEV,OAAO,CAACC,GAAR,CAAYS,kBAPrB;EAQXC,kBAAk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A;AACA;AACA;;AACA,OAAO,SAAS4B,SAAT,CAAmBC,SAAnB,EAA8B;EACnCvC,mBAAmB,CAACU,MAAD,EAAS,QAAT,CAAnB;EACAA,MAAM,GAAG6B,SAAT;EACAzC,OAAO,CAACD,cAAD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS2C,WAAT,CAAqBD,SAArB,EAAgC;EACrCvC,mBAAmB,CAACuC,SAAD,EAAY,yBAAZ,CAAnB;EACA7B,MAAM,GAAG+B,MAAM,CAACC,MAAP,CAAchC,MAAd,EAAsB6B,SAAtB,CAAT;EACAzC,OAAO,CAACD,cAAD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS8C,YAAT,CAAsBC,IAAtB,EAAwE;EAAA,IAA5CC,SAA4C,uEAAhC,8BAAgC;EAC7E9C,SAAS,CAACH,sBAAD,EAAyB,YAAM;IACtCgD,IAAI,CAACE,OAAL,CAAa,UAACC,GAAD,EAAS;MACpB,IAAIrC,MAAM,CAACqC,GAAD,CAAN,KAAgB1C,SAApB,EAA+B;QAC7B;QACA2C,OAAO,CAACC,IAAR,oCAAyCF,GAAzC,6BAA+DF,SAA/D;MACD;IACF,CALD;EAMD,CAPQ,CAAT;AAQD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|