@blogmcp/sdk 0.10.0 → 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.
- package/dist/community/channels.d.ts +3 -2
- package/dist/community/client.d.ts +129 -2
- package/dist/community/client.js +231 -161
- package/dist/community/forum.d.ts +82 -0
- package/dist/community/forum.js +96 -0
- package/dist/community/index.d.ts +14 -7
- package/dist/community/index.js +185 -121
- package/dist/community/links.d.ts +38 -0
- package/dist/community/links.js +98 -71
- package/dist/community/messages.cs.d.ts +160 -1
- package/dist/community/messages.cs.js +178 -1
- package/dist/community/messages.d.ts +19 -1
- package/dist/community/messages.en.d.ts +150 -1
- package/dist/community/messages.en.js +161 -1
- package/dist/community/messages.js +37 -28
- package/dist/community/outcome.d.ts +8 -3
- package/dist/community/outcome.js +64 -20
- package/dist/community/poll.d.ts +28 -4
- package/dist/community/poll.js +70 -47
- package/dist/community/realtime/index.d.ts +19 -3
- package/dist/community/realtime/index.js +175 -145
- package/dist/community/routes.d.ts +36 -1
- package/dist/community/routes.js +51 -21
- package/dist/community/server/bff.d.ts +25 -2
- package/dist/community/server/bff.js +135 -118
- package/dist/community/server/host-routes.d.ts +3 -0
- package/dist/community/server/host-routes.js +17 -0
- package/dist/community/server/index.d.ts +5 -1
- package/dist/community/shapes.d.ts +634 -7
- package/dist/community/shapes.js +92 -61
- package/dist/community/store.d.ts +15 -0
- package/dist/community/store.js +65 -61
- package/dist/community/topic.d.ts +173 -0
- package/dist/community/topic.js +225 -0
- package/package.json +3 -3
- package/src/community/channels.ts +3 -2
- package/src/community/client.ts +209 -5
- package/src/community/forum.ts +209 -0
- package/src/community/index.ts +146 -2
- package/src/community/links.ts +64 -4
- package/src/community/messages.cs.ts +179 -1
- package/src/community/messages.en.ts +162 -1
- package/src/community/messages.ts +25 -2
- package/src/community/outcome.ts +50 -1
- package/src/community/poll.ts +79 -17
- package/src/community/realtime/index.ts +124 -48
- package/src/community/routes.ts +42 -1
- package/src/community/server/bff.ts +89 -30
- package/src/community/server/host-routes.ts +20 -0
- package/src/community/server/index.ts +5 -1
- package/src/community/shapes.ts +662 -6
- package/src/community/store.ts +11 -5
- package/src/community/topic.ts +521 -0
|
@@ -37,6 +37,10 @@ export const COMMUNITY_MESSAGES_EN = {
|
|
|
37
37
|
'error.mentionLimit': 'This post mentions more people than you can mention yet. Remove some of the mentions and send it again.',
|
|
38
38
|
'error.pushRefused': 'Notifications cannot be switched on in this browser. Try another browser, or keep an eye on the notifications page.',
|
|
39
39
|
'error.realtimeOff': 'New posts do not show up instantly here right now. The discussion refreshes itself every so often.',
|
|
40
|
+
'error.membersOnly': 'The forum is open to community members. Sign in and join the community to see it.',
|
|
41
|
+
'error.topicLocked': "This topic is closed, so you can't post in it any more. You can still read it.",
|
|
42
|
+
'error.topicCreationClosed': "You can't start a new topic in this category. Please try another one.",
|
|
43
|
+
'error.followLimit': "You're already following a lot. Please unfollow something and try again.",
|
|
40
44
|
'error.submit': "That didn't work. Please reload the page and try again.",
|
|
41
45
|
|
|
42
46
|
'need.sign_in': 'Sign in to write in the discussion.',
|
|
@@ -297,6 +301,10 @@ export const COMMUNITY_MESSAGES_EN = {
|
|
|
297
301
|
'appealStatus.upheld': 'The decision stands',
|
|
298
302
|
'appealStatus.reversed': 'The decision was reversed',
|
|
299
303
|
'appealStatus.withdrawn': 'Withdrawn',
|
|
304
|
+
// M3 F6/F9 (m3-contracts.md §3.5, §4.7): what the team recorded on an adverse-event case (adverseOutcomeMessageKey).
|
|
305
|
+
'adverseOutcome.recorded': 'Assessed as a possible adverse reaction and recorded in the register.',
|
|
306
|
+
'adverseOutcome.reported_to_authority': 'Assessed as a possible adverse reaction and reported to the competent authority.',
|
|
307
|
+
'adverseOutcome.not_adverse': 'Assessed: it is not an adverse reaction.',
|
|
300
308
|
'notification.decision': 'There is a new decision about your content.',
|
|
301
309
|
'notification.appeal_resolved': 'Your appeal has been resolved.',
|
|
302
310
|
'notification.erasure_scheduled': 'The deletion of your discussion profile is scheduled.',
|
|
@@ -307,6 +315,9 @@ export const COMMUNITY_MESSAGES_EN = {
|
|
|
307
315
|
'notification.mention': 'Someone mentioned you in a discussion.',
|
|
308
316
|
'notification.module_push_reset': 'Browser notifications need to be switched on again in your community settings.',
|
|
309
317
|
'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.',
|
|
318
|
+
'notification.topic_update': 'A discussion you follow has a new post.',
|
|
319
|
+
'notification.category_topic': 'A category you follow has a new topic.',
|
|
320
|
+
'notification.category_topic.article': 'A category you follow has a new discussion under an article.',
|
|
310
321
|
|
|
311
322
|
'centre.title': 'Notifications',
|
|
312
323
|
'centre.empty': 'New notifications will show here.',
|
|
@@ -352,7 +363,8 @@ export const COMMUNITY_MESSAGES_EN = {
|
|
|
352
363
|
'trust.0': 'New member',
|
|
353
364
|
'trust.1': 'Member',
|
|
354
365
|
'trust.2': 'Regular',
|
|
355
|
-
'trust.3': '
|
|
366
|
+
'trust.3': 'Trusted member',
|
|
367
|
+
'role.moderator': 'Moderator',
|
|
356
368
|
|
|
357
369
|
'welcome.title': 'Welcome to the community',
|
|
358
370
|
'welcome.lede': 'Here are a few things that help at the start.',
|
|
@@ -364,6 +376,152 @@ export const COMMUNITY_MESSAGES_EN = {
|
|
|
364
376
|
'realtime.off': 'Live updates are off right now. The discussion refreshes itself every so often.',
|
|
365
377
|
'state.readOnly': "The community's extra features are switched off for now. The discussion under the article goes on.",
|
|
366
378
|
'state.braked': 'Writing is paused for a while. You can keep reading.',
|
|
379
|
+
'state.away': 'The team is away for now; new topics will wait for review.',
|
|
380
|
+
'topic.deleted': 'Deleted topic',
|
|
381
|
+
// M3 (§3.1, B06): a title §3.1's placeholder rule keeps from the viewer (held, removed or held back) — never a deletion,
|
|
382
|
+
// wherever a title reads: a topic, a category's row, a search hit, a moderator's package (M3 FX2, S12: a deleted
|
|
383
|
+
// opening post reads `topic.deleted` in each — topicTitleOf over `openingState`).
|
|
384
|
+
'topic.withheld': 'Topic title unavailable',
|
|
385
|
+
// M3 F9 (§3.3, B16): the follow button — following needs a target the member may read now; unfollowing never fails.
|
|
386
|
+
'follow.follow': 'Follow',
|
|
387
|
+
'follow.following': 'Following',
|
|
388
|
+
'follow.followed': "You're following. You'll see what's new in your notifications.",
|
|
389
|
+
'follow.unfollowed': "You've stopped following.",
|
|
390
|
+
'follow.unavailable': "You can't follow this right now.",
|
|
391
|
+
|
|
392
|
+
// ── M3 F9: the forum's elements (forum.*, forumCategory.*, topic.*, search.*, moderation.*; m3-contracts.md §5.3) ──
|
|
393
|
+
'forum.title': 'Forum',
|
|
394
|
+
'forum.loading': 'Loading the forum…',
|
|
395
|
+
'forum.empty': 'The forum has no categories yet.',
|
|
396
|
+
'forum.topicCount_one': '{count} topic',
|
|
397
|
+
'forum.topicCount_other': '{count} topics',
|
|
398
|
+
'forum.discussionCount_one': '{count} discussion',
|
|
399
|
+
'forum.discussionCount_other': '{count} discussions',
|
|
400
|
+
'forum.lastActivity': 'Last activity {date}',
|
|
401
|
+
'forum.latest': 'Latest topics',
|
|
402
|
+
'forum.allTopics': 'All topics',
|
|
403
|
+
'forum.allCategories': 'All categories',
|
|
404
|
+
'forum.search': 'Search the forum',
|
|
405
|
+
'forum.searchSubmit': 'Search',
|
|
406
|
+
'forum.modePre': 'New posts here wait for review before they appear.',
|
|
407
|
+
'forum.teamTopics': 'The team starts the topics here.',
|
|
408
|
+
'forum.join': 'Join the community',
|
|
409
|
+
'forum.back': 'Back to the forum',
|
|
410
|
+
// The forum's own brake (§4.9): its writes pause, the article discussions go on.
|
|
411
|
+
'state.forumBraked': 'Posting in the forum is paused for a while. You can keep reading.',
|
|
412
|
+
'forumCategory.notFound': "We couldn't find this category.",
|
|
413
|
+
'forumCategory.empty': 'There are no topics in this category yet.',
|
|
414
|
+
'forumCategory.articlesEmpty': 'There are no article discussions here yet.',
|
|
415
|
+
'forumCategory.sort': 'Sort',
|
|
416
|
+
'forumCategory.sortActivity': 'By activity',
|
|
417
|
+
'forumCategory.sortNew': 'Newest',
|
|
418
|
+
'forumCategory.newTopic': 'New topic',
|
|
419
|
+
'topic.loading': 'Loading the topic…',
|
|
420
|
+
'topic.notFound': "We couldn't find this topic. It may no longer be available.",
|
|
421
|
+
'topic.count_one': '{count} post',
|
|
422
|
+
'topic.count_other': '{count} posts',
|
|
423
|
+
'topic.locked': 'Closed',
|
|
424
|
+
'topic.archived': 'Archived',
|
|
425
|
+
'topic.pinned': 'Pinned',
|
|
426
|
+
'topic.titleLabel': 'Topic title',
|
|
427
|
+
'topic.titleMissing': 'Please give the topic a title.',
|
|
428
|
+
'topic.titleTooLong': 'The title is too long. Please shorten it to {max} characters at most.',
|
|
429
|
+
'topic.bodyLabel': 'Opening post',
|
|
430
|
+
'topic.create': 'Start the topic',
|
|
431
|
+
'topic.created': 'The topic is up.',
|
|
432
|
+
'topic.createdHeld': "We've got the topic; it's awaiting review now.",
|
|
433
|
+
'topic.open': 'Open the topic',
|
|
434
|
+
// A topic's thread reads the discussion's texts with these words of the forum's (the topic element maps the keys).
|
|
435
|
+
'forumText.composer.label': 'Your post',
|
|
436
|
+
'forumText.composer.editLabel': 'Editing the post',
|
|
437
|
+
'forumText.composer.placeholder': 'Write a post…',
|
|
438
|
+
'forumText.composer.tooLong': 'The post is too long. Please shorten it to {max} characters at most.',
|
|
439
|
+
'forumText.composer.linksNote_one': 'A post can hold up to {count} link.',
|
|
440
|
+
'forumText.composer.linksNote_other': 'A post can hold up to {count} links.',
|
|
441
|
+
'forumText.composer.posted': 'The post is published.',
|
|
442
|
+
'forumText.composer.held': "We've got the post; it's awaiting review now.",
|
|
443
|
+
'forumText.composer.cooldown_one': 'You can post again in {count} second.',
|
|
444
|
+
'forumText.composer.cooldown_other': 'You can post again in {count} seconds.',
|
|
445
|
+
'forumText.discussion.empty': "There aren't any replies yet. Be the first to reply.",
|
|
446
|
+
'forumText.discussion.deleteTitle': 'Delete the post?',
|
|
447
|
+
'forumText.discussion.deleteExplain': 'The post disappears. If someone has replied to it, an empty placeholder stays in its place.',
|
|
448
|
+
'forumText.discussion.collapsed': "A post by an author you've blocked.",
|
|
449
|
+
'forumText.discussion.heldNote': "The post is awaiting review and only you can see it for now. After the review it shows to others, or you'll find out why not in My community.",
|
|
450
|
+
'forumText.discussion.hiddenUntilConsentNote': 'Only you can see this post for now. Others will see it once you give your consent to the processing.',
|
|
451
|
+
'forumText.discussion.removedNote': "We removed this post; others can't see it.",
|
|
452
|
+
'forumText.discussion.placeholderHeld': 'This post is awaiting review.',
|
|
453
|
+
'forumText.discussion.placeholderRemoved': 'This post was removed.',
|
|
454
|
+
'forumText.discussion.placeholderDeleted': 'This post was deleted.',
|
|
455
|
+
'forumText.report.title': 'Report the post',
|
|
456
|
+
'forumText.report.category': "What's wrong with the post?",
|
|
457
|
+
'forumText.error.links': 'This post has more links than fit. Please remove some of them.',
|
|
458
|
+
'forumText.error.blocked': "This post can't be published as it is. Please try editing it.",
|
|
459
|
+
'forumText.error.confirm': 'Before you send the post, please confirm one thing.',
|
|
460
|
+
'forumText.confirm.other': 'I understand the notice and want to send the post.',
|
|
461
|
+
'forumText.warning.identifier': "The post seems to contain an e-mail address, a phone number or an account number. If it shouldn't be there, edit the post.",
|
|
462
|
+
'forumText.warning.other': 'The post is published, but the discussion rules flag something in it. Please look it over.',
|
|
463
|
+
'forumText.need.onboarding': 'Before your first post, choose a name and confirm the discussion rules.',
|
|
464
|
+
'forumText.need.art9_consent': 'To write in the forum, we need your consent to the processing.',
|
|
465
|
+
'search.title': 'Search the forum',
|
|
466
|
+
'search.label': 'What are you looking for?',
|
|
467
|
+
'search.submit': 'Search',
|
|
468
|
+
'search.searching': 'Searching…',
|
|
469
|
+
'search.tooShort': 'Please type at least {min} characters.',
|
|
470
|
+
'search.tooLong': 'The search text is too long. Please shorten it to {max} characters at most.',
|
|
471
|
+
'search.empty': 'We found no results for that. Try other words.',
|
|
472
|
+
'search.more': 'More results',
|
|
473
|
+
'search.lastPage': "We don't show more results. Try narrowing the search.",
|
|
474
|
+
'search.space': 'Where to search',
|
|
475
|
+
'search.spaceAll': 'Everywhere',
|
|
476
|
+
'search.spaceForum': 'In the forum',
|
|
477
|
+
'search.spaceArticle': 'In article discussions',
|
|
478
|
+
'search.category': 'Category',
|
|
479
|
+
'search.topic': 'Topic',
|
|
480
|
+
'search.message': 'Post',
|
|
481
|
+
'search.inArticle': 'An article discussion',
|
|
482
|
+
'moderation.title': 'Moderation',
|
|
483
|
+
'moderation.loading': 'Loading the queue…',
|
|
484
|
+
'moderation.empty': 'The queue is empty right now.',
|
|
485
|
+
'moderation.source.member_report': 'Reported by a member',
|
|
486
|
+
'moderation.source.filter': 'Caught by the filters',
|
|
487
|
+
'moderation.source.staff': 'From the team',
|
|
488
|
+
'moderation.premod': 'Awaiting approval',
|
|
489
|
+
'moderation.heldBySystem': 'Hidden automatically for now',
|
|
490
|
+
'moderation.deadline': 'Due by {date}',
|
|
491
|
+
'moderation.open': 'Review',
|
|
492
|
+
'moderation.package': 'Content to review',
|
|
493
|
+
'moderation.itemWithheld': "Others can't see this post now, so it isn't shown here.",
|
|
494
|
+
'moderation.restriction': 'Decision',
|
|
495
|
+
'moderation.factsHint': 'Describe what you found. The text becomes part of the statement of reasons for the author.',
|
|
496
|
+
'moderation.ruleRequired': 'Please choose the rule the decision rests on.',
|
|
497
|
+
'moderation.preview': 'Preview the statement',
|
|
498
|
+
'moderation.previewTitle': 'This is the statement the author will see',
|
|
499
|
+
'moderation.decide': 'Decide',
|
|
500
|
+
'moderation.decided': 'Decided.',
|
|
501
|
+
'moderation.escalate': 'Pass to the team',
|
|
502
|
+
'moderation.escalateLede': "Do you think it's illegal? Pass it to the site's team to assess.",
|
|
503
|
+
'moderation.escalateCategory': 'What is it?',
|
|
504
|
+
'moderation.escalated': 'Passed to the team.',
|
|
505
|
+
'moderation.remove': 'Remove as a moderator',
|
|
506
|
+
'moderation.removeLede': 'The post disappears and its author gets a statement of reasons they can appeal.',
|
|
507
|
+
'moderation.removed': 'Removed. The author got a statement of reasons.',
|
|
508
|
+
'moderation.approve': 'Publish',
|
|
509
|
+
'moderation.approved': 'Published.',
|
|
510
|
+
'moderation.reject': 'Reject',
|
|
511
|
+
'moderation.rejected': 'Rejected. The author got a statement of reasons.',
|
|
512
|
+
'moderation.gone': 'This item is no longer in the queue.',
|
|
513
|
+
// M3 FX (R3): a pre-moderated text the author edited while it was being reviewed.
|
|
514
|
+
'moderation.textChanged': 'The author has edited the text since. Read the new version and decide again.',
|
|
515
|
+
'moderation.lock': 'Close the topic',
|
|
516
|
+
'moderation.unlock': 'Reopen the topic',
|
|
517
|
+
'moderation.pin': 'Pin the topic',
|
|
518
|
+
'moderation.unpin': 'Unpin the topic',
|
|
519
|
+
'moderation.move': 'Move the topic',
|
|
520
|
+
'moderation.moveTo': 'Where to move the topic?',
|
|
521
|
+
'moderation.done': 'Done.',
|
|
522
|
+
'moderation.openTopic': 'View in the topic',
|
|
523
|
+
// A member's profile: the categories they moderate now (PublicProfile.moderates; „Moderátor" is role.moderator).
|
|
524
|
+
'profile.moderates': 'In the categories',
|
|
367
525
|
'mention.limit': 'This post mentions more people than you can mention yet.',
|
|
368
526
|
|
|
369
527
|
'notice.title': 'Report content',
|
|
@@ -395,6 +553,9 @@ export const COMMUNITY_MESSAGES_EN = {
|
|
|
395
553
|
'notice.submittedAt': 'Sent on {date}',
|
|
396
554
|
'notice.decidedAt': 'Decided on {date}',
|
|
397
555
|
'notice.statement': 'Statement of reasons',
|
|
556
|
+
// M3 F6/F9: a notice closed by an adverse-event outcome alone — the outcome in plain words and the redress line.
|
|
557
|
+
'notice.outcome': 'Outcome',
|
|
558
|
+
'notice.redress': 'If you disagree with how it was dealt with, you can turn to a court or use an out-of-court dispute settlement.',
|
|
398
559
|
'notice.appealTitle': 'Appeal',
|
|
399
560
|
'notice.appealLede': "Don't agree with how we handled the report? Tell us why.",
|
|
400
561
|
'notice.appealBody': "Why don't you agree with the decision?",
|
|
@@ -11,7 +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
|
+
import { ADVERSE_EVENT_OUTCOMES, NOTIFICATION_CODES, TRUST_LABELS } from './shapes'
|
|
15
15
|
|
|
16
16
|
type PluralCategory = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other'
|
|
17
17
|
type BaseKey<K extends string> = K extends `${infer Base}_${PluralCategory}` ? Base : K
|
|
@@ -121,11 +121,34 @@ export function notificationMessageKey(code: string): CommunityMessageKey | null
|
|
|
121
121
|
return (NOTIFICATION_CODES as readonly string[]).includes(code) ? (`notification.${code}` as CommunityMessageKey) : null
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* M3 (m3-contracts.md §4.3): the sentence of one notification row — notificationMessageKey's, except a `category_topic`
|
|
126
|
+
* row that names an article: the followed „Články" category's new discussion under an article (kb-api fills its
|
|
127
|
+
* `articleId`; a topic's row names none) reads `notification.category_topic.article`. A „Články" row whose article is
|
|
128
|
+
* no longer readable names none either, and reads as a topic's.
|
|
129
|
+
*/
|
|
130
|
+
export function notificationItemMessageKey(item: { readonly code: string; readonly articleId?: string | null }): CommunityMessageKey | null {
|
|
131
|
+
const key = notificationMessageKey(item.code)
|
|
132
|
+
if (key === 'notification.category_topic' && typeof item.articleId === 'string' && item.articleId !== '') return 'notification.category_topic.article'
|
|
133
|
+
return key
|
|
134
|
+
}
|
|
135
|
+
|
|
124
136
|
/**
|
|
125
137
|
* 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` „
|
|
138
|
+
* … `trust.3` „Důvěryhodný člen" — a label, never the number. Null for a label this SDK does not know (show no label).
|
|
139
|
+
* „Moderátor" is no trust level since M3 (D-M3-7): it names a category moderator's appointment, `role.moderator`,
|
|
140
|
+
* shown beside a moderator's messages in their categories (`Author.moderator`) and on their profile (`moderates`).
|
|
127
141
|
*/
|
|
128
142
|
export function trustLabelMessageKey(label: string | null | undefined): CommunityMessageKey | null {
|
|
129
143
|
const level = typeof label === 'string' ? (TRUST_LABELS as readonly string[]).indexOf(label) : -1
|
|
130
144
|
return level < 0 ? null : (`trust.${level}` as CommunityMessageKey)
|
|
131
145
|
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* M3 (m3-contracts.md §3.5, §4.7): the plain words of an adverse-event case's outcome (`ReportItem.outcome`,
|
|
149
|
+
* `NoticeStatus.outcome`) — `adverseOutcome.recorded` … — or null for none, or an outcome this SDK has no words for (show
|
|
150
|
+
* the case's status alone). A notice's page adds the redress line (`notice.redress`), as the `notice_closed` e-mail does.
|
|
151
|
+
*/
|
|
152
|
+
export function adverseOutcomeMessageKey(outcome: string | null | undefined): CommunityMessageKey | null {
|
|
153
|
+
return typeof outcome === 'string' && (ADVERSE_EVENT_OUTCOMES as readonly string[]).includes(outcome) ? (`adverseOutcome.${outcome}` as CommunityMessageKey) : null
|
|
154
|
+
}
|
package/src/community/outcome.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* Browser-safe and server-safe: no I/O, no globals.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import type { KnownNeed } from './shapes'
|
|
15
|
+
import type { BrakeSurface, KnownNeed } from './shapes'
|
|
16
16
|
|
|
17
17
|
/** The codes a page can be told. */
|
|
18
18
|
export const COMMUNITY_UI_CODES = [
|
|
@@ -72,6 +72,17 @@ export const COMMUNITY_UI_CODES = [
|
|
|
72
72
|
'pushRefused',
|
|
73
73
|
/** M2 T5: live updates are not on here: the discussion keeps itself fresh by polling (pollDiscussionHead). */
|
|
74
74
|
'realtimeOff',
|
|
75
|
+
/**
|
|
76
|
+
* M3: the forum is for the community's members — sign in, or finish joining (`needs` says what is missing for a
|
|
77
|
+
* member session that has not finished onboarding; absent for a visitor: offer the sign-in).
|
|
78
|
+
*/
|
|
79
|
+
'membersOnly',
|
|
80
|
+
/** M3: the topic is closed (locked or archived): it takes no new message, and its messages no edit. */
|
|
81
|
+
'topicLocked',
|
|
82
|
+
/** M3: no new topic can be opened in this category (the article discussions' category, or the team's alone). */
|
|
83
|
+
'topicCreationClosed',
|
|
84
|
+
/** M3: the member follows as much as one member may (COMMUNITY_FOLLOWS_MAX): unfollow something first. */
|
|
85
|
+
'followLimit',
|
|
75
86
|
/** Anything else: "that did not work, try again". */
|
|
76
87
|
'submit',
|
|
77
88
|
] as const
|
|
@@ -97,6 +108,11 @@ export interface CommunityFailure {
|
|
|
97
108
|
codes?: string[]
|
|
98
109
|
/** POSTING_RESTRICTED, ACCOUNT_SUSPENDED, MODULE_READ_ONLY, BRAKED: when it ends (absent: no end set). */
|
|
99
110
|
until?: string
|
|
111
|
+
/**
|
|
112
|
+
* M3 (m3-contracts.md §1.2, §4.9): BRAKED by ONE surface's brake — `forum` or `article_discussions` (an open set):
|
|
113
|
+
* that surface is paused and the other one works. Absent on BRAKED: the module's brake, which pauses both.
|
|
114
|
+
*/
|
|
115
|
+
surface?: BrakeSurface
|
|
100
116
|
/** VALIDATION: the paths of the refused fields (`displayName`, `body`, …), never their values. */
|
|
101
117
|
fields?: string[]
|
|
102
118
|
/**
|
|
@@ -152,6 +168,17 @@ export const COMMUNITY_API_CODES = [
|
|
|
152
168
|
'PUSH_LIMIT',
|
|
153
169
|
'REALTIME_OFF',
|
|
154
170
|
'BUSY',
|
|
171
|
+
'BRAKE_KIND_MISMATCH',
|
|
172
|
+
'MEMBERS_ONLY',
|
|
173
|
+
'TOPIC_LOCKED',
|
|
174
|
+
'TOPIC_CREATION_CLOSED',
|
|
175
|
+
'BRAND_RESTRICTED',
|
|
176
|
+
'CATEGORY_NOT_EMPTY',
|
|
177
|
+
'SLUG_TAKEN',
|
|
178
|
+
'MODERATOR_NOT_ELIGIBLE',
|
|
179
|
+
'FOLLOW_LIMIT',
|
|
180
|
+
'STALE_REVISION',
|
|
181
|
+
'CASE_UNDECIDED',
|
|
155
182
|
'NOT_A_MEMBER_SESSION',
|
|
156
183
|
'IDENTITY_NOT_ADMITTED',
|
|
157
184
|
'ACCOUNT_NOT_ELIGIBLE',
|
|
@@ -238,6 +265,28 @@ export const COMMUNITY_OUTCOME_OF_KB: Readonly<Record<CommunityApiCode, Communit
|
|
|
238
265
|
REALTIME_OFF: 'realtimeOff',
|
|
239
266
|
// F-W0-M4: the team router's lock timeout or deadlock (module/enable's first ranking) — no public operation produces it.
|
|
240
267
|
BUSY: 'submit',
|
|
268
|
+
// M2 follow-up F3: the platform's brakes/lift found another kind of brake (no public operation produces it).
|
|
269
|
+
BRAKE_KIND_MISMATCH: 'submit',
|
|
270
|
+
// M3 (m3-contracts.md §1.2): the forum is for onboarded members and the team (`needs` for a member session short of
|
|
271
|
+
// its onboarding); a closed topic; a category that takes no topic from the member; the 500 follows.
|
|
272
|
+
MEMBERS_ONLY: 'membersOnly',
|
|
273
|
+
TOPIC_LOCKED: 'topicLocked',
|
|
274
|
+
TOPIC_CREATION_CLOSED: 'topicCreationClosed',
|
|
275
|
+
FOLLOW_LIMIT: 'followLimit',
|
|
276
|
+
// M3: the team router's own (§1.2 names them the team's: the elements never meet them). `submit`, as every code no
|
|
277
|
+
// element meets (above) — not §1.2's `unavailable`, which says „try later" where nothing will change. BRAND_RESTRICTED
|
|
278
|
+
// also answers a moderator's `moderation/topics/pin` under a preset without brand reactions; the only such preset
|
|
279
|
+
// admits no member moderators, so no element meets it there either.
|
|
280
|
+
BRAND_RESTRICTED: 'submit',
|
|
281
|
+
CATEGORY_NOT_EMPTY: 'submit',
|
|
282
|
+
SLUG_TAKEN: 'submit',
|
|
283
|
+
MODERATOR_NOT_ELIGIBLE: 'submit',
|
|
284
|
+
// M3 FX (m3-contracts.md §1.2; the review of wave 1, R3, R6). STALE_REVISION: a pre-moderation review of a text the
|
|
285
|
+
// author edited since the reviewer read it (the team's premod/review, the moderator's moderation/premod/review) —
|
|
286
|
+
// nothing was written: the moderation element re-reads the item (moderation.queue), shows the new text and asks again.
|
|
287
|
+
// CASE_UNDECIDED: the team's adverse-events/close while the case's message is held by no decision (decide it first).
|
|
288
|
+
STALE_REVISION: 'submit',
|
|
289
|
+
CASE_UNDECIDED: 'submit',
|
|
241
290
|
// A session that is not a reader's (the team, a key) or an identity the tenant does not admit: sign in as a reader.
|
|
242
291
|
NOT_A_MEMBER_SESSION: 'signIn',
|
|
243
292
|
IDENTITY_NOT_ADMITTED: 'signIn',
|
package/src/community/poll.ts
CHANGED
|
@@ -8,26 +8,38 @@
|
|
|
8
8
|
* onChange: (heads) => { if (heads.some((h) => store.applyHead(h))) void refreshDiscussion(store, client, input) },
|
|
9
9
|
* })
|
|
10
10
|
* // on unmount: poller.stop()
|
|
11
|
+
*
|
|
12
|
+
* M3 (m3-contracts.md §3.2, §5.2): `pollTopicHead` polls `forum/topics/head` by the same rules, for forum topics
|
|
13
|
+
* (refreshTopic re-reads one); it stops for good on `membersOnly` too — the forum is not open to the viewer.
|
|
11
14
|
*/
|
|
12
15
|
|
|
13
16
|
import type { CommunityCallOptions, CommunityClient } from './client'
|
|
14
|
-
import type { CommunityFailure } from './outcome'
|
|
15
|
-
import { COMMUNITY_HEAD_ARTICLES_MAX } from './routes'
|
|
16
|
-
import type { DiscussionHead } from './shapes'
|
|
17
|
+
import type { CommunityFailure, CommunityOutcome, CommunityUiCode } from './outcome'
|
|
18
|
+
import { COMMUNITY_HEAD_ARTICLES_MAX, COMMUNITY_HEAD_TOPICS_MAX } from './routes'
|
|
19
|
+
import type { DiscussionHead, TopicHead } from './shapes'
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
/** What a head poller takes, whatever it polls (the head of an article discussion, of a topic). */
|
|
22
|
+
export interface PollHeadOptions<H> {
|
|
19
23
|
/** Whether the discussion is seen now; default: the document is visible. Polls only while true. */
|
|
20
24
|
visible?: () => boolean
|
|
21
25
|
/** Default 20 s (at least 1 s). */
|
|
22
26
|
intervalMs?: number
|
|
23
27
|
/** The heads that differ from the previous answer (the first answer: every head). */
|
|
24
|
-
onChange(heads:
|
|
25
|
-
/**
|
|
28
|
+
onChange(heads: H[]): void
|
|
29
|
+
/**
|
|
30
|
+
* A poll that failed; the poller goes on, slower — `surfaceOff` stops it (the surface is switched off), and for a
|
|
31
|
+
* topic `membersOnly` too (the forum is not open to the viewer).
|
|
32
|
+
*/
|
|
26
33
|
onFailure?(failure: CommunityFailure): void
|
|
27
34
|
/** Aborting it stops the poller (the element's lifetime). */
|
|
28
35
|
signal?: AbortSignal
|
|
29
36
|
}
|
|
30
37
|
|
|
38
|
+
export interface PollDiscussionHeadOptions extends PollHeadOptions<DiscussionHead> {}
|
|
39
|
+
|
|
40
|
+
/** M3: pollTopicHead's options — `onChange` gets the topics' heads. */
|
|
41
|
+
export interface PollTopicHeadOptions extends PollHeadOptions<TopicHead> {}
|
|
42
|
+
|
|
31
43
|
export interface DiscussionHeadPoller {
|
|
32
44
|
/** Stops for good: no timer, no listener, the request in flight aborted. */
|
|
33
45
|
stop(): void
|
|
@@ -35,27 +47,77 @@ export interface DiscussionHeadPoller {
|
|
|
35
47
|
now(): void
|
|
36
48
|
}
|
|
37
49
|
|
|
50
|
+
/** M3: pollTopicHead's poller (the same two methods). */
|
|
51
|
+
export type TopicHeadPoller = DiscussionHeadPoller
|
|
52
|
+
|
|
38
53
|
export const POLL_INTERVAL_MS = 20_000
|
|
39
54
|
export const POLL_MAX_BACKOFF_MS = 5 * 60_000
|
|
40
55
|
/** A 429 without `Retry-After`. */
|
|
41
56
|
const RATE_LIMITED_WAIT_MS = 60_000
|
|
42
57
|
|
|
43
|
-
|
|
58
|
+
type HeadCounters = Pick<DiscussionHead, 'count' | 'lastSeq' | 'lastChangeAt'>
|
|
59
|
+
|
|
60
|
+
const sameHead = (a: HeadCounters, b: HeadCounters): boolean =>
|
|
44
61
|
a.lastSeq === b.lastSeq && a.count === b.count && a.lastChangeAt === b.lastChangeAt
|
|
45
62
|
|
|
63
|
+
/** What one kind of head poller asks, how it keys a head, how many ids one request holds and what stops it for good. */
|
|
64
|
+
interface HeadSource<H extends HeadCounters> {
|
|
65
|
+
ask(ids: string[], call: CommunityCallOptions): Promise<CommunityOutcome<{ heads: H[] }>>
|
|
66
|
+
/** The head's id, lower case (kb-api answers ids in lower case; a host may pass them in upper case), or null. */
|
|
67
|
+
keyOf(head: H): string | null
|
|
68
|
+
max: number
|
|
69
|
+
stopsOn: readonly CommunityUiCode[]
|
|
70
|
+
}
|
|
71
|
+
|
|
46
72
|
export function pollDiscussionHead(
|
|
47
73
|
client: Pick<CommunityClient, 'discussions'>,
|
|
48
74
|
articleIds: readonly string[],
|
|
49
75
|
options: PollDiscussionHeadOptions,
|
|
50
76
|
): DiscussionHeadPoller {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
77
|
+
return pollHeads(
|
|
78
|
+
{
|
|
79
|
+
ask: (ids, call) => client.discussions.head({ articleIds: ids }, call),
|
|
80
|
+
keyOf: (head) => (typeof head?.articleId === 'string' ? head.articleId.toLowerCase() : null),
|
|
81
|
+
max: COMMUNITY_HEAD_ARTICLES_MAX,
|
|
82
|
+
stopsOn: ['surfaceOff'],
|
|
83
|
+
},
|
|
84
|
+
articleIds,
|
|
85
|
+
options,
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* M3 (m3-contracts.md §3.2, §5.2): polls `forum/topics/head` while the page shows the topics — pollDiscussionHead's
|
|
91
|
+
* rules over up to COMMUNITY_HEAD_TOPICS_MAX conversation ids. A topic the viewer may not see is left out of the
|
|
92
|
+
* answer (never refused one by one); `surfaceOff` (the forum switched off) and `membersOnly` stop the poller.
|
|
93
|
+
*
|
|
94
|
+
* const poller = pollTopicHead(client, [conversationId], {
|
|
95
|
+
* onChange: (heads) => { if (heads.some((h) => store.applyHead(h))) void refreshTopic(store, client, input) },
|
|
96
|
+
* })
|
|
97
|
+
*/
|
|
98
|
+
export function pollTopicHead(
|
|
99
|
+
client: Pick<CommunityClient, 'forum'>,
|
|
100
|
+
conversationIds: readonly string[],
|
|
101
|
+
options: PollTopicHeadOptions,
|
|
102
|
+
): TopicHeadPoller {
|
|
103
|
+
return pollHeads(
|
|
104
|
+
{
|
|
105
|
+
ask: (ids, call) => client.forum.topics.head({ conversationIds: ids }, call),
|
|
106
|
+
keyOf: (head) => (typeof head?.conversationId === 'string' ? head.conversationId.toLowerCase() : null),
|
|
107
|
+
max: COMMUNITY_HEAD_TOPICS_MAX,
|
|
108
|
+
stopsOn: ['surfaceOff', 'membersOnly'],
|
|
109
|
+
},
|
|
110
|
+
conversationIds,
|
|
111
|
+
options,
|
|
55
112
|
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function pollHeads<H extends HeadCounters>(source: HeadSource<H>, wanted: readonly string[], options: PollHeadOptions<H>): DiscussionHeadPoller {
|
|
116
|
+
const base = Math.max(1000, options.intervalMs ?? POLL_INTERVAL_MS)
|
|
117
|
+
const ids = [...new Set((Array.isArray(wanted) ? wanted : []).filter((id): id is string => typeof id === 'string' && id !== ''))].slice(0, source.max)
|
|
56
118
|
const visible =
|
|
57
119
|
options.visible ?? ((): boolean => typeof document === 'undefined' || document.visibilityState !== 'hidden')
|
|
58
|
-
const last = new Map<string,
|
|
120
|
+
const last = new Map<string, H>()
|
|
59
121
|
let timer: ReturnType<typeof setTimeout> | null = null
|
|
60
122
|
let inFlight: AbortController | null = null
|
|
61
123
|
let failureDelay = 0
|
|
@@ -89,15 +151,15 @@ export function pollDiscussionHead(
|
|
|
89
151
|
const controller = new AbortController()
|
|
90
152
|
inFlight = controller
|
|
91
153
|
const call: CommunityCallOptions = { signal: controller.signal }
|
|
92
|
-
const r = await
|
|
154
|
+
const r = await source.ask(ids, call)
|
|
93
155
|
inFlight = null
|
|
94
156
|
if (stopped) return
|
|
95
157
|
if (r.ok) {
|
|
96
158
|
failureDelay = 0
|
|
97
|
-
const changed:
|
|
159
|
+
const changed: H[] = []
|
|
98
160
|
for (const head of Array.isArray(r.value.heads) ? r.value.heads : []) {
|
|
99
|
-
|
|
100
|
-
|
|
161
|
+
const key = source.keyOf(head)
|
|
162
|
+
if (key === null) continue
|
|
101
163
|
const before = last.get(key)
|
|
102
164
|
last.set(key, head)
|
|
103
165
|
if (!before || !sameHead(before, head)) changed.push(head)
|
|
@@ -117,7 +179,7 @@ export function pollDiscussionHead(
|
|
|
117
179
|
} catch {
|
|
118
180
|
// As above.
|
|
119
181
|
}
|
|
120
|
-
if (r.code
|
|
182
|
+
if (source.stopsOn.includes(r.code)) return stop()
|
|
121
183
|
if (r.code === 'fast' || r.code === 'quota') {
|
|
122
184
|
hold(Math.max(base, r.retryAfterS !== undefined ? r.retryAfterS * 1000 : RATE_LIMITED_WAIT_MS))
|
|
123
185
|
return
|