@blogmcp/sdk 0.6.1 → 0.7.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 (136) hide show
  1. package/dist/consultations/channel-text.d.ts +118 -0
  2. package/dist/consultations/channel-text.js +40 -0
  3. package/dist/consultations/index.d.ts +28 -0
  4. package/dist/consultations/index.js +60 -0
  5. package/dist/consultations/messages.cs.d.ts +149 -0
  6. package/dist/consultations/messages.cs.js +143 -0
  7. package/dist/consultations/messages.d.ts +34 -0
  8. package/dist/consultations/messages.en.d.ts +143 -0
  9. package/dist/consultations/messages.en.js +141 -0
  10. package/dist/consultations/messages.js +48 -0
  11. package/dist/consultations/outcome.d.ts +121 -0
  12. package/dist/consultations/outcome.js +161 -0
  13. package/dist/consultations/public-config.d.ts +71 -0
  14. package/dist/consultations/public-config.js +104 -0
  15. package/dist/consultations/reader.d.ts +83 -0
  16. package/dist/consultations/reader.js +128 -0
  17. package/dist/consultations/routes.d.ts +214 -0
  18. package/dist/consultations/routes.js +149 -0
  19. package/dist/consultations/server/client-ip.d.ts +50 -0
  20. package/dist/consultations/server/client-ip.js +44 -0
  21. package/dist/consultations/server/contact.d.ts +23 -0
  22. package/dist/consultations/server/contact.js +138 -0
  23. package/dist/consultations/server/context.d.ts +246 -0
  24. package/dist/consultations/server/context.js +152 -0
  25. package/dist/consultations/server/cookie.d.ts +60 -0
  26. package/dist/consultations/server/cookie.js +57 -0
  27. package/dist/consultations/server/env.d.ts +20 -0
  28. package/dist/consultations/server/env.js +35 -0
  29. package/dist/consultations/server/http.d.ts +59 -0
  30. package/dist/consultations/server/http.js +64 -0
  31. package/dist/consultations/server/index.d.ts +37 -0
  32. package/dist/consultations/server/index.js +19 -0
  33. package/dist/consultations/server/origin.d.ts +39 -0
  34. package/dist/consultations/server/origin.js +31 -0
  35. package/dist/consultations/server/server.d.ts +106 -0
  36. package/dist/consultations/server/server.js +122 -0
  37. package/dist/consultations/server/session.d.ts +38 -0
  38. package/dist/consultations/server/session.js +210 -0
  39. package/dist/consultations/server/transport.d.ts +69 -0
  40. package/dist/consultations/server/transport.js +117 -0
  41. package/dist/consultations/server/turnstile.d.ts +44 -0
  42. package/dist/consultations/server/turnstile.js +31 -0
  43. package/dist/consultations/site.d.ts +100 -0
  44. package/dist/consultations/site.js +60 -0
  45. package/dist/consultations/submit-new.d.ts +103 -0
  46. package/dist/consultations/submit-new.js +72 -0
  47. package/dist/core/auth.d.ts +2 -2
  48. package/dist/core/client.d.ts +25 -4
  49. package/dist/core/client.js +35 -30
  50. package/dist/core/consultation-adapter.d.ts +2 -2
  51. package/dist/core/consultations.d.ts +1 -1
  52. package/dist/core/errors.d.ts +1 -1
  53. package/dist/core/errors.js +16 -15
  54. package/dist/core/index.d.ts +31 -31
  55. package/dist/core/index.js +35 -34
  56. package/dist/core/markdown.d.ts +1 -1
  57. package/dist/core/queries.d.ts +4 -1
  58. package/dist/core/queries.js +131 -86
  59. package/dist/core/review/format.d.ts +1 -1
  60. package/dist/core/review/index.d.ts +2 -2
  61. package/dist/core/seo.d.ts +1 -1
  62. package/dist/core/translations/cs.json.js +1 -1
  63. package/dist/core/translations/en.json.js +1 -1
  64. package/dist/core/types.d.ts +50 -1
  65. package/dist/core/view-model.d.ts +12 -2
  66. package/dist/core/view-model.js +40 -34
  67. package/dist/{packages/tripmap-core/node_modules → node_modules}/pmtiles/dist/esm/index.js +1 -1
  68. package/dist/nuxt/composables/useAsyncKb.d.ts +4 -4
  69. package/dist/nuxt/index.d.ts +1 -1
  70. package/dist/packages/tripmap-core/dist/engine.js +3 -3
  71. package/dist/packages/tripmap-core/dist/generated/maplibre-worker.bundle.js +1 -1
  72. package/dist/react/KbMdxContent.d.ts +1 -1
  73. package/dist/react/context.d.ts +4 -4
  74. package/dist/react/hooks/useImageRenderer.d.ts +1 -1
  75. package/dist/react/hooks/useKbClient.d.ts +1 -1
  76. package/dist/react/hooks/useKbContext.d.ts +1 -1
  77. package/dist/react/hooks/useKbI18n.d.ts +1 -1
  78. package/dist/react/hooks/useKbLanguage.d.ts +1 -1
  79. package/dist/react/hooks/useKbSearch.d.ts +1 -1
  80. package/dist/react/hooks/useMdxContent.d.ts +1 -1
  81. package/dist/react/index.d.ts +15 -15
  82. package/dist/react/provider.d.ts +2 -2
  83. package/dist/react/server/index.d.ts +2 -2
  84. package/dist/vue/components/KbAccessGate.vue.d.ts +4 -1
  85. package/dist/vue/components/KbAccessGate.vue.js +42 -32
  86. package/dist/vue/components/KbArticleCard.vue.d.ts +3 -1
  87. package/dist/vue/components/KbArticleCard.vue.js +67 -39
  88. package/dist/vue/composables/useArticles.d.ts +1 -1
  89. package/dist/vue/composables/useImageRenderer.d.ts +1 -1
  90. package/dist/vue/composables/useKbAuth.d.ts +1 -1
  91. package/dist/vue/composables/useKbClient.d.ts +1 -1
  92. package/dist/vue/composables/useKbComments.d.ts +1 -1
  93. package/dist/vue/composables/useKbI18n.d.ts +1 -1
  94. package/dist/vue/composables/useKbLanguage.d.ts +1 -1
  95. package/dist/vue/composables/useNavigation.d.ts +1 -1
  96. package/dist/vue/composables/useSearch.d.ts +1 -1
  97. package/dist/vue/composables/useTags.d.ts +1 -1
  98. package/dist/vue/index.d.ts +19 -19
  99. package/dist/vue/plugin.d.ts +4 -4
  100. package/package.json +15 -5
  101. package/src/consultations/channel-text.ts +168 -0
  102. package/src/consultations/index.ts +87 -0
  103. package/src/consultations/messages.cs.ts +175 -0
  104. package/src/consultations/messages.en.ts +171 -0
  105. package/src/consultations/messages.ts +91 -0
  106. package/src/consultations/outcome.ts +278 -0
  107. package/src/consultations/public-config.ts +246 -0
  108. package/src/consultations/reader.ts +281 -0
  109. package/src/consultations/routes.ts +341 -0
  110. package/src/consultations/server/client-ip.ts +106 -0
  111. package/src/consultations/server/contact.ts +267 -0
  112. package/src/consultations/server/context.ts +403 -0
  113. package/src/consultations/server/cookie.ts +129 -0
  114. package/src/consultations/server/env.ts +66 -0
  115. package/src/consultations/server/http.ts +148 -0
  116. package/src/consultations/server/index.ts +55 -0
  117. package/src/consultations/server/origin.ts +71 -0
  118. package/src/consultations/server/server.ts +322 -0
  119. package/src/consultations/server/session.ts +414 -0
  120. package/src/consultations/server/transport.ts +196 -0
  121. package/src/consultations/server/turnstile.ts +98 -0
  122. package/src/consultations/site.ts +183 -0
  123. package/src/consultations/submit-new.ts +266 -0
  124. package/src/core/auth.ts +1 -1
  125. package/src/core/client.ts +32 -1
  126. package/src/core/errors.ts +5 -2
  127. package/src/core/index.ts +3 -0
  128. package/src/core/queries.ts +56 -0
  129. package/src/core/translations/cs.json +2 -1
  130. package/src/core/translations/en.json +2 -1
  131. package/src/core/types.ts +51 -0
  132. package/src/core/view-model.ts +18 -0
  133. package/src/vue/components/KbAccessGate.vue +14 -1
  134. package/src/vue/components/KbArticleCard.vue +25 -0
  135. /package/dist/{packages/tripmap-core/node_modules → node_modules}/maplibre-gl/dist/maplibre-gl-shared.js +0 -0
  136. /package/dist/{packages/tripmap-core/node_modules → node_modules}/maplibre-gl/dist/maplibre-gl.js +0 -0
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Cloudflare Turnstile — server-side verification of the widget's token
3
+ * (`siteverify`). A port of the drhoubicka backend's verifier
4
+ * (`vendure-backend/src/common/turnstile.ts`).
5
+ *
6
+ * | status | ok | when |
7
+ * |---------------|-------|--------------------------------------------------------------|
8
+ * | `disabled` | true | no secret configured (dev, tests, or switched off on purpose) |
9
+ * | `unavailable` | true | Cloudflare did not answer (network, timeout, 5xx, bad body) |
10
+ * | `verified` | true | Cloudflare confirmed the token |
11
+ * | `rejected` | false | Cloudflare refused it, the token is missing or too long, or the widget's `action` differs |
12
+ *
13
+ * An outage is `ok` on purpose (fail-open, like the backend): a lost reader
14
+ * question is worse than a little more spam, which the honeypot and the KB's
15
+ * quotas still bound. The caller decides — the contact handler refuses on
16
+ * `unavailable` only with `turnstile.failOpen: false`. An attacker cannot
17
+ * cause the outage: they do not control whether Cloudflare answers.
18
+ *
19
+ * Never throws, and the verdict carries no detail: nothing here can put the
20
+ * secret (it is in the request body) or the token into a log.
21
+ */
22
+ export declare const TURNSTILE_VERIFY_URL = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
23
+ /** A Turnstile token is at most 2048 characters (Cloudflare's docs); a longer one is refused unsent. */
24
+ export declare const TURNSTILE_MAX_TOKEN_LENGTH = 2048;
25
+ export type TurnstileVerdict = {
26
+ ok: true;
27
+ status: 'disabled' | 'verified' | 'unavailable';
28
+ } | {
29
+ ok: false;
30
+ status: 'rejected';
31
+ };
32
+ export interface VerifyTurnstileOptions {
33
+ /** The widget's secret key. Empty or missing: verification is off (`disabled`). */
34
+ secret?: string | null;
35
+ /** The reader's IP when known; sent as `remoteip` only when it is exactly one IP. */
36
+ remoteIp?: string | null;
37
+ /** The widget's `action`. When Cloudflare reports one, it must match (a token from another form must not pass). */
38
+ expectedAction?: string;
39
+ /** Default 5000 ms. */
40
+ timeoutMs?: number;
41
+ /** Custom fetch (tests / runtimes without a global fetch). */
42
+ fetch?: typeof fetch;
43
+ }
44
+ export declare function verifyTurnstile(token: string | null | undefined, o: VerifyTurnstileOptions): Promise<TurnstileVerdict>;
@@ -0,0 +1,31 @@
1
+ import { singleIp as u } from "./client-ip.js";
2
+ const l = "https://challenges.cloudflare.com/turnstile/v0/siteverify", f = 2048, d = 5e3;
3
+ async function h(s, t) {
4
+ const o = typeof t?.secret == "string" ? t.secret.trim() : "";
5
+ if (!o) return { ok: !0, status: "disabled" };
6
+ const r = typeof s == "string" ? s.trim() : "";
7
+ if (!r || r.length > f) return { ok: !1, status: "rejected" };
8
+ const n = new URLSearchParams({ secret: o, response: r }), a = u(t.remoteIp);
9
+ a && n.set("remoteip", a);
10
+ let e;
11
+ try {
12
+ const c = await (t.fetch ?? globalThis.fetch)(l, {
13
+ method: "POST",
14
+ body: n,
15
+ signal: AbortSignal.timeout(t.timeoutMs ?? d),
16
+ // Following a redirect would re-send the secret to wherever it points.
17
+ redirect: "error",
18
+ cache: "no-store"
19
+ });
20
+ if (!c.ok) return { ok: !0, status: "unavailable" };
21
+ e = await c.json();
22
+ } catch {
23
+ return { ok: !0, status: "unavailable" };
24
+ }
25
+ return e === null || typeof e != "object" ? { ok: !0, status: "unavailable" } : e.success !== !0 ? (Array.isArray(e["error-codes"]) ? e["error-codes"] : []).includes("internal-error") ? { ok: !0, status: "unavailable" } : { ok: !1, status: "rejected" } : t.expectedAction && typeof e.action == "string" && e.action !== "" && e.action !== t.expectedAction ? { ok: !1, status: "rejected" } : { ok: !0, status: "verified" };
26
+ }
27
+ export {
28
+ f as TURNSTILE_MAX_TOKEN_LENGTH,
29
+ l as TURNSTILE_VERIFY_URL,
30
+ h as verifyTurnstile
31
+ };
@@ -0,0 +1,100 @@
1
+ /**
2
+ * The reader-site gate: does THIS blog serve the reader consultation pages?
3
+ *
4
+ * A tenant has one reader site — the site the KB sends readers to from its
5
+ * notice e-mails (`kb_settings.reader_base_url`, public as
6
+ * `consultationPublicConfig.readerSiteUrl`). The pages are live on a blog
7
+ * only when:
8
+ *
9
+ * 1. the blog holds its reader-proxy key (without it every reader would
10
+ * share one per-IP quota bucket, and the session pages cannot work);
11
+ * 2. the KB can be asked (otherwise `unknown`: the pages answer 503 with
12
+ * `Retry-After`, never 404 and never live);
13
+ * 3. the reader site is set, and
14
+ * 4. it is this blog: `canonicalSiteUrl(readerSiteUrl)` is one of the
15
+ * blog's own canonical URLs (`siteUrls`).
16
+ *
17
+ * So a tenant whose reader site is its storefront (`https://shop.example`)
18
+ * keeps its managed blog (`https://shop.example/blog`) dark: a different path
19
+ * is a different site.
20
+ *
21
+ * The module switch closes only what creates content: the contact form and
22
+ * new questions. Switched off, the KB still lets a reader read their
23
+ * questions, open a link, erase a question and withdraw their consent,
24
+ * because privacy duties do not end with the feature
25
+ * (docs/internal/reader-consultations.md §5.6). The pages that do that stay
26
+ * live, but the site stops linking to them (`features.links`).
27
+ */
28
+ import type { ConsultationPublicConfig } from '../core/types.js';
29
+ import { type ChannelText } from './channel-text.js';
30
+ import type { ConsultationOutcome } from './outcome.js';
31
+ /**
32
+ * A site URL in the KB's canonical reader-site form, or null when it could not
33
+ * be a reader site (empty, not https, a query string, credentials, …).
34
+ *
35
+ * The canonical form is the parsed origin (scheme and host lower-cased, IDN as
36
+ * punycode, default port dropped) plus the path, without trailing slashes:
37
+ * `https://Blog.Example:443/blog/` and `https://blog.example/blog` are the
38
+ * same site. It mirrors the KB's `canonicalReaderBaseUrl` exactly — a parity
39
+ * test runs both over the same vectors — because the KB compares and stores
40
+ * the reader site in this form.
41
+ */
42
+ export declare function canonicalSiteUrl(v: unknown): string | null;
43
+ /**
44
+ * The blog's own URLs, canonical and deduplicated, first occurrence first.
45
+ * Every argument may be a comma-separated list (`KB_MANAGED_BLOG_URLS`), a
46
+ * list of such strings, or empty; an entry that could not be a reader site is
47
+ * dropped. The union of the managed blog's list and a headless kit's
48
+ * `SITE_URL` is fine — both are this blog.
49
+ */
50
+ export declare function parseSiteUrls(...v: Array<string | string[] | null | undefined>): string[];
51
+ export interface ConsultationSiteStatus {
52
+ /** `live`: serve the pages; `dark`: 404 them; `unknown`: 503 with `Retry-After` (the KB could not be asked). */
53
+ state: 'live' | 'dark' | 'unknown';
54
+ /** Why — for logs and smoke tests only, never for readers. */
55
+ reason: 'ok' | 'module_off' | 'reader_site_unset' | 'other_reader_site' | 'reader_proxy_key_missing' | 'kb_unavailable';
56
+ features: {
57
+ /** `/consultation/open`, `/consultation` and the access / attach / forget endpoints. */
58
+ magicLink: boolean;
59
+ /** `/consultation/new-link` — only when answers reach readers by e-mail. */
60
+ newLink: boolean;
61
+ /** `/my-consultations` and `/my-consultations/:id`. (`/my-consultations/new` is decided per reader by `webAsk`.) */
62
+ account: boolean;
63
+ /** `/contact` — e-mail notices, the blog's adapter key, and a usable `contact_form` text in this locale. */
64
+ contactForm: boolean;
65
+ /**
66
+ * Link the pages from the site's menu and footer. Off while the module is
67
+ * off: the pages stay open for the questions readers already have (their
68
+ * e-mails link there), but the site offers consultations to nobody new.
69
+ * Not a page gate — menus and footers read it, `pageGate` does not.
70
+ */
71
+ links: boolean;
72
+ };
73
+ /** The contact form's text; disabled whenever `features.contactForm` is off. */
74
+ contactText: ChannelText;
75
+ }
76
+ /**
77
+ * Whether this blog serves the reader pages, and which of them.
78
+ *
79
+ * | feature | module on | module off (`reason: module_off`) |
80
+ * |---------------|-----------------------------------------------|-----------------------------------|
81
+ * | `magicLink` | yes | yes |
82
+ * | `account` | yes | yes |
83
+ * | `newLink` | `emailNotices` | `emailNotices` |
84
+ * | `contactForm` | `emailNotices` ∧ adapter key ∧ a usable `contact_form` text | no |
85
+ * | `links` | yes | no |
86
+ *
87
+ * Both columns are `live`; everything else is `dark` or `unknown` with every
88
+ * feature off. `/my-consultations/new` is decided per reader by `webAsk`, and
89
+ * the KB closes it while the module is off.
90
+ *
91
+ * `cfg` is the public config outcome (`PublicConfigCache.get(locale)`); `site`
92
+ * describes the blog: its canonical URLs, whether its reader-proxy and adapter
93
+ * keys are configured (never the keys themselves), and the page locale.
94
+ */
95
+ export declare function readerSiteStatus(cfg: ConsultationOutcome<ConsultationPublicConfig>, site: {
96
+ siteUrls: string[];
97
+ readerProxyKey: boolean;
98
+ adapterKey: boolean;
99
+ locale: string;
100
+ }): ConsultationSiteStatus;
@@ -0,0 +1,60 @@
1
+ import { CHANNEL_TEXT_DISABLED as u, channelTextFrom as f, CONSULTATION_CHANNELS as m } from "./channel-text.js";
2
+ const p = /^(https:\/\/[^/?#\s"'<>\\]+|http:\/\/(localhost|127\.0\.0\.1)(:[0-9]+)?)(\/[^?#\s"'<>\\]*)?$/;
3
+ function l(r) {
4
+ if (typeof r != "string" || r === "") return null;
5
+ const e = r.trim();
6
+ if (/[\s"'<>\\]/.test(e) || /[?#]/.test(e)) return null;
7
+ let t;
8
+ try {
9
+ t = new URL(e);
10
+ } catch {
11
+ return null;
12
+ }
13
+ const n = t.hostname === "localhost" || t.hostname === "127.0.0.1";
14
+ if (t.protocol !== "https:" && !(t.protocol === "http:" && n) || t.username || t.password) return null;
15
+ const a = `${t.origin}${t.pathname}`.replace(/\/+$/, "");
16
+ return p.test(a) ? a : null;
17
+ }
18
+ function _(...r) {
19
+ const e = [];
20
+ for (const t of r)
21
+ for (const n of Array.isArray(t) ? t : [t])
22
+ if (typeof n == "string")
23
+ for (const a of n.split(",")) {
24
+ const o = l(a.trim());
25
+ o !== null && !e.includes(o) && e.push(o);
26
+ }
27
+ return e;
28
+ }
29
+ const d = Object.freeze({ magicLink: !1, newLink: !1, account: !1, contactForm: !1, links: !1 });
30
+ function s(r, e, t = d, n = u) {
31
+ return Object.freeze({ state: r, reason: e, features: Object.freeze({ ...t }), contactText: n });
32
+ }
33
+ function h(r, e) {
34
+ if (e.readerProxyKey !== !0) return s("dark", "reader_proxy_key_missing");
35
+ if (!r || r.ok !== !0) return s("unknown", "kb_unavailable");
36
+ const t = r.value, n = l(t.readerSiteUrl);
37
+ if (n === null) return s("dark", "reader_site_unset");
38
+ if (!new Set((Array.isArray(e.siteUrls) ? e.siteUrls : []).map(l)).has(n)) return s("dark", "other_reader_site");
39
+ const o = t.emailNotices === !0;
40
+ if (t.enabled !== !0)
41
+ return s("live", "module_off", {
42
+ magicLink: !0,
43
+ account: !0,
44
+ newLink: o,
45
+ contactForm: !1,
46
+ links: !1
47
+ });
48
+ const i = f(t, m.contactForm, e.locale), c = o && e.adapterKey === !0 && i.enabled;
49
+ return s(
50
+ "live",
51
+ "ok",
52
+ { magicLink: !0, account: !0, newLink: o, contactForm: c, links: !0 },
53
+ c ? i : u
54
+ );
55
+ }
56
+ export {
57
+ l as canonicalSiteUrl,
58
+ _ as parseSiteUrls,
59
+ h as readerSiteStatus
60
+ };
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The new-question form's submit (`/my-consultations/new`, KB channel `web`):
3
+ * the decision tree of the drhoubicka storefront's `account/dotazy.novy.tsx`
4
+ * action, framework-free. The page renders what `webAsk` offers; this checks
5
+ * what was posted and sends it — or says exactly why not, with what the form
6
+ * must show next.
7
+ *
8
+ * ## Consent belongs to the person, not to a question
9
+ *
10
+ * Given once, with a first question, it covers every later one until the
11
+ * reader withdraws it — or until the tenant publishes a consent text that asks
12
+ * everyone again. So the form showed one of three things (`legalMode`):
13
+ *
14
+ * - `consent`: the consent text and an UNTICKED box. Whoever consents,
15
+ * consents to the CURRENT text: the reader's status is fetched afresh and a
16
+ * stale version is refused before anything is created (`textChanged`, with
17
+ * the new text) — the KB would otherwise record a consent to a text that is
18
+ * no longer current (texts are append-only there; keeping them current is
19
+ * ours to do);
20
+ * - `notice`: the notice text, no box; the same freshness check;
21
+ * - `covered`: no text — the reader's consent covers new questions. Nothing
22
+ * is checked first (that would cost a KB call per submit); if the consent
23
+ * stopped covering meanwhile, the KB answers CONSENT_REQUIRED (or
24
+ * NOTICE_REQUIRED once the channel is in notice mode) and the form shows
25
+ * what applies now.
26
+ *
27
+ * ## A retry keeps the idempotency key
28
+ *
29
+ * A replay of the same question with the same `clientRequestId` comes back
30
+ * from the KB as the same thread (`duplicate`) — even when one attempt
31
+ * carried the consent and the other did not. A page that minted a new key for
32
+ * every render would turn a lost response (a timeout, a 5xx from a proxy) into
33
+ * a second thread. So every failure after the form was read carries the key
34
+ * for the NEXT attempt: the posted one (a fresh one when it was malformed and
35
+ * could not have stored anything). Only `conflict` gets a new key: under the
36
+ * posted one the KB already holds DIFFERENT content (the reader edited the
37
+ * text after a lost response), so the question most likely is stored already —
38
+ * the page says so and points to the list; whoever does not find it there
39
+ * sends it again, under the new key.
40
+ *
41
+ * Everything that can be decided without the KB comes first: an empty or too
42
+ * long question, a malformed field, an unticked box. Such an attempt costs
43
+ * neither a request nor quota. Every failure returns the typed text, so a
44
+ * plain form POST (no JavaScript) never loses it.
45
+ */
46
+ import type { WebAsk } from './channel-text.js';
47
+ import type { ConsultationUiCode } from './outcome.js';
48
+ import type { ReaderConsultations } from './reader.js';
49
+ /** What the form offers (`closed` is a 404, never a form). */
50
+ type ShownAsk = Exclude<WebAsk, {
51
+ kind: 'closed';
52
+ }>;
53
+ export type NewQuestionResult = {
54
+ ok: true;
55
+ id: string;
56
+ duplicate: boolean;
57
+ } | {
58
+ ok: false;
59
+ code: ConsultationUiCode;
60
+ /** The reader's text back into the form (line breaks normalised, not trimmed). */
61
+ body: string;
62
+ /**
63
+ * The key for the NEXT attempt: the posted one (a new one after
64
+ * `conflict`, or when the posted one was malformed). Absent only when
65
+ * the fields could not be read at all.
66
+ */
67
+ clientRequestId?: string;
68
+ /** What the form shows now, whenever that is known (fresh from the KB, or what the page showed). */
69
+ ask?: ShownAsk;
70
+ /** The reader confirmed (or saw) another text than the one that applies now: "we have updated the text". */
71
+ textChanged?: true;
72
+ /**
73
+ * The reader sent without a consent because theirs covered new
74
+ * questions, and it no longer does (withdrawn in another window,
75
+ * lapsed): "your earlier consent is no longer valid". An active consent
76
+ * the tenant asks to renew is `textChanged` instead — "no longer valid"
77
+ * would be false.
78
+ */
79
+ consentNeeded?: true;
80
+ /**
81
+ * The KB said the question needs a consent, and what applies now could
82
+ * not be read (an outage). The form stays as it was — but must not keep
83
+ * saying "your consent is valid".
84
+ */
85
+ consentUnknown?: true;
86
+ };
87
+ /**
88
+ * Checks and sends a new question. `fields` are the posted form fields
89
+ * (`NEW_QUESTION_FIELDS`), `locale` the page's language; `maxBody` the form's
90
+ * limit (default `NEW_QUESTION_BODY_MAX`; never above the KB's own). Never
91
+ * throws.
92
+ *
93
+ * On success redirect with 303 to `accountThreadPath(result.id)` — "back" and
94
+ * a reload then do not post again (and if they did, the same key answers with
95
+ * the same thread).
96
+ */
97
+ export declare function submitNewConsultation(reader: ReaderConsultations, input: {
98
+ locale: string;
99
+ fields: Record<string, string | undefined>;
100
+ }, o?: {
101
+ maxBody?: number;
102
+ }): Promise<NewQuestionResult>;
103
+ export {};
@@ -0,0 +1,72 @@
1
+ import { READER_BODY_MAX as b, NEW_QUESTION_BODY_MAX as _, NEW_QUESTION_FIELDS as v, CLIENT_REQUEST_ID_RE as p, newClientRequestId as E, normalizeBody as h, LEGAL_VERSION_RE as x, LOCALE_RE as M } from "./routes.js";
2
+ function R(t, s) {
3
+ return !!t && !!s && t.mode === s.mode && t.version === s.version && t.locale === s.locale;
4
+ }
5
+ function C(t, s) {
6
+ const c = v, l = t[c.legalMode];
7
+ if (l !== "consent" && l !== "notice" && l !== "covered") return { ok: !1, code: "invalid" };
8
+ const a = h(t[c.body], s);
9
+ if (!a.ok) return { ok: !1, code: a.code };
10
+ const d = t[c.clientRequestId];
11
+ if (typeof d != "string" || !p.test(d)) return { ok: !1, code: "invalid" };
12
+ const k = t[c.consent];
13
+ if (k !== void 0 && k !== "on") return { ok: !1, code: "invalid" };
14
+ if (l === "covered") return { ok: !0, body: a.body, clientRequestId: d, legalMode: l };
15
+ const y = t[c.legalVersion], i = t[c.legalLocale];
16
+ return typeof y != "string" || !x.test(y) ? { ok: !1, code: "invalid" } : typeof i != "string" || !M.test(i) ? { ok: !1, code: "invalid" } : { ok: !0, body: a.body, clientRequestId: d, legalMode: l, version: y, locale: i, ticked: k === "on" };
17
+ }
18
+ async function q(t, s, c = {}) {
19
+ const l = s?.fields && typeof s.fields == "object" ? s.fields : {}, a = s?.locale, d = typeof c.maxBody == "number" && Number.isFinite(c.maxBody) ? Math.min(b, Math.max(1, Math.floor(c.maxBody))) : _, k = l[v.body], y = typeof k == "string" ? k.replace(/\r\n?/g, `
20
+ `).slice(0, 2 * Math.max(d, b)) : "", i = l[v.clientRequestId], I = typeof i == "string" && p.test(i) ? i : E(), o = (n, r = {}) => ({
21
+ ok: !1,
22
+ code: n,
23
+ body: y,
24
+ ...r,
25
+ clientRequestId: I
26
+ });
27
+ try {
28
+ const n = C(l, d);
29
+ if (!n.ok) return o(n.code);
30
+ if (n.legalMode === "consent" && !n.ticked) return o("consent");
31
+ let r, u;
32
+ if (n.legalMode === "covered")
33
+ r = null, u = { kind: "covered", givenAt: null };
34
+ else {
35
+ const f = await t.webAsk(a, { fresh: !0 });
36
+ if (!f.ok) return o(f.code);
37
+ const e = f.value.ask;
38
+ if (e.kind === "closed") return o("disabled");
39
+ if (e.kind === "covered")
40
+ r = null, u = e;
41
+ else {
42
+ const m = { mode: e.legal.mode, version: e.legal.version, locale: e.legal.locale }, w = { mode: n.legalMode, version: n.version, locale: n.locale };
43
+ if (!R(m, w))
44
+ return o("consent", { ask: e, textChanged: !0 });
45
+ r = m, u = e;
46
+ }
47
+ }
48
+ const g = await t.create({
49
+ body: n.body,
50
+ languageCode: a,
51
+ legal: r,
52
+ clientRequestId: n.clientRequestId
53
+ });
54
+ if (g.ok) return { ok: !0, id: g.value.id, duplicate: g.value.duplicate };
55
+ if (g.code === "consent") {
56
+ const f = await t.webAsk(a, { fresh: !0 });
57
+ if (!f.ok)
58
+ return r ? o("consent", { ask: u, textChanged: !0 }) : o(f.code, { ask: u, consentUnknown: !0 });
59
+ const e = f.value.ask;
60
+ return e.kind === "closed" ? o("disabled") : e.kind === "covered" ? o("submit", { ask: e }) : r ? o("consent", e.kind === "consent" && R(r, e.legal) ? { ask: e } : { ask: e, textChanged: !0 }) : o(
61
+ "consent",
62
+ e.kind === "consent" && !e.renew ? { ask: e, consentNeeded: !0 } : { ask: e, textChanged: !0 }
63
+ );
64
+ }
65
+ return g.code === "conflict" ? { ok: !1, code: "conflict", body: y, ask: u, clientRequestId: E() } : o(g.code, { ask: u });
66
+ } catch {
67
+ return o("unavailable");
68
+ }
69
+ }
70
+ export {
71
+ q as submitNewConsultation
72
+ };
@@ -4,8 +4,8 @@
4
4
  * Handles JWT token decode, access level checking, login/logout.
5
5
  * Consumers provide their own TokenStorage implementation.
6
6
  */
7
- import type { TokenStorage } from './client-types';
8
- import type { AuthUser, AccessLevel } from './types';
7
+ import type { TokenStorage } from './client-types.js';
8
+ import type { AuthUser, AccessLevel } from './types.js';
9
9
  export interface AuthManager {
10
10
  getToken(): string | null;
11
11
  getUser(): AuthUser | null;
@@ -5,10 +5,10 @@
5
5
  * const client = createKbClient({ endpoint: 'https://api.example.com/graphql' })
6
6
  * const data = await client.articles.list({ status: 'published', limit: 10 })
7
7
  */
8
- import type { KbClientConfig } from './client-types';
9
- import type { Article, ArticleWithTranslation, ArticleVersionContent, Tag, LocalizedTag, Language, SearchResult, KBContextChunk, Translation, Comment, CommentsConnection, CommentResult, AuthResult, RegisterResult, UpdateProfileResult, ReportSettings, UpdateReportSettingsInput } from './types';
10
- import type { NavNode } from './navigation';
11
- import { type KbConsultationsApi, type KbConsultationSessionApi } from './consultations';
8
+ import type { KbClientConfig } from './client-types.js';
9
+ import type { Article, ArticlePreview, ArticleWithTranslation, ArticleVersionContent, Tag, LocalizedTag, Language, SearchResult, KBContextChunk, Translation, Comment, CommentsConnection, CommentResult, AuthResult, RegisterResult, UpdateProfileResult, ReportSettings, UpdateReportSettingsInput } from './types.js';
10
+ import type { NavNode } from './navigation.js';
11
+ import { type KbConsultationsApi, type KbConsultationSessionApi } from './consultations.js';
12
12
  export interface KbClient {
13
13
  articles: {
14
14
  list(params?: {
@@ -19,6 +19,12 @@ export interface KbClient {
19
19
  tagMode?: 'all' | 'any';
20
20
  limit?: number;
21
21
  offset?: number;
22
+ /**
23
+ * Also list the published premium/partners articles the caller may not open but
24
+ * the tenant shows (its locked-article preview is title or excerpt), each flagged
25
+ * `locked` with its `access` tiers. Needs a KB API with the locked-article preview.
26
+ */
27
+ includeLocked?: boolean;
22
28
  }): Promise<{
23
29
  accessibleKbArticles: {
24
30
  articles: Article[];
@@ -42,6 +48,21 @@ export interface KbClient {
42
48
  * extension), or null if the slug was never an alias. Backs the blog
43
49
  * 301-redirect after a rename.
44
50
  */
51
+ /**
52
+ * What a reader who may NOT open a published article sees of it: title,
53
+ * description, the tier that opens it and — when the tenant chose so — a plain-text
54
+ * excerpt. `{ articlePreview: null }` when the tenant hides locked articles, when the
55
+ * article is missing, internal-only or unpublished, and when the caller can open it
56
+ * (then `getWithTranslation` returns it). Call it after `getWithTranslation` came
57
+ * back null, to show a sign-in / upgrade gate instead of "not found".
58
+ */
59
+ getPreview(filename: string, languageCode: string): Promise<{
60
+ articlePreview: ArticlePreview | null;
61
+ }>;
62
+ /** `getPreview` by the article's IMMUTABLE id. */
63
+ getPreviewById(id: string, languageCode: string): Promise<{
64
+ articlePreviewById: ArticlePreview | null;
65
+ }>;
45
66
  resolveAlias(filename: string): Promise<{
46
67
  articleAliasTarget: string | null;
47
68
  }>;
@@ -1,15 +1,15 @@
1
- import { UPDATE_MY_PROFILE as i, ARTICLE_VERSION as A, UPDATE_MY_REPORT_SETTINGS as S, MY_REPORT_SETTINGS as _, CHANGE_PASSWORD as l, RESEND_VERIFICATION as I, RESET_PASSWORD as R, FORGOT_PASSWORD as c, VERIFY_EMAIL as d, REGISTER as C, LOGIN as p, DELETE_COMMENT as u, UPDATE_COMMENT as L, CREATE_COMMENT as N, GET_COMMENT as O, ARTICLE_COMMENTS as h, GET_TRANSLATION as m, ARTICLE_TRANSLATIONS as G, KB_NAVIGATION as g, KB_LANGUAGES as M, LOCALIZED_TAGS as P, ACCESSIBLE_TAGS as y, GET_KB_CONTEXT as D, SEARCH_KNOWLEDGE_BASE as f, ARTICLE_ALIAS_TARGET as w, ARTICLE_WITH_TRANSLATION_BY_ID as B, ARTICLE_WITH_TRANSLATION as v, ACCESSIBLE_ARTICLES as K } from "./queries.js";
2
- import { createMemoryTokenStorage as W } from "./auth.js";
3
- import { KbGraphQLError as k } from "./errors.js";
4
- import { createConsultationSessionApi as x, createConsultationsApi as V } from "./consultations.js";
5
- function b() {
1
+ import { UPDATE_MY_PROFILE as i, ARTICLE_VERSION as A, UPDATE_MY_REPORT_SETTINGS as S, MY_REPORT_SETTINGS as _, CHANGE_PASSWORD as I, RESEND_VERIFICATION as l, RESET_PASSWORD as R, FORGOT_PASSWORD as C, VERIFY_EMAIL as c, REGISTER as d, LOGIN as L, DELETE_COMMENT as u, UPDATE_COMMENT as O, CREATE_COMMENT as p, GET_COMMENT as N, ARTICLE_COMMENTS as h, GET_TRANSLATION as m, ARTICLE_TRANSLATIONS as G, KB_NAVIGATION as P, KB_LANGUAGES as g, LOCALIZED_TAGS as M, ACCESSIBLE_TAGS as y, GET_KB_CONTEXT as D, SEARCH_KNOWLEDGE_BASE as B, ARTICLE_ALIAS_TARGET as f, ARTICLE_PREVIEW_BY_ID as v, ARTICLE_PREVIEW as w, ARTICLE_WITH_TRANSLATION_BY_ID as W, ARTICLE_WITH_TRANSLATION as K, ACCESSIBLE_ARTICLES_WITH_LOCKED as V, ACCESSIBLE_ARTICLES as k } from "./queries.js";
2
+ import { createMemoryTokenStorage as b } from "./auth.js";
3
+ import { KbGraphQLError as x } from "./errors.js";
4
+ import { createConsultationSessionApi as Y, createConsultationsApi as F } from "./consultations.js";
5
+ function H() {
6
6
  return async (o, n) => (await fetch(o, {
7
7
  method: n.method,
8
8
  headers: n.headers,
9
9
  body: n.body
10
10
  })).json();
11
11
  }
12
- async function F(o, n, s) {
12
+ async function U(o, n, s) {
13
13
  const E = {
14
14
  ...o.headers ?? {},
15
15
  "Content-Type": "application/json"
@@ -21,35 +21,40 @@ async function F(o, n, s) {
21
21
  body: JSON.stringify({ query: n, variables: s })
22
22
  });
23
23
  if (t.errors?.length)
24
- throw new k(t.errors);
24
+ throw new x(t.errors);
25
25
  return t.data;
26
26
  }
27
- function j(o) {
28
- const n = o.fetcher || b(), s = o.tokenStorage || W(), a = { endpoint: o.isServer && o.serverEndpoint ? o.serverEndpoint : o.endpoint, fetcher: n, tokenStorage: s, headers: o.headers };
27
+ function J(o) {
28
+ const n = o.fetcher || H(), s = o.tokenStorage || b(), a = { endpoint: o.isServer && o.serverEndpoint ? o.serverEndpoint : o.endpoint, fetcher: n, tokenStorage: s, headers: o.headers };
29
29
  function t(e, r) {
30
- return F(a, e, r);
30
+ return U(a, e, r);
31
31
  }
32
32
  return {
33
33
  articles: {
34
- list: (e) => t(K, e),
35
- getWithTranslation: (e, r) => t(v, { filename: e, languageCode: r }),
36
- getWithTranslationById: (e, r) => t(B, { id: e, languageCode: r }),
37
- resolveAlias: (e) => t(w, { filename: e }),
34
+ list: (e) => {
35
+ const { includeLocked: r, ...T } = e ?? {};
36
+ return t(r ? V : k, T);
37
+ },
38
+ getWithTranslation: (e, r) => t(K, { filename: e, languageCode: r }),
39
+ getWithTranslationById: (e, r) => t(W, { id: e, languageCode: r }),
40
+ getPreview: (e, r) => t(w, { filename: e, languageCode: r }),
41
+ getPreviewById: (e, r) => t(v, { id: e, languageCode: r }),
42
+ resolveAlias: (e) => t(f, { filename: e }),
38
43
  getVersion: (e, r) => t(A, { versionId: e, previewKey: r?.previewKey ?? null })
39
44
  },
40
45
  search: {
41
- query: (e) => t(f, e),
46
+ query: (e) => t(B, e),
42
47
  getContext: (e, r) => t(D, { query: e, maxChunks: r })
43
48
  },
44
49
  tags: {
45
50
  list: () => t(y),
46
- listLocalized: (e) => t(P, { languageCode: e })
51
+ listLocalized: (e) => t(M, { languageCode: e })
47
52
  },
48
53
  languages: {
49
- list: () => t(M)
54
+ list: () => t(g)
50
55
  },
51
56
  navigation: {
52
- get: (e) => t(g, e ?? {})
57
+ get: (e) => t(P, e ?? {})
53
58
  },
54
59
  translations: {
55
60
  list: (e) => t(G, { articleId: e }),
@@ -57,19 +62,19 @@ function j(o) {
57
62
  },
58
63
  comments: {
59
64
  list: (e, r) => t(h, { articleId: e, languageCode: r }),
60
- get: (e, r) => t(O, { commentId: e, languageCode: r }),
61
- create: (e) => t(N, e),
62
- update: (e, r) => t(L, { commentId: e, content: r }),
65
+ get: (e, r) => t(N, { commentId: e, languageCode: r }),
66
+ create: (e) => t(p, e),
67
+ update: (e, r) => t(O, { commentId: e, content: r }),
63
68
  delete: (e) => t(u, { commentId: e })
64
69
  },
65
70
  auth: {
66
- login: (e, r) => t(p, { email: e, password: r }),
67
- register: (e, r, T) => t(C, { email: e, password: r, name: T }),
68
- verifyEmail: (e) => t(d, { token: e }),
69
- forgotPassword: (e) => t(c, { email: e }),
71
+ login: (e, r) => t(L, { email: e, password: r }),
72
+ register: (e, r, T) => t(d, { email: e, password: r, name: T }),
73
+ verifyEmail: (e) => t(c, { token: e }),
74
+ forgotPassword: (e) => t(C, { email: e }),
70
75
  resetPassword: (e, r) => t(R, { token: e, password: r }),
71
- resendVerification: (e) => t(I, { email: e }),
72
- changePassword: (e, r) => t(l, { currentPassword: e, newPassword: r }),
76
+ resendVerification: (e) => t(l, { email: e }),
77
+ changePassword: (e, r) => t(I, { currentPassword: e, newPassword: r }),
73
78
  updateProfile: (e) => t(i, {
74
79
  name: e.name ?? null,
75
80
  email: e.email ?? null
@@ -79,11 +84,11 @@ function j(o) {
79
84
  get: () => t(_),
80
85
  update: (e) => t(S, e)
81
86
  },
82
- consultations: V(t),
83
- consultationSession: x(t),
87
+ consultations: F(t),
88
+ consultationSession: Y(t),
84
89
  executeGraphQL: t
85
90
  };
86
91
  }
87
92
  export {
88
- j as createKbClient
93
+ J as createKbClient
89
94
  };
@@ -20,8 +20,8 @@
20
20
  * `ConsultationAdapterError` with the contract's `{code}` and the HTTP status;
21
21
  * their message names the operation, status and code only, never a body.
22
22
  */
23
- import type { KbErrorCode } from './errors';
24
- import type { ConsultationAckInput, ConsultationEraseInput, ConsultationEraseResult, ConsultationFailInput, ConsultationIngestInput, ConsultationIngestResult, ConsultationLeaseInput, ConsultationLeaseResult, ConsultationOkResult, ConsultationOutboxStats, ConsultationOwnerRefsInput, ConsultationOwnerRefsResult, ConsultationThreadByNotice, ConsultationThreadOwner } from './types';
23
+ import type { KbErrorCode } from './errors.js';
24
+ import type { ConsultationAckInput, ConsultationEraseInput, ConsultationEraseResult, ConsultationFailInput, ConsultationIngestInput, ConsultationIngestResult, ConsultationLeaseInput, ConsultationLeaseResult, ConsultationOkResult, ConsultationOutboxStats, ConsultationOwnerRefsInput, ConsultationOwnerRefsResult, ConsultationThreadByNotice, ConsultationThreadOwner } from './types.js';
25
25
  export interface ConsultationAdapterClientConfig {
26
26
  /**
27
27
  * The KB API base URL: `https://<tenant host>/api` through the ingress, or
@@ -33,7 +33,7 @@
33
33
  * storefront's one egress IP (link exchange, link requests, session posts).
34
34
  * Nothing here logs: bodies, sessions, tokens and addresses stay in memory.
35
35
  */
36
- import type { ConsultationConsentWithdrawalResult, ConsultationMessageInput, ConsultationPublicConfig, ConsultationSessionResult, CreateMyConsultationInput, ReaderConsultation, ReaderConsultationConsent, ReaderConsultationResult, ReaderConsultationSummary } from './types';
36
+ import type { ConsultationConsentWithdrawalResult, ConsultationMessageInput, ConsultationPublicConfig, ConsultationSessionResult, CreateMyConsultationInput, ReaderConsultation, ReaderConsultationConsent, ReaderConsultationResult, ReaderConsultationSummary } from './types.js';
37
37
  /** Executes one GraphQL document (the client's `executeGraphQL`). */
38
38
  export type GraphQLExec = <T>(query: string, variables?: Record<string, unknown>) => Promise<T>;
39
39
  export interface KbConsultationsApi {
@@ -13,7 +13,7 @@
13
13
  * test compares the two lists.
14
14
  */
15
15
  /** Every reader-consultation error code of the KB API, in its declaration order. */
16
- export declare const CONSULTATION_ERROR_CODES: readonly ["UNAUTHENTICATED", "FORBIDDEN", "NOT_FOUND", "FEATURE_DISABLED", "INVALID_INPUT", "BODY_TOO_LONG", "NOTICE_REQUIRED", "NOTICE_VERSION_UNKNOWN", "CONSENT_REQUIRED", "CONSENT_VERSION_UNKNOWN", "CHANNEL_NOT_ALLOWED", "THREAD_REQUIRED", "SENDER_MISMATCH", "QUOTA_EXCEEDED", "INVALID_LINK", "THREAD_CLOSED", "ATTACH_EMAIL_MISMATCH", "STALE_THREAD", "STALE_LEASE", "NOTHING_TO_DO", "IDEMPOTENCY_CONFLICT", "LEGAL_HOLD", "CONTENT_ACCESS_REQUIRED", "READER_URL_MISSING", "READER_PATH_MISSING", "TEXT_MISSING", "OPERATOR_MISSING", "TEXT_VERSION_EXISTS", "CONTENT_ACCESS_ATTESTATION_REQUIRED", "AI_DRAFTS_DISABLED", "AI_LOCAL_UNAVAILABLE", "PROCESSING_RESTRICTED", "DRAFT_FLAGS_UNACKNOWLEDGED", "REPLY_POLICY_MISSING", "DRAFT_ID_REQUIRED", "CARD_GUARD_FAILED", "CARD_CONFIRMATION_REQUIRED", "STALE_CARD", "RETRY_LATER", "INTERNAL_ERROR"];
16
+ export declare const CONSULTATION_ERROR_CODES: readonly ["UNAUTHENTICATED", "FORBIDDEN", "NOT_FOUND", "FEATURE_DISABLED", "INVALID_INPUT", "BODY_TOO_LONG", "NOTICE_REQUIRED", "NOTICE_VERSION_UNKNOWN", "CONSENT_REQUIRED", "CONSENT_VERSION_UNKNOWN", "CHANNEL_NOT_ALLOWED", "THREAD_REQUIRED", "SENDER_MISMATCH", "QUOTA_EXCEEDED", "INVALID_LINK", "THREAD_CLOSED", "ATTACH_EMAIL_MISMATCH", "STALE_THREAD", "STALE_LEASE", "NOTHING_TO_DO", "IDEMPOTENCY_CONFLICT", "LEGAL_HOLD", "CONTENT_ACCESS_REQUIRED", "READER_URL_MISSING", "READER_PATH_MISSING", "TEXT_MISSING", "OPERATOR_MISSING", "MAIL_TRANSPORT_MISSING", "TEXT_VERSION_EXISTS", "CONTENT_ACCESS_ATTESTATION_REQUIRED", "AI_DRAFTS_DISABLED", "AI_LOCAL_UNAVAILABLE", "PROCESSING_RESTRICTED", "DRAFT_FLAGS_UNACKNOWLEDGED", "REPLY_POLICY_MISSING", "DRAFT_ID_REQUIRED", "CARD_GUARD_FAILED", "CARD_CONFIRMATION_REQUIRED", "STALE_CARD", "RETRY_LATER", "INTERNAL_ERROR"];
17
17
  /** A reader-consultation error code (the `code` of a result or of a thrown error). */
18
18
  export type ConsultationErrorCode = (typeof CONSULTATION_ERROR_CODES)[number];
19
19
  /**