@lwrjs/everywhere 0.9.0-alpha.3 → 0.9.0-alpha.30
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 +2 -7
- package/build/__generated_site_amd_modules__/1/application/amd/l/en-US/ai/amd-bootstrap/configuration/ci/-/-/s/b284d11f8cc411b65b6d90502537b418/config.js +10 -0
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/@lwrjs/app-service/amd-bootstrap/module/amd/v/0_9_0-alpha_30/s/c40e6caf07454ce13961de8ca76ab7f0/@lwrjs_app-service_amd-bootstrap_module_amd.js +18 -0
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwc/v/2_38_1/s/8cf6b94d9c0b398c70c97fdca2759caa/lwc.js +8934 -0
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/everywhereAmd/v/0_9_0-alpha_30/s/c538071acf5bde58e816967a14c465c3/lwr_everywhereAmd.js +66 -0
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/init/v/0_9_0-alpha_30/s/206e6e0af6f019fdfd86d87d56331bc2/lwr_init.js +97 -0
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/loader/v/{0_9_0-alpha_3/s/e90b08f1a747eae5e3796b35945f8395 → 0_9_0-alpha_30/s/1844779425734bf5c7932694310b6d89}/lwr_loader.js +362 -137
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/metrics/v/0_9_0-alpha_30/s/3426e42c3e22ce07ab2adc62c4c523a0/lwr_metrics.js +66 -0
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/profiler/v/0_9_0-alpha_30/s/e25f3b0b8b5c096acebf847d0a83ea62/lwr_profiler.js +68 -0
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/vault/v/0_9_0-alpha_30/s/c92abd8c1fec2d7eff62e4b097abbe14/lwr_vault.js +21 -0
- package/build/__generated_site_amd_modules__/1/resource/amd/lwr-error-shim.js/v/{0_9_0-alpha_3 → 0_9_0-alpha_30/lwr-error-shim.js} +1 -1
- package/build/__generated_site_amd_modules__/1/resource/amd/lwr-loader-shim.bundle.js/v/0_9_0-alpha_30/lwr-loader-shim.bundle.js +1547 -0
- package/build/amd-client.js +1 -2
- package/build/assets/amd/lwr-everywhere-debug.js +42 -33
- package/build/assets/amd/lwr-everywhere-min.js +1 -1
- package/build/assets/amd/lwr-everywhere.js +42 -33
- package/build/assets/core/lwr-everywhere-debug.js +39 -30
- package/build/assets/core/lwr-everywhere-min.js +1 -1
- package/build/assets/core/lwr-everywhere.js +39 -30
- package/build/assets/esm/lwr-everywhere-debug.js +4 -7
- package/build/assets/esm/lwr-everywhere-min.js +1 -1
- package/build/assets/esm/lwr-everywhere.js +4 -7
- package/build/esm-client.js +1 -2
- package/build/generate.js +4 -3
- package/build/index.js +2 -2
- package/build/modules/@salesforce/lds-default-luvio/lds-default-luvio.d.ts +24 -0
- package/build/modules/@salesforce/lds-default-luvio/lds-default-luvio.js +60 -0
- package/build/modules/lwr/everywhere/everywhere.d.ts +1 -1
- package/build/modules/lwr/everywhere/everywhere.js +8 -6
- package/build/modules/lwr/everywhereAmd/everywhereAmd.d.ts +1 -1
- package/build/modules/lwr/everywhereAmd/everywhereAmd.js +9 -11
- package/build/modules/lwr/everywhereEsm/everywhereEsm.js +1 -2
- package/build/modules/lwr/host/host.js +23 -27
- package/build/modules/lwr/setupLDS/network.d.ts +3 -0
- package/build/modules/lwr/setupLDS/network.js +88 -0
- package/build/modules/lwr/setupLDS/setupLDS.d.ts +2 -0
- package/build/modules/lwr/setupLDS/setupLDS.js +12 -0
- package/build/modules/lwr/setupNodeLDS/network.d.ts +3 -0
- package/build/modules/lwr/setupNodeLDS/network.js +88 -0
- package/build/modules/lwr/setupNodeLDS/setupNodeLDS.d.ts +2 -0
- package/build/modules/lwr/setupNodeLDS/setupNodeLDS.js +14 -0
- package/build/modules/lwr/vault/vault.d.ts +1 -1
- package/build/modules/lwr/vault/vault.js +3 -1
- package/build/utils.d.ts +1 -8
- package/build/utils.js +1 -4
- package/package.json +18 -8
- package/src/amd-client.ts +1 -2
- package/src/esm-client.ts +2 -3
- package/src/generate.ts +4 -3
- package/src/index.ts +2 -2
- package/src/utils.ts +2 -13
- package/build/__generated_site_amd_modules__/1/application/amd/l/en-US/ai/amd-bootstrap/configuration/ci/-/-/s/ea1d8c27665a4ad1a3f3be01ade2570d/config.js +0 -10
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/@lwrjs/app-service/amd-bootstrap/module/amd/v/0_9_0-alpha_3/s/c40e6caf07454ce13961de8ca76ab7f0/@lwrjs_app-service_amd-bootstrap_module_amd.js +0 -14
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwc/v/2_17_0/s/60dae7a83431c35c02c87ca8aaaa6044/lwc.js +0 -6244
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/everywhereAmd/v/0_9_0-alpha_3/s/e66806169480601930ec9cfca972815e/lwr_everywhereAmd.js +0 -48
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/init/v/0_9_0-alpha_3/s/6258bcb20cc2d5d6a9f3c5a6f9d0acaf/lwr_init.js +0 -58
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/metrics/v/0_9_0-alpha_3/s/dfbc827104d50ff7d16b59c9d0e06aca/lwr_metrics.js +0 -56
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/profiler/v/0_9_0-alpha_3/s/5a10236d8c52bc9f6dee22875cd7016d/lwr_profiler.js +0 -51
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/vault/v/0_9_0-alpha_3/s/6cbce1f9b7e815ee862b26f37ff4c76e/lwr_vault.js +0 -13
- package/build/__generated_site_amd_modules__/1/resource/amd/lwr-loader-shim.js/v/0_9_0-alpha_3 +0 -311
- package/build/__generated_site_amd_modules__/en-US/index.html +0 -26
- package/build/__generated_site_amd_modules__/index.html +0 -26
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
+
globalThis.process = { env: { NODE_ENV: 'development' } };
|
|
7
8
|
// Construct the Client Bootstrap Config object
|
|
8
9
|
function getConfiguration(options) {
|
|
9
10
|
const { format, server, apiVersion, apiPrefix, locale, bundle, debug } = options;
|
|
@@ -38,10 +39,7 @@ function getConfiguration(options) {
|
|
|
38
39
|
if (debug && config.endpoints) {
|
|
39
40
|
config.endpoints.modifiers = { debug: 'true' };
|
|
40
41
|
}
|
|
41
|
-
return
|
|
42
|
-
options: { NODE_ENV: debug ? 'development' : 'production' },
|
|
43
|
-
config, // globalThis.LWR
|
|
44
|
-
};
|
|
42
|
+
return config;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
/**
|
|
@@ -50,7 +48,7 @@ function getConfiguration(options) {
|
|
|
50
48
|
* SPDX-License-Identifier: MIT
|
|
51
49
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
52
50
|
*/
|
|
53
|
-
/* LWR Module Loader v0.9.0-alpha.
|
|
51
|
+
/* LWR Module Loader v0.9.0-alpha.30 */
|
|
54
52
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
55
53
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
54
|
function templateString(template, args) {
|
|
@@ -148,7 +146,7 @@ const STALE_HOOK_ERROR = Object.freeze({
|
|
|
148
146
|
const MODULE_ALREADY_LOADED = Object.freeze({
|
|
149
147
|
code: 3017,
|
|
150
148
|
level: 0,
|
|
151
|
-
message: 'Marking module(s) as externally loaded, but they are already loaded:
|
|
149
|
+
message: 'Marking module(s) as externally loaded, but they are already loaded:',
|
|
152
150
|
});
|
|
153
151
|
const FAIL_HOOK_LOAD = Object.freeze({
|
|
154
152
|
code: 3018,
|
|
@@ -347,11 +345,13 @@ if (hasDocument) {
|
|
|
347
345
|
|
|
348
346
|
// Bootstrap / shim
|
|
349
347
|
|
|
348
|
+
// Loader: modules
|
|
350
349
|
const LOADER_PREFIX = 'lwr.loader.';
|
|
351
350
|
const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
|
|
352
351
|
const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
|
|
353
352
|
const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
|
|
354
353
|
|
|
354
|
+
// Loader: mappings
|
|
355
355
|
const MAPPINGS_FETCH = `${LOADER_PREFIX}mappings.fetch`;
|
|
356
356
|
const MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
|
|
357
357
|
|
|
@@ -812,12 +812,8 @@ class ModuleRegistry {
|
|
|
812
812
|
* @param modules - list of module identifiers
|
|
813
813
|
*/
|
|
814
814
|
registerExternalModules(modules) {
|
|
815
|
-
const alreadyRegistered = [];
|
|
816
815
|
modules.map((id) => {
|
|
817
|
-
if (this.namedDefineRegistry.has(id)) {
|
|
818
|
-
alreadyRegistered.push(id);
|
|
819
|
-
}
|
|
820
|
-
else {
|
|
816
|
+
if (!this.namedDefineRegistry.has(id)) {
|
|
821
817
|
let resolveExternal;
|
|
822
818
|
let timer;
|
|
823
819
|
const moduleDefPromise = new Promise((resolve, reject) => {
|
|
@@ -841,11 +837,11 @@ class ModuleRegistry {
|
|
|
841
837
|
};
|
|
842
838
|
this.namedDefineRegistry.set(id, moduleDef);
|
|
843
839
|
}
|
|
840
|
+
else if (process.env.NODE_ENV !== 'production' && hasConsole) {
|
|
841
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
842
|
+
console.warn(MODULE_ALREADY_LOADED.message, id);
|
|
843
|
+
}
|
|
844
844
|
});
|
|
845
|
-
// throw error for modules that were already registered
|
|
846
|
-
if (alreadyRegistered.length) {
|
|
847
|
-
throw new LoaderError(MODULE_ALREADY_LOADED, [alreadyRegistered.join(', ')]);
|
|
848
|
-
}
|
|
849
845
|
}
|
|
850
846
|
getImportMetadataResolver() {
|
|
851
847
|
return this.resolver;
|
|
@@ -987,7 +983,7 @@ class ModuleRegistry {
|
|
|
987
983
|
moduleDefault = { default: moduleDefault };
|
|
988
984
|
// __defaultInterop is ONLY used to support backwards compatibility
|
|
989
985
|
// of importing default exports the "wrong" way (when not using named exports).
|
|
990
|
-
// See https://github.com/salesforce/lwr/pull/816
|
|
986
|
+
// See https://github.com/salesforce-experience-platform-emu/lwr/pull/816
|
|
991
987
|
Object.defineProperty(moduleDefault, '__defaultInterop', { value: true });
|
|
992
988
|
}
|
|
993
989
|
// if no return value, then we are using the exports object
|
|
@@ -1209,7 +1205,7 @@ class Loader {
|
|
|
1209
1205
|
const appId = match && match[1];
|
|
1210
1206
|
config.appMetadata.appId = appId;
|
|
1211
1207
|
}
|
|
1212
|
-
// TODO: https://github.com/salesforce/lwr/issues/1087
|
|
1208
|
+
// TODO: https://github.com/salesforce-experience-platform-emu/lwr/issues/1087
|
|
1213
1209
|
this.services = Object.freeze({
|
|
1214
1210
|
addLoaderPlugin: this.registry.addLoaderPlugin.bind(this.registry),
|
|
1215
1211
|
handleStaleModule: this.registry.registerHandleStaleModuleHook.bind(this.registry),
|
|
@@ -1284,8 +1280,7 @@ class Loader {
|
|
|
1284
1280
|
// Process the LWR Client Bootstrap Config
|
|
1285
1281
|
const configOptions = { "format": "amd", "apiVersion": "v57.0", "apiPrefix": "/lwr", "bundle": false, "debug": true };
|
|
1286
1282
|
const configuration = getConfiguration(configOptions);
|
|
1287
|
-
const { bootstrapModule, endpoints, baseUrl, imports, index } = configuration
|
|
1288
|
-
globalThis.process = { env: { NODE_ENV: configuration.options.NODE_ENV } }; // Required by LWC
|
|
1283
|
+
const { bootstrapModule, endpoints, baseUrl, imports, index } = configuration;
|
|
1289
1284
|
// Initialize the AMD loader (its code is bundled into the LWR Everywhere module)
|
|
1290
1285
|
const loader = new Loader({ endpoints, baseUrl });
|
|
1291
1286
|
loader.define('lwr/loader/v/0_0_1', ['exports'], (exports) => {
|
|
@@ -1297,9 +1292,11 @@ loader.define('lwr/loader/v/0_0_1', ['exports'], (exports) => {
|
|
|
1297
1292
|
await loader.registerImportMappings({ imports, index }, [bootstrapModule]);
|
|
1298
1293
|
globalThis.LWR = Object.freeze({ define: loader.define.bind(loader) });
|
|
1299
1294
|
// Define preload modules (ie: ABS, vault, etc) BEFORE loading them
|
|
1300
|
-
LWR.define(
|
|
1301
|
-
|
|
1302
|
-
|
|
1295
|
+
LWR.define('lwr/everywhereAmd/v/0_0_1', ['exports', 'lwr/vault/v/0_0_1'], function (exports, _0_9_0Alpha_30) {
|
|
1296
|
+
// IMPORTANT: Do not add any static imports to this file that are not bundled with the amd-client
|
|
1297
|
+
// Do an OAuthed fetch
|
|
1298
|
+
async function authFetch(url, accept = 'javascript') {
|
|
1299
|
+
const authInfo = _0_9_0Alpha_30.getAuthInfo();
|
|
1303
1300
|
if (authInfo) {
|
|
1304
1301
|
return fetch(url, {
|
|
1305
1302
|
headers: {
|
|
@@ -1308,44 +1305,56 @@ LWR.define("lwr/everywhereAmd/v/0_0_1", ["exports", "lwr/vault/v/0_0_1"], functi
|
|
|
1308
1305
|
}
|
|
1309
1306
|
});
|
|
1310
1307
|
}
|
|
1311
|
-
return null;
|
|
1308
|
+
return null; // defer to loader
|
|
1312
1309
|
}
|
|
1310
|
+
// Add a hook for adding OAuth headers to module and mapping requests
|
|
1311
|
+
// Workaround: core does not have proper versioning; replace all versions with 0_0_1
|
|
1313
1312
|
function everywhereHooks(serviceAPI, mappingEndpoint, coreVersion) {
|
|
1314
1313
|
serviceAPI.addLoaderPlugin({
|
|
1315
1314
|
loadModule: async (url) => {
|
|
1316
1315
|
return authFetch(url);
|
|
1317
1316
|
},
|
|
1318
1317
|
loadMapping: async (specifier) => {
|
|
1319
|
-
const res = await authFetch(`${mappingEndpoint}${encodeURIComponent(specifier)}`,
|
|
1318
|
+
const res = await authFetch(`${mappingEndpoint}${encodeURIComponent(specifier)}`, 'json');
|
|
1320
1319
|
if (res && res.ok) {
|
|
1321
1320
|
return res.json();
|
|
1322
1321
|
}
|
|
1323
1322
|
return null;
|
|
1324
1323
|
},
|
|
1325
|
-
resolveModule:
|
|
1324
|
+
resolveModule: specifier => {
|
|
1325
|
+
// Workaround W-8010259 (dynamic imports without versions)
|
|
1326
|
+
// by adding a default version to version-less specifiers
|
|
1326
1327
|
if (specifier && !/\/v\/[^/]+?$/.test(specifier)) {
|
|
1327
1328
|
return `${specifier}/v/${coreVersion}`;
|
|
1328
1329
|
}
|
|
1329
|
-
return null;
|
|
1330
|
+
return null; // defer to loader
|
|
1330
1331
|
}
|
|
1331
1332
|
});
|
|
1332
1333
|
}
|
|
1333
1334
|
function initAmd(services, mappingEndpoint, coreVersion) {
|
|
1335
|
+
// Initialize the loader hooks for LWR-S endpoints
|
|
1334
1336
|
if (mappingEndpoint.match(/\/v5\d\.0\//)) {
|
|
1335
1337
|
everywhereHooks(services, mappingEndpoint, coreVersion);
|
|
1336
1338
|
}
|
|
1337
1339
|
}
|
|
1340
|
+
// Export the LWRE authenticate() API
|
|
1341
|
+
// This is a duplicate of the function exported from "lwr/everywhere"
|
|
1342
|
+
// because it MUST be bundled into the LWRE module via "lwr/everywhereAmd"
|
|
1338
1343
|
function authenticate(authInfo) {
|
|
1344
|
+
// Put OAuth info into the vault
|
|
1339
1345
|
if (authInfo) {
|
|
1340
|
-
|
|
1346
|
+
_0_9_0Alpha_30.setAuthInfo(authInfo);
|
|
1341
1347
|
}
|
|
1342
1348
|
}
|
|
1343
1349
|
exports.authenticate = authenticate;
|
|
1344
1350
|
exports.initAmd = initAmd;
|
|
1345
|
-
Object.defineProperty(exports,
|
|
1351
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1346
1352
|
});
|
|
1347
|
-
LWR.define(
|
|
1353
|
+
LWR.define('lwr/vault/v/0_0_1', ['exports'], function (exports) {
|
|
1354
|
+
// Credential vault for storing setters and subscribers for OAuth info
|
|
1355
|
+
// This module is a SINGLETON and must be excluded from ESM bundling
|
|
1348
1356
|
let authInfo;
|
|
1357
|
+
// Get and set the OAuth info
|
|
1349
1358
|
function getAuthInfo() {
|
|
1350
1359
|
return authInfo;
|
|
1351
1360
|
}
|
|
@@ -1354,7 +1363,7 @@ LWR.define("lwr/vault/v/0_0_1", ["exports"], function (exports) {
|
|
|
1354
1363
|
}
|
|
1355
1364
|
exports.getAuthInfo = getAuthInfo;
|
|
1356
1365
|
exports.setAuthInfo = setAuthInfo;
|
|
1357
|
-
Object.defineProperty(exports,
|
|
1366
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1358
1367
|
});
|
|
1359
1368
|
// Set up the AMD loader hooks for OAuth
|
|
1360
1369
|
const { initAmd, authenticate } = await loader.load(bootstrapModule);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function getConfiguration(e){const{format:t,server:r,apiVersion:o,apiPrefix:n,locale:i,bundle:s,debug:a}=e,l=new URL(import.meta.url),d=r||l.origin||"",c=`${n}/${o}`,u="0"+(i?`/l/${i}`:""),p="/bi/3_A,B,O,S,EG,JLMT,C,D,F,H,I,K,N,P,Q,R",f=s?`${d}${c}/bundle/${t}/${u}${p}-0/module/mi/`:`${d}${c}/module/${t}/${u}/mi/`,h=`lwr/everywhere${"esm"===t?"Esm":"Amd"}/v/0_0_1`,g=`${f}${encodeURIComponent(h)}/latest${a?"?debug":""}`,m={appId:"lwre",autoBoot:!0,bootstrapModule:h,baseUrl:d,imports:{[g]:[h]},index:{[h]:g},endpoints:{uris:{module:f,mapping:`${d}${c}/mapping/${t}/${u}${s?p:""}/mp/`}}};return a&&m.endpoints&&(m.endpoints.modifiers={debug:"true"}),{options:{NODE_ENV:a?"development":"production"},config:m}}const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"}),MODULE_ALREADY_LOADED=Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded: {0}"}),FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),NO_MAPPING_URL=Object.freeze({code:3019,level:0,message:"Mapping endpoint not set"}),BAD_IMPORT_METADATA=Object.freeze({code:3020,level:0,message:"Invalid import metadata: {0} {1}"});Object.freeze({code:3011,level:0,message:"import map is not valid"});const hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const n=o.slice(0,o.lastIndexOf("/")+1)+e,i=[];let s=-1;for(let e=0;e<n.length;e++)-1!==s?"/"===n[e]&&(i.push(n.slice(s,e+1)),s=-1):"."===n[e]?"."!==n[e+1]||"/"!==n[e+2]&&e+2!==n.length?"/"===n[e+1]||e+1===n.length?e+=1:s=e:(i.pop(),e+=2):s=e;return-1!==s&&i.push(n.slice(s)),t.slice(0,t.length-o.length)+i.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const LOADER_PREFIX="lwr.loader.",MODULE_DEFINE=`${LOADER_PREFIX}module.define`,MODULE_FETCH=`${LOADER_PREFIX}module.fetch`,MODULE_ERROR=`${LOADER_PREFIX}module.error`,MAPPINGS_FETCH=`${LOADER_PREFIX}mappings.fetch`,MAPPINGS_ERROR=`${LOADER_PREFIX}mappings.error`;class ImportMetadataResolver{constructor(e,t){this.importURICache=new Map,this.pendingURICache=new Map,this.loadMappingHooks=[],this.config=e,this.invalidationCallback=t}addLoadMappingHook(e){this.loadMappingHooks.push(e)}getMappingEndpoint(){return this.config.endpoints&&this.config.endpoints.uris?this.config.endpoints.uris.mapping:void 0}getModifiersAsUrlParams(){const e=this.config.endpoints?this.config.endpoints.modifiers:void 0;if(e){return`?${Object.keys(e).map((t=>`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`)).join("&")}`}return""}buildMappingUrl(e){return`${this.getMappingEndpoint()}${encodeURIComponent(e)}${this.getModifiersAsUrlParams()}`}getBaseUrl(){return this.config.baseUrl}registerImportMappings(e,t){if(!t||0===t.length){const r=e?JSON.stringify(e):"undefined";throw new LoaderError(BAD_IMPORT_METADATA,[r,t?"[]":"undefined"])}if(!e)throw new LoaderError(BAD_IMPORT_METADATA,["undefined",JSON.stringify(t)]);if(!e.imports||0===Object.keys(e.imports).length)throw new LoaderError(BAD_IMPORT_METADATA,[JSON.stringify(e),JSON.stringify(t)]);const r=e.index||{};for(const[o,n]of Object.entries(e.imports))n.forEach((e=>{const n=r[e],i=this.importURICache.get(e);if(i){const t=n||o,r=i.identity||i.uri;r!==t&&this.invalidationCallback({name:e,oldUrl:r,newUrl:t})}else this.saveImportURIRecord(e,o,n,t.includes(e))}))}getURI(e){return this.importURICache.has(e)?resolveUrl(this.importURICache.get(e).uri,this.getBaseUrl()):void 0}resolveLocal(e){const t=this.getURI(e);return t||(isUrl(e)||e.startsWith("/")?e:void 0)}async resolve(e){let t=this.getURI(e);if(t)return t;if(isUrl(e)||e.startsWith("/"))return e;{const r=this.pendingURICache.get(e);if(r)return r;this.config.profiler.logOperationStart({id:MAPPINGS_FETCH,specifier:e});const o=(this.hasMappingHooks()?this.evaluateMappingHooks:this.fetchNewMappings).bind(this)(e).then((r=>{if(!r||!r.imports)throw new LoaderError(UNRESOLVED,[e]);if(this.registerImportMappings(r,[e]),t=this.getURI(e),!t)throw new LoaderError(UNRESOLVED,[e]);return this.config.profiler.logOperationEnd({id:MAPPINGS_FETCH,specifier:e}),t})).finally((()=>{this.pendingURICache.delete(e)}));return this.pendingURICache.set(e,o),o}}hasMappingHooks(){return this.loadMappingHooks.length>0}async evaluateMappingHooks(e){const t=this.loadMappingHooks;if(t.length){const r=Array.from(this.importURICache.keys());for(let o=0;o<t.length;o++){const n=t[o],i=await n(e,{knownModules:r});if(i||void 0===i)return i}}return this.fetchNewMappings(e)}async fetchNewMappings(e){if("function"!=typeof globalThis.fetch)throw new LoaderError(UNRESOLVED,[e]);const t=resolveUrl(this.buildMappingUrl(e),this.getBaseUrl());return globalThis.fetch(t).then((t=>{if(!t.ok)throw this.config.profiler.logOperationStart({id:MAPPINGS_ERROR,specifier:e}),new LoaderError(UNRESOLVED,[e]);return t.json().then((e=>e)).catch((t=>{throw new LoaderError(UNRESOLVED,[e])}))}))}saveImportURIRecord(e,t,r,o){r&&t!==r?this.importURICache.set(e,{uri:t,identity:r,isRoot:o}):this.importURICache.set(e,{uri:t,isRoot:o})}}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldUrl:o,newUrl:n}=t;for(let t=0;t<e.length;t++){const i=e[t];try{if(null!==i({name:r,oldUrl:o,newUrl:n}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}const MODULE_LOAD_TIMEOUT_TIMER=3e5;let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then((async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,`${response.status}`]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0}))}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise(((r,o)=>{const n=setTimeout((()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER);t.then((e=>{r(e)})).catch((()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))})).finally((()=>{clearTimeout(n)}))})):t}hasDocument&&globalThis.addEventListener("error",(e=>{lastWindowError=e.error})),"production"!==process.env.NODE_ENV&&!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,this.aliases=new Map,this.profiler=e.profiler,this.resolver=new ImportMetadataResolver(e,this.importMetadataInvalidationCallback.bind(this))}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.resolver.getBaseUrl();let o,n=e;const i=this.resolveHook;if(i){for(let e=0;e<i.length;e++){const t=(0,i[e])(n,{parentUrl:r});let s;if((t||null===t)&&(s=isResponseAPromise(t)?await t:t),null!==s){if("string"==typeof s){if(resolveIfNotPlainOrUrl(s,r))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);n=s;continue}if(o=s&&s.url&&(resolveIfNotPlainOrUrl(s.url,r)||s.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(n!==e){if(!o&&this.namedDefineRegistry.has(n))return n;e=n}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;const n=this.resolver.resolveLocal(t);if(n){if(this.namedDefineRegistry.has(t)&&this.namedDefineRegistry.get(t).defined){if(!this.moduleRegistry.get(n)||!this.aliases.has(t))return t}return n}if(this.namedDefineRegistry.has(t))return t;try{o=await this.resolver.resolve(t)}catch(e){}}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+=`?importer=${encodeURIComponent(t)}`),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r){const o=this.namedDefineRegistry.get(e);if(o&&o.defined)return"production"!==process.env.NODE_ENV&&hasConsole&&console.warn(`Module redefine attempted: ${e}`),void(this.lastDefine=o);const n={name:e,dependencies:t,exporter:r,defined:!0};o&&o.external&&o.external.resolveExternal(n),this.profiler.logOperationStart({id:MODULE_DEFINE,specifier:e}),this.namedDefineRegistry.set(e,n),this.lastDefine=n}registerExternalModules(e){const t=[];if(e.map((e=>{if(this.namedDefineRegistry.has(e))t.push(e);else{let t,r;const o=new Promise(((o,n)=>{t=o,r=setTimeout((()=>{n(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER)})).finally((()=>{clearTimeout(r)})),n={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,n)}})),t.length)throw new LoaderError(MODULE_ALREADY_LOADED,[t.join(", ")])}getImportMetadataResolver(){return this.resolver}getExistingModuleRecord(e,t){const r=this.moduleRegistry.get(e);if(r)return this.storeModuleAlias(t,e),r;if(e!==t){const e=this.aliases.get(t);if(e){const t=this.moduleRegistry.get(e);if(t)return t}}return r}getModuleRecord(e,t){const r=this.getExistingModuleRecord(e,t);if(r)return r;const o=this.getModuleDef(e,t),n=o.then((e=>{const t=e.dependencies.map((e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)})).filter((e=>void 0!==e));return Promise.all(t)})),i={id:e,module:Object.create(null),dependencyRecords:n,instantiation:o,evaluated:!1,evaluationPromise:null};return this.moduleRegistry.set(e,i),this.storeModuleAlias(t,e),i}storeModuleAlias(e,t){if(e!==t)if(this.aliases.has(e)){if("production"!==process.env.NODE_ENV&&hasConsole){const r=this.aliases.get(e);r!==t&&console.warn(`Alias update attempt: ${e}=>${r}, ${t}`)}}else this.aliases.set(e,t)}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:n}=await e.instantiation,i={},s=await Promise.all(n.map((async e=>{if("exports"===e)return i;const t=await this.resolve(e),r=this.moduleRegistry.get(t);if(!r)throw new LoaderError(FAILED_DEP,[t]);const o=r.module;if(!r.evaluated)return this.getCircularDependencyWrapper(o);if(o)return o.__defaultInterop?o.default:o;throw new LoaderError(FAILED_DEP,[t])})));if(e.evaluated)return e.module;let a=o(...s);void 0!==a?(a={default:a},Object.defineProperty(a,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(i)&&Object.defineProperty(i,"__useDefault",{value:!0});const l=a||i;for(const t in l)Object.defineProperty(e.module,t,{enumerable:!0,set(e){l[t]=e},get:()=>l[t]});return l.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),l.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),l.__esModule&&Object.defineProperty(e.module,"__esModule",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const n=this.resolver.getBaseUrl(),i=r||t;return this.profiler.logOperationStart({id:MODULE_FETCH,specifier:i}),Promise.resolve().then((async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,n),i=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===i)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(i&&null!==i)return evaluateLoadHookResponse(i,e)}return!1})).then((t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)})).then((()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return this.profiler.logOperationEnd({id:MODULE_FETCH,specifier:i}),o})).catch((e=>{throw this.profiler.logOperationStart({id:MODULE_ERROR,specifier:i}),e}))}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r,loadMapping:o}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t]),o&&this.resolver.addLoadMappingHook(o)}importMetadataInvalidationCallback({name:e,oldUrl:t,newUrl:r}){const o=this.handleStaleModuleHook;o?evaluateHandleStaleModuleHooks(o,{name:e,oldUrl:t,newUrl:r}):"production"!==process.env.NODE_ENV&&hasConsole&&console.warn(`stale module detected ${e}, current URL:${t}, new URL:${r}`)}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}class Loader{constructor(e){let t=e.baseUrl;const r=e.endpoints?e.endpoints.uris.mapping:void 0;let o=e.profiler;if(!r)throw new LoaderError(NO_MAPPING_URL);if(e.endpoints.uris.mapping=r.replace(/\/?$/,"/"),t&&(t=t.replace(/\/?$/,"/")),t||(t=getBaseUrl()),!t)throw new LoaderError(NO_BASE_URL);if(o||(o={logOperationStart:()=>{},logOperationEnd:()=>{}}),this.registry=new ModuleRegistry(Object.freeze({endpoints:e.endpoints,baseUrl:t,profiler:o})),e.appMetadata&&!e.appMetadata.appId){const t=e.appMetadata.bootstrapModule.match(/@lwr-bootstrap\/(.+)\/v\/.+/),r=t&&t[1];e.appMetadata.appId=r}this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry),appMetadata:e.appMetadata})}define(e,t,r){invariant("string"==typeof e,MISSING_NAME);let o=r,n=t;"function"==typeof n&&(o=t,n=[]),invariant(Array.isArray(n),INVALID_DEPS),this.registry.define(e,n,o)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e,t){this.registry.getImportMetadataResolver().registerImportMappings(e,t)}registerExternalModules(e){this.registry.registerExternalModules(e)}}const configOptions={format:"amd",apiVersion:"v57.0",apiPrefix:"/lwr",bundle:!0,debug:!1},configuration=getConfiguration(configOptions),{bootstrapModule:bootstrapModule,endpoints:endpoints,baseUrl:baseUrl,imports:imports,index:index}=configuration.config;globalThis.process={env:{NODE_ENV:configuration.options.NODE_ENV}};const loader=new Loader({endpoints:endpoints,baseUrl:baseUrl});loader.define("lwr/loader/v/0_0_1",["exports"],(e=>{Object.assign(e,{define:loader.define.bind(loader),load:loader.load.bind(loader)})})),await loader.registerImportMappings({imports:imports,index:index},[bootstrapModule]),globalThis.LWR=Object.freeze({define:loader.define.bind(loader)}),LWR.define("lwr/everywhereAmd/v/0_0_1",["exports","lwr/vault/v/0_0_1"],(function(e,t){async function r(e,r="javascript"){const o=t.getAuthInfo();return o?fetch(e,{headers:{Accept:`application/${r}`,Authorization:`Bearer ${o.access_token}`}}):null}e.authenticate=function(e){e&&t.setAuthInfo(e)},e.initAmd=function(e,t,o){t.match(/\/v5\d\.0\//)&&function(e,t,o){e.addLoaderPlugin({loadModule:async e=>r(e),loadMapping:async e=>{const o=await r(`${t}${encodeURIComponent(e)}`,"json");return o&&o.ok?o.json():null},resolveModule:e=>e&&!/\/v\/[^/]+?$/.test(e)?`${e}/v/${o}`:null})}(e,t,o)},Object.defineProperty(e,"__esModule",{value:!0})})),LWR.define("lwr/vault/v/0_0_1",["exports"],(function(e){let t;e.getAuthInfo=function(){return t},e.setAuthInfo=function(e){t=e},Object.defineProperty(e,"__esModule",{value:!0})}));const{initAmd:initAmd,authenticate:authenticate}=await loader.load(bootstrapModule);async function createComponent(e,t,r={},o){const{createComponent:n}=await loader.load(bootstrapModule.replace("Amd",""));return n(e,t,r,o)}initAmd(loader.services,endpoints?.uris.mapping,"0_0_1");export{authenticate,createComponent};
|
|
1
|
+
function getConfiguration(e){const{format:t,server:r,apiVersion:o,apiPrefix:n,locale:i,bundle:s,debug:a}=e,l=new URL(import.meta.url),d=r||l.origin||"",c=`${n}/${o}`,u="0"+(i?`/l/${i}`:""),p="/bi/3_A,B,O,S,EG,JLMT,C,D,F,H,I,K,N,P,Q,R",f=s?`${d}${c}/bundle/${t}/${u}${p}-0/module/mi/`:`${d}${c}/module/${t}/${u}/mi/`,h=`lwr/everywhere${"esm"===t?"Esm":"Amd"}/v/0_0_1`,g=`${f}${encodeURIComponent(h)}/latest${a?"?debug":""}`,m={appId:"lwre",autoBoot:!0,bootstrapModule:h,baseUrl:d,imports:{[g]:[h]},index:{[h]:g},endpoints:{uris:{module:f,mapping:`${d}${c}/mapping/${t}/${u}${s?p:""}/mp/`}}};return a&&m.endpoints&&(m.endpoints.modifiers={debug:"true"}),m}globalThis.process={env:{NODE_ENV:"production"}};const templateRegex=/\{([0-9]+)\}/g;function templateString(e,t){return e.replace(templateRegex,((e,r)=>t[r]))}function generateErrorMessage(e,t){const r=Array.isArray(t)?templateString(e.message,t):e.message;return`LWR${e.code}: ${r}`}class LoaderError extends Error{constructor(e,t){super(),this.message=generateErrorMessage(e,t)}}function invariant(e,t){if(!e)throw new LoaderError(t)}const MISSING_NAME=Object.freeze({code:3e3,message:"A module name is required.",level:0}),FAIL_INSTANTIATE=Object.freeze({code:3004,message:"Failed to instantiate module: {0}",level:0}),NO_AMD_REQUIRE=Object.freeze({code:3005,message:"AMD require not supported.",level:0}),FAILED_DEP=Object.freeze({code:3006,level:0,message:"Failed to load dependency: {0}"}),INVALID_DEPS=Object.freeze({code:3007,message:"Unexpected value received for dependencies argument; expected an array.",level:0}),FAIL_LOAD=Object.freeze({code:3008,level:0,message:"Error loading {0}"}),UNRESOLVED=Object.freeze({code:3009,level:0,message:"Unable to resolve bare specifier: {0}"}),NO_BASE_URL=Object.freeze({code:3010,level:0,message:"baseUrl not set"});Object.freeze({code:3011,level:0,message:"Cannot set a loader service multiple times"});const INVALID_HOOK=Object.freeze({code:3012,level:0,message:"Invalid hook received"}),INVALID_LOADER_SERVICE_RESPONSE=Object.freeze({code:3013,level:0,message:"Invalid response received from hook"}),MODULE_LOAD_TIMEOUT=Object.freeze({code:3014,level:0,message:"Error loading {0} - timed out"}),HTTP_FAIL_LOAD=Object.freeze({code:3015,level:0,message:"Error loading {0}, status code {1}"}),STALE_HOOK_ERROR=Object.freeze({code:3016,level:0,message:"An error occurred handling module conflict"}),MODULE_ALREADY_LOADED=Object.freeze({code:3017,level:0,message:"Marking module(s) as externally loaded, but they are already loaded:"}),FAIL_HOOK_LOAD=Object.freeze({code:3018,level:0,message:'Error loading "{0}" from hook'}),NO_MAPPING_URL=Object.freeze({code:3019,level:0,message:"Mapping endpoint not set"}),BAD_IMPORT_METADATA=Object.freeze({code:3020,level:0,message:"Invalid import metadata: {0} {1}"});Object.freeze({code:3011,level:0,message:"import map is not valid"});const hasDocument="undefined"!=typeof document,hasSetTimeout="function"==typeof setTimeout,hasConsole="undefined"!=typeof console;function getBaseUrl(){let e;if(hasDocument){const t=document.querySelector("base[href]");e=t&&t.href}if(!e&&"undefined"!=typeof location){e=location.href.split("#")[0].split("?")[0];const t=e.lastIndexOf("/");-1!==t&&(e=e.slice(0,t+1))}return e}function isUrl(e){return-1!==e.indexOf("://")}function resolveIfNotPlainOrUrl(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(/\\/g,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){const r=t.slice(0,t.indexOf(":")+1);let o;if("/"===t[r.length+1]?"file:"!==r?(o=t.slice(r.length+2),o=o.slice(o.indexOf("/")+1)):o=t.slice(8):o=t.slice(r.length+("/"===t[r.length]?1:0)),"/"===e[0])return t.slice(0,t.length-o.length-1)+e;const n=o.slice(0,o.lastIndexOf("/")+1)+e,i=[];let s=-1;for(let e=0;e<n.length;e++)-1!==s?"/"===n[e]&&(i.push(n.slice(s,e+1)),s=-1):"."===n[e]?"."!==n[e+1]||"/"!==n[e+2]&&e+2!==n.length?"/"===n[e+1]||e+1===n.length?e+=1:s=e:(i.pop(),e+=2):s=e;return-1!==s&&i.push(n.slice(s)),t.slice(0,t.length-o.length)+i.join("")}}function resolveUrl(e,t){return resolveIfNotPlainOrUrl(e,t)||(isUrl(e)?e:resolveIfNotPlainOrUrl("./"+e,t))}function createScript(e){const t=document.createElement("script");return t.async=!0,t.crossOrigin="anonymous",t.src=e,t}let lastWindowError$1,lastWindowErrorUrl;function loadModuleDef(e){return new Promise((function(t,r){if(hasDocument){const o=createScript(e);o.addEventListener("error",(()=>{r(new LoaderError(FAIL_LOAD,[e]))})),o.addEventListener("load",(()=>{document.head.removeChild(o),lastWindowErrorUrl===e?r(lastWindowError$1):t()})),document.head.appendChild(o)}}))}hasDocument&&window.addEventListener("error",(e=>{lastWindowErrorUrl=e.filename,lastWindowError$1=e.error}));const LOADER_PREFIX="lwr.loader.",MODULE_DEFINE=`${LOADER_PREFIX}module.define`,MODULE_FETCH=`${LOADER_PREFIX}module.fetch`,MODULE_ERROR=`${LOADER_PREFIX}module.error`,MAPPINGS_FETCH=`${LOADER_PREFIX}mappings.fetch`,MAPPINGS_ERROR=`${LOADER_PREFIX}mappings.error`;class ImportMetadataResolver{constructor(e,t){this.importURICache=new Map,this.pendingURICache=new Map,this.loadMappingHooks=[],this.config=e,this.invalidationCallback=t}addLoadMappingHook(e){this.loadMappingHooks.push(e)}getMappingEndpoint(){return this.config.endpoints&&this.config.endpoints.uris?this.config.endpoints.uris.mapping:void 0}getModifiersAsUrlParams(){const e=this.config.endpoints?this.config.endpoints.modifiers:void 0;if(e){return`?${Object.keys(e).map((t=>`${encodeURIComponent(t)}=${encodeURIComponent(e[t])}`)).join("&")}`}return""}buildMappingUrl(e){return`${this.getMappingEndpoint()}${encodeURIComponent(e)}${this.getModifiersAsUrlParams()}`}getBaseUrl(){return this.config.baseUrl}registerImportMappings(e,t){if(!t||0===t.length){const r=e?JSON.stringify(e):"undefined";throw new LoaderError(BAD_IMPORT_METADATA,[r,t?"[]":"undefined"])}if(!e)throw new LoaderError(BAD_IMPORT_METADATA,["undefined",JSON.stringify(t)]);if(!e.imports||0===Object.keys(e.imports).length)throw new LoaderError(BAD_IMPORT_METADATA,[JSON.stringify(e),JSON.stringify(t)]);const r=e.index||{};for(const[o,n]of Object.entries(e.imports))n.forEach((e=>{const n=r[e],i=this.importURICache.get(e);if(i){const t=n||o,r=i.identity||i.uri;r!==t&&this.invalidationCallback({name:e,oldUrl:r,newUrl:t})}else this.saveImportURIRecord(e,o,n,t.includes(e))}))}getURI(e){return this.importURICache.has(e)?resolveUrl(this.importURICache.get(e).uri,this.getBaseUrl()):void 0}resolveLocal(e){const t=this.getURI(e);return t||(isUrl(e)||e.startsWith("/")?e:void 0)}async resolve(e){let t=this.getURI(e);if(t)return t;if(isUrl(e)||e.startsWith("/"))return e;{const r=this.pendingURICache.get(e);if(r)return r;this.config.profiler.logOperationStart({id:MAPPINGS_FETCH,specifier:e});const o=(this.hasMappingHooks()?this.evaluateMappingHooks:this.fetchNewMappings).bind(this)(e).then((r=>{if(!r||!r.imports)throw new LoaderError(UNRESOLVED,[e]);if(this.registerImportMappings(r,[e]),t=this.getURI(e),!t)throw new LoaderError(UNRESOLVED,[e]);return this.config.profiler.logOperationEnd({id:MAPPINGS_FETCH,specifier:e}),t})).finally((()=>{this.pendingURICache.delete(e)}));return this.pendingURICache.set(e,o),o}}hasMappingHooks(){return this.loadMappingHooks.length>0}async evaluateMappingHooks(e){const t=this.loadMappingHooks;if(t.length){const r=Array.from(this.importURICache.keys());for(let o=0;o<t.length;o++){const n=t[o],i=await n(e,{knownModules:r});if(i||void 0===i)return i}}return this.fetchNewMappings(e)}async fetchNewMappings(e){if("function"!=typeof globalThis.fetch)throw new LoaderError(UNRESOLVED,[e]);const t=resolveUrl(this.buildMappingUrl(e),this.getBaseUrl());return globalThis.fetch(t).then((t=>{if(!t.ok)throw this.config.profiler.logOperationStart({id:MAPPINGS_ERROR,specifier:e}),new LoaderError(UNRESOLVED,[e]);return t.json().then((e=>e)).catch((t=>{throw new LoaderError(UNRESOLVED,[e])}))}))}saveImportURIRecord(e,t,r,o){r&&t!==r?this.importURICache.set(e,{uri:t,identity:r,isRoot:o}):this.importURICache.set(e,{uri:t,isRoot:o})}}function reportError(e){hasConsole&&console.error(e)}function evaluateHandleStaleModuleHooks(e,t){const{name:r,oldUrl:o,newUrl:n}=t;for(let t=0;t<e.length;t++){const i=e[t];try{if(null!==i({name:r,oldUrl:o,newUrl:n}))break}catch(e){reportError(new LoaderError(STALE_HOOK_ERROR))}}}const MODULE_LOAD_TIMEOUT_TIMER=3e5;let lastWindowError;function isCustomResponse(e){return Object.prototype.hasOwnProperty.call(e,"data")&&!Object.prototype.hasOwnProperty.call(e,"blob")}function isFetchResponse(e){return"function"==typeof e.blob}function isResponseAPromise(e){return!(!e||!e.then)}async function evaluateLoadHookResponse(response,id){return Promise.resolve().then((async()=>{if(!response.status)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(200!==response.status)throw new LoaderError(HTTP_FAIL_LOAD,[id,`${response.status}`]);const isResponse=isFetchResponse(response);let code;if(isCustomResponse(response))code=response.data;else{if(!isResponse)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);code=await response.text()}if(!code)throw new LoaderError(FAIL_LOAD,[id]);code=`${code}\n//# sourceURL=${id}`;try{eval(code)}catch(e){throw new LoaderError(FAIL_LOAD,[id])}if(lastWindowError)throw new LoaderError(FAIL_LOAD,[id]);return!0}))}async function evaluateLoadHook(e,t){return hasSetTimeout?new Promise(((r,o)=>{const n=setTimeout((()=>{o(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER);t.then((e=>{r(e)})).catch((()=>{o(new LoaderError(FAIL_HOOK_LOAD,[e]))})).finally((()=>{clearTimeout(n)}))})):t}hasDocument&&globalThis.addEventListener("error",(e=>{lastWindowError=e.error})),"production"!==process.env.NODE_ENV&&!hasSetTimeout&&hasConsole&&console.warn("setTimeout API is not available, watchdog timer on load hook will not be set");class ModuleRegistry{constructor(e){this.namedDefineRegistry=new Map,this.moduleRegistry=new Map,this.aliases=new Map,this.profiler=e.profiler,this.resolver=new ImportMetadataResolver(e,this.importMetadataInvalidationCallback.bind(this))}async load(e,t){const r=await this.resolve(e,t),o=this.getModuleRecord(r,e);return o.evaluated?o.module:(o.evaluationPromise||(o.evaluationPromise=this.topLevelEvaluation(o)),o.evaluationPromise)}async resolve(e,t){const r=this.resolver.getBaseUrl();let o,n=e;const i=this.resolveHook;if(i){for(let e=0;e<i.length;e++){const t=(0,i[e])(n,{parentUrl:r});let s;if((t||null===t)&&(s=isResponseAPromise(t)?await t:t),null!==s){if("string"==typeof s){if(resolveIfNotPlainOrUrl(s,r))throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);n=s;continue}if(o=s&&s.url&&(resolveIfNotPlainOrUrl(s.url,r)||s.url),!o)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);break}}if(n!==e){if(!o&&this.namedDefineRegistry.has(n))return n;e=n}}if(!o){const t=resolveIfNotPlainOrUrl(e,r)||e;if(this.moduleRegistry.has(t))return t;const n=this.resolver.resolveLocal(t);if(n){if(this.namedDefineRegistry.has(t)&&this.namedDefineRegistry.get(t).defined){if(!this.moduleRegistry.get(n)||!this.aliases.has(t))return t}return n}if(this.namedDefineRegistry.has(t))return t;try{o=await this.resolver.resolve(t)}catch(e){}}if(!o||!isUrl(o)){if(this.namedDefineRegistry.has(e))return e;throw new LoaderError(UNRESOLVED,[e])}return t&&isUrl(o)&&(o+=`?importer=${encodeURIComponent(t)}`),o}has(e){return this.moduleRegistry.has(e)}define(e,t,r){const o=this.namedDefineRegistry.get(e);if(o&&o.defined)return"production"!==process.env.NODE_ENV&&hasConsole&&console.warn(`Module redefine attempted: ${e}`),void(this.lastDefine=o);const n={name:e,dependencies:t,exporter:r,defined:!0};o&&o.external&&o.external.resolveExternal(n),this.profiler.logOperationStart({id:MODULE_DEFINE,specifier:e}),this.namedDefineRegistry.set(e,n),this.lastDefine=n}registerExternalModules(e){e.map((e=>{if(this.namedDefineRegistry.has(e))"production"!==process.env.NODE_ENV&&hasConsole&&console.warn(MODULE_ALREADY_LOADED.message,e);else{let t,r;const o=new Promise(((o,n)=>{t=o,r=setTimeout((()=>{n(new LoaderError(MODULE_LOAD_TIMEOUT,[e]))}),MODULE_LOAD_TIMEOUT_TIMER)})).finally((()=>{clearTimeout(r)})),n={name:e,defined:!1,external:{resolveExternal:t,moduleDefPromise:o}};this.namedDefineRegistry.set(e,n)}}))}getImportMetadataResolver(){return this.resolver}getExistingModuleRecord(e,t){const r=this.moduleRegistry.get(e);if(r)return this.storeModuleAlias(t,e),r;if(e!==t){const e=this.aliases.get(t);if(e){const t=this.moduleRegistry.get(e);if(t)return t}}return r}getModuleRecord(e,t){const r=this.getExistingModuleRecord(e,t);if(r)return r;const o=this.getModuleDef(e,t),n=o.then((e=>{const t=e.dependencies.map((e=>{if("exports"!==e)return invariant("require"!==e,NO_AMD_REQUIRE),this.getModuleDependencyRecord.call(this,e)})).filter((e=>void 0!==e));return Promise.all(t)})),i={id:e,module:Object.create(null),dependencyRecords:n,instantiation:o,evaluated:!1,evaluationPromise:null};return this.moduleRegistry.set(e,i),this.storeModuleAlias(t,e),i}storeModuleAlias(e,t){if(e!==t)if(this.aliases.has(e)){if("production"!==process.env.NODE_ENV&&hasConsole){const r=this.aliases.get(e);r!==t&&console.warn(`Alias update attempt: ${e}=>${r}, ${t}`)}}else this.aliases.set(e,t)}async getModuleDependencyRecord(e){const t=await this.resolve(e);return this.getModuleRecord(t,e)}async topLevelEvaluation(e){return await this.instantiateAll(e,{}),this.evaluateModule(e,{})}async instantiateAll(e,t){if(!t[e.id]){t[e.id]=!0;const r=await e.dependencyRecords;if(r)for(let e=0;e<r.length;e++){const o=r[e];await this.instantiateAll(o,t)}}}async evaluateModule(e,t){const r=await e.dependencyRecords;r.length>0&&(t[e.id]=!0,await this.evaluateModuleDependencies(r,t));const{exporter:o,dependencies:n}=await e.instantiation,i={},s=await Promise.all(n.map((async e=>{if("exports"===e)return i;const t=await this.resolve(e),r=this.moduleRegistry.get(t);if(!r)throw new LoaderError(FAILED_DEP,[t]);const o=r.module;if(!r.evaluated)return this.getCircularDependencyWrapper(o);if(o)return o.__defaultInterop?o.default:o;throw new LoaderError(FAILED_DEP,[t])})));if(e.evaluated)return e.module;let a=o(...s);void 0!==a?(a={default:a},Object.defineProperty(a,"__defaultInterop",{value:!0})):this.isNamedExportDefaultOnly(i)&&Object.defineProperty(i,"__useDefault",{value:!0});const l=a||i;for(const t in l)Object.defineProperty(e.module,t,{enumerable:!0,set(e){l[t]=e},get:()=>l[t]});return l.__useDefault&&Object.defineProperty(e.module,"__useDefault",{value:!0}),l.__defaultInterop&&Object.defineProperty(e.module,"__defaultInterop",{value:!0}),l.__esModule&&Object.defineProperty(e.module,"__esModule",{value:!0}),e.evaluated=!0,Object.freeze(e.module),e.module}isNamedExportDefaultOnly(e){return void 0!==e&&2===Object.getOwnPropertyNames(e).length&&Object.prototype.hasOwnProperty.call(e,"default")&&Object.prototype.hasOwnProperty.call(e,"__esModule")}getCircularDependencyWrapper(e){const t=()=>e.__useDefault||e.__defaultInterop?e.default:e;return t.__circular__=!0,t}async evaluateModuleDependencies(e,t){for(let r=0;r<e.length;r++){const o=e[r];o.evaluated||t[o.id]||(t[o.id]=!0,await this.evaluateModule(o,t))}}async getModuleDef(e,t){this.lastDefine=void 0;const r=isUrl(e)?t!==e?t:void 0:e;let o=r&&this.namedDefineRegistry.get(r);if(o&&o.external)return o.external.moduleDefPromise;if(o&&o.defined)return o;const n=this.resolver.getBaseUrl(),i=r||t;return this.profiler.logOperationStart({id:MODULE_FETCH,specifier:i}),Promise.resolve().then((async()=>{const t=this.loadHook;if(t)for(let r=0;r<t.length;r++){const o=(0,t[r])(e,n),i=isResponseAPromise(o)?await evaluateLoadHook(e,o):o;if(void 0===i)throw new LoaderError(INVALID_LOADER_SERVICE_RESPONSE);if(i&&null!==i)return evaluateLoadHookResponse(i,e)}return!1})).then((t=>{if(!0!==t&&hasDocument)return loadModuleDef(e)})).then((()=>{if(o=r&&this.namedDefineRegistry.get(r),o||(o=this.lastDefine),!o)throw new LoaderError(FAIL_INSTANTIATE,[e]);return this.profiler.logOperationEnd({id:MODULE_FETCH,specifier:i}),o})).catch((e=>{throw this.profiler.logOperationStart({id:MODULE_ERROR,specifier:i}),e}))}addLoaderPlugin(e){if("object"!=typeof e)throw new LoaderError(INVALID_HOOK);const{loadModule:t,resolveModule:r,loadMapping:o}=e;r&&(this.resolveHook?this.resolveHook.push(r):this.resolveHook=[r]),t&&(this.loadHook?this.loadHook.push(t):this.loadHook=[t]),o&&this.resolver.addLoadMappingHook(o)}importMetadataInvalidationCallback({name:e,oldUrl:t,newUrl:r}){const o=this.handleStaleModuleHook;o?evaluateHandleStaleModuleHooks(o,{name:e,oldUrl:t,newUrl:r}):"production"!==process.env.NODE_ENV&&hasConsole&&console.warn(`stale module detected ${e}, current URL:${t}, new URL:${r}`)}registerHandleStaleModuleHook(e){this.handleStaleModuleHook?this.handleStaleModuleHook.push(e):this.handleStaleModuleHook=[e]}}class Loader{constructor(e){let t=e.baseUrl;const r=e.endpoints?e.endpoints.uris.mapping:void 0;let o=e.profiler;if(!r)throw new LoaderError(NO_MAPPING_URL);if(e.endpoints.uris.mapping=r.replace(/\/?$/,"/"),t&&(t=t.replace(/\/?$/,"/")),t||(t=getBaseUrl()),!t)throw new LoaderError(NO_BASE_URL);if(o||(o={logOperationStart:()=>{},logOperationEnd:()=>{}}),this.registry=new ModuleRegistry(Object.freeze({endpoints:e.endpoints,baseUrl:t,profiler:o})),e.appMetadata&&!e.appMetadata.appId){const t=e.appMetadata.bootstrapModule.match(/@lwr-bootstrap\/(.+)\/v\/.+/),r=t&&t[1];e.appMetadata.appId=r}this.services=Object.freeze({addLoaderPlugin:this.registry.addLoaderPlugin.bind(this.registry),handleStaleModule:this.registry.registerHandleStaleModuleHook.bind(this.registry),appMetadata:e.appMetadata})}define(e,t,r){invariant("string"==typeof e,MISSING_NAME);let o=r,n=t;"function"==typeof n&&(o=t,n=[]),invariant(Array.isArray(n),INVALID_DEPS),this.registry.define(e,n,o)}async load(e,t){return this.registry.load(e,t)}has(e){return this.registry.has(e)}async resolve(e,t){return this.registry.resolve(e,t)}async registerImportMappings(e,t){this.registry.getImportMetadataResolver().registerImportMappings(e,t)}registerExternalModules(e){this.registry.registerExternalModules(e)}}const configOptions={format:"amd",apiVersion:"v57.0",apiPrefix:"/lwr",bundle:!0,debug:!1},configuration=getConfiguration(configOptions),{bootstrapModule:bootstrapModule,endpoints:endpoints,baseUrl:baseUrl,imports:imports,index:index}=configuration,loader=new Loader({endpoints:endpoints,baseUrl:baseUrl});loader.define("lwr/loader/v/0_0_1",["exports"],(e=>{Object.assign(e,{define:loader.define.bind(loader),load:loader.load.bind(loader)})})),await loader.registerImportMappings({imports:imports,index:index},[bootstrapModule]),globalThis.LWR=Object.freeze({define:loader.define.bind(loader)}),LWR.define("lwr/everywhereAmd/v/0_0_1",["exports","lwr/vault/v/0_0_1"],(function(e,t){async function r(e,r="javascript"){const o=t.getAuthInfo();return o?fetch(e,{headers:{Accept:`application/${r}`,Authorization:`Bearer ${o.access_token}`}}):null}e.authenticate=function(e){e&&t.setAuthInfo(e)},e.initAmd=function(e,t,o){t.match(/\/v5\d\.0\//)&&function(e,t,o){e.addLoaderPlugin({loadModule:async e=>r(e),loadMapping:async e=>{const o=await r(`${t}${encodeURIComponent(e)}`,"json");return o&&o.ok?o.json():null},resolveModule:e=>e&&!/\/v\/[^/]+?$/.test(e)?`${e}/v/${o}`:null})}(e,t,o)},Object.defineProperty(e,"__esModule",{value:!0})})),LWR.define("lwr/vault/v/0_0_1",["exports"],(function(e){let t;e.getAuthInfo=function(){return t},e.setAuthInfo=function(e){t=e},Object.defineProperty(e,"__esModule",{value:!0})}));const{initAmd:initAmd,authenticate:authenticate}=await loader.load(bootstrapModule);async function createComponent(e,t,r={},o){const{createComponent:n}=await loader.load(bootstrapModule.replace("Amd",""));return n(e,t,r,o)}initAmd(loader.services,endpoints?.uris.mapping,"0_0_1");export{authenticate,createComponent};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
+
globalThis.process = { env: { NODE_ENV: 'production' } };
|
|
7
8
|
// Construct the Client Bootstrap Config object
|
|
8
9
|
function getConfiguration(options) {
|
|
9
10
|
const { format, server, apiVersion, apiPrefix, locale, bundle, debug } = options;
|
|
@@ -38,10 +39,7 @@ function getConfiguration(options) {
|
|
|
38
39
|
if (debug && config.endpoints) {
|
|
39
40
|
config.endpoints.modifiers = { debug: 'true' };
|
|
40
41
|
}
|
|
41
|
-
return
|
|
42
|
-
options: { NODE_ENV: debug ? 'development' : 'production' },
|
|
43
|
-
config, // globalThis.LWR
|
|
44
|
-
};
|
|
42
|
+
return config;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
/**
|
|
@@ -50,7 +48,7 @@ function getConfiguration(options) {
|
|
|
50
48
|
* SPDX-License-Identifier: MIT
|
|
51
49
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
52
50
|
*/
|
|
53
|
-
/* LWR Module Loader v0.9.0-alpha.
|
|
51
|
+
/* LWR Module Loader v0.9.0-alpha.30 */
|
|
54
52
|
const templateRegex = /\{([0-9]+)\}/g;
|
|
55
53
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
54
|
function templateString(template, args) {
|
|
@@ -148,7 +146,7 @@ const STALE_HOOK_ERROR = Object.freeze({
|
|
|
148
146
|
const MODULE_ALREADY_LOADED = Object.freeze({
|
|
149
147
|
code: 3017,
|
|
150
148
|
level: 0,
|
|
151
|
-
message: 'Marking module(s) as externally loaded, but they are already loaded:
|
|
149
|
+
message: 'Marking module(s) as externally loaded, but they are already loaded:',
|
|
152
150
|
});
|
|
153
151
|
const FAIL_HOOK_LOAD = Object.freeze({
|
|
154
152
|
code: 3018,
|
|
@@ -347,11 +345,13 @@ if (hasDocument) {
|
|
|
347
345
|
|
|
348
346
|
// Bootstrap / shim
|
|
349
347
|
|
|
348
|
+
// Loader: modules
|
|
350
349
|
const LOADER_PREFIX = 'lwr.loader.';
|
|
351
350
|
const MODULE_DEFINE = `${LOADER_PREFIX}module.define`;
|
|
352
351
|
const MODULE_FETCH = `${LOADER_PREFIX}module.fetch`;
|
|
353
352
|
const MODULE_ERROR = `${LOADER_PREFIX}module.error`;
|
|
354
353
|
|
|
354
|
+
// Loader: mappings
|
|
355
355
|
const MAPPINGS_FETCH = `${LOADER_PREFIX}mappings.fetch`;
|
|
356
356
|
const MAPPINGS_ERROR = `${LOADER_PREFIX}mappings.error`;
|
|
357
357
|
|
|
@@ -812,12 +812,8 @@ class ModuleRegistry {
|
|
|
812
812
|
* @param modules - list of module identifiers
|
|
813
813
|
*/
|
|
814
814
|
registerExternalModules(modules) {
|
|
815
|
-
const alreadyRegistered = [];
|
|
816
815
|
modules.map((id) => {
|
|
817
|
-
if (this.namedDefineRegistry.has(id)) {
|
|
818
|
-
alreadyRegistered.push(id);
|
|
819
|
-
}
|
|
820
|
-
else {
|
|
816
|
+
if (!this.namedDefineRegistry.has(id)) {
|
|
821
817
|
let resolveExternal;
|
|
822
818
|
let timer;
|
|
823
819
|
const moduleDefPromise = new Promise((resolve, reject) => {
|
|
@@ -841,11 +837,11 @@ class ModuleRegistry {
|
|
|
841
837
|
};
|
|
842
838
|
this.namedDefineRegistry.set(id, moduleDef);
|
|
843
839
|
}
|
|
840
|
+
else if (process.env.NODE_ENV !== 'production' && hasConsole) {
|
|
841
|
+
// eslint-disable-next-line lwr/no-unguarded-apis
|
|
842
|
+
console.warn(MODULE_ALREADY_LOADED.message, id);
|
|
843
|
+
}
|
|
844
844
|
});
|
|
845
|
-
// throw error for modules that were already registered
|
|
846
|
-
if (alreadyRegistered.length) {
|
|
847
|
-
throw new LoaderError(MODULE_ALREADY_LOADED, [alreadyRegistered.join(', ')]);
|
|
848
|
-
}
|
|
849
845
|
}
|
|
850
846
|
getImportMetadataResolver() {
|
|
851
847
|
return this.resolver;
|
|
@@ -987,7 +983,7 @@ class ModuleRegistry {
|
|
|
987
983
|
moduleDefault = { default: moduleDefault };
|
|
988
984
|
// __defaultInterop is ONLY used to support backwards compatibility
|
|
989
985
|
// of importing default exports the "wrong" way (when not using named exports).
|
|
990
|
-
// See https://github.com/salesforce/lwr/pull/816
|
|
986
|
+
// See https://github.com/salesforce-experience-platform-emu/lwr/pull/816
|
|
991
987
|
Object.defineProperty(moduleDefault, '__defaultInterop', { value: true });
|
|
992
988
|
}
|
|
993
989
|
// if no return value, then we are using the exports object
|
|
@@ -1209,7 +1205,7 @@ class Loader {
|
|
|
1209
1205
|
const appId = match && match[1];
|
|
1210
1206
|
config.appMetadata.appId = appId;
|
|
1211
1207
|
}
|
|
1212
|
-
// TODO: https://github.com/salesforce/lwr/issues/1087
|
|
1208
|
+
// TODO: https://github.com/salesforce-experience-platform-emu/lwr/issues/1087
|
|
1213
1209
|
this.services = Object.freeze({
|
|
1214
1210
|
addLoaderPlugin: this.registry.addLoaderPlugin.bind(this.registry),
|
|
1215
1211
|
handleStaleModule: this.registry.registerHandleStaleModuleHook.bind(this.registry),
|
|
@@ -1284,8 +1280,7 @@ class Loader {
|
|
|
1284
1280
|
// Process the LWR Client Bootstrap Config
|
|
1285
1281
|
const configOptions = { "format": "amd", "apiVersion": "v57.0", "apiPrefix": "/lwr", "bundle": true, "debug": false };
|
|
1286
1282
|
const configuration = getConfiguration(configOptions);
|
|
1287
|
-
const { bootstrapModule, endpoints, baseUrl, imports, index } = configuration
|
|
1288
|
-
globalThis.process = { env: { NODE_ENV: configuration.options.NODE_ENV } }; // Required by LWC
|
|
1283
|
+
const { bootstrapModule, endpoints, baseUrl, imports, index } = configuration;
|
|
1289
1284
|
// Initialize the AMD loader (its code is bundled into the LWR Everywhere module)
|
|
1290
1285
|
const loader = new Loader({ endpoints, baseUrl });
|
|
1291
1286
|
loader.define('lwr/loader/v/0_0_1', ['exports'], (exports) => {
|
|
@@ -1297,9 +1292,11 @@ loader.define('lwr/loader/v/0_0_1', ['exports'], (exports) => {
|
|
|
1297
1292
|
await loader.registerImportMappings({ imports, index }, [bootstrapModule]);
|
|
1298
1293
|
globalThis.LWR = Object.freeze({ define: loader.define.bind(loader) });
|
|
1299
1294
|
// Define preload modules (ie: ABS, vault, etc) BEFORE loading them
|
|
1300
|
-
LWR.define(
|
|
1301
|
-
|
|
1302
|
-
|
|
1295
|
+
LWR.define('lwr/everywhereAmd/v/0_0_1', ['exports', 'lwr/vault/v/0_0_1'], function (exports, _0_9_0Alpha_30) {
|
|
1296
|
+
// IMPORTANT: Do not add any static imports to this file that are not bundled with the amd-client
|
|
1297
|
+
// Do an OAuthed fetch
|
|
1298
|
+
async function authFetch(url, accept = 'javascript') {
|
|
1299
|
+
const authInfo = _0_9_0Alpha_30.getAuthInfo();
|
|
1303
1300
|
if (authInfo) {
|
|
1304
1301
|
return fetch(url, {
|
|
1305
1302
|
headers: {
|
|
@@ -1308,44 +1305,56 @@ LWR.define("lwr/everywhereAmd/v/0_0_1", ["exports", "lwr/vault/v/0_0_1"], functi
|
|
|
1308
1305
|
}
|
|
1309
1306
|
});
|
|
1310
1307
|
}
|
|
1311
|
-
return null;
|
|
1308
|
+
return null; // defer to loader
|
|
1312
1309
|
}
|
|
1310
|
+
// Add a hook for adding OAuth headers to module and mapping requests
|
|
1311
|
+
// Workaround: core does not have proper versioning; replace all versions with 0_0_1
|
|
1313
1312
|
function everywhereHooks(serviceAPI, mappingEndpoint, coreVersion) {
|
|
1314
1313
|
serviceAPI.addLoaderPlugin({
|
|
1315
1314
|
loadModule: async (url) => {
|
|
1316
1315
|
return authFetch(url);
|
|
1317
1316
|
},
|
|
1318
1317
|
loadMapping: async (specifier) => {
|
|
1319
|
-
const res = await authFetch(`${mappingEndpoint}${encodeURIComponent(specifier)}`,
|
|
1318
|
+
const res = await authFetch(`${mappingEndpoint}${encodeURIComponent(specifier)}`, 'json');
|
|
1320
1319
|
if (res && res.ok) {
|
|
1321
1320
|
return res.json();
|
|
1322
1321
|
}
|
|
1323
1322
|
return null;
|
|
1324
1323
|
},
|
|
1325
|
-
resolveModule:
|
|
1324
|
+
resolveModule: specifier => {
|
|
1325
|
+
// Workaround W-8010259 (dynamic imports without versions)
|
|
1326
|
+
// by adding a default version to version-less specifiers
|
|
1326
1327
|
if (specifier && !/\/v\/[^/]+?$/.test(specifier)) {
|
|
1327
1328
|
return `${specifier}/v/${coreVersion}`;
|
|
1328
1329
|
}
|
|
1329
|
-
return null;
|
|
1330
|
+
return null; // defer to loader
|
|
1330
1331
|
}
|
|
1331
1332
|
});
|
|
1332
1333
|
}
|
|
1333
1334
|
function initAmd(services, mappingEndpoint, coreVersion) {
|
|
1335
|
+
// Initialize the loader hooks for LWR-S endpoints
|
|
1334
1336
|
if (mappingEndpoint.match(/\/v5\d\.0\//)) {
|
|
1335
1337
|
everywhereHooks(services, mappingEndpoint, coreVersion);
|
|
1336
1338
|
}
|
|
1337
1339
|
}
|
|
1340
|
+
// Export the LWRE authenticate() API
|
|
1341
|
+
// This is a duplicate of the function exported from "lwr/everywhere"
|
|
1342
|
+
// because it MUST be bundled into the LWRE module via "lwr/everywhereAmd"
|
|
1338
1343
|
function authenticate(authInfo) {
|
|
1344
|
+
// Put OAuth info into the vault
|
|
1339
1345
|
if (authInfo) {
|
|
1340
|
-
|
|
1346
|
+
_0_9_0Alpha_30.setAuthInfo(authInfo);
|
|
1341
1347
|
}
|
|
1342
1348
|
}
|
|
1343
1349
|
exports.authenticate = authenticate;
|
|
1344
1350
|
exports.initAmd = initAmd;
|
|
1345
|
-
Object.defineProperty(exports,
|
|
1351
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1346
1352
|
});
|
|
1347
|
-
LWR.define(
|
|
1353
|
+
LWR.define('lwr/vault/v/0_0_1', ['exports'], function (exports) {
|
|
1354
|
+
// Credential vault for storing setters and subscribers for OAuth info
|
|
1355
|
+
// This module is a SINGLETON and must be excluded from ESM bundling
|
|
1348
1356
|
let authInfo;
|
|
1357
|
+
// Get and set the OAuth info
|
|
1349
1358
|
function getAuthInfo() {
|
|
1350
1359
|
return authInfo;
|
|
1351
1360
|
}
|
|
@@ -1354,7 +1363,7 @@ LWR.define("lwr/vault/v/0_0_1", ["exports"], function (exports) {
|
|
|
1354
1363
|
}
|
|
1355
1364
|
exports.getAuthInfo = getAuthInfo;
|
|
1356
1365
|
exports.setAuthInfo = setAuthInfo;
|
|
1357
|
-
Object.defineProperty(exports,
|
|
1366
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1358
1367
|
});
|
|
1359
1368
|
// Set up the AMD loader hooks for OAuth
|
|
1360
1369
|
const { initAmd, authenticate } = await loader.load(bootstrapModule);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
+
globalThis.process = { env: { NODE_ENV: 'development' } };
|
|
7
8
|
// Construct the Client Bootstrap Config object
|
|
8
9
|
function getConfiguration(options) {
|
|
9
10
|
const { format, server, apiVersion, apiPrefix, locale, bundle, debug } = options;
|
|
@@ -17,7 +18,7 @@ function getConfiguration(options) {
|
|
|
17
18
|
? `${ORIGIN}${PREFIX}/bundle/${format}/${POSTFIX}${BUNDLE_ID}-0/module/mi/`
|
|
18
19
|
: `${ORIGIN}${PREFIX}/module/${format}/${POSTFIX}/mi/`;
|
|
19
20
|
// Component specifiers and URIs
|
|
20
|
-
const BOOT_MODULE = `lwr/everywhere${format === 'esm' ? 'Esm' : 'Amd'}/v/0_9_0-
|
|
21
|
+
const BOOT_MODULE = `lwr/everywhere${format === 'esm' ? 'Esm' : 'Amd'}/v/0_9_0-alpha_30`;
|
|
21
22
|
const BOOT_URI = `${ENDPOINT}${encodeURIComponent(BOOT_MODULE)}/latest${debug ? '?debug' : ''}`;
|
|
22
23
|
// Client Bootstrap Config
|
|
23
24
|
const config = {
|
|
@@ -38,18 +39,14 @@ function getConfiguration(options) {
|
|
|
38
39
|
if (debug && config.endpoints) {
|
|
39
40
|
config.endpoints.modifiers = { debug: 'true' };
|
|
40
41
|
}
|
|
41
|
-
return
|
|
42
|
-
options: { NODE_ENV: debug ? 'development' : 'production' },
|
|
43
|
-
config, // globalThis.LWR
|
|
44
|
-
};
|
|
42
|
+
return config;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
/** LWR Everywhere module for ESM **/
|
|
48
46
|
// Process the LWR Client Bootstrap Config
|
|
49
47
|
const configOptions = { "format": "esm", "apiVersion": "1", "apiPrefix": "", "bundle": false, "debug": true };
|
|
50
48
|
const configuration = getConfiguration(configOptions);
|
|
51
|
-
const { bootstrapModule, imports, index = {}, importMappings, endpoints } = configuration
|
|
52
|
-
globalThis.process = { env: { NODE_ENV: configuration.options.NODE_ENV } }; // Required by LWC
|
|
49
|
+
const { bootstrapModule, imports, index = {}, importMappings, endpoints } = configuration;
|
|
53
50
|
// Set up the ESM loader; Export the LWRE APIs
|
|
54
51
|
const { initEsm, authenticate, createComponent } = await import(
|
|
55
52
|
/* webpackIgnore: true */ index[bootstrapModule]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=function(e){const{format:o,server:i,apiVersion:n,apiPrefix:t,locale:p,bundle:r,debug:s}=e,
|
|
1
|
+
globalThis.process={env:{NODE_ENV:"production"}};const e=function(e){const{format:o,server:i,apiVersion:n,apiPrefix:t,locale:p,bundle:r,debug:s}=e,a=new URL(import.meta.url),m=i||a.origin||"",d=`${t}/${n}`,$="0"+(p?`/l/${p}`:""),u="/bi/3_A,B,O,S,EG,JLMT,C,D,F,H,I,K,N,P,Q,R",l=r?`${m}${d}/bundle/${o}/${$}${u}-0/module/mi/`:`${m}${d}/module/${o}/${$}/mi/`,b=`lwr/everywhere${"esm"===o?"Esm":"Amd"}/v/0_9_0-alpha_30`,g=`${l}${encodeURIComponent(b)}/latest${s?"?debug":""}`,c={appId:"lwre",autoBoot:!0,bootstrapModule:b,baseUrl:m,imports:{[g]:[b]},index:{[b]:g},endpoints:{uris:{module:l,mapping:`${m}${d}/mapping/${o}/${$}${r?u:""}/mp/`}}};return s&&c.endpoints&&(c.endpoints.modifiers={debug:"true"}),c}({format:"esm",apiVersion:"1",apiPrefix:"",bundle:!0,debug:!1}),{bootstrapModule:o,imports:i,index:n={},importMappings:t,endpoints:p}=e,{initEsm:r,authenticate:s,createComponent:a}=await import(n[o]);r({imports:i,index:n,importMappings:t,endpoints:p});export{s as authenticate,a as createComponent};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
6
6
|
*/
|
|
7
|
+
globalThis.process = { env: { NODE_ENV: 'production' } };
|
|
7
8
|
// Construct the Client Bootstrap Config object
|
|
8
9
|
function getConfiguration(options) {
|
|
9
10
|
const { format, server, apiVersion, apiPrefix, locale, bundle, debug } = options;
|
|
@@ -17,7 +18,7 @@ function getConfiguration(options) {
|
|
|
17
18
|
? `${ORIGIN}${PREFIX}/bundle/${format}/${POSTFIX}${BUNDLE_ID}-0/module/mi/`
|
|
18
19
|
: `${ORIGIN}${PREFIX}/module/${format}/${POSTFIX}/mi/`;
|
|
19
20
|
// Component specifiers and URIs
|
|
20
|
-
const BOOT_MODULE = `lwr/everywhere${format === 'esm' ? 'Esm' : 'Amd'}/v/0_9_0-
|
|
21
|
+
const BOOT_MODULE = `lwr/everywhere${format === 'esm' ? 'Esm' : 'Amd'}/v/0_9_0-alpha_30`;
|
|
21
22
|
const BOOT_URI = `${ENDPOINT}${encodeURIComponent(BOOT_MODULE)}/latest${debug ? '?debug' : ''}`;
|
|
22
23
|
// Client Bootstrap Config
|
|
23
24
|
const config = {
|
|
@@ -38,18 +39,14 @@ function getConfiguration(options) {
|
|
|
38
39
|
if (debug && config.endpoints) {
|
|
39
40
|
config.endpoints.modifiers = { debug: 'true' };
|
|
40
41
|
}
|
|
41
|
-
return
|
|
42
|
-
options: { NODE_ENV: debug ? 'development' : 'production' },
|
|
43
|
-
config, // globalThis.LWR
|
|
44
|
-
};
|
|
42
|
+
return config;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
/** LWR Everywhere module for ESM **/
|
|
48
46
|
// Process the LWR Client Bootstrap Config
|
|
49
47
|
const configOptions = { "format": "esm", "apiVersion": "1", "apiPrefix": "", "bundle": true, "debug": false };
|
|
50
48
|
const configuration = getConfiguration(configOptions);
|
|
51
|
-
const { bootstrapModule, imports, index = {}, importMappings, endpoints } = configuration
|
|
52
|
-
globalThis.process = { env: { NODE_ENV: configuration.options.NODE_ENV } }; // Required by LWC
|
|
49
|
+
const { bootstrapModule, imports, index = {}, importMappings, endpoints } = configuration;
|
|
53
50
|
// Set up the ESM loader; Export the LWRE APIs
|
|
54
51
|
const { initEsm, authenticate, createComponent } = await import(
|
|
55
52
|
/* webpackIgnore: true */ index[bootstrapModule]);
|
package/build/esm-client.js
CHANGED
|
@@ -3,8 +3,7 @@ import { getConfiguration } from './utils';
|
|
|
3
3
|
// Process the LWR Client Bootstrap Config
|
|
4
4
|
const configOptions = '$REPLACE_CLIENT_BOOTSTRAP_OPTIONS$';
|
|
5
5
|
const configuration = getConfiguration(configOptions);
|
|
6
|
-
const { bootstrapModule, imports, index = {}, importMappings, endpoints } = configuration
|
|
7
|
-
globalThis.process = { env: { NODE_ENV: configuration.options.NODE_ENV } }; // Required by LWC
|
|
6
|
+
const { bootstrapModule, imports, index = {}, importMappings, endpoints } = configuration;
|
|
8
7
|
// Set up the ESM loader; Export the LWRE APIs
|
|
9
8
|
const { initEsm, authenticate, createComponent } = await import(
|
|
10
9
|
/* webpackIgnore: true */ index[bootstrapModule]);
|
package/build/generate.js
CHANGED
|
@@ -11,7 +11,7 @@ import typescriptPlugin from 'rollup-plugin-typescript';
|
|
|
11
11
|
import { rootPath, version } from '@lwrjs/everywhere/package';
|
|
12
12
|
const CORE_VERSION = '0_0_1';
|
|
13
13
|
const NPM_VERSION = version.replace(/\./g, '_');
|
|
14
|
-
const NPM2CORE_REGEX = new RegExp(
|
|
14
|
+
const NPM2CORE_REGEX = new RegExp(`/v/${NPM_VERSION}`, 'g');
|
|
15
15
|
/* istanbul ignore next */
|
|
16
16
|
const lwcResolver = {
|
|
17
17
|
resolveId(importee, importer) {
|
|
@@ -45,7 +45,7 @@ export async function generate(options) {
|
|
|
45
45
|
amdModules = getAmdModule('everywhereAmd') + getAmdModule('vault');
|
|
46
46
|
if (isCore) {
|
|
47
47
|
// Workaround: core does not have proper versioning; replace all versions with 0.0.1
|
|
48
|
-
amdModules = amdModules.replace(NPM2CORE_REGEX,
|
|
48
|
+
amdModules = amdModules.replace(NPM2CORE_REGEX, `/v/${CORE_VERSION}`);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
// These config options get added to the LWR Everywhere module via string replacement
|
|
@@ -97,7 +97,8 @@ export async function generate(options) {
|
|
|
97
97
|
* All rights reserved.
|
|
98
98
|
* SPDX-License-Identifier: MIT
|
|
99
99
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
100
|
-
|
|
100
|
+
*/
|
|
101
|
+
globalThis.process = { env: { NODE_ENV: '${debug ? 'development' : 'production'}' } };`,
|
|
101
102
|
});
|
|
102
103
|
// Write the rollup output to the file system
|
|
103
104
|
if (!output[0].code) {
|
package/build/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { rootPath, version as VERSION } from '@lwrjs/everywhere/package';
|
|
4
4
|
export default class LwrEverywhereClientProvider {
|
|
5
|
-
constructor({ dir = 'assets' }, context) {
|
|
5
|
+
constructor({ dir = 'build/assets' }, context) {
|
|
6
6
|
this.name = 'lwr-everywhere-client-runtime';
|
|
7
7
|
this.filenames = ['lwr-everywhere.js', 'lwr-everywhere-min.js', 'lwr-everywhere-debug.js'];
|
|
8
8
|
this.version = VERSION;
|
|
@@ -17,7 +17,7 @@ export default class LwrEverywhereClientProvider {
|
|
|
17
17
|
return undefined;
|
|
18
18
|
}
|
|
19
19
|
// Retrieve the filepath from the build directory
|
|
20
|
-
const absFilepath = path.join(rootPath,
|
|
20
|
+
const absFilepath = path.join(rootPath, this.directory, format, specifier);
|
|
21
21
|
if (fs.existsSync(absFilepath)) {
|
|
22
22
|
return {
|
|
23
23
|
specifier,
|