@commentkit/comment-kit 1.6.0 → 2.0.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 (136) hide show
  1. package/CHANGELOG.md +281 -597
  2. package/README.md +334 -154
  3. package/SECURITY.md +47 -46
  4. package/dist/node/THIRD_PARTY_NOTICES.txt +56 -0
  5. package/dist/node/browser.js +17 -0
  6. package/dist/node/cli/api.js +226 -0
  7. package/dist/node/cli/bin.js +18 -0
  8. package/dist/node/cli/credentials.js +268 -0
  9. package/dist/node/cli/doctor.js +725 -0
  10. package/dist/node/cli/format.js +54 -0
  11. package/dist/node/cli/init.js +372 -0
  12. package/dist/node/cli/main.js +519 -0
  13. package/dist/node/cli/mcp.js +114 -0
  14. package/dist/node/cli/open.js +20 -0
  15. package/dist/node/plugins/astro-B5y1Gtbf.js +31 -0
  16. package/dist/node/plugins/astro.js +26 -0
  17. package/dist/node/plugins/git-BIXLbL3f.js +92 -0
  18. package/dist/node/plugins/jsx-Bg4BdSph.js +7958 -0
  19. package/dist/node/plugins/next.js +48 -0
  20. package/dist/node/plugins/options-THop1K92.js +71 -0
  21. package/dist/node/plugins/transform-CKiAuSbk.js +1155 -0
  22. package/dist/node/plugins/vite-BdAYUW10.js +74 -0
  23. package/dist/node/plugins/vite.js +1 -0
  24. package/dist/node/plugins/webpack-R2U2DLlY.js +35 -0
  25. package/dist/node/plugins/webpack-loader.cjs +21 -0
  26. package/dist/node/plugins/webpack-loader.js +18 -0
  27. package/dist/node/plugins/webpack.js +1 -0
  28. package/dist/node/shared/endpoint.js +26 -0
  29. package/dist/node/shared/format.js +63 -0
  30. package/dist/node/types/astro.d.ts +11 -0
  31. package/dist/node/types/next.d.ts +34 -0
  32. package/dist/node/types/options.d.ts +59 -0
  33. package/dist/node/types/vite.d.ts +11 -0
  34. package/dist/node/types/webpack-loader.d.ts +22 -0
  35. package/dist/node/types/webpack.d.ts +27 -0
  36. package/dist/npm/THIRD_PARTY_NOTICES.txt +6 -6
  37. package/dist/npm/chunks/AgentSend-DxRJIYiz.js +68 -0
  38. package/dist/npm/chunks/Checklist-CnlfeSbc.js +282 -0
  39. package/dist/npm/chunks/Composer-B1bBVszY.js +725 -0
  40. package/dist/npm/chunks/Guest-vvNPz8h-.js +267 -0
  41. package/dist/npm/chunks/MarkupEditor-VCOXh9d2.js +338 -0
  42. package/dist/npm/chunks/Panel-F37vIL1K.js +1206 -0
  43. package/dist/npm/chunks/Settings-BGoZS2iV.js +231 -0
  44. package/dist/npm/chunks/Shortcuts-B2OMvczr.js +62 -0
  45. package/dist/npm/chunks/StyleEditor-CJ_d8Huf.js +46 -0
  46. package/dist/npm/chunks/StylePanel-yQzHHlY7.js +199 -0
  47. package/dist/npm/chunks/TaskFields-fmy6_HtK.js +289 -0
  48. package/dist/npm/chunks/ThreadCard-D51slKST.js +1113 -0
  49. package/dist/npm/chunks/Viewer-BOBadqmC.js +111 -0
  50. package/dist/npm/chunks/{agent-BDMQtOzH.js → agent-C1OQzBAm.js} +9 -9
  51. package/dist/npm/chunks/{anchor-BsradQhn.js → anchor-BsQNVkHj.js} +108 -85
  52. package/dist/npm/chunks/{ar-8tPch6W4.js → ar-CAJ3XT8e.js} +69 -19
  53. package/dist/npm/chunks/card-bits-CAnzrqx3.js +53 -0
  54. package/dist/npm/chunks/{client-EFTWxHbJ.js → client-kNAo2TTG.js} +282 -290
  55. package/dist/npm/chunks/confetti-CkBdSu19.js +49 -0
  56. package/dist/npm/chunks/context-B8UAzve0.js +20 -0
  57. package/dist/npm/chunks/context-BuMl7A07.js +48 -0
  58. package/dist/npm/chunks/{de-C63897uD.js → de-Dl18G48t.js} +60 -18
  59. package/dist/npm/chunks/dialog-GO04oC3D.js +3 -0
  60. package/dist/npm/chunks/dpop-U48QIQd7.js +96 -0
  61. package/dist/npm/chunks/drafts-B0ctr1g9.js +21 -0
  62. package/dist/npm/chunks/{es-CI2bSpvB.js → es-Dxk79lS9.js} +60 -18
  63. package/dist/npm/chunks/extension-CKFpPWmi.js +62 -0
  64. package/dist/npm/chunks/{extension-BST6LH1q.js → extension-E81hWyiT.js} +20 -12
  65. package/dist/npm/chunks/files-DyD5BZgp.js +114 -0
  66. package/dist/npm/chunks/{fr-rsVe-Lqk.js → fr-8BebGKYD.js} +118 -76
  67. package/dist/npm/chunks/{hi-cvwbSaWP.js → hi-BIN6Yy_p.js} +61 -19
  68. package/dist/npm/chunks/{i18n-C4v0M-6z.js → i18n-DOBt8e9U.js} +91 -56
  69. package/dist/npm/chunks/identify-CN-3xzqL.js +106 -0
  70. package/dist/npm/chunks/{it-C8tnV0BF.js → it-Cr6EwpPQ.js} +79 -37
  71. package/dist/npm/chunks/{ja-BWxDfC2f.js → ja-Iy3s5aur.js} +58 -16
  72. package/dist/npm/chunks/late-words-B2bmZceJ.js +12 -0
  73. package/dist/npm/chunks/live-CelVeZfP.js +85 -0
  74. package/dist/npm/chunks/locale-D8Q4Q2Nt.js +26 -0
  75. package/dist/npm/chunks/{nl-DNQ6eCht.js → nl-B84WHqqe.js} +61 -19
  76. package/dist/npm/chunks/page-key-DepmJzC1.js +62 -0
  77. package/dist/npm/chunks/{pick-CLyOdjnD.js → pick-yTyqtxN0.js} +45 -44
  78. package/dist/npm/chunks/pkce-ChKGSW_4.js +8 -0
  79. package/dist/npm/chunks/placement-BF_HOUDD.js +74 -0
  80. package/dist/npm/chunks/privacy-BWUGlHw5.js +57 -0
  81. package/dist/npm/chunks/{pt-BR-CkG7vpU2.js → pt-BR-DOkdlfoe.js} +60 -18
  82. package/dist/npm/chunks/{realtime-DIo-Wth4.js → realtime-C79zF50C.js} +14 -12
  83. package/dist/npm/chunks/report-CrIqQZDI.js +44 -0
  84. package/dist/npm/chunks/show-BgVC8gWY.js +97 -0
  85. package/dist/npm/chunks/signin-Dd1rb2BP.js +75 -0
  86. package/dist/npm/chunks/{source-CS7C6wJA.js → source-pXVve2Cx.js} +1 -1
  87. package/dist/npm/chunks/src-BTMy4Gyc.js +208 -0
  88. package/dist/npm/chunks/start-DtVlpt7p.js +1878 -0
  89. package/dist/npm/chunks/states-sfTbjZz8.js +3 -0
  90. package/dist/npm/chunks/upload-MgPYqPyE.js +42 -0
  91. package/dist/npm/chunks/uploads-D49mywwz.js +1146 -0
  92. package/dist/npm/chunks/wrap-Bl0gbnFa.js +69 -0
  93. package/dist/npm/chunks/{zh-CN-BKuZOLBE.js → zh-CN-Z5fQCb7G.js} +59 -17
  94. package/dist/npm/element.js +58 -21
  95. package/dist/npm/headless.js +7 -3
  96. package/dist/npm/index.js +3 -3
  97. package/dist/npm/react.js +18 -11
  98. package/dist/npm/svelte.js +28 -12
  99. package/dist/npm/types/adapters/react.d.ts +4 -1
  100. package/dist/npm/types/adapters/svelte.d.ts +4 -1
  101. package/dist/npm/types/adapters/vue.d.ts +35 -2
  102. package/dist/npm/types/anchor/index.d.ts +19 -0
  103. package/dist/npm/types/capture/privacy.d.ts +14 -0
  104. package/dist/npm/types/core/api.d.ts +20 -1
  105. package/dist/npm/types/core/auth.d.ts +40 -21
  106. package/dist/npm/types/core/client.d.ts +60 -4
  107. package/dist/npm/types/core/page-key.d.ts +42 -0
  108. package/dist/npm/types/core/types.d.ts +87 -4
  109. package/dist/npm/types/element.d.ts +17 -7
  110. package/dist/npm/types/headless.d.ts +2 -1
  111. package/dist/npm/types/index.d.ts +16 -6
  112. package/dist/npm/vue.js +44 -9
  113. package/package.json +88 -14
  114. package/dist/npm/chunks/AgentSend-2JPDseOo.js +0 -63
  115. package/dist/npm/chunks/Checklist-BpDXQebo.js +0 -257
  116. package/dist/npm/chunks/Composer-CAyj-c8e.js +0 -677
  117. package/dist/npm/chunks/Guest-ZdFmTcXI.js +0 -187
  118. package/dist/npm/chunks/MarkupEditor-BFplZwFy.js +0 -332
  119. package/dist/npm/chunks/Panel-BhZ4XRDR.js +0 -861
  120. package/dist/npm/chunks/Settings-SPG9EHUZ.js +0 -204
  121. package/dist/npm/chunks/Shortcuts-C28HVDw6.js +0 -58
  122. package/dist/npm/chunks/StyleEditor-ByZMtq10.js +0 -43
  123. package/dist/npm/chunks/StylePanel-Iwhce2tE.js +0 -197
  124. package/dist/npm/chunks/TaskFields-BsP_fVJg.js +0 -273
  125. package/dist/npm/chunks/ThreadCard-BzVZdDCb.js +0 -1030
  126. package/dist/npm/chunks/Viewer-CqtGrdD8.js +0 -108
  127. package/dist/npm/chunks/card-bits-Bna-g3Py.js +0 -124
  128. package/dist/npm/chunks/confetti-DTKpwF3O.js +0 -40
  129. package/dist/npm/chunks/drafts-akdBsOd0.js +0 -50
  130. package/dist/npm/chunks/extension-D-V3utTm.js +0 -53
  131. package/dist/npm/chunks/live-BCpJVBeN.js +0 -33
  132. package/dist/npm/chunks/report-BBrT3r89.js +0 -27
  133. package/dist/npm/chunks/src-C4FsVoUp.js +0 -148
  134. package/dist/npm/chunks/start-i9M-r3aH.js +0 -1800
  135. package/dist/npm/chunks/upload-DSv7EyBD.js +0 -41
  136. package/dist/npm/chunks/uploads-I01kdqQF.js +0 -1103
@@ -11,17 +11,28 @@ export interface ApiRequest {
11
11
  onETag?(etag: string | null): void;
12
12
  /** Skip the Authorization header (public endpoints). */
13
13
  anonymous?: boolean;
14
+ /** Send a DPoP proof even without a session (POST /guest/start, /guest/finish). */
15
+ proof?: boolean;
14
16
  signal?: AbortSignal;
15
17
  }
16
18
  export type TokenProvider = {
17
19
  accessToken(): Promise<string | null>;
18
20
  /** Called once on a 401; returns true if a fresh token is now available. */
19
21
  recover(): Promise<boolean>;
22
+ /**
23
+ * A DPoP proof for one request (AuthManager.proof): with it, a token goes as `Authorization: DPoP` with a
24
+ * new proof on every attempt; without it (a provider of plain bearer tokens), as `Bearer`.
25
+ */
26
+ proof?(method: string, url: string, token?: string | null): Promise<string>;
27
+ /** Sees every answer (AuthManager.seen); true: sign the request again and send it once more (DPoP nonce or clock). */
28
+ seen?(response: Response, code?: string): boolean;
20
29
  };
30
+ /** Each attempt, answer body included, gets this long; then it counts as a lost connection (GETs and idempotent writes are tried again). */
31
+ export declare const REQUEST_TIMEOUT_MS = 30000;
21
32
  /**
22
33
  * Thin fetch wrapper for /api/v1: JSON in/out, problem+json errors as
23
34
  * CommentKitError, one silent re-auth on 401, and bounded retries with
24
- * backoff for transient failures (network, 429, 5xx).
35
+ * backoff for transient failures (network, timeout, 429, 5xx).
25
36
  */
26
37
  export declare class ApiClient {
27
38
  private readonly baseUrl;
@@ -32,3 +43,11 @@ export declare class ApiClient {
32
43
  request<T>(path: string, options?: ApiRequest): Promise<T>;
33
44
  url(path: string, query?: ApiRequest["query"]): string;
34
45
  }
46
+ /**
47
+ * A signal that aborts after `ms`, or as soon as the caller's `signal` does. The same everywhere (no
48
+ * AbortSignal.any or AbortSignal.timeout needed); `done()` stops the timer and the listener.
49
+ */
50
+ export declare function deadline(ms: number, signal?: AbortSignal): {
51
+ signal: AbortSignal;
52
+ done(): void;
53
+ };
@@ -5,7 +5,8 @@ export interface PendingGuest {
5
5
  }
6
6
  export interface Tokens {
7
7
  access_token: string;
8
- refresh_token: string;
8
+ /** Missing for a session the page cannot renew (an extension handoff: it lasts `expires_in`, an hour). */
9
+ refresh_token?: string;
9
10
  expires_in: number;
10
11
  }
11
12
  export type SignInResult = "signed_in" | "popup_blocked" | "cancelled" | "failed" | "redirecting";
@@ -13,8 +14,9 @@ export type AuthMode = "auto" | "popup" | "redirect";
13
14
  /** Token, exchange and revoke requests are aborted after this long; the storage lock's lease (lock.ts HOLD_MS) is longer. */
14
15
  export declare const TOKEN_TIMEOUT_MS = 10000;
15
16
  /**
16
- * Client email links carry `?ck_signin=<secret>` (single use, 72 hours, one website; the backend's
17
- * ClientSignInLinks). The sign-in window (`/widget/guest`) checks it; this only keeps out what can't be one.
17
+ * Client email links carry `#ck_signin=<secret>` in the fragment (older links `?ck_signin=`): single use,
18
+ * 72 hours, one website (the backend's ClientSignInLinks). The sign-in window (`/widget/guest`) checks it;
19
+ * this only keeps out what can't be one.
18
20
  */
19
21
  export declare const SIGNIN_PARAM = "ck_signin";
20
22
  /**
@@ -27,31 +29,47 @@ export declare const SIGNIN_PARAM = "ck_signin";
27
29
  * revokes the whole session server-side.
28
30
  */
29
31
  export declare class AuthManager {
30
- private readonly endpoint;
31
- private readonly projectKey;
32
- private readonly origin;
33
- private access;
32
+ /** The refresh token, when the DPoP key lives in memory only (no IndexedDB): never stored, so the session ends with the page. */
33
+ private held;
34
34
  private refreshing;
35
+ /** The session has no refresh token (an extension handoff): it lives in memory only and is renewed by `renew`. */
36
+ private handoff;
37
+ private renewing;
35
38
  private listeners;
36
39
  private remember;
37
- private authorize;
38
- /** From a client email link: in memory only (never stored or logged), used by the next sign-in. */
39
- private signInLink;
40
- constructor(endpoint: string, projectKey: string, origin?: string);
40
+ constructor(
41
+ /** @internal */
42
+ endpoint: string,
43
+ /** @internal */
44
+ projectKey: string,
45
+ /** @internal */
46
+ origin?: string);
47
+ /**
48
+ * Signed out in another tab (it removed the shared refresh token): this tab forgets its access token
49
+ * too and says so. A rotation by another tab writes a new token, which this tab simply reads next time.
50
+ */
51
+ private readonly onStorage;
52
+ destroy(): void;
41
53
  get storageKey(): string;
54
+ /** A valid access token, or a refresh token to get one (a session without one ends with its access token). */
42
55
  hasSession(): boolean;
43
- onChange(listener: (signedIn: boolean) => void): () => void;
56
+ /** `ended`: the session ran out or the server refused to renew it (not a sign-out here or in another tab). */
57
+ onChange(listener: (signedIn: boolean, ended?: boolean) => void): () => void;
44
58
  /** A valid access token, refreshing if needed. null when signed out. */
45
59
  accessToken(): Promise<string | null>;
46
60
  recover(): Promise<boolean>;
47
61
  /**
48
- * Takes `?ck_signin=` off the address bar at once (no reload), so it never reaches the page's analytics,
49
- * a bookmark or a Referer, and keeps it for the next sign-in. True when a usable link was there.
62
+ * Keeps a client email link's `?ck_signin=` value for the next sign-in, in memory only. The value was
63
+ * already taken off the address bar (activation.ts takeSignInParam, run first by the CDN loader and by
64
+ * init()), so it never reaches the page's analytics, a bookmark or a Referer. True when it is usable.
50
65
  */
51
- takeSignInLink(): boolean;
66
+ takeSignInLink(value: string | null): boolean;
52
67
  /** A client email link is waiting to be used by the next sign-in. */
53
68
  hasSignInLink(): boolean;
54
- /** Must be called from a user gesture (click) so the popup is allowed. */
69
+ /**
70
+ * Must be called from a user gesture (click) so the popup is allowed. The sign-in code (signin.ts) is
71
+ * a lazy chunk, fetched ahead while the widget shows someone signed out (client.loadSession).
72
+ */
55
73
  signIn(options?: {
56
74
  share?: string | null;
57
75
  mode?: AuthMode;
@@ -63,11 +81,11 @@ export declare class AuthManager {
63
81
  * Returns true when a session was created. Removes the params from the URL.
64
82
  */
65
83
  completeRedirect(): Promise<boolean>;
66
- private get pkceKey();
67
- private authorizeUrl;
68
- private redirect;
84
+ /**
85
+ * Also deletes this browser's DPoP key (core/dpop.ts, loaded by the session's first request): the next
86
+ * sign-in makes a new one.
87
+ */
69
88
  signOut(): Promise<void>;
70
- private awaitCode;
71
89
  /**
72
90
  * One refresh at a time across this site's tabs (they share the refresh token, and the server treats a
73
91
  * second use of a rotated token as theft). The token is read again once the lock is held: another tab
@@ -95,10 +113,11 @@ export declare class AuthManager {
95
113
  /** Start a normal session from tokens the API issued (POST /guest/verify). Ends the pending token. */
96
114
  adopt(tokens: Tokens): void;
97
115
  private store;
98
- /** Only the policy's storage holds the token; the other one is always emptied. */
116
+ /** Only the policy's storage holds the token; the other one is always emptied. With a key in memory only, neither. */
99
117
  private write;
100
118
  /** [where the policy keeps the token, the other one]. */
101
119
  private stores;
120
+ /** `ended`: the session ran out or was refused, rather than signed out (onChange). */
102
121
  private clear;
103
122
  private readRefresh;
104
123
  private emit;
@@ -11,12 +11,31 @@ export interface LinkPreview {
11
11
  description: string | null;
12
12
  }
13
13
  export declare const SDK_VERSION: string;
14
+ export declare const DEFAULT_ENDPOINT = "https://commentkit.dev";
15
+ /** Page keys (core/page-key.ts): what the client needs of them. */
16
+ export interface PageKeys {
17
+ /** The key of an address: the server's key for that page once one was learnt. */
18
+ of(address: string): string;
19
+ /** The server answered `key` for the page at `address`. */
20
+ learn?(address: string, key: string | undefined): void;
21
+ /** This page's address as it is sent (page.url, page_url): core/page-key.ts pageUrl. */
22
+ url?(): string;
23
+ }
24
+ /**
25
+ * This page's address as the API gets it (page.url, page_url): core/page-key.ts pageUrl once installed (without
26
+ * CommentKit's own parameters, the fragment only as a hash route, capped at the API's length), else as it is.
27
+ */
28
+ export declare const currentPageUrl: () => string;
29
+ /** Most threads loadPageThreads reads for one page (100 per request). */
30
+ export declare const MAX_PAGE_THREADS = 500;
14
31
  export interface ClientState {
15
32
  config: WidgetConfig | null;
16
33
  session: Session | null;
17
34
  /** Threads on the current page, newest activity first. */
18
35
  threads: Thread[];
19
36
  loadingThreads: boolean;
37
+ /** The page has more open threads than `threads` holds (more than MAX_PAGE_THREADS). */
38
+ moreThreads: boolean;
20
39
  /** Show feedback from every branch, not only the one this build came from. */
21
40
  allBranches: boolean;
22
41
  unread: number;
@@ -38,6 +57,13 @@ export interface ClientState {
38
57
  /** Team members here right now, by name: only filled in for team members (the team presence channel). */
39
58
  team: Person[];
40
59
  }
60
+ /** A state with nothing loaded yet (also the inert stand-in's, for server rendering). */
61
+ export declare function blankState(): ClientState;
62
+ /**
63
+ * The session as the host page sees it (event payloads, `session()`): without the person's email
64
+ * address, which the page's own scripts and analytics have no need for. The widget keeps it (Settings).
65
+ */
66
+ export declare function publicSession(session: Session | null): Session | null;
41
67
  type Listener<K extends keyof CommentKitEvents> = (payload: CommentKitEvents[K]) => void;
42
68
  /** The `code` of the error an edit gets when someone else changed the thread or message first (HTTP 412). */
43
69
  export declare const EDIT_CONFLICT = "edit_conflict";
@@ -66,17 +92,38 @@ export declare class CommentKitClient {
66
92
  private unreadKnown;
67
93
  /** Conversations read by allMessages, page by page, so a refresh reads only what is new. */
68
94
  private conversations;
95
+ /** Events whose listener threw already (logged once each). */
96
+ private failedEvents;
97
+ /** The latest loadPageThreads call, and the page its threads are for. */
98
+ private pageLoad;
99
+ /** The page key the threads in the state are for. */
100
+ private threadsPage;
101
+ /** Threads created, changed or removed here (null: not on this page) while a page load was under way: kept over its answer. */
102
+ private changed;
69
103
  constructor(options: CommentKitOptions);
70
104
  /** Where CommentKit's own static files live (emoji images), on the same server as the API. */
71
105
  get assets(): string;
72
106
  /** The widget's own crash, sent to CommentKit with the SDK version (see core/report.ts). */
73
107
  reportCrash(error: unknown, kind?: "crash" | "start"): void;
74
108
  on<K extends keyof CommentKitEvents>(event: K, listener: Listener<K>): () => void;
109
+ /**
110
+ * Tells the page's listeners. Each runs on its own: one that throws is logged (once per event) and
111
+ * changes nothing here, neither the other listeners, CommentKit's state, nor its crash reports.
112
+ * Sessions reach the page without the email address (publicSession).
113
+ */
75
114
  emit<K extends keyof CommentKitEvents>(event: K, payload: CommentKitEvents[K]): void;
115
+ /** Fetch the sign-in code ahead, so a click on "Sign in" opens the window at once (popup blockers allow only a short wait). */
116
+ prefetchSignIn(): void;
76
117
  loadConfig(): Promise<WidgetConfig>;
77
118
  loadSession(): Promise<Session | null>;
119
+ /** Never rejects: anything that goes wrong (the window, the code exchange, reading the session) is "failed". */
78
120
  signIn(share?: string | null): Promise<SignInResult>;
79
121
  signOut(): Promise<void>;
122
+ /**
123
+ * The page's open threads: follows `next_cursor` up to MAX_PAGE_THREADS (`moreThreads` says when there
124
+ * are more). On another page the previous page's threads are cleared at once. An answer that arrives
125
+ * after a newer call, or after the address changed (fast single-page navigation), is ignored.
126
+ */
80
127
  loadPageThreads(pageUrl?: string): Promise<Thread[]>;
81
128
  /** The branch lists are limited to: this build's branch, unless "All branches" is on. */
82
129
  branchFilter(): string | undefined;
@@ -146,7 +193,7 @@ export declare class CommentKitClient {
146
193
  allMessages(threadId: string, options?: {
147
194
  refresh?: boolean;
148
195
  }): Promise<Message[]>;
149
- /** A message changed here: forget the conversation holding it, so the next read is complete. */
196
+ /** A message changed here: forget the conversation holding it, so the next read is complete. Returns that thread's id, if known. */
150
197
  private forgetConversationOf;
151
198
  reply(threadId: string, body: string, options?: {
152
199
  replyTo?: string | null;
@@ -162,7 +209,12 @@ export declare class CommentKitClient {
162
209
  editMessage(id: string, body: string, options?: {
163
210
  mentionIds?: number[];
164
211
  }): Promise<Message>;
165
- /** An edit; on a conflict the ETag is forgotten and `reload` (if any) reads the latest version. */
212
+ /**
213
+ * An edit or delete. On a conflict the ETag is forgotten and `reload` (if any) reads the latest version.
214
+ * These writes carry no Idempotency-Key, so a lost answer (timeout, dropped connection) is not retried
215
+ * and the server may have applied it anyway: `reload` reads the real state before the error is shown,
216
+ * and a manual retry then starts from it.
217
+ */
166
218
  private edit;
167
219
  deleteMessage(id: string): Promise<void>;
168
220
  react(messageId: string, emoji: string, on: boolean): Promise<void>;
@@ -227,11 +279,15 @@ export declare class CommentKitClient {
227
279
  /** Try the live connection again now, after it dropped. */
228
280
  reconnectRealtime(): void;
229
281
  refreshThread(id: string): Promise<void>;
282
+ /**
283
+ * This page's key (core/page-key.ts), compared instead of addresses everywhere: the key computed here, or
284
+ * the server's own key for this page once an answer showed it differs (the project's own list of
285
+ * parameters that do not change the page, which the widget cannot know).
286
+ */
287
+ pageKey(address?: string): string;
230
288
  private upsert;
231
289
  destroy(): void;
232
290
  }
233
291
  /** Remember the reader's theme on this device (null forgets it). */
234
292
  export declare function saveTheme(theme: ClientState["theme"]): void;
235
- /** Page identity: origin + path + query + hash routes, without our own params. */
236
- export declare function currentPageUrl(): string;
237
293
  export {};
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A page's key: its stable identity, the same for every address of one page. The server keys feedback and
3
+ * sign-offs by it (contract/openapi-v1.yaml, `Thread.page.key`) and the widget compares pages by it, never
4
+ * by the raw address, so `/pricing`, `/pricing/` and `/pricing?utm_source=x` are one page. These are the
5
+ * spec's built-in rules, in its order; test/page-key.test.ts runs the backend's own table against them.
6
+ *
7
+ * A project can list more parameters that do not change the page. GET /widget/config sends that list
8
+ * (`pages.ignored_query_params`) and the widget applies it (pageKeys.ignore), so its key is right before any
9
+ * comment exists on the page. Older servers leave it out; and whenever the two still disagree, the client
10
+ * trusts the key the server answers for the current page (client.pageKey).
11
+ */
12
+ /** Tracking parameters every project drops, besides any `utm_*` and CommentKit's own `ck` and `ck_*`. */
13
+ export declare const TRACKING: string[];
14
+ /**
15
+ * The page key of an address. `ignored`: the project's own "query parameters that do not change the
16
+ * page" (a trailing `*` matches every name starting with the rest), when known. Never throws.
17
+ */
18
+ export declare function pageKey(address: string, ignored?: readonly string[]): string;
19
+ /**
20
+ * `href` without the query parameters whose name (as written) `names` matches, edited as written: every other
21
+ * pair stays byte for byte, in its order (URLSearchParams would re-encode them, `?ids=1,2` → `ids=1%2C2`, and
22
+ * the server keeps pairs as written, so the page's key would no longer match). A query left empty goes with
23
+ * its `?`. The fragment is never touched.
24
+ */
25
+ export declare const withoutParams: (href: string, names: RegExp) => string;
26
+ /**
27
+ * This page's address as the API gets it (page.url, page_url): without CommentKit's own parameters (also the
28
+ * redirect sign-in ones: a host router, Inertia for one, can write them back after they were taken off), the
29
+ * fragment only as a hash route, at most PAGE_URL_MAX characters (the API's limit on `page.url`).
30
+ */
31
+ export declare const pageUrl: () => string;
32
+ /** What the client uses (client.ts usePageKeys): keys, with what the server answered for a page winning. */
33
+ export declare const pageKeys: {
34
+ url: typeof pageUrl;
35
+ of(address: string): string;
36
+ learn(address: string, key: string | undefined): void;
37
+ /**
38
+ * The project's list from the widget config. Anything that is not a list of names counts as none (an older
39
+ * server). A different list forgets the keys learnt so far: they were learnt against the old one.
40
+ */
41
+ ignore(list: unknown): void;
42
+ };
@@ -82,6 +82,11 @@ export interface Message {
82
82
  author: Person;
83
83
  body: string;
84
84
  source: string;
85
+ /**
86
+ * "team": a team-only reply, which only the project's team members receive (shown as such). Guests and
87
+ * reviewers only ever get "everyone". Older servers leave it out.
88
+ */
89
+ visibility?: "everyone" | "team";
85
90
  reply_to?: {
86
91
  id: string;
87
92
  author: Person;
@@ -168,6 +173,11 @@ export interface Thread {
168
173
  labels?: Label[];
169
174
  page: {
170
175
  url: string;
176
+ /**
177
+ * The page's key: compare pages by this, never by `url` (`/pricing?utm_source=x` and `/pricing/` are
178
+ * `/pricing`). See `pageKey` in `@commentkit/comment-kit/headless`. Older servers leave it out.
179
+ */
180
+ key?: string;
171
181
  path: string;
172
182
  title: string | null;
173
183
  environment: Environment;
@@ -200,8 +210,8 @@ export interface Thread {
200
210
  }
201
211
  /**
202
212
  * A realtime change ping. Ids only: the widget fetches the thread again over HTTP. `actor` (and `by`, on
203
- * newer servers) say who made the change ("user:1", "guest:9"); `page_path` says which page the thread is
204
- * on. Any of them can be missing on older servers.
213
+ * newer servers) say who made the change ("user:1", "guest:9"); `page_key` says which page the thread is
214
+ * on (`page_path` is the older, coarser form). Any of them can be missing on older servers.
205
215
  */
206
216
  export interface FeedbackPing {
207
217
  type: string;
@@ -210,6 +220,8 @@ export interface FeedbackPing {
210
220
  actor?: string | null;
211
221
  by?: string | null;
212
222
  page_path?: string | null;
223
+ /** The page key of the thread's page (`Thread.page.key`); null for tasks without a page. */
224
+ page_key?: string | null;
213
225
  }
214
226
  export interface Capabilities {
215
227
  comment: boolean;
@@ -241,6 +253,14 @@ export interface WidgetConfig {
241
253
  name: string;
242
254
  };
243
255
  enabled: boolean;
256
+ /**
257
+ * Why `enabled` is false: "project_paused" (the project's kill switch: visitors from a link see a short
258
+ * note), "version_blocked" (CommentKit switched this SDK version off: the widget stays silent until it
259
+ * is switched back on) or "not_live" (the website is being tried out before a plan is chosen and this is
260
+ * not a local address: silent for visitors, a signed-in team member sees a short note). Null when enabled;
261
+ * older servers leave it out.
262
+ */
263
+ disabled_reason?: "project_paused" | "version_blocked" | "not_live" | null;
244
264
  read_only: boolean;
245
265
  environment: Environment;
246
266
  local_only_for_members: boolean;
@@ -262,9 +282,28 @@ export interface WidgetConfig {
262
282
  };
263
283
  privacy: {
264
284
  redact_selectors: string[];
285
+ /**
286
+ * Set in the dashboard ("Hide everything people type in screenshots"): "strict" hides every form value and
287
+ * editable region in screenshots. The widget applies the stricter of this and init({ privacy }). Older servers leave it out.
288
+ */
289
+ mode?: "standard" | "strict";
290
+ /** The website's own privacy notice (https), shown to its guests next to CommentKit's. Null or absent when none. */
291
+ notice_url?: string | null;
265
292
  };
293
+ /**
294
+ * `upload_types`: the file types (MIME) this website accepts as attachments, when it limits them (for
295
+ * example images only); absent means every type the API allows.
296
+ */
266
297
  limits: {
267
298
  max_upload_bytes: number;
299
+ upload_types?: string[];
300
+ };
301
+ /**
302
+ * How this website identifies a page: its own query parameters that do not change the page (lower-cased; a
303
+ * trailing `*` matches every name starting with the rest), on top of the built-in tracking ones. Older servers leave it out.
304
+ */
305
+ pages?: {
306
+ ignored_query_params: string[];
268
307
  };
269
308
  /** First read of a page only: proves a real widget load when reporting the widget's own crash. */
270
309
  reporting?: {
@@ -334,8 +373,15 @@ export interface CommentKitOptions {
334
373
  theme?: "auto" | "light" | "dark";
335
374
  /** Where the launcher sits. Defaults to the dashboard setting. */
336
375
  position?: Position;
337
- /** CSS selectors whose content is never captured in screenshots. */
376
+ /** CSS selectors whose content is never captured in screenshots, nor in the text a comment keeps to find its spot. */
338
377
  redact?: string[];
378
+ /**
379
+ * "standard" (default): passwords, payment, contact and identity fields (name, username, birthday,
380
+ * organization) and `redact` are left out of screenshots, and what anyone typed in a form is never kept
381
+ * with a comment. "strict": every form control's value and every editable region are left out of
382
+ * screenshots too.
383
+ */
384
+ privacy?: "standard" | "strict";
339
385
  /**
340
386
  * Interface language, e.g. "fr" or "pt-BR". Defaults to the page's <html lang>,
341
387
  * then the browser language. Built in: en, es, fr, de, pt-BR, it, nl, ja, zh-CN,
@@ -350,20 +396,57 @@ export interface CommentKitOptions {
350
396
  /**
351
397
  * Single-key shortcuts while the widget is shown: C to comment, J / K for next or previous,
352
398
  * E to resolve, ? for the list. Default true. Set false when your app has its own shortcuts
353
- * (WCAG 2.1.4). Esc and Cmd/Ctrl+Shift+K keep working.
399
+ * (WCAG 2.1.4). Esc and Cmd/Ctrl+Shift+K keep working (see `toggleShortcut`).
354
400
  */
355
401
  shortcuts?: boolean;
402
+ /**
403
+ * Cmd/Ctrl+Shift+K shows the widget, and while it is shown opens the inbox. Default true. Set false
404
+ * when your site uses that combination itself; show the widget with `show()` or `comment()` instead.
405
+ * While the widget is hidden the key also reaches your page's own handlers.
406
+ */
407
+ toggleShortcut?: boolean;
356
408
  /**
357
409
  * Turn parts of the comment tools off on this site. Each one defaults to on (screenshots also
358
410
  * follow the dashboard setting). `text: false` stops selected text from becoming a quoted comment.
411
+ * `style` ("Adjust style": suggested CSS changes) and `checklist` are only ever offered to team
412
+ * members who can triage; set either to false to turn it off for them too.
359
413
  */
360
414
  tools?: {
361
415
  screenshots?: boolean;
362
416
  markup?: boolean;
363
417
  text?: boolean;
364
418
  attachments?: boolean;
419
+ style?: boolean;
420
+ checklist?: boolean;
365
421
  };
422
+ /**
423
+ * Sign the reviewer in from your website's own login ("Sign in from your website" in CommentKit, under
424
+ * Settings, For developers). Your **server** signs a short-lived token (HS256 JWT, at most 10 minutes) for
425
+ * the user who is signed in to your site, with the website's identity secret; the page passes it here.
426
+ * Give a function to fetch a fresh token: it is called again whenever the CommentKit session ends.
427
+ * Never put the identity secret in the page. The token is never stored, logged or put in a URL.
428
+ *
429
+ * With an identity the widget shows for that person, on production too, already signed in. A CommentKit
430
+ * team member who is signed in on this browser stays signed in as themselves. When the token is refused
431
+ * the widget emits `error` (with the API's code) and offers the normal sign-in.
432
+ *
433
+ * ```js
434
+ * // Node: the token for the signed-in user (npm install jsonwebtoken)
435
+ * app.get("/commentkit-token", requireLogin, (req, res) => {
436
+ * const now = Math.floor(Date.now() / 1000);
437
+ * res.type("text").send(jwt.sign({ sub: String(req.user.id), email: req.user.email, name: req.user.name, aud: "pk_live_…", iat: now, exp: now + 300 },
438
+ * process.env.COMMENTKIT_IDENTITY_SECRET, { algorithm: "HS256" }));
439
+ * });
440
+ * // In the page:
441
+ * init({ project: "pk_live_…", identity: () => fetch("/commentkit-token").then((r) => r.text()) });
442
+ * ```
443
+ *
444
+ * See https://commentkit.dev/docs/identify
445
+ */
446
+ identity?: IdentitySource;
366
447
  }
448
+ /** A host-app sign-in token (`CommentKitOptions.identity`), or a function giving one (or a Promise of one). */
449
+ export type IdentitySource = string | (() => string | Promise<string>);
367
450
  export interface CommentKitEvents {
368
451
  ready: {
369
452
  session: Session | null;
@@ -1,13 +1,23 @@
1
- /**
2
- * <comment-kit project="pk_live_…" branch="main"></comment-kit>
3
- * Works in any framework or plain HTML. Attributes: project (required), branch, commit, locale,
4
- * theme, position, auth, endpoint, deployment-url, hide-on-production="false", shortcuts="false". Changing project
5
- * restarts the widget.
6
- */
7
- export declare class CommentKitElement extends HTMLElement {
1
+ /** Importing this file on the server (SSR, Node) must not fail: there is no HTMLElement to extend there. */
2
+ declare const Base: typeof HTMLElement;
3
+ export declare class CommentKitElement extends Base {
8
4
  static observedAttributes: string[];
9
5
  private kit;
6
+ /** The settings `kit` was started with, to restart only when one really changed. */
7
+ private started;
10
8
  attributeChangedCallback(_name: string, before: string | null, after: string | null): void;
11
9
  connectedCallback(): void;
10
+ private options;
11
+ /**
12
+ * Sign your site's user in with a token from your server (init()'s `identity`). Resolves false when the
13
+ * token was refused or the element is not started (not in the page, or no project); never rejects.
14
+ */
15
+ identify(token: string): Promise<boolean>;
16
+ /**
17
+ * Sign the reviewer out of CommentKit on this browser, for example when they log out of your website.
18
+ * Does nothing when the element is not started; never rejects.
19
+ */
20
+ signOut(): Promise<void>;
12
21
  disconnectedCallback(): void;
13
22
  }
23
+ export {};
@@ -1,7 +1,8 @@
1
- /** Headless client for custom UIs, extensions and tests. No UI, no globals. */
2
1
  export { CommentKitClient, currentPageUrl, EDIT_CONFLICT, SDK_VERSION } from "./core/client.js";
2
+ export { pageKey } from "./core/page-key.js";
3
3
  export { ApiClient } from "./core/api.js";
4
4
  export { AuthManager } from "./core/auth.js";
5
5
  export { createAnchor, resolveAnchor, stableSelector } from "./anchor/index.js";
6
+ export { configurePrivacy } from "./capture/privacy.js";
6
7
  export type * from "./core/types.js";
7
8
  export { CommentKitError } from "./core/types.js";
@@ -1,6 +1,6 @@
1
1
  import { CommentKitClient, SDK_VERSION } from "./core/client.js";
2
2
  import { type CommentKitEvents, type CommentKitOptions, type Session } from "./core/types.js";
3
- export type { Anchor, Attachment, Capabilities, CaptureInput, ChecklistItem, CommentKitEvents, CommentKitOptions, Environment, InboxItem, MarkupShape, Message, Page, Person, Position, Reaction, Session, StyleChange, StyleProperty, Thread, TaskInput, ThreadPriority, ThreadStatus, WidgetConfig, } from "./core/types.js";
3
+ export type { Anchor, Attachment, Capabilities, CaptureInput, ChecklistItem, CommentKitEvents, CommentKitOptions, Environment, IdentitySource, InboxItem, MarkupShape, Message, Page, Person, Position, Reaction, Session, StyleChange, StyleProperty, Thread, TaskInput, ThreadPriority, ThreadStatus, WidgetConfig, } from "./core/types.js";
4
4
  export { CommentKitError } from "./core/types.js";
5
5
  export { SDK_VERSION };
6
6
  export interface CommentKit {
@@ -15,13 +15,23 @@ export interface CommentKit {
15
15
  * `comment(false)` stops it. Listen to the `mode` event to follow it.
16
16
  */
17
17
  comment(on?: boolean): Promise<void>;
18
- /** Open the sign-in window. Call from a click handler. */
18
+ /** Open the sign-in window. Call from a click handler. Resolves false when it did not sign in; never rejects. */
19
19
  signIn(): Promise<boolean>;
20
+ /**
21
+ * Sign the reviewer in from your website's own login, with a token your server made for them (see
22
+ * `CommentKitOptions.identity`), for example right after they log in to your site. Shows the widget
23
+ * when it is not shown yet. Resolves true when they are signed in, false when the token was refused
24
+ * (the `error` event says why); never rejects. A CommentKit team member signed in here stays signed in.
25
+ */
26
+ identify(token: string): Promise<boolean>;
20
27
  signOut(): Promise<void>;
21
- /** Current person, if signed in. */
28
+ /** Current person, if signed in (without their email address). */
22
29
  session(): Session | null;
23
30
  on<K extends keyof CommentKitEvents>(event: K, listener: (payload: CommentKitEvents[K]) => void): () => void;
24
- /** Remove the widget and every listener from the page. */
31
+ /**
32
+ * Release this handle: its listeners are removed, and when it was the last one (every init() call returns
33
+ * its own handle), the widget and everything CommentKit added to the page are removed too.
34
+ */
25
35
  destroy(): void;
26
36
  readonly client: CommentKitClient;
27
37
  }
@@ -31,7 +41,7 @@ export interface CommentKit {
31
41
  * import { init } from "@commentkit/comment-kit";
32
42
  * init({ project: "pk_live_…" });
33
43
  *
34
- * Safe to call more than once: later calls return the same instance.
35
- * Never throws into the host page.
44
+ * Safe to call more than once: each call returns its own handle onto the same widget, which stays
45
+ * until the last handle is destroyed. Never throws into the host page.
36
46
  */
37
47
  export declare function init(input: CommentKitOptions): CommentKit;
package/dist/npm/vue.js CHANGED
@@ -1,14 +1,14 @@
1
- import { t as e } from "./chunks/src-C4FsVoUp.js";
2
- import { defineComponent as t, onBeforeUnmount as n, onMounted as r } from "vue";
1
+ import { t as e } from "./chunks/src-BTMy4Gyc.js";
2
+ import { defineComponent as t, onBeforeUnmount as n, onMounted as r, watch as i } from "vue";
3
3
  // src/adapters/vue.ts
4
- function i(e) {
4
+ function a(e) {
5
5
  try {
6
6
  return e();
7
7
  } catch (e) {
8
8
  return console.warn("[CommentKit] The widget could not start.", e), null;
9
9
  }
10
10
  }
11
- var a = t({
11
+ var o = t({
12
12
  name: "CommentKit",
13
13
  props: {
14
14
  project: {
@@ -47,6 +47,10 @@ var a = t({
47
47
  type: Array,
48
48
  default: void 0
49
49
  },
50
+ privacy: {
51
+ type: String,
52
+ default: void 0
53
+ },
50
54
  locale: {
51
55
  type: String,
52
56
  default: void 0
@@ -59,16 +63,47 @@ var a = t({
59
63
  type: Boolean,
60
64
  default: void 0
61
65
  },
66
+ toggleShortcut: {
67
+ type: Boolean,
68
+ default: void 0
69
+ },
62
70
  tools: {
63
71
  type: Object,
64
72
  default: void 0
73
+ },
74
+ identity: {
75
+ type: [String, Function],
76
+ default: void 0
65
77
  }
66
78
  },
67
79
  setup(t) {
68
- let a = null, o = () => Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0));
69
- return r(() => a = i(() => e(o()))), n(() => i(() => a?.destroy())), () => null;
80
+ let o = null, s = () => Object.fromEntries(Object.entries(t).filter(([, e]) => e !== void 0)), c = !1, l, u = () => {
81
+ a(() => o?.destroy()), l = t.identity, o = a(() => e(s()));
82
+ };
83
+ return r(() => (c = !0, u())), i(() => [
84
+ t.project,
85
+ t.branch,
86
+ t.commit,
87
+ t.endpoint,
88
+ t.privacy,
89
+ t.toggleShortcut
90
+ ], () => c && u()), i(() => t.identity, (e) => {
91
+ e !== l && (l = e, typeof e == "string" && e && o?.identify(e));
92
+ }), n(() => {
93
+ c = !1, a(() => o?.destroy()), o = null;
94
+ }), () => null;
95
+ }
96
+ }), s = { install(t, n) {
97
+ if (typeof window > "u") return;
98
+ let r = a(() => e(n));
99
+ if (!r) return;
100
+ let i = () => a(() => r.destroy());
101
+ if (typeof t.onUnmount == "function") t.onUnmount(i);
102
+ else {
103
+ let e = t.unmount.bind(t);
104
+ t.unmount = () => {
105
+ i(), e();
106
+ };
70
107
  }
71
- }), o = { install(t, n) {
72
- typeof window < "u" && i(() => e(n));
73
108
  } };
74
- export { a as CommentKit, o as CommentKitPlugin, e as init };
109
+ export { o as CommentKit, s as CommentKitPlugin, e as init };