@blogmcp/sdk 0.9.4 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/community/channels.d.ts +7 -6
- package/dist/community/channels.js +4 -4
- package/dist/community/client.d.ts +74 -4
- package/dist/community/client.js +143 -91
- package/dist/community/index.d.ts +11 -6
- package/dist/community/index.js +111 -80
- package/dist/community/links.d.ts +61 -1
- package/dist/community/links.js +94 -40
- package/dist/community/manifest/index.d.ts +54 -0
- package/dist/community/manifest/index.js +46 -0
- package/dist/community/mentions.d.ts +38 -0
- package/dist/community/mentions.js +25 -0
- package/dist/community/messages.cs.d.ts +73 -3
- package/dist/community/messages.cs.js +82 -3
- package/dist/community/messages.d.ts +11 -0
- package/dist/community/messages.en.d.ts +69 -1
- package/dist/community/messages.en.js +71 -1
- package/dist/community/messages.js +26 -16
- package/dist/community/outcome.d.ts +8 -3
- package/dist/community/outcome.js +75 -28
- package/dist/community/realtime/index.d.ts +118 -0
- package/dist/community/realtime/index.js +215 -0
- package/dist/community/routes.d.ts +12 -0
- package/dist/community/routes.js +41 -25
- package/dist/community/server/bff.js +25 -25
- package/dist/community/server/host-routes.js +12 -0
- package/dist/community/server/index.d.ts +1 -1
- package/dist/community/server/index.js +15 -14
- package/dist/community/server/route-decision.d.ts +8 -0
- package/dist/community/server/route-decision.js +28 -22
- package/dist/community/shapes.d.ts +214 -2
- package/dist/community/shapes.js +65 -25
- package/dist/community/store.d.ts +18 -1
- package/dist/community/store.js +316 -261
- package/dist/community/sw/index.d.ts +45 -0
- package/dist/community/sw/index.js +59 -0
- package/dist/community/ua.d.ts +12 -0
- package/dist/community/ua.js +9 -0
- package/package.json +20 -3
- package/src/community/channels.ts +8 -7
- package/src/community/client.ts +116 -5
- package/src/community/index.ts +59 -1
- package/src/community/links.ts +119 -2
- package/src/community/manifest/index.ts +107 -0
- package/src/community/mentions.ts +59 -0
- package/src/community/messages.cs.ts +88 -3
- package/src/community/messages.en.ts +77 -1
- package/src/community/messages.ts +19 -0
- package/src/community/outcome.ts +53 -1
- package/src/community/realtime/index.ts +522 -0
- package/src/community/routes.ts +16 -0
- package/src/community/server/bff.ts +2 -4
- package/src/community/server/host-routes.ts +12 -0
- package/src/community/server/index.ts +1 -0
- package/src/community/server/route-decision.ts +15 -0
- package/src/community/shapes.ts +256 -3
- package/src/community/store.ts +114 -0
- package/src/community/sw/index.ts +112 -0
- package/src/community/ua.ts +17 -0
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { assertServerOnly as $ } from "../../core/server-only.js";
|
|
2
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
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
|
|
5
|
-
import { communityRouteDecision as W } from "./route-decision.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
6
|
import { communityUnknownPath as E } from "./unknown-path.js";
|
|
7
|
-
const
|
|
7
|
+
const Q = 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
|
+
}), ee = 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
|
-
}),
|
|
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
21
|
function se(t) {
|
|
22
|
-
if (t === void 0) return
|
|
23
|
-
if (typeof t != "string" || !t.startsWith("/") || !
|
|
22
|
+
if (t === void 0) return te;
|
|
23
|
+
if (typeof t != "string" || !t.startsWith("/") || !oe.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
|
);
|
|
@@ -43,11 +43,11 @@ function ae(t, e) {
|
|
|
43
43
|
function ce(t, e) {
|
|
44
44
|
if (t === void 0) return I;
|
|
45
45
|
const r = typeof t == "number" ? Math.floor(t) : Number.NaN;
|
|
46
|
-
return r >= 1 && r <=
|
|
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);
|
|
47
47
|
}
|
|
48
48
|
function ue(t) {
|
|
49
49
|
return (e) => {
|
|
50
|
-
const r = typeof e.kbCode == "string" ?
|
|
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;
|
|
51
51
|
try {
|
|
52
52
|
t({ op: String(e.op).replace(/[^A-Za-z0-9_./-]/g, "").slice(0, 64), outcome: e.outcome, kbCode: r, status: u });
|
|
53
53
|
} catch {
|
|
@@ -86,10 +86,10 @@ function de(t, e) {
|
|
|
86
86
|
return Number.isNaN(u) ? null : Math.max(0, Math.ceil((u - e) / 1e3));
|
|
87
87
|
}
|
|
88
88
|
function R(t, e, r = {}) {
|
|
89
|
-
return { status: t, headers: { ...
|
|
89
|
+
return { status: t, headers: { ...ee, ...r }, body: e };
|
|
90
90
|
}
|
|
91
91
|
function g(t) {
|
|
92
|
-
const { status: e, message: r } =
|
|
92
|
+
const { status: e, message: r } = Q[t];
|
|
93
93
|
return R(e, JSON.stringify({ ok: !1, code: t, message: r }));
|
|
94
94
|
}
|
|
95
95
|
function _e(t) {
|
|
@@ -104,13 +104,13 @@ function _e(t) {
|
|
|
104
104
|
u.has(n) || (u.add(n), console.warn(o));
|
|
105
105
|
}, p = ie(e.kbApiUrl);
|
|
106
106
|
p === null && s("kb_api_url", "[community] kbApiUrl is not an absolute http(s) URL — every community request answers 503.");
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
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
111
|
let h = typeof e.clientIpHeader == "string" ? e.clientIpHeader.trim() : H;
|
|
112
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),
|
|
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
114
|
async function v(n) {
|
|
115
115
|
if (typeof n.json != "function")
|
|
116
116
|
return s(
|
|
@@ -126,8 +126,8 @@ function _e(t) {
|
|
|
126
126
|
if (!o || typeof o != "object" || o.ok !== !0)
|
|
127
127
|
return { ok: !1, code: !!o && typeof o == "object" && o.ok === !1 && o.code === "TOO_LARGE" ? "TOO_LARGE" : "INVALID_JSON" };
|
|
128
128
|
if (!q(o.bytes)) return { ok: !1, code: "INVALID_JSON" };
|
|
129
|
-
if (o.bytes.byteLength >
|
|
130
|
-
const i = new Uint8Array(o.bytes), c =
|
|
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
131
|
return c.ok ? { ok: !0, bytes: i } : c;
|
|
132
132
|
}
|
|
133
133
|
async function B(n, o) {
|
|
@@ -151,7 +151,7 @@ function _e(t) {
|
|
|
151
151
|
body: i,
|
|
152
152
|
redirect: "error",
|
|
153
153
|
cache: "no-store",
|
|
154
|
-
signal: AbortSignal.timeout(
|
|
154
|
+
signal: AbortSignal.timeout(S)
|
|
155
155
|
});
|
|
156
156
|
} catch {
|
|
157
157
|
return l(n);
|
|
@@ -171,15 +171,15 @@ function _e(t) {
|
|
|
171
171
|
"notice_key_refused",
|
|
172
172
|
"[community] kb-api refused the notice key — check COMMUNITY_NOTICE_KEY (scope community:notice)."
|
|
173
173
|
), l(n, N(b), a.status);
|
|
174
|
-
a.status >= 500 &&
|
|
175
|
-
const w = de(a.headers,
|
|
174
|
+
a.status >= 500 && T({ op: n, outcome: "unavailable", kbCode: N(b), status: a.status });
|
|
175
|
+
const w = de(a.headers, U());
|
|
176
176
|
return R(a.status, y, w === null ? {} : { "Retry-After": String(w) });
|
|
177
177
|
}
|
|
178
178
|
async function j(n, o) {
|
|
179
179
|
if ((typeof n.method == "string" ? n.method.toUpperCase() : "") !== "POST") return E();
|
|
180
180
|
const c = me(r, n.path), m = c === null ? null : W("POST", c);
|
|
181
181
|
if (m?.kind !== "allow") return E();
|
|
182
|
-
if (o.op = fe(m.upstreamPath), !G(n,
|
|
182
|
+
if (o.op = fe(m.upstreamPath), !G(n, O))
|
|
183
183
|
return s(
|
|
184
184
|
"origin",
|
|
185
185
|
"[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."
|
|
@@ -188,7 +188,7 @@ function _e(t) {
|
|
|
188
188
|
if (f === null) return l(o.op);
|
|
189
189
|
if (!f.ok) return g(f.code);
|
|
190
190
|
if (p === null) return l(o.op);
|
|
191
|
-
const d = m.upstreamPath
|
|
191
|
+
const d = Z(m.upstreamPath), a = await B(n, d);
|
|
192
192
|
if (a.kind === "unavailable") return l(o.op);
|
|
193
193
|
const y = z(n, { header: h });
|
|
194
194
|
return y === null && s(
|
|
@@ -208,7 +208,7 @@ function _e(t) {
|
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
210
|
export {
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
Q as COMMUNITY_BFF_REFUSALS,
|
|
212
|
+
te as DEFAULT_COMMUNITY_BASE_PATH,
|
|
213
213
|
_e as createCommunityBff
|
|
214
214
|
};
|
|
@@ -14,17 +14,29 @@ const e = Object.freeze([
|
|
|
14
14
|
Object.freeze({ method: "POST", path: "/community/v1/public/me/erase/cancel" }),
|
|
15
15
|
Object.freeze({ method: "POST", path: "/community/v1/public/me/export" }),
|
|
16
16
|
Object.freeze({ method: "POST", path: "/community/v1/public/me/get" }),
|
|
17
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/me/mutes/list" }),
|
|
18
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/me/mutes/set" }),
|
|
17
19
|
Object.freeze({ method: "POST", path: "/community/v1/public/me/notifications/list" }),
|
|
18
20
|
Object.freeze({ method: "POST", path: "/community/v1/public/me/notifications/mark-read" }),
|
|
21
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/me/notifications/unread-count" }),
|
|
19
22
|
Object.freeze({ method: "POST", path: "/community/v1/public/me/onboard" }),
|
|
20
23
|
Object.freeze({ method: "POST", path: "/community/v1/public/me/profile/update" }),
|
|
24
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/me/push/status" }),
|
|
25
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/me/push/subscribe" }),
|
|
26
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/me/push/unsubscribe" }),
|
|
27
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/me/push/vapid" }),
|
|
28
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/me/realtime/token" }),
|
|
21
29
|
Object.freeze({ method: "POST", path: "/community/v1/public/me/reports/list" }),
|
|
30
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/me/settings/get" }),
|
|
31
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/me/settings/unsubscribe-digest" }),
|
|
32
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/me/settings/update" }),
|
|
22
33
|
Object.freeze({ method: "POST", path: "/community/v1/public/messages/delete" }),
|
|
23
34
|
Object.freeze({ method: "POST", path: "/community/v1/public/messages/edit" }),
|
|
24
35
|
Object.freeze({ method: "POST", path: "/community/v1/public/messages/post" }),
|
|
25
36
|
Object.freeze({ method: "POST", path: "/community/v1/public/messages/report" }),
|
|
26
37
|
Object.freeze({ method: "POST", path: "/community/v1/public/profile/get" }),
|
|
27
38
|
Object.freeze({ method: "POST", path: "/community/v1/public/reactions/set" }),
|
|
39
|
+
Object.freeze({ method: "POST", path: "/community/v1/public/realtime/subscribe-token" }),
|
|
28
40
|
Object.freeze({ method: "POST", path: "/trust/v1/notices/appeal" }),
|
|
29
41
|
Object.freeze({ method: "POST", path: "/trust/v1/notices/appeal/withdraw" }),
|
|
30
42
|
Object.freeze({ method: "POST", path: "/trust/v1/notices/status" }),
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* if (decision.kind === 'allow') return forward(decision.upstreamPath) // the bearer, no cookie, the Origin checked
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export { COMMUNITY_NAMESPACES, COMMUNITY_HOST_ROUTES, isCommunityNamespacePath, communityRouteDecision, } from './route-decision.js';
|
|
36
|
+
export { COMMUNITY_NAMESPACES, COMMUNITY_HOST_ROUTES, isCommunityNamespacePath, communityRouteDecision, isNoticeRoute, } from './route-decision.js';
|
|
37
37
|
export type { CommunityHostRoute, CommunityRouteDecision } from './route-decision.js';
|
|
38
38
|
export { COMMUNITY_UNKNOWN_PATH_BODY, communityUnknownPath } from './unknown-path.js';
|
|
39
39
|
export type { CommunityUnknownPathAnswer } from './unknown-path.js';
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { COMMUNITY_NAMESPACES as
|
|
2
|
-
import { COMMUNITY_UNKNOWN_PATH_BODY as M, communityUnknownPath as
|
|
3
|
-
import { createCommunityBff as
|
|
1
|
+
import { COMMUNITY_NAMESPACES as m, communityRouteDecision as t, isCommunityNamespacePath as r, isNoticeRoute as n } from "./route-decision.js";
|
|
2
|
+
import { COMMUNITY_UNKNOWN_PATH_BODY as M, communityUnknownPath as N } from "./unknown-path.js";
|
|
3
|
+
import { createCommunityBff as u } from "./bff.js";
|
|
4
4
|
import { communityServerEnv as _ } from "./env.js";
|
|
5
|
-
import { COMMUNITY_BODY_MAX_BYTES as
|
|
6
|
-
import { COMMUNITY_HOST_ROUTES as
|
|
5
|
+
import { COMMUNITY_BODY_MAX_BYTES as C, fromWebRequest as T, parseCommunityJson as c } from "./http.js";
|
|
6
|
+
import { COMMUNITY_HOST_ROUTES as U } from "./host-routes.js";
|
|
7
7
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
C as COMMUNITY_BODY_MAX_BYTES,
|
|
9
|
+
U as COMMUNITY_HOST_ROUTES,
|
|
10
|
+
m as COMMUNITY_NAMESPACES,
|
|
11
11
|
M as COMMUNITY_UNKNOWN_PATH_BODY,
|
|
12
|
-
|
|
12
|
+
t as communityRouteDecision,
|
|
13
13
|
_ as communityServerEnv,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
N as communityUnknownPath,
|
|
15
|
+
u as createCommunityBff,
|
|
16
|
+
T as fromWebRequest,
|
|
17
|
+
r as isCommunityNamespacePath,
|
|
18
|
+
n as isNoticeRoute,
|
|
19
|
+
c as parseCommunityJson
|
|
19
20
|
};
|
|
@@ -68,3 +68,11 @@ export declare function isCommunityNamespacePath(path: string): boolean;
|
|
|
68
68
|
export declare function decideCommunityRoute(routes: readonly CommunityHostRoute[], method: string, path: string): CommunityRouteDecision;
|
|
69
69
|
/** What a proxy or BFF does with a request for `path`. */
|
|
70
70
|
export declare function communityRouteDecision(method: string, path: string): CommunityRouteDecision;
|
|
71
|
+
/**
|
|
72
|
+
* M2 T10: whether `path` (relative to kb-api's root, as communityRouteDecision takes it) is one of kb-api's notice
|
|
73
|
+
* routes (`/trust/v1/notices/*`) — in every spelling the route decision ALLOWS: with or without the leading `/` and
|
|
74
|
+
* one `api/` segment; a query or fragment is cut first, as the decision cuts it, and the rest decides. A spelling the
|
|
75
|
+
* decision denies (upper case, an escape, a dot segment, an empty segment) and any other path are not: the hosts' one retry under the notice key (m2-contracts.md §12.4) and the BFF's credential rule
|
|
76
|
+
* apply only to a request that is forwarded at all. Never throws.
|
|
77
|
+
*/
|
|
78
|
+
export declare function isNoticeRoute(path: string): boolean;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { COMMUNITY_HOST_ROUTES as
|
|
2
|
-
const E = Object.freeze(["community", "trust"]),
|
|
1
|
+
import { COMMUNITY_HOST_ROUTES as R } from "./host-routes.js";
|
|
2
|
+
const E = Object.freeze(["community", "trust"]), C = Object.freeze(["community/v1/private", "community/v1/staff"]), O = Object.freeze({ kind: "outside" }), a = Object.freeze({ kind: "deny" }), l = 8, A = /^[\u0000-\u0020]*[a-z][a-z0-9+.-]*:\/\//i, g = /(?:%[0-9a-f]{2})+/gi, N = /%([0-7][0-9a-f])/gi, T = /%(?![0-9a-f]{2})/i, P = /[\t\n\r]/g, h = /^[\u0000-\u0020]+|[\u0000-\u0020]+$/g, y = /[\u0000-\u0020\u007f]/g, I = new Set(E), U = C.map((e) => e.split("/")), v = new RegExp(`^/?(?:api/)?((?:${E.join("|")})(?:/[a-z0-9_-]+)+)$`);
|
|
3
3
|
function m(e) {
|
|
4
4
|
const t = e.search(/[?#]/);
|
|
5
5
|
return t === -1 ? e : e.slice(0, t);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
let t =
|
|
7
|
+
function D(e) {
|
|
8
|
+
let t = T.test(e);
|
|
9
9
|
return { text: e.replace(g, (n) => {
|
|
10
10
|
try {
|
|
11
11
|
return decodeURIComponent(n);
|
|
@@ -14,11 +14,11 @@ function v(e) {
|
|
|
14
14
|
}
|
|
15
15
|
}), malformed: t };
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function M(e) {
|
|
18
18
|
const t = /* @__PURE__ */ new Set(), o = [
|
|
19
19
|
e,
|
|
20
|
-
e.replace(
|
|
21
|
-
e.replace(
|
|
20
|
+
e.replace(P, "").replace(h, ""),
|
|
21
|
+
e.replace(y, "")
|
|
22
22
|
];
|
|
23
23
|
for (const n of o) {
|
|
24
24
|
t.add(n);
|
|
@@ -27,10 +27,10 @@ function I(e) {
|
|
|
27
27
|
}
|
|
28
28
|
return [...t];
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function w(e) {
|
|
31
31
|
return e.toLowerCase().replace(/\\/g, "/").split("/").filter((t) => t !== "" && t !== ".");
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function L(e) {
|
|
34
34
|
const t = [];
|
|
35
35
|
for (const o of e)
|
|
36
36
|
o === ".." ? t.pop() : t.push(o);
|
|
@@ -45,7 +45,7 @@ function p(e) {
|
|
|
45
45
|
const t = [m(e)];
|
|
46
46
|
let o = !1, n = !1;
|
|
47
47
|
for (let u = 0; u <= l; u++) {
|
|
48
|
-
const r = t[t.length - 1], i =
|
|
48
|
+
const r = t[t.length - 1], i = D(r);
|
|
49
49
|
if (o ||= i.malformed, i.text === r) {
|
|
50
50
|
n = !0;
|
|
51
51
|
break;
|
|
@@ -55,15 +55,15 @@ function p(e) {
|
|
|
55
55
|
const s = [];
|
|
56
56
|
let c = !1;
|
|
57
57
|
for (const u of t)
|
|
58
|
-
for (const r of
|
|
59
|
-
const i =
|
|
60
|
-
i.includes("..") && (c = !0), s.push(d(i), d(
|
|
58
|
+
for (const r of M(u)) {
|
|
59
|
+
const i = w(r);
|
|
60
|
+
i.includes("..") && (c = !0), s.push(d(i), d(L(i)));
|
|
61
61
|
}
|
|
62
62
|
const f = t[t.length - 1];
|
|
63
63
|
return { readings: s, suspicious: c || o || f.includes("%") || !n, unsettled: !n };
|
|
64
64
|
}
|
|
65
|
-
const _ = (e) => e.unsettled || e.readings.some((t) => t.length > 0 &&
|
|
66
|
-
function
|
|
65
|
+
const _ = (e) => e.unsettled || e.readings.some((t) => t.length > 0 && I.has(t[0])), z = (e) => e.readings.some((t) => U.some((o) => o.every((n, s) => t[s] === n))), S = (e) => typeof e != "string" || A.test(e);
|
|
66
|
+
function Y(e) {
|
|
67
67
|
return S(e) || _(p(e));
|
|
68
68
|
}
|
|
69
69
|
function b(e, t, o) {
|
|
@@ -71,19 +71,25 @@ function b(e, t, o) {
|
|
|
71
71
|
const n = p(o);
|
|
72
72
|
if (!_(n)) return O;
|
|
73
73
|
if (n.suspicious || z(n)) return a;
|
|
74
|
-
const s =
|
|
74
|
+
const s = v.exec(m(o))?.[1];
|
|
75
75
|
if (s === void 0) return a;
|
|
76
76
|
const c = `/${s}`, f = typeof t == "string" ? t.toUpperCase() : "";
|
|
77
77
|
return Array.isArray(e) && e.some((r) => r?.method === f && r.path === c) ? Object.freeze({ kind: "allow", upstreamPath: c }) : a;
|
|
78
78
|
}
|
|
79
|
-
function
|
|
80
|
-
return b(
|
|
79
|
+
function j(e, t) {
|
|
80
|
+
return b(R, e, t);
|
|
81
|
+
}
|
|
82
|
+
const k = "/trust/v1/notices/";
|
|
83
|
+
function $(e) {
|
|
84
|
+
const t = j("POST", e);
|
|
85
|
+
return t.kind === "allow" && t.upstreamPath.startsWith(k);
|
|
81
86
|
}
|
|
82
87
|
export {
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
C as COMMUNITY_CLOSED_PATHS,
|
|
89
|
+
R as COMMUNITY_HOST_ROUTES,
|
|
85
90
|
E as COMMUNITY_NAMESPACES,
|
|
86
|
-
|
|
91
|
+
j as communityRouteDecision,
|
|
87
92
|
b as decideCommunityRoute,
|
|
88
|
-
|
|
93
|
+
Y as isCommunityNamespacePath,
|
|
94
|
+
$ as isNoticeRoute
|
|
89
95
|
};
|
|
@@ -31,10 +31,18 @@ export type KnownRestrictionKind = (typeof RESTRICTION_KINDS)[number];
|
|
|
31
31
|
export type RestrictionKind = Open<KnownRestrictionKind>;
|
|
32
32
|
export declare const isKnownRestrictionKind: (kind: unknown) => kind is KnownRestrictionKind;
|
|
33
33
|
/** In-app notifications: codes and ids only (`appeal_resolved` is a decision that supersedes another). */
|
|
34
|
-
export declare const NOTIFICATION_CODES: readonly ["decision", "appeal_resolved", "erasure_scheduled", "inactivity_warning"];
|
|
34
|
+
export declare const NOTIFICATION_CODES: readonly ["decision", "appeal_resolved", "erasure_scheduled", "inactivity_warning", "module_read_only", "module_braked", "reply", "mention", "module_push_reset", "age_limit_changed"];
|
|
35
35
|
export type KnownNotificationCode = (typeof NOTIFICATION_CODES)[number];
|
|
36
36
|
export type NotificationCode = Open<KnownNotificationCode>;
|
|
37
37
|
export declare const isKnownNotificationCode: (code: unknown) => code is KnownNotificationCode;
|
|
38
|
+
/**
|
|
39
|
+
* A member's trust level as its public name (m2-contracts.md §3.2; kb-api's TRUST_LABELS, pinned by
|
|
40
|
+
* test/community/codes-drift.spec.ts), TL0 … TL3 in order. Open: a label a newer kb-api adds reads as no label.
|
|
41
|
+
*/
|
|
42
|
+
export declare const TRUST_LABELS: readonly ["new", "member", "regular", "trusted"];
|
|
43
|
+
export type KnownTrustLabel = (typeof TRUST_LABELS)[number];
|
|
44
|
+
export type TrustLabel = Open<KnownTrustLabel>;
|
|
45
|
+
export declare const isKnownTrustLabel: (label: unknown) => label is KnownTrustLabel;
|
|
38
46
|
/** The report and notice categories (kb-api's CASE_CATEGORIES; test/community/codes-drift.spec.ts pins them). */
|
|
39
47
|
export declare const CASE_CATEGORIES: readonly ["fraud_spam", "harassment", "hate", "threats", "sexual_content", "child_at_risk", "self_harm", "doxxing", "copyright", "terrorism", "drugs", "other_illegal", "rules", "adverse_event", "third_party_health_data", "suspected_minor"];
|
|
40
48
|
export type CaseCategory = (typeof CASE_CATEGORIES)[number];
|
|
@@ -200,6 +208,13 @@ export interface PublicProfile {
|
|
|
200
208
|
/** `YYYY-MM` (UTC). */
|
|
201
209
|
readonly memberSince: string;
|
|
202
210
|
readonly bio: string | null;
|
|
211
|
+
/**
|
|
212
|
+
* M2: the member's trust level as its public name (TRUST_LABELS: `new`, `member`, `regular`, `trusted`; an open
|
|
213
|
+
* set — an unknown one reads as no label; its text is trustLabelMessageKey's). Never the number: that is the
|
|
214
|
+
* member's own (MyState.trustLevel). Absent from a kb-api older than M2, and while the community module is `dark`
|
|
215
|
+
* (no level is computed then).
|
|
216
|
+
*/
|
|
217
|
+
readonly trustLabel?: TrustLabel;
|
|
203
218
|
}
|
|
204
219
|
/** The member's own profile (MyState, `me/profile/update`). */
|
|
205
220
|
export interface OwnProfile {
|
|
@@ -209,6 +224,55 @@ export interface OwnProfile {
|
|
|
209
224
|
readonly bio: string | null;
|
|
210
225
|
readonly handleChangedAt: string | null;
|
|
211
226
|
}
|
|
227
|
+
/** The community module's state (m2-contracts.md §3.1). An unknown state reads as `dark`. */
|
|
228
|
+
export declare const MODULE_STATES: readonly ["dark", "live", "read_only", "braked"];
|
|
229
|
+
export type KnownModuleState = (typeof MODULE_STATES)[number];
|
|
230
|
+
export type ModuleState = Open<KnownModuleState>;
|
|
231
|
+
export declare const isKnownModuleState: (state: unknown) => state is KnownModuleState;
|
|
232
|
+
/** MyState's `module`: the state, its end and reason, the pause in effect, what it switches on. */
|
|
233
|
+
export interface ModuleInfo {
|
|
234
|
+
readonly state: ModuleState;
|
|
235
|
+
/** read_only or braked: when it ends (absent: no end set). */
|
|
236
|
+
readonly until?: string;
|
|
237
|
+
/** read_only: why (a code: plan_lost, kill_switch, tenant_off, …). */
|
|
238
|
+
readonly reason?: string;
|
|
239
|
+
/** The pause in effect, whatever the state (a tenant without the module may pause its discussions). */
|
|
240
|
+
readonly brake?: {
|
|
241
|
+
readonly kind: string;
|
|
242
|
+
readonly until?: string;
|
|
243
|
+
readonly reasonCode: string;
|
|
244
|
+
};
|
|
245
|
+
readonly features: {
|
|
246
|
+
readonly realtime: boolean;
|
|
247
|
+
readonly push: boolean;
|
|
248
|
+
readonly notifications: boolean;
|
|
249
|
+
readonly profiles: boolean;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* How the art. 9 consent is asked (m2-contracts.md §3.8; community.md §9.8 question 8): `joint` one consent, `split`
|
|
254
|
+
* one per controller of the consent text (`art9ControllersOf`) on the same screen. An unknown value reads as `joint`.
|
|
255
|
+
*/
|
|
256
|
+
export declare const ART9_CONSENT_LAYOUTS: readonly ["joint", "split"];
|
|
257
|
+
export type Art9ConsentLayout = (typeof ART9_CONSENT_LAYOUTS)[number];
|
|
258
|
+
/**
|
|
259
|
+
* What a refused art. 9 consent leaves (§3.8): `read_only` reading only (no refusal is offered — a reader who closes
|
|
260
|
+
* the step keeps reading), `public_write` writing in the public discussion too. An unknown value reads as `read_only`.
|
|
261
|
+
*/
|
|
262
|
+
export declare const ART9_REFUSALS: readonly ["read_only", "public_write"];
|
|
263
|
+
export type Art9Refusal = (typeof ART9_REFUSALS)[number];
|
|
264
|
+
/** The layout `me/get` names, `joint` when it names none or one this SDK does not know (an older kb-api). */
|
|
265
|
+
export declare const art9ConsentLayoutOf: (value: unknown) => Art9ConsentLayout;
|
|
266
|
+
/** The refusal `me/get` names, `read_only` when it names none or one this SDK does not know (an older kb-api). */
|
|
267
|
+
export declare const art9RefusalOf: (value: unknown) => Art9Refusal;
|
|
268
|
+
/**
|
|
269
|
+
* The tenant's art. 9 settings `me/get` carries next to the member's switches (M2 T9, §3.8); absent from a kb-api
|
|
270
|
+
* older than T9 — read them through art9ConsentLayoutOf / art9RefusalOf.
|
|
271
|
+
*/
|
|
272
|
+
export interface CommunityConsentSettings {
|
|
273
|
+
readonly art9ConsentLayout?: Art9ConsentLayout;
|
|
274
|
+
readonly art9Refusal?: Art9Refusal;
|
|
275
|
+
}
|
|
212
276
|
/** `me/get` and `me/onboard`. Anonymous: `member: null`, `needs: ['sign_in']`. */
|
|
213
277
|
export interface MyState {
|
|
214
278
|
readonly member: {
|
|
@@ -221,6 +285,11 @@ export interface MyState {
|
|
|
221
285
|
readonly acceptances: {
|
|
222
286
|
readonly rules: AcceptanceState;
|
|
223
287
|
readonly art9Consent: AcceptanceState | null;
|
|
288
|
+
/**
|
|
289
|
+
* M2 T9 (§3.8): the member refused the art. 9 consent under `art9Refusal = public_write` and has not given it
|
|
290
|
+
* since — `needs` then carries no `art9_consent`. Absent from a kb-api older than T9 (read: false).
|
|
291
|
+
*/
|
|
292
|
+
readonly art9Refused?: boolean;
|
|
224
293
|
};
|
|
225
294
|
readonly needs: readonly Need[];
|
|
226
295
|
readonly restrictions: readonly RestrictionInEffect[];
|
|
@@ -231,12 +300,136 @@ export interface MyState {
|
|
|
231
300
|
readonly statementPath: string | null;
|
|
232
301
|
readonly myCommunityPath: string | null;
|
|
233
302
|
};
|
|
303
|
+
/** M2: the community module's state (absent from a kb-api older than M2). */
|
|
304
|
+
readonly module?: ModuleInfo;
|
|
305
|
+
/**
|
|
306
|
+
* M2: the member's own trust level, 0..3 (0 without a member). Absent from a kb-api older than M2, and while the
|
|
307
|
+
* community module is `dark` (no level is computed then; `caps` stays, TL0's).
|
|
308
|
+
*/
|
|
309
|
+
readonly trustLevel?: number;
|
|
310
|
+
/**
|
|
311
|
+
* M2 T3: the member's notification switches (the defaults without a member; absent from a kb-api older than M2);
|
|
312
|
+
* M2 T9: with the tenant's art. 9 layout and refusal beside them (CommunityConsentSettings).
|
|
313
|
+
*/
|
|
314
|
+
readonly settings?: MemberSettings & CommunityConsentSettings;
|
|
315
|
+
/**
|
|
316
|
+
* M2 T10: what the member's trust level allows in one message — `mentionsPerMessage` distinct `@handle`s (kb-api's
|
|
317
|
+
* TRUST_LEVEL_CAPS; 0 without a member). A composer warns before posting more; kb-api still refuses MENTION_LIMIT.
|
|
318
|
+
* Absent from a kb-api older than T10.
|
|
319
|
+
*/
|
|
320
|
+
readonly caps?: MemberCaps;
|
|
321
|
+
}
|
|
322
|
+
/** MyState's `caps` (M2 T10). */
|
|
323
|
+
export interface MemberCaps {
|
|
324
|
+
readonly mentionsPerMessage: number;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* The member's notification switches (m2-contracts.md §3.3): replies, mentions, topic updates (off by default),
|
|
328
|
+
* push (the master switch), the daily e-mail digest, the night's quiet hours for push (22–7, the site's time).
|
|
329
|
+
*/
|
|
330
|
+
export interface MemberSettings {
|
|
331
|
+
readonly notifyReply: boolean;
|
|
332
|
+
readonly notifyMention: boolean;
|
|
333
|
+
readonly notifyTopic: boolean;
|
|
334
|
+
readonly pushEnabled: boolean;
|
|
335
|
+
readonly digestEmail: boolean;
|
|
336
|
+
readonly quietHours: boolean;
|
|
337
|
+
}
|
|
338
|
+
/** `me/settings/update`: the switches to change; the others keep their value. */
|
|
339
|
+
export type MemberSettingsUpdate = Partial<MemberSettings>;
|
|
340
|
+
/** What a member may mute: a conversation (a discussion) or another member. */
|
|
341
|
+
export declare const MUTE_TARGET_KINDS: readonly ["conversation", "member"];
|
|
342
|
+
export type MuteTargetKind = (typeof MUTE_TARGET_KINDS)[number];
|
|
343
|
+
/** One of the member's mutes (private: nobody else learns of it). */
|
|
344
|
+
export interface MuteEntry {
|
|
345
|
+
readonly targetKind: MuteTargetKind;
|
|
346
|
+
readonly targetId: string;
|
|
347
|
+
readonly mutedAt: string;
|
|
348
|
+
}
|
|
349
|
+
/** What a browser says it is when it subscribes to push (M2 T4; never the raw user agent). */
|
|
350
|
+
export declare const PUSH_USER_AGENT_CLASSES: readonly ["android", "ios", "desktop", "other"];
|
|
351
|
+
export type PushUserAgentClass = (typeof PUSH_USER_AGENT_CLASSES)[number];
|
|
352
|
+
/** `me/push/vapid` (M2 T4): the key `pushManager.subscribe({ applicationServerKey })` takes, and its id. */
|
|
353
|
+
export interface PushVapidKey {
|
|
354
|
+
/** base64url of the uncompressed P-256 point. */
|
|
355
|
+
readonly publicKey: string;
|
|
356
|
+
/** The key's id (16 hex): a subscription made for another id is gone after a rotation. */
|
|
357
|
+
readonly keyId: string;
|
|
358
|
+
}
|
|
359
|
+
/** `me/push/subscribe`: the browser's PushSubscription.toJSON() (endpoint and keys) and, optionally, its class. */
|
|
360
|
+
export interface PushSubscribeInput {
|
|
361
|
+
readonly endpoint: string;
|
|
362
|
+
readonly keys: {
|
|
363
|
+
readonly p256dh: string;
|
|
364
|
+
readonly auth: string;
|
|
365
|
+
};
|
|
366
|
+
readonly userAgentClass?: PushUserAgentClass | null;
|
|
367
|
+
}
|
|
368
|
+
/** `me/push/subscribe`'s answer: the subscription is kept for this key. */
|
|
369
|
+
export interface PushSubscribeAnswer {
|
|
370
|
+
readonly subscribed: true;
|
|
371
|
+
readonly keyId: string;
|
|
372
|
+
}
|
|
373
|
+
/** `me/push/unsubscribe`'s answer: whether the member had a subscription of that endpoint (never refused). */
|
|
374
|
+
export interface PushUnsubscribeAnswer {
|
|
375
|
+
readonly unsubscribed: boolean;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* `me/push/status { endpoint }` (M2 T10, D-M2-10): whether kb-api holds a subscription of that endpoint (compared in
|
|
379
|
+
* the canonical form `subscribe` stores) for the member viewing — false for another member's, a deleted one (a
|
|
380
|
+
* revoked session, „Odhlásit všude", a dead endpoint) or one kb-api never had. Never the endpoint back.
|
|
381
|
+
*/
|
|
382
|
+
export interface PushStatusAnswer {
|
|
383
|
+
readonly subscribed: boolean;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* `me/realtime/token` (M2 T5): the connection token for community-rt and the URL to connect to — kb-api's answer is
|
|
387
|
+
* the only source of that URL (a page never builds it from its own configuration).
|
|
388
|
+
*/
|
|
389
|
+
export interface RealtimeToken {
|
|
390
|
+
readonly token: string;
|
|
391
|
+
/** `https://<instance host>/rt` — the websocket endpoint is `${url}/connection/websocket`. */
|
|
392
|
+
readonly url: string;
|
|
393
|
+
readonly expiresInS: number;
|
|
394
|
+
}
|
|
395
|
+
/** `realtime/subscribe-token` (M2 T5): the token of one channel, `disc:<conversationId>`. */
|
|
396
|
+
export interface RealtimeSubscribeToken {
|
|
397
|
+
readonly token: string;
|
|
398
|
+
}
|
|
399
|
+
/** What a discussion's channel carries (M2 T5, m2-contracts.md §3.5): the public projection, by kind. */
|
|
400
|
+
export declare const REALTIME_EVENT_KINDS: readonly ["message", "edit", "delete", "reaction", "resync"];
|
|
401
|
+
export type RealtimeEventKind = (typeof REALTIME_EVENT_KINDS)[number];
|
|
402
|
+
/**
|
|
403
|
+
* One publication of a `disc:` channel. `rev`: message, edit → the message's rev (0 on a placeholder); delete → the
|
|
404
|
+
* row's rev after the delete; reaction → the message's rev (0 for the article's own reactions, no `seq`); resync →
|
|
405
|
+
* the conversation's last seq (re-read the discussion).
|
|
406
|
+
*/
|
|
407
|
+
export interface RealtimeEvent {
|
|
408
|
+
readonly kind: RealtimeEventKind | (string & {});
|
|
409
|
+
readonly rev: number;
|
|
410
|
+
readonly seq?: number;
|
|
411
|
+
readonly message?: PublicMessage;
|
|
412
|
+
readonly reactions?: ReactionSummary;
|
|
413
|
+
}
|
|
414
|
+
/** `me/notifications/list`'s filter (M2 T3): only unread ones, only these codes. */
|
|
415
|
+
export interface NotificationListInput {
|
|
416
|
+
readonly cursor?: string | null;
|
|
417
|
+
readonly unreadOnly?: boolean;
|
|
418
|
+
readonly codes?: readonly string[];
|
|
234
419
|
}
|
|
235
420
|
export interface NotificationItem {
|
|
236
421
|
readonly id: string;
|
|
237
422
|
readonly code: NotificationCode;
|
|
238
423
|
readonly conversationId: string | null;
|
|
424
|
+
/** The message the row is about (a `reply`: the reply; a `mention`: the message that mentions), else null. */
|
|
239
425
|
readonly seq: number | null;
|
|
426
|
+
/**
|
|
427
|
+
* M2 T10: the article of the conversation a `reply` or `mention` row is about, else null (absent from a kb-api
|
|
428
|
+
* older than T10). With `articleSlug` and `seq`, a page links the message on the article (communityMessageLink).
|
|
429
|
+
*/
|
|
430
|
+
readonly articleId?: string | null;
|
|
431
|
+
/** M2 T10: that article's slug (never its title), else null; absent from a kb-api older than T10. */
|
|
432
|
+
readonly articleSlug?: string | null;
|
|
240
433
|
readonly caseId: string | null;
|
|
241
434
|
readonly decisionId: string | null;
|
|
242
435
|
readonly createdAt: string;
|
|
@@ -328,7 +521,8 @@ export interface CurrentLegalText {
|
|
|
328
521
|
readonly body: string;
|
|
329
522
|
/**
|
|
330
523
|
* The machine-readable form (DSA art. 14(1)); for `rules` `{ version, rules: [{ id, title, summary?, anchor }] }`
|
|
331
|
-
* (communityRulesOf), for `terms` and `privacy` `{ sections: [{ id, title, anchor }] }` (communityLegalSectionsOf)
|
|
524
|
+
* (communityRulesOf), for `terms` and `privacy` `{ sections: [{ id, title, anchor }] }` (communityLegalSectionsOf),
|
|
525
|
+
* for `art9_consent` null or `{ controllers: [{ entity, label }] }` with one or two controllers (art9ControllersOf).
|
|
332
526
|
*/
|
|
333
527
|
readonly bodyJson: Readonly<Record<string, unknown>> | null;
|
|
334
528
|
readonly reconsentRequired: boolean;
|
|
@@ -344,6 +538,19 @@ export interface CommunityRule {
|
|
|
344
538
|
}
|
|
345
539
|
/** The rules of a `rules` text's `bodyJson`, in order; an entry without a string id, title and anchor is skipped. */
|
|
346
540
|
export declare function communityRulesOf(bodyJson: unknown): CommunityRule[];
|
|
541
|
+
/** One controller an `art9_consent` text names (m2-contracts.md §3.8): its registry ref and the name a reader sees. */
|
|
542
|
+
export interface Art9Controller {
|
|
543
|
+
readonly entity: string;
|
|
544
|
+
readonly label: string;
|
|
545
|
+
}
|
|
546
|
+
/** At most this many controllers a consent text names (kb-api refuses a third: BODY_JSON_INVALID). */
|
|
547
|
+
export declare const ART9_CONTROLLERS_MAX = 2;
|
|
548
|
+
/**
|
|
549
|
+
* The controllers of an `art9_consent` text's `bodyJson` (`{ controllers: [{ entity, label }] }`), in order, at most
|
|
550
|
+
* ART9_CONTROLLERS_MAX; an entry without a non-empty string entity and label is skipped. None (an empty list) for a
|
|
551
|
+
* text without them: the consent is the tenant's alone, as before T9.
|
|
552
|
+
*/
|
|
553
|
+
export declare function art9ControllersOf(bodyJson: unknown): Art9Controller[];
|
|
347
554
|
/** One section of a `terms` or `privacy` text: what the page's contents list and link. */
|
|
348
555
|
export interface CommunityLegalSection {
|
|
349
556
|
readonly id: string;
|
|
@@ -438,6 +645,11 @@ export interface OnboardInput {
|
|
|
438
645
|
rulesTextId: string;
|
|
439
646
|
/** The current `art9_consent` text's id, when the tenant asks for the consent. */
|
|
440
647
|
art9TextId?: string | null;
|
|
648
|
+
/**
|
|
649
|
+
* M2 T9 (§3.8): the reader refuses the art. 9 consent — only with no `art9TextId`, and only where the tenant's
|
|
650
|
+
* `art9Refusal` is `public_write` (else VALIDATION on `art9Refused`, issue code `art9_refusal_read_only`).
|
|
651
|
+
*/
|
|
652
|
+
art9Refused?: boolean;
|
|
441
653
|
/** Required on a member's first onboarding (no profile yet). */
|
|
442
654
|
displayName?: string | null;
|
|
443
655
|
/** Generated from the display name when absent. */
|