chub-dev 0.1.0 → 0.1.2-beta.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 +55 -0
- package/bin/chub-mcp +2 -0
- package/dist/airtable/docs/database/javascript/DOC.md +1437 -0
- package/dist/airtable/docs/database/python/DOC.md +1735 -0
- package/dist/amplitude/docs/analytics/javascript/DOC.md +1282 -0
- package/dist/amplitude/docs/analytics/python/DOC.md +1199 -0
- package/dist/anthropic/docs/claude-api/javascript/DOC.md +503 -0
- package/dist/anthropic/docs/claude-api/python/DOC.md +389 -0
- package/dist/asana/docs/tasks/DOC.md +1396 -0
- package/dist/assemblyai/docs/transcription/DOC.md +1043 -0
- package/dist/atlassian/docs/confluence/javascript/DOC.md +1347 -0
- package/dist/atlassian/docs/confluence/python/DOC.md +1604 -0
- package/dist/auth0/docs/identity/javascript/DOC.md +968 -0
- package/dist/auth0/docs/identity/python/DOC.md +1199 -0
- package/dist/aws/docs/s3/javascript/DOC.md +1773 -0
- package/dist/aws/docs/s3/python/DOC.md +1807 -0
- package/dist/binance/docs/trading/javascript/DOC.md +1315 -0
- package/dist/binance/docs/trading/python/DOC.md +1454 -0
- package/dist/braintree/docs/gateway/javascript/DOC.md +1278 -0
- package/dist/braintree/docs/gateway/python/DOC.md +1179 -0
- package/dist/chromadb/docs/embeddings-db/javascript/DOC.md +1263 -0
- package/dist/chromadb/docs/embeddings-db/python/DOC.md +1707 -0
- package/dist/clerk/docs/auth/javascript/DOC.md +1220 -0
- package/dist/clerk/docs/auth/python/DOC.md +274 -0
- package/dist/cloudflare/docs/workers/javascript/DOC.md +918 -0
- package/dist/cloudflare/docs/workers/python/DOC.md +994 -0
- package/dist/cockroachdb/docs/distributed-db/DOC.md +1500 -0
- package/dist/cohere/docs/llm/DOC.md +1335 -0
- package/dist/datadog/docs/monitoring/javascript/DOC.md +1740 -0
- package/dist/datadog/docs/monitoring/python/DOC.md +1815 -0
- package/dist/deepgram/docs/speech/javascript/DOC.md +885 -0
- package/dist/deepgram/docs/speech/python/DOC.md +685 -0
- package/dist/deepl/docs/translation/javascript/DOC.md +887 -0
- package/dist/deepl/docs/translation/python/DOC.md +944 -0
- package/dist/deepseek/docs/llm/DOC.md +1220 -0
- package/dist/directus/docs/headless-cms/javascript/DOC.md +1128 -0
- package/dist/directus/docs/headless-cms/python/DOC.md +1276 -0
- package/dist/discord/docs/bot/javascript/DOC.md +1090 -0
- package/dist/discord/docs/bot/python/DOC.md +1130 -0
- package/dist/elasticsearch/docs/search/DOC.md +1634 -0
- package/dist/elevenlabs/docs/text-to-speech/javascript/DOC.md +336 -0
- package/dist/elevenlabs/docs/text-to-speech/python/DOC.md +552 -0
- package/dist/firebase/docs/auth/DOC.md +1015 -0
- package/dist/gemini/docs/genai/javascript/DOC.md +691 -0
- package/dist/gemini/docs/genai/python/DOC.md +555 -0
- package/dist/github/docs/octokit/DOC.md +1560 -0
- package/dist/google/docs/bigquery/javascript/DOC.md +1688 -0
- package/dist/google/docs/bigquery/python/DOC.md +1503 -0
- package/dist/hubspot/docs/crm/javascript/DOC.md +1805 -0
- package/dist/hubspot/docs/crm/python/DOC.md +2033 -0
- package/dist/huggingface/docs/transformers/DOC.md +948 -0
- package/dist/intercom/docs/messaging/javascript/DOC.md +1844 -0
- package/dist/intercom/docs/messaging/python/DOC.md +1797 -0
- package/dist/jira/docs/issues/javascript/DOC.md +1420 -0
- package/dist/jira/docs/issues/python/DOC.md +1492 -0
- package/dist/kafka/docs/streaming/javascript/DOC.md +1671 -0
- package/dist/kafka/docs/streaming/python/DOC.md +1464 -0
- package/dist/landingai-ade/docs/api/DOC.md +620 -0
- package/dist/landingai-ade/docs/sdk/python/DOC.md +489 -0
- package/dist/landingai-ade/docs/sdk/typescript/DOC.md +542 -0
- package/dist/landingai-ade/skills/SKILL.md +489 -0
- package/dist/launchdarkly/docs/feature-flags/javascript/DOC.md +1191 -0
- package/dist/launchdarkly/docs/feature-flags/python/DOC.md +1671 -0
- package/dist/linear/docs/tracker/DOC.md +1554 -0
- package/dist/livekit/docs/realtime/javascript/DOC.md +303 -0
- package/dist/livekit/docs/realtime/python/DOC.md +163 -0
- package/dist/mailchimp/docs/marketing/DOC.md +1420 -0
- package/dist/meilisearch/docs/search/DOC.md +1241 -0
- package/dist/microsoft/docs/onedrive/javascript/DOC.md +1421 -0
- package/dist/microsoft/docs/onedrive/python/DOC.md +1549 -0
- package/dist/mongodb/docs/atlas/DOC.md +2041 -0
- package/dist/notion/docs/workspace-api/javascript/DOC.md +1435 -0
- package/dist/notion/docs/workspace-api/python/DOC.md +1400 -0
- package/dist/okta/docs/identity/javascript/DOC.md +1171 -0
- package/dist/okta/docs/identity/python/DOC.md +1401 -0
- package/dist/openai/docs/chat/javascript/DOC.md +407 -0
- package/dist/openai/docs/chat/python/DOC.md +568 -0
- package/dist/paypal/docs/checkout/DOC.md +278 -0
- package/dist/pinecone/docs/sdk/javascript/DOC.md +984 -0
- package/dist/pinecone/docs/sdk/python/DOC.md +1395 -0
- package/dist/plaid/docs/banking/javascript/DOC.md +1163 -0
- package/dist/plaid/docs/banking/python/DOC.md +1203 -0
- package/dist/playwright-community/skills/login-flows/SKILL.md +108 -0
- package/dist/postmark/docs/transactional-email/DOC.md +1168 -0
- package/dist/prisma/docs/orm/javascript/DOC.md +1419 -0
- package/dist/prisma/docs/orm/python/DOC.md +1317 -0
- package/dist/qdrant/docs/vector-search/javascript/DOC.md +1221 -0
- package/dist/qdrant/docs/vector-search/python/DOC.md +1653 -0
- package/dist/rabbitmq/docs/message-queue/javascript/DOC.md +1193 -0
- package/dist/rabbitmq/docs/message-queue/python/DOC.md +1243 -0
- package/dist/razorpay/docs/payments/javascript/DOC.md +1219 -0
- package/dist/razorpay/docs/payments/python/DOC.md +1330 -0
- package/dist/redis/docs/key-value/javascript/DOC.md +1851 -0
- package/dist/redis/docs/key-value/python/DOC.md +2054 -0
- package/dist/registry.json +2817 -0
- package/dist/replicate/docs/model-hosting/DOC.md +1318 -0
- package/dist/resend/docs/email/DOC.md +1271 -0
- package/dist/salesforce/docs/crm/javascript/DOC.md +1241 -0
- package/dist/salesforce/docs/crm/python/DOC.md +1183 -0
- package/dist/search-index.json +1 -0
- package/dist/sendgrid/docs/email-api/javascript/DOC.md +371 -0
- package/dist/sendgrid/docs/email-api/python/DOC.md +656 -0
- package/dist/sentry/docs/error-tracking/javascript/DOC.md +1073 -0
- package/dist/sentry/docs/error-tracking/python/DOC.md +1309 -0
- package/dist/shopify/docs/storefront/DOC.md +457 -0
- package/dist/slack/docs/workspace/javascript/DOC.md +933 -0
- package/dist/slack/docs/workspace/python/DOC.md +271 -0
- package/dist/square/docs/payments/javascript/DOC.md +1855 -0
- package/dist/square/docs/payments/python/DOC.md +1728 -0
- package/dist/stripe/docs/api/DOC.md +1727 -0
- package/dist/stripe/docs/payments/DOC.md +1726 -0
- package/dist/stytch/docs/auth/javascript/DOC.md +1813 -0
- package/dist/stytch/docs/auth/python/DOC.md +1962 -0
- package/dist/supabase/docs/client/DOC.md +1606 -0
- package/dist/twilio/docs/messaging/python/DOC.md +469 -0
- package/dist/twilio/docs/messaging/typescript/DOC.md +946 -0
- package/dist/vercel/docs/platform/DOC.md +1940 -0
- package/dist/weaviate/docs/vector-db/javascript/DOC.md +1268 -0
- package/dist/weaviate/docs/vector-db/python/DOC.md +1388 -0
- package/dist/zendesk/docs/support/javascript/DOC.md +2150 -0
- package/dist/zendesk/docs/support/python/DOC.md +2297 -0
- package/package.json +22 -6
- package/skills/get-api-docs/SKILL.md +84 -0
- package/src/commands/annotate.js +83 -0
- package/src/commands/build.js +12 -1
- package/src/commands/feedback.js +150 -0
- package/src/commands/get.js +83 -42
- package/src/commands/search.js +7 -0
- package/src/index.js +43 -17
- package/src/lib/analytics.js +90 -0
- package/src/lib/annotations.js +57 -0
- package/src/lib/bm25.js +170 -0
- package/src/lib/cache.js +69 -6
- package/src/lib/config.js +8 -3
- package/src/lib/identity.js +99 -0
- package/src/lib/registry.js +103 -20
- package/src/lib/telemetry.js +86 -0
- package/src/mcp/server.js +177 -0
- package/src/mcp/tools.js +251 -0
|
@@ -0,0 +1,918 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: workers
|
|
3
|
+
description: "Cloudflare Workers SDK for building edge functions with KV and R2 storage in JavaScript/TypeScript"
|
|
4
|
+
metadata:
|
|
5
|
+
languages: "javascript"
|
|
6
|
+
versions: "5.2.0"
|
|
7
|
+
updated-on: "2026-03-01"
|
|
8
|
+
source: maintainer
|
|
9
|
+
tags: "cloudflare,workers,edge,kv,r2"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Cloudflare API Coding Guidelines (JavaScript/TypeScript)
|
|
13
|
+
|
|
14
|
+
You are a Cloudflare API coding expert. Help me with writing code using the Cloudflare API calling the official libraries and SDKs.
|
|
15
|
+
|
|
16
|
+
You can find the official SDK documentation and code samples here:
|
|
17
|
+
https://developers.cloudflare.com/api/
|
|
18
|
+
|
|
19
|
+
## Golden Rule: Use the Correct and Current SDK
|
|
20
|
+
|
|
21
|
+
Always use the official Cloudflare TypeScript SDK to interact with the Cloudflare API, which is the standard library for all Cloudflare API interactions. Do not use unofficial libraries or deprecated packages.
|
|
22
|
+
|
|
23
|
+
- **Library Name:** Cloudflare TypeScript SDK
|
|
24
|
+
- **NPM Package:** `cloudflare`
|
|
25
|
+
- **Legacy Libraries:** Avoid unofficial packages or legacy clients
|
|
26
|
+
|
|
27
|
+
**Installation:**
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install cloudflare
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**APIs and Usage:**
|
|
34
|
+
|
|
35
|
+
- **Correct:** `import Cloudflare from 'cloudflare'`
|
|
36
|
+
- **Correct:** `const client = new Cloudflare({})`
|
|
37
|
+
- **Correct:** `await client.zones.create(...)`
|
|
38
|
+
- **Correct:** `await client.dns.records.create(...)`
|
|
39
|
+
- **Incorrect:** `CloudflareClient` or `CloudflareAPI`
|
|
40
|
+
- **Incorrect:** Using deprecated multipart form data APIs directly
|
|
41
|
+
- **Incorrect:** Unofficial wrapper libraries
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
Install the Cloudflare SDK:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install cloudflare
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Set your API token as an environment variable:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
export CLOUDFLARE_API_TOKEN='your_api_token_here'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Initialization
|
|
58
|
+
|
|
59
|
+
The `cloudflare` library requires creating a `Cloudflare` instance for all API calls.
|
|
60
|
+
|
|
61
|
+
- Always use `const client = new Cloudflare({})` to create an instance.
|
|
62
|
+
- Set the `CLOUDFLARE_API_TOKEN` environment variable, which will be picked up automatically.
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
import Cloudflare from 'cloudflare';
|
|
66
|
+
|
|
67
|
+
// Uses the CLOUDFLARE_API_TOKEN environment variable if apiToken not specified
|
|
68
|
+
const client = new Cloudflare({});
|
|
69
|
+
|
|
70
|
+
// Or pass the API token directly
|
|
71
|
+
// const client = new Cloudflare({ apiToken: process.env.CLOUDFLARE_API_TOKEN });
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Alternative Authentication
|
|
75
|
+
|
|
76
|
+
You can also authenticate with API email and key (legacy method):
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
const client = new Cloudflare({
|
|
80
|
+
apiEmail: process.env.CLOUDFLARE_API_EMAIL,
|
|
81
|
+
apiKey: process.env.CLOUDFLARE_API_KEY,
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Zone Management
|
|
86
|
+
|
|
87
|
+
Zones are the foundation of Cloudflare - each zone represents a domain.
|
|
88
|
+
|
|
89
|
+
### Create a Zone
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
import Cloudflare from 'cloudflare';
|
|
93
|
+
|
|
94
|
+
const client = new Cloudflare({});
|
|
95
|
+
|
|
96
|
+
async function run() {
|
|
97
|
+
const zone = await client.zones.create({
|
|
98
|
+
account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
|
|
99
|
+
name: 'example.com',
|
|
100
|
+
type: 'full',
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
console.log(zone.id);
|
|
104
|
+
console.log(zone.name);
|
|
105
|
+
console.log(zone.status);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
run();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Get Zone Details
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
const zone = await client.zones.get({
|
|
115
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
console.log(zone.name);
|
|
119
|
+
console.log(zone.status);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### List Zones
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
// List all zones with auto-pagination
|
|
126
|
+
async function listAllZones() {
|
|
127
|
+
const zones = [];
|
|
128
|
+
for await (const zone of client.zones.list()) {
|
|
129
|
+
zones.push(zone);
|
|
130
|
+
}
|
|
131
|
+
return zones;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Or with filtering
|
|
135
|
+
const response = await client.zones.list({
|
|
136
|
+
account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
|
|
137
|
+
status: 'active',
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Edit a Zone
|
|
142
|
+
|
|
143
|
+
```javascript
|
|
144
|
+
await client.zones.edit(
|
|
145
|
+
{
|
|
146
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
paused: false,
|
|
150
|
+
type: 'full',
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Delete a Zone
|
|
156
|
+
|
|
157
|
+
```javascript
|
|
158
|
+
await client.zones.delete({
|
|
159
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## DNS Records Management
|
|
164
|
+
|
|
165
|
+
Manage DNS records for your zones.
|
|
166
|
+
|
|
167
|
+
### Create DNS Record
|
|
168
|
+
|
|
169
|
+
```javascript
|
|
170
|
+
import Cloudflare from 'cloudflare';
|
|
171
|
+
|
|
172
|
+
const client = new Cloudflare({});
|
|
173
|
+
|
|
174
|
+
async function run() {
|
|
175
|
+
const record = await client.dns.records.create({
|
|
176
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
177
|
+
type: 'A',
|
|
178
|
+
name: 'www',
|
|
179
|
+
content: '192.0.2.1',
|
|
180
|
+
ttl: 3600,
|
|
181
|
+
proxied: true,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
console.log(record.id);
|
|
185
|
+
console.log(record.name);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
run();
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### List DNS Records
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
// List all DNS records for a zone
|
|
195
|
+
const records = await client.dns.records.list({
|
|
196
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
for (const record of records.result) {
|
|
200
|
+
console.log(`${record.type} ${record.name} -> ${record.content}`);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Filter by record type
|
|
204
|
+
const aRecords = await client.dns.records.list({
|
|
205
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
206
|
+
type: 'A',
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Update DNS Record
|
|
211
|
+
|
|
212
|
+
```javascript
|
|
213
|
+
await client.dns.records.update({
|
|
214
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
215
|
+
record_id: '372e67954025e0ba6aaa6d586b9e0b59',
|
|
216
|
+
type: 'A',
|
|
217
|
+
name: 'www',
|
|
218
|
+
content: '192.0.2.2',
|
|
219
|
+
ttl: 3600,
|
|
220
|
+
proxied: true,
|
|
221
|
+
});
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Delete DNS Record
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
await client.dns.records.delete({
|
|
228
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
229
|
+
record_id: '372e67954025e0ba6aaa6d586b9e0b59',
|
|
230
|
+
});
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Workers Management
|
|
234
|
+
|
|
235
|
+
Cloudflare Workers allows you to run JavaScript at the edge.
|
|
236
|
+
|
|
237
|
+
### Upload a Worker Script
|
|
238
|
+
|
|
239
|
+
```javascript
|
|
240
|
+
import Cloudflare from 'cloudflare';
|
|
241
|
+
import fs from 'fs';
|
|
242
|
+
|
|
243
|
+
const client = new Cloudflare({});
|
|
244
|
+
|
|
245
|
+
async function uploadWorker() {
|
|
246
|
+
const scriptContent = fs.readFileSync('./worker.js', 'utf8');
|
|
247
|
+
|
|
248
|
+
await client.workers.scripts.update({
|
|
249
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
250
|
+
script_name: 'my-worker',
|
|
251
|
+
'<any part name>': scriptContent,
|
|
252
|
+
metadata: {
|
|
253
|
+
main_module: 'worker.js',
|
|
254
|
+
compatibility_date: '2025-01-01',
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
uploadWorker();
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### List Worker Scripts
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
const scripts = await client.workers.scripts.list({
|
|
266
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
for (const script of scripts.result) {
|
|
270
|
+
console.log(script.id);
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Get Worker Script
|
|
275
|
+
|
|
276
|
+
```javascript
|
|
277
|
+
const script = await client.workers.scripts.get({
|
|
278
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
279
|
+
script_name: 'my-worker',
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Delete Worker Script
|
|
284
|
+
|
|
285
|
+
```javascript
|
|
286
|
+
await client.workers.scripts.delete({
|
|
287
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
288
|
+
script_name: 'my-worker',
|
|
289
|
+
});
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Workers KV Storage
|
|
293
|
+
|
|
294
|
+
Workers KV is a global, low-latency key-value data store.
|
|
295
|
+
|
|
296
|
+
### Create KV Namespace
|
|
297
|
+
|
|
298
|
+
```javascript
|
|
299
|
+
const namespace = await client.kv.namespaces.create({
|
|
300
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
301
|
+
title: 'my-kv-namespace',
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
console.log(namespace.id);
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### List KV Namespaces
|
|
308
|
+
|
|
309
|
+
```javascript
|
|
310
|
+
const namespaces = await client.kv.namespaces.list({
|
|
311
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
for (const ns of namespaces.result) {
|
|
315
|
+
console.log(`${ns.id}: ${ns.title}`);
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Write KV Value
|
|
320
|
+
|
|
321
|
+
```javascript
|
|
322
|
+
await client.kv.namespaces.values.update({
|
|
323
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
324
|
+
namespace_id: '0f2ac74b498b48028cb68387c421e279',
|
|
325
|
+
key_name: 'my-key',
|
|
326
|
+
metadata: JSON.stringify({ someMetadata: 'value' }),
|
|
327
|
+
value: 'my-value',
|
|
328
|
+
});
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Read KV Value
|
|
332
|
+
|
|
333
|
+
```javascript
|
|
334
|
+
const value = await client.kv.namespaces.values.get({
|
|
335
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
336
|
+
namespace_id: '0f2ac74b498b48028cb68387c421e279',
|
|
337
|
+
key_name: 'my-key',
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
console.log(value);
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Delete KV Value
|
|
344
|
+
|
|
345
|
+
```javascript
|
|
346
|
+
await client.kv.namespaces.values.delete({
|
|
347
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
348
|
+
namespace_id: '0f2ac74b498b48028cb68387c421e279',
|
|
349
|
+
key_name: 'my-key',
|
|
350
|
+
});
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Delete KV Namespace
|
|
354
|
+
|
|
355
|
+
```javascript
|
|
356
|
+
await client.kv.namespaces.delete({
|
|
357
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
358
|
+
namespace_id: '0f2ac74b498b48028cb68387c421e279',
|
|
359
|
+
});
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
## R2 Object Storage
|
|
363
|
+
|
|
364
|
+
R2 is S3-compatible object storage without egress fees.
|
|
365
|
+
|
|
366
|
+
### Create R2 Bucket
|
|
367
|
+
|
|
368
|
+
```javascript
|
|
369
|
+
const bucket = await client.r2.buckets.create({
|
|
370
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
371
|
+
name: 'my-bucket',
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
console.log(bucket.name);
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### List R2 Buckets
|
|
378
|
+
|
|
379
|
+
```javascript
|
|
380
|
+
const buckets = await client.r2.buckets.list({
|
|
381
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
for (const bucket of buckets.buckets) {
|
|
385
|
+
console.log(bucket.name);
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Delete R2 Bucket
|
|
390
|
+
|
|
391
|
+
```javascript
|
|
392
|
+
await client.r2.buckets.delete({
|
|
393
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
394
|
+
bucket_name: 'my-bucket',
|
|
395
|
+
});
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## D1 Database
|
|
399
|
+
|
|
400
|
+
D1 is Cloudflare's native serverless SQL database.
|
|
401
|
+
|
|
402
|
+
### Create D1 Database
|
|
403
|
+
|
|
404
|
+
```javascript
|
|
405
|
+
const database = await client.d1.database.create({
|
|
406
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
407
|
+
name: 'my-database',
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
console.log(database.uuid);
|
|
411
|
+
console.log(database.name);
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### List D1 Databases
|
|
415
|
+
|
|
416
|
+
```javascript
|
|
417
|
+
const databases = await client.d1.database.list({
|
|
418
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
for (const db of databases.result) {
|
|
422
|
+
console.log(`${db.uuid}: ${db.name}`);
|
|
423
|
+
}
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### Query D1 Database
|
|
427
|
+
|
|
428
|
+
```javascript
|
|
429
|
+
const result = await client.d1.database.query({
|
|
430
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
431
|
+
database_id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
|
|
432
|
+
sql: 'SELECT * FROM users WHERE id = ?',
|
|
433
|
+
params: ['123'],
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
console.log(result);
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Delete D1 Database
|
|
440
|
+
|
|
441
|
+
```javascript
|
|
442
|
+
await client.d1.database.delete({
|
|
443
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
444
|
+
database_id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
|
|
445
|
+
});
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
## Pages Projects
|
|
449
|
+
|
|
450
|
+
Cloudflare Pages allows you to deploy static sites and full-stack applications.
|
|
451
|
+
|
|
452
|
+
### Create Pages Project
|
|
453
|
+
|
|
454
|
+
```javascript
|
|
455
|
+
const project = await client.pages.projects.create({
|
|
456
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
457
|
+
name: 'my-project',
|
|
458
|
+
production_branch: 'main',
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
console.log(project.name);
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
### List Pages Projects
|
|
465
|
+
|
|
466
|
+
```javascript
|
|
467
|
+
const projects = await client.pages.projects.list({
|
|
468
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
for (const project of projects.result) {
|
|
472
|
+
console.log(project.name);
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
### Get Pages Project
|
|
477
|
+
|
|
478
|
+
```javascript
|
|
479
|
+
const project = await client.pages.projects.get({
|
|
480
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
481
|
+
project_name: 'my-project',
|
|
482
|
+
});
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### Delete Pages Project
|
|
486
|
+
|
|
487
|
+
```javascript
|
|
488
|
+
await client.pages.projects.delete({
|
|
489
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
490
|
+
project_name: 'my-project',
|
|
491
|
+
});
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
## Account Management
|
|
495
|
+
|
|
496
|
+
### List Accounts
|
|
497
|
+
|
|
498
|
+
```javascript
|
|
499
|
+
// Auto-pagination
|
|
500
|
+
async function getAllAccounts() {
|
|
501
|
+
const accounts = [];
|
|
502
|
+
for await (const account of client.accounts.list()) {
|
|
503
|
+
accounts.push(account);
|
|
504
|
+
}
|
|
505
|
+
return accounts;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// Manual pagination
|
|
509
|
+
let page = await client.accounts.list({ per_page: 20 });
|
|
510
|
+
for (const account of page.result) {
|
|
511
|
+
console.log(account.name);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
while (page.hasNextPage()) {
|
|
515
|
+
page = await page.getNextPage();
|
|
516
|
+
// Process next page
|
|
517
|
+
}
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
### Get Account Details
|
|
521
|
+
|
|
522
|
+
```javascript
|
|
523
|
+
const account = await client.accounts.get({
|
|
524
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
console.log(account.name);
|
|
528
|
+
console.log(account.settings);
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
## Load Balancers
|
|
532
|
+
|
|
533
|
+
### Create Load Balancer
|
|
534
|
+
|
|
535
|
+
```javascript
|
|
536
|
+
const loadBalancer = await client.loadBalancers.create({
|
|
537
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
538
|
+
name: 'my-load-balancer',
|
|
539
|
+
default_pools: ['17b5962d775c646f3f9725cbc7a53df4'],
|
|
540
|
+
fallback_pool: '17b5962d775c646f3f9725cbc7a53df4',
|
|
541
|
+
ttl: 30,
|
|
542
|
+
steering_policy: 'random',
|
|
543
|
+
});
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
### List Load Balancers
|
|
547
|
+
|
|
548
|
+
```javascript
|
|
549
|
+
const loadBalancers = await client.loadBalancers.list({
|
|
550
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
551
|
+
});
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
### Create Load Balancer Pool
|
|
555
|
+
|
|
556
|
+
```javascript
|
|
557
|
+
const pool = await client.loadBalancers.pools.create({
|
|
558
|
+
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
559
|
+
name: 'my-pool',
|
|
560
|
+
origins: [
|
|
561
|
+
{
|
|
562
|
+
name: 'origin-1',
|
|
563
|
+
address: '192.0.2.1',
|
|
564
|
+
enabled: true,
|
|
565
|
+
weight: 1,
|
|
566
|
+
},
|
|
567
|
+
],
|
|
568
|
+
});
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
## Cache Management
|
|
572
|
+
|
|
573
|
+
### Purge Cache
|
|
574
|
+
|
|
575
|
+
```javascript
|
|
576
|
+
// Purge everything
|
|
577
|
+
await client.cache.purge({
|
|
578
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
579
|
+
purge_everything: true,
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
// Purge by URLs
|
|
583
|
+
await client.cache.purge({
|
|
584
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
585
|
+
files: [
|
|
586
|
+
'https://example.com/file1.jpg',
|
|
587
|
+
'https://example.com/file2.jpg',
|
|
588
|
+
],
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
// Purge by tags
|
|
592
|
+
await client.cache.purge({
|
|
593
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
594
|
+
tags: ['tag1', 'tag2'],
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
// Purge by prefix
|
|
598
|
+
await client.cache.purge({
|
|
599
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
600
|
+
prefixes: ['https://example.com/images/'],
|
|
601
|
+
});
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
## WAF and Firewall Rules
|
|
605
|
+
|
|
606
|
+
### Create Firewall Rule
|
|
607
|
+
|
|
608
|
+
```javascript
|
|
609
|
+
const rule = await client.firewall.rules.create({
|
|
610
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
611
|
+
filter: {
|
|
612
|
+
expression: '(ip.src eq 192.0.2.1)',
|
|
613
|
+
},
|
|
614
|
+
action: 'block',
|
|
615
|
+
description: 'Block specific IP',
|
|
616
|
+
});
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
### List Firewall Rules
|
|
620
|
+
|
|
621
|
+
```javascript
|
|
622
|
+
const rules = await client.firewall.rules.list({
|
|
623
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
624
|
+
});
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
## SSL/TLS Certificate Management
|
|
628
|
+
|
|
629
|
+
### List SSL Certificates
|
|
630
|
+
|
|
631
|
+
```javascript
|
|
632
|
+
const certificates = await client.ssl.certificates.list({
|
|
633
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
for (const cert of certificates.result) {
|
|
637
|
+
console.log(cert.id);
|
|
638
|
+
console.log(cert.hosts);
|
|
639
|
+
}
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
### Get SSL Settings
|
|
643
|
+
|
|
644
|
+
```javascript
|
|
645
|
+
const settings = await client.ssl.settings.get({
|
|
646
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
647
|
+
});
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
## File Uploads
|
|
651
|
+
|
|
652
|
+
The SDK supports multiple file input formats for endpoints that require file uploads:
|
|
653
|
+
|
|
654
|
+
```javascript
|
|
655
|
+
import fs from 'fs';
|
|
656
|
+
import Cloudflare, { toFile } from 'cloudflare';
|
|
657
|
+
|
|
658
|
+
const client = new Cloudflare({});
|
|
659
|
+
|
|
660
|
+
// Using Node.js streams (recommended)
|
|
661
|
+
await client.apiGateway.userSchemas.create({
|
|
662
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
663
|
+
file: fs.createReadStream('/path/to/file'),
|
|
664
|
+
kind: 'openapi_v3',
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
// Using the File API
|
|
668
|
+
await client.apiGateway.userSchemas.create({
|
|
669
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
670
|
+
file: new File(['my bytes'], 'file'),
|
|
671
|
+
kind: 'openapi_v3',
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
// Using fetch Response
|
|
675
|
+
await client.apiGateway.userSchemas.create({
|
|
676
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
677
|
+
file: await fetch('https://somesite/file'),
|
|
678
|
+
kind: 'openapi_v3',
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
// Using the toFile helper
|
|
682
|
+
await client.apiGateway.userSchemas.create({
|
|
683
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
684
|
+
file: await toFile(Buffer.from('my bytes'), 'file'),
|
|
685
|
+
kind: 'openapi_v3',
|
|
686
|
+
});
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
## Error Handling
|
|
690
|
+
|
|
691
|
+
The SDK provides comprehensive error handling with specific error types:
|
|
692
|
+
|
|
693
|
+
```javascript
|
|
694
|
+
import Cloudflare from 'cloudflare';
|
|
695
|
+
|
|
696
|
+
const client = new Cloudflare({});
|
|
697
|
+
|
|
698
|
+
try {
|
|
699
|
+
const zone = await client.zones.get({
|
|
700
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
701
|
+
});
|
|
702
|
+
} catch (err) {
|
|
703
|
+
if (err instanceof Cloudflare.APIError) {
|
|
704
|
+
console.log(err.status); // HTTP status code (e.g., 400, 404)
|
|
705
|
+
console.log(err.name); // Error type (e.g., BadRequestError)
|
|
706
|
+
console.log(err.headers); // Response headers
|
|
707
|
+
console.log(err.message); // Error message
|
|
708
|
+
} else {
|
|
709
|
+
throw err;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
### Error Types
|
|
715
|
+
|
|
716
|
+
| Status Code | Error Type |
|
|
717
|
+
| ----------- | ----------------------------- |
|
|
718
|
+
| 400 | `BadRequestError` |
|
|
719
|
+
| 401 | `AuthenticationError` |
|
|
720
|
+
| 403 | `PermissionDeniedError` |
|
|
721
|
+
| 404 | `NotFoundError` |
|
|
722
|
+
| 422 | `UnprocessableEntityError` |
|
|
723
|
+
| 429 | `RateLimitError` |
|
|
724
|
+
| >=500 | `InternalServerError` |
|
|
725
|
+
| N/A | `APIConnectionError` |
|
|
726
|
+
|
|
727
|
+
All errors extend from `APIError`.
|
|
728
|
+
|
|
729
|
+
## Advanced Configuration
|
|
730
|
+
|
|
731
|
+
### Retries
|
|
732
|
+
|
|
733
|
+
Configure automatic retry behavior:
|
|
734
|
+
|
|
735
|
+
```javascript
|
|
736
|
+
// Configure default retries for all requests
|
|
737
|
+
const client = new Cloudflare({
|
|
738
|
+
maxRetries: 3, // default is 2
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
// Or configure per-request
|
|
742
|
+
await client.zones.get(
|
|
743
|
+
{
|
|
744
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
745
|
+
},
|
|
746
|
+
{
|
|
747
|
+
maxRetries: 5,
|
|
748
|
+
}
|
|
749
|
+
);
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
The SDK automatically retries:
|
|
753
|
+
- Connection errors
|
|
754
|
+
- 408 Request Timeout
|
|
755
|
+
- 409 Conflict
|
|
756
|
+
- 429 Rate Limit
|
|
757
|
+
- >=500 Internal errors
|
|
758
|
+
|
|
759
|
+
### Timeouts
|
|
760
|
+
|
|
761
|
+
Set custom timeout values:
|
|
762
|
+
|
|
763
|
+
```javascript
|
|
764
|
+
// Configure default timeout for all requests
|
|
765
|
+
const client = new Cloudflare({
|
|
766
|
+
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
// Override per-request
|
|
770
|
+
await client.zones.edit(
|
|
771
|
+
{
|
|
772
|
+
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
timeout: 5 * 1000,
|
|
776
|
+
}
|
|
777
|
+
);
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
### Custom Fetch Implementation
|
|
781
|
+
|
|
782
|
+
Provide a custom fetch function for logging or middleware:
|
|
783
|
+
|
|
784
|
+
```javascript
|
|
785
|
+
import { fetch } from 'undici';
|
|
786
|
+
import Cloudflare from 'cloudflare';
|
|
787
|
+
|
|
788
|
+
const client = new Cloudflare({
|
|
789
|
+
fetch: async (url, init) => {
|
|
790
|
+
console.log('Request:', url, init);
|
|
791
|
+
const response = await fetch(url, init);
|
|
792
|
+
console.log('Response:', response);
|
|
793
|
+
return response;
|
|
794
|
+
},
|
|
795
|
+
});
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
### Accessing Raw Response Data
|
|
799
|
+
|
|
800
|
+
Access underlying HTTP response data:
|
|
801
|
+
|
|
802
|
+
```javascript
|
|
803
|
+
// Get raw response
|
|
804
|
+
const response = await client.zones
|
|
805
|
+
.create({
|
|
806
|
+
account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
|
|
807
|
+
name: 'example.com',
|
|
808
|
+
type: 'full',
|
|
809
|
+
})
|
|
810
|
+
.asResponse();
|
|
811
|
+
|
|
812
|
+
console.log(response.headers.get('X-Request-ID'));
|
|
813
|
+
|
|
814
|
+
// Get both data and response
|
|
815
|
+
const { data: zone, response: raw } = await client.zones
|
|
816
|
+
.create({
|
|
817
|
+
account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
|
|
818
|
+
name: 'example.com',
|
|
819
|
+
type: 'full',
|
|
820
|
+
})
|
|
821
|
+
.withResponse();
|
|
822
|
+
|
|
823
|
+
console.log(zone.id);
|
|
824
|
+
console.log(raw.headers);
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
## Pagination
|
|
828
|
+
|
|
829
|
+
Handle paginated responses automatically or manually:
|
|
830
|
+
|
|
831
|
+
```javascript
|
|
832
|
+
// Auto-pagination (recommended)
|
|
833
|
+
async function fetchAllZones() {
|
|
834
|
+
const allZones = [];
|
|
835
|
+
for await (const zone of client.zones.list()) {
|
|
836
|
+
allZones.push(zone);
|
|
837
|
+
}
|
|
838
|
+
return allZones;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
// Manual pagination
|
|
842
|
+
let page = await client.zones.list({ per_page: 20 });
|
|
843
|
+
for (const zone of page.result) {
|
|
844
|
+
console.log(zone.name);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
while (page.hasNextPage()) {
|
|
848
|
+
page = await page.getNextPage();
|
|
849
|
+
for (const zone of page.result) {
|
|
850
|
+
console.log(zone.name);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
## TypeScript Support
|
|
856
|
+
|
|
857
|
+
The SDK includes full TypeScript definitions:
|
|
858
|
+
|
|
859
|
+
```typescript
|
|
860
|
+
import Cloudflare from 'cloudflare';
|
|
861
|
+
|
|
862
|
+
const client = new Cloudflare({});
|
|
863
|
+
|
|
864
|
+
// Use typed parameters
|
|
865
|
+
const params: Cloudflare.ZoneCreateParams = {
|
|
866
|
+
account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
|
|
867
|
+
name: 'example.com',
|
|
868
|
+
type: 'full',
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
// Get typed response
|
|
872
|
+
const zone: Cloudflare.Zone = await client.zones.create(params);
|
|
873
|
+
|
|
874
|
+
// TypeScript will validate all fields
|
|
875
|
+
console.log(zone.id);
|
|
876
|
+
console.log(zone.name);
|
|
877
|
+
console.log(zone.status);
|
|
878
|
+
```
|
|
879
|
+
|
|
880
|
+
## Custom Endpoints
|
|
881
|
+
|
|
882
|
+
Make requests to endpoints not yet in the typed SDK:
|
|
883
|
+
|
|
884
|
+
```javascript
|
|
885
|
+
// POST request to custom endpoint
|
|
886
|
+
await client.post('/some/path', {
|
|
887
|
+
body: { some_prop: 'foo' },
|
|
888
|
+
query: { some_query_arg: 'bar' },
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
// GET request
|
|
892
|
+
const response = await client.get('/custom/endpoint', {
|
|
893
|
+
query: { filter: 'active' },
|
|
894
|
+
});
|
|
895
|
+
```
|
|
896
|
+
|
|
897
|
+
For undocumented parameters in typed methods:
|
|
898
|
+
|
|
899
|
+
```typescript
|
|
900
|
+
client.zones.create({
|
|
901
|
+
account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
|
|
902
|
+
name: 'example.com',
|
|
903
|
+
// @ts-expect-error undocumented_param is not in the types yet
|
|
904
|
+
undocumented_param: 'some_value',
|
|
905
|
+
});
|
|
906
|
+
```
|
|
907
|
+
|
|
908
|
+
## Useful Links
|
|
909
|
+
|
|
910
|
+
- Documentation: https://developers.cloudflare.com/api/
|
|
911
|
+
- SDK Reference: https://github.com/cloudflare/cloudflare-typescript
|
|
912
|
+
- API Keys: https://dash.cloudflare.com/profile/api-tokens
|
|
913
|
+
- Workers Docs: https://developers.cloudflare.com/workers/
|
|
914
|
+
- R2 Docs: https://developers.cloudflare.com/r2/
|
|
915
|
+
- D1 Docs: https://developers.cloudflare.com/d1/
|
|
916
|
+
- KV Docs: https://developers.cloudflare.com/kv/
|
|
917
|
+
- Pages Docs: https://developers.cloudflare.com/pages/
|
|
918
|
+
- Rate Limits: https://developers.cloudflare.com/fundamentals/api/reference/limits/
|