@segment/action-destinations 3.310.0 → 3.311.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 (66) hide show
  1. package/dist/destinations/facebook-conversions-api/addToCart/generated-types.d.ts +1 -0
  2. package/dist/destinations/facebook-conversions-api/custom/generated-types.d.ts +1 -0
  3. package/dist/destinations/facebook-conversions-api/fb-capi-user-data.js +6 -0
  4. package/dist/destinations/facebook-conversions-api/fb-capi-user-data.js.map +1 -1
  5. package/dist/destinations/facebook-conversions-api/initiateCheckout/generated-types.d.ts +1 -0
  6. package/dist/destinations/facebook-conversions-api/pageView/generated-types.d.ts +1 -0
  7. package/dist/destinations/facebook-conversions-api/purchase/generated-types.d.ts +1 -0
  8. package/dist/destinations/facebook-conversions-api/search/generated-types.d.ts +1 -0
  9. package/dist/destinations/facebook-conversions-api/viewContent/generated-types.d.ts +1 -0
  10. package/dist/destinations/google-enhanced-conversions/functions.d.ts +1 -1
  11. package/dist/destinations/google-enhanced-conversions/functions.js +1 -1
  12. package/dist/destinations/google-enhanced-conversions/uploadCallConversion/index.js +2 -2
  13. package/dist/destinations/google-enhanced-conversions/uploadCallConversion2/index.js +2 -2
  14. package/dist/destinations/google-enhanced-conversions/uploadClickConversion/index.js +2 -2
  15. package/dist/destinations/google-enhanced-conversions/uploadClickConversion2/index.js +2 -2
  16. package/dist/destinations/google-enhanced-conversions/userList/index.js +2 -2
  17. package/dist/destinations/google-sheets/googleapis/index.js +2 -0
  18. package/dist/destinations/google-sheets/googleapis/index.js.map +1 -1
  19. package/dist/destinations/hubspot/customEvent/client.d.ts +10 -0
  20. package/dist/destinations/hubspot/customEvent/client.js +38 -0
  21. package/dist/destinations/hubspot/customEvent/client.js.map +1 -0
  22. package/dist/destinations/hubspot/customEvent/common-fields.js +7 -3
  23. package/dist/destinations/hubspot/customEvent/common-fields.js.map +1 -1
  24. package/dist/destinations/hubspot/customEvent/constants.d.ts +4 -0
  25. package/dist/destinations/hubspot/customEvent/constants.js +141 -1
  26. package/dist/destinations/hubspot/customEvent/constants.js.map +1 -1
  27. package/dist/destinations/hubspot/customEvent/dynamic-fields.js +11 -5
  28. package/dist/destinations/hubspot/customEvent/dynamic-fields.js.map +1 -1
  29. package/dist/destinations/hubspot/customEvent/index.d.ts +1 -1
  30. package/dist/destinations/hubspot/customEvent/index.js +54 -16
  31. package/dist/destinations/hubspot/customEvent/index.js.map +1 -1
  32. package/dist/destinations/hubspot/customEvent/types.d.ts +93 -0
  33. package/dist/destinations/hubspot/customEvent/types.js +10 -0
  34. package/dist/destinations/hubspot/customEvent/types.js.map +1 -0
  35. package/dist/destinations/hubspot/customEvent/utils.d.ts +12 -0
  36. package/dist/destinations/hubspot/customEvent/utils.js +278 -0
  37. package/dist/destinations/hubspot/customEvent/utils.js.map +1 -0
  38. package/dist/destinations/hubspot/upsertObject/client.d.ts +11 -0
  39. package/dist/destinations/hubspot/upsertObject/client.js +39 -0
  40. package/dist/destinations/hubspot/upsertObject/client.js.map +1 -0
  41. package/dist/destinations/hubspot/upsertObject/common-fields.js +14 -7
  42. package/dist/destinations/hubspot/upsertObject/common-fields.js.map +1 -1
  43. package/dist/destinations/hubspot/upsertObject/constants.d.ts +1 -0
  44. package/dist/destinations/hubspot/upsertObject/constants.js +2 -1
  45. package/dist/destinations/hubspot/upsertObject/constants.js.map +1 -1
  46. package/dist/destinations/hubspot/upsertObject/dynamic-fields.js.map +1 -1
  47. package/dist/destinations/hubspot/upsertObject/index.js +36 -35
  48. package/dist/destinations/hubspot/upsertObject/index.js.map +1 -1
  49. package/dist/destinations/hubspot/upsertObject/types.d.ts +192 -0
  50. package/dist/destinations/hubspot/upsertObject/types.js +56 -0
  51. package/dist/destinations/hubspot/upsertObject/types.js.map +1 -0
  52. package/dist/destinations/hubspot/upsertObject/utils.d.ts +13 -0
  53. package/dist/destinations/hubspot/upsertObject/utils.js +548 -0
  54. package/dist/destinations/hubspot/upsertObject/utils.js.map +1 -0
  55. package/dist/destinations/linkedin-conversions/index.js +14 -2
  56. package/dist/destinations/linkedin-conversions/index.js.map +1 -1
  57. package/dist/destinations/loops/createOrUpdateContact/generated-types.d.ts +4 -0
  58. package/dist/destinations/loops/createOrUpdateContact/index.js +48 -2
  59. package/dist/destinations/loops/createOrUpdateContact/index.js.map +1 -1
  60. package/package.json +2 -2
  61. package/dist/destinations/hubspot/customEvent/hubspot-api.d.ts +0 -62
  62. package/dist/destinations/hubspot/customEvent/hubspot-api.js +0 -305
  63. package/dist/destinations/hubspot/customEvent/hubspot-api.js.map +0 -1
  64. package/dist/destinations/hubspot/upsertObject/hubspot-api.d.ts +0 -221
  65. package/dist/destinations/hubspot/upsertObject/hubspot-api.js +0 -617
  66. package/dist/destinations/hubspot/upsertObject/hubspot-api.js.map +0 -1
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const actions_core_1 = require("@segment/actions-core");
4
- const hubspot_api_1 = require("./hubspot-api");
5
3
  const common_fields_1 = require("./common-fields");
4
+ const client_1 = require("./client");
5
+ const actions_core_1 = require("@segment/actions-core");
6
6
  const dynamic_fields_1 = require("./dynamic-fields");
7
+ const types_1 = require("./types");
8
+ const utils_1 = require("./utils");
7
9
  const action = {
8
10
  title: 'Custom Event',
9
11
  description: 'Send Custom Events to HubSpot',
@@ -12,9 +14,9 @@ const action = {
12
14
  label: 'Sync Mode',
13
15
  default: 'update',
14
16
  choices: [
15
- { label: 'Create new event schemas, and update existing event schemas', value: 'upsert' },
16
- { label: 'Create new event schemas, but do not update existing event schemas', value: 'add' },
17
- { label: 'Update existing event schemas, but do not create new event schemas', value: 'update' }
17
+ { label: 'Create new and update existing custom event definitions', value: 'upsert' },
18
+ { label: 'Create new, but do not update existing custom event definitions', value: 'add' },
19
+ { label: 'Update existing, but do ot create new custom event definitions', value: 'update' }
18
20
  ]
19
21
  },
20
22
  fields: {
@@ -40,20 +42,56 @@ const action = {
40
42
  }
41
43
  },
42
44
  perform: async (request, { payload, syncMode }) => {
43
- if (!payload.record_details.object_id && !payload.record_details.email && !payload.record_details.utk) {
44
- throw new actions_core_1.PayloadValidationError('At least one of object_id, email or utk is required');
45
- }
46
- if (payload.record_details.object_id && typeof payload.record_details.object_id !== 'number') {
47
- throw new actions_core_1.PayloadValidationError('Object ID must be numeric');
45
+ return await send(request, payload, syncMode);
46
+ }
47
+ };
48
+ const send = async (request, payload, syncMode) => {
49
+ const client = new client_1.Client(request);
50
+ const validPayload = utils_1.validate(payload);
51
+ const schema = utils_1.eventSchema(validPayload);
52
+ const cacheSchemaDiff = await utils_1.compareToCache(schema);
53
+ switch (cacheSchemaDiff.match) {
54
+ case types_1.SchemaMatch.FullMatch: {
55
+ return await utils_1.sendEvent(client, cacheSchemaDiff?.fullyQualifiedName, validPayload);
48
56
  }
49
- if (payload.record_details.email && payload.record_details.object_type !== 'contact') {
50
- throw new actions_core_1.PayloadValidationError('Email can only be used to associate an event with a Contacts object');
57
+ case types_1.SchemaMatch.Mismatch: {
58
+ throw new actions_core_1.IntegrationError('Cache schema mismatch.', 'CACHE_SCHEMA_MISMATCH', 400);
51
59
  }
52
- if (payload.record_details.utk && payload.record_details.object_type !== 'contact') {
53
- throw new actions_core_1.PayloadValidationError('User Token can only be used to associate an event with a Contacts object');
60
+ case types_1.SchemaMatch.NoMatch:
61
+ case types_1.SchemaMatch.PropertiesMissing: {
62
+ const hubspotSchemaDiff = await utils_1.compareToHubspot(client, schema);
63
+ switch (hubspotSchemaDiff.match) {
64
+ case types_1.SchemaMatch.FullMatch: {
65
+ const fullyQualifiedName = hubspotSchemaDiff?.fullyQualifiedName;
66
+ const name = hubspotSchemaDiff?.name;
67
+ await utils_1.saveSchemaToCache(fullyQualifiedName, name, schema);
68
+ return await utils_1.sendEvent(client, fullyQualifiedName, validPayload);
69
+ }
70
+ case types_1.SchemaMatch.Mismatch: {
71
+ throw new actions_core_1.IntegrationError('Hubspot schema mismatch.', 'HUBSPOT_SCHEMA_MISMATCH', 400);
72
+ }
73
+ case types_1.SchemaMatch.NoMatch: {
74
+ if (syncMode === 'update') {
75
+ throw new actions_core_1.IntegrationError(`The 'Sync Mode' setting is set to 'update' which is stopping Segment from creating a new Custom Event Schema in the HubSpot`, 'HUBSPOT_SCHEMA_MISSING', 400);
76
+ }
77
+ const schemaDiff = await utils_1.createHubspotEventSchema(client, schema);
78
+ const fullyQualifiedName = schemaDiff?.fullyQualifiedName;
79
+ const name = schemaDiff?.name;
80
+ await utils_1.saveSchemaToCache(fullyQualifiedName, name, schema);
81
+ return await utils_1.sendEvent(client, fullyQualifiedName, validPayload);
82
+ }
83
+ case types_1.SchemaMatch.PropertiesMissing: {
84
+ if (syncMode === 'add') {
85
+ throw new actions_core_1.IntegrationError(`The 'Sync Mode' setting is set to 'add' which is stopping Segment from creating a new properties on the Event Schema in the HubSpot`, 'HUBSPOT_SCHEMA_PROPERTIES_MISSING', 400);
86
+ }
87
+ const fullyQualifiedName = hubspotSchemaDiff?.fullyQualifiedName;
88
+ const name = hubspotSchemaDiff?.name;
89
+ await utils_1.updateHubspotSchema(client, fullyQualifiedName, hubspotSchemaDiff);
90
+ await utils_1.saveSchemaToCache(fullyQualifiedName, name, schema);
91
+ return await utils_1.sendEvent(client, fullyQualifiedName, validPayload);
92
+ }
93
+ }
54
94
  }
55
- const hubspotClient = new hubspot_api_1.HubspotClient(request, syncMode);
56
- return await hubspotClient.send(payload);
57
95
  }
58
96
  };
59
97
  exports.default = action;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/hubspot/customEvent/index.ts"],"names":[],"mappings":";;AAAA,wDAAgF;AAGhF,+CAAuD;AACvD,mDAA8C;AAE9C,qDAAuG;AAEvG,MAAM,MAAM,GAAwC;IAClD,KAAK,EAAE,cAAc;IACrB,WAAW,EAAE,+BAA+B;IAC5C,QAAQ,EAAE;QACR,WAAW,EAAE,4DAA4D;QACzE,KAAK,EAAE,WAAW;QAClB,OAAO,EAAE,QAAQ;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CAAC,iBAAiB,CAAC,CAAC;oBAClC,IAAI,QAAQ,KAAK,KAAK,EAAE;wBACtB,MAAM,IAAI,+BAAgB,CACxB,qIAAqI,EACrI,mCAAmC,EACnC,GAAG,CACJ,CAAA;qBACF;oBAED,MAAM,kBAAkB,GAAG,iBAAiB,EAAE,kBAA4B,CAAA;oBAC1E,MAAM,IAAI,GAAG,iBAAiB,EAAE,IAAc,CAAA;oBAC9C,MAAM,2BAAmB,CAAC,MAAM,EAAE,kBAAkB,EAAE,iBAAiB,CAAC,CAAA;oBACxE,MAAM,yBAAiB,CAAC,kBAAkB,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;oBACzD,OAAO,MAAM,iBAAS,CAAC,MAAM,EAAE,kBAAkB,EAAE,YAAY,CAAC,CAAA;iBACjE;aACF;SACF;KACF;AACH,CAAC,CAAA;AAED,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,93 @@
1
+ export declare type SyncMode = 'upsert' | 'add' | 'update';
2
+ export declare type StringFormat = 'date' | 'datetime' | 'string';
3
+ export declare type SegmentPropertyType = 'number' | 'object' | 'boolean' | 'string';
4
+ export interface SegmentProperty {
5
+ type: SegmentPropertyType;
6
+ stringFormat?: StringFormat;
7
+ }
8
+ export declare const SchemaMatch: {
9
+ readonly FullMatch: "full_match";
10
+ readonly PropertiesMissing: "properties_missing";
11
+ readonly NoMatch: "no_match";
12
+ readonly Mismatch: "mismatch";
13
+ };
14
+ export declare type SchemaMatch = typeof SchemaMatch[keyof typeof SchemaMatch];
15
+ export interface SchemaDiff {
16
+ match: SchemaMatch;
17
+ fullyQualifiedName?: string;
18
+ name?: string;
19
+ missingProperties: {
20
+ [key: string]: SegmentProperty;
21
+ };
22
+ }
23
+ export interface Schema {
24
+ eventName: string;
25
+ properties: {
26
+ [key: string]: SegmentProperty;
27
+ };
28
+ primaryObject: string;
29
+ }
30
+ export declare type HubspotPropertyType = 'string' | 'number' | 'enumeration' | 'datetime';
31
+ export interface GetEventDefinitionResp {
32
+ archived: boolean;
33
+ fullyQualifiedName: string;
34
+ name: string;
35
+ properties: Array<{
36
+ archived: boolean;
37
+ name: string;
38
+ type: HubspotPropertyType;
39
+ }>;
40
+ }
41
+ export interface CreateEventDefinitionResp {
42
+ fullyQualifiedName: string;
43
+ name: string;
44
+ }
45
+ export interface CreatePropertyDefintionReq {
46
+ name: string;
47
+ label: string;
48
+ type: HubspotPropertyType;
49
+ description: string;
50
+ options?: Array<{
51
+ label: string;
52
+ value: boolean;
53
+ description: string;
54
+ hidden: boolean;
55
+ displayOrder: number;
56
+ }>;
57
+ }
58
+ export interface CreateEventDefinitionReq {
59
+ label: string;
60
+ name: string;
61
+ description: string;
62
+ primaryObject: string;
63
+ propertyDefinitions: Array<CreatePropertyDefintionReq>;
64
+ }
65
+ export interface CreateEventDefinitionRespErr {
66
+ response: {
67
+ data: {
68
+ message: string;
69
+ status: string;
70
+ category: string;
71
+ };
72
+ };
73
+ }
74
+ export interface CreatePropertyRegectedResp {
75
+ data: {
76
+ status: string;
77
+ message?: string;
78
+ propertiesErrorCode?: string;
79
+ };
80
+ }
81
+ export interface ErrorResponse {
82
+ code: string;
83
+ }
84
+ export interface EventCompletionReq {
85
+ eventName: string;
86
+ objectId?: number | undefined;
87
+ email?: string | undefined;
88
+ utk?: string | undefined;
89
+ occurredAt: string | number | undefined;
90
+ properties?: {
91
+ [k: string]: unknown;
92
+ } | undefined;
93
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaMatch = void 0;
4
+ exports.SchemaMatch = {
5
+ FullMatch: 'full_match',
6
+ PropertiesMissing: 'properties_missing',
7
+ NoMatch: 'no_match',
8
+ Mismatch: 'mismatch'
9
+ };
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/destinations/hubspot/customEvent/types.ts"],"names":[],"mappings":";;;AAUa,QAAA,WAAW,GAAG;IACzB,SAAS,EAAE,YAAY;IACvB,iBAAiB,EAAE,oBAAoB;IACvC,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,UAAU;CACZ,CAAA"}
@@ -0,0 +1,12 @@
1
+ import type { Payload } from './generated-types';
2
+ import { Schema, SchemaDiff } from './types';
3
+ import { Client } from './client';
4
+ export declare function validate(payload: Payload): Payload;
5
+ export declare function cleanEventName(str: string): string;
6
+ export declare function eventSchema(payload: Payload): Schema;
7
+ export declare function compareToCache(_schema: Schema): Promise<SchemaDiff>;
8
+ export declare function compareToHubspot(client: Client, schema: Schema): Promise<SchemaDiff>;
9
+ export declare function saveSchemaToCache(_fullyQualifiedName: string, _name: string, _schema: Schema): Promise<void>;
10
+ export declare function sendEvent(client: Client, fullyQualifiedName: string, payload: Payload): Promise<import("@segment/actions-core/src").ModifiedResponse<unknown>>;
11
+ export declare function createHubspotEventSchema(client: Client, schema: Schema): Promise<SchemaDiff>;
12
+ export declare function updateHubspotSchema(client: Client, fullyQualifiedName: string, schemaDiff: SchemaDiff): Promise<void>;
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateHubspotSchema = exports.createHubspotEventSchema = exports.sendEvent = exports.saveSchemaToCache = exports.compareToHubspot = exports.compareToCache = exports.eventSchema = exports.cleanEventName = exports.validate = void 0;
4
+ const actions_core_1 = require("@segment/actions-core");
5
+ function validate(payload) {
6
+ if (payload.record_details.object_type !== 'contact' && typeof payload.record_details.object_id !== 'number') {
7
+ throw new actions_core_1.PayloadValidationError('object_id is required and must be numeric');
8
+ }
9
+ if (payload.record_details.object_type === 'contact' &&
10
+ typeof payload.record_details.object_id !== 'number' &&
11
+ !payload.record_details.email &&
12
+ !payload.record_details.utk) {
13
+ throw new actions_core_1.PayloadValidationError('Contact requires at least one of object_id (as number), email or utk to be provided');
14
+ }
15
+ cleanIdentifiers(payload);
16
+ payload.event_name = cleanEventName(payload.event_name);
17
+ payload.properties = cleanPropObj(payload.properties ?? {});
18
+ return payload;
19
+ }
20
+ exports.validate = validate;
21
+ function cleanIdentifiers(payload) {
22
+ if (payload.record_details.email && payload.record_details.object_type !== 'contact') {
23
+ delete payload.record_details.email;
24
+ }
25
+ if (payload.record_details.utk && payload.record_details.object_type !== 'contact') {
26
+ delete payload.record_details.utk;
27
+ }
28
+ }
29
+ function cleanEventName(str) {
30
+ return str.toLowerCase().replace(/[^a-z0-9_-]/g, '_');
31
+ }
32
+ exports.cleanEventName = cleanEventName;
33
+ function cleanPropObj(obj) {
34
+ const cleanObj = {};
35
+ if (obj === undefined) {
36
+ return undefined;
37
+ }
38
+ Object.keys(obj).forEach((key) => {
39
+ const value = obj[key];
40
+ const cleanKey = cleanProp(key);
41
+ if (typeof value === 'boolean' || typeof value === 'number') {
42
+ cleanObj[cleanKey] = value;
43
+ }
44
+ else if (typeof value === 'string' && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
45
+ cleanObj[cleanKey] = value.toLowerCase() === 'true';
46
+ }
47
+ else if (!isNaN(Number(value))) {
48
+ cleanObj[cleanKey] = Number(value);
49
+ }
50
+ else if (typeof value === 'object' && value !== null) {
51
+ cleanObj[cleanKey] = JSON.stringify(value);
52
+ }
53
+ else {
54
+ cleanObj[cleanKey] = String(value);
55
+ }
56
+ });
57
+ return cleanObj;
58
+ }
59
+ function cleanProp(str) {
60
+ str = str.toLowerCase().replace(/[^a-z0-9_]/g, '_');
61
+ if (!/^[a-z]/.test(str)) {
62
+ throw new actions_core_1.PayloadValidationError(`Property ${str} in event has an invalid name. Property names must start with a letter.`);
63
+ }
64
+ return str;
65
+ }
66
+ function stringFormat(str) {
67
+ const date = new Date(str);
68
+ if (isNaN(date.getTime())) {
69
+ return 'string';
70
+ }
71
+ const year = date.getUTCFullYear();
72
+ const month = date.getUTCMonth();
73
+ const day = date.getUTCDate();
74
+ const hours = date.getUTCHours();
75
+ const minutes = date.getUTCMinutes();
76
+ const seconds = date.getUTCSeconds();
77
+ const milliseconds = date.getUTCMilliseconds();
78
+ if (hours === 0 && minutes === 0 && seconds === 0 && milliseconds === 0) {
79
+ const reconstructedDate = new Date(Date.UTC(year, month, day));
80
+ if (reconstructedDate.getTime() === date.getTime()) {
81
+ return 'date';
82
+ }
83
+ else {
84
+ return 'datetime';
85
+ }
86
+ }
87
+ return 'datetime';
88
+ }
89
+ function propertyBody(eventName, type, name, stringFormat) {
90
+ switch (type) {
91
+ case 'number':
92
+ return {
93
+ name: name,
94
+ label: name,
95
+ type: 'number',
96
+ description: `${name} - (created by Segment)`
97
+ };
98
+ case 'object':
99
+ return {
100
+ name: name,
101
+ label: name,
102
+ type: 'string',
103
+ description: `${name} - (created by Segment)`
104
+ };
105
+ case 'boolean':
106
+ return {
107
+ name: name,
108
+ label: name,
109
+ type: 'enumeration',
110
+ description: `${name} - (created by Segment)`,
111
+ options: [
112
+ {
113
+ label: 'true',
114
+ value: true,
115
+ hidden: false,
116
+ description: 'True',
117
+ displayOrder: 1
118
+ },
119
+ {
120
+ label: 'false',
121
+ value: false,
122
+ hidden: false,
123
+ description: 'False',
124
+ displayOrder: 2
125
+ }
126
+ ]
127
+ };
128
+ case 'string':
129
+ switch (stringFormat) {
130
+ case 'string':
131
+ return {
132
+ name: name,
133
+ label: name,
134
+ type: 'string',
135
+ description: `${name} - (created by Segment)`
136
+ };
137
+ case 'date':
138
+ case 'datetime':
139
+ return {
140
+ name: name,
141
+ label: name,
142
+ type: 'datetime',
143
+ description: `${name} - (created by Segment)`
144
+ };
145
+ case undefined:
146
+ default:
147
+ throw new actions_core_1.PayloadValidationError(`Property ${name} in event ${eventName} has an unsupported type: ${type}`);
148
+ }
149
+ default:
150
+ throw new actions_core_1.PayloadValidationError(`Property ${name} in event ${eventName} has an unsupported type: ${type}`);
151
+ }
152
+ }
153
+ function eventSchema(payload) {
154
+ const { event_name, properties } = payload;
155
+ const props = {};
156
+ if (properties) {
157
+ Object.entries(properties).forEach(([property, value]) => {
158
+ if (value !== null) {
159
+ props[property] = {
160
+ type: typeof value,
161
+ stringFormat: typeof value === 'string' ? stringFormat(value) : undefined
162
+ };
163
+ }
164
+ });
165
+ }
166
+ return { eventName: event_name, primaryObject: payload.record_details.object_type, properties: props };
167
+ }
168
+ exports.eventSchema = eventSchema;
169
+ async function compareToCache(_schema) {
170
+ const schemaDiff = {
171
+ match: 'no_match',
172
+ missingProperties: {}
173
+ };
174
+ return Promise.resolve(schemaDiff);
175
+ }
176
+ exports.compareToCache = compareToCache;
177
+ async function compareToHubspot(client, schema) {
178
+ const mismatchSchemaDiff = { match: 'mismatch', missingProperties: {} };
179
+ try {
180
+ const { fullyQualifiedName, name, properties: hsProperties, archived } = await client.getEventDefinition(schema.eventName);
181
+ if (archived) {
182
+ return mismatchSchemaDiff;
183
+ }
184
+ const schemaDiff = { missingProperties: {} };
185
+ for (const propName in schema.properties) {
186
+ const matchedProperty = hsProperties.find((hsProp) => hsProp.name === propName);
187
+ if (matchedProperty?.archived === true) {
188
+ return mismatchSchemaDiff;
189
+ }
190
+ const prop = schema.properties[propName];
191
+ if ((['object', 'string', 'boolean'].includes(prop.type) && matchedProperty?.type === 'number') ||
192
+ (['datetime', 'string', 'enumeration'].includes(matchedProperty?.type) && prop.type === 'number')) {
193
+ return mismatchSchemaDiff;
194
+ }
195
+ if (!matchedProperty) {
196
+ schemaDiff.missingProperties[propName] = schema.properties[propName];
197
+ }
198
+ }
199
+ schemaDiff.match = Object.keys(schemaDiff.missingProperties).length === 0 ? 'full_match' : 'properties_missing';
200
+ schemaDiff.fullyQualifiedName = fullyQualifiedName;
201
+ schemaDiff.name = name;
202
+ return schemaDiff;
203
+ }
204
+ catch {
205
+ return { match: 'no_match', missingProperties: {} };
206
+ }
207
+ }
208
+ exports.compareToHubspot = compareToHubspot;
209
+ async function saveSchemaToCache(_fullyQualifiedName, _name, _schema) {
210
+ return;
211
+ }
212
+ exports.saveSchemaToCache = saveSchemaToCache;
213
+ async function sendEvent(client, fullyQualifiedName, payload) {
214
+ const { record_details, properties, occurred_at: occurredAt } = payload;
215
+ const eventName = fullyQualifiedName;
216
+ const json = {
217
+ eventName,
218
+ objectId: record_details.object_id ?? undefined,
219
+ email: record_details.email ?? undefined,
220
+ utk: record_details.utk ?? undefined,
221
+ occurredAt,
222
+ properties: properties
223
+ };
224
+ return await client.send(json);
225
+ }
226
+ exports.sendEvent = sendEvent;
227
+ async function createHubspotEventSchema(client, schema) {
228
+ const json = {
229
+ label: schema.eventName,
230
+ name: schema.eventName,
231
+ description: `${schema.eventName} - (created by Segment)`,
232
+ primaryObject: schema.primaryObject,
233
+ propertyDefinitions: Object.entries(schema.properties).map(([name, { type, stringFormat }]) => {
234
+ return propertyBody(schema.eventName, type, name, stringFormat);
235
+ })
236
+ };
237
+ try {
238
+ const response = await client.createEventDefinition(json);
239
+ return {
240
+ match: 'full_match',
241
+ fullyQualifiedName: response.fullyQualifiedName,
242
+ name: response.name
243
+ };
244
+ }
245
+ catch (error) {
246
+ const responseError = error;
247
+ if (responseError.response.data.category === 'OBJECT_ALREADY_EXISTS') {
248
+ throw new actions_core_1.RetryableError();
249
+ }
250
+ throw new actions_core_1.IntegrationError(`Error creating schema in HubSpot. ${responseError.response.data.message}`, 'HUBSPOT_CREATE_SCHEMA_ERROR', 400);
251
+ }
252
+ }
253
+ exports.createHubspotEventSchema = createHubspotEventSchema;
254
+ async function updateHubspotSchema(client, fullyQualifiedName, schemaDiff) {
255
+ const requests = [];
256
+ try {
257
+ Object.keys(schemaDiff.missingProperties).forEach((propName) => {
258
+ const { type, stringFormat } = schemaDiff.missingProperties[propName];
259
+ const json = propertyBody(schemaDiff?.fullyQualifiedName, type, propName, stringFormat);
260
+ requests.push(client.createPropertyDefinition(json, fullyQualifiedName));
261
+ });
262
+ const responses = await Promise.allSettled(requests);
263
+ for (const response of responses) {
264
+ if (response.status === 'rejected') {
265
+ const error = response.reason;
266
+ if (error.data.propertiesErrorCode !== 'PROPERTY_EXISTS') {
267
+ throw new actions_core_1.IntegrationError(`Error updating schema in HubSpot. ${error.data.message || ''} ${error.data.propertiesErrorCode || ''}`, 'HUBSPOT_UPDATE_SCHEMA_ERROR', 400);
268
+ }
269
+ }
270
+ }
271
+ }
272
+ catch (error) {
273
+ const responseError = error;
274
+ throw new actions_core_1.IntegrationError(`Error updating schema in HubSpot. ${responseError.code}`, `${responseError.code}`, 400);
275
+ }
276
+ }
277
+ exports.updateHubspotSchema = updateHubspotSchema;
278
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/destinations/hubspot/customEvent/utils.ts"],"names":[],"mappings":";;;AAAA,wDAAgG;AAiBhG,SAAgB,QAAQ,CAAC,OAAgB;IACvC,IAAI,OAAO,CAAC,cAAc,CAAC,WAAW,KAAK,SAAS,IAAI,OAAO,OAAO,CAAC,cAAc,CAAC,SAAS,KAAK,QAAQ,EAAE;QAC5G,MAAM,IAAI,qCAAsB,CAAC,2CAA2C,CAAC,CAAA;KAC9E;IAED,IACE,OAAO,CAAC,cAAc,CAAC,WAAW,KAAK,SAAS;QAChD,OAAO,OAAO,CAAC,cAAc,CAAC,SAAS,KAAK,QAAQ;QACpD,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK;QAC7B,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,EAC3B;QACA,MAAM,IAAI,qCAAsB,CAC9B,qFAAqF,CACtF,CAAA;KACF;IAED,gBAAgB,CAAC,OAAO,CAAC,CAAA;IACzB,OAAO,CAAC,UAAU,GAAG,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACvD,OAAO,CAAC,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,CAAA;IAE3D,OAAO,OAAO,CAAA;AAChB,CAAC;AArBD,4BAqBC;AAED,SAAS,gBAAgB,CAAC,OAAgB;IACxC,IAAI,OAAO,CAAC,cAAc,CAAC,KAAK,IAAI,OAAO,CAAC,cAAc,CAAC,WAAW,KAAK,SA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AC7D,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAA;YACrE,MAAM,IAAI,GAAG,YAAY,CAAC,UAAU,EAAE,kBAA4B,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAA;YACjG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAA;QAC1E,CAAC,CAAC,CAAA;QAEF,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;QAEpD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;YAChC,IAAI,QAAQ,CAAC,MAAM,KAAK,UAAU,EAAE;gBAClC,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAoC,CAAA;gBAC3D,IAAI,KAAK,CAAC,IAAI,CAAC,mBAAmB,KAAK,iBAAiB,EAAE;oBACxD,MAAM,IAAI,+BAAgB,CACxB,qCAAqC,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC,mBAAmB,IAAI,EAAE,EAAE,EACvG,6BAA6B,EAC7B,GAAG,CACJ,CAAA;iBACF;aACF;SACF;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,aAAa,GAAG,KAAsB,CAAA;QAC5C,MAAM,IAAI,+BAAgB,CAAC,qCAAqC,aAAa,CAAC,IAAI,EAAE,EAAE,GAAG,aAAa,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,CAAA;KACpH;AACH,CAAC;AA5BD,kDA4BC"}
@@ -0,0 +1,11 @@
1
+ import { RequestClient } from '@segment/actions-core';
2
+ import { BatchAssociationsRequestBody, BatchRequestType, CreateJSON, CreatePropsDefinitionReq, ReadJSON, RespJSON, UpsertJSON } from './types';
3
+ export declare class Client {
4
+ request: RequestClient;
5
+ objectType: string;
6
+ constructor(request: RequestClient, objectType: string);
7
+ readProperties(sensitive: boolean): Promise<import("@segment/actions-core/src").ModifiedResponse<ResponseType>>;
8
+ createPropertiesDefinition(json: CreatePropsDefinitionReq): Promise<void>;
9
+ batchObjectRequest(action: BatchRequestType, objectType: string, data: ReadJSON | UpsertJSON | CreateJSON): Promise<import("@segment/actions-core/src").ModifiedResponse<RespJSON>>;
10
+ batchAssociationsRequest(body: BatchAssociationsRequestBody, toObjectType: string): Promise<import("@segment/actions-core/src").ModifiedResponse<unknown>>;
11
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Client = void 0;
4
+ const properties_1 = require("../properties");
5
+ class Client {
6
+ constructor(request, objectType) {
7
+ this.request = request;
8
+ this.objectType = objectType;
9
+ }
10
+ async readProperties(sensitive) {
11
+ const sensitivity = '?dataSensitivity=sensitive';
12
+ const url = `${properties_1.HUBSPOT_BASE_URL}/crm/v3/properties/${this.objectType}${sensitive ? sensitivity : ''}`;
13
+ return this.request(url, {
14
+ method: 'GET',
15
+ skipResponseCloning: true
16
+ });
17
+ }
18
+ async createPropertiesDefinition(json) {
19
+ await this.request(`${properties_1.HUBSPOT_BASE_URL}/crm/v3/properties/${this.objectType}/batch/create`, {
20
+ method: 'POST',
21
+ skipResponseCloning: true,
22
+ json
23
+ });
24
+ }
25
+ async batchObjectRequest(action, objectType, data) {
26
+ return this.request(`${properties_1.HUBSPOT_BASE_URL}/crm/v3/objects/${objectType}/batch/${action}`, {
27
+ method: 'POST',
28
+ json: data
29
+ });
30
+ }
31
+ async batchAssociationsRequest(body, toObjectType) {
32
+ return this.request(`${properties_1.HUBSPOT_BASE_URL}/crm/v4/associations/${this.objectType}/${toObjectType}/batch/create`, {
33
+ method: 'POST',
34
+ json: body
35
+ });
36
+ }
37
+ }
38
+ exports.Client = Client;
39
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../src/destinations/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,wBAuCC"}
@@ -17,7 +17,8 @@ exports.commonFields = {
17
17
  type: 'string',
18
18
  required: true,
19
19
  allowNull: false,
20
- dynamic: true
20
+ dynamic: true,
21
+ disabledInputMethods: ['literal', 'variable', 'function', 'freeform']
21
22
  },
22
23
  id_field_name: {
23
24
  label: 'Object ID Field Name',
@@ -25,7 +26,8 @@ exports.commonFields = {
25
26
  type: 'string',
26
27
  required: true,
27
28
  allowNull: false,
28
- dynamic: true
29
+ dynamic: true,
30
+ disabledInputMethods: ['literal', 'variable', 'function', 'freeform']
29
31
  },
30
32
  id_field_value: {
31
33
  label: 'Object ID Field Value',
@@ -40,7 +42,8 @@ exports.commonFields = {
40
42
  type: 'string',
41
43
  required: false,
42
44
  default: undefined,
43
- dynamic: true
45
+ dynamic: true,
46
+ disabledInputMethods: ['literal', 'variable', 'function', 'freeform']
44
47
  }
45
48
  }
46
49
  },
@@ -71,7 +74,8 @@ exports.commonFields = {
71
74
  choices: [
72
75
  { label: 'Create', value: 'upsert' },
73
76
  { label: 'Do not create', value: 'read' }
74
- ]
77
+ ],
78
+ disabledInputMethods: ['literal', 'variable', 'function', 'freeform']
75
79
  },
76
80
  associations: {
77
81
  label: 'Associations',
@@ -88,7 +92,8 @@ exports.commonFields = {
88
92
  type: 'string',
89
93
  required: true,
90
94
  dynamic: true,
91
- allowNull: false
95
+ allowNull: false,
96
+ disabledInputMethods: ['literal', 'variable', 'function', 'freeform']
92
97
  },
93
98
  association_label: {
94
99
  label: 'Association Label',
@@ -96,7 +101,8 @@ exports.commonFields = {
96
101
  type: 'string',
97
102
  required: true,
98
103
  dynamic: true,
99
- allowNull: false
104
+ allowNull: false,
105
+ disabledInputMethods: ['literal', 'variable', 'function', 'freeform']
100
106
  },
101
107
  id_field_name: {
102
108
  label: 'To Object ID Field Name',
@@ -104,7 +110,8 @@ exports.commonFields = {
104
110
  type: 'string',
105
111
  required: true,
106
112
  dynamic: true,
107
- allowNull: false
113
+ allowNull: false,
114
+ disabledInputMethods: ['literal', 'variable', 'function', 'freeform']
108
115
  },
109
116
  id_field_value: {
110
117
  label: 'To Object ID Field Value',