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

Export parameter keys (@W-15676813@) #158

Merged
merged 8 commits into from
Jun 6, 2024
Merged

Conversation

vmarta
Copy link
Contributor

@vmarta vmarta commented Jun 6, 2024

This PR exports the parameter keys for each API method, so that a client like commerce-sdk-react will be able to rely on them (and no longer hardcoding those param keys).

For an example on how to consume the exported parameter keys, please see SalesforceCommerceCloud/pwa-kit#1812

Note: this PR is for the parameter keys (not its Typescript types). So we're exporting the list/array.

Previous PR: #157

How to test-drive

In this case, I worked with 2 separate repos: this commerce-sdk-isomorphic (exports the parameter keys) and the pwa-kit (to consume those keys).

So first of all, let's build the commerce-sdk-isomorphic to get its minified output:

  1. yarn install
  2. yarn run renderTemplates
  3. yarn run build:lib
  4. If you need more details: https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/blob/export-parameter-keys/Contributing.md

Once we've gotten those minified scripts, we need to somehow use them in the pwa-kit repo. I've tried npm link but gotten an error. I'm not sure how to npm link properly within a monorepo like ours. Anyways, I manually created a symlink instead, like this:

  1. Switch to the pwa-kit repo and check out this sample PR: [commerce-sdk-react] Try consuming parameter keys from isomorphic lib pwa-kit#1812
  2. Create symlink from commerce-sdk-react
	# From "pwa-kit/packages/commerce-sdk-react"
	rm -r node_modules/commerce-sdk-isomorphic/lib
	ln -s ~/repos/commerce-sdk-isomorphic/lib node_modules/commerce-sdk-isomorphic
  1. Now in your code editor, open the file "packages/commerce-sdk-react/src/hooks/ShopperProducts/query.ts".
  2. Inspect the values of some variables, and you'll see the parameter keys like this:

iTerm2 2024-06-04 at 11 04 02

iTerm2 2024-06-04 at 11 04 43

@vmarta vmarta marked this pull request as ready for review June 6, 2024 18:59
@vmarta vmarta requested a review from a team as a code owner June 6, 2024 18:59
Comment on lines +180 to +184
"maxSize": "48 kB"
},
{
"path": "commerce-sdk-isomorphic-with-deps.tgz",
"maxSize": "400 kB"
"maxSize": "410 kB"
Copy link
Contributor Author

@vmarta vmarta Jun 6, 2024

Choose a reason for hiding this comment

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

The latest sizes.. they're a slight increase from before.
iTerm2 2024-06-06 at 12 35 15

static readonly paramKeys = {
{{#each encodes.endPoints}}
{{#each operations}}
{{{name}}}: [
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice way to also include the endpoint names

@vmarta vmarta merged commit 361aed9 into main Jun 6, 2024
10 checks passed
@vmarta vmarta deleted the export-parameter-keys-2 branch June 6, 2024 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants