cloudcannon-sdk
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseThe CloudCannon SDK
CloudCannon SDK
@cloudcannon/sdkfetchReach for it when the work is programmatic. Reach for the CLI when the work is a shell command.
@cloudcannon/sdkfetch当工作需要通过编程完成时,使用它;当工作是一项 shell 命令时,使用 CLI。
When to use
何时使用
- Calling the CloudCannon API from a script, a build step, or a service
- Operating over many sites or organisations in one pass
- Reaching a surface the CLI does not expose — DAMs, backups, sync history and pulls, site scans, screenshots, provider connect/disconnect, ,
site.copysite.delete - Handling API failures by type rather than by exit code
- Finding out which methods exist, and what they take
- 从脚本、构建步骤或服务调用 CloudCannon API
- 一次处理多个站点或组织
- 访问 CLI 未暴露的 API 功能——DAM、备份、同步历史和 pulls、站点扫描、截图、服务商连接/断开连接、、
site.copysite.delete - 按类型处理 API 故障,而不是依据退出代码
- 了解有哪些方法及其所需参数
When not to use
何时不应使用
- A one-off operation from a shell — that is . If a command already does the job, use it; it resolves site names, prints JSON, and needs no client wiring.
cloudcannon-cli - Running the site locally in CloudCannon — is covered end to end by
cloudcannon dev. The SDK has nothing to do with it.cloudcannon-dev-server - Deciding what belongs in — that is
cloudcannon.config.yml. The SDK reads and writes the file as bytes; it has no opinion on its contents.cloudcannon-configuration - Authoring editable regions or snippets — and
cloudcannon-visual-editing.cloudcannon-snippets
- 从 shell 执行一次性操作——应使用 。如果已有命令可以完成这项工作,就使用该命令;它会解析站点名称、输出 JSON,且无需配置客户端。
cloudcannon-cli - 在 CloudCannon 中本地运行站点——已完整涵盖
cloudcannon-dev-server。SDK 与此无关。cloudcannon dev - 决定 中应包含哪些内容——这属于
cloudcannon.config.yml。SDK 仅以字节形式读写该文件,并不评判其中的内容。cloudcannon-configuration - 编写可编辑区域或 snippets——请使用 和
cloudcannon-visual-editing。cloudcannon-snippets
The rule that costs the most
最需要谨慎的规则
MUST confirm with the user before any call that writes to a hosted site. This is the same rule the CLI carries, and the reason is the same — see § The rule that costs the most for the canonical statement.
cloudcannon-cliTwo things make it easier to break here than at the command line:
- There is no command name to read as a warning. is a method call with no arguments, no flag, and no confirmation prompt.
site.delete() - The SDK reaches destructive endpoints the CLI has no command for at all — ,
site.delete(),site.copy(),disconnectSourceProvider().disconnectOutputProvider()
The gate covers too. A through the escape hatch is a write.
client.fetchPOST调用任何会写入托管站点的接口之前,必须先向用户确认。 这与 CLI 遵循的是同一规则,原因也相同——标准表述见 § 最需要谨慎的规则。
cloudcannon-cli以下两点使其比在命令行中更容易违反这一规则:
- 没有命令名可以作为警告。是一次方法调用,没有参数、标志或确认提示。
site.delete() - SDK 可以访问 CLI 完全没有对应命令的破坏性端点——、
site.delete()、site.copy()、disconnectSourceProvider()。disconnectOutputProvider()
这一确认门槛也适用于 。通过该逃生通道发出的 同样属于写入操作。
client.fetchPOSTRequirements
环境要求
Node 20 or newer, per the package's field — lower than the CLI's Node 24. The package is ESM () and its default export is the client class.
engines"type": "module"js
import CloudCannonClient from "@cloudcannon/sdk";根据包的 字段,需要 Node 20 或更高版本——低于 CLI 要求的 Node 24。该包采用 ESM(),默认导出为客户端类。
engines"type": "module"js
import CloudCannonClient from "@cloudcannon/sdk";Quick start
快速入门
Sub-clients take a UUID and nothing else, so almost every task starts by finding one.
js
import CloudCannonClient from "@cloudcannon/sdk";
// The SDK reads no credentials of its own — you supply them.
const client = new CloudCannonClient({
userAccessKey: {
id: process.env.CC_ACCESS_KEY_ID,
secret: process.env.CC_ACCESS_KEY_SECRET,
},
});
const { items: orgs } = await client.orgs();
const { items: sites } = await client.org(orgs[0].uuid).sites({ filters: { search: "my-site" } });
const site = await client.site(sites[0].uuid).get();子客户端只接受 UUID,因此几乎每项任务都要先找到一个 UUID。
js
import CloudCannonClient from "@cloudcannon/sdk";
// SDK 不会读取任何凭据——需要由你提供。
const client = new CloudCannonClient({
userAccessKey: {
id: process.env.CC_ACCESS_KEY_ID,
secret: process.env.CC_ACCESS_KEY_SECRET,
},
});
const { items: orgs } = await client.orgs();
const { items: sites } = await client.org(orgs[0].uuid).sites({ filters: { search: "my-site" } });
const site = await client.site(sites[0].uuid).get();Contents
目录
| File | Covers |
|---|---|
| SKILL.md (this file) | Routing, the write gate, requirements |
| client.md | Constructing the client, the config shape, and why it reads no credentials itself |
| resources.md | The sub-client hierarchy, UUID addressing, pagination, return types |
| api-surface.md | Reading the authoritative method list, and the raw |
| editing-sessions.md | Writing files to a hosted site through the SDK |
| troubleshooting.md | Symptom → cause → fix |
| 文件 | 涵盖内容 |
|---|---|
| SKILL.md(本文件) | 路由、写入确认门槛、环境要求 |
| client.md | 构建客户端、配置结构,以及它为何不自行读取凭据 |
| resources.md | 子客户端层级、UUID 寻址、分页、返回类型 |
| api-surface.md | 查看权威方法列表,以及原始 |
| editing-sessions.md | 通过 SDK 将文件写入托管站点 |
| troubleshooting.md | 症状 → 原因 → 修复 |
Common mistakes
常见误区
| Excuse | Reality |
|---|---|
"I'll pass the site name to | Sub-clients take a UUID only. Resolve it first — resources.md § Addressing a resource. |
" | There is no such method. Sites are listed per organisation. See resources.md. |
"The SDK will pick up my | It reads nothing from disk or the environment. That chain is a CLI feature — client.md. |
| "I'll write out the method signatures from memory." | Signatures change between releases. Read them from the installed package — api-surface.md. |
" | It gives you a |
| "The list came back, so that's all of them." | Paginated endpoints return one page. Check |
" | The gate is about the endpoint, not the wrapper. A |
| 误区 | 实际情况 |
|---|---|
"我会把站点名称传给 | 子客户端只接受 UUID。请先解析它——resources.md § 资源寻址。 |
" | 不存在这样的方法。站点按组织列出。请参阅 resources.md。 |
"SDK 会读取我的 | 它不会从磁盘或环境变量中读取任何内容。这条凭据链是 CLI 的功能——client.md。 |
| "我会凭记忆写出方法签名。" | 方法签名会随版本发布而变化。请从已安装的包中读取——api-surface.md。 |
" | 它返回的是 |
| "列表已经返回,所以那就是全部。" | 分页端点只返回一页。请检查 |
" | 确认门槛针对的是端点,而不是封装方式。通过 |