@blogmcp/sdk 0.13.0 → 0.14.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/links.d.ts +6 -0
- package/dist/community/links.js +9 -1
- package/dist/community/outcome.d.ts +1 -1
- package/dist/community/outcome.js +60 -23
- package/dist/community/private/browser.d.ts +18 -0
- package/dist/community/private/browser.js +17 -0
- package/dist/community/private/client.d.ts +259 -0
- package/dist/community/private/client.js +98 -0
- package/dist/community/private/dm.d.ts +547 -0
- package/dist/community/private/dm.js +852 -0
- package/dist/community/private/dpop.d.ts +59 -0
- package/dist/community/private/dpop.js +46 -0
- package/dist/community/private/encoding.d.ts +17 -0
- package/dist/community/private/encoding.js +50 -0
- package/dist/community/private/host-state.d.ts +20 -0
- package/dist/community/private/host-state.js +15 -0
- package/dist/community/private/index.d.ts +51 -0
- package/dist/community/private/index.js +71 -0
- package/dist/community/private/keystore.d.ts +73 -0
- package/dist/community/private/keystore.js +91 -0
- package/dist/community/private/marker.d.ts +17 -0
- package/dist/community/private/marker.js +11 -0
- package/dist/community/private/private-routes.d.ts +6 -0
- package/dist/community/private/private-routes.js +72 -0
- package/dist/community/private/promise.d.ts +65 -0
- package/dist/community/private/promise.js +39 -0
- package/dist/community/private/realtime.d.ts +127 -0
- package/dist/community/private/realtime.js +199 -0
- package/dist/community/private/session.d.ts +175 -0
- package/dist/community/private/session.js +441 -0
- package/dist/community/private/transport.d.ts +47 -0
- package/dist/community/private/transport.js +65 -0
- package/dist/community/server/grant-handoff.d.ts +53 -0
- package/dist/community/server/grant-handoff.js +96 -0
- package/dist/community/server/grant.d.ts +100 -0
- package/dist/community/server/grant.js +165 -0
- package/dist/community/server/index.d.ts +4 -0
- package/dist/community/server/index.js +20 -16
- package/dist/community/shapes.d.ts +27 -1
- package/dist/community/shapes.js +27 -17
- package/package.json +7 -3
- package/src/community/links.ts +8 -0
- package/src/community/outcome.ts +37 -0
- package/src/community/private/browser.ts +31 -0
- package/src/community/private/client.ts +304 -0
- package/src/community/private/dm.ts +1687 -0
- package/src/community/private/dpop.ts +110 -0
- package/src/community/private/encoding.ts +71 -0
- package/src/community/private/host-state.ts +37 -0
- package/src/community/private/index.ts +169 -0
- package/src/community/private/keystore.ts +179 -0
- package/src/community/private/marker.ts +28 -0
- package/src/community/private/private-routes.ts +80 -0
- package/src/community/private/promise.ts +125 -0
- package/src/community/private/realtime.ts +431 -0
- package/src/community/private/session.ts +848 -0
- package/src/community/private/transport.ts +125 -0
- package/src/community/server/grant-handoff.ts +179 -0
- package/src/community/server/grant.ts +292 -0
- package/src/community/server/index.ts +6 -0
- package/src/community/shapes.ts +46 -1
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DM client (docs/internal/m4-contracts.md §7.8 DM8a): the member's 1:1 messages over the private session
|
|
3
|
+
* (session.ts) — the inbox, opening a conversation, the messages with their delta by `rev`, sending under a
|
|
4
|
+
* `clientMsgId` with endless retries and jitter, edit, delete for everyone, hide for me, clear, read, typing, the
|
|
5
|
+
* requests, private blocks, the audience check, reports with their preview, the member's private cases, statements and
|
|
6
|
+
* appeals, and the private export. The elements (`@blogmcp/community/private`, DM8b) render on it; a host that renders
|
|
7
|
+
* its own UI uses it directly.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const client = createPrivateClient({ kbOrigin, grantPath, member })
|
|
11
|
+
* const dm = createPrivateDmClient(client)
|
|
12
|
+
* const thread = dm.thread(conversationId)
|
|
13
|
+
* thread.subscribe((state) => render(state.messages, state.pending))
|
|
14
|
+
* await thread.loadLatest()
|
|
15
|
+
* thread.send('Dobrý den') // retried until kb-api takes it or refuses it for good
|
|
16
|
+
* realtime.subscribe((event) => dm.apply(event)) // the inbox's content-free events move the open threads
|
|
17
|
+
* // …and in the host's sign-out flow, before privateSignOut(client):
|
|
18
|
+
* dm.close()
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* **Nothing leaves the device but the call itself.** A draft lives in this tab's memory only (`drafts`): never in
|
|
22
|
+
* IndexedDB, `sessionStorage`, `localStorage`, a cookie or a request — the member's unsent words are not the server's,
|
|
23
|
+
* and an unsent draft that outlived the tab on a shared browser would be readable by the next person. Sending moves the
|
|
24
|
+
* text into the outbox (memory too), which holds it only until kb-api takes it. Decrypted messages exist in this
|
|
25
|
+
* client's memory for as long as a thread is open and are dropped by `thread.close()` and `close()`. Nothing here logs,
|
|
26
|
+
* tracks or reports (§9.3): a refusal is a code, never a text.
|
|
27
|
+
*
|
|
28
|
+
* **Sending.** `send()` names the message with a fresh `clientMsgId` (a v4 uuid) that every retry repeats, so kb-api
|
|
29
|
+
* stores it once however many attempts reach it (`UNIQUE (conversation_id, author_member_id, client_msg_id)`). An
|
|
30
|
+
* outage a retry can cure — no answer, a timeout, a gateway's 5xx page, `BUSY`, `UNAVAILABLE`, `LEDGER_UNAVAILABLE` —
|
|
31
|
+
* is retried without end, after an exponentially growing wait with jitter (`PRIVATE_DM_RETRY`), so that the member's
|
|
32
|
+
* phone in a tunnel delivers the message once it is out of it, and a thousand phones coming back at once do not knock
|
|
33
|
+
* in step. A refusal that may or may not pass by itself — `TOO_FAST`, `INTERNAL`, an edge's 408 or 429 page — is
|
|
34
|
+
* retried only while the waits after such refusals add up to less than `PRIVATE_DM_RETRY.boundedMs` — an outage in
|
|
35
|
+
* between does not start the count again, so refusals that alternate with outages still end — and then it stops as
|
|
36
|
+
* `failed` with its code:
|
|
37
|
+
* kb-api answers `TOO_FAST` both for its per-second and per-minute limiters and for caps that last the day (the
|
|
38
|
+
* per-recipient message cap, the request caps; §5.1, §7.3), without a Retry-After, so an endless retry of a day-long
|
|
39
|
+
* cap would knock all day, spend the private session's limiter, fire the cap's alert on every attempt and deliver the
|
|
40
|
+
* message a day late without the member knowing; a deterministic 500 on one message would loop for as long as the tab
|
|
41
|
+
* stays open. The member's `outbox.retry()` starts a new count. Any other refusal is final at once (`failed`, with
|
|
42
|
+
* its code): `DM_NOT_ALLOWED`, `VALIDATION`, a quota, a device that is pending, removed or restricted, a session the
|
|
43
|
+
* host no longer has. The messages of one conversation go out one at a time and in order; a message retried by hand
|
|
44
|
+
* keeps its place. `cancel()` stops the retries of one message (it may already be stored, if an earlier attempt
|
|
45
|
+
* reached kb-api and its answer was lost); `retryNow()` (the browser came back online) wakes every waiting message at
|
|
46
|
+
* once.
|
|
47
|
+
*
|
|
48
|
+
* **The delta by `rev`.** A thread keeps each message at the highest `rev` it has seen: an answer that carries an older
|
|
49
|
+
* revision than the one shown never replaces it, whatever order answers arrive in. The inbox's events (`{ k, c, s }`,
|
|
50
|
+
* Appendix A.3) carry no content: `m` reads what is newer than the newest loaded message, `e` and `d` re-read the one
|
|
51
|
+
* message (`sinceRev`: the revision already shown), `rd` moves the read mark, `t` shows „píše…“ for a few seconds, and
|
|
52
|
+
* `resync` re-reads every loaded message, because the socket missed events while it was away.
|
|
53
|
+
*
|
|
54
|
+
* The operations are kb-api's private surface (Appendix A.2): DM3 serves the conversations, requests, blocks, the
|
|
55
|
+
* audience check and the settings, DM4 the messages, DM5 the reports, cases, statements and appeals, DM7b the export.
|
|
56
|
+
* Until kb-api serves an operation it sits in `PRIVATE_DM_OPS_AHEAD` (the drift spec's ledger, as `PRIVATE_OPS_AHEAD`
|
|
57
|
+
* in client.ts). DM3's and DM4's answers follow their routes (`routes/private/{dm,requests,blocks,audience,dm-messages}.ts`); the others
|
|
58
|
+
* follow the contract's text until their slice pins them. Every answer is checked before it is passed on: a single
|
|
59
|
+
* answer outside the vocabulary is `BAD_ANSWER`, a list row this client cannot read is left out.
|
|
60
|
+
*/
|
|
61
|
+
import type { DeletedMemberAuthor, MemberAuthor } from '../shapes.js';
|
|
62
|
+
import type { PrivateRealtimeEvent } from './realtime.js';
|
|
63
|
+
import type { PrivateCode, PrivateFailure, PrivateOutcome, PrivateSession } from './session.js';
|
|
64
|
+
/** Every DM operation this client calls (the path after `/community/v1/private/`, Appendix A.2). */
|
|
65
|
+
export declare const PRIVATE_DM_OPS: readonly ["dm/list", "dm/open", "dm/messages", "dm/send", "dm/edit", "dm/delete", "dm/hide", "dm/clear", "dm/read", "dm/typing", "requests/list", "requests/accept", "requests/delete", "requests/block-report", "blocks/add", "blocks/remove", "blocks/list", "audience/check", "reports/preview", "reports/submit", "cases/list", "cases/get", "statements/get", "appeals/submit", "export/download"];
|
|
66
|
+
export type PrivateDmOp = (typeof PRIVATE_DM_OPS)[number];
|
|
67
|
+
/** The slice of the contract that serves an operation kb-api does not serve yet. */
|
|
68
|
+
export type PrivateDmSlice = 'DM3' | 'DM4' | 'DM5' | 'DM7b';
|
|
69
|
+
/**
|
|
70
|
+
* The operations built ahead of kb-api, by the slice that serves them (§7.3–§7.7). The drift spec fails on an entry
|
|
71
|
+
* kb-api already serves (the copy `PRIVATE_ROUTES` names it) and on one Appendix A.2 does not name; the integration
|
|
72
|
+
* that regenerates `PRIVATE_ROUTES` after a slice lands removes that slice's entries here.
|
|
73
|
+
*/
|
|
74
|
+
export declare const PRIVATE_DM_OPS_AHEAD: Readonly<Partial<Record<PrivateDmOp, PrivateDmSlice>>>;
|
|
75
|
+
/** `dm/messages` takes at most this many messages per page (§7.4). */
|
|
76
|
+
export declare const PRIVATE_DM_PAGE_MAX = 50;
|
|
77
|
+
/** At most one `dm/typing` per conversation in this interval: kb-api publishes at most one per 3 s (§7.4). */
|
|
78
|
+
export declare const PRIVATE_DM_TYPING_INTERVAL_MS = 3000;
|
|
79
|
+
/** How long a counterpart's „píše…“ shows after their last `t` event (a little over two of their intervals). */
|
|
80
|
+
export declare const PRIVATE_DM_TYPING_SHOW_MS = 7000;
|
|
81
|
+
/**
|
|
82
|
+
* The send retries' wait: before attempt n+1 (n ≥ 1) a ceiling of `min(maxMs, baseMs · 2^(n−1))`, of which the wait
|
|
83
|
+
* is a random half to whole (the jitter keeps clients that failed together from retrying together). `boundedMs`: how
|
|
84
|
+
* long a run of bounded refusals (`isBoundedDmFailure`) is retried before the send stops — two minutes, so that a
|
|
85
|
+
* per-minute limiter (`private_messages_per_minute`) has passed by the last attempt, and a day-long cap costs nine to
|
|
86
|
+
* thirteen attempts (with the jitter) instead of thousands.
|
|
87
|
+
*/
|
|
88
|
+
export declare const PRIVATE_DM_RETRY: Readonly<{
|
|
89
|
+
baseMs: 1000;
|
|
90
|
+
maxMs: 30000;
|
|
91
|
+
boundedMs: 120000;
|
|
92
|
+
}>;
|
|
93
|
+
/** A thread re-reads at most this many pages at once (a `resync`, a long gap after `m`); the rest on the next event. */
|
|
94
|
+
export declare const PRIVATE_DM_REREAD_PAGES = 20;
|
|
95
|
+
/**
|
|
96
|
+
* The refusals a retry can cure. `NETWORK` (no answer, a timeout, CORS) and a `BAD_ANSWER` with no status, a 5xx (a
|
|
97
|
+
* gateway's page), a 408 or a 429 (an edge's timeout or rate-limit page) included; every other code is final.
|
|
98
|
+
*/
|
|
99
|
+
export declare const PRIVATE_DM_RETRYABLE: ReadonlySet<string>;
|
|
100
|
+
/**
|
|
101
|
+
* The retryable refusals that are retried only for `PRIVATE_DM_RETRY.boundedMs` in a row (see the module doc):
|
|
102
|
+
* `TOO_FAST` may be a day-long cap, and `INTERNAL` may be a fault that every attempt meets again.
|
|
103
|
+
*/
|
|
104
|
+
export declare const PRIVATE_DM_RETRY_BOUNDED: ReadonlySet<string>;
|
|
105
|
+
/** True when a send that failed with this refusal is to be tried again. */
|
|
106
|
+
export declare function isRetryableDmFailure(failure: Pick<PrivateFailure, 'code' | 'status'>): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* True when a retryable refusal is retried only within `PRIVATE_DM_RETRY.boundedMs`: an edge's 408 or 429, and a
|
|
109
|
+
* `BAD_ANSWER` with no status. The last is never kb-api's: the session reports it for a fault of its own on this device
|
|
110
|
+
* (a base the grant did not name, an access token it cannot use), which every attempt meets again, so an endless retry
|
|
111
|
+
* of it would knock for as long as the tab stays open.
|
|
112
|
+
*/
|
|
113
|
+
export declare function isBoundedDmFailure(failure: Pick<PrivateFailure, 'code' | 'status'>): boolean;
|
|
114
|
+
/** The SDK's own code for a send the member or the host stopped (`cancel()`, `close()`). */
|
|
115
|
+
export type PrivateDmClientCode = 'CANCELLED';
|
|
116
|
+
export type PrivateDmFailure = PrivateFailure | {
|
|
117
|
+
ok: false;
|
|
118
|
+
code: PrivateDmClientCode;
|
|
119
|
+
status: null;
|
|
120
|
+
};
|
|
121
|
+
/** What a send resolves to: kb-api's stored message, a final refusal, or `CANCELLED`. */
|
|
122
|
+
export type PrivateDmSendOutcome = {
|
|
123
|
+
ok: true;
|
|
124
|
+
value: {
|
|
125
|
+
message: PrivateDmMessage;
|
|
126
|
+
};
|
|
127
|
+
} | PrivateDmFailure;
|
|
128
|
+
/**
|
|
129
|
+
* The other member of a conversation: their profile card, never more (§7.3) — the public surface's author shape, as
|
|
130
|
+
* DM3 answers it; an erased member, or one without a profile, is the deleted placeholder.
|
|
131
|
+
*/
|
|
132
|
+
export type PrivateDmCounterpart = MemberAuthor | DeletedMemberAuthor;
|
|
133
|
+
/** A conversation of the inbox (`dm/list`): its counterpart, its last activity and the unread count — never a body. */
|
|
134
|
+
export interface PrivateDmConversation {
|
|
135
|
+
readonly conversationId: string;
|
|
136
|
+
/** `request`: a request the member sent that is not accepted yet (a received one is in `requests.list`). */
|
|
137
|
+
readonly state: 'open' | 'request';
|
|
138
|
+
readonly counterpart: PrivateDmCounterpart;
|
|
139
|
+
/** The later of the last message and the conversation's creation. */
|
|
140
|
+
readonly lastActivityAt: string;
|
|
141
|
+
readonly lastSeq: number;
|
|
142
|
+
/** The counterpart's messages after the member's read mark (kb-api stops counting at 99). */
|
|
143
|
+
readonly unread: number;
|
|
144
|
+
}
|
|
145
|
+
/** `dm/open`: the member's one conversation with that person — a new or an existing one. */
|
|
146
|
+
export interface PrivateDmOpened {
|
|
147
|
+
readonly conversationId: string;
|
|
148
|
+
readonly state: 'open' | 'request';
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A message as a participant reads it. `deleted`: its author deleted it for everyone (a tombstone, no text);
|
|
152
|
+
* `removed`: a decision removed it („odstraněno“ for both, no text, the row kept for the case).
|
|
153
|
+
*/
|
|
154
|
+
export declare const PRIVATE_DM_MESSAGE_STATES: readonly ["visible", "deleted", "removed"];
|
|
155
|
+
export type PrivateDmMessageState = (typeof PRIVATE_DM_MESSAGE_STATES)[number];
|
|
156
|
+
export interface PrivateDmMessage {
|
|
157
|
+
readonly conversationId: string;
|
|
158
|
+
readonly seq: number;
|
|
159
|
+
readonly id: string;
|
|
160
|
+
readonly rev: number;
|
|
161
|
+
/** The member wrote it. */
|
|
162
|
+
readonly mine: boolean;
|
|
163
|
+
readonly replyToSeq: number | null;
|
|
164
|
+
readonly state: PrivateDmMessageState;
|
|
165
|
+
/** The decrypted text; null on a tombstone and on a removed message. */
|
|
166
|
+
readonly text: string | null;
|
|
167
|
+
/** „upraveno“. */
|
|
168
|
+
readonly editedMark: boolean;
|
|
169
|
+
readonly createdAt: string;
|
|
170
|
+
readonly editedAt: string | null;
|
|
171
|
+
/** The member's own message: the id its send named, when kb-api echoes it (it lets a pending copy settle early). */
|
|
172
|
+
readonly clientMsgId: string | null;
|
|
173
|
+
}
|
|
174
|
+
/** `dm/messages`' body: the newest page, a page before `beforeSeq`, or the messages after `afterSeq`. */
|
|
175
|
+
export interface PrivateDmMessagesQuery {
|
|
176
|
+
readonly conversationId: string;
|
|
177
|
+
readonly afterSeq?: number;
|
|
178
|
+
readonly beforeSeq?: number;
|
|
179
|
+
/** 1…50 (default 50). */
|
|
180
|
+
readonly limit?: number;
|
|
181
|
+
/** The revision already shown: kb-api may leave out a message whose `rev` is not newer. */
|
|
182
|
+
readonly sinceRev?: number;
|
|
183
|
+
}
|
|
184
|
+
export interface PrivateDmPage {
|
|
185
|
+
/** Ascending by `seq`; a row this client cannot read (a state it does not know, a malformed one) is left out. */
|
|
186
|
+
readonly messages: readonly PrivateDmMessage[];
|
|
187
|
+
/** More beyond this page in the direction asked (the page was full when kb-api did not say). */
|
|
188
|
+
readonly hasMore: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* How far the counterpart has read, when read receipts are mutual (DM4's `counterpartReadSeq`); null when they are
|
|
191
|
+
* not — nothing is told —, and undefined when the answer did not say (a kb-api before DM4's field).
|
|
192
|
+
*/
|
|
193
|
+
readonly counterpartReadSeq?: number | null;
|
|
194
|
+
}
|
|
195
|
+
/** A read mark's outcome: whether `dm/read` was asked, and how many of the conversation's notifications it read. */
|
|
196
|
+
export interface PrivateDmReadResult {
|
|
197
|
+
readonly sent: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* The conversation's unread `dm_message`/`dm_request` notifications kb-api marked read with the cursor (0 when
|
|
200
|
+
* nothing was asked): the host refreshes its unread dot only when this is more than 0.
|
|
201
|
+
*/
|
|
202
|
+
readonly notificationsRead: number;
|
|
203
|
+
}
|
|
204
|
+
export interface PrivateDmSendInput {
|
|
205
|
+
readonly conversationId: string;
|
|
206
|
+
readonly text: string;
|
|
207
|
+
readonly replyToSeq?: number;
|
|
208
|
+
}
|
|
209
|
+
export interface PrivateDmEditInput {
|
|
210
|
+
readonly conversationId: string;
|
|
211
|
+
readonly seq: number;
|
|
212
|
+
/** The revision the member edited: kb-api refuses an edit of a text that changed since. */
|
|
213
|
+
readonly rev: number;
|
|
214
|
+
readonly text: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* One message on its way out (memory only): `queued` behind an earlier message of its conversation (nothing was asked
|
|
218
|
+
* yet), `sending` (an attempt is out), `waiting` for its next attempt, or `failed` for good.
|
|
219
|
+
*/
|
|
220
|
+
export interface PrivateDmPendingSend {
|
|
221
|
+
readonly clientMsgId: string;
|
|
222
|
+
readonly conversationId: string;
|
|
223
|
+
readonly text: string;
|
|
224
|
+
readonly replyToSeq: number | null;
|
|
225
|
+
readonly state: 'queued' | 'sending' | 'waiting' | 'failed';
|
|
226
|
+
readonly attempts: number;
|
|
227
|
+
/** The last refusal (a `waiting` message says why it waits; a `failed` one why it stopped). */
|
|
228
|
+
readonly lastCode: PrivateCode | null;
|
|
229
|
+
}
|
|
230
|
+
/** A send in progress: its id at once, its end when kb-api takes it or refuses it for good. */
|
|
231
|
+
export interface PrivateDmSending {
|
|
232
|
+
readonly clientMsgId: string;
|
|
233
|
+
readonly done: Promise<PrivateDmSendOutcome>;
|
|
234
|
+
/** Stop retrying (see the module doc: an earlier attempt may already have been stored). */
|
|
235
|
+
cancel(): void;
|
|
236
|
+
}
|
|
237
|
+
/** A request the member received (`requests/list`): the sender's card, for „Přijmout“ / „Smazat“ / „Zablokovat a nahlásit“. */
|
|
238
|
+
export interface PrivateDmRequest {
|
|
239
|
+
readonly conversationId: string;
|
|
240
|
+
/** The sender. */
|
|
241
|
+
readonly from: PrivateDmCounterpart;
|
|
242
|
+
readonly createdAt: string;
|
|
243
|
+
readonly lastMessageAt: string | null;
|
|
244
|
+
}
|
|
245
|
+
/** A private-context block (`blocks/list`). */
|
|
246
|
+
export interface PrivateDmBlock {
|
|
247
|
+
readonly memberId: string;
|
|
248
|
+
readonly author: PrivateDmCounterpart;
|
|
249
|
+
readonly blockedAt: string;
|
|
250
|
+
}
|
|
251
|
+
/** `audience/check`: whether the member may write to that handle directly, only by a request, or not at all. */
|
|
252
|
+
export interface PrivateDmAudience {
|
|
253
|
+
readonly canWrite: 'direct' | 'request' | 'no';
|
|
254
|
+
}
|
|
255
|
+
/** The report's line: the tenant's rules (the authorised persons under U18, else blogmcp T&S) or illegal content. */
|
|
256
|
+
export type PrivateDmReportLine = 'rules' | 'illegal';
|
|
257
|
+
export interface PrivateDmReportTarget {
|
|
258
|
+
readonly conversationId: string;
|
|
259
|
+
/** The reported message: the package is the contiguous range that ends with it. */
|
|
260
|
+
readonly seq: number;
|
|
261
|
+
readonly line: PrivateDmReportLine;
|
|
262
|
+
}
|
|
263
|
+
/** Who receives the package („kdo to dostane“): the authorised persons by name, or blogmcp's T&S. */
|
|
264
|
+
export type PrivateDmReportRecipients = {
|
|
265
|
+
readonly kind: 'authorised_persons';
|
|
266
|
+
readonly names: readonly string[];
|
|
267
|
+
} | {
|
|
268
|
+
readonly kind: 'platform_ts';
|
|
269
|
+
};
|
|
270
|
+
/** `reports/preview`: exactly what goes to whom (§7.5). */
|
|
271
|
+
export interface PrivateDmReportPreview {
|
|
272
|
+
readonly messages: readonly PrivateDmMessage[];
|
|
273
|
+
readonly recipients: PrivateDmReportRecipients;
|
|
274
|
+
}
|
|
275
|
+
export interface PrivateDmReportInput extends PrivateDmReportTarget {
|
|
276
|
+
readonly category: string;
|
|
277
|
+
/** The reporter's note (kb-api keeps it encrypted under the case's key). */
|
|
278
|
+
readonly text?: string;
|
|
279
|
+
/**
|
|
280
|
+
* Block the reported sender too. The form shows the box ticked (§7.5: "the sender is blocked automatically (can be
|
|
281
|
+
* unticked …)"), so the SDK sends `true` unless the reporter unticked it.
|
|
282
|
+
*/
|
|
283
|
+
readonly block?: boolean;
|
|
284
|
+
}
|
|
285
|
+
export interface PrivateDmBlockReportInput {
|
|
286
|
+
readonly conversationId: string;
|
|
287
|
+
readonly category: string;
|
|
288
|
+
readonly text?: string;
|
|
289
|
+
}
|
|
290
|
+
/** One of the member's private cases (`cases/list`, `cases/get`): codes and times only, the fields DM5 pins. */
|
|
291
|
+
export interface PrivateDmCase {
|
|
292
|
+
readonly caseId: string;
|
|
293
|
+
readonly state: string;
|
|
294
|
+
readonly line: PrivateDmReportLine;
|
|
295
|
+
readonly openedAt: string;
|
|
296
|
+
/** The decision's id once decided (`statements/get`, `appeals/submit` take it). */
|
|
297
|
+
readonly decisionId: string | null;
|
|
298
|
+
}
|
|
299
|
+
/** A statement of reasons about a private case (`statements/get`). */
|
|
300
|
+
export interface PrivateDmStatement {
|
|
301
|
+
readonly decisionId: string;
|
|
302
|
+
readonly statement: string;
|
|
303
|
+
readonly decidedAt: string;
|
|
304
|
+
/** Until when an appeal is taken (`private_appeal_window_months`). */
|
|
305
|
+
readonly closesAt: string | null;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* `export/download`: on a managed blog the export itself; on a headless site only `{ confirmSent: true }` — the
|
|
309
|
+
* export is confirmed from the e-mail and downloaded on the account host, never through the tenant's origin (§7.7).
|
|
310
|
+
* The session's `call` reads JSON only: an export that kb-api streams (§7.7, a managed blog) needs a streaming read
|
|
311
|
+
* that DM7b pins with its route; until then the client reads a JSON answer and anything else is `BAD_ANSWER`.
|
|
312
|
+
*/
|
|
313
|
+
export type PrivateDmExport = {
|
|
314
|
+
readonly confirmSent: true;
|
|
315
|
+
} | {
|
|
316
|
+
readonly confirmSent?: false;
|
|
317
|
+
readonly export: Readonly<Record<string, unknown>>;
|
|
318
|
+
};
|
|
319
|
+
/** The member's drafts, in this tab's memory only (see the module doc). */
|
|
320
|
+
export interface PrivateDmDrafts {
|
|
321
|
+
get(conversationId: string): string;
|
|
322
|
+
/** An empty text deletes the draft. */
|
|
323
|
+
set(conversationId: string, text: string): void;
|
|
324
|
+
delete(conversationId: string): void;
|
|
325
|
+
/** Every draft of this client. */
|
|
326
|
+
clear(): void;
|
|
327
|
+
}
|
|
328
|
+
/** What a thread shows. */
|
|
329
|
+
export interface PrivateDmThreadState {
|
|
330
|
+
readonly conversationId: string;
|
|
331
|
+
/** Ascending by `seq`, each at the highest revision seen; hidden and cleared ones are gone. */
|
|
332
|
+
readonly messages: readonly PrivateDmMessage[];
|
|
333
|
+
/**
|
|
334
|
+
* The member's messages still on their way, in the order they were sent (a message retried by hand keeps its
|
|
335
|
+
* place; the ones written after it may have gone out while it stood failed).
|
|
336
|
+
*/
|
|
337
|
+
readonly pending: readonly PrivateDmPendingSend[];
|
|
338
|
+
/** Older messages remain (`loadOlder`). */
|
|
339
|
+
readonly hasOlder: boolean;
|
|
340
|
+
readonly loading: boolean;
|
|
341
|
+
/** The newest page was read at least once. */
|
|
342
|
+
readonly loaded: boolean;
|
|
343
|
+
/**
|
|
344
|
+
* How far the counterpart has read (receipts flow only when both members turned them on, §7.4): from the pages'
|
|
345
|
+
* `counterpartReadSeq` — so „Přečteno“ shows as soon as the thread opens — and moved forward by each live `rd`. A page
|
|
346
|
+
* that says receipts are not mutual (null) clears it.
|
|
347
|
+
*/
|
|
348
|
+
readonly readUpTo: number | null;
|
|
349
|
+
/** The counterpart is typing („píše…“). */
|
|
350
|
+
readonly typing: boolean;
|
|
351
|
+
/** The last refusal of a load (null after a load that succeeded). */
|
|
352
|
+
readonly error: PrivateCode | null;
|
|
353
|
+
}
|
|
354
|
+
export type PrivateDmThreadListener = (state: PrivateDmThreadState) => void;
|
|
355
|
+
export interface PrivateDmThread {
|
|
356
|
+
readonly conversationId: string;
|
|
357
|
+
state(): PrivateDmThreadState;
|
|
358
|
+
/** Called at once with the current state and on every change; returns the unsubscribe. */
|
|
359
|
+
subscribe(listener: PrivateDmThreadListener): () => void;
|
|
360
|
+
/** The newest page. */
|
|
361
|
+
loadLatest(): Promise<PrivateOutcome<null>>;
|
|
362
|
+
/** The page before the oldest loaded message. */
|
|
363
|
+
loadOlder(): Promise<PrivateOutcome<null>>;
|
|
364
|
+
/** Everything after the newest loaded message. */
|
|
365
|
+
loadNewer(): Promise<PrivateOutcome<null>>;
|
|
366
|
+
/** Re-read every loaded message (after a `resync`). */
|
|
367
|
+
refresh(): Promise<PrivateOutcome<null>>;
|
|
368
|
+
/** One inbox event about this conversation (`dm.apply` routes them here). */
|
|
369
|
+
apply(event: PrivateRealtimeEvent): void;
|
|
370
|
+
/** Send into this conversation; the draft of it goes (its text moved into the outbox). */
|
|
371
|
+
send(text: string, options?: {
|
|
372
|
+
replyToSeq?: number;
|
|
373
|
+
}): PrivateDmSending;
|
|
374
|
+
/** `dm/read` up to the newest loaded message (only ever forward). */
|
|
375
|
+
markRead(): Promise<PrivateOutcome<PrivateDmReadResult>>;
|
|
376
|
+
/** Forget this thread's messages (pending sends go on). */
|
|
377
|
+
close(): void;
|
|
378
|
+
}
|
|
379
|
+
/** What an inbox event asks of a host besides the open threads (`dmEventEffect`). */
|
|
380
|
+
export type PrivateDmEventEffect =
|
|
381
|
+
/** The inbox list and its unread counts may have changed: re-read them. */
|
|
382
|
+
'inbox'
|
|
383
|
+
/** Only an open thread changes (an edit): the inbox's counts stay. */
|
|
384
|
+
| 'thread'
|
|
385
|
+
/** „píše…“: nothing to re-read. */
|
|
386
|
+
| 'typing'
|
|
387
|
+
/** A read receipt: nothing to re-read. */
|
|
388
|
+
| 'receipt'
|
|
389
|
+
/** Not a DM event (an account event of §6.3): the private view's own business. */
|
|
390
|
+
| 'other';
|
|
391
|
+
/** The DM kinds of the inbox channel's events (Appendix A.3). */
|
|
392
|
+
export declare const PRIVATE_DM_EVENT_KINDS: readonly ["m", "e", "d", "t", "rq", "rd", "resync"];
|
|
393
|
+
/**
|
|
394
|
+
* What a host does with one inbox event beyond `dm.apply`: only `m`, `d`, `rq` and `resync` can move the inbox's list
|
|
395
|
+
* or its unread counts — a typing or a read event re-reads nothing, so a busy conversation never spends the private
|
|
396
|
+
* session's limiter on counts that did not move.
|
|
397
|
+
*/
|
|
398
|
+
export declare function dmEventEffect(event: Pick<PrivateRealtimeEvent, 'k'>): PrivateDmEventEffect;
|
|
399
|
+
export interface PrivateDmClientOptions {
|
|
400
|
+
/** The send retries' wait and the bounded refusals' window (default `PRIVATE_DM_RETRY`). */
|
|
401
|
+
retry?: {
|
|
402
|
+
baseMs?: number;
|
|
403
|
+
maxMs?: number;
|
|
404
|
+
boundedMs?: number;
|
|
405
|
+
};
|
|
406
|
+
/** For the jitter (default `Math.random`). */
|
|
407
|
+
random?: () => number;
|
|
408
|
+
/** For `clientMsgId` (default `crypto.randomUUID`). */
|
|
409
|
+
randomUUID?: () => string;
|
|
410
|
+
now?: () => number;
|
|
411
|
+
/**
|
|
412
|
+
* The member's own id (the host's `me/get`), when the host knows it. An `rd` event whose `r` names the member is the
|
|
413
|
+
* member's own read on another device, not the counterpart's receipt: it moves this client's read mark and never
|
|
414
|
+
* the thread's `readUpTo`, which says how far the OTHER participant has read.
|
|
415
|
+
*/
|
|
416
|
+
self?: () => string | null;
|
|
417
|
+
}
|
|
418
|
+
export interface PrivateDmClient {
|
|
419
|
+
/**
|
|
420
|
+
* One page of the inbox, newest activity first (a pending device sees only conversations active since it exists,
|
|
421
|
+
* §5.10); `nextCursor` asks for the next page. A row this client cannot read is left out.
|
|
422
|
+
*/
|
|
423
|
+
inbox(cursor?: string): Promise<PrivateOutcome<{
|
|
424
|
+
items: readonly PrivateDmConversation[];
|
|
425
|
+
nextCursor: string | null;
|
|
426
|
+
}>>;
|
|
427
|
+
/** The conversation with the member behind `handle`: an existing one, a new one, or a request (§7.3). */
|
|
428
|
+
open(handle: string): Promise<PrivateOutcome<PrivateDmOpened>>;
|
|
429
|
+
/** One page of messages (the threads use it; a host that keeps its own state may too). */
|
|
430
|
+
messages(query: PrivateDmMessagesQuery): Promise<PrivateOutcome<PrivateDmPage>>;
|
|
431
|
+
/** Send with retries (see the module doc). */
|
|
432
|
+
send(input: PrivateDmSendInput): PrivateDmSending;
|
|
433
|
+
edit(input: PrivateDmEditInput): Promise<PrivateOutcome<{
|
|
434
|
+
message: PrivateDmMessage;
|
|
435
|
+
}>>;
|
|
436
|
+
/** Delete for everyone, within `private_delete_for_all_hours` (`DELETE_WINDOW` after it: offer `hide`). */
|
|
437
|
+
delete(input: {
|
|
438
|
+
conversationId: string;
|
|
439
|
+
seq: number;
|
|
440
|
+
}): Promise<PrivateOutcome<{
|
|
441
|
+
message: PrivateDmMessage;
|
|
442
|
+
}>>;
|
|
443
|
+
/** Delete for me („smazat u mě“). */
|
|
444
|
+
hide(input: {
|
|
445
|
+
conversationId: string;
|
|
446
|
+
seq: number;
|
|
447
|
+
}): Promise<PrivateOutcome<null>>;
|
|
448
|
+
/** Clear the conversation for me. */
|
|
449
|
+
clear(conversationId: string): Promise<PrivateOutcome<null>>;
|
|
450
|
+
/**
|
|
451
|
+
* Move the member's read mark to `seq`; a mark that is not further than the last one sent asks nothing. kb-api reads
|
|
452
|
+
* the conversation's own notifications up to the mark with it (`notificationsRead`).
|
|
453
|
+
*/
|
|
454
|
+
read(conversationId: string, seq: number): Promise<PrivateOutcome<PrivateDmReadResult>>;
|
|
455
|
+
/** „píše…“: at most one call per conversation in `PRIVATE_DM_TYPING_INTERVAL_MS`; the others ask nothing. */
|
|
456
|
+
typing(conversationId: string): Promise<PrivateOutcome<{
|
|
457
|
+
sent: boolean;
|
|
458
|
+
}>>;
|
|
459
|
+
readonly requests: {
|
|
460
|
+
/** The requests the member received, a page at a time (a row this client cannot read is left out). */
|
|
461
|
+
list(cursor?: string): Promise<PrivateOutcome<{
|
|
462
|
+
items: readonly PrivateDmRequest[];
|
|
463
|
+
nextCursor: string | null;
|
|
464
|
+
}>>;
|
|
465
|
+
accept(conversationId: string): Promise<PrivateOutcome<null>>;
|
|
466
|
+
/** The request goes, with its conversation (§7.3). */
|
|
467
|
+
delete(conversationId: string): Promise<PrivateOutcome<null>>;
|
|
468
|
+
/** „Zablokovat a nahlásit“: the snapshot, the case, the block, then the request goes (§7.5). */
|
|
469
|
+
blockReport(input: PrivateDmBlockReportInput): Promise<PrivateOutcome<{
|
|
470
|
+
caseId: string;
|
|
471
|
+
}>>;
|
|
472
|
+
};
|
|
473
|
+
readonly blocks: {
|
|
474
|
+
add(memberId: string): Promise<PrivateOutcome<null>>;
|
|
475
|
+
remove(memberId: string): Promise<PrivateOutcome<null>>;
|
|
476
|
+
list(): Promise<PrivateOutcome<{
|
|
477
|
+
blocks: readonly PrivateDmBlock[];
|
|
478
|
+
}>>;
|
|
479
|
+
};
|
|
480
|
+
readonly audience: {
|
|
481
|
+
check(handle: string): Promise<PrivateOutcome<PrivateDmAudience>>;
|
|
482
|
+
};
|
|
483
|
+
readonly reports: {
|
|
484
|
+
preview(target: PrivateDmReportTarget): Promise<PrivateOutcome<PrivateDmReportPreview>>;
|
|
485
|
+
submit(input: PrivateDmReportInput): Promise<PrivateOutcome<{
|
|
486
|
+
caseId: string;
|
|
487
|
+
}>>;
|
|
488
|
+
};
|
|
489
|
+
readonly cases: {
|
|
490
|
+
list(cursor?: string): Promise<PrivateOutcome<{
|
|
491
|
+
items: readonly PrivateDmCase[];
|
|
492
|
+
nextCursor: string | null;
|
|
493
|
+
}>>;
|
|
494
|
+
get(caseId: string): Promise<PrivateOutcome<{
|
|
495
|
+
case: PrivateDmCase;
|
|
496
|
+
}>>;
|
|
497
|
+
};
|
|
498
|
+
readonly statements: {
|
|
499
|
+
get(decisionId: string): Promise<PrivateOutcome<PrivateDmStatement>>;
|
|
500
|
+
};
|
|
501
|
+
readonly appeals: {
|
|
502
|
+
submit(input: {
|
|
503
|
+
decisionId: string;
|
|
504
|
+
text: string;
|
|
505
|
+
}): Promise<PrivateOutcome<{
|
|
506
|
+
appealId: string;
|
|
507
|
+
submittedAt: string;
|
|
508
|
+
}>>;
|
|
509
|
+
};
|
|
510
|
+
readonly export: {
|
|
511
|
+
download(): Promise<PrivateOutcome<PrivateDmExport>>;
|
|
512
|
+
};
|
|
513
|
+
readonly drafts: PrivateDmDrafts;
|
|
514
|
+
readonly outbox: {
|
|
515
|
+
/** The pending sends, of one conversation or of all. */
|
|
516
|
+
pending(conversationId?: string): readonly PrivateDmPendingSend[];
|
|
517
|
+
/** Try every waiting message now (the browser came back online, the realtime socket reconnected). */
|
|
518
|
+
retryNow(): void;
|
|
519
|
+
/**
|
|
520
|
+
* Send a `failed` message again under its `clientMsgId`, in its old place in the conversation's order: the new
|
|
521
|
+
* send (its `done` is the retried message's end), or null when no failed message has that id.
|
|
522
|
+
*/
|
|
523
|
+
retry(clientMsgId: string): PrivateDmSending | null;
|
|
524
|
+
/** Drop a `failed` message (or stop and drop a pending one). */
|
|
525
|
+
discard(clientMsgId: string): boolean;
|
|
526
|
+
};
|
|
527
|
+
/** The thread of one conversation (one per conversation while it is open). */
|
|
528
|
+
thread(conversationId: string): PrivateDmThread;
|
|
529
|
+
/** One inbox event: routed to the open thread it names, `resync` to every open thread. */
|
|
530
|
+
apply(event: PrivateRealtimeEvent): PrivateDmEventEffect;
|
|
531
|
+
/**
|
|
532
|
+
* Drop everything this client holds — drafts, the outbox (its sends end `CANCELLED`), every thread's messages — and
|
|
533
|
+
* stop its timers. Hosts call it when the private view unmounts and before `privateSignOut`.
|
|
534
|
+
*/
|
|
535
|
+
close(): void;
|
|
536
|
+
}
|
|
537
|
+
/** The one thing the DM client needs of the private client: its session's `call`. */
|
|
538
|
+
export type PrivateDmClientSource = {
|
|
539
|
+
readonly session: Pick<PrivateSession, 'call'>;
|
|
540
|
+
};
|
|
541
|
+
/**
|
|
542
|
+
* One message of an answer as the thread keeps it, or null for a row this client cannot read: a state it does not
|
|
543
|
+
* know (an open enum: a later kb-api may add one), a visible row without text, a malformed id, seq or rev, or a row of
|
|
544
|
+
* another conversation.
|
|
545
|
+
*/
|
|
546
|
+
export declare function privateDmMessageOf(raw: unknown, conversationId?: string): PrivateDmMessage | null;
|
|
547
|
+
export declare function createPrivateDmClient(source: PrivateDmClientSource, options?: PrivateDmClientOptions): PrivateDmClient;
|