Skip to content

Commit 1713cbf

Browse files
committed
fix(webhooks): address PR review feedback
- Restore original fall-through behavior for generic requireAuth with no token - Replace `any` params with proper types in processor helper functions - Restore array-aware initializer in processTriggerFileOutputs
1 parent 6e95981 commit 1713cbf

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

apps/sim/background/webhook-execution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async function processTriggerFileOutputs(
6868
return input
6969
}
7070

71-
const processed: Record<string, unknown> = {}
71+
const processed: Record<string, unknown> | unknown[] = Array.isArray(input) ? [] : {}
7272

7373
for (const [key, value] of Object.entries(input)) {
7474
const currentPath = path ? `${path}.${key}` : key

apps/sim/lib/webhooks/processor.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ export async function handlePreLookupWebhookVerification(
182182
* Delegates to the provider handler registry.
183183
*/
184184
export function handleProviderReachabilityTest(
185-
webhookRecord: any,
186-
body: any,
185+
webhookRecord: { provider: string },
186+
body: unknown,
187187
requestId: string
188188
): NextResponse | null {
189189
const handler = getProviderHandler(webhookRecord?.provider)
@@ -195,7 +195,7 @@ export function handleProviderReachabilityTest(
195195
* Delegates to the provider handler registry.
196196
*/
197197
export function formatProviderErrorResponse(
198-
webhookRecord: any,
198+
webhookRecord: { provider: string },
199199
error: string,
200200
status: number
201201
): NextResponse {
@@ -207,9 +207,13 @@ export function formatProviderErrorResponse(
207207
* Check if a webhook event should be skipped based on provider-specific filtering.
208208
* Delegates to the provider handler registry.
209209
*/
210-
export function shouldSkipWebhookEvent(webhookRecord: any, body: any, requestId: string): boolean {
210+
export function shouldSkipWebhookEvent(
211+
webhookRecord: { provider: string; providerConfig?: Record<string, unknown> },
212+
body: unknown,
213+
requestId: string
214+
): boolean {
211215
const handler = getProviderHandler(webhookRecord.provider)
212-
const providerConfig = (webhookRecord.providerConfig as Record<string, unknown>) || {}
216+
const providerConfig = webhookRecord.providerConfig ?? {}
213217
return (
214218
handler.shouldSkipEvent?.({ webhook: webhookRecord, body, requestId, providerConfig }) ?? false
215219
)

apps/sim/lib/webhooks/providers/generic.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@ export const genericHandler: WebhookProviderHandler = {
1414
verifyAuth({ request, requestId, providerConfig }: AuthContext) {
1515
if (providerConfig.requireAuth) {
1616
const configToken = providerConfig.token as string | undefined
17-
if (!configToken) {
18-
return new NextResponse('Unauthorized - Authentication required but not configured', {
19-
status: 401,
20-
})
21-
}
22-
23-
const secretHeaderName = providerConfig.secretHeaderName as string | undefined
24-
if (!verifyTokenAuth(request, configToken, secretHeaderName)) {
25-
return new NextResponse('Unauthorized - Invalid authentication token', { status: 401 })
17+
if (configToken) {
18+
const secretHeaderName = providerConfig.secretHeaderName as string | undefined
19+
if (!verifyTokenAuth(request, configToken, secretHeaderName)) {
20+
return new NextResponse('Unauthorized - Invalid authentication token', { status: 401 })
21+
}
2622
}
2723
}
2824

0 commit comments

Comments
 (0)