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.

remove body from Axiom logRequestDetails

Steven Tey915279536a8e
diff --git a/apps/web/app/api/shopify/integration/webhook/route.ts b/apps/web/app/api/shopify/integration/webhook/route.ts
index 517269a2ce..7d1c5a32f4 100644
--- a/apps/web/app/api/shopify/integration/webhook/route.ts
+++ b/apps/web/app/api/shopify/integration/webhook/route.ts
@@ -1,7 +1,6 @@
import { prisma } from "@dub/prisma";
import { log } from "@dub/utils";
import crypto from "crypto";
-import { withAxiom } from "next-axiom";
import { appUninstalled } from "./app-uninstalled";
import { customersDataRequest } from "./customers-data-request";
import { customersRedact } from "./customers-redact";
@@ -19,95 +18,90 @@ const relevantTopics = new Set([
]);
// POST /api/shopify/integration/webhook – Listen to Shopify webhook events
-export const POST = withAxiom(
- async (req: Request) => {
- const data = await req.text();
- const headers = req.headers;
- const topic = headers.get("x-shopify-topic") || "";
- const signature = headers.get("x-shopify-hmac-sha256") || "";
+export const POST = async (req: Request) => {
+ const data = await req.text();
+ const headers = req.headers;
+ const topic = headers.get("x-shopify-topic") || "";
+ const signature = headers.get("x-shopify-hmac-sha256") || "";
- // Verify signature
- const generatedSignature = crypto
- .createHmac("sha256", `${process.env.SHOPIFY_WEBHOOK_SECRET}`)
- .update(data, "utf8")
- .digest("base64");
+ // Verify signature
+ const generatedSignature = crypto
+ .createHmac("sha256", `${process.env.SHOPIFY_WEBHOOK_SECRET}`)
+ .update(data, "utf8")
+ .digest("base64");
- if (generatedSignature !== signature) {
- return new Response(`[Shopify] Invalid webhook signature. Skipping...`, {
- status: 401,
- });
- }
-
- // Check if topic is relevant
- if (!relevantTopics.has(topic)) {
- return new Response(`[Shopify] Unsupported topic: ${topic}. Skipping...`);
- }
+ if (generatedSignature !== signature) {
+ return new Response(`[Shopify] Invalid webhook signature. Skipping...`, {
+ status: 401,
+ });
+ }
- const event = JSON.parse(data);
- const shopDomain = headers.get("x-shopify-shop-domain") || "";
+ // Check if topic is relevant
+ if (!relevantTopics.has(topic)) {
+ return new Response(`[Shopify] Unsupported topic: ${topic}. Skipping...`);
+ }
- // Find workspace
- const workspace = await prisma.project.findUnique({
- where: {
- shopifyStoreId: shopDomain,
- },
- select: {
- id: true,
- },
- });
+ const event = JSON.parse(data);
+ const shopDomain = headers.get("x-shopify-shop-domain") || "";
- if (!workspace) {
- return new Response(
- `[Shopify] Workspace not found for shop: ${shopDomain}. Skipping...`,
- );
- }
+ // Find workspace
+ const workspace = await prisma.project.findUnique({
+ where: {
+ shopifyStoreId: shopDomain,
+ },
+ select: {
+ id: true,
+ },
+ });
- let response = "OK";
+ if (!workspace) {
+ return new Response(
+ `[Shopify] Workspace not found for shop: ${shopDomain}. Skipping...`,
+ );
+ }
- try {
- switch (topic) {
- case "orders/paid":
- response = await ordersPaid({
- event,
- workspaceId: workspace.id,
- });
- break;
- case "customers/data_request":
- response = await customersDataRequest({
- event,
- workspaceId: workspace.id,
- });
- break;
- case "customers/redact":
- response = await customersRedact({
- event,
- workspaceId: workspace.id,
- });
- break;
- case "shop/redact":
- response = await shopRedact({
- event,
- workspaceId: workspace.id,
- });
- break;
- case "app/uninstalled":
- response = await appUninstalled({
- shopDomain,
- });
- break;
- }
- } catch (error) {
- await log({
- message: `Shopify webhook failed. Error: ${error.message}`,
- type: "errors",
- });
+ let response = "OK";
- return new Response(`[Shopify] Webhook handler failed. View logs`);
+ try {
+ switch (topic) {
+ case "orders/paid":
+ response = await ordersPaid({
+ event,
+ workspaceId: workspace.id,
+ });
+ break;
+ case "customers/data_request":
+ response = await customersDataRequest({
+ event,
+ workspaceId: workspace.id,
+ });
+ break;
+ case "customers/redact":
+ response = await customersRedact({
+ event,
+ workspaceId: workspace.id,
+ });
+ break;
+ case "shop/redact":
+ response = await shopRedact({
+ event,
+ workspaceId: workspace.id,
+ });
+ break;
+ case "app/uninstalled":
+ response = await appUninstalled({
+ shopDomain,
+ });
+ break;
}
+ } catch (error) {
+ await log({
+ message: `Shopify webhook failed. Error: ${error.message}`,
+ type: "errors",
+ });
+
+ return new Response(`[Shopify] Webhook handler failed. View logs`);
+ }
- return new Response(response);
- },
- {
- logRequestDetails: ["body", "nextUrl"],
- },
-);
+ return new Response(response);
+};
diff --git a/apps/web/app/api/stripe/integration/webhook/route.ts b/apps/web/app/api/stripe/integration/webhook/route.ts
index 6c176cf7c8..4ddc713c61 100644
--- a/apps/web/app/api/stripe/integration/webhook/route.ts
+++ b/apps/web/app/api/stripe/integration/webhook/route.ts
@@ -79,6 +79,6 @@ export const POST = withAxiom(
});
},
{
- logRequestDetails: ["body", "nextUrl"],
+ logRequestDetails: ["nextUrl"],
},
);
diff --git a/apps/web/app/api/track/click/route.ts b/apps/web/app/api/track/click/route.ts
index 2f09158d9b..a396f1b081 100644
--- a/apps/web/app/api/track/click/route.ts
+++ b/apps/web/app/api/track/click/route.ts
@@ -81,7 +81,7 @@ export const POST = withAxiom(
}
},
{
- logRequestDetails: ["body", "nextUrl"],
+ logRequestDetails: ["nextUrl"],
},
);
diff --git a/apps/web/app/api/track/visit/route.ts b/apps/web/app/api/track/visit/route.ts
index 4d751d06ef..f39d5e5814 100644
--- a/apps/web/app/api/track/visit/route.ts
+++ b/apps/web/app/api/track/visit/route.ts
@@ -92,7 +92,7 @@ export const POST = withAxiom(
}
},
{
- logRequestDetails: ["body", "nextUrl"],
+ logRequestDetails: ["nextUrl"],
},
);
diff --git a/apps/web/lib/auth/workspace-edge.ts b/apps/web/lib/auth/workspace-edge.ts
index fd30dca43b..f41eb765fe 100644
--- a/apps/web/lib/auth/workspace-edge.ts
+++ b/apps/web/lib/auth/workspace-edge.ts
@@ -412,7 +412,7 @@ export const withWorkspaceEdge = (
}
},
{
- logRequestDetails: ["body", "nextUrl"],
+ logRequestDetails: ["nextUrl"],
},
);
};
diff --git a/apps/web/lib/auth/workspace.ts b/apps/web/lib/auth/workspace.ts
index 3998f201bc..bb37745526 100644
--- a/apps/web/lib/auth/workspace.ts
+++ b/apps/web/lib/auth/workspace.ts
@@ -390,7 +390,7 @@ export const withWorkspace = (
}
},
{
- logRequestDetails: ["body", "nextUrl"],
+ logRequestDetails: ["nextUrl"],
},
);
};