feat(routing): routing_rules schema + types — M4-001/002/003 (#315)
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #315.
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
import { Body, Controller, Get, Inject, Post, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Inject, Param, Post, UseGuards } from '@nestjs/common';
|
||||
import type { RoutingCriteria } from '@mosaic/types';
|
||||
import { AuthGuard } from '../auth/auth.guard.js';
|
||||
import { CurrentUser } from '../auth/current-user.decorator.js';
|
||||
import { ProviderService } from './provider.service.js';
|
||||
import { ProviderCredentialsService } from './provider-credentials.service.js';
|
||||
import { RoutingService } from './routing.service.js';
|
||||
import type { TestConnectionDto, TestConnectionResultDto } from './provider.dto.js';
|
||||
import type {
|
||||
StoreCredentialDto,
|
||||
ProviderCredentialSummaryDto,
|
||||
} from './provider-credentials.dto.js';
|
||||
|
||||
@Controller('api/providers')
|
||||
@UseGuards(AuthGuard)
|
||||
export class ProvidersController {
|
||||
constructor(
|
||||
@Inject(ProviderService) private readonly providerService: ProviderService,
|
||||
@Inject(ProviderCredentialsService)
|
||||
private readonly credentialsService: ProviderCredentialsService,
|
||||
@Inject(RoutingService) private readonly routingService: RoutingService,
|
||||
) {}
|
||||
|
||||
@@ -42,4 +50,49 @@ export class ProvidersController {
|
||||
rank(@Body() criteria: RoutingCriteria) {
|
||||
return this.routingService.rank(criteria);
|
||||
}
|
||||
|
||||
// ── Credential CRUD ──────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* GET /api/providers/credentials
|
||||
* List all provider credentials for the authenticated user.
|
||||
* Returns provider names, types, and metadata — never decrypted values.
|
||||
*/
|
||||
@Get('credentials')
|
||||
listCredentials(@CurrentUser() user: { id: string }): Promise<ProviderCredentialSummaryDto[]> {
|
||||
return this.credentialsService.listProviders(user.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/providers/credentials
|
||||
* Store or update a provider credential for the authenticated user.
|
||||
* The value is encrypted before storage and never returned.
|
||||
*/
|
||||
@Post('credentials')
|
||||
async storeCredential(
|
||||
@CurrentUser() user: { id: string },
|
||||
@Body() body: StoreCredentialDto,
|
||||
): Promise<{ success: boolean; provider: string }> {
|
||||
await this.credentialsService.store(
|
||||
user.id,
|
||||
body.provider,
|
||||
body.type,
|
||||
body.value,
|
||||
body.metadata,
|
||||
);
|
||||
return { success: true, provider: body.provider };
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /api/providers/credentials/:provider
|
||||
* Remove a stored credential for the authenticated user.
|
||||
*/
|
||||
@Delete('credentials/:provider')
|
||||
async removeCredential(
|
||||
@CurrentUser() user: { id: string },
|
||||
@Param('provider') provider: string,
|
||||
): Promise<{ success: boolean; provider: string }> {
|
||||
await this.credentialsService.remove(user.id, provider);
|
||||
return { success: true, provider };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user