({
webhook: webhookRecord,
workflow,
userId,
requestId,
}: SubscriptionContext)
| 439 | |
| 440 | export const airtableHandler: WebhookProviderHandler = { |
| 441 | async createSubscription({ |
| 442 | webhook: webhookRecord, |
| 443 | workflow, |
| 444 | userId, |
| 445 | requestId, |
| 446 | }: SubscriptionContext): Promise<SubscriptionResult | undefined> { |
| 447 | try { |
| 448 | const { path, providerConfig } = webhookRecord as Record<string, unknown> |
| 449 | const config = (providerConfig as Record<string, unknown>) || {} |
| 450 | const { baseId, tableId, includeCellValuesInFieldIds, credentialId } = config as { |
| 451 | baseId?: string |
| 452 | tableId?: string |
| 453 | includeCellValuesInFieldIds?: string |
| 454 | credentialId?: string |
| 455 | } |
| 456 | |
| 457 | if (!baseId || !tableId) { |
| 458 | logger.warn(`[${requestId}] Missing baseId or tableId for Airtable webhook creation.`, { |
| 459 | webhookId: webhookRecord.id, |
| 460 | }) |
| 461 | throw new Error( |
| 462 | 'Base ID and Table ID are required to create Airtable webhook. Please provide valid Airtable base and table IDs.' |
| 463 | ) |
| 464 | } |
| 465 | |
| 466 | const baseIdValidation = validateAirtableId(baseId, 'app', 'baseId') |
| 467 | if (!baseIdValidation.isValid) { |
| 468 | throw new Error(baseIdValidation.error) |
| 469 | } |
| 470 | |
| 471 | const tableIdValidation = validateAirtableId(tableId, 'tbl', 'tableId') |
| 472 | if (!tableIdValidation.isValid) { |
| 473 | throw new Error(tableIdValidation.error) |
| 474 | } |
| 475 | |
| 476 | const credentialOwner = credentialId |
| 477 | ? await getCredentialOwner(credentialId, requestId) |
| 478 | : null |
| 479 | const accessToken = credentialId |
| 480 | ? credentialOwner |
| 481 | ? await refreshAccessTokenIfNeeded( |
| 482 | credentialOwner.accountId, |
| 483 | credentialOwner.userId, |
| 484 | requestId |
| 485 | ) |
| 486 | : null |
| 487 | : await getOAuthToken(userId, 'airtable') |
| 488 | if (!accessToken) { |
| 489 | logger.warn( |
| 490 | `[${requestId}] Could not retrieve Airtable access token for user ${userId}. Cannot create webhook in Airtable.` |
| 491 | ) |
| 492 | throw new Error( |
| 493 | 'Airtable account connection required. Please connect your Airtable account in the trigger configuration and try again.' |
| 494 | ) |
| 495 | } |
| 496 | |
| 497 | const notificationUrl = `${getBaseUrl()}/api/webhooks/trigger/${path}` |
| 498 |
nothing calls this directly
no test coverage detected