( blocks: Record<string, BlockState>, executor: DbOrTx = db )
| 43 | } |
| 44 | |
| 45 | export async function validateTriggerWebhookConfigForDeploy( |
| 46 | blocks: Record<string, BlockState>, |
| 47 | executor: DbOrTx = db |
| 48 | ): Promise<TriggerSaveResult> { |
| 49 | const triggerBlocks = Object.values(blocks || {}).filter((b) => b && b.enabled !== false) |
| 50 | |
| 51 | for (const block of triggerBlocks) { |
| 52 | const triggerId = resolveTriggerId(block) |
| 53 | if (!triggerId || !isTriggerValid(triggerId)) continue |
| 54 | |
| 55 | const triggerDef = getTrigger(triggerId) |
| 56 | const provider = triggerDef.provider |
| 57 | const { providerConfig, missingFields } = buildProviderConfig(block, triggerId, triggerDef) |
| 58 | |
| 59 | if (missingFields.length > 0) { |
| 60 | return { |
| 61 | success: false, |
| 62 | error: { |
| 63 | message: `Missing required fields for ${triggerDef.name || triggerId}: ${missingFields.join(', ')}`, |
| 64 | status: 400, |
| 65 | }, |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if (providerConfig.requireAuth && !providerConfig.token) { |
| 70 | return { |
| 71 | success: false, |
| 72 | error: { |
| 73 | message: |
| 74 | 'Authentication is enabled but no token is configured. Please set an authentication token or disable authentication.', |
| 75 | status: 400, |
| 76 | }, |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if (providerConfig.credentialSetId) { |
| 81 | const oauthProviderId = getProviderIdFromServiceId(provider) |
| 82 | const hasCredential = await credentialSetHasProviderCredential( |
| 83 | providerConfig.credentialSetId as string, |
| 84 | oauthProviderId, |
| 85 | executor |
| 86 | ) |
| 87 | if (!hasCredential) { |
| 88 | return { |
| 89 | success: false, |
| 90 | error: { |
| 91 | message: `No valid credentials found in credential set for ${provider}. Please connect accounts and try again.`, |
| 92 | status: 400, |
| 93 | }, |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return { success: true } |
| 100 | } |
| 101 | |
| 102 | async function credentialSetHasProviderCredential( |
no test coverage detected