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

poplarml-cli

v0.0.0

Published

PoplarML CLI Tool

Downloads

5

Readme

Poplar Cli

Poplar Cli is a command line interface for PoplarML. It is a platform for deploying PoplarML models.

Getting Started

run npm install to install all dependencies.

run npm run build to build the project.

run npm link to link the project to your global node_modules.

run poplar to run the cli.

Usage

poplar

Run the cli.

Example: poplar deploy -i A10 -m Whisper

Deploy a PoplarML model to the A10. The model id is Whisper. This is a mock command which needs to be replaced with the actual command.


Login Class Docs

Config

  static description = 'Log in to PoplarML';

  static aliases: string[] = ['login'];

  static examples: string[] = [`$ poplar login`]

Functions

baseApiEndpoint()

  • This function help provide the appropriate prefix api link when connecting to the backend.
  • This is a public function and can be used where login class is called.
  public baseApiEndpoint(): string {
    const env = process.env.NODE_ENV
    if (env === 'production') {
      return 'prod'
    }

    return 'dev.'
  }

initConfigDir()

  • This function checks if config files exist and will initialize the file if it does not exist.
  • The config file will be used to store user credential tokens.
  private async initConfigDir(): Promise<void> {
    const configDir = this.config.configDir
    const configFile = path.join(configDir, 'config.json')
    try {
      await fs.ensureDir(configDir)
    } catch {
      await fs.mkdirp(configDir)
    }

    try {
      await fs.access(configFile)
    } catch {
      const initialConfig = {
        // eslint-disable-next-line camelcase
        access_token: '',
        // eslint-disable-next-line camelcase
        refresh_token: '',
      }
      await fs.writeJson(configFile, initialConfig)
    }
  }

login()

  • This function handles the login logic.
  • User credentials are sent to the backend to authenticate. If the user is authenticated, the tokens are stored locally in the user's machine in the config file.
   private async login(email: string, password: string): Promise<{accessToken: string, refreshToken: string}> {
    const baseApiEndpoint = this.baseApiEndpoint()
    const loginAPI =
      baseApiEndpoint === 'prod' ?
        'https://auth.api.poplarml.com/sign-in' :
        `https://${baseApiEndpoint}auth.api.poplarml.com/sign-in`
    const data = (await axios.post(loginAPI, {
      email: email,
      password: password,
    })).data
    if (data.status >= 400) {
      this.error('Invalid Credentials')
    }

    const tokens = {
      accessToken: data.AuthenticationResult.AccessToken,
      refreshToken: data.AuthenticationResult.RefreshToken,
    }

    return tokens
  }

storeTokens()

  • Helper function that stores tokens locally in the user's machine.
  • The token is stored in the config file
  private async storeTokens({accessToken, refreshToken}:{accessToken: string, refreshToken: string}): Promise<void> {
    const configDir = this.config.configDir
    const configFile = path.join(configDir, 'config.json')
    const userConfig = await fs.readJSON(configFile)
    // eslint-disable-next-line camelcase
    userConfig.access_token = accessToken
    // eslint-disable-next-line camelcase
    userConfig.refresh_token = refreshToken
    await fs.writeJSON(configFile, userConfig)
  }

checkTokens()

  • This function checks if tokens are stored in the user's config file.
  • Used to check if stored tokens are valid and/or to re-authenticate the user.
  • This is a public function and can be used where login class is called.
  public async checkTokens(): Promise<boolean> {
    try {
      const configDir = this.config.configDir
      const configFile = path.join(configDir, 'config.json')
      const userConfig = await fs.readJSON(configFile)
      if (!userConfig) {
        return false
      }

      if (userConfig.refresh_token) {
        await this.getAccessToken(userConfig.refresh_token)
        return true
      }

      return false
    } catch (error:any)  {
      if (error.code === 'ENOENT') {
        this.error('Config directory does not exist. Please run `poplar init` first.')
      } else if (error instanceof SyntaxError) {
        console.error(error)
        this.error('Config file not a valid JSON')
      } else {
        console.error(error)
        this.error(error)
      }
    }
  }

getAccessToken()

  • Helper function that verifies uses the refresh token to refresh access token.
  • Can also be used to verify tokens.
  public async checkTokens(): Promise<boolean> {
    try {
      const configDir = this.config.configDir
      const configFile = path.join(configDir, 'config.json')
      const userConfig = await fs.readJSON(configFile)
      if (!userConfig) {
        return false
      }

      if (userConfig.refresh_token) {
        await this.getAccessToken(userConfig.refresh_token)
        return true
      }

      return false
    } catch (error:any)  {
      if (error.code === 'ENOENT') {
        this.error('Config directory does not exist. Please run `poplar init` first.')
      } else if (error instanceof SyntaxError) {
        console.error(error)
        this.error('Config file not a valid JSON')
      } else {
        console.error(error)
        this.error(error)
      }
    }
  }

Instructions to use public login functions

import {Command} from '@oclif/core'
import Login from 'path/to/login.ts'

export default class CommandNameHere extends Command{
    // Create login instance
  private login = new Login(this.argv, this.config)

  // Public functions now available
  this.login.checkToken() // return boolean  
  this.login.baseApiEndpoint() // return string ('prod', 'dev.')
}