@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
package/dist/tasks.d.mts
ADDED
|
@@ -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/tasks.d.ts
|
|
7
|
+
declare const getTask: _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 listTasks: _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 createTask: _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 updateTask: _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 deleteTask: _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 { createTask, deleteTask, getTask, listTasks, updateTask };
|
package/dist/tasks.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { n as createSalesforceCrudOperations } from "./shared-B8YQavkg.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/tasks.ts
|
|
4
|
+
const taskCrud = createSalesforceCrudOperations({
|
|
5
|
+
objectName: "Task",
|
|
6
|
+
singularName: "Task",
|
|
7
|
+
pluralName: "Tasks",
|
|
8
|
+
operationPrefix: "task",
|
|
9
|
+
defaultFields: [
|
|
10
|
+
"Id",
|
|
11
|
+
"Subject",
|
|
12
|
+
"Status",
|
|
13
|
+
"Priority",
|
|
14
|
+
"ActivityDate",
|
|
15
|
+
"WhoId",
|
|
16
|
+
"WhatId",
|
|
17
|
+
"OwnerId",
|
|
18
|
+
"CreatedDate",
|
|
19
|
+
"LastModifiedDate"
|
|
20
|
+
]
|
|
21
|
+
});
|
|
22
|
+
const getTask = taskCrud.getRecord;
|
|
23
|
+
const listTasks = taskCrud.listRecords;
|
|
24
|
+
const createTask = taskCrud.createRecord;
|
|
25
|
+
const updateTask = taskCrud.updateRecord;
|
|
26
|
+
const deleteTask = taskCrud.deleteRecord;
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createTask, deleteTask, getTask, listTasks, updateTask };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { n as salesforce } from "./integration-CGYEE2Ge.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { BoundTrigger } from "@keystrokehq/core";
|
|
4
|
+
import { IntegrationTriggerBindingOptions, createPollingTriggerBindingFactory } from "@keystrokehq/integration-authoring";
|
|
5
|
+
import { PollingTriggerManifest } from "@keystrokehq/core/trigger";
|
|
6
|
+
|
|
7
|
+
//#region src/triggers.d.ts
|
|
8
|
+
type Schedule = Parameters<typeof createPollingTriggerBindingFactory>[0]['schedule'];
|
|
9
|
+
type SalesforcePollingCredentialSets = readonly [typeof salesforce];
|
|
10
|
+
declare const salesforcePollingResponseSchema: z.ZodObject<{
|
|
11
|
+
objectName: z.ZodString;
|
|
12
|
+
watermarkField: z.ZodString;
|
|
13
|
+
query: z.ZodString;
|
|
14
|
+
records: z.ZodArray<z.ZodObject<{
|
|
15
|
+
Id: z.ZodOptional<z.ZodString>;
|
|
16
|
+
attributes: z.ZodOptional<z.ZodObject<{
|
|
17
|
+
type: z.ZodString;
|
|
18
|
+
url: z.ZodString;
|
|
19
|
+
}, z.core.$strip>>;
|
|
20
|
+
}, z.core.$catchall<z.ZodUnknown>>>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
declare const salesforceTriggerPayloadSchema: z.ZodObject<{
|
|
23
|
+
eventType: z.ZodEnum<{
|
|
24
|
+
"account.created_or_updated": "account.created_or_updated";
|
|
25
|
+
"contact.updated": "contact.updated";
|
|
26
|
+
"contact.created": "contact.created";
|
|
27
|
+
"lead.created": "lead.created";
|
|
28
|
+
"opportunity.created_or_updated": "opportunity.created_or_updated";
|
|
29
|
+
"task.created": "task.created";
|
|
30
|
+
"task.completed": "task.completed";
|
|
31
|
+
"sobject.updated": "sobject.updated";
|
|
32
|
+
}>;
|
|
33
|
+
objectName: z.ZodString;
|
|
34
|
+
records: z.ZodArray<z.ZodObject<{
|
|
35
|
+
Id: z.ZodOptional<z.ZodString>;
|
|
36
|
+
attributes: z.ZodOptional<z.ZodObject<{
|
|
37
|
+
type: z.ZodString;
|
|
38
|
+
url: z.ZodString;
|
|
39
|
+
}, z.core.$strip>>;
|
|
40
|
+
}, z.core.$catchall<z.ZodUnknown>>>;
|
|
41
|
+
taskEventType: z.ZodOptional<z.ZodEnum<{
|
|
42
|
+
task_created: "task_created";
|
|
43
|
+
task_completed: "task_completed";
|
|
44
|
+
}>>;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
type SalesforcePollingResponse = z.output<typeof salesforcePollingResponseSchema>;
|
|
47
|
+
type SalesforceTriggerPayload = z.output<typeof salesforceTriggerPayloadSchema>;
|
|
48
|
+
type SalesforcePollingBoundTrigger<TOutput = SalesforceTriggerPayload> = BoundTrigger<SalesforcePollingResponse, SalesforcePollingCredentialSets, PollingTriggerManifest, TOutput>;
|
|
49
|
+
type SalesforceFilterValue = string | number | boolean | null;
|
|
50
|
+
interface SalesforcePollingBindingOptions<TOutput = SalesforceTriggerPayload> extends IntegrationTriggerBindingOptions<SalesforceTriggerPayload, TOutput> {
|
|
51
|
+
readonly schedule?: Schedule;
|
|
52
|
+
readonly limit?: number;
|
|
53
|
+
}
|
|
54
|
+
interface SalesforcePollingNamespace {
|
|
55
|
+
readonly accountCreatedOrUpdated: <TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>) => SalesforcePollingBoundTrigger<TOutput>;
|
|
56
|
+
readonly contactUpdated: <TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>) => SalesforcePollingBoundTrigger<TOutput>;
|
|
57
|
+
readonly newContact: <TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>) => SalesforcePollingBoundTrigger<TOutput>;
|
|
58
|
+
readonly newLead: <TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>) => SalesforcePollingBoundTrigger<TOutput>;
|
|
59
|
+
readonly opportunityCreatedOrUpdated: <TOutput = SalesforceTriggerPayload>(options?: SalesforceOpportunityPollingConfig<TOutput>) => SalesforcePollingBoundTrigger<TOutput>;
|
|
60
|
+
readonly taskCreated: <TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>) => SalesforcePollingBoundTrigger<TOutput>;
|
|
61
|
+
readonly taskCompleted: <TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>) => SalesforcePollingBoundTrigger<TOutput>;
|
|
62
|
+
readonly sObjectRecordUpdated: <TOutput = SalesforceTriggerPayload>(config: SalesforceGenericPollingConfig<TOutput>) => SalesforcePollingBoundTrigger<TOutput>;
|
|
63
|
+
}
|
|
64
|
+
interface SalesforceGenericPollingConfig<TOutput = SalesforceTriggerPayload> extends SalesforcePollingBindingOptions<TOutput> {
|
|
65
|
+
readonly objectName: string;
|
|
66
|
+
readonly fields?: readonly string[];
|
|
67
|
+
readonly watermarkField?: string;
|
|
68
|
+
readonly where?: Record<string, SalesforceFilterValue>;
|
|
69
|
+
}
|
|
70
|
+
interface SalesforceOpportunityPollingConfig<TOutput = SalesforceTriggerPayload> extends SalesforcePollingBindingOptions<TOutput> {
|
|
71
|
+
readonly stages?: readonly string[];
|
|
72
|
+
}
|
|
73
|
+
declare function accountCreatedOrUpdated<TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>): SalesforcePollingBoundTrigger<TOutput>;
|
|
74
|
+
declare function contactUpdated<TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>): SalesforcePollingBoundTrigger<TOutput>;
|
|
75
|
+
declare function newContact<TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>): SalesforcePollingBoundTrigger<TOutput>;
|
|
76
|
+
declare function newLead<TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>): SalesforcePollingBoundTrigger<TOutput>;
|
|
77
|
+
declare function opportunityCreatedOrUpdated<TOutput = SalesforceTriggerPayload>(options?: SalesforceOpportunityPollingConfig<TOutput>): SalesforcePollingBoundTrigger<TOutput>;
|
|
78
|
+
declare function taskCreated<TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>): SalesforcePollingBoundTrigger<TOutput>;
|
|
79
|
+
declare function taskCompleted<TOutput = SalesforceTriggerPayload>(options?: SalesforcePollingBindingOptions<TOutput>): SalesforcePollingBoundTrigger<TOutput>;
|
|
80
|
+
declare function sObjectRecordUpdated<TOutput = SalesforceTriggerPayload>(config: SalesforceGenericPollingConfig<TOutput>): SalesforcePollingBoundTrigger<TOutput>;
|
|
81
|
+
declare const polling: SalesforcePollingNamespace;
|
|
82
|
+
//#endregion
|
|
83
|
+
export { SalesforceGenericPollingConfig, SalesforceOpportunityPollingConfig, SalesforcePollingNamespace, accountCreatedOrUpdated, contactUpdated, newContact, newLead, opportunityCreatedOrUpdated, polling, sObjectRecordUpdated, taskCompleted, taskCreated };
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { t as salesforce } from "./integration-C_hbWu9t.mjs";
|
|
2
|
+
import { createSalesforceClient } from "./client.mjs";
|
|
3
|
+
import { s as salesforceRecordSchema } from "./common-BUAhHMqn.mjs";
|
|
4
|
+
import { a as normalizeSalesforceQueryResult } from "./shared-B8YQavkg.mjs";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { createPollingTriggerBindingFactory } from "@keystrokehq/integration-authoring";
|
|
7
|
+
|
|
8
|
+
//#region src/triggers.ts
|
|
9
|
+
const salesforcePollingResponseSchema = z.object({
|
|
10
|
+
objectName: z.string().min(1),
|
|
11
|
+
watermarkField: z.string().min(1),
|
|
12
|
+
query: z.string().min(1),
|
|
13
|
+
records: z.array(salesforceRecordSchema)
|
|
14
|
+
});
|
|
15
|
+
const salesforceTriggerEventTypeSchema = z.enum([
|
|
16
|
+
"account.created_or_updated",
|
|
17
|
+
"contact.updated",
|
|
18
|
+
"contact.created",
|
|
19
|
+
"lead.created",
|
|
20
|
+
"opportunity.created_or_updated",
|
|
21
|
+
"task.created",
|
|
22
|
+
"task.completed",
|
|
23
|
+
"sobject.updated"
|
|
24
|
+
]);
|
|
25
|
+
const salesforceTaskEventTypeSchema = z.enum(["task_created", "task_completed"]);
|
|
26
|
+
z.object({
|
|
27
|
+
eventType: salesforceTriggerEventTypeSchema,
|
|
28
|
+
objectName: z.string().min(1),
|
|
29
|
+
records: z.array(salesforceRecordSchema),
|
|
30
|
+
taskEventType: salesforceTaskEventTypeSchema.optional()
|
|
31
|
+
});
|
|
32
|
+
function withDefaultSchedule(schedule) {
|
|
33
|
+
if (schedule === void 0) return "5m";
|
|
34
|
+
return schedule;
|
|
35
|
+
}
|
|
36
|
+
function escapeSoqlString(value) {
|
|
37
|
+
return value.replaceAll("\\", "\\\\").replaceAll("'", "\\'");
|
|
38
|
+
}
|
|
39
|
+
function toSoqlLiteral(value) {
|
|
40
|
+
if (value === null) return "NULL";
|
|
41
|
+
if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
|
|
42
|
+
if (typeof value === "number") return String(value);
|
|
43
|
+
return `'${escapeSoqlString(value)}'`;
|
|
44
|
+
}
|
|
45
|
+
function toSoqlDateTimeLiteral(value) {
|
|
46
|
+
return escapeSoqlString(value);
|
|
47
|
+
}
|
|
48
|
+
function buildWhereClause(filters) {
|
|
49
|
+
if (filters.length === 0) return "";
|
|
50
|
+
return ` WHERE ${filters.join(" AND ")}`;
|
|
51
|
+
}
|
|
52
|
+
function buildInClause(field, values) {
|
|
53
|
+
if (values.length === 0) return;
|
|
54
|
+
return `${field} IN (${values.map((value) => toSoqlLiteral(value)).join(", ")})`;
|
|
55
|
+
}
|
|
56
|
+
function buildSalesforcePollingQuery(params) {
|
|
57
|
+
const filters = Object.entries(params.where ?? {}).map(([field, value]) => `${field} = ${toSoqlLiteral(value)}`);
|
|
58
|
+
filters.push(...params.extraFilters ?? []);
|
|
59
|
+
if (params.lastPolledAt) filters.push(`${params.watermarkField} >= ${toSoqlDateTimeLiteral(params.lastPolledAt)}`);
|
|
60
|
+
return `SELECT ${Array.from(new Set([
|
|
61
|
+
...params.fields,
|
|
62
|
+
"Id",
|
|
63
|
+
params.watermarkField
|
|
64
|
+
])).join(", ")} FROM ${params.objectName}${buildWhereClause(filters)} ORDER BY ${params.watermarkField} ASC LIMIT ${params.limit}`;
|
|
65
|
+
}
|
|
66
|
+
function createPollingClient(credentials) {
|
|
67
|
+
return createSalesforceClient(credentials);
|
|
68
|
+
}
|
|
69
|
+
function buildIdempotencyKey(payload, eventType) {
|
|
70
|
+
const firstRecord = payload.records[0];
|
|
71
|
+
if (!firstRecord) return;
|
|
72
|
+
const id = typeof firstRecord.Id === "string" ? firstRecord.Id : "unknown";
|
|
73
|
+
const watermark = firstRecord[payload.watermarkField];
|
|
74
|
+
return `${eventType ?? payload.objectName}:${id}:${typeof watermark === "string" ? watermark : "unknown"}`;
|
|
75
|
+
}
|
|
76
|
+
function splitPollingOptions(options) {
|
|
77
|
+
return {
|
|
78
|
+
schedule: options?.schedule,
|
|
79
|
+
limit: options?.limit,
|
|
80
|
+
bindOptions: {
|
|
81
|
+
...options?.name ? { name: options.name } : {},
|
|
82
|
+
...options?.description ? { description: options.description } : {},
|
|
83
|
+
...options?.filter ? { filter: options.filter } : {},
|
|
84
|
+
...options?.transform ? { transform: options.transform } : {}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function createSalesforcePollingBindingFactory(config) {
|
|
89
|
+
return createPollingTriggerBindingFactory({
|
|
90
|
+
defaultName: config.defaultName,
|
|
91
|
+
defaultDescription: config.defaultDescription,
|
|
92
|
+
schedule: withDefaultSchedule(config.schedule),
|
|
93
|
+
credentialSets: [salesforce],
|
|
94
|
+
response: salesforcePollingResponseSchema,
|
|
95
|
+
poll: async (ctx) => {
|
|
96
|
+
const credentials = ctx.credentials.salesforce;
|
|
97
|
+
const client = createPollingClient(credentials);
|
|
98
|
+
const query = buildSalesforcePollingQuery({
|
|
99
|
+
objectName: config.objectName,
|
|
100
|
+
fields: config.defaultFields,
|
|
101
|
+
watermarkField: config.watermarkField,
|
|
102
|
+
lastPolledAt: ctx.lastPolledAt,
|
|
103
|
+
where: config.where,
|
|
104
|
+
extraFilters: config.extraFilters,
|
|
105
|
+
limit: config.limit ?? 100
|
|
106
|
+
});
|
|
107
|
+
const result = normalizeSalesforceQueryResult(await client.query(query));
|
|
108
|
+
return {
|
|
109
|
+
objectName: config.objectName,
|
|
110
|
+
watermarkField: config.watermarkField,
|
|
111
|
+
query,
|
|
112
|
+
records: result.records
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
definitionFilter: (payload) => payload.records.length > 0,
|
|
116
|
+
mapPayload: (payload) => ({
|
|
117
|
+
eventType: config.eventType,
|
|
118
|
+
objectName: payload.objectName,
|
|
119
|
+
records: payload.records,
|
|
120
|
+
...config.taskEventType ? { taskEventType: config.taskEventType } : {}
|
|
121
|
+
}),
|
|
122
|
+
idempotencyKey: (payload, mappedPayload) => buildIdempotencyKey(payload, mappedPayload?.eventType)
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function bindSalesforcePollingTrigger(definition, options) {
|
|
126
|
+
const { schedule, limit, bindOptions } = splitPollingOptions(options);
|
|
127
|
+
return createSalesforcePollingBindingFactory({
|
|
128
|
+
defaultName: definition.defaultName,
|
|
129
|
+
defaultDescription: definition.defaultDescription,
|
|
130
|
+
objectName: definition.objectName,
|
|
131
|
+
defaultFields: definition.defaultFields,
|
|
132
|
+
watermarkField: definition.watermarkField,
|
|
133
|
+
eventType: definition.eventType,
|
|
134
|
+
taskEventType: definition.taskEventType,
|
|
135
|
+
where: definition.where,
|
|
136
|
+
extraFilters: definition.extraFilters,
|
|
137
|
+
schedule,
|
|
138
|
+
limit
|
|
139
|
+
})(bindOptions);
|
|
140
|
+
}
|
|
141
|
+
const accountCreatedOrUpdatedDefinition = {
|
|
142
|
+
defaultName: "Salesforce Account Created Or Updated",
|
|
143
|
+
defaultDescription: "Poll Salesforce accounts created or updated since the last trigger run",
|
|
144
|
+
objectName: "Account",
|
|
145
|
+
defaultFields: [
|
|
146
|
+
"Id",
|
|
147
|
+
"Name",
|
|
148
|
+
"Industry",
|
|
149
|
+
"LastModifiedDate",
|
|
150
|
+
"CreatedDate"
|
|
151
|
+
],
|
|
152
|
+
watermarkField: "LastModifiedDate",
|
|
153
|
+
eventType: "account.created_or_updated"
|
|
154
|
+
};
|
|
155
|
+
const contactUpdatedDefinition = {
|
|
156
|
+
defaultName: "Salesforce Contact Updated",
|
|
157
|
+
defaultDescription: "Poll Salesforce contacts updated since the last trigger run",
|
|
158
|
+
objectName: "Contact",
|
|
159
|
+
defaultFields: [
|
|
160
|
+
"Id",
|
|
161
|
+
"FirstName",
|
|
162
|
+
"LastName",
|
|
163
|
+
"Email",
|
|
164
|
+
"LastModifiedDate"
|
|
165
|
+
],
|
|
166
|
+
watermarkField: "LastModifiedDate",
|
|
167
|
+
eventType: "contact.updated"
|
|
168
|
+
};
|
|
169
|
+
const newContactDefinition = {
|
|
170
|
+
defaultName: "Salesforce New Contact",
|
|
171
|
+
defaultDescription: "Poll new Salesforce contacts since the last trigger run",
|
|
172
|
+
objectName: "Contact",
|
|
173
|
+
defaultFields: [
|
|
174
|
+
"Id",
|
|
175
|
+
"FirstName",
|
|
176
|
+
"LastName",
|
|
177
|
+
"Email",
|
|
178
|
+
"CreatedDate"
|
|
179
|
+
],
|
|
180
|
+
watermarkField: "CreatedDate",
|
|
181
|
+
eventType: "contact.created"
|
|
182
|
+
};
|
|
183
|
+
const newLeadDefinition = {
|
|
184
|
+
defaultName: "Salesforce New Lead",
|
|
185
|
+
defaultDescription: "Poll new Salesforce leads since the last trigger run",
|
|
186
|
+
objectName: "Lead",
|
|
187
|
+
defaultFields: [
|
|
188
|
+
"Id",
|
|
189
|
+
"FirstName",
|
|
190
|
+
"LastName",
|
|
191
|
+
"Company",
|
|
192
|
+
"Status",
|
|
193
|
+
"CreatedDate"
|
|
194
|
+
],
|
|
195
|
+
watermarkField: "CreatedDate",
|
|
196
|
+
eventType: "lead.created"
|
|
197
|
+
};
|
|
198
|
+
const opportunityCreatedOrUpdatedDefinition = {
|
|
199
|
+
defaultName: "Salesforce Opportunity Created Or Updated",
|
|
200
|
+
defaultDescription: "Poll Salesforce opportunities created or updated since the last trigger run",
|
|
201
|
+
objectName: "Opportunity",
|
|
202
|
+
defaultFields: [
|
|
203
|
+
"Id",
|
|
204
|
+
"Name",
|
|
205
|
+
"StageName",
|
|
206
|
+
"Amount",
|
|
207
|
+
"CloseDate",
|
|
208
|
+
"LastModifiedDate"
|
|
209
|
+
],
|
|
210
|
+
watermarkField: "LastModifiedDate",
|
|
211
|
+
eventType: "opportunity.created_or_updated"
|
|
212
|
+
};
|
|
213
|
+
const taskCreatedDefinition = {
|
|
214
|
+
defaultName: "Salesforce Task Created",
|
|
215
|
+
defaultDescription: "Poll Salesforce tasks created since the last trigger run",
|
|
216
|
+
objectName: "Task",
|
|
217
|
+
defaultFields: [
|
|
218
|
+
"Id",
|
|
219
|
+
"Subject",
|
|
220
|
+
"Status",
|
|
221
|
+
"ActivityDate",
|
|
222
|
+
"CreatedDate"
|
|
223
|
+
],
|
|
224
|
+
watermarkField: "CreatedDate",
|
|
225
|
+
eventType: "task.created",
|
|
226
|
+
taskEventType: "task_created"
|
|
227
|
+
};
|
|
228
|
+
const taskCompletedDefinition = {
|
|
229
|
+
defaultName: "Salesforce Task Completed",
|
|
230
|
+
defaultDescription: "Poll Salesforce tasks marked completed since the last trigger run",
|
|
231
|
+
objectName: "Task",
|
|
232
|
+
defaultFields: [
|
|
233
|
+
"Id",
|
|
234
|
+
"Subject",
|
|
235
|
+
"Status",
|
|
236
|
+
"ActivityDate",
|
|
237
|
+
"LastModifiedDate"
|
|
238
|
+
],
|
|
239
|
+
watermarkField: "LastModifiedDate",
|
|
240
|
+
eventType: "task.completed",
|
|
241
|
+
taskEventType: "task_completed",
|
|
242
|
+
where: { Status: "Completed" }
|
|
243
|
+
};
|
|
244
|
+
function accountCreatedOrUpdated(options) {
|
|
245
|
+
return bindSalesforcePollingTrigger(accountCreatedOrUpdatedDefinition, options);
|
|
246
|
+
}
|
|
247
|
+
function contactUpdated(options) {
|
|
248
|
+
return bindSalesforcePollingTrigger(contactUpdatedDefinition, options);
|
|
249
|
+
}
|
|
250
|
+
function newContact(options) {
|
|
251
|
+
return bindSalesforcePollingTrigger(newContactDefinition, options);
|
|
252
|
+
}
|
|
253
|
+
function newLead(options) {
|
|
254
|
+
return bindSalesforcePollingTrigger(newLeadDefinition, options);
|
|
255
|
+
}
|
|
256
|
+
function splitOpportunityPollingOptions(options) {
|
|
257
|
+
return {
|
|
258
|
+
stages: options?.stages,
|
|
259
|
+
schedule: options?.schedule,
|
|
260
|
+
limit: options?.limit,
|
|
261
|
+
bindOptions: {
|
|
262
|
+
...options?.name ? { name: options.name } : {},
|
|
263
|
+
...options?.description ? { description: options.description } : {},
|
|
264
|
+
...options?.filter ? { filter: options.filter } : {},
|
|
265
|
+
...options?.transform ? { transform: options.transform } : {}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function opportunityCreatedOrUpdated(options) {
|
|
270
|
+
const { stages, schedule, limit, bindOptions } = splitOpportunityPollingOptions(options);
|
|
271
|
+
const stageFilter = stages ? buildInClause("StageName", stages) : void 0;
|
|
272
|
+
return createSalesforcePollingBindingFactory({
|
|
273
|
+
defaultName: opportunityCreatedOrUpdatedDefinition.defaultName,
|
|
274
|
+
defaultDescription: opportunityCreatedOrUpdatedDefinition.defaultDescription,
|
|
275
|
+
objectName: opportunityCreatedOrUpdatedDefinition.objectName,
|
|
276
|
+
defaultFields: opportunityCreatedOrUpdatedDefinition.defaultFields,
|
|
277
|
+
watermarkField: opportunityCreatedOrUpdatedDefinition.watermarkField,
|
|
278
|
+
eventType: opportunityCreatedOrUpdatedDefinition.eventType,
|
|
279
|
+
where: stages && stages.length > 0 ? void 0 : opportunityCreatedOrUpdatedDefinition.where,
|
|
280
|
+
extraFilters: stageFilter ? [stageFilter] : void 0,
|
|
281
|
+
schedule,
|
|
282
|
+
limit
|
|
283
|
+
})(bindOptions);
|
|
284
|
+
}
|
|
285
|
+
function taskCreated(options) {
|
|
286
|
+
return bindSalesforcePollingTrigger(taskCreatedDefinition, options);
|
|
287
|
+
}
|
|
288
|
+
function taskCompleted(options) {
|
|
289
|
+
return bindSalesforcePollingTrigger(taskCompletedDefinition, options);
|
|
290
|
+
}
|
|
291
|
+
function sObjectRecordUpdated(config) {
|
|
292
|
+
return bindSalesforcePollingTrigger({
|
|
293
|
+
defaultName: config.name ?? `Salesforce ${config.objectName} Updated`,
|
|
294
|
+
defaultDescription: config.description ?? `Poll ${config.objectName} records updated since the last Salesforce trigger run`,
|
|
295
|
+
objectName: config.objectName,
|
|
296
|
+
defaultFields: config.fields ?? [
|
|
297
|
+
"Id",
|
|
298
|
+
"Name",
|
|
299
|
+
config.watermarkField ?? "LastModifiedDate"
|
|
300
|
+
],
|
|
301
|
+
watermarkField: config.watermarkField ?? "LastModifiedDate",
|
|
302
|
+
eventType: "sobject.updated",
|
|
303
|
+
where: config.where
|
|
304
|
+
}, config);
|
|
305
|
+
}
|
|
306
|
+
const polling = {
|
|
307
|
+
accountCreatedOrUpdated,
|
|
308
|
+
contactUpdated,
|
|
309
|
+
newContact,
|
|
310
|
+
newLead,
|
|
311
|
+
opportunityCreatedOrUpdated,
|
|
312
|
+
taskCreated,
|
|
313
|
+
taskCompleted,
|
|
314
|
+
sObjectRecordUpdated
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
//#endregion
|
|
318
|
+
export { accountCreatedOrUpdated, contactUpdated, newContact, newLead, opportunityCreatedOrUpdated, polling, sObjectRecordUpdated, taskCompleted, taskCreated };
|
package/dist/users.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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/users.d.ts
|
|
6
|
+
declare const getCurrentUserInfo: _keystrokehq_core0.Operation<z.ZodObject<{}, z.core.$strip>, 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
|
+
//#endregion
|
|
14
|
+
export { getCurrentUserInfo };
|
package/dist/users.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createSalesforceClient } from "./client.mjs";
|
|
2
|
+
import { 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/users.ts
|
|
7
|
+
const getCurrentUserInfo = salesforceOperation({
|
|
8
|
+
id: "get_current_user_info",
|
|
9
|
+
name: "Get Salesforce Current User Info",
|
|
10
|
+
description: "Fetch the current Salesforce user identity and profile information for the connected account",
|
|
11
|
+
input: z.object({}),
|
|
12
|
+
output: salesforceGenericObjectSchema,
|
|
13
|
+
run: async (_input, credentials) => {
|
|
14
|
+
const client = createSalesforceClient(credentials);
|
|
15
|
+
return salesforceGenericObjectSchema.parse(await client.request("/services/oauth2/userinfo"));
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { getCurrentUserInfo };
|