mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-12 06:55:15 +00:00
feat: Add analytics, security, and currency SDK modules with comprehensive API endpoints across Elixir and Go SDKs
- Add AnalyticsAPI with churn prediction (predict, metrics, at-risk), market analytics (metrics, competitors, opportunities), predictive maintenance (metrics, assets, alerts, predict), and pricing optimization (metrics, optimize, elasticity) endpoints - Add SecurityAPI with fraud detection (analyze, alerts, update status, metrics, patterns) and SIM swap protection (verify, history) endpoints - Add CurrencyAPI with currency conversion (convert, exchange rates, rate
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { HTTPClient } from './api/http-client';
|
||||
import {
|
||||
ChurnPrediction,
|
||||
ChurnMetrics,
|
||||
ChurnRiskLevel,
|
||||
MarketMetrics,
|
||||
PredictiveMaintenanceMetrics,
|
||||
PricingOptimizationResult,
|
||||
PricingMetrics
|
||||
} from './types';
|
||||
|
||||
export class AnalyticsAPI {
|
||||
constructor(private client: HTTPClient) {}
|
||||
|
||||
async predictChurn(profileId: string): Promise<ChurnPrediction> {
|
||||
return this.client.request({
|
||||
method: 'POST',
|
||||
endpoint: '/api/v1/analytics/churn/predict',
|
||||
data: { profileId }
|
||||
});
|
||||
}
|
||||
|
||||
async getChurnMetrics(period: string): Promise<ChurnMetrics> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: '/api/v1/analytics/churn/metrics',
|
||||
params: { period }
|
||||
});
|
||||
}
|
||||
|
||||
async getAtRiskCustomers(riskLevel: ChurnRiskLevel, limit: number): Promise<ChurnPrediction[]> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: '/api/v1/analytics/churn/at-risk',
|
||||
params: { riskLevel, limit: limit.toString() }
|
||||
});
|
||||
}
|
||||
|
||||
async getMarketMetrics(period: string): Promise<MarketMetrics> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: '/api/v1/analytics/market/metrics',
|
||||
params: { period }
|
||||
});
|
||||
}
|
||||
|
||||
async getPredictiveMaintenanceMetrics(period: string): Promise<PredictiveMaintenanceMetrics> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: '/api/v1/analytics/maintenance/metrics',
|
||||
params: { period }
|
||||
});
|
||||
}
|
||||
|
||||
async getPricingMetrics(period: string): Promise<PricingMetrics> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: '/api/v1/analytics/pricing/metrics',
|
||||
params: { period }
|
||||
});
|
||||
}
|
||||
|
||||
async optimizePrice(ratePlanId: string, strategy: string): Promise<PricingOptimizationResult> {
|
||||
return this.client.request({
|
||||
method: 'POST',
|
||||
endpoint: '/api/v1/analytics/pricing/optimize',
|
||||
data: { ratePlanId, strategy }
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import { HTTPClient } from './api/http-client';
|
||||
|
||||
export interface ConvertRequest {
|
||||
from: string;
|
||||
to: string;
|
||||
amount: number;
|
||||
}
|
||||
|
||||
export interface ConvertResponse {
|
||||
from: string;
|
||||
to: string;
|
||||
amount: number;
|
||||
converted: number;
|
||||
rate: number;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
export interface ExchangeRate {
|
||||
from: string;
|
||||
to: string;
|
||||
rate: number;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
export interface BillingTransaction {
|
||||
id: string;
|
||||
profileId: string;
|
||||
amount: number;
|
||||
currency: string;
|
||||
type: string;
|
||||
status: string;
|
||||
description: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface BillingSummary {
|
||||
profileId: string;
|
||||
period: string;
|
||||
totalAmount: number;
|
||||
currency: string;
|
||||
transactionCount: number;
|
||||
breakdown: Record<string, number>;
|
||||
}
|
||||
|
||||
export class CurrencyAPI {
|
||||
constructor(private client: HTTPClient) {}
|
||||
|
||||
async convert(request: ConvertRequest): Promise<ConvertResponse> {
|
||||
return this.client.request({
|
||||
method: 'POST',
|
||||
endpoint: '/api/v1/currency/convert',
|
||||
data: request
|
||||
});
|
||||
}
|
||||
|
||||
async getExchangeRate(from: string, to: string): Promise<ExchangeRate> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: `/api/v1/currency/exchange/${from}/${to}`
|
||||
});
|
||||
}
|
||||
|
||||
async getExchangeRateHistory(from: string, to: string, days: number = 30): Promise<ExchangeRate[]> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: `/api/v1/currency/exchange/${from}/${to}/history`,
|
||||
params: { days: days.toString() }
|
||||
});
|
||||
}
|
||||
|
||||
async getSupportedCurrencies(): Promise<string[]> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: '/api/v1/currency/currencies'
|
||||
});
|
||||
}
|
||||
|
||||
async refreshExchangeRates(): Promise<void> {
|
||||
return this.client.request({
|
||||
method: 'POST',
|
||||
endpoint: '/api/v1/currency/exchange/refresh',
|
||||
data: {}
|
||||
});
|
||||
}
|
||||
|
||||
async processBilling(billingData: Record<string, any>): Promise<BillingTransaction> {
|
||||
return this.client.request({
|
||||
method: 'POST',
|
||||
endpoint: '/api/v1/currency/billing',
|
||||
data: billingData
|
||||
});
|
||||
}
|
||||
|
||||
async getBillingHistory(profileId: string, limit: number = 50): Promise<BillingTransaction[]> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: `/api/v1/currency/billing/history/${profileId}`,
|
||||
params: { limit: limit.toString() }
|
||||
});
|
||||
}
|
||||
|
||||
async getBillingSummary(profileId: string, period: string = 'monthly'): Promise<BillingSummary> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: `/api/v1/currency/billing/summary/${profileId}`,
|
||||
params: { period }
|
||||
});
|
||||
}
|
||||
|
||||
async processRefund(transactionId: string, reason: string): Promise<BillingTransaction> {
|
||||
return this.client.request({
|
||||
method: 'POST',
|
||||
endpoint: `/api/v1/currency/billing/refund/${transactionId}`,
|
||||
data: { reason }
|
||||
});
|
||||
}
|
||||
|
||||
async getBillingAnalytics(period: string = 'monthly'): Promise<Record<string, any>> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: '/api/v1/currency/billing/analytics',
|
||||
params: { period }
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ export { SDKConfig, TelecomSDKConfig } from './config';
|
||||
export { HttpClient } from './http-client';
|
||||
export { SubscribersService } from './subscribers';
|
||||
export { WebSocketClient } from './websocket';
|
||||
export { AnalyticsAPI } from './analytics';
|
||||
export { SecurityAPI } from './security';
|
||||
export { CurrencyAPI } from './currency';
|
||||
|
||||
// Export all types
|
||||
export * from './types';
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { HTTPClient } from './api/http-client';
|
||||
import { FraudAlert, FraudAlertFilter, FraudMetrics } from './types';
|
||||
|
||||
export class SecurityAPI {
|
||||
constructor(private client: HTTPClient) {}
|
||||
|
||||
async analyzeTransaction(transaction: Record<string, any>): Promise<FraudAlert> {
|
||||
return this.client.request({
|
||||
method: 'POST',
|
||||
endpoint: '/api/v1/security/fraud/analyze',
|
||||
data: transaction
|
||||
});
|
||||
}
|
||||
|
||||
async getFraudAlerts(filter: FraudAlertFilter): Promise<FraudAlert[]> {
|
||||
return this.client.request({
|
||||
method: 'POST',
|
||||
endpoint: '/api/v1/security/fraud/alerts',
|
||||
data: filter
|
||||
});
|
||||
}
|
||||
|
||||
async updateAlertStatus(alertId: string, status: string, actions: string[]): Promise<void> {
|
||||
return this.client.request({
|
||||
method: 'PUT',
|
||||
endpoint: `/api/v1/security/fraud/alerts/${alertId}`,
|
||||
data: { status, actions }
|
||||
});
|
||||
}
|
||||
|
||||
async getFraudMetrics(period: string): Promise<FraudMetrics> {
|
||||
return this.client.request({
|
||||
method: 'GET',
|
||||
endpoint: '/api/v1/security/fraud/metrics',
|
||||
params: { period }
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,11 @@ import {
|
||||
UsageAPI,
|
||||
PaymentAPI,
|
||||
RatingPlanAPI,
|
||||
SystemAPI,
|
||||
GraphQLAPI
|
||||
SystemAPI
|
||||
} from './api';
|
||||
import { AnalyticsAPI } from './analytics';
|
||||
import { SecurityAPI } from './security';
|
||||
import { CurrencyAPI } from './currency';
|
||||
import { WebSocketClient } from './websocket';
|
||||
import { Alert, RealTimeUsageUpdate, WebSocketMessage } from './types';
|
||||
|
||||
@@ -23,7 +25,9 @@ export class TelecomSDK {
|
||||
public payments: PaymentAPI;
|
||||
public ratingPlans: RatingPlanAPI;
|
||||
public system: SystemAPI;
|
||||
public graphql: GraphQLAPI;
|
||||
public analytics: AnalyticsAPI;
|
||||
public security: SecurityAPI;
|
||||
public currency: CurrencyAPI;
|
||||
|
||||
private constructor(config: {
|
||||
baseURL: string;
|
||||
@@ -61,7 +65,9 @@ export class TelecomSDK {
|
||||
this.payments = new PaymentAPI(this.apiClient);
|
||||
this.ratingPlans = new RatingPlanAPI(this.apiClient);
|
||||
this.system = new SystemAPI(this.apiClient);
|
||||
this.graphql = new GraphQLAPI(this.apiClient);
|
||||
this.analytics = new AnalyticsAPI(this.apiClient);
|
||||
this.security = new SecurityAPI(this.apiClient);
|
||||
this.currency = new CurrencyAPI(this.apiClient);
|
||||
}
|
||||
|
||||
static initialize(config: {
|
||||
|
||||
@@ -47,6 +47,219 @@ export interface CreateSubscriberRequest {
|
||||
euiccId?: string;
|
||||
}
|
||||
|
||||
// Churn Analysis Types
|
||||
export enum ChurnRiskLevel {
|
||||
Low = 'low',
|
||||
Medium = 'medium',
|
||||
High = 'high',
|
||||
Critical = 'critical'
|
||||
}
|
||||
|
||||
export interface ChurnPrediction {
|
||||
profileId: string;
|
||||
riskLevel: ChurnRiskLevel;
|
||||
riskScore: number;
|
||||
predictedChurnDate?: string;
|
||||
reasons: string[];
|
||||
recommendations: string[];
|
||||
lastUpdated: string;
|
||||
}
|
||||
|
||||
export interface ChurnMetrics {
|
||||
period: string;
|
||||
totalSubscribers: number;
|
||||
churnedSubscribers: number;
|
||||
churnRate: number;
|
||||
monthlyChurnRate: number;
|
||||
annualChurnRate: number;
|
||||
averageTenureDays: number;
|
||||
riskDistribution: Record<ChurnRiskLevel, number>;
|
||||
generatedAt: string;
|
||||
}
|
||||
|
||||
// Fraud Detection Types
|
||||
export enum FraudType {
|
||||
AccountTakeover = 'account_takeover',
|
||||
SubscriptionFraud = 'subscription_fraud',
|
||||
PaymentFraud = 'payment_fraud',
|
||||
UsageAnomaly = 'usage_anomaly',
|
||||
SIMSwap = 'sim_swap'
|
||||
}
|
||||
|
||||
export enum FraudSeverity {
|
||||
Low = 'low',
|
||||
Medium = 'medium',
|
||||
High = 'high',
|
||||
Critical = 'critical'
|
||||
}
|
||||
|
||||
export interface FraudAlert {
|
||||
id: string;
|
||||
type: FraudType;
|
||||
severity: FraudSeverity;
|
||||
profileId: string;
|
||||
description: string;
|
||||
riskScore: number;
|
||||
evidence: string[];
|
||||
ipAddress: string;
|
||||
timestamp: string;
|
||||
status: string;
|
||||
actionsTaken: string[];
|
||||
metadata: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface FraudMetrics {
|
||||
period: string;
|
||||
totalAlerts: number;
|
||||
resolvedAlerts: number;
|
||||
falsePositives: number;
|
||||
resolutionRatePct: number;
|
||||
falsePositiveRatePct: number;
|
||||
byType: Record<FraudType, number>;
|
||||
bySeverity: Record<FraudSeverity, number>;
|
||||
generatedAt: string;
|
||||
}
|
||||
|
||||
export interface FraudAlertFilter {
|
||||
type?: FraudType;
|
||||
severity?: FraudSeverity;
|
||||
status?: string;
|
||||
fromDate?: string;
|
||||
toDate?: string;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
// Market Analytics Types
|
||||
export interface MarketMetrics {
|
||||
period: string;
|
||||
totalMarketSize: number;
|
||||
ourSubscribers: number;
|
||||
marketSharePct: number;
|
||||
growthRatePct: number;
|
||||
byCountry: Record<string, CountryMetrics>;
|
||||
byCarrier: Record<string, MarketCarrierMetrics>;
|
||||
byDemographic: Record<string, DemoMetrics>;
|
||||
competitorAnalysis: Record<string, CompetitorMetrics>;
|
||||
marketOpportunities: MarketOpportunity[];
|
||||
generatedAt: string;
|
||||
}
|
||||
|
||||
export interface CountryMetrics {
|
||||
country: string;
|
||||
marketSize: number;
|
||||
ourSubscribers: number;
|
||||
marketSharePct: number;
|
||||
growthRatePct: number;
|
||||
averageRevenue: number;
|
||||
}
|
||||
|
||||
export interface MarketCarrierMetrics {
|
||||
carrierId: string;
|
||||
carrierName: string;
|
||||
subscribers: number;
|
||||
marketSharePct: number;
|
||||
averageRevenue: number;
|
||||
qualityScore: number;
|
||||
}
|
||||
|
||||
export interface DemoMetrics {
|
||||
segment: string;
|
||||
subscribers: number;
|
||||
marketSharePct: number;
|
||||
averageRevenue: number;
|
||||
growthRatePct: number;
|
||||
}
|
||||
|
||||
export interface CompetitorMetrics {
|
||||
name: string;
|
||||
marketSharePct: number;
|
||||
subscribers: number;
|
||||
averagePrice: number;
|
||||
strengths: string[];
|
||||
weaknesses: string[];
|
||||
}
|
||||
|
||||
export interface MarketOpportunity {
|
||||
id: string;
|
||||
type: string;
|
||||
description: string;
|
||||
potentialSize: number;
|
||||
confidence: number;
|
||||
requiredActions: string[];
|
||||
}
|
||||
|
||||
// Predictive Maintenance Types
|
||||
export interface PredictiveMaintenanceMetrics {
|
||||
period: string;
|
||||
totalAssets: number;
|
||||
healthyAssets: number;
|
||||
atRiskAssets: number;
|
||||
criticalAssets: number;
|
||||
overallHealthScore: number;
|
||||
byAssetType: Record<string, AssetTypeMetrics>;
|
||||
predictedFailures: PredictedFailure[];
|
||||
maintenanceSchedule: MaintenanceTask[];
|
||||
generatedAt: string;
|
||||
}
|
||||
|
||||
export interface AssetTypeMetrics {
|
||||
assetType: string;
|
||||
total: number;
|
||||
healthy: number;
|
||||
atRisk: number;
|
||||
critical: number;
|
||||
healthScore: number;
|
||||
}
|
||||
|
||||
export interface PredictedFailure {
|
||||
assetId: string;
|
||||
assetType: string;
|
||||
failureType: string;
|
||||
predictedDate: string;
|
||||
confidence: number;
|
||||
recommendedActions: string[];
|
||||
}
|
||||
|
||||
export interface MaintenanceTask {
|
||||
id: string;
|
||||
assetId: string;
|
||||
taskType: string;
|
||||
priority: string;
|
||||
scheduledDate: string;
|
||||
estimatedDurationMinutes: number;
|
||||
description: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
// Pricing Optimization Types
|
||||
export interface PricingOptimizationResult {
|
||||
ratePlanId: string;
|
||||
currentPrice: number;
|
||||
optimalPrice: number;
|
||||
strategy: string;
|
||||
expectedRevenue: number;
|
||||
expectedDemand: number;
|
||||
priceChangePct: number;
|
||||
reasoning: string[];
|
||||
risks: string[];
|
||||
recommendations: string[];
|
||||
confidence: number;
|
||||
generatedAt: string;
|
||||
}
|
||||
|
||||
export interface PricingMetrics {
|
||||
period: string;
|
||||
totalRatePlans: number;
|
||||
optimizedRatePlans: number;
|
||||
averagePriceChangePct: number;
|
||||
expectedRevenueImpactPct: number;
|
||||
churnRateReductionPct: number;
|
||||
priceElasticity: number;
|
||||
competitiveIndex: number;
|
||||
optimizationRoiPct: number;
|
||||
generatedAt: string;
|
||||
}
|
||||
|
||||
export interface UpdateSubscriberRequest {
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
|
||||
Reference in New Issue
Block a user