@salesforce/pwa-kit-react-sdk 3.8.0-preview.1-basepath → 3.8.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.
package/CHANGELOG.md CHANGED
@@ -1,19 +1,6 @@
1
- ## v3.8.0-preview.1-basepath (Sep 05, 2024)
2
- ## v3.8.0-preview.4-basepath (Sep 05, 2024)
3
- ## v3.8.0-preview.4-basepath (Sep 05, 2024)
4
- ## v3.8.0-preview.3-basepath (Sep 05, 2024)
5
- ## v3.8.0-preview.3-basepath (Sep 05, 2024)
6
- ## v3.8.0-preview.1-basepath (Sep 05, 2024)
7
- ## v3.8.0-preview.2-basepath (Sep 05, 2024)
8
- ## v3.8.0-preview.1-basepath (Sep 05, 2024)
9
- ## v3.8.0-preview.1-basepath (Sep 05, 2024)
10
- ## v3.8.0-preview.0-basepath (Sep 05, 2024)
11
- ## v3.8.0-preview.0 (Sep 05, 2024)
12
- ## v3.8.0-preview.basepath (Sep 05, 2024)
13
- ## v3.8.0-dev (Aug 08, 2024)
14
-
15
- - Add support for environment level base paths, a new configuration option `envBasePath` [#1970](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1970)
16
- - Add support for React Router level base paths, a new `getBasePath` method to the `AppConfig` component [#1988](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1988)
1
+ ## v3.8.0 (Oct 28, 2024)
2
+ - [Server Affinity] - Attach dwsid to SCAPI request headers [#2090](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2090)
3
+ - Create useOrigin hook to return an app origin that takes x-forwarded-host header into consideration. [#2050](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2050)
17
4
 
18
5
  ## v3.7.0 (Aug 07, 2024)
19
6
  - Add `beforeHydrate` option to withReactQuery component [#1912](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1912)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/pwa-kit-react-sdk",
3
- "version": "3.8.0-preview.1-basepath",
3
+ "version": "3.8.0",
4
4
  "description": "A library that supports the isomorphic React rendering pipeline for Commerce Cloud Managed Runtime apps",
5
5
  "homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/pwa-kit-react-sdk#readme",
6
6
  "bugs": {
@@ -37,7 +37,7 @@
37
37
  "@loadable/babel-plugin": "^5.15.3",
38
38
  "@loadable/server": "^5.15.3",
39
39
  "@loadable/webpack-plugin": "^5.15.2",
40
- "@salesforce/pwa-kit-runtime": "3.8.0-preview.1-basepath",
40
+ "@salesforce/pwa-kit-runtime": "3.8.0",
41
41
  "@tanstack/react-query": "^4.28.0",
42
42
  "cross-env": "^5.2.1",
43
43
  "event-emitter": "^0.3.5",
@@ -50,11 +50,11 @@
50
50
  },
51
51
  "devDependencies": {
52
52
  "@loadable/component": "^5.15.3",
53
- "@salesforce/pwa-kit-dev": "3.8.0-preview.1-basepath",
53
+ "@salesforce/pwa-kit-dev": "3.8.0",
54
54
  "@testing-library/jest-dom": "^5.16.5",
55
55
  "@testing-library/react": "^14.0.0",
56
56
  "@testing-library/user-event": "^14.4.3",
57
- "internal-lib-build": "3.8.0-preview.1-basepath",
57
+ "internal-lib-build": "3.8.0",
58
58
  "node-html-parser": "^3.3.6",
59
59
  "nodemon": "^2.0.22",
60
60
  "react": "^18.2.0",
@@ -79,5 +79,5 @@
79
79
  "publishConfig": {
80
80
  "directory": "dist"
81
81
  },
82
- "gitHead": "8704488ab2d14e7545c6acbe83fa1d4a330c6289"
82
+ "gitHead": "d6ed7107a4087093442b125f8cc212302046ab7e"
83
83
  }
@@ -48,18 +48,12 @@ const OuterApp = ({
48
48
  locals,
49
49
  onHydrate
50
50
  }) => {
51
- var _AppConfig$getBasePat, _AppConfig$getBasePat2;
52
51
  const AppConfig = (0, _compatibility.getAppConfig)();
53
52
  const isInitialPageRef = (0, _react.useRef)(true);
54
- const basepath = ((_AppConfig$getBasePat = AppConfig.getBasePath) === null || _AppConfig$getBasePat === void 0 ? void 0 : (_AppConfig$getBasePat2 = _AppConfig$getBasePat.call(AppConfig, {
55
- req: undefined,
56
- res: undefined
57
- })) === null || _AppConfig$getBasePat2 === void 0 ? void 0 : _AppConfig$getBasePat2.replace(/\/$/, '')) || '';
58
53
  return /*#__PURE__*/_react.default.createElement(_contexts.ServerContext.Provider, {
59
54
  value: {}
60
55
  }, /*#__PURE__*/_react.default.createElement(_reactRouterDom.BrowserRouter, {
61
- ref: onHydrate,
62
- basename: basepath
56
+ ref: onHydrate
63
57
  }, /*#__PURE__*/_react.default.createElement(_contexts.CorrelationIdProvider, {
64
58
  correlationId: () => {
65
59
  // If we are hydrating an error page use the server correlation id.
@@ -121,7 +121,7 @@ const getLocationSearch = (req, opts = {}) => {
121
121
  exports.getLocationSearch = getLocationSearch;
122
122
  const render = exports.render = /*#__PURE__*/function () {
123
123
  var _ref = _asyncToGenerator(function* (req, res, next) {
124
- var _config$app, _config$app$url, _AppConfig$getBasePat, _AppConfig$getBasePat2;
124
+ var _config$app, _config$app$url;
125
125
  const includeServerTimingHeader = ('__server_timing' in req.query);
126
126
  const shouldTrackPerformance = includeServerTimingHeader || process.env.SERVER_TIMING;
127
127
  res.__performanceTimer = new _performance.default({
@@ -146,15 +146,7 @@ const render = exports.render = /*#__PURE__*/function () {
146
146
  res.__performanceTimer.mark(_performance.PERFORMANCE_MARKS.routeMatching, 'start');
147
147
  let route;
148
148
  let match;
149
- const basepath = ((_AppConfig$getBasePat = AppConfig.getBasePath) === null || _AppConfig$getBasePat === void 0 ? void 0 : (_AppConfig$getBasePat2 = _AppConfig$getBasePat.call(AppConfig, {
150
- req,
151
- res
152
- })) === null || _AppConfig$getBasePat2 === void 0 ? void 0 : _AppConfig$getBasePat2.replace(/\/$/, '')) || '';
153
- routes.some(r => {
154
- let _route = _objectSpread({}, r);
155
- if (basepath && _route !== null && _route !== void 0 && _route.path) {
156
- _route.path = `${basepath}${_route.path}`;
157
- }
149
+ routes.some(_route => {
158
150
  const _match = (0, _reactRouterDom.matchPath)(req.path, _route);
159
151
  if (_match) {
160
152
  match = _match;
@@ -267,12 +259,7 @@ const OuterApp = ({
267
259
  routerContext,
268
260
  location
269
261
  }) => {
270
- var _AppConfig$getBasePat3, _AppConfig$getBasePat4;
271
262
  const AppConfig = (0, _compatibility.getAppConfig)();
272
- const basepath = ((_AppConfig$getBasePat3 = AppConfig.getBasePath) === null || _AppConfig$getBasePat3 === void 0 ? void 0 : (_AppConfig$getBasePat4 = _AppConfig$getBasePat3.call(AppConfig, {
273
- req,
274
- res
275
- })) === null || _AppConfig$getBasePat4 === void 0 ? void 0 : _AppConfig$getBasePat4.replace(/\/$/, '')) || '';
276
263
  return /*#__PURE__*/_react.default.createElement(_contexts.ServerContext.Provider, {
277
264
  value: {
278
265
  req,
@@ -280,8 +267,7 @@ const OuterApp = ({
280
267
  }
281
268
  }, /*#__PURE__*/_react.default.createElement(_reactRouterDom.StaticRouter, {
282
269
  location: location,
283
- context: routerContext,
284
- basename: basepath
270
+ context: routerContext
285
271
  }, /*#__PURE__*/_react.default.createElement(_contexts.CorrelationIdProvider, {
286
272
  correlationId: res.locals.requestId,
287
273
  resetOnPageChange: false
@@ -59,8 +59,7 @@ jest.mock('../universal/routes', () => {
59
59
  const PropTypes = require('prop-types');
60
60
  const errors = require('../universal/errors');
61
61
  const {
62
- Redirect,
63
- Link
62
+ Redirect
64
63
  } = require('react-router-dom');
65
64
  const {
66
65
  Helmet
@@ -93,9 +92,7 @@ jest.mock('../universal/routes', () => {
93
92
  return 'templateName';
94
93
  }
95
94
  render() {
96
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", null, "This is a PWA"), /*#__PURE__*/React.createElement(Link, {
97
- to: "/link"
98
- }, "This is a link (for Router basepath testing)"));
95
+ return /*#__PURE__*/React.createElement("div", null, "This is a PWA");
99
96
  }
100
97
  }
101
98
  class UnknownErrorPage extends React.Component {
@@ -637,44 +634,6 @@ describe('The Node SSR Environment', () => {
637
634
  const shouldIncludeErrorStack = !(0, _ssrServer.isRemote)();
638
635
  expect(html).toContain(shouldIncludeErrorStack ? 'Error: ' : 'Internal Server Error');
639
636
  }
640
- }, {
641
- description: `AppConfig getBasePath works correctly`,
642
- req: {
643
- url: '/base/pwa'
644
- },
645
- mocks: () => {
646
- const AppConfig = (0, _compatibility.getAppConfig)();
647
- jest.spyOn(AppConfig, 'getBasePath').mockImplementation(() => {
648
- return '/base';
649
- });
650
- },
651
- assertions: res => {
652
- expect(res.statusCode).toBe(200);
653
- const html = res.text;
654
- const doc = (0, _nodeHtmlParser.parse)(html);
655
- const links = doc.querySelectorAll('a');
656
- links.forEach(link => {
657
- const href = link.getAttribute('href');
658
- expect(href.startsWith('/base')).toBe(true);
659
- });
660
- expect(html).toContain('This is a PWA');
661
- }
662
- }, {
663
- description: `AppConfig getBasePath works correctly when it is empty string`,
664
- req: {
665
- url: '/pwa'
666
- },
667
- mocks: () => {
668
- const AppConfig = (0, _compatibility.getAppConfig)();
669
- jest.spyOn(AppConfig, 'getBasePath').mockImplementation(() => {
670
- return '';
671
- });
672
- },
673
- assertions: res => {
674
- expect(res.statusCode).toBe(200);
675
- const html = res.text;
676
- expect(html).toContain('This is a PWA');
677
- }
678
637
  }, {
679
638
  description: `Works if the user resolves an Object with useQuery`,
680
639
  req: {
@@ -72,23 +72,6 @@ class AppConfig extends _react.default.Component {
72
72
  return {};
73
73
  }
74
74
 
75
- /**
76
- * Returns a base path to be included in all URLs.
77
- * For example, www.example.com/basepath/category/...
78
- *
79
- * @param params.req - the Express.js request object (undefined on the client)
80
- * @param params.res - the Express.js response object (undefined on the client)
81
- *
82
- * @return string - the base path (no trailing slash)
83
- */
84
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
85
- static getBasePath({
86
- req,
87
- res
88
- }) {
89
- return '';
90
- }
91
-
92
75
  /**
93
76
  * This class is a React Component in order to provide this hook, which lets
94
77
  * you set up context Providers for a state-management library such as Redux.
@@ -17,6 +17,5 @@ describe('The default AppConfig', () => {
17
17
  })).toBeUndefined();
18
18
  expect(_index.default.freeze()).toBeUndefined();
19
19
  expect(_index.default.extraGetPropsArgs()).toEqual({});
20
- expect(_index.default.getBasePath({})).toBe('');
21
20
  });
22
21
  });
@@ -3,13 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useServerContext = exports.useCorrelationId = void 0;
6
+ exports.useServerContext = exports.useOrigin = exports.useCorrelationId = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _contexts = require("../contexts");
9
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
11
  /*
12
- * Copyright (c) 2022, salesforce.com, inc.
12
+ * Copyright (c) 2024, salesforce.com, inc.
13
13
  * All rights reserved.
14
14
  * SPDX-License-Identifier: BSD-3-Clause
15
15
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
@@ -49,4 +49,36 @@ const useServerContext = () => {
49
49
  const serverContext = (0, _react.useContext)(_contexts.ServerContext);
50
50
  return serverContext;
51
51
  };
52
- exports.useServerContext = useServerContext;
52
+
53
+ /**
54
+ * Returns the application's origin.
55
+ *
56
+ * By default, it will return the ORIGIN under which we are serving the page.
57
+ *
58
+ * If `fromXForwardedHeader` is true, it will use the value of `x-forwarded-proto` and `x-forwarded-host` headers in req
59
+ * to build origin. (it is false by default)
60
+ *
61
+ * NOTE: this is a React hook, so it has to be used in a React rendering pipeline.
62
+ * @returns {string} origin string
63
+ *
64
+ */
65
+ exports.useServerContext = useServerContext;
66
+ const useOrigin = ({
67
+ fromXForwardedHeader = false
68
+ }) => {
69
+ const {
70
+ res
71
+ } = useServerContext();
72
+ if (typeof window !== 'undefined') {
73
+ return window.location.origin;
74
+ }
75
+ const {
76
+ APP_ORIGIN
77
+ } = process.env;
78
+ const xForwardedOrigin = res.locals.xForwardedOrigin;
79
+ if (fromXForwardedHeader && xForwardedOrigin) {
80
+ return xForwardedOrigin;
81
+ }
82
+ return APP_ORIGIN;
83
+ };
84
+ exports.useOrigin = useOrigin;
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getProxyConfigs = exports.getAssetUrl = void 0;
7
7
  var _ssrShared = require("@salesforce/pwa-kit-runtime/utils/ssr-shared");
8
- var _ssrPaths = require("@salesforce/pwa-kit-runtime/utils/ssr-paths");
8
+ var _ssrNamespacePaths = require("@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths");
9
9
  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; }
10
10
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
11
  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; }
@@ -29,7 +29,7 @@ const onClient = typeof window !== 'undefined';
29
29
  */
30
30
  const getAssetUrl = path => {
31
31
  /* istanbul ignore next */
32
- const publicPath = onClient ? `${window.Progressive.buildOrigin}` : `${(0, _ssrPaths.getBundlePath)()}/${process.env.BUNDLE_ID || 'development'}/`;
32
+ const publicPath = onClient ? `${window.Progressive.buildOrigin}` : `${_ssrNamespacePaths.bundleBasePath}/${process.env.BUNDLE_ID || 'development'}/`;
33
33
  return path ? `${publicPath}${path}` : publicPath;
34
34
  };
35
35
 
package/utils/url.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getAppOrigin = void 0;
7
7
  /*
8
- * Copyright (c) 2021, salesforce.com, inc.
8
+ * Copyright (c) 2024, salesforce.com, inc.
9
9
  * All rights reserved.
10
10
  * SPDX-License-Identifier: BSD-3-Clause
11
11
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
@@ -18,6 +18,8 @@ exports.getAppOrigin = void 0;
18
18
  * initialized using the `_createApp` method (This happens in your /app/ssr.js file).
19
19
  *
20
20
  * @function
21
+ * @deprecated use `useOrigin()` instead.
22
+ * This function will be removed in version 4.0.0.
21
23
  * @returns {string} Returns the ORIGIN under which we are serving the page.
22
24
  * @example
23
25
  * import {getAppOrigin} from '@salesforce/pwa-kit-react-sdk/utils/url'