Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

666 B
Raw Blame
import {
  FREE_PLAN,
  PLANS,
  TRIAL_LIMITS,
  isWorkspaceBillingTrialActive,
} from "@dub/utils";

export const getRatelimitForPlan = (
  plan: string,
  options?: { trialEndsAt?: Date | null },
) => {
  const currentPlanName = plan.toLowerCase().split(" ")[0]; // to account for old Business plans (e.g. "Business Plus")
  const base =
    PLANS.find((p) => p.name.toLowerCase() === currentPlanName) || FREE_PLAN;

  if (isWorkspaceBillingTrialActive(options?.trialEndsAt)) {
    return {
      ...base,
      limits: {
        ...base.limits,
        api: TRIAL_LIMITS.api,
        analyticsApi: TRIAL_LIMITS.analyticsApi,
      },
    };
  }
  return base;
};