@zola_do/interceptors
v0.1.10
Published
Tenant and transaction interceptors for NestJS
Readme
@zola_do/interceptors
Tenant and transaction interceptors for NestJS applications.
Installation
# Install individually
npm install @zola_do/interceptors
# Or via meta package
npm install @zola_do/nestjs-sharedUsage
TenantInterceptor
Automatically injects tenantId and organizationId into the query string for multi-tenant data isolation. Reads user from req.user (requires JWT auth).
import { Module } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { TenantInterceptor } from '@zola_do/interceptors';
@Module({
providers: [
{
provide: APP_INTERCEPTOR,
useClass: TenantInterceptor,
},
],
})
export class AppModule {}Or apply to specific controllers:
import { Controller, UseInterceptors } from '@nestjs/common';
import { TenantInterceptor } from '@zola_do/interceptors';
@Controller('orders')
@UseInterceptors(TenantInterceptor)
export class OrdersController {}Skip tenant filtering on specific routes using @IgnoreTenantInterceptor() from @zola_do/core:
import { IgnoreTenantInterceptor } from '@zola_do/core';
@Get('global-stats')
@IgnoreTenantInterceptor()
getGlobalStats() {}TransactionInterceptor
Wraps request handlers in a database transaction. Use for routes that must commit or rollback atomically:
import { Controller, UseInterceptors } from '@nestjs/common';
import { TransactionInterceptor } from '@zola_do/interceptors';
@Controller('payments')
@UseInterceptors(TransactionInterceptor)
export class PaymentsController {
@Post('process')
async processPayment() {
// All DB operations in this handler run in a single transaction
}
}Exports
TenantInterceptor— Injects tenant/organization filters into queriesTransactionInterceptor— Wraps handlers in DB transactions
Related Packages
- @zola_do/core —
@IgnoreTenantInterceptordecorator - @zola_do/collection-query — Query format used by TenantInterceptor
- @zola_do/authorization — JWT auth populates
req.userfor TenantInterceptor
