Skip to content

docs: README for @unkey/nextjs #2162#2166

Merged
chronark merged 1 commit intounkeyed:mainfrom
Ionfinisher:main
Oct 3, 2024
Merged

docs: README for @unkey/nextjs #2162#2166
chronark merged 1 commit intounkeyed:mainfrom
Ionfinisher:main

Conversation

@Ionfinisher
Copy link
Contributor

@Ionfinisher Ionfinisher commented Oct 3, 2024

What does this PR do?

This PR adds a README file for the @unkey/nextjs package on npm.

Fixes #2162

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

Summary by CodeRabbit

  • New Features
    • Introduced a comprehensive README for the @unkey/nextjs SDK, detailing installation, quickstart usage, and customization options.
  • Documentation
    • Added sections on protecting API routes and handling API key verification.
    • Included a link to full documentation for further reference.
  • Chores
    • Updated package.json to include the README file in the package distribution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 3, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request introduce a new README file for the @unkey/nextjs SDK, detailing its purpose, installation, quickstart usage, and customization options. Additionally, the package.json file is updated to include the README in the package distribution, ensuring that it is available alongside the SDK when published.

Changes

File Change Summary
packages/nextjs/README.md New README file added, covering SDK overview, usage, and customization options.
packages/nextjs/package.json Updated files array to include README.md alongside ./dist/**.

Assessment against linked issues

Objective Addressed Explanation
Add README for @unkey/nextjs package (#2162)
Include README in the package.json files config (#2162)

Possibly related PRs

  • feat: added README.md in /packages/api #2153: The addition of a README.md file for the @unkey/api SDK is similar to the new README file for the @unkey/nextjs SDK, both providing essential documentation and usage instructions for their respective packages.

Suggested reviewers

  • chronark
  • perkinsjr

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.

@vercel
Copy link

vercel bot commented Oct 3, 2024

@Ionfinisher is attempting to deploy a commit to the Unkey Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link

changeset-bot bot commented Oct 3, 2024

⚠️ No Changeset found

Latest commit: a836587

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@CLAassistant
Copy link

CLAassistant commented Oct 3, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added 🕹️ 150 points Documentation Improvements or additions to documentation Good first issue Good for newcomers labels Oct 3, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2024

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

🧹 Outside diff range and nitpick comments (3)
packages/nextjs/package.json (1)

Line range hint 1-32: Summary: README inclusion addressed, consider adding a description field.

The change to include "README.md" in the files array successfully addresses the PR's main objective. The package.json file is otherwise complete for the package's needs.

As a minor suggestion for future improvements:

Consider adding a description field to the package.json. This would provide a brief explanation of the package's purpose, which is helpful for users browsing npm. For example:

{
  "name": "@unkey/nextjs",
  "version": "0.17.7",
  "description": "Next.js integration for Unkey API key management",
  // ... other fields
}
packages/nextjs/README.md (2)

17-35: LGTM: Quickstart guide is informative and easy to follow.

The quickstart section effectively demonstrates how to use the withUnkey handler with a clear code example. It also provides a helpful explanation about key verification.

Consider adding a brief explanation of what req.unkey contains (e.g., the structure of the verification response) to provide more context for users.


51-51: Minor grammatical improvement suggested.

Consider adding a comma after "By default" for better readability.

-By default errors will be logged to the console, and ```withUnkey``` will return a NextResponse with status 500.
+By default, errors will be logged to the console, and ```withUnkey``` will return a NextResponse with status 500.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~51-~51: Did you mean: “By default,”?
Context: ... You can specify custom error handling. By default errors will be logged to the console, a...

(BY_DEFAULT_COMMA)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 713e831 and a836587.

📒 Files selected for processing (2)
  • packages/nextjs/README.md (1 hunks)
  • packages/nextjs/package.json (1 hunks)
🧰 Additional context used
🪛 LanguageTool
packages/nextjs/README.md

[style] ~39-~39: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ... the authorization header. If you want to customize this, you can do so by passin...

(REP_WANT_TO_VB)


[uncategorized] ~51-~51: Did you mean: “By default,”?
Context: ... You can specify custom error handling. By default errors will be logged to the console, a...

(BY_DEFAULT_COMMA)

🪛 Markdownlint
packages/nextjs/README.md

45-45: Column: 1
Hard tabs

(MD010, no-hard-tabs)


57-57: Column: 1
Hard tabs

(MD010, no-hard-tabs)


72-72: Column: 1
Hard tabs

(MD010, no-hard-tabs)

🔇 Additional comments (6)
packages/nextjs/package.json (1)

16-16: LGTM! README.md correctly added to the files array.

The addition of "README.md" to the files array is correct and aligns with the PR objectives. This change ensures that the README file will be included when the package is published to npm, addressing the issue raised in #2162.

To verify that the README file exists in the correct location, run the following script:

✅ Verification successful

README.md has been successfully added to the files array and exists in the correct location. This change ensures that the README will be included when the package is published to npm, effectively addressing the issue raised in #2162.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of README.md in the packages/nextjs directory

# Test: Check if README.md exists in the packages/nextjs directory
if [ -f "packages/nextjs/README.md" ]; then
    echo "README.md exists in the correct location."
else
    echo "ERROR: README.md is missing from packages/nextjs directory."
fi

Length of output: 131

packages/nextjs/README.md (5)

1-10: LGTM: Header section is well-structured and informative.

The header section provides a clear introduction to the @unkey/nextjs SDK, including its purpose and a link to the full documentation. This aligns well with the PR objectives.


11-15: LGTM: Installation instructions are clear and concise.

The installation section provides a simple npm command to install the package, which is sufficient for most users.


79-89: LGTM: Telemetry information is transparent and provides opt-out instructions.

The section clearly explains the default telemetry behavior and provides an easy way for users to disable it if desired. This transparency is appreciated.


91-93: LGTM: Documentation link is provided as required.

The README concludes with a clear link to the full documentation, which satisfies the PR objective of including documentation links.


1-93: Overall, excellent README that meets PR objectives.

This README file for the @unkey/nextjs SDK successfully addresses the requirements outlined in the PR objectives. It provides a comprehensive guide including installation instructions, a quickstart section, customization options, and links to full documentation. The content is well-structured and informative, making it easy for users to get started with the SDK.

A few minor improvements have been suggested regarding formatting consistency and grammar, but these do not detract from the overall quality of the document. Great job on creating this helpful resource for users of the @unkey/nextjs package!

🧰 Tools
🪛 LanguageTool

[style] ~39-~39: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ... the authorization header. If you want to customize this, you can do so by passin...

(REP_WANT_TO_VB)


[uncategorized] ~51-~51: Did you mean: “By default,”?
Context: ... You can specify custom error handling. By default errors will be logged to the console, a...

(BY_DEFAULT_COMMA)

🪛 Markdownlint

45-45: Column: 1
Hard tabs

(MD010, no-hard-tabs)


57-57: Column: 1
Hard tabs

(MD010, no-hard-tabs)


72-72: Column: 1
Hard tabs

(MD010, no-hard-tabs)

Comment on lines +36 to +76
If you want to customize how withUnkey processes incoming requests, you can do so as follows:

## ```getKey```
By default, withUnkey will look for a bearer token located in the ```authorization``` header. If you want to customize this, you can do so by passing a getter in the configuration object:

```ts
export const GET = withUnkey(async (req) => {
// ...
}, {
getKey: (req) => new URL(req.url).searchParams.get("key"),
});
```

## ```onError```

You can specify custom error handling. By default errors will be logged to the console, and ```withUnkey``` will return a NextResponse with status 500.

```ts
export const GET = withUnkey(async (req) => {
// ...
}, {
onError: async (req, res) => {
await analytics.trackEvent(`Error ${res.code}: ${res.message}`)
return new NextResponse("Unkey error", { status: 500 })
}
});
```

## ```handleInvalidKey```

Specify what to do if Unkey reports that your key is invalid.

```ts
export const GET = withUnkey(async (req) => {
// ...
}, {
handleInvalidKey: (req, res) => {
return new Response("Unauthorized", { status: 401 })
}
});
```
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Issues Found: Inconsistent Indentation in README.md

The README.md file exhibits inconsistent indentation, using both tabs and spaces within the code examples and documentation. Specifically:

  • Uses Tabs:

    • getKey: (req) => new URL(req.url).searchParams.get("key"),
    • onError: async (req, res) => {
    • handleInvalidKey: (req, res) => {
  • Uses Spaces:

    • Various lines in the documentation sections and other parts of the file.

Recommendation:

  • Standardize Indentation: Adopt a single indentation style, preferably spaces, across all code examples and documentation to enhance readability and maintain consistency.
🔗 Analysis chain

LGTM: Customization options are well-explained with clear examples.

The customization section covers important options like getKey, onError, and handleInvalidKey, providing users with the flexibility to adapt the SDK to their needs.

  1. Consider using consistent indentation throughout the code examples. Some lines use tabs (e.g., lines 45, 57, 72) while others use spaces.
  2. In the onError example, consider adding a comment explaining what res.code and res.message represent.

To check for consistent indentation across the file, run:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent indentation in the README.md file

# Test: Look for lines with tabs
rg '\t' packages/nextjs/README.md

# Test: Look for lines with spaces at the beginning
rg '^ +' packages/nextjs/README.md

Length of output: 874

🧰 Tools
🪛 LanguageTool

[style] ~39-~39: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ... the authorization header. If you want to customize this, you can do so by passin...

(REP_WANT_TO_VB)


[uncategorized] ~51-~51: Did you mean: “By default,”?
Context: ... You can specify custom error handling. By default errors will be logged to the console, a...

(BY_DEFAULT_COMMA)

🪛 Markdownlint

45-45: Column: 1
Hard tabs

(MD010, no-hard-tabs)


57-57: Column: 1
Hard tabs

(MD010, no-hard-tabs)


72-72: Column: 1
Hard tabs

(MD010, no-hard-tabs)

@chronark chronark merged commit cff6f74 into unkeyed:main Oct 3, 2024
@oss-gg
Copy link

oss-gg bot commented Oct 3, 2024

Awarding Ionfinisher: 150 points 🕹️ Well done! Check out your new contribution on oss.gg/Ionfinisher

@coderabbitai coderabbitai bot mentioned this pull request Oct 4, 2024
mcstepp pushed a commit that referenced this pull request Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[docs] Add README for @unkey/nextjs package

3 participants