Skip to content

Commit 220aa91

Browse files
waleedlatif1claude
andcommitted
refactor(webhooks): standardize logger names and remove any types from providers
- Standardize logger names to WebhookProvider:X pattern across 6 providers (fathom, gmail, imap, lemlist, outlook, rss) - Replace all `any` types in airtable handler with proper types: - Add AirtableTableChanges interface for API response typing - Change function params from `any` to `Record<string, unknown>` - Change AirtableChange fields from Record<string, any> to Record<string, unknown> - Change all catch blocks from `error: any` to `error: unknown` - Change input object from `any` to `Record<string, unknown>` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7afed0d commit 220aa91

File tree

7 files changed

+47
-35
lines changed

7 files changed

+47
-35
lines changed

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

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,28 @@ interface AirtableChange {
2828
tableId: string
2929
recordId: string
3030
changeType: 'created' | 'updated'
31-
changedFields: Record<string, any> // { fieldId: newValue }
32-
previousFields?: Record<string, any> // { fieldId: previousValue } (optional)
31+
changedFields: Record<string, unknown>
32+
previousFields?: Record<string, unknown>
33+
}
34+
35+
interface AirtableTableChanges {
36+
createdRecordsById?: Record<string, { cellValuesByFieldId?: Record<string, unknown> }>
37+
changedRecordsById?: Record<
38+
string,
39+
{
40+
current?: { cellValuesByFieldId?: Record<string, unknown> }
41+
previous?: { cellValuesByFieldId?: Record<string, unknown> }
42+
}
43+
>
44+
destroyedRecordIds?: string[]
3345
}
3446

3547
/**
3648
* Process Airtable payloads
3749
*/
3850
async function fetchAndProcessAirtablePayloads(
39-
webhookData: any,
40-
workflowData: any,
51+
webhookData: Record<string, unknown>,
52+
workflowData: Record<string, unknown>,
4153
requestId: string // Original request ID from the ping, used for the final execution log
4254
) {
4355
// Logging handles all error logging
@@ -50,8 +62,8 @@ async function fetchAndProcessAirtablePayloads(
5062
// Capture raw payloads from Airtable for exposure to workflows
5163
const allPayloads = []
5264
const localProviderConfig = {
53-
...((webhookData.providerConfig as Record<string, any>) || {}),
54-
}
65+
...((webhookData.providerConfig as Record<string, unknown>) || {}),
66+
} as Record<string, unknown>
5567

5668
try {
5769
const baseId = localProviderConfig.baseId
@@ -64,7 +76,7 @@ async function fetchAndProcessAirtablePayloads(
6476
return
6577
}
6678

67-
const credentialId: string | undefined = localProviderConfig.credentialId
79+
const credentialId = localProviderConfig.credentialId as string | undefined
6880
if (!credentialId) {
6981
logger.error(
7082
`[${requestId}] Missing credentialId in providerConfig for Airtable webhook ${webhookData.id}.`
@@ -117,15 +129,16 @@ async function fetchAndProcessAirtablePayloads(
117129
},
118130
updatedAt: new Date(),
119131
})
120-
.where(eq(webhook.id, webhookData.id))
132+
.where(eq(webhook.id, webhookData.id as string))
121133

122134
localProviderConfig.externalWebhookCursor = null
123135
logger.info(`[${requestId}] Successfully initialized cursor for webhook ${webhookData.id}`)
124-
} catch (initError: any) {
136+
} catch (initError: unknown) {
137+
const err = initError as Error
125138
logger.error(`[${requestId}] Failed to initialize cursor in DB`, {
126139
webhookId: webhookData.id,
127-
error: initError.message,
128-
stack: initError.stack,
140+
error: err.message,
141+
stack: err.stack,
129142
})
130143
}
131144
}
@@ -149,12 +162,13 @@ async function fetchAndProcessAirtablePayloads(
149162
)
150163
throw new Error('Airtable access token not found.')
151164
}
152-
} catch (tokenError: any) {
165+
} catch (tokenError: unknown) {
166+
const err = tokenError as Error
153167
logger.error(
154168
`[${requestId}] Failed to get Airtable OAuth token for credential ${credentialId}`,
155169
{
156-
error: tokenError.message,
157-
stack: tokenError.stack,
170+
error: err.message,
171+
stack: err.stack,
158172
credentialId,
159173
}
160174
)
@@ -222,17 +236,15 @@ async function fetchAndProcessAirtablePayloads(
222236
for (const [tableId, tableChangesUntyped] of Object.entries(
223237
payload.changedTablesById
224238
)) {
225-
const tableChanges = tableChangesUntyped as any // Assert type
239+
const tableChanges = tableChangesUntyped as AirtableTableChanges
226240

227-
// Handle created records
228241
if (tableChanges.createdRecordsById) {
229242
const createdCount = Object.keys(tableChanges.createdRecordsById).length
230243
changeCount += createdCount
231244

232-
for (const [recordId, recordDataUntyped] of Object.entries(
245+
for (const [recordId, recordData] of Object.entries(
233246
tableChanges.createdRecordsById
234247
)) {
235-
const recordData = recordDataUntyped as any // Assert type
236248
const existingChange = consolidatedChangesMap.get(recordId)
237249
if (existingChange) {
238250
// Record was created and possibly updated within the same batch
@@ -258,10 +270,9 @@ async function fetchAndProcessAirtablePayloads(
258270
const updatedCount = Object.keys(tableChanges.changedRecordsById).length
259271
changeCount += updatedCount
260272

261-
for (const [recordId, recordDataUntyped] of Object.entries(
273+
for (const [recordId, recordData] of Object.entries(
262274
tableChanges.changedRecordsById
263275
)) {
264-
const recordData = recordDataUntyped as any // Assert type
265276
const existingChange = consolidatedChangesMap.get(recordId)
266277
const currentFields = recordData.current?.cellValuesByFieldId || {}
267278

@@ -314,14 +325,15 @@ async function fetchAndProcessAirtablePayloads(
314325
providerConfig: updatedConfig, // Use full object
315326
updatedAt: new Date(),
316327
})
317-
.where(eq(webhook.id, webhookData.id))
328+
.where(eq(webhook.id, webhookData.id as string))
318329

319330
localProviderConfig.externalWebhookCursor = currentCursor // Update local copy too
320-
} catch (dbError: any) {
331+
} catch (dbError: unknown) {
332+
const err = dbError as Error
321333
logger.error(`[${requestId}] Failed to persist Airtable cursor to DB`, {
322334
webhookId: webhookData.id,
323335
cursor: currentCursor,
324-
error: dbError.message,
336+
error: err.message,
325337
})
326338
// Error logging handled by logging session
327339
mightHaveMore = false
@@ -337,7 +349,7 @@ async function fetchAndProcessAirtablePayloads(
337349
} else if (nextCursor === currentCursor) {
338350
mightHaveMore = false // Explicitly stop if cursor hasn't changed
339351
}
340-
} catch (fetchError: any) {
352+
} catch (fetchError: unknown) {
341353
logger.error(
342354
`[${requestId}] Network error calling Airtable GET /payloads (Call ${apiCallCount}) for webhook ${webhookData.id}`,
343355
fetchError
@@ -357,8 +369,7 @@ async function fetchAndProcessAirtablePayloads(
357369
try {
358370
// Build input exposing raw payloads and consolidated changes
359371
const latestPayload = allPayloads.length > 0 ? allPayloads[allPayloads.length - 1] : null
360-
const input: any = {
361-
// Raw Airtable payloads as received from the API
372+
const input: Record<string, unknown> = {
362373
payloads: allPayloads,
363374
latestPayload,
364375
// Consolidated, simplified changes for convenience
@@ -393,11 +404,12 @@ async function fetchAndProcessAirtablePayloads(
393404
})
394405

395406
return input
396-
} catch (processingError: any) {
407+
} catch (processingError: unknown) {
408+
const err = processingError as Error
397409
logger.error(`[${requestId}] CRITICAL_TRACE: Error processing Airtable changes`, {
398410
workflowId: workflowData.id,
399-
error: processingError.message,
400-
stack: processingError.stack,
411+
error: err.message,
412+
stack: err.stack,
401413
timestamp: new Date().toISOString(),
402414
})
403415

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
WebhookProviderHandler,
99
} from '@/lib/webhooks/providers/types'
1010

11-
const logger = createLogger('FathomWebhook')
11+
const logger = createLogger('WebhookProvider:Fathom')
1212

1313
export const fathomHandler: WebhookProviderHandler = {
1414
async createSubscription(ctx: SubscriptionContext): Promise<SubscriptionResult | undefined> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
} from '@/lib/webhooks/providers/types'
1111
import { refreshAccessTokenIfNeeded, resolveOAuthAccountId } from '@/app/api/auth/oauth/utils'
1212

13-
const logger = createLogger('GmailWebhookSetup')
13+
const logger = createLogger('WebhookProvider:Gmail')
1414

1515
export const gmailHandler: WebhookProviderHandler = {
1616
async formatInput({ body }: FormatInputContext): Promise<FormatInputResult> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
WebhookProviderHandler,
1010
} from '@/lib/webhooks/providers/types'
1111

12-
const logger = createLogger('ImapWebhookSetup')
12+
const logger = createLogger('WebhookProvider:Imap')
1313

1414
export const imapHandler: WebhookProviderHandler = {
1515
async formatInput({ body }: FormatInputContext): Promise<FormatInputResult> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
WebhookProviderHandler,
99
} from '@/lib/webhooks/providers/types'
1010

11-
const logger = createLogger('LemlistWebhook')
11+
const logger = createLogger('WebhookProvider:Lemlist')
1212

1313
export const lemlistHandler: WebhookProviderHandler = {
1414
async createSubscription(ctx: SubscriptionContext): Promise<SubscriptionResult | undefined> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
} from '@/lib/webhooks/providers/types'
1111
import { refreshAccessTokenIfNeeded, resolveOAuthAccountId } from '@/app/api/auth/oauth/utils'
1212

13-
const logger = createLogger('OutlookWebhookSetup')
13+
const logger = createLogger('WebhookProvider:Outlook')
1414

1515
export const outlookHandler: WebhookProviderHandler = {
1616
async formatInput({ body }: FormatInputContext): Promise<FormatInputResult> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
WebhookProviderHandler,
1010
} from '@/lib/webhooks/providers/types'
1111

12-
const logger = createLogger('RssWebhookSetup')
12+
const logger = createLogger('WebhookProvider:Rss')
1313

1414
export const rssHandler: WebhookProviderHandler = {
1515
async formatInput({ body }: FormatInputContext): Promise<FormatInputResult> {

0 commit comments

Comments
 (0)