Skip to content

Commit

Permalink
change export to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts committed Aug 6, 2024
1 parent a1521b8 commit 91995d6
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 88 deletions.
13 changes: 5 additions & 8 deletions .changeset/fast-knives-peel.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
---
"@clerk/astro": patch
"@clerk/backend": patch
"@clerk/express": patch
"@clerk/fastify": patch
"@clerk/nextjs": patch
"@clerk/remix": patch
"@clerk/clerk-sdk-node": patch
"@clerk/types": patch
---

Move `AuthObject` and its related types to `@clerk/types`. You will now be able to import it from there.
Export the type `AuthObject`. You can now use it like so:

```ts
import type { AuthObject } from "@clerk/backend"
```
10 changes: 10 additions & 0 deletions .changeset/itchy-ravens-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@clerk/clerk-sdk-node": patch
"@clerk/express": patch
"@clerk/fastify": patch
"@clerk/nextjs": patch
"@clerk/astro": patch
"@clerk/remix": patch
---

Internal change: Use `AuthObject` type import from `@clerk/backend`.
3 changes: 1 addition & 2 deletions packages/astro/src/server/clerk-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { ClerkClient } from '@clerk/backend';
import type { AuthObject, ClerkClient } from '@clerk/backend';
import type { AuthenticateRequestOptions, ClerkRequest, RedirectFun, RequestState } from '@clerk/backend/internal';
import { AuthStatus, constants, createClerkRequest, createRedirect } from '@clerk/backend/internal';
import { handleValueOrFn, isDevelopmentFromSecretKey, isHttpOrHttps } from '@clerk/shared';
import { eventMethodCalled } from '@clerk/shared/telemetry';
import type { AuthObject } from '@clerk/types';
import type { APIContext } from 'astro';

// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/server/get-auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AuthObject } from '@clerk/backend';
import { AuthStatus, signedInAuthObject, signedOutAuthObject } from '@clerk/backend/internal';
import { decodeJwt } from '@clerk/backend/jwt';
import type { AuthObject } from '@clerk/types';
import type { APIContext } from 'astro';

import { getSafeEnv } from './get-safe-env';
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,8 @@ export type {
WebhookEvent,
WebhookEventType,
} from './api/resources/Webhooks';

/**
* Auth objects
*/
export type { AuthObject } from './tokens/authObjects';
2 changes: 1 addition & 1 deletion packages/backend/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export { debugRequestState } from './tokens/request';

export type { AuthenticateRequestOptions } from './tokens/types';

export type { SignedInAuthObjectOptions } from './tokens/authObjects';
export type { SignedInAuthObjectOptions, SignedInAuthObject, SignedOutAuthObject } from './tokens/authObjects';
export { makeAuthObjectSerializable, signedOutAuthObject, signedInAuthObject } from './tokens/authObjects';

export { AuthStatus } from './tokens/authStatus';
Expand Down
49 changes: 45 additions & 4 deletions packages/backend/src/tokens/authObjects.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,66 @@
import type {
AuthObject,
AuthObjectDebugData,
ActClaim,
CheckAuthorizationWithCustomPermissions,
JwtPayload,
OrganizationCustomPermissionKey,
OrganizationCustomRoleKey,
ServerGetToken,
ServerGetTokenOptions,
SignedInAuthObject,
SignedOutAuthObject,
} from '@clerk/types';

import type { CreateBackendApiOptions } from '../api';
import { createBackendApiClient } from '../api';
import type { AuthenticateContext } from './authenticateContext';

type AuthObjectDebugData = Record<string, any>;
type AuthObjectDebug = () => AuthObjectDebugData;

/**
* @internal
*/
export type SignedInAuthObjectOptions = CreateBackendApiOptions & {
token: string;
};

/**
* @internal
*/
export type SignedInAuthObject = {
sessionClaims: JwtPayload;
sessionId: string;
actor: ActClaim | undefined;
userId: string;
orgId: string | undefined;
orgRole: OrganizationCustomRoleKey | undefined;
orgSlug: string | undefined;
orgPermissions: OrganizationCustomPermissionKey[] | undefined;
getToken: ServerGetToken;
has: CheckAuthorizationWithCustomPermissions;
debug: AuthObjectDebug;
};

/**
* @internal
*/
export type SignedOutAuthObject = {
sessionClaims: null;
sessionId: null;
actor: null;
userId: null;
orgId: null;
orgRole: null;
orgSlug: null;
orgPermissions: null;
getToken: ServerGetToken;
has: CheckAuthorizationWithCustomPermissions;
debug: AuthObjectDebug;
};

/**
* @internal
*/
export type AuthObject = SignedInAuthObject | SignedOutAuthObject;

const createDebug = (data: AuthObjectDebugData | undefined) => {
return () => {
const res = { ...data };
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/tokens/authStatus.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { JwtPayload, SignedInAuthObject, SignedOutAuthObject } from '@clerk/types';
import type { JwtPayload } from '@clerk/types';

import { constants } from '../constants';
import type { TokenVerificationErrorReason } from '../errors';
import type { AuthenticateContext } from './authenticateContext';
import type { SignedInAuthObject, SignedOutAuthObject } from './authObjects';
import { signedInAuthObject, signedOutAuthObject } from './authObjects';

export const AuthStatus = {
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/util/decorateObjectWithResources.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { AuthObject } from '@clerk/types';

import type { CreateBackendApiOptions, Organization, Session, User } from '../api';
import { createBackendApiClient } from '../api';
import type { AuthObject } from '../tokens/authObjects';

type DecorateAuthWithResourcesOptions = {
loadSession?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/express/src/__tests__/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AuthObject } from '@clerk/types';
import type { AuthObject } from '@clerk/backend';
import type { Application, Request as ExpressRequest, RequestHandler, Response as ExpressResponse } from 'express';
import express from 'express';
import supertest from 'supertest';
Expand Down
2 changes: 1 addition & 1 deletion packages/express/src/getAuth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AuthObject } from '@clerk/types';
import type { AuthObject } from '@clerk/backend';
import type { Request as ExpressRequest } from 'express';

import { middlewareRequired } from './errors';
Expand Down
4 changes: 1 addition & 3 deletions packages/express/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import { createClerkClient } from '@clerk/backend';
import type { AuthObject, createClerkClient } from '@clerk/backend';
import type { AuthenticateRequestOptions } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/types';
import type { Request as ExpressRequest, RequestHandler } from 'express';

export type ExpressRequestWithAuth = ExpressRequest & { auth: AuthObject };
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/types';
import type { AuthObject } from '@clerk/backend';
import type { FastifyRequest } from 'fastify';

import { pluginRegistrationRequired } from './errors';
Expand Down
3 changes: 1 addition & 2 deletions packages/gatsby-plugin-clerk/src/ssr/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Organization, Session, User } from '@clerk/backend';
import type { AuthObject, Organization, Session, User } from '@clerk/backend';
import type { AuthenticateRequestOptions } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/types';
import type { GetServerDataProps } from 'gatsby';

export type WithServerAuthResult<CallbackReturn> = (props: GetServerDataProps) => Promise<Awaited<CallbackReturn>>;
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,6 +1,6 @@
import type { AuthObject } from '@clerk/backend';
import type { RedirectFun } from '@clerk/backend/internal';
import { constants, createClerkRequest, createRedirect } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/types';
import { notFound, redirect } from 'next/navigation';

import { buildClerkProps } from '../../server/buildClerkProps';
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/server/authMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { AuthObject } from '@clerk/backend';
import type { AuthenticateRequestOptions, ClerkRequest } from '@clerk/backend/internal';
import { AuthStatus, constants, createClerkRequest, createRedirect } from '@clerk/backend/internal';
import { isDevelopmentFromSecretKey } from '@clerk/shared/keys';
import { eventMethodCalled } from '@clerk/shared/telemetry';
import type { AuthObject } from '@clerk/types';
import type { NextFetchEvent, NextMiddleware, NextRequest } from 'next/server';
import { NextResponse } from 'next/server';

Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/server/clerkMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AsyncLocalStorage } from 'node:async_hooks';

import type { AuthObject } from '@clerk/backend';
import type { AuthenticateRequestOptions, ClerkRequest, RedirectFun, RequestState } from '@clerk/backend/internal';
import { AuthStatus, constants, createClerkRequest, createRedirect } from '@clerk/backend/internal';
import { eventMethodCalled } from '@clerk/shared/telemetry';
import type { AuthObject } from '@clerk/types';
import type { NextMiddleware } from 'next/server';
import { NextResponse } from 'next/server';

Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/server/createGetAuth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AuthObject } from '@clerk/backend';
import { AuthStatus, constants, signedInAuthObject, signedOutAuthObject } from '@clerk/backend/internal';
import { decodeJwt } from '@clerk/backend/jwt';
import type { AuthObject } from '@clerk/types';

import { withLogger } from '../utils/debugLogger';
import { API_URL, API_VERSION, SECRET_KEY } from './constants';
Expand Down
5 changes: 2 additions & 3 deletions packages/nextjs/src/server/protect.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { RedirectFun } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/backend';
import type { RedirectFun, SignedInAuthObject } from '@clerk/backend/internal';
import { constants } from '@clerk/backend/internal';
import type {
AuthObject,
CheckAuthorizationParamsWithCustomPermissions,
CheckAuthorizationWithCustomPermissions,
SignedInAuthObject,
} from '@clerk/types';

import { constants as nextConstants } from '../constants';
Expand Down
3 changes: 1 addition & 2 deletions packages/remix/src/ssr/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Organization, Session, User, VerifyTokenOptions } from '@clerk/backend';
import type { AuthObject, Organization, Session, User, VerifyTokenOptions } from '@clerk/backend';
import type { RequestState } from '@clerk/backend/internal';
import type {
AuthObject,
LegacyRedirectProps,
MultiDomainAndOrProxy,
SignInFallbackRedirectUrl,
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk-node/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { createClerkClient } from '@clerk/backend';
import type { AuthenticateRequestOptions } from '@clerk/backend/internal';
import type { AuthObject, MultiDomainAndOrProxy, SignedInAuthObject } from '@clerk/types';
import type { AuthObject, createClerkClient } from '@clerk/backend';
import type { AuthenticateRequestOptions, SignedInAuthObject } from '@clerk/backend/internal';
import type { MultiDomainAndOrProxy } from '@clerk/types';
import type { NextFunction, Request, Response } from 'express';
import type { IncomingMessage } from 'http';

Expand Down
49 changes: 0 additions & 49 deletions packages/types/src/token.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,7 @@
import type { ActClaim, JwtPayload } from 'jwtv2';
import type { OrganizationCustomPermissionKey, OrganizationCustomRoleKey } from 'organizationMembership';
import type { CheckAuthorizationWithCustomPermissions } from 'session';
import type { ServerGetToken } from 'ssr';

import type { JWT } from './jwt';
import type { ClerkResource } from './resource';

export interface TokenResource extends ClerkResource {
jwt?: JWT;
getRawString: () => string;
}
/**
* @internal
*/
export type AuthObjectDebugData = Record<string, any>;
/**
* @internal
*/
export type AuthObjectDebug = () => AuthObjectDebugData;

/**
* @internal
*/
export type SignedInAuthObject = {
sessionClaims: JwtPayload;
sessionId: string;
actor: ActClaim | undefined;
userId: string;
orgId: string | undefined;
orgRole: OrganizationCustomRoleKey | undefined;
orgSlug: string | undefined;
orgPermissions: OrganizationCustomPermissionKey[] | undefined;
getToken: ServerGetToken;
has: CheckAuthorizationWithCustomPermissions;
debug: AuthObjectDebug;
};

/**
* @internal
*/
export type SignedOutAuthObject = {
sessionClaims: null;
sessionId: null;
actor: null;
userId: null;
orgId: null;
orgRole: null;
orgSlug: null;
orgPermissions: null;
getToken: ServerGetToken;
has: CheckAuthorizationWithCustomPermissions;
debug: AuthObjectDebug;
};

export type AuthObject = SignedInAuthObject | SignedOutAuthObject;

0 comments on commit 91995d6

Please sign in to comment.