@elevasis/sdk 1.15.0 → 1.15.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/dist/cli.cjs +1 -1
- package/dist/index.d.ts +510 -359
- package/dist/index.js +74 -2
- package/dist/test-utils/index.d.ts +497 -358
- package/dist/test-utils/index.js +2 -0
- package/dist/types/worker/adapters/lead.d.ts +1 -1
- package/dist/worker/index.js +1 -0
- package/package.json +2 -2
- package/reference/claude-config/rules/ui.md +2 -6
- package/reference/claude-config/sync-notes/2026-05-02-crm-ownership-next-action.md +58 -0
- package/reference/claude-config/sync-notes/2026-05-02-template-hardcode-workos-config.md +56 -0
- package/reference/scaffold/recipes/customize-crm-actions.md +433 -433
- package/reference/scaffold/recipes/extend-crm.md +12 -8
- package/reference/scaffold/recipes/extend-lead-gen.md +78 -4
- package/reference/scaffold/reference/contracts.md +826 -703
package/dist/index.js
CHANGED
|
@@ -3787,6 +3787,13 @@ var DealCreatedEventSchema = z.object({
|
|
|
3787
3787
|
type: z.literal("deal_created"),
|
|
3788
3788
|
timestamp: z.string().datetime()
|
|
3789
3789
|
});
|
|
3790
|
+
var ActionFailedEventSchema = z.object({
|
|
3791
|
+
type: z.literal("action_failed"),
|
|
3792
|
+
timestamp: z.string().datetime(),
|
|
3793
|
+
actionKey: z.string(),
|
|
3794
|
+
errorMessage: z.string(),
|
|
3795
|
+
payload: z.record(z.string(), z.unknown()).optional()
|
|
3796
|
+
});
|
|
3790
3797
|
var ActivityEventSchema = z.discriminatedUnion("type", [
|
|
3791
3798
|
StageChangeEventSchema,
|
|
3792
3799
|
StateChangeEventSchema,
|
|
@@ -3795,8 +3802,67 @@ var ActivityEventSchema = z.discriminatedUnion("type", [
|
|
|
3795
3802
|
ApprovalResolvedEventSchema,
|
|
3796
3803
|
ApprovalStaleEventSchema,
|
|
3797
3804
|
TaskCreatedEventSchema,
|
|
3798
|
-
DealCreatedEventSchema
|
|
3805
|
+
DealCreatedEventSchema,
|
|
3806
|
+
ActionFailedEventSchema
|
|
3799
3807
|
]);
|
|
3808
|
+
|
|
3809
|
+
// ../core/src/business/acquisition/deal-ownership.ts
|
|
3810
|
+
var INBOUND_EVENT_TYPES = ["reply_received"];
|
|
3811
|
+
var OUTBOUND_EVENT_TYPES = [
|
|
3812
|
+
"reply_sent_to_lead",
|
|
3813
|
+
"booking_nudge_sent",
|
|
3814
|
+
"reminder_sent",
|
|
3815
|
+
"rebook_sent",
|
|
3816
|
+
"followup_email_sent",
|
|
3817
|
+
"reply_followup_sent",
|
|
3818
|
+
"lead_deferred_next_step"
|
|
3819
|
+
];
|
|
3820
|
+
var INBOUND_SET = new Set(INBOUND_EVENT_TYPES);
|
|
3821
|
+
var OUTBOUND_SET = new Set(OUTBOUND_EVENT_TYPES);
|
|
3822
|
+
function getDealOwnership(deal) {
|
|
3823
|
+
if (deal.state_key === "closed_won" || deal.state_key === "closed_lost") {
|
|
3824
|
+
return null;
|
|
3825
|
+
}
|
|
3826
|
+
if (!Array.isArray(deal.activity_log)) return null;
|
|
3827
|
+
let latestInboundMs = null;
|
|
3828
|
+
let latestOutboundMs = null;
|
|
3829
|
+
for (const entry of deal.activity_log) {
|
|
3830
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
3831
|
+
const record = entry;
|
|
3832
|
+
const type = typeof record.type === "string" ? record.type : null;
|
|
3833
|
+
if (!type) continue;
|
|
3834
|
+
const isInbound = INBOUND_SET.has(type);
|
|
3835
|
+
const isOutbound = OUTBOUND_SET.has(type);
|
|
3836
|
+
if (!isInbound && !isOutbound) continue;
|
|
3837
|
+
const occurredAt = resolveTimestamp(record);
|
|
3838
|
+
if (occurredAt === null) continue;
|
|
3839
|
+
if (isInbound && (latestInboundMs === null || occurredAt > latestInboundMs)) {
|
|
3840
|
+
latestInboundMs = occurredAt;
|
|
3841
|
+
}
|
|
3842
|
+
if (isOutbound && (latestOutboundMs === null || occurredAt > latestOutboundMs)) {
|
|
3843
|
+
latestOutboundMs = occurredAt;
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
if (latestInboundMs === null && latestOutboundMs === null) return null;
|
|
3847
|
+
if (latestOutboundMs !== null && (latestInboundMs === null || latestOutboundMs >= latestInboundMs)) {
|
|
3848
|
+
return "them";
|
|
3849
|
+
}
|
|
3850
|
+
return "us";
|
|
3851
|
+
}
|
|
3852
|
+
function resolveTimestamp(record) {
|
|
3853
|
+
return parseMs(record.timestamp) ?? parseMs(record.occurredAt) ?? parseMs(record.createdAt) ?? parseMs(record.updatedAt) ?? parseMs(record.sentAt) ?? null;
|
|
3854
|
+
}
|
|
3855
|
+
function parseMs(value) {
|
|
3856
|
+
if (value instanceof Date) {
|
|
3857
|
+
const ms2 = value.getTime();
|
|
3858
|
+
return Number.isNaN(ms2) ? null : ms2;
|
|
3859
|
+
}
|
|
3860
|
+
if (typeof value !== "string") return null;
|
|
3861
|
+
const ms = new Date(value).getTime();
|
|
3862
|
+
return Number.isNaN(ms) ? null : ms;
|
|
3863
|
+
}
|
|
3864
|
+
|
|
3865
|
+
// ../core/src/business/acquisition/derive-actions.ts
|
|
3800
3866
|
var SendReplyActionPayloadSchema = z.object({
|
|
3801
3867
|
replyBody: z.string().trim().min(1).max(1e4)
|
|
3802
3868
|
}).strict();
|
|
@@ -3834,7 +3900,7 @@ var DEFAULT_CRM_ACTIONS = [
|
|
|
3834
3900
|
{
|
|
3835
3901
|
key: "send_reply",
|
|
3836
3902
|
label: "Send Reply",
|
|
3837
|
-
isAvailableFor: (deal) => deal.stage_key === "interested" && (deal.state_key === CRM_DISCOVERY_REPLIED_STATE.stateKey || deal.state_key === CRM_DISCOVERY_LINK_SENT_STATE.stateKey || deal.state_key === CRM_DISCOVERY_NUDGING_STATE.stateKey),
|
|
3903
|
+
isAvailableFor: (deal) => deal.stage_key === "interested" && isOurReplyAction(deal) && (deal.state_key === CRM_DISCOVERY_REPLIED_STATE.stateKey || deal.state_key === CRM_DISCOVERY_LINK_SENT_STATE.stateKey || deal.state_key === CRM_DISCOVERY_NUDGING_STATE.stateKey),
|
|
3838
3904
|
workflowId: "crm-send-reply-workflow",
|
|
3839
3905
|
payloadSchema: SendReplyActionPayloadSchema
|
|
3840
3906
|
},
|
|
@@ -3869,5 +3935,11 @@ var DEFAULT_CRM_ACTIONS = [
|
|
|
3869
3935
|
function deriveActions(deal, actions = DEFAULT_CRM_ACTIONS) {
|
|
3870
3936
|
return actions.filter((a) => a.isAvailableFor(deal)).map(({ key, label, payloadSchema }) => ({ key, label, payloadSchema }));
|
|
3871
3937
|
}
|
|
3938
|
+
function isOurReplyAction(deal) {
|
|
3939
|
+
if (Object.prototype.hasOwnProperty.call(deal, "nextAction")) {
|
|
3940
|
+
return deal.nextAction === "send_reply";
|
|
3941
|
+
}
|
|
3942
|
+
return (deal.ownership ?? getDealOwnership(deal)) === "us";
|
|
3943
|
+
}
|
|
3872
3944
|
|
|
3873
3945
|
export { ActivityEventSchema, DEFAULT_CRM_ACTIONS, ExecutionError, RegistryValidationError, ResourceRegistry, StepType, ToolingError, deriveActions };
|