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

Merge simplified hook signatures #1024

Merged
merged 15 commits into from
Mar 3, 2023

Conversation

kevinxh
Copy link
Collaborator

@kevinxh kevinxh commented Mar 2, 2023

WIP

wjhsf and others added 2 commits March 1, 2023 15:23
* Merge hooks changes from wjh/simplify-hooks

* lint fixes

* Use correct type.

* Remove unnecessary file.

* Add support for updater in cache updates.

* Sort imports.

* Change `updater` generic from being the same for all to being per function.

* Clean up cache update matrix.

* Rekerjigger cache logic to see what we can do with it.

* Create options merge util.

* Use merged options in query hooks and simplify query keys.

* Simplify endMatches logic.

* Add predicate helper to match API config values.

* Fix temp test file.

* Use consistent order of generic parameters.

* Remove pointless line.

* Use consistent generic parameter names.

* Add comments.

* More comments.

* Remove test directory.

* Generate hooks for all APIs

* Update Shopper Baskets config from Test directory.

* Update Shopper Experience query hooks.

* Fix missed merged options type.

* Add Shopper Login hooks.

* Convert getGiftCertificate from mutation hook to query hook.

* Update Shopper Login hooks.

Change logoutCustomer from query to mutation.
Change useRetrieveCredQualityUserInfo to getCredQualityUserInfo.

* First pass at converting to new cache update matrix.

* Remove canceled Shopper Discovery Search API.

* Update login helpers.

* Fix auth types.

* Hopefully avoid caching getGiftCertificate.

* Rename shopper login helper to auth helper.

* Move auth helper to hooks root.

* Mark useAuthorizationHeader as internal.

* Rename useAuth to useAuthContext for clarity w/ useAuthHelper.

* Convert useAuthHelper to default export for consistency.

* Remove siteId from AuthData, as it is passed via config.

* Update comment with generated code.

* Move headers to last parameter because we rarely use it.

* Update cache update matrices to new interface.

* Refactore test project after api changes.

* Clean up cache update logic.

Hopefully makes it much easier to maintain.

* Update names for clarity.

* Revert test file to version from develop.

* Add reminder to revert.

* Remove unnecessary default export.

* Cache update TODOs should return functions, not throw.

* Allow user to override authorization header.

* Remove old TODO.

* Remove ability to set custom query key.

Cache update logic requires knowing what query keys are used,
allowing arbitrary keys makes it impossible to know.

* Replace getQueryKey callback with just declaring query key.

* Clean up types.

* Rename config.ts to cache.ts

* Restore type checking test files.

* Suppress react query error logs during tests.

* Strip unused parameters before generating query key.

* Fix tpe errors.

* Partially fix type errors.

* Update Shopper Baskets cache logic to use narrower parameters.

* Test that all endpoints have hooks.

* Create new mutation tests for refactored code.

* Add test to validate all mutations have cache update logic.

* Alphabetize cache updates.

* Simplify mutation tests a bit.

* Fix nock adding duplicate request mocks.

* Make failing tests have more helpful failures.

Show the hook's error instead of "hook timed out" or nock mismatch.

* Fix tests failing due to missing parameters.

* Replace old mutation test file with new one.

* Remove unused helper type.

* Create hook success/error helpers.

* Improve parameter matching.

* Add `deleteBasket` tests.

* Add request mock to fix test.

* Add TODO cache update logic for missing mutations.

* Change onSuccess from bound to unbound function.

I'm not sure why, but testing mutations that throw an error in `onSuccess`
only works with unbound functions. When an unbound function is used, the
error is properly reported in the hook result. With a bound function, the
test framework throws an error.

* Add test for not implemented mutations.

* Pass not implemented tests.

* Remove unused import.

* Implement `resetPassword` caching as a no-op.

* Add Shopper Baskets query tests.

* Add "all endpoints have hooks" tests for all APIs.

* Fix failing index tests.

* Implement tests for all query hooks.

* Remove hooks for `authorizeCustomer` and `getTrustedAgentAuthorizationToken`.

These endpoints modify headers, rather than mutate or return data, so they
don't make sense for either query or mutation hooks. (At least, for our
current implementation.)

* Update "not implemented" tests to check if cache update logic exists.

* Extract reused type into type def.

* Update comment to reflect changed tests.

* Remove unnecessary `async`.

* Implement Shopper Contexts mutation tests.

* Rename `makeOptions` to `createOptions`.

* Implement Shopper Login mutation tests.

* Add extra ResponseError assertion.

* Update test names.

* Implement Shopper Orders mutation tests.

* Convert TODO from throwing to just logging.

* Fix failing "all endpoints have hooks" tests.

* Remove unused imports.

* Introduce query key helpers.

* Remove no longer needed query test file.

All query hooks are now ttested in their respective folders.

* Update hook usage.

* Implement basic Shopper Customers mutation tests.

* Export query key types.

* Remove old file.

* Update cache logic to use query keys instead of predicates.

* Update parser for proper TypeScript support.

babel-eslint is deprecated and superseded by @babel/eslint-parser.

* Remove unused babel-eslint.

* Temporarily(?) use internal-lib-build so TypeScript files are properly linted.

* Fix eslint and tsc errors.

* Temporarily suppress linter errors.

* Implement tests for shopper customers mutations that modify a customer.

* Implement full Shopper Customers mutation tests.

* Rename `StringIndexNever` to `StringIndexToNever`

* Remove unnecessary invalidation.

The query is already updated, so doesn't need to be invalidated.

* Update generated comments for hooks.

* Remove unused variable.

* Remove SLAS `authenticateCustomer` and `getPasswordResetToken` hooks.

They modify state and return headers, rather than body, so they are not
suitable for the current state of mutation hooks.

* Remove deprecated Shopper Customers mutations.

* Comment out Shopper Customers endpoints in closed beta.

* Fix Shopper Customers tests.

* Fix Shopper Login tests.

* Update "hook exists" tests to distinguish between "mutation in enum" and "mutation has cache logic"

---------

Co-authored-by: Ben Chypak <[email protected]>
@kevinxh kevinxh requested a review from a team as a code owner March 2, 2023 06:17
@wjhsf wjhsf merged commit fb5eded into feature/integrate-commerce-sdk-react Mar 3, 2023
@wjhsf wjhsf deleted the merge-20230301 branch March 3, 2023 18:49
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.

2 participants