@edx/frontend-platform 4.1.0 → 4.3.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/README.md +9 -9
- package/analytics/MockAnalyticsService.js.map +1 -1
- package/analytics/SegmentAnalyticsService.js.map +1 -1
- package/auth/AxiosCsrfTokenService.js.map +1 -1
- package/auth/AxiosJwtAuthService.js +5 -0
- 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.map +1 -1
- package/auth/interceptors/createCsrfTokenProviderInterceptor.js.map +1 -1
- package/auth/interceptors/createJwtTokenProviderInterceptor.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/i18n/countries.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/intl-imports.js.map +1 -1
- package/i18n/scripts/transifex-utils.js.map +1 -1
- package/initialize.js +41 -29
- package/initialize.js.map +1 -1
- package/logging/MockLoggingService.js +6 -0
- package/logging/MockLoggingService.js.map +1 -1
- package/logging/NewRelicLoggingService.js +27 -2
- package/logging/NewRelicLoggingService.js.map +1 -1
- package/logging/interface.js +10 -0
- package/logging/interface.js.map +1 -1
- package/package.json +6 -6
- 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/OptionalReduxProvider.js.map +1 -1
- package/react/PageRoute.js.map +1 -1
- package/scripts/GoogleAnalyticsLoader.js +57 -0
- package/scripts/GoogleAnalyticsLoader.js.map +1 -0
- package/scripts/index.js +3 -0
- package/scripts/index.js.map +1 -0
- package/testing/initializeMockApp.js.map +1 -1
- package/utils.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorBoundary.js","names":["React","Component","PropTypes","logError","ErrorPage","ErrorBoundary","_Component","_inherits","_super","_createSuper","props","_this","_classCallCheck","call","state","hasError","_createClass","key","value","componentDidCatch","error","info","stack","componentStack","render","createElement","children","getDerivedStateFromError","default","propTypes","node","defaultProps"],"sources":["../../src/react/ErrorBoundary.jsx"],"sourcesContent":["import React, { Component } from 'react';\nimport PropTypes from 'prop-types';\n\nimport { logError } from '../logging';\n\nimport ErrorPage from './ErrorPage';\n\n/**\n * Error boundary component used to log caught errors and display the error page.\n *\n * @memberof module:React\n * @extends {Component}\n */\nexport default class ErrorBoundary extends Component {\n constructor(props) {\n super(props);\n this.state = { hasError: false };\n }\n\n static getDerivedStateFromError() {\n // Update state so the next render will show the fallback UI.\n return { hasError: true };\n }\n\n componentDidCatch(error, info) {\n logError(error, { stack: info.componentStack });\n }\n\n render() {\n if (this.state.hasError) {\n return <ErrorPage />;\n }\n\n return this.props.children;\n }\n}\n\nErrorBoundary.propTypes = {\n children: PropTypes.node,\n};\n\nErrorBoundary.defaultProps = {\n children: null,\n};\n"],"mappings":";;;;;;;;;;;;;AAAA,OAAOA,KAAK,IAAIC,SAAS,QAAQ,OAAO;AACxC,OAAOC,SAAS,MAAM,YAAY;AAElC,SAASC,QAAQ,QAAQ,YAAY;AAErC,OAAOC,SAAS,MAAM,aAAa;;AAEnC;AACA;AACA;AACA;AACA;AACA;AALA,IAMqBC,aAAa,0BAAAC,UAAA;EAAAC,SAAA,CAAAF,aAAA,EAAAC,UAAA;EAAA,IAAAE,MAAA,GAAAC,YAAA,CAAAJ,aAAA;EAChC,SAAAA,cAAYK,KAAK,EAAE;IAAA,IAAAC,KAAA;IAAAC,eAAA,OAAAP,aAAA;IACjBM,KAAA,GAAAH,MAAA,CAAAK,IAAA,OAAMH,KAAK;IACXC,KAAA,CAAKG,KAAK,GAAG;MAAEC,QAAQ,EAAE;IAAM,CAAC;IAAC,OAAAJ,KAAA;EACnC;EAACK,YAAA,CAAAX,aAAA;IAAAY,GAAA;IAAAC,KAAA,EAOD,SAAAC,kBAAkBC,KAAK,EAAEC,IAAI,EAAE;MAC7BlB,QAAQ,CAACiB,KAAK,EAAE;QAAEE,KAAK,EAAED,IAAI,CAACE;MAAe,CAAC,CAAC;IACjD;EAAC;IAAAN,GAAA;IAAAC,KAAA,EAED,SAAAM,OAAA,EAAS;MACP,IAAI,IAAI,CAACV,KAAK,CAACC,QAAQ,EAAE;QACvB,oBAAOf,KAAA,CAAAyB,aAAA,CAACrB,SAAS,
|
|
1
|
+
{"version":3,"file":"ErrorBoundary.js","names":["React","Component","PropTypes","logError","ErrorPage","ErrorBoundary","_Component","_inherits","_super","_createSuper","props","_this","_classCallCheck","call","state","hasError","_createClass","key","value","componentDidCatch","error","info","stack","componentStack","render","createElement","children","getDerivedStateFromError","default","propTypes","node","defaultProps"],"sources":["../../src/react/ErrorBoundary.jsx"],"sourcesContent":["import React, { Component } from 'react';\nimport PropTypes from 'prop-types';\n\nimport { logError } from '../logging';\n\nimport ErrorPage from './ErrorPage';\n\n/**\n * Error boundary component used to log caught errors and display the error page.\n *\n * @memberof module:React\n * @extends {Component}\n */\nexport default class ErrorBoundary extends Component {\n constructor(props) {\n super(props);\n this.state = { hasError: false };\n }\n\n static getDerivedStateFromError() {\n // Update state so the next render will show the fallback UI.\n return { hasError: true };\n }\n\n componentDidCatch(error, info) {\n logError(error, { stack: info.componentStack });\n }\n\n render() {\n if (this.state.hasError) {\n return <ErrorPage />;\n }\n\n return this.props.children;\n }\n}\n\nErrorBoundary.propTypes = {\n children: PropTypes.node,\n};\n\nErrorBoundary.defaultProps = {\n children: null,\n};\n"],"mappings":";;;;;;;;;;;;;AAAA,OAAOA,KAAK,IAAIC,SAAS,QAAQ,OAAO;AACxC,OAAOC,SAAS,MAAM,YAAY;AAElC,SAASC,QAAQ,QAAQ,YAAY;AAErC,OAAOC,SAAS,MAAM,aAAa;;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PropTypes","Button","Container","Row","Col","useAppEvent","FormattedMessage","IntlProvider","getMessages","getLocale","LOCALE_CHANGED","ErrorPage","_ref","message","_useState","_useState2","_slicedToArray","locale","setLocale","reload","global","location","createElement","messages","fluid","className","id","defaultMessage","description","role","onClick","propTypes","string","defaultProps"],"sources":["../../src/react/ErrorPage.jsx"],"sourcesContent":["import React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport {\n Button, Container, Row, Col,\n} from '@edx/paragon';\n\nimport { useAppEvent } from './hooks';\nimport {\n FormattedMessage,\n IntlProvider,\n getMessages,\n getLocale,\n LOCALE_CHANGED,\n} from '../i18n';\n\n/**\n * An error page that displays a generic message for unexpected errors. Also contains a \"Try\n * Again\" button to refresh the page.\n *\n * @memberof module:React\n * @extends {Component}\n */\nfunction ErrorPage({\n message,\n}) {\n const [locale, setLocale] = useState(getLocale());\n\n useAppEvent(LOCALE_CHANGED, () => {\n setLocale(getLocale());\n });\n\n /* istanbul ignore next */\n const reload = () => {\n global.location.reload();\n };\n\n return (\n <IntlProvider locale={locale} messages={getMessages()}>\n <Container fluid className=\"py-5 justify-content-center align-items-start text-center\">\n <Row>\n <Col>\n <p className=\"text-muted\">\n <FormattedMessage\n id=\"unexpected.error.message.text\"\n defaultMessage=\"An unexpected error occurred. Please click the button below to refresh the page.\"\n description=\"error message when an unexpected error occurs\"\n />\n </p>\n {message && (\n <div role=\"alert\" className=\"my-4\">\n <p>{message}</p>\n </div>\n )}\n <Button onClick={reload}>\n <FormattedMessage\n id=\"unexpected.error.button.text\"\n defaultMessage=\"Try again\"\n description=\"text for button that tries to reload the app by refreshing the page\"\n />\n </Button>\n </Col>\n </Row>\n </Container>\n </IntlProvider>\n );\n}\n\nErrorPage.propTypes = {\n message: PropTypes.string,\n};\n\nErrorPage.defaultProps = {\n message: null,\n};\n\nexport default ErrorPage;\n"],"mappings":";;;;;;AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,OAAOC,SAAS,MAAM,YAAY;AAClC,SACEC,MAAM,EAAEC,SAAS,EAAEC,GAAG,EAAEC,GAAG,QACtB,cAAc;AAErB,SAASC,WAAW,QAAQ,SAAS;AACrC,SACEC,gBAAgB,EAChBC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,cAAc,QACT,SAAS;;AAEhB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAAAC,IAAA,EAEf;EAAA,IADDC,OAAO,GAAAD,IAAA,CAAPC,OAAO;EAEP,IAAAC,SAAA,GAA4Bf,QAAQ,CAACU,SAAS,
|
|
1
|
+
{"version":3,"file":"ErrorPage.js","names":["React","useState","PropTypes","Button","Container","Row","Col","useAppEvent","FormattedMessage","IntlProvider","getMessages","getLocale","LOCALE_CHANGED","ErrorPage","_ref","message","_useState","_useState2","_slicedToArray","locale","setLocale","reload","global","location","createElement","messages","fluid","className","id","defaultMessage","description","role","onClick","propTypes","string","defaultProps"],"sources":["../../src/react/ErrorPage.jsx"],"sourcesContent":["import React, { useState } from 'react';\nimport PropTypes from 'prop-types';\nimport {\n Button, Container, Row, Col,\n} from '@edx/paragon';\n\nimport { useAppEvent } from './hooks';\nimport {\n FormattedMessage,\n IntlProvider,\n getMessages,\n getLocale,\n LOCALE_CHANGED,\n} from '../i18n';\n\n/**\n * An error page that displays a generic message for unexpected errors. Also contains a \"Try\n * Again\" button to refresh the page.\n *\n * @memberof module:React\n * @extends {Component}\n */\nfunction ErrorPage({\n message,\n}) {\n const [locale, setLocale] = useState(getLocale());\n\n useAppEvent(LOCALE_CHANGED, () => {\n setLocale(getLocale());\n });\n\n /* istanbul ignore next */\n const reload = () => {\n global.location.reload();\n };\n\n return (\n <IntlProvider locale={locale} messages={getMessages()}>\n <Container fluid className=\"py-5 justify-content-center align-items-start text-center\">\n <Row>\n <Col>\n <p className=\"text-muted\">\n <FormattedMessage\n id=\"unexpected.error.message.text\"\n defaultMessage=\"An unexpected error occurred. Please click the button below to refresh the page.\"\n description=\"error message when an unexpected error occurs\"\n />\n </p>\n {message && (\n <div role=\"alert\" className=\"my-4\">\n <p>{message}</p>\n </div>\n )}\n <Button onClick={reload}>\n <FormattedMessage\n id=\"unexpected.error.button.text\"\n defaultMessage=\"Try again\"\n description=\"text for button that tries to reload the app by refreshing the page\"\n />\n </Button>\n </Col>\n </Row>\n </Container>\n </IntlProvider>\n );\n}\n\nErrorPage.propTypes = {\n message: PropTypes.string,\n};\n\nErrorPage.defaultProps = {\n message: null,\n};\n\nexport default ErrorPage;\n"],"mappings":";;;;;;AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,OAAOC,SAAS,MAAM,YAAY;AAClC,SACEC,MAAM,EAAEC,SAAS,EAAEC,GAAG,EAAEC,GAAG,QACtB,cAAc;AAErB,SAASC,WAAW,QAAQ,SAAS;AACrC,SACEC,gBAAgB,EAChBC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,cAAc,QACT,SAAS;;AAEhB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAAAC,IAAA,EAEf;EAAA,IADDC,OAAO,GAAAD,IAAA,CAAPC,OAAO;EAEP,IAAAC,SAAA,GAA4Bf,QAAQ,CAACU,SAAS,CAAC,CAAC,CAAC;IAAAM,UAAA,GAAAC,cAAA,CAAAF,SAAA;IAA1CG,MAAM,GAAAF,UAAA;IAAEG,SAAS,GAAAH,UAAA;EAExBV,WAAW,CAACK,cAAc,EAAE,YAAM;IAChCQ,SAAS,CAACT,SAAS,CAAC,CAAC,CAAC;EACxB,CAAC,CAAC;;EAEF;EACA,IAAMU,MAAM,GAAG,SAATA,MAAMA,CAAA,EAAS;IACnBC,MAAM,CAACC,QAAQ,CAACF,MAAM,CAAC,CAAC;EAC1B,CAAC;EAED,oBACErB,KAAA,CAAAwB,aAAA,CAACf,YAAY;IAACU,MAAM,EAAEA,MAAO;IAACM,QAAQ,EAAEf,WAAW,CAAC;EAAE,gBACpDV,KAAA,CAAAwB,aAAA,CAACpB,SAAS;IAACsB,KAAK;IAACC,SAAS,EAAC;EAA2D,gBACpF3B,KAAA,CAAAwB,aAAA,CAACnB,GAAG,qBACFL,KAAA,CAAAwB,aAAA,CAAClB,GAAG,qBACFN,KAAA,CAAAwB,aAAA;IAAGG,SAAS,EAAC;EAAY,gBACvB3B,KAAA,CAAAwB,aAAA,CAAChB,gBAAgB;IACfoB,EAAE,EAAC,+BAA+B;IAClCC,cAAc,EAAC,kFAAkF;IACjGC,WAAW,EAAC;EAA+C,CAC5D,CACA,CAAC,EACHf,OAAO,iBACNf,KAAA,CAAAwB,aAAA;IAAKO,IAAI,EAAC,OAAO;IAACJ,SAAS,EAAC;EAAM,gBAChC3B,KAAA,CAAAwB,aAAA,YAAIT,OAAW,CACZ,CACN,eACDf,KAAA,CAAAwB,aAAA,CAACrB,MAAM;IAAC6B,OAAO,EAAEX;EAAO,gBACtBrB,KAAA,CAAAwB,aAAA,CAAChB,gBAAgB;IACfoB,EAAE,EAAC,8BAA8B;IACjCC,cAAc,EAAC,WAAW;IAC1BC,WAAW,EAAC;EAAqE,CAClF,CACK,CACL,CACF,CACI,CACC,CAAC;AAEnB;AAEAjB,SAAS,CAACoB,SAAS,GAAG;EACpBlB,OAAO,EAAEb,SAAS,CAACgC;AACrB,CAAC;AAEDrB,SAAS,CAACsB,YAAY,GAAG;EACvBpB,OAAO,EAAE;AACX,CAAC;AAED,eAAeF,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptionalReduxProvider.js","names":["React","PropTypes","Provider","OptionalReduxProvider","_ref","store","children","createElement","propTypes","object","node","isRequired","defaultProps"],"sources":["../../src/react/OptionalReduxProvider.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Provider } from 'react-redux';\n\n/**\n * @memberof module:React\n * @param {Object} props\n */\nexport default function OptionalReduxProvider({ store, children }) {\n if (store === null) {\n return children;\n }\n\n return (\n <Provider store={store}>\n {children}\n </Provider>\n );\n}\n\nOptionalReduxProvider.propTypes = {\n store: PropTypes.object, // eslint-disable-line\n children: PropTypes.node.isRequired,\n};\n\nOptionalReduxProvider.defaultProps = {\n store: null,\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,QAAQ,QAAQ,aAAa;;AAEtC;AACA;AACA;AACA;AACA,eAAe,SAASC,qBAAqBA,CAAAC,IAAA,EAAsB;EAAA,IAAnBC,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;EAC7D,IAAID,KAAK,KAAK,IAAI,EAAE;IAClB,OAAOC,QAAQ;EACjB;EAEA,oBACEN,KAAA,CAAAO,aAAA,CAACL,QAAQ;IAACG,KAAK,EAAEA;EAAM,GACpBC,
|
|
1
|
+
{"version":3,"file":"OptionalReduxProvider.js","names":["React","PropTypes","Provider","OptionalReduxProvider","_ref","store","children","createElement","propTypes","object","node","isRequired","defaultProps"],"sources":["../../src/react/OptionalReduxProvider.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Provider } from 'react-redux';\n\n/**\n * @memberof module:React\n * @param {Object} props\n */\nexport default function OptionalReduxProvider({ store, children }) {\n if (store === null) {\n return children;\n }\n\n return (\n <Provider store={store}>\n {children}\n </Provider>\n );\n}\n\nOptionalReduxProvider.propTypes = {\n store: PropTypes.object, // eslint-disable-line\n children: PropTypes.node.isRequired,\n};\n\nOptionalReduxProvider.defaultProps = {\n store: null,\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,QAAQ,QAAQ,aAAa;;AAEtC;AACA;AACA;AACA;AACA,eAAe,SAASC,qBAAqBA,CAAAC,IAAA,EAAsB;EAAA,IAAnBC,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;EAC7D,IAAID,KAAK,KAAK,IAAI,EAAE;IAClB,OAAOC,QAAQ;EACjB;EAEA,oBACEN,KAAA,CAAAO,aAAA,CAACL,QAAQ;IAACG,KAAK,EAAEA;EAAM,GACpBC,QACO,CAAC;AAEf;AAEAH,qBAAqB,CAACK,SAAS,GAAG;EAChCH,KAAK,EAAEJ,SAAS,CAACQ,MAAM;EAAE;EACzBH,QAAQ,EAAEL,SAAS,CAACS,IAAI,CAACC;AAC3B,CAAC;AAEDR,qBAAqB,CAACS,YAAY,GAAG;EACnCP,KAAK,EAAE;AACT,CAAC"}
|
package/react/PageRoute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageRoute.js","names":["React","useEffect","Route","useRouteMatch","sendPageEvent","PageRoute","props","match","path","exact","strict","sensitive","JSON","stringify","createElement"],"sources":["../../src/react/PageRoute.jsx"],"sourcesContent":["/* eslint-disable react/prop-types */\nimport React, { useEffect } from 'react';\nimport { Route, useRouteMatch } from 'react-router-dom';\nimport { sendPageEvent } from '../analytics';\n\n/**\n * A react-router Route component that calls `sendPageEvent` when it becomes active.\n *\n * @see {@link module:frontend-platform/analytics~sendPageEvent}\n * @memberof module:React\n * @param {Object} props\n */\nexport default function PageRoute(props) {\n const match = useRouteMatch({\n path: props.path,\n exact: props.exact,\n strict: props.strict,\n sensitive: props.sensitive,\n });\n\n useEffect(() => {\n if (match) {\n sendPageEvent();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(match)]);\n\n return (\n <Route {...props} />\n );\n}\n"],"mappings":"AAAA;AACA,OAAOA,KAAK,IAAIC,SAAS,QAAQ,OAAO;AACxC,SAASC,KAAK,EAAEC,aAAa,QAAQ,kBAAkB;AACvD,SAASC,aAAa,QAAQ,cAAc;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,SAASA,CAACC,KAAK,EAAE;EACvC,IAAMC,KAAK,GAAGJ,aAAa,CAAC;IAC1BK,IAAI,EAAEF,KAAK,CAACE,IAAI;IAChBC,KAAK,EAAEH,KAAK,CAACG,KAAK;IAClBC,MAAM,EAAEJ,KAAK,CAACI,MAAM;IACpBC,SAAS,EAAEL,KAAK,CAACK;EACnB,CAAC,CAAC;EAEFV,SAAS,CAAC,YAAM;IACd,IAAIM,KAAK,EAAE;MACTH,aAAa,
|
|
1
|
+
{"version":3,"file":"PageRoute.js","names":["React","useEffect","Route","useRouteMatch","sendPageEvent","PageRoute","props","match","path","exact","strict","sensitive","JSON","stringify","createElement"],"sources":["../../src/react/PageRoute.jsx"],"sourcesContent":["/* eslint-disable react/prop-types */\nimport React, { useEffect } from 'react';\nimport { Route, useRouteMatch } from 'react-router-dom';\nimport { sendPageEvent } from '../analytics';\n\n/**\n * A react-router Route component that calls `sendPageEvent` when it becomes active.\n *\n * @see {@link module:frontend-platform/analytics~sendPageEvent}\n * @memberof module:React\n * @param {Object} props\n */\nexport default function PageRoute(props) {\n const match = useRouteMatch({\n path: props.path,\n exact: props.exact,\n strict: props.strict,\n sensitive: props.sensitive,\n });\n\n useEffect(() => {\n if (match) {\n sendPageEvent();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(match)]);\n\n return (\n <Route {...props} />\n );\n}\n"],"mappings":"AAAA;AACA,OAAOA,KAAK,IAAIC,SAAS,QAAQ,OAAO;AACxC,SAASC,KAAK,EAAEC,aAAa,QAAQ,kBAAkB;AACvD,SAASC,aAAa,QAAQ,cAAc;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,SAASA,CAACC,KAAK,EAAE;EACvC,IAAMC,KAAK,GAAGJ,aAAa,CAAC;IAC1BK,IAAI,EAAEF,KAAK,CAACE,IAAI;IAChBC,KAAK,EAAEH,KAAK,CAACG,KAAK;IAClBC,MAAM,EAAEJ,KAAK,CAACI,MAAM;IACpBC,SAAS,EAAEL,KAAK,CAACK;EACnB,CAAC,CAAC;EAEFV,SAAS,CAAC,YAAM;IACd,IAAIM,KAAK,EAAE;MACTH,aAAa,CAAC,CAAC;IACjB;IACF;EACA,CAAC,EAAE,CAACQ,IAAI,CAACC,SAAS,CAACN,KAAK,CAAC,CAAC,CAAC;EAE3B,oBACEP,KAAA,CAAAc,aAAA,CAACZ,KAAK,EAAKI,KAAQ,CAAC;AAExB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
/**
|
|
8
|
+
* @implements {GoogleAnalyticsLoader}
|
|
9
|
+
* @memberof module:GoogleAnalytics
|
|
10
|
+
*/
|
|
11
|
+
var GoogleAnalyticsLoader = /*#__PURE__*/function () {
|
|
12
|
+
function GoogleAnalyticsLoader(_ref) {
|
|
13
|
+
var config = _ref.config;
|
|
14
|
+
_classCallCheck(this, GoogleAnalyticsLoader);
|
|
15
|
+
this.analyticsId = config.GOOGLE_ANALYTICS_4_ID;
|
|
16
|
+
}
|
|
17
|
+
_createClass(GoogleAnalyticsLoader, [{
|
|
18
|
+
key: "loadScript",
|
|
19
|
+
value: function loadScript() {
|
|
20
|
+
if (!this.analyticsId) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
global.googleAnalytics = global.googleAnalytics || [];
|
|
24
|
+
var _global = global,
|
|
25
|
+
googleAnalytics = _global.googleAnalytics;
|
|
26
|
+
|
|
27
|
+
// If the snippet was invoked do nothing.
|
|
28
|
+
if (googleAnalytics.invoked) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Invoked flag, to make sure the snippet
|
|
33
|
+
// is never invoked twice.
|
|
34
|
+
googleAnalytics.invoked = true;
|
|
35
|
+
googleAnalytics.load = function (key, options) {
|
|
36
|
+
var scriptSrc = document.createElement('script');
|
|
37
|
+
scriptSrc.type = 'text/javascript';
|
|
38
|
+
scriptSrc.async = true;
|
|
39
|
+
scriptSrc.src = "https://www.googletagmanager.com/gtag/js?id=".concat(key);
|
|
40
|
+
var scriptGtag = document.createElement('script');
|
|
41
|
+
scriptGtag.innerHTML = "\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '".concat(key, "');\n ");
|
|
42
|
+
|
|
43
|
+
// Insert our scripts next to the first script element.
|
|
44
|
+
var first = document.getElementsByTagName('script')[0];
|
|
45
|
+
first.parentNode.insertBefore(scriptSrc, first);
|
|
46
|
+
first.parentNode.insertBefore(scriptGtag, first);
|
|
47
|
+
googleAnalytics._loadOptions = options; // eslint-disable-line no-underscore-dangle
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Load GoogleAnalytics with your key.
|
|
51
|
+
googleAnalytics.load(this.analyticsId);
|
|
52
|
+
}
|
|
53
|
+
}]);
|
|
54
|
+
return GoogleAnalyticsLoader;
|
|
55
|
+
}();
|
|
56
|
+
export default GoogleAnalyticsLoader;
|
|
57
|
+
//# sourceMappingURL=GoogleAnalyticsLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GoogleAnalyticsLoader.js","names":["GoogleAnalyticsLoader","_ref","config","_classCallCheck","analyticsId","GOOGLE_ANALYTICS_4_ID","_createClass","key","value","loadScript","global","googleAnalytics","_global","invoked","load","options","scriptSrc","document","createElement","type","async","src","concat","scriptGtag","innerHTML","first","getElementsByTagName","parentNode","insertBefore","_loadOptions"],"sources":["../../src/scripts/GoogleAnalyticsLoader.js"],"sourcesContent":["/**\n * @implements {GoogleAnalyticsLoader}\n * @memberof module:GoogleAnalytics\n */\nclass GoogleAnalyticsLoader {\n constructor({ config }) {\n this.analyticsId = config.GOOGLE_ANALYTICS_4_ID;\n }\n\n loadScript() {\n if (!this.analyticsId) {\n return;\n }\n\n global.googleAnalytics = global.googleAnalytics || [];\n const { googleAnalytics } = global;\n\n // If the snippet was invoked do nothing.\n if (googleAnalytics.invoked) {\n return;\n }\n\n // Invoked flag, to make sure the snippet\n // is never invoked twice.\n googleAnalytics.invoked = true;\n\n googleAnalytics.load = (key, options) => {\n const scriptSrc = document.createElement('script');\n scriptSrc.type = 'text/javascript';\n scriptSrc.async = true;\n scriptSrc.src = `https://www.googletagmanager.com/gtag/js?id=${key}`;\n\n const scriptGtag = document.createElement('script');\n scriptGtag.innerHTML = `\n window.dataLayer = window.dataLayer || [];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '${key}');\n `;\n\n // Insert our scripts next to the first script element.\n const first = document.getElementsByTagName('script')[0];\n first.parentNode.insertBefore(scriptSrc, first);\n first.parentNode.insertBefore(scriptGtag, first);\n googleAnalytics._loadOptions = options; // eslint-disable-line no-underscore-dangle\n };\n\n // Load GoogleAnalytics with your key.\n googleAnalyt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AAY,CAACL,UAAU,EAAEE,KAAK,CAAC;QAChDd,eAAe,CAACkB,YAAY,GAAGd,OAAO,CAAC,CAAC;MAC1C,CAAC;;MAED;MACAJ,eAAe,CAACG,IAAI,CAAC,IAAI,CAACV,WAAW,CAAC;IACxC;EAAC;EAAA,OAAAJ,qBAAA;AAAA;AAGH,eAAeA,qBAAqB"}
|
package/scripts/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","GoogleAnalyticsLoader"],"sources":["../../src/scripts/index.js"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\nexport { default as GoogleAnalyticsLoader } from './GoogleAnalyticsLoader';\n"],"mappings":"AAAA;AACA,SAASA,OAAO,IAAIC,qBAAqB,QAAQ,yBAAyB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initializeMockApp.js","names":["configure","configureAnalytics","MockAnalyticsService","configureI18n","configureLogging","MockLoggingService","configureAuth","MockAuthService","getConfig","mockMessages","initializeMockApp","_ref","arguments","length","undefined","_ref$messages","messages","_ref$authenticatedUse","authenticatedUser","loggingService","config","authService","_objectSpread","analyticsService","httpClient","getAuthenticatedHttpClient"],"sources":["../../src/testing/initializeMockApp.js"],"sourcesContent":["import { configure as configureAnalytics, MockAnalyticsService } from '../analytics';\nimport { configure as configureI18n } from '../i18n';\nimport { configure as configureLogging, MockLoggingService } from '../logging';\nimport { configure as configureAuth, MockAuthService } from '../auth';\nimport { getConfig } from '../config';\nimport mockMessages from './mockMessages';\n\n/**\n * Initializes a mock application for component testing. The mock application includes\n * mock analytics, auth, and logging services, and the real i18n service.\n *\n * See MockAnalyticsService, MockAuthService, and MockLoggingService for mock implementation\n * details. For the most part, the analytics and logging services just implement their functions\n * with jest.fn() and do nothing else, whereas the MockAuthService actually has some behavior\n * implemented, it just doesn't make any HTTP calls.\n *\n * Note that this mock application is not sufficient for testing the full application lifecycle or\n * initialization callbacks/custom handlers as described in the 'initialize' function's\n * documentation. It exists merely to set up the mock services that components themselves tend to\n * interact with most often. It could be extended to allow for setting up custom handlers fairly\n * easily, as this functionality would be more-or-less identical to what the real initialize\n * function does.\n *\n * Example:\n *\n * ```\n * import { initializeMockApp } from '@edx/frontend-platform/testing';\n * import { logInfo } from '@edx/frontend-platform/logging';\n *\n * describe('initializeMockApp', () => {\n * it('mocks things correctly', () => {\n * const { loggingService } = initializeMockApp();\n * logInfo('test', {});\n * expect(loggingService.logInfo).toHaveBeenCalledWith('test', {});\n * });\n * });\n * ```\n *\n * @param {Object} [options]\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 {UserData|null} [options.authenticatedUser] A UserData object representing the\n * authenticated user. This is passed directly to MockAuthService.\n * @memberof module:Testing\n */\nexport default function initializeMockApp({\n messages = mockMessages,\n authenticatedUser = null,\n} = {}) {\n const loggingService = configureLogging(MockLoggingService, {\n config: getConfig(),\n });\n\n const authService = configureAuth(MockAuthService, {\n config: { ...getConfig(), authenticatedUser },\n loggingService,\n });\n\n const analyticsService = configureAnalytics(MockAnalyticsService, {\n config: getConfig(),\n httpClient: authService.getAuthenticatedHttpClient(),\n loggingService,\n });\n\n // The i18n service configure function has no return value, since there isn't a service class.\n configureI18n({\n config: getConfig(),\n loggingService,\n messages,\n });\n\n return {\n analyticsService,\n authService,\n loggingService,\n };\n}\n"],"mappings":";;;;;;AAAA,SAASA,SAAS,IAAIC,kBAAkB,EAAEC,oBAAoB,QAAQ,cAAc;AACpF,SAASF,SAAS,IAAIG,aAAa,QAAQ,SAAS;AACpD,SAASH,SAAS,IAAII,gBAAgB,EAAEC,kBAAkB,QAAQ,YAAY;AAC9E,SAASL,SAAS,IAAIM,aAAa,EAAEC,eAAe,QAAQ,SAAS;AACrE,SAASC,SAAS,QAAQ,WAAW;AACrC,OAAOC,YAAY,MAAM,gBAAgB;;AAEzC;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,eAAe,SAASC,iBAAiBA,CAAA,EAGjC;EAAA,IAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAJ,CAAC,CAAC;IAAAG,aAAA,GAAAJ,IAAA,CAFJK,QAAQ;IAARA,QAAQ,GAAAD,aAAA,cAAGN,YAAY,GAAAM,aAAA;IAAAE,qBAAA,GAAAN,IAAA,CACvBO,iBAAiB;IAAjBA,iBAAiB,GAAAD,qBAAA,cAAG,IAAI,GAAAA,qBAAA;EAExB,IAAME,cAAc,GAAGf,gBAAgB,CAACC,kBAAkB,EAAE;IAC1De,MAAM,EAAEZ,SAAS;
|
|
1
|
+
{"version":3,"file":"initializeMockApp.js","names":["configure","configureAnalytics","MockAnalyticsService","configureI18n","configureLogging","MockLoggingService","configureAuth","MockAuthService","getConfig","mockMessages","initializeMockApp","_ref","arguments","length","undefined","_ref$messages","messages","_ref$authenticatedUse","authenticatedUser","loggingService","config","authService","_objectSpread","analyticsService","httpClient","getAuthenticatedHttpClient"],"sources":["../../src/testing/initializeMockApp.js"],"sourcesContent":["import { configure as configureAnalytics, MockAnalyticsService } from '../analytics';\nimport { configure as configureI18n } from '../i18n';\nimport { configure as configureLogging, MockLoggingService } from '../logging';\nimport { configure as configureAuth, MockAuthService } from '../auth';\nimport { getConfig } from '../config';\nimport mockMessages from './mockMessages';\n\n/**\n * Initializes a mock application for component testing. The mock application includes\n * mock analytics, auth, and logging services, and the real i18n service.\n *\n * See MockAnalyticsService, MockAuthService, and MockLoggingService for mock implementation\n * details. For the most part, the analytics and logging services just implement their functions\n * with jest.fn() and do nothing else, whereas the MockAuthService actually has some behavior\n * implemented, it just doesn't make any HTTP calls.\n *\n * Note that this mock application is not sufficient for testing the full application lifecycle or\n * initialization callbacks/custom handlers as described in the 'initialize' function's\n * documentation. It exists merely to set up the mock services that components themselves tend to\n * interact with most often. It could be extended to allow for setting up custom handlers fairly\n * easily, as this functionality would be more-or-less identical to what the real initialize\n * function does.\n *\n * Example:\n *\n * ```\n * import { initializeMockApp } from '@edx/frontend-platform/testing';\n * import { logInfo } from '@edx/frontend-platform/logging';\n *\n * describe('initializeMockApp', () => {\n * it('mocks things correctly', () => {\n * const { loggingService } = initializeMockApp();\n * logInfo('test', {});\n * expect(loggingService.logInfo).toHaveBeenCalledWith('test', {});\n * });\n * });\n * ```\n *\n * @param {Object} [options]\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 {UserData|null} [options.authenticatedUser] A UserData object representing the\n * authenticated user. This is passed directly to MockAuthService.\n * @memberof module:Testing\n */\nexport default function initializeMockApp({\n messages = mockMessages,\n authenticatedUser = null,\n} = {}) {\n const loggingService = configureLogging(MockLoggingService, {\n config: getConfig(),\n });\n\n const authService = configureAuth(MockAuthService, {\n config: { ...getConfig(), authenticatedUser },\n loggingService,\n });\n\n const analyticsService = configureAnalytics(MockAnalyticsService, {\n config: getConfig(),\n httpClient: authService.getAuthenticatedHttpClient(),\n loggingService,\n });\n\n // The i18n service configure function has no return value, since there isn't a service class.\n configureI18n({\n config: getConfig(),\n loggingService,\n messages,\n });\n\n return {\n analyticsService,\n authService,\n loggingService,\n };\n}\n"],"mappings":";;;;;;AAAA,SAASA,SAAS,IAAIC,kBAAkB,EAAEC,oBAAoB,QAAQ,cAAc;AACpF,SAASF,SAAS,IAAIG,aAAa,QAAQ,SAAS;AACpD,SAASH,SAAS,IAAII,gBAAgB,EAAEC,kBAAkB,QAAQ,YAAY;AAC9E,SAASL,SAAS,IAAIM,aAAa,EAAEC,eAAe,QAAQ,SAAS;AACrE,SAASC,SAAS,QAAQ,WAAW;AACrC,OAAOC,YAAY,MAAM,gBAAgB;;AAEzC;AACA;AACA;AAC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
package/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["camelCase","snakeCase","modifyObjectKeys","object","modify","undefined","_typeof","Array","isArray","map","value","result","Object","entries","forEach","_ref","_ref2","_slicedToArray","key","camelCaseObject","snakeCaseObject","convertKeyNames","nameMap","transformer","getQueryParameters","search","arguments","length","global","location","keyValueFragments","slice","indexOf","split","filter","hash","reduce","params","keyValueFragment","assign","_defineProperty","decodeURIComponent","ensureDefinedConfig","requester","keys","console","warn","concat"],"sources":["../src/utils.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform**\n *\n * @module Utilities\n */\nimport camelCase from 'lodash.camelcase';\nimport snakeCase from 'lodash.snakecase';\n\n/**\n * This is the underlying function used by camelCaseObject, snakeCaseObject, and convertKeyNames\n * above.\n *\n * Given an object (or array) and a modification function, will perform the function on each key it\n * encounters on the object and its tree of children.\n *\n * The modification function must take a string as an argument and returns a string.\n *\n * Example:\n *\n * ```\n * (key) => {\n * if (key === 'edX') {\n * return 'Open edX';\n * }\n * return key;\n * }\n * ```\n *\n * This function will turn any key that matches 'edX' into 'Open edX'. All other keys will be\n * passed through unmodified.\n *\n * Can accept arrays as well as objects, and will perform its conversion on any objects it finds in\n * the array.\n *\n * @param {Object} object\n * @param {function} modify\n * @returns {Object}\n */\nexport function modifyObjectKeys(object, modify) {\n // If the passed in object is not an Object, return it.\n if (\n object === undefined\n || object === null\n || (typeof object !== 'object' && !Array.isArray(object))\n ) {\n return object;\n }\n\n if (Array.isArray(object)) {\n return object.map(value => modifyObjectKeys(value, modify));\n }\n\n // Otherwise, process all its keys.\n const result = {};\n Object.entries(object).forEach(([key, value]) => {\n result[modify(key)] = modifyObjectKeys(value, modify);\n });\n return result;\n}\n\n/**\n * Performs a deep conversion to camelCase on all keys in the provided object and its tree of\n * children. Uses [lodash.camelcase](https://lodash.com/docs/4.17.15#camelCase) on each key. This\n * is commonly used to convert snake_case keys in models from a backend server into camelCase keys\n * for use in the JavaScript client.\n *\n * Can accept arrays as well as objects, and will perform its conversion on any objects it finds in\n * the array.\n *\n * @param {Array|Object} object\n * @returns {Array|Object}\n */\nexport function camelCaseObject(object) {\n return modifyObjectKeys(object, camelCase);\n}\n\n/**\n * Performs a deep conversion to snake_case on all keys in the provided object and its tree of\n * children. Uses [lodash.snakecase](https://lodash.com/docs/4.17.15#snakeCase) on each key. This\n * is commonly used to convert camelCase keys from the JavaScript app into snake_case keys expected\n * by backend servers.\n *\n * Can accept arrays as well as objects, and will perform its conversion on any objects it finds in\n * the array.\n *\n * @param {Array|Object} object\n * @returns {Array|Object}\n */\nexport function snakeCaseObject(object) {\n return modifyObjectKeys(object, snakeCase);\n}\n\n/**\n * Given a map of key-value pairs, performs a deep conversion key names in the specified object\n * _from_ the key _to_ the value. This is useful for updating names in an API request to the names\n * used throughout a client application if they happen to differ. It can also be used in the\n * reverse - formatting names from the client application to names expected by an API.\n *\n * ```\n * import { convertKeyNames } from '@edx/frontend-base';\n *\n * // This object can be of any shape or depth with subobjects/arrays.\n * const myObject = {\n * myKey: 'my value',\n * }\n *\n * const result = convertKeyNames(myObject, { myKey: 'their_key' });\n *\n * console.log(result) // { their_key: 'my value' }\n * ```\n *\n * Can accept arrays as well as objects, and will perform its conversion on any objects it finds in\n * the array.\n *\n * @param {Array|Object} object\n * @param {Object} nameMap\n * @returns {Array|Object}\n */\nexport function convertKeyNames(object, nameMap) {\n const transformer = key => (nameMap[key] === undefined ? key : nameMap[key]);\n\n return modifyObjectKeys(object, transformer);\n}\n\n/**\n * *Deprecated*: A method which converts the supplied query string into an object of\n * key-value pairs and returns it. Defaults to the current query string - should perform like\n * [window.searchParams](https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams)\n *\n * @deprecated\n * @param {string} [search=global.location.search]\n * @returns {Object}\n */\nexport function getQueryParameters(search = global.location.search) {\n const keyValueFragments = search\n .slice(search.indexOf('?') + 1)\n .split('&')\n .filter(hash => hash !== '');\n\n return keyValueFragments.reduce((params, keyValueFragment) => {\n const split = keyValueFragment.indexOf('=');\n const key = keyValueFragment.slice(0, split);\n const value = keyValueFragment.slice(split + 1);\n return Object.assign(params, { [key]: decodeURIComponent(value) });\n }, {});\n}\n\n/**\n * This function helps catch a certain class of misconfiguration in which configuration variables\n * are not properly defined and/or supplied to a consumer that requires them. Any key that exists\n * is still set to \"undefined\" indicates a misconfiguration further up in the application, and\n * should be flagged as an error, and is logged to 'warn'.\n *\n * Keys that are intended to be falsy should be defined using null, 0, false, etc.\n *\n * @param {Object} object\n * @param {string} requester A human-readable identifier for the code which called this function.\n * Used when throwing errors to aid in debugging.\n */\nexport function ensureDefinedConfig(object, requester) {\n Object.keys(object).forEach((key) => {\n if (object[key] === undefined) {\n // eslint-disable-next-line no-console\n console.warn(`Module configuration error: ${key} is required by ${requester}.`);\n }\n });\n}\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,kBAAkB;AACxC,OAAOC,SAAS,MAAM,kBAAkB;;AAExC;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,OAAO,SAASC,gBAAgBA,CAACC,MAAM,EAAEC,MAAM,EAAE;EAC/C;EACA,IACED,MAAM,KAAKE,SAAS,IACjBF,MAAM,KAAK,IAAI,IACdG,OAAA,CAAOH,MAAM,MAAK,QAAQ,IAAI,CAACI,KAAK,CAACC,OAAO,CAACL,MAAM,CAAE,EACzD;IACA,OAAOA,MAAM;EACf;EAEA,IAAII,KAAK,CAACC,OAAO,CAACL,MAAM,CAAC,EAAE;IACzB,OAAOA,MAAM,CAACM,GAAG,CAAC,UAAAC,KAAK;MAAA,OAAIR,gBAAgB,CAACQ,KAAK,EAAEN,MAAM,CAAC;IAAA,EAAC;EAC7D;;EAEA;EACA,IAAMO,MAAM,GAAG,CAAC,CA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qB,SAAA,MAAGE,MAAM,CAACC,QAAQ,CAACJ,MAAM;EAChE,IAAMK,iBAAiB,GAAGL,MAAM,CAC7BM,KAAK,CAACN,MAAM,CAACO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAC9BC,KAAK,CAAC,GAAG,CAAC,CACVC,MAAM,CAAC,UAAAC,IAAI;IAAA,OAAIA,IAAI,KAAK,EAAE;EAAA,EAAC;EAE9B,OAAOL,iBAAiB,CAACM,MAAM,CAAC,UAACC,MAAM,EAAEC,gBAAgB,EAAK;IAC5D,IAAML,KAAK,GAAGK,gBAAgB,CAACN,OAAO,CAAC,GAAG,CAAC;IAC3C,IAAMd,GAAG,GAAGoB,gBAAgB,CAACP,KAAK,CAAC,CAAC,EAAEE,KAAK,CAAC;IAC5C,IAAMvB,KAAK,GAAG4B,gBAAgB,CAACP,KAAK,CAACE,KAAK,GAAG,CAAC,CAAC;IAC/C,OAAOrB,MAAM,CAAC2B,MAAM,CAACF,MAAM,EAAAG,eAAA,KAAKtB,GAAG,EAAGuB,kBAAkB,CAAC/B,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"utils.js","names":["camelCase","snakeCase","modifyObjectKeys","object","modify","undefined","_typeof","Array","isArray","map","value","result","Object","entries","forEach","_ref","_ref2","_slicedToArray","key","camelCaseObject","snakeCaseObject","convertKeyNames","nameMap","transformer","getQueryParameters","search","arguments","length","global","location","keyValueFragments","slice","indexOf","split","filter","hash","reduce","params","keyValueFragment","assign","_defineProperty","decodeURIComponent","ensureDefinedConfig","requester","keys","console","warn","concat"],"sources":["../src/utils.js"],"sourcesContent":["/**\n * #### Import members from **@edx/frontend-platform**\n *\n * @module Utilities\n */\nimport camelCase from 'lodash.camelcase';\nimport snakeCase from 'lodash.snakecase';\n\n/**\n * This is the underlying function used by camelCaseObject, snakeCaseObject, and convertKeyNames\n * above.\n *\n * Given an object (or array) and a modification function, will perform the function on each key it\n * encounters on the object and its tree of children.\n *\n * The modification function must take a string as an argument and returns a string.\n *\n * Example:\n *\n * ```\n * (key) => {\n * if (key === 'edX') {\n * return 'Open edX';\n * }\n * return key;\n * }\n * ```\n *\n * This function will turn any key that matches 'edX' into 'Open edX'. All other keys will be\n * passed through unmodified.\n *\n * Can accept arrays as well as objects, and will perform its conversion on any objects it finds in\n * the array.\n *\n * @param {Object} object\n * @param {function} modify\n * @returns {Object}\n */\nexport function modifyObjectKeys(object, modify) {\n // If the passed in object is not an Object, return it.\n if (\n object === undefined\n || object === null\n || (typeof object !== 'object' && !Array.isArray(object))\n ) {\n return object;\n }\n\n if (Array.isArray(object)) {\n return object.map(value => modifyObjectKeys(value, modify));\n }\n\n // Otherwise, process all its keys.\n const result = {};\n Object.entries(object).forEach(([key, value]) => {\n result[modify(key)] = modifyObjectKeys(value, modify);\n });\n return result;\n}\n\n/**\n * Performs a deep conversion to camelCase on all keys in the provided object and its tree of\n * children. Uses [lodash.camelcase](https://lodash.com/docs/4.17.15#camelCase) on each key. This\n * is commonly used to convert snake_case keys in models from a backend server into camelCase keys\n * for use in the JavaScript client.\n *\n * Can accept arrays as well as objects, and will perform its conversion on any objects it finds in\n * the array.\n *\n * @param {Array|Object} object\n * @returns {Array|Object}\n */\nexport function camelCaseObject(object) {\n return modifyObjectKeys(object, camelCase);\n}\n\n/**\n * Performs a deep conversion to snake_case on all keys in the provided object and its tree of\n * children. Uses [lodash.snakecase](https://lodash.com/docs/4.17.15#snakeCase) on each key. This\n * is commonly used to convert camelCase keys from the JavaScript app into snake_case keys expected\n * by backend servers.\n *\n * Can accept arrays as well as objects, and will perform its conversion on any objects it finds in\n * the array.\n *\n * @param {Array|Object} object\n * @returns {Array|Object}\n */\nexport function snakeCaseObject(object) {\n return modifyObjectKeys(object, snakeCase);\n}\n\n/**\n * Given a map of key-value pairs, performs a deep conversion key names in the specified object\n * _from_ the key _to_ the value. This is useful for updating names in an API request to the names\n * used throughout a client application if they happen to differ. It can also be used in the\n * reverse - formatting names from the client application to names expected by an API.\n *\n * ```\n * import { convertKeyNames } from '@edx/frontend-base';\n *\n * // This object can be of any shape or depth with subobjects/arrays.\n * const myObject = {\n * myKey: 'my value',\n * }\n *\n * const result = convertKeyNames(myObject, { myKey: 'their_key' });\n *\n * console.log(result) // { their_key: 'my value' }\n * ```\n *\n * Can accept arrays as well as objects, and will perform its conversion on any objects it finds in\n * the array.\n *\n * @param {Array|Object} object\n * @param {Object} nameMap\n * @returns {Array|Object}\n */\nexport function convertKeyNames(object, nameMap) {\n const transformer = key => (nameMap[key] === undefined ? key : nameMap[key]);\n\n return modifyObjectKeys(object, transformer);\n}\n\n/**\n * *Deprecated*: A method which converts the supplied query string into an object of\n * key-value pairs and returns it. Defaults to the current query string - should perform like\n * [window.searchParams](https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams)\n *\n * @deprecated\n * @param {string} [search=global.location.search]\n * @returns {Object}\n */\nexport function getQueryParameters(search = global.location.search) {\n const keyValueFragments = search\n .slice(search.indexOf('?') + 1)\n .split('&')\n .filter(hash => hash !== '');\n\n return keyValueFragments.reduce((params, keyValueFragment) => {\n const split = keyValueFragment.indexOf('=');\n const key = keyValueFragment.slice(0, split);\n const value = keyValueFragment.slice(split + 1);\n return Object.assign(params, { [key]: decodeURIComponent(value) });\n }, {});\n}\n\n/**\n * This function helps catch a certain class of misconfiguration in which configuration variables\n * are not properly defined and/or supplied to a consumer that requires them. Any key that exists\n * is still set to \"undefined\" indicates a misconfiguration further up in the application, and\n * should be flagged as an error, and is logged to 'warn'.\n *\n * Keys that are intended to be falsy should be defined using null, 0, false, etc.\n *\n * @param {Object} object\n * @param {string} requester A human-readable identifier for the code which called this function.\n * Used when throwing errors to aid in debugging.\n */\nexport function ensureDefinedConfig(object, requester) {\n Object.keys(object).forEach((key) => {\n if (object[key] === undefined) {\n // eslint-disable-next-line no-console\n console.warn(`Module configuration error: ${key} is required by ${requester}.`);\n }\n });\n}\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM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