Spec: PF-89 — API Versioning & Edge Function LifecycleDocumentation Index
Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
Use this file to discover all available pages before exploring further.
Last Updated: 2026-03-25
Overview
Edge Functions support application-level API versioning via theX-API-Version header. Callers request a specific version (e.g. v1, v2); the withVersioning middleware routes to the correct handler. If no header is sent, the latest stable version (highest major key) is used.
Versioning is opt-in per function and gated by ENABLE_API_VERSIONING.
Quick Start — Adding Versioning to a Function
1. Define a contract
Createsupabase/functions/_shared/contracts/my-function.contract.ts:
_shared/contracts/index.ts.
2. Wrap with withVersioning
3. (Optional) Add a v2
How It Works
- Caller sends
X-API-Version: v1header. withVersioninglooks uphandlers['v1'].- If found → executes handler; if deprecated → merges
Deprecation/Sunset/Linkheaders. - If not found → returns 400 with migration guidance (PF-07 error envelope).
- If no header → defaults to highest version key.
Feature Flag
SetENABLE_API_VERSIONING=true in Supabase Edge Function secrets. When unset/false, all requests pass through to the default (latest) handler with no version negotiation.
Contract Conventions
- File:
_shared/contracts/{function-name}.contract.ts - Naming:
{FunctionName}V{N}Request,{FunctionName}V{N}Response - Major-only semver surface:
v1,v2— minor/patch changes stay backward-compatible - Re-export all contracts from
_shared/contracts/index.ts
Deprecation Headers
When a version is marked deprecated, responses include:| Header | Example |
|---|---|
Deprecation | @1711929600 (Unix timestamp) |
Sunset | Sat, 01 Sep 2026 00:00:00 GMT |
Link | </functions/v1/my-function>; rel="successor-version" |
Deprecation headers and plan migration before Sunset.
CI Contract Validation
Runnpx tsx scripts/edge-contracts/diff-contracts.ts to detect breaking changes (removed exports) in contract files. This runs automatically on PRs touching *.contract.ts.
- Additions (new exports): non-breaking ✅
- Removals (deleted exports): breaking ❌ — bump major version
Consumer Obligations
- Send
X-API-Versionheader or accept the default (latest stable). - Handle
400responses with migration guidance when a version is unsupported. - Respect
Sunsetdates by migrating before the removal deadline. - Monitor
Deprecationheaders in responses.