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

@W-14455649@ - DO NOT MERGE - Spike slas private client v2 #1585

Closed
wants to merge 10 commits into from
Closed
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
161 changes: 90 additions & 71 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.

2 changes: 1 addition & 1 deletion packages/commerce-sdk-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"version": "node ./scripts/version.js"
},
"dependencies": {
"commerce-sdk-isomorphic": "^1.10.4",
"commerce-sdk-isomorphic": "/Users/vcua/Git/commerce-sdk-isomorphic",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR needs the changes in SalesforceCommerceCloud/commerce-sdk-isomorphic#138 to work

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI if anyone wants to run this PR locally, you'll need to update this line to point to your own copy of commerce-sdk-isomorphic. Specifically, pull in the PR: SalesforceCommerceCloud/commerce-sdk-isomorphic#138.

Also, in your copy of commerce-sdk-isomorphic, build it first by running:

yarn install
yarn run renderTemplates
yarn build:lib

"js-cookie": "^3.0.1",
"jwt-decode": "^4.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages/commerce-sdk-react/src/auth/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const config = {
shortCode: 'shortCode',
siteId: 'siteId',
proxy: 'proxy',
slasProxy: 'slasProxy',
redirectURI: 'redirectURI'
}

Expand Down
6 changes: 4 additions & 2 deletions packages/commerce-sdk-react/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Helpers = typeof helpers
interface AuthConfig extends ApiClientConfigParams {
redirectURI: string
proxy: string
slasProxy: string
Copy link
Contributor Author

@vcua-mobify vcua-mobify Dec 1, 2023

Choose a reason for hiding this comment

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

We are setting up a new proxy in ssr.js to insert the client secret. This new slasProxy is how I am consuming that separate proxy at this time

fetchOptions?: ShopperLoginTypes.FetchOptions
fetchedToken?: string
OCAPISessionsURL?: string
Expand Down Expand Up @@ -168,7 +169,7 @@ class Auth {

constructor(config: AuthConfig) {
this.client = new ShopperLogin({
proxy: config.proxy,
proxy: config.slasProxy,
Copy link
Contributor Author

@vcua-mobify vcua-mobify Dec 1, 2023

Choose a reason for hiding this comment

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

Using the regular config.proxy would send calls to /mobify/proxy/api/ which does not include the logic for inserting the client secret at this time. So I added this new slasProxy for requests that do go need the client secret

parameters: {
clientId: config.clientId,
organizationId: config.organizationId,
Expand Down Expand Up @@ -405,7 +406,8 @@ class Auth {
}
}
return await this.queueRequest(
() => helpers.loginGuestUser(this.client, {redirectURI: this.redirectURI}),
//() => helpers.loginGuestUser(this.client, {redirectURI: this.redirectURI}),
() => helpers.loginGuestUserPrivateClient(this.client,{redirectURI: this.redirectURI}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This consumes a change made in commerce-sdk-isomorphic to skip the /authorize call when logging in as a guest

true
)
}
Expand Down
13 changes: 10 additions & 3 deletions packages/commerce-sdk-react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {ApiClientConfigParams, ApiClients} from './hooks/types'
export interface CommerceApiProviderProps extends ApiClientConfigParams {
children: React.ReactNode
proxy: string
slasProxy: string
locale: string
currency: string
redirectURI: string
Expand Down Expand Up @@ -52,7 +53,7 @@ export const AuthContext = React.createContext({} as Auth)
* Initialize a set of Commerce API clients and make it available to all of descendant components
*
* @group Components
*
*
* @example
* ```js
import {CommerceApiProvider} from '@salesforce/commerce-sdk-react'
Expand All @@ -73,11 +74,11 @@ export const AuthContext = React.createContext({} as Auth)
{children}
</CommerceApiProvider>
)
}
}

export default App
* ```
*
*
* @returns Provider to wrap your app with
*/
const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
Expand All @@ -87,6 +88,7 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
headers = {},
organizationId,
proxy,
slasProxy,
redirectURI,
fetchOptions,
siteId,
Expand All @@ -99,6 +101,7 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {

const config = {
proxy,
slasProxy,
headers,
parameters: {
clientId,
Expand Down Expand Up @@ -130,6 +133,7 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
shortCode,
siteId,
proxy,
slasProxy,
fetchOptions,
locale,
currency,
Expand All @@ -143,6 +147,7 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
shortCode,
siteId,
proxy,
slasProxy,
redirectURI,
fetchOptions,
fetchedToken,
Expand All @@ -154,6 +159,7 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
shortCode,
siteId,
proxy,
slasProxy,
redirectURI,
fetchOptions,
fetchedToken,
Expand All @@ -170,6 +176,7 @@ const CommerceApiProvider = (props: CommerceApiProviderProps): ReactElement => {
headers,
organizationId,
proxy,
slasProxy,
redirectURI,
fetchOptions,
siteId,
Expand Down
1 change: 1 addition & 0 deletions packages/commerce-sdk-react/src/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const DEFAULT_TEST_HOST = 'http://localhost:8888'

export const DEFAULT_TEST_CONFIG = {
proxy: `${DEFAULT_TEST_HOST}/mobify/proxy/api`,
slasProxy: `${DEFAULT_TEST_HOST}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is how I am consuming the new proxy set in ssr.js. As mentioned in other comments, it is currently separate from /mobify/proxy/api

redirectURI: `${DEFAULT_TEST_HOST}/callback`,
clientId: '12345678-1234-1234-1234-123412341234',
organizationId: 'f_ecom_zzrmy_orgf_001',
Expand Down
Loading
Loading