@openedx/frontend-base 2.0.0-alpha.3 → 2.0.0-alpha.5
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 -1
- package/dist/runtime/config/index.d.ts +8 -0
- package/dist/runtime/config/index.js +29 -8
- package/dist/runtime/config/index.js.map +1 -1
- package/dist/runtime/i18n/index.d.ts +1 -1
- package/dist/runtime/i18n/index.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,7 +36,15 @@ If a change requires corresponding updates to a consuming site (for example, new
|
|
|
36
36
|
|
|
37
37
|
### Releases
|
|
38
38
|
|
|
39
|
-
This library is published
|
|
39
|
+
This library is published to npm by `semantic-release`, and its branches follow [OEP-10 ADR 0002: Frontend Stable Branches](https://docs.openedx.org/projects/openedx-proposals/en/latest/processes/oep-0010/decisions/0002-frontend-stable-branches.html):
|
|
40
|
+
|
|
41
|
+
- **`main`** is unstable. Every merge publishes a prerelease on the `alpha` dist-tag. Breaking changes land here with no DEPR process and no warning, so it is not supported in production. All changes, including bug fixes, should target this branch first.
|
|
42
|
+
- **`stable`** carries the newest stable major and owns the `latest` dist-tag. Changes arrive here as backports from `main`, and no breaking change lands after publication.
|
|
43
|
+
- **`n.x`** and **`n.m.x`** are maintenance branches for majors and minors that `stable` has moved past. Each owns the dist-tag matching its own name, so consumers select a maintained line by semver range, for example `"1.x"`.
|
|
44
|
+
|
|
45
|
+
Both `.releaserc` and the `Release CI` workflow already know the whole layout, including the maintenance branch patterns, so a new line starts publishing as soon as it is pushed.
|
|
46
|
+
|
|
47
|
+
This repository is not branched or tagged for Open edX releases in its own right. It participates by published version instead, per [OEP-10 ADR 0003: Frontend Release Strategy](https://docs.openedx.org/projects/openedx-proposals/en/latest/processes/oep-0010/decisions/0003-frontend-release-strategy.html).
|
|
40
48
|
|
|
41
49
|
## Further reading
|
|
42
50
|
|
|
@@ -169,6 +169,14 @@ export declare function mergeSiteConfig(newSiteConfig: Partial<SiteConfig>, opti
|
|
|
169
169
|
* used at initialization time to process any AppConfigs bundled with the site.
|
|
170
170
|
*/
|
|
171
171
|
export declare function addAppConfigs(): void;
|
|
172
|
+
/**
|
|
173
|
+
* Resolves an app's configuration, deep merging the three sources in order of
|
|
174
|
+
* increasing precedence:
|
|
175
|
+
*
|
|
176
|
+
* - `App.defaultConfig`, bundled by the app author
|
|
177
|
+
* - `SiteConfig.commonAppConfig`, supplied site-wide by an operator
|
|
178
|
+
* - `App.config`, supplied per-app by an operator
|
|
179
|
+
*/
|
|
172
180
|
export declare function getAppConfig(id: string): AppConfig;
|
|
173
181
|
export declare function mergeAppConfig(id: string, newAppConfig: AppConfig): void;
|
|
174
182
|
export declare function setActiveRouteRoles(roles: string[]): void;
|
|
@@ -262,7 +262,8 @@ function mergeApps(oldApps, newApps, options = {}) {
|
|
|
262
262
|
}
|
|
263
263
|
/*
|
|
264
264
|
* Merge a pair of Apps with the same appId. Deep-merges `config` (and, in the
|
|
265
|
-
* full-merge case, `provides`); other fields take `newApp`'s
|
|
265
|
+
* full-merge case, `defaultConfig` and `provides`); other fields take `newApp`'s
|
|
266
|
+
* value verbatim.
|
|
266
267
|
* The result is built via `Object.getOwnPropertyDescriptors` so any lazy
|
|
267
268
|
* getters survive: a snapshot via `lodash.merge` or spread would invoke the
|
|
268
269
|
* getter at merge time and freeze its return value, which is typically empty
|
|
@@ -271,8 +272,9 @@ function mergeApps(oldApps, newApps, options = {}) {
|
|
|
271
272
|
* survive element-wise merging anyway.
|
|
272
273
|
*/
|
|
273
274
|
function mergeApp(oldApp, newApp, options = {}) {
|
|
274
|
-
// configOnly mode: preserve `oldApp` (identity, slots, etc.)
|
|
275
|
-
// only `newApp.config` on top.
|
|
275
|
+
// configOnly mode: preserve `oldApp` (identity, slots, defaultConfig, etc.)
|
|
276
|
+
// and deep-merge only `newApp.config` on top. Operator-supplied config can
|
|
277
|
+
// never write into an app's bundled `defaultConfig`.
|
|
276
278
|
if (options.configOnly) {
|
|
277
279
|
if (!newApp.config) {
|
|
278
280
|
return oldApp;
|
|
@@ -281,9 +283,13 @@ function mergeApp(oldApp, newApp, options = {}) {
|
|
|
281
283
|
config: merge({}, oldApp.config, newApp.config),
|
|
282
284
|
});
|
|
283
285
|
}
|
|
284
|
-
// Full mode: take `newApp` (identity, slots, etc.) and deep-merge
|
|
285
|
-
// and `provides` from `oldApp`. Other fields take
|
|
286
|
+
// Full mode: take `newApp` (identity, slots, etc.) and deep-merge
|
|
287
|
+
// `defaultConfig`, `config`, and `provides` from `oldApp`. Other fields take
|
|
288
|
+
// `newApp`'s value verbatim.
|
|
286
289
|
const deepMerged = {};
|
|
290
|
+
if (oldApp.defaultConfig !== undefined || newApp.defaultConfig !== undefined) {
|
|
291
|
+
deepMerged.defaultConfig = merge({}, oldApp.defaultConfig, newApp.defaultConfig);
|
|
292
|
+
}
|
|
287
293
|
if (oldApp.config !== undefined || newApp.config !== undefined) {
|
|
288
294
|
deepMerged.config = merge({}, oldApp.config, newApp.config);
|
|
289
295
|
}
|
|
@@ -299,6 +305,9 @@ function cloneAppDescriptors(source, overrides) {
|
|
|
299
305
|
}
|
|
300
306
|
return Object.create(Object.getPrototypeOf(source), descriptors);
|
|
301
307
|
}
|
|
308
|
+
/* Bundled by app authors via `App.defaultConfig`. Kept separate from
|
|
309
|
+
`appConfigs` so that operator-supplied config can never write into it. */
|
|
310
|
+
const appDefaultConfigs = {};
|
|
302
311
|
const appConfigs = {};
|
|
303
312
|
/**
|
|
304
313
|
* addAppConfigs finds any AppConfig objects in the apps in SiteConfig and makes their config
|
|
@@ -310,19 +319,31 @@ export function addAppConfigs() {
|
|
|
310
319
|
if (!apps)
|
|
311
320
|
return;
|
|
312
321
|
for (const app of apps) {
|
|
313
|
-
const { appId, config } = app;
|
|
322
|
+
const { appId, config, defaultConfig } = app;
|
|
323
|
+
if (defaultConfig !== undefined) {
|
|
324
|
+
appDefaultConfigs[appId] = defaultConfig;
|
|
325
|
+
}
|
|
314
326
|
if (config !== undefined) {
|
|
315
327
|
appConfigs[appId] = config;
|
|
316
328
|
}
|
|
317
329
|
}
|
|
318
330
|
publish(CONFIG_CHANGED);
|
|
319
331
|
}
|
|
332
|
+
/**
|
|
333
|
+
* Resolves an app's configuration, deep merging the three sources in order of
|
|
334
|
+
* increasing precedence:
|
|
335
|
+
*
|
|
336
|
+
* - `App.defaultConfig`, bundled by the app author
|
|
337
|
+
* - `SiteConfig.commonAppConfig`, supplied site-wide by an operator
|
|
338
|
+
* - `App.config`, supplied per-app by an operator
|
|
339
|
+
*/
|
|
320
340
|
export function getAppConfig(id) {
|
|
321
341
|
const { commonAppConfig } = getSiteConfig();
|
|
322
|
-
|
|
342
|
+
const defaultConfig = appDefaultConfigs[id];
|
|
343
|
+
if (defaultConfig === undefined && commonAppConfig === undefined) {
|
|
323
344
|
return appConfigs[id];
|
|
324
345
|
}
|
|
325
|
-
return merge({}, commonAppConfig, appConfigs[id]);
|
|
346
|
+
return merge({}, defaultConfig, commonAppConfig, appConfigs[id]);
|
|
326
347
|
}
|
|
327
348
|
export function mergeAppConfig(id, newAppConfig) {
|
|
328
349
|
// Non-mutating: produce a fresh entry so consumers holding a reference to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;;;;;;;;;;;;AAEH,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,KAAK,MAAM,cAAc,CAAC;AACjC,OAAO,EAGL,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AACrB,O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O,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC5F,IAAI,EAAE,CAAC;AACZ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;;IAC5C,wCAAwC;IACxC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QAC3C,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,kBAAkB,GAAG,MAAA,aAAa,EAAE,CAAC,wBAAwB,mCAAI,EAAE,CAAC;IAC1E,OAAO,MAAA,kBAAkB,CAAC,GAAG,CAAC,mCAAI,GAAG,CAAC;AACxC,CAAC","sourcesContent":["/**\n * #### Import members from **@edx/frontend-base**\n *\n * The configuration module provides utilities for working with an application's configuration\n * document (SiteConfig). Configuration variables can be supplied to the\n * application in three different ways. They are applied in the following order:\n *\n * - Site Configuration File (site.config.tsx)\n * - Initialization Config Handler\n * - Runtime Configuration\n *\n * Last one in wins, and are deep merged together. Variables with the same name defined via the\n * later methods will override any defined using an earlier method. i.e., if a variable is defined\n * in Runtime Configuration, that will override the same variable defined in either of the earlier\n * methods. Configuration defined in a JS file will override any default values below.\n *\n * ##### Site Configuration File\n *\n * Configuration variables can be supplied in a file named site.config.tsx. This file must\n * export either an Object containing configuration variables or a function. The function must\n * return an Object containing configuration variables or, alternately, a promise which resolves to\n * an Object.\n *\n * Using a function or async function allows the configuration to be resolved at runtime (because\n * the function will be executed at runtime). This is not common, and the capability is included\n * for the sake of flexibility.\n *\n * The Site Configuration File is well-suited to extensibility use cases or component overrides,\n * in that the configuration file can depend on any installed JavaScript module. It is also the\n * preferred way of doing build-time configuration if runtime configuration isn't used by your\n * deployment of the platform.\n *\n * Exporting a config object:\n * ```\n * const siteConfig = {\n * lmsBaseUrl: 'http://localhost:18000'\n * };\n *\n * export default siteConfig;\n * ```\n *\n * Exporting a function that returns an object:\n * ```\n * function getSiteConfig() {\n * return {\n * lmsBaseUrl: 'http://localhost:18000'\n * };\n * }\n * ```\n *\n * Exporting a function that returns a promise that resolves to an object:\n * ```\n * function getAsyncSiteConfig() {\n * return new Promise((resolve, reject) => {\n * resolve({\n * lmsBaseUrl: 'http://localhost:18000'\n * });\n * });\n * }\n *\n * export default getAsyncSiteConfig;\n * ```\n *\n * ##### Initialization Config Handler\n *\n * The configuration document can be extended by\n * applications at run-time using a `config` initialization handler. Please see the Initialization\n * documentation for more information on handlers and initialization phases.\n *\n * ```\n * initialize({\n * handlers: {\n * config: () => {\n * mergeSiteConfig({\n * CUSTOM_VARIABLE: 'custom value',\n * lmsBaseUrl: 'http://localhost:18001' // You can override variables, but this is uncommon.\n * }, 'App config override handler');\n * },\n * },\n * });\n * ```\n *\n * ##### Runtime Configuration\n *\n * Configuration variables can also be supplied using the \"runtime configuration\" method, taking\n * advantage of the Micro-frontend Config API in edx-platform. More information on this API can be\n * found in the ADR which introduced it:\n *\n * https://github.com/openedx/edx-platform/blob/master/lms/djangoapps/mfe_config_api/docs/decisions/0001-mfe-config-api.rst\n *\n * The runtime configuration method can be enabled by supplying a runtimeConfigJsonUrl via one of the other\n * two configuration methods above.\n *\n * Runtime configuration is particularly useful if you need to supply different configurations to\n * a single deployment of a micro-frontend, for instance. It is also a perfectly valid alternative\n * to build-time configuration, though it introduces an additional API call to edx-platform on MFE\n * initialization.\n *\n *\n * @module Config\n */\n\nimport isEqual from 'lodash/isEqual';\nimport keyBy from 'lodash/keyBy';\nimport merge from 'lodash/merge';\nimport {\n App,\n AppConfig,\n EnvironmentTypes,\n SiteConfig\n} from '../../types';\nimport { ACTIVE_ROLES_CHANGED, CONFIG_CHANGED } from '../constants';\nimport { publish } from '../subscriptions';\n\nlet siteConfig: SiteConfig = {\n // Required\n siteId: '',\n baseUrl: '',\n siteName: '',\n loginUrl: '',\n logoutUrl: '',\n lmsBaseUrl: '',\n\n // Optional\n environment: EnvironmentTypes.PRODUCTION,\n cmsBaseUrl: '',\n apps: [],\n externalRoutes: [],\n externalLinkUrlOverrides: [],\n runtimeConfigJsonUrl: null,\n theme: {},\n defaultLanguage: 'en',\n supportedLanguages: [],\n accessTokenCookieName: 'edx-jwt-cookie-header-payload',\n csrfTokenApiPath: '/csrf/api/v1/token',\n ignoredErrorRegex: null,\n languagePreferenceCookieName: 'openedx-language-preference',\n refreshAccessTokenApiPath: '/login_refresh',\n userInfoCookieName: 'edx-user-info',\n segmentKey: null,\n};\n\n/**\n * Getter for the application configuration document. This is synchronous and merely returns a\n * reference to an existing object, and is thus safe to call as often as desired.\n *\n * Example:\n *\n * ```\n * import { getSiteConfig } from '@openedx/frontend-base';\n *\n * const {\n * lmsBaseUrl,\n * } = getSiteConfig();\n * ```\n *\n * @returns {SiteConfig}\n */\nexport function getSiteConfig() {\n return siteConfig;\n}\n\n/**\n * Replaces the existing SiteConfig. This is not commonly used, but can be helpful for tests.\n *\n * Example:\n *\n * ```\n * import { setSiteConfig } from '@openedx/frontend-base';\n *\n * setSiteConfig({\n * lmsBaseUrl, // This is overriding the ENTIRE document - this is not merged in!\n * });\n * ```\n *\n * @param newConfig A replacement SiteConfig which will completely override the current SiteConfig.\n */\nexport function setSiteConfig(newSiteConfig: SiteConfig) {\n siteConfig = newSiteConfig;\n publish(CONFIG_CHANGED);\n}\n\ninterface MergeSiteConfigOptions {\n limitAppMergeToConfig?: boolean;\n}\n\n/**\n * Merges additional configuration values into the site config returned by `getSiteConfig`. Will\n * override any values that exist with the same keys.\n *\n * ```\n * mergeSiteConfig({\n * NEW_KEY: 'new value',\n * OTHER_NEW_KEY: 'other new value',\n * });\n *\n * This function uses lodash.merge internally to merge configuration objects\n * which means they will be merged recursively. See https://lodash.com/docs/latest#merge for\n * documentation on the exact behavior.\n *\n * Apps are merged by appId rather than array index. By default, apps in the incoming config\n * that don't exist in the current config will be added.\n *\n * When `limitAppMergeToConfig` is true:\n * - All non-app parts of the config are still merged normally\n * - Only the `config` property of each existing app is merged\n * - Apps in the incoming config that don't exist in the current config are ignored\n *\n * @param {Object} newSiteConfig\n * @param {Object} options\n * @param {boolean} options.limitAppMergeToConfig - Limit app merging to only the config property of existing apps\n */\nexport function mergeSiteConfig(\n newSiteConfig: Partial<SiteConfig>,\n options: MergeSiteConfigOptions = {}\n) {\n const { limitAppMergeToConfig = false } = options;\n const { apps: newApps, ...restOfNewConfig } = newSiteConfig;\n\n /* `merge({}, ...)` deep-clones into the fresh target, so the new `siteConfig`\n is a brand-new reference and the previous one is never mutated. This is what\n lets React consumers detect that CONFIG_CHANGED actually changed something. */\n siteConfig = merge({}, siteConfig, restOfNewConfig);\n\n // if we don't have new apps, we're done\n if (!newApps?.length) {\n publish(CONFIG_CHANGED);\n return;\n }\n\n // if we're doing a full merge, merge the objects\n if (!limitAppMergeToConfig) {\n siteConfig.apps = mergeApps(siteConfig.apps || [], newApps);\n publish(CONFIG_CHANGED);\n return;\n }\n\n // we're doing a config-only merge, if we don't\n // have apps already, we can't update their configs\n if (!siteConfig.apps?.length) {\n publish(CONFIG_CHANGED);\n return;\n }\n\n // handle config-only merging\n siteConfig.apps = mergeApps(siteConfig.apps, newApps, { configOnly: true });\n\n publish(CONFIG_CHANGED);\n}\n\n/*\n * Merge two App[] by appId. Existing apps stay in their original positions\n * (with their pair-merged counterpart from `newApps` substituted in when\n * present); apps in `newApps` not already in `oldApps` append at the end.\n * With `{ configOnly: true }`, no apps are added and apps not appearing in\n * `newApps` pass through unchanged. Per-pair merging is delegated to\n * `mergeApp`.\n */\nfunction mergeApps(\n oldApps: App[],\n newApps: App[],\n options: { configOnly?: boolean } = {},\n): App[] {\n const incomingByAppId = keyBy(newApps, 'appId');\n\n // Phase 1: walk existing apps in their original order, pair-merging any\n // that have a counterpart in newApps.\n const updatedExisting = oldApps.map((oldApp) => {\n const newApp = incomingByAppId[oldApp.appId];\n return newApp ? mergeApp(oldApp, newApp, options) : oldApp;\n });\n\n // configOnly mode never adds apps, so we're done.\n if (options.configOnly) {\n return updatedExisting;\n }\n\n // Phase 2: append apps from newApps that weren't already in oldApps.\n const existingIds = new Set(oldApps.map((a) => a.appId));\n const additions = newApps.filter((a) => !existingIds.has(a.appId));\n return [...updatedExisting, ...additions];\n}\n\n/*\n * Merge a pair of Apps with the same appId. Deep-merges `config` (and, in the\n * full-merge case, `provides`); other fields take `newApp`'s value verbatim.\n * The result is built via `Object.getOwnPropertyDescriptors` so any lazy\n * getters survive: a snapshot via `lodash.merge` or spread would invoke the\n * getter at merge time and freeze its return value, which is typically empty\n * mid-init. Per-field replacement is also the only sensible behavior for the\n * array fields (`slots`/`routes`/`providers`/`externalScripts`), which don't\n * survive element-wise merging anyway.\n */\nfunction mergeApp(\n oldApp: App,\n newApp: App,\n options: { configOnly?: boolean } = {},\n): App {\n // configOnly mode: preserve `oldApp` (identity, slots, etc.) and deep-merge\n // only `newApp.config` on top.\n if (options.configOnly) {\n if (!newApp.config) {\n return oldApp;\n }\n return cloneAppDescriptors(oldApp, {\n config: merge({}, oldApp.config, newApp.config),\n });\n }\n\n // Full mode: take `newApp` (identity, slots, etc.) and deep-merge `config`\n // and `provides` from `oldApp`. Other fields take `newApp`'s value verbatim.\n const deepMerged: Record<string, unknown> = {};\n if (oldApp.config !== undefined || newApp.config !== undefined) {\n deepMerged.config = merge({}, oldApp.config, newApp.config);\n }\n if (oldApp.provides !== undefined || newApp.provides !== undefined) {\n deepMerged.provides = merge({}, oldApp.provides, newApp.provides);\n }\n return cloneAppDescriptors(newApp, deepMerged);\n}\n\nfunction cloneAppDescriptors(source: App, overrides: Record<string, unknown>): App {\n const descriptors = Object.getOwnPropertyDescriptors(source);\n for (const [key, value] of Object.entries(overrides)) {\n descriptors[key] = { value, writable: true, enumerable: true, configurable: true };\n }\n return Object.create(Object.getPrototypeOf(source), descriptors) as App;\n}\n\nconst appConfigs: Record<string, AppConfig> = {};\n\n/**\n * addAppConfigs finds any AppConfig objects in the apps in SiteConfig and makes their config\n * available to be used by Apps via getAppConfig(appId) or useAppConfig() functions. This is\n * used at initialization time to process any AppConfigs bundled with the site.\n */\nexport function addAppConfigs() {\n const { apps } = getSiteConfig();\n if (!apps) return;\n\n for (const app of apps) {\n const { appId, config } = app;\n if (config !== undefined) {\n appConfigs[appId] = config;\n }\n }\n\n publish(CONFIG_CHANGED);\n}\n\nexport function getAppConfig(id: string) {\n const { commonAppConfig } = getSiteConfig();\n if (commonAppConfig === undefined) {\n return appConfigs[id];\n }\n return merge({}, commonAppConfig, appConfigs[id]);\n}\n\nexport function mergeAppConfig(id: string, newAppConfig: AppConfig) {\n // Non-mutating: produce a fresh entry so consumers holding a reference to\n // the previous one don't observe the change underneath them.\n appConfigs[id] = merge({}, appConfigs[id], newAppConfig);\n publish(CONFIG_CHANGED);\n}\n\nlet activeRouteRoles: string[] = [];\n\nexport function setActiveRouteRoles(roles: string[]) {\n if (isEqual(activeRouteRoles, roles)) return;\n activeRouteRoles = roles;\n publish(ACTIVE_ROLES_CHANGED);\n}\n\nexport function getActiveRouteRoles() {\n return activeRouteRoles;\n}\n\nconst activeWidgetRoles: Record<string, number> = {};\n\nexport function addActiveWidgetRole(role: string) {\n // Only publish when the role transitions from absent to present.\n const wasPresent = (activeWidgetRoles[role] ?? 0) > 0;\n activeWidgetRoles[role] = (activeWidgetRoles[role] ?? 0) + 1;\n if (!wasPresent) publish(ACTIVE_ROLES_CHANGED);\n}\n\nexport function removeActiveWidgetRole(role: string) {\n if (activeWidgetRoles[role] === undefined) return;\n activeWidgetRoles[role] -= 1;\n if (activeWidgetRoles[role] < 1) {\n delete activeWidgetRoles[role];\n // Only publish when the role transitions from present to absent.\n publish(ACTIVE_ROLES_CHANGED);\n }\n}\n\nexport function getActiveWidgetRoles() {\n return Object.entries(activeWidgetRoles)\n .filter(([, count]: [role: string, count: number]) => count !== undefined && count > 0)\n .map(([role]: [role: string, count: number]) => role);\n}\n\n// Gets all active roles from the route roles and widget roles.\nexport function getActiveRoles() {\n return [...getActiveRouteRoles(), ...getActiveWidgetRoles()];\n}\n\n/**\n * Collects all `provides` entries from registered apps that match the given identifier.\n * This enables inter-app data sharing without frontend-base needing to understand the data shape.\n *\n * @param id - The namespaced provides identifier.\n * @returns An array of provided data from all apps that declared data for this identifier.\n */\nexport function getProvides(id: string): unknown[] {\n const { apps } = getSiteConfig();\n if (!apps) return [];\n\n const results: unknown[] = [];\n for (const app of apps) {\n if (app.provides && app.provides[id] !== undefined) {\n results.push(app.provides[id]);\n }\n }\n return results;\n}\n\n/**\n * Collects and flattens all `provides` entries for the given identifier\n * as strings. Each entry can be a single string or a string array; entries\n * of other types are silently skipped.\n *\n * @param id - The namespaced provides identifier.\n * @returns A flat array of strings from all apps that declared data for this identifier.\n */\nexport function getProvidesAsStrings(id: string): string[] {\n return getProvides(id)\n .filter((data): data is string | string[] => typeof data === 'string' || Array.isArray(data))\n .flat();\n}\n\n/**\n * Get an external link URL based on the URL provided. If the passed in URL is overridden in the\n * `externalLinkUrlOverrides` object, it will return the overridden URL. Otherwise, it will return\n * the provided URL.\n *\n *\n * @param {string} url - The default URL.\n * @returns {string} - The external link URL. Defaults to the input URL if not found in the\n * `externalLinkUrlOverrides` object. If the input URL is invalid, '#' is returned.\n *\n * @example\n * import { getExternalLinkUrl } from '@openedx/frontend-base';\n *\n * <Hyperlink\n * destination={getExternalLinkUrl(data.helpLink)}\n * target=\"_blank\"\n * >\n */\nexport function getExternalLinkUrl(url: string): string {\n // Guard against whitespace-only strings\n if (typeof url !== 'string' || !url.trim()) {\n return '#';\n }\n\n const overriddenLinkUrls = getSiteConfig().externalLinkUrlOverrides ?? {};\n return overriddenLinkUrls[url] ?? url;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;;;;;;;;;;;;AAEH,OAAO,OAAO,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AAE,EAAE,GAAG,oBAAoB,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,EAAU;IACpC,MAAM,EAAE,IAAI,EAAE,GAAG,aAAa,EAAE,CAAC;IACjC,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAErB,MAAM,OAAO,GAAc,EAAE,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,SAAS,EAAE,CAAC;YACnD,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAU;IAC7C,OAAO,WAAW,CAAC,EAAE,CAAC;SACnB,MAAM,CAAC,CAAC,IAAI,EAA6B,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;SAC5F,IAAI,EAAE,CAAC;AACZ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;;IAC5C,wCAAwC;IACxC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;QAC3C,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,kBAAkB,GAAG,MAAA,aAAa,EAAE,CAAC,wBAAwB,mCAAI,EAAE,CAAC;IAC1E,OAAO,MAAA,kBAAkB,CAAC,GAAG,CAAC,mCAAI,GAAG,CAAC;AACxC,CAAC","sourcesContent":["/**\n * #### Import members from **@edx/frontend-base**\n *\n * The configuration module provides utilities for working with an application's configuration\n * document (SiteConfig). Configuration variables can be supplied to the\n * application in three different ways. They are applied in the following order:\n *\n * - Site Configuration File (site.config.tsx)\n * - Initialization Config Handler\n * - Runtime Configuration\n *\n * Last one in wins, and are deep merged together. Variables with the same name defined via the\n * later methods will override any defined using an earlier method. i.e., if a variable is defined\n * in Runtime Configuration, that will override the same variable defined in either of the earlier\n * methods. Configuration defined in a JS file will override any default values below.\n *\n * ##### Site Configuration File\n *\n * Configuration variables can be supplied in a file named site.config.tsx. This file must\n * export either an Object containing configuration variables or a function. The function must\n * return an Object containing configuration variables or, alternately, a promise which resolves to\n * an Object.\n *\n * Using a function or async function allows the configuration to be resolved at runtime (because\n * the function will be executed at runtime). This is not common, and the capability is included\n * for the sake of flexibility.\n *\n * The Site Configuration File is well-suited to extensibility use cases or component overrides,\n * in that the configuration file can depend on any installed JavaScript module. It is also the\n * preferred way of doing build-time configuration if runtime configuration isn't used by your\n * deployment of the platform.\n *\n * Exporting a config object:\n * ```\n * const siteConfig = {\n * lmsBaseUrl: 'http://localhost:18000'\n * };\n *\n * export default siteConfig;\n * ```\n *\n * Exporting a function that returns an object:\n * ```\n * function getSiteConfig() {\n * return {\n * lmsBaseUrl: 'http://localhost:18000'\n * };\n * }\n * ```\n *\n * Exporting a function that returns a promise that resolves to an object:\n * ```\n * function getAsyncSiteConfig() {\n * return new Promise((resolve, reject) => {\n * resolve({\n * lmsBaseUrl: 'http://localhost:18000'\n * });\n * });\n * }\n *\n * export default getAsyncSiteConfig;\n * ```\n *\n * ##### Initialization Config Handler\n *\n * The configuration document can be extended by\n * applications at run-time using a `config` initialization handler. Please see the Initialization\n * documentation for more information on handlers and initialization phases.\n *\n * ```\n * initialize({\n * handlers: {\n * config: () => {\n * mergeSiteConfig({\n * CUSTOM_VARIABLE: 'custom value',\n * lmsBaseUrl: 'http://localhost:18001' // You can override variables, but this is uncommon.\n * }, 'App config override handler');\n * },\n * },\n * });\n * ```\n *\n * ##### Runtime Configuration\n *\n * Configuration variables can also be supplied using the \"runtime configuration\" method, taking\n * advantage of the Micro-frontend Config API in edx-platform. More information on this API can be\n * found in the ADR which introduced it:\n *\n * https://github.com/openedx/edx-platform/blob/master/lms/djangoapps/mfe_config_api/docs/decisions/0001-mfe-config-api.rst\n *\n * The runtime configuration method can be enabled by supplying a runtimeConfigJsonUrl via one of the other\n * two configuration methods above.\n *\n * Runtime configuration is particularly useful if you need to supply different configurations to\n * a single deployment of a micro-frontend, for instance. It is also a perfectly valid alternative\n * to build-time configuration, though it introduces an additional API call to edx-platform on MFE\n * initialization.\n *\n *\n * @module Config\n */\n\nimport isEqual from 'lodash/isEqual';\nimport keyBy from 'lodash/keyBy';\nimport merge from 'lodash/merge';\nimport {\n App,\n AppConfig,\n EnvironmentTypes,\n SiteConfig\n} from '../../types';\nimport { ACTIVE_ROLES_CHANGED, CONFIG_CHANGED } from '../constants';\nimport { publish } from '../subscriptions';\n\nlet siteConfig: SiteConfig = {\n // Required\n siteId: '',\n baseUrl: '',\n siteName: '',\n loginUrl: '',\n logoutUrl: '',\n lmsBaseUrl: '',\n\n // Optional\n environment: EnvironmentTypes.PRODUCTION,\n cmsBaseUrl: '',\n apps: [],\n externalRoutes: [],\n externalLinkUrlOverrides: [],\n runtimeConfigJsonUrl: null,\n theme: {},\n defaultLanguage: 'en',\n supportedLanguages: [],\n accessTokenCookieName: 'edx-jwt-cookie-header-payload',\n csrfTokenApiPath: '/csrf/api/v1/token',\n ignoredErrorRegex: null,\n languagePreferenceCookieName: 'openedx-language-preference',\n refreshAccessTokenApiPath: '/login_refresh',\n userInfoCookieName: 'edx-user-info',\n segmentKey: null,\n};\n\n/**\n * Getter for the application configuration document. This is synchronous and merely returns a\n * reference to an existing object, and is thus safe to call as often as desired.\n *\n * Example:\n *\n * ```\n * import { getSiteConfig } from '@openedx/frontend-base';\n *\n * const {\n * lmsBaseUrl,\n * } = getSiteConfig();\n * ```\n *\n * @returns {SiteConfig}\n */\nexport function getSiteConfig() {\n return siteConfig;\n}\n\n/**\n * Replaces the existing SiteConfig. This is not commonly used, but can be helpful for tests.\n *\n * Example:\n *\n * ```\n * import { setSiteConfig } from '@openedx/frontend-base';\n *\n * setSiteConfig({\n * lmsBaseUrl, // This is overriding the ENTIRE document - this is not merged in!\n * });\n * ```\n *\n * @param newConfig A replacement SiteConfig which will completely override the current SiteConfig.\n */\nexport function setSiteConfig(newSiteConfig: SiteConfig) {\n siteConfig = newSiteConfig;\n publish(CONFIG_CHANGED);\n}\n\ninterface MergeSiteConfigOptions {\n limitAppMergeToConfig?: boolean;\n}\n\n/**\n * Merges additional configuration values into the site config returned by `getSiteConfig`. Will\n * override any values that exist with the same keys.\n *\n * ```\n * mergeSiteConfig({\n * NEW_KEY: 'new value',\n * OTHER_NEW_KEY: 'other new value',\n * });\n *\n * This function uses lodash.merge internally to merge configuration objects\n * which means they will be merged recursively. See https://lodash.com/docs/latest#merge for\n * documentation on the exact behavior.\n *\n * Apps are merged by appId rather than array index. By default, apps in the incoming config\n * that don't exist in the current config will be added.\n *\n * When `limitAppMergeToConfig` is true:\n * - All non-app parts of the config are still merged normally\n * - Only the `config` property of each existing app is merged\n * - Apps in the incoming config that don't exist in the current config are ignored\n *\n * @param {Object} newSiteConfig\n * @param {Object} options\n * @param {boolean} options.limitAppMergeToConfig - Limit app merging to only the config property of existing apps\n */\nexport function mergeSiteConfig(\n newSiteConfig: Partial<SiteConfig>,\n options: MergeSiteConfigOptions = {}\n) {\n const { limitAppMergeToConfig = false } = options;\n const { apps: newApps, ...restOfNewConfig } = newSiteConfig;\n\n /* `merge({}, ...)` deep-clones into the fresh target, so the new `siteConfig`\n is a brand-new reference and the previous one is never mutated. This is what\n lets React consumers detect that CONFIG_CHANGED actually changed something. */\n siteConfig = merge({}, siteConfig, restOfNewConfig);\n\n // if we don't have new apps, we're done\n if (!newApps?.length) {\n publish(CONFIG_CHANGED);\n return;\n }\n\n // if we're doing a full merge, merge the objects\n if (!limitAppMergeToConfig) {\n siteConfig.apps = mergeApps(siteConfig.apps || [], newApps);\n publish(CONFIG_CHANGED);\n return;\n }\n\n // we're doing a config-only merge, if we don't\n // have apps already, we can't update their configs\n if (!siteConfig.apps?.length) {\n publish(CONFIG_CHANGED);\n return;\n }\n\n // handle config-only merging\n siteConfig.apps = mergeApps(siteConfig.apps, newApps, { configOnly: true });\n\n publish(CONFIG_CHANGED);\n}\n\n/*\n * Merge two App[] by appId. Existing apps stay in their original positions\n * (with their pair-merged counterpart from `newApps` substituted in when\n * present); apps in `newApps` not already in `oldApps` append at the end.\n * With `{ configOnly: true }`, no apps are added and apps not appearing in\n * `newApps` pass through unchanged. Per-pair merging is delegated to\n * `mergeApp`.\n */\nfunction mergeApps(\n oldApps: App[],\n newApps: App[],\n options: { configOnly?: boolean } = {},\n): App[] {\n const incomingByAppId = keyBy(newApps, 'appId');\n\n // Phase 1: walk existing apps in their original order, pair-merging any\n // that have a counterpart in newApps.\n const updatedExisting = oldApps.map((oldApp) => {\n const newApp = incomingByAppId[oldApp.appId];\n return newApp ? mergeApp(oldApp, newApp, options) : oldApp;\n });\n\n // configOnly mode never adds apps, so we're done.\n if (options.configOnly) {\n return updatedExisting;\n }\n\n // Phase 2: append apps from newApps that weren't already in oldApps.\n const existingIds = new Set(oldApps.map((a) => a.appId));\n const additions = newApps.filter((a) => !existingIds.has(a.appId));\n return [...updatedExisting, ...additions];\n}\n\n/*\n * Merge a pair of Apps with the same appId. Deep-merges `config` (and, in the\n * full-merge case, `defaultConfig` and `provides`); other fields take `newApp`'s\n * value verbatim.\n * The result is built via `Object.getOwnPropertyDescriptors` so any lazy\n * getters survive: a snapshot via `lodash.merge` or spread would invoke the\n * getter at merge time and freeze its return value, which is typically empty\n * mid-init. Per-field replacement is also the only sensible behavior for the\n * array fields (`slots`/`routes`/`providers`/`externalScripts`), which don't\n * survive element-wise merging anyway.\n */\nfunction mergeApp(\n oldApp: App,\n newApp: App,\n options: { configOnly?: boolean } = {},\n): App {\n // configOnly mode: preserve `oldApp` (identity, slots, defaultConfig, etc.)\n // and deep-merge only `newApp.config` on top. Operator-supplied config can\n // never write into an app's bundled `defaultConfig`.\n if (options.configOnly) {\n if (!newApp.config) {\n return oldApp;\n }\n return cloneAppDescriptors(oldApp, {\n config: merge({}, oldApp.config, newApp.config),\n });\n }\n\n // Full mode: take `newApp` (identity, slots, etc.) and deep-merge\n // `defaultConfig`, `config`, and `provides` from `oldApp`. Other fields take\n // `newApp`'s value verbatim.\n const deepMerged: Record<string, unknown> = {};\n if (oldApp.defaultConfig !== undefined || newApp.defaultConfig !== undefined) {\n deepMerged.defaultConfig = merge({}, oldApp.defaultConfig, newApp.defaultConfig);\n }\n if (oldApp.config !== undefined || newApp.config !== undefined) {\n deepMerged.config = merge({}, oldApp.config, newApp.config);\n }\n if (oldApp.provides !== undefined || newApp.provides !== undefined) {\n deepMerged.provides = merge({}, oldApp.provides, newApp.provides);\n }\n return cloneAppDescriptors(newApp, deepMerged);\n}\n\nfunction cloneAppDescriptors(source: App, overrides: Record<string, unknown>): App {\n const descriptors = Object.getOwnPropertyDescriptors(source);\n for (const [key, value] of Object.entries(overrides)) {\n descriptors[key] = { value, writable: true, enumerable: true, configurable: true };\n }\n return Object.create(Object.getPrototypeOf(source), descriptors) as App;\n}\n\n/* Bundled by app authors via `App.defaultConfig`. Kept separate from\n `appConfigs` so that operator-supplied config can never write into it. */\nconst appDefaultConfigs: Record<string, AppConfig> = {};\n\nconst appConfigs: Record<string, AppConfig> = {};\n\n/**\n * addAppConfigs finds any AppConfig objects in the apps in SiteConfig and makes their config\n * available to be used by Apps via getAppConfig(appId) or useAppConfig() functions. This is\n * used at initialization time to process any AppConfigs bundled with the site.\n */\nexport function addAppConfigs() {\n const { apps } = getSiteConfig();\n if (!apps) return;\n\n for (const app of apps) {\n const { appId, config, defaultConfig } = app;\n if (defaultConfig !== undefined) {\n appDefaultConfigs[appId] = defaultConfig;\n }\n if (config !== undefined) {\n appConfigs[appId] = config;\n }\n }\n\n publish(CONFIG_CHANGED);\n}\n\n/**\n * Resolves an app's configuration, deep merging the three sources in order of\n * increasing precedence:\n *\n * - `App.defaultConfig`, bundled by the app author\n * - `SiteConfig.commonAppConfig`, supplied site-wide by an operator\n * - `App.config`, supplied per-app by an operator\n */\nexport function getAppConfig(id: string) {\n const { commonAppConfig } = getSiteConfig();\n const defaultConfig = appDefaultConfigs[id];\n if (defaultConfig === undefined && commonAppConfig === undefined) {\n return appConfigs[id];\n }\n return merge({}, defaultConfig, commonAppConfig, appConfigs[id]);\n}\n\nexport function mergeAppConfig(id: string, newAppConfig: AppConfig) {\n // Non-mutating: produce a fresh entry so consumers holding a reference to\n // the previous one don't observe the change underneath them.\n appConfigs[id] = merge({}, appConfigs[id], newAppConfig);\n publish(CONFIG_CHANGED);\n}\n\nlet activeRouteRoles: string[] = [];\n\nexport function setActiveRouteRoles(roles: string[]) {\n if (isEqual(activeRouteRoles, roles)) return;\n activeRouteRoles = roles;\n publish(ACTIVE_ROLES_CHANGED);\n}\n\nexport function getActiveRouteRoles() {\n return activeRouteRoles;\n}\n\nconst activeWidgetRoles: Record<string, number> = {};\n\nexport function addActiveWidgetRole(role: string) {\n // Only publish when the role transitions from absent to present.\n const wasPresent = (activeWidgetRoles[role] ?? 0) > 0;\n activeWidgetRoles[role] = (activeWidgetRoles[role] ?? 0) + 1;\n if (!wasPresent) publish(ACTIVE_ROLES_CHANGED);\n}\n\nexport function removeActiveWidgetRole(role: string) {\n if (activeWidgetRoles[role] === undefined) return;\n activeWidgetRoles[role] -= 1;\n if (activeWidgetRoles[role] < 1) {\n delete activeWidgetRoles[role];\n // Only publish when the role transitions from present to absent.\n publish(ACTIVE_ROLES_CHANGED);\n }\n}\n\nexport function getActiveWidgetRoles() {\n return Object.entries(activeWidgetRoles)\n .filter(([, count]: [role: string, count: number]) => count !== undefined && count > 0)\n .map(([role]: [role: string, count: number]) => role);\n}\n\n// Gets all active roles from the route roles and widget roles.\nexport function getActiveRoles() {\n return [...getActiveRouteRoles(), ...getActiveWidgetRoles()];\n}\n\n/**\n * Collects all `provides` entries from registered apps that match the given identifier.\n * This enables inter-app data sharing without frontend-base needing to understand the data shape.\n *\n * @param id - The namespaced provides identifier.\n * @returns An array of provided data from all apps that declared data for this identifier.\n */\nexport function getProvides(id: string): unknown[] {\n const { apps } = getSiteConfig();\n if (!apps) return [];\n\n const results: unknown[] = [];\n for (const app of apps) {\n if (app.provides && app.provides[id] !== undefined) {\n results.push(app.provides[id]);\n }\n }\n return results;\n}\n\n/**\n * Collects and flattens all `provides` entries for the given identifier\n * as strings. Each entry can be a single string or a string array; entries\n * of other types are silently skipped.\n *\n * @param id - The namespaced provides identifier.\n * @returns A flat array of strings from all apps that declared data for this identifier.\n */\nexport function getProvidesAsStrings(id: string): string[] {\n return getProvides(id)\n .filter((data): data is string | string[] => typeof data === 'string' || Array.isArray(data))\n .flat();\n}\n\n/**\n * Get an external link URL based on the URL provided. If the passed in URL is overridden in the\n * `externalLinkUrlOverrides` object, it will return the overridden URL. Otherwise, it will return\n * the provided URL.\n *\n *\n * @param {string} url - The default URL.\n * @returns {string} - The external link URL. Defaults to the input URL if not found in the\n * `externalLinkUrlOverrides` object. If the input URL is invalid, '#' is returned.\n *\n * @example\n * import { getExternalLinkUrl } from '@openedx/frontend-base';\n *\n * <Hyperlink\n * destination={getExternalLinkUrl(data.helpLink)}\n * target=\"_blank\"\n * >\n */\nexport function getExternalLinkUrl(url: string): string {\n // Guard against whitespace-only strings\n if (typeof url !== 'string' || !url.trim()) {\n return '#';\n }\n\n const overriddenLinkUrls = getSiteConfig().externalLinkUrlOverrides ?? {};\n return overriddenLinkUrls[url] ?? url;\n}\n"]}
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
* @see {@link https://formatjs.io/docs/react-intl/components/ Intl} for components exported from this module.
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
|
-
export { createIntl, defineMessages, FormattedDate, FormattedMessage, FormattedNumber, FormattedPlural, FormattedRelativeTime, FormattedTime, IntlProvider, useIntl, type IntlConfig, type ResolvedIntlConfig, type IntlShape, } from 'react-intl';
|
|
22
|
+
export { createIntl, defineMessages, FormattedDate, FormattedMessage, FormattedNumber, FormattedPlural, FormattedRelativeTime, FormattedTime, IntlProvider, useIntl, type IntlConfig, type ResolvedIntlConfig, type IntlShape, type MessageDescriptor, } from 'react-intl';
|
|
23
23
|
export { configureI18n, getLocale, getLocalizedLanguageName, getMessages, getPrimaryLanguageSubtag, getSupportedLanguageList, handleRtl, isRtl, LOCALE_CHANGED, LOCALE_TOPIC, mergeMessages, updateLocale, } from './lib';
|
|
24
24
|
export { updateSiteLanguage } from './updateSiteLanguage';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/i18n/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACL,UAAU,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../runtime/i18n/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACL,UAAU,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,OAAO,GAKR,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,aAAa,EACb,SAAS,EACT,wBAAwB,EACxB,WAAW,EACX,wBAAwB,EACxB,wBAAwB,EACxB,SAAS,EACT,KAAK,EACL,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["/**\n * #### Import members from **@openedx/frontend-base**\n * The i18n module relies on react-intl and re-exports all of that package's exports.\n *\n * For each locale we want to support, react-intl needs the translations as an object holding\n * message id / translated string pairs. A locale string and the messages object are passed into\n * the IntlProvider element that wraps your element hierarchy. The locale data used to format\n * numbers, dates, and plurals comes from the runtime's built-in Intl APIs.\n *\n * Note that react-intl has no way of checking if the translations you give it actually have\n * anything to do with the locale you pass it; it will happily use whatever messages object you pass\n * in.\n *\n * Messages are provided to this module via the configureI18n() function below.\n *\n *\n * @module Internationalization\n * @see {@link https://github.com/openedx/frontend-base/blob/master/docs/how_tos/i18n.rst}\n * @see {@link https://formatjs.io/docs/react-intl/components/ Intl} for components exported from this module.\n *\n */\n\nexport {\n createIntl,\n defineMessages,\n FormattedDate,\n FormattedMessage,\n FormattedNumber,\n FormattedPlural,\n FormattedRelativeTime,\n FormattedTime,\n IntlProvider,\n useIntl,\n type IntlConfig,\n type ResolvedIntlConfig,\n type IntlShape,\n type MessageDescriptor,\n} from 'react-intl';\n\nexport {\n configureI18n,\n getLocale,\n getLocalizedLanguageName,\n getMessages,\n getPrimaryLanguageSubtag,\n getSupportedLanguageList,\n handleRtl,\n isRtl,\n LOCALE_CHANGED,\n LOCALE_TOPIC,\n mergeMessages,\n updateLocale,\n} from './lib';\n\nexport { updateSiteLanguage } from './updateSiteLanguage';\n"]}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { configureAnalytics, getAnalyticsService, identifyAnonymousUser, identif
|
|
|
2
2
|
export { AUTHENTICATED_USER_CHANGED, AUTHENTICATED_USER_TOPIC, AxiosJwtAuthService, configureAuth, ensureAuthenticatedUser, fetchAuthenticatedUser, getAuthenticatedHttpClient, getAuthenticatedUser, getAuthService, getHttpClient, getLoginRedirectUrl, getLogoutRedirectUrl, hydrateAuthenticatedUser, MockAuthService, redirectToLogin, redirectToLogout, setAuthenticatedUser } from './auth';
|
|
3
3
|
export { getSiteConfig, setSiteConfig, mergeSiteConfig, addAppConfigs, getAppConfig, mergeAppConfig, setActiveRouteRoles, getActiveRouteRoles, addActiveWidgetRole, removeActiveWidgetRole, getActiveWidgetRoles, getActiveRoles, getExternalLinkUrl, getProvides, getProvidesAsStrings } from './config';
|
|
4
4
|
export * from './constants';
|
|
5
|
-
export { configureI18n, createIntl, defineMessages, FormattedDate, FormattedMessage, FormattedNumber, FormattedPlural, FormattedRelativeTime, FormattedTime, getLocale, getLocalizedLanguageName, getMessages, getPrimaryLanguageSubtag, getSupportedLanguageList, handleRtl, IntlProvider, isRtl, LOCALE_CHANGED, LOCALE_TOPIC, mergeMessages, updateLocale, useIntl, updateSiteLanguage, type IntlConfig, type ResolvedIntlConfig, type IntlShape, } from './i18n';
|
|
5
|
+
export { configureI18n, createIntl, defineMessages, FormattedDate, FormattedMessage, FormattedNumber, FormattedPlural, FormattedRelativeTime, FormattedTime, getLocale, getLocalizedLanguageName, getMessages, getPrimaryLanguageSubtag, getSupportedLanguageList, handleRtl, IntlProvider, isRtl, LOCALE_CHANGED, LOCALE_TOPIC, mergeMessages, updateLocale, useIntl, updateSiteLanguage, type IntlConfig, type ResolvedIntlConfig, type IntlShape, type MessageDescriptor, } from './i18n';
|
|
6
6
|
export { auth, getBasename, initError, initialize } from './initialize';
|
|
7
7
|
export { loadExternalScripts } from './scripts';
|
|
8
8
|
export { configureLogging, getLoggingService, logError, logInfo, MockLoggingService, NewRelicLoggingService, resetLoggingService } from './logging';
|
|
@@ -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,YAAY,EACZ,KAAK,EACL,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,OAAO,EACP,kBAAkB,
|
|
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,EACn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Ae,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 IntlProvider,\n isRtl,\n LOCALE_CHANGED,\n LOCALE_TOPIC,\n mergeMessages,\n updateLocale,\n useIntl,\n updateSiteLanguage,\n type IntlConfig,\n type ResolvedIntlConfig,\n type IntlShape,\n type MessageDescriptor,\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"]}
|
package/dist/types.d.ts
CHANGED
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../types.ts"],"names":[],"mappings":"AAkIA,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 defaultConfig?: AppConfig;\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 // Backends\n cmsBaseUrl: string;\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 // i18n\n defaultLanguage: string;\n supportedLanguages: string[];\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"]}
|