refactor(crm): dedupe opportunity logic, unify hook API type, fix hardcoded recipients#352
Merged
Merged
Conversation
…dcoded recipients - Remove duplicate probability/expected_revenue field-update workflows from opportunity.object.ts; the lifecycle hook is now the single source of truth - Drop dead in-handler constant redefinitions in opportunity.hook.ts - Extract shared HookApi type (src/objects/_hook-api.ts), replacing 10 hand-rolled per-hook api shapes - Replace hardcoded notification mailboxes with role/relationship merge fields in opportunity + case workflows - Add opportunity-lifecycle e2e regression spec (skips when data API is auth-gated)
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Code-quality optimizations across the CRM hooks and object definitions. No behavior change for end users; the goal is removing duplicate logic, tightening types, and adding regression coverage.
What changed & why
Eliminate Opportunity compute double-write —
probabilityandexpected_revenuewere derived in two places: the lifecycle hook (opportunity.hook.ts) and twofield_updateworkflows inopportunity.object.ts. Two value tables = drift risk. Removed the duplicate workflows; the hook is now the single source of truth. Keptset_forecast_category_by_stage(hook doesn't own it) and the large-deal email alert.Remove dead code —
STAGE_PROBABILITYandNARRATIVE_FIELDSwere redefined inside the handler, shadowing identical module-level constants. Deleted the in-handler copies.Unify the hook data-API type — 10 hooks each hand-rolled their own
ctx.apishape, with inconsistentfiltervswherespellings. Extracted a sharedHookApitype intosrc/objects/_hook-api.tsand pointed every hook at it. (The SDK typesHookContext.apiasunknown, so a local structural type is the established/only option — this just consolidates it.)Drop hardcoded notification mailboxes — replaced
sales_management@example.com,support_manager@example.com,escalation_team@example.comwith relationship merge fields ({owner},{owner.manager},{crm_account.owner}) so alerts scale with the role hierarchy.Add regression test — new
e2e/opportunity-lifecycle.spec.tsexercises the hook's stage→probability→expected_revenue math and theclosed_wonclose_date stamp through the REST API.Notes for reviewers
smoke.spec.tspattern and self-skips when the data API returns 401/403 (the default launch mode gates writes, and the mock auth doesn't issue a usable bearer/cookie). It runs fully in an environment where writes are permitted.Verification
pnpm typecheck✅pnpm build✅ (Build complete, artifact unchanged in shape)npx playwright test --listdiscovers the new spec ✅