diff --git a/commands/hook.js b/commands/hook.js index fa9fbc9..f713ec0 100644 --- a/commands/hook.js +++ b/commands/hook.js @@ -12,7 +12,6 @@ function hooks(argv) hooks.add = function add(argv) { - // TODO match with service report.success('hook add', 'hooking ' + chalk.yellow(argv.pkg) + ' to ' + chalk.yellow(argv.url) + ' with shared secret ' + chalk.red(argv.secret) @@ -37,7 +36,7 @@ hooks.add = function add(argv) if (!hook || res.statusCode < 200 || res.statusCode >= 400) return report.failure('hook add', res.statusCode + ' ' + JSON.stringify(hook)); - // TODO assumption here is that the body of the response is the updated hook + report.success('+', hook.name + ' ➜ ' + hook.endpoint); }); }; @@ -66,6 +65,8 @@ hooks.rm = function rm(argv) hooks.ls = function ls(argv) { + + var reg = new Registry(argv); var uri = '/v1/hooks/hook'; if (argv.pkg) diff --git a/lib/registry.js b/lib/registry.js index f37dbb8..294e02a 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -38,17 +38,26 @@ Registry.prototype._registry = null; Registry.prototype.authed = function authed(opts, callback) { var token = this.getAuthToken(this.registry); + if (!token) return callback(new Error('you are not logged into the registry you are trying to use "' + this.registry + '"')); var hostname = opts.legacy ? this.registry : this.api; + + // add a slash if it missing. + // not using url.resolve so we can support api through the registry url paths. url.resolve(hostname, opts.uri), + // https://registry.npmjs.org/-/api/v1/hooks/hook etc. + // we should remove the default api url probably? + // + if(opts.uri.indexOf('/') !== 0) + opts.uri = '/' + opts.uri; + var options = { - url: url.resolve(hostname, opts.uri), - method: opts.method, + url: hostname + opts.uri, + method: opts.method || 'GET', json: opts.json || opts.body || true, - auth: { bearer: token } + auth:{bearer:token} }; - this.requestfunc(options, callback); }; @@ -64,6 +73,7 @@ Registry.prototype.anonymous = function anonymous(opts, callback) this.requestfunc(options, callback); }; + function getReg() { return this._registry;