@mediamonks/canopy-cli 0.7.51 → 0.7.53

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 (75) hide show
  1. package/dist/{ai-BjnuSjmw.mjs → ai-BlqO9NhM.mjs} +2 -2
  2. package/dist/{api-DmJrIsE7.mjs → api-D4KUT6Ly.mjs} +9 -8
  3. package/dist/{audience-BSvOEbco.mjs → audience-Dlrsdthb.mjs} +3 -3
  4. package/dist/{browse-BPLWhoFI.mjs → browse-CW3CnhK_.mjs} +2 -2
  5. package/dist/{calls-COIxX32d.mjs → calls-DFtWVJfv.mjs} +3 -3
  6. package/dist/{db-D5SXZrp5.mjs → db-Dy1csI71.mjs} +15 -18
  7. package/dist/{deploy-D8OZyhH8.mjs → deploy-DHjZj2Pq.mjs} +13 -19
  8. package/dist/dev-CVC7elOr.mjs +2 -0
  9. package/dist/{dev-DjK3Y8jb.mjs → dev-L5slb6ke.mjs} +10 -9
  10. package/dist/{dev-worker-CDxgu7c1.mjs → dev-worker-DBBN0F6X.mjs} +15 -33
  11. package/dist/docs/access-tokens.md +145 -0
  12. package/dist/docs/ci.md +8 -0
  13. package/dist/docs/cli-dev.md +1 -1
  14. package/dist/docs/cli-schedule.md +1 -1
  15. package/dist/docs/cli-token.md +1 -1
  16. package/dist/docs/developers-architecture.md +16 -5
  17. package/dist/docs/index.json +10 -0
  18. package/dist/docs/outside-sign-in.md +1 -1
  19. package/dist/docs/overview-faq.md +4 -3
  20. package/dist/docs/platform-client-access.md +1 -1
  21. package/dist/docs/platform-credentials.md +76 -0
  22. package/dist/docs/platform-egress.md +4 -4
  23. package/dist/docs/platform-members-and-access.md +31 -6
  24. package/dist/docs/platform-project-data.md +4 -0
  25. package/dist/docs/platform-schedules.md +4 -4
  26. package/dist/docs/porting-nextjs.md +23 -23
  27. package/dist/docs/sdk-auth.md +61 -14
  28. package/dist/docs/sdk-files.md +117 -4
  29. package/dist/docs/sdk.md +17 -10
  30. package/dist/docs/staging.md +1 -1
  31. package/dist/docs/static-serving.md +6 -3
  32. package/dist/docs/troubleshooting.md +21 -1
  33. package/dist/{docs-CLgKBi8H.mjs → docs-bnQLqEOn.mjs} +4 -4
  34. package/dist/{egress-BoGWBHRa.mjs → egress-hKpsJF84.mjs} +4 -10
  35. package/dist/{feedback-B6tqJ3cd.mjs → feedback-vHJwLyWF.mjs} +4 -4
  36. package/dist/{files-B7toJRlj.mjs → files-DKtyMjY0.mjs} +3 -3
  37. package/dist/index.mjs +39 -52
  38. package/dist/{local-BmUmiOUN.mjs → local-B15wYk6z.mjs} +19 -8
  39. package/dist/{login-DrMr99-A.mjs → login-cbwynFoT.mjs} +3 -3
  40. package/dist/{logs-DJWrL6ja.mjs → logs-ByDPHO28.mjs} +3 -3
  41. package/dist/{mcp-CWtqUFE3.mjs → mcp-BmT4Es_B.mjs} +3 -3
  42. package/dist/{migrations-BReMlGWP.mjs → migrations-k5pyUUR0.mjs} +3 -3
  43. package/dist/{open-6ev_6m0p.mjs → open-CYfkeTaw.mjs} +2 -2
  44. package/dist/{package-4SGn0Cy3.mjs → package-DtU4jB_Z.mjs} +1 -1
  45. package/dist/{project-template-Bas1UN2O.mjs → project-template-B297eCQ0.mjs} +3 -3
  46. package/dist/project-template-B6YpesjZ.mjs +2 -0
  47. package/dist/{projects-BEBYhy6k.mjs → projects-ztlDQi0P.mjs} +28 -28
  48. package/dist/{rename-PIJmdzHk.mjs → rename-BZ8hvUUt.mjs} +3 -3
  49. package/dist/{repo-Dry87b9d.mjs → repo-BUIM4d_1.mjs} +4 -10
  50. package/dist/repo-fDD4TcJ4.mjs +2 -0
  51. package/dist/{roles-CXY226VM.mjs → roles-DvywfJ8x.mjs} +1 -1
  52. package/dist/{roles-CUFRTp_R.mjs → roles-Yn8U3cr-.mjs} +3 -3
  53. package/dist/{schedule-DJsclUxC.mjs → schedule-Cv26MIfS.mjs} +3 -3
  54. package/dist/{secrets-CV2IwVwU.mjs → secrets-C6tF7BI9.mjs} +3 -3
  55. package/dist/{site-BL5Ik-yj.mjs → site-C0nf9RXY.mjs} +8 -3
  56. package/dist/skill/canopy/SKILL.md +9 -1
  57. package/dist/{skill-CY_4eqOD.mjs → skill-CRTV3ZQ1.mjs} +2 -2
  58. package/dist/{src-DbqT3K2l.mjs → src-UBUAqzqH.mjs} +419 -41
  59. package/dist/{staging-B9sjqvfh.mjs → staging-C9mn0EBS.mjs} +6 -14
  60. package/dist/templates/spa/AGENTS.md +3 -3
  61. package/dist/templates/spa/README.md +2 -2
  62. package/dist/templates/spa/package.json +1 -1
  63. package/dist/templates/static/AGENTS.md +3 -3
  64. package/dist/templates/static/README.md +2 -2
  65. package/dist/templates/worker/AGENTS.md +3 -3
  66. package/dist/templates/worker/README.md +2 -2
  67. package/dist/templates/worker/package.json +1 -1
  68. package/dist/{token-BT2_ELX6.mjs → token-DIJtUPrE.mjs} +3 -3
  69. package/dist/{ui-Ddw4d2Nn.mjs → ui-BPq6-hKS.mjs} +16 -3
  70. package/dist/{upgrade-Dxzb3e3r.mjs → upgrade-LTEfQn4L.mjs} +2 -2
  71. package/dist/{usage-VMT75MZ4.mjs → usage-DBhL6SUo.mjs} +3 -3
  72. package/package.json +3 -3
  73. package/dist/dev-DkaQjBTp.mjs +0 -2
  74. package/dist/project-template-Dti_Mmnb.mjs +0 -2
  75. package/dist/repo-CGTFmIWM.mjs +0 -2
@@ -1,5 +1,5 @@
1
- import { a as apiRequest, m as withContext } from "./api-DmJrIsE7.mjs";
2
- import { r as reportErrors } from "./ui-Ddw4d2Nn.mjs";
1
+ import { a as apiRequest, m as withContext } from "./api-D4KUT6Ly.mjs";
2
+ import { i as reportErrors } from "./ui-BPq6-hKS.mjs";
3
3
  import { defineCommand } from "citty";
4
4
  //#region src/ai.ts
5
5
  /**
@@ -1,4 +1,4 @@
1
- import { f as rewriteCanopyJsonSlug, m as tryReadCanopyJson, r as siteConfig, t as projectDir } from "./site-BL5Ik-yj.mjs";
1
+ import { h as tryReadCanopyJson, p as rewriteCanopyJsonSlug, r as siteConfig, t as projectDir } from "./site-C0nf9RXY.mjs";
2
2
  //#region src/api.ts
3
3
  /**
4
4
  * Authenticated requests to the Canopy control plane. Credentials, in order:
@@ -507,7 +507,7 @@ async function fail(response, kind, method, path) {
507
507
  };
508
508
  throw err;
509
509
  }
510
- async function apiRequest(method, path, body, rawContentType, headers) {
510
+ async function apiRequest(method, path, body, opts = {}) {
511
511
  const { apiUrl, token, kind } = await credentials();
512
512
  const isForm = body instanceof FormData;
513
513
  const response = await fetch(`${apiUrl}/control/v1${path}`, {
@@ -515,10 +515,10 @@ async function apiRequest(method, path, body, rawContentType, headers) {
515
515
  headers: {
516
516
  ...commonHeaders(),
517
517
  authorization: `Bearer ${token}`,
518
- ...body === void 0 || isForm ? {} : { "content-type": rawContentType ?? "application/json" },
519
- ...headers
518
+ ...body === void 0 || isForm ? {} : { "content-type": "application/json" },
519
+ ...opts.headers
520
520
  },
521
- body: body === void 0 ? void 0 : isForm ? body : rawContentType !== void 0 ? body : JSON.stringify(body)
521
+ body: body === void 0 ? void 0 : isForm ? body : JSON.stringify(body)
522
522
  });
523
523
  followRename(response, slugInPath(path));
524
524
  if (!response.ok) return fail(response, kind, method, path);
@@ -560,7 +560,8 @@ async function apiDownload(path) {
560
560
  * unscoped; the target project rides as X-Canopy-Project and the api. gateway
561
561
  * re-vouches it (docs/10-cli-sites.md D17).
562
562
  */
563
- async function apiDataRequest(method, path, projectSlug, body, rawContentType, channel) {
563
+ async function apiDataRequest(method, path, projectSlug, body, opts = {}) {
564
+ const { contentType, channel } = opts;
564
565
  const { apiUrl, token, kind } = await credentials();
565
566
  const response = await fetch(`${apiUrl}/data/v1${path}`, {
566
567
  method,
@@ -569,9 +570,9 @@ async function apiDataRequest(method, path, projectSlug, body, rawContentType, c
569
570
  authorization: `Bearer ${token}`,
570
571
  "x-canopy-project": projectSlug,
571
572
  ...channel === "staging" ? { "x-canopy-channel": "staging" } : {},
572
- ...body === void 0 ? {} : { "content-type": rawContentType ?? "application/json" }
573
+ ...body === void 0 ? {} : { "content-type": contentType ?? "application/json" }
573
574
  },
574
- body: body === void 0 ? void 0 : rawContentType !== void 0 ? body : JSON.stringify(body)
575
+ body: body === void 0 ? void 0 : contentType !== void 0 ? body : JSON.stringify(body)
575
576
  });
576
577
  followRename(response, projectSlug);
577
578
  if (!response.ok) return fail(response, kind, method, path);
@@ -1,6 +1,6 @@
1
- import { c as projectDirArgs, d as resolveProject, l as projectFlagArgs } from "./site-BL5Ik-yj.mjs";
2
- import { a as apiRequest, m as withContext } from "./api-DmJrIsE7.mjs";
3
- import { r as reportErrors } from "./ui-Ddw4d2Nn.mjs";
1
+ import { f as resolveProject, l as projectDirArgs, u as projectFlagArgs } from "./site-C0nf9RXY.mjs";
2
+ import { a as apiRequest, m as withContext } from "./api-D4KUT6Ly.mjs";
3
+ import { i as reportErrors } from "./ui-BPq6-hKS.mjs";
4
4
  import { defineCommand } from "citty";
5
5
  import * as p from "@clack/prompts";
6
6
  //#region src/audience.ts
@@ -1,5 +1,5 @@
1
- import { h as tryResolveProject, r as siteConfig } from "./site-BL5Ik-yj.mjs";
2
- import { a as apiRequest, t as ApiError } from "./api-DmJrIsE7.mjs";
1
+ import { g as tryResolveProject, r as siteConfig } from "./site-C0nf9RXY.mjs";
2
+ import { a as apiRequest, t as ApiError } from "./api-D4KUT6Ly.mjs";
3
3
  import { defineCommand } from "citty";
4
4
  //#region src/browse.ts
5
5
  /**
@@ -1,6 +1,6 @@
1
- import { c as projectDirArgs, d as resolveProject } from "./site-BL5Ik-yj.mjs";
2
- import { a as apiRequest, m as withContext } from "./api-DmJrIsE7.mjs";
3
- import { r as reportErrors, t as formatDateTime } from "./ui-Ddw4d2Nn.mjs";
1
+ import { f as resolveProject, l as projectDirArgs } from "./site-C0nf9RXY.mjs";
2
+ import { a as apiRequest, m as withContext } from "./api-D4KUT6Ly.mjs";
3
+ import { i as reportErrors, n as formatDateTime } from "./ui-BPq6-hKS.mjs";
4
4
  import { defineCommand } from "citty";
5
5
  //#region src/calls.ts
6
6
  /**
@@ -1,7 +1,7 @@
1
- import { d as resolveProject, l as projectFlagArgs } from "./site-BL5Ik-yj.mjs";
2
- import { a as apiRequest, m as withContext, r as apiDataRequest } from "./api-DmJrIsE7.mjs";
3
- import { a as spinner$1, i as requireTty, o as unwrap, r as reportErrors } from "./ui-Ddw4d2Nn.mjs";
4
- import { n as migrateProject, r as readMigrationFiles, t as describeMigrateResult } from "./migrations-BReMlGWP.mjs";
1
+ import { f as resolveProject, u as projectFlagArgs } from "./site-C0nf9RXY.mjs";
2
+ import { a as apiRequest, m as withContext, r as apiDataRequest } from "./api-D4KUT6Ly.mjs";
3
+ import { a as requireTty, i as reportErrors, o as spinner$1, s as unwrap, t as confirmTypedSlug } from "./ui-BPq6-hKS.mjs";
4
+ import { n as migrateProject, r as readMigrationFiles, t as describeMigrateResult } from "./migrations-k5pyUUR0.mjs";
5
5
  import { defineCommand } from "citty";
6
6
  import { readFileSync, writeFileSync } from "node:fs";
7
7
  import * as p from "@clack/prompts";
@@ -49,7 +49,7 @@ const pullCommand = defineCommand({
49
49
  const spin = spinner$1();
50
50
  spin.start(`Exporting ${slug}${channelNote(args)}…`);
51
51
  try {
52
- const { url } = await apiDataRequest("POST", "/db/export", slug, void 0, void 0, channelOf(args));
52
+ const { url } = await apiDataRequest("POST", "/db/export", slug, void 0, { channel: channelOf(args) });
53
53
  const download = await fetch(url);
54
54
  if (!download.ok) throw new Error(`Download failed (HTTP ${download.status}).`);
55
55
  const sql = Buffer.from(await download.arrayBuffer());
@@ -76,7 +76,7 @@ const snapshotCommand = defineCommand({
76
76
  spin.start(`Snapshotting ${slug}${channelNote(args)}…`);
77
77
  let created;
78
78
  try {
79
- ({snapshot: created} = await apiDataRequest("POST", "/db/snapshots", slug, void 0, void 0, channelOf(args)));
79
+ ({snapshot: created} = await apiDataRequest("POST", "/db/snapshots", slug, void 0, { channel: channelOf(args) }));
80
80
  } catch (err) {
81
81
  spin.error("Snapshot failed.");
82
82
  throw err;
@@ -147,7 +147,7 @@ const snapshotsDeleteCommand = defineCommand({
147
147
  return;
148
148
  }
149
149
  }
150
- await withContext(apiDataRequest("DELETE", `/db/snapshots/${encodeURIComponent(args.key)}`, slug, void 0, void 0, channelOf(args)), { action: `delete snapshot ${args.key} of "${slug}"` });
150
+ await withContext(apiDataRequest("DELETE", `/db/snapshots/${encodeURIComponent(args.key)}`, slug, void 0, { channel: channelOf(args) }), { action: `delete snapshot ${args.key} of "${slug}"` });
151
151
  p.log.success(`Deleted ${args.key}${channelNote(args)}.`);
152
152
  })
153
153
  });
@@ -222,7 +222,7 @@ const snapshotsSettingsCommand = defineCommand({
222
222
  });
223
223
  const listSnapshotsRun = reportErrors("db snapshots", async ({ args }) => {
224
224
  const { slug } = resolveProject(args);
225
- const [{ snapshots }, settings] = await Promise.all([apiDataRequest("GET", "/db/snapshots", slug, void 0, void 0, channelOf(args)), apiRequest("GET", `/projects/${slug}/snapshot-settings`).catch(() => null)]);
225
+ const [{ snapshots }, settings] = await Promise.all([apiDataRequest("GET", "/db/snapshots", slug, void 0, { channel: channelOf(args) }), apiRequest("GET", `/projects/${slug}/snapshot-settings`).catch(() => null)]);
226
226
  if (settings) {
227
227
  console.log(`Schedule: ${describeSchedule(settings)} · retention: ${describeRetention(settings)}`);
228
228
  if (settings.lastRun) console.log(`Last scheduled run: ${describeLastRun(settings.lastRun)}`);
@@ -278,7 +278,7 @@ const restoreCommand = defineCommand({
278
278
  let snapshotKey = args.snapshot;
279
279
  if (!snapshotKey && !file) {
280
280
  requireTty("pass a local .sql dump or --snapshot <key>.");
281
- const { snapshots } = await apiDataRequest("GET", "/db/snapshots", slug, void 0, void 0, channelOf(args));
281
+ const { snapshots } = await apiDataRequest("GET", "/db/snapshots", slug, void 0, { channel: channelOf(args) });
282
282
  if (snapshots.length === 0) throw new Error(`No snapshots for ${slug} — run \`canopy db snapshot\` first, or pass a local .sql dump.`);
283
283
  snapshotKey = unwrap(await p.select({
284
284
  message: `Snapshot to restore into ${slug}`,
@@ -289,16 +289,13 @@ const restoreCommand = defineCommand({
289
289
  }))
290
290
  }));
291
291
  }
292
- if (!args.yes) {
293
- requireTty("pass --yes to restore without confirmation.");
294
- if (unwrap(await p.text({ message: `Restore will REPLACE all current data in "${slug}"${channelNote(args)} with ${snapshotKey ?? file}. Type the slug to confirm.` })).trim() !== slug) {
295
- p.cancel("Aborted.");
296
- return;
297
- }
298
- }
292
+ if (!args.yes && !await confirmTypedSlug(slug, `Restore will REPLACE all current data in "${slug}"${channelNote(args)} with ${snapshotKey ?? file}. Type the slug to confirm.`, "pass --yes to restore without confirmation.")) return;
299
293
  const restoreContext = { action: `restore "${slug}" from ${snapshotKey ?? file}` };
300
- if (snapshotKey) await withContext(apiDataRequest("POST", "/db/restore", slug, { snapshot: snapshotKey }, void 0, channelOf(args)), restoreContext);
301
- else if (file) await withContext(apiDataRequest("POST", "/db/restore", slug, readFileSync(file, "utf8"), "application/sql", channelOf(args)), restoreContext);
294
+ if (snapshotKey) await withContext(apiDataRequest("POST", "/db/restore", slug, { snapshot: snapshotKey }, { channel: channelOf(args) }), restoreContext);
295
+ else if (file) await withContext(apiDataRequest("POST", "/db/restore", slug, readFileSync(file, "utf8"), {
296
+ contentType: "application/sql",
297
+ channel: channelOf(args)
298
+ }), restoreContext);
302
299
  p.log.success(`Restored ${slug}${channelNote(args)}.`);
303
300
  })
304
301
  });
@@ -1,7 +1,7 @@
1
- import { c as projectDirArgs, d as resolveProject, l as projectFlagArgs, m as tryReadCanopyJson, p as stagingUrl, r as siteConfig, u as projectUrl } from "./site-BL5Ik-yj.mjs";
2
- import { a as apiRequest, d as githubActionsCredentials, i as apiDownload, l as currentSlug, m as withContext, p as onGithubActions, r as apiDataRequest, t as ApiError } from "./api-DmJrIsE7.mjs";
3
- import { a as spinner$1, o as unwrap, r as reportErrors, t as formatDateTime } from "./ui-Ddw4d2Nn.mjs";
4
- import { n as migrateProject, r as readMigrationFiles, t as describeMigrateResult } from "./migrations-BReMlGWP.mjs";
1
+ import { d as projectUrl, f as resolveProject, h as tryReadCanopyJson, l as projectDirArgs, m as stagingUrl, r as siteConfig, s as parseVersionArg, u as projectFlagArgs } from "./site-C0nf9RXY.mjs";
2
+ import { a as apiRequest, d as githubActionsCredentials, i as apiDownload, l as currentSlug, m as withContext, p as onGithubActions, r as apiDataRequest, t as ApiError } from "./api-D4KUT6Ly.mjs";
3
+ import { i as reportErrors, n as formatDateTime, o as spinner$1, s as unwrap } from "./ui-BPq6-hKS.mjs";
4
+ import { n as migrateProject, r as readMigrationFiles, t as describeMigrateResult } from "./migrations-k5pyUUR0.mjs";
5
5
  import { builtinModules } from "node:module";
6
6
  import { defineCommand } from "citty";
7
7
  import { mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
@@ -285,7 +285,7 @@ const deployCommand = defineCommand({
285
285
  throw err;
286
286
  }
287
287
  }
288
- const source = process.env["GITHUB_ACTIONS"] ? { "x-canopy-source": "github-action" } : {};
288
+ const source = onGithubActions() ? { "x-canopy-source": "github-action" } : {};
289
289
  const spin = spinner$1();
290
290
  const workerNote = workerBytes ? " + worker" : "";
291
291
  const channelNote = channel === "staging" ? " [staging]" : "";
@@ -297,7 +297,7 @@ const deployCommand = defineCommand({
297
297
  const { upload } = await withContext(apiRequest("POST", `/projects/${slug}/deploys`, {
298
298
  worker: workerBytes !== null,
299
299
  channel
300
- }, void 0, source), { action: `deploy "${slug}"` });
300
+ }, { headers: source }), { action: `deploy "${slug}"` });
301
301
  stagingCreated = upload.stagingCreated === true;
302
302
  const overLimit = bundleLimitError(files, upload);
303
303
  if (overLimit) {
@@ -321,7 +321,7 @@ const deployCommand = defineCommand({
321
321
  ({deploy: result} = await withContext(apiRequest("POST", `/projects/${slug}/deploys/${upload.version}/complete`, {
322
322
  grant: upload.grant,
323
323
  migrations: migrateResult?.appliedNow ?? []
324
- }, void 0, source), { action: `deploy "${slug}"` }));
324
+ }, { headers: source }), { action: `deploy "${slug}"` }));
325
325
  } catch (err) {
326
326
  spin.error("Deploy failed.");
327
327
  throw err;
@@ -360,10 +360,8 @@ const promoteCommand = defineCommand({
360
360
  run: reportErrors("promote", async ({ args }) => {
361
361
  const { slug } = resolveProject(args);
362
362
  let target;
363
- if (args.version !== void 0) {
364
- if (!/^v?\d+$/.test(args.version)) throw new Error(`Invalid version "${args.version}" — expected a number like 3 or v3.`);
365
- target = Number(args.version.replace(/^v/, ""));
366
- } else {
363
+ if (args.version !== void 0) target = parseVersionArg(args.version);
364
+ else {
367
365
  const { staging } = await apiRequest("GET", `/projects/${slug}/staging`);
368
366
  if (!staging.provisioned || staging.version === null) throw new Error(`Nothing staged for "${slug}" — run \`canopy deploy --staging\` first, or pass a version explicitly.`);
369
367
  target = staging.version;
@@ -493,10 +491,8 @@ const rollbackCommand = defineCommand({
493
491
  run: reportErrors("rollback", async ({ args }) => {
494
492
  const { slug } = resolveProject(args);
495
493
  let target;
496
- if (args.version !== void 0) {
497
- if (!/^v?\d+$/.test(args.version)) throw new Error(`Invalid version "${args.version}" — expected a number like 3 or v3.`);
498
- target = Number(args.version.replace(/^v/, ""));
499
- } else {
494
+ if (args.version !== void 0) target = parseVersionArg(args.version);
495
+ else {
500
496
  const { deploys, live } = await apiRequest("GET", `/projects/${slug}/deploys`);
501
497
  if (deploys.length < 2) throw new Error("Nothing to roll back to — this project has fewer than two deploys.");
502
498
  if (process.stdin.isTTY) {
@@ -537,10 +533,8 @@ const downloadCommand = defineCommand({
537
533
  run: reportErrors("download", async ({ args }) => {
538
534
  const { slug } = resolveProject(args);
539
535
  let target;
540
- if (args.version !== void 0) {
541
- if (!/^v?\d+$/.test(args.version)) throw new Error(`Invalid version "${args.version}" — expected a number like 3 or v3.`);
542
- target = Number(args.version.replace(/^v/, ""));
543
- } else {
536
+ if (args.version !== void 0) target = parseVersionArg(args.version);
537
+ else {
544
538
  const { deploys, live } = await apiRequest("GET", `/projects/${slug}/deploys`);
545
539
  if (deploys.length === 0) throw new Error("Nothing to download — this project has no deploys yet.");
546
540
  if (process.stdin.isTTY) target = await pickVersion(deploys, live, "Version to download", live ?? void 0);
@@ -0,0 +1,2 @@
1
+ import { n as devCommand } from "./dev-L5slb6ke.mjs";
2
+ export { devCommand };
@@ -1,9 +1,9 @@
1
- import { c as projectDirArgs, d as resolveProject, m as tryReadCanopyJson, r as siteConfig, s as projectDialect } from "./site-BL5Ik-yj.mjs";
2
- import { a as apiRequest, m as withContext, t as ApiError } from "./api-DmJrIsE7.mjs";
3
- import { r as reportErrors, t as formatDateTime } from "./ui-Ddw4d2Nn.mjs";
4
- import { r as readMigrationFiles } from "./migrations-BReMlGWP.mjs";
5
- import { i as stampWorkerHeaders, n as WORKER_ATTEST_HEADER } from "./src-DbqT3K2l.mjs";
6
- import { a as parseAppRoleFlag } from "./roles-CUFRTp_R.mjs";
1
+ import { c as projectDialect, f as resolveProject, h as tryReadCanopyJson, l as projectDirArgs, r as siteConfig } from "./site-C0nf9RXY.mjs";
2
+ import { a as apiRequest, m as withContext, t as ApiError } from "./api-D4KUT6Ly.mjs";
3
+ import { i as reportErrors, n as formatDateTime } from "./ui-BPq6-hKS.mjs";
4
+ import { r as readMigrationFiles } from "./migrations-k5pyUUR0.mjs";
5
+ import { r as stampWorkerHeaders, t as WORKER_ATTEST_HEADER } from "./src-UBUAqzqH.mjs";
6
+ import { a as parseAppRoleFlag } from "./roles-Yn8U3cr-.mjs";
7
7
  import { n as writeDevServerRecord } from "./dev-server-file-Dk9pk4AR.mjs";
8
8
  import { createRequire } from "node:module";
9
9
  import { defineCommand } from "citty";
@@ -107,7 +107,7 @@ async function workerPlugin(flags, slug, workerAttest, remoteUser, roles) {
107
107
  console.log(`note: canopy.json points "worker" at ${entry}, which does not exist — skipping.`);
108
108
  return;
109
109
  }
110
- const { missingSecretNames, readDevVars, workerDevPlugin } = await import("./dev-worker-CDxgu7c1.mjs");
110
+ const { missingSecretNames, readDevVars, workerDevPlugin } = await import("./dev-worker-DBBN0F6X.mjs");
111
111
  const secrets = readDevVars(flags.dir);
112
112
  const email = siteConfig().email;
113
113
  const found = await remoteUser?.() ?? (email ? {
@@ -262,6 +262,7 @@ async function bridgeToSandbox(sandbox, req, res) {
262
262
  const headers = new Headers();
263
263
  if (req.headers["content-type"]) headers.set("content-type", req.headers["content-type"]);
264
264
  if (req.headers["accept"]) headers.set("accept", req.headers["accept"]);
265
+ if (body.length > 0) headers.set("content-length", String(body.length));
265
266
  const attest = req.headers[WORKER_ATTEST_HEADER];
266
267
  if (typeof attest === "string") headers.set(WORKER_ATTEST_HEADER, attest);
267
268
  const response = await sandbox.handle(new Request(`http://canopy.local${req.url ?? ""}`, {
@@ -325,7 +326,7 @@ async function devRemote(flags, slug) {
325
326
  async function devLocal(flags, slug) {
326
327
  let dump;
327
328
  if (flags.pull) {
328
- const { fetchProjectDump } = await import("./local-BmUmiOUN.mjs");
329
+ const { fetchProjectDump } = await import("./local-B15wYk6z.mjs");
329
330
  console.log(`Pulling a fresh export of ${slug}${flags.staging ? " [staging]" : ""}…`);
330
331
  dump = await fetchProjectDump(slug, flags.staging ? "staging" : "live");
331
332
  }
@@ -342,7 +343,7 @@ async function devLocal(flags, slug) {
342
343
  }
343
344
  const workerAttest = randomBytes(24).toString("base64url");
344
345
  const devRoles = await resolveDevRoles(slug, flags.asRoles);
345
- const { createSandbox } = await import("./local-BmUmiOUN.mjs");
346
+ const { createSandbox } = await import("./local-B15wYk6z.mjs");
346
347
  const sandbox = await createSandbox({
347
348
  slug,
348
349
  persistDir: join(flags.dir, ".canopy", "local"),
@@ -1,4 +1,4 @@
1
- import { i as stampWorkerHeaders, n as WORKER_ATTEST_HEADER, r as redactCanopyCredentials, t as CALLER_HEADER } from "./src-DbqT3K2l.mjs";
1
+ import { a as readPersonCaller, i as CALLER_HEADER, n as redactCanopyCredentials, o as readUser, r as stampWorkerHeaders, t as WORKER_ATTEST_HEADER } from "./src-UBUAqzqH.mjs";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { relative, resolve, sep } from "node:path";
4
4
  //#region src/dev-worker.ts
@@ -189,23 +189,13 @@ function createDevBlob(canopyFetch, prefix) {
189
189
  }
190
190
  };
191
191
  }
192
- /** Stamped app roles (project-roles); undefined when the request carries none. */
193
- function rolesFromHeaders(headers) {
194
- const raw = headers.get("x-canopy-identity-roles");
195
- if (raw === null) return void 0;
196
- return raw.split(",").map((r) => r.trim()).filter(Boolean);
197
- }
198
- /** Gateway-stamped identity, honored in dev too so a request can pose as one. */
192
+ /**
193
+ * Gateway-stamped identity, honored in dev too so a request can pose as one.
194
+ * Decoded by the shared caller protocol (@mediamonks/canopy-data-plane,
195
+ * credential-model); the developer stands in when nothing is stamped.
196
+ */
199
197
  function userFromHeaders(headers, fallback) {
200
- const sub = (headers.get("x-canopy-user-sub") ?? "").trim();
201
- if (!sub) return fallback;
202
- const roles = rolesFromHeaders(headers);
203
- return {
204
- sub,
205
- email: (headers.get("x-canopy-user-email") ?? "").trim(),
206
- name: (headers.get("x-canopy-user-name") ?? "").trim(),
207
- ...roles && { roles }
208
- };
198
+ return readUser(headers) ?? fallback;
209
199
  }
210
200
  /**
211
201
  * The caller in dev: stamped caller headers when a request poses as one
@@ -213,28 +203,20 @@ function userFromHeaders(headers, fallback) {
213
203
  * the developer, since no company login fronts a local server.
214
204
  */
215
205
  function callerFromHeaders(headers, fallback) {
216
- const kind = (headers.get("x-canopy-identity-kind") ?? "").trim();
217
- const id = (headers.get("x-canopy-identity-id") ?? "").trim();
218
- const agent = headers.get("x-canopy-caller") === "agent";
219
- if ((kind === "monk" || kind === "external") && id) {
220
- const roles = rolesFromHeaders(headers);
221
- return {
222
- kind,
223
- id,
224
- email: (headers.get("x-canopy-identity-email") ?? "").trim(),
225
- name: (headers.get("x-canopy-identity-name") ?? "").trim(),
226
- agent,
227
- ...roles && { roles }
228
- };
229
- }
206
+ const person = readPersonCaller(headers);
207
+ if (person) return {
208
+ ...person,
209
+ token: null
210
+ };
230
211
  const user = userFromHeaders(headers, fallback);
231
212
  return user ? {
232
213
  kind: "monk",
233
214
  id: user.sub,
234
215
  email: user.email,
235
216
  name: user.name,
236
- agent,
237
- ...user.roles && { roles: user.roles }
217
+ agent: headers.get(CALLER_HEADER) === "agent",
218
+ ...user.roles && { roles: user.roles },
219
+ token: null
238
220
  } : null;
239
221
  }
240
222
  /**
@@ -0,0 +1,145 @@
1
+ ---
2
+ title: Calling from apps and scripts
3
+ description: Let a desktop app, plugin, CI job or script call your project's backend with an access token.
4
+ ---
5
+
6
+ A project's `/api` routes normally open only to someone signed in with a
7
+ browser. An access token lets other software in: a design-tool plugin on a
8
+ designer's laptop, a CI job that pushes a report, a script that pulls
9
+ results. It works only on one project's `/api` routes, never on its pages.
10
+
11
+ There are two kinds:
12
+
13
+ | | Personal token | Project key |
14
+ | ------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
15
+ | For | a desktop app or plugin used by one person | a CI job, script or service |
16
+ | Acts as | the person who made it | itself, with no person behind it |
17
+ | Who makes it | any Monk who can open the project | the owner, managers and site admins |
18
+ | Stops working | when it expires (90 days at most), when its person loses access to the project, or after 30 days without them signing in to Canopy | when it expires (if you gave it a date), or after 90 days without a call |
19
+ | How many | 10 per person on each channel | 20 on each channel |
20
+
21
+ Both stop when they're revoked, when the project is deleted, and when the
22
+ owner turns access tokens off.
23
+
24
+ ## 1. Turn access tokens on
25
+
26
+ The project's owner turns them on under **Settings → Access → Access
27
+ tokens**. They are off by default. Turning them off later stops every token
28
+ on the project at once; turning them back on revives the ones that haven't
29
+ expired.
30
+
31
+ ## 2. Make a token
32
+
33
+ - **A personal token:** on your **Account** page (click your avatar), choose
34
+ **New token**. If you can open the project's settings, **New personal
35
+ token** under **Settings → Access** does the same.
36
+ - **A project key:** on the project's **Settings → Access**, choose **New
37
+ project key**.
38
+
39
+ People outside Monks and client-password visitors can't make tokens.
40
+
41
+ Give it a name you'll recognise later, pick the channel (live or staging) and
42
+ how long it lasts. A personal token lasts 30 days unless you pick another
43
+ length, up to 90. A project key lasts until you revoke it unless you give it a
44
+ date. The token is shown once. Copy it into the app's keychain
45
+ or your CI's secret store, never into a file in your repository.
46
+
47
+ You can limit a token further:
48
+
49
+ - **Routes:** only paths under the prefixes you give (up to 10), like `/api/hooks`. A
50
+ prefix covers whole path segments, so `/api/hooks` doesn't open
51
+ `/api/hooksmith`.
52
+ - **Methods:** only the HTTP methods you pick. `GET` only means other methods
53
+ are refused; a `GET` route that changes data still runs.
54
+ - **Scopes:** your project's own permissions (step 4).
55
+
56
+ Canopy refuses anything outside the routes and methods before your backend
57
+ runs. Give every project key a route limit if you can.
58
+
59
+ ## 3. Call the project
60
+
61
+ Send the token as a bearer token to the project's own address:
62
+
63
+ ```bash
64
+ curl -X POST https://my-project.canopy.website/api/hooks/build \
65
+ -H "Authorization: Bearer $CANOPY_KEY" \
66
+ -H "content-type: application/json" \
67
+ -d '{"status":"passed"}'
68
+ ```
69
+
70
+ A refused token gets a JSON answer, never a sign-in page:
71
+
72
+ | Error | Why |
73
+ | ---------------------------------------------------- | ------------------------------------------------------------------------------------ |
74
+ | `token_invalid` | unknown or revoked, or made for another project or channel |
75
+ | `token_expired` | past its date, or a project key unused for 90 days |
76
+ | `token_disabled` | the owner turned access tokens off |
77
+ | `token_access_lost` | its person can no longer open the project, or hasn't signed in to Canopy for 30 days |
78
+ | `token_path_not_allowed`, `token_method_not_allowed` | outside the token's routes or methods |
79
+ | `project_paused`, `project_moved` | the project is paused, or moved (the answer's `moved_to` says where) |
80
+ | `no_backend` | the project has no backend on that channel |
81
+ | `token_check_unavailable` | Canopy couldn't check the token just now; try again |
82
+
83
+ A personal token keeps working as long as its person signs in to Canopy at
84
+ least once a month, in a browser or with `canopy login`. If someone only ever uses the plugin, the
85
+ `token_access_lost` answer tells them to sign in again.
86
+
87
+ ## 4. Check it in your backend
88
+
89
+ Your backend sees who called on [`env.CALLER`](https://docs.canopy.website/sdk/auth#in-a-backend-worker),
90
+ and the token on `env.CALLER.token`:
91
+
92
+ - A personal token's caller is the person, with their app roles, exactly
93
+ as in their browser, plus `token`.
94
+ - A project key's caller has `kind: "key"`, the key's `id` and `name`, no
95
+ roles, and `env.USER` is `null`.
96
+ - Every other request has `token: null`.
97
+
98
+ Scopes are your project's own words for what a token may do. Add them under
99
+ **Settings → Access → Token scopes** (for example `reports:write`), pick
100
+ them when making a token, and check them in your backend with `requireScope`:
101
+
102
+ ```ts
103
+ import { requireScope, ScopeError } from "@mediamonks/canopy";
104
+
105
+ app.post("/api/hooks/build", async (c) => {
106
+ try {
107
+ requireScope(c.env.CALLER, "reports:write");
108
+ } catch (err) {
109
+ if (err instanceof ScopeError) return c.json({ error: err.message }, 403);
110
+ throw err;
111
+ }
112
+ // …
113
+ });
114
+ ```
115
+
116
+ `requireScope` lets a browser visitor through: scopes narrow what a token may
117
+ do, not what its person may do. A token passes only when it carries the
118
+ scope. A route that never calls `requireScope` gives a token everything its
119
+ caller could do, so check scopes on every route a token shouldn't reach
120
+ freely.
121
+
122
+ During a token call, your backend's own Canopy calls (`auth.user()`, data,
123
+ files) act as the project, not as the token's person. Use `env.CALLER` to
124
+ know who called.
125
+
126
+ A backend deployed before access tokens existed doesn't see `env.CALLER.token`
127
+ or project keys. Run `canopy deploy` once to pick them up.
128
+
129
+ ## Trying it locally
130
+
131
+ `canopy dev` has no token check: the developer is always the caller, and
132
+ `env.CALLER.token` is `null`, so `requireScope` lets every request through. To
133
+ try a token for real, deploy to the [staging channel](https://docs.canopy.website/guides/staging) and make a
134
+ staging token for it.
135
+
136
+ ## See and revoke tokens
137
+
138
+ - Your own personal tokens are on your Account page, on every project.
139
+ - The owner and managers see every token on the project under **Settings →
140
+ Access**, with who made it, when it was last used and when it ends.
141
+ - Revoking one stops it within a few seconds.
142
+ - Signing out everywhere ends all your personal tokens. Project keys you made
143
+ keep working, because they belong to the project.
144
+
145
+ Read [Members & access](https://docs.canopy.website/platform/members-and-access) for who can do what.
package/dist/docs/ci.md CHANGED
@@ -135,3 +135,11 @@ wins over the linked repository when both are there.
135
135
  working when they leave.
136
136
  - A token that goes 90 days without a deploy stops working.
137
137
  - Turning CI deploys off does not stop a deploy token. Revoke it for that.
138
+
139
+ ## CI jobs that call your project
140
+
141
+ A deploy token only deploys. For a CI job that sends data to your project
142
+ while it runs, like test results or a build report, give it a
143
+ [project key](https://docs.canopy.website/guides/access-tokens) and have it call your project's own
144
+ `/api` routes. [Which credential do I need?](https://docs.canopy.website/platform/credentials) compares
145
+ them all.
@@ -40,7 +40,7 @@ With the lock in place, `--local` runs on an embedded SQLite engine instead —
40
40
 
41
41
  **Your backend worker.** If `canopy.json` names a `worker` entry (the worker scaffold does), `canopy dev` serves it too: requests to `/api/*` go to your worker, everything else to the SPA — the same split the platform makes once you deploy. There's no build step; save the file and the next request runs the new code.
42
42
 
43
- Your worker gets the same `env` it gets in production: `env.CANOPY.fetch` for the SDK, `env.DB` and `env.BLOB` for raw database and file access, `env.CALLER` and `env.USER` for whoever is calling, `env.PROJECT_SLUG`, and `env.CANOPY_CHANNEL` (`"staging"` with `--staging`, otherwise `"live"`). They all follow the mode you're in — live project data by default, your sandbox under `--local`. Two differences worth knowing: `env.CALLER` and `env.USER` are you (the account you logged in with), since there's no company login in front of a local server, and a write through `env.DB` reports no row count locally.
43
+ Your worker gets the same `env` it gets in production: `env.CANOPY.fetch` for the SDK, `env.DB` and `env.BLOB` for raw database and file access, `env.CALLER` and `env.USER` for whoever is calling, `env.PROJECT_SLUG`, and `env.CANOPY_CHANNEL` (`"staging"` with `--staging`, otherwise `"live"`). They all follow the mode you're in — live project data by default, your sandbox under `--local`. Three differences worth knowing: `env.CALLER` and `env.USER` are you (the account you logged in with), since there's no company login in front of a local server; there's no [access token](https://docs.canopy.website/guides/access-tokens) check, so `env.CALLER.token` is always `null` and `requireScope` lets every request through; and a write through `env.DB` reports no row count locally.
44
44
 
45
45
  To tick a schedule by hand, post its name to the same path the platform uses:
46
46
 
@@ -4,7 +4,7 @@ description: List, add, and remove the project's cron schedules from the termina
4
4
  ---
5
5
 
6
6
  `canopy schedule` manages the project's named cron jobs — the same schedules
7
- as the dashboard's **Settings → Schedules**, so a migration or an agent can
7
+ as the dashboard's **Backend → Schedules**, so a migration or an agent can
8
8
  set up recurring jobs without leaving the terminal. See
9
9
  [Schedules](https://docs.canopy.website/platform/schedules) for how schedules work and how your worker
10
10
  handles them.
@@ -32,7 +32,7 @@ The token belongs to the project rather than to whoever created it, so CI keeps
32
32
 
33
33
  To use it in CI, put the value in the `CANOPY_DEPLOY_TOKEN` environment variable — the CLI checks it first, so `canopy deploy` works on a runner with no `canopy login`. In GitHub Actions a token wins over the linked repository, and keeps working while CI deploys are switched off.
34
34
 
35
- If a deploy fails with a rejected token, it was likely revoked — create a fresh one here or in the dashboard (Settings → Deploy tokens) and update the secret. Losing a token is never a problem: revoke the old id and mint a new one.
35
+ If a deploy fails with a rejected token, it was likely revoked — create a fresh one here or in the dashboard (Deploys → Deploy tokens) and update the secret. Losing a token is never a problem: revoke the old id and mint a new one.
36
36
 
37
37
  ## Examples
38
38
 
@@ -16,7 +16,7 @@ project has one, dispatches `/api/*` to your backend worker.
16
16
 
17
17
  ```mermaid
18
18
  flowchart TD
19
- B[Browser] --> G["Gateway<br/>auth wall: OneLogin session<br/>or client password"]
19
+ B[Browser or app] --> G["Gateway<br/>auth wall: sign-in, client password<br/>or access token on /api"]
20
20
  G -->|"most paths"| A["Static assets<br/>deployed build, SPA fallback"]
21
21
  G -->|"/api/*"| W["Backend worker<br/>(optional, canopy.json 'worker')"]
22
22
  G -->|"/_api/data/v1/*"| P["Platform data plane<br/>auth · db · blob · ai"]
@@ -28,9 +28,20 @@ flowchart TD
28
28
 
29
29
  Authentication is a platform property — your app cannot opt out, and must not
30
30
  build its own. A visitor without a valid session is redirected into the
31
- OneLogin sign-in flow; on projects with client access enabled, outsiders get a
32
- password page and receive a scope-limited `external` session instead. Only
33
- after that does any project code or asset get served. Your app just asks
31
+ OneLogin sign-in flow. Other ways in, each one the project turns on:
32
+
33
+ - people outside Monks who were [invited by email](https://docs.canopy.website/guides/outside-sign-in)
34
+ sign in with a link or code;
35
+ - on projects with [client access](https://docs.canopy.website/platform/client-access), outsiders get a
36
+ password page and a scope-limited `external` session;
37
+ - an AI agent opens the app on its person's behalf with
38
+ [`canopy browse`](https://docs.canopy.website/guides/agent-browsing);
39
+ - software that isn't a browser calls `/api/*` with an
40
+ [access token](https://docs.canopy.website/guides/access-tokens), and
41
+ [another project's backend](https://docs.canopy.website/guides/calling-projects) calls it with a call
42
+ token Canopy signs.
43
+
44
+ Only after that does any project code or asset get served. Your app just asks
34
45
  `canopy.auth.user()` who came through the door
35
46
  (see the [SDK reference](https://docs.canopy.website/sdk)).
36
47
 
@@ -103,7 +114,7 @@ else is still static serving. A few things to know:
103
114
  const notes = await canopy.db.collection("notes").find();
104
115
  ```
105
116
 
106
- - **Secrets and schedules come from the dashboard.** Secrets (Settings →
117
+ - **Secrets and schedules come from the dashboard.** Secrets (Backend →
107
118
  Secrets) land as Workers-shaped bindings (`c.env.MY_API_KEY`, not
108
119
  `process.env`); dashboard Schedules invoke an exported
109
120
  `scheduled(event, env)` — switch on `event.name`.