@@ -82,38 +82,66 @@ async function fetchStravaActivities({
82
82
athleteId : number ;
83
83
shouldDeletePhotos ?: boolean ;
84
84
} ) : Promise < { activities : Activity [ ] ; photos : Photo [ ] } > {
85
- console . log ( 'Starting fetchStravaActivities with params:' , {
86
- hasAccessToken : ! ! accessToken ,
87
- before,
88
- activityIds,
89
- includePhotos,
90
- athleteId,
91
- shouldDeletePhotos,
85
+ console . log ( 'Starting fetchStravaActivities:' , {
86
+ has_access_token : ! ! accessToken ,
87
+ before : before ? new Date ( before * 1000 ) . toISOString ( ) : undefined ,
88
+ activity_ids : activityIds ,
89
+ include_photos : includePhotos ,
90
+ athlete_id : athleteId ,
91
+ should_delete_photos : shouldDeletePhotos ,
92
+ timestamp : new Date ( ) . toISOString ( ) ,
92
93
} ) ;
93
94
94
95
const client = new StravaClient ( accessToken ) ;
95
96
const photos : Photo [ ] = [ ] ;
96
97
97
98
try {
98
- console . log ( 'Fetching activities from Strava...' ) ;
99
99
let stravaActivities : StravaActivity [ ] ;
100
100
101
101
if ( activityIds ) {
102
- // When fetching specific activities, get complete data
103
- console . log ( 'Fetching complete activity data for IDs:' , activityIds ) ;
102
+ console . log ( 'Fetching complete activities by IDs:' , {
103
+ ids : activityIds ,
104
+ count : activityIds . length ,
105
+ } ) ;
104
106
stravaActivities = await Promise . all (
105
- activityIds . map ( ( id ) => client . getActivity ( id ) ) ,
107
+ activityIds . map ( async ( id ) => {
108
+ try {
109
+ const activity = await client . getActivity ( id ) ;
110
+ console . log ( 'Successfully fetched activity:' , {
111
+ id : activity . id ,
112
+ name : activity . name ,
113
+ type : activity . sport_type ,
114
+ has_polyline :
115
+ ! ! activity . map . polyline || ! ! activity . map . summary_polyline ,
116
+ } ) ;
117
+ return activity ;
118
+ } catch ( error ) {
119
+ console . error ( 'Failed to fetch individual activity:' , {
120
+ id,
121
+ error : error instanceof Error ? error . message : error ,
122
+ } ) ;
123
+ throw error ;
124
+ }
125
+ } ) ,
106
126
) ;
107
127
} else {
108
- // When fetching all activities, get summary data
109
- console . log ( 'Fetching summary activity data' ) ;
128
+ console . log ( 'Fetching summary activities' ) ;
110
129
stravaActivities = await client . getActivities ( {
111
130
before,
112
131
per_page : 200 ,
113
132
} ) ;
114
133
}
115
134
116
- console . log ( `Retrieved ${ stravaActivities . length } activities from Strava` ) ;
135
+ console . log ( 'Activity fetch completed:' , {
136
+ total_activities : stravaActivities . length ,
137
+ first_activity : stravaActivities [ 0 ]
138
+ ? {
139
+ id : stravaActivities [ 0 ] . id ,
140
+ name : stravaActivities [ 0 ] . name ,
141
+ type : stravaActivities [ 0 ] . sport_type ,
142
+ }
143
+ : null ,
144
+ } ) ;
117
145
118
146
// Transform activities
119
147
const activities = stravaActivities
@@ -381,30 +409,83 @@ export async function handleWebhookActivity({
381
409
activityId : number ;
382
410
athleteId : number ;
383
411
} ) {
384
- console . log ( 'Handling webhook activity:' , { activityId, athleteId } ) ;
412
+ console . log ( 'Starting webhook activity processing:' , {
413
+ activityId,
414
+ athleteId,
415
+ timestamp : new Date ( ) . toISOString ( ) ,
416
+ } ) ;
385
417
386
418
// Get account directly using Strava athlete ID
387
419
const account = await getAccount ( {
388
420
providerAccountId : athleteId . toString ( ) ,
389
421
} ) ;
390
422
423
+ console . log ( 'Account lookup result:' , {
424
+ found : ! ! account ,
425
+ athlete_id : athleteId ,
426
+ has_access_token : account ?. access_token ? true : false ,
427
+ token_expires_at : account ?. expires_at
428
+ ? new Date ( account . expires_at * 1000 ) . toISOString ( )
429
+ : null ,
430
+ } ) ;
431
+
391
432
// If no account found, this user hasn't connected their Strava account to our app
392
433
if ( ! account ) {
393
434
console . log ( 'No account found for athlete ID:' , athleteId ) ;
394
435
return { activities : [ ] , photos : [ ] } ;
395
436
}
396
437
397
438
if ( ! account . access_token ) {
439
+ console . error ( 'Account found but no access token present:' , {
440
+ athlete_id : athleteId ,
441
+ provider_account_id : account . providerAccountId ,
442
+ } ) ;
398
443
throw new Error ( 'No Strava access token found' ) ;
399
444
}
400
445
401
- return fetchStravaActivities ( {
402
- accessToken : account . access_token ,
403
- activityIds : [ activityId ] ,
404
- includePhotos : true ,
405
- athleteId,
406
- shouldDeletePhotos : true ,
407
- } ) ;
446
+ try {
447
+ const result = await fetchStravaActivities ( {
448
+ accessToken : account . access_token ,
449
+ activityIds : [ activityId ] ,
450
+ includePhotos : true ,
451
+ athleteId,
452
+ shouldDeletePhotos : true ,
453
+ } ) ;
454
+
455
+ console . log ( 'Webhook activity processing completed:' , {
456
+ activityId,
457
+ athleteId,
458
+ activities_processed : result . activities . length ,
459
+ photos_processed : result . photos . length ,
460
+ first_activity : result . activities [ 0 ]
461
+ ? {
462
+ id : result . activities [ 0 ] . id ,
463
+ name : result . activities [ 0 ] . name ,
464
+ is_complete : result . activities [ 0 ] . is_complete ,
465
+ has_polyline :
466
+ ! ! result . activities [ 0 ] . map_polyline ||
467
+ ! ! result . activities [ 0 ] . map_summary_polyline ,
468
+ }
469
+ : null ,
470
+ } ) ;
471
+
472
+ return result ;
473
+ } catch ( error ) {
474
+ console . error ( 'Error in handleWebhookActivity:' , {
475
+ error :
476
+ error instanceof Error
477
+ ? {
478
+ message : error . message ,
479
+ name : error . name ,
480
+ stack : error . stack ,
481
+ }
482
+ : error ,
483
+ activityId,
484
+ athleteId,
485
+ timestamp : new Date ( ) . toISOString ( ) ,
486
+ } ) ;
487
+ throw error ;
488
+ }
408
489
}
409
490
410
491
export async function checkWebhookStatus ( ) {
0 commit comments