Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also not double-hashing the phone for TikTok Audiences #1770

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,29 @@ describe('TikTok Audiences Functions', () => {
const result: any[][] = extractUsers([payload])
expect(result[0][0].id).toEqual('77bc071241f37b4736df28c0c1cb0a99163d1050696134325b99246b2183d408')
})

it('Should hash phone number when phone is in a plain format', () => {
const payload = {
phone: '+1 (555) 555-5555',
send_phone: true,
audience_id: '1234567890',
advertising_id: '12345'
}

const result: any[][] = extractUsers([payload])
expect(result[0][0].id).toEqual('e5aaca26e304714083dccf6d2dbc16466e9cde94ca54feefa3dca412e2eeb74e')
})

it('Should NOT hash phone number when phone is already hashed', () => {
const payload = {
phone: 'e5aaca26e304714083dccf6d2dbc16466e9cde94ca54feefa3dca412e2eeb74e',
send_phone: true,
audience_id: '1234567890',
advertising_id: '12345'
}

const result: any[][] = extractUsers([payload])
expect(result[0][0].id).toEqual('e5aaca26e304714083dccf6d2dbc16466e9cde94ca54feefa3dca412e2eeb74e')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function getIDSchema(payload: GenericPayload): string[] {
return id_schema
}

const isHashedEmail = (email: string): boolean => new RegExp(/[0-9abcdef]{64}/gi).test(email)
const isHashedInformation = (information: string): boolean => new RegExp(/[0-9abcdef]{64}/gi).test(information)

export function extractUsers(payloads: GenericPayload[]): {}[][] {
const batch_data: {}[][] = []
Expand Down Expand Up @@ -131,7 +131,7 @@ export function extractUsers(payloads: GenericPayload[]): {}[][] {

// If email is already hashed, don't hash it again
let hashedEmail = payload.email
if (!isHashedEmail(payload.email)) {
if (!isHashedInformation(payload.email)) {
hashedEmail = createHash('sha256').update(payload.email).digest('hex')
}

Expand All @@ -146,8 +146,14 @@ export function extractUsers(payloads: GenericPayload[]): {}[][] {
if (payload.send_phone === true) {
let phone_id = {}
if (payload.phone) {
// If phone is already hashed, don't hash it again
let hashedPhone = payload.phone
if (!isHashedInformation(payload.phone)) {
hashedPhone = createHash('sha256').update(payload.phone).digest('hex')
}

phone_id = {
id: createHash('sha256').update(payload.phone).digest('hex'),
id: hashedPhone,
audience_ids: [external_audience_id]
}
}
Expand Down
Loading