Skip to content

Commit 23c195a

Browse files
committed
Merge branch 'develop' into feature/template-extensibility-algo-refactor
* develop: (34 commits) [Phased Launch] Call Session bridge after login (#1220) [v3] Add multi-site suffix to auth token keys (#1208) Footer: fix hydration error with the locale dropdown (#1210) remove unused peerDependency @chakra-ui/system (#1212) @W-12582733: Expose env vars endpoint for E2E smoke tests (#1207) Upgrade to React 18 (#1166) Remove v3 branch name related actions (#1206) add test to reach test coverage threshold remove commerce-api folder Feature: Extract einstein RefArch-specific values to constant (#1200) Bump version number to 2.7.1 and update changelogs (#1197) store usid in cookies (#1193) make sure static files are copied on dev environment (#1196) [WIP] PWA Kit 2.7.1 release (#1181) [V2] Internal lib build typescript dev dependency (#1194) [V2] Re-generate lock files and fix hook lib tests (#1186) Add additional properties to ShopperLogin test types (#1185) Revert 2.7.0 branch to prep for 2.7.1 changes (#1182) #1174 Replace invalid value for wrap property (#1179) Add a redirect to login page after user signs out from checkout page (#1172) ... # Conflicts: # package-lock.json # packages/commerce-sdk-react/CHANGELOG.md # packages/commerce-sdk-react/package-lock.json # packages/internal-lib-build/package-lock.json # packages/pwa-kit-create-app/package-lock.json # packages/pwa-kit-dev/package-lock.json # packages/pwa-kit-dev/package.json # packages/pwa-kit-react-sdk/package-lock.json # packages/pwa-kit-runtime/package-lock.json # packages/template-mrt-reference-app/package-lock.json # packages/template-retail-react-app/app/components/confirmation-modal/index.test.js # packages/template-retail-react-app/app/components/footer/index.jsx # packages/template-retail-react-app/app/components/header/index.jsx # packages/template-retail-react-app/app/components/list-menu/index.test.js # packages/template-retail-react-app/app/components/product-scroller/index.test.js # packages/template-retail-react-app/app/components/product-view-modal/index.test.js # packages/template-retail-react-app/app/components/search/index.test.js # packages/template-retail-react-app/app/hoc/with-registration/index.test.js # packages/template-retail-react-app/app/hooks/use-add-to-cart-modal.js # packages/template-retail-react-app/app/hooks/use-auth-modal.test.js # packages/template-retail-react-app/app/hooks/use-currency.test.js # packages/template-retail-react-app/app/hooks/use-multi-site.test.js # packages/template-retail-react-app/app/hooks/use-navigation.test.js # packages/template-retail-react-app/app/pages/account/addresses.test.js # packages/template-retail-react-app/app/pages/account/index.jsx # packages/template-retail-react-app/app/pages/account/wishlist/partials/wishlist-primary-action.test.js # packages/template-retail-react-app/app/pages/cart/index.test.js # packages/template-retail-react-app/app/pages/cart/partials/cart-secondary-button-group.test.js # packages/template-retail-react-app/app/pages/checkout/index.test.js # packages/template-retail-react-app/app/pages/checkout/partials/contact-info.jsx # packages/template-retail-react-app/app/pages/checkout/partials/contact-info.test.js # packages/template-retail-react-app/app/pages/home/index.test.js # packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx # packages/template-retail-react-app/app/pages/product-list/partials/page-header.jsx # packages/template-retail-react-app/app/pages/registration/index.test.jsx # packages/template-retail-react-app/app/utils/site-utils.js # packages/template-retail-react-app/package-lock.json # packages/template-typescript-minimal/package-lock.json # packages/test-commerce-sdk-react/package-lock.json
2 parents e1b5bfd + e178ed2 commit 23c195a

File tree

152 files changed

+1692
-1366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+1692
-1366
lines changed

.github/workflows/test.yml

+5-14
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,28 @@ on:
1919
- develop
2020
# TODO: Should we run on all pushes to release branches, or should we run on GitHub releases?
2121
- 'release-*'
22-
- 'v3'
2322
schedule:
2423
# Run every day at 12pm (PST) - cron uses UTC times
2524
- cron: '0 8 * * *'
2625
env:
2726
IS_NOT_FORK: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
2827
DEVELOP: ${{ (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && (github.head_ref || github.ref_name) == 'develop' }}
2928
RELEASE: ${{ (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && startsWith(github.head_ref || github.ref_name, 'release-') }}
30-
V3: ${{ (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && (github.head_ref || github.ref_name) == 'v3' }}
3129

3230
jobs:
3331
pwa-kit:
3432
strategy:
3533
fail-fast: false
3634
matrix:
3735
node: [16, 18]
38-
npm: [7, 8, 9]
36+
npm: [8, 9]
3937
runs-on: ubuntu-latest
4038
env:
4139
# The "default" npm is the one that ships with a given version of node.
4240
# For more: https://nodejs.org/en/download/releases/
4341
# (We also use this env var for making sure a step runs once for the current node version)
4442
IS_DEFAULT_NPM: ${{ (matrix.node == 16 && matrix.npm == 8) || (matrix.node == 18 && matrix.npm == 9) }}
45-
# The current recommended version for Managed Runtime:
43+
# The current recommended version for Managed Runtime:
4644
# https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/upgrade-node-version.html
4745
IS_MRT_NODE: ${{ matrix.node == 16 && matrix.npm == 8 }}
4846
steps:
@@ -74,7 +72,7 @@ jobs:
7472
uses: "./.github/actions/smoke_tests"
7573

7674
- name: Create MRT credentials file
77-
if: env.IS_NOT_FORK == 'true' && env.IS_MRT_NODE == 'true' && ( env.DEVELOP == 'true' || env.RELEASE == 'true' || env.V3 == 'true' )
75+
if: env.IS_NOT_FORK == 'true' && env.IS_MRT_NODE == 'true' && ( env.DEVELOP == 'true' || env.RELEASE == 'true' )
7876
uses: "./.github/actions/create_mrt"
7977
with:
8078
mobify_user: ${{ secrets.MOBIFY_CLIENT_USER }}
@@ -86,13 +84,6 @@ jobs:
8684
with:
8785
CWD: "./packages/template-retail-react-app"
8886
TARGET: staging
89-
90-
- name: Push Bundle to MRT (v3)
91-
if: env.IS_NOT_FORK == 'true' && env.IS_MRT_NODE == 'true' && env.V3 == 'true'
92-
uses: "./.github/actions/push_to_mrt"
93-
with:
94-
CWD: "./packages/template-retail-react-app"
95-
TARGET: staging-v3
9687

9788
- name: Push Bundle to MRT (Production)
9889
if: env.IS_NOT_FORK == 'true' && env.IS_MRT_NODE == 'true' && env.RELEASE == 'true'
@@ -134,13 +125,13 @@ jobs:
134125
fail-fast: false
135126
matrix:
136127
node: [16, 18]
137-
npm: [7, 8, 9]
128+
npm: [8, 9]
138129
env:
139130
# The "default" npm is the one that ships with a given version of node.
140131
# For more: https://nodejs.org/en/download/releases/
141132
# (We also use this env var for making sure a step runs once for the current node version)
142133
IS_DEFAULT_NPM: ${{ (matrix.node == 16 && matrix.npm == 8) || (matrix.node == 18 && matrix.npm == 9) }}
143-
# The current recommended version for Managed Runtime:
134+
# The current recommended version for Managed Runtime:
144135
# https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/upgrade-node-version.html
145136
IS_MRT_NODE: ${{ matrix.node == 16 && matrix.npm == 8 }}
146137
runs-on: windows-latest

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ packages/*/out
99
packages/*/docs/www
1010
lerna-debug.log
1111
.idea/
12-
.vscode/
12+
.vscode/
13+
*.orig

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.8.0-dev",
2+
"version": "3.0.0-dev",
33
"packages": [
44
"packages/*"
55
]

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pwa-kit",
3-
"version": "2.8.0-dev",
3+
"version": "3.0.0-dev",
44
"scripts": {
55
"bump-version": "node ./scripts/bump-version.js",
66
"format": "lerna run --stream format",
@@ -21,7 +21,7 @@
2121
"shelljs": "^0.8.5"
2222
},
2323
"engines": {
24-
"node": "^16.0.0 || ^18.0.0",
25-
"npm": "^7.0.0 || ^8.0.0 || ^9.0.0"
24+
"node": "^16.11.0 || ^18.0.0",
25+
"npm": "^8.0.0 || ^9.0.0"
2626
}
2727
}
+24-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1-
## v2.8.0-dev (Mar 03, 2023)
2-
- Add missing cache invalidation for contexts/customers/login/order [#1073](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1073)
1+
## v3.0.0-dev (May 12, 2023)
2+
3+
- Upgrade React 18, React DOM 18, @types/react@18, @types/react-dom@v18 Testing library 14 [#1166](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1166)
4+
5+
## v2.7.1 (May 11, 2023)
6+
7+
- Re-generate lock files and fix hook lib tests [#1186](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1186)
8+
- Add additional properties to ShopperLogin test types [#1185](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1185)
9+
- Add missing cache invalidation for contexts/customers/login/order [#1073](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1073)
10+
- Fix Shopper Baskets Test case [#1082](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1082)
11+
- Implement remaining Shopper Baskets cache logic [#1070](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1070)
12+
- Decode pre-fetched token and save auth data in storage [#1052](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1052)
13+
- Allow query hook parameters to be null. [#1046](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1046)
14+
- Implement updateCustomerPassword as no-op. [#1031](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1031)
15+
316
## v2.7.0 (Mar 03, 2023)
4-
- Add Page/Region/Component components for shopper experience/page designer page rendering [#963](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/963)
5-
- Namespace `Auth` storage keys with site identifier to allow multi-site support [#911](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/911)
6-
- Add Shopper Experience `usePage` and `usePages` hooks[#958](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/958)
17+
18+
- Add Page/Region/Component components for shopper experience/page designer page rendering [#963](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/963)
19+
- Namespace `Auth` storage keys with site identifier to allow multi-site support [#911](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/911)
20+
- Add Shopper Experience `usePage` and `usePages` hooks[#958](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/958)
721

822
## v2.6.0 (Jan 25, 2023)
923

1024
## v2.5.0 (Jan 05, 2023)
11-
- Exclude test files in package file to avoid publishing them [#856](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/856)
12-
- Pass in 'headers' and 'rawResponse' options to mutation hooks [#845](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/845)
13-
- Commerce hooks: basket mutations [#834](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/834)
14-
- Remove overriding of params in mutation hooks [#859](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/859)
25+
26+
- Exclude test files in package file to avoid publishing them [#856](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/856)
27+
- Pass in 'headers' and 'rawResponse' options to mutation hooks [#845](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/845)
28+
- Commerce hooks: basket mutations [#834](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/834)
29+
- Remove overriding of params in mutation hooks [#859](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/859)
1530

1631
## v2.4.0 (Dec 01, 2022)

packages/commerce-sdk-react/package.json

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commerce-sdk-react-preview",
3-
"version": "2.8.0-dev",
3+
"version": "3.0.0-dev",
44
"description": "A library that provides react hooks for fetching data from Commerce Cloud",
55
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/ecom-react-hooks#readme",
66
"bugs": {
@@ -47,23 +47,22 @@
4747
"devDependencies": {
4848
"@tanstack/react-query": "^4.28.0",
4949
"@testing-library/jest-dom": "^5.16.5",
50-
"@testing-library/react": "^12.1.5",
51-
"@testing-library/react-hooks": "^8.0.1",
50+
"@testing-library/react": "^14.0.0",
5251
"@types/js-cookie": "^3.0.3",
5352
"@types/jsonwebtoken": "^8.5.9",
5453
"@types/jwt-decode": "^3.1.0",
5554
"@types/node": "^14.18.40",
56-
"@types/react": "^17.0.53",
57-
"@types/react-dom": "^17.0.19",
55+
"@types/react": "^18.2.0",
56+
"@types/react-dom": "^18.2.1",
5857
"@types/react-helmet": "^6.1.6",
5958
"cross-env": "^5.2.1",
60-
"internal-lib-build": "2.8.0-dev",
59+
"internal-lib-build": "3.0.0-dev",
6160
"jsonwebtoken": "^8.5.1",
6261
"nock": "^13.3.0",
6362
"nodemon": "^2.0.22",
64-
"pwa-kit-dev": "2.8.0-dev",
65-
"react": "^17.0.2",
66-
"react-dom": "^17.0.2",
63+
"pwa-kit-dev": "3.0.0-dev",
64+
"react": "^18.2.0",
65+
"react-dom": "^18.2.0",
6766
"react-helmet": "^6.1.0",
6867
"semver": "^7.3.8",
6968
"shelljs": "^0.8.5",
@@ -72,15 +71,15 @@
7271
},
7372
"peerDependencies": {
7473
"@tanstack/react-query": "^4",
75-
"react": "^17",
74+
"react": "^18",
7675
"react-helmet": "6"
7776
},
7877
"optionalDependencies": {
7978
"prop-types": "^15.8.1"
8079
},
8180
"engines": {
82-
"node": "^16.0.0 || ^18.0.0",
83-
"npm": "^7.0.0 || ^8.0.0 || ^9.0.0"
81+
"node": "^16.11.0 || ^18.0.0",
82+
"npm": "^8.0.0 || ^9.0.0"
8483
},
8584
"publishConfig": {
8685
"directory": "dist"

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ describe('Auth', () => {
6767
expect(auth.get('refresh_token_guest')).toBe(refreshToken)
6868
expect(auth.get('access_token')).toBe(accessToken)
6969
// @ts-expect-error private property
70-
expect([...auth.stores['cookie'].map.keys()]).toEqual([`siteId_cc-nx-g`])
70+
expect([...auth.stores['cookie'].map.keys()]).toEqual([`cc-nx-g_siteId`])
7171
// @ts-expect-error private property
72-
expect([...auth.stores['local'].map.keys()]).toEqual([`siteId_access_token`])
72+
expect([...auth.stores['local'].map.keys()]).toEqual([`access_token_siteId`])
7373
})
7474
test('set registered refresh token will clear guest refresh token, vise versa', () => {
7575
const auth = new Auth(config)
@@ -300,7 +300,7 @@ describe('Auth', () => {
300300
// @ts-expect-error private method
301301
authA.set('refresh_token_guest', refreshTokenGuest)
302302
// @ts-expect-error private property
303-
expect([...authA.stores['memory'].map.keys()]).toEqual([`siteA_cc-nx-g`])
303+
expect([...authA.stores['memory'].map.keys()]).toEqual([`cc-nx-g_siteA`])
304304

305305
// Create a second auth instance and ensure that its memory store has previous
306306
// guest tokens set from the first store (this emulates a second lambda request.)
@@ -309,7 +309,7 @@ describe('Auth', () => {
309309
authB.set('refresh_token_guest', refreshTokenGuest)
310310

311311
// @ts-expect-error private property
312-
expect([...authB.stores['memory'].map.keys()]).toEqual([`siteA_cc-nx-g`, `siteB_cc-nx-g`])
312+
expect([...authB.stores['memory'].map.keys()]).toEqual([`cc-nx-g_siteA`, `cc-nx-g_siteB`])
313313

314314
// Set mock value back to expected.
315315
// @ts-expect-error read-only property

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

+30-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface AuthConfig extends ApiClientConfigParams {
2424
proxy: string
2525
fetchOptions?: ShopperLoginTypes.FetchOptions
2626
fetchedToken?: string
27+
OCAPISessionsURL?: string
2728
}
2829

2930
interface JWTHeaders {
@@ -79,7 +80,7 @@ const DATA_MAP: AuthDataMap = {
7980
key: 'customer_id'
8081
},
8182
usid: {
82-
storageType: 'local',
83+
storageType: 'cookie',
8384
key: 'usid'
8485
},
8586
enc_user_id: {
@@ -138,6 +139,7 @@ class Auth {
138139
private REFRESH_TOKEN_EXPIRATION_DAYS = 90
139140
private stores: Record<StorageType, BaseStorage>
140141
private fetchedToken: string
142+
private OCAPISessionsURL: string
141143

142144
constructor(config: AuthConfig) {
143145
this.client = new ShopperLogin({
@@ -163,9 +165,9 @@ class Auth {
163165
fetchOptions: config.fetchOptions
164166
})
165167

166-
const storageOptions = {keyPrefix: config.siteId}
168+
const storageOptions = {keySuffix: config.siteId}
167169
const serverStorageOptions = {
168-
keyPrefix: config.siteId,
170+
keySuffix: config.siteId,
169171
sharedContext: true // This allows use to reused guest authentication tokens accross lambda runs.
170172
}
171173

@@ -185,6 +187,8 @@ class Auth {
185187
this.redirectURI = config.redirectURI
186188

187189
this.fetchedToken = config.fetchedToken || ''
190+
191+
this.OCAPISessionsURL = config.OCAPISessionsURL || ''
188192
}
189193

190194
get(name: AuthDataKeys) {
@@ -272,7 +276,9 @@ class Auth {
272276
.then(async () => {
273277
const token = await fn()
274278
this.handleTokenResponse(token, isGuest)
275-
279+
if (onClient() && this.OCAPISessionsURL) {
280+
void this.createOCAPISession()
281+
}
276282
// Q: Why don't we just return token? Why re-construct the same object again?
277283
// A: because a user could open multiple tabs and the data in memory could be out-dated
278284
// We must always grab the data from the storage (cookie/localstorage) directly
@@ -430,6 +436,26 @@ class Auth {
430436
return this.loginGuestUser()
431437
}
432438

439+
/**
440+
* Make a post request to the OCAPI /session endpoint to bridge the session.
441+
*
442+
* The HTTP response contains a set-cookie header which sets the dwsid session cookie.
443+
* This cookie is used on SFRA, and it allows shoppers to navigate between SFRA and
444+
* this PWA site seamlessly; this is often used to enable hybrid deployment.
445+
*
446+
* (Note: this method is client side only, b/c MRT doesn't support set-cookie header right now)
447+
*
448+
* @returns {Promise}
449+
*/
450+
createOCAPISession() {
451+
return fetch(this.OCAPISessionsURL, {
452+
method: 'POST',
453+
headers: {
454+
Authorization: this.get('access_token')
455+
}
456+
})
457+
}
458+
433459
/**
434460
* Decode SLAS JWT and extract information such as customer id, usid, etc.
435461
*

packages/commerce-sdk-react/src/auth/storage.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ const testCases = [
2424
{
2525
description: 'MemoryStorage works with options',
2626
storageOptions: {
27-
keyPrefix: 'prefix',
28-
keyPrefixSeparator: '$'
27+
keySuffix: 'suffix'
2928
},
3029
validate: (storage: BaseStorage) => {
3130
storage.set(key, value)
3231
expect(storage.get(key)).toBe(value)
3332
// @ts-expect-error private property
34-
expect([...storage.map.keys()]).toEqual([`prefix$${key}`])
33+
expect([...storage.map.keys()]).toEqual([`${key}_suffix`])
3534
storage.delete(key)
3635
expect(storage.get(key)).toBe('')
3736
}

0 commit comments

Comments
 (0)