@@ -23,7 +23,7 @@ export class FirestoreWatcher {
23
23
constructor (
24
24
private readonly collection :
25
25
| CollectionReference < DocumentData >
26
- | CollectionGroup < DocumentData >
26
+ | CollectionGroup < DocumentData > ,
27
27
) { }
28
28
29
29
async start ( ) : Promise < void > {
@@ -42,7 +42,7 @@ export class FirestoreWatcher {
42
42
async ( snapshot ) => {
43
43
if ( this . isProcessing ) {
44
44
console . log (
45
- "Still processing previous snapshot, skipping..."
45
+ "Still processing previous snapshot, skipping..." ,
46
46
) ;
47
47
return ;
48
48
}
@@ -61,14 +61,14 @@ export class FirestoreWatcher {
61
61
( error ) => {
62
62
console . error ( "Error in Firestore listener:" , error ) ;
63
63
this . handleError ( error ) ;
64
- }
64
+ } ,
65
65
) ;
66
66
67
67
console . log ( `Successfully started watcher for ${ collectionPath } ` ) ;
68
68
} catch ( error ) {
69
69
console . error (
70
70
`Failed to start watcher for ${ collectionPath } :` ,
71
- error
71
+ error ,
72
72
) ;
73
73
throw error ;
74
74
}
@@ -93,7 +93,7 @@ export class FirestoreWatcher {
93
93
this . retryCount ++ ;
94
94
console . log ( `Retrying (${ this . retryCount } /${ this . maxRetries } )...` ) ;
95
95
await new Promise ( ( resolve ) =>
96
- setTimeout ( resolve , this . retryDelay * this . retryCount )
96
+ setTimeout ( resolve , this . retryDelay * this . retryCount ) ,
97
97
) ;
98
98
await this . start ( ) ;
99
99
} else {
@@ -109,7 +109,7 @@ export class FirestoreWatcher {
109
109
? this . collection . path
110
110
: "collection group" ;
111
111
console . log (
112
- `Processing ${ changes . length } changes in ${ collectionPath } `
112
+ `Processing ${ changes . length } changes in ${ collectionPath } ` ,
113
113
) ;
114
114
115
115
for ( const change of changes ) {
@@ -122,7 +122,7 @@ export class FirestoreWatcher {
122
122
case "modified" :
123
123
setTimeout ( ( ) => {
124
124
console . log (
125
- `${ collectionPath } - processing - ${ doc . id } `
125
+ `${ collectionPath } - processing - ${ doc . id } ` ,
126
126
) ;
127
127
if ( adapter . lockedIds . includes ( doc . id ) ) return ;
128
128
this . handleCreateOrUpdate ( doc , data ) ;
@@ -136,7 +136,7 @@ export class FirestoreWatcher {
136
136
} catch ( error ) {
137
137
console . error (
138
138
`Error processing ${ change . type } for document ${ doc . id } :` ,
139
- error
139
+ error ,
140
140
) ;
141
141
// Continue processing other changes even if one fails
142
142
}
@@ -145,7 +145,7 @@ export class FirestoreWatcher {
145
145
146
146
private async handleCreateOrUpdate (
147
147
doc : FirebaseFirestore . QueryDocumentSnapshot < DocumentData > ,
148
- data : DocumentData
148
+ data : DocumentData ,
149
149
) : Promise < void > {
150
150
const tableParts = doc . ref . path . split ( "/" ) ;
151
151
// -2 cuz -1 gives last entry and we need second last which would
@@ -166,27 +166,31 @@ export class FirestoreWatcher {
166
166
this . adapter . lockedIds . includes ( doc . id )
167
167
)
168
168
return ;
169
- const response = await axios . post (
170
- new URL (
171
- "/api/webhook" ,
172
- process . env . PUBLIC_PICTIQUE_BASE_URL
173
- ) . toString ( ) ,
174
- envelope ,
175
- {
176
- headers : {
177
- "Content-Type" : "application/json" ,
178
- "X-Webhook-Source" : "blabsy-w3ds-auth-api" ,
169
+ const response = await axios
170
+ . post (
171
+ new URL (
172
+ "/api/webhook" ,
173
+ process . env . PUBLIC_PICTIQUE_BASE_URL ,
174
+ ) . toString ( ) ,
175
+ envelope ,
176
+ {
177
+ headers : {
178
+ "Content-Type" : "application/json" ,
179
+ "X-Webhook-Source" : "blabsy-w3ds-auth-api" ,
180
+ } ,
179
181
} ,
180
- }
181
- ) ;
182
+ )
183
+ . catch ( ( ) => null ) ;
184
+ if ( ! response )
185
+ return console . error ( `failed to sync ${ envelope . id } ` ) ;
182
186
console . log (
183
187
`Successfully forwarded webhook for ${ doc . id } :` ,
184
- response . status
188
+ response . status ,
185
189
) ;
186
190
} catch ( error ) {
187
191
console . error (
188
192
`Failed to forward webhook for ${ doc . id } :` ,
189
- error
193
+ error ,
190
194
) ;
191
195
throw error ; // Re-throw to trigger retry mechanism
192
196
}
0 commit comments