Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ const { overrides } = require('@netlify/eslint-config-node')

module.exports = {
extends: '@netlify/eslint-config-node',
parserOptions: {
sourceType: 'module',
},
rules: {
'import/extensions': [2, 'ignorePackages'],
// TODO: enable those rules
complexity: 0,
'max-statements': 0,
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,3 @@ jobs:
with:
file: coverage/coverage-final.json
flags: ${{ steps.test-coverage-flags.outputs.os }},${{ steps.test-coverage-flags.outputs.node }}
- name: Build
run: npm run build
if: "${{ matrix.node-version == '*' }}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #589

75 changes: 31 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,32 @@ A Netlify [OpenAPI](https://github.com/netlify/open-api) client that works in th
## Usage

```js
const NetlifyAPI = require('netlify')
import { NetlifyAPI } from 'netlify'

const listNetlifySites = async function () {
const client = new NetlifyAPI('1234myAccessToken')
const sites = await client.listSites()
return sites
}
const client = new NetlifyAPI('1234myAccessToken')
const sites = await client.listSites()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top-level await is possible with pure ES modules.

```

## Using OpenAPI operations

```js
const NetlifyAPI = require('netlify')
import { NetlifyAPI } from 'netlify'

const client = new NetlifyAPI('1234myAccessToken')

const listCreateAndDeleteSite = async function () {
// Fetch sites
const sites = await client.listSites()
// Fetch sites
const sites = await client.listSites()

// Create a site. Notice `body` here for sending OpenAPI body
const site = await client.createSite({
body: {
name: `my-awesome-site`,
// ... https://open-api.netlify.com/#/default/createSite
},
})
// Create a site. Notice `body` here for sending OpenAPI body
const site = await client.createSite({
body: {
name: `my-awesome-site`,
// ... https://open-api.netlify.com/#/default/createSite
},
})

// Delete site. Notice `site_id` is a path parameter https://open-api.netlify.com/#/default/deleteSite
await client.deleteSite({
site_id: siteId,
})
}
// Delete site. Notice `site_id` is a path parameter https://open-api.netlify.com/#/default/deleteSite
await client.deleteSite({ site_id: siteId })
```

## API
Expand Down Expand Up @@ -124,16 +117,14 @@ const opts = {
All operations are conveniently consumed with async/await:

```js
const getSomeData = async () => {
try {
const siteDeploy = await client.getSiteDeploy({
siteId: '1234abcd',
deploy_id: '4567',
})
// Calls may fail!
try {
return await client.getSiteDeploy({
siteId: '1234abcd',
deploy_id: '4567',
})
} catch (error) {
// handle error
}
} catch (error) {
// handle error
}
```

Expand Down Expand Up @@ -162,19 +153,15 @@ const opts = {
See the [authenticating](https://www.netlify.com/docs/api/#authenticating) docs for more context.

```js
// example:
const open = require('open') // installed with 'npm i open'
import open from 'open'

const login = async () => {
const ticket = await client.createTicket({
clientId: CLIENT_ID,
})
// Open browser for authentication
await open(`https://app.netlify.com/authorize?response_type=ticket&ticket=${ticket.id}`)
const accessToken = await client.getAccessToken(ticket)
// API is also set up to use the returned access token as a side effect
return accessToken // Save this for later so you can quickly set up an authenticated client
}
const ticket = await client.createTicket({ clientId: CLIENT_ID })
// Open browser for authentication
await open(`https://app.netlify.com/authorize?response_type=ticket&ticket=${ticket.id}`)

// API is also set up to use the returned access token as a side effect
// Save this for later so you can quickly set up an authenticated client
const accessToken = await client.getAccessToken(ticket)
```

## Proxy support
Expand All @@ -183,7 +170,7 @@ const login = async () => {
`http.Agent` that can handle your situation as `agent` option:

```js
const HttpsProxyAgent = require('https-proxy-agent')
import HttpsProxyAgent from 'https-proxy-agent'

const proxyUri = 'http(s)://[user:password@]proxyhost:port'
const agent = new HttpsProxyAgent(proxyUri)
Expand Down
File renamed without changes.
Loading