MCPcopy Index your code
hub / github.com/simstudioai/sim / createSubscription

Function createSubscription

apps/sim/lib/webhooks/providers/vercel.ts:78–208  ·  view source on GitHub ↗
(ctx: SubscriptionContext)

Source from the content-addressed store, hash-verified

76 },
77
78 async createSubscription(ctx: SubscriptionContext): Promise<SubscriptionResult | undefined> {
79 const { webhook, requestId } = ctx
80 try {
81 const providerConfig = getProviderConfig(webhook)
82 const apiKey = providerConfig.apiKey as string | undefined
83 const triggerId = providerConfig.triggerId as string | undefined
84 const teamId = providerConfig.teamId as string | undefined
85 const filterProjectIds = providerConfig.filterProjectIds as string | undefined
86
87 if (!apiKey) {
88 throw new Error(
89 'Vercel Access Token is required. Please provide your access token in the trigger configuration.'
90 )
91 }
92
93 const { VERCEL_GENERIC_TRIGGER_EVENT_TYPES, VERCEL_TRIGGER_EVENT_TYPES } = await import(
94 '@/triggers/vercel/utils'
95 )
96
97 if (
98 triggerId &&
99 triggerId !== 'vercel_webhook' &&
100 !(triggerId in VERCEL_TRIGGER_EVENT_TYPES)
101 ) {
102 throw new Error(
103 `Unknown Vercel trigger "${triggerId}". Remove and re-add the Vercel trigger, then save again.`
104 )
105 }
106
107 const events =
108 triggerId && triggerId !== 'vercel_webhook'
109 ? [VERCEL_TRIGGER_EVENT_TYPES[triggerId]]
110 : undefined
111 const notificationUrl = getNotificationUrl(webhook)
112
113 logger.info(`[${requestId}] Creating Vercel webhook`, {
114 triggerId,
115 events,
116 hasTeamId: !!teamId,
117 hasProjectIds: !!filterProjectIds,
118 webhookId: webhook.id,
119 })
120
121 /**
122 * Vercel requires an explicit events list — there is no "subscribe to all" option.
123 * For the generic webhook trigger, we subscribe to the most commonly useful events.
124 * Full list: https://vercel.com/docs/webhooks/webhooks-api#event-types
125 */
126 const requestBody: Record<string, unknown> = {
127 url: notificationUrl,
128 events: events || [...VERCEL_GENERIC_TRIGGER_EVENT_TYPES],
129 }
130
131 if (filterProjectIds) {
132 const projectIds = String(filterProjectIds)
133 .split(',')
134 .map((id: string) => id.trim())
135 .filter(Boolean)

Callers

nothing calls this directly

Calls 4

getProviderConfigFunction · 0.90
getNotificationUrlFunction · 0.90
infoMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected