techne-sdk 0.13.1 → 0.14.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,10 +3,43 @@
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.13.1 (unreleased)
6
+ ## 0.14.0 (2026-11-30)
7
7
 
8
- Inputs only. No export is added, removed or renamed, and no function changes. npm 0.13.1 and crate 0.13.1 are
9
- built from the same commit; the crate's code is unchanged and moves to check 0.3.37.
8
+ The sign-in form and the "Sign in with Techne" button. Needs the Techne sign-in page (ePDS) that reads a phone
9
+ `login_hint` and `epds_other_ways=1`: ePDS `main` `0831c41`, on prod since 2026-11-30. Exports are added; none
10
+ is removed or renamed, and no function changes meaning. npm only: nothing in the crate's code changed since
11
+ 0.13.1 (only its manifest `description`), so the crate stays 0.13.1.
12
+
13
+ ### Added
14
+
15
+ - **`techne-sdk/sign-in`: `mountSignIn(target, options)` and `mountSignInButton(target, options)`**, each
16
+ answering `{ unmount() }`. The form is the Techne sign-in card for any web page: your logo and name, Email and
17
+ Phone tabs (a country picker inside the card), "Send me a code", "Other ways to sign in" and "Powered by
18
+ Techne". It has one look for every app and keeps one size in every view. It lives in a shadow root, so no
19
+ styles leak either way. README: "The sign-in form".
20
+ - **`techne-sdk/react/sign-in`: `SignInForm` and `SignInButton`**, the same as React components.
21
+ - **`signIn` takes `email`, `phone` (E.164) or `otherWays: true`.** An address or number goes to the sign-in
22
+ page as `login_hint`, so the page sends the code and opens on the code step. `otherWays` opens the page
23
+ with "Other ways to sign in" already open (`epds_other_ways=1`). Both are set on the authorization URL,
24
+ because `@atproto/oauth-client` replaces a `login_hint` passed in its options with its own. The Techne
25
+ sign-in page reads the URL's `login_hint` before the PAR request's.
26
+ - **`OAuthClientLike` gains optional `authorize` and `abortRequest`** (BrowserOAuthClient has both). A client
27
+ injected with `setOAuthClientFactory` needs `authorize` for the three new options.
28
+ - **Dependency: `libphonenumber-js`** (`min` metadata), for the phone field. It is the same reading the
29
+ Techne sign-in page makes.
30
+
31
+ ### Fixed
32
+
33
+ - **`techne-sdk/catalog`: adopted lexicons group under their own authority.** `org.hypercerts.funding.receipt`
34
+ (and its query document) now have `group: 'org.hypercerts'`, and `app.certified.defs` and
35
+ `app.certified.signature.defs` have `group: 'app.certified'`; they had `'pub.techne'`. Every record's group is
36
+ now a prefix of its NSID. A browse list that grouped by `group` showed them under pub.techne.
37
+
38
+ ## 0.13.1 (2026-11-28)
39
+
40
+ Inputs. No export is added, removed or renamed, and no function
41
+ changes. npm 0.13.1 and crate 0.13.1 are built from the same commit; the crate's code is unchanged and moves to
42
+ check 0.3.37.
10
43
 
11
44
  ### Inputs
12
45
 
package/README.md CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  TechneSDK for apps on the Techne platform: sign in, `put`, query, `useEvent` and the read-time check.
4
4
 
5
+ Roadmap: [where Techne is heading](https://github.com/technefoundation/sdk/blob/main/.claude/skills/techne-platform/roadmap.md), shared by every Techne repo: what is live today, the agreed direction, and what is still open.
6
+
5
7
  - **npm:** one package, `techne-sdk`, with subpaths.
6
- - **Rust:** the crate `techne-sdk` (`crates/techne-sdk`). It holds the logic that must give the platform's answers exactly: the check, the version ranking (`eventState`) and `put`'s private-first, public-last plan. The npm package runs the same crate as WebAssembly, or as wasm2js on hosts without WebAssembly (Hermes). Opt-in features add the atproto plumbing services share (no platform crate either): `crypto` for service-auth JWTs, signed labels, record proofs and service-account passwords, and `net` for DID resolution, verified record fetches and PDS password sessions.
8
+ - **Rust:** the crate `techne-sdk` (`crates/techne-sdk`). It holds the logic that must give the platform's answers exactly: the check, the version ranking (`eventState`) and `put`'s private-first, public-last plan. The npm package runs the same crate as WebAssembly, or as wasm2js on hosts without WebAssembly (Hermes). Opt-in features add the atproto plumbing services share (no platform crate either): `crypto` for service-auth JWTs, signed labels, record proofs and service-account passwords, `net` for DID resolution, verified record fetches and PDS password sessions, and `tap` for the stock client of a Tap's `/channel`.
7
9
 
8
10
  The SDK depends on two things only: the published lexicons (the `lexicons` repo at a tag) and the platform's published API. It contains no platform code.
9
11
 
@@ -27,11 +29,13 @@ Every import goes through the package's `exports`, so the resolver has to read t
27
29
  | `techne-sdk/react/query` | the client's reads as hooks over TanStack Query (`useRecordQuery`, `useRecord`, `useVersions`, `defaultQueryClient`); needs `@tanstack/react-query` |
28
30
  | `techne-sdk/versions` | the same state without React: `eventState`, `verifyAnswer`, version labels |
29
31
  | `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` |
32
+ | `techne-sdk/sign-in` | the sign-in form and the "Sign in with Techne" button for any web page: `mountSignIn`, `mountSignInButton` (no framework; [below](#the-sign-in-form)) |
33
+ | `techne-sdk/react/sign-in` | the same as React components: `SignInForm`, `SignInButton` |
30
34
  | `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
35
  | `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
36
  | `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
37
  | `techne-sdk/query` | the platform's generic queries: `listRecords`, `getRecords`, `compose` (several steps in one `composeRecords` call), hosts (`hostsOf`, `hostSteps`/`hostsFrom`) |
34
- | `techne-sdk/links` | link tokens: create, redeem, check, revoke |
38
+ | `techne-sdk/links` | link tokens: create, reset, redeem, check, revoke, list your links for an app and target, and a link's redemptions |
35
39
  | `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) |
36
40
  | `techne-sdk/catalog` | the browsable lexicon catalog |
37
41
  | `techne-sdk/nsid`, `techne-sdk/nsid.json` | every NSID as a constant (`NSID`, `METHOD`) |
@@ -94,17 +98,12 @@ for (;;) {
94
98
  - **Limits:** each statement times out after 5 s (`query` then throws a `ComposeStepError` with status 500 and a
95
99
  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
100
  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.
101
+ Anonymous callers may share one budget; the guide's Limits section below says when.
100
102
  - **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.)
103
+ `https://techne.computer/xrpc/pub.techne.draft.query.listRecords?query=<JSON>&limit=10` directly.
105
104
 
106
105
  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.
106
+ query rules, the Limits and the other read servers.
108
107
 
109
108
  ## Scripts and agents
110
109
 
@@ -162,13 +161,13 @@ const metadata = clientMetadata({ clientId, clientName: 'Cafe finder' })
162
161
 
163
162
  // On every page load: finishes a sign-in when the page is the redirect back, else restores a kept session.
164
163
  const session = await restore({ clientId })
165
- if (!session) await signIn({ clientId, handle: 'alice' }) // alice.techne.town, once techne.town is live (see below)
164
+ if (!session) await signIn({ clientId, handle: 'alice' }) // alice.techne.town
166
165
  else {
167
166
  const techne = connect(session, TECHNE_PLATFORM_DID)
168
167
  }
169
168
  ```
170
169
 
171
- - **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.
170
+ - **Who:** with no `handle`, the sign-in starts at the default PDS (techne.town), which asks who you are. An app that asked for the address or number itself passes `email` or `phone` (E.164, `+15024429492`) instead: the sign-in page sends the code at once and opens on the code step. `otherWays: true` opens the sign-in page with "Other ways to sign in" (passkey, Nostr key, a handle on another server) already open. One of `handle`, `email`, `phone` and `otherWays` at a time. The [sign-in form](#the-sign-in-form) does all this for you. 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.
172
171
  - **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 records outside `pub.techne.*` (`community.lexicon.*`, `org.hypercerts.funding.receipt`; 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`.
173
172
  - **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.
174
173
  - **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.
@@ -178,7 +177,54 @@ else {
178
177
  - **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.
179
178
  - **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.
180
179
 
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.
180
+ ## The sign-in form
181
+
182
+ `techne-sdk/sign-in` puts the Techne sign-in form on any page of your app, so people start signing in without leaving it:
183
+
184
+ ```ts
185
+ import { mountSignIn } from 'techne-sdk/sign-in'
186
+
187
+ const form = mountSignIn(document.getElementById('sign-in')!, {
188
+ clientId: 'https://cafes.example/oauth-client-metadata.json',
189
+ appName: 'Cafe finder',
190
+ logo: '/logo.png', // a square image; shown 44 px with rounded corners
191
+ })
192
+ // form.unmount() takes it away again.
193
+ ```
194
+
195
+ In React:
196
+
197
+ ```tsx
198
+ import { SignInForm } from 'techne-sdk/react/sign-in'
199
+
200
+ <SignInForm clientId={clientId} appName="Cafe finder" logo="/logo.png" />
201
+ ```
202
+
203
+ **What the person sees.** One card: your logo and name at the top, "Sign in", and a line that says your app uses their Techne account and that the code makes an account for someone new. Below that are Email and Phone tabs. The phone field has a country picker, and its list opens inside the card. Then come a "Send me a code" button, a line of fine print ("We email you a code. No password."), a quiet "Other ways to sign in" link, and "Powered by Techne".
204
+
205
+ - **Send me a code** takes them to the Techne sign-in page with the code already sent, on the step where they type it (it calls `signIn` with `email` or `phone`). After the code they come back to your redirect URI, where `restore` answers the session, as for any sign-in.
206
+ - **Other ways to sign in** takes them to the Techne sign-in page with passkey, Nostr key and a handle on another server open (`signIn` with `otherWays`).
207
+ - A malformed address or number is caught in the form, and the fine print says what is wrong. When the sign-in cannot start (the PDS is unreachable), the fine print says so and `onError` gets the error.
208
+
209
+ **One look for every app.** Your logo and name are the only things that change. The card is 420 px wide, or narrower in a narrower container, and it keeps one size in every view (each tab, the country list), so nothing on your page moves. Put it in a container at least about 320 px wide.
210
+
211
+ **It can't break your page, and your page can't break it.** The form lives in a shadow root on its own element (`<techne-sign-in>`, appended to the element you give). Its styles stay inside, and your page's styles don't reach in. The brand fonts load from the home PDS (`https://pds.techne.town/static/fonts/`), declared once in your document's head under names of its own (`Techne Octave`, `Techne Public Sans`). If they can't load, Georgia and Arial stand in.
212
+
213
+ **Options.** Everything `signIn` takes except who is signing in (`clientId`, `types`, `everything`, `publish`, `scope`, `state`, `platform`, `pds`, `plcUrl`, `handleDomain`, `location`). Pass the same values as to `clientMetadata` and `restore`. Add `appName` (required), `logo` and `onError`. The React components also take `className` and `style` for the `<div>` they mount in, and they mount again when an option changes (not when only `onError` or `onClick` changes).
214
+
215
+ **Accessible.** The inputs have labels. The tabs are a `tablist`: arrow keys, Home and End move between them, and only the selected tab is in the tab order. The country picker is a searchable `listbox`: type to filter, use the arrows and Enter to pick, and Escape or Back to close. The country picked last is kept on the browser (`localStorage`, `techne-sdk:phone-country`). Otherwise the browser's language picks the first one.
216
+
217
+ ### The button
218
+
219
+ Use `mountSignInButton` (`SignInButton` in React) for a "Sign in with Techne" button in a navigation bar or anywhere else a form won't fit:
220
+
221
+ ```ts
222
+ import { mountSignInButton } from 'techne-sdk/sign-in'
223
+
224
+ mountSignInButton(navSlot, { clientId, theme: 'dark', size: 'small' })
225
+ ```
226
+
227
+ `theme: 'dark'` (the default) is black, for light backgrounds. `'light'` is white with a black edge, for dark backgrounds. `size: 'medium'` is 44 px tall and `'small'` is 36 px. A click calls `signIn` with no hint, which opens the Techne sign-in page at its first step. Pass `onClick` to do something else instead, such as showing the form. The button shows the name only, in Techne's type. Don't put the Techne mark beside it.
182
228
 
183
229
  ## A session the app holds (React Native)
184
230
 
@@ -0,0 +1,14 @@
1
+ /**
2
+ * What `signIn` and the sign-in form (`techne-sdk/sign-in`) share about who is signing in and how a redirect
3
+ * ends. Internal: not a package export.
4
+ */
5
+ /** An E.164 number: `+`, then 7 to 15 digits, the first not 0. */
6
+ export declare const E164: RegExp;
7
+ /** An email address as the form and `signIn` take it: something, `@`, a domain with a dot. */
8
+ export declare const isEmailAddress: (s: string) => boolean;
9
+ /** The rejection of a sign-in redirect when the person comes back to the page without signing in (the
10
+ * library's `signInRedirect`, and ours): `Error('User navigated back')`, or an AggregateError holding it when
11
+ * cancelling the pushed request failed too. */
12
+ export declare const NAVIGATED_BACK = "User navigated back";
13
+ /** Whether `err` is that rejection. */
14
+ export declare function isNavigatedBack(err: unknown): boolean;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * What `signIn` and the sign-in form (`techne-sdk/sign-in`) share about who is signing in and how a redirect
3
+ * ends. Internal: not a package export.
4
+ */
5
+ /** An E.164 number: `+`, then 7 to 15 digits, the first not 0. */
6
+ export const E164 = /^\+[1-9]\d{6,14}$/;
7
+ /** An email address as the form and `signIn` take it: something, `@`, a domain with a dot. */
8
+ export const isEmailAddress = (s) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s);
9
+ /** The rejection of a sign-in redirect when the person comes back to the page without signing in (the
10
+ * library's `signInRedirect`, and ours): `Error('User navigated back')`, or an AggregateError holding it when
11
+ * cancelling the pushed request failed too. */
12
+ export const NAVIGATED_BACK = 'User navigated back';
13
+ /** Whether `err` is that rejection. */
14
+ export function isNavigatedBack(err) {
15
+ if (err instanceof AggregateError)
16
+ return err.errors.some(isNavigatedBack);
17
+ return err?.message === NAVIGATED_BACK;
18
+ }
@@ -35,7 +35,9 @@
35
35
  * Where it starts: no handle starts at the techne.town PDS ({@link TECHNE_TOWN_PDS}), which asks who you
36
36
  * are; a bare name (`alice`) is a techne.town handle (`alice.techne.town`); a full handle, a DID or a PDS
37
37
  * URL from any PDS goes as given. `signUp` goes to the techne.town PDS with `prompt: 'create'`, its
38
- * create-account screen. An app whose people live on another PDS (a test deployment's) names it with the `pds`
38
+ * create-account screen. An address or number the app asked for itself goes as `email` or `phone` (the sign-in page
39
+ * sends the code and opens on the code step), and `otherWays` opens it with "Other ways to sign in" open: both set
40
+ * on the authorization URL ({@link SignInOptions.email}); `techne-sdk/sign-in` is the form that does it. An app whose people live on another PDS (a test deployment's) names it with the `pds`
39
41
  * option, and its PLC directory with `plcUrl`: handles then resolve at that PDS, a sign-in with no
40
42
  * handle and every sign-up start there, a bare name takes `handleDomain`, and DIDs resolve at that PLC.
41
43
  *
@@ -88,6 +90,12 @@ export interface OAuthClientLike {
88
90
  state?: string | null;
89
91
  } | undefined>;
90
92
  signInRedirect(input: string, options?: AuthorizeOptions): Promise<unknown>;
93
+ /** The authorization URL a sign-in navigates to (BrowserOAuthClient's, through PAR): {@link signIn} adds
94
+ * `login_hint` and `epds_other_ways` to it, which the library would drop. Needed for `email`, `phone` and
95
+ * `otherWays`. */
96
+ authorize?(input: string, options?: AuthorizeOptions): Promise<URL>;
97
+ /** Cancel the PAR request behind an authorization URL (the person came back without signing in). */
98
+ abortRequest?(url: URL): Promise<void>;
91
99
  revoke(sub: string): Promise<void>;
92
100
  /** The metadata the client signs in with (BrowserOAuthClient's): its `scope` is what a restarted sign-in asks for. */
93
101
  readonly clientMetadata?: {
@@ -206,6 +214,16 @@ export interface SignInOptions extends ClientOptions {
206
214
  signUp?: boolean;
207
215
  /** Handed back by the redirect: {@link redirectState} answers it there. */
208
216
  state?: string;
217
+ /** The person's email address, typed in the app (the sign-in form, `techne-sdk/sign-in`): the Techne sign-in
218
+ * page skips its first step, sends a code to it, and opens on the code step. Sent as `login_hint`. Not with
219
+ * `handle`, `phone` or `otherWays`. */
220
+ email?: string;
221
+ /** The person's phone number, E.164 (`+15024429492`): as `email`, by text message. Not with `handle`,
222
+ * `email` or `otherWays`. */
223
+ phone?: string;
224
+ /** Open the Techne sign-in page with "Other ways to sign in" (passkey, Nostr key, a handle on another server)
225
+ * already open (`epds_other_ways=1`). Not with `handle`, `email` or `phone`. */
226
+ otherWays?: boolean;
209
227
  }
210
228
  /** Sign in: redirects to the person's PDS, and comes back to the app's redirect URI (then {@link restore}).
211
229
  * When the sign-in page hands the person back because their account is on another server, {@link restore}
@@ -3,6 +3,7 @@ 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
5
  import { ownAppSpace } from './app-key.js';
6
+ import { E164, isEmailAddress, NAVIGATED_BACK } from './hints.js';
6
7
  import { TECHNE_TOWN, TECHNE_TOWN_PDS } from './hosts.js';
7
8
  import { PUBLIC_HOMES } from './placement.gen.js';
8
9
  export { appKey, appSpace, ownAppSpace } from './app-key.js';
@@ -179,6 +180,49 @@ export function onSessionDeleted(o, listener) {
179
180
  deletedListeners.delete(clientId);
180
181
  };
181
182
  }
183
+ /** What a sign-in adds to the authorization URL (the library sets `login_hint` itself, from the handle it
184
+ * resolved, and drops one passed in its options, so a typed email or number goes on the URL, which the
185
+ * Techne sign-in page reads before the PAR request's). Throws a TypeError on a combination that makes no sense. */
186
+ function pageParams(o) {
187
+ const email = o.email?.trim();
188
+ const phone = o.phone?.trim();
189
+ const asked = [email && 'email', phone && 'phone', o.otherWays && 'otherWays'].filter(Boolean);
190
+ if (!asked.length)
191
+ return null;
192
+ if (asked.length > 1)
193
+ throw new TypeError(`techne-sdk/auth: signIn takes one of email, phone and otherWays (got ${asked.join(' and ')})`);
194
+ if (o.handle?.trim())
195
+ throw new TypeError(`techne-sdk/auth: signIn takes handle or ${asked[0]}, not both`);
196
+ if (email && !isEmailAddress(email))
197
+ throw new TypeError(`techne-sdk/auth: email is an address (got ${JSON.stringify(o.email)})`);
198
+ if (phone && !E164.test(phone))
199
+ throw new TypeError(`techne-sdk/auth: phone is an E.164 number, +<country code><number> (got ${JSON.stringify(o.phone)})`);
200
+ if (email)
201
+ return { login_hint: email };
202
+ if (phone)
203
+ return { login_hint: phone };
204
+ return { epds_other_ways: '1' };
205
+ }
206
+ /** What BrowserOAuthClient's signInRedirect does, with `params` on the URL: navigate, and if the page is still
207
+ * here 5 s later (the person came back), cancel the request and reject. */
208
+ async function redirectWith(client, input, options, params) {
209
+ if (typeof client.authorize !== 'function')
210
+ throw new Error('techne-sdk/auth: this OAuth client cannot build an authorization URL (email, phone and otherWays need authorize())');
211
+ const url = await client.authorize(input, options);
212
+ for (const [k, v] of Object.entries(params))
213
+ url.searchParams.set(k, v);
214
+ const location = globalThis.location;
215
+ if (!location)
216
+ throw new Error('techne-sdk/auth: signIn navigates, so it needs a browser page');
217
+ location.assign(url.href);
218
+ await new Promise((_, reject) => {
219
+ const timer = setTimeout(() => {
220
+ const err = new Error(NAVIGATED_BACK);
221
+ Promise.resolve(client.abortRequest?.(url)).then(() => reject(err), (reason) => reject(new AggregateError([err, reason])));
222
+ }, 5e3);
223
+ timer.unref?.();
224
+ });
225
+ }
182
226
  /** Where a sign-in for `handle` starts: see the module doc. */
183
227
  function signInTarget(handle, o = {}) {
184
228
  const h = handle?.trim().replace(/^@/, '');
@@ -192,6 +236,7 @@ function signInTarget(handle, o = {}) {
192
236
  * When the sign-in page hands the person back because their account is on another server, {@link restore}
193
237
  * starts this sign-in again there (see {@link MAX_HANDBACKS}). */
194
238
  export async function signIn(o = {}) {
239
+ const params = pageParams(o);
195
240
  const { scope } = resolveClient(o);
196
241
  const client = await oauthClient(o);
197
242
  // A sign-up is at the home PDS unless the app names another PDS by its URL.
@@ -199,7 +244,10 @@ export async function signIn(o = {}) {
199
244
  const options = { scope, state: wrapState(0, o.state) };
200
245
  if (o.signUp)
201
246
  options.prompt = 'create';
202
- await client.signInRedirect(input, options);
247
+ if (params)
248
+ await redirectWith(client, input, options, params);
249
+ else
250
+ await client.signInRedirect(input, options);
203
251
  }
204
252
  /**
205
253
  * How many times one sign-in is started again at another server. The Techne sign-in page (ePDS) hands a
@@ -116,7 +116,7 @@ export const catalog = {
116
116
  {
117
117
  "nsid": "app.certified.defs",
118
118
  "name": "app.certified.defs",
119
- "group": "pub.techne",
119
+ "group": "app.certified",
120
120
  "kind": "object",
121
121
  "description": "Common type definitions used across certified protocols.",
122
122
  "doc": ({
@@ -159,7 +159,7 @@ export const catalog = {
159
159
  {
160
160
  "nsid": "app.certified.signature.defs",
161
161
  "name": "app.certified.signature.defs",
162
- "group": "pub.techne",
162
+ "group": "app.certified",
163
163
  "kind": "array",
164
164
  "description": "Common type definitions for cryptographic signatures attached to records, per the ATProtocol Attestation Specification. Each signature's `$type` says what it attests.",
165
165
  "doc": ({
@@ -1612,7 +1612,7 @@ export const catalog = {
1612
1612
  {
1613
1613
  "nsid": "org.hypercerts.funding.receipt",
1614
1614
  "name": "org.hypercerts.funding.receipt",
1615
- "group": "pub.techne",
1615
+ "group": "org.hypercerts",
1616
1616
  "kind": "record",
1617
1617
  "key": "tid",
1618
1618
  "description": "Records a payment from a sender to a recipient. Any party may record it, and the sender may stay anonymous. When the sender chose the recipient, record one receipt to the final recipient even if platforms or hosts passed the funds on. When an intermediary chose (regranting), record the payment into it and each onward payment as separate receipts. A receipt may be updated in place under the same record key: its URI does not change, so references by URI keep resolving, but a strongRef (as likes and reposts use) still pins the earlier CID, and signatures bind to content and must be renewed. An earlier version cannot be recalled from readers that kept it.",
@@ -1880,7 +1880,7 @@ export const catalog = {
1880
1880
  {
1881
1881
  "nsid": "org.hypercerts.funding.receipt.query",
1882
1882
  "name": "org.hypercerts.funding.receipt.query",
1883
- "group": "pub.techne",
1883
+ "group": "org.hypercerts",
1884
1884
  "kind": "queryDocument",
1885
1885
  "description": "How a reader takes this record's fields. It fills no query role. It is about its recipient, the record at `to.uri` (when `to` is a strong reference), and a where read finds it there when asked to follow subjects.",
1886
1886
  "doc": ({
@@ -0,0 +1,34 @@
1
+ /**
2
+ * techne-sdk/react/sign-in — the Techne sign-in form and the "Sign in with Techne" button as React components:
3
+ * `techne-sdk/sign-in`'s {@link mountSignIn} and {@link mountSignInButton} in a `<div>` of their own.
4
+ *
5
+ * ```tsx
6
+ * <SignInForm clientId="https://cafes.example/oauth-client-metadata.json" appName="Cafés" logo="/logo.png" />
7
+ * <SignInButton clientId={clientId} theme="light" size="small" />
8
+ * ```
9
+ *
10
+ * Its own subpath, so `techne-sdk/react` still loads no OAuth client. The form mounts again when an option
11
+ * changes; `onError` and `onClick` are read when called, so a new function each render does not remount it.
12
+ */
13
+ import { type CSSProperties } from 'react';
14
+ import { type SignInButtonOptions, type SignInFormOptions } from '../sign-in/index.js';
15
+ /** The `<div>` the form or the button is mounted in. */
16
+ interface Box {
17
+ className?: string;
18
+ style?: CSSProperties;
19
+ }
20
+ export type SignInFormProps = SignInFormOptions & Box;
21
+ export type SignInButtonProps = SignInButtonOptions & Box;
22
+ /** The sign-in form (`techne-sdk/sign-in`'s `mountSignIn`). */
23
+ export declare function SignInForm(props: SignInFormProps): import("react").DetailedReactHTMLElement<{
24
+ ref: import("react").RefObject<HTMLDivElement | null>;
25
+ className: string | undefined;
26
+ style: CSSProperties | undefined;
27
+ }, HTMLDivElement>;
28
+ /** The "Sign in with Techne" button (`techne-sdk/sign-in`'s `mountSignInButton`). */
29
+ export declare function SignInButton(props: SignInButtonProps): import("react").DetailedReactHTMLElement<{
30
+ ref: import("react").RefObject<HTMLDivElement | null>;
31
+ className: string | undefined;
32
+ style: CSSProperties | undefined;
33
+ }, HTMLDivElement>;
34
+ export {};
@@ -0,0 +1,52 @@
1
+ /**
2
+ * techne-sdk/react/sign-in — the Techne sign-in form and the "Sign in with Techne" button as React components:
3
+ * `techne-sdk/sign-in`'s {@link mountSignIn} and {@link mountSignInButton} in a `<div>` of their own.
4
+ *
5
+ * ```tsx
6
+ * <SignInForm clientId="https://cafes.example/oauth-client-metadata.json" appName="Cafés" logo="/logo.png" />
7
+ * <SignInButton clientId={clientId} theme="light" size="small" />
8
+ * ```
9
+ *
10
+ * Its own subpath, so `techne-sdk/react` still loads no OAuth client. The form mounts again when an option
11
+ * changes; `onError` and `onClick` are read when called, so a new function each render does not remount it.
12
+ */
13
+ import { createElement, useEffect, useLayoutEffect, useRef } from 'react';
14
+ import { mountSignIn, mountSignInButton } from '../sign-in/index.js';
15
+ /** Mount with `mount` in a div, again when the options (but the callbacks) change. `callbacks` and `mount` are
16
+ * module constants; the options are rebuilt from `key`, so the effect's dependencies are complete. */
17
+ function useMounted(props, callbacks, mount) {
18
+ const ref = useRef(null);
19
+ const latest = useRef(props);
20
+ useLayoutEffect(() => {
21
+ latest.current = props;
22
+ });
23
+ const { className, style, ...rest } = props;
24
+ const options = { ...rest };
25
+ for (const k of callbacks)
26
+ delete options[k];
27
+ // Whether each callback is given changes what the mount does (a button with onClick starts no sign-in).
28
+ const key = JSON.stringify([options, callbacks.map((k) => props[k] !== undefined)]);
29
+ useEffect(() => {
30
+ const el = ref.current;
31
+ if (!el)
32
+ return;
33
+ const [o, given] = JSON.parse(key);
34
+ callbacks.forEach((k, i) => {
35
+ if (given[i])
36
+ o[k] = (...args) => latest.current[k]?.(...args);
37
+ });
38
+ const m = mount(el, o);
39
+ return () => m.unmount();
40
+ }, [key, callbacks, mount]);
41
+ return createElement('div', { ref, className, style });
42
+ }
43
+ const FORM_CALLBACKS = ['onError'];
44
+ const BUTTON_CALLBACKS = ['onError', 'onClick'];
45
+ /** The sign-in form (`techne-sdk/sign-in`'s `mountSignIn`). */
46
+ export function SignInForm(props) {
47
+ return useMounted(props, FORM_CALLBACKS, mountSignIn);
48
+ }
49
+ /** The "Sign in with Techne" button (`techne-sdk/sign-in`'s `mountSignInButton`). */
50
+ export function SignInButton(props) {
51
+ return useMounted(props, BUTTON_CALLBACKS, mountSignInButton);
52
+ }
@@ -0,0 +1,33 @@
1
+ import { type SignInOptions } from '../auth/index.js';
2
+ /** What a sign-in from the form or the button carries: everything {@link signIn} takes but who is signing in. */
3
+ export type SignInFormClient = Omit<SignInOptions, 'handle' | 'email' | 'phone' | 'otherWays' | 'signUp'>;
4
+ /** What {@link mountSignIn} takes. */
5
+ export interface SignInFormOptions extends SignInFormClient {
6
+ /** The app's name, shown beside its logo and in the line under "Sign in". */
7
+ appName: string;
8
+ /** The app's logo: an image URL (a square, shown 44 px with rounded corners). None: the name alone. */
9
+ logo?: string;
10
+ /** Called when a sign-in could not start (the PDS could not be reached, say); the form also says so. */
11
+ onError?: (error: unknown) => void;
12
+ }
13
+ /** What {@link mountSignInButton} takes. */
14
+ export interface SignInButtonOptions extends SignInFormClient {
15
+ /** `dark`: black, for light backgrounds (the default). `light`: white with a black edge, for dark ones. */
16
+ theme?: 'dark' | 'light';
17
+ /** `medium`: 44 px tall (the default). `small`: 36 px, for a navigation bar. */
18
+ size?: 'medium' | 'small';
19
+ /** Called instead of {@link signIn} on a click (to show the form, say). */
20
+ onClick?: () => void;
21
+ /** Called when the sign-in could not start. */
22
+ onError?: (error: unknown) => void;
23
+ }
24
+ /** A mounted form or button. */
25
+ export interface Mounted {
26
+ /** Remove it from the page. */
27
+ unmount(): void;
28
+ }
29
+ /** Mount the sign-in form in `target` (appended to it). See the module doc for what it shows and does. */
30
+ export declare function mountSignIn(target: Element, options: SignInFormOptions): Mounted;
31
+ /** Mount the "Sign in with Techne" button in `target` (appended to it). A click starts {@link signIn} with no
32
+ * handle (the Techne sign-in page's first step), or calls `onClick` instead. */
33
+ export declare function mountSignInButton(target: Element, options: SignInButtonOptions): Mounted;
@@ -0,0 +1,483 @@
1
+ /**
2
+ * techne-sdk/sign-in — the Techne sign-in form and the "Sign in with Techne" button, for any web page, with
3
+ * no framework (`techne-sdk/react/sign-in` wraps both for React).
4
+ *
5
+ * ```ts
6
+ * import { mountSignIn } from 'techne-sdk/sign-in'
7
+ * mountSignIn(document.getElementById('sign-in'), {
8
+ * clientId: 'https://cafes.example/oauth-client-metadata.json',
9
+ * appName: 'Cafés',
10
+ * logo: '/logo.png',
11
+ * })
12
+ * ```
13
+ *
14
+ * The form is one card, one look for every app: the app's logo and name, "Sign in", a short line saying the
15
+ * app uses a Techne account, Email and Phone tabs (the phone with a country list that opens inside the card),
16
+ * "Send me a code", a line of fine print, a quiet "Other ways to sign in" and "Powered by Techne". "Send me a
17
+ * code" starts {@link signIn} with the address or number typed, so the Techne sign-in page opens on the
18
+ * code step, the code already sent; "Other ways to sign in" starts it with `otherWays`, the sign-in page's
19
+ * first step with passkey, Nostr key and a handle on another server open. After the code the person comes
20
+ * back to the app's redirect URI, where `restore` answers the session, as for any sign-in. The card keeps
21
+ * one size in every view (tab, country list) at a given width: 420 px wide at most, as wide as its container below that.
22
+ *
23
+ * Each form and button lives in a shadow root on an element of its own, appended to the target: its styles
24
+ * do not leak out and the page's do not reach in. The two brand fonts load from the home PDS.
25
+ */
26
+ import { getCountries, getCountryCallingCode, parsePhoneNumberFromString } from 'libphonenumber-js/min';
27
+ import { signIn, TECHNE_TOWN_PDS } from '../auth/index.js';
28
+ import { isEmailAddress, isNavigatedBack } from '../auth/hints.js';
29
+ import { BUTTON_CSS, FORM_CSS, fontFaces } from './styles.js';
30
+ /** The fine print under the button, per tab. */
31
+ const FINE = { email: 'We email you a code. No password.', phone: 'We text you a code. No password.' };
32
+ /** Where the form keeps the country last picked on this browser. */
33
+ const COUNTRY_STORAGE_KEY = 'techne-sdk:phone-country';
34
+ /** The country the list starts on when the browser's languages name none. */
35
+ const FALLBACK_COUNTRY = 'US';
36
+ const FORM_HTML = `
37
+ <div class="root card" part="card">
38
+ <div class="app"><img alt="" hidden><span class="name"></span></div>
39
+ <div class="views">
40
+ <div class="view main">
41
+ <h1>Sign in</h1>
42
+ <p class="lede"></p>
43
+ <form novalidate>
44
+ <div class="seg" role="tablist" aria-label="Sign in with">
45
+ <button type="button" role="tab" class="tab" id="tab-email" aria-controls="field-email" aria-selected="true">Email</button>
46
+ <button type="button" role="tab" class="tab" id="tab-phone" aria-controls="field-phone" aria-selected="false" tabindex="-1">Phone</button>
47
+ </div>
48
+ <div class="fields">
49
+ <div class="field" id="field-email" role="tabpanel" aria-labelledby="tab-email">
50
+ <label for="email">Email</label>
51
+ <input type="email" id="email" name="email" autocomplete="email" autocapitalize="none" autocorrect="off" spellcheck="false" placeholder="you@example.com" aria-describedby="fine">
52
+ </div>
53
+ <div class="field off" id="field-phone" role="tabpanel" aria-labelledby="tab-phone">
54
+ <label for="phone">Phone number</label>
55
+ <div class="phone-row">
56
+ <button type="button" class="country-btn" aria-haspopup="listbox" aria-expanded="false" aria-controls="picker"><span class="flag" aria-hidden="true"></span><span class="dial"></span><span class="caret" aria-hidden="true">&#9662;</span></button>
57
+ <input type="tel" id="phone" name="phone" autocomplete="tel-national" inputmode="tel" placeholder="Phone number" aria-describedby="fine">
58
+ </div>
59
+ </div>
60
+ </div>
61
+ <button type="submit" class="send">Send me a code</button>
62
+ <p class="fine" id="fine" aria-live="polite"></p>
63
+ </form>
64
+ <button type="button" class="other">Other ways to sign in</button>
65
+ </div>
66
+ <div class="picker" id="picker" hidden>
67
+ <button type="button" class="back">&#8249; Back</button>
68
+ <input type="text" class="search" placeholder="Search countries" autocomplete="off" spellcheck="false" role="combobox" aria-expanded="true" aria-controls="countries" aria-autocomplete="list" aria-label="Search countries">
69
+ <ul class="list" id="countries" role="listbox" aria-label="Countries"></ul>
70
+ </div>
71
+ </div>
72
+ <div class="powered">Powered by <a href="https://techne.town" target="_blank" rel="noopener"><span class="word">Techne</span><span class="sr"> (opens in a new tab)</span></a></div>
73
+ </div>`;
74
+ /** The document's one `<style>` with the brand fonts (`@font-face` is ignored inside a shadow root). */
75
+ function addFonts(doc, pds) {
76
+ if (doc.getElementById('techne-sdk-sign-in-fonts'))
77
+ return;
78
+ const style = doc.createElement('style');
79
+ style.id = 'techne-sdk-sign-in-fonts';
80
+ style.textContent = fontFaces(`${new URL(pds).origin}/static/fonts/`);
81
+ doc.head.appendChild(style);
82
+ }
83
+ /** A host element with an open shadow root holding `css`, appended to `target`. */
84
+ function host(target, css, pds) {
85
+ if (!target || typeof target.appendChild !== 'function')
86
+ throw new TypeError('techne-sdk/sign-in: mount on an element');
87
+ const doc = target.ownerDocument;
88
+ addFonts(doc, pds);
89
+ const el = doc.createElement('techne-sign-in');
90
+ const root = el.attachShadow({ mode: 'open' });
91
+ const style = doc.createElement('style');
92
+ style.textContent = css;
93
+ root.appendChild(style);
94
+ target.appendChild(el);
95
+ return { el, root };
96
+ }
97
+ /** The sign-in options to pass on: everything but the form's own. */
98
+ function clientOf(o, own) {
99
+ const rest = { ...o };
100
+ for (const k of own)
101
+ delete rest[k];
102
+ return rest;
103
+ }
104
+ const fold = (s) => s.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
105
+ const flagOf = (region) => String.fromCodePoint(0x1f1e6 + region.charCodeAt(0) - 65, 0x1f1e6 + region.charCodeAt(1) - 65);
106
+ /** Every country libphonenumber knows, named in the browser's languages, sorted by name. */
107
+ function countryList(languages) {
108
+ let names = null;
109
+ try {
110
+ names = new Intl.DisplayNames(languages, { type: 'region' });
111
+ }
112
+ catch {
113
+ names = null;
114
+ }
115
+ const out = getCountries().map((region) => {
116
+ let name = region;
117
+ try {
118
+ name = names?.of(region) || region;
119
+ }
120
+ catch {
121
+ name = region;
122
+ }
123
+ return { region, dial: getCountryCallingCode(region), name, key: fold(name) };
124
+ });
125
+ const collator = new Intl.Collator(languages);
126
+ return out.sort((a, b) => collator.compare(a.name, b.name));
127
+ }
128
+ /** The region of the first browser language that names one we know (as "fr" implies FR), else US. */
129
+ function defaultRegion(languages, known) {
130
+ for (const l of languages) {
131
+ let region = '';
132
+ try {
133
+ region = new Intl.Locale(l).maximize().region || '';
134
+ }
135
+ catch {
136
+ region = '';
137
+ }
138
+ if (known.has(region))
139
+ return region;
140
+ }
141
+ return FALLBACK_COUNTRY;
142
+ }
143
+ /** Whether this browser draws flag emoji (Windows draws two letters, which look like a mistake). */
144
+ function flagsDrawn(doc) {
145
+ try {
146
+ const c = doc.createElement('canvas');
147
+ c.width = c.height = 16;
148
+ const g = c.getContext('2d');
149
+ if (!g)
150
+ return false;
151
+ g.font = '14px sans-serif';
152
+ g.textBaseline = 'top';
153
+ g.fillText('\u{1F1FA}\u{1F1F8}', 0, 0);
154
+ const d = g.getImageData(0, 0, 16, 16).data;
155
+ for (let p = 0; p < d.length; p += 4)
156
+ if (d[p + 3] && (d[p] !== d[p + 1] || d[p + 1] !== d[p + 2]))
157
+ return true;
158
+ }
159
+ catch {
160
+ /* no canvas */
161
+ }
162
+ return false;
163
+ }
164
+ /** A typed number read under `region` (a number with its own `+` code wins); undefined when it reads as none. */
165
+ function parsePhone(typed, region) {
166
+ try {
167
+ return parsePhoneNumberFromString(typed || '', region);
168
+ }
169
+ catch {
170
+ return undefined;
171
+ }
172
+ }
173
+ /** A typed number as E.164 under `region`, or null when it cannot be one. */
174
+ function phoneE164(typed, region) {
175
+ const p = parsePhone(typed, region);
176
+ return p && p.isPossible() ? p.number : null;
177
+ }
178
+ /** Re-enable `buttons` when the page comes back from the back-forward cache (the person came back from the
179
+ * sign-in page). Answers the unsubscribe. */
180
+ function onBackForward(doc, enable) {
181
+ const onShow = (e) => {
182
+ if (e.persisted)
183
+ enable();
184
+ };
185
+ doc.defaultView?.addEventListener('pageshow', onShow);
186
+ return () => doc.defaultView?.removeEventListener('pageshow', onShow);
187
+ }
188
+ /** Mount the sign-in form in `target` (appended to it). See the module doc for what it shows and does. */
189
+ export function mountSignIn(target, options) {
190
+ if (!options?.appName?.trim())
191
+ throw new TypeError('techne-sdk/sign-in: mountSignIn needs appName (shown at the top of the form)');
192
+ const client = clientOf(options, ['appName', 'logo', 'onError']);
193
+ const { el, root } = host(target, FORM_CSS, options.pds ?? TECHNE_TOWN_PDS);
194
+ const doc = target.ownerDocument;
195
+ const wrap = doc.createElement('div');
196
+ wrap.innerHTML = FORM_HTML;
197
+ root.appendChild(wrap.firstElementChild);
198
+ const $ = (sel) => {
199
+ const found = root.querySelector(sel);
200
+ if (!found)
201
+ throw new Error(`techne-sdk/sign-in: the form has no ${sel}`);
202
+ return found;
203
+ };
204
+ const appName = options.appName.trim();
205
+ $('.app .name').textContent = appName;
206
+ if (options.logo) {
207
+ const img = $('.app img');
208
+ img.src = options.logo;
209
+ img.hidden = false;
210
+ }
211
+ $('.lede').textContent = `${appName} uses your Techne account. New here? The code we send makes one.`;
212
+ const form = $('form');
213
+ const send = $('.send');
214
+ const other = $('.other');
215
+ const fine = $('.fine');
216
+ const email = $('#email');
217
+ const phone = $('#phone');
218
+ const tabs = { email: $('#tab-email'), phone: $('#tab-phone') };
219
+ const fields = { email: $('#field-email'), phone: $('#field-phone') };
220
+ const main = $('.view.main');
221
+ const picker = $('.picker');
222
+ const countryBtn = $('.country-btn');
223
+ const search = $('.search');
224
+ const list = $('.list');
225
+ let mode = 'email';
226
+ function say(text, error = false) {
227
+ fine.textContent = text;
228
+ fine.classList.toggle('error', error);
229
+ }
230
+ function setTab(m, focus = false) {
231
+ mode = m;
232
+ for (const k of ['email', 'phone']) {
233
+ tabs[k].setAttribute('aria-selected', String(k === m));
234
+ tabs[k].tabIndex = k === m ? 0 : -1;
235
+ fields[k].classList.toggle('off', k !== m);
236
+ }
237
+ say(FINE[m]);
238
+ if (focus)
239
+ tabs[m].focus();
240
+ }
241
+ for (const k of ['email', 'phone'])
242
+ tabs[k].addEventListener('click', () => setTab(k));
243
+ $('.seg').addEventListener('keydown', (e) => {
244
+ const key = e.key;
245
+ if (key === 'ArrowLeft' || key === 'ArrowRight' || key === 'Home' || key === 'End') {
246
+ e.preventDefault();
247
+ setTab(key === 'Home' ? 'email' : key === 'End' ? 'phone' : mode === 'email' ? 'phone' : 'email', true);
248
+ }
249
+ });
250
+ // The country list.
251
+ const nav = doc.defaultView?.navigator;
252
+ const languages = nav?.languages?.length ? nav.languages : [nav?.language || 'en'];
253
+ const countries = countryList(languages);
254
+ const byRegion = new Map(countries.map((c) => [c.region, c]));
255
+ let stored = null;
256
+ try {
257
+ stored = doc.defaultView?.localStorage?.getItem(COUNTRY_STORAGE_KEY) ?? null;
258
+ }
259
+ catch {
260
+ stored = null;
261
+ }
262
+ let current = byRegion.get(stored ?? '') ?? byRegion.get(defaultRegion(languages, new Set(byRegion.keys()))) ?? countries[0];
263
+ let shown = [];
264
+ let active = 0;
265
+ if (!flagsDrawn(doc))
266
+ $('.root').classList.add('no-flags');
267
+ function setCountry(c, remember) {
268
+ current = c;
269
+ $('.country-btn .flag').textContent = flagOf(c.region);
270
+ $('.country-btn .dial').textContent = `+${c.dial}`;
271
+ countryBtn.setAttribute('aria-label', `Country: ${c.name} (+${c.dial}). Change country`);
272
+ if (remember) {
273
+ try {
274
+ doc.defaultView?.localStorage?.setItem(COUNTRY_STORAGE_KEY, c.region);
275
+ }
276
+ catch {
277
+ /* private mode */
278
+ }
279
+ }
280
+ }
281
+ function render() {
282
+ const q = fold(search.value.trim()).replace(/^\+/, '');
283
+ shown = q ? countries.filter((c) => c.key.includes(q) || c.dial.startsWith(q) || c.region.toLowerCase() === q) : [current, ...countries.filter((c) => c !== current)];
284
+ list.replaceChildren();
285
+ if (!shown.length) {
286
+ const li = doc.createElement('li');
287
+ li.className = 'empty';
288
+ li.textContent = 'No country matches';
289
+ list.appendChild(li);
290
+ search.removeAttribute('aria-activedescendant');
291
+ return;
292
+ }
293
+ shown.forEach((c, i) => {
294
+ const li = doc.createElement('li');
295
+ li.id = `country-${c.region}`;
296
+ li.setAttribute('role', 'option');
297
+ li.setAttribute('aria-selected', String(c === current));
298
+ const f = doc.createElement('span');
299
+ f.className = 'flag';
300
+ f.setAttribute('aria-hidden', 'true');
301
+ f.textContent = flagOf(c.region);
302
+ const n = doc.createElement('span');
303
+ n.className = 'cname';
304
+ n.textContent = c.name;
305
+ const d = doc.createElement('span');
306
+ d.className = 'code';
307
+ d.textContent = `+${c.dial}`;
308
+ li.append(f, n, d);
309
+ li.addEventListener('mousedown', (e) => e.preventDefault());
310
+ li.addEventListener('click', () => choose(i));
311
+ list.appendChild(li);
312
+ });
313
+ setActive(0);
314
+ }
315
+ function setActive(i) {
316
+ if (!shown.length)
317
+ return;
318
+ active = Math.max(0, Math.min(i, shown.length - 1));
319
+ const items = list.querySelectorAll('li[role=option]');
320
+ items.forEach((li, k) => li.classList.toggle('active', k === active));
321
+ const li = items[active];
322
+ if (li) {
323
+ search.setAttribute('aria-activedescendant', li.id);
324
+ li.scrollIntoView?.({ block: 'nearest' });
325
+ }
326
+ }
327
+ function openPicker() {
328
+ picker.hidden = false;
329
+ main.classList.add('off');
330
+ main.inert = true;
331
+ countryBtn.setAttribute('aria-expanded', 'true');
332
+ search.value = '';
333
+ render();
334
+ search.focus();
335
+ }
336
+ function closePicker(focusNumber) {
337
+ if (picker.hidden)
338
+ return;
339
+ picker.hidden = true;
340
+ main.classList.remove('off');
341
+ main.inert = false;
342
+ countryBtn.setAttribute('aria-expanded', 'false');
343
+ (focusNumber ? phone : countryBtn).focus();
344
+ }
345
+ function choose(i) {
346
+ const c = shown[i];
347
+ if (!c)
348
+ return;
349
+ setCountry(c, true);
350
+ closePicker(true);
351
+ }
352
+ countryBtn.addEventListener('click', () => (picker.hidden ? openPicker() : closePicker(false)));
353
+ $('.back').addEventListener('click', () => closePicker(false));
354
+ search.addEventListener('input', render);
355
+ search.addEventListener('keydown', (e) => {
356
+ const key = e.key;
357
+ if (key === 'ArrowDown')
358
+ (e.preventDefault(), setActive(active + 1));
359
+ else if (key === 'ArrowUp')
360
+ (e.preventDefault(), setActive(active - 1));
361
+ else if (key === 'Enter')
362
+ (e.preventDefault(), choose(active));
363
+ else if (key === 'Escape')
364
+ (e.preventDefault(), closePicker(false));
365
+ });
366
+ picker.addEventListener('keydown', (e) => {
367
+ if (e.key === 'Escape')
368
+ (e.preventDefault(), closePicker(false));
369
+ });
370
+ setCountry(current, false);
371
+ // A pasted or autofilled number shows the national way under its own country.
372
+ function tidy() {
373
+ const p = parsePhone(phone.value, current.region);
374
+ if (!p || !p.isValid())
375
+ return;
376
+ const own = p.country && byRegion.get(p.country);
377
+ if (own && own !== current)
378
+ setCountry(own, false);
379
+ const national = p.formatNational();
380
+ if (national.replace(/\D/g, '') !== phone.value.replace(/\D/g, ''))
381
+ phone.value = national;
382
+ }
383
+ phone.addEventListener('input', (e) => {
384
+ const t = e.inputType;
385
+ if (!t || t === 'insertFromPaste' || t === 'insertReplacementText')
386
+ tidy();
387
+ });
388
+ phone.addEventListener('change', tidy);
389
+ // Starting the sign-in.
390
+ let busy = false;
391
+ function setBusy(b) {
392
+ busy = b;
393
+ send.disabled = b;
394
+ other.disabled = b;
395
+ }
396
+ function start(o) {
397
+ setBusy(true);
398
+ signIn({ ...client, ...o }).then(() => setBusy(false), (err) => {
399
+ setBusy(false);
400
+ // The person came back from the sign-in page: the form is as they left it.
401
+ if (isNavigatedBack(err))
402
+ return say(FINE[mode]);
403
+ say('Could not reach Techne. Try again.', true);
404
+ options.onError?.(err);
405
+ });
406
+ }
407
+ const offBackForward = onBackForward(doc, () => setBusy(false));
408
+ form.addEventListener('submit', (e) => {
409
+ e.preventDefault();
410
+ if (busy)
411
+ return;
412
+ if (mode === 'email') {
413
+ const v = email.value.trim();
414
+ if (!isEmailAddress(v)) {
415
+ say(v ? 'That address does not look right.' : 'Enter your email address.', true);
416
+ email.focus();
417
+ return;
418
+ }
419
+ start({ email: v });
420
+ }
421
+ else {
422
+ const v = phoneE164(phone.value, current.region);
423
+ if (!v) {
424
+ say(phone.value.trim() ? 'That number does not look right.' : 'Enter your phone number.', true);
425
+ phone.focus();
426
+ return;
427
+ }
428
+ start({ phone: v });
429
+ }
430
+ });
431
+ other.addEventListener('click', () => {
432
+ if (!busy)
433
+ start({ otherWays: true });
434
+ });
435
+ setTab('email');
436
+ return {
437
+ unmount() {
438
+ offBackForward();
439
+ el.remove();
440
+ },
441
+ };
442
+ }
443
+ /** Mount the "Sign in with Techne" button in `target` (appended to it). A click starts {@link signIn} with no
444
+ * handle (the Techne sign-in page's first step), or calls `onClick` instead. */
445
+ export function mountSignInButton(target, options) {
446
+ const o = options ?? {};
447
+ const theme = o.theme ?? 'dark';
448
+ const size = o.size ?? 'medium';
449
+ if (theme !== 'dark' && theme !== 'light')
450
+ throw new TypeError(`techne-sdk/sign-in: theme is 'dark' or 'light' (got ${JSON.stringify(theme)})`);
451
+ if (size !== 'medium' && size !== 'small')
452
+ throw new TypeError(`techne-sdk/sign-in: size is 'medium' or 'small' (got ${JSON.stringify(size)})`);
453
+ const client = clientOf(o, ['theme', 'size', 'onClick', 'onError']);
454
+ const { el, root } = host(target, BUTTON_CSS, o.pds ?? TECHNE_TOWN_PDS);
455
+ const doc = target.ownerDocument;
456
+ const btn = doc.createElement('button');
457
+ btn.type = 'button';
458
+ btn.className = `root btn ${theme}${size === 'small' ? ' small' : ''}`;
459
+ btn.setAttribute('part', 'button');
460
+ btn.append('Sign in with ');
461
+ const word = doc.createElement('span');
462
+ word.className = 'word';
463
+ word.textContent = 'Techne';
464
+ btn.appendChild(word);
465
+ root.appendChild(btn);
466
+ btn.addEventListener('click', () => {
467
+ if (o.onClick)
468
+ return o.onClick();
469
+ btn.disabled = true;
470
+ signIn(client).then(() => (btn.disabled = false), (err) => {
471
+ btn.disabled = false;
472
+ if (!isNavigatedBack(err))
473
+ o.onError?.(err);
474
+ });
475
+ });
476
+ const offBackForward = onBackForward(doc, () => (btn.disabled = false));
477
+ return {
478
+ unmount() {
479
+ offBackForward();
480
+ el.remove();
481
+ },
482
+ };
483
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The sign-in form's and the button's styles: the Techne sign-in page's own values (ePDS auth-service
3
+ * `login-page.ts`, `phone/country-picker.ts` and shared `brand.ts`, as rendered in the approved mocks), in
4
+ * one sheet that lives in each form's shadow root. Nothing here reaches the host page, and the host page's
5
+ * rules do not reach in: `:host` resets every inherited property with `!important`, which beats the page's
6
+ * own rules on the host element.
7
+ *
8
+ * The two brand fonts are the Techne sign-in page's, loaded from the home PDS (`<pds>/static/fonts/`,
9
+ * served with `Access-Control-Allow-Origin: *`) under names of our own, so a host page's 'Octave' or
10
+ * 'Public Sans' is never touched. `@font-face` does not work inside a shadow root, so {@link fontFaces} goes
11
+ * into the document's head, once.
12
+ */
13
+ /** The font families the sheet names (ours: no host page uses them). */
14
+ export declare const SERIF = "'Techne Octave', Georgia, serif";
15
+ export declare const SANS = "'Techne Public Sans', Arial, sans-serif";
16
+ /** The `@font-face` rules for {@link SERIF} and {@link SANS}, from `base` (`<pds>/static/fonts/`). */
17
+ export declare function fontFaces(base: string): string;
18
+ /** The form's sheet. */
19
+ export declare const FORM_CSS = "\n:host { all: initial !important; display: block !important; }\n:host([hidden]) { display: none !important; }\n*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n.root { font-family: 'Techne Public Sans', Arial, sans-serif; color: #000; text-align: left; line-height: normal; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }\nbutton, input { font-family: inherit; }\n:focus-visible { outline: 2px solid #000; outline-offset: 3px; }\n[hidden] { display: none !important; }\n.word { font-family: 'Techne Octave', Georgia, serif; font-weight: 500; font-feature-settings: 'dlig' 1; letter-spacing: -.01em; }\n\n.root { --muted: rgba(0,0,0,.58); --input-border: rgba(0,0,0,.12); }\n.card { width: 100%; max-width: 420px; padding: 28px; display: flex; flex-direction: column; background: #fff; border: 1px solid rgba(0,0,0,.05); border-radius: 20px; box-shadow: 0 6px 24px rgba(0,0,0,.06); }\n.app { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; min-width: 0; }\n.app img { width: 44px; height: 44px; border-radius: 12px; flex: none; display: block; object-fit: cover; }\n.app .name { font-size: 14px; font-weight: 500; color: var(--muted); overflow-wrap: anywhere; }\n/* Every view sits in one grid cell; the country list is laid over it. The cell is as tall as the main view\n whatever tab or view is showing, so the card keeps one size. */\n.views { position: relative; display: grid; flex: 1 0 auto; }\n.view { grid-area: 1 / 1; display: flex; flex-direction: column; min-width: 0; }\n.view.off { visibility: hidden; }\nh1 { font-family: 'Techne Octave', Georgia, serif; font-size: 28px; line-height: 1.2; font-weight: 500; letter-spacing: -.02em; color: #000; margin-bottom: 8px; font-feature-settings: 'dlig' 1; overflow-wrap: anywhere; text-wrap: balance; }\n.lede { color: var(--muted); font-size: 15px; line-height: 1.45; margin-bottom: 24px; text-wrap: pretty; }\n.seg { display: grid; grid-template-columns: 1fr 1fr; background: #EDEBE3; border-radius: 999px; padding: 4px; margin-bottom: 16px; }\n.tab { border: 0; background: none; padding: 9px 0; border-radius: 999px; font-size: 14px; font-weight: 500; color: var(--muted); cursor: pointer; transition: background .15s, color .15s, box-shadow .15s; }\n.tab[aria-selected=\"true\"] { background: #fff; color: #1A130F; box-shadow: 0 1px 4px rgba(0,0,0,.08); }\n.tab:focus-visible { outline-offset: 2px; }\n.fields { display: grid; }\n.field { grid-area: 1 / 1; text-align: left; }\n.field.off { visibility: hidden; }\nlabel { display: block; font-size: 13px; line-height: 18px; font-weight: 500; color: #000; margin-bottom: 6px; }\ninput { width: 100%; height: 48px; padding: 0 14px; border: 1.5px solid var(--input-border); border-radius: 12px; font-size: 16px; color: #000; background: #fff; outline: none; transition: border-color .15s; }\ninput:focus { border-color: #000; }\ninput:focus-visible { outline: none; }\ninput::placeholder { color: rgba(0,0,0,.4); }\n.phone-row { display: flex; gap: 8px; }\n.phone-row input { flex: 1 1 auto; min-width: 0; }\n.country-btn { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; height: 48px; padding: 0 12px; border: 1.5px solid var(--input-border); border-radius: 12px; background: #fff; font-size: 16px; color: #1A130F; cursor: pointer; }\n.country-btn:focus-visible, .country-btn[aria-expanded=\"true\"] { outline: none; border-color: #000; }\n.country-btn .caret { color: var(--muted); font-size: 12px; }\n.flag { font-size: 20px; line-height: 1; }\n.no-flags .flag { display: none; }\n.send { width: 100%; height: 48px; margin-top: 16px; padding: 0 15px; background: #000; color: #fff; border: 0; border-radius: 999px; font-size: 15px; font-weight: 500; cursor: pointer; transition: opacity .15s; }\n.send:hover { opacity: .86; }\n.send:focus-visible { outline-offset: 2px; }\n.send:disabled { opacity: .7; cursor: default; }\n.fine { font-size: 13px; color: var(--muted); margin-top: 12px; line-height: 1.45; }\n.fine.error { color: #B3261E; }\n.other { align-self: center; margin-top: 18px; padding: 4px 2px; border: 0; background: none; font-size: 14px; font-weight: 400; color: rgba(0,0,0,.72); text-decoration: underline; text-decoration-color: rgba(0,0,0,.28); text-underline-offset: 3px; cursor: pointer; }\n.other:hover { color: #000; text-decoration-color: currentColor; }\n.other:disabled { cursor: default; }\n/* The country list: over the views, inside the card. */\n.picker { position: absolute; inset: 0; display: flex; flex-direction: column; background: #fff; }\n.back { align-self: flex-start; margin-bottom: 10px; padding: 4px 0; border: 0; background: none; border-radius: 4px; color: var(--muted); font-size: 14px; font-weight: 500; cursor: pointer; }\n.back:hover { color: #000; }\n.picker input { flex: none; }\n.list { list-style: none; flex: 1 1 0; min-height: 0; overflow-y: auto; margin-top: 8px; }\n.list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 15px; }\n.list li .cname { flex: 1 1 auto; min-width: 0; }\n.list li .code { color: var(--muted); }\n.list li.active, .list li:hover { background: #f3f1ec; }\n.list li[aria-selected=\"true\"] .cname { font-weight: 600; }\n.list li.empty { cursor: default; color: var(--muted); font-size: 14px; background: none; }\n.powered { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 20px; font-size: 12px; color: var(--muted); }\n.powered a { text-decoration: none; color: #000; border-radius: 4px; }\n.powered .word { font-size: 16px; line-height: 1; }\n.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n";
20
+ /** The "Sign in with Techne" button's sheet: `dark` (black, for light backgrounds) and `light` (white with a black
21
+ * edge), 44 px or 36 px (`small`) tall. The name only, never the mark beside it. */
22
+ export declare const BUTTON_CSS = "\n:host { all: initial !important; display: block !important; }\n:host([hidden]) { display: none !important; }\n*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n.root { font-family: 'Techne Public Sans', Arial, sans-serif; color: #000; text-align: left; line-height: normal; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }\nbutton, input { font-family: inherit; }\n:focus-visible { outline: 2px solid #000; outline-offset: 3px; }\n[hidden] { display: none !important; }\n.word { font-family: 'Techne Octave', Georgia, serif; font-weight: 500; font-feature-settings: 'dlig' 1; letter-spacing: -.01em; }\n\n:host { display: inline-block !important; }\n.btn { display: inline-flex; align-items: center; height: 44px; padding: 0 22px; border-radius: 999px; font-family: 'Techne Public Sans', Arial, sans-serif; font-size: 15px; font-weight: 500; line-height: 1; white-space: nowrap; cursor: pointer; border: 1.5px solid #000; }\n.btn .word { font-size: 18px; line-height: 1; }\n.btn.dark { background: #000; color: #fff; }\n.btn.light { background: #fff; color: #000; }\n.btn.small { height: 36px; padding: 0 16px; font-size: 14px; }\n.btn.small .word { font-size: 16px; }\n.btn:hover { opacity: .86; }\n.btn:disabled { opacity: .7; cursor: default; }\n";
@@ -0,0 +1,108 @@
1
+ /**
2
+ * The sign-in form's and the button's styles: the Techne sign-in page's own values (ePDS auth-service
3
+ * `login-page.ts`, `phone/country-picker.ts` and shared `brand.ts`, as rendered in the approved mocks), in
4
+ * one sheet that lives in each form's shadow root. Nothing here reaches the host page, and the host page's
5
+ * rules do not reach in: `:host` resets every inherited property with `!important`, which beats the page's
6
+ * own rules on the host element.
7
+ *
8
+ * The two brand fonts are the Techne sign-in page's, loaded from the home PDS (`<pds>/static/fonts/`,
9
+ * served with `Access-Control-Allow-Origin: *`) under names of our own, so a host page's 'Octave' or
10
+ * 'Public Sans' is never touched. `@font-face` does not work inside a shadow root, so {@link fontFaces} goes
11
+ * into the document's head, once.
12
+ */
13
+ /** The font families the sheet names (ours: no host page uses them). */
14
+ export const SERIF = "'Techne Octave', Georgia, serif";
15
+ export const SANS = "'Techne Public Sans', Arial, sans-serif";
16
+ /** The `@font-face` rules for {@link SERIF} and {@link SANS}, from `base` (`<pds>/static/fonts/`). */
17
+ export function fontFaces(base) {
18
+ const face = (family, file, weight) => `@font-face { font-family: '${family}'; src: url('${base}${file}') format('woff2'); font-weight: ${weight}; font-display: swap; }`;
19
+ return [
20
+ face('Techne Octave', 'octave-medium.woff2', 500),
21
+ face('Techne Public Sans', 'public-sans-latin-400-normal.woff2', 400),
22
+ face('Techne Public Sans', 'public-sans-latin-500-normal.woff2', 500),
23
+ face('Techne Public Sans', 'public-sans-latin-700-normal.woff2', 700),
24
+ ].join('\n');
25
+ }
26
+ /** Shared by the form and the button. */
27
+ const BASE = `
28
+ :host { all: initial !important; display: block !important; }
29
+ :host([hidden]) { display: none !important; }
30
+ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
31
+ .root { font-family: ${SANS}; color: #000; text-align: left; line-height: normal; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
32
+ button, input { font-family: inherit; }
33
+ :focus-visible { outline: 2px solid #000; outline-offset: 3px; }
34
+ [hidden] { display: none !important; }
35
+ .word { font-family: ${SERIF}; font-weight: 500; font-feature-settings: 'dlig' 1; letter-spacing: -.01em; }
36
+ `;
37
+ /** The form's sheet. */
38
+ export const FORM_CSS = `${BASE}
39
+ .root { --muted: rgba(0,0,0,.58); --input-border: rgba(0,0,0,.12); }
40
+ .card { width: 100%; max-width: 420px; padding: 28px; display: flex; flex-direction: column; background: #fff; border: 1px solid rgba(0,0,0,.05); border-radius: 20px; box-shadow: 0 6px 24px rgba(0,0,0,.06); }
41
+ .app { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; min-width: 0; }
42
+ .app img { width: 44px; height: 44px; border-radius: 12px; flex: none; display: block; object-fit: cover; }
43
+ .app .name { font-size: 14px; font-weight: 500; color: var(--muted); overflow-wrap: anywhere; }
44
+ /* Every view sits in one grid cell; the country list is laid over it. The cell is as tall as the main view
45
+ whatever tab or view is showing, so the card keeps one size. */
46
+ .views { position: relative; display: grid; flex: 1 0 auto; }
47
+ .view { grid-area: 1 / 1; display: flex; flex-direction: column; min-width: 0; }
48
+ .view.off { visibility: hidden; }
49
+ h1 { font-family: ${SERIF}; font-size: 28px; line-height: 1.2; font-weight: 500; letter-spacing: -.02em; color: #000; margin-bottom: 8px; font-feature-settings: 'dlig' 1; overflow-wrap: anywhere; text-wrap: balance; }
50
+ .lede { color: var(--muted); font-size: 15px; line-height: 1.45; margin-bottom: 24px; text-wrap: pretty; }
51
+ .seg { display: grid; grid-template-columns: 1fr 1fr; background: #EDEBE3; border-radius: 999px; padding: 4px; margin-bottom: 16px; }
52
+ .tab { border: 0; background: none; padding: 9px 0; border-radius: 999px; font-size: 14px; font-weight: 500; color: var(--muted); cursor: pointer; transition: background .15s, color .15s, box-shadow .15s; }
53
+ .tab[aria-selected="true"] { background: #fff; color: #1A130F; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
54
+ .tab:focus-visible { outline-offset: 2px; }
55
+ .fields { display: grid; }
56
+ .field { grid-area: 1 / 1; text-align: left; }
57
+ .field.off { visibility: hidden; }
58
+ label { display: block; font-size: 13px; line-height: 18px; font-weight: 500; color: #000; margin-bottom: 6px; }
59
+ input { width: 100%; height: 48px; padding: 0 14px; border: 1.5px solid var(--input-border); border-radius: 12px; font-size: 16px; color: #000; background: #fff; outline: none; transition: border-color .15s; }
60
+ input:focus { border-color: #000; }
61
+ input:focus-visible { outline: none; }
62
+ input::placeholder { color: rgba(0,0,0,.4); }
63
+ .phone-row { display: flex; gap: 8px; }
64
+ .phone-row input { flex: 1 1 auto; min-width: 0; }
65
+ .country-btn { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; height: 48px; padding: 0 12px; border: 1.5px solid var(--input-border); border-radius: 12px; background: #fff; font-size: 16px; color: #1A130F; cursor: pointer; }
66
+ .country-btn:focus-visible, .country-btn[aria-expanded="true"] { outline: none; border-color: #000; }
67
+ .country-btn .caret { color: var(--muted); font-size: 12px; }
68
+ .flag { font-size: 20px; line-height: 1; }
69
+ .no-flags .flag { display: none; }
70
+ .send { width: 100%; height: 48px; margin-top: 16px; padding: 0 15px; background: #000; color: #fff; border: 0; border-radius: 999px; font-size: 15px; font-weight: 500; cursor: pointer; transition: opacity .15s; }
71
+ .send:hover { opacity: .86; }
72
+ .send:focus-visible { outline-offset: 2px; }
73
+ .send:disabled { opacity: .7; cursor: default; }
74
+ .fine { font-size: 13px; color: var(--muted); margin-top: 12px; line-height: 1.45; }
75
+ .fine.error { color: #B3261E; }
76
+ .other { align-self: center; margin-top: 18px; padding: 4px 2px; border: 0; background: none; font-size: 14px; font-weight: 400; color: rgba(0,0,0,.72); text-decoration: underline; text-decoration-color: rgba(0,0,0,.28); text-underline-offset: 3px; cursor: pointer; }
77
+ .other:hover { color: #000; text-decoration-color: currentColor; }
78
+ .other:disabled { cursor: default; }
79
+ /* The country list: over the views, inside the card. */
80
+ .picker { position: absolute; inset: 0; display: flex; flex-direction: column; background: #fff; }
81
+ .back { align-self: flex-start; margin-bottom: 10px; padding: 4px 0; border: 0; background: none; border-radius: 4px; color: var(--muted); font-size: 14px; font-weight: 500; cursor: pointer; }
82
+ .back:hover { color: #000; }
83
+ .picker input { flex: none; }
84
+ .list { list-style: none; flex: 1 1 0; min-height: 0; overflow-y: auto; margin-top: 8px; }
85
+ .list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 15px; }
86
+ .list li .cname { flex: 1 1 auto; min-width: 0; }
87
+ .list li .code { color: var(--muted); }
88
+ .list li.active, .list li:hover { background: #f3f1ec; }
89
+ .list li[aria-selected="true"] .cname { font-weight: 600; }
90
+ .list li.empty { cursor: default; color: var(--muted); font-size: 14px; background: none; }
91
+ .powered { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 20px; font-size: 12px; color: var(--muted); }
92
+ .powered a { text-decoration: none; color: #000; border-radius: 4px; }
93
+ .powered .word { font-size: 16px; line-height: 1; }
94
+ .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
95
+ `;
96
+ /** The "Sign in with Techne" button's sheet: `dark` (black, for light backgrounds) and `light` (white with a black
97
+ * edge), 44 px or 36 px (`small`) tall. The name only, never the mark beside it. */
98
+ export const BUTTON_CSS = `${BASE}
99
+ :host { display: inline-block !important; }
100
+ .btn { display: inline-flex; align-items: center; height: 44px; padding: 0 22px; border-radius: 999px; font-family: ${SANS}; font-size: 15px; font-weight: 500; line-height: 1; white-space: nowrap; cursor: pointer; border: 1.5px solid #000; }
101
+ .btn .word { font-size: 18px; line-height: 1; }
102
+ .btn.dark { background: #000; color: #fff; }
103
+ .btn.light { background: #fff; color: #000; }
104
+ .btn.small { height: 36px; padding: 0 16px; font-size: 14px; }
105
+ .btn.small .word { font-size: 16px; }
106
+ .btn:hover { opacity: .86; }
107
+ .btn:disabled { opacity: .7; cursor: default; }
108
+ `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "techne-sdk",
3
- "version": "0.13.1",
3
+ "version": "0.14.0",
4
4
  "description": "TechneSDK: sign in (\"Sign in with Techne\", browser OAuth), put, query, useEvent and the read-time check for apps on the Techne platform. Types and clients are generated from the published lexicons; the logic that must match the platform exactly (the check, version ranking, put's order) is Rust compiled to WebAssembly (wasm2js on hosts without it). Datetime fields are plain strings: send Date.prototype.toISOString() (UTC, trailing Z).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -64,6 +64,10 @@
64
64
  "types": "./dist/react/query.d.ts",
65
65
  "default": "./dist/react/query.js"
66
66
  },
67
+ "./react/sign-in": {
68
+ "types": "./dist/react/sign-in.d.ts",
69
+ "default": "./dist/react/sign-in.js"
70
+ },
67
71
  "./wasm": {
68
72
  "types": "./dist/wasm/index.d.ts",
69
73
  "default": "./dist/wasm/index.js"
@@ -93,6 +97,10 @@
93
97
  "types": "./dist/auth/index.d.ts",
94
98
  "default": "./dist/auth/index.js"
95
99
  },
100
+ "./sign-in": {
101
+ "types": "./dist/sign-in/index.d.ts",
102
+ "default": "./dist/sign-in/index.js"
103
+ },
96
104
  "./session": {
97
105
  "types": "./dist/session/index.d.ts",
98
106
  "default": "./dist/session/index.js"
@@ -109,7 +117,7 @@
109
117
  "typecheck": "tsc --noEmit && tsc --noEmit -p src/types-cli",
110
118
  "build": "node ./scripts/build.mjs",
111
119
  "prepack": "npm run build",
112
- "test": "npm run test:inputs && npm run test:catalog && npm run test:nsid && npm run test:versions && npm run test:wasm && npm run test:put && npm run test:query && npm run test:links && npm run test:read && npm run test:react && npm run test:resend && npm run test:connect && npm run test:auth && npm run test:session && npm run test:types-cli && npm run test:package",
120
+ "test": "npm run test:inputs && npm run test:catalog && npm run test:nsid && npm run test:versions && npm run test:wasm && npm run test:put && npm run test:query && npm run test:links && npm run test:read && npm run test:react && npm run test:resend && npm run test:connect && npm run test:auth && npm run test:sign-in && npm run test:session && npm run test:types-cli && npm run test:package",
113
121
  "test:inputs": "node --test ./scripts/inputs-sync.test.mjs",
114
122
  "test:catalog": "node --test ./scripts/gen-catalog.test.mjs",
115
123
  "test:nsid": "node --test ./scripts/gen-nsid.test.mjs",
@@ -123,6 +131,7 @@
123
131
  "test:resend": "node --import tsx --test ./src/resend.test.mjs",
124
132
  "test:connect": "node --import tsx --test ./src/connect.test.mjs",
125
133
  "test:auth": "node --import tsx --test ./src/auth/auth.test.mjs",
134
+ "test:sign-in": "node --import tsx --test ./src/sign-in/sign-in.test.mjs",
126
135
  "test:session": "node --import tsx --test ./src/session/session.test.mjs",
127
136
  "test:package": "node --test ./scripts/package.test.mjs",
128
137
  "gate": "bash ./scripts/gate.sh",
@@ -137,7 +146,8 @@
137
146
  "@atproto/syntax": "^0.4.3",
138
147
  "@atproto/xrpc": "^0.6.12",
139
148
  "@noble/curves": "^2.4.0",
140
- "@noble/hashes": "^2.4.0"
149
+ "@noble/hashes": "^2.4.0",
150
+ "libphonenumber-js": "^1.13.17"
141
151
  },
142
152
  "peerDependencies": {
143
153
  "react": "^19",
@@ -157,6 +167,7 @@
157
167
  "@tanstack/react-query": "^5.107.1",
158
168
  "@types/node": "^22.20.5",
159
169
  "@types/react": "^19.3.0",
170
+ "happy-dom": "^21.0.4",
160
171
  "multiformats": "^9.9.0",
161
172
  "react": "^19.2.3",
162
173
  "react-test-renderer": "^19.2.3",