gl-got
Advanced tools
Comparing version 8.0.0 to 9.0.0
92
index.js
'use strict'; | ||
const got = require('got'); | ||
const isPlainObj = require('is-plain-obj'); | ||
function glGot(path, opts) { | ||
if (typeof path !== 'string') { | ||
return Promise.reject( | ||
new TypeError(`Expected \`path\` to be a string, got ${typeof path}`) | ||
); | ||
} | ||
const create = () => got.create({ | ||
options: got.mergeOptions(got.defaults.options, { | ||
json: true, | ||
token: process.env.GITLAB_TOKEN, | ||
baseUrl: process.env.GITLAB_ENDPOINT || 'https://gitlab.com/api/v4', | ||
headers: { | ||
'user-agent': 'https://github.com/singapore/gl-got' | ||
} | ||
}), | ||
methods: got.defaults.methods, | ||
handler: (options, next) => { | ||
if (options.token) { | ||
options.headers.authorization = `token ${options.token}`; | ||
} | ||
const env = process.env; | ||
if (options.method && options.method === 'PUT' && !options.body) { | ||
options.headers['content-length'] = 0; | ||
} | ||
opts = Object.assign( | ||
{ | ||
json: true, | ||
token: env.GITLAB_TOKEN, | ||
endpoint: env.GITLAB_ENDPOINT | ||
? env.GITLAB_ENDPOINT.replace(/[^/]$/, '$&/') | ||
: 'https://gitlab.com/api/v4/', | ||
}, | ||
opts | ||
); | ||
if (options.stream) { | ||
return next(options); | ||
} | ||
opts.headers = Object.assign( | ||
{ | ||
'user-agent': 'https://github.com/singapore/gl-got', | ||
}, | ||
opts.headers | ||
); | ||
return next(options).catch(err => { | ||
if (err.response && err.response.body) { | ||
err.name = 'GitLabError'; | ||
err.message = `${err.response.body.message || err.response.body} (${err.statusCode})`; | ||
} | ||
if (opts.token) { | ||
opts.headers['PRIVATE-TOKEN'] = opts.token; | ||
} | ||
throw err; | ||
}); | ||
} | ||
}); | ||
const url = /^https?/.test(path) ? path : opts.endpoint + path; | ||
module.exports = create(); | ||
if (opts.stream) { | ||
return got.stream(url, opts); | ||
} | ||
return got(url, opts).catch(err => { | ||
if (err.response && isPlainObj(err.response.body)) { | ||
err.name = 'GitLabError'; | ||
err.message = `${err.response.body.message} (${err.statusCode})`; | ||
} | ||
throw err; | ||
}); | ||
if (process.env.NODE_ENV === 'test') { | ||
module.exports.recreate = create; | ||
} | ||
const helpers = ['get', 'post', 'put', 'patch', 'head', 'delete']; | ||
glGot.stream = (url, opts) => | ||
glGot( | ||
url, | ||
Object.assign({}, opts, { | ||
json: false, | ||
stream: true, | ||
}) | ||
); | ||
for (const x of helpers) { | ||
const method = x.toUpperCase(); | ||
glGot[x] = (url, opts) => glGot(url, Object.assign({}, opts, { method })); | ||
glGot.stream[x] = (url, opts) => | ||
glGot.stream(url, Object.assign({}, opts, { method })); | ||
} | ||
module.exports = glGot; |
{ | ||
"name": "gl-got", | ||
"version": "8.0.0", | ||
"version": "9.0.0", | ||
"description": "Convenience wrapper for `got` to interact with the GitLab API", | ||
@@ -9,9 +9,13 @@ "license": "MIT", | ||
"name": "Rhys Arkins", | ||
"email": "rhys@keylocation.sg" | ||
"email": "rhys@arkins.net" | ||
}, | ||
"contributors": [ | ||
"Itai Steinherz <itaisteinherz@gmail.com>", | ||
"Hutson Betts <hutson@hyper-expanse.net>" | ||
], | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && nyc ava && nyc report --reporter=html" | ||
"test": "xo && nyc --all --cache --include=index.js --exclude=test.js --reporter=lcov --reporter=text ava" | ||
}, | ||
@@ -36,20 +40,11 @@ "files": [ | ||
"dependencies": { | ||
"got": "^7.0.0", | ||
"is-plain-obj": "^1.1.0" | ||
"got": "^9.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "0.20.0", | ||
"get-stream": "3.0.0", | ||
"ava": "^1.0.0-beta.7", | ||
"get-stream": "^4.0.0", | ||
"nock": "9.0.13", | ||
"nyc": "11.0.1", | ||
"prettier": "1.7.4", | ||
"xo": "0.18.2" | ||
"xo": "^0.22.0" | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
}, | ||
"renovate": { | ||
"automerge": "minor" | ||
}, | ||
"xo": { | ||
@@ -56,0 +51,0 @@ "esnext": true |
@@ -70,6 +70,6 @@ # gl-got [![Build Status](https://travis-ci.org/singapore/gl-got.svg?branch=master)](https://travis-ci.org/singapore/gl-got) | ||
### endpoint | ||
### baseUrl | ||
Type: `string`<br> | ||
Default: `https://gitlab.com/api/v3/` | ||
Default: `https://gitlab.com/api/v3` | ||
@@ -76,0 +76,0 @@ Can be set globally with the `GITLAB_ENDPOINT` environment variable. |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1
5
4943
35
3
+ Added@sindresorhus/is@0.14.0(transitive)
+ Added@szmarczak/http-timer@1.1.2(transitive)
+ Addedcacheable-request@6.1.0(transitive)
+ Addedclone-response@1.0.3(transitive)
+ Addeddefer-to-connect@1.1.3(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedget-stream@4.1.05.2.0(transitive)
+ Addedgot@9.6.0(transitive)
+ Addedhttp-cache-semantics@4.1.1(transitive)
+ Addedjson-buffer@3.0.0(transitive)
+ Addedkeyv@3.1.0(transitive)
+ Addedlowercase-keys@2.0.0(transitive)
+ Addednormalize-url@4.5.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedp-cancelable@1.1.0(transitive)
+ Addedprepend-http@2.0.0(transitive)
+ Addedpump@3.0.0(transitive)
+ Addedresponselike@1.0.2(transitive)
+ Addedto-readable-stream@1.0.0(transitive)
+ Addedurl-parse-lax@3.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedis-plain-obj@^1.1.0
- Removedget-stream@3.0.0(transitive)
- Removedgot@7.1.0(transitive)
- Removedhas-symbol-support-x@1.4.2(transitive)
- Removedhas-to-string-tag-x@1.4.1(transitive)
- Removedis-object@1.0.2(transitive)
- Removedis-plain-obj@1.1.0(transitive)
- Removedis-retry-allowed@1.2.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisurl@1.0.0(transitive)
- Removedp-cancelable@0.3.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-timeout@1.2.1(transitive)
- Removedprepend-http@1.0.4(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedtimed-out@4.0.1(transitive)
- Removedurl-parse-lax@1.0.0(transitive)
- Removedurl-to-options@1.0.1(transitive)
Updatedgot@^9.1.0