@salesforce/commerce-sdk-react 3.5.0-preview.0 → 4.0.0-dev

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 (36) hide show
  1. package/CHANGELOG.md +5 -2
  2. package/README.md +21 -3
  3. package/auth/index.d.ts +127 -57
  4. package/auth/index.js +163 -108
  5. package/components/StorefrontPreview/utils.js +3 -2
  6. package/constant.d.ts +0 -16
  7. package/constant.js +1 -19
  8. package/hooks/ShopperBaskets/helpers.d.ts +32 -21
  9. package/hooks/ShopperBaskets/queryKeyHelpers.js +10 -10
  10. package/hooks/ShopperContexts/queryKeyHelpers.js +2 -2
  11. package/hooks/ShopperCustomers/queryKeyHelpers.js +22 -22
  12. package/hooks/ShopperExperience/queryKeyHelpers.js +4 -4
  13. package/hooks/ShopperGiftCertificates/queryKeyHelpers.js +2 -2
  14. package/hooks/ShopperLogin/queryKeyHelpers.js +6 -6
  15. package/hooks/ShopperOrders/queryKeyHelpers.js +6 -6
  16. package/hooks/ShopperProducts/queryKeyHelpers.js +8 -8
  17. package/hooks/ShopperPromotions/queryKeyHelpers.js +4 -4
  18. package/hooks/{ShopperSeo → ShopperSEO}/query.d.ts +1 -1
  19. package/hooks/{ShopperSeo → ShopperSEO}/query.js +3 -3
  20. package/hooks/{ShopperSeo → ShopperSEO}/queryKeyHelpers.d.ts +2 -2
  21. package/hooks/{ShopperSeo → ShopperSEO}/queryKeyHelpers.js +2 -2
  22. package/hooks/ShopperSearch/queryKeyHelpers.js +4 -4
  23. package/hooks/ShopperStores/queryKeyHelpers.js +4 -4
  24. package/hooks/helpers.d.ts +14 -1
  25. package/hooks/index.d.ts +1 -1
  26. package/hooks/index.js +4 -4
  27. package/hooks/types.d.ts +3 -3
  28. package/hooks/useDNT.d.ts +0 -4
  29. package/hooks/useDNT.js +0 -6
  30. package/hooks/useQuery.js +2 -0
  31. package/package.json +5 -5
  32. package/provider.d.ts +14 -2
  33. package/provider.js +19 -12
  34. package/utils.d.ts +1 -1
  35. /package/hooks/{ShopperSeo → ShopperSEO}/index.d.ts +0 -0
  36. /package/hooks/{ShopperSeo → ShopperSEO}/index.js +0 -0
package/provider.d.ts CHANGED
@@ -2,14 +2,14 @@ import React, { ReactElement } from 'react';
2
2
  import Auth from './auth';
3
3
  import { ApiClientConfigParams, ApiClients } from './hooks/types';
4
4
  import { Logger } from './types';
5
- import { ShopperBasketsTypes } from 'commerce-sdk-isomorphic';
5
+ import { FetchOptions } from 'commerce-sdk-isomorphic';
6
6
  export interface CommerceApiProviderProps extends ApiClientConfigParams {
7
7
  children: React.ReactNode;
8
8
  proxy: string;
9
9
  locale: string;
10
10
  currency: string;
11
11
  redirectURI: string;
12
- fetchOptions?: ShopperBasketsTypes.FetchOptions;
12
+ fetchOptions?: FetchOptions;
13
13
  headers?: Record<string, string>;
14
14
  fetchedToken?: string;
15
15
  enablePWAKitPrivateClient?: boolean;
@@ -23,6 +23,7 @@ export interface CommerceApiProviderProps extends ApiClientConfigParams {
23
23
  refreshTokenGuestCookieTTL?: number;
24
24
  apiClients?: ApiClients;
25
25
  disableAuthInit?: boolean;
26
+ hybridAuthEnabled?: boolean;
26
27
  }
27
28
  /**
28
29
  * @internal
@@ -76,6 +77,17 @@ export declare const AuthContext: React.Context<Auth>;
76
77
  * directly to the provider. However, be careful when doing this as you will have
77
78
  * to make sure the secret is not unexpectedly exposed to the client.
78
79
  *
80
+ *
81
+ * `hybridAuthEnabled` is an optional flag that indicates the current Site has Hybrid Auth enabled.
82
+ * This drives the behavior of the `clearECOMSession` method. If `hybridAuthEnabled` is true,
83
+ * the `clearECOMSession` method will not be called. This makes sure the session-bridged dwsid, received from `/oauth2/token` call
84
+ * on shopper login is NOT cleared and can be used to maintain the server affinity.
85
+ *
86
+ * `hybridAuthEnabled` flag can also be used to drive other Hybrid Auth specific behaviors in the future.
87
+ *
88
+ * Note: `hybridAuthEnabled` should NOT be set to true for hybrid storefronts using Plugin SLAS as we need the dwsid to be deleted
89
+ * to force session-bridging on SFRA as in this case, the `oauth2/token` call does not return a dwsid.
90
+ *
79
91
  * @returns Provider to wrap your app with
80
92
  */
81
93
  declare const CommerceApiProvider: (props: CommerceApiProviderProps) => ReactElement;
package/provider.js CHANGED
@@ -79,6 +79,17 @@ const AuthContext = exports.AuthContext = /*#__PURE__*/_react.default.createCont
79
79
  * Non-PWA Kit users can enable private client mode by passing in a client secret
80
80
  * directly to the provider. However, be careful when doing this as you will have
81
81
  * to make sure the secret is not unexpectedly exposed to the client.
82
+ *
83
+ *
84
+ * `hybridAuthEnabled` is an optional flag that indicates the current Site has Hybrid Auth enabled.
85
+ * This drives the behavior of the `clearECOMSession` method. If `hybridAuthEnabled` is true,
86
+ * the `clearECOMSession` method will not be called. This makes sure the session-bridged dwsid, received from `/oauth2/token` call
87
+ * on shopper login is NOT cleared and can be used to maintain the server affinity.
88
+ *
89
+ * `hybridAuthEnabled` flag can also be used to drive other Hybrid Auth specific behaviors in the future.
90
+ *
91
+ * Note: `hybridAuthEnabled` should NOT be set to true for hybrid storefronts using Plugin SLAS as we need the dwsid to be deleted
92
+ * to force session-bridging on SFRA as in this case, the `oauth2/token` call does not return a dwsid.
82
93
  *
83
94
  * @returns Provider to wrap your app with
84
95
  */
@@ -106,7 +117,8 @@ const CommerceApiProvider = props => {
106
117
  refreshTokenRegisteredCookieTTL,
107
118
  refreshTokenGuestCookieTTL,
108
119
  apiClients,
109
- disableAuthInit = false
120
+ disableAuthInit = false,
121
+ hybridAuthEnabled = false
110
122
  } = props;
111
123
 
112
124
  // Set the logger based on provided configuration, or default to the console object if no logger is provided
@@ -119,6 +131,7 @@ const CommerceApiProvider = props => {
119
131
  siteId,
120
132
  proxy,
121
133
  redirectURI,
134
+ headers,
122
135
  fetchOptions,
123
136
  fetchedToken,
124
137
  enablePWAKitPrivateClient,
@@ -129,9 +142,10 @@ const CommerceApiProvider = props => {
129
142
  defaultDnt,
130
143
  passwordlessLoginCallbackURI,
131
144
  refreshTokenRegisteredCookieTTL,
132
- refreshTokenGuestCookieTTL
145
+ refreshTokenGuestCookieTTL,
146
+ hybridAuthEnabled
133
147
  });
134
- }, [clientId, organizationId, shortCode, siteId, proxy, redirectURI, fetchOptions, fetchedToken, enablePWAKitPrivateClient, privateClientProxyEndpoint, clientSecret, silenceWarnings, configLogger, defaultDnt, passwordlessLoginCallbackURI, refreshTokenRegisteredCookieTTL, refreshTokenGuestCookieTTL, apiClients]);
148
+ }, [clientId, organizationId, shortCode, siteId, proxy, redirectURI, headers, fetchOptions, fetchedToken, enablePWAKitPrivateClient, privateClientProxyEndpoint, clientSecret, silenceWarnings, configLogger, defaultDnt, passwordlessLoginCallbackURI, refreshTokenRegisteredCookieTTL, refreshTokenGuestCookieTTL, apiClients, hybridAuthEnabled]);
135
149
  const dwsid = auth.get(_constant.DWSID_COOKIE_NAME);
136
150
  const serverAffinityHeader = {};
137
151
  if (dwsid) {
@@ -178,13 +192,6 @@ const CommerceApiProvider = props => {
178
192
  throwOnBadResponse: true,
179
193
  fetchOptions
180
194
  };
181
-
182
- // Special proxy endpoint for injecting SLAS private client secret.
183
- // Note: we want to prioritize privateClientProxyEndpoint instead of this since that allows us to use the new envBasePath feature
184
- // This is kept here for now to prevent a breaking change.
185
- // We should remove this in the next major release so we do not have a hard coded proxy path inside commerce-sdk-react
186
- const baseUrl = config.proxy.split(_constant.MOBIFY_PATH)[0];
187
- const privateClientEndpoint = `${baseUrl}${_constant.SLAS_PRIVATE_PROXY_PATH}`;
188
195
  return {
189
196
  shopperBaskets: new _commerceSdkIsomorphic.ShopperBaskets(config),
190
197
  shopperContexts: new _commerceSdkIsomorphic.ShopperContexts(config),
@@ -192,13 +199,13 @@ const CommerceApiProvider = props => {
192
199
  shopperExperience: new _commerceSdkIsomorphic.ShopperExperience(config),
193
200
  shopperGiftCertificates: new _commerceSdkIsomorphic.ShopperGiftCertificates(config),
194
201
  shopperLogin: new _commerceSdkIsomorphic.ShopperLogin(_objectSpread(_objectSpread({}, config), {}, {
195
- proxy: enablePWAKitPrivateClient ? privateClientProxyEndpoint ? privateClientProxyEndpoint : privateClientEndpoint : config.proxy
202
+ proxy: enablePWAKitPrivateClient ? privateClientProxyEndpoint : config.proxy
196
203
  })),
197
204
  shopperOrders: new _commerceSdkIsomorphic.ShopperOrders(config),
198
205
  shopperProducts: new _commerceSdkIsomorphic.ShopperProducts(config),
199
206
  shopperPromotions: new _commerceSdkIsomorphic.ShopperPromotions(config),
200
207
  shopperSearch: new _commerceSdkIsomorphic.ShopperSearch(config),
201
- shopperSeo: new _commerceSdkIsomorphic.ShopperSeo(config),
208
+ shopperSeo: new _commerceSdkIsomorphic.ShopperSEO(config),
202
209
  shopperStores: new _commerceSdkIsomorphic.ShopperStores(config)
203
210
  };
204
211
  }, [clientId, organizationId, shortCode, siteId, proxy, fetchOptions, locale, currency, headers === null || headers === void 0 ? void 0 : headers['correlation-id'], apiClients]);
package/utils.d.ts CHANGED
@@ -25,7 +25,7 @@ export declare const isOriginTrusted: (origin: string | undefined) => boolean;
25
25
  * @returns `undefined` if running on the server, `"none"` if running as an iframe on a trusted site
26
26
  * (i.e. Storefront Preview), otherwise `"Lax"`
27
27
  */
28
- export declare const getCookieSameSiteAttribute: () => "Lax" | "none" | undefined;
28
+ export declare const getCookieSameSiteAttribute: () => "none" | "Lax" | undefined;
29
29
  /**
30
30
  * Gets the default cookie attributes. Sets the secure flag unless running on localhost in Safari.
31
31
  * Sets the sameSite attribute to `"none"` when running in a trusted iframe.
File without changes
File without changes