From 9bb6f529fce291ddd4e200a5dc08e474d5fd3d49 Mon Sep 17 00:00:00 2001 From: Leonel Sanches <113376080+seg-leonelsanches@users.noreply.github.com> Date: Tue, 7 May 2024 05:23:39 -0700 Subject: [PATCH] Also not double-hashing the phone for TikTok Audiences (#1770) * Also not double-hashing the phone for TikTok Audiences * Just renaming the variable. --- .../__tests__/functions.test.ts | 24 +++++++++++++++++++ .../tiktok-audiences/functions.ts | 12 +++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/destination-actions/src/destinations/tiktok-audiences/__tests__/functions.test.ts b/packages/destination-actions/src/destinations/tiktok-audiences/__tests__/functions.test.ts index 61bb33a328..0dfcd433a8 100644 --- a/packages/destination-actions/src/destinations/tiktok-audiences/__tests__/functions.test.ts +++ b/packages/destination-actions/src/destinations/tiktok-audiences/__tests__/functions.test.ts @@ -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') + }) }) }) diff --git a/packages/destination-actions/src/destinations/tiktok-audiences/functions.ts b/packages/destination-actions/src/destinations/tiktok-audiences/functions.ts index 0b8e3b9f5d..7ff5b0ce42 100644 --- a/packages/destination-actions/src/destinations/tiktok-audiences/functions.ts +++ b/packages/destination-actions/src/destinations/tiktok-audiences/functions.ts @@ -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: {}[][] = [] @@ -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') } @@ -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] } }