The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
address the PR comments
Kiran K4326cd9fd078
diff --git a/apps/web/app/(ee)/api/hubspot/callback/route.ts b/apps/web/app/(ee)/api/hubspot/callback/route.tsindex 20c89bb8b3..2a835bef4e 100644--- a/apps/web/app/(ee)/api/hubspot/callback/route.ts+++ b/apps/web/app/(ee)/api/hubspot/callback/route.ts@@ -6,6 +6,7 @@ import {HUBSPOT_REDIRECT_URI,HUBSPOT_STATE_CACHE_PREFIX,} from "@/lib/integrations/hubspot/constants";+import { hubSpotAuthTokenSchema } from "@/lib/integrations/hubspot/schema";import { installIntegration } from "@/lib/integrations/install";import { redis } from "@/lib/upstash";import z from "@/lib/zod";@@ -48,10 +49,10 @@ export const GET = async (req: Request) => {const { code, state } = oAuthCallbackSchema.parse(getSearchParams(req.url));+ const stateKey = `${HUBSPOT_STATE_CACHE_PREFIX}:${state}`;+// Find workspace that initiated the install- const workspaceId = await redis.get<string>(- `${HUBSPOT_STATE_CACHE_PREFIX}:${state}`,- );+ const workspaceId = await redis.get<string>(stateKey);if (!workspaceId) {throw new DubApiError({@@ -107,16 +108,21 @@ export const GET = async (req: Request) => {},});+ const credentials = hubSpotAuthTokenSchema.parse({+ ...result,+ created_at: Date.now(),+ });+// Install the integrationawait installIntegration({integrationId: integration.id,userId: session.user.id,workspaceId,- credentials: {- ...result,- created_at: Date.now(),- },+ credentials,});++ // Delete the state key from Redis+ await redis.del(stateKey);} catch (e: any) {return handleAndReturnErrorResponse(e);}diff --git a/apps/web/lib/integrations/hubspot/constants.ts b/apps/web/lib/integrations/hubspot/constants.tsindex 8c37175c07..68b64fea1c 100644--- a/apps/web/lib/integrations/hubspot/constants.ts+++ b/apps/web/lib/integrations/hubspot/constants.ts@@ -12,9 +12,7 @@ export const HUBSPOT_API_HOST = "https://api.hubapi.com";export const HUBSPOT_APP_SCOPES = ["oauth",- "crm.objects.contacts.read","crm.objects.contacts.write",- "crm.objects.leads.read","crm.objects.deals.read",];diff --git a/apps/web/lib/integrations/hubspot/schema.ts b/apps/web/lib/integrations/hubspot/schema.tsindex 922fa39e87..8e5454af70 100644--- a/apps/web/lib/integrations/hubspot/schema.ts+++ b/apps/web/lib/integrations/hubspot/schema.ts@@ -27,7 +27,6 @@ export const hubSpotContactSchema = z.object({firstname: z.string().nullable(),lastname: z.string().nullable(),dub_id: z.string().nullable(),- createdate: z.string(),}),});diff --git a/apps/web/lib/integrations/hubspot/track-sale.ts b/apps/web/lib/integrations/hubspot/track-sale.tsindex 9db9c8c8d8..7315895c33 100644--- a/apps/web/lib/integrations/hubspot/track-sale.ts+++ b/apps/web/lib/integrations/hubspot/track-sale.ts@@ -49,9 +49,10 @@ export const trackHubSpotSaleEvent = async ({}// Find the contact associated with the deal- const contact = associations.contacts.results[0];+ const contact = associations?.contacts?.results?.[0];if (!contact) {+ console.error(`[HubSpot] No contact associated with deal ${dealId}`);return;}diff --git a/packages/hubspot-app/README.md b/packages/hubspot-app/README.mdindex 0833c27e5a..4528741597 100644--- a/packages/hubspot-app/README.md+++ b/packages/hubspot-app/README.md@@ -8,12 +8,6 @@ This package contains the HubSpot app integration for Dub.# Install dependenciespnpm install-# Build the package-pnpm build--# Run in development mode-pnpm dev-# Upload the project to HubSpot accountpnpm hs project upload