-
Notifications
You must be signed in to change notification settings - Fork 381
fix(backend): Ability to convert bodyParam keys recursively #6418
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: 5c3bb73 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 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 Git ↗︎
|
📝 WalkthroughWalkthroughThe changes introduce a patch to the Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes were found. Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@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: 0
🧹 Nitpick comments (1)
packages/backend/src/api/request.ts (1)
153-154
: Correct implementation of conditional deep snakecasing.The
formatKeys
function now properly uses thedeep
option from the snakecase-keys library based on thedeepSnakecaseBodyParamKeys
flag. This enables the recursive key conversion needed for nested objects likeattributeMapping
.Consider adding a performance note in the JSDoc comment about the potential impact of deep snakecasing on large nested objects:
/** * If true, snakecases the keys of the bodyParams object recursively. + * Note: Deep snakecasing may have performance implications for large nested objects. * @default false */
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.changeset/silver-singers-train.md
(1 hunks)packages/backend/src/api/__tests__/SamlConnectionApi.test.ts
(2 hunks)packages/backend/src/api/endpoints/SamlConnectionApi.ts
(2 hunks)packages/backend/src/api/request.ts
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
.changeset/**
📄 CodeRabbit Inference Engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/silver-singers-train.md
**/*.{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/backend/src/api/endpoints/SamlConnectionApi.ts
packages/backend/src/api/__tests__/SamlConnectionApi.test.ts
packages/backend/src/api/request.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/backend/src/api/endpoints/SamlConnectionApi.ts
packages/backend/src/api/__tests__/SamlConnectionApi.test.ts
packages/backend/src/api/request.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/backend/src/api/endpoints/SamlConnectionApi.ts
packages/backend/src/api/__tests__/SamlConnectionApi.test.ts
packages/backend/src/api/request.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit Inference Engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/backend/src/api/endpoints/SamlConnectionApi.ts
packages/backend/src/api/__tests__/SamlConnectionApi.test.ts
packages/backend/src/api/request.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
Avoidany
type - preferunknown
when type is uncertain, then narrow with type guards
Useinterface
for object shapes that might be extended
Usetype
for unions, primitives, and computed types
Preferreadonly
properties for immutable data structures
Useprivate
for internal implementation details
Useprotected
for inheritance hierarchies
Usepublic
explicitly for clarity in public APIs
Preferreadonly
for 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 assertions
for literal types:as const
Usesatisfies
operator 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 ...
Noany
types without justification
Proper error handling with typed errors
Consistent use ofreadonly
for 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/backend/src/api/endpoints/SamlConnectionApi.ts
packages/backend/src/api/__tests__/SamlConnectionApi.test.ts
packages/backend/src/api/request.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/backend/src/api/endpoints/SamlConnectionApi.ts
packages/backend/src/api/__tests__/SamlConnectionApi.test.ts
packages/backend/src/api/request.ts
**/*
⚙️ CodeRabbit Configuration File
**/*
: If there are no tests added or modified as part of the PR, please suggest that tests be added to cover the changes.Whenever reviewing a pull request, if there are any changes that could impact security, always tag
@clerk/security
in the PR.Security-impacting changes include, but are not limited to:
- Changes to authentication logic or mechanisms (e.g. login, session handling, token issuance)
- Any modification to access control, authorization checks, or role-based permissions
- Introduction or modification of hashing algorithms, signature verification, or cryptographic primitives
- Handling of sensitive data (e.g. passwords, tokens, secrets, PII)
- Integration with external identity providers (e.g. SSO, OAuth, OpenID Connect)
- Modifications to security headers, cookie flags, CORS policies, or CSRF protections
- Bypass mechanisms (e.g. feature flags, testing overrides) that could weaken protections
- Changes to rate limiting, abuse prevention, or input validation
If you're unsure whether a change is security-relevant, err on the side of caution and tag
@clerk/security
.Any time that you tag
@clerk/security
, please do so explicitly in a code comment, rather than within a collapsed section in a coderabbit comment, such as the "recent review details" section. If you do use the team name in any thinking or non-direct-code-comment content, it can be referred to as "clerk security team" to avoid accidentally printing the tag which sends a notification to the team.
Files:
packages/backend/src/api/endpoints/SamlConnectionApi.ts
packages/backend/src/api/__tests__/SamlConnectionApi.test.ts
packages/backend/src/api/request.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/backend/src/api/__tests__/SamlConnectionApi.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/backend/src/api/__tests__/SamlConnectionApi.test.ts
⏰ 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). (23)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Integration Tests (nuxt, chrome)
- GitHub Check: Integration Tests (tanstack-react-start, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 14)
- GitHub Check: Integration Tests (tanstack-react-router, chrome)
- GitHub Check: Integration Tests (expo-web, chrome)
- GitHub Check: Integration Tests (nextjs, chrome, 15)
- GitHub Check: Integration Tests (ap-flows, chrome)
- GitHub Check: Integration Tests (billing, chrome)
- GitHub Check: Integration Tests (vue, chrome)
- GitHub Check: Integration Tests (react-router, chrome)
- GitHub Check: Integration Tests (sessions, chrome)
- GitHub Check: Integration Tests (express, chrome)
- GitHub Check: Integration Tests (astro, chrome)
- GitHub Check: Integration Tests (localhost, chrome)
- GitHub Check: Integration Tests (generic, chrome)
- GitHub Check: Integration Tests (elements, chrome)
- GitHub Check: Integration Tests (quickstart, chrome)
- GitHub Check: Publish with pkg-pr-new
- GitHub Check: Static analysis
- GitHub Check: Unit Tests (22, **)
- GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
.changeset/silver-singers-train.md (1)
5-5
: LGTM! Clear and accurate changeset description.The changeset properly documents the patch to fix SAML Connection
attributeMapping
keys conversion from camelCase to snake_case.packages/backend/src/api/endpoints/SamlConnectionApi.ts (2)
85-87
: LGTM! Consistent implementation of deep snakecasing for create operation.The addition of
deepSnakecaseBodyParamKeys: true
ensures that nested keys likeattributeMapping
are properly converted to snake_case format as intended by the fix.
106-108
: LGTM! Consistent implementation of deep snakecasing for update operation.The change mirrors the create operation, ensuring consistent behavior for all SAML connection modifications.
Since SAML connections are security-sensitive and this change affects how authentication attribute mappings are formatted, please verify that existing SAML connections continue to work correctly after this change. The security team should also review this change.
@clerk/security - Please review this change as it affects SAML authentication attribute mapping formatting.
packages/backend/src/api/__tests__/SamlConnectionApi.test.ts (3)
13-37
: Good refactoring with reusable mock data.The shared mock response object improves test maintainability and consistency across test cases.
77-118
: Excellent test coverage for createSamlConnection.The test properly validates the core functionality:
- Input
attributeMapping
in camelCase is converted toattribute_mapping
in snake_case in the request body- Response is correctly deserialized back to camelCase format
- All expected fields are properly validated
120-186
: Comprehensive test coverage for updateSamlConnection.The test validates both the deep snakecasing functionality and proper handling of all SAML connection parameters. The test correctly verifies that:
- Input parameters in camelCase are converted to snake_case in the request
- Response deserialization works correctly
- All SAML connection fields are properly handled
packages/backend/src/api/request.ts (2)
11-45
: Excellent type refactoring with proper type safety.The intersection types provide better structure and type safety:
- Separates URL/path specification logic
- Properly constrains the
deepSnakecaseBodyParamKeys
option to only be available whenbodyParams
is provided- Maintains backward compatibility while adding the new functionality
100-101
: Clean extraction of the deep snakecasing option.The destructuring properly extracts the option with a sensible default, maintaining backward compatibility.
options: { | ||
deepSnakecaseBodyParamKeys: true, | ||
}, |
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.
Nice. I might use this new options
param to override adding of secret key to the Authorization
header for #6229
Description
Adds the ability to convert bodyParam keys recursively by adding
options.deepSnakecaseBodyParamKeys
.I didn't default to
deep: true
to ensure that there weren't any regressions.USER-2475
Checklist
pnpm test
runs as expected.pnpm build
runs as expected.Type of change
Summary by CodeRabbit
Bug Fixes
Tests
Refactor