@blogmcp/sdk 0.12.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.
Files changed (75) hide show
  1. package/dist/community/links.d.ts +6 -0
  2. package/dist/community/links.js +9 -1
  3. package/dist/community/outcome.d.ts +1 -1
  4. package/dist/community/outcome.js +60 -23
  5. package/dist/community/private/browser.d.ts +18 -0
  6. package/dist/community/private/browser.js +17 -0
  7. package/dist/community/private/client.d.ts +259 -0
  8. package/dist/community/private/client.js +98 -0
  9. package/dist/community/private/dm.d.ts +547 -0
  10. package/dist/community/private/dm.js +852 -0
  11. package/dist/community/private/dpop.d.ts +59 -0
  12. package/dist/community/private/dpop.js +46 -0
  13. package/dist/community/private/encoding.d.ts +17 -0
  14. package/dist/community/private/encoding.js +50 -0
  15. package/dist/community/private/host-state.d.ts +20 -0
  16. package/dist/community/private/host-state.js +15 -0
  17. package/dist/community/private/index.d.ts +51 -0
  18. package/dist/community/private/index.js +71 -0
  19. package/dist/community/private/keystore.d.ts +73 -0
  20. package/dist/community/private/keystore.js +91 -0
  21. package/dist/community/private/marker.d.ts +17 -0
  22. package/dist/community/private/marker.js +11 -0
  23. package/dist/community/private/private-routes.d.ts +6 -0
  24. package/dist/community/private/private-routes.js +72 -0
  25. package/dist/community/private/promise.d.ts +65 -0
  26. package/dist/community/private/promise.js +39 -0
  27. package/dist/community/private/realtime.d.ts +127 -0
  28. package/dist/community/private/realtime.js +199 -0
  29. package/dist/community/private/session.d.ts +175 -0
  30. package/dist/community/private/session.js +441 -0
  31. package/dist/community/private/transport.d.ts +47 -0
  32. package/dist/community/private/transport.js +65 -0
  33. package/dist/community/server/grant-handoff.d.ts +53 -0
  34. package/dist/community/server/grant-handoff.js +96 -0
  35. package/dist/community/server/grant.d.ts +100 -0
  36. package/dist/community/server/grant.js +165 -0
  37. package/dist/community/server/index.d.ts +4 -0
  38. package/dist/community/server/index.js +20 -16
  39. package/dist/community/shapes.d.ts +27 -1
  40. package/dist/community/shapes.js +27 -17
  41. package/dist/core/client.d.ts +9 -0
  42. package/dist/core/client.js +54 -50
  43. package/dist/core/index.d.ts +2 -0
  44. package/dist/core/index.js +113 -103
  45. package/dist/core/queries.d.ts +1 -0
  46. package/dist/core/queries.js +76 -71
  47. package/dist/core/review/types.d.ts +7 -0
  48. package/dist/core/style-layers.d.ts +88 -0
  49. package/dist/core/style-layers.js +69 -0
  50. package/package.json +7 -3
  51. package/src/community/links.ts +8 -0
  52. package/src/community/outcome.ts +37 -0
  53. package/src/community/private/browser.ts +31 -0
  54. package/src/community/private/client.ts +304 -0
  55. package/src/community/private/dm.ts +1687 -0
  56. package/src/community/private/dpop.ts +110 -0
  57. package/src/community/private/encoding.ts +71 -0
  58. package/src/community/private/host-state.ts +37 -0
  59. package/src/community/private/index.ts +169 -0
  60. package/src/community/private/keystore.ts +179 -0
  61. package/src/community/private/marker.ts +28 -0
  62. package/src/community/private/private-routes.ts +80 -0
  63. package/src/community/private/promise.ts +125 -0
  64. package/src/community/private/realtime.ts +431 -0
  65. package/src/community/private/session.ts +848 -0
  66. package/src/community/private/transport.ts +125 -0
  67. package/src/community/server/grant-handoff.ts +179 -0
  68. package/src/community/server/grant.ts +292 -0
  69. package/src/community/server/index.ts +6 -0
  70. package/src/community/shapes.ts +46 -1
  71. package/src/core/client.ts +12 -0
  72. package/src/core/index.ts +14 -0
  73. package/src/core/queries.ts +8 -0
  74. package/src/core/review/types.ts +8 -0
  75. package/src/core/style-layers.ts +169 -0
@@ -57,6 +57,12 @@ export declare const COMMUNITY_ROUTES: Readonly<{
57
57
  readonly topic: "/community/t/{id}";
58
58
  /** The forum's search. */
59
59
  readonly search: "/community/search";
60
+ /** The private view (the dock's „Soukromé zprávy"), client-only. */
61
+ readonly messages: "/community/messages";
62
+ /** The grant route (POST, `createPrivateGrantHandler`): the page's private SDK posts its key's thumbprint. */
63
+ readonly grant: "/community/grant";
64
+ /** The provider_page hand-off (GET, `createPrivateGrantHandoff`): the account host's `/zpravy` navigates here. */
65
+ readonly grantHandoff: "/community/grant/handoff";
60
66
  }>;
61
67
  /** A notifier's receipt: kb-api's `kbnt_` capability token (≤ 512 characters, base64url). */
62
68
  export declare const COMMUNITY_RECEIPT_RE: RegExp;
@@ -33,7 +33,15 @@ const c = Object.freeze({
33
33
  /** A topic; `{id}` is its conversation id (topicPath), a message's anchor in the fragment (topicMessageLink). */
34
34
  topic: "/community/t/{id}",
35
35
  /** The forum's search. */
36
- search: "/community/search"
36
+ search: "/community/search",
37
+ // M4 PU1 (m4-contracts.md §6.1, A.2): the private view and the two grant routes the host's server serves. The
38
+ // storefront names its own (`/komunita/zpravy`, `/komunita/grant`, `/komunita/grant/handoff`).
39
+ /** The private view (the dock's „Soukromé zprávy"), client-only. */
40
+ messages: "/community/messages",
41
+ /** The grant route (POST, `createPrivateGrantHandler`): the page's private SDK posts its key's thumbprint. */
42
+ grant: "/community/grant",
43
+ /** The provider_page hand-off (GET, `createPrivateGrantHandoff`): the account host's `/zpravy` navigates here. */
44
+ grantHandoff: "/community/grant/handoff"
37
45
  }), y = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, d = /^kbnt_[A-Za-z0-9_-]{1,507}$/, h = "t";
38
46
  function i(t) {
39
47
  return typeof t == "string" && /^\/(?![/\\])/.test(t) && !/[\s\\\u0000-\u001f\u007f]/.test(t);
@@ -51,7 +51,7 @@ export type CommunityOutcome<T> = {
51
51
  * Every code kb-api's community routers answer: their own, and the member, trust and quota codes they pass
52
52
  * through. A copy of `COMMUNITY_API_CODES` in kb-api's `routes/community-codes.ts`, in its order.
53
53
  */
54
- export declare const COMMUNITY_API_CODES: readonly ["SURFACE_OFF", "CUTOVER_NOT_MOVED", "NOT_FOUND", "ONBOARDING_REQUIRED", "AGE_BELOW_MINIMUM", "NAME_RESERVED", "NAME_BLOCKED", "HANDLE_TAKEN", "HANDLE_RATE", "POSTING_RESTRICTED", "ACCOUNT_SUSPENDED", "ACCOUNT_TERMINATED", "TOO_MANY_LINKS", "TOO_FAST", "FILTER_BLOCKED", "CONFIRMATION_REQUIRED", "MESSAGE_REMOVED", "REACTION_NOT_ALLOWED", "CAPTCHA_FAILED", "UNAUTHORIZED", "VALIDATION", "UNAVAILABLE", "STALE_LEASE", "STAFF_POSTING_OFF", "PRESET_CONFLICT", "INTERNAL", "MODULE_DARK", "MODULE_READ_ONLY", "BRAKED", "BRAKE_PLATFORM", "MODULE_CONDITIONS", "TRUST_LEVEL_INVALID", "MENTION_LIMIT", "DIGEST_UNSUBSCRIBE_INVALID", "PUSH_ENDPOINT_REFUSED", "PUSH_LIMIT", "REALTIME_OFF", "BUSY", "BRAKE_KIND_MISMATCH", "MEMBERS_ONLY", "TOPIC_LOCKED", "TOPIC_CREATION_CLOSED", "BRAND_RESTRICTED", "CATEGORY_NOT_EMPTY", "SLUG_TAKEN", "MODERATOR_NOT_ELIGIBLE", "FOLLOW_LIMIT", "STALE_REVISION", "CASE_UNDECIDED", "NOT_A_MEMBER_SESSION", "IDENTITY_NOT_ADMITTED", "ACCOUNT_NOT_ELIGIBLE", "MEMBER_READ_ONLY", "MEMBER_DELETION_REQUESTED", "PRIVATE_SPACE", "WRONG_PROVIDER", "CASE_CLOSED", "NOTIFIER_NOT_ALLOWED", "UNSUPPORTED_RESTRICTION", "LADDER_EXCEEDED", "PERSON_REQUIRED", "APPEAL_OPEN", "APPEAL_WINDOW_CLOSED", "APPEAL_NEEDS_ANOTHER_PERSON", "GAG_PLATFORM_ONLY", "ORDER_FINAL", "BODY_JSON_INVALID", "AUDIT_DETAIL_NOT_CODE", "LEDGER_UNAVAILABLE", "INVALID_INPUT", "LEGAL_HOLD", "TEXT_MISSING", "AGE16_NOT_ALLOWED", "QUOTA_DAILY", "QUOTA_IP_HOURLY"];
54
+ export declare const COMMUNITY_API_CODES: readonly ["SURFACE_OFF", "CUTOVER_NOT_MOVED", "NOT_FOUND", "ONBOARDING_REQUIRED", "AGE_BELOW_MINIMUM", "NAME_RESERVED", "NAME_BLOCKED", "HANDLE_TAKEN", "HANDLE_RATE", "POSTING_RESTRICTED", "ACCOUNT_SUSPENDED", "ACCOUNT_TERMINATED", "TOO_MANY_LINKS", "TOO_FAST", "FILTER_BLOCKED", "CONFIRMATION_REQUIRED", "MESSAGE_REMOVED", "REACTION_NOT_ALLOWED", "CAPTCHA_FAILED", "UNAUTHORIZED", "VALIDATION", "UNAVAILABLE", "STALE_LEASE", "STAFF_POSTING_OFF", "PRESET_CONFLICT", "INTERNAL", "MODULE_DARK", "MODULE_READ_ONLY", "BRAKED", "BRAKE_PLATFORM", "MODULE_CONDITIONS", "TRUST_LEVEL_INVALID", "MENTION_LIMIT", "DIGEST_UNSUBSCRIBE_INVALID", "PUSH_ENDPOINT_REFUSED", "PUSH_LIMIT", "REALTIME_OFF", "BUSY", "BRAKE_KIND_MISMATCH", "MEMBERS_ONLY", "TOPIC_LOCKED", "TOPIC_CREATION_CLOSED", "BRAND_RESTRICTED", "CATEGORY_NOT_EMPTY", "SLUG_TAKEN", "MODERATOR_NOT_ELIGIBLE", "FOLLOW_LIMIT", "STALE_REVISION", "CASE_UNDECIDED", "DPOP_INVALID", "DPOP_NONCE", "GRANT_INVALID", "PRIVATE_IDENTITY", "DEVICE_PENDING", "DEVICE_REMOVED", "APPROVAL_INVALID", "APPROVAL_EXHAUSTED", "ADDRESS_REQUIRED", "ADDRESS_LOCKED", "ACTIVATION_REQUIRED", "TEXT_CHANGED", "DM_NOT_ALLOWED", "EDIT_WINDOW", "DELETE_WINDOW", "PRIVATE_RESTRICTED", "STEP_UP_REQUIRED", "NOT_A_MEMBER_SESSION", "IDENTITY_NOT_ADMITTED", "ACCOUNT_NOT_ELIGIBLE", "MEMBER_READ_ONLY", "MEMBER_DELETION_REQUESTED", "PRIVATE_SPACE", "WRONG_PROVIDER", "CASE_CLOSED", "NOTIFIER_NOT_ALLOWED", "UNSUPPORTED_RESTRICTION", "LADDER_EXCEEDED", "PERSON_REQUIRED", "APPEAL_OPEN", "APPEAL_WINDOW_CLOSED", "APPEAL_NEEDS_ANOTHER_PERSON", "GAG_PLATFORM_ONLY", "ORDER_FINAL", "BODY_JSON_INVALID", "AUDIT_DETAIL_NOT_CODE", "LEDGER_UNAVAILABLE", "INVALID_INPUT", "LEGAL_HOLD", "TEXT_MISSING", "AGE16_NOT_ALLOWED", "QUOTA_DAILY", "QUOTA_IP_HOURLY"];
55
55
  /** A code kb-api's community routers answer. */
56
56
  export type CommunityApiCode = (typeof COMMUNITY_API_CODES)[number];
57
57
  /**
@@ -1,4 +1,4 @@
1
- const t = [
1
+ const N = [
2
2
  /** The host refused the method (a programming error: every operation is a POST). */
3
3
  "method",
4
4
  /** The host refused the request's origin (the page and its API are on different sites). */
@@ -68,11 +68,11 @@ const t = [
68
68
  "followLimit",
69
69
  /** Anything else: "that did not work, try again". */
70
70
  "submit"
71
- ], D = new Set(t);
72
- function e(E) {
73
- return typeof E == "string" && D.has(E);
71
+ ], t = new Set(N);
72
+ function S(E) {
73
+ return typeof E == "string" && t.has(E);
74
74
  }
75
- const r = [
75
+ const e = [
76
76
  "SURFACE_OFF",
77
77
  "CUTOVER_NOT_MOVED",
78
78
  "NOT_FOUND",
@@ -122,6 +122,23 @@ const r = [
122
122
  "FOLLOW_LIMIT",
123
123
  "STALE_REVISION",
124
124
  "CASE_UNDECIDED",
125
+ "DPOP_INVALID",
126
+ "DPOP_NONCE",
127
+ "GRANT_INVALID",
128
+ "PRIVATE_IDENTITY",
129
+ "DEVICE_PENDING",
130
+ "DEVICE_REMOVED",
131
+ "APPROVAL_INVALID",
132
+ "APPROVAL_EXHAUSTED",
133
+ "ADDRESS_REQUIRED",
134
+ "ADDRESS_LOCKED",
135
+ "ACTIVATION_REQUIRED",
136
+ "TEXT_CHANGED",
137
+ "DM_NOT_ALLOWED",
138
+ "EDIT_WINDOW",
139
+ "DELETE_WINDOW",
140
+ "PRIVATE_RESTRICTED",
141
+ "STEP_UP_REQUIRED",
125
142
  "NOT_A_MEMBER_SESSION",
126
143
  "IDENTITY_NOT_ADMITTED",
127
144
  "ACCOUNT_NOT_ELIGIBLE",
@@ -148,7 +165,7 @@ const r = [
148
165
  "AGE16_NOT_ALLOWED",
149
166
  "QUOTA_DAILY",
150
167
  "QUOTA_IP_HOURLY"
151
- ], T = Object.freeze({
168
+ ], I = Object.freeze({
152
169
  SURFACE_OFF: "surfaceOff",
153
170
  CUTOVER_NOT_MOVED: "notMoved",
154
171
  NOT_FOUND: "notFound",
@@ -218,6 +235,26 @@ const r = [
218
235
  // CASE_UNDECIDED: the team's adverse-events/close while the case's message is held by no decision (decide it first).
219
236
  STALE_REVISION: "submit",
220
237
  CASE_UNDECIDED: "submit",
238
+ // M4 PX0 (m4-contracts.md Appendix A.6): the private, account, grant and staff surfaces' codes. No public, notice or
239
+ // forum operation produces them, and the private client that meets them (`@blogmcp/sdk/community/private`, PU1)
240
+ // handles most itself (a fresh nonce, a new key on DEVICE_REMOVED) — so here, as every code no element meets, `submit`.
241
+ DPOP_INVALID: "submit",
242
+ DPOP_NONCE: "submit",
243
+ GRANT_INVALID: "submit",
244
+ PRIVATE_IDENTITY: "submit",
245
+ DEVICE_PENDING: "submit",
246
+ DEVICE_REMOVED: "submit",
247
+ APPROVAL_INVALID: "submit",
248
+ APPROVAL_EXHAUSTED: "submit",
249
+ ADDRESS_REQUIRED: "submit",
250
+ ADDRESS_LOCKED: "submit",
251
+ ACTIVATION_REQUIRED: "submit",
252
+ TEXT_CHANGED: "submit",
253
+ DM_NOT_ALLOWED: "submit",
254
+ EDIT_WINDOW: "submit",
255
+ DELETE_WINDOW: "submit",
256
+ PRIVATE_RESTRICTED: "submit",
257
+ STEP_UP_REQUIRED: "submit",
221
258
  // 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.
222
259
  NOT_A_MEMBER_SESSION: "signIn",
223
260
  IDENTITY_NOT_ADMITTED: "signIn",
@@ -250,33 +287,33 @@ const r = [
250
287
  AGE16_NOT_ALLOWED: "submit",
251
288
  QUOTA_DAILY: "quota",
252
289
  QUOTA_IP_HOURLY: "quota"
253
- }), S = ["METHOD", "ORIGIN", "TOO_LARGE", "INVALID_JSON"], I = Object.freeze({
290
+ }), r = ["METHOD", "ORIGIN", "TOO_LARGE", "INVALID_JSON"], T = Object.freeze({
254
291
  METHOD: "method",
255
292
  ORIGIN: "origin",
256
293
  TOO_LARGE: "invalid",
257
294
  INVALID_JSON: "invalid"
258
- }), A = (E, O) => Object.prototype.hasOwnProperty.call(E, O);
295
+ }), A = (E, _) => Object.prototype.hasOwnProperty.call(E, _);
259
296
  function s(E) {
260
- return typeof E != "string" || E === "" ? "submit" : A(T, E) ? T[E] : A(I, E) ? I[E] : "submit";
297
+ return typeof E != "string" || E === "" ? "submit" : A(I, E) ? I[E] : A(T, E) ? T[E] : "submit";
261
298
  }
262
- const N = /* @__PURE__ */ Symbol.for("@blogmcp/sdk/CommunityTransportError");
263
- function L(E) {
299
+ const D = /* @__PURE__ */ Symbol.for("@blogmcp/sdk/CommunityTransportError");
300
+ function R(E) {
264
301
  return typeof E == "number" && Number.isInteger(E) && E >= 100 && E <= 599 ? E : null;
265
302
  }
266
- function i(E) {
303
+ function L(E) {
267
304
  return typeof E == "number" && Number.isFinite(E) && E >= 0 ? Math.ceil(E) : null;
268
305
  }
269
- class R extends Error {
306
+ class i extends Error {
270
307
  /** The HTTP status, or null when there was no response (network, timeout). */
271
308
  status;
272
309
  /** Seconds to wait before retrying (`Retry-After`), or null. */
273
310
  retryAfterS;
274
- constructor(O, _ = {}) {
275
- super(O), this.name = "CommunityTransportError", this.status = L(_.status), this.retryAfterS = i(_.retryAfterS), Object.defineProperty(this, N, { value: !0 });
311
+ constructor(_, O = {}) {
312
+ super(_), this.name = "CommunityTransportError", this.status = R(O.status), this.retryAfterS = L(O.retryAfterS), Object.defineProperty(this, D, { value: !0 });
276
313
  }
277
314
  }
278
315
  function n(E) {
279
- return E instanceof R ? !0 : E instanceof Error && E[N] === !0;
316
+ return E instanceof i ? !0 : E instanceof Error && E[D] === !0;
280
317
  }
281
318
  function u(E) {
282
319
  return n(E) && E.retryAfterS !== null ? { ok: !1, code: "unavailable", retryAfterS: E.retryAfterS } : { ok: !1, code: "unavailable" };
@@ -285,15 +322,15 @@ function C(E) {
285
322
  return E === "unavailable" || E === "submit" || E === "method" || E === "origin" || E === "invalid" || E === "ledger";
286
323
  }
287
324
  export {
288
- r as COMMUNITY_API_CODES,
289
- S as COMMUNITY_HOST_CODES,
290
- I as COMMUNITY_OUTCOME_OF_HOST,
291
- T as COMMUNITY_OUTCOME_OF_KB,
292
- t as COMMUNITY_UI_CODES,
293
- R as CommunityTransportError,
325
+ e as COMMUNITY_API_CODES,
326
+ r as COMMUNITY_HOST_CODES,
327
+ T as COMMUNITY_OUTCOME_OF_HOST,
328
+ I as COMMUNITY_OUTCOME_OF_KB,
329
+ N as COMMUNITY_UI_CODES,
330
+ i as CommunityTransportError,
294
331
  u as communityFailureOf,
295
332
  s as communityOutcomeOf,
296
333
  n as isCommunityTransportError,
297
- e as isCommunityUiCode,
334
+ S as isCommunityUiCode,
298
335
  C as isLoggedCommunityOutcome
299
336
  };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The private entry runs in a browser only (docs/internal/m4-contracts.md §6.1, §7.7). Its key lives in IndexedDB and
3
+ * signs with WebCrypto, and the whole point of the device key is that it never leaves the member's browser: a copy of
4
+ * this code running on a server (an SSR pass of the host, a worker of the tenant's backend) would hold a key the
5
+ * member never approved and could not tell apart from their own device. So the entry refuses to load where `window`,
6
+ * `indexedDB` or `crypto.subtle` is missing — a structural test imports it on a server and expects the throw.
7
+ *
8
+ * Every module that holds or uses browser state calls `assertPrivateBrowser()` at load, not only the entry's index:
9
+ * the package is `sideEffects: false`, so a bundler may import a leaf module directly and skip the index.
10
+ */
11
+ /** The message of the throw, so a host's error page can tell the case from a bug. */
12
+ export declare const PRIVATE_SERVER_IMPORT_MESSAGE: string;
13
+ /** True where the private entry may run: a global `window`, `indexedDB` and WebCrypto's `subtle`. */
14
+ export declare function isPrivateBrowser(): boolean;
15
+ /** Throws everywhere but in a browser (see the module doc). */
16
+ export declare function assertPrivateBrowser(): void;
17
+ /** WebCrypto's SubtleCrypto, read on every use (a test replaces the global between cases). */
18
+ export declare function subtle(): SubtleCrypto;
@@ -0,0 +1,17 @@
1
+ const n = "[blogmcp-sdk] @blogmcp/sdk/community/private runs only in a browser (it needs window, indexedDB and crypto.subtle): the device key must never exist on a server. Import it from client-only code.";
2
+ function o() {
3
+ const e = globalThis;
4
+ return typeof e.window < "u" && e.window !== null && typeof e.indexedDB < "u" && e.indexedDB !== null && !!e.crypto?.subtle;
5
+ }
6
+ function t() {
7
+ if (!o()) throw new Error(n);
8
+ }
9
+ function r() {
10
+ return globalThis.crypto.subtle;
11
+ }
12
+ export {
13
+ n as PRIVATE_SERVER_IMPORT_MESSAGE,
14
+ t as assertPrivateBrowser,
15
+ o as isPrivateBrowser,
16
+ r as subtle
17
+ };
@@ -0,0 +1,259 @@
1
+ /**
2
+ * The private client (docs/internal/m4-contracts.md §6.1): the M0d and M2b operations of the private surface as typed
3
+ * functions over one private session (session.ts). M4's DM operations land in DM8a's file.
4
+ *
5
+ * The operations come from kb-api's list (`PRIVATE_ROUTES`, the generated copy of
6
+ * `community-private-routes.json`). Some are built here before kb-api serves them — today the private settings
7
+ * (DM3, wave 9) — and those sit in `PRIVATE_OPS_AHEAD`, a ledger the drift spec checks against
8
+ * Appendix A.2 of the contract until kb-api's list names them, and then insists they leave it. The answer types of the
9
+ * operations kb-api serves follow its routes' answers (`routes/private/{state,devices,approval,address,activation}.ts`
10
+ * and their services, PS3 and PS4); those still ahead follow the contract's text until their slice pins them.
11
+ */
12
+ import type { PrivateSurfaceState } from '../shapes.js';
13
+ import type { PrivateRealtimeTokenAnswer } from './realtime.js';
14
+ import { type PrivateOutcome, type PrivateSession, type PrivateSessionConfig, type PrivateSessionInfo } from './session.js';
15
+ /** Every private operation this client calls (the path after `/community/v1/private/`). */
16
+ export declare const PRIVATE_CLIENT_OPS: readonly ["session", "session/refresh", "session/end", "state", "devices/list", "devices/sign-out", "devices/sign-out-all", "devices/forget", "devices/reads", "approval/start", "approval/pending", "approval/show", "approval/redeem", "approval/deny", "address/link", "activation/state", "activation/accept", "activation/withdraw", "realtime/token", "push/subscribe", "push/unsubscribe", "notifications/list", "notifications/unread-count", "notifications/mark-read", "settings/get", "settings/set"];
17
+ export type PrivateClientOp = (typeof PRIVATE_CLIENT_OPS)[number];
18
+ /**
19
+ * The operations built ahead of kb-api (see the module doc), by the slice that serves them. The drift spec fails on an
20
+ * entry kb-api already serves and on one Appendix A.2 does not name. PU3's six (realtime, push, notifications) left it
21
+ * at the wave-6 integration (m4-contracts.md C.8), when kb-api's list named them; the private settings (DM3's) left
22
+ * it at the wave-9 integration. Empty while kb-api serves every operation this client calls.
23
+ */
24
+ export declare const PRIVATE_OPS_AHEAD: Readonly<Record<string, 'DM3'>>;
25
+ /** A device's approval: the member's first device, one approved by another, or one still waiting. */
26
+ export type PrivateDeviceState = 'first' | 'approved' | 'pending';
27
+ /** `state` (§5.10): what the private view needs to know about this session before anything else. */
28
+ export interface PrivateStateAnswer {
29
+ /** Never `dark` here: a dark instance answers no private route at all. */
30
+ readonly privateState: Exclude<PrivateSurfaceState, 'dark'>;
31
+ readonly device: {
32
+ readonly state: PrivateDeviceState;
33
+ };
34
+ readonly address: {
35
+ readonly state: 'none' | 'pending' | 'verified';
36
+ readonly resetLockUntil: string | null;
37
+ };
38
+ /** Approval requests waiting for this member's approved devices (0 for a pending device). */
39
+ readonly approvals: {
40
+ readonly pending: number;
41
+ };
42
+ }
43
+ /** One of the member's devices (`devices/list`, §5.10): the signals a member checks a stranger by. */
44
+ export interface PrivateDevice {
45
+ readonly id: string;
46
+ readonly label: string;
47
+ readonly origin: string | null;
48
+ readonly mintKeyId: string | null;
49
+ /** The IP prefix of its sign-in and when it was. */
50
+ readonly signIn: {
51
+ readonly ipPrefix: string | null;
52
+ readonly at: string | null;
53
+ };
54
+ readonly createdAt: string;
55
+ readonly lastSeenAt: string;
56
+ readonly state: PrivateDeviceState;
57
+ /** The device asking. */
58
+ readonly this: boolean;
59
+ }
60
+ /** One hour of one device's reads (`devices/reads`, the last 90 days, newest first). */
61
+ export interface PrivateReadHour {
62
+ readonly deviceId: string;
63
+ readonly hour: string;
64
+ readonly reads: number;
65
+ }
66
+ /** A pending approval request an approved device sees (`approval/pending`). */
67
+ export interface PrivateApprovalRequest {
68
+ readonly approvalId: string;
69
+ readonly deviceId: string;
70
+ readonly label: string;
71
+ readonly origin: string | null;
72
+ readonly createdAt: string;
73
+ readonly expiresAt: string;
74
+ readonly via: 'code' | 'email';
75
+ /** The IP prefix the new device's `private/session` came from. */
76
+ readonly ipPrefix: string | null;
77
+ /** Whether that prefix equals the asking session's: the view warns before it shows a code when it is false. */
78
+ readonly sameNetwork: boolean;
79
+ }
80
+ /** `approval/start`'s answer: approved at once (the first device), or a request with its code or e-mail. */
81
+ export type PrivateApprovalStart = {
82
+ readonly state: 'approved';
83
+ } | {
84
+ readonly state: 'pending';
85
+ readonly via: 'code' | 'email';
86
+ readonly expiresAt: string;
87
+ readonly code?: string;
88
+ readonly notice?: string;
89
+ };
90
+ /** A text served for the activation (`activation/state`, §5.11). */
91
+ export interface PrivateLegalText {
92
+ readonly kind: string;
93
+ readonly id: string;
94
+ readonly version: string;
95
+ readonly locale: string;
96
+ readonly contentSha256: string;
97
+ readonly renderedSha256: string;
98
+ readonly effectiveAt: string | null;
99
+ readonly body: string;
100
+ readonly bodyJson: Readonly<Record<string, unknown>> | null;
101
+ readonly variants: readonly string[];
102
+ }
103
+ /** The member's activation as kb-api states it. */
104
+ export interface PrivateActivation {
105
+ readonly state: 'active' | 'needed' | 'refused';
106
+ readonly activatedAt: string | null;
107
+ }
108
+ export interface PrivateActivationState {
109
+ readonly texts: readonly PrivateLegalText[];
110
+ readonly announced: readonly PrivateLegalText[];
111
+ readonly art9: (PrivateLegalText & {
112
+ readonly state: string;
113
+ readonly layout: 'joint' | 'split';
114
+ }) | null;
115
+ /** Under `split`: the tenant's art. 9 text, when the member's consent to it is not in force. */
116
+ readonly art9Tenant: PrivateLegalText | null;
117
+ readonly activation: PrivateActivation;
118
+ readonly address: {
119
+ readonly state: 'none' | 'pending' | 'verified';
120
+ };
121
+ /** The session's and the member's values for the screen; the address masked (`j•••@s•••.cz`). */
122
+ readonly display: {
123
+ readonly approvalEmail: string | null;
124
+ readonly deviceLabel: string;
125
+ };
126
+ }
127
+ /** A text the member accepted or was shown: its id and the two hashes `activation/state` served. */
128
+ export interface PrivateTextProof {
129
+ readonly id: string;
130
+ readonly contentSha256: string;
131
+ readonly renderedSha256: string;
132
+ }
133
+ export interface PrivateActivationAccept {
134
+ readonly locale?: string;
135
+ readonly accepted: readonly PrivateTextProof[];
136
+ readonly art9: PrivateTextProof | {
137
+ readonly refused: true;
138
+ };
139
+ /** Under `split`: the tenant's art. 9 text, when `activation/state` served one. */
140
+ readonly art9Tenant?: PrivateTextProof;
141
+ readonly shown: readonly PrivateTextProof[];
142
+ }
143
+ /** `push/subscribe` (§6.3): the browser's `PushSubscription` in kb-api's words. */
144
+ export interface PrivatePushSubscription {
145
+ readonly endpoint: string;
146
+ readonly p256dh: string;
147
+ readonly auth: string;
148
+ }
149
+ /** One private notification (`notifications/list`, §6.3, C.8): a code and the ids it names, never content. */
150
+ export interface PrivateNotification {
151
+ readonly id: string;
152
+ readonly code: string;
153
+ readonly conversationId: string | null;
154
+ readonly seq: number | null;
155
+ readonly createdAt: string;
156
+ readonly readAt: string | null;
157
+ }
158
+ /** `notifications/list`'s body: the next page after `cursor`, only the unread ones when `unreadOnly`. */
159
+ export interface PrivateNotificationsQuery {
160
+ readonly cursor?: string;
161
+ readonly unreadOnly?: boolean;
162
+ }
163
+ /** `notifications/mark-read`'s body: the rows by id, or every row of the member. */
164
+ export type PrivateNotificationsMarkRead = {
165
+ readonly ids: readonly string[];
166
+ } | {
167
+ readonly all: true;
168
+ };
169
+ export interface PrivateClientConfig extends PrivateSessionConfig {
170
+ }
171
+ export interface PrivateClient {
172
+ readonly session: PrivateSession;
173
+ state(): Promise<PrivateOutcome<PrivateStateAnswer>>;
174
+ readonly devices: {
175
+ list(): Promise<PrivateOutcome<{
176
+ devices: readonly PrivateDevice[];
177
+ }>>;
178
+ signOut(deviceId: string): Promise<PrivateOutcome<Record<string, never>>>;
179
+ /** Every device but this one; `removed` counts them. */
180
+ signOutAll(): Promise<PrivateOutcome<{
181
+ removed: number;
182
+ }>>;
183
+ /** This device: kb-api removes it and the SDK deletes the key and the refresh token. */
184
+ forget(): Promise<PrivateOutcome<null>>;
185
+ reads(): Promise<PrivateOutcome<{
186
+ reads: readonly PrivateReadHour[];
187
+ }>>;
188
+ };
189
+ readonly approval: {
190
+ start(via: 'code' | 'email'): Promise<PrivateOutcome<PrivateApprovalStart>>;
191
+ pending(): Promise<PrivateOutcome<{
192
+ approvals: readonly PrivateApprovalRequest[];
193
+ }>>;
194
+ show(approvalId: string): Promise<PrivateOutcome<{
195
+ code: string;
196
+ expiresAt: string;
197
+ notice: string;
198
+ }>>;
199
+ redeem(code: string): Promise<PrivateOutcome<{
200
+ state: 'approved';
201
+ }>>;
202
+ deny(approvalId: string): Promise<PrivateOutcome<Record<string, never>>>;
203
+ };
204
+ /** The link to the account host where the member sets the approval address (`/adresa#t=kbas_…`). */
205
+ addressLink(): Promise<PrivateOutcome<{
206
+ url: string;
207
+ expiresAt: string;
208
+ }>>;
209
+ readonly activation: {
210
+ state(locale?: string): Promise<PrivateOutcome<PrivateActivationState>>;
211
+ /** On success the SDK asks the browser to persist this origin's storage (`navigator.storage.persist()`). */
212
+ accept(input: PrivateActivationAccept): Promise<PrivateOutcome<{
213
+ activation: PrivateActivation;
214
+ }>>;
215
+ withdraw(): Promise<PrivateOutcome<{
216
+ activation: {
217
+ state: PrivateActivation['state'];
218
+ };
219
+ }>>;
220
+ };
221
+ /** The private connection token (§6.3, C.8: `{ token, url, expiresInS }`); createPrivateRealtime renews it. */
222
+ readonly realtime: {
223
+ token(): Promise<PrivateOutcome<PrivateRealtimeTokenAnswer>>;
224
+ };
225
+ readonly push: {
226
+ /** C.8: `{ subscribed: true, keyId }` — the VAPID key the row was made for. */
227
+ subscribe(subscription: PrivatePushSubscription): Promise<PrivateOutcome<{
228
+ subscribed: true;
229
+ keyId: string;
230
+ }>>;
231
+ /** C.8: whether a private row of this member was removed. */
232
+ unsubscribe(endpoint: string): Promise<PrivateOutcome<{
233
+ unsubscribed: boolean;
234
+ }>>;
235
+ };
236
+ readonly notifications: {
237
+ list(body?: PrivateNotificationsQuery): Promise<PrivateOutcome<{
238
+ items: readonly PrivateNotification[];
239
+ nextCursor: string | null;
240
+ }>>;
241
+ unreadCount(): Promise<PrivateOutcome<{
242
+ count: number;
243
+ }>>;
244
+ markRead(body: PrivateNotificationsMarkRead): Promise<PrivateOutcome<{
245
+ updated: number;
246
+ }>>;
247
+ };
248
+ readonly settings: {
249
+ get(): Promise<PrivateOutcome<Record<string, unknown>>>;
250
+ set(values: Record<string, unknown>): Promise<PrivateOutcome<Record<string, unknown>>>;
251
+ };
252
+ }
253
+ export declare function createPrivateClient(config: PrivateClientConfig): PrivateClient;
254
+ /** A usable private session for this tab (A.9's name for `client.session.ensureSession()`). */
255
+ export declare function ensureSession(client: Pick<PrivateClient, 'session'>): Promise<PrivateOutcome<PrivateSessionInfo>>;
256
+ /** End this private session and delete its refresh token; the hosts call it in their sign-out flows (§5.9). */
257
+ export declare function privateSignOut(client: Pick<PrivateClient, 'session'>): Promise<PrivateOutcome<null>>;
258
+ /** Remove this device on kb-api and delete its key and refresh token from this browser. */
259
+ export declare function forgetDevice(client: Pick<PrivateClient, 'session'>): Promise<PrivateOutcome<null>>;
@@ -0,0 +1,98 @@
1
+ import { assertPrivateBrowser as n } from "./browser.js";
2
+ import { createPrivateSession as o } from "./session.js";
3
+ n();
4
+ const d = Object.freeze([
5
+ "session",
6
+ "session/refresh",
7
+ "session/end",
8
+ "state",
9
+ "devices/list",
10
+ "devices/sign-out",
11
+ "devices/sign-out-all",
12
+ "devices/forget",
13
+ "devices/reads",
14
+ "approval/start",
15
+ "approval/pending",
16
+ "approval/show",
17
+ "approval/redeem",
18
+ "approval/deny",
19
+ "address/link",
20
+ "activation/state",
21
+ "activation/accept",
22
+ "activation/withdraw",
23
+ "realtime/token",
24
+ "push/subscribe",
25
+ "push/unsubscribe",
26
+ "notifications/list",
27
+ "notifications/unread-count",
28
+ "notifications/mark-read",
29
+ "settings/get",
30
+ "settings/set"
31
+ ]), p = Object.freeze({});
32
+ function v(s) {
33
+ const a = o(s), t = (e, i = {}) => a.call(e, i);
34
+ return {
35
+ session: a,
36
+ state: () => t("state"),
37
+ devices: {
38
+ list: () => t("devices/list"),
39
+ signOut: (e) => t("devices/sign-out", { deviceId: e }),
40
+ signOutAll: () => t("devices/sign-out-all"),
41
+ forget: () => a.forget(),
42
+ reads: () => t("devices/reads")
43
+ },
44
+ approval: {
45
+ start: (e) => t("approval/start", { via: e }),
46
+ pending: () => t("approval/pending"),
47
+ show: (e) => t("approval/show", { approvalId: e }),
48
+ redeem: (e) => t("approval/redeem", { code: e }),
49
+ deny: (e) => t("approval/deny", { approvalId: e })
50
+ },
51
+ addressLink: () => t("address/link"),
52
+ activation: {
53
+ state: (e) => t("activation/state", e === void 0 ? {} : { locale: e }),
54
+ async accept(e) {
55
+ const i = await t("activation/accept", {
56
+ ...e.locale !== void 0 ? { locale: e.locale } : {},
57
+ accepted: e.accepted,
58
+ art9: e.art9,
59
+ ...e.art9Tenant !== void 0 ? { art9Tenant: e.art9Tenant } : {},
60
+ shown: e.shown
61
+ });
62
+ return i.ok && await a.activated(), i;
63
+ },
64
+ withdraw: () => t("activation/withdraw")
65
+ },
66
+ realtime: { token: () => t("realtime/token") },
67
+ push: {
68
+ subscribe: (e) => t("push/subscribe", { endpoint: e.endpoint, p256dh: e.p256dh, auth: e.auth }),
69
+ unsubscribe: (e) => t("push/unsubscribe", { endpoint: e })
70
+ },
71
+ notifications: {
72
+ list: (e = {}) => t("notifications/list", { ...e }),
73
+ unreadCount: () => t("notifications/unread-count"),
74
+ markRead: (e) => t("notifications/mark-read", { ...e })
75
+ },
76
+ settings: {
77
+ get: () => t("settings/get"),
78
+ set: (e) => t("settings/set", e)
79
+ }
80
+ };
81
+ }
82
+ function l(s) {
83
+ return s.session.ensureSession();
84
+ }
85
+ function u(s) {
86
+ return s.session.privateSignOut();
87
+ }
88
+ function g(s) {
89
+ return s.session.forget();
90
+ }
91
+ export {
92
+ d as PRIVATE_CLIENT_OPS,
93
+ p as PRIVATE_OPS_AHEAD,
94
+ v as createPrivateClient,
95
+ l as ensureSession,
96
+ g as forgetDevice,
97
+ u as privateSignOut
98
+ };