@blogmcp/sdk 0.11.0 → 0.13.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 (35) hide show
  1. package/dist/community/client.d.ts +1 -1
  2. package/dist/community/client.js +2 -1
  3. package/dist/community/messages.cs.d.ts +5 -3
  4. package/dist/community/messages.cs.js +7 -3
  5. package/dist/community/messages.en.d.ts +5 -3
  6. package/dist/community/messages.en.js +7 -3
  7. package/dist/community/shapes.d.ts +15 -0
  8. package/dist/community/store.d.ts +12 -0
  9. package/dist/community/store.js +27 -27
  10. package/dist/core/client.d.ts +9 -0
  11. package/dist/core/client.js +54 -50
  12. package/dist/core/index.d.ts +2 -0
  13. package/dist/core/index.js +113 -103
  14. package/dist/core/queries.d.ts +1 -0
  15. package/dist/core/queries.js +76 -71
  16. package/dist/core/review/types.d.ts +7 -0
  17. package/dist/core/style-layers.d.ts +88 -0
  18. package/dist/core/style-layers.js +69 -0
  19. package/dist/nuxt/composables/useAsyncKb.d.ts +10 -4
  20. package/dist/packages/mdx-render-vue/dist/render/gallery/GalleryLightbox.vue.js +2 -2
  21. package/dist/packages/mdx-render-vue/dist/render/tripmap/TripMapDefault.vue.js +36 -36
  22. package/package.json +3 -3
  23. package/src/community/client.ts +3 -2
  24. package/src/community/messages.cs.ts +7 -3
  25. package/src/community/messages.en.ts +7 -3
  26. package/src/community/shapes.ts +15 -0
  27. package/src/community/store.ts +14 -2
  28. package/src/core/client.ts +12 -0
  29. package/src/core/index.ts +14 -0
  30. package/src/core/markdown.ts +1 -1
  31. package/src/core/queries.ts +8 -0
  32. package/src/core/review/types.ts +8 -0
  33. package/src/core/style-layers.ts +169 -0
  34. package/src/nuxt/composables/useAsyncKb.ts +11 -4
  35. package/src/nuxt/nuxt-imports.d.ts +2 -2
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Style layers: named CSS a tenant keeps in the knowledge base and its site applies ON TOP of the
3
+ * design that ships in the site's code — a token, a campaign accent, the print layout of one kind
4
+ * of article — without a deploy of the site.
5
+ *
6
+ * The knowledge base validates a layer when it is saved and hands a site CSS in which every
7
+ * selector already lives under a placeholder scope root (`LAYER_SCOPE_TOKEN`). A site decides what
8
+ * that root is on its pages and substitutes it — a plain string replace, so no site needs a CSS
9
+ * parser:
10
+ *
11
+ * const layers = await client.styleLayers.list() // published, in order
12
+ * for (const layer of matchLayers(layers, { articleSlug })) {
13
+ * const css = layerStyleText(layer, layerScope('.my-article-root', layer.match))
14
+ * if (css) render(<style data-kb-layer={layer.name}>{css}</style>) // after your own stylesheets
15
+ * }
16
+ *
17
+ * Three rules for a site:
18
+ * - render the layers AFTER its own stylesheets, in the order given (a later layer wins);
19
+ * - with no layer, render nothing; a failure to read the layers renders the page without them;
20
+ * - choose a scope root that leaves out what a layer must never restyle (a checkout, an account,
21
+ * a consent dialog). A layer cannot reach outside the root it is given.
22
+ *
23
+ * Pure and dependency-free: safe in a browser bundle, on a server and in a test.
24
+ */
25
+ /** The scope root in the CSS the knowledge base serves. A type selector no element has. */
26
+ export declare const LAYER_SCOPE_TOKEN = "__KB_LAYER_SCOPE__";
27
+ /** What a layer applies to. `value` is an article slug (the filename without `.mdx`) or its start. */
28
+ export type StyleLayerMatch = {
29
+ kind: 'site';
30
+ } | {
31
+ kind: 'article_prefix';
32
+ value: string;
33
+ } | {
34
+ kind: 'article';
35
+ value: string;
36
+ };
37
+ /** One version of a layer as a site receives it. */
38
+ export interface StyleLayer {
39
+ name: string;
40
+ match: StyleLayerMatch;
41
+ /** Layers apply in ascending position, ties by name. */
42
+ position: number;
43
+ version: number;
44
+ versionId: string;
45
+ /** Validated CSS with `LAYER_SCOPE_TOKEN` where the scope root goes. */
46
+ css: string;
47
+ }
48
+ /** The order layers apply in: ascending position, ties by name. Returns a new array. */
49
+ export declare function sortStyleLayers<T extends Pick<StyleLayer, 'position' | 'name'>>(layers: readonly T[]): T[];
50
+ /**
51
+ * The layers of an API answer — the `kbStyleLayers` field, a review session's `styleLayers`, or the
52
+ * REST list — as a sorted list. An entry that is not a layer is dropped, never thrown on: what a
53
+ * site does with a bad answer is render without it.
54
+ */
55
+ export declare function parseStyleLayers(payload: unknown): StyleLayer[];
56
+ /** Whether a layer applies to a page: a `site` layer always, an article layer by the page's article slug. */
57
+ export declare function layerMatches(match: StyleLayerMatch, page: {
58
+ articleSlug?: string | null;
59
+ }): boolean;
60
+ /** The layers that apply to a page, in order. */
61
+ export declare function matchLayers(layers: readonly StyleLayer[], page: {
62
+ articleSlug?: string | null;
63
+ }): StyleLayer[];
64
+ /**
65
+ * The layers of a review page: a version the review link pins stands in for the published version
66
+ * of the same layer, and a pinned layer that is not published is added. In order.
67
+ */
68
+ export declare function mergePinnedLayers(published: readonly StyleLayer[], pinned: readonly StyleLayer[]): StyleLayer[];
69
+ /**
70
+ * The scope root of a layer on a site that marks an article's root element with its slug
71
+ * (`<div class="article" data-article="my-slug">`): `base` for a `site` layer, `base[attr="slug"]`
72
+ * for an article, `base[attr^="prefix"]` for an article prefix. `base` is the selector of the
73
+ * element that carries the attribute.
74
+ */
75
+ export declare function layerScope(base: string, match: StyleLayerMatch, attribute?: string): string;
76
+ /**
77
+ * The layer's CSS with the site's scope root in place of the placeholder.
78
+ *
79
+ * @throws TypeError when `scope` is not one selector (a list would scope only its last part).
80
+ */
81
+ export declare function applyLayerScope(css: string, scope: string): string;
82
+ /**
83
+ * The text of a layer's `<style>` element, or null when the layer must not be rendered: an empty
84
+ * layer, a scope that is not one selector, or CSS holding `</` or `<!--`. The knowledge base
85
+ * refuses those sequences when a layer is saved; this is the same check at the last step before
86
+ * the text goes into a page, where a `</style` would end the element.
87
+ */
88
+ export declare function layerStyleText(layer: Pick<StyleLayer, 'css'>, scope: string): string | null;
@@ -0,0 +1,69 @@
1
+ const o = "__KB_LAYER_SCOPE__", a = /^[a-z][a-z0-9-]{0,62}$/, c = /^[a-z0-9][a-z0-9-]{0,199}$/, u = /[,{}<;]|\/\*|^\s*$/;
2
+ function l(t) {
3
+ if (!t || typeof t != "object") return null;
4
+ const { kind: e, value: r } = t;
5
+ return e === "site" ? { kind: "site" } : (e === "article" || e === "article_prefix") && typeof r == "string" && c.test(r) ? { kind: e, value: r } : null;
6
+ }
7
+ function f(t) {
8
+ if (!t || typeof t != "object") return null;
9
+ const e = t, r = l(e.match);
10
+ return typeof e.name != "string" || !a.test(e.name) || !r || typeof e.css != "string" || typeof e.version != "number" || typeof e.versionId != "string" ? null : {
11
+ name: e.name,
12
+ match: r,
13
+ position: typeof e.position == "number" && Number.isFinite(e.position) ? e.position : 0,
14
+ version: e.version,
15
+ versionId: e.versionId,
16
+ css: e.css
17
+ };
18
+ }
19
+ function i(t) {
20
+ return [...t].sort((e, r) => e.position - r.position || (e.name < r.name ? -1 : e.name > r.name ? 1 : 0));
21
+ }
22
+ function m(t) {
23
+ const e = Array.isArray(t) ? t : t && typeof t == "object" && Array.isArray(t.layers) ? t.layers : [], r = [];
24
+ for (const n of e) {
25
+ const s = f(n);
26
+ s && r.push(s);
27
+ }
28
+ return i(r);
29
+ }
30
+ function y(t, e) {
31
+ if (t.kind === "site") return !0;
32
+ const r = e.articleSlug;
33
+ return r ? t.kind === "article" ? r === t.value : r.startsWith(t.value) : !1;
34
+ }
35
+ function _(t, e) {
36
+ return i(t.filter((r) => y(r.match, e)));
37
+ }
38
+ function E(t, e) {
39
+ const r = new Set(e.map((n) => n.name));
40
+ return i([...t.filter((n) => !r.has(n.name)), ...e]);
41
+ }
42
+ function S(t, e, r = "data-article") {
43
+ return e.kind === "site" ? t : `${t}[${r}${e.kind === "article" ? "=" : "^="}"${e.value}"]`;
44
+ }
45
+ function p(t, e) {
46
+ if (typeof e != "string" || u.test(e))
47
+ throw new TypeError('applyLayerScope: the scope must be one selector, e.g. ".article" or ".article[data-article=\\"x\\"]"');
48
+ return t.split(o).join(e.trim());
49
+ }
50
+ function g(t, e) {
51
+ const r = t.css;
52
+ if (typeof r != "string" || r.trim() === "" || r.includes("</") || r.includes("<!--")) return null;
53
+ try {
54
+ return p(r, e);
55
+ } catch {
56
+ return null;
57
+ }
58
+ }
59
+ export {
60
+ o as LAYER_SCOPE_TOKEN,
61
+ p as applyLayerScope,
62
+ y as layerMatches,
63
+ S as layerScope,
64
+ g as layerStyleText,
65
+ _ as matchLayers,
66
+ E as mergePinnedLayers,
67
+ m as parseStyleLayers,
68
+ i as sortStyleLayers
69
+ };
@@ -7,20 +7,26 @@
7
7
  * Usage in Nuxt pages:
8
8
  * const { articles, totalCount } = await useAsyncArticleList('home', { status: 'published' })
9
9
  */
10
- import type { Ref } from 'vue';
10
+ import type { Ref, WatchSource } from 'vue';
11
11
  import type { ArticleListParams } from '../../vue/composables/useArticles.js';
12
+ /**
13
+ * What `useAsyncData`'s `watch` takes (Vue's `MultiWatchSources`, spelled out because Vue exports that
14
+ * name only from 3.5): refs, getters and reactive objects. The adapters used to type it `unknown[]`,
15
+ * which Nuxt's own `useAsyncData` types refuse (a Nuxt app's typecheck failed in all three).
16
+ */
17
+ export type AsyncWatchDeps = (WatchSource<unknown> | object)[];
12
18
  /**
13
19
  * SSR-hydrated article list.
14
20
  *
15
21
  * Wraps useArticleList with Nuxt's useAsyncData.
16
22
  */
17
- export declare function useAsyncArticleList(key: string, params?: ArticleListParams, watchDeps?: unknown[]): Promise<import("../../vue/index.js").UseArticleListReturn>;
23
+ export declare function useAsyncArticleList(key: string, params?: ArticleListParams, watchDeps?: AsyncWatchDeps): Promise<import("../../vue/index.js").UseArticleListReturn>;
18
24
  /**
19
25
  * SSR-hydrated single article.
20
26
  *
21
27
  * Wraps useArticle with Nuxt's useAsyncData.
22
28
  */
23
- export declare function useAsyncArticle(key: string, filename: Ref<string> | string, languageCode: Ref<string> | string, watchDeps?: unknown[]): Promise<import("../../vue/index.js").UseArticleReturn>;
29
+ export declare function useAsyncArticle(key: string, filename: Ref<string> | string, languageCode: Ref<string> | string, watchDeps?: AsyncWatchDeps): Promise<import("../../vue/index.js").UseArticleReturn>;
24
30
  /**
25
31
  * SSR-hydrated navigation menu.
26
32
  *
@@ -29,4 +35,4 @@ export declare function useAsyncArticle(key: string, filename: Ref<string> | str
29
35
  export declare function useAsyncNavigation(key: string, params?: {
30
36
  scope?: string;
31
37
  locale?: string;
32
- }, watchDeps?: unknown[]): Promise<import("../../vue/index.js").UseNavigationReturn>;
38
+ }, watchDeps?: AsyncWatchDeps): Promise<import("../../vue/index.js").UseNavigationReturn>;
@@ -1,6 +1,6 @@
1
1
  import o from "./GalleryLightbox.vue2.js";
2
2
  import t from "../../_virtual/_plugin-vue_export-helper.js";
3
- const f = /* @__PURE__ */ t(o, [["__scopeId", "data-v-f28ad12c"]]);
3
+ const _ = /* @__PURE__ */ t(o, [["__scopeId", "data-v-458c8685"]]);
4
4
  export {
5
- f as default
5
+ _ as default
6
6
  };
@@ -1,4 +1,4 @@
1
- import { defineComponent as H, ref as f, onMounted as L, onBeforeUnmount as P, createElementBlock as n, openBlock as s, normalizeClass as i, unref as e, createCommentVNode as d, createElementVNode as p, toDisplayString as v, Fragment as B, renderList as F, normalizeStyle as j } from "vue";
1
+ import { defineComponent as H, ref as f, onMounted as L, onBeforeUnmount as P, createElementBlock as s, openBlock as u, normalizeClass as i, unref as e, createCommentVNode as d, createElementVNode as p, toDisplayString as v, Fragment as B, renderList as F, normalizeStyle as j } from "vue";
2
2
  import { tripMapStyles as r } from "@blogmcp/mdx-schema/styles";
3
3
  import { useTripMap as D } from "../../composables/useTripMap.js";
4
4
  import { tripMapFormatTime as G } from "@blogmcp/mdx-schema/tripmap";
@@ -21,7 +21,7 @@ const W = ["aria-label"], $ = ["src", "alt"], R = /* @__PURE__ */ H({
21
21
  title: {}
22
22
  },
23
23
  setup(y) {
24
- const l = y, { handNodes: S, facadeThumbs: w, facadeStops: U, heightStyle: _, geoUrl: z, isConfigOnly: I, labels: A, texts: g } = D(l), N = f(null), h = f(null), x = f(null), u = f("facade"), C = f(0);
24
+ const l = y, { handNodes: S, facadeThumbs: w, facadeStops: U, heightStyle: _, geoUrl: z, isConfigOnly: I, labels: A, texts: g } = D(l), N = f(null), h = f(null), x = f(null), c = f("facade"), C = f(0);
25
25
  let T = null, m = null, k = !1;
26
26
  async function O() {
27
27
  try {
@@ -35,26 +35,26 @@ const W = ["aria-label"], $ = ["src", "alt"], R = /* @__PURE__ */ H({
35
35
  }
36
36
  async function E() {
37
37
  if (!k) {
38
- k = !0, u.value = "loading";
38
+ k = !0, c.value = "loading";
39
39
  try {
40
- const [t, c] = await Promise.all([import("../../../../tripmap-core/dist/index.js"), O()]), a = (c.nodes ?? []).filter((o) => typeof o.latitude == "number" && typeof o.longitude == "number").map((o) => ({
41
- id: o.slug,
42
- lat: o.latitude,
43
- lng: o.longitude,
44
- capturedAt: o.capturedAt ?? void 0,
45
- thumbnailUrl: o.thumbnailUrl ?? void 0,
46
- imageUrl: o.url ?? void 0,
47
- largeImageUrl: o.largeUrl ?? void 0,
48
- altText: o.altText ?? void 0,
49
- title: o.placeName ?? void 0
40
+ const [t, o] = await Promise.all([import("../../../../tripmap-core/dist/index.js"), O()]), a = (o.nodes ?? []).filter((n) => typeof n.latitude == "number" && typeof n.longitude == "number").map((n) => ({
41
+ id: n.slug,
42
+ lat: n.latitude,
43
+ lng: n.longitude,
44
+ capturedAt: n.capturedAt ?? void 0,
45
+ thumbnailUrl: n.thumbnailUrl ?? void 0,
46
+ imageUrl: n.url ?? void 0,
47
+ largeImageUrl: n.largeUrl ?? void 0,
48
+ altText: n.altText ?? void 0,
49
+ title: n.placeName ?? void 0
50
50
  })), M = t.buildTripNodes(a, S.value);
51
- if (C.value = c.skipped ?? 0, M.length === 0 || !h.value) {
52
- u.value = "empty";
51
+ if (C.value = o.skipped ?? 0, M.length === 0 || !h.value) {
52
+ c.value = "empty";
53
53
  return;
54
54
  }
55
55
  const b = new t.TripMap(h.value, {
56
- styleUrl: l.styleUrl || c.config?.styleUrl || "",
57
- darkStyleUrl: c.config?.darkStyleUrl,
56
+ styleUrl: l.styleUrl || o.config?.styleUrl || "",
57
+ darkStyleUrl: o.config?.darkStyleUrl,
58
58
  theme: l.theme,
59
59
  cluster: l.cluster,
60
60
  showLine: l.line,
@@ -63,22 +63,22 @@ const W = ["aria-label"], $ = ["src", "alt"], R = /* @__PURE__ */ H({
63
63
  title: l.title,
64
64
  detail: l.detail,
65
65
  detailHost: l.detail === "panel" ? x.value ?? void 0 : void 0,
66
- extraAttribution: c.config?.attribution,
66
+ extraAttribution: o.config?.attribution,
67
67
  labels: A.value,
68
68
  initialView: V(),
69
69
  events: {}
70
70
  });
71
- b.setNodes(M), await b.init(), T = () => b.destroy(), u.value = "live";
71
+ b.setNodes(M), await b.init(), T = () => b.destroy(), c.value = "live";
72
72
  } catch {
73
- u.value = k && u.value === "loading" ? "facade" : u.value;
73
+ c.value = k && c.value === "loading" ? "facade" : c.value;
74
74
  }
75
75
  }
76
76
  }
77
77
  function V() {
78
78
  if (!l.center) return;
79
- const [t, c] = l.center.split(",").map((a) => Number.parseFloat(a.trim()));
80
- if (!(!Number.isFinite(t) || !Number.isFinite(c)))
81
- return { center: [c, t], zoom: l.zoom };
79
+ const [t, o] = l.center.split(",").map((a) => Number.parseFloat(a.trim()));
80
+ if (!(t === void 0 || o === void 0 || !Number.isFinite(t) || !Number.isFinite(o)))
81
+ return { center: [o, t], zoom: l.zoom };
82
82
  }
83
83
  return L(() => {
84
84
  const t = N.value;
@@ -88,30 +88,30 @@ const W = ["aria-label"], $ = ["src", "alt"], R = /* @__PURE__ */ H({
88
88
  return;
89
89
  }
90
90
  m = new IntersectionObserver(
91
- (c) => {
92
- c.some((a) => a.isIntersecting) && (m?.disconnect(), m = null, E());
91
+ (o) => {
92
+ o.some((a) => a.isIntersecting) && (m?.disconnect(), m = null, E());
93
93
  },
94
94
  { rootMargin: "300px" }
95
95
  ), m.observe(t);
96
96
  }
97
97
  }), P(() => {
98
98
  m?.disconnect(), T?.();
99
- }), (t, c) => (s(), n("div", {
99
+ }), (t, o) => (u(), s("div", {
100
100
  ref_key: "rootEl",
101
101
  ref: N,
102
102
  class: i(e(r).container),
103
103
  "data-mdx-component": "TripMap",
104
104
  "aria-label": y.title
105
105
  }, [
106
- y.title ? (s(), n("p", {
106
+ y.title ? (u(), s("p", {
107
107
  key: 0,
108
108
  class: i(e(r).head)
109
109
  }, v(y.title), 3)) : d("", !0),
110
- e(w).length && u.value !== "live" ? (s(), n("ol", {
110
+ e(w).length && c.value !== "live" ? (u(), s("ol", {
111
111
  key: 1,
112
112
  class: i(e(r).strip)
113
113
  }, [
114
- (s(!0), n(B, null, F(e(w), (a) => (s(), n("li", {
114
+ (u(!0), s(B, null, F(e(w), (a) => (u(), s("li", {
115
115
  key: a.slug,
116
116
  class: i(e(r).stripItem)
117
117
  }, [
@@ -135,7 +135,7 @@ const W = ["aria-label"], $ = ["src", "alt"], R = /* @__PURE__ */ H({
135
135
  ref: h,
136
136
  class: "absolute inset-0"
137
137
  }, null, 512),
138
- u.value !== "live" ? (s(), n("div", {
138
+ c.value !== "live" ? (u(), s("div", {
139
139
  key: 0,
140
140
  class: i([e(r).mapOverlay])
141
141
  }, [
@@ -144,31 +144,31 @@ const W = ["aria-label"], $ = ["src", "alt"], R = /* @__PURE__ */ H({
144
144
  }, [
145
145
  p("span", {
146
146
  class: i(e(r).mapHint)
147
- }, v(u.value === "empty" ? e(g).empty : e(g).hint), 3)
147
+ }, v(c.value === "empty" ? e(g).empty : e(g).hint), 3)
148
148
  ], 2)
149
149
  ], 2)) : d("", !0)
150
150
  ], 6),
151
- l.detail === "panel" ? (s(), n("div", {
151
+ l.detail === "panel" ? (u(), s("div", {
152
152
  key: 2,
153
153
  ref_key: "detailEl",
154
154
  ref: x,
155
155
  class: i(e(r).detailHost)
156
156
  }, null, 2)) : d("", !0),
157
- e(U).length && u.value !== "live" ? (s(), n("ol", {
157
+ e(U).length && c.value !== "live" ? (u(), s("ol", {
158
158
  key: 3,
159
159
  class: i(e(r).stopList)
160
160
  }, [
161
- (s(!0), n(B, null, F(e(U), (a) => (s(), n("li", {
161
+ (u(!0), s(B, null, F(e(U), (a) => (u(), s("li", {
162
162
  key: a.key
163
163
  }, [
164
- a.capturedAt ? (s(), n("span", {
164
+ a.capturedAt ? (u(), s("span", {
165
165
  key: 0,
166
166
  class: i(e(r).stopTime)
167
167
  }, v(e(G)(a.capturedAt)), 3)) : d("", !0),
168
168
  p("span", null, v(a.title), 1)
169
169
  ]))), 128))
170
170
  ], 2)) : d("", !0),
171
- u.value !== "live" ? (s(), n("p", {
171
+ c.value !== "live" ? (u(), s("p", {
172
172
  key: 4,
173
173
  class: i(e(r).note)
174
174
  }, v(e(g).unavailable), 3)) : d("", !0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blogmcp/sdk",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Headless SDK for Knowledge Base blog — core client, Vue composables, Nuxt adapter",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -98,8 +98,8 @@
98
98
  }
99
99
  },
100
100
  "dependencies": {
101
- "@blogmcp/mdx-schema": "^0.11.0",
102
- "@blogmcp/sanitize": "^0.11.0",
101
+ "@blogmcp/mdx-schema": "^0.13.0",
102
+ "@blogmcp/sanitize": "^0.13.0",
103
103
  "marked": "^15.0.7"
104
104
  },
105
105
  "optionalDependencies": {
@@ -168,7 +168,7 @@ export interface CommunityClient {
168
168
  me: {
169
169
  /** Anonymous: `{ member: null, needs: ['sign_in'] }`. */
170
170
  get: CallNoInput<MyState>
171
- /** The light onboarding: the age band, the rules (and the consent when asked), the profile. */
171
+ /** The light onboarding: the age band, the rules (and the terms on a first join, and the consent when asked), the profile. */
172
172
  onboard: Call<OnboardInput, MyState>
173
173
  updateProfile: Call<ProfileUpdateInput, { profile: OwnProfile }>
174
174
  notifications: {
@@ -639,7 +639,8 @@ export function createCommunityClient(config: CommunityClientConfig): CommunityC
639
639
  },
640
640
  me: {
641
641
  get: empty('me.get'),
642
- onboard: fields('me.onboard', ['ageBand', 'rulesTextId', 'art9TextId', 'art9Refused', 'displayName', 'handle', 'avatarPreset']),
642
+ // O-16 / F-51: `termsTextId` goes only when the caller sets it (pick drops an absent key, so an older kb-api never sees it).
643
+ onboard: fields('me.onboard', ['ageBand', 'rulesTextId', 'termsTextId', 'art9TextId', 'art9Refused', 'displayName', 'handle', 'avatarPreset']),
643
644
  updateProfile: fields('me.updateProfile', ['displayName', 'handle', 'avatarPreset', 'bio']),
644
645
  notifications: {
645
646
  list: fields('me.notifications.list', ['cursor', 'unreadOnly', 'codes']),
@@ -48,7 +48,8 @@ export const COMMUNITY_MESSAGES_CS = {
48
48
 
49
49
  // ── what the composer waits for (need.<Need>) ──
50
50
  'need.sign_in': 'Do diskuse můžete psát po přihlášení.',
51
- 'need.onboarding': 'Před prvním komentářem si nastavte jméno a potvrďte pravidla diskuse.',
51
+ // O-16 / F-51: the first join confirms the rules and the terms in one go (the terms once, never again).
52
+ 'need.onboarding': 'Před prvním komentářem si nastavte jméno a potvrďte pravidla diskuse a podmínky.',
52
53
  'need.reconsent_rules': 'Pravidla diskuse se změnila. Potvrďte prosím novou verzi.',
53
54
  'need.art9_consent': 'Pro psaní do diskuse potřebujeme váš souhlas se zpracováním.',
54
55
 
@@ -196,6 +197,9 @@ export const COMMUNITY_MESSAGES_CS = {
196
197
  'onboarding.rulesLede': 'Přečtěte si prosím, jak to v diskusi chodí.',
197
198
  'onboarding.rulesLink': 'Celá pravidla',
198
199
  'onboarding.rulesAccept': 'Souhlasím s pravidly diskuse.',
200
+ // O-16 / F-51: the one consent of a first join where the tenant has terms (the rules and the terms, each linked).
201
+ 'onboarding.rulesTermsAccept': 'Souhlasím s pravidly diskuse a s podmínkami.',
202
+ 'onboarding.termsLink': 'Podmínky diskuse',
199
203
  'onboarding.rulesChanged': 'Pravidla diskuse se od vaší poslední návštěvy změnila. Přečtěte si prosím novou verzi a potvrďte ji.',
200
204
  'onboarding.art9Title': 'Souhlas se zpracováním',
201
205
  'onboarding.art9Lede': 'Pro psaní do diskuse potřebujeme váš souhlas podle textu níže.',
@@ -257,7 +261,7 @@ export const COMMUNITY_MESSAGES_CS = {
257
261
  'panel.art9Refused': 'Souhlas se zpracováním jste odmítli.',
258
262
  'panel.art9Withdraw': 'Odvolat souhlas',
259
263
  'panel.art9WithdrawTitle': 'Odvolat souhlas se zpracováním?',
260
- 'panel.art9WithdrawExplain': 'Diskusi můžete dál číst. Jestli do ní půjde psát i bez souhlasu, nebo až ho zase udělíte, záleží na nastavení webu — řekne vám to před dalším komentářem.',
264
+ 'panel.art9WithdrawExplain': 'Diskusi můžete dál číst. Příspěvky ve fóru, které jste napsali se souhlasem, smažeme za 7 dní — když souhlas do té doby znovu udělíte, zůstanou. Jestli půjde psát i bez souhlasu, záleží na nastavení webu; řekne vám to před dalším komentářem.',
261
265
  'panel.art9WithdrawConfirm': 'Ano, odvolat souhlas',
262
266
  'panel.art9WithdrawCancel': 'Ponechat souhlas',
263
267
  'panel.art9Withdrawn': 'Souhlas jste odvolali.',
@@ -513,7 +517,7 @@ export const COMMUNITY_MESSAGES_CS = {
513
517
  'forumText.confirm.other': 'Rozumím upozornění a chci příspěvek odeslat.',
514
518
  'forumText.warning.identifier': 'V příspěvku je nejspíš e-mail, telefon nebo číslo účtu. Pokud tam být nemá, příspěvek upravte.',
515
519
  'forumText.warning.other': 'Příspěvek je zveřejněný, ale pravidla diskuse u něj na něco upozorňují. Projděte si ho prosím.',
516
- 'forumText.need.onboarding': 'Před prvním příspěvkem si nastavte jméno a potvrďte pravidla diskuse.',
520
+ 'forumText.need.onboarding': 'Před prvním příspěvkem si nastavte jméno a potvrďte pravidla diskuse a podmínky.',
517
521
  'forumText.need.art9_consent': 'Pro psaní ve fóru potřebujeme váš souhlas se zpracováním.',
518
522
  'search.title': 'Hledání ve fóru',
519
523
  'search.label': 'Co hledáte?',
@@ -44,7 +44,8 @@ export const COMMUNITY_MESSAGES_EN = {
44
44
  'error.submit': "That didn't work. Please reload the page and try again.",
45
45
 
46
46
  'need.sign_in': 'Sign in to write in the discussion.',
47
- 'need.onboarding': 'Before your first comment, choose a name and confirm the discussion rules.',
47
+ // O-16 / F-51: the first join confirms the rules and the terms in one go (the terms once, never again).
48
+ 'need.onboarding': 'Before your first comment, choose a name and confirm the discussion rules and terms.',
48
49
  'need.reconsent_rules': 'The discussion rules have changed. Please confirm the new version.',
49
50
  'need.art9_consent': 'To write in the discussion, we need your consent to the processing.',
50
51
 
@@ -173,6 +174,9 @@ export const COMMUNITY_MESSAGES_EN = {
173
174
  'onboarding.rulesLede': 'Please read how the discussion works.',
174
175
  'onboarding.rulesLink': 'The full rules',
175
176
  'onboarding.rulesAccept': 'I agree to the discussion rules.',
177
+ // O-16 / F-51: the one consent of a first join where the tenant has terms (the rules and the terms, each linked).
178
+ 'onboarding.rulesTermsAccept': 'I agree to the discussion rules and the terms.',
179
+ 'onboarding.termsLink': 'The discussion terms',
176
180
  'onboarding.rulesChanged': 'The discussion rules have changed since your last visit. Please read the new version and confirm it.',
177
181
  'onboarding.art9Title': 'Consent to processing',
178
182
  'onboarding.art9Lede': 'To write in the discussion, we need your consent as described below.',
@@ -230,7 +234,7 @@ export const COMMUNITY_MESSAGES_EN = {
230
234
  'panel.art9Refused': 'You declined the consent to the processing.',
231
235
  'panel.art9Withdraw': 'Withdraw consent',
232
236
  'panel.art9WithdrawTitle': 'Withdraw your consent to the processing?',
233
- 'panel.art9WithdrawExplain': "You can keep reading the discussion. Whether you can write without the consent, or only once you give it again, depends on the website's settings — it tells you before your next comment.",
237
+ 'panel.art9WithdrawExplain': "You can keep reading the discussion. The forum posts you wrote under the consent are erased after 7 days — give the consent again before then and they stay. Whether you can write without the consent depends on the website's settings; it tells you before your next comment.",
234
238
  'panel.art9WithdrawConfirm': 'Yes, withdraw consent',
235
239
  'panel.art9WithdrawCancel': 'Keep the consent',
236
240
  'panel.art9Withdrawn': "You've withdrawn your consent.",
@@ -460,7 +464,7 @@ export const COMMUNITY_MESSAGES_EN = {
460
464
  'forumText.confirm.other': 'I understand the notice and want to send the post.',
461
465
  'forumText.warning.identifier': "The post seems to contain an e-mail address, a phone number or an account number. If it shouldn't be there, edit the post.",
462
466
  'forumText.warning.other': 'The post is published, but the discussion rules flag something in it. Please look it over.',
463
- 'forumText.need.onboarding': 'Before your first post, choose a name and confirm the discussion rules.',
467
+ 'forumText.need.onboarding': 'Before your first post, choose a name and confirm the discussion rules and terms.',
464
468
  'forumText.need.art9_consent': 'To write in the forum, we need your consent to the processing.',
465
469
  'search.title': 'Search the forum',
466
470
  'search.label': 'What are you looking for?',
@@ -432,6 +432,14 @@ export interface MyState {
432
432
  readonly profile: OwnProfile | null
433
433
  readonly acceptances: {
434
434
  readonly rules: AcceptanceState
435
+ /**
436
+ * O-16 / F-51 (the owner, 9. 11. 2026: the terms are accepted once, at onboarding, and never asked again): null when
437
+ * the tenant publishes no terms text, `accepted` once the member accepted any terms text (for good — never
438
+ * `reconsent_required`), `never` otherwise. No `need` ever asks for the terms; a first onboarding sends
439
+ * `termsTextId` (viewerNeeds(me).terms). Absent from a kb-api older than O-16 — that kb-api does not take
440
+ * `termsTextId` either (its strict schema refuses the key), so nothing is sent then.
441
+ */
442
+ readonly terms?: AcceptanceState | null
435
443
  readonly art9Consent: AcceptanceState | null
436
444
  /**
437
445
  * M2 T9 (§3.8): the member refused the art. 9 consent under `art9Refusal = public_write` and has not given it
@@ -909,6 +917,13 @@ export interface OnboardInput {
909
917
  ageBand: AgeBand
910
918
  /** The current `rules` text's id (`legal/current`). */
911
919
  rulesTextId: string
920
+ /**
921
+ * O-16 / F-51: the current `terms` text's id (`legal/current { kind: 'terms' }`) — required on a member's first
922
+ * onboarding while the tenant has a terms text (MyState.acceptances.terms `never`): the key absent, null or another
923
+ * id is VALIDATION on `termsTextId` then. Recorded once and never asked again. Send it only to a kb-api whose me/get
924
+ * answers `acceptances.terms` (viewerNeeds(me).terms): an older one refuses the key.
925
+ */
926
+ termsTextId?: string | null
912
927
  /** The current `art9_consent` text's id, when the tenant asks for the consent. */
913
928
  art9TextId?: string | null
914
929
  /**
@@ -780,18 +780,30 @@ export interface ViewerNeeds {
780
780
  readonly rules: boolean
781
781
  /** The consent the tenant asks for before writing. */
782
782
  readonly art9: boolean
783
+ /**
784
+ * O-16 / F-51 (the owner, 9. 11. 2026: the terms once, never again): the first join also accepts the tenant's terms,
785
+ * so its me/onboard sends `termsTextId` — read from a MyState: a first join (`onboarding`) whose `acceptances.terms`
786
+ * is `never` (the tenant has a terms text, none accepted). Presence of the field is the rollout guard: a kb-api
787
+ * older than O-16 answers no `terms` and refuses the key, so nothing is sent to it. Never true for a member already
788
+ * onboarded (they are never asked) nor from a discussion state (no acceptances there), and not a need of its own:
789
+ * `any` does not count it — it rides on the onboarding.
790
+ */
791
+ readonly terms: boolean
783
792
  /** Any of these. */
784
793
  readonly any: boolean
785
794
  }
786
795
 
787
- export function viewerNeeds(state: Pick<DiscussionState, 'viewer'> | { needs: readonly unknown[] }): ViewerNeeds {
796
+ export function viewerNeeds(
797
+ state: Pick<DiscussionState, 'viewer'> | { needs: readonly unknown[]; acceptances?: { readonly terms?: unknown } | null },
798
+ ): ViewerNeeds {
788
799
  const raw = 'viewer' in state ? state.viewer.needs : state.needs
789
800
  const needs = new Set(raw.filter(isKnownNeed))
790
801
  const signIn = needs.has('sign_in')
791
802
  const onboarding = needs.has('onboarding')
792
803
  const rules = onboarding || needs.has('reconsent_rules')
793
804
  const art9 = needs.has('art9_consent')
794
- return Object.freeze({ signIn, onboarding, rules, art9, any: signIn || onboarding || rules || art9 })
805
+ const terms = onboarding && !('viewer' in state) && state.acceptances?.terms === 'never'
806
+ return Object.freeze({ signIn, onboarding, rules, art9, terms, any: signIn || onboarding || rules || art9 })
795
807
  }
796
808
 
797
809
  /** A loaded message (top-level or reply) by its seq, or null. */
@@ -28,6 +28,7 @@ import type {
28
28
  UpdateReportSettingsInput,
29
29
  } from './types'
30
30
  import type { NavNode } from './navigation'
31
+ import { parseStyleLayers, type StyleLayer } from './style-layers'
31
32
  import * as Q from './queries'
32
33
  import { createMemoryTokenStorage } from './auth'
33
34
  import { KbGraphQLError } from './errors'
@@ -208,6 +209,14 @@ export interface KbClient {
208
209
  navigation: {
209
210
  get(params?: { scope?: string; locale?: string }): Promise<{ kbNavigation: NavNode[] }>
210
211
  }
212
+ /**
213
+ * Style layers: the PUBLISHED layers of the site, in the order they apply (see `./style-layers`).
214
+ * Unlike the other groups this returns the parsed list, not the GraphQL field: an entry that is
215
+ * not a layer is dropped, so a caller can render what comes back.
216
+ */
217
+ styleLayers: {
218
+ list(): Promise<StyleLayer[]>
219
+ }
211
220
  /**
212
221
  * Editorial access to translation ROWS — INTERNAL tokens only (a server client holding a
213
222
  * kb_* internal key). The server refuses every other caller: a translation row carries the
@@ -369,6 +378,9 @@ export function createKbClient(config: KbClientConfig): KbClient {
369
378
  navigation: {
370
379
  get: (params) => exec(Q.KB_NAVIGATION, params ?? {}),
371
380
  },
381
+ styleLayers: {
382
+ list: async () => parseStyleLayers((await exec<{ kbStyleLayers?: unknown } | undefined>(Q.KB_STYLE_LAYERS))?.kbStyleLayers),
383
+ },
372
384
  translations: {
373
385
  list: (articleId) => exec(Q.ARTICLE_TRANSLATIONS, { articleId }),
374
386
  get: (sourceFilename, languageCode) =>
package/src/core/index.ts CHANGED
@@ -113,6 +113,20 @@ export {
113
113
  flattenNav,
114
114
  } from './navigation'
115
115
 
116
+ // Style layers (CSS the site applies on top of its own design)
117
+ export type { StyleLayer, StyleLayerMatch } from './style-layers'
118
+ export {
119
+ LAYER_SCOPE_TOKEN,
120
+ parseStyleLayers,
121
+ sortStyleLayers,
122
+ layerMatches,
123
+ matchLayers,
124
+ mergePinnedLayers,
125
+ layerScope,
126
+ applyLayerScope,
127
+ layerStyleText,
128
+ } from './style-layers'
129
+
116
130
  // Auth
117
131
  export type { AuthManager } from './auth'
118
132
  export {
@@ -52,7 +52,7 @@ function safeUrl(url: string | undefined | null): string {
52
52
  // Scheme check — allow only the explicit safe list
53
53
  const schemeMatch = normalized.match(/^([a-z][a-z0-9+.-]*):/i)
54
54
  if (!schemeMatch) return url // schemeless = safe (relative-by-default)
55
- const scheme = schemeMatch[1].toLowerCase()
55
+ const scheme = schemeMatch[1]!.toLowerCase() // group 1 is not optional: it is there whenever the match is
56
56
  const ALLOWED_SCHEMES = ['http', 'https', 'mailto', 'tel', 'ftp', 'sms']
57
57
  return ALLOWED_SCHEMES.includes(scheme) ? url : 'about:blank'
58
58
  }
@@ -246,6 +246,14 @@ export const KB_NAVIGATION = `
246
246
  }
247
247
  `
248
248
 
249
+ // ==================== Style layers ====================
250
+
251
+ export const KB_STYLE_LAYERS = `
252
+ query KbStyleLayers {
253
+ kbStyleLayers
254
+ }
255
+ `
256
+
249
257
  // ==================== Tags ====================
250
258
 
251
259
  export const ACCESSIBLE_TAGS = `