- 
        Couldn't load subscription status. 
- Fork 403
chore(types,shared): Move error related types to errors.ts #6984
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: 98b8f04 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types 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. 
 | 
| WalkthroughAdds a placeholder changeset and publishes type declarations from the shared package; expands build/subpath rules to include a  Changes
 Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
 Pre-merge checks and finishing touches✅ Passed checks (3 passed)
 ✨ Finishing touches
 🧪 Generate unit tests (beta)
 Comment  | 
8697e8e    to
    1ad8ee0      
    Compare
  
    | @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: 2
🧹 Nitpick comments (4)
.changeset/dull-news-live.md (1)
1-2: Fill the changeset with package bumps and summaryThis placeholder won’t publish. Add affected packages and semver bumps (at least @clerk/shared, @clerk/types) and a short note, e.g.:
--- '@clerk/shared': patch '@clerk/types': patch --- chore(types,shared): centralize error-related types in errors.ts and expose shared ./types subpathIf removing './api' exports is user-facing, consider a breaking note and a major bump.
packages/shared/tsup.config.ts (1)
19-19: Include './src/types/*.ts' in build — LGTMThis will emit declarations for the new subpath. If these files are type-only, consider marking exports as
export typeto minimize runtime output; not blocking.packages/types/src/errors.ts (2)
1-25: Add JSDoc and mark collection fields readonly on public JSON typeThis is a public surface; add brief JSDoc and use readonly for arrays to reflect immutability of API payloads.
Apply:
+/** + * JSON wire shape of a Clerk API error as returned by the HTTP API. + * Note: keys follow snake_case to match the API. + */ export interface ClerkAPIErrorJSON { code: string; message: string; long_message?: string; meta?: { param_name?: string; session_id?: string; - email_addresses?: string[]; - identifiers?: string[]; + email_addresses?: readonly string[]; + identifiers?: readonly string[]; zxcvbn?: { - suggestions: { + suggestions: readonly { code: string; message: string; }[]; }; plan?: { amount_formatted: string; annual_monthly_amount_formatted: string; currency_symbol: string; id: string; name: string; }; is_plan_upgrade_possible?: boolean; }; }
77-83: Clarify units for retryAfter and document statusAdd brief JSDoc for HTTP status and whether retryAfter is seconds or milliseconds.
Example:
export interface ClerkAPIResponseError extends Error { clerkError: true; - status: number; - message: string; + /** HTTP status code of the response (e.g., 429, 500). */ + status: number; + message: string; clerkTraceId?: string; - retryAfter?: number; + /** Backoff duration as returned by the API (e.g., seconds from Retry-After header). */ + retryAfter?: number; errors: ClerkAPIError[]; }
📜 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 (9)
- .changeset/dull-news-live.md(1 hunks)
- packages/shared/package.json(2 hunks)
- packages/shared/subpaths.mjs(1 hunks)
- packages/shared/tsup.config.ts(1 hunks)
- packages/types/src/clerk.ts(1 hunks)
- packages/types/src/errors.ts(1 hunks)
- packages/types/src/index.ts(1 hunks)
- packages/types/src/json.ts(1 hunks)
- packages/types/src/verification.ts(1 hunks)
🧰 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:
- packages/shared/tsup.config.ts
- packages/types/src/errors.ts
- packages/types/src/clerk.ts
- packages/types/src/json.ts
- packages/types/src/index.ts
- packages/types/src/verification.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/shared/tsup.config.ts
- packages/types/src/errors.ts
- packages/types/src/clerk.ts
- packages/types/src/json.ts
- packages/types/src/index.ts
- packages/types/src/verification.ts
- packages/shared/package.json
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
- packages/shared/tsup.config.ts
- packages/types/src/errors.ts
- packages/types/src/clerk.ts
- packages/types/src/json.ts
- packages/types/src/index.ts
- packages/types/src/verification.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
- packages/shared/tsup.config.ts
- packages/types/src/errors.ts
- packages/types/src/clerk.ts
- packages/types/src/json.ts
- packages/types/src/index.ts
- packages/types/src/verification.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/shared/tsup.config.ts
- packages/types/src/errors.ts
- packages/types/src/clerk.ts
- packages/types/src/json.ts
- packages/types/src/index.ts
- packages/types/src/verification.ts
packages/*/tsup.config.{js,ts}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
TypeScript compilation and bundling must use tsup.
Files:
- packages/shared/tsup.config.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/shared/tsup.config.ts
- packages/types/src/errors.ts
- packages/types/src/clerk.ts
- packages/types/src/json.ts
- packages/types/src/index.ts
- packages/types/src/verification.ts
packages/**/index.{js,ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use tree-shaking friendly exports
Files:
- packages/types/src/index.ts
**/index.ts
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Use index.ts files for clean imports but avoid deep barrel exports
Avoid barrel files (index.ts re-exports) as they can cause circular dependencies
Files:
- packages/types/src/index.ts
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
- .changeset/dull-news-live.md
packages/*/package.json
📄 CodeRabbit inference engine (.cursor/rules/global.mdc)
All publishable packages should be placed under the packages/ directory
packages/*/package.json: All publishable packages must be located in the 'packages/' directory.
All packages must be published under the @clerk namespace on npm.
Semantic versioning must be used across all packages.
Files:
- packages/shared/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
🔇 Additional comments (5)
packages/shared/subpaths.mjs (1)
10-10: Add 'types' to barrel subpaths — LGTMMatches package.json/files and the new export. No issues.
packages/types/src/json.ts (1)
18-18: Centralize ClerkAPIErrorJSON import — LGTMEnsure the
ClerkAPIErrorJSONinterface inerrors.tsincludes all fields returned by the Clerk API’s error payload.packages/types/src/clerk.ts (1)
34-34: Confirm ClerkAPIResponseError export
ClerkAPIResponseError is explicitly exported from errors.ts and re-exported in index.ts; import path './errors' is correct.packages/types/src/index.ts (1)
20-20: Remove incorrect “./api” BC warning
Nopackages/types/src/api.tsexists andexport * from './api'was never present—this concern is invalid.Likely an incorrect or invalid review comment.
packages/types/src/verification.ts (1)
1-1: LGTM — type-only import move
ImportingClerkAPIErrorfrom'./errors'keeps value emissions out of the bundle; no lingering imports/re-exports from'./api'and errors are properly re-exported.
| "./types": { | ||
| "import": { | ||
| "types": "./dist/types/index.d.mts" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/types/index.d.ts" | ||
| } | ||
| }, | 
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.
🧩 Analysis chain
New "./types" export: verify packaging and declaration output
Looks good and consistent with existing pattern. Please verify:
- dist/types/index.d.mts and index.d.ts are emitted by the build.
- publint/attw are clean for the new subpath.
Suggested commands:
Also consider whether a wildcard subpath (e.g. "./types/*") is desired in the future for granular imports. Not required now.
Also applies to: 134-136
🏁 Script executed:
#!/bin/bash
# Check that type entrypoints are emitted (after a local build)
fd -p 'index.d.(mts|ts)$' dist/types -E node_modules
# Sanity-check subpath exports reference the emitted files
jq '.exports["./types"]' packages/shared/package.json
# Run packaging linters (locally)
echo "In your env, run:"
echo "pnpm -w --filter @clerk/shared build && pnpm -w --filter @clerk/shared lint:publint && pnpm -w --filter @clerk/shared lint:attw"Length of output: 364
🏁 Script executed:
#!/bin/bash
if [ -d packages/shared/dist/types ]; then
  echo "✅ Directory packages/shared/dist/types exists"
  fd -p 'index.d.(mts|ts)$' packages/shared/dist/types
else
  echo "🚨 Directory packages/shared/dist/types is missing"
fiLength of output: 50
Exported ./types subpath files not found
The directory packages/shared/dist/types (with index.d.mts and index.d.ts) is missing, so the new "./types" export will break. Ensure your build generates those declaration files under dist/types before publishing.
🤖 Prompt for AI Agents
In packages/shared/package.json around lines 73 to 80, the new "./types" export
points to dist/types/index.d.mts and dist/types/index.d.ts which do not exist;
update the build to emit declaration files into dist/types (or change the export
to match actual paths). Modify tsconfig/build config to set "declaration": true
and "declarationDir": "dist/types" (or adjust your bundler) so index.d.ts/.d.mts
are generated during build, then ensure the build step runs before publishing
and verify the files exist in dist/types.
| export interface ClerkAPIErrorJSON { | ||
| code: string; | ||
| message: string; | ||
| long_message?: string; | ||
| meta?: { | ||
| param_name?: string; | ||
| session_id?: string; | ||
| email_addresses?: string[]; | ||
| identifiers?: string[]; | ||
| zxcvbn?: { | ||
| suggestions: { | ||
| code: string; | ||
| message: string; | ||
| }[]; | ||
| }; | ||
| plan?: { | ||
| amount_formatted: string; | ||
| annual_monthly_amount_formatted: string; | ||
| currency_symbol: string; | ||
| id: string; | ||
| name: string; | ||
| }; | ||
| is_plan_upgrade_possible?: boolean; | ||
| }; | ||
| } | 
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
🧩 Analysis chain
Align JSON vs runtime error meta shape (plan naming, permissions parity)
- Runtime ClerkAPIError.meta uses camelCase, but plan fields remain snake_case; this is inconsistent with the rest of the runtime shape. Either:
- keep ClerkAPIErrorJSON as the only snake_case type and expose ClerkAPIError.plan with camelCase (document the mapping), or
- add a comment clarifying that plan is intentionally snake_case in runtime.
 
- Also, runtime meta includes permissions?: string[] but JSON meta does not. If the API returns it, mirror it in ClerkAPIErrorJSON; otherwise document the divergence.
Run to locate other references and confirm intended shape:
Also applies to: 58-65
🏁 Script executed:
#!/bin/bash
# Inspect other occurrences of plan fields and permissions across types
rg -nP -C3 --type=ts '\b(plan|permissions)\b.*:'Length of output: 139607
🏁 Script executed:
#!/bin/bash
# Display the beginning of the errors.ts to inspect ClerkAPIErrorJSON
sed -n '1,80p' packages/types/src/errors.ts
# Display the continuation to show runtime meta shape
sed -n '80,140p' packages/types/src/errors.tsLength of output: 1774
Align ClerkAPIErrorJSON & ClerkAPIError.meta (add permissions + unify plan field casing)
- In packages/types/src/errors.ts, add permissions?: string[]toClerkAPIErrorJSON.meta
- Rename plan props in both ClerkAPIErrorJSON.meta.planandClerkAPIError.meta.planto camelCase (amountFormatted,annualMonthlyAmountFormatted,currencySymbol) and update the mapping in parseError.ts accordingly
🤖 Prompt for AI Agents
In packages/types/src/errors.ts around lines 1 to 25, the ClerkAPIErrorJSON.meta
shape needs to include an optional permissions?: string[] field and the nested
plan property keys must be converted from snake/slug/case to camelCase
(amountFormatted, annualMonthlyAmountFormatted, currencySymbol) to match
ClerkAPIError.meta; update the interface accordingly and then modify
parseError.ts mappings to translate incoming API plan fields to these new
camelCase property names (and ensure both the JSON type and the internal
ClerkAPIError.meta plan type use the same camelCase keys).
1ad8ee0    to
    98b8f04      
    Compare
  
    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 (3)
- .changeset/dull-news-live.md(1 hunks)
- packages/shared/src/types/index.ts(1 hunks)
- packages/types/src/clerk.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{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/shared/src/types/index.ts
- packages/types/src/clerk.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/shared/src/types/index.ts
- packages/types/src/clerk.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
- packages/shared/src/types/index.ts
- packages/types/src/clerk.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/index.ts
- packages/types/src/clerk.ts
packages/**/index.{js,ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use tree-shaking friendly exports
Files:
- packages/shared/src/types/index.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/shared/src/types/index.ts
- packages/types/src/clerk.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/shared/src/types/index.ts
- packages/types/src/clerk.ts
**/index.ts
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
Use index.ts files for clean imports but avoid deep barrel exports
Avoid barrel files (index.ts re-exports) as they can cause circular dependencies
Files:
- packages/shared/src/types/index.ts
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
- .changeset/dull-news-live.md
⏰ 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: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
.changeset/dull-news-live.md (1)
1-2: Add meaningful changeset description before merging.This changeset is currently a placeholder. Please add a description of the changes (moving error-related types to errors.ts) and specify the appropriate semver bump type (likely
patchfor this refactoring).packages/types/src/clerk.ts (1)
34-34: All ClerkAPIResponseError imports updatedNo remaining imports from './api'; all references now import from './errors'.
| @@ -0,0 +1 @@ | |||
| export type _unstable_mock_type = any; | |||
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.
Replace any with unknown or provide justification.
The use of any violates TypeScript best practices and defeats type safety guarantees. Additionally, this public type export lacks JSDoc documentation explaining its purpose and usage.
As per coding guidelines:
- "Avoid anytype - preferunknownwhen type is uncertain"
- "All public APIs must be documented with JSDoc"
Consider this refactor:
+/**
+ * Unstable mock type for testing purposes.
+ * @experimental This type is unstable and may change in future versions.
+ */
-export type _unstable_mock_type = any;
+export type _unstable_mock_type = unknown;If any is truly required for mocking scenarios, please add JSDoc explaining why and provide usage examples.
📝 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.
| export type _unstable_mock_type = any; | |
| /** | |
| * Unstable mock type for testing purposes. | |
| * @experimental This type is unstable and may change in future versions. | |
| */ | |
| export type _unstable_mock_type = unknown; | 
🤖 Prompt for AI Agents
In packages/shared/src/types/index.ts around line 1, the exported type
_unstable_mock_type currently uses `any`, which breaks type safety and lacks
documentation; replace `any` with `unknown` (or a more specific generic) and add
JSDoc explaining the type's purpose, usage, and why `unknown` is appropriate, or
if `any` is truly required for mocking, keep `any` but add explicit JSDoc
justification and usage examples showing safe casting/validation patterns.
Description
Tiny cleanup in preparation for #6906
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
New Features
Refactor
Chores