diff --git a/packages/backend/package.json b/packages/backend/package.json index 3ae46239cd0..67229c832ec 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -12,18 +12,50 @@ "directory": "packages/backend" }, "license": "MIT", - "imports": { - "#crypto": { - "edge-light": "./dist/runtime/browser/crypto.mjs", - "worker": "./dist/runtime/browser/crypto.mjs", - "browser": "./dist/runtime/browser/crypto.mjs", - "node": "./dist/runtime/node/crypto.js", - "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" + } + }, + "./internal": { + "import": { + "types": "./dist/internal.d.ts", + "default": "./dist/internal.mjs" + }, + "require": { + "types": "./dist/internal.d.ts", + "default": "./dist/internal.js" + } + }, + "./jwt": { + "import": { + "types": "./dist/jwt/index.d.ts", + "default": "./dist/jwt/index.mjs" + }, + "require": { + "types": "./dist/jwt/index.d.ts", + "default": "./dist/jwt/index.js" + } + }, + "./package.json": "./package.json" }, "main": "./dist/index.js", - "module": "./dist/esm/index.js", - "types": "./dist/types/index.d.ts", "files": [ "dist" ], diff --git a/packages/backend/src/__tests__/exports.test.ts b/packages/backend/src/__tests__/exports.test.ts new file mode 100644 index 00000000000..44aaa2935d7 --- /dev/null +++ b/packages/backend/src/__tests__/exports.test.ts @@ -0,0 +1,56 @@ +import type QUnit from 'qunit'; + +import * as errorExports from '../errors'; +import * as publicExports from '../index'; +import * as internalExports from '../internal'; +import * as jwtExports from '../jwt'; + +export default (QUnit: QUnit) => { + const { module, test } = QUnit; + + module('public exports', () => { + test('should not include a breaking change', assert => { + const exportedApiKeys = ['createClerkClient', 'verifyToken']; + assert.deepEqual(Object.keys(publicExports).sort(), exportedApiKeys); + }); + }); + + module('subpath /errors exports', () => { + test('should not include a breaking change', assert => { + const exportedApiKeys = [ + 'TokenVerificationError', + 'TokenVerificationErrorAction', + 'TokenVerificationErrorCode', + 'TokenVerificationErrorReason', + ]; + assert.deepEqual(Object.keys(errorExports).sort(), exportedApiKeys); + }); + }); + + module('subpath /internal exports', () => { + test('should not include a breaking change', assert => { + const exportedApiKeys = [ + 'AuthStatus', + 'buildRequestUrl', + 'constants', + 'createAuthenticateRequest', + 'createIsomorphicRequest', + 'debugRequestState', + 'makeAuthObjectSerializable', + 'prunePrivateMetadata', + 'redirect', + 'sanitizeAuthObject', + 'signedInAuthObject', + 'signedOutAuthObject', + ]; + assert.deepEqual(Object.keys(internalExports).sort(), exportedApiKeys); + }); + }); + + module('subpath /jwt exports', () => { + test('should not include a breaking change', assert => { + const exportedApiKeys = ['decodeJwt', 'hasValidSignature', 'signJwt', 'verifyJwt']; + assert.deepEqual(Object.keys(jwtExports).sort(), exportedApiKeys); + }); + }); +}; diff --git a/packages/backend/src/redirections.test.ts b/packages/backend/src/__tests__/redirections.test.ts similarity index 99% rename from packages/backend/src/redirections.test.ts rename to packages/backend/src/__tests__/redirections.test.ts index 0085781c7fe..d0054cca6fa 100644 --- a/packages/backend/src/redirections.test.ts +++ b/packages/backend/src/__tests__/redirections.test.ts @@ -1,7 +1,7 @@ import type QUnit from 'qunit'; import sinon from 'sinon'; -import { redirect } from './redirections'; +import { redirect } from '../redirections'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/utils.test.ts b/packages/backend/src/__tests__/utils.test.ts similarity index 98% rename from packages/backend/src/utils.test.ts rename to packages/backend/src/__tests__/utils.test.ts index d76615d66a6..de8e53dd281 100644 --- a/packages/backend/src/utils.test.ts +++ b/packages/backend/src/__tests__/utils.test.ts @@ -1,6 +1,6 @@ import type QUnit from 'qunit'; -import { buildOrigin, buildRequestUrl } from './utils'; +import { buildOrigin, buildRequestUrl } from '../utils'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/api/factory.test.ts b/packages/backend/src/api/__tests__/factory.test.ts similarity index 96% rename from packages/backend/src/api/factory.test.ts rename to packages/backend/src/api/__tests__/factory.test.ts index b5e0612c35f..93ff7b29add 100644 --- a/packages/backend/src/api/factory.test.ts +++ b/packages/backend/src/api/__tests__/factory.test.ts @@ -1,12 +1,20 @@ import type QUnit from 'qunit'; import sinon from 'sinon'; -import emailJson from '../fixtures/responses/email.json'; -import userJson from '../fixtures/responses/user.json'; -import runtime from '../runtime'; -import { assertErrorResponse, assertResponse } from '../util/assertResponse'; -import { jsonError, jsonNotOk, jsonOk, jsonPaginatedOk } from '../util/mockFetch'; -import { createBackendApiClient } from './factory'; +// @ts-ignore +import emailJson from '../../fixtures/email.json'; +// @ts-ignore +import userJson from '../../fixtures/user.json'; +import runtime from '../../runtime'; +import { + assertErrorResponse, + assertResponse, + jsonError, + jsonNotOk, + jsonOk, + jsonPaginatedOk, +} from '../../util/testUtils'; +import { createBackendApiClient } from '../factory'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/api/resources/index.ts b/packages/backend/src/api/resources/index.ts index 936494c56eb..1ec010007d5 100644 --- a/packages/backend/src/api/resources/index.ts +++ b/packages/backend/src/api/resources/index.ts @@ -1,7 +1,6 @@ export * from './AllowlistIdentifier'; export * from './Client'; export * from './DeletedObject'; -export * from './Deserializer'; export * from './Email'; export * from './EmailAddress'; diff --git a/packages/backend/src/tokens/errors.ts b/packages/backend/src/errors.ts similarity index 100% rename from packages/backend/src/tokens/errors.ts rename to packages/backend/src/errors.ts diff --git a/packages/backend/src/exports.test.ts b/packages/backend/src/exports.test.ts deleted file mode 100644 index 97bed0993d5..00000000000 --- a/packages/backend/src/exports.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import type QUnit from 'qunit'; - -import * as publicExports from './index'; - -export default (QUnit: QUnit) => { - const { module, test } = QUnit; - - module('public exports', () => { - test('should not include a breaking change', assert => { - const exportedApiKeys = [ - 'AllowlistIdentifier', - 'AuthStatus', - 'Client', - 'DeletedObject', - 'Email', - 'EmailAddress', - 'ExternalAccount', - 'IdentificationLink', - 'Invitation', - 'OauthAccessToken', - 'ObjectType', - 'Organization', - 'OrganizationInvitation', - 'OrganizationMembership', - 'OrganizationMembershipPublicUserData', - 'PhoneNumber', - 'RedirectUrl', - 'SMSMessage', - 'Session', - 'SignInToken', - 'Token', - 'TokenVerificationError', - 'TokenVerificationErrorReason', - 'User', - 'Verification', - 'buildRequestUrl', - 'constants', - 'createAuthenticateRequest', - 'createClerkClient', - 'createIsomorphicRequest', - 'debugRequestState', - 'decodeJwt', - 'deserialize', - 'hasValidSignature', - 'makeAuthObjectSerializable', - 'prunePrivateMetadata', - 'redirect', - 'sanitizeAuthObject', - 'signJwt', - 'signedInAuthObject', - 'signedOutAuthObject', - 'verifyJwt', - 'verifyToken', - ]; - assert.deepEqual(Object.keys(publicExports).sort(), exportedApiKeys); - }); - }); -}; diff --git a/packages/backend/src/fixtures/responses/email.json b/packages/backend/src/fixtures/email.json similarity index 100% rename from packages/backend/src/fixtures/responses/email.json rename to packages/backend/src/fixtures/email.json diff --git a/packages/backend/src/tokens/fixtures.ts b/packages/backend/src/fixtures/index.ts similarity index 100% rename from packages/backend/src/tokens/fixtures.ts rename to packages/backend/src/fixtures/index.ts diff --git a/packages/backend/src/fixtures/responses/user.json b/packages/backend/src/fixtures/user.json similarity index 100% rename from packages/backend/src/fixtures/responses/user.json rename to packages/backend/src/fixtures/user.json diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index 4b1bcafe9c5..2feccea049a 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -2,20 +2,14 @@ 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'; +import type { CreateAuthenticateRequestOptions } from './tokens/factory'; +import { createAuthenticateRequest } from './tokens/factory'; -export { createIsomorphicRequest } from './util/IsomorphicRequest'; - -export * from './api/resources'; -export * from './tokens'; -export * from './tokens/jwt'; -export * from './tokens/verify'; -export { constants } from './constants'; -export { redirect } from './redirections'; -export { buildRequestUrl } from './utils'; +export type { Organization, Session, User } from './api/resources'; +export type { VerifyTokenOptions } from './tokens/verify'; +export { verifyToken } from './tokens/verify'; export type ClerkOptions = CreateBackendApiOptions & Partial< @@ -25,7 +19,14 @@ export type ClerkOptions = CreateBackendApiOptions & > > & { sdkMetadata?: SDKMetadata; telemetry?: Pick }; -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 = { + telemetry: TelemetryCollector; +} & ApiClient & + ReturnType; + +export function createClerkClient(options: ClerkOptions): ClerkClient { const opts = { ...options }; const apiClient = createBackendApiClient(opts); const requestState = createAuthenticateRequest({ options: opts, apiClient }); diff --git a/packages/backend/src/internal.ts b/packages/backend/src/internal.ts new file mode 100644 index 00000000000..7327bfe5a22 --- /dev/null +++ b/packages/backend/src/internal.ts @@ -0,0 +1,28 @@ +export { constants } from './constants'; +export { redirect } from './redirections'; +export { buildRequestUrl } from './utils'; + +export type { CreateAuthenticateRequestOptions } from './tokens/factory'; +export { createAuthenticateRequest } from './tokens/factory'; + +export { debugRequestState } from './tokens/request'; + +export type { AuthenticateRequestOptions, OptionalVerifyTokenOptions } from './tokens/request'; + +export type { + SignedInAuthObjectOptions, + SignedInAuthObject, + SignedOutAuthObject, + AuthObject, +} from './tokens/authObjects'; +export { + makeAuthObjectSerializable, + sanitizeAuthObject, + prunePrivateMetadata, + signedOutAuthObject, + signedInAuthObject, +} from './tokens/authObjects'; +export { createIsomorphicRequest } from './util/IsomorphicRequest'; + +export { AuthStatus } from './tokens/authStatus'; +export type { RequestState } from './tokens/authStatus'; diff --git a/packages/backend/src/tokens/jwt/assertions.test.ts b/packages/backend/src/jwt/__tests__/assertions.test.ts similarity index 99% rename from packages/backend/src/tokens/jwt/assertions.test.ts rename to packages/backend/src/jwt/__tests__/assertions.test.ts index 97296209867..d4c27350d1a 100644 --- a/packages/backend/src/tokens/jwt/assertions.test.ts +++ b/packages/backend/src/jwt/__tests__/assertions.test.ts @@ -10,7 +10,7 @@ import { assertHeaderType, assertIssuedAtClaim, assertSubClaim, -} from './assertions'; +} from '../assertions'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/tokens/jwt/cryptoKeys.test.ts b/packages/backend/src/jwt/__tests__/cryptoKeys.test.ts similarity index 95% rename from packages/backend/src/tokens/jwt/cryptoKeys.test.ts rename to packages/backend/src/jwt/__tests__/cryptoKeys.test.ts index ad707d3c1f6..3662cd70ef8 100644 --- a/packages/backend/src/tokens/jwt/cryptoKeys.test.ts +++ b/packages/backend/src/jwt/__tests__/cryptoKeys.test.ts @@ -1,7 +1,7 @@ import type QUnit from 'qunit'; -import { pemEncodedPublicKey, pemEncodedSignKey, publicJwks, signingJwks } from '../fixtures'; -import { importKey } from './cryptoKeys'; +import { pemEncodedPublicKey, pemEncodedSignKey, publicJwks, signingJwks } from '../../fixtures'; +import { importKey } from '../cryptoKeys'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/tokens/jwt/signJwt.test.ts b/packages/backend/src/jwt/__tests__/signJwt.test.ts similarity index 91% rename from packages/backend/src/tokens/jwt/signJwt.test.ts rename to packages/backend/src/jwt/__tests__/signJwt.test.ts index 36c7db01f7e..22fa071cd3b 100644 --- a/packages/backend/src/tokens/jwt/signJwt.test.ts +++ b/packages/backend/src/jwt/__tests__/signJwt.test.ts @@ -8,9 +8,9 @@ import { pemEncodedSignKey, publicJwks, signingJwks, -} from '../fixtures'; -import { signJwt } from './signJwt'; -import { verifyJwt } from './verifyJwt'; +} from '../../fixtures'; +import { signJwt } from '../signJwt'; +import { verifyJwt } from '../verifyJwt'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/tokens/jwt/verifyJwt.test.ts b/packages/backend/src/jwt/__tests__/verifyJwt.test.ts similarity index 97% rename from packages/backend/src/tokens/jwt/verifyJwt.test.ts rename to packages/backend/src/jwt/__tests__/verifyJwt.test.ts index 8777cb655c1..39c9e9007f2 100644 --- a/packages/backend/src/tokens/jwt/verifyJwt.test.ts +++ b/packages/backend/src/jwt/__tests__/verifyJwt.test.ts @@ -10,8 +10,8 @@ import { publicJwks, signedJwt, someOtherPublicKey, -} from '../fixtures'; -import { decodeJwt, hasValidSignature, verifyJwt } from './verifyJwt'; +} from '../../fixtures'; +import { decodeJwt, hasValidSignature, verifyJwt } from '../verifyJwt'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/tokens/jwt/algorithms.ts b/packages/backend/src/jwt/algorithms.ts similarity index 100% rename from packages/backend/src/tokens/jwt/algorithms.ts rename to packages/backend/src/jwt/algorithms.ts diff --git a/packages/backend/src/tokens/jwt/assertions.ts b/packages/backend/src/jwt/assertions.ts similarity index 100% rename from packages/backend/src/tokens/jwt/assertions.ts rename to packages/backend/src/jwt/assertions.ts diff --git a/packages/backend/src/tokens/jwt/cryptoKeys.ts b/packages/backend/src/jwt/cryptoKeys.ts similarity index 96% rename from packages/backend/src/tokens/jwt/cryptoKeys.ts rename to packages/backend/src/jwt/cryptoKeys.ts index ae4e3caa1be..fa4200f6c44 100644 --- a/packages/backend/src/tokens/jwt/cryptoKeys.ts +++ b/packages/backend/src/jwt/cryptoKeys.ts @@ -1,6 +1,6 @@ import { isomorphicAtob } from '@clerk/shared/isomorphicAtob'; -import runtime from '../../runtime'; +import runtime from '../runtime'; // https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#pkcs_8_import function pemToBuffer(secret: string): ArrayBuffer { diff --git a/packages/backend/src/tokens/jwt/index.ts b/packages/backend/src/jwt/index.ts similarity index 100% rename from packages/backend/src/tokens/jwt/index.ts rename to packages/backend/src/jwt/index.ts diff --git a/packages/backend/src/tokens/jwt/signJwt.ts b/packages/backend/src/jwt/signJwt.ts similarity index 95% rename from packages/backend/src/tokens/jwt/signJwt.ts rename to packages/backend/src/jwt/signJwt.ts index 25d2ac08cfa..5f3d2f8ef44 100644 --- a/packages/backend/src/tokens/jwt/signJwt.ts +++ b/packages/backend/src/jwt/signJwt.ts @@ -1,5 +1,5 @@ -import runtime from '../../runtime'; -import { base64url } from '../../util/rfc4648'; +import runtime from '../runtime'; +import { base64url } from '../util/rfc4648'; import { getCryptoAlgorithm } from './algorithms'; import { importKey } from './cryptoKeys'; diff --git a/packages/backend/src/tokens/jwt/verifyJwt.ts b/packages/backend/src/jwt/verifyJwt.ts similarity index 98% rename from packages/backend/src/tokens/jwt/verifyJwt.ts rename to packages/backend/src/jwt/verifyJwt.ts index a0b4d218082..8e0dc3a81bb 100644 --- a/packages/backend/src/tokens/jwt/verifyJwt.ts +++ b/packages/backend/src/jwt/verifyJwt.ts @@ -1,10 +1,10 @@ import type { Jwt, JwtPayload } from '@clerk/types'; +import { TokenVerificationError, TokenVerificationErrorAction, TokenVerificationErrorReason } from '../errors'; // DO NOT CHANGE: Runtime needs to be imported as a default export so that we can stub its dependencies with Sinon.js // For more information refer to https://sinonjs.org/how-to/stub-dependency/ -import runtime from '../../runtime'; -import { base64url } from '../../util/rfc4648'; -import { TokenVerificationError, TokenVerificationErrorAction, TokenVerificationErrorReason } from '../errors'; +import runtime from '../runtime'; +import { base64url } from '../util/rfc4648'; import { getCryptoAlgorithm } from './algorithms'; import { assertActivationClaim, diff --git a/packages/backend/src/runtime/index.ts b/packages/backend/src/runtime.ts similarity index 88% rename from packages/backend/src/runtime/index.ts rename to packages/backend/src/runtime.ts index 8de0004e8a2..0c0b28d9f27 100644 --- a/packages/backend/src/runtime/index.ts +++ b/packages/backend/src/runtime.ts @@ -11,12 +11,18 @@ * * TODO: Support TS runtime modules */ - -// @ts-ignore - These are package subpaths -import crypto from '#crypto'; +let webcrypto; +try { + webcrypto = require('node:crypto'); + if (!webcrypto) { + webcrypto = globalThis.crypto; + } +} catch (e) { + webcrypto = globalThis.crypto; +} type Runtime = { - crypto: Crypto; + crypto: typeof webcrypto; fetch: typeof globalThis.fetch; AbortController: typeof globalThis.AbortController; Blob: typeof globalThis.Blob; @@ -36,7 +42,7 @@ const globalFetch = fetch.bind(globalThis); // DO NOT CHANGE: Runtime needs to be imported as a default export so that we can stub its dependencies with Sinon.js // For more information refer to https://sinonjs.org/how-to/stub-dependency/ const runtime: Runtime = { - crypto, + crypto: webcrypto, fetch: globalFetch, AbortController: globalThis.AbortController, Blob: globalThis.Blob, diff --git a/packages/backend/src/runtime/browser/crypto.mjs b/packages/backend/src/runtime/browser/crypto.mjs deleted file mode 100644 index fe98f115451..00000000000 --- a/packages/backend/src/runtime/browser/crypto.mjs +++ /dev/null @@ -1 +0,0 @@ -export default crypto; diff --git a/packages/backend/src/runtime/node/crypto.js b/packages/backend/src/runtime/node/crypto.js deleted file mode 100644 index e192b979353..00000000000 --- a/packages/backend/src/runtime/node/crypto.js +++ /dev/null @@ -1,11 +0,0 @@ -let webcrypto; -try { - webcrypto = require('node:crypto').webcrypto; - if (!webcrypto) { - webcrypto = global.crypto; - } -} catch (e) { - webcrypto = global.crypto; -} - -module.exports = webcrypto; diff --git a/packages/backend/src/tokens/authObjects.test.ts b/packages/backend/src/tokens/__tests__/authObjects.test.ts similarity index 96% rename from packages/backend/src/tokens/authObjects.test.ts rename to packages/backend/src/tokens/__tests__/authObjects.test.ts index 0f29fbefcc8..039276bf061 100644 --- a/packages/backend/src/tokens/authObjects.test.ts +++ b/packages/backend/src/tokens/__tests__/authObjects.test.ts @@ -1,6 +1,6 @@ import type QUnit from 'qunit'; -import { makeAuthObjectSerializable, signedOutAuthObject } from './authObjects'; +import { makeAuthObjectSerializable, signedOutAuthObject } from '../authObjects'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/tokens/factory.test.ts b/packages/backend/src/tokens/__tests__/factory.test.ts similarity index 96% rename from packages/backend/src/tokens/factory.test.ts rename to packages/backend/src/tokens/__tests__/factory.test.ts index 91831161076..63c25c79589 100644 --- a/packages/backend/src/tokens/factory.test.ts +++ b/packages/backend/src/tokens/__tests__/factory.test.ts @@ -1,7 +1,7 @@ import type QUnit from 'qunit'; -import type { ApiClient } from '../api'; -import { createAuthenticateRequest } from './factory'; +import type { ApiClient } from '../../api'; +import { createAuthenticateRequest } from '../factory'; const TEST_PK = 'pk_test_Y2xlcmsuaW5jbHVkZWQua2F0eWRpZC05Mi5sY2wuZGV2JA'; diff --git a/packages/backend/src/tokens/keys.test.ts b/packages/backend/src/tokens/__tests__/keys.test.ts similarity index 95% rename from packages/backend/src/tokens/keys.test.ts rename to packages/backend/src/tokens/__tests__/keys.test.ts index 682d95d7cf1..e1e161d5b5e 100644 --- a/packages/backend/src/tokens/keys.test.ts +++ b/packages/backend/src/tokens/__tests__/keys.test.ts @@ -1,11 +1,19 @@ import type QUnit from 'qunit'; import sinon from 'sinon'; -import runtime from '../runtime'; -import { jsonError, jsonOk } from '../util/mockFetch'; -import { TokenVerificationError, TokenVerificationErrorAction, TokenVerificationErrorReason } from './errors'; -import { mockJwks, mockJwtPayload, mockPEMJwk, mockPEMJwtKey, mockPEMKey, mockRsaJwk, mockRsaJwkKid } from './fixtures'; -import { loadClerkJWKFromLocal, loadClerkJWKFromRemote } from './keys'; +import { TokenVerificationError, TokenVerificationErrorAction, TokenVerificationErrorReason } from '../../errors'; +import { + mockJwks, + mockJwtPayload, + mockPEMJwk, + mockPEMJwtKey, + mockPEMKey, + mockRsaJwk, + mockRsaJwkKid, +} from '../../fixtures'; +import runtime from '../../runtime'; +import { jsonError, jsonOk } from '../../util/testUtils'; +import { loadClerkJWKFromLocal, loadClerkJWKFromRemote } from '../keys'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/tokens/request.test.ts b/packages/backend/src/tokens/__tests__/request.test.ts similarity index 97% rename from packages/backend/src/tokens/request.test.ts rename to packages/backend/src/tokens/__tests__/request.test.ts index 66dc24b3e36..4926c43adfd 100644 --- a/packages/backend/src/tokens/request.test.ts +++ b/packages/backend/src/tokens/__tests__/request.test.ts @@ -1,13 +1,13 @@ import type QUnit from 'qunit'; import sinon from 'sinon'; -import runtime from '../runtime'; -import { jsonOk } from '../util/mockFetch'; -import { AuthErrorReason, type AuthReason, AuthStatus, type RequestState } from './authStatus'; -import { TokenVerificationErrorReason } from './errors'; -import { mockInvalidSignatureJwt, mockJwks, mockJwt, mockJwtPayload, mockMalformedJwt } from './fixtures'; -import type { AuthenticateRequestOptions } from './request'; -import { authenticateRequest, loadOptionsFromHeaders } from './request'; +import { TokenVerificationErrorReason } from '../../errors'; +import { mockInvalidSignatureJwt, mockJwks, mockJwt, mockJwtPayload, mockMalformedJwt } from '../../fixtures'; +import runtime from '../../runtime'; +import { jsonOk } from '../../util/testUtils'; +import { AuthErrorReason, type AuthReason, AuthStatus, type RequestState } from '../authStatus'; +import type { AuthenticateRequestOptions } from '../request'; +import { authenticateRequest, loadOptionsFromHeaders } from '../request'; function assertSignedOut( assert, @@ -181,12 +181,8 @@ export default (QUnit: QUnit) => { test('returns signed out state if jwk fails to load from remote', async assert => { fakeFetch.onCall(0).returns(jsonOk({})); - const requestState = await authenticateRequest( - mockRequestWithHeaderAuth(), - mockOptions({ - skipJwksCache: false, - }), - ); + + const requestState = await authenticateRequest(mockRequestWithHeaderAuth(), mockOptions()); const errMessage = 'The JWKS endpoint did not contain any signing keys. Contact support@clerk.com. Contact support@clerk.com (reason=jwk-remote-failed-to-load, token-carrier=header)'; diff --git a/packages/backend/src/tokens/verify.test.ts b/packages/backend/src/tokens/__tests__/verify.test.ts similarity index 89% rename from packages/backend/src/tokens/verify.test.ts rename to packages/backend/src/tokens/__tests__/verify.test.ts index c9d89e279a3..bd32177b7c9 100644 --- a/packages/backend/src/tokens/verify.test.ts +++ b/packages/backend/src/tokens/__tests__/verify.test.ts @@ -1,10 +1,10 @@ import type QUnit from 'qunit'; import sinon from 'sinon'; -import runtime from '../runtime'; -import { jsonOk } from '../util/mockFetch'; -import { mockJwks, mockJwt, mockJwtPayload } from './fixtures'; -import { verifyToken } from './verify'; +import { mockJwks, mockJwt, mockJwtPayload } from '../../fixtures'; +import runtime from '../../runtime'; +import { jsonOk } from '../../util/testUtils'; +import { verifyToken } from '../verify'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/tokens/authStatus.ts b/packages/backend/src/tokens/authStatus.ts index a44e67f3a94..37552107b33 100644 --- a/packages/backend/src/tokens/authStatus.ts +++ b/packages/backend/src/tokens/authStatus.ts @@ -1,9 +1,9 @@ import type { JwtPayload } from '@clerk/types'; import { createBackendApiClient } from '../api'; +import type { TokenVerificationErrorReason } from '../errors'; import type { SignedInAuthObject, SignedInAuthObjectOptions, SignedOutAuthObject } from './authObjects'; import { signedInAuthObject, signedOutAuthObject } from './authObjects'; -import type { TokenVerificationErrorReason } from './errors'; export enum AuthStatus { SignedIn = 'signed-in', diff --git a/packages/backend/src/tokens/handshake.ts b/packages/backend/src/tokens/handshake.ts index 5c867e4a804..1dfd8b41bb9 100644 --- a/packages/backend/src/tokens/handshake.ts +++ b/packages/backend/src/tokens/handshake.ts @@ -1,6 +1,7 @@ -import { TokenVerificationError, TokenVerificationErrorAction, TokenVerificationErrorReason } from './errors'; -import { decodeJwt, hasValidSignature, type VerifyJwtOptions } from './jwt'; -import { assertHeaderAlgorithm, assertHeaderType } from './jwt/assertions'; +import { TokenVerificationError, TokenVerificationErrorAction, TokenVerificationErrorReason } from '../errors'; +import type { VerifyJwtOptions } from '../jwt'; +import { decodeJwt, hasValidSignature } from '../jwt'; +import { assertHeaderAlgorithm, assertHeaderType } from '../jwt/assertions'; import { loadClerkJWKFromLocal, loadClerkJWKFromRemote } from './keys'; import type { VerifyTokenOptions } from './verify'; diff --git a/packages/backend/src/tokens/index.ts b/packages/backend/src/tokens/index.ts deleted file mode 100644 index 50642216e4b..00000000000 --- a/packages/backend/src/tokens/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -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'; diff --git a/packages/backend/src/tokens/keys.ts b/packages/backend/src/tokens/keys.ts index f6de7713b23..553da86f546 100644 --- a/packages/backend/src/tokens/keys.ts +++ b/packages/backend/src/tokens/keys.ts @@ -1,16 +1,16 @@ import { API_URL, API_VERSION, JWKS_CACHE_TTL_MS, MAX_CACHE_LAST_UPDATED_AT_SECONDS } from '../constants'; +import { + TokenVerificationError, + TokenVerificationErrorAction, + TokenVerificationErrorCode, + TokenVerificationErrorReason, +} from '../errors'; // DO NOT CHANGE: Runtime needs to be imported as a default export so that we can stub its dependencies with Sinon.js // For more information refer to https://sinonjs.org/how-to/stub-dependency/ import runtime from '../runtime'; import { joinPaths } from '../util/path'; import { getErrorObjectByCode } from '../util/request'; import { callWithRetry } from '../util/shared'; -import { - TokenVerificationError, - TokenVerificationErrorAction, - TokenVerificationErrorCode, - TokenVerificationErrorReason, -} from './errors'; type JsonWebKeyWithKid = JsonWebKey & { kid: string }; @@ -147,7 +147,10 @@ export async function loadClerkJWKFromRemote({ if (!jwk) { const cacheValues = getCacheValues(); - const jwkKeys = cacheValues.map(jwk => jwk.kid).join(', '); + const jwkKeys = cacheValues + .map(jwk => jwk.kid) + .sort() + .join(', '); throw new TokenVerificationError({ action: TokenVerificationErrorAction.ContactSupport, diff --git a/packages/backend/src/tokens/request.ts b/packages/backend/src/tokens/request.ts index fa65c36cf25..5b7ba05f322 100644 --- a/packages/backend/src/tokens/request.ts +++ b/packages/backend/src/tokens/request.ts @@ -2,15 +2,15 @@ import { parsePublishableKey } from '@clerk/shared/keys'; import type { JwtPayload } from '@clerk/types'; import { constants } from '../constants'; +import type { TokenCarrier } from '../errors'; +import { TokenVerificationError, TokenVerificationErrorReason } from '../errors'; +import { decodeJwt } from '../jwt'; import { assertValidSecretKey } from '../util/assertValidSecretKey'; import { buildRequest, stripAuthorizationHeader } from '../util/IsomorphicRequest'; import { isDevelopmentFromSecretKey } from '../util/shared'; import type { AuthStatusOptionsType, RequestState } from './authStatus'; import { AuthErrorReason, handshake, signedIn, signedOut } from './authStatus'; -import type { TokenCarrier } from './errors'; -import { TokenVerificationError, TokenVerificationErrorReason } from './errors'; import { verifyHandshakeToken } from './handshake'; -import { decodeJwt } from './jwt'; import { verifyToken, type VerifyTokenOptions } from './verify'; export type OptionalVerifyTokenOptions = Partial< diff --git a/packages/backend/src/tokens/verify.ts b/packages/backend/src/tokens/verify.ts index 9801ed30e42..90d1d716cc0 100644 --- a/packages/backend/src/tokens/verify.ts +++ b/packages/backend/src/tokens/verify.ts @@ -1,8 +1,8 @@ import type { JwtPayload } from '@clerk/types'; -import { TokenVerificationError, TokenVerificationErrorAction, TokenVerificationErrorReason } from './errors'; -import type { VerifyJwtOptions } from './jwt'; -import { decodeJwt, verifyJwt } from './jwt'; +import { TokenVerificationError, TokenVerificationErrorAction, TokenVerificationErrorReason } from '../errors'; +import type { VerifyJwtOptions } from '../jwt'; +import { decodeJwt, verifyJwt } from '../jwt'; import type { LoadClerkJWKFromRemoteOptions } from './keys'; import { loadClerkJWKFromLocal, loadClerkJWKFromRemote } from './keys'; diff --git a/packages/backend/src/util/path.test.ts b/packages/backend/src/util/__tests__/path.test.ts similarity index 88% rename from packages/backend/src/util/path.test.ts rename to packages/backend/src/util/__tests__/path.test.ts index 8ae7d9f95ae..ce632d73a82 100644 --- a/packages/backend/src/util/path.test.ts +++ b/packages/backend/src/util/__tests__/path.test.ts @@ -1,6 +1,6 @@ import type QUnit from 'qunit'; -import { joinPaths } from './path'; +import { joinPaths } from '../path'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/util/request.test.ts b/packages/backend/src/util/__tests__/request.test.ts similarity index 99% rename from packages/backend/src/util/request.test.ts rename to packages/backend/src/util/__tests__/request.test.ts index e24528685ee..8ef856e58ad 100644 --- a/packages/backend/src/util/request.test.ts +++ b/packages/backend/src/util/__tests__/request.test.ts @@ -1,6 +1,6 @@ import type QUnit from 'qunit'; -import { checkCrossOrigin } from './request'; +import { checkCrossOrigin } from '../request'; export default (QUnit: QUnit) => { const { module, test } = QUnit; diff --git a/packages/backend/src/util/assertResponse.ts b/packages/backend/src/util/assertResponse.ts deleted file mode 100644 index 8cdb760ff28..00000000000 --- a/packages/backend/src/util/assertResponse.ts +++ /dev/null @@ -1,9 +0,0 @@ -type ApiResponse = { data: T | null; errors: null | any[] }; -type SuccessApiResponse = { data: T; errors: null }; -type ErrorApiResponse = { data: null; errors: any[]; clerkTraceId: string; status: number; statusText: string }; -export function assertResponse(assert: Assert, resp: ApiResponse): asserts resp is SuccessApiResponse { - assert.equal(resp.errors, null); -} -export function assertErrorResponse(assert: Assert, resp: ApiResponse): asserts resp is ErrorApiResponse { - assert.notEqual(resp.errors, null); -} diff --git a/packages/backend/src/util/mockFetch.ts b/packages/backend/src/util/testUtils.ts similarity index 76% rename from packages/backend/src/util/mockFetch.ts rename to packages/backend/src/util/testUtils.ts index 8524a845fef..b12f26fcd7a 100644 --- a/packages/backend/src/util/mockFetch.ts +++ b/packages/backend/src/util/testUtils.ts @@ -1,5 +1,15 @@ import { constants } from '../constants'; +type ApiResponse = { data: T | null; errors: null | any[] }; +type SuccessApiResponse = { data: T; errors: null }; +type ErrorApiResponse = { data: null; errors: any[]; clerkTraceId: string; status: number; statusText: string }; +export function assertResponse(assert: Assert, resp: ApiResponse): asserts resp is SuccessApiResponse { + assert.equal(resp.errors, null); +} +export function assertErrorResponse(assert: Assert, resp: ApiResponse): asserts resp is ErrorApiResponse { + assert.notEqual(resp.errors, null); +} + export function jsonOk(body: unknown, status = 200) { // Mock response object that satisfies the window.Response interface const mockResponse = { diff --git a/packages/backend/tests/edge-runtime/run.mjs b/packages/backend/tests/edge-runtime/run.mjs index c46f836a4b2..108891c2e08 100644 --- a/packages/backend/tests/edge-runtime/run.mjs +++ b/packages/backend/tests/edge-runtime/run.mjs @@ -1,8 +1,9 @@ -import { EdgeRuntime } from 'edge-runtime'; -import { exit } from 'node:process'; import fs from 'node:fs'; -import * as url from 'url'; +import { exit } from 'node:process'; + +import { EdgeRuntime } from 'edge-runtime'; import * as path from 'path'; +import * as url from 'url'; const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); diff --git a/packages/backend/tests/suites.ts b/packages/backend/tests/suites.ts index c83309eedcc..cbb96ac9db2 100644 --- a/packages/backend/tests/suites.ts +++ b/packages/backend/tests/suites.ts @@ -1,38 +1,39 @@ // Import all suites // TODO: Automate this step using dynamic imports -import factoryTest from './dist/api/factory.test.js'; -import exportsTest from './dist/exports.test.js'; -import redirectTest from './dist/redirections.test.js'; -import authObjectsTest from './dist/tokens/authObjects.test.js'; -import tokenFactoryTest from './dist/tokens/factory.test.js'; -import jwtAssertionsTest from './dist/tokens/jwt/assertions.test.js'; -import cryptoKeysTest from './dist/tokens/jwt/cryptoKeys.test.js'; -import signJwtTest from './dist/tokens/jwt/signJwt.test.js'; -import verifyJwtTest from './dist/tokens/jwt/verifyJwt.test.js'; -import keysTest from './dist/tokens/keys.test.js'; -import requestTest from './dist/tokens/request.test.js'; -import verifyTest from './dist/tokens/verify.test.js'; -import pathTest from './dist/util/path.test.js'; -import utilRequestTest from './dist/util/request.test.js'; -import utilsTest from './dist/utils.test.js'; + +import exportsTest from './dist/__tests__/exports.test.js'; +import redirectTest from './dist/__tests__/redirections.test.js'; +import utilsTest from './dist/__tests__/utils.test.js'; +import factoryTest from './dist/api/__tests__/factory.test.js'; +import jwtAssertionsTest from './dist/jwt/__tests__/assertions.test.js'; +import cryptoKeysTest from './dist/jwt/__tests__/cryptoKeys.test.js'; +import signJwtTest from './dist/jwt/__tests__/signJwt.test.js'; +import verifyJwtTest from './dist/jwt/__tests__/verifyJwt.test.js'; +import authObjectsTest from './dist/tokens/__tests__/authObjects.test.js'; +import tokenFactoryTest from './dist/tokens/__tests__/factory.test.js'; +import keysTest from './dist/tokens/__tests__/keys.test.js'; +import requestTest from './dist/tokens/__tests__/request.test.js'; +import verifyTest from './dist/tokens/__tests__/verify.test.js'; +import pathTest from './dist/util/__tests__/path.test.js'; +import utilRequestTest from './dist/util/__tests__/request.test.js'; // Add them to the suite array const suites = [ authObjectsTest, + cryptoKeysTest, exportsTest, + factoryTest, jwtAssertionsTest, - requestTest, - utilRequestTest, keysTest, - verifyTest, pathTest, - verifyJwtTest, - signJwtTest, - cryptoKeysTest, - factoryTest, redirectTest, - utilsTest, + requestTest, + signJwtTest, tokenFactoryTest, + utilRequestTest, + utilsTest, + verifyJwtTest, + verifyTest, ]; export default suites; diff --git a/packages/backend/tsconfig.declarations.json b/packages/backend/tsconfig.declarations.json index c42a5efd18e..4a7735336e2 100644 --- a/packages/backend/tsconfig.declarations.json +++ b/packages/backend/tsconfig.declarations.json @@ -7,6 +7,6 @@ "emitDeclarationOnly": true, "declarationMap": true, "sourceMap": false, - "declarationDir": "./dist/types" + "declarationDir": "./dist" } } diff --git a/packages/backend/tsconfig.json b/packages/backend/tsconfig.json index 6c79dfa9a5b..e93e0bf52d4 100644 --- a/packages/backend/tsconfig.json +++ b/packages/backend/tsconfig.json @@ -22,5 +22,5 @@ "isolatedModules": true }, "include": ["src"], - "exclude": ["node_modules", "dist", "/src/runtime/*", "src/**/*.spec.ts", "src/**/*.test.ts", "src/tests"] + "exclude": ["node_modules", "dist", "/src/runtime/*", "src/**/__tests__/*.test.ts", "src/tests"] } diff --git a/packages/backend/tsconfig.test.json b/packages/backend/tsconfig.test.json index c1959296aa0..8c600f20dd7 100644 --- a/packages/backend/tsconfig.test.json +++ b/packages/backend/tsconfig.test.json @@ -12,6 +12,6 @@ "@clerk/shared/*": ["../shared/dist/*.js"] } }, - "include": ["src/**/*.test.ts"], - "exclude": ["node_modules", "dist", "src/__tests__"] + "include": ["src/**/__tests__"], + "exclude": ["node_modules", "dist"] } diff --git a/packages/backend/tsup.config.ts b/packages/backend/tsup.config.ts index 294370b7aff..4e21d2e0d22 100644 --- a/packages/backend/tsup.config.ts +++ b/packages/backend/tsup.config.ts @@ -10,7 +10,7 @@ export default defineConfig(overrideOptions => { const shouldPublish = !!overrideOptions.env?.publish; const common: Options = { - entry: ['src/index.ts'], + entry: ['src/index.ts', 'src/errors.ts', 'src/internal.ts', 'src/jwt/index.ts'], onSuccess: `cpy 'src/runtime/**/*.{mjs,js,cjs}' dist/runtime`, sourcemap: true, define: { @@ -18,8 +18,6 @@ export default defineConfig(overrideOptions => { PACKAGE_VERSION: `"${version}"`, __DEV__: `${isWatch}`, }, - external: ['#crypto'], - legacyOutput: true, bundle: true, clean: true, minify: false, diff --git a/packages/fastify/src/constants.ts b/packages/fastify/src/constants.ts index 725f748d28e..1f0b27991ac 100644 --- a/packages/fastify/src/constants.ts +++ b/packages/fastify/src/constants.ts @@ -1,4 +1,4 @@ -import { constants } from '@clerk/backend'; +import { constants } from '@clerk/backend/internal'; import { apiUrlFromPublishableKey } from '@clerk/shared/apiUrlFromPublishableKey'; export const API_VERSION = process.env.CLERK_API_VERSION || 'v1'; diff --git a/packages/fastify/src/getAuth.ts b/packages/fastify/src/getAuth.ts index 7acb04aefc2..1b6c24138ef 100644 --- a/packages/fastify/src/getAuth.ts +++ b/packages/fastify/src/getAuth.ts @@ -1,4 +1,4 @@ -import type { AuthObject } from '@clerk/backend'; +import type { AuthObject } from '@clerk/backend/internal'; import type { FastifyRequest } from 'fastify'; import { pluginRegistrationRequired } from './errors'; diff --git a/packages/fastify/src/withClerkMiddleware.ts b/packages/fastify/src/withClerkMiddleware.ts index c3fe1c1ade5..0a2c94a2ea8 100644 --- a/packages/fastify/src/withClerkMiddleware.ts +++ b/packages/fastify/src/withClerkMiddleware.ts @@ -1,4 +1,4 @@ -import { AuthStatus } from '@clerk/backend'; +import { AuthStatus } from '@clerk/backend/internal'; import type { FastifyRequest } from 'fastify'; import { clerkClient } from './clerkClient'; diff --git a/packages/gatsby-plugin-clerk/src/ssr/types.ts b/packages/gatsby-plugin-clerk/src/ssr/types.ts index aad0a2f6d5b..f823ca971b6 100644 --- a/packages/gatsby-plugin-clerk/src/ssr/types.ts +++ b/packages/gatsby-plugin-clerk/src/ssr/types.ts @@ -1,4 +1,5 @@ -import type { AuthenticateRequestOptions, AuthObject, Organization, Session, User } from '@clerk/backend'; +import type { Organization, Session, User } from '@clerk/backend'; +import type { AuthenticateRequestOptions, AuthObject } from '@clerk/backend/internal'; import type { GetServerDataProps } from 'gatsby'; export type WithServerAuthResult = (props: GetServerDataProps) => Promise>; diff --git a/packages/gatsby-plugin-clerk/src/ssr/utils.ts b/packages/gatsby-plugin-clerk/src/ssr/utils.ts index fed608ad9ff..575cbc82c9a 100644 --- a/packages/gatsby-plugin-clerk/src/ssr/utils.ts +++ b/packages/gatsby-plugin-clerk/src/ssr/utils.ts @@ -1,10 +1,9 @@ -import type { AuthObject } from '@clerk/backend'; -import { prunePrivateMetadata } from '@clerk/backend'; +import type { AuthObject } from '@clerk/backend/internal'; +import { constants, prunePrivateMetadata } from '@clerk/backend/internal'; import cookie from 'cookie'; import type { GetServerDataProps } from 'gatsby'; import { SECRET_KEY } from '../constants'; -import { constants } from './clerkClient'; /** * @internal diff --git a/packages/gatsby-plugin-clerk/src/ssr/withServerAuth.ts b/packages/gatsby-plugin-clerk/src/ssr/withServerAuth.ts index f69e290ddde..eb5e5948ce6 100644 --- a/packages/gatsby-plugin-clerk/src/ssr/withServerAuth.ts +++ b/packages/gatsby-plugin-clerk/src/ssr/withServerAuth.ts @@ -1,4 +1,4 @@ -import { AuthStatus } from '@clerk/backend'; +import { AuthStatus } from '@clerk/backend/internal'; import type { GetServerDataProps, GetServerDataReturn } from 'gatsby'; import { PUBLISHABLE_KEY, SECRET_KEY } from '../constants'; diff --git a/packages/nextjs/src/app-router/server/auth.ts b/packages/nextjs/src/app-router/server/auth.ts index d3f3f21579f..6d0d4df10ac 100644 --- a/packages/nextjs/src/app-router/server/auth.ts +++ b/packages/nextjs/src/app-router/server/auth.ts @@ -1,4 +1,4 @@ -import type { SignedInAuthObject, SignedOutAuthObject } from '@clerk/backend'; +import type { SignedInAuthObject, SignedOutAuthObject } from '@clerk/backend/internal'; import type { CheckAuthorizationParamsWithCustomPermissions, CheckAuthorizationWithCustomPermissions, diff --git a/packages/nextjs/src/server/__tests__/__snapshots__/exports.test.ts.snap b/packages/nextjs/src/server/__tests__/__snapshots__/exports.test.ts.snap index f14079b5887..17c471ccec7 100644 --- a/packages/nextjs/src/server/__tests__/__snapshots__/exports.test.ts.snap +++ b/packages/nextjs/src/server/__tests__/__snapshots__/exports.test.ts.snap @@ -2,56 +2,15 @@ exports[`/server public exports should not include a breaking change 1`] = ` [ - "AllowlistIdentifier", - "AuthStatus", - "Client", - "DeletedObject", - "Email", - "EmailAddress", - "ExternalAccount", - "IdentificationLink", - "Invitation", - "OauthAccessToken", - "ObjectType", - "Organization", - "OrganizationInvitation", - "OrganizationMembership", - "OrganizationMembershipPublicUserData", - "PhoneNumber", - "RedirectUrl", - "SMSMessage", - "Session", - "SignInToken", - "Token", - "TokenVerificationError", - "TokenVerificationErrorReason", - "User", - "Verification", "auth", "authMiddleware", "buildClerkProps", - "buildRequestUrl", "clerkClient", - "constants", - "createAuthenticateRequest", "createClerkClient", - "createIsomorphicRequest", "currentUser", - "debugRequestState", - "decodeJwt", - "deserialize", "getAuth", - "hasValidSignature", - "makeAuthObjectSerializable", - "prunePrivateMetadata", - "redirect", "redirectToSignIn", "redirectToSignUp", - "sanitizeAuthObject", - "signJwt", - "signedInAuthObject", - "signedOutAuthObject", - "verifyJwt", "verifyToken", ] `; diff --git a/packages/nextjs/src/server/authMiddleware.test.ts b/packages/nextjs/src/server/authMiddleware.test.ts index ee6f08de283..1e6559c654a 100644 --- a/packages/nextjs/src/server/authMiddleware.test.ts +++ b/packages/nextjs/src/server/authMiddleware.test.ts @@ -1,6 +1,6 @@ // There is no need to execute the complete authenticateRequest to test authMiddleware // This mock SHOULD exist before the import of authenticateRequest -import { AuthStatus } from '@clerk/backend'; +import { AuthStatus } from '@clerk/backend/internal'; import { expectTypeOf } from 'expect-type'; import { NextURL } from 'next/dist/server/web/next-url'; import type { NextFetchEvent, NextRequest } from 'next/server'; diff --git a/packages/nextjs/src/server/authMiddleware.ts b/packages/nextjs/src/server/authMiddleware.ts index b2a8474a275..c89fcbeebb9 100644 --- a/packages/nextjs/src/server/authMiddleware.ts +++ b/packages/nextjs/src/server/authMiddleware.ts @@ -1,5 +1,5 @@ -import type { AuthenticateRequestOptions, AuthObject } from '@clerk/backend'; -import { AuthStatus, buildRequestUrl, constants } from '@clerk/backend'; +import type { AuthenticateRequestOptions, AuthObject } from '@clerk/backend/internal'; +import { AuthStatus, buildRequestUrl, constants } from '@clerk/backend/internal'; import { DEV_BROWSER_JWT_MARKER, setDevBrowserJWTInURL } from '@clerk/shared/devBrowser'; import { isDevelopmentFromSecretKey } from '@clerk/shared/keys'; import { eventMethodCalled } from '@clerk/shared/telemetry'; diff --git a/packages/nextjs/src/server/getAuth.ts b/packages/nextjs/src/server/getAuth.ts index f6deeeee0d1..9f372fde0ce 100644 --- a/packages/nextjs/src/server/getAuth.ts +++ b/packages/nextjs/src/server/getAuth.ts @@ -1,13 +1,14 @@ -import type { Organization, Session, SignedInAuthObject, SignedOutAuthObject, User } from '@clerk/backend'; +import type { Organization, Session, User } from '@clerk/backend'; +import type { SignedInAuthObject, SignedOutAuthObject } from '@clerk/backend/internal'; import { AuthStatus, constants, - decodeJwt, makeAuthObjectSerializable, sanitizeAuthObject, signedInAuthObject, signedOutAuthObject, -} from '@clerk/backend'; +} from '@clerk/backend/internal'; +import { decodeJwt } from '@clerk/backend/jwt'; import { withLogger } from '../utils/debugLogger'; import { API_URL, API_VERSION, SECRET_KEY } from './constants'; diff --git a/packages/nextjs/src/server/redirect.ts b/packages/nextjs/src/server/redirect.ts index cc955aa5d37..46d76740d4c 100644 --- a/packages/nextjs/src/server/redirect.ts +++ b/packages/nextjs/src/server/redirect.ts @@ -1,4 +1,4 @@ -import { constants, redirect } from '@clerk/backend'; +import { constants, redirect } from '@clerk/backend/internal'; import { NextResponse } from 'next/server'; import { setHeader } from '../utils'; diff --git a/packages/nextjs/src/server/types.ts b/packages/nextjs/src/server/types.ts index b960002590d..767e0ac73d3 100644 --- a/packages/nextjs/src/server/types.ts +++ b/packages/nextjs/src/server/types.ts @@ -1,4 +1,4 @@ -import type { AuthObject, OptionalVerifyTokenOptions } from '@clerk/backend'; +import type { AuthObject, OptionalVerifyTokenOptions } from '@clerk/backend/internal'; import type { MultiDomainAndOrProxy } from '@clerk/types'; import type { IncomingMessage } from 'http'; import type { NextApiRequest } from 'next'; diff --git a/packages/nextjs/src/server/utils.ts b/packages/nextjs/src/server/utils.ts index 6f244db5963..4cc1e388cc9 100644 --- a/packages/nextjs/src/server/utils.ts +++ b/packages/nextjs/src/server/utils.ts @@ -1,5 +1,5 @@ -import type { AuthenticateRequestOptions, RequestState } from '@clerk/backend'; -import { buildRequestUrl, constants } from '@clerk/backend'; +import type { AuthenticateRequestOptions, RequestState } from '@clerk/backend/internal'; +import { buildRequestUrl, constants } from '@clerk/backend/internal'; import { handleValueOrFn } from '@clerk/shared/handleValueOrFn'; import { isDevelopmentFromSecretKey } from '@clerk/shared/keys'; import { isHttpOrHttps } from '@clerk/shared/proxy'; diff --git a/packages/remix/src/ssr/authenticateRequest.ts b/packages/remix/src/ssr/authenticateRequest.ts index 51d203da2e1..1bf35a96245 100644 --- a/packages/remix/src/ssr/authenticateRequest.ts +++ b/packages/remix/src/ssr/authenticateRequest.ts @@ -1,5 +1,6 @@ -import type { RequestState } from '@clerk/backend'; -import { buildRequestUrl, createClerkClient } from '@clerk/backend'; +import { createClerkClient } from '@clerk/backend'; +import type { RequestState } from '@clerk/backend/internal'; +import { buildRequestUrl } from '@clerk/backend/internal'; import { apiUrlFromPublishableKey } from '@clerk/shared/apiUrlFromPublishableKey'; import { handleValueOrFn } from '@clerk/shared/handleValueOrFn'; import { isDevelopmentFromSecretKey } from '@clerk/shared/keys'; diff --git a/packages/remix/src/ssr/getAuth.ts b/packages/remix/src/ssr/getAuth.ts index 8871a5cb1fd..c13836b8c3c 100644 --- a/packages/remix/src/ssr/getAuth.ts +++ b/packages/remix/src/ssr/getAuth.ts @@ -1,4 +1,4 @@ -import { AuthStatus, sanitizeAuthObject } from '@clerk/backend'; +import { AuthStatus, sanitizeAuthObject } from '@clerk/backend/internal'; import { redirect } from '@remix-run/server-runtime'; import { noLoaderArgsPassedInGetAuth } from '../errors'; diff --git a/packages/remix/src/ssr/rootAuthLoader.ts b/packages/remix/src/ssr/rootAuthLoader.ts index f91094893aa..0e2753a2e02 100644 --- a/packages/remix/src/ssr/rootAuthLoader.ts +++ b/packages/remix/src/ssr/rootAuthLoader.ts @@ -1,4 +1,4 @@ -import { AuthStatus, sanitizeAuthObject } from '@clerk/backend'; +import { AuthStatus, sanitizeAuthObject } from '@clerk/backend/internal'; import type { defer } from '@remix-run/server-runtime'; import { redirect } from '@remix-run/server-runtime'; import { isDeferredData } from '@remix-run/server-runtime/dist/responses'; diff --git a/packages/remix/src/ssr/types.ts b/packages/remix/src/ssr/types.ts index ec2fd551abf..dc7b6c2f0aa 100644 --- a/packages/remix/src/ssr/types.ts +++ b/packages/remix/src/ssr/types.ts @@ -1,4 +1,5 @@ -import type { AuthObject, Organization, Session, User, VerifyTokenOptions } from '@clerk/backend'; +import type { Organization, Session, User, VerifyTokenOptions } from '@clerk/backend'; +import type { AuthObject } from '@clerk/backend/internal'; import type { MultiDomainAndOrProxy } from '@clerk/types'; import type { DataFunctionArgs, LoaderFunction } from '@remix-run/server-runtime'; diff --git a/packages/remix/src/ssr/utils.ts b/packages/remix/src/ssr/utils.ts index dd48b5c3d81..4273b42b808 100644 --- a/packages/remix/src/ssr/utils.ts +++ b/packages/remix/src/ssr/utils.ts @@ -1,5 +1,5 @@ -import type { AuthObject, RequestState } from '@clerk/backend'; -import { constants, debugRequestState } from '@clerk/backend'; +import type { AuthObject, RequestState } from '@clerk/backend/internal'; +import { constants, debugRequestState } from '@clerk/backend/internal'; import { isTruthy } from '@clerk/shared/underscore'; import type { AppLoadContext, defer } from '@remix-run/server-runtime'; import { json } from '@remix-run/server-runtime'; diff --git a/packages/sdk-node/src/__tests__/__snapshots__/exports.test.ts.snap b/packages/sdk-node/src/__tests__/__snapshots__/exports.test.ts.snap index f847f40c962..aa792c20c1f 100644 --- a/packages/sdk-node/src/__tests__/__snapshots__/exports.test.ts.snap +++ b/packages/sdk-node/src/__tests__/__snapshots__/exports.test.ts.snap @@ -2,64 +2,13 @@ exports[`module exports should not change unless explicitly set 1`] = ` [ - "AllowlistIdentifier", - "AuthStatus", "ClerkExpressRequireAuth", "ClerkExpressWithAuth", - "Client", - "DeletedObject", - "Email", - "EmailAddress", - "ExternalAccount", - "IdentificationLink", - "Invitation", - "OauthAccessToken", - "ObjectType", - "Organization", - "OrganizationInvitation", - "OrganizationMembership", - "OrganizationMembershipPublicUserData", - "PhoneNumber", - "RedirectUrl", - "SMSMessage", - "Session", - "SignInToken", - "Token", - "TokenVerificationError", - "TokenVerificationErrorReason", - "User", - "Verification", - "allowlistIdentifiers", - "buildRequestUrl", "clerkClient", - "clients", - "constants", - "createAuthenticateRequest", "createClerkClient", "createClerkExpressRequireAuth", "createClerkExpressWithAuth", - "createIsomorphicRequest", - "debugRequestState", - "decodeJwt", - "deserialize", - "domains", - "emailAddresses", - "emails", - "hasValidSignature", - "invitations", - "makeAuthObjectSerializable", - "organizations", - "phoneNumbers", - "prunePrivateMetadata", - "redirect", "requireAuth", - "sanitizeAuthObject", - "sessions", - "signJwt", - "signedInAuthObject", - "signedOutAuthObject", - "users", - "verifyJwt", "verifyToken", "withAuth", ] diff --git a/packages/sdk-node/src/__tests__/authenticateRequest.test.ts b/packages/sdk-node/src/__tests__/authenticateRequest.test.ts index 44b602357b3..1d1751d43e3 100644 --- a/packages/sdk-node/src/__tests__/authenticateRequest.test.ts +++ b/packages/sdk-node/src/__tests__/authenticateRequest.test.ts @@ -1,4 +1,4 @@ -import { constants } from '@clerk/backend'; +import { constants } from '@clerk/backend/internal'; import { Request } from 'express'; import { authenticateRequest } from '../authenticateRequest'; diff --git a/packages/sdk-node/src/__tests__/middleware.test.ts b/packages/sdk-node/src/__tests__/middleware.test.ts index 417148b7a26..74d7f7ca6ca 100644 --- a/packages/sdk-node/src/__tests__/middleware.test.ts +++ b/packages/sdk-node/src/__tests__/middleware.test.ts @@ -1,4 +1,4 @@ -import type { RequestState } from '@clerk/backend'; +import type { RequestState } from '@clerk/backend/internal'; import type { NextFunction, Request, Response } from 'express'; import { createClerkExpressRequireAuth } from '../clerkExpressRequireAuth'; diff --git a/packages/sdk-node/src/authenticateRequest.ts b/packages/sdk-node/src/authenticateRequest.ts index 17db4085c23..cc04de10970 100644 --- a/packages/sdk-node/src/authenticateRequest.ts +++ b/packages/sdk-node/src/authenticateRequest.ts @@ -1,5 +1,5 @@ -import type { RequestState } from '@clerk/backend'; -import { buildRequestUrl, constants } from '@clerk/backend'; +import type { RequestState } from '@clerk/backend/internal'; +import { buildRequestUrl, constants } from '@clerk/backend/internal'; import { handleValueOrFn } from '@clerk/shared/handleValueOrFn'; import { isDevelopmentFromSecretKey } from '@clerk/shared/keys'; import { isHttpOrHttps, isProxyUrlRelative, isValidProxyUrl } from '@clerk/shared/proxy'; diff --git a/packages/sdk-node/src/clerkExpressRequireAuth.ts b/packages/sdk-node/src/clerkExpressRequireAuth.ts index 47f3eef0810..fa9880ab199 100644 --- a/packages/sdk-node/src/clerkExpressRequireAuth.ts +++ b/packages/sdk-node/src/clerkExpressRequireAuth.ts @@ -1,5 +1,5 @@ import type { createClerkClient } from '@clerk/backend'; -import { AuthStatus } from '@clerk/backend'; +import { AuthStatus } from '@clerk/backend/internal'; import { authenticateRequest, decorateResponseWithObservabilityHeaders } from './authenticateRequest'; import type { ClerkMiddlewareOptions, MiddlewareRequireAuthProp, RequireAuthProp } from './types'; diff --git a/packages/sdk-node/src/clerkExpressWithAuth.ts b/packages/sdk-node/src/clerkExpressWithAuth.ts index aba87f14eba..bf3ce796e99 100644 --- a/packages/sdk-node/src/clerkExpressWithAuth.ts +++ b/packages/sdk-node/src/clerkExpressWithAuth.ts @@ -1,4 +1,4 @@ -import { AuthStatus } from '@clerk/backend'; +import { AuthStatus } from '@clerk/backend/internal'; import { authenticateRequest, decorateResponseWithObservabilityHeaders } from './authenticateRequest'; import type { CreateClerkExpressMiddlewareOptions } from './clerkExpressRequireAuth'; diff --git a/packages/sdk-node/src/index.ts b/packages/sdk-node/src/index.ts index e235d41e9c0..7aa1b40e041 100644 --- a/packages/sdk-node/src/index.ts +++ b/packages/sdk-node/src/index.ts @@ -10,42 +10,14 @@ import type { WithAuthProp, } from './types'; -// eslint-disable-next-line import/export export * from '@clerk/backend'; /** * The order of these exports is important, as we want Clerk from clerk/sdk-node * to shadow the Clerk export from clerk/backend, because it needs to support * 2 additional apis: clerk.expressWithAuth, clerk.expressRequireAuth */ -// eslint-disable-next-line import/export export { clerkClient, ClerkExpressRequireAuth, ClerkExpressWithAuth, createClerkClient }; -const { - users, - sessions, - emailAddresses, - phoneNumbers, - emails, - invitations, - organizations, - clients, - allowlistIdentifiers, - domains, -} = clerkClient; - -export { - allowlistIdentifiers, - clients, - domains, - emailAddresses, - emails, - invitations, - organizations, - phoneNumbers, - sessions, - users, -}; - export type { ClerkMiddleware, ClerkMiddlewareOptions, LooseAuthProp, RequireAuthProp, StrictAuthProp, WithAuthProp }; export { createClerkExpressRequireAuth, createClerkExpressWithAuth }; diff --git a/packages/sdk-node/src/types.ts b/packages/sdk-node/src/types.ts index a4e45e80ad7..63bf6b209fa 100644 --- a/packages/sdk-node/src/types.ts +++ b/packages/sdk-node/src/types.ts @@ -1,4 +1,5 @@ -import type { AuthenticateRequestOptions, AuthObject, createClerkClient, SignedInAuthObject } from '@clerk/backend'; +import type { createClerkClient } from '@clerk/backend'; +import type { AuthenticateRequestOptions, AuthObject, SignedInAuthObject } from '@clerk/backend/internal'; import type { MultiDomainAndOrProxy } from '@clerk/types'; import type { NextFunction, Request, Response } from 'express'; import type { IncomingMessage } from 'http';