@mediamonks/canopy-cli 0.7.50 → 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.
- package/dist/{dev-BQ77vmCk.mjs → dev-BnzJ8a1u.mjs} +5 -4
- package/dist/dev-DSI3e4qP.mjs +2 -0
- package/dist/{dev-worker-BP-HGHYb.mjs → dev-worker-DBBN0F6X.mjs} +15 -33
- package/dist/docs/access-tokens.md +145 -0
- package/dist/docs/calling-projects.md +9 -0
- package/dist/docs/ci.md +8 -0
- package/dist/docs/cli-dev.md +1 -1
- package/dist/docs/cli-files.md +57 -0
- package/dist/docs/cli.md +2 -0
- package/dist/docs/developers-architecture.md +20 -4
- package/dist/docs/index.json +20 -0
- package/dist/docs/outside-sign-in.md +79 -0
- package/dist/docs/overview-faq.md +4 -3
- package/dist/docs/platform-client-access.md +6 -0
- package/dist/docs/platform-credentials.md +76 -0
- package/dist/docs/platform-members-and-access.md +31 -6
- package/dist/docs/platform-project-data.md +11 -1
- package/dist/docs/sdk-auth.md +71 -21
- package/dist/docs/sdk-files.md +148 -3
- package/dist/docs/sdk-projects.md +2 -1
- package/dist/docs/sdk.md +17 -10
- package/dist/docs/staging.md +8 -0
- package/dist/docs/troubleshooting.md +20 -0
- package/dist/{docs-Cd6VzYts.mjs → docs-Od4duFhd.mjs} +1 -1
- package/dist/{feedback-BkrdL92o.mjs → feedback-XEIHbeor.mjs} +1 -1
- package/dist/files-B7toJRlj.mjs +69 -0
- package/dist/index.mjs +14 -12
- package/dist/{local-C6ggy2PQ.mjs → local-R-INkPbU.mjs} +17 -6
- package/dist/{mcp-Bt9Z9kdf.mjs → mcp-misDO7O8.mjs} +1 -1
- package/dist/{package-Sir3152_.mjs → package-DBdEKZ6u.mjs} +1 -1
- package/dist/{project-template-DHWdVc6E.mjs → project-template-Bas1UN2O.mjs} +1 -0
- package/dist/project-template-Dti_Mmnb.mjs +2 -0
- package/dist/{projects-Z8ufQIBc.mjs → projects-BEBYhy6k.mjs} +1 -1
- package/dist/skill/canopy/SKILL.md +9 -1
- package/dist/{skill-Bxc5E-wu.mjs → skill-3RZw4vSI.mjs} +1 -1
- package/dist/{src-DzU89gZN.mjs → src-UBUAqzqH.mjs} +442 -43
- package/dist/templates/worker/worker/index.ts +4 -0
- package/dist/{upgrade-DOpeMSWD.mjs → upgrade-Dy4XV7iP.mjs} +1 -1
- package/package.json +2 -2
- package/dist/dev-Z3bI5hgh.mjs +0 -2
- package/dist/project-template-ChFb7A_H.mjs +0 -2
|
@@ -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
|
|
158
|
-
CLI sign-in
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
|
@@ -31,7 +31,17 @@ by design. The explorer is fixed to the channel (live or staging) you opened
|
|
|
31
31
|
it from; to look at the other one, go back to the Data tab and switch there.
|
|
32
32
|
|
|
33
33
|
The **Files** tab next to it lists the project's blob storage — the uploads
|
|
34
|
-
and files your app has saved.
|
|
34
|
+
and files your app has saved. Its **Browser access** card sets what the app's
|
|
35
|
+
own pages may do with those files: upload and delete (the default), read only,
|
|
36
|
+
or off. Your worker and this dashboard always keep full access, and download
|
|
37
|
+
links the worker makes keep working at every level. It is separate from the
|
|
38
|
+
Data tab's browser access for the database; see
|
|
39
|
+
[Files](https://docs.canopy.website/sdk/files#who-can-call-this-from-the-browser) for how pages and the
|
|
40
|
+
worker split the work.
|
|
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).
|
|
35
45
|
|
|
36
46
|
## Snapshots and restores
|
|
37
47
|
|
package/dist/docs/sdk-auth.md
CHANGED
|
@@ -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
|
|
9
|
-
|
|
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,17 +18,24 @@ 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
|
|
22
|
-
| ------- |
|
|
23
|
-
| `id` | `string`
|
|
24
|
-
| `email` | `string`
|
|
25
|
-
| `name` | `string`
|
|
26
|
-
| `kind` | `"monk" \| "external"` | `"monk"` = signed in through OneLogin; `"external"` =
|
|
27
|
-
| `roles` | `string[]`
|
|
28
|
-
|
|
29
|
-
`kind: "
|
|
30
|
-
|
|
31
|
-
|
|
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.
|
|
33
|
+
|
|
34
|
+
`kind: "external"` is someone outside Monks: a person you
|
|
35
|
+
[invited by email](https://docs.canopy.website/guides/outside-sign-in), who has their own email and an
|
|
36
|
+
`id` that stays the same every time they sign in, or a visitor who got in with
|
|
37
|
+
the project's [client password](https://docs.canopy.website/platform/client-access). Branch on it when
|
|
38
|
+
externals should see a trimmed-down experience:
|
|
32
39
|
|
|
33
40
|
```ts
|
|
34
41
|
const user = await canopy.auth.user();
|
|
@@ -46,31 +53,74 @@ if (user.kind === "external") {
|
|
|
46
53
|
|
|
47
54
|
### In a backend worker
|
|
48
55
|
|
|
49
|
-
A worker route already knows who is calling, without asking
|
|
50
|
-
holds the same `id`, `email`, `name`, `kind` and `roles` that
|
|
51
|
-
returns, plus `agent`, which is `true` when an
|
|
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` |
|
|
52
68
|
|
|
53
69
|
```ts
|
|
54
|
-
import type {
|
|
70
|
+
import type { CanopyEnvCaller } from "@mediamonks/canopy";
|
|
55
71
|
|
|
56
72
|
app.get("/api/me", (c) => {
|
|
57
|
-
const caller:
|
|
73
|
+
const caller: CanopyEnvCaller | null = c.env.CALLER;
|
|
58
74
|
if (!caller) return c.json({ error: "no caller" }, 400); // a scheduled run
|
|
59
75
|
return c.json({ kind: caller.kind, name: caller.name });
|
|
60
76
|
});
|
|
61
77
|
```
|
|
62
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
|
+
|
|
63
85
|
`env.CALLER` is `null` only when nobody called, such as during a scheduled
|
|
64
|
-
run. `env.USER` is the Monk-only form: the signed-in Monk, or `null` for
|
|
65
|
-
|
|
86
|
+
run. `env.USER` is the Monk-only form: the signed-in Monk, or `null` for
|
|
87
|
+
anyone outside Monks.
|
|
66
88
|
|
|
67
89
|
When another project's backend calls yours, `env.CALLER.kind` is `"project"`
|
|
68
90
|
and it names that project and the visitor it acts for. See
|
|
69
91
|
[Calling another project](https://docs.canopy.website/guides/calling-projects).
|
|
70
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
|
+
|
|
71
120
|
A client-password visitor has no email address and is named `"Client"`. Its
|
|
72
121
|
`id` changes with every password unlock, so don't key data on it that has to
|
|
73
|
-
last.
|
|
122
|
+
last. Someone outside Monks who [signed in by email](https://docs.canopy.website/guides/outside-sign-in)
|
|
123
|
+
carries their email, the name they gave, and an `id` that stays the same.
|
|
74
124
|
|
|
75
125
|
This is the place to check app roles, because a visitor can't change what
|
|
76
126
|
your worker sees:
|
package/dist/docs/sdk-files.md
CHANGED
|
@@ -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`,
|
|
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,119 @@ 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
|
+
|
|
194
|
+
## Who can call this from the browser
|
|
195
|
+
|
|
196
|
+
Everything above works from a page as well as from your worker, so an upload
|
|
197
|
+
form needs no backend at all. Once your worker manages files that pages must
|
|
198
|
+
not change, set **Browser access** on the project's **Files** tab in the
|
|
199
|
+
dashboard (or with [`canopy files access`](https://docs.canopy.website/cli/files)):
|
|
200
|
+
|
|
201
|
+
- **Upload and delete** is the default and how every project starts. Pages can
|
|
202
|
+
do everything on this page.
|
|
203
|
+
- **Read only** lets pages list and download files and make download links
|
|
204
|
+
with `getUrl()`. `put()` and `delete()` from a page are refused, so changes
|
|
205
|
+
have to come from the worker, or through an [upload link](#upload-links) it
|
|
206
|
+
hands out.
|
|
207
|
+
- **Off** means pages cannot touch files at all.
|
|
208
|
+
|
|
209
|
+
This is separate from the database's [browser access](https://docs.canopy.website/sdk/database#who-can-call-this-from-the-browser),
|
|
210
|
+
so you can lock one and not the other. Your worker, the CLI and the
|
|
211
|
+
dashboard's Files tab keep full access whatever you pick, and so does plain
|
|
212
|
+
`canopy dev`, where your browser shares the dev server's token.
|
|
213
|
+
|
|
214
|
+
Download links keep working at every level, because the link itself is the
|
|
215
|
+
permission. That makes **Off** workable for files a page should still show:
|
|
216
|
+
the page asks a worker route, the worker decides whether this visitor may see
|
|
217
|
+
the file, and answers with a short-lived link from `getUrl()`.
|
|
218
|
+
|
|
219
|
+
Everyone who opens the app gets the same rule: colleagues signed in with
|
|
220
|
+
OneLogin and, if you turned on [client access](https://docs.canopy.website/platform/client-access),
|
|
221
|
+
visitors with the password. Read only protects your files from being changed,
|
|
222
|
+
not from being seen.
|
|
223
|
+
|
|
224
|
+
A refused call throws a `CanopyError` with status 403, `code`
|
|
225
|
+
`browser_blob_access` and a one-line explanation that names the setting.
|
|
226
|
+
|
|
82
227
|
## Example: upload from a file input
|
|
83
228
|
|
|
84
229
|
```tsx
|
|
@@ -94,5 +239,5 @@ async function onFileChange(event: React.ChangeEvent<HTMLInputElement>) {
|
|
|
94
239
|
<input type="file" accept="image/*" onChange={onFileChange} />;
|
|
95
240
|
```
|
|
96
241
|
|
|
97
|
-
|
|
98
|
-
[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).
|
|
@@ -39,7 +39,8 @@ await canopy.projects.fetch("asset-library", "/api/assets", {
|
|
|
39
39
|
- `path` — a path under its `/api`, with a query string if you need one.
|
|
40
40
|
Anything else is refused before it is sent.
|
|
41
41
|
- `init` — optional. The usual fetch options (`method`, `headers`, `body`, …)
|
|
42
|
-
plus `channel`: `"live"` (the default) or `"staging"`.
|
|
42
|
+
plus `channel`: `"live"` (the default) or `"staging"`. Pass
|
|
43
|
+
`env.CANOPY_CHANNEL` to call the same channel your backend runs on.
|
|
43
44
|
|
|
44
45
|
**Returns** a `Response`: the other project's answer as it is. It doesn't
|
|
45
46
|
throw on an error status, so check `res.ok` like any fetch.
|
package/dist/docs/sdk.md
CHANGED
|
@@ -40,11 +40,11 @@ const canopy = createCanopy();
|
|
|
40
40
|
// canopy.services
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
| Option | Type | Default | What it does
|
|
44
|
-
| --------- | -------------- | -------------- |
|
|
45
|
-
| `baseUrl` | `string` | `"/_api"` | Base URL of the platform data API. The default is same-origin, so it works untouched in the browser.
|
|
46
|
-
| `token` | `string` | none | A
|
|
47
|
-
| `fetch` | `typeof fetch` | global `fetch` | Override how requests are sent — a backend worker passes its platform service binding here.
|
|
43
|
+
| Option | Type | Default | What it does |
|
|
44
|
+
| --------- | -------------- | -------------- | ---------------------------------------------------------------------------------------------------------------- |
|
|
45
|
+
| `baseUrl` | `string` | `"/_api"` | Base URL of the platform data API. The default is same-origin, so it works untouched in the browser. |
|
|
46
|
+
| `token` | `string` | none | A dev token sent as a bearer on every request — for a local script that reads the project's data while you work. |
|
|
47
|
+
| `fetch` | `typeof fetch` | global `fetch` | Override how requests are sent — a backend worker passes its platform service binding here. |
|
|
48
48
|
|
|
49
49
|
In the browser no config is needed. In a backend worker (the `worker`
|
|
50
50
|
template), the platform is reachable through the `CANOPY` service binding, so
|
|
@@ -58,18 +58,25 @@ app.get("/api/hello", async (c) => {
|
|
|
58
58
|
});
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
`
|
|
64
|
-
API
|
|
61
|
+
A local Node script has no session and no service binding. While you work,
|
|
62
|
+
it can use a dev token: `canopy dev` mints one for you (it lasts 12 hours and
|
|
63
|
+
needs your `canopy login`), or an editor can mint one with
|
|
64
|
+
`POST /control/v1/projects/:slug/dev-token`. Pass it with the platform's API
|
|
65
|
+
host:
|
|
65
66
|
|
|
66
67
|
```ts
|
|
67
68
|
const canopy = createCanopy({
|
|
68
69
|
baseUrl: "https://api.canopy.website",
|
|
69
|
-
token: process.env.
|
|
70
|
+
token: process.env.CANOPY_DEV_TOKEN, // a dev token, valid for 12 hours
|
|
70
71
|
});
|
|
71
72
|
```
|
|
72
73
|
|
|
74
|
+
A dev token isn't for CI or anything that runs unattended. To let a CI job,
|
|
75
|
+
script or app reach your project, give it a
|
|
76
|
+
[project key or personal token](https://docs.canopy.website/guides/access-tokens) and have it call your
|
|
77
|
+
project's own `/api` routes. Access tokens only work there, so don't pass one
|
|
78
|
+
to `createCanopy`.
|
|
79
|
+
|
|
73
80
|
## One instance, shared
|
|
74
81
|
|
|
75
82
|
In the browser, create the client once and import it everywhere. The scaffolds
|
package/dist/docs/staging.md
CHANGED
|
@@ -78,6 +78,14 @@ Shared with live: members, secrets, the client password, schedules (they run
|
|
|
78
78
|
against live only), and the AI budget — staging traffic counts against the
|
|
79
79
|
same cap.
|
|
80
80
|
|
|
81
|
+
## Knowing which channel you're on
|
|
82
|
+
|
|
83
|
+
Your backend can tell which channel it runs on: `env.CANOPY_CHANNEL` is
|
|
84
|
+
`"live"` or `"staging"`. Use it for a staging banner, or to keep a staged
|
|
85
|
+
backend away from live data in other projects it calls (see
|
|
86
|
+
[Calling other projects](https://docs.canopy.website/guides/calling-projects)). Under `canopy dev` it is
|
|
87
|
+
`"staging"` with `--staging` and `"live"` otherwise.
|
|
88
|
+
|
|
81
89
|
## Developing against staging data
|
|
82
90
|
|
|
83
91
|
Remote dev can point at the staging database instead of live — useful while a
|
|
@@ -45,6 +45,26 @@ Run it on your own laptop.
|
|
|
45
45
|
The `CANOPY_DEPLOY_TOKEN` was revoked or is wrong. Create a new one with
|
|
46
46
|
`canopy token create` (or in the dashboard) and update your CI secret.
|
|
47
47
|
|
|
48
|
+
## `token_invalid`, `token_expired`, `token_access_lost` (401)
|
|
49
|
+
|
|
50
|
+
An access token was refused on a project's `/api`. `token_invalid` means it's
|
|
51
|
+
unknown, revoked, or made for another project or channel; `token_expired`
|
|
52
|
+
means it's past its date, or a project key went 90 days without a call;
|
|
53
|
+
`token_access_lost` means its person lost access to the project or hasn't
|
|
54
|
+
signed in to Canopy for 30 days (signing in again fixes it). The full list is
|
|
55
|
+
in [Calling from apps and scripts](https://docs.canopy.website/guides/access-tokens#3-call-the-project).
|
|
56
|
+
|
|
57
|
+
## `token_disabled` (401)
|
|
58
|
+
|
|
59
|
+
The project's owner turned access tokens off under **Settings → Access**.
|
|
60
|
+
Turning them back on revives every token that hasn't expired.
|
|
61
|
+
|
|
62
|
+
## `credential_out_of_scope` (403)
|
|
63
|
+
|
|
64
|
+
A credential reached past what it may do: a deploy token outside its own
|
|
65
|
+
project's deploys, or a dev token on another project. See
|
|
66
|
+
[Which credential do I need?](https://docs.canopy.website/platform/credentials).
|
|
67
|
+
|
|
48
68
|
## `not_supported_on_target` (501)
|
|
49
69
|
|
|
50
70
|
Some features are platform-target-specific: a site whose platform target
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as version } from "./package-
|
|
1
|
+
import { t as version } from "./package-DBdEKZ6u.mjs";
|
|
2
2
|
import { r as siteConfig } from "./site-BL5Ik-yj.mjs";
|
|
3
3
|
import { i as latestKnownVersion, r as compareSemver } from "./version-check-CcsA1QjI.mjs";
|
|
4
4
|
import { n as agentHeaders } from "./api-DmJrIsE7.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as version } from "./package-
|
|
1
|
+
import { t as version } from "./package-DBdEKZ6u.mjs";
|
|
2
2
|
import { c as projectDirArgs, d as resolveProject, h as tryResolveProject, m as tryReadCanopyJson, r as siteConfig } from "./site-BL5Ik-yj.mjs";
|
|
3
3
|
import { a as apiRequest, c as credentials, i as apiDownload, o as apiUpload, s as commonHeaders } from "./api-DmJrIsE7.mjs";
|
|
4
4
|
import { r as reportErrors, t as formatDateTime } from "./ui-Ddw4d2Nn.mjs";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { d as resolveProject, l as projectFlagArgs } from "./site-BL5Ik-yj.mjs";
|
|
2
|
+
import { a as apiRequest } from "./api-DmJrIsE7.mjs";
|
|
3
|
+
import { r as reportErrors } from "./ui-Ddw4d2Nn.mjs";
|
|
4
|
+
import { defineCommand } from "citty";
|
|
5
|
+
//#region src/files.ts
|
|
6
|
+
/**
|
|
7
|
+
* `canopy files` — the project's file storage (canopy.blob).
|
|
8
|
+
*
|
|
9
|
+
* access show or set what the app's pages may do with its files
|
|
10
|
+
* (OpenSpec browser-blob-access)
|
|
11
|
+
*/
|
|
12
|
+
const BLOB_LEVELS = [
|
|
13
|
+
"full",
|
|
14
|
+
"readonly",
|
|
15
|
+
"off"
|
|
16
|
+
];
|
|
17
|
+
const LEVEL_MEANING = {
|
|
18
|
+
full: "pages can list, download, upload and delete files",
|
|
19
|
+
readonly: "pages can list and download files and make download links; uploads and deletes are refused",
|
|
20
|
+
off: "pages cannot touch files — only the worker, the CLI and the download links the worker makes can"
|
|
21
|
+
};
|
|
22
|
+
/** The level as a word, or null for anything else (case and spaces forgiven). */
|
|
23
|
+
function parseLevel(raw) {
|
|
24
|
+
const wanted = raw.trim().toLowerCase();
|
|
25
|
+
return BLOB_LEVELS.includes(wanted) ? wanted : null;
|
|
26
|
+
}
|
|
27
|
+
function describeAccess(slug, access) {
|
|
28
|
+
const lines = [`${slug}: browser file access is ${access.level} — ${LEVEL_MEANING[access.level]}.`];
|
|
29
|
+
if (access.clientAccess && access.level !== "off") lines.push("", ` ! Client access is on: visitors who know the password can ${access.level === "full" ? "download, upload and delete" : "download"} these files from their browser.`, " Move writes into the worker and run `canopy files access off` to keep them worker-only.");
|
|
30
|
+
return lines;
|
|
31
|
+
}
|
|
32
|
+
const filesCommand = defineCommand({
|
|
33
|
+
meta: {
|
|
34
|
+
name: "files",
|
|
35
|
+
description: "File storage tools: access"
|
|
36
|
+
},
|
|
37
|
+
subCommands: { access: defineCommand({
|
|
38
|
+
meta: {
|
|
39
|
+
name: "access",
|
|
40
|
+
description: "Show or set what the app's own pages may do with its files (full | readonly | off)"
|
|
41
|
+
},
|
|
42
|
+
args: {
|
|
43
|
+
...projectFlagArgs,
|
|
44
|
+
level: {
|
|
45
|
+
type: "positional",
|
|
46
|
+
description: "full | readonly | off (omit to show)",
|
|
47
|
+
required: false
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
run: reportErrors("files access", async ({ args }) => {
|
|
51
|
+
const { slug } = resolveProject(args);
|
|
52
|
+
const print = (access) => {
|
|
53
|
+
for (const line of describeAccess(slug, access)) console.log(line);
|
|
54
|
+
};
|
|
55
|
+
if (!args.level?.trim()) {
|
|
56
|
+
print(await apiRequest("GET", `/projects/${slug}/blob-access`));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const level = parseLevel(args.level);
|
|
60
|
+
if (!level) {
|
|
61
|
+
console.error(`unknown level "${args.level.trim()}" — expected full, readonly or off.`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
print(await apiRequest("PUT", `/projects/${slug}/blob-access`, { level }));
|
|
65
|
+
})
|
|
66
|
+
}) }
|
|
67
|
+
});
|
|
68
|
+
//#endregion
|
|
69
|
+
export { filesCommand };
|