verdaccio
Version:
A lightweight private npm proxy registry
62 lines (50 loc) • 5.93 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _search = _interopRequireDefault(require("../../../lib/search"));
var _constants = require("../../../lib/constants");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @prettier
* @flow
*/
function addSearchWebApi(route, storage, auth) {
// Search package
route.get('/search/:anything', function (req, res, next) {
const results = _search.default.query(req.params.anything); // FUTURE: figure out here the correct type
const packages = [];
const getPackageInfo = function (i) {
storage.getPackage({
name: results[i].ref,
uplinksLook: false,
callback: (err, entry) => {
if (!err && entry) {
auth.allow_access({
packageName: entry.name
}, req.remote_user, function (err, allowed) {
if (err || !allowed) {
return;
}
packages.push(entry.versions[entry[_constants.DIST_TAGS].latest]);
});
}
if (i >= results.length - 1) {
next(packages);
} else {
getPackageInfo(i + 1);
}
}
});
};
if (results.length) {
getPackageInfo(0);
} else {
next([]);
}
});
}
var _default = addSearchWebApi;
exports.default = _default;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9hcGkvd2ViL2VuZHBvaW50L3NlYXJjaC50cyJdLCJuYW1lcyI6WyJhZGRTZWFyY2hXZWJBcGkiLCJyb3V0ZSIsInN0b3JhZ2UiLCJhdXRoIiwiZ2V0IiwicmVxIiwicmVzIiwibmV4dCIsInJlc3VsdHMiLCJTZWFyY2giLCJxdWVyeSIsInBhcmFtcyIsImFueXRoaW5nIiwicGFja2FnZXMiLCJnZXRQYWNrYWdlSW5mbyIsImkiLCJnZXRQYWNrYWdlIiwibmFtZSIsInJlZiIsInVwbGlua3NMb29rIiwiY2FsbGJhY2siLCJlcnIiLCJlbnRyeSIsImFsbG93X2FjY2VzcyIsInBhY2thZ2VOYW1lIiwicmVtb3RlX3VzZXIiLCJhbGxvd2VkIiwicHVzaCIsInZlcnNpb25zIiwiRElTVF9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gICAgICAgICAgIGlmIChlcnIgfHwgIWFsbG93ZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICBwYWNrYWdlcy5wdXNoKGVudHJ5LnZlcnNpb25zW2VudHJ5W0RJU1RfVEFHU10ubGF0ZXN0XSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICApO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoaSA+PSByZXN1bHRzLmxlbmd0aCAtIDEpIHtcbiAgICAgICAgICAgICAgbmV4dChwYWNrYWdlcyk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBnZXRQYWNrYWdlSW5mbyhpICsgMSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgIH07XG5cbiAgICAgIGlmIChyZXN1bHRzLmxlbmd0aCkge1xuICAgICAgICBnZXRQYWNrYWdlSW5mbygwKTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIG5leHQoW10pO1xuICAgICAgfVxuICAgIH1cbiAgKTtcbn1cblxuZXhwb3J0IGRlZmF1bHQgYWRkU2VhcmNoV2ViQXBpO1xuIl19
;