The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
import * as z from "zod/v4";
import {
HUBSPOT_OBJECT_TYPE_IDS,
LEAD_TRIGGER_EVENT_OPTIONS,
} from "./constants";
// Authentication
export const hubSpotAuthTokenSchema = z.object({
access_token: z.string(),
refresh_token: z.string(),
scopes: z.array(z.string()),
hub_id: z.number(),
expires_in: z.number().describe("Expires in seconds."),
created_at: z.number().optional(),
});
// Integration settings
export const hubSpotSettingsSchema = z.object({
leadTriggerEvent: z
.enum(LEAD_TRIGGER_EVENT_OPTIONS)
.nullish()
.default("dealCreated")
.describe(
"Indicates which event should trigger the final lead tracking for the contact.",
),
leadLifecycleStageId: z
.string()
.trim()
.nullish()
.describe(
"The ID of the contact lifecycle stage that represents a lead. Applicable only if leadTrackingTrigger is 'lifecycleStageReached'.",
),
leadDealStageId: z
.string()
.trim()
.nullish()
.describe(
"The ID of the deal stage that represents a lead. Applicable only if leadTriggerEvent is 'dealStageReached'.",
),
closedWonDealStageId: z
.string()
.trim()
.nullish()
.default("closedwon")
.describe("The ID of the deal stage that represents a closed won deal."),
});
// CRM
export const hubSpotContactSchema = z.object({
id: z.string(),
properties: z.object({
email: z.string(),
firstname: z.string().nullable(),
lastname: z.string().nullable(),
dub_id: z.string().nullish(),
dub_link: z.string().nullish(),
lifecyclestage: z.string().nullish(),
}),
});
export const hubSpotDealSchema = z.object({
id: z.string(),
properties: z.object({
dealname: z.string(),
amount: z.string().nullable(),
dealstage: z.string(),
}),
associations: z
.object({
contacts: z.object({
results: z.array(
z.object({
id: z.string(),
type: z.string(),
}),
),
}),
})
.optional(),
});
// Webhooks
export const hubSpotWebhookSchema = z.object({
portalId: z.number(),
objectTypeId: z.enum(HUBSPOT_OBJECT_TYPE_IDS),
subscriptionType: z.enum(["object.creation", "object.propertyChange"]),
});
export const hubSpotLeadEventSchema = z.object({
objectId: z.number(),
subscriptionType: z.enum(["object.propertyChange", "object.creation"]),
objectTypeId: z.enum(HUBSPOT_OBJECT_TYPE_IDS),
propertyName: z.string().optional(),
propertyValue: z.string().optional(),
});
export const hubSpotSaleEventSchema = z.object({
objectId: z.number(),
subscriptionType: z.literal("object.propertyChange"),
propertyName: z.literal("dealstage"),
propertyValue: z.string(), // eg: closedwon
});