@udene/sdk
Version:
Udene Fraud Detection SDK for JavaScript
98 lines (97 loc) • 3.68 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UdeneClient = void 0;
const axios_1 = __importDefault(require("axios"));
/**
* UdeneClient for JavaScript
* A client for interacting with the Udene Fraud Detection API
*/
class UdeneClient {
/**
* Create a new UdeneClient instance
* @param apiKey - Your API key
* @param baseURL - Optional custom API base URL
*/
constructor(apiKey, baseURL = 'https://udene.net/v1') {
this.client = axios_1.default.create({
baseURL,
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
'X-Client-Version': '1.0.0',
'X-SDK-Type': 'javascript'
}
});
// Add response interceptor for error handling
this.client.interceptors.response.use(response => response, error => {
var _a;
console.error('SDK Error:', ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
throw error;
});
}
/**
* Get fraud metrics for the current user/session
* @returns Fraud metrics data
*/
getMetrics() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.get('/metrics');
return response.data;
});
}
/**
* Get activity data for analysis
* @returns Activity data
*/
getActivity() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.get('/activity');
return response.data;
});
}
/**
* Track a user interaction for fraud analysis
* @param data - Interaction data to track
* @returns Tracking confirmation
*/
trackInteraction(data) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.post('/track', data);
return response.data;
});
}
/**
* Analyze a transaction for fraud
* @param transaction - Transaction data to analyze
* @returns Fraud analysis results
*/
analyzeTransaction(transaction) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.post('/analyze-transaction', transaction);
return response.data;
});
}
/**
* Get device fingerprint information
* @returns Device fingerprint data
*/
getDeviceFingerprint() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.client.get('/device-fingerprint');
return response.data;
});
}
}
exports.UdeneClient = UdeneClient;
;