Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"postCreateCommand": "yarn install",
"customizations": {
"vscode": {
"extensions": ["esbenp.prettier-vscode"]
"extensions": [
"esbenp.prettier-vscode"
]
}
}
}
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ body:
- type: checkboxes
id: non_api
attributes:
label: Confirm this is a Typescript library issue and not an underlying Cloudflare API issue
label: Confirm this is a TypeScript library issue and not an underlying Cloudflare API issue
description: Issues with the underlying Cloudflare API should be reported via [Cloudflare Support](https://developers.cloudflare.com/support/contacting-cloudflare-support)
options:
- label: This is an issue with the Typescript library
- label: This is an issue with the TypeScript library
required: true
- type: textarea
id: what-happened
Expand All @@ -34,7 +34,7 @@ body:
attributes:
label: Code snippets
description: If applicable, add code snippets to help explain your problem.
render: Typescript
render: TypeScript
validations:
required: false
- type: input
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ${{ github.repository == 'stainless-sdks/cloudflare-node' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v4
Expand All @@ -45,7 +45,7 @@ jobs:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v4
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
runs-on: ${{ github.repository == 'stainless-sdks/cloudflare-node' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v4
Expand All @@ -97,7 +97,7 @@ jobs:
if: github.repository == 'cloudflare/cloudflare-typescript' && (github.event_name == 'push' || github.event.pull_request.head.repo.fork)

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v4
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/detect-breaking-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI
on:
pull_request:
branches:
- main
- next

jobs:
detect_breaking_changes:
runs-on: 'ubuntu-latest'
name: detect-breaking-changes
if: github.repository == 'cloudflare/cloudflare-typescript'
steps:
- name: Calculate fetch-depth
run: |
echo "FETCH_DEPTH=$(expr ${{ github.event.pull_request.commits }} + 1)" >> $GITHUB_ENV

- uses: actions/checkout@v6
with:
# Ensure we can check out the pull request base in the script below.
fetch-depth: ${{ env.FETCH_DEPTH }}

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install dependencies
run: |
yarn install

- name: Detect breaking changes
run: |
# Try to check out previous versions of the breaking change detection script. This ensures that
# we still detect breaking changes when entire files and their tests are removed.
git checkout "${{ github.event.pull_request.base.sha }}" -- ./scripts/detect-breaking-changes 2>/dev/null || true
./scripts/detect-breaking-changes ${{ github.event.pull_request.base.sha }}
Comment on lines +10 to +36

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI about 1 month ago

  • In general, fix this by adding an explicit permissions: block that grants only the minimal scopes required by the job. This can be defined at the workflow root (applies to all jobs) or within the specific job.
  • For this workflow, the visible steps only require reading repository contents. There is no evidence of any operation that needs write access (no pushes, no issue/PR mutations, etc.). The single best fix is to add permissions: contents: read at the job level for detect_breaking_changes. This documents the intent and prevents the job from inheriting potentially broader default permissions.
  • Concretely, in .github/workflows/detect-breaking-changes.yml, modify the detect_breaking_changes job definition (around line 9–13) to introduce a permissions: block between name: and if: (or between any job-level keys, as long as indentation is correct).
  • No new methods, imports, or other definitions are needed; this is purely a YAML configuration change.
Suggested changeset 1
.github/workflows/detect-breaking-changes.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/detect-breaking-changes.yml b/.github/workflows/detect-breaking-changes.yml
--- a/.github/workflows/detect-breaking-changes.yml
+++ b/.github/workflows/detect-breaking-changes.yml
@@ -9,6 +9,8 @@
   detect_breaking_changes:
     runs-on: 'ubuntu-latest'
     name: detect-breaking-changes
+    permissions:
+      contents: read
     if: github.repository == 'cloudflare/cloudflare-typescript'
     steps:
       - name: Calculate fetch-depth
EOF
@@ -9,6 +9,8 @@
detect_breaking_changes:
runs-on: 'ubuntu-latest'
name: detect-breaking-changes
permissions:
contents: read
if: github.repository == 'cloudflare/cloudflare-typescript'
steps:
- name: Calculate fetch-depth
Copilot is powered by AI and may make mistakes. Always verify output.
2 changes: 1 addition & 1 deletion .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up Node
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
if: github.repository == 'cloudflare/cloudflare-typescript' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Check release environment
run: |
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "6.0.0-beta.1"
".": "6.0.0-beta.2"
}
8 changes: 4 additions & 4 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 1995
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-28b84a5db03b38290dfe7ef1de2c68feb68762d7a8f207bdbea4d39a7aeef1ea.yml
openapi_spec_hash: ba6bd61621e4be20b581f4f3bf0978d3
config_hash: 07dfb48a768bfdcfd417ec643bab23f5
configured_endpoints: 2010
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-c764e67a143aa372dd5f9971c38ba9cb79f063a8527bf09abe87bc40ea4e8d46.yml
openapi_spec_hash: 0f0810f21752c54bb1e0cbaf15b09986
config_hash: 4f7156f8131682ce0acd20f172d81e18
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Changelog

## 6.0.0-beta.2 (2026-02-18)

Full Changelog: [v6.0.0-beta.1...v6.0.0-beta.2](https://github.com/cloudflare/cloudflare-typescript/compare/v6.0.0-beta.1...v6.0.0-beta.2)

### Features

* feat(api): add AI Gateway Dynamic Routing endpoints ([94b9d1b](https://github.com/cloudflare/cloudflare-typescript/commit/94b9d1b7cd39b1f1f4fa617922187497fb626a76))
* feat(fraud): public docs for fraud API ([e0ae79f](https://github.com/cloudflare/cloudflare-typescript/commit/e0ae79f9e8cb81b3edf5d69ce5dbba49cba95014))
* refactor(terraform): restructure origin_tls_client_auth to peer subresources ([16b8e20](https://github.com/cloudflare/cloudflare-typescript/commit/16b8e209208f1f4c10ddb3ba9c71cdceba69b8ae))


### Bug Fixes

* add write ([e6638ba](https://github.com/cloudflare/cloudflare-typescript/commit/e6638ba1cde0c6745c81d759cb78372d74e4286c))
* lint issues ([f2f7905](https://github.com/cloudflare/cloudflare-typescript/commit/f2f79057d0aeb97e8e884e4917a6dc050103ce6d))
* node version, unset auth token var ([5a81485](https://github.com/cloudflare/cloudflare-typescript/commit/5a81485c28a9f8b7c71c5ac111b00c0661324427))
* npm publish url and run ci ([0b5a90f](https://github.com/cloudflare/cloudflare-typescript/commit/0b5a90f52790955187d5972ef101d5432ae1fbba))
* publish script ([e106752](https://github.com/cloudflare/cloudflare-typescript/commit/e1067522c6ab0a4d53298331c00ad7f4c877034c))
* registry url ([82932e9](https://github.com/cloudflare/cloudflare-typescript/commit/82932e9640ee9ee7d6e5461789cc7496c27fa4e0))
* typo ([5d30b47](https://github.com/cloudflare/cloudflare-typescript/commit/5d30b47f2f321360016f6168c487cc089c7ba3e5))
* use npm publish and oidc ([da94040](https://github.com/cloudflare/cloudflare-typescript/commit/da94040946c9f7ef5a7ad300a6d763232b28fe86))


### Chores

* **api:** update composite API spec ([956b744](https://github.com/cloudflare/cloudflare-typescript/commit/956b744db9798f8805b4f322b48598c41bd2f5dc))
* **api:** update composite API spec ([a41ac13](https://github.com/cloudflare/cloudflare-typescript/commit/a41ac13294285c5c107139fa7e3353b6d9cba9ca))
* **api:** update composite API spec ([c088d7d](https://github.com/cloudflare/cloudflare-typescript/commit/c088d7d62118687893dccfb79a269e1943ccb926))
* **internal:** codegen related update ([7ea05a7](https://github.com/cloudflare/cloudflare-typescript/commit/7ea05a73bfcba2df9398294a9808dde39f217917))
* **internal:** codegen related update ([bb49123](https://github.com/cloudflare/cloudflare-typescript/commit/bb491236363152546626d34f1a96062021f757ab))

## 6.0.0-beta.1 (2026-01-20)
> **Disclaimer:** Please note that v6.0.0-beta.1 is in Beta and we are still testing it for stability.

Expand Down
76 changes: 45 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ This library provides convenient access to the Cloudflare REST API from server-s

The REST API documentation can be found on [developers.cloudflare.com](https://developers.cloudflare.com/api). The full API of this library can be found in [api.md](api.md).

## MCP Server

Use the Cloudflare MCP Server to enable AI assistants to interact with this API, allowing them to explore endpoints, make test requests, and use documentation to help integrate this SDK into your application.

[![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en-US/install-mcp?name=cloudflare-mcp&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsImNsb3VkZmxhcmUtbWNwIl19)
[![Install in VS Code](https://img.shields.io/badge/_-Add_to_VS_Code-blue?style=for-the-badge&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZmlsbD0iI0VFRSIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNMzAuMjM1IDM5Ljg4NGEyLjQ5MSAyLjQ5MSAwIDAgMS0xLjc4MS0uNzNMMTIuNyAyNC43OGwtMy40NiAyLjYyNC0zLjQwNiAyLjU4MmExLjY2NSAxLjY2NSAwIDAgMS0xLjA4Mi4zMzggMS42NjQgMS42NjQgMCAwIDEtMS4wNDYtLjQzMWwtMi4yLTJhMS42NjYgMS42NjYgMCAwIDEgMC0yLjQ2M0w3LjQ1OCAyMCA0LjY3IDE3LjQ1MyAxLjUwNyAxNC41N2ExLjY2NSAxLjY2NSAwIDAgMSAwLTIuNDYzbDIuMi0yYTEuNjY1IDEuNjY1IDAgMCAxIDIuMTMtLjA5N2w2Ljg2MyA1LjIwOUwyOC40NTIuODQ0YTIuNDg4IDIuNDg4IDAgMCAxIDEuODQxLS43MjljLjM1MS4wMDkuNjk5LjA5MSAxLjAxOS4yNDVsOC4yMzYgMy45NjFhMi41IDIuNSAwIDAgMSAxLjQxNSAyLjI1M3YuMDk5LS4wNDVWMzMuMzd2LS4wNDUuMDk1YTIuNTAxIDIuNTAxIDAgMCAxLTEuNDE2IDIuMjU3bC04LjIzNSAzLjk2MWEyLjQ5MiAyLjQ5MiAwIDAgMS0xLjA3Ny4yNDZabS43MTYtMjguOTQ3LTExLjk0OCA5LjA2MiAxMS45NTIgOS4wNjUtLjAwNC0xOC4xMjdaIi8+PC9zdmc+)](https://vscode.stainless.com/mcp/%7B%22name%22%3A%22cloudflare-mcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22cloudflare-mcp%22%5D%7D)

> Note: You may need to set environment variables in your MCP client.

## Installation

```sh
Expand Down Expand Up @@ -72,36 +81,31 @@ import Cloudflare, { toFile } from 'cloudflare';
const client = new Cloudflare();

// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
await client.apiGateway.userSchemas.create({
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
file: fs.createReadStream('/path/to/file'),
kind: 'openapi_v3',
await client.kv.namespaces.values.update('0f2ac74b498b48028cb68387c421e279', 'My-Key', {
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
value: fs.createReadStream('/path/to/file'),
});

// Or if you have the web `File` API you can pass a `File` instance:
await client.apiGateway.userSchemas.create({
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
file: new File(['my bytes'], 'file'),
kind: 'openapi_v3',
await client.kv.namespaces.values.update('0f2ac74b498b48028cb68387c421e279', 'My-Key', {
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
value: new File(['my bytes'], 'file'),
});

// You can also pass a `fetch` `Response`:
await client.apiGateway.userSchemas.create({
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
file: await fetch('https://somesite/file'),
kind: 'openapi_v3',
await client.kv.namespaces.values.update('0f2ac74b498b48028cb68387c421e279', 'My-Key', {
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
value: await fetch('https://somesite/file'),
});

// Finally, if none of the above are convenient, you can use our `toFile` helper:
await client.apiGateway.userSchemas.create({
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
file: await toFile(Buffer.from('my bytes'), 'file'),
kind: 'openapi_v3',
await client.kv.namespaces.values.update('0f2ac74b498b48028cb68387c421e279', 'My-Key', {
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
value: await toFile(Buffer.from('my bytes'), 'file'),
});
await client.apiGateway.userSchemas.create({
zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
file: await toFile(new Uint8Array([0, 1, 2]), 'file'),
kind: 'openapi_v3',
await client.kv.namespaces.values.update('0f2ac74b498b48028cb68387c421e279', 'My-Key', {
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
value: await toFile(new Uint8Array([0, 1, 2]), 'file'),
});
```

Expand All @@ -113,15 +117,17 @@ a subclass of `APIError` will be thrown:

<!-- prettier-ignore -->
```ts
const zone = await client.zones.get({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }).catch(async (err) => {
if (err instanceof Cloudflare.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
const zone = await client.zones
.get({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353' })
.catch(async (err) => {
if (err instanceof Cloudflare.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
```

Error codes are as follows:
Expand Down Expand Up @@ -223,13 +229,21 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
const client = new Cloudflare();

const response = await client.zones
.create({ account: { id: '023e105f4ecef8ad9ca31a8372d0c353' }, name: 'example.com', type: 'full' })
.create({
account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
name: 'example.com',
type: 'full',
})
.asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: zone, response: raw } = await client.zones
.create({ account: { id: '023e105f4ecef8ad9ca31a8372d0c353' }, name: 'example.com', type: 'full' })
.create({
account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
name: 'example.com',
type: 'full',
})
.withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(zone.id);
Expand Down
Loading
Loading