@segment/action-destinations 3.257.0 → 3.258.0-staging-b97a16328
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/blackbaud-raisers-edge-nxt/utils/index.d.ts +1 -1
- package/dist/destinations/engage/sendgrid/Profile.d.ts +6 -0
- package/dist/destinations/engage/sendgrid/Profile.js +3 -0
- package/dist/destinations/engage/sendgrid/Profile.js.map +1 -0
- package/dist/destinations/engage/sendgrid/previewApiLookup/api-lookups.d.ts +21 -0
- package/dist/destinations/engage/sendgrid/previewApiLookup/api-lookups.js +174 -0
- package/dist/destinations/engage/sendgrid/previewApiLookup/api-lookups.js.map +1 -0
- package/dist/destinations/engage/utils/track.d.ts +17 -17
- package/dist/destinations/google-enhanced-conversions/functions.d.ts +7 -0
- package/dist/destinations/google-enhanced-conversions/functions.js +7 -3
- package/dist/destinations/google-enhanced-conversions/functions.js.map +1 -1
- package/dist/destinations/index.js.map +1 -1
- package/dist/destinations/klaviyo/addProfileToList/index.js +1 -1
- package/dist/destinations/klaviyo/addProfileToList/index.js.map +1 -1
- package/dist/destinations/klaviyo/functions.d.ts +7 -4
- package/dist/destinations/klaviyo/functions.js +80 -1
- package/dist/destinations/klaviyo/functions.js.map +1 -1
- package/dist/destinations/klaviyo/removeProfileFromList/index.js +1 -1
- package/dist/destinations/klaviyo/removeProfileFromList/index.js.map +1 -1
- package/dist/destinations/klaviyo/types.d.ts +97 -0
- package/dist/destinations/klaviyo/upsertProfile/index.js +29 -19
- package/dist/destinations/klaviyo/upsertProfile/index.js.map +1 -1
- package/dist/destinations/marketo-static-lists/addToList/generated-types.d.ts +13 -4
- package/dist/destinations/marketo-static-lists/addToList/index.js +65 -4
- package/dist/destinations/marketo-static-lists/addToList/index.js.map +1 -1
- package/dist/destinations/marketo-static-lists/constants.d.ts +10 -3
- package/dist/destinations/marketo-static-lists/constants.js +2 -14
- package/dist/destinations/marketo-static-lists/constants.js.map +1 -1
- package/dist/destinations/marketo-static-lists/functions.d.ts +22 -2
- package/dist/destinations/marketo-static-lists/functions.js +91 -3
- package/dist/destinations/marketo-static-lists/functions.js.map +1 -1
- package/dist/destinations/marketo-static-lists/index.js +4 -42
- package/dist/destinations/marketo-static-lists/index.js.map +1 -1
- package/dist/destinations/marketo-static-lists/properties.js +2 -39
- package/dist/destinations/marketo-static-lists/properties.js.map +1 -1
- package/dist/destinations/marketo-static-lists/removeFromList/generated-types.d.ts +1 -1
- package/dist/destinations/mixpanel/utils.d.ts +13 -0
- package/dist/destinations/mixpanel/utils.js +117 -0
- package/dist/destinations/mixpanel/utils.js.map +1 -0
- package/dist/destinations/responsys/asyncMergePetRecords/generated-types.d.ts +14 -0
- package/dist/destinations/responsys/asyncMergePetRecords/generated-types.js +3 -0
- package/dist/destinations/responsys/asyncMergePetRecords/generated-types.js.map +1 -0
- package/dist/destinations/responsys/asyncMergePetRecords/index.d.ts +5 -0
- package/dist/destinations/responsys/asyncMergePetRecords/index.js +113 -0
- package/dist/destinations/responsys/asyncMergePetRecords/index.js.map +1 -0
- package/dist/destinations/responsys/asyncMergeProfileListMembers/generated-types.d.ts +20 -0
- package/dist/destinations/responsys/asyncMergeProfileListMembers/generated-types.js +3 -0
- package/dist/destinations/responsys/asyncMergeProfileListMembers/generated-types.js.map +1 -0
- package/dist/destinations/responsys/asyncMergeProfileListMembers/index.d.ts +5 -0
- package/dist/destinations/responsys/asyncMergeProfileListMembers/index.js +174 -0
- package/dist/destinations/responsys/asyncMergeProfileListMembers/index.js.map +1 -0
- package/dist/destinations/responsys/rsp-operations.d.ts +14 -0
- package/dist/destinations/responsys/rsp-operations.js +33 -0
- package/dist/destinations/responsys/rsp-operations.js.map +1 -0
- package/dist/destinations/responsys/rsp-properties.d.ts +4 -0
- package/dist/destinations/responsys/rsp-properties.js +27 -0
- package/dist/destinations/responsys/rsp-properties.js.map +1 -0
- package/dist/destinations/segment/segment-properties.d.ts +1 -0
- package/dist/destinations/segment/segment-properties.js +8 -1
- package/dist/destinations/segment/segment-properties.js.map +1 -1
- package/dist/destinations/segment/sendGroup/generated-types.d.ts +1 -0
- package/dist/destinations/segment/sendGroup/index.js +2 -0
- package/dist/destinations/segment/sendGroup/index.js.map +1 -1
- package/dist/destinations/segment/sendIdentify/generated-types.d.ts +1 -0
- package/dist/destinations/segment/sendIdentify/index.js +2 -0
- package/dist/destinations/segment/sendIdentify/index.js.map +1 -1
- package/dist/destinations/segment/sendPage/generated-types.d.ts +1 -0
- package/dist/destinations/segment/sendPage/index.js +2 -0
- package/dist/destinations/segment/sendPage/index.js.map +1 -1
- package/dist/destinations/segment/sendScreen/generated-types.d.ts +1 -0
- package/dist/destinations/segment/sendScreen/index.js +2 -0
- package/dist/destinations/segment/sendScreen/index.js.map +1 -1
- package/dist/destinations/segment/sendTrack/generated-types.d.ts +1 -0
- package/dist/destinations/segment/sendTrack/index.js +2 -0
- package/dist/destinations/segment/sendTrack/index.js.map +1 -1
- package/dist/destinations/snap-conversions-api/_tests_/capiV2tests.d.ts +1 -0
- package/dist/destinations/snap-conversions-api/_tests_/capiV2tests.js +381 -0
- package/dist/destinations/snap-conversions-api/_tests_/capiV2tests.js.map +1 -0
- package/dist/destinations/snap-conversions-api/_tests_/capiV3tests.d.ts +1 -0
- package/dist/destinations/snap-conversions-api/_tests_/capiV3tests.js +581 -0
- package/dist/destinations/snap-conversions-api/_tests_/capiV3tests.js.map +1 -0
- package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-v2.d.ts +4 -0
- package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-v2.js +97 -0
- package/dist/destinations/snap-conversions-api/reportConversionEvent/snap-capi-v2.js.map +1 -0
- package/dist/destinations/tiktok-offline-conversions/reportOfflineEvent/formatter.d.ts +3 -0
- package/dist/destinations/tiktok-offline-conversions/reportOfflineEvent/formatter.js +43 -0
- package/dist/destinations/tiktok-offline-conversions/reportOfflineEvent/formatter.js.map +1 -0
- package/package.json +4 -4
|
@@ -99,6 +99,7 @@ export interface ProfileAttributes {
|
|
|
99
99
|
location?: Location | null;
|
|
100
100
|
properties?: Record<string, any>;
|
|
101
101
|
list_id?: string;
|
|
102
|
+
subscriptions?: Record<string, any>;
|
|
102
103
|
}
|
|
103
104
|
export interface ImportJobPayload {
|
|
104
105
|
type: string;
|
|
@@ -126,3 +127,99 @@ export interface Profile {
|
|
|
126
127
|
export interface GetProfileResponse {
|
|
127
128
|
data: Profile[];
|
|
128
129
|
}
|
|
130
|
+
export interface SubProfilePayload {
|
|
131
|
+
type: string;
|
|
132
|
+
attributes: {
|
|
133
|
+
email?: string;
|
|
134
|
+
phone_number?: string;
|
|
135
|
+
subscriptions?: {
|
|
136
|
+
email?: {};
|
|
137
|
+
sms?: {};
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export interface SubscriptionData {
|
|
142
|
+
data: {
|
|
143
|
+
type: string;
|
|
144
|
+
attributes: {
|
|
145
|
+
custom_source: string;
|
|
146
|
+
profiles: {
|
|
147
|
+
data: Array<SubProfilePayload>;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
relationships?: {
|
|
151
|
+
list: {
|
|
152
|
+
data: {
|
|
153
|
+
type: 'list';
|
|
154
|
+
id: string;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export interface SubProfile {
|
|
161
|
+
email?: string;
|
|
162
|
+
phone_number?: string;
|
|
163
|
+
list_id: string;
|
|
164
|
+
}
|
|
165
|
+
export interface KlaviyoJobStatusResponse {
|
|
166
|
+
data: {
|
|
167
|
+
type: string;
|
|
168
|
+
id: string;
|
|
169
|
+
attributes: {
|
|
170
|
+
status: string;
|
|
171
|
+
created_at: string;
|
|
172
|
+
total_count: number;
|
|
173
|
+
completed_count: number;
|
|
174
|
+
failed_count: number;
|
|
175
|
+
completed_at: string | null;
|
|
176
|
+
started_at: string | null;
|
|
177
|
+
};
|
|
178
|
+
relationships: {};
|
|
179
|
+
links: {
|
|
180
|
+
self: string;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
export interface KlaviyoImportJobData {
|
|
185
|
+
data: {
|
|
186
|
+
type: string;
|
|
187
|
+
id: string;
|
|
188
|
+
attributes: {
|
|
189
|
+
status: string;
|
|
190
|
+
created_at: string;
|
|
191
|
+
total_count: number;
|
|
192
|
+
completed_count: number;
|
|
193
|
+
failed_count: number;
|
|
194
|
+
completed_at: string | null;
|
|
195
|
+
expires_at: string;
|
|
196
|
+
started_at: string | null;
|
|
197
|
+
};
|
|
198
|
+
relationships: {
|
|
199
|
+
lists: {
|
|
200
|
+
data: Array<{
|
|
201
|
+
type: string;
|
|
202
|
+
id: string;
|
|
203
|
+
}>;
|
|
204
|
+
links: {
|
|
205
|
+
self: string;
|
|
206
|
+
related: string;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
profiles: {
|
|
210
|
+
links: {
|
|
211
|
+
self: string;
|
|
212
|
+
related: string;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
import_errors: {
|
|
216
|
+
links: {
|
|
217
|
+
related: string;
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
links: {
|
|
222
|
+
self: string;
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
}
|
|
@@ -159,9 +159,12 @@ const action = {
|
|
|
159
159
|
json: profileData
|
|
160
160
|
});
|
|
161
161
|
if (list_id) {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
const subscriptionProfile = {
|
|
163
|
+
email: profileData.data.attributes.email,
|
|
164
|
+
phone_number: profileData.data.attributes.phone_number,
|
|
165
|
+
list_id
|
|
166
|
+
};
|
|
167
|
+
await functions_1.subscribeProfiles(request, subscriptionProfile);
|
|
165
168
|
}
|
|
166
169
|
return profile;
|
|
167
170
|
}
|
|
@@ -177,7 +180,12 @@ const action = {
|
|
|
177
180
|
json: profileData
|
|
178
181
|
});
|
|
179
182
|
if (list_id) {
|
|
180
|
-
|
|
183
|
+
const subscriptionProfile = {
|
|
184
|
+
email: profileData.data.attributes.email,
|
|
185
|
+
phone_number: profileData.data.attributes.phone_number,
|
|
186
|
+
list_id
|
|
187
|
+
};
|
|
188
|
+
await functions_1.subscribeProfiles(request, subscriptionProfile);
|
|
181
189
|
}
|
|
182
190
|
return profile;
|
|
183
191
|
}
|
|
@@ -187,23 +195,25 @@ const action = {
|
|
|
187
195
|
},
|
|
188
196
|
performBatch: async (request, { payload }) => {
|
|
189
197
|
payload = payload.filter((profile) => profile.email || profile.external_id || profile.phone_number);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
let importResponseWithList;
|
|
193
|
-
let importResponseWithoutList;
|
|
194
|
-
if (profilesWithList.length > 0) {
|
|
195
|
-
const listId = profilesWithList[0].list_id;
|
|
196
|
-
const importJobPayload = functions_1.createImportJobPayload(profilesWithList, listId);
|
|
197
|
-
importResponseWithList = await functions_1.sendImportJobRequest(request, importJobPayload);
|
|
198
|
+
if (payload.length === 0) {
|
|
199
|
+
throw new actions_core_1.PayloadValidationError(`'One of External ID, Phone Number and Email is required.'`);
|
|
198
200
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
const profilesForImport = payload.map(({ list_id, ...profile }) => profile);
|
|
202
|
+
const importJobResponse = await functions_1.sendImportJobRequest(request, functions_1.createImportJobPayload(profilesForImport));
|
|
203
|
+
const parsedData = JSON.parse(importJobResponse.data);
|
|
204
|
+
const jobId = parsedData.data.id;
|
|
205
|
+
if (jobId) {
|
|
206
|
+
const jobStatusResponse = await functions_1.pollKlaviyoJobStatus(request, jobId);
|
|
207
|
+
if (jobStatusResponse.data.attributes.status !== 'complete') {
|
|
208
|
+
throw new actions_core_1.APIError('Import job did not complete successfully.', 401);
|
|
209
|
+
}
|
|
210
|
+
const profilesWithListId = payload.filter((profile) => !!profile.list_id);
|
|
211
|
+
for (let i = 0; i < profilesWithListId.length; i += 100) {
|
|
212
|
+
const batch = profilesWithListId.slice(i, i + 100);
|
|
213
|
+
await functions_1.subscribeProfiles(request, batch);
|
|
214
|
+
}
|
|
202
215
|
}
|
|
203
|
-
return
|
|
204
|
-
withList: importResponseWithList,
|
|
205
|
-
withoutList: importResponseWithoutList
|
|
206
|
-
};
|
|
216
|
+
return importJobResponse;
|
|
207
217
|
}
|
|
208
218
|
};
|
|
209
219
|
exports.default = action;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/klaviyo/upsertProfile/index.ts"],"names":[],"mappings":";;AAIA,sCAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/klaviyo/upsertProfile/index.ts"],"names":[],"mappings":";;AAIA,sCAAmC;AACnC,wDAAwE;AAExE,4CAMqB;AACrB,8CAA0C;AAE1C,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,gBAAgB;IACvB,WAAW,EAAE,sBAAsB;IACnC,mBAAmB,EAAE,mBAAmB;IACxC,MAAM,EAAE;QACN,KAAK,EAAE;YACL,KAAK,EAAE,OAAO;YACd,WAAW,EAAE,kFAAkF;YAC/F,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,OAAO,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE;SACvC;QACD,eAAe,EAAE;YACf,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,uBAAuB;YAC9B,WAAW,EAAE,0DAA0D;SACxE;QACD,YAAY,EAAE;YACZ,KAAK,EAAE,cAAc;YACrB,WAAW,EAAE,mKAAmK;YAChL,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,EAAE,OAAO,EAAE,wBAAwB,EAAE;SAC/C;QACD,WAAW,EAAE;YACX,KAAK,EAAE,aAAa;YACpB,WAAW,EAAE,+JAA+J;YAC5K,IAAI,EAAE,QAAQ;SACf;QACD,UAAU,EAAE;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B,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;YAEpE,IAAI,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,UAAU,EAAE;gBAC3D,MAAM,IAAI,uBAAQ,CAAC,2CAA2C,EAAE,GAAG,CAAC,CAAA;aACrE;YAGD,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,EAAyB,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YAChG,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,IAAI,GAAG,EAAE;gBACvD,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,CAAA;gBAClD,MAAM,6BAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;aACxC;SACF;QAED,OAAO,iBAAiB,CAAA;IAC1B,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
export interface Payload {
|
|
2
|
-
external_id
|
|
2
|
+
external_id?: string;
|
|
3
3
|
lookup_field: string;
|
|
4
4
|
data: {
|
|
5
5
|
email?: string;
|
|
6
|
-
firstName?: string;
|
|
7
|
-
lastName?: string;
|
|
8
|
-
phone?: string;
|
|
9
6
|
[k: string]: unknown;
|
|
10
7
|
};
|
|
11
8
|
enable_batching: boolean;
|
|
12
9
|
batch_size: number;
|
|
13
10
|
event_name: string;
|
|
14
11
|
}
|
|
12
|
+
export interface HookBundle {
|
|
13
|
+
retlOnMappingSave: {
|
|
14
|
+
inputs?: {
|
|
15
|
+
list_id?: string;
|
|
16
|
+
list_name?: string;
|
|
17
|
+
};
|
|
18
|
+
outputs?: {
|
|
19
|
+
id?: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -14,13 +14,74 @@ const action = {
|
|
|
14
14
|
batch_size: { ...properties_1.batch_size },
|
|
15
15
|
event_name: { ...properties_1.event_name }
|
|
16
16
|
},
|
|
17
|
-
|
|
17
|
+
hooks: {
|
|
18
|
+
retlOnMappingSave: {
|
|
19
|
+
label: 'Connect to a static list in Marketo',
|
|
20
|
+
description: 'When saving this mapping, we will create a static list in Marketo using the fields you provided.',
|
|
21
|
+
inputFields: {
|
|
22
|
+
list_id: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
label: 'Existing List ID',
|
|
25
|
+
description: 'The ID of the Marketo Static List that users will be synced to. If defined, we will not create a new list.',
|
|
26
|
+
required: false
|
|
27
|
+
},
|
|
28
|
+
list_name: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
label: 'List Name',
|
|
31
|
+
description: 'The name of the Marketo Static List that you would like to create.',
|
|
32
|
+
required: false
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
outputTypes: {
|
|
36
|
+
id: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
label: 'ID',
|
|
39
|
+
description: 'The ID of the created Marketo Static List that users will be synced to.',
|
|
40
|
+
required: false
|
|
41
|
+
},
|
|
42
|
+
name: {
|
|
43
|
+
type: 'string',
|
|
44
|
+
label: 'List Name',
|
|
45
|
+
description: 'The name of the created Marketo Static List that users will be synced to.',
|
|
46
|
+
required: false
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
performHook: async (request, { settings, hookInputs, statsContext }) => {
|
|
50
|
+
if (hookInputs.list_id) {
|
|
51
|
+
return functions_1.getList(request, settings, hookInputs.list_id);
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const input = {
|
|
55
|
+
audienceName: hookInputs.list_name,
|
|
56
|
+
settings: settings
|
|
57
|
+
};
|
|
58
|
+
const listId = await functions_1.createList(request, input, statsContext);
|
|
59
|
+
return {
|
|
60
|
+
successMessage: `List '${hookInputs.list_name}' (id: ${listId}) created successfully!`,
|
|
61
|
+
savedData: {
|
|
62
|
+
id: listId,
|
|
63
|
+
name: hookInputs.list_name
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
return {
|
|
69
|
+
error: {
|
|
70
|
+
message: 'Failed to create list',
|
|
71
|
+
code: 'CREATE_LIST_FAILURE'
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
perform: async (request, { settings, payload, statsContext, hookOutputs }) => {
|
|
18
79
|
statsContext?.statsClient?.incr('addToAudience', 1, statsContext?.tags);
|
|
19
|
-
return functions_1.addToList(request, settings, [payload], statsContext);
|
|
80
|
+
return functions_1.addToList(request, settings, [payload], statsContext, hookOutputs?.retlOnMappingSave?.outputs);
|
|
20
81
|
},
|
|
21
|
-
performBatch: async (request, { settings, payload, statsContext }) => {
|
|
82
|
+
performBatch: async (request, { settings, payload, statsContext, hookOutputs }) => {
|
|
22
83
|
statsContext?.statsClient?.incr('addToAudience.batch', 1, statsContext?.tags);
|
|
23
|
-
return functions_1.addToList(request, settings, payload, statsContext);
|
|
84
|
+
return functions_1.addToList(request, settings, payload, statsContext, hookOutputs?.retlOnMappingSave?.outputs);
|
|
24
85
|
}
|
|
25
86
|
};
|
|
26
87
|
exports.default = action;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/marketo-static-lists/addToList/index.ts"],"names":[],"mappings":";;AAGA,8CAAwG;AACxG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/marketo-static-lists/addToList/index.ts"],"names":[],"mappings":";;AAGA,8CAAwG;AACxG,4CAA6D;AAE7D,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,aAAa;IACpB,WAAW,EAAE,yDAAyD;IACtE,mBAAmB,EAAE,4BAA4B;IACjD,MAAM,EAAE;QACN,WAAW,EAAE,EAA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
+
export declare const OAUTH_ENDPOINT = "identity/oauth/token";
|
|
3
2
|
export declare const GET_FOLDER_ENDPOINT: string;
|
|
4
3
|
export declare const CREATE_LIST_ENDPOINT: string;
|
|
5
4
|
export declare const GET_LIST_ENDPOINT: string;
|
|
@@ -56,4 +55,12 @@ export interface MarketoLeads {
|
|
|
56
55
|
updatedAt: string;
|
|
57
56
|
createdAt: string;
|
|
58
57
|
}
|
|
59
|
-
export
|
|
58
|
+
export interface CreateListInput {
|
|
59
|
+
audienceName: string;
|
|
60
|
+
settings: {
|
|
61
|
+
client_id: string;
|
|
62
|
+
client_secret: string;
|
|
63
|
+
api_endpoint: string;
|
|
64
|
+
folder_name: string;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CSV_LIMIT = exports.REMOVE_USERS_ENDPOINT = exports.GET_LEADS_ENDPOINT = exports.BULK_IMPORT_ENDPOINT = exports.GET_LIST_ENDPOINT = exports.CREATE_LIST_ENDPOINT = exports.GET_FOLDER_ENDPOINT = exports.OAUTH_ENDPOINT = void 0;
|
|
4
4
|
const API_VERSION = 'v1';
|
|
5
|
-
|
|
5
|
+
exports.OAUTH_ENDPOINT = 'identity/oauth/token';
|
|
6
6
|
exports.GET_FOLDER_ENDPOINT = `/rest/asset/${API_VERSION}/folder/byName.json?name=folderName`;
|
|
7
7
|
exports.CREATE_LIST_ENDPOINT = `/rest/asset/${API_VERSION}/staticLists.json?folder=folderId&name=listName`;
|
|
8
8
|
exports.GET_LIST_ENDPOINT = `/rest/asset/${API_VERSION}/staticList/listId.json`;
|
|
@@ -10,16 +10,4 @@ exports.BULK_IMPORT_ENDPOINT = `/bulk/${API_VERSION}/leads.json?format=csv&listI
|
|
|
10
10
|
exports.GET_LEADS_ENDPOINT = `/rest/${API_VERSION}/leads.json?filterType=field&filterValues=emailsToFilter`;
|
|
11
11
|
exports.REMOVE_USERS_ENDPOINT = `/rest/${API_VERSION}/lists/listId/leads.json?id=idsToDelete`;
|
|
12
12
|
exports.CSV_LIMIT = 10000000;
|
|
13
|
-
async function getAccessToken(request, settings) {
|
|
14
|
-
const res = await request(`${settings.api_endpoint}/${OAUTH_ENDPOINT}`, {
|
|
15
|
-
method: 'POST',
|
|
16
|
-
body: new URLSearchParams({
|
|
17
|
-
client_id: settings.client_id,
|
|
18
|
-
client_secret: settings.client_secret,
|
|
19
|
-
grant_type: 'client_credentials'
|
|
20
|
-
})
|
|
21
|
-
});
|
|
22
|
-
return res.data.access_token;
|
|
23
|
-
}
|
|
24
|
-
exports.getAccessToken = getAccessToken;
|
|
25
13
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/destinations/marketo-static-lists/constants.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/destinations/marketo-static-lists/constants.ts"],"names":[],"mappings":";;;AAAA,MAAM,WAAW,GAAG,IAAI,CAAA;AACX,QAAA,cAAc,GAAG,sBAAsB,CAAA;AACvC,QAAA,mBAAmB,GAAG,eAAe,WAAW,qCAAqC,CAAA;AACrF,QAAA,oBAAoB,GAAG,eAAe,WAAW,iDAAiD,CAAA;AAClG,QAAA,iBAAiB,GAAG,eAAe,WAAW,yBAAyB,CAAA;AACvE,QAAA,oBAAoB,GAAG,SAAS,WAAW,oEAAoE,CAAA;AAC/G,QAAA,kBAAkB,GAAG,SAAS,WAAW,0DAA0D,CAAA;AACnG,QAAA,qBAAqB,GAAG,SAAS,WAAW,yCAAyC,CAAA;AAErF,QAAA,SAAS,GAAG,QAAQ,CAAA"}
|
|
@@ -2,7 +2,27 @@ import { RequestClient, StatsContext } from '@segment/actions-core';
|
|
|
2
2
|
import { Settings } from './generated-types';
|
|
3
3
|
import { Payload as AddToListPayload } from './addToList/generated-types';
|
|
4
4
|
import { Payload as RemoveFromListPayload } from './removeFromList/generated-types';
|
|
5
|
-
import { MarketoBulkImportResponse, MarketoDeleteLeadsResponse } from './constants';
|
|
5
|
+
import { MarketoBulkImportResponse, MarketoDeleteLeadsResponse, CreateListInput } from './constants';
|
|
6
6
|
export declare function formatEndpoint(endpoint: string): string;
|
|
7
|
-
export declare function addToList(request: RequestClient, settings: Settings, payloads: AddToListPayload[], statsContext?: StatsContext
|
|
7
|
+
export declare function addToList(request: RequestClient, settings: Settings, payloads: AddToListPayload[], statsContext?: StatsContext, hookOutputs?: {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
}): Promise<MarketoBulkImportResponse>;
|
|
8
11
|
export declare function removeFromList(request: RequestClient, settings: Settings, payloads: RemoveFromListPayload[], statsContext?: StatsContext): Promise<MarketoDeleteLeadsResponse>;
|
|
12
|
+
export declare function getAccessToken(request: RequestClient, settings: Settings): Promise<string>;
|
|
13
|
+
export declare function getList(request: RequestClient, settings: Settings, id: string): Promise<{
|
|
14
|
+
error: {
|
|
15
|
+
message: string;
|
|
16
|
+
code: string;
|
|
17
|
+
};
|
|
18
|
+
successMessage?: undefined;
|
|
19
|
+
savedData?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
successMessage: string;
|
|
22
|
+
savedData: {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
26
|
+
error?: undefined;
|
|
27
|
+
}>;
|
|
28
|
+
export declare function createList(request: RequestClient, input: CreateListInput, statsContext?: StatsContext): Promise<string>;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeFromList = exports.addToList = exports.formatEndpoint = void 0;
|
|
3
|
+
exports.createList = exports.getList = exports.getAccessToken = exports.removeFromList = exports.addToList = exports.formatEndpoint = void 0;
|
|
4
4
|
const actions_core_1 = require("@segment/actions-core");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
function formatEndpoint(endpoint) {
|
|
7
7
|
return endpoint.replace('/rest', '');
|
|
8
8
|
}
|
|
9
9
|
exports.formatEndpoint = formatEndpoint;
|
|
10
|
-
async function addToList(request, settings, payloads, statsContext) {
|
|
10
|
+
async function addToList(request, settings, payloads, statsContext, hookOutputs) {
|
|
11
|
+
const list_id = hookOutputs?.id ?? payloads[0].external_id;
|
|
12
|
+
if (!list_id) {
|
|
13
|
+
throw new actions_core_1.IntegrationError('No list ID found in payload', 'INVALID_REQUEST_DATA', 400);
|
|
14
|
+
}
|
|
11
15
|
const api_endpoint = formatEndpoint(settings.api_endpoint);
|
|
12
16
|
const csvData = formatData(payloads);
|
|
13
17
|
const csvSize = Buffer.byteLength(csvData, 'utf8');
|
|
@@ -16,7 +20,7 @@ async function addToList(request, settings, payloads, statsContext) {
|
|
|
16
20
|
throw new actions_core_1.IntegrationError(`CSV data size exceeds limit of ${constants_1.CSV_LIMIT} bytes`, 'INVALID_REQUEST_DATA', 400);
|
|
17
21
|
}
|
|
18
22
|
const url = api_endpoint +
|
|
19
|
-
constants_1.BULK_IMPORT_ENDPOINT.replace('externalId',
|
|
23
|
+
constants_1.BULK_IMPORT_ENDPOINT.replace('externalId', list_id).replace('fieldToLookup', payloads[0].lookup_field);
|
|
20
24
|
const response = await request(url, {
|
|
21
25
|
method: 'POST',
|
|
22
26
|
headers: {
|
|
@@ -33,6 +37,9 @@ async function addToList(request, settings, payloads, statsContext) {
|
|
|
33
37
|
}
|
|
34
38
|
exports.addToList = addToList;
|
|
35
39
|
async function removeFromList(request, settings, payloads, statsContext) {
|
|
40
|
+
if (!payloads[0].external_id) {
|
|
41
|
+
throw new actions_core_1.IntegrationError('No external_id found in payload', 'INVALID_REQUEST_DATA', 400);
|
|
42
|
+
}
|
|
36
43
|
const api_endpoint = formatEndpoint(settings.api_endpoint);
|
|
37
44
|
const usersToRemove = extractFilterData(payloads);
|
|
38
45
|
const getLeadsUrl = api_endpoint +
|
|
@@ -99,4 +106,85 @@ function parseErrorResponse(response) {
|
|
|
99
106
|
}
|
|
100
107
|
throw new actions_core_1.IntegrationError(response.errors[0].message, 'INVALID_RESPONSE', 400);
|
|
101
108
|
}
|
|
109
|
+
async function getAccessToken(request, settings) {
|
|
110
|
+
const api_endpoint = formatEndpoint(settings.api_endpoint);
|
|
111
|
+
const res = await request(`${api_endpoint}/${constants_1.OAUTH_ENDPOINT}`, {
|
|
112
|
+
method: 'POST',
|
|
113
|
+
body: new URLSearchParams({
|
|
114
|
+
client_id: settings.client_id,
|
|
115
|
+
client_secret: settings.client_secret,
|
|
116
|
+
grant_type: 'client_credentials'
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
return res.data.access_token;
|
|
120
|
+
}
|
|
121
|
+
exports.getAccessToken = getAccessToken;
|
|
122
|
+
async function getList(request, settings, id) {
|
|
123
|
+
const accessToken = await getAccessToken(request, settings);
|
|
124
|
+
const endpoint = formatEndpoint(settings.api_endpoint);
|
|
125
|
+
const getListUrl = endpoint + constants_1.GET_LIST_ENDPOINT.replace('listId', id);
|
|
126
|
+
const getListResponse = await request(getListUrl, {
|
|
127
|
+
method: 'GET',
|
|
128
|
+
headers: {
|
|
129
|
+
authorization: `Bearer ${accessToken}`
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
if (!getListResponse.data.success && getListResponse.data.errors) {
|
|
133
|
+
return {
|
|
134
|
+
error: {
|
|
135
|
+
message: getListResponse.data.errors[0].message,
|
|
136
|
+
code: 'LIST_ID_VERIFICATION_FAILURE'
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
successMessage: `Using existing list '${getListResponse.data.result[0].name}' (id: ${id})`,
|
|
142
|
+
savedData: {
|
|
143
|
+
id: id,
|
|
144
|
+
name: getListResponse.data.result[0].name
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
exports.getList = getList;
|
|
149
|
+
async function createList(request, input, statsContext) {
|
|
150
|
+
const statsClient = statsContext?.statsClient;
|
|
151
|
+
const statsTags = statsContext?.tags;
|
|
152
|
+
if (!input.audienceName) {
|
|
153
|
+
throw new actions_core_1.IntegrationError('Missing audience name value', 'MISSING_REQUIRED_FIELD', 400);
|
|
154
|
+
}
|
|
155
|
+
const endpoint = formatEndpoint(input.settings.api_endpoint);
|
|
156
|
+
const accessToken = await getAccessToken(request, input.settings);
|
|
157
|
+
const getFolderUrl = endpoint + constants_1.GET_FOLDER_ENDPOINT.replace('folderName', encodeURIComponent(input.settings.folder_name));
|
|
158
|
+
const getFolderResponse = await request(getFolderUrl, {
|
|
159
|
+
method: 'GET',
|
|
160
|
+
headers: {
|
|
161
|
+
authorization: `Bearer ${accessToken}`
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
if (!getFolderResponse.data.success && getFolderResponse.data.errors) {
|
|
165
|
+
statsClient?.incr('createAudience.error', 1, statsTags);
|
|
166
|
+
throw new actions_core_1.IntegrationError(`${getFolderResponse.data.errors[0].message}`, 'INVALID_RESPONSE', 400);
|
|
167
|
+
}
|
|
168
|
+
if (!getFolderResponse.data.result) {
|
|
169
|
+
statsClient?.incr('createAudience.error', 1, statsTags);
|
|
170
|
+
throw new actions_core_1.IntegrationError(`A folder with the name ${input.settings.folder_name} not found`, 'INVALID_REQUEST_DATA', 400);
|
|
171
|
+
}
|
|
172
|
+
const folderId = getFolderResponse.data.result[0].id.toString();
|
|
173
|
+
const createListUrl = endpoint +
|
|
174
|
+
constants_1.CREATE_LIST_ENDPOINT.replace('folderId', folderId).replace('listName', encodeURIComponent(input.audienceName));
|
|
175
|
+
const createListResponse = await request(createListUrl, {
|
|
176
|
+
method: 'POST',
|
|
177
|
+
headers: {
|
|
178
|
+
authorization: `Bearer ${accessToken}`
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
if (!createListResponse.data.success && createListResponse.data.errors) {
|
|
182
|
+
statsClient?.incr('createAudience.error', 1, statsTags);
|
|
183
|
+
throw new actions_core_1.IntegrationError(`${createListResponse.data.errors[0].message}`, 'INVALID_RESPONSE', 400);
|
|
184
|
+
}
|
|
185
|
+
const listId = createListResponse.data.result[0].id.toString();
|
|
186
|
+
statsClient?.incr('createAudience.success', 1, statsTags);
|
|
187
|
+
return listId;
|
|
188
|
+
}
|
|
189
|
+
exports.createList = createList;
|
|
102
190
|
//# sourceMappingURL=functions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/destinations/marketo-static-lists/functions.ts"],"names":[],"mappings":";;;AAAA,wDAAqG;AAIrG,
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/destinations/marketo-static-lists/functions.ts"],"names":[],"mappings":";;;AAAA,wDAAqG;AAIrG,2CAiBoB;AAIpB,SAAgB,cAAc,CAAC,QAAgB;IAC7C,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;AACtC,CAAC;AAFD,wCAEC;AAEM,KAAK,UAAU,SAAS,CAC7B,OAAsB,EACtB,QAAkB,EAClB,QAA4B,EAC5B,YAA2B,EAC3B,WAA0C;IAG1C,MAAM,OAAO,GAAG,WAAW,EAAE,EAAE,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;IAE1D,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,+BAAgB,CAAC,6BAA6B,EAAE,sBAAsB,EAAE,GAAG,CAAC,CAAA;KACvF;IAED,MAAM,YAAY,GAAG,cAAc,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;IAE1D,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;IACpC,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAClD,IAAI,OAAO,GAAG,qBAAS,EAAE;QACvB,YAAY,EAAE,WAAW,EAA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AE,CAAC,QAAQ,EAAE,CAAA;IAE/D,MAAM,aAAa,GACjB,QAAQ;QACR,gCAAoB,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,kBAAkB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAA;IAGhH,MAAM,kBAAkB,GAAG,MAAM,OAAO,CAAsB,aAAa,EAAE;QAC3E,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC;KACF,CAAC,CAAA;IAEF,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE;QACtE,WAAW,EAAE,IAAI,CAAC,sBAAsB,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;QACvD,MAAM,IAAI,+BAAgB,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,kBAAkB,EAAE,GAAG,CAAC,CAAA;KACpG;IAED,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAA;IAC9D,WAAW,EAAE,IAAI,CAAC,wBAAwB,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;IAEzD,OAAO,MAAM,CAAA;AACf,CAAC;AA/DD,gCA+DC"}
|
|
@@ -41,7 +41,7 @@ const destination = {
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
refreshAccessToken: async (request, { settings }) => {
|
|
44
|
-
return { accessToken: await
|
|
44
|
+
return { accessToken: await functions_1.getAccessToken(request, settings) };
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
extendRequest({ auth }) {
|
|
@@ -58,47 +58,9 @@ const destination = {
|
|
|
58
58
|
full_audience_sync: false
|
|
59
59
|
},
|
|
60
60
|
async createAudience(request, createAudienceInput) {
|
|
61
|
-
const
|
|
62
|
-
const folder = createAudienceInput.settings.folder_name;
|
|
63
|
-
const endpoint = functions_1.formatEndpoint(createAudienceInput.settings.api_endpoint);
|
|
64
|
-
const statsClient = createAudienceInput?.statsContext?.statsClient;
|
|
65
|
-
const statsTags = createAudienceInput?.statsContext?.tags;
|
|
66
|
-
if (!audienceName) {
|
|
67
|
-
throw new actions_core_1.IntegrationError('Missing audience name value', 'MISSING_REQUIRED_FIELD', 400);
|
|
68
|
-
}
|
|
69
|
-
const accessToken = await constants_1.getAccessToken(request, createAudienceInput.settings);
|
|
70
|
-
const getFolderUrl = endpoint + constants_1.GET_FOLDER_ENDPOINT.replace('folderName', encodeURIComponent(folder));
|
|
71
|
-
const getFolderResponse = await request(getFolderUrl, {
|
|
72
|
-
method: 'GET',
|
|
73
|
-
headers: {
|
|
74
|
-
authorization: `Bearer ${accessToken}`
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
if (!getFolderResponse.data.success && getFolderResponse.data.errors) {
|
|
78
|
-
statsClient?.incr('createAudience.error', 1, statsTags);
|
|
79
|
-
throw new actions_core_1.IntegrationError(`${getFolderResponse.data.errors[0].message}`, 'INVALID_RESPONSE', 400);
|
|
80
|
-
}
|
|
81
|
-
if (!getFolderResponse.data.result) {
|
|
82
|
-
statsClient?.incr('createAudience.error', 1, statsTags);
|
|
83
|
-
throw new actions_core_1.IntegrationError(`A folder with the name ${folder} not found`, 'INVALID_REQUEST_DATA', 400);
|
|
84
|
-
}
|
|
85
|
-
const folderId = getFolderResponse.data.result[0].id.toString();
|
|
86
|
-
const createListUrl = endpoint +
|
|
87
|
-
constants_1.CREATE_LIST_ENDPOINT.replace('folderId', folderId).replace('listName', encodeURIComponent(audienceName));
|
|
88
|
-
const createListResponse = await request(createListUrl, {
|
|
89
|
-
method: 'POST',
|
|
90
|
-
headers: {
|
|
91
|
-
authorization: `Bearer ${accessToken}`
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
if (!createListResponse.data.success && createListResponse.data.errors) {
|
|
95
|
-
statsClient?.incr('createAudience.error', 1, statsTags);
|
|
96
|
-
throw new actions_core_1.IntegrationError(`${createListResponse.data.errors[0].message}`, 'INVALID_RESPONSE', 400);
|
|
97
|
-
}
|
|
98
|
-
const externalId = createListResponse.data.result[0].id.toString();
|
|
99
|
-
statsClient?.incr('createAudience.success', 1, statsTags);
|
|
61
|
+
const listId = await functions_1.createList(request, createAudienceInput, createAudienceInput.statsContext);
|
|
100
62
|
return {
|
|
101
|
-
externalId:
|
|
63
|
+
externalId: listId
|
|
102
64
|
};
|
|
103
65
|
},
|
|
104
66
|
async getAudience(request, getAudienceInput) {
|
|
@@ -106,7 +68,7 @@ const destination = {
|
|
|
106
68
|
const listId = getAudienceInput.externalId;
|
|
107
69
|
const statsClient = getAudienceInput?.statsContext?.statsClient;
|
|
108
70
|
const statsTags = getAudienceInput?.statsContext?.tags;
|
|
109
|
-
const accessToken = await
|
|
71
|
+
const accessToken = await functions_1.getAccessToken(request, getAudienceInput.settings);
|
|
110
72
|
const getListUrl = endpoint + constants_1.GET_LIST_ENDPOINT.replace('listId', listId);
|
|
111
73
|
const getListResponse = await request(getListUrl, {
|
|
112
74
|
method: 'GET',
|