UNPKG

@seckav/security-sdk

Version:

SecKav Security SDK - Enterprise-grade security platform with AI-powered threat detection, LLM-powered misconfiguration scanning (Gemini/GPT-4/Claude), end-to-end encryption, behavioral analysis, enhanced file scanning, adaptive rate limiting, GDPR/DPDP/C

196 lines 6.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthenticationModule = void 0; const axios_1 = __importDefault(require("axios")); /** * Authentication Module for SecKav SDK * Handles user authentication, registration, and API key management */ class AuthenticationModule { constructor(config) { this.config = config; } /** * Register a new user */ async register(email, password, name) { try { const response = await axios_1.default.post(`${this.config.apiUrl}/api/v1/auth/register`, { email, password, name }, { headers: { 'Content-Type': 'application/json' }, timeout: this.config.timeout || 5000, }); return { success: true, user: response.data.user, message: response.data.message, }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Registration failed', message: error.response?.data?.message || 'An error occurred during registration', }; } } /** * Login user */ async login(email, password) { try { const response = await axios_1.default.post(`${this.config.apiUrl}/api/v1/auth/login`, { email, password }, { headers: { 'Content-Type': 'application/json' }, timeout: this.config.timeout || 5000, }); return { success: true, user: response.data.user, token: response.data.token, message: response.data.message, }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Login failed', message: error.response?.data?.message || 'Invalid credentials', }; } } /** * Get user profile */ async getProfile(token) { try { const response = await axios_1.default.get(`${this.config.apiUrl}/api/v1/auth/profile`, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 5000, }); return { success: true, user: response.data.user, }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Failed to get profile', message: error.response?.data?.message || 'Authentication required', }; } } /** * Generate new API key */ async generateApiKey(token, name, description) { try { const response = await axios_1.default.post(`${this.config.apiUrl}/api/v1/auth/api-keys`, { name, description }, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 5000, }); return { success: true, apiKey: response.data.apiKey, message: 'API key generated successfully', }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Failed to generate API key', message: error.response?.data?.message || 'An error occurred', }; } } /** * List API keys */ async listApiKeys(token) { try { const response = await axios_1.default.get(`${this.config.apiUrl}/api/v1/auth/api-keys`, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 5000, }); return { success: true, apiKeys: response.data.apiKeys, }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Failed to list API keys', message: error.response?.data?.message || 'An error occurred', }; } } /** * Revoke API key */ async revokeApiKey(token, apiKey) { try { const response = await axios_1.default.delete(`${this.config.apiUrl}/api/v1/auth/api-keys`, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, data: { apiKey }, timeout: this.config.timeout || 5000, }); return { success: true, message: response.data.message || 'API key revoked successfully', }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Failed to revoke API key', message: error.response?.data?.message || 'An error occurred', }; } } /** * Get module information */ getInfo() { return { name: 'Authentication', version: '2.0.0', description: 'User authentication and API key management', apiUrl: this.config.apiUrl, }; } } exports.AuthenticationModule = AuthenticationModule; //# sourceMappingURL=Authentication.js.map