@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.
- package/dist/community/channels.d.ts +3 -2
- package/dist/community/client.d.ts +129 -2
- package/dist/community/client.js +231 -161
- package/dist/community/forum.d.ts +82 -0
- package/dist/community/forum.js +96 -0
- package/dist/community/index.d.ts +14 -7
- package/dist/community/index.js +185 -121
- package/dist/community/links.d.ts +38 -0
- package/dist/community/links.js +98 -71
- package/dist/community/messages.cs.d.ts +160 -1
- package/dist/community/messages.cs.js +178 -1
- package/dist/community/messages.d.ts +19 -1
- package/dist/community/messages.en.d.ts +150 -1
- package/dist/community/messages.en.js +161 -1
- package/dist/community/messages.js +37 -28
- package/dist/community/outcome.d.ts +8 -3
- package/dist/community/outcome.js +64 -20
- package/dist/community/poll.d.ts +28 -4
- package/dist/community/poll.js +70 -47
- package/dist/community/realtime/index.d.ts +19 -3
- package/dist/community/realtime/index.js +175 -145
- package/dist/community/routes.d.ts +36 -1
- package/dist/community/routes.js +51 -21
- package/dist/community/server/bff.d.ts +25 -2
- package/dist/community/server/bff.js +135 -118
- package/dist/community/server/host-routes.d.ts +3 -0
- package/dist/community/server/host-routes.js +17 -0
- package/dist/community/server/index.d.ts +5 -1
- package/dist/community/shapes.d.ts +634 -7
- package/dist/community/shapes.js +92 -61
- package/dist/community/store.d.ts +15 -0
- package/dist/community/store.js +65 -61
- package/dist/community/topic.d.ts +173 -0
- package/dist/community/topic.js +225 -0
- package/package.json +3 -3
- package/src/community/channels.ts +3 -2
- package/src/community/client.ts +209 -5
- package/src/community/forum.ts +209 -0
- package/src/community/index.ts +146 -2
- package/src/community/links.ts +64 -4
- package/src/community/messages.cs.ts +179 -1
- package/src/community/messages.en.ts +162 -1
- package/src/community/messages.ts +25 -2
- package/src/community/outcome.ts +50 -1
- package/src/community/poll.ts +79 -17
- package/src/community/realtime/index.ts +124 -48
- package/src/community/routes.ts +42 -1
- package/src/community/server/bff.ts +89 -30
- package/src/community/server/host-routes.ts +20 -0
- package/src/community/server/index.ts +5 -1
- package/src/community/shapes.ts +662 -6
- package/src/community/store.ts +11 -5
- 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
|
/**
|
package/dist/community/routes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e = (i,
|
|
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
|
|
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
|
|
53
|
-
function
|
|
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
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
return `${
|
|
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
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
y as
|
|
70
|
-
v as
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
78
|
-
|
|
100
|
+
T as COMMUNITY_PAGE_SIZE,
|
|
101
|
+
f as COMMUNITY_REPLIES_MAX,
|
|
79
102
|
p as COMMUNITY_REPORT_NOTE_MAX,
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
/**
|
|
113
|
-
|
|
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
|
|
2
|
-
import { DEFAULT_CLIENT_IP_HEADER as
|
|
3
|
-
import { originOf as
|
|
4
|
-
import { isBytes as
|
|
5
|
-
import { communityRouteDecision as
|
|
6
|
-
import { communityUnknownPath as
|
|
7
|
-
const
|
|
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
|
-
}),
|
|
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
|
-
}),
|
|
21
|
-
function
|
|
22
|
-
if (t === void 0) return
|
|
23
|
-
if (typeof t != "string" || !t.startsWith("/") || !
|
|
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
|
|
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
|
|
38
|
+
function le(t, e) {
|
|
39
39
|
if (typeof t != "string") return null;
|
|
40
|
-
const
|
|
41
|
-
return
|
|
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
|
|
44
|
-
if (t === void 0) return
|
|
45
|
-
const
|
|
46
|
-
return
|
|
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
|
|
48
|
+
function fe(t) {
|
|
49
49
|
return (e) => {
|
|
50
|
-
const
|
|
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:
|
|
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
|
|
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
|
|
60
|
+
function ye(t, e) {
|
|
61
61
|
if (typeof e != "string") return null;
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
const s =
|
|
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
|
|
67
|
+
function be(t) {
|
|
68
68
|
return t.replace(/^\/community\/v1\/public\//, "").replace(/^\/trust\/v1\//, "");
|
|
69
69
|
}
|
|
70
|
-
function
|
|
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
|
|
78
|
+
function U(t) {
|
|
79
79
|
return typeof t.code == "string" ? t.code : null;
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
const
|
|
83
|
-
if (!
|
|
84
|
-
if (/^\d{1,9}$/.test(
|
|
85
|
-
const
|
|
86
|
-
return Number.isNaN(
|
|
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,
|
|
89
|
-
return { status: t, headers: { ...
|
|
88
|
+
function R(t, e, o = {}) {
|
|
89
|
+
return { status: t, headers: { ...oe, ...o }, body: e };
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
const { status: e, message:
|
|
93
|
-
return R(e, JSON.stringify({ ok: !1, code: t, message:
|
|
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
|
|
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
|
|
104
|
-
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
let
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
async function
|
|
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
|
|
132
|
+
let r;
|
|
121
133
|
try {
|
|
122
|
-
|
|
134
|
+
r = await n.json();
|
|
123
135
|
} catch {
|
|
124
136
|
return { ok: !1, code: "INVALID_JSON" };
|
|
125
137
|
}
|
|
126
|
-
if (!
|
|
127
|
-
return { ok: !1, code: !!
|
|
128
|
-
if (!
|
|
129
|
-
if (
|
|
130
|
-
const
|
|
131
|
-
return
|
|
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
|
|
134
|
-
const i = await
|
|
135
|
-
return i != null && i !== "" ? typeof i == "string" &&
|
|
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" }) :
|
|
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
|
|
155
|
+
async function H(n, r, a, i, b, m, f) {
|
|
144
156
|
const d = { "Content-Type": "application/json" };
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
|
166
|
-
if (
|
|
167
|
-
if (
|
|
168
|
-
return s("credential_echo", "[community] kb-api's answer quoted the request's credential — not passed on (503)."), l(n, null,
|
|
169
|
-
if (
|
|
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,
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
return R(
|
|
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
|
|
179
|
-
if ((typeof n.method == "string" ? n.method.toUpperCase() : "") !== "POST") return
|
|
180
|
-
const
|
|
181
|
-
if (m?.kind !== "allow") return
|
|
182
|
-
if (
|
|
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
|
-
),
|
|
187
|
-
const f = await
|
|
188
|
-
if (f === null) return l(
|
|
189
|
-
if (!f.ok) return
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
),
|
|
214
|
+
), H(r.op, m.upstreamPath, f.bytes, p, h, u, a.signal);
|
|
198
215
|
}
|
|
199
216
|
return {
|
|
200
|
-
async handle(n) {
|
|
201
|
-
const
|
|
217
|
+
async handle(n, r) {
|
|
218
|
+
const a = { op: "bff" };
|
|
202
219
|
try {
|
|
203
|
-
return await
|
|
220
|
+
return await F(n, a, r && typeof r == "object" ? r : {});
|
|
204
221
|
} catch {
|
|
205
|
-
return l(
|
|
222
|
+
return l(a.op);
|
|
206
223
|
}
|
|
207
224
|
}
|
|
208
225
|
};
|
|
209
226
|
}
|
|
210
227
|
export {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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" }),
|