Skip to content

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_cf table (daily aggregates synced from CF)

Preconditions for Removal:

  1. Verify all dashboard usage displays use sgtm_usage_daily_cf table
  2. Remove any frontend calls to this endpoint
  3. 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

AttributeValue
Classification🔴 LEGACY
PositionApp Backend (will be replaced by direct CF data queries)
Receives Public TrafficNo (dashboard only)
Latency SensitiveNo
Safe to RetryYes (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

Released under proprietary license.