Skip to content

Commit fd6df1a

Browse files
authored
feat: HubSpot Actions (#105)
* HubSpot Actions * addressing comments * making properties field partial for hubspot * updating version * fixing build error
1 parent f914d94 commit fd6df1a

File tree

41 files changed

+1607
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1607
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vesselapi/integrations",
3-
"version": "0.0.92",
3+
"version": "0.0.93",
44
"description": "Vessel integrations",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { action } from '@/sdk';
2+
import { z } from 'zod';
3+
import client from '../../client';
4+
5+
import { transformAssociation } from '@/platforms/hubspot/actions/mappers';
6+
import { HUBSPOT_DEFINED_CATEGORY } from '../../constants';
7+
import { hubspotModuleSchema } from '../../schemas';
8+
9+
export default action(
10+
'associations-create',
11+
{
12+
operation: 'create',
13+
resource: 'associations',
14+
mutation: true,
15+
schema: z.object({
16+
fromId: z.string(),
17+
fromType: hubspotModuleSchema,
18+
toId: z.string(),
19+
toType: hubspotModuleSchema,
20+
category: z.string().optional(),
21+
typeId: z.string().optional(),
22+
}),
23+
scopes: [
24+
'crm.schemas.companies.write',
25+
'crm.schemas.contacts.write',
26+
'crm.schemas.deals.write',
27+
],
28+
},
29+
async ({ auth, input }) => {
30+
const { category, typeId } = await (async () => {
31+
if (input.category && input.typeId) return input;
32+
const labelsResponse = await client.associations.labels(auth, {
33+
fromType: input.fromType,
34+
toType: input.toType,
35+
});
36+
const associationTypeId = labelsResponse.data.results?.find(
37+
(id) => id.category === HUBSPOT_DEFINED_CATEGORY,
38+
)?.typeId;
39+
return {
40+
category: HUBSPOT_DEFINED_CATEGORY,
41+
typeId: associationTypeId,
42+
};
43+
})();
44+
const result = await client.associations.create(auth, {
45+
fromId: input.fromId,
46+
fromType: input.fromType,
47+
toId: input.toId,
48+
toType: input.toType,
49+
category,
50+
typeId,
51+
});
52+
53+
return {
54+
results: result.data.results?.map(transformAssociation),
55+
$native: result.$native,
56+
};
57+
},
58+
);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { transformCall } from '@/platforms/hubspot/actions/mappers';
2+
import { action } from '@/sdk';
3+
import * as custom from '@/sdk/validators';
4+
import { z } from 'zod';
5+
import client from '../../client';
6+
7+
export default action(
8+
'calls-create',
9+
{
10+
operation: 'create',
11+
resource: 'calls',
12+
mutation: true,
13+
schema: z
14+
.object({
15+
hsCallDisposition: z.string(),
16+
hsCallDirection: z.enum(['INBOUND', 'OUTBOUND']),
17+
hsCallBody: z.string(),
18+
hsCallTitle: z.string(),
19+
hubspotOwnerId: z.string(),
20+
})
21+
.partial()
22+
.extend({
23+
hsTimestamp: custom.date(),
24+
}),
25+
scopes: [],
26+
},
27+
async ({ auth, input }) => {
28+
const result = await client.calls.create(auth, {
29+
hs_call_disposition: input.hsCallDisposition,
30+
hs_call_direction: input.hsCallDirection,
31+
hs_timestamp: input.hsTimestamp,
32+
hs_call_body: input.hsCallBody,
33+
hs_call_title: input.hsCallTitle,
34+
hubspot_owner_id: input.hubspotOwnerId,
35+
});
36+
37+
return {
38+
...transformCall(result.data),
39+
$native: result.$native,
40+
};
41+
},
42+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { transformCall } from '@/platforms/hubspot/actions/mappers';
2+
import { action } from '@/sdk';
3+
import { z } from 'zod';
4+
import client from '../../client';
5+
import { hubspotCommonAssociationsSchema } from '../../schemas';
6+
7+
export default action(
8+
'find-call',
9+
{
10+
operation: 'find',
11+
resource: 'calls',
12+
mutation: false,
13+
schema: z.object({
14+
id: z.string(),
15+
associations: z.array(hubspotCommonAssociationsSchema).optional(),
16+
}),
17+
scopes: [],
18+
},
19+
async ({ auth, input }) => {
20+
const result = await client.calls.find(auth, {
21+
id: input.id,
22+
});
23+
24+
return {
25+
...transformCall(result.data),
26+
$native: result.$native,
27+
};
28+
},
29+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { transformCall } from '@/platforms/hubspot/actions/mappers';
2+
import { action } from '@/sdk';
3+
import { z } from 'zod';
4+
import client from '../../client';
5+
import { hubspotCommonAssociationsSchema } from '../../schemas';
6+
7+
export default action(
8+
'list-calls',
9+
{
10+
operation: 'list',
11+
resource: 'calls',
12+
mutation: false,
13+
schema: z.object({
14+
after: z.string().optional(),
15+
pageSize: z.number().optional(),
16+
associations: z.array(hubspotCommonAssociationsSchema).optional(),
17+
}),
18+
scopes: [],
19+
},
20+
async ({ auth, input }) => {
21+
const result = await client.calls.list(auth, input);
22+
23+
return {
24+
paging: result.data.paging,
25+
results: result.data.results?.map(transformCall),
26+
$native: result.$native,
27+
};
28+
},
29+
);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { transformCall } from '@/platforms/hubspot/actions/mappers';
2+
import { action } from '@/sdk';
3+
import { z } from 'zod';
4+
import client from '../../client';
5+
6+
export default action(
7+
'calls-update',
8+
{
9+
operation: 'update',
10+
resource: 'calls',
11+
mutation: true,
12+
schema: z
13+
.object({
14+
hsCallDisposition: z.string(),
15+
hubspotOwnerId: z.string(),
16+
})
17+
.partial()
18+
.extend({
19+
id: z.string(),
20+
}),
21+
scopes: [],
22+
},
23+
async ({ auth, input }) => {
24+
const result = await client.calls.update(auth, {
25+
id: input.id,
26+
hs_call_disposition: input.hsCallDisposition,
27+
hubspot_owner_id: input.hubspotOwnerId,
28+
});
29+
30+
return {
31+
...transformCall(result.data),
32+
$native: result.$native,
33+
};
34+
},
35+
);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { action } from '@/sdk';
2+
import { z } from 'zod';
3+
import client from '../../client';
4+
5+
import { transformCompany } from '@/platforms/hubspot/actions/mappers';
6+
import * as custom from '@/sdk/validators';
7+
8+
export default action(
9+
'companies-create',
10+
{
11+
operation: 'create',
12+
resource: 'companies',
13+
mutation: true,
14+
schema: z.object({
15+
name: z.string(),
16+
website: z.string(),
17+
industry: z.string(),
18+
address: z.string(),
19+
city: z.string(),
20+
state: z.string(),
21+
zip: z.string(),
22+
country: z.string(),
23+
numberOfEmployees: z.string(),
24+
annualRevenue: z.string(),
25+
description: z.string(),
26+
phone: custom.formattedPhoneNumber(),
27+
hubspotOwnerId: z.string(),
28+
}),
29+
scopes: ['crm.objects.companies.write'],
30+
},
31+
async ({ auth, input }) => {
32+
const result = await client.companies.create(auth, {
33+
name: input.name,
34+
website: input.website,
35+
industry: input.industry,
36+
address: input.address,
37+
city: input.city,
38+
state: input.state,
39+
zip: input.zip,
40+
country: input.country,
41+
numberofemployees: input.numberOfEmployees,
42+
annualrevenue: input.annualRevenue,
43+
description: input.description,
44+
phone: input.phone,
45+
hubspot_owner_id: input.hubspotOwnerId,
46+
});
47+
48+
return {
49+
...transformCompany(result.data),
50+
$native: result.$native,
51+
};
52+
},
53+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { transformCompany } from '@/platforms/hubspot/actions/mappers';
2+
import { action } from '@/sdk';
3+
import { z } from 'zod';
4+
import client from '../../client';
5+
import { hubspotCommonAssociationsSchema } from '../../schemas';
6+
7+
export default action(
8+
'find-company',
9+
{
10+
operation: 'find',
11+
resource: 'companies',
12+
mutation: false,
13+
schema: z.object({
14+
id: z.string(),
15+
associations: z.array(hubspotCommonAssociationsSchema).optional(),
16+
}),
17+
scopes: ['crm.objects.companies.read'],
18+
},
19+
async ({ auth, input }) => {
20+
const result = await client.companies.find(auth, {
21+
id: input.id,
22+
});
23+
24+
return {
25+
...transformCompany(result.data),
26+
$native: result.$native,
27+
};
28+
},
29+
);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { transformCompany } from '@/platforms/hubspot/actions/mappers';
2+
import { action } from '@/sdk';
3+
import { z } from 'zod';
4+
import client from '../../client';
5+
import { hubspotCommonAssociationsSchema } from '../../schemas';
6+
7+
export default action(
8+
'list-companies',
9+
{
10+
operation: 'list',
11+
resource: 'companies',
12+
mutation: false,
13+
schema: z.object({
14+
after: z.string().optional(),
15+
pageSize: z.number().optional(),
16+
associations: z.array(hubspotCommonAssociationsSchema).optional(),
17+
}),
18+
scopes: ['crm.objects.companies.read'],
19+
},
20+
async ({ auth, input }) => {
21+
const result = await client.companies.list(auth, input);
22+
23+
return {
24+
paging: result.data.paging,
25+
results: result.data.results?.map(transformCompany),
26+
$native: result.$native,
27+
};
28+
},
29+
);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { transformCompany } from '@/platforms/hubspot/actions/mappers';
2+
import { action } from '@/sdk';
3+
import * as custom from '@/sdk/validators';
4+
import { z } from 'zod';
5+
import client from '../../client';
6+
7+
export default action(
8+
'companies-update',
9+
{
10+
operation: 'update',
11+
resource: 'companies',
12+
mutation: true,
13+
schema: z
14+
.object({
15+
name: z.string(),
16+
website: z.string(),
17+
industry: z.string(),
18+
address: z.string(),
19+
city: z.string(),
20+
state: z.string(),
21+
zip: z.string(),
22+
country: z.string(),
23+
numberOfEmployees: z.string(),
24+
annualRevenue: z.string(),
25+
description: z.string(),
26+
phone: custom.formattedPhoneNumber(),
27+
hubspotOwnerId: z.string(),
28+
})
29+
.partial()
30+
.extend({
31+
id: z.string(),
32+
}),
33+
scopes: ['crm.objects.companies.write'],
34+
},
35+
async ({ auth, input }) => {
36+
const result = await client.companies.update(auth, {
37+
id: input.id,
38+
name: input.name,
39+
website: input.website,
40+
industry: input.industry,
41+
address: input.address,
42+
city: input.city,
43+
state: input.state,
44+
zip: input.zip,
45+
country: input.country,
46+
numberofemployees: input.numberOfEmployees,
47+
annualrevenue: input.annualRevenue,
48+
description: input.description,
49+
phone: input.phone,
50+
hubspot_owner_id: input.hubspotOwnerId,
51+
});
52+
53+
return {
54+
...transformCompany(result.data),
55+
$native: result.$native,
56+
};
57+
},
58+
);

0 commit comments

Comments
 (0)