Skip to content

Compliance Dashboard Examples

Build compliance dashboards and reports with the SDK.

Executive Dashboard

typescript
import { DeIterateClient } from '@deiterate/sdk';

const client = new DeIterateClient({
  apiKey: process.env.DEITERATE_API_KEY!,
  organizationId: process.env.DEITERATE_ORG_ID,
});

async function executiveDashboard() {
  // Fetch all data in parallel
  const [soaSummary, complianceData, risks, overdueTasks] = await Promise.all([
    client.soa.getSummary(),
    client.compliance.getAllData(),
    client.risks.list(),
    client.assurance.getOverdue(),
  ]);
  
  console.log('════════════════════════════════════════');
  console.log('       COMPLIANCE EXECUTIVE DASHBOARD    ');
  console.log('════════════════════════════════════════\n');
  
  // SOA Progress
  const pct = soaSummary.implementationPercentage;
  const bar = '█'.repeat(Math.floor(pct / 5)) + '░'.repeat(20 - Math.floor(pct / 5));
  console.log(`📊 SOA Implementation: [${bar}] ${pct}%`);
  console.log(`   ${soaSummary.implemented}/${soaSummary.totalControls} controls implemented\n`);
  
  // Risk Summary
  const activeRisks = risks.risks.filter(r => r.status === 'active');
  const highRisks = activeRisks.filter(r => 
    r.inherentRisk === 'High' || r.inherentRisk === 'Extreme'
  );
  console.log(`⚠️  Active Risks: ${activeRisks.length}`);
  console.log(`   High/Critical: ${highRisks.length}\n`);
  
  // Task Status
  console.log(`📋 Overdue Tasks: ${overdueTasks.length}`);
  console.log(`   Total Assurance Tasks: ${complianceData.assuranceTasks.length}\n`);
  
  // Asset Summary
  const activeAssets = complianceData.assets.filter(a => a.status === 'Active');
  console.log(`💻 Active Assets: ${activeAssets.length}`);
  console.log(`   Total Documents: ${complianceData.documents.length}`);
}

executiveDashboard();

Monthly Compliance Report

typescript
async function monthlyComplianceReport(year: number, month: number) {
  const calendar = await client.compliance.getCalendarByMonth(year, month);
  const monthName = new Date(year, month - 1).toLocaleString('default', { month: 'long' });
  
  console.log(`\n=== ${monthName} ${year} Compliance Report ===\n`);
  console.log(`Total Scheduled Activities: ${calendar.summary.totalEvents}\n`);
  
  console.log('Activity Breakdown:');
  for (const [type, count] of Object.entries(calendar.summary.byType)) {
    if (count > 0) {
      const icon = getTypeIcon(type);
      console.log(`  ${icon} ${formatTypeName(type)}: ${count}`);
    }
  }
  
  console.log('\nUpcoming Events:');
  const sorted = calendar.events
    .sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime())
    .slice(0, 10);
  
  for (const event of sorted) {
    const date = new Date(event.date).toLocaleDateString();
    console.log(`  ${date} - ${event.title} (${event.type})`);
  }
}

function getTypeIcon(type: string): string {
  const icons: Record<string, string> = {
    'assurance-task': '✅',
    'checklist': '📝',
    'corrective-action': '🔧',
    'risk-review': '⚠️',
    'asset-review': '💻',
    'document-review': '📄',
    'policy-review': '📜',
  };
  return icons[type] || '📌';
}

function formatTypeName(type: string): string {
  return type.split('-').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ');
}

Compliance Status by Framework

typescript
async function frameworkStatus() {
  const summary = await client.soa.getSummary();
  
  console.log('\n=== Framework Implementation Status ===\n');
  
  for (const fw of summary.byFramework) {
    const pct = fw.percentage;
    const bar = '█'.repeat(Math.floor(pct / 5)) + '░'.repeat(20 - Math.floor(pct / 5));
    console.log(`${fw.framework}`);
    console.log(`  [${bar}] ${pct}%`);
    console.log(`  ${fw.implemented}/${fw.total} controls\n`);
  }
}

Audit Readiness Check

typescript
async function auditReadinessCheck() {
  const [data, summary] = await Promise.all([
    client.compliance.getAllData(),
    client.soa.getSummary(),
  ]);
  
  const issues: string[] = [];
  
  // Check SOA implementation
  if (summary.implementationPercentage < 80) {
    issues.push(`SOA implementation at ${summary.implementationPercentage}% (target: 80%)`);
  }
  
  // Check for overdue tasks
  const overdueTasks = data.assuranceTasks.filter(t => t.status === 'overdue');
  if (overdueTasks.length > 0) {
    issues.push(`${overdueTasks.length} overdue assurance tasks`);
  }
  
  // Check for expired documents
  const now = new Date();
  const expiredDocs = data.documents.filter(d => {
    if (!d.nextReviewDate) return false;
    return new Date(d.nextReviewDate) < now;
  });
  if (expiredDocs.length > 0) {
    issues.push(`${expiredDocs.length} documents past review date`);
  }
  
  // Check for open corrective actions
  const openActions = data.correctiveActions.filter(a => 
    a.status !== 'completed' && a.status !== 'closed'
  );
  if (openActions.length > 5) {
    issues.push(`${openActions.length} open corrective actions`);
  }
  
  console.log('\n=== Audit Readiness Check ===\n');
  
  if (issues.length === 0) {
    console.log('✅ All checks passed! Ready for audit.\n');
  } else {
    console.log(`⚠️  ${issues.length} issues found:\n`);
    for (const issue of issues) {
      console.log(`  • ${issue}`);
    }
  }
}

Generate Evidence Package

typescript
async function generateEvidencePackage(controlIds: string[]) {
  const data = await client.compliance.getAllData();
  
  const evidence: Record<string, any> = {};
  
  for (const controlId of controlIds) {
    // Get related assurance tasks
    const tasks = data.assuranceTasks.filter(t => t.controlId === controlId);
    
    // Get related documents
    const docs = data.documents.filter(d => 
      d.comments?.includes(controlId) || d.docType?.includes('evidence')
    );
    
    // Get related policies
    const policies = data.policies.filter(p => 
      p.relatedControls?.includes(controlId)
    );
    
    evidence[controlId] = {
      tasks: tasks.map(t => ({
        description: t.description,
        status: t.status,
        completedDate: t.completedDate,
        evidence: t.evidence,
      })),
      documents: docs.map(d => ({
        name: d.fileName,
        type: d.docType,
        status: d.status,
      })),
      policies: policies.map(p => ({
        title: p.title,
        version: p.version,
        status: p.status,
      })),
    };
  }
  
  return evidence;
}

Released under the MIT License.