Skip to content

Commit b7ab09d

Browse files
Support channel id as audience identifier
1 parent a11d1ce commit b7ab09d

17 files changed

Lines changed: 233 additions & 43 deletions

File tree

packages/destination-actions/src/destinations/airship/__tests__/__snapshots__/snapshot.test.ts.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Array [
1313
},
1414
"occurred": false,
1515
"user": Object {
16-
"named_user_id": "Z8PnKI8*YgWA",
16+
"Z8PnKI8*YgWA": "Z8PnKI8*YgWA",
1717
},
1818
},
1919
]
@@ -31,7 +31,7 @@ Array [
3131
},
3232
"occurred": false,
3333
"user": Object {
34-
"named_user_id": "Z8PnKI8*YgWA",
34+
"channel": "Z8PnKI8*YgWA",
3535
},
3636
},
3737
]
@@ -40,15 +40,15 @@ Array [
4040
exports[`Testing snapshot for actions-airship destination: manageTags action - all fields 1`] = `
4141
Object {
4242
"audience": Object {
43-
"named_user_id": "XvmIpuaw",
43+
"XvmIpuaw": "XvmIpuaw",
4444
},
4545
}
4646
`;
4747

4848
exports[`Testing snapshot for actions-airship destination: manageTags action - required fields 1`] = `
4949
Object {
5050
"audience": Object {
51-
"named_user_id": "XvmIpuaw",
51+
"channel": "XvmIpuaw",
5252
},
5353
}
5454
`;
@@ -207,7 +207,7 @@ Object {
207207
},
208208
],
209209
"audience": Object {
210-
"named_user_id": "*N75*",
210+
"*N75*": "*N75*",
211211
},
212212
}
213213
`;
@@ -216,7 +216,7 @@ exports[`Testing snapshot for actions-airship destination: setAttributes action
216216
Object {
217217
"attributes": Array [],
218218
"audience": Object {
219-
"named_user_id": "*N75*",
219+
"channel": "*N75*",
220220
},
221221
}
222222
`;

packages/destination-actions/src/destinations/airship/__tests__/airship.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,72 @@ describe('Airship', () => {
129129
})
130130
})
131131

132+
describe('setAttribute with channel_id', () => {
133+
it('should use channel audience', async () => {
134+
const now = new Date().toISOString()
135+
const event = createTestEvent({
136+
timestamp: now,
137+
traits: { trait1: 1 }
138+
})
139+
140+
nock('https://go.urbanairship.com').post('/api/channels/attributes').reply(200, {})
141+
142+
const responses = await testDestination.testAction('setAttributes', {
143+
event,
144+
settings: { access_token: 'foo', app_key: 'bar', endpoint: 'US' },
145+
mapping: {
146+
channel_id: 'chan-abc',
147+
channel_type: 'email',
148+
occurred: now,
149+
attributes: { trait1: 1 }
150+
}
151+
})
152+
expect(responses[0].status).toBe(200)
153+
})
154+
})
155+
156+
describe('customEvents with channel_id', () => {
157+
it('should use channel audience', async () => {
158+
const now = new Date().toISOString()
159+
const event = createTestEvent({ type: 'track', timestamp: now })
160+
161+
nock('https://go.urbanairship.com').post('/api/custom-events').reply(200, {})
162+
163+
const responses = await testDestination.testAction('customEvents', {
164+
event,
165+
settings: { access_token: 'foo', app_key: 'bar', endpoint: 'US' },
166+
mapping: {
167+
channel_id: 'chan-abc',
168+
channel_type: 'email',
169+
name: 'Test Event',
170+
occurred: now,
171+
enable_batching: false
172+
}
173+
})
174+
expect(responses[0].status).toBe(200)
175+
})
176+
})
177+
178+
describe('manageTags with channel_id', () => {
179+
it('should use channel audience', async () => {
180+
const event = createTestEvent({ traits: { airship_tags: { tag1: true } } })
181+
182+
nock('https://go.urbanairship.com').post('/api/channels/tags').reply(200, {})
183+
184+
const responses = await testDestination.testAction('manageTags', {
185+
event,
186+
settings: { access_token: 'foo', app_key: 'bar', endpoint: 'US' },
187+
mapping: {
188+
channel_id: 'chan-abc',
189+
channel_type: 'sms',
190+
tags: { tag1: true },
191+
tag_group: 'segment-integration'
192+
}
193+
})
194+
expect(responses[0].status).toBe(200)
195+
})
196+
})
197+
132198
describe('delete', () => {
133199
it('should support deletes', async () => {
134200
const event = createTestEvent({

packages/destination-actions/src/destinations/airship/__tests__/utilities.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,62 @@ describe('Testing _parse_and_format_date', () => {
269269
expect(_private._parse_and_format_date('foo')).toEqual('foo')
270270
})
271271
})
272+
273+
describe('Testing _build_audience', () => {
274+
it('should return named_user_id audience when only named_user_id is provided', () => {
275+
expect(_private._build_audience({ named_user_id: 'user-123' })).toEqual({ named_user_id: 'user-123' })
276+
})
277+
278+
it('should return channel audience when channel_id and channel_type are provided', () => {
279+
expect(_private._build_audience({ channel_id: 'chan-abc', channel_type: 'email' })).toEqual({
280+
email: 'chan-abc'
281+
})
282+
})
283+
284+
it('should use channel selector when all three fields are provided (channel_id takes precedence)', () => {
285+
expect(_private._build_audience({ named_user_id: 'user-123', channel_id: 'chan-abc', channel_type: 'email' })).toEqual({
286+
email: 'chan-abc'
287+
})
288+
})
289+
290+
it('should use generic channel audience when channel_id provided without channel_type', () => {
291+
expect(_private._build_audience({ channel_id: 'chan-abc' })).toEqual({ channel: 'chan-abc' })
292+
})
293+
294+
it('should use generic channel audience when channel_id provided without channel_type even if named_user_id is present', () => {
295+
expect(_private._build_audience({ named_user_id: 'user-123', channel_id: 'chan-abc' })).toEqual({
296+
channel: 'chan-abc'
297+
})
298+
})
299+
300+
it('should throw when neither named_user_id nor channel_id is provided', () => {
301+
expect(() => _private._build_audience({})).toThrow('Either Named User ID or Channel ID must be provided')
302+
})
303+
})
304+
305+
describe('Testing _build_custom_event_object with channel_id', () => {
306+
it('should use channel audience when channel_id is provided', () => {
307+
const payload: CustomEventsPayload = {
308+
channel_id: 'chan-abc',
309+
channel_type: 'email',
310+
name: 'Test Event',
311+
occurred: occurred.toISOString(),
312+
enable_batching: false
313+
}
314+
const result = _private._build_custom_event_object(payload) as any
315+
expect(result.user).toEqual({ email: 'chan-abc' })
316+
})
317+
})
318+
319+
describe('Testing _build_tags_object with channel_id', () => {
320+
it('should use channel audience when channel_id is provided', () => {
321+
const payload: ManageTagsPayload = {
322+
channel_id: 'chan-abc',
323+
channel_type: 'sms',
324+
tag_group: 'segment-integration',
325+
tags: { trait3: true }
326+
}
327+
const result = _private._build_tags_object(payload) as any
328+
expect(result.audience).toEqual({ sms: 'chan-abc' })
329+
})
330+
})

packages/destination-actions/src/destinations/airship/customEvents/__tests__/__snapshots__/index.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Array [
1212
},
1313
"occurred": false,
1414
"user": Object {
15-
"named_user_id": "5C5XZ3fWrH)z48",
15+
"channel": "5C5XZ3fWrH)z48",
1616
},
1717
},
1818
]

packages/destination-actions/src/destinations/airship/customEvents/__tests__/__snapshots__/snapshot.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Array [
1313
},
1414
"occurred": false,
1515
"user": Object {
16-
"named_user_id": "5C5XZ3fWrH)z48",
16+
"5C5XZ3fWrH)z48": "5C5XZ3fWrH)z48",
1717
},
1818
},
1919
]
@@ -31,7 +31,7 @@ Array [
3131
},
3232
"occurred": false,
3333
"user": Object {
34-
"named_user_id": "5C5XZ3fWrH)z48",
34+
"channel": "5C5XZ3fWrH)z48",
3535
},
3636
},
3737
]

packages/destination-actions/src/destinations/airship/customEvents/generated-types.ts

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/destination-actions/src/destinations/airship/customEvents/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,25 @@ const action: ActionDefinition<Settings, Payload> = {
1010
fields: {
1111
named_user_id: {
1212
label: 'Airship Named User ID',
13-
description: 'The identifier assigned in Airship as the Named User',
13+
description: 'The identifier assigned in Airship as the Named User. Provide either this or Channel ID.',
1414
type: 'string',
15-
required: true,
15+
required: false,
1616
default: {
1717
'@path': '$.userId'
1818
}
1919
},
20+
channel_id: {
21+
label: 'Channel ID',
22+
description: 'Airship Channel ID. Provide either this or Named User ID.',
23+
type: 'string',
24+
required: false
25+
},
26+
channel_type: {
27+
label: 'Channel Type',
28+
description: 'The Airship audience key for the channel type (e.g. android_channel, ios_channel, amazon_channel, web_channel). If omitted, the generic channel key is used and Airship will resolve the type, which may introduce a slight delay.',
29+
type: 'string',
30+
required: false
31+
},
2032
name: {
2133
label: 'Name',
2234
description: 'Event Name',

packages/destination-actions/src/destinations/airship/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ const destination: DestinationDefinition<Settings> = {
2424
label: 'Access Token',
2525
description: 'Create in the Airship Go dashboard in Settings->Partner Integrations->Segment',
2626
type: 'password',
27-
// default: process.env.DEFAULT_ACCESS_TOKEN,
27+
default: process.env.DEFAULT_ACCESS_TOKEN,
2828
required: true
2929
},
3030
app_key: {
3131
label: 'App Key',
3232
description: 'The App Key identifies the Airship Project to which API requests are made.',
3333
type: 'password',
34-
// default: process.env.DEFAULT_APP_KEY,
34+
default: process.env.DEFAULT_APP_KEY,
3535
required: true
3636
},
3737
endpoint: {

packages/destination-actions/src/destinations/airship/manageTags/__tests__/__snapshots__/index.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
exports[`Testing snapshot for Airship's manageTags destination action: all fields 1`] = `
44
Object {
55
"audience": Object {
6-
"named_user_id": "s0s43LdN(JFJswcY3#g3",
6+
"s0s43LdN(JFJswcY3#g3": "s0s43LdN(JFJswcY3#g3",
77
},
88
}
99
`;
1010

1111
exports[`Testing snapshot for Airship's manageTags destination action: required fields 1`] = `
1212
Object {
1313
"audience": Object {
14-
"named_user_id": "s0s43LdN(JFJswcY3#g3",
14+
"channel": "s0s43LdN(JFJswcY3#g3",
1515
},
1616
}
1717
`;

packages/destination-actions/src/destinations/airship/manageTags/__tests__/__snapshots__/snapshot.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
exports[`Testing snapshot for Airship's manageTags destination action: all fields 1`] = `
44
Object {
55
"audience": Object {
6-
"named_user_id": "s0s43LdN(JFJswcY3#g3",
6+
"s0s43LdN(JFJswcY3#g3": "s0s43LdN(JFJswcY3#g3",
77
},
88
}
99
`;
1010

1111
exports[`Testing snapshot for Airship's manageTags destination action: required fields 1`] = `
1212
Object {
1313
"audience": Object {
14-
"named_user_id": "s0s43LdN(JFJswcY3#g3",
14+
"channel": "s0s43LdN(JFJswcY3#g3",
1515
},
1616
}
1717
`;

0 commit comments

Comments
 (0)