import { Queue } from "bullmq"; import { ClsService } from "nestjs-cls"; import { JsonApiService } from "../../../core/jsonapi/services/jsonapi.service"; import { CacheService } from "../../../core/cache/services/cache.service"; import { CompanyRepository } from "../../company/repositories/company.repository"; import { UserRepository } from "../../user/repositories/user.repository"; import { ReferralRepository } from "../repositories/referral.repository"; import { ReferralModuleConfig } from "../interfaces/referral.config.interface"; import { ReferralCompletionHandler } from "../../stripe-webhook/interfaces/referral-completion-handler.interface"; /** * Referral statistics returned by getStats */ export interface ReferralStats { referralCode: string; completedReferrals: number; totalTokensEarned: number; } export declare class ReferralService implements ReferralCompletionHandler { private readonly config; private readonly jsonApiService; private readonly referralRepository; private readonly companyRepository; private readonly userRepository; private readonly clsService; private readonly cacheService; private readonly emailQueue; private readonly logger; constructor(config: Required, jsonApiService: JsonApiService, referralRepository: ReferralRepository, companyRepository: CompanyRepository, userRepository: UserRepository, clsService: ClsService, cacheService: CacheService, emailQueue: Queue); /** * Check if the referral feature is enabled. */ get isEnabled(): boolean; /** * Generate a Redis key for tracking referral invites. * Uses SHA-256 hash of the email for privacy. */ private getReferralInviteKey; /** * Build the referral URL from the configured app URL (APP_URL). * * `app.url` is normalised with a trailing slash by the config layer, so it is * stripped here to avoid a doubled separator before `/register`. */ private buildReferralUrl; /** * Get the current company's referral code, creating one if it doesn't exist. * @returns The referral code for the current company */ getOrCreateReferralCode(): Promise; /** * Track a referral by creating a pending referral between companies. * Silently ignores invalid referral codes (no error thrown). * Does nothing if referral feature is disabled. * @param params.referralCode - The referral code from the referrer company */ trackReferral(params: { referralCode: string; }): Promise; /** * Queue a referral invite email to be sent. * Enforces a configurable cooldown per company+email to prevent spam. * @param params.email - The email address to send the invite to * @throws BadRequestException if the email was already invited within the cooldown period * @throws BadRequestException if the email is already registered in the system */ sendReferralInvite(params: { email: string; }): Promise; /** * Complete a referral when a payment is made by the referred company. * Awards tokens to both the referrer and referred companies. * Does nothing if referral feature is disabled. * @param params.referredCompanyId - The ID of the company that made the payment */ completeReferralOnPayment(params: { referredCompanyId: string; }): Promise; /** * Get referral statistics for the current company. * @returns Referral code, completed count, and total tokens earned */ getStats(): Promise; /** * Get the current company's referral code as JSON:API response. * Creates a new code if one doesn't exist. * @returns JSON:API formatted referral code response */ getMyCodeJsonApi(): Promise; /** * Get referral statistics as JSON:API response. * @returns JSON:API formatted referral stats response */ getStatsJsonApi(): Promise; } //# sourceMappingURL=referral.service.d.ts.map