Cosmo Docs
Server

Admin Module

Internal enterprise management, org provisioning, and release publishing

The Admin module provides internal endpoints for Cosmo's operations team. All endpoints are protected by AdminSecretGuard, which requires the CLERK_SECRET_KEY as a bearer token. Source: packages/server/src/modules/admin/.

REST Endpoints

All endpoints are prefixed with /api/v1/admin and require AdminSecretGuard.

Org Management

MethodPathDescription
POST/admin/orgsCreate an org + owner user directly
DELETE/admin/orgs/:orgIdDelete an org from Clerk + DB

Enterprise Management

MethodPathDescription
GET/admin/enterpriseList all ENTERPRISE plan orgs
GET/admin/enterprise/:orgIdGet enterprise org with seat audit log
POST/admin/enterpriseProvision an org onto the ENTERPRISE plan
PATCH/admin/enterprise/:orgId/seatsUpdate purchased seat count (with audit)

Release Management

MethodPathDescription
POST/admin/releasesPublish a new desktop release
GET/admin/releasesList all releases
PATCH/admin/releases/:idUpdate release (rollout %, mandatory, etc.)

Admin Service (admin.service.ts)

createOrg({ orgName, ownerEmail, ownerName })

Provisions a complete org directly without going through Clerk sign-up:

  1. Creates the Clerk organisation.
  2. Creates the Clerk user with the provided email.
  3. Adds the user as OWNER of the Clerk org.
  4. Syncs both records to the local DB.
  5. Mints and returns a Cosmo JWT for the new owner.

Used for enterprise org provisioning and testing.

deleteOrg(orgId)

  1. Looks up the org's Clerk ID.
  2. Deletes the Clerk organisation (which cascades membership deletion).
  3. Deletes the local Organization record (cascades to all related DB records).

listEnterpriseOrgs()

Returns all Organization records with plan: ENTERPRISE, including their subscription and recent audit log entries.

getEnterpriseOrg(orgId)

Returns a single enterprise org with its full EnterpriseSeatAudit history, subscription details, and member count.

provisionEnterprise({ orgId, purchasedSeats, changedBy, notes })

Moves an org to the ENTERPRISE plan:

  1. Sets plan: ENTERPRISE on the Organization record.
  2. Creates or updates the Subscription with status: ACTIVE.
  3. Sets purchasedSeats on the subscription.
  4. Creates the first EnterpriseSeatAudit entry.

updateSeats({ orgId, purchasedSeats, changedBy, notes })

Updates seat count for an enterprise org:

  1. Records the previous seat count.
  2. Updates purchasedSeats on the subscription.
  3. Creates an EnterpriseSeatAudit entry with oldSeats, newSeats, changedBy, and notes.

Enterprise Seat Audit

Every seat count change is logged in EnterpriseSeatAudit:

FieldDescription
oldSeatsSeat count before this change
newSeatsSeat count after this change
changedByAdmin identifier (email or service name)
notesReason for the change
createdAtTimestamp of the change

This audit trail is used for billing reconciliation and contract management.

AdminSecretGuard

packages/server/src/common/guards/admin-secret.guard.ts extracts the bearer token from Authorization: Bearer <token> and compares it against process.env.CLERK_SECRET_KEY using crypto.timingSafeEqual — preventing timing-attack extraction of the secret.

Returns 401 Unauthorized if the token is missing or incorrect.