@theholocron/cloudflare-client 1.11.2 → 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: {
@@ -126,6 +133,8 @@ declare function createCloudflareClient(opts: CloudflareClientOptions): {
126
133
  updateProject: (accountId: string, name: string, patch: Partial<Pick<CfPagesProject, "deployment_configs" | "production_branch">>) => Promise<CfPagesProject>;
127
134
  createDeployment: (accountId: string, projectName: string, branch: string) => Promise<CfPagesDeployment>;
128
135
  getDeployment: (accountId: string, projectName: string, deploymentId: string) => Promise<CfPagesDeployment>;
136
+ listDeployments: (accountId: string, projectName: string) => Promise<CfPagesDeployment[]>;
137
+ deleteDeployment: (accountId: string, projectName: string, deploymentId: string) => Promise<void>;
129
138
  listDomains: (accountId: string, projectName: string) => Promise<CfPagesDomain[]>;
130
139
  addDomain: (accountId: string, projectName: string, hostname: string) => Promise<CfPagesDomain>;
131
140
  };
@@ -150,7 +159,13 @@ declare function createCloudflareClient(opts: CloudflareClientOptions): {
150
159
  tokens: {
151
160
  verify: () => Promise<CfTokenVerification>;
152
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
+ };
153
168
  };
154
169
  type CloudflareClient = ReturnType<typeof createCloudflareClient>;
155
170
  //#endregion
156
- 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
@@ -53,6 +53,8 @@ function pages(rest) {
53
53
  updateProject: (accountId, name, patch) => cfRequest(rest, "PATCH", `/accounts/${accountId}/pages/projects/${name}`, patch),
54
54
  createDeployment: (accountId, projectName, branch) => cfRequest(rest, "POST", `/accounts/${accountId}/pages/projects/${projectName}/deployments`, { branch }),
55
55
  getDeployment: (accountId, projectName, deploymentId) => cfRequest(rest, "GET", `/accounts/${accountId}/pages/projects/${projectName}/deployments/${deploymentId}`),
56
+ listDeployments: (accountId, projectName) => cfRequest(rest, "GET", `/accounts/${accountId}/pages/projects/${projectName}/deployments`, void 0, { per_page: "25" }),
57
+ deleteDeployment: (accountId, projectName, deploymentId) => cfRequest(rest, "DELETE", `/accounts/${accountId}/pages/projects/${projectName}/deployments/${deploymentId}`, void 0, { force: "true" }),
56
58
  listDomains: (accountId, projectName) => cfRequest(rest, "GET", `/accounts/${accountId}/pages/projects/${projectName}/domains`),
57
59
  addDomain: (accountId, projectName, hostname) => cfRequest(rest, "POST", `/accounts/${accountId}/pages/projects/${projectName}/domains`, { name: hostname })
58
60
  };
@@ -78,6 +80,41 @@ function tunnels(rest) {
78
80
  };
79
81
  }
80
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
81
118
  //#region src/zones/zones.ts
82
119
  function zones(rest) {
83
120
  return { list: (query) => cfRequest(rest, "GET", "/zones", void 0, {
@@ -94,7 +131,8 @@ function createCloudflareClient(opts) {
94
131
  pages: pages(rest),
95
132
  zones: zones(rest),
96
133
  tunnels: tunnels(rest),
97
- tokens: tokens(rest)
134
+ tokens: tokens(rest),
135
+ workers: workers(rest, opts)
98
136
  };
99
137
  }
100
138
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/cloudflare-client",
3
- "version": "1.11.2",
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.11.2"
37
+ "@theholocron/http-client": "^1.13.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@theholocron/eslint-config": "^7.23.1",