fix(typescript): Refactor types and interfaces to use consistent I prefix and update related tests

This commit is contained in:
2025-05-09 22:46:53 +00:00
parent d924190680
commit f8647516b5
45 changed files with 403 additions and 392 deletions

View File

@ -1,9 +1,10 @@
import { tap, expect } from '@push.rocks/tapbundle';
import * as plugins from '../ts/plugins.js';
import { CertProvisioner } from '../ts/certificate/providers/cert-provisioner.js';
import type { DomainConfig } from '../ts/forwarding/config/forwarding-types.js';
import type { SmartProxyCertProvisionObject } from '../ts/certificate/models/certificate-types.js';
import type { CertificateData } from '../ts/certificate/models/certificate-types.js';
import type { IDomainConfig } from '../ts/forwarding/config/domain-config.js';
import type { ICertificateData } from '../ts/certificate/models/certificate-types.js';
// Import SmartProxyCertProvisionObject type alias
import type { TSmartProxyCertProvisionObject } from '../ts/certificate/providers/cert-provisioner.js';
// Fake Port80Handler stub
class FakePort80Handler extends plugins.EventEmitter {
@ -19,15 +20,15 @@ class FakePort80Handler extends plugins.EventEmitter {
// Fake NetworkProxyBridge stub
class FakeNetworkProxyBridge {
public appliedCerts: CertificateData[] = [];
applyExternalCertificate(cert: CertificateData) {
public appliedCerts: ICertificateData[] = [];
applyExternalCertificate(cert: ICertificateData) {
this.appliedCerts.push(cert);
}
}
tap.test('CertProvisioner handles static provisioning', async () => {
const domain = 'static.com';
const domainConfigs: DomainConfig[] = [{
const domainConfigs: IDomainConfig[] = [{
domains: [domain],
forwarding: {
type: 'https-terminate-to-https',
@ -37,7 +38,7 @@ tap.test('CertProvisioner handles static provisioning', async () => {
const fakePort80 = new FakePort80Handler();
const fakeBridge = new FakeNetworkProxyBridge();
// certProvider returns static certificate
const certProvider = async (d: string): Promise<SmartProxyCertProvisionObject> => {
const certProvider = async (d: string): Promise<TSmartProxyCertProvisionObject> => {
expect(d).toEqual(domain);
return {
domainName: domain,
@ -75,7 +76,7 @@ tap.test('CertProvisioner handles static provisioning', async () => {
tap.test('CertProvisioner handles http01 provisioning', async () => {
const domain = 'http01.com';
const domainConfigs: DomainConfig[] = [{
const domainConfigs: IDomainConfig[] = [{
domains: [domain],
forwarding: {
type: 'https-terminate-to-http',
@ -85,7 +86,7 @@ tap.test('CertProvisioner handles http01 provisioning', async () => {
const fakePort80 = new FakePort80Handler();
const fakeBridge = new FakeNetworkProxyBridge();
// certProvider returns http01 directive
const certProvider = async (): Promise<SmartProxyCertProvisionObject> => 'http01';
const certProvider = async (): Promise<TSmartProxyCertProvisionObject> => 'http01';
const prov = new CertProvisioner(
domainConfigs,
fakePort80 as any,
@ -106,7 +107,7 @@ tap.test('CertProvisioner handles http01 provisioning', async () => {
tap.test('CertProvisioner on-demand http01 renewal', async () => {
const domain = 'renew.com';
const domainConfigs: DomainConfig[] = [{
const domainConfigs: IDomainConfig[] = [{
domains: [domain],
forwarding: {
type: 'https-terminate-to-http',
@ -115,7 +116,7 @@ tap.test('CertProvisioner on-demand http01 renewal', async () => {
}];
const fakePort80 = new FakePort80Handler();
const fakeBridge = new FakeNetworkProxyBridge();
const certProvider = async (): Promise<SmartProxyCertProvisionObject> => 'http01';
const certProvider = async (): Promise<TSmartProxyCertProvisionObject> => 'http01';
const prov = new CertProvisioner(
domainConfigs,
fakePort80 as any,
@ -132,7 +133,7 @@ tap.test('CertProvisioner on-demand http01 renewal', async () => {
tap.test('CertProvisioner on-demand static provisioning', async () => {
const domain = 'ondemand.com';
const domainConfigs: DomainConfig[] = [{
const domainConfigs: IDomainConfig[] = [{
domains: [domain],
forwarding: {
type: 'https-terminate-to-https',
@ -141,7 +142,7 @@ tap.test('CertProvisioner on-demand static provisioning', async () => {
}];
const fakePort80 = new FakePort80Handler();
const fakeBridge = new FakeNetworkProxyBridge();
const certProvider = async (): Promise<SmartProxyCertProvisionObject> => ({
const certProvider = async (): Promise<TSmartProxyCertProvisionObject> => ({
domainName: domain,
publicKey: 'PKEY',
privateKey: 'PRIV',

View File

@ -2,8 +2,8 @@ import * as plugins from '../ts/plugins.js';
import { tap, expect } from '@push.rocks/tapbundle';
import { SmartProxy } from '../ts/proxies/smart-proxy/index.js';
import type { DomainConfig } from '../ts/forwarding/config/forwarding-types.js';
import type { ForwardingType } from '../ts/forwarding/config/forwarding-types.js';
import type { TForwardingType } from '../ts/forwarding/config/forwarding-types.js';
import type { IDomainConfig } from '../ts/forwarding/config/domain-config.js';
import {
httpOnly,
httpsPassthrough,
@ -14,7 +14,7 @@ import {
// Test to demonstrate various forwarding configurations
tap.test('Forwarding configuration examples', async (tools) => {
// Example 1: HTTP-only configuration
const httpOnlyConfig: DomainConfig = {
const httpOnlyConfig: IDomainConfig = {
domains: ['http.example.com'],
forwarding: httpOnly({
target: {
@ -30,7 +30,7 @@ tap.test('Forwarding configuration examples', async (tools) => {
expect(httpOnlyConfig.forwarding.type).toEqual('http-only');
// Example 2: HTTPS Passthrough (SNI)
const httpsPassthroughConfig: DomainConfig = {
const httpsPassthroughConfig: IDomainConfig = {
domains: ['pass.example.com'],
forwarding: httpsPassthrough({
target: {
@ -47,7 +47,7 @@ tap.test('Forwarding configuration examples', async (tools) => {
expect(Array.isArray(httpsPassthroughConfig.forwarding.target.host)).toBeTrue();
// Example 3: HTTPS Termination to HTTP Backend
const terminateToHttpConfig: DomainConfig = {
const terminateToHttpConfig: IDomainConfig = {
domains: ['secure.example.com'],
forwarding: tlsTerminateToHttp({
target: {
@ -75,7 +75,7 @@ tap.test('Forwarding configuration examples', async (tools) => {
expect(terminateToHttpConfig.forwarding.http?.redirectToHttps).toBeTrue();
// Example 4: HTTPS Termination to HTTPS Backend
const terminateToHttpsConfig: DomainConfig = {
const terminateToHttpsConfig: IDomainConfig = {
domains: ['proxy.example.com'],
forwarding: tlsTerminateToHttps({
target: {

View File

@ -1,6 +1,6 @@
import { tap, expect } from '@push.rocks/tapbundle';
import * as plugins from '../ts/plugins.js';
import type { ForwardConfig, ForwardingType } from '../ts/forwarding/config/forwarding-types.js';
import type { IForwardConfig, TForwardingType } from '../ts/forwarding/config/forwarding-types.js';
// First, import the components directly to avoid issues with compiled modules
import { ForwardingHandlerFactory } from '../ts/forwarding/factory/forwarding-factory.js';
@ -17,7 +17,7 @@ const helpers = {
tap.test('ForwardingHandlerFactory - apply defaults based on type', async () => {
// HTTP-only defaults
const httpConfig: ForwardConfig = {
const httpConfig: IForwardConfig = {
type: 'http-only',
target: { host: 'localhost', port: 3000 }
};
@ -26,7 +26,7 @@ tap.test('ForwardingHandlerFactory - apply defaults based on type', async () =>
expect(expandedHttpConfig.http?.enabled).toEqual(true);
// HTTPS-passthrough defaults
const passthroughConfig: ForwardConfig = {
const passthroughConfig: IForwardConfig = {
type: 'https-passthrough',
target: { host: 'localhost', port: 443 }
};
@ -36,7 +36,7 @@ tap.test('ForwardingHandlerFactory - apply defaults based on type', async () =>
expect(expandedPassthroughConfig.http?.enabled).toEqual(false);
// HTTPS-terminate-to-http defaults
const terminateToHttpConfig: ForwardConfig = {
const terminateToHttpConfig: IForwardConfig = {
type: 'https-terminate-to-http',
target: { host: 'localhost', port: 3000 }
};
@ -48,7 +48,7 @@ tap.test('ForwardingHandlerFactory - apply defaults based on type', async () =>
expect(expandedTerminateToHttpConfig.acme?.maintenance).toEqual(true);
// HTTPS-terminate-to-https defaults
const terminateToHttpsConfig: ForwardConfig = {
const terminateToHttpsConfig: IForwardConfig = {
type: 'https-terminate-to-https',
target: { host: 'localhost', port: 8443 }
};
@ -62,7 +62,7 @@ tap.test('ForwardingHandlerFactory - apply defaults based on type', async () =>
tap.test('ForwardingHandlerFactory - validate configuration', async () => {
// Valid configuration
const validConfig: ForwardConfig = {
const validConfig: IForwardConfig = {
type: 'http-only',
target: { host: 'localhost', port: 3000 }
};
@ -77,7 +77,7 @@ tap.test('ForwardingHandlerFactory - validate configuration', async () => {
expect(() => ForwardingHandlerFactory.validateConfig(invalidConfig1)).toThrow();
// Invalid configuration - invalid port
const invalidConfig2: ForwardConfig = {
const invalidConfig2: IForwardConfig = {
type: 'http-only',
target: { host: 'localhost', port: 0 }
};
@ -85,7 +85,7 @@ tap.test('ForwardingHandlerFactory - validate configuration', async () => {
expect(() => ForwardingHandlerFactory.validateConfig(invalidConfig2)).toThrow();
// Invalid configuration - HTTP disabled for HTTP-only
const invalidConfig3: ForwardConfig = {
const invalidConfig3: IForwardConfig = {
type: 'http-only',
target: { host: 'localhost', port: 3000 },
http: { enabled: false }
@ -94,7 +94,7 @@ tap.test('ForwardingHandlerFactory - validate configuration', async () => {
expect(() => ForwardingHandlerFactory.validateConfig(invalidConfig3)).toThrow();
// Invalid configuration - HTTP enabled for HTTPS passthrough
const invalidConfig4: ForwardConfig = {
const invalidConfig4: IForwardConfig = {
type: 'https-passthrough',
target: { host: 'localhost', port: 443 },
http: { enabled: true }

View File

@ -1,6 +1,6 @@
import { tap, expect } from '@push.rocks/tapbundle';
import * as plugins from '../ts/plugins.js';
import type { ForwardConfig } from '../ts/forwarding/config/forwarding-types.js';
import type { IForwardConfig } from '../ts/forwarding/config/forwarding-types.js';
// First, import the components directly to avoid issues with compiled modules
import { ForwardingHandlerFactory } from '../ts/forwarding/factory/forwarding-factory.js';
@ -17,7 +17,7 @@ const helpers = {
tap.test('ForwardingHandlerFactory - apply defaults based on type', async () => {
// HTTP-only defaults
const httpConfig: ForwardConfig = {
const httpConfig: IForwardConfig = {
type: 'http-only',
target: { host: 'localhost', port: 3000 }
};
@ -26,7 +26,7 @@ tap.test('ForwardingHandlerFactory - apply defaults based on type', async () =>
expect(expandedHttpConfig.http?.enabled).toEqual(true);
// HTTPS-passthrough defaults
const passthroughConfig: ForwardConfig = {
const passthroughConfig: IForwardConfig = {
type: 'https-passthrough',
target: { host: 'localhost', port: 443 }
};
@ -36,7 +36,7 @@ tap.test('ForwardingHandlerFactory - apply defaults based on type', async () =>
expect(expandedPassthroughConfig.http?.enabled).toEqual(false);
// HTTPS-terminate-to-http defaults
const terminateToHttpConfig: ForwardConfig = {
const terminateToHttpConfig: IForwardConfig = {
type: 'https-terminate-to-http',
target: { host: 'localhost', port: 3000 }
};
@ -48,7 +48,7 @@ tap.test('ForwardingHandlerFactory - apply defaults based on type', async () =>
expect(expandedTerminateToHttpConfig.acme?.maintenance).toEqual(true);
// HTTPS-terminate-to-https defaults
const terminateToHttpsConfig: ForwardConfig = {
const terminateToHttpsConfig: IForwardConfig = {
type: 'https-terminate-to-https',
target: { host: 'localhost', port: 8443 }
};
@ -62,7 +62,7 @@ tap.test('ForwardingHandlerFactory - apply defaults based on type', async () =>
tap.test('ForwardingHandlerFactory - validate configuration', async () => {
// Valid configuration
const validConfig: ForwardConfig = {
const validConfig: IForwardConfig = {
type: 'http-only',
target: { host: 'localhost', port: 3000 }
};
@ -77,7 +77,7 @@ tap.test('ForwardingHandlerFactory - validate configuration', async () => {
expect(() => ForwardingHandlerFactory.validateConfig(invalidConfig1)).toThrow();
// Invalid configuration - invalid port
const invalidConfig2: ForwardConfig = {
const invalidConfig2: IForwardConfig = {
type: 'http-only',
target: { host: 'localhost', port: 0 }
};

View File

@ -282,10 +282,20 @@ tap.test('should support optional source IP preservation in chained proxies', as
// Test round-robin behavior for multiple target hosts in a domain config.
tap.test('should use round robin for multiple target hosts in domain config', async () => {
// Create a domain config with multiple hosts in the target
const domainConfig = {
const domainConfig: {
domains: string[];
forwarding: {
type: 'http-only';
target: {
host: string[];
port: number;
};
http: { enabled: boolean };
}
} = {
domains: ['rr.test'],
forwarding: {
type: 'http-only',
type: 'http-only' as const,
target: {
host: ['hostA', 'hostB'], // Array of hosts for round-robin
port: 80