chadtmiller.com/group-host
atmosphere group host
0
0
A site's pages write in the group's spaces as whoever signs in
.knotless/workflows/e2e.yml+10−11
| @@ -9,9 +9,11 @@ | ||
# do it together. Each flow that fails leaves the page as it was then | ||
# among the check's outputs, as a picture. | ||
# | ||
# Node, the packages, Chromium, the libraries it needs and the build are | ||
# kept between runs, as main's runs leave them: nothing is fetched again | ||
# until what it is made from changes. | ||
# The world runs the reference PDS on the space alpha harness/alpha.sh | ||
# builds, as the tests do, so that a site's writes in a space are made | ||
# here. Node, the packages, Chromium, the libraries it needs, the alpha | ||
# and the build are kept between runs, as main's runs leave them: nothing | ||
# is fetched again until what it is made from changes. | ||
image: rust:1.98 | ||
# The shared runner host; ci.knotless.dev, also this repository's, runs only deploy.yml. | ||
runners: [runner.knotless.dev] | ||
| @@ -22,10 +24,11 @@ on: | ||
push: {refs: [refs/heads/main]} | ||
pull: | ||
base: [refs/heads/main, refs/heads/feature/*] | ||
paths: [web/**, lexicons/**, crates/**, Cargo.toml, Cargo.lock, harness/e2e/**, docs/guides/**, harness/look/**, harness/shots.mjs, harness/world.mjs, harness/pds.mjs, harness/tls-proxy.mjs, harness/package.json, harness/package-lock.json, .knotless/workflows/e2e.yml, .knotless/uses.lock] | ||
cache: [target, /usr/local/cargo/registry, /usr/local/rustup, /opt/node, /opt/browsers, /opt/chromium-debs, web/node_modules, harness/node_modules] | ||
paths: [web/**, lexicons/**, crates/**, Cargo.toml, Cargo.lock, harness/e2e/**, docs/guides/**, harness/look/**, harness/shots.mjs, harness/world.mjs, harness/pds.mjs, harness/alpha.sh, harness/tls-proxy.mjs, harness/package.json, harness/package-lock.json, .knotless/workflows/e2e.yml, .knotless/uses.lock] | ||
cache: [target, /usr/local/cargo/registry, /usr/local/rustup, /opt/node, /opt/atproto, /opt/browsers, /opt/chromium-debs, web/node_modules, harness/node_modules] | ||
env: | ||
PLAYWRIGHT_BROWSERS_PATH: /opt/browsers | ||
GROUP_HOST_DEV_ENV: /opt/atproto/packages/dev-env | ||
steps: | ||
- uses: chadtmiller.com/steps/node@1 | ||
with: {version: 24.22.1} | ||
| @@ -55,12 +58,8 @@ steps: | ||
echo "$want" > $debs/.want | ||
fi | ||
dpkg -i $debs/*.deb > /dev/null | ||
- name: sqlite | ||
run: | | ||
# The stock PDS's SQLite module, which the install above skips building. | ||
export PATH=/opt/node/bin:$PATH | ||
dir="$(dirname "$(node -p "require.resolve('better-sqlite3/package.json', { paths: ['harness'] })")")" | ||
[ -f "$dir/build/Release/better_sqlite3.node" ] || (cd "$dir" && npm run install) | ||
- name: spaces alpha | ||
run: sh harness/alpha.sh | ||
- name: build | ||
run: | | ||
export PATH=/opt/node/bin:$PATH | ||
.knotless/workflows/test.yml+6−30
| @@ -3,7 +3,7 @@ | ||
# is counted as it runs, so it is told to stop rather than killed. | ||
# | ||
# The tests that reach the network run against the reference PDS and PLC | ||
# (harness/pds.mjs), on the space alpha built at ATPROTO_COMMIT. Node, | ||
# (harness/pds.mjs), on the space alpha harness/alpha.sh builds. Node, | ||
# the harness's packages, the alpha's build, cargo-llvm-cov and the build | ||
# are kept between runs; each is made again only when what it is made from | ||
# changes. | ||
| @@ -17,13 +17,6 @@ on: | ||
push: {refs: [refs/heads/main]} | ||
pull: {base: [refs/heads/main, refs/heads/feature/*]} | ||
cache: [target, /usr/local/cargo/registry, /usr/local/rustup, /opt/tools, /opt/node, /opt/atproto, harness/node_modules] | ||
env: | ||
# The space alpha the tests run against: permissioned-data-alpha as of | ||
# November 13, 2026, the build @atproto/space 0.0.0-spaces-alpha-20261113224550 | ||
# was published from. | ||
ATPROTO_COMMIT: 83d473dec69bbf19fe95fcbbb20a39842779db82 | ||
# Bumped when the steps that build the alpha change, to build it again. | ||
ALPHA_BUILD: "2" | ||
steps: | ||
- uses: chadtmiller.com/steps/node@1 | ||
with: {version: 24.22.1} | ||
| @@ -33,31 +26,14 @@ steps: | ||
- uses: chadtmiller.com/steps/cargo-llvm-cov@1 | ||
with: {version: 0.9.1} | ||
- name: spaces alpha | ||
run: | | ||
[ "$(cat /opt/atproto/.built 2>/dev/null)" = "$ATPROTO_COMMIT $ALPHA_BUILD" ] && exit 0 | ||
export PATH=/opt/node/bin:$PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 COREPACK_HOME=/opt/atproto/.corepack | ||
find /opt/atproto -mindepth 1 -delete | ||
cd /opt/atproto | ||
git init -q . && git fetch -q --depth 1 https://github.com/bluesky-social/atproto.git "$ATPROTO_COMMIT" && git checkout -q FETCH_HEAD | ||
mkdir .bin && corepack enable --install-directory /opt/atproto/.bin | ||
export PATH=/opt/atproto/.bin:$PATH | ||
pnpm install --frozen-lockfile --ignore-scripts | ||
pnpm run build:tooling --force | ||
pnpm --filter '@atproto/dev-env^...' --filter @atproto/dev-env run --if-present prebuild | ||
pnpm exec tsc --build packages/dev-env/tsconfig.build.json | ||
# The PDS serves its OAuth sign-in pages from this bundle, and will | ||
# not start without it. | ||
pnpm --filter @atproto/oauth-provider-ui run build:ui | ||
echo "$ATPROTO_COMMIT $ALPHA_BUILD" > /opt/atproto/.built | ||
run: sh harness/alpha.sh | ||
- name: sqlite | ||
run: | | ||
# SQLite's native module for the alpha's PDS, which the install above | ||
# skips building, and the harness's own for the stock PDS. | ||
# SQLite's native module for the stock PDS, which the install above | ||
# skips building. | ||
export PATH=/opt/node/bin:$PATH | ||
for from in /opt/atproto/packages/pds harness; do | ||
dir="$(dirname "$(node -p "require.resolve('better-sqlite3/package.json', { paths: ['$from'] })")")" | ||
[ -f "$dir/build/Release/better_sqlite3.node" ] || (cd "$dir" && npm run install) | ||
done | ||
dir="$(dirname "$(node -p "require.resolve('better-sqlite3/package.json', { paths: ['harness'] })")")" | ||
[ -f "$dir/build/Release/better_sqlite3.node" ] || (cd "$dir" && npm run install) | ||
- name: test | ||
run: | | ||
export PATH=/opt/node/bin:/opt/tools:$PATH GROUP_HOST_DEV_ENV=/opt/atproto/packages/dev-env | ||
crates/group-host/src/site_kit.js+26−3
| @@ -1,7 +1,8 @@ | ||
// `os`: what a page of a group's site asks the page the host serves | ||
// around it, which holds the visitor's session. Each ask is a message to | ||
// it, answered by one naming the same id; a read nobody may make now is | ||
// refused with `locked` and a reason, "sign in" or "not for you". | ||
// it, answered by one naming the same id; a read or a write nobody may | ||
// make now is refused with `locked` and a reason, "sign in" or "not for | ||
// you". | ||
// | ||
// <os-sign-in> is a button for signing in and out, in the page's own | ||
// markup, so the page's own CSS styles it: "Sign in" while nobody is, | ||
| @@ -36,8 +37,30 @@ | ||
group: () => ask('group'), | ||
/** Who is looking: `{signedIn, did, handle}`. */ | ||
me: () => ask('me'), | ||
/** One of the host's methods the site reads, as whoever is looking. */ | ||
/** | ||
* One of the host's methods the site reads, as whoever is looking: its | ||
* JSON, or a `Blob` for one that answers a file (`getSpaceBlob`), to | ||
* show with `URL.createObjectURL`. | ||
*/ | ||
call: (method, params = {}) => ask('call', { method, params }), | ||
/** | ||
* Uploads `file`, a picture (a `File` or `Blob` of an `image/` type), to | ||
* the visitor's own PDS, for a record the site writes to point to. | ||
* Answers its reference, `{$type: 'blob', ref, mimeType, size}`, which | ||
* the record holds; a site that declares no writes may not upload. | ||
*/ | ||
upload: (file) => ask('upload', { file }), | ||
/** | ||
* Writes `record` in the visitor's own repo, in `space` (one of the | ||
* group's, `at://<group>/space/<type>/<skey>`), as the site declared it | ||
* may: in `collection`, at `rkey` if given. Answers its `uri` and `cid`. | ||
*/ | ||
create: (space, collection, record, { rkey } = {}) => | ||
ask('create', { space, collection, record, ...(rkey ? { rkey } : {}) }), | ||
/** Writes `record` at `rkey`, in place of what is there, as `create` does. */ | ||
put: (space, collection, rkey, record) => ask('put', { space, collection, rkey, record }), | ||
/** Deletes the visitor's own record at `rkey`, as `create` writes it. */ | ||
delete: (space, collection, rkey) => ask('delete', { space, collection, rkey }), | ||
/** | ||
* Opens the host's sign-in dialog, its handle filled in with `hint` if | ||
* given, for the visitor to confirm. Signed in, the page loads again. | ||
crates/group-host/src/sites.rs+40−8
| @@ -100,6 +100,20 @@ fn reads_of(site: &Value) -> Vec<&str> { | ||
all.filter_map(|r| r["method"].as_str()).collect() | ||
} | ||
| ||
/// What a site's `writes` name: each a type of the group's spaces, and a | ||
/// collection its pages may write there in the visitor's own repo. | ||
fn writes_of(site: &Value) -> Vec<(&str, &str)> { | ||
let all = site["writes"].as_array().into_iter().flatten(); | ||
let each = all.map(|w| (w["space"].as_str(), w["collection"].as_str())); | ||
each.filter_map(|(space, collection)| Some((space?, collection?))) | ||
.collect() | ||
} | ||
| ||
/// Whether a site asks for its visitor's session: to read, or to write. | ||
fn is_live(site: &Value) -> bool { | ||
!reads_of(site).is_empty() || !writes_of(site).is_empty() | ||
} | ||
| ||
/// Refuses a site whose `reads` name a method that is none of [`READS`]. | ||
fn reads(site: &Value) -> Result<(), XrpcError> { | ||
match reads_of(site).into_iter().find(|m| !READS.contains(m)) { | ||
| @@ -461,7 +475,7 @@ pub async fn serve(State(host): State<Arc<Host>>, req: Request, next: Next) -> R | ||
// The name the browser asked, as a proxy in front says it if it says, | ||
// else as the request does: the site's OAuth client is named for it. | ||
let asked = text(HeaderName::from_static("x-forwarded-host")); | ||
match host.live_site(&did).filter(|s| !reads_of(s).is_empty()) { | ||
match host.live_site(&did).filter(is_live) { | ||
Some(site) => { | ||
let origin = format!("https://{}", asked.or(named).unwrap_or_default()); | ||
live(&host, &did, &handle, &site, &origin, asking) | ||
| @@ -495,9 +509,8 @@ fn live( | ||
origin: &str, | ||
mut asking: Asking, | ||
) -> Response { | ||
let reads = reads_of(site); | ||
match asking.path.as_str() { | ||
"client-metadata.json" => client_metadata(host, handle, origin, &reads), | ||
"client-metadata.json" => client_metadata(host, did, handle, origin, site), | ||
"_os/kit.js" => script(KIT.as_bytes().to_vec()), | ||
"_os/shell.js" => { | ||
let built = host.config.site_shell.as_ref().map(|d| d.join("shell.js")); | ||
| @@ -524,9 +537,12 @@ fn script(bytes: Vec<u8>) -> Response { | ||
(StatusCode::OK, kind, bytes).into_response() | ||
} | ||
| ||
/// The site's OAuth client document, at its address `origin`: `atproto`, | ||
/// and leave to ask each of `reads`, and `getViewer`, of the host. | ||
fn client_metadata(host: &Host, handle: &str, origin: &str, reads: &[&str]) -> Response { | ||
/// The site's OAuth client document, at its address `origin`: `atproto`; | ||
/// leave to ask each of its `reads`, and `getViewer`, of the host; and to | ||
/// make each of its `writes` in the visitor's own repo, in the group | ||
/// `did`'s spaces of that type alone, with pictures they upload for those | ||
/// records to point to. | ||
fn client_metadata(host: &Host, did: &str, handle: &str, origin: &str, site: &Value) -> Response { | ||
let aud = format!("{}#opensocial", host.config.service_did); | ||
let aud = reqwest::Url::parse_with_params("https://x/", &[("aud", aud)]) | ||
.expect("a URL") | ||
| @@ -535,9 +551,20 @@ fn client_metadata(host: &Host, handle: &str, origin: &str, reads: &[&str]) -> R | ||
.to_string(); | ||
let mut scope = vec!["atproto".to_string()]; | ||
let viewer = "fyi.opensocial.getViewer"; | ||
let reads = reads_of(site); | ||
for method in reads.iter().chain([&viewer]).collect::<BTreeSet<_>>() { | ||
scope.push(format!("rpc:{method}?{aud}")); | ||
} | ||
let writes = "action=create&action=update&action=delete"; | ||
let written = writes_of(site).into_iter().collect::<BTreeSet<_>>(); | ||
for (kind, collection) in &written { | ||
scope.push(format!( | ||
"space:{kind}?authority={did}&collection={collection}&{writes}" | ||
)); | ||
} | ||
if !written.is_empty() { | ||
scope.push("blob:image/*".to_string()); | ||
} | ||
let doc = json!({ | ||
"client_id": format!("{origin}/client-metadata.json"), | ||
"client_name": handle, | ||
| @@ -560,15 +587,20 @@ fn client_metadata(host: &Host, handle: &str, origin: &str, reads: &[&str]) -> R | ||
| ||
/// The page around a site's pages at `path`: the group's page there in a | ||
/// sandboxed frame, and what the host's script needs to sign its visitor | ||
/// in and ask `reads` as them. | ||
/// in, ask `reads` and make `writes` as them. | ||
fn shell(host: &Host, did: &str, handle: &str, site: &Value, path: &str) -> Response { | ||
let reads = reads_of(site); | ||
let (status, html) = host.page_at(did, site, path); | ||
let head = site_head::preview(html.as_deref().unwrap_or_default(), handle); | ||
let writes: Vec<Value> = writes_of(site) | ||
.into_iter() | ||
.map(|(space, collection)| json!({"space": space, "collection": collection})) | ||
.collect(); | ||
let config = json!({ | ||
"group": did, | ||
"handle": handle, | ||
"reads": reads, | ||
"writes": writes, | ||
"aud": format!("{}#opensocial", host.config.service_did), | ||
"handleResolver": host.config.site_handle_resolver, | ||
"plc": host.config.plc_url, | ||
| @@ -655,7 +687,7 @@ pub async fn put_site( | ||
let group = configuring(&host, &headers, &body, "putSite").await?; | ||
host.active(&group)?; | ||
let mut site = json!({"$type": SITE, "files": [], "createdAt": iso(now_millis())}); | ||
for key in ["fallback", "notFound", "reads"] { | ||
for key in ["fallback", "notFound", "reads", "writes"] { | ||
if let Some(given) = body.get(key) { | ||
site[key] = given.clone(); | ||
} | ||
crates/group-host/tests/sites.rs+58−0
| @@ -646,6 +646,64 @@ async fn a_site_reads_only_what_the_host_lets_a_page_read() { | ||
); | ||
} | ||
| ||
#[tokio::test] | ||
async fn a_site_that_writes_asks_its_visitor_for_those_writes_alone() { | ||
let h = start(&[], false).await; | ||
let (did, [alice, ..]) = group(&h).await; | ||
let files = json!([{"path": "index.html", "text": "<p>the board</p>"}]); | ||
let board = "com.example.board"; | ||
let writes = json!([ | ||
{"space": board, "collection": "com.example.note"}, | ||
{"space": format!("{NS}.members"), "collection": format!("{NS}.acceptance")}, | ||
]); | ||
let said = call( | ||
&h, | ||
&alice, | ||
"putSite", | ||
json!({"group": did, "files": files, "writes": writes}), | ||
) | ||
.await; | ||
assert_eq!(said.0, 200, "{}", said.1); | ||
| ||
// Writing, though it reads nothing, its pages are served in the page | ||
// that holds a session, which is told what they may write. | ||
let shell = page(&h, "/").await; | ||
assert!( | ||
shell.body.contains("data-src=\"/_site/\""), | ||
"{}", | ||
shell.body | ||
); | ||
let (_, config) = shell_of(&shell); | ||
assert_eq!(config["writes"], writes); | ||
assert_eq!(config["reads"], json!([])); | ||
| ||
// Its OAuth client asks the visitor's PDS for each write, in this | ||
// group's spaces of that type and in that collection alone, and to | ||
// upload pictures for those records to point to, beside asking the | ||
// host who they are. | ||
let client = page(&h, "/client-metadata.json").await; | ||
let doc: Json = serde_json::from_str(&client.body).unwrap(); | ||
let scope: Vec<&str> = doc["scope"].as_str().unwrap().split(' ').collect(); | ||
let space = |kind: &str, collection: &str| { | ||
format!( | ||
"space:{kind}?authority={did}&collection={collection}&action=create&action=update&action=delete" | ||
) | ||
}; | ||
let wanted = [ | ||
"atproto".to_string(), | ||
format!("rpc:{NS}.getViewer?aud=did%3Aweb%3Ahost.test%23opensocial"), | ||
space(board, "com.example.note"), | ||
space(&format!("{NS}.members"), &format!("{NS}.acceptance")), | ||
"blob:image/*".to_string(), | ||
]; | ||
assert_eq!(scope, wanted); | ||
| ||
// The record says so, for any app that reads it. | ||
let kept = h.host.store.record(&did, SITE, "self").unwrap().unwrap(); | ||
let site = atproto::drisl::decode(&kept.value).unwrap().to_json(); | ||
assert_eq!(site["writes"], writes); | ||
} | ||
| ||
#[test] | ||
fn a_page_previews_as_its_own_head_says_and_never_as_markup() { | ||
let preview = |html: &str| group_host::site_head::preview(html, "riders.test"); | ||
crates/group-host-mcp/src/lib.rs+4−2
| @@ -396,8 +396,10 @@ const TOOLS: &[(&str, &[&str], &str, Made)] = &[ | ||
of it, each as text or as bytes, in place of the site there; a file the group holds \ | ||
already is used again. Its pages run sandboxed, each in an origin of its own, with no \ | ||
cookies or storage. A site that names `reads`, methods of the host's such as \ | ||
fyi.opensocial.listMembers, is served in a page of the host's that signs its visitor in, \ | ||
and its pages ask those as whoever is looking, with `os.call` from `/_os/kit.js`.", | ||
fyi.opensocial.listMembers, or `writes`, records of a collection in a type of the \ | ||
group's spaces, is served in a page of the host's that signs its visitor in: its pages \ | ||
ask those reads as whoever is looking, with `os.call` from `/_os/kit.js`, and make \ | ||
those writes in that person's own repo, with `os.create`, `os.put` and `os.delete`.", | ||
Made::Method("putSite", None), | ||
), | ||
( | ||
crates/opensocial/src/lib.rs+17−2
| @@ -59,9 +59,12 @@ role | ||
add to what a role may do, or with --undo take it away | ||
site | ||
site publish <group> <dir> [--fallback <path>] [--not-found <path>] [--reads <methods>] | ||
[--writes <space:collection,…>] | ||
publish the files under <dir> as the group's website, at its | ||
address, in place of the one there; with --reads, the host's | ||
methods its pages may ask as whoever signs in on it | ||
methods its pages may ask as whoever signs in on it; with | ||
--writes, the records they may write in that person's own repo, | ||
each a type of the group's spaces and a collection there | ||
site delete <group> take the group's website down | ||
site domain <group> [--undo] | ||
serve the website at the group's own domain, its handle, once | ||
| @@ -676,7 +679,7 @@ pub async fn run(args: &[String], env: &Env) -> Result<String> { | ||
Ok(stats_lines(&said)) | ||
} | ||
["site", "publish", rest @ ..] => { | ||
let a = parse(rest, &["fallback", "not-found", "reads"])?; | ||
let a = parse(rest, &["fallback", "not-found", "reads", "writes"])?; | ||
let [group, dir] = a.take()?; | ||
let mut given = json!({"files": site_files(std::path::Path::new(dir))?}); | ||
for (flag, name) in [("fallback", "fallback"), ("not-found", "not_found")] { | ||
| @@ -693,6 +696,18 @@ pub async fn run(args: &[String], env: &Env) -> Result<String> { | ||
}; | ||
given["reads"] = methods.map(|r| json!({"method": named(r)})).collect(); | ||
} | ||
// Each a type of the group's spaces and a collection there. | ||
if let Some(writes) = a.flags.get("writes") { | ||
let each = writes.split(',').map(str::trim).filter(|w| !w.is_empty()); | ||
let write = |w: &str| match w.split_once(':') { | ||
Some((space, collection)) => { | ||
Ok(json!({"space": space.trim(), "collection": collection.trim()})) | ||
} | ||
None => Err(anyhow!("{w}: a write is <space>:<collection>")), | ||
}; | ||
let writes: Vec<Value> = each.map(write).collect::<Result<_>>()?; | ||
given["writes"] = writes.into(); | ||
} | ||
let tools = group_host_mcp::tools(); | ||
let tool = tools.iter().find(|t| t.name == "site_publish"); | ||
let tool = tool.expect("site_publish is a tool"); | ||
crates/opensocial/tests/commands.rs+34−0
| @@ -946,6 +946,40 @@ async fn publishes_a_folder_as_the_groups_site_and_takes_it_down() { | ||
json!([{"method": "fyi.opensocial.getGroup"}, {"method": "fyi.opensocial.listMembers"}]); | ||
assert_eq!(reads, &wanted); | ||
| ||
// Writes, each a type of the group's spaces and a collection there. | ||
let args = [ | ||
"site", | ||
"publish", | ||
group, | ||
folder, | ||
"--writes", | ||
"com.example.board:com.example.note, fyi.opensocial.members:fyi.opensocial.acceptance", | ||
]; | ||
ok(&alice, &args).await; | ||
let record = h.host.store.record(&did, "fyi.opensocial.site", "self"); | ||
let site = atproto::drisl::decode(&record.unwrap().unwrap().value).unwrap(); | ||
let wanted = json!([ | ||
{"space": "com.example.board", "collection": "com.example.note"}, | ||
{"space": "fyi.opensocial.members", "collection": "fyi.opensocial.acceptance"}, | ||
]); | ||
assert_eq!(&site.to_json()["writes"], &wanted); | ||
let unsaid = fails( | ||
&alice, | ||
&[ | ||
"site", | ||
"publish", | ||
group, | ||
folder, | ||
"--writes", | ||
"com.example.note", | ||
], | ||
) | ||
.await; | ||
assert!( | ||
unsaid.contains("a write is <space>:<collection>"), | ||
"{unsaid}" | ||
); | ||
| ||
let missing = fails(&alice, &["site", "publish", group, "/no/such/folder"]).await; | ||
assert!(missing.contains("reading /no/such/folder"), "{missing}"); | ||
| ||
docs/design/sites.md+47−21
| @@ -4,8 +4,9 @@ A group can have a website: a front page that says who it is, or as many | ||
pages as it likes. The host serves it at the group's address, | ||
`https://<address>/`, as static files, the way they were published. It has | ||
no templates, no build step and no rendering on the server. A site that | ||
names `reads` may also show the group as each visitor may see it, once | ||
they sign in on it, through a page the host serves around its own | ||
names `reads` may also show the group as each visitor may see it, and one | ||
that names `writes` may write in the group's spaces as each visitor may, | ||
once they sign in on it, through a page the host serves around its own | ||
([live data](#live-data)). | ||
| ||
## What a site is | ||
| @@ -29,7 +30,9 @@ It may also name two of those files: | ||
And it may name `reads`, up to 20 of the host's methods its pages may | ||
ask as whoever signs in on it: `fyi.opensocial.getGroup`, `listMembers`, | ||
`listSpaceRecords`, `getSpaceBlob`, `getActor` and `getViewer`, and no | ||
others. | ||
others. And `writes`, up to 20 kinds of record its pages may write in that | ||
person's own repo, each a type of the group's spaces and a collection | ||
there, such as `fyi.opensocial.acceptance` in `fyi.opensocial.members`. | ||
| ||
A site has 1 to 2000 files. Each publish replaces the record whole, and | ||
deleting the record takes the site down. A blob only the old record held | ||
| @@ -52,10 +55,10 @@ to its site while it has one, and its settings have a Site page, which | ||
says where the site is, how many files it has and when it was published, | ||
and publishes a folder chosen in the browser, or deletes the site, asked | ||
to be sure of. Publishing takes a `404.html` at the folder's top as | ||
`notFound`, and keeps `fallback` and `reads` under Advanced, ticked and | ||
`notFound`, and keeps `fallback`, `reads` and `writes` under Advanced, | ||
filled as the site has them. The `opensocial site publish` command reads a folder | ||
and sends its files, with `--reads` naming methods by NSID or by their | ||
last part; `site delete` takes the site down. Both leave out files whose | ||
last part, and `--writes` each write as `<space>:<collection>`; `site delete` takes the site down. Both leave out files whose | ||
names start with a dot, send each file as text if it is UTF-8 and as | ||
bytes otherwise, and take the folder's own name off each path. An AI app | ||
connected over MCP publishes with `site_publish`, writing each file as | ||
| @@ -174,14 +177,15 @@ from any app. | ||
| ||
A page in the sandbox has no session, so it can show only what it was | ||
published with. A group often wants more on its site: its rules, who is | ||
in it, what members post. All of that is the group's to show only to | ||
those its roles allow, so it can't be published into the page for | ||
everyone. Instead, each visitor signs in on the site, and the page asks | ||
the host as them. | ||
in it, what members post, and a way for members to post there too. All | ||
of that is the group's to show only to those its roles allow, so it | ||
can't be published into the page for everyone, and what a member writes | ||
is theirs, in their own repo. Instead, each visitor signs in on the site, | ||
and the page asks the host, and writes at the visitor's own PDS, as them. | ||
| ||
### The page around a site | ||
| ||
A site that names `reads` is served differently. Each page of it is the | ||
A site that names `reads` or `writes` is served differently. Each page of it is the | ||
host's own page, which holds the visitor's session and shows the | ||
site's page in a sandboxed frame beneath it, filling the window. The | ||
site's files are under `/_site/` there, sandboxed as above, and a file | ||
| @@ -201,9 +205,12 @@ client of its own, a public one whose client id is | ||
`https://<address>/client-metadata.json`, and whose callback is | ||
`/_os/callback` there; behind a proxy that names the host it was asked | ||
as `X-Forwarded-Host`, as Caddy does, both are at that name instead. Its | ||
scope is `atproto` and, for each of the site's | ||
`reads` and `getViewer`, `rpc:<method>?aud=<the host's service DID>#opensocial`: | ||
it can ask the host those methods and nothing else. The session is kept | ||
scope is `atproto`; for each of the site's `reads` and `getViewer`, | ||
`rpc:<method>?aud=<the host's service DID>#opensocial`; and for each of | ||
its `writes`, `space:<type>?authority=<the group>&collection=<collection>` | ||
with every action. It can ask the host those methods, and write those | ||
records in the visitor's own repo in this group's spaces of those types, | ||
and nothing else. The session is kept | ||
in the browser at the address's origin, and goes to the visitor's PDS | ||
alone; the site's frame never holds it. | ||
| ||
| @@ -220,7 +227,11 @@ the host's page, which answers it: | ||
| --- | --- | | ||
| `os.group()` | `{did, handle}` of the group whose site it is | | ||
| `os.me()` | `{signedIn, did, handle}` of who is looking | | ||
| `os.call(method, params)` | the method's answer, asked as the visitor | | ||
| `os.call(method, params)` | the method's answer, asked as the visitor: its JSON, or a `Blob` for one that answers a file (`getSpaceBlob`) | | ||
| `os.upload(file)` | the blob reference of `file`, a picture, uploaded to the visitor's own PDS for a record the site writes to point to | | ||
| `os.create(space, collection, record, {rkey})` | the `uri` and `cid` of `record` written in the visitor's own repo in `space`, one of the group's (`at://<group>/space/<type>/<skey>`) | | ||
| `os.put(space, collection, rkey, record)` | the same, at `rkey`, in place of what is there | | ||
| `os.delete(space, collection, rkey)` | the visitor's record at `rkey` deleted | | ||
| `os.signIn({hint})` | opens the sign-in dialog, `hint` filled in as the handle | | ||
| `os.signOut()` | signs the visitor out | | ||
| `os.onChange(fn)` | calls `fn` with `os.me()`'s answer whenever it changes | | ||
| @@ -229,13 +240,28 @@ the host's page, which answers it: | ||
styles style: "Sign in" while nobody is, the visitor's handle and "Sign | ||
out" once someone is. | ||
| ||
`os.call` is refused for a method the site does not name in `reads`. | ||
Asked while nobody is signed in, it is refused with `locked` and the | ||
reason `sign in`; when the host refuses the visitor (401 or 403), with | ||
`locked` and `not for you`. A page shows what it may, and asks the | ||
visitor to sign in for the rest. The call goes through the visitor's PDS | ||
to the host, as any app's call does ([signing in](signing-in.md)), and | ||
the host answers it as it answers that person anywhere else. | ||
`os.call` is refused for a method the site does not name in `reads`, and a | ||
write for a collection, or a space, its `writes` do not name, or a space | ||
of another's. Asked while nobody is signed in, either is refused with | ||
`locked` and the reason `sign in`; when the host or the visitor's PDS | ||
refuses the visitor (401 or 403), with `locked` and `not for you`. A page | ||
shows what it may, and asks the visitor to sign in for the rest. A read | ||
goes through the visitor's PDS to the host, as any app's call does | ||
([signing in](signing-in.md)), and the host answers it as it answers that | ||
person anywhere else. A write is made at the visitor's PDS as any app's | ||
write in a space is, and the space's access record still says whether | ||
they may write there ([spaces](spaces.md)): `writes` asks no more of the | ||
visitor than the group lets them do. The host hears of it as of any | ||
member's write, so it is in the next `listSpaceRecords`. A sign-in from | ||
before the site named a write, which the PDS refuses for want of scope, | ||
is forgotten, refused with `sign in`, so that signing in again grants it. | ||
| ||
A site that names `writes` may also upload pictures: its sign-in asks the | ||
visitor's PDS for `blob:image/*` too, and `os.upload` takes only a file of | ||
an `image/` type. The picture is the visitor's, in their own repo; a record | ||
in a space that points to it makes it the space's, and anyone who reads | ||
the space reads it with `getSpaceBlob`, which the site names in `reads` to | ||
show it. A site with no `writes` uploads nothing. | ||
| ||
### Signing in | ||
| ||
docs/reference/api.md+6−6
| @@ -127,16 +127,16 @@ A group's website ([sites](../design/sites.md)). | ||
| ||
| Method | What it does | | ||
| --- | --- | | ||
| `POST fyi.opensocial.putSite` | publishes a group's site whole from the files given, each as text or bytes, in place of the one there, with the host's methods its pages may read (`reads`); takes a body as large as `BLOB_UPLOAD_LIMIT` | | ||
| `POST fyi.opensocial.putSite` | publishes a group's site whole from the files given, each as text or bytes, in place of the one there, with the host's methods its pages may read (`reads`) and the records they may write in whoever signs in's own repo in the group's spaces (`writes`); takes a body as large as `BLOB_UPLOAD_LIMIT` | | ||
| `POST fyi.opensocial.deleteSite` | takes a group's site down | | ||
| `POST fyi.opensocial.putSiteDomain` | serves a group's site at its handle's own domain, once that domain answers as this host; its address and `www.` under the domain redirect there | | ||
| `POST fyi.opensocial.deleteSiteDomain` | serves a group's site at its address alone again | | ||
| `GET /tls/ask?domain=<domain>` | 200 if the proxy in front may get a certificate for `domain`: a group's own domain, or `www.` under it, while the group is on; else 404 | | ||
| `GET`, `HEAD` `https://<address>/<path>` | a file of the site of the group whose address the request's `Host` names, sandboxed; the host keeps `/.well-known/` and `/xrpc/` there for itself. For a site that names `reads`, a page is the host's page around the site's, holding the visitor's session, with the site's page's title and preview tags and the status it would have | | ||
| `GET https://<address>/_site/<path>` | for a site that names `reads`, the file the frame shows, sandboxed, as above | | ||
| `GET https://<address>/client-metadata.json` | for a site that names `reads`, its OAuth client's metadata: a public client asking `atproto` and an `rpc:` scope for each read and `getViewer`, named for the request's `X-Forwarded-Host` if a proxy sends one, else its `Host` | | ||
| `GET https://<address>/_os/kit.js` | for a site that names `reads`, the script its pages load for `os` | | ||
| `GET https://<address>/_os/shell.js` | for a site that names `reads`, the host's page's script, from `SITE_SHELL_DIR`; 404 without it | | ||
| `GET`, `HEAD` `https://<address>/<path>` | a file of the site of the group whose address the request's `Host` names, sandboxed; the host keeps `/.well-known/` and `/xrpc/` there for itself. For a site that names `reads` or `writes`, a page is the host's page around the site's, holding the visitor's session, with the site's page's title and preview tags and the status it would have | | ||
| `GET https://<address>/_site/<path>` | for a site that names `reads` or `writes`, the file the frame shows, sandboxed, as above | | ||
| `GET https://<address>/client-metadata.json` | for a site that names `reads` or `writes`, its OAuth client's metadata: a public client asking `atproto`, an `rpc:` scope for each read and `getViewer`, for each write a `space:` scope of its type, with `authority` the group, its collection, and every action, and with any write `blob:image/*`, named for the request's `X-Forwarded-Host` if a proxy sends one, else its `Host` | | ||
| `GET https://<address>/_os/kit.js` | for a site that names `reads` or `writes`, the script its pages load for `os` | | ||
| `GET https://<address>/_os/shell.js` | for a site that names `reads` or `writes`, the host's page's script, from `SITE_SHELL_DIR`; 404 without it | | ||
| ||
As the spaces' authority and the PDS of the group's own repo in each, the | ||
host answers the space alpha's methods: | ||