({
webhook: webhookRecord,
workflow,
requestId,
strict,
}: DeleteSubscriptionContext)
| 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 { |
nothing calls this directly
no test coverage detected