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

demo project #3

Merged
merged 2 commits into from
Nov 20, 2024
Merged

demo project #3

merged 2 commits into from
Nov 20, 2024

Conversation

markusahlstrand
Copy link
Owner

@markusahlstrand markusahlstrand commented Nov 20, 2024

Got the demo project to render the swagger file. It's still missing some pieces to work all the way but it's exposing the management api that is created using the authhero library

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new documentation route (/docs) serving Swagger UI.
    • Added OpenAPI specifications available at the /spec endpoint.
    • New migration script for database schema modifications.
  • Dependency Updates

    • Updated multiple dependencies across various packages to enhance functionality and compatibility.
    • Removed IIFE build files from several packages.
  • Version Updates

    • Incremented version numbers for multiple packages to reflect recent changes.
  • Changelog Updates

    • Updated changelogs for all affected packages to document recent changes and version history.

Copy link

vercel bot commented Nov 20, 2024

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

Name Status Preview Comments Updated (UTC)
authhero-react-admin ❌ Failed (Inspect) Nov 20, 2024 1:53pm

Copy link

coderabbitai bot commented Nov 20, 2024

Walkthrough

The pull request introduces several updates across multiple packages, focusing on version increments, dependency management, and the removal of IIFE build files. Key changes include the addition of new dependencies in package.json files, the introduction of a new migration script in the Kysely package, and updates to changelogs reflecting these modifications. The overall structure of various configuration files like vite.config.ts has been simplified by eliminating the IIFE format. Additionally, new features such as OpenAPI documentation routes have been integrated into the demo application.

Changes

File Path Change Summary
apps/demo/CHANGELOG.md Updated to version 0.1.1, removed IIFE build files, updated dependencies authhero to 0.10.1, @authhero/kysely-adapter to 0.18.1. Retained entry for version 0.1.0.
apps/demo/package.json Updated version from 0.0.36 to 0.1.1, added new dependencies including @authhero/kysely-adapter and others.
apps/demo/src/app.ts Modified create function to initialize OpenAPIHono, added /docs route for Swagger UI, updated error handling, and simplified return type.
apps/demo/src/bun.ts Changed variable declaration from destructuring to direct assignment of app.
apps/demo/src/server.ts Introduced new server implementation, defined Env interface for database connectivity, and created a fetch method.
apps/demo/src/types/Bindings.ts Added new type definition Bindings for authentication configuration.
apps/demo/wrangler.toml Created new configuration file specifying main entry point and compatibility date.
packages/adapter-interfaces/CHANGELOG.md Updated to version 0.22.1, removed IIFE build files, noted previous version changes.
packages/adapter-interfaces/package.json Version updated to 0.22.1, added new @hono/zod-openapi dependency, updated existing dependencies.
packages/adapter-interfaces/vite.config.ts Removed iife format from build configuration.
packages/authhero/CHANGELOG.md Updated to version 0.10.1, removed IIFE build files, updated @authhero/adapter-interfaces to 0.22.1.
packages/authhero/package.json Version updated to 0.10.1, added dependencies @hono/zod-openapi and hono, updated existing dependencies.
packages/authhero/vite.config.ts Removed iife format from build configuration.
packages/drizzle/CHANGELOG.md Updated to version 0.1.57, removed IIFE build files, updated @authhero/adapter-interfaces to 0.22.1.
packages/drizzle/package.json Version updated to 0.1.57.
packages/drizzle/vite.config.ts Removed iife format from build configuration.
packages/kysely/CHANGELOG.md Updated to version 0.18.1, removed IIFE build files, updated @authhero/adapter-interfaces to 0.22.1.
packages/kysely/package.json Version updated to 0.18.1, added new dependencies including @hono/zod-openapi, hono, and others.
packages/kysely/src/migrate/migrations/2024-11-18T10:37:00_act_as.ts Added new migration script for logins table modification.
packages/kysely/src/migrate/migrations/index.ts Added new migration import and included it in default exports.
packages/kysely/vite.config.ts Removed iife format from build configuration.
packages/saml/CHANGELOG.md Updated to version 0.1.57, removed IIFE build files, updated @authhero/adapter-interfaces to 0.22.1.
packages/saml/package.json Version updated to 0.1.57.

Poem

In the meadow where rabbits play,
New changes hop in, brightening the day.
Dependencies dance, old files take flight,
With Swagger and Kysely, everything's right!
So let’s celebrate, with a joyful cheer,
For the code has transformed, the future is near! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/demo/src/app.ts

Oops! Something went wrong! :(

ESLint: 9.15.0

file:///eslint.config.mjs?mtime=1732110943431:6
import { configs, rules as reactRules } from "eslint-plugin-react";
^^^^^^^
SyntaxError: Named export 'configs' not found. The requested module 'eslint-plugin-react' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'eslint-plugin-react';
const { configs, rules: reactRules } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:171:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:254:5)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26)
at async loadConfigFile (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/config/config-loader.js:202:21)
at async ConfigLoader.calculateConfigArray (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/config/config-loader.js:512:32)
at async #calculateConfigArray (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/config/config-loader.js:646:29)
at async /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js:763:33
at async Promise.all (index 0)
at async ESLint.lintFiles (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js:759:25)
at async Object.execute (/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js:498:23)

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

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

🧹 Outside diff range and nitpick comments (15)
apps/demo/src/types/Bindings.ts (2)

1-7: LGTM! Consider adding JSDoc documentation.

The type structure is well-defined for authentication configuration. Consider adding JSDoc comments to document the purpose and requirements of each property.

+/**
+ * Configuration bindings for authentication and JWKS services
+ */
 export type Bindings = {
+  /** URL for the JSON Web Key Set endpoint */
   JWKS_URL: string;
+  /** Service configuration for JWKS operations */
   JWKS_SERVICE: {
     fetch: typeof fetch;
   };
+  /** Base URL for authentication endpoints */
   AUTH_URL: string;
 };

2-6: Consider stronger typing for URLs and validation.

For improved type safety and runtime validation:

  1. Consider using a URL-specific type or validation for JWKS_URL and AUTH_URL
  2. The JWKS_SERVICE.fetch might benefit from a more specific type if it has custom requirements beyond the global fetch

Example implementation with URL validation:

type ValidURL = string & { _brand: 'URL' };

const validateURL = (url: string): ValidURL => {
  try {
    new URL(url);
    return url as ValidURL;
  } catch {
    throw new Error(`Invalid URL: ${url}`);
  }
};

export type Bindings = {
  JWKS_URL: ValidURL;
  JWKS_SERVICE: {
    fetch: typeof fetch;
  };
  AUTH_URL: ValidURL;
};
packages/kysely/src/migrate/migrations/2024-11-18T10:37:00_act_as.ts (2)

7-7: Consider adding column constraints

The authParams_act_as column might benefit from additional constraints such as:

  • nullable/not null specification
  • Default value if applicable
  • Index if this column will be frequently queried

Example with constraints:

-    .addColumn("authParams_act_as", "varchar(255)")
+    .addColumn("authParams_act_as", "varchar(255)", (col) => col.nullable())

4-9: Document the purpose of authParams_act_as

Please add documentation comments explaining:

  • The purpose of this column
  • Expected format/values
  • How it relates to the authentication flow
apps/demo/src/bun.ts (2)

Line range hint 13-13: Consider adding type safety to the database schema.

Using Kysely<any> loses type safety benefits. Consider defining proper database interface types.

Example:

interface Database {
  users: {
    id: string;
    // ... other columns
  };
  // ... other tables
}

const db = new Kysely<Database>({
  dialect,
});

Line range hint 3-3: Consider documenting the @ts-ignore reason.

While @ts-ignore is necessary for Bun-specific modules, it would be helpful to document why it's needed.

-// @ts-ignore
+// @ts-ignore: Bun-specific module types are not yet available in @types
apps/demo/src/server.ts (3)

7-11: Add JSDoc documentation and consider environment validation

The Env interface handles sensitive credentials but lacks documentation and validation.

+/**
+ * Environment configuration for database connectivity
+ * @property DATABASE_HOST - The PlanetScale database host URL
+ * @property DATABASE_USERNAME - Database username credential
+ * @property DATABASE_PASSWORD - Database password credential
+ */
 interface Env {
   DATABASE_HOST: string;
   DATABASE_USERNAME: string;
   DATABASE_PASSWORD: string;
 }

Consider adding runtime validation for these environment variables to ensure they're properly set before attempting database connection.


13-13: Consider using a more robust initialization pattern

The global mutable app variable could potentially lead to race conditions in a concurrent environment. Consider using a singleton pattern or initialization guard to ensure thread-safe initialization.


22-24: Document the cache override behavior

The cache is explicitly disabled in the fetch options. Add a comment explaining why this is necessary to prevent future modifications that might reintroduce caching.

       fetch: (opts, init) =>
+        // Disable caching to ensure fresh database queries
         fetch(new Request(opts, { ...init, cache: undefined })),
packages/authhero/package.json (2)

42-44: Consider documenting peer dependencies requirements

Moving Hono and OpenAPI packages to peerDependencies is a good architectural decision as it allows consumers to manage their own versions. However, this change might be breaking for existing consumers.

Consider adding installation instructions in the README to guide users about required peer dependencies.


Line range hint 1-44: Consider package stability and documentation

Given that this package is being used in a demo project exposing a management API:

  1. The rapid version changes (0.9.0 -> 0.10.1) and incomplete status suggest the API might not be stable yet. Consider using a 0.x.x version to indicate API instability.
  2. With the addition of OpenAPI support, ensure comprehensive API documentation is generated and included in the package.
apps/demo/CHANGELOG.md (1)

12-22: Consider adding more details about the demo project rendering feature.

The entry "Get the demo project rendering" could benefit from more specific details about what was implemented, particularly regarding the Swagger file rendering mentioned in the PR description.

Example of more detailed entry:

- Get the demo project rendering
+ Add demo project with Swagger UI rendering for management API
packages/drizzle/CHANGELOG.md (1)

3-10: Consider adding more details about the IIFE removal

The changelog entry for removing IIFE build files could benefit from additional context:

  • Why were they removed?
  • What build formats are now supported?
  • Are there any migration steps for consumers?
apps/demo/src/app.ts (2)

37-39: Consider making the issuer configurable

Currently, the issuer is hardcoded to "https://authhero.com". If this value needs to vary between environments or deployments, consider passing it as a parameter or using an environment variable.


42-47: Externalize OpenAPI metadata for easier maintenance

The OpenAPI documentation metadata, such as version and title, are hardcoded within the code. To improve maintainability and ensure consistency, consider sourcing these values from package.json or a centralized configuration file.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0540c12 and a000563.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (23)
  • apps/demo/CHANGELOG.md (1 hunks)
  • apps/demo/package.json (1 hunks)
  • apps/demo/src/app.ts (2 hunks)
  • apps/demo/src/bun.ts (1 hunks)
  • apps/demo/src/server.ts (1 hunks)
  • apps/demo/src/types/Bindings.ts (1 hunks)
  • apps/demo/wrangler.toml (1 hunks)
  • packages/adapter-interfaces/CHANGELOG.md (1 hunks)
  • packages/adapter-interfaces/package.json (2 hunks)
  • packages/adapter-interfaces/vite.config.ts (0 hunks)
  • packages/authhero/CHANGELOG.md (1 hunks)
  • packages/authhero/package.json (2 hunks)
  • packages/authhero/vite.config.ts (0 hunks)
  • packages/drizzle/CHANGELOG.md (1 hunks)
  • packages/drizzle/package.json (1 hunks)
  • packages/drizzle/vite.config.ts (0 hunks)
  • packages/kysely/CHANGELOG.md (1 hunks)
  • packages/kysely/package.json (2 hunks)
  • packages/kysely/src/migrate/migrations/2024-11-18T10:37:00_act_as.ts (1 hunks)
  • packages/kysely/src/migrate/migrations/index.ts (2 hunks)
  • packages/kysely/vite.config.ts (0 hunks)
  • packages/saml/CHANGELOG.md (1 hunks)
  • packages/saml/package.json (1 hunks)
💤 Files with no reviewable changes (4)
  • packages/adapter-interfaces/vite.config.ts
  • packages/authhero/vite.config.ts
  • packages/drizzle/vite.config.ts
  • packages/kysely/vite.config.ts
✅ Files skipped from review due to trivial changes (6)
  • apps/demo/wrangler.toml
  • packages/adapter-interfaces/CHANGELOG.md
  • packages/drizzle/package.json
  • packages/kysely/CHANGELOG.md
  • packages/saml/CHANGELOG.md
  • packages/saml/package.json
🔇 Additional comments (16)
apps/demo/package.json (2)

4-4: Verify the version bump rationale

The version jump from 0.0.36 to 0.1.1 suggests significant changes. Please ensure this aligns with semantic versioning principles given the new features (Swagger UI integration) and incomplete project status mentioned in the PR description.


9-15: Review dependency versions for security and stability

The new dependencies introduce several packages that warrant attention:

  1. Early stage packages (e.g., @hono/[email protected]) might have stability concerns
  2. Using caret (^) for all versions could lead to unexpected breaking changes

Please:

  • Verify these versions against known vulnerabilities
  • Consider pinning versions for critical dependencies
  • Evaluate the stability of early-stage packages in a production context
apps/demo/src/bun.ts (1)

18-18: LGTM! Simplified app initialization.

The direct assignment approach is cleaner and aligns well with the updated app.ts implementation.

apps/demo/src/server.ts (1)

4-5: Verify type definitions for imported functions

Ensure that createApp and createAdapters have proper TypeScript type definitions to maintain type safety throughout the application.

packages/adapter-interfaces/package.json (2)

14-14: Verify version increment from 0.21.0 to 0.22.1

The version has been updated from 0.21.0 to 0.22.1. Please ensure this increment follows semantic versioning principles and is documented in the changelog, particularly since this package is public and used as a dependency by other packages in the ecosystem.


35-35: LGTM: Dependency updates look appropriate

The updates to @types/node and vite versions appear to be minor version increments, which is appropriate for receiving bug fixes and compatible changes.

Also applies to: 38-38

packages/authhero/package.json (1)

3-3: Verify version bump from 0.9.0 to 0.10.1

The version jump from 0.9.0 to 0.10.1 suggests significant changes. Ensure the changelog is updated to reflect all breaking changes and new features.

packages/kysely/package.json (3)

47-48: Review architectural change in dependency management

kysely and nanoid have been moved from peerDependencies to dependencies. This change:

  • Makes these dependencies bundled with your package instead of being provided by the consuming application
  • Could lead to potential version conflicts if the consuming application also uses these packages
  • Increases the package size

Please verify if this architectural change is intentional and aligns with the package's design goals.

Also applies to: 50-54


33-33: OpenAPI-related changes align with PR objectives

The addition of @hono/zod-openapi, hono, and database adapters aligns well with the PR's objective of rendering Swagger documentation. However, ensure that all these dependencies are necessary as they increase the package size.

Also applies to: 37-39


33-33: ⚠️ Potential issue

Version mismatch between devDependencies and peerDependencies

The @hono/zod-openapi package has different versions:

  • devDependencies: ^0.18.0
  • peerDependencies: ^0.16.4

This version mismatch could lead to compatibility issues. Consider aligning these versions.

Also applies to: 51-51

apps/demo/CHANGELOG.md (1)

3-10: LGTM! Well-structured changelog entry.

The changelog follows proper semantic versioning and conventional commits format, clearly documenting the removal of IIFE build files and dependency updates.

packages/authhero/CHANGELOG.md (2)

3-10: LGTM! Clear patch version documentation.

The changelog entry for version 0.10.1 properly documents the removal of IIFE build files and dependency updates following the conventional changelog format.


11-20: LGTM! Version aligns with PR objectives.

The changelog entry for version 0.10.0 correctly documents the demo project rendering feature, which aligns with the PR objectives. The dependency update is also properly documented.

packages/drizzle/CHANGELOG.md (1)

7-7: Verify the impact of removing IIFE build files

The removal of IIFE build files could potentially break consumers who depend on these files. Please ensure that:

  1. This change has been communicated to package consumers
  2. Alternative build formats are available for all use cases
  3. Migration instructions are provided if needed
packages/kysely/src/migrate/migrations/index.ts (2)

64-64: LGTM! Import follows established patterns.

The new migration import follows the existing naming convention and maintains chronological order with respect to previous migrations.


131-131: LGTM! Export maintains alphabetical ordering.

The new migration export is correctly placed in alphabetical order within the default export object.

Comment on lines +15 to +33
const server = {
async fetch(request: Request, env: Env): Promise<Response> {
if (!app) {
const dialect = new PlanetScaleDialect({
host: env.DATABASE_HOST,
username: env.DATABASE_USERNAME,
password: env.DATABASE_PASSWORD,
fetch: (opts, init) =>
fetch(new Request(opts, { ...init, cache: undefined })),
});
const db = new Kysely<any>({ dialect });
const dataAdapter = createAdapters(db);

app = createApp(dataAdapter);
}

return app.fetch(request);
},
};
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling and improve type safety

Several critical improvements are needed in the server implementation:

  1. Replace any with proper database schema type
  2. Add error handling for database connection
  3. Consider connection pooling
  4. Implement proper cleanup
-      const db = new Kysely<any>({ dialect });
+      const db = new Kysely<DatabaseSchema>({ dialect });
       const dataAdapter = createAdapters(db);
 
+      try {
         app = createApp(dataAdapter);
+      } catch (error) {
+        console.error('Failed to initialize app:', error);
+        return new Response('Internal Server Error', { status: 500 });
+      }

Consider implementing:

  1. Connection pooling for better performance
  2. Retry logic for transient database connection issues
  3. Proper resource cleanup on server shutdown

Committable suggestion skipped: line range outside the PR's diff.

packages/adapter-interfaces/package.json Show resolved Hide resolved
packages/authhero/package.json Show resolved Hide resolved
apps/demo/src/app.ts Show resolved Hide resolved
@markusahlstrand markusahlstrand merged commit b5c5ce8 into main Nov 20, 2024
2 of 3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 15, 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.

1 participant