MCPcopy
hub / github.com/simstudioai/sim / deleteSubscription

Function deleteSubscription

apps/sim/lib/webhooks/providers/monday.ts:179–281  ·  view source on GitHub ↗

* Delete a Monday.com webhook subscription via their GraphQL API. * Errors are logged but not thrown (non-fatal cleanup).

(ctx: DeleteSubscriptionContext)

Source from the content-addressed store, hash-verified

177 * Errors are logged but not thrown (non-fatal cleanup).
178 */
179 async deleteSubscription(ctx: DeleteSubscriptionContext): Promise<void> {
180 const config = getProviderConfig(ctx.webhook)
181 const externalId = config.externalId as string | undefined
182
183 if (!externalId) {
184 if (ctx.strict) throw new Error('Missing Monday externalId for webhook deletion')
185 return
186 }
187
188 const externalIdValidation = validateMondayNumericId(externalId, 'webhookId')
189 if (!externalIdValidation.isValid) {
190 logger.warn(
191 `[${ctx.requestId}] Invalid externalId format for Monday webhook deletion: ${externalId}`
192 )
193 if (ctx.strict) throw new Error('Invalid Monday externalId for webhook deletion')
194 return
195 }
196
197 let accessToken: string | null = null
198 try {
199 const credentialId = config.credentialId as string | undefined
200 if (credentialId) {
201 const credentialOwner = await getCredentialOwner(credentialId, ctx.requestId)
202 if (credentialOwner) {
203 accessToken = await refreshAccessTokenIfNeeded(
204 credentialOwner.accountId,
205 credentialOwner.userId,
206 ctx.requestId
207 )
208 }
209 }
210 } catch (error) {
211 logger.warn(
212 `[${ctx.requestId}] Could not resolve credentials for Monday webhook deletion (non-fatal)`,
213 { error: toError(error).message }
214 )
215 if (ctx.strict) throw error
216 }
217
218 if (!accessToken) {
219 logger.warn(
220 `[${ctx.requestId}] No access token available for Monday webhook deletion ${externalId} (non-fatal)`
221 )
222 if (ctx.strict) throw new Error('Missing Monday access token for webhook deletion')
223 return
224 }
225
226 try {
227 const response = await fetch(MONDAY_API_URL, {
228 method: 'POST',
229 headers: {
230 'Content-Type': 'application/json',
231 'API-Version': '2024-10',
232 Authorization: accessToken,
233 },
234 body: JSON.stringify({
235 query: `mutation { delete_webhook(id: ${externalIdValidation.sanitized}) { id board_id } }`,
236 }),

Callers

nothing calls this directly

Calls 9

getProviderConfigFunction · 0.90
validateMondayNumericIdFunction · 0.90
getCredentialOwnerFunction · 0.90
toErrorFunction · 0.90
joinMethod · 0.80
infoMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected