@salesforce/lds-runtime-aura 1.403.0 → 1.404.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.
Files changed (2) hide show
  1. package/dist/ldsEngineCreator.js +119 -196
  2. package/package.json +13 -13
@@ -2666,7 +2666,7 @@ function buildServiceDescriptor$d(luvio) {
2666
2666
  },
2667
2667
  };
2668
2668
  }
2669
- // version: 1.403.0-5476a05446
2669
+ // version: 1.404.0-d0f3b5bc15
2670
2670
 
2671
2671
  /*!
2672
2672
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -3004,7 +3004,7 @@ function buildServiceDescriptor$9(notifyRecordUpdateAvailable, getNormalizedLuvi
3004
3004
  },
3005
3005
  };
3006
3006
  }
3007
- // version: 1.403.0-5476a05446
3007
+ // version: 1.404.0-d0f3b5bc15
3008
3008
 
3009
3009
  /*!
3010
3010
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -4707,7 +4707,7 @@ function getEnvironmentSetting(name) {
4707
4707
  }
4708
4708
  return undefined;
4709
4709
  }
4710
- // version: 1.403.0-5476a05446
4710
+ // version: 1.404.0-d0f3b5bc15
4711
4711
 
4712
4712
  /**
4713
4713
  * Observability / Critical Availability Program (230+)
@@ -5715,195 +5715,6 @@ function buildLexRuntimeLuvio5xxStatusResponseInterceptor() {
5715
5715
  };
5716
5716
  }
5717
5717
 
5718
- const CSRF_TOKEN_KEY = 'salesforce_csrf_token';
5719
- const CSRF_STORAGE_NAME = 'ldsCSRFToken';
5720
- const CSRF_STORAGE_CONFIG = {
5721
- name: CSRF_STORAGE_NAME,
5722
- persistent: true,
5723
- secure: true,
5724
- maxSize: 1024,
5725
- expiration: 24 * 60 * 60,
5726
- clearOnInit: false,
5727
- debugLogging: false,
5728
- };
5729
- /**
5730
- * Manages CSRF token fetching and caching for secure requests.
5731
- * Implements a singleton pattern to ensure consistent token management across the application.
5732
- */
5733
- class CsrfTokenManager {
5734
- constructor() {
5735
- // Initialize AuraStorage
5736
- this.storage = createStorage(CSRF_STORAGE_CONFIG);
5737
- // Try to load token from AuraStorage on initialization
5738
- this.tokenPromise = this.loadOrFetchToken();
5739
- }
5740
- static getInstance() {
5741
- if (!CsrfTokenManager.instance) {
5742
- CsrfTokenManager.instance = new CsrfTokenManager();
5743
- }
5744
- return CsrfTokenManager.instance;
5745
- }
5746
- /**
5747
- * Obtain a CSRF token, either from AuraStorage or by fetching a fresh one.
5748
- *
5749
- * @private
5750
- */
5751
- async loadOrFetchToken() {
5752
- // First try to get token from AuraStorage
5753
- if (this.storage) {
5754
- try {
5755
- const cachedToken = await this.storage.get(CSRF_TOKEN_KEY);
5756
- if (typeof cachedToken === 'string' && cachedToken) {
5757
- return cachedToken;
5758
- }
5759
- }
5760
- catch {
5761
- // If storage read fails, continue to fetch
5762
- }
5763
- }
5764
- // No cached token, fetch from server
5765
- return this.fetchFreshToken();
5766
- }
5767
- /**
5768
- * Call API endpoint to acquire a CSRF token and cache it.
5769
- *
5770
- * @private
5771
- */
5772
- async fetchFreshToken() {
5773
- try {
5774
- const response = await fetch('/session/csrf', {
5775
- method: 'GET',
5776
- credentials: 'same-origin',
5777
- });
5778
- if (!response.ok) {
5779
- return undefined;
5780
- }
5781
- const data = await response.json();
5782
- const token = data.csrfToken;
5783
- if (token && this.storage) {
5784
- // Cache the token in AuraStorage
5785
- try {
5786
- await this.storage.set(CSRF_TOKEN_KEY, token);
5787
- }
5788
- catch {
5789
- // Non-fatal: token is still available even if caching fails
5790
- }
5791
- }
5792
- return token;
5793
- }
5794
- catch {
5795
- return undefined;
5796
- }
5797
- }
5798
- /**
5799
- * Returns the current token value as a Promise.
5800
- */
5801
- async getToken() {
5802
- return this.tokenPromise;
5803
- }
5804
- /**
5805
- * Obtains and returns a new token value as a promise.
5806
- * This will clear the cached token and fetch a fresh one.
5807
- */
5808
- async refreshToken() {
5809
- // Clear cached token
5810
- if (this.storage) {
5811
- try {
5812
- await this.storage.remove(CSRF_TOKEN_KEY);
5813
- }
5814
- catch {
5815
- // Non-fatal: continue with refresh even if clear fails
5816
- }
5817
- }
5818
- // Fetch (and cache) fresh token
5819
- this.tokenPromise = this.fetchFreshToken();
5820
- return this.tokenPromise;
5821
- }
5822
- /**
5823
- * Reset the singleton instance (useful for testing).
5824
- * @internal
5825
- */
5826
- static resetInstance() {
5827
- CsrfTokenManager.instance = null;
5828
- }
5829
- }
5830
- CsrfTokenManager.instance = null;
5831
-
5832
- const CSRF_TOKEN_HEADER = 'X-CSRF-Token';
5833
- /**
5834
- * Determines if the HTTP method requires CSRF protection.
5835
- * Only mutating operations (POST, PUT, PATCH, DELETE) require CSRF tokens.
5836
- *
5837
- * @param method - The HTTP method to check
5838
- * @returns true if the method requires CSRF protection
5839
- */
5840
- function isCsrfMethod(method) {
5841
- if (!method) {
5842
- return false;
5843
- }
5844
- const normalizedMethod = method.toLowerCase();
5845
- return (normalizedMethod === 'post' ||
5846
- normalizedMethod === 'put' ||
5847
- normalizedMethod === 'patch' ||
5848
- normalizedMethod === 'delete');
5849
- }
5850
- /**
5851
- * Builds a request interceptor that adds CSRF token headers to mutating requests.
5852
- * The CSRF token is fetched once and cached for subsequent requests.
5853
- * Only POST, PUT, PATCH, and DELETE requests will have the CSRF token added.
5854
- *
5855
- * @returns A RequestInterceptor function for FetchParameters
5856
- */
5857
- function buildCsrfTokenInterceptor() {
5858
- const csrfTokenManager = CsrfTokenManager.getInstance();
5859
- return async (fetchArgs) => {
5860
- const [urlOrRequest, options] = fetchArgs;
5861
- // Determine the method from either Request object or options
5862
- let method;
5863
- if (typeof urlOrRequest !== 'string' && 'method' in urlOrRequest) {
5864
- method = urlOrRequest.method;
5865
- }
5866
- else if (options && 'method' in options) {
5867
- method = options.method;
5868
- }
5869
- // Only add CSRF token for mutating operations
5870
- if (isCsrfMethod(method)) {
5871
- const token = await csrfTokenManager.getToken();
5872
- if (token) {
5873
- fetchArgs = setHeader(CSRF_TOKEN_HEADER, token, fetchArgs);
5874
- }
5875
- }
5876
- return resolvedPromiseLike$2(fetchArgs);
5877
- };
5878
- }
5879
- /**
5880
- * Builds a Luvio request interceptor that adds CSRF token headers to mutating requests.
5881
- * The CSRF token is fetched once and cached for subsequent requests.
5882
- * Only POST, PUT, PATCH, and DELETE requests will have the CSRF token added.
5883
- *
5884
- * @returns A request interceptor function for Luvio ResourceRequest objects
5885
- */
5886
- function buildLuvioCsrfTokenInterceptor() {
5887
- const csrfTokenManager = CsrfTokenManager.getInstance();
5888
- return async (resourceRequest) => {
5889
- // Ensure headers object exists
5890
- if (!resourceRequest.headers) {
5891
- resourceRequest.headers = {};
5892
- }
5893
- // Only add CSRF token for mutating operations
5894
- if (isCsrfMethod(resourceRequest.method)) {
5895
- // Don't overwrite existing CSRF token header if it already exists
5896
- if (!resourceRequest.headers[CSRF_TOKEN_HEADER]) {
5897
- const token = await csrfTokenManager.getToken();
5898
- if (token) {
5899
- resourceRequest.headers[CSRF_TOKEN_HEADER] = token;
5900
- }
5901
- }
5902
- }
5903
- return resolvedPromiseLike$2(resourceRequest);
5904
- };
5905
- }
5906
-
5907
5718
  const API_PATHS = [
5908
5719
  // getLookupActions
5909
5720
  // '/ui-api/actions/lookup/{objectApiNames}',
@@ -5965,7 +5776,7 @@ const composedFetchNetworkAdapter = {
5965
5776
  return API_PATH_MATCHERS.some((matcher) => matcher.test(path));
5966
5777
  },
5967
5778
  adapter: setupLexNetworkAdapter(requestTracker, requestLogger, {
5968
- request: [buildLuvioPageScopedCacheRequestInterceptor(), buildLuvioCsrfTokenInterceptor()],
5779
+ request: [buildLuvioPageScopedCacheRequestInterceptor()],
5969
5780
  response: [
5970
5781
  buildLexRuntimeLuvio5xxStatusResponseInterceptor(),
5971
5782
  buildLexRuntimeLuvioAuthExpirationRedirectResponseInterceptor(),
@@ -6044,6 +5855,120 @@ function buildTransportMarksReceiveInterceptor() {
6044
5855
  };
6045
5856
  }
6046
5857
 
5858
+ const CSRF_TOKEN_KEY = 'salesforce_csrf_token';
5859
+ const CSRF_STORAGE_NAME = 'ldsCSRFToken';
5860
+ const CSRF_STORAGE_CONFIG = {
5861
+ name: CSRF_STORAGE_NAME,
5862
+ persistent: true,
5863
+ secure: true,
5864
+ maxSize: 1024,
5865
+ expiration: 24 * 60 * 60,
5866
+ clearOnInit: false,
5867
+ debugLogging: false,
5868
+ };
5869
+ /**
5870
+ * Manages CSRF token fetching and caching for secure requests.
5871
+ * Implements a singleton pattern to ensure consistent token management across the application.
5872
+ */
5873
+ class CsrfTokenManager {
5874
+ constructor() {
5875
+ // Initialize AuraStorage
5876
+ this.storage = createStorage(CSRF_STORAGE_CONFIG);
5877
+ // Try to load token from AuraStorage on initialization
5878
+ this.tokenPromise = this.loadOrFetchToken();
5879
+ }
5880
+ static getInstance() {
5881
+ if (!CsrfTokenManager.instance) {
5882
+ CsrfTokenManager.instance = new CsrfTokenManager();
5883
+ }
5884
+ return CsrfTokenManager.instance;
5885
+ }
5886
+ /**
5887
+ * Obtain a CSRF token, either from AuraStorage or by fetching a fresh one.
5888
+ *
5889
+ * @private
5890
+ */
5891
+ async loadOrFetchToken() {
5892
+ // First try to get token from AuraStorage
5893
+ if (this.storage) {
5894
+ try {
5895
+ const cachedToken = await this.storage.get(CSRF_TOKEN_KEY);
5896
+ if (typeof cachedToken === 'string' && cachedToken) {
5897
+ return cachedToken;
5898
+ }
5899
+ }
5900
+ catch {
5901
+ // If storage read fails, continue to fetch
5902
+ }
5903
+ }
5904
+ // No cached token, fetch from server
5905
+ return this.fetchFreshToken();
5906
+ }
5907
+ /**
5908
+ * Call API endpoint to acquire a CSRF token and cache it.
5909
+ *
5910
+ * @private
5911
+ */
5912
+ async fetchFreshToken() {
5913
+ try {
5914
+ const response = await fetch('/session/csrf', {
5915
+ method: 'GET',
5916
+ credentials: 'same-origin',
5917
+ });
5918
+ if (!response.ok) {
5919
+ return undefined;
5920
+ }
5921
+ const data = await response.json();
5922
+ const token = data.csrfToken;
5923
+ if (token && this.storage) {
5924
+ // Cache the token in AuraStorage
5925
+ try {
5926
+ await this.storage.set(CSRF_TOKEN_KEY, token);
5927
+ }
5928
+ catch {
5929
+ // Non-fatal: token is still available even if caching fails
5930
+ }
5931
+ }
5932
+ return token;
5933
+ }
5934
+ catch {
5935
+ return undefined;
5936
+ }
5937
+ }
5938
+ /**
5939
+ * Returns the current token value as a Promise.
5940
+ */
5941
+ async getToken() {
5942
+ return this.tokenPromise;
5943
+ }
5944
+ /**
5945
+ * Obtains and returns a new token value as a promise.
5946
+ * This will clear the cached token and fetch a fresh one.
5947
+ */
5948
+ async refreshToken() {
5949
+ // Clear cached token
5950
+ if (this.storage) {
5951
+ try {
5952
+ await this.storage.remove(CSRF_TOKEN_KEY);
5953
+ }
5954
+ catch {
5955
+ // Non-fatal: continue with refresh even if clear fails
5956
+ }
5957
+ }
5958
+ // Fetch (and cache) fresh token
5959
+ this.tokenPromise = this.fetchFreshToken();
5960
+ return this.tokenPromise;
5961
+ }
5962
+ /**
5963
+ * Reset the singleton instance (useful for testing).
5964
+ * @internal
5965
+ */
5966
+ static resetInstance() {
5967
+ CsrfTokenManager.instance = null;
5968
+ }
5969
+ }
5970
+ CsrfTokenManager.instance = null;
5971
+
6047
5972
  const DEFAULT_CONFIG$1 = {
6048
5973
  maxRetries: 1, // Only retry once after token refresh
6049
5974
  };
@@ -6152,7 +6077,6 @@ function buildLexRuntimeDefaultFetchServiceDescriptor(logger, retryService) {
6152
6077
  buildThirdPartyTrackerRegisterInterceptor(),
6153
6078
  buildPageScopedCacheRequestInterceptor(),
6154
6079
  buildTransportMarksSendInterceptor(),
6155
- buildCsrfTokenInterceptor(),
6156
6080
  ],
6157
6081
  response: [
6158
6082
  buildLexRuntime5xxStatusResponseInterceptor(logger),
@@ -6174,7 +6098,6 @@ function buildLexRuntimeAllow5xxFetchServiceDescriptor(logger, retryService) {
6174
6098
  buildThirdPartyTrackerRegisterInterceptor(),
6175
6099
  buildPageScopedCacheRequestInterceptor(),
6176
6100
  buildTransportMarksSendInterceptor(),
6177
- buildCsrfTokenInterceptor(),
6178
6101
  ],
6179
6102
  response: [buildLexRuntimeAuthExpirationRedirectResponseInterceptor(logger)],
6180
6103
  finally: [
@@ -9781,4 +9704,4 @@ function ldsEngineCreator() {
9781
9704
  }
9782
9705
 
9783
9706
  export { LexRequestStrategy, PdlRequestPriority, buildPredictorForContext, ldsEngineCreator as default, initializeLDS, initializeOneStore, notifyUpdateAvailableFactory, registerRequestStrategy, saveRequestAsPrediction, unregisterRequestStrategy, whenPredictionsReady };
9784
- // version: 1.403.0-bc09fbc54b
9707
+ // version: 1.404.0-fa9e7b68e4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-aura",
3
- "version": "1.403.0",
3
+ "version": "1.404.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS engine for Aura runtime",
6
6
  "main": "dist/ldsEngineCreator.js",
@@ -36,14 +36,14 @@
36
36
  "devDependencies": {
37
37
  "@conduit-client/service-provisioner": "3.2.0",
38
38
  "@conduit-client/tools-core": "3.2.0",
39
- "@salesforce/lds-adapters-apex": "^1.403.0",
40
- "@salesforce/lds-adapters-uiapi": "^1.403.0",
41
- "@salesforce/lds-ads-bridge": "^1.403.0",
42
- "@salesforce/lds-aura-storage": "^1.403.0",
43
- "@salesforce/lds-bindings": "^1.403.0",
44
- "@salesforce/lds-instrumentation": "^1.403.0",
45
- "@salesforce/lds-network-aura": "^1.403.0",
46
- "@salesforce/lds-network-fetch": "^1.403.0",
39
+ "@salesforce/lds-adapters-apex": "^1.404.0",
40
+ "@salesforce/lds-adapters-uiapi": "^1.404.0",
41
+ "@salesforce/lds-ads-bridge": "^1.404.0",
42
+ "@salesforce/lds-aura-storage": "^1.404.0",
43
+ "@salesforce/lds-bindings": "^1.404.0",
44
+ "@salesforce/lds-instrumentation": "^1.404.0",
45
+ "@salesforce/lds-network-aura": "^1.404.0",
46
+ "@salesforce/lds-network-fetch": "^1.404.0",
47
47
  "jwt-encode": "1.0.1"
48
48
  },
49
49
  "dependencies": {
@@ -71,10 +71,10 @@
71
71
  "@luvio/network-adapter-composable": "0.158.7",
72
72
  "@luvio/network-adapter-fetch": "0.158.7",
73
73
  "@lwc/state": "^0.23.0",
74
- "@salesforce/lds-adapters-onestore-graphql": "^1.403.0",
75
- "@salesforce/lds-adapters-uiapi-lex": "^1.403.0",
76
- "@salesforce/lds-luvio-service": "^1.403.0",
77
- "@salesforce/lds-luvio-uiapi-records-service": "^1.403.0"
74
+ "@salesforce/lds-adapters-onestore-graphql": "^1.404.0",
75
+ "@salesforce/lds-adapters-uiapi-lex": "^1.404.0",
76
+ "@salesforce/lds-luvio-service": "^1.404.0",
77
+ "@salesforce/lds-luvio-uiapi-records-service": "^1.404.0"
78
78
  },
79
79
  "luvioBundlesize": [
80
80
  {