/** * NAuth Bootstrap * * Entry point for initializing NAuth with platform adapters. * * **Usage:** * ```typescript * import { NAuth, ExpressAdapter } from '@nauth-toolkit/core'; * * const nauth = await NAuth.create({ * config: authConfig, * dataSource: dataSource, * adapter: new ExpressAdapter(), * }); * * // Mount middleware * app.use(nauth.middleware.clientInfo); * app.use(nauth.middleware.csrf); * app.use(nauth.middleware.auth); * app.use(nauth.middleware.tokenDelivery); * * // Protected routes * app.get('/profile', nauth.helpers.requireAuth(), (req, res) => { * const user = nauth.helpers.getCurrentUser(); * res.json({ user }); * }); * ``` */ import { DataSource } from 'typeorm'; import { NAuthConfig } from './interfaces/config.interface'; import { NAuthLogger } from './utils/nauth-logger'; import { NAuthAdapter } from './platform/interfaces'; import { CsrfService } from './services/csrf.service'; import { TelemetryService } from './services/telemetry.service'; import { NAuthServices } from './utils/setup/init-services'; import { NAuthSocialProviders } from './utils/setup/init-social'; import { ClientInfo } from './interfaces/client-info.interface'; import { IUser } from './interfaces/entities.interface'; import { SocialRedirectHandler } from './services/social-redirect.handler'; /** * Options for NAuth initialization */ export interface NAuthOptions { /** NAuth configuration */ config: NAuthConfig; /** TypeORM DataSource */ dataSource: DataSource; /** * Platform adapter (Express, Fastify, etc.) * @default ExpressAdapter */ adapter?: NAuthAdapter; } /** * NAuth instance returned by NAuth.create() * * Contains services, middleware, and helpers for authentication. * * @typeParam TMiddleware - Type for middleware (framework-specific) * @typeParam THelper - Type for route helpers (framework-specific) */ export interface NAuthInstance extends Omit, NAuthSocialProviders { /** Framework-specific middleware/hooks */ middleware: { /** Client info extraction (MUST BE FIRST) */ clientInfo: TMiddleware; /** JWT authentication */ auth: TMiddleware; /** CSRF protection */ csrf: TMiddleware; /** Token delivery (response interceptor) */ tokenDelivery: TMiddleware; }; /** Route helpers */ helpers: { /** Mark route as public (bypasses CSRF) */ public: () => THelper; /** Require authentication (with optional CSRF bypass) */ requireAuth: (options?: { csrf?: boolean; }) => THelper; /** Optional authentication marker */ optionalAuth: () => THelper; /** Override token delivery mode */ tokenDelivery: (mode: 'json' | 'cookies') => THelper; /** Skip reCAPTCHA validation for this route */ skipRecaptcha: () => THelper; /** Require reCAPTCHA validation for this route */ requireRecaptcha: () => THelper; /** Get current authenticated user */ getCurrentUser: () => IUser | undefined; /** Get current session ID */ getCurrentSession: () => string | number | undefined; /** Get client info */ getClientInfo: () => ClientInfo | undefined; }; /** The adapter being used */ adapter: NAuthAdapter; /** Configuration */ config: NAuthConfig; /** Logger instance */ logger: NAuthLogger; /** CSRF service (if enabled) */ csrfService?: CsrfService; /** Social OAuth redirect handler — start, callback, and exchange flows */ socialRedirect?: SocialRedirectHandler; /** Anonymous usage telemetry (opt-out) — see https://nauth.dev/docs/concepts/telemetry */ telemetryService?: TelemetryService; } /** * NAuth Bootstrap * * Main entry point for initializing NAuth. */ export declare class NAuth { /** * Create NAuth instance * * @param options - Configuration options * @returns Initialized NAuth instance * * @example * ```typescript * const nauth = await NAuth.create({ * config: authConfig, * dataSource: dataSource, * adapter: new ExpressAdapter(), * }); * ``` */ static create(options: NAuthOptions): Promise; } //# sourceMappingURL=bootstrap.d.ts.map