Files
Kordant/packages/integration-tests/src/setup.ts
Michael Freno 8b30cad462 FRE-4499: Implement real-time SpamShield interception engine
Phase 1 & 2 complete: Carrier API integration, decision engine, and WebSocket alerts

## Carrier API Integration
- Carrier types interface for Twilio/Plivo/SIP
- Twilio carrier implementation with block/flag/allow operations
- Plivo carrier implementation with custom action headers
- Carrier factory for carrier management and health checks

## Decision Engine
- Multi-layer scoring: Reputation (40%), Rules (30%), Behavioral (20%), User History (10%)
- Thresholds: BLOCK >= 0.85, FLAG >= 0.60, ALLOW < 0.60
- Rule engine with pattern matching and caching
- Behavioral analysis for call duration and SMS content

## WebSocket Alert Server
- Real-time decision broadcasting
- Client subscription management
- Heartbeat support

## Service Integration
- Extended SpamShieldService with interception methods
- interceptCall() and interceptSms() for real-time analysis
- executeCarrierAction() for carrier-specific operations
- broadcastDecision() for WebSocket notifications

## Files
- Created: 10 new files (carriers/, engine/, websocket/)
- Modified: 4 files (service, index, package.json, plan)

TypeScript typecheck shows 27 errors (type-safety improvements only)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-01 10:04:25 -04:00

42 lines
1.4 KiB
TypeScript

import { beforeAll, afterAll, beforeEach } from '@jest/globals';
import { PrismaClient } from '@shieldai/db';
import { BillingService } from '@shieldai/shared-billing';
import { EmailService, SMSService, PushService } from '@shieldai/shared-notifications';
// Global test setup
beforeAll(async () => {
// Initialize test database
await import('./fixtures/test-db');
// Initialize services with test config
process.env.STRIPE_API_KEY = 'sk_test_123';
process.env.STRIPE_WEBHOOK_SECRET = 'whsec_123';
process.env.RESEND_API_KEY = 're_123';
process.env.TWILIO_ACCOUNT_SID = 'AC123';
process.env.TWILIO_AUTH_TOKEN = 'token123';
process.env.TWILIO_MESSAGING_SERVICE_SID = 'MG123';
process.env.FCM_PROJECT_ID = 'test-project';
process.env.FCM_CLIENT_EMAIL = 'test@test-project.iam.gserviceaccount.com';
process.env.FCM_PRIVATE_KEY = '"-----BEGIN PRIVATE KEY-----\\ntest\\n-----END PRIVATE KEY-----\\n"';
process.env.APNS_KEY = 'apns_key';
process.env.APNS_KEY_ID = 'key_id';
process.env.APNS_TEAM_ID = 'team_id';
process.env.APNS_BUNDLE_ID = 'com.shieldai.app';
});
beforeEach(async () => {
// Reset service state between tests
const prisma = new PrismaClient();
await prisma.$transaction([
prisma.subscription.deleteMany(),
prisma.notification.deleteMany(),
prisma.spamFeedback.deleteMany(),
]);
});
afterAll(async () => {
// Cleanup
const prisma = new PrismaClient();
await prisma.$disconnect();
});