Skip to content

Commit 16dfc1c

Browse files
authored
Klaviyo subscribe profile (#3094)
* Added historical import parameter in klaviyo * Updated unit test cases * Snapshot updated
1 parent 8287c78 commit 16dfc1c

File tree

8 files changed

+109
-19
lines changed

8 files changed

+109
-19
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Object {
117117
"data": Object {
118118
"attributes": Object {
119119
"custom_source": "TsKr#",
120+
"historical_import": true,
120121
"profiles": Object {
121122
"data": Array [
122123
Object {
@@ -161,6 +162,7 @@ Object {
161162
"default": Array [
162163
"list_id",
163164
"custom_source",
165+
"historical_import",
164166
],
165167
"description": "The keys to use for batching the events.",
166168
"label": "Batch Keys",

packages/destination-actions/src/destinations/klaviyo/functions.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ export async function getProfiles(
223223
export function formatSubscribeProfile(
224224
email: string | undefined,
225225
phone_number: string | undefined,
226-
consented_at: string | number | undefined
226+
consented_at: string | number | undefined,
227+
historical_import: boolean | undefined = false
227228
) {
228229
const profileToSubscribe: SubscribeProfile = {
229230
type: 'profile',
@@ -239,7 +240,7 @@ export function formatSubscribeProfile(
239240
consent: 'SUBSCRIBED'
240241
}
241242
}
242-
if (consented_at) {
243+
if (historical_import && consented_at) {
243244
profileToSubscribe.attributes.subscriptions.email.marketing.consented_at = consented_at
244245
}
245246
}
@@ -250,7 +251,7 @@ export function formatSubscribeProfile(
250251
consent: 'SUBSCRIBED'
251252
}
252253
}
253-
if (consented_at) {
254+
if (historical_import && consented_at) {
254255
profileToSubscribe.attributes.subscriptions.sms.marketing.consented_at = consented_at
255256
}
256257
}
@@ -261,7 +262,8 @@ export function formatSubscribeProfile(
261262
export function formatSubscribeRequestBody(
262263
profiles: SubscribeProfile | SubscribeProfile[],
263264
list_id: string | undefined,
264-
custom_source: string | undefined
265+
custom_source: string | undefined,
266+
historical_import: boolean | undefined = false
265267
) {
266268
if (!Array.isArray(profiles)) {
267269
profiles = [profiles]
@@ -272,6 +274,7 @@ export function formatSubscribeRequestBody(
272274
data: {
273275
type: 'profile-subscription-bulk-create-job',
274276
attributes: {
277+
historical_import: historical_import ?? false,
275278
profiles: {
276279
data: profiles
277280
}

packages/destination-actions/src/destinations/klaviyo/subscribeProfile/__tests__/index.test.ts

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ describe('Subscribe Profile', () => {
4343
4444
phone_number: '+17067675219',
4545
list_id: '',
46-
timestamp: '2024-04-01T18:37:06.558Z'
46+
timestamp: '2024-04-01T18:37:06.558Z',
47+
historical_import: true
4748
}
4849
const requestBody = {
4950
data: {
5051
type: 'profile-subscription-bulk-create-job',
5152
attributes: {
5253
custom_source: 'Marketing Event',
54+
historical_import: true,
5355
profiles: {
5456
data: [
5557
{
@@ -88,6 +90,9 @@ describe('Subscribe Profile', () => {
8890
email: payload.email,
8991
phone_number: payload.phone_number
9092
}
93+
},
94+
properties: {
95+
historical_import: payload.historical_import
9196
}
9297
})
9398
const mapping = {
@@ -103,6 +108,9 @@ describe('Subscribe Profile', () => {
103108
},
104109
custom_source: {
105110
'@path': '$.event'
111+
},
112+
historical_import: {
113+
'@path': '$.properties.historical_import'
106114
}
107115
}
108116
await expect(
@@ -114,13 +122,15 @@ describe('Subscribe Profile', () => {
114122
115123
phone_number: '+17067675219',
116124
list_id: '12345',
117-
timestamp: '2024-04-01T18:37:06.558Z'
125+
timestamp: '2024-04-01T18:37:06.558Z',
126+
historical_import: true
118127
}
119128
const requestBody = {
120129
data: {
121130
type: 'profile-subscription-bulk-create-job',
122131
attributes: {
123132
custom_source: '-59',
133+
historical_import: true,
124134
profiles: {
125135
data: [
126136
{
@@ -166,6 +176,9 @@ describe('Subscribe Profile', () => {
166176
email: payload.email,
167177
phone_number: payload.phone_number
168178
}
179+
},
180+
properties: {
181+
historical_import: payload.historical_import
169182
}
170183
})
171184
const mapping = {
@@ -178,6 +191,9 @@ describe('Subscribe Profile', () => {
178191
},
179192
phone_number: {
180193
'@path': '$.context.traits.phone_number'
194+
},
195+
historical_import: {
196+
'@path': '$.properties.historical_import'
181197
}
182198
}
183199
await expect(
@@ -188,12 +204,14 @@ describe('Subscribe Profile', () => {
188204
const payload = {
189205
190206
list_id: '12345',
191-
timestamp: '2024-04-01T18:37:06.558Z'
207+
timestamp: '2024-04-01T18:37:06.558Z',
208+
historical_import: true
192209
}
193210
const requestBody = {
194211
data: {
195212
type: 'profile-subscription-bulk-create-job',
196213
attributes: {
214+
historical_import: true,
197215
custom_source: 'Marketing Event',
198216
profiles: {
199217
data: [
@@ -232,6 +250,9 @@ describe('Subscribe Profile', () => {
232250
traits: {
233251
email: payload.email
234252
}
253+
},
254+
properties: {
255+
historical_import: payload.historical_import
235256
}
236257
})
237258
const mapping = {
@@ -245,6 +266,9 @@ describe('Subscribe Profile', () => {
245266
phone_number: {
246267
'@path': '$.context.traits.phone_number'
247268
},
269+
historical_import: {
270+
'@path': '$.properties.historical_import'
271+
},
248272
custom_source: 'Marketing Event'
249273
}
250274
await expect(
@@ -255,12 +279,14 @@ describe('Subscribe Profile', () => {
255279
const payload = {
256280
phone_number: '+17067675219',
257281
list_id: '12345',
258-
timestamp: '2024-04-01T18:37:06.558Z'
282+
timestamp: '2024-04-01T18:37:06.558Z',
283+
historical_import: true
259284
}
260285
const requestBody = {
261286
data: {
262287
type: 'profile-subscription-bulk-create-job',
263288
attributes: {
289+
historical_import: true,
264290
custom_source: '-59',
265291
profiles: {
266292
data: [
@@ -299,6 +325,9 @@ describe('Subscribe Profile', () => {
299325
traits: {
300326
phone_number: payload.phone_number
301327
}
328+
},
329+
properties: {
330+
historical_import: payload.historical_import
302331
}
303332
})
304333
const mapping = {
@@ -311,6 +340,9 @@ describe('Subscribe Profile', () => {
311340
},
312341
phone_number: {
313342
'@path': '$.context.traits.phone_number'
343+
},
344+
historical_import: {
345+
'@path': '$.properties.historical_import'
314346
}
315347
}
316348
await expect(
@@ -463,6 +495,7 @@ describe('Subscribe Profile', () => {
463495
data: {
464496
type: 'profile-subscription-bulk-create-job',
465497
attributes: {
498+
historical_import: false,
466499
profiles: {
467500
data: [
468501
{
@@ -511,6 +544,9 @@ describe('Subscribe Profile', () => {
511544
},
512545
phone_number: {
513546
'@path': '$.context.traits.phone_number'
547+
},
548+
historical_import: {
549+
'@path': '$.properties.historical_import'
514550
}
515551
}
516552
const events = [
@@ -521,6 +557,9 @@ describe('Subscribe Profile', () => {
521557
traits: {
522558
523559
}
560+
},
561+
properties: {
562+
historical_import: true
524563
}
525564
}),
526565
createTestEvent({
@@ -530,6 +569,9 @@ describe('Subscribe Profile', () => {
530569
traits: {
531570
phone_number: '+17067675129'
532571
}
572+
},
573+
properties: {
574+
historical_import: true
533575
}
534576
}),
535577
createTestEvent({
@@ -540,13 +582,17 @@ describe('Subscribe Profile', () => {
540582
541583
phone_number: '+17067665437'
542584
}
585+
},
586+
properties: {
587+
historical_import: true
543588
}
544589
})
545590
]
546591
const requestBody = {
547592
data: {
548593
type: 'profile-subscription-bulk-create-job',
549594
attributes: {
595+
historical_import: true,
550596
custom_source: '-59',
551597
profiles: {
552598
data: [
@@ -634,6 +680,9 @@ describe('Subscribe Profile', () => {
634680
},
635681
custom_source: {
636682
'@path': '$.event'
683+
},
684+
historical_import: {
685+
'@path': '$.properties.historical_import'
637686
}
638687
}
639688
const events = [
@@ -645,6 +694,9 @@ describe('Subscribe Profile', () => {
645694
646695
list_id: '1'
647696
}
697+
},
698+
properties: {
699+
historical_import: true
648700
}
649701
}),
650702
createTestEvent({
@@ -655,6 +707,9 @@ describe('Subscribe Profile', () => {
655707
phone_number: '+17067675129',
656708
list_id: '2'
657709
}
710+
},
711+
properties: {
712+
historical_import: true
658713
}
659714
}),
660715
createTestEvent({
@@ -665,13 +720,17 @@ describe('Subscribe Profile', () => {
665720
traits: {
666721
667722
}
723+
},
724+
properties: {
725+
historical_import: true
668726
}
669727
})
670728
]
671729
const requestBody1 = {
672730
data: {
673731
type: 'profile-subscription-bulk-create-job',
674732
attributes: {
733+
historical_import: true,
675734
custom_source: 'Test Event',
676735
profiles: {
677736
data: [
@@ -706,6 +765,7 @@ describe('Subscribe Profile', () => {
706765
data: {
707766
type: 'profile-subscription-bulk-create-job',
708767
attributes: {
768+
historical_import: true,
709769
custom_source: 'Test Event',
710770
profiles: {
711771
data: [
@@ -741,6 +801,7 @@ describe('Subscribe Profile', () => {
741801
data: {
742802
type: 'profile-subscription-bulk-create-job',
743803
attributes: {
804+
historical_import: true,
744805
custom_source: 'Marketing Event',
745806
profiles: {
746807
data: [

packages/destination-actions/src/destinations/klaviyo/subscribeProfile/generated-types.ts

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

0 commit comments

Comments
 (0)