feat: Remove domain from AWS if no longer in use by other projects
This commit is contained in:
@@ -8,7 +8,7 @@ import {HttpException} from '../exceptions/index.js';
|
|||||||
import {Keys} from './keys.js';
|
import {Keys} from './keys.js';
|
||||||
import {MembershipService} from './MembershipService.js';
|
import {MembershipService} from './MembershipService.js';
|
||||||
import {NtfyService} from './NtfyService.js';
|
import {NtfyService} from './NtfyService.js';
|
||||||
import {getDomainVerificationAttributes, verifyDomain} from './SESService.js';
|
import {deleteIdentity, getDomainVerificationAttributes, verifyDomain} from './SESService.js';
|
||||||
|
|
||||||
export class DomainService {
|
export class DomainService {
|
||||||
/**
|
/**
|
||||||
@@ -249,6 +249,28 @@ export class DomainService {
|
|||||||
|
|
||||||
await prisma.domain.delete({where: {id: domainId}});
|
await prisma.domain.delete({where: {id: domainId}});
|
||||||
|
|
||||||
|
// Check if this domain is still attached to another project
|
||||||
|
const domainExistsElsewhere = await prisma.domain.findFirst({
|
||||||
|
where: {
|
||||||
|
domain: domainName,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// If domain is not used by any other project, remove it from AWS SES
|
||||||
|
if (!domainExistsElsewhere) {
|
||||||
|
try {
|
||||||
|
await deleteIdentity(domainName);
|
||||||
|
signale.info(`[DOMAIN] Removed AWS SES identity for ${domainName} (no longer used by any project)`);
|
||||||
|
} catch (error) {
|
||||||
|
// Log error but don't fail the domain removal if AWS cleanup fails
|
||||||
|
signale.error(`[DOMAIN] Failed to remove AWS SES identity for ${domainName}:`, error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
signale.info(
|
||||||
|
`[DOMAIN] Keeping AWS SES identity for ${domainName} (still used by project ${domainExistsElsewhere.projectId})`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Send notification about domain removal
|
// Send notification about domain removal
|
||||||
await NtfyService.notifyDomainRemoved(domainName, domain.project.name, domain.project.id);
|
await NtfyService.notifyDomainRemoved(domainName, domain.project.name, domain.project.id);
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
DASHBOARD_URI,
|
DASHBOARD_URI,
|
||||||
SES_CONFIGURATION_SET,
|
SES_CONFIGURATION_SET,
|
||||||
SES_CONFIGURATION_SET_NO_TRACKING,
|
SES_CONFIGURATION_SET_NO_TRACKING,
|
||||||
TRACKING_TOGGLE_ENABLED
|
TRACKING_TOGGLE_ENABLED,
|
||||||
} from '../app/constants.js';
|
} from '../app/constants.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -258,6 +258,13 @@ export const disableFeedbackForwarding = async (domain: string): Promise<void> =
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a verified domain identity from AWS SES
|
||||||
|
*/
|
||||||
|
export const deleteIdentity = async (domain: string): Promise<void> => {
|
||||||
|
await ses.deleteIdentity({Identity: domain});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get AWS SES account sending quota and rate limit
|
* Get AWS SES account sending quota and rate limit
|
||||||
* @returns MaxSendRate (emails per second) or null if the call fails
|
* @returns MaxSendRate (emails per second) or null if the call fails
|
||||||
|
|||||||
Reference in New Issue
Block a user