fix(typescript): Refactor types and interfaces to use consistent I prefix and update related tests
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import type { AcmeOptions } from '../models/certificate-types.js';
|
||||
import type { IAcmeOptions } from '../models/certificate-types.js';
|
||||
import { ensureCertificateDirectory } from '../utils/certificate-helpers.js';
|
||||
// We'll need to update this import when we move the Port80Handler
|
||||
import { Port80Handler } from '../../http/port80/port80-handler.js';
|
||||
@ -12,7 +12,7 @@ import { Port80Handler } from '../../http/port80/port80-handler.js';
|
||||
* @returns A new Port80Handler instance
|
||||
*/
|
||||
export function buildPort80Handler(
|
||||
options: AcmeOptions
|
||||
options: IAcmeOptions
|
||||
): Port80Handler {
|
||||
if (options.certificateStore) {
|
||||
ensureCertificateDirectory(options.certificateStore);
|
||||
@ -32,7 +32,7 @@ export function createDefaultAcmeOptions(
|
||||
email: string,
|
||||
certificateStore: string,
|
||||
useProduction: boolean = false
|
||||
): AcmeOptions {
|
||||
): IAcmeOptions {
|
||||
return {
|
||||
accountEmail: email,
|
||||
enabled: true,
|
||||
|
@ -1,12 +1,12 @@
|
||||
import * as plugins from '../../plugins.js';
|
||||
import type { AcmeOptions, CertificateData } from '../models/certificate-types.js';
|
||||
import type { IAcmeOptions, ICertificateData } from '../models/certificate-types.js';
|
||||
import { CertificateEvents } from '../events/certificate-events.js';
|
||||
|
||||
/**
|
||||
* Manages ACME challenges and certificate validation
|
||||
*/
|
||||
export class AcmeChallengeHandler extends plugins.EventEmitter {
|
||||
private options: AcmeOptions;
|
||||
private options: IAcmeOptions;
|
||||
private client: any; // ACME client from plugins
|
||||
private pendingChallenges: Map<string, any>;
|
||||
|
||||
@ -14,7 +14,7 @@ export class AcmeChallengeHandler extends plugins.EventEmitter {
|
||||
* Creates a new ACME challenge handler
|
||||
* @param options ACME configuration options
|
||||
*/
|
||||
constructor(options: AcmeOptions) {
|
||||
constructor(options: IAcmeOptions) {
|
||||
super();
|
||||
this.options = options;
|
||||
this.pendingChallenges = new Map();
|
||||
|
@ -25,8 +25,8 @@ export * from './storage/file-storage.js';
|
||||
// Convenience function to create a certificate provisioner with common settings
|
||||
import { CertProvisioner } from './providers/cert-provisioner.js';
|
||||
import { buildPort80Handler } from './acme/acme-factory.js';
|
||||
import type { AcmeOptions, DomainForwardConfig } from './models/certificate-types.js';
|
||||
import type { DomainConfig } from '../forwarding/config/domain-config.js';
|
||||
import type { IAcmeOptions, IDomainForwardConfig } from './models/certificate-types.js';
|
||||
import type { IDomainConfig } from '../forwarding/config/domain-config.js';
|
||||
|
||||
/**
|
||||
* Creates a complete certificate provisioning system with default settings
|
||||
@ -37,8 +37,8 @@ import type { DomainConfig } from '../forwarding/config/domain-config.js';
|
||||
* @returns Configured CertProvisioner
|
||||
*/
|
||||
export function createCertificateProvisioner(
|
||||
domainConfigs: DomainConfig[],
|
||||
acmeOptions: AcmeOptions,
|
||||
domainConfigs: IDomainConfig[],
|
||||
acmeOptions: IAcmeOptions,
|
||||
networkProxyBridge: any, // Placeholder until NetworkProxyBridge is migrated
|
||||
certProvider?: any // Placeholder until cert provider type is properly defined
|
||||
): CertProvisioner {
|
||||
|
@ -84,4 +84,5 @@ export interface IAcmeOptions {
|
||||
certificateStore?: string; // Directory to store certificates
|
||||
skipConfiguredCerts?: boolean; // Skip domains with existing certificates
|
||||
domainForwards?: IDomainForwardConfig[]; // Domain-specific forwarding configs
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,34 +1,34 @@
|
||||
import * as plugins from '../../plugins.js';
|
||||
import type { DomainConfig } from '../../forwarding/config/domain-config.js';
|
||||
import type { CertificateData, DomainForwardConfig, DomainOptions } from '../models/certificate-types.js';
|
||||
import type { IDomainConfig } from '../../forwarding/config/domain-config.js';
|
||||
import type { ICertificateData, IDomainForwardConfig, IDomainOptions } from '../models/certificate-types.js';
|
||||
import { Port80HandlerEvents, CertProvisionerEvents } from '../events/certificate-events.js';
|
||||
import { Port80Handler } from '../../http/port80/port80-handler.js';
|
||||
// We need to define this interface until we migrate NetworkProxyBridge
|
||||
interface NetworkProxyBridge {
|
||||
applyExternalCertificate(certData: CertificateData): void;
|
||||
interface INetworkProxyBridge {
|
||||
applyExternalCertificate(certData: ICertificateData): void;
|
||||
}
|
||||
|
||||
// This will be imported after NetworkProxyBridge is migrated
|
||||
// import type { NetworkProxyBridge } from '../../proxies/smart-proxy/network-proxy-bridge.js';
|
||||
|
||||
// For backward compatibility
|
||||
export type ISmartProxyCertProvisionObject = plugins.tsclass.network.ICert | 'http01';
|
||||
export type TSmartProxyCertProvisionObject = plugins.tsclass.network.ICert | 'http01';
|
||||
|
||||
/**
|
||||
* Type for static certificate provisioning
|
||||
*/
|
||||
export type CertProvisionObject = plugins.tsclass.network.ICert | 'http01' | 'dns01';
|
||||
export type TCertProvisionObject = plugins.tsclass.network.ICert | 'http01' | 'dns01';
|
||||
|
||||
/**
|
||||
* CertProvisioner manages certificate provisioning and renewal workflows,
|
||||
* unifying static certificates and HTTP-01 challenges via Port80Handler.
|
||||
*/
|
||||
export class CertProvisioner extends plugins.EventEmitter {
|
||||
private domainConfigs: DomainConfig[];
|
||||
private domainConfigs: IDomainConfig[];
|
||||
private port80Handler: Port80Handler;
|
||||
private networkProxyBridge: NetworkProxyBridge;
|
||||
private certProvisionFunction?: (domain: string) => Promise<CertProvisionObject>;
|
||||
private forwardConfigs: DomainForwardConfig[];
|
||||
private networkProxyBridge: INetworkProxyBridge;
|
||||
private certProvisionFunction?: (domain: string) => Promise<TCertProvisionObject>;
|
||||
private forwardConfigs: IDomainForwardConfig[];
|
||||
private renewThresholdDays: number;
|
||||
private renewCheckIntervalHours: number;
|
||||
private autoRenew: boolean;
|
||||
@ -47,14 +47,14 @@ export class CertProvisioner extends plugins.EventEmitter {
|
||||
* @param forwardConfigs Domain forwarding configurations for ACME challenges
|
||||
*/
|
||||
constructor(
|
||||
domainConfigs: DomainConfig[],
|
||||
domainConfigs: IDomainConfig[],
|
||||
port80Handler: Port80Handler,
|
||||
networkProxyBridge: NetworkProxyBridge,
|
||||
certProvider?: (domain: string) => Promise<CertProvisionObject>,
|
||||
networkProxyBridge: INetworkProxyBridge,
|
||||
certProvider?: (domain: string) => Promise<TCertProvisionObject>,
|
||||
renewThresholdDays: number = 30,
|
||||
renewCheckIntervalHours: number = 24,
|
||||
autoRenew: boolean = true,
|
||||
forwardConfigs: DomainForwardConfig[] = []
|
||||
forwardConfigs: IDomainForwardConfig[] = []
|
||||
) {
|
||||
super();
|
||||
this.domainConfigs = domainConfigs;
|
||||
@ -92,11 +92,11 @@ export class CertProvisioner extends plugins.EventEmitter {
|
||||
*/
|
||||
private setupEventSubscriptions(): void {
|
||||
// We need to reimplement subscribeToPort80Handler here
|
||||
this.port80Handler.on(Port80HandlerEvents.CERTIFICATE_ISSUED, (data: CertificateData) => {
|
||||
this.port80Handler.on(Port80HandlerEvents.CERTIFICATE_ISSUED, (data: ICertificateData) => {
|
||||
this.emit(CertProvisionerEvents.CERTIFICATE_ISSUED, { ...data, source: 'http01', isRenewal: false });
|
||||
});
|
||||
|
||||
this.port80Handler.on(Port80HandlerEvents.CERTIFICATE_RENEWED, (data: CertificateData) => {
|
||||
this.port80Handler.on(Port80HandlerEvents.CERTIFICATE_RENEWED, (data: ICertificateData) => {
|
||||
this.emit(CertProvisionerEvents.CERTIFICATE_RENEWED, { ...data, source: 'http01', isRenewal: true });
|
||||
});
|
||||
|
||||
@ -110,7 +110,7 @@ export class CertProvisioner extends plugins.EventEmitter {
|
||||
*/
|
||||
private setupForwardingConfigs(): void {
|
||||
for (const config of this.forwardConfigs) {
|
||||
const domainOptions: DomainOptions = {
|
||||
const domainOptions: IDomainOptions = {
|
||||
domainName: config.domain,
|
||||
sslRedirect: config.sslRedirect || false,
|
||||
acmeMaintenance: false,
|
||||
@ -138,7 +138,7 @@ export class CertProvisioner extends plugins.EventEmitter {
|
||||
*/
|
||||
private async provisionDomain(domain: string): Promise<void> {
|
||||
const isWildcard = domain.includes('*');
|
||||
let provision: CertProvisionObject = 'http01';
|
||||
let provision: TCertProvisionObject = 'http01';
|
||||
|
||||
// Try to get a certificate from the provision function
|
||||
if (this.certProvisionFunction) {
|
||||
@ -174,7 +174,7 @@ export class CertProvisioner extends plugins.EventEmitter {
|
||||
// Static certificate (e.g., DNS-01 provisioned or user-provided)
|
||||
this.provisionMap.set(domain, 'static');
|
||||
const certObj = provision as plugins.tsclass.network.ICert;
|
||||
const certData: CertificateData = {
|
||||
const certData: ICertificateData = {
|
||||
domain: certObj.domainName,
|
||||
certificate: certObj.publicKey,
|
||||
privateKey: certObj.privateKey,
|
||||
@ -235,7 +235,7 @@ export class CertProvisioner extends plugins.EventEmitter {
|
||||
|
||||
if (provision !== 'http01' && provision !== 'dns01') {
|
||||
const certObj = provision as plugins.tsclass.network.ICert;
|
||||
const certData: CertificateData = {
|
||||
const certData: ICertificateData = {
|
||||
domain: certObj.domainName,
|
||||
certificate: certObj.publicKey,
|
||||
privateKey: certObj.privateKey,
|
||||
@ -267,7 +267,7 @@ export class CertProvisioner extends plugins.EventEmitter {
|
||||
const isWildcard = domain.includes('*');
|
||||
|
||||
// Determine provisioning method
|
||||
let provision: CertProvisionObject = 'http01';
|
||||
let provision: TCertProvisionObject = 'http01';
|
||||
|
||||
if (this.certProvisionFunction) {
|
||||
provision = await this.certProvisionFunction(domain);
|
||||
@ -288,7 +288,7 @@ export class CertProvisioner extends plugins.EventEmitter {
|
||||
} else {
|
||||
// Static certificate (e.g., DNS-01 provisioned) supports wildcards
|
||||
const certObj = provision as plugins.tsclass.network.ICert;
|
||||
const certData: CertificateData = {
|
||||
const certData: ICertificateData = {
|
||||
domain: certObj.domainName,
|
||||
certificate: certObj.publicKey,
|
||||
privateKey: certObj.privateKey,
|
||||
@ -311,7 +311,7 @@ export class CertProvisioner extends plugins.EventEmitter {
|
||||
sslRedirect?: boolean;
|
||||
acmeMaintenance?: boolean;
|
||||
}): Promise<void> {
|
||||
const domainOptions: DomainOptions = {
|
||||
const domainOptions: IDomainOptions = {
|
||||
domainName: domain,
|
||||
sslRedirect: options?.sslRedirect || true,
|
||||
acmeMaintenance: options?.acmeMaintenance || true
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as plugins from '../../plugins.js';
|
||||
import type { CertificateData, Certificates } from '../models/certificate-types.js';
|
||||
import type { ICertificateData, ICertificates } from '../models/certificate-types.js';
|
||||
import { ensureCertificateDirectory } from '../utils/certificate-helpers.js';
|
||||
|
||||
/**
|
||||
@ -21,10 +21,10 @@ export class FileStorage {
|
||||
|
||||
/**
|
||||
* Save a certificate to the file system
|
||||
* @param domain Domain name
|
||||
* @param domain Domain name
|
||||
* @param certData Certificate data to save
|
||||
*/
|
||||
public async saveCertificate(domain: string, certData: CertificateData): Promise<void> {
|
||||
public async saveCertificate(domain: string, certData: ICertificateData): Promise<void> {
|
||||
const sanitizedDomain = this.sanitizeDomain(domain);
|
||||
const certDir = path.join(this.storageDir, sanitizedDomain);
|
||||
ensureCertificateDirectory(certDir);
|
||||
@ -57,7 +57,7 @@ export class FileStorage {
|
||||
* @param domain Domain name
|
||||
* @returns Certificate data if found, null otherwise
|
||||
*/
|
||||
public async loadCertificate(domain: string): Promise<CertificateData | null> {
|
||||
public async loadCertificate(domain: string): Promise<ICertificateData | null> {
|
||||
const sanitizedDomain = this.sanitizeDomain(domain);
|
||||
const certDir = path.join(this.storageDir, sanitizedDomain);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import type { Certificates } from '../models/certificate-types.js';
|
||||
import type { ICertificates } from '../models/certificate-types.js';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
@ -9,7 +9,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
* Loads the default SSL certificates from the assets directory
|
||||
* @returns The certificate key pair
|
||||
*/
|
||||
export function loadDefaultCertificates(): Certificates {
|
||||
export function loadDefaultCertificates(): ICertificates {
|
||||
try {
|
||||
// Need to adjust path from /ts/certificate/utils to /assets/certs
|
||||
const certPath = path.join(__dirname, '..', '..', '..', 'assets', 'certs');
|
||||
|
Reference in New Issue
Block a user