Skip to content

Commit

Permalink
chore(backend): Expose /internal subpath export
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkl committed Dec 14, 2023
1 parent e5e6a46 commit 04347cc
Show file tree
Hide file tree
Showing 33 changed files with 133 additions and 84 deletions.
34 changes: 34 additions & 0 deletions .changeset/red-suns-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
'gatsby-plugin-clerk': major
'@clerk/clerk-sdk-node': major
'@clerk/backend': major
'@clerk/fastify': major
'@clerk/nextjs': major
'@clerk/remix': major
---

Changes in exports in `@clerk/backend`:
- Expose the following helpers and enums from `@clerk/backend/internal`:
```typescript
import {
AuthStatus,
buildRequestUrl,
constants,
createAuthenticateRequest,
createIsomorphicRequest,
debugRequestState,
makeAuthObjectSerializable,
prunePrivateMetadata,
redirect,
sanitizeAuthObject,
signedInAuthObject,
signedOutAuthObject } from '@clerk/backend/internal';
```
- Drop the above exports from the top-level api:
```typescript
// Before
import { AuthStatus, ... } from '@clerk/backend';
// After
import { AuthStatus, ... } from '@clerk/backend/internal';
```
Dropping those exports results in also dropping the exports from `gatsby-plugin-clerk`, `@clerk/clerk-sdk-node`, `@clerk/backend`, `@clerk/fastify`, `@clerk/nextjs`, `@clerk/remix` packages.
10 changes: 10 additions & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
"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"
}
},
"./package.json": "./package.json"
},
"main": "./dist/index.js",
Expand Down
33 changes: 21 additions & 12 deletions packages/backend/src/__tests__/exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type QUnit from 'qunit';

import * as errorExports from '../errors';
import * as publicExports from '../index';
import * as internalExports from '../internal';

export default (QUnit: QUnit) => {
const { module, test } = QUnit;
Expand All @@ -10,7 +11,6 @@ export default (QUnit: QUnit) => {
test('should not include a breaking change', assert => {
const exportedApiKeys = [
'AllowlistIdentifier',
'AuthStatus',
'Client',
'DeletedObject',
'Email',
Expand All @@ -32,21 +32,10 @@ export default (QUnit: QUnit) => {
'Token',
'User',
'Verification',
'buildRequestUrl',
'constants',
'createAuthenticateRequest',
'createClerkClient',
'createIsomorphicRequest',
'debugRequestState',
'decodeJwt',
'hasValidSignature',
'makeAuthObjectSerializable',
'prunePrivateMetadata',
'redirect',
'sanitizeAuthObject',
'signJwt',
'signedInAuthObject',
'signedOutAuthObject',
'verifyJwt',
'verifyToken',
];
Expand All @@ -65,4 +54,24 @@ export default (QUnit: QUnit) => {
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);
});
});
};
10 changes: 2 additions & 8 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ import type { SDKMetadata } from '@clerk/types';

import type { ApiClient, CreateBackendApiOptions } from './api';
import { createBackendApiClient } from './api';
import type { CreateAuthenticateRequestOptions } from './tokens';
import { createAuthenticateRequest } from './tokens';

export { createIsomorphicRequest } from './util/IsomorphicRequest';
import type { CreateAuthenticateRequestOptions } from './tokens/factory';
import { createAuthenticateRequest } from './tokens/factory';

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 ClerkOptions = CreateBackendApiOptions &
Partial<
Expand Down
28 changes: 28 additions & 0 deletions packages/backend/src/internal.ts
Original file line number Diff line number Diff line change
@@ -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';
6 changes: 0 additions & 6 deletions packages/backend/src/tokens/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/backend/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig(overrideOptions => {
const shouldPublish = !!overrideOptions.env?.publish;

const common: Options = {
entry: ['src/index.ts', 'src/errors.ts'],
entry: ['src/index.ts', 'src/errors.ts', 'src/internal.ts'],
onSuccess: `cpy 'src/runtime/**/*.{mjs,js,cjs}' dist/runtime`,
sourcemap: true,
define: {
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify/src/getAuth.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify/src/withClerkMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuthStatus } from '@clerk/backend';
import { AuthStatus } from '@clerk/backend/internal';
import type { FastifyRequest } from 'fastify';

import { clerkClient } from './clerkClient';
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby-plugin-clerk/src/ssr/types.ts
Original file line number Diff line number Diff line change
@@ -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<CallbackReturn> = (props: GetServerDataProps) => Promise<Awaited<CallbackReturn>>;
Expand Down
5 changes: 2 additions & 3 deletions packages/gatsby-plugin-clerk/src/ssr/utils.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-clerk/src/ssr/withServerAuth.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/app-router/server/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SignedInAuthObject, SignedOutAuthObject } from '@clerk/backend';
import type { SignedInAuthObject, SignedOutAuthObject } from '@clerk/backend/internal';
import type {
CheckAuthorizationParamsWithCustomPermissions,
CheckAuthorizationWithCustomPermissions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
exports[`/server public exports should not include a breaking change 1`] = `
[
"AllowlistIdentifier",
"AuthStatus",
"Client",
"DeletedObject",
"Email",
Expand All @@ -28,26 +27,15 @@ exports[`/server public exports should not include a breaking change 1`] = `
"auth",
"authMiddleware",
"buildClerkProps",
"buildRequestUrl",
"clerkClient",
"constants",
"createAuthenticateRequest",
"createClerkClient",
"createIsomorphicRequest",
"currentUser",
"debugRequestState",
"decodeJwt",
"getAuth",
"hasValidSignature",
"makeAuthObjectSerializable",
"prunePrivateMetadata",
"redirect",
"redirectToSignIn",
"redirectToSignUp",
"sanitizeAuthObject",
"signJwt",
"signedInAuthObject",
"signedOutAuthObject",
"verifyJwt",
"verifyToken",
]
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/server/authMiddleware.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/server/authMiddleware.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
7 changes: 4 additions & 3 deletions packages/nextjs/src/server/getAuth.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { Organization, Session, SignedInAuthObject, SignedOutAuthObject, User } from '@clerk/backend';
import type { Organization, Session, User } from '@clerk/backend';
import { decodeJwt } 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 { withLogger } from '../utils/debugLogger';
import { API_URL, API_VERSION, SECRET_KEY } from './constants';
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/server/redirect.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/server/types.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/server/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
5 changes: 3 additions & 2 deletions packages/remix/src/ssr/authenticateRequest.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/remix/src/ssr/getAuth.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/remix/src/ssr/rootAuthLoader.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
3 changes: 2 additions & 1 deletion packages/remix/src/ssr/types.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
4 changes: 2 additions & 2 deletions packages/remix/src/ssr/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
12 changes: 0 additions & 12 deletions packages/sdk-node/src/__tests__/__snapshots__/exports.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
exports[`module exports should not change unless explicitly set 1`] = `
[
"AllowlistIdentifier",
"AuthStatus",
"ClerkExpressRequireAuth",
"ClerkExpressWithAuth",
"Client",
Expand All @@ -27,25 +26,14 @@ exports[`module exports should not change unless explicitly set 1`] = `
"Token",
"User",
"Verification",
"buildRequestUrl",
"clerkClient",
"constants",
"createAuthenticateRequest",
"createClerkClient",
"createClerkExpressRequireAuth",
"createClerkExpressWithAuth",
"createIsomorphicRequest",
"debugRequestState",
"decodeJwt",
"hasValidSignature",
"makeAuthObjectSerializable",
"prunePrivateMetadata",
"redirect",
"requireAuth",
"sanitizeAuthObject",
"signJwt",
"signedInAuthObject",
"signedOutAuthObject",
"verifyJwt",
"verifyToken",
"withAuth",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { constants } from '@clerk/backend';
import { constants } from '@clerk/backend/internal';
import { Request } from 'express';

import { authenticateRequest } from '../authenticateRequest';
Expand Down
Loading

0 comments on commit 04347cc

Please sign in to comment.