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

@app-masters/hubstaff-node-client

v2.0.4

Published

Simple library to access hubstaff API.

Downloads

81

Readme

Hubstaff Node Client

Simple library to access hubstaff API V2, developed by App Masters.

References: Hubstaff developer portal

📦 Installation

yarn add @app-masters/hubstaff-node-client

or

npm i @app-masters/hubstaff-node-client

🔨 How to use

  • Before starting to use the methods, we need to send some parameters to the Hubstaff instance.

  • The first parameter is an object containing the accessToken and the refreshToken. (Click here to see how to get them).

  • The second is a callback function that will be called every time the access token is refreshed.

    Tip: this function receives two parameters, accessToken and the refreshToken, you may consider saving these tokens into some database.

import Hubstaff from '@app-masters/hubstaff-node-client';

const refreshTokenCallback = (accessToken, refreshToken) => {
  console.log("A new token has received");
  console.log("access token", accessToken);
  console.log("refresh token", refreshToken);
};

const hubstaff = new Hubstaff({ accessToken: "your-access-token", refreshToken: "your-refresh-token" }, refreshTokenCallback);
//...
  • By now you can access the methods.

Simple exemple:

//...

// Get organizations
const orgs = hubstaff.getOrganizations();
console.log(orgs); 
/* Output: 
[
  {
    id: 55426,
    name: 'App Masters',
    status: 'active',
    created_at: '2017-06-05T12:21:08.432670Z',
    updated_at: '2020-12-07T17:00:04.712558Z',
    metadata: {},
    invite_url: 'https://app.hubstaff.com/organizations/invite/exfImdk6Skl213g'
  }
]
*/

// Get projects
const projects = hubstaff.getProjects(orgs[0].id);
console.log(projects); // Output: Project[]

// Get tasks
const tasks = hubstaff.getTasks(orgs[0].id);
console.log(tasks); // Output: Task[]

// Get activities
const activities = hubstaff.getActivities(orgs[0].id);
console.log(activities); // Output: Activity[]

⚙ How to get the access and refresh token:

  • Access https://developer.hubstaff.com/personal_access_tokens
  • Create your own access token and copy the refresh_token that will be generated.
import Hubstaff from '@app-masters/hubstaff-node-client';

const tokenObj = Hubstaff.getAccessToken('your-refresh-token');
console.log(tokenObj.accessToken); // Output: 'your-access-token'
console.log(tokenObj.refreshToken); // Output: 'your-refresh-token'

✅ How to test

  • Copy the variables.examples.ts file and create a new file variables.ts inside folder __tests__.
  • In that new file assign your access_token to the accessToken variable that is already declared.
accessToken: 'your-access-token',
refreshToken: '', // you can leave it blank (only for test)
  • Now you can run the tests with this command on terminal:
yarn run test
# or 
npm run test

⚠ Caveats

  • This client makes the pagination by itself, so if the method has more than 500 records the method will make the pagination and return all of them.

🤝 How to contribute

We focused just on some endpoints we need to use, but is really simple to add any other.

Feel free to contribute, start by opening a issue please.