tierrun / tier

The easiest way to add pricing to your SaaS. Get billing over with.
https://tier.run
BSD 3-Clause "New" or "Revised" License
966 stars 32 forks source link

FR: Constant features #183

Open zepatrik opened 1 year ago

zepatrik commented 1 year ago

What are you trying to do?

We have a feature that is not usage based. Our upper rate-limiting depends on the plan, so it is kind of a constant feature value I have to get when applying rate-limits.

How should we solve this?

Allow defining constant features in the pricing.json.

What is the impact of not solving this?

One has to manually manage those features, which kind of defeats the purpose of this project.

Anything else?

No response

isaacs commented 1 year ago

Can you elaborate a little bit on this? (Happy to do a call or something if that's easier for you.)

If I understand you correctly, it sounds like something where you have some set "value" that's determined by the plan. For example, customers on the "pro" plan can make 100 requests per second, but those on the basic plan can make 25 requests per second. But you're not billing them per-request or anything, it's just a setting in a load balancer config or something.

You could express this now in pricing.json by setting a limit and then using that as the source of truth, even though you're not using tier.report() to track charges for the customer. Just look at the limit returned in tier.limit(org, feature) to decide what to set their rate limiting at.

{
  "plans": {
    "plan:pro@0": {
      "features": {
        "feature:ratelimit:requestpersecond": {
          "tiers": [{ "upto": 100 }]
        }
      }
    },
    "plan:basic@0": {
      "features": {
        "feature:ratelimit:requestpersecond": {
          "tiers": [{ "upto": 25 }]
        }
      }
    }
  }
}

Using the sdk:

import { limit } from 'tier'
limit('org:prouser', 'feature:ratelimit:requestpersecond').then(console.log)
/*
{ feature: 'feature:ratelimit:requestpersecond', used: 0, limit: 100 }
 */

I agree it feels like a tiny bit of a hack, though. It might be nice to have a more "blessed" approach.

zepatrik commented 1 year ago

Yes exactly what you described. Thanks for the workaround, but maybe you want to consider a more native approach to this :wink: Feel free to close if applicable.