import { EventEmitter2 } from "@nestjs/event-emitter"; import { DataSource } from "typeorm"; import { GarmrOptions } from "../garmr.options"; import { Authenticatable } from "../interfaces/authenticatable.interface"; /** * Provider-specific profile data returned from Google OAuth. */ export interface GoogleProfile { /** Google account subject identifier */ sub: string; /** Display name from Google account */ name?: string; /** Profile picture URL from Google account */ picture?: string; } /** * Result of authenticating via Google OAuth code exchange. * * @typeParam T - The entity class implementing Authenticatable */ export interface GoogleAuthResult { /** The authenticated or newly created entity */ entity: T; /** True if this was a new registration, false if existing user */ isNewUser: boolean; /** Google profile data extracted from the ID token */ profile: GoogleProfile; } /** * Exchanges a Google authorization code for a verified user entity. * * Follows the same find-or-create-by-email pattern as MagicLinkService.verify(): * 1. Exchanges the code with Google's token endpoint * 2. Decodes the ID token to extract user info * 3. Finds an existing user by email or creates a new one * 4. Optionally writes Google profile data to the entity * 5. Emits registration or authentication events * * @example * ```typescript * const result = await googleAuthService.authenticate(code) * if (result.isNewUser) { * console.log('New user registered via Google:', result.entity.email) * } * ``` */ export declare class GoogleAuthService { private readonly options; private readonly datasource; private readonly eventEmitter; private static readonly DEFAULT_TOKEN_ENDPOINT; constructor(options: GarmrOptions, datasource: DataSource, eventEmitter: EventEmitter2); /** * Returns the Google OAuth options, throwing if not configured. * * @returns The Google OAuth configuration * @throws {Error} If googleAuth is not configured in GarmrOptions */ private getGoogleAuth; /** * Exchanges a Google authorization code for user credentials and finds or * creates the corresponding entity. * * @param code - The authorization code from Google's OAuth redirect * @returns Object containing the entity, isNewUser flag, and Google profile * @throws {GoogleCodeExchangeException} If Google's token endpoint returns a non-OK HTTP response * @throws {GoogleServiceException} If Google's token endpoint returns a 5xx server error * @throws {GoogleNetworkException} If the fetch call itself fails (network error, DNS, timeout) * @throws {GoogleTokenException} If the ID token is missing, has no email claim, or has no sub claim * @throws {EmailNotVerifiedException} If the ID token has email_verified explicitly set to false * @throws {Error} If googleAuth is not configured * * @example * ```typescript * const { entity, isNewUser, profile } = await googleAuthService.authenticate(code) * ``` * * @fires garmr.registered - when a new user is created * @fires garmr.authenticated - when an existing user is authenticated */ authenticate(code: string): Promise>; }