@blogmcp/sdk 0.10.1 → 0.11.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 (53) hide show
  1. package/dist/community/channels.d.ts +3 -2
  2. package/dist/community/client.d.ts +129 -2
  3. package/dist/community/client.js +231 -161
  4. package/dist/community/forum.d.ts +82 -0
  5. package/dist/community/forum.js +96 -0
  6. package/dist/community/index.d.ts +14 -7
  7. package/dist/community/index.js +185 -121
  8. package/dist/community/links.d.ts +38 -0
  9. package/dist/community/links.js +98 -71
  10. package/dist/community/messages.cs.d.ts +160 -1
  11. package/dist/community/messages.cs.js +178 -1
  12. package/dist/community/messages.d.ts +19 -1
  13. package/dist/community/messages.en.d.ts +150 -1
  14. package/dist/community/messages.en.js +161 -1
  15. package/dist/community/messages.js +37 -28
  16. package/dist/community/outcome.d.ts +8 -3
  17. package/dist/community/outcome.js +61 -20
  18. package/dist/community/poll.d.ts +28 -4
  19. package/dist/community/poll.js +70 -47
  20. package/dist/community/realtime/index.d.ts +19 -3
  21. package/dist/community/realtime/index.js +175 -145
  22. package/dist/community/routes.d.ts +36 -1
  23. package/dist/community/routes.js +51 -21
  24. package/dist/community/server/bff.d.ts +25 -2
  25. package/dist/community/server/bff.js +135 -118
  26. package/dist/community/server/host-routes.d.ts +3 -0
  27. package/dist/community/server/host-routes.js +17 -0
  28. package/dist/community/server/index.d.ts +5 -1
  29. package/dist/community/shapes.d.ts +634 -7
  30. package/dist/community/shapes.js +92 -61
  31. package/dist/community/store.d.ts +15 -0
  32. package/dist/community/store.js +65 -61
  33. package/dist/community/topic.d.ts +173 -0
  34. package/dist/community/topic.js +225 -0
  35. package/package.json +3 -3
  36. package/src/community/channels.ts +3 -2
  37. package/src/community/client.ts +209 -5
  38. package/src/community/forum.ts +209 -0
  39. package/src/community/index.ts +146 -2
  40. package/src/community/links.ts +64 -4
  41. package/src/community/messages.cs.ts +179 -1
  42. package/src/community/messages.en.ts +162 -1
  43. package/src/community/messages.ts +25 -2
  44. package/src/community/outcome.ts +47 -1
  45. package/src/community/poll.ts +79 -17
  46. package/src/community/realtime/index.ts +124 -48
  47. package/src/community/routes.ts +42 -1
  48. package/src/community/server/bff.ts +89 -30
  49. package/src/community/server/host-routes.ts +20 -0
  50. package/src/community/server/index.ts +5 -1
  51. package/src/community/shapes.ts +662 -6
  52. package/src/community/store.ts +11 -5
  53. package/src/community/topic.ts +521 -0
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * What the community's operations answer (docs/internal/m1-contracts.md §7.3, §7.4, §7.7, §8.3) — the shapes of
3
- * kb-api's `routes/community-public.ts` and `routes/trust-notices.ts`, as types.
3
+ * kb-api's `routes/community-public.ts` and `routes/trust-notices.ts`, as types. M3 (m3-contracts.md §3.2–§3.5,
4
+ * §5.2): the forum's categories, topics, search, follows and a category moderator's queue and package.
4
5
  *
5
6
  * The enums a newer kb-api may extend are OPEN (community.md §3.7: the client is shaped so later surfaces add on
6
7
  * without breaking it): a message's `state`, an author's `kind`, a `need`, a restriction's `kind` and a
@@ -54,6 +55,10 @@ export const NOTIFICATION_CODES = Object.freeze([
54
55
  'mention',
55
56
  'module_push_reset',
56
57
  'age_limit_changed',
58
+ // M3 F3 (m3-contracts.md §4.3): a new visible message in a followed topic or article discussion; a new topic in a
59
+ // followed category (in-app and the digest, never push). Both switched by `notifyTopic`.
60
+ 'topic_update',
61
+ 'category_topic',
57
62
  ] as const)
58
63
  export type KnownNotificationCode = (typeof NOTIFICATION_CODES)[number]
59
64
  export type NotificationCode = Open<KnownNotificationCode>
@@ -95,6 +100,26 @@ export const isCaseCategory = (value: unknown): value is CaseCategory => has(CAS
95
100
  /** The one category whose notice never carries a notifier's name or e-mail (kb-api: NOTIFIER_NOT_ALLOWED). */
96
101
  export const CATEGORY_WITHOUT_NOTIFIER: CaseCategory = 'child_at_risk'
97
102
 
103
+ /**
104
+ * The categories of the illegal line — every report category but the rules line's four (`rules`, `adverse_event`,
105
+ * `third_party_health_data`, `suspected_minor`: kb-api's `lineOf`, which test/community/codes-drift.spec.ts reads) — in
106
+ * CASE_CATEGORIES' order: what a category moderator escalates to the team (`moderation/escalate`, m3-contracts.md §3.4;
107
+ * D-M3-6 „illegal-line cases escalate only").
108
+ */
109
+ export const ESCALATION_CATEGORIES: readonly CaseCategory[] = Object.freeze(
110
+ CASE_CATEGORIES.filter((c) => c !== 'rules' && c !== 'adverse_event' && c !== 'third_party_health_data' && c !== 'suspected_minor'),
111
+ )
112
+
113
+ /**
114
+ * M3 (m3-contracts.md §3.5, §4.7, D-M3-10): what the team recorded on an adverse-event case — `recorded` (in its
115
+ * register), `reported_to_authority`, `not_adverse` (kb-api's ADVERSE_EVENT_OUTCOMES, pinned by codes-drift). Open: an
116
+ * outcome a newer kb-api adds reads as none (show the case's status alone).
117
+ */
118
+ export const ADVERSE_EVENT_OUTCOMES = Object.freeze(['recorded', 'reported_to_authority', 'not_adverse'] as const)
119
+ export type KnownAdverseEventOutcome = (typeof ADVERSE_EVENT_OUTCOMES)[number]
120
+ export type AdverseEventOutcome = Open<KnownAdverseEventOutcome>
121
+ export const isKnownAdverseEventOutcome = (outcome: unknown): outcome is KnownAdverseEventOutcome => has(ADVERSE_EVENT_OUTCOMES, outcome)
122
+
98
123
  export const AGE_BANDS = Object.freeze(['16_17', '18_plus'] as const)
99
124
  export type AgeBand = (typeof AGE_BANDS)[number]
100
125
 
@@ -112,6 +137,11 @@ export interface MemberAuthor {
112
137
  readonly displayName: string
113
138
  readonly avatarPreset: string | null
114
139
  readonly deleted?: undefined
140
+ /**
141
+ * M3 (m3-contracts.md §3.5, §4.5): `true` on a member's message in a topic of a category the member moderates now —
142
+ * show „Moderátor" (`role.moderator`) beside it there, and nowhere else. Absent otherwise (and from an older kb-api).
143
+ */
144
+ readonly moderator?: true
115
145
  }
116
146
 
117
147
  /** An erased member, a member without a profile, and every placeholder: the author is not told. */
@@ -198,6 +228,12 @@ export interface PublicMessage {
198
228
  * nothing is being reviewed, the author's consent releases it.
199
229
  */
200
230
  readonly hiddenUntilConsent?: boolean
231
+ /**
232
+ * M3 (m3-contracts.md §4.2): `true` on the author's OWN message that waits in a category's pre-moderation queue —
233
+ * its `state` is then `held` („čeká na kontrolu", `state.held`). Nothing was restricted: an approval publishes it
234
+ * without a statement, a rejection is a decision with one. Never on anyone else's row: others see nothing of it.
235
+ */
236
+ readonly premoderated?: boolean
201
237
  /** On a top-level message: its replies, oldest first. */
202
238
  readonly replies: readonly PublicMessage[]
203
239
  /** On a top-level message with more replies than COMMUNITY_REPLIES_MAX. */
@@ -256,6 +292,8 @@ export interface WriteAnswer {
256
292
  readonly message: PublicMessage
257
293
  /** The codes that hit with action `warn` (the message is visible). */
258
294
  readonly warnings: readonly string[]
295
+ /** M3: `messages/edit` with a `title` (a topic's opening post): the topic with its new title. */
296
+ readonly topic?: Topic
259
297
  }
260
298
 
261
299
  /** A reaction's target: the article, or one message. */
@@ -280,6 +318,13 @@ export interface PublicProfile {
280
318
  * (no level is computed then).
281
319
  */
282
320
  readonly trustLabel?: TrustLabel
321
+ /**
322
+ * M3 (m3-contracts.md §3.5, §4.5): the listed categories the member moderates now — appointments that act now (TL3,
323
+ * a preset that admits member moderators); „Moderátor" (`role.moderator`) on the profile names an appointment, never
324
+ * a trust level (D-M3-7). kb-api sends it only to a viewer the forum admits (an onboarded member, the team at the
325
+ * keyboard): absent for anyone else, and from a kb-api older than M3 — so its absence says nothing.
326
+ */
327
+ readonly moderates?: readonly ForumCategoryRef[]
283
328
  }
284
329
 
285
330
  /** The member's own profile (MyState, `me/profile/update`). */
@@ -309,6 +354,49 @@ export interface ModuleInfo {
309
354
  /** The pause in effect, whatever the state (a tenant without the module may pause its discussions). */
310
355
  readonly brake?: { readonly kind: string; readonly until?: string; readonly reasonCode: string }
311
356
  readonly features: { readonly realtime: boolean; readonly push: boolean; readonly notifications: boolean; readonly profiles: boolean }
357
+ /**
358
+ * M3 (m3-contracts.md §3.5, §4.9): each public surface's switch and its own brake (beside the module's `brake`, which
359
+ * stops both). Absent from a kb-api older than M3 — read it through surfaceInfoOf.
360
+ */
361
+ readonly surfaces?: ModuleSurfaces
362
+ /**
363
+ * M3 (§4.8, D-M3-9): the team's away mode („nepřítomen") until when, or null — new topics wait for review meanwhile
364
+ * (`state.away`). Absent from a kb-api older than M3 — read it through communityAwayOf.
365
+ */
366
+ readonly away?: CommunityAway | null
367
+ }
368
+
369
+ /**
370
+ * The brake of one surface (M3 §2.3, §4.9): set by the team (≤ 24 h, `tenant`) or by the automatic brake (`auto`); it
371
+ * always ends (`until`, the database's CHECK). It pauses that surface's member writes only — the other surface works
372
+ * (BRAKED `{ surface }`, brakedSurfaceOf) — while the module's own `brake` pauses both.
373
+ */
374
+ export interface SurfaceBrake {
375
+ /** `tenant` | `auto` (an open set). */
376
+ readonly kind: string
377
+ readonly until: string
378
+ readonly reasonCode: string
379
+ }
380
+
381
+ /** One surface as `me/get` reports it (M3 §3.5): switched on, and its brake in effect (null: none). */
382
+ export interface SurfaceInfo {
383
+ readonly enabled: boolean
384
+ readonly brake: SurfaceBrake | null
385
+ }
386
+
387
+ /** MyState's `module.surfaces` (M3 §3.5): the forum and the article discussions; open groups (M5a) may join. */
388
+ export interface ModuleSurfaces {
389
+ readonly forum: SurfaceInfo
390
+ readonly articleDiscussions: SurfaceInfo
391
+ }
392
+
393
+ /**
394
+ * MyState's `module.away` (M3 §4.8, D-M3-9): the team is away until then (at most 14 days ahead) — new topics wait for
395
+ * review and every flagged message is held meanwhile; me/get carries it for anonymous viewers too. The elements say so
396
+ * in one sentence (`state.away`, read through communityAwayOf).
397
+ */
398
+ export interface CommunityAway {
399
+ readonly until: string
312
400
  }
313
401
 
314
402
  /**
@@ -375,6 +463,17 @@ export interface MyState {
375
463
  * Absent from a kb-api older than T10.
376
464
  */
377
465
  readonly caps?: MemberCaps
466
+ /**
467
+ * M3 (m3-contracts.md §3.5, §4.5, D-M3-6): the categories the member moderates now — active appointments that act
468
+ * (TL3, a preset that admits member moderators); null for everyone else. Absent from a kb-api older than M3. Read
469
+ * it through isCategoryModerator; the moderator's operations re-check it on every call (NOT_FOUND otherwise).
470
+ */
471
+ readonly moderator?: ModeratorInfo | null
472
+ }
473
+
474
+ /** MyState's `moderator` (M3): the categories the member moderates, by id. */
475
+ export interface ModeratorInfo {
476
+ readonly categoryIds: readonly string[]
378
477
  }
379
478
 
380
479
  /** MyState's `caps` (M2 T10). */
@@ -383,8 +482,10 @@ export interface MemberCaps {
383
482
  }
384
483
 
385
484
  /**
386
- * The member's notification switches (m2-contracts.md §3.3): replies, mentions, topic updates (off by default),
387
- * push (the master switch), the daily e-mail digest, the night's quiet hours for push (22–7, the site's time).
485
+ * The member's notification switches (m2-contracts.md §3.3): replies, mentions, topic updates, push (the master
486
+ * switch), the daily e-mail digest, the night's quiet hours for push (22–7, the site's time). M3 (m3-contracts.md §4.3,
487
+ * D-M3-4): `notifyTopic` switches `topic_update` and `category_topic`, and is on for a member who never set it (a
488
+ * follow is the opt-in); a switch the member saved keeps its value.
388
489
  */
389
490
  export interface MemberSettings {
390
491
  readonly notifyReply: boolean
@@ -488,6 +589,9 @@ export interface NotificationListInput {
488
589
  readonly codes?: readonly string[]
489
590
  }
490
591
 
592
+ /** M3 FX (R20): what a notification row's conversation is (an open enum: a newer kb-api may name another kind). */
593
+ export type NotificationConversationKind = 'topic' | 'article' | (string & {})
594
+
491
595
  export interface NotificationItem {
492
596
  readonly id: string
493
597
  readonly code: NotificationCode
@@ -497,10 +601,20 @@ export interface NotificationItem {
497
601
  /**
498
602
  * M2 T10: the article of the conversation a `reply` or `mention` row is about, else null (absent from a kb-api
499
603
  * older than T10). With `articleSlug` and `seq`, a page links the message on the article (communityMessageLink).
604
+ * M3 F3: also a `topic_update` of a followed article discussion and a `category_topic` of the „Články" category (a
605
+ * discussion new to its listing); a topic's row names no article — its link is `conversationId` (topicPath). Null too
606
+ * while the article is not readable at the viewer's level.
500
607
  */
501
608
  readonly articleId?: string | null
502
609
  /** M2 T10: that article's slug (never its title), else null; absent from a kb-api older than T10. */
503
610
  readonly articleSlug?: string | null
611
+ /**
612
+ * M3 FX (the review of wave 1, R20): the kind of the row's conversation — `topic` (link a `reply`, `mention` or
613
+ * `topic_update` with topicMessageLink, a `category_topic` with topicPath) or `article` (its article's page while
614
+ * `articleId` names it; one no longer readable is still an article's row, never a topic's) —, null for a row of no
615
+ * public conversation (a decision, a notice of the module). Absent from a kb-api older than M3's FX.
616
+ */
617
+ readonly conversationKind?: NotificationConversationKind | null
504
618
  readonly caseId: string | null
505
619
  readonly decisionId: string | null
506
620
  readonly createdAt: string
@@ -571,7 +685,14 @@ export interface ReportItem {
571
685
  readonly category: string
572
686
  readonly status: string
573
687
  readonly reportedAt: string
688
+ /** The last decision's time; M3: a case closed by an adverse-event outcome alone takes the outcome's (§3.5). */
574
689
  readonly decidedAt: string | null
690
+ /**
691
+ * M3 (m3-contracts.md §3.5, §4.7): an adverse-event case's outcome once the team recorded one (ADVERSE_EVENT_OUTCOMES,
692
+ * an open set), else null — the member reporter learns the result here, as M1 tells it a decision (adverseOutcome.<…>).
693
+ * Absent from a kb-api older than M3.
694
+ */
695
+ readonly outcome?: AdverseEventOutcome | null
575
696
  }
576
697
 
577
698
  /** `legal/current`: the tenant's current text of a kind. */
@@ -702,9 +823,18 @@ export interface NoticeStatus {
702
823
  readonly status: 'open' | 'decided' | 'appealed' | 'closed' | (string & {})
703
824
  readonly category: CaseCategory
704
825
  readonly submittedAt: string
826
+ /** The last decision's time; M3: a case closed by an adverse-event outcome alone takes the outcome's (§3.5). */
705
827
  readonly decidedAt: string | null
706
828
  /** The statement once decided (plain text), never the package. */
707
829
  readonly statement: string | null
830
+ /**
831
+ * M3 (m3-contracts.md §3.5, §4.7): an adverse-event case's outcome once the team recorded one (ADVERSE_EVENT_OUTCOMES,
832
+ * an open set), else null. A case closed by its outcome alone has no decision: `status` `closed`, `decidedAt` the
833
+ * outcome's time, `statement` null and `appeal.canAppeal` false — the page states the outcome in plain words
834
+ * (adverseOutcome.<…>) with the redress line (`notice.redress`), as the e-mail `notice_closed` does. Absent from a
835
+ * kb-api older than M3.
836
+ */
837
+ readonly outcome?: AdverseEventOutcome | null
708
838
  readonly appeal: {
709
839
  readonly canAppeal: boolean
710
840
  readonly closesAt: string | null
@@ -722,10 +852,10 @@ export interface DiscussionListInput {
722
852
  cursor?: number | null
723
853
  }
724
854
 
725
- export interface MessagePostInput {
726
- articleId: string
855
+ /** What every post carries, wherever it goes. */
856
+ export interface MessagePostFields {
727
857
  body: string
728
- /** A reply names a top-level message of the same discussion. */
858
+ /** A reply names a top-level message of the same discussion or topic. */
729
859
  replyToSeq?: number | null
730
860
  /** newClientMsgId(), the same on a retry. */
731
861
  clientMsgId: string
@@ -735,10 +865,33 @@ export interface MessagePostInput {
735
865
  confirmations?: string[]
736
866
  }
737
867
 
868
+ /** A post under an article: its discussion, by the article (created with the first message). */
869
+ export interface ArticleMessagePostInput extends MessagePostFields {
870
+ articleId: string
871
+ conversationId?: never
872
+ }
873
+
874
+ /**
875
+ * M3 (m3-contracts.md §3.3): a post into a forum topic, by the topic's conversation id. An article discussion is still
876
+ * posted to by `articleId` (Appendix B, choice 3) — kb-api refuses a `conversationId` that names one.
877
+ */
878
+ export interface TopicMessagePostInput extends MessagePostFields {
879
+ conversationId: string
880
+ articleId?: never
881
+ }
882
+
883
+ /** `messages/post`: exactly one of `articleId` and `conversationId`. */
884
+ export type MessagePostInput = ArticleMessagePostInput | TopicMessagePostInput
885
+
738
886
  export interface MessageEditInput {
739
887
  conversationId: string
740
888
  seq: number
741
889
  body: string
890
+ /**
891
+ * M3 (§3.3): a topic's new title (≤ COMMUNITY_TOPIC_TITLE_MAX) — only on its opening post (`seq` 1) by its author,
892
+ * else VALIDATION on `title`. The title and the body are filtered as one text.
893
+ */
894
+ title?: string
742
895
  confirmations?: string[]
743
896
  }
744
897
 
@@ -792,3 +945,506 @@ export interface NoticeSubmitInput {
792
945
  /** Must contain COMMUNITY_GOOD_FAITH. */
793
946
  confirmations?: string[]
794
947
  }
948
+
949
+ // ───────────────────────── the forum (M3, m3-contracts.md §1.1, §3.2–§3.5, §5.2) ─────────────────────────
950
+
951
+ /** A category's kind: members or the team open topics in it, or it lists the article discussions (D-M3-13 „Články"). */
952
+ export const FORUM_CATEGORY_KINDS = Object.freeze(['topics', 'article_discussions'] as const)
953
+ export type KnownForumCategoryKind = (typeof FORUM_CATEGORY_KINDS)[number]
954
+ export type ForumCategoryKind = Open<KnownForumCategoryKind>
955
+ export const isKnownForumCategoryKind = (kind: unknown): kind is KnownForumCategoryKind => has(FORUM_CATEGORY_KINDS, kind)
956
+
957
+ /**
958
+ * A category's mode (§4.1): `post` M1's pipeline, `hold_flagged` a flagged text is held, `pre` every post waits for
959
+ * review. The category's own mode — away mode raises it for every write meanwhile (MyState `module.away`).
960
+ */
961
+ export const FORUM_CATEGORY_MODES = Object.freeze(['post', 'hold_flagged', 'pre'] as const)
962
+ export type KnownForumCategoryMode = (typeof FORUM_CATEGORY_MODES)[number]
963
+ export type ForumCategoryMode = Open<KnownForumCategoryMode>
964
+ export const isKnownForumCategoryMode = (mode: unknown): mode is KnownForumCategoryMode => has(FORUM_CATEGORY_MODES, mode)
965
+
966
+ /** Who opens topics in a category: its members, or only the team (TOPIC_CREATION_CLOSED for a member). */
967
+ export const TOPIC_CREATIONS = Object.freeze(['members', 'team'] as const)
968
+ export type KnownTopicCreation = (typeof TOPIC_CREATIONS)[number]
969
+ export type TopicCreation = Open<KnownTopicCreation>
970
+
971
+ /**
972
+ * A topic's state (§1.1): `open`; `locked` — no new message (reading, reactions on what is there and reports go on);
973
+ * `archived` — locked and out of the default list. An unknown state reads as locked: offer no composer.
974
+ */
975
+ export const TOPIC_STATES = Object.freeze(['open', 'locked', 'archived'] as const)
976
+ export type KnownTopicState = (typeof TOPIC_STATES)[number]
977
+ export type TopicState = Open<KnownTopicState>
978
+ export const isKnownTopicState = (state: unknown): state is KnownTopicState => has(TOPIC_STATES, state)
979
+
980
+ /** What one row of a category's list is: a topic, or (in the „Články" category) an article's discussion. */
981
+ export const TOPIC_ITEM_KINDS = Object.freeze(['topic', 'article'] as const)
982
+ export type KnownTopicItemKind = (typeof TOPIC_ITEM_KINDS)[number]
983
+ export type TopicItemKind = Open<KnownTopicItemKind>
984
+
985
+ /**
986
+ * How `forum/topics/list` orders a category (closed: kb-api validates it): by the latest activity (pinned topics
987
+ * first) or the newest first. There is no sort by reactions, votes or score in v1, for any tenant (§4.6).
988
+ */
989
+ export const FORUM_SORTS = Object.freeze(['activity', 'new'] as const)
990
+ export type ForumSort = (typeof FORUM_SORTS)[number]
991
+
992
+ /** Where a message lives: a forum topic or an article's discussion (`forum/search`, `me/follows/list`). */
993
+ export const FORUM_SPACES = Object.freeze(['forum', 'article'] as const)
994
+ export type KnownForumSpace = (typeof FORUM_SPACES)[number]
995
+ export type ForumSpace = Open<KnownForumSpace>
996
+
997
+ /** A search hit: a topic's title, or a message. */
998
+ export const SEARCH_RESULT_KINDS = Object.freeze(['topic', 'message'] as const)
999
+ export type KnownSearchResultKind = (typeof SEARCH_RESULT_KINDS)[number]
1000
+ export type SearchResultKind = Open<KnownSearchResultKind>
1001
+
1002
+ /** What a member follows: a conversation (a topic or an article discussion) or a category. */
1003
+ export const FOLLOW_TARGET_KINDS = Object.freeze(['conversation', 'category'] as const)
1004
+ export type KnownFollowTargetKind = (typeof FOLLOW_TARGET_KINDS)[number]
1005
+ export type FollowTargetKind = Open<KnownFollowTargetKind>
1006
+
1007
+ /**
1008
+ * The surface a BRAKED refusal names (M3 §1.2, §4.9): its own brake stopped the write — the other surface works.
1009
+ * Absent from the refusal: the module's brake, which stops both. Open: open groups (M5a) will be a third.
1010
+ */
1011
+ export const BRAKE_SURFACES = Object.freeze(['forum', 'article_discussions'] as const)
1012
+ export type KnownBrakeSurface = (typeof BRAKE_SURFACES)[number]
1013
+ export type BrakeSurface = Open<KnownBrakeSurface>
1014
+ export const isKnownBrakeSurface = (surface: unknown): surface is KnownBrakeSurface => has(BRAKE_SURFACES, surface)
1015
+
1016
+ /** A moderator's queue row: an open case, or a message waiting in pre-moderation. */
1017
+ export const MODERATION_ITEM_KINDS = Object.freeze(['case', 'premod'] as const)
1018
+ export type KnownModerationItemKind = (typeof MODERATION_ITEM_KINDS)[number]
1019
+ export type ModerationItemKind = Open<KnownModerationItemKind>
1020
+
1021
+ /**
1022
+ * A queued case's status (§3.4): `open`, or `decided` — a case a `system` decision already decided that still holds
1023
+ * its message (a filter hold is decided at birth; the moderator restores or removes it). Open: a status a newer kb-api
1024
+ * adds reads as `open`.
1025
+ */
1026
+ export const MODERATION_CASE_STATUSES = Object.freeze(['open', 'decided'] as const)
1027
+ export type KnownModerationCaseStatus = (typeof MODERATION_CASE_STATUSES)[number]
1028
+ export type ModerationCaseStatus = Open<KnownModerationCaseStatus>
1029
+
1030
+ /** Where a moderator's case came from (§3.4): a member's report, the filters or the provider's own initiative. */
1031
+ export const MODERATION_SOURCES = Object.freeze(['member_report', 'filter', 'staff'] as const)
1032
+ export type KnownModerationSource = (typeof MODERATION_SOURCES)[number]
1033
+ export type ModerationSource = Open<KnownModerationSource>
1034
+
1035
+ /** What a category moderator may decide (§4.5; closed: anything else is UNSUPPORTED_RESTRICTION). */
1036
+ export const MODERATION_RESTRICTIONS = Object.freeze(['no_action', 'visibility_restricted', 'removal'] as const)
1037
+ export type ModerationRestriction = (typeof MODERATION_RESTRICTIONS)[number]
1038
+
1039
+ /** A moderator's decision's basis: a notice (a report) or the provider's own initiative. */
1040
+ export const MODERATION_BASES = Object.freeze(['notice', 'own_initiative'] as const)
1041
+ export type ModerationBasis = (typeof MODERATION_BASES)[number]
1042
+
1043
+ /** The states a moderator sets (archiving is the team's). */
1044
+ export const MODERATOR_TOPIC_STATES = Object.freeze(['open', 'locked'] as const)
1045
+ export type ModeratorTopicState = (typeof MODERATOR_TOPIC_STATES)[number]
1046
+
1047
+ /** A pre-moderation review: publish (no statement), or refuse (a removal with its statement). */
1048
+ export const PREMOD_OUTCOMES = Object.freeze(['approve', 'reject'] as const)
1049
+ export type PremodOutcome = (typeof PREMOD_OUTCOMES)[number]
1050
+
1051
+ /** A category as a topic, a profile or a follow names it. */
1052
+ export interface ForumCategoryRef {
1053
+ readonly slug: string
1054
+ readonly name: string
1055
+ }
1056
+
1057
+ /** `forum/categories/list`: one listed category (the team's hidden ones never reach a member). */
1058
+ export interface ForumCategory extends ForumCategoryRef {
1059
+ readonly id: string
1060
+ /** Plain text: render it as text. */
1061
+ readonly description: string | null
1062
+ readonly kind: ForumCategoryKind
1063
+ readonly topicCreation: TopicCreation
1064
+ /**
1065
+ * The category's own mode (§4.1) — null for the article discussions' category („Články"), which has none (§2.1: M1's
1066
+ * pipeline with the preset's rules). Never away mode's raise: MyState `module.away` says that.
1067
+ */
1068
+ readonly mode: ForumCategoryMode | null
1069
+ readonly position: number
1070
+ /** The topics (in „Články": the article discussions) another member sees listed (§3.1's rule). */
1071
+ readonly topicCount: number
1072
+ readonly lastActivityAt: string | null
1073
+ /** The viewer follows the category (its new topics notify them). */
1074
+ readonly following: boolean
1075
+ /**
1076
+ * The category's moderators — the appointments that act now (TL3, a preset that admits member moderators; none under
1077
+ * the regulated preset, and none until category moderators exist): as members' messages name them.
1078
+ */
1079
+ readonly moderators: readonly Author[]
1080
+ }
1081
+
1082
+ /** A topic's row in its category's list (a topic is listed to a viewer exactly when `forum/topics/get` answers it). */
1083
+ export interface ForumTopicItem {
1084
+ readonly kind: 'topic'
1085
+ readonly conversationId: string
1086
+ /**
1087
+ * null when the viewer may not see it (§3.1's placeholder rule: the opening post is held, removed or held back, and a
1088
+ * reply keeps the topic readable) and once the opening post is deleted — topicTitleOf tells the two apart by
1089
+ * `openingState`: „Smazané téma" (`topic.deleted`) for `deleted` only, the withheld wording (`topic.withheld`)
1090
+ * otherwise. `author` is then the placeholder author.
1091
+ */
1092
+ readonly title: string | null
1093
+ readonly author: Author
1094
+ readonly state: TopicState
1095
+ readonly pinned: boolean
1096
+ /** The messages everyone is shown. */
1097
+ readonly count: number
1098
+ readonly createdAt: string
1099
+ readonly lastActivityAt: string
1100
+ readonly following: boolean
1101
+ /**
1102
+ * The opening post's state as the viewer sees it, whenever it is not `visible`: on the viewer's own topic `held` (also
1103
+ * while it waits for review: „čeká na kontrolu"); on another member's topic the placeholder's state — `held`,
1104
+ * `removed` or `deleted`. Absent when visible.
1105
+ */
1106
+ readonly openingState?: MessageState
1107
+ }
1108
+
1109
+ /** An article's discussion in the „Články" category's list (articles the viewer may read). */
1110
+ export interface ForumArticleItem {
1111
+ readonly kind: 'article'
1112
+ readonly conversationId: string
1113
+ readonly articleId: string
1114
+ /**
1115
+ * M3 FX (the review of wave 1, R20): what the row's link needs — the article's slug (its filename without `.md`/`.mdx`),
1116
+ * as `ForumSearchResult.articleSlug`: the host's `articlePath` filled with it (communityArticleLink).
1117
+ */
1118
+ readonly articleSlug: string
1119
+ readonly articleTitle: string | null
1120
+ readonly count: number
1121
+ readonly lastActivityAt: string
1122
+ readonly following: boolean
1123
+ }
1124
+
1125
+ /** A row of a kind a newer kb-api added: skip it. */
1126
+ export interface UnknownTopicItem {
1127
+ readonly kind: string & {}
1128
+ }
1129
+
1130
+ export type KnownTopicItem = ForumTopicItem | ForumArticleItem
1131
+ export type TopicItem = KnownTopicItem | UnknownTopicItem
1132
+
1133
+ /** `forum/topics/list`: one keyset page of a category (the cursor is opaque). */
1134
+ export interface ForumTopicsPage {
1135
+ readonly category: { readonly id: string; readonly slug: string; readonly name: string; readonly kind: ForumCategoryKind }
1136
+ readonly items: readonly TopicItem[]
1137
+ readonly nextCursor: string | null
1138
+ }
1139
+
1140
+ /** A topic's header (`forum/topics/get`, a new topic, a title edit, a moderator's change). */
1141
+ export interface Topic {
1142
+ readonly conversationId: string
1143
+ readonly category: { readonly id: string; readonly slug: string; readonly name: string }
1144
+ /**
1145
+ * null when §3.1's placeholder rule withholds it from the viewer (the opening post held, removed or held back; a
1146
+ * reply keeps the topic readable) and once the opening post is deleted — topicTitleOf tells the two apart by the
1147
+ * opening post's state. A re-read (a resync) may bring a withheld title back.
1148
+ */
1149
+ readonly title: string | null
1150
+ readonly state: TopicState
1151
+ readonly pinned: boolean
1152
+ readonly createdAt: string
1153
+ readonly author: Author
1154
+ readonly following: boolean
1155
+ }
1156
+
1157
+ /** The viewer of a topic: the discussion's viewer, and whether they moderate its category. */
1158
+ export interface TopicViewerState extends DiscussionViewerState {
1159
+ readonly moderator: boolean
1160
+ }
1161
+
1162
+ /**
1163
+ * `forum/topics/get`: one page of a topic — the messages, cursor, counters, reactions and preset exactly as
1164
+ * `discussions/list` answers them (the opening post is seq 1), with the topic's header in place of the article.
1165
+ */
1166
+ export interface TopicThread {
1167
+ readonly topic: Topic
1168
+ /** Top-level, oldest first, COMMUNITY_PAGE_SIZE a page. */
1169
+ readonly messages: readonly PublicMessage[]
1170
+ readonly nextCursor: number | null
1171
+ readonly count: number
1172
+ readonly lastSeq: number
1173
+ readonly lastChangeAt: string | null
1174
+ readonly reactionSet: readonly string[]
1175
+ readonly preset: string | null
1176
+ readonly viewer: TopicViewerState
1177
+ }
1178
+
1179
+ /** `forum/topics/head`: the polling signal of one topic (an id the viewer may not see is left out). */
1180
+ export interface TopicHead {
1181
+ readonly conversationId: string
1182
+ readonly count: number
1183
+ readonly lastSeq: number
1184
+ readonly lastChangeAt: string | null
1185
+ }
1186
+
1187
+ /**
1188
+ * One `forum/search` hit (§4.4): plain text only — render the title and the snippet as text. Not `SearchResult`: the
1189
+ * SDK's root entry exports the article search's type of that name (A34).
1190
+ */
1191
+ export interface ForumSearchResult {
1192
+ readonly kind: SearchResultKind
1193
+ readonly space: ForumSpace
1194
+ readonly conversationId: string
1195
+ /** The message's seq (a `message` hit), else null. */
1196
+ readonly seq: number | null
1197
+ /**
1198
+ * The topic's title (or the article's) as the viewer may see it — null for a `message` hit in a topic whose title
1199
+ * §3.1's rule withholds from the viewer, or whose opening post was deleted: `openingState` tells the two apart, as on
1200
+ * a category's row — read a forum hit's title through topicTitleOf (`topic.deleted` „Smazané téma" for a deleted
1201
+ * opening post, `topic.withheld` otherwise).
1202
+ */
1203
+ readonly title: string | null
1204
+ /**
1205
+ * M3 FX2 (m3-contracts.md §5.3; the review of wave 2, S12): `deleted` on a `message` hit of a topic whose opening post
1206
+ * was deleted (its title went with it). Absent otherwise — and from a kb-api older than M3 FX2, whose deleted opening
1207
+ * post then reads as withheld.
1208
+ */
1209
+ readonly openingState?: MessageState
1210
+ /** A topic's category; null for an article discussion's hit. */
1211
+ readonly categoryId: string | null
1212
+ /** An article discussion's article; null for a topic's hit. */
1213
+ readonly articleId: string | null
1214
+ /**
1215
+ * M3 F3 (the wave 2 integration): what an article discussion's hit needs for its link — the article's slug (its
1216
+ * filename without `.md`/`.mdx`, as the notification centre names it): `communityMessageLink(articlePath, articleSlug,
1217
+ * seq)`. Null for a topic's hit (link it by `conversationId`: topicPath, topicMessageLink).
1218
+ */
1219
+ readonly articleSlug: string | null
1220
+ /** At most 200 characters around the first hit, no markup. */
1221
+ readonly snippet: string | null
1222
+ readonly createdAt: string
1223
+ }
1224
+
1225
+ /** `forum/search`: one page of at most COMMUNITY_SEARCH_PAGE_SIZE hits; pages 1..COMMUNITY_SEARCH_PAGES_MAX only. */
1226
+ export interface ForumSearchPage {
1227
+ readonly results: readonly ForumSearchResult[]
1228
+ readonly page: number
1229
+ /** false on the last page (always on page COMMUNITY_SEARCH_PAGES_MAX). */
1230
+ readonly hasMore: boolean
1231
+ }
1232
+
1233
+ /** What `me/follows/set` names: a conversation (a topic or an article discussion with one) or a category. */
1234
+ export type FollowTarget = { readonly conversationId: string } | { readonly categoryId: string }
1235
+
1236
+ /** `me/follows/list`: one of the member's follows. */
1237
+ export interface Follow {
1238
+ readonly targetKind: FollowTargetKind
1239
+ readonly targetId: string
1240
+ /** `forum` | `article` for a conversation, null for a category. */
1241
+ readonly space: ForumSpace | null
1242
+ /** The topic's title, the category's name or the article's title as the member may see it now, else null. */
1243
+ readonly title: string | null
1244
+ /**
1245
+ * M3 F3 (the wave 2 integration): what a link needs while the member may read the target — a category's slug
1246
+ * (categoryPath), an article's slug (its filename without `.md`/`.mdx`: the host's articlePath); null for a topic (link
1247
+ * it by `targetId`: topicPath) and whenever `title` is null.
1248
+ */
1249
+ readonly slug: string | null
1250
+ readonly createdAt: string
1251
+ }
1252
+
1253
+ /** `me/follows/list`: a keyset page. */
1254
+ export interface FollowsPage {
1255
+ readonly follows: readonly Follow[]
1256
+ readonly nextCursor: string | null
1257
+ }
1258
+
1259
+ /**
1260
+ * A row of a category moderator's queue (§3.4): a case of category `rules` in the moderator's categories — open, or
1261
+ * decided while a `system` decision still holds its message — or a message waiting in pre-moderation (reasons
1262
+ * `category_pre`, `away`; a `health_third_party` item never reaches a moderator).
1263
+ */
1264
+ export interface ModerationItem {
1265
+ readonly kind: ModerationItemKind
1266
+ /** The case (a `case` row), else null. */
1267
+ readonly caseId: string | null
1268
+ /** The case's status (a `case` row: `open`, or `decided` while the system's hold stands), else null. */
1269
+ readonly caseStatus: ModerationCaseStatus | null
1270
+ readonly conversationId: string
1271
+ readonly seq: number
1272
+ readonly categoryId: string
1273
+ /** The case's category (a `case` row), else null. */
1274
+ readonly caseCategory: string | null
1275
+ readonly ruleId: string | null
1276
+ readonly source: ModerationSource | null
1277
+ readonly createdAt: string
1278
+ readonly deadlineAt: string | null
1279
+ /**
1280
+ * M3 FX (m3-contracts.md §3.4; the review of wave 1, R3): a `premod` row's message rev — `moderation.reviewPremod` takes
1281
+ * it back and decides that text only (an edit since answers `submit`: re-read the queue, show the new text, ask again);
1282
+ * null on a `case` row.
1283
+ */
1284
+ readonly rev: number | null
1285
+ /** M3 FX (R3): a `premod` row's text as written (render it as text); null on a `case` row (its package is `getCase`'s). */
1286
+ readonly body: string | null
1287
+ /** M3 FX (R3): a `premod` row of an opening post — its topic's title (render it as text). */
1288
+ readonly title?: string | null
1289
+ }
1290
+
1291
+ /** `moderation/queue`: a keyset page. */
1292
+ export interface ModerationQueuePage {
1293
+ readonly items: readonly ModerationItem[]
1294
+ readonly nextCursor: string | null
1295
+ }
1296
+
1297
+ /**
1298
+ * One item of a case's package, as written (render it as text); never who reported it. The case's subject is whole
1299
+ * (its text, title and handle null only once it was deleted); another message of the package only while everyone may
1300
+ * see it now and its author has not edited it since the package was written (M3 FX2, S4) — otherwise its `body`,
1301
+ * `title` and `authorHandle` are null (say so: `moderation.itemWithheld`; an opening post's title through
1302
+ * topicTitleOf: `topic.deleted` for a deleted opening post, `topic.withheld` otherwise).
1303
+ */
1304
+ export interface ModerationCaseItem {
1305
+ readonly itemNo: number
1306
+ /** On an opening post's item: the topic's title — null when withheld, or cleared with a deleted opening post (`openingState`). */
1307
+ readonly title?: string | null
1308
+ /**
1309
+ * M3 FX2 (S12): `deleted` on an opening post's item whose opening post was deleted — its title went with it. Absent
1310
+ * otherwise (and from a kb-api older than M3 FX2).
1311
+ */
1312
+ readonly openingState?: MessageState
1313
+ /** null when withheld (a message of the package other than the subject that others cannot see now). */
1314
+ readonly body: string | null
1315
+ readonly authorHandle: string | null
1316
+ /** When the message was written, as the package recorded it; null when the package holds no time. */
1317
+ readonly createdAt: string | null
1318
+ }
1319
+
1320
+ /** `moderation/cases/get`: the package; no reporter, no reporter's note, no notifier contact, no earlier deciders. */
1321
+ export interface ModerationCase {
1322
+ readonly id: string
1323
+ readonly caseCategory: string
1324
+ readonly ruleId: string | null
1325
+ readonly source: ModerationSource
1326
+ readonly status: string
1327
+ readonly createdAt: string
1328
+ readonly deadlineAt: string | null
1329
+ readonly subject: { readonly conversationId: string; readonly seq: number }
1330
+ readonly items: readonly ModerationCaseItem[]
1331
+ }
1332
+
1333
+ /** `moderation/decide`: the statement (a dry run writes nothing) and, when decided, the decision. */
1334
+ export interface ModerationDecideAnswer {
1335
+ readonly dryRun: boolean
1336
+ /** The statement of reasons as kb-api renders it (plain text). */
1337
+ readonly statement: string
1338
+ readonly decision?: { readonly id: string; readonly restriction: ModerationRestriction | (string & {}) }
1339
+ }
1340
+
1341
+ /** `moderation/remove` and a rejected pre-moderated message: the removal and its statement. */
1342
+ export interface ModerationRemovalAnswer {
1343
+ readonly decision: { readonly id: string }
1344
+ readonly statement: string
1345
+ }
1346
+
1347
+ /** `moderation/premod/review`: the published message (approve), or the removal with its statement (reject). */
1348
+ export type PremodReviewAnswer = { readonly message: PublicMessage } | ModerationRemovalAnswer
1349
+
1350
+ /** `forum/topics/create`: the topic, its opening post as its author sees it, the filters' warnings. */
1351
+ export interface TopicCreateAnswer {
1352
+ readonly topic: Topic
1353
+ readonly message: PublicMessage
1354
+ readonly warnings: readonly string[]
1355
+ }
1356
+
1357
+ // ───────────────────────── the forum's inputs ─────────────────────────
1358
+
1359
+ /** `forum/topics/list`: a category by its id or its slug; `cursor` is the previous page's `nextCursor`. */
1360
+ export type ForumTopicsListInput = ({ categoryId: string; categorySlug?: never } | { categorySlug: string; categoryId?: never }) & {
1361
+ sort?: ForumSort
1362
+ cursor?: string | null
1363
+ /** 1..COMMUNITY_TOPICS_PAGE_MAX (default COMMUNITY_TOPICS_PAGE_SIZE). */
1364
+ limit?: number
1365
+ }
1366
+
1367
+ export interface ForumTopicGetInput {
1368
+ conversationId: string
1369
+ /** The page's language: a translation of each message into it when one exists. */
1370
+ languageCode?: string | null
1371
+ /** The previous page's `nextCursor`; absent for the first page. */
1372
+ cursor?: number | null
1373
+ }
1374
+
1375
+ export interface ForumTopicCreateInput {
1376
+ categoryId: string
1377
+ /** ≤ COMMUNITY_TOPIC_TITLE_MAX characters. */
1378
+ title: string
1379
+ body: string
1380
+ /** newClientMsgId(), the same on a retry (a repeat answers the topic it created). */
1381
+ clientMsgId: string
1382
+ languageCode: string
1383
+ confirmations?: string[]
1384
+ }
1385
+
1386
+ export interface ForumSearchInput {
1387
+ /** COMMUNITY_SEARCH_QUERY_MIN..COMMUNITY_SEARCH_QUERY_MAX characters (forumSearchQueryOf). */
1388
+ query: string
1389
+ categoryId?: string | null
1390
+ space?: KnownForumSpace | null
1391
+ /** 1..COMMUNITY_SEARCH_PAGES_MAX. */
1392
+ page?: number
1393
+ }
1394
+
1395
+ /**
1396
+ * `me/follows/set` (§3.3, B16): `following: true` needs a target the member may read now — anything else (a topic the
1397
+ * member may not see, a hidden or deleted category, an internal or discussion-free article) is the one `notFound`, so
1398
+ * the button says „not available"; then the `community_profile` quota and `followLimit` above COMMUNITY_FOLLOWS_MAX.
1399
+ * `following: false` never fails on the target (an unknown one answers `{ following: false }`): an unfollow needs no
1400
+ * error path of its own.
1401
+ */
1402
+ export interface FollowSetInput {
1403
+ target: FollowTarget
1404
+ following: boolean
1405
+ }
1406
+
1407
+ export interface ModerationQueueInput {
1408
+ categoryId?: string | null
1409
+ cursor?: string | null
1410
+ }
1411
+
1412
+ export interface ModerationDecideInput {
1413
+ caseId: string
1414
+ restriction: ModerationRestriction
1415
+ basis: ModerationBasis
1416
+ /** The facts and circumstances, as the statement will state them. */
1417
+ facts: string
1418
+ /**
1419
+ * A rule id of the tenant's current rules text the restriction rests on (§3.4, A09); absent, the case's own rule id.
1420
+ * A restriction on a case without one and without this is `invalid` with `fields: ['contractualGround']`: ask the
1421
+ * moderator for the rule. `automatedDetection` is kb-api's, from the case — never an input.
1422
+ */
1423
+ contractualGround?: string | null
1424
+ locale?: string | null
1425
+ /** true: render the statement and write nothing (the preview the moderator confirms). */
1426
+ dryRun?: boolean
1427
+ }
1428
+
1429
+ export interface ModerationRemoveInput {
1430
+ conversationId: string
1431
+ seq: number
1432
+ ruleId: string
1433
+ facts: string
1434
+ locale?: string | null
1435
+ }
1436
+
1437
+ export interface ModerationEscalateInput {
1438
+ conversationId: string
1439
+ seq: number
1440
+ /** One of the illegal line's case categories (never `rules`). */
1441
+ category: CaseCategory
1442
+ }
1443
+
1444
+ /**
1445
+ * `moderation/premod/review`: approve, or reject on a rule with the facts; `locale` — the statement's language (reject).
1446
+ * M3 FX (R3): `rev` — the queue row's (`ModerationItem.rev`): the review decides the text the moderator read.
1447
+ */
1448
+ export type PremodReviewInput =
1449
+ | { conversationId: string; seq: number; rev: number; outcome: 'approve'; ruleId?: never; facts?: never; locale?: string | null }
1450
+ | { conversationId: string; seq: number; rev: number; outcome: 'reject'; ruleId: string; facts: string; locale?: string | null }