@blogmcp/sdk 0.10.1 → 0.11.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.
Files changed (53) hide show
  1. package/dist/community/channels.d.ts +3 -2
  2. package/dist/community/client.d.ts +129 -2
  3. package/dist/community/client.js +231 -161
  4. package/dist/community/forum.d.ts +82 -0
  5. package/dist/community/forum.js +96 -0
  6. package/dist/community/index.d.ts +14 -7
  7. package/dist/community/index.js +185 -121
  8. package/dist/community/links.d.ts +38 -0
  9. package/dist/community/links.js +98 -71
  10. package/dist/community/messages.cs.d.ts +160 -1
  11. package/dist/community/messages.cs.js +178 -1
  12. package/dist/community/messages.d.ts +19 -1
  13. package/dist/community/messages.en.d.ts +150 -1
  14. package/dist/community/messages.en.js +161 -1
  15. package/dist/community/messages.js +37 -28
  16. package/dist/community/outcome.d.ts +8 -3
  17. package/dist/community/outcome.js +61 -20
  18. package/dist/community/poll.d.ts +28 -4
  19. package/dist/community/poll.js +70 -47
  20. package/dist/community/realtime/index.d.ts +19 -3
  21. package/dist/community/realtime/index.js +175 -145
  22. package/dist/community/routes.d.ts +36 -1
  23. package/dist/community/routes.js +51 -21
  24. package/dist/community/server/bff.d.ts +25 -2
  25. package/dist/community/server/bff.js +135 -118
  26. package/dist/community/server/host-routes.d.ts +3 -0
  27. package/dist/community/server/host-routes.js +17 -0
  28. package/dist/community/server/index.d.ts +5 -1
  29. package/dist/community/shapes.d.ts +634 -7
  30. package/dist/community/shapes.js +92 -61
  31. package/dist/community/store.d.ts +15 -0
  32. package/dist/community/store.js +65 -61
  33. package/dist/community/topic.d.ts +173 -0
  34. package/dist/community/topic.js +225 -0
  35. package/package.json +3 -3
  36. package/src/community/channels.ts +3 -2
  37. package/src/community/client.ts +209 -5
  38. package/src/community/forum.ts +209 -0
  39. package/src/community/index.ts +146 -2
  40. package/src/community/links.ts +64 -4
  41. package/src/community/messages.cs.ts +179 -1
  42. package/src/community/messages.en.ts +162 -1
  43. package/src/community/messages.ts +25 -2
  44. package/src/community/outcome.ts +47 -1
  45. package/src/community/poll.ts +79 -17
  46. package/src/community/realtime/index.ts +124 -48
  47. package/src/community/routes.ts +42 -1
  48. package/src/community/server/bff.ts +89 -30
  49. package/src/community/server/host-routes.ts +20 -0
  50. package/src/community/server/index.ts +5 -1
  51. package/src/community/shapes.ts +662 -6
  52. package/src/community/store.ts +11 -5
  53. package/src/community/topic.ts +521 -0
@@ -1,240 +1,310 @@
1
- import { communityFailureOf as R, isLoggedCommunityOutcome as j, communityOutcomeOf as D } from "./outcome.js";
2
- import { COMMUNITY_OPS as L } from "./routes.js";
3
- import { isKnownNeed as q } from "./shapes.js";
4
- import { assertCommunityBase as P, fetchTransport as F } from "./transport.js";
5
- const M = 1e4, U = 2147483647;
1
+ import { communityFailureOf as P, isLoggedCommunityOutcome as j, communityOutcomeOf as x } from "./outcome.js";
2
+ import { COMMUNITY_OPS as z } from "./routes.js";
3
+ import { isKnownNeed as D } from "./shapes.js";
4
+ import { assertCommunityBase as L, fetchTransport as U } from "./transport.js";
5
+ const M = 1e4, F = 2147483647;
6
6
  let E = !1;
7
- function z(e) {
7
+ function B(e) {
8
8
  if (e === void 0) return M;
9
9
  const n = typeof e == "number" ? Math.floor(e) : Number.NaN;
10
- return n >= 1 && n <= U ? n : (E || (E = !0, console.warn("[community] timeoutMs is not a number of milliseconds from 1 to 2147483647 — the default 10 s is used.")), M);
10
+ return n >= 1 && n <= F ? n : (E || (E = !0, console.warn("[community] timeoutMs is not a number of milliseconds from 1 to 2147483647 — the default 10 s is used.")), M);
11
11
  }
12
- const c = (e) => typeof e == "object" && e !== null && !Array.isArray(e), I = (e) => typeof e == "string", h = Array.isArray, K = Object.freeze({
13
- string: I,
12
+ const d = (e) => typeof e == "object" && e !== null && !Array.isArray(e), h = (e) => typeof e == "string", g = Array.isArray, K = Object.freeze({
13
+ string: h,
14
14
  number: (e) => typeof e == "number",
15
15
  boolean: (e) => typeof e == "boolean",
16
- array: h,
17
- record: c
18
- }), s = (e) => Object.freeze({ ...e }), B = Object.freeze({
19
- "discussions.list": s({ articleId: "string", messages: "array", viewer: "record" }),
20
- "discussions.head": s({ heads: "array" }),
21
- "messages.post": s({ message: "record", warnings: "array" }),
22
- "messages.edit": s({ message: "record", warnings: "array" }),
23
- "messages.delete": s({ message: "record" }),
24
- "messages.report": s({ caseId: "string" }),
25
- "reactions.set": s({ reactions: "record" }),
26
- "blocks.set": s({ blocked: "boolean" }),
27
- "blocks.list": s({ blocks: "array" }),
28
- "profile.get": s({ author: "record" }),
29
- "me.get": s({ needs: "array" }),
30
- "me.onboard": s({ needs: "array" }),
31
- "me.updateProfile": s({ profile: "record" }),
32
- "me.notifications.list": s({ items: "array" }),
33
- "me.notifications.markRead": s({ updated: "number" }),
34
- "me.notifications.unreadCount": s({ count: "number" }),
35
- "me.settings.get": s({ settings: "record" }),
36
- "me.settings.update": s({ settings: "record" }),
37
- "me.settings.unsubscribeDigest": s({ unsubscribed: "boolean" }),
38
- "me.mutes.set": s({ muted: "boolean" }),
39
- "me.mutes.list": s({ items: "array" }),
40
- "me.push.vapid": s({ publicKey: "string", keyId: "string" }),
41
- "me.push.subscribe": s({ subscribed: "boolean", keyId: "string" }),
42
- "me.push.unsubscribe": s({ unsubscribed: "boolean" }),
43
- "me.push.status": s({ subscribed: "boolean" }),
44
- "me.realtime.token": s({ token: "string", url: "string", expiresInS: "number" }),
45
- "realtime.subscribeToken": s({ token: "string" }),
46
- "me.decisions.list": s({ items: "array" }),
47
- "me.decisions.get": s({ decisionId: "string" }),
48
- "me.appeals.file": s({ appealId: "string" }),
49
- "me.appeals.withdraw": s({ appealId: "string" }),
50
- "me.appeals.list": s({ items: "array" }),
51
- "me.reports.list": s({ items: "array" }),
52
- "me.consents.withdraw": s({ state: "string" }),
53
- "me.export": s({ generatedAt: "string" }),
54
- "me.erase": s({ purgeAfter: "string" }),
55
- "me.cancelErase": s({ status: "string" }),
56
- "legal.current": s({ textId: "string" }),
57
- "notices.submit": s({ caseId: "string", receipt: "string" }),
58
- "notices.status": s({ status: "string" }),
59
- "notices.appeal": s({ appealId: "string" }),
60
- "notices.withdrawAppeal": s({ appealId: "string" })
61
- }), W = (e, n) => Object.entries(B[e]).every(([r, u]) => K[u](n[r]));
62
- function m(e, n) {
63
- const r = {};
64
- if (!c(e)) return r;
65
- for (const u of n) e[u] !== void 0 && (r[u] = e[u]);
66
- return r;
16
+ array: g,
17
+ record: d
18
+ }), t = (e) => Object.freeze({ ...e }), W = Object.freeze({
19
+ "discussions.list": t({ articleId: "string", messages: "array", viewer: "record" }),
20
+ "discussions.head": t({ heads: "array" }),
21
+ "messages.post": t({ message: "record", warnings: "array" }),
22
+ "messages.edit": t({ message: "record", warnings: "array" }),
23
+ "messages.delete": t({ message: "record" }),
24
+ "messages.report": t({ caseId: "string" }),
25
+ "reactions.set": t({ reactions: "record" }),
26
+ "blocks.set": t({ blocked: "boolean" }),
27
+ "blocks.list": t({ blocks: "array" }),
28
+ "profile.get": t({ author: "record" }),
29
+ "me.get": t({ needs: "array" }),
30
+ "me.onboard": t({ needs: "array" }),
31
+ "me.updateProfile": t({ profile: "record" }),
32
+ "me.notifications.list": t({ items: "array" }),
33
+ "me.notifications.markRead": t({ updated: "number" }),
34
+ "me.notifications.unreadCount": t({ count: "number" }),
35
+ "me.settings.get": t({ settings: "record" }),
36
+ "me.settings.update": t({ settings: "record" }),
37
+ "me.settings.unsubscribeDigest": t({ unsubscribed: "boolean" }),
38
+ "me.mutes.set": t({ muted: "boolean" }),
39
+ "me.mutes.list": t({ items: "array" }),
40
+ "me.push.vapid": t({ publicKey: "string", keyId: "string" }),
41
+ "me.push.subscribe": t({ subscribed: "boolean", keyId: "string" }),
42
+ "me.push.unsubscribe": t({ unsubscribed: "boolean" }),
43
+ "me.push.status": t({ subscribed: "boolean" }),
44
+ "me.realtime.token": t({ token: "string", url: "string", expiresInS: "number" }),
45
+ "realtime.subscribeToken": t({ token: "string" }),
46
+ "me.decisions.list": t({ items: "array" }),
47
+ "me.decisions.get": t({ decisionId: "string" }),
48
+ "me.appeals.file": t({ appealId: "string" }),
49
+ "me.appeals.withdraw": t({ appealId: "string" }),
50
+ "me.appeals.list": t({ items: "array" }),
51
+ "me.reports.list": t({ items: "array" }),
52
+ "me.consents.withdraw": t({ state: "string" }),
53
+ "me.export": t({ generatedAt: "string" }),
54
+ "me.erase": t({ purgeAfter: "string" }),
55
+ "me.cancelErase": t({ status: "string" }),
56
+ "legal.current": t({ textId: "string" }),
57
+ "notices.submit": t({ caseId: "string", receipt: "string" }),
58
+ "notices.status": t({ status: "string" }),
59
+ "notices.appeal": t({ appealId: "string" }),
60
+ "notices.withdrawAppeal": t({ appealId: "string" }),
61
+ // M3 (m3-contracts.md §3.2–§3.4).
62
+ "forum.categories.list": t({ categories: "array" }),
63
+ "forum.topics.list": t({ category: "record", items: "array" }),
64
+ "forum.topics.get": t({ topic: "record", messages: "array", viewer: "record" }),
65
+ "forum.topics.head": t({ heads: "array" }),
66
+ "forum.topics.create": t({ topic: "record", message: "record", warnings: "array" }),
67
+ "forum.search": t({ results: "array", page: "number", hasMore: "boolean" }),
68
+ "me.follows.set": t({ following: "boolean" }),
69
+ "me.follows.list": t({ follows: "array" }),
70
+ "moderation.queue": t({ items: "array" }),
71
+ "moderation.getCase": t({ case: "record" }),
72
+ "moderation.decide": t({ dryRun: "boolean", statement: "string" }),
73
+ "moderation.remove": t({ decision: "record", statement: "string" }),
74
+ // The bare envelope `{ ok: true }` (§3.4): the moderator learns nothing of the case it opened or joined.
75
+ "moderation.escalate": t({}),
76
+ "moderation.setTopicState": t({ topic: "record" }),
77
+ "moderation.moveTopic": t({ topic: "record" }),
78
+ "moderation.pinTopic": t({ topic: "record" }),
79
+ // A union: COMMUNITY_ANSWER_VARIANTS says which shapes count.
80
+ "moderation.reviewPremod": t({})
81
+ }), Y = Object.freeze({
82
+ // approve → the published message; reject → the removal and its statement (§3.4, §4.2).
83
+ "moderation.reviewPremod": Object.freeze([t({ message: "record" }), t({ decision: "record", statement: "string" })])
84
+ }), _ = (e, n) => Object.entries(e).every(([o, m]) => K[m](n[o])), X = (e, n) => {
85
+ if (!_(W[e], n)) return !1;
86
+ const o = Y[e];
87
+ return o === void 0 || o.some((m) => _(m, n));
88
+ };
89
+ function u(e, n) {
90
+ const o = {};
91
+ if (!d(e)) return o;
92
+ for (const m of n) e[m] !== void 0 && (o[m] = e[m]);
93
+ return o;
67
94
  }
68
- function _(e) {
69
- return c(e) ? "conversationId" in e ? m(e, ["conversationId", "seq"]) : "memberId" in e ? m(e, ["memberId"]) : "handle" in e ? m(e, ["handle"]) : m(e, ["articleId"]) : e;
95
+ function R(e) {
96
+ return d(e) ? "conversationId" in e ? u(e, ["conversationId", "seq"]) : "memberId" in e ? u(e, ["memberId"]) : "handle" in e ? u(e, ["handle"]) : u(e, ["articleId"]) : e;
70
97
  }
71
- const N = /^[A-Za-z0-9_.:-]{1,64}$/, S = 20;
72
- function X(e) {
73
- if (h(e))
74
- return e.filter((n) => I(n) && N.test(n)).slice(0, S);
98
+ const q = /^[A-Za-z0-9_.:-]{1,64}$/, O = 20;
99
+ function $(e) {
100
+ if (g(e))
101
+ return e.filter((n) => h(n) && q.test(n)).slice(0, O);
75
102
  }
76
- function Y(e) {
77
- return h(e) ? e.filter(q).slice(0, S) : void 0;
103
+ function G(e) {
104
+ return g(e) ? e.filter(D).slice(0, O) : void 0;
78
105
  }
79
106
  function H(e) {
80
- return h(e) ? e.map((r) => c(r) ? r.path : r).filter((r) => I(r) && r.length <= 128).slice(0, S) : void 0;
107
+ return g(e) ? e.map((o) => d(o) ? o.path : o).filter((o) => h(o) && o.length <= 128).slice(0, O) : void 0;
108
+ }
109
+ function V(e) {
110
+ if (!g(e)) return;
111
+ const n = e.map((o) => d(o) ? o.code : void 0).filter((o) => h(o) && q.test(o));
112
+ return n.length > 0 ? [...new Set(n)].slice(0, O) : void 0;
81
113
  }
82
- function Z(e) {
83
- if (!h(e)) return;
84
- const n = e.map((r) => c(r) ? r.code : void 0).filter((r) => I(r) && N.test(r));
85
- return n.length > 0 ? [...new Set(n)].slice(0, S) : void 0;
114
+ const Z = /^[a-z][a-z0-9_]{0,63}$/;
115
+ function J(e) {
116
+ return h(e) && Z.test(e) ? e : void 0;
86
117
  }
87
- function v(e) {
118
+ function Q(e) {
119
+ return d(e) ? "conversationId" in e ? u(e, ["conversationId"]) : u(e, ["categoryId"]) : e;
120
+ }
121
+ function T(e) {
88
122
  return typeof e == "number" && Number.isFinite(e) && e >= 0 ? Math.ceil(e) : void 0;
89
123
  }
90
- function $(e, n) {
91
- const r = { ok: !1, code: D(e.code) }, u = v(e.retryAfterS) ?? v(n.retryAfterS);
92
- u !== void 0 && (r.retryAfterS = u);
93
- const b = Y(e.needs);
94
- b && (r.needs = b);
95
- const l = X(e.codes);
96
- l && (r.codes = l), I(e.until) && (r.until = e.until);
97
- const i = H(e.issues);
98
- i && (r.fields = i);
99
- const a = Z(e.issues);
100
- return a && (r.issueCodes = a), r;
124
+ function ee(e, n) {
125
+ const o = { ok: !1, code: x(e.code) }, m = T(e.retryAfterS) ?? T(n.retryAfterS);
126
+ m !== void 0 && (o.retryAfterS = m);
127
+ const b = G(e.needs);
128
+ b && (o.needs = b);
129
+ const l = $(e.codes);
130
+ l && (o.codes = l), h(e.until) && (o.until = e.until);
131
+ const r = J(e.surface);
132
+ r !== void 0 && (o.surface = r);
133
+ const c = H(e.issues);
134
+ c && (o.fields = c);
135
+ const s = V(e.issues);
136
+ return s && (o.issueCodes = s), o;
101
137
  }
102
- function ee(e) {
103
- P(e?.base);
104
- const n = e.transport ?? F(e.base, e.now ? { now: e.now } : {}), r = z(e.timeoutMs), u = e.logger, b = (t, o, d, k) => {
105
- if (!(!u || !j(o)))
138
+ function ie(e) {
139
+ L(e?.base);
140
+ const n = e.transport ?? U(e.base, e.now ? { now: e.now } : {}), o = B(e.timeoutMs), m = e.logger, b = (s, i, a, v) => {
141
+ if (!(!m || !j(i)))
106
142
  try {
107
- u({ op: t, outcome: o, kbCode: d, status: k });
143
+ m({ op: s, outcome: i, kbCode: a, status: v });
108
144
  } catch {
109
145
  }
110
146
  };
111
- async function l(t, o, d) {
112
- const k = L[t], A = new AbortController(), O = d?.signal, T = () => A.abort();
113
- O?.aborted ? A.abort() : O?.addEventListener("abort", T, { once: !0 });
114
- const x = setTimeout(() => A.abort(), r);
115
- let g;
147
+ async function l(s, i, a) {
148
+ const v = z[s], k = new AbortController(), A = a?.signal, S = () => k.abort();
149
+ A?.aborted ? k.abort() : A?.addEventListener("abort", S, { once: !0 });
150
+ const N = setTimeout(() => k.abort(), o);
151
+ let y;
116
152
  try {
117
- g = await n(k, o, A.signal);
153
+ y = await n(v, i, k.signal);
118
154
  } catch (p) {
119
- const w = R(p);
120
- return O?.aborted || b(t, w.code, null, null), w;
155
+ const w = P(p);
156
+ return A?.aborted || b(s, w.code, null, null), w;
121
157
  } finally {
122
- clearTimeout(x), O?.removeEventListener("abort", T);
158
+ clearTimeout(N), A?.removeEventListener("abort", S);
123
159
  }
124
- const y = typeof g?.status == "number" ? g.status : 0, f = g?.body;
125
- if (c(f) && f.ok === !1 && I(f.code) && f.code !== "") {
126
- const p = $(f, g);
127
- return b(t, p.code, f.code.slice(0, 64), y), p;
160
+ const I = typeof y?.status == "number" ? y.status : 0, f = y?.body;
161
+ if (d(f) && f.ok === !1 && h(f.code) && f.code !== "") {
162
+ const p = ee(f, y);
163
+ return b(s, p.code, f.code.slice(0, 64), I), p;
128
164
  }
129
- if (y >= 200 && y < 300 && c(f) && f.ok === !0) {
165
+ if (I >= 200 && I < 300 && d(f) && f.ok === !0) {
130
166
  const { ok: p, ...w } = f;
131
- return W(t, w) ? { ok: !0, value: w } : (b(t, "unavailable", null, y), { ok: !1, code: "unavailable" });
167
+ return X(s, w) ? { ok: !0, value: w } : (b(s, "unavailable", null, I), { ok: !1, code: "unavailable" });
132
168
  }
133
- if (y === 429) {
134
- const p = v(g.retryAfterS);
169
+ if (I === 429) {
170
+ const p = T(y.retryAfterS);
135
171
  return p === void 0 ? { ok: !1, code: "fast" } : { ok: !1, code: "fast", retryAfterS: p };
136
172
  }
137
- b(t, "unavailable", null, y);
138
- const C = y === 503 ? v(g.retryAfterS) : void 0;
173
+ b(s, "unavailable", null, I);
174
+ const C = I === 503 ? T(y.retryAfterS) : void 0;
139
175
  return C === void 0 ? { ok: !1, code: "unavailable" } : { ok: !1, code: "unavailable", retryAfterS: C };
140
176
  }
141
- const i = (t, o) => (d, k) => l(t, m(d, o), k), a = (t) => (o) => l(t, {}, o);
177
+ const r = (s, i) => (a, v) => l(s, u(a, i), v), c = (s) => (i) => l(s, {}, i);
142
178
  return {
143
179
  discussions: {
144
- list: i("discussions.list", ["articleId", "languageCode", "cursor"]),
145
- head: (t, o) => l("discussions.head", { articleIds: c(t) && h(t.articleIds) ? [...t.articleIds] : [] }, o)
180
+ list: r("discussions.list", ["articleId", "languageCode", "cursor"]),
181
+ head: (s, i) => l("discussions.head", { articleIds: d(s) && g(s.articleIds) ? [...s.articleIds] : [] }, i)
146
182
  },
147
183
  messages: {
148
- post: i("messages.post", ["articleId", "body", "replyToSeq", "clientMsgId", "languageCode", "confirmations"]),
149
- edit: i("messages.edit", ["conversationId", "seq", "body", "confirmations"]),
150
- delete: i("messages.delete", ["conversationId", "seq"]),
151
- report: i("messages.report", ["conversationId", "seq", "category", "ruleId", "note"])
184
+ // M3: `conversationId` (a topic) in place of `articleId`; the caller's type allows exactly one, and both are sent as given.
185
+ post: r("messages.post", ["articleId", "conversationId", "body", "replyToSeq", "clientMsgId", "languageCode", "confirmations"]),
186
+ edit: r("messages.edit", ["conversationId", "seq", "body", "title", "confirmations"]),
187
+ delete: r("messages.delete", ["conversationId", "seq"]),
188
+ report: r("messages.report", ["conversationId", "seq", "category", "ruleId", "note"])
152
189
  },
153
190
  reactions: {
154
- set: (t, o) => l("reactions.set", { target: _(t?.target), emoji: t?.emoji ?? null }, o)
191
+ set: (s, i) => l("reactions.set", { target: R(s?.target), emoji: s?.emoji ?? null }, i)
155
192
  },
156
193
  blocks: {
157
- set: i("blocks.set", ["memberId", "blocked"]),
158
- list: a("blocks.list")
194
+ set: r("blocks.set", ["memberId", "blocked"]),
195
+ list: c("blocks.list")
159
196
  },
160
197
  profile: {
161
- get: (t, o) => l("profile.get", c(t) && "handle" in t ? m(t, ["handle"]) : m(t, ["memberId"]), o)
198
+ get: (s, i) => l("profile.get", d(s) && "handle" in s ? u(s, ["handle"]) : u(s, ["memberId"]), i)
162
199
  },
163
200
  me: {
164
- get: a("me.get"),
165
- onboard: i("me.onboard", ["ageBand", "rulesTextId", "art9TextId", "art9Refused", "displayName", "handle", "avatarPreset"]),
166
- updateProfile: i("me.updateProfile", ["displayName", "handle", "avatarPreset", "bio"]),
201
+ get: c("me.get"),
202
+ onboard: r("me.onboard", ["ageBand", "rulesTextId", "art9TextId", "art9Refused", "displayName", "handle", "avatarPreset"]),
203
+ updateProfile: r("me.updateProfile", ["displayName", "handle", "avatarPreset", "bio"]),
167
204
  notifications: {
168
- list: i("me.notifications.list", ["cursor", "unreadOnly", "codes"]),
169
- markRead: (t, o) => l(
205
+ list: r("me.notifications.list", ["cursor", "unreadOnly", "codes"]),
206
+ markRead: (s, i) => l(
170
207
  "me.notifications.markRead",
171
- c(t) && "all" in t ? { all: t.all } : { ids: c(t) && h(t.ids) ? [...t.ids] : [] },
172
- o
208
+ d(s) && "all" in s ? { all: s.all } : { ids: d(s) && g(s.ids) ? [...s.ids] : [] },
209
+ i
173
210
  ),
174
- unreadCount: a("me.notifications.unreadCount")
211
+ unreadCount: c("me.notifications.unreadCount")
175
212
  },
176
213
  settings: {
177
- get: a("me.settings.get"),
178
- update: i("me.settings.update", ["notifyReply", "notifyMention", "notifyTopic", "pushEnabled", "digestEmail", "quietHours"]),
179
- unsubscribeDigest: i("me.settings.unsubscribeDigest", ["token"])
214
+ get: c("me.settings.get"),
215
+ update: r("me.settings.update", ["notifyReply", "notifyMention", "notifyTopic", "pushEnabled", "digestEmail", "quietHours"]),
216
+ unsubscribeDigest: r("me.settings.unsubscribeDigest", ["token"])
180
217
  },
181
218
  mutes: {
182
- set: i("me.mutes.set", ["targetKind", "targetId", "muted"]),
183
- list: a("me.mutes.list")
219
+ set: r("me.mutes.set", ["targetKind", "targetId", "muted"]),
220
+ list: c("me.mutes.list")
184
221
  },
185
222
  push: {
186
- vapid: a("me.push.vapid"),
187
- subscribe: (t, o) => l(
223
+ vapid: c("me.push.vapid"),
224
+ subscribe: (s, i) => l(
188
225
  "me.push.subscribe",
189
226
  {
190
- ...m(t, ["endpoint", "userAgentClass"]),
191
- ...c(t) && c(t.keys) ? { keys: m(t.keys, ["p256dh", "auth"]) } : {}
227
+ ...u(s, ["endpoint", "userAgentClass"]),
228
+ ...d(s) && d(s.keys) ? { keys: u(s.keys, ["p256dh", "auth"]) } : {}
192
229
  },
193
- o
230
+ i
194
231
  ),
195
- unsubscribe: i("me.push.unsubscribe", ["endpoint"]),
196
- status: i("me.push.status", ["endpoint"])
232
+ unsubscribe: r("me.push.unsubscribe", ["endpoint"]),
233
+ status: r("me.push.status", ["endpoint"])
197
234
  },
198
235
  realtime: {
199
- token: a("me.realtime.token")
236
+ token: c("me.realtime.token")
200
237
  },
201
238
  decisions: {
202
- list: i("me.decisions.list", ["cursor"]),
203
- get: i("me.decisions.get", ["decisionId"])
239
+ list: r("me.decisions.list", ["cursor"]),
240
+ get: r("me.decisions.get", ["decisionId"])
204
241
  },
205
242
  appeals: {
206
- file: i("me.appeals.file", ["decisionId", "body"]),
207
- withdraw: i("me.appeals.withdraw", ["appealId"]),
208
- list: a("me.appeals.list")
243
+ file: r("me.appeals.file", ["decisionId", "body"]),
244
+ withdraw: r("me.appeals.withdraw", ["appealId"]),
245
+ list: c("me.appeals.list")
209
246
  },
210
247
  reports: {
211
- list: a("me.reports.list")
248
+ list: c("me.reports.list")
212
249
  },
213
250
  consents: {
214
- withdraw: (t, o) => l("me.consents.withdraw", { kind: "art9_consent" }, o)
251
+ withdraw: (s, i) => l("me.consents.withdraw", { kind: "art9_consent" }, i)
252
+ },
253
+ follows: {
254
+ set: (s, i) => {
255
+ const a = u(s, ["target", "following"]);
256
+ return a.target !== void 0 && (a.target = Q(a.target)), l("me.follows.set", a, i);
257
+ },
258
+ list: r("me.follows.list", ["cursor"])
215
259
  },
216
- export: a("me.export"),
217
- erase: a("me.erase"),
218
- cancelErase: a("me.cancelErase")
260
+ export: c("me.export"),
261
+ erase: c("me.erase"),
262
+ cancelErase: c("me.cancelErase")
219
263
  },
220
264
  legal: {
221
- current: i("legal.current", ["kind", "locale"])
265
+ current: r("legal.current", ["kind", "locale"])
222
266
  },
223
267
  realtime: {
224
- subscribeToken: i("realtime.subscribeToken", ["channel"])
268
+ subscribeToken: r("realtime.subscribeToken", ["channel"])
269
+ },
270
+ forum: {
271
+ categories: {
272
+ list: c("forum.categories.list")
273
+ },
274
+ topics: {
275
+ // A category by its id or its slug: the caller's type allows exactly one, and what is given is sent.
276
+ list: r("forum.topics.list", ["categoryId", "categorySlug", "sort", "cursor", "limit"]),
277
+ get: r("forum.topics.get", ["conversationId", "languageCode", "cursor"]),
278
+ head: (s, i) => l("forum.topics.head", { conversationIds: d(s) && g(s.conversationIds) ? [...s.conversationIds] : [] }, i),
279
+ create: r("forum.topics.create", ["categoryId", "title", "body", "clientMsgId", "languageCode", "confirmations"])
280
+ },
281
+ search: r("forum.search", ["query", "categoryId", "space", "page"])
282
+ },
283
+ moderation: {
284
+ queue: r("moderation.queue", ["categoryId", "cursor"]),
285
+ getCase: r("moderation.getCase", ["caseId"]),
286
+ decide: r("moderation.decide", ["caseId", "restriction", "basis", "facts", "contractualGround", "locale", "dryRun"]),
287
+ remove: r("moderation.remove", ["conversationId", "seq", "ruleId", "facts", "locale"]),
288
+ escalate: r("moderation.escalate", ["conversationId", "seq", "category"]),
289
+ setTopicState: r("moderation.setTopicState", ["conversationId", "state"]),
290
+ moveTopic: r("moderation.moveTopic", ["conversationId", "categoryId"]),
291
+ pinTopic: r("moderation.pinTopic", ["conversationId", "pinned"]),
292
+ // M3 FX (R3): the rev of the text the moderator read.
293
+ reviewPremod: r("moderation.reviewPremod", ["conversationId", "seq", "rev", "outcome", "ruleId", "facts", "locale"])
225
294
  },
226
295
  notices: {
227
- submit: (t, o) => {
228
- const d = m(t, ["category", "target", "description", "ruleId", "turnstileToken", "confirmations"]);
229
- return d.target !== void 0 && (d.target = _(d.target)), c(t?.notifier) ? d.notifier = m(t.notifier, ["name", "email", "locale"]) : t?.notifier === null && (d.notifier = null), l("notices.submit", d, o);
296
+ submit: (s, i) => {
297
+ const a = u(s, ["category", "target", "description", "ruleId", "turnstileToken", "confirmations"]);
298
+ return a.target !== void 0 && (a.target = R(a.target)), d(s?.notifier) ? a.notifier = u(s.notifier, ["name", "email", "locale"]) : s?.notifier === null && (a.notifier = null), l("notices.submit", a, i);
230
299
  },
231
- status: i("notices.status", ["receipt"]),
232
- appeal: i("notices.appeal", ["receipt", "body"]),
233
- withdrawAppeal: i("notices.withdrawAppeal", ["receipt"])
300
+ status: r("notices.status", ["receipt"]),
301
+ appeal: r("notices.appeal", ["receipt", "body"]),
302
+ withdrawAppeal: r("notices.withdrawAppeal", ["receipt"])
234
303
  }
235
304
  };
236
305
  }
237
306
  export {
238
- B as COMMUNITY_ANSWER_FIELDS,
239
- ee as createCommunityClient
307
+ W as COMMUNITY_ANSWER_FIELDS,
308
+ Y as COMMUNITY_ANSWER_VARIANTS,
309
+ ie as createCommunityClient
240
310
  };
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The forum's helpers (m3-contracts.md §3.2–§3.5, §4.3, §4.4, §4.8, §4.9, §5.2): what a page builds before it asks
3
+ * kb-api, and what it reads out of an answer — pure functions, no I/O.
4
+ *
5
+ * followTargetOf / followKeyOf `me/follows/set`'s target from a kind and an id (the follow button's attributes);
6
+ * forumTopicTitleOf a topic's title as kb-api takes it (1..200 UTF-16 units, as its schema counts);
7
+ * forumSearchQueryOf / nextSearchPage a query kb-api takes (2..200 characters) and the next of the 5 pages;
8
+ * knownTopicItemsOf a category's rows of the kinds this SDK renders (open enum: the rest is skipped);
9
+ * surfaceInfoOf / communityAwayOf MyState's surfaces and away mode, with an older kb-api's absence handled;
10
+ * isCategoryModerator whether the viewer moderates a category now (MyState `moderator`);
11
+ * brakedSurfaceOf which surface a BRAKED refusal paused (null: the module's brake, both).
12
+ */
13
+ import type { CommunityFailure } from './outcome.js';
14
+ import { type CommunityAway, type FollowTarget, type KnownBrakeSurface, type KnownFollowTargetKind, type KnownTopicItem, type ForumSearchPage, type ModuleInfo, type MyState, type SurfaceInfo, type TopicItem } from './shapes.js';
15
+ /**
16
+ * `me/follows/set`'s target from a kind and an id — a follow button's `target-kind` and `target-id`: `conversation` (a
17
+ * topic, or an article discussion that has its conversation: the button appears once it has one) or `category`. Null
18
+ * for any other kind or for an id that is no UUID — no request is built from arbitrary text. The id goes lower case.
19
+ */
20
+ export declare function followTargetOf(kind: unknown, id: unknown): FollowTarget | null;
21
+ /** A follow target's kind and id (the target `me/follows/list` names back as `targetKind` / `targetId`), or null. */
22
+ export declare function followTargetParts(target: unknown): {
23
+ readonly kind: KnownFollowTargetKind;
24
+ readonly id: string;
25
+ } | null;
26
+ /**
27
+ * One key per followed thing (`conversation:<id>`, `category:<id>`, lower case) — for a page's map of what the member
28
+ * follows, built from a FollowTarget or from a `me/follows/list` row (`targetKind`, `targetId`). Null for neither.
29
+ */
30
+ export declare function followKeyOf(target: FollowTarget | {
31
+ readonly targetKind: unknown;
32
+ readonly targetId: unknown;
33
+ } | null | undefined): string | null;
34
+ /**
35
+ * The length of a title as kb-api counts it — both of its bounds, the larger: the UTF-16 units of the title as it is sent
36
+ * (forumTopicTitleOf; zod's `.max(200)`) and its characters as it is stored, NFC'd (the database's `char_length`). NFC
37
+ * may lengthen a text — U+0958 is one unit and two characters stored —, and kb-api refuses a title past either bound
38
+ * (M3 FX, the review of wave 1, R15), so a title this accepts is one kb-api accepts. For a composer's counter (an emoji
39
+ * outside the basic plane counts two).
40
+ */
41
+ export declare function topicTitleLength(raw: unknown): number;
42
+ /**
43
+ * A topic's title as kb-api takes it (`forum/topics/create`, `messages/edit { title }`): trimmed and on one line, 1 to
44
+ * COMMUNITY_TOPIC_TITLE_MAX as topicTitleLength counts — or null for anything else, so the page says so instead of asking
45
+ * (kb-api would answer `invalid` with `fields: ['title']`).
46
+ */
47
+ export declare function forumTopicTitleOf(raw: unknown): string | null;
48
+ /**
49
+ * The query as kb-api takes it: trimmed, inner runs of blanks as one space, at least COMMUNITY_SEARCH_QUERY_MIN
50
+ * characters and at most COMMUNITY_SEARCH_QUERY_MAX — counted the stricter way at each end (characters for the floor,
51
+ * UTF-16 units for the ceiling, as a schema's string length counts them), so kb-api never refuses one this accepts.
52
+ * Null for anything else — the page says so instead of asking (kb-api would answer VALIDATION and spend the quota).
53
+ */
54
+ export declare function forumSearchQueryOf(raw: unknown): string | null;
55
+ /** The next page of a search, or null on the last one (`hasMore` false, or page COMMUNITY_SEARCH_PAGES_MAX). */
56
+ export declare function nextSearchPage(page: Pick<ForumSearchPage, 'page' | 'hasMore'> | null | undefined): number | null;
57
+ /** A row of a kind this SDK renders: a topic or an article discussion with the fields a row needs. */
58
+ export declare function isKnownTopicItem(item: unknown): item is KnownTopicItem;
59
+ /** A category's rows without the kinds this SDK does not know (a newer kb-api's), in order, never a throw. */
60
+ export declare function knownTopicItemsOf(items: readonly TopicItem[] | null | undefined): KnownTopicItem[];
61
+ /**
62
+ * One surface of MyState's `module.surfaces` — `forum` or `article_discussions` (a BRAKED refusal's spelling) — or null
63
+ * when kb-api did not report it (older than M3: no forum there). A brake without its end is no brake here: a surface
64
+ * brake always ends (≤ 24 h, the database's CHECK).
65
+ */
66
+ export declare function surfaceInfoOf(module: Pick<ModuleInfo, 'surfaces'> | null | undefined, surface: KnownBrakeSurface): SurfaceInfo | null;
67
+ /**
68
+ * The team's away mode („nepřítomen", D-M3-9) while it lasts — MyState's `module.away` whose `until` is still ahead of
69
+ * `now` — else null (none, ended, or a kb-api older than M3). Show `state.away` meanwhile.
70
+ */
71
+ export declare function communityAwayOf(module: Pick<ModuleInfo, 'away'> | null | undefined, now?: number): CommunityAway | null;
72
+ /**
73
+ * Whether the viewer moderates `categoryId` now (MyState `moderator.categoryIds`; ids compared in lower case). A
74
+ * page shows the moderator's menu by it; kb-api re-checks the appointment on every moderator operation.
75
+ */
76
+ export declare function isCategoryModerator(state: Pick<MyState, 'moderator'> | null | undefined, categoryId: string | null | undefined): boolean;
77
+ /**
78
+ * Which surface a BRAKED refusal paused — `forum` or `article_discussions`: show that surface paused and leave the
79
+ * other as it is — or null for the module's brake (both paused), for a surface this SDK does not know, and for any
80
+ * other refusal.
81
+ */
82
+ export declare function brakedSurfaceOf(failure: Pick<CommunityFailure, 'code' | 'surface'> | null | undefined): KnownBrakeSurface | null;