Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Refactor campaign workflow conditions to use "partnerJoined" trigger and update related logic for immediate execution. Enhance documentation for workflow execution and adjust Vercel signature verification logic.

Kiran Ka7e935ce9f65
diff --git a/apps/web/app/(ee)/api/campaigns/[campaignId]/route.ts b/apps/web/app/(ee)/api/campaigns/[campaignId]/route.ts
index 3b7623e51f..7fb9549232 100644
--- a/apps/web/app/(ee)/api/campaigns/[campaignId]/route.ts
+++ b/apps/web/app/(ee)/api/campaigns/[campaignId]/route.ts
@@ -134,12 +134,8 @@ export const PATCH = withWorkspace(
const { condition } = parseWorkflowConfig(updatedCampaign.workflow);
- // Skip scheduling if the condition is not based on partnerEnrolledDays,
- // or if the required enrolled days is 0 (immediate execution case)
- if (
- condition.attribute !== "partnerEnrolledDays" ||
- condition.value === 0
- ) {
+ // Skip scheduling if the condition is based on partnerJoined which will run immediately
+ if (condition.attribute === "partnerJoined") {
return;
}
@@ -213,12 +209,7 @@ export const DELETE = withWorkspace(
const { condition } = parseWorkflowConfig(campaign.workflow);
- // Skip scheduling if the condition is not based on partnerEnrolledDays,
- // or if the required enrolled days is 0 (immediate execution case)
- if (
- condition.attribute !== "partnerEnrolledDays" ||
- condition.value === 0
- ) {
+ if (condition.attribute === "partnerJoined") {
return;
}
diff --git a/apps/web/app/(ee)/api/campaigns/route.ts b/apps/web/app/(ee)/api/campaigns/route.ts
index 8eb1d7ab03..4416d5042f 100644
--- a/apps/web/app/(ee)/api/campaigns/route.ts
+++ b/apps/web/app/(ee)/api/campaigns/route.ts
@@ -61,12 +61,12 @@ export const POST = withWorkspace(
});
if (type === "transactional") {
- const trigger = WORKFLOW_ATTRIBUTE_TRIGGER["partnerEnrolledDays"];
+ const trigger = WORKFLOW_ATTRIBUTE_TRIGGER["partnerJoined"];
const triggerCondition: WorkflowCondition = {
- attribute: "partnerEnrolledDays",
+ attribute: "partnerJoined",
operator: "gte",
- value: 1,
+ value: 0,
};
const action: WorkflowAction = {
diff --git a/apps/web/app/(ee)/api/workflows/partner-approved/route.ts b/apps/web/app/(ee)/api/workflows/partner-approved/route.ts
index 52fd586f6b..b158343290 100644
--- a/apps/web/app/(ee)/api/workflows/partner-approved/route.ts
+++ b/apps/web/app/(ee)/api/workflows/partner-approved/route.ts
@@ -40,6 +40,8 @@ type Payload = z.infer<typeof payloadSchema>;
*
* 4. **Trigger Draft Bounty Submission Creation**: Triggers the creation of
* draft bounty submissions for the partner if they are eligible for performance bounties.
+ *
+ * 5. **Execute Dub Workflows**: Executes Dub workflows using the “partnerEnrolled” trigger.
*/
// POST /api/workflows/partner-approved
diff --git a/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts b/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts
index e8d4980f88..000292473e 100644
--- a/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts
+++ b/apps/web/lib/api/workflows/execute-send-campaign-workflow.ts
@@ -48,6 +48,8 @@ export const executeSendCampaignWorkflow = async ({
return;
}
+ console.log(context, buildEnrollmentWhere(condition));
+
let programEnrollments = await prisma.programEnrollment.findMany({
where: {
programId,
@@ -217,13 +219,24 @@ export const executeSendCampaignWorkflow = async ({
};
function buildEnrollmentWhere(condition: WorkflowCondition) {
- const thresholdDate = subDays(new Date(), condition.value);
+ switch (condition.attribute) {
+ case "totalClicks":
+ case "totalLeads":
+ case "totalConversions":
+ case "totalSales":
+ case "totalSaleAmount":
+ case "totalCommissions":
+ return {
+ [condition.attribute]: {
+ gte: condition.value,
+ },
+ };
- switch (condition.operator) {
- case "gte":
+ case "partnerEnrolledDays": // @deprecated
+ case "partnerJoined":
return {
createdAt: {
- lte: thresholdDate,
+ lte: subDays(new Date(), condition.value),
},
};
}
diff --git a/apps/web/lib/api/workflows/execute-workflows.ts b/apps/web/lib/api/workflows/execute-workflows.ts
index c0055215af..38d3c02bf8 100644
--- a/apps/web/lib/api/workflows/execute-workflows.ts
+++ b/apps/web/lib/api/workflows/execute-workflows.ts
@@ -27,6 +27,7 @@ export async function executeWorkflows({
where: {
programId,
trigger,
+ disabledAt: null,
},
});
diff --git a/apps/web/lib/cron/verify-vercel.ts b/apps/web/lib/cron/verify-vercel.ts
index c5bc130aeb..d74d7bd9f5 100644
--- a/apps/web/lib/cron/verify-vercel.ts
+++ b/apps/web/lib/cron/verify-vercel.ts
@@ -2,9 +2,9 @@ import { DubApiError } from "../api/errors";
export const verifyVercelSignature = async (req: Request) => {
// skip verification in local development
- // if (process.env.VERCEL !== "1") {
- // return;
- // }
+ if (process.env.VERCEL !== "1") {
+ return;
+ }
const authHeader = req.headers.get("authorization");