Skip to content

Commit daf7438

Browse files
committed
fix: handlng wbhook returned as string or object
1 parent 1dd4475 commit daf7438

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/server.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,20 @@ class CoCreateLazyLoader {
208208
name = name[3] || name[2] || name[1]
209209

210210
// TODO: webhook secert could be a key pair
211-
const webhookSecret = data.apis[environment].webhooks[name];
211+
let webhookSecret, webhookObject
212+
const webhook = data.apis[environment].webhooks[name];
213+
if (!webhook)
214+
throw new Error(`Webhook ${name} is not defined`);
215+
else if (typeof webhook === 'string')
216+
webhookSecret = webhook
217+
else if (webhook.webhookSecret) {
218+
webhookSecret = webhook.webhookSecret
219+
webhookObject = webhook.webhookObject
220+
// TODO: webhook could conatin $crud to get get webhook data
221+
} else
222+
throw new Error(`Webhook secret ${name} is not defined`);
223+
224+
// const webhookSecret = data.apis[environment].webhooks[name];
212225
if (webhookSecret !== req.headers[name])
213226
throw new Error(`Webhook secret failed for ${name}. Unauthorized access attempt.`);
214227

0 commit comments

Comments
 (0)