@scp-dev/hub 0.1.0 → 0.1.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Envelope, RelayCore, CoreOptions, EndpointRow, PolicySubject, ScopeSubject, ScopeNode, ScopeDirection, Admission, MessageRow, EndpointView, ScopeCap, ScopeEntry, Claim, SendParams, SendResult, EndpointKind, Presence, StatusState, Sql, CrossAccountLink, XDelivered, XListed, XRelease } from '@scp-dev/core';
1
+ import { Envelope, RelayCore, CoreOptions, EndpointRow, PolicySubject, ScopeSubject, ScopeNode, ScopeDirection, Admission, MessageRow, EndpointView, ScopeCap, ScopeEntry, Claim, SendParams, SendResult, EndpointKind, Presence, StatusState, Sql, CrossAccountLink, XDelivered, XListed, ActivityRow, XRelease } from '@scp-dev/core';
2
2
 
3
3
  type RelayAuth = Envelope["from"]["auth"];
4
4
  /** a machine name: one relay host of an account */
@@ -397,6 +397,15 @@ interface HubConn {
397
397
  /** whether a human client said a terminal is attached */
398
398
  tty?: boolean;
399
399
  }
400
+ /** a bound machine, or a revoked token's name kept as a tombstone */
401
+ interface MachineRow {
402
+ name: string;
403
+ kind: string;
404
+ online: boolean;
405
+ bridge: boolean;
406
+ created_at: string | null;
407
+ last_seen: string | null;
408
+ }
400
409
  interface HubSocket {
401
410
  conn: HubConn;
402
411
  send(text: string): void;
@@ -574,6 +583,12 @@ declare class RelayHub {
574
583
  /** machines a live connection holds */
575
584
  private liveMachines;
576
585
  /** bindings, then names a revoke left behind (kind `revoked`) */
586
+ /** a read-only view of the account for a dashboard: its machines, listed endpoints and latest activity */
587
+ overview(activity?: number): {
588
+ machines: MachineRow[];
589
+ endpoints: EndpointView[];
590
+ activity: ActivityRow[];
591
+ };
577
592
  private machineList;
578
593
  /** only the token the machine is bound to, a full login of the member who bound it, or an admin may release it (or a revoked token's name) */
579
594
  private releaseMachine;
@@ -599,4 +614,4 @@ declare class RelayHub {
599
614
  xnotice(endpoint: string, text: string): void;
600
615
  }
601
616
 
602
- export { type Delivery, FederatedCore, type FederatedOptions, HUB_LIMITS, type HubAuth, type HubConn, type HubDeps, type HubGrant, type HubLimits, type HubRole, type HubSocket, MACHINE_NAME, type MirrorCaps, type MirrorChange, type MirrorRules, type MirrorScope, type MirrorView, type RelayAuth, RelayHub, type RemoteView, type XEndpoint };
617
+ export { type Delivery, FederatedCore, type FederatedOptions, HUB_LIMITS, type HubAuth, type HubConn, type HubDeps, type HubGrant, type HubLimits, type HubRole, type HubSocket, MACHINE_NAME, type MachineRow, type MirrorCaps, type MirrorChange, type MirrorRules, type MirrorScope, type MirrorView, type RelayAuth, RelayHub, type RemoteView, type XEndpoint };
package/dist/index.js CHANGED
@@ -2721,6 +2721,11 @@ var RelayHub = class _RelayHub {
2721
2721
  return live;
2722
2722
  }
2723
2723
  /** bindings, then names a revoke left behind (kind `revoked`) */
2724
+ /** a read-only view of the account for a dashboard: its machines, listed endpoints and latest activity */
2725
+ overview(activity = 20) {
2726
+ const { endpoints, activity: rows } = this.relay.snapshot({ activity });
2727
+ return { machines: this.machineList(), endpoints, activity: rows };
2728
+ }
2724
2729
  machineList() {
2725
2730
  const sockets = this.deps.sockets().filter((s) => !this.gone.has(s.conn.id));
2726
2731
  const bound = this.deps.sql.all(`SELECT name, kind, created_at, last_seen FROM machines ORDER BY name`).map((row) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scp-dev/hub",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Swarm Communication Protocol federation and account hub: mirrored endpoints across machines, bridges, direct clients and cross-account delivery.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://scp.dev",
@@ -29,7 +29,7 @@
29
29
  "typecheck": "tsc -p ."
30
30
  },
31
31
  "dependencies": {
32
- "@scp-dev/core": "0.1.0"
32
+ "@scp-dev/core": "0.1.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "tsup": "^8.5.1"
package/src/hub.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ type ActivityRow,
2
3
  allowlisted,
3
4
  CAPABILITIES,
4
5
  CLI_NAME,
@@ -81,6 +82,16 @@ export interface HubConn {
81
82
  tty?: boolean
82
83
  }
83
84
 
85
+ /** a bound machine, or a revoked token's name kept as a tombstone */
86
+ export interface MachineRow {
87
+ name: string
88
+ kind: string
89
+ online: boolean
90
+ bridge: boolean
91
+ created_at: string | null
92
+ last_seen: string | null
93
+ }
94
+
84
95
  export interface HubSocket {
85
96
  conn: HubConn
86
97
  send(text: string): void
@@ -1442,7 +1453,13 @@ export class RelayHub {
1442
1453
  }
1443
1454
 
1444
1455
  /** bindings, then names a revoke left behind (kind `revoked`) */
1445
- private machineList(): { name: string; kind: string; online: boolean; bridge: boolean; created_at: string | null; last_seen: string | null }[] {
1456
+ /** a read-only view of the account for a dashboard: its machines, listed endpoints and latest activity */
1457
+ overview(activity = 20): { machines: MachineRow[]; endpoints: EndpointView[]; activity: ActivityRow[] } {
1458
+ const { endpoints, activity: rows } = this.relay.snapshot({ activity })
1459
+ return { machines: this.machineList(), endpoints, activity: rows }
1460
+ }
1461
+
1462
+ private machineList(): MachineRow[] {
1446
1463
  const sockets = this.deps.sockets().filter((s) => !this.gone.has(s.conn.id))
1447
1464
  const bound = this.deps.sql
1448
1465
  .all<{ name: string; kind: string; created_at: number; last_seen: number | null }>(`SELECT name, kind, created_at, last_seen FROM machines ORDER BY name`)
package/src/index.ts CHANGED
@@ -12,4 +12,15 @@ export {
12
12
  type RemoteView,
13
13
  type XEndpoint,
14
14
  } from "./federation"
15
- export { HUB_LIMITS, RelayHub, type HubAuth, type HubConn, type HubDeps, type HubGrant, type HubLimits, type HubRole, type HubSocket } from "./hub"
15
+ export {
16
+ HUB_LIMITS,
17
+ RelayHub,
18
+ type HubAuth,
19
+ type HubConn,
20
+ type HubDeps,
21
+ type HubGrant,
22
+ type HubLimits,
23
+ type HubRole,
24
+ type HubSocket,
25
+ type MachineRow,
26
+ } from "./hub"