@commentkit/comment-kit 2.0.0 → 2.1.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/CHANGELOG.md +57 -0
- package/README.md +123 -19
- package/SECURITY.md +2 -2
- package/dist/node/cli/api.js +61 -15
- package/dist/node/cli/credentials.js +8 -0
- package/dist/node/cli/doctor.js +152 -25
- package/dist/node/cli/init.js +349 -35
- package/dist/node/cli/main.js +310 -69
- package/dist/node/cli/mcp.js +187 -6
- package/dist/node/cli/website.js +140 -0
- package/dist/node/shared/dashboard-places.js +33 -0
- package/dist/node/types/next.d.ts +4 -4
- package/dist/npm/THIRD_PARTY_NOTICES.txt +47 -0
- package/dist/npm/chunks/{AgentSend-DxRJIYiz.js → AgentSend-pA7Ufvye.js} +16 -16
- package/dist/npm/chunks/Checklist-Cn9skOYK.js +269 -0
- package/dist/npm/chunks/Composer-D7H-pzGa.js +734 -0
- package/dist/npm/chunks/DatePicker-Nta5a1xD.js +161 -0
- package/dist/npm/chunks/{Guest-vvNPz8h-.js → Guest-Bi7hlzhs.js} +63 -59
- package/dist/npm/chunks/{MarkupEditor-VCOXh9d2.js → MarkupEditor-WU3USeTk.js} +46 -39
- package/dist/npm/chunks/Panel-DhAzbUbC.js +1210 -0
- package/dist/npm/chunks/{Settings-BGoZS2iV.js → Settings-BmKqPX40.js} +91 -90
- package/dist/npm/chunks/{Shortcuts-B2OMvczr.js → Shortcuts-Bl-c0Sez.js} +25 -23
- package/dist/npm/chunks/SignInFirst-CmGvSYkQ.js +35 -0
- package/dist/npm/chunks/{StyleEditor-CJ_d8Huf.js → StyleEditor-D6fUnlwq.js} +10 -10
- package/dist/npm/chunks/{StylePanel-yQzHHlY7.js → StylePanel-C-Gikxt1.js} +61 -61
- package/dist/npm/chunks/TaskFields-CaKi523b.js +617 -0
- package/dist/npm/chunks/ThreadCard-d_3pUB5V.js +1142 -0
- package/dist/npm/chunks/Viewer-BULQsi9-.js +115 -0
- package/dist/npm/chunks/{agent-C1OQzBAm.js → agent-DHdhIJ3s.js} +1 -1
- package/dist/npm/chunks/{ar-CAJ3XT8e.js → ar-B5UszrQp.js} +53 -12
- package/dist/npm/chunks/card-bits-cV8GdFWX.js +55 -0
- package/dist/npm/chunks/{client-kNAo2TTG.js → client-Cv8ddtuM.js} +13 -11
- package/dist/npm/chunks/{confetti-CkBdSu19.js → confetti-B9zlyILU.js} +1 -1
- package/dist/npm/chunks/{context-B8UAzve0.js → context-CsHnabaA.js} +1 -1
- package/dist/npm/chunks/{de-Dl18G48t.js → de-BE0Aaq8u.js} +53 -12
- package/dist/npm/chunks/{dialog-GO04oC3D.js → dialog-DvdIkCW0.js} +1 -1
- package/dist/npm/chunks/{dpop-U48QIQd7.js → dpop-CwW9ifkq.js} +1 -1
- package/dist/npm/chunks/entrance-Bn_5M9uO.js +90 -0
- package/dist/npm/chunks/{es-Dxk79lS9.js → es-BQviao4d.js} +53 -12
- package/dist/npm/chunks/{extension-E81hWyiT.js → extension-CnQTDC1j.js} +2 -2
- package/dist/npm/chunks/{extension-CKFpPWmi.js → extension-DXhz81XD.js} +1 -1
- package/dist/npm/chunks/{files-DyD5BZgp.js → files-DLEr_wmh.js} +2 -2
- package/dist/npm/chunks/{fr-8BebGKYD.js → fr-C5gu6A06.js} +53 -12
- package/dist/npm/chunks/{hi-BIN6Yy_p.js → hi-DXfQ5EvY.js} +53 -12
- package/dist/npm/chunks/{i18n-DOBt8e9U.js → i18n-Mgs9VOuk.js} +63 -58
- package/dist/npm/chunks/icons-_C6ZWmBY.js +141 -0
- package/dist/npm/chunks/{identify-CN-3xzqL.js → identify-BnQGJOa0.js} +4 -4
- package/dist/npm/chunks/{it-Cr6EwpPQ.js → it-BPHt13FV.js} +53 -12
- package/dist/npm/chunks/{ja-Iy3s5aur.js → ja-BkCqyKR0.js} +52 -11
- package/dist/npm/chunks/late-words-D4Oo_yhJ.js +57 -0
- package/dist/npm/chunks/{live-CelVeZfP.js → live-DXcxj_Af.js} +28 -22
- package/dist/npm/chunks/{nl-B84WHqqe.js → nl-DZxdLLMU.js} +53 -12
- package/dist/npm/chunks/{page-key-DepmJzC1.js → page-key-UqAozdZi.js} +1 -1
- package/dist/npm/chunks/{pick-yTyqtxN0.js → pick-C20RVUas.js} +1 -1
- package/dist/npm/chunks/{pkce-ChKGSW_4.js → pkce-BPvWoBrr.js} +1 -1
- package/dist/npm/chunks/{pt-BR-DOkdlfoe.js → pt-BR-lA9mJ05F.js} +53 -12
- package/dist/npm/chunks/{report-CrIqQZDI.js → report-BjUgUNnT.js} +1 -1
- package/dist/npm/chunks/show-BinoJyED.js +97 -0
- package/dist/npm/chunks/signin-C2jjsxz9.js +101 -0
- package/dist/npm/chunks/{source-pXVve2Cx.js → source-NuflODx3.js} +1 -1
- package/dist/npm/chunks/src-9o2Ocq8d.js +221 -0
- package/dist/npm/chunks/start-Cbx6rMrr.js +1904 -0
- package/dist/npm/chunks/states-DLMCvwes.js +3 -0
- package/dist/npm/chunks/{upload-MgPYqPyE.js → upload-C4NpM-jE.js} +1 -1
- package/dist/npm/chunks/uploads-CY4bDbaI.js +1236 -0
- package/dist/npm/chunks/{wrap-Bl0gbnFa.js → wrap-D-xTKIzj.js} +20 -20
- package/dist/npm/chunks/{zh-CN-Z5fQCb7G.js → zh-CN-yqaDHwBx.js} +53 -12
- package/dist/npm/element.js +7 -1
- package/dist/npm/headless.js +2 -2
- package/dist/npm/index.js +2 -2
- package/dist/npm/react.js +1 -1
- package/dist/npm/svelte.js +1 -1
- package/dist/npm/types/adapters/vue.d.ts +12 -0
- package/dist/npm/types/core/auth.d.ts +1 -0
- package/dist/npm/types/core/client.d.ts +5 -1
- package/dist/npm/types/core/types.d.ts +19 -4
- package/dist/npm/vue.js +5 -1
- package/package.json +4 -1
- package/dist/npm/chunks/Checklist-CnlfeSbc.js +0 -282
- package/dist/npm/chunks/Composer-B1bBVszY.js +0 -725
- package/dist/npm/chunks/Panel-F37vIL1K.js +0 -1206
- package/dist/npm/chunks/TaskFields-fmy6_HtK.js +0 -289
- package/dist/npm/chunks/ThreadCard-D51slKST.js +0 -1113
- package/dist/npm/chunks/Viewer-BOBadqmC.js +0 -111
- package/dist/npm/chunks/card-bits-CAnzrqx3.js +0 -53
- package/dist/npm/chunks/late-words-B2bmZceJ.js +0 -12
- package/dist/npm/chunks/show-BgVC8gWY.js +0 -97
- package/dist/npm/chunks/signin-Dd1rb2BP.js +0 -75
- package/dist/npm/chunks/src-BTMy4Gyc.js +0 -208
- package/dist/npm/chunks/start-DtVlpt7p.js +0 -1878
- package/dist/npm/chunks/states-sfTbjZz8.js +0 -3
- package/dist/npm/chunks/uploads-D49mywwz.js +0 -1146
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,62 @@
|
|
|
1
1
|
# @commentkit/comment-kit
|
|
2
2
|
|
|
3
|
+
## [2.1.0] - 2026-11-20
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- One sign-in for every website in a workspace. `login` can cover all websites in a workspace, including ones added later: in the browser, choose "All websites in …" next to the list (one website stays the default). `websites` lists the websites the sign-in reaches. `use [website]` chooses the website for this folder, by id or name or from a numbered list, and keeps the choice in `.commentkit/project.json`.
|
|
8
|
+
- `inset` option (`data-inset-x` / `data-inset-y` on the script tag, `inset-x` / `inset-y` on `<comment-kit>`): extra room, in pixels, between the toolbar and the edges of the screen, so it stays clear of your page's own bottom bar or buttons. Your page can also set the CSS properties `--commentkit-inset-x` and `--commentkit-inset-y` on `:root`; those win over the option.
|
|
9
|
+
- Assigning a comment works for large teams: the assignee button opens a search field over the team, with faces and a check on each person assigned. Type part of a name, use the arrow keys, and press Enter, or click several people one after another. "Unassign everyone" clears it.
|
|
10
|
+
- The due date opens a small calendar in the widget's own style instead of the browser's date field, with Today, Tomorrow, Next week and Clear at the top, and full keyboard support. It loads only when someone opens the due date.
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Signing in comes first on websites without a review link. Pressing Comment (or C, or `kit.comment()`) while signed out shows a short "Sign in to comment" note by the toolbar; after signing in, comment mode starts straight away. People with a review link still comment first, with no account.
|
|
15
|
+
- While the sign-in window is open the comment box says "Signing in…" with a "Cancel sign-in" button. It says "Sending…" only once the comment is on its way, and "Still sending…" after 10 seconds. The text stays while you sign in, including a sign-in that leaves the page and comes back.
|
|
16
|
+
- The comment card and the comment box are laid out like the dashboard. The card shows the feedback first, then what belongs to it (description, checklist, style changes, details), then the replies. Priority, assignee, due date and labels are buttons in a row under the card's header, and the status is a button in the header that opens the five statuses with a line on what each means. "Add a checklist" moved into the ⋯ menu.
|
|
17
|
+
- The reply and comment boxes hold their formatting and attach buttons inside one outlined box. The screenshot is a small thumbnail with "Draw on it" and "Remove" beside it. Reply and Send stay readable before you type and fill in when there is something to send.
|
|
18
|
+
- Icons match the dashboard's and load with the card instead of with every page, so the widget's first load is a little smaller. Icon-only buttons show a tooltip after a short hover or at once on keyboard focus. "Attach a file" now reads "Attach files".
|
|
19
|
+
- When someone shows the widget with Cmd/Ctrl+Shift+K, or opens a share or email link, the toolbar appears in the middle of the screen and moves to its corner, so people see where it went. With reduced motion it fades in at its corner.
|
|
20
|
+
- Every command picks its website the same way: `COMMENTKIT_PROJECT_ID` (with `COMMENTKIT_TOKEN`), then the folder's choice, then the publishable key in the folder, then the sign-in's only website. Otherwise it stops and asks you to run `use`. `status` shows which website the folder uses and how it was chosen.
|
|
21
|
+
- Screen readers can tell the widget's controls from your page's: the toolbar's "More" button is "More feedback options", each close button says what it closes, and the widget's message area is labelled "CommentKit messages".
|
|
22
|
+
- The new and changed words are first-draft translations.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- Sign-in works on websites sent with `Cross-Origin-Opener-Policy: same-origin`. With the default `auth`, the widget notices that the sign-in window is cut off from the page and signs in on the same tab instead. `auth: "popup"` still means a popup: on such a page it says once in the console why it cannot work.
|
|
27
|
+
- The comment box no longer stays on "Sending…" when a sign-in window was closed, or when the comment arrived but its answer was lost.
|
|
28
|
+
- A sign-in that was closed or cancelled no longer brings that comment back at the next sign-in.
|
|
29
|
+
- Cmd/Ctrl+Shift+K no longer also opens your site's own Cmd/Ctrl+K search.
|
|
30
|
+
- A `next.config.ts` typed with Next's own `NextConfig` passes to `withCommentKit` without a cast, on Next.js 15 and 16.
|
|
31
|
+
|
|
32
|
+
### Upgrading
|
|
33
|
+
|
|
34
|
+
- Nothing to change. A sign-in for a whole workspace is not read by older versions of the command: they say you are not signed in. A sign-in for one website works as before.
|
|
35
|
+
|
|
36
|
+
## [2.0.1] - 2026-11-20
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
|
|
40
|
+
- The `commentkit` command works on Laravel apps. `init` sets up Laravel with Inertia (React, Vue or Svelte), Blade or Livewire: it adds `init()` to `resources/js/app.*` (or the entry `vite.config` lists), with the key written in as the default so the server needs no new environment variable. It names layouts whose `@vite` loads only stylesheets, and for plain Blade pages it prints the script tag and the layouts it belongs in instead of editing them. The README has a Laravel section.
|
|
41
|
+
- `init` prints the exact lines to add the build plugin to vite-plus configs that use `lazyPlugins`, with the Node version the plugin needs.
|
|
42
|
+
|
|
43
|
+
### Changed
|
|
44
|
+
|
|
45
|
+
- The widget now looks like the CommentKit dashboard. Cards, menus and the inbox have slightly smaller corners and softer shadows, and the colours are a little cooler. Fields, the comment box, chips and reactions have a clearer edge, so you can see where to type or press. Focus shows as one grey ring on every control, fields included, instead of the accent colour. The default accent is Ember red with white text on buttons; pins keep the orange. Statuses match the dashboard: open is stone grey and "In review" is violet, and delete actions use their own red. If your site sets its own accent colour, it is kept on buttons and pins (a few mid-tone colours are darkened just enough for white text on them to stay readable). Nothing to change to upgrade.
|
|
46
|
+
- A single click on the page beside an open comment no longer looks like nothing happened: the card gives a small shake (none if you prefer reduced motion) and says how to close it. A double-click or double-tap outside closes it, like ×. The page still receives every click as before, and an unsent reply stays saved as a draft.
|
|
47
|
+
- `doctor` says in one neutral line when the terminal is signed in to a different website than the folder's key, with how to switch, instead of warning. Without an address, it suggests running it with the site's address.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- The ⋯ menu on an open comment shows that it is open, and closes when you click or tap beside it, press Esc (focus goes back to ⋯) or choose an item.
|
|
52
|
+
- Esc in any of the widget's menus and drop-downs (the ⋯ menus, priority, assignee, labels, reactions, the inbox filters) closes only that menu, not the comment card or the inbox around it.
|
|
53
|
+
- If one of the parts the widget loads on demand fails to download (a deploy in progress, a network blip), it is tried again a moment later instead of leaving the widget missing until the page is reloaded. A later Cmd/Ctrl+Shift+K or opening another comment tries again too.
|
|
54
|
+
- `doctor` finds the widget in Laravel entries, in the entries `vite.config` lists under `input`, in a file an entry imports, and as the script tag in a Blade layout, and reads the key written there.
|
|
55
|
+
- The package manager is chosen by lockfile first: a `package-lock.json` next to a stray `pnpm-workspace.yaml` now means npm.
|
|
56
|
+
- `mcp install` changes only the entry it adds: the file keeps its indentation, line endings and trailing newline. Backups no longer land in a git repository where git would pick them up, and a git-ignored `.mcp.json` is reported as such.
|
|
57
|
+
- Messages from `doctor`, the CLI and the SDK's console warnings point to the dashboard pages that exist (for example the website's Settings → Install, under Addresses) instead of the retired Setup and Connect pages.
|
|
58
|
+
- The README's Vue, Nuxt and build plugin examples work as pasted.
|
|
59
|
+
|
|
3
60
|
## [2.0.0] - 2026-11-17
|
|
4
61
|
|
|
5
62
|
### Added
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ This package, `@commentkit/comment-kit`, holds the browser SDK, the build plugin
|
|
|
8
8
|
|
|
9
9
|
## Install in 60 seconds
|
|
10
10
|
|
|
11
|
-
Find your project key in CommentKit
|
|
11
|
+
Find your project key (the website key, `pk_live_…`) in CommentKit in the website's **Settings → Install**, and add every address the site runs on there, under **Addresses** (live, staging, previews). A wildcard such as `https://*.preview.example.com` covers one level of subdomains (`pr-1.preview.example.com`, not `a.b.preview.example.com`); shared hosts such as `vercel.app` take the exact address instead (or `https://*--yoursite.netlify.app` for one Netlify site's previews). `localhost` always works for your team.
|
|
12
12
|
|
|
13
13
|
### Any website: the script tag
|
|
14
14
|
|
|
@@ -27,7 +27,7 @@ npm install @commentkit/comment-kit
|
|
|
27
27
|
npx @commentkit/comment-kit init
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
`init` finds your framework (Next.js, Vite, SvelteKit, React Router, Remix, Astro, Nuxt or a plain website) and shows each change before it makes it: the key in your env file, the build plugin in your config, `.commentkit/` in `.gitignore` and the widget in your layout or entry file. Without signing in, pass the key: `npx @commentkit/comment-kit init --key pk_live_your_key`. The full package name works before and after the package is installed.
|
|
30
|
+
`init` finds your framework (Next.js, Vite, SvelteKit, React Router, Remix, Astro, Nuxt, Laravel or a plain website) and shows each change before it makes it: the key in your env file, the build plugin in your config, `.commentkit/` in `.gitignore` and the widget in your layout or entry file. Without signing in, pass the key: `npx @commentkit/comment-kit init --key pk_live_your_key`. The full package name works before and after the package is installed.
|
|
31
31
|
|
|
32
32
|
Or call `init()` yourself, once, in browser code:
|
|
33
33
|
|
|
@@ -56,15 +56,22 @@ Options are read when it mounts. A change to `project`, `branch`, `commit`, `end
|
|
|
56
56
|
|
|
57
57
|
### Vue and Nuxt
|
|
58
58
|
|
|
59
|
+
Vue: install the plugin where your app is created, before `mount()`. Keep your other imports, such as your CSS:
|
|
60
|
+
|
|
59
61
|
```ts
|
|
62
|
+
// src/main.ts
|
|
63
|
+
import { createApp } from "vue";
|
|
60
64
|
import { CommentKitPlugin } from "@commentkit/comment-kit/vue";
|
|
65
|
+
import App from "./App.vue";
|
|
61
66
|
|
|
67
|
+
const app = createApp(App);
|
|
62
68
|
app.use(CommentKitPlugin, { project: "pk_live_your_key" });
|
|
69
|
+
app.mount("#app");
|
|
63
70
|
```
|
|
64
71
|
|
|
65
72
|
Or place `<CommentKit project="pk_live_your_key" />` from `@commentkit/comment-kit/vue` once in your root component. Its props are the options. A change to `project`, `branch`, `commit`, `endpoint`, `privacy` or `toggleShortcut` restarts the widget; a new `identity` token signs that person in without a restart.
|
|
66
73
|
|
|
67
|
-
Nuxt: create `plugins/commentkit.client.ts
|
|
74
|
+
Nuxt: create `app/plugins/commentkit.client.ts` (on Nuxt 3, `plugins/commentkit.client.ts`):
|
|
68
75
|
|
|
69
76
|
```ts
|
|
70
77
|
import { init } from "@commentkit/comment-kit";
|
|
@@ -91,6 +98,81 @@ and add `runtimeConfig: { public: { commentkitKey: "" } }` to `nuxt.config.ts` (
|
|
|
91
98
|
|
|
92
99
|
A change to `project`, `branch`, `commit`, `endpoint`, `privacy` or `toggleShortcut` restarts the widget.
|
|
93
100
|
|
|
101
|
+
### Laravel
|
|
102
|
+
|
|
103
|
+
`npx @commentkit/comment-kit init` sets up a Laravel app (one with `artisan` and `laravel/framework` in `composer.json`) and shows each change first. By hand:
|
|
104
|
+
|
|
105
|
+
**Inertia (React, Vue or Svelte), and Blade or Livewire pages that load a Vite entry.** Call `init()` once in the JavaScript entry your pages load, usually `resources/js/app.js` (or `app.ts`, `app.jsx`, `app.tsx`; the entries are listed under `input` in `vite.config.js`). Keep what the file has, such as `createInertiaApp(…)`: put the import with your other imports and the call at the end.
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
// resources/js/app.js
|
|
109
|
+
import { init } from '@commentkit/comment-kit';
|
|
110
|
+
|
|
111
|
+
init({ project: import.meta.env.VITE_COMMENTKIT_KEY || 'pk_live_your_key' });
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
That one call covers every page that loads the entry, whichever Inertia flavour you use; the React, Vue and Svelte helpers are not needed. It does nothing during server-side rendering.
|
|
115
|
+
|
|
116
|
+
**Where the key goes.** In the entry, as the default value, as above. Publishable keys are public by design, so it is safe to commit, and a server that builds on deploy needs no new environment variable. `VITE_COMMENTKIT_KEY` in `.env` overrides it when you build (for example `pk_test_…` on staging). A key only in `.env.local` would not reach a server: that file is git-ignored and Laravel itself never reads it.
|
|
117
|
+
|
|
118
|
+
**Layouts.** A page shows the widget only when its layout loads the entry. A layout whose `@vite` lists only stylesheets needs the entry added:
|
|
119
|
+
|
|
120
|
+
```blade
|
|
121
|
+
@vite(['resources/css/app.css', 'resources/js/app.js'])
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Pages with no JavaScript entry.** Paste the script tag before `</body>` in the layout; there is nothing to install or build:
|
|
125
|
+
|
|
126
|
+
```html
|
|
127
|
+
<script src="https://commentkit.dev/cdn/v1/loader.js" data-project="pk_live_your_key" defer></script>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`init` prints this line and the layouts that look like the place for it. It does not edit Blade files.
|
|
131
|
+
|
|
132
|
+
**Filament.** Filament admin panels do not load your app's entry, so the widget does not show in them. To add it there, render the script tag through Filament's `PanelsRenderHook::BODY_END` render hook.
|
|
133
|
+
|
|
134
|
+
**Content Security Policy.** If the app sends a policy (often from a middleware), allow CommentKit's hosts as described in [What CommentKit does to your page](#what-commentkit-does-to-your-page), then run `npx @commentkit/comment-kit doctor https://your-site.com` to check it.
|
|
135
|
+
|
|
136
|
+
**Build plugin (optional).** Put `commentkit()` first in `plugins`, before `laravel(…)`:
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
// vite.config.js
|
|
140
|
+
import { defineConfig } from 'vite';
|
|
141
|
+
import laravel from 'laravel-vite-plugin';
|
|
142
|
+
import commentkit from '@commentkit/comment-kit/vite';
|
|
143
|
+
|
|
144
|
+
export default defineConfig({
|
|
145
|
+
plugins: [
|
|
146
|
+
commentkit(),
|
|
147
|
+
laravel({
|
|
148
|
+
input: ['resources/css/app.css', 'resources/js/app.js'],
|
|
149
|
+
refresh: true,
|
|
150
|
+
}),
|
|
151
|
+
],
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
With vite-plus, where the list is built in `lazyPlugins(() => [...])`, it goes first in the list the callback returns (`init` prints these lines rather than editing inside the callback):
|
|
156
|
+
|
|
157
|
+
```js
|
|
158
|
+
// vite.config.js
|
|
159
|
+
import { defineConfig, lazyPlugins } from 'vite-plus';
|
|
160
|
+
import laravel from 'laravel-vite-plugin';
|
|
161
|
+
import commentkit from '@commentkit/comment-kit/vite';
|
|
162
|
+
|
|
163
|
+
export default defineConfig({
|
|
164
|
+
plugins: lazyPlugins(() => [
|
|
165
|
+
commentkit(),
|
|
166
|
+
laravel({
|
|
167
|
+
input: ['resources/css/app.css', 'resources/js/app.js'],
|
|
168
|
+
refresh: true,
|
|
169
|
+
}),
|
|
170
|
+
]),
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The plugin's source locations need Node 22.18+ or 24.11+. A server that builds on deploy with an older Node prints one warning and builds as usual, without them.
|
|
175
|
+
|
|
94
176
|
### Custom element (Angular, Solid, Astro, Qwik, anything else)
|
|
95
177
|
|
|
96
178
|
Import it once in your bundle, then place the tag anywhere:
|
|
@@ -107,7 +189,12 @@ A change to any attribute restarts the widget with the new settings. You can als
|
|
|
107
189
|
|
|
108
190
|
### Headless
|
|
109
191
|
|
|
110
|
-
`@commentkit/comment-kit/headless` exports `CommentKitClient`, `createAnchor`, `resolveAnchor`, `stableSelector`, `pageKey`, `configurePrivacy`, `ApiClient` and `AuthManager` for your own interface. It adds nothing to the page.
|
|
192
|
+
`@commentkit/comment-kit/headless` exports `CommentKitClient`, `createAnchor`, `resolveAnchor`, `stableSelector`, `pageKey`, `configurePrivacy`, `ApiClient` and `AuthManager` for your own interface. It adds nothing to the page. It also exports:
|
|
193
|
+
|
|
194
|
+
- `currentPageUrl()`: this page's address as CommentKit stores it (without CommentKit's own parameters);
|
|
195
|
+
- `SDK_VERSION`: the version string of the SDK you installed;
|
|
196
|
+
- `EDIT_CONFLICT`: the error code (`"edit_conflict"`) a `CommentKitError` carries when someone else changed a message or thread first;
|
|
197
|
+
- `CommentKitError`, and every public type.
|
|
111
198
|
|
|
112
199
|
## Options
|
|
113
200
|
|
|
@@ -123,15 +210,19 @@ One table for every way in. `init()` and the React, Vue and Svelte helpers take
|
|
|
123
210
|
| `hideOnProduction` | `boolean` | `true` | `false` shows the widget to every visitor, not only to people who bring a reason (see [What CommentKit does to your page](#what-commentkit-does-to-your-page)). | `data-hide-on-production="false"` | `hide-on-production="false"` |
|
|
124
211
|
| `theme` | `"auto" \| "light" \| "dark"` | the dashboard setting | Colour scheme. A reader's own choice in Settings wins. | — | `theme` |
|
|
125
212
|
| `position` | `"bottom-right" \| "bottom-left" \| "top-right" \| "top-left"` | the dashboard setting | Where the widget starts. Readers can drag it. | — | `position` |
|
|
213
|
+
| `inset` | `{ x?: number; y?: number }` (CSS pixels) | none | Extra room between the toolbar and the edges it docks to, to keep clear of your page's own fixed bars and buttons: `x` from the left or right edge, `y` from the top or bottom. A dragged toolbar keeps it. | `data-inset-x`, `data-inset-y` | `inset-x`, `inset-y` |
|
|
126
214
|
| `privacy` | `"standard" \| "strict"` | `"standard"` | `"strict"` also leaves every form field's value and every editable region out of screenshots (see [Privacy](#privacy)). | `data-privacy="strict"` | `privacy="strict"` |
|
|
127
215
|
| `redact` | `string[]` | none | CSS selectors whose content never appears in screenshots or in the text a comment keeps to find its spot. Added to the dashboard's privacy selectors. | `data-redact=".a, #b"` (one selector list) | `redact=".a, #b"` |
|
|
128
216
|
| `locale` | `string` | `<html lang>`, then the browser | Widget language, for example `"fr"` or `"pt-BR"` (see [Languages](#languages)). | `data-locale` | `locale` |
|
|
129
|
-
| `auth` | `"auto" \| "popup" \| "redirect"` | `"auto"` | How sign-in opens: a popup, or a same-tab redirect in in-app browsers
|
|
217
|
+
| `auth` | `"auto" \| "popup" \| "redirect"` | `"auto"` | How sign-in opens: a popup, or a same-tab redirect in in-app browsers, when popups are blocked, and on pages sent with `Cross-Origin-Opener-Policy: same-origin` (`"auto"` asks for the page's own headers when someone signs in). `"popup"` cannot work under that header. | `data-auth` | `auth` |
|
|
130
218
|
| `shortcuts` | `boolean` | `true` | Allows single-key shortcuts while the widget is shown: C comment, J / K next or previous, E resolve, ? list. They start on for team members and off for clients, and each reader can switch them in Settings. `false` turns them off for everyone, for example when your app uses those keys. Esc and Cmd/Ctrl+Shift+K keep working. | `data-shortcuts="false"` | `shortcuts="false"` |
|
|
131
219
|
| `toggleShortcut` | `boolean` | `true` | Cmd/Ctrl+Shift+K shows the widget, and while it is shown opens the inbox. Set `false` if your site uses that combination; show the widget with `show()` or `comment()` instead. | `data-toggle-shortcut="false"` | `toggle-shortcut="false"` |
|
|
132
220
|
| `tools` | `{ screenshots?, markup?, text?, attachments?, style?, checklist? }` (booleans) | all on | Turn parts of the comment tools off. `text: false` stops selected text becoming a quoted comment. `style` (suggested CSS changes) and `checklist` are only offered to team members who can triage. Screenshots also follow the dashboard setting. | — | `tools-off="style checklist"` (space-separated names) |
|
|
133
221
|
| `identity` | `string \| () => string \| Promise<string>` | none | Signs the reviewer in from your website's own login (see [Sign reviewers in from your own login](#sign-reviewers-in-from-your-own-login)). | `window.CommentKit = { identity }` before the tag | — (call `element.identify(token)`) |
|
|
134
222
|
|
|
223
|
+
To change that room while your page runs (a bar that comes and goes, a different layout on phones), set `--commentkit-inset-x` and `--commentkit-inset-y` (lengths, such as `72px`) on `:root`, for example in a media query or while your "unsaved changes" bar shows.
|
|
224
|
+
They win over the `inset` option; without either, the toolbar sits 20 px from its edges, plus the phone's safe area.
|
|
225
|
+
|
|
135
226
|
Settings that apply without a deploy live in the dashboard: pausing feedback, theme, position, accent colour, privacy selectors, and console and network capture.
|
|
136
227
|
|
|
137
228
|
### Methods and events
|
|
@@ -139,6 +230,8 @@ Settings that apply without a deploy live in the dashboard: pausing feedback, th
|
|
|
139
230
|
`init()` returns a handle. Every method is safe to call at any time: none throws, and the promises never reject.
|
|
140
231
|
|
|
141
232
|
```ts
|
|
233
|
+
import { init } from "@commentkit/comment-kit";
|
|
234
|
+
|
|
142
235
|
const kit = init({ project: "pk_live_your_key" });
|
|
143
236
|
|
|
144
237
|
kit.show(); // show the widget (same as Cmd/Ctrl+Shift+K)
|
|
@@ -151,6 +244,7 @@ await kit.signOut(); // sign the reviewer out of CommentKit on this brows
|
|
|
151
244
|
kit.session(); // { person, role, project, environment, capabilities } | null
|
|
152
245
|
const off = kit.on("thread:created", ({ thread }) => console.log(thread.reference));
|
|
153
246
|
kit.destroy(); // release this handle; the last one removes the widget
|
|
247
|
+
kit.client; // the CommentKitClient underneath (see Headless), e.g. kit.client.pageKey()
|
|
154
248
|
```
|
|
155
249
|
|
|
156
250
|
`init()` can be called more than once: each call returns its own handle onto the same widget, which stays until the last handle is destroyed. A second copy of the SDK on the same page (npm and the script tag together) stays off and says so in the console.
|
|
@@ -202,13 +296,13 @@ Read this before you add CommentKit to a client's production site.
|
|
|
202
296
|
- the CommentKit browser extension turned comments on for this tab;
|
|
203
297
|
- they pressed Cmd/Ctrl+Shift+K. This is remembered on that browser (`commentkit:active` in `localStorage`) once the widget has shown.
|
|
204
298
|
|
|
205
|
-
Turn the shortcut off with `toggleShortcut: false` (`data-toggle-shortcut="false"`, `toggle-shortcut="false"`).
|
|
299
|
+
Turn the shortcut off with `toggleShortcut: false` (`data-toggle-shortcut="false"`, `toggle-shortcut="false"`). When the key shows the widget or opens its inbox, your page's own handlers do not get it (its keydown, keypress and keyup stop in CommentKit's listener on `window`, capture phase), so a Cmd/Ctrl+K search that ignores Shift does not open too. A listener your page adds to `window`'s capture phase before CommentKit's script runs still sees it. `hideOnProduction: false` shows the widget to every visitor. If the widget crashes three times in a row on a browser, it stays hidden there for six hours unless a link, the shortcut or `show()` brings it back.
|
|
206
300
|
|
|
207
301
|
**What it adds to the page.**
|
|
208
302
|
|
|
209
303
|
- One element, `<div data-commentkit-host>`, appended to `<html>` (not `<body>`, which some frameworks replace), with the widget inside an open Shadow DOM. Its styles are constructable stylesheets inside that shadow root; no CSS reaches your page. From the script tag it joins the page after the `load` event, when the browser is idle.
|
|
210
304
|
- The script tag adds one global, `window.CommentKit`, while the widget is shown, and marks `<html data-commentkit-loader>` so that Turbo, Livewire and htmx page changes do not start it twice. npm installs add no global.
|
|
211
|
-
-
|
|
305
|
+
- `keydown`, `keypress` and `keyup` listeners on `window` (capture) for Cmd/Ctrl+Shift+K (unless `toggleShortcut` is `false`).
|
|
212
306
|
- Only when the project turns console or network capture on, and only while the widget is shown: wrappers around `console.error`, `console.warn`, `fetch` and `XMLHttpRequest`, and `error` and `unhandledrejection` listeners. They record metadata only (see [Privacy](#privacy)).
|
|
213
307
|
- No cookies. One IndexedDB database, `commentkit` (store `keys`), holding one record per project key: the browser's sign-in key for that website (`{ pair }`, an ECDSA P-256 key pair whose private key cannot be read out, see [Sessions are bound to this browser](#sessions-are-bound-to-this-browser)). It is made at the first sign-in and deleted at sign-out. `localStorage` and `sessionStorage` keys, all starting `commentkit:`: the sign-in (`commentkit:v1:<project key>`, a rotating refresh token that only works together with that key; in `sessionStorage` when the project turns "keep reviewers signed in" off, and not stored at all where IndexedDB is unavailable), unsent drafts (`commentkit:draft:v2:…`, hashed keys, deleted after 7 days), the reader's preferences (`commentkit:v1:prefs`, `commentkit:theme`, `commentkit:dock`, `commentkit:welcomed`, `commentkit:agent`, `commentkit:dblclick-hint`), activation and the crash guard (`commentkit:active`, `commentkit:crashes`), and short-lived sign-in and hand-off state (`commentkit:pkce:<key>`, `commentkit:share`, `commentkit:pending-*`, `commentkit:guest-details`, `commentkit:confetti`, and `commentkit:lock:*` in browsers without Web Locks).
|
|
214
308
|
|
|
@@ -242,10 +336,10 @@ The exact hosts for your project are listed at `https://commentkit.dev/docs/csp`
|
|
|
242
336
|
|
|
243
337
|
**Removing it.** `kit.destroy()` (the last handle), or `window.CommentKit.destroy()` for the script tag, removes the element, the listeners, the wrappers and the global. Signing out, from your code with `signOut()`, from the widget's Settings or in another tab, ends the session and removes that person's drafts on this device.
|
|
244
338
|
|
|
245
|
-
**No automatic updates.** `/cdn/v1/loader.js` always loads the latest
|
|
339
|
+
**No automatic updates.** `/cdn/v1/loader.js` always loads the latest stable release (`v1` names the channel, not the SDK version). To pin one version, use its folder and its Subresource Integrity hash from `https://commentkit.dev/cdn/integrity.json` (keyed by version, then file):
|
|
246
340
|
|
|
247
341
|
```html
|
|
248
|
-
<script src="https://commentkit.dev/cdn/
|
|
342
|
+
<script src="https://commentkit.dev/cdn/2.0.0/loader.js" integrity="sha384-…" crossorigin="anonymous" data-project="pk_live_your_key" defer></script>
|
|
249
343
|
```
|
|
250
344
|
|
|
251
345
|
A pinned loader never switches version and loads the rest of the widget from the same folder, which never changes after it is published. The browser checks the hash of `loader.js` itself; the files the loader then imports (`commentkit.js` and its chunks) are not covered by that hash, because browsers do not apply a preloaded integrity hash to a later dynamic import (see [SECURITY.md](SECURITY.md#trust-model)). If you need every byte checked, install from npm and bundle it. A pinned version gets no fixes: move to a newer one on purpose. With npm, pin an exact version (`npm install --save-exact`) and commit your lockfile.
|
|
@@ -265,7 +359,7 @@ A pinned loader never switches version and loads the rest of the widget from the
|
|
|
265
359
|
|
|
266
360
|
**Masked by default.** Screenshots leave out password, hidden, email and phone inputs; any field whose `autocomplete` says it is a password, one-time code, payment, contact (email, phone, address, postal code) or identity (name, username, birthday, organisation) field; every iframe; the widget itself; and anything matching `data-commentkit-redact`, your `redact` selectors or the dashboard's privacy selectors. The text a comment keeps to find its spot never comes from those elements and never contains what anyone typed into a form field.
|
|
267
361
|
|
|
268
|
-
**`privacy: "strict"`** also leaves every form field's value (`input`, `textarea`, `select`) and every editable region (`contenteditable`) out of screenshots. The website's
|
|
362
|
+
**`privacy: "strict"`** also leaves every form field's value (`input`, `textarea`, `select`) and every editable region (`contenteditable`) out of screenshots. The website's **Settings → Feedback button** in CommentKit can turn this on for everyone ("Hide everything people type in screenshots"): the widget then uses strict mode whatever `init()` says. The stricter of the two always wins; `privacy: "standard"` never turns the dashboard's setting off.
|
|
269
363
|
|
|
270
364
|
**Mark private parts of your page** with the attribute, or list selectors:
|
|
271
365
|
|
|
@@ -274,6 +368,8 @@ A pinned loader never switches version and loads the rest of the widget from the
|
|
|
274
368
|
```
|
|
275
369
|
|
|
276
370
|
```ts
|
|
371
|
+
import { init } from "@commentkit/comment-kit";
|
|
372
|
+
|
|
277
373
|
init({ project: "pk_live_your_key", redact: [".customer-email", "#account-number"] });
|
|
278
374
|
```
|
|
279
375
|
|
|
@@ -291,7 +387,7 @@ See [SECURITY.md](SECURITY.md) for the trust model and how to report a vulnerabi
|
|
|
291
387
|
|
|
292
388
|
If your website has its own login, the people signed in to it can comment without a second sign-in. Your **server** makes a short-lived token for the signed-in user, and the page passes it to the widget.
|
|
293
389
|
|
|
294
|
-
1. In CommentKit open
|
|
390
|
+
1. In CommentKit open the website's **Settings → For developers**, under **Sign in from your website**, and create the identity secret. Keep it on your server only.
|
|
295
391
|
2. On your server, make a token for the signed-in user. It is an HS256 JWT with `sub` (your user id), `email`, optional `name`, `aud` (your project key), `iat` and `exp` (at most 10 minutes after `iat`). An optional `jti` makes it work once.
|
|
296
392
|
|
|
297
393
|
Node (no dependencies):
|
|
@@ -322,6 +418,8 @@ If your website has its own login, the people signed in to it can comment withou
|
|
|
322
418
|
3. Give the token to the widget. A function is best: the widget calls it again whenever the CommentKit session ends.
|
|
323
419
|
|
|
324
420
|
```ts
|
|
421
|
+
import { init } from "@commentkit/comment-kit";
|
|
422
|
+
|
|
325
423
|
init({ project: "pk_live_your_key", identity: () => fetch("/commentkit-token").then((r) => r.text()) });
|
|
326
424
|
```
|
|
327
425
|
|
|
@@ -350,8 +448,10 @@ Reviewers can approve a page when they are happy with it. In the inbox, above "T
|
|
|
350
448
|
|
|
351
449
|
Optional. The plugins tag elements with their source location in development, so a comment says which file and line to open, and they record the branch and commit of each build, so the widget shows this branch's feedback first.
|
|
352
450
|
|
|
451
|
+
Add them to the config you already have: keep your settings and plugins, add the `commentkit` import and put `commentkit()` first in `plugins`. Next.js: wrap your existing config in `withCommentKit()`. SvelteKit and Nuxt are in [plugins/README.md](plugins/README.md#sveltekit).
|
|
452
|
+
|
|
353
453
|
```ts
|
|
354
|
-
// vite.config.ts
|
|
454
|
+
// vite.config.ts
|
|
355
455
|
import { defineConfig } from "vite";
|
|
356
456
|
import react from "@vitejs/plugin-react";
|
|
357
457
|
import commentkit from "@commentkit/comment-kit/vite";
|
|
@@ -383,21 +483,25 @@ The command comes with the package. Run it as `npx @commentkit/comment-kit <comm
|
|
|
383
483
|
|
|
384
484
|
| Command | What it does |
|
|
385
485
|
| --- | --- |
|
|
386
|
-
| `login` | Shows a short code and opens CommentKit in your browser; confirm it and choose
|
|
486
|
+
| `login` | Shows a short code and opens CommentKit in your browser; confirm it and choose one website or all websites in a workspace, and what the CLI may do. |
|
|
387
487
|
| `logout` | Forgets the sign-in on this computer. |
|
|
388
|
-
| `status` |
|
|
488
|
+
| `status` | What you are signed in to, which website this folder uses and how it was chosen, and what the CLI may do. |
|
|
489
|
+
| `websites` | The websites the sign-in reaches, with the one this folder uses marked. |
|
|
490
|
+
| `use [website]` | Chooses the website for this folder (by id or name), saved in `.commentkit/project.json`. |
|
|
389
491
|
| `init` | Adds the key, the build plugin, `.commentkit/` in `.gitignore` and the widget to your app. Asks before each change. |
|
|
390
492
|
| `doctor [url]` | Finds out why the widget is not showing, in this folder and on your site. |
|
|
391
493
|
| `pull` | Saves open feedback and tasks to `.commentkit/feedback.md` for your coding agent. |
|
|
392
494
|
| `open [CK-12]` | Opens a task, or the task board, in the browser. |
|
|
393
|
-
| `token list\|create\|revoke` | Tokens for CI. |
|
|
495
|
+
| `token list\|create\|revoke` | Tokens for CI, each for one website. |
|
|
394
496
|
| `mcp install <cursor\|vscode\|claude\|codex>` | Adds the hosted CommentKit MCP server to your coding agent's config. |
|
|
395
497
|
|
|
498
|
+
Signed in to a whole workspace, each folder uses one website: `COMMENTKIT_PROJECT_ID` (with `COMMENTKIT_TOKEN`), else the folder's choice from `use`, else the publishable key in the folder, else the sign-in's only website. Otherwise the command asks you to run `use`.
|
|
499
|
+
|
|
396
500
|
Every command takes `--help`. Full reference: [cli/README.md](cli/README.md).
|
|
397
501
|
|
|
398
502
|
## AI agents (MCP)
|
|
399
503
|
|
|
400
|
-
Connect your coding agent to `https://commentkit.dev/mcp` and sign in when it asks; in the browser you choose the
|
|
504
|
+
Connect your coding agent to `https://commentkit.dev/mcp` and sign in when it asks; in the browser you choose the website and what the agent may do. Nothing to install:
|
|
401
505
|
|
|
402
506
|
```sh
|
|
403
507
|
npx @commentkit/comment-kit mcp install cursor # or vscode, claude, codex
|
|
@@ -423,8 +527,8 @@ A site with everything in place:
|
|
|
423
527
|
```text
|
|
424
528
|
CommentKit doctor (https://commentkit.dev)
|
|
425
529
|
|
|
426
|
-
✓ @commentkit/comment-kit
|
|
427
|
-
✓ The widget is added in
|
|
530
|
+
✓ @commentkit/comment-kit 2.0.0 is installed (Vite).
|
|
531
|
+
✓ The widget is added in src/main.ts.
|
|
428
532
|
✓ Project key pk_live_abcd… found in .env.local (VITE_COMMENTKIT_KEY).
|
|
429
533
|
✓ The build plugin is set up in vite.config.ts.
|
|
430
534
|
✓ The CLI is signed in to “Acme site”.
|
|
@@ -441,7 +545,7 @@ Everything CommentKit needs is in place.
|
|
|
441
545
|
A site that is not on the project's list and whose CSP blocks CommentKit:
|
|
442
546
|
|
|
443
547
|
```text
|
|
444
|
-
✗ https://shop.acme.com is not on the project's list of allowed websites, so the widget will not load there.
|
|
548
|
+
✗ https://shop.acme.com is not on the project's list of allowed websites, so the widget will not load there. A workspace owner or admin adds it in CommentKit, in the website's Settings → Install, under Addresses.
|
|
445
549
|
✓ The page has the CommentKit script tag (key pk_live_abcd…).
|
|
446
550
|
✗ The page's CSP blocks the CommentKit script: script-src does not allow https://commentkit.dev. Add https://commentkit.dev to script-src in the Content-Security-Policy header.
|
|
447
551
|
✗ The page's CSP blocks the widget's requests: default-src does not allow https://commentkit.dev. Add https://commentkit.dev to default-src in the Content-Security-Policy header.
|
package/SECURITY.md
CHANGED
|
@@ -48,7 +48,7 @@ What limits the damage:
|
|
|
48
48
|
- **Sign-in secrets travel only in URL fragments.** A sign-in link from a CommentKit email carries its secret after `#`, which browsers never send to servers, and so does the code email's "Send my comment" link (`#ck_code=`). The loader and `init()` take them off the address bar before anything else runs. The "Send my comment" link publishes only after the guest presses a button in the widget, so a mail scanner that opens links cannot use it; it works once, for 10 minutes, on the website the comment was left on, and the session it starts is bound to the key of the browser that pressed it.
|
|
49
49
|
- **Credentials never touch your page.** Sign-in happens in a CommentKit window (or a same-tab redirect) with PKCE.
|
|
50
50
|
- **Website sign-in is guest-only.** A token from your own login (`identity`) always makes a client-level reviewer, never a team member, and only works on the project's listed websites. Make every token single-use (a `jti`): the widget never re-sends a token that may already have reached the server. An email address that belongs to a reviewer who joined with an emailed code is refused (`identity_conflict`) unless you turn on "Trust email addresses from my website's login" (website settings → For developers). Call `signOut()` from your own logout so the next person on that browser starts signed out.
|
|
51
|
-
- **The project key identifies, it does not authorise.** `pk_…` keys are public. The API accepts browser calls only from the website addresses listed
|
|
51
|
+
- **The project key identifies, it does not authorise.** `pk_…` keys are public. The API accepts browser calls only from the website addresses listed in the website's Settings → Install, under Addresses, and checks every action against the signed-in person's role. A `*.` wildcard there covers one level of subdomains only (`*.example.com` lets in `shop.example.com`, never `a.b.example.com`), and is refused on shared hosts where anyone can have a site (`vercel.app`, `github.io` and the like).
|
|
52
52
|
- **Agent tokens are for servers only.** They are scoped to one project, read-only unless a person grants more, refused when sent from a browser, and stop working when the person who made them loses access.
|
|
53
53
|
- **Feedback is untrusted.** The widget renders it as text, never as HTML. Agent prompts, `npx @commentkit/comment-kit pull` and the MCP server wrap it in `<untrusted-user-content>` fences.
|
|
54
54
|
- **Screenshots leave out private data** before the image is made (see [README → Privacy](README.md#privacy)). Uploaded images are re-encoded on the server, which removes EXIF and GPS data.
|
|
@@ -57,7 +57,7 @@ What limits the damage:
|
|
|
57
57
|
|
|
58
58
|
1. **Load only the scripts you trust** on pages where the widget runs, and keep CommentKit off payment, password-reset, medical and financial pages unless you have reviewed them. Page addresses, titles, selected text, comments and attachments can still contain personal data.
|
|
59
59
|
2. **Pin and review releases** if you need to: an exact npm version and your lockfile, or a pinned `/cdn/<version>/loader.js` with its `integrity` hash (see [README → What CommentKit does to your page](README.md#what-commentkit-does-to-your-page)). The `integrity` hash covers `loader.js` only: the widget files it imports from the same version folder are not checked by the browser. A `<link rel="modulepreload" integrity>` does not close that gap: in our tests WebKit ignores it, and Chromium and Firefox fetch the file again, unchecked, for an `import()` that starts after the preload finished (Firefox also skips it for imported chunks). To have every byte checked, install from npm and serve the widget from your own bundle.
|
|
60
|
-
3. **List only the websites you need**
|
|
60
|
+
3. **List only the websites you need** in the website's Settings → Install, under Addresses, and remove old preview patterns. Prefer exact addresses; a wildcard reaches one subdomain level.
|
|
61
61
|
4. **Use a Content Security Policy.** CommentKit needs no `unsafe-eval` or `unsafe-inline`. The directives are in the README; `npx @commentkit/comment-kit doctor <url>` checks a page's policy. Under Trusted Types, allow the `commentkit-capture` policy name.
|
|
62
62
|
5. **Mark private regions** with `data-commentkit-redact` or `redact`, and use `privacy: "strict"` on pages full of forms, or turn on "Hide everything people type in screenshots" in the website's settings in CommentKit to enforce it everywhere (the widget uses the stricter of the two). Add your own privacy notice there too: guests then see a link to it next to CommentKit's.
|
|
63
63
|
6. **Attachments.** Your CommentKit workspace may limit attachments to images; the widget then offers and accepts only those.
|
package/dist/node/cli/api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// HTTP for the CLI: OAuth (device sign-in, refresh) and the project agent API.
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { checkEndpoint } from "../shared/endpoint.js";
|
|
4
|
-
import { credentialsPath, load, saveLocked, withLock } from "./credentials.js";
|
|
4
|
+
import { credentialsPath, load, saveLocked, signInTarget, withLock } from "./credentials.js";
|
|
5
5
|
const DEFAULT_ENDPOINT = "https://commentkit.dev";
|
|
6
6
|
const DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
7
7
|
const TIMEOUT_MS = 30_000;
|
|
@@ -104,34 +104,45 @@ const SIGNED_OUT = "Your sign-in has ended. Run `npx @commentkit/comment-kit log
|
|
|
104
104
|
export const SIGN_IN_AGAIN = "This computer's CommentKit sign-in no longer works. Run `npx @commentkit/comment-kit login` again.";
|
|
105
105
|
/** An access token this close to expiry is refreshed before use. */
|
|
106
106
|
const EXPIRY_MARGIN_MS = 60_000;
|
|
107
|
-
/**
|
|
108
|
-
|
|
107
|
+
/**
|
|
108
|
+
* The agent API with a CI token from the environment or the saved sign-in (refreshed when needed). A
|
|
109
|
+
* sign-in may cover one website or every website of a workspace: which website a command uses is
|
|
110
|
+
* chosen in website.ts (chooseWebsite), never here.
|
|
111
|
+
*/
|
|
112
|
+
export class Connection {
|
|
109
113
|
endpoint;
|
|
110
|
-
|
|
114
|
+
access;
|
|
111
115
|
token;
|
|
112
116
|
credential;
|
|
113
117
|
retryDelayMs;
|
|
114
|
-
|
|
118
|
+
projectList = null;
|
|
119
|
+
constructor(endpoint, access, token, credential, retryDelayMs = RETRY_DELAY_MS) {
|
|
115
120
|
this.endpoint = endpoint;
|
|
116
|
-
this.
|
|
121
|
+
this.access = access;
|
|
117
122
|
this.token = token;
|
|
118
123
|
this.credential = credential;
|
|
119
124
|
this.retryDelayMs = retryDelayMs;
|
|
120
125
|
}
|
|
121
|
-
static async
|
|
126
|
+
static async open(endpoint = endpointFrom(), env = process.env, options = {}) {
|
|
122
127
|
if (env.COMMENTKIT_TOKEN) {
|
|
123
128
|
const id = Number(env.COMMENTKIT_PROJECT_ID);
|
|
124
129
|
if (!Number.isInteger(id) || id < 1)
|
|
125
130
|
throw new CliError("Set COMMENTKIT_PROJECT_ID to the numeric project id when using COMMENTKIT_TOKEN.");
|
|
126
|
-
return new
|
|
131
|
+
return new Connection(endpoint, { kind: "token", projectId: id }, env.COMMENTKIT_TOKEN, null, options.retryDelayMs);
|
|
127
132
|
}
|
|
128
133
|
const credential = load(endpoint);
|
|
129
|
-
|
|
134
|
+
const target = signInTarget(credential);
|
|
135
|
+
if (!credential.access_token || !target)
|
|
130
136
|
throw new CliError("You are not signed in. Run `npx @commentkit/comment-kit login` first (or set COMMENTKIT_TOKEN and COMMENTKIT_PROJECT_ID).", "signed_out");
|
|
131
|
-
const
|
|
137
|
+
const connection = new Connection(endpoint, target, credential.access_token, credential, options.retryDelayMs);
|
|
132
138
|
if ((credential.expires_at ?? 0) < Date.now() + EXPIRY_MARGIN_MS)
|
|
133
|
-
await
|
|
134
|
-
return
|
|
139
|
+
await connection.renew();
|
|
140
|
+
return connection;
|
|
141
|
+
}
|
|
142
|
+
/** The websites these credentials reach now (`GET /agent/projects`), by name. Asked once per run. */
|
|
143
|
+
projects() {
|
|
144
|
+
this.projectList ??= this.request("/projects").then((answer) => answer.data);
|
|
145
|
+
return this.projectList;
|
|
135
146
|
}
|
|
136
147
|
/**
|
|
137
148
|
* Get a working access token. The refresh token rotates on every use, so this runs under the
|
|
@@ -146,8 +157,10 @@ export class Project {
|
|
|
146
157
|
const latest = load(this.endpoint, path);
|
|
147
158
|
if (!latest.refresh_token || !latest.access_token)
|
|
148
159
|
throw new CliError(SIGNED_OUT, "signed_out");
|
|
149
|
-
|
|
150
|
-
|
|
160
|
+
const target = signInTarget(latest);
|
|
161
|
+
if (target?.kind !== this.access.kind || target.id !== this.access.id) {
|
|
162
|
+
throw new CliError("You signed in again (to another website or workspace) while this was running. Run the command again.", "signed_out");
|
|
163
|
+
}
|
|
151
164
|
const refreshedElsewhere = latest.access_token !== this.token && (latest.expires_at ?? 0) > Date.now() + EXPIRY_MARGIN_MS;
|
|
152
165
|
if (!refreshedElsewhere) {
|
|
153
166
|
const answer = await refresh(this.endpoint, latest);
|
|
@@ -159,6 +172,7 @@ export class Project {
|
|
|
159
172
|
Object.assign(this.credential, latest);
|
|
160
173
|
}, path);
|
|
161
174
|
}
|
|
175
|
+
/** A request to the agent API; `path` is under /api/v1/agent (for example /projects/7/threads). */
|
|
162
176
|
async request(path, init = {}) {
|
|
163
177
|
const qs = new URLSearchParams(Object.entries(init.query ?? {}).filter(([, v]) => v !== undefined && v !== "").map(([k, v]) => [k, String(v)])).toString();
|
|
164
178
|
const method = init.method ?? "GET";
|
|
@@ -171,7 +185,7 @@ export class Project {
|
|
|
171
185
|
const last = attempt >= MAX_RETRIES;
|
|
172
186
|
let answer;
|
|
173
187
|
try {
|
|
174
|
-
answer = await call(`${this.endpoint}/api/v1/agent
|
|
188
|
+
answer = await call(`${this.endpoint}/api/v1/agent${path}${qs ? `?${qs}` : ""}`, {
|
|
175
189
|
method,
|
|
176
190
|
headers: { authorization: `Bearer ${this.token}`, ...(init.body === undefined ? {} : { "content-type": "application/json" }), ...(key ? { "idempotency-key": key } : {}) },
|
|
177
191
|
body: init.body === undefined ? undefined : JSON.stringify(init.body),
|
|
@@ -213,6 +227,38 @@ export class Project {
|
|
|
213
227
|
return this.retryDelayMs * 2 ** attempt;
|
|
214
228
|
}
|
|
215
229
|
}
|
|
230
|
+
/** The agent API for one website. */
|
|
231
|
+
export class Project {
|
|
232
|
+
connection;
|
|
233
|
+
projectId;
|
|
234
|
+
name;
|
|
235
|
+
chosenBy;
|
|
236
|
+
constructor(connection, projectId,
|
|
237
|
+
/** The website's name when it is known without asking (the sign-in, the list or the folder's file). */
|
|
238
|
+
name = null, chosenBy = { how: "sign-in" }) {
|
|
239
|
+
this.connection = connection;
|
|
240
|
+
this.projectId = projectId;
|
|
241
|
+
this.name = name;
|
|
242
|
+
this.chosenBy = chosenBy;
|
|
243
|
+
}
|
|
244
|
+
get endpoint() {
|
|
245
|
+
return this.connection.endpoint;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The website this folder uses, with a CI token from the environment or the saved sign-in. The order
|
|
249
|
+
* (environment, .commentkit/project.json, the folder's publishable key, the only website) is in
|
|
250
|
+
* website.ts, chooseWebsite.
|
|
251
|
+
*/
|
|
252
|
+
static async connect(endpoint = endpointFrom(), env = process.env, options = {}, cwd = process.cwd()) {
|
|
253
|
+
const connection = await Connection.open(endpoint, env, options);
|
|
254
|
+
// Imported when needed: website.ts reads the folder with doctor.ts and init.ts, which import this file.
|
|
255
|
+
const { chooseWebsite } = await import("./website.js");
|
|
256
|
+
return chooseWebsite(connection, cwd);
|
|
257
|
+
}
|
|
258
|
+
request(path, init = {}) {
|
|
259
|
+
return this.connection.request(`/projects/${this.projectId}${path}`, init);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
216
262
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
217
263
|
/** Retry-After (seconds or an HTTP date) in ms. Absent means 1 s; unreadable means null. */
|
|
218
264
|
export function retryAfterMs(header, now = Date.now()) {
|
|
@@ -8,6 +8,14 @@ import { createHash, randomBytes } from "node:crypto";
|
|
|
8
8
|
import { chmodSync, closeSync, copyFileSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
9
9
|
import { homedir, hostname } from "node:os";
|
|
10
10
|
import { dirname, join } from "node:path";
|
|
11
|
+
const positive = (value) => typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
12
|
+
export function signInTarget(credential) {
|
|
13
|
+
if (positive(credential.project_id))
|
|
14
|
+
return { kind: "website", id: credential.project_id, name: String(credential.project_name ?? "") };
|
|
15
|
+
if (positive(credential.workspace_id))
|
|
16
|
+
return { kind: "workspace", id: credential.workspace_id, name: String(credential.workspace_name ?? "") };
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
11
19
|
/** A lock older than this is from a run that died; nothing holding it takes longer (a request times out at 30 s). */
|
|
12
20
|
export const LOCK_STALE_MS = 60_000;
|
|
13
21
|
/** How long to wait for another run to finish with the file. */
|