Upsert ArvanCloud DNS records when a super-admin adds or updates a domain.

Tenant zones get an apex ANAME and CNAMEs for www, business, customer, and api without storing origin IPs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-08-14 11:16:35 +03:30
co-authored by Cursor
parent d08a85cee5
commit 30119e6d9e
6 changed files with 301 additions and 2 deletions
@@ -2,6 +2,7 @@ import {
BadRequestException,
ConflictException,
ForbiddenException,
HttpException,
Injectable,
NotFoundException,
} from '@nestjs/common';
@@ -40,6 +41,7 @@ import {
DEFAULT_ENABLED_BUSINESS_MODULES,
DEFAULT_HOME_CHARTS,
} from '../business-settings/business-settings.types';
import { ArvanDnsService } from '../arvan-dns/arvan-dns.service';
import { WebsiteDeployAgentService } from '../website-deploy/website-deploy-agent.service';
import {
deploySlugFromHost,
@@ -88,6 +90,7 @@ export class BusinessAdminService {
private readonly legacyMigrate: LegacyMigrateService,
private readonly legacyPurge: LegacyPurgeService,
private readonly websiteDeployAgent: WebsiteDeployAgentService,
private readonly arvanDns: ArvanDnsService,
) {}
private async assertSuperAdmin(actor: AuthUser) {
@@ -545,9 +548,12 @@ export class BusinessAdminService {
},
});
const dnsError = await this.applyArvanDns(host);
return {
...domain,
provisionError,
dnsError,
};
}
@@ -642,12 +648,35 @@ export class BusinessAdminService {
},
});
const dnsError = await this.applyArvanDns(host);
return {
...updated,
provisionError,
dnsError,
};
}
private async applyArvanDns(host: string): Promise<string | null> {
try {
await this.arvanDns.ensureTenantRecords(host);
return null;
} catch (err) {
if (err instanceof HttpException) {
const res = err.getResponse();
if (typeof res === 'string') return res;
if (res && typeof res === 'object' && 'message' in res) {
const message = (res as { message: unknown }).message;
return Array.isArray(message) ? message.map(String).join(', ') : String(message);
}
}
if (err && typeof err === 'object' && 'message' in err && typeof err.message === 'string') {
return err.message;
}
return 'Arvan DNS update failed';
}
}
async disable(businessIdRaw: string, dto: DisableBusinessDto, actor: AuthUser) {
await this.assertSuperAdmin(actor);