@volter/teams 0.1.11 → 0.1.13

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.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 supercode contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/teams",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
6
6
  "license": "MIT",
@@ -29,6 +29,7 @@
29
29
  "./server/viewer": "./server/viewer.mjs"
30
30
  },
31
31
  "files": [
32
+ "LICENSE-MIT",
32
33
  "*.mjs",
33
34
  "server",
34
35
  "viewer",
@@ -19,6 +19,9 @@ const CAPS = {
19
19
  folder: { control: ['files'], view: ['observe'] },
20
20
  pane: { control: ['observe', 'control'], view: ['observe'] },
21
21
  };
22
+
23
+ /** The daemon caps a surface of `kind` grants at `scope`, capped at the publication's `maxScope` (the narrower wins). */
24
+ export const surfaceCaps = (kind, scope, maxScope = 'control') => CAPS[kind]?.[scope === 'control' && maxScope === 'control' ? 'control' : 'view'] ?? null;
22
25
  const KEYS_TTL_MS = 5 * 60 * 1000;
23
26
  const SKEW_S = 30;
24
27
  // A delegated token lives at most 15 minutes (exp - iat, and exp - now). The viewer asks its page for a fresh one
@@ -16,7 +16,7 @@
16
16
  // and the caps the token names, expiring with the token; its channel closes then, or when the surface is unpublished.
17
17
  import { Channel } from '../channel.mjs';
18
18
  import { bearer } from './auth.mjs';
19
- import { delegatedAccessOf, delegatedPrincipal, looksDelegated } from './delegated.mjs';
19
+ import { delegatedAccessOf, delegatedPrincipal, looksDelegated, surfaceCaps } from './delegated.mjs';
20
20
  import { delegatedGrantIssuer, publicationFor } from './publications.mjs';
21
21
 
22
22
  const LINK_PROTOCOL = 'supercode-machine-link.v1';
@@ -196,7 +196,7 @@ async function delegatedChannel(api, teamId, machineId, token) {
196
196
  ], [
197
197
  // Delegated grants live as long as their tokens; the expired ones go as new ones come.
198
198
  { sql: "DELETE FROM machine_grants WHERE team_id=? AND issuer_id LIKE 'delegated:%' AND expires_at<=?", params: [teamId, now] },
199
- { sql: 'INSERT INTO machine_grants(team_id,id,machine_id,subject_id,caps_json,targets_json,issuer_id,created_at,expires_at) VALUES (?,?,?,?,?,?,?,?,?)', params: [teamId, id, machineId, principal, JSON.stringify(access.caps), JSON.stringify([publication.target]), issuer, now, access.expiresAt] },
199
+ { sql: 'INSERT INTO machine_grants(team_id,id,machine_id,subject_id,caps_json,targets_json,issuer_id,created_at,expires_at) VALUES (?,?,?,?,?,?,?,?,?)', params: [teamId, id, machineId, principal, JSON.stringify(surfaceCaps(access.kind, access.scope, publication.max_scope)), JSON.stringify([publication.target]), issuer, now, access.expiresAt] },
200
200
  ]);
201
201
  } catch (error) {
202
202
  if (error.code === 'not_found') return { status: 404, code: 'not_found', message: 'machine not found' };
@@ -0,0 +1,6 @@
1
+ // Schema migration 007 (SQLite DDL), applied in order by store-core migrate().
2
+ export default `-- Schema 7: a publication's widest scope. A workplace's token picks view or control, but the custodian
3
+ -- decides what a surface offers: a publication capped at view opens as view whatever the token says, so a
4
+ -- workplace key that is misused can at most watch it. Publications made before this offered control.
5
+ ALTER TABLE machine_publications ADD COLUMN max_scope TEXT NOT NULL DEFAULT 'control' CHECK(max_scope IN ('view','control'));
6
+ `;
@@ -5,4 +5,5 @@ import m003 from './003.mjs';
5
5
  import m004 from './004.mjs';
6
6
  import m005 from './005.mjs';
7
7
  import m006 from './006.mjs';
8
- export const MIGRATIONS = [m001, m002, m003, m004, m005, m006];
8
+ import m007 from './007.mjs';
9
+ export const MIGRATIONS = [m001, m002, m003, m004, m005, m006, m007];
@@ -21,7 +21,7 @@ export function publishableTarget(kind, target) {
21
21
  }
22
22
 
23
23
  const originOf = (text) => { try { const url = new URL(text); return (url.protocol === 'https:' || url.protocol === 'http:') && url.origin === text ? text : null; } catch { return null; } };
24
- const json = (row) => ({ id: row.id, machine_id: row.machine_id, kind: row.kind, target: row.target, workplace: row.workplace, room: row.room, surface_key: row.surface_key, publisher_id: row.publisher_id, created_at: row.created_at });
24
+ const json = (row) => ({ id: row.id, machine_id: row.machine_id, kind: row.kind, target: row.target, workplace: row.workplace, room: row.room, surface_key: row.surface_key, publisher_id: row.publisher_id, max_scope: row.max_scope ?? 'control', created_at: row.created_at });
25
25
  /** The grant issuer a delegated grant minted on one publication carries, so unpublishing finds exactly those grants. */
26
26
  export const delegatedGrantIssuer = (issuer, publicationId) => `delegated:${new URL(issuer).host}/${publicationId}`;
27
27
 
@@ -72,7 +72,10 @@ export async function publicationRoute({ api, req, res, auth, machineId, publica
72
72
  }
73
73
  if (req.method === 'POST' && !publicationId) {
74
74
  if (!custodian) fail(403, 'forbidden', "only the machine's custodian publishes its panes and folders");
75
- const body = await parseJson(req); exact(body, ['kind', 'target', 'workplace', 'room', 'surface_key']);
75
+ const body = await parseJson(req); exact(body, ['kind', 'target', 'workplace', 'room', 'surface_key', 'max_scope']);
76
+ // The widest a workplace's token can open the surface: control (watch and drive) unless the custodian caps it at view.
77
+ const maxScope = body.max_scope ?? 'control';
78
+ if (maxScope !== 'view' && maxScope !== 'control') fail(400, 'invalid_request', 'max_scope must be view or control');
76
79
  if (body.kind !== 'pane' && body.kind !== 'folder') fail(400, 'invalid_request', 'kind must be pane or folder');
77
80
  if (!publishableTarget(body.kind, body.target)) fail(400, 'invalid_request', body.kind === 'pane' ? 'target must be one pane, pane:<key> (no wildcard)' : 'target must be one absolute folder, root:/path (not root:/, no wildcard, normalized)');
78
81
  const workplace = typeof body.workplace === 'string' ? originOf(body.workplace) : null;
@@ -82,13 +85,14 @@ export async function publicationRoute({ api, req, res, auth, machineId, publica
82
85
  if (body.surface_key !== undefined && (typeof body.surface_key !== 'string' || !body.surface_key || body.surface_key.length > 256)) fail(400, 'invalid_request', 'surface_key must be a non-empty string');
83
86
  const existing = await api.store.one('SELECT * FROM machine_publications WHERE team_id=? AND machine_id=? AND target=? AND workplace=? AND room=?', [auth.team_id, machineId, body.target, workplace, body.room]);
84
87
  // Publishing the same surface again answers the record already there.
85
- if (existing && existing.kind === body.kind) return send(res, 200, result(api, auth, json(existing)), requestId);
88
+ if (existing && existing.kind === body.kind && (existing.max_scope ?? 'control') === maxScope) return send(res, 200, result(api, auth, json(existing)), requestId);
89
+ if (existing && existing.kind === body.kind) fail(409, 'conflict', `that surface is already published with max scope ${existing.max_scope}; unpublish it first`);
86
90
  if (existing) fail(409, 'conflict', 'that target is already published as another kind');
87
91
  const now = api.clock.nowMs(), id = api.ids.next('publication');
88
- const row = { id, machine_id: machineId, kind: body.kind, target: body.target, workplace, room: body.room, surface_key: body.surface_key ?? null, publisher_id: auth.principal_id, created_at: now };
92
+ const row = { id, machine_id: machineId, kind: body.kind, target: body.target, workplace, room: body.room, surface_key: body.surface_key ?? null, publisher_id: auth.principal_id, max_scope: maxScope, created_at: now };
89
93
  const response = result(api, auth, json(row));
90
94
  await guardedMutation(api, res, auth, [{ sql: 'SELECT 1 ok FROM machines WHERE team_id=? AND id=? AND custodian_id=? AND revoked_at IS NULL', params: [auth.team_id, machineId, auth.principal_id], code: 'not_found', status: 404, message: 'machine not found' }], [
91
- { sql: 'INSERT INTO machine_publications(team_id,id,machine_id,kind,target,workplace,room,surface_key,publisher_id,created_at) VALUES (?,?,?,?,?,?,?,?,?,?)', params: [auth.team_id, id, machineId, row.kind, row.target, row.workplace, row.room, row.surface_key, row.publisher_id, now] },
95
+ { sql: 'INSERT INTO machine_publications(team_id,id,machine_id,kind,target,workplace,room,surface_key,publisher_id,max_scope,created_at) VALUES (?,?,?,?,?,?,?,?,?,?,?)', params: [auth.team_id, id, machineId, row.kind, row.target, row.workplace, row.room, row.surface_key, row.publisher_id, maxScope, now] },
92
96
  ], { status: 201, body: response, targetId: id });
93
97
  return send(res, 201, response, requestId);
94
98
  }