@blogmcp/sdk 0.8.0 → 0.9.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 (97) hide show
  1. package/dist/community/channels.d.ts +12 -0
  2. package/dist/community/channels.js +7 -0
  3. package/dist/community/client.d.ts +211 -0
  4. package/dist/community/client.js +188 -0
  5. package/dist/community/index.d.ts +34 -0
  6. package/dist/community/index.js +92 -0
  7. package/dist/community/links.d.ts +65 -0
  8. package/dist/community/links.js +81 -0
  9. package/dist/community/messages.cs.d.ts +331 -0
  10. package/dist/community/messages.cs.js +342 -0
  11. package/dist/community/messages.d.ts +40 -0
  12. package/dist/community/messages.en.d.ts +315 -0
  13. package/dist/community/messages.en.js +313 -0
  14. package/dist/community/messages.js +66 -0
  15. package/dist/community/outcome.d.ts +96 -0
  16. package/dist/community/outcome.js +211 -0
  17. package/dist/community/poll.d.ts +35 -0
  18. package/dist/community/poll.js +70 -0
  19. package/dist/community/routes.d.ts +110 -0
  20. package/dist/community/routes.js +66 -0
  21. package/dist/community/server/bff.d.ts +123 -0
  22. package/dist/community/server/bff.js +214 -0
  23. package/dist/community/server/env.d.ts +20 -0
  24. package/dist/community/server/env.js +16 -0
  25. package/dist/community/server/host-routes.d.ts +15 -0
  26. package/dist/community/server/host-routes.js +35 -0
  27. package/dist/community/server/http.d.ts +64 -0
  28. package/dist/community/server/http.js +90 -0
  29. package/dist/community/server/index.d.ts +45 -0
  30. package/dist/community/server/index.js +19 -0
  31. package/dist/community/server/route-decision.d.ts +70 -0
  32. package/dist/community/server/route-decision.js +89 -0
  33. package/dist/community/server/unknown-path.d.ts +21 -0
  34. package/dist/community/server/unknown-path.js +11 -0
  35. package/dist/community/shapes.d.ts +457 -0
  36. package/dist/community/shapes.js +51 -0
  37. package/dist/community/store.d.ts +183 -0
  38. package/dist/community/store.js +423 -0
  39. package/dist/community/transport.d.ts +42 -0
  40. package/dist/community/transport.js +59 -0
  41. package/dist/core/client.d.ts +17 -0
  42. package/dist/core/client.js +58 -55
  43. package/dist/core/comments-legacy.d.ts +19 -0
  44. package/dist/core/comments-legacy.js +18 -0
  45. package/dist/core/index.d.ts +3 -0
  46. package/dist/core/index.js +107 -101
  47. package/dist/core/queries.d.ts +46 -0
  48. package/dist/core/queries.js +128 -84
  49. package/dist/core/review/page.d.ts +1 -1
  50. package/dist/core/review/page.js +1 -1
  51. package/dist/core/review/plan.d.ts +1 -1
  52. package/dist/core/review/plan.js +8 -4
  53. package/dist/core/review/stamp.d.ts +4 -2
  54. package/dist/core/review/stamp.js +47 -47
  55. package/dist/core/seo.js +40 -39
  56. package/dist/core/translations/cs.json.js +6 -6
  57. package/dist/core/translations/en.json.js +1 -1
  58. package/dist/core/types.d.ts +23 -1
  59. package/dist/core/view-model.d.ts +7 -0
  60. package/dist/core/view-model.js +29 -25
  61. package/dist/react/KbMdxContent.js +4 -3
  62. package/dist/vue/components/KbMdxContent.vue2.js +3 -2
  63. package/dist/vue/composables/useKbComments.d.ts +8 -0
  64. package/package.json +13 -4
  65. package/src/community/channels.ts +12 -0
  66. package/src/community/client.ts +437 -0
  67. package/src/community/index.ts +190 -0
  68. package/src/community/links.ts +166 -0
  69. package/src/community/messages.cs.ts +371 -0
  70. package/src/community/messages.en.ts +341 -0
  71. package/src/community/messages.ts +112 -0
  72. package/src/community/outcome.ts +317 -0
  73. package/src/community/poll.ts +154 -0
  74. package/src/community/routes.ts +139 -0
  75. package/src/community/server/bff.ts +530 -0
  76. package/src/community/server/env.ts +42 -0
  77. package/src/community/server/host-routes.ts +48 -0
  78. package/src/community/server/http.ts +175 -0
  79. package/src/community/server/index.ts +55 -0
  80. package/src/community/server/route-decision.ts +226 -0
  81. package/src/community/server/unknown-path.ts +32 -0
  82. package/src/community/shapes.ts +513 -0
  83. package/src/community/store.ts +786 -0
  84. package/src/community/transport.ts +111 -0
  85. package/src/core/client.ts +24 -1
  86. package/src/core/comments-legacy.ts +39 -0
  87. package/src/core/index.ts +8 -0
  88. package/src/core/queries.ts +93 -0
  89. package/src/core/review/page.ts +1 -1
  90. package/src/core/review/plan.ts +4 -2
  91. package/src/core/review/stamp.ts +18 -5
  92. package/src/core/seo.ts +5 -1
  93. package/src/core/translations/cs.json +3 -1
  94. package/src/core/translations/en.json +3 -1
  95. package/src/core/types.ts +19 -1
  96. package/src/core/view-model.ts +12 -1
  97. package/src/vue/composables/useKbComments.ts +8 -0
@@ -0,0 +1,66 @@
1
+ import { COMMUNITY_MESSAGES_CS as a } from "./messages.cs.js";
2
+ import { COMMUNITY_MESSAGES_EN as p } from "./messages.en.js";
3
+ const c = Object.freeze({
4
+ cs: Object.freeze(a),
5
+ en: Object.freeze(p)
6
+ });
7
+ function M(t) {
8
+ return (typeof t == "string" ? t.toLowerCase().split("-")[0] : "") === "cs" ? "cs" : "en";
9
+ }
10
+ const u = /* @__PURE__ */ new Map();
11
+ function h(t, n) {
12
+ if (!u.has(t)) {
13
+ let e = null;
14
+ try {
15
+ e = new Intl.PluralRules(t);
16
+ } catch {
17
+ }
18
+ u.set(t, e);
19
+ }
20
+ return u.get(t)?.select(n) ?? "other";
21
+ }
22
+ function y(t) {
23
+ const n = typeof t == "number" ? t : typeof t == "string" && t.trim() !== "" ? Number(t) : Number.NaN;
24
+ return Number.isFinite(n) ? n : null;
25
+ }
26
+ function i(t, n) {
27
+ return Object.prototype.hasOwnProperty.call(t, n) ? t[n] : void 0;
28
+ }
29
+ function m(t, n) {
30
+ return n ? t.replace(
31
+ /\{(\w+)\}/g,
32
+ (e, r) => Object.prototype.hasOwnProperty.call(n, r) && n[r] != null ? String(n[r]) : e
33
+ ) : t;
34
+ }
35
+ function O(t, n, e) {
36
+ const r = M(t), s = c[r];
37
+ let o = i(s, n);
38
+ if (o === void 0) {
39
+ const f = y(e?.count), g = f === null ? "other" : h(r, f);
40
+ o = i(s, `${n}_${g}`) ?? i(s, `${n}_other`);
41
+ }
42
+ return o === void 0 ? String(n) : m(o, e);
43
+ }
44
+ function l(t) {
45
+ return typeof t != "string" ? !1 : i(c.en, t) !== void 0 || i(c.en, `${t}_other`) !== void 0;
46
+ }
47
+ function _(t) {
48
+ return typeof t == "string" && t.startsWith("identifier_") ? "warning.identifier" : t === "invisible_chars" ? "warning.invisible_chars" : "warning.other";
49
+ }
50
+ function w(t) {
51
+ const n = `confirm.${t}`;
52
+ return t !== "title" && t !== "submit" && t !== "other" && l(n) ? n : "confirm.other";
53
+ }
54
+ function N(t) {
55
+ const n = `note.${t}`;
56
+ return l(n) ? n : null;
57
+ }
58
+ export {
59
+ c as COMMUNITY_MESSAGES,
60
+ O as communityMessage,
61
+ M as communityMessageLanguage,
62
+ w as confirmMessageKey,
63
+ l as hasCommunityMessage,
64
+ N as noteMessageKey,
65
+ _ as warningMessageKey
66
+ };
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The envelope every community call answers with, and the one mapping from kb-api's codes to the codes a page
3
+ * shows (docs/internal/m1-contracts.md §7.12, §10.2).
4
+ *
5
+ * ⚠️ A reader never sees kb-api's text. kb-api refuses with a code and a fixed English sentence
6
+ * (`{ ok: false, code, message }`); the client turns the code into one of COMMUNITY_UI_CODES, and the page turns
7
+ * that into its own text (`communityMessage(locale, 'error.<code>')`). The mapping is total: every code kb-api
8
+ * answers (COMMUNITY_API_CODES — a copy of kb-api's `routes/community-codes.ts`, pinned by
9
+ * test/community/codes-drift.spec.ts) and every code a host's BFF answers itself has a UI code, checked by the
10
+ * compiler; a code neither list knows is `submit`.
11
+ *
12
+ * Browser-safe and server-safe: no I/O, no globals.
13
+ */
14
+ import type { KnownNeed } from './shapes.js';
15
+ /** The codes a page can be told. */
16
+ export declare const COMMUNITY_UI_CODES: readonly ["method", "origin", "unavailable", "invalid", "signIn", "onboarding", "age", "name", "handle", "restricted", "suspended", "terminated", "links", "fast", "blocked", "confirm", "removed", "quota", "captcha", "notFound", "surfaceOff", "notMoved", "ledger", "submit"];
17
+ export type CommunityUiCode = (typeof COMMUNITY_UI_CODES)[number];
18
+ /** True for one of COMMUNITY_UI_CODES. */
19
+ export declare function isCommunityUiCode(code: unknown): code is CommunityUiCode;
20
+ /** What a refusal may carry besides its code — codes, needs, a time, field paths; never anything a member wrote. */
21
+ export interface CommunityFailure {
22
+ ok: false;
23
+ code: CommunityUiCode;
24
+ /** Seconds before a retry may succeed (a quota, the burst, the rate limiter, `Retry-After`). */
25
+ retryAfterS?: number;
26
+ /** ONBOARDING_REQUIRED: what is still missing (an unknown need is dropped). */
27
+ needs?: KnownNeed[];
28
+ /** FILTER_BLOCKED, CONFIRMATION_REQUIRED: the filter codes (CONFIRMATION_REQUIRED: the ones to confirm). */
29
+ codes?: string[];
30
+ /** POSTING_RESTRICTED, ACCOUNT_SUSPENDED: when it ends (absent: no end set). */
31
+ until?: string;
32
+ /** VALIDATION: the paths of the refused fields (`displayName`, `body`, …), never their values. */
33
+ fields?: string[];
34
+ }
35
+ /** What every client method resolves to; none of them throws. */
36
+ export type CommunityOutcome<T> = {
37
+ ok: true;
38
+ value: T;
39
+ } | CommunityFailure;
40
+ /**
41
+ * Every code kb-api's community routers answer: their own, and the member, trust and quota codes they pass
42
+ * through. A copy of `COMMUNITY_API_CODES` in kb-api's `routes/community-codes.ts`, in its order.
43
+ */
44
+ export declare const COMMUNITY_API_CODES: readonly ["SURFACE_OFF", "CUTOVER_NOT_MOVED", "NOT_FOUND", "ONBOARDING_REQUIRED", "AGE_BELOW_MINIMUM", "NAME_RESERVED", "NAME_BLOCKED", "HANDLE_TAKEN", "HANDLE_RATE", "POSTING_RESTRICTED", "ACCOUNT_SUSPENDED", "ACCOUNT_TERMINATED", "TOO_MANY_LINKS", "TOO_FAST", "FILTER_BLOCKED", "CONFIRMATION_REQUIRED", "MESSAGE_REMOVED", "REACTION_NOT_ALLOWED", "CAPTCHA_FAILED", "UNAUTHORIZED", "VALIDATION", "UNAVAILABLE", "STALE_LEASE", "STAFF_POSTING_OFF", "PRESET_CONFLICT", "INTERNAL", "NOT_A_MEMBER_SESSION", "IDENTITY_NOT_ADMITTED", "ACCOUNT_NOT_ELIGIBLE", "MEMBER_READ_ONLY", "MEMBER_DELETION_REQUESTED", "PRIVATE_SPACE", "WRONG_PROVIDER", "CASE_CLOSED", "NOTIFIER_NOT_ALLOWED", "UNSUPPORTED_RESTRICTION", "LADDER_EXCEEDED", "PERSON_REQUIRED", "APPEAL_OPEN", "APPEAL_WINDOW_CLOSED", "APPEAL_NEEDS_ANOTHER_PERSON", "GAG_PLATFORM_ONLY", "ORDER_FINAL", "BODY_JSON_INVALID", "AUDIT_DETAIL_NOT_CODE", "LEDGER_UNAVAILABLE", "INVALID_INPUT", "LEGAL_HOLD", "TEXT_MISSING", "QUOTA_DAILY", "QUOTA_IP_HOURLY"];
45
+ /** A code kb-api's community routers answer. */
46
+ export type CommunityApiCode = (typeof COMMUNITY_API_CODES)[number];
47
+ /**
48
+ * Every kb-api code → the page's code. `satisfies Record` over the whole union: a code kb-api adds (and the drift
49
+ * spec makes this list add) fails the type check here instead of reaching a page as an unknown string.
50
+ *
51
+ * Codes no public or notice operation can produce (the team's, the adapter's, the decision engine's) map to
52
+ * `submit`: should one arrive anyway, the page gets the generic text and the log shows the kb-api code.
53
+ */
54
+ export declare const COMMUNITY_OUTCOME_OF_KB: Readonly<Record<CommunityApiCode, CommunityUiCode>>;
55
+ /**
56
+ * The codes a host's BFF answers ITSELF, in kb-api's envelope, before kb-api is asked (m1-contracts.md §10.3):
57
+ * a method other than POST, a foreign origin, a body over 64 KB, a body that is not JSON.
58
+ */
59
+ export declare const COMMUNITY_HOST_CODES: readonly ["METHOD", "ORIGIN", "TOO_LARGE", "INVALID_JSON"];
60
+ export type CommunityHostCode = (typeof COMMUNITY_HOST_CODES)[number];
61
+ export declare const COMMUNITY_OUTCOME_OF_HOST: Readonly<Record<CommunityHostCode, CommunityUiCode>>;
62
+ /** A kb-api or host code → the page's code. Unknown and absent codes are `submit`. */
63
+ export declare function communityOutcomeOf(code: string | null | undefined): CommunityUiCode;
64
+ /**
65
+ * The host could not be asked: the network failed, the request timed out or was aborted. A replaceable transport
66
+ * throws it (or anything else — every throw is a failure the client maps, never a crash of the page).
67
+ *
68
+ * Its message must stay free of anything a member sent (bodies, names, tokens): it names what failed.
69
+ */
70
+ export declare class CommunityTransportError extends Error {
71
+ /** The HTTP status, or null when there was no response (network, timeout). */
72
+ readonly status: number | null;
73
+ /** Seconds to wait before retrying (`Retry-After`), or null. */
74
+ readonly retryAfterS: number | null;
75
+ constructor(message: string, init?: {
76
+ status?: number | null;
77
+ retryAfterS?: number | null;
78
+ });
79
+ }
80
+ /** True for a CommunityTransportError, also one thrown by another copy of the SDK. */
81
+ export declare function isCommunityTransportError(err: unknown): err is CommunityTransportError;
82
+ /** Anything a transport threw → `unavailable`, with the error's `retryAfterS` when it carries one. */
83
+ export declare function communityFailureOf(err: unknown): CommunityFailure;
84
+ /**
85
+ * Where the client reports what operators should see — an outage, a host misconfiguration, something unexpected
86
+ * (isLoggedCommunityOutcome). It gets the operation, the outcome, kb-api's code and the HTTP status: never a body,
87
+ * a name, a handle, an address, a receipt, a token, a session or an IP.
88
+ */
89
+ export type CommunityLogger = (e: {
90
+ op: string;
91
+ outcome: CommunityUiCode;
92
+ kbCode?: string | null;
93
+ status?: number | null;
94
+ }) => void;
95
+ /** The outcomes worth an operator's attention; the rest are ordinary member states (a quota, a needed sign-in). */
96
+ export declare function isLoggedCommunityOutcome(code: CommunityUiCode): boolean;
@@ -0,0 +1,211 @@
1
+ const I = [
2
+ /** The host refused the method (a programming error: every operation is a POST). */
3
+ "method",
4
+ /** The host refused the request's origin (the page and its API are on different sites). */
5
+ "origin",
6
+ /** The host or kb-api could not be reached, or asked to retry later. */
7
+ "unavailable",
8
+ /** The request did not validate (a field's shape, a body too large). */
9
+ "invalid",
10
+ /** A signed-in reader is needed — or the session cannot take part (not a reader's, or not admitted here). */
11
+ "signIn",
12
+ /** The member has to finish joining first (`needs` says what). */
13
+ "onboarding",
14
+ /** The community is not open to the member's age group. */
15
+ "age",
16
+ /** The display name is reserved or not accepted. */
17
+ "name",
18
+ /** The handle is taken, or changed too recently. */
19
+ "handle",
20
+ /** Posting is restricted (a sanction; `until` when it ends) or the member is read-only. */
21
+ "restricted",
22
+ /** The community account is suspended (`until`). */
23
+ "suspended",
24
+ /** The community account is closed. */
25
+ "terminated",
26
+ /** Too many links in one message. */
27
+ "links",
28
+ /** Too fast — wait `retryAfterS`. */
29
+ "fast",
30
+ /** The filters refused the text: nothing was stored. */
31
+ "blocked",
32
+ /** The author must confirm `codes` (e.g. writing about themselves) and send again with `confirmations`. */
33
+ "confirm",
34
+ /** The message was removed: it cannot be edited. */
35
+ "removed",
36
+ /** A daily or per-network quota — `retryAfterS` when it frees. */
37
+ "quota",
38
+ /** The Turnstile check failed: a fresh token, then again. */
39
+ "captcha",
40
+ /** No such thing, or not visible to this viewer (the same answer for both). */
41
+ "notFound",
42
+ /** Discussions are switched off here: render nothing. */
43
+ "surfaceOff",
44
+ /** The discussion does not take writes yet (the legacy comments' cutover). */
45
+ "notMoved",
46
+ /** kb-api could not record the change; nothing changed — retry. */
47
+ "ledger",
48
+ /** Anything else: "that did not work, try again". */
49
+ "submit"
50
+ ], n = new Set(I);
51
+ function R(E) {
52
+ return typeof E == "string" && n.has(E);
53
+ }
54
+ const L = [
55
+ "SURFACE_OFF",
56
+ "CUTOVER_NOT_MOVED",
57
+ "NOT_FOUND",
58
+ "ONBOARDING_REQUIRED",
59
+ "AGE_BELOW_MINIMUM",
60
+ "NAME_RESERVED",
61
+ "NAME_BLOCKED",
62
+ "HANDLE_TAKEN",
63
+ "HANDLE_RATE",
64
+ "POSTING_RESTRICTED",
65
+ "ACCOUNT_SUSPENDED",
66
+ "ACCOUNT_TERMINATED",
67
+ "TOO_MANY_LINKS",
68
+ "TOO_FAST",
69
+ "FILTER_BLOCKED",
70
+ "CONFIRMATION_REQUIRED",
71
+ "MESSAGE_REMOVED",
72
+ "REACTION_NOT_ALLOWED",
73
+ "CAPTCHA_FAILED",
74
+ "UNAUTHORIZED",
75
+ "VALIDATION",
76
+ "UNAVAILABLE",
77
+ "STALE_LEASE",
78
+ "STAFF_POSTING_OFF",
79
+ "PRESET_CONFLICT",
80
+ "INTERNAL",
81
+ "NOT_A_MEMBER_SESSION",
82
+ "IDENTITY_NOT_ADMITTED",
83
+ "ACCOUNT_NOT_ELIGIBLE",
84
+ "MEMBER_READ_ONLY",
85
+ "MEMBER_DELETION_REQUESTED",
86
+ "PRIVATE_SPACE",
87
+ "WRONG_PROVIDER",
88
+ "CASE_CLOSED",
89
+ "NOTIFIER_NOT_ALLOWED",
90
+ "UNSUPPORTED_RESTRICTION",
91
+ "LADDER_EXCEEDED",
92
+ "PERSON_REQUIRED",
93
+ "APPEAL_OPEN",
94
+ "APPEAL_WINDOW_CLOSED",
95
+ "APPEAL_NEEDS_ANOTHER_PERSON",
96
+ "GAG_PLATFORM_ONLY",
97
+ "ORDER_FINAL",
98
+ "BODY_JSON_INVALID",
99
+ "AUDIT_DETAIL_NOT_CODE",
100
+ "LEDGER_UNAVAILABLE",
101
+ "INVALID_INPUT",
102
+ "LEGAL_HOLD",
103
+ "TEXT_MISSING",
104
+ "QUOTA_DAILY",
105
+ "QUOTA_IP_HOURLY"
106
+ ], t = Object.freeze({
107
+ SURFACE_OFF: "surfaceOff",
108
+ CUTOVER_NOT_MOVED: "notMoved",
109
+ NOT_FOUND: "notFound",
110
+ ONBOARDING_REQUIRED: "onboarding",
111
+ AGE_BELOW_MINIMUM: "age",
112
+ NAME_RESERVED: "name",
113
+ NAME_BLOCKED: "name",
114
+ HANDLE_TAKEN: "handle",
115
+ HANDLE_RATE: "handle",
116
+ POSTING_RESTRICTED: "restricted",
117
+ ACCOUNT_SUSPENDED: "suspended",
118
+ ACCOUNT_TERMINATED: "terminated",
119
+ TOO_MANY_LINKS: "links",
120
+ TOO_FAST: "fast",
121
+ FILTER_BLOCKED: "blocked",
122
+ CONFIRMATION_REQUIRED: "confirm",
123
+ MESSAGE_REMOVED: "removed",
124
+ // An emoji outside the tenant's set: the page offered a stale set, the request was malformed.
125
+ REACTION_NOT_ALLOWED: "invalid",
126
+ CAPTCHA_FAILED: "captcha",
127
+ UNAUTHORIZED: "signIn",
128
+ VALIDATION: "invalid",
129
+ // The notice routes without kb-api's capability key, and a BFF's failed upstream call.
130
+ UNAVAILABLE: "unavailable",
131
+ STALE_LEASE: "submit",
132
+ STAFF_POSTING_OFF: "submit",
133
+ PRESET_CONFLICT: "submit",
134
+ INTERNAL: "unavailable",
135
+ // A session that is not a reader's (the team, a key) or an identity the tenant does not admit: sign in as a reader.
136
+ NOT_A_MEMBER_SESSION: "signIn",
137
+ IDENTITY_NOT_ADMITTED: "signIn",
138
+ ACCOUNT_NOT_ELIGIBLE: "signIn",
139
+ // Writes are closed for the member (a 16–17 member under an 18 minimum, a pending deletion); MyState says which.
140
+ MEMBER_READ_ONLY: "restricted",
141
+ MEMBER_DELETION_REQUESTED: "restricted",
142
+ PRIVATE_SPACE: "submit",
143
+ WRONG_PROVIDER: "submit",
144
+ // An appeal that came too late or twice (another tab, a window that closed meanwhile): refetch the statement.
145
+ CASE_CLOSED: "submit",
146
+ // A child-at-risk notice with a name or e-mail: the form hides those fields, so this is a wrong form.
147
+ NOTIFIER_NOT_ALLOWED: "invalid",
148
+ UNSUPPORTED_RESTRICTION: "submit",
149
+ LADDER_EXCEEDED: "submit",
150
+ PERSON_REQUIRED: "submit",
151
+ APPEAL_OPEN: "submit",
152
+ APPEAL_WINDOW_CLOSED: "submit",
153
+ APPEAL_NEEDS_ANOTHER_PERSON: "submit",
154
+ GAG_PLATFORM_ONLY: "submit",
155
+ ORDER_FINAL: "submit",
156
+ BODY_JSON_INVALID: "invalid",
157
+ AUDIT_DETAIL_NOT_CODE: "submit",
158
+ LEDGER_UNAVAILABLE: "ledger",
159
+ INVALID_INPUT: "invalid",
160
+ LEGAL_HOLD: "submit",
161
+ // The tenant has not published the text a join needs: the community cannot be joined yet.
162
+ TEXT_MISSING: "unavailable",
163
+ QUOTA_DAILY: "quota",
164
+ QUOTA_IP_HOURLY: "quota"
165
+ }), s = ["METHOD", "ORIGIN", "TOO_LARGE", "INVALID_JSON"], A = Object.freeze({
166
+ METHOD: "method",
167
+ ORIGIN: "origin",
168
+ TOO_LARGE: "invalid",
169
+ INVALID_JSON: "invalid"
170
+ }), N = (E, O) => Object.prototype.hasOwnProperty.call(E, O);
171
+ function S(E) {
172
+ return typeof E != "string" || E === "" ? "submit" : N(t, E) ? t[E] : N(A, E) ? A[E] : "submit";
173
+ }
174
+ const T = /* @__PURE__ */ Symbol.for("@blogmcp/sdk/CommunityTransportError");
175
+ function r(E) {
176
+ return typeof E == "number" && Number.isInteger(E) && E >= 100 && E <= 599 ? E : null;
177
+ }
178
+ function i(E) {
179
+ return typeof E == "number" && Number.isFinite(E) && E >= 0 ? Math.ceil(E) : null;
180
+ }
181
+ class D extends Error {
182
+ /** The HTTP status, or null when there was no response (network, timeout). */
183
+ status;
184
+ /** Seconds to wait before retrying (`Retry-After`), or null. */
185
+ retryAfterS;
186
+ constructor(O, _ = {}) {
187
+ super(O), this.name = "CommunityTransportError", this.status = r(_.status), this.retryAfterS = i(_.retryAfterS), Object.defineProperty(this, T, { value: !0 });
188
+ }
189
+ }
190
+ function e(E) {
191
+ return E instanceof D ? !0 : E instanceof Error && E[T] === !0;
192
+ }
193
+ function u(E) {
194
+ return e(E) && E.retryAfterS !== null ? { ok: !1, code: "unavailable", retryAfterS: E.retryAfterS } : { ok: !1, code: "unavailable" };
195
+ }
196
+ function o(E) {
197
+ return E === "unavailable" || E === "submit" || E === "method" || E === "origin" || E === "invalid" || E === "ledger";
198
+ }
199
+ export {
200
+ L as COMMUNITY_API_CODES,
201
+ s as COMMUNITY_HOST_CODES,
202
+ A as COMMUNITY_OUTCOME_OF_HOST,
203
+ t as COMMUNITY_OUTCOME_OF_KB,
204
+ I as COMMUNITY_UI_CODES,
205
+ D as CommunityTransportError,
206
+ u as communityFailureOf,
207
+ S as communityOutcomeOf,
208
+ e as isCommunityTransportError,
209
+ R as isCommunityUiCode,
210
+ o as isLoggedCommunityOutcome
211
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Polls `discussions/head` while the page shows the discussion (docs/internal/m1-contracts.md §10.2; M1 has no
3
+ * realtime off Pro): the review layer's poller rules — only while visible, `Retry-After` honoured on 429, every
4
+ * failure doubles the wait up to 5 minutes, stopped when the element goes. A page shown again, or `now()`, asks at
5
+ * once — except while a failure's wait runs: neither cuts a `Retry-After` or the backoff short.
6
+ *
7
+ * const poller = pollDiscussionHead(client, [articleId], {
8
+ * onChange: (heads) => { if (heads.some((h) => store.applyHead(h))) void refreshDiscussion(store, client, input) },
9
+ * })
10
+ * // on unmount: poller.stop()
11
+ */
12
+ import type { CommunityClient } from './client.js';
13
+ import type { CommunityFailure } from './outcome.js';
14
+ import type { DiscussionHead } from './shapes.js';
15
+ export interface PollDiscussionHeadOptions {
16
+ /** Whether the discussion is seen now; default: the document is visible. Polls only while true. */
17
+ visible?: () => boolean;
18
+ /** Default 20 s (at least 1 s). */
19
+ intervalMs?: number;
20
+ /** The heads that differ from the previous answer (the first answer: every head). */
21
+ onChange(heads: DiscussionHead[]): void;
22
+ /** A poll that failed; the poller goes on, slower — `surfaceOff` stops it (discussions are switched off). */
23
+ onFailure?(failure: CommunityFailure): void;
24
+ /** Aborting it stops the poller (the element's lifetime). */
25
+ signal?: AbortSignal;
26
+ }
27
+ export interface DiscussionHeadPoller {
28
+ /** Stops for good: no timer, no listener, the request in flight aborted. */
29
+ stop(): void;
30
+ /** Polls now (the element came into view) — or when a failure's wait ends, if one runs. */
31
+ now(): void;
32
+ }
33
+ export declare const POLL_INTERVAL_MS = 20000;
34
+ export declare const POLL_MAX_BACKOFF_MS: number;
35
+ export declare function pollDiscussionHead(client: Pick<CommunityClient, 'discussions'>, articleIds: readonly string[], options: PollDiscussionHeadOptions): DiscussionHeadPoller;
@@ -0,0 +1,70 @@
1
+ import { COMMUNITY_HEAD_ARTICLES_MAX as p } from "./routes.js";
2
+ const C = 2e4, I = 5 * 6e4, w = 6e4, O = (a, o) => a.lastSeq === o.lastSeq && a.count === o.count && a.lastChangeAt === o.lastChangeAt;
3
+ function F(a, o, n) {
4
+ const l = Math.max(1e3, n.intervalMs ?? C), g = [...new Set((Array.isArray(o) ? o : []).filter((e) => typeof e == "string" && e !== ""))].slice(
5
+ 0,
6
+ p
7
+ ), m = n.visible ?? (() => typeof document > "u" || document.visibilityState !== "hidden"), v = /* @__PURE__ */ new Map();
8
+ let i = null, s = null, f = 0, d = !1, r = !1;
9
+ const c = (e) => {
10
+ r || (i && clearTimeout(i), i = setTimeout(() => {
11
+ E();
12
+ }, e));
13
+ }, A = (e) => {
14
+ c(e), d = !0;
15
+ }, M = () => {
16
+ !r && !s && !d && c(0);
17
+ };
18
+ async function E() {
19
+ if (i = null, d = !1, r || s) return;
20
+ if (!m()) {
21
+ c(l);
22
+ return;
23
+ }
24
+ const e = new AbortController();
25
+ s = e;
26
+ const T = { signal: e.signal }, t = await a.discussions.head({ articleIds: g }, T);
27
+ if (s = null, !r) {
28
+ if (t.ok) {
29
+ f = 0;
30
+ const y = [];
31
+ for (const u of Array.isArray(t.value.heads) ? t.value.heads : []) {
32
+ if (typeof u?.articleId != "string") continue;
33
+ const _ = u.articleId.toLowerCase(), S = v.get(_);
34
+ v.set(_, u), (!S || !O(S, u)) && y.push(u);
35
+ }
36
+ if (y.length > 0)
37
+ try {
38
+ n.onChange(y);
39
+ } catch {
40
+ }
41
+ c(l);
42
+ return;
43
+ }
44
+ try {
45
+ n.onFailure?.(t);
46
+ } catch {
47
+ }
48
+ if (t.code === "surfaceOff") return h();
49
+ if (t.code === "fast" || t.code === "quota") {
50
+ A(Math.max(l, t.retryAfterS !== void 0 ? t.retryAfterS * 1e3 : w));
51
+ return;
52
+ }
53
+ f = Math.min(I, (f || l) * 2), A(f);
54
+ }
55
+ }
56
+ const b = () => {
57
+ m() && M();
58
+ }, L = () => h();
59
+ function h() {
60
+ r || (r = !0, i && clearTimeout(i), i = null, s?.abort(), s = null, typeof document < "u" && document.removeEventListener("visibilitychange", b), n.signal?.removeEventListener("abort", L));
61
+ }
62
+ return g.length === 0 || n.signal?.aborted ? (r = !0, { stop: () => {
63
+ }, now: () => {
64
+ } }) : (typeof document < "u" && document.addEventListener("visibilitychange", b), n.signal?.addEventListener("abort", L, { once: !0 }), c(l), { stop: h, now: M });
65
+ }
66
+ export {
67
+ C as POLL_INTERVAL_MS,
68
+ I as POLL_MAX_BACKOFF_MS,
69
+ F as pollDiscussionHead
70
+ };
@@ -0,0 +1,110 @@
1
+ /**
2
+ * The community's operations — the one place in `@blogmcp/sdk/community` that spells kb-api's paths
3
+ * (docs/internal/m1-contracts.md §7.1, §7.4, §7.7, §8.3, §10.2) — and the limits a page checks before it posts.
4
+ *
5
+ * Every operation is a POST of a JSON body to one literal path; ids travel in the body, never in a path or a query,
6
+ * so a host's proxy or BFF forwards a list of literal routes and nothing else. COMMUNITY_OPS is kb-api's
7
+ * `routes/community-public-routes.json` (the allowlist kb-api generates from its routers) keyed by the client's
8
+ * name for each operation; test/community/ops-drift.spec.ts reads that file and fails on any difference.
9
+ *
10
+ * A host serves the operations under ONE relative base (the blog's proxy, a headless site's BFF): the public ones
11
+ * at `${base}/v1/public/<resource>/<verb>`, the notice form's at `${base}/trust/v1/notices/<verb>`
12
+ * (`communityOpPath`). The private surfaces have no operation here: their client is its own entry, later
13
+ * (community.md §3.7).
14
+ *
15
+ * Browser-safe: nothing here takes a key, and nothing imports `node:*`.
16
+ */
17
+ /** Which kb-api router serves an operation: the public API (`/community/v1/public`) or the notice form (`/trust/v1`). */
18
+ export type CommunitySurface = 'public' | 'notice';
19
+ /** One operation: the client's name, the method and kb-api's literal path. */
20
+ export interface CommunityOp<N extends string = CommunityOpName> {
21
+ readonly name: N;
22
+ readonly method: 'POST';
23
+ /** kb-api's path, exactly as `routes/community-public-routes.json` lists it. */
24
+ readonly path: string;
25
+ readonly surface: CommunitySurface;
26
+ }
27
+ /** Every operation of the public client, by name. */
28
+ export declare const COMMUNITY_OPS: Readonly<{
29
+ readonly 'discussions.list': CommunityOp<"discussions.list">;
30
+ readonly 'discussions.head': CommunityOp<"discussions.head">;
31
+ readonly 'messages.post': CommunityOp<"messages.post">;
32
+ readonly 'messages.edit': CommunityOp<"messages.edit">;
33
+ readonly 'messages.delete': CommunityOp<"messages.delete">;
34
+ readonly 'messages.report': CommunityOp<"messages.report">;
35
+ readonly 'reactions.set': CommunityOp<"reactions.set">;
36
+ readonly 'blocks.set': CommunityOp<"blocks.set">;
37
+ readonly 'blocks.list': CommunityOp<"blocks.list">;
38
+ readonly 'profile.get': CommunityOp<"profile.get">;
39
+ readonly 'me.get': CommunityOp<"me.get">;
40
+ readonly 'me.onboard': CommunityOp<"me.onboard">;
41
+ readonly 'me.updateProfile': CommunityOp<"me.updateProfile">;
42
+ readonly 'me.notifications.list': CommunityOp<"me.notifications.list">;
43
+ readonly 'me.notifications.markRead': CommunityOp<"me.notifications.markRead">;
44
+ readonly 'me.decisions.list': CommunityOp<"me.decisions.list">;
45
+ readonly 'me.decisions.get': CommunityOp<"me.decisions.get">;
46
+ readonly 'me.appeals.file': CommunityOp<"me.appeals.file">;
47
+ readonly 'me.appeals.withdraw': CommunityOp<"me.appeals.withdraw">;
48
+ readonly 'me.appeals.list': CommunityOp<"me.appeals.list">;
49
+ readonly 'me.reports.list': CommunityOp<"me.reports.list">;
50
+ readonly 'me.consents.withdraw': CommunityOp<"me.consents.withdraw">;
51
+ readonly 'me.export': CommunityOp<"me.export">;
52
+ readonly 'me.erase': CommunityOp<"me.erase">;
53
+ readonly 'me.cancelErase': CommunityOp<"me.cancelErase">;
54
+ readonly 'legal.current': CommunityOp<"legal.current">;
55
+ readonly 'notices.submit': CommunityOp<"notices.submit">;
56
+ readonly 'notices.status': CommunityOp<"notices.status">;
57
+ readonly 'notices.appeal': CommunityOp<"notices.appeal">;
58
+ readonly 'notices.withdrawAppeal': CommunityOp<"notices.withdrawAppeal">;
59
+ }>;
60
+ /** The client's name of an operation: `discussions.list`, `me.notifications.markRead`, … */
61
+ export type CommunityOpName = keyof typeof COMMUNITY_OPS;
62
+ /**
63
+ * Where an operation is served under a host's base: `/v1/public/<resource>/<verb>` for the public API (the base
64
+ * stands in for kb-api's `/community`), `/trust/v1/notices/<verb>` for the notice form.
65
+ */
66
+ export declare function communityOpPath(o: Pick<CommunityOp, 'path' | 'surface'>): string;
67
+ /** A message body, in code points (kb-api's MESSAGE_MAX_CHARS and the DB's CHECK). */
68
+ export declare const COMMUNITY_MESSAGE_MAX = 4000;
69
+ /** Links in one message (TOO_MANY_LINKS above it). */
70
+ export declare const COMMUNITY_MESSAGE_LINKS_MAX = 2;
71
+ /** A report's note (`messages/report`). */
72
+ export declare const COMMUNITY_REPORT_NOTE_MAX = 1000;
73
+ /** An appeal's text (`me/appeals/file`, `notices/appeal`). */
74
+ export declare const COMMUNITY_APPEAL_MAX = 4000;
75
+ /** A notice's description (`notices/submit`). */
76
+ export declare const COMMUNITY_NOTICE_DESCRIPTION_MAX = 4000;
77
+ /** A notifier's optional name. */
78
+ export declare const COMMUNITY_NOTIFIER_NAME_MAX = 120;
79
+ /** A display name, in characters after kb-api's NFKC fold. */
80
+ export declare const COMMUNITY_DISPLAY_NAME_MIN = 2;
81
+ export declare const COMMUNITY_DISPLAY_NAME_MAX = 80;
82
+ /** A profile's bio. */
83
+ export declare const COMMUNITY_BIO_MAX = 280;
84
+ /** A handle (kb-api's HANDLE_RE): lower case, digits and `_`, 3–30 characters, not starting with `_`. */
85
+ export declare const COMMUNITY_HANDLE_RE: RegExp;
86
+ /** Days between two handle changes (HANDLE_RATE). */
87
+ export declare const COMMUNITY_HANDLE_CHANGE_DAYS = 30;
88
+ /** Articles one `discussions/head` asks about. */
89
+ export declare const COMMUNITY_HEAD_ARTICLES_MAX = 50;
90
+ /** Top-level messages in one `discussions/list` page (the cursor is the last one's `seq`). */
91
+ export declare const COMMUNITY_PAGE_SIZE = 50;
92
+ /** Replies one top-level message carries before `repliesTruncated`. */
93
+ export declare const COMMUNITY_REPLIES_MAX = 200;
94
+ /** The Turnstile action the notice form's widget declares; kb-api refuses a token issued for any other. */
95
+ export declare const COMMUNITY_NOTICE_TURNSTILE_ACTION = "community_notice";
96
+ /**
97
+ * The confirmation a notice carries (DSA art. 16(2)(d): the notifier's good-faith statement). Without it in
98
+ * `confirmations`, `notices/submit` answers CONFIRMATION_REQUIRED with this code.
99
+ */
100
+ export declare const COMMUNITY_GOOD_FAITH = "good_faith";
101
+ /** A `clientMsgId`: a UUID (the pattern kb-api validates). */
102
+ export declare const COMMUNITY_CLIENT_MSG_ID_RE: RegExp;
103
+ /**
104
+ * A fresh `clientMsgId` for one post (a v4 UUID). Mint it when the composer submits and send the SAME id again on
105
+ * a retry: kb-api answers a repeat with the message it already stored instead of posting twice.
106
+ *
107
+ * `crypto.randomUUID` exists only in secure contexts; a page opened over plain http on a LAN address (a phone
108
+ * during development) gets a UUID from `crypto.getRandomValues`, which exists everywhere.
109
+ */
110
+ export declare function newClientMsgId(): string;
@@ -0,0 +1,66 @@
1
+ const e = (i, s, t) => Object.freeze({ name: i, method: "POST", path: t, surface: s }), n = Object.freeze({
2
+ "discussions.list": e("discussions.list", "public", "/community/v1/public/discussions/list"),
3
+ "discussions.head": e("discussions.head", "public", "/community/v1/public/discussions/head"),
4
+ "messages.post": e("messages.post", "public", "/community/v1/public/messages/post"),
5
+ "messages.edit": e("messages.edit", "public", "/community/v1/public/messages/edit"),
6
+ "messages.delete": e("messages.delete", "public", "/community/v1/public/messages/delete"),
7
+ "messages.report": e("messages.report", "public", "/community/v1/public/messages/report"),
8
+ "reactions.set": e("reactions.set", "public", "/community/v1/public/reactions/set"),
9
+ "blocks.set": e("blocks.set", "public", "/community/v1/public/blocks/set"),
10
+ "blocks.list": e("blocks.list", "public", "/community/v1/public/blocks/list"),
11
+ "profile.get": e("profile.get", "public", "/community/v1/public/profile/get"),
12
+ "me.get": e("me.get", "public", "/community/v1/public/me/get"),
13
+ "me.onboard": e("me.onboard", "public", "/community/v1/public/me/onboard"),
14
+ "me.updateProfile": e("me.updateProfile", "public", "/community/v1/public/me/profile/update"),
15
+ "me.notifications.list": e("me.notifications.list", "public", "/community/v1/public/me/notifications/list"),
16
+ "me.notifications.markRead": e("me.notifications.markRead", "public", "/community/v1/public/me/notifications/mark-read"),
17
+ "me.decisions.list": e("me.decisions.list", "public", "/community/v1/public/me/decisions/list"),
18
+ "me.decisions.get": e("me.decisions.get", "public", "/community/v1/public/me/decisions/get"),
19
+ "me.appeals.file": e("me.appeals.file", "public", "/community/v1/public/me/appeals/file"),
20
+ "me.appeals.withdraw": e("me.appeals.withdraw", "public", "/community/v1/public/me/appeals/withdraw"),
21
+ "me.appeals.list": e("me.appeals.list", "public", "/community/v1/public/me/appeals/list"),
22
+ "me.reports.list": e("me.reports.list", "public", "/community/v1/public/me/reports/list"),
23
+ "me.consents.withdraw": e("me.consents.withdraw", "public", "/community/v1/public/me/consents/withdraw"),
24
+ "me.export": e("me.export", "public", "/community/v1/public/me/export"),
25
+ "me.erase": e("me.erase", "public", "/community/v1/public/me/erase"),
26
+ "me.cancelErase": e("me.cancelErase", "public", "/community/v1/public/me/erase/cancel"),
27
+ "legal.current": e("legal.current", "public", "/community/v1/public/legal/current"),
28
+ "notices.submit": e("notices.submit", "notice", "/trust/v1/notices/submit"),
29
+ "notices.status": e("notices.status", "notice", "/trust/v1/notices/status"),
30
+ "notices.appeal": e("notices.appeal", "notice", "/trust/v1/notices/appeal"),
31
+ "notices.withdrawAppeal": e("notices.withdrawAppeal", "notice", "/trust/v1/notices/appeal/withdraw")
32
+ }), c = "/community";
33
+ function m(i) {
34
+ return i.surface === "public" && i.path.startsWith(`${c}/`) ? i.path.slice(c.length) : i.path;
35
+ }
36
+ const l = 4e3, u = 2, a = 1e3, p = 4e3, r = 4e3, b = 120, M = 2, _ = 80, d = 280, I = /^[a-z0-9][a-z0-9_]{2,29}$/, N = 30, y = 50, O = 50, T = 200, A = "community_notice", f = "good_faith", g = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
37
+ function v() {
38
+ const i = globalThis.crypto;
39
+ if (typeof i?.randomUUID == "function") return i.randomUUID();
40
+ const s = i.getRandomValues(new Uint8Array(16));
41
+ s[6] = (s[6] ?? 0) & 15 | 64, s[8] = (s[8] ?? 0) & 63 | 128;
42
+ const t = Array.from(s, (o) => o.toString(16).padStart(2, "0")).join("");
43
+ return `${t.slice(0, 8)}-${t.slice(8, 12)}-${t.slice(12, 16)}-${t.slice(16, 20)}-${t.slice(20)}`;
44
+ }
45
+ export {
46
+ p as COMMUNITY_APPEAL_MAX,
47
+ d as COMMUNITY_BIO_MAX,
48
+ g as COMMUNITY_CLIENT_MSG_ID_RE,
49
+ _ as COMMUNITY_DISPLAY_NAME_MAX,
50
+ M as COMMUNITY_DISPLAY_NAME_MIN,
51
+ f as COMMUNITY_GOOD_FAITH,
52
+ N as COMMUNITY_HANDLE_CHANGE_DAYS,
53
+ I as COMMUNITY_HANDLE_RE,
54
+ y as COMMUNITY_HEAD_ARTICLES_MAX,
55
+ u as COMMUNITY_MESSAGE_LINKS_MAX,
56
+ l as COMMUNITY_MESSAGE_MAX,
57
+ r as COMMUNITY_NOTICE_DESCRIPTION_MAX,
58
+ A as COMMUNITY_NOTICE_TURNSTILE_ACTION,
59
+ b as COMMUNITY_NOTIFIER_NAME_MAX,
60
+ n as COMMUNITY_OPS,
61
+ O as COMMUNITY_PAGE_SIZE,
62
+ T as COMMUNITY_REPLIES_MAX,
63
+ a as COMMUNITY_REPORT_NOTE_MAX,
64
+ m as communityOpPath,
65
+ v as newClientMsgId
66
+ };