@segment/action-destinations 3.421.1-staging-a34dd23ea.0 → 3.421.1-staging-6aa9713b5.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/cordial/cordial-client.js +12 -3
- package/dist/destinations/cordial/cordial-client.js.map +1 -1
- package/dist/destinations/cordial/upsertOrder/generated-types.d.ts +4 -0
- package/dist/destinations/cordial/upsertOrder/index.js +35 -8
- package/dist/destinations/cordial/upsertOrder/index.js.map +1 -1
- package/dist/destinations/google-data-manager/constants.d.ts +6 -0
- package/dist/destinations/google-data-manager/constants.js +10 -0
- package/dist/destinations/google-data-manager/constants.js.map +1 -0
- package/dist/destinations/google-data-manager/errors.d.ts +3 -0
- package/dist/destinations/google-data-manager/errors.js +54 -0
- package/dist/destinations/google-data-manager/errors.js.map +1 -0
- package/dist/destinations/google-data-manager/functions.d.ts +6 -0
- package/dist/destinations/google-data-manager/functions.js +85 -0
- package/dist/destinations/google-data-manager/functions.js.map +1 -0
- package/dist/destinations/google-data-manager/generated-types.d.ts +9 -0
- package/dist/destinations/google-data-manager/index.d.ts +3 -3
- package/dist/destinations/google-data-manager/index.js +180 -32
- package/dist/destinations/google-data-manager/index.js.map +1 -1
- package/dist/destinations/google-data-manager/properties.d.ts +12 -0
- package/dist/destinations/google-data-manager/properties.js +104 -0
- package/dist/destinations/google-data-manager/properties.js.map +1 -0
- package/dist/destinations/google-data-manager/shared.d.ts +17 -0
- package/dist/destinations/google-data-manager/shared.js +42 -0
- package/dist/destinations/google-data-manager/shared.js.map +1 -0
- package/dist/destinations/google-data-manager/syncUserData/generated-types.d.ts +11 -0
- package/dist/destinations/google-data-manager/syncUserData/generated-types.js.map +1 -0
- package/dist/destinations/google-data-manager/{remove → syncUserData}/index.d.ts +1 -1
- package/dist/destinations/google-data-manager/syncUserData/index.js +28 -0
- package/dist/destinations/google-data-manager/syncUserData/index.js.map +1 -0
- package/dist/destinations/google-data-manager/types.d.ts +16 -0
- package/dist/destinations/google-data-manager/{remove/generated-types.js → types.js} +1 -1
- package/dist/destinations/google-data-manager/types.js.map +1 -0
- package/dist/destinations/index.js +1 -1
- package/dist/destinations/index.js.map +1 -1
- package/dist/destinations/kafka/utils.d.ts +1 -1
- package/dist/destinations/kafka/utils.js +11 -14
- package/dist/destinations/kafka/utils.js.map +1 -1
- package/dist/destinations/klaviyo/functions.js +0 -14
- package/dist/destinations/klaviyo/functions.js.map +1 -1
- package/dist/destinations/klaviyo/upsertProfile/index.js +1 -7
- package/dist/destinations/klaviyo/upsertProfile/index.js.map +1 -1
- package/dist/destinations/ms-bing-ads-audiences/generated-types.d.ts +0 -3
- package/dist/destinations/ms-bing-ads-audiences/index.d.ts +1 -1
- package/dist/destinations/ms-bing-ads-audiences/index.js +3 -82
- package/dist/destinations/ms-bing-ads-audiences/index.js.map +1 -1
- package/dist/destinations/taguchi/syncUserProfile/fields.js +1 -1
- package/dist/destinations/taguchi/syncUserProfile/fields.js.map +1 -1
- package/dist/destinations/twilio-messaging/sendMessage/fields.js +0 -2
- package/dist/destinations/twilio-messaging/sendMessage/fields.js.map +1 -1
- package/package.json +2 -2
- package/dist/destinations/google-data-manager/ingest/generated-types.d.ts +0 -2
- package/dist/destinations/google-data-manager/ingest/generated-types.js.map +0 -1
- package/dist/destinations/google-data-manager/ingest/index.d.ts +0 -5
- package/dist/destinations/google-data-manager/ingest/index.js +0 -12
- package/dist/destinations/google-data-manager/ingest/index.js.map +0 -1
- package/dist/destinations/google-data-manager/remove/generated-types.d.ts +0 -2
- package/dist/destinations/google-data-manager/remove/generated-types.js.map +0 -1
- package/dist/destinations/google-data-manager/remove/index.js +0 -12
- package/dist/destinations/google-data-manager/remove/index.js.map +0 -1
- /package/dist/destinations/google-data-manager/{ingest → syncUserData}/generated-types.js +0 -0
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
3
7
|
class CordialClient {
|
|
4
8
|
constructor(settings, request) {
|
|
5
9
|
this.apiUrl = `${settings.endpoint}/api/segment`;
|
|
6
10
|
this.request = request;
|
|
7
11
|
this.identityKeys = {
|
|
8
|
-
segmentIdKey: settings.segmentIdKey
|
|
12
|
+
segmentIdKey: settings.segmentIdKey
|
|
9
13
|
};
|
|
10
14
|
}
|
|
11
15
|
extractIdentities(payload) {
|
|
12
16
|
return {
|
|
13
17
|
segmentId: payload.segmentId,
|
|
14
18
|
anonymousId: payload.anonymousId,
|
|
15
|
-
userIdentities: payload.userIdentities
|
|
19
|
+
userIdentities: payload.userIdentities
|
|
16
20
|
};
|
|
17
21
|
}
|
|
18
22
|
async addContactActivity(payload) {
|
|
@@ -100,7 +104,12 @@ class CordialClient {
|
|
|
100
104
|
status: payload.status,
|
|
101
105
|
totalAmount: payload.totalAmount,
|
|
102
106
|
properties: payload.properties,
|
|
103
|
-
items: payload.items
|
|
107
|
+
items: payload.items,
|
|
108
|
+
discountApplication: !(0, isEmpty_1.default)(payload.discountApplication) &&
|
|
109
|
+
payload?.discountApplication?.type === 'fixed' &&
|
|
110
|
+
payload?.discountApplication?.amount
|
|
111
|
+
? payload.discountApplication
|
|
112
|
+
: null
|
|
104
113
|
}
|
|
105
114
|
});
|
|
106
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cordial-client.js","sourceRoot":"","sources":["../../../src/destinations/cordial/cordial-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cordial-client.js","sourceRoot":"","sources":["../../../src/destinations/cordial/cordial-client.ts"],"names":[],"mappings":";;;;;AAUA,6DAAoC;AAUpC,MAAM,aAAa;IAKjB,YAAY,QAAkB,EAAE,OAAsB;QACpD,IAAI,CAAC,MAAM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AAE,OAAO,CAAC,SAAS;gBAC5B,UAAU,EAAE,OAAO,CAAC,UAAU;aAC/B;SACF,CAAC,CAAA;IACJ,CAAC;CACF;AAED,kBAAe,aAAa,CAAA"}
|
|
@@ -47,6 +47,33 @@ const action = {
|
|
|
47
47
|
'@path': '$.properties.total'
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
+
discountApplication: {
|
|
51
|
+
label: 'Discount application',
|
|
52
|
+
description: "Discount application data, allowed fields: type (only 'fixed' as of now), amount (float discount amount, e.g. 10.45)",
|
|
53
|
+
type: 'object',
|
|
54
|
+
required: false,
|
|
55
|
+
default: {
|
|
56
|
+
type: 'fixed',
|
|
57
|
+
amount: { '@path': '$.properties.discount' }
|
|
58
|
+
},
|
|
59
|
+
properties: {
|
|
60
|
+
type: {
|
|
61
|
+
label: 'Type',
|
|
62
|
+
description: 'Type of discount applied to the order (e.g. fixed)',
|
|
63
|
+
type: 'string',
|
|
64
|
+
required: false,
|
|
65
|
+
placeholder: 'fixed',
|
|
66
|
+
choices: [{ value: 'fixed', label: 'fixed' }]
|
|
67
|
+
},
|
|
68
|
+
amount: {
|
|
69
|
+
label: 'Amount',
|
|
70
|
+
description: 'Amount of the discount applied to the order',
|
|
71
|
+
type: 'number',
|
|
72
|
+
required: false,
|
|
73
|
+
placeholder: '0.0'
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
50
77
|
properties: {
|
|
51
78
|
label: 'Order properties',
|
|
52
79
|
description: 'Additional order properties (e.g. affiliation/tax/revenue)',
|
|
@@ -96,32 +123,32 @@ const action = {
|
|
|
96
123
|
manufacturerName: {
|
|
97
124
|
label: 'Manufacturer name',
|
|
98
125
|
description: 'Manufacturer name of the purchased item.',
|
|
99
|
-
type: 'string'
|
|
126
|
+
type: 'string'
|
|
100
127
|
},
|
|
101
128
|
itemPrice: {
|
|
102
129
|
label: 'Price',
|
|
103
130
|
description: 'Price of the purchased item.',
|
|
104
|
-
type: 'number'
|
|
131
|
+
type: 'number'
|
|
105
132
|
},
|
|
106
133
|
qty: {
|
|
107
134
|
label: 'Quantity',
|
|
108
135
|
description: 'Quantity of the purchased item.',
|
|
109
|
-
type: 'integer'
|
|
136
|
+
type: 'integer'
|
|
110
137
|
},
|
|
111
138
|
url: {
|
|
112
139
|
label: 'URL',
|
|
113
140
|
description: 'URL of the purchased item.',
|
|
114
|
-
type: 'string'
|
|
141
|
+
type: 'string'
|
|
115
142
|
},
|
|
116
143
|
imageUrl: {
|
|
117
144
|
label: 'Image URL',
|
|
118
145
|
description: 'Image URL of the purchased item.',
|
|
119
|
-
type: 'string'
|
|
146
|
+
type: 'string'
|
|
120
147
|
},
|
|
121
148
|
properties: {
|
|
122
149
|
label: 'Properties',
|
|
123
150
|
description: 'Additional properties of the purchased item.',
|
|
124
|
-
type: 'object'
|
|
151
|
+
type: 'object'
|
|
125
152
|
}
|
|
126
153
|
},
|
|
127
154
|
default: {
|
|
@@ -158,12 +185,12 @@ const action = {
|
|
|
158
185
|
properties: {
|
|
159
186
|
variant: { '@path': '$.variant' },
|
|
160
187
|
coupon: { '@path': '$.coupon' }
|
|
161
|
-
}
|
|
188
|
+
}
|
|
162
189
|
}
|
|
163
190
|
]
|
|
164
191
|
},
|
|
165
192
|
defaultObjectUI: 'keyvalue:only'
|
|
166
|
-
}
|
|
193
|
+
}
|
|
167
194
|
},
|
|
168
195
|
perform: (request, { settings, payload }) => {
|
|
169
196
|
const client = new cordial_client_1.default(settings, request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/cordial/upsertOrder/index.ts"],"names":[],"mappings":";;;;;AAGA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/cordial/upsertOrder/index.ts"],"names":[],"mappings":";;;;;AAGA,uEAA6C;AAC7C,6EAAqD;AAErD,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,cAAc;IACrB,WAAW,EAAE,0BAA0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EAAE,aAAa;yBACvB;wBACD,UAAU,EAAE;4BACV,OAAO,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE;4BACjC,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;yBAChC;qBACF;iBACF;aACF;YACD,eAAe,EAAE,eAAe;SACjC;KACF;IACD,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;QAC1C,MAAM,MAAM,GAAG,IAAI,wBAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QACnD,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;IACpC,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const GOOGLE_API_VERSION = "v2";
|
|
2
|
+
export declare const BASE_URL = "https://audiencepartner.googleapis.com/v2/products/GOOGLE_ADS/customers/advertiserID/";
|
|
3
|
+
export declare const CREATE_AUDIENCE_URL = "https://audiencepartner.googleapis.com/v2/products/GOOGLE_ADS/customers/advertiserID/userLists:mutate";
|
|
4
|
+
export declare const GET_AUDIENCE_URL = "https://audiencepartner.googleapis.com/v2/products/GOOGLE_ADS/customers/advertiserID/audiencePartner:searchStream";
|
|
5
|
+
export declare const OAUTH_URL = "https://accounts.google.com/o/oauth2/token";
|
|
6
|
+
export declare const SEGMENT_DATA_PARTNER_ID = "8152223833";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SEGMENT_DATA_PARTNER_ID = exports.OAUTH_URL = exports.GET_AUDIENCE_URL = exports.CREATE_AUDIENCE_URL = exports.BASE_URL = exports.GOOGLE_API_VERSION = void 0;
|
|
4
|
+
exports.GOOGLE_API_VERSION = 'v2';
|
|
5
|
+
exports.BASE_URL = `https://audiencepartner.googleapis.com/${exports.GOOGLE_API_VERSION}/products/GOOGLE_ADS/customers/advertiserID/`;
|
|
6
|
+
exports.CREATE_AUDIENCE_URL = `${exports.BASE_URL}userLists:mutate`;
|
|
7
|
+
exports.GET_AUDIENCE_URL = `${exports.BASE_URL}audiencePartner:searchStream`;
|
|
8
|
+
exports.OAUTH_URL = 'https://accounts.google.com/o/oauth2/token';
|
|
9
|
+
exports.SEGMENT_DATA_PARTNER_ID = '8152223833';
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/destinations/google-data-manager/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,kBAAkB,GAAG,IAAI,CAAA;AAGzB,QAAA,QAAQ,GAAG,0CAA0C,0BAAkB,8CAA8C,CAAA;AACrH,QAAA,mBAAmB,GAAG,GAAG,gBAAQ,kBAAkB,CAAA;AACnD,QAAA,gBAAgB,GAAG,GAAG,gBAAQ,8BAA8B,CAAA;AAC5D,QAAA,SAAS,GAAG,4CAA4C,CAAA;AACxD,QAAA,uBAAuB,GAAG,YAAY,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IntegrationError, InvalidAuthenticationError } from '@segment/actions-core';
|
|
2
|
+
import { StatsContext } from '@segment/actions-core/destination-kit';
|
|
3
|
+
export declare const handleRequestError: (error: unknown, statsName: string, statsContext: StatsContext | undefined) => IntegrationError | InvalidAuthenticationError;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleRequestError = void 0;
|
|
4
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
5
|
+
const isGoogleAPIError = (error) => {
|
|
6
|
+
if (typeof error === 'object' && error !== null) {
|
|
7
|
+
const e = error;
|
|
8
|
+
return (typeof e.response === 'object' &&
|
|
9
|
+
e.response !== null &&
|
|
10
|
+
typeof e.response.data === 'object' &&
|
|
11
|
+
e.response.data !== null &&
|
|
12
|
+
typeof e.response.data.error === 'object' &&
|
|
13
|
+
e.response.data.error !== null);
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
const handleRequestError = (error, statsName, statsContext) => {
|
|
18
|
+
const { statsClient, tags: statsTags } = statsContext || {};
|
|
19
|
+
if (!isGoogleAPIError(error)) {
|
|
20
|
+
if (!error) {
|
|
21
|
+
statsTags?.push('error:unknown');
|
|
22
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
23
|
+
return new actions_core_1.IntegrationError('Unknown error', 'UNKNOWN_ERROR', 500);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const gError = error;
|
|
27
|
+
const code = gError.response?.status;
|
|
28
|
+
const message = gError.response?.data?.error?.message || gError.response?.data?.[0]?.error?.message;
|
|
29
|
+
if (code === 401) {
|
|
30
|
+
statsTags?.push('error:invalid-authentication');
|
|
31
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
32
|
+
return new actions_core_1.InvalidAuthenticationError(message, actions_core_1.ErrorCodes.INVALID_AUTHENTICATION);
|
|
33
|
+
}
|
|
34
|
+
if (code === 403) {
|
|
35
|
+
statsTags?.push('error:forbidden');
|
|
36
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
37
|
+
return new actions_core_1.IntegrationError(message, 'FORBIDDEN', 403);
|
|
38
|
+
}
|
|
39
|
+
if (code === 501) {
|
|
40
|
+
statsTags?.push('error:integration-error');
|
|
41
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
42
|
+
return new actions_core_1.IntegrationError(message, 'INTEGRATION_ERROR', 501);
|
|
43
|
+
}
|
|
44
|
+
if (code === 408 || code === 423 || code === 429 || code >= 500) {
|
|
45
|
+
statsTags?.push('error:retryable-error');
|
|
46
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
47
|
+
return new actions_core_1.IntegrationError(message, 'RETRYABLE_ERROR', code);
|
|
48
|
+
}
|
|
49
|
+
statsTags?.push('error:generic-error');
|
|
50
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
51
|
+
return new actions_core_1.IntegrationError(message, 'INTEGRATION_ERROR', code);
|
|
52
|
+
};
|
|
53
|
+
exports.handleRequestError = handleRequestError;
|
|
54
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/destinations/google-data-manager/errors.ts"],"names":[],"mappings":";;;AAAA,wDAAgG;AAIhG,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAA2B,EAAE;IACnE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,MAAM,CAAC,GAAG,KAAuB,CAAA;QAEjC,OAAO,CACL,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ;YAC9B,CAAC,CAAC,QAAQ,KAAK,IAAI;YACnB,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,KAAK,QAAQ;YACnC,CAAC,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI;YACxB,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,KAAK,QAAQ;YACzC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,CAC/B,CAAA;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAGM,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAAE,SAAiB,EAAE,YAAsC,EAAE,EAAE;IAC9G,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,YAAY,IAAI,EAAE,CAAA;IAE3D,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAA;YAChC,WAAW,EAAE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AAC;IAED,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,IAAI,GAAG,EAAE,CAAC;QAChE,SAAS,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAA;QACxC,WAAW,EAAE,IAAI,CAAC,GAAG,SAAS,QAAQ,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;QACrD,OAAO,IAAI,+BAAgB,CAAC,OAAO,EAAE,iBAAiB,EAAE,IAAI,CAAC,CAAA;IAC/D,CAAC;IAED,SAAS,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAA;IACtC,WAAW,EAAE,IAAI,CAAC,GAAG,SAAS,QAAQ,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;IACrD,OAAO,IAAI,+BAAgB,CAAC,OAAO,EAAE,mBAAmB,EAAE,IAAI,CAAC,CAAA;AACjE,CAAC,CAAA;AA5CY,QAAA,kBAAkB,sBA4C9B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RequestClient } from '@segment/actions-core';
|
|
2
|
+
import type { Payload } from './syncUserData/generated-types';
|
|
3
|
+
import type { AudienceSettings, Settings } from './generated-types';
|
|
4
|
+
import { AuthTokens } from '@segment/actions-core/destination-kit/parse-settings';
|
|
5
|
+
export declare const verifyCustomerId: (customerId: string | undefined) => string;
|
|
6
|
+
export declare function ingestAudienceMembers(request: RequestClient, settings: Settings, payloads: Payload[], audienceSettings: AudienceSettings, auth?: AuthTokens): Promise<import("@segment/actions-core/src").ModifiedResponse<unknown>>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyCustomerId = void 0;
|
|
4
|
+
exports.ingestAudienceMembers = ingestAudienceMembers;
|
|
5
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
6
|
+
const hashing_utils_1 = require("../../lib/hashing-utils");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
const verifyCustomerId = (customerId) => {
|
|
9
|
+
if (!customerId) {
|
|
10
|
+
throw new actions_core_1.PayloadValidationError('Customer ID is required.');
|
|
11
|
+
}
|
|
12
|
+
return customerId.replace(/-/g, '');
|
|
13
|
+
};
|
|
14
|
+
exports.verifyCustomerId = verifyCustomerId;
|
|
15
|
+
function buildUserIdentifiers(payload) {
|
|
16
|
+
const identifiers = [];
|
|
17
|
+
if (payload.emailAddress) {
|
|
18
|
+
identifiers.push({
|
|
19
|
+
emailAddress: (0, hashing_utils_1.processHashing)(payload.emailAddress, 'sha256', 'hex')
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (payload.phoneNumber) {
|
|
23
|
+
identifiers.push({
|
|
24
|
+
phoneNumber: (0, hashing_utils_1.processHashing)(payload.phoneNumber, 'sha256', 'hex')
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (payload.givenName || payload.familyName || payload.regionCode || payload.postalCode) {
|
|
28
|
+
identifiers.push({
|
|
29
|
+
address: {
|
|
30
|
+
givenName: payload.givenName ? (0, hashing_utils_1.processHashing)(payload.givenName, 'sha256', 'hex') : undefined,
|
|
31
|
+
familyName: payload.familyName ? (0, hashing_utils_1.processHashing)(payload.familyName, 'sha256', 'hex') : undefined,
|
|
32
|
+
regionCode: payload.regionCode,
|
|
33
|
+
postalCode: payload.postalCode
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return identifiers;
|
|
38
|
+
}
|
|
39
|
+
function buildAudienceMember(payload) {
|
|
40
|
+
return {
|
|
41
|
+
consent: {
|
|
42
|
+
adUserData: 'CONSENT_GRANTED',
|
|
43
|
+
adPersonalization: 'CONSENT_GRANTED'
|
|
44
|
+
},
|
|
45
|
+
userData: {
|
|
46
|
+
userIdentifiers: buildUserIdentifiers(payload)
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function ingestAudienceMembers(request, settings, payloads, audienceSettings, auth) {
|
|
51
|
+
const accessToken = auth?.accessToken || '';
|
|
52
|
+
if (!accessToken)
|
|
53
|
+
throw new actions_core_1.IntegrationError('Missing access token.', 'ACCESS_TOKEN_MISSING', 401);
|
|
54
|
+
const body = buildRequestBody(payloads, settings, audienceSettings);
|
|
55
|
+
return request('https://datamanager.googleapis.com/v1/audienceMembers:ingest', {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
headers: {
|
|
58
|
+
Authorization: `Bearer ${accessToken}`,
|
|
59
|
+
Accept: 'application/json',
|
|
60
|
+
'Content-Type': 'application/json'
|
|
61
|
+
},
|
|
62
|
+
json: body
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const buildRequestBody = (payloads, settings, audienceSettings) => ({
|
|
66
|
+
audienceMembers: payloads.map(buildAudienceMember),
|
|
67
|
+
destinations: [
|
|
68
|
+
{
|
|
69
|
+
operatingAccount: {
|
|
70
|
+
accountId: settings.advertiserAccountId,
|
|
71
|
+
product: audienceSettings.product
|
|
72
|
+
},
|
|
73
|
+
loginAccount: {
|
|
74
|
+
accountId: `${constants_1.SEGMENT_DATA_PARTNER_ID}`,
|
|
75
|
+
product: 'DATA_PARTNER'
|
|
76
|
+
},
|
|
77
|
+
productDestinationId: audienceSettings.productDestinationId
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
encoding: 'HEX',
|
|
81
|
+
termsOfService: {
|
|
82
|
+
customerMatchTermsOfServiceStatus: 'ACCEPTED'
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/destinations/google-data-manager/functions.ts"],"names":[],"mappings":";;;AAuDA,sDAmBC;AA1ED,wDAA+F;AAE/F,2DAAwD;AAGxD,2CAAqD;AAE9C,MAAM,gBAAgB,GAAG,CAAC,UAA8B,EAAE,EAAE;IACjE,IAAI,CAAC,U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AE,KAAK;IACf,cAAc,EAAE;QACd,iCAAiC,EAAE,UAAU;KAC9C;CACF,CAAC,CAAA"}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
export interface Settings {
|
|
2
|
+
advertiserAccountId: string;
|
|
3
|
+
}
|
|
4
|
+
export interface AudienceSettings {
|
|
5
|
+
product: string;
|
|
6
|
+
productDestinationId: string;
|
|
7
|
+
externalIdType?: string;
|
|
8
|
+
app_id?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
membershipDurationDays: string;
|
|
2
11
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { Settings } from './generated-types';
|
|
1
|
+
import { AudienceDestinationDefinition } from '@segment/actions-core';
|
|
2
|
+
import type { AudienceSettings, Settings } from './generated-types';
|
|
3
3
|
export interface RefreshTokenResponse {
|
|
4
4
|
access_token: string;
|
|
5
5
|
scope: string;
|
|
6
6
|
expires_in: number;
|
|
7
7
|
token_type: string;
|
|
8
8
|
}
|
|
9
|
-
declare const destination: AudienceDestinationDefinition<Settings>;
|
|
9
|
+
declare const destination: AudienceDestinationDefinition<Settings, AudienceSettings>;
|
|
10
10
|
export default destination;
|
|
@@ -3,56 +3,204 @@ 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
|
|
7
|
-
const
|
|
6
|
+
const actions_core_1 = require("@segment/actions-core");
|
|
7
|
+
const syncUserData_1 = __importDefault(require("./syncUserData"));
|
|
8
|
+
const shared_1 = require("./shared");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
const errors_1 = require("./errors");
|
|
11
|
+
const functions_1 = require("./functions");
|
|
12
|
+
const testAuthUrl = `https://audiencepartner.googleapis.com/v2/products/DATA_PARTNER/customers/${constants_1.SEGMENT_DATA_PARTNER_ID}/audiencePartner:searchStream`;
|
|
13
|
+
const audienceFields = {
|
|
14
|
+
product: {
|
|
15
|
+
label: 'Product',
|
|
16
|
+
description: 'The product for which you want to create or manage audiences.',
|
|
17
|
+
type: 'string',
|
|
18
|
+
required: true,
|
|
19
|
+
choices: [
|
|
20
|
+
{ label: 'Google Ads', value: 'GOOGLE_ADS' },
|
|
21
|
+
{ label: 'Display & Video 360', value: 'DISPLAY_VIDEO_ADVERTISER' }
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
productDestinationId: {
|
|
25
|
+
label: 'Product Destination ID',
|
|
26
|
+
description: 'The ID of the product destination, used to identify the specific destination for audience management.',
|
|
27
|
+
type: 'string',
|
|
28
|
+
required: true
|
|
29
|
+
},
|
|
30
|
+
externalIdType: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
label: 'External ID Type',
|
|
33
|
+
description: 'Customer match upload key types. Required if you are using UserLists. Not used by the other actions.',
|
|
34
|
+
choices: [
|
|
35
|
+
{ label: 'CONTACT INFO', value: 'CONTACT_INFO' },
|
|
36
|
+
{ label: 'CRM ID', value: 'CRM_ID' },
|
|
37
|
+
{ label: 'MOBILE ADVERTISING ID', value: 'MOBILE_ADVERTISING_ID' }
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
app_id: {
|
|
41
|
+
label: 'App ID',
|
|
42
|
+
description: 'A string that uniquely identifies a mobile application from which the data was collected. Required if external ID type is mobile advertising ID',
|
|
43
|
+
type: 'string',
|
|
44
|
+
depends_on: {
|
|
45
|
+
match: 'all',
|
|
46
|
+
conditions: [
|
|
47
|
+
{
|
|
48
|
+
fieldKey: 'external_id_type',
|
|
49
|
+
operator: 'is',
|
|
50
|
+
value: 'MOBILE_ADVERTISING_ID'
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
description: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
label: 'Description',
|
|
58
|
+
required: false,
|
|
59
|
+
description: 'The description of the audience.'
|
|
60
|
+
},
|
|
61
|
+
membershipDurationDays: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
label: 'Membership Duration Days',
|
|
64
|
+
required: true,
|
|
65
|
+
description: 'The duration in days that an entry remains in the audience after the qualifying event. If the audience has no expiration, set the value of this field to 10000. Otherwise, the set value must be greater than 0 and less than or equal to 540.'
|
|
66
|
+
}
|
|
67
|
+
};
|
|
8
68
|
const destination = {
|
|
9
69
|
name: 'Google Data Manager',
|
|
10
70
|
slug: 'actions-google-data-manager',
|
|
11
71
|
mode: 'cloud',
|
|
12
72
|
authentication: {
|
|
13
73
|
scheme: 'oauth2',
|
|
14
|
-
fields: {
|
|
15
|
-
|
|
74
|
+
fields: {
|
|
75
|
+
advertiserAccountId: {
|
|
76
|
+
label: 'Advertiser Account ID',
|
|
77
|
+
description: 'The ID of the advertiser in Google Product.',
|
|
78
|
+
type: 'string',
|
|
79
|
+
required: true
|
|
80
|
+
}
|
|
16
81
|
},
|
|
17
|
-
|
|
18
|
-
const
|
|
82
|
+
testAuthentication: async (request, { auth, settings }) => {
|
|
83
|
+
const accessToken = auth.accessToken;
|
|
84
|
+
if (!accessToken)
|
|
85
|
+
throw new Error('Missing access token for authentication test.');
|
|
86
|
+
const response = await request(testAuthUrl, {
|
|
19
87
|
method: 'POST',
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
88
|
+
headers: {
|
|
89
|
+
'Content-Type': 'application/json',
|
|
90
|
+
Authorization: `Bearer ${accessToken}`,
|
|
91
|
+
'login-customer-id': settings.advertiserAccountId
|
|
92
|
+
},
|
|
93
|
+
body: JSON.stringify({
|
|
94
|
+
query: `SELECT product_link.google_ads.google_ads_customer FROM product_link WHERE product_link.google_ads.google_ads_customer = 'products/GOOGLE_ADS/customers/${settings.advertiserAccountId}'`
|
|
25
95
|
})
|
|
26
96
|
});
|
|
27
|
-
|
|
97
|
+
if (response.status < 200 || response.status >= 300)
|
|
98
|
+
throw new Error('Authentication failed: ' + response.statusText);
|
|
99
|
+
return response;
|
|
100
|
+
},
|
|
101
|
+
refreshAccessToken: async (request, { auth }) => {
|
|
102
|
+
const res = await refreshAccessTokenRequest(request, auth);
|
|
103
|
+
const data = await res.json();
|
|
104
|
+
return { accessToken: data.access_token };
|
|
28
105
|
}
|
|
29
106
|
},
|
|
30
107
|
extendRequest({ auth }) {
|
|
31
|
-
return {
|
|
32
|
-
headers: {
|
|
33
|
-
authorization: `Bearer ${auth?.accessToken}`
|
|
34
|
-
}
|
|
35
|
-
};
|
|
108
|
+
return { headers: { authorization: `Bearer ${auth?.accessToken}` } };
|
|
36
109
|
},
|
|
37
|
-
|
|
110
|
+
actions: { syncUserData: syncUserData_1.default },
|
|
38
111
|
audienceConfig: {
|
|
39
|
-
mode: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
112
|
+
mode: { type: 'synced', full_audience_sync: false },
|
|
113
|
+
async createAudience(request, { audienceName, settings, statsContext, audienceSettings }) {
|
|
114
|
+
const advertiserId = settings?.advertiserAccountId.trim();
|
|
115
|
+
const { statsClient, tags: statsTags = [] } = statsContext || {};
|
|
116
|
+
const statsName = 'createAudience';
|
|
117
|
+
statsTags.push(`slug:${destination.slug}`);
|
|
118
|
+
statsClient?.incr(`${statsName}.call`, 1, statsTags);
|
|
119
|
+
if (!audienceName) {
|
|
120
|
+
statsTags.push('error:missing-settings');
|
|
121
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
122
|
+
throw new actions_core_1.IntegrationError('Missing audience name value', 'MISSING_REQUIRED_FIELD', 400);
|
|
123
|
+
}
|
|
124
|
+
(0, functions_1.verifyCustomerId)(advertiserId);
|
|
125
|
+
const partnerCreateAudienceUrl = constants_1.CREATE_AUDIENCE_URL.replace('advertiserID', advertiserId);
|
|
126
|
+
const listTypeMap = { basicUserList: {}, type: 'REMARKETING', membershipStatus: 'OPEN' };
|
|
127
|
+
try {
|
|
128
|
+
const authToken = await (0, shared_1.getAuthToken)(request, (0, shared_1.getAuthSettings)());
|
|
129
|
+
const response = await request(partnerCreateAudienceUrl, {
|
|
130
|
+
headers: (0, shared_1.buildHeaders)(audienceSettings, settings, authToken),
|
|
131
|
+
method: 'POST',
|
|
132
|
+
json: {
|
|
133
|
+
operations: [
|
|
134
|
+
{
|
|
135
|
+
create: {
|
|
136
|
+
...listTypeMap,
|
|
137
|
+
name: audienceName,
|
|
138
|
+
description: audienceSettings?.description || 'Created by Segment',
|
|
139
|
+
membershipLifeSpan: audienceSettings?.membershipDurationDays
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
const r = await response?.json();
|
|
146
|
+
statsClient?.incr(`${statsName}.success`, 1, statsTags);
|
|
147
|
+
return { externalId: r['results'][0]['resourceName'] };
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
throw (0, errors_1.handleRequestError)(error, statsName, statsContext);
|
|
151
|
+
}
|
|
45
152
|
},
|
|
46
|
-
|
|
47
|
-
|
|
153
|
+
async getAudience(request, { statsContext, settings, audienceSettings, externalId }) {
|
|
154
|
+
const { statsClient, tags: statsTags = [] } = statsContext || {};
|
|
155
|
+
const advertiserId = settings?.advertiserAccountId?.trim();
|
|
156
|
+
const statsName = 'getAudience';
|
|
157
|
+
statsTags.push(`slug:${destination.slug}`);
|
|
158
|
+
statsClient?.incr(`${statsName}.call`, 1, statsTags);
|
|
159
|
+
if (!advertiserId) {
|
|
160
|
+
statsTags.push('error:missing-settings');
|
|
161
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
162
|
+
throw new actions_core_1.IntegrationError('Missing required advertiser ID value', 'MISSING_REQUIRED_FIELD', 400);
|
|
163
|
+
}
|
|
164
|
+
const advertiserGetAudienceUrl = constants_1.GET_AUDIENCE_URL.replace('advertiserID', advertiserId);
|
|
165
|
+
try {
|
|
166
|
+
const authToken = await (0, shared_1.getAuthToken)(request, (0, shared_1.getAuthSettings)());
|
|
167
|
+
const response = await request(advertiserGetAudienceUrl, {
|
|
168
|
+
headers: (0, shared_1.buildHeaders)(audienceSettings, settings, authToken),
|
|
169
|
+
method: 'POST',
|
|
170
|
+
json: {
|
|
171
|
+
query: `SELECT user_list.name, user_list.description, user_list.membership_status, user_list.match_rate_percentage FROM user_list WHERE user_list.resource_name = "${externalId}"`
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
const r = await response.json();
|
|
175
|
+
const foundId = r[0]?.results[0]?.userList?.resourceName;
|
|
176
|
+
if (foundId !== externalId) {
|
|
177
|
+
statsTags.push('error:id-mismatch');
|
|
178
|
+
statsClient?.incr(`${statsName}.error`, 1, statsTags);
|
|
179
|
+
throw new actions_core_1.IntegrationError("Unable to verify ownership over audience. Segment Audience ID doesn't match Google's Audience ID.", 'INVALID_REQUEST_DATA', 400);
|
|
180
|
+
}
|
|
181
|
+
statsClient?.incr(`${statsName}.success`, 1, statsTags);
|
|
182
|
+
return { externalId: foundId };
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error instanceof actions_core_1.IntegrationError) {
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
throw (0, errors_1.handleRequestError)(error, statsName, statsContext);
|
|
189
|
+
}
|
|
48
190
|
}
|
|
49
191
|
},
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
actions: {
|
|
53
|
-
ingest: ingest_1.default,
|
|
54
|
-
remove: remove_1.default
|
|
55
|
-
}
|
|
192
|
+
audienceFields
|
|
56
193
|
};
|
|
194
|
+
function refreshAccessTokenRequest(request, auth) {
|
|
195
|
+
return request('https://www.googleapis.com/oauth2/v4/token', {
|
|
196
|
+
method: 'POST',
|
|
197
|
+
body: new URLSearchParams({
|
|
198
|
+
refresh_token: auth.refreshToken,
|
|
199
|
+
client_id: auth.clientId,
|
|
200
|
+
client_secret: auth.clientSecret,
|
|
201
|
+
grant_type: 'refresh_token'
|
|
202
|
+
})
|
|
203
|
+
});
|
|
204
|
+
}
|
|
57
205
|
exports.default = destination;
|
|
58
206
|
//# sourceMappingURL=index.js.map
|