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

Update Node SDK #715

Merged
merged 7 commits into from
Nov 13, 2024
Merged

Update Node SDK #715

merged 7 commits into from
Nov 13, 2024

Conversation

rygine
Copy link
Collaborator

@rygine rygine commented Nov 13, 2024

Summary

  • Upgraded Node bindings
  • Updated return type of Client.canMessage to match the browser SDK
  • Added requirement of encryption key
  • Updated logging options
  • Added smart contract wallet support
  • Updated node bindings re-exports

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced logging capabilities in the Client class with structured logging options.
    • Added a method for adding signatures with additional parameters.
  • Improvements

    • Updated method signatures to better accommodate new parameters.
    • Explicitly exported types for improved clarity and organization.
  • Bug Fixes

    • Adjusted test cases to align with changes in the canMessage method's return structure.
  • Chores

    • Updated dependency version for @xmtp/node-bindings.

@rygine rygine requested a review from a team as a code owner November 13, 2024 17:47
Copy link

changeset-bot bot commented Nov 13, 2024

🦋 Changeset detected

Latest commit: 31ca82d

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 Nov 13, 2024

Walkthrough

The pull request introduces several updates to the @xmtp/node-sdk package, including a version bump of the @xmtp/node-bindings dependency. Key modifications to the Client class involve changes to method signatures, the introduction of new types for logging options, and adjustments to how encryption keys are handled. Additionally, the exports in the index.ts file are made more explicit. Test cases are updated to reflect these changes, particularly in how the canMessage method's return value is validated.

Changes

File Change Summary
sdks/node-sdk/package.json Dependency version updated: @xmtp/node-bindings from ^0.0.17 to ^0.0.18.
sdks/node-sdk/src/Client.ts - Method signature updated for create to include encryptionKey.
- New method addScwSignature added.
- New type LogOptions imported.
- OtherOptions updated to include structuredLogging and loggingLevel.
- Removed encryptionKey from StorageOptions.
sdks/node-sdk/src/index.ts Wildcard exports replaced with explicit type exports for clarity. New types exported include LogOptions, Consent, and others from @xmtp/node-bindings.
sdks/node-sdk/test/Client.test.ts Updated test cases for Client class: changed verification of canMessage return value to use Object.fromEntries(), and removed specific assertions related to the previous structure.
sdks/node-sdk/test/helpers.ts Added testEncryptionKey constant and updated the createClient function to pass this key as an argument to Client.create, reflecting changes in the method signature.

Possibly related PRs

  • Update Node SDK #694: Updates to the Client class, including method signature modifications and new types, relevant to the changes in the main PR.
  • Upgrade node bindings #709: Updates the @xmtp/node-bindings dependency, directly related to the version bump in the main PR's package.json.
  • Update Browser SDK #713: Introduces a requirement for an encryptionKey when creating a new client, aligning with the changes made in the main PR.

Suggested reviewers

  • nplasterer
  • insipx

Poem

🐰 In the meadow where rabbits play,
A new version hops in today!
With keys for encrypting our chat,
And logs that are structured, imagine that!
So let’s celebrate this code delight,
As we bound into the coding night! 🌙


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1f1e713 and 31ca82d.

📒 Files selected for processing (1)
  • .changeset/ninety-moons-agree.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/ninety-moons-agree.md

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.

Copy link

cloudflare-workers-and-pages bot commented Nov 13, 2024

Deploying xmtp-js-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 31ca82d
Status: ✅  Deploy successful!
Preview URL: https://a442f404.xmtp-js.pages.dev
Branch Preview URL: https://rygine-node-sdk-update.xmtp-js.pages.dev

View logs

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: 2

🧹 Outside diff range and nitpick comments (7)
sdks/node-sdk/test/helpers.ts (1)

1-1: Consider generating unique encryption keys per test

While using getRandomValues for key generation is secure, having a single shared encryption key at module level could potentially lead to test interference or make it harder to test key-specific scenarios. Consider moving the key generation into the createClient function to ensure each test instance has its own unique key.

-const testEncryptionKey = getRandomValues(new Uint8Array(32));

 export const createClient = async (user: User, options?: ClientOptions) => {
+  const testEncryptionKey = getRandomValues(new Uint8Array(32));
   const opts = {
     ...options,
     env: options?.env ?? "local",
   };
   return Client.create(user.account.address, testEncryptionKey, {

Also applies to: 17-17

sdks/node-sdk/test/Client.test.ts (3)

38-40: LGTM! Consider adding more test cases.

The updated assertion correctly validates the new return type of canMessage using Object.fromEntries(). This aligns with the PR objective of updating the method's return type to match the browser SDK.

Consider adding more test cases to cover:

  • Multiple addresses with mixed registration status
  • Invalid/malformed addresses
  • Empty address array
  • Case sensitivity handling

Example:

it("should handle multiple addresses with mixed registration status", async () => {
  const user1 = createUser();
  const user2 = createUser();
  const client = await createRegisteredClient(user1);
  const canMessage = await client.canMessage([
    user1.account.address,
    user2.account.address
  ]);
  expect(Object.fromEntries(canMessage)).toEqual({
    [user1.account.address.toLowerCase()]: true,
    [user2.account.address.toLowerCase()]: false
  });
});

Line range hint 1-1: Add test coverage for new features.

The PR introduces two significant features that require test coverage:

  1. Encryption key requirement:
  • Add tests to verify proper encryption key handling
  • Include negative test cases for invalid/missing keys
  1. Smart contract wallet support:
  • Add test cases using smart contract wallet addresses
  • Verify integration with existing wallet association tests

Would you like me to help generate the test cases for these features?


Line range hint 1-275: Enhance test organization and coverage.

The test suite is well-structured but could benefit from these improvements:

  1. Group related tests using nested describe blocks
  2. Split longer tests into smaller, focused cases
  3. Add explicit error case coverage

Example restructuring:

describe("Client", () => {
  describe("initialization", () => {
    it("should create an unregistered client", async () => {
      // existing create client test
    });
    
    it("should fail with invalid encryption key", async () => {
      // new test
    });
  });

  describe("registration", () => {
    // existing registration tests
  });

  describe("messaging capabilities", () => {
    // existing and new canMessage tests
  });

  describe("wallet management", () => {
    describe("adding wallets", () => {
      // split from existing add wallet test
    });
    
    describe("revoking wallets", () => {
      // split from existing revoke wallet test
    });
    
    describe("smart contract wallets", () => {
      // new tests
    });
  });
});
sdks/node-sdk/src/Client.ts (3)

76-80: Document default values for logging options

Including the default values in the JSDoc comments for structuredLogging and loggingLevel would enhance clarity for users regarding the expected behavior when these options are omitted.


101-105: Add documentation for the create method's parameters

Now that the create method requires an encryptionKey parameter, adding JSDoc comments for the method and its parameters would improve usability and help developers understand how to use it effectively.


207-215: Add documentation for the addScwSignature method

Adding JSDoc comments for the addScwSignature method would provide clarity on its purpose, parameters, and usage, benefiting other developers interfacing with this API.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b2a03b1 and 1f1e713.

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

13-25: LGTM! Explicit type exports improve clarity and maintainability.

The change from wildcard exports to explicit type exports is a good practice as it:

  • Makes dependencies more transparent
  • Enables better tree-shaking
  • Improves IDE support and type documentation

26-43: Verify version compatibility with node-bindings.

The explicit exports look good and support the new features. Let's verify the version compatibility to ensure all exported entities are available in the required version.

✅ Verification successful

Based on the results, I can now generate the final response:

Version compatibility with node-bindings is confirmed

The package requires ^0.0.18 of @xmtp/node-bindings and all exported types in the index.ts are actively used throughout the codebase, as evidenced by the import statements found in multiple files. The types being exported are consistent with their usage in the codebase, indicating proper version compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all exported entities exist in the specified version of node-bindings

# Check package.json for the required version
echo "Required version:"
fd -t f package.json -x grep -l "@xmtp/node-bindings" {} \; -exec grep -A 1 "@xmtp/node-bindings" {} \;

# Verify exports in node_modules (if available) or npm registry
echo -e "\nVerifying exports in @xmtp/node-bindings:"
curl -s https://registry.npmjs.org/@xmtp/node-bindings/latest | jq '.exports'

# Look for any potential breaking changes in the changelog
echo -e "\nChecking for breaking changes:"
fd -t f "CHANGELOG.md" -x grep -A 5 "0.0.18" {} \;

Length of output: 854


Script:

#!/bin/bash
# Let's try a different approach to verify the exports

# First, check the exact version requirement in package.json
echo "Checking package.json for node-bindings version:"
fd package.json -x cat {} \; | jq '.dependencies["@xmtp/node-bindings"]'

# Now let's check the actual type definitions in the source code
echo -e "\nChecking imported types from node-bindings:"
rg -A 1 "from ['\"]@xmtp/node-bindings['\"]" --type ts

# Let's also check if there are any type errors in the codebase
echo -e "\nChecking for potential type-related imports:"
ast-grep --pattern 'import { $$$_ } from "@xmtp/node-bindings"'

Length of output: 4143

sdks/node-sdk/package.json (1)

Line range hint 82-84: Verify Node.js version compatibility

The package requires Node.js >= 20. Please ensure that the new features and changes in @xmtp/[email protected] are compatible with this version requirement.

✅ Verification successful

Let me generate another verification script to check the node-bindings package's requirements and features:


Based on the verification results:

  1. The package requires Node.js >= 20 as specified in the package.json
  2. No Node.js 20+ specific features (WeakRef, Array.fromAsync, Promise.withResolvers) are used in the codebase
  3. The only modern JavaScript feature found is import.meta which is supported since Node.js 16
  4. The dependency @xmtp/[email protected] is used as a regular dependency

Node.js version compatibility verified

The codebase appears to be compatible with Node.js 20 requirement. No Node.js 20-specific features are used, and the existing code uses features well-supported in Node.js 20.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for Node.js version requirements in dependencies

# Check package.json in node-bindings for engine requirements
rg -l "node-bindings" | xargs rg "engines|node"

# Check for usage of Node.js 20+ specific features
ast-grep --pattern 'import.meta' # ES2020 feature

Length of output: 48466


Script:

#!/bin/bash
# Check node-bindings package.json for engine requirements and dependencies
rg -g "package.json" "\"@xmtp/node-bindings\"" -B5 -A5

# Look for any Node.js 20+ specific features in the codebase
ast-grep --pattern 'WeakRef'  # Node.js 20 feature
ast-grep --pattern 'Array.fromAsync' # Node.js 20 feature
ast-grep --pattern 'Promise.withResolvers' # Node.js 20 feature

Length of output: 797

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

115-118: Logging options initialized correctly

The logOptions object is properly initialized with default values, ensuring logging behaves as expected when options are not specified.


196-197: Updated return type of canMessage method to Map

Changing the return type of canMessage to a Map enhances data handling and aligns with modern JavaScript practices.

sdks/node-sdk/package.json Show resolved Hide resolved
sdks/node-sdk/test/helpers.ts Show resolved Hide resolved
@rygine rygine requested a review from a team as a code owner November 13, 2024 17:54
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