Skip to content

Commit

Permalink
Resolved conflicts , merged with main
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav Kochar committed Dec 12, 2024
2 parents 55949b0 + 5913cd9 commit 1ad0f81
Show file tree
Hide file tree
Showing 62 changed files with 1,549 additions and 340 deletions.
28 changes: 11 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
Expand All @@ -33,6 +36,11 @@ jobs:
registry-url: 'https://registry.npmjs.org'
cache: yarn

- name: Setup git credentials
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Install Dependencies
run: yarn install --frozen-lockfile

Expand All @@ -52,22 +60,6 @@ jobs:
run: |
yarn lerna publish from-package --yes --loglevel=verbose --dist-tag latest
release:
needs: build-and-publish # comment when testing locally with https://github.com/nektos/act

runs-on: ubuntu-20.04
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled to ensure the commit history for the repository is available to the action
fetch-tags: true

- name: Setup git credentials
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Generate Tags
id: get-release-tag
run: ./scripts/generate-release-tags.sh
Expand All @@ -79,5 +71,7 @@ jobs:
RELEASE_TAG: ${{ steps.get-release-tag.outputs.release-tag }}
with:
script: |
const cloudManifest = require('./packages/destination-actions/dist/destinations/index.js').manifest
const browserManifest = require('./packages/destinations-manifest/dist/index.js').manifest
const script = require('./scripts/github-action/create-github-release.js')
await script({github, context, core, exec})
await script({github, context, core, exec, cloudManifest, browserManifest})
2 changes: 1 addition & 1 deletion packages/destination-actions/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@segment/action-destinations",
"description": "Destination Actions engine and definitions.",
"version": "3.346.0",
"version": "3.349.0",
"repository": {
"type": "git",
"url": "https://github.com/segmentio/action-destinations",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Object {
"beforeRequest": Array [
[Function],
],
"body": "{\\"records\\":[{\\"externalUserId\\":\\"test-kochar-01\\",\\"countryCode\\":\\"US\\",\\"action\\":\\"CREATE\\",\\"hashedPII\\":[{\\"firstname\\":\\"44104fcaef8476724152090d6d7bd9afa8ca5b385f6a99d3c6cf36b943b9872d\\",\\"city\\":\\"b4c0372af033c406857a420644e46c806280a0bab8246bd0c62c7807f66f794f\\",\\"state\\":\\"92db9c574d420b2437b29d898d55604f61df6c17f5163e53337f2169dd70d38d\\",\\"email\\":\\"87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674\\"}]},{\\"externalUserId\\":\\"test-kochar-02\\",\\"countryCode\\":\\"US\\",\\"action\\":\\"DELETE\\",\\"hashedPII\\":[{\\"firstname\\":\\"44104fcaef8476724152090d6d7bd9afa8ca5b385f6a99d3c6cf36b943b9872d\\",\\"lastname\\":\\"4cd1cb0957bc59e698beab9e86f062f2e84138bff5a446e49762da8fe0c2f499\\",\\"address\\":\\"45cfec5f1df1af649d49fc74314d7c9272e2f63ae9119bd3ef4b22a040d98cbc\\",\\"postal\\":\\"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08\\",\\"state\\":\\"92db9c574d420b2437b29d898d55604f61df6c17f5163e53337f2169dd70d38d\\",\\"email\\":\\"bd0bcf03735a1a00c6f1dd21c63c5d819e7e450298f301698192e8df90da3bb3\\"}]}],\\"audienceId\\":379909525712777677}",
"body": "{\\"records\\":[{\\"externalUserId\\":\\"test_kochar-02\\",\\"countryCode\\":\\"US\\",\\"action\\":\\"DELETE\\",\\"hashedPII\\":[{\\"firstname\\":\\"44104fcaef8476724152090d6d7bd9afa8ca5b385f6a99d3c6cf36b943b9872d\\",\\"lastname\\":\\"4cd1cb0957bc59e698beab9e86f062f2e84138bff5a446e49762da8fe0c2f499\\",\\"address\\":\\"45cfec5f1df1af649d49fc74314d7c9272e2f63ae9119bd3ef4b22a040d98cbc\\",\\"postal\\":\\"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08\\",\\"state\\":\\"92db9c574d420b2437b29d898d55604f61df6c17f5163e53337f2169dd70d38d\\",\\"email\\":\\"bd0bcf03735a1a00c6f1dd21c63c5d819e7e450298f301698192e8df90da3bb3\\"}]}],\\"audienceId\\":379909525712777677}",
"headers": Headers {
Symbol(map): Object {
"amazon-advertising-api-clientid": Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ describe('AmazonAds.syncAudiencesToDSP', () => {
)
expect(response[0].options).toMatchSnapshot()
})
it('should throw an error when an event has invalid externalUserId', async () => {
await expect(
testDestination.testAction('syncAudiencesToDSP', {
event: {
...event,
userId: '[email protected]'
},
settings,
useDefaultMappings: true
})
).rejects.toThrowError('externalUserId must satisfy regular expression pattern: [0-9a-zA-Z\\-\\_]{1,128}}')
})

it('should work with batch events', async () => {
nock(`https://advertising-api.amazon.com`)
Expand All @@ -128,6 +140,7 @@ describe('AmazonAds.syncAudiencesToDSP', () => {
const events: SegmentEvent[] = [
{
...event,
userId: '[email protected]',
event: 'Audience Entered',
properties: {
audience_key: 'example_event_once_30_4_24_1',
Expand All @@ -140,7 +153,7 @@ describe('AmazonAds.syncAudiencesToDSP', () => {
},
{
...event,
userId: 'test-kochar-02',
userId: 'test_kochar-02',
event: 'Audience Exited',
properties: {
audience_key: 'example_event_once_30_4_24_1',
Expand All @@ -165,11 +178,52 @@ describe('AmazonAds.syncAudiencesToDSP', () => {
expect(response[0].status).toBe(202)
expect(response[0].data).toMatchObject({ jobRequestId: '1155d3e3-b18c-4b2b-a3b2-26173cdaf770' })
expect(response[0].options.body).toBe(
'{"records":[{"externalUserId":"test-kochar-01","countryCode":"US","action":"CREATE","hashedPII":[{"firstname":"44104fcaef8476724152090d6d7bd9afa8ca5b385f6a99d3c6cf36b943b9872d","city":"b4c0372af033c406857a420644e46c806280a0bab8246bd0c62c7807f66f794f","state":"92db9c574d420b2437b29d898d55604f61df6c17f5163e53337f2169dd70d38d","email":"87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674"}]},{"externalUserId":"test-kochar-02","countryCode":"US","action":"DELETE","hashedPII":[{"firstname":"44104fcaef8476724152090d6d7bd9afa8ca5b385f6a99d3c6cf36b943b9872d","lastname":"4cd1cb0957bc59e698beab9e86f062f2e84138bff5a446e49762da8fe0c2f499","address":"45cfec5f1df1af649d49fc74314d7c9272e2f63ae9119bd3ef4b22a040d98cbc","postal":"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08","state":"92db9c574d420b2437b29d898d55604f61df6c17f5163e53337f2169dd70d38d","email":"bd0bcf03735a1a00c6f1dd21c63c5d819e7e450298f301698192e8df90da3bb3"}]}],"audienceId":379909525712777677}'
'{"records":[{"externalUserId":"test_kochar-02","countryCode":"US","action":"DELETE","hashedPII":[{"firstname":"44104fcaef8476724152090d6d7bd9afa8ca5b385f6a99d3c6cf36b943b9872d","lastname":"4cd1cb0957bc59e698beab9e86f062f2e84138bff5a446e49762da8fe0c2f499","address":"45cfec5f1df1af649d49fc74314d7c9272e2f63ae9119bd3ef4b22a040d98cbc","postal":"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08","state":"92db9c574d420b2437b29d898d55604f61df6c17f5163e53337f2169dd70d38d","email":"bd0bcf03735a1a00c6f1dd21c63c5d819e7e450298f301698192e8df90da3bb3"}]}],"audienceId":379909525712777677}'
)
expect(response[0].options).toMatchSnapshot()
})

it('should throw an error when all events are having invalid externalUserId', async () => {
const events: SegmentEvent[] = [
{
...event,
userId: '[email protected]',
event: 'Audience Entered',
properties: {
audience_key: 'example_event_once_30_4_24_1',
example_event_once_30_4_24_1: true,
email: '[email protected]',
first_name: 'gaurav',
city: 'Gurgaon',
state: 'Haryana'
}
},
{
...event,
userId: '[email protected]',
event: 'Audience Exited',
properties: {
audience_key: 'example_event_once_30_4_24_1',
example_event_once_30_4_24_1: true,
email: '[email protected]',
postal: 'test',
address: '#501/2, Test Address',
first_name: 'gaurav',
last_name: 'kochar',
state: 'Haryana'
}
}
]

await expect(
testDestination.testBatchAction('syncAudiencesToDSP', {
events,
settings,
useDefaultMappings: true
})
).rejects.toThrowError('externalUserId must satisfy regular expression pattern: [0-9a-zA-Z\\-\\_]{1,128}}')
})

it('Handle Error when amazon ads API throw error', async () => {
nock(`https://advertising-api.amazon.com`)
.post('/amc/audiences/records')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ActionDefinition, RequestClient } from '@segment/actions-core'
import { ActionDefinition, RequestClient, PayloadValidationError } from '@segment/actions-core'
import type { AudienceSettings, Settings } from '../generated-types'
import type { Payload } from './generated-types'
import { CONSTANTS, RecordsResponseType } from '../utils'
import { CONSTANTS, RecordsResponseType, REGEX_EXTERNALUSERID } from '../utils'
import { createHash } from 'crypto'
import { AudienceRecord, HashedPIIObject } from '../types'

Expand Down Expand Up @@ -145,6 +145,11 @@ function createPayloadToUploadRecords(payloads: Payload[], audienceSettings: Aud
const records: AudienceRecord[] = []
const { audienceId } = payloads[0]
payloads.forEach((payload: Payload) => {
// Check if the externalUserId matches the pattern
if (!REGEX_EXTERNALUSERID.test(payload.externalUserId)) {
return // Skip to the next iteration
}

const hashedPII: HashedPIIObject = {}
if (payload.firstName) {
hashedPII.firstname = normalizeAndHash(payload.firstName)
Expand Down Expand Up @@ -179,6 +184,12 @@ function createPayloadToUploadRecords(payloads: Payload[], audienceSettings: Aud
}
records.push(payloadRecord)
})
// When all invalid payloads are being filtered out or discarded because they do not match the externalUserId regular expression pattern.
if (!records?.length) {
throw new PayloadValidationError(
'externalUserId must satisfy regular expression pattern: [0-9a-zA-Z\\-\\_]{1,128}}'
)
}

return {
records: records,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ export const getAuthSettings = (settings: SettingsWithOauth): OAuth2ClientCreden
clientSecret: process.env.ACTIONS_AMAZON_AMC_CLIENT_SECRET
} as OAuth2ClientCredentials
}
export const REGEX_EXTERNALUSERID = /^[0-9a-zA-Z-_]{1,128}$/
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Object {
},
"email": "[email protected]",
"ip_address": "33.172.51.152",
"sms_number": "XoS!vJs",
"phone": "XoS!vJs",
"status": "XoS!vJs",
"status_updated_at": "2021-02-01T00:00:00.000Z",
"tags": Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Object {
},
"email": "[email protected]",
"ip_address": "100.102.165.77",
"sms_number": "DVw6A7$UK[I",
"phone": "DVw6A7$UK[I",
"status": "DVw6A7$UK[I",
"status_updated_at": "2021-02-01T00:00:00.000Z",
"tags": Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Drip.identify', () => {
},
email: '[email protected]',
ip_address: '127.0.0.1',
sms_number: '1234567890',
phone: '1234567890',
status: 'unsubscribed',
status_updated_at: '2021-01-01T00:00:00Z',
tags: ['tag1', 'tag2'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const person = (payload: Payload) => {
})(),
email: payload.email,
ip_address: payload.ip,
sms_number: payload.phone,
phone: payload.phone,
status: payload.status,
status_updated_at: payload.status_updated_at,
tags: payload.tags?.split(',').map((tag) => tag.trim()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Object {
"data": Object {
"attributes": Object {
"anonymous_id": "mTdOx(Nl)",
"email": "[email protected]",
"email": "[email protected]",
"external_id": "mTdOx(Nl)",
"phone_number": "+5694788449",
},
Expand Down
Loading

0 comments on commit 1ad0f81

Please sign in to comment.