Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 468
chore(*): Improve @clerk/backend DX [Part 2 - Errors subpath exports]#2362
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4b52325ad14f8008f3459077642bd225d56802b76275b6bee637d245File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| '@clerk/clerk-sdk-node': major | ||
| --- | ||
| Drop all pre-instantiated Backend API resources (`allowlistIdentifiers`, `clients`, `emailAddresses`, `emails`, `invitations`, `organizations`, `phoneNumbers`, `redirectUrls`, `sessions`, `signInTokens`, `users`, `domains`). Use the `clerkClient` import instead. | ||
| ```typescript | ||
| // Before | ||
| import { users } from "@clerk/clerk-sdk-node" | ||
| // After | ||
| import { clerkClient } from "@clerk/clerk-sdk-node" | ||
| clerkClient.users | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| '@clerk/clerk-sdk-node': major | ||
| '@clerk/backend': major | ||
| '@clerk/nextjs': major | ||
| --- | ||
| Changes in `@clerk/backend` exports: | ||
| - Drop Internal `deserialize` helper | ||
| - Introduce `/errors` subpath export, eg: | ||
| ```typescript | ||
| import { | ||
| TokenVerificationError, | ||
| TokenVerificationErrorAction, | ||
| TokenVerificationErrorCode, | ||
| TokenVerificationErrorReason } from '@clerk/backend/errors'; | ||
| ``` | ||
| - Drop errors from top-level export | ||
| ```typescript | ||
| // Before | ||
| import { TokenVerificationError, TokenVerificationErrorReason } from '@clerk/backend'; | ||
| // After | ||
| import { TokenVerificationError, TokenVerificationErrorReason } from '@clerk/backend/errors'; | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -24,9 +24,30 @@ | ||
| "default": "./dist/runtime/browser/crypto.mjs" | ||
| } | ||
| }, | ||
| "exports": { | ||
| ".": { | ||
| "import": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| } | ||
| }, | ||
| "./errors": { | ||
| "import": { | ||
| "types": "./dist/errors.d.ts", | ||
| "default": "./dist/errors.mjs" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/errors.d.ts", | ||
| "default": "./dist/errors.js" | ||
| } | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "main": "./dist/index.js", | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's drop TS will use the Extra context: https://www.typescriptlang.org/tsconfig#moduleResolution ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i will apply it as part of: #2365 | ||
| "module": "./dist/esm/index.js", | ||
| "types": "./dist/types/index.d.ts", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,7 +2,7 @@ import type { TelemetryCollectorOptions } from '@clerk/shared/telemetry'; | ||
| import { TelemetryCollector } from '@clerk/shared/telemetry'; | ||
| import type { SDKMetadata } from '@clerk/types'; | ||
| import type { CreateBackendApiOptions } from './api'; | ||
| import type { ApiClient, CreateBackendApiOptions } from './api'; | ||
| import { createBackendApiClient } from './api'; | ||
| import type { CreateAuthenticateRequestOptions } from './tokens'; | ||
| import { createAuthenticateRequest } from './tokens'; | ||
| @@ -25,7 +25,14 @@ export type ClerkOptions = CreateBackendApiOptions & | ||
| > | ||
| > & { sdkMetadata?: SDKMetadata; telemetry?: Pick<TelemetryCollectorOptions, 'disabled' | 'debug'> }; | ||
| export function createClerkClient(options: ClerkOptions) { | ||
| // The current exported type resolves the following issue in packages importing createClerkClient | ||
| // TS4023: Exported variable 'clerkClient' has or is using name 'AuthErrorReason' from external module "/packages/backend/dist/index" but cannot be named. | ||
| export type ClerkClient = { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed offline, problematic area with types and type inference, will come back to this after v5 or next week. | ||
| telemetry: TelemetryCollector; | ||
| } & ApiClient & | ||
| ReturnType<typeof createAuthenticateRequest>; | ||
| export function createClerkClient(options: ClerkOptions): ClerkClient { | ||
| const opts = { ...options }; | ||
| const apiClient = createBackendApiClient(opts); | ||
| const requestState = createAuthenticateRequest({ options: opts, apiClient }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| export default crypto; | ||
| export const webcrypto = crypto; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1 @@ | ||
| let webcrypto; | ||
| try { | ||
| webcrypto = require('node:crypto').webcrypto; | ||
| if (!webcrypto) { | ||
| webcrypto = global.crypto; | ||
| } | ||
| } catch (e) { | ||
| webcrypto = global.crypto; | ||
| } | ||
| module.exports = webcrypto; | ||
| module.exports.webcrypto = require('node:crypto').webcrypto; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| export * from './authObjects'; | ||
| export { AuthStatus } from './authStatus'; | ||
| export type { RequestState } from './authStatus'; | ||
| export { TokenVerificationError, TokenVerificationErrorReason } from './errors'; | ||
| export * from './factory'; | ||
| export { debugRequestState } from './request'; | ||
| export type { AuthenticateRequestOptions, OptionalVerifyTokenOptions } from './request'; |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.