credentials-by-uri
Advanced tools
Comparing version 1.0.0 to 2.0.0-0
export = getCredentialsByURI | ||
declare function getCredentialsByURI (uri: string, config: Object): { | ||
scope: string, | ||
token: string | undefined, | ||
password: string | undefined, | ||
username: string | undefined, | ||
email: string | undefined, | ||
auth: string | undefined, | ||
alwaysAuth: string | undefined | ||
authHeaderValue: string | undefined, | ||
alwaysAuth: boolean | undefined | ||
} |
83
index.js
'use strict' | ||
var assert = require('assert') | ||
const assert = require('assert') | ||
var toNerfDart = require('nerf-dart') | ||
const toNerfDart = require('nerf-dart') | ||
@@ -10,65 +10,54 @@ module.exports = getCredentialsByURI | ||
assert(uri && typeof uri === 'string', 'registry URL is required') | ||
var nerfed = toNerfDart(uri) | ||
var defnerf = toNerfDart(config['registry']) | ||
const nerfed = toNerfDart(uri) | ||
const defnerf = toNerfDart(config.registry) | ||
// hidden class micro-optimization | ||
var c = { | ||
scope: nerfed, | ||
token: undefined, | ||
password: undefined, | ||
username: undefined, | ||
email: undefined, | ||
auth: undefined, | ||
alwaysAuth: undefined | ||
const creds = getScopedCredentials(nerfed, `${nerfed}:`, config) | ||
if (nerfed !== defnerf) return creds | ||
return { | ||
...getScopedCredentials(nerfed, '', config), | ||
...creds | ||
} | ||
} | ||
function getScopedCredentials (nerfed, scope, config) { | ||
// hidden class micro-optimization | ||
const c = {} | ||
// used to override scope matching for tokens as well as legacy auth | ||
if (config[nerfed + ':always-auth'] !== undefined) { | ||
var val = config[nerfed + ':always-auth'] | ||
if (config[`${scope}always-auth`] !== undefined) { | ||
const val = config[`${scope}always-auth`] | ||
c.alwaysAuth = val === 'false' ? false : !!val | ||
} else if (config['always-auth'] !== undefined) { | ||
c.alwaysAuth = config['always-auth'] | ||
} | ||
if (config[nerfed + ':_authToken']) { | ||
c.token = config[nerfed + ':_authToken'] | ||
// the bearer token is enough, don't confuse things | ||
// Check for bearer token | ||
if (config[`${scope}_authToken`]) { | ||
c.authHeaderValue = `Bearer ${config[`${scope}_authToken`]}` | ||
return c | ||
} | ||
// Handle the old-style _auth=<base64> style for the default | ||
// registry, if set. | ||
var authDef = config['_auth'] | ||
var userDef = config['username'] | ||
var passDef = config['_password'] | ||
if (authDef && !(userDef && passDef)) { | ||
authDef = new Buffer(authDef, 'base64').toString() | ||
authDef = authDef.split(':') | ||
userDef = authDef.shift() | ||
passDef = authDef.join(':') | ||
// Check for basic auth token | ||
if (config[`${scope}_auth`]) { | ||
c.authHeaderValue = `Basic ${config[`${scope}_auth`]}` | ||
return c | ||
} | ||
if (config[nerfed + ':_password']) { | ||
c.password = new Buffer(config[nerfed + ':_password'], 'base64').toString('utf8') | ||
} else if (nerfed === defnerf && passDef) { | ||
c.password = passDef | ||
// Check for username/password auth | ||
let username, password | ||
if (config[`${scope}username`]) { | ||
username = config[`${scope}username`] | ||
} | ||
if (config[nerfed + ':username']) { | ||
c.username = config[nerfed + ':username'] | ||
} else if (nerfed === defnerf && userDef) { | ||
c.username = userDef | ||
if (config[`${scope}_password`]) { | ||
if (scope === '') { | ||
password = config[`${scope}_password`] | ||
} else { | ||
password = Buffer.from(config[`${scope}_password`], 'base64').toString('utf8') | ||
} | ||
} | ||
if (config[nerfed + ':email']) { | ||
c.email = config[nerfed + ':email'] | ||
} else if (config['email']) { | ||
c.email = config['email'] | ||
if (username && password) { | ||
c.authHeaderValue = `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}` | ||
} | ||
if (c.username && c.password) { | ||
c.auth = new Buffer(c.username + ':' + c.password).toString('base64') | ||
} | ||
return c | ||
} |
{ | ||
"name": "credentials-by-uri", | ||
"version": "1.0.0", | ||
"description": "Gets credentials for URI from npm configs", | ||
"main": "index.js", | ||
"typings": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"test": "node test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/pnpm/credentials-by-uri.git" | ||
}, | ||
"keywords": [ | ||
"npm", | ||
"config", | ||
"credentials" | ||
], | ||
"author": { | ||
"name": "Zoltan Kochan", | ||
"email": "z@kochan.io", | ||
"url": "https://www.kochan.io", | ||
"twitter": "ZoltanKochan" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnpm/credentials-by-uri/issues" | ||
}, | ||
"homepage": "https://github.com/pnpm/credentials-by-uri#readme", | ||
"dependencies": { | ||
"nerf-dart": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"safe-buffer": "^5.1.1", | ||
"tape": "^4.8.0" | ||
} | ||
"name": "credentials-by-uri", | ||
"version": "2.0.0-0", | ||
"description": "Gets credentials for URI from npm configs", | ||
"main": "index.js", | ||
"typings": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"scripts": { | ||
"test": "standard && c8 node test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/pnpm/credentials-by-uri.git" | ||
}, | ||
"keywords": [ | ||
"npm", | ||
"config", | ||
"credentials" | ||
], | ||
"author": { | ||
"name": "Zoltan Kochan", | ||
"email": "z@kochan.io", | ||
"url": "https://www.kochan.io", | ||
"twitter": "ZoltanKochan" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnpm/credentials-by-uri/issues" | ||
}, | ||
"homepage": "https://github.com/pnpm/credentials-by-uri#readme", | ||
"dependencies": { | ||
"nerf-dart": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"c8": "^7.0.1", | ||
"safe-buffer": "^5.1.1", | ||
"standard": "^14.3.1", | ||
"tape": "^4.8.0" | ||
} | ||
} |
@@ -12,6 +12,4 @@ # credentials-by-uri | ||
Install it via npm. | ||
``` | ||
npm install credentials-by-uri | ||
pnpm add credentials-by-uri | ||
``` | ||
@@ -18,0 +16,0 @@ |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4647
4
55
1
31