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

228 lines 7.79 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.OrganizationModule = void 0; const axios_1 = __importDefault(require("axios")); /** * Organization Management Module for SecKav SDK * Handles organization CRUD operations and member management */ class OrganizationModule { constructor(config) { this.config = config; } /** * Create a new organization */ async createOrganization(token, name, description, domain) { try { const response = await axios_1.default.post(`${this.config.apiUrl}/api/v1/organizations`, { name, description, domain }, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 5000, }); return { success: true, organization: response.data, }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Failed to create organization', message: error.response?.data?.message || 'An error occurred', }; } } /** * Get all organizations for the user */ async getOrganizations(token) { try { const response = await axios_1.default.get(`${this.config.apiUrl}/api/v1/organizations`, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 5000, }); return { success: true, organizations: response.data, }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Failed to get organizations', message: error.response?.data?.message || 'An error occurred', }; } } /** * Get organization by ID */ async getOrganizationById(token, organizationId) { try { const response = await axios_1.default.get(`${this.config.apiUrl}/api/v1/organizations/${organizationId}`, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 5000, }); return { success: true, organization: response.data, }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Failed to get organization', message: error.response?.data?.message || 'Organization not found', }; } } /** * Update organization */ async updateOrganization(token, organizationId, updates) { try { const response = await axios_1.default.put(`${this.config.apiUrl}/api/v1/organizations/${organizationId}`, updates, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 5000, }); return { success: true, organization: response.data, }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Failed to update organization', message: error.response?.data?.message || 'An error occurred', }; } } /** * Delete organization */ async deleteOrganization(token, organizationId) { try { const response = await axios_1.default.delete(`${this.config.apiUrl}/api/v1/organizations/${organizationId}`, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 5000, }); return { success: true, message: 'Organization deleted successfully', }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Failed to delete organization', message: error.response?.data?.message || 'An error occurred', }; } } /** * Add member to organization */ async addMember(token, organizationId, memberData) { try { const response = await axios_1.default.post(`${this.config.apiUrl}/api/v1/organizations/${organizationId}/members`, memberData, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 5000, }); return { success: true, organization: response.data, message: 'Member added successfully', }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Failed to add member', message: error.response?.data?.message || 'An error occurred', }; } } /** * Remove member from organization */ async removeMember(token, organizationId, memberId) { try { const response = await axios_1.default.delete(`${this.config.apiUrl}/api/v1/organizations/${organizationId}/members`, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, data: { memberId }, timeout: this.config.timeout || 5000, }); return { success: true, organization: response.data, message: 'Member removed successfully', }; } catch (error) { if (this.config.onError) { this.config.onError(error); } return { success: false, error: error.response?.data?.error || 'Failed to remove member', message: error.response?.data?.message || 'An error occurred', }; } } /** * Get module information */ getInfo() { return { name: 'Organization', version: '2.0.0', description: 'Organization management and member operations', apiUrl: this.config.apiUrl, }; } } exports.OrganizationModule = OrganizationModule; //# sourceMappingURL=Organization.js.map