Skip to content

Commit c8bd543

Browse files
authored
Add salesforce marketing cloud (#54)
* Add client and auth for sfmc * Add changes * Remove package-lock * Update yarn.lock * Add create and update for salesforce contact * Fix types * Fix typing for TOAuth2Answers and TAnswers * Fix type * Fix typing * Remove changes from other file * Hook up actions to platform * Fix formatting * Add listview and listviewresults * Add to platforms * Rename utils.ts to pagination.ts * add default value * Add categories to sfdc * Change get to find * Move marketing automation first * Match end platform for Id * Remove extra slash * Bump version
1 parent c179584 commit c8bd543

File tree

21 files changed

+964
-365
lines changed

21 files changed

+964
-365
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.51",
3+
"version": "0.0.52",
44
"description": "Vessel integrations",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

src/platforms/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import apollo from '@/platforms/apollo';
33
import dialpad from '@/platforms/dialpad';
44
import outreach from '@/platforms/outreach';
55
import ringcentral from '@/platforms/ringcentral';
6+
import salesforce from '@/platforms/salesforce';
67
import salesloft from '@/platforms/salesloft';
78
import slack from '@/platforms/slack';
89
import { Platform } from '@/sdk';
@@ -18,18 +19,23 @@ export {
1819
default as ringcentral,
1920
types as ringcentralTypes,
2021
} from '@/platforms/ringcentral';
22+
export {
23+
default as salesforce,
24+
types as salesforceTypes,
25+
} from '@/platforms/salesforce';
2126
export {
2227
default as salesloft,
2328
types as salesloftTypes,
2429
} from '@/platforms/salesloft';
2530
export { default as slack, types as slackTypes } from '@/platforms/slack';
2631

27-
export const integrationsList: Platform<any, any, any>[] = Object.values([
32+
export const integrationsList: Platform<any, any, any, any, any>[] = [
2833
aircall,
2934
apollo,
3035
dialpad,
3136
outreach,
3237
ringcentral,
38+
salesforce,
3339
salesloft,
3440
slack,
35-
]);
41+
];
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { client } from '@/platforms/salesforce/client';
2+
import { action } from '@/sdk';
3+
import { salesforceContactCreate } from '../../schemas';
4+
5+
export default action(
6+
'create-contact',
7+
{
8+
operation: 'create',
9+
resource: 'contacts',
10+
mutation: true,
11+
schema: salesforceContactCreate,
12+
scopes: [],
13+
},
14+
async ({ input, auth }) => {
15+
return await client.contacts.create(auth, input);
16+
},
17+
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { client } from '@/platforms/salesforce/client';
2+
import { action } from '@/sdk';
3+
import { z } from 'zod';
4+
5+
export default action(
6+
'find-contact',
7+
{
8+
operation: 'find',
9+
resource: 'contacts',
10+
mutation: false,
11+
schema: z.object({
12+
Id: z.number(),
13+
}),
14+
scopes: [],
15+
},
16+
async ({ input, auth }) => {
17+
return await client.contacts.find(auth, { Id: input.Id });
18+
},
19+
);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { client } from '@/platforms/salesforce/client';
2+
import { action } from '@/sdk';
3+
import { z } from 'zod';
4+
import { MAX_QUERY_PAGE_SIZE } from '../../constants';
5+
import { getNextCursor } from '../pagination';
6+
7+
export default action(
8+
'list-contacts',
9+
{
10+
operation: 'list',
11+
resource: 'contacts',
12+
mutation: false,
13+
schema: z.object({
14+
cursor: z.number(),
15+
}),
16+
scopes: [],
17+
},
18+
async ({ input, auth }) => {
19+
const resp = await client.contacts.list(auth, {
20+
cursor: input.cursor,
21+
limit: MAX_QUERY_PAGE_SIZE,
22+
});
23+
return {
24+
...resp,
25+
cursor: getNextCursor({
26+
records: resp.records,
27+
limit: MAX_QUERY_PAGE_SIZE,
28+
}),
29+
};
30+
},
31+
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { client } from '@/platforms/salesforce/client';
2+
import { action } from '@/sdk';
3+
import { salesforceContactUpdate } from '../../schemas';
4+
5+
export default action(
6+
'update-contact',
7+
{
8+
operation: 'update',
9+
resource: 'contacts',
10+
mutation: true,
11+
schema: salesforceContactUpdate,
12+
scopes: [],
13+
},
14+
async ({ input, auth }) => {
15+
return await client.contacts.update(auth, input);
16+
},
17+
);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { client } from '@/platforms/salesforce/client';
2+
import { action } from '@/sdk';
3+
import { z } from 'zod';
4+
5+
export default action(
6+
'find-list-view-results',
7+
{
8+
operation: 'find',
9+
resource: 'list-view-results',
10+
mutation: false,
11+
schema: z.object({
12+
Id: z.number(),
13+
objectType: z.string(),
14+
}),
15+
scopes: [],
16+
},
17+
async ({ input, auth }) => {
18+
return await client.listViewResults.find(auth, {
19+
Id: input.Id,
20+
objectType: input.objectType,
21+
});
22+
},
23+
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { client } from '@/platforms/salesforce/client';
2+
import { action } from '@/sdk';
3+
import { z } from 'zod';
4+
5+
export default action(
6+
'find-list-view',
7+
{
8+
operation: 'find',
9+
resource: 'list-views',
10+
mutation: false,
11+
schema: z.object({
12+
Id: z.number(),
13+
}),
14+
scopes: [],
15+
},
16+
async ({ input, auth }) => {
17+
return await client.listViews.find(auth, { Id: input.Id });
18+
},
19+
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { client } from '@/platforms/salesforce/client';
2+
import { action } from '@/sdk';
3+
import { z } from 'zod';
4+
import { MAX_QUERY_PAGE_SIZE } from '../../constants';
5+
import { getNextCursor } from '../pagination';
6+
7+
export default action(
8+
'list-list-views',
9+
{
10+
operation: 'list',
11+
resource: 'list-views',
12+
mutation: false,
13+
schema: z.object({
14+
cursor: z.number(),
15+
objectType: z.string().optional(),
16+
}),
17+
scopes: [],
18+
},
19+
async ({ input, auth }) => {
20+
const resp = await client.listViews.list(auth, {
21+
cursor: input.cursor,
22+
objectType: input.objectType,
23+
limit: MAX_QUERY_PAGE_SIZE,
24+
});
25+
return {
26+
...resp,
27+
cursor: getNextCursor({
28+
records: resp.records,
29+
limit: MAX_QUERY_PAGE_SIZE,
30+
}),
31+
};
32+
},
33+
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { last } from 'radash';
2+
3+
export const getNextCursor = ({
4+
records,
5+
limit,
6+
}: {
7+
records: { Id: number }[];
8+
limit: number;
9+
}) => {
10+
if (records.length < limit) {
11+
return null;
12+
}
13+
return last(records)?.Id;
14+
};

0 commit comments

Comments
 (0)