Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: hook.js
'use strict'
[0] Fix | Delete
[1] Fix | Delete
const BB = require('bluebird')
[2] Fix | Delete
[3] Fix | Delete
const hookApi = require('libnpm/hook')
[4] Fix | Delete
const npmConfig = require('./config/figgy-config.js')
[5] Fix | Delete
const output = require('./utils/output.js')
[6] Fix | Delete
const otplease = require('./utils/otplease.js')
[7] Fix | Delete
const pudding = require('figgy-pudding')
[8] Fix | Delete
const relativeDate = require('tiny-relative-date')
[9] Fix | Delete
const Table = require('cli-table3')
[10] Fix | Delete
const validate = require('aproba')
[11] Fix | Delete
const npm = require('./npm')
[12] Fix | Delete
[13] Fix | Delete
hook.usage = [
[14] Fix | Delete
'npm hook add <pkg> <url> <secret> [--type=<type>]',
[15] Fix | Delete
'npm hook ls [pkg]',
[16] Fix | Delete
'npm hook rm <id>',
[17] Fix | Delete
'npm hook update <id> <url> <secret>'
[18] Fix | Delete
].join('\n')
[19] Fix | Delete
[20] Fix | Delete
hook.completion = (opts, cb) => {
[21] Fix | Delete
validate('OF', [opts, cb])
[22] Fix | Delete
return cb(null, []) // fill in this array with completion values
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
const HookConfig = pudding({
[26] Fix | Delete
json: {},
[27] Fix | Delete
loglevel: {},
[28] Fix | Delete
parseable: {},
[29] Fix | Delete
silent: {},
[30] Fix | Delete
unicode: {}
[31] Fix | Delete
})
[32] Fix | Delete
[33] Fix | Delete
function UsageError () {
[34] Fix | Delete
throw Object.assign(new Error(hook.usage), {code: 'EUSAGE'})
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
module.exports = (args, cb) => BB.try(() => hook(args)).then(
[38] Fix | Delete
val => cb(null, val),
[39] Fix | Delete
err => err.code === 'EUSAGE' ? cb(err.message) : cb(err)
[40] Fix | Delete
)
[41] Fix | Delete
function hook (args) {
[42] Fix | Delete
if (args.length === 4) { // secret is passed in the args
[43] Fix | Delete
// we have the user secret in the CLI args, we need to redact it from the referer.
[44] Fix | Delete
redactUserSecret()
[45] Fix | Delete
}
[46] Fix | Delete
return otplease(npmConfig(), opts => {
[47] Fix | Delete
opts = HookConfig(opts)
[48] Fix | Delete
switch (args[0]) {
[49] Fix | Delete
case 'add':
[50] Fix | Delete
return add(args[1], args[2], args[3], opts)
[51] Fix | Delete
case 'ls':
[52] Fix | Delete
return ls(args[1], opts)
[53] Fix | Delete
case 'rm':
[54] Fix | Delete
return rm(args[1], opts)
[55] Fix | Delete
case 'update':
[56] Fix | Delete
case 'up':
[57] Fix | Delete
return update(args[1], args[2], args[3], opts)
[58] Fix | Delete
default:
[59] Fix | Delete
UsageError()
[60] Fix | Delete
}
[61] Fix | Delete
})
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
function add (pkg, uri, secret, opts) {
[65] Fix | Delete
return hookApi.add(pkg, uri, secret, opts).then(hook => {
[66] Fix | Delete
if (opts.json) {
[67] Fix | Delete
output(JSON.stringify(hook, null, 2))
[68] Fix | Delete
} else if (opts.parseable) {
[69] Fix | Delete
output(Object.keys(hook).join('\t'))
[70] Fix | Delete
output(Object.keys(hook).map(k => hook[k]).join('\t'))
[71] Fix | Delete
} else if (!opts.silent && opts.loglevel !== 'silent') {
[72] Fix | Delete
output(`+ ${hookName(hook)} ${
[73] Fix | Delete
opts.unicode ? ' ➜ ' : ' -> '
[74] Fix | Delete
} ${hook.endpoint}`)
[75] Fix | Delete
}
[76] Fix | Delete
})
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
function ls (pkg, opts) {
[80] Fix | Delete
return hookApi.ls(opts.concat({package: pkg})).then(hooks => {
[81] Fix | Delete
if (opts.json) {
[82] Fix | Delete
output(JSON.stringify(hooks, null, 2))
[83] Fix | Delete
} else if (opts.parseable) {
[84] Fix | Delete
output(Object.keys(hooks[0]).join('\t'))
[85] Fix | Delete
hooks.forEach(hook => {
[86] Fix | Delete
output(Object.keys(hook).map(k => hook[k]).join('\t'))
[87] Fix | Delete
})
[88] Fix | Delete
} else if (!hooks.length) {
[89] Fix | Delete
output("You don't have any hooks configured yet.")
[90] Fix | Delete
} else if (!opts.silent && opts.loglevel !== 'silent') {
[91] Fix | Delete
if (hooks.length === 1) {
[92] Fix | Delete
output('You have one hook configured.')
[93] Fix | Delete
} else {
[94] Fix | Delete
output(`You have ${hooks.length} hooks configured.`)
[95] Fix | Delete
}
[96] Fix | Delete
const table = new Table({head: ['id', 'target', 'endpoint']})
[97] Fix | Delete
hooks.forEach((hook) => {
[98] Fix | Delete
table.push([
[99] Fix | Delete
{rowSpan: 2, content: hook.id},
[100] Fix | Delete
hookName(hook),
[101] Fix | Delete
hook.endpoint
[102] Fix | Delete
])
[103] Fix | Delete
if (hook.last_delivery) {
[104] Fix | Delete
table.push([
[105] Fix | Delete
{
[106] Fix | Delete
colSpan: 1,
[107] Fix | Delete
content: `triggered ${relativeDate(hook.last_delivery)}`
[108] Fix | Delete
},
[109] Fix | Delete
hook.response_code
[110] Fix | Delete
])
[111] Fix | Delete
} else {
[112] Fix | Delete
table.push([{colSpan: 2, content: 'never triggered'}])
[113] Fix | Delete
}
[114] Fix | Delete
})
[115] Fix | Delete
output(table.toString())
[116] Fix | Delete
}
[117] Fix | Delete
})
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
function rm (id, opts) {
[121] Fix | Delete
return hookApi.rm(id, opts).then(hook => {
[122] Fix | Delete
if (opts.json) {
[123] Fix | Delete
output(JSON.stringify(hook, null, 2))
[124] Fix | Delete
} else if (opts.parseable) {
[125] Fix | Delete
output(Object.keys(hook).join('\t'))
[126] Fix | Delete
output(Object.keys(hook).map(k => hook[k]).join('\t'))
[127] Fix | Delete
} else if (!opts.silent && opts.loglevel !== 'silent') {
[128] Fix | Delete
output(`- ${hookName(hook)} ${
[129] Fix | Delete
opts.unicode ? ' ✘ ' : ' X '
[130] Fix | Delete
} ${hook.endpoint}`)
[131] Fix | Delete
}
[132] Fix | Delete
})
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
function update (id, uri, secret, opts) {
[136] Fix | Delete
return hookApi.update(id, uri, secret, opts).then(hook => {
[137] Fix | Delete
if (opts.json) {
[138] Fix | Delete
output(JSON.stringify(hook, null, 2))
[139] Fix | Delete
} else if (opts.parseable) {
[140] Fix | Delete
output(Object.keys(hook).join('\t'))
[141] Fix | Delete
output(Object.keys(hook).map(k => hook[k]).join('\t'))
[142] Fix | Delete
} else if (!opts.silent && opts.loglevel !== 'silent') {
[143] Fix | Delete
output(`+ ${hookName(hook)} ${
[144] Fix | Delete
opts.unicode ? ' ➜ ' : ' -> '
[145] Fix | Delete
} ${hook.endpoint}`)
[146] Fix | Delete
}
[147] Fix | Delete
})
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
function hookName (hook) {
[151] Fix | Delete
let target = hook.name
[152] Fix | Delete
if (hook.type === 'scope') { target = '@' + target }
[153] Fix | Delete
if (hook.type === 'owner') { target = '~' + target }
[154] Fix | Delete
return target
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
function redactUserSecret () {
[158] Fix | Delete
const referer = npm.referer
[159] Fix | Delete
if (!referer) return
[160] Fix | Delete
const splittedReferer = referer.split(' ')
[161] Fix | Delete
splittedReferer[4] = '[REDACTED]'
[162] Fix | Delete
npm.referer = splittedReferer.join(' ')
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function