bctx-cloud-core 0.1.4

bctx-cloud-core — cloud client and server for Vault sync, dashboard API, billing
Documentation
pub mod webhook;

use crate::client::upgrade::Tier;

pub struct Quota {
    pub tier: Tier,
    pub tokens_used: u64,
}

impl Quota {
    pub fn is_over_limit(&self) -> bool {
        match self.tier.cloud_token_quota() {
            Some(limit) => self.tokens_used > limit,
            None => false,
        }
    }

    pub fn enforce(&self) -> Result<(), String> {
        if self.is_over_limit() {
            Err(format!(
                "Monthly cloud token quota exceeded for {:?} tier. Upgrade at {}",
                self.tier,
                self.tier.upgrade_url()
            ))
        } else {
            Ok(())
        }
    }
}

pub struct TierPrice {
    pub tier: Tier,
    pub monthly_usd: f64,
}

pub const TIER_PRICES: &[TierPrice] = &[
    TierPrice {
        tier: Tier::Free,
        monthly_usd: 0.0,
    },
    TierPrice {
        tier: Tier::Beacon,
        monthly_usd: 9.0,
    },
    TierPrice {
        tier: Tier::Studio,
        monthly_usd: 29.0,
    },
    TierPrice {
        tier: Tier::Enterprise,
        monthly_usd: 499.0,
    },
];