Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = {
'no-magic-numbers': 0,
'no-param-reassign': 0,
'fp/no-class': 0,
'fp/no-delete': 0,
'fp/no-let': 0,
'fp/no-loops': 0,
'fp/no-mutating-assign': 0,
Expand Down
18 changes: 7 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@
"@netlify/zip-it-and-ship-it": "^1.3.12",
"backoff": "^2.5.0",
"clean-deep": "^3.3.0",
"filter-obj": "^2.0.1",
"flush-write-stream": "^2.0.0",
"folder-walker": "^3.2.0",
"from2-array": "0.0.4",
"hasha": "^5.0.0",
"lodash.camelcase": "^4.3.0",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
"micro-api-client": "^3.3.0",
"node-fetch": "^2.2.0",
"omit.js": "^2.0.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously removed by #93
However, omit.js does not use core-js anymore, so we can use it again.

"p-map": "^3.0.0",
"p-wait-for": "^3.1.0",
"parallel-transform": "^1.1.0",
Expand Down
19 changes: 13 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const dfn = require('@netlify/open-api')
const get = require('lodash.get')
const set = require('lodash.set')
const pWaitFor = require('p-wait-for')

const deploy = require('./deploy')
Expand Down Expand Up @@ -41,15 +39,24 @@ class NetlifyAPI {
}

get accessToken() {
return (get(this, 'defaultHeaders.Authorization') || '').replace('Bearer ', '') || null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.defaultHeaders is set by the constuctors, so we can assume it is defined.

const {
defaultHeaders: { Authorization },
} = this
if (typeof Authorization !== 'string' || !Authorization.startsWith('Bearer ')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is slightly different, but seems to capture the actual intent. @erezrokah What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this looks much better

return null
}

return Authorization.replace('Bearer ', '')
}

set accessToken(token) {
if (token) {
set(this, 'defaultHeaders.Authorization', `Bearer ${token}`)
} else {
if (!token) {
// eslint-disable-next-line fp/no-delete
delete this.defaultHeaders.Authorization
return
}

this.defaultHeaders.Authorization = `Bearer ${token}`
}

get basePath() {
Expand Down
4 changes: 2 additions & 2 deletions src/methods/response.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { JSONHTTPError, TextHTTPError } = require('micro-api-client')
const omit = require('omit.js').default

// Read and parse the HTTP response
const parseResponse = async function (response) {
Expand Down Expand Up @@ -38,8 +39,7 @@ const parseJsonResponse = function (response, textResponse, responseType) {
}

const getFetchError = function (error, url, opts) {
const data = { ...opts }
delete data.Authorization
const data = omit(opts, ['Authorization'])
Object.assign(error, { name: 'FetchError', url, data })
return error
}
Expand Down
3 changes: 1 addition & 2 deletions src/operations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { paths } = require('@netlify/open-api')

const { omit } = require('./utils/omit')
const omit = require('omit.js').default

// Retrieve all OpenAPI operations
const getOperations = function () {
Expand Down
8 changes: 0 additions & 8 deletions src/utils/omit.js

This file was deleted.