UNPKG

@seckav/security-sdk

Version:

Lightweight API Security SDK for Enterprises - One-click protection with rate limiting, threat detection, security analytics, and real-time monitoring for Express.js and Next.js applications

261 lines 9 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GitIntegrationModule = void 0; const axios_1 = __importDefault(require("axios")); /** * Git Integration Module - GitHub and GitLab repository integration * Provides repository management and security scanning capabilities */ class GitIntegrationModule { constructor(config) { this.config = config; } /** * Test connection to Git provider */ async testConnection(token, provider) { try { const response = await axios_1.default.post(`${this.config.apiUrl}/api/git-integration/test-connection`, { provider }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 10000, }); return response.data; } catch (error) { if (this.config.onError) { this.config.onError(error); } throw new Error(`Failed to test Git provider connection: ${error}`); } } /** * Get repositories from Git provider */ async getRepositories(token, provider, options = {}) { try { const response = await axios_1.default.post(`${this.config.apiUrl}/api/git-integration/repositories`, { provider, ...options, }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 15000, }); return response.data; } catch (error) { if (this.config.onError) { this.config.onError(error); } throw new Error(`Failed to fetch repositories: ${error}`); } } /** * Get repository details */ async getRepositoryDetails(token, provider, repositoryId) { try { const response = await axios_1.default.post(`${this.config.apiUrl}/api/git-integration/repositories/${repositoryId}`, { provider }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 10000, }); return response.data.repository; } catch (error) { if (this.config.onError) { this.config.onError(error); } throw new Error(`Failed to fetch repository details: ${error}`); } } /** * Scan repository for security issues */ async scanRepository(token, provider, repositoryId, options = {}) { try { const response = await axios_1.default.post(`${this.config.apiUrl}/api/git-integration/scan`, { provider, repositoryId, ...options, }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 60000, // Longer timeout for scanning }); return response.data.scanResult; } catch (error) { if (this.config.onError) { this.config.onError(error); } throw new Error(`Failed to scan repository: ${error}`); } } /** * Get scan history for repositories */ async getScanHistory(token, options = {}) { try { const response = await axios_1.default.get(`${this.config.apiUrl}/api/git-integration/scans`, { headers: { Authorization: `Bearer ${token}`, }, params: options, timeout: this.config.timeout || 10000, }); return response.data; } catch (error) { if (this.config.onError) { this.config.onError(error); } throw new Error(`Failed to fetch scan history: ${error}`); } } /** * Setup webhook for repository */ async setupWebhook(token, provider, repositoryId, options = {}) { try { const response = await axios_1.default.post(`${this.config.apiUrl}/api/git-integration/webhooks`, { provider, repositoryId, events: options.events || ['push', 'pull_request'], autoScan: options.autoScan || true, webhookUrl: options.webhookUrl, }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 15000, }); return response.data.webhook; } catch (error) { if (this.config.onError) { this.config.onError(error); } throw new Error(`Failed to setup webhook: ${error}`); } } /** * Get webhook configurations */ async getWebhooks(token, repositoryId) { try { const params = repositoryId ? { repositoryId } : {}; const response = await axios_1.default.get(`${this.config.apiUrl}/api/git-integration/webhooks`, { headers: { Authorization: `Bearer ${token}`, }, params, timeout: this.config.timeout || 10000, }); return response.data.webhooks; } catch (error) { if (this.config.onError) { this.config.onError(error); } throw new Error(`Failed to fetch webhooks: ${error}`); } } /** * Delete webhook */ async deleteWebhook(token, webhookId) { try { const response = await axios_1.default.delete(`${this.config.apiUrl}/api/git-integration/webhooks/${webhookId}`, { headers: { Authorization: `Bearer ${token}`, }, timeout: this.config.timeout || 10000, }); return response.data; } catch (error) { if (this.config.onError) { this.config.onError(error); } throw new Error(`Failed to delete webhook: ${error}`); } } /** * Get repository branches */ async getRepositoryBranches(token, provider, repositoryId) { try { const response = await axios_1.default.post(`${this.config.apiUrl}/api/git-integration/repositories/${repositoryId}/branches`, { provider }, { headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, timeout: this.config.timeout || 10000, }); return response.data.branches; } catch (error) { if (this.config.onError) { this.config.onError(error); } throw new Error(`Failed to fetch repository branches: ${error}`); } } /** * Get scan report for a specific scan */ async getScanReport(token, scanId, format = 'json') { try { const response = await axios_1.default.get(`${this.config.apiUrl}/api/git-integration/scans/${scanId}/report`, { headers: { Authorization: `Bearer ${token}`, }, params: { format }, timeout: this.config.timeout || 15000, }); return response.data; } catch (error) { if (this.config.onError) { this.config.onError(error); } throw new Error(`Failed to get scan report: ${error}`); } } /** * Get organization's Git integration summary */ async getIntegrationSummary(token) { try { const response = await axios_1.default.get(`${this.config.apiUrl}/api/git-integration/summary`, { headers: { Authorization: `Bearer ${token}`, }, timeout: this.config.timeout || 10000, }); return response.data.summary; } catch (error) { if (this.config.onError) { this.config.onError(error); } throw new Error(`Failed to fetch integration summary: ${error}`); } } } exports.GitIntegrationModule = GitIntegrationModule; //# sourceMappingURL=GitIntegration.js.map