@edx/frontend-platform 1.15.5 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analytics/MockAnalyticsService.js.map +1 -1
- package/analytics/SegmentAnalyticsService.js.map +1 -1
- package/analytics/index.js.map +1 -1
- package/analytics/interface.js.map +1 -1
- package/auth/AxiosCsrfTokenService.js.map +1 -1
- package/auth/AxiosJwtAuthService.js.map +1 -1
- package/auth/AxiosJwtTokenService.js.map +1 -1
- package/auth/LocalForageCache.js +36 -8
- package/auth/LocalForageCache.js.map +1 -1
- package/auth/MockAuthService.js.map +1 -1
- package/auth/index.js.map +1 -1
- package/auth/interceptors/createCsrfTokenProviderInterceptor.js.map +1 -1
- package/auth/interceptors/createJwtTokenProviderInterceptor.js.map +1 -1
- package/auth/interceptors/createProcessAxiosRequestErrorInterceptor.js.map +1 -1
- package/auth/interceptors/createRetryInterceptor.js.map +1 -1
- package/auth/interface.js.map +1 -1
- package/auth/utils.js.map +1 -1
- package/config.js.map +1 -1
- package/constants.js.map +1 -1
- package/i18n/countries.js.map +1 -1
- package/i18n/index.js +12 -18
- package/i18n/index.js.map +1 -1
- package/i18n/injectIntlWithShim.js +2 -2
- package/i18n/injectIntlWithShim.js.map +1 -1
- package/i18n/languages.js.map +1 -1
- package/i18n/lib.js +42 -17
- package/i18n/lib.js.map +1 -1
- package/i18n/scripts/transifex-utils.js.map +1 -1
- package/index.js.map +1 -1
- package/initialize.js.map +1 -1
- package/logging/MockLoggingService.js.map +1 -1
- package/logging/NewRelicLoggingService.js.map +1 -1
- package/logging/index.js.map +1 -1
- package/logging/interface.js.map +1 -1
- package/package.json +11 -8
- package/pubSub.js.map +1 -1
- package/react/AppContext.js.map +1 -1
- package/react/AppProvider.js +4 -4
- package/react/AppProvider.js.map +1 -1
- package/react/AuthenticatedPageRoute.js.map +1 -1
- package/react/ErrorBoundary.js.map +1 -1
- package/react/ErrorPage.js.map +1 -1
- package/react/LoginRedirect.js.map +1 -1
- package/react/OptionalReduxProvider.js.map +1 -1
- package/react/PageRoute.js.map +1 -1
- package/react/hooks.js.map +1 -1
- package/react/index.js.map +1 -1
- package/testing/index.js.map +1 -1
- package/testing/initializeMockApp.js.map +1 -1
- package/testing/mockMessages.js.map +1 -1
- package/utils.js.map +1 -1
package/auth/interface.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/interface.js"],"names":["PropTypes","publish","AUTHENTICATED_USER_TOPIC","AUTHENTICATED_USER_CHANGED","optionsShape","config","shape","BASE_URL","string","isRequired","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","ACCESS_TOKEN_COOKIE_NAME","CSRF_TOKEN_API_PATH","loggingService","logError","func","logInfo","serviceShape","getAuthenticatedHttpClient","getHttpClient","getLoginRedirectUrl","redirectToLogin","getLogoutRedirectUrl","redirectToLogout","getAuthenticatedUser","setAuthenticatedUser","fetchAuthenticatedUser","ensureAuthenticatedUser","hydrateAuthenticatedUser","service","configure","AuthService","options","checkPropTypes","getAuthService","Error","resetAuthService","redirectUrl","authUser"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,YAAtB;AACA,SAASC,OAAT,QAAwB,WAAxB;AAEA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,wBAAwB,GAAG,oBAAjC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,0BAA0B,aAAMD,wBAAN,aAAhC;AAEP,IAAME,YAAY,GAAG;AACnBC,EAAAA,MAAM,EAAEL,SAAS,CAACM,KAAV,CAAgB;AACtBC,IAAAA,QAAQ,EAAEP,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CU,WAAhC,CADF;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G;;;;AAiBP,gBAAsBT,wBAAtB;AAAA;AAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;sFA5DO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBACCC,OAAO,CAACD,wBAAR,EADD;;AAAA;AAEL9B,YAAAA,OAAO,CAACE,0BAAD,CAAP;;AAFK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G","sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform/auth**\n *\n * Simplifies the process of making authenticated API requests to backend edX services by providing\n * common authN/authZ client code that enables the login/logout flow and handles ensuring the\n * presence of a valid [JWT cookie](https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/oauth_dispatch/docs/decisions/0009-jwt-in-session-cookie.rst).\n *\n * The `initialize` function performs much of the auth configuration for you. If, however, you're\n * not using the `initialize` function, an authenticated API client can be created via:\n *\n * ```\n * import {\n * configure,\n * fetchAuthenticatedUser,\n * getAuthenticatedHttpClient\n * } from '@edx/frontend-platform/auth';\n * import { getConfig } from '@edx/frontend-platform';\n * import { getLoggingService } from '@edx/frontend-platform/logging';\n *\n * configure({\n * loggingService: getLoggingService(),\n * config: getConfig(),\n * });\n *\n * const authenticatedUser = await fetchAuthenticatedUser(); // validates and decodes JWT token\n * const authenticatedHttpClient = getAuthenticatedHttpClient();\n * const response = await getAuthenticatedHttpClient().get(`https://example.com/api/user/data/${authenticatedUser.username}`); // fetching from an authenticated API using user data\n * ```\n *\n * As shown in this example, auth depends on the configuration document and logging.\n *\n * NOTE: The documentation for AxiosJwtAuthService is nearly the same as that for the top-level\n * auth interface, except that it contains some Axios-specific details.\n *\n * @module Auth\n */\nimport PropTypes from 'prop-types';\nimport { publish } from '../pubSub';\n\n/**\n * @constant\n * @private\n */\nexport const AUTHENTICATED_USER_TOPIC = 'AUTHENTICATED_USER';\n\n/**\n * Published when the authenticated user data changes. This can happen when the authentication\n * service determines that the user is authenticated or anonymous, as well as when we fetch\n * additional user account data if the `hydrateAuthenticatedUser` flag has been set in the\n * `initialize` function.\n *\n * @event\n * @see {@link module:Initialization~initialize}\n */\nexport const AUTHENTICATED_USER_CHANGED = `${AUTHENTICATED_USER_TOPIC}.CHANGED`;\n\nconst optionsShape = {\n config: PropTypes.shape({\n BASE_URL: PropTypes.string.isRequired,\n LMS_BASE_URL: PropTypes.string.isRequired,\n LOGIN_URL: PropTypes.string.isRequired,\n LOGOUT_URL: PropTypes.string.isRequired,\n REFRESH_ACCESS_TOKEN_ENDPOINT: PropTypes.string.isRequired,\n ACCESS_TOKEN_COOKIE_NAME: PropTypes.string.isRequired,\n CSRF_TOKEN_API_PATH: PropTypes.string.isRequired,\n }).isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n logInfo: PropTypes.func.isRequired,\n }).isRequired,\n};\n\nconst serviceShape = {\n getAuthenticatedHttpClient: PropTypes.func.isRequired,\n getHttpClient: PropTypes.func.isRequired,\n getLoginRedirectUrl: PropTypes.func.isRequired,\n redirectToLogin: PropTypes.func.isRequired,\n getLogoutRedirectUrl: PropTypes.func.isRequired,\n redirectToLogout: PropTypes.func.isRequired,\n getAuthenticatedUser: PropTypes.func.isRequired,\n setAuthenticatedUser: PropTypes.func.isRequired,\n fetchAuthenticatedUser: PropTypes.func.isRequired,\n ensureAuthenticatedUser: PropTypes.func.isRequired,\n hydrateAuthenticatedUser: PropTypes.func.isRequired,\n};\n\nlet service;\n\n/**\n *\n * @param {class} AuthService\n * @param {*} options\n * @returns {AuthService}\n */\nexport function configure(AuthService, options) {\n PropTypes.checkPropTypes(optionsShape, options, 'property', 'Auth');\n service = new AuthService(options);\n PropTypes.checkPropTypes(serviceShape, service, 'property', 'AuthService');\n return service;\n}\n\n/**\n *\n *\n * @returns {AuthService}\n */\nexport function getAuthService() {\n if (!service) {\n throw Error('You must first configure the auth service.');\n }\n\n return service;\n}\n\n/**\n *\n */\nexport function resetAuthService() {\n service = null;\n}\n\n/**\n * Gets the authenticated HTTP client for the service.\n *\n * @param {Object} [options] Optional options for how to configure the authenticated HTTP client\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made with the returned client\n *\n * @returns {HttpClient}\n */\nexport function getAuthenticatedHttpClient(options = {}) {\n return service.getAuthenticatedHttpClient(options);\n}\n\n/**\n * Gets the unauthenticated HTTP client for the service.\n *\n * @param {Object} [options] Optional options for how to configure the authenticated HTTP client\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made with the returned client\n *\n * @returns {HttpClient}\n */\nexport function getHttpClient(options = {}) {\n return service.getHttpClient(options);\n}\n\n/**\n * Builds a URL to the login page with a post-login redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLoginRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/login?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\nexport function getLoginRedirectUrl(redirectUrl) {\n return service.getLoginRedirectUrl(redirectUrl);\n}\n\n/**\n * Redirects the user to the login page.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\nexport function redirectToLogin(redirectUrl) {\n return service.redirectToLogin(redirectUrl);\n}\n\n/**\n * Builds a URL to the logout page with a post-logout redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLogoutRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/logout?redirect_url=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\nexport function getLogoutRedirectUrl(redirectUrl) {\n return service.getLogoutRedirectUrl(redirectUrl);\n}\n\n/**\n * Redirects the user to the logout page.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\nexport function redirectToLogout(redirectUrl) {\n return service.redirectToLogout(redirectUrl);\n}\n\n/**\n * If it exists, returns the user data representing the currently authenticated user. If the\n * user is anonymous, returns null.\n *\n * @returns {UserData|null}\n */\nexport function getAuthenticatedUser() {\n return service.getAuthenticatedUser();\n}\n\n/**\n * Sets the authenticated user to the provided value.\n *\n * @param {UserData} authUser\n * @emits AUTHENTICATED_USER_CHANGED\n */\nexport function setAuthenticatedUser(authUser) {\n service.setAuthenticatedUser(authUser);\n publish(AUTHENTICATED_USER_CHANGED);\n}\n\n/**\n * Reads the authenticated user's access token. Resolves to null if the user is\n * unauthenticated.\n *\n * @returns {Promise<UserData>|Promise<null>} Resolves to the user's access token if they are\n * logged in.\n */\nexport async function fetchAuthenticatedUser(options = {}) {\n return service.fetchAuthenticatedUser(options);\n}\n\n/**\n * Ensures a user is authenticated. It will redirect to login when not\n * authenticated.\n *\n * @param {string} [redirectUrl=config.BASE_URL] to return user after login when not\n * authenticated.\n * @returns {Promise<UserData>}\n */\nexport async function ensureAuthenticatedUser(redirectUrl) {\n return service.ensureAuthenticatedUser(redirectUrl);\n}\n\n/**\n * Fetches additional user account information for the authenticated user and merges it into the\n * existing authenticatedUser object, available via getAuthenticatedUser().\n *\n * ```\n * console.log(authenticatedUser); // Will be sparse and only contain basic information.\n * await hydrateAuthenticatedUser()\n * const authenticatedUser = getAuthenticatedUser();\n * console.log(authenticatedUser); // Will contain additional user information\n * ```\n *\n * @emits AUTHENTICATED_USER_CHANGED\n */\nexport async function hydrateAuthenticatedUser() {\n await service.hydrateAuthenticatedUser();\n publish(AUTHENTICATED_USER_CHANGED);\n}\n\n/**\n * @name AuthService\n * @interface\n * @memberof module:Auth\n * @property {function} getAuthenticatedHttpClient\n * @property {function} getHttpClient\n * @property {function} getLoginRedirectUrl\n * @property {function} redirectToLogin\n * @property {function} getLogoutRedirectUrl\n * @property {function} redirectToLogout\n * @property {function} getAuthenticatedUser\n * @property {function} setAuthenticatedUser\n * @property {function} fetchAuthenticatedUser\n * @property {function} ensureAuthenticatedUser\n * @property {function} hydrateAuthenticatedUser\n */\n\n/**\n * A configured axios client. See axios docs for more\n * info https://github.com/axios/axios. All the functions\n * below accept isPublic and isCsrfExempt in the request\n * config options. Setting these to true will prevent this\n * client from attempting to refresh the jwt access token\n * or a csrf token respectively.\n *\n * ```\n * // A public endpoint (no jwt token refresh)\n * apiClient.get('/path/to/endpoint', { isPublic: true });\n * ```\n *\n * ```\n * // A csrf exempt endpoint\n * apiClient.post('/path/to/endpoint', { data }, { isCsrfExempt: true });\n * ```\n *\n * @name HttpClient\n * @interface\n * @memberof module:Auth\n * @property {function} get\n * @property {function} head\n * @property {function} options\n * @property {function} delete (csrf protected)\n * @property {function} post (csrf protected)\n * @property {function} put (csrf protected)\n * @property {function} patch (csrf protected)\n */\n\n/**\n * @name UserData\n * @interface\n * @memberof module:Auth\n * @property {string} userId\n * @property {string} username\n * @property {Array} roles\n * @property {boolean} administrator\n */\n"],"file":"interface.js"}
|
|
1
|
+
{"version":3,"file":"interface.js","names":["PropTypes","publish","AUTHENTICATED_USER_TOPIC","AUTHENTICATED_USER_CHANGED","optionsShape","config","shape","BASE_URL","string","isRequired","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","ACCESS_TOKEN_COOKIE_NAME","CSRF_TOKEN_API_PATH","loggingService","logError","func","logInfo","serviceShape","getAuthenticatedHttpClient","getHttpClient","getLoginRedirectUrl","redirectToLogin","getLogoutRedirectUrl","redirectToLogout","getAuthenticatedUser","setAuthenticatedUser","fetchAuthenticatedUser","ensureAuthenticatedUser","hydrateAuthenticatedUser","service","configure","AuthService","options","checkPropTypes","getAuthService","Error","resetAuthService","redirectUrl","authUser"],"sources":["../../src/auth/interface.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform/auth**\n *\n * Simplifies the process of making authenticated API requests to backend edX services by providing\n * common authN/authZ client code that enables the login/logout flow and handles ensuring the\n * presence of a valid [JWT cookie](https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/oauth_dispatch/docs/decisions/0009-jwt-in-session-cookie.rst).\n *\n * The `initialize` function performs much of the auth configuration for you. If, however, you're\n * not using the `initialize` function, an authenticated API client can be created via:\n *\n * ```\n * import {\n * configure,\n * fetchAuthenticatedUser,\n * getAuthenticatedHttpClient\n * } from '@edx/frontend-platform/auth';\n * import { getConfig } from '@edx/frontend-platform';\n * import { getLoggingService } from '@edx/frontend-platform/logging';\n *\n * configure({\n * loggingService: getLoggingService(),\n * config: getConfig(),\n * });\n *\n * const authenticatedUser = await fetchAuthenticatedUser(); // validates and decodes JWT token\n * const authenticatedHttpClient = getAuthenticatedHttpClient();\n * const response = await getAuthenticatedHttpClient().get(`https://example.com/api/user/data/${authenticatedUser.username}`); // fetching from an authenticated API using user data\n * ```\n *\n * As shown in this example, auth depends on the configuration document and logging.\n *\n * NOTE: The documentation for AxiosJwtAuthService is nearly the same as that for the top-level\n * auth interface, except that it contains some Axios-specific details.\n *\n * @module Auth\n */\nimport PropTypes from 'prop-types';\nimport { publish } from '../pubSub';\n\n/**\n * @constant\n * @private\n */\nexport const AUTHENTICATED_USER_TOPIC = 'AUTHENTICATED_USER';\n\n/**\n * Published when the authenticated user data changes. This can happen when the authentication\n * service determines that the user is authenticated or anonymous, as well as when we fetch\n * additional user account data if the `hydrateAuthenticatedUser` flag has been set in the\n * `initialize` function.\n *\n * @event\n * @see {@link module:Initialization~initialize}\n */\nexport const AUTHENTICATED_USER_CHANGED = `${AUTHENTICATED_USER_TOPIC}.CHANGED`;\n\nconst optionsShape = {\n config: PropTypes.shape({\n BASE_URL: PropTypes.string.isRequired,\n LMS_BASE_URL: PropTypes.string.isRequired,\n LOGIN_URL: PropTypes.string.isRequired,\n LOGOUT_URL: PropTypes.string.isRequired,\n REFRESH_ACCESS_TOKEN_ENDPOINT: PropTypes.string.isRequired,\n ACCESS_TOKEN_COOKIE_NAME: PropTypes.string.isRequired,\n CSRF_TOKEN_API_PATH: PropTypes.string.isRequired,\n }).isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n logInfo: PropTypes.func.isRequired,\n }).isRequired,\n};\n\nconst serviceShape = {\n getAuthenticatedHttpClient: PropTypes.func.isRequired,\n getHttpClient: PropTypes.func.isRequired,\n getLoginRedirectUrl: PropTypes.func.isRequired,\n redirectToLogin: PropTypes.func.isRequired,\n getLogoutRedirectUrl: PropTypes.func.isRequired,\n redirectToLogout: PropTypes.func.isRequired,\n getAuthenticatedUser: PropTypes.func.isRequired,\n setAuthenticatedUser: PropTypes.func.isRequired,\n fetchAuthenticatedUser: PropTypes.func.isRequired,\n ensureAuthenticatedUser: PropTypes.func.isRequired,\n hydrateAuthenticatedUser: PropTypes.func.isRequired,\n};\n\nlet service;\n\n/**\n *\n * @param {class} AuthService\n * @param {*} options\n * @returns {AuthService}\n */\nexport function configure(AuthService, options) {\n PropTypes.checkPropTypes(optionsShape, options, 'property', 'Auth');\n service = new AuthService(options);\n PropTypes.checkPropTypes(serviceShape, service, 'property', 'AuthService');\n return service;\n}\n\n/**\n *\n *\n * @returns {AuthService}\n */\nexport function getAuthService() {\n if (!service) {\n throw Error('You must first configure the auth service.');\n }\n\n return service;\n}\n\n/**\n *\n */\nexport function resetAuthService() {\n service = null;\n}\n\n/**\n * Gets the authenticated HTTP client for the service.\n *\n * @param {Object} [options] Optional options for how to configure the authenticated HTTP client\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made with the returned client\n *\n * @returns {HttpClient}\n */\nexport function getAuthenticatedHttpClient(options = {}) {\n return service.getAuthenticatedHttpClient(options);\n}\n\n/**\n * Gets the unauthenticated HTTP client for the service.\n *\n * @param {Object} [options] Optional options for how to configure the authenticated HTTP client\n * @param {boolean} [options.useCache] Whether to use front end caching for all requests made with the returned client\n *\n * @returns {HttpClient}\n */\nexport function getHttpClient(options = {}) {\n return service.getHttpClient(options);\n}\n\n/**\n * Builds a URL to the login page with a post-login redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLoginRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/login?next=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\nexport function getLoginRedirectUrl(redirectUrl) {\n return service.getLoginRedirectUrl(redirectUrl);\n}\n\n/**\n * Redirects the user to the login page.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging in.\n */\nexport function redirectToLogin(redirectUrl) {\n return service.redirectToLogin(redirectUrl);\n}\n\n/**\n * Builds a URL to the logout page with a post-logout redirect URL attached as a query parameter.\n *\n * ```\n * const url = getLogoutRedirectUrl('http://localhost/mypage');\n * console.log(url); // http://localhost/logout?redirect_url=http%3A%2F%2Flocalhost%2Fmypage\n * ```\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\nexport function getLogoutRedirectUrl(redirectUrl) {\n return service.getLogoutRedirectUrl(redirectUrl);\n}\n\n/**\n * Redirects the user to the logout page.\n *\n * @param {string} redirectUrl The URL the user should be redirected to after logging out.\n */\nexport function redirectToLogout(redirectUrl) {\n return service.redirectToLogout(redirectUrl);\n}\n\n/**\n * If it exists, returns the user data representing the currently authenticated user. If the\n * user is anonymous, returns null.\n *\n * @returns {UserData|null}\n */\nexport function getAuthenticatedUser() {\n return service.getAuthenticatedUser();\n}\n\n/**\n * Sets the authenticated user to the provided value.\n *\n * @param {UserData} authUser\n * @emits AUTHENTICATED_USER_CHANGED\n */\nexport function setAuthenticatedUser(authUser) {\n service.setAuthenticatedUser(authUser);\n publish(AUTHENTICATED_USER_CHANGED);\n}\n\n/**\n * Reads the authenticated user's access token. Resolves to null if the user is\n * unauthenticated.\n *\n * @returns {Promise<UserData>|Promise<null>} Resolves to the user's access token if they are\n * logged in.\n */\nexport async function fetchAuthenticatedUser(options = {}) {\n return service.fetchAuthenticatedUser(options);\n}\n\n/**\n * Ensures a user is authenticated. It will redirect to login when not\n * authenticated.\n *\n * @param {string} [redirectUrl=config.BASE_URL] to return user after login when not\n * authenticated.\n * @returns {Promise<UserData>}\n */\nexport async function ensureAuthenticatedUser(redirectUrl) {\n return service.ensureAuthenticatedUser(redirectUrl);\n}\n\n/**\n * Fetches additional user account information for the authenticated user and merges it into the\n * existing authenticatedUser object, available via getAuthenticatedUser().\n *\n * ```\n * console.log(authenticatedUser); // Will be sparse and only contain basic information.\n * await hydrateAuthenticatedUser()\n * const authenticatedUser = getAuthenticatedUser();\n * console.log(authenticatedUser); // Will contain additional user information\n * ```\n *\n * @emits AUTHENTICATED_USER_CHANGED\n */\nexport async function hydrateAuthenticatedUser() {\n await service.hydrateAuthenticatedUser();\n publish(AUTHENTICATED_USER_CHANGED);\n}\n\n/**\n * @name AuthService\n * @interface\n * @memberof module:Auth\n * @property {function} getAuthenticatedHttpClient\n * @property {function} getHttpClient\n * @property {function} getLoginRedirectUrl\n * @property {function} redirectToLogin\n * @property {function} getLogoutRedirectUrl\n * @property {function} redirectToLogout\n * @property {function} getAuthenticatedUser\n * @property {function} setAuthenticatedUser\n * @property {function} fetchAuthenticatedUser\n * @property {function} ensureAuthenticatedUser\n * @property {function} hydrateAuthenticatedUser\n */\n\n/**\n * A configured axios client. See axios docs for more\n * info https://github.com/axios/axios. All the functions\n * below accept isPublic and isCsrfExempt in the request\n * config options. Setting these to true will prevent this\n * client from attempting to refresh the jwt access token\n * or a csrf token respectively.\n *\n * ```\n * // A public endpoint (no jwt token refresh)\n * apiClient.get('/path/to/endpoint', { isPublic: true });\n * ```\n *\n * ```\n * // A csrf exempt endpoint\n * apiClient.post('/path/to/endpoint', { data }, { isCsrfExempt: true });\n * ```\n *\n * @name HttpClient\n * @interface\n * @memberof module:Auth\n * @property {function} get\n * @property {function} head\n * @property {function} options\n * @property {function} delete (csrf protected)\n * @property {function} post (csrf protected)\n * @property {function} put (csrf protected)\n * @property {function} patch (csrf protected)\n */\n\n/**\n * @name UserData\n * @interface\n * @memberof module:Auth\n * @property {string} userId\n * @property {string} username\n * @property {Array} roles\n * @property {boolean} administrator\n */\n"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,YAAtB;AACA,SAASC,OAAT,QAAwB,WAAxB;AAEA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,wBAAwB,GAAG,oBAAjC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,0BAA0B,aAAMD,wBAAN,aAAhC;AAEP,IAAME,YAAY,GAAG;EACnBC,MAAM,EAAEL,SAAS,CAACM,KAAV,CAAgB;IACtBC,QAAQ,EAAEP,SAAS,CAACQ,MAAV,CAAiBC,UADL;IAEtBC,YAAY,EAAEV,SAAS,CAACQ,MAAV,CAAiBC,UAFT;IAGtBE,SAAS,EAAEX,SAAS,CAACQ,MAAV,CAAiBC,UAHN;IAItBG,UAAU,EAAEZ,SAAS,CAACQ,MAAV,CAAiBC,UAJP;IAKtBI,6BAA6B,EAAEb,SAAS,CAACQ,MAAV,CAAiBC,UAL1B;IAMtBK,wBAAwB,EAAEd,SAAS,CAACQ,MAAV,CAAiBC,UANrB;IAOtBM,mBAAmB,EAAEf,SAAS,CAACQ,MAAV,CAAiBC;EAPhB,CAAhB,EAQLA,UATgB;EAUnBO,cAAc,EAAEhB,SAAS,CAACM,KAAV,CAAgB;IAC9BW,QAAQ,EAAEjB,SAAS,CAACkB,IAAV,CAAeT,UADK;IAE9BU,OAAO,EAAEnB,SAAS,CAACkB,IAAV,CAAeT;EAFM,CAAhB,EAGbA;AAbgB,CAArB;AAgBA,IAAMW,YAAY,GAAG;EACnBC,0BAA0B,EAAErB,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AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;oFAXO;IAAA;IAAA;IAAA;MAAA;QAAA;UAAA;YAAsCM,OAAtC,2DAAgD,EAAhD;YAAA,iCACEH,OAAO,CAACH,sBAAR,CAA+BM,OAA/B,CADF;;UAAA;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,C;;;;AAYP,gBAAsBL,uBAAtB;EAAA;AAAA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;qFAhBO,kBAAuCU,WAAvC;IAAA;MAAA;QAAA;UAAA;YAAA,kCACER,OAAO,CAACF,uBAAR,CAAgCU,WAAhC,CADF;;UAAA;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,C;;;;AAiBP,gBAAsBT,wBAAtB;EAAA;AAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;sFA5DO;IAAA;MAAA;QAAA;UAAA;YAAA;YAAA,OACCC,OAAO,CAACD,wBAAR,EADD;;UAAA;YAEL9B,OAAO,CAACE,0BAAD,CAAP;;UAFK;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,C"}
|
package/auth/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils.js","names":["urlRegex","getUrlParts","url","found","match","fullUrl","protocol","domain","path","endFilename","endFileExtension","query","hash","e","Error","logFrontendAuthError","loggingService","error","prefixedMessageError","Object","create","message","logError","customAttributes","processAxiosError","axiosErrorObject","request","response","config","httpErrorType","httpErrorRequestUrl","httpErrorRequestMethod","method","status","data","stringifiedData","JSON","stringify","responseIsHTML","includes","httpErrorResponseData","httpErrorStatus","httpErrorMessage","processAxiosErrorAndThrow"],"sources":["../../src/auth/utils.js"],"sourcesContent":["// Lifted from here: https://regexr.com/3ok5o\nconst urlRegex = /([a-z]{1,2}tps?):\\/\\/((?:(?!(?:\\/|#|\\?|&)).)+)(?:(\\/(?:(?:(?:(?!(?:#|\\?|&)).)+\\/))?))?(?:((?:(?!(?:\\.|$|\\?|#)).)+))?(?:(\\.(?:(?!(?:\\?|$|#)).)+))?(?:(\\?(?:(?!(?:$|#)).)+))?(?:(#.+))?/;\nconst getUrlParts = (url) => {\n const found = url.match(urlRegex);\n try {\n const [\n fullUrl,\n protocol,\n domain,\n path,\n endFilename,\n endFileExtension,\n query,\n hash,\n ] = found;\n\n return {\n fullUrl,\n protocol,\n domain,\n path,\n endFilename,\n endFileExtension,\n query,\n hash,\n };\n } catch (e) {\n throw new Error(`Could not find url parts from ${url}.`);\n }\n};\n\nconst logFrontendAuthError = (loggingService, error) => {\n const prefixedMessageError = Object.create(error);\n prefixedMessageError.message = `[frontend-auth] ${error.message}`;\n loggingService.logError(prefixedMessageError, prefixedMessageError.customAttributes);\n};\n\nconst processAxiosError = (axiosErrorObject) => {\n const error = Object.create(axiosErrorObject);\n const { request, response, config } = error;\n\n if (!config) {\n error.customAttributes = {\n ...error.customAttributes,\n httpErrorType: 'unknown-api-request-error',\n };\n return error;\n }\n\n const {\n url: httpErrorRequestUrl,\n method: httpErrorRequestMethod,\n } = config;\n /* istanbul ignore else: difficult to enter the request-only error case in a unit test */\n if (response) {\n const { status, data } = response;\n const stringifiedData = JSON.stringify(data) || '(empty response)';\n const responseIsHTML = stringifiedData.includes('<!DOCTYPE html>');\n // Don't include data if it is just an HTML document, like a 500 error page.\n /* istanbul ignore next */\n const httpErrorResponseData = responseIsHTML ? '<Response is HTML>' : stringifiedData;\n error.customAttributes = {\n ...error.customAttributes,\n httpErrorType: 'api-response-error',\n httpErrorStatus: status,\n httpErrorResponseData,\n httpErrorRequestUrl,\n httpErrorRequestMethod,\n };\n error.message = `Axios Error (Response): ${status} ${httpErrorRequestUrl} ${httpErrorResponseData}`;\n } else if (request) {\n error.customAttributes = {\n ...error.customAttributes,\n httpErrorType: 'api-request-error',\n httpErrorMessage: error.message,\n httpErrorRequestUrl,\n httpErrorRequestMethod,\n };\n // This case occurs most likely because of intermittent internet connection issues\n // but it also, though less often, catches CORS or server configuration problems.\n error.message = `Axios Error (Request): ${error.message} (possible local connectivity issue) ${httpErrorRequestMethod} ${httpErrorRequestUrl}`;\n } else {\n error.customAttributes = {\n ...error.customAttributes,\n httpErrorType: 'api-request-config-error',\n httpErrorMessage: error.message,\n httpErrorRequestUrl,\n httpErrorRequestMethod,\n };\n error.message = `Axios Error (Config): ${error.message} ${httpErrorRequestMethod} ${httpErrorRequestUrl}`;\n }\n\n return error;\n};\n\nconst processAxiosErrorAndThrow = (axiosErrorObject) => {\n throw processAxiosError(axiosErrorObject);\n};\n\nexport {\n getUrlParts,\n logFrontendAuthError,\n processAxiosError,\n processAxiosErrorAndThrow,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA,IAAMA,QAAQ,GAAG,uLAAjB;;AACA,IAAMC,WAAW,GAAG,SAAdA,WAAc,CAACC,GAAD,EAAS;EAC3B,IAAMC,KAAK,GAAGD,GAAG,CAACE,KAAJ,CAAUJ,QAAV,CAAd;;EACA,IAAI;IACF,4BASIG,KATJ;IAAA,IACEE,OADF;IAAA,IAEEC,QAFF;IAAA,IAGEC,MAHF;IAAA,IAIEC,IAJF;IAAA,IAKEC,WALF;IAAA,IAMEC,gBANF;IAAA,IAOEC,KAPF;IAAA,IAQEC,IARF;;IAWA,OAAO;MACLP,OAAO,EAAPA,OADK;MAELC,QAAQ,EAARA,QAFK;MAGLC,MAAM,EAANA,MAHK;MAILC,IAAI,EAAJA,IAJK;MAKLC,WAAW,EAAXA,WALK;MAMLC,gBAAgB,EAAhBA,gBANK;MAOLC,KAAK,EAALA,K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sources":["../src/config.js"],"names":["APP_CONFIG_INITIALIZED","CONFIG_CHANGED","publish","subscribe","ensureDefinedConfig","extractRegex","envVar","trim","RegExp","undefined","ENVIRONMENT","process","env","NODE_ENV","config","ACCESS_TOKEN_COOKIE_NAME","BASE_URL","PUBLIC_PATH","CREDENTIALS_BASE_URL","CSRF_TOKEN_API_PATH","DISCOVERY_API_BASE_URL","PUBLISHER_BASE_URL","ECOMMERCE_BASE_URL","IGNORED_ERROR_REGEX","LANGUAGE_PREFERENCE_COOKIE_NAME","LEARNING_BASE_URL","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","STUDIO_BASE_URL","MARKETING_SITE_BASE_URL","ORDER_HISTORY_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","SECURE_COOKIES","SEGMENT_KEY","SITE_NAME","USER_INFO_COOKIE_NAME","LOGO_URL","LOGO_TRADEMARK_URL","LOGO_WHITE_URL","FAVICON_URL","getConfig","setConfig","newConfig","mergeConfig","Object","assign","ensureConfig","keys","requester","forEach","key","console","warn"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,sBAAT,EAAiCC,cAAjC,QAAuD,aAAvD;AAEA,SAASC,OAAT,EAAkBC,SAAlB,QAAmC,UAAnC;AACA,SAASC,mBAAT,QAAoC,SAApC;;AAEA,SAASC,YAAT,CAAsBC,MAAtB,EAA8B;AAC5B;AACA;AACA,MAAI,OAAOA,MAAP,KAAkB,QAAlB,IAA8BA,MAAM,CAACC,IAAP,OAAkB,EAApD,EAAwD;AACtD,WAAO,IAAIC,MAAJ,CAAWF,MAAX,CAAP;AACD;;AACD,SAAOG,SAAP;AACD;;AAED,IAAMC,WAAW,GAAGC,OAAO,CAACC,GAAR,CAAYC,QAAhC;AACA,IAAIC,MAAM,GAAG;AACXC,EAAAA,wBAAwB,EAAEJ,OAAO,C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AA,MAA5CC,SAA4C,uEAAhC,8BAAgC;AAC7E9C,EAAAA,SAAS,CAACH,sBAAD,EAAyB,YAAM;AACtCgD,IAAAA,IAAI,CAACE,OAAL,CAAa,UAACC,GAAD,EAAS;AACpB,UAAIrC,MAAM,CAACqC,GAAD,CAAN,KAAgB1C,SAApB,EAA+B;AAC7B;AACA2C,QAAAA,OAAO,CAACC,IAAR,oCAAyCF,GAAzC,6BAA+DF,SAA/D;AACD;AACF,KALD;AAMD,GAPQ,CAAT;AAQD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform**\n *\n * The configuration module provides utilities for working with an application's configuration\n * document (ConfigDocument). This module uses `process.env` to import configuration variables\n * from the command-line build process. It can be dynamically extended at run-time using a\n * `config` initialization handler. Please see the Initialization documentation for more\n * information on handlers and initialization phases.\n *\n * ```\n * import { getConfig } from '@edx/frontend-platform';\n *\n * const {\n * BASE_URL,\n * LMS_BASE_URL,\n * LOGIN_URL,\n * LOGIN_URL,\n * REFRESH_ACCESS_TOKEN_ENDPOINT,\n * ACCESS_TOKEN_COOKIE_NAME,\n * CSRF_TOKEN_API_PATH,\n * } = getConfig();\n * ```\n *\n * @module Config\n */\n\nimport { APP_CONFIG_INITIALIZED, CONFIG_CHANGED } from './constants';\n\nimport { publish, subscribe } from './pubSub';\nimport { ensureDefinedConfig } from './utils';\n\nfunction extractRegex(envVar) {\n // Convert the environment variable string to a regex, while guarding\n // against a non-string and an empty/whitespace-only string.\n if (typeof envVar === 'string' && envVar.trim() !== '') {\n return new RegExp(envVar);\n }\n return undefined;\n}\n\nconst ENVIRONMENT = process.env.NODE_ENV;\nlet config = {\n ACCESS_TOKEN_COOKIE_NAME: process.env.ACCESS_TOKEN_COOKIE_NAME,\n BASE_URL: process.env.BASE_URL,\n PUBLIC_PATH: process.env.PUBLIC_PATH || '/',\n CREDENTIALS_BASE_URL: process.env.CREDENTIALS_BASE_URL,\n CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH,\n DISCOVERY_API_BASE_URL: process.env.DISCOVERY_API_BASE_URL,\n PUBLISHER_BASE_URL: process.env.PUBLISHER_BASE_URL,\n ECOMMERCE_BASE_URL: process.env.ECOMMERCE_BASE_URL,\n ENVIRONMENT,\n IGNORED_ERROR_REGEX: extractRegex(process.env.IGNORED_ERROR_REGEX),\n LANGUAGE_PREFERENCE_COOKIE_NAME: process.env.LANGUAGE_PREFERENCE_COOKIE_NAME,\n LEARNING_BASE_URL: process.env.LEARNING_BASE_URL,\n LMS_BASE_URL: process.env.LMS_BASE_URL,\n LOGIN_URL: process.env.LOGIN_URL,\n LOGOUT_URL: process.env.LOGOUT_URL,\n STUDIO_BASE_URL: process.env.STUDIO_BASE_URL,\n MARKETING_SITE_BASE_URL: process.env.MARKETING_SITE_BASE_URL,\n ORDER_HISTORY_URL: process.env.ORDER_HISTORY_URL,\n REFRESH_ACCESS_TOKEN_ENDPOINT: process.env.REFRESH_ACCESS_TOKEN_ENDPOINT,\n SECURE_COOKIES: ENVIRONMENT !== 'development',\n SEGMENT_KEY: process.env.SEGMENT_KEY,\n SITE_NAME: process.env.SITE_NAME,\n USER_INFO_COOKIE_NAME: process.env.USER_INFO_COOKIE_NAME,\n LOGO_URL: process.env.LOGO_URL,\n LOGO_TRADEMARK_URL: process.env.LOGO_TRADEMARK_URL,\n LOGO_WHITE_URL: process.env.LOGO_WHITE_URL,\n FAVICON_URL: process.env.FAVICON_URL,\n};\n\n/**\n * Getter for the application configuration document. This is synchronous and merely returns a\n * reference to an existing object, and is thus safe to call as often as desired. The document\n * should have the following keys at a minimum:\n *\n * @returns {ConfigDocument}\n */\nexport function getConfig() {\n return config;\n}\n\n/**\n * Replaces the existing ConfigDocument. This is not commonly used, but can be helpful for tests.\n *\n * The supplied config document will be tested with `ensureDefinedConfig` to ensure it does not\n * have any `undefined` keys.\n *\n * @param {ConfigDocument} newConfig\n */\nexport function setConfig(newConfig) {\n ensureDefinedConfig(config, 'config');\n config = newConfig;\n publish(CONFIG_CHANGED);\n}\n\n/**\n * Merges additional configuration values into the ConfigDocument returned by `getConfig`. Will\n * override any values that exist with the same keys.\n *\n * ```\n * mergeConfig({\n * NEW_KEY: 'new value',\n * OTHER_NEW_KEY: 'other new value',\n * });\n *\n * If any of the key values are `undefined`, an error will be logged to 'warn'.\n *\n * @param {Object} newConfig\n */\nexport function mergeConfig(newConfig) {\n ensureDefinedConfig(newConfig, 'ProcessEnvConfigService');\n config = Object.assign(config, newConfig);\n publish(CONFIG_CHANGED);\n}\n\n/**\n * A method allowing application code to indicate that particular ConfigDocument keys are required\n * for them to function. This is useful for diagnosing development/deployment issues, primarily,\n * by surfacing misconfigurations early. For instance, if the build process fails to supply an\n * environment variable on the command-line, it's possible that one of the `process.env` variables\n * will be undefined. Should be used in conjunction with `mergeConfig` for custom `ConfigDocument`\n * properties. Requester is for informational/error reporting purposes only.\n *\n * ```\n * ensureConfig(['LMS_BASE_URL', 'LOGIN_URL'], 'MySpecialComponent');\n *\n * // Will log a warning with:\n * // \"App configuration error: LOGIN_URL is required by MySpecialComponent.\"\n * // if LOGIN_URL is undefined, for example.\n * ```\n *\n * *NOTE*: `ensureConfig` waits until `APP_CONFIG_INITIALIZED` is published to verify the existence\n * of the specified properties. This means that this function is compatible with custom `config`\n * phase handlers responsible for loading additional configuration data in the initialization\n * sequence.\n *\n * @param {Array} keys\n * @param {string} [requester='unspecified application code']\n */\nexport function ensureConfig(keys, requester = 'unspecified application code') {\n subscribe(APP_CONFIG_INITIALIZED, () => {\n keys.forEach((key) => {\n if (config[key] === undefined) {\n // eslint-disable-next-line no-console\n console.warn(`App configuration error: ${key} is required by ${requester}.`);\n }\n });\n });\n}\n\n/**\n * An object describing the current application configuration.\n *\n * The implementation loads this document via `process.env` variables.\n *\n * ```\n * {\n * BASE_URL: process.env.BASE_URL,\n * // ... other vars\n * }\n * ```\n *\n * When using Webpack (i.e., normal usage), the build process is responsible for supplying these\n * variables via command-line environment variables. That means they must be supplied at build\n * time.\n *\n * @name ConfigDocument\n * @memberof module:Config\n * @property {string} ACCESS_TOKEN_COOKIE_NAME\n * @property {string} BASE_URL The URL of the current application.\n * @property {string} CREDENTIALS_BASE_URL\n * @property {string} CSRF_TOKEN_API_PATH\n * @property {string} DISCOVERY_API_BASE_URL\n * @property {string} PUBLISHER_BASE_URL\n * @property {string} ECOMMERCE_BASE_URL\n * @property {string} ENVIRONMENT This is one of: development, production, or test.\n * @property {string} IGNORED_ERROR_REGEX\n * @property {string} LANGUAGE_PREFERENCE_COOKIE_NAME\n * @property {string} LEARNING_BASE_URL\n * @property {string} LMS_BASE_URL\n * @property {string} LOGIN_URL\n * @property {string} LOGOUT_URL\n * @property {string} STUDIO_BASE_URL\n * @property {string} MARKETING_SITE_BASE_URL\n * @property {string} ORDER_HISTORY_URL\n * @property {string} REFRESH_ACCESS_TOKEN_ENDPOINT\n * @property {boolean} SECURE_COOKIES\n * @property {string} SEGMENT_KEY\n * @property {string} SITE_NAME\n * @property {string} USER_INFO_COOKIE_NAME\n * @property {string} LOGO_URL\n * @property {string} LOGO_TRADEMARK_URL\n * @property {string} LOGO_WHITE_URL\n * @property {string} FAVICON_URL\n */\n"],"file":"config.js"}
|
|
1
|
+
{"version":3,"file":"config.js","names":["APP_CONFIG_INITIALIZED","CONFIG_CHANGED","publish","subscribe","ensureDefinedConfig","extractRegex","envVar","trim","RegExp","undefined","ENVIRONMENT","process","env","NODE_ENV","config","ACCESS_TOKEN_COOKIE_NAME","BASE_URL","PUBLIC_PATH","CREDENTIALS_BASE_URL","CSRF_TOKEN_API_PATH","DISCOVERY_API_BASE_URL","PUBLISHER_BASE_URL","ECOMMERCE_BASE_URL","IGNORED_ERROR_REGEX","LANGUAGE_PREFERENCE_COOKIE_NAME","LEARNING_BASE_URL","LMS_BASE_URL","LOGIN_URL","LOGOUT_URL","STUDIO_BASE_URL","MARKETING_SITE_BASE_URL","ORDER_HISTORY_URL","REFRESH_ACCESS_TOKEN_ENDPOINT","SECURE_COOKIES","SEGMENT_KEY","SITE_NAME","USER_INFO_COOKIE_NAME","LOGO_URL","LOGO_TRADEMARK_URL","LOGO_WHITE_URL","FAVICON_URL","getConfig","setConfig","newConfig","mergeConfig","Object","assign","ensureConfig","keys","requester","forEach","key","console","warn"],"sources":["../src/config.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform**\n *\n * The configuration module provides utilities for working with an application's configuration\n * document (ConfigDocument). This module uses `process.env` to import configuration variables\n * from the command-line build process. It can be dynamically extended at run-time using a\n * `config` initialization handler. Please see the Initialization documentation for more\n * information on handlers and initialization phases.\n *\n * ```\n * import { getConfig } from '@edx/frontend-platform';\n *\n * const {\n * BASE_URL,\n * LMS_BASE_URL,\n * LOGIN_URL,\n * LOGIN_URL,\n * REFRESH_ACCESS_TOKEN_ENDPOINT,\n * ACCESS_TOKEN_COOKIE_NAME,\n * CSRF_TOKEN_API_PATH,\n * } = getConfig();\n * ```\n *\n * @module Config\n */\n\nimport { APP_CONFIG_INITIALIZED, CONFIG_CHANGED } from './constants';\n\nimport { publish, subscribe } from './pubSub';\nimport { ensureDefinedConfig } from './utils';\n\nfunction extractRegex(envVar) {\n // Convert the environment variable string to a regex, while guarding\n // against a non-string and an empty/whitespace-only string.\n if (typeof envVar === 'string' && envVar.trim() !== '') {\n return new RegExp(envVar);\n }\n return undefined;\n}\n\nconst ENVIRONMENT = process.env.NODE_ENV;\nlet config = {\n ACCESS_TOKEN_COOKIE_NAME: process.env.ACCESS_TOKEN_COOKIE_NAME,\n BASE_URL: process.env.BASE_URL,\n PUBLIC_PATH: process.env.PUBLIC_PATH || '/',\n CREDENTIALS_BASE_URL: process.env.CREDENTIALS_BASE_URL,\n CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH,\n DISCOVERY_API_BASE_URL: process.env.DISCOVERY_API_BASE_URL,\n PUBLISHER_BASE_URL: process.env.PUBLISHER_BASE_URL,\n ECOMMERCE_BASE_URL: process.env.ECOMMERCE_BASE_URL,\n ENVIRONMENT,\n IGNORED_ERROR_REGEX: extractRegex(process.env.IGNORED_ERROR_REGEX),\n LANGUAGE_PREFERENCE_COOKIE_NAME: process.env.LANGUAGE_PREFERENCE_COOKIE_NAME,\n LEARNING_BASE_URL: process.env.LEARNING_BASE_URL,\n LMS_BASE_URL: process.env.LMS_BASE_URL,\n LOGIN_URL: process.env.LOGIN_URL,\n LOGOUT_URL: process.env.LOGOUT_URL,\n STUDIO_BASE_URL: process.env.STUDIO_BASE_URL,\n MARKETING_SITE_BASE_URL: process.env.MARKETING_SITE_BASE_URL,\n ORDER_HISTORY_URL: process.env.ORDER_HISTORY_URL,\n REFRESH_ACCESS_TOKEN_ENDPOINT: process.env.REFRESH_ACCESS_TOKEN_ENDPOINT,\n SECURE_COOKIES: ENVIRONMENT !== 'development',\n SEGMENT_KEY: process.env.SEGMENT_KEY,\n SITE_NAME: process.env.SITE_NAME,\n USER_INFO_COOKIE_NAME: process.env.USER_INFO_COOKIE_NAME,\n LOGO_URL: process.env.LOGO_URL,\n LOGO_TRADEMARK_URL: process.env.LOGO_TRADEMARK_URL,\n LOGO_WHITE_URL: process.env.LOGO_WHITE_URL,\n FAVICON_URL: process.env.FAVICON_URL,\n};\n\n/**\n * Getter for the application configuration document. This is synchronous and merely returns a\n * reference to an existing object, and is thus safe to call as often as desired. The document\n * should have the following keys at a minimum:\n *\n * @returns {ConfigDocument}\n */\nexport function getConfig() {\n return config;\n}\n\n/**\n * Replaces the existing ConfigDocument. This is not commonly used, but can be helpful for tests.\n *\n * The supplied config document will be tested with `ensureDefinedConfig` to ensure it does not\n * have any `undefined` keys.\n *\n * @param {ConfigDocument} newConfig\n */\nexport function setConfig(newConfig) {\n ensureDefinedConfig(config, 'config');\n config = newConfig;\n publish(CONFIG_CHANGED);\n}\n\n/**\n * Merges additional configuration values into the ConfigDocument returned by `getConfig`. Will\n * override any values that exist with the same keys.\n *\n * ```\n * mergeConfig({\n * NEW_KEY: 'new value',\n * OTHER_NEW_KEY: 'other new value',\n * });\n *\n * If any of the key values are `undefined`, an error will be logged to 'warn'.\n *\n * @param {Object} newConfig\n */\nexport function mergeConfig(newConfig) {\n ensureDefinedConfig(newConfig, 'ProcessEnvConfigService');\n config = Object.assign(config, newConfig);\n publish(CONFIG_CHANGED);\n}\n\n/**\n * A method allowing application code to indicate that particular ConfigDocument keys are required\n * for them to function. This is useful for diagnosing development/deployment issues, primarily,\n * by surfacing misconfigurations early. For instance, if the build process fails to supply an\n * environment variable on the command-line, it's possible that one of the `process.env` variables\n * will be undefined. Should be used in conjunction with `mergeConfig` for custom `ConfigDocument`\n * properties. Requester is for informational/error reporting purposes only.\n *\n * ```\n * ensureConfig(['LMS_BASE_URL', 'LOGIN_URL'], 'MySpecialComponent');\n *\n * // Will log a warning with:\n * // \"App configuration error: LOGIN_URL is required by MySpecialComponent.\"\n * // if LOGIN_URL is undefined, for example.\n * ```\n *\n * *NOTE*: `ensureConfig` waits until `APP_CONFIG_INITIALIZED` is published to verify the existence\n * of the specified properties. This means that this function is compatible with custom `config`\n * phase handlers responsible for loading additional configuration data in the initialization\n * sequence.\n *\n * @param {Array} keys\n * @param {string} [requester='unspecified application code']\n */\nexport function ensureConfig(keys, requester = 'unspecified application code') {\n subscribe(APP_CONFIG_INITIALIZED, () => {\n keys.forEach((key) => {\n if (config[key] === undefined) {\n // eslint-disable-next-line no-console\n console.warn(`App configuration error: ${key} is required by ${requester}.`);\n }\n });\n });\n}\n\n/**\n * An object describing the current application configuration.\n *\n * The implementation loads this document via `process.env` variables.\n *\n * ```\n * {\n * BASE_URL: process.env.BASE_URL,\n * // ... other vars\n * }\n * ```\n *\n * When using Webpack (i.e., normal usage), the build process is responsible for supplying these\n * variables via command-line environment variables. That means they must be supplied at build\n * time.\n *\n * @name ConfigDocument\n * @memberof module:Config\n * @property {string} ACCESS_TOKEN_COOKIE_NAME\n * @property {string} BASE_URL The URL of the current application.\n * @property {string} CREDENTIALS_BASE_URL\n * @property {string} CSRF_TOKEN_API_PATH\n * @property {string} DISCOVERY_API_BASE_URL\n * @property {string} PUBLISHER_BASE_URL\n * @property {string} ECOMMERCE_BASE_URL\n * @property {string} ENVIRONMENT This is one of: development, production, or test.\n * @property {string} IGNORED_ERROR_REGEX\n * @property {string} LANGUAGE_PREFERENCE_COOKIE_NAME\n * @property {string} LEARNING_BASE_URL\n * @property {string} LMS_BASE_URL\n * @property {string} LOGIN_URL\n * @property {string} LOGOUT_URL\n * @property {string} STUDIO_BASE_URL\n * @property {string} MARKETING_SITE_BASE_URL\n * @property {string} ORDER_HISTORY_URL\n * @property {string} REFRESH_ACCESS_TOKEN_ENDPOINT\n * @property {boolean} SECURE_COOKIES\n * @property {string} SEGMENT_KEY\n * @property {string} SITE_NAME\n * @property {string} USER_INFO_COOKIE_NAME\n * @property {string} LOGO_URL\n * @property {string} LOGO_TRADEMARK_URL\n * @property {string} LOGO_WHITE_URL\n * @property {string} FAVICON_URL\n */\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,sBAAT,EAAiCC,cAAjC,QAAuD,aAAvD;AAEA,SAASC,OAAT,EAAkBC,SAAlB,QAAmC,UAAnC;AACA,SAASC,mBAAT,QAAoC,SAApC;;AAEA,SAASC,YAAT,CAAsBC,MAAtB,EAA8B;EAC5B;EACA;EACA,IAAI,OAAOA,MAAP,KAAkB,QAAlB,IAA8BA,MAAM,CAACC,IAAP,OAAkB,EAApD,EAAwD;IACtD,OAAO,IAAIC,MAAJ,CAAWF,MAAX,CAAP;EACD;;EACD,OAAOG,SAAP;AACD;;AAED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EAAS;MACpB,IAAIrC,MAAM,CAACqC,GAAD,CAAN,KAAgB1C,SAApB,EAA+B;QAC7B;QACA2C,OAAO,CAACC,IAAR,oCAAyCF,GAAzC,6BAA+DF,SAA/D;MACD;IACF,CALD;EAMD,CAPQ,CAAT;AAQD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
package/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"constants.js","names":["APP_TOPIC","APP_PUBSUB_INITIALIZED","APP_CONFIG_INITIALIZED","APP_AUTH_INITIALIZED","APP_I18N_INITIALIZED","APP_LOGGING_INITIALIZED","APP_ANALYTICS_INITIALIZED","APP_READY","APP_INIT_ERROR","CONFIG_TOPIC","CONFIG_CHANGED"],"sources":["../src/constants.js"],"sourcesContent":["/** @constant */\nexport const APP_TOPIC = 'APP';\n\nexport const APP_PUBSUB_INITIALIZED = `${APP_TOPIC}.PUBSUB_INITIALIZED`;\n\n/**\n * Event published when the application initialization sequence has finished loading any dynamic\n * configuration setup in a custom config handler.\n *\n * @event\n */\nexport const APP_CONFIG_INITIALIZED = `${APP_TOPIC}.CONFIG_INITIALIZED`;\n\n/**\n * Event published when the application initialization sequence has finished determining the user's\n * authentication state, creating an authenticated API client, and executing auth handlers.\n *\n * @event\n */\nexport const APP_AUTH_INITIALIZED = `${APP_TOPIC}.AUTH_INITIALIZED`;\n\n/**\n * Event published when the application initialization sequence has finished initializing\n * internationalization and executing any i18n handlers.\n *\n * @event\n */\nexport const APP_I18N_INITIALIZED = `${APP_TOPIC}.I18N_INITIALIZED`;\n\n/**\n * Event published when the application initialization sequence has finished initializing the\n * logging service and executing any logging handlers.\n *\n * @event\n */\nexport const APP_LOGGING_INITIALIZED = `${APP_TOPIC}.LOGGING_INITIALIZED`;\n\n/**\n * Event published when the application initialization sequence has finished initializing the\n * analytics service and executing any analytics handlers.\n *\n * @event\n */\nexport const APP_ANALYTICS_INITIALIZED = `${APP_TOPIC}.ANALYTICS_INITIALIZED`;\n\n/**\n * Event published when the application initialization sequence has finished. Applications should\n * subscribe to this event and start rendering the UI when it has fired.\n *\n * @event\n */\nexport const APP_READY = `${APP_TOPIC}.READY`;\n\n/**\n * Event published when the application initialization sequence has aborted. This is frequently\n * used to show an error page when an initialization error has occurred.\n *\n * @see {@link module:React~ErrorPage}\n * @event\n */\nexport const APP_INIT_ERROR = `${APP_TOPIC}.INIT_ERROR`;\n\n/** @constant */\nexport const CONFIG_TOPIC = 'CONFIG';\n\nexport const CONFIG_CHANGED = `${CONFIG_TOPIC}.CHANGED`;\n"],"mappings":"AAAA;AACA,OAAO,IAAMA,SAAS,GAAG,KAAlB;AAEP,OAAO,IAAMC,sBAAsB,aAAMD,SAAN,wBAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAME,sBAAsB,aAAMF,SAAN,wBAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMG,oBAAoB,aAAMH,SAAN,sBAA1B;AAEP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMI,oBAAoB,aAAMJ,SAAN,sBAA1B;AAEP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMK,uBAAuB,aAAML,SAAN,yBAA7B;AAEP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMM,yBAAyB,aAAMN,SAAN,2BAA/B;AAEP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMO,SAAS,aAAMP,SAAN,WAAf;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMQ,cAAc,aAAMR,SAAN,gBAApB;AAEP;;AACA,OAAO,IAAMS,YAAY,GAAG,QAArB;AAEP,OAAO,IAAMC,cAAc,aAAMD,YAAN,aAApB"}
|
package/i18n/countries.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"countries.js","names":["COUNTRIES","langs","countryLangs","getPrimaryLanguageSubtag","registerLocale","require","getCountryMessages","locale","primaryLanguageSubtag","languageCode","includes","getNames","getCountryList","countryMessages","Object","entries","map","code","name"],"sources":["../../src/i18n/countries.js"],"sourcesContent":["import COUNTRIES, { langs as countryLangs } from 'i18n-iso-countries';\n\nimport { getPrimaryLanguageSubtag } from './lib';\n\n/*\n * COUNTRY LISTS\n *\n * Lists of country names localized in supported languages.\n *\n * TODO: When we start dynamically loading translations only for the current locale, change this.\n */\n\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/ar.json'));\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/en.json'));\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/es.json'));\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/fr.json'));\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/zh.json'));\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/ca.json'));\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/he.json'));\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/id.json'));\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/ko.json'));\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/pl.json'));\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/pt.json'));\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/ru.json'));\n// COUNTRIES.registerLocale(require('i18n-iso-countries/langs/th.json')); // Doesn't exist in lib.\nCOUNTRIES.registerLocale(require('i18n-iso-countries/langs/uk.json'));\n\n/**\n * Provides a lookup table of country IDs to country names for the current locale.\n *\n * @memberof module:I18n\n */\nexport function getCountryMessages(locale) {\n const primaryLanguageSubtag = getPrimaryLanguageSubtag(locale);\n const languageCode = countryLangs().includes(primaryLanguageSubtag) ? primaryLanguageSubtag : 'en';\n\n return COUNTRIES.getNames(languageCode);\n}\n\n/**\n * Provides a list of countries represented as objects of the following shape:\n *\n * {\n * key, // The ID of the country\n * name // The localized name of the country\n * }\n *\n * TODO: ARCH-878: The list should be sorted alphabetically in the current locale.\n * This is useful for populating dropdowns.\n *\n * @memberof module:I18n\n */\nexport function getCountryList(locale) {\n const countryMessages = getCountryMessages(locale);\n return Object.entries(countryMessages).map(([code, name]) => ({ code, name }));\n}\n"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,SAAP,IAAoBC,KAAK,IAAIC,YAA7B,QAAiD,oBAAjD;AAEA,SAASC,wBAAT,QAAyC,OAAzC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEAH,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC,E,CACA;;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,kCAAD,CAAhC;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,kBAAT,CAA4BC,MAA5B,EAAoC;EACzC,IAAMC,qBAAqB,GAAGL,wBAAwB,CAACI,MAAD,CAAtD;EACA,IAAME,YAAY,GAAGP,YAAY,GAAGQ,QAAf,CAAwBF,qBAAxB,IAAiDA,qBAAjD,GAAyE,IAA9F;EAEA,OAAOR,SAAS,CAACW,QAAV,CAAmBF,YAAnB,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,cAAT,CAAwBL,MAAxB,EAAgC;EACrC,IAAMM,eAAe,GAAGP,kBAAkB,CAACC,MAAD,CAA1C;EACA,OAAOO,MAAM,CAACC,OAAP,CAAeF,eAAf,EAAgCG,GAAhC,CAAoC;IAAA;IAAA,IAAEC,IAAF;IAAA,IAAQC,IAAR;;IAAA,OAAmB;MAAED,IAAI,EAAJA,IAAF;MAAQC,IAAI,EAAJA;IAAR,CAAnB;EAAA,CAApC,CAAP;AACD"}
|
package/i18n/index.js
CHANGED
|
@@ -19,65 +19,59 @@
|
|
|
19
19
|
*
|
|
20
20
|
* @module Internationalization
|
|
21
21
|
* @see {@link https://github.com/edx/frontend-platform/blob/master/docs/how_tos/i18n.rst}
|
|
22
|
-
* @see {@link https://
|
|
22
|
+
* @see {@link https://formatjs.io/docs/react-intl/components/ Intl} for components exported from this module.
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* @name FormattedDate
|
|
28
28
|
* @kind class
|
|
29
|
-
* @see {@link https://
|
|
29
|
+
* @see {@link https://formatjs.io/docs/react-intl/components/#formatteddate Intl}
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* @name FormattedTime
|
|
34
34
|
* @kind class
|
|
35
|
-
* @see {@link https://
|
|
35
|
+
* @see {@link https://formatjs.io/docs/react-intl/components/#formattedtime Intl}
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* @name
|
|
39
|
+
* @name FormattedRelativeTime
|
|
40
40
|
* @kind class
|
|
41
|
-
* @see {@link https://
|
|
41
|
+
* @see {@link https://formatjs.io/docs/react-intl/components/#formattedrelativetime Intl}
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* @name FormattedNumber
|
|
46
46
|
* @kind class
|
|
47
|
-
* @see {@link https://
|
|
47
|
+
* @see {@link https://formatjs.io/docs/react-intl/components/#formattednumber Intl}
|
|
48
48
|
*/
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* @name FormattedPlural
|
|
52
52
|
* @kind class
|
|
53
|
-
* @see {@link https://
|
|
53
|
+
* @see {@link https://formatjs.io/docs/react-intl/components/#formattedplural Intl}
|
|
54
54
|
*/
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* @name FormattedMessage
|
|
58
58
|
* @kind class
|
|
59
|
-
* @see {@link https://
|
|
59
|
+
* @see {@link https://formatjs.io/docs/react-intl/components/#formattedmessage Intl}
|
|
60
60
|
*/
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* @name IntlProvider
|
|
64
64
|
* @kind class
|
|
65
|
-
* @see {@link https://
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @name intlShape
|
|
70
|
-
* @kind constant
|
|
71
|
-
* @see {@link https://github.com/formatjs/react-intl/blob/master/docs/API.md#intlshape|React Intl}
|
|
65
|
+
* @see {@link https://formatjs.io/docs/react-intl/components/#intlprovider Intl}
|
|
72
66
|
*/
|
|
73
67
|
|
|
74
68
|
/**
|
|
75
69
|
* @name defineMessages
|
|
76
70
|
* @kind function
|
|
77
|
-
* @see {@link https://
|
|
71
|
+
* @see {@link https://formatjs.io/docs/react-intl/api#definemessagesdefinemessage Intl}
|
|
78
72
|
*/
|
|
79
|
-
export {
|
|
80
|
-
export { configure, getPrimaryLanguageSubtag, getLocale, getMessages, isRtl, handleRtl, LOCALE_CHANGED, LOCALE_TOPIC } from './lib';
|
|
73
|
+
export { FormattedDate, FormattedTime, FormattedRelativeTime, FormattedNumber, FormattedPlural, FormattedMessage, defineMessages, IntlProvider } from 'react-intl';
|
|
74
|
+
export { intlShape, configure, getPrimaryLanguageSubtag, getLocale, getMessages, isRtl, handleRtl, LOCALE_CHANGED, LOCALE_TOPIC } from './lib';
|
|
81
75
|
export { default as injectIntl } from './injectIntlWithShim';
|
|
82
76
|
export { getCountryList, getCountryMessages } from './countries';
|
|
83
77
|
export { getLanguageList, getLanguageMessages } from './languages';
|
package/i18n/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["FormattedDate","FormattedTime","FormattedRelativeTime","FormattedNumber","FormattedPlural","FormattedMessage","defineMessages","IntlProvider","intlShape","configure","getPrimaryLanguageSubtag","getLocale","getMessages","isRtl","handleRtl","LOCALE_CHANGED","LOCALE_TOPIC","default","injectIntl","getCountryList","getCountryMessages","getLanguageList","getLanguageMessages"],"sources":["../../src/i18n/index.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform/i18n**\n * The i18n module relies on react-intl and re-exports all of that package's exports.\n *\n * For each locale we want to support, react-intl needs 1) the locale-data, which includes\n * information about how to format numbers, handle plurals, etc., and 2) the translations, as an\n * object holding message id / translated string pairs. A locale string and the messages object are\n * passed into the IntlProvider element that wraps your element hierarchy.\n *\n * Note that react-intl has no way of checking if the translations you give it actually have\n * anything to do with the locale you pass it; it will happily use whatever messages object you pass\n * in. However, if the locale data for the locale you passed into the IntlProvider was not\n * correctly installed with addLocaleData, all of your translations will fall back to the default\n * (in our case English), *even if you gave IntlProvider the correct messages object for that\n * locale*.\n *\n * Messages are provided to this module via the configure() function below.\n *\n *\n * @module Internationalization\n * @see {@link https://github.com/edx/frontend-platform/blob/master/docs/how_tos/i18n.rst}\n * @see {@link https://formatjs.io/docs/react-intl/components/ Intl} for components exported from this module.\n *\n */\n\n/**\n * @name FormattedDate\n * @kind class\n * @see {@link https://formatjs.io/docs/react-intl/components/#formatteddate Intl}\n */\n\n/**\n * @name FormattedTime\n * @kind class\n * @see {@link https://formatjs.io/docs/react-intl/components/#formattedtime Intl}\n */\n\n/**\n * @name FormattedRelativeTime\n * @kind class\n * @see {@link https://formatjs.io/docs/react-intl/components/#formattedrelativetime Intl}\n */\n\n/**\n * @name FormattedNumber\n * @kind class\n * @see {@link https://formatjs.io/docs/react-intl/components/#formattednumber Intl}\n */\n\n/**\n * @name FormattedPlural\n * @kind class\n * @see {@link https://formatjs.io/docs/react-intl/components/#formattedplural Intl}\n */\n\n/**\n * @name FormattedMessage\n * @kind class\n * @see {@link https://formatjs.io/docs/react-intl/components/#formattedmessage Intl}\n */\n\n/**\n * @name IntlProvider\n * @kind class\n * @see {@link https://formatjs.io/docs/react-intl/components/#intlprovider Intl}\n */\n\n/**\n * @name defineMessages\n * @kind function\n * @see {@link https://formatjs.io/docs/react-intl/api#definemessagesdefinemessage Intl}\n */\n\nexport {\n FormattedDate,\n FormattedTime,\n FormattedRelativeTime,\n FormattedNumber,\n FormattedPlural,\n FormattedMessage,\n defineMessages,\n IntlProvider,\n} from 'react-intl';\n\nexport {\n intlShape,\n configure,\n getPrimaryLanguageSubtag,\n getLocale,\n getMessages,\n isRtl,\n handleRtl,\n LOCALE_CHANGED,\n LOCALE_TOPIC,\n} from './lib';\n\nexport {\n default as injectIntl,\n} from './injectIntlWithShim';\n\nexport {\n getCountryList,\n getCountryMessages,\n} from './countries';\n\nexport {\n getLanguageList,\n getLanguageMessages,\n} from './languages';\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;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAEA,SACEA,aADF,EAEEC,aAFF,EAGEC,qBAHF,EAIEC,eAJF,EAKEC,eALF,EAMEC,gBANF,EAOEC,cAPF,EAQEC,YARF,QASO,YATP;AAWA,SACEC,SADF,EAEEC,SAFF,EAGEC,wBAHF,EAIEC,SAJF,EAKEC,WALF,EAMEC,KANF,EAOEC,SAPF,EAQEC,cARF,EASEC,YATF,QAUO,OAVP;AAYA,SACEC,OAAO,IAAIC,UADb,QAEO,sBAFP;AAIA,SACEC,cADF,EAEEC,kBAFF,QAGO,aAHP;AAKA,SACEC,eADF,EAEEC,mBAFF,QAGO,aAHP"}
|
|
@@ -23,8 +23,8 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
23
23
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
24
|
|
|
25
25
|
import React from 'react';
|
|
26
|
-
import { injectIntl
|
|
27
|
-
import { getLoggingService } from './lib';
|
|
26
|
+
import { injectIntl } from 'react-intl';
|
|
27
|
+
import { getLoggingService, intlShape } from './lib';
|
|
28
28
|
/**
|
|
29
29
|
* This function wraps react-intl's injectIntl function in order to add error logging to the intl
|
|
30
30
|
* property's formatMessage function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"injectIntlWithShim.js","names":["React","injectIntl","getLoggingService","intlShape","injectIntlWithShim","WrappedComponent","ShimmedIntlComponent","props","shimmedIntl","Object","create","intl","formatMessage","value","definition","undefined","id","error","Error","process","env","NODE_ENV","console","logError","args","Component","propTypes","isRequired"],"sources":["../../src/i18n/injectIntlWithShim.jsx"],"sourcesContent":["import React from 'react';\nimport { injectIntl } from 'react-intl';\nimport { getLoggingService, intlShape } from './lib';\n\n/**\n * This function wraps react-intl's injectIntl function in order to add error logging to the intl\n * property's formatMessage function.\n *\n * @memberof I18n\n */\nconst injectIntlWithShim = (WrappedComponent) => {\n class ShimmedIntlComponent extends React.Component {\n constructor(props) {\n super(props);\n this.shimmedIntl = Object.create(this.props.intl, {\n formatMessage: {\n value: (definition, ...args) => {\n if (definition === undefined || definition.id === undefined) {\n const error = new Error('i18n error: An undefined message was supplied to intl.formatMessage.');\n if (process.env.NODE_ENV !== 'production') {\n console.error(error); // eslint-disable-line no-console\n return '!!! Missing message supplied to intl.formatMessage !!!';\n }\n getLoggingService().logError(error);\n return ''; // Fail silently in production\n }\n return this.props.intl.formatMessage(definition, ...args);\n },\n },\n });\n }\n\n render() {\n return <WrappedComponent {...this.props} intl={this.shimmedIntl} />;\n }\n }\n\n ShimmedIntlComponent.propTypes = {\n intl: intlShape.isRequired,\n };\n\n return injectIntl(ShimmedIntlComponent);\n};\n\nexport default injectIntlWithShim;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,UAAT,QAA2B,YAA3B;AACA,SAASC,iBAAT,EAA4BC,SAA5B,QAA6C,OAA7C;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,kBAAkB,GAAG,SAArBA,kBAAqB,CAACC,gBAAD,EAAsB;EAAA,IACzCC,oBADyC;IAAA;;IAAA;;IAE7C,8BAAYC,KAAZ,EAAmB;MAAA;;MAAA;;MACjB,0BAAMA,KAAN;MACA,MAAKC,WAAL,GAAmBC,MAAM,CAACC,MAAP,CAAc,MAAKH,KAAL,CAAWI,IAAzB,EAA+B;QAChDC,aAAa,EAAE;UACbC,KAAK,EAAE,eAACC,UAAD,EAAyB;YAAA;;YAC9B,IAAIA,UAAU,KAAKC,SAAf,IAA4BD,UAAU,CAACE,EAAX,KAAkBD,SAAlD,EAA6D;cAC3D,IAAME,KAAK,GAAG,IAAIC,KAAJ,CAAU,sEAAV,CAAd;;cACA,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;gBACzCC,OAAO,CAACL,KAAR,CAAcA,KAAd,EADyC,CACnB;;gBACtB,OAAO,wDAAP;cACD;;cACDf,iBAAiB,GAAGqB,QAApB,CAA6BN,KAA7B;cACA,OAAO,EAAP,CAP2D,CAOhD;YACZ;;YAT6B,kCAATO,IAAS;cAATA,IAAS;YAAA;;YAU9B,OAAO,0BAAKjB,KAAL,CAAWI,IAAX,EAAgBC,aAAhB,0BAA8BE,UAA9B,SAA6CU,IAA7C,EAAP;UACD;QAZY;MADiC,CAA/B,CAAnB;MAFiB;IAkBlB;;IApB4C;MAAA;MAAA,OAsB7C,kBAAS;QACP,oBAAO,oBAAC,gBAAD,eAAsB,KAAKjB,KAA3B;UAAkC,IAAI,EAAE,KAAKC;QAA7C,GAAP;MACD;IAxB4C;;IAAA;EAAA,EACZR,KAAK,CAACyB,SADM;;EA2B/CnB,oBAAoB,CAACoB,SAArB,GAAiC;IAC/Bf,IAAI,EAAER,SAAS,CAACwB;EADe,CAAjC;EAIA,OAAO1B,UAAU,CAACK,oBAAD,CAAjB;AACD,CAhCD;;AAkCA,eAAeF,kBAAf"}
|
package/i18n/languages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"languages.js","names":["LANGUAGES","langs","languageLangs","getPrimaryLanguageSubtag","registerLocale","require","getLanguageMessages","locale","primaryLanguageSubtag","languageCode","includes","getNames","getLanguageList","languageMessages","Object","entries","map","code","name"],"sources":["../../src/i18n/languages.js"],"sourcesContent":["import LANGUAGES, { langs as languageLangs } from '@cospired/i18n-iso-languages';\n\nimport { getPrimaryLanguageSubtag } from './lib';\n\n/*\n * LANGUAGE LISTS\n *\n * Lists of language names localized in supported languages.\n *\n * TODO: When we start dynamically loading translations only for the current locale, change this.\n * TODO: Also note that a bunch of languages are missing here. They're present but commented out\n * for reference. That's because they're not implemented in this library. If you read this and it's\n * been a while, go check and see if that's changed!\n */\n\n// LANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/ar.json'));\nLANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/en.json'));\nLANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/es.json'));\nLANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/fr.json'));\n// LANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/zh.json'));\n// LANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/ca.json'));\n// LANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/he.json'));\n// LANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/id.json'));\n// LANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/ko.json'));\nLANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/pl.json'));\nLANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/pt.json'));\n// LANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/ru.json'));\n// LANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/th.json'));\n// LANGUAGES.registerLocale(require('@cospired/i18n-iso-languages/langs/uk.json'));\n\n/**\n * Provides a lookup table of language IDs to language names for the current locale.\n *\n * @memberof I18n\n */\nexport const getLanguageMessages = (locale) => {\n const primaryLanguageSubtag = getPrimaryLanguageSubtag(locale);\n const languageCode = languageLangs().includes(primaryLanguageSubtag) ? primaryLanguageSubtag : 'en';\n\n return LANGUAGES.getNames(languageCode);\n};\n\n/**\n * Provides a list of languages represented as objects of the following shape:\n *\n * {\n * key, // The ID of the language\n * name // The localized name of the language\n * }\n *\n * TODO: ARCH-878: The list should be sorted alphabetically in the current locale.\n * This is useful for populating dropdowns.\n *\n * @memberof I18n\n */\nexport const getLanguageList = (locale) => {\n const languageMessages = getLanguageMessages(locale);\n return Object.entries(languageMessages).map(([code, name]) => ({ code, name }));\n};\n"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,SAAP,IAAoBC,KAAK,IAAIC,aAA7B,QAAkD,8BAAlD;AAEA,SAASC,wBAAT,QAAyC,OAAzC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;;AACAH,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,4CAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,4CAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,4CAAD,CAAhC,E,CACA;AACA;AACA;AACA;AACA;;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,4CAAD,CAAhC;AACAL,SAAS,CAACI,cAAV,CAAyBC,OAAO,CAAC,4CAAD,CAAhC,E,CACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACC,MAAD,EAAY;EAC7C,IAAMC,qBAAqB,GAAGL,wBAAwB,CAACI,MAAD,CAAtD;EACA,IAAME,YAAY,GAAGP,aAAa,GAAGQ,QAAhB,CAAyBF,qBAAzB,IAAkDA,qBAAlD,GAA0E,IAA/F;EAEA,OAAOR,SAAS,CAACW,QAAV,CAAmBF,YAAnB,CAAP;AACD,CALM;AAOP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMG,eAAe,GAAG,SAAlBA,eAAkB,CAACL,MAAD,EAAY;EACzC,IAAMM,gBAAgB,GAAGP,mBAAmB,CAACC,MAAD,CAA5C;EACA,OAAOO,MAAM,CAACC,OAAP,CAAeF,gBAAf,EAAiCG,GAAjC,CAAqC;IAAA;IAAA,IAAEC,IAAF;IAAA,IAAQC,IAAR;;IAAA,OAAmB;MAAED,IAAI,EAAJA,IAAF;MAAQC,IAAI,EAAJA;IAAR,CAAnB;EAAA,CAArC,CAAP;AACD,CAHM"}
|
package/i18n/lib.js
CHANGED
|
@@ -11,23 +11,38 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
11
11
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
12
12
|
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
|
-
import { addLocaleData } from 'react-intl';
|
|
15
|
-
import arLocale from 'react-intl/locale-data/ar';
|
|
16
|
-
import enLocale from 'react-intl/locale-data/en';
|
|
17
|
-
import esLocale from 'react-intl/locale-data/es';
|
|
18
|
-
import frLocale from 'react-intl/locale-data/fr';
|
|
19
|
-
import zhLocale from 'react-intl/locale-data/zh';
|
|
20
|
-
import caLocale from 'react-intl/locale-data/ca';
|
|
21
|
-
import heLocale from 'react-intl/locale-data/he';
|
|
22
|
-
import idLocale from 'react-intl/locale-data/id';
|
|
23
|
-
import koLocale from 'react-intl/locale-data/ko';
|
|
24
|
-
import plLocale from 'react-intl/locale-data/pl';
|
|
25
|
-
import ptLocale from 'react-intl/locale-data/pt';
|
|
26
|
-
import ruLocale from 'react-intl/locale-data/ru';
|
|
27
|
-
import thLocale from 'react-intl/locale-data/th';
|
|
28
|
-
import ukLocale from 'react-intl/locale-data/uk';
|
|
29
14
|
import Cookies from 'universal-cookie';
|
|
30
15
|
import merge from 'lodash.merge';
|
|
16
|
+
import '@formatjs/intl-pluralrules/polyfill';
|
|
17
|
+
import '@formatjs/intl-pluralrules/locale-data/ar';
|
|
18
|
+
import '@formatjs/intl-pluralrules/locale-data/en';
|
|
19
|
+
import '@formatjs/intl-pluralrules/locale-data/es';
|
|
20
|
+
import '@formatjs/intl-pluralrules/locale-data/fr';
|
|
21
|
+
import '@formatjs/intl-pluralrules/locale-data/zh';
|
|
22
|
+
import '@formatjs/intl-pluralrules/locale-data/ca';
|
|
23
|
+
import '@formatjs/intl-pluralrules/locale-data/he';
|
|
24
|
+
import '@formatjs/intl-pluralrules/locale-data/id';
|
|
25
|
+
import '@formatjs/intl-pluralrules/locale-data/ko';
|
|
26
|
+
import '@formatjs/intl-pluralrules/locale-data/pl';
|
|
27
|
+
import '@formatjs/intl-pluralrules/locale-data/pt';
|
|
28
|
+
import '@formatjs/intl-pluralrules/locale-data/ru';
|
|
29
|
+
import '@formatjs/intl-pluralrules/locale-data/th';
|
|
30
|
+
import '@formatjs/intl-pluralrules/locale-data/uk';
|
|
31
|
+
import '@formatjs/intl-relativetimeformat/polyfill';
|
|
32
|
+
import '@formatjs/intl-relativetimeformat/locale-data/ar';
|
|
33
|
+
import '@formatjs/intl-relativetimeformat/locale-data/en';
|
|
34
|
+
import '@formatjs/intl-relativetimeformat/locale-data/es';
|
|
35
|
+
import '@formatjs/intl-relativetimeformat/locale-data/fr';
|
|
36
|
+
import '@formatjs/intl-relativetimeformat/locale-data/zh';
|
|
37
|
+
import '@formatjs/intl-relativetimeformat/locale-data/ca';
|
|
38
|
+
import '@formatjs/intl-relativetimeformat/locale-data/he';
|
|
39
|
+
import '@formatjs/intl-relativetimeformat/locale-data/id';
|
|
40
|
+
import '@formatjs/intl-relativetimeformat/locale-data/ko';
|
|
41
|
+
import '@formatjs/intl-relativetimeformat/locale-data/pl';
|
|
42
|
+
import '@formatjs/intl-relativetimeformat/locale-data/pt';
|
|
43
|
+
import '@formatjs/intl-relativetimeformat/locale-data/ru';
|
|
44
|
+
import '@formatjs/intl-relativetimeformat/locale-data/th';
|
|
45
|
+
import '@formatjs/intl-relativetimeformat/locale-data/uk';
|
|
31
46
|
var cookies = new Cookies();
|
|
32
47
|
var supportedLocales = ['ar', // Arabic
|
|
33
48
|
// NOTE: 'en' is not included in this list intentionally, since it's the fallback.
|
|
@@ -52,11 +67,22 @@ var rtlLocales = ['ar', // Arabic
|
|
|
52
67
|
var config = null;
|
|
53
68
|
var loggingService = null;
|
|
54
69
|
var messages = null;
|
|
70
|
+
/**
|
|
71
|
+
* @memberof module:Internationalization
|
|
72
|
+
*
|
|
73
|
+
* Prior versions of react-intl (our primary implementation of the i18n service) included a
|
|
74
|
+
* PropTypes-based 'shape' for its `intl` object. This has since been removed. For legacy
|
|
75
|
+
* compatibility, we include an `intlShape` export that is set to PropTypes.object. Usage of this
|
|
76
|
+
* export is deprecated.
|
|
77
|
+
*
|
|
78
|
+
* @deprecated
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
export var intlShape = PropTypes.object;
|
|
55
82
|
/**
|
|
56
83
|
*
|
|
57
84
|
* @ignore
|
|
58
85
|
* @returns {LoggingService}
|
|
59
|
-
*
|
|
60
86
|
*/
|
|
61
87
|
|
|
62
88
|
export var getLoggingService = function getLoggingService() {
|
|
@@ -81,7 +107,6 @@ export var LOCALE_CHANGED = "".concat(LOCALE_TOPIC, ".CHANGED");
|
|
|
81
107
|
export function getCookies() {
|
|
82
108
|
return cookies;
|
|
83
109
|
}
|
|
84
|
-
addLocaleData([].concat(_toConsumableArray(arLocale), _toConsumableArray(enLocale), _toConsumableArray(esLocale), _toConsumableArray(frLocale), _toConsumableArray(zhLocale), _toConsumableArray(caLocale), _toConsumableArray(heLocale), _toConsumableArray(idLocale), _toConsumableArray(koLocale), _toConsumableArray(plLocale), _toConsumableArray(ptLocale), _toConsumableArray(ruLocale), _toConsumableArray(thLocale), _toConsumableArray(ukLocale)));
|
|
85
110
|
/**
|
|
86
111
|
* Some of our dependencies function on primary language subtags, rather than full locales.
|
|
87
112
|
* This function strips a locale down to that first subtag. Depending on the code, this
|
package/i18n/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/i18n/lib.js"],"names":["PropTypes","addLocaleData","arLocale","enLocale","esLocale","frLocale","zhLocale","caLocale","heLocale","idLocale","koLocale","plLocale","ptLocale","ruLocale","thLocale","ukLocale","Cookies","merge","cookies","supportedLocales","rtlLocales","config","loggingService","messages","getLoggingService","LOCALE_TOPIC","LOCALE_CHANGED","getCookies","getPrimaryLanguageSubtag","code","split","findSupportedLocale","locale","undefined","getLocale","Error","cookieLangPref","get","LANGUAGE_PREFERENCE_COOKIE_NAME","toLowerCase","global","navigator","language","getMessages","isRtl","includes","handleRtl","document","getElementsByTagName","setAttribute","messagesShape","ar","objectOf","string","en","fr","ca","he","id","pl","ru","th","uk","optionsShape","object","isRequired","shape","logError","func","oneOfType","arrayOf","mergeMessages","messagesArray","Array","isArray","configure","options","checkPropTypes","ENVIRONMENT","Object","keys","forEach","key","indexOf","console","warn"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,SAAP,MAAsB,YAAtB;AACA,SAASC,aAAT,QAA8B,YAA9B;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,QAAP,MAAqB,2BAArB;AACA,OAAOC,OAAP,MAAoB,kBAApB;AACA,OAAOC,KAAP,MAAkB,cAAlB;AAEA,IAAMC,OAAO,GAAG,IAAIF,OAAJ,EAAhB;AACA,IAAMG,gBAAgB,GAAG,CACvB,IADuB,EACjB;AACN;AACA,QAHuB,EAGb;AACV,IAJuB,EAIjB;AACN,OALuB,EAKd;AACT,IANuB,EAMjB;AACN,IAPuB,EAOjB;AACN,IARuB,EAQjB;AACN,OATuB,EASd;AACT,IAVuB,E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,OAAO,CAACrD,QAAtB,IAAkCgD,aAAa,CAACK,OAAO,CAACrD,QAAT,CAA/C,GAAoEqD,OAAO,CAACrD,QAAvF;;AAEA,MAAIF,MAAM,CAACyD,WAAP,KAAuB,YAA3B,EAAyC;AACvCC,IAAAA,MAAM,CAACC,IAAP,CAAYzD,QAAZ,EAAsB0D,OAAtB,CAA8B,UAACC,GAAD,EAAS;AACrC,UAAI/D,gBAAgB,CAACgE,OAAjB,CAAyBD,GAAzB,IAAgC,CAApC,EAAuC;AACrCE,QAAAA,OAAO,CAACC,IAAR,8BAAmCH,GAAnC,GADqC,CACM;AAC5C;AACF,KAJD;AAMA/D,IAAAA,gBAAgB,CAAC8D,OAAjB,CAAyB,UAACC,GAAD,EAAS;AAChC,UAAI3D,QAAQ,CAAC2D,GAAD,CAAR,KAAkBjD,SAAtB,EAAiC;AAC/BmD,QAAAA,OAAO,CAACC,IAAR,2BAAgCH,GAAhC,GAD+B,CACS;AACzC;AACF,KAJD;AAKD;;AAEDpC,EAAAA,SAAS;AACV","sourcesContent":["import PropTypes from 'prop-types';\nimport { addLocaleData } from 'react-intl';\nimport arLocale from 'react-intl/locale-data/ar';\nimport enLocale from 'react-intl/locale-data/en';\nimport esLocale from 'react-intl/locale-data/es';\nimport frLocale from 'react-intl/locale-data/fr';\nimport zhLocale from 'react-intl/locale-data/zh';\nimport caLocale from 'react-intl/locale-data/ca';\nimport heLocale from 'react-intl/locale-data/he';\nimport idLocale from 'react-intl/locale-data/id';\nimport koLocale from 'react-intl/locale-data/ko';\nimport plLocale from 'react-intl/locale-data/pl';\nimport ptLocale from 'react-intl/locale-data/pt';\nimport ruLocale from 'react-intl/locale-data/ru';\nimport thLocale from 'react-intl/locale-data/th';\nimport ukLocale from 'react-intl/locale-data/uk';\nimport Cookies from 'universal-cookie';\nimport merge from 'lodash.merge';\n\nconst cookies = new Cookies();\nconst supportedLocales = [\n 'ar', // Arabic\n // NOTE: 'en' is not included in this list intentionally, since it's the fallback.\n 'es-419', // Spanish, Latin American\n 'fr', // French\n 'zh-cn', // Chinese, Simplified\n 'ca', // Catalan\n 'he', // Hebrew\n 'id', // Indonesian\n 'ko-kr', // Korean (Korea)\n 'pl', // Polish\n 'pt-br', // Portuguese (Brazil)\n 'ru', // Russian\n 'th', // Thai\n 'uk', // Ukrainian\n];\nconst rtlLocales = [\n 'ar', // Arabic\n 'he', // Hebrew\n 'fa', // Farsi (not currently supported)\n 'ur', // Urdu (not currently supported)\n];\n\nlet config = null;\nlet loggingService = null;\nlet messages = null;\n\n/**\n *\n * @ignore\n * @returns {LoggingService}\n *\n */\nexport const getLoggingService = () => loggingService;\n\n/**\n * @memberof module:Internationalization\n */\nexport const LOCALE_TOPIC = 'LOCALE';\n\n/**\n * @memberof module:Internationalization\n */\nexport const LOCALE_CHANGED = `${LOCALE_TOPIC}.CHANGED`;\n\n/**\n *\n * @memberof module:Internationalization\n * @returns {Cookies}\n */\nexport function getCookies() {\n return cookies;\n}\n\naddLocaleData([\n ...arLocale,\n ...enLocale,\n ...esLocale,\n ...frLocale,\n ...zhLocale,\n ...caLocale,\n ...heLocale,\n ...idLocale,\n ...koLocale,\n ...plLocale,\n ...ptLocale,\n ...ruLocale,\n ...thLocale,\n ...ukLocale,\n]);\n\n/**\n * Some of our dependencies function on primary language subtags, rather than full locales.\n * This function strips a locale down to that first subtag. Depending on the code, this\n * may be 2 or more characters.\n *\n * @param {string} code\n * @memberof module:Internationalization\n */\nexport function getPrimaryLanguageSubtag(code) {\n return code.split('-')[0];\n}\n\n/**\n * Finds the closest supported locale to the one provided. This is done in three steps:\n *\n * 1. Returning the locale itself if its exact language code is supported.\n * 2. Returning the primary language subtag of the language code if it is supported (ar for ar-eg,\n * for instance).\n * 3. Returning 'en' if neither of the above produce a supported locale.\n *\n * @param {string} locale\n * @returns {string}\n * @memberof module:Internationalization\n */\nexport function findSupportedLocale(locale) {\n if (messages[locale] !== undefined) {\n return locale;\n }\n\n if (messages[getPrimaryLanguageSubtag(locale)] !== undefined) {\n return getPrimaryLanguageSubtag(locale);\n }\n\n return 'en';\n}\n\n/**\n * Get the locale from the cookie or, failing that, the browser setting.\n * Gracefully fall back to a more general primary language subtag or to English (en)\n * if we don't support that language.\n *\n * @param {string} locale If a locale is provided, returns the closest supported locale. Optional.\n * @throws An error if i18n has not yet been configured.\n * @returns {string}\n * @memberof module:Internationalization\n */\nexport function getLocale(locale) {\n if (messages === null) {\n throw new Error('getLocale called before configuring i18n. Call configure with messages first.');\n }\n // 1. Explicit application request\n if (locale !== undefined) {\n return findSupportedLocale(locale);\n }\n // 2. User setting in cookie\n const cookieLangPref = cookies\n .get(config.LANGUAGE_PREFERENCE_COOKIE_NAME);\n if (cookieLangPref) {\n return findSupportedLocale(cookieLangPref.toLowerCase());\n }\n // 3. Browser language (default)\n // Note that some browers prefer upper case for the region part of the locale, while others don't.\n // Thus the toLowerCase, for consistency.\n // https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/language\n return findSupportedLocale(global.navigator.language.toLowerCase());\n}\n\n/**\n * Returns messages for the provided locale, or the user's preferred locale if no argument is\n * provided.\n *\n * @param {string} [locale=getLocale()]\n * @memberof module:Internationalization\n */\nexport function getMessages(locale = getLocale()) {\n return messages[locale];\n}\n\n/**\n * Determines if the provided locale is a right-to-left language.\n *\n * @param {string} locale\n * @memberof module:Internationalization\n */\nexport function isRtl(locale) {\n return rtlLocales.includes(locale);\n}\n\n/**\n * Handles applying the RTL stylesheet and \"dir=rtl\" attribute to the html tag if the current locale\n * is a RTL language.\n *\n * @memberof module:Internationalization\n */\nexport function handleRtl() {\n if (isRtl(getLocale())) {\n global.document.getElementsByTagName('html')[0].setAttribute('dir', 'rtl');\n } else {\n global.document.getElementsByTagName('html')[0].setAttribute('dir', 'ltr');\n }\n}\n\nconst messagesShape = {\n ar: PropTypes.objectOf(PropTypes.string), // Arabic\n en: PropTypes.objectOf(PropTypes.string),\n 'es-419': PropTypes.objectOf(PropTypes.string), // Spanish, Latin American\n fr: PropTypes.objectOf(PropTypes.string), // French\n 'zh-cn': PropTypes.objectOf(PropTypes.string), // Chinese, Simplified\n ca: PropTypes.objectOf(PropTypes.string), // Catalan\n he: PropTypes.objectOf(PropTypes.string), // Hebrew\n id: PropTypes.objectOf(PropTypes.string), // Indonesian\n 'ko-kr': PropTypes.objectOf(PropTypes.string), // Korean (Korea)\n pl: PropTypes.objectOf(PropTypes.string), // Polish\n 'pt-br': PropTypes.objectOf(PropTypes.string), // Portuguese (Brazil)\n ru: PropTypes.objectOf(PropTypes.string), // Russian\n th: PropTypes.objectOf(PropTypes.string), // Thai\n uk: PropTypes.objectOf(PropTypes.string), // Ukrainian\n};\n\nconst optionsShape = {\n config: PropTypes.object.isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n }).isRequired,\n messages: PropTypes.oneOfType([\n PropTypes.shape(messagesShape),\n PropTypes.arrayOf(PropTypes.shape(messagesShape)),\n ]).isRequired,\n};\n\n/**\n *\n *\n * @param {Array} [messagesArray=[]]\n * @returns {Object}\n * @memberof module:Internationalization\n */\nexport function mergeMessages(messagesArray = []) {\n return Array.isArray(messagesArray) ? merge({}, ...messagesArray) : {};\n}\n\n/**\n * Configures the i18n library with messages for your application.\n *\n * Logs a warning if it detects a locale it doesn't expect (as defined by the supportedLocales list\n * above), or if an expected locale is not provided.\n *\n * @param {Object} options\n * @param {LoggingService} options.loggingService\n * @param {Object} options.config\n * @param {Object} options.messages\n * @memberof module:Internationalization\n */\nexport function configure(options) {\n PropTypes.checkPropTypes(optionsShape, options, 'property', 'i18n');\n // eslint-disable-next-line prefer-destructuring\n loggingService = options.loggingService;\n // eslint-disable-next-line prefer-destructuring\n config = options.config;\n messages = Array.isArray(options.messages) ? mergeMessages(options.messages) : options.messages;\n\n if (config.ENVIRONMENT !== 'production') {\n Object.keys(messages).forEach((key) => {\n if (supportedLocales.indexOf(key) < 0) {\n console.warn(`Unexpected locale: ${key}`); // eslint-disable-line no-console\n }\n });\n\n supportedLocales.forEach((key) => {\n if (messages[key] === undefined) {\n console.warn(`Missing locale: ${key}`); // eslint-disable-line no-console\n }\n });\n }\n\n handleRtl();\n}\n"],"file":"lib.js"}
|
|
1
|
+
{"version":3,"file":"lib.js","names":["PropTypes","Cookies","merge","cookies","supportedLocales","rtlLocales","config","loggingService","messages","intlShape","object","getLoggingService","LOCALE_TOPIC","LOCALE_CHANGED","getCookies","getPrimaryLanguageSubtag","code","split","findSupportedLocale","locale","undefined","getLocale","Error","cookieLangPref","get","LANGUAGE_PREFERENCE_COOKIE_NAME","toLowerCase","global","navigator","language","getMessages","isRtl","includes","handleRtl","document","getElementsByTagName","setAttribute","messagesShape","ar","objectOf","string","en","fr","ca","he","id","pl","ru","th","uk","optionsShape","isRequired","shape","logError","func","oneOfType","arrayOf","mergeMessages","messagesArray","Array","isArray","configure","options","checkPropTypes","ENVIRONMENT","Object","keys","forEach","key","indexOf","console","warn"],"sources":["../../src/i18n/lib.js"],"sourcesContent":["import PropTypes from 'prop-types';\nimport Cookies from 'universal-cookie';\nimport merge from 'lodash.merge';\n\nimport '@formatjs/intl-pluralrules/polyfill';\nimport '@formatjs/intl-pluralrules/locale-data/ar';\nimport '@formatjs/intl-pluralrules/locale-data/en';\nimport '@formatjs/intl-pluralrules/locale-data/es';\nimport '@formatjs/intl-pluralrules/locale-data/fr';\nimport '@formatjs/intl-pluralrules/locale-data/zh';\nimport '@formatjs/intl-pluralrules/locale-data/ca';\nimport '@formatjs/intl-pluralrules/locale-data/he';\nimport '@formatjs/intl-pluralrules/locale-data/id';\nimport '@formatjs/intl-pluralrules/locale-data/ko';\nimport '@formatjs/intl-pluralrules/locale-data/pl';\nimport '@formatjs/intl-pluralrules/locale-data/pt';\nimport '@formatjs/intl-pluralrules/locale-data/ru';\nimport '@formatjs/intl-pluralrules/locale-data/th';\nimport '@formatjs/intl-pluralrules/locale-data/uk';\n\nimport '@formatjs/intl-relativetimeformat/polyfill';\nimport '@formatjs/intl-relativetimeformat/locale-data/ar';\nimport '@formatjs/intl-relativetimeformat/locale-data/en';\nimport '@formatjs/intl-relativetimeformat/locale-data/es';\nimport '@formatjs/intl-relativetimeformat/locale-data/fr';\nimport '@formatjs/intl-relativetimeformat/locale-data/zh';\nimport '@formatjs/intl-relativetimeformat/locale-data/ca';\nimport '@formatjs/intl-relativetimeformat/locale-data/he';\nimport '@formatjs/intl-relativetimeformat/locale-data/id';\nimport '@formatjs/intl-relativetimeformat/locale-data/ko';\nimport '@formatjs/intl-relativetimeformat/locale-data/pl';\nimport '@formatjs/intl-relativetimeformat/locale-data/pt';\nimport '@formatjs/intl-relativetimeformat/locale-data/ru';\nimport '@formatjs/intl-relativetimeformat/locale-data/th';\nimport '@formatjs/intl-relativetimeformat/locale-data/uk';\n\nconst cookies = new Cookies();\nconst supportedLocales = [\n 'ar', // Arabic\n // NOTE: 'en' is not included in this list intentionally, since it's the fallback.\n 'es-419', // Spanish, Latin American\n 'fr', // French\n 'zh-cn', // Chinese, Simplified\n 'ca', // Catalan\n 'he', // Hebrew\n 'id', // Indonesian\n 'ko-kr', // Korean (Korea)\n 'pl', // Polish\n 'pt-br', // Portuguese (Brazil)\n 'ru', // Russian\n 'th', // Thai\n 'uk', // Ukrainian\n];\nconst rtlLocales = [\n 'ar', // Arabic\n 'he', // Hebrew\n 'fa', // Farsi (not currently supported)\n 'ur', // Urdu (not currently supported)\n];\n\nlet config = null;\nlet loggingService = null;\nlet messages = null;\n\n/**\n * @memberof module:Internationalization\n *\n * Prior versions of react-intl (our primary implementation of the i18n service) included a\n * PropTypes-based 'shape' for its `intl` object. This has since been removed. For legacy\n * compatibility, we include an `intlShape` export that is set to PropTypes.object. Usage of this\n * export is deprecated.\n *\n * @deprecated\n */\nexport const intlShape = PropTypes.object;\n\n/**\n *\n * @ignore\n * @returns {LoggingService}\n */\nexport const getLoggingService = () => loggingService;\n\n/**\n * @memberof module:Internationalization\n */\nexport const LOCALE_TOPIC = 'LOCALE';\n\n/**\n * @memberof module:Internationalization\n */\nexport const LOCALE_CHANGED = `${LOCALE_TOPIC}.CHANGED`;\n\n/**\n *\n * @memberof module:Internationalization\n * @returns {Cookies}\n */\nexport function getCookies() {\n return cookies;\n}\n\n/**\n * Some of our dependencies function on primary language subtags, rather than full locales.\n * This function strips a locale down to that first subtag. Depending on the code, this\n * may be 2 or more characters.\n *\n * @param {string} code\n * @memberof module:Internationalization\n */\nexport function getPrimaryLanguageSubtag(code) {\n return code.split('-')[0];\n}\n\n/**\n * Finds the closest supported locale to the one provided. This is done in three steps:\n *\n * 1. Returning the locale itself if its exact language code is supported.\n * 2. Returning the primary language subtag of the language code if it is supported (ar for ar-eg,\n * for instance).\n * 3. Returning 'en' if neither of the above produce a supported locale.\n *\n * @param {string} locale\n * @returns {string}\n * @memberof module:Internationalization\n */\nexport function findSupportedLocale(locale) {\n if (messages[locale] !== undefined) {\n return locale;\n }\n\n if (messages[getPrimaryLanguageSubtag(locale)] !== undefined) {\n return getPrimaryLanguageSubtag(locale);\n }\n\n return 'en';\n}\n\n/**\n * Get the locale from the cookie or, failing that, the browser setting.\n * Gracefully fall back to a more general primary language subtag or to English (en)\n * if we don't support that language.\n *\n * @param {string} locale If a locale is provided, returns the closest supported locale. Optional.\n * @throws An error if i18n has not yet been configured.\n * @returns {string}\n * @memberof module:Internationalization\n */\nexport function getLocale(locale) {\n if (messages === null) {\n throw new Error('getLocale called before configuring i18n. Call configure with messages first.');\n }\n // 1. Explicit application request\n if (locale !== undefined) {\n return findSupportedLocale(locale);\n }\n // 2. User setting in cookie\n const cookieLangPref = cookies\n .get(config.LANGUAGE_PREFERENCE_COOKIE_NAME);\n if (cookieLangPref) {\n return findSupportedLocale(cookieLangPref.toLowerCase());\n }\n // 3. Browser language (default)\n // Note that some browers prefer upper case for the region part of the locale, while others don't.\n // Thus the toLowerCase, for consistency.\n // https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/language\n return findSupportedLocale(global.navigator.language.toLowerCase());\n}\n\n/**\n * Returns messages for the provided locale, or the user's preferred locale if no argument is\n * provided.\n *\n * @param {string} [locale=getLocale()]\n * @memberof module:Internationalization\n */\nexport function getMessages(locale = getLocale()) {\n return messages[locale];\n}\n\n/**\n * Determines if the provided locale is a right-to-left language.\n *\n * @param {string} locale\n * @memberof module:Internationalization\n */\nexport function isRtl(locale) {\n return rtlLocales.includes(locale);\n}\n\n/**\n * Handles applying the RTL stylesheet and \"dir=rtl\" attribute to the html tag if the current locale\n * is a RTL language.\n *\n * @memberof module:Internationalization\n */\nexport function handleRtl() {\n if (isRtl(getLocale())) {\n global.document.getElementsByTagName('html')[0].setAttribute('dir', 'rtl');\n } else {\n global.document.getElementsByTagName('html')[0].setAttribute('dir', 'ltr');\n }\n}\n\nconst messagesShape = {\n ar: PropTypes.objectOf(PropTypes.string), // Arabic\n en: PropTypes.objectOf(PropTypes.string),\n 'es-419': PropTypes.objectOf(PropTypes.string), // Spanish, Latin American\n fr: PropTypes.objectOf(PropTypes.string), // French\n 'zh-cn': PropTypes.objectOf(PropTypes.string), // Chinese, Simplified\n ca: PropTypes.objectOf(PropTypes.string), // Catalan\n he: PropTypes.objectOf(PropTypes.string), // Hebrew\n id: PropTypes.objectOf(PropTypes.string), // Indonesian\n 'ko-kr': PropTypes.objectOf(PropTypes.string), // Korean (Korea)\n pl: PropTypes.objectOf(PropTypes.string), // Polish\n 'pt-br': PropTypes.objectOf(PropTypes.string), // Portuguese (Brazil)\n ru: PropTypes.objectOf(PropTypes.string), // Russian\n th: PropTypes.objectOf(PropTypes.string), // Thai\n uk: PropTypes.objectOf(PropTypes.string), // Ukrainian\n};\n\nconst optionsShape = {\n config: PropTypes.object.isRequired,\n loggingService: PropTypes.shape({\n logError: PropTypes.func.isRequired,\n }).isRequired,\n messages: PropTypes.oneOfType([\n PropTypes.shape(messagesShape),\n PropTypes.arrayOf(PropTypes.shape(messagesShape)),\n ]).isRequired,\n};\n\n/**\n *\n *\n * @param {Array} [messagesArray=[]]\n * @returns {Object}\n * @memberof module:Internationalization\n */\nexport function mergeMessages(messagesArray = []) {\n return Array.isArray(messagesArray) ? merge({}, ...messagesArray) : {};\n}\n\n/**\n * Configures the i18n library with messages for your application.\n *\n * Logs a warning if it detects a locale it doesn't expect (as defined by the supportedLocales list\n * above), or if an expected locale is not provided.\n *\n * @param {Object} options\n * @param {LoggingService} options.loggingService\n * @param {Object} options.config\n * @param {Object} options.messages\n * @memberof module:Internationalization\n */\nexport function configure(options) {\n PropTypes.checkPropTypes(optionsShape, options, 'property', 'i18n');\n // eslint-disable-next-line prefer-destructuring\n loggingService = options.loggingService;\n // eslint-disable-next-line prefer-destructuring\n config = options.config;\n messages = Array.isArray(options.messages) ? mergeMessages(options.messages) : options.messages;\n\n if (config.ENVIRONMENT !== 'production') {\n Object.keys(messages).forEach((key) => {\n if (supportedLocales.indexOf(key) < 0) {\n console.warn(`Unexpected locale: ${key}`); // eslint-disable-line no-console\n }\n });\n\n supportedLocales.forEach((key) => {\n if (messages[key] === undefined) {\n console.warn(`Missing locale: ${key}`); // eslint-disable-line no-console\n }\n });\n }\n\n handleRtl();\n}\n"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,SAAP,MAAsB,YAAtB;AACA,OAAOC,OAAP,MAAoB,kBAApB;AACA,OAAOC,KAAP,MAAkB,cAAlB;AAEA,OAAO,qCAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AACA,OAAO,2CAAP;AAEA,OAAO,4CAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDA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D,KAAK,CAACC,OAAN,CAAcE,OAAO,CAACtD,QAAtB,IAAkCiD,aAAa,CAACK,OAAO,CAACtD,QAAT,CAA/C,GAAoEsD,OAAO,CAACtD,QAAvF;;EAEA,IAAIF,MAAM,CAAC0D,WAAP,KAAuB,YAA3B,EAAyC;IACvCC,MAAM,CAACC,IAAP,CAAY1D,QAAZ,EAAsB2D,OAAtB,CAA8B,UAACC,GAAD,EAAS;MACrC,IAAIhE,gBAAgB,CAACiE,OAAjB,CAAyBD,GAAzB,IAAgC,CAApC,EAAuC;QACrCE,OAAO,CAACC,IAAR,8BAAmCH,GAAnC,GADqC,CACM;MAC5C;IACF,CAJD;IAMAhE,gBAAgB,CAAC+D,OAAjB,CAAyB,UAACC,GAAD,EAAS;MAChC,IAAI5D,QAAQ,CAAC4D,GAAD,CAAR,KAAkBhD,SAAtB,EAAiC;QAC/BkD,OAAO,CAACC,IAAR,2BAAgCH,GAAhC,GAD+B,CACS;MACzC;IACF,CAJD;EAKD;;EAEDnC,SAAS;AACV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"transifex-utils.js","names":["fs","require","glob","path","gatherJson","dir","ret","files","sync","forEach","filename","messages","JSON","parse","readFileSync","push","escapeDots","messageId","replace","jsonDir","process","argv","messageObjects","length","exitCode","Error","loggingPrefix","basename","__filename","bashScriptsPath","hashFile","stdout","write","messageInfo","outputFile","writeFileSync","message","transifexFormatId","id","info","find","mi","key","appendFileSync","string_hash","description","output","defaultMessage","stringify"],"sources":["../../../src/i18n/scripts/transifex-utils.js"],"sourcesContent":["#!/usr/bin/env node\n\nconst fs = require('fs');\nconst glob = require('glob');\nconst path = require('path');\n\n/*\n * See the Makefile for how the required hash file is downloaded from Transifex.\n */\n\n/*\n * Expected input: a directory, possibly containing subdirectories, with .json files. Each .json\n * file is an array of translation triplets (id, description, defaultMessage).\n *\n *\n */\nfunction gatherJson(dir) {\n const ret = [];\n const files = glob.sync(`${dir}/**/*.json`);\n\n files.forEach((filename) => {\n const messages = JSON.parse(fs.readFileSync(filename));\n ret.push(...messages);\n });\n return ret;\n}\n\n// the hash file returns ids whose periods are \"escaped\" (sort of), like this:\n// \"key\": \"profile\\\\.sociallinks\\\\.social\\\\.links\"\n// so our regular messageIds won't match them out of the box\nfunction escapeDots(messageId) {\n return messageId.replace(/\\./g, '\\\\.');\n}\n\nconst jsonDir = process.argv[2];\nconst messageObjects = gatherJson(jsonDir);\n\nif (messageObjects.length === 0) {\n process.exitCode = 1;\n throw new Error('Found no messages');\n}\n\nif (process.argv[3] === '--comments') { // prepare to handle the translator notes\n const loggingPrefix = path.basename(`${__filename}`); // the name of this JS file\n const bashScriptsPath = (\n process.argv[4] && process.argv[4] === '--v3-scripts-path'\n ? './node_modules/@edx/reactifex/bash_scripts'\n : './node_modules/reactifex/bash_scripts');\n\n const hashFile = `${bashScriptsPath}/hashmap.json`;\n process.stdout.write(`${loggingPrefix}: reading hash file ${hashFile}\\n`);\n const messageInfo = JSON.parse(fs.readFileSync(hashFile));\n\n const outputFile = `${bashScriptsPath}/hashed_data.txt`;\n process.stdout.write(`${loggingPrefix}: writing to output file ${outputFile}\\n`);\n fs.writeFileSync(outputFile, '');\n\n messageObjects.forEach((message) => {\n const transifexFormatId = escapeDots(message.id);\n\n const info = messageInfo.find(mi => mi.key === transifexFormatId);\n if (info) {\n fs.appendFileSync(outputFile, `${info.string_hash}|${message.description}\\n`);\n } else {\n process.stdout.write(`${loggingPrefix}: string ${message.id} does not yet exist on transifex!\\n`);\n }\n });\n} else {\n const output = {};\n\n messageObjects.forEach((message) => {\n output[message.id] = message.defaultMessage;\n });\n fs.writeFileSync(process.argv[3], JSON.stringify(output, null, 2));\n}\n"],"mappings":"AAAA;;;;;;;;;;;;;;AAEA,IAAMA,EAAE,GAAGC,OAAO,CAAC,IAAD,CAAlB;;AACA,IAAMC,IAAI,GAAGD,OAAO,CAAC,MAAD,CAApB;;AACA,IAAME,IAAI,GAAGF,OAAO,C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