@tomato414941/foundation 0.23.0 → 0.24.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 (2) hide show
  1. package/package.json +1 -1
  2. package/runtime.mjs +11 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomato414941/foundation",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Foundation CLI: give this machine a WebAuthn credential, and hand what is kept to a command without it passing through the agent.",
5
5
  "type": "module",
6
6
  "engines": {
package/runtime.mjs CHANGED
@@ -300,11 +300,20 @@ async function main() {
300
300
  console.log(JSON.stringify(answer, null, 2));
301
301
  return;
302
302
  }
303
+ // What others hold and this machine has a line onto: the things at the far end of the lines it is at the near end of.
304
+ const shownToMe = async () => {
305
+ const things = [];
306
+ for (let after = null; ;) {
307
+ const page = await send('/v1/principals/me/relations?direction=from&limit=200' + (after ? '&after=' + encodeURIComponent(after) : ''), undefined, { method: 'GET', accept: () => true });
308
+ things.push(...(page.relations ?? []).filter(line => line.resource).map(line => line.resource));
309
+ if (!(after = page.next)) return things;
310
+ }
311
+ };
303
312
  // Reading a secret this machine was handed an envelope for: its own, or one shown to it along a line.
304
313
  if (action === 'read') {
305
314
  if (!key.own) throw new Error('This machine has no key of its own here, so nothing sealed for it can be opened.');
306
315
  const own = await send('/v1/principals/me/resources?kind=secret&name=' + encodeURIComponent(call.name), undefined, { method: 'GET', accept: () => true });
307
- const resource = own.resource ?? (await send('/v1/principals/me/resources?shown=me', undefined, { method: 'GET' })).resources.find(item => item.kind === 'secret' && item.name === call.name);
316
+ const resource = own.resource ?? (await shownToMe()).find(item => item.kind === 'secret' && item.name === call.name);
308
317
  if (!resource) throw new Error('No secret named ' + JSON.stringify(call.name) + ' is kept by this machine or shown to it.');
309
318
  const kept = await send('/v1/resources/' + resource.id + '/content', undefined, { method: 'GET' });
310
319
  if (!kept.envelope) throw new Error('No envelope was made for this machine: it may read about this secret, but was not handed its key.');
@@ -344,7 +353,7 @@ async function main() {
344
353
  const handed = { environment: {}, files: [] };
345
354
  let asked = names;
346
355
  if (key.own && names.some(item => typeof item.name === 'string')) {
347
- const shown = owner ? (await send('/v1/principals/me/resources?shown=me', undefined, { method: 'GET', accept: () => true })).resources ?? [] : [];
356
+ const shown = owner ? await shownToMe() : [];
348
357
  asked = [];
349
358
  for (const item of names) {
350
359
  let resource = null;