(params: {
workflowId: string
blockId: string
provider: string
triggerPath: string
providerConfig: Record<string, unknown>
requestId: string
deploymentVersionId?: string
})
| 396 | } |
| 397 | |
| 398 | async function syncCredentialSetWebhooks(params: { |
| 399 | workflowId: string |
| 400 | blockId: string |
| 401 | provider: string |
| 402 | triggerPath: string |
| 403 | providerConfig: Record<string, unknown> |
| 404 | requestId: string |
| 405 | deploymentVersionId?: string |
| 406 | }): Promise<CredentialSetSyncResult> { |
| 407 | const { |
| 408 | workflowId, |
| 409 | blockId, |
| 410 | provider, |
| 411 | triggerPath, |
| 412 | providerConfig, |
| 413 | requestId, |
| 414 | deploymentVersionId, |
| 415 | } = params |
| 416 | |
| 417 | const credentialSetId = providerConfig.credentialSetId as string | undefined |
| 418 | if (!credentialSetId) { |
| 419 | return { error: null, warnings: [] } |
| 420 | } |
| 421 | |
| 422 | const oauthProviderId = getProviderIdFromServiceId(provider) |
| 423 | |
| 424 | const { credentialId: _cId, credentialSetId: _csId, userId: _uId, ...baseConfig } = providerConfig |
| 425 | |
| 426 | const syncResult = await syncWebhooksForCredentialSet({ |
| 427 | workflowId, |
| 428 | blockId, |
| 429 | provider, |
| 430 | basePath: triggerPath, |
| 431 | credentialSetId, |
| 432 | oauthProviderId, |
| 433 | providerConfig: baseConfig as Record<string, unknown>, |
| 434 | requestId, |
| 435 | deploymentVersionId, |
| 436 | }) |
| 437 | |
| 438 | const warnings: string[] = [] |
| 439 | |
| 440 | if (syncResult.failed.length > 0) { |
| 441 | const failedCount = syncResult.failed.length |
| 442 | const totalCount = syncResult.webhooks.length + failedCount |
| 443 | warnings.push( |
| 444 | `${failedCount} of ${totalCount} credentials in the set failed to sync for ${provider}. Some team members may not receive triggers.` |
| 445 | ) |
| 446 | } |
| 447 | |
| 448 | if (syncResult.webhooks.length === 0) { |
| 449 | return { |
| 450 | error: { |
| 451 | message: `No valid credentials found in credential set for ${provider}. Please connect accounts and try again.`, |
| 452 | status: 400, |
| 453 | }, |
| 454 | warnings, |
| 455 | } |
no test coverage detected