@edx/frontend-platform 2.1.1 → 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.
@@ -84,20 +84,45 @@ var AxiosJwtAuthService = /*#__PURE__*/function () {
84
84
  _this.cachedHttpClient = _this.httpClient;
85
85
  logFrontendAuthError(_this.loggingService, "configureCache failed with error: ".concat(e.message));
86
86
  });
87
+ this.middleware = options.middleware;
88
+ this.applyMiddleware(options.middleware);
87
89
  }
88
90
  /**
89
- * Gets the authenticated HTTP client for the service. This is an axios instance.
91
+ * Applies middleware to the axios instances in this service.
90
92
  *
91
- * @param {Object} [options] Optional options for how the HTTP client should be configured.
92
- * @param {boolean} [options.useCache] Whether to use front end caching for all requests made
93
- * with the returned client.
94
- *
95
- * @returns {HttpClient} A configured axios http client which can be used for authenticated
96
- * requests.
93
+ * @param {Array} middleware Middleware to apply.
97
94
  */
98
95
 
99
96
 
100
97
  _createClass(AxiosJwtAuthService, [{
98
+ key: "applyMiddleware",
99
+ value: function applyMiddleware() {
100
+ var middleware = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
101
+ var clients = [this.authenticatedHttpClient, this.httpClient, this.cachedAuthenticatedHttpClient, this.cachedHttpClient];
102
+
103
+ try {
104
+ middleware.forEach(function (middlewareFn) {
105
+ clients.forEach(function (client) {
106
+ return client && middlewareFn(client);
107
+ });
108
+ });
109
+ } catch (error) {
110
+ logFrontendAuthError(this.loggingService, error);
111
+ throw error;
112
+ }
113
+ }
114
+ /**
115
+ * Gets the authenticated HTTP client for the service. This is an axios instance.
116
+ *
117
+ * @param {Object} [options] Optional options for how the HTTP client should be configured.
118
+ * @param {boolean} [options.useCache] Whether to use front end caching for all requests made
119
+ * with the returned client.
120
+ *
121
+ * @returns {HttpClient} A configured axios http client which can be used for authenticated
122
+ * requests.
123
+ */
124
+
125
+ }, {
101
126
  key: "getAuthenticatedHttpClient",
102
127
  value: function getAuthenticatedHttpClient() {
103
128
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -1 +1 @@
1
- {"version":3,"file":"AxiosJwtAuthService.js","names":["axios","PropTypes","logFrontendAuthError","camelCaseObject","ensureDefinedConfig","createJwtTokenProviderInterceptor","createCsrfTokenProviderInterceptor","createProcessAxiosRequestErrorInterceptor","AxiosJwtTokenService","AxiosCsrfTokenService","configureCache","optionsPropTypes","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","AxiosJwtAuthService","options","authenticatedHttpClient","httpClient","cachedAuthenticatedHttpClient","cachedHttpClient","authenticatedUser","checkPropTypes","jwtTokenService","csrfTokenService","addAuthenticationToHttpClient","create","then","cachedAxiosClient","e","message","useCache","redirectUrl","encodeURIComponent","global","location","assign","getLoginRedirectUrl","getLogoutRedirectUrl","authUser","getJwtToken","forceRefresh","decodedAccessToken","setAuthenticatedUser","email","userId","user_id","username","preferred_username","roles","administrator","name","getAuthenticatedUser","fetchAuthenticatedUser","isRedirectFromLoginPage","document","referrer","startsWith","redirectLoopError","Error","redirectToLogin","unauthorizedError","isRedirecting","user","get","response","data","newHttpClient","Object","defaults","withCredentials","refreshAccessTokenInterceptor","shouldSkip","axiosRequestConfig","isPublic","attachCsrfTokenInterceptor","method","isCsrfExempt","CSRF_PROTECTED_METHODS","includes","processAxiosRequestErrorInterceptor","interceptors","request","use"],"sources":["../../src/auth/AxiosJwtAuthService.js"],"sourcesContent":["import axios from 'axios';\nimport PropTypes from 'prop-types';\nimport { logFrontendAuthError } from './utils';\nimport { camelCaseObject, ensureDefinedConfig } from '../utils';\nimport createJwtTokenProviderInterceptor from './interceptors/createJwtTokenProviderInterceptor';\nimport createCsrfTokenProviderInterceptor from './interceptors/createCsrfTokenProviderInterceptor';\nimport createProcessAxiosRequestErrorInterceptor from './interceptors/createProcessAxiosRequestErrorInterceptor';\nimport AxiosJwtTokenService from './AxiosJwtTokenService';\nimport AxiosCsrfTokenService from './AxiosCsrfTokenService';\nimport configureCache from './LocalForageCache';\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};\n\n/**\n * @implements {AuthService}\n * @memberof module:Auth\n */\nclass AxiosJwtAuthService {\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.loggingService requires logError and logInfo methods\n */\n constructor(options) {\n this.authenticatedHttpClient = null;\n this.httpClient = null;\n this.cachedAuthenticatedHttpClient = null;\n this.cachedHttpClient = null;\n this.authenticatedUser = 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 this.jwtTokenService = new AxiosJwtTokenService(\n this.loggingService,\n this.config.ACCESS_TOKEN_COOKIE_NAME,\n this.config.REFRESH_ACCESS_TOKEN_ENDPOINT,\n );\n this.csrfTokenService = new AxiosCsrfTokenService(this.config.CSRF_TOKEN_API_PATH);\n this.authenticatedHttpClient = this.addAuthenticationToHttpClient(axios.create());\n this.httpClient = axios.create();\n configureCache()\n .then((cachedAxiosClient) => {\n this.cachedAuthenticatedHttpClient = this.addAuthenticationToHttpClient(cachedAxiosClient);\n this.cachedHttpClient = cachedAxiosClient;\n })\n .catch((e) => {\n // fallback to non-cached HTTP clients and log error\n this.cachedAuthenticatedHttpClient = this.authenticatedHttpClient;\n this.cachedHttpClient = this.httpClient;\n logFrontendAuthError(this.loggingService, `configureCache failed with error: ${e.message}`);\n });\n }\n\n /**\n * Gets the authenticated HTTP client for the service. This is an axios instance.\n *\n * @param {Object} [options] Optional options for how the HTTP client should be configured.\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made\n * with the returned client.\n *\n * @returns {HttpClient} A configured axios http client which can be used for authenticated\n * requests.\n */\n getAuthenticatedHttpClient(options = {}) {\n if (options.useCache) {\n return this.cachedAuthenticatedHttpClient;\n }\n return this.authenticatedHttpClient;\n }\n\n /**\n * Gets the unauthenticated HTTP client for the service. This is an axios instance.\n *\n * @param {Object} [options] Optional options for how the HTTP client should be configured.\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made\n * with the returned client.\n * @returns {HttpClient} A configured axios http client.\n */\n getHttpClient(options = {}) {\n if (options.useCache) {\n return this.cachedHttpClient;\n }\n return this.httpClient;\n }\n\n /**\n * Used primarily for testing.\n *\n * @ignore\n */\n getJwtTokenService() {\n return this.jwtTokenService;\n }\n\n /**\n * Used primarily for testing.\n *\n * @ignore\n */\n getCsrfTokenService() {\n return this.csrfTokenService;\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 */\n getLoginRedirectUrl(redirectUrl = this.config.BASE_URL) {\n return `${this.config.LOGIN_URL}?next=${encodeURIComponent(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 */\n redirectToLogin(redirectUrl = this.config.BASE_URL) {\n global.location.assign(this.getLoginRedirectUrl(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?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(redirectUrl = this.config.BASE_URL) {\n return `${this.config.LOGOUT_URL}?redirect_url=${encodeURIComponent(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 */\n redirectToLogout(redirectUrl = this.config.BASE_URL) {\n global.location.assign(this.getLogoutRedirectUrl(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 */\n getAuthenticatedUser() {\n return this.authenticatedUser;\n }\n\n /**\n * Sets the authenticated user to the provided value.\n *\n * @param {UserData} authUser\n */\n setAuthenticatedUser(authUser) {\n this.authenticatedUser = authUser;\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 */\n async fetchAuthenticatedUser(options = {}) {\n const decodedAccessToken = await this.jwtTokenService.getJwtToken(options.forceRefresh || false);\n\n if (decodedAccessToken !== null) {\n this.setAuthenticatedUser({\n email: decodedAccessToken.email,\n userId: decodedAccessToken.user_id,\n username: decodedAccessToken.preferred_username,\n roles: decodedAccessToken.roles || [],\n administrator: decodedAccessToken.administrator,\n name: decodedAccessToken.name,\n });\n } else {\n this.setAuthenticatedUser(null);\n }\n\n return this.getAuthenticatedUser();\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 */\n async ensureAuthenticatedUser(redirectUrl = this.config.BASE_URL) {\n await this.fetchAuthenticatedUser();\n\n if (this.getAuthenticatedUser() === null) {\n const isRedirectFromLoginPage = global.document.referrer\n && global.document.referrer.startsWith(this.config.LOGIN_URL);\n\n if (isRedirectFromLoginPage) {\n const redirectLoopError = new Error('Redirect from login page. Rejecting to avoid infinite redirect loop.');\n logFrontendAuthError(this.loggingService, redirectLoopError);\n throw redirectLoopError;\n }\n\n // The user is not authenticated, send them to the login page.\n this.redirectToLogin(redirectUrl);\n\n const unauthorizedError = new Error('Failed to ensure the user is authenticated');\n unauthorizedError.isRedirecting = true;\n throw unauthorizedError;\n }\n\n return this.getAuthenticatedUser();\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 * @returns {Promise<null>}\n */\n async hydrateAuthenticatedUser() {\n const user = this.getAuthenticatedUser();\n if (user !== null) {\n const response = await this.authenticatedHttpClient\n .get(`${this.config.LMS_BASE_URL}/api/user/v1/accounts/${user.username}`);\n this.setAuthenticatedUser({ ...user, ...camelCaseObject(response.data) });\n }\n }\n\n /**\n * Adds authentication defaults and interceptors to an HTTP client instance.\n *\n * @param {HttpClient} newHttpClient\n * @param {Object} config\n * @param {string} [config.REFRESH_ACCESS_TOKEN_ENDPOINT]\n * @param {string} [config.ACCESS_TOKEN_COOKIE_NAME]\n * @param {string} [config.CSRF_TOKEN_API_PATH]\n * @returns {HttpClient} A configured Axios HTTP client.\n */\n addAuthenticationToHttpClient(newHttpClient) {\n const httpClient = Object.create(newHttpClient);\n // Set withCredentials to true. Enables cross-site Access-Control requests\n // to be made using cookies, authorization headers or TLS client\n // certificates. More on MDN:\n // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials\n httpClient.defaults.withCredentials = true;\n\n // Axios interceptors\n\n // The JWT access token interceptor attempts to refresh the user's jwt token\n // before any request unless the isPublic flag is set on the request config.\n const refreshAccessTokenInterceptor = createJwtTokenProviderInterceptor({\n jwtTokenService: this.jwtTokenService,\n shouldSkip: axiosRequestConfig => axiosRequestConfig.isPublic,\n });\n // The CSRF token intercepter fetches and caches a csrf token for any post,\n // put, patch, or delete request. That token is then added to the request\n // headers.\n const attachCsrfTokenInterceptor = createCsrfTokenProviderInterceptor({\n csrfTokenService: this.csrfTokenService,\n CSRF_TOKEN_API_PATH: this.config.CSRF_TOKEN_API_PATH,\n shouldSkip: (axiosRequestConfig) => {\n const { method, isCsrfExempt } = axiosRequestConfig;\n const CSRF_PROTECTED_METHODS = ['post', 'put', 'patch', 'delete'];\n return isCsrfExempt || !CSRF_PROTECTED_METHODS.includes(method);\n },\n });\n\n const processAxiosRequestErrorInterceptor = createProcessAxiosRequestErrorInterceptor({\n loggingService: this.loggingService,\n });\n\n // Request interceptors: Axios runs the interceptors in reverse order from\n // how they are listed. After fetching csrf tokens no longer require jwt\n // authentication, it won't matter which happens first. This change is\n // coming soon in edx-platform. Nov. 2019\n httpClient.interceptors.request.use(attachCsrfTokenInterceptor);\n httpClient.interceptors.request.use(refreshAccessTokenInterceptor);\n\n // Response interceptor: moves axios response error data into the error\n // object at error.customAttributes\n httpClient.interceptors.response.use(\n response => response,\n processAxiosRequestErrorInterceptor,\n );\n\n return httpClient;\n }\n}\n\nexport default AxiosJwtAuthService;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SAASC,oBAAT,QAAqC,SAArC;AACA,SAASC,eAAT,EAA0BC,mBAA1B,QAAqD,UAArD;AACA,OAAOC,iCAAP,MAA8C,kDA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D,UAAU,EAAE,oBAAAC,kBAAkB;UAAA,OAAIA,kBAAkB,CAACC,QAAvB;QAAA;MAFwC,CAAD,CAAvE,CAZ2C,CAgB3C;MACA;MACA;;MACA,IAAMC,0BAA0B,GAAGjF,kCAAkC,CAAC;QACpE8B,gBAAgB,EAAE,KAAKA,gBAD6C;QAEpEd,mBAAmB,EAAE,KAAKV,MAAL,CAAYU,mBAFmC;QAGpE8D,UAAU,EAAE,oBAACC,kBAAD,EAAwB;UAClC,IAAQG,MAAR,GAAiCH,kBAAjC,CAAQG,MAAR;UAAA,IAAgBC,YAAhB,GAAiCJ,kBAAjC,CAAgBI,YAAhB;UACA,IAAMC,sBAAsB,GAAG,CAAC,MAAD,EAAS,KAAT,EAAgB,OAAhB,EAAyB,QAAzB,CAA/B;UACA,OAAOD,YAAY,IAAI,CAACC,sBAAsB,CAACC,QAAvB,CAAgCH,MAAhC,CAAxB;QACD;MAPmE,CAAD,CAArE;MAUA,IAAMI,mCAAmC,GAAGrF,yCAAyC,CAAC;QACpFgB,cAAc,EAAE,KAAKA;MAD+D,CAAD,CAArF,CA7B2C,CAiC3C;MACA;MACA;MACA;;MACAO,UAAU,CAAC+D,YAAX,CAAwBC,OAAxB,CAAgCC,GAAhC,CAAoCR,0BAApC;MACAzD,UAAU,CAAC+D,YAAX,CAAwBC,OAAxB,CAAgCC,GAAhC,CAAoCZ,6BAApC,EAtC2C,CAwC3C;MACA;;MACArD,UAAU,CAAC+D,YAAX,CAAwBhB,QAAxB,CAAiCkB,GAAjC,CACE,UAAAlB,QAAQ;QAAA,OAAIA,QAAJ;MAAA,CADV,EAEEe,mCAFF;MAKA,OAAO9D,UAAP;IACD;;;;;;AAGH,eAAeH,mBAAf"}
1
+ {"version":3,"file":"AxiosJwtAuthService.js","names":["axios","PropTypes","logFrontendAuthError","camelCaseObject","ensureDefinedConfig","createJwtTokenProviderInterceptor","createCsrfTokenProviderInterceptor","createProcessAxiosRequestErrorInterceptor","AxiosJwtTokenService","AxiosCsrfTokenService","configureCache","optionsPropTypes","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","AxiosJwtAuthService","options","authenticatedHttpClient","httpClient","cachedAuthenticatedHttpClient","cachedHttpClient","authenticatedUser","checkPropTypes","jwtTokenService","csrfTokenService","addAuthenticationToHttpClient","create","then","cachedAxiosClient","e","message","middleware","applyMiddleware","clients","forEach","middlewareFn","client","error","useCache","redirectUrl","encodeURIComponent","global","location","assign","getLoginRedirectUrl","getLogoutRedirectUrl","authUser","getJwtToken","forceRefresh","decodedAccessToken","setAuthenticatedUser","email","userId","user_id","username","preferred_username","roles","administrator","name","getAuthenticatedUser","fetchAuthenticatedUser","isRedirectFromLoginPage","document","referrer","startsWith","redirectLoopError","Error","redirectToLogin","unauthorizedError","isRedirecting","user","get","response","data","newHttpClient","Object","defaults","withCredentials","refreshAccessTokenInterceptor","shouldSkip","axiosRequestConfig","isPublic","attachCsrfTokenInterceptor","method","isCsrfExempt","CSRF_PROTECTED_METHODS","includes","processAxiosRequestErrorInterceptor","interceptors","request","use"],"sources":["../../src/auth/AxiosJwtAuthService.js"],"sourcesContent":["import axios from 'axios';\nimport PropTypes from 'prop-types';\nimport { logFrontendAuthError } from './utils';\nimport { camelCaseObject, ensureDefinedConfig } from '../utils';\nimport createJwtTokenProviderInterceptor from './interceptors/createJwtTokenProviderInterceptor';\nimport createCsrfTokenProviderInterceptor from './interceptors/createCsrfTokenProviderInterceptor';\nimport createProcessAxiosRequestErrorInterceptor from './interceptors/createProcessAxiosRequestErrorInterceptor';\nimport AxiosJwtTokenService from './AxiosJwtTokenService';\nimport AxiosCsrfTokenService from './AxiosCsrfTokenService';\nimport configureCache from './LocalForageCache';\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};\n\n/**\n * @implements {AuthService}\n * @memberof module:Auth\n */\nclass AxiosJwtAuthService {\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.loggingService requires logError and logInfo methods\n */\n constructor(options) {\n this.authenticatedHttpClient = null;\n this.httpClient = null;\n this.cachedAuthenticatedHttpClient = null;\n this.cachedHttpClient = null;\n this.authenticatedUser = 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 this.jwtTokenService = new AxiosJwtTokenService(\n this.loggingService,\n this.config.ACCESS_TOKEN_COOKIE_NAME,\n this.config.REFRESH_ACCESS_TOKEN_ENDPOINT,\n );\n this.csrfTokenService = new AxiosCsrfTokenService(this.config.CSRF_TOKEN_API_PATH);\n this.authenticatedHttpClient = this.addAuthenticationToHttpClient(axios.create());\n this.httpClient = axios.create();\n configureCache()\n .then((cachedAxiosClient) => {\n this.cachedAuthenticatedHttpClient = this.addAuthenticationToHttpClient(cachedAxiosClient);\n this.cachedHttpClient = cachedAxiosClient;\n })\n .catch((e) => {\n // fallback to non-cached HTTP clients and log error\n this.cachedAuthenticatedHttpClient = this.authenticatedHttpClient;\n this.cachedHttpClient = this.httpClient;\n logFrontendAuthError(this.loggingService, `configureCache failed with error: ${e.message}`);\n });\n\n this.middleware = options.middleware;\n this.applyMiddleware(options.middleware);\n }\n\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 logFrontendAuthError(this.loggingService, error);\n throw error;\n }\n }\n\n /**\n * Gets the authenticated HTTP client for the service. This is an axios instance.\n *\n * @param {Object} [options] Optional options for how the HTTP client should be configured.\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made\n * with the returned client.\n *\n * @returns {HttpClient} A configured axios http client which can be used for authenticated\n * requests.\n */\n getAuthenticatedHttpClient(options = {}) {\n if (options.useCache) {\n return this.cachedAuthenticatedHttpClient;\n }\n\n return this.authenticatedHttpClient;\n }\n\n /**\n * Gets the unauthenticated HTTP client for the service. This is an axios instance.\n *\n * @param {Object} [options] Optional options for how the HTTP client should be configured.\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made\n * with the returned client.\n * @returns {HttpClient} A configured axios http client.\n */\n getHttpClient(options = {}) {\n if (options.useCache) {\n return this.cachedHttpClient;\n }\n\n return this.httpClient;\n }\n\n /**\n * Used primarily for testing.\n *\n * @ignore\n */\n getJwtTokenService() {\n return this.jwtTokenService;\n }\n\n /**\n * Used primarily for testing.\n *\n * @ignore\n */\n getCsrfTokenService() {\n return this.csrfTokenService;\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 */\n getLoginRedirectUrl(redirectUrl = this.config.BASE_URL) {\n return `${this.config.LOGIN_URL}?next=${encodeURIComponent(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 */\n redirectToLogin(redirectUrl = this.config.BASE_URL) {\n global.location.assign(this.getLoginRedirectUrl(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?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(redirectUrl = this.config.BASE_URL) {\n return `${this.config.LOGOUT_URL}?redirect_url=${encodeURIComponent(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 */\n redirectToLogout(redirectUrl = this.config.BASE_URL) {\n global.location.assign(this.getLogoutRedirectUrl(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 */\n getAuthenticatedUser() {\n return this.authenticatedUser;\n }\n\n /**\n * Sets the authenticated user to the provided value.\n *\n * @param {UserData} authUser\n */\n setAuthenticatedUser(authUser) {\n this.authenticatedUser = authUser;\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 */\n async fetchAuthenticatedUser(options = {}) {\n const decodedAccessToken = await this.jwtTokenService.getJwtToken(options.forceRefresh || false);\n\n if (decodedAccessToken !== null) {\n this.setAuthenticatedUser({\n email: decodedAccessToken.email,\n userId: decodedAccessToken.user_id,\n username: decodedAccessToken.preferred_username,\n roles: decodedAccessToken.roles || [],\n administrator: decodedAccessToken.administrator,\n name: decodedAccessToken.name,\n });\n } else {\n this.setAuthenticatedUser(null);\n }\n\n return this.getAuthenticatedUser();\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 */\n async ensureAuthenticatedUser(redirectUrl = this.config.BASE_URL) {\n await this.fetchAuthenticatedUser();\n\n if (this.getAuthenticatedUser() === null) {\n const isRedirectFromLoginPage = global.document.referrer\n && global.document.referrer.startsWith(this.config.LOGIN_URL);\n\n if (isRedirectFromLoginPage) {\n const redirectLoopError = new Error('Redirect from login page. Rejecting to avoid infinite redirect loop.');\n logFrontendAuthError(this.loggingService, redirectLoopError);\n throw redirectLoopError;\n }\n\n // The user is not authenticated, send them to the login page.\n this.redirectToLogin(redirectUrl);\n\n const unauthorizedError = new Error('Failed to ensure the user is authenticated');\n unauthorizedError.isRedirecting = true;\n throw unauthorizedError;\n }\n\n return this.getAuthenticatedUser();\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 * @returns {Promise<null>}\n */\n async hydrateAuthenticatedUser() {\n const user = this.getAuthenticatedUser();\n if (user !== null) {\n const response = await this.authenticatedHttpClient\n .get(`${this.config.LMS_BASE_URL}/api/user/v1/accounts/${user.username}`);\n this.setAuthenticatedUser({ ...user, ...camelCaseObject(response.data) });\n }\n }\n\n /**\n * Adds authentication defaults and interceptors to an HTTP client instance.\n *\n * @param {HttpClient} newHttpClient\n * @param {Object} config\n * @param {string} [config.REFRESH_ACCESS_TOKEN_ENDPOINT]\n * @param {string} [config.ACCESS_TOKEN_COOKIE_NAME]\n * @param {string} [config.CSRF_TOKEN_API_PATH]\n * @returns {HttpClient} A configured Axios HTTP client.\n */\n addAuthenticationToHttpClient(newHttpClient) {\n const httpClient = Object.create(newHttpClient);\n // Set withCredentials to true. Enables cross-site Access-Control requests\n // to be made using cookies, authorization headers or TLS client\n // certificates. More on MDN:\n // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials\n httpClient.defaults.withCredentials = true;\n\n // Axios interceptors\n\n // The JWT access token interceptor attempts to refresh the user's jwt token\n // before any request unless the isPublic flag is set on the request config.\n const refreshAccessTokenInterceptor = createJwtTokenProviderInterceptor({\n jwtTokenService: this.jwtTokenService,\n shouldSkip: axiosRequestConfig => axiosRequestConfig.isPublic,\n });\n // The CSRF token intercepter fetches and caches a csrf token for any post,\n // put, patch, or delete request. That token is then added to the request\n // headers.\n const attachCsrfTokenInterceptor = createCsrfTokenProviderInterceptor({\n csrfTokenService: this.csrfTokenService,\n CSRF_TOKEN_API_PATH: this.config.CSRF_TOKEN_API_PATH,\n shouldSkip: (axiosRequestConfig) => {\n const { method, isCsrfExempt } = axiosRequestConfig;\n const CSRF_PROTECTED_METHODS = ['post', 'put', 'patch', 'delete'];\n return isCsrfExempt || !CSRF_PROTECTED_METHODS.includes(method);\n },\n });\n\n const processAxiosRequestErrorInterceptor = createProcessAxiosRequestErrorInterceptor({\n loggingService: this.loggingService,\n });\n\n // Request interceptors: Axios runs the interceptors in reverse order from\n // how they are listed. After fetching csrf tokens no longer require jwt\n // authentication, it won't matter which happens first. This change is\n // coming soon in edx-platform. Nov. 2019\n httpClient.interceptors.request.use(attachCsrfTokenInterceptor);\n httpClient.interceptors.request.use(refreshAccessTokenInterceptor);\n\n // Response interceptor: moves axios response error data into the error\n // object at error.customAttributes\n httpClient.interceptors.response.use(\n response => response,\n processAxiosRequestErrorInterceptor,\n );\n\n return httpClient;\n }\n}\n\nexport default AxiosJwtAuthService;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC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AI,CAACC,sBAAsB,CAACC,QAAvB,CAAgCH,MAAhC,CAAxB;QACD;MAPmE,CAAD,CAArE;MAUA,IAAMI,mCAAmC,GAAG5F,yCAAyC,CAAC;QACpFgB,cAAc,EAAE,KAAKA;MAD+D,CAAD,CAArF,CA7B2C,CAiC3C;MACA;MACA;MACA;;MACAO,UAAU,CAACsE,YAAX,CAAwBC,OAAxB,CAAgCC,GAAhC,CAAoCR,0BAApC;MACAhE,UAAU,CAACsE,YAAX,CAAwBC,OAAxB,CAAgCC,GAAhC,CAAoCZ,6BAApC,EAtC2C,CAwC3C;MACA;;MACA5D,UAAU,CAACsE,YAAX,CAAwBhB,QAAxB,CAAiCkB,GAAjC,CACE,UAAAlB,QAAQ;QAAA,OAAIA,QAAJ;MAAA,CADV,EAEEe,mCAFF;MAKA,OAAOrE,UAAP;IACD;;;;;;AAGH,eAAeH,mBAAf"}
@@ -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__*/_createClass(
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));
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
- 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
- * 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,"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"],"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 * 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"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SAASC,mBAAT,QAAoC,UAApC;AAEA,IAAMC,aAAa,GAAGF,SAAS,CAACG,KAAV,CAAgB;EACpCC,MAAM,EAAEJ,SAAS,CAACK,MAAV,CAAiBC,UADW;EAEpCC,QAAQ,EAAEP,SAAS,CAACK,MAAV,CAAiBC,UAFS;EAGpCE,KAAK,EAAER,SAAS,CAACS,OAAV,CAAkBT,SAAS,CAACK,MAA5B,CAH6B;EAIpCK,aAAa,EAAEV,SAAS;AAJY,CAAhB,CAAtB;AAOA,IAAMW,gBAAgB,GAAG;EACvBC,MAAM,EAAEZ,SAAS,CAACG,KAAV,CAAgB;IACtBU,QAAQ,EAAEb,SAAS,CAACK,MAAV,CAAiBC,UADL;IAEtBQ,YAAY,EAAEd,SAAS,CAACK,MAAV,CAAiBC,UAFT;IAGtBS,SAAS,EAAEf,SAAS,CAACK,MAAV,CAAiBC,UAHN;IAItBU,UAAU,EAAEhB,SAAS,CAACK,MAAV,CAAiBC,UAJP;IAKtBW,6BAA6B,EAAEjB,SAAS,CAACK,MAAV,CAAiBC,UAL1B;IAMtBY,wBAAwB,EAAElB,SAAS,CAACK,MAAV,CAAiBC,UANrB;IAOtBa,mBAAmB,EAAEnB,SAAS,CAACK,MAAV,CAAiBC;EAPhB,CAAhB,EAQLA,UAToB;EAUvBc,cAAc,EAAEpB,SAAS,CAACG,KAAV,CAA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aAAV,CAAnB;EACA3B,SAAS,CAAC0C,cAAV,CAAyB/B,gBAAzB,EAA2CgB,OAA3C,EAAoD,SAApD,EAA+D,aAA/D;EAEA,KAAKf,MAAL,GAAce,OAAO,CAACf,MAAtB;EACA,KAAKQ,cAAL,GAAsBO,OAAO,CAACP,cAA9B,CARmB,CAUnB;;EACA,KAAKI,iBAAL,GAAyB,KAAKZ,MAAL,CAAYY,iBAAZ,GAAgC,KAAKZ,MAAL,CAAYY,iBAA5C,GAAgE,IAAzF;EACA,KAAKC,yBAAL,GAAiC,KAAKb,MAAL,CAAYa,yBAAZ,GAC7B,KAAKb,MAAL,CAAYa,yBADiB,GAE7B,EAFJ;EAIA,KAAKK,uBAAL,GAA+B/B,KAAK,CAAC4C,MAAN,EAA/B;EACA,KAAKZ,UAAL,GAAkBhC,KAAK,CAAC4C,MAAN,EAAlB;AACD;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;;;AAiJA,eAAejB,eAAf"}
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, ...this.hydratedAuthenticatedUser });\n }\n });\n}\n\nexport default MockAuthService;\n"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SAASC,mBAAT,QAAoC,UAApC;AAEA,IAAMC,aAAa,GAAGF,SAAS,CAACG,KAAV,CAAgB;EACpCC,MAAM,EAAEJ,SAAS,CAACK,MAAV,CAAiBC,UADW;EAEpCC,QAAQ,EAAEP,SAAS,CAACK,MAAV,CAAiBC,UAFS;EAGpCE,KAAK,EAAER,SAAS,CAACS,OAAV,CAAkBT,SAAS,CAACK,MAA5B,CAH6B;EAIpCK,aAAa,EAAEV,SAAS;AAJY,CAAhB,CAAtB;AAOA,IAAMW,gBAAgB,GAAG;EACvBC,MAAM,EAAEZ,SAAS,CAACG,KAAV,CAAgB;IACtBU,QAAQ,EAAEb,SAAS,CAACK,MAAV,CAAiBC,UADL;IAEtBQ,YAAY,EAAEd,SAAS,CAACK,MAAV,CAAiBC,UAFT;IAGtBS,SAAS,EAAEf,SAAS,CAACK,MAAV,CAAiBC,UAHN;IAItBU,UAAU,EAAEhB,SAAS,CAACK,MAAV,CAAiBC,UAJP;IAKtBW,6BAA6B,EAAEjB,SAAS,CAACK,MAAV,CAAiBC,UAL1B;IAMtBY,wBAAwB,EAAElB,SAAS,CAACK,MAAV,CAAiBC,UANrB;IAOtBa,mBAAmB,EAAEnB,SAAS,CAACK,MAAV,CAAiBC;EAPhB,CAAhB,EAQLA,UAToB;EAUvBc,cAAc,EAAEpB,SAAS,CAACG,KAAV,CAAgB;IAC9BkB,QAAQ,EAAErB,SAAS,CAACsB,IAAV,CAAehB,UADK;IAE9BiB,OAAO,EAAEvB,SAAS,CAACsB,IAAV,CAAehB;EAFM,CAAhB,EAGbA,UAboB;EAcvB;EACA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A,KAAKQ,cAAL,GAAsBO,OAAO,CAACP,cAA9B,CARmB,CAUnB;;IACA,KAAKI,iBAAL,GAAyB,KAAKZ,MAAL,CAAYY,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/initialize.js CHANGED
@@ -266,6 +266,7 @@ function applyOverrideHandlers(overrides) {
266
266
  * to use.
267
267
  * @param {*} [options.analyticsService=SegmentAnalyticsService] The `AnalyticsService`
268
268
  * implementation to use.
269
+ * @param {*} [options.authMiddleware=[]] An array of middleware to apply to http clients in the auth service.
269
270
  * @param {*} [options.requireAuthenticatedUser=false] If true, turns on automatic login
270
271
  * redirection for unauthenticated users. Defaults to false, meaning that by default the
271
272
  * application will allow anonymous/unauthenticated sessions.
@@ -288,13 +289,13 @@ export function initialize(_x4) {
288
289
 
289
290
  function _initialize() {
290
291
  _initialize = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(_ref2) {
291
- var _ref2$loggingService, loggingService, _ref2$analyticsServic, analyticsService, _ref2$authService, authService, _ref2$requireAuthenti, requireUser, _ref2$hydrateAuthenti, hydrateUser, messages, _ref2$handlers, overrideHandlers, handlers;
292
+ var _ref2$loggingService, loggingService, _ref2$analyticsServic, analyticsService, _ref2$authService, authService, _ref2$authMiddleware, authMiddleware, _ref2$requireAuthenti, requireUser, _ref2$hydrateAuthenti, hydrateUser, messages, _ref2$handlers, overrideHandlers, handlers;
292
293
 
293
294
  return regeneratorRuntime.wrap(function _callee5$(_context5) {
294
295
  while (1) {
295
296
  switch (_context5.prev = _context5.next) {
296
297
  case 0:
297
- _ref2$loggingService = _ref2.loggingService, loggingService = _ref2$loggingService === void 0 ? NewRelicLoggingService : _ref2$loggingService, _ref2$analyticsServic = _ref2.analyticsService, analyticsService = _ref2$analyticsServic === void 0 ? SegmentAnalyticsService : _ref2$analyticsServic, _ref2$authService = _ref2.authService, authService = _ref2$authService === void 0 ? AxiosJwtAuthService : _ref2$authService, _ref2$requireAuthenti = _ref2.requireAuthenticatedUser, requireUser = _ref2$requireAuthenti === void 0 ? false : _ref2$requireAuthenti, _ref2$hydrateAuthenti = _ref2.hydrateAuthenticatedUser, hydrateUser = _ref2$hydrateAuthenti === void 0 ? false : _ref2$hydrateAuthenti, messages = _ref2.messages, _ref2$handlers = _ref2.handlers, overrideHandlers = _ref2$handlers === void 0 ? {} : _ref2$handlers;
298
+ _ref2$loggingService = _ref2.loggingService, loggingService = _ref2$loggingService === void 0 ? NewRelicLoggingService : _ref2$loggingService, _ref2$analyticsServic = _ref2.analyticsService, analyticsService = _ref2$analyticsServic === void 0 ? SegmentAnalyticsService : _ref2$analyticsServic, _ref2$authService = _ref2.authService, authService = _ref2$authService === void 0 ? AxiosJwtAuthService : _ref2$authService, _ref2$authMiddleware = _ref2.authMiddleware, authMiddleware = _ref2$authMiddleware === void 0 ? [] : _ref2$authMiddleware, _ref2$requireAuthenti = _ref2.requireAuthenticatedUser, requireUser = _ref2$requireAuthenti === void 0 ? false : _ref2$requireAuthenti, _ref2$hydrateAuthenti = _ref2.hydrateAuthenticatedUser, hydrateUser = _ref2$hydrateAuthenti === void 0 ? false : _ref2$hydrateAuthenti, messages = _ref2.messages, _ref2$handlers = _ref2.handlers, overrideHandlers = _ref2$handlers === void 0 ? {} : _ref2$handlers;
298
299
  handlers = applyOverrideHandlers(overrideHandlers);
299
300
  _context5.prev = 2;
300
301
  _context5.next = 5;
@@ -320,7 +321,8 @@ function _initialize() {
320
321
 
321
322
  configureAuth(authService, {
322
323
  loggingService: getLoggingService(),
323
- config: getConfig()
324
+ config: getConfig(),
325
+ middleware: authMiddleware
324
326
  });
325
327
  _context5.next = 16;
326
328
  return handlers.auth(requireUser, hydrateUser);
package/initialize.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"initialize.js","names":["createBrowserHistory","createMemoryHistory","publish","getConfig","configure","configureLogging","getLoggingService","NewRelicLoggingService","logError","configureAnalytics","SegmentAnalyticsService","identifyAnonymousUser","identifyAuthenticatedUser","getAuthenticatedHttpClient","configureAuth","ensureAuthenticatedUser","fetchAuthenticatedUser","hydrateAuthenticatedUser","getAuthenticatedUser","AxiosJwtAuthService","configureI18n","APP_PUBSUB_INITIALIZED","APP_CONFIG_INITIALIZED","APP_AUTH_INITIALIZED","APP_I18N_INITIALIZED","APP_LOGGING_INITIALIZED","APP_ANALYTICS_INITIALIZED","APP_READY","APP_INIT_ERROR","history","window","basename","PUBLIC_PATH","initError","error","auth","requireUser","hydrateUser","global","location","href","analytics","authenticatedUser","userId","applyOverrideHandlers","overrides","noOp","pubSub","config","logging","i18n","ready","initialize","loggingService","analyticsService","authService","requireAuthenticatedUser","messages","handlers","overrideHandlers","httpClient","isRedirecting"],"sources":["../src/initialize.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform**\n *\n * The initialization module provides a function for managing an application's initialization\n * lifecycle. It also provides constants and default handler implementations.\n *\n * ```\n * import {\n * initialize,\n * APP_INIT_ERROR,\n * APP_READY,\n * subscribe,\n * } from '@edx/frontend-platform';\n * import { AppProvider, ErrorPage, PageRoute } from '@edx/frontend-platform/react';\n * import React from 'react';\n * import ReactDOM from 'react-dom';\n * import { Switch } from 'react-router-dom';\n *\n * subscribe(APP_READY, () => {\n * ReactDOM.render(\n * <AppProvider store={configureStore()}>\n * <Header />\n * <main>\n * <Switch>\n * <PageRoute exact path=\"/\" component={PaymentPage} />\n * </Switch>\n * </main>\n * <Footer />\n * </AppProvider>,\n * document.getElementById('root'),\n * );\n * });\n *\n * subscribe(APP_INIT_ERROR, (error) => {\n * ReactDOM.render(<ErrorPage message={error.message} />, document.getElementById('root'));\n * });\n *\n * initialize({\n * messages: [appMessages],\n * requireAuthenticatedUser: true,\n * hydrateAuthenticatedUser: true,\n * });\n\n```\n * @module Initialization\n */\n\nimport { createBrowserHistory, createMemoryHistory } from 'history';\nimport {\n publish,\n} from './pubSub';\n// eslint-disable-next-line import/no-cycle\nimport { getConfig } from './config';\nimport {\n configure as configureLogging, getLoggingService, NewRelicLoggingService, logError,\n} from './logging';\nimport {\n configure as configureAnalytics, SegmentAnalyticsService, identifyAnonymousUser, identifyAuthenticatedUser,\n} from './analytics';\nimport {\n getAuthenticatedHttpClient,\n configure as configureAuth,\n ensureAuthenticatedUser,\n fetchAuthenticatedUser,\n hydrateAuthenticatedUser,\n getAuthenticatedUser,\n AxiosJwtAuthService,\n} from './auth';\nimport { configure as configureI18n } from './i18n';\nimport {\n APP_PUBSUB_INITIALIZED,\n APP_CONFIG_INITIALIZED,\n APP_AUTH_INITIALIZED,\n APP_I18N_INITIALIZED,\n APP_LOGGING_INITIALIZED,\n APP_ANALYTICS_INITIALIZED,\n APP_READY, APP_INIT_ERROR,\n} from './constants';\n\n/**\n * A browser history or memory history object created by the [history](https://github.com/ReactTraining/history)\n * package. Applications are encouraged to use this history object, rather than creating their own,\n * as behavior may be undefined when managing history via multiple mechanisms/instances. Note that\n * in environments where browser history may be inaccessible due to `window` being undefined, this\n * falls back to memory history.\n */\nexport const history = (typeof window !== 'undefined')\n ? createBrowserHistory({\n basename: getConfig().PUBLIC_PATH,\n }) : createMemoryHistory();\n\n/**\n * The default handler for the initialization lifecycle's `initError` phase. Logs the error to the\n * LoggingService using `logError`\n *\n * @see {@link module:frontend-platform/logging~logError}\n * @param {*} error\n */\nexport async function initError(error) {\n logError(error);\n}\n\n/**\n * The default handler for the initialization lifecycle's `auth` phase.\n *\n * The handler has several responsibilities:\n * - Determining the user's authentication state (authenticated or anonymous)\n * - Optionally redirecting to login if the application requires an authenticated user.\n * - Optionally loading additional user information via the application's user account data\n * endpoint.\n *\n * @param {boolean} requireUser Whether or not we should redirect to login if a user is not\n * authenticated.\n * @param {boolean} hydrateUser Whether or not we should fetch additional user account data.\n */\nexport async function auth(requireUser, hydrateUser) {\n if (requireUser) {\n await ensureAuthenticatedUser(global.location.href);\n } else {\n await fetchAuthenticatedUser();\n }\n\n if (hydrateUser && getAuthenticatedUser() !== null) {\n // We intentionally do not await the promise returned by hydrateAuthenticatedUser. All the\n // critical data is returned as part of fetch/ensureAuthenticatedUser above, and anything else\n // is a nice-to-have for application code.\n hydrateAuthenticatedUser();\n }\n}\n\n/**\n * The default handler for the initialization lifecycle's `analytics` phase.\n *\n * The handler is responsible for identifying authenticated and anonymous users with the analytics\n * service. This is a pre-requisite for sending analytics events, thus, we do it during the\n * initialization sequence so that analytics is ready once the application's UI code starts to load.\n *\n */\nexport async function analytics() {\n const authenticatedUser = getAuthenticatedUser();\n if (authenticatedUser && authenticatedUser.userId) {\n identifyAuthenticatedUser(authenticatedUser.userId);\n } else {\n await identifyAnonymousUser();\n }\n}\n\nfunction applyOverrideHandlers(overrides) {\n const noOp = async () => { };\n return {\n pubSub: noOp,\n config: noOp,\n logging: noOp,\n auth,\n analytics,\n i18n: noOp,\n ready: noOp,\n initError,\n ...overrides, // This will override any same-keyed handlers from above.\n };\n}\n\n/**\n * Invokes the application initialization sequence.\n *\n * The sequence proceeds through a number of lifecycle phases, during which pertinent services are\n * configured.\n *\n * Using the `handlers` option, lifecycle phase handlers can be overridden to perform custom\n * functionality. Note that while these override handlers _do_ replace the default handler\n * functionality for analytics, auth, and initError (the other phases have no default\n * functionality), they do _not_ override the configuration of the actual services that those\n * handlers leverage.\n *\n * Some services can be overridden via the loggingService and analyticsService options. The other\n * services (auth and i18n) cannot currently be overridden.\n *\n * The following lifecycle phases exist:\n *\n * - pubSub: A no-op by default.\n * - config: A no-op by default.\n * - logging: A no-op by default.\n * - auth: Uses the 'auth' handler defined above.\n * - analytics: Uses the 'analytics' handler defined above.\n * - i18n: A no-op by default.\n * - ready: A no-op by default.\n * - initError: Uses the 'initError' handler defined above.\n *\n * @param {Object} [options]\n * @param {*} [options.loggingService=NewRelicLoggingService] The `LoggingService` implementation\n * to use.\n * @param {*} [options.analyticsService=SegmentAnalyticsService] The `AnalyticsService`\n * implementation to use.\n * @param {*} [options.requireAuthenticatedUser=false] If true, turns on automatic login\n * redirection for unauthenticated users. Defaults to false, meaning that by default the\n * application will allow anonymous/unauthenticated sessions.\n * @param {*} [options.hydrateAuthenticatedUser=false] If true, makes an API call to the user\n * account endpoint (`${App.config.LMS_BASE_URL}/api/user/v1/accounts/${username}`) to fetch\n * detailed account information for the authenticated user. This data is merged into the return\n * value of `getAuthenticatedUser`, overriding any duplicate keys that already exist. Defaults to\n * false, meaning that no additional account information will be loaded.\n * @param {*} [options.messages] A i18n-compatible messages object, or an array of such objects. If\n * an array is provided, duplicate keys are resolved with the last-one-in winning.\n * @param {*} [options.handlers={}] An optional object of handlers which can be used to replace the\n * default behavior of any part of the startup sequence. It can also be used to add additional\n * initialization behavior before or after the rest of the sequence.\n */\nexport async function initialize({\n loggingService = NewRelicLoggingService,\n analyticsService = SegmentAnalyticsService,\n authService = AxiosJwtAuthService,\n requireAuthenticatedUser: requireUser = false,\n hydrateAuthenticatedUser: hydrateUser = false,\n messages,\n handlers: overrideHandlers = {},\n}) {\n const handlers = applyOverrideHandlers(overrideHandlers);\n try {\n // Pub/Sub\n await handlers.pubSub();\n publish(APP_PUBSUB_INITIALIZED);\n\n // Configuration\n await handlers.config();\n publish(APP_CONFIG_INITIALIZED);\n\n // Logging\n configureLogging(loggingService, {\n config: getConfig(),\n });\n await handlers.logging();\n publish(APP_LOGGING_INITIALIZED);\n\n // Authentication\n configureAuth(authService, {\n loggingService: getLoggingService(),\n config: getConfig(),\n });\n await handlers.auth(requireUser, hydrateUser);\n publish(APP_AUTH_INITIALIZED);\n\n // Analytics\n configureAnalytics(analyticsService, {\n config: getConfig(),\n loggingService: getLoggingService(),\n httpClient: getAuthenticatedHttpClient(),\n });\n await handlers.analytics();\n publish(APP_ANALYTICS_INITIALIZED);\n\n // Internationalization\n configureI18n({\n messages,\n config: getConfig(),\n loggingService: getLoggingService(),\n });\n await handlers.i18n();\n publish(APP_I18N_INITIALIZED);\n\n // Application Ready\n await handlers.ready();\n publish(APP_READY);\n } catch (error) {\n if (!error.isRedirecting) {\n // Initialization Error\n await handlers.initError(error);\n publish(APP_INIT_ERROR, error);\n }\n }\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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,oBAAT,EAA+BC,mBAA/B,QAA0D,SAA1D;AACA,SACEC,OADF,QAEO,UAFP,C,CAGA;;AACA,SAASC,SAAT,QAA0B,UAA1B;AACA,SACEC,SAAS,IAAIC,gBADf,EACiCC,iBADjC,EACoDC,sBADpD,EAC4E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ARA,QADY;cAEZT,MAAM,EAAE7C,SAAS,EAFL;cAGZkD,cAAc,EAAE/C,iBAAiB;YAHrB,CAAD,CAAb;YA5CG;YAAA,OAiDGoD,QAAQ,CAACR,IAAT,EAjDH;;UAAA;YAkDHhD,OAAO,CAACsB,oBAAD,CAAP,CAlDG,CAoDH;;YApDG;YAAA,OAqDGkC,QAAQ,CAACP,KAAT,EArDH;;UAAA;YAsDHjD,OAAO,CAACyB,SAAD,CAAP;YAtDG;YAAA;;UAAA;YAAA;YAAA;;YAAA,IAwDE,aAAMkC,aAxDR;cAAA;cAAA;YAAA;;YAAA;YAAA,OA0DKH,QAAQ,CAACzB,SAAT,cA1DL;;UAAA;YA2DD/B,OAAO,CAAC0B,cAAD,eAAP;;UA3DC;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,C"}
1
+ {"version":3,"file":"initialize.js","names":["createBrowserHistory","createMemoryHistory","publish","getConfig","configure","configureLogging","getLoggingService","NewRelicLoggingService","logError","configureAnalytics","SegmentAnalyticsService","identifyAnonymousUser","identifyAuthenticatedUser","getAuthenticatedHttpClient","configureAuth","ensureAuthenticatedUser","fetchAuthenticatedUser","hydrateAuthenticatedUser","getAuthenticatedUser","AxiosJwtAuthService","configureI18n","APP_PUBSUB_INITIALIZED","APP_CONFIG_INITIALIZED","APP_AUTH_INITIALIZED","APP_I18N_INITIALIZED","APP_LOGGING_INITIALIZED","APP_ANALYTICS_INITIALIZED","APP_READY","APP_INIT_ERROR","history","window","basename","PUBLIC_PATH","initError","error","auth","requireUser","hydrateUser","global","location","href","analytics","authenticatedUser","userId","applyOverrideHandlers","overrides","noOp","pubSub","config","logging","i18n","ready","initialize","loggingService","analyticsService","authService","authMiddleware","requireAuthenticatedUser","messages","handlers","overrideHandlers","middleware","httpClient","isRedirecting"],"sources":["../src/initialize.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform**\n *\n * The initialization module provides a function for managing an application's initialization\n * lifecycle. It also provides constants and default handler implementations.\n *\n * ```\n * import {\n * initialize,\n * APP_INIT_ERROR,\n * APP_READY,\n * subscribe,\n * } from '@edx/frontend-platform';\n * import { AppProvider, ErrorPage, PageRoute } from '@edx/frontend-platform/react';\n * import React from 'react';\n * import ReactDOM from 'react-dom';\n * import { Switch } from 'react-router-dom';\n *\n * subscribe(APP_READY, () => {\n * ReactDOM.render(\n * <AppProvider store={configureStore()}>\n * <Header />\n * <main>\n * <Switch>\n * <PageRoute exact path=\"/\" component={PaymentPage} />\n * </Switch>\n * </main>\n * <Footer />\n * </AppProvider>,\n * document.getElementById('root'),\n * );\n * });\n *\n * subscribe(APP_INIT_ERROR, (error) => {\n * ReactDOM.render(<ErrorPage message={error.message} />, document.getElementById('root'));\n * });\n *\n * initialize({\n * messages: [appMessages],\n * requireAuthenticatedUser: true,\n * hydrateAuthenticatedUser: true,\n * });\n\n```\n * @module Initialization\n */\n\nimport { createBrowserHistory, createMemoryHistory } from 'history';\nimport {\n publish,\n} from './pubSub';\n// eslint-disable-next-line import/no-cycle\nimport { getConfig } from './config';\nimport {\n configure as configureLogging, getLoggingService, NewRelicLoggingService, logError,\n} from './logging';\nimport {\n configure as configureAnalytics, SegmentAnalyticsService, identifyAnonymousUser, identifyAuthenticatedUser,\n} from './analytics';\nimport {\n getAuthenticatedHttpClient,\n configure as configureAuth,\n ensureAuthenticatedUser,\n fetchAuthenticatedUser,\n hydrateAuthenticatedUser,\n getAuthenticatedUser,\n AxiosJwtAuthService,\n} from './auth';\nimport { configure as configureI18n } from './i18n';\nimport {\n APP_PUBSUB_INITIALIZED,\n APP_CONFIG_INITIALIZED,\n APP_AUTH_INITIALIZED,\n APP_I18N_INITIALIZED,\n APP_LOGGING_INITIALIZED,\n APP_ANALYTICS_INITIALIZED,\n APP_READY, APP_INIT_ERROR,\n} from './constants';\n\n/**\n * A browser history or memory history object created by the [history](https://github.com/ReactTraining/history)\n * package. Applications are encouraged to use this history object, rather than creating their own,\n * as behavior may be undefined when managing history via multiple mechanisms/instances. Note that\n * in environments where browser history may be inaccessible due to `window` being undefined, this\n * falls back to memory history.\n */\nexport const history = (typeof window !== 'undefined')\n ? createBrowserHistory({\n basename: getConfig().PUBLIC_PATH,\n }) : createMemoryHistory();\n\n/**\n * The default handler for the initialization lifecycle's `initError` phase. Logs the error to the\n * LoggingService using `logError`\n *\n * @see {@link module:frontend-platform/logging~logError}\n * @param {*} error\n */\nexport async function initError(error) {\n logError(error);\n}\n\n/**\n * The default handler for the initialization lifecycle's `auth` phase.\n *\n * The handler has several responsibilities:\n * - Determining the user's authentication state (authenticated or anonymous)\n * - Optionally redirecting to login if the application requires an authenticated user.\n * - Optionally loading additional user information via the application's user account data\n * endpoint.\n *\n * @param {boolean} requireUser Whether or not we should redirect to login if a user is not\n * authenticated.\n * @param {boolean} hydrateUser Whether or not we should fetch additional user account data.\n */\nexport async function auth(requireUser, hydrateUser) {\n if (requireUser) {\n await ensureAuthenticatedUser(global.location.href);\n } else {\n await fetchAuthenticatedUser();\n }\n\n if (hydrateUser && getAuthenticatedUser() !== null) {\n // We intentionally do not await the promise returned by hydrateAuthenticatedUser. All the\n // critical data is returned as part of fetch/ensureAuthenticatedUser above, and anything else\n // is a nice-to-have for application code.\n hydrateAuthenticatedUser();\n }\n}\n\n/**\n * The default handler for the initialization lifecycle's `analytics` phase.\n *\n * The handler is responsible for identifying authenticated and anonymous users with the analytics\n * service. This is a pre-requisite for sending analytics events, thus, we do it during the\n * initialization sequence so that analytics is ready once the application's UI code starts to load.\n *\n */\nexport async function analytics() {\n const authenticatedUser = getAuthenticatedUser();\n if (authenticatedUser && authenticatedUser.userId) {\n identifyAuthenticatedUser(authenticatedUser.userId);\n } else {\n await identifyAnonymousUser();\n }\n}\n\nfunction applyOverrideHandlers(overrides) {\n const noOp = async () => { };\n return {\n pubSub: noOp,\n config: noOp,\n logging: noOp,\n auth,\n analytics,\n i18n: noOp,\n ready: noOp,\n initError,\n ...overrides, // This will override any same-keyed handlers from above.\n };\n}\n\n/**\n * Invokes the application initialization sequence.\n *\n * The sequence proceeds through a number of lifecycle phases, during which pertinent services are\n * configured.\n *\n * Using the `handlers` option, lifecycle phase handlers can be overridden to perform custom\n * functionality. Note that while these override handlers _do_ replace the default handler\n * functionality for analytics, auth, and initError (the other phases have no default\n * functionality), they do _not_ override the configuration of the actual services that those\n * handlers leverage.\n *\n * Some services can be overridden via the loggingService and analyticsService options. The other\n * services (auth and i18n) cannot currently be overridden.\n *\n * The following lifecycle phases exist:\n *\n * - pubSub: A no-op by default.\n * - config: A no-op by default.\n * - logging: A no-op by default.\n * - auth: Uses the 'auth' handler defined above.\n * - analytics: Uses the 'analytics' handler defined above.\n * - i18n: A no-op by default.\n * - ready: A no-op by default.\n * - initError: Uses the 'initError' handler defined above.\n *\n * @param {Object} [options]\n * @param {*} [options.loggingService=NewRelicLoggingService] The `LoggingService` implementation\n * to use.\n * @param {*} [options.analyticsService=SegmentAnalyticsService] The `AnalyticsService`\n * implementation to use.\n * @param {*} [options.authMiddleware=[]] An array of middleware to apply to http clients in the auth service.\n * @param {*} [options.requireAuthenticatedUser=false] If true, turns on automatic login\n * redirection for unauthenticated users. Defaults to false, meaning that by default the\n * application will allow anonymous/unauthenticated sessions.\n * @param {*} [options.hydrateAuthenticatedUser=false] If true, makes an API call to the user\n * account endpoint (`${App.config.LMS_BASE_URL}/api/user/v1/accounts/${username}`) to fetch\n * detailed account information for the authenticated user. This data is merged into the return\n * value of `getAuthenticatedUser`, overriding any duplicate keys that already exist. Defaults to\n * false, meaning that no additional account information will be loaded.\n * @param {*} [options.messages] A i18n-compatible messages object, or an array of such objects. If\n * an array is provided, duplicate keys are resolved with the last-one-in winning.\n * @param {*} [options.handlers={}] An optional object of handlers which can be used to replace the\n * default behavior of any part of the startup sequence. It can also be used to add additional\n * initialization behavior before or after the rest of the sequence.\n */\nexport async function initialize({\n loggingService = NewRelicLoggingService,\n analyticsService = SegmentAnalyticsService,\n authService = AxiosJwtAuthService,\n authMiddleware = [],\n requireAuthenticatedUser: requireUser = false,\n hydrateAuthenticatedUser: hydrateUser = false,\n messages,\n handlers: overrideHandlers = {},\n}) {\n const handlers = applyOverrideHandlers(overrideHandlers);\n try {\n // Pub/Sub\n await handlers.pubSub();\n publish(APP_PUBSUB_INITIALIZED);\n\n // Configuration\n await handlers.config();\n publish(APP_CONFIG_INITIALIZED);\n\n // Logging\n configureLogging(loggingService, {\n config: getConfig(),\n });\n await handlers.logging();\n publish(APP_LOGGING_INITIALIZED);\n\n // Authentication\n configureAuth(authService, {\n loggingService: getLoggingService(),\n config: getConfig(),\n middleware: authMiddleware,\n });\n\n await handlers.auth(requireUser, hydrateUser);\n publish(APP_AUTH_INITIALIZED);\n\n // Analytics\n configureAnalytics(analyticsService, {\n config: getConfig(),\n loggingService: getLoggingService(),\n httpClient: getAuthenticatedHttpClient(),\n });\n await handlers.analytics();\n publish(APP_ANALYTICS_INITIALIZED);\n\n // Internationalization\n configureI18n({\n messages,\n config: getConfig(),\n loggingService: getLoggingService(),\n });\n await handlers.i18n();\n publish(APP_I18N_INITIALIZED);\n\n // Application Ready\n await handlers.ready();\n publish(APP_READY);\n } catch (error) {\n if (!error.isRedirecting) {\n // Initialization Error\n await handlers.initError(error);\n publish(APP_INIT_ERROR, error);\n }\n }\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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,oBAAT,EAA+BC,mBAA/B,QAA0D,SAA1D;AACA,SACEC,OADF,QAEO,UAFP,C,CAGA;;AACA,SAASC,SAAT,QAA0B,UAA1B;AACA,SACEC,SAAS,IAAIC,gBADf,EACiCC,iBADjC,EACoDC,sBADpD,EAC4EC,QAD5E,QAEO,WAFP;AAGA,SACEJ,SAAS,IA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;YACAN,aAAa,CAAC;cACZsC,QAAQ,EAARA,QADY;cAEZV,MAAM,EAAE7C,SAAS,EAFL;cAGZkD,cAAc,EAAE/C,iBAAiB;YAHrB,CAAD,CAAb;YA/CG;YAAA,OAoDGqD,QAAQ,CAACT,IAAT,EApDH;;UAAA;YAqDHhD,OAAO,CAACsB,oBAAD,CAAP,CArDG,CAuDH;;YAvDG;YAAA,OAwDGmC,QAAQ,CAACR,KAAT,EAxDH;;UAAA;YAyDHjD,OAAO,CAACyB,SAAD,CAAP;YAzDG;YAAA;;UAAA;YAAA;YAAA;;YAAA,IA2DE,aAAMoC,aA3DR;cAAA;cAAA;YAAA;;YAAA;YAAA,OA6DKJ,QAAQ,CAAC1B,SAAT,cA7DL;;UAAA;YA8DD/B,OAAO,CAAC0B,cAAD,eAAP;;UA9DC;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edx/frontend-platform",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "Foundational application framework for Open edX micro-frontend applications.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {