@salesforce/lds-runtime-aura 1.306.0 → 1.308.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.
@@ -136,6 +136,48 @@ function buildFetchNetworkCommandBaseClassService() {
136
136
  */
137
137
 
138
138
 
139
+ const LogLevelMap$1 = {
140
+ TRACE: 4,
141
+ DEBUG: 3,
142
+ INFO: 2,
143
+ WARN: 1,
144
+ ERROR: 0,
145
+ };
146
+ /**
147
+ * A simple Logger implementation.
148
+ */
149
+ let ConsoleLogger$1 = class ConsoleLogger {
150
+ constructor(level = 'WARN',
151
+ // eslint-disable-next-line no-console
152
+ printer = console.log, formatter = (level, message) => `${level}: ${message}`) {
153
+ this.level = level;
154
+ this.printer = printer;
155
+ this.formatter = formatter;
156
+ this.messages = [];
157
+ }
158
+ trace(message) {
159
+ this.log('TRACE', message);
160
+ }
161
+ debug(message) {
162
+ this.log('DEBUG', message);
163
+ }
164
+ info(message) {
165
+ this.log('INFO', message);
166
+ }
167
+ warn(message) {
168
+ this.log('WARN', message);
169
+ }
170
+ error(message) {
171
+ this.log('ERROR', message);
172
+ }
173
+ log(level, message) {
174
+ if (LogLevelMap$1[level] > LogLevelMap$1[this.level]) {
175
+ return;
176
+ }
177
+ this.printer(this.formatter(level, message));
178
+ }
179
+ };
180
+
139
181
  function resolvedPromiseLike(result) {
140
182
  // Don't nest anything promise like
141
183
  if (isPromiseOrPromiseLike(result)) {
@@ -1158,7 +1200,7 @@ function buildDefaultTypeRegistryService() {
1158
1200
  * For full license text, see the LICENSE.txt file
1159
1201
  */
1160
1202
 
1161
- function e(e){this.message=e;}e.prototype=new Error,e.prototype.name="InvalidCharacterError";var r="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(r){var t=String(r).replace(/=+$/,"");if(t.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,a=0,i=0,c="";o=t.charAt(i++);~o&&(n=a%4?64*n+o:o,a++%4)?c+=String.fromCharCode(255&n>>(-2*a&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return c};function t(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw "Illegal base64url string!"}try{return function(e){return decodeURIComponent(r(e).replace(/(.)/g,(function(e,r){var t=r.charCodeAt(0).toString(16).toUpperCase();return t.length<2&&(t="0"+t),"%"+t})))}(t)}catch(e){return r(t)}}function n(e){this.message=e;}function o(e,r){if("string"!=typeof e)throw new n("Invalid token specified");var o=!0===(r=r||{}).header?0:1;try{return JSON.parse(t(e.split(".")[o]))}catch(e){throw new n("Invalid token specified: "+e.message)}}n.prototype=new Error,n.prototype.name="InvalidTokenError";
1203
+ function e$1(e){this.message=e;}e$1.prototype=new Error,e$1.prototype.name="InvalidCharacterError";var r$1="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(r){var t=String(r).replace(/=+$/,"");if(t.length%4==1)throw new e$1("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,a=0,i=0,c="";o=t.charAt(i++);~o&&(n=a%4?64*n+o:o,a++%4)?c+=String.fromCharCode(255&n>>(-2*a&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return c};function t$1(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw "Illegal base64url string!"}try{return function(e){return decodeURIComponent(r$1(e).replace(/(.)/g,(function(e,r){var t=r.charCodeAt(0).toString(16).toUpperCase();return t.length<2&&(t="0"+t),"%"+t})))}(t)}catch(e){return r$1(t)}}function n$1(e){this.message=e;}function o$1(e,r){if("string"!=typeof e)throw new n$1("Invalid token specified");var o=!0===(r=r||{}).header?0:1;try{return JSON.parse(t$1(e.split(".")[o]))}catch(e){throw new n$1("Invalid token specified: "+e.message)}}n$1.prototype=new Error,n$1.prototype.name="InvalidTokenError";
1162
1204
 
1163
1205
  /**
1164
1206
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -1298,7 +1340,7 @@ if (process.env.NODE_ENV !== 'production') {
1298
1340
  * @returns An object of decoded JWT token information.
1299
1341
  */
1300
1342
  function computeDecodedInfo(token, defaultTokenTTLInSeconds, logger) {
1301
- const decodedInfo = o(token);
1343
+ const decodedInfo = o$1(token);
1302
1344
  if (decodedInfo.exp === undefined) {
1303
1345
  logger.warn(`"exp" claim is not present in the provided token.`);
1304
1346
  decodedInfo.exp = Date.now() / 1000 + defaultTokenTTLInSeconds;
@@ -1653,17 +1695,29 @@ const composedNetworkAdapter$1 = {
1653
1695
  adapter: sfapNetworkAdapter,
1654
1696
  };
1655
1697
 
1656
- function buildJwtAuthorizedSfapFetchService() {
1698
+ function e(e){this.message=e;}e.prototype=new Error,e.prototype.name="InvalidCharacterError";var r="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(r){var t=String(r).replace(/=+$/,"");if(t.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,a=0,i=0,c="";o=t.charAt(i++);~o&&(n=a%4?64*n+o:o,a++%4)?c+=String.fromCharCode(255&n>>(-2*a&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return c};function t(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw "Illegal base64url string!"}try{return function(e){return decodeURIComponent(r(e).replace(/(.)/g,(function(e,r){var t=r.charCodeAt(0).toString(16).toUpperCase();return t.length<2&&(t="0"+t),"%"+t})))}(t)}catch(e){return r(t)}}function n(e){this.message=e;}function o(e,r){if("string"!=typeof e)throw new n("Invalid token specified");var o=!0===(r=r||{}).header?0:1;try{return JSON.parse(t(e.split(".")[o]))}catch(e){throw new n("Invalid token specified: "+e.message)}}n.prototype=new Error,n.prototype.name="InvalidTokenError";
1699
+
1700
+ const SFAP_BASE_URL = 'api.salesforce.com';
1701
+ function buildJwtAuthorizedSfapFetchService(logger) {
1657
1702
  const jwtRepository = new JwtRepository();
1658
1703
  const jwtManager = new JwtManager(jwtRepository, platformSfapJwtResolver);
1659
1704
  const jwtRequestModifier = ({ baseUri }, [resource, request]) => {
1660
- if (typeof resource !== 'string') {
1705
+ if (typeof resource !== 'string' && !(resource instanceof URL)) {
1661
1706
  // istanbul ignore else: this will not be tested in NODE_ENV = production for test coverage
1662
1707
  if (process.env.NODE_ENV !== 'production') {
1663
- throw new Error('JwtAuthorizedSfapFetchService expects a string path');
1708
+ throw new Error('SFAP fetch service expects a string or URL resource');
1664
1709
  }
1710
+ return [resource, request];
1711
+ }
1712
+ const overrideUrl = new URL(baseUri);
1713
+ const url = typeof resource === 'string' ? new URL(resource) : new URL(resource.toString());
1714
+ if (!(url.host === SFAP_BASE_URL)) {
1715
+ logger.warn(`SFAP fetch service requires that the host of the resource is ${SFAP_BASE_URL}`);
1716
+ return [resource, request];
1665
1717
  }
1666
- return [`${baseUri}${resource}`, request];
1718
+ url.host = overrideUrl.host;
1719
+ url.protocol = overrideUrl.protocol;
1720
+ return [url, request];
1667
1721
  };
1668
1722
  const jwtRequestHeaderInterceptor = buildJwtRequestHeaderInterceptor(jwtManager, jwtRequestModifier);
1669
1723
  const jwtAuthorizedFetchService = buildFetchService({ request: [jwtRequestHeaderInterceptor] });
@@ -1672,6 +1726,51 @@ function buildJwtAuthorizedSfapFetchService() {
1672
1726
  tags: { authenticationScopes: 'sfap_api' },
1673
1727
  };
1674
1728
  }
1729
+ const lightningJwtResolver = {
1730
+ getJwt() {
1731
+ // JWT Manager should be updated to use promise like instead of promise to accomadate use cases like this
1732
+ return resolvedPromiseLike(window.$A.clientService.getJwtAuthToken()).then((jwt) => {
1733
+ const baseUri = o(jwt.jwt).iss;
1734
+ return {
1735
+ jwt: jwt.jwt,
1736
+ extraInfo: { baseUri },
1737
+ };
1738
+ });
1739
+ },
1740
+ };
1741
+ function buildJwtAuthorizedLightningFetchService() {
1742
+ const jwtRepository = new JwtRepository();
1743
+ const jwtManager = new JwtManager(jwtRepository, lightningJwtResolver);
1744
+ const jwtRequestModifier = ({ baseUri }, [resource, request]) => {
1745
+ if (typeof resource !== 'string' && !(resource instanceof URL)) {
1746
+ // istanbul ignore else: this will not be tested in NODE_ENV = production for test coverage
1747
+ if (process.env.NODE_ENV !== 'production') {
1748
+ throw new Error('Lightning fetch service expects a string or URL resource');
1749
+ }
1750
+ return [resource, request];
1751
+ }
1752
+ const url = typeof resource === 'string'
1753
+ ? new URL(resource, 'https://lightning.salesforce.com')
1754
+ : new URL(resource.toString());
1755
+ const overrideUrl = new URL(baseUri);
1756
+ url.host = overrideUrl.host;
1757
+ url.protocol = overrideUrl.protocol;
1758
+ return [url, request];
1759
+ };
1760
+ const jwtRequestHeaderInterceptor = buildJwtRequestHeaderInterceptor(jwtManager, jwtRequestModifier);
1761
+ const jwtAuthorizedFetchService = buildFetchService({ request: [jwtRequestHeaderInterceptor] });
1762
+ return {
1763
+ ...jwtAuthorizedFetchService,
1764
+ tags: { authenticationScopes: 'lightning_api' },
1765
+ };
1766
+ }
1767
+ function buildUnauthorizedFetchService() {
1768
+ const fetchService = buildFetchService();
1769
+ return {
1770
+ ...fetchService,
1771
+ tags: { authenticationScopes: '' },
1772
+ };
1773
+ }
1675
1774
 
1676
1775
  const PDL_EXECUTE_ASYNC_OPTIONS = {
1677
1776
  LOG_ERROR_ONLY: true,
@@ -3924,7 +4023,7 @@ function getEnvironmentSetting(name) {
3924
4023
  }
3925
4024
  return undefined;
3926
4025
  }
3927
- // version: 1.306.0-c047984840
4026
+ // version: 1.308.0-dev1-36d38ba652
3928
4027
 
3929
4028
  const forceRecordTransactionsDisabled = getEnvironmentSetting(EnvironmentSettings.ForceRecordTransactionsDisabled);
3930
4029
  //TODO: Some duplication here that can be most likely moved to a util class
@@ -4423,15 +4522,17 @@ function initializeOneStore() {
4423
4522
  defaultCachePolicyName: 'cache-then-network',
4424
4523
  },
4425
4524
  };
4426
- const jwtAuthorizedSfapFetchService = buildJwtAuthorizedSfapFetchService();
4427
4525
  // TODO [W-1234567]: Export descriptor builder for o11y and noop instrumentaiton
4428
4526
  const instrumentationServiceDescriptor = {
4429
4527
  type: 'instrumentation',
4430
4528
  version: '1.0',
4431
4529
  service: buildNoopInstrumentationService(),
4432
4530
  };
4531
+ const loggerService = new ConsoleLogger$1('ERROR');
4433
4532
  const services = [
4434
- jwtAuthorizedSfapFetchService,
4533
+ buildUnauthorizedFetchService(),
4534
+ buildJwtAuthorizedSfapFetchService(loggerService),
4535
+ buildJwtAuthorizedLightningFetchService(),
4435
4536
  keySubscriptionServiceDescriptor,
4436
4537
  metadataRepositoryServiceDescriptor,
4437
4538
  storeServiceDescriptor,
@@ -4477,4 +4578,4 @@ function ldsEngineCreator() {
4477
4578
  }
4478
4579
 
4479
4580
  export { buildPredictorForContext, ldsEngineCreator as default, initializeLDS, initializeOneStore };
4480
- // version: 1.306.0-66359b439e
4581
+ // version: 1.308.0-dev1-975a2363c7
@@ -1,2 +1,8 @@
1
- import { type PublishedService } from '@luvio/service-broker';
2
- export declare function buildJwtAuthorizedSfapFetchService(): PublishedService;
1
+ import { type FetchServiceDescriptor } from '@luvio/service-fetch-network/v1';
2
+ import { type LoggerService } from '@luvio/utils';
3
+ export declare function buildJwtAuthorizedSfapFetchService(logger: LoggerService): FetchServiceDescriptor;
4
+ export declare const lightningJwtResolver: {
5
+ getJwt(): Promise<any>;
6
+ };
7
+ export declare function buildJwtAuthorizedLightningFetchService(): FetchServiceDescriptor;
8
+ export declare function buildUnauthorizedFetchService(): FetchServiceDescriptor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-aura",
3
- "version": "1.306.0",
3
+ "version": "1.308.0-dev1",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS engine for Aura runtime",
6
6
  "main": "dist/ldsEngineCreator.js",
@@ -35,15 +35,15 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@luvio/service-broker": "5.3.1",
38
- "@salesforce/lds-adapters-apex": "^1.306.0",
39
- "@salesforce/lds-adapters-uiapi": "^1.306.0",
38
+ "@salesforce/lds-adapters-apex": "^1.308.0-dev1",
39
+ "@salesforce/lds-adapters-uiapi": "^1.308.0-dev1",
40
40
  "@salesforce/lds-adapters-uiapi-lex": "^1.302.0",
41
- "@salesforce/lds-ads-bridge": "^1.306.0",
42
- "@salesforce/lds-aura-storage": "^1.306.0",
43
- "@salesforce/lds-bindings": "^1.306.0",
44
- "@salesforce/lds-instrumentation": "^1.306.0",
45
- "@salesforce/lds-network-aura": "^1.306.0",
46
- "@salesforce/lds-network-fetch-with-jwt": "^1.306.0"
41
+ "@salesforce/lds-ads-bridge": "^1.308.0-dev1",
42
+ "@salesforce/lds-aura-storage": "^1.308.0-dev1",
43
+ "@salesforce/lds-bindings": "^1.308.0-dev1",
44
+ "@salesforce/lds-instrumentation": "^1.308.0-dev1",
45
+ "@salesforce/lds-network-aura": "^1.308.0-dev1",
46
+ "@salesforce/lds-network-fetch-with-jwt": "^1.308.0-dev1"
47
47
  },
48
48
  "dependencies": {
49
49
  "@luvio/command-aura-network": "5.3.1",
@@ -64,14 +64,14 @@
64
64
  "@luvio/service-subscription": "5.3.1",
65
65
  "@luvio/service-type-registry": "5.3.1",
66
66
  "@luvio/utils": "5.3.1",
67
- "@salesforce/lds-adapters-uiapi-lex": "^1.306.0"
67
+ "@salesforce/lds-adapters-uiapi-lex": "^1.308.0-dev1"
68
68
  },
69
69
  "luvioBundlesize": [
70
70
  {
71
71
  "path": "./dist/ldsEngineCreator.js",
72
72
  "maxSize": {
73
- "none": "170 kB",
74
- "min": "70 kB",
73
+ "none": "175 kB",
74
+ "min": "75 kB",
75
75
  "compressed": "31 kB"
76
76
  }
77
77
  }