@commentkit/comment-kit 2.0.1 → 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 +33 -0
- package/README.md +14 -6
- package/dist/node/cli/api.js +61 -15
- package/dist/node/cli/credentials.js +8 -0
- package/dist/node/cli/doctor.js +68 -5
- package/dist/node/cli/main.js +275 -52
- package/dist/node/cli/website.js +140 -0
- package/dist/node/types/next.d.ts +4 -4
- package/dist/npm/THIRD_PARTY_NOTICES.txt +47 -0
- package/dist/npm/chunks/{AgentSend-DOy3jhyF.js → AgentSend-pA7Ufvye.js} +3 -3
- 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-7hcN765o.js → Guest-Bi7hlzhs.js} +18 -17
- package/dist/npm/chunks/{MarkupEditor-6bJGpWGO.js → MarkupEditor-WU3USeTk.js} +2 -2
- package/dist/npm/chunks/{Panel-ChPUB68C.js → Panel-DhAzbUbC.js} +308 -309
- package/dist/npm/chunks/{Settings-CB5eEKnf.js → Settings-BmKqPX40.js} +34 -33
- package/dist/npm/chunks/{Shortcuts-eAyjJ89P.js → Shortcuts-Bl-c0Sez.js} +25 -23
- package/dist/npm/chunks/SignInFirst-CmGvSYkQ.js +35 -0
- package/dist/npm/chunks/{StyleEditor-CZTdAA5c.js → StyleEditor-D6fUnlwq.js} +4 -4
- package/dist/npm/chunks/{StylePanel-B4pHQUL9.js → StylePanel-C-Gikxt1.js} +3 -3
- package/dist/npm/chunks/TaskFields-CaKi523b.js +617 -0
- package/dist/npm/chunks/ThreadCard-d_3pUB5V.js +1142 -0
- package/dist/npm/chunks/{Viewer-DY6zb90M.js → Viewer-BULQsi9-.js} +9 -8
- package/dist/npm/chunks/{agent-MTQHr9ei.js → agent-DHdhIJ3s.js} +1 -1
- package/dist/npm/chunks/{ar-L5cQ-NPe.js → ar-B5UszrQp.js} +51 -12
- package/dist/npm/chunks/{card-bits-CTdrkYn8.js → card-bits-cV8GdFWX.js} +12 -10
- package/dist/npm/chunks/{client-7eVxvg5j.js → client-Cv8ddtuM.js} +13 -11
- package/dist/npm/chunks/{confetti-BIs5s14P.js → confetti-B9zlyILU.js} +1 -1
- package/dist/npm/chunks/{context-Cf6khm7A.js → context-CsHnabaA.js} +1 -1
- package/dist/npm/chunks/{de-D0C-v6tP.js → de-BE0Aaq8u.js} +51 -12
- package/dist/npm/chunks/{dpop-0A76OPa9.js → dpop-CwW9ifkq.js} +1 -1
- package/dist/npm/chunks/entrance-Bn_5M9uO.js +90 -0
- package/dist/npm/chunks/{es-Bw4Dj9tN.js → es-BQviao4d.js} +51 -12
- package/dist/npm/chunks/{extension-SmoH5AA4.js → extension-CnQTDC1j.js} +2 -2
- package/dist/npm/chunks/{extension-DFVOvciD.js → extension-DXhz81XD.js} +1 -1
- package/dist/npm/chunks/{files-4lV9YQIX.js → files-DLEr_wmh.js} +2 -2
- package/dist/npm/chunks/{fr-TkuQaIAa.js → fr-C5gu6A06.js} +51 -12
- package/dist/npm/chunks/{hi-DXSH2U8d.js → hi-DXfQ5EvY.js} +51 -12
- package/dist/npm/chunks/{i18n-aVSu9TcJ.js → i18n-Mgs9VOuk.js} +17 -21
- package/dist/npm/chunks/icons-_C6ZWmBY.js +141 -0
- package/dist/npm/chunks/{identify-BGYh2dVo.js → identify-BnQGJOa0.js} +1 -1
- package/dist/npm/chunks/{it-CiWA_bch.js → it-BPHt13FV.js} +51 -12
- package/dist/npm/chunks/{ja-C-QmR3yz.js → ja-BkCqyKR0.js} +50 -11
- package/dist/npm/chunks/late-words-D4Oo_yhJ.js +57 -0
- package/dist/npm/chunks/{live-BExWHzQ7.js → live-DXcxj_Af.js} +28 -22
- package/dist/npm/chunks/{nl-CEmZRqjX.js → nl-DZxdLLMU.js} +51 -12
- package/dist/npm/chunks/{page-key-HSY3Lze5.js → page-key-UqAozdZi.js} +1 -1
- package/dist/npm/chunks/{pick-B3sR7jtS.js → pick-C20RVUas.js} +1 -1
- package/dist/npm/chunks/{pkce-CfZhiNBi.js → pkce-BPvWoBrr.js} +1 -1
- package/dist/npm/chunks/{pt-BR-b-a8sxO8.js → pt-BR-lA9mJ05F.js} +51 -12
- package/dist/npm/chunks/{report-DaVuoRYS.js → report-BjUgUNnT.js} +1 -1
- package/dist/npm/chunks/{show-BoN8AC-F.js → show-BinoJyED.js} +7 -7
- package/dist/npm/chunks/signin-C2jjsxz9.js +101 -0
- package/dist/npm/chunks/{source-mk3rGBBQ.js → source-NuflODx3.js} +1 -1
- package/dist/npm/chunks/{src-C8rZFyL_.js → src-9o2Ocq8d.js} +21 -15
- package/dist/npm/chunks/start-Cbx6rMrr.js +1904 -0
- package/dist/npm/chunks/states-DLMCvwes.js +3 -0
- package/dist/npm/chunks/{upload-B2mkgMeJ.js → upload-C4NpM-jE.js} +1 -1
- package/dist/npm/chunks/uploads-CY4bDbaI.js +1236 -0
- package/dist/npm/chunks/{wrap-DW6EFbVQ.js → wrap-D-xTKIzj.js} +20 -20
- package/dist/npm/chunks/{zh-CN-JTscW8u8.js → zh-CN-yqaDHwBx.js} +51 -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 +17 -2
- package/dist/npm/vue.js +5 -1
- package/package.json +2 -1
- package/dist/npm/chunks/Checklist-CW_SwMpS.js +0 -282
- package/dist/npm/chunks/Composer-Bveq5QrK.js +0 -727
- package/dist/npm/chunks/TaskFields-C8BX0Sgg.js +0 -289
- package/dist/npm/chunks/ThreadCard-B1EsX3PR.js +0 -1160
- package/dist/npm/chunks/late-words-80_VWt8S.js +0 -14
- package/dist/npm/chunks/signin-BOWr_WCo.js +0 -75
- package/dist/npm/chunks/start-CV4j78_q.js +0 -1894
- package/dist/npm/chunks/states-b9Bv3Ci7.js +0 -3
- package/dist/npm/chunks/uploads-8AxyRq7g.js +0 -1147
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
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
|
+
|
|
3
36
|
## [2.0.1] - 2026-11-20
|
|
4
37
|
|
|
5
38
|
### Added
|
package/README.md
CHANGED
|
@@ -210,15 +210,19 @@ One table for every way in. `init()` and the React, Vue and Svelte helpers take
|
|
|
210
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"` |
|
|
211
211
|
| `theme` | `"auto" \| "light" \| "dark"` | the dashboard setting | Colour scheme. A reader's own choice in Settings wins. | — | `theme` |
|
|
212
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` |
|
|
213
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"` |
|
|
214
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"` |
|
|
215
216
|
| `locale` | `string` | `<html lang>`, then the browser | Widget language, for example `"fr"` or `"pt-BR"` (see [Languages](#languages)). | `data-locale` | `locale` |
|
|
216
|
-
| `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` |
|
|
217
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"` |
|
|
218
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"` |
|
|
219
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) |
|
|
220
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)`) |
|
|
221
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
|
+
|
|
222
226
|
Settings that apply without a deploy live in the dashboard: pausing feedback, theme, position, accent colour, privacy selectors, and console and network capture.
|
|
223
227
|
|
|
224
228
|
### Methods and events
|
|
@@ -292,13 +296,13 @@ Read this before you add CommentKit to a client's production site.
|
|
|
292
296
|
- the CommentKit browser extension turned comments on for this tab;
|
|
293
297
|
- they pressed Cmd/Ctrl+Shift+K. This is remembered on that browser (`commentkit:active` in `localStorage`) once the widget has shown.
|
|
294
298
|
|
|
295
|
-
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.
|
|
296
300
|
|
|
297
301
|
**What it adds to the page.**
|
|
298
302
|
|
|
299
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.
|
|
300
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.
|
|
301
|
-
-
|
|
305
|
+
- `keydown`, `keypress` and `keyup` listeners on `window` (capture) for Cmd/Ctrl+Shift+K (unless `toggleShortcut` is `false`).
|
|
302
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)).
|
|
303
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).
|
|
304
308
|
|
|
@@ -479,16 +483,20 @@ The command comes with the package. Run it as `npx @commentkit/comment-kit <comm
|
|
|
479
483
|
|
|
480
484
|
| Command | What it does |
|
|
481
485
|
| --- | --- |
|
|
482
|
-
| `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. |
|
|
483
487
|
| `logout` | Forgets the sign-in on this computer. |
|
|
484
|
-
| `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`. |
|
|
485
491
|
| `init` | Adds the key, the build plugin, `.commentkit/` in `.gitignore` and the widget to your app. Asks before each change. |
|
|
486
492
|
| `doctor [url]` | Finds out why the widget is not showing, in this folder and on your site. |
|
|
487
493
|
| `pull` | Saves open feedback and tasks to `.commentkit/feedback.md` for your coding agent. |
|
|
488
494
|
| `open [CK-12]` | Opens a task, or the task board, in the browser. |
|
|
489
|
-
| `token list\|create\|revoke` | Tokens for CI. |
|
|
495
|
+
| `token list\|create\|revoke` | Tokens for CI, each for one website. |
|
|
490
496
|
| `mcp install <cursor\|vscode\|claude\|codex>` | Adds the hosted CommentKit MCP server to your coding agent's config. |
|
|
491
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
|
+
|
|
492
500
|
Every command takes `--help`. Full reference: [cli/README.md](cli/README.md).
|
|
493
501
|
|
|
494
502
|
## AI agents (MCP)
|
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. */
|
package/dist/node/cli/doctor.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { DASHBOARD } from "../shared/dashboard-places.js";
|
|
6
|
-
import { CliError,
|
|
6
|
+
import { CliError, Connection, endpointFrom } from "./api.js";
|
|
7
7
|
import { safeUrl } from "./format.js";
|
|
8
8
|
import { describePlace, PLUGIN_IMPORT, plan, templatesWithTag } from "./init.js";
|
|
9
9
|
import { PUBLISHABLE_KEY } from "./main.js";
|
|
@@ -454,6 +454,15 @@ function projectSetup(cwd, flagKey, env) {
|
|
|
454
454
|
}
|
|
455
455
|
return { checks, key, keySource, installedVersion, bundled, appFound };
|
|
456
456
|
}
|
|
457
|
+
/**
|
|
458
|
+
* The publishable key written in this folder, where doctor and init look for it: the env files init
|
|
459
|
+
* writes, the script tag in index.html, the default in the entry file, a Blade tag. Not the shell's
|
|
460
|
+
* environment variables: they belong to the terminal, not to the folder.
|
|
461
|
+
*/
|
|
462
|
+
export function folderKey(cwd) {
|
|
463
|
+
const { key, keySource } = projectSetup(cwd, undefined, {});
|
|
464
|
+
return key && keySource && PUBLISHABLE_KEY.test(key) ? { key, source: keySource } : null;
|
|
465
|
+
}
|
|
457
466
|
/** Code hosts and registries: a package.json homepage there is not the website. */
|
|
458
467
|
const NOT_A_SITE = /(^|\.)(github\.com|gitlab\.com|bitbucket\.org|npmjs\.com|npmjs\.org)$/i;
|
|
459
468
|
/**
|
|
@@ -535,11 +544,32 @@ function keyCheck(answer, key, host, sdk) {
|
|
|
535
544
|
return { config: null, check: { id: "api.key", status: "warn", message: "CommentKit is getting too many requests from this network right now, so the key was not checked.", fix: `Run ${CLI} doctor again in a minute.` } };
|
|
536
545
|
return { config: null, check: { id: "api.key", status: "fail", message: `CommentKit answered HTTP ${status} when checking the key${json.detail ? `: ${clean(json.detail)}` : ""}.`, fix: `Run ${CLI} doctor again in a few minutes; if it keeps failing, contact CommentKit support.` } };
|
|
537
546
|
}
|
|
538
|
-
|
|
547
|
+
const keysOf = (p) => [p.publishable_keys?.live, p.publishable_keys?.test].filter((k) => typeof k === "string");
|
|
548
|
+
async function signedIn(cwd) {
|
|
549
|
+
// Imported when needed: website.ts imports this file.
|
|
550
|
+
const { chooseWebsite, describeChoice } = await import("./website.js");
|
|
539
551
|
try {
|
|
540
|
-
const
|
|
552
|
+
const connection = await Connection.open();
|
|
553
|
+
if (connection.access.kind === "workspace") {
|
|
554
|
+
const websites = (await connection.projects()).map((p) => ({ id: p.id, name: p.name, keys: keysOf(p) }));
|
|
555
|
+
let uses = null;
|
|
556
|
+
let problem = null;
|
|
557
|
+
try {
|
|
558
|
+
const project = await chooseWebsite(connection, cwd);
|
|
559
|
+
uses = { id: project.projectId, name: project.name ?? "", how: describeChoice(project.chosenBy, cwd) };
|
|
560
|
+
}
|
|
561
|
+
catch (error) {
|
|
562
|
+
// No website chosen for this folder yet, or a choice it no longer reaches: said in the checks.
|
|
563
|
+
if (!(error instanceof CliError))
|
|
564
|
+
throw error;
|
|
565
|
+
if (error.code === "folder_choice")
|
|
566
|
+
problem = error.message;
|
|
567
|
+
}
|
|
568
|
+
return { name: connection.access.name, keys: websites.flatMap((w) => w.keys), workspace: { websites }, uses, problem };
|
|
569
|
+
}
|
|
570
|
+
const project = await chooseWebsite(connection, cwd);
|
|
541
571
|
const info = await project.request("");
|
|
542
|
-
return { name: info.data.name, keys:
|
|
572
|
+
return { name: info.data.name, keys: keysOf(info.data) };
|
|
543
573
|
}
|
|
544
574
|
catch (error) {
|
|
545
575
|
if (error instanceof CliError && error.code === "signed_out")
|
|
@@ -602,11 +632,37 @@ export async function doctor(options, deps = {}) {
|
|
|
602
632
|
checks.push({ id: "setup.key", status: "fail", message: "No project key to check: none in this folder" + (site ? " or on the page." : "."), fix: `Run doctor in your app's folder, or pass --key pk_… (the key is in ${DASHBOARD.install} in CommentKit).` });
|
|
603
633
|
// 2. Sign-in (optional for doctor).
|
|
604
634
|
let otherWebsite = null;
|
|
635
|
+
let otherWorkspace = null;
|
|
605
636
|
try {
|
|
606
|
-
const project = await (deps.project ?? signedIn)();
|
|
637
|
+
const project = await (deps.project ?? (() => signedIn(options.cwd)))();
|
|
607
638
|
if (!project) {
|
|
608
639
|
checks.push({ id: "signin", status: "info", message: "The CLI is not signed in, so the check that the key belongs to your project was skipped.", fix: `Run ${CLI} login to include it.` });
|
|
609
640
|
}
|
|
641
|
+
else if (project.workspace) {
|
|
642
|
+
// A sign-in for every website of a workspace: say which website this folder uses.
|
|
643
|
+
const { websites } = project.workspace;
|
|
644
|
+
checks.push({ id: "signin", status: "pass", message: `The CLI is signed in to all websites in “${clean(project.name, 80)}” (${websites.length}).` });
|
|
645
|
+
const owner = key ? websites.find((w) => w.keys.includes(key)) : undefined;
|
|
646
|
+
const uses = project.uses;
|
|
647
|
+
const site = (w) => `“${clean(w.name, 80)}” (id ${w.id})`;
|
|
648
|
+
if (project.problem) {
|
|
649
|
+
checks.push({ id: "signin.website", status: "warn", message: clean(project.problem, 400), fix: `Run ${CLI} use to choose the website for this folder.` });
|
|
650
|
+
}
|
|
651
|
+
else if (owner && (!uses || uses.id === owner.id)) {
|
|
652
|
+
checks.push({ id: "signin.website", status: "pass", message: `This folder's key belongs to ${site(owner)}: commands in this folder use it.` });
|
|
653
|
+
}
|
|
654
|
+
else if (owner && uses) {
|
|
655
|
+
checks.push({ id: "signin.website", status: "warn", message: `This folder's key belongs to ${site(owner)}, but commands in this folder use ${site(uses)} (${uses.how}).`, fix: `If this folder is for ${site(owner)}, run ${CLI} use ${owner.id}.` });
|
|
656
|
+
}
|
|
657
|
+
else if (uses) {
|
|
658
|
+
checks.push({ id: "signin.website", status: "info", message: `Commands in this folder use ${site(uses)} (${uses.how}).` });
|
|
659
|
+
}
|
|
660
|
+
else if (!key) {
|
|
661
|
+
checks.push({ id: "signin.website", status: "info", message: "No website is chosen for this folder yet.", fix: `Run ${CLI} use to choose one (or ${CLI} init, which also adds the key).` });
|
|
662
|
+
}
|
|
663
|
+
if (key && !owner)
|
|
664
|
+
otherWorkspace = clean(project.name, 80);
|
|
665
|
+
}
|
|
610
666
|
else {
|
|
611
667
|
checks.push({ id: "signin", status: "pass", message: `The CLI is signed in to “${clean(project.name, 80)}”.` });
|
|
612
668
|
if (key && project.keys.length && !project.keys.includes(key))
|
|
@@ -637,6 +693,13 @@ export async function doctor(options, deps = {}) {
|
|
|
637
693
|
? { id: "signin.key", status: "info", message: `The terminal is signed in to “${otherWebsite}”, a different website from this folder's key${known ? ` (“${known}”)` : ""}. To switch, run ${CLI} login and choose ${known ? `“${known}”` : "this website"}.` }
|
|
638
694
|
: { id: "signin.key", status: "warn", message: `The key ${maskKey(key)} is not one of “${otherWebsite}”'s keys.`, fix: `If this app belongs to another website, ignore this; otherwise copy the key from ${DASHBOARD.install} in CommentKit.` });
|
|
639
695
|
}
|
|
696
|
+
// The folder's key belongs to none of the websites of the workspace the CLI is signed in to.
|
|
697
|
+
if (otherWorkspace && key) {
|
|
698
|
+
const known = config ? clean(config.project?.name, 80) : "";
|
|
699
|
+
checks.push(config
|
|
700
|
+
? { id: "signin.key", status: "info", message: `The terminal is signed in to all websites in “${otherWorkspace}”, and this folder's key${known ? ` (“${known}”)` : ""} belongs to none of them. To reach it, run ${CLI} login and choose ${known ? `“${known}”` : "this website"} or its workspace.` }
|
|
701
|
+
: { id: "signin.key", status: "warn", message: `The key ${maskKey(key)} is not a key of any website in “${otherWorkspace}”.`, fix: `If this app belongs to another workspace, ignore this; otherwise copy the key from ${DASHBOARD.install} in CommentKit.` });
|
|
702
|
+
}
|
|
640
703
|
// 4. The website.
|
|
641
704
|
if (site) {
|
|
642
705
|
const shown = clean(safeUrl(site.href), 200);
|