Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
livemode: event.livemode,
});

const commission = await createPartnerCommission({
await createPartnerCommission({
event: "sale",
programId: link.programId,
partnerId: link.partnerId,
Expand All @@ -362,15 +362,25 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
},
});

if (commission) {
waitUntil(
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(
Expand Down
16 changes: 7 additions & 9 deletions apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,13 @@ export async function invoicePaid(event: Stripe.Event) {
},
});

if (commission) {
waitUntil(
executeWorkflows({
trigger: WorkflowTrigger.saleRecorded,
programId: link.programId,
partnerId: link.partnerId,
}),
);
}
waitUntil(
executeWorkflows({
trigger: WorkflowTrigger.saleRecorded,
programId: link.programId,
partnerId: link.partnerId,
}),
);
}

// send workspace webhook
Expand Down
14 changes: 14 additions & 0 deletions apps/web/lib/actions/partners/create-commission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { isFirstConversion } from "@/lib/analytics/is-first-conversion";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
import { executeWorkflows } from "@/lib/api/workflows/execute-workflows";
import { createPartnerCommission } from "@/lib/partners/create-partner-commission";
import { getLeadEvent } from "@/lib/tinybird";
import { recordClick } from "@/lib/tinybird/record-click";
Expand All @@ -15,6 +16,7 @@ import { leadEventSchemaTB } from "@/lib/zod/schemas/leads";
import { prisma } from "@dub/prisma";
import { nanoid } from "@dub/utils";
import { COUNTRIES_TO_CONTINENTS } from "@dub/utils/src";
import { WorkflowTrigger } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { authActionClient } from "../safe-action";

Expand Down Expand Up @@ -200,6 +202,12 @@ export const createCommissionAction = authActionClient
},
},
}),

executeWorkflows({
trigger: WorkflowTrigger.leadRecorded,
programId,
partnerId,
}),
]);
}

Expand Down Expand Up @@ -238,6 +246,12 @@ export const createCommissionAction = authActionClient
},
},
}),

executeWorkflows({
trigger: WorkflowTrigger.saleRecorded,
programId,
partnerId,
}),
]);
}

Expand Down
10 changes: 10 additions & 0 deletions apps/web/lib/integrations/shopify/create-sale.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isFirstConversion } from "@/lib/analytics/is-first-conversion";
import { includeTags } from "@/lib/api/links/include-tags";
import { executeWorkflows } from "@/lib/api/workflows/execute-workflows";
import { createPartnerCommission } from "@/lib/partners/create-partner-commission";
import { recordSale } from "@/lib/tinybird";
import { LeadEventTB } from "@/lib/types";
Expand All @@ -8,6 +9,7 @@ import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
import { transformSaleEventData } from "@/lib/webhook/transform";
import { prisma } from "@dub/prisma";
import { nanoid } from "@dub/utils";
import { WorkflowTrigger } from "@prisma/client";
Copy link
Contributor

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.

Suggested change
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.

import { waitUntil } from "@vercel/functions";
import { orderSchema } from "./schema";

Expand Down Expand Up @@ -154,5 +156,13 @@ export async function createShopifySale({
},
},
});

waitUntil(
executeWorkflows({
trigger: WorkflowTrigger.saleRecorded,
programId: link.programId,
partnerId: link.partnerId,
}),
);
}
}
6 changes: 5 additions & 1 deletion apps/web/lib/partners/create-partner-commission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
EventType,
WorkflowTrigger,
} from "@dub/prisma/client";
import { log } from "@dub/utils";
import { currencyFormatter, log } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { differenceInMonths } from "date-fns";
import { recordAuditLog } from "../api/audit-logs/record-audit-log";
Expand Down Expand Up @@ -238,6 +238,10 @@ export const createPartnerCommission = async ({
},
});

console.log(
`Created a ${event} commission ${commission.id} (${currencyFormatter(commission.earnings)}) for ${partnerId}: ${JSON.stringify(commission)}`,
);

waitUntil(
(async () => {
const program = await prisma.program.findUniqueOrThrow({
Expand Down