@celljs/ta-gateway 4.15.2 → 4.17.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/README.en.md +5 -2
- package/README.md +5 -2
- package/esm/node/command-sandbox.d.ts +1 -0
- package/esm/node/command-sandbox.js +10 -1
- package/esm/node/docker-engine.d.ts +10 -1
- package/esm/node/docker-engine.js +18 -1
- package/esm/node/docker-sandbox.d.ts +13 -1
- package/esm/node/docker-sandbox.js +35 -2
- package/esm/node/egress-proxy.d.ts +98 -0
- package/esm/node/egress-proxy.js +428 -0
- package/esm/node/environments.d.ts +5 -0
- package/esm/node/environments.js +7 -3
- package/esm/node/gateway-cli.js +12 -5
- package/esm/node/gateway-exec.d.ts +19 -0
- package/esm/node/gateway-exec.js +65 -0
- package/esm/node/gateway-policy.d.ts +7 -1
- package/esm/node/gateway-policy.js +12 -2
- package/esm/node/gateway-quotas.d.ts +15 -2
- package/esm/node/gateway-quotas.js +51 -3
- package/esm/node/gateway-server.d.ts +43 -1
- package/esm/node/gateway-server.js +179 -10
- package/esm/node/gateway-service-util.d.ts +41 -0
- package/esm/node/gateway-service-util.js +178 -0
- package/esm/node/gateway-service.d.ts +13 -41
- package/esm/node/gateway-service.js +41 -176
- package/esm/node/gateway-socket.d.ts +1 -1
- package/esm/node/gateway-socket.js +1 -1
- package/esm/node/index.d.ts +4 -0
- package/esm/node/index.js +4 -0
- package/esm/node/kubernetes-api.d.ts +35 -0
- package/esm/node/kubernetes-api.js +115 -0
- package/esm/node/kubernetes-sandbox.d.ts +198 -0
- package/esm/node/kubernetes-sandbox.js +279 -0
- package/esm/node/local-sandbox.d.ts +1 -0
- package/esm/node/local-sandbox.js +2 -1
- package/esm/node/model-proxy.d.ts +105 -0
- package/esm/node/model-proxy.js +435 -0
- package/esm/node/sandbox-provider.d.ts +17 -0
- package/esm/node/sandbox-provider.js +2 -1
- package/esm/node/tenant-store.d.ts +22 -0
- package/esm/node/tenant-store.js +25 -0
- package/lib/node/command-sandbox.d.ts +1 -0
- package/lib/node/command-sandbox.js +10 -1
- package/lib/node/docker-engine.d.ts +10 -1
- package/lib/node/docker-engine.js +18 -1
- package/lib/node/docker-sandbox.d.ts +13 -1
- package/lib/node/docker-sandbox.js +35 -2
- package/lib/node/egress-proxy.d.ts +99 -0
- package/lib/node/egress-proxy.js +433 -0
- package/lib/node/environments.d.ts +5 -0
- package/lib/node/environments.js +7 -3
- package/lib/node/gateway-cli.js +12 -5
- package/lib/node/gateway-exec.d.ts +20 -0
- package/lib/node/gateway-exec.js +69 -0
- package/lib/node/gateway-policy.d.ts +7 -1
- package/lib/node/gateway-policy.js +12 -2
- package/lib/node/gateway-quotas.d.ts +15 -2
- package/lib/node/gateway-quotas.js +51 -3
- package/lib/node/gateway-server.d.ts +43 -1
- package/lib/node/gateway-server.js +177 -8
- package/lib/node/gateway-service-util.d.ts +42 -0
- package/lib/node/gateway-service-util.js +182 -0
- package/lib/node/gateway-service.d.ts +13 -41
- package/lib/node/gateway-service.js +63 -199
- package/lib/node/gateway-socket.d.ts +1 -1
- package/lib/node/gateway-socket.js +10 -10
- package/lib/node/index.d.ts +4 -0
- package/lib/node/index.js +4 -0
- package/lib/node/kubernetes-api.d.ts +36 -0
- package/lib/node/kubernetes-api.js +120 -0
- package/lib/node/kubernetes-sandbox.d.ts +199 -0
- package/lib/node/kubernetes-sandbox.js +283 -0
- package/lib/node/local-sandbox.d.ts +1 -0
- package/lib/node/local-sandbox.js +2 -1
- package/lib/node/model-proxy.d.ts +106 -0
- package/lib/node/model-proxy.js +440 -0
- package/lib/node/sandbox-provider.d.ts +17 -0
- package/lib/node/sandbox-provider.js +2 -1
- package/lib/node/tenant-store.d.ts +22 -0
- package/lib/node/tenant-store.js +25 -0
- package/package.json +4 -4
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GatewayServiceUtil = exports.GatewayCallError = void 0;
|
|
4
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
5
|
+
const gateway_policy_1 = require("./gateway-policy");
|
|
6
|
+
const ta_sandbox_1 = require("./ta-sandbox");
|
|
7
|
+
class GatewayCallError extends Error {
|
|
8
|
+
constructor(message, code, hint) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.hint = hint;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.GatewayCallError = GatewayCallError;
|
|
15
|
+
var GatewayServiceUtil;
|
|
16
|
+
(function (GatewayServiceUtil) {
|
|
17
|
+
GatewayServiceUtil.DEFAULT_LOG_LINES = 200;
|
|
18
|
+
GatewayServiceUtil.MAX_LOG_LINES = 2000;
|
|
19
|
+
/**
|
|
20
|
+
* Who may call each method: `anyone` signed in (about their own Ta, their own sign-ins), `admin` (owners too),
|
|
21
|
+
* `owner`. A method not here is no method. What an admin may do to another account is checked again by its role
|
|
22
|
+
* (GatewayService.manage).
|
|
23
|
+
*/
|
|
24
|
+
GatewayServiceUtil.RULES = {
|
|
25
|
+
TaGatewayServer: {
|
|
26
|
+
getGateway: 'anyone',
|
|
27
|
+
setEnvironment: 'anyone',
|
|
28
|
+
restartEnvironment: 'anyone',
|
|
29
|
+
listTenants: 'admin',
|
|
30
|
+
getConsole: 'admin',
|
|
31
|
+
getTenantAgents: 'admin',
|
|
32
|
+
getAgentActivity: 'admin',
|
|
33
|
+
getTenantLogs: 'admin',
|
|
34
|
+
getUsageTrend: 'admin',
|
|
35
|
+
getPolicy: 'admin',
|
|
36
|
+
getAudit: 'admin',
|
|
37
|
+
startTenant: 'admin',
|
|
38
|
+
stopTenant: 'admin',
|
|
39
|
+
restartTenant: 'admin',
|
|
40
|
+
createSignInLink: 'admin',
|
|
41
|
+
setTenantLimits: 'admin',
|
|
42
|
+
grantMinutes: 'admin',
|
|
43
|
+
setSuspended: 'admin',
|
|
44
|
+
setDefaultLimits: 'owner',
|
|
45
|
+
setRole: 'owner',
|
|
46
|
+
setEgressHosts: 'owner',
|
|
47
|
+
createAccessToken: 'anyone',
|
|
48
|
+
},
|
|
49
|
+
TaAccessServer: {
|
|
50
|
+
getAccess: 'anyone',
|
|
51
|
+
signOut: 'anyone',
|
|
52
|
+
bindUrl: 'admin',
|
|
53
|
+
allow: 'admin',
|
|
54
|
+
dismiss: 'admin',
|
|
55
|
+
disallow: 'admin',
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
/** What an administrator did or looked at of others: kept in the audit. */
|
|
59
|
+
GatewayServiceUtil.AUDITED = new Set([
|
|
60
|
+
'startTenant',
|
|
61
|
+
'stopTenant',
|
|
62
|
+
'restartTenant',
|
|
63
|
+
'getTenantLogs',
|
|
64
|
+
'getAgentActivity',
|
|
65
|
+
'createSignInLink',
|
|
66
|
+
'setTenantLimits',
|
|
67
|
+
'grantMinutes',
|
|
68
|
+
'setSuspended',
|
|
69
|
+
'setDefaultLimits',
|
|
70
|
+
'setRole',
|
|
71
|
+
'setEgressHosts',
|
|
72
|
+
'allow',
|
|
73
|
+
'dismiss',
|
|
74
|
+
'disallow',
|
|
75
|
+
]);
|
|
76
|
+
/** By name, own keys only: a method such as `toString` is no rule. */
|
|
77
|
+
const BY_SERVICE = new Map(Object.entries(GatewayServiceUtil.RULES).map(([service, rules]) => [service, new Map(Object.entries(rules))]));
|
|
78
|
+
function need(service, name) {
|
|
79
|
+
var _a;
|
|
80
|
+
return (_a = BY_SERVICE.get(service)) === null || _a === void 0 ? void 0 : _a.get(name);
|
|
81
|
+
}
|
|
82
|
+
GatewayServiceUtil.need = need;
|
|
83
|
+
function allowed(role, need) {
|
|
84
|
+
return need === 'anyone' || gateway_policy_1.GatewayPolicyUtil.rank(role) >= gateway_policy_1.GatewayPolicyUtil.rank(need);
|
|
85
|
+
}
|
|
86
|
+
GatewayServiceUtil.allowed = allowed;
|
|
87
|
+
/** As many lines as asked, within bounds. */
|
|
88
|
+
function lines(value) {
|
|
89
|
+
const count = Math.floor(Number(value !== null && value !== void 0 ? value : GatewayServiceUtil.DEFAULT_LOG_LINES));
|
|
90
|
+
return Number.isFinite(count) && count > 0 ? Math.min(count, GatewayServiceUtil.MAX_LOG_LINES) : GatewayServiceUtil.DEFAULT_LOG_LINES;
|
|
91
|
+
}
|
|
92
|
+
GatewayServiceUtil.lines = lines;
|
|
93
|
+
/** Days of a trend, 1 to 31. */
|
|
94
|
+
function days(value) {
|
|
95
|
+
const count = Math.floor(Number(value !== null && value !== void 0 ? value : 7));
|
|
96
|
+
return Number.isFinite(count) ? Math.min(31, Math.max(1, count)) : 7;
|
|
97
|
+
}
|
|
98
|
+
GatewayServiceUtil.days = days;
|
|
99
|
+
/** The services the gateway answers itself, not the Ta of the tenant. */
|
|
100
|
+
GatewayServiceUtil.SERVICES = Object.keys(GatewayServiceUtil.RULES);
|
|
101
|
+
function owns(method) {
|
|
102
|
+
return typeof method === 'string' && GatewayServiceUtil.SERVICES.includes(method.split('/')[0]);
|
|
103
|
+
}
|
|
104
|
+
GatewayServiceUtil.owns = owns;
|
|
105
|
+
/** Whether the text of a message may be a call of {@link SERVICES}: those that are not are not parsed. */
|
|
106
|
+
function mayOwn(text) {
|
|
107
|
+
return GatewayServiceUtil.SERVICES.some(service => text.includes(`"${service}/`));
|
|
108
|
+
}
|
|
109
|
+
GatewayServiceUtil.mayOwn = mayOwn;
|
|
110
|
+
/** The calls that send the agents a message, which the limit of messages a minute counts. */
|
|
111
|
+
GatewayServiceUtil.PROMPTS = ['TaServer/prompt', 'TaServer/steer', 'TaServer/followUp'];
|
|
112
|
+
function mayPrompt(text) {
|
|
113
|
+
return GatewayServiceUtil.PROMPTS.some(method => text.includes(`"${method}"`));
|
|
114
|
+
}
|
|
115
|
+
GatewayServiceUtil.mayPrompt = mayPrompt;
|
|
116
|
+
/** The error of a JSON-RPC answer, as ta serve sends an ApplicationError: the client reads its code and hint. */
|
|
117
|
+
function error(id, message, code, hint) {
|
|
118
|
+
return JSON.stringify({ jsonrpc: '2.0', id, error: { code: ta_protocol_1.TA_RPC_ERROR_CODE, message, data: { kind: 'application', data: { code, hint } } } });
|
|
119
|
+
}
|
|
120
|
+
GatewayServiceUtil.error = error;
|
|
121
|
+
function result(id, result) {
|
|
122
|
+
return JSON.stringify({ jsonrpc: '2.0', id, result: result !== null && result !== void 0 ? result : null });
|
|
123
|
+
}
|
|
124
|
+
GatewayServiceUtil.result = result;
|
|
125
|
+
function invalid(message, hint) {
|
|
126
|
+
return new GatewayCallError(message, ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, hint);
|
|
127
|
+
}
|
|
128
|
+
function forbidden(message, hint) {
|
|
129
|
+
return new GatewayCallError(message, ta_protocol_1.TaErrorCode.FORBIDDEN, hint);
|
|
130
|
+
}
|
|
131
|
+
GatewayServiceUtil.forbidden = forbidden;
|
|
132
|
+
function choice(value, own, providers) {
|
|
133
|
+
var _a;
|
|
134
|
+
const given = (value !== null && value !== void 0 ? value : {});
|
|
135
|
+
if (typeof given.provider === 'string') {
|
|
136
|
+
if (!providers.includes(given.provider)) {
|
|
137
|
+
throw invalid(`The gateway has no provider ${given.provider} for you.`, 'Pick one of the options of getGateway.');
|
|
138
|
+
}
|
|
139
|
+
return { provider: given.provider };
|
|
140
|
+
}
|
|
141
|
+
if (given.type === 'ta') {
|
|
142
|
+
if (!own) {
|
|
143
|
+
throw invalid('This gateway runs your Ta in its own sandboxes only.', 'Pick one of the options of getGateway.');
|
|
144
|
+
}
|
|
145
|
+
let url;
|
|
146
|
+
try {
|
|
147
|
+
url = ta_sandbox_1.TaSandboxUtil.url(String((_a = given.url) !== null && _a !== void 0 ? _a : ''));
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
throw invalid(error.message, 'Write the address its Ta service is reached at, such as https://ta.example.com.');
|
|
151
|
+
}
|
|
152
|
+
if (typeof given.token !== 'string' || !given.token.trim()) {
|
|
153
|
+
throw invalid('A Ta service of your own is reached with its access token.', 'Copy it from ~/.ta/agent/serve.json there, or the link ta serve printed.');
|
|
154
|
+
}
|
|
155
|
+
return { type: 'ta', url, token: given.token.trim(), name: typeof given.name === 'string' && given.name.trim() ? given.name.trim() : undefined };
|
|
156
|
+
}
|
|
157
|
+
throw invalid('No environment was named.', 'Pass { provider } or { type: "ta", url, token }.');
|
|
158
|
+
}
|
|
159
|
+
GatewayServiceUtil.choice = choice;
|
|
160
|
+
/** What the audit says of the arguments of a call: its numbers, flags and roles, never more. */
|
|
161
|
+
function detail(method, params) {
|
|
162
|
+
const [, second] = params;
|
|
163
|
+
switch (method) {
|
|
164
|
+
case 'setTenantLimits':
|
|
165
|
+
case 'setDefaultLimits':
|
|
166
|
+
return JSON.stringify(method === 'setDefaultLimits' ? params[0] : second);
|
|
167
|
+
case 'grantMinutes':
|
|
168
|
+
case 'getTenantLogs':
|
|
169
|
+
return String(second !== null && second !== void 0 ? second : '');
|
|
170
|
+
case 'setSuspended':
|
|
171
|
+
return second ? 'suspended' : 'let go';
|
|
172
|
+
case 'setRole':
|
|
173
|
+
return String(second);
|
|
174
|
+
case 'setEgressHosts':
|
|
175
|
+
return Array.isArray(params[0]) ? params[0].join(', ') || 'any public host' : undefined;
|
|
176
|
+
default:
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
GatewayServiceUtil.detail = detail;
|
|
181
|
+
})(GatewayServiceUtil || (exports.GatewayServiceUtil = GatewayServiceUtil = {}));
|
|
182
|
+
//# sourceMappingURL=gateway-service-util.js.map
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { SignInFlow } from '@celljs/ta-host/lib/node/sign-in/sign-in-flow';
|
|
2
|
-
import { type TaAccessInfo, type TaAgentActivity, type
|
|
2
|
+
import { type TaAccessInfo, type TaAgentActivity, type TaGatewayConsole, type TaGatewayInfo, type TaGatewayLimits, type TaGatewayPolicy, type TaGatewayRole, type TaGatewayTenant, type TaUsageTrend } from '@celljs/ta-protocol';
|
|
3
|
+
import { type EgressProxy } from './egress-proxy';
|
|
3
4
|
import type { Environments } from './environments';
|
|
4
5
|
import type { GatewayAudit } from './gateway-audit';
|
|
5
6
|
import { type GatewayPolicy } from './gateway-policy';
|
|
6
7
|
import type { GatewayQuotas } from './gateway-quotas';
|
|
7
8
|
import { type GatewayUsage } from './gateway-usage';
|
|
9
|
+
import { type ModelProxy } from './model-proxy';
|
|
8
10
|
import type { SignInLinks } from './sign-in-links';
|
|
9
11
|
import type { Tenant, TenantStore } from './tenant-store';
|
|
10
12
|
/** Who calls: the browser signed in as `account`, with the token `token`, and what that account is on the gateway. */
|
|
@@ -16,11 +18,6 @@ export interface GatewayCaller {
|
|
|
16
18
|
/** An owner or an admin. */
|
|
17
19
|
admin: boolean;
|
|
18
20
|
}
|
|
19
|
-
export declare class GatewayCallError extends Error {
|
|
20
|
-
readonly code: TaErrorCode;
|
|
21
|
-
readonly hint: string;
|
|
22
|
-
constructor(message: string, code: TaErrorCode, hint: string);
|
|
23
|
-
}
|
|
24
21
|
/** What the console says of the gateway itself. */
|
|
25
22
|
export interface GatewayMeta {
|
|
26
23
|
links: SignInLinks;
|
|
@@ -42,40 +39,8 @@ export interface GatewayParts {
|
|
|
42
39
|
reset(tenantId: string): void;
|
|
43
40
|
};
|
|
44
41
|
meta: GatewayMeta;
|
|
45
|
-
|
|
46
|
-
|
|
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;
|
|
64
|
-
/** The services the gateway answers itself, not the Ta of the tenant. */
|
|
65
|
-
const SERVICES: string[];
|
|
66
|
-
function owns(method: unknown): method is string;
|
|
67
|
-
/** Whether the text of a message may be a call of {@link SERVICES}: those that are not are not parsed. */
|
|
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;
|
|
72
|
-
/** The error of a JSON-RPC answer, as ta serve sends an ApplicationError: the client reads its code and hint. */
|
|
73
|
-
function error(id: unknown, message: string, code: TaErrorCode, hint: string): string;
|
|
74
|
-
function result(id: unknown, result: unknown): string;
|
|
75
|
-
function forbidden(message: string, hint: string): GatewayCallError;
|
|
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;
|
|
42
|
+
models?: ModelProxy;
|
|
43
|
+
egress?: EgressProxy;
|
|
79
44
|
}
|
|
80
45
|
/**
|
|
81
46
|
* The calls the gateway answers on the WebSocket of a browser: TaGatewayServer, and TaAccessServer, whose
|
|
@@ -92,6 +57,8 @@ export declare class GatewayService {
|
|
|
92
57
|
protected readonly audit: GatewayAudit;
|
|
93
58
|
protected readonly hooks: GatewayParts['hooks'];
|
|
94
59
|
protected readonly meta: GatewayMeta;
|
|
60
|
+
protected readonly models?: ModelProxy;
|
|
61
|
+
protected readonly egress?: EgressProxy;
|
|
95
62
|
constructor(parts: GatewayParts);
|
|
96
63
|
call(caller: GatewayCaller, method: string, params: unknown[]): Promise<unknown>;
|
|
97
64
|
protected handle(caller: GatewayCaller, service: string, name: string, params: unknown[]): Promise<unknown>;
|
|
@@ -103,6 +70,7 @@ export declare class GatewayService {
|
|
|
103
70
|
/** 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
71
|
protected console(caller: GatewayCaller): Promise<TaGatewayConsole>;
|
|
105
72
|
protected policyView(): TaGatewayPolicy;
|
|
73
|
+
protected setEgressHosts(value: unknown): TaGatewayPolicy;
|
|
106
74
|
protected tenant(id: unknown): Tenant;
|
|
107
75
|
/** 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
76
|
protected manage(caller: GatewayCaller, id: unknown): Tenant;
|
|
@@ -119,6 +87,11 @@ export declare class GatewayService {
|
|
|
119
87
|
protected setSuspended(caller: GatewayCaller, id: unknown, suspended: unknown): Promise<void>;
|
|
120
88
|
protected setDefaultLimits(value: unknown): TaGatewayPolicy;
|
|
121
89
|
protected setRole(caller: GatewayCaller, account: unknown, role: unknown): TaGatewayPolicy;
|
|
90
|
+
/** A sign-in of the caller's own account, named for where it is used. */
|
|
91
|
+
protected accessToken(caller: GatewayCaller, label: unknown): {
|
|
92
|
+
token: string;
|
|
93
|
+
url?: string;
|
|
94
|
+
};
|
|
122
95
|
protected access(caller: GatewayCaller): TaAccessInfo;
|
|
123
96
|
protected allow(account: unknown, name: unknown): void;
|
|
124
97
|
/** The browsers of the account are cut off, and what reaches its Ta otherwise (paired phones) goes with its sandbox. */
|
|
@@ -130,5 +103,4 @@ export declare class GatewayService {
|
|
|
130
103
|
*/
|
|
131
104
|
protected signInLink(account: unknown, name: unknown): string;
|
|
132
105
|
}
|
|
133
|
-
export {};
|
|
134
106
|
//# sourceMappingURL=gateway-service.d.ts.map
|