@segment/action-destinations 3.112.0 → 3.112.1-alpha.0
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/linkedin-audiences/api/index.d.ts +13 -0
- package/dist/destinations/linkedin-audiences/api/index.js +62 -0
- package/dist/destinations/linkedin-audiences/api/index.js.map +1 -0
- package/dist/destinations/linkedin-audiences/constants.d.ts +2 -0
- package/dist/destinations/linkedin-audiences/constants.js +6 -0
- package/dist/destinations/linkedin-audiences/constants.js.map +1 -0
- package/dist/destinations/linkedin-audiences/generated-types.d.ts +2 -0
- package/dist/destinations/linkedin-audiences/index.js +25 -9
- package/dist/destinations/linkedin-audiences/index.js.map +1 -1
- package/dist/destinations/linkedin-audiences/types.d.ts +12 -0
- package/dist/destinations/linkedin-audiences/types.js +3 -0
- package/dist/destinations/linkedin-audiences/types.js.map +1 -0
- package/dist/destinations/linkedin-audiences/updateAudience/generated-types.d.ts +0 -2
- package/dist/destinations/linkedin-audiences/updateAudience/index.js +26 -63
- package/dist/destinations/linkedin-audiences/updateAudience/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/destinations/linkedin-audiences/linkedin-properties.d.ts +0 -1
- package/dist/destinations/linkedin-audiences/linkedin-properties.js +0 -5
- package/dist/destinations/linkedin-audiences/linkedin-properties.js.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RequestClient, ModifiedResponse } from '@segment/actions-core';
|
|
2
|
+
import type { Settings } from '../generated-types';
|
|
3
|
+
import type { Payload } from '../updateAudience/generated-types';
|
|
4
|
+
import type { ProfileAPIResponse, AdAccountUserResponse } from '../types';
|
|
5
|
+
export declare class LinkedInAudiences {
|
|
6
|
+
request: RequestClient;
|
|
7
|
+
constructor(request: RequestClient);
|
|
8
|
+
getProfile(): Promise<ModifiedResponse<ProfileAPIResponse>>;
|
|
9
|
+
getAdAccountUserProfile(settings: Settings, userId: string): Promise<ModifiedResponse<AdAccountUserResponse>>;
|
|
10
|
+
getDmpSegment(settings: Settings, payload: Payload): Promise<ModifiedResponse>;
|
|
11
|
+
createDmpSegment(settings: Settings, payload: Payload): Promise<ModifiedResponse>;
|
|
12
|
+
batchUpdate(dmpSegmentId: string, elements: Record<string, string>[]): Promise<ModifiedResponse>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LinkedInAudiences = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
class LinkedInAudiences {
|
|
6
|
+
constructor(request) {
|
|
7
|
+
this.request = request;
|
|
8
|
+
}
|
|
9
|
+
async getProfile() {
|
|
10
|
+
return this.request(`${constants_1.BASE_URL}/me`, {
|
|
11
|
+
method: 'GET'
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
async getAdAccountUserProfile(settings, userId) {
|
|
15
|
+
return this.request(`${constants_1.BASE_URL}/adAccountUsers/account=urn:li:sponsoredAccount:${settings.ad_account_id}&user=urn:li:person:${userId}`, {
|
|
16
|
+
method: 'GET'
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async getDmpSegment(settings, payload) {
|
|
20
|
+
return this.request(`${constants_1.BASE_URL}/dmpSegments`, {
|
|
21
|
+
method: 'GET',
|
|
22
|
+
searchParams: {
|
|
23
|
+
q: 'account',
|
|
24
|
+
account: `urn:li:sponsoredAccount:${settings.ad_account_id}`,
|
|
25
|
+
sourceSegmentId: payload.source_segment_id || '',
|
|
26
|
+
sourcePlatform: 'SEGMENT'
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async createDmpSegment(settings, payload) {
|
|
31
|
+
return this.request(`${constants_1.BASE_URL}/dmpSegments`, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
json: {
|
|
34
|
+
name: payload.dmp_segment_name,
|
|
35
|
+
sourcePlatform: 'SEGMENT',
|
|
36
|
+
sourceSegmentId: payload.source_segment_id,
|
|
37
|
+
account: `urn:li:sponsoredAccount:${settings.ad_account_id}`,
|
|
38
|
+
accessPolicy: 'PRIVATE',
|
|
39
|
+
type: 'USER',
|
|
40
|
+
destinations: [
|
|
41
|
+
{
|
|
42
|
+
destination: 'LINKEDIN'
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async batchUpdate(dmpSegmentId, elements) {
|
|
49
|
+
return this.request(`${constants_1.BASE_URL}/dmpSegments/${dmpSegmentId}/users`, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: {
|
|
52
|
+
'X-RestLi-Method': 'BATCH_CREATE'
|
|
53
|
+
},
|
|
54
|
+
json: {
|
|
55
|
+
elements
|
|
56
|
+
},
|
|
57
|
+
throwHttpErrors: false
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.LinkedInAudiences = LinkedInAudiences;
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/linkedin-audiences/api/index.ts"],"names":[],"mappings":";;;AAGA,4CAAuC;AAGvC,MAAa,iBAAiB;IAG5B,YAAY,OAAsB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,oBAAQ,KAAK,EAAE;YACpC,MAAM,EAAE,KAAK;SACd,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,QAAkB,EAAE,MAAc;QAC9D,OAAO,IAAI,CAAC,OAAO,CACjB,GAAG,oBAAQ,mDAAmD,QAAQ,CAAC,aAAa,uBAAuB,MAAM,EAAE,EACnH;YACE,MAAM,EAAE,KAAK;SACd,CACF,CAAA;IACH,CAAC;IAED,KAAK,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DIN_API_VERSION = void 0;
|
|
4
|
+
exports.LINKEDIN_API_VERSION = '202207';
|
|
5
|
+
exports.BASE_URL = 'https://api.linkedin.com/rest';
|
|
6
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/destinations/linkedin-audiences/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,QAAQ,CAAA;AAC/B,QAAA,QAAQ,GAAG,+BAA+B,CAAA"}
|
|
@@ -3,9 +3,11 @@ 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 actions_core_1 = require("@segment/actions-core");
|
|
6
7
|
const updateAudience_1 = __importDefault(require("./updateAudience"));
|
|
7
|
-
const
|
|
8
|
+
const constants_1 = require("./constants");
|
|
8
9
|
const https_1 = __importDefault(require("https"));
|
|
10
|
+
const api_1 = require("./api");
|
|
9
11
|
const destination = {
|
|
10
12
|
name: 'Linkedin Audiences',
|
|
11
13
|
slug: 'actions-linkedin-audiences',
|
|
@@ -18,17 +20,33 @@ const destination = {
|
|
|
18
20
|
description: 'The id of the LinkedIn Ad Account where batches should be synced.',
|
|
19
21
|
type: 'string',
|
|
20
22
|
required: true
|
|
23
|
+
},
|
|
24
|
+
send_email: {
|
|
25
|
+
label: 'Send Email',
|
|
26
|
+
description: 'Whether to send `email` to LinkedIn. This setting applies to mappings you create in this destination instance.',
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
default: true,
|
|
29
|
+
required: true
|
|
30
|
+
},
|
|
31
|
+
send_google_advertising_id: {
|
|
32
|
+
label: 'Send Google Advertising ID',
|
|
33
|
+
description: 'Whether to send Google Advertising ID to LinkedIn. This setting applies to all mappings you create in this destination instance.',
|
|
34
|
+
type: 'boolean',
|
|
35
|
+
default: true,
|
|
36
|
+
required: true
|
|
21
37
|
}
|
|
22
38
|
},
|
|
23
39
|
testAuthentication: async (request, { settings, auth }) => {
|
|
24
40
|
if (!auth?.accessToken) {
|
|
25
|
-
throw new
|
|
41
|
+
throw new actions_core_1.InvalidAuthenticationError('Please authenticate via Oauth before updating other settings and/or enabling the destination.');
|
|
42
|
+
}
|
|
43
|
+
if (!settings.send_email && !settings.send_google_advertising_id) {
|
|
44
|
+
throw new Error('At least one of `Send Email` or `Send Google Advertising ID` must be set to `true`.');
|
|
26
45
|
}
|
|
46
|
+
const linkedinApiClient = new api_1.LinkedInAudiences(request);
|
|
27
47
|
let firstRes;
|
|
28
48
|
try {
|
|
29
|
-
firstRes = await
|
|
30
|
-
method: 'GET'
|
|
31
|
-
});
|
|
49
|
+
firstRes = await linkedinApiClient.getProfile();
|
|
32
50
|
}
|
|
33
51
|
catch (e) {
|
|
34
52
|
if (e.message === 'Unauthorized') {
|
|
@@ -39,9 +57,7 @@ const destination = {
|
|
|
39
57
|
const userId = firstRes?.data?.id;
|
|
40
58
|
let secondRes;
|
|
41
59
|
try {
|
|
42
|
-
secondRes = await
|
|
43
|
-
method: 'GET'
|
|
44
|
-
});
|
|
60
|
+
secondRes = await linkedinApiClient.getAdAccountUserProfile(settings, userId);
|
|
45
61
|
}
|
|
46
62
|
catch (e) {
|
|
47
63
|
if (e.message === 'Not Found') {
|
|
@@ -73,7 +89,7 @@ const destination = {
|
|
|
73
89
|
return {
|
|
74
90
|
headers: {
|
|
75
91
|
authorization: `Bearer ${auth?.accessToken}`,
|
|
76
|
-
'LinkedIn-Version':
|
|
92
|
+
'LinkedIn-Version': constants_1.LINKEDIN_API_VERSION
|
|
77
93
|
},
|
|
78
94
|
agent
|
|
79
95
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/linkedin-audiences/index.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRo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AAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAElD,OAAO;YACL,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,IAAI,EAAE,WAAW,EAAE;gBAC5C,kBAAkB,EAAE,gCAAoB;aACzC;YACD,KAAK;SACN,CAAA;IACH,CAAC;IAED,OAAO,EAAE;QACP,cAAc,EAAd,wBAAc;KACf;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/destinations/linkedin-audiences/types.ts"],"names":[],"mappings":""}
|
|
@@ -2,9 +2,7 @@ export interface Payload {
|
|
|
2
2
|
dmp_segment_name?: string;
|
|
3
3
|
enable_batching?: boolean;
|
|
4
4
|
email?: string;
|
|
5
|
-
send_email?: boolean;
|
|
6
5
|
google_advertising_id?: string;
|
|
7
|
-
send_google_advertising_id?: boolean;
|
|
8
6
|
source_segment_id?: string;
|
|
9
7
|
personas_audience_key: string;
|
|
10
8
|
event_name?: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const actions_core_1 = require("@segment/actions-core");
|
|
4
4
|
const crypto_1 = require("crypto");
|
|
5
|
-
const
|
|
5
|
+
const api_1 = require("../api");
|
|
6
6
|
const action = {
|
|
7
7
|
title: 'Sync To LinkedIn DMP Segment',
|
|
8
8
|
description: 'Syncs contacts from a Personas Audience to a LinkedIn DMP Segment.',
|
|
@@ -29,12 +29,6 @@ const action = {
|
|
|
29
29
|
'@path': '$.context.traits.email'
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
|
-
send_email: {
|
|
33
|
-
label: 'Send Email',
|
|
34
|
-
description: 'Whether to send `email` to LinkedIn.',
|
|
35
|
-
type: 'boolean',
|
|
36
|
-
default: true
|
|
37
|
-
},
|
|
38
32
|
google_advertising_id: {
|
|
39
33
|
label: 'User Google Advertising ID',
|
|
40
34
|
description: "The user's Google Advertising ID to send to LinkedIn.",
|
|
@@ -43,12 +37,6 @@ const action = {
|
|
|
43
37
|
'@path': '$.context.device.advertisingId'
|
|
44
38
|
}
|
|
45
39
|
},
|
|
46
|
-
send_google_advertising_id: {
|
|
47
|
-
label: 'Send Google Advertising ID',
|
|
48
|
-
description: 'Whether to send Google Advertising ID to LinkedIn.',
|
|
49
|
-
type: 'boolean',
|
|
50
|
-
default: true
|
|
51
|
-
},
|
|
52
40
|
source_segment_id: {
|
|
53
41
|
label: 'LinkedIn Source Segment ID',
|
|
54
42
|
description: "A Segment-specific key associated with the LinkedIn DMP Segment. This is the lookup key Segment uses to fetch the DMP Segment from LinkedIn's API.",
|
|
@@ -80,66 +68,41 @@ const action = {
|
|
|
80
68
|
}
|
|
81
69
|
};
|
|
82
70
|
async function processPayload(request, settings, payloads) {
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
validate(settings, payloads);
|
|
72
|
+
const linkedinApiClient = new api_1.LinkedInAudiences(request);
|
|
73
|
+
const dmpSegmentId = await getDmpSegmentId(linkedinApiClient, settings, payloads[0]);
|
|
74
|
+
const elements = extractUsers(settings, payloads);
|
|
75
|
+
if (elements.length < 1) {
|
|
76
|
+
return;
|
|
85
77
|
}
|
|
86
|
-
const
|
|
87
|
-
const elements = extractUsers(payloads);
|
|
88
|
-
const res = await request(`https://api.linkedin.com/rest/dmpSegments/${dmpSegmentId}/users`, {
|
|
89
|
-
method: 'POST',
|
|
90
|
-
headers: {
|
|
91
|
-
'X-RestLi-Method': 'BATCH_CREATE'
|
|
92
|
-
},
|
|
93
|
-
json: {
|
|
94
|
-
elements
|
|
95
|
-
},
|
|
96
|
-
throwHttpErrors: false
|
|
97
|
-
});
|
|
78
|
+
const res = await linkedinApiClient.batchUpdate(dmpSegmentId, elements);
|
|
98
79
|
if (res.status !== 200) {
|
|
99
80
|
throw new actions_core_1.RetryableError('Error while attempting to update LinkedIn DMP Segment. This batch will be retried.');
|
|
100
81
|
}
|
|
101
82
|
return res;
|
|
102
83
|
}
|
|
103
|
-
|
|
104
|
-
|
|
84
|
+
function validate(settings, payloads) {
|
|
85
|
+
if (payloads[0].source_segment_id !== payloads[0].personas_audience_key) {
|
|
86
|
+
throw new actions_core_1.IntegrationError('The value of `source_segment_id` and `personas_audience_key` must match.', 'Invalid settings.', 400);
|
|
87
|
+
}
|
|
88
|
+
if (!settings.send_google_advertising_id && !settings.send_email) {
|
|
89
|
+
throw new actions_core_1.IntegrationError('At least one of `Send Email` or `Send Google Advertising ID` must be set to `true`.', 'Invalid settings.', 400);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function getDmpSegmentId(linkedinApiClient, settings, payload) {
|
|
93
|
+
const res = await linkedinApiClient.getDmpSegment(settings, payload);
|
|
105
94
|
const body = await res.json();
|
|
106
95
|
if (body.elements?.length > 0) {
|
|
107
96
|
return body.elements[0].id;
|
|
108
97
|
}
|
|
109
|
-
return createDmpSegment(
|
|
98
|
+
return createDmpSegment(linkedinApiClient, settings, payload);
|
|
110
99
|
}
|
|
111
|
-
async function
|
|
112
|
-
|
|
113
|
-
method: 'GET',
|
|
114
|
-
searchParams: {
|
|
115
|
-
q: 'account',
|
|
116
|
-
account: `urn:li:sponsoredAccount:${settings.ad_account_id}`,
|
|
117
|
-
sourceSegmentId: payload.source_segment_id || '',
|
|
118
|
-
sourcePlatform: 'SEGMENT'
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
async function createDmpSegment(request, settings, payload) {
|
|
123
|
-
const res = await request('https://api.linkedin.com/rest/dmpSegments', {
|
|
124
|
-
method: 'POST',
|
|
125
|
-
json: {
|
|
126
|
-
name: payload.dmp_segment_name,
|
|
127
|
-
sourcePlatform: 'SEGMENT',
|
|
128
|
-
sourceSegmentId: payload.source_segment_id,
|
|
129
|
-
account: `urn:li:sponsoredAccount:${settings.ad_account_id}`,
|
|
130
|
-
accessPolicy: 'PRIVATE',
|
|
131
|
-
type: 'USER',
|
|
132
|
-
destinations: [
|
|
133
|
-
{
|
|
134
|
-
destination: 'LINKEDIN'
|
|
135
|
-
}
|
|
136
|
-
]
|
|
137
|
-
}
|
|
138
|
-
});
|
|
100
|
+
async function createDmpSegment(linkedinApiClient, settings, payload) {
|
|
101
|
+
const res = await linkedinApiClient.createDmpSegment(settings, payload);
|
|
139
102
|
const headers = res.headers.toJSON();
|
|
140
103
|
return headers['x-linkedin-id'];
|
|
141
104
|
}
|
|
142
|
-
function extractUsers(payloads) {
|
|
105
|
+
function extractUsers(settings, payloads) {
|
|
143
106
|
const elements = [];
|
|
144
107
|
payloads.forEach((payload) => {
|
|
145
108
|
if (!payload.email && !payload.google_advertising_id) {
|
|
@@ -147,7 +110,7 @@ function extractUsers(payloads) {
|
|
|
147
110
|
}
|
|
148
111
|
elements.push({
|
|
149
112
|
action: getAction(payload),
|
|
150
|
-
userIds: getUserIds(payload)
|
|
113
|
+
userIds: getUserIds(settings, payload)
|
|
151
114
|
});
|
|
152
115
|
});
|
|
153
116
|
return elements;
|
|
@@ -160,15 +123,15 @@ function getAction(payload) {
|
|
|
160
123
|
return 'REMOVE';
|
|
161
124
|
}
|
|
162
125
|
}
|
|
163
|
-
function getUserIds(payload) {
|
|
126
|
+
function getUserIds(settings, payload) {
|
|
164
127
|
const users = [];
|
|
165
|
-
if (payload.email) {
|
|
128
|
+
if (payload.email && settings.send_email === true) {
|
|
166
129
|
users.push({
|
|
167
130
|
idType: 'SHA256_EMAIL',
|
|
168
131
|
idValue: crypto_1.createHash('sha256').update(payload.email).digest('hex')
|
|
169
132
|
});
|
|
170
133
|
}
|
|
171
|
-
if (payload.google_advertising_id) {
|
|
134
|
+
if (payload.google_advertising_id && settings.send_google_advertising_id === true) {
|
|
172
135
|
users.push({
|
|
173
136
|
idType: 'GOOGLE_AID',
|
|
174
137
|
idValue: payload.google_advertising_id
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/linkedin-audiences/updateAudience/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/linkedin-audiences/updateAudience/index.ts"],"names":[],"mappings":";;AACA,wDAAuF;AAGvF,mCAAmC;AACnC,gCAA0C;AAE1C,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,8BAA8B;IACrC,WAAW,EAAE,oEAAoE;IACjF,MAAM,EAAE;QACN,gBAAgB,EAAE;YAChB,KAAK,EAAE,0BAA0B;YACjC,WAAW,EAAE,+CAA+C;YAC5D,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,OAAO,EAAE,2BAA2B;aACrC;SACF;QACD,eAAe,EAAE;YACf,KAAK,EAAE,iBAAiB;YACxB,WAAW,EAAE,0DAA0D;YACvE,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,IAAI;SACd;QACD,KAAK,EAAE;YACL,KAAK,EAAE,YAAY;YACnB,WAAW,EAAE,+CAA+C;YAC5D,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,OAAO,EAAE,wBAAwB;aAClC;SACF;QACD,qBAAqB,EAAE;YACrB,KAAK,EAAE,4BAA4B;YACnC,WAAW,EAAE,uDAAuD;YACpE,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,OAAO,EAAE,gCAAgC;aAC1C;SACF;QACD,iBAAiB,EAAE;YACjB,KAAK,EAAE,4BAA4B;YACnC,WAAW,EACT,oJAAoJ;YACtJ,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,OAAO,EAAE,2BAA2B;aACrC;SACF;QACD,qBAAqB,EAAE;YACrB,KAAK,EAAE,+BAA+B;YACtC,WAAW,EACT,mMAAmM;YACrM,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;SACf;QACD,UAAU,EAAE;YACV,KAAK,EAAE,YAAY;YACnB,WAAW,EAAE,wCAAwC;YACrD,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,OAA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,OAAO,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC;SACvC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,SAAS,SAAS,CAAC,OAAgB;IACjC,IAAI,OAAO,CAAC,UAAU,KAAK,kBAAkB,EAAE;QAC7C,OAAO,KAAK,CAAA;KACb;SAAM,IAAI,OAAO,CAAC,UAAU,KAAK,iBAAiB,EAAE;QACnD,OAAO,QAAQ,CAAA;KAChB;AACH,CAAC;AAED,SAAS,UAAU,CAAC,QAAkB,EAAE,OAAgB;IACtD,MAAM,KAAK,GAAG,EAAE,CAAA;IAEhB,IAAI,OAAO,CAAC,KAAK,IAAI,QAAQ,CAAC,UAAU,KAAK,IAAI,EAAE;QACjD,KAAK,CAAC,IAAI,CAAC;YACT,MAAM,EAAE,cAAc;YACtB,OAAO,EAAE,mBAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAClE,CAAC,CAAA;KACH;IAED,IAAI,OAAO,CAAC,qBAAqB,IAAI,QAAQ,CAAC,0BAA0B,KAAK,IAAI,EAAE;QACjF,KAAK,CAAC,IAAI,CAAC;YACT,MAAM,EAAE,YAAY;YACpB,OAAO,EAAE,OAAO,CAAC,qBAAqB;SACvC,CAAC,CAAA;KACH;IAED,OAAO,KAAK,CAAA;AACd,CAAC;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.112.0",
|
|
4
|
+
"version": "3.112.1-alpha.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/segmentio/action-destinations",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@amplitude/ua-parser-js": "^0.7.25",
|
|
40
40
|
"@segment/a1-notation": "^2.1.4",
|
|
41
|
-
"@segment/actions-core": "^3.40.0",
|
|
42
|
-
"@segment/actions-shared": "^1.23.0",
|
|
41
|
+
"@segment/actions-core": "^3.40.1-alpha.0",
|
|
42
|
+
"@segment/actions-shared": "^1.23.1-alpha.0",
|
|
43
43
|
"cheerio": "^1.0.0-rc.10",
|
|
44
44
|
"dayjs": "^1.10.7",
|
|
45
45
|
"escape-goat": "^3",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"lcov"
|
|
66
66
|
]
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "cb5f41ad164f522aad2cba10059f399864cdf199"
|
|
69
69
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const LINKEDIN_API_VERSION = "202207";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"linkedin-properties.js","sourceRoot":"","sources":["../../../src/destinations/linkedin-audiences/linkedin-properties.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,QAAQ,CAAA"}
|