-
Notifications
You must be signed in to change notification settings - Fork 243
CS-37 [Improvement] - render records on trust portal settings in app for vercel #1663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
03b73ab
feat(app): show domain verification status on trust portal settings
chasprowebdev 13d98d2
Merge branch 'main' of https://github.com/trycompai/comp into chas/sh…
chasprowebdev 69113b4
Merge branch 'main' of https://github.com/trycompai/comp into chas/sh…
chasprowebdev fff9d15
feat(api): create an API to get the vercel trust portal domain status
chasprowebdev 2fe574d
fix(app): show domain verification status using api
chasprowebdev 9c17bcf
fix(api): validate incoming request data using class-validator decora…
chasprowebdev 1a5d586
fix(app): prevent API call if the domain is empty
chasprowebdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { ApiProperty } from '@nestjs/swagger'; | ||
| import { IsNotEmpty, IsString, Matches } from 'class-validator'; | ||
|
|
||
| export class GetDomainStatusDto { | ||
| @ApiProperty({ | ||
| description: 'The domain name to check status for', | ||
| example: 'portal.example.com', | ||
| }) | ||
| @IsString() | ||
| @IsNotEmpty({ message: 'domain cannot be empty' }) | ||
| @Matches(/^(?!-)[A-Za-z0-9-]+([-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,6}$/, { | ||
| message: 'domain must be a valid domain format', | ||
| }) | ||
| domain: string; | ||
| } | ||
|
|
||
| export class DomainVerificationDto { | ||
| @ApiProperty({ description: 'Verification type (e.g., TXT, CNAME)' }) | ||
| type: string; | ||
|
|
||
| @ApiProperty({ description: 'Domain for verification' }) | ||
| domain: string; | ||
|
|
||
| @ApiProperty({ description: 'Verification value' }) | ||
| value: string; | ||
|
|
||
| @ApiProperty({ | ||
| description: 'Reason for verification status', | ||
| required: false, | ||
| }) | ||
| reason?: string; | ||
| } | ||
|
|
||
| export class DomainStatusResponseDto { | ||
| @ApiProperty({ description: 'The domain name' }) | ||
| domain: string; | ||
|
|
||
| @ApiProperty({ description: 'Whether the domain is verified' }) | ||
| verified: boolean; | ||
|
|
||
| @ApiProperty({ | ||
| description: 'Verification records for the domain', | ||
| type: [DomainVerificationDto], | ||
| required: false, | ||
| }) | ||
| verification?: DomainVerificationDto[]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { | ||
| Controller, | ||
| Get, | ||
| HttpCode, | ||
| HttpStatus, | ||
| Query, | ||
| UseGuards, | ||
| } from '@nestjs/common'; | ||
| import { | ||
| ApiHeader, | ||
| ApiOperation, | ||
| ApiQuery, | ||
| ApiResponse, | ||
| ApiSecurity, | ||
| ApiTags, | ||
| } from '@nestjs/swagger'; | ||
| import { HybridAuthGuard } from '../auth/hybrid-auth.guard'; | ||
| import { | ||
| DomainStatusResponseDto, | ||
| GetDomainStatusDto, | ||
| } from './dto/domain-status.dto'; | ||
| import { TrustPortalService } from './trust-portal.service'; | ||
|
|
||
| @ApiTags('Trust Portal') | ||
| @Controller({ path: 'trust-portal', version: '1' }) | ||
| @UseGuards(HybridAuthGuard) | ||
| @ApiSecurity('apikey') | ||
| @ApiHeader({ | ||
| name: 'X-Organization-Id', | ||
| description: | ||
| 'Organization ID (required for session auth, optional for API key auth)', | ||
| required: false, | ||
| }) | ||
| export class TrustPortalController { | ||
| constructor(private readonly trustPortalService: TrustPortalService) {} | ||
|
|
||
| @Get('domain/status') | ||
| @HttpCode(HttpStatus.OK) | ||
| @ApiOperation({ | ||
| summary: 'Get domain verification status', | ||
| description: | ||
| 'Retrieve the verification status and DNS records for a custom domain configured in the Vercel trust portal project', | ||
| }) | ||
| @ApiQuery({ | ||
| name: 'domain', | ||
| description: 'The domain name to check status for', | ||
| example: 'portal.example.com', | ||
| required: true, | ||
| }) | ||
| @ApiResponse({ | ||
| status: HttpStatus.OK, | ||
| description: 'Domain status retrieved successfully', | ||
| type: DomainStatusResponseDto, | ||
| }) | ||
| @ApiResponse({ | ||
| status: HttpStatus.INTERNAL_SERVER_ERROR, | ||
| description: 'Failed to retrieve domain status from Vercel', | ||
| }) | ||
| @ApiResponse({ | ||
| status: HttpStatus.UNAUTHORIZED, | ||
| description: 'Unauthorized - Invalid or missing authentication', | ||
| }) | ||
| async getDomainStatus( | ||
| @Query() dto: GetDomainStatusDto, | ||
| ): Promise<DomainStatusResponseDto> { | ||
| return this.trustPortalService.getDomainStatus(dto); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { AuthModule } from '../auth/auth.module'; | ||
| import { TrustPortalController } from './trust-portal.controller'; | ||
| import { TrustPortalService } from './trust-portal.service'; | ||
|
|
||
| @Module({ | ||
| imports: [AuthModule], | ||
| controllers: [TrustPortalController], | ||
| providers: [TrustPortalService], | ||
| exports: [TrustPortalService], | ||
| }) | ||
| export class TrustPortalModule {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { | ||
| BadRequestException, | ||
| Injectable, | ||
| InternalServerErrorException, | ||
| Logger, | ||
| } from '@nestjs/common'; | ||
| import axios, { AxiosInstance } from 'axios'; | ||
| import { | ||
| DomainStatusResponseDto, | ||
| DomainVerificationDto, | ||
| GetDomainStatusDto, | ||
| } from './dto/domain-status.dto'; | ||
|
|
||
| interface VercelDomainVerification { | ||
| type: string; | ||
| domain: string; | ||
| value: string; | ||
| reason?: string; | ||
| } | ||
|
|
||
| interface VercelDomainResponse { | ||
| name: string; | ||
| verified: boolean; | ||
| verification?: VercelDomainVerification[]; | ||
| } | ||
|
|
||
| @Injectable() | ||
| export class TrustPortalService { | ||
| private readonly logger = new Logger(TrustPortalService.name); | ||
| private readonly vercelApi: AxiosInstance; | ||
|
|
||
| constructor() { | ||
| const bearerToken = process.env.VERCEL_ACCESS_TOKEN; | ||
|
|
||
| if (!bearerToken) { | ||
| this.logger.warn('VERCEL_ACCESS_TOKEN is not set'); | ||
| } | ||
|
|
||
| // Initialize axios instance for Vercel API | ||
| this.vercelApi = axios.create({ | ||
| baseURL: 'https://api.vercel.com', | ||
| headers: { | ||
| Authorization: `Bearer ${bearerToken || ''}`, | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| async getDomainStatus( | ||
| dto: GetDomainStatusDto, | ||
| ): Promise<DomainStatusResponseDto> { | ||
| const { domain } = dto; | ||
|
|
||
| if (!process.env.TRUST_PORTAL_PROJECT_ID) { | ||
| throw new InternalServerErrorException( | ||
| 'TRUST_PORTAL_PROJECT_ID is not configured', | ||
| ); | ||
| } | ||
|
|
||
| if (!process.env.VERCEL_TEAM_ID) { | ||
| throw new InternalServerErrorException( | ||
| 'VERCEL_TEAM_ID is not configured', | ||
| ); | ||
| } | ||
|
|
||
| if (!domain) { | ||
| throw new BadRequestException('Domain is required'); | ||
| } | ||
|
|
||
| try { | ||
| this.logger.log(`Fetching domain status for: ${domain}`); | ||
|
|
||
| // Get domain information including verification status | ||
| // Vercel API endpoint: GET /v9/projects/{projectId}/domains/{domain} | ||
| const response = await this.vercelApi.get<VercelDomainResponse>( | ||
| `/v9/projects/${process.env.TRUST_PORTAL_PROJECT_ID}/domains/${domain}`, | ||
| { | ||
| params: { | ||
| teamId: process.env.VERCEL_TEAM_ID, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| const domainInfo = response.data; | ||
|
|
||
| const verification: DomainVerificationDto[] | undefined = | ||
| domainInfo.verification?.map((v) => ({ | ||
| type: v.type, | ||
| domain: v.domain, | ||
| value: v.value, | ||
| reason: v.reason, | ||
| })); | ||
|
|
||
| return { | ||
| domain: domainInfo.name, | ||
| verified: domainInfo.verified ?? false, | ||
| verification, | ||
| }; | ||
| } catch (error) { | ||
| this.logger.error( | ||
| `Failed to get domain status for ${domain}:`, | ||
| error instanceof Error ? error.stack : error, | ||
| ); | ||
|
|
||
| // Handle axios errors with more detail | ||
| if (axios.isAxiosError(error)) { | ||
| const statusCode = error.response?.status; | ||
| const message = error.response?.data?.error?.message || error.message; | ||
| this.logger.error(`Vercel API error (${statusCode}): ${message}`); | ||
| } | ||
|
|
||
| throw new InternalServerErrorException( | ||
| 'Failed to get domain status from Vercel', | ||
| ); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| 'use client'; | ||
|
|
||
| import { useApiSWR } from '@/hooks/use-api-swr'; | ||
|
|
||
| export interface DomainVerification { | ||
| type: string; | ||
| domain: string; | ||
| value: string; | ||
| reason?: string; | ||
| } | ||
|
|
||
| export interface DomainStatusResponse { | ||
| domain: string; | ||
| verified: boolean; | ||
| verification: DomainVerification[]; | ||
| } | ||
|
|
||
| export function useDomain(domain: string) { | ||
| const endpoint = | ||
| domain && domain.trim() !== '' | ||
| ? `/v1/trust-portal/domain/status?domain=${domain}` | ||
| : null; | ||
|
|
||
| return useApiSWR<DomainStatusResponse>(endpoint); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.