@lwrjs/everywhere 0.9.0-alpha.2 → 0.9.0-alpha.21
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/1b0754f98a1d222fca718deb5838c625/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_21/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_33_0/s/90a5f16131da45cef1653112862ca9dc/lwc.js +8969 -0
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/everywhereAmd/v/0_9_0-alpha_21/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_21/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_2/s/a7fb654bda624ba7d02dcd76e8d1217c → 0_9_0-alpha_21/s/64c5a2bb3dcf1759c879fc87bf2fdaf6}/lwr_loader.js +360 -131
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/metrics/v/0_9_0-alpha_21/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_21/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_21/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_2 → 0_9_0-alpha_21/lwr-error-shim.js} +1 -1
- package/build/__generated_site_amd_modules__/1/resource/amd/lwr-loader-shim.js/v/{0_9_0-alpha_2 → 0_9_0-alpha_21/lwr-loader-shim.js} +18 -17
- package/build/amd-client.js +1 -2
- package/build/assets/amd/lwr-everywhere-debug.js +36 -23
- package/build/assets/amd/lwr-everywhere-min.js +1 -1
- package/build/assets/amd/lwr-everywhere.js +36 -23
- package/build/assets/core/lwr-everywhere-debug.js +33 -20
- package/build/assets/core/lwr-everywhere-min.js +1 -1
- package/build/assets/core/lwr-everywhere.js +33 -20
- 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 +15 -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/68e51659d71a9691c09702509beecf4f/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_2/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_2/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_2/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_2/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_2/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_2/s/6cbce1f9b7e815ee862b26f37ff4c76e/lwr_vault.js +0 -13
- 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: '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_21`;
|
|
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,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Luvio } from '@luvio/engine';
|
|
2
|
+
export declare type Callback = (luvio: Luvio) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Constructs/sets the default Luvio instance. Any previously-set default luvio instance
|
|
5
|
+
* is overwritten.
|
|
6
|
+
*/
|
|
7
|
+
export declare function setDefaultLuvio({ luvio }: {
|
|
8
|
+
luvio: Luvio;
|
|
9
|
+
}): void;
|
|
10
|
+
/**
|
|
11
|
+
* Registers a callback to be invoked with the default Luvio instance. Note that the
|
|
12
|
+
* callback may be invoked multiple times if the default Luvio changes.
|
|
13
|
+
*
|
|
14
|
+
* @param callback callback to be invoked with default Luvio instance
|
|
15
|
+
*/
|
|
16
|
+
export declare function withDefaultLuvio(callback: Callback): void;
|
|
17
|
+
export declare type Registration = {
|
|
18
|
+
id: string;
|
|
19
|
+
};
|
|
20
|
+
export declare type RegistrationCallback<R = Registration> = (registration: R) => void;
|
|
21
|
+
export declare function forEachRegistration(callback: RegistrationCallback): void;
|
|
22
|
+
export declare function withRegistration<R extends Registration>(id: R['id'], callback: RegistrationCallback<R>): void;
|
|
23
|
+
export declare function register<R extends Registration = Registration>(r: R): void;
|
|
24
|
+
//# sourceMappingURL=lds-default-luvio.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// temp from https://github.com/salesforce-experience-platform-emu/lds-lightning-platform/blob/main/packages/lds-default-luvio/src/main.ts
|
|
2
|
+
|
|
3
|
+
// callback used to inform interested parties that a new default Luvio has been set.
|
|
4
|
+
|
|
5
|
+
// most recently set default Luvio instance
|
|
6
|
+
let defaultLuvio;
|
|
7
|
+
|
|
8
|
+
// callbacks to be invoked when default luvio instance is set/changed
|
|
9
|
+
const callbacks = [];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Constructs/sets the default Luvio instance. Any previously-set default luvio instance
|
|
13
|
+
* is overwritten.
|
|
14
|
+
*/
|
|
15
|
+
export function setDefaultLuvio({
|
|
16
|
+
luvio
|
|
17
|
+
}) {
|
|
18
|
+
if (luvio === undefined) {
|
|
19
|
+
throw new Error('unable to construct default Luvio instance from supplied parameters');
|
|
20
|
+
}
|
|
21
|
+
defaultLuvio = luvio;
|
|
22
|
+
|
|
23
|
+
// inform observers
|
|
24
|
+
for (let i = 0; i < callbacks.length; ++i) {
|
|
25
|
+
callbacks[i](defaultLuvio);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Registers a callback to be invoked with the default Luvio instance. Note that the
|
|
31
|
+
* callback may be invoked multiple times if the default Luvio changes.
|
|
32
|
+
*
|
|
33
|
+
* @param callback callback to be invoked with default Luvio instance
|
|
34
|
+
*/
|
|
35
|
+
export function withDefaultLuvio(callback) {
|
|
36
|
+
if (defaultLuvio) {
|
|
37
|
+
callback(defaultLuvio);
|
|
38
|
+
}
|
|
39
|
+
callbacks.push(callback);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// export * from './registry'; see below
|
|
43
|
+
|
|
44
|
+
const registryCallbacks = [];
|
|
45
|
+
const registrations = [];
|
|
46
|
+
export function forEachRegistration(callback) {
|
|
47
|
+
registryCallbacks.push(callback);
|
|
48
|
+
registrations.forEach(r => callback(r));
|
|
49
|
+
}
|
|
50
|
+
export function withRegistration(id, callback) {
|
|
51
|
+
forEachRegistration(r => {
|
|
52
|
+
if (r.id === id) {
|
|
53
|
+
callback(r);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export function register(r) {
|
|
58
|
+
registrations.push(r);
|
|
59
|
+
registryCallbacks.forEach(callback => callback(r));
|
|
60
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@lwc/synthetic-shadow';
|
|
2
2
|
export declare function authenticate(authInfo: {
|
|
3
|
-
access_token
|
|
3
|
+
access_token?: string;
|
|
4
4
|
instance_url: string;
|
|
5
5
|
}): void;
|
|
6
6
|
export declare function createComponent(specifier: string, nodeId: string | HTMLElement, properties?: Record<string, any>, config?: {
|
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
2
|
import '@lwc/synthetic-shadow'; // @ts-ignore: Typescript thinks createElement does not exist
|
|
3
|
-
|
|
4
3
|
import { createElement } from 'lwc';
|
|
5
4
|
import { setAuthInfo } from 'lwr/vault';
|
|
6
|
-
import HostCtor from 'lwr/host';
|
|
5
|
+
import HostCtor from 'lwr/host';
|
|
6
|
+
import setupLDS from 'lwr/setupLDS';
|
|
7
|
+
|
|
8
|
+
// Setup a Luvio instance with an OAuth network adapter
|
|
9
|
+
setupLDS();
|
|
7
10
|
|
|
11
|
+
// Export the LWRE authenticate() API
|
|
8
12
|
export function authenticate(authInfo) {
|
|
9
13
|
// Put OAuth info into the vault
|
|
10
14
|
if (authInfo) {
|
|
11
15
|
setAuthInfo(authInfo);
|
|
12
16
|
}
|
|
13
|
-
}
|
|
17
|
+
}
|
|
14
18
|
|
|
19
|
+
// Export the LWRE createComponent() API
|
|
15
20
|
export function createComponent(specifier, nodeId, properties = {}, config = {
|
|
16
21
|
navigation: false
|
|
17
22
|
}) {
|
|
18
23
|
if (!specifier) {
|
|
19
24
|
throw new Error('LWR Everywhere - createComponent requires a component specifier');
|
|
20
25
|
}
|
|
21
|
-
|
|
22
26
|
const hostCmp = createElement('lwr-host', {
|
|
23
27
|
is: HostCtor
|
|
24
28
|
});
|
|
25
29
|
hostCmp.componentId = specifier;
|
|
26
30
|
hostCmp.navigation = config.navigation;
|
|
27
31
|
const node = typeof nodeId === 'string' ? document.getElementById(nodeId) : nodeId;
|
|
28
|
-
|
|
29
32
|
if (!node) {
|
|
30
33
|
throw new Error('LWR Everywhere - cannot find node passed to createComponent');
|
|
31
34
|
}
|
|
32
|
-
|
|
33
35
|
node.appendChild(hostCmp);
|
|
34
36
|
hostCmp.properties = properties;
|
|
35
37
|
return hostCmp;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ServiceAPI } from '@lwrjs/types';
|
|
2
2
|
export declare function initAmd(services: ServiceAPI, mappingEndpoint: string, coreVersion: string): void;
|
|
3
3
|
export declare function authenticate(authInfo: {
|
|
4
|
-
access_token
|
|
4
|
+
access_token?: string;
|
|
5
5
|
instance_url: string;
|
|
6
6
|
}): void;
|
|
7
7
|
//# sourceMappingURL=everywhereAmd.d.ts.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// IMPORTANT: Do not add any static imports to this file that are not bundled with the amd-client
|
|
2
|
-
import { getAuthInfo, setAuthInfo } from 'lwr/vault'; // Do an OAuthed fetch
|
|
3
2
|
|
|
3
|
+
import { getAuthInfo, setAuthInfo } from 'lwr/vault';
|
|
4
|
+
|
|
5
|
+
// Do an OAuthed fetch
|
|
4
6
|
async function authFetch(url, accept = 'javascript') {
|
|
5
7
|
const authInfo = getAuthInfo();
|
|
6
|
-
|
|
7
8
|
if (authInfo) {
|
|
8
9
|
return fetch(url, {
|
|
9
10
|
headers: {
|
|
@@ -12,12 +13,11 @@ async function authFetch(url, accept = 'javascript') {
|
|
|
12
13
|
}
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
|
-
|
|
16
16
|
return null; // defer to loader
|
|
17
|
-
}
|
|
18
|
-
// Workaround: core does not have proper versioning; replace all versions with 0_0_1
|
|
19
|
-
|
|
17
|
+
}
|
|
20
18
|
|
|
19
|
+
// Add a hook for adding OAuth headers to module and mapping requests
|
|
20
|
+
// Workaround: core does not have proper versioning; replace all versions with 0_0_1
|
|
21
21
|
function everywhereHooks(serviceAPI, mappingEndpoint, coreVersion) {
|
|
22
22
|
serviceAPI.addLoaderPlugin({
|
|
23
23
|
loadModule: async url => {
|
|
@@ -25,11 +25,9 @@ function everywhereHooks(serviceAPI, mappingEndpoint, coreVersion) {
|
|
|
25
25
|
},
|
|
26
26
|
loadMapping: async specifier => {
|
|
27
27
|
const res = await authFetch(`${mappingEndpoint}${encodeURIComponent(specifier)}`, 'json');
|
|
28
|
-
|
|
29
28
|
if (res && res.ok) {
|
|
30
29
|
return res.json();
|
|
31
30
|
}
|
|
32
|
-
|
|
33
31
|
return null;
|
|
34
32
|
},
|
|
35
33
|
resolveModule: specifier => {
|
|
@@ -38,7 +36,6 @@ function everywhereHooks(serviceAPI, mappingEndpoint, coreVersion) {
|
|
|
38
36
|
if (specifier && !/\/v\/[^/]+?$/.test(specifier)) {
|
|
39
37
|
return `${specifier}/v/${coreVersion}`;
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
return null; // defer to loader
|
|
43
40
|
}
|
|
44
41
|
});
|
|
@@ -49,10 +46,11 @@ export function initAmd(services, mappingEndpoint, coreVersion) {
|
|
|
49
46
|
if (mappingEndpoint.match(/\/v5\d\.0\//)) {
|
|
50
47
|
everywhereHooks(services, mappingEndpoint, coreVersion);
|
|
51
48
|
}
|
|
52
|
-
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Export the LWRE authenticate() API
|
|
53
52
|
// This is a duplicate of the function exported from "lwr/everywhere"
|
|
54
53
|
// because it MUST be bundled into the LWRE module via "lwr/everywhereAmd"
|
|
55
|
-
|
|
56
54
|
export function authenticate(authInfo) {
|
|
57
55
|
// Put OAuth info into the vault
|
|
58
56
|
if (authInfo) {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
2
|
// @ts-ignore: Use LWC module resolver
|
|
3
3
|
import { init } from 'lwr/esmLoader'; // @ts-ignore
|
|
4
|
-
|
|
5
|
-
export { createComponent } from 'lwr/everywhere';
|
|
4
|
+
export { authenticate, createComponent } from 'lwr/everywhere';
|
|
6
5
|
export function initEsm({
|
|
7
6
|
imports,
|
|
8
7
|
index,
|
|
@@ -1,46 +1,41 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
|
|
3
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
3
|
import { LightningElement, api } from 'lwc'; // @ts-ignore: Use LWC module resolver
|
|
5
4
|
|
|
6
5
|
// Host component constants
|
|
7
|
-
const SPECIFIER_REGEX = /^@?[\w-]+(\/[\w-]+)*$/;
|
|
6
|
+
const SPECIFIER_REGEX = /^@?[\w-]+(\/[\w-]+)*$/;
|
|
8
7
|
|
|
8
|
+
// Navigation events
|
|
9
9
|
const NAV_EVENT = 'navigate'; // FIRED after a navigation event has been completed
|
|
10
|
-
|
|
11
10
|
const NAV_ERROR_EVENT = 'navigationerror'; // FIRED when a navigation event has failed
|
|
12
11
|
|
|
13
12
|
export default class LwrHost extends LightningElement {
|
|
14
13
|
// The component specifier of the Salesforce UI content to embed
|
|
15
14
|
@api
|
|
16
|
-
componentId = undefined;
|
|
15
|
+
componentId = undefined;
|
|
17
16
|
|
|
17
|
+
// Getter and setter for the public (@api) properties on the embedded component
|
|
18
18
|
_props = {};
|
|
19
|
-
|
|
20
19
|
@api
|
|
21
20
|
get properties() {
|
|
22
21
|
return this._props;
|
|
23
22
|
}
|
|
24
|
-
|
|
25
23
|
set properties(value) {
|
|
26
24
|
this._props = value;
|
|
27
25
|
this.setProperties(value);
|
|
28
|
-
}
|
|
29
|
-
|
|
26
|
+
}
|
|
30
27
|
|
|
28
|
+
// Import and embed the Salesforce UI content
|
|
31
29
|
ctor = undefined;
|
|
32
|
-
|
|
33
30
|
async connectedCallback() {
|
|
34
31
|
// Setup navigation hooks before the embedded component is mounted
|
|
35
32
|
await this.setUpNavBridge();
|
|
36
|
-
|
|
37
33
|
if (this.componentId) {
|
|
38
34
|
if (typeof this.componentId !== 'string' || !SPECIFIER_REGEX.test(this.componentId)) {
|
|
39
35
|
// Validate component specifier format
|
|
40
36
|
console.error('LWR Everywhere - Salesforce UI content has an invalid component-id:', this.componentId);
|
|
41
37
|
return;
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
try {
|
|
45
40
|
const module = await import(this.componentId);
|
|
46
41
|
this.ctor = module.default;
|
|
@@ -49,22 +44,21 @@ export default class LwrHost extends LightningElement {
|
|
|
49
44
|
console.error('LWR Everywhere - Salesforce UI content did not load:', e.message);
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
47
|
+
}
|
|
54
48
|
|
|
49
|
+
// Initialize public (@api) properties on the embedded content
|
|
55
50
|
renderedCallback() {
|
|
56
51
|
this.setProperties(this.properties);
|
|
57
|
-
}
|
|
58
|
-
|
|
52
|
+
}
|
|
59
53
|
|
|
54
|
+
// When the Salesforce UI content has an unhandled error, print an error to the console
|
|
60
55
|
errorCallback(e) {
|
|
61
56
|
console.error(`LWR Everywhere - Salesforce UI content for "${this.componentId}" cannot be displayed:`, e.message);
|
|
62
|
-
}
|
|
63
|
-
|
|
57
|
+
}
|
|
64
58
|
|
|
59
|
+
// Update public (@api) properties on the embedded content
|
|
65
60
|
setProperties(properties) {
|
|
66
61
|
const dynamicContent = this.template.querySelector('lwr-dynamic');
|
|
67
|
-
|
|
68
62
|
if (dynamicContent) {
|
|
69
63
|
Object.entries(properties).forEach(([key, value]) => {
|
|
70
64
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -73,15 +67,16 @@ export default class LwrHost extends LightningElement {
|
|
|
73
67
|
});
|
|
74
68
|
}
|
|
75
69
|
}
|
|
70
|
+
|
|
76
71
|
/**
|
|
77
72
|
* NAVIGATION FEATURE PROPERTIES AND METHODS
|
|
78
73
|
* The navigation feature creates a bridge between the root router of embedded
|
|
79
74
|
* Salesforce UI content and the host document with public properties and events
|
|
80
75
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
76
|
@api
|
|
84
|
-
navigation = false;
|
|
77
|
+
navigation = false;
|
|
78
|
+
|
|
79
|
+
// Create the router bridge
|
|
85
80
|
|
|
86
81
|
async setUpNavBridge() {
|
|
87
82
|
if (this.navigation && !this.bridge) {
|
|
@@ -101,12 +96,14 @@ export default class LwrHost extends LightningElement {
|
|
|
101
96
|
onError: error => this.dispatchEvent(new CustomEvent(NAV_ERROR_EVENT, {
|
|
102
97
|
detail: error
|
|
103
98
|
}))
|
|
104
|
-
},
|
|
99
|
+
},
|
|
100
|
+
// The bridge is attached to this component, and observes the root router inside its slot
|
|
105
101
|
this);
|
|
106
102
|
}
|
|
107
|
-
}
|
|
108
|
-
// The host component cannot call "lwr/navigation" APIs; it has no access to a NavigationContext
|
|
103
|
+
}
|
|
109
104
|
|
|
105
|
+
// Navigate via the bridge, which is hooked into its descendent root router
|
|
106
|
+
// The host component cannot call "lwr/navigation" APIs; it has no access to a NavigationContext
|
|
110
107
|
|
|
111
108
|
navigate(pageRef) {
|
|
112
109
|
if (pageRef && this.bridge && this.bridge.navigate(pageRef)) {
|
|
@@ -116,17 +113,16 @@ export default class LwrHost extends LightningElement {
|
|
|
116
113
|
// SAVE the pending page reference if the navigation event was NOT fired
|
|
117
114
|
this.pendingPageRef = pageRef;
|
|
118
115
|
}
|
|
119
|
-
}
|
|
116
|
+
}
|
|
120
117
|
|
|
118
|
+
// Navigate to the page reference when set from the host document
|
|
121
119
|
|
|
122
120
|
@api
|
|
123
121
|
get pageReference() {
|
|
124
122
|
return this._pageRef;
|
|
125
123
|
}
|
|
126
|
-
|
|
127
124
|
set pageReference(pageRef) {
|
|
128
125
|
this._pageRef = pageRef;
|
|
129
126
|
this.navigate(pageRef);
|
|
130
127
|
}
|
|
131
|
-
|
|
132
128
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { getAuthInfo } from 'lwr/vault';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Authenticated UI API Luvio Network Adapter
|
|
5
|
+
* See LDS error handling: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.data_error
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
class RecordError extends Error {
|
|
9
|
+
constructor(message, status = 404) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.body = {
|
|
12
|
+
message
|
|
13
|
+
};
|
|
14
|
+
this.ok = false;
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.statusText = message;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
export async function networkAdapter(req) {
|
|
22
|
+
const authInfo = getAuthInfo();
|
|
23
|
+
if (authInfo) {
|
|
24
|
+
const {
|
|
25
|
+
instance_url,
|
|
26
|
+
access_token
|
|
27
|
+
} = authInfo;
|
|
28
|
+
const {
|
|
29
|
+
baseUri,
|
|
30
|
+
basePath,
|
|
31
|
+
body,
|
|
32
|
+
queryParams,
|
|
33
|
+
method,
|
|
34
|
+
headers
|
|
35
|
+
} = req;
|
|
36
|
+
const path = `${instance_url}${baseUri}${basePath}${generateQueryString(queryParams)}`;
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch(path, {
|
|
39
|
+
method: method.toUpperCase(),
|
|
40
|
+
headers: access_token ? generateHeaders({
|
|
41
|
+
...headers,
|
|
42
|
+
Authorization: `Bearer ${access_token}`
|
|
43
|
+
}) : generateHeaders(headers),
|
|
44
|
+
body: body === null ? null : JSON.stringify(body)
|
|
45
|
+
});
|
|
46
|
+
if (res.ok) {
|
|
47
|
+
return {
|
|
48
|
+
body: res.status === 204 ? undefined : await res.json(),
|
|
49
|
+
// HTTP 204 = No Content
|
|
50
|
+
status: res.status,
|
|
51
|
+
statusText: res.statusText,
|
|
52
|
+
ok: res.ok,
|
|
53
|
+
headers: {}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Request goes through but returns HTTP errors
|
|
57
|
+
throw new RecordError(res.statusText, res.status);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
// Return the failure; no response status => 401
|
|
60
|
+
const error = e;
|
|
61
|
+
throw new RecordError(error.message, error.status >= 0 ? error.status : 401);
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
// There is no authentication data available to make this request
|
|
65
|
+
throw new RecordError('You are not authenticated.', 401);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
+
function generateQueryString(params) {
|
|
71
|
+
const queryStrings = [];
|
|
72
|
+
for (const key of Object.keys(params)) {
|
|
73
|
+
const value = Array.isArray(params[key]) ? params[key].join(',') : params[key];
|
|
74
|
+
if (value) {
|
|
75
|
+
queryStrings.push(`${key}=${value}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return queryStrings.length > 0 ? `?${queryStrings.join('&')}` : '';
|
|
79
|
+
}
|
|
80
|
+
function generateHeaders(headers) {
|
|
81
|
+
const fetchHeaders = new globalThis.Headers();
|
|
82
|
+
for (const key of Object.keys(headers)) {
|
|
83
|
+
fetchHeaders.set(key, headers[key]);
|
|
84
|
+
}
|
|
85
|
+
fetchHeaders.set('Accept', 'application/json');
|
|
86
|
+
fetchHeaders.set('Content-Type', 'application/json');
|
|
87
|
+
return fetchHeaders;
|
|
88
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Luvio, Store, Environment } from '@luvio/engine';
|
|
2
|
+
// import { setDefaultLuvio } from 'force/ldsEngine'; // TODO: uncomment if available on-core
|
|
3
|
+
import { networkAdapter } from './network';
|
|
4
|
+
|
|
5
|
+
// This module is used with LWR Java apps, the "force/ldsEngine" module is available on-core
|
|
6
|
+
// Set the default Luvio instance for LWR Everywhere
|
|
7
|
+
// It uses a fetch-based "web" network adapter with OAuth headers
|
|
8
|
+
|
|
9
|
+
export default function () {
|
|
10
|
+
/* const luvio = */new Luvio(new Environment(new Store(), networkAdapter));
|
|
11
|
+
// setDefaultLuvio({ luvio });
|
|
12
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { getAuthInfo } from 'lwr/vault';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Authenticated UI API Luvio Network Adapter
|
|
5
|
+
* See LDS error handling: https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.data_error
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
class RecordError extends Error {
|
|
9
|
+
constructor(message, status = 404) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.body = {
|
|
12
|
+
message
|
|
13
|
+
};
|
|
14
|
+
this.ok = false;
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.statusText = message;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
export async function networkAdapter(req) {
|
|
22
|
+
const authInfo = getAuthInfo();
|
|
23
|
+
if (authInfo) {
|
|
24
|
+
const {
|
|
25
|
+
instance_url,
|
|
26
|
+
access_token
|
|
27
|
+
} = authInfo;
|
|
28
|
+
const {
|
|
29
|
+
baseUri,
|
|
30
|
+
basePath,
|
|
31
|
+
body,
|
|
32
|
+
queryParams,
|
|
33
|
+
method,
|
|
34
|
+
headers
|
|
35
|
+
} = req;
|
|
36
|
+
const path = `${instance_url}${baseUri}${basePath}${generateQueryString(queryParams)}`;
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch(path, {
|
|
39
|
+
method: method.toUpperCase(),
|
|
40
|
+
headers: access_token ? generateHeaders({
|
|
41
|
+
...headers,
|
|
42
|
+
Authorization: `Bearer ${access_token}`
|
|
43
|
+
}) : generateHeaders(headers),
|
|
44
|
+
body: body === null ? null : JSON.stringify(body)
|
|
45
|
+
});
|
|
46
|
+
if (res.ok) {
|
|
47
|
+
return {
|
|
48
|
+
body: res.status === 204 ? undefined : await res.json(),
|
|
49
|
+
// HTTP 204 = No Content
|
|
50
|
+
status: res.status,
|
|
51
|
+
statusText: res.statusText,
|
|
52
|
+
ok: res.ok,
|
|
53
|
+
headers: {}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Request goes through but returns HTTP errors
|
|
57
|
+
throw new RecordError(res.statusText, res.status);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
// Return the failure; no response status => 401
|
|
60
|
+
const error = e;
|
|
61
|
+
throw new RecordError(error.message, error.status >= 0 ? error.status : 401);
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
// There is no authentication data available to make this request
|
|
65
|
+
throw new RecordError('You are not authenticated.', 401);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
+
function generateQueryString(params) {
|
|
71
|
+
const queryStrings = [];
|
|
72
|
+
for (const key of Object.keys(params)) {
|
|
73
|
+
const value = Array.isArray(params[key]) ? params[key].join(',') : params[key];
|
|
74
|
+
if (value) {
|
|
75
|
+
queryStrings.push(`${key}=${value}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return queryStrings.length > 0 ? `?${queryStrings.join('&')}` : '';
|
|
79
|
+
}
|
|
80
|
+
function generateHeaders(headers) {
|
|
81
|
+
const fetchHeaders = new globalThis.Headers();
|
|
82
|
+
for (const key of Object.keys(headers)) {
|
|
83
|
+
fetchHeaders.set(key, headers[key]);
|
|
84
|
+
}
|
|
85
|
+
fetchHeaders.set('Accept', 'application/json');
|
|
86
|
+
fetchHeaders.set('Content-Type', 'application/json');
|
|
87
|
+
return fetchHeaders;
|
|
88
|
+
}
|