106 lines
4.4 KiB
TypeScript
106 lines
4.4 KiB
TypeScript
import { Module } from "@nestjs/common";
|
|
import { ConfigModule } from "@nestjs/config";
|
|
import { ThrottlerModule, ThrottlerGuard } from "@nestjs/throttler";
|
|
import { APP_GUARD, APP_INTERCEPTOR } from "@nestjs/core";
|
|
|
|
import { envValidationSchema } from "./config/env.validation";
|
|
import { CommonModule } from "./common/common.module";
|
|
import { PrismaModule } from "./prisma/prisma.module";
|
|
import { StorageModule } from "./storage/storage.module";
|
|
import { SupabaseModule } from "./supabase/supabase.module";
|
|
import { EmailModule } from "./email/email.module";
|
|
import { AuthModule } from "./auth/auth.module";
|
|
import { PlaidModule } from "./plaid/plaid.module";
|
|
import { TellerModule } from "./teller/teller.module";
|
|
import { TaxModule } from "./tax/tax.module";
|
|
import { TransactionsModule } from "./transactions/transactions.module";
|
|
import { AccountsModule } from "./accounts/accounts.module";
|
|
import { RulesModule } from "./rules/rules.module";
|
|
import { ExportsModule } from "./exports/exports.module";
|
|
import { StripeModule } from "./stripe/stripe.module";
|
|
import { TwoFactorModule } from "./auth/twofa/two-factor.module";
|
|
import { GoogleModule } from "./google/google.module";
|
|
import { AbuseModule } from "./abuse/abuse.module";
|
|
import { PublicApiModule } from "./public-api/public-api.module";
|
|
import { AdminModule } from "./admin/admin.module";
|
|
import { HouseholdsModule } from "./households/households.module";
|
|
import { NotificationsModule } from "./notifications/notifications.module";
|
|
import { BillPayModule } from "./bill-pay/bill-pay.module";
|
|
import { CreditScoreModule } from "./credit-score/credit-score.module";
|
|
import { ViewModule } from "./view/view.module";
|
|
import { ComplianceModule } from "./compliance/compliance.module";
|
|
import { PlanningModule } from "./planning/planning.module";
|
|
import { LoggerModule } from "nestjs-pino";
|
|
import { JwtAuthGuard } from "./common/guards/jwt-auth.guard";
|
|
import { BrowserUntrustedInterceptor } from "./common/browser-untrusted.interceptor";
|
|
|
|
@Module({
|
|
imports: [
|
|
// ─── Env validation ──────────────────────────────────────────────────────
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
validationSchema: envValidationSchema,
|
|
validationOptions: { allowUnknown: true, abortEarly: false },
|
|
}),
|
|
|
|
// ─── Rate limiting: 100 requests / 60 seconds per IP ─────────────────────
|
|
ThrottlerModule.forRoot([
|
|
{
|
|
name: "default",
|
|
ttl: 60_000,
|
|
limit: 100,
|
|
},
|
|
]),
|
|
|
|
// ─── Structured logging (Pino) ────────────────────────────────────────────
|
|
LoggerModule.forRoot({
|
|
pinoHttp: {
|
|
level: process.env.NODE_ENV === "production" ? "info" : "debug",
|
|
transport: process.env.NODE_ENV !== "production"
|
|
? { target: "pino-pretty", options: { colorize: true, singleLine: true } }
|
|
: undefined,
|
|
redact: ["req.headers.authorization", "req.headers.cookie"],
|
|
},
|
|
}),
|
|
|
|
// ─── Core infrastructure ─────────────────────────────────────────────────
|
|
CommonModule,
|
|
PrismaModule,
|
|
StorageModule,
|
|
SupabaseModule,
|
|
EmailModule,
|
|
AbuseModule,
|
|
|
|
// ─── Feature modules ─────────────────────────────────────────────────────
|
|
AuthModule,
|
|
PlaidModule,
|
|
TellerModule,
|
|
TaxModule,
|
|
TransactionsModule,
|
|
AccountsModule,
|
|
RulesModule,
|
|
ExportsModule,
|
|
StripeModule,
|
|
TwoFactorModule,
|
|
GoogleModule,
|
|
PublicApiModule,
|
|
AdminModule,
|
|
HouseholdsModule,
|
|
NotificationsModule,
|
|
BillPayModule,
|
|
CreditScoreModule,
|
|
ViewModule,
|
|
ComplianceModule,
|
|
PlanningModule,
|
|
],
|
|
providers: [
|
|
// Apply rate limiting globally
|
|
{ provide: APP_GUARD, useClass: ThrottlerGuard },
|
|
// Apply JWT auth globally (routes decorated with @Public() are exempt)
|
|
{ provide: APP_GUARD, useClass: JwtAuthGuard },
|
|
// Treat browser/API clients as untrusted presentation clients by default.
|
|
{ provide: APP_INTERCEPTOR, useClass: BrowserUntrustedInterceptor },
|
|
],
|
|
})
|
|
export class AppModule {}
|