digital-identity-platform-docs
digital-identity-platform-docs / supabase/functions/sgtm_container_usage
supabase/functions/sgtm_container_usage
Returns current billing period usage statistics for an SGTM container.
⚠️ LEGACY FUNCTION
Status: This function is scheduled for deprecation.
Replacement: Usage data is now sourced from:
- Cloudflare Analytics Engine (raw events)
sgtm_usage_daily_cftable (daily aggregates synced from CF)
Preconditions for Removal:
- Verify all dashboard usage displays use
sgtm_usage_daily_cftable - Remove any frontend calls to this endpoint
- Update billing-usage-check to use CF data exclusively (already done)
Last Known Purpose: Real-time billing period usage statistics. This was superseded when raw event logging moved from Supabase to Cloudflare Analytics Engine for cost optimization.
Cloudflare Architecture Context
| Attribute | Value |
|---|---|
| Classification | 🔴 LEGACY |
| Position | App Backend (will be replaced by direct CF data queries) |
| Receives Public Traffic | No (dashboard only) |
| Latency Sensitive | No |
| Safe to Retry | Yes (read-only) |
Overview
This Edge Function provides real-time usage data for billing and analytics, using aggregated daily usage from the Cloudflare-synced CF tables to show accurate hits used, remaining quota, and over-limit status.
Endpoint
GET /functions/v1/sgtm_container_usage?container_id=<uuid>
Authentication
Service role - uses SUPABASE_SERVICE_ROLE_KEY.
Behavior
- Fetches active subscription and billing plan for container
- Calculates current billing period (calendar month)
- Sums aggregated usage from
sgtm_usage_daily_cf - Returns plan details, period dates, and usage statistics
Tables Touched
sgtm_container_subscriptions(read)billing_plans(read)sgtm_usage_daily_cf(read)
Notes
- Read-only operation, safe to call frequently
- CF Worker updates today's row incrementally via cron
- Used by billing UI and usage dashboards