BREAKING CHANGE(email-ops): migrate email operations to catalog-compatible email model and simplify UI/router

This commit is contained in:
2026-02-22 00:45:01 +00:00
parent 4759c4f011
commit 48d3d1218f
12 changed files with 338 additions and 1561 deletions

View File

@@ -2,162 +2,93 @@ import * as plugins from '../plugins.js';
import * as authInterfaces from '../data/auth.js';
// ============================================================================
// Email Queue Item Interface (matches backend IQueueItem)
// Catalog-compatible email types (matches @serve.zone/catalog IEmail/IEmailDetail)
// ============================================================================
export type TEmailQueueStatus = 'pending' | 'processing' | 'delivered' | 'failed' | 'deferred';
export type TEmailStatus = 'delivered' | 'bounced' | 'rejected' | 'deferred' | 'pending';
export type TEmailDirection = 'inbound' | 'outbound';
export interface IEmailQueueItem {
export interface IEmail {
id: string;
processingMode: 'forward' | 'mta' | 'process';
status: TEmailQueueStatus;
attempts: number;
nextAttempt: number; // timestamp
lastError?: string;
createdAt: number; // timestamp
updatedAt: number; // timestamp
deliveredAt?: number; // timestamp
// Email details extracted from processingResult
from?: string;
to?: string[];
subject?: string;
direction: TEmailDirection;
status: TEmailStatus;
from: string;
to: string;
subject: string;
timestamp: string;
messageId: string;
size: string;
}
export interface ISmtpLogEntry {
timestamp: string;
direction: 'client' | 'server';
command: string;
responseCode?: number;
}
export interface IConnectionInfo {
sourceIp: string;
sourceHostname: string;
destinationIp: string;
destinationPort: number;
tlsVersion: string;
tlsCipher: string;
authenticated: boolean;
authMethod: string;
authUser: string;
}
export interface IAuthenticationResults {
spf: 'pass' | 'fail' | 'softfail' | 'neutral' | 'none';
spfDomain: string;
dkim: 'pass' | 'fail' | 'none';
dkimDomain: string;
dmarc: 'pass' | 'fail' | 'none';
dmarcPolicy: string;
}
export interface IEmailDetail extends IEmail {
toList: string[];
cc?: string[];
smtpLog: ISmtpLogEntry[];
connectionInfo: IConnectionInfo;
authenticationResults: IAuthenticationResults;
rejectionReason?: string;
bounceMessage?: string;
headers: Record<string, string>;
body: string;
}
// ============================================================================
// Bounce Record Interface (matches backend BounceRecord)
// Get All Emails Request
// ============================================================================
export type TBounceType =
| 'invalid_recipient'
| 'domain_not_found'
| 'mailbox_full'
| 'mailbox_inactive'
| 'blocked'
| 'spam_related'
| 'policy_related'
| 'server_unavailable'
| 'temporary_failure'
| 'quota_exceeded'
| 'network_error'
| 'timeout'
| 'auto_response'
| 'challenge_response'
| 'unknown';
export type TBounceCategory = 'hard' | 'soft' | 'auto_response' | 'unknown';
export interface IBounceRecord {
id: string;
originalEmailId?: string;
recipient: string;
sender: string;
domain: string;
subject?: string;
bounceType: TBounceType;
bounceCategory: TBounceCategory;
timestamp: number;
smtpResponse?: string;
diagnosticCode?: string;
statusCode?: string;
processed: boolean;
retryCount?: number;
nextRetryTime?: number;
}
// ============================================================================
// Security Incident Interface (matches backend ISecurityEvent)
// ============================================================================
export type TSecurityLogLevel = 'info' | 'warn' | 'error' | 'critical';
export type TSecurityEventType =
| 'authentication'
| 'access_control'
| 'email_validation'
| 'email_processing'
| 'email_forwarding'
| 'email_delivery'
| 'dkim'
| 'spf'
| 'dmarc'
| 'rate_limit'
| 'rate_limiting'
| 'spam'
| 'malware'
| 'connection'
| 'data_exposure'
| 'configuration'
| 'ip_reputation'
| 'rejected_connection';
export interface ISecurityIncident {
timestamp: number;
level: TSecurityLogLevel;
type: TSecurityEventType;
message: string;
details?: any;
ipAddress?: string;
userId?: string;
sessionId?: string;
emailId?: string;
domain?: string;
action?: string;
result?: string;
success?: boolean;
}
// ============================================================================
// Get Queued Emails Request
// ============================================================================
export interface IReq_GetQueuedEmails extends plugins.typedrequestInterfaces.implementsTR<
export interface IReq_GetAllEmails extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_GetQueuedEmails
IReq_GetAllEmails
> {
method: 'getQueuedEmails';
method: 'getAllEmails';
request: {
identity?: authInterfaces.IIdentity;
status?: TEmailQueueStatus;
limit?: number;
offset?: number;
};
response: {
items: IEmailQueueItem[];
total: number;
emails: IEmail[];
};
}
// ============================================================================
// Get Sent Emails Request
// Get Email Detail Request
// ============================================================================
export interface IReq_GetSentEmails extends plugins.typedrequestInterfaces.implementsTR<
export interface IReq_GetEmailDetail extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_GetSentEmails
IReq_GetEmailDetail
> {
method: 'getSentEmails';
method: 'getEmailDetail';
request: {
identity?: authInterfaces.IIdentity;
limit?: number;
offset?: number;
emailId: string;
};
response: {
items: IEmailQueueItem[];
total: number;
};
}
// ============================================================================
// Get Failed Emails Request
// ============================================================================
export interface IReq_GetFailedEmails extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_GetFailedEmails
> {
method: 'getFailedEmails';
request: {
identity?: authInterfaces.IIdentity;
limit?: number;
offset?: number;
};
response: {
items: IEmailQueueItem[];
total: number;
email: IEmailDetail | null;
};
}
@@ -179,61 +110,3 @@ export interface IReq_ResendEmail extends plugins.typedrequestInterfaces.impleme
error?: string;
};
}
// ============================================================================
// Get Security Incidents Request
// ============================================================================
export interface IReq_GetSecurityIncidents extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_GetSecurityIncidents
> {
method: 'getSecurityIncidents';
request: {
identity?: authInterfaces.IIdentity;
type?: TSecurityEventType;
level?: TSecurityLogLevel;
limit?: number;
};
response: {
incidents: ISecurityIncident[];
total: number;
};
}
// ============================================================================
// Get Bounce Records Request
// ============================================================================
export interface IReq_GetBounceRecords extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_GetBounceRecords
> {
method: 'getBounceRecords';
request: {
identity?: authInterfaces.IIdentity;
limit?: number;
offset?: number;
};
response: {
records: IBounceRecord[];
suppressionList: string[];
total: number;
};
}
// ============================================================================
// Remove from Suppression List Request
// ============================================================================
export interface IReq_RemoveFromSuppressionList extends plugins.typedrequestInterfaces.implementsTR<
plugins.typedrequestInterfaces.ITypedRequest,
IReq_RemoveFromSuppressionList
> {
method: 'removeFromSuppressionList';
request: {
identity?: authInterfaces.IIdentity;
email: string;
};
response: {
success: boolean;
error?: string;
};
}