@ccmsg/cli 0.9.1 → 0.11.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccmsg/cli",
3
- "version": "0.9.1",
3
+ "version": "0.11.0",
4
4
  "description": "The ccmsg daemon, CLI and agent plugins for one instance (= one config home)",
5
5
  "license": "MIT",
6
6
  "author": "kawaz",
package/src/auth/admin.ts CHANGED
@@ -22,23 +22,49 @@ export type AdminRequest =
22
22
  readonly sub?: Subject;
23
23
  }
24
24
  | { readonly admin: "passkey_list"; readonly request_id: string }
25
- | { readonly admin: "passkey_remove"; readonly request_id: string; readonly sub: Subject };
25
+ | { readonly admin: "passkey_remove"; readonly request_id: string; readonly sub: Subject }
26
+ /** Stop being a peer of this endpoint, now rather than at the next start.
27
+ *
28
+ * Here with the passkey requests because it is the same kind of thing: what
29
+ * this host is prepared to talk to, said from the machine it runs on, on the
30
+ * socket where reaching the address is the permission. `ccmsg mesh remove`
31
+ * has already taken it off the list; this is the running instance being told
32
+ * so, because a revocation that waited for a restart would leave the link it
33
+ * revoked standing. */
34
+ | { readonly admin: "mesh_forget"; readonly request_id: string; readonly endpoint: Endpoint };
35
+
36
+ const ADMIN_NAMES = ["passkey_add", "passkey_list", "passkey_remove", "mesh_forget"];
26
37
 
27
38
  /** Whether a frame is one of these, without deciding anything about it. */
28
39
  export function adminRequestOf(frame: unknown): AdminRequest | undefined {
29
40
  if (typeof frame !== "object" || frame === null) return undefined;
30
41
  const fields = frame as Record<string, unknown>;
31
- const name = fields["admin"];
32
- if (name !== "passkey_add" && name !== "passkey_list" && name !== "passkey_remove") {
33
- return undefined;
34
- }
42
+ if (!ADMIN_NAMES.includes(fields["admin"] as string)) return undefined;
35
43
  return typeof fields["request_id"] === "string" ? (frame as AdminRequest) : undefined;
36
44
  }
37
45
 
46
+ /** What an administrative request is asked of: the passkeys, and the mesh on an
47
+ * instance that has one. */
48
+ export interface Administered {
49
+ readonly auth: Auth;
50
+ readonly mesh?: { forget(peer: Endpoint): boolean };
51
+ }
52
+
38
53
  /** Run one administrative request. */
39
- export function handleAdmin(auth: Auth, request: AdminRequest): DispatchResult {
54
+ export function handleAdmin(at: Administered, request: AdminRequest): DispatchResult {
55
+ const auth = at.auth;
40
56
  try {
41
57
  switch (request.admin) {
58
+ case "mesh_forget": {
59
+ const mesh = at.mesh;
60
+ if (mesh === undefined) {
61
+ return reply(request.request_id, { endpoint: request.endpoint, dropped: false });
62
+ }
63
+ return reply(request.request_id, {
64
+ endpoint: request.endpoint,
65
+ dropped: mesh.forget(request.endpoint),
66
+ });
67
+ }
42
68
  case "passkey_add":
43
69
  return reply(
44
70
  request.request_id,