@serfab/cadre-client 0.0.0-stage → 2.0.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/ADOPTING.md +220 -0
- package/README.md +129 -3
- package/dist/address.d.ts +45 -0
- package/dist/address.js +109 -0
- package/dist/address.js.map +1 -0
- package/dist/app-link/index.d.ts +16 -0
- package/dist/app-link/index.js +17 -0
- package/dist/app-link/index.js.map +1 -0
- package/dist/app-link/join-response.d.ts +31 -0
- package/dist/app-link/join-response.js +87 -0
- package/dist/app-link/join-response.js.map +1 -0
- package/dist/app-link/known-apps.d.ts +32 -0
- package/dist/app-link/known-apps.js +51 -0
- package/dist/app-link/known-apps.js.map +1 -0
- package/dist/app-link/link-request-store.d.ts +50 -0
- package/dist/app-link/link-request-store.js +101 -0
- package/dist/app-link/link-request-store.js.map +1 -0
- package/dist/app-link/links.d.ts +47 -0
- package/dist/app-link/links.js +76 -0
- package/dist/app-link/links.js.map +1 -0
- package/dist/app-link/recommend-links.d.ts +30 -0
- package/dist/app-link/recommend-links.js +33 -0
- package/dist/app-link/recommend-links.js.map +1 -0
- package/dist/app-link/recommendation-store.d.ts +54 -0
- package/dist/app-link/recommendation-store.js +99 -0
- package/dist/app-link/recommendation-store.js.map +1 -0
- package/dist/bootstrap.d.ts +106 -0
- package/dist/bootstrap.js +106 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/inbox.d.ts +10 -0
- package/dist/inbox.js +28 -0
- package/dist/inbox.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/invitation-text.d.ts +81 -0
- package/dist/invitation-text.js +80 -0
- package/dist/invitation-text.js.map +1 -0
- package/dist/lifecycle/background-runner.d.ts +94 -0
- package/dist/lifecycle/background-runner.js +278 -0
- package/dist/lifecycle/background-runner.js.map +1 -0
- package/dist/lifecycle/index.d.ts +9 -0
- package/dist/lifecycle/index.js +10 -0
- package/dist/lifecycle/index.js.map +1 -0
- package/dist/loader.d.ts +47 -0
- package/dist/loader.js +93 -0
- package/dist/loader.js.map +1 -0
- package/dist/model.d.ts +284 -0
- package/dist/model.js +22 -0
- package/dist/model.js.map +1 -0
- package/dist/node-code-text.d.ts +10 -0
- package/dist/node-code-text.js +30 -0
- package/dist/node-code-text.js.map +1 -0
- package/dist/result.d.ts +79 -0
- package/dist/result.js +84 -0
- package/dist/result.js.map +1 -0
- package/dist/sereus/client.d.ts +49 -0
- package/dist/sereus/client.js +420 -0
- package/dist/sereus/client.js.map +1 -0
- package/dist/sereus/edge-host.d.ts +22 -0
- package/dist/sereus/edge-host.js +61 -0
- package/dist/sereus/edge-host.js.map +1 -0
- package/dist/sereus/host.d.ts +57 -0
- package/dist/sereus/host.js +2 -0
- package/dist/sereus/host.js.map +1 -0
- package/dist/sereus/index.d.ts +8 -0
- package/dist/sereus/index.js +9 -0
- package/dist/sereus/index.js.map +1 -0
- package/dist/sereus/invitations.d.ts +16 -0
- package/dist/sereus/invitations.js +196 -0
- package/dist/sereus/invitations.js.map +1 -0
- package/dist/sereus/node-code.d.ts +52 -0
- package/dist/sereus/node-code.js +51 -0
- package/dist/sereus/node-code.js.map +1 -0
- package/dist/store.d.ts +27 -0
- package/dist/store.js +51 -0
- package/dist/store.js.map +1 -0
- package/dist/stores.d.ts +37 -0
- package/dist/stores.js +45 -0
- package/dist/stores.js.map +1 -0
- package/examples/README.md +20 -0
- package/examples/nativescript/cadrons-page.xml +24 -0
- package/examples/nativescript/cadrons-view-model.ts +68 -0
- package/examples/react-native/CadronList.tsx +204 -0
- package/examples/react-native/InvitationPanel.tsx +162 -0
- package/examples/react-native/useStore.ts +11 -0
- package/examples/svelte/CadronList.svelte +86 -0
- package/examples/svelte/InvitationPanel.svelte +79 -0
- package/package.json +65 -3
- package/src/address.ts +125 -0
- package/src/app-link/index.ts +45 -0
- package/src/app-link/join-response.ts +109 -0
- package/src/app-link/known-apps.ts +70 -0
- package/src/app-link/link-request-store.ts +129 -0
- package/src/app-link/links.ts +90 -0
- package/src/app-link/recommend-links.ts +49 -0
- package/src/app-link/recommendation-store.ts +132 -0
- package/src/bootstrap.ts +184 -0
- package/src/globals.d.ts +26 -0
- package/src/inbox.ts +36 -0
- package/src/index.ts +15 -0
- package/src/invitation-text.ts +156 -0
- package/src/lifecycle/background-runner.ts +363 -0
- package/src/lifecycle/index.ts +17 -0
- package/src/loader.ts +103 -0
- package/src/model.ts +299 -0
- package/src/node-code-text.ts +25 -0
- package/src/result.ts +131 -0
- package/src/sereus/client.ts +454 -0
- package/src/sereus/edge-host.ts +81 -0
- package/src/sereus/host.ts +56 -0
- package/src/sereus/index.ts +8 -0
- package/src/sereus/invitations.ts +206 -0
- package/src/sereus/node-code.ts +80 -0
- package/src/store.ts +61 -0
- package/src/stores.ts +59 -0
package/ADOPTING.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Adopting @serfab/cadre-client in an app
|
|
2
|
+
|
|
3
|
+
For whoever wires cadre management into a Sereus app (a person or an agent). The model behind it
|
|
4
|
+
is [The cadre client](https://github.com/gotchoices/sereus/blob/master/docs/cadre/cadre-client.md);
|
|
5
|
+
the API summary is the [README](README.md); screens to copy are in [examples/](examples/README.md).
|
|
6
|
+
|
|
7
|
+
## 1. Install
|
|
8
|
+
|
|
9
|
+
**After a sereus release that includes the package:** `yarn add @serfab/cadre-client`, at the
|
|
10
|
+
same version as the app's `@serfab/cadre-core`. Nothing below applies any more.
|
|
11
|
+
|
|
12
|
+
**Until then**, the package exists only in the sereus repository (`packages/cadre-client`, on
|
|
13
|
+
`master`). It is a peer of cadre-core, so the one rule is: **the app's cadre-core and
|
|
14
|
+
cadre-client's cadre-core must be the same copy.** Which way satisfies it depends on where the
|
|
15
|
+
app takes the rest of the stack from.
|
|
16
|
+
|
|
17
|
+
| The app takes cadre-core, Optimystic, Quereus… from | Take cadre-client from | Spec |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| **Local clones** (a "local stack" mode: `portal:` or `link:` to `ser/sereus/packages/cadre-core` and the rest) | the same sereus clone, linked like the others | `"@serfab/cadre-client": "portal:../sereus/packages/cadre-client"` |
|
|
20
|
+
| **npmjs.org** (published versions) | a tarball packed from a sereus clone | `"@serfab/cadre-client": "file:.local-packages/serfab-cadre-client.tgz"` |
|
|
21
|
+
| — | or wait for the release | — |
|
|
22
|
+
|
|
23
|
+
**Never mix them**: cadre-client linked from the clone while cadre-core comes from npm. Through
|
|
24
|
+
a link, cadre-client's own `import '@serfab/cadre-core'` resolves from where its files really are,
|
|
25
|
+
the clone's workspace, so the app ends up with two copies: TypeScript sees two `CadreNode` types,
|
|
26
|
+
and at run time `instanceof` fails across them (a refused claim is no longer recognised as one).
|
|
27
|
+
|
|
28
|
+
### Linked, with a local stack
|
|
29
|
+
|
|
30
|
+
- Keep the sereus clone pulled and **built**: the link points at its `dist`
|
|
31
|
+
(`yarn workspace @serfab/cadre-client build` in the clone, or the whole repo's `yarn build`).
|
|
32
|
+
- Link it the way the app links cadre-core. In a React Native app that means whatever its Metro
|
|
33
|
+
config already does for the local stack (watch folders, source aliases): add cadre-client to the
|
|
34
|
+
same lists.
|
|
35
|
+
- A change in the clone shows up after a rebuild there; no reinstall.
|
|
36
|
+
|
|
37
|
+
### A tarball, with the stack from npm
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
(cd ../sereus/packages/cadre-client && yarn build && yarn pack --out "$OLDPWD/.local-packages/serfab-cadre-client.tgz")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- In `package.json`: `"@serfab/cadre-client": "file:.local-packages/serfab-cadre-client.tgz"`,
|
|
44
|
+
then `yarn install`. Add `.local-packages/` to `.gitignore`.
|
|
45
|
+
- Installed by copy, its peer resolves from the app's own `node_modules`: one cadre-core. React
|
|
46
|
+
Native needs no Metro changes.
|
|
47
|
+
- `yarn pack` rewrites the `workspace:^` peer range to the released one (`^1.25.0`).
|
|
48
|
+
- After a change to the package: repack, then `yarn install` again.
|
|
49
|
+
|
|
50
|
+
## 2. Create the client
|
|
51
|
+
|
|
52
|
+
**On cadre-core's edge node** (React Native with `@serfab/cadre-rn`'s `createPhoneNode`, or
|
|
53
|
+
`createEdgeNode` on the web and NativeScript):
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { createCadreClient, edgeNodeHost } from '@serfab/cadre-client/sereus';
|
|
57
|
+
|
|
58
|
+
const client = createCadreClient(edgeNodeHost(phone, {
|
|
59
|
+
ownerKeyStore, // the kit's SecureStoreKeyStore: lets the person back up the owner key
|
|
60
|
+
preferences: { // where cadron preferences live; AsyncStorage on React Native
|
|
61
|
+
load: async () => (await AsyncStorage.getItem('cadronPreferences')) ?? undefined,
|
|
62
|
+
save: text => AsyncStorage.setItem('cadronPreferences', text),
|
|
63
|
+
},
|
|
64
|
+
}));
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**With a node service of the app's own** (a hand-built `CadreNode`), implement `CadreHost`. A
|
|
68
|
+
reference, over a service that builds the node and can rebuild it (`service.node`,
|
|
69
|
+
`service.restart(options)`):
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import type { CadreHost } from '@serfab/cadre-client/sereus';
|
|
73
|
+
|
|
74
|
+
// Relays are read when a node is BUILT (`network.relayAddrs`), so the service keeps them and a new
|
|
75
|
+
// set rebuilds the node. Persist them where the service keeps its start options.
|
|
76
|
+
const relaySlot = { load: () => AsyncStorage.getItem('relays'), save: (t: string) => AsyncStorage.setItem('relays', t) };
|
|
77
|
+
const readRelays = async (): Promise<string[]> => JSON.parse((await relaySlot.load()) ?? '[]');
|
|
78
|
+
|
|
79
|
+
const host: CadreHost = {
|
|
80
|
+
ownerKeyStore, // or exportOwnerKey, below
|
|
81
|
+
preferences, // as above
|
|
82
|
+
node: {
|
|
83
|
+
get node() { return service.node; }, // the running node, or null
|
|
84
|
+
on: (event, handler) => service.on(event, handler), // must re-attach to each node the service builds
|
|
85
|
+
getRelayAddrs: readRelays,
|
|
86
|
+
async applyRelays(addrs) {
|
|
87
|
+
const current = await readRelays();
|
|
88
|
+
if (addrs.length === current.length && addrs.every((a, i) => a === current[i])) return;
|
|
89
|
+
await relaySlot.save(JSON.stringify(addrs));
|
|
90
|
+
await service.restart({ relayAddrs: addrs }); // stop, build with the new relays, start
|
|
91
|
+
},
|
|
92
|
+
partyId: () => service.partyId,
|
|
93
|
+
ownerEnrolled: () => service.ownerEnrolled, // owner genesis ran: this device can sign
|
|
94
|
+
relayStatus: () => service.node?.getRelayReservationState().status ?? null,
|
|
95
|
+
onReachabilityChange(onChange) {
|
|
96
|
+
// The control node's own addresses changing (`self:peer:update`), and each rebuild.
|
|
97
|
+
const watch = () => {
|
|
98
|
+
const control = service.node?.getControlNode();
|
|
99
|
+
control?.addEventListener('self:peer:update', onChange);
|
|
100
|
+
return () => control?.removeEventListener('self:peer:update', onChange);
|
|
101
|
+
};
|
|
102
|
+
let unwatch = watch();
|
|
103
|
+
const offRestart = service.onRestart(() => { unwatch(); unwatch = watch(); onChange(); });
|
|
104
|
+
return () => { offRestart(); unwatch(); };
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
- **No relays?** An app whose service cannot rebuild its node can make `applyRelays` throw; the
|
|
111
|
+
client reports the failure and leaves the relays as they were. Reachability then counts only an
|
|
112
|
+
always-on cadron with a public address.
|
|
113
|
+
- **The owner key kept its own way** (derived from the node's identity, say): give
|
|
114
|
+
`exportOwnerKey: async () => privateKeyOrNull` instead of `ownerKeyStore`.
|
|
115
|
+
- Create the client once, for the app's lifetime.
|
|
116
|
+
|
|
117
|
+
## 3. The cadre screen
|
|
118
|
+
|
|
119
|
+
| Show or do | Call | Store |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| This device and its cadrons, with a status dot each | `client.cadre.status()` | `cadreStore(client)`; `cadronPresence(machine)` per row |
|
|
122
|
+
| Add a cadron from its code (scanned or pasted) | `cadre.inspectNodeCode(text)`, then after the person approves `cadre.claimNode(text)` | `nodeCodeInbox()` holds a code that arrives early |
|
|
123
|
+
| Add a node listening for seeds, by its address | `cadre.connectNode(address)` (returns a seed to hand over when not delivered) | |
|
|
124
|
+
| A seed for a node not created yet | `cadre.createSeed()` (authorizes nothing) | |
|
|
125
|
+
| Remove a cadron | `cadre.planRemoval(peerId)` for the confirmation, then `cadre.removeMachine(peerId)` | `client.changes.removed(peerId => …)` |
|
|
126
|
+
| Back up the owner key (behind a confirmed, private reveal) | `cadre.exportOwnerKey()` | |
|
|
127
|
+
| Relays | `client.relays.get()` / `set(addrs)` | |
|
|
128
|
+
| Whether anybody can reach this device | `client.reachability.get()` | `reachabilityStore(client)` |
|
|
129
|
+
| Preferred cadrons, their names, addresses per invitation | `client.invitations.preferences()` / `setPreferences(changes)` | re-read on `client.changes.invitations` |
|
|
130
|
+
|
|
131
|
+
Rules for the screen:
|
|
132
|
+
|
|
133
|
+
- **Say which machine a cadron is.** Title a row with the person's name for it, else its host name
|
|
134
|
+
(`suggestedName(machine)`, e.g. `server.example.com`), and under it the host and the short id
|
|
135
|
+
(`shortPeerId`) they can match against the machine's own host. Name a new cadron after its host
|
|
136
|
+
right after the claim. Mark a cadron whose `trusted` is false as not verified.
|
|
137
|
+
- **Never claim on a code alone.** A link or QR code can come from anyone: show what
|
|
138
|
+
`inspectNodeCode` says (the cadron's short id, whether it is reachable from anywhere, and this
|
|
139
|
+
cadre's network id and owner fingerprint, which the node shows once it joins) and claim only
|
|
140
|
+
after the person approves.
|
|
141
|
+
- **An honest removal:** confirm with what `planRemoval` says (the invitations it closes, the
|
|
142
|
+
closed strands re-keyed). Keep per-cadron state (saved addresses) in step with `changes.removed`.
|
|
143
|
+
- **A store kept subscribed app-wide** (a status badge): `cadreStore(client, { pollMs })` can poll
|
|
144
|
+
less often; [What re-reads a store](https://github.com/gotchoices/sereus/blob/master/docs/cadre/cadre-client.md#what-re-reads-a-store)
|
|
145
|
+
says what the poll is for.
|
|
146
|
+
- **Never log a node code or an invitation link**; they carry secrets. Log peer ids.
|
|
147
|
+
- **The status dot:** connected (green) means this device holds a connection to the cadron now;
|
|
148
|
+
recent (amber) that it was seen within the last 15 minutes (label it "Seen recently", not
|
|
149
|
+
"Running": it stays recent for a while after the machine stops). Another phone usually shows
|
|
150
|
+
recent, not connected.
|
|
151
|
+
- **Relays:** `relays.set` returns at once and the node rebuilds behind it; a failure shows as
|
|
152
|
+
`Reachability.relayError`, with a reachability change.
|
|
153
|
+
|
|
154
|
+
## 4. Invitations
|
|
155
|
+
|
|
156
|
+
Wherever the app mints a strand invitation, route it through the client, and show its readiness
|
|
157
|
+
and details beside it:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
const who = await client.invitable(); // somebody must be able to answer
|
|
161
|
+
if (!who.ok) return explainUnreachable(who.error); // kind 'unreachable': suggest a relay or a cadron
|
|
162
|
+
|
|
163
|
+
const invitation = await node.createOpenInvitation(sAppId, validForMs);
|
|
164
|
+
await node.publishFormationInvite(invitation.token, sAppId, { expiresAtMs, strandId, totalUses: 1 });
|
|
165
|
+
const token = node.encodeInvitation(await client.invitations.withBootstrap(invitation));
|
|
166
|
+
// the link the app shares carries `token`
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
- **`withBootstrap`** replaces cadre-core's address list with the person's cadrons that reach from
|
|
170
|
+
anywhere (preferred first, at most their `maxAddrs`). It never fails: on any problem it returns
|
|
171
|
+
the invitation as it came.
|
|
172
|
+
- **Readiness:** `invitationReadinessStore(client, strandId, { newStrand })`, with `newStrand: true`
|
|
173
|
+
when this invitation founded the strand just now. Show "ready to hand out" only on `ready`; on
|
|
174
|
+
`no-cadron`, say only this device can answer.
|
|
175
|
+
- **The readable invitation:** `client.invitations.describe(token, link)`, behind a "What's in this
|
|
176
|
+
invitation" control. Show `cadrons`: each machine as the cadre screen shows it (its label, its
|
|
177
|
+
`presence` dot, "your machine" or, when `yours` is false, "not one of your machines"), with its
|
|
178
|
+
addresses under it. Say how many it names against `maxAddrs`, and when `cadronAddrsLeftOut` is 0
|
|
179
|
+
that the person's machines have no other usable address, so a short list does not look like a
|
|
180
|
+
fault.
|
|
181
|
+
- **Changing one invitation's addresses:** each address can be a checkbox, the ones it names
|
|
182
|
+
(`included`) checked and the others it could name unchecked. A change calls
|
|
183
|
+
`client.invitations.rebootstrap(token, addrs)` and the app rebuilds its link and QR code from the
|
|
184
|
+
returned token and keeps it with the invitation. The token and terms do not change, so a link
|
|
185
|
+
already handed out still works with its old addresses. Keep at least one checked.
|
|
186
|
+
- **The QR code:** let a tap open it full screen, dark on white.
|
|
187
|
+
|
|
188
|
+
## 5. Errors
|
|
189
|
+
|
|
190
|
+
Every operation returns `CadreResult<T>`; render `error.kind` (and `reason` where given) through
|
|
191
|
+
the app's own strings, and fall back to `error.message`. `CADRE_ERROR_KINDS` lists every kind for a
|
|
192
|
+
catalog; `retryable` says whether trying again can help.
|
|
193
|
+
|
|
194
|
+
| Kind | `reason` |
|
|
195
|
+
|---|---|
|
|
196
|
+
| `unreachable` | |
|
|
197
|
+
| `unavailable` | `owner-not-ready` (owner genesis has not finished; try again shortly) |
|
|
198
|
+
| `invalid-node-code` | `not-node-code`, `newer-version`, `damaged`; for a good code of a known machine, `this-device`, `already-a-cadron` |
|
|
199
|
+
| `node-unreachable` | `anywhere`, `home-network` (the node's reach) |
|
|
200
|
+
| `claim-refused` | the node's refusal code, when it sent one (e.g. `claim-rate-limited`) |
|
|
201
|
+
| `claim-failed` | `busy` (a claim is already running) |
|
|
202
|
+
| `removal-refused` | `not-an-owner`, `self` |
|
|
203
|
+
| `invalid-address` | `unparsable`, `no-peer-id` |
|
|
204
|
+
| `not-supported`, `unexpected` | |
|
|
205
|
+
|
|
206
|
+
## 6. Checklist
|
|
207
|
+
|
|
208
|
+
- [ ] One `@serfab/cadre-core` in the app (the package is a peer, not a second copy).
|
|
209
|
+
- [ ] The client created once, with `ownerKeyStore` and `preferences`.
|
|
210
|
+
- [ ] The cadre screen: status dots, add with approval, remove after `planRemoval`, owner key backup, relays.
|
|
211
|
+
- [ ] Incoming node-code links handed to a `nodeCodeInbox`; the screen takes them when it can prompt.
|
|
212
|
+
- [ ] Invitations minted through `withBootstrap`; readiness shown with the right `newStrand`.
|
|
213
|
+
- [ ] Error kinds in the app's string catalog.
|
|
214
|
+
- [ ] No node code or invitation link in logs.
|
|
215
|
+
|
|
216
|
+
## Not covered yet
|
|
217
|
+
|
|
218
|
+
Joining an existing cadre from a second app (`EdgeNode.joinCadre`, strand move, dissolving the
|
|
219
|
+
former party), cadre invitations and join approvals, and owner keys beyond backup. Each is cadre-core API the package does not wrap yet; see
|
|
220
|
+
[Several apps in one cadre](https://github.com/gotchoices/sereus/blob/master/docs/cadre/apps.md).
|
package/README.md
CHANGED
|
@@ -1,3 +1,129 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @serfab/cadre-client
|
|
2
|
+
|
|
3
|
+
Cadre management for a Sereus app, without UI: the person's **cadrons** (the machines of their
|
|
4
|
+
cadre), claiming a node by its code, removing one, backing up the owner key, relays, whether
|
|
5
|
+
anybody can reach this device, and which cadrons an invitation names. Every operation returns a
|
|
6
|
+
result instead of throwing; each piece of screen state is a store any UI framework binds to.
|
|
7
|
+
|
|
8
|
+
The model behind it: [The cadre client](https://github.com/gotchoices/sereus/blob/master/docs/cadre/cadre-client.md).
|
|
9
|
+
Wiring it into an app, step by step: [ADOPTING.md](ADOPTING.md). Screens to copy (React Native,
|
|
10
|
+
Svelte, NativeScript): [examples/](examples/README.md).
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
yarn add @serfab/cadre-client @serfab/cadre-core
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`@serfab/cadre-core` is a peer dependency: the app brings its own, one copy.
|
|
19
|
+
|
|
20
|
+
## Entry points
|
|
21
|
+
|
|
22
|
+
- **`@serfab/cadre-client`** loads no cadre-core code. Types (`Cadron`, `CadreStatus`,
|
|
23
|
+
`Reachability`, `CadronPreferences`, `BootstrapPlan`, `InvitationText`, …), results
|
|
24
|
+
(`CadreResult`, `cadreOk`, `cadreFail`), node-code text (`isNodeCode`, `nodeCodeFromUrl`) and the
|
|
25
|
+
one-slot `nodeCodeInbox`,
|
|
26
|
+
address judgement (`addressKind`, `nodeReach`), the pure planner (`planBootstrap`,
|
|
27
|
+
`describeInvitation`) and stores (`cadreStore`, `reachabilityStore`,
|
|
28
|
+
`invitationReadinessStore`, `writable`, `loader`; `cadreStore(view, { pollMs })`).
|
|
29
|
+
- **`@serfab/cadre-client/sereus`** works over a running node: `createCadreClient(host)`,
|
|
30
|
+
`edgeNodeHost(edge, options)`, `readNodeCode`, `classifyClaimFailure`.
|
|
31
|
+
- **`@serfab/cadre-client/app-link`**: two Sereus apps on one device handing a join request and its
|
|
32
|
+
answer to each other by link, and recommending an app: the link builders and parser, the
|
|
33
|
+
response codec, `installedSereusApps(canOpenURL)`, `LinkRequestStore`, `AppRecommendationStore`.
|
|
34
|
+
The platform registers the URL schemes and listens for links (on React Native, `@serfab/cadre-rn`).
|
|
35
|
+
- **`@serfab/cadre-client/lifecycle`**: `createBackgroundRunner`, hibernating the node in the
|
|
36
|
+
background and resuming it on return, over the platform's app-state events (`AppStateLike`).
|
|
37
|
+
|
|
38
|
+
## Using it
|
|
39
|
+
|
|
40
|
+
On cadre-core's edge node (React Native with `@serfab/cadre-rn`'s `createPhoneNode`, the web or
|
|
41
|
+
NativeScript with `createEdgeNode`) the host is ready-made:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { createCadreClient, edgeNodeHost } from '@serfab/cadre-client/sereus';
|
|
45
|
+
import { cadreStore, reachabilityStore } from '@serfab/cadre-client';
|
|
46
|
+
|
|
47
|
+
const client = createCadreClient(edgeNodeHost(phone, { ownerKeyStore, preferences: mySlot }));
|
|
48
|
+
|
|
49
|
+
const cadrons = cadreStore(client); // { state, value: CadreStatus, error }; each cadron's
|
|
50
|
+
// `connected`, `lastSeenAt` → cadronPresence(m): a status dot
|
|
51
|
+
const reach = reachabilityStore(client); // { state, value: Reachability, error }
|
|
52
|
+
|
|
53
|
+
await client.cadre.inspectNodeCode(scanned); // preview (peer, reach, this cadre's id and owner fingerprint) to approve
|
|
54
|
+
await client.cadre.claimNode(scanned); // after they approve
|
|
55
|
+
const who = await client.invitable(); // before minting a strand invitation
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Adding and removing cadrons
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
await client.cadre.connectNode('/dns4/node.example.com/tcp/443/wss/p2p/<peerId>'); // a node listening for seeds:
|
|
62
|
+
// authorized, seed delivered (or returned to hand over another way)
|
|
63
|
+
await client.cadre.createSeed(); // for a node not created yet; authorizes nothing
|
|
64
|
+
|
|
65
|
+
const plan = await client.cadre.planRemoval(peerId); // invitations it closes, closed strands re-keyed
|
|
66
|
+
await client.cadre.removeMachine(peerId); // the complete removal; `removal-refused` for self / no owner key
|
|
67
|
+
client.changes.removed(peerId => forgetSavedAddresses(peerId)); // here, or found gone on a re-read
|
|
68
|
+
|
|
69
|
+
const inbox = nodeCodeInbox(); // hold a code that arrives before the screen can show it
|
|
70
|
+
linking.onUrl(url => inbox.offer(url)); // the app's link listener
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`preferences` is any `{ load(): Promise<string | undefined>; save(text): Promise<void> }`; without
|
|
74
|
+
it, cadron preferences last for the session. The text is opaque to the app (it carries its own
|
|
75
|
+
format version). An app with its own node service implements `CadreHost` itself
|
|
76
|
+
([ADOPTING.md](ADOPTING.md) has one over a plain `CadreNode`); `CadreHost.exportOwnerKey` serves an
|
|
77
|
+
app that keeps the owner key its own way.
|
|
78
|
+
|
|
79
|
+
### Invitations
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
await client.invitations.setPreferences({ preferred: [homePeerId], names: { [homePeerId]: 'home' }, maxAddrs: 2 });
|
|
83
|
+
|
|
84
|
+
const inv = await node.createOpenInvitation(sAppId, validForMs);
|
|
85
|
+
const token = node.encodeInvitation(await client.invitations.withBootstrap(inv));
|
|
86
|
+
|
|
87
|
+
const ready = invitationReadinessStore(client, strandId, { newStrand: true }); // 'waiting' → 'ready'
|
|
88
|
+
const words = await client.invitations.describe(token, link); // per machine: presence, yours; per address: kind, host, port, included
|
|
89
|
+
const edited = await client.invitations.rebootstrap(token, chosenAddrs); // the same invitation, the person's own list
|
|
90
|
+
const plan = await client.invitations.bootstrapPlan(); // the list and its warnings, before minting
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`CadronPreferences`: `preferred` (peer ids, in order), `names`, `maxAddrs` (1–8, default 2),
|
|
94
|
+
`thisDevice` (`'fallback'` default, `'always'`, `'never'`), `allowPrivate` (default false).
|
|
95
|
+
|
|
96
|
+
### Binding a store
|
|
97
|
+
|
|
98
|
+
A store follows the Svelte store contract plus `get()`, and is reference-counted (it reads,
|
|
99
|
+
subscribes and polls only while something is subscribed):
|
|
100
|
+
|
|
101
|
+
- **Svelte:** `$cadrons`.
|
|
102
|
+
- **React / React Native:** `useSyncExternalStore(store.subscribe, store.get)`.
|
|
103
|
+
- **NativeScript:** copy each value into an `Observable` from `subscribe`.
|
|
104
|
+
|
|
105
|
+
Errors carry a stable `kind` (and sometimes a `reason`) for an app's own string catalog, and an
|
|
106
|
+
English `message` for logs.
|
|
107
|
+
|
|
108
|
+
## Using it from source before a release
|
|
109
|
+
|
|
110
|
+
Until a sereus release includes it, take it from a sereus clone. The app's cadre-core and this
|
|
111
|
+
package's must be the same copy, so:
|
|
112
|
+
|
|
113
|
+
- **The app runs the whole stack from local clones** (a local-stack mode: cadre-core, Optimystic,
|
|
114
|
+
Quereus by `portal:` / `link:`): link this package from the same clone,
|
|
115
|
+
`"@serfab/cadre-client": "portal:../sereus/packages/cadre-client"`, built (`yarn build` there).
|
|
116
|
+
- **The app takes the stack from npm:** install a packed tarball (`yarn build && yarn pack --out
|
|
117
|
+
<app>/.local-packages/serfab-cadre-client.tgz` here, then `"file:.local-packages/serfab-cadre-client.tgz"`
|
|
118
|
+
in the app). Repack and reinstall after each change.
|
|
119
|
+
- **Never link it while cadre-core comes from npm:** its cadre-core import would resolve to this
|
|
120
|
+
repository's copy, a second one (two `CadreNode` types, `instanceof` failing across them).
|
|
121
|
+
|
|
122
|
+
Step by step: [ADOPTING.md](ADOPTING.md), "1. Install".
|
|
123
|
+
|
|
124
|
+
## Rules the package keeps
|
|
125
|
+
|
|
126
|
+
- Imports only `@serfab/cadre-core`, `@multiformats/multiaddr` and its own files; the stack-free
|
|
127
|
+
entry point imports no cadre-core (`test/standalone.spec.ts`).
|
|
128
|
+
- No UI, no platform module, no host globals beyond timers and `console` (`src/globals.d.ts`).
|
|
129
|
+
- English only in `message`; everything a UI shows comes from a code.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { NodeReach } from './model.js';
|
|
2
|
+
/**
|
|
3
|
+
* How far an address reaches for a phone dialing it, as cadre-core's `classifyDialAddress` judges
|
|
4
|
+
* it, with one difference (below):
|
|
5
|
+
*
|
|
6
|
+
* - `relay`: through a relay (`/p2p-circuit`) reached over a WebSocket, from anywhere while the
|
|
7
|
+
* reservation holds;
|
|
8
|
+
* - `webrtc`: a relay hop then WebRTC, from anywhere only if ICE finds a path;
|
|
9
|
+
* - `name` / `public`: a DNS name or public IP with a WebSocket, from anywhere;
|
|
10
|
+
* - `private`: a private-network IP, only from the same network;
|
|
11
|
+
* - `loopback`: the machine itself, never from another one.
|
|
12
|
+
*
|
|
13
|
+
* Null when no phone can dial it at all: plain TCP (phones dial WebSocket and relays only), a
|
|
14
|
+
* relay reached over plain TCP, the unspecified address, or anything unparsable. The relay hop is
|
|
15
|
+
* the difference: `classifyDialAddress` calls any relayed address `relay`.
|
|
16
|
+
*/
|
|
17
|
+
export type CadronAddressKind = 'relay' | 'webrtc' | 'name' | 'public' | 'private' | 'loopback';
|
|
18
|
+
interface Component {
|
|
19
|
+
name: string;
|
|
20
|
+
value?: string;
|
|
21
|
+
}
|
|
22
|
+
/** The address's components, or null when it does not parse. */
|
|
23
|
+
export declare function addressComponents(addr: string): Component[] | null;
|
|
24
|
+
export declare function addressKind(addr: string): CadronAddressKind | null;
|
|
25
|
+
/** Reaches from anywhere: what an invitation should name. */
|
|
26
|
+
export declare function reachesAnywhere(kind: CadronAddressKind | null): boolean;
|
|
27
|
+
/** Best first for an invitation: a direct name or public address, then a relay, then WebRTC, then private. */
|
|
28
|
+
export declare const ADDRESS_KIND_RANK: Record<CadronAddressKind, number>;
|
|
29
|
+
/** `anywhere` when at least one address names a public IP or a DNS name, else `home-network`. */
|
|
30
|
+
export declare function nodeReach(multiaddrs: readonly string[]): NodeReach;
|
|
31
|
+
/**
|
|
32
|
+
* The address's host is a DNS name or a public IP. The host is its first component, so a relayed
|
|
33
|
+
* address is judged by its relay.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isPublicAddress(addr: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* A name for a machine from its addresses: the first DNS host it is reached at directly
|
|
38
|
+
* (`server.example.com`), or null. A relayed address names the relay, not the machine, so it is skipped;
|
|
39
|
+
* so is `localhost`. For the claim prompt ("Add server.example.com?"), a row's subtitle, and the name
|
|
40
|
+
* dialog's starting text.
|
|
41
|
+
*/
|
|
42
|
+
export declare function suggestedName(machine: {
|
|
43
|
+
addresses: readonly string[];
|
|
44
|
+
}): string | null;
|
|
45
|
+
export {};
|
package/dist/address.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Judging an address for a phone dialing it: from anywhere, only on the same network, or not at
|
|
3
|
+
* all. Parsed with `@multiformats/multiaddr`; the private-range check is a small built-in one, so
|
|
4
|
+
* this entry point loads no stack code.
|
|
5
|
+
*/
|
|
6
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
7
|
+
/** The address's components, or null when it does not parse. */
|
|
8
|
+
export function addressComponents(addr) {
|
|
9
|
+
try {
|
|
10
|
+
return multiaddr(addr).getComponents().map(c => ({ name: c.name, value: c.value }));
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const DNS = new Set(['dns', 'dns4', 'dns6', 'dnsaddr']);
|
|
17
|
+
const hasWebSocket = (components) => components.some(c => c.name === 'ws' || c.name === 'wss');
|
|
18
|
+
export function addressKind(addr) {
|
|
19
|
+
const components = addressComponents(addr);
|
|
20
|
+
if (!components)
|
|
21
|
+
return null;
|
|
22
|
+
const circuit = components.findIndex(c => c.name === 'p2p-circuit');
|
|
23
|
+
if (circuit >= 0) {
|
|
24
|
+
// The hop to the relay is dialed like any other address: a phone reaches a relay over a
|
|
25
|
+
// WebSocket only, never plain TCP.
|
|
26
|
+
if (!hasWebSocket(components.slice(0, circuit)))
|
|
27
|
+
return null;
|
|
28
|
+
return components.slice(circuit + 1).some(c => c.name === 'webrtc') ? 'webrtc' : 'relay';
|
|
29
|
+
}
|
|
30
|
+
if (!hasWebSocket(components))
|
|
31
|
+
return null;
|
|
32
|
+
return hostKind(components[0]);
|
|
33
|
+
}
|
|
34
|
+
function hostKind(host) {
|
|
35
|
+
if (!host?.value)
|
|
36
|
+
return null;
|
|
37
|
+
if (DNS.has(host.name))
|
|
38
|
+
return host.value === 'localhost' ? 'loopback' : 'name';
|
|
39
|
+
if (host.name === 'ip4') {
|
|
40
|
+
if (host.value === '0.0.0.0')
|
|
41
|
+
return null;
|
|
42
|
+
if (host.value.startsWith('127.'))
|
|
43
|
+
return 'loopback';
|
|
44
|
+
return isPrivateIp4(host.value) ? 'private' : 'public';
|
|
45
|
+
}
|
|
46
|
+
if (host.name === 'ip6') {
|
|
47
|
+
const ip = host.value.toLowerCase();
|
|
48
|
+
if (ip === '::')
|
|
49
|
+
return null;
|
|
50
|
+
if (ip === '::1')
|
|
51
|
+
return 'loopback';
|
|
52
|
+
return isPrivateIp6(ip) ? 'private' : 'public';
|
|
53
|
+
}
|
|
54
|
+
return host.name === 'ip6zone' ? 'private' : null;
|
|
55
|
+
}
|
|
56
|
+
/** Reaches from anywhere: what an invitation should name. */
|
|
57
|
+
export function reachesAnywhere(kind) {
|
|
58
|
+
return kind === 'name' || kind === 'public' || kind === 'relay' || kind === 'webrtc';
|
|
59
|
+
}
|
|
60
|
+
/** Best first for an invitation: a direct name or public address, then a relay, then WebRTC, then private. */
|
|
61
|
+
export const ADDRESS_KIND_RANK = { name: 0, public: 0, relay: 1, webrtc: 2, private: 3, loopback: 4 };
|
|
62
|
+
/** `anywhere` when at least one address names a public IP or a DNS name, else `home-network`. */
|
|
63
|
+
export function nodeReach(multiaddrs) {
|
|
64
|
+
return multiaddrs.some(isPublicAddress) ? 'anywhere' : 'home-network';
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The address's host is a DNS name or a public IP. The host is its first component, so a relayed
|
|
68
|
+
* address is judged by its relay.
|
|
69
|
+
*/
|
|
70
|
+
export function isPublicAddress(addr) {
|
|
71
|
+
const kind = hostKind(addressComponents(addr)?.[0]);
|
|
72
|
+
return kind === 'name' || kind === 'public';
|
|
73
|
+
}
|
|
74
|
+
function isPrivateIp4(ip) {
|
|
75
|
+
const o = ip.split('.').map(Number);
|
|
76
|
+
if (o.length !== 4 || o.some(n => !Number.isInteger(n) || n < 0 || n > 255))
|
|
77
|
+
return true; // unparsable: not public
|
|
78
|
+
const [a, b] = o;
|
|
79
|
+
return a === 10 || a === 127 || a === 0
|
|
80
|
+
|| (a === 172 && b >= 16 && b <= 31)
|
|
81
|
+
|| (a === 192 && b === 168)
|
|
82
|
+
|| (a === 169 && b === 254)
|
|
83
|
+
|| (a === 100 && b >= 64 && b <= 127); // carrier-grade NAT, Tailscale
|
|
84
|
+
}
|
|
85
|
+
function isPrivateIp6(ip) {
|
|
86
|
+
if (ip.startsWith('::ffff:'))
|
|
87
|
+
return isPrivateIp4(ip.slice(7));
|
|
88
|
+
const first = parseInt(ip.split(':')[0] || '0', 16);
|
|
89
|
+
return (first & 0xfe00) === 0xfc00 // fc00::/7 unique local
|
|
90
|
+
|| (first & 0xffc0) === 0xfe80; // fe80::/10 link local
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A name for a machine from its addresses: the first DNS host it is reached at directly
|
|
94
|
+
* (`server.example.com`), or null. A relayed address names the relay, not the machine, so it is skipped;
|
|
95
|
+
* so is `localhost`. For the claim prompt ("Add server.example.com?"), a row's subtitle, and the name
|
|
96
|
+
* dialog's starting text.
|
|
97
|
+
*/
|
|
98
|
+
export function suggestedName(machine) {
|
|
99
|
+
for (const addr of machine.addresses) {
|
|
100
|
+
const components = addressComponents(addr);
|
|
101
|
+
if (!components || components.some(c => c.name === 'p2p-circuit'))
|
|
102
|
+
continue;
|
|
103
|
+
const host = components[0];
|
|
104
|
+
if (host && DNS.has(host.name) && host.value && host.value !== 'localhost')
|
|
105
|
+
return host.value;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAsBpD,gEAAgE;AAChE,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC7C,IAAI,CAAC;QACJ,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACrF,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC;AAED,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AACxD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CAAC,CAAC,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;IACpD,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,MAAM,CAAC,wBAAwB;WACvD,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,MAAM,CAAC,CAAC,uBAAuB;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,OAAyC;IACtE,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtC,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,CAAC;YAAE,SAAS;QAC5E,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC;IAC/F,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@serfab/cadre-client/app-link` — what two Sereus apps on one device need to hand a join request
|
|
3
|
+
* and its answer to each other by opening each other with a link, and for one to recommend another.
|
|
4
|
+
* See docs/cadre/apps.md → "Between apps on one phone".
|
|
5
|
+
*
|
|
6
|
+
* Platform-neutral: the app passes its platform's pieces in (`Linking.canOpenURL` on React Native,
|
|
7
|
+
* a storage slot), so this runs anywhere, a Node test included. Listening for incoming links and
|
|
8
|
+
* registering the URL schemes stay with the platform (on React Native, `@serfab/cadre-rn`'s config
|
|
9
|
+
* plugin and the app's linking handler).
|
|
10
|
+
*/
|
|
11
|
+
export { installedSereusApps, KNOWN_SEREUS_APPS, type SereusApp } from './known-apps.js';
|
|
12
|
+
export { CADRE_JOIN_RESPONSE_PREFIX, decodeCadreJoinResponse, encodeCadreJoinResponse, type CadreJoinResponse, type JoinRefusal, } from './join-response.js';
|
|
13
|
+
export { CADRE_LINK_MAX_LENGTH, CadreLinkTooLongError, joinRequestLink, joinResponseLink, parseCadreLink, recommendedByLink, type CadreLink, } from './links.js';
|
|
14
|
+
export { LINK_REQUEST_TTL_MS, LinkRequestStore, UnsolicitedJoinResponseError, type OpenLinkRequest, } from './link-request-store.js';
|
|
15
|
+
export { AppRecommendationStore, RECOMMENDATION_TTL_MS, type AppRecommendation, } from './recommendation-store.js';
|
|
16
|
+
export { RECOMMENDED_BY_REFERRER_PREFIX, recommendedByReferrer, recommendedBySchemeFromReferrer, storePageLink, type StorePlatform, } from './recommend-links.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@serfab/cadre-client/app-link` — what two Sereus apps on one device need to hand a join request
|
|
3
|
+
* and its answer to each other by opening each other with a link, and for one to recommend another.
|
|
4
|
+
* See docs/cadre/apps.md → "Between apps on one phone".
|
|
5
|
+
*
|
|
6
|
+
* Platform-neutral: the app passes its platform's pieces in (`Linking.canOpenURL` on React Native,
|
|
7
|
+
* a storage slot), so this runs anywhere, a Node test included. Listening for incoming links and
|
|
8
|
+
* registering the URL schemes stay with the platform (on React Native, `@serfab/cadre-rn`'s config
|
|
9
|
+
* plugin and the app's linking handler).
|
|
10
|
+
*/
|
|
11
|
+
export { installedSereusApps, KNOWN_SEREUS_APPS } from './known-apps.js';
|
|
12
|
+
export { CADRE_JOIN_RESPONSE_PREFIX, decodeCadreJoinResponse, encodeCadreJoinResponse, } from './join-response.js';
|
|
13
|
+
export { CADRE_LINK_MAX_LENGTH, CadreLinkTooLongError, joinRequestLink, joinResponseLink, parseCadreLink, recommendedByLink, } from './links.js';
|
|
14
|
+
export { LINK_REQUEST_TTL_MS, LinkRequestStore, UnsolicitedJoinResponseError, } from './link-request-store.js';
|
|
15
|
+
export { AppRecommendationStore, RECOMMENDATION_TTL_MS, } from './recommendation-store.js';
|
|
16
|
+
export { RECOMMENDED_BY_REFERRER_PREFIX, recommendedByReferrer, recommendedBySchemeFromReferrer, storePageLink, } from './recommend-links.js';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/app-link/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAkB,MAAM,iBAAiB,CAAC;AACzF,OAAO,EACN,0BAA0B,EAC1B,uBAAuB,EACvB,uBAAuB,GAGvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,iBAAiB,GAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,mBAAmB,EACnB,gBAAgB,EAChB,4BAA4B,GAE5B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,sBAAsB,EACtB,qBAAqB,GAErB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,8BAA8B,EAC9B,qBAAqB,EACrB,+BAA+B,EAC/B,aAAa,GAEb,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Version 1 of the join response; the only one either side reads. */
|
|
2
|
+
export declare const CADRE_JOIN_RESPONSE_PREFIX = "sereus-join-response:1.";
|
|
3
|
+
/**
|
|
4
|
+
* Why the owner app minted no invitation: the user declined (`denied`), it has no cadre
|
|
5
|
+
* (`no-cadre`), it is not an owner of its cadre (`not-owner`), or the request's peer id is
|
|
6
|
+
* already a member (`already-member`).
|
|
7
|
+
*/
|
|
8
|
+
export type JoinRefusal = 'denied' | 'no-cadre' | 'not-owner' | 'already-member';
|
|
9
|
+
export type CadreJoinResponse =
|
|
10
|
+
/** `invitation` is an encoded `sereus-invite:1.` text; the asking app's join decodes it fully. */
|
|
11
|
+
{
|
|
12
|
+
v: 1;
|
|
13
|
+
nonce: string;
|
|
14
|
+
appName: string;
|
|
15
|
+
invitation: string;
|
|
16
|
+
} | {
|
|
17
|
+
v: 1;
|
|
18
|
+
nonce: string;
|
|
19
|
+
appName: string;
|
|
20
|
+
refused: JoinRefusal;
|
|
21
|
+
};
|
|
22
|
+
/** Encode a response as the text the owner app's link carries. Refuses what {@link decodeCadreJoinResponse} would. */
|
|
23
|
+
export declare function encodeCadreJoinResponse(response: CadreJoinResponse): string;
|
|
24
|
+
/**
|
|
25
|
+
* Decode the text an answering link carried. Refuses, naming the problem: a join request,
|
|
26
|
+
* any prefix but version 1's, a body that is not base64url JSON of the response's shape, an
|
|
27
|
+
* empty nonce, an `appName` that is empty or longer than 64 characters once trimmed, an
|
|
28
|
+
* `invitation` that is not an invitation's text, an unknown refusal, and both or neither of
|
|
29
|
+
* `invitation` and `refused`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function decodeCadreJoinResponse(text: string): CadreJoinResponse;
|