fedipod-server 0.11.0 → 0.13.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 (152) hide show
  1. package/README.md +22 -6
  2. package/dist/claims.d.ts +8 -0
  3. package/dist/claims.js +10 -0
  4. package/dist/handler.d.ts +13 -0
  5. package/dist/handler.js +56 -11
  6. package/dist/handler.jsonld +8 -0
  7. package/dist/store-pod.js +18 -4
  8. package/lib/{c2s.mjs → client/c2s.mjs} +10 -3
  9. package/lib/{localapi.mjs → client/localapi.mjs} +2 -2
  10. package/lib/client/masto/accounts.mjs +264 -0
  11. package/lib/client/masto/body.mjs +69 -0
  12. package/lib/client/masto/index.mjs +183 -0
  13. package/lib/client/masto/instance.mjs +104 -0
  14. package/lib/client/masto/media.mjs +133 -0
  15. package/lib/client/masto/oauth.mjs +599 -0
  16. package/lib/client/masto/render.mjs +459 -0
  17. package/lib/client/masto/statuses.mjs +331 -0
  18. package/lib/client/masto/timelines.mjs +316 -0
  19. package/lib/{streaming.mjs → client/streaming.mjs} +1 -1
  20. package/lib/{acctfeed.mjs → connections/acctfeed.mjs} +1 -1
  21. package/lib/{atproto.mjs → connections/atproto.mjs} +15 -16
  22. package/lib/{bskygroup.mjs → connections/bskygroup.mjs} +1 -1
  23. package/lib/{fediacct.mjs → connections/fediacct.mjs} +31 -35
  24. package/lib/{import.mjs → connections/import.mjs} +1 -1
  25. package/lib/{tagfeed.mjs → connections/tagfeed.mjs} +3 -3
  26. package/lib/connections/vault.mjs +114 -0
  27. package/lib/core/as2.mjs +170 -0
  28. package/lib/core/contexts/activitystreams.json +379 -0
  29. package/lib/core/contexts/did-v1.json +57 -0
  30. package/lib/core/contexts/fep-5711.json +36 -0
  31. package/lib/core/contexts/gotosocial.json +86 -0
  32. package/lib/core/contexts/identity-v1.json +152 -0
  33. package/lib/core/contexts/index.mjs +45 -0
  34. package/lib/core/contexts/join-lemmy.json +33 -0
  35. package/lib/core/contexts/joinmastodon.json +28 -0
  36. package/lib/core/contexts/map.json +16 -0
  37. package/lib/core/contexts/miscellany.json +19 -0
  38. package/lib/core/contexts/schemaorg.json +8845 -0
  39. package/lib/core/contexts/security-data-integrity-v1.json +78 -0
  40. package/lib/core/contexts/security-data-integrity-v2.json +81 -0
  41. package/lib/core/contexts/security-multikey-v1.json +35 -0
  42. package/lib/core/contexts/security-v1.json +74 -0
  43. package/lib/core/contexts/webfinger.json +10 -0
  44. package/lib/{deliver.mjs → core/deliver.mjs} +2 -2
  45. package/lib/core/graphview.mjs +269 -0
  46. package/lib/core/intake/activities.mjs +437 -0
  47. package/lib/core/intake/activity.mjs +240 -0
  48. package/lib/core/intake/channel.mjs +144 -0
  49. package/lib/core/intake/group.mjs +222 -0
  50. package/lib/core/intake/index.mjs +629 -0
  51. package/lib/core/intake/notes.mjs +288 -0
  52. package/lib/core/intake/verify.mjs +142 -0
  53. package/lib/{keys.mjs → core/keys.mjs} +1 -1
  54. package/lib/core/publisher/collections.mjs +229 -0
  55. package/lib/core/publisher/index.mjs +421 -0
  56. package/lib/core/publisher/notes.mjs +188 -0
  57. package/lib/core/publisher/questions.mjs +233 -0
  58. package/lib/core/publisher/restore.mjs +199 -0
  59. package/lib/core/shapes/activitystreams.ttl +129 -0
  60. package/lib/core/shapes/index.mjs +107 -0
  61. package/lib/core/shapes/shapes-text.mjs +13 -0
  62. package/lib/{social.mjs → core/social.mjs} +2 -2
  63. package/lib/{store.mjs → core/store.mjs} +4 -0
  64. package/lib/{wire.mjs → core/wire.mjs} +2 -2
  65. package/lib/device/admin/index.mjs +13 -0
  66. package/lib/device/admin/origins.mjs +35 -0
  67. package/lib/device/admin/routes/connections.mjs +144 -0
  68. package/lib/device/admin/routes/gateway.mjs +199 -0
  69. package/lib/device/admin/routes/lifecycle.mjs +191 -0
  70. package/lib/device/admin/routes/owner.mjs +322 -0
  71. package/lib/device/admin/routes/setup.mjs +393 -0
  72. package/lib/device/admin/routes/social.mjs +188 -0
  73. package/lib/device/admin/server.mjs +95 -0
  74. package/lib/device/admin/static.mjs +244 -0
  75. package/lib/device/admin/surface.mjs +274 -0
  76. package/lib/device/cli/commands/account.mjs +586 -0
  77. package/lib/device/cli/commands/run.mjs +278 -0
  78. package/lib/device/cli/commands/service.mjs +221 -0
  79. package/lib/device/cli/commands/setup.mjs +410 -0
  80. package/lib/device/cli/commands/state.mjs +559 -0
  81. package/lib/device/cli/context.mjs +288 -0
  82. package/lib/{migrate.mjs → device/migrate.mjs} +1 -1
  83. package/lib/{remote.mjs → device/remote.mjs} +3 -3
  84. package/lib/{setup.mjs → device/setup.mjs} +3 -3
  85. package/lib/{update.mjs → device/update.mjs} +1 -1
  86. package/lib/{directory.mjs → gateway/directory.mjs} +1 -1
  87. package/lib/{front-core.mjs → gateway/front-core.mjs} +3 -3
  88. package/lib/{gateway-core.mjs → gateway/gateway-core.mjs} +1 -1
  89. package/lib/{httpsig.mjs → gateway/httpsig.mjs} +1 -1
  90. package/lib/server/embed.mjs +405 -0
  91. package/lib/{links.mjs → shared/links.mjs} +1 -1
  92. package/lib/{ua.mjs → shared/ua.mjs} +1 -1
  93. package/package.json +1 -1
  94. package/run-agent.mjs +33 -25
  95. package/web/admin/actors.js +145 -0
  96. package/web/admin/common.js +23 -0
  97. package/web/admin/connections.js +112 -0
  98. package/web/admin/gateway.js +111 -0
  99. package/web/admin/group.js +258 -0
  100. package/web/admin/index.html +7 -1
  101. package/web/admin/record.js +378 -0
  102. package/web/admin/setup/index.html +1 -0
  103. package/web/admin/setup/setup.js +2 -13
  104. package/web/admin/upkeep.js +170 -0
  105. package/web/app/README.md +6 -6
  106. package/web/app/admin-facade.mjs +3 -3
  107. package/web/app/agent.mjs +14 -16
  108. package/web/app/atproto-browser.mjs +1 -1
  109. package/web/app/boot.mjs +2 -3
  110. package/web/app/deliver-relay.mjs +1 -1
  111. package/web/app/dist/boot.js +22 -3
  112. package/web/app/dist/boot.js.map +2 -2
  113. package/web/app/dist/sw.js +21913 -5446
  114. package/web/app/dist/sw.js.map +4 -4
  115. package/web/app/fediacct-browser.mjs +1 -1
  116. package/web/app/keys-browser.mjs +27 -4
  117. package/web/app/shims/shapes-text.mjs +8 -0
  118. package/web/app/signup.mjs +2 -3
  119. package/web/app/site/admin/actors.js +145 -0
  120. package/web/app/site/admin/common.js +23 -0
  121. package/web/app/site/admin/connections.js +112 -0
  122. package/web/app/site/admin/gateway.js +111 -0
  123. package/web/app/site/admin/group.js +258 -0
  124. package/web/app/site/admin/index.html +7 -1
  125. package/web/app/site/admin/record.js +378 -0
  126. package/web/app/site/admin/setup/index.html +1 -0
  127. package/web/app/site/admin/setup/setup.js +2 -13
  128. package/web/app/site/admin/upkeep.js +170 -0
  129. package/web/app/site/boot.js +22 -3
  130. package/web/app/site/sw.js +21913 -5446
  131. package/web/app/sw-src.mjs +17 -2
  132. package/lib/admin.mjs +0 -1913
  133. package/lib/embed.mjs +0 -220
  134. package/lib/intake.mjs +0 -1981
  135. package/lib/mastoapi.mjs +0 -2284
  136. package/lib/publisher.mjs +0 -1192
  137. package/web/admin/admin.js +0 -1181
  138. package/web/app/site/admin/admin.js +0 -1181
  139. /package/lib/{oidc-auth.mjs → client/oidc-auth.mjs} +0 -0
  140. /package/lib/{webpush.mjs → client/webpush.mjs} +0 -0
  141. /package/lib/{bskyfeed.mjs → connections/bskyfeed.mjs} +0 -0
  142. /package/lib/{lease.mjs → core/lease.mjs} +0 -0
  143. /package/lib/{polls.mjs → core/polls.mjs} +0 -0
  144. /package/lib/{proof.mjs → core/proof.mjs} +0 -0
  145. /package/lib/{storage.mjs → core/storage.mjs} +0 -0
  146. /package/lib/{account.mjs → device/account.mjs} +0 -0
  147. /package/lib/{certs.mjs → device/certs.mjs} +0 -0
  148. /package/lib/{export-collections.mjs → device/export-collections.mjs} +0 -0
  149. /package/lib/{home.mjs → device/home.mjs} +0 -0
  150. /package/lib/{ports.mjs → device/ports.mjs} +0 -0
  151. /package/lib/{guard.mjs → shared/guard.mjs} +0 -0
  152. /package/lib/{safefetch.mjs → shared/safefetch.mjs} +0 -0
@@ -0,0 +1,258 @@
1
+ // group.js — the group operator's console and the status, joins, review and
2
+ // follower controls shared with a person: the pickers with their keyboard
3
+ // guard, the request rows, and the refresh of every list.
4
+
5
+ // Each control shows the setting it would change, so what it displays IS the
6
+ // current state — no separate sentence reporting it.
7
+ const MOD = { on: 'moderated', off: 'unmoderated' };
8
+ function renderGroupToggles() {
9
+ $('joins-mod').value = config.approveJoins ? MOD.on : MOD.off;
10
+ $('review-mod').value = config.review ? MOD.on : MOD.off;
11
+ }
12
+ function renderStatus() {
13
+ STATUS_PICK.value = config.quiescedAt ? 'parked' : 'active';
14
+ }
15
+
16
+ // Parking is reversible — the follow graph is saved first and going back to
17
+ // active re-sends a Follow to everyone in it — so the word applies directly,
18
+ // like the moderation controls. The result line says what actually happened.
19
+ let statusBusy = false;
20
+ const setStatus = async (parked) => {
21
+ if (statusBusy || parked === !!config.quiescedAt) return;
22
+ statusBusy = true;
23
+ try {
24
+ const r = await write(parked ? '/park' : '/revive', {},
25
+ parked ? 'parking — unfollowing everyone and closing the inbox' : 'reviving — re-following the saved graph');
26
+ if (r) {
27
+ say(parked
28
+ ? `parked ${r.quiescedAt}: unfollowed ${r.unfollowed}/${r.following}, inbox closed`
29
+ : `revived: inbox open, ${r.refollowed}/${r.of} follow(s) re-sent`);
30
+ await load();
31
+ }
32
+ renderStatus();
33
+ } finally { statusBusy = false; }
34
+ };
35
+
36
+ // One write at a time, because committing an open picker with Enter fires our
37
+ // keydown AND the browser's change — the second call must find the first still
38
+ // holding the flag, or config, not yet updated by the awaited write, lets a
39
+ // duplicate POST through.
40
+ let modBusy = false;
41
+ const setJoins = async (approve) => {
42
+ // Picking the value already in force is not a change: no write, and no
43
+ // republish of the actor for a setting that did not move.
44
+ if (modBusy || approve === !!config.approveJoins) return;
45
+ modBusy = true;
46
+ try {
47
+ if (await write('/joins', { approve }, approve ? 'join requests will wait' : 'anyone may join')) {
48
+ config.approveJoins = approve;
49
+ refreshGroup();
50
+ }
51
+ // Both ways: refused, the control must not keep the value it did not get;
52
+ // granted, a blur meanwhile may have repainted it to the old state.
53
+ renderGroupToggles();
54
+ } finally { modBusy = false; }
55
+ };
56
+ const setReview = async (on) => {
57
+ if (modBusy || on === !!config.review) return;
58
+ modBusy = true;
59
+ try {
60
+ if (await write('/review', { on }, on ? 'posts will be held' : 'posts will be carried at once')) {
61
+ config.review = on;
62
+ refreshGroup();
63
+ }
64
+ renderGroupToggles();
65
+ } finally { modBusy = false; }
66
+ };
67
+
68
+ // Arrowing a closed select fires `change` on every keypress, so a keyboard user
69
+ // running down the list would apply each value they passed — here that silently
70
+ // opens or closes the group. An arrow arms a flag and the change it causes is
71
+ // ignored; Enter commits. A mouse never sets the flag, so clicking is unchanged.
72
+ // Same guard as the actor picker above, for the same reason.
73
+ function onPick(el, apply, repaint = renderGroupToggles) {
74
+ let arrowing = false;
75
+ el.addEventListener('keydown', (ev) => {
76
+ if (['ArrowUp', 'ArrowDown', 'Home', 'End', 'PageUp', 'PageDown'].includes(ev.key)) arrowing = true;
77
+ if (ev.key === 'Enter') { arrowing = false; apply(el.value); }
78
+ // Escape abandons the armed value; what shows must return to what is.
79
+ if (ev.key === 'Escape') { arrowing = false; repaint(); }
80
+ });
81
+ // Leaving abandons too. Unconditional, because the swallow above already
82
+ // consumed the flag — the select may show a state that was never applied,
83
+ // and repainting from config costs nothing when it does match.
84
+ el.addEventListener('blur', () => { arrowing = false; repaint(); });
85
+ el.addEventListener('pointerdown', () => { arrowing = false; });
86
+ el.addEventListener('change', () => {
87
+ if (!arrowing) apply(el.value);
88
+ arrowing = false;
89
+ });
90
+ }
91
+
92
+ onPick($('joins-mod'), (v) => setJoins(v === MOD.on));
93
+ onPick($('review-mod'), (v) => setReview(v === MOD.on));
94
+ onPick(STATUS_PICK, (v) => setStatus(v === 'parked'), renderStatus);
95
+
96
+ // A person's follower gate. Automatic is what a migration wave needs: every
97
+ // follower's server re-follows at once, and the waiting queue caps at 500.
98
+ let followsBusy = false;
99
+ const setAutoAccept = async (auto) => {
100
+ if (followsBusy || auto === !!config.autoAcceptFollows) return;
101
+ followsBusy = true;
102
+ try {
103
+ if (await write('/config', { autoAcceptFollows: auto },
104
+ auto ? 'new followers are accepted automatically' : 'new followers will wait for you')) {
105
+ config.autoAcceptFollows = auto;
106
+ }
107
+ FOLLOWS_PICK.value = config.autoAcceptFollows ? 'auto' : 'approve';
108
+ } finally { followsBusy = false; }
109
+ };
110
+ onPick(FOLLOWS_PICK, (v) => setAutoAccept(v === 'auto'),
111
+ () => { FOLLOWS_PICK.value = config?.autoAcceptFollows ? 'auto' : 'approve'; });
112
+
113
+ // One row: what it is, then what can be done to it.
114
+ function row(text, sub, actions) {
115
+ const li = document.createElement('li');
116
+ const span = document.createElement('span');
117
+ span.textContent = text;
118
+ if (sub) {
119
+ const small = document.createElement('div');
120
+ small.className = 'muted';
121
+ small.textContent = sub;
122
+ span.appendChild(small);
123
+ }
124
+ li.appendChild(span);
125
+ for (const [label, run, hint] of actions) {
126
+ const b = document.createElement('button');
127
+ b.className = 'inline'; // sized like the page's other buttons
128
+ b.textContent = label;
129
+ // A list of fifteen buttons all reading "Mute" tells a screen-reader user
130
+ // browsing by button nothing; name each one for the row it acts on.
131
+ b.setAttribute('aria-label', `${label} ${text}`);
132
+ // Three leading spaces: the tooltip appears under the pointer, and without
133
+ // them the first word sits behind the cursor.
134
+ if (hint) b.title = ` ${hint}`;
135
+ // Where focus should land afterwards. `b.disabled = true` blurs it to
136
+ // <body> at once, and refreshGroup() then wipes and rebuilds the list, so
137
+ // without this every mute, eject, admit or refuse dropped a keyboard user
138
+ // back to the top of the page.
139
+ b.addEventListener('click', async () => {
140
+ const list = li.parentNode;
141
+ focusAfterRefresh = { listId: list?.id, index: [...(list?.children || [])].indexOf(li), label };
142
+ b.disabled = true;
143
+ await run();
144
+ refreshGroup();
145
+ });
146
+ li.appendChild(b);
147
+ }
148
+ return li;
149
+ }
150
+
151
+ // Set by a row action, consumed by the fill() that replaces that row.
152
+ let focusAfterRefresh = null;
153
+
154
+ function fill(listId, countId, items, make) {
155
+ const ul = $(listId);
156
+ ul.textContent = '';
157
+ $(countId).textContent = items.length ? `(${items.length})` : '(none)';
158
+ for (const it of items) ul.appendChild(make(it));
159
+ if (!focusAfterRefresh || focusAfterRefresh.listId !== listId) return;
160
+ const { index, label } = focusAfterRefresh;
161
+ focusAfterRefresh = null;
162
+ // The same action on the row that took this one's place, or the row before it
163
+ // when the list just got shorter. Nothing left to land on is the one case
164
+ // where the heading is the honest answer.
165
+ const rows = [...ul.children];
166
+ const li = rows[Math.min(index, rows.length - 1)];
167
+ const same = li && [...li.querySelectorAll('button')].find(x => x.textContent === label);
168
+ const heading = $(countId).closest('h3');
169
+ // A bare <h3> is not focusable, so the "nothing left" fallback would silently
170
+ // drop focus to <body> — give it a programmatic-only tab stop first.
171
+ if (heading && !heading.hasAttribute('tabindex')) heading.setAttribute('tabindex', '-1');
172
+ (same || li?.querySelector('button') || heading)?.focus?.();
173
+ }
174
+
175
+ // The request rows, shared: a group calls them joins, a person calls them
176
+ // follows, and the two do exactly the same thing to exactly the same queue.
177
+ function fillRequests(list) {
178
+ fill('requests', 'requests-count', list, (r) => row(r.actor, r.at, [
179
+ ['Accept', () => write('/admit', { actor: r.actor }, 'accepted'), 'Let them follow you'],
180
+ ['Refuse', () => write('/refuse', { actor: r.actor }, 'refused'), 'Turn this down; they may ask again'],
181
+ ]));
182
+ }
183
+
184
+ // The whole queue in one action — the shape a migration wave arrives in.
185
+ $('admit-all').addEventListener('click', async () => {
186
+ if (await write('/admit', { all: true }, 'accepted everyone waiting')) {
187
+ if (config.kind === 'group') refreshGroup(); else refreshRequests();
188
+ }
189
+ });
190
+
191
+ // A person's whole group pane is this one block, and only when it has something
192
+ // in it — an empty heading promising a list is what the group console avoids too.
193
+ async function refreshRequests() {
194
+ const { json } = await api('/requests');
195
+ const list = json?.requests || [];
196
+ $('pane-group').hidden = !list.length;
197
+ $('block-requests').hidden = !list.length;
198
+ if (list.length) fillRequests(list);
199
+ }
200
+
201
+ // What a queued moderation would do, in the words the buttons beside it use.
202
+ function describeModeration(e) {
203
+ const o = e.activity?.object;
204
+ const id = typeof o === 'string' ? o : o?.id || '';
205
+ if (e.type === 'Block') return `block ${id}`;
206
+ if (e.type === 'Remove') return `eject ${id}`;
207
+ if (e.type === 'Delete') return `take down ${id}`;
208
+ if (e.type === 'Add') return `add ${id}`;
209
+ return id || 'no target named';
210
+ }
211
+
212
+ async function refreshGroup() {
213
+ const [members, requests, pending, announced, modqueue] = await Promise.all(
214
+ ['/members', '/requests', '/pending', '/announced', '/modqueue']
215
+ .map(p => api(p).then(r => r.json || {})));
216
+
217
+ fill('requests', 'requests-count', requests.requests || [], (r) => row(r.actor, r.at, [
218
+ ['Admit', () => write('/admit', { actor: r.actor }, 'admitted'), 'Let them in — they become a member'],
219
+ ['Refuse', () => write('/refuse', { actor: r.actor }, 'refused'), 'Turn this request down; they may ask again'],
220
+ ]));
221
+
222
+ fill('pending', 'pending-count', pending.pending || [], (p) => row(p.noteId, `${p.actor} · ${p.at}`, [
223
+ ['Carry it', () => write('/approve', { noteId: p.noteId }, 'carried'), 'Announce this post to every member'],
224
+ ['Decline', () => write('/decline', { noteId: p.noteId }, 'declined'), 'Do not carry it — the post stays up on its author\u2019s pod'],
225
+ ]));
226
+
227
+ // Moderation another server asked for: apply it, or turn it down. The route
228
+ // answers with the list itself, not an object wrapping one.
229
+ const modq = Array.isArray(modqueue) ? modqueue : (modqueue.queue || []);
230
+ fill('modqueue', 'modqueue-count', modq, (e) => row(
231
+ `${e.type} — ${describeModeration(e)}`, `asked by ${e.moderator} · ${e.at}`, [
232
+ ['Carry it out', () => write('/modqueue', { id: e.id, action: 'apply' }, 'applied'),
233
+ 'Do what the moderator asked, as if you had asked it'],
234
+ ['Turn it down', () => write('/modqueue', { id: e.id, action: 'dismiss' }, 'dismissed'),
235
+ 'Leave things as they are and drop the request'],
236
+ ]));
237
+
238
+ // A queue nothing can arrive in is not an empty list, it is a list that does
239
+ // not apply — so the setting has to be on before the heading appears at all.
240
+ // This one has no setting: it fills only when a moderator has asked.
241
+ $('block-requests').hidden = !(config.approveJoins && (requests.requests || []).length);
242
+ $('block-pending').hidden = !(config.review && (pending.pending || []).length);
243
+ $('block-modqueue').hidden = !modq.length;
244
+
245
+ fill('members', 'members-count', members.members || [], (m) => row(
246
+ m.handle || m.actor, m.muted ? 'muted — their posts are not carried' : null,
247
+ [
248
+ m.muted
249
+ ? ['Unmute', () => write('/unmute', { actor: m.actor }, 'unmuted'), 'Carry their posts again']
250
+ : ['Mute', () => write('/mute', { actor: m.actor }, 'muted'), 'Stop carrying their posts; they stay a member'],
251
+ ['Eject', () => write('/eject', { actor: m.actor }, 'ejected'), 'Remove them and tell their server; also mutes'],
252
+ ]));
253
+
254
+ fill('announced', 'announced-count', announced.announced || [], (a) => row(
255
+ a.noteId, `${a.actor} · ${a.announcedAt}`,
256
+ [['Retract', () => write('/retract', { noteId: a.noteId }, 'retracted'), 'Un-say this announcement to everyone it reached']]));
257
+ }
258
+
@@ -551,6 +551,12 @@ pre { overflow-x: auto; background: #0001; padding: .6rem; border-radius: .3rem;
551
551
 
552
552
  <script src="bar.js"></script>
553
553
  <script src="window.js"></script>
554
- <script src="admin.js"></script>
554
+ <script src="common.js"></script>
555
+ <script src="record.js"></script>
556
+ <script src="actors.js"></script>
557
+ <script src="connections.js"></script>
558
+ <script src="group.js"></script>
559
+ <script src="upkeep.js"></script>
560
+ <script src="gateway.js"></script>
555
561
  </body>
556
562
  </html>
@@ -0,0 +1,378 @@
1
+ // record.js — the record itself: what the page holds of the config, the
2
+ // messages it says, every write, the load, the panels, and the rows of the
3
+ // facts list with the identity rows and their controls.
4
+ // admin.js — the record, as a page. Everything here is an existing admin
5
+ // route; the CLI's own group commands are thin clients over the same ones.
6
+ //
7
+ // Two rules the routes enforce and this page respects: a write is a MERGE, so a
8
+ // form that never mentions a field cannot delete it; and anything on the wire is
9
+ // not real until the actor is republished, which POST /config does for itself.
10
+ //
11
+ // The UI password is deliberately not here — `fedipod passwd` sets it. It
12
+ // only gates /oauth/authorize, so it does nothing for a loopback-only agent.
13
+
14
+ let config = null;
15
+ // Held, because render() moves it into a generated row and empties that row's
16
+ // list on the next pass — after which getElementById would not find it again.
17
+ const MODERATION = $('moderation');
18
+ const STATUS = $('status-ctl');
19
+ const STATUS_PICK = $('status-pick'); // held: getElementById can't see it mid-render
20
+ const IDENT_CTL = $('ident-ctl');
21
+ const FOLLOWS_CTL = $('follows-ctl');
22
+ const FOLLOWS_PICK = $('follows-pick');
23
+ const UPDATE_CTL = $('update-ctl');
24
+ const UPDATE_WORD = $('update-word');
25
+ const UPDATE_GO = $('update-go');
26
+
27
+ // #say and #fatal live in the accessibility tree from load and hide by being
28
+ // empty (see the stylesheet). Unhiding a live region and filling it in the same
29
+ // task is the classic way to get no announcement at all.
30
+ function say(text, cls = 'ok') {
31
+ const el = $('say');
32
+ el.className = cls;
33
+ // Clear first, then set on the next task: a live region that is handed the
34
+ // same text it already holds announces nothing, so two identical messages in
35
+ // a row ("nothing changed", "nothing changed") would be silent the second time.
36
+ el.textContent = '';
37
+ setTimeout(() => { el.textContent = text; }, 30);
38
+ }
39
+
40
+ // Every write goes through here, so nothing silently half-succeeds.
41
+ async function write(path, body, done) {
42
+ const { status, json } = await postJson(path, body);
43
+ if (status >= 400) { say(json?.error || `refused (HTTP ${status})`, 'err'); return null; }
44
+ say(done);
45
+ return json;
46
+ }
47
+
48
+ UPDATE_GO.onclick = async () => {
49
+ UPDATE_GO.disabled = true;
50
+ const r = await write('/update', {}, 'updating — the agents restart when it finishes; reload in a moment');
51
+ if (!r) UPDATE_GO.disabled = false;
52
+ };
53
+
54
+ async function load() {
55
+ const { status, json } = await api('/config');
56
+ if (status === 409) {
57
+ $('fatal').textContent = 'This agent has no identity yet.';
58
+ const a = document.createElement('a');
59
+ a.href = '/admin/setup/';
60
+ a.textContent = ' Set it up.';
61
+ $('fatal').appendChild(a);
62
+ return;
63
+ }
64
+ if (status !== 200 || !json) {
65
+ $('fatal').textContent = json?.error || `could not read the record (HTTP ${status})`;
66
+ return;
67
+ }
68
+ config = json;
69
+ render();
70
+ if (new URLSearchParams(location.search).has('new')) openNewActor();
71
+ }
72
+
73
+ // Every disclosure on the page — a form, the log, a lifecycle confirmation —
74
+ // is a panel declared inside the floating window and shown by window.js. It
75
+ // used to be an accordion at the foot of the page, which pushed whatever you
76
+ // were reading out from under you and could only ever show one thing.
77
+ //
78
+ // The reset lives here rather than in window.js: the window knows how to show a
79
+ // panel, not what any of them mean.
80
+ function resetConfirm() {
81
+ pending = null;
82
+ for (const k of Object.keys(LIFECYCLE)) $(`warn-${k}`)?.hidden !== undefined && ($(`warn-${k}`).hidden = true);
83
+ $('confirm-handle').value = '';
84
+ $('confirm-handle-move').value = '';
85
+ $('move-target').value = '';
86
+ $('rotate-password').value = '';
87
+ }
88
+ function closePanels(keep = null) {
89
+ if (!keep) solWindow.close();
90
+ if (keep !== 'output') outputSource = null;
91
+ if (keep !== 'confirm-form') resetConfirm();
92
+ }
93
+ // Closing it by the ✕ or by Escape has to clear the same state a Cancel does.
94
+ document.getElementById('win').addEventListener('win:closed', () => {
95
+ outputSource = null;
96
+ resetConfirm();
97
+ $('bsky-password').value = ''; // never leave a secret in a closed panel
98
+ });
99
+
100
+
101
+ // One row per identity connected elsewhere, indented under the row that adds
102
+ // them. Each carries its own way out: disconnecting one has nothing to do with
103
+ // the others.
104
+ function identityRows() {
105
+ const out = [];
106
+ const row = (label, ...nodes) => {
107
+ const dt = document.createElement('dt');
108
+ dt.className = 'under';
109
+ dt.textContent = label;
110
+ const dd = document.createElement('dd');
111
+ dd.append(...nodes);
112
+ out.push([dt, dd]);
113
+ };
114
+ // One descriptor shape for every connected account — Bluesky and each
115
+ // fediverse account — so the row and its Options menu build the same way.
116
+ const accounts = [];
117
+ if (config.atproto?.connected) accounts.push({
118
+ label: 'Bluesky', handle: `@${config.atproto.handle}`,
119
+ href: `https://bsky.app/profile/${config.atproto.handle}`,
120
+ storage: config.atproto.storage || null,
121
+ feedPaused: 'feedPaused' in config.atproto ? config.atproto.feedPaused : null,
122
+ crossPost: 'crossPost' in config.atproto ? config.atproto.crossPost : null,
123
+ feed: (paused) => ['/atproto', { feedPaused: paused }],
124
+ cross: (on) => ['/atproto', { crossPost: on }],
125
+ store: (w) => ['/atproto', { storage: w }],
126
+ off: () => ['/atproto/disconnect', {}],
127
+ });
128
+ for (const acct of config.fediAccounts || []) accounts.push({
129
+ label: acct.host,
130
+ handle: acct.needsReconnect ? `${acct.handle} — sign in again` : acct.handle,
131
+ warn: acct.needsReconnect,
132
+ storage: acct.storage || null,
133
+ feedPaused: !acct.enabled,
134
+ crossPost: null,
135
+ feed: (paused) => ['/fediacct', { id: acct.id, enabled: !paused }],
136
+ store: (w) => ['/fediacct', { id: acct.id, storage: w }],
137
+ off: () => ['/fediacct/disconnect', { id: acct.id }],
138
+ });
139
+ for (const acct of accounts) {
140
+ const name = document.createElement(acct.href ? 'a' : 'span');
141
+ name.textContent = acct.handle;
142
+ if (acct.href) { name.href = acct.href; name.target = '_blank'; name.rel = 'noopener'; name.title = ' Open this account elsewhere in a new tab'; }
143
+ if (acct.warn) name.className = 'warn';
144
+ // Where storage is a real choice (every browser-build account today), two
145
+ // dropdowns sit in the row itself. Where it isn't (the Node agent's
146
+ // Bluesky, which shows a cross-post toggle instead), the Options
147
+ // disclosure it always has is unchanged.
148
+ row(acct.label, name, ' ', ...(acct.storage ? connectionControls(acct) : [optionsMenu(acct)]));
149
+ }
150
+ return out;
151
+ }
152
+
153
+ // Connected, Paused or Disconnected, and where the key lives — one dropdown
154
+ // each, in the row. Replaces the separate feed and connect dropdowns that used
155
+ // to sit behind an Options disclosure; only reached where acct.storage is set.
156
+ function connectionControls(acct) {
157
+ const send = async ([path, payload], msg) => { if (await write(path, payload, msg)) await load(); };
158
+ const pick = (opts, current, onChange, title) => {
159
+ const el = document.createElement('select');
160
+ if (title) el.title = title;
161
+ for (const [v, t] of opts) { const o = document.createElement('option'); o.value = v; o.textContent = t; o.selected = v === current; el.appendChild(o); }
162
+ el.addEventListener('change', () => onChange(el.value));
163
+ return el;
164
+ };
165
+ const conn = pick(
166
+ [['connected', 'Connected'], ['paused', 'Paused'], ['disconnected', 'Disconnected']],
167
+ acct.feedPaused ? 'paused' : 'connected',
168
+ (v) => (v === 'disconnected'
169
+ ? send(acct.off(), 'disconnected')
170
+ : send(acct.feed(v === 'paused'), v === 'paused' ? 'paused adding to your feed' : 'added to your home feed')),
171
+ ' Connected feeds this account into your home feed here; Paused keeps the account but stops adding its posts; Disconnected removes it.');
172
+ const storage = pick(
173
+ [['pod', 'Store key on Pod'], ['browser', 'Store key in Browser']],
174
+ acct.storage,
175
+ (v) => {
176
+ if (v === 'pod' && !confirm('Store this account on your pod?\n\nIt will follow you to any browser you sign in from — but a full-access token to that account then lives on your pod.')) { load(); return; }
177
+ send(acct.store(v), v === 'pod' ? 'stored on your pod' : 'stored in this browser');
178
+ },
179
+ ' On your pod the key follows you to any browser you sign in from, and a full-access token then lives there; in this browser the token never leaves this device.');
180
+ const wrap = document.createElement('span');
181
+ wrap.className = 'conn-controls';
182
+ wrap.append(conn, ' ', storage);
183
+ return [wrap];
184
+ }
185
+
186
+ // Every connected account without a storage choice carries an Options menu
187
+ // instead: pause its feed, its cross-post toggle (the Node agent's Bluesky),
188
+ // disconnect.
189
+ function optionsMenu(acct) {
190
+ const d = document.createElement('details');
191
+ d.className = 'opts';
192
+ const sum = document.createElement('summary');
193
+ sum.textContent = 'Options';
194
+ d.appendChild(sum);
195
+ const body = document.createElement('div');
196
+ d.appendChild(body);
197
+
198
+ // Each control is one dropdown whose options ARE the states, so it needs no
199
+ // separate label — the chosen option reads as the current state.
200
+ const pick = (opts, current, onChange) => {
201
+ const el = document.createElement('select');
202
+ for (const [v, t] of opts) { const o = document.createElement('option'); o.value = v; o.textContent = t; o.selected = v === current; el.appendChild(o); }
203
+ el.addEventListener('change', () => onChange(el.value));
204
+ body.appendChild(el);
205
+ };
206
+ const send = async ([path, payload], msg) => { if (await write(path, payload, msg)) await load(); };
207
+
208
+ // Feed: shown in / hidden from the feed you read here.
209
+ if (acct.feedPaused !== null) {
210
+ pick([['show', 'Add to home feed'], ['hide', 'Pause adding to home feed']], acct.feedPaused ? 'hide' : 'show',
211
+ (v) => send(acct.feed(v === 'hide'), v === 'hide' ? 'paused adding to your feed' : 'added to your home feed'));
212
+ }
213
+ // Storage where the browser offers the choice; the Node agent's Bluesky shows
214
+ // its cross-post toggle in the same slot instead.
215
+ if (acct.storage) {
216
+ pick([['browser', 'Store key in Browser'], ['pod', 'Store key on Pod']], acct.storage, (v) => {
217
+ if (v === 'pod' && !confirm('Store this account on your pod?\n\nIt will follow you to any browser you sign in from — but a full-access token to that account then lives on your pod.')) { load(); return; }
218
+ send(acct.store(v), v === 'pod' ? 'stored on your pod' : 'stored in this browser');
219
+ });
220
+ } else if (acct.crossPost !== null) {
221
+ pick([['on', 'Cross-post On'], ['off', 'Cross-post Off']], acct.crossPost ? 'on' : 'off',
222
+ (v) => send(acct.cross(v === 'on'), ''));
223
+ }
224
+ // Connection: staying connected, or disconnecting.
225
+ pick([['connected', 'Connected'], ['disconnect', 'Disconnect']], 'connected',
226
+ (v) => { if (v === 'disconnect') send(acct.off(), 'disconnected'); else load(); });
227
+
228
+ // The storage consequence, at the bottom of the box under every dropdown.
229
+ if (acct.storage) {
230
+ const hint = document.createElement('p'); hint.className = 'opt-hint';
231
+ hint.textContent = acct.storage === 'pod'
232
+ ? 'Follows you to every browser you sign in from; a full-access token lives on your pod.'
233
+ : 'Stays in this browser; the token never leaves this device.';
234
+ body.appendChild(hint);
235
+ }
236
+ return d;
237
+ }
238
+
239
+ function render() {
240
+ // The bar names the actor, the same way on every page. Only the tab title is
241
+ // this page's own business.
242
+ document.title = `FediPod — ${config.handle}`;
243
+ const facts = $('facts');
244
+ facts.textContent = '';
245
+ // What this actor IS comes first. The handle is already in the address beside
246
+ // the heading; the pod, the issuer and the actor URL all read off the WebID;
247
+ // and where the private half sits is not something you act on from here.
248
+ const origins = config.origins || {};
249
+ // Two of these are addresses of things you can open, so they are links. The
250
+ // fediverse one goes to this actor's own page in the client, same origin, so
251
+ // it stays in the tab. The Solid one leaves for the pod, so it does not.
252
+ const rows = [
253
+ ['kind', config.kind ? config.kind[0].toUpperCase() + config.kind.slice(1) : config.kind],
254
+ // The value is the select itself — what it shows IS the state, and
255
+ // changing the word is the whole action, like the moderation controls.
256
+ ['status', 'ctl'],
257
+ ['Fediverse identity', config.address || `@${config.handle} — no resolvable address`,
258
+ config.accountId && config.address ? { href: `/admin/client/#/a/${config.accountId}` } : null],
259
+ ['Solid identity', config.webId, config.remotePod ? { href: config.remotePod, blank: true } : null],
260
+ ['Other identities', 'ctl'],
261
+ ['local store', config.home],
262
+ // The address you actually open, not the bare number — the named origin when
263
+ // there is one, since that is what the client and the OAuth redirect use. An
264
+ // agent with no local host of its own (embedded in a pod server, or in a
265
+ // browser) sends none, and then there is no row rather than a bare number.
266
+ ['local host', (origins.named || origins.loopback || '').replace(/\/$/, '') || null],
267
+ ];
268
+ if (config.version || config.update || config.pendingUpgrade?.length) rows.push(['software', 'ctl']);
269
+ rows.push(['gateway', 'ctl']);
270
+ if (config.quiescedAt) rows.push(['parked since', config.quiescedAt]);
271
+ if (config.movedTo) rows.push(['moved to', config.movedTo]);
272
+ // A person gates followers here; a group's gate is the joins control on its
273
+ // kind row, so the row would be a second switch for the same thing.
274
+ if (config.kind !== 'group') rows.splice(2, 0, ['new followers', 'ctl']);
275
+ // Rows that belong under the one being written, appended after it.
276
+ let kids = null;
277
+ for (const [k, v, link] of rows) {
278
+ if (!v) continue;
279
+ const dt = document.createElement('dt');
280
+ dt.textContent = k;
281
+ const dd = document.createElement('dd');
282
+ if (link) {
283
+ const a = document.createElement('a');
284
+ a.href = link.href;
285
+ a.textContent = v;
286
+ if (link.blank) {
287
+ a.target = '_blank';
288
+ // noopener because the pod is another origin: without it the page we
289
+ // open gets a handle on this one through window.opener.
290
+ a.rel = 'noopener';
291
+ a.title = ` Open ${link.href} in a new tab`;
292
+ } else {
293
+ a.title = ` This actor's page in our client`;
294
+ }
295
+ dd.appendChild(a);
296
+ } else {
297
+ dd.textContent = v;
298
+ }
299
+ // What a group can be moderated into is a property of BEING a group, so the
300
+ // controls sit on the row that says so. Moved rather than built here: the
301
+ // page still declares them, and `facts` is emptied on every render.
302
+ if (k === 'kind' && config.kind === 'group') dd.append(MODERATION);
303
+ if (k === 'status') {
304
+ dd.textContent = '';
305
+ dd.append(STATUS);
306
+ STATUS.hidden = false;
307
+ renderStatus();
308
+ }
309
+ if (k === 'new followers') {
310
+ dd.textContent = '';
311
+ dd.append(FOLLOWS_CTL);
312
+ FOLLOWS_CTL.hidden = false;
313
+ FOLLOWS_PICK.value = config.autoAcceptFollows ? 'auto' : 'approve';
314
+ }
315
+ if (k === 'gateway') {
316
+ dd.textContent = '';
317
+ dd.append(GATEWAY_CTL);
318
+ refreshGateway();
319
+ }
320
+ if (k === 'software') {
321
+ dd.textContent = '';
322
+ dd.append(UPDATE_CTL);
323
+ UPDATE_CTL.hidden = false;
324
+ const u = config.update;
325
+ // The version this agent is running, never the one sitting in the
326
+ // checkout — saying otherwise would name a version nobody is serving.
327
+ const running = config.version || u?.current || null;
328
+ const words = [];
329
+ if (running) words.push(u?.available ? `FediPod ${running} — ${u.latest} available` : `FediPod ${running}`);
330
+ if (config.versionOnDisk && running && config.versionOnDisk !== running)
331
+ words.push(`${config.versionOnDisk} is on disk — restart to run it`);
332
+ if (config.pendingUpgrade?.length) words.push('older data layout — run `fedipod upgrade` in a terminal');
333
+ UPDATE_WORD.textContent = words.join('; ');
334
+ UPDATE_GO.hidden = !u?.available;
335
+ }
336
+ // The way to add one. Each account already connected is a row of its own
337
+ // underneath, so this row stays the action and never becomes a list.
338
+ if (k === 'Other identities') {
339
+ dd.textContent = '';
340
+ dd.append(IDENT_CTL);
341
+ IDENT_CTL.hidden = false;
342
+ kids = identityRows();
343
+ }
344
+ facts.append(dt, dd);
345
+ if (kids) {
346
+ for (const [ckt, ckd] of kids) facts.append(ckt, ckd);
347
+ kids = null;
348
+ }
349
+ }
350
+ if (!config.address) {
351
+ const p = document.createElement('p');
352
+ p.className = 'warn';
353
+ p.textContent = `${config.remotePod} is not the root of its own host, so this actor cannot be `
354
+ + 'discovered as a handle by other servers. Posting and reading still work.';
355
+ $('pane-identity').appendChild(p);
356
+ }
357
+
358
+ // pane-others carries the create control too, so it appears even when this is
359
+ // the only actor and even if /profiles cannot be read.
360
+ for (const id of ['pane-others', 'pane-identity', 'rail']) $(id).hidden = false;
361
+ renderAliases();
362
+ renderOthers();
363
+ renderInbox();
364
+ if (config.kind === 'group') {
365
+ // Its lists have no bound, so this page scrolls — see body.group in the CSS.
366
+ document.body.classList.add('group');
367
+ $('pane-group').hidden = false;
368
+ MODERATION.hidden = false; // only a group has any
369
+ renderGroupToggles();
370
+ refreshGroup();
371
+ } else {
372
+ // A person has a follow-request queue too now: nothing binds an inbound
373
+ // Follow to the actor it names, so one that cannot be verified waits here
374
+ // rather than being accepted on the strength of who it claims to be.
375
+ refreshRequests();
376
+ }
377
+ }
378
+
@@ -186,6 +186,7 @@ button:disabled { opacity: .5; cursor: default; }
186
186
  </main>
187
187
 
188
188
  <script src="../bar.js"></script>
189
+ <script src="../common.js"></script>
189
190
  <script src="setup.js"></script>
190
191
  </body>
191
192
  </html>