npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

artifactory-rest-api

v0.0.6

Published

A module for interacting with Artifactory API

Downloads

2

Readme

Artifactory REST API

The ArtifactoryApi class provides you with a friendly way of interacting with the Artifactory REST API. Supports both v3 and v4 APIs where possible.

Authentication

You need to provide basic http credentials when creating a new instance. Just provide username:password in base 64.

  • Hint: you can quickly obtain the base64 of any string by opening a Chrome browser and typing this in the developer console:

    btoa('user:password') //prints: "dXNlcjpwYXNzd29yZA=="

    Usage example:

    var artifactory = new ArtifactoryApi('https:<myServerURL>', "dXNlcjpwYXNzd29yZA==");

Actions

All actions return a Q Promise.

getFileInfo(repoKey, remoteFilePath)

Provides all the info related to a file in a json object. You need to provide the repoKey and the path to the file.

API: FileInfo

Usage example:

var artifactory = new ArtifactoryApi('http://localhost:8080', "dXNlcjpwYXNzd29yZA==");
artifactory.getFileInfo('libs-release-local','/org/acme/lib/ver/lib-ver.pom').then(function(fileInfoJson){
  console.log(JSON.stringify(fileInfoJson));
});

That would print to console something like this:

{
  "uri": "http://localhost:8080/artifactory/api/storage/libs-release-local/org/acme/lib/ver/lib-ver.pom",
  "downloadUri": "http://localhost:8080/artifactory/libs-release-local/org/acme/lib/ver/lib-ver.pom",
  "repo": "libs-release-local",
  "path": "/org/acme/lib/ver/lib-ver.pom",
  "remoteUrl": "http://some-remote-repo/mvn/org/acme/lib/ver/lib-ver.pom",
  "created": ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ),
  "createdBy": "userY",
  "lastModified": ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ),
  "modifiedBy": "userX",
  "lastUpdated": ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ),
  "size": "1024", //bytes
  "mimeType": "application/pom+xml",
  "checksums": {
    "md5" : string,
    "sha1" : string
  },
  "originalChecksums":{
    "md5" : string,
    "sha1" : string
  }
}

All this info will be available in the fileInfoJson object that is returned as part of the promise resolution.

uploadFile(repoKey, remoteFilePath, localfilePath, forceUpload)

Uploads a file to artifactory. All you need to provide is the repoKey, the remote path where you want to upload the file and the local path of the file you want to upload. If the file already exists in the server it will fail unless you provide the forceUpload flag with a true value. In that case, it will overwite the file in the server.

API: DeployArtifact

Usage example:

var artifactory = new ArtifactoryApi('http://localhost:8080', "dXNlcjpwYXNzd29yZA==");
artifactory.uploadFile('libs-release-local', '/my/jar/1.0/jar-1.0.jar', '/Users/user/artifacts/jar-1.0.jar').then(function (uploadInfo) {
  console.log('UPLOAD INFO IS: ' + JSON.stringify(uploadInfo));
}).fail(function (err) {
  console.log('ERROR: ' + err);
});

This would print to console the creation info:

{
  "uri": "http://localhost:8080/artifactory/libs-release-local/my/jar/1.0/jar-1.0.jar",
  "downloadUri": "http://localhost:8080/artifactory/libs-release-local/my/jar/1.0/jar-1.0.jar",
  "repo": "libs-release-local",
  "path": "/my/jar/1.0/jar-1.0.jar",
  "created": ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ),
  "createdBy": "userY",
  "size": "1024", //bytes
  "mimeType": "application/java-archive",
  "checksums":
  {
    "md5" : string,
    "sha1" : string
  },
  "originalChecksums":{
    "md5" : string,
    "sha1" : string
  }
}

All this info will be available in the uploadInfo object that is returned as part of the promise resolution.

downloadFile(repoKey, remoteFilePath, destinationFile, checkChecksum)

Downloads a file from a given repository/path into a specific file. You need to provide the repoKey, the remote path where the file is located and a destination file. The folder that will contain the destination file must exist! Additionally you can indicate whether you want to perform a checksum verification as part of the download or not.

API: RetrieveArtifact

Usage example:

var artifactory = new ArtifactoryApi('http://localhost:8080', "dXNlcjpwYXNzd29yZA==");
artifactory.downloadFile('libs-release-local', '/my/jar/1.0/jar-1.0.jar', '/Users/user/Downloads/myJar.jar', true).then(function (result) {
  console.log(result);
}).fail(function (err) {
  console.log('ERROR: ' + err);
});

The result object returned as part of the promise resolution is just a string indicating the final result of the operation.

fileExists(repoKey, remoteFilePath)

Verifies if the file exists in the server. You need to provide the repoKey and the path to the file in the server.

API: RetrieveArtifact but only asking for the HEAD instead of doing a GET.

Usage example:

var artifactory = new ArtifactoryApi('http://localhost:8080', "dXNlcjpwYXNzd29yZA==");
artifactory.fileExists('libs-release-local', '/my/jar/1.0/jar-1.0.jar').then(function (exists) {
  if(exists){
    console.log('YES, file exists!');
  }
  console.log('NO, it\'s not there');
}).fail(function (err) {
  console.log('ERROR: ' + err);
});

deleteItem(repoKey, remoteFilePath)

Deletes the file or folder from the server. You need to provide the repoKey and the path to the file on the server.

API: DeleteItem

Usage example:

var artifactory = new ArtifactoryApi('http://localhost:8080', "dXNlcjpwYXNzd29yZA==");
artifactory.deleteFile('libs-release-local', '/my/jar/1.0/jar-1.0.jar').then(function () {
  // success
}).fail(function (err) {
  console.log('ERROR: ' + err);
});