Add plan model

This commit is contained in:
Jon Staab
2026-03-26 12:35:48 -07:00
parent 05437ef113
commit 1b3fe346f5
7 changed files with 128 additions and 11 deletions
+20
View File
@@ -27,6 +27,19 @@ Notes:
- Adds CORS middleware based on `origins`
- Calls `axum::serve` with a listener
--- Plan routes
## `async fn list_plans(...) -> Response`
- Serves `GET /plans`
- Return `data` is a list of plan structs from `Repo::list_plans`
## `async fn get_plan(...) -> Response`
- Serves `GET /plans/:id`
- Return `data` is a single plan struct matching `id`
- If plan does not exist, return `404` with `code=not-found`
--- Tenant routes
## `async fn list_tenants(...) -> Response`
@@ -100,6 +113,13 @@ Notes:
- If user is a tenant, `tenant` query parameter is not ok; authenticated `pubkey` is used
- Return `data` is a list of invoice structs from `repo.list_invoices`
## `async fn update_tenant_billing(...) -> Response`
- Serves `PUT /tenants/:pubkey/billing`
- Authorizes admin or matching tenant
- Updates tenant billing NWC URL using `repo.update_tenant_nwc_url`
- Return `data` is the submitted billing payload
# Utility functions
## `extract_auth_pubkey(headers: &HeaderMap, method: &Method, uri: &Uri) -> Result<String>`
+17
View File
@@ -27,6 +27,23 @@ Activity is an audit log of all actions performed by a user or a worker process.
- `resource_type` is a string identifying the resource type being modified.
- `resource_id` is a string identifying the resource id being modified.
# Plan
A plan represents a rate charged for relays at a given feature/usage limit. Plans aren't saved to the database, but are simply hardcoded. However, they are exposed through the API so they can be used as a single source of truth.
- `id` - the plan slug
- `name` - the plan name
- `sats` - the plan't cost per month
- `members` - the max number of members a relay can have before needing to upgrade. If empty, membership is not limited.
- `blossom` - whether blossom media hosting is available on this plan
- `livekit` - whether livekit audio/video calls are available on this plan
There are three plans available:
- `free` - 0 sats/mo, up to 10 members, no blossom/livekit
- `basic` - 10k sats/mo, up to 100 members, includes blossom/livekit
- `growth` - 50k sats/mo, unlimited members, includes blossom/livekit
# Tenant
Tenants are customers of the service, identified by a nostr `pubkey`. Public metadata like name etc are pulled from the nostr network. They also have associated billing information.
+10
View File
@@ -48,6 +48,11 @@ Notes:
- Updates tenant `nwc_url`
- Logs activity as `(update_tenant_nwc_url, tenant_id)`
## `pub fn list_plans() -> Vec<Plan>`
- Returns the hardcoded relay plans used by the system (`free`, `basic`, `growth`)
- This is the source of truth for plan metadata exposed via API
## `pub fn list_relays(&self, tenant_id: Option<&str>) -> Result<Vec<Relay>>`
- Returns all matching relays
@@ -120,3 +125,8 @@ Notes:
## `pub fn list_activity(&self, since: &i64, tenant: Option<&str>) -> Result<Vec<Activity>>`
- Returns all activity occuring after `since` matching `tenant`
## `pub fn get_relay_plan_sats(&self, plan: &str) -> Result<i64>`
- Returns the monthly sats amount for a given plan id
- Uses `list_plans()` data for consistent pricing logic across API and billing