* Resolves an OAuth access token from the webhook's credential configuration. * Follows the Airtable pattern: credentialId → getCredentialOwner → refreshAccessTokenIfNeeded.
( config: Record<string, unknown>, userId: string, requestId: string )
| 26 | * Follows the Airtable pattern: credentialId → getCredentialOwner → refreshAccessTokenIfNeeded. |
| 27 | */ |
| 28 | async function resolveAccessToken( |
| 29 | config: Record<string, unknown>, |
| 30 | userId: string, |
| 31 | requestId: string |
| 32 | ): Promise<string> { |
| 33 | const credentialId = config.credentialId as string | undefined |
| 34 | |
| 35 | if (credentialId) { |
| 36 | const credentialOwner = await getCredentialOwner(credentialId, requestId) |
| 37 | if (credentialOwner) { |
| 38 | const token = await refreshAccessTokenIfNeeded( |
| 39 | credentialOwner.accountId, |
| 40 | credentialOwner.userId, |
| 41 | requestId |
| 42 | ) |
| 43 | if (token) return token |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | const fallbackToken = await getOAuthToken(userId, 'monday') |
| 48 | if (fallbackToken) return fallbackToken |
| 49 | |
| 50 | throw new Error( |
| 51 | 'Monday.com account connection required. Please connect your Monday.com account in the trigger configuration and try again.' |
| 52 | ) |
| 53 | } |
| 54 | |
| 55 | export const mondayHandler: WebhookProviderHandler = { |
| 56 | /** |
no test coverage detected