@celljs/ta-relay 4.24.0 → 4.25.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 +6 -6
- package/README.md +6 -6
- package/esm/common/index.d.ts +5 -0
- package/esm/common/index.js +5 -0
- package/esm/common/relay-accounts.d.ts +2 -0
- package/esm/common/relay-accounts.js +21 -0
- package/esm/common/relay-blobs.d.ts +2 -0
- package/esm/common/relay-blobs.js +1 -0
- package/esm/common/relay-content-origin.d.ts +44 -0
- package/esm/common/relay-content-origin.js +67 -0
- package/esm/common/relay-content.d.ts +2 -0
- package/esm/common/relay-content.js +12 -2
- package/esm/common/relay-friends.js +1 -1
- package/esm/common/relay-hub-util.js +1 -1
- package/esm/common/relay-hub.js +4 -4
- package/esm/common/relay-hubs-admins.js +3 -3
- package/esm/common/relay-hubs.js +5 -5
- package/esm/common/relay-info.d.ts +11 -1
- package/esm/common/relay-info.js +20 -2
- package/esm/common/relay-moderation-client.d.ts +32 -0
- package/esm/common/relay-moderation-client.js +51 -0
- package/esm/common/relay-moderation-door.d.ts +24 -0
- package/esm/common/relay-moderation-door.js +48 -0
- package/esm/common/relay-moderation-policy.d.ts +78 -0
- package/esm/common/relay-moderation-policy.js +59 -0
- package/esm/common/relay-moderation.d.ts +165 -0
- package/esm/common/relay-moderation.js +464 -0
- package/esm/common/relay-protocol.d.ts +5 -1
- package/esm/common/relay-protocol.js +4 -0
- package/esm/common/relay-room-app.d.ts +5 -0
- package/esm/common/relay-room-app.js +8 -0
- package/esm/node/relay-chat-files.js +1 -1
- package/esm/node/relay-server-accounts.d.ts +2 -0
- package/esm/node/relay-server-accounts.js +4 -0
- package/esm/node/relay-server-gate.d.ts +39 -0
- package/esm/node/relay-server-gate.js +124 -0
- package/esm/node/relay-server-web.d.ts +5 -0
- package/esm/node/relay-server-web.js +28 -0
- package/esm/node/relay-server.d.ts +9 -2
- package/esm/node/relay-server.js +40 -47
- package/esm/node/relay-store.d.ts +4 -0
- package/esm/node/relay-store.js +2 -0
- package/esm/viewer/viewer-i18n.d.ts +25 -0
- package/esm/viewer/viewer-i18n.js +132 -32
- package/esm/viewer/viewer-style.d.ts +1 -1
- package/esm/viewer/viewer-style.js +13 -0
- package/esm/viewer/viewer.js +127 -6
- package/lib/common/index.d.ts +5 -0
- package/lib/common/index.js +5 -0
- package/lib/common/relay-accounts.d.ts +2 -0
- package/lib/common/relay-accounts.js +21 -0
- package/lib/common/relay-blobs.d.ts +2 -0
- package/lib/common/relay-blobs.js +1 -0
- package/lib/common/relay-content-origin.d.ts +45 -0
- package/lib/common/relay-content-origin.js +71 -0
- package/lib/common/relay-content.d.ts +2 -0
- package/lib/common/relay-content.js +12 -2
- package/lib/common/relay-friends.js +1 -1
- package/lib/common/relay-hub-util.js +1 -1
- package/lib/common/relay-hub.js +4 -4
- package/lib/common/relay-hubs-admins.js +3 -3
- package/lib/common/relay-hubs.js +5 -5
- package/lib/common/relay-info.d.ts +11 -1
- package/lib/common/relay-info.js +20 -2
- package/lib/common/relay-moderation-client.d.ts +33 -0
- package/lib/common/relay-moderation-client.js +54 -0
- package/lib/common/relay-moderation-door.d.ts +25 -0
- package/lib/common/relay-moderation-door.js +51 -0
- package/lib/common/relay-moderation-policy.d.ts +79 -0
- package/lib/common/relay-moderation-policy.js +62 -0
- package/lib/common/relay-moderation.d.ts +166 -0
- package/lib/common/relay-moderation.js +468 -0
- package/lib/common/relay-protocol.d.ts +5 -1
- package/lib/common/relay-protocol.js +4 -0
- package/lib/common/relay-room-app.d.ts +5 -0
- package/lib/common/relay-room-app.js +8 -0
- package/lib/node/relay-chat-files.js +1 -1
- package/lib/node/relay-server-accounts.d.ts +2 -0
- package/lib/node/relay-server-accounts.js +4 -0
- package/lib/node/relay-server-gate.d.ts +40 -0
- package/lib/node/relay-server-gate.js +128 -0
- package/lib/node/relay-server-web.d.ts +6 -0
- package/lib/node/relay-server-web.js +31 -0
- package/lib/node/relay-server.d.ts +9 -2
- package/lib/node/relay-server.js +39 -46
- package/lib/node/relay-store.d.ts +4 -0
- package/lib/node/relay-store.js +2 -0
- package/lib/viewer/viewer-i18n.d.ts +25 -0
- package/lib/viewer/viewer-i18n.js +132 -32
- package/lib/viewer/viewer-style.d.ts +1 -1
- package/lib/viewer/viewer-style.js +13 -0
- package/lib/viewer/viewer.js +127 -6
- package/package.json +3 -3
- package/viewer/join.html +5 -5
- package/viewer/page.html +25 -12
- package/viewer/room.html +4 -4
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelayContentOrigins = exports.RelayContentOrigin = void 0;
|
|
4
|
+
const relay_info_1 = require("./relay-info");
|
|
5
|
+
const relay_moderation_1 = require("./relay-moderation");
|
|
6
|
+
const relay_protocol_1 = require("./relay-protocol");
|
|
7
|
+
const relay_team_1 = require("./relay-team");
|
|
8
|
+
/**
|
|
9
|
+
* The domain of content (RelayInfo.content, `TA_CONTENT_ORIGIN`): another domain of the same relay, where links of
|
|
10
|
+
* content open, so that what users share never shows on the relay's own domain (docs/design/ta-link.md 2.10). It
|
|
11
|
+
* answers only what a viewer needs: the pages of a link, the connection to the host that shared it, its copy, the
|
|
12
|
+
* report; the relay's own domain sends links of content there.
|
|
13
|
+
*/
|
|
14
|
+
var RelayContentOrigin;
|
|
15
|
+
(function (RelayContentOrigin) {
|
|
16
|
+
const PAGES = new Set([relay_protocol_1.RELAY_CONTENT_PATH, relay_protocol_1.RELAY_FRAME_PATH, relay_info_1.RELAY_INFO_PATH, relay_moderation_1.RELAY_REPORT_PATH, '/healthz', '/readyz']);
|
|
17
|
+
const PREFIXES = [relay_protocol_1.RELAY_CONNECT_PATH, relay_protocol_1.RELAY_BLOB_PATH, relay_team_1.RELAY_WEB_PATH];
|
|
18
|
+
/** Whether the request came to the domain of content. */
|
|
19
|
+
function isContent(url, content) {
|
|
20
|
+
return !!content && url.host === new URL(content).host;
|
|
21
|
+
}
|
|
22
|
+
RelayContentOrigin.isContent = isContent;
|
|
23
|
+
/** `content` none: the relay has no domain of content, and serves all on its own. */
|
|
24
|
+
function route(url, content) {
|
|
25
|
+
if (!content) {
|
|
26
|
+
return { kind: 'serve' };
|
|
27
|
+
}
|
|
28
|
+
const path = url.pathname;
|
|
29
|
+
if (isContent(url, content)) {
|
|
30
|
+
return PAGES.has(path) || PREFIXES.some(prefix => path.startsWith(prefix)) || path === relay_team_1.RELAY_WEB_PATH.slice(0, -1)
|
|
31
|
+
? { kind: 'serve' }
|
|
32
|
+
: { kind: 'refuse' };
|
|
33
|
+
}
|
|
34
|
+
if (path === relay_protocol_1.RELAY_CONTENT_PATH) {
|
|
35
|
+
return { kind: 'redirect', location: `${content}${relay_protocol_1.RELAY_CONTENT_PATH}${url.search}` };
|
|
36
|
+
}
|
|
37
|
+
// A page of a user framed under the relay's own domain: never.
|
|
38
|
+
return path === relay_protocol_1.RELAY_FRAME_PATH ? { kind: 'refuse' } : { kind: 'serve' };
|
|
39
|
+
}
|
|
40
|
+
RelayContentOrigin.route = route;
|
|
41
|
+
})(RelayContentOrigin || (exports.RelayContentOrigin = RelayContentOrigin = {}));
|
|
42
|
+
/**
|
|
43
|
+
* Where links of content of each relay open, as the relay says (RelayInfo.content), asked again an hour later: its domain
|
|
44
|
+
* of content, else its own (also while it does not answer: the link still works, and it is sent on once there is one).
|
|
45
|
+
*/
|
|
46
|
+
class RelayContentOrigins {
|
|
47
|
+
constructor(probe = relay => relay_info_1.RelayInfoUtil.probe(relay, 3000).then(found => found.info)) {
|
|
48
|
+
this.probe = probe;
|
|
49
|
+
this.known = new Map();
|
|
50
|
+
}
|
|
51
|
+
info(relay, now) {
|
|
52
|
+
const known = this.known.get(relay);
|
|
53
|
+
if (known && now - known.at < 60 * 60 * 1000) {
|
|
54
|
+
return known.info;
|
|
55
|
+
}
|
|
56
|
+
const info = this.probe(relay).catch(() => undefined);
|
|
57
|
+
this.known.set(relay, { at: now, info });
|
|
58
|
+
return info;
|
|
59
|
+
}
|
|
60
|
+
async of(relay, now = Date.now()) {
|
|
61
|
+
var _a;
|
|
62
|
+
return (_a = (await this.info(relay, now))) === null || _a === void 0 ? void 0 : _a.content;
|
|
63
|
+
}
|
|
64
|
+
/** Whether the relay needs the one who shares a public link to have signed in to an account (RelayInfo.needsAccount). */
|
|
65
|
+
async needsAccount(relay, now = Date.now()) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
return !!((_b = (_a = (await this.info(relay, now))) === null || _a === void 0 ? void 0 : _a.needsAccount) === null || _b === void 0 ? void 0 : _b.includes('share'));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.RelayContentOrigins = RelayContentOrigins;
|
|
71
|
+
//# sourceMappingURL=relay-content-origin.js.map
|
|
@@ -17,6 +17,8 @@ export interface RelayContentLink {
|
|
|
17
17
|
owner?: string;
|
|
18
18
|
/** A copy is kept on the relay, sealed: it opens while the computer that shared it is off. */
|
|
19
19
|
offline?: boolean;
|
|
20
|
+
/** The origin the link opens at: the domain of content of the relay (RelayInfo.content); none, the relay's own. */
|
|
21
|
+
page?: string;
|
|
20
22
|
/**
|
|
21
23
|
* What it shares, in the link (`c`) for kinds other than a conversation or a file (an agent's card), so that the
|
|
22
24
|
* package that opens it claims the link before it is fetched. Not secret.
|
|
@@ -16,6 +16,7 @@ class RelayContentError extends Error {
|
|
|
16
16
|
}
|
|
17
17
|
exports.RelayContentError = RelayContentError;
|
|
18
18
|
const PBKDF2_ITERATIONS = 600000;
|
|
19
|
+
const BLOCKED_MESSAGE = 'The operator of the relay blocked this link after a report.';
|
|
19
20
|
/** Kinds the links of before carry no `c` for. */
|
|
20
21
|
const PLAIN_KINDS = new Set(['ta-conversation', 'file']);
|
|
21
22
|
const KIND = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
@@ -31,7 +32,7 @@ var RelayContentUtil;
|
|
|
31
32
|
* `c=<kind>` for what is no conversation or file.
|
|
32
33
|
*/
|
|
33
34
|
function link(content) {
|
|
34
|
-
var _a;
|
|
35
|
+
var _a, _b;
|
|
35
36
|
const fragment = new URLSearchParams({ v: '1', h: content.host, s: content.share });
|
|
36
37
|
if (content.access === 'self') {
|
|
37
38
|
fragment.set('m', 'self');
|
|
@@ -52,7 +53,7 @@ var RelayContentUtil;
|
|
|
52
53
|
if (content.kind && !PLAIN_KINDS.has(content.kind) && KIND.test(content.kind)) {
|
|
53
54
|
fragment.set('c', content.kind);
|
|
54
55
|
}
|
|
55
|
-
return `${content.relay}${relay_protocol_1.RELAY_CONTENT_PATH}#${fragment}`;
|
|
56
|
+
return `${(_b = content.page) !== null && _b !== void 0 ? _b : content.relay}${relay_protocol_1.RELAY_CONTENT_PATH}#${fragment}`;
|
|
56
57
|
}
|
|
57
58
|
RelayContentUtil.link = link;
|
|
58
59
|
function is(text) {
|
|
@@ -204,6 +205,9 @@ var RelayContentUtil;
|
|
|
204
205
|
? new RelayContentError('wrong', 'The password is wrong.')
|
|
205
206
|
: new RelayContentError('gone', 'This link no longer works.');
|
|
206
207
|
}
|
|
208
|
+
if (response.status === 410 || response.status === 451) {
|
|
209
|
+
throw new RelayContentError('gone', BLOCKED_MESSAGE);
|
|
210
|
+
}
|
|
207
211
|
if (response.status === 429) {
|
|
208
212
|
throw new RelayContentError('busy', 'Too many wrong passwords: try again in a few minutes.');
|
|
209
213
|
}
|
|
@@ -302,6 +306,12 @@ var RelayContentUtil;
|
|
|
302
306
|
}
|
|
303
307
|
return new RelayContentError('gone', 'This link no longer works: the share was stopped or ran out.');
|
|
304
308
|
}
|
|
309
|
+
if (code === relay_protocol_1.RelayCloseCode.BLOCKED) {
|
|
310
|
+
return new RelayContentError('gone', BLOCKED_MESSAGE);
|
|
311
|
+
}
|
|
312
|
+
if (code === relay_protocol_1.RelayCloseCode.SIGN_IN) {
|
|
313
|
+
return new RelayContentError('gone', 'The one who shared it has not signed in to an account, which this relay needs of public links.');
|
|
314
|
+
}
|
|
305
315
|
return code === relay_protocol_1.RelayCloseCode.HOST_OFFLINE || code === relay_protocol_1.RelayCloseCode.TIMEOUT
|
|
306
316
|
? new RelayContentError('offline', 'The computer that shared it is not running Ta now. Try again later.')
|
|
307
317
|
: new RelayContentError('offline', 'The computer that shared it cannot be reached now. Try again later.');
|
|
@@ -76,7 +76,7 @@ class RelayFriends {
|
|
|
76
76
|
const other = info === null || info === void 0 ? void 0 : info.members.find(item => item.member === member);
|
|
77
77
|
const identity = this.rooms.memberOf(room, member);
|
|
78
78
|
if (!info || !other || other.self || other.guest || !identity) {
|
|
79
|
-
throw new Error('Not one to ask in that
|
|
79
|
+
throw new Error('Not one to ask in that group chat.');
|
|
80
80
|
}
|
|
81
81
|
const { link } = await this.link();
|
|
82
82
|
this.choose(identity);
|
|
@@ -44,7 +44,7 @@ var RelayHubUtil;
|
|
|
44
44
|
!relay_protocol_1.RELAY_ID.test(room) ||
|
|
45
45
|
!/^[A-Za-z0-9_-]{43}$/.test(invite) ||
|
|
46
46
|
!/^[A-Za-z0-9_-]{22}$/.test(owner)) {
|
|
47
|
-
throw new Error('Not a link inviting into a
|
|
47
|
+
throw new Error('Not a link inviting into a group chat of Ta.');
|
|
48
48
|
}
|
|
49
49
|
const kind = (_a = fragment.get('c')) !== null && _a !== void 0 ? _a : '';
|
|
50
50
|
return {
|
package/lib/common/relay-hub.js
CHANGED
|
@@ -126,7 +126,7 @@ class RelayHub {
|
|
|
126
126
|
}
|
|
127
127
|
const members = (_b = (await this.storage.get('members'))) !== null && _b !== void 0 ? _b : {};
|
|
128
128
|
if (!RelayHub.id(member) || ((_a = members[member]) === null || _a === void 0 ? void 0 : _a.hash) !== (await relay_identity_1.RelayKeys.hash(String(token)))) {
|
|
129
|
-
this.refuse(socket, 'auth', 'Not a member of this
|
|
129
|
+
this.refuse(socket, 'auth', 'Not a member of this group chat.', RelayHubCloseCode.REFUSED);
|
|
130
130
|
return;
|
|
131
131
|
}
|
|
132
132
|
const wasOnline = this.online(member, socket);
|
|
@@ -179,7 +179,7 @@ class RelayHub {
|
|
|
179
179
|
return;
|
|
180
180
|
}
|
|
181
181
|
if (Object.keys(asks).length >= relay_protocol_1.RELAY_HUB_MAX_ASKS) {
|
|
182
|
-
this.refuse(socket, 'full', 'Too many ask to join this
|
|
182
|
+
this.refuse(socket, 'full', 'Too many ask to join this group chat now.', RelayHubCloseCode.REFUSED);
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
185
|
asks[request.ask] = { hash: await relay_identity_1.RelayKeys.hash(request.token), d: request.d, at: now };
|
|
@@ -229,7 +229,7 @@ class RelayHub {
|
|
|
229
229
|
const meta = await this.storage.get('meta');
|
|
230
230
|
const members = (_c = (await this.storage.get('members'))) !== null && _c !== void 0 ? _c : {};
|
|
231
231
|
if (!meta || !members[member]) {
|
|
232
|
-
this.refuse(socket, 'gone', 'Not in this
|
|
232
|
+
this.refuse(socket, 'gone', 'Not in this group chat any more.', RelayHubCloseCode.REMOVED);
|
|
233
233
|
return;
|
|
234
234
|
}
|
|
235
235
|
const owner = member === meta.owner;
|
|
@@ -260,7 +260,7 @@ class RelayHub {
|
|
|
260
260
|
await this.unmake(meta, member);
|
|
261
261
|
await this.log.gone(member);
|
|
262
262
|
for (const other of this.members(member)) {
|
|
263
|
-
other.close(RelayHubCloseCode.REMOVED, 'Left the
|
|
263
|
+
other.close(RelayHubCloseCode.REMOVED, 'Left the group chat.');
|
|
264
264
|
}
|
|
265
265
|
this.broadcast({ t: 'left', member });
|
|
266
266
|
return;
|
|
@@ -73,21 +73,21 @@ class RelayHubsAdmins extends relay_hubs_identity_1.RelayHubsIdentity {
|
|
|
73
73
|
managed(roomId) {
|
|
74
74
|
const live = this.member(roomId);
|
|
75
75
|
if (!this.manages(live)) {
|
|
76
|
-
throw new Error('Only the owner or an admin of the
|
|
76
|
+
throw new Error('Only the owner or an admin of the group chat does that.');
|
|
77
77
|
}
|
|
78
78
|
return live;
|
|
79
79
|
}
|
|
80
80
|
owned(roomId) {
|
|
81
81
|
const live = this.member(roomId);
|
|
82
82
|
if (!live.record.own) {
|
|
83
|
-
throw new Error('Only the owner of the
|
|
83
|
+
throw new Error('Only the owner of the group chat does that.');
|
|
84
84
|
}
|
|
85
85
|
return live;
|
|
86
86
|
}
|
|
87
87
|
member(roomId) {
|
|
88
88
|
const live = this.live.get(roomId);
|
|
89
89
|
if ((live === null || live === void 0 ? void 0 : live.record.status) !== 'member') {
|
|
90
|
-
throw new Error('Not in that
|
|
90
|
+
throw new Error('Not in that group chat.');
|
|
91
91
|
}
|
|
92
92
|
return live;
|
|
93
93
|
}
|
package/lib/common/relay-hubs.js
CHANGED
|
@@ -189,7 +189,7 @@ class RelayHubs extends relay_hubs_chats_1.RelayHubsChats {
|
|
|
189
189
|
return this.info(known);
|
|
190
190
|
}
|
|
191
191
|
if (known === null || known === void 0 ? void 0 : known.record.own) {
|
|
192
|
-
throw new Error('This is a
|
|
192
|
+
throw new Error('This is a group chat of your own.');
|
|
193
193
|
}
|
|
194
194
|
const friends = relay_friends_1.RelayFriendsUtil.isKind(link.kind);
|
|
195
195
|
const record = {
|
|
@@ -275,11 +275,11 @@ class RelayHubs extends relay_hubs_chats_1.RelayHubsChats {
|
|
|
275
275
|
var _a, _b;
|
|
276
276
|
const live = this.managed(roomId);
|
|
277
277
|
if (member === live.record.member) {
|
|
278
|
-
throw new Error('The owner leaves by closing the
|
|
278
|
+
throw new Error('The owner leaves by closing the group chat.');
|
|
279
279
|
}
|
|
280
280
|
const owner = (_b = (_a = live.roster) === null || _a === void 0 ? void 0 : _a.members.find(other => other.owner)) === null || _b === void 0 ? void 0 : _b.member;
|
|
281
281
|
if (!live.record.own && (member === owner || this.isAdmin(live, member))) {
|
|
282
|
-
throw new Error('Only the owner of the
|
|
282
|
+
throw new Error('Only the owner of the group chat does that.');
|
|
283
283
|
}
|
|
284
284
|
await this.ready(live);
|
|
285
285
|
// A new key for those left: the one taken out holds those of before alone (docs/design/ta-link.md 8.7).
|
|
@@ -361,9 +361,9 @@ class RelayHubs extends relay_hubs_chats_1.RelayHubsChats {
|
|
|
361
361
|
throw new Error(result.error === 'large'
|
|
362
362
|
? 'The value is too large.'
|
|
363
363
|
: result.error === 'limit'
|
|
364
|
-
? 'The shared state of the
|
|
364
|
+
? 'The shared state of the group chat is full.'
|
|
365
365
|
: result.error === 'owned'
|
|
366
|
-
? 'Another member keeps this key: only they or the owner of the
|
|
366
|
+
? 'Another member keeps this key: only they or the owner of the group chat change it.'
|
|
367
367
|
: 'The relay refused it.');
|
|
368
368
|
}
|
|
369
369
|
if (result.ok) {
|
|
@@ -24,6 +24,14 @@ export interface RelayInfo {
|
|
|
24
24
|
* member who has one is online: so many days, so many bytes each. None (the default): it keeps none.
|
|
25
25
|
*/
|
|
26
26
|
media?: RelayMedia;
|
|
27
|
+
/**
|
|
28
|
+
* The origin links of content open at (RELAY_CONTENT_PATH), another domain of the same relay, set by its operator
|
|
29
|
+
* (`TA_CONTENT_ORIGIN`): what users share shows there, so that a page of one of them that is reported or blocked
|
|
30
|
+
* takes down that domain, never the relay's own (docs/design/ta-link.md 2.10). None: the relay's own.
|
|
31
|
+
*/
|
|
32
|
+
content?: string;
|
|
33
|
+
/** What needs the one who shares to have signed in to an account there (RelayModerationPolicy.needsAccount): `share` for public links. */
|
|
34
|
+
needsAccount?: string[];
|
|
27
35
|
}
|
|
28
36
|
/** What a relay keeps of the pictures of chats (RelayInfo.media), as its operator set it. */
|
|
29
37
|
export interface RelayMedia {
|
|
@@ -50,7 +58,9 @@ export interface RelayProbe {
|
|
|
50
58
|
error?: string;
|
|
51
59
|
}
|
|
52
60
|
export declare namespace RelayInfoUtil {
|
|
53
|
-
function of(persistent: boolean, media?: RelayMedia): RelayInfo;
|
|
61
|
+
function of(persistent: boolean, media?: RelayMedia, content?: string): RelayInfo;
|
|
62
|
+
/** An origin of https (or http for a test), as `TA_CONTENT_ORIGIN` or RelayInfo.content give it; undefined for what is not one. */
|
|
63
|
+
function origin(value: unknown): string | undefined;
|
|
54
64
|
/**
|
|
55
65
|
* What the operator of a relay lets it keep of the pictures of chats, from its settings (`TA_MEDIA_DAYS`,
|
|
56
66
|
* `TA_MEDIA_MAX_MB`): RELAY_MEDIA_DEFAULT_DAYS unless set, none with 0, within RELAY_MEDIA_MAX.
|
package/lib/common/relay-info.js
CHANGED
|
@@ -28,10 +28,24 @@ exports.RELAY_LEGACY_INFO = {
|
|
|
28
28
|
};
|
|
29
29
|
var RelayInfoUtil;
|
|
30
30
|
(function (RelayInfoUtil) {
|
|
31
|
-
function of(persistent, media) {
|
|
32
|
-
return { ...exports.RELAY_LEGACY_INFO, persistent, ...(media ? { media } : {}) };
|
|
31
|
+
function of(persistent, media, content) {
|
|
32
|
+
return { ...exports.RELAY_LEGACY_INFO, persistent, ...(media ? { media } : {}), ...(content ? { content } : {}) };
|
|
33
33
|
}
|
|
34
34
|
RelayInfoUtil.of = of;
|
|
35
|
+
/** An origin of https (or http for a test), as `TA_CONTENT_ORIGIN` or RelayInfo.content give it; undefined for what is not one. */
|
|
36
|
+
function origin(value) {
|
|
37
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const url = new URL(value.trim());
|
|
42
|
+
return /^https?:$/.test(url.protocol) && !url.username && !url.password ? url.origin : undefined;
|
|
43
|
+
}
|
|
44
|
+
catch (_a) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
RelayInfoUtil.origin = origin;
|
|
35
49
|
/**
|
|
36
50
|
* What the operator of a relay lets it keep of the pictures of chats, from its settings (`TA_MEDIA_DAYS`,
|
|
37
51
|
* `TA_MEDIA_MAX_MB`): RELAY_MEDIA_DEFAULT_DAYS unless set, none with 0, within RELAY_MEDIA_MAX.
|
|
@@ -107,12 +121,16 @@ var RelayInfoUtil;
|
|
|
107
121
|
}
|
|
108
122
|
}
|
|
109
123
|
const kept = info.media && media(info.media.days, (Number(info.media.bytes) || 0) / (1024 * 1024));
|
|
124
|
+
const content = origin(info.content);
|
|
125
|
+
const needs = Array.isArray(info.needsAccount) ? info.needsAccount.filter((each) => typeof each === 'string').slice(0, 8) : [];
|
|
110
126
|
return {
|
|
111
127
|
v: 1,
|
|
112
128
|
capabilities: info.capabilities.filter((capability) => known.includes(capability)),
|
|
113
129
|
limits,
|
|
114
130
|
persistent: info.persistent !== false,
|
|
115
131
|
...(kept ? { media: kept } : {}),
|
|
132
|
+
...(content ? { content } : {}),
|
|
133
|
+
...(needs.length ? { needsAccount: needs } : {}),
|
|
116
134
|
};
|
|
117
135
|
}
|
|
118
136
|
RelayInfoUtil.parse = parse;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type RelayBlocks, type RelayModerationAction, type RelayReport } from './relay-moderation';
|
|
2
|
+
import { type RelayAppeal, type RelayModerationEntry, type RelayModerationPolicy, type RelaySanction, type RelayStanding } from './relay-moderation-policy';
|
|
3
|
+
/** What the operator of a relay reads (RELAY_MODERATION_PATH). */
|
|
4
|
+
export interface RelayModerationState {
|
|
5
|
+
reports: RelayReport[];
|
|
6
|
+
blocks: RelayBlocks;
|
|
7
|
+
policy: RelayModerationPolicy;
|
|
8
|
+
sanctions: Record<string, RelaySanction>;
|
|
9
|
+
appeals: RelayAppeal[];
|
|
10
|
+
log: RelayModerationEntry[];
|
|
11
|
+
/** Who shares through each computer reported, by its id. */
|
|
12
|
+
owners: Record<string, {
|
|
13
|
+
account: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
at: number;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
/** The operator's side, from Ta: reads and acts, with the token of the relay. */
|
|
19
|
+
export declare namespace RelayModerationClient {
|
|
20
|
+
function read(relay: string, token: string): Promise<RelayModerationState>;
|
|
21
|
+
function apply(relay: string, token: string, action: RelayModerationAction): Promise<RelayModerationState>;
|
|
22
|
+
}
|
|
23
|
+
/** An account's side: the computer it shares through, how it stands, and its appeal, with the token of the account. */
|
|
24
|
+
export declare namespace RelayStandingClient {
|
|
25
|
+
/** Proves both: the account by its token, the computer by the secret it holds its id on the relay with. */
|
|
26
|
+
function bind(relay: string, token: string, host: {
|
|
27
|
+
id: string;
|
|
28
|
+
secret: string;
|
|
29
|
+
}): Promise<RelayStanding>;
|
|
30
|
+
function standing(relay: string, token: string): Promise<RelayStanding>;
|
|
31
|
+
function appeal(relay: string, token: string, text: string): Promise<RelayStanding>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=relay-moderation-client.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelayStandingClient = exports.RelayModerationClient = void 0;
|
|
4
|
+
const relay_moderation_1 = require("./relay-moderation");
|
|
5
|
+
const relay_moderation_policy_1 = require("./relay-moderation-policy");
|
|
6
|
+
async function call(url, token, init) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const response = await fetch(url, {
|
|
9
|
+
...init,
|
|
10
|
+
headers: { authorization: `Bearer ${token}`, ...((init === null || init === void 0 ? void 0 : init.body) ? { 'content-type': 'application/json' } : {}) },
|
|
11
|
+
});
|
|
12
|
+
const body = (await response.json().catch(() => undefined));
|
|
13
|
+
if (response.status === 401) {
|
|
14
|
+
throw new Error((_a = body === null || body === void 0 ? void 0 : body.error) !== null && _a !== void 0 ? _a : 'The token is wrong.');
|
|
15
|
+
}
|
|
16
|
+
if (response.status === 404) {
|
|
17
|
+
throw new Error('This relay does not answer it.');
|
|
18
|
+
}
|
|
19
|
+
if (!response.ok || !body) {
|
|
20
|
+
throw new Error((_b = body === null || body === void 0 ? void 0 : body.error) !== null && _b !== void 0 ? _b : `The relay answered ${response.status}.`);
|
|
21
|
+
}
|
|
22
|
+
return body;
|
|
23
|
+
}
|
|
24
|
+
const base = (relay) => relay.replace(/\/+$/, '');
|
|
25
|
+
/** The operator's side, from Ta: reads and acts, with the token of the relay. */
|
|
26
|
+
var RelayModerationClient;
|
|
27
|
+
(function (RelayModerationClient) {
|
|
28
|
+
function read(relay, token) {
|
|
29
|
+
return call(`${base(relay)}${relay_moderation_1.RELAY_MODERATION_PATH}`, token);
|
|
30
|
+
}
|
|
31
|
+
RelayModerationClient.read = read;
|
|
32
|
+
function apply(relay, token, action) {
|
|
33
|
+
return call(`${base(relay)}${relay_moderation_1.RELAY_MODERATION_PATH}`, token, { method: 'POST', body: JSON.stringify(action) });
|
|
34
|
+
}
|
|
35
|
+
RelayModerationClient.apply = apply;
|
|
36
|
+
})(RelayModerationClient || (exports.RelayModerationClient = RelayModerationClient = {}));
|
|
37
|
+
/** An account's side: the computer it shares through, how it stands, and its appeal, with the token of the account. */
|
|
38
|
+
var RelayStandingClient;
|
|
39
|
+
(function (RelayStandingClient) {
|
|
40
|
+
/** Proves both: the account by its token, the computer by the secret it holds its id on the relay with. */
|
|
41
|
+
function bind(relay, token, host) {
|
|
42
|
+
return call(`${base(relay)}${relay_moderation_policy_1.RELAY_BIND_PATH}`, token, { method: 'POST', body: JSON.stringify({ host: host.id, secret: host.secret }) });
|
|
43
|
+
}
|
|
44
|
+
RelayStandingClient.bind = bind;
|
|
45
|
+
function standing(relay, token) {
|
|
46
|
+
return call(`${base(relay)}${relay_moderation_policy_1.RELAY_STANDING_PATH}`, token);
|
|
47
|
+
}
|
|
48
|
+
RelayStandingClient.standing = standing;
|
|
49
|
+
function appeal(relay, token, text) {
|
|
50
|
+
return call(`${base(relay)}${relay_moderation_policy_1.RELAY_APPEAL_PATH}`, token, { method: 'POST', body: JSON.stringify({ text }) });
|
|
51
|
+
}
|
|
52
|
+
RelayStandingClient.appeal = appeal;
|
|
53
|
+
})(RelayStandingClient || (exports.RelayStandingClient = RelayStandingClient = {}));
|
|
54
|
+
//# sourceMappingURL=relay-moderation-client.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type RelayAccountWho } from './relay-moderation';
|
|
2
|
+
/** What the relay checks for the door: an account by its token, a computer by its secret; where moderation runs. */
|
|
3
|
+
export interface RelayModerationDoorContext {
|
|
4
|
+
/** The account of a bearer token, or undefined. */
|
|
5
|
+
whoIs(authorization: string): Promise<RelayAccountWho | undefined>;
|
|
6
|
+
/** Whether this secret is the one the computer holds its id on the relay with. */
|
|
7
|
+
holds(host: string, secret: string): Promise<boolean>;
|
|
8
|
+
/** Moderation (RelayModeration.handle), told the address and, once checked, the account. */
|
|
9
|
+
moderate(request: Request, address: string, who?: RelayAccountWho): Promise<Response>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The paths of moderation anyone reaches (docs/design/ta-moderation.md): the relay checks who calls before moderation
|
|
13
|
+
* reads them, the same in the Worker and in `ta relay`. Internal paths are never reached from outside.
|
|
14
|
+
*/
|
|
15
|
+
export declare namespace RelayModerationDoor {
|
|
16
|
+
function handles(pathname: string): boolean;
|
|
17
|
+
function handle(request: Request, address: string, context: RelayModerationDoorContext): Promise<Response>;
|
|
18
|
+
/** Whether a request came from the pages of the relay in a browser: its Origin one of the relay's. */
|
|
19
|
+
function browser(request: {
|
|
20
|
+
headers: {
|
|
21
|
+
get(name: string): string | null;
|
|
22
|
+
};
|
|
23
|
+
} | undefined, origins: readonly (string | undefined)[]): boolean;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=relay-moderation-door.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelayModerationDoor = void 0;
|
|
4
|
+
const relay_moderation_1 = require("./relay-moderation");
|
|
5
|
+
const relay_moderation_policy_1 = require("./relay-moderation-policy");
|
|
6
|
+
const relay_protocol_1 = require("./relay-protocol");
|
|
7
|
+
const json = (status, body) => new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json', 'cache-control': 'no-store' } });
|
|
8
|
+
/**
|
|
9
|
+
* The paths of moderation anyone reaches (docs/design/ta-moderation.md): the relay checks who calls before moderation
|
|
10
|
+
* reads them, the same in the Worker and in `ta relay`. Internal paths are never reached from outside.
|
|
11
|
+
*/
|
|
12
|
+
var RelayModerationDoor;
|
|
13
|
+
(function (RelayModerationDoor) {
|
|
14
|
+
const PUBLIC = new Set([relay_moderation_1.RELAY_REPORT_PATH, relay_moderation_1.RELAY_MODERATION_PATH, relay_moderation_policy_1.RELAY_BIND_PATH, relay_moderation_policy_1.RELAY_STANDING_PATH, relay_moderation_policy_1.RELAY_APPEAL_PATH]);
|
|
15
|
+
function handles(pathname) {
|
|
16
|
+
return PUBLIC.has(pathname);
|
|
17
|
+
}
|
|
18
|
+
RelayModerationDoor.handles = handles;
|
|
19
|
+
async function handle(request, address, context) {
|
|
20
|
+
var _a;
|
|
21
|
+
const { pathname } = new URL(request.url);
|
|
22
|
+
if (pathname === relay_moderation_1.RELAY_REPORT_PATH || pathname === relay_moderation_1.RELAY_MODERATION_PATH) {
|
|
23
|
+
return context.moderate(request, address);
|
|
24
|
+
}
|
|
25
|
+
const who = await context.whoIs((_a = request.headers.get('authorization')) !== null && _a !== void 0 ? _a : '').catch(() => undefined);
|
|
26
|
+
if (!who) {
|
|
27
|
+
return json(401, { error: 'Sign in to an account first.' });
|
|
28
|
+
}
|
|
29
|
+
if (pathname !== relay_moderation_policy_1.RELAY_BIND_PATH) {
|
|
30
|
+
return context.moderate(request, address, who);
|
|
31
|
+
}
|
|
32
|
+
if (request.method !== 'POST') {
|
|
33
|
+
return json(405, { error: 'Not allowed.' });
|
|
34
|
+
}
|
|
35
|
+
const body = (await request.json().catch(() => ({})));
|
|
36
|
+
const host = typeof body.host === 'string' && relay_protocol_1.RELAY_ID.test(body.host) ? body.host : '';
|
|
37
|
+
const secret = typeof body.secret === 'string' ? body.secret : '';
|
|
38
|
+
if (!host || secret.length < 32 || !(await context.holds(host, secret))) {
|
|
39
|
+
return json(403, { error: 'Not the secret this computer holds its id with.' });
|
|
40
|
+
}
|
|
41
|
+
return context.moderate(new Request(`https://moderation${relay_moderation_1.RELAY_MODERATION_INTERNAL.bind}`, { method: 'POST', body: JSON.stringify({ host }) }), address, who);
|
|
42
|
+
}
|
|
43
|
+
RelayModerationDoor.handle = handle;
|
|
44
|
+
/** Whether a request came from the pages of the relay in a browser: its Origin one of the relay's. */
|
|
45
|
+
function browser(request, origins) {
|
|
46
|
+
const origin = request === null || request === void 0 ? void 0 : request.headers.get('origin');
|
|
47
|
+
return !!origin && origins.some(each => !!each && new URL(each).origin === origin);
|
|
48
|
+
}
|
|
49
|
+
RelayModerationDoor.browser = browser;
|
|
50
|
+
})(RelayModerationDoor || (exports.RelayModerationDoor = RelayModerationDoor = {}));
|
|
51
|
+
//# sourceMappingURL=relay-moderation-door.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the operator of a relay governs what people share through it (docs/design/ta-moderation.md): the rules that act
|
|
3
|
+
* by themselves, what needs an account, what a ban takes away, and the record of what was done and why.
|
|
4
|
+
*/
|
|
5
|
+
/** What of the relay reaches other people, and so may need an account and be taken away by a ban. */
|
|
6
|
+
export declare const RELAY_OUTWARD_FEATURES: readonly ['share', 'rooms', 'moments', 'nearby'];
|
|
7
|
+
export type RelayOutwardFeature = (typeof RELAY_OUTWARD_FEATURES)[number];
|
|
8
|
+
/** What the relay enforces itself today: a link opened in a browser, or a copy kept on it. The others need tickets (ta-moderation.md 9). */
|
|
9
|
+
export declare const RELAY_ENFORCED_FEATURES: readonly RelayOutwardFeature[];
|
|
10
|
+
/** The operator's settings. */
|
|
11
|
+
export interface RelayModerationPolicy {
|
|
12
|
+
/** The rules act by themselves; off until the operator turns them on. */
|
|
13
|
+
auto: boolean;
|
|
14
|
+
/** People who reported a link, for any reason, to stop it. */
|
|
15
|
+
people: number;
|
|
16
|
+
/** People who reported it for phishing or malware. */
|
|
17
|
+
severe: number;
|
|
18
|
+
/** Links of one person (or of one computer without an account) stopped, to limit them; 0: never. */
|
|
19
|
+
hostAfter: number;
|
|
20
|
+
/** Days a limit the rules set lasts: as far as they go by themselves. */
|
|
21
|
+
limitDays: number;
|
|
22
|
+
/** What needs the one who shares to have signed in to an account. */
|
|
23
|
+
needsAccount: RelayOutwardFeature[];
|
|
24
|
+
/** What a ban takes away; the user's own devices reaching each other never. */
|
|
25
|
+
banCovers: RelayOutwardFeature[];
|
|
26
|
+
}
|
|
27
|
+
export declare const RELAY_MODERATION_POLICY: RelayModerationPolicy;
|
|
28
|
+
/**
|
|
29
|
+
* What an account may not do for a while: `limit`, its links do not open for others (the rules go this far, for
|
|
30
|
+
* policy.limitDays); `ban`, nothing of policy.banCovers (the operator alone). None of `until`: until lifted.
|
|
31
|
+
*/
|
|
32
|
+
export interface RelaySanction {
|
|
33
|
+
account: string;
|
|
34
|
+
/** Its name where it signed in (a login of GitHub), as the operator reads it. */
|
|
35
|
+
name?: string;
|
|
36
|
+
level: 'limit' | 'ban';
|
|
37
|
+
at: number;
|
|
38
|
+
until?: number;
|
|
39
|
+
by: 'rule' | 'operator';
|
|
40
|
+
/** Why, in a few words: the rule, or what the operator wrote. */
|
|
41
|
+
reason: string;
|
|
42
|
+
}
|
|
43
|
+
/** A line of the record: who did what to what, and why. */
|
|
44
|
+
export interface RelayModerationEntry {
|
|
45
|
+
at: number;
|
|
46
|
+
by: 'rule' | 'operator' | 'user';
|
|
47
|
+
/** block, unblock, limit, ban, lift, dismiss, appeal, policy. */
|
|
48
|
+
action: string;
|
|
49
|
+
/** `share:<id>`, `host:<id>`, `account:<id>`, or `policy`. */
|
|
50
|
+
target: string;
|
|
51
|
+
reason?: string;
|
|
52
|
+
}
|
|
53
|
+
/** What one who was limited or banned asks of the operator. */
|
|
54
|
+
export interface RelayAppeal {
|
|
55
|
+
account: string;
|
|
56
|
+
name?: string;
|
|
57
|
+
at: number;
|
|
58
|
+
text: string;
|
|
59
|
+
}
|
|
60
|
+
/** What an account is told of itself (RELAY_STANDING_PATH). */
|
|
61
|
+
export interface RelayStanding {
|
|
62
|
+
sanction?: RelaySanction;
|
|
63
|
+
/** Links of it the operator or the rules stopped. */
|
|
64
|
+
blocked: string[];
|
|
65
|
+
appeal?: RelayAppeal;
|
|
66
|
+
}
|
|
67
|
+
/** Links its computer shares through an account, once proven (RELAY_BIND_PATH): who shares, when reported. */
|
|
68
|
+
export declare const RELAY_BIND_PATH = "/v1/bind";
|
|
69
|
+
/** An account reads how it stands, and appeals: `authorization: Bearer <its token>`. */
|
|
70
|
+
export declare const RELAY_STANDING_PATH = "/v1/standing";
|
|
71
|
+
export declare const RELAY_APPEAL_PATH = "/v1/appeal";
|
|
72
|
+
export declare namespace RelayModerationPolicyUtil {
|
|
73
|
+
/** As given, each value within what makes sense; the rules off unless `auto` is true. */
|
|
74
|
+
function of(given: Partial<RelayModerationPolicy> | undefined): RelayModerationPolicy;
|
|
75
|
+
function active(sanction: RelaySanction | undefined, now: number): sanction is RelaySanction;
|
|
76
|
+
/** Whether a sanction takes this feature away now. */
|
|
77
|
+
function takes(sanction: RelaySanction | undefined, feature: RelayOutwardFeature, policy: RelayModerationPolicy, now: number): boolean;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=relay-moderation-policy.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* How the operator of a relay governs what people share through it (docs/design/ta-moderation.md): the rules that act
|
|
4
|
+
* by themselves, what needs an account, what a ban takes away, and the record of what was done and why.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.RelayModerationPolicyUtil = exports.RELAY_APPEAL_PATH = exports.RELAY_STANDING_PATH = exports.RELAY_BIND_PATH = exports.RELAY_MODERATION_POLICY = exports.RELAY_ENFORCED_FEATURES = exports.RELAY_OUTWARD_FEATURES = void 0;
|
|
8
|
+
/** What of the relay reaches other people, and so may need an account and be taken away by a ban. */
|
|
9
|
+
exports.RELAY_OUTWARD_FEATURES = ['share', 'rooms', 'moments', 'nearby'];
|
|
10
|
+
/** What the relay enforces itself today: a link opened in a browser, or a copy kept on it. The others need tickets (ta-moderation.md 9). */
|
|
11
|
+
exports.RELAY_ENFORCED_FEATURES = ['share'];
|
|
12
|
+
exports.RELAY_MODERATION_POLICY = {
|
|
13
|
+
auto: false,
|
|
14
|
+
people: 3,
|
|
15
|
+
severe: 2,
|
|
16
|
+
hostAfter: 3,
|
|
17
|
+
limitDays: 7,
|
|
18
|
+
needsAccount: [],
|
|
19
|
+
banCovers: ['share', 'rooms', 'moments', 'nearby'],
|
|
20
|
+
};
|
|
21
|
+
/** Links its computer shares through an account, once proven (RELAY_BIND_PATH): who shares, when reported. */
|
|
22
|
+
exports.RELAY_BIND_PATH = '/v1/bind';
|
|
23
|
+
/** An account reads how it stands, and appeals: `authorization: Bearer <its token>`. */
|
|
24
|
+
exports.RELAY_STANDING_PATH = '/v1/standing';
|
|
25
|
+
exports.RELAY_APPEAL_PATH = '/v1/appeal';
|
|
26
|
+
var RelayModerationPolicyUtil;
|
|
27
|
+
(function (RelayModerationPolicyUtil) {
|
|
28
|
+
function count(value, fallback, min, max = 100) {
|
|
29
|
+
const n = Math.round(Number(value));
|
|
30
|
+
return Number.isFinite(n) && n >= min ? Math.min(n, max) : fallback;
|
|
31
|
+
}
|
|
32
|
+
function features(value, fallback) {
|
|
33
|
+
return Array.isArray(value) ? exports.RELAY_OUTWARD_FEATURES.filter(feature => value.includes(feature)) : fallback;
|
|
34
|
+
}
|
|
35
|
+
/** As given, each value within what makes sense; the rules off unless `auto` is true. */
|
|
36
|
+
function of(given) {
|
|
37
|
+
const base = exports.RELAY_MODERATION_POLICY;
|
|
38
|
+
return {
|
|
39
|
+
auto: (given === null || given === void 0 ? void 0 : given.auto) === true,
|
|
40
|
+
people: count(given === null || given === void 0 ? void 0 : given.people, base.people, 1),
|
|
41
|
+
severe: count(given === null || given === void 0 ? void 0 : given.severe, base.severe, 1),
|
|
42
|
+
hostAfter: count(given === null || given === void 0 ? void 0 : given.hostAfter, base.hostAfter, 0),
|
|
43
|
+
limitDays: count(given === null || given === void 0 ? void 0 : given.limitDays, base.limitDays, 1, 30),
|
|
44
|
+
needsAccount: features(given === null || given === void 0 ? void 0 : given.needsAccount, base.needsAccount),
|
|
45
|
+
banCovers: features(given === null || given === void 0 ? void 0 : given.banCovers, base.banCovers),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
RelayModerationPolicyUtil.of = of;
|
|
49
|
+
function active(sanction, now) {
|
|
50
|
+
return !!sanction && (sanction.until === undefined || sanction.until > now);
|
|
51
|
+
}
|
|
52
|
+
RelayModerationPolicyUtil.active = active;
|
|
53
|
+
/** Whether a sanction takes this feature away now. */
|
|
54
|
+
function takes(sanction, feature, policy, now) {
|
|
55
|
+
if (!active(sanction, now)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return sanction.level === 'limit' ? feature === 'share' : policy.banCovers.includes(feature);
|
|
59
|
+
}
|
|
60
|
+
RelayModerationPolicyUtil.takes = takes;
|
|
61
|
+
})(RelayModerationPolicyUtil || (exports.RelayModerationPolicyUtil = RelayModerationPolicyUtil = {}));
|
|
62
|
+
//# sourceMappingURL=relay-moderation-policy.js.map
|