@lwrjs/everywhere 0.8.0-alpha.10

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.
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Copyright (c) 2022, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: MIT
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
+ */
7
+ // Construct the Client Bootstrap Config object
8
+ function getConfiguration(options) {
9
+ const { format, server, apiVersion, apiPrefix, locale, bundle, debug } = options;
10
+ const thisUrl = new URL(import.meta.url);
11
+ // URLs
12
+ const ORIGIN = server || thisUrl.origin || '';
13
+ const PREFIX = `${apiPrefix}/${apiVersion}`;
14
+ const POSTFIX = `0${locale ? `/l/${locale}` : ''}`; // hardcode compat='0': LWR-S doesn't accept '1' and LWR-JS ignores it
15
+ const BUNDLE_ID = '/bi/3_A,B,O,S,EG,JLMT,C,D,F,H,I,K,N,P,Q,R'; // core strategies
16
+ const ENDPOINT = bundle
17
+ ? `${ORIGIN}${PREFIX}/bundle/${format}/${POSTFIX}${BUNDLE_ID}-0/module/mi/`
18
+ : `${ORIGIN}${PREFIX}/module/${format}/${POSTFIX}/mi/`;
19
+ // Component specifiers and URIs
20
+ const BOOT_MODULE = `lwr/everywhere${format === 'esm' ? 'Esm' : 'Amd'}/v/0_8_0-alpha_10`;
21
+ const BOOT_URI = `${ENDPOINT}${encodeURIComponent(BOOT_MODULE)}/latest${debug ? '?debug' : ''}`;
22
+ // Client Bootstrap Config
23
+ const config = {
24
+ appId: 'lwre',
25
+ autoBoot: true,
26
+ bootstrapModule: BOOT_MODULE,
27
+ baseUrl: ORIGIN,
28
+ imports: { [BOOT_URI]: [BOOT_MODULE] },
29
+ index: { [BOOT_MODULE]: BOOT_URI },
30
+ endpoints: {
31
+ uris: {
32
+ module: ENDPOINT,
33
+ mapping: `${ORIGIN}${PREFIX}/mapping/${format}/${POSTFIX}${bundle ? BUNDLE_ID : ''}/mp/`,
34
+ },
35
+ },
36
+ };
37
+ // Add the debug modifier to the endpoints
38
+ if (debug && config.endpoints) {
39
+ config.endpoints.modifiers = { debug: 'true' };
40
+ }
41
+ return {
42
+ options: { NODE_ENV: debug ? 'development' : 'production' },
43
+ config, // globalThis.LWR
44
+ };
45
+ }
46
+
47
+ /** LWR Everywhere module for ESM **/
48
+ // Process the LWR Client Bootstrap Config
49
+ const configOptions = { "format": "esm", "apiVersion": "1", "apiPrefix": "", "bundle": false, "debug": true };
50
+ const configuration = getConfiguration(configOptions);
51
+ const { bootstrapModule, imports, index = {}, importMappings, endpoints } = configuration.config;
52
+ globalThis.process = { env: { NODE_ENV: configuration.options.NODE_ENV } }; // Required by LWC
53
+ // Set up the ESM loader; Export the LWRE APIs
54
+ const { initEsm, authenticate, createComponent } = await import(
55
+ /* webpackIgnore: true */ index[bootstrapModule]);
56
+ initEsm({ imports, index, importMappings, endpoints });
57
+
58
+ export { authenticate, createComponent };
@@ -0,0 +1 @@
1
+ const e=function(e){const{format:o,server:i,apiVersion:n,apiPrefix:t,locale:p,bundle:r,debug:s}=e,m=new URL(import.meta.url),a=i||m.origin||"",d=`${t}/${n}`,$="0"+(p?`/l/${p}`:""),l="/bi/3_A,B,O,S,EG,JLMT,C,D,F,H,I,K,N,P,Q,R",u=r?`${a}${d}/bundle/${o}/${$}${l}-0/module/mi/`:`${a}${d}/module/${o}/${$}/mi/`,b=`lwr/everywhere${"esm"===o?"Esm":"Amd"}/v/0_8_0-alpha_10`,c=`${u}${encodeURIComponent(b)}/latest${s?"?debug":""}`,g={appId:"lwre",autoBoot:!0,bootstrapModule:b,baseUrl:a,imports:{[c]:[b]},index:{[b]:c},endpoints:{uris:{module:u,mapping:`${a}${d}/mapping/${o}/${$}${r?l:""}/mp/`}}};return s&&g.endpoints&&(g.endpoints.modifiers={debug:"true"}),{options:{NODE_ENV:s?"development":"production"},config:g}}({format:"esm",apiVersion:"1",apiPrefix:"",bundle:!0,debug:!1}),{bootstrapModule:o,imports:i,index:n={},importMappings:t,endpoints:p}=e.config;globalThis.process={env:{NODE_ENV:e.options.NODE_ENV}};const{initEsm:r,authenticate:s,createComponent:m}=await import(n[o]);r({imports:i,index:n,importMappings:t,endpoints:p});export{s as authenticate,m as createComponent};
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Copyright (c) 2022, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: MIT
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
+ */
7
+ // Construct the Client Bootstrap Config object
8
+ function getConfiguration(options) {
9
+ const { format, server, apiVersion, apiPrefix, locale, bundle, debug } = options;
10
+ const thisUrl = new URL(import.meta.url);
11
+ // URLs
12
+ const ORIGIN = server || thisUrl.origin || '';
13
+ const PREFIX = `${apiPrefix}/${apiVersion}`;
14
+ const POSTFIX = `0${locale ? `/l/${locale}` : ''}`; // hardcode compat='0': LWR-S doesn't accept '1' and LWR-JS ignores it
15
+ const BUNDLE_ID = '/bi/3_A,B,O,S,EG,JLMT,C,D,F,H,I,K,N,P,Q,R'; // core strategies
16
+ const ENDPOINT = bundle
17
+ ? `${ORIGIN}${PREFIX}/bundle/${format}/${POSTFIX}${BUNDLE_ID}-0/module/mi/`
18
+ : `${ORIGIN}${PREFIX}/module/${format}/${POSTFIX}/mi/`;
19
+ // Component specifiers and URIs
20
+ const BOOT_MODULE = `lwr/everywhere${format === 'esm' ? 'Esm' : 'Amd'}/v/0_8_0-alpha_10`;
21
+ const BOOT_URI = `${ENDPOINT}${encodeURIComponent(BOOT_MODULE)}/latest${debug ? '?debug' : ''}`;
22
+ // Client Bootstrap Config
23
+ const config = {
24
+ appId: 'lwre',
25
+ autoBoot: true,
26
+ bootstrapModule: BOOT_MODULE,
27
+ baseUrl: ORIGIN,
28
+ imports: { [BOOT_URI]: [BOOT_MODULE] },
29
+ index: { [BOOT_MODULE]: BOOT_URI },
30
+ endpoints: {
31
+ uris: {
32
+ module: ENDPOINT,
33
+ mapping: `${ORIGIN}${PREFIX}/mapping/${format}/${POSTFIX}${bundle ? BUNDLE_ID : ''}/mp/`,
34
+ },
35
+ },
36
+ };
37
+ // Add the debug modifier to the endpoints
38
+ if (debug && config.endpoints) {
39
+ config.endpoints.modifiers = { debug: 'true' };
40
+ }
41
+ return {
42
+ options: { NODE_ENV: debug ? 'development' : 'production' },
43
+ config, // globalThis.LWR
44
+ };
45
+ }
46
+
47
+ /** LWR Everywhere module for ESM **/
48
+ // Process the LWR Client Bootstrap Config
49
+ const configOptions = { "format": "esm", "apiVersion": "1", "apiPrefix": "", "bundle": true, "debug": false };
50
+ const configuration = getConfiguration(configOptions);
51
+ const { bootstrapModule, imports, index = {}, importMappings, endpoints } = configuration.config;
52
+ globalThis.process = { env: { NODE_ENV: configuration.options.NODE_ENV } }; // Required by LWC
53
+ // Set up the ESM loader; Export the LWRE APIs
54
+ const { initEsm, authenticate, createComponent } = await import(
55
+ /* webpackIgnore: true */ index[bootstrapModule]);
56
+ initEsm({ imports, index, importMappings, endpoints });
57
+
58
+ export { authenticate, createComponent };
@@ -0,0 +1,6 @@
1
+ declare const authenticate: any;
2
+ declare function createComponent(specifier: string, nodeId: string | HTMLElement, properties?: Record<string, any>, config?: {
3
+ navigation: boolean;
4
+ }): Promise<Element>;
5
+ export { authenticate, createComponent };
6
+ //# sourceMappingURL=amd-client.d.ts.map
@@ -0,0 +1,39 @@
1
+ import { getConfiguration } from './utils';
2
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
+ // @ts-ignore: Use LWC module resolver
4
+ import { Loader } from 'lwr/loader';
5
+ /** LWR Everywhere module for AMD **/
6
+ // Process the LWR Client Bootstrap Config
7
+ const configOptions = '$REPLACE_CLIENT_BOOTSTRAP_OPTIONS$';
8
+ const configuration = getConfiguration(configOptions);
9
+ const { bootstrapModule, endpoints, baseUrl, imports, index } = configuration.config;
10
+ globalThis.process = { env: { NODE_ENV: configuration.options.NODE_ENV } }; // Required by LWC
11
+ // Initialize the AMD loader (its code is bundled into the LWR Everywhere module)
12
+ const loader = new Loader({ endpoints, baseUrl });
13
+ loader.define('lwr/loader/v/$REPLACE_MODULE_VERSION$', ['exports'], (exports) => {
14
+ Object.assign(exports, {
15
+ define: loader.define.bind(loader),
16
+ load: loader.load.bind(loader),
17
+ });
18
+ });
19
+ await loader.registerImportMappings({ imports, index }, [bootstrapModule]);
20
+ globalThis.LWR = Object.freeze({ define: loader.define.bind(loader) });
21
+ // Define preload modules (ie: ABS, vault, etc) BEFORE loading them
22
+ // $REPLACE_PRELOAD_MODULES$
23
+ // Set up the AMD loader hooks for OAuth
24
+ const { initAmd, authenticate } = await loader.load(bootstrapModule);
25
+ initAmd(loader.services, endpoints?.uris.mapping, '$REPLACE_MODULE_VERSION$');
26
+ // Wrap the createComponent API to allow proper ordering of module definitions:
27
+ // 1. LWRE module bundle (this): lwr/loader, lwr/everywhereAmd, lwr/vault
28
+ // 2. lwr/everywhere (deps: lwc, synthetic shadow, lwr/host, etc)
29
+ // 3. Salesforce hosted UI content (i.e. embedded components and deps)
30
+ async function createComponent(specifier, nodeId, properties = {}, config) {
31
+ // Do not load the "lwr/everywhere" API module ahead of time
32
+ // This import MUST be done AFTER the loader hooks are in place via authenticate() so
33
+ // modules [statically] imported from core have the appropriate Authorization headers
34
+ const { createComponent: cc } = await loader.load(bootstrapModule.replace('Amd', ''));
35
+ return cc(specifier, nodeId, properties, config);
36
+ }
37
+ // Export the LWRE APIs
38
+ export { authenticate, createComponent };
39
+ //# sourceMappingURL=amd-client.js.map
@@ -0,0 +1,3 @@
1
+ declare const authenticate: any, createComponent: any;
2
+ export { authenticate, createComponent };
3
+ //# sourceMappingURL=esm-client.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { getConfiguration } from './utils';
2
+ /** LWR Everywhere module for ESM **/
3
+ // Process the LWR Client Bootstrap Config
4
+ const configOptions = '$REPLACE_CLIENT_BOOTSTRAP_OPTIONS$';
5
+ const configuration = getConfiguration(configOptions);
6
+ const { bootstrapModule, imports, index = {}, importMappings, endpoints } = configuration.config;
7
+ globalThis.process = { env: { NODE_ENV: configuration.options.NODE_ENV } }; // Required by LWC
8
+ // Set up the ESM loader; Export the LWRE APIs
9
+ const { initEsm, authenticate, createComponent } = await import(
10
+ /* webpackIgnore: true */ index[bootstrapModule]);
11
+ initEsm({ imports, index, importMappings, endpoints });
12
+ export { authenticate, createComponent };
13
+ //# sourceMappingURL=esm-client.js.map
@@ -0,0 +1,7 @@
1
+ import type { EverywhereClientBootstrapOptions } from './utils';
2
+ export interface GenerationOptions extends EverywhereClientBootstrapOptions {
3
+ minify?: boolean;
4
+ outFile?: string;
5
+ }
6
+ export declare function generate(options: GenerationOptions): Promise<void>;
7
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1,127 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import typescript from 'typescript';
4
+ import { rollup } from 'rollup';
5
+ import replace from '@rollup/plugin-replace';
6
+ import { terser } from 'rollup-plugin-terser';
7
+ import { resolveModule } from '@lwc/module-resolver';
8
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
9
+ // @ts-ignore - this package has no types
10
+ import typescriptPlugin from 'rollup-plugin-typescript';
11
+ import { rootPath, version } from '@lwrjs/everywhere/package';
12
+ const CORE_VERSION = '0_0_1';
13
+ const NPM_VERSION = version.replace(/\./g, '_');
14
+ const NPM2CORE_REGEX = new RegExp(`lwr/([a-zA-Z#_.]+)/v/${NPM_VERSION}`, 'g');
15
+ /* istanbul ignore next */
16
+ const lwcResolver = {
17
+ resolveId(importee, importer) {
18
+ if (importee === 'lwr/loader') {
19
+ try {
20
+ return resolveModule(importee, importer, {
21
+ modules: [{ npm: '@lwrjs/loader' }],
22
+ }).entry;
23
+ }
24
+ catch (e) {
25
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
26
+ // @ts-ignore
27
+ if (e.code !== 'NO_LWC_MODULE_FOUND') {
28
+ throw e;
29
+ }
30
+ }
31
+ }
32
+ return undefined;
33
+ },
34
+ };
35
+ // Generate a LWR Everywhere module file
36
+ export async function generate(options) {
37
+ const { format, server, apiVersion = '1', apiPrefix = '', locale, bundle = true, debug = false, minify = false, outFile = '__lwr_client__/lwr-everywhere.js', } = options;
38
+ if (!format || (format !== 'esm' && format !== 'amd')) {
39
+ throw new Error('The "format" option is required and must be either "esm" or "amd".');
40
+ }
41
+ const isCore = apiPrefix !== '';
42
+ // Required modules get added to the LWR Everywhere module when the format is "amd", so:
43
+ // - the modules will be in AMD format (ie: LWR.define(...))
44
+ // - the loader hook(s) are added before ANY modules are requested
45
+ let amdModules = '';
46
+ if (format === 'amd') {
47
+ amdModules = getAmdModule('everywhereAmd') + getAmdModule('vault');
48
+ if (isCore) {
49
+ // Workaround: core does not have proper versioning; replace all versions with 0.0.1
50
+ amdModules = amdModules.replace(NPM2CORE_REGEX, `lwr/$1/v/${CORE_VERSION}`);
51
+ }
52
+ }
53
+ // These config options get added to the LWR Everywhere module via string replacement
54
+ const clientBootstrapOptions = {
55
+ format,
56
+ server,
57
+ apiVersion,
58
+ apiPrefix,
59
+ locale,
60
+ bundle,
61
+ debug,
62
+ };
63
+ const rootDir = path.join(rootPath, 'src');
64
+ const theBundle = await rollup({
65
+ input: path.join(rootPath, `src/${format}-client.ts`),
66
+ plugins: [
67
+ replace({
68
+ "'$REPLACE_CLIENT_BOOTSTRAP_OPTIONS$'": JSON.stringify(clientBootstrapOptions),
69
+ // Workaround: core does not have proper versioning; the version is always 0.0.1
70
+ $REPLACE_MODULE_VERSION$: isCore ? CORE_VERSION : NPM_VERSION,
71
+ '// $REPLACE_PRELOAD_MODULES$': amdModules,
72
+ delimiters: ['', ''],
73
+ preventAssignment: true,
74
+ }),
75
+ typescriptPlugin({
76
+ typescript,
77
+ // the following options are needed to run outside this package
78
+ rootDir,
79
+ include: [rootDir + '/**/*'],
80
+ tsconfig: path.join(rootPath, 'tsconfig.json'),
81
+ }),
82
+ minify && terser(),
83
+ lwcResolver,
84
+ ],
85
+ /* istanbul ignore next */
86
+ onwarn({ code, message }) {
87
+ if (code === 'EVAL') {
88
+ return;
89
+ }
90
+ if (code !== 'CIRCULAR_DEPENDENCY') {
91
+ throw new Error(message);
92
+ }
93
+ },
94
+ });
95
+ const { output } = await theBundle.generate({
96
+ format: 'esm',
97
+ banner: `/**
98
+ * Copyright (c) 2022, salesforce.com, inc.
99
+ * All rights reserved.
100
+ * SPDX-License-Identifier: MIT
101
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
102
+ */`,
103
+ });
104
+ // Write the rollup output to the file system
105
+ if (!output[0].code) {
106
+ throw new Error('Generating the LWR Everywhere module produced no output.');
107
+ }
108
+ const outputPath = path.resolve(outFile);
109
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
110
+ fs.writeFileSync(outputPath, output[0].code);
111
+ }
112
+ function getAmdModule(moduleName) {
113
+ // Return contents of the lwr module with the given name, i.e. "lwr/moduleName"
114
+ // These modules are built in the "build:amd" script using the static site generator
115
+ const rootDir = path.join(rootPath, '__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr');
116
+ const moduleDir = path.join(rootDir, `${moduleName}/v/${NPM_VERSION}/s`);
117
+ const moduleSigs = fs
118
+ .readdirSync(moduleDir, { withFileTypes: true })
119
+ .filter((dir) => dir.isDirectory())
120
+ .map((dir) => dir.name);
121
+ if (moduleSigs.length > 0) {
122
+ return fs.readFileSync(path.join(moduleDir, moduleSigs[0], `lwr_${moduleName}.js`), 'utf8');
123
+ }
124
+ console.warn(`Generate: Could not find static module for "lwr/${moduleName}"`);
125
+ return '';
126
+ }
127
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1,13 @@
1
+ import type { ProviderContext, ResourceDefinition, ResourceIdentifier, ResourceProvider, RuntimeEnvironment } from '@lwrjs/types';
2
+ export default class LwrEverywhereClientProvider implements ResourceProvider {
3
+ name: string;
4
+ filenames: string[];
5
+ version: string;
6
+ directory: string;
7
+ context: ProviderContext;
8
+ constructor({ dir }: {
9
+ dir: string;
10
+ }, context: ProviderContext);
11
+ getResource<T extends ResourceIdentifier, R extends RuntimeEnvironment>(resource: T, environment: R): Promise<ResourceDefinition | undefined>;
12
+ }
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,36 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import { version as VERSION } from '@lwrjs/everywhere/package';
4
+ import { dirname } from 'path';
5
+ import { fileURLToPath } from 'url';
6
+ const dirName = dirname(fileURLToPath(import.meta.url));
7
+ const rootPath = path.join(dirName, './');
8
+ export default class LwrEverywhereClientProvider {
9
+ constructor({ dir = 'assets' }, context) {
10
+ this.name = 'lwr-everywhere-client-runtime';
11
+ this.filenames = ['lwr-everywhere.js', 'lwr-everywhere-min.js', 'lwr-everywhere-debug.js'];
12
+ this.version = VERSION;
13
+ this.directory = dir;
14
+ this.context = context;
15
+ }
16
+ async getResource(resource, environment) {
17
+ const { specifier, version = this.version } = resource;
18
+ const { format } = environment;
19
+ // Check that the resource is the LWR Everywhere module
20
+ if (!this.filenames.includes(specifier) || (version && version !== this.version)) {
21
+ return undefined;
22
+ }
23
+ // Retrieve the filepath from the build directory
24
+ const absFilepath = path.join(rootPath, '..', this.directory, format, specifier);
25
+ if (fs.existsSync(absFilepath)) {
26
+ return {
27
+ specifier,
28
+ type: 'application/javascript',
29
+ content: fs.readFileSync(absFilepath).toString(),
30
+ src: this.context.resourceRegistry.resolveResourceUri({ specifier, version }, environment),
31
+ };
32
+ }
33
+ return undefined;
34
+ }
35
+ }
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,22 @@
1
+ import type { ClientBootstrapConfig } from '@lwrjs/types';
2
+ export declare type GlobalThis = {
3
+ [key: string]: unknown;
4
+ };
5
+ export interface EverywhereClientBootstrapOptions {
6
+ format: 'esm' | 'amd';
7
+ server?: string;
8
+ apiVersion: string;
9
+ apiPrefix: string;
10
+ locale?: string;
11
+ bundle?: boolean;
12
+ debug?: boolean;
13
+ }
14
+ interface EverywhereClientBootstrap {
15
+ options: {
16
+ NODE_ENV: 'production' | 'development';
17
+ };
18
+ config: ClientBootstrapConfig;
19
+ }
20
+ export declare function getConfiguration(options: EverywhereClientBootstrapOptions): EverywhereClientBootstrap;
21
+ export {};
22
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,40 @@
1
+ // Construct the Client Bootstrap Config object
2
+ export function getConfiguration(options) {
3
+ const { format, server, apiVersion, apiPrefix, locale, bundle, debug } = options;
4
+ const thisUrl = new URL(import.meta.url);
5
+ // URLs
6
+ const ORIGIN = server || thisUrl.origin || '';
7
+ const PREFIX = `${apiPrefix}/${apiVersion}`;
8
+ const POSTFIX = `0${locale ? `/l/${locale}` : ''}`; // hardcode compat='0': LWR-S doesn't accept '1' and LWR-JS ignores it
9
+ const BUNDLE_ID = '/bi/3_A,B,O,S,EG,JLMT,C,D,F,H,I,K,N,P,Q,R'; // core strategies
10
+ const ENDPOINT = bundle
11
+ ? `${ORIGIN}${PREFIX}/bundle/${format}/${POSTFIX}${BUNDLE_ID}-0/module/mi/`
12
+ : `${ORIGIN}${PREFIX}/module/${format}/${POSTFIX}/mi/`;
13
+ // Component specifiers and URIs
14
+ const BOOT_MODULE = `lwr/everywhere${format === 'esm' ? 'Esm' : 'Amd'}/v/$REPLACE_MODULE_VERSION$`;
15
+ const BOOT_URI = `${ENDPOINT}${encodeURIComponent(BOOT_MODULE)}/latest${debug ? '?debug' : ''}`;
16
+ // Client Bootstrap Config
17
+ const config = {
18
+ appId: 'lwre',
19
+ autoBoot: true,
20
+ bootstrapModule: BOOT_MODULE,
21
+ baseUrl: ORIGIN,
22
+ imports: { [BOOT_URI]: [BOOT_MODULE] },
23
+ index: { [BOOT_MODULE]: BOOT_URI },
24
+ endpoints: {
25
+ uris: {
26
+ module: ENDPOINT,
27
+ mapping: `${ORIGIN}${PREFIX}/mapping/${format}/${POSTFIX}${bundle ? BUNDLE_ID : ''}/mp/`,
28
+ },
29
+ },
30
+ };
31
+ // Add the debug modifier to the endpoints
32
+ if (debug && config.endpoints) {
33
+ config.endpoints.modifiers = { debug: 'true' };
34
+ }
35
+ return {
36
+ options: { NODE_ENV: debug ? 'development' : 'production' },
37
+ config, // globalThis.LWR
38
+ };
39
+ }
40
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,37 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ // @ts-ignore
5
+ import '@lwc/synthetic-shadow'; // @ts-ignore
6
+
7
+ import { createElement } from 'lwc'; // @ts-ignore
8
+
9
+ import { setAuthInfo } from 'lwr/vault'; // @ts-ignore
10
+
11
+ import HostCtor from 'lwr/host'; // Export the LWRE authenticate() API
12
+
13
+ export function authenticate(authInfo) {
14
+ // Put OAuth info into the vault
15
+ if (authInfo) {
16
+ setAuthInfo(authInfo);
17
+ }
18
+ } // Export the LWRE createComponent() API
19
+
20
+ export function createComponent(specifier, nodeId, properties = {}, config = {
21
+ navigation: false
22
+ }) {
23
+ const hostCmp = createElement('lwr-host', {
24
+ is: HostCtor
25
+ });
26
+ hostCmp.componentId = specifier;
27
+ hostCmp.navigation = config.navigation;
28
+ const node = typeof nodeId === 'string' ? document.getElementById(nodeId) : nodeId;
29
+
30
+ if (!node) {
31
+ throw new Error('LWR Everywhere - cannot find node passed to createComponent');
32
+ }
33
+
34
+ node.appendChild(hostCmp);
35
+ hostCmp.properties = properties;
36
+ return hostCmp;
37
+ }
@@ -0,0 +1,61 @@
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
+
4
+ async function authFetch(url, accept = 'javascript') {
5
+ const authInfo = getAuthInfo();
6
+
7
+ if (authInfo) {
8
+ return fetch(url, {
9
+ headers: {
10
+ Accept: `application/${accept}`,
11
+ Authorization: `Bearer ${authInfo.access_token}`
12
+ }
13
+ });
14
+ }
15
+
16
+ return null; // defer to loader
17
+ } // Add a hook for adding OAuth headers to module and mapping requests
18
+ // Workaround: core does not have proper versioning; replace all versions with 0_0_1
19
+
20
+
21
+ function everywhereHooks(serviceAPI, mappingEndpoint, coreVersion) {
22
+ serviceAPI.addLoaderPlugin({
23
+ loadModule: async url => {
24
+ return authFetch(url);
25
+ },
26
+ loadMapping: async specifier => {
27
+ const res = await authFetch(`${mappingEndpoint}${encodeURIComponent(specifier)}`, 'json');
28
+
29
+ if (res && res.ok) {
30
+ return res.json();
31
+ }
32
+
33
+ return null;
34
+ },
35
+ resolveModule: specifier => {
36
+ // Workaround W-8010259 (dynamic imports without versions)
37
+ // by adding a default version to version-less specifiers
38
+ if (specifier && !/\/v\/[^/]+?$/.test(specifier)) {
39
+ return `${specifier}/v/${coreVersion}`;
40
+ }
41
+
42
+ return null; // defer to loader
43
+ }
44
+ });
45
+ }
46
+
47
+ export function initAmd(services, mappingEndpoint, coreVersion) {
48
+ // Initialize the loader hooks for LWR-S endpoints
49
+ if (mappingEndpoint.match(/\/v5\d\.0\//)) {
50
+ everywhereHooks(services, mappingEndpoint, coreVersion);
51
+ }
52
+ } // Export the LWRE authenticate() API
53
+ // This is a duplicate of the function exported from "lwr/everywhere"
54
+ // because it MUST be bundled into the LWRE module via "lwr/everywhereAmd"
55
+
56
+ export function authenticate(authInfo) {
57
+ // Put OAuth info into the vault
58
+ if (authInfo) {
59
+ setAuthInfo(authInfo);
60
+ }
61
+ }
@@ -0,0 +1,16 @@
1
+ import { init } from 'lwr/esmLoader';
2
+ export { createComponent } from 'lwr/everywhere';
3
+ export function initEsm({
4
+ imports,
5
+ index,
6
+ importMappings,
7
+ endpoints
8
+ }) {
9
+ // Initialize the ESM loader
10
+ init({
11
+ imports,
12
+ index,
13
+ importMappings,
14
+ endpoints
15
+ });
16
+ }
@@ -0,0 +1,5 @@
1
+ <template>
2
+ <div role="region" aria-live="polite" tabindex="-1">
3
+ <lwr-dynamic lwc:dynamic={ctor}></lwr-dynamic>
4
+ </div>
5
+ </template>