Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
request(url: string, options: any = {}) {
options.headers = {
Authorization: `Bearer ${this.token}`,
'User-Agent': this.version
}
if (['POST', 'PATCH', 'DELETE'].includes(options.method)) {
options.headers['Content-type'] = 'application/json'
}
return HTTP.request(KOLKRABBI_BASE_URL + url, options).then((res: any) => res.body)
}
async function get (name, etag) {
try {
if (etag && redis && (await isEtagFresh(name, etag))) return 304
let pkg = redis ? await fetchFromCache(name) : null
if (pkg) return pkg
let req = await HTTP.request(url.resolve(config.uplink.href, '/' + name.replace(/\//, '%2F')), getRequestOpts(etag))
pkg = typeof req.body === 'string' ? JSON.parse(req.body) : req.body
if (!pkg.versions) return 404
pkg.etag = req.response.headers.etag
updateCache(pkg)
return pkg
} catch (err) {
switch (err.statusCode) {
case 304:
if (redis) updateEtag(name, etag)
return 304
case 404:
return 404
default:
warn(err, {pkg: name})
return 404
}