-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new kevel-audience Destination (#1910)
* adding kevel-audience Destination * fixing spelling issue
- Loading branch information
1 parent
ca71fbf
commit 726d281
Showing
9 changed files
with
258 additions
and
5 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
packages/destination-actions/src/destinations/kevel-audience/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
packages/destination-actions/src/destinations/kevel-audience/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import type { DestinationDefinition } from '@segment/actions-core' | ||
import type { Settings } from './generated-types' | ||
|
||
import syncKevelAudience from './syncKevelAudience' | ||
|
||
const destination: DestinationDefinition<Settings> = { | ||
name: 'Kevel Audience (Actions)', | ||
slug: 'actions-kevel-audience', | ||
description: | ||
'Sync Segment user profile traits and Engage Audiences to Kevel Audiences. Only users with a Segment userId will be synced.', | ||
mode: 'cloud', | ||
|
||
authentication: { | ||
scheme: 'custom', | ||
fields: { | ||
audienceDomain: { | ||
label: 'Kevel Audience Domain', | ||
description: 'Your Kevel Audience root subdomain. For example: "cdp.yourdomain.com".', | ||
type: 'string', | ||
required: true | ||
}, | ||
userIdType: { | ||
label: 'Kevel Audience User ID Type', | ||
description: 'Kevel Audience User ID Type to map your Segment User ID to. For example: "crm".', | ||
type: 'string', | ||
required: true | ||
}, | ||
clientId: { | ||
label: 'Kevel Audience client ID', | ||
description: 'The Kevel Audience client ID to identify the event. For example: "brand-name".', | ||
type: 'string', | ||
required: true | ||
}, | ||
siteId: { | ||
label: 'Kevel Audience site ID', | ||
description: 'The Kevel Audience site ID to identify the event. For example: "segment-app".', | ||
type: 'string', | ||
required: true | ||
}, | ||
apiKey: { | ||
label: 'Kevel Audience API Key', | ||
description: | ||
'The Kevel Audience API Key to authorize the requests. Get yours from your Kevel Customer Success representative.', | ||
type: 'string', | ||
required: true | ||
}, | ||
eventType: { | ||
label: 'Event Type', | ||
description: 'The type of event to send to Kevel Audience. For example: "segmentSync".', | ||
type: 'string', | ||
required: true | ||
} | ||
} | ||
}, | ||
extendRequest() { | ||
return { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
} | ||
}, | ||
actions: { | ||
syncKevelAudience | ||
} | ||
} | ||
|
||
export default destination |
87 changes: 87 additions & 0 deletions
87
...ination-actions/src/destinations/kevel-audience/syncKevelAudience/__tests__/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import nock from 'nock' | ||
import { createTestEvent, createTestIntegration } from '@segment/actions-core' | ||
import Destination from '../../index' | ||
|
||
const testDestination = createTestIntegration(Destination) | ||
|
||
const goodTrackEvent = createTestEvent({ | ||
type: 'track', | ||
userId: 'uid1', | ||
context: { | ||
personas: { | ||
computation_class: 'audience', | ||
computation_key: 'kevel_segment_test_name' | ||
}, | ||
traits: { | ||
email: 'test@email.com' | ||
} | ||
}, | ||
properties: { | ||
audience_key: 'kevel_segment_test_name', | ||
kevel_segment_test_name: true | ||
} | ||
}) | ||
|
||
const goodIdentifyEvent = createTestEvent({ | ||
type: 'identify', | ||
userId: 'uid1', | ||
context: { | ||
personas: { | ||
computation_class: 'audience', | ||
computation_key: 'kevel_segment_test_name' | ||
} | ||
}, | ||
traits: { | ||
audience_key: 'kevel_segment_test_name', | ||
kevel_segment_test_name: true | ||
}, | ||
properties: undefined | ||
}) | ||
|
||
describe('KevelAuddience.syncKevelAudience', () => { | ||
it('should not throw an error if the audience creation succeed - track', async () => { | ||
const baseUrl = 'https://tr.domain.brand.com/' | ||
|
||
nock(baseUrl) | ||
.post('/events/server', (body) => body.customData.kevel_segment_test_name === true) | ||
.reply(200) | ||
|
||
await expect( | ||
testDestination.testAction('syncKevelAudience', { | ||
event: goodTrackEvent, | ||
settings: { | ||
audienceDomain: 'domain.brand.com', | ||
userIdType: 'email_sha256', | ||
apiKey: 'api_key', | ||
clientId: 'client_id', | ||
siteId: 'site_id', | ||
eventType: 'segmentSync' | ||
}, | ||
useDefaultMappings: true | ||
}) | ||
).resolves.not.toThrowError() | ||
}) | ||
|
||
it('should not throw an error if the audience creation succeed - identify', async () => { | ||
const baseUrl = 'https://tr.domain.brand.com' | ||
|
||
nock(baseUrl) | ||
.post('/events/server', (body) => body.customData.kevel_segment_test_name === true) | ||
.reply(200) | ||
|
||
await expect( | ||
testDestination.testAction('syncKevelAudience', { | ||
event: goodIdentifyEvent, | ||
settings: { | ||
audienceDomain: 'domain.brand.com', | ||
userIdType: 'email_sha256', | ||
apiKey: 'api_key', | ||
clientId: 'client_id', | ||
siteId: 'site_id', | ||
eventType: 'segmentSync' | ||
}, | ||
useDefaultMappings: true | ||
}) | ||
).resolves.not.toThrowError() | ||
}) | ||
}) |
14 changes: 14 additions & 0 deletions
14
.../destination-actions/src/destinations/kevel-audience/syncKevelAudience/generated-types.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
packages/destination-actions/src/destinations/kevel-audience/syncKevelAudience/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { ActionDefinition } from '@segment/actions-core' | ||
import type { Settings } from '../generated-types' | ||
import type { Payload } from './generated-types' | ||
|
||
const action: ActionDefinition<Settings, Payload> = { | ||
title: 'Sync Kevel Audience', | ||
description: | ||
'Sync Segment user profile traits and Engage Audiences to Kevel Audiences. Only users with a Segment userId will be synced.', | ||
defaultSubscription: 'type = "track" or type = "identify"', | ||
fields: { | ||
segment_user_id: { | ||
label: 'User ID', | ||
description: "The user's unique ID", | ||
type: 'string', | ||
unsafe_hidden: true, | ||
required: true, | ||
default: { '@path': '$.userId' } | ||
}, | ||
traits_or_props: { | ||
label: 'Traits or properties object', | ||
description: 'A computed object for track and identify events. This field should not need to be edited.', | ||
type: 'object', | ||
required: true, | ||
unsafe_hidden: true, | ||
default: { | ||
'@if': { | ||
exists: { '@path': '$.properties' }, | ||
then: { '@path': '$.properties' }, | ||
else: { '@path': '$.traits' } | ||
} | ||
} | ||
} | ||
}, | ||
perform: async (request, data) => { | ||
const baseUrl = `https://tr.${data.settings.audienceDomain}/events/server` // TODO event tracker | ||
const payload = { | ||
clientId: data.settings.clientId, | ||
siteId: data.settings.siteId, | ||
type: 'custom', | ||
customType: data.settings.eventType, | ||
user: { | ||
type: data.settings.userIdType, | ||
id: data.payload.segment_user_id | ||
}, | ||
customData: data.payload.traits_or_props | ||
} | ||
|
||
return request(`${baseUrl}`, { | ||
json: payload, | ||
method: 'POST' | ||
}) | ||
} | ||
} | ||
|
||
export default action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters