Skip to content

Commit

Permalink
Truncate emails in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
zachlatta committed May 21, 2024
1 parent cb94310 commit a8b60ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dotenv from 'dotenv'
import Airtable from 'airtable'

import loadCsv from './loadCsv'
import { formatDate, isWithinPastNDays } from './util'
import { formatDate, isWithinPastNDays, anonymizeEmail } from './util'

dotenv.config()

Expand All @@ -14,6 +14,8 @@ const loopsCsvExportPath = 'dev_files/loops_export.csv'
// process only the people who have lastEngagementAt in the past 365 days
const onlyLastYear = true

const truncateEmailsInLogs = true

if (!airtableApiKey) {
console.error('AIRTABLE_API_KEY must be set')
process.exit(1)
Expand Down Expand Up @@ -89,7 +91,8 @@ let updateQueue = []
let createQueue = []

for (let row of loopsData) {
console.log(` ${row.email}`)
let emailToLog = truncateEmailsInLogs ? anonymizeEmail(row.email) : row.email
console.log(` ${emailToLog}`)

if (row.userGroup != 'Hack Clubber') {
console.log(" Skipping because not Hack Clubber")
Expand Down
11 changes: 11 additions & 0 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ export function isWithinPastNDays(date, n) {
nDaysAgo.setDate(nDaysAgo.getDate() - n); // Subtract n days from the current date

return date >= nDaysAgo;
}

// zach@hackclub.com => zac*@hac*****.com
export function anonymizeEmail(email) {
let [localPart, domain] = email.split('@');
let [baseDomain, tld] = domain.split('.');

localPart = localPart.length > 3 ? localPart.slice(0, 3) + '*'.repeat(localPart.length - 3) : localPart;
domain = baseDomain.length > 3 ? baseDomain.slice(0, 3) + '*'.repeat(baseDomain.length - 3) : baseDomain;

return `${localPart}@${domain}.${tld}`;
}

0 comments on commit a8b60ae

Please sign in to comment.