NestJS SDK
@subdomainto/nestjs v0.1 supports NestJS 10 and 11 on Node.js 20+. It is server-only.
Installation
npm install @subdomainto/nestjs
Register the module
import { Module } from '@nestjs/common';
import { SubdomainToModule } from '@subdomainto/nestjs';
@Module({
imports: [SubdomainToModule.forRoot({
apiKey: process.env.SUBDOMAINTO_API_KEY!,
webhookSecret: process.env.SUBDOMAINTO_WEBHOOK_SECRET,
})],
})
export class AppModule {}
forRootAsync is available for configuration providers. Inject the SubdomainTo class from @subdomainto/node in your services and use its typed resources normally.
Enable raw request bodies
const app = await NestFactory.create(AppModule, { rawBody: true });
Protect a webhook controller
import { Controller, Post, Req, UseGuards } from '@nestjs/common';
import { SubdomainToWebhookGuard } from '@subdomainto/nestjs';
@Controller('webhooks')
export class WebhooksController {
@Post('subdomainto')
@UseGuards(SubdomainToWebhookGuard)
receive(@Req() request: { subdomainToEvent?: unknown }) {
return { received: Boolean(request.subdomainToEvent) };
}
}
The guard verifies request.rawBody, validates the signature, and places the event on request.subdomainToEvent. Invalid deliveries raise BadRequestException.