@blogmcp/sdk 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core/auth.js CHANGED
@@ -1,27 +1,27 @@
1
1
  import { ACCESS_LEVEL_ORDER as o } from "./types.js";
2
- function c(e) {
2
+ function l(e) {
3
3
  try {
4
4
  const t = e.split(".");
5
5
  if (t.length !== 3) return null;
6
- const n = JSON.parse(atob(t[1]));
6
+ const r = t[1].replace(/-/g, "+").replace(/_/g, "/"), n = atob(r.padEnd(Math.ceil(r.length / 4) * 4, "=")), c = JSON.parse(new TextDecoder().decode(Uint8Array.from(n, (a) => a.charCodeAt(0))));
7
7
  return {
8
- id: n.sub || n.userId || "",
9
- email: n.email || "",
10
- name: n.name,
11
- accessLevel: n.accessLevel || "public"
8
+ id: c.sub || c.userId || "",
9
+ email: c.email || "",
10
+ name: c.name,
11
+ accessLevel: c.accessLevel || "public"
12
12
  };
13
13
  } catch {
14
14
  return null;
15
15
  }
16
16
  }
17
17
  function u(e, t) {
18
- const n = o.indexOf(e), r = o.indexOf(t);
19
- return n >= r;
18
+ const r = o.indexOf(e), n = o.indexOf(t);
19
+ return r >= n;
20
20
  }
21
- function s(e) {
21
+ function i(e) {
22
22
  let t = null;
23
- const n = e.getToken();
24
- return n && (t = c(n)), {
23
+ const r = e.getToken();
24
+ return r && (t = l(r)), {
25
25
  getToken() {
26
26
  return e.getToken();
27
27
  },
@@ -34,18 +34,18 @@ function s(e) {
34
34
  accessLevel() {
35
35
  return t?.accessLevel || "public";
36
36
  },
37
- hasAccess(r) {
38
- return u(this.accessLevel(), r);
37
+ hasAccess(n) {
38
+ return u(this.accessLevel(), n);
39
39
  },
40
- login(r, l) {
41
- e.setToken(r), t = l || c(r);
40
+ login(n, c) {
41
+ e.setToken(n), t = c || l(n);
42
42
  },
43
43
  logout() {
44
44
  e.removeToken(), t = null;
45
45
  }
46
46
  };
47
47
  }
48
- function i() {
48
+ function g() {
49
49
  let e = null;
50
50
  return {
51
51
  getToken: () => e,
@@ -57,7 +57,7 @@ function i() {
57
57
  }
58
58
  };
59
59
  }
60
- function g(e = "kb_blog_token") {
60
+ function d(e = "kb_blog_token") {
61
61
  return {
62
62
  getToken: () => {
63
63
  try {
@@ -81,9 +81,9 @@ function g(e = "kb_blog_token") {
81
81
  };
82
82
  }
83
83
  export {
84
- s as createAuthManager,
85
- g as createLocalStorageTokenStorage,
86
- i as createMemoryTokenStorage,
87
- c as decodeJwtUser,
84
+ i as createAuthManager,
85
+ d as createLocalStorageTokenStorage,
86
+ g as createMemoryTokenStorage,
87
+ l as decodeJwtUser,
88
88
  u as hasAccessLevel
89
89
  };
@@ -1,87 +1,110 @@
1
1
  import { ACCESS_LEVEL_ORDER as t } from "./types.js";
2
- import { CONSULTATION_ERROR_CODES as n, KbGraphQLError as i, isConsultationErrorCode as s, isKbGraphQLError as l } from "./errors.js";
3
- import { createKbClient as m } from "./client.js";
4
- import { findNavNode as d, flattenNav as c, isNavigable as x, navBreadcrumbs as g, navNextPrev as E, navSiblings as T, navSubtree as u, navWalk as A } from "./navigation.js";
5
- import { createAuthManager as C, createLocalStorageTokenStorage as R, createMemoryTokenStorage as v, decodeJwtUser as S, hasAccessLevel as L } from "./auth.js";
6
- import { DelegatedTokenError as h, createDelegatedTokenMinter as N } from "./delegated-identity.js";
7
- import { ConsultationAdapterError as M, createConsultationAdapterClient as _, isConsultationAdapterError as D } from "./consultation-adapter.js";
8
- import { generateDescription as H, stripLeadingH1 as O } from "./article-seo.js";
9
- import { createMarkedInstance as K, defaultImageHtml as U, parseMarkdownSafe as V } from "./markdown.js";
2
+ import { CONSULTATION_ERROR_CODES as i, KbGraphQLError as n, isConsultationErrorCode as s, isKbGraphQLError as l } from "./errors.js";
3
+ import { createKbClient as p } from "./client.js";
4
+ import { findNavNode as E, flattenNav as R, isNavigable as d, navBreadcrumbs as x, navNextPrev as T, navSiblings as c, navSubtree as v, navWalk as A } from "./navigation.js";
5
+ import { createAuthManager as S, createLocalStorageTokenStorage as _, createMemoryTokenStorage as u, decodeJwtUser as I, hasAccessLevel as C } from "./auth.js";
6
+ import { DelegatedTokenError as b, createDelegatedTokenMinter as L } from "./delegated-identity.js";
7
+ import { ConsultationAdapterError as h, createConsultationAdapterClient as k, isConsultationAdapterError as O } from "./consultation-adapter.js";
8
+ import { generateDescription as D, stripLeadingH1 as M } from "./article-seo.js";
9
+ import { createMarkedInstance as H, defaultImageHtml as P, parseMarkdownSafe as U } from "./markdown.js";
10
10
  import { deepMerge as G } from "./blog-config.js";
11
- import { retryWithBackoff as y } from "./retry.js";
12
- import { buildThemeCssVars as F, darkenColor as Q, hexToHsl as z, hexToRgb as J, hslToRgb as j, lightenColor as X, rgbTriplet as Y } from "./theme.js";
11
+ import { retryWithBackoff as B } from "./retry.js";
12
+ import { buildThemeCssVars as y, darkenColor as z, hexToHsl as Q, hexToRgb as J, hslToRgb as Y, lightenColor as j, rgbTriplet as X } from "./theme.js";
13
13
  import { buildArticleSeo as $, buildHomeSeo as ee, buildListPageSeo as re, localizedHref as oe, pageUrl as te, stripLocalePrefix as ae } from "./seo.js";
14
- import { buildArticleListItem as ie, formatArticleDate as se, lockedRequiredAccess as le, resolveArticleAccessLevel as pe, toIsoDate as me } from "./view-model.js";
15
- import { createKbI18n as de, mergeTranslations as ce } from "./i18n.js";
14
+ import { buildArticleListItem as ne, formatArticleDate as se, lockedRequiredAccess as le, resolveArticleAccessLevel as me, toIsoDate as pe } from "./view-model.js";
15
+ import { createKbI18n as Ee, mergeTranslations as Re } from "./i18n.js";
16
16
  import * as e from "./queries.js";
17
- import { prepareProps as ge } from "@blogmcp/mdx-schema/prepareProps";
18
- import { componentMetadata as Te, getComponentMetadata as ue, getComponentNames as Ae } from "@blogmcp/mdx-schema/metadata";
19
- import { REVIEW_PAGE_PATH as Ce, REVIEW_ROUTE_PATTERN as Re, isReviewTokenFormat as ve } from "./review/types.js";
20
- import { formatReviewForAgent as Le, formatReviewRound as ke } from "./review/format.js";
21
- import { default as Ne } from "./translations/cs.json.js";
22
- import { default as Me } from "./translations/en.json.js";
17
+ import { prepareProps as xe } from "@blogmcp/mdx-schema/prepareProps";
18
+ import { componentMetadata as ce, getComponentMetadata as ve, getComponentNames as Ae } from "@blogmcp/mdx-schema/metadata";
19
+ import { REVIEW_PAGE_PATH as Se, REVIEW_ROUTE_PATTERN as _e, isReviewTokenFormat as ue } from "./review/types.js";
20
+ import { formatReviewForAgent as Ce, formatReviewRound as we } from "./review/format.js";
21
+ import { REVIEW_REASON_STATUS as Le, createReviewClient as Ne, getReviewSession as he } from "./review/client.js";
22
+ import { REVIEW_LAYER_SCRIPT_URL as Oe, REVIEW_SESSION_ELEMENT_ID as We, renderReviewStatusHtml as De, reviewBootstrapHtml as Me, reviewContentWithMedia as Ve, reviewFieldAttrs as He, reviewIgnoreAttrs as Pe, reviewResponseHeaders as Ue, reviewRootAttrs as Fe, reviewStatusText as Ge } from "./review/page.js";
23
+ import { createReviewPlan as Be, normalizeReviewText as qe } from "./review/plan.js";
24
+ import { REVIEW_FIELD_ATTR as ze, REVIEW_IGNORE_ATTR as Qe, REVIEW_ROOT_ATTR as Je, stampReviewDom as Ye } from "./review/stamp.js";
25
+ import { default as Xe } from "./translations/cs.json.js";
26
+ import { default as $e } from "./translations/en.json.js";
23
27
  export {
24
28
  t as ACCESS_LEVEL_ORDER,
25
- n as CONSULTATION_ERROR_CODES,
26
- M as ConsultationAdapterError,
27
- h as DelegatedTokenError,
28
- i as KbGraphQLError,
29
- Ce as REVIEW_PAGE_PATH,
30
- Re as REVIEW_ROUTE_PATTERN,
31
- ie as buildArticleListItem,
29
+ i as CONSULTATION_ERROR_CODES,
30
+ h as ConsultationAdapterError,
31
+ b as DelegatedTokenError,
32
+ n as KbGraphQLError,
33
+ ze as REVIEW_FIELD_ATTR,
34
+ Qe as REVIEW_IGNORE_ATTR,
35
+ Oe as REVIEW_LAYER_SCRIPT_URL,
36
+ Se as REVIEW_PAGE_PATH,
37
+ Le as REVIEW_REASON_STATUS,
38
+ Je as REVIEW_ROOT_ATTR,
39
+ _e as REVIEW_ROUTE_PATTERN,
40
+ We as REVIEW_SESSION_ELEMENT_ID,
41
+ ne as buildArticleListItem,
32
42
  $ as buildArticleSeo,
33
43
  ee as buildHomeSeo,
34
44
  re as buildListPageSeo,
35
- F as buildThemeCssVars,
36
- Te as componentMetadata,
37
- C as createAuthManager,
38
- _ as createConsultationAdapterClient,
39
- N as createDelegatedTokenMinter,
40
- m as createKbClient,
41
- de as createKbI18n,
42
- R as createLocalStorageTokenStorage,
43
- K as createMarkedInstance,
44
- v as createMemoryTokenStorage,
45
- Ne as csTranslations,
46
- Q as darkenColor,
47
- S as decodeJwtUser,
45
+ y as buildThemeCssVars,
46
+ ce as componentMetadata,
47
+ S as createAuthManager,
48
+ k as createConsultationAdapterClient,
49
+ L as createDelegatedTokenMinter,
50
+ p as createKbClient,
51
+ Ee as createKbI18n,
52
+ _ as createLocalStorageTokenStorage,
53
+ H as createMarkedInstance,
54
+ u as createMemoryTokenStorage,
55
+ Ne as createReviewClient,
56
+ Be as createReviewPlan,
57
+ Xe as csTranslations,
58
+ z as darkenColor,
59
+ I as decodeJwtUser,
48
60
  G as deepMerge,
49
- U as defaultImageHtml,
50
- Me as enTranslations,
51
- d as findNavNode,
52
- c as flattenNav,
61
+ P as defaultImageHtml,
62
+ $e as enTranslations,
63
+ E as findNavNode,
64
+ R as flattenNav,
53
65
  se as formatArticleDate,
54
- Le as formatReviewForAgent,
55
- ke as formatReviewRound,
56
- H as generateDescription,
57
- ue as getComponentMetadata,
66
+ Ce as formatReviewForAgent,
67
+ we as formatReviewRound,
68
+ D as generateDescription,
69
+ ve as getComponentMetadata,
58
70
  Ae as getComponentNames,
59
- L as hasAccessLevel,
60
- z as hexToHsl,
71
+ he as getReviewSession,
72
+ C as hasAccessLevel,
73
+ Q as hexToHsl,
61
74
  J as hexToRgb,
62
- j as hslToRgb,
63
- D as isConsultationAdapterError,
75
+ Y as hslToRgb,
76
+ O as isConsultationAdapterError,
64
77
  s as isConsultationErrorCode,
65
78
  l as isKbGraphQLError,
66
- x as isNavigable,
67
- ve as isReviewTokenFormat,
68
- X as lightenColor,
79
+ d as isNavigable,
80
+ ue as isReviewTokenFormat,
81
+ j as lightenColor,
69
82
  oe as localizedHref,
70
83
  le as lockedRequiredAccess,
71
- ce as mergeTranslations,
72
- g as navBreadcrumbs,
73
- E as navNextPrev,
74
- T as navSiblings,
75
- u as navSubtree,
84
+ Re as mergeTranslations,
85
+ x as navBreadcrumbs,
86
+ T as navNextPrev,
87
+ c as navSiblings,
88
+ v as navSubtree,
76
89
  A as navWalk,
90
+ qe as normalizeReviewText,
77
91
  te as pageUrl,
78
- V as parseMarkdownSafe,
79
- ge as prepareProps,
92
+ U as parseMarkdownSafe,
93
+ xe as prepareProps,
80
94
  e as queries,
81
- pe as resolveArticleAccessLevel,
82
- y as retryWithBackoff,
83
- Y as rgbTriplet,
84
- O as stripLeadingH1,
95
+ De as renderReviewStatusHtml,
96
+ me as resolveArticleAccessLevel,
97
+ B as retryWithBackoff,
98
+ Me as reviewBootstrapHtml,
99
+ Ve as reviewContentWithMedia,
100
+ He as reviewFieldAttrs,
101
+ Pe as reviewIgnoreAttrs,
102
+ Ue as reviewResponseHeaders,
103
+ Fe as reviewRootAttrs,
104
+ Ge as reviewStatusText,
105
+ X as rgbTriplet,
106
+ Ye as stampReviewDom,
107
+ M as stripLeadingH1,
85
108
  ae as stripLocalePrefix,
86
- me as toIsoDate
109
+ pe as toIsoDate
87
110
  };
@@ -0,0 +1,125 @@
1
+ /**
2
+ * The page API client (`/api/review/v1`, docs: "Add review to your frontend").
3
+ *
4
+ * Two entry points:
5
+ * - `getReviewSession(token, …)` for the site's SERVER, which renders the review page: one call,
6
+ * and an outcome the route turns into the page or a status page (`renderReviewStatusHtml`).
7
+ * - `createReviewClient(…)` for the page itself (the review layer): state poll, media library,
8
+ * Send.
9
+ *
10
+ * The token travels only in the `X-Review-Token` header, never in a URL. Nothing here throws: every
11
+ * call answers `{ ok: true, … }` or `{ ok: false, reason, status, … }`.
12
+ */
13
+ import type { ReviewMediaItem, ReviewSession, ReviewState, ReviewSubmissionV1 } from './types.js';
14
+ /** Why a call failed, in the terms a page shows. */
15
+ export type ReviewFailureReason =
16
+ /** Unknown, malformed or someone else's token (kb-api never says which). */
17
+ 'not_found' | 'expired' | 'revoked'
18
+ /** A newer link for the same article replaced this one. */
19
+ | 'superseded'
20
+ /** Review links are switched off on this KB. */
21
+ | 'unavailable' | 'rate_limited'
22
+ /** All 20 rounds of this link were sent. */
23
+ | 'submission_limit'
24
+ /** The submission did not validate (`details` says where). */
25
+ | 'invalid' | 'too_large'
26
+ /** A picked media item is outside what this link may use (`details.slugs`). */
27
+ | 'media_not_available'
28
+ /** kb-api could not be reached, or the request timed out. */
29
+ | 'network' | 'error';
30
+ export interface ReviewFailure {
31
+ ok: false;
32
+ reason: ReviewFailureReason;
33
+ /** HTTP status; 0 when the request never got an answer. */
34
+ status: number;
35
+ /** kb-api's error code, when it sent one. */
36
+ code?: string;
37
+ details?: unknown;
38
+ /** Seconds to wait before retrying (429). */
39
+ retryAfter?: number;
40
+ }
41
+ export type ReviewResult<T> = ({
42
+ ok: true;
43
+ } & T) | ReviewFailure;
44
+ /** The statuses a review page itself answers with for each reason. */
45
+ export declare const REVIEW_REASON_STATUS: Readonly<Record<ReviewFailureReason, number>>;
46
+ type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
47
+ export interface ReviewTransportOptions {
48
+ /** The KB's public origin, e.g. `https://acme.blogmcp.ai` (the API lives under `/api/review/v1`). */
49
+ kbUrl: string;
50
+ /** Override the API base entirely (in-cluster: `http://kb-api:5070/review/v1`). */
51
+ apiBase?: string;
52
+ fetch?: FetchLike;
53
+ /** Per-request timeout; default 15 s. */
54
+ timeoutMs?: number;
55
+ }
56
+ export interface GetReviewSessionOptions extends ReviewTransportOptions {
57
+ /**
58
+ * The reviewer's IP, as the site's server saw it. kb-api rate-limits and fingerprints per reviewer
59
+ * only when it is forwarded WITH a `credential` it trusts to forward (a service key, a delegated
60
+ * session or an internal token); otherwise every reviewer of the site shares the server's address,
61
+ * and one visitor trying dead links could lock the review page for everyone.
62
+ */
63
+ clientIp?: string | null;
64
+ /** Bearer credential that may forward `clientIp` (never sent without it). */
65
+ credential?: string | null;
66
+ /** Extra request headers (e.g. the edge's `CF-Connecting-IP` for an in-cluster call). */
67
+ headers?: Record<string, string>;
68
+ }
69
+ /**
70
+ * Load a review link's session, working copy and referenced media, for rendering the review page.
71
+ * Counts as a view of the link. A token of the wrong shape answers `not_found` without a request
72
+ * (kb-api would say the same, and count it against the site's enumeration brake).
73
+ */
74
+ export declare function getReviewSession(token: string, opts: GetReviewSessionOptions): Promise<ReviewResult<{
75
+ session: ReviewSession;
76
+ }>>;
77
+ export interface ReviewMediaQuery {
78
+ q?: string;
79
+ type?: 'image' | 'video' | 'audio';
80
+ /** Tag slugs (at most 10). */
81
+ tags?: string[];
82
+ /** 1..50, default 30. */
83
+ limit?: number;
84
+ offset?: number;
85
+ /** Language of titles/alt texts; default the link's language. */
86
+ lang?: string;
87
+ }
88
+ export interface ReviewSubmitAnswer {
89
+ submissionId: string;
90
+ seq: number;
91
+ submittedAt: string;
92
+ /** True when kb-api had already stored this request (same `Idempotency-Key`). */
93
+ replayed: boolean;
94
+ }
95
+ export interface ReviewClient {
96
+ session(): Promise<ReviewResult<{
97
+ session: ReviewSession;
98
+ }>>;
99
+ /** Cheap poll: did the working copy change, did the agent take the last round? */
100
+ state(): Promise<ReviewResult<{
101
+ state: ReviewState;
102
+ }>>;
103
+ /** The library at the link's scope. Do not call with `mediaScope: 'none'` (a 404 that counts as a miss). */
104
+ media(query?: ReviewMediaQuery): Promise<ReviewResult<{
105
+ items: ReviewMediaItem[];
106
+ }>>;
107
+ mediaTags(): Promise<ReviewResult<{
108
+ tags: Array<{
109
+ id: string;
110
+ slug: string;
111
+ name: string;
112
+ color: string | null;
113
+ }>;
114
+ }>>;
115
+ /**
116
+ * Send one round. `idempotencyKey` (a UUID) must stay the same across retries of the SAME round,
117
+ * so a retry after a lost answer is stored once.
118
+ */
119
+ submit(payload: ReviewSubmissionV1, idempotencyKey: string): Promise<ReviewResult<ReviewSubmitAnswer>>;
120
+ }
121
+ export interface ReviewClientOptions extends ReviewTransportOptions {
122
+ token: string;
123
+ }
124
+ export declare function createReviewClient(opts: ReviewClientOptions): ReviewClient;
125
+ export {};
@@ -0,0 +1,116 @@
1
+ import { isReviewTokenFormat as l } from "./types.js";
2
+ const k = Object.freeze({
3
+ not_found: 404,
4
+ expired: 410,
5
+ revoked: 410,
6
+ superseded: 410,
7
+ unavailable: 503,
8
+ rate_limited: 429,
9
+ submission_limit: 409,
10
+ invalid: 400,
11
+ too_large: 413,
12
+ media_not_available: 422,
13
+ network: 502,
14
+ error: 500
15
+ }), d = {
16
+ REVIEW_TOKEN_MISSING: "not_found",
17
+ REVIEW_NOT_FOUND: "not_found",
18
+ REVIEW_EXPIRED: "expired",
19
+ REVIEW_REVOKED: "revoked",
20
+ REVIEW_SUPERSEDED: "superseded",
21
+ REVIEW_UNAVAILABLE: "unavailable",
22
+ RATE_LIMITED: "rate_limited",
23
+ REVIEW_SUBMISSION_LIMIT: "submission_limit",
24
+ VALIDATION_FAILED: "invalid",
25
+ PAYLOAD_TOO_LARGE: "too_large",
26
+ MEDIA_NOT_AVAILABLE: "media_not_available"
27
+ }, u = {
28
+ 400: "invalid",
29
+ 413: "too_large",
30
+ 429: "rate_limited"
31
+ }, f = 15e3, E = /^[0-9A-Fa-f:.]{2,45}$/;
32
+ function _(e) {
33
+ return (e.apiBase ?? `${e.kbUrl.replace(/\/+$/, "")}/api/review/v1`).replace(/\/+$/, "");
34
+ }
35
+ function m(e) {
36
+ const a = e.headers.get("Retry-After");
37
+ if (!a) return;
38
+ const n = Number(a);
39
+ return Number.isFinite(n) && n >= 0 ? n : void 0;
40
+ }
41
+ async function A(e) {
42
+ let a = {};
43
+ try {
44
+ a = await e.json();
45
+ } catch {
46
+ }
47
+ const n = typeof a.code == "string" ? a.code : void 0;
48
+ return {
49
+ ok: !1,
50
+ reason: n && d[n] || u[e.status] || (e.status >= 500 ? "network" : "error"),
51
+ status: e.status,
52
+ ...n ? { code: n } : {},
53
+ ...a.details !== void 0 ? { details: a.details } : {},
54
+ ...e.status === 429 ? { retryAfter: m(e) } : {}
55
+ };
56
+ }
57
+ async function r(e, a, n) {
58
+ const t = e.fetch ?? ((o, c) => fetch(o, c)), s = typeof AbortController == "function" ? new AbortController() : null, i = s ? setTimeout(() => s.abort(), e.timeoutMs ?? f) : null;
59
+ try {
60
+ const o = await t(`${_(e)}${a}`, {
61
+ ...n,
62
+ // The page API ignores cookies; never send the site's.
63
+ credentials: "omit",
64
+ cache: "no-store",
65
+ ...s ? { signal: s.signal } : {}
66
+ });
67
+ return o.ok ? { ok: !0, data: await o.json(), status: o.status } : A(o);
68
+ } catch {
69
+ return { ok: !1, reason: "network", status: 0 };
70
+ } finally {
71
+ i && clearTimeout(i);
72
+ }
73
+ }
74
+ async function p(e, a) {
75
+ if (!l(e)) return { ok: !1, reason: "not_found", status: 404 };
76
+ const n = { Accept: "application/json", ...a.headers, "X-Review-Token": e }, t = a.clientIp?.trim();
77
+ t && a.credential && E.test(t) && (n.Authorization = `Bearer ${a.credential}`, n["X-Blogmcp-Client-Ip"] = t);
78
+ const s = await r(a, "/session", { method: "GET", headers: n });
79
+ return s.ok ? { ok: !0, session: s.data } : s;
80
+ }
81
+ function T(e) {
82
+ const a = () => ({ Accept: "application/json", "X-Review-Token": e.token }), n = (t) => r(e, t, { method: "GET", headers: a() });
83
+ return {
84
+ async session() {
85
+ const t = await n("/session");
86
+ return t.ok ? { ok: !0, session: t.data } : t;
87
+ },
88
+ async state() {
89
+ const t = await n("/state");
90
+ return t.ok ? { ok: !0, state: t.data } : t;
91
+ },
92
+ async media(t = {}) {
93
+ const s = new URLSearchParams();
94
+ t.q && s.set("q", t.q.slice(0, 200)), t.type && s.set("type", t.type), t.tags?.length && s.set("tags", t.tags.slice(0, 10).join(",")), t.limit != null && s.set("limit", String(t.limit)), t.offset != null && s.set("offset", String(t.offset)), t.lang && s.set("lang", t.lang);
95
+ const i = s.toString(), o = await n(`/media${i ? `?${i}` : ""}`);
96
+ return o.ok ? { ok: !0, items: o.data.items } : o;
97
+ },
98
+ async mediaTags() {
99
+ const t = await n("/media/tags");
100
+ return t.ok ? { ok: !0, tags: t.data.tags } : t;
101
+ },
102
+ async submit(t, s) {
103
+ const i = await r(e, "/submit", {
104
+ method: "POST",
105
+ headers: { ...a(), "Content-Type": "application/json", "Idempotency-Key": s },
106
+ body: JSON.stringify(t)
107
+ });
108
+ return i.ok ? { ok: !0, ...i.data, replayed: i.status === 200 } : i;
109
+ }
110
+ };
111
+ }
112
+ export {
113
+ k as REVIEW_REASON_STATUS,
114
+ T as createReviewClient,
115
+ p as getReviewSession
116
+ };
@@ -1,6 +1,12 @@
1
1
  /**
2
2
  * Review links — review a draft on your own article page (docs: "Add review to your
3
- * frontend"). Dependency-free; the review layer itself ships as `@blogmcp/review`.
3
+ * frontend"). Framework-free: wire types and the agent formatter (server code such as
4
+ * md-editor's MCP tools), the page API client, the helpers a site's review route needs,
5
+ * and the block plan + DOM matching the review layer (`@blogmcp/review`) is built on.
4
6
  */
5
7
  export { REVIEW_PAGE_PATH, REVIEW_ROUTE_PATTERN, isReviewTokenFormat, type ReviewMediaScope, type ReviewMediaItem, type ReviewArticle, type ReviewRoundInfo, type ReviewSession, type ReviewState, type ReviewNodeRef, type ReviewComment, type ReviewMediaPick, type ReviewSubmissionV1, type ReviewMediaSnapshot, type StoredReviewRound, } from './types.js';
6
8
  export { formatReviewRound, formatReviewForAgent } from './format.js';
9
+ export { getReviewSession, createReviewClient, REVIEW_REASON_STATUS, type ReviewFailureReason, type ReviewFailure, type ReviewResult, type ReviewTransportOptions, type GetReviewSessionOptions, type ReviewMediaQuery, type ReviewSubmitAnswer, type ReviewClient, type ReviewClientOptions, } from './client.js';
10
+ export { reviewResponseHeaders, reviewRootAttrs, reviewFieldAttrs, reviewIgnoreAttrs, reviewStatusText, renderReviewStatusHtml, reviewBootstrapHtml, reviewContentWithMedia, REVIEW_LAYER_SCRIPT_URL, REVIEW_SESSION_ELEMENT_ID, type ReviewLang, type ReviewBootstrapOptions, } from './page.js';
11
+ export { createReviewPlan, normalizeReviewText, type ReviewPlan, type ReviewPlanUnit } from './plan.js';
12
+ export { stampReviewDom, REVIEW_ROOT_ATTR, REVIEW_FIELD_ATTR, REVIEW_IGNORE_ATTR, type ReviewStamp, } from './stamp.js';
@@ -1,9 +1,32 @@
1
- import { REVIEW_PAGE_PATH as r, REVIEW_ROUTE_PATTERN as R, isReviewTokenFormat as E } from "./types.js";
2
- import { formatReviewForAgent as m, formatReviewRound as T } from "./format.js";
1
+ import { REVIEW_PAGE_PATH as r, REVIEW_ROUTE_PATTERN as R, isReviewTokenFormat as o } from "./types.js";
2
+ import { formatReviewForAgent as i, formatReviewRound as T } from "./format.js";
3
+ import { REVIEW_REASON_STATUS as v, createReviewClient as w, getReviewSession as m } from "./client.js";
4
+ import { REVIEW_LAYER_SCRIPT_URL as a, REVIEW_SESSION_ELEMENT_ID as s, renderReviewStatusHtml as A, reviewBootstrapHtml as n, reviewContentWithMedia as S, reviewFieldAttrs as p, reviewIgnoreAttrs as W, reviewResponseHeaders as f, reviewRootAttrs as x, reviewStatusText as V } from "./page.js";
5
+ import { createReviewPlan as O, normalizeReviewText as d } from "./plan.js";
6
+ import { REVIEW_FIELD_ATTR as P, REVIEW_IGNORE_ATTR as F, REVIEW_ROOT_ATTR as H, stampReviewDom as L } from "./stamp.js";
3
7
  export {
8
+ P as REVIEW_FIELD_ATTR,
9
+ F as REVIEW_IGNORE_ATTR,
10
+ a as REVIEW_LAYER_SCRIPT_URL,
4
11
  r as REVIEW_PAGE_PATH,
12
+ v as REVIEW_REASON_STATUS,
13
+ H as REVIEW_ROOT_ATTR,
5
14
  R as REVIEW_ROUTE_PATTERN,
6
- m as formatReviewForAgent,
15
+ s as REVIEW_SESSION_ELEMENT_ID,
16
+ w as createReviewClient,
17
+ O as createReviewPlan,
18
+ i as formatReviewForAgent,
7
19
  T as formatReviewRound,
8
- E as isReviewTokenFormat
20
+ m as getReviewSession,
21
+ o as isReviewTokenFormat,
22
+ d as normalizeReviewText,
23
+ A as renderReviewStatusHtml,
24
+ n as reviewBootstrapHtml,
25
+ S as reviewContentWithMedia,
26
+ p as reviewFieldAttrs,
27
+ W as reviewIgnoreAttrs,
28
+ f as reviewResponseHeaders,
29
+ x as reviewRootAttrs,
30
+ V as reviewStatusText,
31
+ L as stampReviewDom
9
32
  };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * What a site's review route needs besides the session: response headers, the status page for a
3
+ * link that does not open, the attributes that tell the review layer where the article is, and the
4
+ * one-line bootstrap for sites without a framework wrapper.
5
+ */
6
+ import type { ReviewFailureReason } from './client.js';
7
+ import type { ReviewSession } from './types.js';
8
+ /**
9
+ * Headers for the review page (and its status pages). The page shows an unpublished draft behind a
10
+ * secret URL: never cached, never indexed, never framed, and the URL never leaves in a Referer.
11
+ */
12
+ export declare function reviewResponseHeaders(): Record<string, string>;
13
+ /** Attributes for the element that holds the rendered article. */
14
+ export declare function reviewRootAttrs(): Record<string, string>;
15
+ /** Attributes for the title, description or featured image, so a comment on it names the field. */
16
+ export declare function reviewFieldAttrs(field: 'title' | 'description' | 'featuredImage'): Record<string, string>;
17
+ /** Attributes for site chrome inside the article root that is not part of the article. */
18
+ export declare function reviewIgnoreAttrs(): Record<string, string>;
19
+ export type ReviewLang = 'cs' | 'en';
20
+ type StatusText = {
21
+ title: string;
22
+ body: string;
23
+ };
24
+ /** Title and sentence for a link that does not open, in the reviewer's language. */
25
+ export declare function reviewStatusText(reason: ReviewFailureReason, lang?: string): StatusText;
26
+ /**
27
+ * A self-contained fragment for a link that does not open (put it in the site's layout, or answer
28
+ * with it as is). Answer with `REVIEW_REASON_STATUS[reason]` and `reviewResponseHeaders()`.
29
+ */
30
+ export declare function renderReviewStatusHtml(reason: ReviewFailureReason, opts?: {
31
+ lang?: string;
32
+ }): string;
33
+ /**
34
+ * The published build of the review layer for `<script>` use (`@blogmcp/review`, dist/global), pinned
35
+ * to an exact version: the page holds the review token, so what runs on it must not change under it.
36
+ * Self-host the file (`@blogmcp/review/global`) under a strict CSP or to add Subresource Integrity.
37
+ */
38
+ export declare const REVIEW_LAYER_SCRIPT_URL = "https://cdn.jsdelivr.net/npm/@blogmcp/review@0.1.0/dist/blogmcp-review.global.js";
39
+ /** Id of the JSON island `reviewBootstrapHtml` writes the session into. */
40
+ export declare const REVIEW_SESSION_ELEMENT_ID = "blogmcp-review-session";
41
+ export interface ReviewBootstrapOptions {
42
+ token: string;
43
+ kbUrl: string;
44
+ /** UI language of the layer; default: the article's. */
45
+ lang?: string;
46
+ /** Where the layer's script comes from; default jsDelivr (`REVIEW_LAYER_SCRIPT_URL`). Self-host it under a strict CSP. */
47
+ scriptSrc?: string;
48
+ /** CSP nonce for the two script tags. */
49
+ nonce?: string;
50
+ }
51
+ /**
52
+ * The review layer for a site without a framework wrapper: the session as a JSON island (so the
53
+ * layer does not fetch it again and count a second view), the `<blogmcp-review>` element and its
54
+ * script. Put it at the end of `<body>`, after the article marked with `reviewRootAttrs()`.
55
+ */
56
+ export declare function reviewBootstrapHtml(session: ReviewSession, opts: ReviewBootstrapOptions): string;
57
+ /**
58
+ * The working copy as the review page should render it: every reference to a NON-public media item
59
+ * (`/api/media/file/<slug>`, `/api/media/thumb/<slug>`, with or without an origin) points at the
60
+ * signed URL the session carries for it, because the reviewer is anonymous to kb-api and the plain
61
+ * URL would answer 403 (page-review.md §5: the page renders referenced media at any tier). Public
62
+ * items, unknown slugs and everything else stay as they are, so a public draft renders exactly like
63
+ * the live page. Render this; pair the layer against the session's original `content` (the review
64
+ * layer does, offsets are unaffected either way).
65
+ *
66
+ * Components that take a bare `slug` and look the item up themselves are not covered; they show
67
+ * non-public items as missing.
68
+ */
69
+ export declare function reviewContentWithMedia(content: string, media: ReviewSession['media']): string;
70
+ export {};