Assurance Task Examples
Manage and automate assurance tasks with the SDK.
Task 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 taskDashboard() {
const response = await client.assurance.list();
const tasks = response.data;
const byStatus = {
pending: 0,
in_progress: 0,
completed: 0,
overdue: 0,
};
for (const task of tasks) {
const status = task.status || 'pending';
if (status in byStatus) {
byStatus[status as keyof typeof byStatus]++;
}
}
console.log('=== Assurance Task Dashboard ===\n');
console.log(`Total Tasks: ${tasks.length}\n`);
console.log('By Status:');
console.log(` ⏳ Pending: ${byStatus.pending}`);
console.log(` 🔄 In Progress: ${byStatus.in_progress}`);
console.log(` ✅ Completed: ${byStatus.completed}`);
console.log(` 🔴 Overdue: ${byStatus.overdue}`);
}Send Overdue Reminders
typescript
async function sendOverdueReminders() {
const overdue = await client.assurance.getOverdue();
console.log(`Found ${overdue.length} overdue tasks\n`);
for (const task of overdue) {
console.log(`Sending reminder for: ${task.description}`);
console.log(` Assignee: ${task.assignedTo}`);
console.log(` Due: ${task.dueDate}`);
// Send email notification
await sendReminderEmail({
to: task.assignedTo!,
taskId: task.id,
description: task.description,
dueDate: task.dueDate,
});
}
}
async function sendReminderEmail(params: {
to: string;
taskId: string;
description: string;
dueDate: Date | null;
}) {
// Integrate with your email service
console.log(`Email sent to ${params.to}`);
}Complete Tasks with Evidence
typescript
async function completeTaskWithEvidence(
taskId: string,
evidenceFiles: string[],
notes: string
) {
// Complete the task
const completed = await client.assurance.complete(
taskId,
evidenceFiles,
notes
);
console.log(`Task completed: ${completed.description}`);
console.log(`Evidence: ${evidenceFiles.join(', ')}`);
console.log(`Notes: ${notes}`);
return completed;
}
// Usage
await completeTaskWithEvidence(
'task-123',
['access-review-jan-2025.pdf', 'screenshot.png'],
'Monthly access review completed. No anomalies found.'
);Create Recurring Tasks
typescript
async function createRecurringTask(params: {
description: string;
controlId: string;
assignee: string;
frequency: 'weekly' | 'monthly' | 'quarterly' | 'annually';
}) {
const task = await client.assurance.create({
description: params.description,
controlId: params.controlId,
assignedTo: params.assignee,
frequency: params.frequency,
evidenceRequired: true,
dueDate: calculateNextDueDate(params.frequency),
});
console.log(`Created recurring task: ${task.id}`);
console.log(`Frequency: ${params.frequency}`);
return task;
}
function calculateNextDueDate(frequency: string): Date {
const now = new Date();
switch (frequency) {
case 'weekly':
return new Date(now.setDate(now.getDate() + 7));
case 'monthly':
return new Date(now.setMonth(now.getMonth() + 1));
case 'quarterly':
return new Date(now.setMonth(now.getMonth() + 3));
case 'annually':
return new Date(now.setFullYear(now.getFullYear() + 1));
default:
return new Date(now.setMonth(now.getMonth() + 1));
}
}Task Assignment Report
typescript
async function taskAssignmentReport() {
const response = await client.assurance.list();
const tasks = response.data;
// Group by assignee
const byAssignee: Record<string, typeof tasks> = {};
for (const task of tasks) {
const assignee = task.assignedTo || 'Unassigned';
if (!byAssignee[assignee]) {
byAssignee[assignee] = [];
}
byAssignee[assignee].push(task);
}
console.log('=== Task Assignment Report ===\n');
for (const [assignee, assigneeTasks] of Object.entries(byAssignee)) {
const pending = assigneeTasks.filter(t => t.status === 'pending').length;
const overdue = assigneeTasks.filter(t => t.status === 'overdue').length;
console.log(`${assignee}:`);
console.log(` Total: ${assigneeTasks.length}`);
console.log(` Pending: ${pending}`);
console.log(` Overdue: ${overdue}`);
console.log();
}
}