-
Notifications
You must be signed in to change notification settings - Fork 143
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
[commerce-sdk-react] Multisite support #769
Conversation
const {locale, currency} = useConfig() | ||
parameters.locale = parameters.locale || locale | ||
parameters.currency = parameters.currency || currency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.. we haven't been using and passing in the locale
until now 👍
This change is worthy to share with everyone in the team. For every hooks we're working on, we'll need to make sure to pass in the locale, if it's supported for that particular API endpoint.
}, | ||
site_id: { | ||
storage: cookieStorage, | ||
key: 'cc-site-id', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ticket mentions about namespacing the token. Do we still want to do that?
Without namespacing it, I guess the consequence would be that when you switch back to a previously-visited site, you would lose your basket progress?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this cookie is used as the "namespacer". It's not realistic to store tokens for every single site as we are bound by the size limitation of Cookie/Localstorage. A customer could have 100+ sites and we can't keep them all.
You are right that customer will lose the basket progress unfortunately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
* [commerce-sdk-react] Add mutation hooks and refactor query hooks (#726) * add mutation hook and refactor query hook * lint * fix eslint * fix ts types * fix ts type for usequery * fix lint * fix test * lint * add mutation example * fix typo * DRY useAuthenticated * fix object.keys type * use better name * change mutation signature * fix types * rename mutations * fix typos * fix shopper login types * fix test * remove unused vars * refactor mutation types * allow useMutation to pass thru options * remove comment Co-authored-by: Alex Vuong <[email protected]> * Dynamic footer Copyright date (#741) * Update checkout-footer.jsx * whitespace to bump CLA check * Add translation and alternate footer changes (force push is to remove unsigned commits from git history) * Shopper promotions hooks (#759) * usePromotions and usePromotionsForCampaign hooks * Footer copyright: remove the remaining hardcoded year (#760) * Revert "Remove custom options for react query hoc (#755)" (#775) This reverts commit 9e0f596. * `<ImageGallery >` uses `image.link` when DIS is not set (#786) * Fix global context pollution coming from nock (#785) * Fix global context pollution coming from nock * remove nock debug env var * npm run lint:fix * remove IDE-inserted import * Use default locale as target if none is specified (#788) * Use default locale as target if none is specified * Update CHANGELOG.md * [commerce-sdk-react] Multisite support (#769) * add multisite support * add test * update comment * pr feedback * add locale * add locale props to queries * add cookie expire * attempt to address test issues * attempt to resolve test issue * fix test * fix test again Co-authored-by: Brian Feister <[email protected]> * ShopperOrders hooks & mutations (#766) * Implement useOrder and usePaymentMethodsForOrder hooks * Add useOrder shopper hook to test * Add usePaymentMethods hook to test * Added valid order # to test * Updating demo * Completed demo of useOrder and usePaymentMethods * Added tests * working on tests * Fix tests * remove custom mode * record mock * mock oauths/login endpoint * added more tests * Updating demos * add mock response * add mock response * Implement hooks in test-commerce * Began writing tests for mutation, implemented useTaxes hook, cleaned up test-commerce demo * Passing parameters and body to mutate function * Mutation test, tax hook, lint * mocked response * added removePaymentMethodForOrder hook test * lint * Remove mutation tests for now * remove mutation mocks * lint * remove nock for mutation * createOrder hook in test project Co-authored-by: Alex Vuong <[email protected]> * ShopperCustomer hooks and mutations (#762) * `useCustomer` hook * `useCustomerAddress` hook * `useCustomerOrders` hook * Solve merge conflicts * Refactor `useCustomer` test page * Add `useCustomerOrders` hook to test page * Add `useCustomerBaskets` hook * Add `useShopperCustomerProductList` hook * Clean up * Add ShopperCustomer mutations to test page * Solve merge conflicts * Wait to add test file until completed * Add initial `useCustomer` tests * add useRegisteredUser HOC * clean up * clean up * Add query hooks tests * Revert "Add use registered user HOC" (#783) * Add mutation test * Update query key structure & Invalidate cache onSuccess mutations * lint * Add `useQueryClient` * Update mock responses * Update usecustomer-returns-data.json * PR Feedback * Remove failing mutation test * update mock responses * try fix flaky test * restore test-utils * Solve merge conflict Co-authored-by: Alex Vuong <[email protected]> * [commerce-sdk-react] Implement shopper baskets hooks (#768) * Implement queries for shopperBasket hooks * Added UseShopperBasket page to test-commerce-sdk-react app * Added unit tests for ShopperBasket Queries * Added test integrations for ShopperBasket queries * Added test integrations for shopperbasket queries * wip * set cache keys * multiple refactors * bug fixes * lint * revert unnecessary changes * remove the bad test examples * revert temp shopper customer changes * fix test Co-authored-by: Jainam Tushar Sheth <[email protected]> Co-authored-by: Brian Feister <[email protected]> Co-authored-by: Adam Raya <[email protected]> * ApiClient config needs to be updated when cid is changed (#790) * Add Support policy to all SDKs (#764) * add Support policy to all SDKs * Additional default options for React Query (#791) * Explore having react-query config be on user land * PR feedback, and simplifying the default options * Revert to making this option applied server side only * Fix `useServerContext` returning `isServerSide=false` when on server. (#782) * Revert contraint on prepass JSX * PR feedback * Nock: clean up the list of mocks after each test (#792) * Update `instanceUrl` on `retail-react-app-demo` preset (#799) * Update changelog files * Bump alpha version * Upgrade minimatch (#793) * remove minimatch from sdk and update version in pwa-kit-dev * update lock files * update lock files * add more tests * add comment * lint * revert packge-lock file changes * update pwa-kit-dev package-lock.json * fix lockfile again Co-authored-by: Kevin He <[email protected]> Co-authored-by: Alex Vuong <[email protected]> Co-authored-by: Brian Feister <[email protected]> Co-authored-by: Alex Vuong <[email protected]> Co-authored-by: Vincent Marta <[email protected]> Co-authored-by: Charles Lavery <[email protected]> Co-authored-by: Ben Chypak <[email protected]> Co-authored-by: yunakim714 <[email protected]> Co-authored-by: Jainam Tushar Sheth <[email protected]>
* Starting release process for 2.3.0 * Add guards to result sent to Einstein (#756) * Add result guards to Einstein and PLP sendViewCategory Einstein * Bump alpha version * Update changelog * 🚢 `2.3.0-alpha.2` (#800) * [commerce-sdk-react] Add mutation hooks and refactor query hooks (#726) * add mutation hook and refactor query hook * lint * fix eslint * fix ts types * fix ts type for usequery * fix lint * fix test * lint * add mutation example * fix typo * DRY useAuthenticated * fix object.keys type * use better name * change mutation signature * fix types * rename mutations * fix typos * fix shopper login types * fix test * remove unused vars * refactor mutation types * allow useMutation to pass thru options * remove comment Co-authored-by: Alex Vuong <[email protected]> * Dynamic footer Copyright date (#741) * Update checkout-footer.jsx * whitespace to bump CLA check * Add translation and alternate footer changes (force push is to remove unsigned commits from git history) * Shopper promotions hooks (#759) * usePromotions and usePromotionsForCampaign hooks * Footer copyright: remove the remaining hardcoded year (#760) * Revert "Remove custom options for react query hoc (#755)" (#775) This reverts commit 9e0f596. * `<ImageGallery >` uses `image.link` when DIS is not set (#786) * Fix global context pollution coming from nock (#785) * Fix global context pollution coming from nock * remove nock debug env var * npm run lint:fix * remove IDE-inserted import * Use default locale as target if none is specified (#788) * Use default locale as target if none is specified * Update CHANGELOG.md * [commerce-sdk-react] Multisite support (#769) * add multisite support * add test * update comment * pr feedback * add locale * add locale props to queries * add cookie expire * attempt to address test issues * attempt to resolve test issue * fix test * fix test again Co-authored-by: Brian Feister <[email protected]> * ShopperOrders hooks & mutations (#766) * Implement useOrder and usePaymentMethodsForOrder hooks * Add useOrder shopper hook to test * Add usePaymentMethods hook to test * Added valid order # to test * Updating demo * Completed demo of useOrder and usePaymentMethods * Added tests * working on tests * Fix tests * remove custom mode * record mock * mock oauths/login endpoint * added more tests * Updating demos * add mock response * add mock response * Implement hooks in test-commerce * Began writing tests for mutation, implemented useTaxes hook, cleaned up test-commerce demo * Passing parameters and body to mutate function * Mutation test, tax hook, lint * mocked response * added removePaymentMethodForOrder hook test * lint * Remove mutation tests for now * remove mutation mocks * lint * remove nock for mutation * createOrder hook in test project Co-authored-by: Alex Vuong <[email protected]> * ShopperCustomer hooks and mutations (#762) * `useCustomer` hook * `useCustomerAddress` hook * `useCustomerOrders` hook * Solve merge conflicts * Refactor `useCustomer` test page * Add `useCustomerOrders` hook to test page * Add `useCustomerBaskets` hook * Add `useShopperCustomerProductList` hook * Clean up * Add ShopperCustomer mutations to test page * Solve merge conflicts * Wait to add test file until completed * Add initial `useCustomer` tests * add useRegisteredUser HOC * clean up * clean up * Add query hooks tests * Revert "Add use registered user HOC" (#783) * Add mutation test * Update query key structure & Invalidate cache onSuccess mutations * lint * Add `useQueryClient` * Update mock responses * Update usecustomer-returns-data.json * PR Feedback * Remove failing mutation test * update mock responses * try fix flaky test * restore test-utils * Solve merge conflict Co-authored-by: Alex Vuong <[email protected]> * [commerce-sdk-react] Implement shopper baskets hooks (#768) * Implement queries for shopperBasket hooks * Added UseShopperBasket page to test-commerce-sdk-react app * Added unit tests for ShopperBasket Queries * Added test integrations for ShopperBasket queries * Added test integrations for shopperbasket queries * wip * set cache keys * multiple refactors * bug fixes * lint * revert unnecessary changes * remove the bad test examples * revert temp shopper customer changes * fix test Co-authored-by: Jainam Tushar Sheth <[email protected]> Co-authored-by: Brian Feister <[email protected]> Co-authored-by: Adam Raya <[email protected]> * ApiClient config needs to be updated when cid is changed (#790) * Add Support policy to all SDKs (#764) * add Support policy to all SDKs * Additional default options for React Query (#791) * Explore having react-query config be on user land * PR feedback, and simplifying the default options * Revert to making this option applied server side only * Fix `useServerContext` returning `isServerSide=false` when on server. (#782) * Revert contraint on prepass JSX * PR feedback * Nock: clean up the list of mocks after each test (#792) * Update `instanceUrl` on `retail-react-app-demo` preset (#799) * Update changelog files * Bump alpha version * Upgrade minimatch (#793) * remove minimatch from sdk and update version in pwa-kit-dev * update lock files * update lock files * add more tests * add comment * lint * revert packge-lock file changes * update pwa-kit-dev package-lock.json * fix lockfile again Co-authored-by: Kevin He <[email protected]> Co-authored-by: Alex Vuong <[email protected]> Co-authored-by: Brian Feister <[email protected]> Co-authored-by: Alex Vuong <[email protected]> Co-authored-by: Vincent Marta <[email protected]> Co-authored-by: Charles Lavery <[email protected]> Co-authored-by: Ben Chypak <[email protected]> Co-authored-by: yunakim714 <[email protected]> Co-authored-by: Jainam Tushar Sheth <[email protected]> * 🚢 Version 2.3.0 (#802) * Version 2.3.0 * Update changelog files * Begin development on 2.4.0 Co-authored-by: Kevin He <[email protected]> Co-authored-by: Alex Vuong <[email protected]> Co-authored-by: Brian Feister <[email protected]> Co-authored-by: Alex Vuong <[email protected]> Co-authored-by: Vincent Marta <[email protected]> Co-authored-by: Charles Lavery <[email protected]> Co-authored-by: Ben Chypak <[email protected]> Co-authored-by: yunakim714 <[email protected]> Co-authored-by: Jainam Tushar Sheth <[email protected]>
This PR adds multi-site support to the
commerce-sdk-react
package.background
We've learned recently that SLAS tokens has the scope limited to a site, which means, you can't re-use tokens across two different site. When a user switch site, we must get new tokens from SLAS.
Implementation
The implementation is quite simple that every time an
Auth
class is initialized, it will detect if the site is different, if site is different from the last login, it will clears the storage and attempts to restart the authentication flow.How can I test it?
Pull the code then