waybetter-for-x/docs/STORE.md
2026-09-30 23:01:13 +00:00

112 lines
9.6 KiB
Markdown

# wayBetter Store, install links and the gallery
Owner-approved (2026-09-28): themes and plugins can be installed from a dropped file, a
`waybetter://install` link or the signed wayBetter Store, always through the app's install screen.
This page is for whoever adds to or publishes wayBetter for X's items. Users: see PLUGINS.md →
"Installing". The Store on the web: <https://waybetter.fyi/store/>.
The Store is part of the wayBetter framework, so every wayBetter app has the same one:
**waybetter/docs/STORE.md** has the shared catalog format (format 2: every item names its `apps`),
signing and key rotation, the `waybetter store` command, install links and the trust model. This
app is id **`x`** in the shared catalog and supplies only what is X's.
## Pieces
| Piece | Where |
| --- | --- |
| Catalog + items + previews | `apps/web/public/store/` (`catalog.json`, `catalog.json.sig`, `plugins/`, `themes/`, `previews/`), served by the site as `https://waybetter.fyi/store/…`; one catalog for every wayBetter app |
| X's items (the source) | `store/x/plugins/<id>/` and `store/x/themes/<id>/`, one folder per item ([store/README.md](../store/README.md)); read by `scripts/store/source.mjs` for `scripts/store.config.mjs`. First-party plugins point at `apps/desktop/src-tauri/bundled-plugins/` (`"bundled"`), built-in themes are exported like Appearance → Export (`"builtin"`); a folder without its own preview gets one from `scripts/store/preview.mjs`. `store/featured.json` is the storefront's Featured shelf |
| Checks | `bun run check:store` (`scripts/check-store.mjs`): the folders, the catalog they would build, and the published catalog's signature and hashes. No key needed |
| Builder | `node scripts/build-store.mjs` = `waybetter store build` with that config (only X's items are replaced; other apps' items stay) |
| Signer | `node scripts/sign-store.mjs` = `waybetter store sign` / `--verify` with X's key paths (Ed25519 over the exact `catalog.json` bytes → `catalog.json.sig`, base64 of 64 bytes) |
| Store key | private: `%USERPROFILE%\.better-twttr-keys\store.key` on the owner's Windows PC (PKCS#8 PEM, created once with `--init`; never commit, print, copy or move it, never to another machine). Public: `apps/desktop/src-tauri/keys/store.pub` (base64 of the raw 32-byte key), compiled into the app (`distribution::STORE_PUBKEYS`, a list so a key can be rotated) |
| App side | `apps/desktop/src-tauri/src/distribution.rs` (X's `StoreConfig`: app id `x`, scheme `waybetter`, the framework's hosts, the public key) over waybetter-host `store`; `desktop_store.rs` (the shell-only commands and deep links around a framework `Store`); shell `src/shell/InstallDialog.tsx`, `installStore.ts`, `installModel.ts` wrap the framework's `InstallHost`, install controller, `storeModel` and `StoreView` (X's theme parse/save/preview, the panel's controls, `--wb-*` tokens mapped in `install.css` / `store.css`); the panel's Store section is the framework's (`waybetter/packages/shell/src/panel/StoreSection.tsx`, configured by `store` in `src/ui/Panel.tsx`) |
| Strings | framework catalogs, `wb.store.*`, `wb.install.*`, `wb.permission.*` (`{site}` = X) |
| The Store on the web | <https://waybetter.fyi/store/>: the storefront (`apps/web/store/index.html`), one page per item at `/store/themes/<id>/` and `/store/plugins/<id>/` (frame `apps/web/store/_item.html`), `/store/submit/`, and X's galleries `/themes/`, `/plugins/`. `apps/web/store-pages.ts` generates the cards and item pages from the signed catalog at build time, `apps/web/seo.ts` every page's title, description, canonical, Open Graph, Twitter card and JSON-LD plus `sitemap.xml` and `robots.txt`; repository links come from `apps/web/site.config.ts`. `apps/web/tests/seo.test.ts` (in `bun run test`) builds the site and checks all of it |
| Link previews | `node scripts/store/og-images.mjs` draws `apps/web/public/og/` (one picture per page and per item; an item without one uses the Store's) |
## Add your theme or plugin with a pull request
A pull request that adds one folder is a submission. You need a free account on the forge this
repository lives on (sign-up is open); nothing else.
1. **Make it and try it.** `npm create waybetter plugin` / `npm create waybetter theme`, or export
a theme from Appearance ([PLUGINS.md](PLUGINS.md), [THEMES.md](THEMES.md)). Drop the file on the
wayBetter window: the install screen you see is the one Store users will see.
2. **Add one folder**: `store/x/plugins/<id>/` with your `name.plugin.js` and an `item.json`
(`{ "category": "tools", "tags": ["notes"] }`), or `store/x/themes/<id>/` with `theme.json` and
an `item.json` (`{ "version": "1.0.0" }`). A `preview.svg` or `preview.png` (640×400) is
optional. [store/README.md](../store/README.md) has every field and rule.
3. **Run the checks**: `git submodule update --init`, `bun install --frozen-lockfile`, then
`bun run check:store` and `bun run test`. There is no hosted CI: these commands are the checks,
and a maintainer runs them again before merging.
4. **Open the pull request** from your fork. The template asks what the item does and what it uses.
No git? Open an issue with the "Submit a theme" or "Submit a plugin" template and attach the
file; a maintainer adds the folder for you.
What `bun run check:store` checks: folder ids and file names, `item.json` fields, categories and
tags, duplicates; for plugins the rules the app applies at install (UTF-8 text, a header with
`@name` and `@version`, valid `@permissions`) plus the Store's own (a description of 50 characters
or more, a `@permissions` line that names `network` or `network:none`, `network:none` refused when
the code calls network APIs, gated API calls declared, nothing loaded or evaluated at run time);
for themes that the app's sanitizer accepts the file and its CSS loads nothing from outside;
previews (16:10, at most 300 KB, nothing scriptable); the page title (at most 60 characters) and
description (50 to 160) the site will generate, both unique; that the folders build into a catalog
the apps accept; and that the published catalog still matches its signature and every file's hash.
It ends by listing the items that are in the folders but not yet in the signed catalog.
**Merging is not publishing.** The Store key is offline by design, so after the merge a maintainer
reads the code and runs the next section on the machine that holds the key. Only then is the item
in the signed catalog, in the apps, and on the site, where its page, card, search entry, link
preview, structured data and sitemap entry are generated by the build.
**Languages** are not Store items: all 51 are built into the app and load on demand. Fix or finish
one in `apps/desktop/locales/<tag>.json` by pull request, or by an issue with the "Fix or improve
a translation" template; `bun run i18n:check` validates it (must print `0 error(s)`) and it ships
with the next app update. See [TRANSLATING.md](TRANSLATING.md).
## Publishing a change (maintainers)
1. Change the plugin/theme (bump `@version` for plugins), or merge a contribution's folder.
2. `bun run check:store` and read the code of anything new: anything in a signed catalog is
vouched for by the store key.
3. `node scripts/build-store.mjs` (rewrites X's items in `apps/web/public/store/` from `store/x/`).
4. `node scripts/sign-store.mjs` on the PC with the store key (it verifies the signature right after).
5. `bun run test:rust` checks that the committed catalog verifies with the compiled-in public key
and that every X file matches its size, sha256, header version and permissions;
`apps/desktop/tests/install.test.ts` that every bundled plugin is in it.
6. Optional: `node scripts/store/og-images.mjs` draws the new item's link-preview picture.
7. `bun run --cwd apps/web build && bun run --cwd apps/web test`, commit, then deploy the site the
usual way (the owner deploys). The build generates the item's page and everything around it.
A build changes `generatedAt`, so every build needs a new signature; never commit a built catalog
without signing it.
X specifics: plugins are installed under `file`; first-party plugins use their bundled names
(`bt-*.plugin.js`) so a bundled copy counts as installed and the store can offer its updates.
Built-in theme ids show as "Built in · Use" in the app (the files are for the gallery and for
sharing). X's own look (`x`) is not in the store.
## Install links
`waybetter://install?kind=theme|plugin&url=<percent-encoded https URL>` (rules in
waybetter/docs/STORE.md; hosts `waybetter.fyi`, `cdn1.crt.fyi`, `git.crt.fyi` raw files). The
scheme is registered by the NSIS installer (Windows, `HKCU\Software\Classes\waybetter`),
`Info.plist` (macOS) and the `.desktop` file (Linux packages; an AppImage and a Windows debug build
register it at startup). A second launch forwards its link to the running app (single-instance
plugin, `deep-link` feature).
## Trust model (X)
- Only the local shell webview can call the install commands (`install_*`, `store_*`,
`plugin_remove`; capability `workspace-local`, asserted in `tests/security.rs`, which also checks
that each command starts with `shell_only`). X tabs and web pages cannot; a link only proposes an
install.
- Everything else is the framework's and the same in every app: staged exact bytes under a random
token, commit ≥ 0.6 s after staging (Install enabled after 1 s, Enter never confirms), catalog
signature then size + sha256, `validate_plugin`, and for themes X's own `sanitizeSpec` and native
`x_set_theme` validation, as for any import.
- A leaked store key could put any plugin in front of users' install screens (they still see the
code, hash and permissions and must confirm). Rotate by adding a new key to `STORE_PUBKEYS`,
shipping that app version, re-signing, then removing the old key.