@segment/action-destinations 3.112.1-alpha.8 → 3.112.1-alpha.9
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/hubspot/index.js +3 -5
- package/dist/destinations/hubspot/index.js.map +1 -1
- package/dist/destinations/hubspot/properties.d.ts +1 -3
- package/dist/destinations/hubspot/properties.js +2 -4
- package/dist/destinations/hubspot/properties.js.map +1 -1
- package/dist/destinations/hubspot/sendCustomBehavioralEvent/index.js +2 -2
- package/dist/destinations/hubspot/sendCustomBehavioralEvent/index.js.map +1 -1
- package/dist/destinations/hubspot/testHelper.d.ts +7 -0
- package/dist/destinations/hubspot/testHelper.js +24 -0
- package/dist/destinations/hubspot/testHelper.js.map +1 -0
- package/dist/destinations/hubspot/upsertContact/index.js +5 -5
- package/dist/destinations/hubspot/upsertContact/index.js.map +1 -1
- package/dist/destinations/hubspot/upsertCustomObjectRecord/index.js +10 -39
- package/dist/destinations/hubspot/upsertCustomObjectRecord/index.js.map +1 -1
- 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 +49 -20
- package/dist/destinations/linkedin-audiences/index.js.map +1 -1
- package/dist/destinations/linkedin-audiences/types.d.ts +28 -0
- package/dist/destinations/linkedin-audiences/types.js +11 -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 +5 -4
- package/dist/destinations/hubspot/errors.d.ts +0 -17
- package/dist/destinations/hubspot/errors.js +0 -30
- package/dist/destinations/hubspot/errors.js.map +0 -1
- package/dist/destinations/hubspot/upsertCompany/generated-types.d.ts +0 -21
- package/dist/destinations/hubspot/upsertCompany/generated-types.js +0 -3
- package/dist/destinations/hubspot/upsertCompany/generated-types.js.map +0 -1
- package/dist/destinations/hubspot/upsertCompany/index.d.ts +0 -5
- package/dist/destinations/hubspot/upsertCompany/index.js +0 -321
- package/dist/destinations/hubspot/upsertCompany/index.js.map +0 -1
- 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
|
@@ -5,21 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const sendCustomBehavioralEvent_1 = __importDefault(require("./sendCustomBehavioralEvent"));
|
|
7
7
|
const upsertContact_1 = __importDefault(require("./upsertContact"));
|
|
8
|
-
const upsertCompany_1 = __importDefault(require("./upsertCompany"));
|
|
9
8
|
const upsertCustomObjectRecord_1 = __importDefault(require("./upsertCustomObjectRecord"));
|
|
10
9
|
const properties_1 = require("./properties");
|
|
11
10
|
const destination = {
|
|
12
|
-
name: '
|
|
11
|
+
name: 'Hubspot Cloud Mode (Actions)',
|
|
13
12
|
slug: 'actions-hubspot-cloud',
|
|
14
13
|
mode: 'cloud',
|
|
15
14
|
authentication: {
|
|
16
15
|
scheme: 'oauth2',
|
|
17
16
|
fields: {},
|
|
18
17
|
testAuthentication: (request) => {
|
|
19
|
-
return request(`${properties_1.
|
|
18
|
+
return request(`${properties_1.hubSpotBaseURL}/crm/v3/objects/contacts?limit=1`);
|
|
20
19
|
},
|
|
21
20
|
refreshAccessToken: async (request, { auth }) => {
|
|
22
|
-
const res = await request(`${properties_1.
|
|
21
|
+
const res = await request(`${properties_1.hubSpotBaseURL}/oauth/v1/token`, {
|
|
23
22
|
method: 'POST',
|
|
24
23
|
body: new URLSearchParams({
|
|
25
24
|
refresh_token: auth.refreshToken,
|
|
@@ -41,7 +40,6 @@ const destination = {
|
|
|
41
40
|
actions: {
|
|
42
41
|
sendCustomBehavioralEvent: sendCustomBehavioralEvent_1.default,
|
|
43
42
|
upsertContact: upsertContact_1.default,
|
|
44
|
-
upsertCompany: upsertCompany_1.default,
|
|
45
43
|
upsertCustomObjectRecord: upsertCustomObjectRecord_1.default
|
|
46
44
|
}
|
|
47
45
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/hubspot/index.ts"],"names":[],"mappings":";;;;;AAGA,4FAAmE;AACnE,oEAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/hubspot/index.ts"],"names":[],"mappings":";;;;;AAGA,4FAAmE;AACnE,oEAA2C;AAC3C,0FAAiE;AACjE,6CAA6C;AAK7C,MAAM,WAAW,GAAoC;IACnD,IAAI,EAAE,8BAA8B;IACpC,IAAI,EAAE,uBAAuB;IAC7B,IAAI,EAAE,OAAO;IAEb,cAAc,EAAE;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,EAAE;QACV,kBAAkB,EAAE,CAAC,OAAO,EAAE,EAAE;YAE9B,OAAO,OAAO,CAAC,GAAG,2BAAc,kCAAkC,CAAC,CAAA;QACrE,CAAC;QACD,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;YAE9C,MAAM,GAAG,GAAG,MAAM,OAAO,CAAuB,GAAG,2BAAc,iBAAiB,EAAE;gBAClF,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,IAAI,eAAe,CAAC;oBACxB,aAAa,EAAE,IAAI,CAAC,YAAY;oBAChC,SAAS,EAAE,IAAI,CAAC,QAAQ;oBACxB,aAAa,EAAE,IAAI,CAAC,YAAY;oBAChC,UAAU,EAAE,eAAe;iBAC5B,CAAC;aACH,CAAC,CAAA;YAEF,OAAO,EAAE,WAAW,EAAE,GAAG,CAAC,IAAI,EAAE,YAAY,EAAE,CAAA;QAChD,CAAC;KACF;IACD,aAAa,CAAC,EAAE,IAAI,EAAE;QACpB,OAAO;YACL,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,IAAI,EAAE,WAAW,EAAE;aAC7C;SACF,CAAA;IACH,CAAC;IAED,OAAO,EAAE;QACP,yBAAyB,EAAzB,mCAAyB;QACzB,aAAa,EAAb,uBAAa;QACb,wBAAwB,EAAxB,kCAAwB;KACzB;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.SEGMENT_UNIQUE_IDENTIFIER = 'segment_group_id';
|
|
6
|
-
exports.ASSOCIATION_TYPE = 'company_to_contact';
|
|
3
|
+
exports.hubSpotBaseURL = void 0;
|
|
4
|
+
exports.hubSpotBaseURL = 'https://api.hubapi.com';
|
|
7
5
|
//# sourceMappingURL=properties.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../../../src/destinations/hubspot/properties.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../../../src/destinations/hubspot/properties.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,wBAAwB,CAAA"}
|
|
@@ -45,7 +45,7 @@ const action = {
|
|
|
45
45
|
},
|
|
46
46
|
properties: {
|
|
47
47
|
label: 'Event Properties',
|
|
48
|
-
description: 'Default or custom properties that describe the event.
|
|
48
|
+
description: 'Default or custom properties that describe the event. See more information in [HubSpot’s documentation](https://knowledge.hubspot.com/analytics-tools/create-custom-behavioral-events#add-and-manage-event-properties).',
|
|
49
49
|
type: 'object',
|
|
50
50
|
defaultObjectUI: 'keyvalue:only'
|
|
51
51
|
}
|
|
@@ -59,7 +59,7 @@ const action = {
|
|
|
59
59
|
objectId: payload.objectId,
|
|
60
60
|
properties: payload.properties
|
|
61
61
|
};
|
|
62
|
-
return request(`${properties_1.
|
|
62
|
+
return request(`${properties_1.hubSpotBaseURL}/events/v3/send`, {
|
|
63
63
|
method: 'post',
|
|
64
64
|
json: event
|
|
65
65
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/hubspot/sendCustomBehavioralEvent/index.ts"],"names":[],"mappings":";;AAEA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/hubspot/sendCustomBehavioralEvent/index.ts"],"names":[],"mappings":";;AAEA,8CAA8C;AAY9C,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,8BAA8B;IACrC,WAAW,EAAE,4CAA4C;IACzD,mBAAmB,EAAE,gBAAgB;IACrC,MAAM,EAAE;QACN,SAAS,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,WAAW,EACT,gRAAgR;YAClR,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;SACf;QACD,UAAU,EAAE;YACV,KAAK,EAAE,iBAAiB;YACxB,WAAW,EAAE,sFAAsF;YACnG,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE;gBACP,OAAO,EAAE,aAAa;aACvB;SACF;QACD,KAAK,EAAE;YACL,KAAK,EAAE,eAAe;YACtB,WAAW,EACT,kHAAkH;YACpH,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,KAAK,EAAE;oBACL,MAAM,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;oBACzC,IAAI,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;oBACvC,IAAI,EAAE,EAAE,OAAO,EAAE,wBAAwB,EAAE;iBAC5C;aACF;SACF;QACD,GAAG,EAAE;YACH,KAAK,EAAE,YAAY;YACnB,WAAW,EACT,wHAAwH;YAC1H,IAAI,EAAE,QAAQ;SACf;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,WAAW;YAClB,WAAW,EACT,qLAAqL;YACvL,IAAI,EAAE,QAAQ;SACf;QACD,UAAU,EAAE;YACV,KAAK,EAAE,kBAAkB;YACzB,WAAW,EACT,yNAAyN;YAC3N,IAAI,EAAE,QAAQ;YACd,eAAe,EAAE,eAAe;SACjC;KACF;IACD,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAChC,MAAM,KAAK,GAA0B;YACnC,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAA;QACD,OAAO,OAAO,CAAC,GAAG,2BAAc,iBAAiB,EAAE;YACjD,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,KAAK;SACZ,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateValidHubSpotCustomObjectName = void 0;
|
|
4
|
+
const generateHash = (seed) => {
|
|
5
|
+
let i, chr, hash;
|
|
6
|
+
hash = 0;
|
|
7
|
+
if (seed.length === 0)
|
|
8
|
+
return hash;
|
|
9
|
+
for (i = 0; i < seed.length; i++) {
|
|
10
|
+
chr = seed.charCodeAt(i);
|
|
11
|
+
hash = (hash << 5) - hash + chr;
|
|
12
|
+
hash |= 0;
|
|
13
|
+
}
|
|
14
|
+
return Math.abs(hash);
|
|
15
|
+
};
|
|
16
|
+
const generateValidHubSpotCustomObjectName = (seed) => {
|
|
17
|
+
const hash = generateHash(seed);
|
|
18
|
+
return {
|
|
19
|
+
objectType: `p${hash}_Obj${hash}`,
|
|
20
|
+
properties: { testProperty: `testValue-${hash}` }
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.generateValidHubSpotCustomObjectName = generateValidHubSpotCustomObjectName;
|
|
24
|
+
//# sourceMappingURL=testHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testHelper.js","sourceRoot":"","sources":["../../../src/destinations/hubspot/testHelper.ts"],"names":[],"mappings":";;;AAAA,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,EAAE;IACpC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAA;IAChB,IAAI,GAAG,CAAC,CAAA;IAER,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAClC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAChC,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QACxB,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,CAAA;QAC/B,IAAI,IAAI,CAAC,CAAA;KACV;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AACvB,CAAC,CAAA;AAED,MAAM,oCAAoC,GAAG,CAAC,IAAY,EAAE,EAAE;IAC5D,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IAC/B,OAAO;QACL,UAAU,EAAE,IAAI,IAAI,OAAO,IAAI,EAAE;QACjC,UAAU,EAAE,EAAE,YAAY,EAAE,aAAa,IAAI,EAAE,EAAE;KAClD,CAAA;AACH,CAAC,CAAA;AACQ,oFAAoC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
3
4
|
const properties_1 = require("../properties");
|
|
4
5
|
const action = {
|
|
5
6
|
title: 'Upsert Contact',
|
|
@@ -116,7 +117,7 @@ const action = {
|
|
|
116
117
|
properties: {
|
|
117
118
|
label: 'Other properties',
|
|
118
119
|
type: 'object',
|
|
119
|
-
description: 'Any other default or custom contact properties.
|
|
120
|
+
description: 'Any other default or custom contact properties. Custom properties must be predefined in HubSpot. See more information in [HubSpot’s documentation](https://knowledge.hubspot.com/crm-setup/manage-your-properties#create-custom-properties).',
|
|
120
121
|
defaultObjectUI: 'keyvalue:only'
|
|
121
122
|
}
|
|
122
123
|
},
|
|
@@ -132,7 +133,6 @@ const action = {
|
|
|
132
133
|
country: payload.country,
|
|
133
134
|
zip: payload.zip,
|
|
134
135
|
email: payload.email,
|
|
135
|
-
website: payload.website,
|
|
136
136
|
lifecyclestage: payload.lifecyclestage?.toLowerCase(),
|
|
137
137
|
...payload.properties
|
|
138
138
|
};
|
|
@@ -150,7 +150,7 @@ const action = {
|
|
|
150
150
|
return response;
|
|
151
151
|
}
|
|
152
152
|
catch (ex) {
|
|
153
|
-
if (ex
|
|
153
|
+
if (ex instanceof actions_core_1.HTTPError && ex.response.status == 404) {
|
|
154
154
|
const result = await createContact(request, contactProperties);
|
|
155
155
|
transactionContext?.setTransaction('contact_id', result.data.id);
|
|
156
156
|
return result;
|
|
@@ -160,7 +160,7 @@ const action = {
|
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
162
|
async function createContact(request, contactProperties) {
|
|
163
|
-
return request(`${properties_1.
|
|
163
|
+
return request(`${properties_1.hubSpotBaseURL}/crm/v3/objects/contacts`, {
|
|
164
164
|
method: 'POST',
|
|
165
165
|
json: {
|
|
166
166
|
properties: {
|
|
@@ -170,7 +170,7 @@ async function createContact(request, contactProperties) {
|
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
async function updateContact(request, email, properties) {
|
|
173
|
-
return request(`${properties_1.
|
|
173
|
+
return request(`${properties_1.hubSpotBaseURL}/crm/v3/objects/contacts/${email}?idProperty=email`, {
|
|
174
174
|
method: 'PATCH',
|
|
175
175
|
json: {
|
|
176
176
|
properties: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/hubspot/upsertContact/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/hubspot/upsertContact/index.ts"],"names":[],"mappings":";;AAAA,wDAAiD;AAGjD,8CAA8C;AAQ9C,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,gBAAgB;IACvB,WAAW,EAAE,wCAAwC;IACrD,mBAAmB,EAAE,mBAAmB;IACxC,MAAM,EAAE;QACN,KAAK,EAAE;YACL,KAAK,EAAE,OAAO;YACd,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,2NAA2N;YAC7N,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,OAAO,EAAE,gBAAgB;aAC1B;SACF;QACD,OAAO,EAAE;YACP,KAAK,EAAE,cAAc;YACrB,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,wBAAwB;YACrC,OAAO,EAAE;gBACP,OAAO,EAAE,kBAAkB;aAC5B;SACF;QACD,SAAS,EAAE;YACT,KAAK,EAAE,YAAY;YACnB,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,2BAA2B;YACxC,OAAO,EAAE;gBACP,KAAK,EAAE;oBACL,MAAM,EAAE,EAAE,OAAO,EAAE,qBAAqB,EAAE;oBAC1C,IAAI,EAAE,EAAE,OAAO,EAAE,qBAAqB,EAAE;oBACxC,IAAI,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE;iBACxC;aACF;SACF;Q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UAAU,EAAE;gBACV,GAAG,UAAU;aACd;SACF;KACF,CAAC,CAAA;AACJ,CAAC;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
4
|
+
const hubspotDefinedObjects = ['deals', 'tickets'];
|
|
5
|
+
const customObjectExpression = new RegExp('^[a-zA-Z0-9]+_[a-zA-Z][a-zA-Z0-9_-]+$');
|
|
4
6
|
const action = {
|
|
5
7
|
title: 'Create Custom Object Record',
|
|
6
8
|
description: 'Create records in any HubSpot standard or custom object.',
|
|
7
9
|
fields: {
|
|
8
10
|
objectType: {
|
|
9
11
|
label: 'Object Type',
|
|
10
|
-
description: 'The CRM object schema to use for creating a record. This can be a standard object (i.e. tickets, deals) or ***fullyQualifiedName*** of a custom object. Schema for the Custom Objects must be predefined in HubSpot. More information on Custom Objects and *fullyQualifiedName* in [HubSpot documentation](https://developers.hubspot.com/docs/
|
|
12
|
+
description: 'The CRM object schema to use for creating a record. This can be a standard object (i.e. tickets, deals) or ***fullyQualifiedName*** of a custom object. Schema for the Custom Objects must be predefined in HubSpot. More information on Custom Objects and *fullyQualifiedName* in [HubSpot documentation](https://developers.hubspot.com/docs/cms/data/crm-objects#getting-a-custom-object-type-s-details).',
|
|
11
13
|
type: 'string',
|
|
12
|
-
required: true
|
|
13
|
-
dynamic: true
|
|
14
|
+
required: true
|
|
14
15
|
},
|
|
15
16
|
properties: {
|
|
16
17
|
label: 'Properties',
|
|
17
|
-
description: 'Properties to send to HubSpot.
|
|
18
|
+
description: 'Properties to send to HubSpot. Please make sure to include the object’s required properties. Any custom properties must be predefined in HubSpot. More information in [HubSpot documentation](https://knowledge.hubspot.com/crm-setup/manage-your-properties#create-custom-properties).',
|
|
18
19
|
type: 'object',
|
|
19
20
|
required: true,
|
|
20
21
|
defaultObjectUI: 'keyvalue:only',
|
|
21
22
|
allowNull: false
|
|
22
23
|
}
|
|
23
24
|
},
|
|
24
|
-
dynamicFields: {
|
|
25
|
-
objectType: async (request, _) => {
|
|
26
|
-
return getCustomObjects(request);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
25
|
perform: async (request, { payload }) => {
|
|
30
|
-
|
|
26
|
+
if (!customObjectExpression.test(payload.objectType) && !hubspotDefinedObjects.includes(payload.objectType)) {
|
|
27
|
+
throw new actions_core_1.IntegrationError('Custom Object is not in valid format. Please make sure that you are using either a valid format of object’s fullyQualifiedName (eg: p11223344_myobject) or a supported HubSpot defined object (i.e.: deals, tickets).', 'Custom Object is not in valid format', 400);
|
|
28
|
+
}
|
|
29
|
+
return request(`https://api.hubapi.com/crm/v3/objects/${payload.objectType}`, {
|
|
31
30
|
method: 'POST',
|
|
32
31
|
json: {
|
|
33
32
|
properties: { ...payload.properties }
|
|
@@ -35,33 +34,5 @@ const action = {
|
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
|
-
async function getCustomObjects(request) {
|
|
39
|
-
const defaultChoices = [
|
|
40
|
-
{ value: 'deals', label: 'Deals' },
|
|
41
|
-
{ value: 'tickets', label: 'Tickets' }
|
|
42
|
-
];
|
|
43
|
-
try {
|
|
44
|
-
const response = await request(`${properties_1.HUBSPOT_BASE_URL}/crm/v3/schemas?archived=false`, {
|
|
45
|
-
method: 'GET',
|
|
46
|
-
skipResponseCloning: true
|
|
47
|
-
});
|
|
48
|
-
const choices = response.data.results.map((schema) => ({
|
|
49
|
-
label: schema.labels.plural,
|
|
50
|
-
value: schema.fullyQualifiedName
|
|
51
|
-
}));
|
|
52
|
-
return {
|
|
53
|
-
choices: [...choices, ...defaultChoices]
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
return {
|
|
58
|
-
choices: [],
|
|
59
|
-
error: {
|
|
60
|
-
message: err?.response?.data?.message ?? 'Unknown error',
|
|
61
|
-
code: err?.response?.data?.category ?? 'Unknown code'
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
37
|
exports.default = action;
|
|
67
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/hubspot/upsertCustomObjectRecord/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/hubspot/upsertCustomObjectRecord/index.ts"],"names":[],"mappings":";;AACA,wDAAwD;AAKxD,MAAM,qBAAqB,GAAa,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;AAK5D,MAAM,sBAAsB,GAAG,IAAI,MAAM,CAAC,uCAAuC,CAAC,CAAA;AAIlF,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,6BAA6B;IACpC,WAAW,EAAE,0DAA0D;IACvE,MAAM,EAAE;QACN,UAAU,EAAE;YACV,KAAK,EAAE,aAAa;YACpB,WAAW,EACT,+YAA+Y;YACjZ,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;SACf;QACD,UAAU,EAAE;YACV,KAAK,EAAE,YAAY;YACnB,WAAW,EACT,yRAAyR;YAC3R,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,eAAe,EAAE,eAAe;YAChC,SAAS,EAAE,KAAK;SACjB;KACF;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAEtC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC3G,MAAM,IAAI,+BAAgB,CACxB,uNAAuN,EACvN,sCAAsC,EACtC,GAAG,CACJ,CAAA;SACF;QAED,OAAO,OAAO,CAAC,yCAAyC,OAAO,CAAC,UAAU,EAAE,EAAE;YAC5E,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,UAAU,EAAE,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE;aACtC;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -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,CAAC,aAAa,CAAC,QAAkB,EAAE,OAAgB;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,oBAAQ,cAAc,EAAE;YAC7C,MAAM,EAAE,KAAK;YACb,YAAY,EAAE;gBACZ,CAAC,EAAE,SAAS;gBACZ,OAAO,EAAE,2BAA2B,QAAQ,CAAC,aAAa,EAAE;gBAC5D,eAAe,EAAE,OAAO,CAAC,iBAAiB,IAAI,EAAE;gBAChD,cAAc,EAAE,SAAS;aAC1B;SACF,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,QAAkB,EAAE,OAAgB;QACzD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,oBAAQ,cAAc,EAAE;YAC7C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,IAAI,EAAE,OAAO,CAAC,gBAAgB;gBAC9B,cAAc,EAAE,SAAS;gBACzB,eAAe,EAAE,OAAO,CAAC,iBAAiB;gBAC1C,OAAO,EAAE,2BAA2B,QAAQ,CAAC,aAAa,EAAE;gBAC5D,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,MAAM;gBACZ,YAAY,EAAE;oBACZ;wBACE,WAAW,EAAE,UAAU;qBACxB;iBACF;aACF;SACF,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,YAAoB,EAAE,QAAkC;QACxE,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,oBAAQ,gBAAgB,YAAY,QAAQ,EAAE;YACnE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,iBAAiB,EAAE,cAAc;aAClC;YACD,IAAI,EAAE;gBACJ,QAAQ;aACT;YACD,eAAe,EAAE,KAAK;SACvB,CAAC,CAAA;IACJ,CAAC;CACF;AAjED,8CAiEC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BASE_URL = exports.LINKEDIN_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,12 @@ 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");
|
|
11
|
+
const actions_core_2 = require("@segment/actions-core");
|
|
9
12
|
const destination = {
|
|
10
13
|
name: 'Linkedin Audiences',
|
|
11
14
|
slug: 'actions-linkedin-audiences',
|
|
@@ -18,20 +21,37 @@ const destination = {
|
|
|
18
21
|
description: 'The id of the LinkedIn Ad Account where batches should be synced.',
|
|
19
22
|
type: 'string',
|
|
20
23
|
required: true
|
|
24
|
+
},
|
|
25
|
+
send_email: {
|
|
26
|
+
label: 'Send Email',
|
|
27
|
+
description: 'Whether to send `email` to LinkedIn. This setting applies to all mappings you create in this destination instance.',
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
default: true,
|
|
30
|
+
required: true
|
|
31
|
+
},
|
|
32
|
+
send_google_advertising_id: {
|
|
33
|
+
label: 'Send Google Advertising ID',
|
|
34
|
+
description: 'Whether to send Google Advertising ID to LinkedIn. This setting applies to all mappings you create in this destination instance.',
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
default: true,
|
|
37
|
+
required: true
|
|
21
38
|
}
|
|
22
39
|
},
|
|
23
40
|
testAuthentication: async (request, { settings, auth }) => {
|
|
24
41
|
if (!auth?.accessToken) {
|
|
25
|
-
throw new
|
|
42
|
+
throw new actions_core_1.InvalidAuthenticationError('Please authenticate via Oauth before updating other settings and/or enabling the destination.');
|
|
26
43
|
}
|
|
44
|
+
if (!settings.send_email && !settings.send_google_advertising_id) {
|
|
45
|
+
throw new Error('At least one of `Send Email` or `Send Google Advertising ID` must be set to `true`.');
|
|
46
|
+
}
|
|
47
|
+
const linkedinApiClient = new api_1.LinkedInAudiences(request);
|
|
27
48
|
let firstRes;
|
|
28
49
|
try {
|
|
29
|
-
firstRes = await
|
|
30
|
-
method: 'GET'
|
|
31
|
-
});
|
|
50
|
+
firstRes = await linkedinApiClient.getProfile();
|
|
32
51
|
}
|
|
33
52
|
catch (e) {
|
|
34
|
-
|
|
53
|
+
const error = e;
|
|
54
|
+
if (error.message === 'Unauthorized') {
|
|
35
55
|
throw new Error('Invalid LinkedIn Oauth access token. Please reauthenticate to retrieve a valid access token before updating other settings and/or enabling the destination.');
|
|
36
56
|
}
|
|
37
57
|
throw e;
|
|
@@ -39,12 +59,11 @@ const destination = {
|
|
|
39
59
|
const userId = firstRes?.data?.id;
|
|
40
60
|
let secondRes;
|
|
41
61
|
try {
|
|
42
|
-
secondRes = await
|
|
43
|
-
method: 'GET'
|
|
44
|
-
});
|
|
62
|
+
secondRes = await linkedinApiClient.getAdAccountUserProfile(settings, userId);
|
|
45
63
|
}
|
|
46
64
|
catch (e) {
|
|
47
|
-
|
|
65
|
+
const error = e;
|
|
66
|
+
if (error.message === 'Not Found') {
|
|
48
67
|
throw new Error('Invalid LinkedIn Ad Account id. Please verify that the LinkedIn Ad Account exists and that you have access to it.');
|
|
49
68
|
}
|
|
50
69
|
throw e;
|
|
@@ -56,15 +75,25 @@ const destination = {
|
|
|
56
75
|
return true;
|
|
57
76
|
},
|
|
58
77
|
refreshAccessToken: async (request, { auth }) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
let res;
|
|
79
|
+
try {
|
|
80
|
+
res = await request('https://www.linkedin.com/oauth/v2/accessToken', {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
body: new URLSearchParams({
|
|
83
|
+
refresh_token: auth.refreshToken,
|
|
84
|
+
client_id: auth.clientId,
|
|
85
|
+
client_secret: auth.clientSecret,
|
|
86
|
+
grant_type: 'refresh_token'
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
const error = e;
|
|
92
|
+
if (error.response?.data?.error === 'invalid_grant') {
|
|
93
|
+
throw new actions_core_2.IntegrationError(`Invalid Authentication: Your refresh token is invalid or expired. Please re-authenticate to fetch a new refresh token.`, 'REFRESH_TOKEN_EXPIRED', 401);
|
|
94
|
+
}
|
|
95
|
+
throw new actions_core_2.IntegrationError(`Failed to fetch a new access token. Reason: ${error.response?.data?.error}`, 'OAUTH_REFRESH_FAILED', 401);
|
|
96
|
+
}
|
|
68
97
|
return { accessToken: res?.data?.access_token };
|
|
69
98
|
}
|
|
70
99
|
},
|
|
@@ -73,7 +102,7 @@ const destination = {
|
|
|
73
102
|
return {
|
|
74
103
|
headers: {
|
|
75
104
|
authorization: `Bearer ${auth?.accessToken}`,
|
|
76
|
-
'LinkedIn-Version':
|
|
105
|
+
'LinkedIn-Version': constants_1.LINKEDIN_API_VERSION
|
|
77
106
|
},
|
|
78
107
|
agent
|
|
79
108
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/linkedin-audiences/index.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/linkedin-audiences/index.ts"],"names":[],"mappings":";;;;;AACA,wDAAkE;AAElE,sEAA6C;AAC7C,2CAAkD;AAClD,kDAAyB;AACzB,+BAAyC;AASzC,wDAAwD;AAExD,MAAM,WAAW,GAAoC;IAEnD,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,4BAA4B;IAClC,IAAI,EAAE,OAAO;IAEb,cAAc,EAAE;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE;YACN,aAAa,EAAE;gBACb,KAAK,EAAE,wBAAwB;gBAC/B,WAAW,EAAE,mEAAmE;gBAChF,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,IAAI;aACf;YACD,UAAU,EAAE;gBACV,KAAK,EAAE,YAAY;gBACnB,WAAW,EACT,oHAAoH;gBACtH,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,IAAI;aACf;YACD,0BAA0B,EAAE;gBAC1B,KAAK,EAAE,4BAA4B;gBACnC,WAAW,EACT,kIAAkI;gBACpI,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AC;IAED,OAAO,EAAE;QACP,cAAc,EAAd,wBAAc;KACf;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { HTTPError } from '@segment/actions-core';
|
|
2
|
+
export interface RefreshTokenResponse {
|
|
3
|
+
access_token: string;
|
|
4
|
+
scope: string;
|
|
5
|
+
expires_in: number;
|
|
6
|
+
token_type: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ProfileAPIResponse {
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
export interface AdAccountUserResponse {
|
|
12
|
+
role: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class LinkedInRefreshTokenError extends HTTPError {
|
|
15
|
+
response: Response & {
|
|
16
|
+
data: {
|
|
17
|
+
error: string;
|
|
18
|
+
error_description: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare class LinkedInTestAuthenticationError extends HTTPError {
|
|
23
|
+
response: Response & {
|
|
24
|
+
data: {
|
|
25
|
+
message: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LinkedInTestAuthenticationError = exports.LinkedInRefreshTokenError = void 0;
|
|
4
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
5
|
+
class LinkedInRefreshTokenError extends actions_core_1.HTTPError {
|
|
6
|
+
}
|
|
7
|
+
exports.LinkedInRefreshTokenError = LinkedInRefreshTokenError;
|
|
8
|
+
class LinkedInTestAuthenticationError extends actions_core_1.HTTPError {
|
|
9
|
+
}
|
|
10
|
+
exports.LinkedInTestAuthenticationError = LinkedInTestAuthenticationError;
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/destinations/linkedin-audiences/types.ts"],"names":[],"mappings":";;;AAAA,wDAAiD;AAiBjD,MAAa,yBAA0B,SAAQ,wBAAS;CAOvD;AAPD,8DAOC;AAED,MAAa,+BAAgC,SAAQ,wBAAS;CAM7D;AAND,0EAMC"}
|
|
@@ -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;
|