@theholocron/cloudflare-client 1.12.0 → 1.13.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/dist/index.d.mts CHANGED
@@ -106,6 +106,13 @@ interface CfTokenVerification {
106
106
  status: "active" | "disabled" | "expired";
107
107
  }
108
108
  //#endregion
109
+ //#region src/workers/workers.d.ts
110
+ interface CfWorkerRoute {
111
+ id: string;
112
+ pattern: string;
113
+ script: string | null;
114
+ }
115
+ //#endregion
109
116
  //#region src/index.d.ts
110
117
  declare function createCloudflareClient(opts: CloudflareClientOptions): {
111
118
  dns: {
@@ -152,7 +159,13 @@ declare function createCloudflareClient(opts: CloudflareClientOptions): {
152
159
  tokens: {
153
160
  verify: () => Promise<CfTokenVerification>;
154
161
  };
162
+ workers: {
163
+ putScript: (accountId: string, scriptName: string, script: string) => Promise<void>;
164
+ listRoutes: (zoneId: string) => Promise<CfWorkerRoute[]>;
165
+ createRoute: (zoneId: string, pattern: string, script: string) => Promise<CfWorkerRoute>;
166
+ updateRoute: (zoneId: string, routeId: string, pattern: string, script: string) => Promise<CfWorkerRoute>;
167
+ };
155
168
  };
156
169
  type CloudflareClient = ReturnType<typeof createCloudflareClient>;
157
170
  //#endregion
158
- 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 CfZone, CloudflareClient, type CloudflareClientOptions, createCloudflareClient };
171
+ 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 };
package/dist/index.mjs CHANGED
@@ -80,6 +80,41 @@ function tunnels(rest) {
80
80
  };
81
81
  }
82
82
  //#endregion
83
+ //#region src/workers/workers.ts
84
+ function workers(rest, opts) {
85
+ const baseUrl = opts.baseUrl ?? "https://api.cloudflare.com/client/v4";
86
+ const fetchImpl = opts.fetch ?? globalThis.fetch;
87
+ return {
88
+ putScript: async (accountId, scriptName, script) => {
89
+ const form = new FormData();
90
+ form.append("metadata", new Blob([JSON.stringify({
91
+ main_module: "index.js",
92
+ compatibility_date: "2025-08-31"
93
+ })], { type: "application/json" }));
94
+ form.append("index.js", new Blob([script], { type: "application/javascript+module" }), "index.js");
95
+ const path = `/accounts/${accountId}/workers/scripts/${encodeURIComponent(scriptName)}`;
96
+ const res = await fetchImpl(`${baseUrl}${path}`, {
97
+ method: "PUT",
98
+ headers: { authorization: `Bearer ${opts.token}` },
99
+ body: form
100
+ });
101
+ if (!res.ok) {
102
+ const body = await res.text().catch(() => "");
103
+ throw new ProviderApiError(`Cloudflare PUT ${path} → ${res.status}`, res.status, body);
104
+ }
105
+ },
106
+ listRoutes: (zoneId) => cfRequest(rest, "GET", `/zones/${zoneId}/workers/routes`),
107
+ createRoute: (zoneId, pattern, script) => cfRequest(rest, "POST", `/zones/${zoneId}/workers/routes`, {
108
+ pattern,
109
+ script
110
+ }),
111
+ updateRoute: (zoneId, routeId, pattern, script) => cfRequest(rest, "PUT", `/zones/${zoneId}/workers/routes/${routeId}`, {
112
+ pattern,
113
+ script
114
+ })
115
+ };
116
+ }
117
+ //#endregion
83
118
  //#region src/zones/zones.ts
84
119
  function zones(rest) {
85
120
  return { list: (query) => cfRequest(rest, "GET", "/zones", void 0, {
@@ -96,7 +131,8 @@ function createCloudflareClient(opts) {
96
131
  pages: pages(rest),
97
132
  zones: zones(rest),
98
133
  tunnels: tunnels(rest),
99
- tokens: tokens(rest)
134
+ tokens: tokens(rest),
135
+ workers: workers(rest, opts)
100
136
  };
101
137
  }
102
138
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/cloudflare-client",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "A TypeScript client for the Cloudflare API",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -34,7 +34,7 @@
34
34
  "README.md"
35
35
  ],
36
36
  "dependencies": {
37
- "@theholocron/http-client": "^1.12.0"
37
+ "@theholocron/http-client": "^1.13.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@theholocron/eslint-config": "^7.23.1",