@skillswaveca/nova-shared-libraries 4.26.0 → 4.27.1
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/docs-base/package-info.js +5 -5
- package/package.json +1 -1
- package/packages/drivers/package.json +1 -1
- package/packages/drivers/src/hubspot.js +14 -13
- package/packages/nova-middleware/package.json +1 -1
- package/packages/nova-model/package.json +1 -1
- package/packages/nova-router/package.json +1 -1
- package/packages/nova-utils/package.json +1 -1
- package/packages/nova-utils/src/event-definitions.js +50 -55
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
export const packageInfo = [
|
|
2
2
|
{
|
|
3
3
|
"name": "@skillswaveca/nova-utils",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.27.0",
|
|
5
5
|
"description": "A collection of random utils used in nova repos",
|
|
6
6
|
"docsPath": "./nova-utils/index.html"
|
|
7
7
|
},
|
|
8
8
|
{
|
|
9
9
|
"name": "@skillswaveca/nova-router",
|
|
10
|
-
"version": "4.
|
|
10
|
+
"version": "4.27.0",
|
|
11
11
|
"description": "An extended Koa router that enables better validation",
|
|
12
12
|
"docsPath": "./nova-router/index.html"
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
"name": "@skillswaveca/nova-model",
|
|
16
|
-
"version": "4.
|
|
16
|
+
"version": "4.27.0",
|
|
17
17
|
"description": "Nova model stuff",
|
|
18
18
|
"docsPath": "./nova-model/index.html"
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
"name": "@skillswaveca/nova-middleware",
|
|
22
|
-
"version": "4.
|
|
22
|
+
"version": "4.27.0",
|
|
23
23
|
"description": "A collection of middleware used by nova projects",
|
|
24
24
|
"docsPath": "./nova-middleware/index.html"
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
"name": "@skillswaveca/nova-drivers",
|
|
28
|
-
"version": "4.
|
|
28
|
+
"version": "4.27.0",
|
|
29
29
|
"description": "Some helper drivers for AWS services",
|
|
30
30
|
"docsPath": "./drivers/index.html"
|
|
31
31
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@skillswaveca/nova-shared-libraries",
|
|
4
4
|
"description": "A monorepo of shared libraries for Nova projects.",
|
|
5
5
|
"repository": "https://github.com/SkillsWave/nova-shared-libraries",
|
|
6
|
-
"version": "4.
|
|
6
|
+
"version": "4.27.1",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"keywords": [],
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@skillswaveca/nova-drivers",
|
|
4
4
|
"description": "Some helper drivers for AWS services",
|
|
5
5
|
"repository": "https://github.com/SkillsWave/nova-shared-libraries",
|
|
6
|
-
"version": "4.
|
|
6
|
+
"version": "4.27.1",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"pre-release": "pnpm run create-index",
|
|
@@ -113,8 +113,8 @@ export class HubSpotDriver extends NovaDriver {
|
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* Updates a HubSpot deal with the given properties.
|
|
116
|
-
* @param {string} dealId
|
|
117
|
-
* @param {object} properties
|
|
116
|
+
* @param {string} dealId
|
|
117
|
+
* @param {object} properties
|
|
118
118
|
* @returns The updated deal object.
|
|
119
119
|
*/
|
|
120
120
|
async updateDeal(dealId, properties) {
|
|
@@ -123,7 +123,7 @@ export class HubSpotDriver extends NovaDriver {
|
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
125
|
* Looks up a HubSpot contact ID for a given user. May return multiple IDs.
|
|
126
|
-
* @param {Object} user
|
|
126
|
+
* @param {Object} user
|
|
127
127
|
* @returns {Promise<string[]|null>} An array of HubSpot contact IDs or null if no contact is found.
|
|
128
128
|
*/
|
|
129
129
|
async lookupUserContactId(user) {
|
|
@@ -152,7 +152,7 @@ export class HubSpotDriver extends NovaDriver {
|
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
154
|
* Creates or updates a HubSpot contact. If the provided user has a `hubSpotContactId`, it will update the existing contact; otherwise, it will create a new one.
|
|
155
|
-
* @param {object} user
|
|
155
|
+
* @param {object} user
|
|
156
156
|
* @returns {object} The created/updated HubSpot user.
|
|
157
157
|
*/
|
|
158
158
|
async upsertUser(user) {
|
|
@@ -169,7 +169,7 @@ export class HubSpotDriver extends NovaDriver {
|
|
|
169
169
|
|
|
170
170
|
/**
|
|
171
171
|
* Deletes a HubSpot user.
|
|
172
|
-
* @param {object} user
|
|
172
|
+
* @param {object} user
|
|
173
173
|
* @returns {Promise<void>}
|
|
174
174
|
*/
|
|
175
175
|
async deleteUser(user) {
|
|
@@ -184,7 +184,7 @@ export class HubSpotDriver extends NovaDriver {
|
|
|
184
184
|
/**
|
|
185
185
|
* Sends a custom event to HubSpot using the event definitions.
|
|
186
186
|
* This method validates the event data against the predefined schema before sending.
|
|
187
|
-
*
|
|
187
|
+
*
|
|
188
188
|
* @param {string} eventName - The name of the event to send
|
|
189
189
|
* @param {object} eventData - The event data to send
|
|
190
190
|
* @returns {Promise<object>} The response from HubSpot API
|
|
@@ -192,6 +192,7 @@ export class HubSpotDriver extends NovaDriver {
|
|
|
192
192
|
*/
|
|
193
193
|
async sendEvent(eventName, eventData) {
|
|
194
194
|
try {
|
|
195
|
+
log.info({ eventName, eventData }, 'Sending event to HubSpot');
|
|
195
196
|
// Validate the event exists and get its definition
|
|
196
197
|
const eventDefinition = getEventDefinition(eventName);
|
|
197
198
|
if (!eventDefinition) {
|
|
@@ -204,7 +205,7 @@ export class HubSpotDriver extends NovaDriver {
|
|
|
204
205
|
const eventMetadata = await getEventMetadata(eventName, validatedData);
|
|
205
206
|
|
|
206
207
|
const response = await this._callHubSpot('events.send.basicApi.send', {
|
|
207
|
-
eventName: `pe${this.accountId}_${
|
|
208
|
+
eventName: `pe${this.accountId}_${eventDefinition.name}`,
|
|
208
209
|
properties: validatedData,
|
|
209
210
|
occurredAt: new Date(),
|
|
210
211
|
...eventMetadata,
|
|
@@ -213,14 +214,14 @@ export class HubSpotDriver extends NovaDriver {
|
|
|
213
214
|
log.debug({ eventName, response }, 'Event sent to HubSpot successfully');
|
|
214
215
|
return response;
|
|
215
216
|
} catch (error) {
|
|
216
|
-
log.error({
|
|
217
|
-
eventName,
|
|
218
|
-
eventData,
|
|
217
|
+
log.error({
|
|
218
|
+
eventName,
|
|
219
|
+
eventData,
|
|
219
220
|
error: error.message,
|
|
220
|
-
stack: error.stack
|
|
221
|
+
stack: error.stack
|
|
221
222
|
}, 'Unexpected error while sending event');
|
|
222
|
-
|
|
223
|
+
|
|
223
224
|
throw error;
|
|
224
225
|
}
|
|
225
226
|
}
|
|
226
|
-
}
|
|
227
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@skillswaveca/nova-middleware",
|
|
4
4
|
"description": "A collection of middleware used by nova projects",
|
|
5
5
|
"repository": "https://github.com/SkillsWave/nova-shared-libraries",
|
|
6
|
-
"version": "4.
|
|
6
|
+
"version": "4.27.1",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"pre-release": "pnpm run create-index",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@skillswaveca/nova-model",
|
|
4
4
|
"description": "Nova model stuff",
|
|
5
5
|
"repository": "https://github.com/SkillsWave/nova-shared-libraries",
|
|
6
|
-
"version": "4.
|
|
6
|
+
"version": "4.27.1",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"pre-release": "pnpm run create-index",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@skillswaveca/nova-router",
|
|
4
4
|
"description": "An extended Koa router that enables better validation",
|
|
5
5
|
"repository": "https://github.com/SkillsWave/nova-shared-libraries",
|
|
6
|
-
"version": "4.
|
|
6
|
+
"version": "4.27.1",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"pre-release": "pnpm run create-index",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@skillswaveca/nova-utils",
|
|
4
4
|
"description": "A collection of random utils used in nova repos",
|
|
5
5
|
"repository": "https://github.com/SkillsWave/nova-shared-libraries",
|
|
6
|
-
"version": "4.
|
|
6
|
+
"version": "4.27.1",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"pre-release": "pnpm run create-index",
|
|
@@ -11,151 +11,146 @@ import * as yup from 'yup';
|
|
|
11
11
|
* - validator: Yup validation schema for the event data
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
const TENANT_PROPERTIES = {
|
|
15
|
+
tenant_id: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
required: true,
|
|
18
|
+
description: 'The ID of the tenant',
|
|
19
|
+
},
|
|
20
|
+
tenant_name: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
required: true,
|
|
23
|
+
description: 'The name of the tenant',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const TENANT_PROPERTIES_VALIDATOR = {
|
|
28
|
+
tenant_id: yup.string().required('Tenant ID is required'),
|
|
29
|
+
tenant_name: yup.string().required('Tenant name is required'),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const TENANT_METADATA_PROPERTIES = data => {
|
|
33
|
+
return {
|
|
34
|
+
tenant_id: data.tenant_id,
|
|
35
|
+
tenant_name: data.tenant_name,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
14
39
|
const clientOnboardingCompletedEventDefinition = {
|
|
40
|
+
key: 'clientOnboardingCompleted',
|
|
15
41
|
name: 'client_onboarding_completed',
|
|
16
42
|
description: 'Client has finished PLG onboarding and pressed "create workspace."',
|
|
17
43
|
properties: {
|
|
44
|
+
...TENANT_PROPERTIES,
|
|
18
45
|
email: {
|
|
19
46
|
type: 'string',
|
|
20
47
|
required: true,
|
|
21
48
|
description: 'Email address of the user',
|
|
22
49
|
},
|
|
23
|
-
tenant_id: {
|
|
24
|
-
type: 'string',
|
|
25
|
-
required: true,
|
|
26
|
-
description: 'The ID of the tenant that was created',
|
|
27
|
-
},
|
|
28
|
-
tenant_name: {
|
|
29
|
-
type: 'string',
|
|
30
|
-
required: true,
|
|
31
|
-
description: 'The name of the tenant that was created',
|
|
32
|
-
},
|
|
33
50
|
},
|
|
34
51
|
validator: yup.object({
|
|
52
|
+
...TENANT_PROPERTIES_VALIDATOR,
|
|
35
53
|
email: yup.string().email('Must be a valid email').required('Email is required'),
|
|
36
54
|
}),
|
|
37
55
|
getMetadata: eventData => {
|
|
38
56
|
return {
|
|
57
|
+
...TENANT_METADATA_PROPERTIES(eventData),
|
|
39
58
|
email: eventData.email,
|
|
40
59
|
};
|
|
41
60
|
},
|
|
42
61
|
};
|
|
43
62
|
|
|
44
63
|
const usersInvitedEventDefinition = {
|
|
64
|
+
key: 'usersInvited',
|
|
45
65
|
name: 'users_invited',
|
|
46
66
|
description: 'PLG Admin has invited one or more users to their workspace.',
|
|
47
67
|
properties: {
|
|
68
|
+
...TENANT_PROPERTIES,
|
|
48
69
|
email: {
|
|
49
70
|
type: 'string',
|
|
50
71
|
required: true,
|
|
51
72
|
description: 'Email address of the user',
|
|
52
73
|
},
|
|
53
|
-
tenant_id: {
|
|
54
|
-
type: 'string',
|
|
55
|
-
required: true,
|
|
56
|
-
description: 'The ID of the tenant that was created',
|
|
57
|
-
},
|
|
58
|
-
tenant_name: {
|
|
59
|
-
type: 'string',
|
|
60
|
-
required: true,
|
|
61
|
-
description: 'The name of the tenant that was created',
|
|
62
|
-
},
|
|
63
74
|
},
|
|
64
75
|
validator: yup.object({
|
|
76
|
+
...TENANT_PROPERTIES_VALIDATOR,
|
|
65
77
|
email: yup.string().email('Must be a valid email').required('Email is required'),
|
|
66
78
|
}),
|
|
67
79
|
getMetadata: eventData => {
|
|
68
80
|
return {
|
|
81
|
+
...TENANT_METADATA_PROPERTIES(eventData),
|
|
69
82
|
email: eventData.email,
|
|
70
83
|
};
|
|
71
84
|
},
|
|
72
85
|
};
|
|
73
86
|
|
|
74
87
|
const creditCardEventDefinition = {
|
|
88
|
+
key: 'creditCardAdded',
|
|
75
89
|
name: 'credit_card_added',
|
|
76
90
|
description: 'PLG Admin added a credit card in Stripe.',
|
|
77
91
|
properties: {
|
|
92
|
+
...TENANT_PROPERTIES,
|
|
78
93
|
email: {
|
|
79
94
|
type: 'string',
|
|
80
95
|
required: true,
|
|
81
96
|
description: 'Email address of the user',
|
|
82
97
|
},
|
|
83
|
-
tenant_id: {
|
|
84
|
-
type: 'string',
|
|
85
|
-
required: true,
|
|
86
|
-
description: 'The ID of the tenant that was created',
|
|
87
|
-
},
|
|
88
|
-
tenant_name: {
|
|
89
|
-
type: 'string',
|
|
90
|
-
required: true,
|
|
91
|
-
description: 'The name of the tenant that was created',
|
|
92
|
-
},
|
|
93
98
|
},
|
|
94
99
|
validator: yup.object({
|
|
100
|
+
...TENANT_PROPERTIES_VALIDATOR,
|
|
95
101
|
email: yup.string().email('Must be a valid email').required('Email is required'),
|
|
96
102
|
}),
|
|
97
103
|
getMetadata: eventData => {
|
|
98
104
|
return {
|
|
105
|
+
...TENANT_METADATA_PROPERTIES(eventData),
|
|
99
106
|
email: eventData.email,
|
|
100
107
|
};
|
|
101
108
|
},
|
|
102
109
|
};
|
|
103
110
|
|
|
104
111
|
const firstRequestSubmittedEventDefinition = {
|
|
112
|
+
key: 'firstRequestSubmitted',
|
|
105
113
|
name: 'first_request_submitted',
|
|
106
114
|
description: 'A user in the PLG workspace has submitted the first request.',
|
|
107
115
|
properties: {
|
|
116
|
+
...TENANT_PROPERTIES,
|
|
108
117
|
email: {
|
|
109
118
|
type: 'string',
|
|
110
119
|
required: true,
|
|
111
120
|
description: 'Email address of the user',
|
|
112
121
|
},
|
|
113
|
-
tenant_id: {
|
|
114
|
-
type: 'string',
|
|
115
|
-
required: true,
|
|
116
|
-
description: 'The ID of the tenant that was created',
|
|
117
|
-
},
|
|
118
|
-
tenant_name: {
|
|
119
|
-
type: 'string',
|
|
120
|
-
required: true,
|
|
121
|
-
description: 'The name of the tenant that was created',
|
|
122
|
-
},
|
|
123
122
|
},
|
|
124
123
|
validator: yup.object({
|
|
124
|
+
...TENANT_PROPERTIES_VALIDATOR,
|
|
125
125
|
email: yup.string().email('Must be a valid email').required('Email is required'),
|
|
126
126
|
}),
|
|
127
127
|
getMetadata: eventData => {
|
|
128
128
|
return {
|
|
129
|
+
...TENANT_METADATA_PROPERTIES(eventData),
|
|
129
130
|
email: eventData.email,
|
|
130
131
|
};
|
|
131
132
|
},
|
|
132
133
|
};
|
|
133
134
|
|
|
134
135
|
const transactionsThresholdMetEventDefinition = {
|
|
136
|
+
key: 'transactionsThresholdMet',
|
|
135
137
|
name: 'transactions_threshold_met',
|
|
136
138
|
description: 'The PLG tenant has completed a specified number of transactions.',
|
|
137
139
|
properties: {
|
|
140
|
+
...TENANT_PROPERTIES,
|
|
138
141
|
email: {
|
|
139
142
|
type: 'string',
|
|
140
143
|
required: true,
|
|
141
144
|
description: 'Email address of the user',
|
|
142
145
|
},
|
|
143
|
-
tenant_id: {
|
|
144
|
-
type: 'string',
|
|
145
|
-
required: true,
|
|
146
|
-
description: 'The ID of the tenant that was created',
|
|
147
|
-
},
|
|
148
|
-
tenant_name: {
|
|
149
|
-
type: 'string',
|
|
150
|
-
required: true,
|
|
151
|
-
description: 'The name of the tenant that was created',
|
|
152
|
-
},
|
|
153
146
|
},
|
|
154
147
|
validator: yup.object({
|
|
148
|
+
...TENANT_PROPERTIES_VALIDATOR,
|
|
155
149
|
email: yup.string().email('Must be a valid email').required('Email is required'),
|
|
156
150
|
}),
|
|
157
151
|
getMetadata: eventData => {
|
|
158
152
|
return {
|
|
153
|
+
...TENANT_METADATA_PROPERTIES(eventData),
|
|
159
154
|
email: eventData.email,
|
|
160
155
|
};
|
|
161
156
|
},
|
|
@@ -166,11 +161,11 @@ const transactionsThresholdMetEventDefinition = {
|
|
|
166
161
|
* Key: event name, Value: event definition object
|
|
167
162
|
*/
|
|
168
163
|
export const eventDefinitions = {
|
|
169
|
-
[clientOnboardingCompletedEventDefinition.
|
|
170
|
-
[usersInvitedEventDefinition.
|
|
171
|
-
[creditCardEventDefinition.
|
|
172
|
-
[firstRequestSubmittedEventDefinition.
|
|
173
|
-
[transactionsThresholdMetEventDefinition.
|
|
164
|
+
[clientOnboardingCompletedEventDefinition.key]: clientOnboardingCompletedEventDefinition,
|
|
165
|
+
[usersInvitedEventDefinition.key]: usersInvitedEventDefinition,
|
|
166
|
+
[creditCardEventDefinition.key]: creditCardEventDefinition,
|
|
167
|
+
[firstRequestSubmittedEventDefinition.key]: firstRequestSubmittedEventDefinition,
|
|
168
|
+
[transactionsThresholdMetEventDefinition.key]: transactionsThresholdMetEventDefinition,
|
|
174
169
|
};
|
|
175
170
|
/**
|
|
176
171
|
* Get event definition by name
|