@robinpath/cloudflare 0.1.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 +123 -0
- package/dist/cloudflare.d.ts +387 -0
- package/dist/cloudflare.d.ts.map +1 -0
- package/dist/cloudflare.js +741 -0
- package/dist/cloudflare.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/package.json +13 -0
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
const BASE_URL = "https://api.cloudflare.com/client/v4";
|
|
2
|
+
let storedApiToken;
|
|
3
|
+
let storedEmail;
|
|
4
|
+
let storedApiKey;
|
|
5
|
+
function getAuthHeaders() {
|
|
6
|
+
if (storedApiToken) {
|
|
7
|
+
return { Authorization: `Bearer ${storedApiToken}`, "Content-Type": "application/json" };
|
|
8
|
+
}
|
|
9
|
+
if (storedEmail && storedApiKey) {
|
|
10
|
+
return { "X-Auth-Email": storedEmail, "X-Auth-Key": storedApiKey, "Content-Type": "application/json" };
|
|
11
|
+
}
|
|
12
|
+
throw new Error("Cloudflare not authenticated. Call cloudflare.setToken or cloudflare.setCredentials first.");
|
|
13
|
+
}
|
|
14
|
+
async function cfRequest(method, path, body) {
|
|
15
|
+
const headers = getAuthHeaders();
|
|
16
|
+
const options = { method, headers };
|
|
17
|
+
if (body !== undefined)
|
|
18
|
+
options.body = JSON.stringify(body);
|
|
19
|
+
const response = await fetch(`${BASE_URL}${path}`, options);
|
|
20
|
+
const data = (await response.json());
|
|
21
|
+
if (!data.success) {
|
|
22
|
+
const errors = data.errors;
|
|
23
|
+
const msg = errors?.map((e) => e.message).join("; ") ?? "Unknown Cloudflare API error";
|
|
24
|
+
throw new Error(`Cloudflare API error: ${msg}`);
|
|
25
|
+
}
|
|
26
|
+
return data.result;
|
|
27
|
+
}
|
|
28
|
+
async function cfRequestRaw(method, path) {
|
|
29
|
+
const headers = getAuthHeaders();
|
|
30
|
+
const response = await fetch(`${BASE_URL}${path}`, { method, headers });
|
|
31
|
+
if (!response.ok)
|
|
32
|
+
throw new Error(`Cloudflare API error: ${response.status} ${response.statusText}`);
|
|
33
|
+
return await response.text();
|
|
34
|
+
}
|
|
35
|
+
// --- Auth ---
|
|
36
|
+
const setToken = (args) => {
|
|
37
|
+
const apiToken = args[0];
|
|
38
|
+
if (!apiToken)
|
|
39
|
+
throw new Error("API token is required");
|
|
40
|
+
storedApiToken = apiToken;
|
|
41
|
+
storedEmail = undefined;
|
|
42
|
+
storedApiKey = undefined;
|
|
43
|
+
return { success: true, method: "bearer_token" };
|
|
44
|
+
};
|
|
45
|
+
const setCredentials = (args) => {
|
|
46
|
+
const email = args[0];
|
|
47
|
+
const apiKey = args[1];
|
|
48
|
+
if (!email || !apiKey)
|
|
49
|
+
throw new Error("Both email and API key are required");
|
|
50
|
+
storedEmail = email;
|
|
51
|
+
storedApiKey = apiKey;
|
|
52
|
+
storedApiToken = undefined;
|
|
53
|
+
return { success: true, method: "global_api_key" };
|
|
54
|
+
};
|
|
55
|
+
// --- Zones ---
|
|
56
|
+
const listZones = async (args) => {
|
|
57
|
+
const options = args[0] ?? {};
|
|
58
|
+
const params = new URLSearchParams();
|
|
59
|
+
if (options.name)
|
|
60
|
+
params.set("name", String(options.name));
|
|
61
|
+
if (options.status)
|
|
62
|
+
params.set("status", String(options.status));
|
|
63
|
+
if (options.page)
|
|
64
|
+
params.set("page", String(options.page));
|
|
65
|
+
if (options.perPage)
|
|
66
|
+
params.set("per_page", String(options.perPage));
|
|
67
|
+
const query = params.toString();
|
|
68
|
+
return await cfRequest("GET", `/zones${query ? `?${query}` : ""}`);
|
|
69
|
+
};
|
|
70
|
+
const getZone = async (args) => {
|
|
71
|
+
const zoneId = args[0];
|
|
72
|
+
if (!zoneId)
|
|
73
|
+
throw new Error("zoneId is required");
|
|
74
|
+
return await cfRequest("GET", `/zones/${zoneId}`);
|
|
75
|
+
};
|
|
76
|
+
const createZone = async (args) => {
|
|
77
|
+
const name = args[0];
|
|
78
|
+
const options = args[1] ?? {};
|
|
79
|
+
if (!name)
|
|
80
|
+
throw new Error("Zone name is required");
|
|
81
|
+
const body = { name };
|
|
82
|
+
if (options.accountId)
|
|
83
|
+
body.account = { id: options.accountId };
|
|
84
|
+
if (options.jumpStart !== undefined)
|
|
85
|
+
body.jump_start = options.jumpStart;
|
|
86
|
+
if (options.type)
|
|
87
|
+
body.type = options.type;
|
|
88
|
+
return await cfRequest("POST", "/zones", body);
|
|
89
|
+
};
|
|
90
|
+
const deleteZone = async (args) => {
|
|
91
|
+
const zoneId = args[0];
|
|
92
|
+
if (!zoneId)
|
|
93
|
+
throw new Error("zoneId is required");
|
|
94
|
+
await cfRequest("DELETE", `/zones/${zoneId}`);
|
|
95
|
+
return { success: true, zoneId };
|
|
96
|
+
};
|
|
97
|
+
const purgeCache = async (args) => {
|
|
98
|
+
const zoneId = args[0];
|
|
99
|
+
const options = args[1] ?? {};
|
|
100
|
+
if (!zoneId)
|
|
101
|
+
throw new Error("zoneId is required");
|
|
102
|
+
const body = {};
|
|
103
|
+
if (options.purgeEverything) {
|
|
104
|
+
body.purge_everything = true;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
if (options.files)
|
|
108
|
+
body.files = options.files;
|
|
109
|
+
if (options.tags)
|
|
110
|
+
body.tags = options.tags;
|
|
111
|
+
if (options.hosts)
|
|
112
|
+
body.hosts = options.hosts;
|
|
113
|
+
if (options.prefixes)
|
|
114
|
+
body.prefixes = options.prefixes;
|
|
115
|
+
}
|
|
116
|
+
return await cfRequest("POST", `/zones/${zoneId}/purge_cache`, body);
|
|
117
|
+
};
|
|
118
|
+
// --- DNS ---
|
|
119
|
+
const listDnsRecords = async (args) => {
|
|
120
|
+
const zoneId = args[0];
|
|
121
|
+
const options = args[1] ?? {};
|
|
122
|
+
if (!zoneId)
|
|
123
|
+
throw new Error("zoneId is required");
|
|
124
|
+
const params = new URLSearchParams();
|
|
125
|
+
if (options.type)
|
|
126
|
+
params.set("type", String(options.type));
|
|
127
|
+
if (options.name)
|
|
128
|
+
params.set("name", String(options.name));
|
|
129
|
+
if (options.content)
|
|
130
|
+
params.set("content", String(options.content));
|
|
131
|
+
if (options.page)
|
|
132
|
+
params.set("page", String(options.page));
|
|
133
|
+
if (options.perPage)
|
|
134
|
+
params.set("per_page", String(options.perPage));
|
|
135
|
+
const query = params.toString();
|
|
136
|
+
return await cfRequest("GET", `/zones/${zoneId}/dns_records${query ? `?${query}` : ""}`);
|
|
137
|
+
};
|
|
138
|
+
const getDnsRecord = async (args) => {
|
|
139
|
+
const zoneId = args[0];
|
|
140
|
+
const recordId = args[1];
|
|
141
|
+
if (!zoneId || !recordId)
|
|
142
|
+
throw new Error("zoneId and recordId are required");
|
|
143
|
+
return await cfRequest("GET", `/zones/${zoneId}/dns_records/${recordId}`);
|
|
144
|
+
};
|
|
145
|
+
const createDnsRecord = async (args) => {
|
|
146
|
+
const zoneId = args[0];
|
|
147
|
+
const type = args[1];
|
|
148
|
+
const name = args[2];
|
|
149
|
+
const content = args[3];
|
|
150
|
+
const options = args[4] ?? {};
|
|
151
|
+
if (!zoneId || !type || !name || !content)
|
|
152
|
+
throw new Error("zoneId, type, name, and content are required");
|
|
153
|
+
const body = { type, name, content };
|
|
154
|
+
if (options.ttl !== undefined)
|
|
155
|
+
body.ttl = Number(options.ttl);
|
|
156
|
+
if (options.proxied !== undefined)
|
|
157
|
+
body.proxied = Boolean(options.proxied);
|
|
158
|
+
if (options.priority !== undefined)
|
|
159
|
+
body.priority = Number(options.priority);
|
|
160
|
+
return await cfRequest("POST", `/zones/${zoneId}/dns_records`, body);
|
|
161
|
+
};
|
|
162
|
+
const updateDnsRecord = async (args) => {
|
|
163
|
+
const zoneId = args[0];
|
|
164
|
+
const recordId = args[1];
|
|
165
|
+
const type = args[2];
|
|
166
|
+
const name = args[3];
|
|
167
|
+
const content = args[4];
|
|
168
|
+
const options = args[5] ?? {};
|
|
169
|
+
if (!zoneId || !recordId || !type || !name || !content)
|
|
170
|
+
throw new Error("zoneId, recordId, type, name, and content are required");
|
|
171
|
+
const body = { type, name, content };
|
|
172
|
+
if (options.ttl !== undefined)
|
|
173
|
+
body.ttl = Number(options.ttl);
|
|
174
|
+
if (options.proxied !== undefined)
|
|
175
|
+
body.proxied = Boolean(options.proxied);
|
|
176
|
+
if (options.priority !== undefined)
|
|
177
|
+
body.priority = Number(options.priority);
|
|
178
|
+
return await cfRequest("PUT", `/zones/${zoneId}/dns_records/${recordId}`, body);
|
|
179
|
+
};
|
|
180
|
+
const deleteDnsRecord = async (args) => {
|
|
181
|
+
const zoneId = args[0];
|
|
182
|
+
const recordId = args[1];
|
|
183
|
+
if (!zoneId || !recordId)
|
|
184
|
+
throw new Error("zoneId and recordId are required");
|
|
185
|
+
await cfRequest("DELETE", `/zones/${zoneId}/dns_records/${recordId}`);
|
|
186
|
+
return { success: true, zoneId, recordId };
|
|
187
|
+
};
|
|
188
|
+
// --- Workers ---
|
|
189
|
+
const listWorkers = async (args) => {
|
|
190
|
+
const accountId = args[0];
|
|
191
|
+
if (!accountId)
|
|
192
|
+
throw new Error("accountId is required");
|
|
193
|
+
return await cfRequest("GET", `/accounts/${accountId}/workers/scripts`);
|
|
194
|
+
};
|
|
195
|
+
const getWorkerScript = async (args) => {
|
|
196
|
+
const accountId = args[0];
|
|
197
|
+
const scriptName = args[1];
|
|
198
|
+
if (!accountId || !scriptName)
|
|
199
|
+
throw new Error("accountId and scriptName are required");
|
|
200
|
+
return await cfRequestRaw("GET", `/accounts/${accountId}/workers/scripts/${scriptName}`);
|
|
201
|
+
};
|
|
202
|
+
const deployWorker = async (args) => {
|
|
203
|
+
const accountId = args[0];
|
|
204
|
+
const scriptName = args[1];
|
|
205
|
+
const script = args[2];
|
|
206
|
+
const options = args[3] ?? {};
|
|
207
|
+
if (!accountId || !scriptName || !script)
|
|
208
|
+
throw new Error("accountId, scriptName, and script are required");
|
|
209
|
+
const headers = getAuthHeaders();
|
|
210
|
+
const metadata = {
|
|
211
|
+
main_module: options.mainModule ?? "worker.js",
|
|
212
|
+
compatibility_date: options.compatibilityDate ?? new Date().toISOString().split("T")[0],
|
|
213
|
+
};
|
|
214
|
+
if (options.bindings)
|
|
215
|
+
metadata.bindings = options.bindings;
|
|
216
|
+
const boundary = `----CloudflareWorkerBoundary${Date.now()}`;
|
|
217
|
+
const body = [
|
|
218
|
+
`--${boundary}`,
|
|
219
|
+
'Content-Disposition: form-data; name="metadata"; filename="metadata.json"',
|
|
220
|
+
"Content-Type: application/json",
|
|
221
|
+
"",
|
|
222
|
+
JSON.stringify(metadata),
|
|
223
|
+
`--${boundary}`,
|
|
224
|
+
`Content-Disposition: form-data; name="script"; filename="${options.mainModule ?? "worker.js"}"`,
|
|
225
|
+
"Content-Type: application/javascript",
|
|
226
|
+
"",
|
|
227
|
+
script,
|
|
228
|
+
`--${boundary}--`,
|
|
229
|
+
].join("\r\n");
|
|
230
|
+
delete headers["Content-Type"];
|
|
231
|
+
headers["Content-Type"] = `multipart/form-data; boundary=${boundary}`;
|
|
232
|
+
const response = await fetch(`${BASE_URL}/accounts/${accountId}/workers/scripts/${scriptName}`, {
|
|
233
|
+
method: "PUT",
|
|
234
|
+
headers,
|
|
235
|
+
body,
|
|
236
|
+
});
|
|
237
|
+
const data = (await response.json());
|
|
238
|
+
if (!data.success) {
|
|
239
|
+
const errors = data.errors;
|
|
240
|
+
const msg = errors?.map((e) => e.message).join("; ") ?? "Unknown Cloudflare API error";
|
|
241
|
+
throw new Error(`Cloudflare API error: ${msg}`);
|
|
242
|
+
}
|
|
243
|
+
return data.result;
|
|
244
|
+
};
|
|
245
|
+
const deleteWorker = async (args) => {
|
|
246
|
+
const accountId = args[0];
|
|
247
|
+
const scriptName = args[1];
|
|
248
|
+
if (!accountId || !scriptName)
|
|
249
|
+
throw new Error("accountId and scriptName are required");
|
|
250
|
+
await cfRequest("DELETE", `/accounts/${accountId}/workers/scripts/${scriptName}`);
|
|
251
|
+
return { success: true, accountId, scriptName };
|
|
252
|
+
};
|
|
253
|
+
// --- KV ---
|
|
254
|
+
const listKvNamespaces = async (args) => {
|
|
255
|
+
const accountId = args[0];
|
|
256
|
+
const options = args[1] ?? {};
|
|
257
|
+
if (!accountId)
|
|
258
|
+
throw new Error("accountId is required");
|
|
259
|
+
const params = new URLSearchParams();
|
|
260
|
+
if (options.page)
|
|
261
|
+
params.set("page", String(options.page));
|
|
262
|
+
if (options.perPage)
|
|
263
|
+
params.set("per_page", String(options.perPage));
|
|
264
|
+
const query = params.toString();
|
|
265
|
+
return await cfRequest("GET", `/accounts/${accountId}/storage/kv/namespaces${query ? `?${query}` : ""}`);
|
|
266
|
+
};
|
|
267
|
+
const createKvNamespace = async (args) => {
|
|
268
|
+
const accountId = args[0];
|
|
269
|
+
const title = args[1];
|
|
270
|
+
if (!accountId || !title)
|
|
271
|
+
throw new Error("accountId and title are required");
|
|
272
|
+
return await cfRequest("POST", `/accounts/${accountId}/storage/kv/namespaces`, { title });
|
|
273
|
+
};
|
|
274
|
+
const deleteKvNamespace = async (args) => {
|
|
275
|
+
const accountId = args[0];
|
|
276
|
+
const namespaceId = args[1];
|
|
277
|
+
if (!accountId || !namespaceId)
|
|
278
|
+
throw new Error("accountId and namespaceId are required");
|
|
279
|
+
await cfRequest("DELETE", `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}`);
|
|
280
|
+
return { success: true, accountId, namespaceId };
|
|
281
|
+
};
|
|
282
|
+
const kvGet = async (args) => {
|
|
283
|
+
const accountId = args[0];
|
|
284
|
+
const namespaceId = args[1];
|
|
285
|
+
const key = args[2];
|
|
286
|
+
if (!accountId || !namespaceId || !key)
|
|
287
|
+
throw new Error("accountId, namespaceId, and key are required");
|
|
288
|
+
const headers = getAuthHeaders();
|
|
289
|
+
const response = await fetch(`${BASE_URL}/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${encodeURIComponent(key)}`, { method: "GET", headers });
|
|
290
|
+
if (!response.ok) {
|
|
291
|
+
if (response.status === 404)
|
|
292
|
+
return null;
|
|
293
|
+
throw new Error(`Cloudflare API error: ${response.status} ${response.statusText}`);
|
|
294
|
+
}
|
|
295
|
+
const text = await response.text();
|
|
296
|
+
try {
|
|
297
|
+
return JSON.parse(text);
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
return text;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const kvPut = async (args) => {
|
|
304
|
+
const accountId = args[0];
|
|
305
|
+
const namespaceId = args[1];
|
|
306
|
+
const key = args[2];
|
|
307
|
+
const value = args[3];
|
|
308
|
+
const options = args[4] ?? {};
|
|
309
|
+
if (!accountId || !namespaceId || !key)
|
|
310
|
+
throw new Error("accountId, namespaceId, and key are required");
|
|
311
|
+
const params = new URLSearchParams();
|
|
312
|
+
if (options.expiration)
|
|
313
|
+
params.set("expiration", String(options.expiration));
|
|
314
|
+
if (options.expirationTtl)
|
|
315
|
+
params.set("expiration_ttl", String(options.expirationTtl));
|
|
316
|
+
const query = params.toString();
|
|
317
|
+
const headers = getAuthHeaders();
|
|
318
|
+
headers["Content-Type"] = "text/plain";
|
|
319
|
+
const body = typeof value === "string" ? value : JSON.stringify(value);
|
|
320
|
+
const response = await fetch(`${BASE_URL}/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${encodeURIComponent(key)}${query ? `?${query}` : ""}`, { method: "PUT", headers, body });
|
|
321
|
+
const data = (await response.json());
|
|
322
|
+
if (!data.success) {
|
|
323
|
+
const errors = data.errors;
|
|
324
|
+
const msg = errors?.map((e) => e.message).join("; ") ?? "Unknown Cloudflare API error";
|
|
325
|
+
throw new Error(`Cloudflare API error: ${msg}`);
|
|
326
|
+
}
|
|
327
|
+
return { success: true, key };
|
|
328
|
+
};
|
|
329
|
+
const kvDelete = async (args) => {
|
|
330
|
+
const accountId = args[0];
|
|
331
|
+
const namespaceId = args[1];
|
|
332
|
+
const key = args[2];
|
|
333
|
+
if (!accountId || !namespaceId || !key)
|
|
334
|
+
throw new Error("accountId, namespaceId, and key are required");
|
|
335
|
+
await cfRequest("DELETE", `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${encodeURIComponent(key)}`);
|
|
336
|
+
return { success: true, key };
|
|
337
|
+
};
|
|
338
|
+
const kvListKeys = async (args) => {
|
|
339
|
+
const accountId = args[0];
|
|
340
|
+
const namespaceId = args[1];
|
|
341
|
+
const options = args[2] ?? {};
|
|
342
|
+
if (!accountId || !namespaceId)
|
|
343
|
+
throw new Error("accountId and namespaceId are required");
|
|
344
|
+
const params = new URLSearchParams();
|
|
345
|
+
if (options.prefix)
|
|
346
|
+
params.set("prefix", String(options.prefix));
|
|
347
|
+
if (options.limit)
|
|
348
|
+
params.set("limit", String(options.limit));
|
|
349
|
+
if (options.cursor)
|
|
350
|
+
params.set("cursor", String(options.cursor));
|
|
351
|
+
const query = params.toString();
|
|
352
|
+
return await cfRequest("GET", `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/keys${query ? `?${query}` : ""}`);
|
|
353
|
+
};
|
|
354
|
+
// --- R2 ---
|
|
355
|
+
const listR2Buckets = async (args) => {
|
|
356
|
+
const accountId = args[0];
|
|
357
|
+
if (!accountId)
|
|
358
|
+
throw new Error("accountId is required");
|
|
359
|
+
return await cfRequest("GET", `/accounts/${accountId}/r2/buckets`);
|
|
360
|
+
};
|
|
361
|
+
const createR2Bucket = async (args) => {
|
|
362
|
+
const accountId = args[0];
|
|
363
|
+
const name = args[1];
|
|
364
|
+
if (!accountId || !name)
|
|
365
|
+
throw new Error("accountId and name are required");
|
|
366
|
+
return await cfRequest("POST", `/accounts/${accountId}/r2/buckets`, { name });
|
|
367
|
+
};
|
|
368
|
+
const deleteR2Bucket = async (args) => {
|
|
369
|
+
const accountId = args[0];
|
|
370
|
+
const bucketName = args[1];
|
|
371
|
+
if (!accountId || !bucketName)
|
|
372
|
+
throw new Error("accountId and bucketName are required");
|
|
373
|
+
await cfRequest("DELETE", `/accounts/${accountId}/r2/buckets/${bucketName}`);
|
|
374
|
+
return { success: true, accountId, bucketName };
|
|
375
|
+
};
|
|
376
|
+
// --- Pages ---
|
|
377
|
+
const listPages = async (args) => {
|
|
378
|
+
const accountId = args[0];
|
|
379
|
+
if (!accountId)
|
|
380
|
+
throw new Error("accountId is required");
|
|
381
|
+
return await cfRequest("GET", `/accounts/${accountId}/pages/projects`);
|
|
382
|
+
};
|
|
383
|
+
const getPageProject = async (args) => {
|
|
384
|
+
const accountId = args[0];
|
|
385
|
+
const projectName = args[1];
|
|
386
|
+
if (!accountId || !projectName)
|
|
387
|
+
throw new Error("accountId and projectName are required");
|
|
388
|
+
return await cfRequest("GET", `/accounts/${accountId}/pages/projects/${projectName}`);
|
|
389
|
+
};
|
|
390
|
+
// --- Analytics ---
|
|
391
|
+
const getZoneAnalytics = async (args) => {
|
|
392
|
+
const zoneId = args[0];
|
|
393
|
+
const options = args[1] ?? {};
|
|
394
|
+
if (!zoneId)
|
|
395
|
+
throw new Error("zoneId is required");
|
|
396
|
+
const params = new URLSearchParams();
|
|
397
|
+
if (options.since)
|
|
398
|
+
params.set("since", String(options.since));
|
|
399
|
+
if (options.until)
|
|
400
|
+
params.set("until", String(options.until));
|
|
401
|
+
const query = params.toString();
|
|
402
|
+
return await cfRequest("GET", `/zones/${zoneId}/analytics/dashboard${query ? `?${query}` : ""}`);
|
|
403
|
+
};
|
|
404
|
+
// --- Exports ---
|
|
405
|
+
export const CloudflareFunctions = {
|
|
406
|
+
setToken,
|
|
407
|
+
setCredentials,
|
|
408
|
+
listZones,
|
|
409
|
+
getZone,
|
|
410
|
+
createZone,
|
|
411
|
+
deleteZone,
|
|
412
|
+
purgeCache,
|
|
413
|
+
listDnsRecords,
|
|
414
|
+
getDnsRecord,
|
|
415
|
+
createDnsRecord,
|
|
416
|
+
updateDnsRecord,
|
|
417
|
+
deleteDnsRecord,
|
|
418
|
+
listWorkers,
|
|
419
|
+
getWorkerScript,
|
|
420
|
+
deployWorker,
|
|
421
|
+
deleteWorker,
|
|
422
|
+
listKvNamespaces,
|
|
423
|
+
createKvNamespace,
|
|
424
|
+
deleteKvNamespace,
|
|
425
|
+
kvGet,
|
|
426
|
+
kvPut,
|
|
427
|
+
kvDelete,
|
|
428
|
+
kvListKeys,
|
|
429
|
+
listR2Buckets,
|
|
430
|
+
createR2Bucket,
|
|
431
|
+
deleteR2Bucket,
|
|
432
|
+
listPages,
|
|
433
|
+
getPageProject,
|
|
434
|
+
getZoneAnalytics,
|
|
435
|
+
};
|
|
436
|
+
export const CloudflareFunctionMetadata = {
|
|
437
|
+
setToken: {
|
|
438
|
+
description: "Set Cloudflare API token for authentication",
|
|
439
|
+
parameters: [
|
|
440
|
+
{ name: "apiToken", dataType: "string", description: "Cloudflare API token", formInputType: "text", required: true },
|
|
441
|
+
],
|
|
442
|
+
returnType: "object",
|
|
443
|
+
returnDescription: "{ success, method }",
|
|
444
|
+
example: 'cloudflare.setToken "your-api-token"',
|
|
445
|
+
},
|
|
446
|
+
setCredentials: {
|
|
447
|
+
description: "Set Cloudflare global API key credentials",
|
|
448
|
+
parameters: [
|
|
449
|
+
{ name: "email", dataType: "string", description: "Cloudflare account email", formInputType: "text", required: true },
|
|
450
|
+
{ name: "apiKey", dataType: "string", description: "Cloudflare global API key", formInputType: "text", required: true },
|
|
451
|
+
],
|
|
452
|
+
returnType: "object",
|
|
453
|
+
returnDescription: "{ success, method }",
|
|
454
|
+
example: 'cloudflare.setCredentials "user@example.com" "your-global-api-key"',
|
|
455
|
+
},
|
|
456
|
+
listZones: {
|
|
457
|
+
description: "List Cloudflare zones",
|
|
458
|
+
parameters: [
|
|
459
|
+
{ name: "options", dataType: "object", description: "Filter options: name, status, page, perPage", formInputType: "json", required: false },
|
|
460
|
+
],
|
|
461
|
+
returnType: "array",
|
|
462
|
+
returnDescription: "Array of zone objects",
|
|
463
|
+
example: 'cloudflare.listZones {"name": "example.com"}',
|
|
464
|
+
},
|
|
465
|
+
getZone: {
|
|
466
|
+
description: "Get details of a specific zone",
|
|
467
|
+
parameters: [
|
|
468
|
+
{ name: "zoneId", dataType: "string", description: "Zone ID", formInputType: "text", required: true },
|
|
469
|
+
],
|
|
470
|
+
returnType: "object",
|
|
471
|
+
returnDescription: "Zone details object",
|
|
472
|
+
example: 'cloudflare.getZone "zone-id-here"',
|
|
473
|
+
},
|
|
474
|
+
createZone: {
|
|
475
|
+
description: "Create a new Cloudflare zone",
|
|
476
|
+
parameters: [
|
|
477
|
+
{ name: "name", dataType: "string", description: "Domain name for the zone", formInputType: "text", required: true },
|
|
478
|
+
{ name: "options", dataType: "object", description: "Options: accountId, jumpStart, type", formInputType: "json", required: false },
|
|
479
|
+
],
|
|
480
|
+
returnType: "object",
|
|
481
|
+
returnDescription: "Created zone object",
|
|
482
|
+
example: 'cloudflare.createZone "example.com" {"accountId": "abc123"}',
|
|
483
|
+
},
|
|
484
|
+
deleteZone: {
|
|
485
|
+
description: "Delete a Cloudflare zone",
|
|
486
|
+
parameters: [
|
|
487
|
+
{ name: "zoneId", dataType: "string", description: "Zone ID", formInputType: "text", required: true },
|
|
488
|
+
],
|
|
489
|
+
returnType: "object",
|
|
490
|
+
returnDescription: "{ success, zoneId }",
|
|
491
|
+
example: 'cloudflare.deleteZone "zone-id-here"',
|
|
492
|
+
},
|
|
493
|
+
purgeCache: {
|
|
494
|
+
description: "Purge cache for a zone (all or selective by URLs/tags/hosts/prefixes)",
|
|
495
|
+
parameters: [
|
|
496
|
+
{ name: "zoneId", dataType: "string", description: "Zone ID", formInputType: "text", required: true },
|
|
497
|
+
{ name: "options", dataType: "object", description: "Options: purgeEverything, files, tags, hosts, prefixes", formInputType: "json", required: false },
|
|
498
|
+
],
|
|
499
|
+
returnType: "object",
|
|
500
|
+
returnDescription: "Purge result object",
|
|
501
|
+
example: 'cloudflare.purgeCache "zone-id" {"purgeEverything": true}',
|
|
502
|
+
},
|
|
503
|
+
listDnsRecords: {
|
|
504
|
+
description: "List DNS records for a zone",
|
|
505
|
+
parameters: [
|
|
506
|
+
{ name: "zoneId", dataType: "string", description: "Zone ID", formInputType: "text", required: true },
|
|
507
|
+
{ name: "options", dataType: "object", description: "Filter options: type, name, content, page, perPage", formInputType: "json", required: false },
|
|
508
|
+
],
|
|
509
|
+
returnType: "array",
|
|
510
|
+
returnDescription: "Array of DNS record objects",
|
|
511
|
+
example: 'cloudflare.listDnsRecords "zone-id" {"type": "A"}',
|
|
512
|
+
},
|
|
513
|
+
getDnsRecord: {
|
|
514
|
+
description: "Get a specific DNS record",
|
|
515
|
+
parameters: [
|
|
516
|
+
{ name: "zoneId", dataType: "string", description: "Zone ID", formInputType: "text", required: true },
|
|
517
|
+
{ name: "recordId", dataType: "string", description: "DNS record ID", formInputType: "text", required: true },
|
|
518
|
+
],
|
|
519
|
+
returnType: "object",
|
|
520
|
+
returnDescription: "DNS record object",
|
|
521
|
+
example: 'cloudflare.getDnsRecord "zone-id" "record-id"',
|
|
522
|
+
},
|
|
523
|
+
createDnsRecord: {
|
|
524
|
+
description: "Create a DNS record in a zone",
|
|
525
|
+
parameters: [
|
|
526
|
+
{ name: "zoneId", dataType: "string", description: "Zone ID", formInputType: "text", required: true },
|
|
527
|
+
{ name: "type", dataType: "string", description: "Record type (A, AAAA, CNAME, MX, TXT, etc.)", formInputType: "text", required: true },
|
|
528
|
+
{ name: "name", dataType: "string", description: "DNS record name", formInputType: "text", required: true },
|
|
529
|
+
{ name: "content", dataType: "string", description: "DNS record content/value", formInputType: "text", required: true },
|
|
530
|
+
{ name: "options", dataType: "object", description: "Options: ttl, proxied, priority", formInputType: "json", required: false },
|
|
531
|
+
],
|
|
532
|
+
returnType: "object",
|
|
533
|
+
returnDescription: "Created DNS record object",
|
|
534
|
+
example: 'cloudflare.createDnsRecord "zone-id" "A" "example.com" "1.2.3.4" {"proxied": true}',
|
|
535
|
+
},
|
|
536
|
+
updateDnsRecord: {
|
|
537
|
+
description: "Update an existing DNS record",
|
|
538
|
+
parameters: [
|
|
539
|
+
{ name: "zoneId", dataType: "string", description: "Zone ID", formInputType: "text", required: true },
|
|
540
|
+
{ name: "recordId", dataType: "string", description: "DNS record ID", formInputType: "text", required: true },
|
|
541
|
+
{ name: "type", dataType: "string", description: "Record type (A, AAAA, CNAME, MX, TXT, etc.)", formInputType: "text", required: true },
|
|
542
|
+
{ name: "name", dataType: "string", description: "DNS record name", formInputType: "text", required: true },
|
|
543
|
+
{ name: "content", dataType: "string", description: "DNS record content/value", formInputType: "text", required: true },
|
|
544
|
+
{ name: "options", dataType: "object", description: "Options: ttl, proxied, priority", formInputType: "json", required: false },
|
|
545
|
+
],
|
|
546
|
+
returnType: "object",
|
|
547
|
+
returnDescription: "Updated DNS record object",
|
|
548
|
+
example: 'cloudflare.updateDnsRecord "zone-id" "record-id" "A" "example.com" "5.6.7.8" {"proxied": true}',
|
|
549
|
+
},
|
|
550
|
+
deleteDnsRecord: {
|
|
551
|
+
description: "Delete a DNS record from a zone",
|
|
552
|
+
parameters: [
|
|
553
|
+
{ name: "zoneId", dataType: "string", description: "Zone ID", formInputType: "text", required: true },
|
|
554
|
+
{ name: "recordId", dataType: "string", description: "DNS record ID", formInputType: "text", required: true },
|
|
555
|
+
],
|
|
556
|
+
returnType: "object",
|
|
557
|
+
returnDescription: "{ success, zoneId, recordId }",
|
|
558
|
+
example: 'cloudflare.deleteDnsRecord "zone-id" "record-id"',
|
|
559
|
+
},
|
|
560
|
+
listWorkers: {
|
|
561
|
+
description: "List Workers scripts for an account",
|
|
562
|
+
parameters: [
|
|
563
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
564
|
+
],
|
|
565
|
+
returnType: "array",
|
|
566
|
+
returnDescription: "Array of Worker script objects",
|
|
567
|
+
example: 'cloudflare.listWorkers "account-id"',
|
|
568
|
+
},
|
|
569
|
+
getWorkerScript: {
|
|
570
|
+
description: "Get the content of a Worker script",
|
|
571
|
+
parameters: [
|
|
572
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
573
|
+
{ name: "scriptName", dataType: "string", description: "Worker script name", formInputType: "text", required: true },
|
|
574
|
+
],
|
|
575
|
+
returnType: "string",
|
|
576
|
+
returnDescription: "Worker script source code",
|
|
577
|
+
example: 'cloudflare.getWorkerScript "account-id" "my-worker"',
|
|
578
|
+
},
|
|
579
|
+
deployWorker: {
|
|
580
|
+
description: "Deploy a Worker script",
|
|
581
|
+
parameters: [
|
|
582
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
583
|
+
{ name: "scriptName", dataType: "string", description: "Worker script name", formInputType: "text", required: true },
|
|
584
|
+
{ name: "script", dataType: "string", description: "Worker script source code", formInputType: "code", required: true },
|
|
585
|
+
{ name: "options", dataType: "object", description: "Options: mainModule, compatibilityDate, bindings", formInputType: "json", required: false },
|
|
586
|
+
],
|
|
587
|
+
returnType: "object",
|
|
588
|
+
returnDescription: "Deployed Worker result object",
|
|
589
|
+
example: 'cloudflare.deployWorker "account-id" "my-worker" "export default { fetch() { return new Response(\'Hello\') } }"',
|
|
590
|
+
},
|
|
591
|
+
deleteWorker: {
|
|
592
|
+
description: "Delete a Worker script",
|
|
593
|
+
parameters: [
|
|
594
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
595
|
+
{ name: "scriptName", dataType: "string", description: "Worker script name", formInputType: "text", required: true },
|
|
596
|
+
],
|
|
597
|
+
returnType: "object",
|
|
598
|
+
returnDescription: "{ success, accountId, scriptName }",
|
|
599
|
+
example: 'cloudflare.deleteWorker "account-id" "my-worker"',
|
|
600
|
+
},
|
|
601
|
+
listKvNamespaces: {
|
|
602
|
+
description: "List KV namespaces for an account",
|
|
603
|
+
parameters: [
|
|
604
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
605
|
+
{ name: "options", dataType: "object", description: "Options: page, perPage", formInputType: "json", required: false },
|
|
606
|
+
],
|
|
607
|
+
returnType: "array",
|
|
608
|
+
returnDescription: "Array of KV namespace objects",
|
|
609
|
+
example: 'cloudflare.listKvNamespaces "account-id"',
|
|
610
|
+
},
|
|
611
|
+
createKvNamespace: {
|
|
612
|
+
description: "Create a KV namespace",
|
|
613
|
+
parameters: [
|
|
614
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
615
|
+
{ name: "title", dataType: "string", description: "Namespace title", formInputType: "text", required: true },
|
|
616
|
+
],
|
|
617
|
+
returnType: "object",
|
|
618
|
+
returnDescription: "Created KV namespace object",
|
|
619
|
+
example: 'cloudflare.createKvNamespace "account-id" "my-kv-store"',
|
|
620
|
+
},
|
|
621
|
+
deleteKvNamespace: {
|
|
622
|
+
description: "Delete a KV namespace",
|
|
623
|
+
parameters: [
|
|
624
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
625
|
+
{ name: "namespaceId", dataType: "string", description: "KV namespace ID", formInputType: "text", required: true },
|
|
626
|
+
],
|
|
627
|
+
returnType: "object",
|
|
628
|
+
returnDescription: "{ success, accountId, namespaceId }",
|
|
629
|
+
example: 'cloudflare.deleteKvNamespace "account-id" "namespace-id"',
|
|
630
|
+
},
|
|
631
|
+
kvGet: {
|
|
632
|
+
description: "Read a value from KV storage",
|
|
633
|
+
parameters: [
|
|
634
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
635
|
+
{ name: "namespaceId", dataType: "string", description: "KV namespace ID", formInputType: "text", required: true },
|
|
636
|
+
{ name: "key", dataType: "string", description: "Key to read", formInputType: "text", required: true },
|
|
637
|
+
],
|
|
638
|
+
returnType: "any",
|
|
639
|
+
returnDescription: "Value stored at the key, or null if not found",
|
|
640
|
+
example: 'cloudflare.kvGet "account-id" "namespace-id" "my-key"',
|
|
641
|
+
},
|
|
642
|
+
kvPut: {
|
|
643
|
+
description: "Write a value to KV storage",
|
|
644
|
+
parameters: [
|
|
645
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
646
|
+
{ name: "namespaceId", dataType: "string", description: "KV namespace ID", formInputType: "text", required: true },
|
|
647
|
+
{ name: "key", dataType: "string", description: "Key to write", formInputType: "text", required: true },
|
|
648
|
+
{ name: "value", dataType: "any", description: "Value to store", formInputType: "text", required: true },
|
|
649
|
+
{ name: "options", dataType: "object", description: "Options: expiration (unix timestamp), expirationTtl (seconds)", formInputType: "json", required: false },
|
|
650
|
+
],
|
|
651
|
+
returnType: "object",
|
|
652
|
+
returnDescription: "{ success, key }",
|
|
653
|
+
example: 'cloudflare.kvPut "account-id" "namespace-id" "my-key" "my-value" {"expirationTtl": 3600}',
|
|
654
|
+
},
|
|
655
|
+
kvDelete: {
|
|
656
|
+
description: "Delete a key from KV storage",
|
|
657
|
+
parameters: [
|
|
658
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
659
|
+
{ name: "namespaceId", dataType: "string", description: "KV namespace ID", formInputType: "text", required: true },
|
|
660
|
+
{ name: "key", dataType: "string", description: "Key to delete", formInputType: "text", required: true },
|
|
661
|
+
],
|
|
662
|
+
returnType: "object",
|
|
663
|
+
returnDescription: "{ success, key }",
|
|
664
|
+
example: 'cloudflare.kvDelete "account-id" "namespace-id" "my-key"',
|
|
665
|
+
},
|
|
666
|
+
kvListKeys: {
|
|
667
|
+
description: "List keys in a KV namespace",
|
|
668
|
+
parameters: [
|
|
669
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
670
|
+
{ name: "namespaceId", dataType: "string", description: "KV namespace ID", formInputType: "text", required: true },
|
|
671
|
+
{ name: "options", dataType: "object", description: "Options: prefix, limit, cursor", formInputType: "json", required: false },
|
|
672
|
+
],
|
|
673
|
+
returnType: "array",
|
|
674
|
+
returnDescription: "Array of key objects",
|
|
675
|
+
example: 'cloudflare.kvListKeys "account-id" "namespace-id" {"prefix": "user:"}',
|
|
676
|
+
},
|
|
677
|
+
listR2Buckets: {
|
|
678
|
+
description: "List R2 buckets for an account",
|
|
679
|
+
parameters: [
|
|
680
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
681
|
+
],
|
|
682
|
+
returnType: "array",
|
|
683
|
+
returnDescription: "Array of R2 bucket objects",
|
|
684
|
+
example: 'cloudflare.listR2Buckets "account-id"',
|
|
685
|
+
},
|
|
686
|
+
createR2Bucket: {
|
|
687
|
+
description: "Create an R2 bucket",
|
|
688
|
+
parameters: [
|
|
689
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
690
|
+
{ name: "name", dataType: "string", description: "Bucket name", formInputType: "text", required: true },
|
|
691
|
+
],
|
|
692
|
+
returnType: "object",
|
|
693
|
+
returnDescription: "Created R2 bucket object",
|
|
694
|
+
example: 'cloudflare.createR2Bucket "account-id" "my-bucket"',
|
|
695
|
+
},
|
|
696
|
+
deleteR2Bucket: {
|
|
697
|
+
description: "Delete an R2 bucket",
|
|
698
|
+
parameters: [
|
|
699
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
700
|
+
{ name: "bucketName", dataType: "string", description: "Bucket name", formInputType: "text", required: true },
|
|
701
|
+
],
|
|
702
|
+
returnType: "object",
|
|
703
|
+
returnDescription: "{ success, accountId, bucketName }",
|
|
704
|
+
example: 'cloudflare.deleteR2Bucket "account-id" "my-bucket"',
|
|
705
|
+
},
|
|
706
|
+
listPages: {
|
|
707
|
+
description: "List Cloudflare Pages projects",
|
|
708
|
+
parameters: [
|
|
709
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
710
|
+
],
|
|
711
|
+
returnType: "array",
|
|
712
|
+
returnDescription: "Array of Pages project objects",
|
|
713
|
+
example: 'cloudflare.listPages "account-id"',
|
|
714
|
+
},
|
|
715
|
+
getPageProject: {
|
|
716
|
+
description: "Get details of a Cloudflare Pages project",
|
|
717
|
+
parameters: [
|
|
718
|
+
{ name: "accountId", dataType: "string", description: "Cloudflare account ID", formInputType: "text", required: true },
|
|
719
|
+
{ name: "projectName", dataType: "string", description: "Pages project name", formInputType: "text", required: true },
|
|
720
|
+
],
|
|
721
|
+
returnType: "object",
|
|
722
|
+
returnDescription: "Pages project details object",
|
|
723
|
+
example: 'cloudflare.getPageProject "account-id" "my-site"',
|
|
724
|
+
},
|
|
725
|
+
getZoneAnalytics: {
|
|
726
|
+
description: "Get analytics data for a zone",
|
|
727
|
+
parameters: [
|
|
728
|
+
{ name: "zoneId", dataType: "string", description: "Zone ID", formInputType: "text", required: true },
|
|
729
|
+
{ name: "options", dataType: "object", description: "Options: since (ISO date or negative minutes), until (ISO date or negative minutes)", formInputType: "json", required: false },
|
|
730
|
+
],
|
|
731
|
+
returnType: "object",
|
|
732
|
+
returnDescription: "Zone analytics dashboard data",
|
|
733
|
+
example: 'cloudflare.getZoneAnalytics "zone-id" {"since": "-10080", "until": "0"}',
|
|
734
|
+
},
|
|
735
|
+
};
|
|
736
|
+
export const CloudflareModuleMetadata = {
|
|
737
|
+
description: "Cloudflare API v4 client for managing zones, DNS, Workers, KV, R2, Pages, and analytics",
|
|
738
|
+
methods: Object.keys(CloudflareFunctions),
|
|
739
|
+
category: "cloud",
|
|
740
|
+
};
|
|
741
|
+
//# sourceMappingURL=cloudflare.js.map
|