Skip to content

Commit fea0c8a

Browse files
authored
Merge pull request #2 from cloudflare/release-please--branches--main--changes--next--components--cloudflare
release: 3.0.0-beta.1
2 parents 17a6786 + 38edbae commit fea0c8a

File tree

1,498 files changed

+190920
-86651
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,498 files changed

+190920
-86651
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414

1515

1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1818

1919
- name: Set up Node
20-
uses: actions/setup-node@v3
20+
uses: actions/setup-node@v4
2121
with:
2222
node-version: '18'
2323

.github/workflows/publish-npm.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This workflow is triggered when a GitHub release is created.
2+
# It can also be run manually to re-publish to NPM in case it failed for some reason.
3+
# You can run this workflow by navigating to https://www.github.com/cloudflare/cloudflare-typescript/actions/workflows/publish-npm.yml
4+
name: Publish NPM
5+
on:
6+
workflow_dispatch:
7+
8+
release:
9+
types: [published]
10+
11+
jobs:
12+
publish:
13+
name: publish
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Node
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: '18'
23+
24+
- name: Install dependencies
25+
run: |
26+
yarn install
27+
28+
- name: Publish to NPM
29+
run: |
30+
bash ./bin/publish-npm
31+
env:
32+
NPM_TOKEN: ${{ secrets.CLOUDFLARE_NPM_TOKEN || secrets.NPM_TOKEN }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Release Doctor
2+
on:
3+
pull_request:
4+
workflow_dispatch:
5+
6+
jobs:
7+
release_doctor:
8+
name: release doctor
9+
runs-on: ubuntu-latest
10+
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')
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Check release environment
16+
run: |
17+
bash ./bin/check-release-environment
18+
env:
19+
NPM_TOKEN: ${{ secrets.CLOUDFLARE_NPM_TOKEN || secrets.NPM_TOKEN }}

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "3.0.0-beta.1"
3+
}

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configured_endpoints: 326
1+
configured_endpoints: 1282

CHANGELOG.md

Lines changed: 151 additions & 0 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable).
44
Other package managers may work but are not officially supported for development.
55

6-
To setup the repository, run:
6+
To set up the repository, run:
77

88
```bash
99
yarn
@@ -42,15 +42,15 @@ If you’d like to use the repository from source, you can either install from g
4242
To install via git:
4343

4444
```bash
45-
npm install --save git+ssh://[email protected]:cloudflare/cloudflare-sdk-node.git
45+
npm install git+ssh://[email protected]:cloudflare/cloudflare-typescript.git
4646
```
4747

4848
Alternatively, to link a local copy of the repo:
4949

5050
```bash
5151
# Clone
52-
git clone https://www.github.com/cloudflare/cloudflare-sdk-node
53-
cd cloudflare-sdk-node
52+
git clone https://www.github.com/cloudflare/cloudflare-typescript
53+
cd cloudflare-typescript
5454

5555
# With yarn
5656
yarn link
@@ -65,7 +65,7 @@ pnpm link -—global cloudflare
6565

6666
## Running tests
6767

68-
Most tests will require you to [setup a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.
68+
Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.
6969

7070
```bash
7171
npx prism path/to/your/openapi.yml
@@ -99,7 +99,7 @@ the changes aren't made through the automated pipeline, you may want to make rel
9999

100100
### Publish with a GitHub workflow
101101

102-
You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/cloudflare/cloudflare-sdk-node/actions/workflows/publish-npm.yml). This will require a setup organization or repository secret to be set up.
102+
You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/cloudflare/cloudflare-typescript/actions/workflows/publish-npm.yml). This requires a setup organization or repository secret to be set up.
103103

104104
### Publish manually
105105

README.md

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44

55
This library provides convenient access to the Cloudflare REST API from server-side TypeScript or JavaScript.
66

7-
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).
7+
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).
88

99
## Installation
1010

1111
```sh
12-
npm install --save cloudflare
13-
# or
14-
yarn add cloudflare
12+
npm install cloudflare
1513
```
1614

1715
## Usage
@@ -22,7 +20,10 @@ The full API of this library can be found in [api.md](api.md).
2220
```js
2321
import Cloudflare from 'cloudflare';
2422

25-
const cloudflare = new Cloudflare();
23+
const cloudflare = new Cloudflare({
24+
apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted
25+
apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted
26+
});
2627

2728
async function main() {
2829
const zoneCreateResponse = await cloudflare.zones.create({
@@ -45,7 +46,10 @@ This library includes TypeScript definitions for all request params and response
4546
```ts
4647
import Cloudflare from 'cloudflare';
4748

48-
const cloudflare = new Cloudflare();
49+
const cloudflare = new Cloudflare({
50+
apiEmail: process.env['CLOUDFLARE_EMAIL'], // This is the default and can be omitted
51+
apiKey: process.env['CLOUDFLARE_API_KEY'], // This is the default and can be omitted
52+
});
4953

5054
async function main() {
5155
const params: Cloudflare.ZoneCreateParams = {
@@ -70,9 +74,9 @@ a subclass of `APIError` will be thrown:
7074
<!-- prettier-ignore -->
7175
```ts
7276
async function main() {
73-
const zoneCreateResponse = await cloudflare.zones
74-
.create({ account: { id: '023e105f4ecef8ad9ca31a8372d0c353' }, name: 'example.com', type: 'full' })
75-
.catch((err) => {
77+
const zone = await cloudflare.zones
78+
.get({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353' })
79+
.catch(async (err) => {
7680
if (err instanceof Cloudflare.APIError) {
7781
console.log(err.status); // 400
7882
console.log(err.name); // BadRequestError
@@ -115,7 +119,7 @@ const cloudflare = new Cloudflare({
115119
});
116120

117121
// Or, configure per-request:
118-
await cloudflare.zones.create({ account: { id: '023e105f4ecef8ad9ca31a8372d0c353' }, name: 'example.com', type: 'full' }, {
122+
await cloudflare.zones.get({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, {
119123
maxRetries: 5,
120124
});
121125
```
@@ -132,7 +136,7 @@ const cloudflare = new Cloudflare({
132136
});
133137

134138
// Override per-request:
135-
await cloudflare.zones.create({ account: { id: '023e105f4ecef8ad9ca31a8372d0c353' }, name: 'example.com', type: 'full' }, {
139+
await cloudflare.zones.edit({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, {
136140
timeout: 5 * 1000,
137141
});
138142
```
@@ -141,6 +145,37 @@ On timeout, an `APIConnectionTimeoutError` is thrown.
141145

142146
Note that requests which time out will be [retried twice by default](#retries).
143147

148+
## Auto-pagination
149+
150+
List methods in the Cloudflare API are paginated.
151+
You can use `for await … of` syntax to iterate through items across all pages:
152+
153+
```ts
154+
async function fetchAllAccounts(params) {
155+
const allAccounts = [];
156+
// Automatically fetches more pages as needed.
157+
for await (const accountListResponse of cloudflare.accounts.list()) {
158+
allAccounts.push(accountListResponse);
159+
}
160+
return allAccounts;
161+
}
162+
```
163+
164+
Alternatively, you can make request a single page at a time:
165+
166+
```ts
167+
let page = await cloudflare.accounts.list();
168+
for (const accountListResponse of page.result) {
169+
console.log(accountListResponse);
170+
}
171+
172+
// Convenience methods are provided for manually paginating:
173+
while (page.hasNextPage()) {
174+
page = page.getNextPage();
175+
// ...
176+
}
177+
```
178+
144179
## Advanced Usage
145180

146181
### Accessing raw Response data (e.g., headers)
@@ -182,7 +217,7 @@ import Cloudflare from 'cloudflare';
182217
```
183218

184219
To do the inverse, add `import "cloudflare/shims/node"` (which does import polyfills).
185-
This can also be useful if you are getting the wrong TypeScript types for `Response` more details [here](https://github.com/cloudflare/cloudflare-sdk-node/tree/main/src/_shims#readme).
220+
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/cloudflare/cloudflare-typescript/tree/main/src/_shims#readme)).
186221

187222
You may also provide a custom `fetch` function when instantiating the client,
188223
which can be used to inspect or alter the `Request` or `Response` before/after each request:
@@ -192,7 +227,7 @@ import { fetch } from 'undici'; // as one example
192227
import Cloudflare from 'cloudflare';
193228

194229
const client = new Cloudflare({
195-
fetch: async (url: RequestInfo, init?: RequestInfo): Promise<Response> => {
230+
fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
196231
console.log('About to make a request', url, init);
197232
const response = await fetch(url, init);
198233
console.log('Got response', response);
@@ -213,18 +248,20 @@ If you would like to disable or customize this behavior, for example to use the
213248
<!-- prettier-ignore -->
214249
```ts
215250
import http from 'http';
216-
import HttpsProxyAgent from 'https-proxy-agent';
251+
import { HttpsProxyAgent } from 'https-proxy-agent';
217252

218253
// Configure the default for all requests:
219254
const cloudflare = new Cloudflare({
220255
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
221256
});
222257

223258
// Override per-request:
224-
await cloudflare.zones.create({ account: { id: '023e105f4ecef8ad9ca31a8372d0c353' }, name: 'example.com', type: 'full' }, {
225-
baseURL: 'http://localhost:8080/test-api',
226-
httpAgent: new http.Agent({ keepAlive: false }),
227-
})
259+
await cloudflare.zones.delete(
260+
{ zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
261+
{
262+
httpAgent: new http.Agent({ keepAlive: false }),
263+
},
264+
);
228265
```
229266

230267
## Semantic Versioning
@@ -237,7 +274,7 @@ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) con
237274

238275
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
239276

240-
We are keen for your feedback; please open an [issue](https://www.github.com/cloudflare/cloudflare-sdk-node/issues) with questions, bugs, or suggestions.
277+
We are keen for your feedback; please open an [issue](https://www.github.com/cloudflare/cloudflare-typescript/issues) with questions, bugs, or suggestions.
241278

242279
## Requirements
243280

0 commit comments

Comments
 (0)