@keystrokehq/salesforce 0.0.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/README.md +205 -0
- package/dist/_official/index.d.mts +42 -0
- package/dist/_official/index.mjs +3 -0
- package/dist/_runtime/index.d.mts +6 -0
- package/dist/_runtime/index.mjs +89 -0
- package/dist/accounts.d.mts +97 -0
- package/dist/accounts.mjs +30 -0
- package/dist/associations.d.mts +40 -0
- package/dist/associations.mjs +70 -0
- package/dist/campaign-members.d.mts +97 -0
- package/dist/campaign-members.mjs +27 -0
- package/dist/campaigns.d.mts +97 -0
- package/dist/campaigns.mjs +28 -0
- package/dist/cases.d.mts +97 -0
- package/dist/cases.mjs +30 -0
- package/dist/client.d.mts +8 -0
- package/dist/client.mjs +26 -0
- package/dist/common-BUAhHMqn.mjs +28 -0
- package/dist/connection.d.mts +2 -0
- package/dist/connection.mjs +3 -0
- package/dist/contacts.d.mts +97 -0
- package/dist/contacts.mjs +29 -0
- package/dist/dashboards.d.mts +32 -0
- package/dist/dashboards.mjs +44 -0
- package/dist/factory-BBQAdBIT.mjs +8 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/integration-CGYEE2Ge.d.mts +62 -0
- package/dist/integration-C_hbWu9t.mjs +131 -0
- package/dist/leads.d.mts +97 -0
- package/dist/leads.mjs +30 -0
- package/dist/messaging.d.mts +1 -0
- package/dist/messaging.mjs +1 -0
- package/dist/notes.d.mts +97 -0
- package/dist/notes.mjs +26 -0
- package/dist/objects.d.mts +23 -0
- package/dist/objects.mjs +31 -0
- package/dist/opportunities.d.mts +97 -0
- package/dist/opportunities.mjs +29 -0
- package/dist/opportunity-line-items.d.mts +97 -0
- package/dist/opportunity-line-items.mjs +29 -0
- package/dist/ownership.d.mts +25 -0
- package/dist/ownership.mjs +49 -0
- package/dist/reports.d.mts +40 -0
- package/dist/reports.mjs +59 -0
- package/dist/schemas/index.d.mts +40 -0
- package/dist/schemas/index.mjs +3 -0
- package/dist/shared-B8YQavkg.mjs +196 -0
- package/dist/soql.d.mts +47 -0
- package/dist/soql.mjs +30 -0
- package/dist/tasks.d.mts +97 -0
- package/dist/tasks.mjs +29 -0
- package/dist/triggers.d.mts +83 -0
- package/dist/triggers.mjs +318 -0
- package/dist/users.d.mts +14 -0
- package/dist/users.mjs +20 -0
- package/package.json +153 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as zod from "zod";
|
|
2
|
+
import * as _keystrokehq_core0 from "@keystrokehq/core";
|
|
3
|
+
import * as _keystrokehq_core_credential_set0 from "@keystrokehq/core/credential-set";
|
|
4
|
+
import * as zod_v4_core0 from "zod/v4/core";
|
|
5
|
+
|
|
6
|
+
//#region src/opportunity-line-items.d.ts
|
|
7
|
+
declare const getOpportunityLineItem: _keystrokehq_core0.Operation<zod.ZodObject<{
|
|
8
|
+
id: zod.ZodString;
|
|
9
|
+
fields: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
|
|
10
|
+
}, zod_v4_core0.$strip>, zod.ZodObject<{
|
|
11
|
+
Id: zod.ZodOptional<zod.ZodString>;
|
|
12
|
+
attributes: zod.ZodOptional<zod.ZodObject<{
|
|
13
|
+
type: zod.ZodString;
|
|
14
|
+
url: zod.ZodString;
|
|
15
|
+
}, zod_v4_core0.$strip>>;
|
|
16
|
+
}, zod_v4_core0.$catchall<zod.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", zod.ZodObject<{
|
|
17
|
+
SALESFORCE_ACCESS_TOKEN: zod.ZodString;
|
|
18
|
+
SALESFORCE_INSTANCE_URL: zod.ZodURL;
|
|
19
|
+
}, zod_v4_core0.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<zod.ZodObject<{
|
|
20
|
+
SALESFORCE_ACCESS_TOKEN: zod.ZodString;
|
|
21
|
+
SALESFORCE_INSTANCE_URL: zod.ZodURL;
|
|
22
|
+
}, zod_v4_core0.$strip>>[] | undefined>], undefined>;
|
|
23
|
+
declare const listOpportunityLineItems: _keystrokehq_core0.Operation<zod.ZodObject<{
|
|
24
|
+
fields: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
|
|
25
|
+
where: zod.ZodOptional<zod.ZodRecord<zod.ZodString, zod.ZodUnion<readonly [zod.ZodString, zod.ZodNumber, zod.ZodBoolean, zod.ZodNull]>>>;
|
|
26
|
+
orderBy: zod.ZodOptional<zod.ZodString>;
|
|
27
|
+
orderDirection: zod.ZodOptional<zod.ZodEnum<{
|
|
28
|
+
ASC: "ASC";
|
|
29
|
+
DESC: "DESC";
|
|
30
|
+
}>>;
|
|
31
|
+
limit: zod.ZodOptional<zod.ZodNumber>;
|
|
32
|
+
}, zod_v4_core0.$strip>, zod.ZodObject<{
|
|
33
|
+
totalSize: zod.ZodNumber;
|
|
34
|
+
done: zod.ZodBoolean;
|
|
35
|
+
nextRecordsUrl: zod.ZodOptional<zod.ZodString>;
|
|
36
|
+
records: zod.ZodArray<zod.ZodObject<{
|
|
37
|
+
Id: zod.ZodOptional<zod.ZodString>;
|
|
38
|
+
attributes: zod.ZodOptional<zod.ZodObject<{
|
|
39
|
+
type: zod.ZodString;
|
|
40
|
+
url: zod.ZodString;
|
|
41
|
+
}, zod_v4_core0.$strip>>;
|
|
42
|
+
}, zod_v4_core0.$catchall<zod.ZodUnknown>>>;
|
|
43
|
+
}, zod_v4_core0.$strip>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", zod.ZodObject<{
|
|
44
|
+
SALESFORCE_ACCESS_TOKEN: zod.ZodString;
|
|
45
|
+
SALESFORCE_INSTANCE_URL: zod.ZodURL;
|
|
46
|
+
}, zod_v4_core0.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<zod.ZodObject<{
|
|
47
|
+
SALESFORCE_ACCESS_TOKEN: zod.ZodString;
|
|
48
|
+
SALESFORCE_INSTANCE_URL: zod.ZodURL;
|
|
49
|
+
}, zod_v4_core0.$strip>>[] | undefined>], undefined>;
|
|
50
|
+
declare const createOpportunityLineItem: _keystrokehq_core0.Operation<zod.ZodObject<{
|
|
51
|
+
fields: zod.ZodRecord<zod.ZodString, zod.ZodUnknown>;
|
|
52
|
+
returnFields: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
|
|
53
|
+
}, zod_v4_core0.$strip>, zod.ZodObject<{
|
|
54
|
+
Id: zod.ZodOptional<zod.ZodString>;
|
|
55
|
+
attributes: zod.ZodOptional<zod.ZodObject<{
|
|
56
|
+
type: zod.ZodString;
|
|
57
|
+
url: zod.ZodString;
|
|
58
|
+
}, zod_v4_core0.$strip>>;
|
|
59
|
+
}, zod_v4_core0.$catchall<zod.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", zod.ZodObject<{
|
|
60
|
+
SALESFORCE_ACCESS_TOKEN: zod.ZodString;
|
|
61
|
+
SALESFORCE_INSTANCE_URL: zod.ZodURL;
|
|
62
|
+
}, zod_v4_core0.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<zod.ZodObject<{
|
|
63
|
+
SALESFORCE_ACCESS_TOKEN: zod.ZodString;
|
|
64
|
+
SALESFORCE_INSTANCE_URL: zod.ZodURL;
|
|
65
|
+
}, zod_v4_core0.$strip>>[] | undefined>], undefined>;
|
|
66
|
+
declare const updateOpportunityLineItem: _keystrokehq_core0.Operation<zod.ZodObject<{
|
|
67
|
+
id: zod.ZodString;
|
|
68
|
+
fields: zod.ZodRecord<zod.ZodString, zod.ZodUnknown>;
|
|
69
|
+
returnFields: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
|
|
70
|
+
}, zod_v4_core0.$strip>, zod.ZodObject<{
|
|
71
|
+
Id: zod.ZodOptional<zod.ZodString>;
|
|
72
|
+
attributes: zod.ZodOptional<zod.ZodObject<{
|
|
73
|
+
type: zod.ZodString;
|
|
74
|
+
url: zod.ZodString;
|
|
75
|
+
}, zod_v4_core0.$strip>>;
|
|
76
|
+
}, zod_v4_core0.$catchall<zod.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", zod.ZodObject<{
|
|
77
|
+
SALESFORCE_ACCESS_TOKEN: zod.ZodString;
|
|
78
|
+
SALESFORCE_INSTANCE_URL: zod.ZodURL;
|
|
79
|
+
}, zod_v4_core0.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<zod.ZodObject<{
|
|
80
|
+
SALESFORCE_ACCESS_TOKEN: zod.ZodString;
|
|
81
|
+
SALESFORCE_INSTANCE_URL: zod.ZodURL;
|
|
82
|
+
}, zod_v4_core0.$strip>>[] | undefined>], undefined>;
|
|
83
|
+
declare const deleteOpportunityLineItem: _keystrokehq_core0.Operation<zod.ZodObject<{
|
|
84
|
+
id: zod.ZodString;
|
|
85
|
+
}, zod_v4_core0.$strip>, zod.ZodObject<{
|
|
86
|
+
success: zod.ZodBoolean;
|
|
87
|
+
id: zod.ZodOptional<zod.ZodString>;
|
|
88
|
+
errors: zod.ZodOptional<zod.ZodArray<zod.ZodString>>;
|
|
89
|
+
}, zod_v4_core0.$strip>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", zod.ZodObject<{
|
|
90
|
+
SALESFORCE_ACCESS_TOKEN: zod.ZodString;
|
|
91
|
+
SALESFORCE_INSTANCE_URL: zod.ZodURL;
|
|
92
|
+
}, zod_v4_core0.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<zod.ZodObject<{
|
|
93
|
+
SALESFORCE_ACCESS_TOKEN: zod.ZodString;
|
|
94
|
+
SALESFORCE_INSTANCE_URL: zod.ZodURL;
|
|
95
|
+
}, zod_v4_core0.$strip>>[] | undefined>], undefined>;
|
|
96
|
+
//#endregion
|
|
97
|
+
export { createOpportunityLineItem, deleteOpportunityLineItem, getOpportunityLineItem, listOpportunityLineItems, updateOpportunityLineItem };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { n as createSalesforceCrudOperations } from "./shared-B8YQavkg.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/opportunity-line-items.ts
|
|
4
|
+
const opportunityLineItemCrud = createSalesforceCrudOperations({
|
|
5
|
+
objectName: "OpportunityLineItem",
|
|
6
|
+
singularName: "Opportunity Line Item",
|
|
7
|
+
pluralName: "Opportunity Line Items",
|
|
8
|
+
operationPrefix: "opportunity_line_item",
|
|
9
|
+
defaultFields: [
|
|
10
|
+
"Id",
|
|
11
|
+
"OpportunityId",
|
|
12
|
+
"PricebookEntryId",
|
|
13
|
+
"Quantity",
|
|
14
|
+
"UnitPrice",
|
|
15
|
+
"TotalPrice",
|
|
16
|
+
"ServiceDate",
|
|
17
|
+
"Description",
|
|
18
|
+
"CreatedDate",
|
|
19
|
+
"LastModifiedDate"
|
|
20
|
+
]
|
|
21
|
+
});
|
|
22
|
+
const getOpportunityLineItem = opportunityLineItemCrud.getRecord;
|
|
23
|
+
const listOpportunityLineItems = opportunityLineItemCrud.listRecords;
|
|
24
|
+
const createOpportunityLineItem = opportunityLineItemCrud.createRecord;
|
|
25
|
+
const updateOpportunityLineItem = opportunityLineItemCrud.updateRecord;
|
|
26
|
+
const deleteOpportunityLineItem = opportunityLineItemCrud.deleteRecord;
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createOpportunityLineItem, deleteOpportunityLineItem, getOpportunityLineItem, listOpportunityLineItems, updateOpportunityLineItem };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as _keystrokehq_core0 from "@keystrokehq/core";
|
|
3
|
+
import * as _keystrokehq_core_credential_set0 from "@keystrokehq/core/credential-set";
|
|
4
|
+
|
|
5
|
+
//#region src/ownership.d.ts
|
|
6
|
+
declare const transferRecordOwnership: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
7
|
+
objectName: z.ZodString;
|
|
8
|
+
recordId: z.ZodString;
|
|
9
|
+
ownerId: z.ZodString;
|
|
10
|
+
returnFields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
11
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
12
|
+
Id: z.ZodOptional<z.ZodString>;
|
|
13
|
+
attributes: z.ZodOptional<z.ZodObject<{
|
|
14
|
+
type: z.ZodString;
|
|
15
|
+
url: z.ZodString;
|
|
16
|
+
}, z.core.$strip>>;
|
|
17
|
+
}, z.core.$catchall<z.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", z.ZodObject<{
|
|
18
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
19
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
20
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
21
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
22
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
23
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { transferRecordOwnership };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createSalesforceClient } from "./client.mjs";
|
|
2
|
+
import { i as salesforceIdSchema, s as salesforceRecordSchema } from "./common-BUAhHMqn.mjs";
|
|
3
|
+
import { t as salesforceOperation } from "./factory-BBQAdBIT.mjs";
|
|
4
|
+
import { a as normalizeSalesforceQueryResult, i as getSelectFields, o as salesforceFieldListSchema, r as ensureMutationSuccess, t as buildSelectQuery } from "./shared-B8YQavkg.mjs";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
//#region src/ownership.ts
|
|
8
|
+
const defaultOwnershipFields = [
|
|
9
|
+
"Id",
|
|
10
|
+
"OwnerId",
|
|
11
|
+
"LastModifiedDate"
|
|
12
|
+
];
|
|
13
|
+
function getClient(credentials) {
|
|
14
|
+
return createSalesforceClient(credentials);
|
|
15
|
+
}
|
|
16
|
+
async function getRecord(client, objectName, recordId, returnFields) {
|
|
17
|
+
const record = normalizeSalesforceQueryResult(await client.query(buildSelectQuery({
|
|
18
|
+
objectName,
|
|
19
|
+
fields: getSelectFields(returnFields, defaultOwnershipFields),
|
|
20
|
+
where: { Id: recordId },
|
|
21
|
+
limit: 1
|
|
22
|
+
}))).records[0];
|
|
23
|
+
if (!record) throw new Error(`Salesforce ${objectName} record ${recordId} was not found.`);
|
|
24
|
+
return salesforceRecordSchema.parse(record);
|
|
25
|
+
}
|
|
26
|
+
const transferRecordOwnership = salesforceOperation({
|
|
27
|
+
id: "transfer_record_ownership",
|
|
28
|
+
name: "Transfer Salesforce Record Ownership",
|
|
29
|
+
description: "Transfer a Salesforce record by updating its OwnerId to a new user",
|
|
30
|
+
input: z.object({
|
|
31
|
+
objectName: z.string().min(1),
|
|
32
|
+
recordId: salesforceIdSchema,
|
|
33
|
+
ownerId: salesforceIdSchema,
|
|
34
|
+
returnFields: salesforceFieldListSchema.optional()
|
|
35
|
+
}),
|
|
36
|
+
output: salesforceRecordSchema,
|
|
37
|
+
needsApproval: true,
|
|
38
|
+
run: async (input, credentials) => {
|
|
39
|
+
const client = getClient(credentials);
|
|
40
|
+
ensureMutationSuccess("update", input.objectName, await client.sobject(input.objectName).update({
|
|
41
|
+
Id: input.recordId,
|
|
42
|
+
OwnerId: input.ownerId
|
|
43
|
+
}));
|
|
44
|
+
return getRecord(client, input.objectName, input.recordId, input.returnFields);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { transferRecordOwnership };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as _keystrokehq_core0 from "@keystrokehq/core";
|
|
3
|
+
import * as _keystrokehq_core_credential_set0 from "@keystrokehq/core/credential-set";
|
|
4
|
+
|
|
5
|
+
//#region src/reports.d.ts
|
|
6
|
+
declare const listReports: _keystrokehq_core0.Operation<z.ZodObject<{}, z.core.$strip>, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", z.ZodObject<{
|
|
7
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
8
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
9
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
10
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
11
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
12
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
13
|
+
declare const listReportTypes: _keystrokehq_core0.Operation<z.ZodObject<{}, z.core.$strip>, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", z.ZodObject<{
|
|
14
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
15
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
16
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
17
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
18
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
19
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
20
|
+
declare const getReportMetadata: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
21
|
+
reportId: z.ZodString;
|
|
22
|
+
}, z.core.$strip>, z.ZodRecord<z.ZodString, z.ZodUnknown>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", z.ZodObject<{
|
|
23
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
24
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
25
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
26
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
27
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
28
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
29
|
+
declare const runReport: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
30
|
+
reportId: z.ZodString;
|
|
31
|
+
includeDetails: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
}, z.core.$strip>, z.ZodRecord<z.ZodString, z.ZodUnknown>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", z.ZodObject<{
|
|
33
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
34
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
35
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
36
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
37
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
38
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { getReportMetadata, listReportTypes, listReports, runReport };
|
package/dist/reports.mjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createSalesforceClient } from "./client.mjs";
|
|
2
|
+
import { n as salesforceGenericObjectArraySchema, r as salesforceGenericObjectSchema } from "./common-BUAhHMqn.mjs";
|
|
3
|
+
import { t as salesforceOperation } from "./factory-BBQAdBIT.mjs";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/reports.ts
|
|
7
|
+
const SALESFORCE_API_VERSION = "v61.0";
|
|
8
|
+
const listReports = salesforceOperation({
|
|
9
|
+
id: "list_reports",
|
|
10
|
+
name: "List Salesforce Reports",
|
|
11
|
+
description: "List report definitions available in Salesforce analytics",
|
|
12
|
+
input: z.object({}),
|
|
13
|
+
output: salesforceGenericObjectArraySchema,
|
|
14
|
+
run: async (_input, credentials) => {
|
|
15
|
+
const client = createSalesforceClient(credentials);
|
|
16
|
+
return salesforceGenericObjectArraySchema.parse(await client.request(`/services/data/${SALESFORCE_API_VERSION}/analytics/reports`));
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const listReportTypes = salesforceOperation({
|
|
20
|
+
id: "list_report_types",
|
|
21
|
+
name: "List Salesforce Report Types",
|
|
22
|
+
description: "List Salesforce analytics report types available to the connected account",
|
|
23
|
+
input: z.object({}),
|
|
24
|
+
output: salesforceGenericObjectArraySchema,
|
|
25
|
+
run: async (_input, credentials) => {
|
|
26
|
+
const client = createSalesforceClient(credentials);
|
|
27
|
+
return salesforceGenericObjectArraySchema.parse(await client.request(`/services/data/${SALESFORCE_API_VERSION}/analytics/reportTypes`));
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const getReportMetadata = salesforceOperation({
|
|
31
|
+
id: "get_report_metadata",
|
|
32
|
+
name: "Get Salesforce Report Metadata",
|
|
33
|
+
description: "Fetch metadata for a Salesforce analytics report",
|
|
34
|
+
input: z.object({ reportId: z.string().min(1) }),
|
|
35
|
+
output: salesforceGenericObjectSchema,
|
|
36
|
+
run: async (input, credentials) => {
|
|
37
|
+
const client = createSalesforceClient(credentials);
|
|
38
|
+
return salesforceGenericObjectSchema.parse(await client.request(`/services/data/${SALESFORCE_API_VERSION}/analytics/reports/${input.reportId}/describe`));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const runReport = salesforceOperation({
|
|
42
|
+
id: "run_report",
|
|
43
|
+
name: "Run Salesforce Report",
|
|
44
|
+
description: "Run a Salesforce analytics report and return the result payload",
|
|
45
|
+
input: z.object({
|
|
46
|
+
reportId: z.string().min(1),
|
|
47
|
+
includeDetails: z.boolean().optional()
|
|
48
|
+
}),
|
|
49
|
+
output: salesforceGenericObjectSchema,
|
|
50
|
+
run: async (input, credentials) => {
|
|
51
|
+
const client = createSalesforceClient(credentials);
|
|
52
|
+
const url = new URL(`/services/data/${SALESFORCE_API_VERSION}/analytics/reports/${input.reportId}`, "https://keystroke.local");
|
|
53
|
+
url.searchParams.set("includeDetails", String(input.includeDetails ?? false));
|
|
54
|
+
return salesforceGenericObjectSchema.parse(await client.request(`${url.pathname}${url.search}`));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { getReportMetadata, listReportTypes, listReports, runReport };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/schemas/common.d.ts
|
|
4
|
+
declare const salesforceIdSchema: z.ZodString;
|
|
5
|
+
declare const salesforceAttributesSchema: z.ZodObject<{
|
|
6
|
+
type: z.ZodString;
|
|
7
|
+
url: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
declare const salesforceRecordSchema: z.ZodObject<{
|
|
10
|
+
Id: z.ZodOptional<z.ZodString>;
|
|
11
|
+
attributes: z.ZodOptional<z.ZodObject<{
|
|
12
|
+
type: z.ZodString;
|
|
13
|
+
url: z.ZodString;
|
|
14
|
+
}, z.core.$strip>>;
|
|
15
|
+
}, z.core.$catchall<z.ZodUnknown>>;
|
|
16
|
+
declare const salesforceQueryResultSchema: z.ZodObject<{
|
|
17
|
+
totalSize: z.ZodNumber;
|
|
18
|
+
done: z.ZodBoolean;
|
|
19
|
+
nextRecordsUrl: z.ZodOptional<z.ZodString>;
|
|
20
|
+
records: z.ZodArray<z.ZodObject<{
|
|
21
|
+
Id: z.ZodOptional<z.ZodString>;
|
|
22
|
+
attributes: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
type: z.ZodString;
|
|
24
|
+
url: z.ZodString;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
}, z.core.$catchall<z.ZodUnknown>>>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
declare const salesforceMutationResultSchema: z.ZodObject<{
|
|
29
|
+
success: z.ZodBoolean;
|
|
30
|
+
id: z.ZodOptional<z.ZodString>;
|
|
31
|
+
errors: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
declare const salesforceGenericObjectSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
34
|
+
declare const salesforceGenericObjectArraySchema: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
35
|
+
type SalesforceRecord = z.infer<typeof salesforceRecordSchema>;
|
|
36
|
+
type SalesforceQueryResult = z.infer<typeof salesforceQueryResultSchema>;
|
|
37
|
+
type SalesforceMutationResult = z.infer<typeof salesforceMutationResultSchema>;
|
|
38
|
+
type SalesforceGenericObject = z.infer<typeof salesforceGenericObjectSchema>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { type SalesforceGenericObject, type SalesforceMutationResult, type SalesforceQueryResult, type SalesforceRecord, salesforceAttributesSchema, salesforceGenericObjectArraySchema, salesforceGenericObjectSchema, salesforceIdSchema, salesforceMutationResultSchema, salesforceQueryResultSchema, salesforceRecordSchema };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as salesforceMutationResultSchema, i as salesforceIdSchema, n as salesforceGenericObjectArraySchema, o as salesforceQueryResultSchema, r as salesforceGenericObjectSchema, s as salesforceRecordSchema, t as salesforceAttributesSchema } from "../common-BUAhHMqn.mjs";
|
|
2
|
+
|
|
3
|
+
export { salesforceAttributesSchema, salesforceGenericObjectArraySchema, salesforceGenericObjectSchema, salesforceIdSchema, salesforceMutationResultSchema, salesforceQueryResultSchema, salesforceRecordSchema };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { createSalesforceClient } from "./client.mjs";
|
|
2
|
+
import { a as salesforceMutationResultSchema, i as salesforceIdSchema, o as salesforceQueryResultSchema, s as salesforceRecordSchema } from "./common-BUAhHMqn.mjs";
|
|
3
|
+
import { t as salesforceOperation } from "./factory-BBQAdBIT.mjs";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/shared.ts
|
|
7
|
+
const salesforceFilterValueSchema = z.union([
|
|
8
|
+
z.string(),
|
|
9
|
+
z.number(),
|
|
10
|
+
z.boolean(),
|
|
11
|
+
z.null()
|
|
12
|
+
]);
|
|
13
|
+
const salesforceFieldListSchema = z.array(z.string().min(1));
|
|
14
|
+
const salesforceRecordFieldsSchema = z.record(z.string(), z.unknown());
|
|
15
|
+
const salesforceWhereSchema = z.record(z.string(), salesforceFilterValueSchema);
|
|
16
|
+
const salesforceGetRecordInputSchema = z.object({
|
|
17
|
+
id: salesforceIdSchema,
|
|
18
|
+
fields: salesforceFieldListSchema.optional()
|
|
19
|
+
});
|
|
20
|
+
const salesforceListRecordsInputSchema = z.object({
|
|
21
|
+
fields: salesforceFieldListSchema.optional(),
|
|
22
|
+
where: salesforceWhereSchema.optional(),
|
|
23
|
+
orderBy: z.string().min(1).optional(),
|
|
24
|
+
orderDirection: z.enum(["ASC", "DESC"]).optional(),
|
|
25
|
+
limit: z.number().int().positive().max(200).optional()
|
|
26
|
+
});
|
|
27
|
+
const salesforceCreateRecordInputSchema = z.object({
|
|
28
|
+
fields: salesforceRecordFieldsSchema,
|
|
29
|
+
returnFields: salesforceFieldListSchema.optional()
|
|
30
|
+
});
|
|
31
|
+
const salesforceUpdateRecordInputSchema = z.object({
|
|
32
|
+
id: salesforceIdSchema,
|
|
33
|
+
fields: salesforceRecordFieldsSchema,
|
|
34
|
+
returnFields: salesforceFieldListSchema.optional()
|
|
35
|
+
});
|
|
36
|
+
const salesforceDeleteRecordInputSchema = z.object({ id: salesforceIdSchema });
|
|
37
|
+
function getClient(credentials) {
|
|
38
|
+
return createSalesforceClient(credentials);
|
|
39
|
+
}
|
|
40
|
+
function escapeSoqlString(value) {
|
|
41
|
+
return value.replaceAll("\\", "\\\\").replaceAll("'", "\\'");
|
|
42
|
+
}
|
|
43
|
+
function toSoqlLiteral(value) {
|
|
44
|
+
if (value === null) return "NULL";
|
|
45
|
+
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
46
|
+
if (typeof value === "number") return String(value);
|
|
47
|
+
return `'${escapeSoqlString(value)}'`;
|
|
48
|
+
}
|
|
49
|
+
function getSelectFields(fields, defaultFields) {
|
|
50
|
+
return Array.from(new Set([...fields ?? defaultFields, "Id"]));
|
|
51
|
+
}
|
|
52
|
+
function buildWhereClause(where) {
|
|
53
|
+
if (!where || Object.keys(where).length === 0) return "";
|
|
54
|
+
return ` WHERE ${Object.entries(where).map(([field, value]) => `${field} = ${toSoqlLiteral(value)}`).join(" AND ")}`;
|
|
55
|
+
}
|
|
56
|
+
function buildSelectQuery(params) {
|
|
57
|
+
const orderByClause = params.orderBy ? ` ORDER BY ${params.orderBy} ${params.orderDirection ?? "ASC"}` : "";
|
|
58
|
+
const limitClause = params.limit ? ` LIMIT ${params.limit}` : "";
|
|
59
|
+
return `SELECT ${params.fields.join(", ")} FROM ${params.objectName}${buildWhereClause(params.where)}${orderByClause}${limitClause}`;
|
|
60
|
+
}
|
|
61
|
+
function normalizeSalesforceRecord(record) {
|
|
62
|
+
return salesforceRecordSchema.parse(record);
|
|
63
|
+
}
|
|
64
|
+
function normalizeSalesforceQueryResult(result) {
|
|
65
|
+
const parsed = salesforceQueryResultSchema.parse(result);
|
|
66
|
+
return {
|
|
67
|
+
...parsed,
|
|
68
|
+
records: parsed.records.map(normalizeSalesforceRecord)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function formatMutationErrors(errors) {
|
|
72
|
+
if (!errors || errors.length === 0) return;
|
|
73
|
+
return errors.map((error) => {
|
|
74
|
+
if (typeof error === "string") return error;
|
|
75
|
+
if (typeof error === "object" && error !== null && "message" in error) {
|
|
76
|
+
const message = error.message;
|
|
77
|
+
if (typeof message === "string" && message.length > 0) return message;
|
|
78
|
+
}
|
|
79
|
+
return JSON.stringify(error);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function ensureMutationSuccess(action, objectName, result) {
|
|
83
|
+
if (!result.success) {
|
|
84
|
+
const errors = formatMutationErrors(result.errors);
|
|
85
|
+
throw new Error(`Salesforce ${action} failed for ${objectName}.${errors?.length ? ` ${errors.join("; ")}` : ""}`.trim());
|
|
86
|
+
}
|
|
87
|
+
return salesforceMutationResultSchema.parse({
|
|
88
|
+
success: true,
|
|
89
|
+
id: result.id,
|
|
90
|
+
...formatMutationErrors(result.errors) ? { errors: formatMutationErrors(result.errors) } : {}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async function getRecordById(params) {
|
|
94
|
+
const record = normalizeSalesforceQueryResult(await params.client.query(buildSelectQuery({
|
|
95
|
+
objectName: params.objectName,
|
|
96
|
+
fields: getSelectFields(params.fields, params.defaultFields),
|
|
97
|
+
where: { Id: params.id },
|
|
98
|
+
limit: 1
|
|
99
|
+
}))).records[0];
|
|
100
|
+
if (!record) throw new Error(`Salesforce ${params.objectName} record ${params.id} was not found.`);
|
|
101
|
+
return record;
|
|
102
|
+
}
|
|
103
|
+
function createSalesforceCrudOperations(config) {
|
|
104
|
+
return {
|
|
105
|
+
getRecord: salesforceOperation({
|
|
106
|
+
id: `get_${config.operationPrefix}`,
|
|
107
|
+
name: `Get Salesforce ${config.singularName}`,
|
|
108
|
+
description: `Retrieve a single ${config.singularName.toLowerCase()} record from Salesforce`,
|
|
109
|
+
input: salesforceGetRecordInputSchema,
|
|
110
|
+
output: salesforceRecordSchema,
|
|
111
|
+
run: async (input, credentials) => {
|
|
112
|
+
return getRecordById({
|
|
113
|
+
client: getClient(credentials),
|
|
114
|
+
objectName: config.objectName,
|
|
115
|
+
id: input.id,
|
|
116
|
+
fields: input.fields,
|
|
117
|
+
defaultFields: config.defaultFields
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}),
|
|
121
|
+
listRecords: salesforceOperation({
|
|
122
|
+
id: `list_${config.operationPrefix}s`,
|
|
123
|
+
name: `List Salesforce ${config.pluralName}`,
|
|
124
|
+
description: `List ${config.pluralName.toLowerCase()} from Salesforce`,
|
|
125
|
+
input: salesforceListRecordsInputSchema,
|
|
126
|
+
output: salesforceQueryResultSchema,
|
|
127
|
+
run: async (input, credentials) => {
|
|
128
|
+
return normalizeSalesforceQueryResult(await getClient(credentials).query(buildSelectQuery({
|
|
129
|
+
objectName: config.objectName,
|
|
130
|
+
fields: getSelectFields(input.fields, config.defaultFields),
|
|
131
|
+
where: input.where,
|
|
132
|
+
orderBy: input.orderBy,
|
|
133
|
+
orderDirection: input.orderDirection,
|
|
134
|
+
limit: input.limit ?? 25
|
|
135
|
+
})));
|
|
136
|
+
}
|
|
137
|
+
}),
|
|
138
|
+
createRecord: salesforceOperation({
|
|
139
|
+
id: `create_${config.operationPrefix}`,
|
|
140
|
+
name: `Create Salesforce ${config.singularName}`,
|
|
141
|
+
description: `Create a new ${config.singularName.toLowerCase()} record in Salesforce`,
|
|
142
|
+
input: salesforceCreateRecordInputSchema,
|
|
143
|
+
output: salesforceRecordSchema,
|
|
144
|
+
needsApproval: true,
|
|
145
|
+
run: async (input, credentials) => {
|
|
146
|
+
const client = getClient(credentials);
|
|
147
|
+
const result = ensureMutationSuccess("create", config.objectName, await client.sobject(config.objectName).create(input.fields));
|
|
148
|
+
if (!result.id) throw new Error(`Salesforce create did not return an id for ${config.objectName}.`);
|
|
149
|
+
return getRecordById({
|
|
150
|
+
client,
|
|
151
|
+
objectName: config.objectName,
|
|
152
|
+
id: result.id,
|
|
153
|
+
fields: input.returnFields,
|
|
154
|
+
defaultFields: config.defaultFields
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}),
|
|
158
|
+
updateRecord: salesforceOperation({
|
|
159
|
+
id: `update_${config.operationPrefix}`,
|
|
160
|
+
name: `Update Salesforce ${config.singularName}`,
|
|
161
|
+
description: `Update an existing ${config.singularName.toLowerCase()} record in Salesforce`,
|
|
162
|
+
input: salesforceUpdateRecordInputSchema,
|
|
163
|
+
output: salesforceRecordSchema,
|
|
164
|
+
needsApproval: true,
|
|
165
|
+
run: async (input, credentials) => {
|
|
166
|
+
const client = getClient(credentials);
|
|
167
|
+
ensureMutationSuccess("update", config.objectName, await client.sobject(config.objectName).update({
|
|
168
|
+
Id: input.id,
|
|
169
|
+
...input.fields
|
|
170
|
+
}));
|
|
171
|
+
return getRecordById({
|
|
172
|
+
client,
|
|
173
|
+
objectName: config.objectName,
|
|
174
|
+
id: input.id,
|
|
175
|
+
fields: input.returnFields,
|
|
176
|
+
defaultFields: config.defaultFields
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}),
|
|
180
|
+
deleteRecord: salesforceOperation({
|
|
181
|
+
id: `delete_${config.operationPrefix}`,
|
|
182
|
+
name: `Delete Salesforce ${config.singularName}`,
|
|
183
|
+
description: `Delete a ${config.singularName.toLowerCase()} record in Salesforce`,
|
|
184
|
+
input: salesforceDeleteRecordInputSchema,
|
|
185
|
+
output: salesforceMutationResultSchema,
|
|
186
|
+
needsApproval: true,
|
|
187
|
+
run: async (input, credentials) => {
|
|
188
|
+
const client = getClient(credentials);
|
|
189
|
+
return ensureMutationSuccess("delete", config.objectName, await client.sobject(config.objectName).destroy(input.id));
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
//#endregion
|
|
196
|
+
export { normalizeSalesforceQueryResult as a, getSelectFields as i, createSalesforceCrudOperations as n, salesforceFieldListSchema as o, ensureMutationSuccess as r, buildSelectQuery as t };
|
package/dist/soql.d.mts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as _keystrokehq_core0 from "@keystrokehq/core";
|
|
3
|
+
import * as _keystrokehq_core_credential_set0 from "@keystrokehq/core/credential-set";
|
|
4
|
+
|
|
5
|
+
//#region src/soql.d.ts
|
|
6
|
+
declare const runSoqlQuery: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
7
|
+
query: z.ZodString;
|
|
8
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
9
|
+
totalSize: z.ZodNumber;
|
|
10
|
+
done: z.ZodBoolean;
|
|
11
|
+
nextRecordsUrl: z.ZodOptional<z.ZodString>;
|
|
12
|
+
records: z.ZodArray<z.ZodObject<{
|
|
13
|
+
Id: z.ZodOptional<z.ZodString>;
|
|
14
|
+
attributes: z.ZodOptional<z.ZodObject<{
|
|
15
|
+
type: z.ZodString;
|
|
16
|
+
url: z.ZodString;
|
|
17
|
+
}, z.core.$strip>>;
|
|
18
|
+
}, z.core.$catchall<z.ZodUnknown>>>;
|
|
19
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", z.ZodObject<{
|
|
20
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
21
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
22
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
23
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
24
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
25
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
26
|
+
declare const queryMore: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
27
|
+
nextRecordsUrl: z.ZodString;
|
|
28
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
29
|
+
totalSize: z.ZodNumber;
|
|
30
|
+
done: z.ZodBoolean;
|
|
31
|
+
nextRecordsUrl: z.ZodOptional<z.ZodString>;
|
|
32
|
+
records: z.ZodArray<z.ZodObject<{
|
|
33
|
+
Id: z.ZodOptional<z.ZodString>;
|
|
34
|
+
attributes: z.ZodOptional<z.ZodObject<{
|
|
35
|
+
type: z.ZodString;
|
|
36
|
+
url: z.ZodString;
|
|
37
|
+
}, z.core.$strip>>;
|
|
38
|
+
}, z.core.$catchall<z.ZodUnknown>>>;
|
|
39
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"salesforce", z.ZodObject<{
|
|
40
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
41
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
42
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
43
|
+
SALESFORCE_ACCESS_TOKEN: z.ZodString;
|
|
44
|
+
SALESFORCE_INSTANCE_URL: z.ZodURL;
|
|
45
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { queryMore, runSoqlQuery };
|
package/dist/soql.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createSalesforceClient } from "./client.mjs";
|
|
2
|
+
import { o as salesforceQueryResultSchema } from "./common-BUAhHMqn.mjs";
|
|
3
|
+
import { t as salesforceOperation } from "./factory-BBQAdBIT.mjs";
|
|
4
|
+
import { a as normalizeSalesforceQueryResult } from "./shared-B8YQavkg.mjs";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
//#region src/soql.ts
|
|
8
|
+
const runSoqlQuery = salesforceOperation({
|
|
9
|
+
id: "run_soql_query",
|
|
10
|
+
name: "Run Salesforce SOQL Query",
|
|
11
|
+
description: "Run an arbitrary SOQL query against Salesforce",
|
|
12
|
+
input: z.object({ query: z.string().min(1) }),
|
|
13
|
+
output: salesforceQueryResultSchema,
|
|
14
|
+
run: async (input, credentials) => {
|
|
15
|
+
return normalizeSalesforceQueryResult(await createSalesforceClient(credentials).query(input.query));
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const queryMore = salesforceOperation({
|
|
19
|
+
id: "query_more",
|
|
20
|
+
name: "Run Salesforce Query More",
|
|
21
|
+
description: "Fetch the next page of a Salesforce query result using nextRecordsUrl",
|
|
22
|
+
input: z.object({ nextRecordsUrl: z.string().min(1) }),
|
|
23
|
+
output: salesforceQueryResultSchema,
|
|
24
|
+
run: async (input, credentials) => {
|
|
25
|
+
return normalizeSalesforceQueryResult(await createSalesforceClient(credentials).queryMore(input.nextRecordsUrl));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { queryMore, runSoqlQuery };
|