@commentkit/comment-kit 1.6.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +281 -597
- package/README.md +334 -154
- package/SECURITY.md +47 -46
- package/dist/node/THIRD_PARTY_NOTICES.txt +56 -0
- package/dist/node/browser.js +17 -0
- package/dist/node/cli/api.js +226 -0
- package/dist/node/cli/bin.js +18 -0
- package/dist/node/cli/credentials.js +268 -0
- package/dist/node/cli/doctor.js +725 -0
- package/dist/node/cli/format.js +54 -0
- package/dist/node/cli/init.js +372 -0
- package/dist/node/cli/main.js +519 -0
- package/dist/node/cli/mcp.js +114 -0
- package/dist/node/cli/open.js +20 -0
- package/dist/node/plugins/astro-B5y1Gtbf.js +31 -0
- package/dist/node/plugins/astro.js +26 -0
- package/dist/node/plugins/git-BIXLbL3f.js +92 -0
- package/dist/node/plugins/jsx-Bg4BdSph.js +7958 -0
- package/dist/node/plugins/next.js +48 -0
- package/dist/node/plugins/options-THop1K92.js +71 -0
- package/dist/node/plugins/transform-CKiAuSbk.js +1155 -0
- package/dist/node/plugins/vite-BdAYUW10.js +74 -0
- package/dist/node/plugins/vite.js +1 -0
- package/dist/node/plugins/webpack-R2U2DLlY.js +35 -0
- package/dist/node/plugins/webpack-loader.cjs +21 -0
- package/dist/node/plugins/webpack-loader.js +18 -0
- package/dist/node/plugins/webpack.js +1 -0
- package/dist/node/shared/endpoint.js +26 -0
- package/dist/node/shared/format.js +63 -0
- package/dist/node/types/astro.d.ts +11 -0
- package/dist/node/types/next.d.ts +34 -0
- package/dist/node/types/options.d.ts +59 -0
- package/dist/node/types/vite.d.ts +11 -0
- package/dist/node/types/webpack-loader.d.ts +22 -0
- package/dist/node/types/webpack.d.ts +27 -0
- package/dist/npm/THIRD_PARTY_NOTICES.txt +6 -6
- package/dist/npm/chunks/AgentSend-DxRJIYiz.js +68 -0
- package/dist/npm/chunks/Checklist-CnlfeSbc.js +282 -0
- package/dist/npm/chunks/Composer-B1bBVszY.js +725 -0
- package/dist/npm/chunks/Guest-vvNPz8h-.js +267 -0
- package/dist/npm/chunks/MarkupEditor-VCOXh9d2.js +338 -0
- package/dist/npm/chunks/Panel-F37vIL1K.js +1206 -0
- package/dist/npm/chunks/Settings-BGoZS2iV.js +231 -0
- package/dist/npm/chunks/Shortcuts-B2OMvczr.js +62 -0
- package/dist/npm/chunks/StyleEditor-CJ_d8Huf.js +46 -0
- package/dist/npm/chunks/StylePanel-yQzHHlY7.js +199 -0
- package/dist/npm/chunks/TaskFields-fmy6_HtK.js +289 -0
- package/dist/npm/chunks/ThreadCard-D51slKST.js +1113 -0
- package/dist/npm/chunks/Viewer-BOBadqmC.js +111 -0
- package/dist/npm/chunks/{agent-BDMQtOzH.js → agent-C1OQzBAm.js} +9 -9
- package/dist/npm/chunks/{anchor-BsradQhn.js → anchor-BsQNVkHj.js} +108 -85
- package/dist/npm/chunks/{ar-8tPch6W4.js → ar-CAJ3XT8e.js} +69 -19
- package/dist/npm/chunks/card-bits-CAnzrqx3.js +53 -0
- package/dist/npm/chunks/{client-EFTWxHbJ.js → client-kNAo2TTG.js} +282 -290
- package/dist/npm/chunks/confetti-CkBdSu19.js +49 -0
- package/dist/npm/chunks/context-B8UAzve0.js +20 -0
- package/dist/npm/chunks/context-BuMl7A07.js +48 -0
- package/dist/npm/chunks/{de-C63897uD.js → de-Dl18G48t.js} +60 -18
- package/dist/npm/chunks/dialog-GO04oC3D.js +3 -0
- package/dist/npm/chunks/dpop-U48QIQd7.js +96 -0
- package/dist/npm/chunks/drafts-B0ctr1g9.js +21 -0
- package/dist/npm/chunks/{es-CI2bSpvB.js → es-Dxk79lS9.js} +60 -18
- package/dist/npm/chunks/extension-CKFpPWmi.js +62 -0
- package/dist/npm/chunks/{extension-BST6LH1q.js → extension-E81hWyiT.js} +20 -12
- package/dist/npm/chunks/files-DyD5BZgp.js +114 -0
- package/dist/npm/chunks/{fr-rsVe-Lqk.js → fr-8BebGKYD.js} +118 -76
- package/dist/npm/chunks/{hi-cvwbSaWP.js → hi-BIN6Yy_p.js} +61 -19
- package/dist/npm/chunks/{i18n-C4v0M-6z.js → i18n-DOBt8e9U.js} +91 -56
- package/dist/npm/chunks/identify-CN-3xzqL.js +106 -0
- package/dist/npm/chunks/{it-C8tnV0BF.js → it-Cr6EwpPQ.js} +79 -37
- package/dist/npm/chunks/{ja-BWxDfC2f.js → ja-Iy3s5aur.js} +58 -16
- package/dist/npm/chunks/late-words-B2bmZceJ.js +12 -0
- package/dist/npm/chunks/live-CelVeZfP.js +85 -0
- package/dist/npm/chunks/locale-D8Q4Q2Nt.js +26 -0
- package/dist/npm/chunks/{nl-DNQ6eCht.js → nl-B84WHqqe.js} +61 -19
- package/dist/npm/chunks/page-key-DepmJzC1.js +62 -0
- package/dist/npm/chunks/{pick-CLyOdjnD.js → pick-yTyqtxN0.js} +45 -44
- package/dist/npm/chunks/pkce-ChKGSW_4.js +8 -0
- package/dist/npm/chunks/placement-BF_HOUDD.js +74 -0
- package/dist/npm/chunks/privacy-BWUGlHw5.js +57 -0
- package/dist/npm/chunks/{pt-BR-CkG7vpU2.js → pt-BR-DOkdlfoe.js} +60 -18
- package/dist/npm/chunks/{realtime-DIo-Wth4.js → realtime-C79zF50C.js} +14 -12
- package/dist/npm/chunks/report-CrIqQZDI.js +44 -0
- package/dist/npm/chunks/show-BgVC8gWY.js +97 -0
- package/dist/npm/chunks/signin-Dd1rb2BP.js +75 -0
- package/dist/npm/chunks/{source-CS7C6wJA.js → source-pXVve2Cx.js} +1 -1
- package/dist/npm/chunks/src-BTMy4Gyc.js +208 -0
- package/dist/npm/chunks/start-DtVlpt7p.js +1878 -0
- package/dist/npm/chunks/states-sfTbjZz8.js +3 -0
- package/dist/npm/chunks/upload-MgPYqPyE.js +42 -0
- package/dist/npm/chunks/uploads-D49mywwz.js +1146 -0
- package/dist/npm/chunks/wrap-Bl0gbnFa.js +69 -0
- package/dist/npm/chunks/{zh-CN-BKuZOLBE.js → zh-CN-Z5fQCb7G.js} +59 -17
- package/dist/npm/element.js +58 -21
- package/dist/npm/headless.js +7 -3
- package/dist/npm/index.js +3 -3
- package/dist/npm/react.js +18 -11
- package/dist/npm/svelte.js +28 -12
- package/dist/npm/types/adapters/react.d.ts +4 -1
- package/dist/npm/types/adapters/svelte.d.ts +4 -1
- package/dist/npm/types/adapters/vue.d.ts +35 -2
- package/dist/npm/types/anchor/index.d.ts +19 -0
- package/dist/npm/types/capture/privacy.d.ts +14 -0
- package/dist/npm/types/core/api.d.ts +20 -1
- package/dist/npm/types/core/auth.d.ts +40 -21
- package/dist/npm/types/core/client.d.ts +60 -4
- package/dist/npm/types/core/page-key.d.ts +42 -0
- package/dist/npm/types/core/types.d.ts +87 -4
- package/dist/npm/types/element.d.ts +17 -7
- package/dist/npm/types/headless.d.ts +2 -1
- package/dist/npm/types/index.d.ts +16 -6
- package/dist/npm/vue.js +44 -9
- package/package.json +88 -14
- package/dist/npm/chunks/AgentSend-2JPDseOo.js +0 -63
- package/dist/npm/chunks/Checklist-BpDXQebo.js +0 -257
- package/dist/npm/chunks/Composer-CAyj-c8e.js +0 -677
- package/dist/npm/chunks/Guest-ZdFmTcXI.js +0 -187
- package/dist/npm/chunks/MarkupEditor-BFplZwFy.js +0 -332
- package/dist/npm/chunks/Panel-BhZ4XRDR.js +0 -861
- package/dist/npm/chunks/Settings-SPG9EHUZ.js +0 -204
- package/dist/npm/chunks/Shortcuts-C28HVDw6.js +0 -58
- package/dist/npm/chunks/StyleEditor-ByZMtq10.js +0 -43
- package/dist/npm/chunks/StylePanel-Iwhce2tE.js +0 -197
- package/dist/npm/chunks/TaskFields-BsP_fVJg.js +0 -273
- package/dist/npm/chunks/ThreadCard-BzVZdDCb.js +0 -1030
- package/dist/npm/chunks/Viewer-CqtGrdD8.js +0 -108
- package/dist/npm/chunks/card-bits-Bna-g3Py.js +0 -124
- package/dist/npm/chunks/confetti-DTKpwF3O.js +0 -40
- package/dist/npm/chunks/drafts-akdBsOd0.js +0 -50
- package/dist/npm/chunks/extension-D-V3utTm.js +0 -53
- package/dist/npm/chunks/live-BCpJVBeN.js +0 -33
- package/dist/npm/chunks/report-BBrT3r89.js +0 -27
- package/dist/npm/chunks/src-C4FsVoUp.js +0 -148
- package/dist/npm/chunks/start-i9M-r3aH.js +0 -1800
- package/dist/npm/chunks/upload-DSv7EyBD.js +0 -41
- package/dist/npm/chunks/uploads-I01kdqQF.js +0 -1103
package/SECURITY.md
CHANGED
|
@@ -1,68 +1,69 @@
|
|
|
1
1
|
# Security Policy
|
|
2
2
|
|
|
3
|
-
## Supported
|
|
3
|
+
## Supported versions
|
|
4
4
|
|
|
5
|
-
| Release
|
|
6
|
-
|
|
|
7
|
-
| Latest published
|
|
8
|
-
| Older
|
|
9
|
-
|
|
|
5
|
+
| Release | Supported |
|
|
6
|
+
| --- | --- |
|
|
7
|
+
| Latest published release of `@commentkit/comment-kit` and `comment-kit-mcp` | Yes |
|
|
8
|
+
| Older releases of the current major | Fixes land in the latest release; upgrade to get them |
|
|
9
|
+
| Previous major | Security fixes for 24 months after the next major is released |
|
|
10
|
+
| Release candidates (npm `next`) | Test builds; not supported in production |
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
The `/cdn/v1/` script tag and `^` version ranges receive fixes automatically. Pinned versions (`/cdn/<version>/`, exact npm versions) do not: move to a newer one on purpose.
|
|
12
13
|
|
|
13
|
-
## Reporting a
|
|
14
|
+
## Reporting a vulnerability
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
Report it privately to **<hello@commentkit.dev>**. Do not open a public GitHub issue.
|
|
16
17
|
|
|
17
|
-
Include, where
|
|
18
|
+
Include, where you can:
|
|
18
19
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
20
|
+
- what the problem is and what an attacker could do with it;
|
|
21
|
+
- steps to reproduce (a proof of concept or a minimal host page);
|
|
22
|
+
- the package and version (`@commentkit/comment-kit` or `comment-kit-mcp`), or the part of the hosted service.
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
What to expect:
|
|
24
25
|
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
26
|
+
- acknowledgement within 2 business days;
|
|
27
|
+
- a first assessment within 7 days;
|
|
28
|
+
- a fix or a mitigation plan within 30 days for confirmed issues.
|
|
28
29
|
|
|
29
|
-
We
|
|
30
|
+
We credit reporters in the release notes unless you prefer not to be named.
|
|
30
31
|
|
|
31
32
|
## Scope
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
- `@commentkit/comment-kit`: the script-tag loader, `init()`, the `<comment-kit>` element, the React, Vue and Svelte helpers, the headless client, the build plugins (`/vite`, `/next`, `/webpack`, `/astro`) and the `commentkit` command.
|
|
35
|
+
- `comment-kit-mcp`, the local MCP server (`mcp/`).
|
|
36
|
+
- The browser extension (`extension/`), the WordPress plugin (`wordpress/commentkit`), and the Zapier and Make apps (`zapier/`, `make/`).
|
|
37
|
+
- The hosted service (`commentkit.dev`, the dashboard, the API and the hosted MCP server) at the same address.
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
- **The MCP server** (`comment-kit-mcp`, in `mcp/`).
|
|
37
|
-
- **The CLI** (`@commentkit/cli`, in `cli/`) and **the build plugins** (`@commentkit/build`, in `build/`).
|
|
38
|
-
- **The browser extension** (`extension/`), **the WordPress plugin** (`wordpress/commentkit`) and **the Zapier and Make apps** (`zapier/`, `make/`).
|
|
39
|
+
## Trust model
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
**The widget runs inside your page.** It has the same JavaScript privileges as every other script there. Shadow DOM keeps its styles apart from yours; it does not keep scripts apart. So any script on the page, including a compromised third-party script, can do what the signed-in reviewer can do in CommentKit for that project while the page is open: read the feedback they can see, comment, reply and approve pages, by calling the widget's own code. It can also read the reviewer's refresh token, which is kept in `localStorage` (or `sessionStorage`) for that website, but that token is useless on its own (next point).
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
What limits the damage:
|
|
43
44
|
|
|
44
|
-
- **
|
|
45
|
-
- **
|
|
46
|
-
- **
|
|
47
|
-
- **
|
|
48
|
-
- **
|
|
45
|
+
- **Sessions are bound to a key that cannot leave the browser** (DPoP, RFC 9449). At sign-in the widget makes a non-extractable ECDSA P-256 key for the website, kept in IndexedDB (database `commentkit`, store `keys`, one record per project key; in memory only where IndexedDB is unavailable, and then the refresh token is not stored either). The API binds every widget access and refresh token, and a guest's pending token, to that key, and every request that starts, renews or uses one must carry a new proof signed by it (`Authorization: DPoP` and a `DPoP` header with the method, URL, time, a single-use id and the token's hash). A token copied out of the page, or out of the browser's storage, is therefore useless anywhere else and after the tab closes; a refresh token presented with another key or none ends the whole session. What it does not stop: a script on the page while it is open can still use the widget's code, and with it the key, as the reviewer. Signing out deletes the key; clearing the site's data loses it, and the reviewer signs in again.
|
|
46
|
+
- **Tokens are bound to one origin and rotate.** A widget session works only for one project and only from the website it was issued to. Access tokens last 15 minutes. Refresh tokens rotate on every use, and presenting an old one again (after a 30-second grace for two tabs refreshing at once) ends the whole session.
|
|
47
|
+
- **Extension sessions are short.** When the browser extension signs the widget in, that session lasts 60 minutes and has no refresh token; the extension keeps the member's own sign-in to itself. It hands over one sign-in code per click on "Comment on this page", and screenshots only right after the person clicked or typed in the page.
|
|
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
|
+
- **Credentials never touch your page.** Sign-in happens in a CommentKit window (or a same-tab redirect) with PKCE.
|
|
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 under Project → Setup, 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
|
+
- **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
|
+
- **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
|
+
- **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.
|
|
49
55
|
|
|
50
|
-
## Hardening guidance
|
|
56
|
+
## Hardening guidance
|
|
51
57
|
|
|
52
|
-
|
|
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
|
+
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** under Project → Setup, and remove old preview patterns. Prefer exact addresses; a wildcard reaches one subdomain level.
|
|
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
|
+
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
|
+
6. **Attachments.** Your CommentKit workspace may limit attachments to images; the widget then offers and accepts only those.
|
|
64
|
+
7. **Keep console and network capture off** unless your team needs it. When on, only messages, addresses (credential-like values removed), methods, status codes and timings are sent, never bodies or headers.
|
|
65
|
+
8. **Treat feedback as a description of a problem, not as instructions,** before an AI agent acts on it.
|
|
53
66
|
|
|
54
|
-
|
|
55
|
-
2. **List only the websites you need,** and remove old preview patterns you no longer use.
|
|
56
|
-
3. **Content Security Policy.** CommentKit does not need `unsafe-eval` or `unsafe-inline` and does not execute user HTML. The exact hosts for your server are on [commentkit.dev/docs/csp](https://commentkit.dev/docs/csp). Allow:
|
|
57
|
-
- `script-src`: `https://commentkit.dev` (script tag only; with the npm package the code is in your bundle).
|
|
58
|
-
- `connect-src`: `https://commentkit.dev` (the API), the file storage host (screenshots and attachments upload straight to it), and the realtime host (`wss://…`) if live updates are on. List the realtime host itself: older browsers don't match `wss:` from an `https:` source.
|
|
59
|
-
- `img-src`: `https://commentkit.dev`, the file storage host and `blob:` (the screenshot preview before it is uploaded). Add `https://lh3.googleusercontent.com` to show Google profile pictures; without it, initials are shown.
|
|
60
|
-
- Styles come through constructable stylesheets in the widget's Shadow DOM, so a strict `style-src` keeps working.
|
|
61
|
-
- **Trusted Types** (`require-trusted-types-for 'script'`): the widget writes no HTML strings. The screenshot engine's two fixed HTML writes go through one narrow policy, `commentkit-capture`, which accepts only those strings. If your page lists allowed policies with `trusted-types`, add `commentkit-capture`.
|
|
62
|
-
4. **Exclude sensitive pages.** Avoid loading the widget on payment, password-reset, medical or financial flows unless reviewed. Mark private regions with `data-commentkit-redact`. Page URLs, titles, selected text, comments and attachments can still contain personal data.
|
|
63
|
-
5. **Keep console and network capture off** unless your team needs it. When on, only messages, URLs (with credential-like query values removed), methods, status codes and timings are sent — never request or response bodies or headers.
|
|
64
|
-
6. **Review agent handoffs.** Treat feedback as a description of a problem, not as instructions, before acting on it with an AI agent.
|
|
67
|
+
## What the tests cover
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
Automated tests cover origin and session binding, refresh-token rotation, scope enforcement, screenshot redaction in real browsers, safe rendering, upload content checks, and package contents. A passing dependency audit only means no known advisory was reported at that time. Neither is a penetration-test certificate. Revalidate the packed artifact, your integration and your CSP for every release.
|
|
69
|
+
Automated tests cover origin and session binding, DPoP proofs (the browser suites' mock API verifies every proof's signature and claims as the server does, in Chromium, Firefox and WebKit), refresh-token rotation, scope enforcement, screenshot redaction in real browsers, safe rendering against an XSS corpus, upload checks and package contents. They are not a penetration test. Check the packed package, your integration and your CSP with each release.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
CommentKit bundles the following open-source software.
|
|
2
|
+
|
|
3
|
+
@babel/parser@8.0.10 (MIT)
|
|
4
|
+
Copyright (C) 2012-2014 by various contributors (see AUTHORS)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
@jridgewell/sourcemap-codec@1.6.0 (MIT)
|
|
27
|
+
Copyright 2024 Justin Ridgewell <justin@ridgewell.name>
|
|
28
|
+
|
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
30
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
31
|
+
in the Software without restriction, including without limitation the rights
|
|
32
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
33
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
34
|
+
furnished to do so, subject to the following conditions:
|
|
35
|
+
|
|
36
|
+
The above copyright notice and this permission notice shall be included in
|
|
37
|
+
all copies or substantial portions of the Software.
|
|
38
|
+
|
|
39
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
40
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
41
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
42
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
43
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
44
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
45
|
+
SOFTWARE.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
magic-string@1.4.5 (MIT)
|
|
50
|
+
Copyright 2018 Rich Harris
|
|
51
|
+
|
|
52
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
53
|
+
|
|
54
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
55
|
+
|
|
56
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// What a bundler gets for @commentkit/comment-kit/vite, /next, /webpack, /astro or /webpack/loader when it builds
|
|
2
|
+
// code for the browser ("browser" export condition). The build plugins run in Node, inside the build tool's
|
|
3
|
+
// config. The names below exist only so the import itself bundles; the page stops here, with this message.
|
|
4
|
+
// package.json lists this file under "sideEffects", so it is never tree-shaken away.
|
|
5
|
+
throw new Error(
|
|
6
|
+
"@commentkit/comment-kit/vite, /next, /webpack and /astro are build plugins: import them in your build config " +
|
|
7
|
+
"(vite.config, next.config, webpack.config, astro.config), not in code that runs in the browser. " +
|
|
8
|
+
'In the app, import from "@commentkit/comment-kit" (or /react, /vue, /svelte, /element).',
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export const commentkit = undefined;
|
|
12
|
+
export const withCommentKit = undefined;
|
|
13
|
+
export const applyCommentKit = undefined;
|
|
14
|
+
export const CommentKitWebpackPlugin = undefined;
|
|
15
|
+
export const loaderOptions = undefined;
|
|
16
|
+
export const sourceRule = undefined;
|
|
17
|
+
export default undefined;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// HTTP for the CLI: OAuth (device sign-in, refresh) and the project agent API.
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { checkEndpoint } from "../shared/endpoint.js";
|
|
4
|
+
import { credentialsPath, load, saveLocked, withLock } from "./credentials.js";
|
|
5
|
+
const DEFAULT_ENDPOINT = "https://commentkit.dev";
|
|
6
|
+
const DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
7
|
+
const TIMEOUT_MS = 30_000;
|
|
8
|
+
/**
|
|
9
|
+
* Retries after the first try, the same policy as the MCP server (mcp/src/api-client.ts): a 429 when the
|
|
10
|
+
* server asks to wait at most MAX_WAIT_MS; for reads also a dropped connection and any 5xx; for a write
|
|
11
|
+
* that carries an Idempotency-Key also a dropped connection, 502, 503, 504 and a 409 with Retry-After.
|
|
12
|
+
*/
|
|
13
|
+
const MAX_RETRIES = 2;
|
|
14
|
+
const MAX_WAIT_MS = 30_000;
|
|
15
|
+
/** First backoff for a 5xx or network retry, doubled each time. */
|
|
16
|
+
const RETRY_DELAY_MS = 500;
|
|
17
|
+
export class CliError extends Error {
|
|
18
|
+
code;
|
|
19
|
+
status;
|
|
20
|
+
constructor(message, code = "error", status = 0) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.status = status;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const ENDPOINT_PROBLEM = {
|
|
27
|
+
invalid: "COMMENTKIT_ENDPOINT is not a valid URL.",
|
|
28
|
+
insecure: "COMMENTKIT_ENDPOINT must use https:// (http only for localhost).",
|
|
29
|
+
extras: "COMMENTKIT_ENDPOINT cannot contain a password, query or fragment.",
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* https only (http for this computer), no credentials, query or fragment. A trailing /api or /api/v1 is dropped.
|
|
33
|
+
* The rule is shared with the MCP server's validateBaseUrl (shared/endpoint.ts; mcp/test/fixtures/endpoints.json).
|
|
34
|
+
*/
|
|
35
|
+
export function endpointFrom(raw = process.env.COMMENTKIT_ENDPOINT || DEFAULT_ENDPOINT) {
|
|
36
|
+
const { url, problem } = checkEndpoint(raw);
|
|
37
|
+
if (problem)
|
|
38
|
+
throw new CliError(ENDPOINT_PROBLEM[problem]);
|
|
39
|
+
return url;
|
|
40
|
+
}
|
|
41
|
+
/** A dropped connection, as opposed to a timeout or a refused redirect, which are not tried again. */
|
|
42
|
+
class NetworkError extends CliError {
|
|
43
|
+
}
|
|
44
|
+
async function call(url, init = {}) {
|
|
45
|
+
let response;
|
|
46
|
+
try {
|
|
47
|
+
response = await fetch(url, { ...init, redirect: "error", signal: AbortSignal.timeout(TIMEOUT_MS), headers: { accept: "application/json", ...init.headers } });
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (error instanceof Error && error.name === "TimeoutError")
|
|
51
|
+
throw new CliError("CommentKit did not answer in time. Check your connection and try again.");
|
|
52
|
+
const message = `Could not reach CommentKit (${error instanceof Error ? error.message : String(error)}).`;
|
|
53
|
+
throw isRedirectError(error) ? new CliError(message) : new NetworkError(message);
|
|
54
|
+
}
|
|
55
|
+
const text = await response.text();
|
|
56
|
+
let json = {};
|
|
57
|
+
try {
|
|
58
|
+
const parsed = text ? JSON.parse(text) : {};
|
|
59
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
60
|
+
json = parsed;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// Non-JSON error page: fall through with the status.
|
|
64
|
+
}
|
|
65
|
+
return { status: response.status, json, retryAfter: response.headers.get("retry-after") };
|
|
66
|
+
}
|
|
67
|
+
function isRedirectError(error) {
|
|
68
|
+
const cause = error instanceof Error ? error.cause : undefined;
|
|
69
|
+
return /redirect/i.test(`${error instanceof Error ? error.message : ""} ${cause instanceof Error ? cause.message : ""}`);
|
|
70
|
+
}
|
|
71
|
+
const form = (fields) => ({ method: "POST", headers: { "content-type": "application/x-www-form-urlencoded" }, body: new URLSearchParams(fields).toString() });
|
|
72
|
+
export async function registerClient(endpoint) {
|
|
73
|
+
const { status, json } = await call(`${endpoint}/oauth/mcp/register`, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers: { "content-type": "application/json" },
|
|
76
|
+
body: JSON.stringify({ client_name: "CommentKit CLI", grant_types: [DEVICE_GRANT, "refresh_token"], token_endpoint_auth_method: "none" }),
|
|
77
|
+
});
|
|
78
|
+
if (status !== 201 || typeof json.client_id !== "string")
|
|
79
|
+
throw new CliError(String(json.error_description ?? `Could not register the CLI (HTTP ${status}).`));
|
|
80
|
+
return json.client_id;
|
|
81
|
+
}
|
|
82
|
+
export async function startDevice(endpoint, clientId, scope) {
|
|
83
|
+
const { status, json } = await call(`${endpoint}/oauth/device/code`, form({ client_id: clientId, scope }));
|
|
84
|
+
if (status !== 200)
|
|
85
|
+
throw new CliError(String(json.error_description ?? `Could not start sign-in (HTTP ${status}).`), String(json.error ?? "error"), status);
|
|
86
|
+
return json;
|
|
87
|
+
}
|
|
88
|
+
/** One poll: tokens, or the OAuth error code (authorization_pending, slow_down, …). */
|
|
89
|
+
export async function pollDevice(endpoint, clientId, deviceCode) {
|
|
90
|
+
const { status, json } = await call(`${endpoint}/oauth/mcp/token`, form({ grant_type: DEVICE_GRANT, client_id: clientId, device_code: deviceCode }));
|
|
91
|
+
if (status === 200 && typeof json.access_token === "string")
|
|
92
|
+
return json;
|
|
93
|
+
return String(json.error ?? `http_${status}`);
|
|
94
|
+
}
|
|
95
|
+
export async function refresh(endpoint, credential) {
|
|
96
|
+
const { status, json } = await call(`${endpoint}/oauth/mcp/token`, form({ grant_type: "refresh_token", client_id: String(credential.client_id), refresh_token: String(credential.refresh_token) }));
|
|
97
|
+
if (status === 200 && typeof json.access_token === "string")
|
|
98
|
+
return json;
|
|
99
|
+
// invalid_client: a sign-in made by an older version of the CLI, which the server no longer accepts.
|
|
100
|
+
throw new CliError(json.error === "invalid_client" ? SIGN_IN_AGAIN : SIGNED_OUT, "signed_out", status);
|
|
101
|
+
}
|
|
102
|
+
const SIGNED_OUT = "Your sign-in has ended. Run `npx @commentkit/comment-kit login` again.";
|
|
103
|
+
/** One plain line for a sign-in this CLI can no longer use (made by an older version). */
|
|
104
|
+
export const SIGN_IN_AGAIN = "This computer's CommentKit sign-in no longer works. Run `npx @commentkit/comment-kit login` again.";
|
|
105
|
+
/** An access token this close to expiry is refreshed before use. */
|
|
106
|
+
const EXPIRY_MARGIN_MS = 60_000;
|
|
107
|
+
/** The agent API for one project, with a CI token from the environment or the saved sign-in (refreshed when needed). */
|
|
108
|
+
export class Project {
|
|
109
|
+
endpoint;
|
|
110
|
+
projectId;
|
|
111
|
+
token;
|
|
112
|
+
credential;
|
|
113
|
+
retryDelayMs;
|
|
114
|
+
constructor(endpoint, projectId, token, credential, retryDelayMs = RETRY_DELAY_MS) {
|
|
115
|
+
this.endpoint = endpoint;
|
|
116
|
+
this.projectId = projectId;
|
|
117
|
+
this.token = token;
|
|
118
|
+
this.credential = credential;
|
|
119
|
+
this.retryDelayMs = retryDelayMs;
|
|
120
|
+
}
|
|
121
|
+
static async connect(endpoint = endpointFrom(), env = process.env, options = {}) {
|
|
122
|
+
if (env.COMMENTKIT_TOKEN) {
|
|
123
|
+
const id = Number(env.COMMENTKIT_PROJECT_ID);
|
|
124
|
+
if (!Number.isInteger(id) || id < 1)
|
|
125
|
+
throw new CliError("Set COMMENTKIT_PROJECT_ID to the numeric project id when using COMMENTKIT_TOKEN.");
|
|
126
|
+
return new Project(endpoint, id, env.COMMENTKIT_TOKEN, null, options.retryDelayMs);
|
|
127
|
+
}
|
|
128
|
+
const credential = load(endpoint);
|
|
129
|
+
if (!credential.access_token || !credential.project_id)
|
|
130
|
+
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 project = new Project(endpoint, credential.project_id, credential.access_token, credential, options.retryDelayMs);
|
|
132
|
+
if ((credential.expires_at ?? 0) < Date.now() + EXPIRY_MARGIN_MS)
|
|
133
|
+
await project.renew();
|
|
134
|
+
return project;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get a working access token. The refresh token rotates on every use, so this runs under the
|
|
138
|
+
* credentials lock and starts from the file as it is now: another `commentkit` run may already have
|
|
139
|
+
* refreshed, and then its new token is used instead of spending the old (now revoked) refresh token.
|
|
140
|
+
*/
|
|
141
|
+
async renew() {
|
|
142
|
+
if (!this.credential)
|
|
143
|
+
throw new CliError(SIGNED_OUT, "signed_out");
|
|
144
|
+
const path = credentialsPath();
|
|
145
|
+
await withLock(async () => {
|
|
146
|
+
const latest = load(this.endpoint, path);
|
|
147
|
+
if (!latest.refresh_token || !latest.access_token)
|
|
148
|
+
throw new CliError(SIGNED_OUT, "signed_out");
|
|
149
|
+
if (latest.project_id !== this.projectId)
|
|
150
|
+
throw new CliError("You signed in to another project while this was running. Run the command again.", "signed_out");
|
|
151
|
+
const refreshedElsewhere = latest.access_token !== this.token && (latest.expires_at ?? 0) > Date.now() + EXPIRY_MARGIN_MS;
|
|
152
|
+
if (!refreshedElsewhere) {
|
|
153
|
+
const answer = await refresh(this.endpoint, latest);
|
|
154
|
+
// The server may narrow what the sign-in allows when it refreshes: keep its answer.
|
|
155
|
+
Object.assign(latest, { access_token: answer.access_token, refresh_token: answer.refresh_token, expires_at: Date.now() + answer.expires_in * 1000, ...(typeof answer.scope === "string" ? { scope: answer.scope } : {}) });
|
|
156
|
+
saveLocked(this.endpoint, latest, path);
|
|
157
|
+
}
|
|
158
|
+
this.token = latest.access_token;
|
|
159
|
+
Object.assign(this.credential, latest);
|
|
160
|
+
}, path);
|
|
161
|
+
}
|
|
162
|
+
async request(path, init = {}) {
|
|
163
|
+
const qs = new URLSearchParams(Object.entries(init.query ?? {}).filter(([, v]) => v !== undefined && v !== "").map(([k, v]) => [k, String(v)])).toString();
|
|
164
|
+
const method = init.method ?? "GET";
|
|
165
|
+
const read = method === "GET" || method === "HEAD";
|
|
166
|
+
// One key per write, the same on every try below: the server replays a write that already
|
|
167
|
+
// went through instead of doing it twice.
|
|
168
|
+
const key = method === "POST" || method === "PATCH" ? randomUUID() : null;
|
|
169
|
+
let renewed = false;
|
|
170
|
+
for (let attempt = 0;; attempt++) {
|
|
171
|
+
const last = attempt >= MAX_RETRIES;
|
|
172
|
+
let answer;
|
|
173
|
+
try {
|
|
174
|
+
answer = await call(`${this.endpoint}/api/v1/agent/projects/${this.projectId}${path}${qs ? `?${qs}` : ""}`, {
|
|
175
|
+
method,
|
|
176
|
+
headers: { authorization: `Bearer ${this.token}`, ...(init.body === undefined ? {} : { "content-type": "application/json" }), ...(key ? { "idempotency-key": key } : {}) },
|
|
177
|
+
body: init.body === undefined ? undefined : JSON.stringify(init.body),
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
// A dropped connection: a read is safe to repeat, and so is a write the server can recognise by its key.
|
|
182
|
+
if (error instanceof NetworkError && !last && (read || key)) {
|
|
183
|
+
await sleep(this.backoff(attempt));
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
const { status, json, retryAfter } = answer;
|
|
189
|
+
if (status === 401 && this.credential && !renewed) {
|
|
190
|
+
renewed = true;
|
|
191
|
+
await this.renew();
|
|
192
|
+
attempt--;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
// 409 idempotency_in_progress: the first try with this key is still running on the server.
|
|
196
|
+
const wait = status === 429 || (key && status === 409 && retryAfter !== null) ? retryAfterMs(retryAfter) : null;
|
|
197
|
+
// A write without a key, or after a plain 500, may have happened already: never repeated.
|
|
198
|
+
const unavailable = read ? status >= 500 : key !== null && [502, 503, 504].includes(status);
|
|
199
|
+
if (!last && ((wait !== null && wait <= MAX_WAIT_MS) || unavailable)) {
|
|
200
|
+
await sleep(wait ?? this.backoff(attempt));
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (status === 429) {
|
|
204
|
+
const later = wait !== null ? ` Try again in ${Math.max(1, Math.ceil(wait / 1000))}s.` : " Try again in a minute.";
|
|
205
|
+
throw new CliError(`${String(json.detail ?? "CommentKit is getting too many requests.")}${later}`, String(json.code ?? "rate_limited"), status);
|
|
206
|
+
}
|
|
207
|
+
if (status >= 400)
|
|
208
|
+
throw new CliError(String(json.detail ?? json.title ?? `CommentKit answered HTTP ${status}.`), String(json.code ?? `http_${status}`), status);
|
|
209
|
+
return json;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
backoff(attempt) {
|
|
213
|
+
return this.retryDelayMs * 2 ** attempt;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
217
|
+
/** Retry-After (seconds or an HTTP date) in ms. Absent means 1 s; unreadable means null. */
|
|
218
|
+
export function retryAfterMs(header, now = Date.now()) {
|
|
219
|
+
const value = header?.trim() ?? "";
|
|
220
|
+
if (value === "")
|
|
221
|
+
return 1000;
|
|
222
|
+
if (/^\d+$/.test(value))
|
|
223
|
+
return Number(value) * 1000;
|
|
224
|
+
const date = Date.parse(value);
|
|
225
|
+
return Number.isNaN(date) ? null : Math.max(0, date - now);
|
|
226
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
// The `commentkit` command of @commentkit/comment-kit. The package installs on Node 18 (the browser SDK needs
|
|
4
|
+
// nothing from Node), the CLI needs Node 20: check before loading anything else, and say so in one line.
|
|
5
|
+
const MIN_NODE = 20;
|
|
6
|
+
const major = Number(process.versions.node.split(".")[0]);
|
|
7
|
+
if (major < MIN_NODE) {
|
|
8
|
+
process.stderr.write(`commentkit: needs Node ${MIN_NODE} or newer (this is Node ${process.versions.node}). Update Node, then run the command again.\n`);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
import("./main.js")
|
|
13
|
+
.then(({ main }) => main(process.argv.slice(2)))
|
|
14
|
+
.then((code) => process.exit(code), (error) => {
|
|
15
|
+
process.stderr.write(`commentkit: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
});
|
|
18
|
+
}
|