API Reference

Most writes happen through Server Actions; these HTTP routes exist for webhooks, downloads, and anything a browser cannot sign safely.

HTTP routes

Stripe webhook

  • POST /api/stripe/webhook -- receives Stripe subscription lifecycle events

Events handled: checkout.session.completed, customer.subscription.updated, customer.subscription.deleted

See Stripe Setup for configuration.

Server Actions

Most mutations are implemented as Server Actions. They live near the pages that use them.

Common pattern

Every server action follows this flow:

export async function myAction(workspaceId: string, formData: FormData) {
  const user = await requireUser();                   // 1. Authenticate
  await requireRole(workspaceId, user.id, ["OWNER"]); // 2. Authorize
  const parsed = schema.safeParse({ ... });           // 3. Validate (Zod)
  await supabase.from("table").insert({ ... });       // 4. Write (workspace-scoped)
  await insertAuditLog({ ... });                      // 5. Audit log
  revalidatePath("/w/...");                           // 6. Revalidate
}

Product actions

Location: src/app/(app)/w/[workspaceSlug]/products/actions.ts

ActionRolesDescription
createProductOWNER, ADMIN, MEMBERCreate a new product (checks plan limits)
updateProductOWNER, ADMIN, MEMBERUpdate name, description, or status
softDeleteProductOWNER, ADMIN, MEMBERMove to trash
permanentDeleteProductOWNER, ADMINPermanently remove
restoreFromTrashOWNER, ADMIN, MEMBERRestore from trash
archiveProductOWNER, ADMIN, MEMBERSet status to ARCHIVED
restoreProductOWNER, ADMIN, MEMBERSet status to ACTIVE
bulkSoftDeleteOWNER, ADMIN, MEMBERBulk move to trash
bulkUpdateStatusOWNER, ADMIN, MEMBERBulk status change

Settings actions

Location: src/app/(app)/w/[workspaceSlug]/settings/settings-actions.ts

ActionRolesDescription
updateWorkspaceNameOWNERRename the workspace
deleteWorkspaceOWNERPermanently delete workspace
transferOwnershipOWNERTransfer OWNER role to an ADMIN
updateProfileAnyUpdate user's full name

Billing actions

Location: src/app/(app)/w/[workspaceSlug]/billing/billing-actions.ts

ActionRolesDescription
createCheckoutSessionOWNERStart Stripe Checkout
createBillingPortalSessionOWNEROpen Stripe Customer Portal

Auth actions

Location: src/app/(auth)/actions/auth.ts

ActionDescription
signInEmail/password sign-in
signUpCreate new account
signOutSign out and clear session
resetPasswordRequest password reset email
updatePasswordSet new password from reset link

Library modules

Reusable business logic lives in src/lib/. Each module exports server actions and helper functions.

ModuleLocationKey functions
Tagssrc/lib/tags/tag-actions.tscreateTag, deleteTag, addTagToRecord, removeTagFromRecord, getWorkspaceTags, getRecordTags
Commentssrc/lib/comments/comment-actions.tsaddComment, editComment, deleteComment, getComments
Attachmentssrc/lib/attachments/attachment-actions.tscreateAttachmentRecord, deleteAttachment, getAttachments
Custom fieldssrc/lib/custom-fields/custom-field-actions.tscreateCustomField, updateCustomField, deleteCustomField, getCustomFieldDefinitions
API keyssrc/lib/api-keys/api-key-actions.tscreateApiKey, revokeApiKey, getApiKeys
Webhookssrc/lib/webhooks/webhook-actions.tscreateWebhook, deleteWebhook, getWebhooks
Bookmarkssrc/lib/bookmarks/toggleBookmark, getUserBookmarks
Saved viewssrc/lib/saved-views/createSavedView, deleteSavedView, getSavedViews
Notificationssrc/lib/notifications/notification-actions.tsgetNotificationPreferences, updateNotificationPreferences
Sessionssrc/lib/sessions/session-actions.tsgetLoginHistory
SSOsrc/lib/sso/sso-actions.tsgetSSOConfig, updateSSOConfig
Scheduled actionssrc/lib/scheduled-actions/scheduled-action-actions.tscreateScheduledAction, getScheduledActions
IP allowlistsrc/lib/ip-allowlist/ip-allowlist-actions.tsaddIPRange, removeIPRange, getIPAllowlist
GDPRsrc/lib/gdpr/Data export and account deletion
Auditsrc/lib/audit/insert-log.tsinsertAuditLog
Billingsrc/lib/billing/check-limit.tscheckLimit
Authsrc/lib/auth/require-user.tsrequireUser
RBACsrc/lib/rbac/require-membership.tsrequireRole

Database tables

The full schema is documented in Data Model. Key tables:

Core tables

  • workspaces -- tenant boundary
  • memberships -- user-to-workspace with role
  • invitations -- invite tokens with expiry
  • products -- example entity with soft delete
  • subscriptions -- Stripe state
  • audit_logs -- append-only event log

Collaboration tables

  • tags, record_tags -- colored labels
  • comments -- threaded comments
  • attachments -- file records

Developer platform tables

  • api_keys -- API key management
  • webhooks, webhook_deliveries -- outgoing webhooks
  • webhook_events -- incoming webhooks
  • custom_field_definitions -- dynamic fields

User feature tables

  • bookmarks -- per-user bookmarks
  • saved_views -- saved table configurations
  • notification_preferences -- notification settings
  • login_history -- sign-in records
  • scheduled_actions -- scheduled tasks
  • workspace_ip_allowlist -- IP restrictions

Database functions

FunctionDescription
daily_audit_counts(workspace_id, days)Daily event counts for the activity chart
is_workspace_member(workspace_id)RLS helper: checks membership
workspace_role(workspace_id)RLS helper: returns user's role
set_updated_at()Trigger function: auto-updates updated_at
handle_new_user()Trigger function: creates profile on sign-up