Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: access.js
'use strict'
[0] Fix | Delete
/* eslint-disable standard/no-callback-literal */
[1] Fix | Delete
[2] Fix | Delete
const BB = require('bluebird')
[3] Fix | Delete
[4] Fix | Delete
const figgyPudding = require('figgy-pudding')
[5] Fix | Delete
const libaccess = require('libnpm/access')
[6] Fix | Delete
const npmConfig = require('./config/figgy-config.js')
[7] Fix | Delete
const output = require('./utils/output.js')
[8] Fix | Delete
const otplease = require('./utils/otplease.js')
[9] Fix | Delete
const path = require('path')
[10] Fix | Delete
const prefix = require('./npm.js').prefix
[11] Fix | Delete
const readPackageJson = BB.promisify(require('read-package-json'))
[12] Fix | Delete
const usage = require('./utils/usage.js')
[13] Fix | Delete
const whoami = require('./whoami.js')
[14] Fix | Delete
[15] Fix | Delete
module.exports = access
[16] Fix | Delete
[17] Fix | Delete
access.usage = usage(
[18] Fix | Delete
'npm access',
[19] Fix | Delete
'npm access public [<package>]\n' +
[20] Fix | Delete
'npm access restricted [<package>]\n' +
[21] Fix | Delete
'npm access grant <read-only|read-write> <scope:team> [<package>]\n' +
[22] Fix | Delete
'npm access revoke <scope:team> [<package>]\n' +
[23] Fix | Delete
'npm access 2fa-required [<package>]\n' +
[24] Fix | Delete
'npm access 2fa-not-required [<package>]\n' +
[25] Fix | Delete
'npm access ls-packages [<user>|<scope>|<scope:team>]\n' +
[26] Fix | Delete
'npm access ls-collaborators [<package> [<user>]]\n' +
[27] Fix | Delete
'npm access edit [<package>]'
[28] Fix | Delete
)
[29] Fix | Delete
[30] Fix | Delete
access.subcommands = [
[31] Fix | Delete
'public', 'restricted', 'grant', 'revoke',
[32] Fix | Delete
'ls-packages', 'ls-collaborators', 'edit',
[33] Fix | Delete
'2fa-required', '2fa-not-required'
[34] Fix | Delete
]
[35] Fix | Delete
[36] Fix | Delete
const AccessConfig = figgyPudding({
[37] Fix | Delete
json: {}
[38] Fix | Delete
})
[39] Fix | Delete
[40] Fix | Delete
function UsageError (msg = '') {
[41] Fix | Delete
throw Object.assign(new Error(
[42] Fix | Delete
(msg ? `\nUsage: ${msg}\n\n` : '') +
[43] Fix | Delete
access.usage
[44] Fix | Delete
), {code: 'EUSAGE'})
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
access.completion = function (opts, cb) {
[48] Fix | Delete
var argv = opts.conf.argv.remain
[49] Fix | Delete
if (argv.length === 2) {
[50] Fix | Delete
return cb(null, access.subcommands)
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
switch (argv[2]) {
[54] Fix | Delete
case 'grant':
[55] Fix | Delete
if (argv.length === 3) {
[56] Fix | Delete
return cb(null, ['read-only', 'read-write'])
[57] Fix | Delete
} else {
[58] Fix | Delete
return cb(null, [])
[59] Fix | Delete
}
[60] Fix | Delete
case 'public':
[61] Fix | Delete
case 'restricted':
[62] Fix | Delete
case 'ls-packages':
[63] Fix | Delete
case 'ls-collaborators':
[64] Fix | Delete
case 'edit':
[65] Fix | Delete
case '2fa-required':
[66] Fix | Delete
case '2fa-not-required':
[67] Fix | Delete
return cb(null, [])
[68] Fix | Delete
case 'revoke':
[69] Fix | Delete
return cb(null, [])
[70] Fix | Delete
default:
[71] Fix | Delete
return cb(new Error(argv[2] + ' not recognized'))
[72] Fix | Delete
}
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
function access ([cmd, ...args], cb) {
[76] Fix | Delete
return BB.try(() => {
[77] Fix | Delete
const fn = access.subcommands.includes(cmd) && access[cmd]
[78] Fix | Delete
if (!cmd) { UsageError('Subcommand is required.') }
[79] Fix | Delete
if (!fn) { UsageError(`${cmd} is not a recognized subcommand.`) }
[80] Fix | Delete
[81] Fix | Delete
return fn(args, AccessConfig(npmConfig()))
[82] Fix | Delete
}).then(
[83] Fix | Delete
x => cb(null, x),
[84] Fix | Delete
err => err.code === 'EUSAGE' ? cb(err.message) : cb(err)
[85] Fix | Delete
)
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
access.public = ([pkg], opts) => {
[89] Fix | Delete
return modifyPackage(pkg, opts, libaccess.public)
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
access.restricted = ([pkg], opts) => {
[93] Fix | Delete
return modifyPackage(pkg, opts, libaccess.restricted)
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
access.grant = ([perms, scopeteam, pkg], opts) => {
[97] Fix | Delete
return BB.try(() => {
[98] Fix | Delete
if (!perms || (perms !== 'read-only' && perms !== 'read-write')) {
[99] Fix | Delete
UsageError('First argument must be either `read-only` or `read-write.`')
[100] Fix | Delete
}
[101] Fix | Delete
if (!scopeteam) {
[102] Fix | Delete
UsageError('`<scope:team>` argument is required.')
[103] Fix | Delete
}
[104] Fix | Delete
const [, scope, team] = scopeteam.match(/^@?([^:]+):(.*)$/) || []
[105] Fix | Delete
if (!scope && !team) {
[106] Fix | Delete
UsageError(
[107] Fix | Delete
'Second argument used incorrect format.\n' +
[108] Fix | Delete
'Example: @example:developers'
[109] Fix | Delete
)
[110] Fix | Delete
}
[111] Fix | Delete
return modifyPackage(pkg, opts, (pkgName, opts) => {
[112] Fix | Delete
return libaccess.grant(pkgName, scopeteam, perms, opts)
[113] Fix | Delete
}, false)
[114] Fix | Delete
})
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
access.revoke = ([scopeteam, pkg], opts) => {
[118] Fix | Delete
return BB.try(() => {
[119] Fix | Delete
if (!scopeteam) {
[120] Fix | Delete
UsageError('`<scope:team>` argument is required.')
[121] Fix | Delete
}
[122] Fix | Delete
const [, scope, team] = scopeteam.match(/^@?([^:]+):(.*)$/) || []
[123] Fix | Delete
if (!scope || !team) {
[124] Fix | Delete
UsageError(
[125] Fix | Delete
'First argument used incorrect format.\n' +
[126] Fix | Delete
'Example: @example:developers'
[127] Fix | Delete
)
[128] Fix | Delete
}
[129] Fix | Delete
return modifyPackage(pkg, opts, (pkgName, opts) => {
[130] Fix | Delete
return libaccess.revoke(pkgName, scopeteam, opts)
[131] Fix | Delete
})
[132] Fix | Delete
})
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
access['2fa-required'] = access.tfaRequired = ([pkg], opts) => {
[136] Fix | Delete
return modifyPackage(pkg, opts, libaccess.tfaRequired, false)
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
access['2fa-not-required'] = access.tfaNotRequired = ([pkg], opts) => {
[140] Fix | Delete
return modifyPackage(pkg, opts, libaccess.tfaNotRequired, false)
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
access['ls-packages'] = access.lsPackages = ([owner], opts) => {
[144] Fix | Delete
return (
[145] Fix | Delete
owner ? BB.resolve(owner) : BB.fromNode(cb => whoami([], true, cb))
[146] Fix | Delete
).then(owner => {
[147] Fix | Delete
return libaccess.lsPackages(owner, opts)
[148] Fix | Delete
}).then(pkgs => {
[149] Fix | Delete
// TODO - print these out nicely (breaking change)
[150] Fix | Delete
output(JSON.stringify(pkgs, null, 2))
[151] Fix | Delete
})
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
access['ls-collaborators'] = access.lsCollaborators = ([pkg, usr], opts) => {
[155] Fix | Delete
return getPackage(pkg, false).then(pkgName =>
[156] Fix | Delete
libaccess.lsCollaborators(pkgName, usr, opts)
[157] Fix | Delete
).then(collabs => {
[158] Fix | Delete
// TODO - print these out nicely (breaking change)
[159] Fix | Delete
output(JSON.stringify(collabs, null, 2))
[160] Fix | Delete
})
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
access['edit'] = () => BB.reject(new Error('edit subcommand is not implemented yet'))
[164] Fix | Delete
[165] Fix | Delete
function modifyPackage (pkg, opts, fn, requireScope = true) {
[166] Fix | Delete
return getPackage(pkg, requireScope).then(pkgName =>
[167] Fix | Delete
otplease(opts, opts => fn(pkgName, opts))
[168] Fix | Delete
)
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
function getPackage (name, requireScope = true) {
[172] Fix | Delete
return BB.try(() => {
[173] Fix | Delete
if (name && name.trim()) {
[174] Fix | Delete
return name.trim()
[175] Fix | Delete
} else {
[176] Fix | Delete
return readPackageJson(
[177] Fix | Delete
path.resolve(prefix, 'package.json')
[178] Fix | Delete
).then(
[179] Fix | Delete
data => data.name,
[180] Fix | Delete
err => {
[181] Fix | Delete
if (err.code === 'ENOENT') {
[182] Fix | Delete
throw new Error('no package name passed to command and no package.json found')
[183] Fix | Delete
} else {
[184] Fix | Delete
throw err
[185] Fix | Delete
}
[186] Fix | Delete
}
[187] Fix | Delete
)
[188] Fix | Delete
}
[189] Fix | Delete
}).then(name => {
[190] Fix | Delete
if (requireScope && !name.match(/^@[^/]+\/.*$/)) {
[191] Fix | Delete
UsageError('This command is only available for scoped packages.')
[192] Fix | Delete
} else {
[193] Fix | Delete
return name
[194] Fix | Delete
}
[195] Fix | Delete
})
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function