@segment/action-destinations 3.132.1-staging.183 → 3.132.1-staging.206
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/destinations/tiktok-audiences/addUser/generated-types.d.ts +12 -0
- package/dist/destinations/tiktok-audiences/addUser/generated-types.js.map +1 -0
- package/dist/destinations/tiktok-audiences/addUser/index.js +47 -0
- package/dist/destinations/tiktok-audiences/addUser/index.js.map +1 -0
- package/dist/destinations/tiktok-audiences/api/api.test.d.ts +1 -0
- package/dist/destinations/tiktok-audiences/api/api.test.js +118 -0
- package/dist/destinations/tiktok-audiences/api/api.test.js.map +1 -0
- package/dist/destinations/tiktok-audiences/api/index.d.ts +7 -5
- package/dist/destinations/tiktok-audiences/api/index.js +61 -6
- package/dist/destinations/tiktok-audiences/api/index.js.map +1 -1
- package/dist/destinations/tiktok-audiences/functions.d.ts +14 -0
- package/dist/destinations/tiktok-audiences/functions.js +116 -0
- package/dist/destinations/tiktok-audiences/functions.js.map +1 -0
- package/dist/destinations/tiktok-audiences/generated-types.d.ts +1 -1
- package/dist/destinations/tiktok-audiences/index.js +9 -6
- package/dist/destinations/tiktok-audiences/index.js.map +1 -1
- package/dist/destinations/tiktok-audiences/properties.d.ts +11 -0
- package/dist/destinations/tiktok-audiences/properties.js +80 -0
- package/dist/destinations/tiktok-audiences/properties.js.map +1 -0
- package/dist/destinations/tiktok-audiences/removeUser/generated-types.d.ts +12 -0
- package/dist/destinations/tiktok-audiences/removeUser/generated-types.js +3 -0
- package/dist/destinations/tiktok-audiences/removeUser/generated-types.js.map +1 -0
- package/dist/destinations/tiktok-audiences/removeUser/index.d.ts +5 -0
- package/dist/destinations/tiktok-audiences/removeUser/index.js +47 -0
- package/dist/destinations/tiktok-audiences/removeUser/index.js.map +1 -0
- package/package.json +2 -2
- package/dist/destinations/tiktok-audiences/updateAudience/generated-types.d.ts +0 -9
- package/dist/destinations/tiktok-audiences/updateAudience/generated-types.js.map +0 -1
- package/dist/destinations/tiktok-audiences/updateAudience/index.js +0 -160
- package/dist/destinations/tiktok-audiences/updateAudience/index.js.map +0 -1
- /package/dist/destinations/tiktok-audiences/{updateAudience → addUser}/generated-types.js +0 -0
- /package/dist/destinations/tiktok-audiences/{updateAudience → addUser}/index.d.ts +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Payload {
|
|
2
|
+
selected_advertiser_id: string;
|
|
3
|
+
custom_audience_name: string;
|
|
4
|
+
id_type: string;
|
|
5
|
+
email?: string;
|
|
6
|
+
advertising_id?: string;
|
|
7
|
+
send_email?: boolean;
|
|
8
|
+
send_advertising_id?: boolean;
|
|
9
|
+
event_name?: string;
|
|
10
|
+
enable_batching?: boolean;
|
|
11
|
+
personas_audience_key?: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/tiktok-audiences/addUser/generated-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const functions_1 = require("../functions");
|
|
4
|
+
const properties_1 = require("../properties");
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const action = {
|
|
7
|
+
title: 'Add Users',
|
|
8
|
+
description: 'Add contacts from an Engage Audience to a TikTok Audience Segment.',
|
|
9
|
+
defaultSubscription: 'event = "Audience Entered"',
|
|
10
|
+
fields: {
|
|
11
|
+
selected_advertiser_id: { ...properties_1.selected_advertiser_id },
|
|
12
|
+
custom_audience_name: { ...properties_1.custom_audience_name },
|
|
13
|
+
id_type: { ...properties_1.id_type },
|
|
14
|
+
email: { ...properties_1.email },
|
|
15
|
+
advertising_id: { ...properties_1.advertising_id },
|
|
16
|
+
send_email: { ...properties_1.send_email },
|
|
17
|
+
send_advertising_id: { ...properties_1.send_advertising_id },
|
|
18
|
+
event_name: { ...properties_1.event_name },
|
|
19
|
+
enable_batching: { ...properties_1.enable_batching },
|
|
20
|
+
personas_audience_key: { ...properties_1.personas_audience_key }
|
|
21
|
+
},
|
|
22
|
+
dynamicFields: {
|
|
23
|
+
selected_advertiser_id: async (request, { settings }) => {
|
|
24
|
+
try {
|
|
25
|
+
const tiktok = new api_1.TikTokAudiences(request);
|
|
26
|
+
return tiktok.fetchAdvertisers(settings.advertiser_ids);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
return {
|
|
30
|
+
choices: [],
|
|
31
|
+
error: {
|
|
32
|
+
message: JSON.stringify(err),
|
|
33
|
+
code: '500'
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
perform: async (request, { settings, payload }) => {
|
|
40
|
+
return functions_1.processPayload(request, settings, [payload], 'add');
|
|
41
|
+
},
|
|
42
|
+
performBatch: async (request, { settings, payload }) => {
|
|
43
|
+
return functions_1.processPayload(request, settings, payload, 'add');
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.default = action;
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/tiktok-audiences/addUser/index.ts"],"names":[],"mappings":";;AAGA,4CAA6C;AAC7C,8CAWsB;AACtB,gCAAwC;AAExC,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,WAAW;IAClB,WAAW,EAAE,oEAAoE;IACjF,mBAAmB,EAAE,4BAA4B;IACjD,MAAM,EAAE;QACN,sBAAsB,EAAE,EAAE,GAAG,mCAAsB,EAAE;QACrD,oBAAoB,EAAE,EAAE,GAAG,iCAAoB,EAAE;QACjD,OAAO,EAAE,EAAE,GAAG,oBAAO,EAAE;QACvB,KAAK,EAAE,EAAE,GAAG,kBAAK,EAAE;QACnB,cAAc,EAAE,EAAE,GAAG,2BAAc,EAAE;QACrC,UAA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mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const nock_1 = __importDefault(require("nock"));
|
|
7
|
+
const create_request_client_1 = __importDefault(require("../../../../../core/src/create-request-client"));
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
const constants_1 = require("../constants");
|
|
10
|
+
const settings = {
|
|
11
|
+
advertiser_ids: ['1234567890', '0987654321', '2345675643']
|
|
12
|
+
};
|
|
13
|
+
const requestClient = create_request_client_1.default();
|
|
14
|
+
describe('TikTok', () => {
|
|
15
|
+
describe('fetchAdvertisers', () => {
|
|
16
|
+
const tiktok = new index_1.TikTokAudiences(requestClient);
|
|
17
|
+
it('should fetch a list of advertisers, with their names', async () => {
|
|
18
|
+
nock_1.default(`${constants_1.BASE_URL}${constants_1.TIKTOK_API_VERSION}/advertiser/info`)
|
|
19
|
+
.get(`/`)
|
|
20
|
+
.query({ advertiser_ids: JSON.stringify(settings.advertiser_ids) })
|
|
21
|
+
.reply(200, {
|
|
22
|
+
code: 0,
|
|
23
|
+
message: 'success',
|
|
24
|
+
data: {
|
|
25
|
+
list: [
|
|
26
|
+
{
|
|
27
|
+
balance: 0.0,
|
|
28
|
+
email: 'd*******************@***********',
|
|
29
|
+
promotion_area: '0',
|
|
30
|
+
display_timezone: 'America/New_York',
|
|
31
|
+
create_time: 1672341876,
|
|
32
|
+
telephone_number: '+10000****00',
|
|
33
|
+
license_no: '',
|
|
34
|
+
description: null,
|
|
35
|
+
license_province: null,
|
|
36
|
+
address: '',
|
|
37
|
+
industry: '292801',
|
|
38
|
+
currency: 'USD',
|
|
39
|
+
rejection_reason: '-',
|
|
40
|
+
country: 'US',
|
|
41
|
+
license_url: null,
|
|
42
|
+
timezone: 'Etc/GMT+5',
|
|
43
|
+
license_city: null,
|
|
44
|
+
brand: null,
|
|
45
|
+
promotion_center_province: null,
|
|
46
|
+
advertiser_account_type: 'AUCTION',
|
|
47
|
+
status: 'STATUS_ENABLE',
|
|
48
|
+
cellphone_number: '+10000****00',
|
|
49
|
+
name: 'TestAccount1',
|
|
50
|
+
role: 'ROLE_ADVERTISER',
|
|
51
|
+
contacter: 'Se***nt',
|
|
52
|
+
promotion_center_city: null,
|
|
53
|
+
advertiser_id: '1234567890',
|
|
54
|
+
language: '',
|
|
55
|
+
company: 'Segment'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
advertiser_id: '0987654321',
|
|
59
|
+
name: 'TestAccount2'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
advertiser_id: '2345675643',
|
|
63
|
+
name: 'TestAccount3'
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const fetchAdvertisersRes = await tiktok.fetchAdvertisers(settings.advertiser_ids);
|
|
69
|
+
expect(fetchAdvertisersRes).toEqual({
|
|
70
|
+
choices: [
|
|
71
|
+
{
|
|
72
|
+
label: 'TestAccount1',
|
|
73
|
+
value: '1234567890'
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
label: 'TestAccount2',
|
|
77
|
+
value: '0987654321'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
label: 'TestAccount3',
|
|
81
|
+
value: '2345675643'
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
it('should fallback to stored advertiser_ids if tiktok returns an error', async () => {
|
|
87
|
+
nock_1.default(`${constants_1.BASE_URL}${constants_1.TIKTOK_API_VERSION}/advertiser/info`)
|
|
88
|
+
.get(`/`)
|
|
89
|
+
.query({ advertiser_ids: JSON.stringify(settings.advertiser_ids) })
|
|
90
|
+
.reply(200, {
|
|
91
|
+
code: 500,
|
|
92
|
+
message: 'Internal Server Error'
|
|
93
|
+
});
|
|
94
|
+
const fetchAdvertisersRes = await tiktok.fetchAdvertisers(settings.advertiser_ids);
|
|
95
|
+
expect(fetchAdvertisersRes).toEqual({
|
|
96
|
+
choices: [
|
|
97
|
+
{
|
|
98
|
+
label: '1234567890',
|
|
99
|
+
value: '1234567890'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
label: '0987654321',
|
|
103
|
+
value: '0987654321'
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
label: '2345675643',
|
|
107
|
+
value: '2345675643'
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
error: {
|
|
111
|
+
message: 'Internal Server Error',
|
|
112
|
+
code: '500'
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=api.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.test.js","sourceRoot":"","sources":["../../../../src/destinations/tiktok-audiences/api/api.test.ts"],"names":[],"mappings":";;;;;AAAA,gDAAuB;AACvB,0GAA+E;AAC/E,mCAAyC;AACzC,4CAA2D;AAC3D,MAAM,QAAQ,GAAG;IACf,cAAc,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC;CAC3D,CAAA;AAED,MAAM,aAAa,GAAG,+BAAmB,EAAE,CAAA;AAE3C,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAChC,MAAM,MAAM,GAAoB,IAAI,uBAAe,CAAC,aAAa,CAAC,CAAA;QAElE,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;YACpE,cAAI,CAAC,GAAG,oBAAQ,GAAG,8BAAkB,kBAAkB,CAAC;iBACrD,GAAG,CAAC,GAAG,CAAC;iBACR,KAAK,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;iBAClE,KAAK,CAAC,GAAG,EAAE;gBACV,IAAI,EAAE,CAAC;gBACP,OAAO,EAAE,SAAS;gBAClB,IAAI,EAAE;oBACJ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;oBACD;wBACE,KAAK,EAAE,cAAc;wBACrB,KAAK,EAAE,YAAY;qBACpB;iBACF;aACF,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,qEAAqE,EAAE,KAAK,IAAI,EAAE;YACnF,cAAI,CAAC,GAAG,oBAAQ,GAAG,8BAAkB,kBAAkB,CAAC;iBACrD,GAAG,CAAC,GAAG,CAAC;iBACR,KAAK,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;iBAClE,KAAK,CAAC,GAAG,EAAE;gBACV,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,uBAAuB;aACjC,CAAC,CAAA;YAEJ,MAAM,mBAAmB,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAA;YAElF,MAAM,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC;gBAClC,OAAO,EAAE;oBACP;wBACE,KAAK,EAAE,YAAY;wBACnB,KAAK,EAAE,YAAY;qBACpB;oBACD;wBACE,KAAK,EAAE,YAAY;wBACnB,KAAK,EAAE,YAAY;qBACpB;oBACD;wBACE,KAAK,EAAE,YAAY;wBACnB,KAAK,EAAE,YAAY;qBACpB;iBACF;gBACD,KAAK,EAAE;oBACL,OAAO,EAAE,uBAAuB;oBAChC,IAAI,EAAE,KAAK;iBACZ;aACF,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { RequestClient, ModifiedResponse } from '@segment/actions-core';
|
|
2
|
-
import type {
|
|
3
|
-
import type { Payload } from '../updateAudience/generated-types';
|
|
2
|
+
import type { Payload } from '../addUser/generated-types';
|
|
4
3
|
import type { GetAudienceAPIResponse, CreateAudienceAPIResponse } from '../types';
|
|
4
|
+
import { DynamicFieldResponse } from '@segment/actions-core';
|
|
5
5
|
export declare class TikTokAudiences {
|
|
6
6
|
request: RequestClient;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
selectedAdvertiserID?: string;
|
|
8
|
+
constructor(request: RequestClient, selectedAdvertiserID?: string);
|
|
9
|
+
getAudiences(page_number: number, page_size: number): Promise<ModifiedResponse<GetAudienceAPIResponse>>;
|
|
10
|
+
createAudience(payload: Payload): Promise<ModifiedResponse<CreateAudienceAPIResponse>>;
|
|
10
11
|
batchUpdate(elements: {}): Promise<ModifiedResponse>;
|
|
12
|
+
fetchAdvertisers: (advertiser_ids: string[]) => Promise<DynamicFieldResponse>;
|
|
11
13
|
}
|
|
@@ -3,25 +3,79 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TikTokAudiences = void 0;
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
5
|
class TikTokAudiences {
|
|
6
|
-
constructor(request) {
|
|
6
|
+
constructor(request, selectedAdvertiserID) {
|
|
7
|
+
this.fetchAdvertisers = async (advertiser_ids) => {
|
|
8
|
+
if (!advertiser_ids.length) {
|
|
9
|
+
throw {
|
|
10
|
+
error: {
|
|
11
|
+
message: 'Sign in via OAuth on the settings page to load advertisers.',
|
|
12
|
+
code: 'NOT_LOGGED_IN'
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const result = await this.request(`${constants_1.BASE_URL}${constants_1.TIKTOK_API_VERSION}/advertiser/info/`, {
|
|
18
|
+
method: 'GET',
|
|
19
|
+
searchParams: {
|
|
20
|
+
advertiser_ids: JSON.stringify(advertiser_ids)
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
console.log(result);
|
|
24
|
+
if (result.data.code !== 0) {
|
|
25
|
+
throw {
|
|
26
|
+
response: {
|
|
27
|
+
data: {
|
|
28
|
+
message: result.data.message,
|
|
29
|
+
code: result.data.code
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const choices = result.data.data.list.map((item) => {
|
|
35
|
+
return {
|
|
36
|
+
label: item.name,
|
|
37
|
+
value: item.advertiser_id
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
choices: choices
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
const choices = advertiser_ids.map((id) => {
|
|
46
|
+
return {
|
|
47
|
+
label: id,
|
|
48
|
+
value: id
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
choices: choices,
|
|
53
|
+
error: {
|
|
54
|
+
message: err.response.data.message ?? 'An error occurred while fetching advertisers.',
|
|
55
|
+
code: err.response.data.code.toString() ?? 'FETCH_ADVERTISERS_ERROR'
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
7
60
|
this.request = request;
|
|
61
|
+
this.selectedAdvertiserID = selectedAdvertiserID;
|
|
8
62
|
}
|
|
9
|
-
async getAudiences(
|
|
63
|
+
async getAudiences(page_number, page_size) {
|
|
10
64
|
return this.request(`${constants_1.BASE_URL}${constants_1.TIKTOK_API_VERSION}/dmp/custom_audience/list/`, {
|
|
11
65
|
method: 'GET',
|
|
12
66
|
searchParams: {
|
|
13
|
-
advertiser_id:
|
|
67
|
+
advertiser_id: this.selectedAdvertiserID ?? '',
|
|
14
68
|
page: page_number,
|
|
15
69
|
page_size: page_size
|
|
16
70
|
}
|
|
17
71
|
});
|
|
18
72
|
}
|
|
19
|
-
async createAudience(
|
|
73
|
+
async createAudience(payload) {
|
|
20
74
|
return this.request(`${constants_1.BASE_URL}${constants_1.TIKTOK_API_VERSION}/segment/audience/`, {
|
|
21
75
|
method: 'POST',
|
|
22
76
|
json: {
|
|
23
77
|
custom_audience_name: payload.custom_audience_name,
|
|
24
|
-
advertiser_id:
|
|
78
|
+
advertiser_id: this.selectedAdvertiserID,
|
|
25
79
|
id_type: payload.id_type,
|
|
26
80
|
action: 'create'
|
|
27
81
|
}
|
|
@@ -30,7 +84,8 @@ class TikTokAudiences {
|
|
|
30
84
|
async batchUpdate(elements) {
|
|
31
85
|
return this.request(`${constants_1.BASE_URL}${constants_1.TIKTOK_API_VERSION}/segment/mapping/`, {
|
|
32
86
|
method: 'POST',
|
|
33
|
-
json: elements
|
|
87
|
+
json: elements,
|
|
88
|
+
throwHttpErrors: false
|
|
34
89
|
});
|
|
35
90
|
}
|
|
36
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/tiktok-audiences/api/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/tiktok-audiences/api/index.ts"],"names":[],"mappings":";;;AAEA,4CAA2D;AAyB3D,MAAa,eAAe;IAI1B,YAAY,OAAsB,EAAE,oBAA6B;QAoCjE,qBAAgB,GAAG,KAAK,EAAE,cAAwB,EAAiC,EAAE;YACnF,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE;gBAC1B,MAAM;oBACJ,KAAK,EAAE;wBACL,OAAO,EAAE,6DAA6D;wBACtE,IAAI,EAAE,eAAe;qBACtB;iBACF,CAAA;aACF;YACD,IAAI;gBACF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAyB,GAAG,oBAAQ,GAAG,8BAAkB,mBAAmB,EAAE;oBAC7G,MAAM,EAAE,KAAK;oBACb,YAAY,EAAE;wBACZ,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;qBAC/C;iBACF,CAAC,CAAA;gBACF,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBAEnB,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE;oBAC1B,MAAM;wBACJ,QAAQ,EAAE;4BACR,IAAI,EAAE;gCACJ,OAAO,EAAE,MAAM,CAAC,IA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rB;SACF,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAgB;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,oBAAQ,GAAG,8BAAkB,oBAAoB,EAAE;YACxE,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;gBAClD,aAAa,EAAE,IAAI,CAAC,oBAAoB;gBACxC,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,MAAM,EAAE,QAAQ;aACjB;SACF,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,QAAY;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,oBAAQ,GAAG,8BAAkB,mBAAmB,EAAE;YACvE,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,QAAQ;YACd,eAAe,EAAE,KAAK;SACvB,CAAC,CAAA;IACJ,CAAC;CA2DF;AAjGD,0CAiGC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RequestClient } from '@segment/actions-core';
|
|
2
|
+
import { Audiences } from './types';
|
|
3
|
+
import { TikTokAudiences } from './api';
|
|
4
|
+
import { Payload as AddUserPayload } from './addUser/generated-types';
|
|
5
|
+
import { Payload as RemoveUserPayload } from './removeUser/generated-types';
|
|
6
|
+
import { Settings } from './generated-types';
|
|
7
|
+
declare type GenericPayload = AddUserPayload | RemoveUserPayload;
|
|
8
|
+
export declare function processPayload(request: RequestClient, settings: Settings, payloads: GenericPayload[], action: string): Promise<import("@segment/actions-core").ModifiedResponse<unknown> | undefined>;
|
|
9
|
+
export declare function validate(payloads: GenericPayload[]): void;
|
|
10
|
+
export declare function getAllAudiences(TikTokApiClient: TikTokAudiences): Promise<Audiences[]>;
|
|
11
|
+
export declare function getAudienceID(TikTokApiClient: TikTokAudiences, payload: GenericPayload, audiences: Audiences[]): Promise<string>;
|
|
12
|
+
export declare function getIDSchema(payload: GenericPayload): string[];
|
|
13
|
+
export declare function extractUsers(payloads: GenericPayload[], audienceID: string): {}[][];
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractUsers = exports.getIDSchema = exports.getAudienceID = exports.getAllAudiences = exports.validate = exports.processPayload = void 0;
|
|
4
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const api_1 = require("./api");
|
|
7
|
+
async function processPayload(request, settings, payloads, action) {
|
|
8
|
+
validate(payloads);
|
|
9
|
+
const selected_advertiser_id = payloads[0].selected_advertiser_id ?? undefined;
|
|
10
|
+
const TikTokApiClient = new api_1.TikTokAudiences(request, selected_advertiser_id);
|
|
11
|
+
const audiences = await getAllAudiences(TikTokApiClient);
|
|
12
|
+
const audience_id = await getAudienceID(TikTokApiClient, payloads[0], audiences);
|
|
13
|
+
const id_schema = getIDSchema(payloads[0]);
|
|
14
|
+
const users = extractUsers(payloads, audience_id);
|
|
15
|
+
let res;
|
|
16
|
+
if (users.length > 0) {
|
|
17
|
+
const elements = {
|
|
18
|
+
advertiser_ids: settings.advertiser_ids,
|
|
19
|
+
action: action,
|
|
20
|
+
id_schema: id_schema,
|
|
21
|
+
batch_data: users
|
|
22
|
+
};
|
|
23
|
+
res = await TikTokApiClient.batchUpdate(elements);
|
|
24
|
+
if (res.status !== 200) {
|
|
25
|
+
throw new actions_core_1.RetryableError('Error while attempting to update TikTok Audience. This batch will be retried.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return res;
|
|
29
|
+
}
|
|
30
|
+
exports.processPayload = processPayload;
|
|
31
|
+
function validate(payloads) {
|
|
32
|
+
if (payloads[0].custom_audience_name !== payloads[0].personas_audience_key) {
|
|
33
|
+
throw new actions_core_1.IntegrationError('The value of `custom_audience_name` and `personas_audience_key` must match.', 'INVALID_SETTINGS', 400);
|
|
34
|
+
}
|
|
35
|
+
if (payloads[0].send_email === false && payloads[0].send_advertising_id === false) {
|
|
36
|
+
throw new actions_core_1.IntegrationError('At least one of `Send Email`, or `Send Advertising ID` must be set to `true`.', 'INVALID_SETTINGS', 400);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.validate = validate;
|
|
40
|
+
async function getAllAudiences(TikTokApiClient) {
|
|
41
|
+
let response = await TikTokApiClient.getAudiences(1, 100);
|
|
42
|
+
let audiences = response.data.data.list;
|
|
43
|
+
const total_number_audiences = response.data.data.page_info.total_number;
|
|
44
|
+
let recieved_audiences = 100;
|
|
45
|
+
let page_number = 2;
|
|
46
|
+
while (recieved_audiences < total_number_audiences) {
|
|
47
|
+
response = await TikTokApiClient.getAudiences(page_number, 100);
|
|
48
|
+
audiences = audiences.concat(response.data.data.list);
|
|
49
|
+
page_number += 1;
|
|
50
|
+
recieved_audiences += 100;
|
|
51
|
+
}
|
|
52
|
+
return audiences;
|
|
53
|
+
}
|
|
54
|
+
exports.getAllAudiences = getAllAudiences;
|
|
55
|
+
async function getAudienceID(TikTokApiClient, payload, audiences) {
|
|
56
|
+
let audienceID;
|
|
57
|
+
const audienceExists = audiences.filter(function (audience) {
|
|
58
|
+
if (audience.name === payload.custom_audience_name) {
|
|
59
|
+
return audience.audience_id;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (audienceExists.length > 1) {
|
|
63
|
+
throw new actions_core_1.IntegrationError('Multiple audiences found with the same name', 'INVALID_SETTINGS', 400);
|
|
64
|
+
}
|
|
65
|
+
if (audienceExists.length == 1) {
|
|
66
|
+
audienceID = audienceExists[0].audience_id;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const response = await TikTokApiClient.createAudience(payload);
|
|
70
|
+
audienceID = response.data.data.audience_id;
|
|
71
|
+
}
|
|
72
|
+
return audienceID;
|
|
73
|
+
}
|
|
74
|
+
exports.getAudienceID = getAudienceID;
|
|
75
|
+
function getIDSchema(payload) {
|
|
76
|
+
const id_schema = [];
|
|
77
|
+
if (payload.send_email === true) {
|
|
78
|
+
id_schema.push('EMAIL_SHA256');
|
|
79
|
+
}
|
|
80
|
+
if (payload.send_advertising_id === true) {
|
|
81
|
+
id_schema.push('IDFA_SHA256');
|
|
82
|
+
}
|
|
83
|
+
return id_schema;
|
|
84
|
+
}
|
|
85
|
+
exports.getIDSchema = getIDSchema;
|
|
86
|
+
function extractUsers(payloads, audienceID) {
|
|
87
|
+
const batch_data = [];
|
|
88
|
+
payloads.forEach((payload) => {
|
|
89
|
+
if (!payload.email && !payload.advertising_id) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const user_ids = [];
|
|
93
|
+
if (payload.send_email === true) {
|
|
94
|
+
let email_id = {};
|
|
95
|
+
if (payload.email) {
|
|
96
|
+
payload.email = payload.email.replace(/\+.*@/, '@').replace(/\./g, '').toLowerCase();
|
|
97
|
+
email_id = { id: crypto_1.createHash('sha256').update(payload.email).digest('hex'), audience_ids: [audienceID] };
|
|
98
|
+
}
|
|
99
|
+
user_ids.push(email_id);
|
|
100
|
+
}
|
|
101
|
+
if (payload.send_advertising_id === true) {
|
|
102
|
+
let advertising_id = {};
|
|
103
|
+
if (payload.advertising_id) {
|
|
104
|
+
advertising_id = {
|
|
105
|
+
id: crypto_1.createHash('sha256').update(payload.advertising_id).digest('hex'),
|
|
106
|
+
audience_ids: [audienceID]
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
user_ids.push(advertising_id);
|
|
110
|
+
}
|
|
111
|
+
batch_data.push(user_ids);
|
|
112
|
+
});
|
|
113
|
+
return batch_data;
|
|
114
|
+
}
|
|
115
|
+
exports.extractUsers = extractUsers;
|
|
116
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/destinations/tiktok-audiences/functions.ts"],"names":[],"mappings":";;;AAAA,wDAAuF;AAEvF,mCAAmC;AACnC,+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CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAA;gBACpF,QAAQ,GAAG,EAAE,EAAE,EAAE,mBAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC,UAAU,CAAC,EAAE,CAAA;aACxG;YACD,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SACxB;QAED,IAAI,OAAO,CAAC,mBAAmB,KAAK,IAAI,EAAE;YACxC,IAAI,cAAc,GAAG,EAAE,CAAA;YACvB,IAAI,OAAO,CAAC,cAAc,EAAE;gBAC1B,cAAc,GAAG;oBACf,EAAE,EAAE,mBAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;oBACrE,YAAY,EAAE,CAAC,UAAU,CAAC;iBAC3B,CAAA;aACF;YACD,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;SAC9B;QAED,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC3B,CAAC,CAAC,CAAA;IACF,OAAO,UAAU,CAAA;AACnB,CAAC;AAjCD,oCAiCC"}
|
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const addUser_1 = __importDefault(require("./addUser"));
|
|
7
|
+
const removeUser_1 = __importDefault(require("./removeUser"));
|
|
7
8
|
const destination = {
|
|
8
9
|
name: 'TikTok Audiences',
|
|
9
10
|
slug: 'actions-tiktok-audiences',
|
|
@@ -11,11 +12,12 @@ const destination = {
|
|
|
11
12
|
authentication: {
|
|
12
13
|
scheme: 'oauth2',
|
|
13
14
|
fields: {
|
|
14
|
-
|
|
15
|
-
label: 'TikTok Advertiser
|
|
16
|
-
description: 'The Advertiser
|
|
15
|
+
advertiser_ids: {
|
|
16
|
+
label: 'TikTok Advertiser IDs',
|
|
17
|
+
description: 'The Advertiser IDs where audiences should be synced.',
|
|
17
18
|
type: 'string',
|
|
18
|
-
required: true
|
|
19
|
+
required: true,
|
|
20
|
+
multiple: true
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
},
|
|
@@ -28,7 +30,8 @@ const destination = {
|
|
|
28
30
|
};
|
|
29
31
|
},
|
|
30
32
|
actions: {
|
|
31
|
-
|
|
33
|
+
addUser: addUser_1.default,
|
|
34
|
+
removeUser: removeUser_1.default
|
|
32
35
|
}
|
|
33
36
|
};
|
|
34
37
|
exports.default = destination;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/tiktok-audiences/index.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/tiktok-audiences/index.ts"],"names":[],"mappings":";;;;;AAGA,wDAA+B;AAC/B,8DAAqC;AAErC,MAAM,WAAW,GAAoC;IACnD,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,0BAA0B;IAChC,IAAI,EAAE,OAAO;IAEb,cAAc,EAAE;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE;YACN,cAAc,EAAE;gBACd,KAAK,EAAE,uBAAuB;gBAC9B,WAAW,EAAE,sDAAsD;gBACnE,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;gBACd,QAAQ,EAAE,IAAI;aACf;SACF;KASF;IACD,aAAa,CAAC,EAAE,IAAI,EAAE;QACpB,OAAO;YACL,OAAO,EAAE;gBACP,cAAc,EAAE,GAAG,IAAI,EAAE,WAAW,EAAE;gBACtC,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAA;IACH,CAAC;IAED,OAAO,EAAE;QACP,OAAO,EAAP,iBAAO;QACP,UAAU,EAAV,oBAAU;KACX;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { InputField } from '@segment/actions-core/src/destination-kit/types';
|
|
2
|
+
export declare const selected_advertiser_id: InputField;
|
|
3
|
+
export declare const custom_audience_name: InputField;
|
|
4
|
+
export declare const id_type: InputField;
|
|
5
|
+
export declare const email: InputField;
|
|
6
|
+
export declare const send_email: InputField;
|
|
7
|
+
export declare const advertising_id: InputField;
|
|
8
|
+
export declare const send_advertising_id: InputField;
|
|
9
|
+
export declare const event_name: InputField;
|
|
10
|
+
export declare const enable_batching: InputField;
|
|
11
|
+
export declare const personas_audience_key: InputField;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.personas_audience_key = exports.enable_batching = exports.event_name = exports.send_advertising_id = exports.advertising_id = exports.send_email = exports.email = exports.id_type = exports.custom_audience_name = exports.selected_advertiser_id = void 0;
|
|
4
|
+
exports.selected_advertiser_id = {
|
|
5
|
+
label: 'Advertiser ID',
|
|
6
|
+
description: 'The advertiser ID to use when syncing audiences.',
|
|
7
|
+
type: 'string',
|
|
8
|
+
dynamic: true,
|
|
9
|
+
required: true
|
|
10
|
+
};
|
|
11
|
+
exports.custom_audience_name = {
|
|
12
|
+
label: 'Custom Audience Name',
|
|
13
|
+
description: 'Custom audience name of audience to be created. Please note that names over 70 characters will be truncated to 67 characters with "..." appended. This field is set only when Segment creates a new audience. Updating this field after Segment has created an audience will not update the audience name in TikTok.',
|
|
14
|
+
type: 'string',
|
|
15
|
+
default: {
|
|
16
|
+
'@path': '$.properties.audience_key'
|
|
17
|
+
},
|
|
18
|
+
required: true
|
|
19
|
+
};
|
|
20
|
+
exports.id_type = {
|
|
21
|
+
label: 'ID Type',
|
|
22
|
+
description: 'Encryption type to be used for populating the audience. This field is set only when Segment creates a new audience.',
|
|
23
|
+
type: 'string',
|
|
24
|
+
choices: [
|
|
25
|
+
{ label: 'Email', value: 'EMAIL_SHA256' },
|
|
26
|
+
{ label: 'Phone', value: 'PHONE_SHA256' },
|
|
27
|
+
{ label: 'Google Advertising ID', value: 'GAID_SHA256' },
|
|
28
|
+
{ label: 'Android Advertising ID', value: 'AAID_SHA256' },
|
|
29
|
+
{ label: 'iOS Advertising ID', value: 'IDFA_SHA256' }
|
|
30
|
+
],
|
|
31
|
+
required: true
|
|
32
|
+
};
|
|
33
|
+
exports.email = {
|
|
34
|
+
label: 'User Email',
|
|
35
|
+
description: "The user's email address to send to TikTok.",
|
|
36
|
+
type: 'hidden',
|
|
37
|
+
default: {
|
|
38
|
+
'@path': '$.context.traits.email'
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.send_email = {
|
|
42
|
+
label: 'Send Email',
|
|
43
|
+
description: 'Send email to TikTok. Segment will hash this value before sending',
|
|
44
|
+
type: 'boolean',
|
|
45
|
+
default: true
|
|
46
|
+
};
|
|
47
|
+
exports.advertising_id = {
|
|
48
|
+
label: 'User Advertising ID',
|
|
49
|
+
description: "The user's mobile dvertising ID to send to TikTok. This could be a GAID, IDFA, or AAID",
|
|
50
|
+
type: 'hidden',
|
|
51
|
+
default: {
|
|
52
|
+
'@path': '$.context.device.advertisingId'
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports.send_advertising_id = {
|
|
56
|
+
label: 'Send Mobile Advertising ID',
|
|
57
|
+
description: 'Send mobile advertising ID (IDFA, AAID or GAID) to TikTok. Segment will hash this value before sending.',
|
|
58
|
+
type: 'boolean',
|
|
59
|
+
default: true
|
|
60
|
+
};
|
|
61
|
+
exports.event_name = {
|
|
62
|
+
label: 'Event Name',
|
|
63
|
+
description: 'The name of the current Segment event.',
|
|
64
|
+
type: 'hidden',
|
|
65
|
+
default: {
|
|
66
|
+
'@path': '$.event'
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.enable_batching = {
|
|
70
|
+
label: 'Enable Batching',
|
|
71
|
+
description: 'Enable batching of requests to the TikTok Audiences.',
|
|
72
|
+
type: 'boolean',
|
|
73
|
+
default: true
|
|
74
|
+
};
|
|
75
|
+
exports.personas_audience_key = {
|
|
76
|
+
label: 'Segment Engage Audience Key',
|
|
77
|
+
description: 'The `audience_key` of the Engage audience you want to sync to TikTok. This value must be a hard-coded string variable, e.g. `personas_test_audience`, in order for batching to work properly.',
|
|
78
|
+
type: 'string'
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=properties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../../../src/destinations/tiktok-audiences/properties.ts"],"names":[],"mappings":";;;AAEa,QAAA,sBAAsB,GAAe;IAChD,KAAK,EAAE,eAAe;IACtB,WAAW,EAAE,kDAAkD;IAC/D,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,IAAI;CACf,CAAA;AAEY,QAAA,oBAAoB,GAAe;IAC9C,KAAK,EAAE,sBAAsB;IAC7B,WAAW,EACT,sTAAsT;IACxT,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE;QACP,OAAO,EAAE,2BAA2B;KACrC;IACD,QAAQ,EAAE,IAAI;CACf,CAAA;AAEY,QAAA,OAAO,GAAe;IACjC,KAAK,EAAE,SAAS;IAChB,WAAW,EACT,qHAAqH;IACvH,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE;QACP,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE;QACzC,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE;QACzC,EAAE,KAAK,EAAE,uBAAuB,EAAE,KAAK,EAAE,aAAa,EAAE;QACxD,EAAE,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,aAAa,E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;
|
|
5
|
+
email?: string;
|
|
6
|
+
advertising_id?: string;
|
|
7
|
+
send_email?: boolean;
|
|
8
|
+
send_advertising_id?: boolean;
|
|
9
|
+
event_name?: string;
|
|
10
|
+
enable_batching?: boolean;
|
|
11
|
+
personas_audience_key?: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/tiktok-audiences/removeUser/generated-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const functions_1 = require("../functions");
|
|
4
|
+
const properties_1 = require("../properties");
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const action = {
|
|
7
|
+
title: 'Remove Users',
|
|
8
|
+
description: 'Remove contacts from an Engage Audience to a TikTok Audience Segment.',
|
|
9
|
+
defaultSubscription: 'event = "Audience Exited"',
|
|
10
|
+
fields: {
|
|
11
|
+
selected_advertiser_id: { ...properties_1.selected_advertiser_id },
|
|
12
|
+
custom_audience_name: { ...properties_1.custom_audience_name },
|
|
13
|
+
id_type: { ...properties_1.id_type },
|
|
14
|
+
email: { ...properties_1.email },
|
|
15
|
+
advertising_id: { ...properties_1.advertising_id },
|
|
16
|
+
send_email: { ...properties_1.send_email },
|
|
17
|
+
send_advertising_id: { ...properties_1.send_advertising_id },
|
|
18
|
+
event_name: { ...properties_1.event_name },
|
|
19
|
+
enable_batching: { ...properties_1.enable_batching },
|
|
20
|
+
personas_audience_key: { ...properties_1.personas_audience_key }
|
|
21
|
+
},
|
|
22
|
+
dynamicFields: {
|
|
23
|
+
selected_advertiser_id: async (request, { settings }) => {
|
|
24
|
+
try {
|
|
25
|
+
const tiktok = new api_1.TikTokAudiences(request);
|
|
26
|
+
return tiktok.fetchAdvertisers(settings.advertiser_ids);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
return {
|
|
30
|
+
choices: [],
|
|
31
|
+
error: {
|
|
32
|
+
message: JSON.stringify(err),
|
|
33
|
+
code: '500'
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
perform: async (request, { settings, payload }) => {
|
|
40
|
+
return functions_1.processPayload(request, settings, [payload], 'delete');
|
|
41
|
+
},
|
|
42
|
+
performBatch: async (request, { settings, payload }) => {
|
|
43
|
+
return functions_1.processPayload(request, settings, payload, 'delete');
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.default = action;
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/tiktok-audiences/removeUser/index.ts"],"names":[],"mappings":";;AAGA,4CAA6C;AAC7C,8CAWsB;AACtB,gCAAwC;AAExC,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,cAAc;IACrB,WAAW,EAAE,uEAAuE;IACpF,mBAAmB,EAAE,2BAA2B;IAChD,MAAM,EAAE;QACN,sBAAsB,EAAE,EAAE,GAAG,mCAAsB,EAAE;QACrD,oBAAoB,EAAE,EAAE,GAAG,iCAAoB,EAAE;QACjD,OAAO,EAAE,EAAE,GAAG,oBAAO,EAAE;QACvB,KAAK,EAAE,EAAE,GAAG,kBAAK,EAAE;QACnB,cAAc,EAAE,EAAE,GAAG,2BAAc,EAAE;QACrC,UAAU,EAAE,EAAE,GAAG,uBAAU,EAAE;QAC7B,mBAAmB,EAAE,EAAE,GAAG,gCAAmB,EAAE;QAC/C,UAAU,EAAE,EAAE,GAAG,uBAAU,EAAE;QAC7B,eAAe,EAAE,EAAE,GAAG,4BAAe,EAAE;QACvC,qBAAqB,EAAE,EAAE,GAAG,kCAAqB,EAAE;KACpD;IACD,aAAa,EAAE;QACb,sBAAsB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;YACtD,IAAI;gBACF,MAAM,MAAM,GAAG,IAAI,qBAAe,CAAC,OAAO,CAAC,CAAA;gBAE3C,OAAO,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAA;aACxD;YAAC,OAAO,GAAG,EAAE;gBACZ,OAAO;oBACL,OAAO,EAAE,EAAE;oBACX,KAAK,EAAE;wBACL,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;wBAC5B,IAAI,EAAE,KAAK;qBACZ;iBACF,CAAA;aACF;QACH,CAAC;KACF;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;QAChD,OAAO,0BAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAA;IAC/D,CAAC;IACD,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;QACrD,OAAO,0BAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC7D,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segment/action-destinations",
|
|
3
3
|
"description": "Destination Actions engine and definitions.",
|
|
4
|
-
"version": "3.132.1-staging.
|
|
4
|
+
"version": "3.132.1-staging.206+c3c489ec4",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/segmentio/action-destinations",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"lcov"
|
|
69
69
|
]
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "c3c489ec47e6fc45af0d304e2ff7ce3e1e00159c"
|
|
72
72
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/tiktok-audiences/updateAudience/generated-types.ts"],"names":[],"mappings":""}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const actions_core_1 = require("@segment/actions-core");
|
|
4
|
-
const api_1 = require("../api");
|
|
5
|
-
const crypto_1 = require("crypto");
|
|
6
|
-
const action = {
|
|
7
|
-
title: 'Update Audience',
|
|
8
|
-
description: 'Sync contacts from an Engage Audience to a TikTok Audience Segment.',
|
|
9
|
-
defaultSubscription: 'event = "Audience Entered" or event = "Audience Exited"',
|
|
10
|
-
fields: {
|
|
11
|
-
custom_audience_name: {
|
|
12
|
-
label: 'Custom Audience Name',
|
|
13
|
-
description: 'Custom audience name of audience to be created. Please note that names over 70 characters will be truncated to 67 characters with "..." appended. This field is set only when Segment creates a new audience. Updating this field after Segment has created an audience will not update the audience name in TikTok.',
|
|
14
|
-
type: 'string',
|
|
15
|
-
default: {
|
|
16
|
-
'@path': '$.properties.audience_key'
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
id_type: {
|
|
20
|
-
label: 'ID Type',
|
|
21
|
-
description: 'Encryption type to be used for populating the audience.',
|
|
22
|
-
type: 'string',
|
|
23
|
-
choices: [
|
|
24
|
-
{ label: 'Email', value: 'EMAIL_SHA256' },
|
|
25
|
-
{ label: 'Google Advertising ID', value: 'GAID_SHA256' }
|
|
26
|
-
]
|
|
27
|
-
},
|
|
28
|
-
email: {
|
|
29
|
-
label: 'User Email',
|
|
30
|
-
description: "The user's email address to send to LinkedIn.",
|
|
31
|
-
type: 'hidden',
|
|
32
|
-
default: {
|
|
33
|
-
'@path': '$.context.traits.email'
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
google_advertising_id: {
|
|
37
|
-
label: 'User Google Advertising ID',
|
|
38
|
-
description: "The user's Google Advertising ID to send to LinkedIn.",
|
|
39
|
-
type: 'hidden',
|
|
40
|
-
default: {
|
|
41
|
-
'@path': '$.context.device.advertisingId'
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
event_name: {
|
|
45
|
-
label: 'Event Name',
|
|
46
|
-
description: 'The name of the current Segment event.',
|
|
47
|
-
type: 'hidden',
|
|
48
|
-
default: {
|
|
49
|
-
'@path': '$.event'
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
enable_batching: {
|
|
53
|
-
label: 'Enable Batching',
|
|
54
|
-
description: 'Enable batching of requests to the TikTok Audiences.',
|
|
55
|
-
type: 'boolean',
|
|
56
|
-
default: true
|
|
57
|
-
},
|
|
58
|
-
personas_audience_key: {
|
|
59
|
-
label: 'Segment Engage Audience Key',
|
|
60
|
-
description: 'The `audience_key` of the Engage audience you want to sync to TikTok. This value must be a hard-coded string variable, e.g. `personas_test_audience`, in order for batching to work properly.',
|
|
61
|
-
type: 'string'
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
perform: async (request, { settings, payload }) => {
|
|
65
|
-
return processPayload(request, settings, [payload]);
|
|
66
|
-
},
|
|
67
|
-
performBatch: async (request, { settings, payload }) => {
|
|
68
|
-
return processPayload(request, settings, payload);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
async function processPayload(request, settings, payloads) {
|
|
72
|
-
validate(payloads);
|
|
73
|
-
const TikTokApiClient = new api_1.TikTokAudiences(request);
|
|
74
|
-
const audiences = await getAllAudiences(TikTokApiClient, settings);
|
|
75
|
-
const audience_id = await getAudienceID(TikTokApiClient, settings, payloads[0], audiences);
|
|
76
|
-
const users = extractUsers(payloads, audience_id);
|
|
77
|
-
let res;
|
|
78
|
-
if (users.length > 0) {
|
|
79
|
-
const elements = {
|
|
80
|
-
advertiser_ids: [settings.advertiser_id],
|
|
81
|
-
action: 'add',
|
|
82
|
-
data: users
|
|
83
|
-
};
|
|
84
|
-
res = await TikTokApiClient.batchUpdate(elements);
|
|
85
|
-
}
|
|
86
|
-
return res;
|
|
87
|
-
}
|
|
88
|
-
function validate(payloads) {
|
|
89
|
-
if (payloads[0].custom_audience_name !== payloads[0].personas_audience_key) {
|
|
90
|
-
throw new actions_core_1.IntegrationError('The value of `custom_audience_name` and `personas_audience_key` must match.', 'INVALID_SETTINGS', 400);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async function getAllAudiences(TikTokApiClient, settings) {
|
|
94
|
-
let response = await TikTokApiClient.getAudiences(settings, 1, 100);
|
|
95
|
-
let audiences = response.data.data.list;
|
|
96
|
-
const total_number_audiences = response.data.data.page_info.total_number;
|
|
97
|
-
let recieved_audiences = 100;
|
|
98
|
-
let page_number = 2;
|
|
99
|
-
while (recieved_audiences < total_number_audiences) {
|
|
100
|
-
response = await TikTokApiClient.getAudiences(settings, page_number, 100);
|
|
101
|
-
audiences = audiences.concat(response.data.data.list);
|
|
102
|
-
page_number += 1;
|
|
103
|
-
recieved_audiences += 100;
|
|
104
|
-
}
|
|
105
|
-
return audiences;
|
|
106
|
-
}
|
|
107
|
-
async function getAudienceID(TikTokApiClient, settings, payload, audiences) {
|
|
108
|
-
let audienceID;
|
|
109
|
-
const audienceExists = audiences.filter(function (audience) {
|
|
110
|
-
if (audience.name === payload.custom_audience_name) {
|
|
111
|
-
return audience.audience_id;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
if (audienceExists.length > 0) {
|
|
115
|
-
audienceID = audienceExists[0].audience_id;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
const response = await TikTokApiClient.createAudience(settings, payload);
|
|
119
|
-
audienceID = response.data.data.audience_id;
|
|
120
|
-
}
|
|
121
|
-
return audienceID;
|
|
122
|
-
}
|
|
123
|
-
function getAction(payload) {
|
|
124
|
-
if (payload.event_name === 'Audience Entered') {
|
|
125
|
-
return 'add';
|
|
126
|
-
}
|
|
127
|
-
else if (payload.event_name === 'Audience Exited') {
|
|
128
|
-
return 'delete';
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
function extractUsers(payloads, audienceID) {
|
|
132
|
-
const data = [];
|
|
133
|
-
payloads.forEach((payload) => {
|
|
134
|
-
if (!payload.email && !payload.google_advertising_id) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const payloadAction = getAction(payload);
|
|
138
|
-
if (payloadAction === 'add') {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (payload.id_type == 'EMAIL_SHA256' && payload.email) {
|
|
142
|
-
payload.email = payload.email.replace(/\+.*@/, '@').replace(/\./g, '').toLowerCase();
|
|
143
|
-
data.push({
|
|
144
|
-
id_type: 'EMAIL_SHA256',
|
|
145
|
-
id: crypto_1.createHash('sha256').update(payload.email).digest('hex'),
|
|
146
|
-
audience_ids: [audienceID]
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
if (payload.id_type == 'GAID_SHA256' && payload.google_advertising_id) {
|
|
150
|
-
data.push({
|
|
151
|
-
id_type: 'GAID_SHA256',
|
|
152
|
-
id: crypto_1.createHash('sha256').update(payload.google_advertising_id).digest('hex'),
|
|
153
|
-
audience_ids: [audienceID]
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
return data;
|
|
158
|
-
}
|
|
159
|
-
exports.default = action;
|
|
160
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/tiktok-audiences/updateAudience/index.ts"],"names":[],"mappings":";;AACA,wDAAuE;AACvE,gCAAwC;AAIxC,mCAAmC;AAEnC,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,iBAAiB;IACxB,WAAW,EAAE,qEAAqE;IAClF,mBAAmB,EAAE,yDAAyD;IAC9E,MAAM,EAAE;QACN,oBAAoB,EAAE;YACpB,KAAK,EAAE,sBAAsB;YAC7B,WAAW,EACT,sTAAsT;YACxT,IAAI,EAAE,QAAQ;YACd,OAAO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