@mediamonks/canopy-cli 0.7.51 → 0.7.52

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.
@@ -2,7 +2,7 @@ import { c as projectDirArgs, d as resolveProject, m as tryReadCanopyJson, r as
2
2
  import { a as apiRequest, m as withContext, t as ApiError } from "./api-DmJrIsE7.mjs";
3
3
  import { r as reportErrors, t as formatDateTime } from "./ui-Ddw4d2Nn.mjs";
4
4
  import { r as readMigrationFiles } from "./migrations-BReMlGWP.mjs";
5
- import { i as stampWorkerHeaders, n as WORKER_ATTEST_HEADER } from "./src-DbqT3K2l.mjs";
5
+ import { r as stampWorkerHeaders, t as WORKER_ATTEST_HEADER } from "./src-UBUAqzqH.mjs";
6
6
  import { a as parseAppRoleFlag } from "./roles-CUFRTp_R.mjs";
7
7
  import { n as writeDevServerRecord } from "./dev-server-file-Dk9pk4AR.mjs";
8
8
  import { createRequire } from "node:module";
@@ -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-R-INkPbU.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-R-INkPbU.mjs");
346
347
  const sandbox = await createSandbox({
347
348
  slug,
348
349
  persistDir: join(flags.dir, ".canopy", "local"),
@@ -0,0 +1,2 @@
1
+ import { n as devCommand } from "./dev-BnzJ8a1u.mjs";
2
+ export { devCommand };
@@ -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
 
@@ -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
 
@@ -67,6 +67,11 @@
67
67
  "title": "Calling another project",
68
68
  "summary": "Let one project's backend call another project's API, and tell who is calling."
69
69
  },
70
+ {
71
+ "slug": "access-tokens",
72
+ "title": "Calling from apps and scripts",
73
+ "summary": "Let a desktop app, plugin, CI job or script call your project's backend with an access token."
74
+ },
70
75
  {
71
76
  "slug": "data",
72
77
  "title": "Working with project data",
@@ -174,6 +179,11 @@
174
179
  "title": "Members & access",
175
180
  "summary": "Everything on Canopy sits behind Monks sign-in. Editors manage a project, managers also run its members list, viewers open it, and your app can hand out its own roles on top."
176
181
  },
182
+ {
183
+ "slug": "platform-credentials",
184
+ "title": "Which credential do I need?",
185
+ "summary": "Every way in to Canopy and to your project, and which one fits the job — sign-ins, dev tokens, deploy tokens, access tokens and agent tokens."
186
+ },
177
187
  {
178
188
  "slug": "platform-feedback",
179
189
  "title": "Feedback & bug reports",
@@ -88,9 +88,10 @@ whether your app is a good fit.
88
88
 
89
89
  ## Can it deploy automatically when we change the code?
90
90
 
91
- Yes. Create a project-scoped deploy token, add it to your repository's CI, and
92
- merging to `main` ships a new version on its own. The token can only deploy
93
- that one project — it can't touch your data. See the [CI guide](https://docs.canopy.website/guides/ci).
91
+ Yes. On GitHub, link the repository once with `canopy repo link`, and every
92
+ push to its main branch ships a new version, with no secret to manage. Other
93
+ CI systems use a deploy token, which can only deploy that one project — it
94
+ can't touch your data. See the [CI guide](https://docs.canopy.website/guides/ci).
94
95
 
95
96
  ## What if my project outgrows Canopy?
96
97
 
@@ -0,0 +1,76 @@
1
+ ---
2
+ title: Which credential do I need?
3
+ description: Every way in to Canopy and to your project, and which one fits the job — sign-ins, dev tokens, deploy tokens, access tokens and agent tokens.
4
+ ---
5
+
6
+ Most of the time you never handle a credential: you sign in once, and the
7
+ platform takes care of the rest. This page is for when something that isn't
8
+ your browser needs a way in.
9
+
10
+ ## Pick by job
11
+
12
+ | You want to… | Use | Lasts |
13
+ | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
14
+ | work with Canopy from your terminal | [`canopy login`](https://docs.canopy.website/cli/login) | 30 days, or until you sign out |
15
+ | run your project locally against its real data | a dev token — [`canopy dev`](https://docs.canopy.website/cli/dev) makes one for you | 12 hours, or until you sign out |
16
+ | deploy from GitHub Actions | nothing: [link the repository](https://docs.canopy.website/guides/ci) | — |
17
+ | deploy from any other CI | a deploy token — [`canopy token create`](https://docs.canopy.website/cli/token) | until revoked, or 90 days without a deploy |
18
+ | let a CI job, script or service call your project's `/api` | a [project key](https://docs.canopy.website/guides/access-tokens) | until revoked or its date, or 90 days without a call |
19
+ | let a desktop app or plugin call your project's `/api` as you | a [personal token](https://docs.canopy.website/guides/access-tokens) | up to 90 days, while you keep signing in |
20
+ | let an AI agent work on your project | nothing: [`canopy mcp`](https://docs.canopy.website/cli/mcp) and [`canopy browse`](https://docs.canopy.website/cli/browse) do it | while your `canopy login` lasts |
21
+ | let another project's backend call yours | nothing: [`canopy calls allow`](https://docs.canopy.website/cli/calls) | — |
22
+ | let people outside Monks open your project | an [email invite](https://docs.canopy.website/guides/outside-sign-in) or the [client password](https://docs.canopy.website/platform/client-access) | — |
23
+
24
+ Your own backend never needs a credential either: the platform gives it one,
25
+ and the [SDK](https://docs.canopy.website/sdk) uses it for you.
26
+
27
+ ## What each one can reach
28
+
29
+ - **Your sign-in** (browser or `canopy login`) reaches everything you can
30
+ reach in the dashboard.
31
+ - **A dev token** reaches what your project's backend reaches on the
32
+ platform (data, files, AI and the rest), on one project, as you.
33
+ It can't change the project's settings, and it isn't meant for anything
34
+ that runs unattended. It ends when the `canopy login` it came from ends.
35
+ - **A deploy token** deploys one project and does nothing else. It belongs to
36
+ the project, so it keeps working when the person who made it leaves.
37
+ - **An access token** opens one project's `/api` routes on one channel, and
38
+ nothing else: not its pages, not its data directly, not Canopy itself. The
39
+ project's owner turns access tokens on, and your backend decides what each
40
+ one may do. A personal token acts as you; a project key acts as itself.
41
+ - **An agent's credentials** act as you, on one project and channel, and end
42
+ when the `canopy login` they came from ends.
43
+
44
+ ## Telling tokens apart
45
+
46
+ Every Canopy token starts with `cnpy_` and a short name for its kind, so you
47
+ can tell what you're looking at in a log or a pasted snippet:
48
+
49
+ | Starts with | What it is |
50
+ | ----------- | ---------------------------------- |
51
+ | `cnpy_cli_` | a `canopy login` sign-in |
52
+ | `cnpy_dev_` | a dev token from `canopy dev` |
53
+ | `cnpy_dep_` | a deploy token |
54
+ | `cnpy_wrk_` | your backend's own token |
55
+ | `cnpy_agt_` | an AI agent's token (`canopy mcp`) |
56
+ | `cnpy_tkt_` | a `canopy browse` link |
57
+ | `cnpy_pat_` | a personal token |
58
+ | `cnpy_key_` | a project key |
59
+
60
+ Tokens made before this naming start with just `cnpy_` and keep working until
61
+ they expire. Secret scanners, such as GitHub's, can look for these prefixes
62
+ too.
63
+
64
+ ## When one leaks
65
+
66
+ - **Your sign-in or a personal token:** use **Sign out everywhere** on your
67
+ Account page. It ends every browser session, CLI sign-in, `canopy dev` and
68
+ agent session, and personal token of yours at once.
69
+ - **A deploy token:** revoke it with `canopy token revoke` or under the
70
+ project's **Settings**, and make a new one.
71
+ - **A project key:** revoke it under the project's **Settings → Access**.
72
+ - **Not sure what it was?** Revoke it anyway. Making a new credential is
73
+ always cheap.
74
+
75
+ Read [Members & access](https://docs.canopy.website/platform/members-and-access) for who can do what on a
76
+ project.
@@ -135,6 +135,28 @@ Both are labels only. They never change who can open the project; that's
135
135
  what members-only and the client password are for. From the CLI, use
136
136
  [`canopy audience`](https://docs.canopy.website/cli/audience).
137
137
 
138
+ ## Access tokens
139
+
140
+ Software that isn't a browser, like a design-tool plugin or a CI job, can call
141
+ a project's `/api` routes with an access token. They are off until the owner
142
+ turns them on under **Settings → Access → Access tokens**, and turning them
143
+ off stops every token at once.
144
+
145
+ - **Personal tokens** act as the person who made them. Any Monk who can open
146
+ the project makes their own on their Account page (or the project's
147
+ **Settings → Access**, if they can open it). People outside Monks and
148
+ client-password visitors can't make them.
149
+ - **Project keys** act as themselves, for CI jobs and scripts. The owner,
150
+ managers and site admins make them, and they keep working after their maker
151
+ leaves.
152
+ - The owner and managers see every token on the project and can revoke any
153
+ of them. Everyone else sees only their own.
154
+ - **Token scopes** are the project's own permissions for tokens. The owner
155
+ and editors add them; the project's code decides what each one allows.
156
+
157
+ Read [Calling from apps and scripts](https://docs.canopy.website/guides/access-tokens) for the whole
158
+ walkthrough.
159
+
138
160
  ## Platform admins and the Admin page
139
161
 
140
162
  Platform admins get an extra **Admin** page in the dashboard. Its **Users**
@@ -154,12 +176,15 @@ machines you have signed in from, with when each token was last used, and lets
154
176
  you revoke any of them. Revoking a token is what `canopy logout` does for the
155
177
  machine it runs on.
156
178
 
157
- **Sign out everywhere** on the same page ends every browser session and every
158
- CLI sign-in of yours on that site at once, this one included. Reach for it
159
- when a laptop goes missing or you signed in somewhere you shouldn't have; the
160
- next request from any of those places meets the sign-in page. Deploy tokens
161
- used by CI belong to their projects, not to you, and keep working — revoke
162
- those from the project's Deploys tab if they were on the lost machine too.
179
+ **Sign out everywhere** on the same page ends every browser session, every
180
+ CLI sign-in (and the `canopy dev` and agent sessions started from them) and
181
+ every personal access token of yours on that site at once, this one
182
+ included. Reach for it
183
+ when a laptop goes missing or you signed in somewhere you shouldn't have. A
184
+ browser meets the sign-in page on its next request, the CLI asks you to run
185
+ `canopy login` again, and a personal token is refused. Deploy tokens
186
+ and project keys belong to their projects, not to you, and keep working —
187
+ revoke those from the project if they were on the lost machine too.
163
188
 
164
189
  Platform admins have the same button for any user on the **Admin** page, which
165
190
  is how someone who leaves the company is signed out of Canopy before their
@@ -39,6 +39,10 @@ Data tab's browser access for the database; see
39
39
  [Files](https://docs.canopy.website/sdk/files#who-can-call-this-from-the-browser) for how pages and the
40
40
  worker split the work.
41
41
 
42
+ One file can be up to 200 MB on `main` and `staging` (100 MB when a browser
43
+ uploads it) and up to 25 MB on `gcp-pilot`. See
44
+ [how big a file can be](https://docs.canopy.website/sdk/files#how-big-a-file-can-be).
45
+
42
46
  ## Snapshots and restores
43
47
 
44
48
  The Data tab's **Data safety** card is your undo button for data:
@@ -5,8 +5,8 @@ description: Read who the platform signed in — you never build a login screen.
5
5
 
6
6
  Authentication happens before your code runs: the platform gates every request
7
7
  to your project, so by the time a page loads or a worker route fires, there is
8
- always a signed-in user. You never build a login screen, store passwords, or
9
- check tokens — see [Members and access](https://docs.canopy.website/platform/members-and-access) for
8
+ always a signed-in user. You never build a login screen or store passwords —
9
+ see [Members and access](https://docs.canopy.website/platform/members-and-access) for
10
10
  who gets in and how. `canopy.auth` only reports who the platform let in.
11
11
 
12
12
  ## auth.user()
@@ -18,13 +18,18 @@ const user = await canopy.auth.user();
18
18
  // { id: "…", email: "ada@monks.com", name: "Ada Lovelace", kind: "monk", roles: ["user"] }
19
19
  ```
20
20
 
21
- | Field | Type | Meaning |
22
- | ------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
23
- | `id` | `string` | Stable id — safe to key user data on, except for a client-password visitor (see below). |
24
- | `email` | `string` | The user's email address; empty for a client-password visitor. |
25
- | `name` | `string` | Display name. |
26
- | `kind` | `"monk" \| "external"` | `"monk"` = signed in through OneLogin; `"external"` = someone outside Monks, signed in by email or with the client password. |
27
- | `roles` | `string[]` | The project's [app roles](https://docs.canopy.website/guides/roles) this person has: the default role first, then their own. Empty when the project has none. |
21
+ | Field | Type | Meaning |
22
+ | ------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
23
+ | `id` | `string` | Stable id — safe to key user data on, except for a client-password visitor (see below). Empty for `"worker"`. |
24
+ | `email` | `string` | The user's email address; empty for a client-password visitor and for `"worker"`. |
25
+ | `name` | `string` | Display name. |
26
+ | `kind` | `"monk" \| "external" \| "worker"` | `"monk"` = signed in through OneLogin; `"external"` = someone outside Monks, signed in by email or with the client password; `"worker"` = your backend acting as the project (below). |
27
+ | `roles` | `string[]` | The project's [app roles](https://docs.canopy.website/guides/roles) this person has: the default role first, then their own. Empty when the project has none. |
28
+
29
+ `kind: "worker"` only comes back in a backend worker, when nobody's session
30
+ rides along: a scheduled run, or a call made with an
31
+ [access token](https://docs.canopy.website/guides/access-tokens). Use `env.CALLER` there to see who
32
+ called.
28
33
 
29
34
  `kind: "external"` is someone outside Monks: a person you
30
35
  [invited by email](https://docs.canopy.website/guides/outside-sign-in), who has their own email and an
@@ -48,20 +53,35 @@ if (user.kind === "external") {
48
53
 
49
54
  ### In a backend worker
50
55
 
51
- A worker route already knows who is calling, without asking: `env.CALLER`
52
- holds the same `id`, `email`, `name`, `kind` and `roles` that `auth.user()`
53
- returns, plus `agent`, which is `true` when an AI agent is acting for a Monk.
56
+ A worker route already knows who is calling, without asking. For a person,
57
+ `env.CALLER` holds the same `id`, `email`, `name`, `kind` and `roles` that
58
+ `auth.user()` returns in their browser, plus `agent`, which is `true` when an
59
+ AI agent is acting for a Monk, and `token`, the access token the call came
60
+ with. Its `kind` is one of:
61
+
62
+ | `kind` | Who called | Type |
63
+ | ------------ | --------------------------------------------------------------- | --------------------- |
64
+ | `"monk"` | a Monk, in a browser, through an agent or with a personal token | `CanopyCaller` |
65
+ | `"external"` | someone outside Monks, or a client-password visitor | `CanopyCaller` |
66
+ | `"key"` | a [project key](https://docs.canopy.website/guides/access-tokens) | `CanopyKeyCaller` |
67
+ | `"project"` | [another project's backend](https://docs.canopy.website/guides/calling-projects) | `CanopyProjectCaller` |
54
68
 
55
69
  ```ts
56
- import type { CanopyCaller } from "@mediamonks/canopy";
70
+ import type { CanopyEnvCaller } from "@mediamonks/canopy";
57
71
 
58
72
  app.get("/api/me", (c) => {
59
- const caller: CanopyCaller | null = c.env.CALLER;
73
+ const caller: CanopyEnvCaller | null = c.env.CALLER;
60
74
  if (!caller) return c.json({ error: "no caller" }, 400); // a scheduled run
61
75
  return c.json({ kind: caller.kind, name: caller.name });
62
76
  });
63
77
  ```
64
78
 
79
+ `CanopyEnvCaller` (from `@mediamonks/canopy` 0.0.19) is the union of the three
80
+ types; on an older SDK, write it as `CanopyCaller | CanopyKeyCaller | CanopyProjectCaller`.
81
+
82
+ > **Warning:** New kinds of caller can appear as Canopy grows. When you `switch` on `kind`, give it a `default`
83
+ > that refuses, so a caller your code doesn't know never gets in by accident.
84
+
65
85
  `env.CALLER` is `null` only when nobody called, such as during a scheduled
66
86
  run. `env.USER` is the Monk-only form: the signed-in Monk, or `null` for
67
87
  anyone outside Monks.
@@ -70,6 +90,33 @@ When another project's backend calls yours, `env.CALLER.kind` is `"project"`
70
90
  and it names that project and the visitor it acts for. See
71
91
  [Calling another project](https://docs.canopy.website/guides/calling-projects).
72
92
 
93
+ When software calls with an [access token](https://docs.canopy.website/guides/access-tokens),
94
+ `env.CALLER.token` describes it: its `id`, `name`, `kind` (`"personal"` or
95
+ `"project"`), the `scopes` it carries, and the `paths` and `methods` it is
96
+ limited to. On every other request it is `null`. A personal token's caller is
97
+ its person, as in their browser. A project key's caller has `kind: "key"`,
98
+ the key's `id` and `name`, and no roles, and `env.USER` is `null`. During a
99
+ token call, `auth.user()` answers as your project's own backend, not as the
100
+ token's person.
101
+
102
+ Check a scope with `requireScope`. It throws a `ScopeError` (with `status:
103
+ 403`) unless the caller has no token or the token carries the scope;
104
+ `hasScope` gives the same answer as a boolean:
105
+
106
+ ```ts
107
+ import { requireScope, ScopeError } from "@mediamonks/canopy";
108
+
109
+ app.post("/api/reports", (c) => {
110
+ try {
111
+ requireScope(c.env.CALLER, "reports:write");
112
+ } catch (err) {
113
+ if (err instanceof ScopeError) return c.json({ error: err.message }, 403);
114
+ throw err;
115
+ }
116
+ // …
117
+ });
118
+ ```
119
+
73
120
  A client-password visitor has no email address and is named `"Client"`. Its
74
121
  `id` changes with every password unlock, so don't key data on it that has to
75
122
  last. Someone outside Monks who [signed in by email](https://docs.canopy.website/guides/outside-sign-in)