Skip to content

Commit

Permalink
Also not double-hashing the phone for TikTok Audiences (#1770)
Browse files Browse the repository at this point in the history
* Also not double-hashing the phone for TikTok Audiences

* Just renaming the variable.
  • Loading branch information
seg-leonelsanches authored May 7, 2024
1 parent 1524355 commit 9bb6f52
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
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

0 comments on commit 9bb6f52

Please sign in to comment.