Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

netlify

Package Overview
Dependencies
Maintainers
16
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

netlify - npm Package Compare versions

Comparing version 9.0.0 to 10.0.0

src/open_api.js

36

package.json
{
"name": "netlify",
"description": "Netlify Node.js API client",
"version": "9.0.0",
"version": "10.0.0",
"type": "module",
"files": [
"src/**/*.js",
"!src/**/*.test.js",
"dist/main.js",
"dist/main.js.map"
"!src/**/*.test.js"
],
"exports": "./src/index.js",
"main": "./src/index.js",
"unpkg": "./dist/main.js",
"umd:main": "./dist/main.js",
"scripts": {
"prepublishOnly": "npm ci && run-s test build",
"test": "npm run format && npm run test:dev",
"prepublishOnly": "npm ci && npm test",
"test": "run-s format test:dev",
"format": "run-s format:check-fix:*",

@@ -29,8 +27,7 @@ "format:lint": "eslint --ignore-path .gitignore --fix --cache --format=codeframe --max-warnings=0 \"src/**/*.js\"",

"test:ci": "nyc -r lcovonly -r text -r json ava",
"update-snapshots": "ava -u",
"build": "webpack"
"update-snapshots": "ava -u"
},
"config": {
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,tests,.github}/**/*.{js,md,html}\" \"*.{js,md,html}\" \".*.{js,md,html}\"",
"prettier": "--ignore-path .gitignore --loglevel=warn \"{src,tests,.github}/**/*.{js,md,yml,json,html}\" \"*.{js,yml,json,html}\" \".*.{js,yml,json,html}\" \"!package-lock.json\" \"!CHANGELOG.md\""
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{src,tests,.github}/**/*.{cjs,mjs,js,md,html}\" \"*.{cjs,mjs,js,md,html}\" \".*.{cjs,mjs,js,md,html}\"",
"prettier": "--ignore-path .gitignore --loglevel=warn \"{src,tests,.github}/**/*.{cjs,mjs,js,md,yml,json,html}\" \"*.{cjs,mjs,js,yml,json,html}\" \".*.{cjs,mjs,js,yml,json,html}\" \"!package-lock.json\" \"!CHANGELOG.md\""
},

@@ -75,9 +72,4 @@ "husky": {

"devDependencies": {
"@babel/core": "^7.12.17",
"@babel/plugin-transform-runtime": "^7.12.17",
"@babel/preset-env": "^7.12.17",
"@babel/runtime": "^7.12.18",
"@netlify/eslint-config-node": "^3.3.8",
"ava": "^2.4.0",
"babel-loader": "^8.2.2",
"@netlify/eslint-config-node": "^3.3.10",
"ava": "^3.0.0",
"from2-string": "^1.1.0",

@@ -88,5 +80,3 @@ "husky": "^4.3.8",

"nyc": "^15.1.0",
"uuid": "^8.3.2",
"webpack": "^4.46.0",
"webpack-cli": "^4.5.0"
"uuid": "^8.3.2"
},

@@ -100,6 +90,4 @@ "engines": {

],
"compileEnhancements": false,
"babel": false,
"verbose": true
}
}

@@ -11,9 +11,6 @@ ![netlify/js-client](js-client.png)

```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()
```

@@ -24,23 +21,19 @@

```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 })
```

@@ -129,12 +122,10 @@

```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
}

@@ -168,15 +159,11 @@ ```

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

@@ -190,3 +177,3 @@

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

@@ -203,7 +190,2 @@ const proxyUri = 'http(s)://[user:password@]proxyhost:port'

## UMD Builds
A UMD build is provided for your convenience, however browser support is still experimental. Contributions to improve
browser support are welcome.
## Contributing

@@ -210,0 +192,0 @@

@@ -1,8 +0,8 @@

const dfn = require('@netlify/open-api')
const pWaitFor = require('p-wait-for')
import pWaitFor from 'p-wait-for'
const { getMethods } = require('./methods')
const { getOperations } = require('./operations')
import { getMethods } from './methods/index.js'
import { openApiSpec } from './open_api.js'
import { getOperations } from './operations.js'
class NetlifyAPI {
export class NetlifyAPI {
constructor(firstArg, secondArg) {

@@ -15,5 +15,5 @@ // variadic arguments

userAgent = 'netlify/js-client',
scheme = dfn.schemes[0],
host = dfn.host,
pathPrefix = dfn.basePath,
scheme = openApiSpec.schemes[0],
host = openApiSpec.host,
pathPrefix = openApiSpec.basePath,
accessToken = accessTokenInput,

@@ -93,4 +93,2 @@ globalParams = {},

module.exports = NetlifyAPI
module.exports.methods = getOperations()
export const methods = getOperations()
// Handle request body
const addBody = function (body, parameters, opts) {
export const addBody = function (body, parameters, opts) {
if (!body) {

@@ -31,3 +31,1 @@ return opts

}
module.exports = { addBody }

@@ -1,15 +0,13 @@

const nodeFetch = require('node-fetch')
// Webpack will sometimes export default exports in different places
const fetch = nodeFetch.default || nodeFetch
import fetch from 'node-fetch'
const { getOperations } = require('../operations')
import { getOperations } from '../operations.js'
const { addBody } = require('./body')
const { parseResponse, getFetchError } = require('./response')
const { shouldRetry, waitForRetry, MAX_RETRY } = require('./retry')
const { getUrl } = require('./url')
import { addBody } from './body.js'
import { parseResponse, getFetchError } from './response.js'
import { shouldRetry, waitForRetry, MAX_RETRY } from './retry.js'
import { getUrl } from './url.js'
// For each OpenAPI operation, add a corresponding method.
// The `operationId` is the method name.
const getMethods = function ({ basePath, defaultHeaders, agent, globalParams }) {
export const getMethods = function ({ basePath, defaultHeaders, agent, globalParams }) {
const operations = getOperations()

@@ -93,3 +91,1 @@ const methods = operations.map((method) => getMethod({ method, basePath, defaultHeaders, agent, globalParams }))

}
module.exports = { getMethods }

@@ -1,6 +0,6 @@

const { JSONHTTPError, TextHTTPError } = require('micro-api-client')
const omit = require('omit.js').default
import { JSONHTTPError, TextHTTPError } from 'micro-api-client'
import omit from 'omit.js'
// Read and parse the HTTP response
const parseResponse = async function (response) {
export const parseResponse = async function (response) {
const responseType = getResponseType(response)

@@ -41,4 +41,4 @@ const textResponse = await response.text()

const getFetchError = function (error, url, opts) {
const data = omit(opts, ['Authorization'])
export const getFetchError = function (error, url, opts) {
const data = omit.default(opts, ['Authorization'])
error.name = 'FetchError'

@@ -49,3 +49,1 @@ error.url = url

}
module.exports = { parseResponse, getFetchError }
// We retry:
// - when receiving a rate limiting response
// - on network failures due to timeouts
const shouldRetry = function ({ response = {}, error = {} }) {
export const shouldRetry = function ({ response = {}, error = {} }) {
return isRetryStatus(response) || RETRY_ERROR_CODES.has(error.code)

@@ -12,3 +12,3 @@ }

const waitForRetry = async function (response) {
export const waitForRetry = async function (response) {
const delay = getDelay(response)

@@ -41,7 +41,5 @@ await sleep(delay)

const SECS_TO_MSECS = 1e3
const MAX_RETRY = 5
export const MAX_RETRY = 5
const RATE_LIMIT_STATUS = 429
const RATE_LIMIT_HEADER = 'X-RateLimit-Reset'
const RETRY_ERROR_CODES = new Set(['ETIMEDOUT', 'ECONNRESET'])
module.exports = { shouldRetry, waitForRetry, MAX_RETRY }

@@ -1,7 +0,7 @@

const camelCase = require('lodash.camelcase')
const queryString = require('qs')
import camelCase from 'lodash.camelcase'
import queryString from 'qs'
// Replace path parameters and query parameters in the URI, using the OpenAPI
// definition
const getUrl = function ({ path, parameters }, basePath, requestParams) {
export const getUrl = function ({ path, parameters }, basePath, requestParams) {
const url = `${basePath}${path}`

@@ -48,3 +48,1 @@ const urlA = addPathParams(url, parameters, requestParams)

}
module.exports = { getUrl }

@@ -1,8 +0,9 @@

const { paths } = require('@netlify/open-api')
const omit = require('omit.js').default
import omit from 'omit.js'
import { openApiSpec } from './open_api.js'
// Retrieve all OpenAPI operations
const getOperations = function () {
return Object.entries(paths).flatMap(([path, pathItem]) => {
const operations = omit(pathItem, ['parameters'])
export const getOperations = function () {
return Object.entries(openApiSpec.paths).flatMap(([path, pathItem]) => {
const operations = omit.default(pathItem, ['parameters'])
return Object.entries(operations).map(([method, operation]) => {

@@ -23,3 +24,1 @@ const parameters = getParameters(pathItem.parameters, operation.parameters)

}
module.exports = { getOperations }
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc