Skip to content

feat: add all options to verifyKey#2827

Merged
chronark merged 5 commits intomainfrom
verify-key-options
Jan 21, 2025
Merged

feat: add all options to verifyKey#2827
chronark merged 5 commits intomainfrom
verify-key-options

Conversation

@chronark
Copy link
Collaborator

@chronark chronark commented Jan 21, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced key verification functionality in the @unkey/api package.
    • Added comprehensive options for key validation.
    • Improved API verification endpoint with detailed filtering and reporting capabilities.
  • Documentation

    • Updated API specification with more detailed verification parameters and response structures.

@vercel
Copy link

vercel bot commented Jan 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 21, 2025 4:54pm
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 21, 2025 4:54pm
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 21, 2025 4:54pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 21, 2025 4:54pm

@changeset-bot
Copy link

changeset-bot bot commented Jan 21, 2025

🦋 Changeset detected

Latest commit: 24c7a87

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

This PR includes changesets to release 5 packages
Name Type
@unkey/api Minor
@unkey/hono Patch
@unkey/nextjs Patch
@unkey/ratelimit Patch
@unkey/dashboard 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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The pull request introduces enhanced functionality for key verification in the @unkey/api package. The changes include adding a new verifyKey method that allows for comprehensive validation with various options, and modifying the getVerifications operation in the OpenAPI specification. This includes renaming the operation and updating its parameters and response structure to provide more detailed verification statistics.

Changes

File Change Summary
.changeset/unlucky-bottles-punch.md Added changeset for new key verification functionality
packages/api/src/openapi.d.ts Renamed getVerifications operation to keys.getVerifications, updated parameters and response structure for verification queries
packages/api/src/verify.ts Enhanced verifyKey function with a more complex type signature supporting permissions and broader request formats

Possibly related PRs

Suggested labels

Feature

Suggested reviewers

  • mcstepp
  • perkinsjr
  • MichaelUnkey
  • chronark

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 21, 2025

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
packages/api/src/verify.ts (1)

26-31: Consider simplifying the verifyKey function signature for readability

The function signature is quite complex due to deep type manipulation. To improve readability and maintainability, consider extracting the complex type into a named type alias.

You might define a type alias like:

type VerifyKeyRequest<TPermission extends string = string> = string | Omit<
  paths["/v1/keys.verifyKey"]["post"]["requestBody"]["content"]["application/json"],
  "authorization"
> & { authorization?: { permissions: PermissionQuery<TPermission> } };

Then, update the function signature:

-export function verifyKey<TPermission extends string = string>(
-  req: string | Omit<
-      paths["/v1/keys.verifyKey"]["post"]["requestBody"]["content"]["application/json"],
-      "authorization"
-    > & { authorization?: { permissions: PermissionQuery<TPermission> } },
-) {
+export function verifyKey<TPermission extends string = string>(
+  req: VerifyKeyRequest<TPermission>,
+) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8fa80a and 591bf74.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • .changeset/unlucky-bottles-punch.md (1 hunks)
  • packages/api/src/openapi.d.ts (3 hunks)
  • packages/api/src/verify.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Test Packages / Test ./internal/billing
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Build / Build
  • GitHub Check: autofix
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
packages/api/src/openapi.d.ts (2)

41-41: Ensure consistent operation ID updates throughout the codebase

The operation ID has been updated to keys.getVerifications. Please verify that all occurrences of getVerifications have been updated accordingly to prevent inconsistencies.

Run the following script to find any remaining references to getVerifications:

✅ Verification successful

Operation ID update is correct and consistent

The operation ID keys.getVerifications is correctly used for the keys API endpoint, while getVerifications is a separate operation ID for the analytics API endpoint. Both are being used consistently in their respective contexts throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all occurrences of 'operations["getVerifications"]' in the codebase.

rg 'operations\["getVerifications"\]'

Length of output: 110


Script:

#!/bin/bash
# Search for any occurrence of getVerifications, case-sensitive
rg -t ts -t js "getVerifications" -A 2

# Search for the new format specifically
rg -t ts -t js 'keys\.getVerifications' -A 2

Length of output: 21951


4498-4607: ⚠️ Potential issue

Resolve potential duplicate definitions of getVerifications operation

It appears that there is still a definition of the getVerifications operation starting at line 4498, which may conflict with the updated keys.getVerifications operation. This duplication could cause confusion or errors in the API specification.

Run the following script to identify any duplicate operation definitions:

.changeset/unlucky-bottles-punch.md (1)

1-5: Changeset is properly formatted

The changeset correctly specifies the package and the change type, and provides an appropriate description.

Copy link
Contributor

@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: 1

🧹 Nitpick comments (2)
packages/api/src/verify.ts (2)

Line range hint 34-37: Consider clarifying the empty token comment.

The comment about the empty token could be more explicit about why this is necessary and any potential future improvements.

Consider updating the comment to:

-  // yes this is empty to make typescript happy but we don't need a token for verifying keys
-  // it's not the cleanest but it works for now :)
+  // The rootKey is set to "public" as key verification doesn't require authentication.
+  // This satisfies TypeScript's type requirements while maintaining security.
+  // TODO: Consider refactoring the client initialization to better handle public endpoints

Line range hint 37-37: Consider type safety improvement for the verify call.

The current implementation uses type assertion through the ternary operator. Consider making this more type-safe.

-  return unkey.keys.verify(typeof req === "string" ? { key: req } : req);
+  const request = typeof req === "string" ? { key: req } : req;
+  return unkey.keys.verify(request);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 591bf74 and 99cffc4.

📒 Files selected for processing (1)
  • packages/api/src/verify.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Test Packages / Test ./packages/rbac
  • GitHub Check: Test Packages / Test ./packages/nextjs
  • GitHub Check: Test Packages / Test ./packages/cache
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test API / API Test Local
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Build / Build
  • GitHub Check: autofix

@chronark chronark requested a review from perkinsjr January 21, 2025 16:49
@chronark chronark deleted the verify-key-options branch January 21, 2025 16:58
@coderabbitai coderabbitai bot mentioned this pull request Jan 23, 2025
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