@blogmcp/sdk 0.10.0 → 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 +64 -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 +50 -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
@@ -10,7 +10,8 @@
10
10
  * A host serves the operations under ONE relative base (the blog's proxy, a headless site's BFF): the public ones
11
11
  * at `${base}/v1/public/<resource>/<verb>`, the notice form's at `${base}/trust/v1/notices/<verb>`
12
12
  * (`communityOpPath`). The private surfaces have no operation here: their client is its own entry, later
13
- * (community.md §3.7).
13
+ * (community.md §3.7). M3 (m3-contracts.md §3.9): the forum's, the follows' and a category moderator's operations
14
+ * are the public router's too — and no operation of the team router is here (the KB admin calls those itself).
14
15
  *
15
16
  * Browser-safe: nothing here takes a key, and nothing imports `node:*`.
16
17
  */
@@ -64,6 +65,23 @@ export declare const COMMUNITY_OPS: Readonly<{
64
65
  readonly 'me.erase': CommunityOp<"me.erase">;
65
66
  readonly 'me.cancelErase': CommunityOp<"me.cancelErase">;
66
67
  readonly 'legal.current': CommunityOp<"legal.current">;
68
+ readonly 'forum.categories.list': CommunityOp<"forum.categories.list">;
69
+ readonly 'forum.topics.list': CommunityOp<"forum.topics.list">;
70
+ readonly 'forum.topics.get': CommunityOp<"forum.topics.get">;
71
+ readonly 'forum.topics.head': CommunityOp<"forum.topics.head">;
72
+ readonly 'forum.topics.create': CommunityOp<"forum.topics.create">;
73
+ readonly 'forum.search': CommunityOp<"forum.search">;
74
+ readonly 'me.follows.set': CommunityOp<"me.follows.set">;
75
+ readonly 'me.follows.list': CommunityOp<"me.follows.list">;
76
+ readonly 'moderation.queue': CommunityOp<"moderation.queue">;
77
+ readonly 'moderation.getCase': CommunityOp<"moderation.getCase">;
78
+ readonly 'moderation.decide': CommunityOp<"moderation.decide">;
79
+ readonly 'moderation.remove': CommunityOp<"moderation.remove">;
80
+ readonly 'moderation.escalate': CommunityOp<"moderation.escalate">;
81
+ readonly 'moderation.setTopicState': CommunityOp<"moderation.setTopicState">;
82
+ readonly 'moderation.moveTopic': CommunityOp<"moderation.moveTopic">;
83
+ readonly 'moderation.pinTopic': CommunityOp<"moderation.pinTopic">;
84
+ readonly 'moderation.reviewPremod': CommunityOp<"moderation.reviewPremod">;
67
85
  readonly 'notices.submit': CommunityOp<"notices.submit">;
68
86
  readonly 'notices.status': CommunityOp<"notices.status">;
69
87
  readonly 'notices.appeal': CommunityOp<"notices.appeal">;
@@ -103,6 +121,23 @@ export declare const COMMUNITY_HEAD_ARTICLES_MAX = 50;
103
121
  export declare const COMMUNITY_PAGE_SIZE = 50;
104
122
  /** Replies one top-level message carries before `repliesTruncated`. */
105
123
  export declare const COMMUNITY_REPLIES_MAX = 200;
124
+ /** A topic's title, in characters (`community.topics.title`'s CHECK; `forum/topics/create`, `messages/edit { title }`). */
125
+ export declare const COMMUNITY_TOPIC_TITLE_MAX = 200;
126
+ /** Topics one `forum/topics/list` page holds by default, and at most (`limit` 1..50). */
127
+ export declare const COMMUNITY_TOPICS_PAGE_SIZE = 30;
128
+ export declare const COMMUNITY_TOPICS_PAGE_MAX = 50;
129
+ /** Topics one `forum/topics/head` asks about. */
130
+ export declare const COMMUNITY_HEAD_TOPICS_MAX = 50;
131
+ /** A search query, in characters after trimming (VALIDATION outside it). */
132
+ export declare const COMMUNITY_SEARCH_QUERY_MIN = 2;
133
+ export declare const COMMUNITY_SEARCH_QUERY_MAX = 200;
134
+ /** Results one `forum/search` page holds, and the deepest page (no deeper paging: no bulk read, §4.4). */
135
+ export declare const COMMUNITY_SEARCH_PAGE_SIZE = 20;
136
+ export declare const COMMUNITY_SEARCH_PAGES_MAX = 5;
137
+ /** Follows one member may hold (FOLLOW_LIMIT above it). */
138
+ export declare const COMMUNITY_FOLLOWS_MAX = 500;
139
+ /** A category's slug (`community.forum_categories.slug`'s CHECK): the path segment of its page. */
140
+ export declare const COMMUNITY_CATEGORY_SLUG_RE: RegExp;
106
141
  /** The Turnstile action the notice form's widget declares; kb-api refuses a token issued for any other. */
107
142
  export declare const COMMUNITY_NOTICE_TURNSTILE_ACTION = "community_notice";
108
143
  /**
@@ -1,4 +1,4 @@
1
- const e = (i, s, t) => Object.freeze({ name: i, method: "POST", path: t, surface: s }), m = Object.freeze({
1
+ const e = (i, t, s) => Object.freeze({ name: i, method: "POST", path: s, surface: t }), m = Object.freeze({
2
2
  "discussions.list": e("discussions.list", "public", "/community/v1/public/discussions/list"),
3
3
  "discussions.head": e("discussions.head", "public", "/community/v1/public/discussions/head"),
4
4
  "messages.post": e("messages.post", "public", "/community/v1/public/messages/post"),
@@ -41,42 +41,72 @@ const e = (i, s, t) => Object.freeze({ name: i, method: "POST", path: t, surface
41
41
  "me.erase": e("me.erase", "public", "/community/v1/public/me/erase"),
42
42
  "me.cancelErase": e("me.cancelErase", "public", "/community/v1/public/me/erase/cancel"),
43
43
  "legal.current": e("legal.current", "public", "/community/v1/public/legal/current"),
44
+ // M3 F2–F3 (m3-contracts.md §3.2–§3.3): the forum — its categories, topics, the polling head, a new topic and search;
45
+ // the member's follows of a topic, an article discussion or a category.
46
+ "forum.categories.list": e("forum.categories.list", "public", "/community/v1/public/forum/categories/list"),
47
+ "forum.topics.list": e("forum.topics.list", "public", "/community/v1/public/forum/topics/list"),
48
+ "forum.topics.get": e("forum.topics.get", "public", "/community/v1/public/forum/topics/get"),
49
+ "forum.topics.head": e("forum.topics.head", "public", "/community/v1/public/forum/topics/head"),
50
+ "forum.topics.create": e("forum.topics.create", "public", "/community/v1/public/forum/topics/create"),
51
+ "forum.search": e("forum.search", "public", "/community/v1/public/forum/search"),
52
+ "me.follows.set": e("me.follows.set", "public", "/community/v1/public/me/follows/set"),
53
+ "me.follows.list": e("me.follows.list", "public", "/community/v1/public/me/follows/list"),
54
+ // M3 F4 (§3.4): a category moderator's operations — a member session with an active appointment; anyone else NOT_FOUND.
55
+ "moderation.queue": e("moderation.queue", "public", "/community/v1/public/moderation/queue"),
56
+ "moderation.getCase": e("moderation.getCase", "public", "/community/v1/public/moderation/cases/get"),
57
+ "moderation.decide": e("moderation.decide", "public", "/community/v1/public/moderation/decide"),
58
+ "moderation.remove": e("moderation.remove", "public", "/community/v1/public/moderation/remove"),
59
+ "moderation.escalate": e("moderation.escalate", "public", "/community/v1/public/moderation/escalate"),
60
+ "moderation.setTopicState": e("moderation.setTopicState", "public", "/community/v1/public/moderation/topics/set-state"),
61
+ "moderation.moveTopic": e("moderation.moveTopic", "public", "/community/v1/public/moderation/topics/move"),
62
+ "moderation.pinTopic": e("moderation.pinTopic", "public", "/community/v1/public/moderation/topics/pin"),
63
+ "moderation.reviewPremod": e("moderation.reviewPremod", "public", "/community/v1/public/moderation/premod/review"),
44
64
  "notices.submit": e("notices.submit", "notice", "/trust/v1/notices/submit"),
45
65
  "notices.status": e("notices.status", "notice", "/trust/v1/notices/status"),
46
66
  "notices.appeal": e("notices.appeal", "notice", "/trust/v1/notices/appeal"),
47
67
  "notices.withdrawAppeal": e("notices.withdrawAppeal", "notice", "/trust/v1/notices/appeal/withdraw")
48
68
  }), c = "/community";
49
- function n(i) {
69
+ function u(i) {
50
70
  return i.surface === "public" && i.path.startsWith(`${c}/`) ? i.path.slice(c.length) : i.path;
51
71
  }
52
- const o = 4e3, l = 2, p = 1e3, a = 4e3, b = 4e3, r = 120, d = 2, M = 80, _ = 280, y = /^[a-z0-9][a-z0-9_]{2,29}$/, g = 30, v = 50, I = 50, N = 200, T = "community_notice", h = "good_faith", O = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
53
- function f() {
72
+ const n = 4e3, l = 2, p = 1e3, a = 4e3, r = 4e3, b = 120, d = 2, M = 80, _ = 280, v = /^[a-z0-9][a-z0-9_]{2,29}$/, y = 30, I = 50, T = 50, f = 200, g = 200, O = 30, C = 50, A = 50, N = 2, E = 200, h = 20, U = 5, Y = 500, S = /^[a-z0-9][a-z0-9-]{0,62}$/, w = "community_notice", P = "good_faith", R = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
73
+ function X() {
54
74
  const i = globalThis.crypto;
55
75
  if (typeof i?.randomUUID == "function") return i.randomUUID();
56
- const s = i.getRandomValues(new Uint8Array(16));
57
- s[6] = (s[6] ?? 0) & 15 | 64, s[8] = (s[8] ?? 0) & 63 | 128;
58
- const t = Array.from(s, (u) => u.toString(16).padStart(2, "0")).join("");
59
- return `${t.slice(0, 8)}-${t.slice(8, 12)}-${t.slice(12, 16)}-${t.slice(16, 20)}-${t.slice(20)}`;
76
+ const t = i.getRandomValues(new Uint8Array(16));
77
+ t[6] = (t[6] ?? 0) & 15 | 64, t[8] = (t[8] ?? 0) & 63 | 128;
78
+ const s = Array.from(t, (o) => o.toString(16).padStart(2, "0")).join("");
79
+ return `${s.slice(0, 8)}-${s.slice(8, 12)}-${s.slice(12, 16)}-${s.slice(16, 20)}-${s.slice(20)}`;
60
80
  }
61
81
  export {
62
82
  a as COMMUNITY_APPEAL_MAX,
63
83
  _ as COMMUNITY_BIO_MAX,
64
- O as COMMUNITY_CLIENT_MSG_ID_RE,
84
+ S as COMMUNITY_CATEGORY_SLUG_RE,
85
+ R as COMMUNITY_CLIENT_MSG_ID_RE,
65
86
  M as COMMUNITY_DISPLAY_NAME_MAX,
66
87
  d as COMMUNITY_DISPLAY_NAME_MIN,
67
- h as COMMUNITY_GOOD_FAITH,
68
- g as COMMUNITY_HANDLE_CHANGE_DAYS,
69
- y as COMMUNITY_HANDLE_RE,
70
- v as COMMUNITY_HEAD_ARTICLES_MAX,
88
+ Y as COMMUNITY_FOLLOWS_MAX,
89
+ P as COMMUNITY_GOOD_FAITH,
90
+ y as COMMUNITY_HANDLE_CHANGE_DAYS,
91
+ v as COMMUNITY_HANDLE_RE,
92
+ I as COMMUNITY_HEAD_ARTICLES_MAX,
93
+ A as COMMUNITY_HEAD_TOPICS_MAX,
71
94
  l as COMMUNITY_MESSAGE_LINKS_MAX,
72
- o as COMMUNITY_MESSAGE_MAX,
73
- b as COMMUNITY_NOTICE_DESCRIPTION_MAX,
74
- T as COMMUNITY_NOTICE_TURNSTILE_ACTION,
75
- r as COMMUNITY_NOTIFIER_NAME_MAX,
95
+ n as COMMUNITY_MESSAGE_MAX,
96
+ r as COMMUNITY_NOTICE_DESCRIPTION_MAX,
97
+ w as COMMUNITY_NOTICE_TURNSTILE_ACTION,
98
+ b as COMMUNITY_NOTIFIER_NAME_MAX,
76
99
  m as COMMUNITY_OPS,
77
- I as COMMUNITY_PAGE_SIZE,
78
- N as COMMUNITY_REPLIES_MAX,
100
+ T as COMMUNITY_PAGE_SIZE,
101
+ f as COMMUNITY_REPLIES_MAX,
79
102
  p as COMMUNITY_REPORT_NOTE_MAX,
80
- n as communityOpPath,
81
- f as newClientMsgId
103
+ U as COMMUNITY_SEARCH_PAGES_MAX,
104
+ h as COMMUNITY_SEARCH_PAGE_SIZE,
105
+ E as COMMUNITY_SEARCH_QUERY_MAX,
106
+ N as COMMUNITY_SEARCH_QUERY_MIN,
107
+ C as COMMUNITY_TOPICS_PAGE_MAX,
108
+ O as COMMUNITY_TOPICS_PAGE_SIZE,
109
+ g as COMMUNITY_TOPIC_TITLE_MAX,
110
+ u as communityOpPath,
111
+ X as newClientMsgId
82
112
  };
@@ -37,6 +37,15 @@
37
37
  * which the page reads as "sign in"); it only lets kb-api count the visitor by their own IP. A 401 is therefore
38
38
  * the key's refusal on a notice route only.
39
39
  *
40
+ * Per request (M3 FX3; m3-contracts.md §5.2, §16.1), `handle(http, options)` takes two options. `serverInitiated`: a read
41
+ * the site's SERVER makes on its own behalf — a tenant-wide state that is the same for every reader, such as the forum's
42
+ * switch the storefront's chrome reads for every page — rather than a visitor's request: no visitor IP is forwarded
43
+ * (`X-Blogmcp-Client-Ip` is left out, whatever the request carries; kb-api counts the call on the site server's own
44
+ * address, as any call without one), the "request without a client IP" warning is not logged for it, and the host's
45
+ * session is not asked (`memberToken` is not called): the site's notice key, else no credential. `signal`: the caller's
46
+ * deadline — aborting it aborts the upstream call beside `timeoutMs`; the answer is then 503 UNAVAILABLE, not logged as
47
+ * an outage (the caller gave up and logs its own timeout); a signal already aborted calls nothing.
48
+ *
40
49
  * kb-api's status and body pass through, with the BFF's own headers (`Cache-Control: private, no-store`,
41
50
  * `Referrer-Policy: same-origin`, `X-Robots-Tag: noindex`, `X-Frame-Options: DENY`, nosniff, JSON) and kb-api's
42
51
  * `Retry-After`. The BFF's own refusals are kb-api's envelope `{ ok: false, code, message }`. UNAVAILABLE (503)
@@ -108,9 +117,23 @@ export interface CommunityBffConfig {
108
117
  /** Gets outages and the unexpected only (the client's `CommunityLogger` fits); default one `console.warn` line. */
109
118
  logger?: (e: CommunityBffLogEvent) => void;
110
119
  }
120
+ /** Per-request options of `CommunityBff.handle` (M3 FX3; the module doc says what each changes). */
121
+ export interface CommunityBffRequestOptions {
122
+ /**
123
+ * A read the site's server makes on its own behalf — a tenant-wide state, the same for every reader (the forum's
124
+ * switch read for every page) —, never a visitor's request: no visitor IP forwarded and no warning for its absence,
125
+ * the host's session not asked (the site's notice key, else no credential). Default false: a visitor's request.
126
+ */
127
+ serverInitiated?: boolean;
128
+ /** The caller's deadline: aborting it aborts the upstream call (503 UNAVAILABLE, not logged as an outage). */
129
+ signal?: AbortSignal;
130
+ }
111
131
  export interface CommunityBff {
112
- /** One request of the page's client: its answer, never a throw. */
113
- handle(http: CommunityHttp): Promise<CommunityResponse>;
132
+ /**
133
+ * One request of the page's client — or, with `options.serverInitiated`, a read the site's server makes on its own
134
+ * behalf: its answer, never a throw.
135
+ */
136
+ handle(http: CommunityHttp, options?: CommunityBffRequestOptions): Promise<CommunityResponse>;
114
137
  }
115
138
  /** The BFF's own refusals (kb-api's envelope); the client maps them like kb-api's codes. */
116
139
  export type CommunityBffCode = 'ORIGIN' | 'TOO_LARGE' | 'INVALID_JSON' | 'UNAVAILABLE';
@@ -1,32 +1,32 @@
1
- import { assertServerOnly as $ } from "../../core/server-only.js";
2
- import { DEFAULT_CLIENT_IP_HEADER as H, isHeaderName as F, clientIpFrom as z, KB_CLIENT_IP_HEADER as J } from "../../consultations/server/client-ip.js";
3
- import { originOf as Y, siteOrigins as x, isAllowedOrigin as G } from "../../consultations/server/origin.js";
4
- import { isBytes as q, COMMUNITY_BODY_MAX_BYTES as K, parseCommunityJson as X, isJsonContentType as V } from "./http.js";
5
- import { communityRouteDecision as W, isNoticeRoute as Z } from "./route-decision.js";
6
- import { communityUnknownPath as E } from "./unknown-path.js";
7
- const Q = Object.freeze({
1
+ import { assertServerOnly as z } from "../../core/server-only.js";
2
+ import { DEFAULT_CLIENT_IP_HEADER as J, isHeaderName as Y, clientIpFrom as x, KB_CLIENT_IP_HEADER as G } from "../../consultations/server/client-ip.js";
3
+ import { originOf as V, siteOrigins as q, isAllowedOrigin as K } from "../../consultations/server/origin.js";
4
+ import { isBytes as X, COMMUNITY_BODY_MAX_BYTES as W, parseCommunityJson as Z, isJsonContentType as Q } from "./http.js";
5
+ import { communityRouteDecision as ee, isNoticeRoute as te } from "./route-decision.js";
6
+ import { communityUnknownPath as L } from "./unknown-path.js";
7
+ const ne = Object.freeze({
8
8
  ORIGIN: Object.freeze({ status: 403, message: "This request did not come from the site" }),
9
9
  TOO_LARGE: Object.freeze({ status: 413, message: "The request body is too large" }),
10
10
  INVALID_JSON: Object.freeze({ status: 400, message: "The request body must be a JSON object" }),
11
11
  // kb-api's own message for its UNAVAILABLE.
12
12
  UNAVAILABLE: Object.freeze({ status: 503, message: "Temporarily unavailable" })
13
- }), ee = Object.freeze({
13
+ }), oe = Object.freeze({
14
14
  "Content-Type": "application/json; charset=utf-8",
15
15
  "Cache-Control": "private, no-store",
16
16
  "Referrer-Policy": "same-origin",
17
17
  "X-Robots-Tag": "noindex",
18
18
  "X-Frame-Options": "DENY",
19
19
  "X-Content-Type-Options": "nosniff"
20
- }), te = "/api/community", I = 1e4, ne = 2147483647, C = /^[\x21-\x7E]+$/, L = 8192, oe = /^(?:\/[A-Za-z0-9_~-][A-Za-z0-9._~-]*)*\/?$/, re = /^[A-Z][A-Z0-9_]{0,63}$/;
21
- function se(t) {
22
- if (t === void 0) return te;
23
- if (typeof t != "string" || !t.startsWith("/") || !oe.test(t))
20
+ }), re = "/api/community", C = 1e4, se = 2147483647, v = /^[\x21-\x7E]+$/, S = 8192, ie = /^(?:\/[A-Za-z0-9_~-][A-Za-z0-9._~-]*)*\/?$/, ae = /^[A-Z][A-Z0-9_]{0,63}$/;
21
+ function ue(t) {
22
+ if (t === void 0) return re;
23
+ if (typeof t != "string" || !t.startsWith("/") || !ie.test(t))
24
24
  throw new TypeError(
25
25
  "[blogmcp-sdk] createCommunityBff basePath must be an absolute path of plain segments, like /api/community"
26
26
  );
27
27
  return t.replace(/\/$/, "");
28
28
  }
29
- function ie(t) {
29
+ function ce(t) {
30
30
  if (typeof t != "string" || t.trim() === "") return null;
31
31
  try {
32
32
  const e = new URL(t.trim());
@@ -35,39 +35,39 @@ function ie(t) {
35
35
  return null;
36
36
  }
37
37
  }
38
- function ae(t, e) {
38
+ function le(t, e) {
39
39
  if (typeof t != "string") return null;
40
- const r = t.trim();
41
- return r === "" ? null : !C.test(r) || r.length > L ? (e("notice_key_invalid", "[community] the notice key contains characters not allowed in an HTTP header — ignored."), null) : r;
40
+ const o = t.trim();
41
+ return o === "" ? null : !v.test(o) || o.length > S ? (e("notice_key_invalid", "[community] the notice key contains characters not allowed in an HTTP header — ignored."), null) : o;
42
42
  }
43
- function ce(t, e) {
44
- if (t === void 0) return I;
45
- const r = typeof t == "number" ? Math.floor(t) : Number.NaN;
46
- return r >= 1 && r <= ne ? r : (e("timeout_ms", "[community] timeoutMs is not a number of milliseconds from 1 to 2147483647 — the default 10 s is used."), I);
43
+ function me(t, e) {
44
+ if (t === void 0) return C;
45
+ const o = typeof t == "number" ? Math.floor(t) : Number.NaN;
46
+ return o >= 1 && o <= se ? o : (e("timeout_ms", "[community] timeoutMs is not a number of milliseconds from 1 to 2147483647 — the default 10 s is used."), C);
47
47
  }
48
- function ue(t) {
48
+ function fe(t) {
49
49
  return (e) => {
50
- const r = typeof e.kbCode == "string" ? re.test(e.kbCode) ? e.kbCode : "other" : null, u = typeof e.status == "number" && Number.isInteger(e.status) ? e.status : null;
50
+ const o = typeof e.kbCode == "string" ? ae.test(e.kbCode) ? e.kbCode : "other" : null, c = typeof e.status == "number" && Number.isInteger(e.status) ? e.status : null;
51
51
  try {
52
- t({ op: String(e.op).replace(/[^A-Za-z0-9_./-]/g, "").slice(0, 64), outcome: e.outcome, kbCode: r, status: u });
52
+ t({ op: String(e.op).replace(/[^A-Za-z0-9_./-]/g, "").slice(0, 64), outcome: e.outcome, kbCode: o, status: c });
53
53
  } catch {
54
54
  }
55
55
  };
56
56
  }
57
- const le = (t) => {
57
+ const de = (t) => {
58
58
  console.warn(`[community] op=${t.op} outcome=${t.outcome} kb_code=${t.kbCode ?? "none"} status=${t.status ?? "none"}`);
59
59
  };
60
- function me(t, e) {
60
+ function ye(t, e) {
61
61
  if (typeof e != "string") return null;
62
- const r = e.search(/[?#]/), u = r === -1 ? e : e.slice(0, r);
63
- if (!u.startsWith(`${t}/`)) return null;
64
- const s = u.slice(t.length);
62
+ const o = e.search(/[?#]/), c = o === -1 ? e : e.slice(0, o);
63
+ if (!c.startsWith(`${t}/`)) return null;
64
+ const s = c.slice(t.length);
65
65
  return s.startsWith("/trust/") ? s : `/community${s}`;
66
66
  }
67
- function fe(t) {
67
+ function be(t) {
68
68
  return t.replace(/^\/community\/v1\/public\//, "").replace(/^\/trust\/v1\//, "");
69
69
  }
70
- function ye(t) {
70
+ function he(t) {
71
71
  try {
72
72
  const e = JSON.parse(t);
73
73
  return typeof e == "object" && e !== null && !Array.isArray(e) ? e : null;
@@ -75,140 +75,157 @@ function ye(t) {
75
75
  return null;
76
76
  }
77
77
  }
78
- function N(t) {
78
+ function U(t) {
79
79
  return typeof t.code == "string" ? t.code : null;
80
80
  }
81
- function de(t, e) {
82
- const r = t.get("retry-after")?.trim();
83
- if (!r) return null;
84
- if (/^\d{1,9}$/.test(r)) return Number(r);
85
- const u = Date.parse(r);
86
- return Number.isNaN(u) ? null : Math.max(0, Math.ceil((u - e) / 1e3));
81
+ function pe(t, e) {
82
+ const o = t.get("retry-after")?.trim();
83
+ if (!o) return null;
84
+ if (/^\d{1,9}$/.test(o)) return Number(o);
85
+ const c = Date.parse(o);
86
+ return Number.isNaN(c) ? null : Math.max(0, Math.ceil((c - e) / 1e3));
87
87
  }
88
- function R(t, e, r = {}) {
89
- return { status: t, headers: { ...ee, ...r }, body: e };
88
+ function R(t, e, o = {}) {
89
+ return { status: t, headers: { ...oe, ...o }, body: e };
90
90
  }
91
- function g(t) {
92
- const { status: e, message: r } = Q[t];
93
- return R(e, JSON.stringify({ ok: !1, code: t, message: r }));
91
+ function y(t) {
92
+ const { status: e, message: o } = ne[t];
93
+ return R(e, JSON.stringify({ ok: !1, code: t, message: o }));
94
94
  }
95
- function _e(t) {
96
- $(
95
+ function ge(t, e) {
96
+ const o = AbortSignal.timeout(t);
97
+ if (!e) return { signal: o, release: () => {
98
+ } };
99
+ const c = new AbortController(), s = () => c.abort();
100
+ return e.aborted || o.aborted ? c.abort() : (e.addEventListener("abort", s, { once: !0 }), o.addEventListener("abort", s, { once: !0 })), {
101
+ signal: c.signal,
102
+ release: () => {
103
+ e.removeEventListener("abort", s), o.removeEventListener("abort", s);
104
+ }
105
+ };
106
+ }
107
+ function we(t) {
108
+ z(
97
109
  "createCommunityBff",
98
110
  "it holds the site's community notice key and its members' tokens, which must never reach the browser."
99
111
  );
100
112
  const e = t ?? {};
101
113
  if (typeof e.memberToken != "function")
102
114
  throw new TypeError("[blogmcp-sdk] createCommunityBff needs memberToken: (http) => Promise<string | null>");
103
- const r = se(e.basePath), u = /* @__PURE__ */ new Set(), s = (n, o) => {
104
- u.has(n) || (u.add(n), console.warn(o));
105
- }, p = ie(e.kbApiUrl);
106
- p === null && s("kb_api_url", "[community] kbApiUrl is not an absolute http(s) URL — every community request answers 503.");
107
- const k = Array.isArray(e.allowedOrigins) ? e.allowedOrigins : [];
108
- k.some((n) => Y(n) === null) && s("allowed_origins", "[community] an allowedOrigins entry is not an http(s) URL — ignored.");
109
- const O = x(Array.isArray(e.siteUrls) ? e.siteUrls : [], k);
110
- O.length === 0 && s("site_urls", "[community] no usable siteUrls — every community request is refused (ORIGIN).");
111
- let h = typeof e.clientIpHeader == "string" ? e.clientIpHeader.trim() : H;
112
- h !== "" && !F(h) && (s("client_ip_header", "[community] clientIpHeader is not an HTTP header name — no edge header is read."), h = "");
113
- const _ = ae(e.noticeKey, s), S = ce(e.timeoutMs, s), U = typeof e.now == "function" ? e.now : Date.now, P = () => typeof e.fetch == "function" ? e.fetch() : globalThis.fetch, A = e.logger, T = ue(typeof A == "function" ? (n) => A.call(e, n) : le), M = e.memberToken, l = (n, o = null, i = null) => (T({ op: n, outcome: "unavailable", kbCode: o, status: i }), g("UNAVAILABLE"));
114
- async function v(n) {
115
+ const o = ue(e.basePath), c = /* @__PURE__ */ new Set(), s = (n, r) => {
116
+ c.has(n) || (c.add(n), console.warn(r));
117
+ }, O = ce(e.kbApiUrl);
118
+ O === null && s("kb_api_url", "[community] kbApiUrl is not an absolute http(s) URL — every community request answers 503.");
119
+ const _ = Array.isArray(e.allowedOrigins) ? e.allowedOrigins : [];
120
+ _.some((n) => V(n) === null) && s("allowed_origins", "[community] an allowedOrigins entry is not an http(s) URL — ignored.");
121
+ const T = q(Array.isArray(e.siteUrls) ? e.siteUrls : [], _);
122
+ T.length === 0 && s("site_urls", "[community] no usable siteUrls — every community request is refused (ORIGIN).");
123
+ let g = typeof e.clientIpHeader == "string" ? e.clientIpHeader.trim() : J;
124
+ g !== "" && !Y(g) && (s("client_ip_header", "[community] clientIpHeader is not an HTTP header name — no edge header is read."), g = "");
125
+ const E = le(e.noticeKey, s), P = me(e.timeoutMs, s), M = typeof e.now == "function" ? e.now : Date.now, B = () => typeof e.fetch == "function" ? e.fetch() : globalThis.fetch, w = e.logger, I = fe(typeof w == "function" ? (n) => w.call(e, n) : de), j = e.memberToken, l = (n, r = null, a = null) => (I({ op: n, outcome: "unavailable", kbCode: r, status: a }), y("UNAVAILABLE"));
126
+ async function D(n) {
115
127
  if (typeof n.json != "function")
116
128
  return s(
117
129
  "json_missing",
118
130
  "[community] the request adapter has no json() — use the community server's fromWebRequest or add it."
119
131
  ), null;
120
- let o;
132
+ let r;
121
133
  try {
122
- o = await n.json();
134
+ r = await n.json();
123
135
  } catch {
124
136
  return { ok: !1, code: "INVALID_JSON" };
125
137
  }
126
- if (!o || typeof o != "object" || o.ok !== !0)
127
- return { ok: !1, code: !!o && typeof o == "object" && o.ok === !1 && o.code === "TOO_LARGE" ? "TOO_LARGE" : "INVALID_JSON" };
128
- if (!q(o.bytes)) return { ok: !1, code: "INVALID_JSON" };
129
- if (o.bytes.byteLength > K) return { ok: !1, code: "TOO_LARGE" };
130
- const i = new Uint8Array(o.bytes), c = X(n.header("content-type"), i);
131
- return c.ok ? { ok: !0, bytes: i } : c;
138
+ if (!r || typeof r != "object" || r.ok !== !0)
139
+ return { ok: !1, code: !!r && typeof r == "object" && r.ok === !1 && r.code === "TOO_LARGE" ? "TOO_LARGE" : "INVALID_JSON" };
140
+ if (!X(r.bytes)) return { ok: !1, code: "INVALID_JSON" };
141
+ if (r.bytes.byteLength > W) return { ok: !1, code: "TOO_LARGE" };
142
+ const a = new Uint8Array(r.bytes), i = Z(n.header("content-type"), a);
143
+ return i.ok ? { ok: !0, bytes: a } : i;
132
144
  }
133
- async function B(n, o) {
134
- const i = await M(n);
135
- return i != null && i !== "" ? typeof i == "string" && C.test(i) && i.length <= L ? { kind: "member", token: i } : (s(
145
+ async function $(n, r, a) {
146
+ const i = a ? null : await j(n);
147
+ return i != null && i !== "" ? typeof i == "string" && v.test(i) && i.length <= S ? { kind: "member", token: i } : (s(
136
148
  "member_token_invalid",
137
149
  '[community] memberToken returned something that is not a token (the bare JWT, visible ASCII, no "Bearer ") — answered 503.'
138
- ), { kind: "unavailable" }) : _ ? { kind: "notice", token: _ } : o ? (s(
150
+ ), { kind: "unavailable" }) : E ? { kind: "notice", token: E } : r ? (s(
139
151
  "notice_key",
140
152
  "[community] no notice key (COMMUNITY_NOTICE_KEY) — the notice form works only for signed-in members."
141
153
  ), { kind: "unavailable" }) : { kind: "anonymous" };
142
154
  }
143
- async function D(n, o, i, c, m, f) {
155
+ async function H(n, r, a, i, b, m, f) {
144
156
  const d = { "Content-Type": "application/json" };
145
- c.kind !== "anonymous" && (d.Authorization = `Bearer ${c.token}`), f && (d[J] = f);
146
- let a;
157
+ i.kind !== "anonymous" && (d.Authorization = `Bearer ${i.token}`), m && (d[G] = m);
158
+ const h = () => f?.aborted === !0, p = ge(P, f);
159
+ let u, k;
147
160
  try {
148
- a = await P()(`${p}${o}`, {
149
- method: "POST",
150
- headers: d,
151
- body: i,
152
- redirect: "error",
153
- cache: "no-store",
154
- signal: AbortSignal.timeout(S)
155
- });
156
- } catch {
157
- return l(n);
158
- }
159
- let y;
160
- try {
161
- y = await a.text();
162
- } catch {
163
- return l(n, null, a.status);
161
+ try {
162
+ u = await B()(`${O}${r}`, {
163
+ method: "POST",
164
+ headers: d,
165
+ body: a,
166
+ redirect: "error",
167
+ cache: "no-store",
168
+ signal: p.signal
169
+ });
170
+ } catch {
171
+ return h() ? y("UNAVAILABLE") : l(n);
172
+ }
173
+ try {
174
+ k = await u.text();
175
+ } catch {
176
+ return h() ? y("UNAVAILABLE") : l(n, null, u.status);
177
+ }
178
+ } finally {
179
+ p.release();
164
180
  }
165
- const b = V(a.headers.get("content-type")) ? ye(y) : null;
166
- if (b === null) return l(n, null, a.status);
167
- if (c.kind !== "anonymous" && y.includes(c.token))
168
- return s("credential_echo", "[community] kb-api's answer quoted the request's credential — not passed on (503)."), l(n, null, a.status);
169
- if (a.status === 401 && c.kind === "notice" && m)
181
+ const A = Q(u.headers.get("content-type")) ? he(k) : null;
182
+ if (A === null) return l(n, null, u.status);
183
+ if (i.kind !== "anonymous" && k.includes(i.token))
184
+ return s("credential_echo", "[community] kb-api's answer quoted the request's credential — not passed on (503)."), l(n, null, u.status);
185
+ if (u.status === 401 && i.kind === "notice" && b)
170
186
  return s(
171
187
  "notice_key_refused",
172
188
  "[community] kb-api refused the notice key — check COMMUNITY_NOTICE_KEY (scope community:notice)."
173
- ), l(n, N(b), a.status);
174
- a.status >= 500 && T({ op: n, outcome: "unavailable", kbCode: N(b), status: a.status });
175
- const w = de(a.headers, U());
176
- return R(a.status, y, w === null ? {} : { "Retry-After": String(w) });
189
+ ), l(n, U(A), u.status);
190
+ u.status >= 500 && I({ op: n, outcome: "unavailable", kbCode: U(A), status: u.status });
191
+ const N = pe(u.headers, M());
192
+ return R(u.status, k, N === null ? {} : { "Retry-After": String(N) });
177
193
  }
178
- async function j(n, o) {
179
- if ((typeof n.method == "string" ? n.method.toUpperCase() : "") !== "POST") return E();
180
- const c = me(r, n.path), m = c === null ? null : W("POST", c);
181
- if (m?.kind !== "allow") return E();
182
- if (o.op = fe(m.upstreamPath), !G(n, O))
194
+ async function F(n, r, a) {
195
+ if ((typeof n.method == "string" ? n.method.toUpperCase() : "") !== "POST") return L();
196
+ const b = ye(o, n.path), m = b === null ? null : ee("POST", b);
197
+ if (m?.kind !== "allow") return L();
198
+ if (r.op = be(m.upstreamPath), !K(n, T))
183
199
  return s(
184
200
  "origin",
185
201
  "[community] a request was refused for its Origin (not one of siteUrls / allowedOrigins, or not same-origin) — if the site's own pages are refused, check siteUrls."
186
- ), g("ORIGIN");
187
- const f = await v(n);
188
- if (f === null) return l(o.op);
189
- if (!f.ok) return g(f.code);
190
- if (p === null) return l(o.op);
191
- const d = Z(m.upstreamPath), a = await B(n, d);
192
- if (a.kind === "unavailable") return l(o.op);
193
- const y = z(n, { header: h });
194
- return y === null && s(
202
+ ), y("ORIGIN");
203
+ const f = await D(n);
204
+ if (f === null) return l(r.op);
205
+ if (!f.ok) return y(f.code);
206
+ if (O === null) return l(r.op);
207
+ if (a.signal?.aborted === !0) return y("UNAVAILABLE");
208
+ const d = a.serverInitiated === !0, h = te(m.upstreamPath), p = await $(n, h, d);
209
+ if (p.kind === "unavailable") return l(r.op);
210
+ const u = d ? null : x(n, { header: g });
211
+ return u === null && !d && s(
195
212
  "client_ip",
196
213
  "[community] a request without a client IP (no valid edge header or X-Forwarded-For) — check clientIpHeader and the reverse-proxy configuration. kb-api counts a visitor by a forwarded IP only behind a delegated member token or the site's notice key; without one the call is counted on the site server's own IP."
197
- ), D(o.op, m.upstreamPath, f.bytes, a, d, y);
214
+ ), H(r.op, m.upstreamPath, f.bytes, p, h, u, a.signal);
198
215
  }
199
216
  return {
200
- async handle(n) {
201
- const o = { op: "bff" };
217
+ async handle(n, r) {
218
+ const a = { op: "bff" };
202
219
  try {
203
- return await j(n, o);
220
+ return await F(n, a, r && typeof r == "object" ? r : {});
204
221
  } catch {
205
- return l(o.op);
222
+ return l(a.op);
206
223
  }
207
224
  }
208
225
  };
209
226
  }
210
227
  export {
211
- Q as COMMUNITY_BFF_REFUSALS,
212
- te as DEFAULT_COMMUNITY_BASE_PATH,
213
- _e as createCommunityBff
228
+ ne as COMMUNITY_BFF_REFUSALS,
229
+ re as DEFAULT_COMMUNITY_BASE_PATH,
230
+ we as createCommunityBff
214
231
  };
@@ -9,6 +9,9 @@
9
9
  * unknown path through every host, a stale one would forward to a path kb-api no longer serves. The team, adapter
10
10
  * and platform surfaces are never in it (the team is not a host session; the others call kb-api themselves), nor
11
11
  * is either closed surface — route-decision.ts refuses those whatever this list says.
12
+ *
13
+ * M3 (m3-contracts.md §3.9, §5.2): the forum's public operations and a category moderator's (`forum/…`,
14
+ * `me/follows/…`, `moderation/…`) — seventeen, kb-api's since the wave 2 integration (F2, F3, F4).
12
15
  */
13
16
  import type { CommunityHostRoute } from './route-decision.js';
14
17
  /** kb-api's allowlist, sorted by path as kb-api writes it. Frozen, every entry too. */
@@ -3,6 +3,12 @@ const e = Object.freeze([
3
3
  Object.freeze({ method: "POST", path: "/community/v1/public/blocks/set" }),
4
4
  Object.freeze({ method: "POST", path: "/community/v1/public/discussions/head" }),
5
5
  Object.freeze({ method: "POST", path: "/community/v1/public/discussions/list" }),
6
+ Object.freeze({ method: "POST", path: "/community/v1/public/forum/categories/list" }),
7
+ Object.freeze({ method: "POST", path: "/community/v1/public/forum/search" }),
8
+ Object.freeze({ method: "POST", path: "/community/v1/public/forum/topics/create" }),
9
+ Object.freeze({ method: "POST", path: "/community/v1/public/forum/topics/get" }),
10
+ Object.freeze({ method: "POST", path: "/community/v1/public/forum/topics/head" }),
11
+ Object.freeze({ method: "POST", path: "/community/v1/public/forum/topics/list" }),
6
12
  Object.freeze({ method: "POST", path: "/community/v1/public/legal/current" }),
7
13
  Object.freeze({ method: "POST", path: "/community/v1/public/me/appeals/file" }),
8
14
  Object.freeze({ method: "POST", path: "/community/v1/public/me/appeals/list" }),
@@ -13,6 +19,8 @@ const e = Object.freeze([
13
19
  Object.freeze({ method: "POST", path: "/community/v1/public/me/erase" }),
14
20
  Object.freeze({ method: "POST", path: "/community/v1/public/me/erase/cancel" }),
15
21
  Object.freeze({ method: "POST", path: "/community/v1/public/me/export" }),
22
+ Object.freeze({ method: "POST", path: "/community/v1/public/me/follows/list" }),
23
+ Object.freeze({ method: "POST", path: "/community/v1/public/me/follows/set" }),
16
24
  Object.freeze({ method: "POST", path: "/community/v1/public/me/get" }),
17
25
  Object.freeze({ method: "POST", path: "/community/v1/public/me/mutes/list" }),
18
26
  Object.freeze({ method: "POST", path: "/community/v1/public/me/mutes/set" }),
@@ -34,6 +42,15 @@ const e = Object.freeze([
34
42
  Object.freeze({ method: "POST", path: "/community/v1/public/messages/edit" }),
35
43
  Object.freeze({ method: "POST", path: "/community/v1/public/messages/post" }),
36
44
  Object.freeze({ method: "POST", path: "/community/v1/public/messages/report" }),
45
+ Object.freeze({ method: "POST", path: "/community/v1/public/moderation/cases/get" }),
46
+ Object.freeze({ method: "POST", path: "/community/v1/public/moderation/decide" }),
47
+ Object.freeze({ method: "POST", path: "/community/v1/public/moderation/escalate" }),
48
+ Object.freeze({ method: "POST", path: "/community/v1/public/moderation/premod/review" }),
49
+ Object.freeze({ method: "POST", path: "/community/v1/public/moderation/queue" }),
50
+ Object.freeze({ method: "POST", path: "/community/v1/public/moderation/remove" }),
51
+ Object.freeze({ method: "POST", path: "/community/v1/public/moderation/topics/move" }),
52
+ Object.freeze({ method: "POST", path: "/community/v1/public/moderation/topics/pin" }),
53
+ Object.freeze({ method: "POST", path: "/community/v1/public/moderation/topics/set-state" }),
37
54
  Object.freeze({ method: "POST", path: "/community/v1/public/profile/get" }),
38
55
  Object.freeze({ method: "POST", path: "/community/v1/public/reactions/set" }),
39
56
  Object.freeze({ method: "POST", path: "/community/v1/public/realtime/subscribe-token" }),