Skip to content

CredentialManager

Main class for managing authentication and credentials.

new CredentialManager(options?: CredentialManagerOptions)

Options:

interface CredentialManagerOptions {
profileName?: string; // Specific profile to use
requireAuth?: boolean; // Throw error if not authenticated (default: false)
debug?: boolean; // Enable debug logging (default: false)
}

Example:

// Use default profile
const cm1 = new CredentialManager();
// Use specific profile
const cm2 = new CredentialManager({ profileName: 'production' });
// Require authentication
const cm3 = new CredentialManager({ requireAuth: true });

Initialize the credential manager and load credentials.

const credentialManager = new CredentialManager();
await credentialManager.initialize();

Check if credentials are loaded and valid.

if (credentialManager.isAuthenticated()) {
console.log('Ready to make API calls');
}

Get the configured API URL.

const apiUrl = credentialManager.getApiUrl();
console.log('API URL:', apiUrl);

Extract tenant name from API URL.

const tenant = credentialManager.getTenant();
console.log('Tenant:', tenant);

Get the default namespace.

const namespace = credentialManager.getNamespace();
console.log('Namespace:', namespace);

Get authentication headers for API requests.

const headers = credentialManager.getAuthHeaders();
// Returns: { 'Authorization': 'APIToken your-token' }
// or: { 'X-Client-Cert': '...', 'X-Client-Key': '...' }

Get configured HTTPS agent with TLS settings.

const agent = credentialManager.getHttpsAgent();
// Use with axios or other HTTP libraries