-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add executeWorkflows to a few spots that were missed earlier #2810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds workflow triggers for saleRecorded and leadRecorded across Stripe webhooks, Shopify sale handling, and commission creation. Removes prior gating on commission results. Introduces parallel execution via Promise.allSettled and schedules background workflows with waitUntil. Adds detailed logging after partner commission creation. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant SRC as Source Event<br/>(Stripe/Shopify)
participant H as Handler
participant PC as Commission Creation
participant WF as Workflow Engine
Note over SRC,H: Sale or checkout completion received
SRC->>H: HTTP request / event payload
H->>PC: createPartnerCommission(...) (as applicable)
PC-->>H: commission created (async)
rect rgb(240,248,255)
Note over H,WF: Parallel workflow triggers
par Always
H->>WF: executeWorkflows(trigger: saleRecorded,<br/>programId, partnerId)
WF-->>H: enqueued/settled
and New lead only
alt clickEvent exists AND not existingCustomer
H->>WF: executeWorkflows(trigger: leadRecorded,<br/>programId, partnerId)
WF-->>H: enqueued/settled
else No lead workflow
H-->>H: skip leadRecorded
end
end
end
sequenceDiagram
autonumber
participant SH as Shopify
participant HS as create-sale handler
participant WF as Workflow Engine
SH->>HS: Sale processed
alt link has programId & partnerId
HS->>WF: waitUntil(executeWorkflows(saleRecorded,...))
WF-->>HS: scheduled (non-blocking)
else no link
HS-->>HS: skip workflow
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (2)
apps/web/lib/actions/partners/create-commission.ts (1)
19-19: Standardize WorkflowTrigger import pathMatch the rest of the codebase by importing from "@dub/prisma/client".
Apply:
-import { WorkflowTrigger } from "@prisma/client"; +import { WorkflowTrigger } from "@dub/prisma/client";apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts (1)
365-383: Minor: avoid non-Promise entries in Promise.allSettled for clarityPassing a falsy value is fine (it settles immediately), but building the tasks array reads cleaner.
Apply:
- waitUntil( - Promise.allSettled([ - executeWorkflows({ - trigger: WorkflowTrigger.saleRecorded, - programId: link.programId, - partnerId: link.partnerId, - }), - // same logic as lead.created webhook below: - // if the clickEvent variable exists and there was no existing customer before, - // we need to trigger the leadRecorded workflow - clickEvent && - !existingCustomer && - executeWorkflows({ - trigger: WorkflowTrigger.leadRecorded, - programId: link.programId, - partnerId: link.partnerId, - }), - ]), - ); + waitUntil( + (async () => { + const tasks: Promise<unknown>[] = [ + executeWorkflows({ + trigger: WorkflowTrigger.saleRecorded, + programId: link.programId, + partnerId: link.partnerId, + }), + ]; + if (clickEvent && !existingCustomer) { + tasks.push( + executeWorkflows({ + trigger: WorkflowTrigger.leadRecorded, + programId: link.programId, + partnerId: link.partnerId, + }), + ); + } + await Promise.allSettled(tasks); + })(), + );
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (5)
apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts(2 hunks)apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts(1 hunks)apps/web/lib/actions/partners/create-commission.ts(4 hunks)apps/web/lib/integrations/shopify/create-sale.ts(3 hunks)apps/web/lib/partners/create-partner-commission.ts(2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: devkiran
PR: dubinc/dub#2736
File: apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts:12-12
Timestamp: 2025-08-25T17:33:45.072Z
Learning: The WorkflowTrigger enum in packages/prisma/schema/workflow.prisma contains three values: leadRecorded, saleRecorded, and commissionEarned. All three are properly used throughout the codebase.
📚 Learning: 2025-08-25T17:33:45.072Z
Learnt from: devkiran
PR: dubinc/dub#2736
File: apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts:12-12
Timestamp: 2025-08-25T17:33:45.072Z
Learning: The WorkflowTrigger enum in packages/prisma/schema/workflow.prisma contains three values: leadRecorded, saleRecorded, and commissionEarned. All three are properly used throughout the codebase.
Applied to files:
apps/web/lib/partners/create-partner-commission.tsapps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.tsapps/web/lib/integrations/shopify/create-sale.tsapps/web/lib/actions/partners/create-commission.ts
🧬 Code graph analysis (5)
apps/web/lib/partners/create-partner-commission.ts (1)
packages/utils/src/functions/currency-formatter.ts (1)
currencyFormatter(5-16)
apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts (2)
apps/web/lib/partners/create-partner-commission.ts (1)
createPartnerCommission(25-341)apps/web/lib/api/workflows/execute-workflows.ts (1)
executeWorkflows(17-122)
apps/web/lib/integrations/shopify/create-sale.ts (2)
apps/web/lib/api/workflows/execute-workflows.ts (1)
executeWorkflows(17-122)packages/prisma/client.ts (1)
WorkflowTrigger(25-25)
apps/web/lib/actions/partners/create-commission.ts (2)
apps/web/lib/api/workflows/execute-workflows.ts (1)
executeWorkflows(17-122)packages/prisma/client.ts (1)
WorkflowTrigger(25-25)
apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts (1)
apps/web/lib/api/workflows/execute-workflows.ts (1)
executeWorkflows(17-122)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Vade Review
- GitHub Check: build
🔇 Additional comments (5)
apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts (1)
212-218: Good call: always enqueue saleRecorded workflows in the backgroundNon-blocking trigger via waitUntil aligns with the PR goal and avoids coupling to commission creation.
apps/web/lib/integrations/shopify/create-sale.ts (1)
160-166: LGTM: non-blocking saleRecorded workflow triggerScheduling executeWorkflows with waitUntil keeps Shopify sale handling fast while ensuring workflows run.
apps/web/lib/actions/partners/create-commission.ts (2)
206-211: LGTM: trigger leadRecorded in parallel with lead recording/commissionParallelizing with Promise.allSettled is appropriate here.
250-255: LGTM: trigger saleRecorded in parallel with sale recording/commissionConsistent with the rest of the PR and resilient via Promise.allSettled.
apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts (1)
344-363: Decoupling from commission result is correctAwaiting createPartnerCommission without gating subsequent steps matches the intent to always trigger workflows.
| import { transformSaleEventData } from "@/lib/webhook/transform"; | ||
| import { prisma } from "@dub/prisma"; | ||
| import { nanoid } from "@dub/utils"; | ||
| import { WorkflowTrigger } from "@prisma/client"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Standardize WorkflowTrigger import path
Other files import WorkflowTrigger from "@dub/prisma/client". For consistency (and to avoid dual-type/enums across modules), import from the same path here.
Apply:
-import { WorkflowTrigger } from "@prisma/client";
+import { WorkflowTrigger } from "@dub/prisma/client";Run to check inconsistent imports across the repo:
🏁 Script executed:
#!/bin/bash
# Show all WorkflowTrigger import sources with context
rg -nP -C1 'import\s+{?\s*WorkflowTrigger\s*}?\s+from\s+["\'](@dub/prisma/client|@prisma/client)["\']'Length of output: 285
🏁 Script executed:
#!/bin/bash
# List all import statements of WorkflowTrigger and their source modules
rg -nP 'import\s+{[^}]*WorkflowTrigger[^}]*}\s+from\s+["\']([^"\']+)["\']'Length of output: 257
🏁 Script executed:
#!/bin/bash
# List all import statements of WorkflowTrigger in TypeScript files
grep -RIn --include \*.ts "import.*WorkflowTrigger" .Length of output: 1072
Standardize WorkflowTrigger import path
In apps/web/lib/integrations/shopify/create-sale.ts, change the import to match other modules and avoid dual‐type/enums:
-import { WorkflowTrigger } from "@prisma/client";
+import { WorkflowTrigger } from "@dub/prisma/client";📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { WorkflowTrigger } from "@prisma/client"; | |
| import { WorkflowTrigger } from "@dub/prisma/client"; |
🤖 Prompt for AI Agents
In apps/web/lib/integrations/shopify/create-sale.ts around line 12, replace the
direct import from "@prisma/client" with the project's shared export for Prisma
enums/types to match other modules (for example: import { WorkflowTrigger } from
"db"), so you consistently consume the single re-exported WorkflowTrigger and
avoid dual-type/enum mismatches across bundles.
| console.log( | ||
| `Created a ${event} commission ${commission.id} (${currencyFormatter(commission.earnings)}) for ${partnerId}: ${JSON.stringify(commission)}`, | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid logging full commission object (PII risk) and format in the correct currency
console.log(JSON.stringify(commission)) may leak customer PII and sensitive metadata. Also, currencyFormatter defaults to USD, which can misrepresent non-USD commissions. Log a concise, non-PII message and pass the commission currency.
Apply:
- console.log(
- `Created a ${event} commission ${commission.id} (${currencyFormatter(commission.earnings)}) for ${partnerId}: ${JSON.stringify(commission)}`,
- );
+ console.log(
+ `Created ${event} commission ${commission.id} for ${partnerId} — ${currencyFormatter(commission.earnings, { currency: (commission.currency ?? "usd").toUpperCase() })}.`,
+ );📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| console.log( | |
| `Created a ${event} commission ${commission.id} (${currencyFormatter(commission.earnings)}) for ${partnerId}: ${JSON.stringify(commission)}`, | |
| ); | |
| console.log( | |
| `Created ${event} commission ${commission.id} for ${partnerId} — ${currencyFormatter( | |
| commission.earnings, | |
| { currency: (commission.currency ?? "usd").toUpperCase() } | |
| )}.`, | |
| ); |
🤖 Prompt for AI Agents
In apps/web/lib/partners/create-partner-commission.ts around lines 241 to 243,
the current console.log prints the entire commission object (risking PII
exposure) and calls currencyFormatter without the commission currency; replace
this with a concise, non-PII log that only includes safe identifiers
(commission.id, partnerId, event) and the earnings formatted with the
commission's currency (e.g., currencyFormatter(commission.earnings,
commission.currency)), and ensure you do not stringify or print any customer or
sensitive fields from the commission object.
Summary by CodeRabbit
New Features
Refactor
Chores