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

@taghub/api

v1.8.0

Published

This is a JavaScript module wrapping the [TagHub API](https://gitlab.taghub.net/documentation/devdocs/wikis/home).

Downloads

39

Readme

TagHub API module

This is a JavaScript module wrapping the TagHub API.

It makes use of JavaScript modules and async/await and is designed to work both on the web and with NodeJS.

Requirements

Web: Tested with `create-react-app` (webpack).   
NodeJS: 13.5+ and "type": "module" in package.json.

Install

npm install --save @taghub/api

Usage

import { login, getProjects } from '@taghub/api'

const credentials = await login('username', 'password')
const projects = await getProjects(credentials)

API

Common options

Most API calls take an options object as one of their parameters. Some of these options are common and are listed below.

param         type      descrption
--
init          boolean   If `true` the options will be stored in module state
consumerKey   string    Passed as the `TAGHUB_CONSUMER_KEY` header for API calls (required)
accessKey     string    Passed as the `TAGHUB_ACCESS_KEY` header for API calls (required)
endpoint      string    Used as base URL (optional) - overwrite any attempt at detecting the environemnt

.init(options)

Init will store options in the module state for future calls. Useful so you only have to pass the consumerKey once.

Example:

import { init } from '@taghub/api'

init({ consumerKey: '123' })

.login(username, password, options)

Logs the user into TagHub. Returns an object with an accessKey parameter that can be used for access to other APIs. Passing init: true in options will also store accessKey in module state.

Example:

import { login } from '@taghub/api'

await login('username', 'password', { consumerKey: '123', init: true })

.loginSSO(username, ssoKey, updateUserOptions, options)

Logs the user into TagHub from a SSO key which is linked to a Company. Returns an object with an accessKey parameter that can be used for access to other APIs. Passing init: true in options will also store accessKey in module state.

updateUserOptions contains options to update the user:

param type descrption

createIfNotExists: boolean If true it will create a user if it does not exist. firstName: string It will update the user's first name on every login. lastName: string It will update the user's last name on every login. roles: array It will update the project-role relationship on every login. Of shape: [{ project, role }].

Example:

import { login } from '@taghub/api'

await loginSSO('username', 'ssoKey', {}, { consumerKey: '123', init: true })

Updating user properties:

await loginSSO('username', 'ssoKey', {
  createIfNotExists: true,
  firstName: 'Bob',
  lastName: 'Sponge',
  roles: [
    { project: 'Norway', role: 'Spectator' },
    { project: 'USA', role: 'Administrator' }
  ]
}, { consumerKey: '123', init: true })

.getProjects(options)

Get a list of the projects the current user has access to.

Example:

import { login, getProjects } from '@taghub/api'

await login('username', 'password', { consumerKey: '123', init: true })
const projects = await getProjects()

.getItems(project_uuid, options)

Get a list of items for the passed project.

Options:

param         type      descrption
--
query         object    Object containing query params to pass to items call (optional)

Example:

import { login, getItems } from '@taghub/api'

await login('username', 'password', { consumerKey: '123', init: true })
const items = await getItems('project_uuid')
const equipment = await getItems('project_uuid', { query: { filter9: 1 }})

.getItem(project_uuid, epcString, options)

Get an item of a project.

Example:

import { login, getItem } from '@taghub/api'

await login('username', 'password', { consumerKey: '123', init: true })
const item = await getItem('project_uuid', 'epcString')

.getEvents(project_uuid, epcString, serviceId, options)

Get a list of events of a Service or all Services if serviceId is not passed.

Options:

param             type      descrption
--
query             object    Object containing query params to pass to items call (optional)
query.startFrom   number    Index from where to start fetching events (latest events come first).
query.maxHits     number    Max number of events to fetch

Example:

import { login, getEvents } from '@taghub/api'

await login('username', 'password', { consumerKey: '123', init: true })
const items = await getEvents('project_uuid', 'epcString', 'serviceId')
const equipment = await getEvents('project_uuid', 'epcString', 'serviceId', { query: { startFrom: 0, maxHits: 5 }})

.getProjectMeta(project_uuid, options)

Get the metadata of a project. Information about enabled services etc.

Example:

import { login, getProjectMeta } from '@taghub/api'

await login('username', 'password', { consumerKey: '123', init: true })
const meta = await getProjectMeta('project_uuid')

.getProfiles(project_uuid, options)

Get a list of profiles of a project.

Options:

param         type      descrption
--
query         object    Object containing query params to pass to items call (optional)

Example:

import { login, getProfiles } from '@taghub/api'

await login('username', 'password', { consumerKey: '123', init: true })
const items = await getProfiles('project_uuid')

.getItemTypes(project_uuid, options)

Get a list of item types related to a project.

Example:

import { getItemTypes } from '@taghub/api'

const items = await getItemTypes('project_uuid')

enjoy.