Last active
January 21, 2026 21:22
-
-
Save willviles/c5a8d60b288a5d3f03d59e796fa6479f to your computer and use it in GitHub Desktop.
Sync Team Support Info
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
| /** | |
| * A single flow, always initiated from the `Account` entity. | |
| */ | |
| async function syncTeamSupportInfo (accountId: string) { | |
| // Get the account | |
| const account = await getAccount(accountId) | |
| // Return early if it doesn't contain an Enterprise team | |
| if (!account?.planHighest === 'Enterprise') return | |
| // Get the active enterprise opportunity | |
| const currentOpportunity = account.opportunities.find(({ plan, stage }) => plan === 'Enterprise' && stage === 'Close Won') | |
| // Get all enterprise teams on the account | |
| const teams = account.teams.filter(({ plan, onborarded }) => plan === 'Enterprise' && onboarded === true) | |
| // If no teams, return early | |
| if (!teams.length) return | |
| // POST for each ENT team | |
| await Promise.allSettled( | |
| teams.map(async (team) => { | |
| await fetch('https://api.vercel.com/v1/support/team-support-info', { | |
| method: 'POST', | |
| body: JSON.stringify({ | |
| "teamId": team.id, | |
| "ae": account.ae ? { | |
| "email": account.ae.email, | |
| "salesforceId": account.ae.salesforceId, | |
| "firstName": account.ae.firstName, | |
| "lastName": account.ae.lastName, | |
| "slackHandle": account.ae.slackHandle | |
| } : null, | |
| "csm": account.csm ? { | |
| "email": account.csm.email, | |
| "salesforceId": account.csm.salesforceId, | |
| "firstName": account.csm.firstName, | |
| "lastName": account.csm.lastName, | |
| "slackHandle": account.csm.slackHandle | |
| } : null, | |
| "se": currentOpportunity?.se ? { | |
| "email": currentOpportunity.se.email, | |
| "salesforceId": currentOpportunity.se.salesforceId, | |
| "firstName": currentOpportunity.se.firstName, | |
| "lastName": currentOpportunity.se.lastName, | |
| "slackHandle": currentOpportunity.se.slackHandle | |
| } : null, | |
| "supportLevel": account.supportLevel, | |
| "contract": { | |
| "value": currentOpportunity?.contractValue ?? null, | |
| "arr": account.arr ?? null | |
| }, | |
| "updatedAt": new Date().toISOString() | |
| }) | |
| }) | |
| }) | |
| ) | |
| } | |
| /* | |
| * Trigger the fn on update of each dependent entity | |
| */ | |
| events.on('accountUpdated', async ({ account }) => await syncTeamSupportInfo(account.id)) | |
| events.on('opportunityUpdated', async ({ opportunity }) => await syncTeamSupportInfo(opportunity.account.id)) | |
| events.on('teamUpdated', async ({ team }) => await syncTeamSupportInfo(team.account.id)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment