@coda-console/friends 0.2.0 → 0.3.1
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.md +27 -3
- package/lib/friends.mjs +111 -21
- package/lib/gateway.mjs +198 -42
- package/lib/outbox.mjs +8 -4
- package/lib/social-streams.mjs +218 -0
- package/lib/view-machine.mjs +42 -0
- package/package.json +171 -4
- package/view/app.mjs +149 -55
- package/view/style.css +2 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// 私信 friends/dm 与好友动态 friends/feed 的纯逻辑:发布入参的清洗、Accord 记录的投影,以及实时流的变更集与游标。不碰 Coda,也不碰磁盘。
|
|
2
|
+
// 记录照旧由 coda/accord@1 签名与保存;这里只把一页页读回来的记录投影成规范项,并在内存里比对前后两份投影,算出增量帧。
|
|
3
|
+
import { normalizeContentPointer, readContentPointer } from './friends.mjs';
|
|
4
|
+
|
|
5
|
+
export const DM_KIND = 'friends/dm', FEED_KIND = 'friends/feed';
|
|
6
|
+
export const MAX_TEXT = 8000, MAX_MEDIA = 4, MAX_HISTORY = 500;
|
|
7
|
+
// 快照一帧的字节上限,远低于 readFrames 默认的一行 1 MiB:快照按它分片。
|
|
8
|
+
export const MAX_SNAPSHOT_FRAME_BYTES = 256 * 1024;
|
|
9
|
+
const MAX_ID = 200, MAX_ID_BYTES = 256, MAX_AUDIENCE = 500;
|
|
10
|
+
const AUTHOR = /^ed25519:[0-9a-f]{64}$/, AUDIENCE = /^(?:public|ed25519:[0-9a-f]{64})$/;
|
|
11
|
+
const CONTROL = /[\p{Cc}]/u;
|
|
12
|
+
const UUID = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
|
|
13
|
+
const CURSOR = new RegExp(`^(${UUID}):(0|[1-9][0-9]*)$`);
|
|
14
|
+
|
|
15
|
+
const fail = message => { throw new Error(message); };
|
|
16
|
+
const length = text => [...text].length;
|
|
17
|
+
const encoder = new TextEncoder();
|
|
18
|
+
const bytes = text => encoder.encode(text).length;
|
|
19
|
+
const isPlain = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
20
|
+
const isTime = value => Number.isSafeInteger(value) && value >= 0;
|
|
21
|
+
const validLabel = text => typeof text === 'string' && text.length > 0 && length(text) <= MAX_ID && !CONTROL.test(text);
|
|
22
|
+
export const isAuthor = value => typeof value === 'string' && AUTHOR.test(value);
|
|
23
|
+
|
|
24
|
+
// ---- 发布入参 ----
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 可选的 id、replyTo:原样至多 200 个字符(与 schema 的 maxLength 同样按码点数)、UTF-8 至多 256 字节(与 Accord 一致)、
|
|
28
|
+
* 不含控制字符,去首尾空白后不能是空的;省略给 undefined(id 由调用方生成)。
|
|
29
|
+
*/
|
|
30
|
+
function readLabel(value, name) {
|
|
31
|
+
if (value === undefined) return undefined;
|
|
32
|
+
if (typeof value !== 'string' || length(value) > MAX_ID || bytes(value) > MAX_ID_BYTES || CONTROL.test(value) || !value.trim())
|
|
33
|
+
fail(`${name} 须是 1–${MAX_ID} 个字符、UTF-8 至多 ${MAX_ID_BYTES} 字节的文本,不含控制字符`);
|
|
34
|
+
return value.trim();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** text 原样至多 8000 个字(码点,与 schema 一致),再去首尾空白。 */
|
|
38
|
+
function readText(text) {
|
|
39
|
+
if (text === undefined) return '';
|
|
40
|
+
if (typeof text !== 'string') fail('text 须是文本');
|
|
41
|
+
if (length(text) > MAX_TEXT) fail(`text 最多 ${MAX_TEXT} 个字`);
|
|
42
|
+
return text.trim();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function readPointers(list, name) {
|
|
46
|
+
if (list === undefined) return [];
|
|
47
|
+
if (!Array.isArray(list) || !list.length || list.length > MAX_MEDIA) fail(`${name} 须是 1–${MAX_MEDIA} 项的数组`);
|
|
48
|
+
return list.map(normalizeContentPointer);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const createdAtOf = (existingCreatedAt, now) => {
|
|
52
|
+
const at = isTime(existingCreatedAt) ? existingCreatedAt : now;
|
|
53
|
+
if (!isTime(at)) fail('createdAt 须是非负整数');
|
|
54
|
+
return at;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 私信的入参 `{ to, id?, text?, attachments?, replyTo? }` → `{ id, to, audience: [to], body }`。只发给一个人,不能发给 public 或自己;
|
|
59
|
+
* text 与 attachments 不能都空。createdAt 先用同一 id 已有记录的(重试时内容不变,才能按幂等跳过),没有再取 now。
|
|
60
|
+
*/
|
|
61
|
+
export function normalizeDmInput(input, { selfAuthor, existingCreatedAt, now = Date.now() } = {}) {
|
|
62
|
+
if (!isPlain(input)) fail('私信须是对象');
|
|
63
|
+
const { to } = input;
|
|
64
|
+
if (!isAuthor(to)) fail('to 须是一位好友的公钥 ed25519:<64 位小写十六进制>');
|
|
65
|
+
if (to === selfAuthor) fail('不能给自己发私信');
|
|
66
|
+
const id = readLabel(input.id, 'id'), text = readText(input.text), attachments = readPointers(input.attachments, 'attachments');
|
|
67
|
+
if (!text && !attachments.length) fail('私信的 text 与 attachments 不能都空');
|
|
68
|
+
const replyTo = readLabel(input.replyTo, 'replyTo'), createdAt = createdAtOf(existingCreatedAt, now);
|
|
69
|
+
return { id, to, audience: [to], body: { to, text, ...(attachments.length ? { attachments } : {}), ...(replyTo ? { replyTo } : {}), createdAt } };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 动态的入参 `{ id?, text?, media?, audience? }` → `{ id, audience, body }`。audience 省略是 `['public']`,写了须是 1–500 项、
|
|
74
|
+
* 每项 public 或公钥,去重;`[]` 不收(撤回走 retract)。text 与 media 不能都空;createdAt 同私信。
|
|
75
|
+
*/
|
|
76
|
+
export function normalizeFeedInput(input, { existingCreatedAt, now = Date.now() } = {}) {
|
|
77
|
+
if (!isPlain(input)) fail('动态须是对象');
|
|
78
|
+
const id = readLabel(input.id, 'id'), text = readText(input.text), media = readPointers(input.media, 'media');
|
|
79
|
+
if (!text && !media.length) fail('动态的 text 与 media 不能都空');
|
|
80
|
+
const { audience = ['public'] } = input;
|
|
81
|
+
if (!Array.isArray(audience) || !audience.length || audience.length > MAX_AUDIENCE) fail(`audience 须是 1–${MAX_AUDIENCE} 项的数组;撤回用 retract`);
|
|
82
|
+
if (!audience.every(item => typeof item === 'string' && AUDIENCE.test(item))) fail("audience 每项须是 'public' 或 ed25519:<64 位小写十六进制>");
|
|
83
|
+
return { id, audience: [...new Set(audience)], body: { text, ...(media.length ? { media } : {}), createdAt: createdAtOf(existingCreatedAt, now) } };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ---- 记录投影 ----
|
|
87
|
+
|
|
88
|
+
// 每个 (author, id) 只留 version 最大的一条:最新的是撤回(空 body)或畸形,整条就算没了,不回落到旧版本。
|
|
89
|
+
function latest(records) {
|
|
90
|
+
const top = new Map();
|
|
91
|
+
for (const record of records ?? []) {
|
|
92
|
+
if (!isPlain(record) || typeof record.author !== 'string' || typeof record.id !== 'string') continue;
|
|
93
|
+
const key = JSON.stringify([record.author, record.id]), version = Number.isSafeInteger(record.version) ? record.version : 0;
|
|
94
|
+
if (!top.has(key) || version > top.get(key).version) top.set(key, { record, version });
|
|
95
|
+
}
|
|
96
|
+
return [...top.values()];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 外来正文:text 是至多 8000 字的文本(不合法当空),图片指针只留校验通过的、至多 4 个;两样都空、或 createdAt 不对就是畸形(null)。
|
|
100
|
+
function readBody(body, pointersKey) {
|
|
101
|
+
if (!isPlain(body) || !isTime(body.createdAt)) return null;
|
|
102
|
+
const text = typeof body.text === 'string' && length(body.text) <= MAX_TEXT ? body.text.trim() : '';
|
|
103
|
+
const pointers = Array.isArray(body[pointersKey]) ? body[pointersKey].map(readContentPointer).filter(Boolean).slice(0, MAX_MEDIA) : [];
|
|
104
|
+
return text || pointers.length ? { text, pointers, createdAt: body.createdAt } : null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const compare = (a, b) => a.createdAt - b.createdAt || a.version - b.version || (a.author < b.author ? -1 : a.author > b.author ? 1 : 0) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Accord 的 friends/dm 记录 → 私信规范项,按 (createdAt, version, author, id) 升序。只收真是本机与对方之间的:本机发出的须是本人签的、
|
|
111
|
+
* 发给别人;收到的须是别人签的、发给本人。`peer` 是对面那个人。
|
|
112
|
+
*/
|
|
113
|
+
export function projectDmRecords(records, { selfAuthor } = {}) {
|
|
114
|
+
const items = [];
|
|
115
|
+
for (const { record, version } of latest(records)) {
|
|
116
|
+
const body = readBody(record.body, 'attachments'), to = record.body?.to;
|
|
117
|
+
if (!body || !isAuthor(to)) continue;
|
|
118
|
+
let peer;
|
|
119
|
+
if (record.local === true && record.author === selfAuthor && to !== selfAuthor) peer = to;
|
|
120
|
+
else if (record.local === false && record.author !== selfAuthor && to === selfAuthor) peer = record.author;
|
|
121
|
+
else continue;
|
|
122
|
+
const { replyTo } = record.body;
|
|
123
|
+
items.push({ author: record.author, id: record.id, version, local: record.local, peer, to, text: body.text, attachments: body.pointers,
|
|
124
|
+
...(validLabel(replyTo) ? { replyTo } : {}), createdAt: body.createdAt });
|
|
125
|
+
}
|
|
126
|
+
return items.sort(compare);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Accord 的 friends/feed 记录 → 动态规范项,按 (createdAt, version, author, id) 降序(新的在前)。 */
|
|
130
|
+
export function projectFeedRecords(records) {
|
|
131
|
+
const items = [];
|
|
132
|
+
for (const { record, version } of latest(records)) {
|
|
133
|
+
const body = readBody(record.body, 'media');
|
|
134
|
+
if (body) items.push({ author: record.author, id: record.id, version, local: record.local === true, text: body.text, media: body.pointers, createdAt: body.createdAt });
|
|
135
|
+
}
|
|
136
|
+
return items.sort((a, b) => compare(b, a));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ---- 变更集与游标 ----
|
|
140
|
+
|
|
141
|
+
/** 游标 `${epoch}:${seq}` → `{ epoch, seq }`;不合法给 null。 */
|
|
142
|
+
export function parseCursor(after) {
|
|
143
|
+
const match = typeof after === 'string' ? CURSOR.exec(after) : null;
|
|
144
|
+
if (!match) return null;
|
|
145
|
+
const seq = Number(match[2]);
|
|
146
|
+
return Number.isSafeInteger(seq) ? { epoch: match[1], seq } : null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const keyOf = item => JSON.stringify([item.author, item.id]);
|
|
150
|
+
/** 一次变化里用来过滤的那一项:upsert 看它的 item,retract 看它自己(带 author、peer)。 */
|
|
151
|
+
export const subjectOf = event => event.type === 'upsert' ? event.item : event;
|
|
152
|
+
/** 变化 → 帧:seq 换成游标。 */
|
|
153
|
+
export const frameOf = (epoch, { seq, ...event }) => ({ ...event, cursor: `${epoch}:${seq}` });
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 快照的帧:items 按序切成每帧 JSON 至多 `maxBytes` 字节的几片,`{ type: 'snapshot', cursor, items, more }`,还有后续分片的
|
|
157
|
+
* `more` 为 true,最后一片(空快照也有这一片,`items: []`)为 false;客户端收到 more 为 false 才把整份快照与游标落定。
|
|
158
|
+
*/
|
|
159
|
+
export function snapshotFrames(cursor, items, maxBytes = MAX_SNAPSHOT_FRAME_BYTES) {
|
|
160
|
+
const empty = bytes(JSON.stringify({ type: 'snapshot', cursor, items: [], more: false })), chunks = [[]];
|
|
161
|
+
let size = empty;
|
|
162
|
+
for (const item of items) {
|
|
163
|
+
const one = bytes(JSON.stringify(item)) + 1;
|
|
164
|
+
if (chunks.at(-1).length && size + one > maxBytes) { chunks.push([]); size = empty; }
|
|
165
|
+
chunks.at(-1).push(item);
|
|
166
|
+
size += one;
|
|
167
|
+
}
|
|
168
|
+
return chunks.map((chunk, i) => ({ type: 'snapshot', cursor, items: chunk, more: i < chunks.length - 1 }));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 一条流的内存状态:启动时的 epoch、单调的 seq、当前投影(按 (author, id))、至多 `maxHistory` 条变化的环缓冲。
|
|
173
|
+
* `applySnapshot` 换上新一份投影并给出这次的变化;`resume(after, match)` 按游标给出续上的增量,续不上就给全量快照。
|
|
174
|
+
*/
|
|
175
|
+
export function createStreamHub({ epoch = globalThis.crypto.randomUUID(), maxHistory = MAX_HISTORY } = {}) {
|
|
176
|
+
let seq = 0, current = new Map(), history = [];
|
|
177
|
+
const oldestSeq = () => history.length ? history[0].seq : seq + 1;
|
|
178
|
+
const cursor = () => `${epoch}:${seq}`;
|
|
179
|
+
return {
|
|
180
|
+
epoch,
|
|
181
|
+
get seq() { return seq; },
|
|
182
|
+
get oldestSeq() { return oldestSeq(); },
|
|
183
|
+
cursor,
|
|
184
|
+
items: () => [...current.values()],
|
|
185
|
+
// 先在局部算好这次的变化,最后一并换上投影、seq 与历史:中途出错,hub 还是原来那份。
|
|
186
|
+
applySnapshot(nextItems) {
|
|
187
|
+
const next = new Map(nextItems.map(item => [keyOf(item), item])), events = [];
|
|
188
|
+
let at = seq;
|
|
189
|
+
for (const [key, item] of current) {
|
|
190
|
+
if (!next.has(key)) events.push({ seq: ++at, type: 'retract', author: item.author, id: item.id, ...(item.peer ? { peer: item.peer } : {}) });
|
|
191
|
+
}
|
|
192
|
+
for (const [key, item] of next) {
|
|
193
|
+
const old = current.get(key);
|
|
194
|
+
if (old && old.version === item.version && JSON.stringify(old) === JSON.stringify(item)) continue;
|
|
195
|
+
// 同一条私信换了收件人:旧会话那边先撤掉,新会话再收到它。
|
|
196
|
+
if (old?.peer && old.peer !== item.peer) events.push({ seq: ++at, type: 'retract', author: old.author, id: old.id, peer: old.peer });
|
|
197
|
+
events.push({ seq: ++at, type: 'upsert', item });
|
|
198
|
+
}
|
|
199
|
+
// 不把 events 展开成实参(一次几十万条会超出实参上限):够多就只取最后 maxHistory 条,否则逐条追加再裁。
|
|
200
|
+
let kept;
|
|
201
|
+
if (events.length >= maxHistory) kept = events.slice(-maxHistory);
|
|
202
|
+
else {
|
|
203
|
+
kept = history.slice();
|
|
204
|
+
for (const event of events) kept.push(event);
|
|
205
|
+
if (kept.length > maxHistory) kept.splice(0, kept.length - maxHistory);
|
|
206
|
+
}
|
|
207
|
+
current = next;
|
|
208
|
+
seq = at;
|
|
209
|
+
history = kept;
|
|
210
|
+
return events;
|
|
211
|
+
},
|
|
212
|
+
resume(after, match = () => true) {
|
|
213
|
+
const at = parseCursor(after);
|
|
214
|
+
if (!at || at.epoch !== epoch || at.seq > seq || at.seq < oldestSeq() - 1) return { mode: 'snapshot', cursor: cursor(), items: [...current.values()].filter(match) };
|
|
215
|
+
return { mode: 'delta', cursor: cursor(), events: history.filter(event => event.seq > at.seq && match(subjectOf(event))) };
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// 页面选机器与发消息的纯逻辑:多台机器都提供这页时,页面须指明消息发往哪台。不碰 Coda 的 Node API;页面和单测都加载它。
|
|
2
|
+
|
|
3
|
+
export function reachableMachines(coda) {
|
|
4
|
+
const list = Array.isArray(coda?.machines) ? coda.machines : [coda?.machine];
|
|
5
|
+
const seen = new Set();
|
|
6
|
+
return list.filter(m => {
|
|
7
|
+
if (typeof m?.id !== 'string' || !m.id || m.unreachable || seen.has(m.id)) return false;
|
|
8
|
+
seen.add(m.id);
|
|
9
|
+
return true;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function pickMachine(coda, savedId) {
|
|
14
|
+
const ids = reachableMachines(coda).map(m => m.id);
|
|
15
|
+
if (typeof savedId === 'string' && ids.includes(savedId)) return savedId;
|
|
16
|
+
const own = coda?.machine?.id;
|
|
17
|
+
if (ids.includes(own)) return own;
|
|
18
|
+
return ids[0] ?? own ?? null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 入队瞬间固定目标机器与代际(getEpoch,调用方每次选机自增);轮到它发送时选择已变,就整条丢弃,不发往新机器、也不报错。
|
|
22
|
+
// 发送失败交给 onError(error, msg, machine, epoch),不吞;只收当前目标机器的回包。send 返回的 Promise 以「是否发出」收尾。
|
|
23
|
+
export function createMachineBridge({ coda, getMachine, getEpoch, onMessage, onError, targetWindow = globalThis }) {
|
|
24
|
+
let chain = Promise.resolve();
|
|
25
|
+
const send = msg => {
|
|
26
|
+
const machine = getMachine(), epoch = getEpoch?.();
|
|
27
|
+
chain = chain.then(async () => {
|
|
28
|
+
if (getMachine() !== machine || getEpoch?.() !== epoch) return false;
|
|
29
|
+
try { await coda.postMessage(msg, machine ? { machine } : undefined); return true; } catch (error) { onError(error, msg, machine, epoch); return false; }
|
|
30
|
+
});
|
|
31
|
+
return chain;
|
|
32
|
+
};
|
|
33
|
+
const listener = event => {
|
|
34
|
+
const d = event.data;
|
|
35
|
+
if (!(d && typeof d === 'object' && typeof d.type === 'string')) return;
|
|
36
|
+
const current = getMachine();
|
|
37
|
+
if (event.machine?.id && current && event.machine.id !== current) return;
|
|
38
|
+
onMessage(d, event);
|
|
39
|
+
};
|
|
40
|
+
targetWindow.addEventListener('message', listener);
|
|
41
|
+
return { send, dispose: () => targetWindow.removeEventListener('message', listener) };
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName": "好友",
|
|
5
5
|
"description": "管理 Accord 身份、个人名片与熟人好友通道",
|
|
6
6
|
"icon": { "symbol": "person.2.fill", "color": "blue" },
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.3.1",
|
|
8
8
|
"categories": [
|
|
9
9
|
"Skills 与工具"
|
|
10
10
|
],
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
{
|
|
41
41
|
"name": "friends/social@1",
|
|
42
42
|
"title": "好友社交网关",
|
|
43
|
-
"description": "
|
|
43
|
+
"description": "业务无关的好友网关:读好友与好友分享的记录,向好友发布、撤回记录,设置可代签的社交名片 friends/card,发私信 friends/dm、好友动态 friends/feed,并以 dm、feed 两条帧流实时跟随;签名与记录全部透传 coda/accord@1,没有身份或证书过期时在本机排队,恢复后自动补发。",
|
|
44
44
|
"spec": {
|
|
45
45
|
"type": "object",
|
|
46
46
|
"properties": { "version": { "const": 1 } },
|
|
@@ -136,6 +136,145 @@
|
|
|
136
136
|
"additionalProperties": false
|
|
137
137
|
}
|
|
138
138
|
},
|
|
139
|
+
"set-card": {
|
|
140
|
+
"idempotent": true,
|
|
141
|
+
"input": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"properties": {
|
|
144
|
+
"name": { "type": "string", "minLength": 1, "maxLength": 40 },
|
|
145
|
+
"emoji": { "type": "string", "maxLength": 8 },
|
|
146
|
+
"color": { "enum": ["blue", "orange", "green", "purple", "pink", "teal", "gray"] },
|
|
147
|
+
"avatar": {
|
|
148
|
+
"anyOf": [
|
|
149
|
+
{
|
|
150
|
+
"type": "object",
|
|
151
|
+
"description": "内容寻址的图片指针(BlobPointer):path 只收 content/<sha256>,sha256 须与 path 里的一致",
|
|
152
|
+
"properties": {
|
|
153
|
+
"owner": { "type": "string", "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" },
|
|
154
|
+
"path": { "type": "string", "pattern": "^content/[0-9a-f]{64}$" },
|
|
155
|
+
"sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
|
|
156
|
+
"mime": { "type": "string", "minLength": 1, "maxLength": 128 },
|
|
157
|
+
"size": { "type": "integer", "minimum": 0, "maximum": 5242880 },
|
|
158
|
+
"name": { "type": "string", "minLength": 1, "maxLength": 200 }
|
|
159
|
+
},
|
|
160
|
+
"required": ["owner", "path", "sha256"],
|
|
161
|
+
"additionalProperties": false
|
|
162
|
+
},
|
|
163
|
+
{ "type": "null" }
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
"required": ["name"],
|
|
168
|
+
"additionalProperties": false
|
|
169
|
+
},
|
|
170
|
+
"result": {
|
|
171
|
+
"type": "object",
|
|
172
|
+
"properties": {
|
|
173
|
+
"state": { "enum": ["synced", "queued", "paused", "no_identity", "needs_cert", "error"] },
|
|
174
|
+
"skipped": { "type": "boolean" },
|
|
175
|
+
"author": { "type": ["string", "null"] },
|
|
176
|
+
"version": { "type": "integer", "minimum": 0 },
|
|
177
|
+
"error": { "type": "string" }
|
|
178
|
+
},
|
|
179
|
+
"required": ["state"],
|
|
180
|
+
"additionalProperties": false
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
"send-dm": {
|
|
184
|
+
"idempotent": true,
|
|
185
|
+
"input": {
|
|
186
|
+
"type": "object",
|
|
187
|
+
"properties": {
|
|
188
|
+
"to": { "type": "string", "pattern": "^ed25519:[0-9a-f]{64}$" },
|
|
189
|
+
"id": { "type": "string", "minLength": 1, "maxLength": 200, "pattern": "^[^\\u0000-\\u001f\\u007f-\\u009f]*[^\\s\\u0000-\\u001f\\u007f-\\u009f][^\\u0000-\\u001f\\u007f-\\u009f]*$", "description": "至多 200 个字符且 UTF-8 至多 256 字节,不含控制字符,去首尾空白后不能为空;省略由网关生成 UUID" },
|
|
190
|
+
"text": { "type": "string", "maxLength": 8000, "description": "至多 8000 个字符(码点,按原样计,含首尾空白),发布时去首尾空白" },
|
|
191
|
+
"attachments": {
|
|
192
|
+
"type": "array",
|
|
193
|
+
"minItems": 1,
|
|
194
|
+
"maxItems": 4,
|
|
195
|
+
"items": {
|
|
196
|
+
"type": "object",
|
|
197
|
+
"description": "内容寻址的图片指针(BlobPointer):path 只收 content/<sha256>,sha256 须与 path 里的一致",
|
|
198
|
+
"properties": {
|
|
199
|
+
"owner": { "type": "string", "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" },
|
|
200
|
+
"path": { "type": "string", "pattern": "^content/[0-9a-f]{64}$" },
|
|
201
|
+
"sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
|
|
202
|
+
"mime": { "type": "string", "minLength": 1, "maxLength": 128 },
|
|
203
|
+
"size": { "type": "integer", "minimum": 0, "maximum": 5242880 },
|
|
204
|
+
"name": { "type": "string", "minLength": 1, "maxLength": 200 }
|
|
205
|
+
},
|
|
206
|
+
"required": ["owner", "path", "sha256"],
|
|
207
|
+
"additionalProperties": false
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
"replyTo": { "type": "string", "minLength": 1, "maxLength": 200, "pattern": "^[^\\u0000-\\u001f\\u007f-\\u009f]*[^\\s\\u0000-\\u001f\\u007f-\\u009f][^\\u0000-\\u001f\\u007f-\\u009f]*$", "description": "所回复私信的 id:与 id 同样至多 200 个字符且 UTF-8 至多 256 字节,不含控制字符" }
|
|
211
|
+
},
|
|
212
|
+
"required": ["to"],
|
|
213
|
+
"additionalProperties": false
|
|
214
|
+
},
|
|
215
|
+
"result": {
|
|
216
|
+
"type": "object",
|
|
217
|
+
"properties": {
|
|
218
|
+
"state": { "enum": ["synced", "queued", "paused", "no_identity", "needs_cert", "error"] },
|
|
219
|
+
"id": { "type": "string" },
|
|
220
|
+
"skipped": { "type": "boolean" },
|
|
221
|
+
"author": { "type": ["string", "null"] },
|
|
222
|
+
"version": { "type": "integer", "minimum": 0 },
|
|
223
|
+
"error": { "type": "string" }
|
|
224
|
+
},
|
|
225
|
+
"required": ["state"],
|
|
226
|
+
"additionalProperties": false
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
"post-feed": {
|
|
230
|
+
"idempotent": true,
|
|
231
|
+
"input": {
|
|
232
|
+
"type": "object",
|
|
233
|
+
"properties": {
|
|
234
|
+
"id": { "type": "string", "minLength": 1, "maxLength": 200, "pattern": "^[^\\u0000-\\u001f\\u007f-\\u009f]*[^\\s\\u0000-\\u001f\\u007f-\\u009f][^\\u0000-\\u001f\\u007f-\\u009f]*$", "description": "至多 200 个字符且 UTF-8 至多 256 字节,不含控制字符,去首尾空白后不能为空;省略由网关生成 UUID" },
|
|
235
|
+
"text": { "type": "string", "maxLength": 8000, "description": "至多 8000 个字符(码点,按原样计,含首尾空白),发布时去首尾空白" },
|
|
236
|
+
"media": {
|
|
237
|
+
"type": "array",
|
|
238
|
+
"minItems": 1,
|
|
239
|
+
"maxItems": 4,
|
|
240
|
+
"items": {
|
|
241
|
+
"type": "object",
|
|
242
|
+
"description": "内容寻址的图片指针(BlobPointer):path 只收 content/<sha256>,sha256 须与 path 里的一致",
|
|
243
|
+
"properties": {
|
|
244
|
+
"owner": { "type": "string", "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" },
|
|
245
|
+
"path": { "type": "string", "pattern": "^content/[0-9a-f]{64}$" },
|
|
246
|
+
"sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
|
|
247
|
+
"mime": { "type": "string", "minLength": 1, "maxLength": 128 },
|
|
248
|
+
"size": { "type": "integer", "minimum": 0, "maximum": 5242880 },
|
|
249
|
+
"name": { "type": "string", "minLength": 1, "maxLength": 200 }
|
|
250
|
+
},
|
|
251
|
+
"required": ["owner", "path", "sha256"],
|
|
252
|
+
"additionalProperties": false
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
"audience": {
|
|
256
|
+
"type": "array",
|
|
257
|
+
"items": { "type": "string", "pattern": "^(?:public|ed25519:[0-9a-f]{64})$" },
|
|
258
|
+
"minItems": 1,
|
|
259
|
+
"maxItems": 500
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
"additionalProperties": false
|
|
263
|
+
},
|
|
264
|
+
"result": {
|
|
265
|
+
"type": "object",
|
|
266
|
+
"properties": {
|
|
267
|
+
"state": { "enum": ["synced", "queued", "paused", "no_identity", "needs_cert", "error"] },
|
|
268
|
+
"id": { "type": "string" },
|
|
269
|
+
"skipped": { "type": "boolean" },
|
|
270
|
+
"author": { "type": ["string", "null"] },
|
|
271
|
+
"version": { "type": "integer", "minimum": 0 },
|
|
272
|
+
"error": { "type": "string" }
|
|
273
|
+
},
|
|
274
|
+
"required": ["state"],
|
|
275
|
+
"additionalProperties": false
|
|
276
|
+
}
|
|
277
|
+
},
|
|
139
278
|
"retract": {
|
|
140
279
|
"idempotent": true,
|
|
141
280
|
"input": {
|
|
@@ -196,9 +335,37 @@
|
|
|
196
335
|
}
|
|
197
336
|
}
|
|
198
337
|
},
|
|
338
|
+
"streams": {
|
|
339
|
+
"dm": {
|
|
340
|
+
"shape": "read",
|
|
341
|
+
"frames": true,
|
|
342
|
+
"description": "私信的实时帧流:首帧 { type: 'snapshot', cursor, items }(按 createdAt 升序),之后每次变化一帧 { type: 'upsert', cursor, item } 或 { type: 'retract', cursor, author, id, peer };peer 只看与这位好友的私信,after 给上次的 cursor 只补增量,续不上回到快照",
|
|
343
|
+
"input": {
|
|
344
|
+
"type": "object",
|
|
345
|
+
"properties": {
|
|
346
|
+
"peer": { "type": "string", "pattern": "^ed25519:[0-9a-f]{64}$" },
|
|
347
|
+
"after": { "type": "string", "minLength": 1, "maxLength": 128 }
|
|
348
|
+
},
|
|
349
|
+
"additionalProperties": false
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
"feed": {
|
|
353
|
+
"shape": "read",
|
|
354
|
+
"frames": true,
|
|
355
|
+
"description": "好友动态的实时帧流:首帧 { type: 'snapshot', cursor, items }(按 createdAt 降序),之后每次变化一帧 { type: 'upsert', cursor, item } 或 { type: 'retract', cursor, author, id };author 只看这一位的,after 给上次的 cursor 只补增量,续不上回到快照",
|
|
356
|
+
"input": {
|
|
357
|
+
"type": "object",
|
|
358
|
+
"properties": {
|
|
359
|
+
"author": { "type": "string", "pattern": "^ed25519:[0-9a-f]{64}$" },
|
|
360
|
+
"after": { "type": "string", "minLength": 1, "maxLength": 128 }
|
|
361
|
+
},
|
|
362
|
+
"additionalProperties": false
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
},
|
|
199
366
|
"permissions": {
|
|
200
|
-
"read": { "title": "
|
|
201
|
-
"publish": { "title": "
|
|
367
|
+
"read": { "title": "查看好友列表、读取好友分享的记录与实时私信、动态", "read": true, "operations": ["friends", "records"], "streams": ["dm", "feed"] },
|
|
368
|
+
"publish": { "title": "通过好友网关发布、撤回记录、设置社交名片、发私信与动态、查看待发队列", "operations": ["publish", "set-card", "send-dm", "post-feed", "retract", "outbox"] }
|
|
202
369
|
}
|
|
203
370
|
}
|
|
204
371
|
],
|