Skip to content

Command-line tool for dashboard user administration and ad hoc D1 queries against the Legaciti monorepo.

The Legaciti CLI (legaciti) lives in the monorepo directory cli/ (package @legaciti/cli). It targets the dashboard worker (for example https://my.legaciti.org) for user operations and optional direct D1 access.

From the repository root:

Terminal window
pnpm cli -- --help

That runs the CLI in development mode via tsx. To use the compiled binary after a build:

Terminal window
pnpm -C cli build
pnpm -C cli exec legaciti --help

Global options:

OptionDescription
-h, --helpShow help for the program or a subcommand
-V, --versionPrint the CLI version

Environment variables are read from, in order: the repository root .env, the current working directory .env, and cli/.env (if present). Copy cli/.env.example to cli/.env (or merge into the root .env) as a starting point.

VariableRequired forDescription
BASE_URLUser API commandsDashboard origin (default http://localhost:5173). Example: https://my.legaciti.org. Alias: LEGACITI_BASE_URL.
ADMIN_CLI_SECRETusers list, users create, users edit, users deleteBearer token shared with the Worker (ADMIN_CLI_SECRET secret / .dev.vars).
RESET_PASSWORD_REDIRECT_TOOptional for users reset-passwordDefault redirect URL embedded in the reset email. Must match a Better Auth trustedOrigins entry on the dashboard (for example https://my.legaciti.org/reset-password).
CLOUDFLARE_ACCOUNT_IDd1 query --httpCloudflare account ID
CLOUDFLARE_API_TOKENd1 query --httpCloudflare API token with D1 (and any other) permissions — same name as Worker / Drizzle.
D1_DATABASE_IDd1 query --httpUUID for DB_0 (publications-db-0); see apps/dashboard/wrangler.jsonc
D1_DATABASE_NAMEd1 query (wrangler mode)Database name passed to wrangler d1 execute (default publications-db-0)

Set the Worker secret from apps/dashboard:

Terminal window
pnpm exec wrangler secret put ADMIN_CLI_SECRET

For local development, add the same name and value to apps/dashboard/.dev.vars.


Parent command:

Terminal window
legaciti users --help

All users subcommands except reset-password require ADMIN_CLI_SECRET and call the dashboard JSON API at /api/cli/users with Authorization: Bearer <ADMIN_CLI_SECRET>.

Prints every row from app_users (email, display name, superadmin flag, id) as a table.

Terminal window
pnpm cli -- users list

API: GET /api/cli/users → response body { "users": [ … ] }.

Interactive prompts: email, then whether the user should be a superadmin. Inserts into app_users (same semantics as the dashboard admin flow).

Terminal window
pnpm cli -- users create

API: POST /api/cli/users with JSON body { "email": "<email>", "is_superadmin": <boolean> } (validated with AdminUserSchema).

Interactive prompts: user email to update, then new superadmin yes/no. Updates is_superadmin (and updated_at) for that primary_email.

Terminal window
pnpm cli -- users edit

API: PATCH /api/cli/users with JSON body { "email": "<email>", "is_superadmin": <boolean> } (email required; is_superadmin optional in the schema but the CLI always sends a value).

Interactive prompts: user email, then confirmation. Removes workspace_memberships for that app user and deletes the app_users row.

Terminal window
pnpm cli -- users delete

API: DELETE /api/cli/users?email=<url-encoded-email>.

Interactive prompts: account email, then reset redirect URL (defaults to RESET_PASSWORD_REDIRECT_TO or <BASE_URL>/reset-password). Does not use ADMIN_CLI_SECRET; it calls Better Auth’s HTTP handler.

Terminal window
pnpm cli -- users reset-password

API: POST /api/auth/request-password-reset with JSON { "email": "<email>", "redirectTo": "<absolute-url>" }. The redirectTo URL must be allowed by the dashboard’s Better Auth trustedOrigins configuration.


Run raw SQL against the dashboard’s DB_0 database (auth and app metadata shard). Use read-only queries when possible; writes can affect production data.

Parent help:

Terminal window
legaciti d1 --help
Terminal window
legaciti d1 query "<sql>" [options]
OptionDescription
--httpUse Cloudflare’s D1 HTTP API instead of Wrangler. Requires CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_API_TOKEN, and D1_DATABASE_ID.
--localWith the default Wrangler mode, run against local D1 (omit --remote).
--cwd <dir>Working directory for pnpm exec wrangler (defaults to the current directory). Run from the monorepo root so wrangler resolves via the workspace.

Default mode (no --http): runs:

pnpm exec wrangler d1 execute <D1_DATABASE_NAME> --remote --json --command "<sql>"

Examples:

Terminal window
# Remote D1 via wrangler (from repo root)
pnpm cli -- d1 query "SELECT COUNT(*) AS n FROM app_users"
# Cloudflare HTTP API
pnpm cli -- d1 query "SELECT name FROM sqlite_schema WHERE type='table'" --http

These routes are implemented on the dashboard worker and are intended for operator automation (including this CLI).

MethodPathAuthDescription
GET/api/cli/usersBearer ADMIN_CLI_SECRETList app_users
POST/api/cli/usersBearerCreate user
PATCH/api/cli/usersBearerUpdate superadmin flag
DELETE/api/cli/users?email=BearerDelete user and memberships

If ADMIN_CLI_SECRET is not configured on the Worker, these endpoints respond with 503 and a JSON error body.