@segment/action-destinations 3.310.0 → 3.312.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/destinations/facebook-conversions-api/addToCart/generated-types.d.ts +1 -0
- package/dist/destinations/facebook-conversions-api/custom/generated-types.d.ts +1 -0
- package/dist/destinations/facebook-conversions-api/fb-capi-user-data.js +6 -0
- package/dist/destinations/facebook-conversions-api/fb-capi-user-data.js.map +1 -1
- package/dist/destinations/facebook-conversions-api/initiateCheckout/generated-types.d.ts +1 -0
- package/dist/destinations/facebook-conversions-api/pageView/generated-types.d.ts +1 -0
- package/dist/destinations/facebook-conversions-api/purchase/generated-types.d.ts +1 -0
- package/dist/destinations/facebook-conversions-api/search/generated-types.d.ts +1 -0
- package/dist/destinations/facebook-conversions-api/viewContent/generated-types.d.ts +1 -0
- package/dist/destinations/google-enhanced-conversions/functions.d.ts +1 -1
- package/dist/destinations/google-enhanced-conversions/functions.js +1 -1
- package/dist/destinations/google-enhanced-conversions/uploadCallConversion/index.js +2 -2
- package/dist/destinations/google-enhanced-conversions/uploadCallConversion2/index.js +2 -2
- package/dist/destinations/google-enhanced-conversions/uploadClickConversion/index.js +2 -2
- package/dist/destinations/google-enhanced-conversions/uploadClickConversion2/index.js +2 -2
- package/dist/destinations/google-enhanced-conversions/userList/index.js +2 -2
- package/dist/destinations/google-sheets/googleapis/index.js +2 -0
- package/dist/destinations/google-sheets/googleapis/index.js.map +1 -1
- package/dist/destinations/hubspot/customEvent/client.d.ts +10 -0
- package/dist/destinations/hubspot/customEvent/client.js +39 -0
- package/dist/destinations/hubspot/customEvent/client.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/common-fields.js +7 -3
- package/dist/destinations/hubspot/customEvent/common-fields.js.map +1 -1
- package/dist/destinations/hubspot/customEvent/constants.d.ts +4 -0
- package/dist/destinations/hubspot/customEvent/constants.js +141 -1
- package/dist/destinations/hubspot/customEvent/constants.js.map +1 -1
- package/dist/destinations/hubspot/customEvent/dynamic-fields.js +11 -5
- package/dist/destinations/hubspot/customEvent/dynamic-fields.js.map +1 -1
- package/dist/destinations/hubspot/customEvent/index.d.ts +1 -1
- package/dist/destinations/hubspot/customEvent/index.js +54 -16
- package/dist/destinations/hubspot/customEvent/index.js.map +1 -1
- package/dist/destinations/hubspot/customEvent/types.d.ts +81 -0
- package/dist/destinations/hubspot/customEvent/types.js +10 -0
- package/dist/destinations/hubspot/customEvent/types.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/utils.d.ts +12 -0
- package/dist/destinations/hubspot/customEvent/utils.js +296 -0
- package/dist/destinations/hubspot/customEvent/utils.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/client.d.ts +11 -0
- package/dist/destinations/hubspot/upsertObject/client.js +39 -0
- package/dist/destinations/hubspot/upsertObject/client.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/common-fields.js +14 -7
- package/dist/destinations/hubspot/upsertObject/common-fields.js.map +1 -1
- package/dist/destinations/hubspot/upsertObject/constants.d.ts +1 -0
- package/dist/destinations/hubspot/upsertObject/constants.js +2 -1
- package/dist/destinations/hubspot/upsertObject/constants.js.map +1 -1
- package/dist/destinations/hubspot/upsertObject/dynamic-fields.js.map +1 -1
- package/dist/destinations/hubspot/upsertObject/index.js +36 -35
- package/dist/destinations/hubspot/upsertObject/index.js.map +1 -1
- package/dist/destinations/hubspot/upsertObject/types.d.ts +192 -0
- package/dist/destinations/hubspot/upsertObject/types.js +56 -0
- package/dist/destinations/hubspot/upsertObject/types.js.map +1 -0
- package/dist/destinations/hubspot/upsertObject/utils.d.ts +13 -0
- package/dist/destinations/hubspot/upsertObject/utils.js +548 -0
- package/dist/destinations/hubspot/upsertObject/utils.js.map +1 -0
- package/dist/destinations/iterable/updateUser/generated-types.d.ts +2 -0
- package/dist/destinations/iterable/updateUser/index.js +42 -13
- package/dist/destinations/iterable/updateUser/index.js.map +1 -1
- package/dist/destinations/iterable/utils.d.ts +1 -0
- package/dist/destinations/iterable/utils.js +1 -0
- package/dist/destinations/iterable/utils.js.map +1 -1
- package/dist/destinations/linkedin-conversions/index.js +14 -2
- package/dist/destinations/linkedin-conversions/index.js.map +1 -1
- package/dist/destinations/loops/createOrUpdateContact/generated-types.d.ts +4 -0
- package/dist/destinations/loops/createOrUpdateContact/index.js +48 -2
- package/dist/destinations/loops/createOrUpdateContact/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/destinations/hubspot/customEvent/hubspot-api.d.ts +0 -62
- package/dist/destinations/hubspot/customEvent/hubspot-api.js +0 -305
- package/dist/destinations/hubspot/customEvent/hubspot-api.js.map +0 -1
- package/dist/destinations/hubspot/upsertObject/hubspot-api.d.ts +0 -221
- package/dist/destinations/hubspot/upsertObject/hubspot-api.js +0 -617
- 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
|
|
16
|
-
{ label: 'Create new
|
|
17
|
-
{ label: 'Update existing
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
throw new actions_core_1.
|
|
57
|
+
case types_1.SchemaMatch.Mismatch: {
|
|
58
|
+
throw new actions_core_1.IntegrationError('Cache schema mismatch.', 'CACHE_SCHEMA_MISMATCH', 400);
|
|
51
59
|
}
|
|
52
|
-
|
|
53
|
-
|
|
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":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/destinations/hubspot/customEvent/index.ts"],"names":[],"mappings":";;AAEA,mDAA8C;AAC9C,qCAAiC;AACjC,wDAAyF;AACzF,qDAAuG;AACvG,mCAA+C;AAC/C,mCASgB;AAEhB,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;QACjB,OAAO,EAAE;YACP,EAAE,KAAK,EAAE,yDAAyD,EAAE,KAAK,EAAE,QAAQ,EAAE;YACrF,EAAE,KAAK,EAAE,iEAAiE,EAAE,KAAK,EAAE,KAAK,EAAE;YAC1F,EAAE,KAAK,EAAE,gEAAgE,EAAE,KAAK,EAAE,QAAQ,EAAE;SAC7F;KACF;IACD,MAAM,EAAE;QACN,GAAG,4BAAY;KAChB;IACD,aAAa,EAAE;QACb,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YAC5B,OAAO,MAAM,sCAAqB,CAAC,OAAO,CAAC,CAAA;QAC7C,CAAC;QACD,cAAc,EAAE;YACd,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;gBAC7B,OAAO,MAAM,uCAAsB,CAAC,OAAO,CAAC,CAAA;YAC9C,CAAC;SACF;QACD,UAAU,EAAE;YACV,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;gBACvC,MAAM,SAAS,GAAG,OAAO,EAAE,UAAU,CAAA;gBACrC,IAAI,CAAC,SAAS,EAAE;oBACd,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;iBAClD;gBACD,OAAO,MAAM,sCAAqB,CAAC,OA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,MAAM,EAAE,kBAAkB,EAAE,YAAY,CAAC,CAAA;iBACjE;aACF;SACF;KACF;AACH,CAAC,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
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 CreatePropertyRegectedResp {
|
|
66
|
+
data: {
|
|
67
|
+
status: string;
|
|
68
|
+
message?: string;
|
|
69
|
+
propertiesErrorCode?: string;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export interface EventCompletionReq {
|
|
73
|
+
eventName: string;
|
|
74
|
+
objectId?: number | undefined;
|
|
75
|
+
email?: string | undefined;
|
|
76
|
+
utk?: string | undefined;
|
|
77
|
+
occurredAt: string | number | undefined;
|
|
78
|
+
properties?: {
|
|
79
|
+
[k: string]: unknown;
|
|
80
|
+
} | undefined;
|
|
81
|
+
}
|
|
@@ -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,296 @@
|
|
|
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
|
+
const response = await client.getEventDefinition(schema.eventName);
|
|
180
|
+
switch (response.status) {
|
|
181
|
+
case 200: {
|
|
182
|
+
const { fullyQualifiedName, name, properties: hsProperties, archived } = response.data;
|
|
183
|
+
if (archived) {
|
|
184
|
+
return mismatchSchemaDiff;
|
|
185
|
+
}
|
|
186
|
+
const schemaDiff = { missingProperties: {} };
|
|
187
|
+
for (const propName in schema.properties) {
|
|
188
|
+
const matchedProperty = hsProperties.find((hsProp) => hsProp.name === propName);
|
|
189
|
+
if (matchedProperty?.archived === true) {
|
|
190
|
+
return mismatchSchemaDiff;
|
|
191
|
+
}
|
|
192
|
+
const prop = schema.properties[propName];
|
|
193
|
+
if ((['object', 'string', 'boolean'].includes(prop.type) && matchedProperty?.type === 'number') ||
|
|
194
|
+
(['datetime', 'string', 'enumeration'].includes(matchedProperty?.type) && prop.type === 'number')) {
|
|
195
|
+
return mismatchSchemaDiff;
|
|
196
|
+
}
|
|
197
|
+
if (!matchedProperty) {
|
|
198
|
+
schemaDiff.missingProperties[propName] = schema.properties[propName];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
schemaDiff.match = Object.keys(schemaDiff.missingProperties).length === 0 ? 'full_match' : 'properties_missing';
|
|
202
|
+
schemaDiff.fullyQualifiedName = fullyQualifiedName;
|
|
203
|
+
schemaDiff.name = name;
|
|
204
|
+
return schemaDiff;
|
|
205
|
+
}
|
|
206
|
+
case 400:
|
|
207
|
+
case 404:
|
|
208
|
+
return { match: 'no_match', missingProperties: {} };
|
|
209
|
+
case 429:
|
|
210
|
+
throw new actions_core_1.RetryableError('Hubspot:CustomEvent:compareToHubspot: Rate limit reached');
|
|
211
|
+
default:
|
|
212
|
+
throw new actions_core_1.IntegrationError(`Hubspot.CustomEvent.compareToHubspot: ${response?.statusText ? response.statusText : 'Unexpected Error'}`, 'UNEXPECTED_ERROR', response.status);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.compareToHubspot = compareToHubspot;
|
|
216
|
+
async function saveSchemaToCache(_fullyQualifiedName, _name, _schema) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
exports.saveSchemaToCache = saveSchemaToCache;
|
|
220
|
+
async function sendEvent(client, fullyQualifiedName, payload) {
|
|
221
|
+
const { record_details, properties, occurred_at: occurredAt } = payload;
|
|
222
|
+
const eventName = fullyQualifiedName;
|
|
223
|
+
const json = {
|
|
224
|
+
eventName,
|
|
225
|
+
objectId: record_details.object_id ?? undefined,
|
|
226
|
+
email: record_details.email ?? undefined,
|
|
227
|
+
utk: record_details.utk ?? undefined,
|
|
228
|
+
occurredAt,
|
|
229
|
+
properties: properties
|
|
230
|
+
};
|
|
231
|
+
return await client.send(json);
|
|
232
|
+
}
|
|
233
|
+
exports.sendEvent = sendEvent;
|
|
234
|
+
async function createHubspotEventSchema(client, schema) {
|
|
235
|
+
const json = {
|
|
236
|
+
label: schema.eventName,
|
|
237
|
+
name: schema.eventName,
|
|
238
|
+
description: `${schema.eventName} - (created by Segment)`,
|
|
239
|
+
primaryObject: schema.primaryObject,
|
|
240
|
+
propertyDefinitions: Object.entries(schema.properties).map(([name, { type, stringFormat }]) => {
|
|
241
|
+
return propertyBody(schema.eventName, type, name, stringFormat);
|
|
242
|
+
})
|
|
243
|
+
};
|
|
244
|
+
const response = await client.createEventDefinition(json);
|
|
245
|
+
switch (response.status) {
|
|
246
|
+
case 201:
|
|
247
|
+
case 200: {
|
|
248
|
+
return {
|
|
249
|
+
match: 'full_match',
|
|
250
|
+
fullyQualifiedName: response.data.fullyQualifiedName,
|
|
251
|
+
name: response.data.name
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
case 409:
|
|
255
|
+
throw new actions_core_1.RetryableError('Hubspot:CustomEvent:createHubspotEventSchema: Object already exists');
|
|
256
|
+
case 429:
|
|
257
|
+
throw new actions_core_1.RetryableError('Hubspot:CustomEvent:createHubspotEventSchema: Rate limit reached');
|
|
258
|
+
default:
|
|
259
|
+
throw new actions_core_1.IntegrationError(`Hubspot.CustomEvent.createHubspotEventSchema: ${response?.statusText ? response.statusText : 'Unexpected Error'}`, 'UNEXPECTED_ERROR', response.status);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
exports.createHubspotEventSchema = createHubspotEventSchema;
|
|
263
|
+
async function updateHubspotSchema(client, fullyQualifiedName, schemaDiff) {
|
|
264
|
+
const requests = [];
|
|
265
|
+
Object.keys(schemaDiff.missingProperties).forEach((propName) => {
|
|
266
|
+
const { type, stringFormat } = schemaDiff.missingProperties[propName];
|
|
267
|
+
const json = propertyBody(schemaDiff?.fullyQualifiedName, type, propName, stringFormat);
|
|
268
|
+
requests.push(client.createPropertyDefinition(json, fullyQualifiedName));
|
|
269
|
+
});
|
|
270
|
+
const responses = await Promise.allSettled(requests);
|
|
271
|
+
for (const response of responses) {
|
|
272
|
+
if (response.status === 'fulfilled') {
|
|
273
|
+
const { status, statusText, data: { message } } = response.value;
|
|
274
|
+
switch (status) {
|
|
275
|
+
case 201:
|
|
276
|
+
case 200:
|
|
277
|
+
return;
|
|
278
|
+
case 409:
|
|
279
|
+
throw new actions_core_1.RetryableError('Hubspot:CustomEvent:updateHubspotSchema: Property already exists', 429);
|
|
280
|
+
case 429:
|
|
281
|
+
throw new actions_core_1.RetryableError('Hubspot:CustomEvent:updateHubspotSchema: Rate limit reached', 429);
|
|
282
|
+
default: {
|
|
283
|
+
throw new actions_core_1.IntegrationError(`Hubspot.CustomEvent.updateHubspotSchema: ${statusText ? statusText : 'Unexpected Error'}. ${message ? message : ''}`, 'UNEXPECTED_ERROR', status);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (response.status === 'rejected') {
|
|
288
|
+
const error = response.reason;
|
|
289
|
+
if (error.data.propertiesErrorCode !== 'PROPERTY_EXISTS') {
|
|
290
|
+
throw new actions_core_1.IntegrationError(`Error updating schema in HubSpot. ${error.data.message || ''} ${error.data.propertiesErrorCode || ''}`, 'HUBSPOT_UPDATE_SCHEMA_ERROR', 400);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
exports.updateHubspotSchema = updateHubspotSchema;
|
|
296
|
+
//# 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;AAehG,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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,CAAC;AAlDD,kDAkDC"}
|
|
@@ -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/hubspot/upsertObject/client.ts"],"names":[],"mappings":";;;AACA,8CAAgD;AAWhD,MAAa,MAAM;IAIjB,YAAY,OAAsB,EAAE,UAAkB;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,SAAkB;QACrC,MAAM,WAAW,GAAG,4BAA4B,CAAA;QAChD,MAAM,GAAG,GAAG,GAAG,6BAAgB,sBAAsB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;QACrG,OAAO,IAAI,CAAC,OAAO,CAAe,GAAG,EAAE;YACrC,MAAM,EAAE,KAAK;YACb,mBAAmB,EAAE,IAAI;SAC1B,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,0BAA0B,CAAC,IAA8B;QAC7D,MAAM,IAAI,CAAC,OAAO,CAAC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