#3545·verdaccio

v1 search does not work with pagination

Author: dre2901Created Dec 28, 2022Updated Apr 19, 2026
Labelsstatus: investigating

Hi!

Firstly, thanks for your work on this project!

Today I used patch-package to patch [email protected] for the project I'm working on.

The problem is in 5.x/src/api/endpoint/api/v1/search.ts (I checked and the same logical issue exists also in master 6.x branch master/packages/api/src/v1/search.ts).

Basically, search returns always total equal or less than size query param.

For example, direct search of @babel packages on npmjs (https://registry.npmjs.org/-/v1/search?text=@babel&size=20&from=0) returns total of 192 and I can do pagination by using size and from params. Same call via verdaccio returns always total of 20 (equal to size) and pagination is not possible at all.

Here is the diff that solved my problem:

diff
diff --git a/node_modules/verdaccio/build/api/endpoint/api/v1/search.js b/node_modules/verdaccio/build/api/endpoint/api/v1/search.js
index 27b03a0..8b1939e 100644
--- a/node_modules/verdaccio/build/api/endpoint/api/v1/search.js
+++ b/node_modules/verdaccio/build/api/endpoint/api/v1/search.js
@@ -106,11 +106,12 @@ async function sendResponse(resultBuf, resultStream, auth, req, from, size) {
   const checkAccessPromises = await Promise.all(removeDuplicates(resultsCollection).map(pkgItem => {
     return checkAccess(pkgItem, auth, req.remote_user);
   }));
-  const final = checkAccessPromises.filter(i => !_lodash.default.isNull(i)).slice(from, size);
+  const totalAllowed = checkAccessPromises.filter(i => !_lodash.default.isNull(i));
+  const final = totalAllowed.slice(from, from + size);
   _logger.logger.debug(`search results ${final === null || final === void 0 ? void 0 : final.length}`);
   const response = {
     objects: final,
-    total: final.length,
+    total: totalAllowed.length,
     time: new Date().toUTCString()
   };
   _logger.logger.debug(`total response ${final.length}`);

This issue body was partially generated by patch-package.