techne-sdk 0.3.0 → 0.3.1

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 CHANGED
@@ -3,6 +3,30 @@
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
+ - **A private record must name its space.** The platform now refuses a `permissioned.putRecord(s)` write
9
+ with no `space` (400 `InvalidRequest`; lucian 2026-11-09). `put` checks first: a record that is written
10
+ privately (a type with no public home) and names no `space` throws `PutError` with `InvalidRequest`, and
11
+ nothing is written. A record only the person reads goes in their own `space.personal`
12
+ (`at://{did}/pub.techne.draft.space.personal/self`). Public records are unchanged. The generated types
13
+ follow when the lexicons pin moves to the tag that carries the change (v0.1.22-techne.62).
14
+
15
+ ## 0.3.1
16
+
17
+ Fixes found by a developer building on 0.3.0 from the public docs alone (techne.computer, 2026-11-09).
18
+
19
+ - **`connect(session, platform)` works with an atproto `OAuthSession`.** It passed `session.fetchHandler`
20
+ on unbound, and an `OAuthSession`'s is a method that reads its own token set, so the first call threw
21
+ `Cannot read properties of undefined (reading 'getTokenSet')`. It now calls it on the session. The doc
22
+ comment names the platform DID as `did:web:techne.computer` (`TECHNE_PLATFORM_DID`).
23
+ - **`put` writes a community draft (`pub.techne.draft.c.*`) to the user's repo.** It counted the community
24
+ namespace as the platform's own and sent those records to the private batch write. A community draft
25
+ record is public now, like another app's own type; with a `space` it is private, as any record.
26
+ - **`scopes({ publish: true })`** (and `signIn`, `clientMetadata`): adds
27
+ `rpc:pub.techne.draft.registry.publishType` at the platform, so an app can publish its own community
28
+ type as the signed-in person. Off by default.
29
+
6
30
  ## 0.3.0
7
31
 
8
32
  Built on lexicons `agent/devplatform` b10ae5d and the platform's published API at regenOS `e3814f0f6`
package/README.md CHANGED
@@ -91,8 +91,9 @@ else {
91
91
  ```
92
92
 
93
93
  - **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.
94
- - **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>`; 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, `everything: 'write'` adds `authRead`, `authWrite` and a `repo:` scope for the public `community.lexicon.*` records (then our own public types need no `types` entry). 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.
95
- - **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, and only through this app. 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), so the consent page shows the private-data warning; the platform still serves the space only for the app its key names.
94
+ - **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>`; 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, `everything: 'write'` adds `authRead`, `authWrite` and a `repo:` scope for the public `community.lexicon.*` records (then our own public types need no `types` entry). 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`.
95
+ - **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.
96
+ - **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, and only through this app. 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); Techne's PDS reads that keyless scope from a loopback client as its own space, adds the key when it calls the platform, and shows the own-space line on the consent page. 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.
96
97
  - **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.
97
98
  - **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.
98
99
  - **Another deployment:** `platform` names the platform's DID (`TECHNE_PLATFORM_DID` by default). `pds`, `plcUrl` and `handleDomain` name the PDS people sign in at, its PLC directory and its handle domain. Pass them the same way to every call.
@@ -106,6 +106,8 @@ export interface ClientOptions {
106
106
  types?: readonly string[];
107
107
  /** Ask for everything the person can reach, for the default {@link scopes} (ignored with `scope`). */
108
108
  everything?: Everything;
109
+ /** Ask to publish community types, for the default {@link scopes} (ignored with `scope`). */
110
+ publish?: boolean;
109
111
  /** The page's location; `globalThis.location` by default. */
110
112
  location?: Pick<Location, 'protocol' | 'hostname' | 'port'>;
111
113
  /** The home PDS: where handles resolve, and where a sign-in with no handle and every sign-up start.
@@ -134,6 +136,9 @@ export interface ScopesOptions {
134
136
  types?: readonly string[];
135
137
  /** Everything the person can reach, an opt-in (see {@link Everything}); none by default. */
136
138
  everything?: Everything;
139
+ /** Ask to publish community types (`registry.publishType`), for an app that publishes its own type
140
+ * (`pub.techne.draft.c.*`) as the signed-in person. Off by default. */
141
+ publish?: boolean;
137
142
  }
138
143
  /** The scopes signIn asks for by default (see the module doc): least privilege, the permissioned calls,
139
144
  * the app's own private space, an `rpc` scope per read in `READ_METHODS` and a `repo` scope per type
@@ -155,6 +160,8 @@ export interface ClientMetadataOptions {
155
160
  types?: readonly string[];
156
161
  /** As {@link ClientOptions.everything}. */
157
162
  everything?: Everything;
163
+ /** As {@link ClientOptions.publish}. */
164
+ publish?: boolean;
158
165
  platform?: string;
159
166
  }
160
167
  /** The client-metadata document an app serves at its client id: a public browser client (no secret,
@@ -57,7 +57,7 @@ export function scopes(o) {
57
57
  }
58
58
  /** {@link scopes}, with `space` the private-space scope's query: the app's key, or nothing for the
59
59
  * loopback client (whose id is built from its scope, so the scope cannot name the id's hash). */
60
- function scopeList({ platform = TECHNE_PLATFORM_DID, types = [], everything }, space) {
60
+ function scopeList({ platform = TECHNE_PLATFORM_DID, types = [], everything, publish }, space) {
61
61
  if (everything !== undefined && everything !== 'read' && everything !== 'write') {
62
62
  throw new TypeError(`techne-sdk/auth: everything is 'read' or 'write' (got ${JSON.stringify(everything)})`);
63
63
  }
@@ -82,6 +82,8 @@ function scopeList({ platform = TECHNE_PLATFORM_DID, types = [], everything }, s
82
82
  // `put` hints each public write to the platform (the only way a pending type's records are indexed);
83
83
  // authWrite carries that call, so without it an app that writes public types asks for it alone.
84
84
  ...(own.length && !write ? [`rpc:${NSID.SYNC_INDEX_RECORD}?aud=${aud}`] : []),
85
+ // Publishing a community type: a public act, asked for only by an app that does it.
86
+ ...(publish ? [`rpc:${NSID.REGISTRY_PUBLISH_TYPE}?aud=${aud}`] : []),
85
87
  ];
86
88
  }
87
89
  /** A `repo` scope for `collections`, every action (regenOS `regenos_appview::nsid_rewrite::repo_scope`,
package/dist/connect.d.ts CHANGED
@@ -26,7 +26,10 @@ export interface Techne {
26
26
  /** The platform, reached through the user's PDS (`atproto-proxy`). */
27
27
  platform: AtpBaseClient;
28
28
  }
29
- /** The clients for `session`, with `platform` the platform's service DID: its `did:plc` (techne P13.6), whose document names the `#atproto_appview` endpoint, so a host move changes nothing here. */
29
+ /** The clients for `session`, with `platform` the platform's service DID (`TECHNE_PLATFORM_DID`,
30
+ * `did:web:techne.computer`, from `techne-sdk/auth`), whose document names the `#atproto_appview` endpoint,
31
+ * so a host move changes nothing here. `session.fetchHandler` is called on `session`: an OAuthSession's is a
32
+ * method that reads its own token set. */
30
33
  export declare function connect(session: Session, platform: string): Techne;
31
34
  /**
32
35
  * The clients for an app that holds only a platform session (techne P19.1, option (a)): the platform is
package/dist/connect.js CHANGED
@@ -1,10 +1,14 @@
1
1
  import { AtpBaseClient } from './generated/index.js';
2
2
  import { appviewRef } from './platform.js';
3
- /** The clients for `session`, with `platform` the platform's service DID: its `did:plc` (techne P13.6), whose document names the `#atproto_appview` endpoint, so a host move changes nothing here. */
3
+ /** The clients for `session`, with `platform` the platform's service DID (`TECHNE_PLATFORM_DID`,
4
+ * `did:web:techne.computer`, from `techne-sdk/auth`), whose document names the `#atproto_appview` endpoint,
5
+ * so a host move changes nothing here. `session.fetchHandler` is called on `session`: an OAuthSession's is a
6
+ * method that reads its own token set. */
4
7
  export function connect(session, platform) {
5
- const proxied = new AtpBaseClient(session.fetchHandler);
8
+ const fetchHandler = (url, init) => session.fetchHandler(url, init);
9
+ const proxied = new AtpBaseClient(fetchHandler);
6
10
  proxied.setHeader('atproto-proxy', appviewRef(platform));
7
- return { did: session.did, pds: new AtpBaseClient(session.fetchHandler), platform: proxied };
11
+ return { did: session.did, pds: new AtpBaseClient(fetchHandler), platform: proxied };
8
12
  }
9
13
  /**
10
14
  * The clients for an app that holds only a platform session (techne P19.1, option (a)): the platform is
@@ -13,7 +13,11 @@ export interface PutRecord {
13
13
  record: AnyRecord;
14
14
  /** Its record key; derived when absent (see the module doc). */
15
15
  rkey?: string;
16
- /** The space it is placed in (`at://{authority}/{spaceType}/{skey}`); a record with a space is private. */
16
+ /**
17
+ * The space it is placed in (`at://{authority}/{spaceType}/{skey}`); a record with a space is private.
18
+ * Required for a private record (a lexicon type with no public home): a record only you read goes in
19
+ * your own `space.personal`. A public record names none.
20
+ */
17
21
  space?: string;
18
22
  }
19
23
  /** One write, as planned. */
package/dist/put/index.js CHANGED
@@ -8,9 +8,13 @@
8
8
  * order: private records (a `space` named, or a lexicon type with no public home) first, public last;
9
9
  * a type the platform has no lexicon for (another app's own record) is public: it goes to the user's
10
10
  * PDS and the platform answers it `invalid`, "not curated: no lexicon" (P18.1). An unknown name in
11
- * the platform's own namespace (a typo after it, an old name, other letter case) stays private instead;
11
+ * the platform's own namespace (a typo after it, an old name, other letter case) stays private instead
12
+ * (a community draft, `pub.techne.draft.c.*`, is not the platform's: public, like another app's type);
12
13
  * 2. writes the private ones with the platform's private batch write (`permissioned.putRecords`,
13
- * through the user's PDS) and stops if any is refused;
14
+ * through the user's PDS) and stops if any is refused. Every private record names its `space`: one
15
+ * that names none throws {@link PutError} (`InvalidRequest`) with nothing written, as the platform
16
+ * refuses it. A record only the user reads goes in their own `space.personal`
17
+ * (`at://{did}/pub.techne.draft.space.personal/self`);
14
18
  * 3. writes the public ones to the user's PDS in one atomic `com.atproto.repo.applyWrites`;
15
19
  * 4. with `deletes`: deletes the private ones, one `permissioned.deleteRecord` each (below);
16
20
  * 5. hints each public record (`sync.indexRecord`, signed as the user through the PDS) so the platform
@@ -62,6 +66,11 @@ import { call } from '../wasm/index.js';
62
66
  import { contactConflicts, ContactConflictError, storedContacts } from './contacts.js';
63
67
  import { getRecordsAnswer } from '../query/index.js';
64
68
  export { contactConflicts, ContactConflictError } from './contacts.js';
69
+ /** Why a private record with no space is not written (lucian 2026-11-09): the platform's private write
70
+ * needs a space, as `permissioned.putRecords` refuses a write that names none. */
71
+ function noSpace(did, collection) {
72
+ return `names no space. ${collection} is written privately, so name the space it is for: a record only you read goes in your own space.personal (at://${did}/${NSID.SPACE_PERSONAL}/self). Public records are written with com.atproto.repo.putRecord.`;
73
+ }
65
74
  /** A put whose private batch write refused some records: nothing public was written. */
66
75
  export class PutError extends Error {
67
76
  refused;
@@ -91,6 +100,9 @@ export async function put(techne, records, options = {}) {
91
100
  const privates = writes.filter((w) => w.private);
92
101
  const publics = writes.filter((w) => !w.private);
93
102
  const publicDeletes = deletes.filter((d) => !d.private);
103
+ const unplaced = privates.filter((w) => !w.space);
104
+ if (unplaced.length)
105
+ throw new PutError(unplaced.map((w) => ({ uri: w.uri, error: 'InvalidRequest', message: noSpace(did, w.collection) })));
94
106
  const contacts = writes.filter((w) => w.collection === NSID.CONTACT);
95
107
  if (contacts.length) {
96
108
  const gone = new Set(deletes.map((d) => d.uri));
@@ -101,7 +113,8 @@ export async function put(techne, records, options = {}) {
101
113
  if (privates.length) {
102
114
  const { data } = await techne.platform.pub.techne.draft.permissioned.putRecords({
103
115
  repo: did,
104
- writes: privates.map(({ collection, rkey, record, space }) => ({ collection, rkey, record, space })),
116
+ // Every private write names its space (checked above).
117
+ writes: privates.map(({ collection, rkey, record, space }) => ({ collection, rkey, record, space: space })),
105
118
  });
106
119
  const refused = data.results.flatMap((r, i) => r.$type === NSID.PERMISSIONED_PUT_RECORDS_WRITE_ERROR ? [{ uri: privates[i].uri, error: String(r.error), message: String(r.message) }] : []);
107
120
  if (refused.length)