purgeai-shield
Version:
PurgeAI Shield - AI Security SDK for prompt injection detection, jailbreak prevention, and PII protection
86 lines (81 loc) • 2.4 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var axios = require('axios');
class PurgeAI {
constructor(config) {
if (!config.apiKey) {
throw new Error('API key is required');
}
this.apiKey = config.apiKey;
this.domain = config.domain;
this.client = axios.create({
baseURL: config.baseURL || 'https://api.purgeai.com',
timeout: config.timeout || 10000,
headers: {
'X-API-Key': this.apiKey,
'Content-Type': 'application/json',
},
});
}
/**
* Protect a single input from threats
* @param input - The user input to analyze
* @returns Protection result with threat analysis
*/
async protect(input) {
try {
const response = await this.client.post('/api/sdk/v1/protect', {
input,
domain: this.domain,
});
return response.data;
}
catch (error) {
if (error.response) {
throw new Error(error.response.data.error || 'Protection failed');
}
throw new Error('Network error: Unable to connect to PurgeAI');
}
}
/**
* Protect multiple inputs in batch
* @param inputs - Array of user inputs to analyze
* @returns Batch protection results
*/
async batchProtect(inputs) {
try {
const results = await Promise.all(inputs.map(input => this.protect(input)));
return { results };
}
catch (error) {
throw new Error(`Batch protection failed: ${error.message}`);
}
}
/**
* Check if input is safe (convenience method)
* @param input - The user input to check
* @returns True if safe, false if threat detected
*/
async isSafe(input) {
const result = await this.protect(input);
return result.safe;
}
/**
* Update API key
* @param apiKey - New API key
*/
setApiKey(apiKey) {
this.apiKey = apiKey;
this.client.defaults.headers['X-API-Key'] = apiKey;
}
/**
* Update domain
* @param domain - New domain
*/
setDomain(domain) {
this.domain = domain;
}
}
exports.PurgeAI = PurgeAI;
exports.default = PurgeAI;
//# sourceMappingURL=index.js.map