@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.
Files changed (92) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +123 -19
  3. package/SECURITY.md +2 -2
  4. package/dist/node/cli/api.js +61 -15
  5. package/dist/node/cli/credentials.js +8 -0
  6. package/dist/node/cli/doctor.js +152 -25
  7. package/dist/node/cli/init.js +349 -35
  8. package/dist/node/cli/main.js +310 -69
  9. package/dist/node/cli/mcp.js +187 -6
  10. package/dist/node/cli/website.js +140 -0
  11. package/dist/node/shared/dashboard-places.js +33 -0
  12. package/dist/node/types/next.d.ts +4 -4
  13. package/dist/npm/THIRD_PARTY_NOTICES.txt +47 -0
  14. package/dist/npm/chunks/{AgentSend-DxRJIYiz.js → AgentSend-pA7Ufvye.js} +16 -16
  15. package/dist/npm/chunks/Checklist-Cn9skOYK.js +269 -0
  16. package/dist/npm/chunks/Composer-D7H-pzGa.js +734 -0
  17. package/dist/npm/chunks/DatePicker-Nta5a1xD.js +161 -0
  18. package/dist/npm/chunks/{Guest-vvNPz8h-.js → Guest-Bi7hlzhs.js} +63 -59
  19. package/dist/npm/chunks/{MarkupEditor-VCOXh9d2.js → MarkupEditor-WU3USeTk.js} +46 -39
  20. package/dist/npm/chunks/Panel-DhAzbUbC.js +1210 -0
  21. package/dist/npm/chunks/{Settings-BGoZS2iV.js → Settings-BmKqPX40.js} +91 -90
  22. package/dist/npm/chunks/{Shortcuts-B2OMvczr.js → Shortcuts-Bl-c0Sez.js} +25 -23
  23. package/dist/npm/chunks/SignInFirst-CmGvSYkQ.js +35 -0
  24. package/dist/npm/chunks/{StyleEditor-CJ_d8Huf.js → StyleEditor-D6fUnlwq.js} +10 -10
  25. package/dist/npm/chunks/{StylePanel-yQzHHlY7.js → StylePanel-C-Gikxt1.js} +61 -61
  26. package/dist/npm/chunks/TaskFields-CaKi523b.js +617 -0
  27. package/dist/npm/chunks/ThreadCard-d_3pUB5V.js +1142 -0
  28. package/dist/npm/chunks/Viewer-BULQsi9-.js +115 -0
  29. package/dist/npm/chunks/{agent-C1OQzBAm.js → agent-DHdhIJ3s.js} +1 -1
  30. package/dist/npm/chunks/{ar-CAJ3XT8e.js → ar-B5UszrQp.js} +53 -12
  31. package/dist/npm/chunks/card-bits-cV8GdFWX.js +55 -0
  32. package/dist/npm/chunks/{client-kNAo2TTG.js → client-Cv8ddtuM.js} +13 -11
  33. package/dist/npm/chunks/{confetti-CkBdSu19.js → confetti-B9zlyILU.js} +1 -1
  34. package/dist/npm/chunks/{context-B8UAzve0.js → context-CsHnabaA.js} +1 -1
  35. package/dist/npm/chunks/{de-Dl18G48t.js → de-BE0Aaq8u.js} +53 -12
  36. package/dist/npm/chunks/{dialog-GO04oC3D.js → dialog-DvdIkCW0.js} +1 -1
  37. package/dist/npm/chunks/{dpop-U48QIQd7.js → dpop-CwW9ifkq.js} +1 -1
  38. package/dist/npm/chunks/entrance-Bn_5M9uO.js +90 -0
  39. package/dist/npm/chunks/{es-Dxk79lS9.js → es-BQviao4d.js} +53 -12
  40. package/dist/npm/chunks/{extension-E81hWyiT.js → extension-CnQTDC1j.js} +2 -2
  41. package/dist/npm/chunks/{extension-CKFpPWmi.js → extension-DXhz81XD.js} +1 -1
  42. package/dist/npm/chunks/{files-DyD5BZgp.js → files-DLEr_wmh.js} +2 -2
  43. package/dist/npm/chunks/{fr-8BebGKYD.js → fr-C5gu6A06.js} +53 -12
  44. package/dist/npm/chunks/{hi-BIN6Yy_p.js → hi-DXfQ5EvY.js} +53 -12
  45. package/dist/npm/chunks/{i18n-DOBt8e9U.js → i18n-Mgs9VOuk.js} +63 -58
  46. package/dist/npm/chunks/icons-_C6ZWmBY.js +141 -0
  47. package/dist/npm/chunks/{identify-CN-3xzqL.js → identify-BnQGJOa0.js} +4 -4
  48. package/dist/npm/chunks/{it-Cr6EwpPQ.js → it-BPHt13FV.js} +53 -12
  49. package/dist/npm/chunks/{ja-Iy3s5aur.js → ja-BkCqyKR0.js} +52 -11
  50. package/dist/npm/chunks/late-words-D4Oo_yhJ.js +57 -0
  51. package/dist/npm/chunks/{live-CelVeZfP.js → live-DXcxj_Af.js} +28 -22
  52. package/dist/npm/chunks/{nl-B84WHqqe.js → nl-DZxdLLMU.js} +53 -12
  53. package/dist/npm/chunks/{page-key-DepmJzC1.js → page-key-UqAozdZi.js} +1 -1
  54. package/dist/npm/chunks/{pick-yTyqtxN0.js → pick-C20RVUas.js} +1 -1
  55. package/dist/npm/chunks/{pkce-ChKGSW_4.js → pkce-BPvWoBrr.js} +1 -1
  56. package/dist/npm/chunks/{pt-BR-DOkdlfoe.js → pt-BR-lA9mJ05F.js} +53 -12
  57. package/dist/npm/chunks/{report-CrIqQZDI.js → report-BjUgUNnT.js} +1 -1
  58. package/dist/npm/chunks/show-BinoJyED.js +97 -0
  59. package/dist/npm/chunks/signin-C2jjsxz9.js +101 -0
  60. package/dist/npm/chunks/{source-pXVve2Cx.js → source-NuflODx3.js} +1 -1
  61. package/dist/npm/chunks/src-9o2Ocq8d.js +221 -0
  62. package/dist/npm/chunks/start-Cbx6rMrr.js +1904 -0
  63. package/dist/npm/chunks/states-DLMCvwes.js +3 -0
  64. package/dist/npm/chunks/{upload-MgPYqPyE.js → upload-C4NpM-jE.js} +1 -1
  65. package/dist/npm/chunks/uploads-CY4bDbaI.js +1236 -0
  66. package/dist/npm/chunks/{wrap-Bl0gbnFa.js → wrap-D-xTKIzj.js} +20 -20
  67. package/dist/npm/chunks/{zh-CN-Z5fQCb7G.js → zh-CN-yqaDHwBx.js} +53 -12
  68. package/dist/npm/element.js +7 -1
  69. package/dist/npm/headless.js +2 -2
  70. package/dist/npm/index.js +2 -2
  71. package/dist/npm/react.js +1 -1
  72. package/dist/npm/svelte.js +1 -1
  73. package/dist/npm/types/adapters/vue.d.ts +12 -0
  74. package/dist/npm/types/core/auth.d.ts +1 -0
  75. package/dist/npm/types/core/client.d.ts +5 -1
  76. package/dist/npm/types/core/types.d.ts +19 -4
  77. package/dist/npm/vue.js +5 -1
  78. package/package.json +4 -1
  79. package/dist/npm/chunks/Checklist-CnlfeSbc.js +0 -282
  80. package/dist/npm/chunks/Composer-B1bBVszY.js +0 -725
  81. package/dist/npm/chunks/Panel-F37vIL1K.js +0 -1206
  82. package/dist/npm/chunks/TaskFields-fmy6_HtK.js +0 -289
  83. package/dist/npm/chunks/ThreadCard-D51slKST.js +0 -1113
  84. package/dist/npm/chunks/Viewer-BOBadqmC.js +0 -111
  85. package/dist/npm/chunks/card-bits-CAnzrqx3.js +0 -53
  86. package/dist/npm/chunks/late-words-B2bmZceJ.js +0 -12
  87. package/dist/npm/chunks/show-BgVC8gWY.js +0 -97
  88. package/dist/npm/chunks/signin-Dd1rb2BP.js +0 -75
  89. package/dist/npm/chunks/src-BTMy4Gyc.js +0 -208
  90. package/dist/npm/chunks/start-DtVlpt7p.js +0 -1878
  91. package/dist/npm/chunks/states-sfTbjZz8.js +0 -3
  92. package/dist/npm/chunks/uploads-D49mywwz.js +0 -1146
@@ -2,9 +2,10 @@
2
2
  // Node built-ins only. Every network call goes through an injectable fetch, so the tests run offline.
3
3
  import { existsSync, readFileSync } from "node:fs";
4
4
  import { join } from "node:path";
5
- import { CliError, endpointFrom, Project } from "./api.js";
5
+ import { DASHBOARD } from "../shared/dashboard-places.js";
6
+ import { CliError, Connection, endpointFrom } from "./api.js";
6
7
  import { safeUrl } from "./format.js";
7
- import { PLUGIN_IMPORT, plan } from "./init.js";
8
+ import { describePlace, PLUGIN_IMPORT, plan, templatesWithTag } from "./init.js";
8
9
  import { PUBLISHABLE_KEY } from "./main.js";
9
10
  const TIMEOUT_MS = 10_000;
10
11
  const MAX_PAGE_BYTES = 2 * 1024 * 1024;
@@ -339,15 +340,20 @@ function projectSetup(cwd, flagKey, env) {
339
340
  const checks = [];
340
341
  const pkg = readJson(join(cwd, "package.json"));
341
342
  const htmlFiles = ["index.html", "public/index.html"].filter((f) => existsSync(join(cwd, f)));
342
- const appFound = Boolean(pkg) || htmlFiles.length > 0;
343
343
  // The same framework and entry-file detection init uses; plan() only reads files.
344
344
  const p = plan(cwd, PLAN_KEY);
345
+ // A Laravel app with plain Blade pages may have no package.json.
346
+ const appFound = Boolean(pkg) || htmlFiles.length > 0 || p.framework === "laravel";
345
347
  const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
346
348
  const installed = readJson(join(cwd, "node_modules", SDK, "package.json"));
347
349
  const installedVersion = typeof installed?.version === "string" ? clean(installed.version, 40) : null;
348
350
  const html = htmlFiles.map((f) => ({ file: f, text: readFileSync(join(cwd, f), "utf8") }));
349
351
  const htmlLoader = html.map((h) => ({ file: h.file, sdk: findSdk(h.text, "http://localhost/") })).find((h) => h.sdk.loader);
352
+ // Laravel: the script tag can be in a Blade layout or a public/*.html page.
353
+ const templateTags = p.framework === "laravel" ? templatesWithTag(cwd) : [];
350
354
  const bundled = Boolean(deps[SDK]);
355
+ // Where the widget is: the entry or a file it imports (Vite, Laravel), else what init's plan found.
356
+ const widget = p.widget;
351
357
  const add = p.install[0]?.join(" ") ?? `npm install ${SDK}`;
352
358
  if (!appFound) {
353
359
  checks.push({ id: "setup.app", status: "info", message: "No package.json or index.html in this folder, so the project checks were skipped.", fix: `Run ${CLI} doctor in your app's folder to include them.` });
@@ -360,18 +366,23 @@ function projectSetup(cwd, flagKey, env) {
360
366
  else if (htmlLoader) {
361
367
  checks.push({ id: "setup.package", status: "pass", message: `The CommentKit script tag is in ${htmlLoader.file}.` });
362
368
  }
369
+ else if (templateTags.length) {
370
+ checks.push({ id: "setup.package", status: "pass", message: `The CommentKit script tag is in ${templateTags.map((t) => t.file).slice(0, 3).join(", ")}${templateTags.length > 3 ? ` and ${templateTags.length - 3} more` : ""}.` });
371
+ }
363
372
  else if (p.entry === "done") {
364
373
  checks.push({ id: "setup.package", status: "pass", message: `The CommentKit script tag is in your ${p.label} app.` });
365
374
  }
366
375
  else {
367
- checks.push({ id: "setup.package", status: "fail", message: `CommentKit is not installed in this ${p.label} app: no ${SDK} in package.json and no script tag.`, fix: p.framework === "html" ? `Run ${CLI} init, or add the script tag before </body> (https://commentkit.dev/docs).` : `Run ${CLI} init (or ${add}).` });
376
+ checks.push({ id: "setup.package", status: "fail", message: `CommentKit is not installed in this ${p.label} app: no ${SDK} in package.json and no script tag.`, fix: p.framework === "html" || !p.install.length ? `Run ${CLI} init, or add the script tag before </body> (https://commentkit.dev/docs).` : `Run ${CLI} init (or ${add}).` });
368
377
  }
369
378
  if (appFound && bundled) {
370
- if (p.entry === "done")
379
+ if (widget)
380
+ checks.push({ id: "setup.widget", status: "pass", message: `The widget is added in ${describePlace(widget)}.` });
381
+ else if (p.entry === "done")
371
382
  checks.push({ id: "setup.widget", status: "pass", message: "The widget is added in your layout or entry file." });
372
383
  else {
373
384
  const where = p.entry ? p.entry.file : "your layout or entry file";
374
- checks.push({ id: "setup.widget", status: "warn", message: `Could not find the widget in ${where}.`, fix: `If you call init() or render <CommentKit> somewhere else, ignore this; otherwise run ${CLI} init.` });
385
+ checks.push({ id: "setup.widget", status: "warn", message: `Could not find the widget in ${where}${p.entry && p.framework === "laravel" ? " or a file it imports" : ""}.`, fix: `If you call init() or render <CommentKit> somewhere else, ignore this; otherwise run ${CLI} init.` });
375
386
  }
376
387
  }
377
388
  // The key: --key, then the env files init writes, then the environment, then the script tag.
@@ -411,9 +422,15 @@ function projectSetup(cwd, flagKey, env) {
411
422
  key = htmlLoader.sdk.loader.key;
412
423
  keySource = htmlLoader.file;
413
424
  }
425
+ // Written into the code as the default (init({ project: import.meta.env.VITE_COMMENTKIT_KEY || "pk_…" })), or on a template's tag.
426
+ const written = [widget, ...templateTags].find((place) => place?.key);
427
+ if (!key && written) {
428
+ key = written.key;
429
+ keySource = written.file;
430
+ }
414
431
  }
415
432
  if (key && !PUBLISHABLE_KEY.test(key)) {
416
- checks.push({ id: "setup.key", status: "fail", message: `The project key in ${keySource} is not a publishable key (it should look like pk_live_… or pk_test_…).`, fix: "Copy the key again from Setup in CommentKit." });
433
+ checks.push({ id: "setup.key", status: "fail", message: `The project key in ${keySource} is not a publishable key (it should look like pk_live_… or pk_test_…).`, fix: `Copy the key again from ${DASHBOARD.install} in CommentKit.` });
417
434
  }
418
435
  else if (key) {
419
436
  checks.push({ id: "setup.key", status: "pass", message: `Project key ${maskKey(key)} found in ${keySource}.` });
@@ -421,18 +438,59 @@ function projectSetup(cwd, flagKey, env) {
421
438
  checks.push({ id: "setup.key-name", status: "warn", message: `${p.label} apps do not read ${keyVar}, so the widget gets no key.`, fix: `Rename it to ${p.envVar} in ${keySource.split(" ")[0]}.` });
422
439
  }
423
440
  }
441
+ else if (appFound && p.framework === "laravel") {
442
+ checks.push({ id: "setup.key", status: "fail", message: "No project key found in .env, your JavaScript entry or a Blade script tag.", fix: `Run ${CLI} init, or write the key into your entry: init({ project: import.meta.env.VITE_COMMENTKIT_KEY || "pk_…" }) (the key is in ${DASHBOARD.install} in CommentKit). If the key comes from somewhere else, run ${CLI} doctor --key pk_… instead.` });
443
+ }
424
444
  else if (appFound) {
425
- checks.push({ id: "setup.key", status: "fail", message: `No project key found${p.envFile ? ` in ${p.envFile}` : ""}${htmlFiles.length ? ` or ${htmlFiles[0]}` : ""}.`, fix: p.envVar ? `Run ${CLI} init, or add ${p.envVar}=pk_… to ${p.envFile} (the key is under Setup in CommentKit). If the key is written straight into your code, run ${CLI} doctor --key pk_… instead.` : `Run ${CLI} init, or put data-project="pk_…" on the script tag (the key is under Setup in CommentKit).` });
445
+ checks.push({ id: "setup.key", status: "fail", message: `No project key found${p.envFile ? ` in ${p.envFile}` : ""}${htmlFiles.length ? ` or ${htmlFiles[0]}` : ""}.`, fix: p.envVar ? `Run ${CLI} init, or add ${p.envVar}=pk_… to ${p.envFile} (the key is in ${DASHBOARD.install} in CommentKit). If the key is written straight into your code, run ${CLI} doctor --key pk_… instead.` : `Run ${CLI} init, or put data-project="pk_…" on the script tag (the key is in ${DASHBOARD.install} in CommentKit).` });
426
446
  }
427
- if (appFound && p.framework !== "html") {
447
+ // A Laravel app without a JavaScript entry uses the script tag: there is no build to add the plugin to.
448
+ if (appFound && p.framework !== "html" && !(p.framework === "laravel" && !p.configFile)) {
428
449
  const config = p.configFile ? readFileSync(join(cwd, p.configFile), "utf8") : "";
429
450
  if (PLUGIN_IMPORT.test(config))
430
451
  checks.push({ id: "setup.plugin", status: "pass", message: `The build plugin is set up in ${p.configFile}.` });
431
452
  else
432
- checks.push({ id: "setup.plugin", status: "info", message: "The build plugin is not set up. It is optional: it adds source file and line to feedback, so you and your coding agent land on the right code.", fix: `Run ${CLI} init to add it.` });
453
+ checks.push({ id: "setup.plugin", status: "info", message: "The build plugin is not set up. It is optional: it adds source file and line to feedback, so you and your coding agent land on the right code.", fix: p.configFile && !p.configEdit ? `Run ${CLI} init: it prints the lines to add to ${p.configFile}, which it cannot edit safely.` : `Run ${CLI} init to add it.` });
433
454
  }
434
455
  return { checks, key, keySource, installedVersion, bundled, appFound };
435
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
+ }
466
+ /** Code hosts and registries: a package.json homepage there is not the website. */
467
+ const NOT_A_SITE = /(^|\.)(github\.com|gitlab\.com|bitbucket\.org|npmjs\.com|npmjs\.org)$/i;
468
+ /**
469
+ * The website's address as the project records it: APP_URL in .env.example (Laravel), then "homepage" in
470
+ * package.json. Only a real http(s) address counts: localhost, *.test and code-host links are left out.
471
+ */
472
+ export function siteAddress(cwd) {
473
+ const candidates = [];
474
+ if (existsSync(join(cwd, ".env.example")))
475
+ candidates.push({ raw: envValue(readFileSync(join(cwd, ".env.example"), "utf8"), "APP_URL"), source: ".env.example (APP_URL)" });
476
+ const homepage = readJson(join(cwd, "package.json"))?.homepage;
477
+ candidates.push({ raw: typeof homepage === "string" ? homepage : null, source: "package.json (homepage)" });
478
+ for (const { raw, source } of candidates) {
479
+ if (!raw || /[\s"'`$<>]/.test(raw))
480
+ continue;
481
+ let url;
482
+ try {
483
+ url = new URL(raw);
484
+ }
485
+ catch {
486
+ continue;
487
+ }
488
+ if ((url.protocol !== "http:" && url.protocol !== "https:") || url.username || url.password || isDevHost(url.hostname) || NOT_A_SITE.test(url.hostname))
489
+ continue;
490
+ return { url: url.origin, source };
491
+ }
492
+ return null;
493
+ }
436
494
  async function getJson(fetchFn, url, headers, timeoutMs) {
437
495
  try {
438
496
  const response = await fetchFn(url, { redirect: "error", credentials: "omit", signal: AbortSignal.timeout(timeoutMs), headers: { accept: "application/json", ...headers } });
@@ -475,22 +533,43 @@ function keyCheck(answer, key, host, sdk) {
475
533
  if (config.enabled === false && config.disabled_reason === "version_blocked")
476
534
  return { config, check: { id: "api.key", status: "fail", message: `This SDK version${sdk ? ` (${clean(sdk, 40)})` : ""} has been switched off by CommentKit; update the package. Until then the widget stays hidden everywhere.`, fix: `npm install ${SDK}@latest, then deploy (sites with the /cdn/v1/ script tag get the fix by themselves).` } };
477
535
  if (config.enabled === false)
478
- return { config, check: { id: "api.key", status: "fail", message: `Feedback is paused for “${name}” (the kill switch is on), so the widget stays hidden everywhere.`, fix: "Turn feedback back on in the project's settings in CommentKit; it applies within a minute." } };
536
+ return { config, check: { id: "api.key", status: "fail", message: `Feedback is paused for “${name}” (the kill switch is on), so the widget stays hidden everywhere.`, fix: `Turn feedback back on in CommentKit, in ${DASHBOARD.feedbackState}; it applies within a minute.` } };
479
537
  if (config.read_only === true)
480
- return { config, check: { id: "api.key", status: "warn", message: `“${name}” is read-only: the widget shows existing feedback, but nobody can add new feedback (comments are turned off or the plan ended).`, fix: "Check the project's plan and settings in CommentKit." } };
538
+ return { config, check: { id: "api.key", status: "warn", message: `“${name}” is read-only: the widget shows existing feedback, but nobody can add new feedback (comments are turned off or the plan ended).`, fix: `Check the workspace's plan in CommentKit, and ${DASHBOARD.feedbackState}.` } };
481
539
  return { config, check: { id: "api.key", status: "pass", message: `CommentKit knows the key ${maskKey(key)} (project “${name}”) and feedback is on.` } };
482
540
  }
483
541
  if (status === 404)
484
- return { config: null, check: { id: "api.key", status: "fail", message: `CommentKit does not know the key ${maskKey(key)}.`, fix: "Copy the key again from Setup in CommentKit (pk_live_… for your live site, pk_test_… for staging)." } };
542
+ return { config: null, check: { id: "api.key", status: "fail", message: `CommentKit does not know the key ${maskKey(key)}.`, fix: `Copy the key again from ${DASHBOARD.install} in CommentKit (pk_live_… for your live site, pk_test_… for staging).` } };
485
543
  if (status === 429)
486
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.` } };
487
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.` } };
488
546
  }
489
- async function signedIn() {
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");
490
551
  try {
491
- const project = await Project.connect();
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);
492
571
  const info = await project.request("");
493
- return { name: info.data.name, keys: [info.data.publishable_keys?.live, info.data.publishable_keys?.test].filter((k) => typeof k === "string") };
572
+ return { name: info.data.name, keys: keysOf(info.data) };
494
573
  }
495
574
  catch (error) {
496
575
  if (error instanceof CliError && error.code === "signed_out")
@@ -550,18 +629,44 @@ export async function doctor(options, deps = {}) {
550
629
  const pageKey = sdk?.loader?.key ?? sdk?.key ?? null;
551
630
  const key = setup.key && PUBLISHABLE_KEY.test(setup.key) ? setup.key : pageKey && PUBLISHABLE_KEY.test(pageKey) ? pageKey : null;
552
631
  if (!setup.appFound && !key)
553
- 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 under Setup in CommentKit)." });
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).` });
554
633
  // 2. Sign-in (optional for doctor).
634
+ let otherWebsite = null;
635
+ let otherWorkspace = null;
555
636
  try {
556
- const project = await (deps.project ?? signedIn)();
637
+ const project = await (deps.project ?? (() => signedIn(options.cwd)))();
557
638
  if (!project) {
558
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.` });
559
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
+ }
560
666
  else {
561
667
  checks.push({ id: "signin", status: "pass", message: `The CLI is signed in to “${clean(project.name, 80)}”.` });
562
- if (key && project.keys.length && !project.keys.includes(key)) {
563
- checks.push({ id: "signin.key", status: "warn", message: `The key ${maskKey(key)} is not one of “${clean(project.name, 80)}”'s keys.`, fix: "If this app belongs to another project, ignore this; otherwise copy the key from Setup in CommentKit." });
564
- }
668
+ if (key && project.keys.length && !project.keys.includes(key))
669
+ otherWebsite = clean(project.name, 80);
565
670
  }
566
671
  }
567
672
  catch (error) {
@@ -580,6 +685,21 @@ export async function doctor(options, deps = {}) {
580
685
  else if (setup.appFound) {
581
686
  checks.push({ id: "api.key", status: "info", message: "Skipped the check with CommentKit: there is no valid project key." });
582
687
  }
688
+ // The folder's key belongs to another website than the one the CLI is signed in to. When CommentKit
689
+ // confirmed the key, that is a normal setup (one terminal, several websites): one neutral line.
690
+ if (otherWebsite && key) {
691
+ const known = config ? clean(config.project?.name, 80) : "";
692
+ checks.push(config
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"}.` }
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.` });
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
+ }
583
703
  // 4. The website.
584
704
  if (site) {
585
705
  const shown = clean(safeUrl(site.href), 200);
@@ -595,14 +715,14 @@ export async function doctor(options, deps = {}) {
595
715
  if ("error" in answer)
596
716
  checks.push(unreachable("site.origin", host, answer.error));
597
717
  else if (answer.status === 403 && answer.json.code === "origin_not_allowed")
598
- checks.push({ id: "site.origin", status: "fail", message: `${origin} is not on the project's list of allowed websites, so the widget will not load there.`, fix: "Add it in CommentKit under Project → Setup, step 1 (a project admin can)." });
718
+ checks.push({ id: "site.origin", status: "fail", message: `${origin} is not on the project's list of allowed websites, so the widget will not load there.`, fix: `A workspace owner or admin adds it in CommentKit, in ${DASHBOARD.addresses}.` });
599
719
  else if (answer.status === 200) {
600
720
  const environment = clean(answer.json.environment, 30);
601
721
  checks.push({ id: "site.origin", status: "pass", message: `${origin} is on the project's allowed websites${environment ? ` (${environment})` : ""}.` });
602
722
  config ??= answer.json;
603
723
  }
604
724
  else if (answer.status === 404)
605
- checks.push({ id: "site.origin", status: "fail", message: `CommentKit does not know the key ${maskKey(originKey)} used on the page.`, fix: "Copy the key again from Setup in CommentKit." });
725
+ checks.push({ id: "site.origin", status: "fail", message: `CommentKit does not know the key ${maskKey(originKey)} used on the page.`, fix: `Copy the key again from ${DASHBOARD.install} in CommentKit.` });
606
726
  else
607
727
  checks.push({ id: "site.origin", status: "warn", message: `Could not check whether ${origin} is allowed (HTTP ${answer.status}).`, fix: `Run ${CLI} doctor again in a minute.` });
608
728
  }
@@ -623,9 +743,9 @@ export async function doctor(options, deps = {}) {
623
743
  if (sdk.loader) {
624
744
  const loaderKey = sdk.loader.key;
625
745
  if (!loaderKey)
626
- checks.push({ id: "site.sdk", status: "fail", message: "The page has the CommentKit script tag, but without a project key.", fix: 'Add data-project="pk_…" to the script tag (the key is under Setup in CommentKit).' });
746
+ checks.push({ id: "site.sdk", status: "fail", message: "The page has the CommentKit script tag, but without a project key.", fix: `Add data-project="pk_…" to the script tag (the key is in ${DASHBOARD.install} in CommentKit).` });
627
747
  else if (!PUBLISHABLE_KEY.test(loaderKey))
628
- checks.push({ id: "site.sdk", status: "fail", message: "The CommentKit script tag on the page has a key that is not a publishable key.", fix: "Copy the key again from Setup in CommentKit into data-project." });
748
+ checks.push({ id: "site.sdk", status: "fail", message: "The CommentKit script tag on the page has a key that is not a publishable key.", fix: `Copy the key again from ${DASHBOARD.install} in CommentKit into data-project.` });
629
749
  else {
630
750
  checks.push({ id: "site.sdk", status: "pass", message: `The page has the CommentKit script tag (key ${maskKey(loaderKey)}).` });
631
751
  if (setup.key && PUBLISHABLE_KEY.test(setup.key) && setup.key !== loaderKey)
@@ -703,6 +823,13 @@ export async function doctor(options, deps = {}) {
703
823
  checks.push({ id: "site.visibility", status: "info", message: `On ${site.host} the Comment button is hidden from ordinary visitors. It appears after opening a share link, for signed-in reviewers, or after pressing Cmd+Shift+K (Ctrl+Shift+K on Windows).` });
704
824
  }
705
825
  }
826
+ // Without an address only this folder and the key were checked. Say how to check the site too.
827
+ if (!site && (setup.appFound || key)) {
828
+ const found = siteAddress(options.cwd);
829
+ checks.push(found
830
+ ? { id: "site.suggest", status: "info", message: `To also check that ${found.url} is on the project's allowed websites and that its Content Security Policy lets CommentKit load, run ${CLI} doctor ${found.url} (address from ${found.source}).` }
831
+ : { id: "site.suggest", status: "info", message: `To also check that your site is on the project's allowed websites and that its Content Security Policy lets CommentKit load, run ${CLI} doctor with its address, for example ${CLI} doctor https://staging.example.com.` });
832
+ }
706
833
  // 5. Version: GET /sdk/latest is the newest stable SDK (public, no key needed). A canary rolling out is not
707
834
  // offered: only what every site gets once it is stable.
708
835
  if (reachable && setup.installedVersion) {