@@ -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 */
3850async 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
0 commit comments