-
Notifications
You must be signed in to change notification settings - Fork 130
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] SCAPI Custom endpoint support #1793
Conversation
packages/commerce-sdk-react/src/hooks/ShopperPromotions/query.test.ts
Outdated
Show resolved
Hide resolved
@@ -16,7 +16,7 @@ describe('Shopper Orders hooks', () => { | |||
const unimplemented = getUnimplementedEndpoints(ShopperOrders, queries, mutations) | |||
// If this test fails: create a new query hook, add the endpoint to the mutations enum, | |||
// or add it to the `expected` array with a comment explaining "TODO" or "never" (and why). | |||
expect(unimplemented).toEqual([]) | |||
expect(unimplemented).toEqual(['guestOrderLookup']) |
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.
new method came from commerce-sdk-isomorphic@2
'invalidateCustomerAuth', // DEPRECATED, not included | ||
'authorizeCustomer', // DEPRECATED, not included | ||
'authorizeTrustedSystem', // DEPRECATED, not included |
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.
Deprecated method removed from commerce-sdk-isomorphic@2
shortCode="kv7kzm78" | ||
clientId="4afbc51f-6423-41c8-8b29-d7f2825b5bee" | ||
organizationId="f_ecom_zzrf_006" |
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.
for custom endpoint manual testing, we have zzrf_006 setup for that
@@ -208,3 +209,14 @@ export type CacheUpdateMatrix<Client extends ApiClient> = { | |||
? CacheUpdateGetter<MergedOptions<Client, Argument<Client[Method]>>, Data> | |||
: never | |||
} | |||
|
|||
type CustomEndpointArg = Parameters<typeof helpers.callCustomEndpoint>[0] | |||
type CustomEndpointArgClientConfig = Parameters< |
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.
type CustomEndpointArgClientConfig = Parameters< | |
type CustomEndpointParam = Parameters<typeof helpers.callCustomEndpoint>[0] | |
type CustomEndpointClientConfig = CustomEndpointParam['clientConfig'] |
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.
sorry i'm not quite understanding this diff, are you suggesting to rename CustomEndpointArgClientConfig
to CustomEndpointParam
?
This type is a partial of the entire param just to extract the client config.
@@ -40,7 +40,7 @@ | |||
"version": "node ./scripts/version.js" | |||
}, | |||
"dependencies": { | |||
"commerce-sdk-isomorphic": "^1.13.1", | |||
"commerce-sdk-isomorphic": "^2.0.0", |
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.
Did we inadvertently force a breaking on this project by pumping this dependency as we are exposing the api clients via the useCommerceApi
hook?
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.
yes i think so
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'm bumping the major version for commerce-sdk-react too
`/${apiOptions.options.customApiPathParameters?.apiName || 'apiName'}`, | ||
`/${apiOptions.options.customApiPathParameters?.apiVersion || 'apiVersion'}`, | ||
`/organizations`, | ||
`/${apiOptions.options.customApiPathParameters?.organizationId || 'organizationId'}`, | ||
`/${apiOptions.options.customApiPathParameters?.endpointPath || 'endpointPath'}`, |
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'm understanding the default values used to fallback on here, e.g. the static value 'apiName', 'apiVersion', 'organizationId' and 'endpointPath'.
- If apiName isn't defined we probably already failed making the call.
- we'll probably have to have duplicate logic that defines what the apiVersion is.. alternatively we have it exported from the isomorphic lib.
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 think customApiPathParameters
should be required, but it's optional at the moment, shall we fix that in commerce-sdk-isomorphic
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.
Good call. i added a guard to make sure customApiPathParameters is defined before calling the api. otherwise throw error
@@ -21,7 +21,7 @@ | |||
"bundlesize": [ | |||
{ | |||
"path": "build/main.js", | |||
"maxSize": "43 kB" | |||
"maxSize": "44 kB" |
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.
Ass we get older we get fatter 😭
CacheUpdateGetter, | ||
ApiOptions, | ||
ApiMethod, | ||
ApiClient, | ||
MergedOptions, | ||
CustomEndpointArgClientConfigOptional |
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.
NIT: Might be an opportunity to sort this alphabetically.
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.
sounds good
shortCode: config.organizationId | ||
}, | ||
proxy: config.proxy, | ||
...clientConfig |
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 answers my previous question. 👍
Co-authored-by: Alex Vuong <alex.vuong@salesforce.com> Signed-off-by: Kevin He <kevin.he@salesforce.com>
…ceCommerceCloud/pwa-kit into custom-endpoint-support
Description
This PR introduces support for calling SCAPI custom endpoint. It upgrades
commerce-sdk-isormorphic
to the latest versionv2
. Two new hooks are introduced in this PR.New hooks
useCustomQuery
useCustomMutation
Types of Changes
How to Test-Drive This PR
npm ci
cd ./packages/test-commerce-sdk-react && npm start
localhost:3000/custom-endpoint
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization