Repository navigation
feat(cloud): read-only admin dashboard of every account - #100
Merged
Merged
Conversation
pnpm cloud:dashboard serves, through Localify, an overview of every Localify Cloud account: headline numbers, accounts per plan, sign-ups per week, what needs attention, a sortable users table and a page per account. It reads D1 in one wrangler call of SELECT statements, cached 30 seconds, and its database layer refuses anything else.
Wrangler ran through spawnSync, so a stalled read froze every request and the stop signals. It now runs asynchronously, is killed after a minute or when the dashboard stops, and a failed read is still not cached.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it shows
pnpm cloud:dashboardserves an overview of every Localify Cloud account on the operator's Mac, through Localify:past_dueaccounts, overrides ending within 30 days, and accounts at 80% or more of their URL, serving-machine or signed-in-machine limit.cloud:admin showprints, laid out visually: ban, override, billing snapshot, add-ons, entitlement, machines, and each URL with the machine serving it and its state (serving, suspended, suspended until the next reconcile, taken down).Plans, overrides and add-ons go through
src/entitlement.ts(accountOf,servingUrlLimit,signedInMachineCap). The only change there is a newEVERY_ACCOUNT_SQLexport: the existing account select, without aWHERE.Light and dark themes (the system setting, plus a toggle). Data is read when a page loads, cached 30 seconds, with a refresh button (at most one re-read every 5 seconds) and the time of the last read. Plain Node
httpwith server-rendered HTML, no new dependency.Read-only
scripts/dashboard/db.tsrefuses, before anything is sent, any statement that is not one plainSELECT. That coversWITH(a CTE can hold a write),;, unterminated quotes or comments, and write, schema or connection keywords outside string literals. Tests cover the refusal, and check that nothing reaches the database when one statement of a batch is refused.GETandHEADgets405. Only.localifyhosts and loopback are answered, which a Localify public URL's traffic arrives as.503without its error, which goes to the terminal only.Cache-Control: no-store, a nonce-based CSP,frame-ancestors 'none'andnoindex. Every value from D1 is escaped.wrangler d1 execute --remotecall asCLOUDFLARE_DEPLOY_TOKENfrom Infisical. Only that token and the account id are kept in memory. A dedicated read-only D1 token in Infisical would be safer than the deploy token; creating it is left to Téo.How to run it
The README's new "Dashboard" section has the steps:
Without the
PORTthat Localify sets, it refuses to start.Checks
pnpm cloud:typecheckandpnpm cloud:testpass (446 tests, 45 of them new). The new tests cover the SELECT guard, the queries and aggregation against the real migrations with fixture rows, the cache, and the routes.SELECT, whichnode:sqlitedoesn't, so the activity query uses joins instead of aUNION.infisical exportanswers 403 "This project does not belong to your selected organization", so the deploy token could not be loaded.pnpm cloud:adminhits the same error. After switching Infisical to the right organization, run the production command above once.