Fix #158 – @trigger.dev/typeform: Check that webhook has a matching url

This commit is contained in:
Matt Aitken
2023-07-14 15:30:56 +01:00
parent bb11001fb7
commit dbb9fe44d8
2 changed files with 29 additions and 16 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/typeform": patch
---
Create a new webhook if the existing webhook url doesn't match
+24 -16
View File
@@ -180,12 +180,35 @@ export function createWebhookEventSource(
};
}
const createWebhook = async () => {
const newWebhookData = await io.integration.createWebhook(
"create-webhook",
{
uid: params.uid,
tag: params.tag,
url: httpSource.url,
enabled: true,
secret: httpSource.secret,
verifySSL: true,
}
);
return {
data: newWebhookData,
registeredEvents: ["all"],
};
};
try {
const existingWebhook = await io.integration.getWebhook(
"get-webhook",
params
);
if (existingWebhook.url !== httpSource.url) {
return createWebhook();
}
if (existingWebhook.enabled) {
return {
data: existingWebhook,
@@ -210,22 +233,7 @@ export function createWebhookEventSource(
registeredEvents: ["all"],
};
} catch (error) {
const newWebhookData = await io.integration.createWebhook(
"create-webhook",
{
uid: params.uid,
tag: params.tag,
url: httpSource.url,
enabled: true,
secret: httpSource.secret,
verifySSL: true,
}
);
return {
data: newWebhookData,
registeredEvents: ["all"],
};
return createWebhook();
}
},
});