@celljs/ta-relay 4.24.1 → 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,24 @@
|
|
|
1
|
+
import { type RelayAccountWho } from './relay-moderation.js';
|
|
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
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RELAY_MODERATION_INTERNAL, RELAY_MODERATION_PATH, RELAY_REPORT_PATH } from './relay-moderation.js';
|
|
2
|
+
import { RELAY_APPEAL_PATH, RELAY_BIND_PATH, RELAY_STANDING_PATH } from './relay-moderation-policy.js';
|
|
3
|
+
import { RELAY_ID } from './relay-protocol.js';
|
|
4
|
+
const json = (status, body) => new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json', 'cache-control': 'no-store' } });
|
|
5
|
+
/**
|
|
6
|
+
* The paths of moderation anyone reaches (docs/design/ta-moderation.md): the relay checks who calls before moderation
|
|
7
|
+
* reads them, the same in the Worker and in `ta relay`. Internal paths are never reached from outside.
|
|
8
|
+
*/
|
|
9
|
+
export var RelayModerationDoor;
|
|
10
|
+
(function (RelayModerationDoor) {
|
|
11
|
+
const PUBLIC = new Set([RELAY_REPORT_PATH, RELAY_MODERATION_PATH, RELAY_BIND_PATH, RELAY_STANDING_PATH, RELAY_APPEAL_PATH]);
|
|
12
|
+
function handles(pathname) {
|
|
13
|
+
return PUBLIC.has(pathname);
|
|
14
|
+
}
|
|
15
|
+
RelayModerationDoor.handles = handles;
|
|
16
|
+
async function handle(request, address, context) {
|
|
17
|
+
var _a;
|
|
18
|
+
const { pathname } = new URL(request.url);
|
|
19
|
+
if (pathname === RELAY_REPORT_PATH || pathname === RELAY_MODERATION_PATH) {
|
|
20
|
+
return context.moderate(request, address);
|
|
21
|
+
}
|
|
22
|
+
const who = await context.whoIs((_a = request.headers.get('authorization')) !== null && _a !== void 0 ? _a : '').catch(() => undefined);
|
|
23
|
+
if (!who) {
|
|
24
|
+
return json(401, { error: 'Sign in to an account first.' });
|
|
25
|
+
}
|
|
26
|
+
if (pathname !== RELAY_BIND_PATH) {
|
|
27
|
+
return context.moderate(request, address, who);
|
|
28
|
+
}
|
|
29
|
+
if (request.method !== 'POST') {
|
|
30
|
+
return json(405, { error: 'Not allowed.' });
|
|
31
|
+
}
|
|
32
|
+
const body = (await request.json().catch(() => ({})));
|
|
33
|
+
const host = typeof body.host === 'string' && RELAY_ID.test(body.host) ? body.host : '';
|
|
34
|
+
const secret = typeof body.secret === 'string' ? body.secret : '';
|
|
35
|
+
if (!host || secret.length < 32 || !(await context.holds(host, secret))) {
|
|
36
|
+
return json(403, { error: 'Not the secret this computer holds its id with.' });
|
|
37
|
+
}
|
|
38
|
+
return context.moderate(new Request(`https://moderation${RELAY_MODERATION_INTERNAL.bind}`, { method: 'POST', body: JSON.stringify({ host }) }), address, who);
|
|
39
|
+
}
|
|
40
|
+
RelayModerationDoor.handle = handle;
|
|
41
|
+
/** Whether a request came from the pages of the relay in a browser: its Origin one of the relay's. */
|
|
42
|
+
function browser(request, origins) {
|
|
43
|
+
const origin = request === null || request === void 0 ? void 0 : request.headers.get('origin');
|
|
44
|
+
return !!origin && origins.some(each => !!each && new URL(each).origin === origin);
|
|
45
|
+
}
|
|
46
|
+
RelayModerationDoor.browser = browser;
|
|
47
|
+
})(RelayModerationDoor || (RelayModerationDoor = {}));
|
|
48
|
+
//# sourceMappingURL=relay-moderation-door.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 const RELAY_OUTWARD_FEATURES = ['share', 'rooms', 'moments', 'nearby'];
|
|
7
|
+
/** 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). */
|
|
8
|
+
export const RELAY_ENFORCED_FEATURES = ['share'];
|
|
9
|
+
export const RELAY_MODERATION_POLICY = {
|
|
10
|
+
auto: false,
|
|
11
|
+
people: 3,
|
|
12
|
+
severe: 2,
|
|
13
|
+
hostAfter: 3,
|
|
14
|
+
limitDays: 7,
|
|
15
|
+
needsAccount: [],
|
|
16
|
+
banCovers: ['share', 'rooms', 'moments', 'nearby'],
|
|
17
|
+
};
|
|
18
|
+
/** Links its computer shares through an account, once proven (RELAY_BIND_PATH): who shares, when reported. */
|
|
19
|
+
export const RELAY_BIND_PATH = '/v1/bind';
|
|
20
|
+
/** An account reads how it stands, and appeals: `authorization: Bearer <its token>`. */
|
|
21
|
+
export const RELAY_STANDING_PATH = '/v1/standing';
|
|
22
|
+
export const RELAY_APPEAL_PATH = '/v1/appeal';
|
|
23
|
+
export var RelayModerationPolicyUtil;
|
|
24
|
+
(function (RelayModerationPolicyUtil) {
|
|
25
|
+
function count(value, fallback, min, max = 100) {
|
|
26
|
+
const n = Math.round(Number(value));
|
|
27
|
+
return Number.isFinite(n) && n >= min ? Math.min(n, max) : fallback;
|
|
28
|
+
}
|
|
29
|
+
function features(value, fallback) {
|
|
30
|
+
return Array.isArray(value) ? RELAY_OUTWARD_FEATURES.filter(feature => value.includes(feature)) : fallback;
|
|
31
|
+
}
|
|
32
|
+
/** As given, each value within what makes sense; the rules off unless `auto` is true. */
|
|
33
|
+
function of(given) {
|
|
34
|
+
const base = RELAY_MODERATION_POLICY;
|
|
35
|
+
return {
|
|
36
|
+
auto: (given === null || given === void 0 ? void 0 : given.auto) === true,
|
|
37
|
+
people: count(given === null || given === void 0 ? void 0 : given.people, base.people, 1),
|
|
38
|
+
severe: count(given === null || given === void 0 ? void 0 : given.severe, base.severe, 1),
|
|
39
|
+
hostAfter: count(given === null || given === void 0 ? void 0 : given.hostAfter, base.hostAfter, 0),
|
|
40
|
+
limitDays: count(given === null || given === void 0 ? void 0 : given.limitDays, base.limitDays, 1, 30),
|
|
41
|
+
needsAccount: features(given === null || given === void 0 ? void 0 : given.needsAccount, base.needsAccount),
|
|
42
|
+
banCovers: features(given === null || given === void 0 ? void 0 : given.banCovers, base.banCovers),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
RelayModerationPolicyUtil.of = of;
|
|
46
|
+
function active(sanction, now) {
|
|
47
|
+
return !!sanction && (sanction.until === undefined || sanction.until > now);
|
|
48
|
+
}
|
|
49
|
+
RelayModerationPolicyUtil.active = active;
|
|
50
|
+
/** Whether a sanction takes this feature away now. */
|
|
51
|
+
function takes(sanction, feature, policy, now) {
|
|
52
|
+
if (!active(sanction, now)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return sanction.level === 'limit' ? feature === 'share' : policy.banCovers.includes(feature);
|
|
56
|
+
}
|
|
57
|
+
RelayModerationPolicyUtil.takes = takes;
|
|
58
|
+
})(RelayModerationPolicyUtil || (RelayModerationPolicyUtil = {}));
|
|
59
|
+
//# sourceMappingURL=relay-moderation-policy.js.map
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { type RelayAppeal, type RelayModerationEntry, type RelayModerationPolicy, type RelaySanction, type RelayStanding } from './relay-moderation-policy.js';
|
|
2
|
+
/** Where anyone reports a link of content (the viewer's "Report"): POST, JSON of RelayReportInput. */
|
|
3
|
+
export declare const RELAY_REPORT_PATH = "/v1/report";
|
|
4
|
+
/** Where the operator of the relay reads the reports and blocks: `authorization: Bearer <TA_ADMIN_TOKEN>`. */
|
|
5
|
+
export declare const RELAY_MODERATION_PATH = "/v1/moderation";
|
|
6
|
+
/** Why a link is reported. */
|
|
7
|
+
export declare const RELAY_REPORT_REASONS: readonly ['phishing', 'malware', 'sexual', 'illegal', 'harassment', 'other'];
|
|
8
|
+
export type RelayReportReason = (typeof RELAY_REPORT_REASONS)[number];
|
|
9
|
+
/** What a report names: the host and the share of the link (never its key, which stays in the fragment). */
|
|
10
|
+
export interface RelayReportInput {
|
|
11
|
+
host: string;
|
|
12
|
+
share: string;
|
|
13
|
+
reason: RelayReportReason;
|
|
14
|
+
note?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The link itself, its key with it, when the one who reports chose to send it: the operator then sees what is
|
|
17
|
+
* reported, as nobody else on the relay can. Only a link of this host and share.
|
|
18
|
+
*/
|
|
19
|
+
link?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface RelayReport extends RelayReportInput {
|
|
22
|
+
/** When it was first and last reported, and how many times. */
|
|
23
|
+
at: number;
|
|
24
|
+
last: number;
|
|
25
|
+
count: number;
|
|
26
|
+
/** How many people reported it (by the addresses they came from), and of them for phishing or malware. */
|
|
27
|
+
people?: number;
|
|
28
|
+
severe?: number;
|
|
29
|
+
}
|
|
30
|
+
/** Reasons a few reports are enough for (RelayModerationPolicy.severe). */
|
|
31
|
+
export declare const RELAY_SEVERE_REASONS: readonly RelayReportReason[];
|
|
32
|
+
/** A block the relay made by itself: when, and by which rule. */
|
|
33
|
+
export interface RelayAutoBlock {
|
|
34
|
+
at: number;
|
|
35
|
+
rule: 'people' | 'severe' | 'host';
|
|
36
|
+
/** The people, or the links blocked, that made it. */
|
|
37
|
+
count: number;
|
|
38
|
+
}
|
|
39
|
+
/** What the operator blocked: every link of a host (shown through the domain of content), or one share. */
|
|
40
|
+
export interface RelayBlocks {
|
|
41
|
+
hosts: string[];
|
|
42
|
+
shares: string[];
|
|
43
|
+
/** Those the rules blocked, by `share:<id>` or `host:<id>`. */
|
|
44
|
+
auto?: Record<string, RelayAutoBlock>;
|
|
45
|
+
/** What the operator unblocked after the rules blocked it: never blocked by them again (`share:<id>`, `host:<id>`). */
|
|
46
|
+
pardoned?: string[];
|
|
47
|
+
}
|
|
48
|
+
export type RelayModerationAction = {
|
|
49
|
+
action: 'block' | 'unblock';
|
|
50
|
+
host?: string;
|
|
51
|
+
share?: string;
|
|
52
|
+
} | {
|
|
53
|
+
action: 'dismiss';
|
|
54
|
+
share: string;
|
|
55
|
+
} | {
|
|
56
|
+
action: 'policy';
|
|
57
|
+
policy: Partial<RelayModerationPolicy>;
|
|
58
|
+
} | {
|
|
59
|
+
action: 'limit' | 'ban';
|
|
60
|
+
account: string;
|
|
61
|
+
days?: number;
|
|
62
|
+
reason?: string;
|
|
63
|
+
} | {
|
|
64
|
+
action: 'lift';
|
|
65
|
+
account: string;
|
|
66
|
+
reason?: string;
|
|
67
|
+
} | {
|
|
68
|
+
action: 'answer';
|
|
69
|
+
account: string;
|
|
70
|
+
restore: boolean;
|
|
71
|
+
};
|
|
72
|
+
/** An account, as the relay checked its token. */
|
|
73
|
+
export interface RelayAccountWho {
|
|
74
|
+
id: string;
|
|
75
|
+
name?: string;
|
|
76
|
+
}
|
|
77
|
+
/** Who shares through a computer, once its Ta proved both (RELAY_BIND_PATH). */
|
|
78
|
+
interface Owner {
|
|
79
|
+
account: string;
|
|
80
|
+
name?: string;
|
|
81
|
+
at: number;
|
|
82
|
+
}
|
|
83
|
+
/** Internal paths, reached only from the Worker or `ta relay` once they checked the caller (RelayModerationDoor). */
|
|
84
|
+
export declare const RELAY_MODERATION_INTERNAL: {
|
|
85
|
+
readonly bind: '/bind';
|
|
86
|
+
readonly blocks: '/blocks';
|
|
87
|
+
readonly viewer: '/viewer';
|
|
88
|
+
readonly copy: '/copy';
|
|
89
|
+
readonly policy: '/policy';
|
|
90
|
+
};
|
|
91
|
+
/** Where reports and blocks are kept: the storage of one Durable Object, or of `ta relay`. */
|
|
92
|
+
export interface RelayModerationStorage {
|
|
93
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
94
|
+
put(key: string, value: unknown): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
/** A report as it is kept: the hashes of the addresses it came from, never shown. */
|
|
97
|
+
interface KeptReport extends RelayReport {
|
|
98
|
+
from?: string[];
|
|
99
|
+
fromSevere?: string[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Reports of links of content and what the operator blocked (docs/design/ta-link.md 2.10). The relay cannot read what is
|
|
103
|
+
* shared, so it can only take reports, and stop handing on what its operator blocked: the copy of a share on the relay,
|
|
104
|
+
* and every link of a host through the domain of content. Runs the same in a Durable Object and in `ta relay`.
|
|
105
|
+
*/
|
|
106
|
+
export declare class RelayModeration {
|
|
107
|
+
protected readonly storage: RelayModerationStorage;
|
|
108
|
+
protected readonly now: () => number;
|
|
109
|
+
constructor(storage: RelayModerationStorage, now?: () => number);
|
|
110
|
+
/**
|
|
111
|
+
* POST RELAY_REPORT_PATH from anyone, `address` counted for its limit; GET and POST RELAY_MODERATION_PATH with
|
|
112
|
+
* `adminToken` (none: the operator set none, and they are not there).
|
|
113
|
+
*/
|
|
114
|
+
handle(request: Request, address: string, adminToken?: string, who?: RelayAccountWho): Promise<Response>;
|
|
115
|
+
/** Whether the operator blocked this host or this share. */
|
|
116
|
+
blocked(host?: string, share?: string): Promise<boolean>;
|
|
117
|
+
reports(): Promise<RelayReport[]>;
|
|
118
|
+
protected kept(): Promise<KeptReport[]>;
|
|
119
|
+
blocks(): Promise<RelayBlocks>;
|
|
120
|
+
policy(): Promise<RelayModerationPolicy>;
|
|
121
|
+
sanctions(): Promise<Record<string, RelaySanction>>;
|
|
122
|
+
appeals(): Promise<RelayAppeal[]>;
|
|
123
|
+
log(): Promise<RelayModerationEntry[]>;
|
|
124
|
+
protected record(entry: Omit<RelayModerationEntry, 'at'>): Promise<void>;
|
|
125
|
+
owner(host: string): Promise<Owner | undefined>;
|
|
126
|
+
/** What the operator reads: the reports, blocks, sanctions, appeals, the record, and who shares through each computer reported. */
|
|
127
|
+
state(): Promise<{
|
|
128
|
+
reports: RelayReport[];
|
|
129
|
+
blocks: RelayBlocks;
|
|
130
|
+
policy: RelayModerationPolicy;
|
|
131
|
+
sanctions: Record<string, RelaySanction>;
|
|
132
|
+
appeals: RelayAppeal[];
|
|
133
|
+
log: RelayModerationEntry[];
|
|
134
|
+
owners: Record<string, Owner>;
|
|
135
|
+
}>;
|
|
136
|
+
/** How an account stands, for itself. */
|
|
137
|
+
standing(account: string): Promise<RelayStanding>;
|
|
138
|
+
protected appeal(who: RelayAccountWho, text: string): Promise<RelayStanding>;
|
|
139
|
+
/** The paths only the Worker or `ta relay` reach, the caller checked. */
|
|
140
|
+
protected internal(request: Request, url: URL, who: RelayAccountWho | undefined): Promise<Response | undefined>;
|
|
141
|
+
/** A computer shares through this account from now on: its reports count for it. */
|
|
142
|
+
bind(host: string, who: RelayAccountWho): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Why a link of this computer does not open: blocked by the operator or the rules; and in a browser (the pages of the
|
|
145
|
+
* relay, `browser`), shared by no account where the policy needs one, or by one limited or banned. `who`: the account
|
|
146
|
+
* a copy is put by, in place of the owner of the computer.
|
|
147
|
+
*/
|
|
148
|
+
viewer(host: string, browser: boolean, who?: RelayAccountWho): Promise<number | undefined>;
|
|
149
|
+
apply(action: RelayModerationAction | undefined): Promise<RelayBlocks>;
|
|
150
|
+
/** Limits, bans, or lifts what an account may do; answers its appeal. What the operator lifts of the rules' they leave be. */
|
|
151
|
+
protected sanction(action: Extract<RelayModerationAction, {
|
|
152
|
+
account: string;
|
|
153
|
+
}>): Promise<void>;
|
|
154
|
+
/** What the rules block after a report of this link: the link, then perhaps its computer. */
|
|
155
|
+
protected enforce(report: KeptReport, reports: readonly KeptReport[]): Promise<void>;
|
|
156
|
+
protected report(request: Request, address: string): Promise<Response>;
|
|
157
|
+
static parse(value: unknown): RelayReportInput | undefined;
|
|
158
|
+
/** A link of content of this host and share, as sent with a report; undefined for anything else. */
|
|
159
|
+
static linkOf(value: unknown, host: string, share: string): string | undefined;
|
|
160
|
+
static answer(status: number, body: unknown): Response;
|
|
161
|
+
/** Compares by their SHA-256, so that the time it takes says nothing of the token. */
|
|
162
|
+
static same(given: string, expected: string): Promise<boolean>;
|
|
163
|
+
static digest(text: string): Promise<string>;
|
|
164
|
+
}
|
|
165
|
+
export {};
|