techne-sdk 0.11.0 → 0.12.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 CHANGED
@@ -3,6 +3,36 @@
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
+ ## 0.12.0 (2026-11-26)
7
+
8
+ A `Query` names its view: a break, so this is a major-line version (RELEASING.md). Ship after the platform
9
+ that reads `view` is on prod (an older platform ignores `view` and refuses the `any` form).
10
+
11
+ npm 0.12.0 and crate 0.12.0 are built from the same commit. The crate's code is unchanged since 0.10.0; it
12
+ moves to check 0.3.35, the check the platform pins, so the commons can pin platform `main` again.
13
+
14
+ ### Changed (breaking)
15
+
16
+ - Migrate: `curated: true` becomes `view: 'curated'`, `curated: false` becomes `view: 'asWritten'`, and a query
17
+ that set neither picks one (the platform's old default was `curated` for an unscoped query).
18
+ - `Query` is a union type alias, no longer an interface: `interface X extends Query` no longer compiles (use
19
+ `type X = Query & {…}`). Its non-branch fields are the exported `QueryOptions`. The `any` form takes 1 to 8
20
+ branches; an empty `any` is a type error.
21
+ - **`Query.view` is required** (`'curated'` or `'asWritten'`, type `View`), or the `any` form gives each branch
22
+ its own (`{ any: [{ view, where }, …] }`, type `QueryBranch`). `curated` is gone from the type; the platform
23
+ refuses a query naming no view (`ViewRequired`) and a curated read of a type no curator covers (`NotCurated`).
24
+ - `PROVENANCE_OF_QUERY`, `MIRROR_SIDECARS_QUERY`, `HOST_SOURCES_QUERY` and `CURATED_FROM_QUERY` name `asWritten`.
25
+
26
+ ### Added
27
+
28
+ - **Items carry `author`**, the DID whose repo holds the record.
29
+
30
+ ### Inputs
31
+
32
+ - **Lexicons `v0.1.22-techne.99`, check crate `techne-lexicon-check` 0.3.35** (the crate's dependency, exact).
33
+ - **Platform API at platform `main` `12fb349ec`**, the merge of the platform PR that reads `view` (same tree as `6f63db0f6`). New
34
+ method lexicons `social.scenius.listOwnLinkRedemptions` and `ackOwnLinkRedemptions` in `inputs/platform-api/`.
35
+
6
36
  ## 0.11.0 (2026-11-22)
7
37
 
8
38
  npm 0.11.0 changes `techne-sdk/session` only; no export is removed or renamed. Nothing under `crates/` changed
package/README.md CHANGED
@@ -29,7 +29,7 @@ Every import goes through the package's `exports`, so the resolver has to read t
29
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/session` | a session the app holds itself, for React Native as well as the browser (plain JS, no native module): phone sign-in through the platform's door (`startPhoneSignIn`, `finishPhoneSignIn`), `OwnSession` (`did` + `fetchHandler` for `connect`, refresh, `signOut`, the device credential's proofs), DPoP helpers; `adoptHeldSession` (deprecated) |
31
31
  | `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 |
32
- | `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
+ | `techne-sdk/put` | `put(techne, records, { deletes })`: the one write, deletes included (public deletes hinted to the platform); each of `records` is `{ record, rkey?, space? }` (`record` the body with its `$type`; `rkey` derived when absent: the lexicon's literal key, else a TID from the record's `createdAt` and CID, and with neither `put` throws before writing anything; `space` only for a private record); `put(techne, [], { deletes })` for deletes alone. Its `status` is never `valid`: `invalid` with the reason (not counted; `not curated: no lexicon`, another app's own type, is written all the same) or `pending` (not refused: indexed when the hint answered, so it reads back by URI, but not yet in the commons' curated view; a failed hint is `pending` too, and the record comes by the relay); `curation` says per record whether it is `curated`, `notCurated` (why) or still `pending`, and `{ wait: ms }` waits for the curated record |
33
33
  | `techne-sdk/query` | the platform's generic queries: `listRecords`, `getRecords`, `compose` (several steps in one `composeRecords` call), hosts (`hostsOf`, `hostSteps`/`hostsFrom`) |
34
34
  | `techne-sdk/links` | link tokens: create, redeem, check, revoke |
35
35
  | `techne-sdk/wasm` | the check itself: `validate`, `decide`, `verify` (`validate` knows the built-in lexicons only; a runtime type is checked by the platform on write) |
@@ -57,6 +57,82 @@ function Event({ uri }: { uri: string }) {
57
57
 
58
58
  Pass `{ claims }` too, and `verification` holds the check's answer for every record (valid, signer, chain verified).
59
59
 
60
+ ## Reading without signing in
61
+
62
+ Public records need no account. `connectAnonymous()` reads the platform directly (it resolves
63
+ `did:web:techne.computer` on the first read); `put` on it rejects.
64
+
65
+ ```ts
66
+ import { connectAnonymous } from 'techne-sdk/connect'
67
+ import type { Query } from 'techne-sdk/query'
68
+
69
+ const techne = connectAnonymous()
70
+ const near: Query = { view: 'curated', where: { all: [
71
+ { type: { is: 'pub.techne.draft.place' } },
72
+ { location: { near: { point: '40.015,-105.27', within: '2km' } } },
73
+ ] } }
74
+ let page = await techne.query(near, { limit: 10 })
75
+ for (;;) {
76
+ for (const item of page.items) console.log(item.uri, item.curated, item.record)
77
+ if (!page.cursor) break
78
+ page = await techne.query(near, { limit: 10, cursor: page.cursor })
79
+ }
80
+ ```
81
+
82
+ - **Paging:** `limit` defaults to 50. Keep it at 500 or less: `query` accepts up to 50000, but past 500 the
83
+ platform reads page after page and charges every row to your budget (below). Keep paging until `cursor` is absent: a page can be shorter than
84
+ `limit` and still have one. `{ count: true }` adds `count` and `capped` (counting stops at 1000).
85
+ - **Two views:** every query names its view, and there is no default (a query naming none is refused with
86
+ `ViewRequired`). `view: 'curated'` reads the commons' listed records: one curated record per thing, merged
87
+ from its sources by a curator the commons root trusts, moderated (an event only inside the supported areas).
88
+ A type no curator covers is refused with `NotCurated`, naming the type, rather than answered as an empty list.
89
+ `view: 'asWritten'` reads every public record as its author wrote it: each source copy and the curated record
90
+ (counts in this view hold both copies of a curated thing). A private record reads the same in both. To mix
91
+ them in one list, give each branch its own: `{ any: [{ view: 'curated', where: events }, { view:
92
+ 'asWritten', where: mine }] }`. Every item says whether it is `curated`, and its `author`. The platform
93
+ guide's "Two views" section says who curates and how versions merge.
94
+ - **Limits:** each statement times out after 5 s (`query` then throws a `ComposeStepError` with status 500 and a
95
+ message starting `query read:`); a `near` over a dense area can approach it, so page `near` small. `query` sends `composeRecords`, which has a row
96
+ budget per signed-in DID and answers 429 `RateLimitExceeded` past it; `query` retries twice, then throws.
97
+ Anonymous callers get one such budget per client IP only where the server is set up to know the client's IP
98
+ (the platform's `AUTH_RATE_LIMIT_CLIENT_IP`); where it is not, all anonymous callers share one budget ten times
99
+ that size, so another anonymous reader can use up yours.
100
+ - **Without the SDK:** `/xrpc/*` (and `/.well-known/did.json`) on the platform answers CORS for any origin, so a page can `fetch`
101
+ `https://techne.computer/xrpc/pub.techne.draft.query.listRecords?query=<JSON>&limit=10` directly. The routes
102
+ under `/xrpc/_*` (the agent consent flow and the change stream) are not methods and get no CORS. (CORS is live
103
+ on staging since 2026-11-24 and reaches techne.computer with the first platform release after that; until
104
+ then a browser page reads techne.computer through its own server.)
105
+
106
+ The builder guide's `reading-public-data` section (https://techne.computer/docs/reading-public-data.md) has the
107
+ query rules and the other read servers.
108
+
109
+ ## Scripts and agents
110
+
111
+ A script with no browser signs in with a password and hands the agent to `connect`, which takes anything with a
112
+ `did` and a `fetchHandler`:
113
+
114
+ ```ts
115
+ import { AtpAgent } from '@atproto/api'
116
+ import { connect } from 'techne-sdk/connect'
117
+
118
+ const agent = new AtpAgent({ service: 'https://<the account PDS>' })
119
+ await agent.login({ identifier: '<handle>', password: process.env.PASSWORD! })
120
+ const techne = connect(
121
+ { did: agent.assertDid, fetchHandler: (url, init) => agent.fetchHandler(url, init) },
122
+ 'did:web:techne.computer',
123
+ )
124
+ ```
125
+
126
+ Only an account with a password can do this; techne.town accounts sign in with a code and have no password they know. The guide's
127
+ `scripts-and-datasets` section covers testing and publishing a dataset (places, `source` sidecars at
128
+ `appKey(uri)` (it hashes any string, a record's AT-URI here), attribution, `publisher`).
129
+
130
+ ## In a browser
131
+
132
+ The package is ES modules plus WebAssembly. A bundler (Vite, esbuild, webpack 5) handles both. With no build
133
+ step, `import { connectAnonymous } from 'https://esm.sh/techne-sdk@<version>/connect'` loads it: about 75 modules,
134
+ 2.7 MB in all, the WebAssembly inlined in one 1.7 MB module.
135
+
60
136
  ## Types for any type
61
137
 
62
138
  The generated client covers the platform's own lexicons. For a community draft, a requested type or any other
@@ -100,7 +176,7 @@ else {
100
176
  - **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.
101
177
  - **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.)
102
178
  - **The account page and Delete account:** people manage their account (profile, ways to sign in, devices and apps, Delete account) on the account page at their PDS's sign-in host, never inside an app. `openAccountSettings()` opens it in a new tab; call it from the tap's handler. `openAccountSettings({ section: 'delete' })` opens it at Delete account: that is the link for Apple's account-deletion rule (the app still deletes its own data itself). There is no API that deletes an account. Sections are `'profile'`, `'methods'` and `'delete'`. Pass `session` (from `restore`) and it answers `false` without opening anything when the person signed in at another server, which has no Techne account page. Pass `open: (url) => …` to open it elsewhere (an in-app browser sheet in React Native). `accountSettingsUrl(options)` is the address alone. The host comes from the PDS's OAuth metadata, so a move of the sign-in host changes nothing for you. An app on a platform session (`connectHosted`) passes `techne` too, and the page opens already signed in through the platform's one-time link (`identity.openAccountPage`) where the platform and this SDK carry it; otherwise the page asks for a code.
103
- - **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.
179
+ - **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 `techne-sdk/auth` call that takes them (`signIn`, `signUp`, `restore`, `signOut`, `redirectState`, …): the OAuth client is made once per client id with the first call's values. `connect(session, platform)` takes only the platform: the user's PDS resolves its DID. `connectAnonymous(platform, { plcUrl })` takes the PLC directory too, since it resolves a did:plc platform itself.
104
180
 
105
181
  **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.
106
182
 
@@ -1,6 +1,7 @@
1
1
  /** SHA-256 (FIPS 180-4) of `bytes`. */
2
2
  export declare function sha256(bytes: Uint8Array): Uint8Array;
3
- /** The key of the app `clientId`'s private space: the platform's `sidecar_rkey(client_id)`. */
3
+ /** The key of the app `clientId`'s private space: the platform's `sidecar_rkey(client_id)`. It hashes any string the
4
+ * same way, so `appKey(uri)` is also a sidecar's key for the record at `uri` (a `pub.techne.draft.source`, say). */
4
5
  export declare function appKey(clientId: string): string;
5
6
  /** The 0016 scope for the app `clientId`'s own private space, by its exact key:
6
7
  * `space:pub.techne.draft.space.private?skey=<appKey(clientId)>`, what {@link scopes} asks for by default.
@@ -79,7 +79,8 @@ function base32LowerNoPad(bytes) {
79
79
  out += alphabet[(buffer << (5 - bits)) & 31];
80
80
  return out;
81
81
  }
82
- /** The key of the app `clientId`'s private space: the platform's `sidecar_rkey(client_id)`. */
82
+ /** The key of the app `clientId`'s private space: the platform's `sidecar_rkey(client_id)`. It hashes any string the
83
+ * same way, so `appKey(uri)` is also a sidecar's key for the record at `uri` (a `pub.techne.draft.source`, say). */
83
84
  export function appKey(clientId) {
84
85
  if (!clientId)
85
86
  throw new TypeError('techne-sdk/auth: appKey needs the client id');