@salesforce/lds-runtime-aura 1.322.0 → 1.323.0

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.
@@ -1215,6 +1215,35 @@ function buildServiceDescriptor$1(cache) {
1215
1215
  };
1216
1216
  }
1217
1217
 
1218
+ /**
1219
+ * Copyright (c) 2022, Salesforce, Inc.,
1220
+ * All rights reserved.
1221
+ * For full license text, see the LICENSE.txt file
1222
+ */
1223
+
1224
+ /**
1225
+ * Most-recently set of published services.
1226
+ */
1227
+ let servicesAvailable;
1228
+ new Promise((resolve) => (servicesAvailable = resolve));
1229
+ /**
1230
+ * Sets the services that will be used to satisfy calls to getServices().
1231
+ * Any previously registered services are replaced with the services provided.
1232
+ * Note overwriting services should be done with great care as previous callers
1233
+ * of getServices() will not be aware of the new services.
1234
+ *
1235
+ * The default implementation provided by this module only supports a single
1236
+ * set of active services. Runtime environments that require multiple sets of
1237
+ * active services will need to override this module with their own
1238
+ * implementation.
1239
+
1240
+ * @param services services to be used to satisfy future getServices() requests
1241
+ */
1242
+ function setServices(services) {
1243
+ resolvedPromiseLike(services);
1244
+ servicesAvailable(services);
1245
+ }
1246
+
1218
1247
  /**
1219
1248
  * Copyright (c) 2022, Salesforce, Inc.,
1220
1249
  * All rights reserved.
@@ -1722,27 +1751,8 @@ const SFAP_BASE_URL = 'api.salesforce.com';
1722
1751
  const sfapJwtRepository = new JwtRepository();
1723
1752
  const sfapJwtManager = new JwtManager(sfapJwtRepository, platformSfapJwtResolver);
1724
1753
  function buildJwtAuthorizedSfapFetchServiceDescriptor(logger) {
1725
- const jwtRequestModifier = ({ baseUri }, [resource, request]) => {
1726
- if (typeof resource !== 'string' && !(resource instanceof URL)) {
1727
- // istanbul ignore else: this will not be tested in NODE_ENV = production for test coverage
1728
- if (process.env.NODE_ENV !== 'production') {
1729
- throw new Error('SFAP fetch service expects a string or URL resource');
1730
- }
1731
- return [resource, request];
1732
- }
1733
- const overrideUrl = new URL(baseUri);
1734
- const url = typeof resource === 'string' ? new URL(resource) : new URL(resource.toString());
1735
- if (!(url.host === SFAP_BASE_URL)) {
1736
- logger.warn(`SFAP fetch service requires that the host of the resource is ${SFAP_BASE_URL}`);
1737
- return [resource, request];
1738
- }
1739
- url.host = overrideUrl.host;
1740
- url.protocol = overrideUrl.protocol;
1741
- return [url, request];
1742
- };
1743
- const jwtRequestHeaderInterceptor = buildJwtRequestHeaderInterceptor(sfapJwtManager, jwtRequestModifier);
1744
1754
  const jwtAuthorizedFetchService = buildServiceDescriptor({
1745
- request: [jwtRequestHeaderInterceptor],
1755
+ request: [buildJwtRequestInterceptor(logger)],
1746
1756
  });
1747
1757
  return {
1748
1758
  ...jwtAuthorizedFetchService,
@@ -1779,10 +1789,13 @@ function buildCopilotFetchServiceDescriptor(logger) {
1779
1789
  return resolvedPromiseLike(sfapJwtManager.getJwt()).then((token) => {
1780
1790
  // replace the body's instanceConfig.endpoint with the JWT's iss value
1781
1791
  const body = JSON.parse(requestInit.body);
1782
- if (!body || !body.instanceConfig || !token.decodedInfo.iss) {
1792
+ if (!body || !token.decodedInfo || !token.decodedInfo.iss) {
1783
1793
  logger.warn('skipping injection of endpoint into start session request');
1784
1794
  }
1785
1795
  else {
1796
+ if (!body.instanceConfig) {
1797
+ body.instanceConfig = {};
1798
+ }
1786
1799
  body.instanceConfig.endpoint = token.decodedInfo.iss;
1787
1800
  }
1788
1801
  return [
@@ -1794,6 +1807,7 @@ function buildCopilotFetchServiceDescriptor(logger) {
1794
1807
  ];
1795
1808
  });
1796
1809
  },
1810
+ buildJwtRequestInterceptor(logger),
1797
1811
  ],
1798
1812
  }),
1799
1813
  tags: { specialHacksFor: 'copilot' },
@@ -1806,6 +1820,28 @@ function buildUnauthorizedFetchServiceDescriptor() {
1806
1820
  tags: { authenticationScopes: '' },
1807
1821
  };
1808
1822
  }
1823
+ function buildJwtRequestInterceptor(logger) {
1824
+ const jwtRequestModifier = ({ baseUri }, [resource, request]) => {
1825
+ if (typeof resource !== 'string' && !(resource instanceof URL)) {
1826
+ // istanbul ignore else: this will not be tested in NODE_ENV = production for test coverage
1827
+ if (process.env.NODE_ENV !== 'production') {
1828
+ throw new Error('SFAP fetch service expects a string or URL resource');
1829
+ }
1830
+ return [resource, request];
1831
+ }
1832
+ const overrideUrl = new URL(baseUri);
1833
+ const url = typeof resource === 'string' ? new URL(resource) : new URL(resource.toString());
1834
+ if (!(url.host === SFAP_BASE_URL)) {
1835
+ logger.warn(`SFAP fetch service requires that the host of the resource is ${SFAP_BASE_URL}`);
1836
+ return [resource, request];
1837
+ }
1838
+ url.host = overrideUrl.host;
1839
+ url.protocol = overrideUrl.protocol;
1840
+ return [url, request];
1841
+ };
1842
+ const jwtRequestHeaderInterceptor = buildJwtRequestHeaderInterceptor(sfapJwtManager, jwtRequestModifier);
1843
+ return jwtRequestHeaderInterceptor;
1844
+ }
1809
1845
 
1810
1846
  const PDL_EXECUTE_ASYNC_OPTIONS = {
1811
1847
  LOG_ERROR_ONLY: true,
@@ -1853,7 +1889,17 @@ const { create, keys, hasOwnProperty, entries } = Object;
1853
1889
  const { isArray, from } = Array;
1854
1890
  const { stringify } = JSON;
1855
1891
 
1892
+ // Note: exported enum for core usage.
1893
+ var PdlRequestPriority;
1894
+ (function (PdlRequestPriority) {
1895
+ PdlRequestPriority[PdlRequestPriority["LOW"] = 0] = "LOW";
1896
+ PdlRequestPriority[PdlRequestPriority["NORMAL"] = 1] = "NORMAL";
1897
+ PdlRequestPriority[PdlRequestPriority["HIGH"] = 2] = "HIGH";
1898
+ })(PdlRequestPriority || (PdlRequestPriority = {}));
1856
1899
  class RequestStrategy {
1900
+ getRequestPriority(_request, _context) {
1901
+ return 1 /* RequestPriority.NORMAL */;
1902
+ }
1857
1903
  /**
1858
1904
  * Perform any transformations required to prepare the request for saving.
1859
1905
  *
@@ -4065,6 +4111,39 @@ async function runRequestsWithLimit(requests, runner, concurrentRequestsLimit, p
4065
4111
  // Wait for all initial requests to complete
4066
4112
  await Promise.all(promises);
4067
4113
  }
4114
+ /**
4115
+ * Compares two request entries based on their priority and, if the priorities are the same, their request times.
4116
+ * This function is typically used for sorting requests where priority takes precedence, and timing is used
4117
+ * as a secondary criterion. The function assumes that any necessary filtering of requests has already been done.
4118
+ *
4119
+ * @template Context - Extends `DefaultPageContext`, provides additional context for the request priority determination.
4120
+ *
4121
+ * @param {RequestEntry<LexRequest>} requestA - The first request entry containing the request and its metadata.
4122
+ * @param {RequestEntry<LexRequest>} requestB - The second request entry containing the request and its metadata.
4123
+ * @param {RequestStrategyManager} requestStrategyManager - Manager that provides access to request strategies based on adapter names.
4124
+ * @param {Context} context - The context in which the requests are being compared, used to determine request priority.
4125
+ *
4126
+ * @returns {number} A negative number if the first request should come before the second, a positive number if the
4127
+ * second should come before the first, or zero if they are considered equal for sorting purposes.
4128
+ * This is determined first by the priority (higher priority comes first) and then by the request
4129
+ * time (earlier request comes first) if priorities are the same. The priorities are fetched from
4130
+ * the `requestStrategyManager` for each request's `adapterName`. If a strategy is not found,
4131
+ * the priority defaults to `RequestPriority.LOW`.
4132
+ */
4133
+ function compareByPriorityThenTime({ request: requestA, requestMetadata: requestMetadataA }, { request: requestB, requestMetadata: requestMetadataB }, requestStrategyManager, context) {
4134
+ const aPriority = requestStrategyManager.get(requestA.adapterName)?.getRequestPriority(requestA, context) ||
4135
+ 0 /* RequestPriority.LOW */;
4136
+ const bPriority = requestStrategyManager.get(requestB.adapterName)?.getRequestPriority(requestB, context) ||
4137
+ 0 /* RequestPriority.LOW */;
4138
+ if (aPriority === bPriority) {
4139
+ // when both requests have the same priority, use the request time in waterfall.
4140
+ return requestMetadataA.requestTime - requestMetadataB.requestTime;
4141
+ }
4142
+ else {
4143
+ // sort by priority, descending
4144
+ return bPriority - aPriority;
4145
+ }
4146
+ }
4068
4147
 
4069
4148
  function isBoxcarableRequest({ request: { adapterName } }, requestStrategyManager) {
4070
4149
  const strategy = requestStrategyManager.get(adapterName);
@@ -4117,20 +4196,22 @@ class LexPredictivePrefetcher extends ApplicationPredictivePrefetcher {
4117
4196
  return [...exactPageRequests, ...similarPageRequests];
4118
4197
  }
4119
4198
  async predict() {
4199
+ // perf: caching access, to avoid this.prop in loops.
4200
+ const { requestStrategyManager, context } = this;
4120
4201
  const alwaysRequests = this.page.getAlwaysRunRequests();
4121
4202
  const pageRequests = this.getAllPageRequests();
4122
4203
  // IMPORTANT: Because there's no way to differentiate a cmpDef prediction from the page
4123
4204
  // requesting the cmpDef, we need to predict cmpDefs before we start watching
4124
4205
  // for predictions in the page. Having this code after an
4125
4206
  // await will make the predictions to be saved as predictions too.
4126
- predictNonBoxcarableRequest(pageRequests.filter((r) => !isBoxcarableRequest(r, this.requestStrategyManager)), this.requestRunner);
4207
+ predictNonBoxcarableRequest(pageRequests.filter((r) => !isBoxcarableRequest(r, requestStrategyManager)), this.requestRunner);
4127
4208
  const alwaysRequestEntries = alwaysRequests.map((request) => {
4128
4209
  return {
4129
4210
  request,
4130
4211
  requestMetadata: { requestTime: 0 }, // ensures always requests are executed, and executed first.
4131
4212
  };
4132
4213
  });
4133
- const boxcarablePredictions = pageRequests.filter((r) => isBoxcarableRequest(r, this.requestStrategyManager));
4214
+ const boxcarablePredictions = pageRequests.filter((r) => isBoxcarableRequest(r, requestStrategyManager));
4134
4215
  const reducedPredictions = this.page.shouldReduceAlwaysRequestsWithPredictions()
4135
4216
  ? this.requestRunner.reduceRequests([...boxcarablePredictions, ...alwaysRequestEntries])
4136
4217
  : this.requestRunner.reduceRequests(boxcarablePredictions);
@@ -4138,7 +4219,7 @@ class LexPredictivePrefetcher extends ApplicationPredictivePrefetcher {
4138
4219
  ? [...alwaysRequestEntries, ...reducedPredictions]
4139
4220
  : reducedPredictions)
4140
4221
  // Sorting in order requested
4141
- .sort((a, b) => a.requestMetadata.requestTime - b.requestMetadata.requestTime);
4222
+ .sort((a, b) => compareByPriorityThenTime(a, b, requestStrategyManager, context));
4142
4223
  this.totalRequestCount = predictedRequestsWithLimit.length;
4143
4224
  await runRequestsWithLimit(predictedRequestsWithLimit, this.requestRunner, this.options.inflightRequestLimit,
4144
4225
  // `this.repository.pageStartTime` would be the correct here,
@@ -4296,7 +4377,7 @@ function getEnvironmentSetting(name) {
4296
4377
  }
4297
4378
  return undefined;
4298
4379
  }
4299
- // version: 1.322.0-87f682c9f3
4380
+ // version: 1.323.0-34d96539ec
4300
4381
 
4301
4382
  const forceRecordTransactionsDisabled = getEnvironmentSetting(EnvironmentSettings.ForceRecordTransactionsDisabled);
4302
4383
  //TODO: Some duplication here that can be most likely moved to a util class
@@ -4971,6 +5052,7 @@ function initializeOneStore() {
4971
5052
  buildServiceDescriptor$8(),
4972
5053
  ];
4973
5054
  serviceBroker.publish(services);
5055
+ setServices(services);
4974
5056
  }
4975
5057
  function initializeOnestoreUiApiAdapters() {
4976
5058
  configuration.setGetObjectInfoAdapter(getObjectInfo);
@@ -4996,5 +5078,5 @@ function ldsEngineCreator() {
4996
5078
  return { name: 'ldsEngineCreator' };
4997
5079
  }
4998
5080
 
4999
- export { LexRequestStrategy, buildPredictorForContext, ldsEngineCreator as default, initializeLDS, initializeOneStore, registerRequestStrategy, saveRequestAsPrediction, unregisterRequestStrategy, whenPredictionsReady };
5000
- // version: 1.322.0-6aa042602a
5081
+ export { LexRequestStrategy, PdlRequestPriority, buildPredictorForContext, ldsEngineCreator as default, initializeLDS, initializeOneStore, registerRequestStrategy, saveRequestAsPrediction, unregisterRequestStrategy, whenPredictionsReady };
5082
+ // version: 1.323.0-ddaba12fc0
@@ -1,6 +1,7 @@
1
1
  import { type RecordHomePageContext } from './predictive-loading';
2
2
  import type { LexRequestStrategy } from './predictive-loading/request-strategy/lex-request-strategy';
3
3
  import { type LexRequest } from './predictive-loading/lex';
4
+ export { PdlRequestPriority } from './predictive-loading';
4
5
  export { LexRequestStrategy } from './predictive-loading/request-strategy/lex-request-strategy';
5
6
  /**
6
7
  * Registers a request strategy to be utilized by PDL.
@@ -1,5 +1,8 @@
1
1
  import type { RequestRunner } from '../request-runner';
2
2
  import type { RequestEntry } from '../common';
3
+ import type { LexRequest } from '../lex';
4
+ import type { RequestStrategyManager } from '../request-strategy-manager/request-strategy-manager';
5
+ import type { DefaultPageContext } from '../pages';
3
6
  /**
4
7
  * Runs a list of requests with a specified concurrency limit.
5
8
  *
@@ -14,3 +17,23 @@ import type { RequestEntry } from '../common';
14
17
  * Requests are only processed if their `requestTime` is less than the time elapsed since `pageStartTime`.
15
18
  */
16
19
  export declare function runRequestsWithLimit<Request>(requests: RequestEntry<Request>[], runner: RequestRunner<Request>, concurrentRequestsLimit: number, pageStartTime: number): Promise<void>;
20
+ /**
21
+ * Compares two request entries based on their priority and, if the priorities are the same, their request times.
22
+ * This function is typically used for sorting requests where priority takes precedence, and timing is used
23
+ * as a secondary criterion. The function assumes that any necessary filtering of requests has already been done.
24
+ *
25
+ * @template Context - Extends `DefaultPageContext`, provides additional context for the request priority determination.
26
+ *
27
+ * @param {RequestEntry<LexRequest>} requestA - The first request entry containing the request and its metadata.
28
+ * @param {RequestEntry<LexRequest>} requestB - The second request entry containing the request and its metadata.
29
+ * @param {RequestStrategyManager} requestStrategyManager - Manager that provides access to request strategies based on adapter names.
30
+ * @param {Context} context - The context in which the requests are being compared, used to determine request priority.
31
+ *
32
+ * @returns {number} A negative number if the first request should come before the second, a positive number if the
33
+ * second should come before the first, or zero if they are considered equal for sorting purposes.
34
+ * This is determined first by the priority (higher priority comes first) and then by the request
35
+ * time (earlier request comes first) if priorities are the same. The priorities are fetched from
36
+ * the `requestStrategyManager` for each request's `adapterName`. If a strategy is not found,
37
+ * the priority defaults to `RequestPriority.LOW`.
38
+ */
39
+ export declare function compareByPriorityThenTime<Context extends DefaultPageContext = DefaultPageContext>({ request: requestA, requestMetadata: requestMetadataA }: RequestEntry<LexRequest>, { request: requestB, requestMetadata: requestMetadataB }: RequestEntry<LexRequest>, requestStrategyManager: RequestStrategyManager, context: Context): number;
@@ -3,6 +3,16 @@ export type BaseAdapterRequest<Config = unknown> = {
3
3
  adapterName: string;
4
4
  config: Config;
5
5
  };
6
+ export declare const enum RequestPriority {
7
+ LOW = 0,
8
+ NORMAL = 1,
9
+ HIGH = 2
10
+ }
11
+ export declare enum PdlRequestPriority {
12
+ LOW = 0,
13
+ NORMAL = 1,
14
+ HIGH = 2
15
+ }
6
16
  export declare abstract class RequestStrategy<Config, Request extends BaseAdapterRequest<Config>, Context> {
7
17
  /**
8
18
  * Name of the adapter used in this strategy.
@@ -10,6 +20,7 @@ export declare abstract class RequestStrategy<Config, Request extends BaseAdapte
10
20
  abstract adapterName: string;
11
21
  abstract execute(config: Config): any;
12
22
  abstract buildConcreteRequest(similarRequest: Request, context: Context): Request;
23
+ getRequestPriority(_request: Request, _context: Context): RequestPriority;
13
24
  /**
14
25
  * Perform any transformations required to prepare the request for saving.
15
26
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-aura",
3
- "version": "1.322.0",
3
+ "version": "1.323.0",
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,17 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@luvio/service-broker": "5.13.0",
38
- "@salesforce/lds-adapters-apex": "^1.322.0",
39
- "@salesforce/lds-adapters-uiapi": "^1.322.0",
38
+ "@luvio/service-provisioner": "5.13.0",
39
+ "@salesforce/lds-adapters-apex": "^1.323.0",
40
+ "@salesforce/lds-adapters-uiapi": "^1.323.0",
40
41
  "@salesforce/lds-adapters-uiapi-lex": "^1.302.0",
41
- "@salesforce/lds-ads-bridge": "^1.322.0",
42
- "@salesforce/lds-aura-storage": "^1.322.0",
43
- "@salesforce/lds-bindings": "^1.322.0",
44
- "@salesforce/lds-instrumentation": "^1.322.0",
45
- "@salesforce/lds-network-aura": "^1.322.0",
46
- "@salesforce/lds-network-fetch-with-jwt": "^1.322.0"
42
+ "@salesforce/lds-ads-bridge": "^1.323.0",
43
+ "@salesforce/lds-aura-storage": "^1.323.0",
44
+ "@salesforce/lds-bindings": "^1.323.0",
45
+ "@salesforce/lds-instrumentation": "^1.323.0",
46
+ "@salesforce/lds-network-aura": "^1.323.0",
47
+ "@salesforce/lds-network-fetch-with-jwt": "^1.323.0",
48
+ "jwt-encode": "1.0.1"
47
49
  },
48
50
  "dependencies": {
49
51
  "@luvio/command-aura-network": "5.13.0",
@@ -61,7 +63,7 @@
61
63
  "@luvio/service-instrument-command": "5.13.0",
62
64
  "@luvio/service-store": "5.13.0",
63
65
  "@luvio/utils": "5.13.0",
64
- "@salesforce/lds-adapters-uiapi-lex": "^1.322.0"
66
+ "@salesforce/lds-adapters-uiapi-lex": "^1.323.0"
65
67
  },
66
68
  "luvioBundlesize": [
67
69
  {