@openedx/frontend-base 1.0.0-alpha.27 → 1.0.0-alpha.28

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.
@@ -4,6 +4,7 @@ export { getSiteConfig, setSiteConfig, mergeSiteConfig, addAppConfigs, getAppCon
4
4
  export * from './constants';
5
5
  export { configureI18n, createIntl, defineMessages, FormattedDate, FormattedMessage, FormattedNumber, FormattedPlural, FormattedRelativeTime, FormattedTime, getLocale, getLocalizedLanguageName, getMessages, getPrimaryLanguageSubtag, getSupportedLanguageList, handleRtl, injectIntl, IntlProvider, intlShape, isRtl, LOCALE_CHANGED, LOCALE_TOPIC, mergeMessages, updateLocale, useIntl } from './i18n';
6
6
  export { auth, getBasename, initError, initialize } from './initialize';
7
+ export { loadExternalScripts } from './scripts';
7
8
  export { configureLogging, getLoggingService, logError, logInfo, MockLoggingService, NewRelicLoggingService, resetLoggingService } from './logging';
8
9
  export { CurrentAppContext, CurrentAppProvider, SiteContext, SiteProvider, AuthenticatedPageRoute, Divider, ErrorBoundary, ErrorPage, LoginRedirect, PageWrap, useSiteEvent, useAuthenticatedUser, useSiteConfig, useAppConfig } from './react';
9
10
  export { authenticatedLoader, getUrlByRouteRole, isRoleRouteObject } from './routing';
@@ -4,6 +4,7 @@ export { getSiteConfig, setSiteConfig, mergeSiteConfig, addAppConfigs, getAppCon
4
4
  export * from './constants';
5
5
  export { configureI18n, createIntl, defineMessages, FormattedDate, FormattedMessage, FormattedNumber, FormattedPlural, FormattedRelativeTime, FormattedTime, getLocale, getLocalizedLanguageName, getMessages, getPrimaryLanguageSubtag, getSupportedLanguageList, handleRtl, injectIntl, IntlProvider, intlShape, isRtl, LOCALE_CHANGED, LOCALE_TOPIC, mergeMessages, updateLocale, useIntl } from './i18n';
6
6
  export { auth, getBasename, initError, initialize } from './initialize';
7
+ export { loadExternalScripts } from './scripts';
7
8
  export { configureLogging, getLoggingService, logError, logInfo, MockLoggingService, NewRelicLoggingService, resetLoggingService } from './logging';
8
9
  export { CurrentAppContext, CurrentAppProvider, SiteContext, SiteProvider, AuthenticatedPageRoute, Divider, ErrorBoundary, ErrorPage, LoginRedirect, PageWrap, useSiteEvent, useAuthenticatedUser, useSiteConfig, useAppConfig } from './react';
9
10
  export { authenticatedLoader, getUrlByRouteRole, isRoleRouteObject } from './routing';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,EACf,aAAa,EACb,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAElB,cAAc,aAAa,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,wBAAwB,EACxB,WAAW,EACX,wBAAwB,EACxB,wBAAwB,EACxB,SAAS,EACT,UAAU,EACV,YAAY,EACZ,SAAS,EACT,KAAK,EACL,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,OAAO,EACR,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,IAAI,EACJ,WAAW,EACX,SAAS,EACT,UAAU,EACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,OAAO,EACP,aAAa,EACb,SAAS,EACT,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,SAAS,EACT,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,iBAAiB,EACjB,YAAY,EACb,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,cAAc,SAAS,CAAC","sourcesContent":["export {\n configureAnalytics,\n getAnalyticsService,\n identifyAnonymousUser,\n identifyAuthenticatedUser,\n MockAnalyticsService,\n resetAnalyticsService,\n SegmentAnalyticsService,\n sendPageEvent,\n sendTrackEvent,\n sendTrackingLogEvent\n} from './analytics';\n\nexport {\n AUTHENTICATED_USER_CHANGED,\n AUTHENTICATED_USER_TOPIC,\n AxiosJwtAuthService,\n configureAuth,\n ensureAuthenticatedUser,\n fetchAuthenticatedUser,\n getAuthenticatedHttpClient,\n getAuthenticatedUser,\n getAuthService,\n getHttpClient,\n getLoginRedirectUrl,\n getLogoutRedirectUrl,\n hydrateAuthenticatedUser,\n MockAuthService,\n redirectToLogin,\n redirectToLogout,\n setAuthenticatedUser\n} from './auth';\n\nexport {\n getSiteConfig,\n setSiteConfig,\n mergeSiteConfig,\n addAppConfigs,\n getAppConfig,\n mergeAppConfig,\n setActiveRouteRoles,\n getActiveRouteRoles,\n addActiveWidgetRole,\n removeActiveWidgetRole,\n getActiveWidgetRoles,\n getActiveRoles,\n getExternalLinkUrl,\n getProvides,\n getProvidesAsStrings\n} from './config';\n\nexport * from './constants';\n\nexport {\n configureI18n,\n createIntl,\n defineMessages,\n FormattedDate,\n FormattedMessage,\n FormattedNumber,\n FormattedPlural,\n FormattedRelativeTime,\n FormattedTime,\n getLocale,\n getLocalizedLanguageName,\n getMessages,\n getPrimaryLanguageSubtag,\n getSupportedLanguageList,\n handleRtl,\n injectIntl,\n IntlProvider,\n intlShape,\n isRtl,\n LOCALE_CHANGED,\n LOCALE_TOPIC,\n mergeMessages,\n updateLocale,\n useIntl\n} from './i18n';\n\nexport {\n auth,\n getBasename,\n initError,\n initialize\n} from './initialize';\n\nexport {\n configureLogging,\n getLoggingService,\n logError,\n logInfo,\n MockLoggingService,\n NewRelicLoggingService,\n resetLoggingService\n} from './logging';\n\nexport {\n CurrentAppContext,\n CurrentAppProvider,\n SiteContext,\n SiteProvider,\n AuthenticatedPageRoute,\n Divider,\n ErrorBoundary,\n ErrorPage,\n LoginRedirect,\n PageWrap,\n useSiteEvent,\n useAuthenticatedUser,\n useSiteConfig,\n useAppConfig\n} from './react';\n\nexport {\n authenticatedLoader,\n getUrlByRouteRole,\n isRoleRouteObject\n} from './routing';\n\nexport {\n clearAllSubscriptions,\n publish,\n subscribe,\n unsubscribe\n} from './subscriptions';\n\nexport {\n initializeMockApp,\n mockMessages\n} from './testing';\n\nexport {\n camelCaseObject,\n convertKeyNames,\n getQueryParameters,\n isValidVariableName,\n modifyObjectKeys,\n snakeCaseObject\n} from './utils';\n\nexport * from './slots';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,aAAa,EACb,cAAc,EACd,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,aAAa,EACb,aAAa,EACb,eAAe,EACf,aAAa,EACb,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAElB,cAAc,aAAa,CAAC;AAE5B,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,wBAAwB,EACxB,WAAW,EACX,wBAAwB,EACxB,wBAAwB,EACxB,SAAS,EACT,UAAU,EACV,YAAY,EACZ,SAAS,EACT,KAAK,EACL,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,OAAO,EACR,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,IAAI,EACJ,WAAW,EACX,SAAS,EACT,UAAU,EACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,mBAAmB,EACpB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,sBAAsB,EACtB,OAAO,EACP,aAAa,EACb,SAAS,EACT,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,SAAS,EACT,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,iBAAiB,EACjB,YAAY,EACb,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,cAAc,SAAS,CAAC","sourcesContent":["export {\n configureAnalytics,\n getAnalyticsService,\n identifyAnonymousUser,\n identifyAuthenticatedUser,\n MockAnalyticsService,\n resetAnalyticsService,\n SegmentAnalyticsService,\n sendPageEvent,\n sendTrackEvent,\n sendTrackingLogEvent\n} from './analytics';\n\nexport {\n AUTHENTICATED_USER_CHANGED,\n AUTHENTICATED_USER_TOPIC,\n AxiosJwtAuthService,\n configureAuth,\n ensureAuthenticatedUser,\n fetchAuthenticatedUser,\n getAuthenticatedHttpClient,\n getAuthenticatedUser,\n getAuthService,\n getHttpClient,\n getLoginRedirectUrl,\n getLogoutRedirectUrl,\n hydrateAuthenticatedUser,\n MockAuthService,\n redirectToLogin,\n redirectToLogout,\n setAuthenticatedUser\n} from './auth';\n\nexport {\n getSiteConfig,\n setSiteConfig,\n mergeSiteConfig,\n addAppConfigs,\n getAppConfig,\n mergeAppConfig,\n setActiveRouteRoles,\n getActiveRouteRoles,\n addActiveWidgetRole,\n removeActiveWidgetRole,\n getActiveWidgetRoles,\n getActiveRoles,\n getExternalLinkUrl,\n getProvides,\n getProvidesAsStrings\n} from './config';\n\nexport * from './constants';\n\nexport {\n configureI18n,\n createIntl,\n defineMessages,\n FormattedDate,\n FormattedMessage,\n FormattedNumber,\n FormattedPlural,\n FormattedRelativeTime,\n FormattedTime,\n getLocale,\n getLocalizedLanguageName,\n getMessages,\n getPrimaryLanguageSubtag,\n getSupportedLanguageList,\n handleRtl,\n injectIntl,\n IntlProvider,\n intlShape,\n isRtl,\n LOCALE_CHANGED,\n LOCALE_TOPIC,\n mergeMessages,\n updateLocale,\n useIntl\n} from './i18n';\n\nexport {\n auth,\n getBasename,\n initError,\n initialize\n} from './initialize';\n\nexport {\n loadExternalScripts\n} from './scripts';\n\nexport {\n configureLogging,\n getLoggingService,\n logError,\n logInfo,\n MockLoggingService,\n NewRelicLoggingService,\n resetLoggingService\n} from './logging';\n\nexport {\n CurrentAppContext,\n CurrentAppProvider,\n SiteContext,\n SiteProvider,\n AuthenticatedPageRoute,\n Divider,\n ErrorBoundary,\n ErrorPage,\n LoginRedirect,\n PageWrap,\n useSiteEvent,\n useAuthenticatedUser,\n useSiteConfig,\n useAppConfig\n} from './react';\n\nexport {\n authenticatedLoader,\n getUrlByRouteRole,\n isRoleRouteObject\n} from './routing';\n\nexport {\n clearAllSubscriptions,\n publish,\n subscribe,\n unsubscribe\n} from './subscriptions';\n\nexport {\n initializeMockApp,\n mockMessages\n} from './testing';\n\nexport {\n camelCaseObject,\n convertKeyNames,\n getQueryParameters,\n isValidVariableName,\n modifyObjectKeys,\n snakeCaseObject\n} from './utils';\n\nexport * from './slots';\n"]}
@@ -20,7 +20,6 @@ export function initError(error: any): Promise<void>;
20
20
  * @param {boolean} hydrateUser Whether or not we should fetch additional user account data.
21
21
  */
22
22
  export function auth(requireUser: boolean, hydrateUser: boolean): Promise<void>;
23
- export function loadExternalScripts(externalScripts: any, data: any): void;
24
23
  /**
25
24
  * The default handler for the initialization lifecycle's `analytics` phase.
26
25
  *
@@ -62,8 +61,6 @@ export function analytics(): Promise<void>;
62
61
  * @param {*} [options.analyticsService=SegmentAnalyticsService] The `AnalyticsService`
63
62
  * implementation to use.
64
63
  * @param {*} [options.authMiddleware=[]] An array of middleware to apply to http clients in the auth service.
65
- * @param {*} [options.externalScripts=[GoogleAnalyticsLoader]] An array of externalScripts.
66
- * By default added GoogleAnalyticsLoader.
67
64
  * @param {*} [options.requireAuthenticatedUser=false] If true, turns on automatic login
68
65
  * redirection for unauthenticated users. Defaults to false, meaning that by default the
69
66
  * application will allow anonymous/unauthenticated sessions.
@@ -78,11 +75,10 @@ export function analytics(): Promise<void>;
78
75
  * default behavior of any part of the startup sequence. It can also be used to add additional
79
76
  * initialization behavior before or after the rest of the sequence.
80
77
  */
81
- export function initialize({ loggingService, analyticsService, authService, authMiddleware, externalScripts, requireAuthenticatedUser: requireUser, hydrateAuthenticatedUser: hydrateUser, messages, handlers: overrideHandlers, }?: {
78
+ export function initialize({ loggingService, analyticsService, authService, authMiddleware, requireAuthenticatedUser: requireUser, hydrateAuthenticatedUser: hydrateUser, messages, handlers: overrideHandlers, }?: {
82
79
  loggingService?: any;
83
80
  analyticsService?: any;
84
81
  authMiddleware?: any;
85
- externalScripts?: any;
86
82
  requireAuthenticatedUser?: any;
87
83
  hydrateAuthenticatedUser?: any;
88
84
  messages?: any;
@@ -67,7 +67,6 @@ import { getSiteConfig, mergeSiteConfig, } from './config';
67
67
  import { SITE_ANALYTICS_INITIALIZED, SITE_AUTH_INITIALIZED, SITE_CONFIG_INITIALIZED, SITE_I18N_INITIALIZED, SITE_INIT_ERROR, SITE_LOGGING_INITIALIZED, SITE_PUBSUB_INITIALIZED, SITE_READY, } from './constants';
68
68
  import { configureI18n } from './i18n';
69
69
  import { configureLogging, getLoggingService, logError, NewRelicLoggingService, } from './logging';
70
- import { GoogleAnalyticsLoader } from './scripts';
71
70
  import { publish } from './subscriptions';
72
71
  import { EnvironmentTypes } from '../types';
73
72
  /**
@@ -169,12 +168,6 @@ function runtimeConfig() {
169
168
  }
170
169
  });
171
170
  }
172
- export function loadExternalScripts(externalScripts, data) {
173
- externalScripts.forEach(ExternalScript => {
174
- const script = new ExternalScript(data);
175
- script.loadScript();
176
- });
177
- }
178
171
  /**
179
172
  * The default handler for the initialization lifecycle's `analytics` phase.
180
173
  *
@@ -231,8 +224,6 @@ function applyOverrideHandlers(overrides) {
231
224
  * @param {*} [options.analyticsService=SegmentAnalyticsService] The `AnalyticsService`
232
225
  * implementation to use.
233
226
  * @param {*} [options.authMiddleware=[]] An array of middleware to apply to http clients in the auth service.
234
- * @param {*} [options.externalScripts=[GoogleAnalyticsLoader]] An array of externalScripts.
235
- * By default added GoogleAnalyticsLoader.
236
227
  * @param {*} [options.requireAuthenticatedUser=false] If true, turns on automatic login
237
228
  * redirection for unauthenticated users. Defaults to false, meaning that by default the
238
229
  * application will allow anonymous/unauthenticated sessions.
@@ -248,7 +239,7 @@ function applyOverrideHandlers(overrides) {
248
239
  * initialization behavior before or after the rest of the sequence.
249
240
  */
250
241
  export function initialize(_a) {
251
- return __awaiter(this, arguments, void 0, function* ({ loggingService = NewRelicLoggingService, analyticsService = SegmentAnalyticsService, authService = AxiosJwtAuthService, authMiddleware = [], externalScripts = [GoogleAnalyticsLoader], requireAuthenticatedUser: requireUser = false, hydrateAuthenticatedUser: hydrateUser = false, messages, handlers: overrideHandlers = {}, }) {
242
+ return __awaiter(this, arguments, void 0, function* ({ loggingService = NewRelicLoggingService, analyticsService = SegmentAnalyticsService, authService = AxiosJwtAuthService, authMiddleware = [], requireAuthenticatedUser: requireUser = false, hydrateAuthenticatedUser: hydrateUser = false, messages, handlers: overrideHandlers = {}, }) {
252
243
  var _b, _c, _d;
253
244
  const handlers = applyOverrideHandlers(overrideHandlers);
254
245
  try {
@@ -260,14 +251,13 @@ export function initialize(_a) {
260
251
  yield handlers.config();
261
252
  yield runtimeConfig();
262
253
  publish(SITE_CONFIG_INITIALIZED);
263
- loadExternalScripts(externalScripts, {
264
- config: getSiteConfig(),
265
- });
266
- // This allows us to replace the implementations of the logging, analytics, and auth services
267
- // based on keys in the SiteConfig. The JavaScript File Configuration method is the only
268
- // one capable of supplying an alternate implementation since it can import other modules.
269
- // If a service wasn't supplied we fall back to the default parameters on the initialize
270
- // function signature.
254
+ /*
255
+ * This allows us to replace the implementations of the logging, analytics, and auth
256
+ * services based on keys in the SiteConfig. The JavaScript File Configuration method is
257
+ * the only one capable of supplying an alternate implementation since it can import other
258
+ * modules. If a service wasn't supplied we fall back to the default parameters on the
259
+ * initialize function signature.
260
+ */
271
261
  const loggingServiceImpl = (_b = getSiteConfig().loggingService) !== null && _b !== void 0 ? _b : loggingService;
272
262
  const analyticsServiceImpl = (_c = getSiteConfig().analyticsService) !== null && _c !== void 0 ? _c : analyticsService;
273
263
  const authServiceImpl = (_d = getSiteConfig().authService) !== null && _d !== void 0 ? _d : authService;
@@ -1 +1 @@
1
- {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../runtime/initialize.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;;;;;;;;;;AAEH;;;EAGE;AACF,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,QAAQ,CAAC;AAChB,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EACL,aAAa,EAAE,eAAe,GAC/B,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,EACf,wBAAwB,EACxB,uBAAuB,EACvB,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ACvB,cAAc,EAAE,iBAAiB,EAAE;gBACnC,UAAU,EAAE,0BAA0B,EAAE;aACzC,CAAC,CAAC;YACH,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAC;YAC3B,OAAO,CAAC,0BAA0B,CAAC,CAAC;YAEpC,oBAAoB;YACpB,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;YACvB,OAAO,CAAC,UAAU,CAAC,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;gBACzB,uBAAuB;gBACvB,MAAM,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBAChC,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;IACH,CAAC;CAAA","sourcesContent":["/**\n * #### Import members from **@openedx/frontend-base**\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 * SITE_INIT_ERROR,\n * SITE_READY,\n * subscribe,\n * SiteProvider,\n * ErrorPage,\n * PageWrap\n * } from '@openedx/frontend-base';\n * import React from 'react';\n * import ReactDOM from 'react-dom';\n * import { Routes, Route } from 'react-router-dom';\n *\n * subscribe(SITE_READY, () => {\n * ReactDOM.render(\n * <SiteProvider>\n * <Header />\n * <main>\n * <Routes>\n * <Route path=\"/\" element={<PageWrap><PaymentPage /></PageWrap>} />\n * </Routes>\n * </main>\n * <Footer />\n * </SiteProvider>,\n * document.getElementById('root'),\n * );\n * });\n *\n * subscribe(SITE_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\n/*\nThis 'site.config' package is a special 'magic' alias in our webpack configuration in the `config`\nfolder. It points at an `site.config.tsx` file in the root of a site's repository.\n*/\nimport siteConfig from 'site.config';\nimport {\n configureAnalytics,\n identifyAnonymousUser,\n identifyAuthenticatedUser,\n SegmentAnalyticsService,\n} from './analytics';\nimport {\n AxiosJwtAuthService,\n configureAuth,\n ensureAuthenticatedUser,\n fetchAuthenticatedUser,\n getAuthenticatedHttpClient,\n getAuthenticatedUser,\n hydrateAuthenticatedUser,\n} from './auth';\nimport configureCache from './auth/LocalForageCache';\nimport {\n getSiteConfig, mergeSiteConfig,\n} from './config';\nimport {\n SITE_ANALYTICS_INITIALIZED,\n SITE_AUTH_INITIALIZED,\n SITE_CONFIG_INITIALIZED,\n SITE_I18N_INITIALIZED,\n SITE_INIT_ERROR,\n SITE_LOGGING_INITIALIZED,\n SITE_PUBSUB_INITIALIZED,\n SITE_READY,\n} from './constants';\nimport { configureI18n } from './i18n';\nimport {\n configureLogging,\n getLoggingService,\n logError,\n NewRelicLoggingService,\n} from './logging';\nimport { GoogleAnalyticsLoader } from './scripts';\nimport { publish } from './subscriptions';\nimport { EnvironmentTypes } from '../types';\n\n/**\n * If set in configuration, a basename will be prepended to all relative routes under BrowserRouter.\n *\n * Unlike webpack's publicPath, the basename cannot be auto-discovered, so when publicPath is set\n * (or when it's set to 'auto' and the site is being served from a path other than '/') this\n * needs to be configured.\n */\nexport const getBasename = () => getSiteConfig().basename;\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-base~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(globalThis.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 * Set or overrides configuration via an site.config.tsx file in the consuming application.\n * This site.config.tsx is loaded at runtime and must export one of two things:\n *\n * - An object which will be merged into the application config via `mergeSiteConfig`.\n * - A function which returns an object which will be merged into the application config via\n * `mergeSiteConfig`. This function can return a promise.\n */\nasync function fileConfig() {\n let config = {};\n if (typeof siteConfig === 'function') {\n config = await siteConfig();\n } else {\n config = siteConfig;\n }\n\n mergeSiteConfig(config);\n}\n\n/*\n * Set or overrides configuration through an API.\n * This method allows runtime configuration.\n * Set a basic configuration when an error happen and allow initError and display the ErrorPage.\n */\nasync function runtimeConfig() {\n try {\n const { runtimeConfigJsonUrl, environment } = getSiteConfig();\n\n if (runtimeConfigJsonUrl) {\n const apiConfig = { headers: { accept: 'application/json' } };\n const apiService = await configureCache();\n\n const runtimeConfigUrl = new URL(runtimeConfigJsonUrl, window.location.origin);\n\n // In development mode, add a timestamp as a cache buster\n // to support live-editing runtime config JSON\n if (environment === EnvironmentTypes.DEVELOPMENT) {\n runtimeConfigUrl.searchParams.set('timestamp', Date.now());\n }\n\n const { data } = await apiService.get(runtimeConfigUrl.toString(), apiConfig);\n if (!data || typeof data !== 'object' || Array.isArray(data)) {\n throw new TypeError('Runtime config must be a valid JSON object.');\n }\n mergeSiteConfig(data, { limitAppMergeToConfig: true });\n }\n } catch (error) {\n console.error('Error with config API:', error.message);\n }\n}\n\nexport function loadExternalScripts(externalScripts, data) {\n externalScripts.forEach(ExternalScript => {\n const script = new ExternalScript(data);\n script.loadScript();\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?.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.externalScripts=[GoogleAnalyticsLoader]] An array of externalScripts.\n * By default added GoogleAnalyticsLoader.\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.lmsBaseUrl}/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 externalScripts = [GoogleAnalyticsLoader],\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(SITE_PUBSUB_INITIALIZED);\n\n // Configuration\n await fileConfig();\n await handlers.config();\n await runtimeConfig();\n publish(SITE_CONFIG_INITIALIZED);\n\n loadExternalScripts(externalScripts, {\n config: getSiteConfig(),\n });\n\n // This allows us to replace the implementations of the logging, analytics, and auth services\n // based on keys in the SiteConfig. The JavaScript File Configuration method is the only\n // one capable of supplying an alternate implementation since it can import other modules.\n // If a service wasn't supplied we fall back to the default parameters on the initialize\n // function signature.\n const loggingServiceImpl = getSiteConfig().loggingService ?? loggingService;\n const analyticsServiceImpl = getSiteConfig().analyticsService ?? analyticsService;\n const authServiceImpl = getSiteConfig().authService ?? authService;\n\n // Logging\n configureLogging(loggingServiceImpl, {\n config: getSiteConfig(),\n });\n await handlers.logging();\n publish(SITE_LOGGING_INITIALIZED);\n\n // Internationalization\n configureI18n({\n messages,\n });\n await handlers.i18n();\n publish(SITE_I18N_INITIALIZED);\n\n // Authentication\n configureAuth(authServiceImpl, {\n loggingService: getLoggingService(),\n config: getSiteConfig(),\n middleware: authMiddleware,\n });\n\n await handlers.auth(requireUser, hydrateUser);\n publish(SITE_AUTH_INITIALIZED);\n\n // Analytics\n configureAnalytics(analyticsServiceImpl, {\n config: getSiteConfig(),\n loggingService: getLoggingService(),\n httpClient: getAuthenticatedHttpClient(),\n });\n await handlers.analytics();\n publish(SITE_ANALYTICS_INITIALIZED);\n\n // Application Ready\n await handlers.ready();\n publish(SITE_READY);\n } catch (error) {\n if (!error.isRedirecting) {\n // Initialization Error\n await handlers.initError(error);\n publish(SITE_INIT_ERROR, error);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../runtime/initialize.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;;;;;;;;;;AAEH;;;EAGE;AACF,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,QAAQ,CAAC;AAChB,OAAO,cAAc,MAAM,yBAAyB,CAAC;AACrD,OAAO,EACL,aAAa,EAAE,eAAe,GAC/B,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,EACf,wBAAwB,EACxB,uBAAuB,EACvB,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,sBAAsB,GACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EA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AE,CAAC;YACzB,OAAO,CAAC,wBAAwB,CAAC,CAAC;YAElC,uBAAuB;YACvB,aAAa,CAAC;gBACZ,QAAQ;aACT,CAAC,CAAC;YACH,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACtB,OAAO,CAAC,qBAAqB,CAAC,CAAC;YAE/B,iBAAiB;YACjB,aAAa,CAAC,eAAe,EAAE;gBAC7B,cAAc,EAAE,iBAAiB,EAAE;gBACnC,MAAM,EAAE,aAAa,EAAE;gBACvB,UAAU,EAAE,cAAc;aAC3B,CAAC,CAAC;YAEH,MAAM,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;YAC9C,OAAO,CAAC,qBAAqB,CAAC,CAAC;YAE/B,YAAY;YACZ,kBAAkB,CAAC,oBAAoB,EAAE;gBACvC,MAAM,EAAE,aAAa,EAAE;gBACvB,cAAc,EAAE,iBAAiB,EAAE;gBACnC,UAAU,EAAE,0BAA0B,EAAE;aACzC,CAAC,CAAC;YACH,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAC;YAC3B,OAAO,CAAC,0BAA0B,CAAC,CAAC;YAEpC,oBAAoB;YACpB,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;YACvB,OAAO,CAAC,UAAU,CAAC,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;gBACzB,uBAAuB;gBACvB,MAAM,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBAChC,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;IACH,CAAC;CAAA","sourcesContent":["/**\n * #### Import members from **@openedx/frontend-base**\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 * SITE_INIT_ERROR,\n * SITE_READY,\n * subscribe,\n * SiteProvider,\n * ErrorPage,\n * PageWrap\n * } from '@openedx/frontend-base';\n * import React from 'react';\n * import ReactDOM from 'react-dom';\n * import { Routes, Route } from 'react-router-dom';\n *\n * subscribe(SITE_READY, () => {\n * ReactDOM.render(\n * <SiteProvider>\n * <Header />\n * <main>\n * <Routes>\n * <Route path=\"/\" element={<PageWrap><PaymentPage /></PageWrap>} />\n * </Routes>\n * </main>\n * <Footer />\n * </SiteProvider>,\n * document.getElementById('root'),\n * );\n * });\n *\n * subscribe(SITE_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\n/*\nThis 'site.config' package is a special 'magic' alias in our webpack configuration in the `config`\nfolder. It points at an `site.config.tsx` file in the root of a site's repository.\n*/\nimport siteConfig from 'site.config';\nimport {\n configureAnalytics,\n identifyAnonymousUser,\n identifyAuthenticatedUser,\n SegmentAnalyticsService,\n} from './analytics';\nimport {\n AxiosJwtAuthService,\n configureAuth,\n ensureAuthenticatedUser,\n fetchAuthenticatedUser,\n getAuthenticatedHttpClient,\n getAuthenticatedUser,\n hydrateAuthenticatedUser,\n} from './auth';\nimport configureCache from './auth/LocalForageCache';\nimport {\n getSiteConfig, mergeSiteConfig,\n} from './config';\nimport {\n SITE_ANALYTICS_INITIALIZED,\n SITE_AUTH_INITIALIZED,\n SITE_CONFIG_INITIALIZED,\n SITE_I18N_INITIALIZED,\n SITE_INIT_ERROR,\n SITE_LOGGING_INITIALIZED,\n SITE_PUBSUB_INITIALIZED,\n SITE_READY,\n} from './constants';\nimport { configureI18n } from './i18n';\nimport {\n configureLogging,\n getLoggingService,\n logError,\n NewRelicLoggingService,\n} from './logging';\nimport { publish } from './subscriptions';\nimport { EnvironmentTypes } from '../types';\n\n/**\n * If set in configuration, a basename will be prepended to all relative routes under BrowserRouter.\n *\n * Unlike webpack's publicPath, the basename cannot be auto-discovered, so when publicPath is set\n * (or when it's set to 'auto' and the site is being served from a path other than '/') this\n * needs to be configured.\n */\nexport const getBasename = () => getSiteConfig().basename;\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-base~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(globalThis.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 * Set or overrides configuration via an site.config.tsx file in the consuming application.\n * This site.config.tsx is loaded at runtime and must export one of two things:\n *\n * - An object which will be merged into the application config via `mergeSiteConfig`.\n * - A function which returns an object which will be merged into the application config via\n * `mergeSiteConfig`. This function can return a promise.\n */\nasync function fileConfig() {\n let config = {};\n if (typeof siteConfig === 'function') {\n config = await siteConfig();\n } else {\n config = siteConfig;\n }\n\n mergeSiteConfig(config);\n}\n\n/*\n * Set or overrides configuration through an API.\n * This method allows runtime configuration.\n * Set a basic configuration when an error happen and allow initError and display the ErrorPage.\n */\nasync function runtimeConfig() {\n try {\n const { runtimeConfigJsonUrl, environment } = getSiteConfig();\n\n if (runtimeConfigJsonUrl) {\n const apiConfig = { headers: { accept: 'application/json' } };\n const apiService = await configureCache();\n\n const runtimeConfigUrl = new URL(runtimeConfigJsonUrl, window.location.origin);\n\n // In development mode, add a timestamp as a cache buster\n // to support live-editing runtime config JSON\n if (environment === EnvironmentTypes.DEVELOPMENT) {\n runtimeConfigUrl.searchParams.set('timestamp', Date.now());\n }\n\n const { data } = await apiService.get(runtimeConfigUrl.toString(), apiConfig);\n if (!data || typeof data !== 'object' || Array.isArray(data)) {\n throw new TypeError('Runtime config must be a valid JSON object.');\n }\n mergeSiteConfig(data, { limitAppMergeToConfig: true });\n }\n } catch (error) {\n console.error('Error with config API:', error.message);\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?.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.lmsBaseUrl}/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(SITE_PUBSUB_INITIALIZED);\n\n // Configuration\n await fileConfig();\n await handlers.config();\n await runtimeConfig();\n publish(SITE_CONFIG_INITIALIZED);\n\n /*\n * This allows us to replace the implementations of the logging, analytics, and auth\n * services based on keys in the SiteConfig. The JavaScript File Configuration method is\n * the only one capable of supplying an alternate implementation since it can import other\n * modules. If a service wasn't supplied we fall back to the default parameters on the\n * initialize function signature.\n */\n const loggingServiceImpl = getSiteConfig().loggingService ?? loggingService;\n const analyticsServiceImpl = getSiteConfig().analyticsService ?? analyticsService;\n const authServiceImpl = getSiteConfig().authService ?? authService;\n\n // Logging\n configureLogging(loggingServiceImpl, {\n config: getSiteConfig(),\n });\n await handlers.logging();\n publish(SITE_LOGGING_INITIALIZED);\n\n // Internationalization\n configureI18n({\n messages,\n });\n await handlers.i18n();\n publish(SITE_I18N_INITIALIZED);\n\n // Authentication\n configureAuth(authServiceImpl, {\n loggingService: getLoggingService(),\n config: getSiteConfig(),\n middleware: authMiddleware,\n });\n\n await handlers.auth(requireUser, hydrateUser);\n publish(SITE_AUTH_INITIALIZED);\n\n // Analytics\n configureAnalytics(analyticsServiceImpl, {\n config: getSiteConfig(),\n loggingService: getLoggingService(),\n httpClient: getAuthenticatedHttpClient(),\n });\n await handlers.analytics();\n publish(SITE_ANALYTICS_INITIALIZED);\n\n // Application Ready\n await handlers.ready();\n publish(SITE_READY);\n } catch (error) {\n if (!error.isRedirecting) {\n // Initialization Error\n await handlers.initError(error);\n publish(SITE_INIT_ERROR, error);\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- export { default as GoogleAnalyticsLoader } from './GoogleAnalyticsLoader';
1
+ export declare function loadExternalScripts(): void;
@@ -1,2 +1,14 @@
1
- export { default as GoogleAnalyticsLoader } from './GoogleAnalyticsLoader';
1
+ import { getAppConfig, getSiteConfig } from '../config';
2
+ export function loadExternalScripts() {
3
+ var _a;
4
+ const apps = (_a = getSiteConfig().apps) !== null && _a !== void 0 ? _a : [];
5
+ apps.forEach(app => {
6
+ var _a, _b;
7
+ const config = (_a = getAppConfig(app.appId)) !== null && _a !== void 0 ? _a : {};
8
+ ((_b = app.externalScripts) !== null && _b !== void 0 ? _b : []).forEach(ExternalScript => {
9
+ const script = new ExternalScript({ config });
10
+ script.loadScript();
11
+ });
12
+ });
13
+ }
2
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/scripts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAC","sourcesContent":["export { default as GoogleAnalyticsLoader } from './GoogleAnalyticsLoader';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/scripts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,UAAU,mBAAmB;;IACjC,MAAM,IAAI,GAAG,MAAA,aAAa,EAAE,CAAC,IAAI,mCAAI,EAAE,CAAC;IACxC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;;QACjB,MAAM,MAAM,GAAG,MAAA,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAI,EAAE,CAAC;QAC7C,CAAC,MAAA,GAAG,CAAC,eAAe,mCAAI,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;YACnD,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YAC9C,MAAM,CAAC,UAAU,EAAE,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { getAppConfig, getSiteConfig } from '../config';\n\nexport function loadExternalScripts() {\n const apps = getSiteConfig().apps ?? [];\n apps.forEach(app => {\n const config = getAppConfig(app.appId) ?? {};\n (app.externalScripts ?? []).forEach(ExternalScript => {\n const script = new ExternalScript({ config });\n script.loadScript();\n });\n });\n}\n"]}
@@ -12,7 +12,7 @@ import { lazy, StrictMode, Suspense } from 'react';
12
12
  import { createRoot } from 'react-dom/client';
13
13
  import { RouterProvider } from 'react-router-dom';
14
14
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
15
- import { SITE_INIT_ERROR, SITE_READY, initialize, subscribe } from '../runtime';
15
+ import { SITE_INIT_ERROR, SITE_READY, initialize, loadExternalScripts, subscribe } from '../runtime';
16
16
  import { addAppConfigs } from '../runtime/config';
17
17
  import messages from 'site.i18n';
18
18
  import createRouter from './router/createRouter';
@@ -31,6 +31,7 @@ subscribe(SITE_READY, () => __awaiter(void 0, void 0, void 0, function* () {
31
31
  const queryClient = new QueryClient();
32
32
  const router = createRouter();
33
33
  addAppConfigs();
34
+ loadExternalScripts();
34
35
  const root = createRoot(document.getElementById('root'));
35
36
  root.render(_jsx(StrictMode, { children: _jsxs(QueryClientProvider, { client: queryClient, children: [_jsx(RouterProvider, { router: router }), ReactQueryDevtools && (_jsx(Suspense, { fallback: null, children: _jsx(ReactQueryDevtools, { initialIsOpen: false }) }))] }) }));
36
37
  }));
@@ -1 +1 @@
1
- {"version":3,"file":"site.js","sourceRoot":"","sources":["../../shell/site.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EACL,eAAe,EACf,UAAU,EACV,UAAU,EACV,SAAS,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,YAAY,MAAM,uBAAuB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;IAC/D,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,gCAAgC,CAAC;SAChD,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,kBAAkB,EAAE,CAAC,CAAC;SAChD,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC,IAAI,CAAC;AAET,SAAS,CAAC,UAAU,EAAE,GAAS,EAAE;IAC/B,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;IACtC,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;IAE9B,aAAa,EAAE,CAAC;IAEhB,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAgB,CAAC,CAAC;IACxE,IAAI,CAAC,MAAM,CACT,KAAC,UAAU,cACT,MAAC,mBAAmB,IAAC,MAAM,EAAE,WAAW,aACtC,KAAC,cAAc,IAAC,MAAM,EAAE,MAAM,GAAI,EACjC,kBAAkB,IAAI,CACrB,KAAC,QAAQ,IAAC,QAAQ,EAAE,IAAI,YACtB,KAAC,kBAAkB,IAAC,aAAa,EAAE,KAAK,GAAI,GACnC,CACZ,IACmB,GACX,CACd,CAAC;AACJ,CAAC,CAAA,CAAC,CAAC;AAEH,SAAS,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;IACnC,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAgB,CAAC,CAAC;IACxE,IAAI,CAAC,MAAM,CAAC,wBAAM,KAAK,CAAC,OAAO,GAAO,CAAC,CAAC;AAC1C,CAAC,CAAC,CAAC;AAEH,UAAU,CAAC;IACT,QAAQ;CACT,CAAC,CAAC","sourcesContent":["import { lazy, StrictMode, Suspense } from 'react';\nimport { createRoot } from 'react-dom/client';\nimport { RouterProvider } from 'react-router-dom';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\n\nimport {\n SITE_INIT_ERROR,\n SITE_READY,\n initialize,\n subscribe\n} from '../runtime';\nimport { addAppConfigs } from '../runtime/config';\nimport messages from 'site.i18n';\nimport createRouter from './router/createRouter';\n\n/*\n * Use a dynamic import guarded by process.env.NODE_ENV so that webpack\n * places the devtools in a separate async chunk that is only requested\n * in development. In production the ternary resolves to null and the\n * chunk is never loaded.\n */\nconst ReactQueryDevtools = process.env.NODE_ENV === 'development'\n ? lazy(() => import('@tanstack/react-query-devtools')\n .then((m) => ({ default: m.ReactQueryDevtools }))\n .catch(() => ({ default: () => null })))\n : null;\n\nsubscribe(SITE_READY, async () => {\n const queryClient = new QueryClient();\n const router = createRouter();\n\n addAppConfigs();\n\n const root = createRoot(document.getElementById('root') as HTMLElement);\n root.render(\n <StrictMode>\n <QueryClientProvider client={queryClient}>\n <RouterProvider router={router} />\n {ReactQueryDevtools && (\n <Suspense fallback={null}>\n <ReactQueryDevtools initialIsOpen={false} />\n </Suspense>\n )}\n </QueryClientProvider>\n </StrictMode>\n );\n});\n\nsubscribe(SITE_INIT_ERROR, (error) => {\n const root = createRoot(document.getElementById('root') as HTMLElement);\n root.render(<div>{error.message}</div>);\n});\n\ninitialize({\n messages,\n});\n"]}
1
+ {"version":3,"file":"site.js","sourceRoot":"","sources":["../../shell/site.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EACL,eAAe,EACf,UAAU,EACV,UAAU,EACV,mBAAmB,EACnB,SAAS,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,YAAY,MAAM,uBAAuB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;IAC/D,CAAC,CA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react-dom/client';\nimport { RouterProvider } from 'react-router-dom';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\n\nimport {\n SITE_INIT_ERROR,\n SITE_READY,\n initialize,\n loadExternalScripts,\n subscribe\n} from '../runtime';\nimport { addAppConfigs } from '../runtime/config';\nimport messages from 'site.i18n';\nimport createRouter from './router/createRouter';\n\n/*\n * Use a dynamic import guarded by process.env.NODE_ENV so that webpack\n * places the devtools in a separate async chunk that is only requested\n * in development. In production the ternary resolves to null and the\n * chunk is never loaded.\n */\nconst ReactQueryDevtools = process.env.NODE_ENV === 'development'\n ? lazy(() => import('@tanstack/react-query-devtools')\n .then((m) => ({ default: m.ReactQueryDevtools }))\n .catch(() => ({ default: () => null })))\n : null;\n\nsubscribe(SITE_READY, async () => {\n const queryClient = new QueryClient();\n const router = createRouter();\n\n addAppConfigs();\n loadExternalScripts();\n\n const root = createRoot(document.getElementById('root') as HTMLElement);\n root.render(\n <StrictMode>\n <QueryClientProvider client={queryClient}>\n <RouterProvider router={router} />\n {ReactQueryDevtools && (\n <Suspense fallback={null}>\n <ReactQueryDevtools initialIsOpen={false} />\n </Suspense>\n )}\n </QueryClientProvider>\n </StrictMode>\n );\n});\n\nsubscribe(SITE_INIT_ERROR, (error) => {\n const root = createRoot(document.getElementById('root') as HTMLElement);\n root.render(<div>{error.message}</div>);\n});\n\ninitialize({\n messages,\n});\n"]}
package/dist/types.d.ts CHANGED
@@ -23,9 +23,16 @@ export interface App {
23
23
  routes?: RoleRouteObject[];
24
24
  providers?: AppProvider[];
25
25
  slots?: SlotOperation[];
26
+ externalScripts?: ExternalScriptLoaderClass[];
26
27
  config?: AppConfig;
27
28
  provides?: Record<string, unknown>;
28
29
  }
30
+ export interface ExternalScriptLoader {
31
+ loadScript(): void;
32
+ }
33
+ export type ExternalScriptLoaderClass = new (data: {
34
+ config: AppConfig;
35
+ }) => ExternalScriptLoader;
29
36
  export interface RequiredSiteConfig {
30
37
  siteId: string;
31
38
  siteName: string;
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAiHA,MAAM,CAAN,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,6CAAyB,CAAA;IACzB,+CAA2B,CAAA;IAC3B,iCAAa,CAAA;AACf,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,QAI3B","sourcesContent":["import { FC, ReactElement, ReactNode } from 'react';\nimport { MessageDescriptor } from 'react-intl';\nimport { RouteObject } from 'react-router';\nimport { SlotOperation } from './runtime/slots/types';\n\n// Apps\n\nexport interface ExternalRoute {\n role: string,\n url: string,\n}\n\nexport type RoleRouteObject = RouteObject & {\n handle?: {\n /**\n * Route roles identify the purpose(s) a route fulfills in the site.\n */\n roles?: string[],\n },\n};\n\nexport type AppConfig = Record<string, unknown>;\n\nexport type AppProvider = FC<{ children?: ReactNode }>;\n\nexport interface App {\n appId: string,\n routes?: RoleRouteObject[],\n providers?: AppProvider[],\n slots?: SlotOperation[],\n config?: AppConfig,\n provides?: Record<string, unknown>,\n}\n\n// Site Config\n\nexport interface RequiredSiteConfig {\n siteId: string,\n siteName: string,\n baseUrl: string,\n\n // Backends\n lmsBaseUrl: string,\n\n // Frontends\n loginUrl: string,\n logoutUrl: string,\n}\n\nexport type LocalizedMessages = Record<string, Record<string, string>>;\nexport type SiteMessages = LocalizedMessages[];\n\nexport interface OptionalSiteConfig {\n // Site environment\n environment: EnvironmentTypes,\n\n // Apps, routes, and URLs\n apps: App[],\n basename: string,\n externalRoutes: ExternalRoute[],\n externalLinkUrlOverrides: string[],\n runtimeConfigJsonUrl: string | null,\n commonAppConfig: AppConfig,\n headerLogoImageUrl: string,\n\n // Theme\n theme: Theme,\n\n // Cookies\n accessTokenCookieName: string,\n languagePreferenceCookieName: string,\n userInfoCookieName: string,\n\n // Paths\n csrfTokenApiPath: string,\n refreshAccessTokenApiPath: string,\n\n // Logging\n ignoredErrorRegex: RegExp | null,\n\n // Analytics\n segmentKey: string | null,\n}\n\nexport type SiteConfig = RequiredSiteConfig & Partial<OptionalSiteConfig>;\n\nexport interface ThemeVariant {\n url: string,\n}\n\nexport interface ThemeDefaults {\n light?: string,\n dark?: string,\n}\n\nexport type ThemeVariants = Record<string, ThemeVariant>;\n\nexport interface Theme {\n core?: ThemeVariant,\n defaults?: ThemeDefaults,\n variants?: ThemeVariants,\n}\n\nexport interface User {\n administrator: boolean,\n email: string,\n name: string,\n roles: string[],\n userId: number,\n username: string,\n avatar: string,\n}\n\nexport enum EnvironmentTypes {\n PRODUCTION = 'production',\n DEVELOPMENT = 'development',\n TEST = 'test',\n}\n\n// Menu Items\n\nexport type MenuItemName = string | MessageDescriptor | ReactElement;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AA0HA,MAAM,CAAN,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,6CAAyB,CAAA;IACzB,+CAA2B,CAAA;IAC3B,iCAAa,CAAA;AACf,CAAC,EAJW,gBAAgB,KAAhB,gBAAgB,QAI3B","sourcesContent":["import { FC, ReactElement, ReactNode } from 'react';\nimport { MessageDescriptor } from 'react-intl';\nimport { RouteObject } from 'react-router';\nimport { SlotOperation } from './runtime/slots/types';\n\n// Apps\n\nexport interface ExternalRoute {\n role: string,\n url: string,\n}\n\nexport type RoleRouteObject = RouteObject & {\n handle?: {\n /**\n * Route roles identify the purpose(s) a route fulfills in the site.\n */\n roles?: string[],\n },\n};\n\nexport type AppConfig = Record<string, unknown>;\n\nexport type AppProvider = FC<{ children?: ReactNode }>;\n\nexport interface App {\n appId: string,\n routes?: RoleRouteObject[],\n providers?: AppProvider[],\n slots?: SlotOperation[],\n externalScripts?: ExternalScriptLoaderClass[],\n config?: AppConfig,\n provides?: Record<string, unknown>,\n}\n\n// External Scripts\n\nexport interface ExternalScriptLoader {\n loadScript(): void,\n}\n\nexport type ExternalScriptLoaderClass = new (data: { config: AppConfig }) => ExternalScriptLoader;\n\n// Site Config\n\nexport interface RequiredSiteConfig {\n siteId: string,\n siteName: string,\n baseUrl: string,\n\n // Backends\n lmsBaseUrl: string,\n\n // Frontends\n loginUrl: string,\n logoutUrl: string,\n}\n\nexport type LocalizedMessages = Record<string, Record<string, string>>;\nexport type SiteMessages = LocalizedMessages[];\n\nexport interface OptionalSiteConfig {\n // Site environment\n environment: EnvironmentTypes,\n\n // Apps, routes, and URLs\n apps: App[],\n basename: string,\n externalRoutes: ExternalRoute[],\n externalLinkUrlOverrides: string[],\n runtimeConfigJsonUrl: string | null,\n commonAppConfig: AppConfig,\n headerLogoImageUrl: string,\n\n // Theme\n theme: Theme,\n\n // Cookies\n accessTokenCookieName: string,\n languagePreferenceCookieName: string,\n userInfoCookieName: string,\n\n // Paths\n csrfTokenApiPath: string,\n refreshAccessTokenApiPath: string,\n\n // Logging\n ignoredErrorRegex: RegExp | null,\n\n // Analytics\n segmentKey: string | null,\n}\n\nexport type SiteConfig = RequiredSiteConfig & Partial<OptionalSiteConfig>;\n\nexport interface ThemeVariant {\n url: string,\n}\n\nexport interface ThemeDefaults {\n light?: string,\n dark?: string,\n}\n\nexport type ThemeVariants = Record<string, ThemeVariant>;\n\nexport interface Theme {\n core?: ThemeVariant,\n defaults?: ThemeDefaults,\n variants?: ThemeVariants,\n}\n\nexport interface User {\n administrator: boolean,\n email: string,\n name: string,\n roles: string[],\n userId: number,\n username: string,\n avatar: string,\n}\n\nexport enum EnvironmentTypes {\n PRODUCTION = 'production',\n DEVELOPMENT = 'development',\n TEST = 'test',\n}\n\n// Menu Items\n\nexport type MenuItemName = string | MessageDescriptor | ReactElement;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openedx/frontend-base",
3
- "version": "1.0.0-alpha.27",
3
+ "version": "1.0.0-alpha.28",
4
4
  "description": "Build tools, setup and config for frontend apps",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,12 +0,0 @@
1
- /**
2
- * @implements {GoogleAnalyticsLoader}
3
- * @memberof module:GoogleAnalytics
4
- */
5
- declare class GoogleAnalyticsLoader {
6
- analyticsId: string;
7
- constructor({ config }: {
8
- config: any;
9
- });
10
- loadScript(): void;
11
- }
12
- export default GoogleAnalyticsLoader;
@@ -1,49 +0,0 @@
1
- /**
2
- * @implements {GoogleAnalyticsLoader}
3
- * @memberof module:GoogleAnalytics
4
- */
5
- class GoogleAnalyticsLoader {
6
- constructor({ config }) {
7
- this.analyticsId = config.GOOGLE_ANALYTICS_4_ID;
8
- }
9
- loadScript() {
10
- if (!this.analyticsId) {
11
- return;
12
- }
13
- global.googleAnalytics = global.googleAnalytics || [];
14
- // @ts-expect-error We just added googleAnalytics to global, it's there.
15
- const { googleAnalytics } = global;
16
- // If the snippet was invoked do nothing.
17
- if (googleAnalytics.invoked) {
18
- return;
19
- }
20
- // Invoked flag, to make sure the snippet
21
- // is never invoked twice.
22
- googleAnalytics.invoked = true;
23
- googleAnalytics.load = (key, options) => {
24
- const scriptSrc = document.createElement('script');
25
- scriptSrc.type = 'text/javascript';
26
- scriptSrc.async = true;
27
- scriptSrc.src = `https://www.googletagmanager.com/gtag/js?id=${key}`;
28
- const scriptGtag = document.createElement('script');
29
- scriptGtag.innerHTML = `
30
- window.dataLayer = window.dataLayer || [];
31
- function gtag(){dataLayer.push(arguments);}
32
- gtag('js', new Date());
33
- gtag('config', '${key}');
34
- `;
35
- // Insert our scripts next to the first script element.
36
- const first = document.getElementsByTagName('script')[0];
37
- if ((first === null || first === void 0 ? void 0 : first.parentNode) === null) {
38
- throw new Error('No script to insert Google analytics script before.');
39
- }
40
- first.parentNode.insertBefore(scriptSrc, first);
41
- first.parentNode.insertBefore(scriptGtag, first);
42
- googleAnalytics._loadOptions = options;
43
- };
44
- // Load GoogleAnalytics with your key.
45
- googleAnalytics.load(this.analyticsId);
46
- }
47
- }
48
- export default GoogleAnalyticsLoader;
49
- //# sourceMappingURL=GoogleAnalyticsLoader.js.map
@@ -1 +0,0 @@
1
-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CAAC;YACzE,CAAC;YACD,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YAChD,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;YACjD,eAAe,CAAC,YAAY,GAAG,OAAO,CAAC;QACzC,CAAC,CAAC;QAEF,sCAAsC;QACtC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;CACF;AAED,eAAe,qBAAqB,CAAC","sourcesContent":["/**\n * @implements {GoogleAnalyticsLoader}\n * @memberof module:GoogleAnalytics\n */\nclass GoogleAnalyticsLoader {\n analyticsId: string;\n\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 // @ts-expect-error We just added googleAnalytics to global, it's there.\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 if (first?.parentNode === null) {\n throw new Error('No script to insert Google analytics script before.');\n }\n first.parentNode.insertBefore(scriptSrc, first);\n first.parentNode.insertBefore(scriptGtag, first);\n googleAnalytics._loadOptions = options;\n };\n\n // Load GoogleAnalytics with your key.\n googleAnalytics.load(this.analyticsId);\n }\n}\n\nexport default GoogleAnalyticsLoader;\n"]}