Skip to content
AdiosDocumentation
Browse documentation

CRM and API reference

Use this reference when changing CRM behavior, permissions, or API calls. The JavaScript implementation lives in runtime/javascript and web/app. For your first deployment, start with Get started; for feature changes, use Build with AI.

Implemented journey

Create an email/password account, verify email, sign in, create a personal/team workspace, invite teammates, manage roles, add contacts, create a sales pipeline, add deals, and move deals between stages. The free tier allows 25 contacts and 10 deals per workspace. Stripe Pro removes those record limits. No payment price is invented in the UI; your configured Stripe recurring price appears in Checkout.

Passwords use salted scrypt. Sessions use random tokens stored as hashes in PostgreSQL, HttpOnly cookies, same-origin write checks, and session-bound CSRF tokens. Verification and reset links expire after 30 minutes and are single-use. Reset invalidates existing sessions. Authentication attempts are rate-limited in the shared database. Proxy-forwarded IP headers are deliberately not trusted; deployments behind a shared proxy need an explicit, reviewed trusted-proxy configuration before broad launch.

CRM records use the existing workspace transaction adapter and database RLS. Writes record audit events. Creating pipelines requires owner/admin; contacts and deals allow members; billing requires the owner. Module flags are checked on each CRM request. Disabling CRM blocks new checkout but keeps the existing subscription portal available to the owner. Counts and inserts share a workspace lock to prevent concurrent writes bypassing free limits.

Configure and run

For a hosted app, follow Deploy to Adios and Configure your app. For a local app, follow Run locally and manual database setup.

The runtime requires three distinct database roles for ordinary records, account management, and billing. adios kit deploy creates them; local setup requires configuring them explicitly. Keep the migration owner's connection out of the application.

Teams and invitations

Open the Team tab to see your workspace members. Owners can invite administrators or members, change roles, and remove people. Administrators can invite and remove members, but cannot grant administrative access or change roles. Members can view the roster. An owner must promote another owner before demoting or removing the last owner. Role changes and removals ask for confirmation in the interface.

Invitation emails contain a random, single-use token; only its hash is stored in PostgreSQL. Links expire after 7 days. The recipient must sign in with the verified email address that received the invitation, review the workspace and role, and choose Join workspace. Opening a link never grants access by itself. New users can register and verify their account first. The invitation is retained in the original browser tab for that flow; reopen the original invitation email if verification finishes in a different tab.

Sending another invitation to the same address replaces its old pending links. Revoking an invitation, removing a member, or failing email delivery invalidates the relevant pending links. Accepting an invitation never overwrites an existing membership role. Accepting the first teammate converts a personal workspace to a team without moving its data. Team management remains available when CRM is disabled.

Membership and invitation mutations share a per-workspace transaction lock. Permission checks run after acquiring it; the last-owner check, membership change, and audit event commit together. Subsequent requests by a removed member are denied; requests already authorized before removal may finish. Membership data is served through the restricted auth service, and the general runtime role has no membership-write or invitation-read grants.

For an existing installation, apply the new append-only core migration and refresh the auth service grants before starting this version:

sh
adios kit init
adios kit grant-service auth saas_auth

Use your actual auth role name if it differs. The auth role gains membership management, invitation access, workspace-kind updates, and audit insertion. It does not gain billing writes. Team emails use the same configured mail provider or local outbox as verification emails. Verify invitation delivery with your configured mail provider.

Stripe setup

Create a recurring Stripe price and set STRIPE_PRICE_ID, STRIPE_SECRET_KEY, and STRIPE_WEBHOOK_SECRET. Use test mode first. Register POST /api/billing/webhook for customer.subscription.created, customer.subscription.updated, and customer.subscription.deleted, using API version 2026-11-18.endive. Configure the Stripe customer portal for your product. Missing Stripe settings disable checkout and portal requests explicitly.

Checkout uses server-configured prices and workspace-bound customers. Repeated checkout requests reuse the open session. Idempotency keys cover customer creation and checkout generations. Portal and checkout require an authenticated workspace owner and CSRF protection.

Webhooks verify the raw body signature and timestamp, reject mode mismatches, deduplicate event IDs, and fetch current subscription state from Stripe while holding a per-workspace lock. This handles duplicate and out-of-order delivery. An active or trialing subscription to the configured price enables crm.pro; cancellation, unpaid, and past-due states do not. Transient Stripe failures roll back the receipt for retry. A successful checkout redirect does not grant access.

The webhook reconciles one founder Stripe account and one configured recurring price. Stripe Connect, multiple plan catalogs, seat billing, credit packs, and usage billing are not implemented. This integration has not yet been exercised against a real Stripe test account.

API surface

MethodPathPurpose
POST/api/auth/signupRegister and send verification email
POST/api/auth/loginCreate session cookie
POST/api/auth/logoutRevoke current session
POST/api/auth/verify/requestResend verification
POST/api/auth/verifyConsume verification token
POST/api/auth/reset/requestRequest password reset
POST/api/auth/resetSet password and revoke sessions
GET/api/meUser, CSRF token, and accessible workspaces
POST/api/workspacesCreate personal/team workspace
GET/api/workspaces/:id/teamMember roster and pending invitations for administrators
POST/api/workspaces/:id/team/invitationsInvite an administrator or member
DELETE/api/workspaces/:id/team/invitations/:invitationRevoke a pending invitation
PATCH/api/workspaces/:id/team/members/:userChange role (owner only)
DELETE/api/workspaces/:id/team/members/:userRemove a member while preserving an owner
POST/api/invitations/previewReview an invitation using workspace_id and token
POST/api/invitations/acceptExplicitly accept for the matching verified account
GET/api/workspaces/:id/crmContacts, pipelines, stages, deals, plan state
POST/api/workspaces/:id/crm/contactsAdd contact
POST/api/workspaces/:id/crm/pipelinesAdd pipeline with default stages
POST/api/workspaces/:id/crm/dealsAdd deal
PATCH/api/workspaces/:id/crm/deals/:dealMove stage within pipeline
GET/api/workspaces/:id/billingCurrent plan and membership role
POST/api/workspaces/:id/billing/checkoutCreate/reuse Stripe Checkout session
POST/api/workspaces/:id/billing/portalOpen Stripe customer portal
POST/api/billing/webhookReceive signed Stripe event

All application writes use JSON, exact APP_ORIGIN, and (after login) X-CSRF-Token from /api/me. The webhook uses raw bytes and a Stripe signature instead. Responses use a JSON error field on failure. Reads currently return the 200 most recent contacts and deals; server-side pagination, search, and CRUD expansion remain work.

Check an API change

Use local development tests after changing endpoints, then check the user flow in Verify your SaaS. The database-backed runner uses a temporary database and controlled provider responses.

For API work, preserve workspace and role checks, same-origin writes, CSRF protection, and server-side plan enforcement. See What's included for features that still need implementation.