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

Instantiate XrpcClient from an OAuthAgent #2714

Merged
merged 27 commits into from
Aug 22, 2024
Merged

Conversation

matthieusieben
Copy link
Contributor

@matthieusieben matthieusieben commented Aug 14, 2024

  • @atproto/api's Agent class can now be instantiated using a SessionManager interface (new Agent(sessMgr))
  • @atproto/client's OAuthSession implements the SessionManager interface meaning that we can do new Agent(oauthSession)
  • @atproto/api's AtpAgent works exactly as before. A comment was added to say that is will soon become deprecated as it adds no value anymore.
  • @atproto/api now exposes an CredentialSession class that can be used to instantiate both new Agent(credSession) as-well-as new XrpcClient(credSession, myLex)

Potentially breaking changes:

  • Agent is no longer abstract, and its constructor signature has changed. This means that any implementation extending that class will be broken. Since this abstract class was release very recently, the impact should be minimal.

  • Agent no longer extends AtpBaseClient (this is an implementation detail so should no really impact anything)

  • @atproto/oauth-client* no longer expose an agent, but a session instead. Adapting to this is very straight forward (new Agent(session)).

  • OAuthAgent was renamed into OAuthSession and some method signatures where changed

Copy link
Collaborator

@devinivy devinivy left a comment

Choose a reason for hiding this comment

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

Looks good! I support this change to the oauth client 👍 I think it will be much friendlier to folks building their own apps, and at little cost of convenience.

It does stand out to me that the dependency of @atproto/oauth-client on @atproto/api is now very shallow. I can't help but wonder if there's a way to maintain the convenience of obtaining an OAuthAtpClient without the hard dependency on @atproto/api.

@matthieusieben
Copy link
Contributor Author

Hey @devinivy, thank you for the review. I moved the OAuthAtpAgent class into the api agent. This reverses the dependency between @atproto/api and @atproto/oauth-client but that extra dependency in api is only needed for typing purposes and should not impact the bundle size.

With this change, the @atproto/api is no longer needed in order to instantiate custom @atproto/xrpc clients.

@matthieusieben
Copy link
Contributor Author

This whole PR introduces a breaking change in the oauth-client* packages but I think it's fine since those were not released yet (will impact ozone but no big deal).

cc @foysalit

.changeset/chilled-jokes-relax.md Outdated Show resolved Hide resolved
.changeset/old-mice-give.md Outdated Show resolved Hide resolved
packages/api/OAUTH.md Outdated Show resolved Hide resolved
packages/api/OAUTH.md Outdated Show resolved Hide resolved
packages/oauth/oauth-client/README.md Outdated Show resolved Hide resolved
matthieusieben and others added 2 commits August 22, 2024 16:08
Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com>
Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com>
matthieusieben and others added 2 commits August 22, 2024 16:09
Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com>
Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com>
packages/api/OAUTH.md Outdated Show resolved Hide resolved
@matthieusieben
Copy link
Contributor Author

Thanks @surfdude29 for your careful review <3

@surfdude29
Copy link
Contributor

Thanks @surfdude29 for your careful review <3

No worries, happy to help :)

devinivy
devinivy approved these changes Aug 22, 2024
Copy link
Collaborator

@devinivy devinivy left a comment

Choose a reason for hiding this comment

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

A couple tiny questions but this looks good— very excited by these changes. Breaking the dependency between @atproto/api and @atproto/oauth-client is also 💎.

```

### API calls

The agent includes methods for many common operations, including:

```typescript
// The DID of the user currently authenticated (or undefined)
agent.did
agent.accountDid // Throws if the user is not authenticated
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting! I just noticed this part of the api for the first time.

Small thing: I wonder if this should be assertDid instead of accountDid to make this clearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep that would probably have been a better name -_-

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd recommend we add assertDid and deprecate accountDid at some point soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@pfrazee pfrazee left a comment

Choose a reason for hiding this comment

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

Really great. I'm excited to be making progress on cleaning up all these interfaces -- they've been clunky for a long time before oauth.

@devinivy devinivy merged commit d9ffa3c into main Aug 22, 2024
1 check passed
@devinivy devinivy deleted the msieben/oauth-xrpc-dx branch August 22, 2024 21:59
@github-actions github-actions bot mentioned this pull request Aug 22, 2024
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.

4 participants