Skip to content

Commit

Permalink
Merge pull request #2 from cloudflare/release-please--branches--main-…
Browse files Browse the repository at this point in the history
…-changes--next--components--cloudflare

release: 3.0.0-beta.1
  • Loading branch information
jacobbednarz authored Mar 12, 2024
2 parents 17a6786 + 38edbae commit fea0c8a
Show file tree
Hide file tree
Showing 1,498 changed files with 190,920 additions and 86,651 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:


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

- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '18'

Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow is triggered when a GitHub release is created.
# It can also be run manually to re-publish to NPM in case it failed for some reason.
# You can run this workflow by navigating to https://www.github.com/cloudflare/cloudflare-typescript/actions/workflows/publish-npm.yml
name: Publish NPM
on:
workflow_dispatch:

release:
types: [published]

jobs:
publish:
name: publish
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: |
yarn install
- name: Publish to NPM
run: |
bash ./bin/publish-npm
env:
NPM_TOKEN: ${{ secrets.CLOUDFLARE_NPM_TOKEN || secrets.NPM_TOKEN }}
19 changes: 19 additions & 0 deletions .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Release Doctor
on:
pull_request:
workflow_dispatch:

jobs:
release_doctor:
name: release doctor
runs-on: ubuntu-latest
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@v3

- name: Check release environment
run: |
bash ./bin/check-release-environment
env:
NPM_TOKEN: ${{ secrets.CLOUDFLARE_NPM_TOKEN || secrets.NPM_TOKEN }}
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "3.0.0-beta.1"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 326
configured_endpoints: 1282
151 changes: 151 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable).
Other package managers may work but are not officially supported for development.

To setup the repository, run:
To set up the repository, run:

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

```bash
npm install --save git+ssh://git@github.com:cloudflare/cloudflare-sdk-node.git
npm install git+ssh://git@github.com:cloudflare/cloudflare-typescript.git
```

Alternatively, to link a local copy of the repo:

```bash
# Clone
git clone https://www.github.com/cloudflare/cloudflare-sdk-node
cd cloudflare-sdk-node
git clone https://www.github.com/cloudflare/cloudflare-typescript
cd cloudflare-typescript

# With yarn
yarn link
Expand All @@ -65,7 +65,7 @@ pnpm link -—global cloudflare

## Running tests

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

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

### Publish with a GitHub workflow

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.
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.

### Publish manually

Expand Down
75 changes: 56 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

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

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

## Installation

```sh
npm install --save cloudflare
# or
yarn add cloudflare
npm install cloudflare
```

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

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

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

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

async function main() {
const params: Cloudflare.ZoneCreateParams = {
Expand All @@ -70,9 +74,9 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const zoneCreateResponse = await cloudflare.zones
.create({ account: { id: '023e105f4ecef8ad9ca31a8372d0c353' }, name: 'example.com', type: 'full' })
.catch((err) => {
const zone = await cloudflare.zones
.get({ zone_id: '023e105f4ecef8ad9ca31a8372d0c353' })
.catch(async (err) => {
if (err instanceof Cloudflare.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
Expand Down Expand Up @@ -115,7 +119,7 @@ const cloudflare = new Cloudflare({
});

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

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

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

## Auto-pagination

List methods in the Cloudflare API are paginated.
You can use `for await … of` syntax to iterate through items across all pages:

```ts
async function fetchAllAccounts(params) {
const allAccounts = [];
// Automatically fetches more pages as needed.
for await (const accountListResponse of cloudflare.accounts.list()) {
allAccounts.push(accountListResponse);
}
return allAccounts;
}
```

Alternatively, you can make request a single page at a time:

```ts
let page = await cloudflare.accounts.list();
for (const accountListResponse of page.result) {
console.log(accountListResponse);
}

// Convenience methods are provided for manually paginating:
while (page.hasNextPage()) {
page = page.getNextPage();
// ...
}
```

## Advanced Usage

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

To do the inverse, add `import "cloudflare/shims/node"` (which does import polyfills).
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).
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)).

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

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

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

// Override per-request:
await cloudflare.zones.create({ account: { id: '023e105f4ecef8ad9ca31a8372d0c353' }, name: 'example.com', type: 'full' }, {
baseURL: 'http://localhost:8080/test-api',
httpAgent: new http.Agent({ keepAlive: false }),
})
await cloudflare.zones.delete(
{ zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
{
httpAgent: new http.Agent({ keepAlive: false }),
},
);
```

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

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

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

## Requirements

Expand Down
Loading

0 comments on commit fea0c8a

Please sign in to comment.