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.

update sendViaResend logic

Steven Tey999d0495eb3b
diff --git a/apps/web/scripts/customers/geoship/update-sale-events-amount.ts b/apps/web/scripts/customers/geoship/update-sale-events-amount.ts
new file mode 100644
index 0000000000..540d5f4ff4
--- /dev/null
+++ b/apps/web/scripts/customers/geoship/update-sale-events-amount.ts
@@ -0,0 +1,86 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+import * as z from "zod/v4";
+import { tb } from "../../../lib/tinybird/client";
+import { recordSaleWithTimestamp } from "../../../lib/tinybird/record-sale";
+
+const getSaleEvent = tb.buildPipe({
+ pipe: "get_sale_events",
+ parameters: z.object({
+ linkId: z.string(),
+ }),
+ data: z.any(),
+});
+
+// update tinybird sale event
+async function main() {
+ const linkId = "link_xxx";
+ const columnName = "amount";
+ const columnValue = 20000;
+
+ const link = await prisma.link.findUniqueOrThrow({
+ where: {
+ id: linkId,
+ },
+ });
+
+ const { data } = await getSaleEvent({ linkId });
+ if (data.length === 0) {
+ console.log("No data found");
+ return;
+ }
+ const updatedData = data.map((item) => ({
+ ...item,
+ [columnName]: columnValue,
+ domain: link.domain,
+ key: link.key,
+ workspace_id: link.projectId,
+ }));
+ console.log(updatedData);
+
+ const res = await recordSaleWithTimestamp(updatedData);
+ console.log(res);
+
+ // delete data from tinybird
+ const deleteRes = await Promise.allSettled([
+ deleteData({
+ dataSource: "dub_sale_events",
+ linkId,
+ columnName,
+ oldValue: 50000,
+ }),
+ deleteData({
+ dataSource: "dub_sale_events_mv",
+ linkId,
+ columnName,
+ oldValue: 50000,
+ }),
+ ]);
+ console.log(deleteRes);
+}
+
+const deleteData = async ({
+ dataSource,
+ linkId,
+ columnName,
+ oldValue,
+}: {
+ dataSource: string;
+ linkId: string;
+ columnName: string;
+ oldValue: number;
+}) => {
+ return fetch(
+ `https://api.us-east.tinybird.co/v0/datasources/${dataSource}/delete`,
+ {
+ method: "POST",
+ headers: {
+ Authorization: `Bearer ${process.env.TINYBIRD_API_KEY}`,
+ "Content-Type": "application/x-www-form-urlencoded",
+ },
+ body: `delete_condition=link_id='${linkId}' and ${columnName}='${oldValue}'`,
+ },
+ ).then((res) => res.json());
+};
+
+main();
diff --git a/packages/email/src/send-via-resend.ts b/packages/email/src/send-via-resend.ts
index 9d1f439c64..aaf6a4c838 100644
--- a/packages/email/src/send-via-resend.ts
+++ b/packages/email/src/send-via-resend.ts
@@ -21,15 +21,15 @@ const resendEmailForOptions = (
unsubscribeUrl,
} = opts;
- const isProdEnv = process.env.VERCEL_ENV === "production";
+ const isPreviewEnv = process.env.VERCEL_ENV === "preview";
const gitBranch = process.env.VERCEL_GIT_COMMIT_REF;
// Build base options without rendered outputs (react/text)
// CreateEmailOptions requires at least one of react or text
const baseOptions = {
- to: isProdEnv ? to : "[email protected]",
+ to: isPreviewEnv ? "[email protected]" : to,
from: from || VARIANT_TO_FROM_MAP[variant],
- subject: `${subject}${!isProdEnv && gitBranch ? ` [${gitBranch}]` : ""}`,
+ subject: `${subject}${isPreviewEnv && gitBranch ? ` [${gitBranch}]` : ""}`,
bcc,
// if replyTo is set to "[email protected]", don't set replyTo
// else set it to the value of replyTo or fallback to [email protected]