import { EventEmitter2 } from "@nestjs/event-emitter"; import { DataSource } from "typeorm"; import { GarmrOptions } from "../garmr.options"; import { Authenticatable } from "../interfaces/authenticatable.interface"; import { TokenService } from "./token.service"; export declare const MAGIC_LINK_AUDIENCE = "magic-link"; export declare const SESSION_AUDIENCE = "session"; /** * Result of verifying a magic link token. */ export interface MagicLinkVerifyResult { /** * The authenticated or newly created entity. */ entity: T; /** * True if this was a new registration, false if existing user. */ isNewUser: boolean; } export declare class MagicLinkService { private readonly options; private readonly tokenService; private readonly datasource; private readonly eventEmitter; private transport?; constructor(options: GarmrOptions, tokenService: TokenService, datasource: DataSource, eventEmitter: EventEmitter2); /** * Returns the mailer options, throwing if magic link is not configured. * * @returns The mailer options from the magicLink configuration * @throws {Error} If magicLink is not configured in GarmrOptions */ private getMailer; /** * Returns the nodemailer transport, lazily creating it on first use. * * @returns The nodemailer Transporter instance * @throws {Error} If magicLink is not configured in GarmrOptions */ private getTransport; send(email: string): Promise; /** * Verifies a magic link token and returns/creates the user. * * - Validates token signature and expiry * - Validates required claims (aud, email) * - Creates new user if email not found, or returns existing user * - Emits `garmr.registered` for new users, `garmr.authenticated` for existing * * @param token - The magic link JWT token * @returns Object containing the entity and whether it's a new user * @throws {@link TokenFailedVerificationException} if token signature invalid or expired * @throws {@link InvalidMagicLinkTokenException} if missing required claims or wrong audience * * @example * ```typescript * const { entity, isNewUser } = await magicLinkService.verify(token) * if (isNewUser) { * await emailService.sendWelcome(entity.email) * } * ``` * * @fires garmr.registered - when a new user is created * @fires garmr.authenticated - when an existing user is authenticated */ verify(token: string): Promise>; }