@lwrjs/everywhere 0.9.0-alpha.1 → 0.9.0-alpha.11
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 +1 -6
- package/build/__generated_site_amd_modules__/1/application/amd/l/en-US/ai/amd-bootstrap/configuration/ci/-/-/s/192f06f301107fde8653b5881ce02072/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_11/s/c40e6caf07454ce13961de8ca76ab7f0/@lwrjs_app-service_amd-bootstrap_module_amd.js +14 -0
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwc/v/{2_17_0/s/60dae7a83431c35c02c87ca8aaaa6044 → 2_33_0/s/90a5f16131da45cef1653112862ca9dc}/lwc.js +1907 -1061
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/everywhereAmd/v/{0_9_0-alpha_1/s/e66806169480601930ec9cfca972815e → 0_9_0-alpha_11/s/c538071acf5bde58e816967a14c465c3}/lwr_everywhereAmd.js +3 -3
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/init/v/{0_9_0-alpha_1/s/6258bcb20cc2d5d6a9f3c5a6f9d0acaf → 0_9_0-alpha_11/s/206e6e0af6f019fdfd86d87d56331bc2}/lwr_init.js +4 -4
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/loader/v/{0_9_0-alpha_1/s/ad376c7463bc9c203f7fed53444fe91d → 0_9_0-alpha_11/s/c9ab8c12a1c56b4580563bf949681854}/lwr_loader.js +5 -3
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/metrics/v/{0_9_0-alpha_1/s/dfbc827104d50ff7d16b59c9d0e06aca → 0_9_0-alpha_11/s/3426e42c3e22ce07ab2adc62c4c523a0}/lwr_metrics.js +1 -1
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/profiler/v/{0_9_0-alpha_1/s/5a10236d8c52bc9f6dee22875cd7016d → 0_9_0-alpha_11/s/e25f3b0b8b5c096acebf847d0a83ea62}/lwr_profiler.js +1 -1
- package/build/__generated_site_amd_modules__/1/module/amd/1/l/en-US/mi/lwr/vault/v/{0_9_0-alpha_1/s/6cbce1f9b7e815ee862b26f37ff4c76e → 0_9_0-alpha_11/s/c92abd8c1fec2d7eff62e4b097abbe14}/lwr_vault.js +1 -1
- package/build/__generated_site_amd_modules__/1/resource/amd/lwr-error-shim.js/v/{0_9_0-alpha_1 → 0_9_0-alpha_11} +1 -1
- package/build/__generated_site_amd_modules__/1/resource/amd/lwr-loader-shim.js/v/{0_9_0-alpha_1 → 0_9_0-alpha_11} +17 -16
- package/build/amd-client.js +1 -2
- package/build/assets/amd/lwr-everywhere-debug.js +21 -19
- package/build/assets/amd/lwr-everywhere-min.js +1 -1
- package/build/assets/amd/lwr-everywhere.js +21 -19
- package/build/assets/core/lwr-everywhere-debug.js +17 -15
- package/build/assets/core/lwr-everywhere-min.js +1 -1
- package/build/assets/core/lwr-everywhere.js +17 -15
- 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 +0 -1
- 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 +13 -6
- 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/ebc92226f879111d81405de719f1f046/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_1/s/c40e6caf07454ce13961de8ca76ab7f0/@lwrjs_app-service_amd-bootstrap_module_amd.js +0 -14
- package/build/__generated_site_amd_modules__/en-US/index.html +0 -26
- package/build/__generated_site_amd_modules__/index.html +0 -26
|
@@ -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,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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Luvio, Store, Environment } from '@luvio/engine';
|
|
2
|
+
import { setDefaultLuvio } from '@salesforce/lds-default-luvio';
|
|
3
|
+
import { networkAdapter } from './network';
|
|
4
|
+
|
|
5
|
+
// This module is used with LWR Node.js apps, it's aliased as "lwr/setupLDS" in package.json
|
|
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({
|
|
12
|
+
luvio
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Credential vault for storing setters and subscribers for OAuth info
|
|
2
2
|
// This module is a SINGLETON and must be excluded from ESM bundling
|
|
3
|
-
let authInfo; // Get and set the OAuth info
|
|
4
3
|
|
|
4
|
+
let authInfo;
|
|
5
|
+
|
|
6
|
+
// Get and set the OAuth info
|
|
5
7
|
export function getAuthInfo() {
|
|
6
8
|
return authInfo;
|
|
7
9
|
}
|
package/build/utils.d.ts
CHANGED
|
@@ -11,12 +11,5 @@ export interface EverywhereClientBootstrapOptions {
|
|
|
11
11
|
bundle?: boolean;
|
|
12
12
|
debug?: boolean;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
options: {
|
|
16
|
-
NODE_ENV: 'production' | 'development';
|
|
17
|
-
};
|
|
18
|
-
config: ClientBootstrapConfig;
|
|
19
|
-
}
|
|
20
|
-
export declare function getConfiguration(options: EverywhereClientBootstrapOptions): EverywhereClientBootstrap;
|
|
21
|
-
export {};
|
|
14
|
+
export declare function getConfiguration(options: EverywhereClientBootstrapOptions): ClientBootstrapConfig;
|
|
22
15
|
//# sourceMappingURL=utils.d.ts.map
|
package/build/utils.js
CHANGED
|
@@ -32,9 +32,6 @@ export function getConfiguration(options) {
|
|
|
32
32
|
if (debug && config.endpoints) {
|
|
33
33
|
config.endpoints.modifiers = { debug: 'true' };
|
|
34
34
|
}
|
|
35
|
-
return
|
|
36
|
-
options: { NODE_ENV: debug ? 'development' : 'production' },
|
|
37
|
-
config, // globalThis.LWR
|
|
38
|
-
};
|
|
35
|
+
return config;
|
|
39
36
|
}
|
|
40
37
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lwrjs/everywhere",
|
|
3
3
|
"description": "LWR Everywhere",
|
|
4
|
-
"version": "0.9.0-alpha.
|
|
4
|
+
"version": "0.9.0-alpha.11",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -48,24 +48,31 @@
|
|
|
48
48
|
"rollup-plugin-typescript": "^1.0.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@lwrjs/
|
|
54
|
-
"@lwrjs/
|
|
51
|
+
"@luvio/engine": "0.47.5",
|
|
52
|
+
"@lwc/module-resolver": "2.33.0",
|
|
53
|
+
"@lwrjs/loader": "0.9.0-alpha.11",
|
|
54
|
+
"@lwrjs/router": "0.9.0-alpha.11",
|
|
55
|
+
"@lwrjs/types": "0.9.0-alpha.11"
|
|
55
56
|
},
|
|
56
57
|
"lwc": {
|
|
57
58
|
"modules": [
|
|
58
59
|
{
|
|
59
60
|
"dir": "build/modules"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "lwr/setupLDS",
|
|
64
|
+
"path": "build/modules/lwr/setupNodeLDS/setupNodeLDS.js"
|
|
60
65
|
}
|
|
61
66
|
],
|
|
62
67
|
"expose": [
|
|
68
|
+
"@salesforce/lds-default-luvio",
|
|
63
69
|
"lwr/everywhere",
|
|
64
70
|
"lwr/everywhereAmd",
|
|
65
71
|
"lwr/everywhereEsm",
|
|
66
72
|
"lwr/host",
|
|
73
|
+
"lwr/setupLDS",
|
|
67
74
|
"lwr/vault"
|
|
68
75
|
]
|
|
69
76
|
},
|
|
70
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "3cb1275b364ae7373c1868c79e6082a122dbef9c"
|
|
71
78
|
}
|
package/src/amd-client.ts
CHANGED
|
@@ -10,8 +10,7 @@ import { Loader } from 'lwr/loader';
|
|
|
10
10
|
// Process the LWR Client Bootstrap Config
|
|
11
11
|
const configOptions = '$REPLACE_CLIENT_BOOTSTRAP_OPTIONS$' as unknown as EverywhereClientBootstrapOptions;
|
|
12
12
|
const configuration = getConfiguration(configOptions);
|
|
13
|
-
const { bootstrapModule, endpoints, baseUrl, imports, index } = configuration
|
|
14
|
-
(globalThis as GlobalThis).process = { env: { NODE_ENV: configuration.options.NODE_ENV } }; // Required by LWC
|
|
13
|
+
const { bootstrapModule, endpoints, baseUrl, imports, index } = configuration;
|
|
15
14
|
|
|
16
15
|
// Initialize the AMD loader (its code is bundled into the LWR Everywhere module)
|
|
17
16
|
const loader = new Loader({ endpoints, baseUrl });
|
package/src/esm-client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EverywhereClientBootstrapOptions
|
|
1
|
+
import type { EverywhereClientBootstrapOptions } from './utils';
|
|
2
2
|
import { getConfiguration } from './utils';
|
|
3
3
|
|
|
4
4
|
/** LWR Everywhere module for ESM **/
|
|
@@ -6,8 +6,7 @@ import { getConfiguration } from './utils';
|
|
|
6
6
|
// Process the LWR Client Bootstrap Config
|
|
7
7
|
const configOptions = '$REPLACE_CLIENT_BOOTSTRAP_OPTIONS$' as unknown as EverywhereClientBootstrapOptions;
|
|
8
8
|
const configuration = getConfiguration(configOptions);
|
|
9
|
-
const { bootstrapModule, imports, index = {}, importMappings, endpoints } = configuration
|
|
10
|
-
(globalThis as GlobalThis).process = { env: { NODE_ENV: configuration.options.NODE_ENV } }; // Required by LWC
|
|
9
|
+
const { bootstrapModule, imports, index = {}, importMappings, endpoints } = configuration;
|
|
11
10
|
|
|
12
11
|
// Set up the ESM loader; Export the LWRE APIs
|
|
13
12
|
const { initEsm, authenticate, createComponent } = await import(
|
package/src/generate.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { rootPath, version } from '@lwrjs/everywhere/package';
|
|
|
13
13
|
|
|
14
14
|
const CORE_VERSION = '0_0_1';
|
|
15
15
|
const NPM_VERSION = version.replace(/\./g, '_');
|
|
16
|
-
const NPM2CORE_REGEX = new RegExp(
|
|
16
|
+
const NPM2CORE_REGEX = new RegExp(`/v/${NPM_VERSION}`, 'g');
|
|
17
17
|
|
|
18
18
|
/* istanbul ignore next */
|
|
19
19
|
const lwcResolver = {
|
|
@@ -64,7 +64,7 @@ export async function generate(options: GenerationOptions): Promise<void> {
|
|
|
64
64
|
amdModules = getAmdModule('everywhereAmd') + getAmdModule('vault');
|
|
65
65
|
if (isCore) {
|
|
66
66
|
// Workaround: core does not have proper versioning; replace all versions with 0.0.1
|
|
67
|
-
amdModules = amdModules.replace(NPM2CORE_REGEX,
|
|
67
|
+
amdModules = amdModules.replace(NPM2CORE_REGEX, `/v/${CORE_VERSION}`);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -118,7 +118,8 @@ export async function generate(options: GenerationOptions): Promise<void> {
|
|
|
118
118
|
* All rights reserved.
|
|
119
119
|
* SPDX-License-Identifier: MIT
|
|
120
120
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
121
|
-
|
|
121
|
+
*/
|
|
122
|
+
globalThis.process = { env: { NODE_ENV: '${debug ? 'development' : 'production'}' } };`,
|
|
122
123
|
});
|
|
123
124
|
|
|
124
125
|
// Write the rollup output to the file system
|
package/src/index.ts
CHANGED
|
@@ -16,7 +16,7 @@ export default class LwrEverywhereClientProvider implements ResourceProvider {
|
|
|
16
16
|
directory: string;
|
|
17
17
|
context: ProviderContext;
|
|
18
18
|
|
|
19
|
-
constructor({ dir = 'assets' }: { dir: string }, context: ProviderContext) {
|
|
19
|
+
constructor({ dir = 'build/assets' }: { dir: string }, context: ProviderContext) {
|
|
20
20
|
this.directory = dir;
|
|
21
21
|
this.context = context;
|
|
22
22
|
}
|
|
@@ -33,7 +33,7 @@ export default class LwrEverywhereClientProvider implements ResourceProvider {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Retrieve the filepath from the build directory
|
|
36
|
-
const absFilepath = path.join(rootPath,
|
|
36
|
+
const absFilepath = path.join(rootPath, this.directory, format, specifier);
|
|
37
37
|
if (fs.existsSync(absFilepath)) {
|
|
38
38
|
return {
|
|
39
39
|
specifier,
|
package/src/utils.ts
CHANGED
|
@@ -13,16 +13,8 @@ export interface EverywhereClientBootstrapOptions {
|
|
|
13
13
|
debug?: boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
// Output: Normalized options and Client Bootstrap Config object
|
|
17
|
-
interface EverywhereClientBootstrap {
|
|
18
|
-
options: {
|
|
19
|
-
NODE_ENV: 'production' | 'development';
|
|
20
|
-
};
|
|
21
|
-
config: ClientBootstrapConfig;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
16
|
// Construct the Client Bootstrap Config object
|
|
25
|
-
export function getConfiguration(options: EverywhereClientBootstrapOptions):
|
|
17
|
+
export function getConfiguration(options: EverywhereClientBootstrapOptions): ClientBootstrapConfig {
|
|
26
18
|
const { format, server, apiVersion, apiPrefix, locale, bundle, debug } = options;
|
|
27
19
|
const thisUrl = new URL(import.meta.url);
|
|
28
20
|
|
|
@@ -59,8 +51,5 @@ export function getConfiguration(options: EverywhereClientBootstrapOptions): Eve
|
|
|
59
51
|
config.endpoints.modifiers = { debug: 'true' };
|
|
60
52
|
}
|
|
61
53
|
|
|
62
|
-
return
|
|
63
|
-
options: { NODE_ENV: debug ? 'development' : 'production' },
|
|
64
|
-
config, // globalThis.LWR
|
|
65
|
-
};
|
|
54
|
+
return config;
|
|
66
55
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/* This script is generated */
|
|
2
|
-
/* Client Bootstrap configuration */
|
|
3
|
-
globalThis.LWR = globalThis.LWR || {};
|
|
4
|
-
Object.assign(globalThis.LWR, {"appId":"amd-bootstrap","bootstrapModule":"@lwrjs/app-service/amd-bootstrap/module/amd/v/0_9_0-alpha_1","autoBoot":true,"imports":{"/1/module/amd/1/l/en-US/mi/%40lwrjs%2Fapp-service%2Famd-bootstrap%2Fmodule%2Famd%2Fv%2F0_9_0-alpha_1/s/c40e6caf07454ce13961de8ca76ab7f0/@lwrjs_app-service_amd-bootstrap_module_amd.js":["@lwrjs/app-service/amd-bootstrap/module/amd/v/0_9_0-alpha_1"],"/1/module/amd/1/l/en-US/mi/lwr%2Finit%2Fv%2F0_9_0-alpha_1/s/6258bcb20cc2d5d6a9f3c5a6f9d0acaf/lwr_init.js":["lwr/init/v/0_9_0-alpha_1"],"/1/module/amd/1/l/en-US/mi/lwr%2Fmetrics%2Fv%2F0_9_0-alpha_1/s/dfbc827104d50ff7d16b59c9d0e06aca/lwr_metrics.js":["lwr/metrics/v/0_9_0-alpha_1"],"/1/module/amd/1/l/en-US/mi/lwr%2Fprofiler%2Fv%2F0_9_0-alpha_1/s/5a10236d8c52bc9f6dee22875cd7016d/lwr_profiler.js":["lwr/profiler/v/0_9_0-alpha_1"],"/1/module/amd/1/l/en-US/mi/lwc%2Fv%2F2_17_0/s/60dae7a83431c35c02c87ca8aaaa6044/lwc.js":["lwc/v/2_17_0"],"/1/module/amd/1/l/en-US/mi/lwr%2FeverywhereAmd%2Fv%2F0_9_0-alpha_1/s/e66806169480601930ec9cfca972815e/lwr_everywhereAmd.js":["lwr/everywhereAmd/v/0_9_0-alpha_1"],"/1/module/amd/1/l/en-US/mi/lwr%2Fvault%2Fv%2F0_9_0-alpha_1/s/6cbce1f9b7e815ee862b26f37ff4c76e/lwr_vault.js":["lwr/vault/v/0_9_0-alpha_1"]},"index":{"@lwrjs/app-service/amd-bootstrap/module/amd/v/0_9_0-alpha_1":"/1/module/amd/1/l/en-US/mi/%40lwrjs%2Fapp-service%2Famd-bootstrap%2Fmodule%2Famd%2Fv%2F0_9_0-alpha_1/s/c40e6caf07454ce13961de8ca76ab7f0/@lwrjs_app-service_amd-bootstrap_module_amd.js","lwr/init/v/0_9_0-alpha_1":"/1/module/amd/1/l/en-US/mi/lwr%2Finit%2Fv%2F0_9_0-alpha_1/s/6258bcb20cc2d5d6a9f3c5a6f9d0acaf/lwr_init.js","lwr/metrics/v/0_9_0-alpha_1":"/1/module/amd/1/l/en-US/mi/lwr%2Fmetrics%2Fv%2F0_9_0-alpha_1/s/dfbc827104d50ff7d16b59c9d0e06aca/lwr_metrics.js","lwr/profiler/v/0_9_0-alpha_1":"/1/module/amd/1/l/en-US/mi/lwr%2Fprofiler%2Fv%2F0_9_0-alpha_1/s/5a10236d8c52bc9f6dee22875cd7016d/lwr_profiler.js","lwc/v/2_17_0":"/1/module/amd/1/l/en-US/mi/lwc%2Fv%2F2_17_0/s/60dae7a83431c35c02c87ca8aaaa6044/lwc.js","lwr/everywhereAmd/v/0_9_0-alpha_1":"/1/module/amd/1/l/en-US/mi/lwr%2FeverywhereAmd%2Fv%2F0_9_0-alpha_1/s/e66806169480601930ec9cfca972815e/lwr_everywhereAmd.js","lwr/vault/v/0_9_0-alpha_1":"/1/module/amd/1/l/en-US/mi/lwr%2Fvault%2Fv%2F0_9_0-alpha_1/s/6cbce1f9b7e815ee862b26f37ff4c76e/lwr_vault.js"},"rootComponents":["lwr/everywhereAmd/v/0_9_0-alpha_1"],"requiredModules":["@lwrjs/app-service/amd-bootstrap/module/amd/v/0_9_0-alpha_1"],"preloadModules":["lwr/everywhereAmd/v/0_9_0-alpha_1"],"endpoints":{"uris":{"mapping":"/1/mapping/amd/1/l/en-US/mp/"}}});
|
|
5
|
-
globalThis.process = { env: { NODE_ENV: "compat" } };
|
|
6
|
-
// Appended by Static Site Generator
|
|
7
|
-
if (!globalThis.LWR.imports) { globalThis.LWR.imports = {}; }
|
|
8
|
-
Object.assign(globalThis.LWR.imports, {"/1/module/amd/1/l/en-US/mi/lwr%2Floader%2Fv%2F0_9_0-alpha_1/s/ad376c7463bc9c203f7fed53444fe91d/lwr_loader.js":["lwr/loader/v/0_9_0-alpha_1"]})
|
|
9
|
-
if (!globalThis.LWR.index) { globalThis.LWR.index = {}; }
|
|
10
|
-
Object.assign(globalThis.LWR.index, {"lwr/loader/v/0_9_0-alpha_1":"/1/module/amd/1/l/en-US/mi/lwr%2Floader%2Fv%2F0_9_0-alpha_1/s/ad376c7463bc9c203f7fed53444fe91d/lwr_loader.js"})
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
LWR.define("@lwrjs/app-service/amd-bootstrap/module/amd/v/0_9_0-alpha_1", ["lwr/loader/v/0_9_0-alpha_1", "lwr/init/v/0_9_0-alpha_1"], function(_0_9_0Alpha_1$1, _0_9_0Alpha_1) {
|
|
2
|
-
"use strict";
|
|
3
|
-
const clientBootstrapConfig = globalThis.LWR;
|
|
4
|
-
const {rootComponents, ssrProps} = clientBootstrapConfig;
|
|
5
|
-
Promise.all(rootComponents.map(async (rootSpecifier) => {
|
|
6
|
-
const element = _0_9_0Alpha_1.toKebabCase(rootSpecifier);
|
|
7
|
-
return _0_9_0Alpha_1$1.load(rootSpecifier, "@lwrjs/app-service/amd-bootstrap/module/amd/v/0_9_0-alpha_1").then(({default: Ctor}) => {
|
|
8
|
-
_0_9_0Alpha_1.init([[element, Ctor]], ssrProps);
|
|
9
|
-
});
|
|
10
|
-
}));
|
|
11
|
-
globalThis.LWR = Object.freeze({
|
|
12
|
-
define: globalThis.LWR.define
|
|
13
|
-
});
|
|
14
|
-
});
|