@theholocron/cloudflare-client 1.19.0 → 1.20.0

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/README.md CHANGED
@@ -93,6 +93,31 @@ await cf.pages.updateProject(ACCOUNT, "my-docs-preview", {
93
93
  });
94
94
  ```
95
95
 
96
+ ## Usage — Workers
97
+
98
+ ```ts
99
+ const cf = createCloudflareClient({ token: process.env.CLOUDFLARE_API_TOKEN! });
100
+ const ACCOUNT = process.env.CLOUDFLARE_ACCOUNT_ID!;
101
+
102
+ // Deploy (or update) a Worker script
103
+ await cf.workers.putScript(ACCOUNT, "my-worker", "export default { fetch() { … } };");
104
+
105
+ // Set a secret — one call both stores the encrypted value and binds it as
106
+ // `env.MY_SECRET` in the Worker; values are write-only, never echoed back
107
+ await cf.workers.putSecret(ACCOUNT, "my-worker", "MY_SECRET", "shh");
108
+
109
+ // List secret names bound to a script (no values)
110
+ const secrets = await cf.workers.listSecrets(ACCOUNT, "my-worker");
111
+
112
+ // Remove a secret binding
113
+ await cf.workers.deleteSecret(ACCOUNT, "my-worker", "MY_SECRET");
114
+
115
+ // Route management — zone-scoped
116
+ const routes = await cf.workers.listRoutes("zone-id");
117
+ await cf.workers.createRoute("zone-id", "example.com/*", "my-worker");
118
+ await cf.workers.updateRoute("zone-id", routes[0].id, "example.com/*", "my-worker");
119
+ ```
120
+
96
121
  ## Auth
97
122
 
98
123
  Create an [API Token](https://dash.cloudflare.com/profile/api-tokens) with the permissions your use case requires:
@@ -102,6 +127,8 @@ Create an [API Token](https://dash.cloudflare.com/profile/api-tokens) with the p
102
127
  | DNS management | `Zone:Read`, `DNS:Edit` |
103
128
  | Tunnel management | `Account:Cloudflare Tunnel:Edit` |
104
129
  | Pages deployments | `Account:Cloudflare Pages:Edit` |
130
+ | Workers + secrets | `Account:Workers Scripts:Edit` |
131
+ | Worker routes | `Zone:Workers Routes:Edit` |
105
132
  | Token verification | `User:API Tokens:Read` |
106
133
 
107
134
  Pass the token directly or via the `CLOUDFLARE_API_TOKEN` environment variable.
package/dist/index.d.mts CHANGED
@@ -117,6 +117,11 @@ interface CfWorkerRoute {
117
117
  pattern: string;
118
118
  script: string | null;
119
119
  }
120
+ /** https://developers.cloudflare.com/api/operations/worker-script-put-encrypted-secret-binding */
121
+ interface CfWorkerSecret {
122
+ name: string;
123
+ type: "secret_text";
124
+ }
120
125
  //#endregion
121
126
  //#region src/index.d.ts
122
127
  declare function createCloudflareClient(opts: CloudflareClientOptions): {
@@ -169,8 +174,11 @@ declare function createCloudflareClient(opts: CloudflareClientOptions): {
169
174
  listRoutes: (zoneId: string) => Promise<CfWorkerRoute[]>;
170
175
  createRoute: (zoneId: string, pattern: string, script: string) => Promise<CfWorkerRoute>;
171
176
  updateRoute: (zoneId: string, routeId: string, pattern: string, script: string) => Promise<CfWorkerRoute>;
177
+ putSecret: (accountId: string, scriptName: string, name: string, value: string) => Promise<CfWorkerSecret>;
178
+ listSecrets: (accountId: string, scriptName: string) => Promise<CfWorkerSecret[]>;
179
+ deleteSecret: (accountId: string, scriptName: string, name: string) => Promise<void>;
172
180
  };
173
181
  };
174
182
  type CloudflareClient = ReturnType<typeof createCloudflareClient>;
175
183
  //#endregion
176
- export { type CfDnsRecord, type CfDnsRecordInput, type CfDnsRecordType, type CfEnvelope, type CfIngressRule, type CfPagesDeployment, type CfPagesDeploymentStage, type CfPagesDomain, type CfPagesEnvConfig, type CfPagesEnvVar, type CfPagesEnvVarType, type CfPagesProject, type CfPagesProjectInput, type CfTokenVerification, type CfTunnel, type CfTunnelConfig, type CfWorkerRoute, type CfZone, CloudflareClient, type CloudflareClientOptions, createCloudflareClient };
184
+ export { type CfDnsRecord, type CfDnsRecordInput, type CfDnsRecordType, type CfEnvelope, type CfIngressRule, type CfPagesDeployment, type CfPagesDeploymentStage, type CfPagesDomain, type CfPagesEnvConfig, type CfPagesEnvVar, type CfPagesEnvVarType, type CfPagesProject, type CfPagesProjectInput, type CfTokenVerification, type CfTunnel, type CfTunnelConfig, type CfWorkerRoute, type CfWorkerSecret, type CfZone, CloudflareClient, type CloudflareClientOptions, createCloudflareClient };
package/dist/index.mjs CHANGED
@@ -113,7 +113,14 @@ function workers(rest, opts) {
113
113
  updateRoute: (zoneId, routeId, pattern, script) => cfRequest(rest, "PUT", `/zones/${zoneId}/workers/routes/${routeId}`, {
114
114
  pattern,
115
115
  script
116
- })
116
+ }),
117
+ putSecret: (accountId, scriptName, name, value) => cfRequest(rest, "PUT", `/accounts/${accountId}/workers/scripts/${encodeURIComponent(scriptName)}/secrets`, {
118
+ name,
119
+ text: value,
120
+ type: "secret_text"
121
+ }),
122
+ listSecrets: (accountId, scriptName) => cfRequest(rest, "GET", `/accounts/${accountId}/workers/scripts/${encodeURIComponent(scriptName)}/secrets`),
123
+ deleteSecret: (accountId, scriptName, name) => cfRequest(rest, "DELETE", `/accounts/${accountId}/workers/scripts/${encodeURIComponent(scriptName)}/secrets/${encodeURIComponent(name)}`)
117
124
  };
118
125
  }
119
126
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/cloudflare-client",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "A TypeScript client for the Cloudflare API",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -33,7 +33,7 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@theholocron/observability": "^0.3.0",
36
- "@theholocron/http-client": "^1.19.0"
36
+ "@theholocron/http-client": "^1.20.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@theholocron/cli": "5.0.0-alpha.3",