@celljs/ta-gateway 4.20.0 → 4.22.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/esm/node/gateway-files.d.ts +8 -1
- package/esm/node/gateway-files.js +19 -3
- package/esm/node/gateway-server.d.ts +5 -0
- package/esm/node/gateway-server.js +18 -6
- package/lib/node/gateway-files.d.ts +8 -1
- package/lib/node/gateway-files.js +19 -3
- package/lib/node/gateway-server.d.ts +5 -0
- package/lib/node/gateway-server.js +18 -6
- package/package.json +5 -5
|
@@ -7,9 +7,16 @@ export declare namespace GatewayFiles {
|
|
|
7
7
|
* path of that address, and of any address a tenant names as its own Ta service.
|
|
8
8
|
*/
|
|
9
9
|
function target(requestUrl: string, endpoint: string): URL | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* What a file read through the gateway may do, whatever the Ta of the tenant said: run its scripts in an origin of
|
|
12
|
+
* its own (as ta serve's WorkspaceFiles has it), never in the gateway's, where the console and its sign-ins are.
|
|
13
|
+
*/
|
|
14
|
+
const SANDBOX = "sandbox allow-scripts allow-forms allow-popups allow-modals allow-downloads";
|
|
10
15
|
/**
|
|
11
16
|
* The headers of an answer of the Ta of a tenant, as the browser gets them: without cookies, which a Ta
|
|
12
|
-
* service of the user's (or what runs in a sandbox) would otherwise set on the gateway's origin
|
|
17
|
+
* service of the user's (or what runs in a sandbox) would otherwise set on the gateway's origin, and sandboxed by
|
|
18
|
+
* the gateway itself, not trusting what runs there to say so. A PDF alone is left out: browsers do not show one
|
|
19
|
+
* sandboxed, and none runs scripts in the gateway's origin.
|
|
13
20
|
*/
|
|
14
21
|
function headers(headers: IncomingMessage['headers']): IncomingMessage['headers'];
|
|
15
22
|
/** Reads `target` for `request`, its answer to `response` with the headers `answered` lets through. */
|
|
@@ -17,13 +17,29 @@ export var GatewayFiles;
|
|
|
17
17
|
return target.origin === new URL(endpoint).origin && target.pathname.startsWith(`${TA_FILES_PATH}/`) ? target : undefined;
|
|
18
18
|
}
|
|
19
19
|
GatewayFiles.target = target;
|
|
20
|
+
/**
|
|
21
|
+
* What a file read through the gateway may do, whatever the Ta of the tenant said: run its scripts in an origin of
|
|
22
|
+
* its own (as ta serve's WorkspaceFiles has it), never in the gateway's, where the console and its sign-ins are.
|
|
23
|
+
*/
|
|
24
|
+
GatewayFiles.SANDBOX = 'sandbox allow-scripts allow-forms allow-popups allow-modals allow-downloads';
|
|
20
25
|
/**
|
|
21
26
|
* The headers of an answer of the Ta of a tenant, as the browser gets them: without cookies, which a Ta
|
|
22
|
-
* service of the user's (or what runs in a sandbox) would otherwise set on the gateway's origin
|
|
27
|
+
* service of the user's (or what runs in a sandbox) would otherwise set on the gateway's origin, and sandboxed by
|
|
28
|
+
* the gateway itself, not trusting what runs there to say so. A PDF alone is left out: browsers do not show one
|
|
29
|
+
* sandboxed, and none runs scripts in the gateway's origin.
|
|
23
30
|
*/
|
|
24
31
|
function headers(headers) {
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
var _a;
|
|
33
|
+
const { 'set-cookie': _cookies, 'content-security-policy': _policy, 'x-content-type-options': _sniff, ...rest } = headers;
|
|
34
|
+
const type = String((_a = rest['content-type']) !== null && _a !== void 0 ? _a : '')
|
|
35
|
+
.split(';')[0]
|
|
36
|
+
.trim()
|
|
37
|
+
.toLowerCase();
|
|
38
|
+
return {
|
|
39
|
+
...rest,
|
|
40
|
+
'x-content-type-options': 'nosniff',
|
|
41
|
+
...(type === 'application/pdf' ? {} : { 'content-security-policy': GatewayFiles.SANDBOX }),
|
|
42
|
+
};
|
|
27
43
|
}
|
|
28
44
|
GatewayFiles.headers = headers;
|
|
29
45
|
/** Reads `target` for `request`, its answer to `response` with the headers `answered` lets through. */
|
|
@@ -53,6 +53,11 @@ export declare namespace GatewayServerUtil {
|
|
|
53
53
|
* pairs, shares and opens rooms on the relay of its people, and its name.
|
|
54
54
|
*/
|
|
55
55
|
function deploymentEnv(env: Record<string, string | undefined>): Record<string, string>;
|
|
56
|
+
/**
|
|
57
|
+
* What makes a sandbox a Ta in the cloud of its account (TaAccountService.cloud): where it reaches this gateway's
|
|
58
|
+
* accounts, and the address devices know the gateway by, the only account it joins.
|
|
59
|
+
*/
|
|
60
|
+
function accountEnv(env: Record<string, string | undefined>, url: string): Record<string, string>;
|
|
56
61
|
/** Where another Ta reaches the exec server of its account's sandbox. */
|
|
57
62
|
const EXEC_PATH = "/api/exec";
|
|
58
63
|
/** What a page is told when its Ta does not start for its account's limits; TaGatewayInfo.quota says it in the page's words. */
|
|
@@ -92,6 +92,17 @@ export var GatewayServerUtil;
|
|
|
92
92
|
return given;
|
|
93
93
|
}
|
|
94
94
|
GatewayServerUtil.deploymentEnv = deploymentEnv;
|
|
95
|
+
/**
|
|
96
|
+
* What makes a sandbox a Ta in the cloud of its account (TaAccountService.cloud): where it reaches this gateway's
|
|
97
|
+
* accounts, and the address devices know the gateway by, the only account it joins.
|
|
98
|
+
*/
|
|
99
|
+
function accountEnv(env, url) {
|
|
100
|
+
var _a;
|
|
101
|
+
var _b;
|
|
102
|
+
const service = (_a = ((_b = env.TA_GATEWAY_URL) !== null && _b !== void 0 ? _b : env.TA_PUBLIC_URL)) === null || _a === void 0 ? void 0 : _a.trim().replace(/\/+$/, '');
|
|
103
|
+
return { TA_ACCOUNT_KIND: 'cloud', TA_ACCOUNT_URL: url, ...(service ? { TA_ACCOUNT_SERVICE: service } : {}) };
|
|
104
|
+
}
|
|
105
|
+
GatewayServerUtil.accountEnv = accountEnv;
|
|
95
106
|
/** Where another Ta reaches the exec server of its account's sandbox. */
|
|
96
107
|
GatewayServerUtil.EXEC_PATH = '/api/exec';
|
|
97
108
|
/** What a page is told when its Ta does not start for its account's limits; TaGatewayInfo.quota says it in the page's words. */
|
|
@@ -153,7 +164,11 @@ export class GatewayServer {
|
|
|
153
164
|
this.flow = new SignInFlow(SignInProviders.fromEnv(env), new AccessStore(join(options.dir, 'access.json'), allowed), SignInProviders.publicUrl(env), SignInProviders.polled(env));
|
|
154
165
|
this.tenants = new TenantStore(options.dir);
|
|
155
166
|
// The devices of each account (docs/design/ta-account.md 3), its tokens those of this gateway's sign-in.
|
|
156
|
-
this.accounts = new RelayServerAccounts(options.dir, {
|
|
167
|
+
this.accounts = new RelayServerAccounts(options.dir, {
|
|
168
|
+
authenticate: async (token) => GatewayServerUtil.accountOf(this.caller(token)),
|
|
169
|
+
// A computer the user scanned joins their account with a sign-in of its own (docs/design/ta-me.md 4).
|
|
170
|
+
issue: async (account) => this.flow.store.signIn({ id: account.id, name: account.name }, 'A computer of the account'),
|
|
171
|
+
});
|
|
157
172
|
this.links = new SignInLinks(options.dir);
|
|
158
173
|
this.environments = new Environments(providers, this.tenants, {
|
|
159
174
|
default: config.default,
|
|
@@ -176,13 +191,10 @@ export class GatewayServer {
|
|
|
176
191
|
this.quotas.egressOf = tenant => (this.egress.enabled ? this.egress.refused(tenant.id) : undefined);
|
|
177
192
|
this.environments.envOf = (tenant, provider, fresh) => {
|
|
178
193
|
var _a, _b, _c;
|
|
179
|
-
const deployment = GatewayServerUtil.deploymentEnv(env);
|
|
180
|
-
if (!this.models.enabled && !this.egress.enabled) {
|
|
181
|
-
return Object.keys(deployment).length ? deployment : undefined;
|
|
182
|
-
}
|
|
183
194
|
const base = (_a = provider.gatewayUrl) !== null && _a !== void 0 ? _a : GatewayServerUtil.reach(provider.type, (_c = (_b = this.port) !== null && _b !== void 0 ? _b : options.port) !== null && _c !== void 0 ? _c : 4100, SandboxProviders.publicBase(env));
|
|
184
195
|
const url = base.replace(/\/+$/, '');
|
|
185
|
-
|
|
196
|
+
// The sandbox is a device of its account (docs/design/ta-me.md 2): the accounts of this gateway, from within.
|
|
197
|
+
const given = { ...GatewayServerUtil.deploymentEnv(env), ...GatewayServerUtil.accountEnv(env, url) };
|
|
186
198
|
if (this.models.enabled) {
|
|
187
199
|
Object.assign(given, { TA_MODEL_PROXY_URL: url, TA_MODEL_PROXY_KEY: this.tenants.modelKey(tenant.id) });
|
|
188
200
|
}
|
|
@@ -7,9 +7,16 @@ export declare namespace GatewayFiles {
|
|
|
7
7
|
* path of that address, and of any address a tenant names as its own Ta service.
|
|
8
8
|
*/
|
|
9
9
|
function target(requestUrl: string, endpoint: string): URL | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* What a file read through the gateway may do, whatever the Ta of the tenant said: run its scripts in an origin of
|
|
12
|
+
* its own (as ta serve's WorkspaceFiles has it), never in the gateway's, where the console and its sign-ins are.
|
|
13
|
+
*/
|
|
14
|
+
const SANDBOX = "sandbox allow-scripts allow-forms allow-popups allow-modals allow-downloads";
|
|
10
15
|
/**
|
|
11
16
|
* The headers of an answer of the Ta of a tenant, as the browser gets them: without cookies, which a Ta
|
|
12
|
-
* service of the user's (or what runs in a sandbox) would otherwise set on the gateway's origin
|
|
17
|
+
* service of the user's (or what runs in a sandbox) would otherwise set on the gateway's origin, and sandboxed by
|
|
18
|
+
* the gateway itself, not trusting what runs there to say so. A PDF alone is left out: browsers do not show one
|
|
19
|
+
* sandboxed, and none runs scripts in the gateway's origin.
|
|
13
20
|
*/
|
|
14
21
|
function headers(headers: IncomingMessage['headers']): IncomingMessage['headers'];
|
|
15
22
|
/** Reads `target` for `request`, its answer to `response` with the headers `answered` lets through. */
|
|
@@ -20,13 +20,29 @@ var GatewayFiles;
|
|
|
20
20
|
return target.origin === new URL(endpoint).origin && target.pathname.startsWith(`${ta_protocol_1.TA_FILES_PATH}/`) ? target : undefined;
|
|
21
21
|
}
|
|
22
22
|
GatewayFiles.target = target;
|
|
23
|
+
/**
|
|
24
|
+
* What a file read through the gateway may do, whatever the Ta of the tenant said: run its scripts in an origin of
|
|
25
|
+
* its own (as ta serve's WorkspaceFiles has it), never in the gateway's, where the console and its sign-ins are.
|
|
26
|
+
*/
|
|
27
|
+
GatewayFiles.SANDBOX = 'sandbox allow-scripts allow-forms allow-popups allow-modals allow-downloads';
|
|
23
28
|
/**
|
|
24
29
|
* The headers of an answer of the Ta of a tenant, as the browser gets them: without cookies, which a Ta
|
|
25
|
-
* service of the user's (or what runs in a sandbox) would otherwise set on the gateway's origin
|
|
30
|
+
* service of the user's (or what runs in a sandbox) would otherwise set on the gateway's origin, and sandboxed by
|
|
31
|
+
* the gateway itself, not trusting what runs there to say so. A PDF alone is left out: browsers do not show one
|
|
32
|
+
* sandboxed, and none runs scripts in the gateway's origin.
|
|
26
33
|
*/
|
|
27
34
|
function headers(headers) {
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
var _a;
|
|
36
|
+
const { 'set-cookie': _cookies, 'content-security-policy': _policy, 'x-content-type-options': _sniff, ...rest } = headers;
|
|
37
|
+
const type = String((_a = rest['content-type']) !== null && _a !== void 0 ? _a : '')
|
|
38
|
+
.split(';')[0]
|
|
39
|
+
.trim()
|
|
40
|
+
.toLowerCase();
|
|
41
|
+
return {
|
|
42
|
+
...rest,
|
|
43
|
+
'x-content-type-options': 'nosniff',
|
|
44
|
+
...(type === 'application/pdf' ? {} : { 'content-security-policy': GatewayFiles.SANDBOX }),
|
|
45
|
+
};
|
|
30
46
|
}
|
|
31
47
|
GatewayFiles.headers = headers;
|
|
32
48
|
/** Reads `target` for `request`, its answer to `response` with the headers `answered` lets through. */
|
|
@@ -53,6 +53,11 @@ export declare namespace GatewayServerUtil {
|
|
|
53
53
|
* pairs, shares and opens rooms on the relay of its people, and its name.
|
|
54
54
|
*/
|
|
55
55
|
function deploymentEnv(env: Record<string, string | undefined>): Record<string, string>;
|
|
56
|
+
/**
|
|
57
|
+
* What makes a sandbox a Ta in the cloud of its account (TaAccountService.cloud): where it reaches this gateway's
|
|
58
|
+
* accounts, and the address devices know the gateway by, the only account it joins.
|
|
59
|
+
*/
|
|
60
|
+
function accountEnv(env: Record<string, string | undefined>, url: string): Record<string, string>;
|
|
56
61
|
/** Where another Ta reaches the exec server of its account's sandbox. */
|
|
57
62
|
const EXEC_PATH = "/api/exec";
|
|
58
63
|
/** What a page is told when its Ta does not start for its account's limits; TaGatewayInfo.quota says it in the page's words. */
|
|
@@ -95,6 +95,17 @@ var GatewayServerUtil;
|
|
|
95
95
|
return given;
|
|
96
96
|
}
|
|
97
97
|
GatewayServerUtil.deploymentEnv = deploymentEnv;
|
|
98
|
+
/**
|
|
99
|
+
* What makes a sandbox a Ta in the cloud of its account (TaAccountService.cloud): where it reaches this gateway's
|
|
100
|
+
* accounts, and the address devices know the gateway by, the only account it joins.
|
|
101
|
+
*/
|
|
102
|
+
function accountEnv(env, url) {
|
|
103
|
+
var _a;
|
|
104
|
+
var _b;
|
|
105
|
+
const service = (_a = ((_b = env.TA_GATEWAY_URL) !== null && _b !== void 0 ? _b : env.TA_PUBLIC_URL)) === null || _a === void 0 ? void 0 : _a.trim().replace(/\/+$/, '');
|
|
106
|
+
return { TA_ACCOUNT_KIND: 'cloud', TA_ACCOUNT_URL: url, ...(service ? { TA_ACCOUNT_SERVICE: service } : {}) };
|
|
107
|
+
}
|
|
108
|
+
GatewayServerUtil.accountEnv = accountEnv;
|
|
98
109
|
/** Where another Ta reaches the exec server of its account's sandbox. */
|
|
99
110
|
GatewayServerUtil.EXEC_PATH = '/api/exec';
|
|
100
111
|
/** What a page is told when its Ta does not start for its account's limits; TaGatewayInfo.quota says it in the page's words. */
|
|
@@ -156,7 +167,11 @@ class GatewayServer {
|
|
|
156
167
|
this.flow = new sign_in_flow_1.SignInFlow(sign_in_provider_1.SignInProviders.fromEnv(env), new access_store_1.AccessStore((0, node_path_1.join)(options.dir, 'access.json'), allowed), sign_in_provider_1.SignInProviders.publicUrl(env), sign_in_provider_1.SignInProviders.polled(env));
|
|
157
168
|
this.tenants = new tenant_store_1.TenantStore(options.dir);
|
|
158
169
|
// The devices of each account (docs/design/ta-account.md 3), its tokens those of this gateway's sign-in.
|
|
159
|
-
this.accounts = new node_1.RelayServerAccounts(options.dir, {
|
|
170
|
+
this.accounts = new node_1.RelayServerAccounts(options.dir, {
|
|
171
|
+
authenticate: async (token) => GatewayServerUtil.accountOf(this.caller(token)),
|
|
172
|
+
// A computer the user scanned joins their account with a sign-in of its own (docs/design/ta-me.md 4).
|
|
173
|
+
issue: async (account) => this.flow.store.signIn({ id: account.id, name: account.name }, 'A computer of the account'),
|
|
174
|
+
});
|
|
160
175
|
this.links = new sign_in_links_1.SignInLinks(options.dir);
|
|
161
176
|
this.environments = new environments_1.Environments(providers, this.tenants, {
|
|
162
177
|
default: config.default,
|
|
@@ -179,13 +194,10 @@ class GatewayServer {
|
|
|
179
194
|
this.quotas.egressOf = tenant => (this.egress.enabled ? this.egress.refused(tenant.id) : undefined);
|
|
180
195
|
this.environments.envOf = (tenant, provider, fresh) => {
|
|
181
196
|
var _a, _b, _c;
|
|
182
|
-
const deployment = GatewayServerUtil.deploymentEnv(env);
|
|
183
|
-
if (!this.models.enabled && !this.egress.enabled) {
|
|
184
|
-
return Object.keys(deployment).length ? deployment : undefined;
|
|
185
|
-
}
|
|
186
197
|
const base = (_a = provider.gatewayUrl) !== null && _a !== void 0 ? _a : GatewayServerUtil.reach(provider.type, (_c = (_b = this.port) !== null && _b !== void 0 ? _b : options.port) !== null && _c !== void 0 ? _c : 4100, sandbox_provider_1.SandboxProviders.publicBase(env));
|
|
187
198
|
const url = base.replace(/\/+$/, '');
|
|
188
|
-
|
|
199
|
+
// The sandbox is a device of its account (docs/design/ta-me.md 2): the accounts of this gateway, from within.
|
|
200
|
+
const given = { ...GatewayServerUtil.deploymentEnv(env), ...GatewayServerUtil.accountEnv(env, url) };
|
|
189
201
|
if (this.models.enabled) {
|
|
190
202
|
Object.assign(given, { TA_MODEL_PROXY_URL: url, TA_MODEL_PROXY_KEY: this.tenants.modelKey(tenant.id) });
|
|
191
203
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-gateway",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.22.0",
|
|
4
4
|
"description": "ta gateway: one Ta per account, each in a sandbox of its own, behind one sign-in",
|
|
5
5
|
"homepage": "https://github.com/cellbang/ta",
|
|
6
6
|
"bugs": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@celljs/rpc": "4.
|
|
33
|
-
"@celljs/ta-host": "4.
|
|
34
|
-
"@celljs/ta-protocol": "4.
|
|
35
|
-
"@celljs/ta-relay": "4.
|
|
32
|
+
"@celljs/rpc": "4.22.0",
|
|
33
|
+
"@celljs/ta-host": "4.22.0",
|
|
34
|
+
"@celljs/ta-protocol": "4.22.0",
|
|
35
|
+
"@celljs/ta-relay": "4.22.0"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|