breathe-api
Version:
Model Context Protocol server for Breathe HR APIs with Swagger/OpenAPI support - also works with custom APIs
54 lines • 1.66 kB
JavaScript
export function isApiToken(value) {
return typeof value === 'string' && value.length > 0;
}
export function isPassword(value) {
return typeof value === 'string' && value.length > 0;
}
export function isBasicAuthHeader(value) {
return typeof value === 'string' && value.startsWith('Basic ');
}
export function isBearerToken(value) {
return typeof value === 'string' && value.startsWith('Bearer ');
}
export function isApiKey(value) {
return typeof value === 'string' && value.length > 0;
}
export function createApiToken(value) {
if (!value || typeof value !== 'string') {
throw new Error('Invalid API token');
}
return value;
}
export function createPassword(value) {
if (!value || typeof value !== 'string') {
throw new Error('Invalid password');
}
return value;
}
export function createBasicAuthHeader(username, password) {
if (!username || !password) {
throw new Error('Username and password are required for basic auth');
}
const encoded = Buffer.from(`${username}:${password}`).toString('base64');
return `Basic ${encoded}`;
}
export function createBearerToken(token) {
if (!token || typeof token !== 'string') {
throw new Error('Invalid bearer token');
}
return `Bearer ${token}`;
}
export function createApiKey(value) {
if (!value || typeof value !== 'string') {
throw new Error('Invalid API key');
}
return value;
}
export function sanitizeForLogging(value) {
const str = value.toString();
if (str.length <= 8) {
return '***';
}
return str.substring(0, 4) + '***';
}
//# sourceMappingURL=security.js.map