0fa5925e47
Universal: Changelog Validation / Validate CHANGELOG.md (push) Failing after 37s
MCP: Build & Release / Build, Validate & Release (push) Failing after 38s
MCP: Build & Validate / build (20) (push) Failing after 5s
MCP: Build & Validate / build (22) (push) Failing after 5s
MCP: Standards Compliance / Secret Scanning (push) Successful in 3s
MCP: Standards Compliance / License Header Validation (push) Failing after 3s
MCP: Standards Compliance / Repository Structure Validation (push) Failing after 3s
MCP: Standards Compliance / Coding Standards Check (push) Failing after 3s
Universal: CodeQL Analysis / Analyze (actions) (push) Failing after 1m38s
MCP: Standards Compliance / Workflow Configuration Check (push) Failing after 4s
MCP: Standards Compliance / Version Consistency Check (push) Successful in 36s
MCP: Standards Compliance / Documentation Quality Check (push) Successful in 3s
MCP: Standards Compliance / README Completeness Check (push) Failing after 4s
MCP: Standards Compliance / Git Repository Hygiene (push) Successful in 3s
MCP: Standards Compliance / Script Integrity Validation (push) Successful in 4s
MCP: Standards Compliance / Line Length Check (push) Failing after 4s
MCP: Standards Compliance / File Naming Standards (push) Successful in 3s
MCP: Standards Compliance / Insecure Code Pattern Detection (push) Successful in 3s
MCP: Standards Compliance / Code Complexity Analysis (push) Successful in 33s
MCP: Standards Compliance / Code Duplication Detection (push) Successful in 34s
MCP: Standards Compliance / Dead Code Detection (push) Successful in 4s
MCP: Standards Compliance / File Size Limits (push) Successful in 3s
MCP: Standards Compliance / TODO/FIXME Tracking (push) Successful in 2s
MCP: Standards Compliance / Binary File Detection (push) Successful in 3s
MCP: Standards Compliance / Unused Dependencies Check (push) Successful in 35s
MCP: Standards Compliance / Dependency Vulnerability Scanning (push) Successful in 36s
MCP: Standards Compliance / Broken Link Detection (push) Successful in 3s
MCP: Standards Compliance / API Documentation Coverage (push) Successful in 3s
MCP: Standards Compliance / Accessibility Check (push) Successful in 3s
MCP: Standards Compliance / Performance Metrics (push) Successful in 3s
MCP: Standards Compliance / Enterprise Readiness Check (push) Successful in 37s
MCP: Standards Compliance / Repository Health Check (push) Successful in 37s
MCP: Standards Compliance / Terraform Configuration Validation (push) Successful in 7s
Universal: Sync Version on Merge / Propagate README version (push) Failing after 32s
Universal: CodeQL Analysis / Security Scan Summary (push) Has been cancelled
MCP: Standards Compliance / Compliance Summary (push) Has been cancelled
Universal: CodeQL Analysis / Analyze (javascript) (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
*
|
|
* This file is part of a Moko Consulting project.
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* FILE INFORMATION
|
|
* DEFGROUP: dolibarr-api-mcp.Config
|
|
* INGROUP: dolibarr-api-mcp
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/dolibarr-api-mcp
|
|
* PATH: /src/config.ts
|
|
* VERSION: 01.00.00
|
|
* BRIEF: Configuration loader for Dolibarr API MCP connections
|
|
*/
|
|
|
|
import { readFile } from 'node:fs/promises';
|
|
import { resolve } from 'node:path';
|
|
import { homedir } from 'node:os';
|
|
import type { DolibarrConfig, DolibarrConnection } from './types.js';
|
|
|
|
const CONFIG_FILENAME = '.mcp_mokocrm.json';
|
|
|
|
export async function loadConfig(): Promise<DolibarrConfig> {
|
|
const config_path = process.env.DOLIBARR_API_MCP_CONFIG
|
|
? resolve(process.env.DOLIBARR_API_MCP_CONFIG)
|
|
: resolve(homedir(), CONFIG_FILENAME);
|
|
|
|
try {
|
|
const raw = await readFile(config_path, 'utf-8');
|
|
const parsed = JSON.parse(raw) as Partial<DolibarrConfig>;
|
|
|
|
if (!parsed.connections || Object.keys(parsed.connections).length === 0) {
|
|
throw new Error('No connections defined in config');
|
|
}
|
|
|
|
return {
|
|
connections: parsed.connections,
|
|
defaultConnection: parsed.defaultConnection ?? Object.keys(parsed.connections)[0],
|
|
};
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : String(err);
|
|
throw new Error(
|
|
`Failed to load config from ${config_path}: ${message}\n` +
|
|
`Create ${config_path} — see config.example.json for format.`,
|
|
);
|
|
}
|
|
}
|
|
|
|
export function getConnection(config: DolibarrConfig, name?: string): DolibarrConnection {
|
|
const key = name ?? config.defaultConnection;
|
|
const conn = config.connections[key];
|
|
if (!conn) {
|
|
throw new Error(
|
|
`Connection "${key}" not found. Available: ${Object.keys(config.connections).join(', ')}`,
|
|
);
|
|
}
|
|
return conn;
|
|
}
|