@salesforce/lds-runtime-browser 0.1.0-dev1
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/LICENSE.txt
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Terms of Use
|
|
2
|
+
|
|
3
|
+
Copyright 2022 Salesforce, Inc. All rights reserved.
|
|
4
|
+
|
|
5
|
+
These Terms of Use govern the download, installation, and/or use of this
|
|
6
|
+
software provided by Salesforce, Inc. ("Salesforce") (the "Software"), were
|
|
7
|
+
last updated on April 15, 2022, and constitute a legally binding
|
|
8
|
+
agreement between you and Salesforce. If you do not agree to these Terms of
|
|
9
|
+
Use, do not install or use the Software.
|
|
10
|
+
|
|
11
|
+
Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free
|
|
12
|
+
copyright license to reproduce, prepare derivative works of, publicly
|
|
13
|
+
display, publicly perform, sublicense, and distribute the Software and
|
|
14
|
+
derivative works subject to these Terms. These Terms shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
Subject to the limited rights expressly granted hereunder, Salesforce
|
|
18
|
+
reserves all rights, title, and interest in and to all intellectual
|
|
19
|
+
property subsisting in the Software. No rights are granted to you hereunder
|
|
20
|
+
other than as expressly set forth herein. Users residing in countries on
|
|
21
|
+
the United States Office of Foreign Assets Control sanction list, or which
|
|
22
|
+
are otherwise subject to a US export embargo, may not use the Software.
|
|
23
|
+
|
|
24
|
+
Implementation of the Software may require development work, for which you
|
|
25
|
+
are responsible. The Software may contain bugs, errors and
|
|
26
|
+
incompatibilities and is made available on an AS IS basis without support,
|
|
27
|
+
updates, or service level commitments.
|
|
28
|
+
|
|
29
|
+
Salesforce reserves the right at any time to modify, suspend, or
|
|
30
|
+
discontinue, the Software (or any part thereof) with or without notice. You
|
|
31
|
+
agree that Salesforce shall not be liable to you or to any third party for
|
|
32
|
+
any modification, suspension, or discontinuance.
|
|
33
|
+
|
|
34
|
+
You agree to defend Salesforce against any claim, demand, suit or
|
|
35
|
+
proceeding made or brought against Salesforce by a third party arising out
|
|
36
|
+
of or accruing from (a) your use of the Software, and (b) any application
|
|
37
|
+
you develop with the Software that infringes any copyright, trademark,
|
|
38
|
+
trade secret, trade dress, patent, or other intellectual property right of
|
|
39
|
+
any person or defames any person or violates their rights of publicity or
|
|
40
|
+
privacy (each a "Claim Against Salesforce"), and will indemnify Salesforce
|
|
41
|
+
from any damages, attorney fees, and costs finally awarded against
|
|
42
|
+
Salesforce as a result of, or for any amounts paid by Salesforce under a
|
|
43
|
+
settlement approved by you in writing of, a Claim Against Salesforce,
|
|
44
|
+
provided Salesforce (x) promptly gives you written notice of the Claim
|
|
45
|
+
Against Salesforce, (y) gives you sole control of the defense and
|
|
46
|
+
settlement of the Claim Against Salesforce (except that you may not settle
|
|
47
|
+
any Claim Against Salesforce unless it unconditionally releases Salesforce
|
|
48
|
+
of all liability), and (z) gives you all reasonable assistance, at your
|
|
49
|
+
expense.
|
|
50
|
+
|
|
51
|
+
WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT
|
|
52
|
+
SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
53
|
+
IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES,
|
|
54
|
+
INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
|
55
|
+
PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA,
|
|
56
|
+
OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN
|
|
57
|
+
CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU
|
|
58
|
+
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
59
|
+
|
|
60
|
+
These Terms of Use shall be governed exclusively by the internal laws of
|
|
61
|
+
the State of California, without regard to its conflicts of laws
|
|
62
|
+
rules. Each party hereby consents to the exclusive jurisdiction of the
|
|
63
|
+
state and federal courts located in San Francisco County, California to
|
|
64
|
+
adjudicate any dispute arising out of or relating to these Terms of Use and
|
|
65
|
+
the download, installation, and/or use of the Software. Except as expressly
|
|
66
|
+
stated herein, these Terms of Use constitute the entire agreement between
|
|
67
|
+
the parties, and supersede all prior and contemporaneous agreements,
|
|
68
|
+
proposals, or representations, written or oral, concerning their subject
|
|
69
|
+
matter. No modification, amendment, or waiver of any provision of these
|
|
70
|
+
Terms of Use shall be effective unless it is by an update to these Terms of
|
|
71
|
+
Use that Salesforce makes available, or is in writing and signed by the
|
|
72
|
+
party against whom the modification, amendment, or waiver is to be
|
|
73
|
+
asserted.
|
|
74
|
+
|
|
75
|
+
Data Privacy: Salesforce may collect, process, and store device,
|
|
76
|
+
system, and other information related to your use of the Software. This
|
|
77
|
+
information includes, but is not limited to, IP address, user metrics, and
|
|
78
|
+
other data ("Usage Data"). Salesforce may use Usage Data for analytics,
|
|
79
|
+
product development, and marketing purposes. You acknowledge that files
|
|
80
|
+
generated in conjunction with the Software may contain sensitive or
|
|
81
|
+
confidential data, and you are solely responsible for anonymizing and
|
|
82
|
+
protecting such data.
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* ATTENTION!
|
|
9
|
+
* THIS IS A GENERATED FILE FROM https://github.com/salesforce-experience-platform-emu/lds-lightning-platform
|
|
10
|
+
* If you would like to contribute to LDS, please follow the steps outlined in the git repo.
|
|
11
|
+
* Any changes made to this file in p4 will be automatically overwritten.
|
|
12
|
+
* *******************************************************************************************
|
|
13
|
+
*/
|
|
14
|
+
import { setDefaultLuvio, withRegistration, register } from '@salesforce/lds-default-luvio';
|
|
15
|
+
import { instrumentLuvio, setLdsNetworkAdapterInstrumentation } from '@salesforce/lds-instrumentation';
|
|
16
|
+
import salesforceNetworkAdapter, { instrument } from '@salesforce/lds-network-adapter';
|
|
17
|
+
import { InMemoryStore, Environment, Luvio } from '@luvio/engine';
|
|
18
|
+
import { makeDurable } from '@luvio/environments';
|
|
19
|
+
import { fetchNetworkAdapter } from '@luvio/network-adapter-fetch';
|
|
20
|
+
import { IndexedDbDurableStore } from '@luvio/durable-store-idb';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A NetworkAdapter HOF that sets location.href to
|
|
24
|
+
* "/login?redirect_uri=<location.origin>/oauth" on 401 responses.
|
|
25
|
+
*/
|
|
26
|
+
function makeNetworkAdapterRedirectToLoginOn401(baseNetworkAdapter) {
|
|
27
|
+
return (resourceRequest, resourceRequestContext) => {
|
|
28
|
+
return baseNetworkAdapter(resourceRequest, resourceRequestContext).then((response) => {
|
|
29
|
+
if (response.status === 401) {
|
|
30
|
+
const redirectUrl = `${location.origin}/oauth`;
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.log(`401 response detected, re-directing to /login page`);
|
|
33
|
+
location.href = `/login?redirect_uri=${encodeURIComponent(redirectUrl)}`;
|
|
34
|
+
}
|
|
35
|
+
return response;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A NetworkAdapter HOF that works with salesforce Core authentication sid cookie
|
|
42
|
+
*/
|
|
43
|
+
function makeNetworkAdapterCoreAuthenticated(baseNetworkAdapter) {
|
|
44
|
+
return (resourceRequest, resourceRequestContext) => {
|
|
45
|
+
const { headers } = resourceRequest;
|
|
46
|
+
const headersWithAuth = buildHeaders(headers);
|
|
47
|
+
resourceRequest.headers = headersWithAuth;
|
|
48
|
+
return baseNetworkAdapter(resourceRequest, resourceRequestContext);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function buildHeaders(additionalHeaders = {}) {
|
|
52
|
+
const headers = {
|
|
53
|
+
...additionalHeaders,
|
|
54
|
+
};
|
|
55
|
+
if (headers.Authorization === undefined && document && document.cookie) {
|
|
56
|
+
// TODO [W-123]: need to work with auth team to come up with better way
|
|
57
|
+
// to do this... if LWR@Core followed the pattern that LWR@node auth middleware
|
|
58
|
+
// follows then this wouldn't be needed
|
|
59
|
+
const sidCookie = document.cookie.match(new RegExp('(^| )' + 'sid' + '=([^;]+)'));
|
|
60
|
+
if (sidCookie) {
|
|
61
|
+
const sid = sidCookie[2];
|
|
62
|
+
headers['Authorization'] = `Bearer ${sid}`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return headers;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// so eslint doesn't complain about nimbus
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
|
+
/* global __nimbus */
|
|
71
|
+
let lazyLuvio;
|
|
72
|
+
let lazyEnvironment;
|
|
73
|
+
/**
|
|
74
|
+
* This returns the LDS on Browser Runtime singleton object.
|
|
75
|
+
*/
|
|
76
|
+
function getRuntime() {
|
|
77
|
+
if (lazyLuvio === undefined || lazyEnvironment === undefined) {
|
|
78
|
+
const store = new InMemoryStore();
|
|
79
|
+
const networkAdapter = makeNetworkAdapterCoreAuthenticated(makeNetworkAdapterRedirectToLoginOn401(salesforceNetworkAdapter(
|
|
80
|
+
// TODO [W-123]: move the record field chunking code out of nimbus network
|
|
81
|
+
// adapter package and into the shared lds-network-adapter package
|
|
82
|
+
// makeNetworkAdapterChunkRecordFields(fetchNetworkAdapter)
|
|
83
|
+
fetchNetworkAdapter)));
|
|
84
|
+
const baseEnv = new Environment(store, networkAdapter);
|
|
85
|
+
lazyEnvironment = makeDurable(baseEnv, {
|
|
86
|
+
durableStore: new IndexedDbDurableStore(),
|
|
87
|
+
});
|
|
88
|
+
lazyEnvironment.setDefaultCachePolicy({ type: 'cache-then-network' });
|
|
89
|
+
lazyLuvio = new Luvio(lazyEnvironment, {
|
|
90
|
+
instrument: instrumentLuvio,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
luvio: lazyLuvio,
|
|
95
|
+
environment: lazyEnvironment,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function setupLuvio() {
|
|
99
|
+
const { luvio } = getRuntime();
|
|
100
|
+
setDefaultLuvio({ luvio });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// defer instrumentation setup on these modules unless/until other code causes
|
|
104
|
+
// them to be loaded
|
|
105
|
+
withRegistration('@salesforce/lds-network-adapter', (reg) => setLdsNetworkAdapterInstrumentation(reg));
|
|
106
|
+
// This code *should* be in lds-network-adapter, but when combined with the Aura
|
|
107
|
+
// component test workaround in lds-default-luvio it creates a circular dependency
|
|
108
|
+
// between lds-default-luvio and lds-network-adapter. We do the register on behalf
|
|
109
|
+
// of lds-network-adapter here to avoid the cycle.
|
|
110
|
+
register({
|
|
111
|
+
id: '@salesforce/lds-network-adapter',
|
|
112
|
+
instrument: instrument,
|
|
113
|
+
});
|
|
114
|
+
// This loader hook sets the luvio instance for running in the browser.
|
|
115
|
+
// This must run before any adapters are invoked, otherwise the adapter will be
|
|
116
|
+
// undefined (adapter factories need a luvio instance to build adapters)
|
|
117
|
+
function ldsRuntimeLoader(_serviceAPI) {
|
|
118
|
+
setupLuvio();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { ldsRuntimeLoader as default, getRuntime };
|
|
122
|
+
// version: 0.1.0-dev1-54c03dd38c
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { NetworkAdapter } from '@luvio/engine';
|
|
2
|
+
/**
|
|
3
|
+
* A NetworkAdapter HOF that sets location.href to
|
|
4
|
+
* "/login?redirect_uri=<location.origin>/oauth" on 401 responses.
|
|
5
|
+
*/
|
|
6
|
+
export declare function makeNetworkAdapterRedirectToLoginOn401(baseNetworkAdapter: NetworkAdapter): NetworkAdapter;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Luvio, Environment } from '@luvio/engine';
|
|
2
|
+
export interface Runtime {
|
|
3
|
+
luvio: Luvio;
|
|
4
|
+
environment: Environment;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This returns the LDS on Browser Runtime singleton object.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getRuntime(): Runtime;
|
|
10
|
+
export declare function setupLuvio(): void;
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@salesforce/lds-runtime-browser",
|
|
3
|
+
"version": "0.1.0-dev1",
|
|
4
|
+
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
|
+
"description": "LDS runtime for browser environments (depends on IndexedDB and Fetch API).",
|
|
6
|
+
"main": "dist/main.js",
|
|
7
|
+
"module": "dist/main.js",
|
|
8
|
+
"types": "dist/types/main.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/types/main.d.ts",
|
|
15
|
+
"import": "./dist/main.js",
|
|
16
|
+
"default": "./dist/main.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"prepare": "yarn build",
|
|
21
|
+
"build": "rollup --bundleConfigAsCjs --config rollup.config.js",
|
|
22
|
+
"test:debug": "node --inspect-brk ../../node_modules/.bin/jest --runInBand",
|
|
23
|
+
"test:unit": "NODE_ENV=production jest",
|
|
24
|
+
"test:size": "luvioBundlesize",
|
|
25
|
+
"clean": "rm -rf dist",
|
|
26
|
+
"release:corejar": "yarn build && ../core-build/scripts/core.js --name=lds-runtime-browser"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@luvio/durable-store-idb": "0.158.7",
|
|
30
|
+
"@luvio/engine": "0.158.7",
|
|
31
|
+
"@luvio/environments": "0.158.7",
|
|
32
|
+
"@luvio/network-adapter-fetch": "0.158.7",
|
|
33
|
+
"@salesforce/lds-default-luvio": "^0.1.0-dev1",
|
|
34
|
+
"@salesforce/lds-instrumentation": "^0.1.0-dev1",
|
|
35
|
+
"@salesforce/lds-network-adapter": "^0.1.0-dev1"
|
|
36
|
+
},
|
|
37
|
+
"luvioBundlesize": [
|
|
38
|
+
{
|
|
39
|
+
"path": "./dist/main.js",
|
|
40
|
+
"maxSize": {
|
|
41
|
+
"none": "650 kB",
|
|
42
|
+
"min": "255 kB",
|
|
43
|
+
"compressed": "100 kB"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"nx": {
|
|
48
|
+
"targets": {
|
|
49
|
+
"build": {
|
|
50
|
+
"outputs": [
|
|
51
|
+
"{projectRoot}/dist"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"volta": {
|
|
57
|
+
"extends": "../../package.json"
|
|
58
|
+
}
|
|
59
|
+
}
|