@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
package/README.en.md
CHANGED
|
@@ -48,7 +48,7 @@ A Ta service can also hand an extension of its computer to another through the r
|
|
|
48
48
|
## Deploying Relay
|
|
49
49
|
|
|
50
50
|
- Cloudflare Workers: [apps/ta-relay](../../apps/ta-relay/README.md) (Durable Objects, sleep when idle).
|
|
51
|
-
- Your own machine: `ta relay [--host 0.0.0.0] [--port 8080] [--data <dir>]`, behind an HTTPS reverse proxy. With `--data`,
|
|
51
|
+
- Your own machine: `ta relay [--host 0.0.0.0] [--port 8080] [--data <dir>]`, behind an HTTPS reverse proxy. With `--data`, group chats, offline copies and which host holds which ID are kept on disk across restarts; without it they live in memory, and after a restart the first host to connect reclaims its ID.
|
|
52
52
|
|
|
53
53
|
## A relay of your own (relays.json)
|
|
54
54
|
|
|
@@ -66,10 +66,10 @@ Which relay each feature uses is set by `relays.json` in the agent directory (de
|
|
|
66
66
|
|
|
67
67
|
- `cellbang` is the official relay `https://relay.cellbang.com`, there without being written.
|
|
68
68
|
- A service may also be a folder of a cloud drive: `{ "type": "folder", "path": "~/Library/Mobile Documents/com~apple~CloudDocs/Ta" }`, for `sync` alone (sync goes through the folder, no relay; see the README of @celljs/ta-sync).
|
|
69
|
-
- Features of `use`: `devices` (devices paired from now on; also `ta pair` without an address), `share` (links of extensions and content, their offline copies, the pages links open in), `rooms` (new
|
|
70
|
-
- Only what is made from now on: each device, share and
|
|
69
|
+
- Features of `use`: `devices` (devices paired from now on; also `ta pair` without an address), `share` (links of extensions and content, their offline copies, the pages links open in), `rooms` (new group chats; the group chats of extensions too), `sync` (the group chat of sync; as `rooms` when not named). Those not named take `default`.
|
|
70
|
+
- Only what is made from now on: each device, share and group chat keeps the relay it is on (`devices[].relay`, `shares[].relay`, `contents[].relay` of `relay.json`, `relay` of `rooms.json`) whatever the configuration says later. `ta serve` connects to every relay that still has a device or a share, one connection each; a device is known only through the relay it was paired on.
|
|
71
71
|
- Capabilities: a relay answers `GET /v1/info` (`{ v, capabilities, limits, persistent }`, readable from any origin). A relay of before, without it, is taken as one with every capability and the limits of then.
|
|
72
|
-
- Running your own: `ta relay --data <dir>` keeps
|
|
72
|
+
- Running your own: `ta relay --data <dir>` keeps group chats, offline copies and which host holds which id on disk, across restarts; without `--data` they live in memory.
|
|
73
73
|
|
|
74
74
|
## Known Limitations
|
|
75
75
|
|
|
@@ -84,9 +84,9 @@ Which relay each feature uses is set by `relays.json` in the agent directory (de
|
|
|
84
84
|
|
|
85
85
|
`/s` is the viewer for a browser (`src/viewer/`, built by `scripts/build-viewer.ts` into `viewer/page.html`, its script allowed by its hash), which decrypts on the page; a shared HTML page runs in the sandboxed frame of `/s/frame` (no `allow-same-origin`, no `connect-src`). Design notes: [docs/design/ta-link.md](../../docs/design/ta-link.md).
|
|
86
86
|
|
|
87
|
-
##
|
|
87
|
+
## Group chats (`/v1/hub/<room>`)
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
Group chats several Ta share ([docs/design/ta-link.md](../../docs/design/ta-link.md), section 3): `RelayHub` keeps on the relay the hashes of the members' tokens, the asks to join till the owner answers, the roster signed by the owner and the shared state, all sealed; it passes messages between members and sets the state on its version. On the Worker each group chat is a Durable Object (`RelayHubObject`); in `ta relay`, memory. On the side of Ta, `RelayHubs` (its identity in `identity.json`, group chats in `rooms.json`, friends in `friends.json`): making a group chat, links that invite (`/r#…`, `RelayHubUtil`), asks and the owner's answers (the key of the group chat sealed by ECDH and signed), and the signatures and sealing of messages and the state. `RelayHubs` is in `common/`, its store its own: `RelayHubFiles` for Ta, localStorage in a browser. A link that invites opens the page of web guests in a browser (`src/guest` → `viewer/room.html`, its script allowed by its hash, connecting to this relay alone): one without Ta asks there and, let in, only chats (`RelayRoomChat`); the Ta of the others take no other state it sets and none of its messages.
|
|
90
90
|
|
|
91
91
|
## Joining another's Ta from a browser (`/j`, `/w/`)
|
|
92
92
|
|
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ Ta 服务也能经中继把本机的一个扩展交给另一台电脑(`RelaySt
|
|
|
48
48
|
## 部署 Relay
|
|
49
49
|
|
|
50
50
|
- Cloudflare Workers:[apps/ta-relay](../../apps/ta-relay/README.md)(Durable Objects,空闲时休眠)。
|
|
51
|
-
- 自己的机器:`ta relay [--host 0.0.0.0] [--port 8080] [--data <目录>]`,放在 HTTPS 反向代理后面。带 `--data`
|
|
51
|
+
- 自己的机器:`ta relay [--host 0.0.0.0] [--port 8080] [--data <目录>]`,放在 HTTPS 反向代理后面。带 `--data` 时群聊、离线副本和主机 id 的归属存到磁盘,重启不丢;不带时只在内存里,重启后由先连上来的主机重新认领。
|
|
52
52
|
|
|
53
53
|
## 换用自己的中继(relays.json)
|
|
54
54
|
|
|
@@ -66,10 +66,10 @@ Ta 服务也能经中继把本机的一个扩展交给另一台电脑(`RelaySt
|
|
|
66
66
|
|
|
67
67
|
- `cellbang` 是官方中继 `https://relay.cellbang.com`,不写也在。
|
|
68
68
|
- 服务也可以是网盘里的文件夹:`{ "type": "folder", "path": "~/Library/Mobile Documents/com~apple~CloudDocs/Ta" }`,只能用于 `sync`(设备同步经文件夹进行,不经过中继,见 @celljs/ta-sync 的 README)。
|
|
69
|
-
- `use` 的功能:`devices`(新配对的设备,`ta pair` 不带地址时也用它)、`share`(分享扩展与内容的链接、离线副本、链接打开的网页)、`rooms
|
|
70
|
-
-
|
|
69
|
+
- `use` 的功能:`devices`(新配对的设备,`ta pair` 不带地址时也用它)、`share`(分享扩展与内容的链接、离线副本、链接打开的网页)、`rooms`(新建群聊;扩展自己的群聊也按它)、`sync`(设备同步的群聊,不写时跟 `rooms`)。没写的用 `default`。
|
|
70
|
+
- 只影响新建的东西:每台设备、每个分享、每个群聊都记着自己所在的中继(`relay.json` 的 `devices[].relay`、`shares[].relay`、`contents[].relay`,`rooms.json` 的 `relay`),换了配置也留在原来的中继上。`ta serve` 连到所有还有设备或分享的中继,每个中继一条连接;设备只认它配对时的那个中继。
|
|
71
71
|
- 能力探测:中继回答 `GET /v1/info`(`{ v, capabilities, limits, persistent }`,允许跨域)。没有这个接口的旧中继按全部能力、当时的上限处理。
|
|
72
|
-
- 自己运行:`ta relay --data <目录>`
|
|
72
|
+
- 自己运行:`ta relay --data <目录>` 把群聊、离线副本和主机 id 的归属存到磁盘,重启后不丢;不带 `--data` 时只在内存里。
|
|
73
73
|
|
|
74
74
|
## 已知限制
|
|
75
75
|
|
|
@@ -84,9 +84,9 @@ Ta 服务也能经中继把本机的一个扩展交给另一台电脑(`RelaySt
|
|
|
84
84
|
|
|
85
85
|
`/s` 是浏览器里的查看页(`src/viewer/`,`scripts/build-viewer.ts` 打成 `viewer/page.html`,脚本按哈希放行),在页面里解密后显示;分享的 HTML 放进 `/s/frame` 的沙箱 iframe(无 `allow-same-origin`,禁止 `connect-src`)。设计记录见 [docs/design/ta-link.md](../../docs/design/ta-link.md)。
|
|
86
86
|
|
|
87
|
-
##
|
|
87
|
+
## 群聊(`/v1/hub/<群聊>`)
|
|
88
88
|
|
|
89
|
-
几台 Ta
|
|
89
|
+
几台 Ta 共用的群聊([docs/design/ta-link.md](../../docs/design/ta-link.md) 第 3 节):`RelayHub` 在中继上保存成员令牌的哈希、未处理的加入申请、群主签名的成员名单和共享状态(都是密文),转发成员之间的消息,按版本号写入状态;Worker 上每个群聊一个 Durable Object(`RelayHubObject`),`ta relay` 里在内存。Ta 一侧是 `RelayHubs`(身份 `identity.json`、群聊 `rooms.json`、好友 `friends.json`):建群、邀请链接(`/r#…`,`RelayHubUtil`)、申请与群主答复(ECDH 加密群聊密钥并签名)、消息与状态的签名和加密。`RelayHubs` 在 `common/`,存储可换:Ta 用 `RelayHubFiles`,浏览器用 localStorage。邀请链接在浏览器里打开的是网页访客页(`src/guest` → `viewer/room.html`,脚本按哈希放行,只连本中继):没装 Ta 的人在网页里申请,群主同意后只能聊天(`RelayRoomChat`),其他成员的 Ta 不采用访客写的其他状态和发的消息。
|
|
90
90
|
|
|
91
91
|
## 从浏览器加入别人的 Ta(`/j`、`/w/`)
|
|
92
92
|
|
package/esm/common/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './relay-card.js';
|
|
|
8
8
|
export * from './relay-chat-store.js';
|
|
9
9
|
export * from './relay-cipher.js';
|
|
10
10
|
export * from './relay-content.js';
|
|
11
|
+
export * from './relay-content-origin.js';
|
|
11
12
|
export * from './relay-conversation.js';
|
|
12
13
|
export * from './relay-faces.js';
|
|
13
14
|
export * from './relay-files.js';
|
|
@@ -23,6 +24,10 @@ export * from './relay-hubs-protocol.js';
|
|
|
23
24
|
export * from './relay-hubs-util.js';
|
|
24
25
|
export * from './relay-identity.js';
|
|
25
26
|
export * from './relay-info.js';
|
|
27
|
+
export * from './relay-moderation.js';
|
|
28
|
+
export * from './relay-moderation-client.js';
|
|
29
|
+
export * from './relay-moderation-door.js';
|
|
30
|
+
export * from './relay-moderation-policy.js';
|
|
26
31
|
export * from './relay-pairing.js';
|
|
27
32
|
export * from './relay-protocol.js';
|
|
28
33
|
export * from './relay-room.js';
|
package/esm/common/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from './relay-card.js';
|
|
|
8
8
|
export * from './relay-chat-store.js';
|
|
9
9
|
export * from './relay-cipher.js';
|
|
10
10
|
export * from './relay-content.js';
|
|
11
|
+
export * from './relay-content-origin.js';
|
|
11
12
|
export * from './relay-conversation.js';
|
|
12
13
|
export * from './relay-faces.js';
|
|
13
14
|
export * from './relay-files.js';
|
|
@@ -23,6 +24,10 @@ export * from './relay-hubs-protocol.js';
|
|
|
23
24
|
export * from './relay-hubs-util.js';
|
|
24
25
|
export * from './relay-identity.js';
|
|
25
26
|
export * from './relay-info.js';
|
|
27
|
+
export * from './relay-moderation.js';
|
|
28
|
+
export * from './relay-moderation-client.js';
|
|
29
|
+
export * from './relay-moderation-door.js';
|
|
30
|
+
export * from './relay-moderation-policy.js';
|
|
26
31
|
export * from './relay-pairing.js';
|
|
27
32
|
export * from './relay-protocol.js';
|
|
28
33
|
export * from './relay-room.js';
|
|
@@ -92,6 +92,8 @@ export declare class RelayAccounts {
|
|
|
92
92
|
handle(request: Request): Promise<Response>;
|
|
93
93
|
protected provider(id: unknown): RelayAccountProvider;
|
|
94
94
|
protected poll(id: unknown, handle: unknown): Promise<AccountSignInPoll>;
|
|
95
|
+
/** The account of a bearer token, checked as a call checks it; undefined for one no longer of an account. */
|
|
96
|
+
whoIs(authorization: string): Promise<AccountName | undefined>;
|
|
95
97
|
protected call(authorization: string, op: unknown, args: unknown): Promise<unknown>;
|
|
96
98
|
}
|
|
97
99
|
/** The books of a `ta relay` or a gateway, in one process: the requests of one account one after another. */
|
|
@@ -339,6 +339,27 @@ export class RelayAccounts {
|
|
|
339
339
|
await this.options.book(signedIn.id).handle({ op: 'issue', account: signedIn, hash: await RelayKeys.hash(token) });
|
|
340
340
|
return { status: 'done', token, account: signedIn };
|
|
341
341
|
}
|
|
342
|
+
/** The account of a bearer token, checked as a call checks it; undefined for one no longer of an account. */
|
|
343
|
+
async whoIs(authorization) {
|
|
344
|
+
const token = authorization.replace(/^Bearer\s+/i, '');
|
|
345
|
+
if (!token) {
|
|
346
|
+
return undefined;
|
|
347
|
+
}
|
|
348
|
+
if (this.options.authenticate) {
|
|
349
|
+
return this.options.authenticate(token);
|
|
350
|
+
}
|
|
351
|
+
const account = RelayAccounts.accountOf(token);
|
|
352
|
+
if (!account) {
|
|
353
|
+
return undefined;
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
const roster = (await this.options.book(account).handle({ op: 'roster', args: [], hash: await RelayKeys.hash(token) }));
|
|
357
|
+
return roster.account;
|
|
358
|
+
}
|
|
359
|
+
catch (_a) {
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
342
363
|
async call(authorization, op, args) {
|
|
343
364
|
const token = authorization.replace(/^Bearer\s+/i, '');
|
|
344
365
|
if (!ACCOUNT_CALLS.includes(op)) {
|
|
@@ -81,6 +81,8 @@ export declare namespace RelayBlobClient {
|
|
|
81
81
|
authHash: string;
|
|
82
82
|
expiresAt: number;
|
|
83
83
|
bytes: Uint8Array;
|
|
84
|
+
/** The token of the account it is put by, where the relay needs one of public links (RelayInfo.needsAccount). */
|
|
85
|
+
account?: string;
|
|
84
86
|
}
|
|
85
87
|
function put(copy: Copy): Promise<void>;
|
|
86
88
|
function remove(relay: string, share: string, token: string): Promise<void>;
|
|
@@ -164,6 +164,7 @@ export var RelayBlobClient;
|
|
|
164
164
|
authorization: `Bearer ${copy.token}`,
|
|
165
165
|
'x-ta-auth-hash': copy.authHash,
|
|
166
166
|
'x-ta-expires': String(copy.expiresAt),
|
|
167
|
+
...(copy.account ? { 'x-ta-account': copy.account } : {}),
|
|
167
168
|
'content-type': 'application/octet-stream',
|
|
168
169
|
},
|
|
169
170
|
body: copy.bytes,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type RelayInfo } from './relay-info.js';
|
|
2
|
+
/** What a relay does with a request, by the domain it came to (RelayContentOrigin.route). */
|
|
3
|
+
export type RelayContentRoute =
|
|
4
|
+
/** Answer it as always. */
|
|
5
|
+
{
|
|
6
|
+
kind: 'serve';
|
|
7
|
+
}
|
|
8
|
+
/** A link of content on the relay's own domain: the same link on the domain of content (the fragment stays, as browsers keep it). */
|
|
9
|
+
| {
|
|
10
|
+
kind: 'redirect';
|
|
11
|
+
location: string;
|
|
12
|
+
}
|
|
13
|
+
/** Not here: 404. */
|
|
14
|
+
| {
|
|
15
|
+
kind: 'refuse';
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The domain of content (RelayInfo.content, `TA_CONTENT_ORIGIN`): another domain of the same relay, where links of
|
|
19
|
+
* content open, so that what users share never shows on the relay's own domain (docs/design/ta-link.md 2.10). It
|
|
20
|
+
* answers only what a viewer needs: the pages of a link, the connection to the host that shared it, its copy, the
|
|
21
|
+
* report; the relay's own domain sends links of content there.
|
|
22
|
+
*/
|
|
23
|
+
export declare namespace RelayContentOrigin {
|
|
24
|
+
/** Whether the request came to the domain of content. */
|
|
25
|
+
function isContent(url: URL, content: string | undefined): boolean;
|
|
26
|
+
/** `content` none: the relay has no domain of content, and serves all on its own. */
|
|
27
|
+
function route(url: URL, content: string | undefined): RelayContentRoute;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Where links of content of each relay open, as the relay says (RelayInfo.content), asked again an hour later: its domain
|
|
31
|
+
* of content, else its own (also while it does not answer: the link still works, and it is sent on once there is one).
|
|
32
|
+
*/
|
|
33
|
+
export declare class RelayContentOrigins {
|
|
34
|
+
protected readonly probe: (relay: string) => Promise<RelayInfo | undefined>;
|
|
35
|
+
protected readonly known: Map<string, {
|
|
36
|
+
at: number;
|
|
37
|
+
info: Promise<RelayInfo | undefined>;
|
|
38
|
+
}>;
|
|
39
|
+
constructor(probe?: (relay: string) => Promise<RelayInfo | undefined>);
|
|
40
|
+
protected info(relay: string, now: number): Promise<RelayInfo | undefined>;
|
|
41
|
+
of(relay: string, now?: number): Promise<string | undefined>;
|
|
42
|
+
/** Whether the relay needs the one who shares a public link to have signed in to an account (RelayInfo.needsAccount). */
|
|
43
|
+
needsAccount(relay: string, now?: number): Promise<boolean>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { RELAY_INFO_PATH, RelayInfoUtil } from './relay-info.js';
|
|
2
|
+
import { RELAY_REPORT_PATH } from './relay-moderation.js';
|
|
3
|
+
import { RELAY_BLOB_PATH, RELAY_CONNECT_PATH, RELAY_CONTENT_PATH, RELAY_FRAME_PATH } from './relay-protocol.js';
|
|
4
|
+
import { RELAY_WEB_PATH } from './relay-team.js';
|
|
5
|
+
/**
|
|
6
|
+
* The domain of content (RelayInfo.content, `TA_CONTENT_ORIGIN`): another domain of the same relay, where links of
|
|
7
|
+
* content open, so that what users share never shows on the relay's own domain (docs/design/ta-link.md 2.10). It
|
|
8
|
+
* answers only what a viewer needs: the pages of a link, the connection to the host that shared it, its copy, the
|
|
9
|
+
* report; the relay's own domain sends links of content there.
|
|
10
|
+
*/
|
|
11
|
+
export var RelayContentOrigin;
|
|
12
|
+
(function (RelayContentOrigin) {
|
|
13
|
+
const PAGES = new Set([RELAY_CONTENT_PATH, RELAY_FRAME_PATH, RELAY_INFO_PATH, RELAY_REPORT_PATH, '/healthz', '/readyz']);
|
|
14
|
+
const PREFIXES = [RELAY_CONNECT_PATH, RELAY_BLOB_PATH, RELAY_WEB_PATH];
|
|
15
|
+
/** Whether the request came to the domain of content. */
|
|
16
|
+
function isContent(url, content) {
|
|
17
|
+
return !!content && url.host === new URL(content).host;
|
|
18
|
+
}
|
|
19
|
+
RelayContentOrigin.isContent = isContent;
|
|
20
|
+
/** `content` none: the relay has no domain of content, and serves all on its own. */
|
|
21
|
+
function route(url, content) {
|
|
22
|
+
if (!content) {
|
|
23
|
+
return { kind: 'serve' };
|
|
24
|
+
}
|
|
25
|
+
const path = url.pathname;
|
|
26
|
+
if (isContent(url, content)) {
|
|
27
|
+
return PAGES.has(path) || PREFIXES.some(prefix => path.startsWith(prefix)) || path === RELAY_WEB_PATH.slice(0, -1)
|
|
28
|
+
? { kind: 'serve' }
|
|
29
|
+
: { kind: 'refuse' };
|
|
30
|
+
}
|
|
31
|
+
if (path === RELAY_CONTENT_PATH) {
|
|
32
|
+
return { kind: 'redirect', location: `${content}${RELAY_CONTENT_PATH}${url.search}` };
|
|
33
|
+
}
|
|
34
|
+
// A page of a user framed under the relay's own domain: never.
|
|
35
|
+
return path === RELAY_FRAME_PATH ? { kind: 'refuse' } : { kind: 'serve' };
|
|
36
|
+
}
|
|
37
|
+
RelayContentOrigin.route = route;
|
|
38
|
+
})(RelayContentOrigin || (RelayContentOrigin = {}));
|
|
39
|
+
/**
|
|
40
|
+
* Where links of content of each relay open, as the relay says (RelayInfo.content), asked again an hour later: its domain
|
|
41
|
+
* of content, else its own (also while it does not answer: the link still works, and it is sent on once there is one).
|
|
42
|
+
*/
|
|
43
|
+
export class RelayContentOrigins {
|
|
44
|
+
constructor(probe = relay => RelayInfoUtil.probe(relay, 3000).then(found => found.info)) {
|
|
45
|
+
this.probe = probe;
|
|
46
|
+
this.known = new Map();
|
|
47
|
+
}
|
|
48
|
+
info(relay, now) {
|
|
49
|
+
const known = this.known.get(relay);
|
|
50
|
+
if (known && now - known.at < 60 * 60 * 1000) {
|
|
51
|
+
return known.info;
|
|
52
|
+
}
|
|
53
|
+
const info = this.probe(relay).catch(() => undefined);
|
|
54
|
+
this.known.set(relay, { at: now, info });
|
|
55
|
+
return info;
|
|
56
|
+
}
|
|
57
|
+
async of(relay, now = Date.now()) {
|
|
58
|
+
var _a;
|
|
59
|
+
return (_a = (await this.info(relay, now))) === null || _a === void 0 ? void 0 : _a.content;
|
|
60
|
+
}
|
|
61
|
+
/** Whether the relay needs the one who shares a public link to have signed in to an account (RelayInfo.needsAccount). */
|
|
62
|
+
async needsAccount(relay, now = Date.now()) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
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'));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# 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.
|
|
@@ -12,6 +12,7 @@ export class RelayContentError extends Error {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
const PBKDF2_ITERATIONS = 600000;
|
|
15
|
+
const BLOCKED_MESSAGE = 'The operator of the relay blocked this link after a report.';
|
|
15
16
|
/** Kinds the links of before carry no `c` for. */
|
|
16
17
|
const PLAIN_KINDS = new Set(['ta-conversation', 'file']);
|
|
17
18
|
const KIND = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
@@ -27,7 +28,7 @@ export var RelayContentUtil;
|
|
|
27
28
|
* `c=<kind>` for what is no conversation or file.
|
|
28
29
|
*/
|
|
29
30
|
function link(content) {
|
|
30
|
-
var _a;
|
|
31
|
+
var _a, _b;
|
|
31
32
|
const fragment = new URLSearchParams({ v: '1', h: content.host, s: content.share });
|
|
32
33
|
if (content.access === 'self') {
|
|
33
34
|
fragment.set('m', 'self');
|
|
@@ -48,7 +49,7 @@ export var RelayContentUtil;
|
|
|
48
49
|
if (content.kind && !PLAIN_KINDS.has(content.kind) && KIND.test(content.kind)) {
|
|
49
50
|
fragment.set('c', content.kind);
|
|
50
51
|
}
|
|
51
|
-
return `${content.relay}${RELAY_CONTENT_PATH}#${fragment}`;
|
|
52
|
+
return `${(_b = content.page) !== null && _b !== void 0 ? _b : content.relay}${RELAY_CONTENT_PATH}#${fragment}`;
|
|
52
53
|
}
|
|
53
54
|
RelayContentUtil.link = link;
|
|
54
55
|
function is(text) {
|
|
@@ -200,6 +201,9 @@ export var RelayContentUtil;
|
|
|
200
201
|
? new RelayContentError('wrong', 'The password is wrong.')
|
|
201
202
|
: new RelayContentError('gone', 'This link no longer works.');
|
|
202
203
|
}
|
|
204
|
+
if (response.status === 410 || response.status === 451) {
|
|
205
|
+
throw new RelayContentError('gone', BLOCKED_MESSAGE);
|
|
206
|
+
}
|
|
203
207
|
if (response.status === 429) {
|
|
204
208
|
throw new RelayContentError('busy', 'Too many wrong passwords: try again in a few minutes.');
|
|
205
209
|
}
|
|
@@ -298,6 +302,12 @@ export var RelayContentUtil;
|
|
|
298
302
|
}
|
|
299
303
|
return new RelayContentError('gone', 'This link no longer works: the share was stopped or ran out.');
|
|
300
304
|
}
|
|
305
|
+
if (code === RelayCloseCode.BLOCKED) {
|
|
306
|
+
return new RelayContentError('gone', BLOCKED_MESSAGE);
|
|
307
|
+
}
|
|
308
|
+
if (code === RelayCloseCode.SIGN_IN) {
|
|
309
|
+
return new RelayContentError('gone', 'The one who shared it has not signed in to an account, which this relay needs of public links.');
|
|
310
|
+
}
|
|
301
311
|
return code === RelayCloseCode.HOST_OFFLINE || code === RelayCloseCode.TIMEOUT
|
|
302
312
|
? new RelayContentError('offline', 'The computer that shared it is not running Ta now. Try again later.')
|
|
303
313
|
: new RelayContentError('offline', 'The computer that shared it cannot be reached now. Try again later.');
|
|
@@ -73,7 +73,7 @@ export class RelayFriends {
|
|
|
73
73
|
const other = info === null || info === void 0 ? void 0 : info.members.find(item => item.member === member);
|
|
74
74
|
const identity = this.rooms.memberOf(room, member);
|
|
75
75
|
if (!info || !other || other.self || other.guest || !identity) {
|
|
76
|
-
throw new Error('Not one to ask in that
|
|
76
|
+
throw new Error('Not one to ask in that group chat.');
|
|
77
77
|
}
|
|
78
78
|
const { link } = await this.link();
|
|
79
79
|
this.choose(identity);
|
|
@@ -41,7 +41,7 @@ export var RelayHubUtil;
|
|
|
41
41
|
!RELAY_ID.test(room) ||
|
|
42
42
|
!/^[A-Za-z0-9_-]{43}$/.test(invite) ||
|
|
43
43
|
!/^[A-Za-z0-9_-]{22}$/.test(owner)) {
|
|
44
|
-
throw new Error('Not a link inviting into a
|
|
44
|
+
throw new Error('Not a link inviting into a group chat of Ta.');
|
|
45
45
|
}
|
|
46
46
|
const kind = (_a = fragment.get('c')) !== null && _a !== void 0 ? _a : '';
|
|
47
47
|
return {
|
package/esm/common/relay-hub.js
CHANGED
|
@@ -123,7 +123,7 @@ export class RelayHub {
|
|
|
123
123
|
}
|
|
124
124
|
const members = (_b = (await this.storage.get('members'))) !== null && _b !== void 0 ? _b : {};
|
|
125
125
|
if (!RelayHub.id(member) || ((_a = members[member]) === null || _a === void 0 ? void 0 : _a.hash) !== (await RelayKeys.hash(String(token)))) {
|
|
126
|
-
this.refuse(socket, 'auth', 'Not a member of this
|
|
126
|
+
this.refuse(socket, 'auth', 'Not a member of this group chat.', RelayHubCloseCode.REFUSED);
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
129
|
const wasOnline = this.online(member, socket);
|
|
@@ -176,7 +176,7 @@ export class RelayHub {
|
|
|
176
176
|
return;
|
|
177
177
|
}
|
|
178
178
|
if (Object.keys(asks).length >= RELAY_HUB_MAX_ASKS) {
|
|
179
|
-
this.refuse(socket, 'full', 'Too many ask to join this
|
|
179
|
+
this.refuse(socket, 'full', 'Too many ask to join this group chat now.', RelayHubCloseCode.REFUSED);
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
182
182
|
asks[request.ask] = { hash: await RelayKeys.hash(request.token), d: request.d, at: now };
|
|
@@ -226,7 +226,7 @@ export class RelayHub {
|
|
|
226
226
|
const meta = await this.storage.get('meta');
|
|
227
227
|
const members = (_c = (await this.storage.get('members'))) !== null && _c !== void 0 ? _c : {};
|
|
228
228
|
if (!meta || !members[member]) {
|
|
229
|
-
this.refuse(socket, 'gone', 'Not in this
|
|
229
|
+
this.refuse(socket, 'gone', 'Not in this group chat any more.', RelayHubCloseCode.REMOVED);
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
232
|
const owner = member === meta.owner;
|
|
@@ -257,7 +257,7 @@ export class RelayHub {
|
|
|
257
257
|
await this.unmake(meta, member);
|
|
258
258
|
await this.log.gone(member);
|
|
259
259
|
for (const other of this.members(member)) {
|
|
260
|
-
other.close(RelayHubCloseCode.REMOVED, 'Left the
|
|
260
|
+
other.close(RelayHubCloseCode.REMOVED, 'Left the group chat.');
|
|
261
261
|
}
|
|
262
262
|
this.broadcast({ t: 'left', member });
|
|
263
263
|
return;
|
|
@@ -70,21 +70,21 @@ export class RelayHubsAdmins extends RelayHubsIdentity {
|
|
|
70
70
|
managed(roomId) {
|
|
71
71
|
const live = this.member(roomId);
|
|
72
72
|
if (!this.manages(live)) {
|
|
73
|
-
throw new Error('Only the owner or an admin of the
|
|
73
|
+
throw new Error('Only the owner or an admin of the group chat does that.');
|
|
74
74
|
}
|
|
75
75
|
return live;
|
|
76
76
|
}
|
|
77
77
|
owned(roomId) {
|
|
78
78
|
const live = this.member(roomId);
|
|
79
79
|
if (!live.record.own) {
|
|
80
|
-
throw new Error('Only the owner of the
|
|
80
|
+
throw new Error('Only the owner of the group chat does that.');
|
|
81
81
|
}
|
|
82
82
|
return live;
|
|
83
83
|
}
|
|
84
84
|
member(roomId) {
|
|
85
85
|
const live = this.live.get(roomId);
|
|
86
86
|
if ((live === null || live === void 0 ? void 0 : live.record.status) !== 'member') {
|
|
87
|
-
throw new Error('Not in that
|
|
87
|
+
throw new Error('Not in that group chat.');
|
|
88
88
|
}
|
|
89
89
|
return live;
|
|
90
90
|
}
|
package/esm/common/relay-hubs.js
CHANGED
|
@@ -186,7 +186,7 @@ export class RelayHubs extends RelayHubsChats {
|
|
|
186
186
|
return this.info(known);
|
|
187
187
|
}
|
|
188
188
|
if (known === null || known === void 0 ? void 0 : known.record.own) {
|
|
189
|
-
throw new Error('This is a
|
|
189
|
+
throw new Error('This is a group chat of your own.');
|
|
190
190
|
}
|
|
191
191
|
const friends = RelayFriendsUtil.isKind(link.kind);
|
|
192
192
|
const record = {
|
|
@@ -272,11 +272,11 @@ export class RelayHubs extends RelayHubsChats {
|
|
|
272
272
|
var _a, _b;
|
|
273
273
|
const live = this.managed(roomId);
|
|
274
274
|
if (member === live.record.member) {
|
|
275
|
-
throw new Error('The owner leaves by closing the
|
|
275
|
+
throw new Error('The owner leaves by closing the group chat.');
|
|
276
276
|
}
|
|
277
277
|
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;
|
|
278
278
|
if (!live.record.own && (member === owner || this.isAdmin(live, member))) {
|
|
279
|
-
throw new Error('Only the owner of the
|
|
279
|
+
throw new Error('Only the owner of the group chat does that.');
|
|
280
280
|
}
|
|
281
281
|
await this.ready(live);
|
|
282
282
|
// A new key for those left: the one taken out holds those of before alone (docs/design/ta-link.md 8.7).
|
|
@@ -358,9 +358,9 @@ export class RelayHubs extends RelayHubsChats {
|
|
|
358
358
|
throw new Error(result.error === 'large'
|
|
359
359
|
? 'The value is too large.'
|
|
360
360
|
: result.error === 'limit'
|
|
361
|
-
? 'The shared state of the
|
|
361
|
+
? 'The shared state of the group chat is full.'
|
|
362
362
|
: result.error === 'owned'
|
|
363
|
-
? 'Another member keeps this key: only they or the owner of the
|
|
363
|
+
? 'Another member keeps this key: only they or the owner of the group chat change it.'
|
|
364
364
|
: 'The relay refused it.');
|
|
365
365
|
}
|
|
366
366
|
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/esm/common/relay-info.js
CHANGED
|
@@ -25,10 +25,24 @@ export const RELAY_LEGACY_INFO = {
|
|
|
25
25
|
};
|
|
26
26
|
export var RelayInfoUtil;
|
|
27
27
|
(function (RelayInfoUtil) {
|
|
28
|
-
function of(persistent, media) {
|
|
29
|
-
return { ...RELAY_LEGACY_INFO, persistent, ...(media ? { media } : {}) };
|
|
28
|
+
function of(persistent, media, content) {
|
|
29
|
+
return { ...RELAY_LEGACY_INFO, persistent, ...(media ? { media } : {}), ...(content ? { content } : {}) };
|
|
30
30
|
}
|
|
31
31
|
RelayInfoUtil.of = of;
|
|
32
|
+
/** An origin of https (or http for a test), as `TA_CONTENT_ORIGIN` or RelayInfo.content give it; undefined for what is not one. */
|
|
33
|
+
function origin(value) {
|
|
34
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const url = new URL(value.trim());
|
|
39
|
+
return /^https?:$/.test(url.protocol) && !url.username && !url.password ? url.origin : undefined;
|
|
40
|
+
}
|
|
41
|
+
catch (_a) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
RelayInfoUtil.origin = origin;
|
|
32
46
|
/**
|
|
33
47
|
* What the operator of a relay lets it keep of the pictures of chats, from its settings (`TA_MEDIA_DAYS`,
|
|
34
48
|
* `TA_MEDIA_MAX_MB`): RELAY_MEDIA_DEFAULT_DAYS unless set, none with 0, within RELAY_MEDIA_MAX.
|
|
@@ -104,12 +118,16 @@ export var RelayInfoUtil;
|
|
|
104
118
|
}
|
|
105
119
|
}
|
|
106
120
|
const kept = info.media && media(info.media.days, (Number(info.media.bytes) || 0) / (1024 * 1024));
|
|
121
|
+
const content = origin(info.content);
|
|
122
|
+
const needs = Array.isArray(info.needsAccount) ? info.needsAccount.filter((each) => typeof each === 'string').slice(0, 8) : [];
|
|
107
123
|
return {
|
|
108
124
|
v: 1,
|
|
109
125
|
capabilities: info.capabilities.filter((capability) => known.includes(capability)),
|
|
110
126
|
limits,
|
|
111
127
|
persistent: info.persistent !== false,
|
|
112
128
|
...(kept ? { media: kept } : {}),
|
|
129
|
+
...(content ? { content } : {}),
|
|
130
|
+
...(needs.length ? { needsAccount: needs } : {}),
|
|
113
131
|
};
|
|
114
132
|
}
|
|
115
133
|
RelayInfoUtil.parse = parse;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type RelayBlocks, type RelayModerationAction, type RelayReport } from './relay-moderation.js';
|
|
2
|
+
import { type RelayAppeal, type RelayModerationEntry, type RelayModerationPolicy, type RelaySanction, type RelayStanding } from './relay-moderation-policy.js';
|
|
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
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { RELAY_MODERATION_PATH } from './relay-moderation.js';
|
|
2
|
+
import { RELAY_APPEAL_PATH, RELAY_BIND_PATH, RELAY_STANDING_PATH, } from './relay-moderation-policy.js';
|
|
3
|
+
async function call(url, token, init) {
|
|
4
|
+
var _a, _b;
|
|
5
|
+
const response = await fetch(url, {
|
|
6
|
+
...init,
|
|
7
|
+
headers: { authorization: `Bearer ${token}`, ...((init === null || init === void 0 ? void 0 : init.body) ? { 'content-type': 'application/json' } : {}) },
|
|
8
|
+
});
|
|
9
|
+
const body = (await response.json().catch(() => undefined));
|
|
10
|
+
if (response.status === 401) {
|
|
11
|
+
throw new Error((_a = body === null || body === void 0 ? void 0 : body.error) !== null && _a !== void 0 ? _a : 'The token is wrong.');
|
|
12
|
+
}
|
|
13
|
+
if (response.status === 404) {
|
|
14
|
+
throw new Error('This relay does not answer it.');
|
|
15
|
+
}
|
|
16
|
+
if (!response.ok || !body) {
|
|
17
|
+
throw new Error((_b = body === null || body === void 0 ? void 0 : body.error) !== null && _b !== void 0 ? _b : `The relay answered ${response.status}.`);
|
|
18
|
+
}
|
|
19
|
+
return body;
|
|
20
|
+
}
|
|
21
|
+
const base = (relay) => relay.replace(/\/+$/, '');
|
|
22
|
+
/** The operator's side, from Ta: reads and acts, with the token of the relay. */
|
|
23
|
+
export var RelayModerationClient;
|
|
24
|
+
(function (RelayModerationClient) {
|
|
25
|
+
function read(relay, token) {
|
|
26
|
+
return call(`${base(relay)}${RELAY_MODERATION_PATH}`, token);
|
|
27
|
+
}
|
|
28
|
+
RelayModerationClient.read = read;
|
|
29
|
+
function apply(relay, token, action) {
|
|
30
|
+
return call(`${base(relay)}${RELAY_MODERATION_PATH}`, token, { method: 'POST', body: JSON.stringify(action) });
|
|
31
|
+
}
|
|
32
|
+
RelayModerationClient.apply = apply;
|
|
33
|
+
})(RelayModerationClient || (RelayModerationClient = {}));
|
|
34
|
+
/** An account's side: the computer it shares through, how it stands, and its appeal, with the token of the account. */
|
|
35
|
+
export var RelayStandingClient;
|
|
36
|
+
(function (RelayStandingClient) {
|
|
37
|
+
/** Proves both: the account by its token, the computer by the secret it holds its id on the relay with. */
|
|
38
|
+
function bind(relay, token, host) {
|
|
39
|
+
return call(`${base(relay)}${RELAY_BIND_PATH}`, token, { method: 'POST', body: JSON.stringify({ host: host.id, secret: host.secret }) });
|
|
40
|
+
}
|
|
41
|
+
RelayStandingClient.bind = bind;
|
|
42
|
+
function standing(relay, token) {
|
|
43
|
+
return call(`${base(relay)}${RELAY_STANDING_PATH}`, token);
|
|
44
|
+
}
|
|
45
|
+
RelayStandingClient.standing = standing;
|
|
46
|
+
function appeal(relay, token, text) {
|
|
47
|
+
return call(`${base(relay)}${RELAY_APPEAL_PATH}`, token, { method: 'POST', body: JSON.stringify({ text }) });
|
|
48
|
+
}
|
|
49
|
+
RelayStandingClient.appeal = appeal;
|
|
50
|
+
})(RelayStandingClient || (RelayStandingClient = {}));
|
|
51
|
+
//# sourceMappingURL=relay-moderation-client.js.map
|