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

Add static authorization methods to Node SDK Client #740

Merged
merged 4 commits into from
Dec 2, 2024

Conversation

rygine
Copy link
Collaborator

@rygine rygine commented Dec 2, 2024

Summary

  • Upgraded node bindings
  • Replaced existing authorization client methods with static methods
  • Added tests

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced static authorization methods for enhanced user authentication and authorization workflows in the Node SDK Client.
  • Bug Fixes

    • Removed outdated instance methods for address and installation authorization, replacing them with more efficient static methods.
  • Tests

    • Added new test cases to validate the functionality of the static authorization methods.

@rygine rygine requested a review from a team as a code owner December 2, 2024 22:44
Copy link

changeset-bot bot commented Dec 2, 2024

🦋 Changeset detected

Latest commit: c8d7dea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@xmtp/node-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

coderabbitai bot commented Dec 2, 2024

Warning

Rate limit exceeded

@rygine has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 31 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8acbbe1 and c8d7dea.

Walkthrough

The changes introduce static authorization methods to the Node SDK Client in the @xmtp/node-sdk package, replacing existing instance methods. The package.json file is updated to reflect a new version of the @xmtp/node-bindings dependency. Additionally, test cases are added to validate the new static methods for checking authorization based on inbox and installation IDs.

Changes

File Change Summary
.changeset/clean-students-sell.md Added static authorization methods to the Node SDK Client.
sdks/node-sdk/package.json Updated dependency version of @xmtp/node-bindings from ^0.0.27 to ^0.0.28.
sdks/node-sdk/src/Client.ts Removed instance methods isAddressAuthorized and isInstallationAuthorized; added static methods with an options parameter. Updated import statements for new bindings.
sdks/node-sdk/test/Client.test.ts Added two test cases for the new static methods isAddressAuthorized and isInstallationAuthorized.

Possibly related PRs

  • Update Node SDK #694: Updates the Client class in the @xmtp/node-sdk, including changes to authorization methods directly related to the static methods introduced.
  • Update the node bindings #737: Adds new methods for checking address and installation authorization in the Client class, aligning with the static methods introduced.
  • Upgrade Node bindings #738: Focuses on upgrading the Node bindings, relevant to the SDK's authorization methods that may depend on these bindings.

Suggested reviewers

  • nplasterer

🐰 In the code so bright,
Static methods take flight,
Authorization made clear,
With tests that bring cheer!
Bouncing through code with glee,
Hop along, come see! 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rygine rygine requested a review from a team as a code owner December 2, 2024 22:44
Copy link

cloudflare-workers-and-pages bot commented Dec 2, 2024

Deploying xmtp-js-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: c8d7dea
Status: ✅  Deploy successful!
Preview URL: https://f173f434.xmtp-js.pages.dev
Branch Preview URL: https://rygine-node-sdk-client-updat.xmtp-js.pages.dev

View logs

"@xmtp/node-sdk": patch
---

Add static authorization methods to Node SDK Client
Copy link
Contributor

Choose a reason for hiding this comment

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

The random name generator really picked a good one this time. 😬 😆

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (2)
.changeset/clean-students-sell.md (1)

1-5: Consider enhancing the changeset description

While the description accurately reflects the changes, it could be more detailed to help users understand the impact. Consider adding:

  • Mention of the specific methods being added (isAddressAuthorized, isInstallationAuthorized)
  • Note about the removal of instance methods
  • Any breaking changes or migration steps if applicable
sdks/node-sdk/test/Client.test.ts (1)

238-242: Consider extracting environment configuration

The environment configuration is hardcoded in both tests. Consider:

  1. Using a shared constant or configuration
  2. Testing with different environment values
  3. Adding validation for the environment parameter
+const TEST_ENV = "local";
+
 it("should check if an address is authorized", async () => {
   // ...
   const authorized = await Client.isAddressAuthorized(
     client.inboxId,
     user.account.address.toLowerCase(),
-    { env: "local" },
+    { env: TEST_ENV },
   );
   // ...
 });

 it("should check if an installation is authorized", async () => {
   // ...
   const authorized = await Client.isInstallationAuthorized(
     client.inboxId,
     client.installationIdBytes,
-    { env: "local" },
+    { env: TEST_ENV },
   );
   // ...
 });

Also applies to: 249-253

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ee08db4 and 8acbbe1.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • .changeset/clean-students-sell.md (1 hunks)
  • sdks/node-sdk/package.json (1 hunks)
  • sdks/node-sdk/src/Client.ts (2 hunks)
  • sdks/node-sdk/test/Client.test.ts (1 hunks)
🔇 Additional comments (3)
sdks/node-sdk/package.json (1)

56-56: Verify compatibility with node-bindings pre-1.0 version

The dependency update to @xmtp/node-bindings@^0.0.28 uses caret versioning with a pre-1.0 version. Since pre-1.0 versions can include breaking changes even in minor versions, consider:

  1. Pinning to exact version (0.0.28) to prevent unexpected updates
  2. Adding a changelog entry or comment documenting the reason for the update
✅ Verification successful

Version update is documented and safe to use

The CHANGELOG.md shows this is a patch update (0.0.29) that simply upgrades to the latest node bindings. Since this is documented and intentional, the caret versioning (^0.0.28) is acceptable as it follows the project's versioning pattern seen throughout the changelog. No breaking changes are indicated for this update.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for breaking changes in node-bindings changelog
gh api repos/xmtp/xmtp-js/releases | jq -r '.[] | select(.tag_name | contains("node-bindings-v0.0.28")) | .body'

Length of output: 114


Script:

#!/bin/bash
# Let's try a different approach to check for any breaking changes or major updates
# First, check if there are any major dependency changes in package-lock.json
fd package-lock.json --exec cat {} | grep -A 5 -B 5 "@xmtp/node-bindings"

# Also check for any migration guides or upgrade notes in documentation
fd "CHANGELOG.md|UPGRADING.md|MIGRATION.md" --type f

Length of output: 751


Script:

#!/bin/bash
# Let's check the node-sdk's changelog for any relevant information about this dependency update
cat sdks/node-sdk/CHANGELOG.md

# Also check the package.json history to see the version progression
git log -p sdks/node-sdk/package.json | grep -A 5 -B 5 "@xmtp/node-bindings"

Length of output: 5780

sdks/node-sdk/src/Client.ts (2)

18-19: LGTM: Clean import additions

The new authorization binding imports are properly organized and clearly aliased.


444-460: Verify the impact of moving to static methods

The change from instance methods to static methods is a breaking change. Let's verify that all usages have been updated.

✅ Verification successful

Let me search for all usages of these methods to ensure they are being called correctly as static methods.


No breaking changes detected in the migration to static methods

All existing usages in the codebase are already using the static method syntax (Client.isAddressAuthorized and Client.isInstallationAuthorized). There are no instances of these methods being called with this. syntax, indicating that the migration to static methods has been properly handled.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining instance method calls that need to be updated
rg -l 'isAddressAuthorized|isInstallationAuthorized' --type ts | while read -r file; do
  echo "=== Checking $file ==="
  # Look for instance method calls (this.*) that need to be updated to static calls (Client.*)
  rg 'this\.(isAddressAuthorized|isInstallationAuthorized)' "$file" || true
done

Length of output: 515


Script:

#!/bin/bash
# Search for all usages of these methods
rg -A 2 'isAddressAuthorized|isInstallationAuthorized' --type ts

Length of output: 1453

sdks/node-sdk/test/Client.test.ts Outdated Show resolved Hide resolved
sdks/node-sdk/test/Client.test.ts Outdated Show resolved Hide resolved
sdks/node-sdk/src/Client.ts Show resolved Hide resolved
sdks/node-sdk/src/Client.ts Show resolved Hide resolved
@rygine rygine merged commit 7338e0e into main Dec 2, 2024
24 checks passed
@rygine rygine deleted the rygine/node-sdk-client-update branch December 2, 2024 23:00
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