Skip to content

Commit de04a2b

Browse files
authored
Fix salesforce actions (#75)
* Fix salesforce actions * Convert id number to string * Bump versino * Rename camelcase to kebab case for actions files * Rename queryBuilder to query-builder
1 parent c61cb4f commit de04a2b

File tree

17 files changed

+125
-101
lines changed

17 files changed

+125
-101
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.54",
3+
"version": "0.0.55",
44
"description": "Vessel integrations",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

src/platforms/salesforce/actions/contacts/find.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default action(
99
resource: 'contacts',
1010
mutation: false,
1111
schema: z.object({
12-
Id: z.number(),
12+
Id: z.string(),
1313
}),
1414
scopes: [],
1515
},

src/platforms/salesforce/actions/contacts/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default action(
1111
resource: 'contacts',
1212
mutation: false,
1313
schema: z.object({
14-
cursor: z.number(),
14+
cursor: z.string().optional(),
1515
}),
1616
scopes: [],
1717
},

src/platforms/salesforce/actions/listViewResults/find.ts renamed to src/platforms/salesforce/actions/list-view-results/find.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default action(
99
resource: 'list-view-results',
1010
mutation: false,
1111
schema: z.object({
12-
Id: z.number(),
12+
Id: z.string(),
1313
objectType: z.string(),
1414
}),
1515
scopes: [],

src/platforms/salesforce/actions/listViews/find.ts renamed to src/platforms/salesforce/actions/list-views/find.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default action(
99
resource: 'list-views',
1010
mutation: false,
1111
schema: z.object({
12-
Id: z.number(),
12+
Id: z.string(),
1313
}),
1414
scopes: [],
1515
},

src/platforms/salesforce/actions/listViews/list.ts renamed to src/platforms/salesforce/actions/list-views/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default action(
1111
resource: 'list-views',
1212
mutation: false,
1313
schema: z.object({
14-
cursor: z.number(),
14+
cursor: z.string().optional(),
1515
objectType: z.string().optional(),
1616
}),
1717
scopes: [],

src/platforms/salesforce/actions/pagination.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const getNextCursor = ({
44
records,
55
limit,
66
}: {
7-
records: { Id: number }[];
7+
records: { Id: string }[];
88
limit: number;
99
}) => {
1010
if (records.length < limit) {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { trim } from 'radash';
2+
import { MAX_QUERY_PAGE_SIZE } from '../constants';
3+
import { SalesforceSupportedObjectType } from '../schemas';
4+
5+
declare const brand: unique symbol;
6+
7+
type Brand<T, TBrand extends string> = T & {
8+
[brand]: TBrand;
9+
};
10+
11+
type SalesforceQuery = Brand<string, 'SalesforceQuery'>;
12+
13+
const formatQuery = (query: string): SalesforceQuery => {
14+
const cleanedQuery = trim(query.replace(/\n/g, ' '));
15+
return cleanedQuery.replace(/ +/g, '+') as SalesforceQuery;
16+
};
17+
18+
export const salesforceQueryBuilder: Record<
19+
string,
20+
(...args: any[]) => SalesforceQuery
21+
> = {
22+
list: ({
23+
objectType,
24+
cursor,
25+
relationalSelect,
26+
limit = MAX_QUERY_PAGE_SIZE,
27+
}: {
28+
objectType: SalesforceSupportedObjectType;
29+
cursor?: number;
30+
relationalSelect?: string;
31+
limit?: number;
32+
}) => {
33+
const select =
34+
'SELECT FIELDS(ALL)' + (relationalSelect ? `, ${relationalSelect}` : '');
35+
const getWhere = () => {
36+
if (!cursor) {
37+
return '';
38+
}
39+
return `WHERE Id < '${cursor}'`;
40+
};
41+
const where = getWhere();
42+
return formatQuery(`
43+
${select}
44+
FROM ${objectType}
45+
${where}
46+
ORDER BY Id DESC
47+
LIMIT ${limit}
48+
`);
49+
},
50+
listListView: ({
51+
objectType,
52+
cursor,
53+
limit = MAX_QUERY_PAGE_SIZE,
54+
}: {
55+
objectType?: string;
56+
cursor?: number;
57+
limit?: number;
58+
}) => {
59+
const getWhere = () => {
60+
if (!cursor) {
61+
return '';
62+
}
63+
return (
64+
`WHERE Id < '${cursor}'` +
65+
(objectType ? `AND SobjectType = '${objectType.toUpperCase()}'` : '')
66+
);
67+
};
68+
const where = getWhere();
69+
return formatQuery(`
70+
SELECT FIELDS(ALL)
71+
FROM ListView
72+
${where}
73+
ORDER BY Id DESC
74+
LIMIT ${limit}
75+
`);
76+
},
77+
};

src/platforms/salesforce/actions/users/find.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default action(
99
resource: 'users',
1010
mutation: false,
1111
schema: z.object({
12-
Id: z.number(),
12+
Id: z.string(),
1313
}),
1414
scopes: [],
1515
},

src/platforms/salesforce/actions/users/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default action(
1111
resource: 'users',
1212
mutation: false,
1313
schema: z.object({
14-
cursor: z.number().optional(),
14+
cursor: z.string().optional(),
1515
}),
1616
scopes: [],
1717
},

0 commit comments

Comments
 (0)