feat(certificates): add certificate overview and reprovisioning in ops UI and API; track SmartProxy certificate events

This commit is contained in:
2026-02-13 17:05:33 +00:00
parent d10896196d
commit c5e2c262b7
16 changed files with 757 additions and 15 deletions

View File

@@ -53,6 +53,14 @@ export interface INetworkState {
error: string | null;
}
export interface ICertificateState {
certificates: interfaces.requests.ICertificateInfo[];
summary: { total: number; valid: number; expiring: number; expired: number; failed: number; unknown: number };
isLoading: boolean;
error: string | null;
lastUpdated: number;
}
export interface IEmailOpsState {
currentView: 'queued' | 'sent' | 'failed' | 'received' | 'security';
queuedEmails: interfaces.requests.IEmailQueueItem[];
@@ -103,7 +111,7 @@ export const configStatePart = await appState.getStatePart<IConfigState>(
// Determine initial view from URL path
const getInitialView = (): string => {
const path = typeof window !== 'undefined' ? window.location.pathname : '/';
const validViews = ['overview', 'network', 'emails', 'logs', 'configuration', 'security'];
const validViews = ['overview', 'network', 'emails', 'logs', 'configuration', 'security', 'certificates'];
const segments = path.split('/').filter(Boolean);
const view = segments[0];
return validViews.includes(view) ? view : 'overview';
@@ -162,6 +170,18 @@ export const emailOpsStatePart = await appState.getStatePart<IEmailOpsState>(
'soft'
);
export const certificateStatePart = await appState.getStatePart<ICertificateState>(
'certificates',
{
certificates: [],
summary: { total: 0, valid: 0, expiring: 0, expired: 0, failed: 0, unknown: 0 },
isLoading: false,
error: null,
lastUpdated: 0,
},
'soft'
);
// Actions for state management
interface IActionContext {
identity: interfaces.data.IIdentity | null;
@@ -340,7 +360,14 @@ export const setActiveViewAction = uiStatePart.createAction<string>(async (state
networkStatePart.dispatchAction(fetchNetworkStatsAction, null);
}, 100);
}
// If switching to certificates view, ensure we fetch certificate data
if (viewName === 'certificates' && currentState.activeView !== 'certificates') {
setTimeout(() => {
certificateStatePart.dispatchAction(fetchCertificateOverviewAction, null);
}, 100);
}
return {
...currentState,
activeView: viewName,
@@ -641,6 +668,66 @@ export const removeFromSuppressionListAction = emailOpsStatePart.createAction<st
}
);
// ============================================================================
// Certificate Actions
// ============================================================================
export const fetchCertificateOverviewAction = certificateStatePart.createAction(async (statePartArg) => {
const context = getActionContext();
const currentState = statePartArg.getState();
try {
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
interfaces.requests.IReq_GetCertificateOverview
>('/typedrequest', 'getCertificateOverview');
const response = await request.fire({
identity: context.identity,
});
return {
certificates: response.certificates,
summary: response.summary,
isLoading: false,
error: null,
lastUpdated: Date.now(),
};
} catch (error) {
return {
...currentState,
isLoading: false,
error: error instanceof Error ? error.message : 'Failed to fetch certificate overview',
};
}
});
export const reprovisionCertificateAction = certificateStatePart.createAction<string>(
async (statePartArg, routeName) => {
const context = getActionContext();
const currentState = statePartArg.getState();
try {
const request = new plugins.domtools.plugins.typedrequest.TypedRequest<
interfaces.requests.IReq_ReprovisionCertificate
>('/typedrequest', 'reprovisionCertificate');
await request.fire({
identity: context.identity,
routeName,
});
// Re-fetch overview after reprovisioning
await certificateStatePart.dispatchAction(fetchCertificateOverviewAction, null);
return statePartArg.getState();
} catch (error) {
return {
...currentState,
error: error instanceof Error ? error.message : 'Failed to reprovision certificate',
};
}
}
);
// Combined refresh action for efficient polling
async function dispatchCombinedRefreshAction() {
const context = getActionContext();
@@ -725,6 +812,15 @@ async function dispatchCombinedRefreshAction() {
});
}
}
// Refresh certificate data if on certificates view
if (currentView === 'certificates') {
try {
await certificateStatePart.dispatchAction(fetchCertificateOverviewAction, null);
} catch (error) {
console.error('Certificate refresh failed:', error);
}
}
} catch (error) {
console.error('Combined refresh failed:', error);
}