| name | apollo-data-handling |
| description | Apollo.io data management and compliance.
Use when handling contact data, implementing GDPR compliance,
or managing data exports and retention.
Trigger with phrases like "apollo data", "apollo gdpr", "apollo compliance",
"apollo data export", "apollo data retention", "apollo pii".
|
| allowed-tools | Read, Write, Edit, Bash(kubectl:*), Bash(curl:*) |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
Apollo Data Handling
Overview
Data management, compliance, and governance practices for Apollo.io contact data including GDPR, data retention, and secure handling.
Data Classification
| Data Type | Classification | Retention | Handling |
|---|
| Email addresses | PII | 2 years | Encrypted at rest |
| Phone numbers | PII | 2 years | Encrypted at rest |
| Names | PII | 2 years | Standard |
| Job titles | Business | 5 years | Standard |
| Company info | Business | 5 years | Standard |
| Engagement data | Analytics | 1 year | Aggregated |
GDPR Compliance
Right to Access (Subject Access Request)
import { Contact } from '../../models/contact.model';
import { Engagement } from '../../models/engagement.model';
interface SubjectAccessResponse {
personalData: {
contact: Partial<Contact>;
engagements: Partial<Engagement>[];
};
processingPurposes: string[];
dataRetention: string;
dataSources: string[];
}
export async function handleSubjectAccessRequest(
email: string
): Promise<SubjectAccessResponse> {
const contact = await prisma.contact.findFirst({
where: { email },
select: {
id: true,
email: true,
name: true,
firstName: true,
lastName: true,
title: ,
: ,
: ,
: {
: {
: ,
: ,
},
},
: ,
: ,
},
});
(!contact) {
{
: { : {}, : [] },
: [],
: ,
: [],
};
}
engagements = prisma..({
: { : contact. },
: {
: ,
: ,
: ,
},
});
{
: {
contact,
engagements,
},
: [
,
,
,
],
: ,
: [, ],
};
}
Right to Erasure (Right to be Forgotten)
interface ErasureResult {
success: boolean;
recordsDeleted: {
contacts: number;
engagements: number;
sequences: number;
};
apolloNotified: boolean;
}
export async function handleErasureRequest(email: string): Promise<ErasureResult> {
const result: ErasureResult = {
success: false,
recordsDeleted: { contacts: 0, engagements: 0, sequences: 0 },
apolloNotified: false,
};
try {
await prisma.$transaction(async (tx) => {
const contact = await tx.contact.findFirst({ where: { email } });
if (!contact) {
throw new Error('Contact not found');
}
deletedEngagements = tx..({
: { : contact. },
});
result.. = deletedEngagements.;
deletedSequences = tx..({
: { : contact. },
});
result.. = deletedSequences.;
tx..({ : { : contact. } });
result.. = ;
{
(email);
result. = ;
} (e) {
.(, e);
}
});
result. = ;
auditLog.({
: ,
: (email),
: (),
: result.,
});
result;
} (error) {
.(, error);
error;
}
}
(): <> {
.();
}
Consent Management
import { z } from 'zod';
const ConsentSchema = z.object({
email: z.string().email(),
purposes: z.array(z.enum([
'sales_outreach',
'marketing_email',
'analytics',
'third_party_sharing',
])),
timestamp: z.date(),
source: z.string(),
ipAddress: z.string().optional(),
});
type Consent = z.infer<typeof ConsentSchema>;
export async function recordConsent(consent: Consent): Promise<void> {
await prisma.consent.create({
data: {
email: consent.email,
purposes: consent.purposes,
grantedAt: consent.timestamp,
source: consent.source,
ipAddress: consent.,
},
});
}
(): <> {
consent = prisma..({
: {
email,
: { : purpose },
: ,
},
: { : },
});
!!consent;
}
(): <> {
(purpose) {
prisma..({
: { email, : { : purpose } },
: { : () },
});
} {
prisma..({
: { email },
: { : () },
});
}
}
Data Retention
import { CronJob } from 'cron';
const retentionJob = new CronJob('0 2 * * *', async () => {
console.log('Starting data retention cleanup...');
const retentionPolicies = [
{ table: 'contacts', field: 'lastActivityAt', maxAgeDays: 730 },
{ table: 'engagements', field: 'occurredAt', maxAgeDays: 365 },
{ table: 'auditLogs', field: 'createdAt', maxAgeDays: 2555 },
];
for (const policy of retentionPolicies) {
const cutoffDate = new Date();
cutoffDate.setDate(cutoffDate.getDate() - policy.maxAgeDays);
const deleted = await prisma[policy.table].deleteMany({
where: {
[policy.field]: { lt: cutoffDate },
},
});
.();
}
();
});
(): <> {
archiveCutoff = ();
archiveCutoff.(archiveCutoff.() - );
oldContacts = prisma..({
: { : { : archiveCutoff } },
});
(oldContacts. > ) {
(, oldContacts);
}
}
Data Export
import { stringify } from 'csv-stringify/sync';
import { createWriteStream } from 'fs';
import archiver from 'archiver';
interface ExportOptions {
format: 'csv' | 'json';
includeEngagements: boolean;
dateRange?: { start: Date; end: Date };
}
export async function exportContactData(
criteria: any,
options: ExportOptions
): Promise<string> {
const contacts = await prisma.contact.findMany({
where: {
...criteria,
...(options.dateRange && {
createdAt: {
gte: options.dateRange.start,
lte: options.dateRange.end,
},
}),
},
include: options.includeEngagements ? { engagements: true } : undefined,
});
filename = ;
(options. === ) {
csv = (contacts, {
: ,
: [, , , , , ],
});
(, csv);
;
} {
(, .(contacts, , ));
;
}
}
(): <> {
data = .(contacts);
encrypted = (data, encryptionKey);
encrypted;
}
Data Encryption
import crypto from 'crypto';
const ALGORITHM = 'aes-256-gcm';
const IV_LENGTH = 16;
const AUTH_TAG_LENGTH = 16;
export function encryptPII(plaintext: string, key: Buffer): string {
const iv = crypto.randomBytes(IV_LENGTH);
const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
let encrypted = cipher.update(plaintext, 'utf8', 'hex');
encrypted += cipher.final('hex');
const authTag = cipher.getAuthTag();
return `${iv.toString('hex')}:${authTag.toString('hex')}:${encrypted}`;
}
export function decryptPII(encrypted: string, key: Buffer): {
[ivHex, authTagHex, ciphertext] = encrypted.();
iv = .(ivHex, );
authTag = .(authTagHex, );
decipher = crypto.(, key, iv);
decipher.(authTag);
decrypted = decipher.(ciphertext, , );
decrypted += decipher.();
decrypted;
}
encryptedFields = {
: {
: (value, ()),
: (value, ()),
},
: {
: (value, ()),
: (value, ()),
},
};
Audit Logging
interface AuditEntry {
action: string;
actor: string;
resource: string;
resourceId: string;
changes?: Record<string, { old: any; new: any }>;
metadata?: Record<string, any>;
timestamp: Date;
}
export async function logDataAccess(entry: AuditEntry): Promise<void> {
await prisma.auditLog.create({
data: {
action: entry.action,
actor: entry.actor,
resource: entry.resource,
resourceId: entry.resourceId,
changes: entry.changes ? JSON.stringify(entry.changes) : null,
metadata: entry.metadata ? .(entry.) : ,
: entry.,
},
});
}
() {
originalSend = res.;
res. = () {
(req..() && req. === ) {
({
: ,
: req.?. || ,
: ,
: req.. || ,
: {
: req.,
: req.,
: body?.,
},
: (),
});
}
originalSend.(, body);
};
();
}
Output
- GDPR compliance (access, erasure, consent)
- Data retention policies
- Secure data export
- Column-level encryption
- Comprehensive audit logging
Error Handling
| Issue | Resolution |
|---|
| Export too large | Implement streaming |
| Encryption key lost | Use key management service |
| Audit log gaps | Implement retry queue |
| Consent conflicts | Use latest consent record |
Resources
Next Steps
Proceed to apollo-enterprise-rbac for access control.