({
webhook: webhookRecord,
workflow,
userId,
requestId,
}: SubscriptionContext)
| 17 | |
| 18 | export const webflowHandler: WebhookProviderHandler = { |
| 19 | async createSubscription({ |
| 20 | webhook: webhookRecord, |
| 21 | workflow, |
| 22 | userId, |
| 23 | requestId, |
| 24 | }: SubscriptionContext): Promise<SubscriptionResult | undefined> { |
| 25 | try { |
| 26 | const { path, providerConfig } = webhookRecord as Record<string, unknown> |
| 27 | const config = (providerConfig as Record<string, unknown>) || {} |
| 28 | const { siteId, triggerId, collectionId, formName, credentialId } = config as { |
| 29 | siteId?: string |
| 30 | triggerId?: string |
| 31 | collectionId?: string |
| 32 | formName?: string |
| 33 | credentialId?: string |
| 34 | } |
| 35 | |
| 36 | if (!siteId) { |
| 37 | logger.warn(`[${requestId}] Missing siteId for Webflow webhook creation.`, { |
| 38 | webhookId: webhookRecord.id, |
| 39 | }) |
| 40 | throw new Error('Site ID is required to create Webflow webhook') |
| 41 | } |
| 42 | |
| 43 | const siteIdValidation = validateAlphanumericId(siteId, 'siteId', 100) |
| 44 | if (!siteIdValidation.isValid) { |
| 45 | throw new Error(siteIdValidation.error) |
| 46 | } |
| 47 | |
| 48 | if (!triggerId) { |
| 49 | logger.warn(`[${requestId}] Missing triggerId for Webflow webhook creation.`, { |
| 50 | webhookId: webhookRecord.id, |
| 51 | }) |
| 52 | throw new Error('Trigger type is required to create Webflow webhook') |
| 53 | } |
| 54 | |
| 55 | const credentialOwner = credentialId |
| 56 | ? await getCredentialOwner(credentialId, requestId) |
| 57 | : null |
| 58 | const accessToken = credentialId |
| 59 | ? credentialOwner |
| 60 | ? await refreshAccessTokenIfNeeded( |
| 61 | credentialOwner.accountId, |
| 62 | credentialOwner.userId, |
| 63 | requestId |
| 64 | ) |
| 65 | : null |
| 66 | : await getOAuthToken(userId, 'webflow') |
| 67 | if (!accessToken) { |
| 68 | logger.warn( |
| 69 | `[${requestId}] Could not retrieve Webflow access token for user ${userId}. Cannot create webhook in Webflow.` |
| 70 | ) |
| 71 | throw new Error( |
| 72 | 'Webflow account connection required. Please connect your Webflow account in the trigger configuration and try again.' |
| 73 | ) |
| 74 | } |
| 75 | |
| 76 | const notificationUrl = `${getBaseUrl()}/api/webhooks/trigger/${path}` |
nothing calls this directly
no test coverage detected