@blogmcp/sdk 0.9.4 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/community/channels.d.ts +7 -6
  2. package/dist/community/channels.js +4 -4
  3. package/dist/community/client.d.ts +74 -4
  4. package/dist/community/client.js +143 -91
  5. package/dist/community/index.d.ts +11 -6
  6. package/dist/community/index.js +111 -80
  7. package/dist/community/links.d.ts +61 -1
  8. package/dist/community/links.js +94 -40
  9. package/dist/community/manifest/index.d.ts +54 -0
  10. package/dist/community/manifest/index.js +46 -0
  11. package/dist/community/mentions.d.ts +38 -0
  12. package/dist/community/mentions.js +25 -0
  13. package/dist/community/messages.cs.d.ts +73 -3
  14. package/dist/community/messages.cs.js +82 -3
  15. package/dist/community/messages.d.ts +11 -0
  16. package/dist/community/messages.en.d.ts +69 -1
  17. package/dist/community/messages.en.js +71 -1
  18. package/dist/community/messages.js +26 -16
  19. package/dist/community/outcome.d.ts +8 -3
  20. package/dist/community/outcome.js +75 -28
  21. package/dist/community/realtime/index.d.ts +118 -0
  22. package/dist/community/realtime/index.js +215 -0
  23. package/dist/community/routes.d.ts +12 -0
  24. package/dist/community/routes.js +41 -25
  25. package/dist/community/server/bff.js +25 -25
  26. package/dist/community/server/host-routes.js +12 -0
  27. package/dist/community/server/index.d.ts +1 -1
  28. package/dist/community/server/index.js +15 -14
  29. package/dist/community/server/route-decision.d.ts +8 -0
  30. package/dist/community/server/route-decision.js +28 -22
  31. package/dist/community/shapes.d.ts +214 -2
  32. package/dist/community/shapes.js +65 -25
  33. package/dist/community/store.d.ts +18 -1
  34. package/dist/community/store.js +316 -261
  35. package/dist/community/sw/index.d.ts +45 -0
  36. package/dist/community/sw/index.js +59 -0
  37. package/dist/community/ua.d.ts +12 -0
  38. package/dist/community/ua.js +9 -0
  39. package/package.json +20 -3
  40. package/src/community/channels.ts +8 -7
  41. package/src/community/client.ts +116 -5
  42. package/src/community/index.ts +59 -1
  43. package/src/community/links.ts +119 -2
  44. package/src/community/manifest/index.ts +107 -0
  45. package/src/community/mentions.ts +59 -0
  46. package/src/community/messages.cs.ts +88 -3
  47. package/src/community/messages.en.ts +77 -1
  48. package/src/community/messages.ts +19 -0
  49. package/src/community/outcome.ts +53 -1
  50. package/src/community/realtime/index.ts +522 -0
  51. package/src/community/routes.ts +16 -0
  52. package/src/community/server/bff.ts +2 -4
  53. package/src/community/server/host-routes.ts +12 -0
  54. package/src/community/server/index.ts +1 -0
  55. package/src/community/server/route-decision.ts +15 -0
  56. package/src/community/shapes.ts +256 -3
  57. package/src/community/store.ts +114 -0
  58. package/src/community/sw/index.ts +112 -0
  59. package/src/community/ua.ts +17 -0
@@ -9,9 +9,15 @@
9
9
  * takes them as attributes. Without them the managed blog's pages apply, COMMUNITY_ROUTES — the paths kb-api's
10
10
  * deliveries fall back to (a drift spec pins them to kb-api's).
11
11
  *
12
- * Browser-safe; readReceiptFromHash is the one function that touches `window` (on call, never on import).
12
+ * M2 T8: the module's pages (profile, settings, welcome, notifications, discussions) and the digest's unsubscribe
13
+ * token, which travels in the fragment of the settings page's link (`#u=<kbun_…>`) by the receipt's rule.
14
+ *
15
+ * Browser-safe; readReceiptFromHash and readDigestTokenFromHash are the functions that touch `window` (on call,
16
+ * never on import).
13
17
  */
14
18
 
19
+ import { COMMUNITY_HANDLE_RE } from './routes'
20
+
15
21
  /**
16
22
  * The managed blog's community pages (router-relative; the blog prepends its own base). The three legal pages —
17
23
  * `rules`, `terms`, `privacy` — are each the tenant's current `legal/current` text of that kind, rendered by the blog's
@@ -32,6 +38,17 @@ export const COMMUNITY_ROUTES = Object.freeze({
32
38
  terms: '/community/terms',
33
39
  /** The discussion privacy notice, rendered the same way. */
34
40
  privacy: '/community/privacy',
41
+ // M2 T8 (m2-contracts.md §3.10, §3.3): the module's pages. The storefront names its own (`/komunita/…`).
42
+ /** The discussions overview (the articles with a discussion). */
43
+ discussions: '/community/discussions',
44
+ /** A member's public profile; `{handle}` is the member's handle (profilePath). */
45
+ profile: '/community/u/{handle}',
46
+ /** The member's notification settings — also where the digest's unsubscribe link lands (`#u=<token>`). */
47
+ settings: '/community/settings',
48
+ /** The welcome page after joining: the rules' summary and three links. */
49
+ welcome: '/community/welcome',
50
+ /** The notification centre (kb-api's fallback for `notifications_link_path`). */
51
+ notifications: '/community/notifications',
35
52
  } as const)
36
53
 
37
54
  /** A decision's id (kb-api's UUIDs). */
@@ -60,6 +77,56 @@ export function statementPath(template: string | null | undefined, decisionId: s
60
77
  return t.split('{id}').join(decisionId.toLowerCase())
61
78
  }
62
79
 
80
+ /**
81
+ * A member's profile page: `{handle}` of the template filled with the handle (lower-cased; a leading `@` is dropped).
82
+ * The template is the host's (its `profilePath` attribute); absent, the managed blog's. Null for a handle that is no
83
+ * handle, or a template that is no site path, lacks `{handle}` or holds another brace — no link from arbitrary text.
84
+ */
85
+ export function profilePath(template: string | null | undefined, handle: string): string | null {
86
+ const t = template === null || template === undefined || template === '' ? COMMUNITY_ROUTES.profile : template
87
+ if (!isSitePath(t) || !t.includes('{handle}') || /[{}]/.test(t.split('{handle}').join(''))) return null
88
+ const h = typeof handle === 'string' ? handle.replace(/^@/, '').toLowerCase() : ''
89
+ if (!COMMUNITY_HANDLE_RE.test(h)) return null
90
+ return t.split('{handle}').join(h)
91
+ }
92
+
93
+ /**
94
+ * M2 T10: the id `<blogmcp-discussion>` gives a message's row — `bcm-msg-<seq>` (the seq is the message's number in
95
+ * its conversation, the same for every reader) — and the fragment a link to that message carries. The element
96
+ * renders in a shadow root, so it scrolls to the row itself once its first page is in (the browser cannot).
97
+ */
98
+ export const COMMUNITY_MESSAGE_ANCHOR_PREFIX = 'bcm-msg-'
99
+
100
+ const isSeq = (seq: unknown): seq is number => typeof seq === 'number' && Number.isSafeInteger(seq) && seq > 0
101
+
102
+ /** A message's anchor id (`bcm-msg-12`), or null for anything that is not a message's seq (a pending row's 0). */
103
+ export function communityMessageAnchor(seq: number): string | null {
104
+ return isSeq(seq) ? `${COMMUNITY_MESSAGE_ANCHOR_PREFIX}${seq}` : null
105
+ }
106
+
107
+ /** The seq of a message anchor in a URL fragment (`#bcm-msg-12`), or null — nothing else of the fragment is read. */
108
+ export function communityMessageSeqFromHash(hash: string): number | null {
109
+ const m = new RegExp(`^#${COMMUNITY_MESSAGE_ANCHOR_PREFIX}([1-9][0-9]{0,14})$`).exec(typeof hash === 'string' ? hash : '')
110
+ const seq = m ? Number(m[1]) : NaN
111
+ return isSeq(seq) ? seq : null
112
+ }
113
+
114
+ /**
115
+ * M2 T10: a message on its article's page — the host's article template (`articlePath`, one `{slug}`: the managed
116
+ * blogs `/blog/articles/{slug}`, the storefront `/blog/{slug}`) filled with the article's slug (URL-encoded), and the
117
+ * message's anchor in the fragment. No default: null without a template, for a template that is no site path, holds
118
+ * a fragment, lacks `{slug}` or holds another brace, and for a slug or seq that is none — no link from arbitrary text.
119
+ */
120
+ export function communityMessageLink(articlePath: string | null | undefined, articleSlug: string | null | undefined, seq: number | null | undefined): string | null {
121
+ const t = articlePath
122
+ if (!isSitePath(t) || t.includes('#') || !t.includes('{slug}') || /[{}]/.test(t.split('{slug}').join(''))) return null
123
+ if (typeof articleSlug !== 'string' || articleSlug === '' || articleSlug.length > 512 || articleSlug === '.' || articleSlug === '..') return null
124
+ if (/[\u0000-\u001f\u007f]/.test(articleSlug)) return null
125
+ const anchor = communityMessageAnchor(seq as number)
126
+ if (anchor === null) return null
127
+ return `${t.split('{slug}').join(encodeURIComponent(articleSlug))}#${anchor}`
128
+ }
129
+
63
130
  /** The „Moje komunita" page: the host's path when it is a site path, else the managed blog's. */
64
131
  export function myCommunityPath(path?: string | null): string {
65
132
  return isSitePath(path) ? path : COMMUNITY_ROUTES.myCommunity
@@ -104,7 +171,7 @@ const receipts = new WeakMap<Window, string | null>()
104
171
  function browserWindow(): Window {
105
172
  if (typeof window === 'undefined') {
106
173
  throw new Error(
107
- '[blogmcp-sdk] readReceiptFromHash reads the address bar — call it in the browser (onMounted / useEffect), ' +
174
+ '[blogmcp-sdk] readReceiptFromHash and readDigestTokenFromHash read the address bar — call them in the browser (onMounted / useEffect), ' +
108
175
  'never while rendering on the server',
109
176
  )
110
177
  }
@@ -172,3 +239,53 @@ export function readReceiptFromHash(win: Window = browserWindow()): string | nul
172
239
  if (first || fresh !== null) receipts.set(win, fresh)
173
240
  return receipts.get(win) ?? null
174
241
  }
242
+
243
+ // ───────────────────────── the digest's unsubscribe link (M2 T3, m2-contracts.md §3.3, §9.3) ─────────────────────────
244
+
245
+ /** The digest's unsubscribe token: kb-api's `kbun_` capability (DIGEST_TOKEN_RE: 64 base64url characters). */
246
+ export const COMMUNITY_DIGEST_TOKEN_RE = /^kbun_[A-Za-z0-9_-]{64}$/
247
+
248
+ /** The fragment key of the unsubscribe token (`#u=…`), kb-api's UNSUBSCRIBE_FRAGMENT_KEY. */
249
+ const DIGEST_TOKEN_KEY = 'u'
250
+
251
+ /**
252
+ * The unsubscribe token in a URL fragment (`#u=<token>`, the digest e-mail's link to the settings page), or null.
253
+ * Only kb-api's exact token shape is accepted, as receiptFromHash does for a receipt.
254
+ */
255
+ export function digestTokenFromHash(hash: string): string | null {
256
+ const match = /^#u=([^&]*)/.exec(typeof hash === 'string' ? hash : '')
257
+ const token = match?.[1] ?? ''
258
+ return COMMUNITY_DIGEST_TOKEN_RE.test(token) ? token : null
259
+ }
260
+
261
+ /** The unsubscribe token each window's address bar carried, read once. */
262
+ const digestTokens = new WeakMap<Window, string | null>()
263
+
264
+ /**
265
+ * The digest's unsubscribe token from the address bar, which is then cleared of it (the URL and the router's copy in
266
+ * `history.state`), as readReceiptFromHash does for a receipt — the token switches the member's digest off, so it
267
+ * stays out of the history, a bookmark and a shared link. Remembered per window (a second mount still gets it)
268
+ * until forgetDigestToken — call it once the token was used, so a later mount does not offer the unsubscribe again.
269
+ *
270
+ * Reading it never sends it: the page POSTs `me.settings.unsubscribeDigest({ token })` only on the member's click
271
+ * (a mail scanner that opens the link must not unsubscribe anyone). ⚠️ In a vue-router app follow it with
272
+ * `router.replace({ hash: '' })`.
273
+ */
274
+ export function readDigestTokenFromHash(win: Window = browserWindow()): string | null {
275
+ const hash = win.location.hash
276
+ const fresh = digestTokenFromHash(hash)
277
+ const first = !digestTokens.has(win)
278
+ if (hash.startsWith(`#${DIGEST_TOKEN_KEY}=`)) {
279
+ win.history.replaceState(scrubbedState(win.history.state, hash, fresh), '', win.location.pathname + win.location.search)
280
+ }
281
+ if (first || fresh !== null) digestTokens.set(win, fresh)
282
+ return digestTokens.get(win) ?? null
283
+ }
284
+
285
+ /**
286
+ * Forgets the window's remembered unsubscribe token (after `me.settings.unsubscribeDigest` answered, either way: the
287
+ * token is single-purpose). The next readDigestTokenFromHash reads the address bar afresh — which it cleared.
288
+ */
289
+ export function forgetDigestToken(win: Window = browserWindow()): void {
290
+ digestTokens.delete(win)
291
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * `@blogmcp/sdk/community/manifest` — the web app manifest that lets a member install the site (community M2,
3
+ * slice T4; docs/internal/m2-contracts.md §3.4; community.md §7.5: iOS shows web push only to a website added to
4
+ * the home screen).
5
+ *
6
+ * A host serves `JSON.stringify(communityManifest(…))` from `<base>/manifest.webmanifest` as
7
+ * COMMUNITY_MANIFEST_CONTENT_TYPE and links it from its pages (`<link rel="manifest">`). `display: standalone`, the
8
+ * start URL is the notification centre, the scope is the site's base (the managed blogs' `/blog/`, the
9
+ * storefront's `/`), so an installed app opens where a notification would.
10
+ *
11
+ * Pure: no DOM, no globals, no import.
12
+ */
13
+
14
+ /** The Content-Type a host serves the manifest with. */
15
+ export const COMMUNITY_MANIFEST_CONTENT_TYPE = 'application/manifest+json; charset=utf-8'
16
+
17
+ export interface CommunityManifestIcon {
18
+ /** A path on this site. */
19
+ readonly src: string
20
+ /** `192x192`, `512x512`, … */
21
+ readonly sizes: string
22
+ readonly type?: string
23
+ readonly purpose?: 'any' | 'maskable' | 'monochrome' | 'any maskable'
24
+ }
25
+
26
+ export interface CommunityManifestOptions {
27
+ readonly name: string
28
+ readonly shortName?: string
29
+ /** The notification centre: where the installed app opens (a path inside `scope`). */
30
+ readonly startUrl: string
31
+ /** The site's base (default `/`): what the installed app covers. */
32
+ readonly scope?: string
33
+ readonly icons: readonly CommunityManifestIcon[]
34
+ readonly themeColor?: string
35
+ readonly backgroundColor?: string
36
+ /** The manifest's language (`cs`, `en`). */
37
+ readonly lang?: string
38
+ }
39
+
40
+ /** The manifest (W3C Web App Manifest) a host serves. */
41
+ export interface CommunityWebManifest {
42
+ readonly name: string
43
+ readonly short_name: string
44
+ readonly start_url: string
45
+ readonly scope: string
46
+ readonly display: 'standalone'
47
+ readonly icons: ReadonlyArray<{ src: string; sizes: string; type?: string; purpose?: string }>
48
+ readonly theme_color?: string
49
+ readonly background_color?: string
50
+ readonly lang?: string
51
+ }
52
+
53
+ const NAME_MAX = 80
54
+ const SHORT_NAME_MAX = 30
55
+ const COLOR_RE = /^(#[0-9a-fA-F]{3,8}|[a-zA-Z]{3,30}|(rgb|hsl)a?\([0-9.,%\s/]{1,60}\))$/
56
+ const SIZES_RE = /^(any|\d{1,4}x\d{1,4}( \d{1,4}x\d{1,4})*)$/
57
+
58
+ function sitePath(value: unknown, what: string): string {
59
+ if (typeof value !== 'string' || !/^\/(?!\/)[^\s\\]*$/.test(value) || value.length > 512) {
60
+ throw new TypeError(`communityManifest: ${what} must be a path on this site (starting with a single /)`)
61
+ }
62
+ return value
63
+ }
64
+
65
+ function text(value: unknown, max: number, what: string): string {
66
+ if (typeof value !== 'string' || value.trim() === '') throw new TypeError(`communityManifest: ${what} is required`)
67
+ return value.replace(/[\u0000-\u001f\u007f]/g, ' ').trim().slice(0, max)
68
+ }
69
+
70
+ /** The manifest (see the module comment). Throws a TypeError for a path outside the site or a start URL outside the scope. */
71
+ export function communityManifest(options: CommunityManifestOptions): CommunityWebManifest {
72
+ const name = text(options?.name, NAME_MAX, 'name')
73
+ const shortName = options.shortName === undefined ? name.slice(0, SHORT_NAME_MAX) : text(options.shortName, SHORT_NAME_MAX, 'shortName')
74
+ const scopeRaw = sitePath(options.scope ?? '/', 'scope')
75
+ const scope = scopeRaw.endsWith('/') ? scopeRaw : `${scopeRaw}/`
76
+ const startUrl = sitePath(options.startUrl, 'startUrl')
77
+ if (!startUrl.startsWith(scope) && `${startUrl}/` !== scope) throw new TypeError('communityManifest: startUrl must lie inside scope')
78
+ if (!Array.isArray(options.icons) || options.icons.length === 0) throw new TypeError('communityManifest: at least one icon is required')
79
+ const icons = options.icons.map((icon, i) => {
80
+ const src = sitePath(icon?.src, `icons[${i}].src`)
81
+ if (typeof icon.sizes !== 'string' || !SIZES_RE.test(icon.sizes)) throw new TypeError(`communityManifest: icons[${i}].sizes is not a sizes list`)
82
+ return {
83
+ src,
84
+ sizes: icon.sizes,
85
+ ...(typeof icon.type === 'string' && /^image\/[a-z0-9.+-]{1,40}$/.test(icon.type) ? { type: icon.type } : {}),
86
+ ...(icon.purpose ? { purpose: icon.purpose } : {}),
87
+ }
88
+ })
89
+ const color = (value: unknown, what: string): string | undefined => {
90
+ if (value === undefined) return undefined
91
+ if (typeof value !== 'string' || !COLOR_RE.test(value)) throw new TypeError(`communityManifest: ${what} is not a colour`)
92
+ return value
93
+ }
94
+ const themeColor = color(options.themeColor, 'themeColor')
95
+ const backgroundColor = color(options.backgroundColor, 'backgroundColor')
96
+ return {
97
+ name,
98
+ short_name: shortName,
99
+ start_url: startUrl,
100
+ scope,
101
+ display: 'standalone',
102
+ icons,
103
+ ...(themeColor ? { theme_color: themeColor } : {}),
104
+ ...(backgroundColor ? { background_color: backgroundColor } : {}),
105
+ ...(typeof options.lang === 'string' && /^[a-z]{2}(-[A-Za-z0-9]{2,8})?$/.test(options.lang) ? { lang: options.lang } : {}),
106
+ }
107
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * `@handle` mentions in a message body (community M2, slice T8; docs/internal/m2-contracts.md §3.3 "Mentions"): the
3
+ * same token rule kb-api's `services/community/mentions.ts` applies when it notifies the mentioned member, so a page
4
+ * links exactly the handles kb-api counted (test/community/mentions.spec.ts pins the pattern to kb-api's source).
5
+ *
6
+ * A mention is TEXT with a link to the member's profile page (profilePath): the body is split into spans, never
7
+ * parsed as HTML — a page renders each span as a text node (a mention inside an `<a>` whose href profilePath built).
8
+ * Whether a handle names anyone is kb-api's to know; the page links every well-formed one (the profile page answers
9
+ * `notFound` for a handle nobody holds, the same answer as for one hidden from the viewer).
10
+ *
11
+ * Pure: no I/O, no globals.
12
+ */
13
+
14
+ import { COMMUNITY_HANDLE_RE } from './routes'
15
+
16
+ /**
17
+ * One `@handle` token: `@` at the start or after a character that is not a letter, a digit, `_`, `@`, `.` or `/`
18
+ * (so `jana@example.com` and a URL's `/@x` are no mentions), then a handle in any case, not followed by a handle
19
+ * character. Group 1 is the character before the `@`, group 2 the handle as typed. kb-api's MENTION_TOKEN_RE.
20
+ *
21
+ * ⚠️ The regex is global (`/g`, as kb-api's), so `.test()` and `.exec()` on it carry `lastIndex` from one call to the
22
+ * next. Use `communityMentionSpans`, `communityMentionHandles` or `text.matchAll(COMMUNITY_MENTION_RE)` — never
23
+ * `.test`/`.exec` on the shared object.
24
+ */
25
+ export const COMMUNITY_MENTION_RE = /(^|[^A-Za-z0-9_@./])@([A-Za-z0-9][A-Za-z0-9_]{2,29})(?![A-Za-z0-9_])/g
26
+
27
+ /** A piece of a message body: plain text, or a mention (`text` as typed, `@` included; `handle` lower-cased). */
28
+ export type CommunityTextSpan =
29
+ | { readonly kind: 'text'; readonly text: string }
30
+ | { readonly kind: 'mention'; readonly text: string; readonly handle: string }
31
+
32
+ /**
33
+ * The body as spans, in order: the text between mentions and each mention. Joining every span's `text` gives the
34
+ * body back unchanged. A body without a mention is one text span; an empty or absent body, none.
35
+ */
36
+ export function communityMentionSpans(text: string | null | undefined): CommunityTextSpan[] {
37
+ if (typeof text !== 'string' || text === '') return []
38
+ if (!text.includes('@')) return [{ kind: 'text', text }]
39
+ const out: CommunityTextSpan[] = []
40
+ let at = 0
41
+ for (const m of text.matchAll(new RegExp(COMMUNITY_MENTION_RE.source, 'g'))) {
42
+ const typed = m[2]!
43
+ const handle = typed.toLowerCase()
44
+ if (!COMMUNITY_HANDLE_RE.test(handle)) continue
45
+ const start = (m.index ?? 0) + m[1]!.length
46
+ if (start > at) out.push({ kind: 'text', text: text.slice(at, start) })
47
+ out.push({ kind: 'mention', text: `@${typed}`, handle })
48
+ at = start + 1 + typed.length
49
+ }
50
+ if (at < text.length) out.push({ kind: 'text', text: text.slice(at) })
51
+ return out
52
+ }
53
+
54
+ /** The distinct handles a body mentions, lower-cased, in the order they first appear (kb-api's mentionHandles). */
55
+ export function communityMentionHandles(text: string | null | undefined): string[] {
56
+ const out: string[] = []
57
+ for (const span of communityMentionSpans(text)) if (span.kind === 'mention' && !out.includes(span.handle)) out.push(span.handle)
58
+ return out
59
+ }
@@ -34,6 +34,11 @@ export const COMMUNITY_MESSAGES_CS = {
34
34
  'error.surfaceOff': 'Diskuse tu teď není k dispozici.',
35
35
  'error.notMoved': 'Diskusi teď připravujeme. Psát do ní půjde brzy.',
36
36
  'error.ledger': 'Teď se to nepodařilo uložit a všechno zůstalo, jak bylo. Zkuste to prosím znovu.',
37
+ 'error.readOnly': 'Tahle funkce komunity je teď vypnutá. Diskuse pod články běží dál.',
38
+ 'error.braked': 'Psaní je teď na chvíli pozastavené. Číst můžete dál, psát půjde zase brzy.',
39
+ 'error.mentionLimit': 'V jednom příspěvku jste zmínili víc lidí, než zatím jde. Některé zmínky odeberte a pošlete znovu.',
40
+ 'error.pushRefused': 'V tomhle prohlížeči upozornění zapnout nejde. Zkuste jiný prohlížeč, nebo sledujte stránku s upozorněními.',
41
+ 'error.realtimeOff': 'Nové příspěvky se tu teď neukazují hned. Diskuse se obnovuje sama každou chvíli.',
37
42
  'error.submit': 'Nepovedlo se to. Obnovte prosím stránku a zkuste to znovu.',
38
43
 
39
44
  // ── what the composer waits for (need.<Need>) ──
@@ -189,7 +194,13 @@ export const COMMUNITY_MESSAGES_CS = {
189
194
  '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.',
190
195
  'onboarding.art9Title': 'Souhlas se zpracováním',
191
196
  'onboarding.art9Lede': 'Pro psaní do diskuse potřebujeme váš souhlas podle textu níže.',
197
+ // art9Refusal = public_write: the consent is offered, writing in the public discussion does not depend on it (§9.8 q8).
198
+ 'onboarding.art9LedeOptional': 'Prosíme o váš souhlas podle textu níže. Psát ve veřejné diskusi můžete i bez něj.',
192
199
  'onboarding.art9Accept': 'Souhlasím se zpracováním podle textu výše.',
200
+ 'onboarding.art9Controller': 'Souhlas pro {label}',
201
+ 'onboarding.art9Refuse': 'Nesouhlasím',
202
+ 'onboarding.art9RefusedDone': 'Bez tohoto souhlasu můžete psát ve veřejné diskusi.',
203
+ 'onboarding.art9RequiredToWrite': 'Bez souhlasu můžete diskusi jen číst.',
193
204
  'onboarding.profileTitle': 'Jak vás uvidí ostatní',
194
205
  'onboarding.displayName': 'Jméno v diskusi',
195
206
  'onboarding.displayNameHint': 'Může to být i přezdívka. Uvidí ho všichni čtenáři.',
@@ -226,8 +237,8 @@ export const COMMUNITY_MESSAGES_CS = {
226
237
  'panel.statementsEmpty': 'Rozhodnutí o vašem obsahu uvidíte tady.',
227
238
  'panel.reports': 'Moje hlášení',
228
239
  'panel.reportsEmpty': 'Hlášení, která pošlete, uvidíte tady.',
229
- 'panel.notifications': 'Oznámení',
230
- 'panel.notificationsEmpty': 'Nová oznámení uvidíte tady.',
240
+ 'panel.notifications': 'Upozornění',
241
+ 'panel.notificationsEmpty': 'Nová upozornění uvidíte tady.',
231
242
  'panel.unread_one': '{count} nepřečtené oznámení',
232
243
  'panel.unread_few': '{count} nepřečtená oznámení',
233
244
  'panel.unread_many': '{count} nepřečteného oznámení',
@@ -238,9 +249,10 @@ export const COMMUNITY_MESSAGES_CS = {
238
249
  'panel.consents': 'Souhlasy',
239
250
  'panel.art9Given': 'Souhlas se zpracováním je udělený.',
240
251
  'panel.art9NotGiven': 'Souhlas se zpracováním jste zatím nedali.',
252
+ 'panel.art9Refused': 'Souhlas se zpracováním jste odmítli.',
241
253
  'panel.art9Withdraw': 'Odvolat souhlas',
242
254
  'panel.art9WithdrawTitle': 'Odvolat souhlas se zpracováním?',
243
- 'panel.art9WithdrawExplain': 'Diskusi můžete dál číst. Psát do ní půjde, až souhlas zase udělíte.',
255
+ '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.',
244
256
  'panel.art9WithdrawConfirm': 'Ano, odvolat souhlas',
245
257
  'panel.art9WithdrawCancel': 'Ponechat souhlas',
246
258
  'panel.art9Withdrawn': 'Souhlas jste odvolali.',
@@ -317,6 +329,79 @@ export const COMMUNITY_MESSAGES_CS = {
317
329
  'notification.appeal_resolved': 'Vaše odvolání je vyřízené.',
318
330
  'notification.erasure_scheduled': 'Smazání vašeho profilu v diskusi je naplánované.',
319
331
  'notification.inactivity_warning': 'Dlouho jste v diskusi nebyli. Bez další aktivity váš profil po čase smažeme.',
332
+ 'notification.module_read_only': 'Rozšířené funkce komunity jsou vypnuté. Diskuse pod články běží dál; co se pro vás mění, najdete na stránce Moje komunita.',
333
+ 'notification.module_braked': 'Psaní v komunitě je teď pozastavené. Číst můžete dál.',
334
+ 'notification.reply': 'Někdo odpověděl na váš příspěvek.',
335
+ 'notification.mention': 'Někdo vás zmínil v diskusi.',
336
+ 'notification.module_push_reset': 'Upozornění v prohlížeči je potřeba znovu zapnout v nastavení komunity.',
337
+ 'notification.age_limit_changed': 'Komunita je nově jen pro dospělé, váš profil je proto jen ke čtení. Podrobnosti najdete na stránce Moje komunita.',
338
+
339
+ // ── M2 T8: the notification centre (centre.*) and the header badge (badge.*) ──
340
+ 'centre.title': 'Upozornění',
341
+ 'centre.empty': 'Nová upozornění uvidíte tady.',
342
+ 'centre.markAllRead': 'Označit vše jako přečtené',
343
+ 'centre.settings': 'Nastavení upozornění',
344
+ 'centre.loadMore': 'Načíst starší',
345
+ 'centre.unreadOnly': 'Jen nepřečtené',
346
+ 'centre.signIn': 'Upozornění uvidíte po přihlášení.',
347
+ // M2 T10: a reply's or a mention's row links its message on the article page.
348
+ 'centre.openMessage': 'Zobrazit příspěvek',
349
+ 'badge.unread_one': '{count} nové upozornění',
350
+ 'badge.unread_few': '{count} nová upozornění',
351
+ 'badge.unread_many': '{count} nového upozornění',
352
+ 'badge.unread_other': '{count} nových upozornění',
353
+
354
+ // ── M2 T8: the member's settings (settings.*) ──
355
+ 'settings.title': 'Nastavení upozornění',
356
+ 'settings.signIn': 'Nastavení upozornění změníte po přihlášení.',
357
+ 'settings.notifyReply': 'Odpovědi na moje příspěvky',
358
+ 'settings.notifyMention': 'Když mě někdo zmíní',
359
+ 'settings.notifyTopic': 'Novinky v diskusích, které sleduji',
360
+ 'settings.pushEnabled': 'Upozornění v prohlížeči',
361
+ 'settings.digestEmail': 'Denní souhrn e-mailem',
362
+ 'settings.quietHours': 'Noční klid: mezi 22:00 a 7:00 počkají upozornění v prohlížeči do rána.',
363
+ 'settings.saved': 'Uloženo.',
364
+ 'settings.push.enable': 'Zapnout upozornění',
365
+ 'settings.push.disable': 'Vypnout upozornění',
366
+ 'settings.push.carries': 'Upozornění doručuje tento web. Samo upozornění nenese, co přišlo ani od koho.',
367
+ 'settings.push.unsupported': 'Tenhle prohlížeč upozornění neumí. Nové odpovědi a zmínky najdete na stránce s upozorněními.',
368
+ 'settings.push.refused': 'Upozornění se v tomhle prohlížeči zapnout nepodařilo. Zkuste to prosím později nebo v jiném prohlížeči.',
369
+ 'settings.push.denied': 'Upozornění má tenhle prohlížeč pro tento web zablokovaná. Povolit je můžete v nastavení prohlížeče.',
370
+ 'settings.push.inAppExplain': 'V aplikaci Facebooku nebo Instagramu upozornění zapnout nejdou. Otevřete stránku v prohlížeči.',
371
+ 'settings.push.openInBrowser': 'Otevřít v prohlížeči',
372
+ 'settings.push.iosGuide':
373
+ 'Na iPhonu a iPadu fungují upozornění jen u webu přidaného na plochu: v Safari klepněte na Sdílet a zvolte „Přidat na plochu“. Pak web otevřete z plochy a upozornění zapněte.',
374
+ 'settings.push.reset': 'Zapněte si upozornění znovu: nastavení webu se změnilo a dřívější zapnutí přestalo platit.',
375
+ 'settings.digest.prompt': 'Chcete přestat dostávat denní souhrn e-mailem?',
376
+ 'settings.digest.confirm': 'Odhlásit denní souhrn',
377
+ 'settings.digest.unsubscribed': 'Denní souhrn e-mailem jsme vypnuli.',
378
+ 'settings.digest.staleLink': 'Odkaz na odhlášení souhrnu už neplatí. Po přihlášení ho vypnete přepínačem v nastavení.',
379
+
380
+ // ── M2 T8: a member's public profile (profile.*) and the trust level's label (trust.<level>, from trustLabel) ──
381
+ 'profile.memberSince': 'Členem od {date}',
382
+ 'profile.bio': 'O mně',
383
+ 'profile.notFound': 'Tenhle profil jsme nenašli.',
384
+ 'profile.signIn': 'Profily členů uvidíte po přihlášení.',
385
+ 'trust.0': 'Nový člen',
386
+ 'trust.1': 'Člen',
387
+ 'trust.2': 'Stálý člen',
388
+ 'trust.3': 'Moderátor',
389
+
390
+ // ── M2 T8: the welcome page (welcome.*) ──
391
+ 'welcome.title': 'Vítejte v komunitě',
392
+ 'welcome.lede': 'Tady je pár věcí, které se vám na začátku hodí.',
393
+ 'welcome.rules': 'Jak to v diskusi chodí',
394
+ 'welcome.discussions': 'Projít diskuse',
395
+ 'welcome.settings': 'Nastavit upozornění',
396
+ 'welcome.profile': 'Můj profil',
397
+
398
+ // ── M2 T8: the discussion under the module's states ──
399
+ 'realtime.off': 'Živé aktualizace jsou teď vypnuté. Diskuse se sama obnovuje každou chvíli.',
400
+ // `state.readOnly` names what module `read_only` stops (realtime → polling, push; m2-contracts.md §3.1): the
401
+ // discussion stays writable — only a brake (`state.braked`) stops its writes — so the composer stays enabled.
402
+ 'state.readOnly': 'Rozšířené funkce komunity jsou teď vypnuté. Diskuse pod článkem běží dál.',
403
+ 'state.braked': 'Psaní je teď na chvíli pozastavené. Číst můžete dál.',
404
+ 'mention.limit': 'V jednom příspěvku jste zmínili víc lidí, než zatím jde.',
320
405
 
321
406
  // ── the notice form ──
322
407
  'notice.title': 'Nahlásit obsah',
@@ -32,6 +32,11 @@ export const COMMUNITY_MESSAGES_EN = {
32
32
  'error.surfaceOff': "The discussion isn't available here right now.",
33
33
  'error.notMoved': "We're preparing the discussion. You'll be able to write here soon.",
34
34
  'error.ledger': "That couldn't be saved just now, and everything is as it was. Please try again.",
35
+ 'error.readOnly': 'This community feature is switched off for now. The discussions under articles keep working.',
36
+ 'error.braked': 'Writing is paused for a while. You can keep reading, and writing will open again soon.',
37
+ 'error.mentionLimit': 'This post mentions more people than you can mention yet. Remove some of the mentions and send it again.',
38
+ 'error.pushRefused': 'Notifications cannot be switched on in this browser. Try another browser, or keep an eye on the notifications page.',
39
+ 'error.realtimeOff': 'New posts do not show up instantly here right now. The discussion refreshes itself every so often.',
35
40
  'error.submit': "That didn't work. Please reload the page and try again.",
36
41
 
37
42
  'need.sign_in': 'Sign in to write in the discussion.',
@@ -167,7 +172,13 @@ export const COMMUNITY_MESSAGES_EN = {
167
172
  'onboarding.rulesChanged': 'The discussion rules have changed since your last visit. Please read the new version and confirm it.',
168
173
  'onboarding.art9Title': 'Consent to processing',
169
174
  'onboarding.art9Lede': 'To write in the discussion, we need your consent as described below.',
175
+ // art9Refusal = public_write: the consent is offered, writing in the public discussion does not depend on it (§9.8 q8).
176
+ 'onboarding.art9LedeOptional': 'We ask for your consent as described below. You can write in the public discussion without it too.',
170
177
  'onboarding.art9Accept': 'I consent to the processing as described above.',
178
+ 'onboarding.art9Controller': 'Consent for {label}',
179
+ 'onboarding.art9Refuse': 'I do not consent',
180
+ 'onboarding.art9RefusedDone': 'You can write in the public discussion without this consent.',
181
+ 'onboarding.art9RequiredToWrite': 'Without the consent you can only read.',
171
182
  'onboarding.profileTitle': 'How others will see you',
172
183
  'onboarding.displayName': 'Name in the discussion',
173
184
  'onboarding.displayNameHint': 'It can be a nickname. Every reader will see it.',
@@ -212,9 +223,10 @@ export const COMMUNITY_MESSAGES_EN = {
212
223
  'panel.consents': 'Consents',
213
224
  'panel.art9Given': 'Consent to the processing is given.',
214
225
  'panel.art9NotGiven': "You haven't given consent to the processing yet.",
226
+ 'panel.art9Refused': 'You declined the consent to the processing.',
215
227
  'panel.art9Withdraw': 'Withdraw consent',
216
228
  'panel.art9WithdrawTitle': 'Withdraw your consent to the processing?',
217
- 'panel.art9WithdrawExplain': "You can keep reading the discussion. You'll be able to write again once you give the consent again.",
229
+ '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.",
218
230
  'panel.art9WithdrawConfirm': 'Yes, withdraw consent',
219
231
  'panel.art9WithdrawCancel': 'Keep the consent',
220
232
  'panel.art9Withdrawn': "You've withdrawn your consent.",
@@ -289,6 +301,70 @@ export const COMMUNITY_MESSAGES_EN = {
289
301
  'notification.appeal_resolved': 'Your appeal has been resolved.',
290
302
  'notification.erasure_scheduled': 'The deletion of your discussion profile is scheduled.',
291
303
  'notification.inactivity_warning': "You haven't been active in the discussion for a long time. Without further activity, we'll delete your profile after a while.",
304
+ 'notification.module_read_only': "The community's extra features are switched off. The discussions under articles go on; what changes for you is on the My community page.",
305
+ 'notification.module_braked': 'Writing in the community is paused for now. You can keep reading.',
306
+ 'notification.reply': 'Someone replied to your post.',
307
+ 'notification.mention': 'Someone mentioned you in a discussion.',
308
+ 'notification.module_push_reset': 'Browser notifications need to be switched on again in your community settings.',
309
+ 'notification.age_limit_changed': 'The community is now for adults only, so your profile is read-only. The details are on the My community page.',
310
+
311
+ 'centre.title': 'Notifications',
312
+ 'centre.empty': 'New notifications will show here.',
313
+ 'centre.markAllRead': 'Mark all as read',
314
+ 'centre.settings': 'Notification settings',
315
+ 'centre.loadMore': 'Load older',
316
+ 'centre.unreadOnly': 'Unread only',
317
+ 'centre.signIn': 'Sign in to see your notifications.',
318
+ // M2 T10: a reply's or a mention's row links its message on the article page.
319
+ 'centre.openMessage': 'Show the post',
320
+ 'badge.unread_one': '{count} new notification',
321
+ 'badge.unread_other': '{count} new notifications',
322
+
323
+ 'settings.title': 'Notification settings',
324
+ 'settings.signIn': 'Sign in to change your notification settings.',
325
+ 'settings.notifyReply': 'Replies to my posts',
326
+ 'settings.notifyMention': 'When someone mentions me',
327
+ 'settings.notifyTopic': 'News in discussions I follow',
328
+ 'settings.pushEnabled': 'Browser notifications',
329
+ 'settings.digestEmail': 'Daily e-mail summary',
330
+ 'settings.quietHours': 'Quiet hours: between 22:00 and 7:00, browser notifications wait until the morning.',
331
+ 'settings.saved': 'Saved.',
332
+ 'settings.push.enable': 'Turn on notifications',
333
+ 'settings.push.disable': 'Turn off notifications',
334
+ 'settings.push.carries': "This website delivers the notifications. A notification doesn't say what arrived or who it's from.",
335
+ 'settings.push.unsupported': "This browser can't show notifications. You'll find new replies and mentions on the notifications page.",
336
+ 'settings.push.refused': "Notifications couldn't be turned on in this browser. Please try again later or in another browser.",
337
+ 'settings.push.denied': 'This browser blocks notifications for this site. You can allow them in the browser settings.',
338
+ 'settings.push.inAppExplain': "Notifications can't be turned on inside the Facebook or Instagram app. Open the page in your browser.",
339
+ 'settings.push.openInBrowser': 'Open in browser',
340
+ 'settings.push.iosGuide':
341
+ 'On an iPhone or iPad, notifications work only for a site added to the Home Screen: in Safari tap Share and choose “Add to Home Screen”. Then open the site from the Home Screen and turn notifications on.',
342
+ 'settings.push.reset': 'Turn notifications on again: a site setting changed, so the earlier setup no longer works.',
343
+ 'settings.digest.prompt': 'Do you want to stop receiving the daily e-mail summary?',
344
+ 'settings.digest.confirm': 'Stop the daily summary',
345
+ 'settings.digest.unsubscribed': "We've switched off the daily e-mail summary.",
346
+ 'settings.digest.staleLink': 'This unsubscribe link is no longer valid. Sign in to switch the summary off in the settings.',
347
+
348
+ 'profile.memberSince': 'Member since {date}',
349
+ 'profile.bio': 'About me',
350
+ 'profile.notFound': "We couldn't find this profile.",
351
+ 'profile.signIn': "Sign in to see members' profiles.",
352
+ 'trust.0': 'New member',
353
+ 'trust.1': 'Member',
354
+ 'trust.2': 'Regular',
355
+ 'trust.3': 'Moderator',
356
+
357
+ 'welcome.title': 'Welcome to the community',
358
+ 'welcome.lede': 'Here are a few things that help at the start.',
359
+ 'welcome.rules': 'How the discussion works',
360
+ 'welcome.discussions': 'Browse the discussions',
361
+ 'welcome.settings': 'Set up notifications',
362
+ 'welcome.profile': 'My profile',
363
+
364
+ 'realtime.off': 'Live updates are off right now. The discussion refreshes itself every so often.',
365
+ 'state.readOnly': "The community's extra features are switched off for now. The discussion under the article goes on.",
366
+ 'state.braked': 'Writing is paused for a while. You can keep reading.',
367
+ 'mention.limit': 'This post mentions more people than you can mention yet.',
292
368
 
293
369
  'notice.title': 'Report content',
294
370
  'notice.lede': 'You can report a comment, a profile or an article, even without signing in.',
@@ -11,6 +11,7 @@
11
11
 
12
12
  import { COMMUNITY_MESSAGES_CS } from './messages.cs'
13
13
  import { COMMUNITY_MESSAGES_EN } from './messages.en'
14
+ import { NOTIFICATION_CODES, TRUST_LABELS } from './shapes'
14
15
 
15
16
  type PluralCategory = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other'
16
17
  type BaseKey<K extends string> = K extends `${infer Base}_${PluralCategory}` ? Base : K
@@ -110,3 +111,21 @@ export function noteMessageKey(code: string): CommunityMessageKey | null {
110
111
  const key = `note.${code}`
111
112
  return hasCommunityMessage(key) ? key : null
112
113
  }
114
+
115
+ /**
116
+ * The sentence of a notification in the centre (`notification.<code>`), or null for a code this SDK has no text for
117
+ * (a newer kb-api's: skip the row's sentence, never show the code). The sentence names no member and quotes nothing:
118
+ * the page links the subject.
119
+ */
120
+ export function notificationMessageKey(code: string): CommunityMessageKey | null {
121
+ return (NOTIFICATION_CODES as readonly string[]).includes(code) ? (`notification.${code}` as CommunityMessageKey) : null
122
+ }
123
+
124
+ /**
125
+ * The label of a public trust level (`profile/get`'s `trustLabel`, m2-contracts.md §3.2, §3.10): `trust.0` „Nový člen"
126
+ * … `trust.3` „Moderátor" — a label, never the number. Null for a label this SDK does not know (show no label).
127
+ */
128
+ export function trustLabelMessageKey(label: string | null | undefined): CommunityMessageKey | null {
129
+ const level = typeof label === 'string' ? (TRUST_LABELS as readonly string[]).indexOf(label) : -1
130
+ return level < 0 ? null : (`trust.${level}` as CommunityMessageKey)
131
+ }