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

@qiwi/nexus-helper

v2.3.0

Published

API for managing Nexus NPM repository contents

Downloads

21

Readme

@qiwi/nexus-helper

Helper for managing Nexus NPM repository contents

Installation

yarn add @qiwi/nexus-helper

or

npm i @qiwi/nexus-helper

Usage

You should create and pass ContentsApi, SearchApi from @qiwi/nexus-client and AxiosInstance from axios to NexusContentsHelper's constructor.

import { ComponentsApi, SearchApi } from '@qiwi/nexus-client'
import { NexusComponentsHelper } from '@qiwi/nexus-helper'
import axios from 'axios'

const basePath = 'http://localhost/service/rest'
const componentsApi = new ComponentsApi({ basePath })
const searchApi = new SearchApi({ basePath })
const rateLimitOpts = {
  period: 1000,
  count: 2,
}
const helper = new NexusComponentsHelper(searchApi, componentsApi, axios, rateLimitOpts)

rateLimitOpts is optional, it represents rate limit of delete method of Nexus Components API

Get package components

const components = await helper.getPackageComponents({
  repository: 'npm',
  group: 'qiwi',
  name: 'substrate'
})
/*
{
    "items": [
        {
            "id": "12345678901234567890123456789012345678901234567890123456",
            "repository": "npm-proxy",
            "format": "npm",
            "group": "qiwi",
            "name": "substrate",
            "version": "1.18.35",
            "assets": [
                 {
                    "downloadUrl": "https://some.url/repository/npm/@qiwi/substrate/-/substrate-1.18.35.tgz",
                    "filePath": "@qiwi/substrate/-/substrate-1.18.35.tgz",
                    "id": "qwertyuiopasdfghjklzxcvbnmqwertyuioasdfghjklzxcvzxcvbnmb",
                    "repository": "npm-proxy",
                    "format": "npm",
                    "checksum": {
                        "sha1": "abcdef1234567890abcdef1234567890abcdef13"
                    }
                },
                ...
            ]
        },
        ...,
        {
            "id": "12345678901234567890123456789012345678901234567890123457",
            "repository": "npm-proxy",
            "format": "npm",
            "group": "qiwi",
            "name": "substrate",
            "version": "1.18.33",
            "assets": [
                {
                    "downloadUrl": "https://some.url/repository/npm/@qiwi/substrate/-/substrate-1.18.33.tgz",
                    "filePath": "@qiwi/substrate/-/substrate-1.18.33.tgz",
                    "id": "qwertyuiopasdfghjklzxcvbnmqwertyuioasdfghjklzxcvzxcvbnma",
                    "repository": "npm-proxy",
                    "format": "npm",
                    "checksum": {
                        "sha1": "abcdef1234567890abcdef1234567890abcdef12"
                    }
                },
                ...
            ]
        }
    ],
    "continuationToken": "token"
}
*/

continuationToken is used for pagination, pass it as the second argument to get more components:

const { items, continuationToken } = await helper.getPackageComponents({
  repository: 'npm',
  group: 'qiwi',
  name: 'substrate'
})
const components = [...items]
let token = continuationToken
while (token) {
  const data = await helper.getPackageComponents(
    {
        repository: 'npm',
        group: 'qiwi',
        name: 'substrate'
    },
    token
  )
  components.push(...data.items)
  token = data.continuationToken
}

Delete components by their ids

Nexus identifies components by their ids, see Nexus Components API docs

const componentsToBeDeleted = NexusComponentsHelper.filterComponentsByRange(
    components,
    '>1.0.0'
)
await helper.deletePackagesByIds(componentsToBeDeleted.map(item => item.id))

If error occurs, deleting will be stopped. If you want to delete all components despite on errors, use deletePackagesByIdsSettled.

await helper.deletePackagesByIdsSettled(componentsToBeDeleted.map(item => item.id))

Get package assets info

This method uses the same pagination as getPackageComponents

const { items, continuationToken } = await helper.getPackageAssets({
  repository: 'npm',
  group: 'qiwi',
  name: 'substrate'
})
/*
{
    "items": [
        {
            "downloadUrl": "https://some.url.com/repository/npm/@qiwi/substrate/-/substrate-0.11.0.tgz",
            "filePath": "@qiwi/substrate/-/substrate-0.11.0.tgz",
            "id": "asdfghjklqwertyuiozxcvbnmasdfghjklqwertyuiozxcvbnmasdfghjasd",
            "repository": "npm",
            "format": "npm",
            "checksum": {
                "sha1": "1234567890123456789012345678901234567890"
            }
        },
        ...
     ],
     "continuationToken": "token"
 */

Download package asset

Saves the asset to the path specified as the third argument

const data = await helper.downloadPackageAsset(
  'https://some.url.com/repository/npm/@qiwi/substrate/-/substrate-0.11.0.tgz',
  '@qiwi/substrate/-/substrate-0.11.0.tgz',
  'pathToSaveTarball'
)
/*
{
  name: '@qiwi/substrate',
  version: '0.11.0',
  filePath: 'pathToSaveTarball/@qiwi%2Fsubstrate%2F-%2Fsubstrate-0.11.0.tgz'
}
 */

Download package assets

The same as a getPackageAssets, but with saving tarballs to given path

const data = await helper.downloadPackageAssets(
  {
    repository: 'npm',
    group: 'qiwi', // optional
    name: 'substrate', // optional
    range: '<1.0.0' // optional
  },
  'pathToSaveTarball'
)
/*
{
  "items": [
    {
        "status": "fulfilled",
        "value": {
            "name": "@qiwi/substrate",
            "version": "0.11.0",
            "filePath": "pathToSaveTarball/@qiwi%2Fsubstrate%2F-%2Fsubstrate-0.11.0.tgz"
        }
    },
    {
        "status": "fulfilled",
        "value": {
            "name": "@qiwi/substrate",
            "version": "0.12.0",
            "filePath": "pathToSaveTarball/@qiwi%2Fsubstrate%2F-%2Fsubstrate-0.12.0.tgz"
        }
    },
    {
        "status": "rejected",
        "reason": {
            "message": "Not Found",
        }
    },
    ...
  ],
  "continuationToken": "token"
}
 */

Tarballs are saved to value.path