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

Function deleteSubscription

apps/sim/lib/webhooks/providers/attio.ts:240–304  ·  view source on GitHub ↗
({
    webhook: webhookRecord,
    workflow,
    requestId,
    strict,
  }: DeleteSubscriptionContext)

Source from the content-addressed store, hash-verified

238 },
239
240 async deleteSubscription({
241 webhook: webhookRecord,
242 workflow,
243 requestId,
244 strict,
245 }: DeleteSubscriptionContext): Promise<void> {
246 try {
247 const config = getProviderConfig(webhookRecord)
248 const externalId = config.externalId as string | undefined
249 const credentialId = config.credentialId as string | undefined
250
251 if (!externalId) {
252 logger.warn(
253 `[${requestId}] Missing externalId for Attio webhook deletion ${webhookRecord.id}, skipping cleanup`
254 )
255 if (strict) throw new Error('Missing Attio externalId for webhook deletion')
256 return
257 }
258
259 if (!credentialId) {
260 logger.warn(
261 `[${requestId}] Missing credentialId for Attio webhook deletion ${webhookRecord.id}, skipping cleanup`
262 )
263 if (strict) throw new Error('Missing Attio credentialId for webhook deletion')
264 return
265 }
266
267 const credentialOwner = await getCredentialOwner(credentialId, requestId)
268 const accessToken = credentialOwner
269 ? await refreshAccessTokenIfNeeded(
270 credentialOwner.accountId,
271 credentialOwner.userId,
272 requestId
273 )
274 : null
275
276 if (!accessToken) {
277 const message = `[${requestId}] Could not retrieve Attio access token. Cannot delete webhook.`
278 logger.warn(message, { webhookId: webhookRecord.id })
279 if (strict) throw new Error(message)
280 return
281 }
282
283 const attioResponse = await fetch(`https://api.attio.com/v2/webhooks/${externalId}`, {
284 method: 'DELETE',
285 headers: {
286 Authorization: `Bearer ${accessToken}`,
287 },
288 })
289
290 if (!attioResponse.ok && attioResponse.status !== 404) {
291 const responseBody = await attioResponse.json().catch(() => ({}))
292 logger.warn(
293 `[${requestId}] Failed to delete Attio webhook (non-fatal): ${attioResponse.status}`,
294 { response: responseBody }
295 )
296 if (strict) throw new Error(`Failed to delete Attio webhook: ${attioResponse.status}`)
297 } else {

Callers

nothing calls this directly

Calls 5

getProviderConfigFunction · 0.90
getCredentialOwnerFunction · 0.90
infoMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected