diff --git a/packages/destination-actions/src/destinations/liveramp-audiences/__tests__/__snapshots__/snapshot.test.ts.snap b/packages/destination-actions/src/destinations/liveramp-audiences/__tests__/__snapshots__/snapshot.test.ts.snap index 218d1a84da..22b8058a8b 100644 --- a/packages/destination-actions/src/destinations/liveramp-audiences/__tests__/__snapshots__/snapshot.test.ts.snap +++ b/packages/destination-actions/src/destinations/liveramp-audiences/__tests__/__snapshots__/snapshot.test.ts.snap @@ -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`] = ` @@ -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", @@ -37,7 +37,7 @@ Headers { "Segment (Actions)", ], "x-amz-content-sha256": Array [ - "c52b8202716894946461f92ea7d3ae902483d4c0339c06e616618d84bce9d642", + "7a49d5af27bc7082b91a53af6cdf36cb91586b219e408b0873a7f4740c7545b8", ], "x-amz-date": Array [ "19700101T000012Z", diff --git a/packages/destination-actions/src/destinations/liveramp-audiences/audienceEntered/generated-types.ts b/packages/destination-actions/src/destinations/liveramp-audiences/audienceEntered/generated-types.ts index 988f49093c..3daa26deb1 100644 --- a/packages/destination-actions/src/destinations/liveramp-audiences/audienceEntered/generated-types.ts +++ b/packages/destination-actions/src/destinations/liveramp-audiences/audienceEntered/generated-types.ts @@ -6,11 +6,17 @@ export interface Payload { */ audience_key: string /** - * Additional data pertaining to the user. + * Additional data pertaining to the user to be written to the file. */ identifier_data?: { [k: string]: unknown } + /** + * Additional data pertaining to the user to be hashed before written to the file + */ + unhashed_identifier_data?: { + [k: string]: unknown + } /** * Character used to separate tokens in the resulting file. */ diff --git a/packages/destination-actions/src/destinations/liveramp-audiences/audienceEntered/index.ts b/packages/destination-actions/src/destinations/liveramp-audiences/audienceEntered/index.ts index bc3a0fa808..20d4e3ae85 100644 --- a/packages/destination-actions/src/destinations/liveramp-audiences/audienceEntered/index.ts +++ b/packages/destination-actions/src/destinations/liveramp-audiences/audienceEntered/index.ts @@ -19,11 +19,17 @@ const action: ActionDefinition = { }, 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', diff --git a/packages/destination-actions/src/destinations/liveramp-audiences/operations.ts b/packages/destination-actions/src/destinations/liveramp-audiences/operations.ts index 99ef51b866..3e46e8d46f 100644 --- a/packages/destination-actions/src/destinations/liveramp-audiences/operations.ts +++ b/packages/destination-actions/src/destinations/liveramp-audiences/operations.ts @@ -1,3 +1,4 @@ +import { createHash } from 'crypto' import type { Payload } from './audienceEntered/generated-types' /* @@ -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 @@ -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')) @@ -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 }