Modules@robinpath/cloudflare
cloudflare

@robinpath/cloudflare

0.1.2Node.jsPublic

Cloudflare 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.listZones to perform this operation
  • Get details of a specific zone -- Use cloudflare.getZone to perform this operation
  • Create a new Cloudflare zone -- Use cloudflare.createZone to perform this operation
  • Delete a Cloudflare zone -- Use cloudflare.deleteZone to perform this operation
  • Purge cache for a zone (all or selective by URLs/tags/hosts/prefixes) -- Use cloudflare.purgeCache to perform this operation

Quick Reference

FunctionDescriptionReturns
setTokenSet Cloudflare API token for authentication{ success, method }
setCredentialsSet Cloudflare global API key credentials{ success, method }
listZonesList Cloudflare zonesArray of zone objects
getZoneGet details of a specific zoneZone details object
createZoneCreate a new Cloudflare zoneCreated zone object
deleteZoneDelete a Cloudflare zone{ success, zoneId }
purgeCachePurge cache for a zone (all or selective by URLs/tags/hosts/prefixes)Purge result object
listDnsRecordsList DNS records for a zoneArray of DNS record objects
getDnsRecordGet a specific DNS recordDNS record object
createDnsRecordCreate a DNS record in a zoneCreated DNS record object
updateDnsRecordUpdate an existing DNS recordUpdated DNS record object
deleteDnsRecordDelete a DNS record from a zone{ success, zoneId, recordId }
listWorkersList Workers scripts for an accountArray of Worker script objects
getWorkerScriptGet the content of a Worker scriptWorker script source code
deployWorkerDeploy a Worker scriptDeployed Worker result object
deleteWorkerDelete a Worker script{ success, accountId, scriptName }
listKvNamespacesList KV namespaces for an accountArray of KV namespace objects
createKvNamespaceCreate a KV namespaceCreated KV namespace object
deleteKvNamespaceDelete a KV namespace{ success, accountId, namespaceId }
kvGetRead a value from KV storageValue stored at the key, or null if not found
kvPutWrite a value to KV storage{ success, key }
kvDeleteDelete a key from KV storage{ success, key }
kvListKeysList keys in a KV namespaceArray of key objects
listR2BucketsList R2 buckets for an accountArray of R2 bucket objects
createR2BucketCreate an R2 bucketCreated R2 bucket object
deleteR2BucketDelete an R2 bucket{ success, accountId, bucketName }
listPagesList Cloudflare Pages projectsArray of Pages project objects
getPageProjectGet details of a Cloudflare Pages projectPages project details object
getZoneAnalyticsGet analytics data for a zoneZone analytics dashboard data

Functions

setToken

Set Cloudflare API token for authentication

Module: cloudflare | Returns: object -- { success, method }

cloudflare.setToken "your-api-token"
ParameterTypeRequiredDescription
apiTokenstringYesCloudflare API token

setCredentials

Set Cloudflare global API key credentials

Module: cloudflare | Returns: object -- { success, method }

cloudflare.setCredentials "user@example.com" "your-global-api-key"
ParameterTypeRequiredDescription
emailstringYesCloudflare account email
apiKeystringYesCloudflare global API key

listZones

List Cloudflare zones

Module: cloudflare | Returns: array -- Array of zone objects

cloudflare.listZones {"name": "example.com"}
ParameterTypeRequiredDescription
optionsobjectNoFilter options: name, status, page, perPage

getZone

Get details of a specific zone

Module: cloudflare | Returns: object -- Zone details object

cloudflare.getZone "zone-id-here"
ParameterTypeRequiredDescription
zoneIdstringYesZone ID

createZone

Create a new Cloudflare zone

Module: cloudflare | Returns: object -- Created zone object

cloudflare.createZone "example.com" {"accountId": "abc123"}
ParameterTypeRequiredDescription
namestringYesDomain name for the zone
optionsobjectNoOptions: accountId, jumpStart, type

deleteZone

Delete a Cloudflare zone

Module: cloudflare | Returns: object -- { success, zoneId }

cloudflare.deleteZone "zone-id-here"
ParameterTypeRequiredDescription
zoneIdstringYesZone 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}
ParameterTypeRequiredDescription
zoneIdstringYesZone ID
optionsobjectNoOptions: 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"}
ParameterTypeRequiredDescription
zoneIdstringYesZone ID
optionsobjectNoFilter 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"
ParameterTypeRequiredDescription
zoneIdstringYesZone ID
recordIdstringYesDNS 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}
ParameterTypeRequiredDescription
zoneIdstringYesZone ID
typestringYesRecord type (A, AAAA, CNAME, MX, TXT, etc.)
namestringYesDNS record name
contentstringYesDNS record content/value
optionsobjectNoOptions: 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}
ParameterTypeRequiredDescription
zoneIdstringYesZone ID
recordIdstringYesDNS record ID
typestringYesRecord type (A, AAAA, CNAME, MX, TXT, etc.)
namestringYesDNS record name
contentstringYesDNS record content/value
optionsobjectNoOptions: ttl, proxied, priority

deleteDnsRecord

Delete a DNS record from a zone

Module: cloudflare | Returns: object -- { success, zoneId, recordId }

cloudflare.deleteDnsRecord "zone-id" "record-id"
ParameterTypeRequiredDescription
zoneIdstringYesZone ID
recordIdstringYesDNS record ID

listWorkers

List Workers scripts for an account

Module: cloudflare | Returns: array -- Array of Worker script objects

cloudflare.listWorkers "account-id"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID

getWorkerScript

Get the content of a Worker script

Module: cloudflare | Returns: string -- Worker script source code

cloudflare.getWorkerScript "account-id" "my-worker"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
scriptNamestringYesWorker 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') } }"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
scriptNamestringYesWorker script name
scriptstringYesWorker script source code
optionsobjectNoOptions: mainModule, compatibilityDate, bindings

deleteWorker

Delete a Worker script

Module: cloudflare | Returns: object -- { success, accountId, scriptName }

cloudflare.deleteWorker "account-id" "my-worker"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
scriptNamestringYesWorker script name

listKvNamespaces

List KV namespaces for an account

Module: cloudflare | Returns: array -- Array of KV namespace objects

cloudflare.listKvNamespaces "account-id"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
optionsobjectNoOptions: page, perPage

createKvNamespace

Create a KV namespace

Module: cloudflare | Returns: object -- Created KV namespace object

cloudflare.createKvNamespace "account-id" "my-kv-store"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
titlestringYesNamespace title

deleteKvNamespace

Delete a KV namespace

Module: cloudflare | Returns: object -- { success, accountId, namespaceId }

cloudflare.deleteKvNamespace "account-id" "namespace-id"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
namespaceIdstringYesKV 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"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
namespaceIdstringYesKV namespace ID
keystringYesKey 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}
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
namespaceIdstringYesKV namespace ID
keystringYesKey to write
valueanyYesValue to store
optionsobjectNoOptions: 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"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
namespaceIdstringYesKV namespace ID
keystringYesKey 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:"}
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
namespaceIdstringYesKV namespace ID
optionsobjectNoOptions: prefix, limit, cursor

listR2Buckets

List R2 buckets for an account

Module: cloudflare | Returns: array -- Array of R2 bucket objects

cloudflare.listR2Buckets "account-id"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID

createR2Bucket

Create an R2 bucket

Module: cloudflare | Returns: object -- Created R2 bucket object

cloudflare.createR2Bucket "account-id" "my-bucket"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
namestringYesBucket name

deleteR2Bucket

Delete an R2 bucket

Module: cloudflare | Returns: object -- { success, accountId, bucketName }

cloudflare.deleteR2Bucket "account-id" "my-bucket"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
bucketNamestringYesBucket name

listPages

List Cloudflare Pages projects

Module: cloudflare | Returns: array -- Array of Pages project objects

cloudflare.listPages "account-id"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID

getPageProject

Get details of a Cloudflare Pages project

Module: cloudflare | Returns: object -- Pages project details object

cloudflare.getPageProject "account-id" "my-site"
ParameterTypeRequiredDescription
accountIdstringYesCloudflare account ID
projectNamestringYesPages 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"}
ParameterTypeRequiredDescription
zoneIdstringYesZone ID
optionsobjectNoOptions: since (ISO date or negative minutes), until (ISO date or negative minutes)

Error Handling

All functions throw on failure. Common errors:

ErrorCause
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 requiredCheck the error message for details
Both email and API key are requiredCheck the error message for details
zoneId is requiredCheck the error message for details
Zone name is requiredCheck the error message for details
zoneId and recordId are requiredCheck 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)

VersionTagPublished
0.1.2latest1 months ago
Install
$ robinpath add @robinpath/cloudflare

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.2
LicenseMIT
Unpacked Size9.4 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Category

devops