@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
@@ -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",
@@ -14,7 +14,7 @@ one person without touching anyone else.
14
14
 
15
15
  ## Inviting someone
16
16
 
17
- On the project's **Settings** tab, in the **Members** card, type the person's
17
+ On the project's **Settings → Access** page, in the **Members** card, type the person's
18
18
  full email address and add them. People outside Monks are always added as
19
19
  **viewers**: they can open the app and nothing that manages it. You can give
20
20
  them [app roles](https://docs.canopy.website/guides/roles) like anyone else.
@@ -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
 
@@ -28,7 +28,7 @@ The unlock is deliberately narrow:
28
28
 
29
29
  ## Enabling it
30
30
 
31
- Open the project's **Settings** tab and use the **Who outside Monks can open
31
+ Open the project's **Settings → Access** page and use the **Who outside Monks can open
32
32
  it** card:
33
33
 
34
34
  1. Set a password. Pick something you're comfortable saying out loud on a
@@ -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 on the
70
+ project's **Deploys** tab, 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.
@@ -26,7 +26,7 @@ canopy egress list
26
26
  canopy egress remove generativelanguage.googleapis.com
27
27
  ```
28
28
 
29
- Or in the dashboard: **Settings → Outbound hosts**.
29
+ Or in the dashboard: **Backend → Outbound hosts**.
30
30
 
31
31
  Changes apply to the **running** workers within moments — the platform re-rolls
32
32
  the project's services with the new list, no deploy needed. Live and staging
@@ -75,7 +75,7 @@ so an allowed name can't lead your worker into the platform's own network.
75
75
 
76
76
  You don't have to guess what got denied: the runtime reports every blocked
77
77
  host back to the platform, and they show up as **Recently blocked** in
78
- Settings → Outbound hosts (and in `canopy egress list`), with how often and
78
+ Backend → Outbound hosts (and in `canopy egress list`), with how often and
79
79
  how recently each was hit. One click on **Allow** puts the host on the list
80
80
  and clears it from the blocked section. Hosts that keep a low profile drop
81
81
  off — the list remembers the 50 most recent — and allowing a host removes its
@@ -92,7 +92,7 @@ growing the list forever, switch the project to **open egress mode**:
92
92
  canopy egress mode open
93
93
  ```
94
94
 
95
- or in the dashboard: **Settings → Outbound hosts → Egress mode**. In open mode
95
+ or in the dashboard: **Backend → Outbound hosts → Egress mode**. In open mode
96
96
  the worker may fetch **any public hostname**. Three guardrails replace the
97
97
  allowlist:
98
98
 
@@ -206,7 +206,7 @@ addresses. There the setting shows as always on and there is nothing to set.
206
206
  In both modes, the platform keeps a per-project log of the hosts the worker
207
207
  **actually fetched** — hostnames only, never paths, query strings, headers, or
208
208
  bodies. Per host it tracks a fetch count and first/last seen. See it under
209
- **Outbound traffic** in Settings → Outbound hosts, or:
209
+ **Outbound traffic** in Backend → Outbound hosts, or:
210
210
 
211
211
  ```bash
212
212
  canopy egress log
@@ -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:
@@ -10,12 +10,12 @@ platform wakes your project's backend at the right times; your code only
10
10
  decides what each job does.
11
11
 
12
12
  > **Note:** Schedules need a project with a custom backend. Per-project backends run on the **main** site and
13
- > the **GCP pilot** site. On sites without backend support the Schedules section doesn't appear in
14
- > Settings, and the API answers `not_supported_on_target`.
13
+ > the **GCP pilot** site. On sites without backend support the Schedules section doesn't appear on
14
+ > the Backend tab, and the API answers `not_supported_on_target`.
15
15
 
16
16
  ## Defining a schedule
17
17
 
18
- In the dashboard, open the project's **Settings → Schedules**. Each schedule
18
+ In the dashboard, open the project's **Backend → Schedules**. Each schedule
19
19
  has:
20
20
 
21
21
  - a **name** (like `daily-digest`) — this is what your code switches on;
@@ -119,6 +119,6 @@ What happens around a run:
119
119
  `kind: "worker"` and no identity.
120
120
  - **All times are UTC.** `0 6 * * *` is 6:00 UTC, not local time.
121
121
  - **Failures are visible.** A run that throws records its error on the
122
- schedule row in Settings, so silent breakage doesn't stay silent.
122
+ schedule row on the Backend tab, so silent breakage doesn't stay silent.
123
123
 
124
124
  - [How the platform serves your project](https://docs.canopy.website/developers/architecture) — Where your backend runs, and what it can reach — the same environment a scheduled run gets.
@@ -62,24 +62,24 @@ together as a single version, with rollback.
62
62
  List everything in the app that runs on the server. Each item lands in one of
63
63
  three buckets:
64
64
 
65
- | Next.js feature | Where it goes on Canopy |
66
- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------- |
67
- | Pages, layouts, client components | Static build (unchanged in spirit) |
68
- | Server components fetching data at request time | Client-side fetching, or a worker endpoint |
69
- | Route handlers (`app/api/*/route.ts`) | Worker endpoints under `/api/*` |
70
- | Server actions | Explicit worker endpoints, called with `fetch` from the client |
71
- | Middleware | Usually deleted (auth is platform-provided); anything else moves into the worker |
72
- | NextAuth / auth middleware | Deleted — use `canopy.auth.user()` (client) or `env.CALLER` (worker) |
73
- | Database (Prisma, Postgres, …) | `canopy.db` — per-project database, document API + SQL escape hatch |
74
- | File uploads (S3, …) | `canopy.blob` — per-project file storage with signed downloads |
75
- | AI SDK / OpenAI client | `canopy.ai.chat()`, or point the Vercel AI SDK at `canopy.ai.endpoint()` |
76
- | `NEXT_PUBLIC_*` env vars | Build-time env vars in your CI — the platform doesn't inject build config |
77
- | Server-side env vars / secrets | Project secrets (`canopy secrets set` or dashboard Settings) — injected into the worker's `env` |
78
- | Cron (`vercel.json` crons) | [Schedules](https://docs.canopy.website/platform/schedules) — delivered to the worker's `scheduled()` |
79
- | ISR / `revalidate` / caching | Dropped — at internal-tool scale, fetch fresh or cache in the client |
80
- | `next/image` optimization | Plain `<img>`, or optimize at build time |
81
- | Custom domain | Not available — projects live at `<slug>.canopy.<domain>` behind sign-in |
82
- | Queues / background jobs | Not supported — restructure around request/response plus schedules |
65
+ | Next.js feature | Where it goes on Canopy |
66
+ | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
67
+ | Pages, layouts, client components | Static build (unchanged in spirit) |
68
+ | Server components fetching data at request time | Client-side fetching, or a worker endpoint |
69
+ | Route handlers (`app/api/*/route.ts`) | Worker endpoints under `/api/*` |
70
+ | Server actions | Explicit worker endpoints, called with `fetch` from the client |
71
+ | Middleware | Usually deleted (auth is platform-provided); anything else moves into the worker |
72
+ | NextAuth / auth middleware | Deleted — use `canopy.auth.user()` (client) or `env.CALLER` (worker) |
73
+ | Database (Prisma, Postgres, …) | `canopy.db` — per-project database, document API + SQL escape hatch |
74
+ | File uploads (S3, …) | `canopy.blob` — per-project file storage with signed downloads |
75
+ | AI SDK / OpenAI client | `canopy.ai.chat()`, or point the Vercel AI SDK at `canopy.ai.endpoint()` |
76
+ | `NEXT_PUBLIC_*` env vars | Build-time env vars in your CI — the platform doesn't inject build config |
77
+ | Server-side env vars / secrets | Project secrets (`canopy secrets set` or the dashboard's Backend tab) — injected into the worker's `env` |
78
+ | Cron (`vercel.json` crons) | [Schedules](https://docs.canopy.website/platform/schedules) — delivered to the worker's `scheduled()` |
79
+ | ISR / `revalidate` / caching | Dropped — at internal-tool scale, fetch fresh or cache in the client |
80
+ | `next/image` optimization | Plain `<img>`, or optimize at build time |
81
+ | Custom domain | Not available — projects live at `<slug>.canopy.<domain>` behind sign-in |
82
+ | Queues / background jobs | Not supported — restructure around request/response plus schedules |
83
83
 
84
84
  If the last two rows are deal-breakers, stop here: see
85
85
  [When not to port](#when-not-to-port).
@@ -126,7 +126,7 @@ type Env = {
126
126
  CALLER: CanopyCaller | null;
127
127
  /** The signed-in monk only; null for cron and client-password visitors. */
128
128
  USER: { sub: string; email: string; name: string } | null;
129
- /** Project secrets from dashboard Settings appear as plain keys. */
129
+ /** Project secrets from the dashboard's Backend tab appear as plain keys. */
130
130
  MY_API_KEY?: string;
131
131
  };
132
132
 
@@ -155,7 +155,7 @@ app.post("/api/submit", async (c) => {
155
155
 
156
156
  export default {
157
157
  fetch: app.fetch.bind(app),
158
- // was: vercel.json crons — configure in dashboard Settings → Schedules
158
+ // was: vercel.json crons — configure in dashboard Backend → Schedules
159
159
  async scheduled(event: { name: string }, env: Env) {
160
160
  if (event.name === "nightly-report") {
161
161
  // …
@@ -173,7 +173,7 @@ Rules of the road for the worker:
173
173
  - **Outbound requests are controlled.** Calls to external APIs pass through a
174
174
  per-project egress allowlist — deny-by-default, managed by you. Allow the
175
175
  hosts your worker calls with `canopy egress allow <host>` or in dashboard
176
- Settings → Outbound hosts (see [Outbound requests](https://docs.canopy.website/platform/egress)).
176
+ Backend → Outbound hosts (see [Outbound requests](https://docs.canopy.website/platform/egress)).
177
177
  - Frontend calls are plain `fetch("/api/…")` — same origin, the platform
178
178
  session cookie rides along automatically.
179
179
 
@@ -258,6 +258,6 @@ past greenhouse size (see [Use cases](https://docs.canopy.website/overview/use-c
258
258
  - [ ] Worker: route handlers + server actions → `/api/*` endpoints in `worker/index.ts`
259
259
  - [ ] Data: ORM → `canopy.db`; uploads → `canopy.blob`; AI clients → `canopy.ai`
260
260
  - [ ] Delete NextAuth/middleware; read identity from `canopy.auth.user()` / `env.CALLER`
261
- - [ ] Secrets via `canopy secrets set` (or dashboard Settings); `NEXT_PUBLIC_*` into your CI build
262
- - [ ] Crons into Settings → Schedules, handled in `scheduled()`
261
+ - [ ] Secrets via `canopy secrets set` (or dashboard Backend → Secrets); `NEXT_PUBLIC_*` into your CI build
262
+ - [ ] Crons into Backend → Schedules, handled in `scheduled()`
263
263
  - [ ] `canopy.json` with `build`, `dist`, `worker` — then `canopy deploy`
@@ -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)
@@ -15,12 +15,44 @@ await canopy.blob.put("notes.txt", "hello canopy", { contentType: "text/plain" }
15
15
  await canopy.blob.put("avatars/arjan.png", file); // a File/Blob carries its own type
16
16
  ```
17
17
 
18
- `data` can be a `Blob` (including a `File`), an `ArrayBuffer`, or a `string`.
18
+ `data` can be a `Blob` (including a `File`), an `ArrayBuffer`, a `string`, or a
19
+ `ReadableStream` together with its `size` in bytes.
19
20
  The content type is resolved in order: the explicit `options.contentType`, then
20
21
  the `Blob`'s own `type`, then `application/octet-stream`. Keys are plain
21
22
  strings — use `/`-separated segments (`avatars/arjan.png`) so related files
22
23
  share a prefix you can `list()` later. Putting to an existing key overwrites it.
23
24
 
25
+ In your backend, a stream lets you store a file without holding it in memory
26
+ first, such as a response you fetched:
27
+
28
+ ```ts title="worker/index.ts"
29
+ const res = await fetch(renderUrl);
30
+ await canopy.blob.put("renders/layer.tif", res.body!, {
31
+ size: Number(res.headers.get("content-length")),
32
+ contentType: "image/tiff",
33
+ });
34
+ ```
35
+
36
+ ### How big a file can be
37
+
38
+ | Site | One file | Uploaded from a browser |
39
+ | -------------------- | ---------------- | ----------------------- |
40
+ | `main` and `staging` | up to **200 MB** | up to **100 MB** |
41
+ | `gcp-pilot` | up to **25 MB** | up to **25 MB** |
42
+
43
+ A browser upload (a page calling `put`, or a page using an
44
+ [upload link](#upload-links)) passes through the site's front door, which
45
+ stops at 100 MB. Your backend's own `put` doesn't, so for a file between 100
46
+ and 200 MB, upload it from the backend. Anything above the limit is refused
47
+ with `blob_too_large` (413), which tells you the limit in `maxBytes`, and
48
+ nothing is stored.
49
+
50
+ Files over 25 MB need two things: the upload must say how big it is (a `Blob`,
51
+ `File`, `ArrayBuffer` or `string` always does; a stream needs `size`), and the
52
+ project must have been
53
+ deployed since large files arrived. An older deploy answers `runtime_outdated`
54
+ (503) for big files until you redeploy; smaller files keep working.
55
+
24
56
  Every upload (and every `list` entry) is described by a `BlobObject`:
25
57
 
26
58
  | Field | Type | Meaning |
@@ -79,6 +111,86 @@ const avatars = await canopy.blob.list("avatars/");
79
111
  await canopy.blob.delete("notes.txt");
80
112
  ```
81
113
 
114
+ ## Upload links
115
+
116
+ ```ts
117
+ // uploadUrl(key, options?) → Promise<{ url: string; method: "PUT"; expiresAt: string }>
118
+ const link = await canopy.blob.uploadUrl("uploads/cv.pdf", {
119
+ contentType: "application/pdf", // the only type the upload may carry
120
+ maxBytes: 5_000_000, // the largest file it accepts
121
+ });
122
+ ```
123
+
124
+ An upload link lets someone else upload one file to one key, straight to your
125
+ project's storage, without signing in. Your backend usually makes it and hands
126
+ it to a page, so the backend decides what may be uploaded and where, while the
127
+ file itself never passes through it. Send a `PUT` of the file's bytes to `url`:
128
+
129
+ ```ts
130
+ await fetch(link.url, { method: "PUT", body: file, headers: { "content-type": file.type } });
131
+ ```
132
+
133
+ What a link allows is fixed when it's made:
134
+
135
+ - `expiresIn` — seconds until it stops working. 10 minutes unless you ask
136
+ otherwise, at most an hour.
137
+ - `maxBytes` — the largest upload it accepts, at most the site's
138
+ [file limit](#how-big-a-file-can-be).
139
+ - `contentType` — when set, only that type is accepted.
140
+ - `overwrite` — `false` (the default) means the link only creates the file:
141
+ once something is stored under the key, another upload gets `409
142
+ blob_exists`, so the link works once. Set `true` to let it replace an
143
+ existing file, as often as it's used until it expires.
144
+
145
+ A refused upload answers with an error code: `invalid_upload_link` (wrong key,
146
+ or a link that was changed), `upload_link_expired`, `blob_too_large` (413) or
147
+ `content_type_mismatch` (415). An upload through a link works at every
148
+ [browser access](#who-can-call-this-from-the-browser) level, so it pairs well
149
+ with **Read only** or **Off**: pages can't upload on their own, only where
150
+ your backend lets them. Making a link counts as an upload, so at those levels
151
+ only your backend can make one. Anyone holding a link can use it until it
152
+ expires, so keep it short-lived and give it to one person.
153
+
154
+ ### Example: your backend decides, the page uploads
155
+
156
+ ```ts title="worker/index.ts"
157
+ // The page asks for a link; the backend checks who is asking.
158
+ app.post("/api/sow-upload", async (c) => {
159
+ const canopy = createCanopy({ fetch: c.env.CANOPY.fetch.bind(c.env.CANOPY) });
160
+ const caller = c.env.CALLER;
161
+ if (!caller?.roles.includes("approver")) return c.json({ error: "forbidden" }, 403);
162
+ const key = `sow/${crypto.randomUUID()}.pdf`;
163
+ const link = await canopy.blob.uploadUrl(key, {
164
+ contentType: "application/pdf",
165
+ maxBytes: 10_000_000,
166
+ });
167
+ // Remember the key, so only links this backend made can be confirmed.
168
+ await canopy.db.collection("sows").insert({ key, by: caller.id, status: "uploading" });
169
+ return c.json({ key, url: link.url });
170
+ });
171
+
172
+ // Once the upload is done, the page says so and the backend records it.
173
+ app.post("/api/sow-uploaded", async (c) => {
174
+ const canopy = createCanopy({ fetch: c.env.CANOPY.fetch.bind(c.env.CANOPY) });
175
+ const { key } = await c.req.json<{ key: string }>();
176
+ const [sow] = await canopy.db.collection("sows").find({ where: { key, status: "uploading" } });
177
+ if (!sow) return c.json({ error: "unknown_upload" }, 404);
178
+ const file = await canopy.blob.get(key);
179
+ if (!file) return c.json({ error: "not_uploaded" }, 409);
180
+ await canopy.db.collection("sows").update(sow._id, { size: file.size, status: "review" });
181
+ return c.json({ ok: true });
182
+ });
183
+ ```
184
+
185
+ ```ts title="src/upload.ts"
186
+ const { key, url } = await (await fetch("/api/sow-upload", { method: "POST" })).json();
187
+ await fetch(url, { method: "PUT", body: file, headers: { "content-type": "application/pdf" } });
188
+ await fetch("/api/sow-uploaded", { method: "POST", body: JSON.stringify({ key }) });
189
+ ```
190
+
191
+ The platform doesn't tell your backend when an upload lands, which is why the
192
+ page reports back and the backend checks the file before trusting it.
193
+
82
194
  ## Who can call this from the browser
83
195
 
84
196
  Everything above works from a page as well as from your worker, so an upload
@@ -90,7 +202,8 @@ dashboard (or with [`canopy files access`](https://docs.canopy.website/cli/files
90
202
  do everything on this page.
91
203
  - **Read only** lets pages list and download files and make download links
92
204
  with `getUrl()`. `put()` and `delete()` from a page are refused, so changes
93
- have to come from the worker.
205
+ have to come from the worker, or through an [upload link](#upload-links) it
206
+ hands out.
94
207
  - **Off** means pages cannot touch files at all.
95
208
 
96
209
  This is separate from the database's [browser access](https://docs.canopy.website/sdk/database#who-can-call-this-from-the-browser),
@@ -126,5 +239,5 @@ async function onFileChange(event: React.ChangeEvent<HTMLInputElement>) {
126
239
  <input type="file" accept="image/*" onChange={onFileChange} />;
127
240
  ```
128
241
 
129
- Storage location and limits are covered in
130
- [Project data](https://docs.canopy.website/platform/project-data).
242
+ File size limits are [above](#how-big-a-file-can-be); the Files tab and
243
+ browser access are covered in [Project data](https://docs.canopy.website/platform/project-data).