chadtmiller.com/group-host
atmosphere group host
0
0
A site keeps its members' records in the host's published space type
crates/group-host/src/lexicons.rs+1−0
| @@ -114,6 +114,7 @@ pub const FILES: &[&str] = &[ | ||
lexicon!("fyi/opensocial/rule"), | ||
lexicon!("fyi/opensocial/searchActors"), | ||
lexicon!("fyi/opensocial/site"), | ||
lexicon!("fyi/opensocial/siteSpace"), | ||
lexicon!("fyi/opensocial/space"), | ||
lexicon!("fyi/opensocial/startAccountMove"), | ||
lexicon!("fyi/opensocial/updateGroupHandle"), | ||
crates/group-host/src/sites.rs+58−19
| @@ -116,23 +116,43 @@ fn acts_of(site: &Value) -> Vec<&str> { | ||
named(site, "acts") | ||
} | ||
| ||
/// 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)> { | ||
/// What a site's `writes` name: each a type of the group's spaces, one | ||
/// space of it by key or all of them, and a collection its pages may write | ||
/// there in the visitor's own repo. | ||
fn writes_of(site: &Value) -> Vec<(&str, Option<&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?))) | ||
let each = all.map(|w| { | ||
( | ||
w["space"].as_str(), | ||
w["key"].as_str(), | ||
w["collection"].as_str(), | ||
) | ||
}); | ||
each.filter_map(|(space, key, collection)| Some((space?, key, collection?))) | ||
.collect() | ||
} | ||
| ||
/// The space types a site's `spaces` name: those its pages read whole, | ||
/// as the visitor. | ||
fn spaces_of(site: &Value) -> Vec<&str> { | ||
/// The spaces a site's `spaces` name, each a type and one space of it by | ||
/// key or all of them: those its pages read whole, as the visitor. | ||
fn spaces_of(site: &Value) -> Vec<(&str, Option<&str>)> { | ||
let all = site["spaces"].as_array().into_iter().flatten(); | ||
all.map(|s| s["space"].as_str().unwrap_or_default()) | ||
all.map(|s| (s["space"].as_str().unwrap_or_default(), s["key"].as_str())) | ||
.collect() | ||
} | ||
| ||
/// A space as a person types it: `<type>`, or `<type>/<key>` for one. | ||
fn space_name(kind: &str, key: Option<&str>) -> String { | ||
match key { | ||
Some(key) => format!("{kind}/{key}"), | ||
None => kind.to_string(), | ||
} | ||
} | ||
| ||
/// The `&skey=` part of a scope naming one space by key, empty for all. | ||
fn skey(key: Option<&str>) -> String { | ||
key.map(|key| format!("&skey={key}")).unwrap_or_default() | ||
} | ||
| ||
/// Whether a site asks for its visitor's session: to read, act, read | ||
/// spaces or write. | ||
fn is_live(site: &Value) -> bool { | ||
| @@ -142,16 +162,17 @@ fn is_live(site: &Value) -> bool { | ||
|| !writes_of(site).is_empty() | ||
} | ||
| ||
/// Refuses a site whose `spaces` name no type, or one type twice. | ||
/// Refuses a site whose `spaces` name no type, or one space twice. | ||
fn spaces(site: &Value) -> Result<(), XrpcError> { | ||
let mut seen = BTreeSet::new(); | ||
for kind in spaces_of(site) { | ||
for (kind, key) in spaces_of(site) { | ||
if kind.is_empty() { | ||
return Err(refused("a site's space names no type".to_string())); | ||
} | ||
if !seen.insert(kind) { | ||
if !seen.insert((kind, key)) { | ||
let name = space_name(kind, key); | ||
return Err(refused(format!( | ||
"{kind} is named twice in the site's spaces" | ||
"{name} is named twice in the site's spaces" | ||
))); | ||
} | ||
} | ||
| @@ -606,14 +627,16 @@ fn client_metadata(host: &Host, did: &str, handle: &str, origin: &str, site: &Va | ||
for method in asked.chain([viewer]).collect::<BTreeSet<_>>() { | ||
scope.push(format!("rpc:{method}?{aud}")); | ||
} | ||
for kind in spaces_of(site).into_iter().collect::<BTreeSet<_>>() { | ||
scope.push(format!("space:{kind}?authority={did}&action=read")); | ||
for (kind, key) in spaces_of(site).into_iter().collect::<BTreeSet<_>>() { | ||
let skey = skey(key); | ||
scope.push(format!("space:{kind}?authority={did}{skey}&action=read")); | ||
} | ||
let writes = "action=create&action=update&action=delete"; | ||
let written = writes_of(site).into_iter().collect::<BTreeSet<_>>(); | ||
for (kind, collection) in &written { | ||
for (kind, key, collection) in &written { | ||
let skey = skey(*key); | ||
scope.push(format!( | ||
"space:{kind}?authority={did}&collection={collection}&{writes}" | ||
"space:{kind}?authority={did}{skey}&collection={collection}&{writes}" | ||
)); | ||
} | ||
if !written.is_empty() { | ||
| @@ -648,14 +671,30 @@ fn shell(host: &Host, did: &str, handle: &str, site: &Value, path: &str) -> Resp | ||
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})) | ||
.map(|(space, key, collection)| { | ||
let mut write = json!({"space": space, "collection": collection}); | ||
if let Some(key) = key { | ||
write["key"] = json!(key); | ||
} | ||
write | ||
}) | ||
.collect(); | ||
let spaces: Vec<Value> = spaces_of(site) | ||
.into_iter() | ||
.map(|(space, key)| { | ||
let mut each = json!({"space": space}); | ||
if let Some(key) = key { | ||
each["key"] = json!(key); | ||
} | ||
each | ||
}) | ||
.collect(); | ||
let config = json!({ | ||
"group": did, | ||
"handle": handle, | ||
"reads": reads, | ||
"acts": acts, | ||
"spaces": spaces_of(site), | ||
"spaces": spaces, | ||
"writes": writes, | ||
"aud": format!("{}#opensocial", host.config.service_did), | ||
"handleResolver": host.config.site_handle_resolver, | ||
crates/group-host/tests/sites.rs+17−10
| @@ -725,11 +725,13 @@ async fn a_site_reads_the_groups_spaces_whole_as_its_visitor() { | ||
let (did, [alice, ..]) = group(&h).await; | ||
let files = json!([{"path": "index.html", "text": "<p>the board</p>"}]); | ||
| ||
// A type named twice is refused; one naming none is no NSID, refused | ||
// by the lexicon before the host looks. | ||
// A space named twice, whole or by its key, is refused; one naming | ||
// none is no NSID, refused by the lexicon before the host looks. | ||
let board = json!({"space": "com.example.board"}); | ||
let pins = json!({"space": "com.example.board", "key": "pins"}); | ||
let refused = [ | ||
(json!([board, board]), "InvalidSite"), | ||
(json!([pins, pins]), "InvalidSite"), | ||
(json!([{"space": ""}]), "InvalidRequest"), | ||
]; | ||
for (spaces, wanted) in refused { | ||
| @@ -744,9 +746,10 @@ async fn a_site_reads_the_groups_spaces_whole_as_its_visitor() { | ||
} | ||
| ||
// Reading spaces alone, its pages are served in the page that holds a | ||
// session, which is told which spaces they read. | ||
// session, which is told which spaces they read. A type named whole and | ||
// one space of it by key is redundant, but no harm. | ||
let members = format!("{NS}.members"); | ||
let spaces = json!([board, {"space": members}]); | ||
let spaces = json!([board, pins, {"space": members}]); | ||
let said = call( | ||
&h, | ||
&alice, | ||
| @@ -762,9 +765,10 @@ async fn a_site_reads_the_groups_spaces_whole_as_its_visitor() { | ||
shell.body | ||
); | ||
let (_, config) = shell_of(&shell); | ||
assert_eq!(config["spaces"], json!(["com.example.board", members])); | ||
assert_eq!(config["spaces"], spaces); | ||
| ||
// Its OAuth client asks to read each, with the group as authority. | ||
// Its OAuth client asks to read each, with the group as authority, and | ||
// the one space alone where it names one by key. | ||
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(); | ||
| @@ -772,6 +776,7 @@ async fn a_site_reads_the_groups_spaces_whole_as_its_visitor() { | ||
"atproto".to_string(), | ||
format!("rpc:{NS}.getViewer?aud=did%3Aweb%3Ahost.test%23opensocial"), | ||
format!("space:com.example.board?authority={did}&action=read"), | ||
format!("space:com.example.board?authority={did}&skey=pins&action=read"), | ||
format!("space:{members}?authority={did}&action=read"), | ||
]; | ||
assert_eq!(scope, wanted); | ||
| @@ -790,6 +795,7 @@ async fn a_site_that_writes_asks_its_visitor_for_those_writes_alone() { | ||
let board = "com.example.board"; | ||
let writes = json!([ | ||
{"space": board, "collection": "com.example.note"}, | ||
{"space": board, "key": "pins", "collection": "com.example.note"}, | ||
{"space": format!("{NS}.members"), "collection": format!("{NS}.acceptance")}, | ||
]); | ||
let said = call( | ||
| @@ -820,16 +826,17 @@ async fn a_site_that_writes_asks_its_visitor_for_those_writes_alone() { | ||
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| { | ||
let space = |kind: &str, skey: &str, collection: &str| { | ||
format!( | ||
"space:{kind}?authority={did}&collection={collection}&action=create&action=update&action=delete" | ||
"space:{kind}?authority={did}{skey}&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")), | ||
space(board, "", "com.example.note"), | ||
space(board, "&skey=pins", "com.example.note"), | ||
space(&format!("{NS}.members"), "", &format!("{NS}.acceptance")), | ||
"blob:image/*".to_string(), | ||
]; | ||
assert_eq!(scope, wanted); | ||
crates/group-host-mcp/src/lib.rs+2−1
| @@ -398,7 +398,8 @@ const TOOLS: &[(&str, &[&str], &str, Made)] = &[ | ||
cookies or storage. A site that names `reads`, methods of the host's such as \ | ||
fyi.opensocial.listMembers, `acts`, procedures of the host's such as \ | ||
fyi.opensocial.createReport, `spaces`, types of the group's spaces, or `writes`, \ | ||
records of a collection in a type of the group's spaces, is served in a page of the \ | ||
records of a collection in a type of the group's spaces, each type alone for every \ | ||
space of it or with a `key` for just the one space of it by that key, 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`, those acts with `os.act`, and open those spaces \ | ||
with `os.space`, to sync and read them whole and make those writes in that person's \ | ||
crates/opensocial/src/lib.rs+32−10
| @@ -59,7 +59,8 @@ 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>] | ||
[--acts <methods>] [--spaces <type,…>] [--writes <space:collection,…>] | ||
[--acts <methods>] [--spaces <type[/key],…>] | ||
[--writes <type[/key]: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; with | ||
| @@ -67,7 +68,8 @@ site | ||
as createReport; with --spaces, the types of the group's spaces | ||
they may read whole as that person, each by its NSID; 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 | ||
each a type of the group's spaces and a collection there; a type | ||
with /<key> after it names just the one space of it by that key | ||
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 | ||
| @@ -702,20 +704,40 @@ pub async fn run(args: &[String], env: &Env) -> Result<String> { | ||
given[key] = methods.map(|r| json!({"method": named(r)})).collect(); | ||
} | ||
} | ||
// Each a type of the group's spaces, by its NSID: not ours to | ||
// name by its last part. | ||
// A space is a type of the group's spaces, by its NSID, not ours | ||
// to name by its last part, and with /<key> after it, just the one | ||
// space of that type by that key. | ||
let space = |s: &str| { | ||
let (kind, key) = match s.split_once('/') { | ||
Some((kind, key)) => (kind.trim(), Some(key.trim())), | ||
None => (s.trim(), None), | ||
}; | ||
if kind.is_empty() || key == Some("") { | ||
bail!("{s}: a space is <type> or <type>/<key>"); | ||
} | ||
let mut named = json!({"space": kind}); | ||
if let Some(key) = key { | ||
named["key"] = key.into(); | ||
} | ||
Ok(named) | ||
}; | ||
if let Some(listed) = a.flags.get("spaces") { | ||
let kinds = listed.split(',').map(str::trim).filter(|s| !s.is_empty()); | ||
given["spaces"] = kinds.map(|s| json!({"space": s})).collect(); | ||
let each = listed.split(',').map(str::trim).filter(|s| !s.is_empty()); | ||
let spaces: Vec<Value> = each.map(space).collect::<Result<_>>()?; | ||
given["spaces"] = spaces.into(); | ||
} | ||
// Each a type of the group's spaces and a collection there. | ||
// Each a space, as above, 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()})) | ||
Some((named, collection)) => { | ||
let mut write = space(named)?; | ||
write["collection"] = collection.trim().into(); | ||
Ok(write) | ||
} | ||
None => Err(anyhow!("{w}: a write is <space>:<collection>")), | ||
None => Err(anyhow!( | ||
"{w}: a write is <type>:<collection> or <type>/<key>:<collection>" | ||
)), | ||
}; | ||
let writes: Vec<Value> = each.map(write).collect::<Result<_>>()?; | ||
given["writes"] = writes.into(); | ||
crates/opensocial/tests/commands.rs+47−1
| @@ -976,9 +976,25 @@ async fn publishes_a_folder_as_the_groups_site_and_takes_it_down() { | ||
) | ||
.await; | ||
assert!( | ||
unsaid.contains("a write is <space>:<collection>"), | ||
unsaid.contains("a write is <type>:<collection> or <type>/<key>:<collection>"), | ||
"{unsaid}" | ||
); | ||
// A write in just the one space of a type, by its key. | ||
let args = [ | ||
"site", | ||
"publish", | ||
group, | ||
folder, | ||
"--writes", | ||
"fyi.opensocial.siteSpace/board:com.example.note", | ||
]; | ||
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": "fyi.opensocial.siteSpace", "key": "board", "collection": "com.example.note"}, | ||
]); | ||
assert_eq!(&site.to_json()["writes"], &wanted); | ||
| ||
// Spaces, each a type by its NSID, read whole by the site's pages. | ||
let args = [ | ||
| @@ -994,6 +1010,36 @@ async fn publishes_a_folder_as_the_groups_site_and_takes_it_down() { | ||
let site = atproto::drisl::decode(&record.unwrap().unwrap().value).unwrap(); | ||
let wanted = json!([{"space": "com.example.board"}, {"space": "fyi.opensocial.members"}]); | ||
assert_eq!(&site.to_json()["spaces"], &wanted); | ||
// Or just the one space of a type, by its key. | ||
let args = [ | ||
"site", | ||
"publish", | ||
group, | ||
folder, | ||
"--spaces", | ||
"fyi.opensocial.siteSpace/board, fyi.opensocial.siteSpace/calendar", | ||
]; | ||
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": "fyi.opensocial.siteSpace", "key": "board"}, | ||
{"space": "fyi.opensocial.siteSpace", "key": "calendar"}, | ||
]); | ||
assert_eq!(&site.to_json()["spaces"], &wanted); | ||
let keyless = [ | ||
"site", | ||
"publish", | ||
group, | ||
folder, | ||
"--spaces", | ||
"fyi.opensocial.siteSpace/", | ||
]; | ||
let keyless = fails(&alice, &keyless).await; | ||
assert!( | ||
keyless.contains("a space is <type> or <type>/<key>"), | ||
"{keyless}" | ||
); | ||
| ||
let missing = fails(&alice, &["site", "publish", group, "/no/such/folder"]).await; | ||
assert!(missing.contains("reading /no/such/folder"), "{missing}"); | ||
docs/design/sites.md+58−16
| @@ -37,12 +37,14 @@ call as the visitor who signs in on it. Those are | ||
| ||
It may name `acts`, up to 20 of the host's procedures its pages may call | ||
as that person, each acting for them alone. For now that's | ||
`fyi.opensocial.createReport` only. It may name `spaces`, up to 20 types | ||
of the group's spaces its pages may read whole as that person, such as | ||
`com.example.place.room`. And it may name `writes`, up to 20 kinds of | ||
record its pages may write in that person's own repo. Each is a type of | ||
the group's spaces and a collection there, such as | ||
`fyi.opensocial.acceptance` in `fyi.opensocial.members`. | ||
`fyi.opensocial.createReport` only. It may name `spaces`, up to 20 of | ||
the group's spaces its pages may read whole as that person. Each is a | ||
type, such as `fyi.opensocial.siteSpace`, and may give a `key` to name | ||
one space of that type, such as `board`. Without a key, it's every space | ||
of the type. And it may name `writes`, up to 20 kinds of record its | ||
pages may write in that person's own repo. Each is a type of the group's | ||
spaces, a key if it's for one space of them, and a collection there, | ||
such as `com.example.note` in `fyi.opensocial.siteSpace` under `board`. | ||
| ||
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 | ||
| @@ -70,8 +72,9 @@ the folder's top as `notFound`. It keeps `fallback`, `reads`, `spaces`, | ||
| ||
The `opensocial site publish` command reads a folder and sends its | ||
files. `--reads` and `--acts` name methods by NSID or by their last | ||
part, `--spaces` names space types by NSID, and `--writes` names each | ||
write as `<space>:<collection>`. `site delete` takes the site down. Both | ||
part, `--spaces` names each space as `<type>` or `<type>/<key>`, and | ||
`--writes` names each write as `<type>:<collection>` or | ||
`<type>/<key>:<collection>`. `site delete` takes the site down. Both | ||
leave out files whose names start with a dot. They send each file as | ||
text if it's UTF-8 and as bytes otherwise, and they take the folder's | ||
own name off each path. An AI app | ||
| @@ -84,12 +87,44 @@ that write to the same rules. The record is kept at `self`, and the | ||
member who approved the app must hold `group.configure`. Every path must | ||
be one a file may be at, with none given twice, and every file must name | ||
a blob. `fallback` and `notFound` must name files of the site. `reads` | ||
and `acts` must name only the methods above, and `spaces` may name no | ||
type twice. A site that breaks a rule fails with `InvalidSite`. | ||
and `acts` must name only the methods above. Each of `spaces` must name | ||
a type, and may name no type and key twice. Naming a type whole and also | ||
by one of its keys is allowed. A site that breaks a rule fails with | ||
`InvalidSite`. | ||
| ||
A path is `/`-separated, with no leading `/`, and no empty, `.` or `..` | ||
segment, backslash or control character. | ||
| ||
## A space for a site | ||
| ||
A member's PDS grants a site permission to a space type only once it can | ||
read that type's schema, published under a DNS lexicon authority. A site | ||
with space types of its own would need a domain, a `_lexicon` TXT record | ||
and its schemas published there before anyone could sign in to it. | ||
| ||
So the host publishes one space type with its own lexicons, | ||
`fyi.opensocial.siteSpace`, for a site to keep its members' records in. | ||
It lists no collections, and a group makes one space of it for each part | ||
of its site, under a key of its own, such as `board` or `calendar`. The | ||
site names those spaces by key in `spaces` and `writes`, so each sign-in | ||
asks for those spaces only, not every space of the type. The collections | ||
written there never need publishing either: a write permission names | ||
its collection, and a PDS doesn't look collections up. | ||
| ||
A group makes such a space with `space create`, as any other: | ||
| ||
```sh | ||
opensocial space create <group> fyi.opensocial.siteSpace --skey board \ | ||
--name Board --access '{"grants": [{"role": "member", "scopes": ["space:fyi.opensocial.siteSpace?action=read"]}]}' | ||
``` | ||
| ||
Then the site names it: | ||
| ||
```sh | ||
opensocial site publish <group> <dir> --spaces fyi.opensocial.siteSpace/board \ | ||
--writes fyi.opensocial.siteSpace/board:com.example.note | ||
``` | ||
| ||
## Serving | ||
| ||
When a request's `Host` is a group's address here, the host answers it | ||
| @@ -240,17 +275,24 @@ Its scope is `atproto`, plus these: | ||
| ||
- for each of the site's `reads` and `acts`, and `getViewer`, | ||
`rpc:<method>?aud=<the host's service DID>#opensocial`. | ||
- for each of its `spaces`, `space:<type>?authority=<the group>&action=read`. | ||
- for each of its `spaces`, | ||
`space:<type>?authority=<the group>&skey=<key>&action=read`. | ||
- for each of its `writes`, | ||
`space:<type>?authority=<the group>&collection=<collection>` with | ||
every action. | ||
`space:<type>?authority=<the group>&skey=<key>&collection=<collection>&action=create&action=update&action=delete`. | ||
- `blob:image/*`, if it has any `writes`. | ||
| ||
So it can call those methods on the host, read this group's spaces of | ||
those types, and write those records in the visitor's own repo in them. | ||
An entry without a key leaves out `&skey=<key>`, and its scope covers | ||
every space of the type. So the site can call those methods on the | ||
host, read those of this group's spaces, and write those records in the | ||
visitor's own repo in them. | ||
It can't do anything else. The session is kept in the browser at the | ||
address's origin and goes only to the visitor's PDS. The site's frame | ||
never holds it. | ||
| ||
The visitor's PDS must support spaces for them to sign in to a site | ||
that names `spaces` or `writes`, since it must grant the `space:` | ||
scopes. bsky.social doesn't yet. | ||
| ||
As the visitor moves through the site, the host's page puts the frame's | ||
page in the address bar and its title on the tab. So a reload or a | ||
copied link opens the page they're on. | ||
| @@ -268,7 +310,7 @@ gives each ask's parameters, answers and refusals, and an example page: | ||
| `os.call(method, params)` | the method's answer, asked as the visitor. That's its JSON, or a `Blob` for a method that answers with a file (`getSpaceBlob`) | | ||
| `os.act(method, input)` | the procedure's answer, asked as the visitor with `input` as its JSON. For `createReport` that's its `id` and `createdAt` | | ||
| `os.space(uri)` | one of the group's spaces (`at://<group>/space/<type>/<skey>`), with the SDK's `GroupSpace` methods below. The same `uri` gives the same object | | ||
| `space.sync()` | `{failed}`, once the page's records of a space are up to date as the visitor may read them. The space's type must be one the site names in `spaces`. `failed` lists the writers whose PDS didn't answer | | ||
| `space.sync()` | `{failed}`, once the page's records of a space are up to date as the visitor may read them. The site must name the space in `spaces`, by its type alone or by its type and key. `failed` lists the writers whose PDS didn't answer | | ||
| `space.records({collections})` | every record held, right away, each as `{uri, repo, collection, rkey, cid, value}`. Given `collections`, only those collections' records | | ||
| `space.onChange(fn)` | calls `fn` with every record held after each sync that changes them | | ||
| `space.create(collection, value, {rkey})` | the `uri` and `cid` of `value`, written in the visitor's own repo in the space | | ||
docs/design/spaces.md+6−0
| @@ -34,6 +34,12 @@ ends one with `fyi.opensocial.deleteSpace`, listed or not. Nobody makes | ||
or deletes meta and members this way. Only the chosen people a space is | ||
for can change it ([groups](groups.md)). | ||
| ||
A space's type is any NSID, but a member's PDS grants an app a type only | ||
once it can read that type's published schema. For a group's site, the | ||
host publishes one, `fyi.opensocial.siteSpace`. It lists no collections, | ||
and a group makes one space of it per part of its site under its own key, | ||
such as `board` or `calendar` ([sites](sites.md#a-space-for-a-site)). | ||
| ||
## Who writes where | ||
| ||
The group's own repo in a space holds what the group writes as itself. A | ||
docs/reference/api.md+2−2
| @@ -130,14 +130,14 @@ A group's website ([sites](../design/sites.md)). | ||
| ||
| Method | What it does | | ||
| --- | --- | | ||
| `POST fyi.opensocial.putSite` | publishes a group's whole site from the files given, each as text or bytes, and replaces the one there. `reads` lists the host's methods its pages may read, `acts` the procedures they may ask, and `spaces` the group's space types they may read whole. `writes` lists the records they may write in the signed-in person's own repo in the group's spaces. Pages do all of it as that person. It takes a body up to `BLOB_UPLOAD_LIMIT` | | ||
| `POST fyi.opensocial.putSite` | publishes a group's whole site from the files given, each as text or bytes, and replaces the one there. `reads` lists the host's methods its pages may read, `acts` the procedures they may ask, and `spaces` the group's spaces they may read whole, each a type and, for one space of it, a `key`. `writes` lists the records they may write in the signed-in person's own repo in the group's spaces, each a type, an optional `key` and a collection. Pages do all of it as that person. It takes a body up to `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. The site's 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>` | answers 200 if the proxy in front may get a certificate for `domain`, and 404 otherwise. A domain qualifies if it's a group's own domain, or `www.` under it, while the group is on | | ||
| `GET`, `HEAD` `https://<address>/<path>` | serves a file, sandboxed, from the site of the group whose address the request's `Host` names. The host keeps `/.well-known/` and `/xrpc/` there for itself. For a site that names `reads`, `spaces`, `acts` or `writes`, a page is the host's page wrapped around the site's. It holds the visitor's session and carries the site page's title, preview tags and the status it would have | | ||
| `GET https://<address>/_site/<path>` | for a site that names `reads`, `spaces`, `acts` or `writes`, serves the file the frame shows, sandboxed, as above | | ||
| `GET https://<address>/client-metadata.json` | for a site that names `reads`, `spaces`, `acts` or `writes`, serves its OAuth client's metadata. It's a public client asking for `atproto`, an `rpc:` scope for each read, each act and `getViewer`, and a `space:` scope to read each space type, with `authority` the group. For each write it asks a `space:` scope of its type, with `authority` the group, its collection and every action, and with any write it asks `blob:image/*`. It's named for the request's `X-Forwarded-Host` if a proxy sends one, and otherwise its `Host` | | ||
| `GET https://<address>/client-metadata.json` | for a site that names `reads`, `spaces`, `acts` or `writes`, serves its OAuth client's metadata. It's a public client asking for `atproto`, an `rpc:` scope for each read, each act and `getViewer`, and a `space:` scope to read each of its `spaces`, with `authority` the group and `skey` its key if it has one. For each write it asks a `space:` scope of its type, with `authority` the group, `skey` its key if it has one, its collection and every action, and with any write it asks `blob:image/*` ([live data](../design/sites.md#live-data)). It's named for the request's `X-Forwarded-Host` if a proxy sends one, and otherwise its `Host` | | ||
| `GET https://<address>/_os/kit.js` | for a site that names `reads`, `spaces`, `acts` or `writes`, serves the script its pages load for `os` ([the site kit](site-kit.md)) | | ||
| `GET https://<address>/_os/shell.js` | for a site that names `reads`, `spaces`, `acts` or `writes`, serves the host's page script from `SITE_SHELL_DIR`, or 404 without it | | ||
| ||
docs/reference/cli.md+1−1
| @@ -91,7 +91,7 @@ group's requests in it, while an MCP client acts in one group. | ||
| ||
| Command | What it does | | ||
| --- | --- | | ||
| `site publish <group> <dir> [--fallback <path>] [--not-found <path>] [--reads <methods>] [--acts <methods>] [--spaces <types>] [--writes <space:collection,…>]` | publishes the files under `<dir>`, except those whose names start with a dot, as the group's website at its address. It replaces the site that's there, sending each file as text if it's UTF-8 and as bytes otherwise. `--reads` is a comma-separated list of the host's methods the site's pages may ask as whoever signs in on it, each by NSID or by its last part (`getGroup,listMembers`). `--acts` lists the procedures they may ask as that person the same way (`createReport`). `--spaces` is a comma-separated list of the group's space types they may read whole as that person, each by NSID (`com.example.place.room`). `--writes` is a comma-separated list of the records they may write in that person's own repo, each a type of the group's spaces and a collection there (`fyi.opensocial.members:fyi.opensocial.acceptance`) ([live data](../design/sites.md#live-data)) | | ||
| `site publish <group> <dir> [--fallback <path>] [--not-found <path>] [--reads <methods>] [--acts <methods>] [--spaces <type[/key],…>] [--writes <type[/key]:collection,…>]` | publishes the files under `<dir>`, except those whose names start with a dot, as the group's website at its address. It replaces the site that's there, sending each file as text if it's UTF-8 and as bytes otherwise. `--reads` is a comma-separated list of the host's methods the site's pages may ask as whoever signs in on it, each by NSID or by its last part (`getGroup,listMembers`). `--acts` lists the procedures they may ask as that person the same way (`createReport`). `--spaces` is a comma-separated list of the group's spaces they may read whole as that person, each a type by NSID, or a type and one space's key (`fyi.opensocial.siteSpace/board,fyi.opensocial.siteSpace/calendar`). `--writes` is a comma-separated list of the records they may write in that person's own repo, each a space named the same way and a collection there (`fyi.opensocial.siteSpace/board:com.example.note`) ([live data](../design/sites.md#live-data)) | | ||
| `site delete <group>` | takes the group's website down | | ||
| `site domain <group> [--undo]` | serves the group's website at its handle's own domain once that domain reaches this host, and redirects its address and `www.` there. With `--undo`, it serves the site at its address alone again ([on its own domain](../design/sites.md#on-its-own-domain)) | | ||
| ||