This repository was archived by the owner on Oct 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
chore!: use pure ES modules #590
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Top-level |
||
``` | ||
|
||
## 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 | ||
|
@@ -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 | ||
} | ||
``` | ||
|
||
|
@@ -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 | ||
|
@@ -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) | ||
|
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #589