Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SLAS private proxy path #1752

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.5.0",
"version": "3.5.1",
"packages": [
"packages/*"
]
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pwa-kit",
"version": "3.5.0",
"version": "3.5.1",
"scripts": {
"bump-version": "node ./scripts/bump-version/index.js",
"bump-version:retail-react-app": "node ./scripts/bump-version/index.js --package=@salesforce/retail-react-app",
Expand Down
3 changes: 3 additions & 0 deletions packages/commerce-sdk-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v1.4.2 (Apr 17, 2024)
- Update SLAS private proxy path [#1752](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1752)

## v1.4.1 (Apr 16, 2024)
- Add missing params keys `allVariationProperties` and `perPricebook` for Shopper Search [#1750](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1750)

Expand Down
4 changes: 2 additions & 2 deletions packages/commerce-sdk-react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/commerce-sdk-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/commerce-sdk-react",
"version": "1.4.1",
"version": "1.4.2",
"description": "A library that provides react hooks for fetching data from Commerce Cloud",
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/ecom-react-hooks#readme",
"bugs": {
Expand Down Expand Up @@ -45,7 +45,7 @@
"jwt-decode": "^4.0.0"
},
"devDependencies": {
"@salesforce/pwa-kit-dev": "3.5.0",
"@salesforce/pwa-kit-dev": "3.5.1",
"@tanstack/react-query": "^4.28.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
Expand All @@ -59,7 +59,7 @@
"@types/react-helmet": "~6.1.6",
"@types/react-router-dom": "~5.3.3",
"cross-env": "^5.2.1",
"internal-lib-build": "3.5.0",
"internal-lib-build": "3.5.1",
"jsonwebtoken": "^9.0.0",
"nock": "^13.3.0",
"nodemon": "^2.0.22",
Expand Down
6 changes: 3 additions & 3 deletions packages/commerce-sdk-react/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class Auth {
constructor(config: AuthConfig) {
// Special endpoint for injecting SLAS private client secret
const baseUrl = config.proxy.split(`/mobify/proxy/api`)[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a bug in the waiting here as well. Since the proxy path value is configurable we might run into issues if someone was to change that.

const privateClientEndpoint = `${baseUrl}/mobify/scapi/shopper/auth`
const privateClientEndpoint = `${baseUrl}/mobify/slas/private`

this.client = new ShopperLogin({
proxy: config.enablePWAKitPrivateClient ? privateClientEndpoint : config.proxy,
Expand Down Expand Up @@ -221,12 +221,12 @@ class Auth {

/*
* There are 2 ways to enable SLAS private client mode.
* If enablePWAKitPrivateClient=true, we route SLAS calls to /mobify/scapi/shopper/auth
* If enablePWAKitPrivateClient=true, we route SLAS calls to /mobify/slas/private
* and set an internal placeholder as the client secret. The proxy will override the placeholder
* with the actual client secret so any truthy value as the placeholder works here.
*
* If enablePWAKitPrivateClient=false and clientSecret is provided as a non-empty string,
* private client mode is enabled but we don't route calls to /mobify/scapi/shopper/auth
* private client mode is enabled but we don't route calls to /mobify/slas/private
* This is how non-PWA Kit consumers of commerce-sdk-react can enable private client and set a secret
*
* If both enablePWAKitPrivateClient and clientSecret are truthy, enablePWAKitPrivateClient takes
Expand Down
2 changes: 1 addition & 1 deletion packages/commerce-sdk-react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const AuthContext = React.createContext({} as Auth)
* ```
* Note: The provider can enable SLAS Private Client mode in 2 ways.
* `enablePWAKitPrivateClient` sets commerce-sdk-react to work with the PWA proxy
* `/mobify/scapi/api/auth` to set the private client secret. PWA users should use
* `/mobify/slas/private` to set the private client secret. PWA users should use
* this option.
*
* Non-PWA Kit users can enable private client mode by passing in a client secret
Expand Down
4 changes: 2 additions & 2 deletions packages/internal-lib-build/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/internal-lib-build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internal-lib-build",
"version": "3.5.0",
"version": "3.5.1",
"private": true,
"description": "Build tools for *libraries* in the monorepo",
"bugs": {
Expand Down Expand Up @@ -60,7 +60,7 @@
"shelljs": "^0.8.5"
},
"devDependencies": {
"@salesforce/pwa-kit-dev": "3.5.0",
"@salesforce/pwa-kit-dev": "3.5.1",
"npm-packlist": "^4.0.0",
"typescript": "4.9.5"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/pwa-kit-create-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/pwa-kit-create-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/pwa-kit-create-app",
"version": "3.5.0",
"version": "3.5.1",
"description": "Salesforce's project generator tool",
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/pwa-kit-create-app#readme",
"bugs": {
Expand Down Expand Up @@ -38,8 +38,8 @@
"tar": "^6.2.1"
},
"devDependencies": {
"@salesforce/pwa-kit-dev": "3.5.0",
"internal-lib-build": "3.5.0",
"@salesforce/pwa-kit-dev": "3.5.1",
"internal-lib-build": "3.5.1",
"verdaccio": "^5.22.1"
},
"engines": {
Expand Down
3 changes: 3 additions & 0 deletions packages/pwa-kit-dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v3.5.1 (Apr 17, 2024)
- Update SLAS private proxy path [#1752](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1752)

## v3.5.0 (Apr 15, 2024)

- Add Support for SLAS private flow [#1722](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1722)
Expand Down
4 changes: 2 additions & 2 deletions packages/pwa-kit-dev/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/pwa-kit-dev/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/pwa-kit-dev",
"version": "3.5.0",
"version": "3.5.1",
"description": "Build tools for pwa-kit",
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/pwa-kit-dev#readme",
"bugs": {
Expand Down Expand Up @@ -58,7 +58,7 @@
"@loadable/server": "^5.15.3",
"@loadable/webpack-plugin": "^5.15.2",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
"@salesforce/pwa-kit-runtime": "3.5.0",
"@salesforce/pwa-kit-runtime": "3.5.1",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"archiver": "1.3.0",
Expand Down Expand Up @@ -121,7 +121,7 @@
"@types/node": "~16.0.3",
"@types/node-fetch": "~2.6.3",
"@types/validator": "~13.7.14",
"internal-lib-build": "3.5.0",
"internal-lib-build": "3.5.1",
"nock": "^13.3.0",
"nodemon": "^2.0.22",
"superagent": "^6.1.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/pwa-kit-react-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## v3.5.1 (Apr 17, 2024)

## v3.5.0 (Apr 15, 2024)

## v3.4.0 (Jan 19, 2024)
Expand Down
4 changes: 2 additions & 2 deletions packages/pwa-kit-react-sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/pwa-kit-react-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/pwa-kit-react-sdk",
"version": "3.5.0",
"version": "3.5.1",
"description": "A library that supports the isomorphic React rendering pipeline for Commerce Cloud Managed Runtime apps",
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/pwa-kit-react-sdk#readme",
"bugs": {
Expand Down Expand Up @@ -37,7 +37,7 @@
"@loadable/babel-plugin": "^5.15.3",
"@loadable/server": "^5.15.3",
"@loadable/webpack-plugin": "^5.15.2",
"@salesforce/pwa-kit-runtime": "3.5.0",
"@salesforce/pwa-kit-runtime": "3.5.1",
"@tanstack/react-query": "^4.28.0",
"cross-env": "^5.2.1",
"event-emitter": "^0.3.5",
Expand All @@ -50,11 +50,11 @@
},
"devDependencies": {
"@loadable/component": "^5.15.3",
"@salesforce/pwa-kit-dev": "3.5.0",
"@salesforce/pwa-kit-dev": "3.5.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"internal-lib-build": "3.5.0",
"internal-lib-build": "3.5.1",
"node-html-parser": "^3.3.6",
"nodemon": "^2.0.22",
"react": "^18.2.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/pwa-kit-runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v3.5.1 (Apr 17, 2024)
- Update SLAS private proxy path [#1752](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1752)

## v3.5.0 (Apr 15, 2024)

## v3.4.0 (Jan 19, 2024)
Expand Down
4 changes: 2 additions & 2 deletions packages/pwa-kit-runtime/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/pwa-kit-runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/pwa-kit-runtime",
"version": "3.5.0",
"version": "3.5.1",
"description": "The PWAKit Runtime",
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/pwa-kit-runtime#readme",
"bugs": {
Expand Down Expand Up @@ -46,19 +46,19 @@
},
"devDependencies": {
"@loadable/component": "^5.15.3",
"@salesforce/pwa-kit-dev": "3.5.0",
"@salesforce/pwa-kit-dev": "3.5.1",
"@serverless/event-mocks": "^1.1.1",
"aws-lambda-mock-context": "^3.2.1",
"fs-extra": "^11.1.1",
"internal-lib-build": "3.5.0",
"internal-lib-build": "3.5.1",
"nock": "^13.3.0",
"nodemon": "^2.0.22",
"sinon": "^13.0.2",
"superagent": "^6.1.0",
"supertest": "^4.0.2"
},
"peerDependencies": {
"@salesforce/pwa-kit-dev": "3.5.0"
"@salesforce/pwa-kit-dev": "3.5.1"
},
"peerDependenciesMeta": {
"@salesforce/pwa-kit-dev": {
Expand Down
15 changes: 15 additions & 0 deletions packages/pwa-kit-runtime/src/ssr/server/build-remote-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,21 @@ export const RemoteServerFactory = {
if (incomingRequest.path?.match(options.applySLASPrivateClientToEndpoints)) {
proxyRequest.setHeader('Authorization', `Basic ${encodedSlasCredentials}`)
}
},
onProxyRes: (proxyRes, req) => {
if (proxyRes.statusCode && proxyRes.statusCode >= 400) {
console.error(
`Failed to proxy SLAS Private Client request - ${proxyRes.statusCode}`
)
console.error(
`Please make sure you have enabled the SLAS Private Client Proxy in your ssr.js and set the correct environment variable PWA_KIT_SLAS_CLIENT_SECRET.`
)
console.error(
`SLAS Private Client Proxy Request URL - ${req.protocol}://${req.get(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log the full proxied request URL, this may help if user have configuration issues.

'host'
)}${req.originalUrl}`
)
}
}
})
)
Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-kit-runtime/src/ssr/server/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export const CACHE_CONTROL = 'cache-control'
export const NO_CACHE = 'max-age=0, nocache, nostore, must-revalidate'
export const CONTENT_SECURITY_POLICY = 'content-security-policy'
export const STRICT_TRANSPORT_SECURITY = 'strict-transport-security'
export const SLAS_CUSTOM_PROXY_PATH = '/mobify/scapi/shopper/auth'
export const SLAS_CUSTOM_PROXY_PATH = '/mobify/slas/private'
8 changes: 4 additions & 4 deletions packages/pwa-kit-runtime/src/ssr/server/express.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,12 +1066,12 @@ describe('SLAS private client proxy', () => {

test('should not create proxy by default', () => {
const app = RemoteServerFactory._createApp(opts())
return request(app).get('/mobify/scapi/shopper/auth').expect(404)
return request(app).get('/mobify/slas/private').expect(404)
})

test('should return HTTP 501 if PWA_KIT_SLAS_CLIENT_SECRET env var not set', () => {
const app = RemoteServerFactory._createApp(opts({useSLASPrivateClient: true}))
return request(app).get('/mobify/scapi/shopper/auth').expect(501)
return request(app).get('/mobify/slas/private').expect(501)
})

test('does not insert client secret if request not for /oauth2/token', async () => {
Expand All @@ -1095,7 +1095,7 @@ describe('SLAS private client proxy', () => {
)

return await request(app)
.get('/mobify/scapi/shopper/auth/somePath')
.get('/mobify/slas/private/somePath')
.then((response) => {
expect(response.body.authorization).toBeUndefined()
expect(response.body.host).toBe('shortCode.api.commercecloud.salesforce.com')
Expand Down Expand Up @@ -1126,7 +1126,7 @@ describe('SLAS private client proxy', () => {
)

return await request(app)
.get('/mobify/scapi/shopper/auth/oauth2/token')
.get('/mobify/slas/private/oauth2/token')
.then((response) => {
expect(response.body.authorization).toBe(`Basic ${encodedCredentials}`)
expect(response.body.host).toBe('shortCode.api.commercecloud.salesforce.com')
Expand Down
Loading
Loading