Unable to get NPM artifact details

I’m developing a plugin for the nexus repository manager. In this case, I need to get the artifact name and the version request from various build tools on Maven, NPM, and Nuget repositories. I was able to get the name and version details for Maven and Nuget from the context object as below. But I’m unable to get name and version for NPM. Could you please guide me on how to get version details for NPM artifacts?

Nexus Plugin class

 public class MyRequestHandler extends ConditionalRequestHandler { 
public Response handle(@Nonnull Context context) throws Exception {
     //Get artifact version But Not working for NPM artifacts
    State state = (State)context.getAttributes().require(State.class);
    String packageName = (String)state.getTokens().get("packageName");
    String version = (String)state.getTokens().get("packageVersion");

I request artifact from NodeJs Project using “npm install” . Below is the package.json file

"name": "nexus-test-nodejs-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
  "i18n": "0.9.1",
  "winston-console-formatter": "0.1.0",
  "logback": "1.0.16",
  "parse-server": "4.4.0",
  "harp": "0.33.0",
  "react-native-webview": "10.10.2"

It isn’t part of the context for npm, you’d have to query the asset & component database tables based on the path.

My use case is to validate the artifact before caching it in the nexus repository. If validation failed, it will not allow to download and cache in the nexus repository. In this case, there will not be any data of the artifact in the component/artifact database. Also, if we have multiple versions of the artifact, how do we determine the requested version from the path? Is there any similar example that I can refer to?

You could also read the package root metadata and look at the tarball paths for versions.

In case you aren’t aware we also sell a product that does this based on user defined policies like security, license, etc. Nexus Firewall - Application Security | Sonatype