-
Notifications
You must be signed in to change notification settings - Fork 406
chore(clerk-js,shared): Support granular API keys settings #7179
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
Conversation
🦋 Changeset detectedLatest commit: f07c6d5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThis PR implements granular API keys settings by replacing the single Changes
Sequence DiagramsequenceDiagram
participant Component as UserProfile/OrganizationProfile
participant Context as ProfileContext
participant APIKeysRoutes as APIKeysRoutes
participant Navbar as ProfileNavbar
Component->>Context: Consume apiKeysProps & apiKeysSettings
Component->>APIKeysRoutes: Render with settings/props
alt Render API Keys Route
APIKeysRoutes->>APIKeysRoutes: Check flag + !hide
rect rgb(200, 220, 255)
Note over APIKeysRoutes: user_api_keys_enabled<br/>or orgs_api_keys_enabled
end
APIKeysRoutes->>Component: Render route
else Hide API Keys
rect rgb(255, 220, 220)
Note over APIKeysRoutes: Flag false or hide=true
end
APIKeysRoutes->>Component: Skip route
end
Component->>Navbar: Render navbar with filtered routes
Navbar->>Navbar: Filter routes if hide=true
Navbar->>Component: Render navigation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (7)
packages/clerk-js/src/core/clerk.ts(2 hunks)packages/clerk-js/src/core/resources/APIKeySettings.ts(2 hunks)packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsx(1 hunks)packages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsx(1 hunks)packages/clerk-js/src/ui/utils/createCustomPages.tsx(2 hunks)packages/clerk-js/src/utils/componentGuards.ts(1 hunks)packages/shared/src/types/apiKeysSettings.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
packages/clerk-js/src/ui/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/clerk-js-ui.mdc)
packages/clerk-js/src/ui/**/*.{ts,tsx}: Element descriptors should always be camelCase
Use element descriptors in UI components to enable consistent theming and styling via appearance.elements
Element descriptors should generate unique, stable CSS classes for theming
Element descriptors should handle state classes (e.g., cl-loading, cl-active, cl-error, cl-open) automatically based on component state
Do not render hard-coded values; all user-facing strings must be localized using provided localization methods
Use the useLocalizations hook and localizationKeys utility for all text and error messages
Use the styled system (sx prop, theme tokens, responsive values) for custom component styling
Use useCardState for card-level state, useFormState for form-level state, and useLoadingStatus for loading states
Always use handleError utility for API errors and use translateError for localized error messages
Use useFormControl for form field state, implement proper validation, and handle loading and error states in forms
Use localization keys for all form labels and placeholders
Use element descriptors for consistent styling and follow the theme token system
Use the Card and FormContainer patterns for consistent UI structure
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsxpackages/clerk-js/src/ui/utils/createCustomPages.tsx
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/shared/src/types/apiKeysSettings.tspackages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsxpackages/clerk-js/src/core/resources/APIKeySettings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/shared/src/types/apiKeysSettings.tspackages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsxpackages/clerk-js/src/core/resources/APIKeySettings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/shared/src/types/apiKeysSettings.tspackages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsxpackages/clerk-js/src/core/resources/APIKeySettings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/shared/src/types/apiKeysSettings.tspackages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsxpackages/clerk-js/src/core/resources/APIKeySettings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/shared/src/types/apiKeysSettings.tspackages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsxpackages/clerk-js/src/core/resources/APIKeySettings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.ts
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{jsx,tsx}: Use error boundaries in React components
Minimize re-renders in React components
**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components:UserProfile,NavigationMenu
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsxpackages/clerk-js/src/ui/utils/createCustomPages.tsx
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/shared/src/types/apiKeysSettings.tspackages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsxpackages/clerk-js/src/core/resources/APIKeySettings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.ts
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.tsx: Use proper type definitions for props and state
Leverage TypeScript's type inference where possible
Use proper event types for handlers
Implement proper generic types for reusable components
Use proper type guards for conditional rendering
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsxpackages/clerk-js/src/ui/utils/createCustomPages.tsx
🧬 Code graph analysis (3)
packages/clerk-js/src/core/resources/APIKeySettings.ts (2)
packages/shared/src/types/apiKeysSettings.ts (1)
APIKeysSettingsJSON(5-11)packages/shared/src/types/snapshots.ts (1)
APIKeysSettingsJSONSnapshot(192-192)
packages/clerk-js/src/core/clerk.ts (1)
packages/clerk-js/src/utils/componentGuards.ts (2)
disabledOrganizationAPIKeysStandaloneFeature(59-61)disabledUserAPIKeysStandaloneFeature(52-54)
packages/clerk-js/src/ui/utils/createCustomPages.tsx (2)
packages/react/src/isomorphicClerk.ts (1)
organization(711-717)packages/clerk-js/src/utils/componentGuards.ts (2)
disabledOrganizationAPIKeysFeature(45-47)disabledUserAPIKeysFeature(41-43)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
packages/clerk-js/src/utils/componentGuards.ts (1)
49-61: LGTM! Well-documented standalone guards.The standalone guards correctly check only the enablement flags without considering profile visibility, which is appropriate for standalone
<APIKeys />component usage. The JSDoc comments clearly explain the distinction from the profile-context guards.The separation between profile guards (checking both enablement and visibility) and standalone guards (checking only enablement) provides the right level of granular control for different usage contexts.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/clerk-js/src/core/clerk.ts (1)
1238-1263: Don't block org API keys when only user keys are disabled.With the new per-scope flags, it should be possible to disable user API keys while keeping organization API keys active. In org context (
this.organizationtruthy) we still hitdisabledUserAPIKeysFeature, so we short-circuit with the user-disabled error. The standalone<APIKeys/>can never mount for orgs when user keys are off, which breaks the main objective of this PR. Please gate the user-only check behind a!this.organizationcondition (or otherwise branch by context) so org flows keep working.- if (disabledUserAPIKeysFeature(this, this.environment)) { + if (!this.organization && disabledUserAPIKeysFeature(this, this.environment)) { if (this.#instanceType === 'development') { throw new ClerkRuntimeError(warnings.cannotRenderAPIKeysComponentForUserWhenDisabled, { code: CANNOT_RENDER_API_KEYS_USER_DISABLED_ERROR_CODE, }); } return; }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (6)
.changeset/serious-mugs-flash.md(1 hunks)integration/tests/machine-auth/component.test.ts(2 hunks)packages/clerk-js/src/core/clerk.ts(4 hunks)packages/clerk-js/src/core/warnings.ts(1 hunks)packages/clerk-js/src/ui/utils/createCustomPages.tsx(2 hunks)packages/clerk-js/src/utils/componentGuards.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (13)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/clerk-js/src/core/warnings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.tsintegration/tests/machine-auth/component.test.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/clerk-js/src/core/warnings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.tsintegration/tests/machine-auth/component.test.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/core/warnings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/clerk-js/src/core/warnings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/clerk-js/src/core/warnings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.tsintegration/tests/machine-auth/component.test.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/clerk-js/src/core/warnings.tspackages/clerk-js/src/core/clerk.tspackages/clerk-js/src/ui/utils/createCustomPages.tsxpackages/clerk-js/src/utils/componentGuards.tsintegration/tests/machine-auth/component.test.ts
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/serious-mugs-flash.md
packages/clerk-js/src/ui/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/clerk-js-ui.mdc)
packages/clerk-js/src/ui/**/*.{ts,tsx}: Element descriptors should always be camelCase
Use element descriptors in UI components to enable consistent theming and styling via appearance.elements
Element descriptors should generate unique, stable CSS classes for theming
Element descriptors should handle state classes (e.g., cl-loading, cl-active, cl-error, cl-open) automatically based on component state
Do not render hard-coded values; all user-facing strings must be localized using provided localization methods
Use the useLocalizations hook and localizationKeys utility for all text and error messages
Use the styled system (sx prop, theme tokens, responsive values) for custom component styling
Use useCardState for card-level state, useFormState for form-level state, and useLoadingStatus for loading states
Always use handleError utility for API errors and use translateError for localized error messages
Use useFormControl for form field state, implement proper validation, and handle loading and error states in forms
Use localization keys for all form labels and placeholders
Use element descriptors for consistent styling and follow the theme token system
Use the Card and FormContainer patterns for consistent UI structure
Files:
packages/clerk-js/src/ui/utils/createCustomPages.tsx
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{jsx,tsx}: Use error boundaries in React components
Minimize re-renders in React components
**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components:UserProfile,NavigationMenu
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...
Files:
packages/clerk-js/src/ui/utils/createCustomPages.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.tsx: Use proper type definitions for props and state
Leverage TypeScript's type inference where possible
Use proper event types for handlers
Implement proper generic types for reusable components
Use proper type guards for conditional rendering
Files:
packages/clerk-js/src/ui/utils/createCustomPages.tsx
integration/**
📄 CodeRabbit inference engine (.cursor/rules/global.mdc)
Framework integration templates and E2E tests should be placed under the integration/ directory
Files:
integration/tests/machine-auth/component.test.ts
integration/**/*
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
End-to-end tests and integration templates must be located in the 'integration/' directory.
Files:
integration/tests/machine-auth/component.test.ts
integration/**/*.{test,spec}.{js,ts}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Integration tests should use Playwright.
Files:
integration/tests/machine-auth/component.test.ts
🧬 Code graph analysis (3)
packages/clerk-js/src/core/clerk.ts (1)
packages/clerk-js/src/utils/componentGuards.ts (3)
disabledAllAPIKeysFeatures(45-47)disabledOrganizationAPIKeysFeature(41-43)disabledUserAPIKeysFeature(37-39)
packages/clerk-js/src/ui/utils/createCustomPages.tsx (2)
packages/react/src/isomorphicClerk.ts (1)
organization(711-717)packages/clerk-js/src/utils/componentGuards.ts (2)
disabledOrganizationProfileAPIKeysFeature(53-55)disabledUserProfileAPIKeysFeature(49-51)
integration/tests/machine-auth/component.test.ts (2)
integration/templates/next-app-router/src/app/api-keys/page.tsx (1)
Page(3-5)integration/testUtils/index.ts (1)
createTestUtils(24-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (25)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (custom, chrome)
- GitHub Check: Integration Tests (quickstart, chrome, 16)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (nextjs, chrome, 16)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (quickstart, chrome, 15)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (handshake:staging, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (sessions:staging, chrome)
- GitHub Check: Integration Tests (handshake, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Static analysis
- GitHub Check: Unit Tests (22, **)
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/clerk-js/src/core/resources/__tests__/Environment.test.ts (1)
10-14: Update test expectations to match the new API shape.This test still expects the old
enabledfield, which is inconsistent with the refactoring to four granular fields (user_api_keys_enabled,show_in_user_profile,orgs_api_keys_enabled,show_in_org_profile) shown elsewhere in this file (lines 56-59, 584-587).Apply this diff to align with the new API shape:
expect(environment).toMatchObject({ apiKeysSettings: expect.objectContaining({ - enabled: false, + orgsApiKeysEnabled: false, + showInOrgProfile: false, + showInUserProfile: false, + userApiKeysEnabled: false, pathRoot: '', }), authConfig: expect.objectContaining({
🧹 Nitpick comments (3)
integration/tests/machine-auth/component.test.ts (3)
8-32: Consider adding error handling to the mock helper.The
mockAPIKeysEnvironmentSettingsfunction doesn't handle potential failures inroute.fetch()orresponse.json(). If the API call fails or returns unexpected data, tests will fail with unclear error messages.Consider wrapping the route handler in a try-catch:
const mockAPIKeysEnvironmentSettings = async ( page: Page, overrides: Partial<{ user_api_keys_enabled: boolean; show_in_user_profile: boolean; orgs_api_keys_enabled: boolean; show_in_org_profile: boolean; }>, ) => { await page.route('*/**/v1/environment*', async route => { + try { const response = await route.fetch(); const json = await response.json(); const newJson = { ...json, api_keys_settings: { user_api_keys_enabled: true, show_in_user_profile: true, orgs_api_keys_enabled: true, show_in_org_profile: true, ...overrides, }, }; await route.fulfill({ response, json: newJson }); + } catch (error) { + console.error('Failed to mock API keys environment settings:', error); + await route.continue(); + } }); };
274-299: Add explicit wait after navigating to organization profile.The test navigates to
/organization-profile(line 284) and immediately navigates to the hash route without waiting for the profile to mount. This could cause race conditions if the profile component hasn't fully initialized.Add a wait after the initial navigation:
// orgs_api_keys_enabled: false should hide API keys page await mockAPIKeysEnvironmentSettings(u.page, { orgs_api_keys_enabled: false }); await u.po.page.goToRelative('/organization-profile'); + await u.po.organizationProfile.waitForMounted(); await u.po.page.goToRelative('/organization-profile#/organization-api-keys'); await expect(u.page.locator('.cl-apiKeys')).toBeHidden({ timeout: 2000 });Apply the same pattern to the other scenarios in this test as well.
301-328: Clean up the request listener after the test.The request listener attached at line 313 is never removed, which could cause it to fire during subsequent tests if they share the same page context, potentially leading to flaky test results or false positives.
Store the listener function and remove it after use:
// user_api_keys_enabled: false should prevent standalone component from rendering await mockAPIKeysEnvironmentSettings(u.page, { user_api_keys_enabled: false }); let apiKeysRequestWasMade = false; - u.page.on('request', request => { + const requestListener = (request) => { if (request.url().includes('/api_keys')) { apiKeysRequestWasMade = true; } - }); + }; + u.page.on('request', requestListener); await u.po.page.goToRelative('/api-keys'); await expect(u.page.locator('.cl-apiKeys-root')).toBeHidden({ timeout: 1000 }); expect(apiKeysRequestWasMade).toBe(false); + u.page.off('request', requestListener); // user_api_keys_enabled: true should allow standalone component to render await mockAPIKeysEnvironmentSettings(u.page, { user_api_keys_enabled: true }); await page.reload(); await u.po.apiKeys.waitForMounted(); await expect(u.page.locator('.cl-apiKeys-root')).toBeVisible();
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
integration/tests/machine-auth/component.test.ts(2 hunks)packages/clerk-js/src/core/resources/__tests__/Environment.test.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (12)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/clerk-js/src/core/resources/__tests__/Environment.test.tsintegration/tests/machine-auth/component.test.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/clerk-js/src/core/resources/__tests__/Environment.test.tsintegration/tests/machine-auth/component.test.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/core/resources/__tests__/Environment.test.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/clerk-js/src/core/resources/__tests__/Environment.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/clerk-js/src/core/resources/__tests__/Environment.test.tsintegration/tests/machine-auth/component.test.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Unit tests should use Jest or Vitest as the test runner.
Files:
packages/clerk-js/src/core/resources/__tests__/Environment.test.ts
packages/{clerk-js,elements,themes}/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Visual regression testing should be performed for UI components.
Files:
packages/clerk-js/src/core/resources/__tests__/Environment.test.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/clerk-js/src/core/resources/__tests__/Environment.test.tsintegration/tests/machine-auth/component.test.ts
**/__tests__/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/__tests__/**/*.{ts,tsx}: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces
Files:
packages/clerk-js/src/core/resources/__tests__/Environment.test.ts
integration/**
📄 CodeRabbit inference engine (.cursor/rules/global.mdc)
Framework integration templates and E2E tests should be placed under the integration/ directory
Files:
integration/tests/machine-auth/component.test.ts
integration/**/*
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
End-to-end tests and integration templates must be located in the 'integration/' directory.
Files:
integration/tests/machine-auth/component.test.ts
integration/**/*.{test,spec}.{js,ts}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Integration tests should use Playwright.
Files:
integration/tests/machine-auth/component.test.ts
🧬 Code graph analysis (1)
integration/tests/machine-auth/component.test.ts (2)
integration/templates/next-app-router/src/app/api-keys/page.tsx (1)
Page(3-5)integration/testUtils/index.ts (1)
createTestUtils(24-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 16)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (quickstart, chrome, 16)
- GitHub Check: Integration Tests (custom, chrome)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (quickstart, chrome, 15)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (sessions:staging, chrome)
- GitHub Check: Integration Tests (handshake:staging, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (handshake, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Static analysis
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (3)
packages/clerk-js/src/core/resources/__tests__/Environment.test.ts (2)
56-59: LGTM! Correctly implements the new API shape.The test input now properly uses the four granular API keys settings fields.
584-587: LGTM! Snapshot expectations correctly reflect the new API shape.The
__internal_toSnapshot()test now properly expects the four granular API keys settings fields.integration/tests/machine-auth/component.test.ts (1)
244-272: LGTM! Well-structured visibility test.The test correctly validates UserProfile API keys page visibility based on both
user_api_keys_enabledandshow_in_user_profileflags, covering all three scenarios: disabled enabled flag, disabled visibility flag, and both enabled.
There was a problem hiding this 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
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (11)
integration/tests/machine-auth/component.test.ts(2 hunks)packages/clerk-js/src/core/resources/APIKeySettings.ts(2 hunks)packages/clerk-js/src/core/resources/__tests__/Environment.test.ts(3 hunks)packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsx(2 hunks)packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx(1 hunks)packages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsx(2 hunks)packages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsx(1 hunks)packages/clerk-js/src/ui/utils/createCustomPages.tsx(2 hunks)packages/clerk-js/src/utils/componentGuards.ts(1 hunks)packages/shared/src/types/apiKeysSettings.ts(1 hunks)packages/shared/src/types/clerk.ts(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/shared/src/types/apiKeysSettings.ts
- packages/clerk-js/src/ui/components/UserProfile/UserProfileRoutes.tsx
- packages/clerk-js/src/ui/utils/createCustomPages.tsx
🧰 Additional context used
📓 Path-based instructions (11)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
integration/tests/machine-auth/component.test.tspackages/shared/src/types/clerk.tspackages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsxpackages/clerk-js/src/utils/componentGuards.tspackages/clerk-js/src/core/resources/__tests__/Environment.test.tspackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsxpackages/clerk-js/src/core/resources/APIKeySettings.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
integration/tests/machine-auth/component.test.tspackages/shared/src/types/clerk.tspackages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsxpackages/clerk-js/src/utils/componentGuards.tspackages/clerk-js/src/core/resources/__tests__/Environment.test.tspackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsxpackages/clerk-js/src/core/resources/APIKeySettings.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
integration/tests/machine-auth/component.test.tspackages/shared/src/types/clerk.tspackages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsxpackages/clerk-js/src/utils/componentGuards.tspackages/clerk-js/src/core/resources/__tests__/Environment.test.tspackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsxpackages/clerk-js/src/core/resources/APIKeySettings.ts
integration/**
📄 CodeRabbit inference engine (.cursor/rules/global.mdc)
Framework integration templates and E2E tests should be placed under the integration/ directory
Files:
integration/tests/machine-auth/component.test.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/shared/src/types/clerk.tspackages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsxpackages/clerk-js/src/utils/componentGuards.tspackages/clerk-js/src/core/resources/__tests__/Environment.test.tspackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsxpackages/clerk-js/src/core/resources/APIKeySettings.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/shared/src/types/clerk.tspackages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsxpackages/clerk-js/src/utils/componentGuards.tspackages/clerk-js/src/core/resources/__tests__/Environment.test.tspackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsxpackages/clerk-js/src/core/resources/APIKeySettings.ts
packages/clerk-js/src/ui/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/clerk-js-ui.mdc)
packages/clerk-js/src/ui/**/*.{ts,tsx}: Element descriptors should always be camelCase
Use element descriptors in UI components to enable consistent theming and styling via appearance.elements
Element descriptors should generate unique, stable CSS classes for theming
Element descriptors should handle state classes (e.g., cl-loading, cl-active, cl-error, cl-open) automatically based on component state
Do not render hard-coded values; all user-facing strings must be localized using provided localization methods
Use the useLocalizations hook and localizationKeys utility for all text and error messages
Use the styled system (sx prop, theme tokens, responsive values) for custom component styling
Use useCardState for card-level state, useFormState for form-level state, and useLoadingStatus for loading states
Always use handleError utility for API errors and use translateError for localized error messages
Use useFormControl for form field state, implement proper validation, and handle loading and error states in forms
Use localization keys for all form labels and placeholders
Use element descriptors for consistent styling and follow the theme token system
Use the Card and FormContainer patterns for consistent UI structure
Files:
packages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{jsx,tsx}: Use error boundaries in React components
Minimize re-renders in React components
**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components:UserProfile,NavigationMenu
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...
Files:
packages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.tsx: Use proper type definitions for props and state
Leverage TypeScript's type inference where possible
Use proper event types for handlers
Implement proper generic types for reusable components
Use proper type guards for conditional rendering
Files:
packages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
**/*.test.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.test.{jsx,tsx}: Use React Testing Library
Test component behavior, not implementation
Use proper test queries
Implement proper test isolation
Use proper test coverage
Test component interactions
Use proper test data
Implement proper test setup
Use proper test cleanup
Implement proper test assertions
Use proper test structure
Files:
packages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
**/__tests__/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/__tests__/**/*.{ts,tsx}: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces
Files:
packages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsxpackages/clerk-js/src/core/resources/__tests__/Environment.test.tspackages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx
🧬 Code graph analysis (4)
integration/tests/machine-auth/component.test.ts (1)
integration/testUtils/index.ts (1)
createTestUtils(24-86)
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsx (1)
packages/clerk-js/src/ui/contexts/components/OrganizationProfile.ts (1)
useOrganizationProfileContext(33-86)
packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx (1)
packages/clerk-js/src/ui/components/OrganizationProfile/index.tsx (1)
OrganizationProfile(58-58)
packages/clerk-js/src/core/resources/APIKeySettings.ts (2)
packages/shared/src/types/apiKeysSettings.ts (1)
APIKeysSettingsJSON(5-8)packages/shared/src/types/snapshots.ts (1)
APIKeysSettingsJSONSnapshot(192-192)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (9)
packages/clerk-js/src/core/resources/__tests__/Environment.test.ts (1)
12-13: LGTM! Test data correctly updated for new API keys settings structure.The test fixtures and expectations have been updated to use the new granular
orgs_api_keys_enabledanduser_api_keys_enabledfields instead of the singleenabledflag. The changes are consistent across all test cases.Also applies to: 57-58, 583-584
packages/clerk-js/src/ui/components/UserProfile/__tests__/UserProfile.test.tsx (1)
245-294: LGTM! Comprehensive test coverage for API Keys visibility.The new test suite properly validates all combinations of the
user_api_keys_enabledenvironment flag and thehideprop:
- Environment flag disabled: hides API keys regardless of hide prop
- Environment flag enabled + hide=false: shows API keys
- Environment flag enabled + hide not set: shows API keys (default behavior)
- hide=true: hides API keys regardless of environment flag
packages/shared/src/types/clerk.ts (1)
1567-1574: LGTM! Type definitions correctly extended with hide flag.The
apiKeysPropstype has been properly extended for bothUserProfilePropsandOrganizationProfilePropswith an optionalhideflag. The JSDoc documentation clearly explains the flag's purpose and default behavior.Also applies to: 1610-1617
packages/clerk-js/src/ui/components/OrganizationProfile/__tests__/OrganizationProfile.test.tsx (1)
382-465: LGTM! Comprehensive test coverage for organization API Keys visibility.The new test suite validates all combinations of the
orgs_api_keys_enabledenvironment flag and thehideprop, parallel to the UserProfile tests. The tests correctly:
- Set up users with the required
org:sys_api_keys:readpermission- Test environment flag + hide prop interactions
- Verify UI rendering behavior with appropriate assertions
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileRoutes.tsx (1)
41-49: LGTM! Routing logic correctly updated for granular API keys control.The changes properly implement the new visibility logic:
- Line 48: Extracts
apiKeysPropsfrom context- Line 127: Updates the rendering condition to check both
orgs_api_keys_enabled(environment flag) and!apiKeysProps?.hide(component prop)The implementation correctly uses optional chaining to handle undefined
apiKeysPropsand maintains the existing permission checks.Also applies to: 127-143
packages/clerk-js/src/core/resources/APIKeySettings.ts (1)
9-10: LGTM! API key settings correctly refactored to granular flags.The implementation properly replaces the single
enabledflag with separateuser_api_keys_enabledandorgs_api_keys_enabledfields. The changes are consistent across:
- Field declarations (lines 9-10) with appropriate default values
- JSON deserialization (lines 23-24)
- Snapshot serialization (lines 31-32)
Also applies to: 23-24, 31-32
integration/tests/machine-auth/component.test.ts (2)
8-28: LGTM! Well-designed environment mocking helper.The
mockAPIKeysEnvironmentSettingshelper provides a clean way to override API keys settings for testing. It properly:
- Intercepts environment API calls
- Preserves existing response data
- Merges in test-specific overrides
- Uses proper async/await patterns
240-282: LGTM! Comprehensive visibility tests for profile components.The tests properly validate that:
- UserProfile respects
user_api_keys_enabledflag- OrganizationProfile respects
orgs_api_keys_enabledflag- Page reloads correctly apply new environment settings
- UI visibility changes match expected behavior
packages/clerk-js/src/utils/componentGuards.ts (1)
37-47: LGTM! Component guards correctly refactored for granular control.The implementation properly replaces the single API keys guard with three specialized guards:
disabledUserAPIKeysFeature: Checksuser_api_keys_enableddisabledOrganizationAPIKeysFeature: Checksorgs_api_keys_enableddisabledAllAPIKeysFeatures: Combines both checksThe guards follow the established pattern and correctly use optional chaining to handle potentially undefined environment settings.
Based on learnings.
There was a problem hiding this 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx (1)
16-16: Consolidate the duplicate hook call.
useOrganizationProfileContext()is called twice (lines 16 and 32) to destructure different properties. This is inefficient and should be consolidated into a single call.Apply this diff to combine the destructuring:
- const { pages } = useOrganizationProfileContext(); + const { pages, apiKeysProps } = useOrganizationProfileContext(); const allowMembersRoute = useProtect( has => has({ permission: 'org:sys_memberships:read', }) || has({ permission: 'org:sys_memberships:manage' }), ); const allowBillingRoutes = useProtect( has => has({ permission: 'org:sys_billing:read', }) || has({ permission: 'org:sys_billing:manage' }), ); - const { apiKeysProps } = useOrganizationProfileContext(); - const routes = pages.routesAlso applies to: 32-33
🧹 Nitpick comments (3)
packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsx (2)
5-5: Consider extracting the API Keys route filtering logic to reduce duplication.The filtering pattern
r.id !== USER_PROFILE_NAVBAR_ROUTE_ID.API_KEYS || !apiKeysProps?.hideis duplicated inOrganizationProfileNavbar.tsx(line 45). Extracting this to a shared utility function would improve maintainability and ensure consistent behavior across both components.Example implementation in a shared utilities file:
// utils/routeFilters.ts export const filterApiKeysRoute = <T extends { id: string }>( routes: T[], apiKeysRouteId: string, shouldHide: boolean | undefined ): T[] => { return routes.filter(r => r.id !== apiKeysRouteId || !shouldHide); };Then use it in both navbar components:
-const routes = pages.routes.filter(r => r.id !== USER_PROFILE_NAVBAR_ROUTE_ID.API_KEYS || !apiKeysProps?.hide); +const routes = filterApiKeysRoute(pages.routes, USER_PROFILE_NAVBAR_ROUTE_ID.API_KEYS, apiKeysProps?.hide);Also applies to: 13-15, 22-22
15-15: Consider clarifying the filter predicate for readability.The condition
r.id !== USER_PROFILE_NAVBAR_ROUTE_ID.API_KEYS || !apiKeysProps?.hideuses double negation which requires careful parsing. A comment explaining the logic would improve readability.+// Keep all non-API-Keys routes, and keep API-Keys route only when not explicitly hidden const routes = pages.routes.filter(r => r.id !== USER_PROFILE_NAVBAR_ROUTE_ID.API_KEYS || !apiKeysProps?.hide);packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx (1)
34-45: Consider refactoring the filter chain for improved readability.The three chained
.filter()calls are becoming verbose. While functionally correct, extracting the filter predicates into named functions or using intermediate variables could improve readability and maintainability.Example approach:
const shouldShowMembersRoute = (r: NavbarRoute) => r.id !== ORGANIZATION_PROFILE_NAVBAR_ROUTE_ID.MEMBERS || allowMembersRoute; const shouldShowBillingRoute = (r: NavbarRoute) => r.id !== ORGANIZATION_PROFILE_NAVBAR_ROUTE_ID.BILLING || allowBillingRoutes; const shouldShowApiKeysRoute = (r: NavbarRoute) => r.id !== ORGANIZATION_PROFILE_NAVBAR_ROUTE_ID.API_KEYS || !apiKeysProps?.hide; const routes = pages.routes .filter(shouldShowMembersRoute) .filter(shouldShowBillingRoute) .filter(shouldShowApiKeysRoute);
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx(2 hunks)packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsx(1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
packages/clerk-js/src/ui/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/clerk-js-ui.mdc)
packages/clerk-js/src/ui/**/*.{ts,tsx}: Element descriptors should always be camelCase
Use element descriptors in UI components to enable consistent theming and styling via appearance.elements
Element descriptors should generate unique, stable CSS classes for theming
Element descriptors should handle state classes (e.g., cl-loading, cl-active, cl-error, cl-open) automatically based on component state
Do not render hard-coded values; all user-facing strings must be localized using provided localization methods
Use the useLocalizations hook and localizationKeys utility for all text and error messages
Use the styled system (sx prop, theme tokens, responsive values) for custom component styling
Use useCardState for card-level state, useFormState for form-level state, and useLoadingStatus for loading states
Always use handleError utility for API errors and use translateError for localized error messages
Use useFormControl for form field state, implement proper validation, and handle loading and error states in forms
Use localization keys for all form labels and placeholders
Use element descriptors for consistent styling and follow the theme token system
Use the Card and FormContainer patterns for consistent UI structure
Files:
packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{jsx,tsx}: Use error boundaries in React components
Minimize re-renders in React components
**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components:UserProfile,NavigationMenu
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...
Files:
packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.tsx: Use proper type definitions for props and state
Leverage TypeScript's type inference where possible
Use proper event types for handlers
Implement proper generic types for reusable components
Use proper type guards for conditional rendering
Files:
packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsxpackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx
🧬 Code graph analysis (2)
packages/clerk-js/src/ui/components/UserProfile/UserProfileNavbar.tsx (3)
packages/clerk-js/src/ui/elements/Navbar.tsx (1)
NavBar(53-140)packages/clerk-js/src/ui/contexts/components/UserProfile.ts (1)
useUserProfileContext(30-83)packages/clerk-js/src/ui/constants.ts (1)
USER_PROFILE_NAVBAR_ROUTE_ID(1-6)
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationProfileNavbar.tsx (2)
packages/clerk-js/src/ui/contexts/components/OrganizationProfile.ts (1)
useOrganizationProfileContext(33-86)packages/clerk-js/src/ui/constants.ts (1)
ORGANIZATION_PROFILE_NAVBAR_ROUTE_ID(8-13)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
There was a problem hiding this 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
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
integration/tests/machine-auth/component.test.ts(2 hunks)package.json(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- integration/tests/machine-auth/component.test.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
There was a problem hiding this 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
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
integration/tests/machine-auth/component.test.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
integration/tests/machine-auth/component.test.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
integration/tests/machine-auth/component.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
integration/tests/machine-auth/component.test.ts
integration/**
📄 CodeRabbit inference engine (.cursor/rules/global.mdc)
Framework integration templates and E2E tests should be placed under the integration/ directory
Files:
integration/tests/machine-auth/component.test.ts
🧬 Code graph analysis (1)
integration/tests/machine-auth/component.test.ts (2)
integration/templates/next-app-router/src/app/api-keys/page.tsx (1)
Page(3-5)integration/testUtils/index.ts (1)
createTestUtils(24-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (30)
- GitHub Check: Integration Tests (nextjs, chrome, 16)
- GitHub Check: Integration Tests (quickstart, chrome, 15)
- GitHub Check: Integration Tests (machine, chrome)
- GitHub Check: Integration Tests (quickstart, chrome, 16)
- GitHub Check: Integration Tests (custom, chrome)
- GitHub Check: Integration Tests (sessions:staging, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (handshake:staging, chrome)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (handshake, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Static analysis
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
integration/tests/machine-auth/component.test.ts (1)
318-346: Ensure the standalone org context test explicitly establishes organization context.The verification reveals a significant ambiguity: both standalone tests (lines 288–316 and 318–346) navigate to the identical
/api-keysroute, differentiated only by environment flags (user_api_keys_enabledvsorgs_api_keys_enabled). In contrast, the profile-based tests explicitly navigate to different URL paths (/user#/api-keysvs/organization-profile#/organization-api-keys), making context unambiguous.While
fakeAdminis created with organization membership intest.beforeAll(line 43), the org context test does not explicitly switch to or activate that organization context before navigating to/api-keys. Without visible context establishment (e.g., organization selection or URL path that indicates org scope), it's unclear how the standalone component determines whether to checkuser_api_keys_enabledororgs_api_keys_enabledwhen both flags are present in the environment settings.Consider adding explicit org context establishment (similar to how profile tests navigate to
/organization-profile) or clarify the mechanism by which the standalone component auto-detects and uses organization context from the current session.
| const mockAPIKeysEnvironmentSettings = async ( | ||
| page: Page, | ||
| overrides: Partial<{ | ||
| user_api_keys_enabled: boolean; | ||
| orgs_api_keys_enabled: boolean; | ||
| }>, | ||
| ) => { | ||
| await page.route('*/**/v1/environment*', async route => { | ||
| const response = await route.fetch(); | ||
| const json = await response.json(); | ||
| const newJson = { | ||
| ...json, | ||
| api_keys_settings: { | ||
| user_api_keys_enabled: true, | ||
| orgs_api_keys_enabled: true, | ||
| ...overrides, | ||
| }, | ||
| }; | ||
| await route.fulfill({ response, json: newJson }); | ||
| }); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Add explicit return type and JSDoc documentation.
Per coding guidelines, functions should have explicit return types and public/shared functions should have JSDoc documentation.
Apply this diff:
+/**
+ * Mocks the environment settings API response to override API keys settings.
+ * @param page - Playwright page instance
+ * @param overrides - Partial overrides for user_api_keys_enabled and orgs_api_keys_enabled
+ */
const mockAPIKeysEnvironmentSettings = async (
page: Page,
overrides: Partial<{
user_api_keys_enabled: boolean;
orgs_api_keys_enabled: boolean;
}>,
-) => {
+): Promise<void> => {
await page.route('*/**/v1/environment*', async route => {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const mockAPIKeysEnvironmentSettings = async ( | |
| page: Page, | |
| overrides: Partial<{ | |
| user_api_keys_enabled: boolean; | |
| orgs_api_keys_enabled: boolean; | |
| }>, | |
| ) => { | |
| await page.route('*/**/v1/environment*', async route => { | |
| const response = await route.fetch(); | |
| const json = await response.json(); | |
| const newJson = { | |
| ...json, | |
| api_keys_settings: { | |
| user_api_keys_enabled: true, | |
| orgs_api_keys_enabled: true, | |
| ...overrides, | |
| }, | |
| }; | |
| await route.fulfill({ response, json: newJson }); | |
| }); | |
| }; | |
| /** | |
| * Mocks the environment settings API response to override API keys settings. | |
| * @param page - Playwright page instance | |
| * @param overrides - Partial overrides for user_api_keys_enabled and orgs_api_keys_enabled | |
| */ | |
| const mockAPIKeysEnvironmentSettings = async ( | |
| page: Page, | |
| overrides: Partial<{ | |
| user_api_keys_enabled: boolean; | |
| orgs_api_keys_enabled: boolean; | |
| }>, | |
| ): Promise<void> => { | |
| await page.route('*/**/v1/environment*', async route => { | |
| const response = await route.fetch(); | |
| const json = await response.json(); | |
| const newJson = { | |
| ...json, | |
| api_keys_settings: { | |
| user_api_keys_enabled: true, | |
| orgs_api_keys_enabled: true, | |
| ...overrides, | |
| }, | |
| }; | |
| await route.fulfill({ response, json: newJson }); | |
| }); | |
| }; |
🤖 Prompt for AI Agents
In integration/tests/machine-auth/component.test.ts around lines 8 to 28, the
helper function mockAPIKeysEnvironmentSettings is missing an explicit return
type and JSDoc; add a concise JSDoc block above the function describing its
purpose, parameters (page: Page, overrides: Partial<{ user_api_keys_enabled:
boolean; orgs_api_keys_enabled: boolean; }>), and behavior, and update the
function signature to include an explicit return type of Promise<void>. Ensure
the JSDoc uses standard tags (@param, @returns) and the signature remains
consistent with the existing usage.
Description
This PR refactors API keys settings to support granular per-user/per-org enablement and adds component-level visibility control via props.
Changes
hideprop toapiKeysPropsinUserProfilePropsandOrganizationProfileProps:Visibility Logic
user_api_keys_enabledistrueANDapiKeysProps?.hideis nottrueorgs_api_keys_enabledistrueANDapiKeysProps?.hideis nottrue<APIKeys />: Controlled byuser_api_keys_enabledororgs_api_keys_enabledonlyTests
hidepropResolves USER-3923
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
New Features
hideproperty.Bug Fixes
Tests