@segment/action-destinations 3.100.1-alpha.1 → 3.100.1-alpha.3

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.
Files changed (96) hide show
  1. package/dist/destinations/1plusx/sendEvent/generated-types.d.ts +1 -1
  2. package/dist/destinations/1plusx/sendEvent/index.js +1 -2
  3. package/dist/destinations/1plusx/sendEvent/index.js.map +1 -1
  4. package/dist/destinations/1plusx/sendPageview/generated-types.d.ts +1 -1
  5. package/dist/destinations/1plusx/sendPageview/index.js +1 -2
  6. package/dist/destinations/1plusx/sendPageview/index.js.map +1 -1
  7. package/dist/destinations/1plusx/sendUserData/generated-types.d.ts +1 -1
  8. package/dist/destinations/1plusx/sendUserData/index.js +1 -2
  9. package/dist/destinations/1plusx/sendUserData/index.js.map +1 -1
  10. package/dist/destinations/actions-pardot/index.js +1 -1
  11. package/dist/destinations/actions-pardot/index.js.map +1 -1
  12. package/dist/destinations/actions-pardot/pa-operations.d.ts +1 -1
  13. package/dist/destinations/actions-pardot/pa-operations.js +3 -3
  14. package/dist/destinations/actions-pardot/pa-operations.js.map +1 -1
  15. package/dist/destinations/actions-pardot/prospects/index.js +5 -4
  16. package/dist/destinations/actions-pardot/prospects/index.js.map +1 -1
  17. package/dist/destinations/engage-messaging-twilio/sendSms/index.js +1 -1
  18. package/dist/destinations/engage-messaging-twilio/sendSms/index.js.map +1 -1
  19. package/dist/destinations/google-enhanced-conversions/constants.d.ts +1 -0
  20. package/dist/destinations/google-enhanced-conversions/constants.js +185 -0
  21. package/dist/destinations/google-enhanced-conversions/constants.js.map +1 -0
  22. package/dist/destinations/google-enhanced-conversions/functions.d.ts +3 -0
  23. package/dist/destinations/google-enhanced-conversions/functions.js +36 -0
  24. package/dist/destinations/google-enhanced-conversions/functions.js.map +1 -0
  25. package/dist/destinations/google-enhanced-conversions/generated-types.d.ts +1 -0
  26. package/dist/destinations/google-enhanced-conversions/index.js +12 -1
  27. package/dist/destinations/google-enhanced-conversions/index.js.map +1 -1
  28. package/dist/destinations/google-enhanced-conversions/uploadCallConversion/generated-types.d.ts +11 -0
  29. package/dist/destinations/google-enhanced-conversions/uploadCallConversion/generated-types.js +3 -0
  30. package/dist/destinations/google-enhanced-conversions/uploadCallConversion/generated-types.js.map +1 -0
  31. package/dist/destinations/google-enhanced-conversions/uploadCallConversion/index.d.ts +5 -0
  32. package/dist/destinations/google-enhanced-conversions/uploadCallConversion/index.js +99 -0
  33. package/dist/destinations/google-enhanced-conversions/uploadCallConversion/index.js.map +1 -0
  34. package/dist/destinations/google-enhanced-conversions/uploadClickConversion/generated-types.d.ts +25 -0
  35. package/dist/destinations/google-enhanced-conversions/uploadClickConversion/generated-types.js +3 -0
  36. package/dist/destinations/google-enhanced-conversions/uploadClickConversion/generated-types.js.map +1 -0
  37. package/dist/destinations/google-enhanced-conversions/uploadClickConversion/index.d.ts +5 -0
  38. package/dist/destinations/google-enhanced-conversions/uploadClickConversion/index.js +238 -0
  39. package/dist/destinations/google-enhanced-conversions/uploadClickConversion/index.js.map +1 -0
  40. package/dist/destinations/google-enhanced-conversions/uploadClickConversion/types.d.ts +5 -0
  41. package/dist/destinations/google-enhanced-conversions/uploadClickConversion/types.js +3 -0
  42. package/dist/destinations/google-enhanced-conversions/uploadClickConversion/types.js.map +1 -0
  43. package/dist/destinations/google-enhanced-conversions/uploadConversionAdjustment/generated-types.d.ts +20 -0
  44. package/dist/destinations/google-enhanced-conversions/uploadConversionAdjustment/generated-types.js +3 -0
  45. package/dist/destinations/google-enhanced-conversions/uploadConversionAdjustment/generated-types.js.map +1 -0
  46. package/dist/destinations/google-enhanced-conversions/uploadConversionAdjustment/index.d.ts +5 -0
  47. package/dist/destinations/google-enhanced-conversions/uploadConversionAdjustment/index.js +269 -0
  48. package/dist/destinations/google-enhanced-conversions/uploadConversionAdjustment/index.js.map +1 -0
  49. package/dist/destinations/index.js +1 -1
  50. package/dist/destinations/intercom/groupIdentifyContact/generated-types.d.ts +2 -0
  51. package/dist/destinations/intercom/groupIdentifyContact/index.js +44 -36
  52. package/dist/destinations/intercom/groupIdentifyContact/index.js.map +1 -1
  53. package/dist/destinations/intercom/identifyContact/index.js +24 -54
  54. package/dist/destinations/intercom/identifyContact/index.js.map +1 -1
  55. package/dist/destinations/intercom/index.d.ts +1 -1
  56. package/dist/destinations/intercom/index.js +24 -8
  57. package/dist/destinations/intercom/index.js.map +1 -1
  58. package/dist/destinations/intercom/trackEvent/generated-types.d.ts +12 -0
  59. package/dist/destinations/intercom/trackEvent/generated-types.js +3 -0
  60. package/dist/destinations/intercom/trackEvent/generated-types.js.map +1 -0
  61. package/dist/destinations/intercom/trackEvent/index.d.ts +5 -0
  62. package/dist/destinations/intercom/trackEvent/index.js +111 -0
  63. package/dist/destinations/intercom/trackEvent/index.js.map +1 -0
  64. package/dist/destinations/intercom/util.d.ts +11 -0
  65. package/dist/destinations/intercom/util.js +48 -0
  66. package/dist/destinations/intercom/util.js.map +1 -0
  67. package/dist/destinations/mixpanel/alias/index.js +2 -1
  68. package/dist/destinations/mixpanel/alias/index.js.map +1 -1
  69. package/dist/destinations/mixpanel/generated-types.d.ts +1 -0
  70. package/dist/destinations/mixpanel/groupIdentifyUser/index.js +2 -1
  71. package/dist/destinations/mixpanel/groupIdentifyUser/index.js.map +1 -1
  72. package/dist/destinations/mixpanel/identifyUser/index.js +4 -2
  73. package/dist/destinations/mixpanel/identifyUser/index.js.map +1 -1
  74. package/dist/destinations/mixpanel/index.js +8 -0
  75. package/dist/destinations/mixpanel/index.js.map +1 -1
  76. package/dist/destinations/mixpanel/trackEvent/index.js +1 -1
  77. package/dist/destinations/mixpanel/trackEvent/index.js.map +1 -1
  78. package/dist/destinations/mixpanel/utils.d.ts +5 -0
  79. package/dist/destinations/mixpanel/utils.js +13 -1
  80. package/dist/destinations/mixpanel/utils.js.map +1 -1
  81. package/dist/destinations/salesforce/account/index.js +1 -1
  82. package/dist/destinations/salesforce/account/index.js.map +1 -1
  83. package/dist/destinations/salesforce/cases/index.js +1 -1
  84. package/dist/destinations/salesforce/cases/index.js.map +1 -1
  85. package/dist/destinations/salesforce/contact/index.js +1 -1
  86. package/dist/destinations/salesforce/contact/index.js.map +1 -1
  87. package/dist/destinations/salesforce/customObject/index.js +1 -1
  88. package/dist/destinations/salesforce/customObject/index.js.map +1 -1
  89. package/dist/destinations/salesforce/lead/index.js +1 -1
  90. package/dist/destinations/salesforce/lead/index.js.map +1 -1
  91. package/dist/destinations/salesforce/opportunity/index.js +1 -1
  92. package/dist/destinations/salesforce/opportunity/index.js.map +1 -1
  93. package/dist/lib/engage-test-data/create-messaging-test-event.d.ts +1 -15
  94. package/dist/lib/engage-test-data/create-messaging-test-event.js +0 -15
  95. package/dist/lib/engage-test-data/create-messaging-test-event.js.map +1 -1
  96. package/package.json +4 -4
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const actions_core_1 = require("@segment/actions-core");
4
+ const functions_1 = require("../functions");
5
+ const action = {
6
+ title: 'Upload Conversion Adjustment',
7
+ description: 'Upload a conversion adjustment to the Google Ads API.',
8
+ fields: {
9
+ conversion_action: {
10
+ label: 'Conversion Action ID',
11
+ description: 'The ID of the conversion action associated with this conversion. To find the Conversion Action ID, click on your conversion in Google Ads and get the value for ctId in the URL. For example, if the URL is https://ads.google.com/aw/conversions/detail?ocid=00000000&ctId=576882000, your Conversion Action ID is 576882000.',
12
+ type: 'string',
13
+ required: true,
14
+ default: ''
15
+ },
16
+ adjustment_type: {
17
+ label: 'Adjustment Type',
18
+ description: 'The adjustment type. See Google’s documentation for details on each type.',
19
+ type: 'string',
20
+ choices: [
21
+ { label: 'UNSPECIFIED', value: 'UNSPECIFIED' },
22
+ { label: 'UNKNOWN', value: 'UNKNOWN' },
23
+ { label: `RETRACTION`, value: 'RETRACTION' },
24
+ { label: 'RESTATEMENT', value: 'RESTATEMENT' },
25
+ { label: `ENHANCEMENT`, value: 'ENHANCEMENT' }
26
+ ],
27
+ required: true
28
+ },
29
+ adjustment_timestamp: {
30
+ label: 'Adjustment Timestamp',
31
+ description: 'The date time at which the adjustment occurred. Must be after the conversion_date_time. The timezone must be specified. The format is "yyyy-mm-dd hh:mm:ss+|-hh:mm", e.g. "2019-01-01 12:32:45-08:00".',
32
+ type: 'string',
33
+ required: true,
34
+ default: {
35
+ '@path': '$.timestamp'
36
+ }
37
+ },
38
+ order_id: {
39
+ label: 'Order ID',
40
+ description: 'The order ID of the conversion to be adjusted. If the conversion was reported with an order ID specified, that order ID must be used as the identifier here. Required for ENHANCEMENT adjustments.',
41
+ type: 'string',
42
+ default: {
43
+ '@path': '$.properties.orderId'
44
+ }
45
+ },
46
+ gclid: {
47
+ label: 'GCLID',
48
+ description: 'Google click ID associated with the original conversion for this adjustment. This is used for the GCLID Date Time Pair. Required for non-ENHANCEMENT adjustments. If adjustment is ENHANCEMENT, this value is optional but may be set in addition to the order ID.',
49
+ type: 'string',
50
+ default: ''
51
+ },
52
+ conversion_timestamp: {
53
+ label: 'Conversion Timestamp',
54
+ description: 'The date time at which the original conversion for this adjustment occurred. The timezone must be specified. The format is "yyyy-mm-dd hh:mm:ss+|-hh:mm", e.g. "2019-01-01 12:32:45-08:00". This is used for the GCLID Date Time Pair. Required for non-ENHANCEMENT adjustments. If adjustment is ENHANCEMENT, this value is optional but may be set in addition to the order ID.',
55
+ type: 'string',
56
+ default: ''
57
+ },
58
+ restatement_value: {
59
+ label: 'Restatement Value',
60
+ description: 'The restated conversion value. This is the value of the conversion after restatement. For example, to change the value of a conversion from 100 to 70, an adjusted value of 70 should be reported. Required for RESTATEMENT adjustments.',
61
+ type: 'number',
62
+ default: ''
63
+ },
64
+ restatement_currency_code: {
65
+ label: 'Restatement Currency Code',
66
+ description: 'The currency of the restated value. If not provided, then the default currency from the conversion action is used, and if that is not set then the account currency is used. This is the ISO 4217 3-character currency code e.g. USD or EUR.',
67
+ type: 'string',
68
+ default: ''
69
+ },
70
+ email_address: {
71
+ label: 'Email Address',
72
+ description: 'Email address of the individual who triggered the conversion event. Segment will hash this value before sending to Google.',
73
+ type: 'string',
74
+ format: 'email',
75
+ default: {
76
+ '@if': {
77
+ exists: { '@path': '$.properties.email' },
78
+ then: { '@path': '$.properties.email' },
79
+ else: { '@path': '$context.traits.email' }
80
+ }
81
+ }
82
+ },
83
+ phone_number: {
84
+ label: 'Phone Number',
85
+ description: 'Phone number of the individual who triggered the conversion event, in E.164 standard format, e.g. +14150000000. Segment will hash this value before sending to Google.',
86
+ type: 'string',
87
+ default: {
88
+ '@if': {
89
+ exists: { '@path': '$.properties.phone' },
90
+ then: { '@path': '$.properties.phone' },
91
+ else: { '@path': '$context.traits.phone' }
92
+ }
93
+ }
94
+ },
95
+ first_name: {
96
+ label: 'First Name',
97
+ description: 'First name of the user who performed the conversion. Segment will hash this value before sending to Google.',
98
+ type: 'string',
99
+ default: {
100
+ '@if': {
101
+ exists: { '@path': '$.properties.firstName' },
102
+ then: { '@path': '$.properties.firstName' },
103
+ else: { '@path': '$context.traits.firstName' }
104
+ }
105
+ }
106
+ },
107
+ last_name: {
108
+ label: 'Last Name',
109
+ description: 'Last name of the user who performed the conversion. Segment will hash this value before sending to Google.',
110
+ type: 'string',
111
+ default: {
112
+ '@if': {
113
+ exists: { '@path': '$.properties.lastName' },
114
+ then: { '@path': '$.properties.lastName' },
115
+ else: { '@path': '$context.traits.lastName' }
116
+ }
117
+ }
118
+ },
119
+ city: {
120
+ label: 'City',
121
+ description: 'City of the user who performed the conversion.',
122
+ type: 'string',
123
+ default: {
124
+ '@if': {
125
+ exists: { '@path': '$.properties.address.city,' },
126
+ then: { '@path': '$.properties.address.city,' },
127
+ else: { '@path': '$.context.traits.address.city' }
128
+ }
129
+ }
130
+ },
131
+ state: {
132
+ label: 'State',
133
+ description: 'State of the user who performed the conversion.',
134
+ type: 'string',
135
+ default: {
136
+ '@if': {
137
+ exists: { '@path': '$.properties.address.state,' },
138
+ then: { '@path': '$.properties.address.state,' },
139
+ else: { '@path': '$.context.traits.address.state' }
140
+ }
141
+ }
142
+ },
143
+ country: {
144
+ label: 'Country',
145
+ description: '2-letter country code in ISO-3166-1 alpha-2 of the user who performed the conversion.',
146
+ type: 'string',
147
+ default: {
148
+ '@if': {
149
+ exists: { '@path': '$.properties.address.country,' },
150
+ then: { '@path': '$.properties.address.country,' },
151
+ else: { '@path': '$.context.traits.address.country' }
152
+ }
153
+ }
154
+ },
155
+ postal_code: {
156
+ label: 'Postal Code',
157
+ description: 'Postal code of the user who performed the conversion.',
158
+ type: 'string',
159
+ default: {
160
+ '@if': {
161
+ exists: { '@path': '$.properties.address.postalCode,' },
162
+ then: { '@path': '$.properties.address.postalCode,' },
163
+ else: { '@path': '$.context.traits.address.postalCode' }
164
+ }
165
+ }
166
+ },
167
+ street_address: {
168
+ label: 'Street Address',
169
+ description: 'Street address of the user who performed the conversion. Segment will hash this value before sending to Google.',
170
+ type: 'string',
171
+ default: {
172
+ '@if': {
173
+ exists: { '@path': '$.properties.address.street,' },
174
+ then: { '@path': '$.properties.address.street,' },
175
+ else: { '@path': '$.context.traits.address.street' }
176
+ }
177
+ }
178
+ },
179
+ user_agent: {
180
+ label: 'User Agent',
181
+ description: 'The user agent to enhance the original conversion. User agent can only be specified in enhancements with user identifiers. This should match the user agent of the request that sent the original conversion so the conversion and its enhancement are either both attributed as same-device or both attributed as cross-device.',
182
+ type: 'string',
183
+ default: {
184
+ '@path': '$.context.userAgent'
185
+ }
186
+ }
187
+ },
188
+ perform: async (request, { settings, payload }) => {
189
+ if (!settings.customerId) {
190
+ throw new actions_core_1.IntegrationError('Customer id is required for this action. Please set it in destination settings.', 'Missing required fields.', 400);
191
+ }
192
+ settings.customerId = settings.customerId.replace(/[^0-9.]+/g, '');
193
+ if (payload.adjustment_type == 'ENHANCEMENT' && !payload.order_id) {
194
+ throw new actions_core_1.IntegrationError('Order id required for enhancement conversion', 'INVALID_ARGUMENT', 400);
195
+ }
196
+ else if (payload.adjustment_type != 'ENHANCEMENT') {
197
+ if (!payload.gclid) {
198
+ throw new actions_core_1.IntegrationError('Gclid required for chosen conversion type', 'INVALID_ARGUMENT', 400);
199
+ }
200
+ if (!payload.conversion_timestamp) {
201
+ throw new actions_core_1.IntegrationError('Conversion timestamp required for chosen conversion type', 'INVALID_ARGUMENT', 400);
202
+ }
203
+ if (payload.adjustment_type == 'RESTATEMENT' && !payload.restatement_value) {
204
+ throw new actions_core_1.IntegrationError('Restatement value required for restatement conversion', 'INVALID_ARGUMENT', 400);
205
+ }
206
+ }
207
+ const request_object = {
208
+ conversionAction: `customers/${settings.customerId}/conversionActions/${payload.conversion_action}`,
209
+ adjustmentType: payload.adjustment_type,
210
+ adjustmentDateTime: payload.adjustment_timestamp.replace(/T/, ' ').replace(/\..+/, '+00:00'),
211
+ orderId: payload.order_id,
212
+ gclidDateTimePair: {
213
+ gclid: payload.gclid,
214
+ conversionDateTime: payload.conversion_timestamp
215
+ },
216
+ restatementValue: {
217
+ adjustedValue: payload.restatement_value,
218
+ currencyCode: payload.restatement_currency_code
219
+ },
220
+ userIdentifiers: [],
221
+ userAgent: payload.user_agent
222
+ };
223
+ if (payload.email_address) {
224
+ request_object.userIdentifiers.push({ hashedEmail: functions_1.hash(payload.email_address) });
225
+ }
226
+ if (payload.phone_number) {
227
+ request_object.userIdentifiers.push({ hashedPhoneNumber: functions_1.hash(payload.phone_number) });
228
+ }
229
+ if (payload.first_name ||
230
+ payload.last_name ||
231
+ payload.city ||
232
+ payload.state ||
233
+ payload.country ||
234
+ payload.postal_code ||
235
+ payload.street_address) {
236
+ request_object.userIdentifiers.push({
237
+ addressInfo: {
238
+ hashedFirstName: functions_1.hash(payload.first_name),
239
+ hashedLastName: functions_1.hash(payload.last_name),
240
+ hashedStreetAddress: functions_1.hash(payload.street_address),
241
+ city: payload.city,
242
+ state: payload.state,
243
+ countryCode: payload.country,
244
+ postalCode: payload.postal_code
245
+ }
246
+ });
247
+ }
248
+ const response = await request(`https://googleads.googleapis.com/v11/customers/${settings.customerId}:uploadConversionAdjustments`, {
249
+ method: 'post',
250
+ headers: {
251
+ 'developer-token': `${process.env.ADWORDS_DEVELOPER_TOKEN}`
252
+ },
253
+ json: {
254
+ conversionAdjustments: [request_object],
255
+ partialFailure: true
256
+ }
257
+ });
258
+ if (typeof response.data === 'object' && response.data != null) {
259
+ Object.entries(response.data).forEach(([key, value]) => {
260
+ if (key === 'partialFailureError' && value.code !== 0) {
261
+ throw new actions_core_1.IntegrationError(value.message, 'INVALID_ARGUMENT', 400);
262
+ }
263
+ });
264
+ }
265
+ return response;
266
+ }
267
+ };
268
+ exports.default = action;
269
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/google-enhanced-conversions/uploadConversionAdjustment/index.ts"],"names":[],"mappings":";;AAAA,wDAA0E;AAC1E,4CAAmC;AAInC,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,8BAA8B;IACrC,WAAW,EAAE,uDAAuD;IACpE,MAAM,EAAE;QACN,iBAAiB,EAAE;YACjB,KAAK,EAAE,sBAAsB;YAC7B,WAAW,EACT,gUAAgU;YAClU,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,EAAE;SACZ;QACD,eAAe,EAAE;YACf,KAAK,EAAE,iBAAiB;YACxB,WAAW,EAAE,2EAA2E;YACxF,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE;gBAC9C,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;gBACtC,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE;gBAC5C,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE;gBAC9C,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE;aAC/C;YACD,QAAQ,EAAE,IAAI;SACf;QACD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,CAC5B,kDAAkD,QAAQ,CAAC,UAAU,8BAA8B,EACnG;YACE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,iBAAiB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE;aAC5D;YACD,IAAI,EAAE;gBACJ,qBAAqB,EAAE,CAAC,cAAc,CAAC;gBACvC,cAAc,EAAE,IAAI;aACrB;SACF,CACF,CAAA;QAGD,IAAI,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,IAAI,IAAI,EAAE;YAC9D,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBACrD,IAAI,GAAG,KAAK,qBAAqB,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE;oBACrD,MAAM,IAAI,+BAAgB,CAAC,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,CAAC,CAAA;iBACnE;YACH,CAAC,CAAC,CAAA;SACH;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -62,7 +62,7 @@ register('615cae349d109d6b7496a131', './tiktok-conversions');
62
62
  register('602efa1f249b9a5e2bf8a813', './twilio');
63
63
  register('614a3c7d791c91c41bae7599', './webhook');
64
64
  register('61dc4e96894a6d7954cc6e45', './voyage');
65
- register('62b5f2f40b10eaace2e12b23', './intercom');
65
+ register('62ded0cf5753c743883ca0f3', './intercom');
66
66
  function register(id, destinationPath) {
67
67
  const definition = require(destinationPath).default;
68
68
  const resolvedPath = require.resolve(destinationPath);
@@ -1,5 +1,7 @@
1
1
  export interface Payload {
2
2
  remote_created_at?: string | number;
3
+ external_id?: string;
4
+ email?: string;
3
5
  company_id: string;
4
6
  contact_id?: string;
5
7
  name?: string;
@@ -1,23 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const actions_core_1 = require("@segment/actions-core");
3
+ const util_1 = require("../util");
4
4
  const action = {
5
- title: 'Group Identify Contact',
6
- description: "Create or Update A Company. Note: Companies will be only visible in Intercom's Dashboard when there is at least one associated contact.",
5
+ title: 'Identify Company',
6
+ description: 'Create or update a company in Intercom and attach a contact.',
7
7
  defaultSubscription: 'type = "group"',
8
- platform: 'web',
9
8
  fields: {
10
9
  remote_created_at: {
11
10
  type: 'datetime',
12
11
  description: 'The time the company was created by you.',
13
- label: 'Remote Created At',
12
+ label: 'Company Creation Time',
14
13
  default: {
15
14
  '@path': '$.traits.createdAt'
16
15
  }
17
16
  },
17
+ external_id: {
18
+ type: 'string',
19
+ description: 'A unique identifier for the contact generated outside Intercom. External ID is required to attach a contact to a company if no email or Contact ID is provided.',
20
+ label: 'External ID',
21
+ default: {
22
+ '@path': '$.userId'
23
+ }
24
+ },
25
+ email: {
26
+ type: 'string',
27
+ description: "The contact's email address. Email is required to attach a contact to a company if no External ID or Contact ID is provided.",
28
+ label: 'Email Address',
29
+ format: 'email',
30
+ default: {
31
+ '@path': '$.traits.email'
32
+ }
33
+ },
18
34
  company_id: {
19
35
  type: 'string',
20
- description: "The unique identifier of the company. Can't be updated.",
36
+ description: "The unique identifier of the company. Once set, this can't be updated.",
21
37
  label: 'Company ID',
22
38
  required: true,
23
39
  default: {
@@ -26,55 +42,52 @@ const action = {
26
42
  },
27
43
  contact_id: {
28
44
  type: 'string',
29
- description: 'Attach this contact to the company. This ID is NOT the external_id or email; it is the Intercom unique identifier.',
30
- label: 'Contact ID',
31
- default: {
32
- '@path': '$.userId'
33
- }
45
+ description: 'The unique identifier for the contact which is given by Intercom. If no Contact ID is provided, Segment will use External ID or email to find a contact to attach to the company.',
46
+ label: 'Contact ID'
34
47
  },
35
48
  name: {
36
49
  type: 'string',
37
50
  description: 'The name of the company.',
38
- label: 'Name',
51
+ label: 'Company Name',
39
52
  default: {
40
53
  '@path': '$.traits.name'
41
54
  }
42
55
  },
43
56
  monthly_spend: {
44
57
  type: 'number',
45
- description: 'The monthly spend of the company.',
58
+ description: 'The monthly spend of the company, e.g. how much revenue the company generates for your business.',
46
59
  label: 'Monthly Spend',
47
60
  default: {
48
- '@path': '$.traits.plan'
61
+ '@path': '$.traits.monthly_spend'
49
62
  }
50
63
  },
51
64
  plan: {
52
65
  type: 'string',
53
- description: 'The plan of the company.',
54
- label: 'Plan',
66
+ description: 'The name of the plan you have associated with the company.',
67
+ label: 'Company Plan',
55
68
  default: {
56
69
  '@path': '$.traits.plan'
57
70
  }
58
71
  },
59
72
  size: {
60
73
  type: 'number',
61
- description: 'The size of the company.',
62
- label: 'Size',
74
+ description: 'The number of employees in the company.',
75
+ label: 'Company Size',
63
76
  default: {
64
77
  '@path': '$.traits.employees'
65
78
  }
66
79
  },
67
80
  website: {
68
81
  type: 'string',
69
- description: 'The website of the company.',
70
- label: 'Website',
82
+ description: "The URL for the company's website",
83
+ label: 'Company Website',
71
84
  default: {
72
85
  '@path': '$.traits.website'
73
86
  }
74
87
  },
75
88
  industry: {
76
89
  type: 'string',
77
- description: 'The industry of the company.',
90
+ description: 'The industry that the company operates in.',
78
91
  label: 'Industry',
79
92
  default: {
80
93
  '@path': '$.traits.industry'
@@ -82,25 +95,20 @@ const action = {
82
95
  },
83
96
  custom_attributes: {
84
97
  type: 'object',
85
- description: 'Passing any traits not mapped to individual fields as Custom Attributes. Note: Will throw an error if you pass an attribute that isn`t explicitly defined.',
86
- label: 'Custom Attributes'
98
+ description: 'A hash of key-value pairs containing any other data about the company you want Intercom to store. You can only write to custom attributes that already exist in your Intercom workspace. Please ensure custom attributes are created in Intercom first. See [Intercom documentation](https://developers.intercom.com/intercom-api-reference/reference/create-data-attributes) for more information on creating attributes.',
99
+ label: 'Custom Attributes',
100
+ defaultObjectUI: 'keyvalue'
87
101
  }
88
102
  },
89
103
  perform: async (request, { payload }) => {
90
- const contactId = payload.contact_id;
91
- delete payload.contact_id;
104
+ const contact = await util_1.getUniqueIntercomContact(request, payload);
105
+ delete payload.email;
106
+ delete payload.external_id;
92
107
  const response = await createOrUpdateIntercomCompany(request, payload);
93
- if (contactId) {
94
- try {
95
- const companyId = response.data.id;
96
- return await attachContactToIntercomCompany(request, contactId, companyId);
97
- }
98
- catch (error) {
99
- if (error?.response?.status === 404) {
100
- throw new actions_core_1.RetryableError(`Contact doesn't exist, retrying`);
101
- }
102
- throw error;
103
- }
108
+ if (contact) {
109
+ payload.contact_id = contact.id;
110
+ const companyId = response.data.id;
111
+ return attachContactToIntercomCompany(request, contact.id, companyId);
104
112
  }
105
113
  }
106
114
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/intercom/groupIdentifyContact/index.ts"],"names":[],"mappings":";;AAAA,wDAAyG;AAQzG,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,wBAAwB;IAC/B,WAAW,EACT,yIAAyI;IAC3I,mBAAmB,EAAE,gBAAgB;IACrC,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE;QACN,iBAAiB,EAAE;YACjB,IAAI,EAAE,UAAU;YAChB,WAAW,EAAE,0CAA0C;YACvD,KAAK,EAAE,mBAAmB;YAC1B,OAAO,EAAE;gBACP,OAAO,EAAE,oBAAoB;aAC9B;SACF;QACD,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,yDAAyD;YACtE,KAAK,EAAE,YAAY;YACnB,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE;gBACP,OAAO,EAAE,WAAW;aACrB;SACF;QACD,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,oHAAoH;YACtH,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE;gBACP,OAAO,EAAE,UAAU;aACpB;SACF;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,0BAA0B;YACvC,KAAK,EAAE,MAAM;YACb,OAAO,EAAE;gBACP,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AAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;aAC3E;YAAC,OAAO,KAAK,EAAE;gBAEd,IAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,GAAG,EAAE;oBACnC,MAAM,IAAI,6BAAc,CAAC,iCAAiC,CAAC,CAAA;iBAC5D;gBACD,MAAM,KAAK,CAAA;aACZ;SACF;IACH,CAAC;CACF,CAAA;AAED,SAAS,6BAA6B,CACpC,OAAsB,EACtB,OAAgB;IAEhB,OAAO,OAAO,CAAC,mCAAmC,EAAE;QAClD,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,OAAO;KACd,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,8BAA8B,CAAC,OAAsB,EAAE,SAAiB,EAAE,SAAiB;IAClG,OAAO,OAAO,CAAC,oCAAoC,SAAS,YAAY,EAAE;QACxE,MAAM,EAAE,MAAM;QACd,IAAI,EAAE;YACJ,EAAE,EAAE,SAAS;SACd;KACF,CAAC,CAAA;AACJ,CAAC;AAED,kBAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/intercom/groupIdentifyContact/index.ts"],"names":[],"mappings":";;AAEA,kCAAkD;AAOlD,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,kBAAkB;IACzB,WAAW,EAAE,8DAA8D;IAC3E,mBAAmB,EAAE,gBAAgB;IACrC,MAAM,EAAE;QACN,iBAAiB,EAAE;YACjB,IAAI,EAAE,UAAU;YAChB,WAAW,EAAE,0CAA0C;YACvD,KAAK,EAAE,uBAAuB;YAC9B,OAAO,EAAE;gBACP,OAAO,EAAE,oBAAoB;aAC9B;SACF;QACD,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,iKAAiK;YACnK,KAAK,EAAE,aAAa;YACpB,OAAO,EAAE;gBACP,OAAO,EAAE,UAAU;aACpB;SACF;QACD,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,8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,mBAAmB;aAC7B;SACF;QACD,iBAAiB,EAAE;YACjB,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,4ZAA4Z;YAC9Z,KAAK,EAAE,mBAAmB;YAC1B,eAAe,EAAE,UAAU;SAC5B;KACF;IAOD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACtC,MAAM,OAAO,GAAG,MAAM,+BAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAChE,OAAO,OAAO,CAAC,KAAK,CAAA;QACpB,OAAO,OAAO,CAAC,WAAW,CAAA;QAE1B,MAAM,QAAQ,GAAG,MAAM,6BAA6B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACtE,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,EAAE,CAAA;YAC/B,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAA;YAClC,OAAO,8BAA8B,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,SAAS,CAAC,CAAA;SACtE;IACH,CAAC;CACF,CAAA;AAED,SAAS,6BAA6B,CACpC,OAAsB,EACtB,OAAgB;IAEhB,OAAO,OAAO,CAAC,mCAAmC,EAAE;QAClD,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,OAAO;KACd,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,8BAA8B,CAAC,OAAsB,EAAE,SAAiB,EAAE,SAAiB;IAClG,OAAO,OAAO,CAAC,oCAAoC,SAAS,YAAY,EAAE;QACxE,MAAM,EAAE,MAAM;QACd,IAAI,EAAE;YACJ,EAAE,EAAE,SAAS;SACd;KACF,CAAC,CAAA;AACJ,CAAC;AAED,kBAAe,MAAM,CAAA"}
@@ -1,22 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const actions_core_1 = require("@segment/actions-core");
4
+ const util_1 = require("../util");
4
5
  const action = {
5
6
  title: 'Identify Contact',
6
- description: 'Create or Update a Contact.',
7
+ description: 'Create or update a contact in Intercom',
7
8
  defaultSubscription: 'type = "identify"',
8
- platform: 'web',
9
9
  fields: {
10
10
  role: {
11
11
  type: 'string',
12
12
  required: true,
13
- description: 'The role of the contact. Accepted values are `user` or `lead`. Can only be updated if `lead`.',
13
+ description: 'The role of the contact. Accepted values are `user` or `lead`.',
14
14
  label: 'Role',
15
- default: 'lead'
15
+ choices: [
16
+ { label: 'Lead', value: 'lead' },
17
+ { label: 'User', value: 'user' }
18
+ ]
16
19
  },
17
20
  external_id: {
18
21
  type: 'string',
19
- description: 'A unique identifier generated outside Intercom. Required if role=user and email is blank.',
22
+ description: 'A unique identifier for the contact generated outside Intercom. External ID is required if the role is `user` and email is blank.',
20
23
  label: 'External ID',
21
24
  default: {
22
25
  '@path': '$.userId'
@@ -24,8 +27,8 @@ const action = {
24
27
  },
25
28
  email: {
26
29
  type: 'string',
27
- description: "The contact's email. Required if role=user and external_id is blank.",
28
- label: 'Email',
30
+ description: "The contact's email address. Email is required if the role is `user` and External ID is blank.",
31
+ label: 'Email Address',
29
32
  format: 'email',
30
33
  default: {
31
34
  '@path': '$.traits.email'
@@ -49,7 +52,7 @@ const action = {
49
52
  },
50
53
  avatar: {
51
54
  label: 'Avatar',
52
- description: 'URL of image to be associated with contact profile.',
55
+ description: 'An image URL containing the avatar of a contact.',
53
56
  type: 'string',
54
57
  format: 'uri',
55
58
  default: {
@@ -57,43 +60,40 @@ const action = {
57
60
  }
58
61
  },
59
62
  signed_up_at: {
60
- label: 'Signed Up At',
63
+ label: 'Signed Up Timestamp',
61
64
  type: 'datetime',
62
- description: 'The timestamp when the contact was created.',
63
- default: {
64
- '@path': '$.createdAt'
65
- }
65
+ description: 'The time specified for when a contact signed up.'
66
66
  },
67
67
  last_seen_at: {
68
- label: 'Timestamp',
68
+ label: 'Last Seen Timestamp',
69
69
  type: 'datetime',
70
- description: 'The timestamp the contact was last seen.',
70
+ description: 'The time when the contact was last seen.',
71
71
  default: {
72
72
  '@path': '$.timestamp'
73
73
  }
74
74
  },
75
75
  owner_id: {
76
- label: 'Owner Id',
76
+ label: 'Owner ID',
77
77
  type: 'number',
78
- description: 'The id of an admin that has been assigned account ownership of the contact.'
78
+ description: 'The ID of an admin that has been assigned account ownership of the contact.'
79
79
  },
80
80
  unsubscribed_from_emails: {
81
81
  label: 'Unsubscribed From Emails',
82
82
  type: 'boolean',
83
- description: 'Whether the contact is unsubscribed from emails.'
83
+ description: "The contact's email unsubscribe status."
84
84
  },
85
85
  custom_attributes: {
86
86
  label: 'Custom Attributes',
87
- description: 'The custom attributes which are set for the contact. Note: Will throw an error if the object has an attribute that isn`t explicitly defined on Intercom.',
87
+ description: 'The custom attributes which are set for the contact. You can only write to custom attributes that already exist in your Intercom workspace. Please ensure custom attributes are created in Intercom first. See [Intercom documentation](https://developers.intercom.com/intercom-api-reference/reference/create-data-attributes) for more information on creating attributes.',
88
88
  type: 'object',
89
- default: {
90
- '@path': '$.traits.customAttributes'
91
- }
89
+ defaultObjectUI: 'keyvalue'
92
90
  }
93
91
  },
94
92
  perform: async (request, { payload }) => {
93
+ payload.signed_up_at = util_1.convertValidTimestamp(payload.signed_up_at);
94
+ payload.last_seen_at = util_1.convertValidTimestamp(payload.last_seen_at);
95
95
  try {
96
- const contact = await searchIntercomContact(request, payload);
96
+ const contact = await util_1.getUniqueIntercomContact(request, payload);
97
97
  if (contact) {
98
98
  return updateIntercomContact(request, contact.id, payload);
99
99
  }
@@ -113,40 +113,10 @@ async function createIntercomContact(request, payload) {
113
113
  json: payload
114
114
  });
115
115
  }
116
- async function searchIntercomContact(request, payload) {
117
- const searchFields = {
118
- email: payload.email,
119
- external_id: payload.external_id,
120
- role: payload.role
121
- };
122
- const value = [];
123
- for (const [key, fieldValue] of Object.entries(searchFields)) {
124
- if (fieldValue) {
125
- value.push({
126
- field: key,
127
- operator: '=',
128
- value: fieldValue
129
- });
130
- }
131
- }
132
- const query = {
133
- operator: 'AND',
134
- value
135
- };
136
- const response = await request('https://api.intercom.io/contacts/search', {
137
- method: 'POST',
138
- json: { query }
139
- });
140
- if (response.data.total_count === 1) {
141
- return response.data.data[0];
142
- }
143
- }
144
116
  async function updateIntercomContact(request, contactId, payload) {
145
117
  return request(`https://api.intercom.io/contacts/${contactId}`, {
146
118
  method: 'PUT',
147
- json: {
148
- ...payload
149
- }
119
+ json: payload
150
120
  });
151
121
  }
152
122
  exports.default = action;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/intercom/identifyContact/index.ts"],"names":[],"mappings":";;AAAA,wDAAyG;AAazG,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,kBAAkB;IACzB,WAAW,EAAE,6BAA6B;IAC1C,mBAAmB,EAAE,mBAAmB;IACxC,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,+FAA+F;YAC5G,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,MAAM;SAChB;QACD,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,2FAA2F;YACxG,KAAK,EAAE,aAAa;YACpB,OAAO,EAAE;gBACP,OAAO,EAAE,UAAU;aACpB;SACF;QACD,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,sEAAsE;YACnF,KAAK,EAAE,OAAO;YACd,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,OAAO,EAAE,gBAAgB;aAC1B;SACF;QACD,KAAK,EAAE;YACL,KAAK,EAAE,cAAc;YACrB,WAAW,EAAE,6BAA6B;YAC1C,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,OAAO,EAAE,gBAAgB;aAC1B;SACF;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,qBAAqB;YAClC,KAAK,EAAE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EAAE,OAAgB;IAC9F,OAAO,OAAO,CAAC,oCAAoC,SAAS,EAAE,EAAE;QAC9D,MAAM,EAAE,KAAK;QACb,IAAI,EAAE;YACJ,GAAG,OAAO;SACX;KACF,CAAC,CAAA;AACJ,CAAC;AAED,kBAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/intercom/identifyContact/index.ts"],"names":[],"mappings":";;AAAA,wDAAuF;AAEvF,kCAAyE;AAGzE,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,kBAAkB;IACzB,WAAW,EAAE,wCAAwC;IACrD,mBAAmB,EAAE,mBAAmB;IACxC,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,gEAAgE;YAC7E,KAAK,EAAE,MAAM;YACb,OAAO,EAAE;gBACP,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;gBAChC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;aACjC;SACF;QACD,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,mIAAmI;YACrI,KAAK,EAAE,aAAa;YACpB,OAAO,EAAE;gBACP,OAAO,EAAE,UAAU;aACpB;SACF;QACD,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,gGAAgG;YAC7G,KAAK,EAAE,eAAe;YACtB,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,OAAO,EAAE,gBAAgB;aAC1B;SACF;QACD,KAAK,EAAE;YACL,KAAK,EAAE,cAAc;YACrB,WAAW,EAAE,6BAA6B;YAC1C,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE;gBACP,OAAO,EAAE,gBAAgB;aAC1B;SACF;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,qBAAqB;YAClC,KAAK,E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;YACD,OAAO,MAAM,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;SACrD;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,GAAG,EAAE;gBAEnC,MAAM,IAAI,6BAAc,CACtB,wHAAwH,CACzH,CAAA;aACF;YACD,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CACF,CAAA;AAED,KAAK,UAAU,qBAAqB,CAAC,OAAsB,EAAE,OAAgB;IAC3E,OAAO,OAAO,CAAC,kCAAkC,EAAE;QACjD,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,OAAO;KACd,CAAC,CAAA;AACJ,CAAC;AAED,KAAK,UAAU,qBAAqB,CAAC,OAAsB,EAAE,SAAiB,EAAE,OAAgB;IAC9F,OAAO,OAAO,CAAC,oCAAoC,SAAS,EAAE,EAAE;QAC9D,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,OAAO;KACd,CAAC,CAAA;AACJ,CAAC;AAED,kBAAe,MAAM,CAAA"}
@@ -1,4 +1,4 @@
1
- import type { DestinationDefinition } from '@segment/actions-core';
1
+ import { DestinationDefinition } from '@segment/actions-core';
2
2
  import type { Settings } from './generated-types';
3
3
  declare const destination: DestinationDefinition<Settings>;
4
4
  export default destination;