Skip to content

Commit

Permalink
LiveRamp: add support for hashing (#1372)
Browse files Browse the repository at this point in the history
* add support for hashing

* Update snapshot.test.ts

* updated snapshots

* update snapshots
  • Loading branch information
rhall-twilio authored Jul 6, 2023
1 parent e05e642 commit a76b6bf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing snapshot for LiverampAudiences's audienceEntered destination action: all fields 1`] = `
"audience_key,testType
\\"PywYAY\\",\\"PywYAY\\""
"audience_key,testType,testType
\\"PywYAY\\",\\"PywYAY\\",\\"7c7ff3a8560d336d69d788505dafaee28b45e77aecd04dd34648e3435865bb38\\""
`;

exports[`Testing snapshot for LiverampAudiences's audienceEntered destination action: enquotated indentifier data 1`] = `
Expand All @@ -14,18 +14,18 @@ Array [
`;

exports[`Testing snapshot for LiverampAudiences's audienceEntered destination action: required fields 1`] = `
"audience_key,testType
\\"PywYAY\\",\\"PywYAY\\""
"audience_key,testType,testType
\\"PywYAY\\",\\"PywYAY\\",\\"7c7ff3a8560d336d69d788505dafaee28b45e77aecd04dd34648e3435865bb38\\""
`;

exports[`Testing snapshot for LiverampAudiences's audienceEntered destination action: required fields 2`] = `
Headers {
Symbol(map): Object {
"authorization": Array [
"AWS4-HMAC-SHA256 Credential=PywYAY/19700101/PywYAY/s3/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-content-sha256;x-amz-date, Signature=0e2838c897a25891722f065e3c21b3592e67626b4a50f2f1ad0f78ad1a7ad524",
"AWS4-HMAC-SHA256 Credential=PywYAY/19700101/PywYAY/s3/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-content-sha256;x-amz-date, Signature=e2fe7f56f215ba3c674806db5629bdfffdd3ab2d2b03450c20a219aa713ed8d4",
],
"content-length": Array [
"39",
"115",
],
"content-type": Array [
"application/x-www-form-urlencoded; charset=utf-8",
Expand All @@ -37,7 +37,7 @@ Headers {
"Segment (Actions)",
],
"x-amz-content-sha256": Array [
"c52b8202716894946461f92ea7d3ae902483d4c0339c06e616618d84bce9d642",
"7a49d5af27bc7082b91a53af6cdf36cb91586b219e408b0873a7f4740c7545b8",
],
"x-amz-date": Array [
"19700101T000012Z",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ const action: ActionDefinition<Settings, Payload> = {
},
identifier_data: {
label: 'Identifier Data',
description: `Additional data pertaining to the user.`,
description: `Additional data pertaining to the user to be written to the file.`,
type: 'object',
required: false,
defaultObjectUI: 'keyvalue:only',
default: { '@path': '$.context.traits' }
defaultObjectUI: 'keyvalue:only'
},
unhashed_identifier_data: {
label: 'Hashable Identifier Data',
description: `Additional data pertaining to the user to be hashed before written to the file`,
type: 'object',
required: false,
defaultObjectUI: 'keyvalue:only'
},
delimiter: {
label: 'Delimeter',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createHash } from 'crypto'
import type { Payload } from './audienceEntered/generated-types'

/*
Expand All @@ -7,11 +8,19 @@ liveramp_audience_key[1],identifier_data[0..n]
function generateFile(payloads: Payload[]) {
const rows = []
const headers = ['audience_key']

// Prepare header row
if (payloads[0].identifier_data) {
for (const identifier of Object.getOwnPropertyNames(payloads[0].identifier_data)) {
headers.push(identifier)
}
}

if (payloads[0].unhashed_identifier_data) {
for (const identifier of Object.getOwnPropertyNames(payloads[0].unhashed_identifier_data)) {
headers.push(identifier)
}
}
rows.push(headers.join(payloads[0].delimiter))

// Prepare data rows
Expand All @@ -23,10 +32,16 @@ function generateFile(payloads: Payload[]) {
row.push(payload.identifier_data[identifier] as string)
}
}

if (payload.unhashed_identifier_data) {
for (const identifier of Object.getOwnPropertyNames(payload.unhashed_identifier_data)) {
row.push(hash(payload.unhashed_identifier_data[identifier] as string))
}
}
rows.push(row.map(enquoteIdentifier).join(payload.delimiter))
}

// STRATCONN-2584: verify multiple emails are handled
// TODO: verify multiple emails are handled
const filename = payloads[0].filename
const fileContent = Buffer.from(rows.join('\n'))

Expand All @@ -45,4 +60,10 @@ function enquoteIdentifier(identifier: string) {
return `"${identifier.replace(/"/g, '""')}"`
}

const hash = (value: string): string => {
const hash = createHash('sha256')
hash.update(value)
return hash.digest('hex')
}

export { generateFile, enquoteIdentifier }

0 comments on commit a76b6bf

Please sign in to comment.