Skip to content

Commit 9bd406e

Browse files
authored
STRATCONN-6462 - [Altertable] - Update destination ahead of public beta (#3683)
* Update Altertable's destination ahead of public beta - Add batch support - Add Alias handling - Fix `anonymous_id` - Fix `$screen` event * joe's feedback
1 parent cc5d5df commit 9bd406e

14 files changed

Lines changed: 699 additions & 326 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Testing snapshot for actions-altertable destination: alias action - all fields 1`] = `
4+
Object {
5+
"device_id": "ggO&g",
6+
"distinct_id": "ggO&g",
7+
"environment": "ggO&g",
8+
"new_user_id": "ggO&g",
9+
"timestamp": "2024-06-01T12:00:00.000Z",
10+
}
11+
`;
12+
13+
exports[`Testing snapshot for actions-altertable destination: alias action - required fields 1`] = `
14+
Object {
15+
"distinct_id": "ggO&g",
16+
"environment": "ggO&g",
17+
"new_user_id": "ggO&g",
18+
"timestamp": "2024-06-01T12:00:00.000Z",
19+
}
20+
`;
21+
322
exports[`Testing snapshot for actions-altertable destination: event action - all fields 1`] = `
423
Object {
24+
"anonymous_id": "UM[e12E",
525
"device_id": "UM[e12E",
626
"distinct_id": "UM[e12E",
727
"environment": "UM[e12E",
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import nock from 'nock'
2+
import { createTestEvent, createTestIntegration } from '@segment/actions-core'
3+
import Destination from '../../index'
4+
5+
const testDestination = createTestIntegration(Destination)
6+
7+
describe('Altertable.alias', () => {
8+
const endpoint = 'https://api.altertable.ai'
9+
const apiKey = 'test-api-key'
10+
const environment = 'test-environment'
11+
12+
beforeEach(() => nock.cleanAll())
13+
14+
it('should send alias to Altertable', async () => {
15+
const event = createTestEvent({
16+
previousId: 'prev-anon-id',
17+
userId: 'new-user-id',
18+
timestamp: '2026-01-05T09:35:42.275Z',
19+
context: {
20+
device: {
21+
id: 'device-xyz'
22+
}
23+
}
24+
})
25+
26+
nock(endpoint).post('/alias').reply(200, {})
27+
28+
const responses = await testDestination.testAction('alias', {
29+
event,
30+
useDefaultMappings: true,
31+
settings: {
32+
apiKey,
33+
endpoint,
34+
environment
35+
}
36+
})
37+
38+
expect(responses.length).toBe(1)
39+
expect(responses[0].status).toBe(200)
40+
const payload = JSON.parse(responses[0].options.body as string)
41+
expect(payload).toEqual({
42+
distinct_id: 'prev-anon-id',
43+
device_id: 'device-xyz',
44+
environment: 'test-environment',
45+
new_user_id: 'new-user-id',
46+
timestamp: '2026-01-05T09:35:42.275Z'
47+
})
48+
})
49+
})

packages/destination-actions/src/destinations/altertable/alias/generated-types.ts

Lines changed: 101 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import type { ActionDefinition } from '@segment/actions-core'
2+
import type { Settings } from '../generated-types'
3+
import type { Payload } from './generated-types'
4+
import { commonFields } from '../fields'
5+
import { sendAlias, sendAliasBatch } from '../utils'
6+
7+
const action: ActionDefinition<Settings, Payload> = {
8+
title: 'Alias',
9+
description: 'Link a previous anonymous or temporary ID to a user ID in Altertable.',
10+
defaultSubscription: 'type = "alias"',
11+
fields: {
12+
previousId: {
13+
label: 'Previous ID',
14+
description: 'The previous user identifier (maps to distinct_id in the Altertable API).',
15+
type: 'string',
16+
required: true,
17+
default: {
18+
'@path': '$.previousId'
19+
}
20+
},
21+
...commonFields,
22+
enable_batching: {
23+
label: 'Enable Batching',
24+
type: 'boolean',
25+
required: true,
26+
default: true,
27+
unsafe_hidden: true,
28+
description: 'When enabled, events are sent in batches to Altertable.'
29+
},
30+
batch_size: {
31+
label: 'Batch Size',
32+
type: 'number',
33+
required: false,
34+
default: 1000,
35+
unsafe_hidden: true,
36+
description: 'Maximum number of events per batch request.'
37+
},
38+
batch_bytes: {
39+
label: 'Batch Bytes',
40+
type: 'number',
41+
required: false,
42+
default: 4000000,
43+
unsafe_hidden: true,
44+
description: 'Maximum batch payload size in bytes.'
45+
}
46+
},
47+
perform: (request, { settings, payload }) => {
48+
return sendAlias(request, settings, payload)
49+
},
50+
performBatch: (request, { settings, payload }) => {
51+
return sendAliasBatch(request, settings, payload)
52+
}
53+
}
54+
55+
export default action

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`Testing snapshot for Altertable's event destination action: all fields 1`] = `
44
Object {
5+
"anonymous_id": "CHXbRcxq]U",
56
"device_id": "CHXbRcxq]U",
67
"distinct_id": "CHXbRcxq]U",
78
"environment": "CHXbRcxq]U",

packages/destination-actions/src/destinations/altertable/event/generated-types.ts

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

packages/destination-actions/src/destinations/altertable/event/index.ts

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,21 @@ import type { ActionDefinition } from '@segment/actions-core'
22
import type { Settings } from '../generated-types'
33
import type { Payload } from './generated-types'
44
import { commonFields } from '../fields'
5-
import { send } from '../utils'
5+
import { sendTrack, sendTrackBatch } from '../utils'
66

77
const action: ActionDefinition<Settings, Payload> = {
88
title: 'Track Event',
99
description: 'Track a single event in Altertable.',
1010
defaultSubscription: 'type = "track"',
1111
fields: {
12-
type: {
13-
label: 'Segment Event Type',
14-
description: 'The Segment event type',
15-
type: 'string',
16-
choices: [
17-
{ label: 'track', value: 'track' },
18-
{ label: 'page', value: 'page' },
19-
{ label: 'screen', value: 'screen' }
20-
],
21-
required: true,
22-
default: 'track'
23-
},
2412
event: {
2513
label: 'Event Name',
26-
description: 'The name of the event to track. Only required for `track` event type.',
14+
description: 'The name of the event to track.',
2715
type: 'string',
2816
default: {
2917
'@path': '$.event'
3018
},
31-
required: {
32-
conditions: [
33-
{
34-
fieldKey: 'eventType',
35-
operator: 'is',
36-
value: 'track'
37-
}
38-
]
39-
},
40-
depends_on: {
41-
conditions: [
42-
{
43-
fieldKey: 'eventType',
44-
operator: 'is',
45-
value: 'track'
46-
}
47-
]
48-
}
19+
required: true
4920
},
5021
properties: {
5122
label: 'Properties',
@@ -56,12 +27,38 @@ const action: ActionDefinition<Settings, Payload> = {
5627
'@path': '$.properties'
5728
}
5829
},
59-
...commonFields
30+
...commonFields,
31+
enable_batching: {
32+
label: 'Enable Batching',
33+
type: 'boolean',
34+
required: true,
35+
default: true,
36+
unsafe_hidden: true,
37+
description: 'When enabled, events are sent in batches to Altertable.'
38+
},
39+
batch_size: {
40+
label: 'Batch Size',
41+
type: 'number',
42+
required: false,
43+
default: 1000,
44+
unsafe_hidden: true,
45+
description: 'Maximum number of events per batch request.'
46+
},
47+
batch_bytes: {
48+
label: 'Batch Bytes',
49+
type: 'number',
50+
required: false,
51+
default: 4000000,
52+
unsafe_hidden: true,
53+
description: 'Maximum batch payload size in bytes.'
54+
}
6055
},
6156
perform: (request, { settings, payload }) => {
62-
return send(request, settings, payload)
57+
return sendTrack(request, settings, payload)
58+
},
59+
performBatch: (request, { settings, payload }) => {
60+
return sendTrackBatch(request, settings, payload)
6361
}
6462
}
6563

66-
6764
export default action

0 commit comments

Comments
 (0)