@robinpath/cloudflare
0.1.2Node.jsPublicCloudflare module for RobinPath.
Cloudflare
Cloudflare module for RobinPath.
Package: @robinpath/cloudflare | Category: Devops | Type: Integration
Authentication
cloudflare.setCredentials "user@example.com" "your-global-api-key"
Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.
Use Cases
Use the cloudflare module when you need to:
- List Cloudflare zones -- Use
cloudflare.listZonesto perform this operation - Get details of a specific zone -- Use
cloudflare.getZoneto perform this operation - Create a new Cloudflare zone -- Use
cloudflare.createZoneto perform this operation - Delete a Cloudflare zone -- Use
cloudflare.deleteZoneto perform this operation - Purge cache for a zone (all or selective by URLs/tags/hosts/prefixes) -- Use
cloudflare.purgeCacheto perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
setToken | Set Cloudflare API token for authentication | { success, method } |
setCredentials | Set Cloudflare global API key credentials | { success, method } |
listZones | List Cloudflare zones | Array of zone objects |
getZone | Get details of a specific zone | Zone details object |
createZone | Create a new Cloudflare zone | Created zone object |
deleteZone | Delete a Cloudflare zone | { success, zoneId } |
purgeCache | Purge cache for a zone (all or selective by URLs/tags/hosts/prefixes) | Purge result object |
listDnsRecords | List DNS records for a zone | Array of DNS record objects |
getDnsRecord | Get a specific DNS record | DNS record object |
createDnsRecord | Create a DNS record in a zone | Created DNS record object |
updateDnsRecord | Update an existing DNS record | Updated DNS record object |
deleteDnsRecord | Delete a DNS record from a zone | { success, zoneId, recordId } |
listWorkers | List Workers scripts for an account | Array of Worker script objects |
getWorkerScript | Get the content of a Worker script | Worker script source code |
deployWorker | Deploy a Worker script | Deployed Worker result object |
deleteWorker | Delete a Worker script | { success, accountId, scriptName } |
listKvNamespaces | List KV namespaces for an account | Array of KV namespace objects |
createKvNamespace | Create a KV namespace | Created KV namespace object |
deleteKvNamespace | Delete a KV namespace | { success, accountId, namespaceId } |
kvGet | Read a value from KV storage | Value stored at the key, or null if not found |
kvPut | Write a value to KV storage | { success, key } |
kvDelete | Delete a key from KV storage | { success, key } |
kvListKeys | List keys in a KV namespace | Array of key objects |
listR2Buckets | List R2 buckets for an account | Array of R2 bucket objects |
createR2Bucket | Create an R2 bucket | Created R2 bucket object |
deleteR2Bucket | Delete an R2 bucket | { success, accountId, bucketName } |
listPages | List Cloudflare Pages projects | Array of Pages project objects |
getPageProject | Get details of a Cloudflare Pages project | Pages project details object |
getZoneAnalytics | Get analytics data for a zone | Zone analytics dashboard data |
Functions
setToken
Set Cloudflare API token for authentication
Module: cloudflare | Returns: object -- { success, method }
cloudflare.setToken "your-api-token"
| Parameter | Type | Required | Description |
|---|---|---|---|
apiToken | string | Yes | Cloudflare API token |
setCredentials
Set Cloudflare global API key credentials
Module: cloudflare | Returns: object -- { success, method }
cloudflare.setCredentials "user@example.com" "your-global-api-key"
| Parameter | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Cloudflare account email |
apiKey | string | Yes | Cloudflare global API key |
listZones
List Cloudflare zones
Module: cloudflare | Returns: array -- Array of zone objects
cloudflare.listZones {"name": "example.com"}
| Parameter | Type | Required | Description |
|---|---|---|---|
options | object | No | Filter options: name, status, page, perPage |
getZone
Get details of a specific zone
Module: cloudflare | Returns: object -- Zone details object
cloudflare.getZone "zone-id-here"
| Parameter | Type | Required | Description |
|---|---|---|---|
zoneId | string | Yes | Zone ID |
createZone
Create a new Cloudflare zone
Module: cloudflare | Returns: object -- Created zone object
cloudflare.createZone "example.com" {"accountId": "abc123"}
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Domain name for the zone |
options | object | No | Options: accountId, jumpStart, type |
deleteZone
Delete a Cloudflare zone
Module: cloudflare | Returns: object -- { success, zoneId }
cloudflare.deleteZone "zone-id-here"
| Parameter | Type | Required | Description |
|---|---|---|---|
zoneId | string | Yes | Zone ID |
purgeCache
Purge cache for a zone (all or selective by URLs/tags/hosts/prefixes)
Module: cloudflare | Returns: object -- Purge result object
cloudflare.purgeCache "zone-id" {"purgeEverything": true}
| Parameter | Type | Required | Description |
|---|---|---|---|
zoneId | string | Yes | Zone ID |
options | object | No | Options: purgeEverything, files, tags, hosts, prefixes |
listDnsRecords
List DNS records for a zone
Module: cloudflare | Returns: array -- Array of DNS record objects
cloudflare.listDnsRecords "zone-id" {"type": "A"}
| Parameter | Type | Required | Description |
|---|---|---|---|
zoneId | string | Yes | Zone ID |
options | object | No | Filter options: type, name, content, page, perPage |
getDnsRecord
Get a specific DNS record
Module: cloudflare | Returns: object -- DNS record object
cloudflare.getDnsRecord "zone-id" "record-id"
| Parameter | Type | Required | Description |
|---|---|---|---|
zoneId | string | Yes | Zone ID |
recordId | string | Yes | DNS record ID |
createDnsRecord
Create a DNS record in a zone
Module: cloudflare | Returns: object -- Created DNS record object
cloudflare.createDnsRecord "zone-id" "A" "example.com" "1.2.3.4" {"proxied": true}
| Parameter | Type | Required | Description |
|---|---|---|---|
zoneId | string | Yes | Zone ID |
type | string | Yes | Record type (A, AAAA, CNAME, MX, TXT, etc.) |
name | string | Yes | DNS record name |
content | string | Yes | DNS record content/value |
options | object | No | Options: ttl, proxied, priority |
updateDnsRecord
Update an existing DNS record
Module: cloudflare | Returns: object -- Updated DNS record object
cloudflare.updateDnsRecord "zone-id" "record-id" "A" "example.com" "5.6.7.8" {"proxied": true}
| Parameter | Type | Required | Description |
|---|---|---|---|
zoneId | string | Yes | Zone ID |
recordId | string | Yes | DNS record ID |
type | string | Yes | Record type (A, AAAA, CNAME, MX, TXT, etc.) |
name | string | Yes | DNS record name |
content | string | Yes | DNS record content/value |
options | object | No | Options: ttl, proxied, priority |
deleteDnsRecord
Delete a DNS record from a zone
Module: cloudflare | Returns: object -- { success, zoneId, recordId }
cloudflare.deleteDnsRecord "zone-id" "record-id"
| Parameter | Type | Required | Description |
|---|---|---|---|
zoneId | string | Yes | Zone ID |
recordId | string | Yes | DNS record ID |
listWorkers
List Workers scripts for an account
Module: cloudflare | Returns: array -- Array of Worker script objects
cloudflare.listWorkers "account-id"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
getWorkerScript
Get the content of a Worker script
Module: cloudflare | Returns: string -- Worker script source code
cloudflare.getWorkerScript "account-id" "my-worker"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
scriptName | string | Yes | Worker script name |
deployWorker
Deploy a Worker script
Module: cloudflare | Returns: object -- Deployed Worker result object
cloudflare.deployWorker "account-id" "my-worker" "export default { fetch() { return new Response('Hello') } }"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
scriptName | string | Yes | Worker script name |
script | string | Yes | Worker script source code |
options | object | No | Options: mainModule, compatibilityDate, bindings |
deleteWorker
Delete a Worker script
Module: cloudflare | Returns: object -- { success, accountId, scriptName }
cloudflare.deleteWorker "account-id" "my-worker"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
scriptName | string | Yes | Worker script name |
listKvNamespaces
List KV namespaces for an account
Module: cloudflare | Returns: array -- Array of KV namespace objects
cloudflare.listKvNamespaces "account-id"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
options | object | No | Options: page, perPage |
createKvNamespace
Create a KV namespace
Module: cloudflare | Returns: object -- Created KV namespace object
cloudflare.createKvNamespace "account-id" "my-kv-store"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
title | string | Yes | Namespace title |
deleteKvNamespace
Delete a KV namespace
Module: cloudflare | Returns: object -- { success, accountId, namespaceId }
cloudflare.deleteKvNamespace "account-id" "namespace-id"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
namespaceId | string | Yes | KV namespace ID |
kvGet
Read a value from KV storage
Module: cloudflare | Returns: any -- Value stored at the key, or null if not found
cloudflare.kvGet "account-id" "namespace-id" "my-key"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
namespaceId | string | Yes | KV namespace ID |
key | string | Yes | Key to read |
kvPut
Write a value to KV storage
Module: cloudflare | Returns: object -- { success, key }
cloudflare.kvPut "account-id" "namespace-id" "my-key" "my-value" {"expirationTtl": 3600}
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
namespaceId | string | Yes | KV namespace ID |
key | string | Yes | Key to write |
value | any | Yes | Value to store |
options | object | No | Options: expiration (unix timestamp), expirationTtl (seconds) |
kvDelete
Delete a key from KV storage
Module: cloudflare | Returns: object -- { success, key }
cloudflare.kvDelete "account-id" "namespace-id" "my-key"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
namespaceId | string | Yes | KV namespace ID |
key | string | Yes | Key to delete |
kvListKeys
List keys in a KV namespace
Module: cloudflare | Returns: array -- Array of key objects
cloudflare.kvListKeys "account-id" "namespace-id" {"prefix": "user:"}
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
namespaceId | string | Yes | KV namespace ID |
options | object | No | Options: prefix, limit, cursor |
listR2Buckets
List R2 buckets for an account
Module: cloudflare | Returns: array -- Array of R2 bucket objects
cloudflare.listR2Buckets "account-id"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
createR2Bucket
Create an R2 bucket
Module: cloudflare | Returns: object -- Created R2 bucket object
cloudflare.createR2Bucket "account-id" "my-bucket"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
name | string | Yes | Bucket name |
deleteR2Bucket
Delete an R2 bucket
Module: cloudflare | Returns: object -- { success, accountId, bucketName }
cloudflare.deleteR2Bucket "account-id" "my-bucket"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
bucketName | string | Yes | Bucket name |
listPages
List Cloudflare Pages projects
Module: cloudflare | Returns: array -- Array of Pages project objects
cloudflare.listPages "account-id"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
getPageProject
Get details of a Cloudflare Pages project
Module: cloudflare | Returns: object -- Pages project details object
cloudflare.getPageProject "account-id" "my-site"
| Parameter | Type | Required | Description |
|---|---|---|---|
accountId | string | Yes | Cloudflare account ID |
projectName | string | Yes | Pages project name |
getZoneAnalytics
Get analytics data for a zone
Module: cloudflare | Returns: object -- Zone analytics dashboard data
cloudflare.getZoneAnalytics "zone-id" {"since": "-10080", "until": "0"}
| Parameter | Type | Required | Description |
|---|---|---|---|
zoneId | string | Yes | Zone ID |
options | object | No | Options: since (ISO date or negative minutes), until (ISO date or negative minutes) |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
Cloudflare not authenticated. Call cloudflare.setToken or cloudflare.setCredentials first. | Check the error message for details |
Cloudflare API error: ${msg} | Check the error message for details |
Cloudflare API error: ${response.status} ${response.statusText} | Check the error message for details |
API token is required | Check the error message for details |
Both email and API key are required | Check the error message for details |
zoneId is required | Check the error message for details |
Zone name is required | Check the error message for details |
zoneId and recordId are required | Check the error message for details |
@desc "List zones and validate result"
do
set $result as cloudflare.listZones {"name": "example.com"}
if $result != null
print "Success"
else
print "No result"
end
enddo
Recipes
1. List and iterate Zones
Retrieve all items and loop through them.
@desc "Setup authentication"
do
cloudflare.setToken $token
enddo
@desc "List zones and iterate results"
do
set $result as cloudflare.listZones {"name": "example.com"}
each $item in $result
print $item
end
enddo
2. Create a new item with createZone
Create a new resource and capture the result.
@desc "Setup authentication"
do
cloudflare.setToken $token
enddo
@desc "Create zone"
do
set $result as cloudflare.createZone "example.com" {"accountId": "abc123"}
print "Created: " + $result
enddo
3. Create and update workflow
Create an item and then update it.
@desc "Setup authentication"
do
cloudflare.setToken $token
enddo
@desc "Create zone and update dns record"
do
set $created as cloudflare.createZone "example.com" {"accountId": "abc123"}
# Update the created item
cloudflare.updateDnsRecord "zone-id" "record-id" "A" "example.com" "5.6.7.8" {"proxied": true}
enddo
4. Check before creating
List existing items and only create if needed.
@desc "Setup authentication"
do
cloudflare.setToken $token
enddo
@desc "List zones and create zone"
do
set $existing as cloudflare.listZones {"name": "example.com"}
if $existing == null
cloudflare.createZone "example.com" {"accountId": "abc123"}
print "Item created"
else
print "Item already exists"
end
enddo
5. Multi-step Cloudflare workflow
Chain multiple cloudflare operations together.
@desc "Setup authentication"
do
cloudflare.setToken $token
enddo
@desc "List zones, get zone, and more"
do
set $r_listZones as cloudflare.listZones {"name": "example.com"}
set $r_getZone as cloudflare.getZone "zone-id-here"
set $r_createZone as cloudflare.createZone "example.com" {"accountId": "abc123"}
print "All operations complete"
enddo
6. Safe listZones with validation
Check results before proceeding.
@desc "Setup authentication"
do
cloudflare.setToken $token
enddo
@desc "List zones and validate result"
do
set $result as cloudflare.listZones {"name": "example.com"}
if $result != null
print "Success: " + $result
else
print "Operation returned no data"
end
enddo
Related Modules
- docker -- Docker module for complementary functionality
- git -- Git module for complementary functionality
- github -- GitHub module for complementary functionality
- gitlab -- GitLab module for complementary functionality
- vercel -- Vercel module for complementary functionality
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.2 | latest | 1 months ago |
Related Modules
github
JS@robinpathv0.1.1
GitHub module for RobinPath.
bitbucket
JS@robinpathv0.1.2
Bitbucket module for RobinPath.
box
JS@robinpathv0.1.2
Box module for RobinPath.
cache
JS@robinpathv0.1.2
In-memory key-value cache with optional TTL expiration for temporary data storage
$ robinpath add @robinpath/cloudflare
