UNPKG

verdaccio

Version:

A lightweight private npm proxy registry

172 lines (134 loc) 21.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _lodash = _interopRequireDefault(require("lodash")); var _utils = require("../../../lib/utils"); var _middleware = require("../../middleware"); var _constants = require("../../../lib/constants"); var _user = require("../../../utils/user"); var _logger = require("../../../lib/logger"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } const getOrder = (order = 'asc') => { return order === 'asc'; }; function addPackageWebApi(route, storage, auth, config) { const can = (0, _middleware.allow)(auth); const checkAllow = (name, remoteUser) => new Promise((resolve, reject) => { try { auth.allow_access({ packageName: name }, remoteUser, (err, allowed) => { if (err) { resolve(false); } resolve(allowed); }); } catch (err) { reject(err); } }); // Get list of all visible package route.get('/packages', function (req, res, next) { storage.getLocalDatabase(async function (err, packages) { if (err) { throw err; } async function processPackages(packages = []) { const permissions = []; const packgesCopy = packages.slice(); for (const pkg of packgesCopy) { const pkgCopy = _objectSpread({}, pkg); pkgCopy.author = (0, _utils.formatAuthor)(pkg.author); try { if (await checkAllow(pkg.name, req.remote_user)) { if (config.web) { pkgCopy.author.avatar = (0, _user.generateGravatarUrl)(pkgCopy.author.email, config.web.gravatar); } if (!_lodash.default.isNil(pkgCopy.dist) && !_lodash.default.isNull(pkgCopy.dist.tarball)) { pkgCopy.dist.tarball = (0, _utils.getLocalRegistryTarballUri)(pkgCopy.dist.tarball, pkg.name, req, config.url_prefix); } permissions.push(pkgCopy); } } catch (err) { _logger.logger.logger.error({ name: pkg.name, error: err }, 'permission process for @{name} has failed: @{error}'); throw err; } } return permissions; } const { web } = config; // @ts-ignore const order = config.web ? getOrder(web.sort_packages) : true; next((0, _utils.sortByName)(await processPackages(packages), order)); }); }); // Get package readme route.get('/package/readme/(@:scope/)?:package/:version?', can('access'), function (req, res, next) { const packageName = req.params.scope ? (0, _utils.addScope)(req.params.scope, req.params.package) : req.params.package; storage.getPackage({ name: packageName, uplinksLook: true, req, callback: function (err, info) { if (err) { return next(err); } res.set(_constants.HEADER_TYPE.CONTENT_TYPE, _constants.HEADERS.TEXT_PLAIN); next((0, _utils.parseReadme)(info.name, info.readme)); } }); }); route.get('/sidebar/(@:scope/)?:package', can('access'), function (req, res, next) { const packageName = req.params.scope ? (0, _utils.addScope)(req.params.scope, req.params.package) : req.params.package; storage.getPackage({ name: packageName, uplinksLook: true, keepUpLinkData: true, req, callback: function (err, info) { if (_lodash.default.isNil(err)) { const { v } = req.query; let sideBarInfo = _lodash.default.clone(info); sideBarInfo.versions = (0, _utils.convertDistRemoteToLocalTarballUrls)(info, req, config.url_prefix).versions; if ((0, _utils.isVersionValid)(info, v)) { // @ts-ignore sideBarInfo.latest = sideBarInfo.versions[v]; sideBarInfo.latest.author = (0, _utils.formatAuthor)(sideBarInfo.latest.author); } else { var _sideBarInfo; sideBarInfo.latest = sideBarInfo.versions[info[_constants.DIST_TAGS].latest]; if ((_sideBarInfo = sideBarInfo) !== null && _sideBarInfo !== void 0 && _sideBarInfo.latest) { sideBarInfo.latest.author = (0, _utils.formatAuthor)(sideBarInfo.latest.author); } else { res.status(_constants.HTTP_STATUS.NOT_FOUND); res.end(); return; } } sideBarInfo = (0, _utils.deleteProperties)(['readme', '_attachments', '_rev', 'name'], sideBarInfo); if (config.web) { sideBarInfo = (0, _utils.addGravatarSupport)(sideBarInfo, config.web.gravatar); } else { sideBarInfo = (0, _utils.addGravatarSupport)(sideBarInfo); } next(sideBarInfo); } else { res.status(_constants.HTTP_STATUS.NOT_FOUND); res.end(); } } }); }); } var _default = addPackageWebApi; exports.default = _default; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9hcGkvd2ViL2VuZHBvaW50L3BhY2thZ2UudHMiXSwibmFtZXMiOlsiZ2V0T3JkZXIiLCJvcmRlciIsImFkZFBhY2thZ2VXZWJBcGkiLCJyb3V0ZSIsInN0b3JhZ2UiLCJhdXRoIiwiY29uZmlnIiwiY2FuIiwiY2hlY2tBbGxvdyIsIm5hbWUiLCJyZW1vdGVVc2VyIiwiUHJvbWlzZSIsInJlc29sdmUiLCJyZWplY3QiLCJhbGxvd19hY2Nlc3MiLCJwYWNrYWdlTmFtZSIsImVyciIsImFsbG93ZWQiLCJnZXQiLCJyZXEiLCJyZXMiLCJuZXh0IiwiZ2V0TG9jYWxEYXRhYmFzZSIsInBhY2thZ2VzIiwicHJvY2Vzc1BhY2thZ2VzIiwicGVybWlzc2lvbnMiLCJwYWNrZ2VzQ29weSIsInNsaWNlIiwicGtnIiwicGtnQ29weSIsImF1dGhvciIsInJlbW90ZV91c2VyIiwid2ViIiwiYXZhdGFyIiwiZW1haWwiLCJncmF2YXRhciIsIl8iLCJpc05pbCIsImRpc3QiLCJpc051bGwiLCJ0YXJiYWxsIiwidXJsX3ByZWZpeCIsInB1c2giLCJsb2dnZXIiLCJlcnJvciIsInNvcnRfcGFja2FnZXMiLCJwYXJhbXMiLCJzY29wZSIsInBhY2thZ2UiLCJnZXRQYWNrYWdlIiwidXBsaW5rc0xvb2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0NvcHkuYXV0aG9yLmVtYWlsLFxuICAgICAgICAgICAgICAgICAgICBjb25maWcud2ViLmdyYXZhdGFyXG4gICAgICAgICAgICAgICAgICApO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBpZiAoIV8uaXNOaWwocGtnQ29weS5kaXN0KSAmJiAhXy5pc051bGwocGtnQ29weS5kaXN0LnRhcmJhbGwpKSB7XG4gICAgICAgICAgICAgICAgICBwa2dDb3B5LmRpc3QudGFyYmFsbCA9IGdldExvY2FsUmVnaXN0cnlUYXJiYWxsVXJpKFxuICAgICAgICAgICAgICAgICAgICBwa2dDb3B5LmRpc3QudGFyYmFsbCxcbiAgICAgICAgICAgICAgICAgICAgcGtnLm5hbWUsXG4gICAgICAgICAgICAgICAgICAgIHJlcSxcbiAgICAgICAgICAgICAgICAgICAgY29uZmlnLnVybF9wcmVmaXhcbiAgICAgICAgICAgICAgICAgICk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHBlcm1pc3Npb25zLnB1c2gocGtnQ29weSk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gY2F0Y2ggKGVycikge1xuICAgICAgICAgICAgICBsb2dnZXIubG9nZ2VyLmVycm9yKFxuICAgICAgICAgICAgICAgIHsgbmFtZTogcGtnLm5hbWUsIGVycm9yOiBlcnIgfSxcbiAgICAgICAgICAgICAgICAncGVybWlzc2lvbiBwcm9jZXNzIGZvciBAe25hbWV9IGhhcyBmYWlsZWQ6IEB7ZXJyb3J9J1xuICAgICAgICAgICAgICApO1xuICAgICAgICAgICAgICB0aHJvdyBlcnI7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgcmV0dXJuIHBlcm1pc3Npb25zO1xuICAgICAgICB9XG5cbiAgICAgICAgY29uc3QgeyB3ZWIgfSA9IGNvbmZpZztcbiAgICAgICAgLy8gQHRzLWlnbm9yZVxuICAgICAgICBjb25zdCBvcmRlcjogYm9vbGVhbi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iAoaXNWZXJzaW9uVmFsaWQoaW5mbywgdikpIHtcbiAgICAgICAgICAgICAgLy8gQHRzLWlnbm9yZVxuICAgICAgICAgICAgICBzaWRlQmFySW5mby5sYXRlc3QgPSBzaWRlQmFySW5mby52ZXJzaW9uc1t2XTtcbiAgICAgICAgICAgICAgc2lkZUJhckluZm8ubGF0ZXN0LmF1dGhvciA9IGZvcm1hdEF1dGhvcihzaWRlQmFySW5mby5sYXRlc3QuYXV0aG9yKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHNpZGVCYXJJbmZvLmxhdGVzdCA9IHNpZGVCYXJJbmZvLnZlcnNpb25zW2luZm9bRElTVF9UQUdTXS5sYXRlc3RdO1xuICAgICAgICAgICAgICBpZiAoc2lkZUJhckluZm8/LmxhdGVzdCkge1xuICAgICAgICAgICAgICAgIHNpZGVCYXJJbmZvLmxhdGVzdC5hdXRob3IgPSBmb3JtYXRBdXRob3Ioc2lkZUJhckluZm8ubGF0ZXN0LmF1dGhvcik7XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmVzLnN0YXR1cyhIVFRQX1NUQVRVUy5OT1RfRk9VTkQpO1xuICAgICAgICAgICAgICAgIHJlcy5lbmQoKTtcbiAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHNpZGVCYXJJbmZvID0gZGVsZXRlUHJvcGVydGllcyhbJ3JlYWRtZScsICdfYXR0YWNobWVudHMnLCAnX3JldicsICduYW1lJ10sIHNpZGVCYXJJbmZvKTtcbiAgICAgICAgICAgIGlmIChjb25maWcud2ViKSB7XG4gICAgICAgICAgICAgIHNpZGVCYXJJbmZvID0gYWRkR3JhdmF0YXJTdXBwb3J0KHNpZGVCYXJJbmZvLCBjb25maWcud2ViLmdyYXZhdGFyKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIHNpZGVCYXJJbmZvID0gYWRkR3JhdmF0YXJTdXBwb3J0KHNpZGVCYXJJbmZvKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIG5leHQoc2lkZUJhckluZm8pO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXMuc3RhdHVzKEhUVFBfU1RBVFVTLk5PVF9GT1VORCk7XG4gICAgICAgICAgICByZXMuZW5kKCk7XG4gICAgICAgICAgfVxuICAgICAgICB9XG4gICAgICB9KTtcbiAgICB9XG4gICk7XG59XG5cbmV4cG9ydCBkZWZhdWx0IGFkZFBhY2thZ2VXZWJBcGk7XG4iXX0=