UNPKG

bb-inspired

Version:

Core library for BB-inspired NestJS backend

52 lines 2.65 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var TenantValidationPipe_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.TenantValidationPipe = void 0; const common_1 = require("@nestjs/common"); const logger_1 = require("../../../utils/logger"); let TenantValidationPipe = TenantValidationPipe_1 = class TenantValidationPipe { constructor() { this.logger = new logger_1.AppLogger(TenantValidationPipe_1.name); } transform(value) { if (value && typeof value === 'object' && 'tenantId' in value) { value = value.tenantId; } if (value === undefined || value === null) { this.logger.warn('Missing tenant ID'); throw new common_1.BadRequestException('Tenant ID is required'); } if (typeof value !== 'string' && typeof value !== 'number') { this.logger.warn('Invalid tenant ID format'); throw new common_1.BadRequestException('Tenant ID must be a string or number'); } if (typeof value === 'string') { if (value.trim().length === 0) { this.logger.warn('Empty tenant ID'); throw new common_1.BadRequestException('Tenant ID cannot be empty'); } const sanitizedTenantId = value.trim().replace(/[^a-zA-Z0-9\-_\.]/g, ''); if (sanitizedTenantId !== value.trim()) { this.logger.warn('Tenant ID contains invalid characters'); throw new common_1.BadRequestException('Tenant ID contains invalid characters'); } return sanitizedTenantId; } if (value <= 0) { this.logger.warn('Invalid tenant ID: must be positive'); throw new common_1.BadRequestException('Tenant ID must be a positive number'); } return value; } }; exports.TenantValidationPipe = TenantValidationPipe; exports.TenantValidationPipe = TenantValidationPipe = TenantValidationPipe_1 = __decorate([ (0, common_1.Injectable)() ], TenantValidationPipe); //# sourceMappingURL=tenant-validation.pipe.js.map