Skip to content

Commit

Permalink
cleaned up sdk webhook backend (#2165)
Browse files Browse the repository at this point in the history
  • Loading branch information
gazzdingo committed Feb 26, 2024
1 parent e0f2a2b commit 08202da
Showing 1 changed file with 7 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getAccountPlan,
getEffectiveAccountPlan,
getLicense,
orgHasPremiumFeature,
setLicense,
} from "enterprise";
import { hasReadAccess } from "shared/permissions";
Expand Down Expand Up @@ -1571,35 +1572,17 @@ export async function postWebhookSDK(
) {
req.checkPermissions("manageWebhooks");

// enterprise is unlimited
const limits = {
pro: 99,
starter: 2,
};
const { org } = getContextFromReq(req);
const { name, endpoint, sdkid, sendPayload, headers, httpMethod } = req.body;
const webhookcount = await countWebhooksByOrg(org.id);
if (
IS_CLOUD &&
getAccountPlan(org).includes("pro") &&
webhookcount > limits.pro
) {
return res.status(426).json({
status: 426,
message: "SDK webhook limit has been reached",
});
const canAddMultipleSdkWebhooks = orgHasPremiumFeature(
org,
"multiple-sdk-webhooks"
);
if (!canAddMultipleSdkWebhooks && webhookcount > 0) {
throw new Error("your webhook limit has been reached");
}

if (
IS_CLOUD &&
getAccountPlan(org).includes("starter") &&
webhookcount > limits.starter
) {
return res.status(426).json({
status: 426,
message: "SDK webhook limit has been reached",
});
}
const webhook = await createSdkWebhook({
organization: org.id,
name,
Expand Down

0 comments on commit 08202da

Please sign in to comment.