clavarium 0.2.242-beta.1 → 0.2.243-beta.1

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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.242-beta.1",
3
+ "version": "0.2.243-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.242-beta.1",
9
+ "version": "0.2.243-beta.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.242-beta.1",
3
+ "version": "0.2.243-beta.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
@@ -143,6 +143,14 @@ export class Mailboxes {
143
143
  return { host: m.host, port: m.port ?? 993, user: m.user, password: this.#vault.open(m.sealed) };
144
144
  }
145
145
 
146
+ /* WHAT A SIGN-IN MAILBOX READS when it is one of these (20-11, #395): server side only, never to the page;
147
+ a classic one or one signed in with Google or Microsoft alike. */
148
+ readSettings(name) {
149
+ const m = this.#store.get(name);
150
+ if (!m) throw new Refusal(404, 'No such mailbox.');
151
+ return { host: m.host, port: m.port ?? 993, user: m.user, ...(m.provider ? { provider: m.provider } : {}), password: this.#vault.open(m.sealed) };
152
+ }
153
+
146
154
  /* Adds a mailbox after proving it can be read, as a folder of that name. */
147
155
  async add(body) {
148
156
  const name = String(body?.name ?? '');
package/server/main.mjs CHANGED
@@ -425,7 +425,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
425
425
  secrets.expired = (name, users) => { events.add({ kind: 'asset', text: `Secret ${name} expired: no longer given${users.length ? ` to ${users.join(', ')}` : ''}` }); };
426
426
  secrets.check();
427
427
  const expiryTimer = setInterval(() => secrets.check(), 10 * 60_000); expiryTimer.unref();
428
- const signin = new SignInMailboxes({ store: new Store(`${dataDir}/signin.json`), vault, rules: (name) => all.signinRules(name) });
428
+ const signin = new SignInMailboxes({ store: new Store(`${dataDir}/signin.json`), vault, rules: (name) => all.signinRules(name), mailboxes: () => { try { return mailboxes; } catch { return null; } } });
429
429
  /* Each opening: the runner and the attached secrets are put in the VM,
430
430
  and the tool is started through the runner. */
431
431
  const network = new Network({ host: asHost, offline: () => all.offline() });
@@ -197,6 +197,7 @@ export const SETTINGS_WORDS_FR = {
197
197
  'set-carry-replace': 'Son travail a des fichiers. Tout remplacer ?', 'set-carry-replace-go': 'Remplacer son travail',
198
198
  'set-carry-tolink': 'À relier à la main :', 'set-carry-import': 'Importer…', 'set-carry-reminders': 'Importer aussi ses rappels et réveils', 'set-carry-go': 'Importer',
199
199
  'set-carry-ask': '« {file} » dans « {name} » ? Mémoire remplacée.', 'set-carry-done': 'Importé depuis « {from} ».',
200
+ 'signin-typed': 'Une autre, saisie ici',
200
201
  'set-mcp-drop': 'Collez ici la configuration du service', 'set-mcp-drop-hint': 'le bloc { "mcpServers": … } de sa page d\'aide',
201
202
  'set-mcp-hand': 'Remplir à la main', 'set-mcp-add-n': 'Ajouter les {n}', 'set-mcp-nokey': 'aucune',
202
203
  'set-mcp-notjson': 'Pas du JSON : collez tout le bloc.',
package/server/signin.mjs CHANGED
@@ -181,23 +181,40 @@ export async function recentSignIns(settings, rules, { connect = tlsConnect, now
181
181
  const CACHE_MS = 5_000;
182
182
 
183
183
  export class SignInMailboxes {
184
- #store; #vault; #rules; #cache = new Map(); #reader;
184
+ #store; #vault; #rules; #cache = new Map(); #reader; #mailboxes;
185
185
 
186
- /* `rules(conversation)` gives the tool's sign-in rules, or undefined. */
187
- constructor({ store, vault, rules, reader = recentSignIns }) { this.#store = store; this.#vault = vault; this.#rules = rules; this.#reader = reader; }
186
+ /* `rules(conversation)` gives the tool's sign-in rules, or undefined. `mailboxes()`: the mailboxes of Assets
187
+ (mailbox.mjs), one of which may be chosen instead of a mailbox typed in here (20-11, #395). */
188
+ constructor({ store, vault, rules, reader = recentSignIns, mailboxes = () => null }) { this.#store = store; this.#vault = vault; this.#rules = rules; this.#reader = reader; this.#mailboxes = mailboxes; }
188
189
 
189
- /* What the page may know: that a mailbox is set, and where. Never the password. */
190
+ /* Where it reads, whichever way it was set: an asset's own settings, or its own. */
191
+ #where(s) {
192
+ if (s?.mailbox) { const boxes = this.#mailboxes(); if (!boxes) throw new Refusal(404, 'No such mailbox.'); return boxes.readSettings(s.mailbox); }
193
+ return { host: s.host, port: s.port, user: s.user, password: this.#vault.open(s.sealed) };
194
+ }
195
+
196
+ /* What the page may know: that a mailbox is set, and where (an asset by its name). Never the password. */
190
197
  settings(conversation) {
191
198
  const s = this.#store.get(conversation);
192
- return { available: this.#rules(conversation) !== undefined, configured: s !== undefined, host: s?.host ?? null, port: s?.port ?? null, user: s?.user ?? null };
199
+ let host = s?.host ?? null; let port = s?.port ?? null; let user = s?.user ?? null;
200
+ if (s?.mailbox) { const m = (this.#mailboxes()?.list() ?? []).find((x) => x.name === s.mailbox); host = m?.host ?? null; port = m?.port ?? null; user = m?.user ?? null; }
201
+ const offered = (this.#mailboxes()?.list() ?? []).map((m) => ({ name: m.name, user: m.user }));
202
+ return { available: this.#rules(conversation) !== undefined, configured: s !== undefined, mailbox: s?.mailbox ?? null, host, port, user, mailboxes: offered };
193
203
  }
194
204
 
195
- /* Saves a mailbox after proving it can be read; an empty host removes it. */
205
+ /* Saves a mailbox after proving it can be read: one of Assets by its name, or one typed in; an empty host
206
+ (and no mailbox) removes it. */
196
207
  async set(conversation, body) {
197
208
  this.#cache.delete(conversation);
198
- if (String(body?.host ?? '').trim() === '') { this.#store.remove(conversation); return this.settings(conversation); }
209
+ const chosen = String(body?.mailbox ?? '').trim();
210
+ if (!chosen && String(body?.host ?? '').trim() === '') { this.#store.remove(conversation); return this.settings(conversation); }
199
211
  const rules = this.#rules(conversation);
200
212
  if (!rules) throw new Refusal(400, 'The tool of this conversation has no sign-in by mail.');
213
+ if (chosen) {
214
+ await this.#reader(this.#where({ mailbox: chosen }), rules);
215
+ this.#store.put({ name: conversation, mailbox: chosen });
216
+ return this.settings(conversation);
217
+ }
201
218
  const settings = readSettings(body);
202
219
  await this.#reader(settings, rules);
203
220
  this.#store.put({ name: conversation, host: settings.host, port: settings.port, user: settings.user, sealed: this.#vault.seal(settings.password) });
@@ -212,7 +229,7 @@ export class SignInMailboxes {
212
229
  if (!s || !rules) return [];
213
230
  const cached = this.#cache.get(conversation);
214
231
  if (cached && Date.now() - cached.at < CACHE_MS) return cached.items;
215
- const items = await this.#reader({ host: s.host, port: s.port, user: s.user, password: this.#vault.open(s.sealed) }, rules);
232
+ const items = await this.#reader(this.#where(s), rules);
216
233
  this.#cache.set(conversation, { at: Date.now(), items });
217
234
  return items;
218
235
  }
package/web/app.js CHANGED
@@ -12816,14 +12816,23 @@
12816
12816
  async function paintSignIn() {
12817
12817
  const j = await (await fetch(`${API}/conversations/${encodeURIComponent(current)}/signin`)).json();
12818
12818
  $('signin-setup').hidden = !j.available;
12819
- $('signin-state').textContent = j.configured ? `Watching ${j.user} on ${j.host}.${j.failure ? ` Not readable just now: ${j.failure}` : ''}` : 'No mailbox is set for this conversation.';
12819
+ $('signin-state').textContent = j.configured ? `Watching ${j.mailbox ? `« ${j.mailbox} » (${j.user ?? '?'})` : `${j.user} on ${j.host}`}.${j.failure ? ` Not readable just now: ${j.failure}` : ''}` : 'No mailbox is set for this conversation.';
12820
12820
  $('signin-remove').hidden = !j.configured;
12821
- }
12821
+ /* One of Assets' mailboxes, or one typed in (20-11, #395). */
12822
+ const box = $('signin-box'); const offered = j.mailboxes ?? [];
12823
+ box.replaceChildren(...offered.map((m) => { const o = document.createElement('option'); o.value = m.name; o.textContent = `${m.name} · ${m.user}`; return o; }));
12824
+ const typed = document.createElement('option'); typed.value = ''; typed.textContent = uiSaid('signin-typed', 'Another, typed in'); box.append(typed);
12825
+ box.value = j.mailbox ?? (j.configured ? '' : (offered[0]?.name ?? ''));
12826
+ $('signin-box-row').hidden = !offered.length;
12827
+ signinTyped();
12828
+ }
12829
+ const signinTyped = () => { const typed = !$('signin-box').value; for (const id of ['signin-host', 'signin-user', 'signin-password']) $(id).hidden = !typed; };
12830
+ $('signin-box').addEventListener('change', signinTyped);
12822
12831
  $('signin-form').addEventListener('submit', async (event) => {
12823
12832
  event.preventDefault();
12824
12833
  $('panel-error').hidden = true;
12825
12834
  $('signin-state').textContent = 'Reading the mailbox once, to check...';
12826
- try { await post(`${API}/conversations/${encodeURIComponent(current)}/signin`, { host: $('signin-host').value, user: $('signin-user').value, password: $('signin-password').value }); $('signin-password').value = ''; }
12835
+ try { const box = $('signin-box').value; await post(`${API}/conversations/${encodeURIComponent(current)}/signin`, box ? { mailbox: box } : { host: $('signin-host').value, user: $('signin-user').value, password: $('signin-password').value }); $('signin-password').value = ''; }
12827
12836
  catch (error) { $('panel-error').textContent = error.message; $('panel-error').hidden = false; }
12828
12837
  await paintSignIn(); void watchSignIn();
12829
12838
  });
package/web/index.html CHANGED
@@ -276,6 +276,7 @@
276
276
  <p class="hint">Its sign-in links, beside the terminal</p><p class="hint tip" hidden>A mailbox for this tool's account, read only; its password never enters the machine.</p>
277
277
  <p id="signin-state" class="hint"></p>
278
278
  <form id="signin-form" autocomplete="off">
279
+ <div class="row" id="signin-box-row"><select id="signin-box" aria-label="Which mailbox"></select></div>
279
280
  <div class="row"><input id="signin-host" placeholder="imap.example.com" aria-label="Mail server" spellcheck="false" autocapitalize="none">
280
281
  <input id="signin-user" placeholder="user" aria-label="Mailbox user" spellcheck="false" autocapitalize="none">
281
282
  <input id="signin-password" type="password" placeholder="password" aria-label="Mailbox password" autocomplete="new-password">