@edx/frontend-platform 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analytics/MockAnalyticsService.js.map +1 -1
- package/analytics/SegmentAnalyticsService.js.map +1 -1
- package/analytics/index.js.map +1 -1
- package/analytics/interface.js.map +1 -1
- package/auth/AxiosCsrfTokenService.js.map +1 -1
- package/auth/AxiosJwtAuthService.js +32 -7
- package/auth/AxiosJwtAuthService.js.map +1 -1
- package/auth/AxiosJwtTokenService.js.map +1 -1
- package/auth/LocalForageCache.js.map +1 -1
- package/auth/MockAuthService.js +136 -107
- package/auth/MockAuthService.js.map +1 -1
- package/auth/index.js.map +1 -1
- package/auth/interceptors/createCsrfTokenProviderInterceptor.js.map +1 -1
- package/auth/interceptors/createJwtTokenProviderInterceptor.js.map +1 -1
- package/auth/interceptors/createProcessAxiosRequestErrorInterceptor.js.map +1 -1
- package/auth/interceptors/createRetryInterceptor.js.map +1 -1
- package/auth/interface.js.map +1 -1
- package/auth/utils.js.map +1 -1
- package/config.js.map +1 -1
- package/constants.js.map +1 -1
- package/i18n/countries.js.map +1 -1
- package/i18n/index.js.map +1 -1
- package/i18n/injectIntlWithShim.js.map +1 -1
- package/i18n/languages.js.map +1 -1
- package/i18n/lib.js.map +1 -1
- package/i18n/scripts/README.md +25 -0
- package/i18n/scripts/transifex-utils.js.map +1 -1
- package/index.js.map +1 -1
- package/initialize.js +5 -3
- package/initialize.js.map +1 -1
- package/logging/MockLoggingService.js.map +1 -1
- package/logging/NewRelicLoggingService.js.map +1 -1
- package/logging/index.js.map +1 -1
- package/logging/interface.js.map +1 -1
- package/package.json +4 -5
- package/pubSub.js.map +1 -1
- package/react/AppContext.js.map +1 -1
- package/react/AppProvider.js.map +1 -1
- package/react/AuthenticatedPageRoute.js.map +1 -1
- package/react/ErrorBoundary.js.map +1 -1
- package/react/ErrorPage.js.map +1 -1
- package/react/LoginRedirect.js.map +1 -1
- package/react/OptionalReduxProvider.js.map +1 -1
- package/react/PageRoute.js.map +1 -1
- package/react/hooks.js.map +1 -1
- package/react/index.js.map +1 -1
- package/testing/index.js.map +1 -1
- package/testing/initializeMockApp.js.map +1 -1
- package/testing/mockMessages.js.map +1 -1
- package/utils.js.map +1 -1
- package/i18n/scripts/Makefile +0 -39
package/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.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"}
|
|
@@ -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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/i18n/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"],"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,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;AACA,OAAO,kDAAP;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,EAUjB;AACN,OAXuB,EAWd;AACT,IAZuB,EAYjB;AACN,IAbuB,EAajB;AACN,IAduB,CAcjB;AAdiB,CAAzB;AAgBA,IAAMC,UAA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,UAAIhE,gBAAgB,CAACiE,OAAjB,CAAyBD,GAAzB,IAAgC,CAApC,EAAuC;AACrCE,QAAAA,OAAO,CAACC,IAAR,8BAAmCH,GAAnC,GADqC,CACM;AAC5C;AACF,KAJD;AAMAhE,IAAAA,gBAAgB,CAAC+D,OAAjB,CAAyB,UAACC,GAAD,EAAS;AAChC,UAAI5D,QAAQ,CAAC4D,GAAD,CAAR,KAAkBhD,SAAtB,EAAiC;AAC/BkD,QAAAA,OAAO,CAACC,IAAR,2BAAgCH,GAAhC,GAD+B,CACS;AACzC;AACF,KAJD;AAKD;;AAEDnC,EAAAA,SAAS;AACV","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"],"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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,EAAN,4BAAawD,aAAb,GAA/B,GAA6D,EAApE;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,SAAT,CAAmBC,OAAnB,EAA4B;EACjC9D,SAAS,CAAC+D,cAAV,CAAyBb,YAAzB,EAAuCY,OAAvC,EAAgD,UAAhD,EAA4D,MAA5D,EADiC,CAEjC;;EACAvD,cAAc,GAAGuD,OAAO,CAACvD,cAAzB,CAHiC,CAIjC;;EACAD,MAAM,GAAGwD,OAAO,CAACxD,MAAjB;EACAE,QAAQ,GAAGmD,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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# i18n/scripts
|
|
2
|
+
|
|
3
|
+
This directory contains the `transifex-utils.js` file which is shared across all micro-frontends.
|
|
4
|
+
|
|
5
|
+
The package.json of `frontend-platform` includes the following section:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
"bin": {
|
|
9
|
+
"transifex-utils.js": "i18n/scripts/transifex-utils.js"
|
|
10
|
+
},
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
This config block causes `transifex-utils.js` to be copied to the following path when `frontend-platform` is installed as a dependency of an micro-frontend:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
/node_modules/.bin/transifex-utils.js
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
All micro-frontends have a `Makefile` with a line that loads `transifex-utils.js` from the above path:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
transifex_utils = ./node_modules/.bin/transifex-utils.js
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
So if you delete `transifex-utils.js` or the `scripts` directory, you'll break all micro-frontend builds. Happy coding!
|
|
@@ -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,CAAC,MAAD,CAApB;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASG,UAAT,CAAoBC,GAApB,EAAyB;EACvB,IAAMC,GAAG,GAAG,EAAZ;EACA,IAAMC,KAAK,GAAGL,IAAI,CAACM,IAAL,WAAa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BN,aAAxB,sCAAiEQ,UAAjE;EACAlC,EAAE,CAACmC,aAAH,CAAiBD,UAAjB,EAA6B,EAA7B;EAEAZ,cAAc,CAACb,OAAf,CAAuB,UAAC2B,OAAD,EAAa;IAClC,IAAMC,iBAAiB,GAAGrB,UAAU,CAACoB,OAAO,CAACE,EAAT,CAApC;IAEA,IAAMC,IAAI,GAAGN,WAAW,CAACO,IAAZ,CAAiB,UAAAC,EAAE;MAAA,OAAIA,EAAE,CAACC,GAAH,KAAWL,iBAAf;IAAA,CAAnB,CAAb;;IACA,IAAIE,IAAJ,EAAU;MACRvC,EAAE,CAAC2C,cAAH,CAAkBT,UAAlB,YAAiCK,IAAI,CAACK,WAAtC,cAAqDR,OAAO,CAACS,WAA7D;IACD,CAFD,MAEO;MACLzB,OAAO,CAACW,MAAR,CAAeC,KAAf,WAAwBN,aAAxB,sBAAiDU,OAAO,CAACE,EAAzD;IACD;EACF,CATD;AAUD,CAzBD,MAyBO;EACL,IAAMQ,MAAM,GAAG,EAAf;EAEAxB,cAAc,CAACb,OAAf,CAAuB,UAAC2B,OAAD,EAAa;IAClCU,MAAM,CAACV,OAAO,CAACE,EAAT,CAAN,GAAqBF,OAAO,CAACW,cAA7B;EACD,CAFD;EAGA/C,EAAE,CAACmC,aAAH,CAAiBf,OAAO,CAACC,IAAR,CAAa,CAAb,CAAjB,EAAkCT,IAAI,CAACoC,SAAL,CAAeF,MAAf,EAAuB,IAAvB,EAA6B,CAA7B,CAAlC;AACD"}
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["modifyObjectKeys","camelCaseObject","snakeCaseObject","convertKeyNames","getQueryParameters","ensureDefinedConfig","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","initialize","history","initError","auth","publish","subscribe","unsubscribe","getConfig","setConfig","mergeConfig","ensureConfig","initializeMockApp","mockMessages"],"sources":["../src/index.js"],"sourcesContent":["export {\n modifyObjectKeys,\n camelCaseObject,\n snakeCaseObject,\n convertKeyNames,\n getQueryParameters,\n ensureDefinedConfig,\n} from './utils';\nexport {\n APP_TOPIC,\n APP_PUBSUB_INITIALIZED,\n APP_CONFIG_INITIALIZED,\n APP_AUTH_INITIALIZED,\n APP_I18N_INITIALIZED,\n APP_LOGGING_INITIALIZED,\n APP_ANALYTICS_INITIALIZED,\n APP_READY,\n APP_INIT_ERROR,\n CONFIG_TOPIC,\n CONFIG_CHANGED,\n} from './constants';\nexport {\n initialize,\n history,\n initError,\n auth,\n} from './initialize';\nexport {\n publish,\n subscribe,\n unsubscribe,\n} from './pubSub';\nexport {\n getConfig,\n setConfig,\n mergeConfig,\n ensureConfig,\n} from './config';\nexport {\n initializeMockApp,\n mockMessages,\n} from './testing';\n"],"mappings":"AAAA,SACEA,gBADF,EAEEC,eAFF,EAGEC,eAHF,EAIEC,eAJF,EAKEC,kBALF,EAMEC,mBANF,QAOO,SAPP;AAQA,SACEC,SADF,EAEEC,sBAFF,EAGEC,sBAHF,EAIEC,oBAJF,EAKEC,oBALF,EAMEC,uBANF,EAOEC,yBAPF,EAQEC,SARF,EASEC,cATF,EAUEC,YAVF,EAWEC,cAXF,QAYO,aAZP;AAaA,SACEC,UADF,EAEEC,OAFF,EAGEC,SAHF,EAIEC,IAJF,QAKO,cALP;AAMA,SACEC,OADF,EAEEC,SAFF,EAGEC,WAHF,QAIO,UAJP;AAKA,SACEC,SADF,EAEEC,SAFF,EAGEC,WAHF,EAIEC,YAJF,QAKO,UALP;AAMA,SACEC,iBADF,EAEEC,YAFF,QAGO,WAHP"}
|
package/initialize.js
CHANGED
|
@@ -266,6 +266,7 @@ function applyOverrideHandlers(overrides) {
|
|
|
266
266
|
* to use.
|
|
267
267
|
* @param {*} [options.analyticsService=SegmentAnalyticsService] The `AnalyticsService`
|
|
268
268
|
* implementation to use.
|
|
269
|
+
* @param {*} [options.authMiddleware=[]] An array of middleware to apply to http clients in the auth service.
|
|
269
270
|
* @param {*} [options.requireAuthenticatedUser=false] If true, turns on automatic login
|
|
270
271
|
* redirection for unauthenticated users. Defaults to false, meaning that by default the
|
|
271
272
|
* application will allow anonymous/unauthenticated sessions.
|
|
@@ -288,13 +289,13 @@ export function initialize(_x4) {
|
|
|
288
289
|
|
|
289
290
|
function _initialize() {
|
|
290
291
|
_initialize = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(_ref2) {
|
|
291
|
-
var _ref2$loggingService, loggingService, _ref2$analyticsServic, analyticsService, _ref2$authService, authService, _ref2$requireAuthenti, requireUser, _ref2$hydrateAuthenti, hydrateUser, messages, _ref2$handlers, overrideHandlers, handlers;
|
|
292
|
+
var _ref2$loggingService, loggingService, _ref2$analyticsServic, analyticsService, _ref2$authService, authService, _ref2$authMiddleware, authMiddleware, _ref2$requireAuthenti, requireUser, _ref2$hydrateAuthenti, hydrateUser, messages, _ref2$handlers, overrideHandlers, handlers;
|
|
292
293
|
|
|
293
294
|
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
294
295
|
while (1) {
|
|
295
296
|
switch (_context5.prev = _context5.next) {
|
|
296
297
|
case 0:
|
|
297
|
-
_ref2$loggingService = _ref2.loggingService, loggingService = _ref2$loggingService === void 0 ? NewRelicLoggingService : _ref2$loggingService, _ref2$analyticsServic = _ref2.analyticsService, analyticsService = _ref2$analyticsServic === void 0 ? SegmentAnalyticsService : _ref2$analyticsServic, _ref2$authService = _ref2.authService, authService = _ref2$authService === void 0 ? AxiosJwtAuthService : _ref2$authService, _ref2$requireAuthenti = _ref2.requireAuthenticatedUser, requireUser = _ref2$requireAuthenti === void 0 ? false : _ref2$requireAuthenti, _ref2$hydrateAuthenti = _ref2.hydrateAuthenticatedUser, hydrateUser = _ref2$hydrateAuthenti === void 0 ? false : _ref2$hydrateAuthenti, messages = _ref2.messages, _ref2$handlers = _ref2.handlers, overrideHandlers = _ref2$handlers === void 0 ? {} : _ref2$handlers;
|
|
298
|
+
_ref2$loggingService = _ref2.loggingService, loggingService = _ref2$loggingService === void 0 ? NewRelicLoggingService : _ref2$loggingService, _ref2$analyticsServic = _ref2.analyticsService, analyticsService = _ref2$analyticsServic === void 0 ? SegmentAnalyticsService : _ref2$analyticsServic, _ref2$authService = _ref2.authService, authService = _ref2$authService === void 0 ? AxiosJwtAuthService : _ref2$authService, _ref2$authMiddleware = _ref2.authMiddleware, authMiddleware = _ref2$authMiddleware === void 0 ? [] : _ref2$authMiddleware, _ref2$requireAuthenti = _ref2.requireAuthenticatedUser, requireUser = _ref2$requireAuthenti === void 0 ? false : _ref2$requireAuthenti, _ref2$hydrateAuthenti = _ref2.hydrateAuthenticatedUser, hydrateUser = _ref2$hydrateAuthenti === void 0 ? false : _ref2$hydrateAuthenti, messages = _ref2.messages, _ref2$handlers = _ref2.handlers, overrideHandlers = _ref2$handlers === void 0 ? {} : _ref2$handlers;
|
|
298
299
|
handlers = applyOverrideHandlers(overrideHandlers);
|
|
299
300
|
_context5.prev = 2;
|
|
300
301
|
_context5.next = 5;
|
|
@@ -320,7 +321,8 @@ function _initialize() {
|
|
|
320
321
|
|
|
321
322
|
configureAuth(authService, {
|
|
322
323
|
loggingService: getLoggingService(),
|
|
323
|
-
config: getConfig()
|
|
324
|
+
config: getConfig(),
|
|
325
|
+
middleware: authMiddleware
|
|
324
326
|
});
|
|
325
327
|
_context5.next = 16;
|
|
326
328
|
return handlers.auth(requireUser, hydrateUser);
|
package/initialize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/initialize.js"],"names":["createBrowserHistory","createMemoryHistory","publish","getConfig","configure","configureLogging","getLoggingService","NewRelicLoggingService","logError","configureAnalytics","SegmentAnalyticsService","identifyAnonymousUser","identifyAuthenticatedUser","getAuthenticatedHttpClient","configureAuth","ensureAuthenticatedUser","fetchAuthenticatedUser","hydrateAuthenticatedUser","getAuthenticatedUser","AxiosJwtAuthService","configureI18n","APP_PUBSUB_INITIALIZED","APP_CONFIG_INITIALIZED","APP_AUTH_INITIALIZED","APP_I18N_INITIALIZED","APP_LOGGING_INITIALIZED","APP_ANALYTICS_INITIALIZED","APP_READY","APP_INIT_ERROR","history","window","basename","PUBLIC_PATH","initError","error","auth","requireUser","hydrateUser","global","location","href","analytics","authenticatedUser","userId","applyOverrideHandlers","overrides","noOp","pubSub","config","logging","i18n","ready","initialize","loggingService","analyticsService","authService","requireAuthenticatedUser","messages","handlers","overrideHandlers","httpClient","isRedirecting"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,oBAAT,EAA+BC,mBAA/B,QAA0D,SAA1D;AACA,SACEC,OADF,QAEO,UAFP,C,CAGA;;AACA,SAASC,SAAT,QAA0B,UAA1B;AACA,SACEC,SAAS,IAAIC,gBADf,EACiCC,iBADjC,EACoDC,sBADpD,EAC4EC,QAD5E,QAEO,WAFP;AAGA,SACEJ,SAAS,IAAIK,kBADf,EACmCC,uBADnC,EAC4DC,qBAD5D,EACmFC,yBADnF,QAEO,aAFP;AAGA,SACEC,0BADF,EAEET,SAAS,IAAIU,aAFf,EAGEC,uBAHF,EAIEC,sBAJF,EAKEC,wBALF,EAMEC,oBANF,EAOEC,mBAPF,QAQO,QARP;AASA,SAASf,SAAS,IAAIgB,aAAtB,QAA2C,QAA3C;AACA,SACEC,sBADF,EAEEC,sBAFF,EAGEC,oBAHF,EAIEC,oBAJF,EAKEC,uBALF,EAMEC,yBANF,EAOEC,SAPF,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jDH;;AAAA;AAkDHhD,YAAAA,OAAO,CAACsB,oBAAD,CAAP,CAlDG,CAoDH;;AApDG;AAAA,mBAqDGkC,QAAQ,CAACP,KAAT,EArDH;;AAAA;AAsDHjD,YAAAA,OAAO,CAACyB,SAAD,CAAP;AAtDG;AAAA;;AAAA;AAAA;AAAA;;AAAA,gBAwDE,aAAMkC,aAxDR;AAAA;AAAA;AAAA;;AAAA;AAAA,mBA0DKH,QAAQ,CAACzB,SAAT,cA1DL;;AAAA;AA2DD/B,YAAAA,OAAO,CAAC0B,cAAD,eAAP;;AA3DC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G","sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform**\n *\n * The initialization module provides a function for managing an application's initialization\n * lifecycle. It also provides constants and default handler implementations.\n *\n * ```\n * import {\n * initialize,\n * APP_INIT_ERROR,\n * APP_READY,\n * subscribe,\n * } from '@edx/frontend-platform';\n * import { AppProvider, ErrorPage, PageRoute } from '@edx/frontend-platform/react';\n * import React from 'react';\n * import ReactDOM from 'react-dom';\n * import { Switch } from 'react-router-dom';\n *\n * subscribe(APP_READY, () => {\n * ReactDOM.render(\n * <AppProvider store={configureStore()}>\n * <Header />\n * <main>\n * <Switch>\n * <PageRoute exact path=\"/\" component={PaymentPage} />\n * </Switch>\n * </main>\n * <Footer />\n * </AppProvider>,\n * document.getElementById('root'),\n * );\n * });\n *\n * subscribe(APP_INIT_ERROR, (error) => {\n * ReactDOM.render(<ErrorPage message={error.message} />, document.getElementById('root'));\n * });\n *\n * initialize({\n * messages: [appMessages],\n * requireAuthenticatedUser: true,\n * hydrateAuthenticatedUser: true,\n * });\n\n```\n * @module Initialization\n */\n\nimport { createBrowserHistory, createMemoryHistory } from 'history';\nimport {\n publish,\n} from './pubSub';\n// eslint-disable-next-line import/no-cycle\nimport { getConfig } from './config';\nimport {\n configure as configureLogging, getLoggingService, NewRelicLoggingService, logError,\n} from './logging';\nimport {\n configure as configureAnalytics, SegmentAnalyticsService, identifyAnonymousUser, identifyAuthenticatedUser,\n} from './analytics';\nimport {\n getAuthenticatedHttpClient,\n configure as configureAuth,\n ensureAuthenticatedUser,\n fetchAuthenticatedUser,\n hydrateAuthenticatedUser,\n getAuthenticatedUser,\n AxiosJwtAuthService,\n} from './auth';\nimport { configure as configureI18n } from './i18n';\nimport {\n APP_PUBSUB_INITIALIZED,\n APP_CONFIG_INITIALIZED,\n APP_AUTH_INITIALIZED,\n APP_I18N_INITIALIZED,\n APP_LOGGING_INITIALIZED,\n APP_ANALYTICS_INITIALIZED,\n APP_READY, APP_INIT_ERROR,\n} from './constants';\n\n/**\n * A browser history or memory history object created by the [history](https://github.com/ReactTraining/history)\n * package. Applications are encouraged to use this history object, rather than creating their own,\n * as behavior may be undefined when managing history via multiple mechanisms/instances. Note that\n * in environments where browser history may be inaccessible due to `window` being undefined, this\n * falls back to memory history.\n */\nexport const history = (typeof window !== 'undefined')\n ? createBrowserHistory({\n basename: getConfig().PUBLIC_PATH,\n }) : createMemoryHistory();\n\n/**\n * The default handler for the initialization lifecycle's `initError` phase. Logs the error to the\n * LoggingService using `logError`\n *\n * @see {@link module:frontend-platform/logging~logError}\n * @param {*} error\n */\nexport async function initError(error) {\n logError(error);\n}\n\n/**\n * The default handler for the initialization lifecycle's `auth` phase.\n *\n * The handler has several responsibilities:\n * - Determining the user's authentication state (authenticated or anonymous)\n * - Optionally redirecting to login if the application requires an authenticated user.\n * - Optionally loading additional user information via the application's user account data\n * endpoint.\n *\n * @param {boolean} requireUser Whether or not we should redirect to login if a user is not\n * authenticated.\n * @param {boolean} hydrateUser Whether or not we should fetch additional user account data.\n */\nexport async function auth(requireUser, hydrateUser) {\n if (requireUser) {\n await ensureAuthenticatedUser(global.location.href);\n } else {\n await fetchAuthenticatedUser();\n }\n\n if (hydrateUser && getAuthenticatedUser() !== null) {\n // We intentionally do not await the promise returned by hydrateAuthenticatedUser. All the\n // critical data is returned as part of fetch/ensureAuthenticatedUser above, and anything else\n // is a nice-to-have for application code.\n hydrateAuthenticatedUser();\n }\n}\n\n/**\n * The default handler for the initialization lifecycle's `analytics` phase.\n *\n * The handler is responsible for identifying authenticated and anonymous users with the analytics\n * service. This is a pre-requisite for sending analytics events, thus, we do it during the\n * initialization sequence so that analytics is ready once the application's UI code starts to load.\n *\n */\nexport async function analytics() {\n const authenticatedUser = getAuthenticatedUser();\n if (authenticatedUser && authenticatedUser.userId) {\n identifyAuthenticatedUser(authenticatedUser.userId);\n } else {\n await identifyAnonymousUser();\n }\n}\n\nfunction applyOverrideHandlers(overrides) {\n const noOp = async () => { };\n return {\n pubSub: noOp,\n config: noOp,\n logging: noOp,\n auth,\n analytics,\n i18n: noOp,\n ready: noOp,\n initError,\n ...overrides, // This will override any same-keyed handlers from above.\n };\n}\n\n/**\n * Invokes the application initialization sequence.\n *\n * The sequence proceeds through a number of lifecycle phases, during which pertinent services are\n * configured.\n *\n * Using the `handlers` option, lifecycle phase handlers can be overridden to perform custom\n * functionality. Note that while these override handlers _do_ replace the default handler\n * functionality for analytics, auth, and initError (the other phases have no default\n * functionality), they do _not_ override the configuration of the actual services that those\n * handlers leverage.\n *\n * Some services can be overridden via the loggingService and analyticsService options. The other\n * services (auth and i18n) cannot currently be overridden.\n *\n * The following lifecycle phases exist:\n *\n * - pubSub: A no-op by default.\n * - config: A no-op by default.\n * - logging: A no-op by default.\n * - auth: Uses the 'auth' handler defined above.\n * - analytics: Uses the 'analytics' handler defined above.\n * - i18n: A no-op by default.\n * - ready: A no-op by default.\n * - initError: Uses the 'initError' handler defined above.\n *\n * @param {Object} [options]\n * @param {*} [options.loggingService=NewRelicLoggingService] The `LoggingService` implementation\n * to use.\n * @param {*} [options.analyticsService=SegmentAnalyticsService] The `AnalyticsService`\n * implementation to use.\n * @param {*} [options.requireAuthenticatedUser=false] If true, turns on automatic login\n * redirection for unauthenticated users. Defaults to false, meaning that by default the\n * application will allow anonymous/unauthenticated sessions.\n * @param {*} [options.hydrateAuthenticatedUser=false] If true, makes an API call to the user\n * account endpoint (`${App.config.LMS_BASE_URL}/api/user/v1/accounts/${username}`) to fetch\n * detailed account information for the authenticated user. This data is merged into the return\n * value of `getAuthenticatedUser`, overriding any duplicate keys that already exist. Defaults to\n * false, meaning that no additional account information will be loaded.\n * @param {*} [options.messages] A i18n-compatible messages object, or an array of such objects. If\n * an array is provided, duplicate keys are resolved with the last-one-in winning.\n * @param {*} [options.handlers={}] An optional object of handlers which can be used to replace the\n * default behavior of any part of the startup sequence. It can also be used to add additional\n * initialization behavior before or after the rest of the sequence.\n */\nexport async function initialize({\n loggingService = NewRelicLoggingService,\n analyticsService = SegmentAnalyticsService,\n authService = AxiosJwtAuthService,\n requireAuthenticatedUser: requireUser = false,\n hydrateAuthenticatedUser: hydrateUser = false,\n messages,\n handlers: overrideHandlers = {},\n}) {\n const handlers = applyOverrideHandlers(overrideHandlers);\n try {\n // Pub/Sub\n await handlers.pubSub();\n publish(APP_PUBSUB_INITIALIZED);\n\n // Configuration\n await handlers.config();\n publish(APP_CONFIG_INITIALIZED);\n\n // Logging\n configureLogging(loggingService, {\n config: getConfig(),\n });\n await handlers.logging();\n publish(APP_LOGGING_INITIALIZED);\n\n // Authentication\n configureAuth(authService, {\n loggingService: getLoggingService(),\n config: getConfig(),\n });\n await handlers.auth(requireUser, hydrateUser);\n publish(APP_AUTH_INITIALIZED);\n\n // Analytics\n configureAnalytics(analyticsService, {\n config: getConfig(),\n loggingService: getLoggingService(),\n httpClient: getAuthenticatedHttpClient(),\n });\n await handlers.analytics();\n publish(APP_ANALYTICS_INITIALIZED);\n\n // Internationalization\n configureI18n({\n messages,\n config: getConfig(),\n loggingService: getLoggingService(),\n });\n await handlers.i18n();\n publish(APP_I18N_INITIALIZED);\n\n // Application Ready\n await handlers.ready();\n publish(APP_READY);\n } catch (error) {\n if (!error.isRedirecting) {\n // Initialization Error\n await handlers.initError(error);\n publish(APP_INIT_ERROR, error);\n }\n }\n}\n"],"file":"initialize.js"}
|
|
1
|
+
{"version":3,"file":"initialize.js","names":["createBrowserHistory","createMemoryHistory","publish","getConfig","configure","configureLogging","getLoggingService","NewRelicLoggingService","logError","configureAnalytics","SegmentAnalyticsService","identifyAnonymousUser","identifyAuthenticatedUser","getAuthenticatedHttpClient","configureAuth","ensureAuthenticatedUser","fetchAuthenticatedUser","hydrateAuthenticatedUser","getAuthenticatedUser","AxiosJwtAuthService","configureI18n","APP_PUBSUB_INITIALIZED","APP_CONFIG_INITIALIZED","APP_AUTH_INITIALIZED","APP_I18N_INITIALIZED","APP_LOGGING_INITIALIZED","APP_ANALYTICS_INITIALIZED","APP_READY","APP_INIT_ERROR","history","window","basename","PUBLIC_PATH","initError","error","auth","requireUser","hydrateUser","global","location","href","analytics","authenticatedUser","userId","applyOverrideHandlers","overrides","noOp","pubSub","config","logging","i18n","ready","initialize","loggingService","analyticsService","authService","authMiddleware","requireAuthenticatedUser","messages","handlers","overrideHandlers","middleware","httpClient","isRedirecting"],"sources":["../src/initialize.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform**\n *\n * The initialization module provides a function for managing an application's initialization\n * lifecycle. It also provides constants and default handler implementations.\n *\n * ```\n * import {\n * initialize,\n * APP_INIT_ERROR,\n * APP_READY,\n * subscribe,\n * } from '@edx/frontend-platform';\n * import { AppProvider, ErrorPage, PageRoute } from '@edx/frontend-platform/react';\n * import React from 'react';\n * import ReactDOM from 'react-dom';\n * import { Switch } from 'react-router-dom';\n *\n * subscribe(APP_READY, () => {\n * ReactDOM.render(\n * <AppProvider store={configureStore()}>\n * <Header />\n * <main>\n * <Switch>\n * <PageRoute exact path=\"/\" component={PaymentPage} />\n * </Switch>\n * </main>\n * <Footer />\n * </AppProvider>,\n * document.getElementById('root'),\n * );\n * });\n *\n * subscribe(APP_INIT_ERROR, (error) => {\n * ReactDOM.render(<ErrorPage message={error.message} />, document.getElementById('root'));\n * });\n *\n * initialize({\n * messages: [appMessages],\n * requireAuthenticatedUser: true,\n * hydrateAuthenticatedUser: true,\n * });\n\n```\n * @module Initialization\n */\n\nimport { createBrowserHistory, createMemoryHistory } from 'history';\nimport {\n publish,\n} from './pubSub';\n// eslint-disable-next-line import/no-cycle\nimport { getConfig } from './config';\nimport {\n configure as configureLogging, getLoggingService, NewRelicLoggingService, logError,\n} from './logging';\nimport {\n configure as configureAnalytics, SegmentAnalyticsService, identifyAnonymousUser, identifyAuthenticatedUser,\n} from './analytics';\nimport {\n getAuthenticatedHttpClient,\n configure as configureAuth,\n ensureAuthenticatedUser,\n fetchAuthenticatedUser,\n hydrateAuthenticatedUser,\n getAuthenticatedUser,\n AxiosJwtAuthService,\n} from './auth';\nimport { configure as configureI18n } from './i18n';\nimport {\n APP_PUBSUB_INITIALIZED,\n APP_CONFIG_INITIALIZED,\n APP_AUTH_INITIALIZED,\n APP_I18N_INITIALIZED,\n APP_LOGGING_INITIALIZED,\n APP_ANALYTICS_INITIALIZED,\n APP_READY, APP_INIT_ERROR,\n} from './constants';\n\n/**\n * A browser history or memory history object created by the [history](https://github.com/ReactTraining/history)\n * package. Applications are encouraged to use this history object, rather than creating their own,\n * as behavior may be undefined when managing history via multiple mechanisms/instances. Note that\n * in environments where browser history may be inaccessible due to `window` being undefined, this\n * falls back to memory history.\n */\nexport const history = (typeof window !== 'undefined')\n ? createBrowserHistory({\n basename: getConfig().PUBLIC_PATH,\n }) : createMemoryHistory();\n\n/**\n * The default handler for the initialization lifecycle's `initError` phase. Logs the error to the\n * LoggingService using `logError`\n *\n * @see {@link module:frontend-platform/logging~logError}\n * @param {*} error\n */\nexport async function initError(error) {\n logError(error);\n}\n\n/**\n * The default handler for the initialization lifecycle's `auth` phase.\n *\n * The handler has several responsibilities:\n * - Determining the user's authentication state (authenticated or anonymous)\n * - Optionally redirecting to login if the application requires an authenticated user.\n * - Optionally loading additional user information via the application's user account data\n * endpoint.\n *\n * @param {boolean} requireUser Whether or not we should redirect to login if a user is not\n * authenticated.\n * @param {boolean} hydrateUser Whether or not we should fetch additional user account data.\n */\nexport async function auth(requireUser, hydrateUser) {\n if (requireUser) {\n await ensureAuthenticatedUser(global.location.href);\n } else {\n await fetchAuthenticatedUser();\n }\n\n if (hydrateUser && getAuthenticatedUser() !== null) {\n // We intentionally do not await the promise returned by hydrateAuthenticatedUser. All the\n // critical data is returned as part of fetch/ensureAuthenticatedUser above, and anything else\n // is a nice-to-have for application code.\n hydrateAuthenticatedUser();\n }\n}\n\n/**\n * The default handler for the initialization lifecycle's `analytics` phase.\n *\n * The handler is responsible for identifying authenticated and anonymous users with the analytics\n * service. This is a pre-requisite for sending analytics events, thus, we do it during the\n * initialization sequence so that analytics is ready once the application's UI code starts to load.\n *\n */\nexport async function analytics() {\n const authenticatedUser = getAuthenticatedUser();\n if (authenticatedUser && authenticatedUser.userId) {\n identifyAuthenticatedUser(authenticatedUser.userId);\n } else {\n await identifyAnonymousUser();\n }\n}\n\nfunction applyOverrideHandlers(overrides) {\n const noOp = async () => { };\n return {\n pubSub: noOp,\n config: noOp,\n logging: noOp,\n auth,\n analytics,\n i18n: noOp,\n ready: noOp,\n initError,\n ...overrides, // This will override any same-keyed handlers from above.\n };\n}\n\n/**\n * Invokes the application initialization sequence.\n *\n * The sequence proceeds through a number of lifecycle phases, during which pertinent services are\n * configured.\n *\n * Using the `handlers` option, lifecycle phase handlers can be overridden to perform custom\n * functionality. Note that while these override handlers _do_ replace the default handler\n * functionality for analytics, auth, and initError (the other phases have no default\n * functionality), they do _not_ override the configuration of the actual services that those\n * handlers leverage.\n *\n * Some services can be overridden via the loggingService and analyticsService options. The other\n * services (auth and i18n) cannot currently be overridden.\n *\n * The following lifecycle phases exist:\n *\n * - pubSub: A no-op by default.\n * - config: A no-op by default.\n * - logging: A no-op by default.\n * - auth: Uses the 'auth' handler defined above.\n * - analytics: Uses the 'analytics' handler defined above.\n * - i18n: A no-op by default.\n * - ready: A no-op by default.\n * - initError: Uses the 'initError' handler defined above.\n *\n * @param {Object} [options]\n * @param {*} [options.loggingService=NewRelicLoggingService] The `LoggingService` implementation\n * to use.\n * @param {*} [options.analyticsService=SegmentAnalyticsService] The `AnalyticsService`\n * implementation to use.\n * @param {*} [options.authMiddleware=[]] An array of middleware to apply to http clients in the auth service.\n * @param {*} [options.requireAuthenticatedUser=false] If true, turns on automatic login\n * redirection for unauthenticated users. Defaults to false, meaning that by default the\n * application will allow anonymous/unauthenticated sessions.\n * @param {*} [options.hydrateAuthenticatedUser=false] If true, makes an API call to the user\n * account endpoint (`${App.config.LMS_BASE_URL}/api/user/v1/accounts/${username}`) to fetch\n * detailed account information for the authenticated user. This data is merged into the return\n * value of `getAuthenticatedUser`, overriding any duplicate keys that already exist. Defaults to\n * false, meaning that no additional account information will be loaded.\n * @param {*} [options.messages] A i18n-compatible messages object, or an array of such objects. If\n * an array is provided, duplicate keys are resolved with the last-one-in winning.\n * @param {*} [options.handlers={}] An optional object of handlers which can be used to replace the\n * default behavior of any part of the startup sequence. It can also be used to add additional\n * initialization behavior before or after the rest of the sequence.\n */\nexport async function initialize({\n loggingService = NewRelicLoggingService,\n analyticsService = SegmentAnalyticsService,\n authService = AxiosJwtAuthService,\n authMiddleware = [],\n requireAuthenticatedUser: requireUser = false,\n hydrateAuthenticatedUser: hydrateUser = false,\n messages,\n handlers: overrideHandlers = {},\n}) {\n const handlers = applyOverrideHandlers(overrideHandlers);\n try {\n // Pub/Sub\n await handlers.pubSub();\n publish(APP_PUBSUB_INITIALIZED);\n\n // Configuration\n await handlers.config();\n publish(APP_CONFIG_INITIALIZED);\n\n // Logging\n configureLogging(loggingService, {\n config: getConfig(),\n });\n await handlers.logging();\n publish(APP_LOGGING_INITIALIZED);\n\n // Authentication\n configureAuth(authService, {\n loggingService: getLoggingService(),\n config: getConfig(),\n middleware: authMiddleware,\n });\n\n await handlers.auth(requireUser, hydrateUser);\n publish(APP_AUTH_INITIALIZED);\n\n // Analytics\n configureAnalytics(analyticsService, {\n config: getConfig(),\n loggingService: getLoggingService(),\n httpClient: getAuthenticatedHttpClient(),\n });\n await handlers.analytics();\n publish(APP_ANALYTICS_INITIALIZED);\n\n // Internationalization\n configureI18n({\n messages,\n config: getConfig(),\n loggingService: getLoggingService(),\n });\n await handlers.i18n();\n publish(APP_I18N_INITIALIZED);\n\n // Application Ready\n await handlers.ready();\n publish(APP_READY);\n } catch (error) {\n if (!error.isRedirecting) {\n // Initialization Error\n await handlers.initError(error);\n publish(APP_INIT_ERROR, error);\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,oBAAT,EAA+BC,mBAA/B,QAA0D,SAA1D;AACA,SACEC,OADF,QAEO,UAFP,C,CAGA;;AACA,SAASC,SAAT,QAA0B,UAA1B;AACA,SACEC,SAAS,IAAIC,gBADf,EACiCC,iBADjC,EACoDC,sBADpD,EAC4EC,QAD5E,QAEO,WAFP;AAGA,SACEJ,SAAS,IAAIK,kBADf,EACmCC,uBADnC,EAC4DC,qBAD5D,EACmFC,yBADnF,QAEO,aAFP;AAGA,SACEC,0BADF,EAEET,SAAS,IAAIU,aAFf,EAGEC,uBAHF,EAIEC,sBAJF,EAKEC,wBALF,EAMEC,oBANF,EAOEC,mBAPF,QAQO,QARP;AASA,SAASf,SAAS,IAAIgB,aAAtB,QAA2C,QAA3C;AACA,SACEC,sBADF,EAEEC,sBAFF,EAGEC,oBAHF,EAIEC,oBAJF,EAKEC,uBALF,EAMEC,yBANF,EAOEC,SAPF,EAOaC,cAPb,QAQO,aARP;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,OAAO,GAAI,OAAOC,MAAP,KAAkB,WAAnB,GACnB9B,oBAAoB,CAAC;EACrB+B,QAAQ,EAAE5B,SAAS,GAAG6B;AADD,CAAD,CADD,GA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AA;EAAA,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"MockLoggingService.js","names":["MockLoggingService","jest","fn"],"sources":["../../src/logging/MockLoggingService.js"],"sourcesContent":["/**\n * The MockLoggingService implements both logInfo and logError as jest mock functions via\n * jest.fn(). It has no other functionality.\n *\n * @implements {LoggingService}\n * @memberof module:Logging\n */\nclass MockLoggingService {\n /**\n * Implemented as a jest.fn()\n *\n * @memberof MockLoggingService\n */\n logInfo = jest.fn();\n\n /**\n * Implemented as a jest.fn()\n *\n * @memberof MockLoggingService\n */\n logError = jest.fn();\n}\n\nexport default MockLoggingService;\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;IACMA,kB;;;mCAMMC,IAAI,CAACC,EAAL,E;;oCAOCD,IAAI,CAACC,EAAL,E;;;AAGb,eAAeF,kBAAf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"NewRelicLoggingService.js","names":["MAX_ERROR_LENGTH","fixErrorLength","error","message","length","processedError","Object","create","substring","pageActionNameInfo","pageActionNameIgnoredError","sendPageAction","actionName","customAttributes","process","env","NODE_ENV","console","log","window","newrelic","addPageAction","sendError","noticeError","NewRelicLoggingService","options","config","undefined","ignoredErrorRegexes","IGNORED_ERROR_REGEX","infoStringOrErrorObject","customAttrs","infoCustomAttributes","errorStringOrObject","errorCustomAttributes","allCustomAttributes","keys","errorMessage","match"],"sources":["../../src/logging/NewRelicLoggingService.js"],"sourcesContent":["/**\n * NewRelic will not log an error if it is too long.\n *\n * @ignore\n */\nexport const MAX_ERROR_LENGTH = 4000;\n\nfunction fixErrorLength(error) {\n if (error.message && error.message.length > MAX_ERROR_LENGTH) {\n const processedError = Object.create(error);\n processedError.message = processedError.message.substring(0, MAX_ERROR_LENGTH);\n return processedError;\n }\n if (typeof error === 'string' && error.length > MAX_ERROR_LENGTH) {\n return error.substring(0, MAX_ERROR_LENGTH);\n }\n return error;\n}\n\n/* Constants used as New Relic page action names. */\nconst pageActionNameInfo = 'INFO';\nconst pageActionNameIgnoredError = 'IGNORED_ERROR';\n\nfunction sendPageAction(actionName, message, customAttributes) {\n if (process.env.NODE_ENV === 'development') {\n console.log(message, customAttributes); // eslint-disable-line\n }\n if (window && typeof window.newrelic !== 'undefined') {\n window.newrelic.addPageAction(actionName, { message, ...customAttributes });\n }\n}\n\nfunction sendError(error, customAttributes) {\n if (process.env.NODE_ENV === 'development') {\n console.error(error, customAttributes); // eslint-disable-line\n }\n if (window && typeof window.newrelic !== 'undefined') {\n window.newrelic.noticeError(fixErrorLength(error), customAttributes);\n }\n}\n\n/**\n * The NewRelicLoggingService is a concrete implementation of the logging service interface that\n * sends messages to NewRelic that can be seen in NewRelic Browser and NewRelic Insights. When in\n * development mode, all messages will instead be sent to the console.\n *\n * When you use `logError`, your errors will be checked to see if they're ignored *or* not.\n * Not-ignored errors will appear under \"JS errors\" for your Browser application.\n *\n * ```\n * SELECT * from JavaScriptError WHERE errorStatus is not null SINCE 10 days ago\n * ```\n *\n * Ignored errors will appear in New Relic Insights as page actions, which can be queried:\n *\n * ```\n * SELECT * from PageAction WHERE actionName = 'IGNORED_ERROR' SINCE 1 hour ago\n * ```\n *\n * When using `logInfo`, these only appear in New Relic Insights when querying for page actions as\n * follows:\n *\n * ```\n * SELECT * from PageAction WHERE actionName = 'INFO' SINCE 1 hour ago\n * ```\n *\n * You can also add your own custom metrics as an additional argument, or see the code to find\n * other standard custom attributes.\n *\n * Requires the NewRelic Browser JavaScript snippet.\n *\n * @implements {LoggingService}\n * @memberof module:Logging\n */\nexport default class NewRelicLoggingService {\n constructor(options) {\n const config = options ? options.config : undefined;\n /*\n String which is an explicit error message regex. If an error message matches the regex, the error\n is considered an *ignored* error and submitted to New Relic as a page action - not an error.\n\n Ignored error regexes are configured per frontend application (MFE).\n\n The regex for all ignored errors are represented in the .env files as a single string. If you need to\n ignore multiple errors, use the standard `|` regex syntax.\n\n For example, here's a .env line which ignores two specific errors:\n\n IGNORED_ERROR_REGEX='^\\\\[frontend-auth\\\\] Unimportant Error|Specific non-critical error #[\\\\d]+'\n\n This example would ignore errors with the following messages:\n\n [frontend-app-generic] - Specific non-critical error #45678 happened.\n [frontend-app-generic] - Specific non-critical error #93475 happened.\n [frontend-auth] Unimportant Error: Browser strangeness occurred.\n\n To test your regex additions, use a JS CLI environment (such as node) and run code like this:\n\n x = new RegExp('^\\\\[frontend-auth\\\\] Unimportant Error|Specific non-critical error #[\\\\d]+');\n '[frontend-app-generic] - Specific non-critical error #45678 happened.'.match(x);\n '[frontend-auth] Unimportant Error: Browser strangeness occurred.'.match(x);\n 'This error should not match anything!'.match(x);\n\n For edx.org, add new error message regexes in edx-internal YAML as needed.\n */\n this.ignoredErrorRegexes = config ? config.IGNORED_ERROR_REGEX : undefined;\n }\n\n /**\n *\n *\n * @param {*} infoStringOrErrorObject\n * @param {*} [customAttributes={}]\n * @memberof NewRelicLoggingService\n */\n logInfo(infoStringOrErrorObject, customAttributes = {}) {\n let message = infoStringOrErrorObject;\n let customAttrs = customAttributes;\n if (typeof infoStringOrErrorObject === 'object' && 'message' in infoStringOrErrorObject) {\n /* Caller has passed in an error object to be logged as a page action. */\n /* Extract the attributes and the message. */\n const infoCustomAttributes = infoStringOrErrorObject.customAttributes || {};\n customAttrs = { ...infoCustomAttributes, ...customAttributes };\n message = infoStringOrErrorObject.message;\n }\n sendPageAction(pageActionNameInfo, message, customAttrs);\n }\n\n /**\n *\n *\n * @param {*} errorStringOrObject\n * @param {*} [customAttributes={}]\n * @memberof NewRelicLoggingService\n */\n logError(errorStringOrObject, customAttributes = {}) {\n const errorCustomAttributes = errorStringOrObject.customAttributes || {};\n let allCustomAttributes = { ...errorCustomAttributes, ...customAttributes };\n if (Object.keys(allCustomAttributes).length === 0) {\n // noticeError expects undefined if there are no custom attributes.\n allCustomAttributes = undefined;\n }\n\n /*\n Separate the errors into ignored errors and other errors.\n Ignored errors are logged via adding a page action.\n Other errors are logged via noticeError and count as \"JS Errors\" for the application.\n */\n const errorMessage = errorStringOrObject.message || (typeof errorStringOrObject === 'string' ? errorStringOrObject : '');\n if (this.ignoredErrorRegexes && errorMessage.match(this.ignoredErrorRegexes)) {\n /* ignored error */\n sendPageAction(pageActionNameIgnoredError, errorMessage, allCustomAttributes);\n } else {\n /* error! */\n sendError(errorStringOrObject, allCustomAttributes);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMA,gBAAgB,GAAG,IAAzB;;AAEP,SAASC,cAAT,CAAwBC,KAAxB,EAA+B;EAC7B,IAAIA,KAAK,CAACC,OAAN,IAAiBD,KAAK,CAACC,OAAN,CAAcC,MAAd,GAAuBJ,gBAA5C,EAA8D;IAC5D,IAAMK,cAAc,GAAGC,MAAM,CAACC,MAAP,CAAcL,KAAd,CAAvB;IACAG,cAAc,CAACF,OAAf,GAAyBE,cAAc,CAACF,OAAf,CAAuBK,SAAvB,CAAiC,CAAjC,EAAoCR,gBAApC,CAAzB;IACA,OAAOK,cAAP;EACD;;EACD,IAAI,OAAOH,KAAP,KAAiB,QAAjB,IAA6BA,KAAK,CAACE,MAAN,GAAeJ,gBAAhD,EAAkE;IAChE,OAAOE,KAAK,CAACM,SAAN,CAAgB,CAAhB,EAAmBR,gBAAnB,CAAP;EACD;;EACD,OAAOE,KAAP;AACD;AAED;;;AACA,IAAMO,kBAAkB,GAAG,MAA3B;AACA,IAAMC,0BAA0B,GAAG,eAAnC;;AAEA,SAASC,cAAT,CAAwBC,UAAxB,EAAoCT,OAApC,EAA6CU,gBAA7C,EAA+D;EAC7D,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,aAA7B,EAA4C;IAC1CC,OAAO,CAACC,GAAR,CAAYf,OAAZ,EAAqBU,gBAArB,EAD0C,CACF;EACzC;;EACD,IAAIM,MAAM,IAAI,OAAOA,MAAM,CAACC,QAAd,KAA2B,WAA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,GAAGF,uBAAuB,CAACjB,gBAAxB,IAA4C,EAAzE;QACAkB,WAAW,mCAAQC,oBAAR,GAAiCnB,gBAAjC,CAAX;QACAV,OAAO,GAAG2B,uBAAuB,CAAC3B,OAAlC;MACD;;MACDQ,cAAc,CAACF,kBAAD,EAAqBN,OAArB,EAA8B4B,WAA9B,CAAd;IACD;IAED;AACF;AACA;AACA;AACA;AACA;AACA;;;;WACE,kBAASE,mBAAT,EAAqD;MAAA,IAAvBpB,gBAAuB,uEAAJ,EAAI;MACnD,IAAMqB,qBAAqB,GAAGD,mBAAmB,CAACpB,gBAApB,IAAwC,EAAtE;;MACA,IAAIsB,mBAAmB,mCAAQD,qBAAR,GAAkCrB,gBAAlC,CAAvB;;MACA,IAAIP,MAAM,CAAC8B,IAAP,CAAYD,mBAAZ,EAAiC/B,MAAjC,KAA4C,CAAhD,EAAmD;QACjD;QACA+B,mBAAmB,GAAGR,SAAtB;MACD;MAED;AACJ;AACA;AACA;AACA;;;MACI,IAAMU,YAAY,GAAGJ,mBAAmB,CAAC9B,OAApB,KAAgC,OAAO8B,mBAAP,KAA+B,QAA/B,GAA0CA,mBAA1C,GAAgE,EAAhG,CAArB;;MACA,IAAI,KAAKL,mBAAL,IAA4BS,YAAY,CAACC,KAAb,CAAmB,KAAKV,mBAAxB,CAAhC,EAA8E;QAC5E;QACAjB,cAAc,CAACD,0BAAD,EAA6B2B,YAA7B,EAA2CF,mBAA3C,CAAd;MACD,CAHD,MAGO;QACL;QACAb,SAAS,CAACW,mBAAD,EAAsBE,mBAAtB,CAAT;MACD;IACF;;;;;;SAlFkBX,sB"}
|
package/logging/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["getLoggingService","resetLoggingService","configure","logInfo","logError","default","NewRelicLoggingService","MockLoggingService"],"sources":["../../src/logging/index.js"],"sourcesContent":["export {\n getLoggingService,\n resetLoggingService,\n configure,\n logInfo,\n logError,\n} from './interface';\nexport { default as NewRelicLoggingService } from './NewRelicLoggingService';\nexport { default as MockLoggingService } from './MockLoggingService';\n"],"mappings":"AAAA,SACEA,iBADF,EAEEC,mBAFF,EAGEC,SAHF,EAIEC,OAJF,EAKEC,QALF,QAMO,aANP;AAOA,SAASC,OAAO,IAAIC,sBAApB,QAAkD,0BAAlD;AACA,SAASD,OAAO,IAAIE,kBAApB,QAA8C,sBAA9C"}
|
package/logging/interface.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"interface.js","names":["PropTypes","optionsShape","config","object","isRequired","serviceShape","logInfo","func","logError","service","configure","LoggingService","options","checkPropTypes","infoStringOrErrorObject","customAttributes","errorStringOrObject","getLoggingService","Error","resetLoggingService"],"sources":["../../src/logging/interface.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform/logging**\n *\n * Contains a shared interface for logging information. (The default implementation is in\n * NewRelicLoggingService.js.) When in development mode, all messages will instead be sent to the console.\n *\n * The `initialize` function performs much of the logging configuration for you. If, however,\n * you're not using the `initialize` function, logging (via New Relic) can be configured via:\n *\n * ```\n * import { configure, NewRelicLoggingService, logInfo, logError } from '@edx/frontend-platform/logging';\n * import { geConfig } from '@edx/frontend-platform';\n *\n * configureLogging(NewRelicLoggingService, {\n * config: getConfig(),\n * });\n *\n * logInfo('Just so you know...');\n * logInfo(new Error('Unimportant error'), { type: 'unimportant' });\n * logError('Uhoh!');\n * logError(new Error('Uhoh error!'));\n * ```\n *\n * As shown in this example, logging depends on the configuration document.\n *\n * @module Logging\n */\n\nimport PropTypes from 'prop-types';\n\nconst optionsShape = {\n config: PropTypes.object.isRequired,\n};\n\nconst serviceShape = {\n logInfo: PropTypes.func.isRequired,\n logError: PropTypes.func.isRequired,\n};\n\nlet service = null;\n\n/**\n *\n */\nexport function configure(LoggingService, options) {\n PropTypes.checkPropTypes(optionsShape, options, 'property', 'Logging');\n service = new LoggingService(options);\n PropTypes.checkPropTypes(serviceShape, service, 'property', 'LoggingService');\n return service;\n}\n\n/**\n * Logs a message to the 'info' log level. Can accept custom attributes as a property of the error\n * object, or as an optional second parameter.\n *\n * @param {string|Error} infoStringOrErrorObject\n * @param {Object} [customAttributes={}]\n */\nexport function logInfo(infoStringOrErrorObject, customAttributes) {\n return service.logInfo(infoStringOrErrorObject, customAttributes);\n}\n\n/**\n * Logs a message to the 'error' log level. Can accept custom attributes as a property of the error\n * object, or as an optional second parameter.\n *\n * @param {string|Error} errorStringOrObject\n * @param {Object} [customAttributes={}]\n */\nexport function logError(errorStringOrObject, customAttributes) {\n return service.logError(errorStringOrObject, customAttributes);\n}\n\n/**\n *\n * @throws {Error} Thrown if the logging service has not yet been configured via {@link configure}.\n * @returns {LoggingService}\n */\nexport function getLoggingService() {\n if (!service) {\n throw Error('You must first configure the logging service.');\n }\n return service;\n}\n\n/**\n * Sets the configured logging service back to null.\n *\n */\nexport function resetLoggingService() {\n service = null;\n}\n\n/**\n * @name LoggingService\n * @interface\n * @memberof module:Logging\n * @property {function} logError\n * @property {function} logInfo\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;AAEA,OAAOA,SAAP,MAAsB,YAAtB;AAEA,IAAMC,YAAY,GAAG;EACnBC,MAAM,EAAEF,SAAS,CAACG,MAAV,CAAiBC;AADN,CAArB;AAIA,IAAMC,YAAY,GAAG;EACnBC,OAAO,EAAEN,SAAS,CAACO,IAAV,CAAeH,UADL;EAEnBI,QAAQ,EAAER,SAAS,CAACO,IAAV,CAAeH;AAFN,CAArB;AAKA,IAAIK,OAAO,GAAG,IAAd;AAEA;AACA;AACA;;AACA,OAAO,SAASC,SAAT,CAAmBC,cAAnB,EAAmCC,OAAnC,EAA4C;EACjDZ,SAAS,CAACa,cAAV,CAAyBZ,YAAzB,EAAuCW,OAAvC,EAAgD,UAAhD,EAA4D,SAA5D;EACAH,OAAO,GAAG,IAAIE,cAAJ,CAAmBC,OAAnB,CAAV;EACAZ,SAAS,CAACa,cAAV,CAAyBR,YAAzB,EAAuCI,OAAvC,EAAgD,UAAhD,EAA4D,gBAA5D;EACA,OAAOA,OAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASH,OAAT,CAAiBQ,uBAAjB,EAA0CC,gBAA1C,EAA4D;EACjE,OAAON,OAAO,CAACH,OAAR,CAAgBQ,uBAAhB,EAAyCC,gBAAzC,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASP,QAAT,CAAkBQ,mBAAlB,EAAuCD,gBAAvC,EAAyD;EAC9D,OAAON,OAAO,CAACD,QAAR,CAAiBQ,mBAAjB,EAAsCD,gBAAtC,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,iBAAT,GAA6B;EAClC,IAAI,CAACR,OAAL,EAAc;IACZ,MAAMS,KAAK,CAAC,+CAAD,CAAX;EACD;;EACD,OAAOT,OAAP;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASU,mBAAT,GAA+B;EACpCV,OAAO,GAAG,IAAV;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edx/frontend-platform",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Foundational application framework for Open edX micro-frontend applications.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
"test:watch": "npm run test -- --watch"
|
|
19
19
|
},
|
|
20
20
|
"bin": {
|
|
21
|
-
"transifex-utils.js": "i18n/scripts/transifex-utils.js"
|
|
22
|
-
"transifex-Makefile": "i18n/scripts/Makefile"
|
|
21
|
+
"transifex-utils.js": "i18n/scripts/transifex-utils.js"
|
|
23
22
|
},
|
|
24
23
|
"repository": {
|
|
25
24
|
"type": "git",
|
|
@@ -33,8 +32,8 @@
|
|
|
33
32
|
"homepage": "https://github.com/edx/frontend-platform#readme",
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"@edx/brand": "npm:@edx/brand-openedx@1.1.0",
|
|
36
|
-
"@edx/frontend-build": "9.
|
|
37
|
-
"@edx/paragon": "19.
|
|
35
|
+
"@edx/frontend-build": "9.2.2",
|
|
36
|
+
"@edx/paragon": "19.20.0",
|
|
38
37
|
"axios-mock-adapter": "1.20.0",
|
|
39
38
|
"codecov": "3.8.3",
|
|
40
39
|
"core-js": "3.21.1",
|
package/pubSub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"pubSub.js","names":["PubSub","subscribe","type","callback","unsubscribe","token","publish","data"],"sources":["../src/pubSub.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform**\n *\n * The PubSub module is a thin wrapper around the base functionality of\n * [PubSubJS](https://github.com/mroderick/PubSubJS). For the sake of simplicity and not relying\n * too heavily on implementation-specific features, it maintains a fairly simple API (subscribe,\n * unsubscribe, and publish).\n *\n * Publish/Subscribe events should be used mindfully, especially in relation to application UI\n * frameworks like React. Given React's unidirectional data flow and prop/state management\n * capabilities, using a pub/sub mechanism is at odds with that framework's best practices.\n *\n * That said, we use pub/sub in our application initialization sequence to allow applications to\n * hook into the initialization lifecycle, and we also use them to publish when the application\n * state has changed, i.e., when the config document or user's authentication state have changed.\n *\n * @module PubSub\n */\n\nimport PubSub from 'pubsub-js';\n\n/**\n *\n * @param {string} type\n * @param {function} callback\n * @returns {string} A subscription token that can be passed to `unsubscribe`\n */\nexport function subscribe(type, callback) {\n return PubSub.subscribe(type, callback);\n}\n\n/**\n *\n * @param {string} token A subscription token provided by `subscribe`\n */\nexport function unsubscribe(token) {\n return PubSub.unsubscribe(token);\n}\n\n/**\n *\n * @param {string} type\n * @param {Object} data\n */\nexport function publish(type, data) {\n return PubSub.publish(type, data);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,MAAP,MAAmB,WAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,SAAT,CAAmBC,IAAnB,EAAyBC,QAAzB,EAAmC;EACxC,OAAOH,MAAM,CAACC,SAAP,CAAiBC,IAAjB,EAAuBC,QAAvB,CAAP;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASC,WAAT,CAAqBC,KAArB,EAA4B;EACjC,OAAOL,MAAM,CAACI,WAAP,CAAmBC,KAAnB,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,OAAT,CAAiBJ,IAAjB,EAAuBK,IAAvB,EAA6B;EAClC,OAAOP,MAAM,CAACM,OAAP,CAAeJ,IAAf,EAAqBK,IAArB,CAAP;AACD"}
|
package/react/AppContext.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"AppContext.js","names":["React","AppContext","createContext","authenticatedUser","config"],"sources":["../../src/react/AppContext.jsx"],"sourcesContent":["import React from 'react';\n\n/**\n * `AppContext` provides data from `App` in a way that React components can readily consume, even\n * if it's mutable data. `AppContext` contains the following data structure:\n *\n * ```\n * {\n * authenticatedUser: <THE App.authenticatedUser OBJECT>,\n * config: <THE App.config OBJECT>\n * }\n * ```\n * If the `App.authenticatedUser` or `App.config` data changes, `AppContext` will be updated\n * accordingly and pass those changes onto React components using the context.\n *\n * `AppContext` is used in a React application like any other `[React Context](https://reactjs.org/docs/context.html)\n * @memberof module:React\n */\nconst AppContext = React.createContext({\n authenticatedUser: null,\n config: {},\n});\n\nexport default AppContext;\n"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,UAAU,gBAAGD,KAAK,CAACE,aAAN,CAAoB;EACrCC,iBAAiB,EAAE,IADkB;EAErCC,MAAM,EAAE;AAF6B,CAApB,CAAnB;AAKA,eAAeH,UAAf"}
|
package/react/AppProvider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"AppProvider.js","names":["React","useState","PropTypes","Router","OptionalReduxProvider","ErrorBoundary","AppContext","useAppEvent","getAuthenticatedUser","AUTHENTICATED_USER_CHANGED","getConfig","CONFIG_CHANGED","history","getLocale","getMessages","IntlProvider","LOCALE_CHANGED","AppProvider","store","children","config","setConfig","authenticatedUser","setAuthenticatedUser","locale","setLocale","propTypes","object","node","isRequired","defaultProps"],"sources":["../../src/react/AppProvider.jsx"],"sourcesContent":["import React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport { Router } from 'react-router-dom';\n\nimport OptionalReduxProvider from './OptionalReduxProvider';\n\nimport ErrorBoundary from './ErrorBoundary';\nimport AppContext from './AppContext';\nimport { useAppEvent } from './hooks';\nimport { getAuthenticatedUser, AUTHENTICATED_USER_CHANGED } from '../auth';\nimport { getConfig } from '../config';\nimport { CONFIG_CHANGED } from '../constants';\nimport { history } from '../initialize';\nimport {\n getLocale,\n getMessages,\n IntlProvider,\n LOCALE_CHANGED,\n} from '../i18n';\n\n/**\n * A wrapper component for React-based micro-frontends to initialize a number of common data/\n * context providers.\n *\n * ```\n * subscribe(APP_READY, () => {\n * ReactDOM.render(\n * <AppProvider>\n * <HelloWorld />\n * </AppProvider>\n * )\n * });\n * ```\n *\n * This will provide the following to HelloWorld:\n * - An error boundary as described above.\n * - An `AppContext` provider for React context data.\n * - IntlProvider for @edx/frontend-i18n internationalization\n * - Optionally a redux `Provider`. Will only be included if a `store` property is passed to\n * `AppProvider`.\n * - A `Router` for react-router.\n *\n * @param {Object} props\n * @param {Object} [props.store] A redux store.\n * @memberof module:React\n */\nexport default function AppProvider({ store, children }) {\n const [config, setConfig] = useState(getConfig());\n const [authenticatedUser, setAuthenticatedUser] = useState(getAuthenticatedUser());\n const [locale, setLocale] = useState(getLocale());\n\n useAppEvent(AUTHENTICATED_USER_CHANGED, () => {\n setAuthenticatedUser(getAuthenticatedUser());\n });\n\n useAppEvent(CONFIG_CHANGED, () => {\n setConfig(getConfig());\n });\n\n useAppEvent(LOCALE_CHANGED, () => {\n setLocale(getLocale());\n });\n\n return (\n <IntlProvider locale={locale} messages={getMessages()}>\n <ErrorBoundary>\n <AppContext.Provider\n value={{ authenticatedUser, config, locale }}\n >\n <OptionalReduxProvider store={store}>\n <Router history={history}>\n <>{children}</>\n </Router>\n </OptionalReduxProvider>\n </AppContext.Provider>\n </ErrorBoundary>\n </IntlProvider>\n );\n}\n\nAppProvider.propTypes = {\n // eslint-disable-next-line react/forbid-prop-types\n store: PropTypes.object,\n children: PropTypes.node.isRequired,\n};\n\nAppProvider.defaultProps = {\n store: null,\n};\n"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,KAAP,IAAgBC,QAAhB,QAAgC,OAAhC;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SAASC,MAAT,QAAuB,kBAAvB;AAEA,OAAOC,qBAAP,MAAkC,yBAAlC;AAEA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,UAAP,MAAuB,cAAvB;AACA,SAASC,WAAT,QAA4B,SAA5B;AACA,SAASC,oBAAT,EAA+BC,0BAA/B,QAAiE,SAAjE;AACA,SAASC,SAAT,QAA0B,WAA1B;AACA,SAASC,cAAT,QAA+B,cAA/B;AACA,SAASC,OAAT,QAAwB,eAAxB;AACA,SACEC,SADF,EAEEC,WAFF,EAGEC,YAHF,EAIEC,cAJF,QAKO,SALP;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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