@celljs/ta-gateway 4.15.0 → 4.15.2

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 (57) hide show
  1. package/esm/node/command-sandbox.d.ts +5 -2
  2. package/esm/node/command-sandbox.js +17 -4
  3. package/esm/node/docker-engine.d.ts +45 -0
  4. package/esm/node/docker-engine.js +87 -11
  5. package/esm/node/docker-sandbox.d.ts +3 -1
  6. package/esm/node/docker-sandbox.js +6 -0
  7. package/esm/node/environments.d.ts +34 -2
  8. package/esm/node/environments.js +187 -11
  9. package/esm/node/gateway-audit.d.ts +12 -0
  10. package/esm/node/gateway-audit.js +47 -0
  11. package/esm/node/gateway-cli.d.ts +2 -0
  12. package/esm/node/gateway-cli.js +1 -0
  13. package/esm/node/gateway-policy.d.ts +46 -0
  14. package/esm/node/gateway-policy.js +151 -0
  15. package/esm/node/gateway-quotas.d.ts +32 -0
  16. package/esm/node/gateway-quotas.js +104 -0
  17. package/esm/node/gateway-server.d.ts +16 -1
  18. package/esm/node/gateway-server.js +58 -6
  19. package/esm/node/gateway-service.d.ts +91 -16
  20. package/esm/node/gateway-service.js +366 -45
  21. package/esm/node/gateway-socket.d.ts +7 -1
  22. package/esm/node/gateway-socket.js +40 -1
  23. package/esm/node/gateway-usage.d.ts +37 -0
  24. package/esm/node/gateway-usage.js +137 -0
  25. package/esm/node/local-sandbox.d.ts +12 -0
  26. package/esm/node/local-sandbox.js +36 -1
  27. package/esm/node/sandbox-provider.d.ts +10 -0
  28. package/esm/node/tenant-store.d.ts +12 -1
  29. package/lib/node/command-sandbox.d.ts +5 -2
  30. package/lib/node/command-sandbox.js +17 -4
  31. package/lib/node/docker-engine.d.ts +45 -0
  32. package/lib/node/docker-engine.js +87 -11
  33. package/lib/node/docker-sandbox.d.ts +3 -1
  34. package/lib/node/docker-sandbox.js +6 -0
  35. package/lib/node/environments.d.ts +34 -2
  36. package/lib/node/environments.js +186 -10
  37. package/lib/node/gateway-audit.d.ts +13 -0
  38. package/lib/node/gateway-audit.js +51 -0
  39. package/lib/node/gateway-cli.d.ts +2 -0
  40. package/lib/node/gateway-cli.js +1 -0
  41. package/lib/node/gateway-policy.d.ts +47 -0
  42. package/lib/node/gateway-policy.js +156 -0
  43. package/lib/node/gateway-quotas.d.ts +33 -0
  44. package/lib/node/gateway-quotas.js +108 -0
  45. package/lib/node/gateway-server.d.ts +16 -1
  46. package/lib/node/gateway-server.js +58 -6
  47. package/lib/node/gateway-service.d.ts +91 -16
  48. package/lib/node/gateway-service.js +365 -44
  49. package/lib/node/gateway-socket.d.ts +7 -1
  50. package/lib/node/gateway-socket.js +40 -1
  51. package/lib/node/gateway-usage.d.ts +38 -0
  52. package/lib/node/gateway-usage.js +141 -0
  53. package/lib/node/local-sandbox.d.ts +12 -0
  54. package/lib/node/local-sandbox.js +38 -2
  55. package/lib/node/sandbox-provider.d.ts +10 -0
  56. package/lib/node/tenant-store.d.ts +12 -1
  57. package/package.json +4 -4
@@ -1,12 +1,19 @@
1
1
  import type { SignInFlow } from '@celljs/ta-host/lib/node/sign-in/sign-in-flow';
2
- import { type TaAccessInfo, type TaEnvironmentChoice, TaErrorCode, type TaGatewayInfo, type TaGatewayTenant } from '@celljs/ta-protocol';
2
+ import { type TaAccessInfo, type TaAgentActivity, type TaEnvironmentChoice, TaErrorCode, type TaGatewayConsole, type TaGatewayInfo, type TaGatewayLimits, type TaGatewayPolicy, type TaGatewayRole, type TaGatewayTenant, type TaUsageTrend } from '@celljs/ta-protocol';
3
3
  import type { Environments } from './environments.js';
4
+ import type { GatewayAudit } from './gateway-audit.js';
5
+ import { type GatewayPolicy } from './gateway-policy.js';
6
+ import type { GatewayQuotas } from './gateway-quotas.js';
7
+ import { type GatewayUsage } from './gateway-usage.js';
8
+ import type { SignInLinks } from './sign-in-links.js';
4
9
  import type { Tenant, TenantStore } from './tenant-store.js';
5
- /** Who calls: the browser signed in as `account`, with the token `token`. */
10
+ /** Who calls: the browser signed in as `account`, with the token `token`, and what that account is on the gateway. */
6
11
  export interface GatewayCaller {
7
12
  token: string;
8
13
  account: string;
9
14
  tenant: Tenant;
15
+ role: TaGatewayRole;
16
+ /** An owner or an admin. */
10
17
  admin: boolean;
11
18
  }
12
19
  export declare class GatewayCallError extends Error {
@@ -14,45 +21,113 @@ export declare class GatewayCallError extends Error {
14
21
  readonly hint: string;
15
22
  constructor(message: string, code: TaErrorCode, hint: string);
16
23
  }
24
+ /** What the console says of the gateway itself. */
25
+ export interface GatewayMeta {
26
+ links: SignInLinks;
27
+ startedAt: number;
28
+ version?: string;
29
+ publicUrl?: string;
30
+ }
31
+ /** The parts of the gateway its calls use. */
32
+ export interface GatewayParts {
33
+ flow: SignInFlow;
34
+ tenants: TenantStore;
35
+ environments: Environments;
36
+ policy: GatewayPolicy;
37
+ quotas: GatewayQuotas;
38
+ usage: GatewayUsage;
39
+ audit: GatewayAudit;
40
+ hooks: {
41
+ cutOff(): void;
42
+ reset(tenantId: string): void;
43
+ };
44
+ meta: GatewayMeta;
45
+ }
46
+ type Need = TaGatewayRole | 'anyone';
17
47
  export declare namespace GatewayServiceUtil {
48
+ const DEFAULT_LOG_LINES = 200;
49
+ const MAX_LOG_LINES = 2000;
50
+ /**
51
+ * Who may call each method: `anyone` signed in (about their own Ta, their own sign-ins), `admin` (owners too),
52
+ * `owner`. A method not here is no method. What an admin may do to another account is checked again by its role
53
+ * (GatewayService.manage).
54
+ */
55
+ const RULES: Record<string, Record<string, Need>>;
56
+ /** What an administrator did or looked at of others: kept in the audit. */
57
+ const AUDITED: Set<string>;
58
+ function need(service: string, name: string): Need | undefined;
59
+ function allowed(role: TaGatewayRole, need: Need): boolean;
60
+ /** As many lines as asked, within bounds. */
61
+ function lines(value: unknown): number;
62
+ /** Days of a trend, 1 to 31. */
63
+ function days(value: unknown): number;
18
64
  /** The services the gateway answers itself, not the Ta of the tenant. */
19
65
  const SERVICES: string[];
20
66
  function owns(method: unknown): method is string;
21
67
  /** Whether the text of a message may be a call of {@link SERVICES}: those that are not are not parsed. */
22
68
  function mayOwn(text: string): boolean;
69
+ /** The calls that send the agents a message, which the limit of messages a minute counts. */
70
+ const PROMPTS: string[];
71
+ function mayPrompt(text: string): boolean;
23
72
  /** The error of a JSON-RPC answer, as ta serve sends an ApplicationError: the client reads its code and hint. */
24
73
  function error(id: unknown, message: string, code: TaErrorCode, hint: string): string;
25
74
  function result(id: unknown, result: unknown): string;
75
+ function forbidden(message: string, hint: string): GatewayCallError;
26
76
  function choice(value: unknown, own: boolean, providers: string[]): TaEnvironmentChoice | undefined;
77
+ /** What the audit says of the arguments of a call: its numbers, flags and roles, never more. */
78
+ function detail(method: string, params: unknown[]): string | undefined;
27
79
  }
28
80
  /**
29
81
  * The calls the gateway answers on the WebSocket of a browser: TaGatewayServer, and TaAccessServer, whose
30
- * accounts are those that may have a tenant here; administrators manage them, everyone else sees their own
31
- * sign-ins.
82
+ * accounts are those that may have a tenant here. Each method needs a role (GatewayServiceUtil.RULES); what an
83
+ * admin does to another account needs a role above it; what administrators do is kept in the audit.
32
84
  */
33
85
  export declare class GatewayService {
34
86
  protected readonly flow: SignInFlow;
35
87
  protected readonly tenants: TenantStore;
36
88
  protected readonly environments: Environments;
37
- protected readonly hooks: {
38
- cutOff(): void;
39
- reset(tenantId: string): void;
40
- };
41
- constructor(flow: SignInFlow, tenants: TenantStore, environments: Environments, hooks: {
42
- cutOff(): void;
43
- reset(tenantId: string): void;
44
- });
89
+ protected readonly policy: GatewayPolicy;
90
+ protected readonly quotas: GatewayQuotas;
91
+ protected readonly usage: GatewayUsage;
92
+ protected readonly audit: GatewayAudit;
93
+ protected readonly hooks: GatewayParts['hooks'];
94
+ protected readonly meta: GatewayMeta;
95
+ constructor(parts: GatewayParts);
45
96
  call(caller: GatewayCaller, method: string, params: unknown[]): Promise<unknown>;
97
+ protected handle(caller: GatewayCaller, service: string, name: string, params: unknown[]): Promise<unknown>;
98
+ protected record(caller: GatewayCaller, action: string, params: unknown[]): void;
46
99
  info(caller: GatewayCaller): TaGatewayInfo;
47
- protected ownAllowed(): boolean;
48
100
  protected setEnvironment(caller: GatewayCaller, value: unknown): Promise<TaGatewayInfo>;
49
101
  protected restart(caller: GatewayCaller): Promise<TaGatewayInfo>;
50
- protected listTenants(caller: GatewayCaller): Promise<TaGatewayTenant[]>;
102
+ protected tenantInfo(tenant: Tenant): TaGatewayTenant;
103
+ /** The tenants with what their sandboxes take and their agents do, read together: a slow one holds the console a second, not a second each. */
104
+ protected console(caller: GatewayCaller): Promise<TaGatewayConsole>;
105
+ protected policyView(): TaGatewayPolicy;
106
+ protected tenant(id: unknown): Tenant;
107
+ /** A tenant the caller may change: an owner any; an admin a member's only, not their own, nor another admin's or an owner's. */
108
+ protected manage(caller: GatewayCaller, id: unknown): Tenant;
109
+ protected startTenant(caller: GatewayCaller, id: unknown): Promise<void>;
51
110
  protected stopTenant(caller: GatewayCaller, id: unknown): Promise<void>;
111
+ protected restartTenant(caller: GatewayCaller, id: unknown): Promise<void>;
112
+ /** What its sandbox wrote, its secrets hidden: tokens and keys printed by what ran there do not reach the page. */
113
+ protected logs(id: unknown, lines: unknown): Promise<string>;
114
+ protected activity(id: unknown, sessionId: unknown): Promise<TaAgentActivity[]>;
115
+ protected trend(daysValue: unknown, id: unknown): Promise<TaUsageTrend>;
116
+ protected limits(value: unknown, nullable: boolean): TaGatewayLimits;
117
+ protected setTenantLimits(caller: GatewayCaller, id: unknown, value: unknown): void;
118
+ protected grantMinutes(caller: GatewayCaller, id: unknown, minutes: unknown): void;
119
+ protected setSuspended(caller: GatewayCaller, id: unknown, suspended: unknown): Promise<void>;
120
+ protected setDefaultLimits(value: unknown): TaGatewayPolicy;
121
+ protected setRole(caller: GatewayCaller, account: unknown, role: unknown): TaGatewayPolicy;
52
122
  protected access(caller: GatewayCaller): TaAccessInfo;
53
123
  protected allow(account: unknown, name: unknown): void;
54
124
  /** The browsers of the account are cut off, and what reaches its Ta otherwise (paired phones) goes with its sandbox. */
55
- protected disallow(account: string): Promise<void>;
125
+ protected disallow(caller: GatewayCaller, account: string): Promise<void>;
56
126
  protected signOut(caller: GatewayCaller, id: string): Promise<void>;
57
- protected admin<T>(caller: GatewayCaller, action: () => T | Promise<T>): Promise<T>;
127
+ /**
128
+ * A link that signs in once as an account that has never been here: one that has a tenant, or is an owner's or an
129
+ * admin's, would let whoever makes the link into another's Ta. `ta gateway link`, where the gateway runs, may.
130
+ */
131
+ protected signInLink(account: unknown, name: unknown): string;
58
132
  }
133
+ export {};