Skip to content

Commit d4e9ee9

Browse files
authored
PWA Kit v2 guide for channel_id and siteId scoping guide (#1935)
* Update README.md * Update README.md * Update README.md
1 parent 949b8b3 commit d4e9ee9

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,85 @@ Feel free to share this survey link with your colleagues, partners, or anyone wh
88

99
Thank you for being a part of our community and for your continuous support! :raised_hands:
1010

11+
## :warning: Planned API Changes :warning:
12+
13+
### Shopper Context
14+
15+
Starting July 31st 2024, all endpoints in the Shopper context API will require the `siteId` parameter for new customers. This field is marked as optional for backward compatibility and will be changed to mandatory tentatively by January 2025. You can read more about the planned change [here](https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-context?meta=Summary) in the notes section.
16+
17+
### Shopper Login (SLAS)
18+
19+
SLAS will soon require new tenants to pass `channel_id` as an argument for retrieving guest access tokens. You can read more about the planned change [here](https://developer.salesforce.com/docs/commerce/commerce-api/guide/slas.html#guest-tokens).
20+
21+
Please be aware that existing tenants are on a temporary allow list and will see no immediate disruption to service. We do ask that all users seek to adhere to the `channel_id` requirement before the end of August to enhance your security posture before the holiday peak season.
22+
23+
### Summary of Changes for PWA Kit v2
24+
25+
To comply with the planned API changes effective July 31st, 2024, you need to update your PWA Kit v2 projects. These changes involve adding the `channel_id` parameter for Shopper Login and optionally scoping your local storage keys and cookie names with the `siteId` prefix if your site uses multisite.
26+
27+
#### 1. Update `auth.js` to Include `channel_id` in Calls to Shopper Login
28+
29+
Add the `channel_id` parameter in the appropriate functions for obtaining tokens.
30+
31+
##### Example Changes:
32+
```diff
33+
// In the Auth class, add channel_id to the data in _loginAsGuest method
34+
channel_id: this._config.parameters.siteId
35+
36+
// In the refreshToken method, add channel_id to the data
37+
data.append('channel_id', this._config.parameters.siteId)
38+
```
39+
40+
#### 2. Scope Local Storage Keys and Cookie Names per Site for Multisite Projects
41+
42+
For customers using multiple site IDs, it is recommended to scope your local storage keys and cookie names per site to avoid conflicts. This ensures that tokens from different sites (e.g., RefArch and RefArchGlobal) are not incorrectly used across sites.
43+
44+
##### Example Changes:
45+
```diff
46+
// Add siteId parameter in LocalStorage and CookieStorage constructors
47+
constructor(siteId, ...args) {
48+
super(args)
49+
if (typeof window === 'undefined') {
50+
throw new Error('LocalStorage is not available in the current environment.')
51+
}
52+
this.siteId = siteId
53+
}
54+
55+
// Create storage key with siteId prefix
56+
createStorageKey(key) {
57+
return `${this.siteId}_${key}`
58+
}
59+
60+
// Set item in local storage with siteId prefix
61+
set(key, value) {
62+
window.localStorage.setItem(this.createStorageKey(key), value)
63+
}
64+
65+
// Get item from local storage with siteId prefix
66+
get(key) {
67+
return window.localStorage.getItem(this.createStorageKey(key))
68+
}
69+
70+
// Delete item from local storage with siteId prefix
71+
delete(key) {
72+
window.localStorage.removeItem(this.createStorageKey(key))
73+
}
74+
75+
// Similar changes for CookieStorage
76+
```
77+
78+
Full example of the changes in the `auth.js` file:
79+
https://github.com/SalesforceCommerceCloud/pwa-kit/compare/949b8b3b7...534dab260
80+
81+
#### Important Note:
82+
83+
Implementing the `siteId` prefix for local storage keys and cookie names will effectively log out any existing customer sessions on the site. This includes registered logins and baskets for all users.
84+
85+
#### Recommendation:
86+
87+
- Established sites that do not need this change should avoid implementing it to prevent logging out existing users.
88+
- If a project decides to implement this change, be aware that the PWA will now look for tokens under a different cookie name, causing all existing users to be logged out.
89+
1190
<div align="center">
1291

1392
<h1>The Progressive Web App (PWA) Kit</h1>

0 commit comments

Comments
 (0)