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.

fix the integration settings

Kiran K9c9ff2455410
diff --git a/apps/web/app/(ee)/api/hubspot/webhook/route.ts b/apps/web/app/(ee)/api/hubspot/webhook/route.ts
index 6a4983b4d6..6d2f5bf05e 100644
--- a/apps/web/app/(ee)/api/hubspot/webhook/route.ts
+++ b/apps/web/app/(ee)/api/hubspot/webhook/route.ts
@@ -1,8 +1,5 @@
import { DubApiError, handleAndReturnErrorResponse } from "@/lib/api/errors";
-import {
- DEFAULT_CLOSED_WON_DEAL_STAGE_ID,
- HUBSPOT_CLIENT_SECRET,
-} from "@/lib/integrations/hubspot/constants";
+import { HUBSPOT_CLIENT_SECRET } from "@/lib/integrations/hubspot/constants";
import { refreshAccessToken } from "@/lib/integrations/hubspot/refresh-token";
import {
hubSpotSettingsSchema,
@@ -128,14 +125,13 @@ async function processWebhookEvent(event: any) {
// Track the sale event when deal is closed won
if (subscriptionType === "object.propertyChange") {
- const settings = hubSpotSettingsSchema.parse(installation.settings);
+ const settings = hubSpotSettingsSchema.parse(installation.settings ?? {});
await trackHubSpotSaleEvent({
payload: event,
workspace,
authToken,
- closedWonDealStageId:
- settings?.closedWonDealStageId ?? DEFAULT_CLOSED_WON_DEAL_STAGE_ID,
+ closedWonDealStageId: settings?.closedWonDealStageId,
});
}
}
diff --git a/apps/web/lib/integrations/hubspot/schema.ts b/apps/web/lib/integrations/hubspot/schema.ts
index 2759fb16a1..cd17a8265c 100644
--- a/apps/web/lib/integrations/hubspot/schema.ts
+++ b/apps/web/lib/integrations/hubspot/schema.ts
@@ -12,14 +12,12 @@ export const hubSpotAuthTokenSchema = z.object({
});
// Integration settings
-export const hubSpotSettingsSchema = z
- .object({
- closedWonDealStageId: z
- .string()
- .nullish()
- .describe("The ID of the deal stage that represents a closed won deal."),
- })
- .nullish();
+export const hubSpotSettingsSchema = z.object({
+ closedWonDealStageId: z
+ .string()
+ .nullish()
+ .describe("The ID of the deal stage that represents a closed won deal."),
+});
export const hubSpotRefreshTokenSchema = z.object({
access_token: z.string(),
diff --git a/apps/web/lib/integrations/hubspot/track-sale.ts b/apps/web/lib/integrations/hubspot/track-sale.ts
index 7e01c7fc8a..a659d98a70 100644
--- a/apps/web/lib/integrations/hubspot/track-sale.ts
+++ b/apps/web/lib/integrations/hubspot/track-sale.ts
@@ -1,5 +1,6 @@
import { trackSale } from "@/lib/api/conversions/track-sale";
import { WorkspaceProps } from "@/lib/types";
+import { DEFAULT_CLOSED_WON_DEAL_STAGE_ID } from "./constants";
import { getHubSpotContact } from "./get-contact";
import { getHubSpotDeal } from "./get-deal";
import { hubSpotSaleEventSchema } from "./schema";
@@ -14,8 +15,11 @@ export const trackHubSpotSaleEvent = async ({
payload: Record<string, any>;
workspace: Pick<WorkspaceProps, "id" | "stripeConnectId" | "webhookEnabled">;
authToken: HubSpotAuthToken;
- closedWonDealStageId: string;
+ closedWonDealStageId?: string | null;
}) => {
+ closedWonDealStageId =
+ closedWonDealStageId ?? DEFAULT_CLOSED_WON_DEAL_STAGE_ID;
+
const { objectId, subscriptionType, propertyName, propertyValue } =
hubSpotSaleEventSchema.parse(payload);
@@ -30,7 +34,9 @@ export const trackHubSpotSaleEvent = async ({
}
if (propertyValue !== closedWonDealStageId) {
- console.error(`[HubSpot] Unknown propertyValue ${propertyValue}`);
+ console.error(
+ `[HubSpot] Unknown propertyValue ${propertyValue}. Expected ${closedWonDealStageId}`,
+ );
return;
}