import type { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common'; import { Injectable } from '@nestjs/common'; import type { FastifyReply } from 'fastify'; import type { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { withResponseMeta } from '../core/http.js'; @Injectable() export class ApiEnvelopeInterceptor implements NestInterceptor { intercept(context: ExecutionContext, next: CallHandler): Observable { const reply = context.switchToHttp().getResponse(); return next.handle().pipe(map(body => withResponseMeta(body, String(reply.getHeader('x-request-id') || '')))); } }