// src/config/AppConfig.ts
import dotenv from "dotenv";
import path from "path";
dotenv.config({ path: path.resolve(__dirname, "../../.env") });
export class AppConfig {
private static instance: AppConfig;
private readonly jiraBaseUrl: string;
private readonly jiraEmail: string;
private readonly jiraApiToken: string;
private readonly jiraProjectKey: string;
private readonly jiraBoardId: string;
private readonly serverPort: number;
private readonly useHttpTransport: boolean;
private constructor() {
this.jiraBaseUrl = this.getEnvValue(
"JIRA_BASE_URL",
"https://your-domain.atlassian.net"
);
this.jiraEmail = this.getEnvValue("JIRA_EMAIL", "");
this.jiraApiToken = this.getEnvValue("JIRA_API_TOKEN", "");
this.jiraProjectKey = this.getEnvValue("JIRA_PROJECT_KEY", "TBC");
this.jiraBoardId = this.getEnvValue("JIRA_BOARD_ID", "");
this.serverPort = parseInt(this.getEnvValue("PORT", "8080"), 10);
this.useHttpTransport = this.getEnvValue("USE_HTTP", "true") === "true";
this.validateConfig();
}
public static getInstance(): AppConfig {
if (!AppConfig.instance) {
AppConfig.instance = new AppConfig();
}
return AppConfig.instance;
}
private getEnvValue(key: string, defaultValue: string): string {
return process.env[key] || defaultValue;
}
private validateConfig(): void {
const requiredFields = [
{ name: "JIRA_EMAIL", value: this.jiraEmail },
{ name: "JIRA_API_TOKEN", value: this.jiraApiToken },
];
const missingFields = requiredFields.filter((field) => !field.value);
if (missingFields.length > 0) {
console.warn(
`⚠️ Warning: Missing configuration fields: ${missingFields
.map((f) => f.name)
.join(", ")}`
);
}
}
public getJiraBaseUrl(): string {
return this.jiraBaseUrl;
}
public getJiraEmail(): string {
return this.jiraEmail;
}
public getJiraApiToken(): string {
return this.jiraApiToken;
}
public getJiraProjectKey(): string {
return this.jiraProjectKey;
}
public getJiraBoardId(): string {
return this.jiraBoardId;
}
public getServerPort(): number {
return this.serverPort;
}
public shouldUseHttpTransport(): boolean {
return this.useHttpTransport;
}
}