apps
What it does
CRUD over public.apps — the app registry that controls routing (route_prefix, renderer), visibility (min_role, required_roles), and install metadata (version, app_type, source, integration_deps). Also exposes schema, availability, and version-bump RPC pass-throughs.
Route and methods
/.netlify/functions/apps, reachable as /api/apps (/api/* → /.netlify/functions/:splat, .framework/public/_redirects). Dispatch is by method plus ?action=/?id/?slug:
| Call | Handler |
|---|---|
GET /api/apps | list (also ?action=list) |
GET /api/apps?id=<uuid> or ?slug=<s> or ?action=get | get |
GET /api/apps?action=schema&slug=<s> | getSchema → RPC get_app_schema |
GET /api/apps?action=available&slug=<s> | checkAvailability → RPC is_app_available |
POST /api/apps | create |
POST /api/apps?action=version | updateVersion → RPC update_app_version |
PATCH /api/apps?id=<uuid> (or id in body) | update |
DELETE /api/apps?id=<uuid> (or id in body) | remove |
Authentication
Standard createHandler auth: x-api-key → machine principal, x-internal-secret → internal principal, Bearer <jwt> → human; anonymous → 401.
listrequires an account context (ctx.accountIdor an explicitaccount_idquery param). A non-system caller asking for anotheraccount_idmust have it inside theirget_accessible_accountsset (own account plus descendants) — otherwiseAccount not accessible(403).createallows non-system-admins only whenresolveFirstSurfacePermissions(principal.id, accountId, 'app', 'create')grantscanCreate.update/removehave no role gate in this file — field-level control comes fromvalidateUpdatePermissions(update only) and RLS onctx.dbfor human callers. Machine principals runctx.dbas the service role.
Request contract
list (query): account_id (defaults to ctx.accountId), include_system (default true; 'false' excludes), include_inactive ('true' to include). Backed by the get_account_apps RPC, which filters by ownership, active state, required_roles/min_role against the caller's role slugs unless the caller is a system admin (.framework/migrations/013_get_account_apps_role_filter.sql).
get (query): id or slug (active rows only).
getSchema / checkAvailability (query): slug.
create (body): slug, name required. Optional with defaults: version '1.0.0', app_type 'custom', source 'custom', owner_account_id → caller's account, config {}, nav_items [], min_role 'member', required_roles [], integration_deps [], metadata {}, route_prefix '/' + slug, renderer 'generic'; is_active: true, is_system: false are forced.
update (id in body or query + body): no field allowlist — every body key except id is written verbatim plus updated_at, after validateUpdatePermissions(ctx, updates, current, 'apps') passes.
remove (id in body or query): sets is_active = false.
updateVersion (body): id, version required.
Response contract
Standard { data, error, meta } envelope.
list→ rows fromget_account_apps, each passed throughsanitizeRecordData. Non-system-admins receive only the routing whitelist (id, slug, name, description, route_prefix, min_role, required_roles, preview_domain, prod_domain, is_active, is_system, renderer, created_at, updated_at); admins get the full row.get→ sanitized row.getSchema→ raw RPC result.checkAvailability→{ available: boolean }.updateVersion→{ success: true }.
Side effects
createinserts intopublic.apps; a duplicateslugis rejected by a pre-check before insert (slug has a globalUNIQUEconstraint in.framework/migrations/001_core_schema.sql).update/removewriteupdated_at; remove is a soft delete.emitLogwritesapp.created,app.updated,app.deleted, andapp.version_updatedaudit rows topublic.logs.
Errors
| Condition | HTTP | Message |
|---|---|---|
| No account context (list, available) | 500 | Account context required |
Foreign account_id on list | 403 | Account not accessible |
| Missing slug/id | 500 | App ID or slug is required / App slug is required / App ID is required |
| Missing create fields | 500 | slug and name are required |
| Non-admin without create grant | 500 | Insufficient permissions to create apps |
| Duplicate slug | 500 | App slug already exists |
| Missing row (update/remove) | 500 | App not found |
| Missing version args | 500 | App ID and version are required |
| Unknown method | 500 | Unsupported method: <METHOD> |
Validation failures surface as HTTP 500 — thrown Errors without a statusCode map to 500 in the shared error path.
Agent notes
- The four RPCs called here —
get_app_schema,is_app_available,update_app_version(plusget_type_schemafor types) — are provided by.framework/migrations/070_app_type_schema_rpcs.sql;get_account_appsexists via.framework/migrations/013_get_account_apps_role_filter.sql. Installs missing migration 070 will seefunction does not existerrors. updatewill write any column present in the body (includingslug,is_system,owner_account_id) — the only guard isvalidateUpdatePermissions, which is config-object (second-surface) logic. Treat it as an admin-trusted endpoint.removedoes not checkis_systemor permissions at all beyond authentication + RLS for human callers.rendererdefaults to'generic'on create — custom-renderer apps must passrenderer: 'custom'explicitly (see Apps and renderers).