@salesforce/lds-runtime-webruntime 1.370.0 → 1.371.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.
@@ -15,8 +15,11 @@
15
15
  import { getInstrumentation } from 'o11y/client';
16
16
  import { setServices } from 'force/luvioServiceProvisioner1';
17
17
  export { default, resolve, setServices } from 'force/luvioServiceProvisioner1';
18
- import { executeGlobalControllerRawResponse } from 'aura';
19
18
  import { getSfapJwt } from 'force/clwrSfapExchange';
19
+ import language from '@salesforce/i18n/lang';
20
+ import isDesignMode from '@app/isDesignMode';
21
+ import isPreviewMode from '@app/isPreviewMode';
22
+ import authenticationCookieName from '@app/authenticationCookieName';
20
23
 
21
24
  /*!
22
25
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -2811,6 +2814,75 @@ const platformSfapJwtResolver = {
2811
2814
  },
2812
2815
  };
2813
2816
 
2817
+ const METHODS_WITH_CSRF = ['POST', 'PATCH', 'PUT', 'DELETE'];
2818
+ /**
2819
+ * Webruntime request interceptor that modifies outgoing HTTP requests with standard
2820
+ * query parameters and security headers. This ensures the api calls for onestore adapters
2821
+ * follow the same pattern as the equivalent luvio api calls for all CLWR endpoints.
2822
+ *
2823
+ * This interceptor:
2824
+ * - Adds language query parameter from i18n settings
2825
+ * - Adds asGuest parameter based on design/preview mode and SID cookie presence
2826
+ * - Adds htmlEncode=false query parameter (since this is an api call by definition)
2827
+ * - For POST/PATCH/PUT/DELETE requests, adds CSRF token to headers
2828
+ *
2829
+ * @param {FetchParameters} args - The fetch parameters array containing [url, requestInit]
2830
+ * @returns Promise-like resolved with the modified fetch parameters
2831
+ *
2832
+ * @example
2833
+ * ```typescript
2834
+ * const modifiedArgs = await webruntimeRequestInterceptor(['/api/data', { method: 'GET' }]);
2835
+ * // URL will have ?language=en_US&asGuest=false&htmlEncode=false appended
2836
+ * ```
2837
+ */
2838
+ async function webruntimeRequestInterceptor(args) {
2839
+ const [url, requestInit] = args;
2840
+ if (!(typeof url === 'string' || url instanceof URL)) {
2841
+ return resolvedPromiseLike$3(args);
2842
+ }
2843
+ const urlObj = url instanceof URL ? url : new URL(url, location?.href);
2844
+ urlObj.searchParams.append('language', language);
2845
+ urlObj.searchParams.append('asGuest', getAsGuestParamValue().toString());
2846
+ urlObj.searchParams.append('htmlEncode', 'false');
2847
+ // Update the args array with the modified URL string
2848
+ args[0] = urlObj;
2849
+ if (requestInit?.method && METHODS_WITH_CSRF.includes(requestInit.method)) {
2850
+ await addCSRFToken(requestInit);
2851
+ }
2852
+ return resolvedPromiseLike$3(args);
2853
+ }
2854
+ function hasSidCookie() {
2855
+ const cookies = document.cookie.split(';');
2856
+ return cookies.some((cookie) => {
2857
+ const [name] = cookie.trim().split('=');
2858
+ return name === authenticationCookieName;
2859
+ });
2860
+ }
2861
+ function getAsGuestParamValue() {
2862
+ // authenticationCookieName (__Secure-has-sid) is set in design mode or preview mode
2863
+ if (isDesignMode || isPreviewMode) {
2864
+ return false;
2865
+ }
2866
+ return !hasSidCookie();
2867
+ }
2868
+ async function addCSRFToken(params) {
2869
+ const { csrfToken } = await getUser();
2870
+ if (!params.headers) {
2871
+ params.headers = {};
2872
+ }
2873
+ if (csrfToken) {
2874
+ params.headers['CSRF-Token'] = csrfToken;
2875
+ }
2876
+ }
2877
+ async function getUser() {
2878
+ if (typeof window === 'undefined') {
2879
+ // always make API calls as guest on the server
2880
+ return { isGuest: true, id: null, csrfToken: null };
2881
+ }
2882
+ const { default: user } = await import('@app/user');
2883
+ return user;
2884
+ }
2885
+
2814
2886
  const SFAP_BASE_URL = 'api.salesforce.com';
2815
2887
  const sfapJwtRepository = new JwtRepository();
2816
2888
  const sfapJwtManager = new JwtManager(sfapJwtRepository, platformSfapJwtResolver);
@@ -2877,8 +2949,8 @@ function buildCopilotFetchServiceDescriptor(logger) {
2877
2949
  tags: { specialHacksFor: 'copilot' },
2878
2950
  };
2879
2951
  }
2880
- function buildUnauthorizedFetchServiceDescriptor() {
2881
- const fetchService = buildServiceDescriptor();
2952
+ function buildDefaultFetchServiceDescriptor() {
2953
+ const fetchService = buildServiceDescriptor({ request: [webruntimeRequestInterceptor] });
2882
2954
  return {
2883
2955
  ...fetchService,
2884
2956
  tags: { authenticationScopes: '' },
@@ -2907,23 +2979,15 @@ function buildJwtRequestInterceptor(logger) {
2907
2979
  return jwtRequestHeaderInterceptor;
2908
2980
  }
2909
2981
 
2910
- function buildAuraNetworkService() {
2911
- return {
2912
- type: 'auraNetwork',
2913
- version: '1.0',
2914
- service: executeGlobalControllerRawResponse,
2915
- };
2916
- }
2917
2982
  const loggerService = new ConsoleLogger$1('ERROR');
2918
2983
  const cacheServiceDescriptor = buildServiceDescriptor$4();
2919
2984
  const instrumentationServiceDescriptor = buildServiceDescriptor$5(loggerService);
2920
2985
  const inMemoryCacheInclusionPolicyServiceDescriptor = buildInMemoryCacheInclusionPolicyService(cacheServiceDescriptor.service);
2921
2986
  const services = [
2922
2987
  instrumentationServiceDescriptor,
2923
- buildUnauthorizedFetchServiceDescriptor(),
2988
+ buildDefaultFetchServiceDescriptor(),
2924
2989
  buildJwtAuthorizedSfapFetchServiceDescriptor(loggerService),
2925
2990
  buildCopilotFetchServiceDescriptor(loggerService),
2926
- buildAuraNetworkService(),
2927
2991
  buildServiceDescriptor$6(instrumentationServiceDescriptor.service),
2928
2992
  buildServiceDescriptor$3(cacheServiceDescriptor.service, inMemoryCacheInclusionPolicyServiceDescriptor.service),
2929
2993
  buildServiceDescriptor$d(),
@@ -2938,4 +3002,4 @@ const services = [
2938
3002
  buildServiceDescriptor$2(),
2939
3003
  ];
2940
3004
  setServices(services);
2941
- // version: 1.370.0-3ec6ffba72
3005
+ // version: 1.371.0-e11a80989c
@@ -0,0 +1,22 @@
1
+ import { type FetchParameters } from '@luvio/service-fetch-network/v1';
2
+ /**
3
+ * Webruntime request interceptor that modifies outgoing HTTP requests with standard
4
+ * query parameters and security headers. This ensures the api calls for onestore adapters
5
+ * follow the same pattern as the equivalent luvio api calls for all CLWR endpoints.
6
+ *
7
+ * This interceptor:
8
+ * - Adds language query parameter from i18n settings
9
+ * - Adds asGuest parameter based on design/preview mode and SID cookie presence
10
+ * - Adds htmlEncode=false query parameter (since this is an api call by definition)
11
+ * - For POST/PATCH/PUT/DELETE requests, adds CSRF token to headers
12
+ *
13
+ * @param {FetchParameters} args - The fetch parameters array containing [url, requestInit]
14
+ * @returns Promise-like resolved with the modified fetch parameters
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const modifiedArgs = await webruntimeRequestInterceptor(['/api/data', { method: 'GET' }]);
19
+ * // URL will have ?language=en_US&asGuest=false&htmlEncode=false appended
20
+ * ```
21
+ */
22
+ export declare function webruntimeRequestInterceptor(args: FetchParameters): Promise<[input: RequestInfo | URL, init?: RequestInit | undefined]>;
@@ -7,4 +7,4 @@ export declare function buildJwtAuthorizedSfapFetchServiceDescriptor(logger: Log
7
7
  * copilot commands.
8
8
  */
9
9
  export declare function buildCopilotFetchServiceDescriptor(logger: LoggerService): FetchServiceDescriptor;
10
- export declare function buildUnauthorizedFetchServiceDescriptor(): FetchServiceDescriptor;
10
+ export declare function buildDefaultFetchServiceDescriptor(): FetchServiceDescriptor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-webruntime",
3
- "version": "1.370.0",
3
+ "version": "1.371.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS engine for Webruntime runtime",
6
6
  "main": "dist/ldsWebruntimeOneStoreInit.js",
@@ -61,7 +61,7 @@
61
61
  "@luvio/service-pubsub": "5.44.0",
62
62
  "@luvio/service-store": "5.44.0",
63
63
  "@luvio/utils": "5.44.0",
64
- "@salesforce/lds-adapters-uiapi-lex": "^1.370.0"
64
+ "@salesforce/lds-adapters-uiapi-lex": "^1.371.0"
65
65
  },
66
66
  "luvioBundlesize": [
67
67
  {