34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
|
import type { Port80Handler } from '../port80handler/classes.port80handler.js';
|
||
|
import { Port80HandlerEvents } from './types.js';
|
||
|
import type { ICertificateData, ICertificateFailure, ICertificateExpiring } from './types.js';
|
||
|
|
||
|
/**
|
||
|
* Subscribers callback definitions for Port80Handler events
|
||
|
*/
|
||
|
export interface Port80HandlerSubscribers {
|
||
|
onCertificateIssued?: (data: ICertificateData) => void;
|
||
|
onCertificateRenewed?: (data: ICertificateData) => void;
|
||
|
onCertificateFailed?: (data: ICertificateFailure) => void;
|
||
|
onCertificateExpiring?: (data: ICertificateExpiring) => void;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Subscribes to Port80Handler events based on provided callbacks
|
||
|
*/
|
||
|
export function subscribeToPort80Handler(
|
||
|
handler: Port80Handler,
|
||
|
subscribers: Port80HandlerSubscribers
|
||
|
): void {
|
||
|
if (subscribers.onCertificateIssued) {
|
||
|
handler.on(Port80HandlerEvents.CERTIFICATE_ISSUED, subscribers.onCertificateIssued);
|
||
|
}
|
||
|
if (subscribers.onCertificateRenewed) {
|
||
|
handler.on(Port80HandlerEvents.CERTIFICATE_RENEWED, subscribers.onCertificateRenewed);
|
||
|
}
|
||
|
if (subscribers.onCertificateFailed) {
|
||
|
handler.on(Port80HandlerEvents.CERTIFICATE_FAILED, subscribers.onCertificateFailed);
|
||
|
}
|
||
|
if (subscribers.onCertificateExpiring) {
|
||
|
handler.on(Port80HandlerEvents.CERTIFICATE_EXPIRING, subscribers.onCertificateExpiring);
|
||
|
}
|
||
|
}
|