Spaces:
Runtime error
Runtime error
| import { Controller, Get, Query } from '@nestjs/common'; | |
| import { ApiTags, ApiOperation, ApiResponse, ApiQuery } from '@nestjs/swagger'; | |
| import { WebhookService } from './webhook.service'; | |
| import { WebhookResponseDto } from './dto'; | |
| import { WebhookDeliveryFailure } from './entities/webhook-delivery-failure.entity'; | |
| import { RequireRole, CurrentApiKey } from '../auth/decorators/auth.decorators'; | |
| import { ApiKey, ApiKeyRole } from '../auth/entities/api-key.entity'; | |
| ('webhooks') | |
| ('webhooks') | |
| export class WebhooksListController { | |
| constructor(private readonly webhookService: WebhookService) {} | |
| ('delivery-failures') | |
| (ApiKeyRole.ADMIN) | |
| ({ summary: 'List recently-failed webhook deliveries (all retries exhausted)' }) | |
| ({ status: 200, description: 'Permanently-failed webhook deliveries, most recent first' }) | |
| ({ name: 'sessionId', required: false, description: 'Filter to a single session' }) | |
| ({ name: 'limit', required: false, description: 'Max records to return (1-1000, default 1000)' }) | |
| ({ name: 'offset', required: false, description: 'Number of records to skip (for paging)' }) | |
| async deliveryFailures( | |
| () apiKey?: ApiKey, | |
| ('sessionId') sessionId?: string, | |
| ('limit') limit?: string, | |
| ('offset') offset?: string, | |
| ): Promise<WebhookDeliveryFailure[]> { | |
| // Scope to the calling key's allowedSessions so a session-restricted ADMIN key cannot read another | |
| // session's failed-delivery URLs/errors via the `sessionId` query param (which bypasses the guard). | |
| return this.webhookService.listDeliveryFailures( | |
| { | |
| sessionId, | |
| limit: limit ? parseInt(limit, 10) : undefined, | |
| offset: offset ? parseInt(offset, 10) : undefined, | |
| }, | |
| apiKey?.allowedSessions, | |
| ); | |
| } | |
| () | |
| (ApiKeyRole.OPERATOR) | |
| ({ summary: 'List webhooks visible to the calling key (scoped to its allowed sessions)' }) | |
| ({ | |
| status: 200, | |
| description: 'List of webhooks', | |
| type: [WebhookResponseDto], | |
| }) | |
| ({ name: 'limit', required: false, description: 'Max webhooks to return (1-1000, default 1000)' }) | |
| ({ name: 'offset', required: false, description: 'Number of webhooks to skip (for paging)' }) | |
| async findAll( | |
| () apiKey?: ApiKey, | |
| ('limit') limit?: string, | |
| ('offset') offset?: string, | |
| ): Promise<WebhookResponseDto[]> { | |
| // Scope to the key's allowedSessions so a session-restricted key cannot enumerate every | |
| // session's webhook URLs. A null/empty allowlist (e.g. ADMIN) still sees all. | |
| return WebhookResponseDto.fromEntities( | |
| await this.webhookService.findAll(apiKey?.allowedSessions, { | |
| limit: limit ? parseInt(limit, 10) : undefined, | |
| offset: offset ? parseInt(offset, 10) : undefined, | |
| }), | |
| ); | |
| } | |
| } | |