/api/queryOptions.ts - Contains the query option factories that should be used in multiple places throughout the codebase
Almost all previous auth logic has been consolidated into CoderAuthProvider.tsx
Created a UrlSync class for managing URLs a lot more consistently
It's basically a wrapper over Backstage's DiscoveryApi, and is designed to work with useSyncExternalStore
The idea is that when CoderClient needs to make a request, it will get it through UrlSync. UrlSync will then detect when the API endpoints change and notify React components through the hook
This is almost exactly the same setup that Backstage recommends through DiscoveryApi, except that we have better React UI support
Upgraded the useBackstageEndpoints hook into useUrlSync
Modified the workspaces queries so that they'll periodically refetch if any of the workspaces returned were in a pending state
Updated the mock server middleware to ensure that all requests have a valid Coder session token
Notes
@code-asher I know we talked about how trying to fix the DiscoveryApi jank right now wasn't worth it, but the more I thought about it, the more I realized that it would fix a lot of problems
Help centralize a bunch of ad-hoc API logic I have strewn all over the codebase, and make sure that they can't get out of sync with each other
Make it a lot easier to implement CoderClient – a lot of the properties I was originally trying to expose through it were better suited for UrlSync
I also approached this PR more incrementally, to ensure I wasn't breaking tests left and right
One of the problems with the previous PRs is that I still don't know how to get the tests 100% passing without trying to cheat the tests. But if we're cheating the tests, that's just going to destroy our trust in them
Next PRs will cover the CoderClient, and then the Coder SDK
I'm going to wait until the dust settles a bit before trying to make a universal auth system for token auth/OAuth
Think I finally have things figured out. This is part 1 of a new set of PRs for bringing the Coder SDK into Backstage. Connected to #107
Changes made
I'd say most of these changes qualify as me cleaning up previous messes, and making it easier to build on the plugin going forward.
api.ts
file up:/api/api.ts
- Contains the majority of the previous fetch logic. This will eventually becomeCoderClient
/api/errors.ts
- Contains custom error definitions/api/queryOptions.ts
- Contains the query option factories that should be used in multiple places throughout the codebaseCoderAuthProvider.tsx
UrlSync
class for managing URLs a lot more consistentlyDiscoveryApi
, and is designed to work withuseSyncExternalStore
CoderClient
needs to make a request, it will get it throughUrlSync
.UrlSync
will then detect when the API endpoints change and notify React components through the hookDiscoveryApi
, except that we have better React UI supportuseBackstageEndpoints
hook intouseUrlSync
Notes
DiscoveryApi
jank right now wasn't worth it, but the more I thought about it, the more I realized that it would fix a lot of problemsCoderClient
– a lot of the properties I was originally trying to expose through it were better suited forUrlSync
CoderClient
, and then the Coder SDK