import { b as ContentstackOAuthScope, c as ContentstackUser, f as OAuthTokens } from '../../types-BmuNBa52.js'; import { ContentstackRegion } from '../../regions/index.js'; import * as next_auth from 'next-auth'; import '../../types-C8x5GGVP.js'; type AuthLoggerMethod = (...args: unknown[]) => unknown; type AuthLogger = Record & { warn?: (code: string) => void; error?: (error: Error) => void; debug?: (message: string, metadata?: unknown) => void; }; interface OAuthMiddlewareConfig { region: ContentstackRegion; appId: string; clientId: string; clientSecret: string; scopes: ContentstackOAuthScope[]; redirectUri?: string; secret: string; trustHost?: boolean; signInPage?: string; errorPage?: string; onSignIn?: (user: ContentstackUser, tokens: OAuthTokens) => Promise; logger?: AuthLogger; } type AuthFn = () => Promise<{ accessToken?: string; user?: unknown; } | null>; interface ContentstackSession { accessToken: string; user?: unknown; } /** * Create a complete Auth.js v5 (NextAuth) configuration for Contentstack OAuth. * * This wraps NextAuth with all Contentstack-specific config baked in, reducing * ~150 lines of Auth.js configuration down to ~10 lines. * * Requires `next-auth@>=5.0.0-beta.0` as an installed peer dependency. * * @example * ```ts * import { createContentstackAuth } from "@timbenniks/contentstack-platform-sdk/server/middleware" * * const { handlers, auth, signIn, signOut } = await createContentstackAuth({ * region: "us", * appId: "your-app-uid", * clientId: "your-client-id", * clientSecret: "your-client-secret", * scopes: ["user:read"], * secret: process.env.AUTH_SECRET!, * }) * * // app/api/auth/[...nextauth]/route.ts * export const { GET, POST } = handlers * ``` */ declare function createContentstackAuth(config: OAuthMiddlewareConfig): Promise; /** * Get the current Contentstack session. * * @param authFn - Framework-agnostic auth function (e.g., the `auth()` function from NextAuth) * @returns The session with `accessToken`, or `null` if unauthenticated. */ declare function getSession(authFn: AuthFn): Promise; /** * Require an authenticated Contentstack session. * Throws `ContentstackAuthError` if no session or no access token is present. * * @param authFn - Framework-agnostic auth function * @param redirectTo - Optional redirect path included in the error for the caller to use * @returns The session with a guaranteed `accessToken`. */ declare function requireSession(authFn: AuthFn, redirectTo?: string): Promise; /** * Get the OAuth access token from the current session. * * @param authFn - Framework-agnostic auth function * @returns The access token string, or `null` if unauthenticated. */ declare function getAccessToken(authFn: AuthFn): Promise; export { type AuthFn, type AuthLogger, type ContentstackSession, type OAuthMiddlewareConfig, createContentstackAuth, getAccessToken, getSession, requireSession };