@@ -8,39 +8,32 @@ A Netlify [OpenAPI](https://github.com/netlify/open-api) client that works in th
88## Usage
99
1010``` js
11- const NetlifyAPI = require ( ' netlify' )
11+ import { NetlifyAPI } from ' netlify'
1212
13- const listNetlifySites = async function () {
14- const client = new NetlifyAPI (' 1234myAccessToken' )
15- const sites = await client .listSites ()
16- return sites
17- }
13+ const client = new NetlifyAPI (' 1234myAccessToken' )
14+ const sites = await client .listSites ()
1815```
1916
2017## Using OpenAPI operations
2118
2219``` js
23- const NetlifyAPI = require ( ' netlify' )
20+ import { NetlifyAPI } from ' netlify'
2421
2522const client = new NetlifyAPI (' 1234myAccessToken' )
2623
27- const listCreateAndDeleteSite = async function () {
28- // Fetch sites
29- const sites = await client .listSites ()
24+ // Fetch sites
25+ const sites = await client .listSites ()
3026
31- // Create a site. Notice `body` here for sending OpenAPI body
32- const site = await client .createSite ({
33- body: {
34- name: ` my-awesome-site` ,
35- // ... https://open-api.netlify.com/#/default/createSite
36- },
37- })
27+ // Create a site. Notice `body` here for sending OpenAPI body
28+ const site = await client .createSite ({
29+ body: {
30+ name: ` my-awesome-site` ,
31+ // ... https://open-api.netlify.com/#/default/createSite
32+ },
33+ })
3834
39- // Delete site. Notice `site_id` is a path parameter https://open-api.netlify.com/#/default/deleteSite
40- await client .deleteSite ({
41- site_id: siteId,
42- })
43- }
35+ // Delete site. Notice `site_id` is a path parameter https://open-api.netlify.com/#/default/deleteSite
36+ await client .deleteSite ({ site_id: siteId })
4437```
4538
4639## API
@@ -124,16 +117,14 @@ const opts = {
124117All operations are conveniently consumed with async/await:
125118
126119``` js
127- const getSomeData = async () => {
120+ try {
121+ const siteDeploy = await client .getSiteDeploy ({
122+ siteId: ' 1234abcd' ,
123+ deploy_id: ' 4567' ,
124+ })
128125 // Calls may fail!
129- try {
130- return await client .getSiteDeploy ({
131- siteId: ' 1234abcd' ,
132- deploy_id: ' 4567' ,
133- })
134- } catch (error) {
135- // handle error
136- }
126+ } catch (error) {
127+ // handle error
137128}
138129```
139130
@@ -162,19 +153,15 @@ const opts = {
162153See the [ authenticating] ( https://www.netlify.com/docs/api/#authenticating ) docs for more context.
163154
164155``` js
165- // example:
166- const open = require (' open' ) // installed with 'npm i open'
156+ import open from ' open'
167157
168- const login = async () => {
169- const ticket = await client .createTicket ({
170- clientId: CLIENT_ID ,
171- })
172- // Open browser for authentication
173- await open (` https://app.netlify.com/authorize?response_type=ticket&ticket=${ ticket .id } ` )
174- const accessToken = await client .getAccessToken (ticket)
175- // API is also set up to use the returned access token as a side effect
176- return accessToken // Save this for later so you can quickly set up an authenticated client
177- }
158+ const ticket = await client .createTicket ({ clientId: CLIENT_ID })
159+ // Open browser for authentication
160+ await open (` https://app.netlify.com/authorize?response_type=ticket&ticket=${ ticket .id } ` )
161+
162+ // API is also set up to use the returned access token as a side effect
163+ // Save this for later so you can quickly set up an authenticated client
164+ const accessToken = await client .getAccessToken (ticket)
178165```
179166
180167## Proxy support
@@ -183,7 +170,7 @@ const login = async () => {
183170` http.Agent ` that can handle your situation as ` agent ` option:
184171
185172``` js
186- const HttpsProxyAgent = require ( ' https-proxy-agent' )
173+ import HttpsProxyAgent from ' https-proxy-agent'
187174
188175const proxyUri = ' http(s)://[user:password@]proxyhost:port'
189176const agent = new HttpsProxyAgent (proxyUri)
0 commit comments