config.ts•1.44 kB
/**
* Configuration handling for ClickUp API credentials
*
* The required environment variables (CLICKUP_API_KEY and CLICKUP_TEAM_ID) are passed
* securely to this file when running the hosted server at smithery.ai. Optionally,
* they can be parsed via command line arguments when running the server locally.
*/
// Parse any command line environment arguments
const args = process.argv.slice(2);
const envArgs: { [key: string]: string } = {};
for (let i = 0; i < args.length; i++) {
if (args[i] === '--env' && i + 1 < args.length) {
const [key, value] = args[i + 1].split('=');
if (key === 'CLICKUP_API_KEY') envArgs.clickupApiKey = value;
if (key === 'CLICKUP_TEAM_ID') envArgs.clickupTeamId = value;
i++;
}
}
// Define required configuration interface
interface Config {
clickupApiKey: string;
clickupTeamId: string;
}
// Load configuration from command line args or environment variables
const configuration: Config = {
clickupApiKey: envArgs.clickupApiKey || process.env.CLICKUP_API_KEY || '',
clickupTeamId: envArgs.clickupTeamId || process.env.CLICKUP_TEAM_ID || '',
};
// Validate all required variables are present
const missingEnvVars = Object.entries(configuration)
.filter(([_, value]) => !value)
.map(([key]) => key);
if (missingEnvVars.length > 0) {
throw new Error(
`Missing required environment variables: ${missingEnvVars.join(', ')}`
);
}
export default configuration;