@salesforce/commerce-sdk-react 3.2.1 → 3.3.0-extensibility-preview.4

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v3.3.0-extensibility-preview.4 (Feb 12, 2025)
2
+ - Add `ServerContext` type for `useServerContext` hook [#2239](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2239)
3
+
4
+ ## v3.3.0-dev (Feb 18, 2025)
5
+ - Invalidate cache instead of removing cache when triggering logout [#2323](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2323)
6
+ - Fix dependencies vulnerabilities [#2338](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2338)
7
+ - Allow custom parameters/body to be passed to SLAS authorize/authenticate calls via commerce-sdk-react auth helpers [#2358](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2358)
8
+
1
9
  ## v3.2.1 (Mar 05, 2025)
2
10
  - Update PWA-Kit SDKs to v3.9.1 [#2301](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2301)
3
11
 
package/auth/index.d.ts CHANGED
@@ -24,6 +24,16 @@ type LoginIDPUserParams = Parameters<Helpers['loginIDPUser']>[2];
24
24
  type AuthorizePasswordlessParams = Parameters<Helpers['authorizePasswordless']>[2];
25
25
  type LoginPasswordlessParams = Parameters<Helpers['getPasswordLessAccessToken']>[2];
26
26
  type LoginRegisteredUserB2CCredentials = Parameters<Helpers['loginRegisteredUserB2C']>[1];
27
+ /**
28
+ * This is a temporary type until we can make a breaking change and modify the signature for
29
+ * loginRegisteredUserB2C so that it takes in a body rather than just credentials
30
+ *
31
+ */
32
+ type LoginRegisteredUserCredentialsWithCustomParams = LoginRegisteredUserB2CCredentials & {
33
+ options?: {
34
+ body: helpers.CustomRequestBody;
35
+ };
36
+ };
27
37
  /**
28
38
  * The extended field is not from api response, we manually store the auth type,
29
39
  * so we don't need to make another API call when we already have the data.
@@ -199,7 +209,7 @@ declare class Auth {
199
209
  * A wrapper method for commerce-sdk-isomorphic helper: loginGuestUser.
200
210
  *
201
211
  */
202
- loginGuestUser(): Promise<ShopperLoginTypes.TokenResponse>;
212
+ loginGuestUser(parameters?: helpers.CustomQueryParameters): Promise<ShopperLoginTypes.TokenResponse>;
203
213
  /**
204
214
  * This is a wrapper method for ShopperCustomer API registerCustomer endpoint.
205
215
  *
@@ -302,8 +312,14 @@ declare class Auth {
302
312
  /**
303
313
  * A wrapper method for commerce-sdk-isomorphic helper: loginRegisteredUserB2C.
304
314
  *
315
+ * Note: This uses the type LoginRegisteredUserCredentialsWithCustomParams rather than LoginRegisteredUserB2CCredentials
316
+ * as a workaround to allow custom parameters through because the login.mutateAsync hook will only pass through a single
317
+ * 'body' argument into this function.
318
+ *
319
+ * In the next major version release, we should modify this method so that it's input is a body containing credentials,
320
+ * similar to the input for the register function.
305
321
  */
306
- loginRegisteredUserB2C(credentials: LoginRegisteredUserB2CCredentials): Promise<helpers.TokenResponse>;
322
+ loginRegisteredUserB2C(credentials: LoginRegisteredUserCredentialsWithCustomParams): Promise<helpers.TokenResponse>;
307
323
  /**
308
324
  * Trusted agent authorization
309
325
  *
package/auth/index.js CHANGED
@@ -9,6 +9,9 @@ var _jwtDecode = require("jwt-decode");
9
9
  var _storage = require("./storage");
10
10
  var _utils = require("../utils");
11
11
  var _constant = require("../constant");
12
+ const _excluded = ["customer", "password"];
13
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
14
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
12
15
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
13
16
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
14
17
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -21,6 +24,12 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
21
24
  * SPDX-License-Identifier: BSD-3-Clause
22
25
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
23
26
  */
27
+ /**
28
+ * This is a temporary type until we can make a breaking change and modify the signature for
29
+ * loginRegisteredUserB2C so that it takes in a body rather than just credentials
30
+ *
31
+ */
32
+
24
33
  /**
25
34
  * The extended field is not from api response, we manually store the auth type,
26
35
  * so we don't need to make another API call when we already have the data.
@@ -582,7 +591,7 @@ class Auth {
582
591
  var _this3 = this;
583
592
  return _asyncToGenerator(function* () {
584
593
  const queue = _this3.pendingToken ?? Promise.resolve();
585
- _this3.pendingToken = queue.then( /*#__PURE__*/_asyncToGenerator(function* () {
594
+ _this3.pendingToken = queue.then(/*#__PURE__*/_asyncToGenerator(function* () {
586
595
  const token = yield fn();
587
596
  _this3.handleTokenResponse(token, isGuest);
588
597
  // Q: Why don't we just return token? Why re-construct the same object again?
@@ -692,7 +701,7 @@ class Auth {
692
701
  * A wrapper method for commerce-sdk-isomorphic helper: loginGuestUser.
693
702
  *
694
703
  */
695
- loginGuestUser() {
704
+ loginGuestUser(parameters) {
696
705
  var _this6 = this;
697
706
  return _asyncToGenerator(function* () {
698
707
  if (_this6.clientSecret && (0, _utils.onClient)() && _this6.clientSecret !== _constant.SLAS_SECRET_PLACEHOLDER) {
@@ -710,12 +719,12 @@ class Auth {
710
719
  }), {
711
720
  clientSecret: _this6.clientSecret
712
721
  }];
713
- const guestPublicArgs = [_this6.client, _objectSpread({
722
+ const guestPublicArgs = [_this6.client, _objectSpread(_objectSpread({
714
723
  redirectURI: _this6.redirectURI,
715
724
  dnt: dntPref
716
725
  }, usid && {
717
726
  usid
718
- })];
727
+ }), parameters)];
719
728
  const callback = _this6.clientSecret ? () => _commerceSdkIsomorphic.helpers.loginGuestUserPrivate(...guestPrivateArgs) : () => _commerceSdkIsomorphic.helpers.loginGuestUser(...guestPublicArgs);
720
729
  try {
721
730
  return yield _this6.queueRequest(callback, isGuest);
@@ -740,11 +749,14 @@ class Auth {
740
749
  var _this7 = this;
741
750
  return _asyncToGenerator(function* () {
742
751
  const {
743
- customer: {
744
- login
745
- },
746
- password
747
- } = body;
752
+ customer,
753
+ password
754
+ } = body,
755
+ parameters = _objectWithoutProperties(body, _excluded);
756
+ const {
757
+ login
758
+ } = customer;
759
+ const customParameters = (0, _utils.extractCustomParameters)(parameters);
748
760
 
749
761
  // login is optional field from isomorphic library
750
762
  // type CustomerRegistration
@@ -752,15 +764,24 @@ class Auth {
752
764
  if (!login) {
753
765
  throw new Error('Customer registration is missing login field.');
754
766
  }
767
+
768
+ // The registerCustomer endpoint currently does not support custom parameters
769
+ // so we make sure not to send any custom params here
755
770
  const res = yield _this7.shopperCustomersClient.registerCustomer({
756
771
  headers: {
757
772
  authorization: `Bearer ${_this7.get('access_token')}`
758
773
  },
759
- body
774
+ body: {
775
+ customer,
776
+ password
777
+ }
760
778
  });
761
779
  yield _this7.loginRegisteredUserB2C({
762
780
  username: login,
763
- password
781
+ password,
782
+ options: {
783
+ body: customParameters
784
+ }
764
785
  });
765
786
  return res;
766
787
  })();
@@ -769,6 +790,12 @@ class Auth {
769
790
  /**
770
791
  * A wrapper method for commerce-sdk-isomorphic helper: loginRegisteredUserB2C.
771
792
  *
793
+ * Note: This uses the type LoginRegisteredUserCredentialsWithCustomParams rather than LoginRegisteredUserB2CCredentials
794
+ * as a workaround to allow custom parameters through because the login.mutateAsync hook will only pass through a single
795
+ * 'body' argument into this function.
796
+ *
797
+ * In the next major version release, we should modify this method so that it's input is a body containing credentials,
798
+ * similar to the input for the register function.
772
799
  */
773
800
  loginRegisteredUserB2C(credentials) {
774
801
  var _this8 = this;
@@ -782,14 +809,16 @@ class Auth {
782
809
  includeDefaults: true
783
810
  });
784
811
  const isGuest = false;
785
- const token = yield _commerceSdkIsomorphic.helpers.loginRegisteredUserB2C(_this8.client, _objectSpread(_objectSpread({}, credentials), {}, {
812
+ const token = yield _commerceSdkIsomorphic.helpers.loginRegisteredUserB2C(_this8.client, {
813
+ username: credentials.username,
814
+ password: credentials.password,
786
815
  clientSecret: _this8.clientSecret
787
- }), _objectSpread({
816
+ }, _objectSpread({
788
817
  redirectURI,
789
818
  dnt: dntPref
790
819
  }, usid && {
791
820
  usid
792
- }));
821
+ }), credentials.options);
793
822
  _this8.handleTokenResponse(token, isGuest);
794
823
  if ((0, _utils.onClient)()) {
795
824
  void _this8.clearECOMSession();
@@ -956,15 +985,16 @@ class Auth {
956
985
  return _asyncToGenerator(function* () {
957
986
  const redirectURI = parameters.redirectURI || _this14.redirectURI;
958
987
  const usid = _this14.get('usid');
988
+ const customParameters = (0, _utils.extractCustomParameters)(parameters);
959
989
  const {
960
990
  url,
961
991
  codeVerifier
962
- } = yield _commerceSdkIsomorphic.helpers.authorizeIDP(_this14.client, _objectSpread({
992
+ } = yield _commerceSdkIsomorphic.helpers.authorizeIDP(_this14.client, _objectSpread(_objectSpread({
963
993
  redirectURI,
964
994
  hint: parameters.hint
965
995
  }, usid && {
966
996
  usid
967
- }), _this14.isPrivate);
997
+ }), customParameters), _this14.isPrivate);
968
998
  if ((0, _utils.onClient)()) {
969
999
  window.location.assign(url);
970
1000
  } else {
@@ -15,8 +15,8 @@ const _excluded = ["data"];
15
15
  */
16
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
17
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
18
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
19
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
18
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
19
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
20
20
  const ComponentNotFound = ({
21
21
  typeId
22
22
  }) => /*#__PURE__*/_react.default.createElement("div", null, `Component type '${typeId}' not found!`);
@@ -22,8 +22,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
22
22
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
23
23
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
24
24
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
25
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
26
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
25
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
26
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
27
27
  // This context will hold the component map as well as any other future context.
28
28
  const PageContext = exports.PageContext = /*#__PURE__*/_react.default.createContext(undefined);
29
29
 
@@ -17,8 +17,8 @@ const _excluded = ["region", "className"];
17
17
  */
18
18
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
19
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
20
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
21
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
20
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
21
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
22
22
  /**
23
23
  * This PropType represents a `region` object from the ShopperExperience API.
24
24
  */
package/hooks/types.d.ts CHANGED
@@ -144,5 +144,10 @@ export type TMutationVariables = {
144
144
  [key: string]: string;
145
145
  };
146
146
  } | void;
147
+ export type ServerContext = {
148
+ req: {
149
+ originalUrl?: string;
150
+ };
151
+ };
147
152
  export {};
148
153
  //# sourceMappingURL=types.d.ts.map
@@ -87,7 +87,7 @@ const cacheUpdateMatrix = {
87
87
  loginGuestUser: noop,
88
88
  logout() {
89
89
  return {
90
- remove: [{
90
+ invalidate: [{
91
91
  queryKey: ['/commerce-sdk-react']
92
92
  }]
93
93
  };
@@ -42,7 +42,7 @@ const useAuthorizationHeader = method => {
42
42
  headers: _objectSpread({
43
43
  Authorization: `Bearer ${access_token}`
44
44
  }, options.headers)
45
- })).catch( /*#__PURE__*/function () {
45
+ })).catch(/*#__PURE__*/function () {
46
46
  var _ref2 = _asyncToGenerator(function* (error) {
47
47
  const {
48
48
  access_token
@@ -61,7 +61,7 @@ const useCustomMutation = (apiOptions, mutationOptions) => {
61
61
  const {
62
62
  access_token
63
63
  } = yield auth.ready();
64
- return yield _commerceSdkIsomorphic.helpers.callCustomEndpoint((0, _helpers.generateCustomEndpointOptions)(apiOptions, globalConfig, access_token, args)).catch( /*#__PURE__*/function () {
64
+ return yield _commerceSdkIsomorphic.helpers.callCustomEndpoint((0, _helpers.generateCustomEndpointOptions)(apiOptions, globalConfig, access_token, args)).catch(/*#__PURE__*/function () {
65
65
  var _ref2 = _asyncToGenerator(function* (error) {
66
66
  const {
67
67
  access_token
package/hooks/useQuery.js CHANGED
@@ -86,7 +86,7 @@ const useCustomQuery = (apiOptions, queryOptions) => {
86
86
  access_token
87
87
  } = yield auth.ready();
88
88
  const customEndpointOptions = (0, _helpers.generateCustomEndpointOptions)(options, config, access_token);
89
- return yield _commerceSdkIsomorphic.helpers.callCustomEndpoint(customEndpointOptions).catch( /*#__PURE__*/function () {
89
+ return yield _commerceSdkIsomorphic.helpers.callCustomEndpoint(customEndpointOptions).catch(/*#__PURE__*/function () {
90
90
  var _ref3 = _asyncToGenerator(function* (error) {
91
91
  const {
92
92
  access_token
@@ -127,7 +127,7 @@ const useTrustedAgent = () => {
127
127
  const authorizeTrustedAgent = (0, _reactQuery.useMutation)(auth.authorizeTrustedAgent.bind(auth));
128
128
  const loginTrustedAgent = (0, _reactQuery.useMutation)(auth.loginTrustedAgent.bind(auth));
129
129
  const logoutTrustedAgent = (0, _reactQuery.useMutation)(auth.logout.bind(auth));
130
- const login = (0, _react.useCallback)( /*#__PURE__*/function () {
130
+ const login = (0, _react.useCallback)(/*#__PURE__*/function () {
131
131
  var _ref2 = _asyncToGenerator(function* (loginId, usid, refresh = false) {
132
132
  if (!(0, _utils.onClient)()) {
133
133
  throw new Error('Something went wrong, this client side method is invoked on the server.');
@@ -154,7 +154,7 @@ const useTrustedAgent = () => {
154
154
  return _ref2.apply(this, arguments);
155
155
  };
156
156
  }(), [auth]);
157
- const logout = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator(function* () {
157
+ const logout = (0, _react.useCallback)(/*#__PURE__*/_asyncToGenerator(function* () {
158
158
  return yield logoutTrustedAgent.mutateAsync();
159
159
  }), [auth]);
160
160
  (0, _react.useEffect)(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/commerce-sdk-react",
3
- "version": "3.2.1",
3
+ "version": "3.3.0-extensibility-preview.4",
4
4
  "description": "A library that provides react hooks for fetching data from Commerce Cloud",
5
5
  "homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/ecom-react-hooks#readme",
6
6
  "bugs": {
@@ -40,12 +40,12 @@
40
40
  "version": "node ./scripts/version.js"
41
41
  },
42
42
  "dependencies": {
43
- "commerce-sdk-isomorphic": "^3.2.0",
43
+ "commerce-sdk-isomorphic": "^3.3.0",
44
44
  "js-cookie": "^3.0.1",
45
45
  "jwt-decode": "^4.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@salesforce/pwa-kit-dev": "3.9.1",
48
+ "@salesforce/pwa-kit-dev": "4.0.0-extensibility-preview.4",
49
49
  "@tanstack/react-query": "^4.28.0",
50
50
  "@testing-library/jest-dom": "^5.16.5",
51
51
  "@testing-library/react": "^14.0.0",
@@ -60,7 +60,7 @@
60
60
  "@types/react-helmet": "~6.1.6",
61
61
  "@types/react-router-dom": "~5.3.3",
62
62
  "cross-env": "^5.2.1",
63
- "internal-lib-build": "3.9.1",
63
+ "internal-lib-build": "4.0.0-extensibility-preview.4",
64
64
  "jsonwebtoken": "^9.0.0",
65
65
  "nock": "^13.3.0",
66
66
  "nodemon": "^2.0.22",
@@ -69,7 +69,7 @@
69
69
  "react-helmet": "^6.1.0",
70
70
  "react-router-dom": "^5.3.4",
71
71
  "semver": "^7.5.2",
72
- "shelljs": "^0.8.5",
72
+ "shelljs": "^0.9.2",
73
73
  "typedoc": "^0.24.7",
74
74
  "typedoc-plugin-missing-exports": "^2.0.0",
75
75
  "typescript": "4.9.5"
@@ -90,5 +90,5 @@
90
90
  "publishConfig": {
91
91
  "directory": "dist"
92
92
  },
93
- "gitHead": "c31cd5055676a26c8b632c53b8193cfd331503de"
93
+ "gitHead": "5ad3b1f0e598cfe0fbdec5b1212b4dabc0a8733c"
94
94
  }
package/provider.d.ts CHANGED
@@ -20,6 +20,7 @@ export interface CommerceApiProviderProps extends ApiClientConfigParams {
20
20
  passwordlessLoginCallbackURI?: string;
21
21
  refreshTokenRegisteredCookieTTL?: number;
22
22
  refreshTokenGuestCookieTTL?: number;
23
+ OCAPISessionsURL?: string;
23
24
  }
24
25
  /**
25
26
  * @internal
package/utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { CookieAttributes } from 'js-cookie';
2
+ import { helpers } from 'commerce-sdk-isomorphic';
2
3
  /** Utility to determine if you are on the browser (client) or not. */
3
4
  export declare const onClient: () => boolean;
4
5
  /** Detects whether the storefront is running in an iframe. */
@@ -58,4 +59,15 @@ export declare function isAbsoluteUrl(url: string): boolean;
58
59
  * that uses `Buffer` to perform the Base64 encoding.
59
60
  */
60
61
  export declare const stringToBase64: typeof btoa;
62
+ /**
63
+ * Extracts custom parameters from a set of SCAPI parameters
64
+ *
65
+ * Custom parameters are identified by the 'c_' prefix before their key
66
+ *
67
+ * @param parameters object containing all parameters for a SCAPI / SLAS call
68
+ * @returns new object containing only custom parameters
69
+ */
70
+ export declare const extractCustomParameters: (parameters: {
71
+ [key: string]: string | number | boolean | string[] | number[];
72
+ } | null) => helpers.CustomQueryParameters | helpers.CustomRequestBody;
61
73
  //# sourceMappingURL=utils.d.ts.map
package/utils.js CHANGED
@@ -7,7 +7,7 @@ exports.DEVELOPMENT_ORIGIN = void 0;
7
7
  exports.detectCookiesAvailable = detectCookiesAvailable;
8
8
  exports.detectInIframe = void 0;
9
9
  exports.detectLocalStorageAvailable = detectLocalStorageAvailable;
10
- exports.getParentOrigin = exports.getDefaultCookieAttributes = exports.getCookieSameSiteAttribute = void 0;
10
+ exports.getParentOrigin = exports.getDefaultCookieAttributes = exports.getCookieSameSiteAttribute = exports.extractCustomParameters = void 0;
11
11
  exports.isAbsoluteUrl = isAbsoluteUrl;
12
12
  exports.stringToBase64 = exports.onClient = exports.isOriginTrusted = void 0;
13
13
  var _jsCookie = _interopRequireDefault(require("js-cookie"));
@@ -154,4 +154,20 @@ function isAbsoluteUrl(url) {
154
154
  * - In a non-browser environment (like Node.js), a fallback is provided
155
155
  * that uses `Buffer` to perform the Base64 encoding.
156
156
  */
157
- const stringToBase64 = exports.stringToBase64 = typeof window === 'object' && typeof window.document === 'object' ? btoa : unencoded => Buffer.from(unencoded).toString('base64');
157
+ const stringToBase64 = exports.stringToBase64 = typeof window === 'object' && typeof window.document === 'object' ? btoa : unencoded => Buffer.from(unencoded).toString('base64');
158
+
159
+ /**
160
+ * Extracts custom parameters from a set of SCAPI parameters
161
+ *
162
+ * Custom parameters are identified by the 'c_' prefix before their key
163
+ *
164
+ * @param parameters object containing all parameters for a SCAPI / SLAS call
165
+ * @returns new object containing only custom parameters
166
+ */
167
+ const extractCustomParameters = parameters => {
168
+ if (typeof parameters !== 'object' || parameters === null) {
169
+ throw new Error('Invalid input. Expecting an object as an input.');
170
+ }
171
+ return Object.fromEntries(Object.entries(parameters).filter(([key]) => key.startsWith('c_')));
172
+ };
173
+ exports.extractCustomParameters = extractCustomParameters;