* Fire-and-forget customer notification when the webhook dedup helper * canceled a duplicate subscription on this org. We always send to the * full set of org admins (typically a single founder/owner). All failures * are logged but never thrown — the dedup itself is the primary action.
(args: {
org: { workos_organization_id: string; name: string | null };
workos: WorkOS;
logger: import('pino').Logger;
scenario: 'canceled_new' | 'canceled_existing';
survivingTierLabel: string | null;
})
| 265 | * are logged but never thrown — the dedup itself is the primary action. |
| 266 | */ |
| 267 | function fireDedupNotice(args: { |
| 268 | org: { workos_organization_id: string; name: string | null }; |
| 269 | workos: WorkOS; |
| 270 | logger: import('pino').Logger; |
| 271 | scenario: 'canceled_new' | 'canceled_existing'; |
| 272 | survivingTierLabel: string | null; |
| 273 | }): void { |
| 274 | const { org, workos: workosClient, logger: log, scenario, survivingTierLabel } = args; |
| 275 | void (async () => { |
| 276 | try { |
| 277 | const { getOrgAdminEmails } = await import('./utils/org-admins.js'); |
| 278 | const adminEmails = await getOrgAdminEmails(workosClient, org.workos_organization_id); |
| 279 | if (adminEmails.length === 0) { |
| 280 | log.warn( |
| 281 | { orgId: org.workos_organization_id, scenario }, |
| 282 | 'No admin emails found for org — skipping duplicate-subscription notice', |
| 283 | ); |
| 284 | return; |
| 285 | } |
| 286 | await Promise.all( |
| 287 | adminEmails.map((to) => |
| 288 | sendDuplicateSubscriptionNotice({ |
| 289 | to, |
| 290 | organizationName: org.name ?? 'your organization', |
| 291 | scenario, |
| 292 | survivingTierLabel, |
| 293 | workosOrganizationId: org.workos_organization_id, |
| 294 | }).catch((err) => |
| 295 | log.error({ err, to, orgId: org.workos_organization_id }, 'Failed to send dedup notice'), |
| 296 | ), |
| 297 | ), |
| 298 | ); |
| 299 | } catch (err) { |
| 300 | log.error( |
| 301 | { err, orgId: org.workos_organization_id, scenario }, |
| 302 | 'Error dispatching duplicate-subscription notice', |
| 303 | ); |
| 304 | } |
| 305 | })(); |
| 306 | } |
| 307 | |
| 308 | function getCachedOrg(orgId: string): { name: string } | null { |
| 309 | const entry = workosOrgCache.get(orgId); |
no test coverage detected