@segment/action-destinations 3.94.1-alpha.1 → 3.95.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.
Files changed (85) hide show
  1. package/dist/destinations/cordial/addProductToCart/index.js +1 -1
  2. package/dist/destinations/cordial/addProductToCart/index.js.map +1 -1
  3. package/dist/destinations/cordial/index.js +1 -1
  4. package/dist/destinations/cordial/index.js.map +1 -1
  5. package/dist/destinations/cordial/removeProductFromCart/index.js.map +1 -1
  6. package/dist/destinations/cordial/upsertOrder/index.js +8 -8
  7. package/dist/destinations/cordial/upsertOrder/index.js.map +1 -1
  8. package/dist/destinations/customerio/trackEvent/index.js.map +1 -1
  9. package/dist/destinations/engage-messaging-sendgrid/sendEmail/generated-types.d.ts +0 -9
  10. package/dist/destinations/engage-messaging-sendgrid/sendEmail/index.js +1 -57
  11. package/dist/destinations/engage-messaging-sendgrid/sendEmail/index.js.map +1 -1
  12. package/dist/destinations/engage-messaging-twilio/sendSms/generated-types.d.ts +0 -4
  13. package/dist/destinations/engage-messaging-twilio/sendSms/index.js +1 -21
  14. package/dist/destinations/engage-messaging-twilio/sendSms/index.js.map +1 -1
  15. package/dist/destinations/google-analytics-4/ga4-functions.js +4 -4
  16. package/dist/destinations/google-analytics-4/ga4-functions.js.map +1 -1
  17. package/dist/destinations/google-enhanced-conversions/postConversion/index.js +3 -5
  18. package/dist/destinations/google-enhanced-conversions/postConversion/index.js.map +1 -1
  19. package/dist/destinations/index.js +1 -3
  20. package/dist/destinations/index.js.map +1 -1
  21. package/dist/destinations/intercom/groupIdentifyContact/generated-types.d.ts +2 -0
  22. package/dist/destinations/intercom/groupIdentifyContact/index.js +44 -36
  23. package/dist/destinations/intercom/groupIdentifyContact/index.js.map +1 -1
  24. package/dist/destinations/intercom/identifyContact/index.js +24 -54
  25. package/dist/destinations/intercom/identifyContact/index.js.map +1 -1
  26. package/dist/destinations/intercom/index.d.ts +1 -1
  27. package/dist/destinations/intercom/index.js +24 -8
  28. package/dist/destinations/intercom/index.js.map +1 -1
  29. package/dist/destinations/intercom/trackEvent/generated-types.d.ts +12 -0
  30. package/dist/destinations/{actions-pardot → intercom/trackEvent}/generated-types.js +0 -0
  31. package/dist/destinations/intercom/trackEvent/generated-types.js.map +1 -0
  32. package/dist/destinations/{actions-pardot/prospects → intercom/trackEvent}/index.d.ts +0 -0
  33. package/dist/destinations/intercom/trackEvent/index.js +111 -0
  34. package/dist/destinations/intercom/trackEvent/index.js.map +1 -0
  35. package/dist/destinations/intercom/util.d.ts +11 -0
  36. package/dist/destinations/intercom/util.js +48 -0
  37. package/dist/destinations/intercom/util.js.map +1 -0
  38. package/dist/destinations/mixpanel/alias/index.js +2 -1
  39. package/dist/destinations/mixpanel/alias/index.js.map +1 -1
  40. package/dist/destinations/mixpanel/generated-types.d.ts +1 -0
  41. package/dist/destinations/mixpanel/groupIdentifyUser/index.js +2 -1
  42. package/dist/destinations/mixpanel/groupIdentifyUser/index.js.map +1 -1
  43. package/dist/destinations/mixpanel/identifyUser/index.js +4 -2
  44. package/dist/destinations/mixpanel/identifyUser/index.js.map +1 -1
  45. package/dist/destinations/mixpanel/index.js +8 -0
  46. package/dist/destinations/mixpanel/index.js.map +1 -1
  47. package/dist/destinations/mixpanel/trackEvent/index.js +1 -1
  48. package/dist/destinations/mixpanel/trackEvent/index.js.map +1 -1
  49. package/dist/destinations/mixpanel/utils.d.ts +5 -0
  50. package/dist/destinations/mixpanel/utils.js +13 -1
  51. package/dist/destinations/mixpanel/utils.js.map +1 -1
  52. package/dist/destinations/salesforce/lead/index.js +1 -2
  53. package/dist/destinations/salesforce/lead/index.js.map +1 -1
  54. package/package.json +4 -4
  55. package/dist/destinations/actions-pardot/generated-types.d.ts +0 -5
  56. package/dist/destinations/actions-pardot/generated-types.js.map +0 -1
  57. package/dist/destinations/actions-pardot/index.d.ts +0 -4
  58. package/dist/destinations/actions-pardot/index.js +0 -62
  59. package/dist/destinations/actions-pardot/index.js.map +0 -1
  60. package/dist/destinations/actions-pardot/pa-operations.d.ts +0 -17
  61. package/dist/destinations/actions-pardot/pa-operations.js +0 -51
  62. package/dist/destinations/actions-pardot/pa-operations.js.map +0 -1
  63. package/dist/destinations/actions-pardot/pa-properties.d.ts +0 -2
  64. package/dist/destinations/actions-pardot/pa-properties.js +0 -13
  65. package/dist/destinations/actions-pardot/pa-properties.js.map +0 -1
  66. package/dist/destinations/actions-pardot/pa-type.d.ts +0 -15
  67. package/dist/destinations/actions-pardot/pa-type.js +0 -3
  68. package/dist/destinations/actions-pardot/pa-type.js.map +0 -1
  69. package/dist/destinations/actions-pardot/prospects/generated-types.d.ts +0 -19
  70. package/dist/destinations/actions-pardot/prospects/generated-types.js +0 -3
  71. package/dist/destinations/actions-pardot/prospects/generated-types.js.map +0 -1
  72. package/dist/destinations/actions-pardot/prospects/index.js +0 -204
  73. package/dist/destinations/actions-pardot/prospects/index.js.map +0 -1
  74. package/dist/destinations/salesforce-marketing-cloud/contact/generated-types.d.ts +0 -2
  75. package/dist/destinations/salesforce-marketing-cloud/contact/generated-types.js +0 -3
  76. package/dist/destinations/salesforce-marketing-cloud/contact/generated-types.js.map +0 -1
  77. package/dist/destinations/salesforce-marketing-cloud/contact/index.d.ts +0 -5
  78. package/dist/destinations/salesforce-marketing-cloud/contact/index.js +0 -11
  79. package/dist/destinations/salesforce-marketing-cloud/contact/index.js.map +0 -1
  80. package/dist/destinations/salesforce-marketing-cloud/generated-types.d.ts +0 -2
  81. package/dist/destinations/salesforce-marketing-cloud/generated-types.js +0 -3
  82. package/dist/destinations/salesforce-marketing-cloud/generated-types.js.map +0 -1
  83. package/dist/destinations/salesforce-marketing-cloud/index.d.ts +0 -4
  84. package/dist/destinations/salesforce-marketing-cloud/index.js +0 -27
  85. package/dist/destinations/salesforce-marketing-cloud/index.js.map +0 -1
@@ -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,OAAO,EAAE,eAAe;aACzB;SACF;QACD,aAAa,EAAE;YACb,IAAI,EAAE,Q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K,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,8HAA8H;YAChI,KAAK,EAAE,eAAe;YACtB,MAAM,EAAE,OAAO;YACf,OAA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;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,MAAM;YACb,OAAO,EAAE;gBACP,OAAO,EAAE,eAAe;aACzB;SACF;QACD,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;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,EAAE,MAAM;YACb,OAAO,EAAE;gBACP,OAAO,EAAE,eAAe;aACzB;SACF;Q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ACrD;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;
@@ -3,17 +3,25 @@ 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 identifyContact_1 = __importDefault(require("./identifyContact"));
7
8
  const groupIdentifyContact_1 = __importDefault(require("./groupIdentifyContact"));
9
+ const trackEvent_1 = __importDefault(require("./trackEvent"));
10
+ const util_1 = require("./util");
8
11
  const destination = {
9
- name: 'Intercom (Actions)',
10
- slug: 'actions-intercom',
12
+ name: 'Intercom Cloud Mode (Actions)',
13
+ slug: 'actions-intercom-cloud',
11
14
  mode: 'cloud',
12
15
  authentication: {
13
16
  scheme: 'oauth2',
14
17
  fields: {},
15
- testAuthentication: (request) => {
16
- return request('https://api.intercom.io/admins');
18
+ testAuthentication: async (request) => {
19
+ try {
20
+ return await request('https://api.intercom.io/admins');
21
+ }
22
+ catch (error) {
23
+ throw new Error('Test authentication failed');
24
+ }
17
25
  }
18
26
  },
19
27
  extendRequest({ auth }) {
@@ -24,13 +32,21 @@ const destination = {
24
32
  };
25
33
  },
26
34
  onDelete: async (request, { payload }) => {
27
- return request(`https://api.intercom.io/contacts/${payload.userId}`, {
28
- method: 'DELETE'
29
- });
35
+ const external_id = payload.userId;
36
+ const contact = await util_1.getUniqueIntercomContact(request, { external_id });
37
+ if (contact) {
38
+ return request(`https://api.intercom.io/contacts/${payload.userId}`, {
39
+ method: 'DELETE'
40
+ });
41
+ }
42
+ else {
43
+ throw new actions_core_1.IntegrationError('No unique contact found', 'Contact not found', 404);
44
+ }
30
45
  },
31
46
  actions: {
32
47
  identifyContact: identifyContact_1.default,
33
- groupIdentifyContact: groupIdentifyContact_1.default
48
+ groupIdentifyContact: groupIdentifyContact_1.default,
49
+ trackEvent: trackEvent_1.default
34
50
  }
35
51
  };
36
52
  exports.default = destination;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/destinations/intercom/index.ts"],"names":[],"mappings":";;;;;AAEA,wEAA+C;AAC/C,kFAAyD;AAEzD,MAAM,WAAW,GAAoC;IACnD,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,OAAO;IAEb,cAAc,EAAE;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,EAAE;QACV,kBAAkB,EAAE,CAAC,OAAO,EAAE,EAAE;YAG9B,OAAO,OAAO,CAAC,gCAAgC,CAAC,CAAA;QAClD,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,QAA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oCAAoC,OAAO,CAAC,MAAM,EAAE,EAAE;gBACnE,MAAM,EAAE,QAAQ;aACjB,CAAC,CAAA;SACH;aAAM;YACL,MAAM,IAAI,+BAAgB,CAAC,yBAAyB,EAAE,mBAAmB,EAAE,GAAG,CAAC,CAAA;SAChF;IACH,CAAC;IAED,OAAO,EAAE;QACP,eAAe,EAAf,yBAAe;QACf,oBAAoB,EAApB,8BAAoB;QACpB,UAAU,EAAV,oBAAU;KACX;CACF,CAAA;AAED,kBAAe,WAAW,CAAA"}
@@ -0,0 +1,12 @@
1
+ export interface Payload {
2
+ event_name: string;
3
+ created_at: string | number;
4
+ user_id?: string;
5
+ email?: string;
6
+ revenue?: number;
7
+ currency?: string;
8
+ id?: string;
9
+ metadata?: {
10
+ [k: string]: unknown;
11
+ };
12
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../../src/destinations/intercom/trackEvent/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const actions_core_1 = require("@segment/actions-core");
4
+ const util_1 = require("../util");
5
+ const action = {
6
+ title: 'Track Event',
7
+ description: 'Submit an event to Intercom.',
8
+ defaultSubscription: 'type = "track"',
9
+ fields: {
10
+ event_name: {
11
+ type: 'string',
12
+ required: true,
13
+ description: 'The name of the event that occurred. Names are treated as case insensitive. Periods and dollar signs in event names are replaced with hyphens.',
14
+ label: 'Event Name',
15
+ default: {
16
+ '@path': '$.event'
17
+ }
18
+ },
19
+ created_at: {
20
+ type: 'datetime',
21
+ required: true,
22
+ description: 'The time the event occurred as a UTC Unix timestamp. Segment will convert to Unix if not already converted.',
23
+ label: 'Event Timestamp',
24
+ default: {
25
+ '@path': '$.timestamp'
26
+ }
27
+ },
28
+ user_id: {
29
+ type: 'string',
30
+ description: 'Your identifier for the user who performed the event. User ID is required if no email or Contact ID is provided.',
31
+ label: 'User ID',
32
+ default: {
33
+ '@path': '$.userId'
34
+ }
35
+ },
36
+ email: {
37
+ type: 'string',
38
+ description: 'The email address for the user who performed the event. Email is required if no User ID or Contact ID is provided.',
39
+ label: 'Email Address',
40
+ format: 'email',
41
+ default: {
42
+ '@path': '$.properties.email'
43
+ }
44
+ },
45
+ revenue: {
46
+ label: 'Revenue',
47
+ type: 'number',
48
+ description: 'The amount associated with a purchase. Segment will multiply by 100 as Intercom requires the amount in cents.',
49
+ default: {
50
+ '@path': '$.properties.revenue'
51
+ }
52
+ },
53
+ currency: {
54
+ label: 'Currency',
55
+ type: 'string',
56
+ description: 'The currency of the purchase amount. Segment will default to USD if revenue is provided without a currency.',
57
+ default: {
58
+ '@path': '$.properties.currency'
59
+ }
60
+ },
61
+ id: {
62
+ label: 'Contact ID',
63
+ description: "Intercom's unique identifier for the contact. If no Contact ID is provided, Segment will use User ID or Email to find a user or lead.",
64
+ type: 'string'
65
+ },
66
+ metadata: {
67
+ type: 'object',
68
+ description: 'Optional metadata describing the event. Each event can contain up to ten metadata key-value pairs. If you send more than ten keys, Intercom will ignore the rest. Intercom does not support nested JSON structures within metadata.',
69
+ label: 'Event Metadata',
70
+ default: {
71
+ '@path': '$.properties'
72
+ }
73
+ }
74
+ },
75
+ perform: async (request, { payload }) => {
76
+ payload.created_at = util_1.convertValidTimestamp(payload.created_at);
77
+ delete payload.metadata?.email;
78
+ if (payload.email && !payload.user_id && !payload.id) {
79
+ const contact = await util_1.getUniqueIntercomContact(request, payload);
80
+ if (contact) {
81
+ payload.id = contact.id;
82
+ }
83
+ else {
84
+ throw new actions_core_1.IntegrationError('No unique contact found', 'Contact not found', 404);
85
+ }
86
+ }
87
+ possiblyPopulatePrice(payload);
88
+ return request('https://api.intercom.io/events', {
89
+ method: 'POST',
90
+ json: payload
91
+ });
92
+ }
93
+ };
94
+ function possiblyPopulatePrice(payload) {
95
+ const { revenue, currency } = payload;
96
+ delete payload.revenue;
97
+ delete payload.currency;
98
+ delete payload.metadata?.revenue;
99
+ delete payload.metadata?.currency;
100
+ if (revenue || revenue === 0) {
101
+ if (!payload.metadata) {
102
+ payload.metadata = {};
103
+ }
104
+ payload.metadata.price = {
105
+ amount: revenue * 100,
106
+ currency: currency || 'USD'
107
+ };
108
+ }
109
+ }
110
+ exports.default = action;
111
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/intercom/trackEvent/index.ts"],"names":[],"mappings":";;AAAA,wDAA0E;AAE1E,kCAAyE;AAGzE,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,aAAa;IACpB,WAAW,EAAE,8BAA8B;IAC3C,mBAAmB,EAAE,gBAAgB;IACrC,MAAM,EAAE;QACN,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,WAAW,EACT,gJAAgJ;YAClJ,KAAK,EAAE,YAAY;YACnB,OAAO,EAAE;gBACP,OAAO,EAAE,SAAS;aACnB;SACF;QACD,UAAU,EAAE;YACV,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,IAAI;YACd,WAAW,EACT,6GAA6G;YAC/G,KAAK,EAAE,iBAAiB;YACxB,OAAO,EAAE;gBACP,OAAO,EAAE,aAAa;aACvB;SACF;QACD,OAAO,EAAE;YACP,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,kHAAkH;YACpH,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE;gBACP,OAAO,EAAE,UAAU;aACpB;SACF;QACD,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,oHAAoH;YACtH,KAAK,EAAE,eAAe;YACtB,MAAM,EAAE,OAAO;YACf,OAAO,EAAE;gBACP,OAAO,EAAE,oBAAoB;aAC9B;SACF;QACD,OAAO,EAAE;YACP,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,+GAA+G;YACjH,OAAO,EAAE;gBACP,OAAO,EAAE,sBAAsB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,CAAC,OAAO,CAAA;IACtB,OAAO,OAAO,CAAC,QAAQ,CAAA;IACvB,OAAO,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAA;IAChC,OAAO,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAEjC,IAAI,OAAO,IAAI,OAAO,KAAK,CAAC,EAAE;QAC5B,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACrB,OAAO,CAAC,QAAQ,GAAG,EAAE,CAAA;SACtB;QAED,OAAO,CAAC,QAAQ,CAAC,KAAK,GAAG;YACvB,MAAM,EAAE,OAAO,GAAG,GAAG;YACrB,QAAQ,EAAE,QAAQ,IAAI,KAAK;SAC5B,CAAA;KACF;AACH,CAAC;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { RequestClient } from '@segment/actions-core';
2
+ interface IntercomContact {
3
+ id: string;
4
+ }
5
+ interface SearchPayload {
6
+ external_id?: string;
7
+ email?: string;
8
+ }
9
+ export declare function getUniqueIntercomContact(request: RequestClient, payload: SearchPayload): Promise<IntercomContact | undefined>;
10
+ export declare const convertValidTimestamp: <Value = unknown>(value: Value) => number | Value;
11
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.convertValidTimestamp = exports.getUniqueIntercomContact = void 0;
7
+ const dayjs_1 = __importDefault(require("../../lib/dayjs"));
8
+ async function getUniqueIntercomContact(request, payload) {
9
+ const { external_id, email } = payload;
10
+ let query;
11
+ if (external_id) {
12
+ query = {
13
+ field: 'external_id',
14
+ operator: '=',
15
+ value: external_id
16
+ };
17
+ }
18
+ else if (email) {
19
+ query = {
20
+ field: 'email',
21
+ operator: '=',
22
+ value: email
23
+ };
24
+ }
25
+ else {
26
+ return;
27
+ }
28
+ const response = await request('https://api.intercom.io/contacts/search', {
29
+ method: 'POST',
30
+ json: { query }
31
+ });
32
+ if (response?.data?.total_count === 1) {
33
+ return response.data.data[0];
34
+ }
35
+ }
36
+ exports.getUniqueIntercomContact = getUniqueIntercomContact;
37
+ const convertValidTimestamp = (value) => {
38
+ if (typeof value !== 'string' || /^\d+$/.test(value)) {
39
+ return value;
40
+ }
41
+ const maybeDate = dayjs_1.default.utc(value);
42
+ if (maybeDate.isValid()) {
43
+ return maybeDate.unix();
44
+ }
45
+ return value;
46
+ };
47
+ exports.convertValidTimestamp = convertValidTimestamp;
48
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../../src/destinations/intercom/util.ts"],"names":[],"mappings":";;;;;;AACA,4DAAmC;AAqB5B,KAAK,UAAU,wBAAwB,CAAC,OAAsB,EAAE,OAAsB;IAC3F,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,OAAO,CAAA;IACtC,IAAI,KAAK,CAAA;IACT,IAAI,WAAW,EAAE;QACf,KAAK,GAAG;YACN,KAAK,EAAE,aAAa;YACpB,QAAQ,EAAE,GAAG;YACb,KAAK,EAAE,WAAW;SACnB,CAAA;KACF;SAAM,IAAI,KAAK,EAAE;QAChB,KAAK,GAAG;YACN,KAAK,EAAE,OAAO;YACd,QAAQ,EAAE,GAAG;YACb,KAAK,EAAE,KAAK;SACb,CAAA;KACF;SAAM;QACL,OAAM;KACP;IAED,MAAM,QAAQ,GAAyC,MAAM,OAAO,CAAC,yCAAyC,EAAE;QAC9G,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,EAAE,KAAK,EAAE;KAChB,CAAC,CAAA;IAEF,IAAI,QAAQ,EAAE,IAAI,EAAE,WAAW,KAAK,CAAC,EAAE;QACrC,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAC7B;AACH,CAAC;AA3BD,4DA2BC;AAEM,MAAM,qBAAqB,GAAG,CAAkB,KAAY,EAAkB,EAAE;IAKrF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACpD,OAAO,KAAK,CAAA;KACb;IAED,MAAM,SAAS,GAAG,eAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAElC,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE;QACvB,OAAO,SAAS,CAAC,IAAI,EAAE,CAAA;KACxB;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAhBY,QAAA,qBAAqB,yBAgBjC"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../utils");
3
4
  const action = {
4
5
  title: 'Alias',
5
6
  description: 'Create an alias to a distinct id. This action is primarily supported for the sake of customers using the legacy identity management in their Mixpanel project. For new customers or those who have [migrated](https://help.mixpanel.com/hc/en-us/articles/360039133851-Moving-to-Identity-Merge?source=segment-actions) to the [new identity management](https://help.mixpanel.com/hc/en-us/articles/360041039771-Getting-Started-with-Identity-Management?source=segment-actions) in Mixpanel should use `identify`.',
@@ -35,7 +36,7 @@ const action = {
35
36
  token: settings.projectToken
36
37
  }
37
38
  };
38
- return request('https://api.mixpanel.com/track', {
39
+ return request(`${utils_1.getApiServerUrl(settings.apiRegion)}/track`, {
39
40
  method: 'post',
40
41
  body: new URLSearchParams({ data: JSON.stringify(data) })
41
42
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/mixpanel/alias/index.ts"],"names":[],"mappings":";;AAIA,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,OAAO;IACd,WAAW,EACT,ufAAuf;IACzf,MAAM,EAAE;QACN,KAAK,EAAE;YACL,KAAK,EAAE,OAAO;YACd,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,IAAI;YACf,WAAW,EACT,2GAA2G;YAC7G,OAAO,EAAE;gBACP,KAAK,EAAE;oBACL,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;oBAC/B,IAAI,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;oBAC7B,IAAI,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE;iBACnC;aACF;SACF;QACD,WAAW,EAAE;YACX,KAAK,EAAE,aAAa;YACpB,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,4CAA4C;YACzD,OAAO,EAAE;gBACP,OAAO,EAAE,cAAc;aACxB;SACF;KACF;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;QAChD,MAAM,IAAI,GAAG;YACX,KAAK,EAAE,eAAe;YACtB,UAAU,EAAE;gBACV,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,KAAK,EAAE,QAAQ,CAAC,YAAY;aAC7B;SACF,CAAA;QAED,OAAO,OAAO,CAAC,gCAAgC,EAAE;YAC/C,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;SAC1D,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/mixpanel/alias/index.ts"],"names":[],"mappings":";;AAIA,oCAA0C;AAE1C,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,OAAO;IACd,WAAW,EACT,ufAAuf;IACzf,MAAM,EAAE;QACN,KAAK,EAAE;YACL,KAAK,EAAE,OAAO;YACd,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,IAAI;YACf,WAAW,EACT,2GAA2G;YAC7G,OAAO,EAAE;gBACP,KAAK,EAAE;oBACL,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;oBAC/B,IAAI,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE;oBAC7B,IAAI,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE;iBACnC;aACF;SACF;QACD,WAAW,EAAE;YACX,KAAK,EAAE,aAAa;YACpB,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,4CAA4C;YACzD,OAAO,EAAE;gBACP,OAAO,EAAE,cAAc;aACxB;SACF;KACF;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;QAChD,MAAM,IAAI,GAAG;YACX,KAAK,EAAE,eAAe;YACtB,UAAU,EAAE;gBACV,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,KAAK,EAAE,QAAQ,CAAC,YAAY;aAC7B;SACF,CAAA;QAED,OAAO,OAAO,CAAC,GAAG,uBAAe,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC7D,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;SAC1D,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}