@salesforce/lds-runtime-webruntime 1.370.0 → 1.372.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.,
@@ -770,14 +773,20 @@ let AuraCacheControlCommand$1 = class AuraCacheControlCommand extends CacheContr
770
773
  async coerceFetchError(errorResponse) {
771
774
  return toError(errorResponse.statusText);
772
775
  }
776
+ processAuraReturnValue(auraReturnValue) {
777
+ return ok$2(auraReturnValue);
778
+ }
779
+ processFetchReturnValue(json) {
780
+ return ok$2(json);
781
+ }
773
782
  convertAuraResponseToData(responsePromise, coerceError) {
774
783
  return responsePromise.then((response) => {
775
- const auraReturnValue = response.getReturnValue();
784
+ return this.processAuraReturnValue(response.getReturnValue());
785
+ }).finally(() => {
776
786
  try {
777
787
  this.afterRequestHooks({ statusCode: 200 });
778
788
  } catch (e) {
779
789
  }
780
- return ok$2(auraReturnValue);
781
790
  }).catch((error) => {
782
791
  if (!error || !error.getError) {
783
792
  return err$1(toError("Failed to get error from response"));
@@ -796,7 +805,9 @@ let AuraCacheControlCommand$1 = class AuraCacheControlCommand extends CacheContr
796
805
  (response2) => {
797
806
  if (response2.ok) {
798
807
  return response2.json().then(
799
- (json) => ok$2(json),
808
+ (json) => {
809
+ return this.processFetchReturnValue(json);
810
+ },
800
811
  (reason) => err$1(toError(reason))
801
812
  ).finally(() => {
802
813
  try {
@@ -908,14 +919,20 @@ class AuraCacheControlCommand extends CacheControlCommand {
908
919
  async coerceFetchError(errorResponse) {
909
920
  return toError(errorResponse.statusText);
910
921
  }
922
+ processAuraReturnValue(auraReturnValue) {
923
+ return ok$2(auraReturnValue);
924
+ }
925
+ processFetchReturnValue(json) {
926
+ return ok$2(json);
927
+ }
911
928
  convertAuraResponseToData(responsePromise, coerceError) {
912
929
  return responsePromise.then((response) => {
913
- const auraReturnValue = response.getReturnValue();
930
+ return this.processAuraReturnValue(response.getReturnValue());
931
+ }).finally(() => {
914
932
  try {
915
933
  this.afterRequestHooks({ statusCode: 200 });
916
934
  } catch (e) {
917
935
  }
918
- return ok$2(auraReturnValue);
919
936
  }).catch((error) => {
920
937
  if (!error || !error.getError) {
921
938
  return err$1(toError("Failed to get error from response"));
@@ -934,7 +951,9 @@ class AuraCacheControlCommand extends CacheControlCommand {
934
951
  (response2) => {
935
952
  if (response2.ok) {
936
953
  return response2.json().then(
937
- (json) => ok$2(json),
954
+ (json) => {
955
+ return this.processFetchReturnValue(json);
956
+ },
938
957
  (reason) => err$1(toError(reason))
939
958
  ).finally(() => {
940
959
  try {
@@ -1013,12 +1032,17 @@ class HttpCacheControlCommand extends CacheControlCommand {
1013
1032
  async coerceError(errorResponse) {
1014
1033
  return toError(errorResponse.statusText);
1015
1034
  }
1035
+ processFetchReturnValue(json) {
1036
+ return ok$2(json);
1037
+ }
1016
1038
  convertFetchResponseToData(response) {
1017
1039
  return response.then(
1018
1040
  (response2) => {
1019
1041
  if (response2.ok) {
1020
1042
  return response2.json().then(
1021
- (json) => ok$2(json),
1043
+ (json) => {
1044
+ return this.processFetchReturnValue(json);
1045
+ },
1022
1046
  (reason) => err$1(toError(reason))
1023
1047
  ).finally(() => {
1024
1048
  try {
@@ -2811,6 +2835,75 @@ const platformSfapJwtResolver = {
2811
2835
  },
2812
2836
  };
2813
2837
 
2838
+ const METHODS_WITH_CSRF = ['POST', 'PATCH', 'PUT', 'DELETE'];
2839
+ /**
2840
+ * Webruntime request interceptor that modifies outgoing HTTP requests with standard
2841
+ * query parameters and security headers. This ensures the api calls for onestore adapters
2842
+ * follow the same pattern as the equivalent luvio api calls for all CLWR endpoints.
2843
+ *
2844
+ * This interceptor:
2845
+ * - Adds language query parameter from i18n settings
2846
+ * - Adds asGuest parameter based on design/preview mode and SID cookie presence
2847
+ * - Adds htmlEncode=false query parameter (since this is an api call by definition)
2848
+ * - For POST/PATCH/PUT/DELETE requests, adds CSRF token to headers
2849
+ *
2850
+ * @param {FetchParameters} args - The fetch parameters array containing [url, requestInit]
2851
+ * @returns Promise-like resolved with the modified fetch parameters
2852
+ *
2853
+ * @example
2854
+ * ```typescript
2855
+ * const modifiedArgs = await webruntimeRequestInterceptor(['/api/data', { method: 'GET' }]);
2856
+ * // URL will have ?language=en_US&asGuest=false&htmlEncode=false appended
2857
+ * ```
2858
+ */
2859
+ async function webruntimeRequestInterceptor(args) {
2860
+ const [url, requestInit] = args;
2861
+ if (!(typeof url === 'string' || url instanceof URL)) {
2862
+ return resolvedPromiseLike$3(args);
2863
+ }
2864
+ const urlObj = url instanceof URL ? url : new URL(url, location?.href);
2865
+ urlObj.searchParams.append('language', language);
2866
+ urlObj.searchParams.append('asGuest', getAsGuestParamValue().toString());
2867
+ urlObj.searchParams.append('htmlEncode', 'false');
2868
+ // Update the args array with the modified URL string
2869
+ args[0] = urlObj;
2870
+ if (requestInit?.method && METHODS_WITH_CSRF.includes(requestInit.method)) {
2871
+ await addCSRFToken(requestInit);
2872
+ }
2873
+ return resolvedPromiseLike$3(args);
2874
+ }
2875
+ function hasSidCookie() {
2876
+ const cookies = document.cookie.split(';');
2877
+ return cookies.some((cookie) => {
2878
+ const [name] = cookie.trim().split('=');
2879
+ return name === authenticationCookieName;
2880
+ });
2881
+ }
2882
+ function getAsGuestParamValue() {
2883
+ // authenticationCookieName (__Secure-has-sid) is set in design mode or preview mode
2884
+ if (isDesignMode || isPreviewMode) {
2885
+ return false;
2886
+ }
2887
+ return !hasSidCookie();
2888
+ }
2889
+ async function addCSRFToken(params) {
2890
+ const { csrfToken } = await getUser();
2891
+ if (!params.headers) {
2892
+ params.headers = {};
2893
+ }
2894
+ if (csrfToken) {
2895
+ params.headers['CSRF-Token'] = csrfToken;
2896
+ }
2897
+ }
2898
+ async function getUser() {
2899
+ if (typeof window === 'undefined') {
2900
+ // always make API calls as guest on the server
2901
+ return { isGuest: true, id: null, csrfToken: null };
2902
+ }
2903
+ const { default: user } = await import('@app/user');
2904
+ return user;
2905
+ }
2906
+
2814
2907
  const SFAP_BASE_URL = 'api.salesforce.com';
2815
2908
  const sfapJwtRepository = new JwtRepository();
2816
2909
  const sfapJwtManager = new JwtManager(sfapJwtRepository, platformSfapJwtResolver);
@@ -2877,8 +2970,8 @@ function buildCopilotFetchServiceDescriptor(logger) {
2877
2970
  tags: { specialHacksFor: 'copilot' },
2878
2971
  };
2879
2972
  }
2880
- function buildUnauthorizedFetchServiceDescriptor() {
2881
- const fetchService = buildServiceDescriptor();
2973
+ function buildDefaultFetchServiceDescriptor() {
2974
+ const fetchService = buildServiceDescriptor({ request: [webruntimeRequestInterceptor] });
2882
2975
  return {
2883
2976
  ...fetchService,
2884
2977
  tags: { authenticationScopes: '' },
@@ -2907,23 +3000,15 @@ function buildJwtRequestInterceptor(logger) {
2907
3000
  return jwtRequestHeaderInterceptor;
2908
3001
  }
2909
3002
 
2910
- function buildAuraNetworkService() {
2911
- return {
2912
- type: 'auraNetwork',
2913
- version: '1.0',
2914
- service: executeGlobalControllerRawResponse,
2915
- };
2916
- }
2917
3003
  const loggerService = new ConsoleLogger$1('ERROR');
2918
3004
  const cacheServiceDescriptor = buildServiceDescriptor$4();
2919
3005
  const instrumentationServiceDescriptor = buildServiceDescriptor$5(loggerService);
2920
3006
  const inMemoryCacheInclusionPolicyServiceDescriptor = buildInMemoryCacheInclusionPolicyService(cacheServiceDescriptor.service);
2921
3007
  const services = [
2922
3008
  instrumentationServiceDescriptor,
2923
- buildUnauthorizedFetchServiceDescriptor(),
3009
+ buildDefaultFetchServiceDescriptor(),
2924
3010
  buildJwtAuthorizedSfapFetchServiceDescriptor(loggerService),
2925
3011
  buildCopilotFetchServiceDescriptor(loggerService),
2926
- buildAuraNetworkService(),
2927
3012
  buildServiceDescriptor$6(instrumentationServiceDescriptor.service),
2928
3013
  buildServiceDescriptor$3(cacheServiceDescriptor.service, inMemoryCacheInclusionPolicyServiceDescriptor.service),
2929
3014
  buildServiceDescriptor$d(),
@@ -2938,4 +3023,4 @@ const services = [
2938
3023
  buildServiceDescriptor$2(),
2939
3024
  ];
2940
3025
  setServices(services);
2941
- // version: 1.370.0-3ec6ffba72
3026
+ // version: 1.372.0-5866fad2db
@@ -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.372.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS engine for Webruntime runtime",
6
6
  "main": "dist/ldsWebruntimeOneStoreInit.js",
@@ -35,33 +35,33 @@
35
35
  "ready": "yarn build && jest --collectCoverage && yarn test:size && yarn release:corejar"
36
36
  },
37
37
  "devDependencies": {
38
- "@luvio/service-provisioner": "5.44.0",
39
- "@luvio/tools-core": "5.44.0",
38
+ "@luvio/service-provisioner": "5.49.0",
39
+ "@luvio/tools-core": "5.49.0",
40
40
  "jwt-encode": "1.0.1"
41
41
  },
42
42
  "dependencies": {
43
- "@luvio/command-aura-network": "5.44.0",
44
- "@luvio/command-aura-normalized-cache-control": "5.44.0",
45
- "@luvio/command-aura-resource-cache-control": "5.44.0",
46
- "@luvio/command-fetch-network": "5.44.0",
47
- "@luvio/command-http-normalized-cache-control": "5.44.0",
48
- "@luvio/command-ndjson": "5.44.0",
49
- "@luvio/command-network": "5.44.0",
50
- "@luvio/command-sse": "5.44.0",
51
- "@luvio/command-streaming": "5.44.0",
52
- "@luvio/jwt-manager": "5.44.0",
43
+ "@luvio/command-aura-network": "5.49.0",
44
+ "@luvio/command-aura-normalized-cache-control": "5.49.0",
45
+ "@luvio/command-aura-resource-cache-control": "5.49.0",
46
+ "@luvio/command-fetch-network": "5.49.0",
47
+ "@luvio/command-http-normalized-cache-control": "5.49.0",
48
+ "@luvio/command-ndjson": "5.49.0",
49
+ "@luvio/command-network": "5.49.0",
50
+ "@luvio/command-sse": "5.49.0",
51
+ "@luvio/command-streaming": "5.49.0",
52
+ "@luvio/jwt-manager": "5.49.0",
53
53
  "@luvio/network-adapter-composable": "0.158.7",
54
54
  "@luvio/network-adapter-fetch": "0.158.7",
55
- "@luvio/service-aura-network": "5.44.0",
56
- "@luvio/service-cache": "5.44.0",
57
- "@luvio/service-cache-control": "5.44.0",
58
- "@luvio/service-cache-inclusion-policy": "5.44.0",
59
- "@luvio/service-fetch-network": "5.44.0",
60
- "@luvio/service-instrument-command": "5.44.0",
61
- "@luvio/service-pubsub": "5.44.0",
62
- "@luvio/service-store": "5.44.0",
63
- "@luvio/utils": "5.44.0",
64
- "@salesforce/lds-adapters-uiapi-lex": "^1.370.0"
55
+ "@luvio/service-aura-network": "5.49.0",
56
+ "@luvio/service-cache": "5.49.0",
57
+ "@luvio/service-cache-control": "5.49.0",
58
+ "@luvio/service-cache-inclusion-policy": "5.49.0",
59
+ "@luvio/service-fetch-network": "5.49.0",
60
+ "@luvio/service-instrument-command": "5.49.0",
61
+ "@luvio/service-pubsub": "5.49.0",
62
+ "@luvio/service-store": "5.49.0",
63
+ "@luvio/utils": "5.49.0",
64
+ "@salesforce/lds-adapters-uiapi-lex": "^1.372.0"
65
65
  },
66
66
  "luvioBundlesize": [
67
67
  {