MCPcopy Index your code
hub / github.com/simstudioai/sim / syncWebhooksForCredentialSet

Function syncWebhooksForCredentialSet

apps/sim/lib/webhooks/utils.server.ts:90–306  ·  view source on GitHub ↗
(params: {
  workflowId: string
  blockId: string
  provider: string
  basePath: string
  credentialSetId: string
  oauthProviderId: string
  providerConfig: Record<string, unknown>
  requestId: string
  deploymentVersionId?: string
})

Source from the content-addressed store, hash-verified

88 * a pooled connection is held.
89 */
90export 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)

Callers 3

route.tsFile · 0.90

Calls 15

createLoggerFunction · 0.90
isPollingWebhookProviderFunction · 0.90
generateShortIdFunction · 0.90
getErrorMessageFunction · 0.90
cleanupExternalWebhookFunction · 0.90
infoMethod · 0.80
debugMethod · 0.80
errorMethod · 0.80
warnMethod · 0.65
setMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected