netlify 11.0.3 → 12.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "netlify",
3
3
  "description": "Netlify Node.js API client",
4
- "version": "11.0.3",
4
+ "version": "12.0.1",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "src/**/*.js",
@@ -52,7 +52,7 @@
52
52
  "node client"
53
53
  ],
54
54
  "dependencies": {
55
- "@netlify/open-api": "^2.10.0",
55
+ "@netlify/open-api": "^2.12.0",
56
56
  "lodash.camelcase": "^4.3.0",
57
57
  "micro-api-client": "^3.3.0",
58
58
  "node-fetch": "^3.0.0",
@@ -61,11 +61,11 @@
61
61
  "qs": "^6.9.6"
62
62
  },
63
63
  "devDependencies": {
64
- "@netlify/eslint-config-node": "^6.0.0",
64
+ "@netlify/eslint-config-node": "^7.0.0",
65
65
  "ava": "^4.0.0",
66
66
  "c8": "^7.11.0",
67
67
  "from2-string": "^1.1.0",
68
- "husky": "^7.0.4",
68
+ "husky": "^8.0.0",
69
69
  "nock": "^13.0.0",
70
70
  "npm-run-all": "^4.1.5",
71
71
  "uuid": "^8.3.2"
@@ -3,6 +3,7 @@ import fetch from 'node-fetch'
3
3
  import { getOperations } from '../operations.js'
4
4
 
5
5
  import { addBody } from './body.js'
6
+ import { getRequestParams } from './params.js'
6
7
  import { parseResponse, getFetchError } from './response.js'
7
8
  import { shouldRetry, waitForRetry, MAX_RETRY } from './retry.js'
8
9
  import { getUrl } from './url.js'
@@ -32,12 +33,23 @@ const callMethod = async function ({ method, basePath, defaultHeaders, agent, gl
32
33
  return parsedResponse
33
34
  }
34
35
 
35
- const getOpts = function ({ method: { verb, parameters }, defaultHeaders, agent, requestParams: { body }, opts }) {
36
+ const getOpts = function ({ method: { verb, parameters }, defaultHeaders, agent, requestParams, opts }) {
37
+ const { body } = requestParams
36
38
  const optsA = addHttpMethod(verb, opts)
37
- const optsB = addDefaultHeaders(defaultHeaders, optsA)
38
- const optsC = addBody(body, parameters, optsB)
39
- const optsD = addAgent(agent, optsC)
40
- return optsD
39
+ const optsB = addHeaderParams(parameters, requestParams, optsA)
40
+ const optsC = addDefaultHeaders(defaultHeaders, optsB)
41
+ const optsD = addBody(body, parameters, optsC)
42
+ const optsE = addAgent(agent, optsD)
43
+ return optsE
44
+ }
45
+
46
+ // Add header parameters
47
+ const addHeaderParams = function (parameters, requestParams, opts) {
48
+ if (parameters.header === undefined) {
49
+ return opts
50
+ }
51
+
52
+ return { ...opts, headers: getRequestParams(parameters.header, requestParams, 'header parameter') }
41
53
  }
42
54
 
43
55
  // Add the HTTP method based on the OpenAPI definition
@@ -64,7 +76,7 @@ const makeRequestOrRetry = async function ({ url, method, defaultHeaders, agent,
64
76
  const optsA = getOpts({ method, defaultHeaders, agent, requestParams, opts })
65
77
  const { response, error } = await makeRequest(url, optsA)
66
78
 
67
- if (shouldRetry({ response, error }) && index !== MAX_RETRY) {
79
+ if (shouldRetry({ response, error, method }) && index !== MAX_RETRY) {
68
80
  await waitForRetry(response)
69
81
  continue
70
82
  }
@@ -0,0 +1,18 @@
1
+ import camelCase from 'lodash.camelcase'
2
+
3
+ export const getRequestParams = function (params, requestParams, name) {
4
+ const entries = Object.values(params).map((param) => getRequestParam(param, requestParams, name))
5
+ return Object.assign({}, ...entries)
6
+ }
7
+
8
+ const getRequestParam = function (param, requestParams, name) {
9
+ const value = requestParams[param.name] || requestParams[camelCase(param.name)]
10
+
11
+ if (value !== undefined) {
12
+ return { [param.name]: value }
13
+ }
14
+
15
+ if (param.required) {
16
+ throw new Error(`Missing required ${name} '${param.name}'`)
17
+ }
18
+ }
@@ -1,12 +1,18 @@
1
1
  // We retry:
2
2
  // - when receiving a rate limiting response
3
3
  // - on network failures due to timeouts
4
- export const shouldRetry = function ({ response = {}, error = {} }) {
5
- return isRetryStatus(response) || RETRY_ERROR_CODES.has(error.code)
6
- }
4
+ export const shouldRetry = function ({ response = {}, error = {}, method = {} }) {
5
+ if (response.status === RATE_LIMIT_STATUS || RETRY_ERROR_CODES.has(error.code)) {
6
+ return true
7
+ }
8
+
9
+ // Special case for the `getLatestPluginRuns` endpoint.
10
+ // See https://github.com/netlify/bitballoon/issues/9616.
11
+ if (method.operationId === 'getLatestPluginRuns' && response.status === 500) {
12
+ return true
13
+ }
7
14
 
8
- const isRetryStatus = function ({ status }) {
9
- return typeof status === 'number' && (status === RATE_LIMIT_STATUS || String(status).startsWith('5'))
15
+ return false
10
16
  }
11
17
 
12
18
  export const waitForRetry = async function (response) {
@@ -1,6 +1,7 @@
1
- import camelCase from 'lodash.camelcase'
2
1
  import queryString from 'qs'
3
2
 
3
+ import { getRequestParams } from './params.js'
4
+
4
5
  // Replace path parameters and query parameters in the URI, using the OpenAPI
5
6
  // definition
6
7
  export const getUrl = function ({ path, parameters }, basePath, requestParams) {
@@ -28,20 +29,3 @@ const addQueryParams = function (url, parameters, requestParams) {
28
29
 
29
30
  return `${url}?${queryString.stringify(queryParams, { arrayFormat: 'brackets' })}`
30
31
  }
31
-
32
- const getRequestParams = function (params, requestParams, name) {
33
- const entries = Object.values(params).map((param) => getRequestParam(param, requestParams, name))
34
- return Object.assign({}, ...entries)
35
- }
36
-
37
- const getRequestParam = function (param, requestParams, name) {
38
- const value = requestParams[param.name] || requestParams[camelCase(param.name)]
39
-
40
- if (value !== undefined) {
41
- return { [param.name]: value }
42
- }
43
-
44
- if (param.required) {
45
- throw new Error(`Missing required ${name} '${param.name}'`)
46
- }
47
- }