-
Couldn't load subscription status.
- Fork 402
feat(shared): Export SAML_IDPS from shared/saml #6682
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
feat(shared): Export SAML_IDPS from shared/saml #6682
Conversation
🦋 Changeset detectedLatest commit: 0344588 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.
|
WalkthroughRelocates SAML_IDPS from @clerk/types to @clerk/shared/saml and publishes the shared saml module. Introduces deprecated runtime-values in @clerk/types and re-exports them from index. Removes OAuth/Web3 provider data and helpers from types. Adjusts multiple import paths to relative. Updates types tsconfig to NodeNext. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
@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
🧹 Nitpick comments (9)
packages/shared/package.json (1)
118-118: Ensure SAML artifacts are published and consider explicit subpath export
- Verify your local build of @clerk/shared emits
packages/shared/dist/saml.*artifacts (e.g..js,.mjs,.d.ts,.d.mts).- Optionally add a
./samlexport entry in theexportsfield for stricter tooling compatibility:"exports": { ".": { … }, + "./saml": { + "import": { "types": "./dist/saml.d.mts", "default": "./dist/saml.mjs" }, + "require": { "types": "./dist/saml.d.ts", "default": "./dist/saml.js" } + }, "./*": { … } }packages/types/tsconfig.json (1)
4-7: Enable optional NodeNext compiler knobs in packages/types/tsconfig.json
Confirmed no absolute intra-package imports (only externalcsstype) or.ts-extension imports in packages/types/src; you can safely add:"moduleResolution": "NodeNext", + "verbatimModuleSyntax": true, + "moduleDetection": "force",packages/shared/src/saml.ts (2)
3-20: Prefersatisfies+as constfor safer, immutable, tree-shakeable data.
Locks the shape to SamlIdpMap, prevents accidental mutation in TS, and keeps literal types.-export const SAML_IDPS: SamlIdpMap = { +export const SAML_IDPS = { saml_okta: { name: 'Okta Workforce', logo: 'okta', }, saml_google: { name: 'Google Workspace', logo: 'google', }, saml_microsoft: { - name: 'Microsoft Entra ID (Formerly AD)', + name: 'Microsoft Entra ID (Formerly AD)', logo: 'azure', }, saml_custom: { name: 'SAML', logo: 'saml', }, -}; +} as const satisfies SamlIdpMap;Optionally freeze at runtime (shallow):
export const SAML_IDPS = Object.freeze({ /* ... */ }) as const satisfies SamlIdpMap;Add minimal JSDoc (outside diff range shown):
/** * Canonical SAML IdP metadata. * Public API: import from '@clerk/shared/saml'. */
13-14: Fix product naming for clarity.
Use “formerly Azure AD” to match Microsoft’s terminology.- name: 'Microsoft Entra ID (Formerly AD)', + name: 'Microsoft Entra ID (formerly Azure AD)',packages/types/src/index.ts (1)
53-56: Strengthen deprecation banner on root re-export
Update the comment in packages/types/src/index.ts (≈ lines 53–56) to:/** * DEPRECATED: Transitional re-export for backward compatibility only. * Will be removed in the next major release. * Migrate to: * - @clerk/shared/oauth for OAuth provider data and utils * - @clerk/shared/web3 for Web3 provider data and utils * - @clerk/shared/saml for SAML_IDPS */ export * from './runtime-values';Optionally narrow this
export *to only the symbols needed for BC once those migration paths are in place. No local index-import cycles detected..changeset/new-deer-attend.md (1)
1-8: Expand the changeset to cover OAuth/Web3 deprecations and migration stepsThe body mentions only SAML_IDPS. Since OAuth/Web3 runtime values and helpers are also deprecated in @clerk/types and moved to @clerk/shared, document that and provide migration snippets.
Apply this diff:
--- '@clerk/shared': patch '@clerk/types': patch --- -The `SAML_IDPS` export was moved from `@clerk/types` to `@clerk/shared/saml` and was marked as deprecated. - -Please use `import { SAML_IDPS } from "@clerk/shared/saml"` instead. +The `SAML_IDPS` export was moved from `@clerk/types` to `@clerk/shared/saml` and is deprecated in `@clerk/types`. +In addition, OAuth and Web3 runtime values and helpers were moved to `@clerk/shared` and are deprecated in `@clerk/types`. + +Migration: + +```ts +// Before +import { SAML_IDPS, OAUTH_PROVIDERS, WEB3_PROVIDERS, getOAuthProviderData, getWeb3ProviderData, sortedOAuthProviders } from '@clerk/types'; + +// After +import { SAML_IDPS } from '@clerk/shared/saml'; +import { OAUTH_PROVIDERS, getOAuthProviderData, sortedOAuthProviders } from '@clerk/shared/oauth'; +import { WEB3_PROVIDERS, getWeb3ProviderData } from '@clerk/shared/web3'; +``` + +Note: `@clerk/types` temporarily re-exports these for backward compatibility and will remove them in the next major release.packages/types/src/runtime-values.ts (3)
11-32: Make the provider list immutable at the type levelPrevent accidental mutation by using
as constwithsatisfies readonly Web3ProviderData[].-export const WEB3_PROVIDERS: Web3ProviderData[] = [ +export const WEB3_PROVIDERS = [ { provider: 'metamask', strategy: 'web3_metamask_signature', name: 'MetaMask', }, { provider: 'base', strategy: 'web3_base_signature', name: 'Base', }, { provider: 'coinbase_wallet', strategy: 'web3_coinbase_wallet_signature', name: 'Coinbase Wallet', }, { provider: 'okx_wallet', strategy: 'web3_okx_wallet_signature', name: 'OKX Wallet', }, -]; +] as const satisfies readonly Web3ProviderData[];
56-225: Apply immutability pattern to OAuth providersSame rationale as WEB3_PROVIDERS.
-export const OAUTH_PROVIDERS: OAuthProviderData[] = [ +export const OAUTH_PROVIDERS = [ { provider: 'google', strategy: 'oauth_google', name: 'Google', docsUrl: 'https://clerk.com/docs/authentication/social-connections/google', }, { provider: 'discord', strategy: 'oauth_discord', name: 'Discord', docsUrl: 'https://clerk.com/docs/authentication/social-connections/discord', }, ... -]; +] as const satisfies readonly OAuthProviderData[];
270-287: Mark SAML_IDPS immutable at the type levelKeep parity with the provider lists and make intent explicit.
-export const SAML_IDPS: SamlIdpMap = { +export const SAML_IDPS = { saml_okta: { name: 'Okta Workforce', logo: 'okta', }, saml_google: { name: 'Google Workspace', logo: 'google', }, saml_microsoft: { name: 'Microsoft Entra ID (Formerly AD)', logo: 'azure', }, saml_custom: { name: 'SAML', logo: 'saml', }, -}; +} as const satisfies SamlIdpMap;
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (16)
.changeset/new-deer-attend.md(1 hunks)packages/shared/package.json(1 hunks)packages/shared/src/saml.ts(1 hunks)packages/types/src/authConfig.ts(1 hunks)packages/types/src/commerceSettings.ts(1 hunks)packages/types/src/hooks.ts(1 hunks)packages/types/src/index.ts(1 hunks)packages/types/src/oauth.ts(0 hunks)packages/types/src/phoneNumber.ts(1 hunks)packages/types/src/runtime-values.ts(1 hunks)packages/types/src/saml.ts(0 hunks)packages/types/src/signUp.ts(2 hunks)packages/types/src/telemetry.ts(1 hunks)packages/types/src/userSettings.ts(1 hunks)packages/types/src/web3.ts(0 hunks)packages/types/tsconfig.json(1 hunks)
💤 Files with no reviewable changes (3)
- packages/types/src/oauth.ts
- packages/types/src/saml.ts
- packages/types/src/web3.ts
🧰 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/types/src/telemetry.tspackages/types/src/userSettings.tspackages/types/src/authConfig.tspackages/types/src/hooks.tspackages/types/src/commerceSettings.tspackages/shared/src/saml.tspackages/types/src/phoneNumber.tspackages/types/src/index.tspackages/types/src/signUp.tspackages/types/src/runtime-values.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/types/src/telemetry.tspackages/shared/package.jsonpackages/types/tsconfig.jsonpackages/types/src/userSettings.tspackages/types/src/authConfig.tspackages/types/src/hooks.tspackages/types/src/commerceSettings.tspackages/shared/src/saml.tspackages/types/src/phoneNumber.tspackages/types/src/index.tspackages/types/src/signUp.tspackages/types/src/runtime-values.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/types/src/telemetry.tspackages/types/src/userSettings.tspackages/types/src/authConfig.tspackages/types/src/hooks.tspackages/types/src/commerceSettings.tspackages/shared/src/saml.tspackages/types/src/phoneNumber.tspackages/types/src/index.tspackages/types/src/signUp.tspackages/types/src/runtime-values.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/types/src/telemetry.tspackages/types/src/userSettings.tspackages/types/src/authConfig.tspackages/types/src/hooks.tspackages/types/src/commerceSettings.tspackages/shared/src/saml.tspackages/types/src/phoneNumber.tspackages/types/src/index.tspackages/types/src/signUp.tspackages/types/src/runtime-values.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/types/src/telemetry.tspackages/types/src/userSettings.tspackages/types/src/authConfig.tspackages/types/src/hooks.tspackages/types/src/commerceSettings.tspackages/shared/src/saml.tspackages/types/src/phoneNumber.tspackages/types/src/index.tspackages/types/src/signUp.tspackages/types/src/runtime-values.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/types/src/telemetry.tspackages/types/src/userSettings.tspackages/types/src/authConfig.tspackages/types/src/hooks.tspackages/types/src/commerceSettings.tspackages/shared/src/saml.tspackages/types/src/phoneNumber.tspackages/types/src/index.tspackages/types/src/signUp.tspackages/types/src/runtime-values.ts
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
packages/*/tsconfig.json
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Type checking must be performed with TypeScript and publint.
Files:
packages/types/tsconfig.json
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/new-deer-attend.md
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
🧬 Code graph analysis (2)
packages/shared/src/saml.ts (1)
packages/types/src/saml.ts (1)
SamlIdpMap(8-8)
packages/types/src/runtime-values.ts (4)
packages/types/src/web3.ts (2)
Web3ProviderData(3-7)Web3Provider(14-14)packages/types/src/strategies.ts (1)
Web3Strategy(19-19)packages/types/src/oauth.ts (2)
OAuthProviderData(5-10)OAuthProvider(42-71)packages/types/src/saml.ts (1)
SamlIdpMap(8-8)
⏰ 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). (6)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: semgrep/ci
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (10)
packages/types/src/telemetry.ts (1)
1-1: Relative import under NodeNext: LGTM. No bare local imports remain in packages/types/src.packages/types/src/phoneNumber.ts (1)
2-2: PhoneCodeChannel import normalized: LGTM.
Consistent with NodeNext + type-only import usage.packages/types/src/authConfig.ts (1)
1-1: Approve: import path normalization complete
Verified no barePhoneCodeChannelimports remain; all references use./phoneCodeChannel.packages/types/src/commerceSettings.ts (1)
3-3: LGTM: path normalization is correct and type-only import fits NodeNext.packages/shared/src/saml.ts (3)
1-1: No cross-package cycle detected between @clerk/shared and @clerk/types. packages/types/src contains no runtime imports from @clerk/shared (only deprecation comments), and only @clerk/shared lists @clerk/types as a dependency.
3-20: SAML_IDPS keys exhaustively match SamlIdpSlug.
3-3: Wildcard export covers saml subpath
The existing"./*"export mapping in packages/shared/package.json already exposesdist/saml.*, soimport { SAML_IDPS } from '@clerk/shared/saml'works without adding an explicit./samlexport.packages/types/src/userSettings.ts (1)
2-2: LGTM: relative, type-only import; keeps barrels clean and aligns with NodeNext.packages/types/src/hooks.ts (1)
3-3: LGTM: path corrections to local type-only imports.
No API changes; ESLint-friendly.Also applies to: 10-10
packages/types/src/signUp.ts (1)
1-5: LGTM: explicit imports and local paths reduce barrel coupling.
Type-only usage is correct; should be emission-free.Also applies to: 16-16
| export function getWeb3ProviderData(params: { | ||
| provider?: Web3Provider; | ||
| strategy?: Web3Strategy; | ||
| }): Web3ProviderData | undefined | null { | ||
| const { provider, strategy } = params; | ||
| if (provider) { | ||
| return WEB3_PROVIDERS.find(p => p.provider == provider); | ||
| } | ||
|
|
||
| return WEB3_PROVIDERS.find(p => p.strategy == strategy); | ||
| } |
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
Fix return type and use strict equality
The function never returns null and eqeqeq will likely flag ==. Also guard when both params are absent.
-export function getWeb3ProviderData(params: {
+export function getWeb3ProviderData(params: {
provider?: Web3Provider;
strategy?: Web3Strategy;
-}): Web3ProviderData | undefined | null {
+}): Web3ProviderData | undefined {
const { provider, strategy } = params;
- if (provider) {
- return WEB3_PROVIDERS.find(p => p.provider == provider);
- }
-
- return WEB3_PROVIDERS.find(p => p.strategy == strategy);
+ if (provider) {
+ return WEB3_PROVIDERS.find(p => p.provider === provider);
+ }
+ if (strategy) {
+ return WEB3_PROVIDERS.find(p => p.strategy === strategy);
+ }
+ return undefined;
}📝 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 function getWeb3ProviderData(params: { | |
| provider?: Web3Provider; | |
| strategy?: Web3Strategy; | |
| }): Web3ProviderData | undefined | null { | |
| const { provider, strategy } = params; | |
| if (provider) { | |
| return WEB3_PROVIDERS.find(p => p.provider == provider); | |
| } | |
| return WEB3_PROVIDERS.find(p => p.strategy == strategy); | |
| } | |
| export function getWeb3ProviderData(params: { | |
| provider?: Web3Provider; | |
| strategy?: Web3Strategy; | |
| }): Web3ProviderData | undefined { | |
| const { provider, strategy } = params; | |
| if (provider) { | |
| return WEB3_PROVIDERS.find(p => p.provider === provider); | |
| } | |
| if (strategy) { | |
| return WEB3_PROVIDERS.find(p => p.strategy === strategy); | |
| } | |
| return undefined; | |
| } |
🤖 Prompt for AI Agents
In packages/types/src/runtime-values.ts around lines 39 to 49, the function
signature and logic are incorrect: it declares a possible null return and uses
non-strict equality; also it doesn't explicitly handle the case when neither
param is provided. Update the return type to only allow Web3ProviderData |
undefined, add an early guard that returns undefined if both provider and
strategy are absent, and replace any == comparisons with strict === when
matching provider or strategy against entries in WEB3_PROVIDERS.
| export function getOAuthProviderData(params: { | ||
| provider?: OAuthProvider; | ||
| strategy?: OAuthStrategy; | ||
| }): OAuthProviderData | undefined | null { | ||
| const { provider, strategy } = params; | ||
| if (provider) { | ||
| return OAUTH_PROVIDERS.find(oauth_provider => oauth_provider.provider == provider); | ||
| } | ||
|
|
||
| return OAUTH_PROVIDERS.find(oauth_provider => oauth_provider.strategy == strategy); | ||
| } |
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
Fix return type and use strict equality
Align with the Web3 helper.
-export function getOAuthProviderData(params: {
+export function getOAuthProviderData(params: {
provider?: OAuthProvider;
strategy?: OAuthStrategy;
-}): OAuthProviderData | undefined | null {
+}): OAuthProviderData | undefined {
const { provider, strategy } = params;
if (provider) {
- return OAUTH_PROVIDERS.find(oauth_provider => oauth_provider.provider == provider);
+ return OAUTH_PROVIDERS.find(oauth_provider => oauth_provider.provider === provider);
}
-
- return OAUTH_PROVIDERS.find(oauth_provider => oauth_provider.strategy == strategy);
+ if (strategy) {
+ return OAUTH_PROVIDERS.find(oauth_provider => oauth_provider.strategy === strategy);
+ }
+ return undefined;
}📝 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 function getOAuthProviderData(params: { | |
| provider?: OAuthProvider; | |
| strategy?: OAuthStrategy; | |
| }): OAuthProviderData | undefined | null { | |
| const { provider, strategy } = params; | |
| if (provider) { | |
| return OAUTH_PROVIDERS.find(oauth_provider => oauth_provider.provider == provider); | |
| } | |
| return OAUTH_PROVIDERS.find(oauth_provider => oauth_provider.strategy == strategy); | |
| } | |
| export function getOAuthProviderData(params: { | |
| provider?: OAuthProvider; | |
| strategy?: OAuthStrategy; | |
| }): OAuthProviderData | undefined { | |
| const { provider, strategy } = params; | |
| if (provider) { | |
| return OAUTH_PROVIDERS.find( | |
| oauth_provider => oauth_provider.provider === provider | |
| ); | |
| } | |
| if (strategy) { | |
| return OAUTH_PROVIDERS.find( | |
| oauth_provider => oauth_provider.strategy === strategy | |
| ); | |
| } | |
| return undefined; | |
| } |
🤖 Prompt for AI Agents
In packages/types/src/runtime-values.ts around lines 232 to 242, the function
return type and equality checks are incorrect: change the signature to return
OAuthProviderData | null (remove undefined), replace == with strict === for both
provider and strategy comparisons, and ensure you return null when no match is
found (do not let find return undefined).
| export function sortedOAuthProviders(sortingArray: OAuthStrategy[]) { | ||
| return OAUTH_PROVIDERS.slice().sort((a, b) => { | ||
| let aPos = sortingArray.indexOf(a.strategy); | ||
| if (aPos == -1) { | ||
| aPos = Number.MAX_SAFE_INTEGER; | ||
| } | ||
|
|
||
| let bPos = sortingArray.indexOf(b.strategy); | ||
| if (bPos == -1) { | ||
| bPos = Number.MAX_SAFE_INTEGER; | ||
| } | ||
|
|
||
| return aPos - bPos; | ||
| }); | ||
| } |
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
Add explicit return type and simplify sentinel logic
Public API should declare explicit return types. Using Infinity reads clearer than Number.MAX_SAFE_INTEGER.
-export function sortedOAuthProviders(sortingArray: OAuthStrategy[]) {
- return OAUTH_PROVIDERS.slice().sort((a, b) => {
- let aPos = sortingArray.indexOf(a.strategy);
- if (aPos == -1) {
- aPos = Number.MAX_SAFE_INTEGER;
- }
-
- let bPos = sortingArray.indexOf(b.strategy);
- if (bPos == -1) {
- bPos = Number.MAX_SAFE_INTEGER;
- }
-
- return aPos - bPos;
- });
+export function sortedOAuthProviders(sortingArray: OAuthStrategy[]): OAuthProviderData[] {
+ return [...OAUTH_PROVIDERS].sort((a, b) => {
+ const aPos = sortingArray.indexOf(a.strategy);
+ const bPos = sortingArray.indexOf(b.strategy);
+ return (aPos === -1 ? Infinity : aPos) - (bPos === -1 ? Infinity : bPos);
+ });
}📝 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 function sortedOAuthProviders(sortingArray: OAuthStrategy[]) { | |
| return OAUTH_PROVIDERS.slice().sort((a, b) => { | |
| let aPos = sortingArray.indexOf(a.strategy); | |
| if (aPos == -1) { | |
| aPos = Number.MAX_SAFE_INTEGER; | |
| } | |
| let bPos = sortingArray.indexOf(b.strategy); | |
| if (bPos == -1) { | |
| bPos = Number.MAX_SAFE_INTEGER; | |
| } | |
| return aPos - bPos; | |
| }); | |
| } | |
| export function sortedOAuthProviders(sortingArray: OAuthStrategy[]): OAuthProviderData[] { | |
| return [...OAUTH_PROVIDERS].sort((a, b) => { | |
| const aPos = sortingArray.indexOf(a.strategy); | |
| const bPos = sortingArray.indexOf(b.strategy); | |
| return (aPos === -1 ? Infinity : aPos) - (bPos === -1 ? Infinity : bPos); | |
| }); | |
| } |
🤖 Prompt for AI Agents
In packages/types/src/runtime-values.ts around lines 249 to 263, add an explicit
return type (e.g., OAuthProvider[] or the correct provider element type used by
OAUTH_PROVIDERS) to the sortedOAuthProviders signature and simplify the sentinel
logic by using Infinity instead of Number.MAX_SAFE_INTEGER; compute positions
with a concise expression like const aPos = (sortingArray.indexOf(a.strategy)
=== -1 ? Infinity : sortingArray.indexOf(a.strategy)) (or call indexOf once into
a temp and map -1 -> Infinity) and do the same for b, then return aPos - bPos.
Description
runtime-valuesYou can validate that there aren't any other runtime values present in
clerk/typesby commenting outexport * from './runtime-values';intypes/src/index.tsand then building the pkg:pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
New Features
Refactor
Chores