@coda-console/friends 0.0.0 → 0.2.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.md +32 -2
- package/lib/friends.mjs +159 -0
- package/lib/gateway.mjs +338 -0
- package/lib/json-file.mjs +25 -0
- package/lib/notes.mjs +65 -0
- package/lib/outbox.mjs +141 -0
- package/lib/policy.mjs +22 -0
- package/main.mjs +45 -0
- package/package.json +212 -3
- package/view/app.mjs +259 -0
- package/view/index.html +12 -0
- package/view/style.css +61 -0
package/lib/outbox.mjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// 网关的纯逻辑:入参校验、保留类型、证书状态、规范哈希,以及待发队列(outbox.json)的条目与状态转换。不碰 Coda。
|
|
2
|
+
// 不另建目录库:签名写入与记录查询都由 coda/accord@1 完成;这里只在记录待发、暂停或失败排队时留着待发的 body,
|
|
3
|
+
// 同步成功就释放 body,只留去重用的轻量元数据;撤回完成就删掉条目。
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { readJson, writeJson } from './json-file.mjs';
|
|
6
|
+
|
|
7
|
+
/** 网关不替业务发布、撤回的类型:好友关系、名片等 Accord 自己的记录。 */
|
|
8
|
+
export const RESERVED_KINDS = new Set(['binding', 'profile', 'friends', 'coda/profile', 'coda/friends']);
|
|
9
|
+
export const MAX_ID_CHARS = 200, MAX_ID_BYTES = 256, MAX_BODY_BYTES = 65536, MAX_AUDIENCE = 500;
|
|
10
|
+
const KIND = /^[a-z][a-z0-9-]{0,63}(?:\/[a-z][a-z0-9-]{0,63})?$/;
|
|
11
|
+
const AUDIENCE = /^(?:public|ed25519:[0-9a-f]{64})$/;
|
|
12
|
+
|
|
13
|
+
export const invalid = message => Object.assign(new Error(message), { code: 'invalid_input', effects: 'none' });
|
|
14
|
+
const isPlain = value => {
|
|
15
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
16
|
+
const proto = Object.getPrototypeOf(value);
|
|
17
|
+
return proto === Object.prototype || proto === null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const validKind = kind => typeof kind === 'string' && KIND.test(kind) && !RESERVED_KINDS.has(kind);
|
|
21
|
+
|
|
22
|
+
/** kind 须符合 Accord 的格式,且不是保留类型。 */
|
|
23
|
+
export function checkKind(kind) {
|
|
24
|
+
if (typeof kind !== 'string' || !KIND.test(kind)) throw invalid('kind 须是小写字母开头的 name 或 ns/name(只含小写字母、数字、连字符,各段最长 64 位)');
|
|
25
|
+
if (RESERVED_KINDS.has(kind)) throw invalid(`kind「${kind}」是保留类型,网关不发布也不撤回它`);
|
|
26
|
+
return kind;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** id 非空、合法 UTF-8、至多 256 字节;发布与撤回再限 200 个字符(`query: true` 的记录查询只管字节)。 */
|
|
30
|
+
export function checkId(id, { query = false } = {}) {
|
|
31
|
+
if (typeof id !== 'string' || !id || !id.isWellFormed()) throw invalid('id 须是非空的文本');
|
|
32
|
+
if (Buffer.byteLength(id) > MAX_ID_BYTES) throw invalid(`id 最多 ${MAX_ID_BYTES} 字节`);
|
|
33
|
+
if (!query && [...id].length > MAX_ID_CHARS) throw invalid(`id 最多 ${MAX_ID_CHARS} 个字符`);
|
|
34
|
+
return id;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 校验并规范发布的入参:`{ kind, id, body, audience }`,audience 缺省 `['public']`;body 复制一份纯 JSON。 */
|
|
38
|
+
export function checkPublish({ kind, id, body, audience = ['public'] } = {}) {
|
|
39
|
+
checkKind(kind);
|
|
40
|
+
checkId(id);
|
|
41
|
+
if (!isPlain(body)) throw invalid('body 须是对象');
|
|
42
|
+
let text;
|
|
43
|
+
try { text = JSON.stringify(body); } catch { throw invalid('body 须能转成 JSON'); }
|
|
44
|
+
if (Buffer.byteLength(text) > MAX_BODY_BYTES) throw invalid(`body 最多 ${MAX_BODY_BYTES} 字节`);
|
|
45
|
+
if (!Array.isArray(audience) || audience.length > MAX_AUDIENCE) throw invalid(`audience 须是至多 ${MAX_AUDIENCE} 项的数组`);
|
|
46
|
+
if (!audience.every(item => typeof item === 'string' && AUDIENCE.test(item))) throw invalid("audience 每项须是 'public' 或 ed25519:<64 位十六进制>");
|
|
47
|
+
return { kind, id, body: JSON.parse(text), audience: [...audience] };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 本机 Accord 记录(`coda/accord@1` 的 local)的证书状态:状态里写了 `certificate` 的按它判:null 没有身份,
|
|
52
|
+
* `active` 为 true 才是可发布,其余要换证书;旧宿主不写这个键,有作者就当可发布(发布遇 invalid_state 再落到需要证书)。
|
|
53
|
+
*/
|
|
54
|
+
export function certStateOf(accord) {
|
|
55
|
+
const status = accord?.status;
|
|
56
|
+
if (status && typeof status === 'object' && Object.hasOwn(status, 'certificate')) {
|
|
57
|
+
if (status.certificate === null) return 'no_identity';
|
|
58
|
+
return status.certificate?.active === true ? 'active' : 'needs_cert';
|
|
59
|
+
}
|
|
60
|
+
return accord?.spec?.author ? 'active' : 'no_identity';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const canonical = value => {
|
|
64
|
+
if (Array.isArray(value)) return value.map(canonical);
|
|
65
|
+
if (value && typeof value === 'object') return Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])]));
|
|
66
|
+
return value;
|
|
67
|
+
};
|
|
68
|
+
/** 规范化哈希:对象键递归按字典序排,再取 JSON 的 SHA-256(十六进制);键序不同的同一内容哈希相同。 */
|
|
69
|
+
export const canonicalHash = value => createHash('sha256').update(JSON.stringify(canonical(value))).digest('hex');
|
|
70
|
+
|
|
71
|
+
// ---- 条目与状态转换 ----
|
|
72
|
+
// 发布条目按 `p:${kind}:${id}` 索引,待撤条目按 `r:${targetAuthor}:${kind}:${id}` 索引(kind 不含冒号,两类前缀互斥,键不会撞):
|
|
73
|
+
// 不同作者对同一个 (kind, id) 排下的待撤互不相干,也不挡着对方撤自己的记录。
|
|
74
|
+
// 每次写入发布或撤回的意图都领一个递增的整数 `seq`(落在条目里,不看系统时钟):冲洗按它的先后执行,并据它判断旧撤回是否已被更晚的发布取代。
|
|
75
|
+
// 待发 { seq, kind, id, desired: 'publish', state: queued|paused|no_identity|needs_cert, body, audience, hash, lastError?, + 上次同步的元数据 }
|
|
76
|
+
// 已同步 { seq, kind, id, desired: 'publish', state: 'synced', hash, audience, lastAuthor, lastSyncedHash, lastSyncedAt }(没有 body)
|
|
77
|
+
// 待撤 { seq, kind, id, desired: 'retract', state: queued|no_identity|needs_cert, targetAuthor, lastError?, + 上次同步的元数据 }
|
|
78
|
+
// targetAuthor 是排队时的作者:换了作者就不再替新作者撤,等原作者回来
|
|
79
|
+
// 被拒 { …, state: 'error', lastError }:Accord 明确拒绝,不再自动重试;下一次发布或撤回同一条会替换它
|
|
80
|
+
export const entryKey = (kind, id) => `p:${kind}:${id}`;
|
|
81
|
+
export const retractKey = (author, kind, id) => `r:${author}:${kind}:${id}`;
|
|
82
|
+
// 序号计数器挂在整张表上(不可枚举,不算条目),随表一起写进 `outbox.json` 顶层:条目删了、发布被拒了,序号也不会倒退。
|
|
83
|
+
const withSeq = (entries, seq) => Object.defineProperty(entries, 'seq', { value: seq, writable: true, configurable: true });
|
|
84
|
+
/** 分配下一个意图序号:严格大于此前分配过的所有序号,随下一次写盘落地。 */
|
|
85
|
+
export const nextSeq = entries => withSeq(entries, (entries.seq ?? 0) + 1).seq;
|
|
86
|
+
export const keyOf = entry => entry.desired === 'retract' ? retractKey(entry.targetAuthor, entry.kind, entry.id) : entryKey(entry.kind, entry.id);
|
|
87
|
+
/** 等着发出去的状态(被拒的 error 不算,已同步的也不算)。 */
|
|
88
|
+
export const isPending = entry => ['queued', 'paused', 'no_identity', 'needs_cert'].includes(entry?.state);
|
|
89
|
+
|
|
90
|
+
const synced = prev => ({ ...(prev?.lastAuthor === undefined ? {} : { lastAuthor: prev.lastAuthor }),
|
|
91
|
+
...(prev?.lastSyncedHash === undefined ? {} : { lastSyncedHash: prev.lastSyncedHash }), ...(prev?.lastSyncedAt === undefined ? {} : { lastSyncedAt: prev.lastSyncedAt }) });
|
|
92
|
+
|
|
93
|
+
/** 同作者、同内容、已同步的发布不用再发。作者换了(`lastAuthor !== author`)必须重发。 */
|
|
94
|
+
export const canSkip = (prev, hash, author) =>
|
|
95
|
+
!!author && prev?.desired === 'publish' && prev.state === 'synced' && prev.lastAuthor === author && prev.lastSyncedHash === hash;
|
|
96
|
+
|
|
97
|
+
/** 一次发布的待发条目(带 body),保留上一次同步的元数据。 */
|
|
98
|
+
export const queuePublish = (prev, { kind, id, body, audience }, seq) =>
|
|
99
|
+
({ seq, kind, id, desired: 'publish', state: 'queued', body, audience, hash: canonicalHash({ body, audience }), ...synced(prev) });
|
|
100
|
+
|
|
101
|
+
/** 一次撤回的待撤条目:记下要撤的是哪个作者的记录,保留上一次同步的元数据。 */
|
|
102
|
+
export const queueRetract = (prev, kind, id, targetAuthor, seq) => ({ seq, kind, id, desired: 'retract', state: 'queued', targetAuthor, ...synced(prev) });
|
|
103
|
+
|
|
104
|
+
/** 换状态;`error` 是这次失败的原因,不给就清掉旧的。 */
|
|
105
|
+
export function withState(entry, state, error) {
|
|
106
|
+
const { lastError, ...rest } = entry;
|
|
107
|
+
return { ...rest, state, ...(error ? { lastError: error } : {}) };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 发布成功:释放 body,只留 `{ seq, kind, id, desired, state: 'synced', hash, audience, lastAuthor, lastSyncedHash, lastSyncedAt }`。 */
|
|
111
|
+
export const markSynced = (entry, author, now) =>
|
|
112
|
+
({ seq: entry.seq, kind: entry.kind, id: entry.id, desired: 'publish', state: 'synced', hash: entry.hash, audience: entry.audience, lastAuthor: author, lastSyncedHash: entry.hash, lastSyncedAt: now });
|
|
113
|
+
|
|
114
|
+
/** Accord 明确拒绝:不再留 body 和 audience,只留元数据与原因。 */
|
|
115
|
+
export const markRejected = (entry, message) =>
|
|
116
|
+
({ kind: entry.kind, id: entry.id, desired: entry.desired, state: 'error', lastError: message, ...(entry.hash === undefined ? {} : { hash: entry.hash }), ...synced(entry) });
|
|
117
|
+
|
|
118
|
+
/** 现在拦着这个条目、不让它外发的状态:暂停(只管发布,撤回不拦)、没有身份、需要证书;没有就是 null,可以发。 */
|
|
119
|
+
export function holdState(entry, certState, pausedKinds) {
|
|
120
|
+
if (entry.desired === 'publish' && pausedKinds.includes(entry.kind)) return 'paused';
|
|
121
|
+
return certState === 'active' ? null : certState;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ---- 持久化 ----
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 读出整张表 `{ 键: 条目 }`(磁盘上是 `{ seq, entries }`,旧版是直接平铺的条目);键按条目内容重新规范(兼容旧键名),
|
|
128
|
+
* 缺失、损坏、条目不成样子的都丢掉。序号计数器取顶层 `seq` 与现存条目最大序号中较大的。
|
|
129
|
+
*/
|
|
130
|
+
export async function readOutbox(dir) {
|
|
131
|
+
const parsed = await readJson(dir, 'outbox.json'), entries = withSeq({}, 0);
|
|
132
|
+
if (!isPlain(parsed)) return entries;
|
|
133
|
+
const stored = isPlain(parsed.entries) ? parsed.entries : parsed;
|
|
134
|
+
for (const entry of Object.values(stored)) {
|
|
135
|
+
if (isPlain(entry) && typeof entry.kind === 'string' && typeof entry.id === 'string' && ['publish', 'retract'].includes(entry.desired) && typeof entry.state === 'string'
|
|
136
|
+
&& (entry.desired === 'publish' || typeof entry.targetAuthor === 'string')) entries[keyOf(entry)] = entry;
|
|
137
|
+
}
|
|
138
|
+
return withSeq(entries, Math.max(Number.isSafeInteger(parsed.seq) ? parsed.seq : 0, ...Object.values(entries).map(entry => entry.seq ?? 0)));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const writeOutbox = (dir, entries) => writeJson(dir, 'outbox.json', { seq: entries.seq ?? 0, entries });
|
package/lib/policy.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// 网关的本机策略:哪些 kind 暂停外发。存在插件状态目录的 policy.json(卸载后保留);缺失或损坏时当 `{ pausedKinds: [] }`。
|
|
2
|
+
import { readJson, writeJson } from './json-file.mjs';
|
|
3
|
+
import { checkKind, validKind } from './outbox.mjs';
|
|
4
|
+
|
|
5
|
+
const NAME = 'policy.json';
|
|
6
|
+
|
|
7
|
+
/** 读出 `{ pausedKinds }`:只留合法且非保留的 kind,去重排序。 */
|
|
8
|
+
export async function readPolicy(dir) {
|
|
9
|
+
const parsed = await readJson(dir, NAME);
|
|
10
|
+
const kinds = Array.isArray(parsed?.pausedKinds) ? parsed.pausedKinds.filter(validKind) : [];
|
|
11
|
+
return { pausedKinds: [...new Set(kinds)].sort() };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** 暂停或恢复一个 kind 的外发;kind 不合法或是保留类型就抛错。`beforeWrite` 在写第一个字节前调用(它抛错就不写)。返回现在的策略。 */
|
|
15
|
+
export async function setKindPaused(dir, kind, paused, beforeWrite) {
|
|
16
|
+
checkKind(kind);
|
|
17
|
+
const { pausedKinds } = await readPolicy(dir), next = new Set(pausedKinds);
|
|
18
|
+
if (paused) next.add(kind); else next.delete(kind);
|
|
19
|
+
const policy = { pausedKinds: [...next].sort() };
|
|
20
|
+
await writeJson(dir, NAME, policy, beforeWrite);
|
|
21
|
+
return policy;
|
|
22
|
+
}
|
package/main.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// 好友插件的模块(Coda 的 docs/plugins.md「插件宿主」)。好友页自己的 Accord 读写在页面里发起(页面用自己的 coda.query /
|
|
2
|
+
// coda.call / coda.watch);模块管两件事:
|
|
3
|
+
// - 好友的本地备注:存在插件自己的持久目录 notes.json 里,不外发,页面通过视图消息读写,
|
|
4
|
+
// 也能用 `coda self notes.list|notes.set|notes.delete` 读写;
|
|
5
|
+
// - 业务无关的社交网关 friends/social@1(lib/gateway.mjs):别的插件经它读好友、发布与撤回记录,全部透传 coda/accord@1;
|
|
6
|
+
// 发布策略用 `coda self policy.get|policy.setKind` 读写。
|
|
7
|
+
import { createGateway } from './lib/gateway.mjs';
|
|
8
|
+
import { deleteNote, readNotes, setNote } from './lib/notes.mjs';
|
|
9
|
+
|
|
10
|
+
let dir = null, gateway = null;
|
|
11
|
+
const handles = [];
|
|
12
|
+
|
|
13
|
+
export async function activate(coda) {
|
|
14
|
+
dir = coda.plugin.state;
|
|
15
|
+
const actions = {
|
|
16
|
+
'notes.list': () => readNotes(dir),
|
|
17
|
+
'notes.set': ({ node, note } = {}) => setNote(dir, node, note),
|
|
18
|
+
'notes.delete': ({ node } = {}) => deleteNote(dir, node),
|
|
19
|
+
};
|
|
20
|
+
const run = (name, input) => {
|
|
21
|
+
if (!dir) throw new Error('这台机器没有插件状态目录,备注存不下');
|
|
22
|
+
return actions[name](input);
|
|
23
|
+
};
|
|
24
|
+
for (const name of Object.keys(actions)) handles.push(coda.self.handle(name, input => run(name, input ?? {})));
|
|
25
|
+
coda.views.register('friends', {
|
|
26
|
+
open(view) {
|
|
27
|
+
view.onMessage(async message => {
|
|
28
|
+
const name = message?.type;
|
|
29
|
+
if (!Object.hasOwn(actions, name) || typeof message.rid !== 'string') return;
|
|
30
|
+
try { view.postMessage({ type: 'reply', rid: message.rid, ok: true, value: await run(name, message) }); }
|
|
31
|
+
catch (e) { view.postMessage({ type: 'reply', rid: message.rid, ok: false, error: String(e?.message ?? e) }); }
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
gateway = createGateway(coda, dir);
|
|
36
|
+
for (const [name, fn] of Object.entries(gateway.policy)) handles.push(coda.self.handle(name, input => fn(input ?? {})));
|
|
37
|
+
await gateway.start();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function deactivate() {
|
|
41
|
+
gateway?.stop();
|
|
42
|
+
gateway = null;
|
|
43
|
+
for (const handle of handles.splice(0)) handle?.dispose?.();
|
|
44
|
+
dir = null;
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,211 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coda-console/friends",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"id": "friends",
|
|
4
|
+
"displayName": "好友",
|
|
5
|
+
"description": "管理 Accord 身份、个人名片与熟人好友通道",
|
|
6
|
+
"icon": { "symbol": "person.2.fill", "color": "blue" },
|
|
7
|
+
"version": "0.2.0",
|
|
8
|
+
"categories": [
|
|
9
|
+
"Skills 与工具"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"engines": {
|
|
13
|
+
"coda": 13
|
|
14
|
+
},
|
|
15
|
+
"main": "main.mjs",
|
|
16
|
+
"activationEvents": [
|
|
17
|
+
"onStartupFinished"
|
|
18
|
+
],
|
|
19
|
+
"uses": {
|
|
20
|
+
"coda/accord@1": [
|
|
21
|
+
"read",
|
|
22
|
+
"publish",
|
|
23
|
+
"manage"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
"contributes": {
|
|
27
|
+
"views": [
|
|
28
|
+
{
|
|
29
|
+
"id": "friends",
|
|
30
|
+
"title": "好友",
|
|
31
|
+
"entry": "view/index.html",
|
|
32
|
+
"in": [
|
|
33
|
+
"page"
|
|
34
|
+
],
|
|
35
|
+
"icon": "person.2.fill",
|
|
36
|
+
"frame": "document"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"protocols": [
|
|
40
|
+
{
|
|
41
|
+
"name": "friends/social@1",
|
|
42
|
+
"title": "好友社交网关",
|
|
43
|
+
"description": "业务无关的好友网关:读好友与好友分享的记录,向好友发布、撤回记录;签名与记录全部透传 coda/accord@1,没有身份或证书过期时在本机排队,恢复后自动补发。",
|
|
44
|
+
"spec": {
|
|
45
|
+
"type": "object",
|
|
46
|
+
"properties": { "version": { "const": 1 } },
|
|
47
|
+
"required": ["version"],
|
|
48
|
+
"additionalProperties": false
|
|
49
|
+
},
|
|
50
|
+
"status": {
|
|
51
|
+
"type": "object",
|
|
52
|
+
"properties": {
|
|
53
|
+
"author": { "type": ["string", "null"] },
|
|
54
|
+
"certState": { "enum": ["no_identity", "needs_cert", "active"] },
|
|
55
|
+
"certUntil": { "type": "integer", "minimum": 0 },
|
|
56
|
+
"friendCount": { "type": "integer", "minimum": 0 },
|
|
57
|
+
"pendingCount": { "type": "integer", "minimum": 0 },
|
|
58
|
+
"pausedKinds": { "type": "array", "items": { "type": "string" } }
|
|
59
|
+
},
|
|
60
|
+
"required": ["author", "certState", "friendCount", "pendingCount", "pausedKinds"],
|
|
61
|
+
"additionalProperties": false
|
|
62
|
+
},
|
|
63
|
+
"operations": {
|
|
64
|
+
"friends": {
|
|
65
|
+
"safe": true,
|
|
66
|
+
"input": {
|
|
67
|
+
"type": "object",
|
|
68
|
+
"properties": { "includePending": { "type": "boolean" } },
|
|
69
|
+
"additionalProperties": false
|
|
70
|
+
},
|
|
71
|
+
"result": {
|
|
72
|
+
"type": "object",
|
|
73
|
+
"properties": {
|
|
74
|
+
"selfAuthor": { "type": ["string", "null"] },
|
|
75
|
+
"certState": { "enum": ["no_identity", "needs_cert", "active"] },
|
|
76
|
+
"friends": { "type": "array", "items": { "type": "object" } },
|
|
77
|
+
"truncated": { "type": "boolean" }
|
|
78
|
+
},
|
|
79
|
+
"required": ["selfAuthor", "certState", "friends", "truncated"],
|
|
80
|
+
"additionalProperties": false
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"records": {
|
|
84
|
+
"safe": true,
|
|
85
|
+
"input": {
|
|
86
|
+
"type": "object",
|
|
87
|
+
"properties": {
|
|
88
|
+
"kind": { "type": "string", "minLength": 1 },
|
|
89
|
+
"author": { "type": "string" },
|
|
90
|
+
"id": { "type": "string", "minLength": 1, "maxLength": 256 },
|
|
91
|
+
"limit": { "type": "integer", "minimum": 1, "maximum": 200 },
|
|
92
|
+
"cursor": { "type": "string" },
|
|
93
|
+
"includeAudience": { "type": "boolean" }
|
|
94
|
+
},
|
|
95
|
+
"required": ["kind"],
|
|
96
|
+
"additionalProperties": false
|
|
97
|
+
},
|
|
98
|
+
"result": {
|
|
99
|
+
"type": "object",
|
|
100
|
+
"properties": {
|
|
101
|
+
"records": { "type": "array", "items": { "type": "object" } },
|
|
102
|
+
"truncated": { "type": "boolean" },
|
|
103
|
+
"nextCursor": { "type": "string" }
|
|
104
|
+
},
|
|
105
|
+
"required": ["records", "truncated"]
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"publish": {
|
|
109
|
+
"idempotent": true,
|
|
110
|
+
"input": {
|
|
111
|
+
"type": "object",
|
|
112
|
+
"properties": {
|
|
113
|
+
"kind": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}(?:/[a-z][a-z0-9-]{0,63})?$" },
|
|
114
|
+
"id": { "type": "string", "minLength": 1, "maxLength": 256 },
|
|
115
|
+
"body": { "type": "object" },
|
|
116
|
+
"audience": {
|
|
117
|
+
"type": "array",
|
|
118
|
+
"items": { "type": "string", "pattern": "^(?:public|ed25519:[0-9a-f]{64})$" },
|
|
119
|
+
"maxItems": 500,
|
|
120
|
+
"default": ["public"]
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"required": ["kind", "id", "body"],
|
|
124
|
+
"additionalProperties": false
|
|
125
|
+
},
|
|
126
|
+
"result": {
|
|
127
|
+
"type": "object",
|
|
128
|
+
"properties": {
|
|
129
|
+
"state": { "enum": ["synced", "queued", "paused", "no_identity", "needs_cert", "error"] },
|
|
130
|
+
"skipped": { "type": "boolean" },
|
|
131
|
+
"author": { "type": ["string", "null"] },
|
|
132
|
+
"version": { "type": "integer", "minimum": 0 },
|
|
133
|
+
"error": { "type": "string" }
|
|
134
|
+
},
|
|
135
|
+
"required": ["state"],
|
|
136
|
+
"additionalProperties": false
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"retract": {
|
|
140
|
+
"idempotent": true,
|
|
141
|
+
"input": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"properties": {
|
|
144
|
+
"kind": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}(?:/[a-z][a-z0-9-]{0,63})?$" },
|
|
145
|
+
"id": { "type": "string", "minLength": 1, "maxLength": 256 }
|
|
146
|
+
},
|
|
147
|
+
"required": ["kind"],
|
|
148
|
+
"additionalProperties": false
|
|
149
|
+
},
|
|
150
|
+
"result": {
|
|
151
|
+
"type": "object",
|
|
152
|
+
"properties": {
|
|
153
|
+
"state": { "enum": ["retracted", "queued", "no_identity", "needs_cert", "error"] },
|
|
154
|
+
"count": { "type": "integer", "minimum": 0 },
|
|
155
|
+
"queued": { "type": "integer", "minimum": 0 },
|
|
156
|
+
"truncated": { "type": "boolean" },
|
|
157
|
+
"error": { "type": "string" }
|
|
158
|
+
},
|
|
159
|
+
"required": ["state", "count"],
|
|
160
|
+
"additionalProperties": false
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"outbox": {
|
|
164
|
+
"safe": true,
|
|
165
|
+
"input": {
|
|
166
|
+
"type": "object",
|
|
167
|
+
"properties": { "kind": { "type": "string" } },
|
|
168
|
+
"additionalProperties": false
|
|
169
|
+
},
|
|
170
|
+
"result": {
|
|
171
|
+
"type": "object",
|
|
172
|
+
"properties": {
|
|
173
|
+
"author": { "type": ["string", "null"] },
|
|
174
|
+
"certState": { "enum": ["no_identity", "needs_cert", "active"] },
|
|
175
|
+
"pausedKinds": { "type": "array", "items": { "type": "string" } },
|
|
176
|
+
"pendingCount": { "type": "integer", "minimum": 0 },
|
|
177
|
+
"items": {
|
|
178
|
+
"type": "array",
|
|
179
|
+
"items": {
|
|
180
|
+
"type": "object",
|
|
181
|
+
"properties": {
|
|
182
|
+
"kind": { "type": "string" },
|
|
183
|
+
"id": { "type": "string" },
|
|
184
|
+
"desired": { "enum": ["publish", "retract"] },
|
|
185
|
+
"state": { "type": "string" },
|
|
186
|
+
"lastSyncedAt": { "type": "integer", "minimum": 0 },
|
|
187
|
+
"lastError": { "type": "string" }
|
|
188
|
+
},
|
|
189
|
+
"required": ["kind", "id", "desired", "state"],
|
|
190
|
+
"additionalProperties": false
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
"required": ["author", "certState", "pausedKinds", "pendingCount", "items"],
|
|
195
|
+
"additionalProperties": false
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
"permissions": {
|
|
200
|
+
"read": { "title": "查看好友列表与读取好友分享的记录", "read": true, "operations": ["friends", "records"] },
|
|
201
|
+
"publish": { "title": "通过好友网关发布、撤回记录与查看待发队列", "operations": ["publish", "retract", "outbox"] }
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
"protocolImplementations": [
|
|
206
|
+
"friends/social@1"
|
|
207
|
+
]
|
|
208
|
+
},
|
|
5
209
|
"license": "MIT",
|
|
6
210
|
"repository": {
|
|
7
211
|
"type": "git",
|
|
@@ -10,5 +214,10 @@
|
|
|
10
214
|
},
|
|
11
215
|
"publishConfig": {
|
|
12
216
|
"access": "public"
|
|
13
|
-
}
|
|
217
|
+
},
|
|
218
|
+
"files": [
|
|
219
|
+
"main.mjs",
|
|
220
|
+
"lib",
|
|
221
|
+
"view"
|
|
222
|
+
]
|
|
14
223
|
}
|