@serfab/cadre-client 0.0.0-stage → 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.
Files changed (116) hide show
  1. package/ADOPTING.md +228 -0
  2. package/README.md +130 -3
  3. package/dist/address.d.ts +45 -0
  4. package/dist/address.js +109 -0
  5. package/dist/address.js.map +1 -0
  6. package/dist/app-link/index.d.ts +16 -0
  7. package/dist/app-link/index.js +17 -0
  8. package/dist/app-link/index.js.map +1 -0
  9. package/dist/app-link/join-response.d.ts +31 -0
  10. package/dist/app-link/join-response.js +87 -0
  11. package/dist/app-link/join-response.js.map +1 -0
  12. package/dist/app-link/known-apps.d.ts +32 -0
  13. package/dist/app-link/known-apps.js +51 -0
  14. package/dist/app-link/known-apps.js.map +1 -0
  15. package/dist/app-link/link-request-store.d.ts +50 -0
  16. package/dist/app-link/link-request-store.js +101 -0
  17. package/dist/app-link/link-request-store.js.map +1 -0
  18. package/dist/app-link/links.d.ts +47 -0
  19. package/dist/app-link/links.js +76 -0
  20. package/dist/app-link/links.js.map +1 -0
  21. package/dist/app-link/recommend-links.d.ts +30 -0
  22. package/dist/app-link/recommend-links.js +33 -0
  23. package/dist/app-link/recommend-links.js.map +1 -0
  24. package/dist/app-link/recommendation-store.d.ts +54 -0
  25. package/dist/app-link/recommendation-store.js +99 -0
  26. package/dist/app-link/recommendation-store.js.map +1 -0
  27. package/dist/bootstrap.d.ts +106 -0
  28. package/dist/bootstrap.js +106 -0
  29. package/dist/bootstrap.js.map +1 -0
  30. package/dist/inbox.d.ts +10 -0
  31. package/dist/inbox.js +28 -0
  32. package/dist/inbox.js.map +1 -0
  33. package/dist/index.d.ts +15 -0
  34. package/dist/index.js +16 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/invitation-text.d.ts +81 -0
  37. package/dist/invitation-text.js +80 -0
  38. package/dist/invitation-text.js.map +1 -0
  39. package/dist/lifecycle/background-runner.d.ts +94 -0
  40. package/dist/lifecycle/background-runner.js +278 -0
  41. package/dist/lifecycle/background-runner.js.map +1 -0
  42. package/dist/lifecycle/index.d.ts +9 -0
  43. package/dist/lifecycle/index.js +10 -0
  44. package/dist/lifecycle/index.js.map +1 -0
  45. package/dist/loader.d.ts +47 -0
  46. package/dist/loader.js +93 -0
  47. package/dist/loader.js.map +1 -0
  48. package/dist/model.d.ts +309 -0
  49. package/dist/model.js +22 -0
  50. package/dist/model.js.map +1 -0
  51. package/dist/node-code-text.d.ts +10 -0
  52. package/dist/node-code-text.js +30 -0
  53. package/dist/node-code-text.js.map +1 -0
  54. package/dist/result.d.ts +79 -0
  55. package/dist/result.js +84 -0
  56. package/dist/result.js.map +1 -0
  57. package/dist/sereus/client.d.ts +49 -0
  58. package/dist/sereus/client.js +420 -0
  59. package/dist/sereus/client.js.map +1 -0
  60. package/dist/sereus/edge-host.d.ts +22 -0
  61. package/dist/sereus/edge-host.js +61 -0
  62. package/dist/sereus/edge-host.js.map +1 -0
  63. package/dist/sereus/host.d.ts +57 -0
  64. package/dist/sereus/host.js +2 -0
  65. package/dist/sereus/host.js.map +1 -0
  66. package/dist/sereus/index.d.ts +8 -0
  67. package/dist/sereus/index.js +9 -0
  68. package/dist/sereus/index.js.map +1 -0
  69. package/dist/sereus/invitations.d.ts +16 -0
  70. package/dist/sereus/invitations.js +333 -0
  71. package/dist/sereus/invitations.js.map +1 -0
  72. package/dist/sereus/node-code.d.ts +52 -0
  73. package/dist/sereus/node-code.js +51 -0
  74. package/dist/sereus/node-code.js.map +1 -0
  75. package/dist/store.d.ts +27 -0
  76. package/dist/store.js +51 -0
  77. package/dist/store.js.map +1 -0
  78. package/dist/stores.d.ts +38 -0
  79. package/dist/stores.js +48 -0
  80. package/dist/stores.js.map +1 -0
  81. package/examples/README.md +20 -0
  82. package/examples/nativescript/cadrons-page.xml +24 -0
  83. package/examples/nativescript/cadrons-view-model.ts +68 -0
  84. package/examples/react-native/CadronList.tsx +204 -0
  85. package/examples/react-native/InvitationPanel.tsx +191 -0
  86. package/examples/react-native/useStore.ts +11 -0
  87. package/examples/svelte/CadronList.svelte +86 -0
  88. package/examples/svelte/InvitationPanel.svelte +97 -0
  89. package/package.json +65 -3
  90. package/src/address.ts +125 -0
  91. package/src/app-link/index.ts +45 -0
  92. package/src/app-link/join-response.ts +109 -0
  93. package/src/app-link/known-apps.ts +70 -0
  94. package/src/app-link/link-request-store.ts +129 -0
  95. package/src/app-link/links.ts +90 -0
  96. package/src/app-link/recommend-links.ts +49 -0
  97. package/src/app-link/recommendation-store.ts +132 -0
  98. package/src/bootstrap.ts +184 -0
  99. package/src/globals.d.ts +26 -0
  100. package/src/inbox.ts +36 -0
  101. package/src/index.ts +15 -0
  102. package/src/invitation-text.ts +156 -0
  103. package/src/lifecycle/background-runner.ts +363 -0
  104. package/src/lifecycle/index.ts +17 -0
  105. package/src/loader.ts +103 -0
  106. package/src/model.ts +327 -0
  107. package/src/node-code-text.ts +25 -0
  108. package/src/result.ts +131 -0
  109. package/src/sereus/client.ts +454 -0
  110. package/src/sereus/edge-host.ts +81 -0
  111. package/src/sereus/host.ts +56 -0
  112. package/src/sereus/index.ts +8 -0
  113. package/src/sereus/invitations.ts +359 -0
  114. package/src/sereus/node-code.ts +80 -0
  115. package/src/store.ts +61 -0
  116. package/src/stores.ts +62 -0
@@ -0,0 +1,16 @@
1
+ import type { CadreMachine, InvitationsModel } from '../model.js';
2
+ import type { CadreHost } from './host.js';
3
+ export interface InvitationsDeps {
4
+ host: CadreHost;
5
+ /** The person's cadron list, as the cadre screen has it; empty when it cannot be read. */
6
+ machines(): Promise<CadreMachine[]>;
7
+ controlReadMs: number;
8
+ log: {
9
+ info(...args: unknown[]): void;
10
+ warn(...args: unknown[]): void;
11
+ };
12
+ }
13
+ export declare function createInvitations({ host, machines, controlReadMs, log }: InvitationsDeps): {
14
+ invitations: InvitationsModel;
15
+ onChange(listener: () => void): () => void;
16
+ };
@@ -0,0 +1,333 @@
1
+ /**
2
+ * Invitations over a running node: which addresses one names (`bootstrap.ts` plans, this
3
+ * gathers the evidence), whether it is ready to hand out, and what it says in words.
4
+ *
5
+ * The evidence for each cadron (each other machine of the party), best first:
6
+ * - `connection`: a connection this device opened to it with no relay hop is open now;
7
+ * - `record`: its signed, recently published record (`resolvePeerAddrs`), every address;
8
+ * - `claim`: what this device was handed when it claimed it (cadre-core's bootstrap peer store),
9
+ * which is all there is in the minute before the cadron's first record arrives. cadre-core's
10
+ * own invitation leaves such a cadron out altogether.
11
+ *
12
+ * READINESS comes from cadre-core's probe of the machines an invitation names
13
+ * (`CadreNode.readInvitationReadiness`), which asks each of them whether it could answer a
14
+ * redemption of that invitation right now. Nothing here infers it from replication: this module
15
+ * keeps the probe's answer per token, asks again on cadre-core's ladder while the answer is
16
+ * still `waiting`, and reports which of the five things the machines said they are missing.
17
+ */
18
+ import { multiaddr } from '@multiformats/multiaddr';
19
+ import { nextFormationReadyPoll } from '@serfab/cadre-core';
20
+ import { CADRON_PREFERENCES_FORMAT, normalizePreferences, planBootstrap } from '../bootstrap.js';
21
+ import { describeInvitation, destinationPeerId } from '../invitation-text.js';
22
+ import { cadreAttempt, CadreFailure, describeThrown, withTimeout } from '../result.js';
23
+ /** `addr` ending in `/p2p/<peerId>` (a claim's or a connection's address may not); unchanged when it does not parse. */
24
+ function withPeer(addr, peerId) {
25
+ try {
26
+ const ma = multiaddr(addr);
27
+ return ma.getComponents().at(-1)?.value === peerId ? ma.toString() : ma.encapsulate(`/p2p/${peerId}`).toString();
28
+ }
29
+ catch {
30
+ return addr;
31
+ }
32
+ }
33
+ /** The answer before a probe has landed, and when there is no node to probe with. */
34
+ const NOT_YET = { state: 'waiting', missing: [] };
35
+ /** Each gap the OTHER machines reported, once, in the order they reported it. */
36
+ function missingAcross(machines) {
37
+ const gaps = new Set();
38
+ for (const machine of machines) {
39
+ if (!machine.self)
40
+ for (const gap of machine.gaps)
41
+ gaps.add(gap);
42
+ }
43
+ return [...gaps];
44
+ }
45
+ /**
46
+ * cadre-core's per-machine report as one answer about the invitation.
47
+ *
48
+ * `spent` is read first: a machine holding the invitation's record and reading it dead settles
49
+ * the question, and a gap another machine reports cannot change that. `no-cadron` is the
50
+ * invitation naming no machine but this one, which is settled too — the machines probed are the
51
+ * ones its bootstrap list names, and that list cannot grow after minting.
52
+ */
53
+ function readinessOf(report) {
54
+ if (report.machines.some(m => m.outcome === 'spent'))
55
+ return { state: 'spent', missing: [] };
56
+ if (report.answerable)
57
+ return { state: 'ready', missing: [] };
58
+ if (!report.machines.some(m => !m.self))
59
+ return { state: 'no-cadron', missing: [] };
60
+ return { state: 'waiting', missing: missingAcross(report.machines) };
61
+ }
62
+ /** Two answers a screen would render identically, so the change signal can stay quiet. */
63
+ function sameReadiness(a, b) {
64
+ return a !== null && a.state === b.state && a.missing.length === b.missing.length
65
+ && a.missing.every((gap, i) => gap === b.missing[i]);
66
+ }
67
+ export function createInvitations({ host, machines, controlReadMs, log }) {
68
+ const listeners = new Set();
69
+ const changed = () => { for (const l of [...listeners])
70
+ l(); };
71
+ // Preferences: per device, in the host's slot. Without one, kept in memory for the session.
72
+ let prefs = null;
73
+ // One first read, however many callers ask at once.
74
+ let loading = null;
75
+ function loadPrefs() {
76
+ if (prefs)
77
+ return Promise.resolve(prefs);
78
+ loading ??= (async () => {
79
+ let raw = null;
80
+ try {
81
+ const text = await host.preferences?.load();
82
+ raw = text ? JSON.parse(text) : null;
83
+ }
84
+ catch (err) {
85
+ log.warn('[cadre-client] cadron preferences unreadable; using defaults:', describeThrown(err));
86
+ }
87
+ prefs ??= normalizePreferences(raw);
88
+ return prefs;
89
+ })();
90
+ return loading;
91
+ }
92
+ // Writes one after another: each merges into the result of the one before, so two changes made
93
+ // in quick succession (two stars) both stay.
94
+ let writing = Promise.resolve();
95
+ // Readiness per encoded invitation: what cadre-core's probe last answered, read in the
96
+ // background and cached. Per token, because half of what it answers is whether that
97
+ // invitation's own record has reached the machine that would answer a join through it.
98
+ // NOTE: one ladder per token, and nothing coalesces two tokens of the same party — each costs
99
+ // one small control request per machine the invitation names, at most four a minute once the
100
+ // ladder tops out. Fine for an invitation screen, which shows one. If an app ever shows a list
101
+ // of pending invitations, share one ladder across them.
102
+ // NOTE: an entry is never evicted, so a session holds one small object per token it has read.
103
+ // A token is only ever re-minted by `rebootstrap`, so that is one per address the person
104
+ // toggled. If an app ever reads readiness for tokens it mints in a loop, evict by last read.
105
+ const probes = new Map();
106
+ /** `waiting` is the only answer a further probe can change. */
107
+ const settled = (probe) => probe.answer !== null && probe.answer.state !== 'waiting';
108
+ /**
109
+ * cadre-core's probe for an encoded invitation, as a promise even for a token that will not decode.
110
+ *
111
+ * NOTE: no `withTimeout` here, unlike the control reads below. cadre-core bounds each dial it
112
+ * makes, and a probe that outran a bound of ours would still be in flight behind it; the one
113
+ * unbounded leg is its read of this machine's own control database. A probe that never settles
114
+ * leaves the token reading `waiting` with its ladder stopped. Bound it here if that is ever seen.
115
+ */
116
+ async function askReadiness(node, token) {
117
+ return await node.readInvitationReadiness(node.decodeInvitation(token));
118
+ }
119
+ /** The cached probe for `token`, carrying its ladder on before the answer is read. */
120
+ function probeFor(node, token) {
121
+ const probe = probes.get(token) ?? { answer: null, asks: 0, asking: false, timer: null, at: 0 };
122
+ probes.set(token, probe);
123
+ ladder(node, token, probe);
124
+ return probe;
125
+ }
126
+ /**
127
+ * Ask again while the answer is still `waiting`, each ask no sooner than cadre-core's own
128
+ * ladder allows (`nextFormationReadyPoll`: two seconds doubling to fifteen) — the one cadence
129
+ * there is, so the client adds none of its own. An ask the ladder allows now is made at once,
130
+ * which is what answers the first read for a token. A later one is scheduled only while
131
+ * something is watching, because an answer nothing listens for has nowhere to go; the next
132
+ * read, or the next listener, picks the ladder up where it stopped.
133
+ */
134
+ function ladder(node, token, probe) {
135
+ if (probe.asking || probe.timer !== null || settled(probe))
136
+ return;
137
+ const waitMs = Math.max(0, probe.at + nextFormationReadyPoll(probe.asks) - Date.now());
138
+ if (waitMs === 0) {
139
+ ask(node, token, probe);
140
+ return;
141
+ }
142
+ if (listeners.size === 0)
143
+ return;
144
+ probe.timer = setTimeout(() => {
145
+ probe.timer = null;
146
+ if (probes.get(token) === probe && listeners.size > 0)
147
+ ladder(node, token, probe);
148
+ }, waitMs);
149
+ }
150
+ /** Cancel a scheduled re-ask, so no timer outlives what wanted its answer. */
151
+ function unschedule(probe) {
152
+ if (probe.timer === null)
153
+ return;
154
+ clearTimeout(probe.timer);
155
+ probe.timer = null;
156
+ }
157
+ function ask(node, token, probe) {
158
+ probe.asking = true;
159
+ void askReadiness(node, token).then(report => keep(node, token, probe, readinessOf(report)), err => {
160
+ // A failed read forgets its entry: the next read asks again, and a failure is never
161
+ // reported as an answer. Never log the token itself.
162
+ // NOTE: forgetting also drops the ladder's backoff, so a probe that keeps throwing is
163
+ // re-asked — and warns — once per read rather than on a climbing gap. Reads are driven
164
+ // by the change signal, so that is bounded in practice. If a persistent failure ever
165
+ // shows up as a run of warnings, keep the entry and carry `asks` on instead of deleting.
166
+ if (probes.get(token) === probe)
167
+ probes.delete(token);
168
+ log.warn('[cadre-client] an invitation\'s readiness could not be read:', describeThrown(err));
169
+ });
170
+ }
171
+ /**
172
+ * Keep what a probe answered, and tell the app only when it differs from the answer before:
173
+ * the ladder asks every couple of seconds while a machine is still catching up, and a screen
174
+ * has nothing to re-render for an unchanged answer.
175
+ */
176
+ function keep(node, token, probe, answer) {
177
+ if (probes.get(token) !== probe)
178
+ return; // forgotten while the probe was in flight
179
+ const differs = !sameReadiness(probe.answer, answer);
180
+ probe.asking = false;
181
+ probe.asks += 1;
182
+ probe.at = Date.now();
183
+ if (differs) {
184
+ probe.answer = answer;
185
+ changed();
186
+ }
187
+ ladder(node, token, probe);
188
+ }
189
+ /** Something is watching again: carry on every ladder that stopped for want of a listener. */
190
+ function resumeLadders() {
191
+ const node = host.node.node;
192
+ if (!node)
193
+ return;
194
+ for (const [token, probe] of probes)
195
+ ladder(node, token, probe);
196
+ }
197
+ /** Put every token still waiting back at the foot of the ladder, so the next read asks at once. */
198
+ function restartLadders() {
199
+ for (const probe of probes.values()) {
200
+ if (settled(probe))
201
+ continue;
202
+ unschedule(probe);
203
+ probe.asks = 0;
204
+ probe.at = 0;
205
+ }
206
+ }
207
+ // A cadron coming or going may make a machine an invitation names reachable for the probe: ask
208
+ // again at once for the tokens still waiting. A settled answer is KEPT, where the serving counts
209
+ // this replaced were cleared wholesale: `ready` would otherwise read `waiting` again until the
210
+ // re-probe landed, so a screen already telling the person they may close the app would take it
211
+ // back for a second or two. Nor can a connection change the other two — `spent` is permanent,
212
+ // and `no-cadron` is the invitation's own bootstrap list, which does not grow after minting.
213
+ host.node.on('control:connected', () => { restartLadders(); changed(); });
214
+ async function candidates(node) {
215
+ const machines = await withTimeout(node.listMachines(), controlReadMs, 'listMachines').catch(() => []);
216
+ const claimed = node.getBootstrapPeerStore()?.all() ?? new Map();
217
+ const connections = node.getControlNode()?.getConnections() ?? [];
218
+ const others = machines.filter(m => !m.isSelf && m.trusted);
219
+ return Promise.all(others.map(async (m) => {
220
+ const addrs = [];
221
+ const record = await withTimeout(node.resolvePeerAddrs(m.peerId), controlReadMs, 'resolvePeerAddrs').catch(() => []);
222
+ for (const a of record)
223
+ addrs.push({ addr: withPeer(a.toString(), m.peerId), source: 'record' });
224
+ // WORKAROUND(sereus: name a just-claimed machine): until its first record arrives, what its
225
+ // node code carried. cadre-core's own invitation leaves such a machine out.
226
+ for (const a of claimed.get(m.peerId)?.addrs ?? [])
227
+ addrs.push({ addr: withPeer(a, m.peerId), source: 'claim' });
228
+ for (const c of connections) {
229
+ const remote = c.remoteAddr.toString();
230
+ if (c.remotePeer.toString() !== m.peerId || c.direction !== 'outbound' || c.limits !== undefined || remote.includes('/p2p-circuit'))
231
+ continue;
232
+ addrs.push({ addr: withPeer(remote, m.peerId), source: 'connection' });
233
+ }
234
+ return { peerId: m.peerId, alwaysOn: m.alwaysOn === true, lastPublishedAt: m.lastPublishedAt, addrs };
235
+ }));
236
+ }
237
+ const requireNode = () => {
238
+ const node = host.node.node;
239
+ if (!node)
240
+ throw new CadreFailure('unavailable', 'The cadre node is not running yet.');
241
+ return node;
242
+ };
243
+ async function plan() {
244
+ const node = requireNode();
245
+ return planBootstrap({
246
+ cadrons: await candidates(node),
247
+ thisDevice: { peerId: node.peerId?.toString() ?? '', addrs: node.getMultiaddrs().map(a => a.toString()) },
248
+ prefs: await loadPrefs(),
249
+ });
250
+ }
251
+ const invitations = {
252
+ preferences: loadPrefs,
253
+ setPreferences: changes => {
254
+ const write = writing.then(() => cadreAttempt(async () => {
255
+ const next = normalizePreferences({ ...(await loadPrefs()), ...changes });
256
+ if (host.preferences)
257
+ await host.preferences.save(JSON.stringify({ format: CADRON_PREFERENCES_FORMAT, ...next }));
258
+ prefs = next;
259
+ changed();
260
+ return next;
261
+ }));
262
+ writing = write;
263
+ return write;
264
+ },
265
+ bootstrapPlan: () => cadreAttempt(plan),
266
+ // WORKAROUND(sereus: an option on `createOpenInvitation`): the list is replaced after minting,
267
+ // before the app encodes it. It is not signed; the responder checks only the token.
268
+ async withBootstrap(invitation) {
269
+ try {
270
+ const { entries, warnings } = await plan();
271
+ if (entries.length === 0)
272
+ return invitation;
273
+ if (warnings.length)
274
+ log.info('[cadre-client] invitation bootstrap:', warnings.join(', '));
275
+ return { ...invitation, bootstrap: entries.map(e => e.addr) };
276
+ }
277
+ catch (err) {
278
+ log.warn('[cadre-client] kept cadre-core\'s bootstrap list:', err instanceof Error ? err.message : err);
279
+ return invitation;
280
+ }
281
+ },
282
+ readiness(token) {
283
+ const node = host.node.node;
284
+ // NOTE: with no node the question is dropped rather than remembered, so a store built
285
+ // while the node is stopped reads `waiting` until something else fires the change signal.
286
+ // Harmless as apps use it — a token exists only because a running node minted it. If an
287
+ // app ever reads readiness for a token it kept across a restart, queue the token here.
288
+ if (!node)
289
+ return NOT_YET;
290
+ return probeFor(node, token).answer ?? NOT_YET;
291
+ },
292
+ describe: (token, link) => cadreAttempt(async () => {
293
+ const node = requireNode();
294
+ const decoded = node.decodeInvitation(token);
295
+ const [{ names, maxAddrs }, list, now] = await Promise.all([
296
+ loadPrefs(),
297
+ machines(),
298
+ plan().catch(() => ({ entries: [], others: [] })),
299
+ ]);
300
+ return describeInvitation(decoded, {
301
+ link: link ?? token, names, thisDevicePeerId: node.peerId?.toString() ?? null,
302
+ machines: list, others: [...now.entries, ...now.others].map(e => e.addr), maxAddrs,
303
+ });
304
+ }),
305
+ // WORKAROUND(sereus: an option on `createOpenInvitation`), as `withBootstrap`.
306
+ rebootstrap: (token, addrs) => cadreAttempt(async () => {
307
+ const node = requireNode();
308
+ if (addrs.length === 0)
309
+ throw new CadreFailure('invalid-address', 'An invitation must name at least one address.');
310
+ if (addrs.some(a => !destinationPeerId(a)))
311
+ throw new CadreFailure('invalid-address', 'An address does not end in the peer it reaches.');
312
+ return node.encodeInvitation({ ...node.decodeInvitation(token), bootstrap: [...new Set(addrs)] });
313
+ }),
314
+ };
315
+ return {
316
+ invitations,
317
+ onChange(listener) {
318
+ listeners.add(listener);
319
+ if (listeners.size === 1)
320
+ resumeLadders();
321
+ return () => {
322
+ listeners.delete(listener);
323
+ // Nothing is watching: stop the ladders here rather than leave timers to fire into an
324
+ // empty listener set — under Node one would hold the process open for up to fifteen
325
+ // seconds. The next read, or the next listener, picks each one up where it stopped.
326
+ if (listeners.size === 0)
327
+ for (const probe of probes.values())
328
+ unschedule(probe);
329
+ };
330
+ },
331
+ };
332
+ }
333
+ //# sourceMappingURL=invitations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invitations.js","sourceRoot":"","sources":["../../src/sereus/invitations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAA6G,MAAM,oBAAoB,CAAC;AACvK,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,aAAa,EAAgD,MAAM,iBAAiB,CAAC;AAC/I,OAAO,EAAE,kBAAkB,EAAE,i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,CAAC,KAAK,IAAI,EAAE;YACtD,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC;YAC3B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,MAAM,IAAI,YAAY,CAAC,iBAAiB,EAAE,+CAA+C,CAAC,CAAC;YACnH,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;gBAAE,MAAM,IAAI,YAAY,CAAC,iBAAiB,EAAE,iDAAiD,CAAC,CAAC;YACzI,OAAO,IAAI,CAAC,gBAAgB,CAAC,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;QACnG,CAAC,CAAC;KACF,CAAC;IAEF,OAAO;QACN,WAAW;QACX,QAAQ,CAAC,QAAQ;YAChB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACxB,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC;gBAAE,aAAa,EAAE,CAAC;YAC1C,OAAO,GAAG,EAAE;gBACX,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC3B,sFAAsF;gBACtF,oFAAoF;gBACpF,oFAAoF;gBACpF,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC;oBAAE,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE;wBAAE,UAAU,CAAC,KAAK,CAAC,CAAC;YAClF,CAAC,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Node codes: the `sereus-join:1.…` text a cadre node shows (as a QR code, a link or plain
3
+ * text) while it waits to be claimed, and how to read one and sort a claim's failure.
4
+ *
5
+ * Descends from reference-app-rn's `src/node-claim.ts`; this one returns codes rather than
6
+ * English, so each app words them in its own catalog.
7
+ *
8
+ * SECURITY: a code carries the node's one-time claim secret. Never log the code text, a
9
+ * link containing one, or a decoded payload — log the peer id only.
10
+ */
11
+ import { type NodeClaimPayload } from '@serfab/cadre-core';
12
+ import type { NodeReach } from '../model.js';
13
+ export type NodeCodeProblem =
14
+ /** Does not start with `sereus-join:` — some other QR, link or text. */
15
+ 'not-node-code'
16
+ /** A node code from a newer node than this build reads: the app needs updating. */
17
+ | 'newer-version'
18
+ /** Right prefix, but cut short or corrupted. */
19
+ | 'damaged';
20
+ export type NodeCodeReading = {
21
+ ok: true;
22
+ payload: NodeClaimPayload;
23
+ } | {
24
+ ok: false;
25
+ problem: NodeCodeProblem; /** The decoder's words (never the secret), for logs. */
26
+ detail?: string;
27
+ };
28
+ /** Decode scanned or pasted text, or say which problem it has. */
29
+ export declare function readNodeCode(text: string): NodeCodeReading;
30
+ export type ClaimFailure =
31
+ /** No connection formed from any address; nothing was sent. */
32
+ {
33
+ kind: 'node-unreachable';
34
+ reach: NodeReach;
35
+ retryable: true;
36
+ detail: string;
37
+ }
38
+ /** The node answered and said no. `refusal` is absent when it gave no (known) code. */
39
+ | {
40
+ kind: 'claim-refused';
41
+ refusal?: string;
42
+ retryable: boolean;
43
+ detail: string;
44
+ }
45
+ /** Reached, then the exchange or a local step failed. Repeating with the same code is safe. */
46
+ | {
47
+ kind: 'claim-failed';
48
+ retryable: true;
49
+ detail: string;
50
+ };
51
+ /** Sort an error thrown by `CadreNode.claimNode(payload)` into what to say and whether to keep the code. */
52
+ export declare function classifyClaimFailure(error: unknown, payload: NodeClaimPayload): ClaimFailure;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Node codes: the `sereus-join:1.…` text a cadre node shows (as a QR code, a link or plain
3
+ * text) while it waits to be claimed, and how to read one and sort a claim's failure.
4
+ *
5
+ * Descends from reference-app-rn's `src/node-claim.ts`; this one returns codes rather than
6
+ * English, so each app words them in its own catalog.
7
+ *
8
+ * SECURITY: a code carries the node's one-time claim secret. Never log the code text, a
9
+ * link containing one, or a decoded payload — log the peer id only.
10
+ */
11
+ import { ClaimRefusedError, NODE_CLAIM_PAYLOAD_PREFIX, PeerUnreachableError, decodeNodeClaimPayload, describeThrown, } from '@serfab/cadre-core';
12
+ import { NODE_CODE_SCHEME, nodeCodeFromUrl } from '../node-code-text.js';
13
+ import { nodeReach } from '../address.js';
14
+ /** A code with a version this build does not read: `sereus-join:<n>.` with n ≠ 1. */
15
+ const VERSIONED_NODE_CODE = /^sereus-join:(\d+)\./;
16
+ /** Decode scanned or pasted text, or say which problem it has. */
17
+ export function readNodeCode(text) {
18
+ const trimmed = (nodeCodeFromUrl(text) ?? text).trim();
19
+ if (!trimmed.startsWith(NODE_CODE_SCHEME))
20
+ return { ok: false, problem: 'not-node-code' };
21
+ if (!trimmed.startsWith(NODE_CLAIM_PAYLOAD_PREFIX) && VERSIONED_NODE_CODE.test(trimmed)) {
22
+ return { ok: false, problem: 'newer-version' };
23
+ }
24
+ try {
25
+ return { ok: true, payload: decodeNodeClaimPayload(trimmed) };
26
+ }
27
+ catch (err) {
28
+ // The decoder never echoes the secret, so its message is safe to keep.
29
+ return { ok: false, problem: 'damaged', detail: describeThrown(err) };
30
+ }
31
+ }
32
+ /** Refusals after which the same code can still succeed. */
33
+ const RETRYABLE_REFUSALS = new Set(['claim-rate-limited', 'claim-not-persisted']);
34
+ /** Sort an error thrown by `CadreNode.claimNode(payload)` into what to say and whether to keep the code. */
35
+ export function classifyClaimFailure(error, payload) {
36
+ const detail = describeThrown(error);
37
+ if (error instanceof PeerUnreachableError) {
38
+ return { kind: 'node-unreachable', reach: nodeReach(payload.multiaddrs), retryable: true, detail };
39
+ }
40
+ if (error instanceof ClaimRefusedError) {
41
+ const refusal = error.code;
42
+ return {
43
+ kind: 'claim-refused',
44
+ refusal,
45
+ retryable: refusal !== undefined && RETRYABLE_REFUSALS.has(refusal),
46
+ detail: error.reason ?? detail,
47
+ };
48
+ }
49
+ return { kind: 'claim-failed', retryable: true, detail };
50
+ }
51
+ //# sourceMappingURL=node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,CAAC,oBAAoB,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAUvG,4GAA4G;AAC5G,MAAM,UAAU,oBAAoB,CAAC,KAAc,EAAE,OAAyB;IAC7E,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,KAAK,YAAY,oBAAoB,EAAE,CAAC;QAC3C,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IACpG,CAAC;IACD,IAAI,KAAK,YAAY,iBAAiB,EAAE,CAAC;QACxC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;QAC3B,OAAO;YACN,IAAI,EAAE,eAAe;YACrB,OAAO;YACP,SAAS,EAAE,OAAO,KAAK,SAAS,IAAI,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC;YACnE,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,MAAM;SAC9B,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The store primitive cadre screens bind to: the Svelte store contract — `subscribe(fn)`
3
+ * calls `fn` at once with the current value and returns an unsubscribe function — plus
4
+ * `get()`, with two rules:
5
+ *
6
+ * - `get()` returns the same object until the value changes. React's
7
+ * `useSyncExternalStore` re-renders whenever the snapshot is a new object, so a store
8
+ * that rebuilt its value on every read would loop.
9
+ * - Reference-counted: `start` runs when the first subscriber arrives and the function it
10
+ * returns runs when the last one leaves, so a store costs nothing while nothing shows it.
11
+ *
12
+ * Binding: Svelte uses a store directly (`$store`); React through
13
+ * `useSyncExternalStore(store.subscribe, store.get)`; NativeScript by copying each value
14
+ * into an `Observable` from `subscribe`. Self-contained on purpose, so the package
15
+ * depends on nothing but cadre-core; an app with its own store type of the same contract
16
+ * binds these the same way.
17
+ */
18
+ export interface Readable<T> {
19
+ subscribe(run: (value: T) => void): () => void;
20
+ get(): T;
21
+ }
22
+ export interface Writable<T> extends Readable<T> {
23
+ set(value: T): void;
24
+ update(fn: (value: T) => T): void;
25
+ }
26
+ export type StartStop<T> = (set: (value: T) => void, update: (fn: (value: T) => T) => void) => void | (() => void);
27
+ export declare function writable<T>(initial: T, start?: StartStop<T>): Writable<T>;
package/dist/store.js ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The store primitive cadre screens bind to: the Svelte store contract — `subscribe(fn)`
3
+ * calls `fn` at once with the current value and returns an unsubscribe function — plus
4
+ * `get()`, with two rules:
5
+ *
6
+ * - `get()` returns the same object until the value changes. React's
7
+ * `useSyncExternalStore` re-renders whenever the snapshot is a new object, so a store
8
+ * that rebuilt its value on every read would loop.
9
+ * - Reference-counted: `start` runs when the first subscriber arrives and the function it
10
+ * returns runs when the last one leaves, so a store costs nothing while nothing shows it.
11
+ *
12
+ * Binding: Svelte uses a store directly (`$store`); React through
13
+ * `useSyncExternalStore(store.subscribe, store.get)`; NativeScript by copying each value
14
+ * into an `Observable` from `subscribe`. Self-contained on purpose, so the package
15
+ * depends on nothing but cadre-core; an app with its own store type of the same contract
16
+ * binds these the same way.
17
+ */
18
+ export function writable(initial, start) {
19
+ let value = initial;
20
+ let stop = undefined;
21
+ const subscribers = new Set();
22
+ const set = (next) => {
23
+ if (Object.is(next, value))
24
+ return;
25
+ value = next;
26
+ for (const run of [...subscribers])
27
+ run(value);
28
+ };
29
+ const update = (fn) => set(fn(value));
30
+ return {
31
+ get: () => value,
32
+ set,
33
+ update,
34
+ subscribe(run) {
35
+ subscribers.add(run);
36
+ if (subscribers.size === 1 && start)
37
+ stop = start(set, update);
38
+ run(value);
39
+ return () => {
40
+ if (!subscribers.delete(run))
41
+ return;
42
+ if (subscribers.size === 0 && stop) {
43
+ const halt = stop;
44
+ stop = undefined;
45
+ halt();
46
+ }
47
+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AI,EAAE,CAAC;gBACR,CAAC;YACF,CAAC,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The stores a cadre screen binds to. Each reads through a view (`CadreView`,
3
+ * `ReachabilityView`), so it works over the Sereus client, an app's mock, or an app's
4
+ * whole model when that has the same two members.
5
+ */
6
+ import type { CadreStatus, CadreView, InvitationReadiness, InvitationsView, Reachability, ReachabilityView } from './model.js';
7
+ import { type Readable } from './store.js';
8
+ import { type Loader } from './loader.js';
9
+ /** How often a store re-reads with nothing announcing a change, while subscribed. */
10
+ export interface StoreOptions {
11
+ /** Milliseconds; 0 turns the poll off. Default 30 s. */
12
+ pollMs?: number;
13
+ }
14
+ /**
15
+ * The cadre: this device, its cadrons, and whether it is an enrolled owner. Re-read on every
16
+ * change that has an event: this node starting or stopping, a cadron connecting or dropping, the
17
+ * cadron preferences. The poll catches what has none: a cadron added or removed on another
18
+ * device (it arrives by control replication), and a cadron's `lastSeenAt` ageing, so its
19
+ * presence turns from recent to quiet. A store kept subscribed app-wide (a status badge) can poll
20
+ * less often, or not at all if those can wait for the next screen.
21
+ */
22
+ export declare function cadreStore(view: CadreView, opts?: StoreOptions): Loader<CadreStatus>;
23
+ /**
24
+ * Reachability: can anybody answer an invitation from this device, which relays it is
25
+ * configured with, and whether the relay reservation holds — read live, because a
26
+ * configured relay is not a working one and a reservation can be lost after it was
27
+ * granted. Re-read when this device's addresses change; a slow backstop poll covers a
28
+ * change no event announces (a machine of the party's coming up or going quiet).
29
+ */
30
+ export declare function reachabilityStore(view: ReachabilityView, opts?: StoreOptions): Loader<Reachability>;
31
+ /**
32
+ * Whether the invitation `token` is ready to hand out (`InvitationReadiness`), live: it turns
33
+ * `ready` once one of the machines the invitation names can answer a join through it, and until
34
+ * then says what those machines are missing. The answer comes from cadre-core's probe of those
35
+ * machines, which the model asks in the background and asks again on its own ladder while the
36
+ * answer is still `waiting`; this store re-reads each time one lands.
37
+ */
38
+ export declare function invitationReadinessStore(view: InvitationsView, token: string): Readable<InvitationReadiness>;
package/dist/stores.js ADDED
@@ -0,0 +1,48 @@
1
+ import { writable } from './store.js';
2
+ import { cadreOk } from './result.js';
3
+ import { loader } from './loader.js';
4
+ /**
5
+ * The cadre: this device, its cadrons, and whether it is an enrolled owner. Re-read on every
6
+ * change that has an event: this node starting or stopping, a cadron connecting or dropping, the
7
+ * cadron preferences. The poll catches what has none: a cadron added or removed on another
8
+ * device (it arrives by control replication), and a cadron's `lastSeenAt` ageing, so its
9
+ * presence turns from recent to quiet. A store kept subscribed app-wide (a status badge) can poll
10
+ * less often, or not at all if those can wait for the next screen.
11
+ */
12
+ export function cadreStore(view, opts = {}) {
13
+ return loader({
14
+ load: () => view.cadre.status(),
15
+ changes: onChange => view.changes.cadre(onChange),
16
+ pollMs: opts.pollMs ?? 30_000,
17
+ });
18
+ }
19
+ /**
20
+ * Reachability: can anybody answer an invitation from this device, which relays it is
21
+ * configured with, and whether the relay reservation holds — read live, because a
22
+ * configured relay is not a working one and a reservation can be lost after it was
23
+ * granted. Re-read when this device's addresses change; a slow backstop poll covers a
24
+ * change no event announces (a machine of the party's coming up or going quiet).
25
+ */
26
+ export function reachabilityStore(view, opts = {}) {
27
+ return loader({
28
+ load: async () => cadreOk(await view.reachability.get()),
29
+ changes: onChange => view.changes.reachability(onChange),
30
+ debounceMs: 250,
31
+ pollMs: opts.pollMs ?? 30_000,
32
+ });
33
+ }
34
+ /**
35
+ * Whether the invitation `token` is ready to hand out (`InvitationReadiness`), live: it turns
36
+ * `ready` once one of the machines the invitation names can answer a join through it, and until
37
+ * then says what those machines are missing. The answer comes from cadre-core's probe of those
38
+ * machines, which the model asks in the background and asks again on its own ladder while the
39
+ * answer is still `waiting`; this store re-reads each time one lands.
40
+ */
41
+ export function invitationReadinessStore(view, token) {
42
+ const read = () => view.invitations.readiness(token);
43
+ return writable(read(), set => {
44
+ set(read());
45
+ return view.changes.invitations(() => set(read()));
46
+ });
47
+ }
48
+ //# sourceMappingURL=stores.js.map