JezK
Edit File: login.js
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.getOneTimePassword = getOneTimePassword; exports.getToken = getToken; exports.hasWrapper = hasWrapper; exports.run = run; exports.setFlags = setFlags; function _regenerator() { var data = _interopRequireDefault(require("@babel/runtime/regenerator")); _regenerator = function _regenerator() { return data; }; return data; } function _asyncToGenerator2() { var data = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); _asyncToGenerator2 = function _asyncToGenerator2() { return data; }; return data; } function _errors() { var data = require("../../errors.js"); _errors = function _errors() { return data; }; return data; } function getCredentials(_x, _x2) { return _getCredentials.apply(this, arguments); } function _getCredentials() { _getCredentials = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee(config, reporter) { var _config$registries$ya, username, email; return _regenerator()["default"].wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _config$registries$ya = config.registries.yarn.config, username = _config$registries$ya.username, email = _config$registries$ya.email; if (!username) { _context.next = 5; break; } reporter.info("".concat(reporter.lang('npmUsername'), ": ").concat(username)); _context.next = 10; break; case 5: _context.next = 7; return reporter.question(reporter.lang('npmUsername')); case 7: username = _context.sent; if (username) { _context.next = 10; break; } return _context.abrupt("return", null); case 10: if (!email) { _context.next = 14; break; } reporter.info("".concat(reporter.lang('npmEmail'), ": ").concat(email)); _context.next = 19; break; case 14: _context.next = 16; return reporter.question(reporter.lang('npmEmail')); case 16: email = _context.sent; if (email) { _context.next = 19; break; } return _context.abrupt("return", null); case 19: _context.next = 21; return config.registries.yarn.saveHomeConfig({ username: username, email: email }); case 21: return _context.abrupt("return", { username: username, email: email }); case 22: case "end": return _context.stop(); } }, _callee); })); return _getCredentials.apply(this, arguments); } function getOneTimePassword(reporter) { return reporter.question(reporter.lang('npmOneTimePassword')); } function getToken(_x3, _x4) { return _getToken.apply(this, arguments); } function _getToken() { _getToken = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee3(config, reporter) { var name, flags, registry, auth, env, creds, username, email, password, userobj, res, token, _args3 = arguments; return _regenerator()["default"].wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: name = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : ''; flags = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : {}; registry = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : ''; auth = registry ? config.registries.npm.getAuthByRegistry(registry) : config.registries.npm.getAuth(name); if (config.otp) { config.registries.npm.setOtp(config.otp); } if (!auth) { _context3.next = 8; break; } config.registries.npm.setToken(auth); return _context3.abrupt("return", function revoke() { reporter.info(reporter.lang('notRevokingConfigToken')); return Promise.resolve(); }); case 8: env = process.env.YARN_AUTH_TOKEN || process.env.NPM_AUTH_TOKEN; if (!env) { _context3.next = 12; break; } config.registries.npm.setToken("Bearer ".concat(env)); return _context3.abrupt("return", function revoke() { reporter.info(reporter.lang('notRevokingEnvToken')); return Promise.resolve(); }); case 12: if (!(flags.nonInteractive || config.nonInteractive)) { _context3.next = 14; break; } throw new (_errors().MessageError)(reporter.lang('nonInteractiveNoToken')); case 14: _context3.next = 16; return getCredentials(config, reporter); case 16: creds = _context3.sent; if (creds) { _context3.next = 20; break; } reporter.warn(reporter.lang('loginAsPublic')); return _context3.abrupt("return", function revoke() { reporter.info(reporter.lang('noTokenToRevoke')); return Promise.resolve(); }); case 20: username = creds.username, email = creds.email; _context3.next = 23; return reporter.question(reporter.lang('npmPassword'), { password: true, required: true }); case 23: password = _context3.sent; // userobj = { _id: "org.couchdb.user:".concat(username), name: username, password: password, email: email, type: 'user', roles: [], date: new Date().toISOString() }; // _context3.next = 27; return config.registries.npm.request("-/user/org.couchdb.user:".concat(encodeURIComponent(username)), { method: 'PUT', registry: registry, body: userobj, auth: { username: username, password: password, email: email } }); case 27: res = _context3.sent; if (!(res && res.ok)) { _context3.next = 35; break; } reporter.success(reporter.lang('loggedIn')); token = res.token; config.registries.npm.setToken("Bearer ".concat(token)); return _context3.abrupt("return", /*#__PURE__*/function () { var _revoke = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee2() { return _regenerator()["default"].wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: reporter.success(reporter.lang('revokedToken')); _context2.next = 3; return config.registries.npm.request("-/user/token/".concat(token), { method: 'DELETE', registry: registry }); case 3: case "end": return _context2.stop(); } }, _callee2); })); function revoke() { return _revoke.apply(this, arguments); } return revoke; }()); case 35: throw new (_errors().MessageError)(reporter.lang('incorrectCredentials')); case 36: case "end": return _context3.stop(); } }, _callee3); })); return _getToken.apply(this, arguments); } function hasWrapper(commander, args) { return true; } function setFlags(commander) { commander.description('Stores registry username and email.'); } function run(_x5, _x6, _x7, _x8, _x9) { return _run.apply(this, arguments); } function _run() { _run = (0, _asyncToGenerator2()["default"])( /*#__PURE__*/_regenerator()["default"].mark(function _callee4(config, reporter, commander, flags, args) { return _regenerator()["default"].wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return getCredentials(config, reporter); case 2: case "end": return _context4.stop(); } }, _callee4); })); return _run.apply(this, arguments); } //# sourceMappingURL=login.js.map