@@ -4,6 +4,7 @@ import { APL } from "@/APL";
4
4
import { createDebug } from "@/debug" ;
5
5
import { fetchRemoteJwks } from "@/fetch-remote-jwks" ;
6
6
import { getOtelTracer } from "@/open-telemetry" ;
7
+ import { SaleorSchemaVersion } from "@/types" ;
7
8
import { parseSchemaVersion } from "@/util" ;
8
9
import { verifySignatureWithJwks } from "@/verify-signature" ;
9
10
@@ -94,7 +95,7 @@ export class SaleorWebhookValidator {
94
95
95
96
throw new WebhookError (
96
97
`Wrong incoming request event: ${ event } . Expected: ${ expected } ` ,
97
- "WRONG_EVENT"
98
+ "WRONG_EVENT" ,
98
99
) ;
99
100
}
100
101
@@ -121,7 +122,10 @@ export class SaleorWebhookValidator {
121
122
throw new WebhookError ( "Request body can't be parsed" , "CANT_BE_PARSED" ) ;
122
123
}
123
124
124
- let parsedSchemaVersion : number | null = null ;
125
+ /**
126
+ * Can be undefined - subscription must contain "version", otherwise nothing to parse
127
+ */
128
+ let parsedSchemaVersion : SaleorSchemaVersion | null = null ;
125
129
126
130
try {
127
131
parsedSchemaVersion = parseSchemaVersion ( parsedBody . version ) ;
@@ -139,7 +143,7 @@ export class SaleorWebhookValidator {
139
143
140
144
throw new WebhookError (
141
145
`Can't find auth data for ${ saleorApiUrl } . Please register the application` ,
142
- "NOT_REGISTERED"
146
+ "NOT_REGISTERED" ,
143
147
) ;
144
148
}
145
149
@@ -162,15 +166,15 @@ export class SaleorWebhookValidator {
162
166
163
167
throw new WebhookError (
164
168
"Fetching remote JWKS failed" ,
165
- "SIGNATURE_VERIFICATION_FAILED"
169
+ "SIGNATURE_VERIFICATION_FAILED" ,
166
170
) ;
167
171
} ) ;
168
172
169
173
this . debug ( "Fetched refreshed JWKS" ) ;
170
174
171
175
try {
172
176
this . debug (
173
- "Second attempt to validate the signature JWKS, using fresh tokens from the API"
177
+ "Second attempt to validate the signature JWKS, using fresh tokens from the API" ,
174
178
) ;
175
179
176
180
await verifySignatureWithJwks ( newJwks , signature , rawBody ) ;
@@ -183,7 +187,7 @@ export class SaleorWebhookValidator {
183
187
184
188
throw new WebhookError (
185
189
"Request signature check failed" ,
186
- "SIGNATURE_VERIFICATION_FAILED"
190
+ "SIGNATURE_VERIFICATION_FAILED" ,
187
191
) ;
188
192
}
189
193
}
@@ -211,7 +215,7 @@ export class SaleorWebhookValidator {
211
215
} finally {
212
216
span . end ( ) ;
213
217
}
214
- }
218
+ } ,
215
219
) ;
216
220
}
217
221
}
0 commit comments