techne-sdk 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -0
- package/README.md +12 -3
- package/dist/auth/app-key.d.ts +5 -0
- package/dist/auth/app-key.js +7 -0
- package/dist/auth/index.d.ts +19 -11
- package/dist/auth/index.js +21 -13
- package/dist/catalog/catalog.gen.js +499 -139
- package/dist/connect.d.ts +18 -3
- package/dist/connect.js +2 -0
- package/dist/generated/index.d.ts +3 -0
- package/dist/generated/index.js +9 -0
- package/dist/generated/lexicons.d.ts +590 -146
- package/dist/generated/lexicons.js +332 -71
- package/dist/generated/nsid.d.ts +3 -0
- package/dist/generated/nsid.js +3 -0
- package/dist/generated/nsid.json +3 -0
- package/dist/generated/types/pub/techne/draft/identity/attest.d.ts +2 -0
- package/dist/generated/types/pub/techne/draft/identity/defs.d.ts +23 -7
- package/dist/generated/types/pub/techne/draft/identity/defs.js +7 -0
- package/dist/generated/types/pub/techne/draft/identity/finishAddMethod.d.ts +3 -0
- package/dist/generated/types/pub/techne/draft/identity/listMethods.d.ts +2 -1
- package/dist/generated/types/pub/techne/draft/identity/manageMethods.d.ts +52 -10
- package/dist/generated/types/pub/techne/draft/identity/manageMethods.js +56 -0
- package/dist/generated/types/pub/techne/draft/identity/writeAsCollective.d.ts +51 -0
- package/dist/generated/types/pub/techne/draft/identity/writeAsCollective.js +55 -0
- package/dist/generated/types/pub/techne/draft/permissioned/putRecord.d.ts +1 -1
- package/dist/generated/types/pub/techne/draft/permissioned/putRecords.d.ts +1 -1
- package/dist/generated/types/pub/techne/draft/query/getRecords.d.ts +11 -0
- package/dist/generated/types/pub/techne/draft/query/getRecords.js +7 -0
- package/dist/query/compose.d.ts +1 -1
- package/dist/query/compose.js +1 -1
- package/dist/query/index.d.ts +7 -0
- package/dist/query/index.js +28 -1
- package/dist/versions/react.js +19 -6
- package/dist/wasm/techne-wasm.gen.js +1 -1
- package/dist/wasm/techne-wasm2js.gen.js +16836 -16838
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,80 @@
|
|
|
3
3
|
`techne-sdk` on npm and the `techne-sdk` crate share a version. Each entry names what changes for an app or
|
|
4
4
|
a crate user.
|
|
5
5
|
|
|
6
|
+
## Unreleased
|
|
7
|
+
|
|
8
|
+
- **README: Where we differ from atproto.** Spaces, collectives, tokens with no scope claim, and app approval.
|
|
9
|
+
Docs only.
|
|
10
|
+
- **`ownAppSpace(clientId)`**: the scope for the app's own private space by exact key,
|
|
11
|
+
`space:pub.techne.draft.space.private?skey=<appKey(clientId)>`, what `scopes()` asks for by default. A keyless
|
|
12
|
+
`space.private` scope (or `skey=*`) is every app's private space; the consent page shows it as a red warning.
|
|
13
|
+
- **`everything` names the whole store by its `space:` scope.** `'read'` adds `space:*?authority=*&action=read`
|
|
14
|
+
(`WHOLE_STORE_READ`), `'write'` adds `space:*?authority=*&manage=create&manage=update`
|
|
15
|
+
(`WHOLE_STORE`, the string Beacon and Commons declare). The `authRead`/`authWrite` sets reach no space on
|
|
16
|
+
Techne's PDS (#redesign 412a8235), so an app that opted in keeps its reach only by asking for the scope. Default
|
|
17
|
+
scopes are unchanged. The loopback client's keyless private-space scope is no longer narrowed to its own space
|
|
18
|
+
by the PDS.
|
|
19
|
+
- **Inputs:** lexicons `v0.1.22-techne.89` (commit `64c3caeb`, techne-lexicon-check `=0.3.27`) and the platform API at
|
|
20
|
+
`26f9c6e69` (the scopes branch on platform main `69fbf4986`; its published API is unchanged from `b9ca69248`).
|
|
21
|
+
`space.private` and the permissioned write descriptions: an app space is reached by `space:` scopes that cover
|
|
22
|
+
it, or by a token with none; which app is calling is not asked.
|
|
23
|
+
|
|
24
|
+
## 0.6.0 (2026-11-19)
|
|
25
|
+
|
|
26
|
+
npm 0.6.0 and crate 0.6.0 are built from the same commit. Lexicons `v0.1.22-techne.87` (commit `5cbac780`) with `techne-lexicon-check` `=0.3.25` from crates.io. The
|
|
27
|
+
platform's published API is pinned at platform `main` `b9ca69248` (the merge that ships
|
|
28
|
+
`identity.writeAsCollective`; its published API is unchanged from the branch commit `d9eb299d7`). Codegen, the catalog and the WebAssembly are regenerated. Additions
|
|
29
|
+
only, so this is a minor version. What changes for an app:
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- `writeAsCollective(input)` on the `connect`, `connectHosted` and `bind` clients: the platform's
|
|
34
|
+
`pub.techne.draft.identity.writeAsCollective`, com.atproto.repo.applyWrites's input and answer with `repo` a
|
|
35
|
+
collective the user may write as, applied by the platform with the credential it holds for the collective. Under
|
|
36
|
+
`connect` it goes through the user's PDS, so the app's OAuth scope needs
|
|
37
|
+
`rpc:pub.techne.draft.identity.writeAsCollective?aud=<platform DID>%23atproto_appview`; that is enough, since
|
|
38
|
+
the writes are public records (a write naming a `space` is refused: use `put` into the collective's space). `connectAnonymous`
|
|
39
|
+
refuses it (sign in to write). Types `WriteAsCollectiveInput` and `WriteAsCollectiveOutput`.
|
|
40
|
+
- The generated `pub.techne.draft.identity.writeAsCollective` client and types, and `NSID.IDENTITY_WRITE_AS_COLLECTIVE`.
|
|
41
|
+
|
|
42
|
+
## 0.5.0 (2026-11-17)
|
|
43
|
+
|
|
44
|
+
npm 0.5.0 and crate 0.5.0 are built from the same commit. Lexicons `v0.1.22-techne.85` (commit `06a30bd7`) with
|
|
45
|
+
`techne-lexicon-check` `=0.3.23` from crates.io, and the platform's published API from platform `main` `6b8466292`.
|
|
46
|
+
Codegen, the catalog and the WebAssembly are regenerated. A generated field is removed (below), so this is a major
|
|
47
|
+
version (RELEASING.md). What changes for an app:
|
|
48
|
+
|
|
49
|
+
### Removed (breaking)
|
|
50
|
+
|
|
51
|
+
- `primary` from the generated `identity.defs#linkView` (`identity.listMethods` `links[]`): linked accounts have no
|
|
52
|
+
primary (Linking v2). `mutual` is retired and always `true`; `since` is new.
|
|
53
|
+
|
|
54
|
+
### Added
|
|
55
|
+
|
|
56
|
+
- `RecordsAnswer.linked` (`getRecordsAnswer`, `answerOf`, a composed get step's `answer`): asked with
|
|
57
|
+
`handles`, the other accounts of each named repo's person, by DID, as `LinkedAccount` (`{did, handle?,
|
|
58
|
+
displayName?}`, the generated `getRecords#linkedHandle`), from each `getRecords#handle` entry's `linked`. Only
|
|
59
|
+
DIDs that have some; empty from a platform that does not send the field yet. `handle` is never `handle.invalid`.
|
|
60
|
+
- Lexicons techne.81 to .85 (Linking v2): `getRecords#handle.linked`; `identity.manageMethods` gains the
|
|
61
|
+
`moveMethod` (links two accounts) and `unlink` ops, `list`'s `person`, addChannel's `otherPerson` and `other`, and
|
|
62
|
+
the `FromStepUpRequired`, `Frozen`, `PendingChange`, `TooMany`, `Same`, `NoKey`, `NeedsMethod` and `NotLinked`
|
|
63
|
+
errors; new `identity.defs#personMember`; `defs#pendingChange` gains `moveMethod` and `other`; `defs#methodView`
|
|
64
|
+
gains `value` (manageMethods `list` only); `attest` gains `termsShown`.
|
|
65
|
+
|
|
66
|
+
### Changed
|
|
67
|
+
|
|
68
|
+
- Retired (Linking v2): `identity.link` and `identity.unlinkAccount` (the platform no longer serves them; use
|
|
69
|
+
`identity.manageMethods` `moveMethod` and `unlink`), and the `link` op of `identity.manageMethods` (400
|
|
70
|
+
`InvalidRequest`). Its `notices` list is unused and always empty: the platform emails every notice itself.
|
|
71
|
+
|
|
72
|
+
### Fixed
|
|
73
|
+
|
|
74
|
+
- `useEvent`'s `reload()` no longer drops the read still in flight for the same uri. An app that reloaded
|
|
75
|
+
faster than `getVersions` answered (a change stream nudging every 200 ms against 300 ms reads) never saw an
|
|
76
|
+
answer, so a record `put` answered pending never flipped to its curated version. A read in flight now lands
|
|
77
|
+
unless a newer read of the same uri landed first, so the newest answer wins. Changing the uri still discards
|
|
78
|
+
the previous uri's read. 0.4.0 has the same bug.
|
|
79
|
+
|
|
6
80
|
## 0.4.0 (2026-11-14)
|
|
7
81
|
|
|
8
82
|
npm 0.4.0 and crate 0.4.0 are built from the same commit. Lexicons `v0.1.22-techne.69` to `v0.1.22-techne.80`
|
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Every import goes through the package's `exports`, so the resolver has to read t
|
|
|
26
26
|
| `techne-sdk/react` | `TechneProvider` / `useTechne` (the client in React), and `useEvent(uri)`: one commons event or place as its versions, with the check's verdict (React only) |
|
|
27
27
|
| `techne-sdk/react/query` | the client's reads as hooks over TanStack Query (`useRecordQuery`, `useRecord`, `useVersions`, `defaultQueryClient`); needs `@tanstack/react-query` |
|
|
28
28
|
| `techne-sdk/versions` | the same state without React: `eventState`, `verifyAnswer`, version labels |
|
|
29
|
-
| `techne-sdk/auth` | sign-in ("Sign in with Techne"): `signIn`, `signUp`, `restore`, `signOut`, `clientMetadata`, `scopes`, `appKey`, `appSpace` (browser OAuth); the account page: `openAccountSettings`, `accountSettingsUrl` |
|
|
29
|
+
| `techne-sdk/auth` | sign-in ("Sign in with Techne"): `signIn`, `signUp`, `restore`, `signOut`, `clientMetadata`, `scopes`, `appKey`, `appSpace`, `ownAppSpace`, `WHOLE_STORE` (browser OAuth); the account page: `openAccountSettings`, `accountSettingsUrl` |
|
|
30
30
|
| `techne-sdk/connect` | `connect(session, platform?)` / `connectHosted(did, fetchHandler)` / `connectAnonymous(platform?)`: the client over one session, with its reads (`query`, `get`, `versions`, their options forms) and `put`; `bind(clients)` over clients made elsewhere |
|
|
31
31
|
| `techne-sdk/put` | `put(techne, records, { deletes })`: the one write, deletes included (public deletes hinted to the platform); `put(techne, [], { deletes })` for deletes alone |
|
|
32
32
|
| `techne-sdk/query` | the platform's generic queries: `listRecords`, `getRecords`, `compose` (several steps in one `composeRecords` call), hosts (`hostsOf`, `hostSteps`/`hostsFrom`) |
|
|
@@ -92,9 +92,9 @@ else {
|
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
- **Who:** with no `handle`, the sign-in starts at the default PDS (techne.town), which asks who you are. A bare name (`alice`) is a handle on the default handle domain. A full handle, a DID or a PDS URL from any PDS is used as given. `signUp({ clientId })` opens the PDS's create-account screen.
|
|
95
|
-
- **Scopes:** `scopes({ clientId })` is what it asks for by default, least privilege: `atproto`; the platform's `authPermissioned` permission set with the platform as its audience (the `permissioned.*` calls: private writes, reads and deletes); the app's own private space, `space:pub.techne.draft.space.private?skey=<appKey
|
|
95
|
+
- **Scopes:** `scopes({ clientId })` is what it asks for by default, least privilege: `atproto`; the platform's `authPermissioned` permission set with the platform as its audience (the `permissioned.*` calls: private writes, reads and deletes); the app's own private space by its exact key, `ownAppSpace(clientId)` = `space:pub.techne.draft.space.private?skey=<appKey>` (ask for your own space this way: a keyless `space.private` scope, or `skey=*`, is every app's private data, and the consent page shows it as a red warning); and an `rpc:<nsid>?aud=<platform>%23atproto_appview` scope for each generic read the SDK makes signed in: `query.listRecords`, `query.countRecords` and `query.getRecords` (`techne-sdk/query`, `put`'s curation answer) and `registry.getType` and `registry.listTypes`. The platform narrows those reads by the token's space scopes, so they reach public data and the app's own space. An app passes the types it writes as `types: [nsid, ...]`, and each adds a `repo:<nsid>` scope (create, update, delete), as the platform's own least-privilege list does, plus `rpc:pub.techne.draft.sync.indexRecord` so `put` can hint the platform what it wrote (a pending type's records are indexed no other way); without `types` the app writes no public record. `query.composeRecords` is not in the default (the SDK makes no such call); an app that calls it asks for `everything: 'read'`. Everything the person can reach (their personal space, their circles, beacons shared with them) is an opt-in: `everything: 'read'` adds the `authRead` set and `space:*?authority=*&action=read` (`WHOLE_STORE_READ`), `everything: 'write'` adds `authRead`, `authWrite`, `space:*?authority=*&manage=create&manage=update` (`WHOLE_STORE`) and a `repo:` scope for the public `community.lexicon.*` records (then our own public types need no `types` entry). The sets reach no space on Techne's PDS; the `space:` scope, asked for by name, does. The consent page shows those with a large warning; ask only if the app needs them. Pass the same `types` and `everything` to `signIn` and `clientMetadata`, since the PDS refuses a request beyond what the metadata declares. Pass `scope` to ask for other scopes, and pass it to both. An app that publishes its own community type (`pub.techne.draft.c.*`) as the signed-in person passes `publish: true`, which adds `rpc:pub.techne.draft.registry.publishType` (publishing a type is a public act). The type's NSID is the registry's answer, so its `repo:` scope can be asked for only after publishing: publish once (a setup sign-in with `publish: true`), then sign in with the published NSID in `types`.
|
|
96
96
|
- **A private record names its space:** a record of a type with no public home is written privately, and it must name the `space` it is for; `put` throws `PutError` (`InvalidRequest`) with nothing written when one does not, as the platform's `permissioned.putRecords` refuses it. A record only the person reads goes in their own `space.personal`: `` { record, space: `at://${did}/pub.techne.draft.space.personal/self` } ``. Public records name no space and go to the person's PDS.
|
|
97
|
-
- **The app's private space:** `appSpace(session.did, clientId)` is `at://{did}/pub.techne.draft.space.private/{appKey}`, where `appKey(clientId)` is the client id hashed (base32, lowercase, no padding, of its SHA-256; the platform's `sidecar_rkey`). Write there with `put(techne, [{ record, space: appSpace(did, clientId) }])` and read with `permissioned.listRecords({ space })`. Only that person reads it,
|
|
97
|
+
- **The app's private space:** `appSpace(session.did, clientId)` is `at://{did}/pub.techne.draft.space.private/{appKey}`, where `appKey(clientId)` is the client id hashed (base32, lowercase, no padding, of its SHA-256; the platform's `sidecar_rkey`). Write there with `put(techne, [{ record, space: appSpace(did, clientId) }])` and read with `permissioned.listRecords({ space })`. Only that person reads it, through a token whose `space:` scopes cover it or one with no scope claim at all (below). In development the client id is the loopback client's, `resolveClientId(options)` with the same options `signIn` took: it carries the scope, so it changes with the port, `types` and `everything`, and so does the space. Its scope names the space type without a key (an id cannot carry its own hash), which is every app's private space: Techne's PDS no longer narrows it to the loopback app's own, and the consent page shows the red every-app warning. That is development only; a hosted app asks with `ownAppSpace(clientId)`. The browser keeps one stored session per origin, so a page that switches between client ids (other `types`, another port's id) signs out first; `restore` hands back whichever session the origin holds.
|
|
98
98
|
- **Development:** on `localhost` or `127.0.0.1` you can leave `clientId` out. The SDK then uses atproto's loopback client, so you don't need to host anything.
|
|
99
99
|
- **Sessions:** the library refreshes tokens itself. `restore` returns the session, `null` when nobody is signed in, and rejects when a sign-in or refresh failed. `signOut({ clientId, session })` revokes the session. `onSessionDeleted` tells you when the library drops a session. A `state` passed to `signIn` comes back from `redirectState({ clientId })` on the page the redirect lands on.
|
|
100
100
|
- **Accounts on another server:** the Techne sign-in page also takes a handle from any server. When the account lives elsewhere, the page sends the person back to your redirect URI with `error=login_required&login_hint=<handle>`, and `restore` starts the sign-in again at that handle's server, with your `state` and the scope your client metadata declares; `restore` does not settle while the page navigates there. You write nothing for it; it is one reason to sign in through `signIn` and not hand-roll the OAuth. (The SDK sends its own `state`, `techne-sdk:<n>:<yours>`; `redirectState`, and the error `restore` rejects with, hand back yours.)
|
|
@@ -103,6 +103,15 @@ else {
|
|
|
103
103
|
|
|
104
104
|
**Before the Techne release:** the techne.town defaults (`TECHNE_PLATFORM_DID`, the techne.town PDS and handle domain) go live at the Techne release. Until then, `signIn()` without `pds` fails: pass `pds`, `plcUrl`, `handleDomain` and `platform` explicitly, and ask the Techne team for the current staging values.
|
|
105
105
|
|
|
106
|
+
## Where we differ from atproto
|
|
107
|
+
|
|
108
|
+
The platform follows atproto where atproto has an answer. These are the places it does not, today. The platform's builder guide (`get_app_guide`) has the same list.
|
|
109
|
+
|
|
110
|
+
- **Spaces.** A space has the shape of atproto proposal 0016: its address is `at://{authority}/{spaceType}/{key}`, each space type is a 0016 space declaration, and apps ask for spaces with 0016 `space:` scopes. atproto has not shipped 0016 yet. Read is all or nothing per space: there is no per-record read grant inside a space.
|
|
111
|
+
- **Collectives.** atproto has no account that several people write as. A collective here is an account whose key the platform holds. A person who manages it writes as it with `techne.writeAsCollective(input)` (`pub.techne.draft.identity.writeAsCollective`). It goes through their own PDS with `atproto-proxy: did:web:techne.computer#atproto_appview`, and the app's scope needs `rpc:pub.techne.draft.identity.writeAsCollective?aud=did:web:techne.computer%23atproto_appview`. `com.atproto.repo.applyWrites` with a collective's `repo`, sent through the person's PDS, is refused: the PDS answers it itself. The platform's own `applyWrites` still takes it for older app builds and is deprecated. Writes to one of the collective's private spaces go through `pub.techne.draft.permissioned.putRecords` (`put` with a `space`) and a `space:` scope that covers that space.
|
|
112
|
+
- **Tokens with no scope claim.** In 0016 a token reaches only the spaces its `space:` scopes name. Here a token that carries no scope claim at all reaches the whole store of its own user, every app's private space included: a token from a PDS that does not grant `space:` scopes, an agent token minted without a `space:` scope (public-only ones excepted), and the sessions Techne's own apps use today. An OAuth grant on techne.town always carries the claim, so one that names no `space:` scope reaches no space. This is temporary. It ends when Techne's own apps hold their own OAuth sessions (platform item 659c31df); after that, no claim means no space.
|
|
113
|
+
- **App approval.** 0016 lets an app into a space only when the person may read it and the space's authority has approved the app (`appAccess`). The platform checks only the first. The `appAccess` records and requests exist, but no read or write checks them yet, so a person's consent is enough for now.
|
|
114
|
+
|
|
106
115
|
## Layout
|
|
107
116
|
|
|
108
117
|
| Path | What |
|
package/dist/auth/app-key.d.ts
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
export declare function sha256(bytes: Uint8Array): Uint8Array;
|
|
3
3
|
/** The key of the app `clientId`'s private space: the platform's `sidecar_rkey(client_id)`. */
|
|
4
4
|
export declare function appKey(clientId: string): string;
|
|
5
|
+
/** The 0016 scope for the app `clientId`'s own private space, by its exact key:
|
|
6
|
+
* `space:pub.techne.draft.space.private?skey=<appKey(clientId)>`, what {@link scopes} asks for by default.
|
|
7
|
+
* Ask for your own space this way. A keyless `space:pub.techne.draft.space.private` (or `skey=*`) is the
|
|
8
|
+
* private space of every app the person uses, and the consent page warns on it in red. */
|
|
9
|
+
export declare function ownAppSpace(clientId: string): string;
|
|
5
10
|
/** The address of `did`'s private space for the app `clientId`: `at://{did}/pub.techne.draft.space.private/{appKey}`,
|
|
6
11
|
* the `space` a `put` or `permissioned.listRecords` names. In development (the loopback client) pass the
|
|
7
12
|
* loopback client id, `resolveClientId(options)`. */
|
package/dist/auth/app-key.js
CHANGED
|
@@ -85,6 +85,13 @@ export function appKey(clientId) {
|
|
|
85
85
|
throw new TypeError('techne-sdk/auth: appKey needs the client id');
|
|
86
86
|
return base32LowerNoPad(sha256(new TextEncoder().encode(clientId)));
|
|
87
87
|
}
|
|
88
|
+
/** The 0016 scope for the app `clientId`'s own private space, by its exact key:
|
|
89
|
+
* `space:pub.techne.draft.space.private?skey=<appKey(clientId)>`, what {@link scopes} asks for by default.
|
|
90
|
+
* Ask for your own space this way. A keyless `space:pub.techne.draft.space.private` (or `skey=*`) is the
|
|
91
|
+
* private space of every app the person uses, and the consent page warns on it in red. */
|
|
92
|
+
export function ownAppSpace(clientId) {
|
|
93
|
+
return `space:${NSID.SPACE_PRIVATE}?skey=${appKey(clientId)}`;
|
|
94
|
+
}
|
|
88
95
|
/** The address of `did`'s private space for the app `clientId`: `at://{did}/pub.techne.draft.space.private/{appKey}`,
|
|
89
96
|
* the `space` a `put` or `permissioned.listRecords` names. In development (the loopback client) pass the
|
|
90
97
|
* loopback client id, `resolveClientId(options)`. */
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* What it asks for ({@link scopes}), least privilege by default: `atproto`; the platform's
|
|
15
15
|
* `authPermissioned` permission set with the platform's appview as its audience
|
|
16
16
|
* (`include:pub.techne.draft.authPermissioned?aud=<platform>%23atproto_appview`: the `permissioned.*` calls);
|
|
17
|
-
* the app's own private space, `space:pub.techne.draft.space.private?skey=<appKey>` ({@link
|
|
18
|
-
* client id hashed, so the scope names this app's space and no other); `rpc:<nsid>?aud=<platform>%23atproto_appview`
|
|
17
|
+
* the app's own private space, `space:pub.techne.draft.space.private?skey=<appKey>` ({@link ownAppSpace};
|
|
18
|
+
* {@link appKey}: the client id hashed, so the scope names this app's space and no other); `rpc:<nsid>?aud=<platform>%23atproto_appview`
|
|
19
19
|
* for each generic read the SDK makes signed in (`query.listRecords`, `countRecords` and
|
|
20
20
|
* `getRecords`, behind `techne-sdk/query` and `put`'s curation read, and `registry.getType` and `listTypes`),
|
|
21
21
|
* which the platform narrows by the token's space scopes to public data and the app's own space; and one `repo:<nsid>` scope
|
|
@@ -24,10 +24,11 @@
|
|
|
24
24
|
* type minted after it), with `rpc:pub.techne.draft.sync.indexRecord` at the platform so `put` can hint
|
|
25
25
|
* what it wrote.
|
|
26
26
|
* Everything the person can reach (their personal space, their circles, beacons
|
|
27
|
-
* shared with them) is an opt-in, `everything: 'read'` (the `authRead` set
|
|
28
|
-
* (`authRead` and `authWrite`, plus a `repo:` scope for our
|
|
29
|
-
* `community.lexicon.*`, from the placement manifest,
|
|
30
|
-
*
|
|
27
|
+
* shared with them) is an opt-in, `everything: 'read'` (the `authRead` set and {@link WHOLE_STORE_READ})
|
|
28
|
+
* or `everything: 'write'` (`authRead` and `authWrite`, {@link WHOLE_STORE}, plus a `repo:` scope for our
|
|
29
|
+
* public homes outside our namespace, `community.lexicon.*`, from the placement manifest,
|
|
30
|
+
* `placement.gen.ts`). The sets reach no space on the Techne ePDS; the `space:` scope, asked for by name,
|
|
31
|
+
* does. The consent page shows those with a large warning: they include what other apps keep private. Pass the same options to {@link clientMetadata} and {@link signIn}: the PDS refuses
|
|
31
32
|
* a request beyond what the metadata declares. The platform is {@link TECHNE_PLATFORM_DID} unless a
|
|
32
33
|
* `platform` option names another (a test deployment's did:plc).
|
|
33
34
|
*
|
|
@@ -41,8 +42,8 @@
|
|
|
41
42
|
* On localhost (or 127.0.0.1) the client is atproto's loopback client
|
|
42
43
|
* (`http://localhost?redirect_uri=http://127.0.0.1:<port>/&scope=…`), with or without a client id, so an app
|
|
43
44
|
* runs in development with nothing hosted. A page elsewhere with no client id cannot sign in. The loopback
|
|
44
|
-
* id carries its scope, so its private-space scope names no key
|
|
45
|
-
* private-data warning
|
|
45
|
+
* id carries its scope, so its private-space scope names no key: that is every app's private space, and
|
|
46
|
+
* the consent page shows it as the red private-data warning; its {@link appSpace} is keyed by the whole id ({@link resolveClientId} with the
|
|
46
47
|
* same options as {@link signIn}), which changes with the port and the scope.
|
|
47
48
|
*
|
|
48
49
|
* Restore and refresh. {@link restore} is the library's `init()`: it finishes a sign-in when the page is
|
|
@@ -75,7 +76,7 @@ import type { AuthorizeOptions, OAuthSession } from '@atproto/oauth-client-brows
|
|
|
75
76
|
import { type OAuthClientMetadataInput } from '@atproto/oauth-types';
|
|
76
77
|
import { TECHNE_PLATFORM_DID } from '../platform.js';
|
|
77
78
|
import { TECHNE_TOWN, TECHNE_TOWN_PDS } from './hosts.js';
|
|
78
|
-
export { appKey, appSpace } from './app-key.js';
|
|
79
|
+
export { appKey, appSpace, ownAppSpace } from './app-key.js';
|
|
79
80
|
export { accountSettingsUrl, openAccountSettings, type AccountSection, type AccountSettingsOptions, type OpenAccountSettingsOptions } from './account.js';
|
|
80
81
|
export { TECHNE_PLATFORM_DID };
|
|
81
82
|
export type { OAuthSession };
|
|
@@ -138,9 +139,16 @@ export interface ClientOptions {
|
|
|
138
139
|
* `include:<nsid>?aud=<platform>%23atproto_appview`. {@link TECHNE_PLATFORM_DID} by default; another
|
|
139
140
|
* platform (a local stack, a test deployment) passes its own DID. */
|
|
140
141
|
export declare function includeScope(nsid: string, platform?: string): string;
|
|
141
|
-
/** The opt-in to everything the person can reach: `'read'` adds the platform's `authRead` set
|
|
142
|
-
* `
|
|
142
|
+
/** The opt-in to everything the person can reach: `'read'` adds the platform's `authRead` set and
|
|
143
|
+
* {@link WHOLE_STORE_READ}, `'write'` `authRead`, `authWrite` and {@link WHOLE_STORE} (and the `repo:` scope
|
|
144
|
+
* for our public `community.lexicon.*` homes). The sets carry no space reach; the `space:` scope does. */
|
|
143
145
|
export type Everything = 'read' | 'write';
|
|
146
|
+
/** The 0016 `space:` scope over every space the person can reach, every app's private space included, with
|
|
147
|
+
* `manage=create` and `manage=update`, making spaces and changing their settings (`everything: 'write'`): the
|
|
148
|
+
* string our own apps (Beacon, Commons) declare. */
|
|
149
|
+
export declare const WHOLE_STORE = "space:*?authority=*&manage=create&manage=update";
|
|
150
|
+
/** The whole store, read only (`everything: 'read'`). */
|
|
151
|
+
export declare const WHOLE_STORE_READ = "space:*?authority=*&action=read";
|
|
144
152
|
/** What {@link scopes} takes. */
|
|
145
153
|
export interface ScopesOptions {
|
|
146
154
|
/** The app's client id: the key of its private space ({@link appKey}). */
|
package/dist/auth/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import { buildAtprotoLoopbackClientId, isLoopbackHost } from '@atproto/oauth-typ
|
|
|
2
2
|
import { isValidDid, isValidHandle, isValidNsid } from '@atproto/syntax';
|
|
3
3
|
import { NSID } from '../generated/nsid.js';
|
|
4
4
|
import { appviewRef, TECHNE_PLATFORM_DID } from '../platform.js';
|
|
5
|
-
import {
|
|
5
|
+
import { ownAppSpace } from './app-key.js';
|
|
6
6
|
import { TECHNE_TOWN, TECHNE_TOWN_PDS } from './hosts.js';
|
|
7
7
|
import { PUBLIC_HOMES } from './placement.gen.js';
|
|
8
|
-
export { appKey, appSpace } from './app-key.js';
|
|
8
|
+
export { appKey, appSpace, ownAppSpace } from './app-key.js';
|
|
9
9
|
export { accountSettingsUrl, openAccountSettings } from './account.js';
|
|
10
10
|
export { TECHNE_PLATFORM_DID };
|
|
11
11
|
export { TECHNE_TOWN, TECHNE_TOWN_PDS };
|
|
@@ -34,6 +34,12 @@ export function includeScope(nsid, platform = TECHNE_PLATFORM_DID) {
|
|
|
34
34
|
}
|
|
35
35
|
/** `platform`'s appview as a scope's `aud` value (its `#` encoded). */
|
|
36
36
|
const audParam = (platform) => appviewRef(platform).replace('#', '%23');
|
|
37
|
+
/** The 0016 `space:` scope over every space the person can reach, every app's private space included, with
|
|
38
|
+
* `manage=create` and `manage=update`, making spaces and changing their settings (`everything: 'write'`): the
|
|
39
|
+
* string our own apps (Beacon, Commons) declare. */
|
|
40
|
+
export const WHOLE_STORE = 'space:*?authority=*&manage=create&manage=update';
|
|
41
|
+
/** The whole store, read only (`everything: 'read'`). */
|
|
42
|
+
export const WHOLE_STORE_READ = 'space:*?authority=*&action=read';
|
|
37
43
|
/** The platform's generic reads the SDK makes signed in (`techne-sdk/query`, `put`'s curation read through
|
|
38
44
|
* `getRecords`) and the registry reads: one `rpc:` scope each in the default {@link scopes}, so they work
|
|
39
45
|
* without `authRead`. The platform narrows them by the token's space scopes (public data and the app's
|
|
@@ -52,9 +58,9 @@ const READ_METHODS = [
|
|
|
52
58
|
export function scopes(o) {
|
|
53
59
|
if (!o?.clientId)
|
|
54
60
|
throw new TypeError('techne-sdk/auth: scopes needs the client id (its private space is keyed by it)');
|
|
55
|
-
return scopeList(o,
|
|
61
|
+
return scopeList(o, ownAppSpace(o.clientId));
|
|
56
62
|
}
|
|
57
|
-
/** {@link scopes}, with `space` the private-space scope
|
|
63
|
+
/** {@link scopes}, with `space` the private-space scope: {@link ownAppSpace}, or the keyless one for the
|
|
58
64
|
* loopback client (whose id is built from its scope, so the scope cannot name the id's hash). */
|
|
59
65
|
function scopeList({ platform = TECHNE_PLATFORM_DID, types = [], everything, publish }, space) {
|
|
60
66
|
if (everything !== undefined && everything !== 'read' && everything !== 'write') {
|
|
@@ -71,11 +77,13 @@ function scopeList({ platform = TECHNE_PLATFORM_DID, types = [], everything, pub
|
|
|
71
77
|
return [
|
|
72
78
|
'atproto',
|
|
73
79
|
includeScope(NSID.AUTH_PERMISSIONED, platform),
|
|
74
|
-
|
|
80
|
+
space,
|
|
75
81
|
// Signed-in reads (query, put's curation read, the registry); kept with authRead, which lacks the registry.
|
|
76
82
|
...READ_METHODS.map((m) => `rpc:${m}?aud=${aud}`),
|
|
77
83
|
...(everything ? [includeScope(NSID.AUTH_READ, platform)] : []),
|
|
78
84
|
...(write ? [includeScope(NSID.AUTH_WRITE, platform)] : []),
|
|
85
|
+
// The sets reach no space: the opt-in names the whole store by its `space:` scope.
|
|
86
|
+
...(everything ? [write ? WHOLE_STORE : WHOLE_STORE_READ] : []),
|
|
79
87
|
...(community.length ? [repoScope(community)] : []),
|
|
80
88
|
...own.map((t) => repoScope([t])),
|
|
81
89
|
// `put` hints each public write to the platform (the only way a pending type's records are indexed);
|
|
@@ -92,12 +100,12 @@ function repoScope(collections) {
|
|
|
92
100
|
return collections.length === 1 ? `repo:${collections[0]}?${actions}` : `repo?${collections.map((c) => `collection=${c}`).join('&')}&${actions}`;
|
|
93
101
|
}
|
|
94
102
|
/** The scope string a client asks for: `scope` as given, else the default with `space` as the private-space
|
|
95
|
-
* scope
|
|
96
|
-
* it cannot carry the id's own hash
|
|
97
|
-
* key names, the loopback id's hash). */
|
|
103
|
+
* scope: {@link ownAppSpace}, or {@link LOOPBACK_SPACE} for the loopback client (its id carries its scope,
|
|
104
|
+
* so it cannot carry the id's own hash). */
|
|
98
105
|
const scopeString = (o, space) => (typeof o.scope === 'string' ? o.scope : (o.scope ?? scopeList(o, space)).join(' '));
|
|
99
|
-
/** The private-space scope
|
|
100
|
-
|
|
106
|
+
/** The loopback client's private-space scope: keyless, so every app's private space (development only;
|
|
107
|
+
* the consent page shows it as the red warning). */
|
|
108
|
+
const LOOPBACK_SPACE = `space:${NSID.SPACE_PRIVATE}`;
|
|
101
109
|
/** The client-metadata document an app serves at its client id: a public browser client (no secret,
|
|
102
110
|
* DPoP-bound tokens), asking for {@link scopes} by default. */
|
|
103
111
|
export function clientMetadata(o) {
|
|
@@ -114,7 +122,7 @@ export function clientMetadata(o) {
|
|
|
114
122
|
dpop_bound_access_tokens: true,
|
|
115
123
|
grant_types: ['authorization_code', 'refresh_token'],
|
|
116
124
|
response_types: ['code'],
|
|
117
|
-
scope: scopeString(o,
|
|
125
|
+
scope: scopeString(o, ownAppSpace(o.clientId)),
|
|
118
126
|
redirect_uris: o.redirectUris ?? [`${url.origin}/`],
|
|
119
127
|
};
|
|
120
128
|
}
|
|
@@ -125,12 +133,12 @@ function resolveClient(o) {
|
|
|
125
133
|
if (location && isLoopbackHost(location.hostname)) {
|
|
126
134
|
const host = location.hostname === 'localhost' ? '127.0.0.1' : location.hostname;
|
|
127
135
|
const redirect = `http://${host}${location.port ? `:${location.port}` : ''}/`;
|
|
128
|
-
const scope = scopeString(o,
|
|
136
|
+
const scope = scopeString(o, LOOPBACK_SPACE);
|
|
129
137
|
return { clientId: buildAtprotoLoopbackClientId({ scope, redirect_uris: [redirect] }), scope };
|
|
130
138
|
}
|
|
131
139
|
if (!o.clientId)
|
|
132
140
|
throw new Error('techne-sdk/auth: no clientId (the https URL of the client metadata the app serves); only a localhost page may leave it out');
|
|
133
|
-
return { clientId: o.clientId, scope: scopeString(o,
|
|
141
|
+
return { clientId: o.clientId, scope: scopeString(o, ownAppSpace(o.clientId)) };
|
|
134
142
|
}
|
|
135
143
|
/** The client id a call signs in as: the loopback client on a loopback page or with no client id, else
|
|
136
144
|
* `clientId`. Its {@link appSpace} is the app's private space. */
|