Skip to content

Commit 69518a5

Browse files
committed
Merge branch 'develop' into v3/template-retail-react-app
2 parents 5ad2b76 + b79d8d1 commit 69518a5

File tree

21 files changed

+165
-48
lines changed

21 files changed

+165
-48
lines changed

packages/commerce-sdk-react/src/auth/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {BaseStorage, LocalStorage, CookieStorage, MemoryStorage, StorageType} fr
1717
import {CustomerType} from '../hooks/useCustomerType'
1818
import {getParentOrigin, isOriginTrusted, onClient} from '../utils'
1919
import {
20+
MOBIFY_PATH,
21+
SLAS_PRIVATE_PROXY_PATH,
2022
SLAS_SECRET_WARNING_MSG,
2123
SLAS_SECRET_PLACEHOLDER,
2224
SLAS_SECRET_OVERRIDE_MSG
@@ -178,9 +180,9 @@ class Auth {
178180
private logger: Logger
179181

180182
constructor(config: AuthConfig) {
181-
// Special endpoint for injecting SLAS private client secret
182-
const baseUrl = config.proxy.split(`/mobify/proxy/api`)[0]
183-
const privateClientEndpoint = `${baseUrl}/mobify/slas/private`
183+
// Special endpoint for injecting SLAS private client secret.
184+
const baseUrl = config.proxy.split(MOBIFY_PATH)[0]
185+
const privateClientEndpoint = `${baseUrl}${SLAS_PRIVATE_PROXY_PATH}`
184186

185187
this.client = new ShopperLogin({
186188
proxy: config.enablePWAKitPrivateClient ? privateClientEndpoint : config.proxy,

packages/commerce-sdk-react/src/components/StorefrontPreview/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import {ApiClients} from '../../hooks/types'
99
import {DEVELOPMENT_ORIGIN, getParentOrigin, isOriginTrusted} from '../../utils'
10+
import {LOCAL_BUNDLE_PATH} from '../../constant'
1011

1112
/** Detects whether the storefront is running in an iframe as part of Storefront Preview.
1213
* @private
@@ -16,13 +17,15 @@ export const detectStorefrontPreview = () => {
1617
return isOriginTrusted(parentOrigin)
1718
}
1819

19-
/** Returns the URL to load the Storefront Preview client script from the parent origin.
20+
/**
21+
* Returns the URL to load the Storefront Preview client script from the parent origin.
22+
* The client script is served from Runtime Admin and is not a part of the PWA Retail React App bundle.
2023
* @private
2124
*/
2225
export const getClientScript = () => {
2326
const parentOrigin = getParentOrigin() ?? 'https://runtime.commercecloud.com'
2427
return parentOrigin === DEVELOPMENT_ORIGIN
25-
? `${parentOrigin}/mobify/bundle/development/static/storefront-preview.js`
28+
? `${parentOrigin}${LOCAL_BUNDLE_PATH}/static/storefront-preview.js`
2629
: `${parentOrigin}/cc/b2c/preview/preview.client.js`
2730
}
2831

packages/commerce-sdk-react/src/constant.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export const IFRAME_HOST_ALLOW_LIST = Object.freeze([
1414
'https://runtime-admin-preview.mobify-storefront.com'
1515
])
1616

17+
// We hardcode these here since we don't want commerce-sdk-react to have a dependency on pwa-kit-runtime
18+
export const MOBIFY_PATH = '/mobify'
19+
export const PROXY_PATH = `${MOBIFY_PATH}/proxy`
20+
export const LOCAL_BUNDLE_PATH = `${MOBIFY_PATH}/bundle/development`
21+
export const SLAS_PRIVATE_PROXY_PATH = `${MOBIFY_PATH}/slas/private`
22+
1723
export const SLAS_SECRET_WARNING_MSG =
1824
'You are potentially exposing SLAS secret on browser. Make sure to keep it safe and secure!'
1925

packages/commerce-sdk-react/src/test-utils.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import {
1616
import nock from 'nock'
1717
import CommerceApiProvider, {CommerceApiProviderProps} from './provider'
1818
import userEvent from '@testing-library/user-event'
19+
import {PROXY_PATH} from './constant'
20+
1921
// Note: this host does NOT exist
2022
// it is intentional b/c we can catch those unintercepted requests
2123
// from log easily. You should always make sure all requests are nocked.
2224
export const DEFAULT_TEST_HOST = 'http://localhost:8888'
2325

2426
export const DEFAULT_TEST_CONFIG = {
25-
proxy: `${DEFAULT_TEST_HOST}/mobify/proxy/api`,
27+
proxy: `${DEFAULT_TEST_HOST}${PROXY_PATH}/api`,
2628
redirectURI: `${DEFAULT_TEST_HOST}/callback`,
2729
clientId: '12345678-1234-1234-1234-123412341234',
2830
organizationId: 'f_ecom_zzrmy_orgf_001',
@@ -31,7 +33,7 @@ export const DEFAULT_TEST_CONFIG = {
3133
locale: 'en-US',
3234
currency: 'USD',
3335
fetchedToken: 'test-token',
34-
OCAPISessionsURL: `${DEFAULT_TEST_HOST}/mobify/proxy/ocapi/s/RefArch/dw/shop/v22_8/sessions`
36+
OCAPISessionsURL: `${DEFAULT_TEST_HOST}${PROXY_PATH}/ocapi/s/RefArch/dw/shop/v22_8/sessions`
3537
}
3638

3739
export const createQueryClient = () => {

packages/pwa-kit-create-app/assets/bootstrap/js/overrides/app/components/_app-config/index.jsx.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
resolveLocaleFromUrl
1919
} from '@salesforce/retail-react-app/app/utils/site-utils'
2020
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
21+
import {proxyBasePath} from '@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths'
2122
import {createUrlTemplate} from '@salesforce/retail-react-app/app/utils/url'
2223

2324
import {CommerceApiProvider} from '@salesforce/commerce-sdk-react'
@@ -55,7 +56,7 @@ const AppConfig = ({children, locals = {}}) => {
5556
redirectURI={`${appOrigin}/callback`}
5657
proxy={`${appOrigin}${commerceApiConfig.proxyPath}`}
5758
headers={headers}
58-
OCAPISessionsURL={`${appOrigin}/mobify/proxy/ocapi/s/${locals.site?.id}/dw/shop/v22_8/sessions`}
59+
OCAPISessionsURL={`${appOrigin}${proxyBasePath}/ocapi/s/${locals.site?.id}/dw/shop/v22_8/sessions`}
5960
{{#if answers.project.commerce.isSlasPrivate}}
6061
// Set 'enablePWAKitPrivateClient' to true use SLAS private client login flows.
6162
// Make sure to also enable useSLASPrivateClient in ssr.js when enabling this setting.

packages/pwa-kit-create-app/assets/templates/@salesforce/retail-react-app/app/components/_app-config/index.jsx.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
resolveLocaleFromUrl
1919
} from '@salesforce/retail-react-app/app/utils/site-utils'
2020
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
21+
import {proxyBasePath} from '@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths'
2122
import {createUrlTemplate} from '@salesforce/retail-react-app/app/utils/url'
2223

2324
import {CommerceApiProvider} from '@salesforce/commerce-sdk-react'
@@ -55,7 +56,7 @@ const AppConfig = ({children, locals = {}}) => {
5556
redirectURI={`${appOrigin}/callback`}
5657
proxy={`${appOrigin}${commerceApiConfig.proxyPath}`}
5758
headers={headers}
58-
OCAPISessionsURL={`${appOrigin}/mobify/proxy/ocapi/s/${locals.site?.id}/dw/shop/v22_8/sessions`}
59+
OCAPISessionsURL={`${appOrigin}${proxyBasePath}/ocapi/s/${locals.site?.id}/dw/shop/v22_8/sessions`}
5960
{{#if answers.project.commerce.isSlasPrivate}}
6061
// Set 'enablePWAKitPrivateClient' to true use SLAS private client login flows.
6162
// Make sure to also enable useSLASPrivateClient in ssr.js when enabling this setting.

packages/pwa-kit-dev/src/configs/jest/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ module.exports = {
2626
DEBUG: true,
2727
NODE_ENV: 'test',
2828
Progressive: {
29+
// BuildOrigin can be any non-empty string. It does not have to be /mobify/xyz
30+
// This is used by tests that call getAssetUrl in pwa-kit-react-sdk to simulate
31+
// asset urls.
2932
buildOrigin: '/mobify/bundle/development/'
3033
}
3134
},

packages/pwa-kit-dev/src/configs/webpack/config.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ const getAppEntryPoint = () => {
121121
return resolve('./', EXT_OVERRIDES_DIR_NO_SLASH, 'app', 'main')
122122
}
123123

124+
const getPublicPathEntryPoint = () => {
125+
return resolve(
126+
projectDir,
127+
'node_modules',
128+
'@salesforce',
129+
'pwa-kit-dev',
130+
'ssr',
131+
'server',
132+
'public-path'
133+
)
134+
}
135+
124136
const findDepInStack = (pkg) => {
125137
// Look for the SDK node_modules in two places because in CI,
126138
// pwa-kit-dev is published under a 'dist' directory, which
@@ -394,7 +406,11 @@ const enableReactRefresh = (config) => {
394406
},
395407
entry: {
396408
...config.entry,
397-
main: ['webpack-hot-middleware/client?path=/__mrt/hmr', getAppEntryPoint()]
409+
main: [
410+
'webpack-hot-middleware/client?path=/__mrt/hmr',
411+
getPublicPathEntryPoint(),
412+
getAppEntryPoint()
413+
]
398414
},
399415
plugins: [
400416
...config.plugins,
@@ -403,12 +419,7 @@ const enableReactRefresh = (config) => {
403419
new ReactRefreshWebpackPlugin({
404420
overlay: false
405421
})
406-
],
407-
output: {
408-
...config.output,
409-
// Setting this so that *.hot-update.json requests are resolving
410-
publicPath: '/mobify/bundle/development/'
411-
}
422+
]
412423
}
413424
}
414425

packages/pwa-kit-dev/src/ssr/server/build-dev-server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import open from 'open'
1919
import requireFromString from 'require-from-string'
2020
import {RemoteServerFactory} from '@salesforce/pwa-kit-runtime/ssr/server/build-remote-server'
2121
import {proxyConfigs} from '@salesforce/pwa-kit-runtime/utils/ssr-shared'
22+
import {bundleBasePath} from '@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths'
2223
import {
2324
SERVER,
2425
CLIENT,
@@ -166,7 +167,7 @@ export const DevServerMixin = {
166167
app.__hotServerMiddleware = webpackHotServerMiddleware(app.__compiler)
167168
}
168169

169-
app.use('/mobify/bundle/development', app.__devMiddleware)
170+
app.use(`${bundleBasePath}/development`, app.__devMiddleware)
170171

171172
app.__hmrMiddleware = (_, res) => res.status(501).send('Hot Module Reloading is disabled.')
172173
const clientCompiler = app.__compiler.compilers.find((compiler) => compiler.name === CLIENT)
@@ -209,7 +210,7 @@ export const DevServerMixin = {
209210
// Proxy bundle asset requests to the local
210211
// build directory.
211212
app.use(
212-
'/mobify/bundle/development',
213+
`${bundleBasePath}/development`,
213214
express.static(path.resolve(process.cwd(), 'src'), {
214215
dotFiles: 'deny',
215216
setHeaders: setLocalAssetHeaders,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2024, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
/**
9+
* This file is used to dynamically set the webpack public path used by HMR via the global webpack variable
10+
* __webpack_public_path__
11+
* See https://webpack.js.org/guides/public-path/
12+
*
13+
* Previously, we hard coded the public path in our webpack config to '/mobify/bundle/development/'
14+
* but we need something more dynamic to support namespaced /mobify paths.
15+
*/
16+
17+
import {bundleBasePath} from '@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths'
18+
19+
/* global __webpack_public_path__: writable */
20+
__webpack_public_path__ = `${bundleBasePath}/development/`

0 commit comments

Comments
 (0)