(params: {
workflowId: string
blockId: string
provider: string
basePath: string
credentialSetId: string
oauthProviderId: string
providerConfig: Record<string, unknown>
requestId: string
deploymentVersionId?: string
})
| 88 | * a pooled connection is held. |
| 89 | */ |
| 90 | export async function syncWebhooksForCredentialSet(params: { |
| 91 | workflowId: string |
| 92 | blockId: string |
| 93 | provider: string |
| 94 | basePath: string |
| 95 | credentialSetId: string |
| 96 | oauthProviderId: string |
| 97 | providerConfig: Record<string, unknown> |
| 98 | requestId: string |
| 99 | deploymentVersionId?: string |
| 100 | }): Promise<CredentialSetWebhookSyncResult> { |
| 101 | const { |
| 102 | workflowId, |
| 103 | blockId, |
| 104 | provider, |
| 105 | basePath, |
| 106 | credentialSetId, |
| 107 | oauthProviderId, |
| 108 | providerConfig, |
| 109 | requestId, |
| 110 | deploymentVersionId, |
| 111 | } = params |
| 112 | |
| 113 | const syncLogger = createLogger('CredentialSetWebhookSync') |
| 114 | syncLogger.info( |
| 115 | `[${requestId}] Syncing webhooks for credential set ${credentialSetId}, provider ${provider}` |
| 116 | ) |
| 117 | |
| 118 | const useUniquePaths = isPollingWebhookProvider(provider) |
| 119 | |
| 120 | const credentials = await getCredentialsForCredentialSet(credentialSetId, oauthProviderId) |
| 121 | |
| 122 | if (credentials.length === 0) { |
| 123 | syncLogger.warn( |
| 124 | `[${requestId}] No credentials found in credential set ${credentialSetId} for provider ${oauthProviderId}` |
| 125 | ) |
| 126 | return { webhooks: [], created: 0, updated: 0, deleted: 0, failed: [] } |
| 127 | } |
| 128 | |
| 129 | syncLogger.info( |
| 130 | `[${requestId}] Found ${credentials.length} credentials in set ${credentialSetId}` |
| 131 | ) |
| 132 | |
| 133 | const existingWebhooks = await db |
| 134 | .select() |
| 135 | .from(webhook) |
| 136 | .where( |
| 137 | deploymentVersionId |
| 138 | ? and( |
| 139 | eq(webhook.workflowId, workflowId), |
| 140 | eq(webhook.blockId, blockId), |
| 141 | eq(webhook.deploymentVersionId, deploymentVersionId), |
| 142 | isNull(webhook.archivedAt) |
| 143 | ) |
| 144 | : and( |
| 145 | eq(webhook.workflowId, workflowId), |
| 146 | eq(webhook.blockId, blockId), |
| 147 | isNull(webhook.archivedAt) |
no test coverage detected