Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit ba87fb6

Browse files
authored
chore!: use pure ES modules (#590)
1 parent 1fc2540 commit ba87fb6

File tree

17 files changed

+1314
-2854
lines changed

17 files changed

+1314
-2854
lines changed

.eslintrc.js renamed to .eslintrc.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ const { overrides } = require('@netlify/eslint-config-node')
22

33
module.exports = {
44
extends: '@netlify/eslint-config-node',
5+
parserOptions: {
6+
sourceType: 'module',
7+
},
58
rules: {
9+
'import/extensions': [2, 'ignorePackages'],
610
// TODO: enable those rules
711
complexity: 0,
812
'max-statements': 0,

.github/workflows/workflow.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,3 @@ jobs:
4848
with:
4949
file: coverage/coverage-final.json
5050
flags: ${{ steps.test-coverage-flags.outputs.os }},${{ steps.test-coverage-flags.outputs.node }}
51-
- name: Build
52-
run: npm run build
53-
if: "${{ matrix.node-version == '*' }}"

README.md

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2522
const 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 = {
124117
All 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 = {
162153
See 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

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

0 commit comments

Comments
 (0)