@serfab/cadre-client 2.0.0 → 2.1.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.
@@ -4,18 +4,18 @@
4
4
  change re-encoding it through `invitations.rebootstrap`), and its QR code full screen on a click. Copy and adapt; it is not
5
5
  built or published. The QR code here comes from the `qrcode` package (`toDataURL`).
6
6
  Props as in the React Native example: `token` (encoded, after `invitations.withBootstrap`),
7
- `link` (the text shared), `strandId`, `newStrand` (the invitation founded the strand just now), `onRebootstrap(token)` (the
8
- person changed its addresses: the app rebuilds the link from the new token and keeps it).
7
+ `link` (the text shared), `onRebootstrap(token)` (the person changed its addresses: the app
8
+ rebuilds the link from the new token and keeps it).
9
9
  -->
10
10
  <script lang="ts">
11
11
  import QRCode from 'qrcode';
12
- import { invitationReadinessStore, type InvitationText } from '@serfab/cadre-client';
12
+ import { invitationReadinessStore, type FormationReadinessGap, type InvitationReadiness, type InvitationText } from '@serfab/cadre-client';
13
13
  import type { CadreClient } from '@serfab/cadre-client/sereus';
14
14
 
15
- const { client, token, link, strandId, newStrand, onRebootstrap }:
16
- { client: CadreClient; token: string; link: string; strandId: string; newStrand: boolean; onRebootstrap(token: string): void } = $props();
15
+ const { client, token, link, onRebootstrap }:
16
+ { client: CadreClient; token: string; link: string; onRebootstrap(token: string): void } = $props();
17
17
 
18
- const readiness = $derived(invitationReadinessStore(client, strandId, { newStrand }));
18
+ const readiness = $derived(invitationReadinessStore(client, token));
19
19
  let details = $state<InvitationText | null>(null);
20
20
  let open = $state(false);
21
21
  let full = $state(false);
@@ -36,17 +36,34 @@
36
36
  if (r.ok) onRebootstrap(r.value);
37
37
  }
38
38
 
39
- const READINESS = {
39
+ const READINESS: Record<InvitationReadiness['state'], string> = {
40
40
  ready: 'Ready to hand out: your machine can answer even while this device sleeps.',
41
- waiting: 'Getting ready to hand out… your machine is taking a copy of the conversation.',
41
+ waiting: 'Not ready to hand out yet: no other machine of yours can let them in on its own.',
42
42
  'no-cadron': 'Only this device can answer it: keep the app open until they join, or add a machine that stays on.',
43
- } as const;
43
+ spent: 'This invitation can no longer be used: it has expired, or it has been used up. Make a new one.',
44
+ };
45
+
46
+ // Each thing a machine can still be missing, as the step the person is waiting for. Phrased
47
+ // without a subject: `missing` is the union over every machine the invitation names.
48
+ const MISSING: Record<FormationReadinessGap, string> = {
49
+ 'invitation-record': 'being told about this invitation',
50
+ 'strand-record': 'being told about the conversation',
51
+ 'membership-key': 'a key for the conversation, to sign your guest in',
52
+ 'strand-runtime': 'running the conversation',
53
+ 'strand-database': 'its own copy of the conversation',
54
+ };
55
+
56
+ // Why it is not ready, when the machines said: a person waiting wants the reason, not a spinner.
57
+ const detail = $derived($readiness.state !== 'waiting' ? null
58
+ : $readiness.missing.length === 0 ? 'None of the machines it names has answered: one may be offline, or still starting.'
59
+ : `Still needed on the machines it names: ${$readiness.missing.map(gap => MISSING[gap]).join('; ')}.`);
44
60
  </script>
45
61
 
46
62
  {#if qr}
47
63
  <button class="qr" onclick={() => { full = true; }} aria-label="Enlarge the QR code"><img src={qr} alt="Invitation QR code" width="180" /></button>
48
64
  {/if}
49
- <p class:ready={$readiness === 'ready'}>{READINESS[$readiness]}</p>
65
+ <p class:ready={$readiness.state === 'ready'} class:spent={$readiness.state === 'spent'}>{READINESS[$readiness.state]}</p>
66
+ {#if detail}<p class="muted">{detail}</p>{/if}
50
67
 
51
68
  <button class="link" onclick={() => { open = !open; }}>{open ? 'Hide the details' : "What's in this invitation"}</button>
52
69
  {#if open && details}
@@ -72,6 +89,7 @@
72
89
  .qr, .link, .full { background: none; border: 0; padding: 0; cursor: pointer; }
73
90
  .link { color: #0066cc; }
74
91
  .ready { color: #2c8a3f; }
92
+ .spent { color: #b3261e; }
75
93
  .muted { color: #777; }
76
94
  label { display: block; }
77
95
  .full { position: fixed; inset: 0; background: #fff; display: grid; place-items: center; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serfab/cadre-client",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
5
  "description": "Cadre management for Sereus apps, without UI: cadrons (the cadre's machines), claiming a node by its code, owner key backup, relays, reachability, and which cadrons an invitation names",
6
6
  "main": "dist/index.js",
@@ -54,10 +54,10 @@
54
54
  "uint8arrays": "^6.1.1"
55
55
  },
56
56
  "peerDependencies": {
57
- "@serfab/cadre-core": "^2.0.0"
57
+ "@serfab/cadre-core": "^2.1.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@serfab/cadre-core": "^2.0.0",
60
+ "@serfab/cadre-core": "^2.1.0",
61
61
  "@types/node": "^25.0.10",
62
62
  "rimraf": "^6.1.2",
63
63
  "typescript": "^5.9.3",
package/src/model.ts CHANGED
@@ -10,6 +10,7 @@
10
10
  * These are interfaces. `@serfab/cadre-client/sereus` implements them over a running
11
11
  * cadre-core node; an app's mock implements them over sample data.
12
12
  */
13
+ import type { FormationReadinessGap } from '@serfab/cadre-core';
13
14
  import type { CadreResult } from './result.js';
14
15
  import type { BootstrapPlan, CadronPreferences } from './bootstrap.js';
15
16
  import type { InvitationText } from './invitation-text.js';
@@ -200,14 +201,36 @@ export interface RelaysModel {
200
201
  }
201
202
 
202
203
  /**
203
- * Whether a new invitation can be handed out with this device about to go quiet:
204
- * - `ready`: another cadron holds the invitation's strand (one of its commits is held
205
- * elsewhere), so it can answer a join without this device;
206
- * - `waiting`: not yet (a new strand's copy reaches a cadron a second or two after the
207
- * invitation is made);
208
- * - `no-cadron`: no other cadron serves the party's strands; only this device answers.
204
+ * What a machine of the party is missing before it could answer a join through an invitation,
205
+ * as cadre-core's probe names it (`docs/strands/formation.md` → "Whether a named machine can
206
+ * answer yet"). Re-exported so a screen can label the gaps without importing cadre-core.
209
207
  */
210
- export type InvitationReadiness = 'ready' | 'waiting' | 'no-cadron';
208
+ export type { FormationReadinessGap };
209
+
210
+ /**
211
+ * Whether a new invitation can be handed out with this device about to go quiet. cadre-core
212
+ * asks each machine the invitation names whether it could answer a redemption of it right now
213
+ * (`CadreNode.readInvitationReadiness`); this is that report as one answer about the invitation.
214
+ */
215
+ export interface InvitationReadiness {
216
+ /**
217
+ * - `ready`: another of the party's machines can answer a join through this invitation now,
218
+ * so this device may go quiet;
219
+ * - `waiting`: none of them can yet, and `missing` says what they lack;
220
+ * - `no-cadron`: the invitation names no machine but this one, so only this device can ever
221
+ * answer it. Waiting changes nothing: stay open until the guest joins, or add a machine
222
+ * that stays on and make a new invitation;
223
+ * - `spent`: the invitation is expired or used up, so no machine will answer it; the remedy
224
+ * is a new invitation.
225
+ */
226
+ state: 'ready' | 'waiting' | 'no-cadron' | 'spent';
227
+ /**
228
+ * What the other machines are missing, each gap once, in the order they reported it. Empty
229
+ * unless `state` is `waiting` — and empty there too when no machine answered the probe at
230
+ * all (unreachable, or too busy to decide), which a later probe may change.
231
+ */
232
+ missing: readonly FormationReadinessGap[];
233
+ }
211
234
 
212
235
  /**
213
236
  * What goes into an invitation, and whether it is ready to hand out. The app mints the
@@ -226,11 +249,16 @@ export interface InvitationsModel {
226
249
  */
227
250
  withBootstrap<T extends { bootstrap: string[] }>(invitation: T): Promise<T>;
228
251
  /**
229
- * `newStrand`: the invitation founded this strand just now. Its copy reaches a cadron only once
230
- * a commit of it is held there (the signal waited for). An established strand counts as ready
231
- * when another cadron serves it.
252
+ * Whether another machine can answer a join through this invitation now. The encoded
253
+ * invitation, not a strand id: half the question is whether that invitation's own record has
254
+ * reached the machine that would answer.
255
+ *
256
+ * Synchronous, over a cache per token: the first read for a token starts cadre-core's probe
257
+ * and answers `waiting`, and `changes.invitations` fires when an answer differs from the one
258
+ * before. While an answer stays `waiting` the probe repeats on cadre-core's own ladder, and
259
+ * only while something is watching, so a subscribed store sees `waiting` turn `ready`.
232
260
  */
233
- readiness(strandId: string, opts?: { newStrand?: boolean }): InvitationReadiness;
261
+ readiness(token: string): InvitationReadiness;
234
262
  /**
235
263
  * An invitation in words, from its encoded form. `link`: the text actually shared (the URL the
236
264
  * QR code carries), for its length; the token's length otherwise. Its addresses grouped by
@@ -59,7 +59,7 @@ export interface CadreClient extends CadreView, ReachabilityView, InvitationsVie
59
59
  /** What an invitation names, whether it is ready to hand out, and what it says in words. */
60
60
  invitations: InvitationsModel;
61
61
  changes: {
62
- /** Cadron preferences changed, or a cadron came to hold a strand (readiness). */
62
+ /** Cadron preferences changed, or an invitation's readiness did (a probe answered differently). */
63
63
  invitations(onChange: () => void): () => void;
64
64
  /**
65
65
  * A cadron left the cadre: removed through this client, or found gone when the machine list is