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

myhours-api-wrapper

v0.1.1

Published

Unofficial Wrapper for the MyHours API

Downloads

2

Readme

MyHours API Wrapper

This is an unofficial wrapper for the MyHours API, which provides convenience methods for indirectly interacting with the documented v1.1 API (api2). This includes getting/editing/setting/deleting of projects, tasks, and time logs, team members, tags, etc.

Full Disclosure: This project is not affiliated with MyHours in any way. Use it at your own risk.

This SDK effectively mirrors what's available in the official MyHours API, providing convenience methods for each endpoint. For reference, please refer to the actual MyHours API v1.1 to see what kinds of actions are available.

Installation

npm install myhours-api-wrapper

Usage

Examples are provided in the examples directory, which the following examples are based on.

General usage is as follows:

import { MyHoursAPIWrapper } from 'myhours-api-wrapper';

const mhWrapper = new MyHoursAPIWrapper();

// login
const session = await mhWrapper.login('my-username', 'my-password');
if (!session) {
    throw new Error('Login failed');
} else {
    console.log('Logged in');
    // save to session to be used later...
}

// you can also set a previous session, rather than logging in repeatedly
mhWrapper.setSession(session);


// get active project & team members
const projects = await mhWrapper.getActiveProjects();
const teamMates = await mhWrapper.getAllTeamMembers();


// retrieve dashboard reports in a given time range
const dateFrom = new Date();
dateFrom.setDate(dateFrom.getDate() - 1);
const dashboardReports = await mhWrapper.getDashboardReports(dateFrom, new Date(), ReportGroup.GroupByClientProjects);
console.log('Dashboard reports:', dashboardReports);


// retrieve logs in a given time range
// get logs from the 1st to the 31st of the current month
const dateFrom = new Date();
dateFrom.setDate(1);

const dateTo = new Date();
dateTo.setDate(31);

const logs = await mhWrapper.getTimeLogs(dateFrom, dateTo);
console.log('Logs:', logs);

For restoring a session, you can use the setSession method. This allows you to avoid repeatedly logging in:

/**
 * An example of using an auth token to login instead
 */

import { MyHoursAPIWrapper, Session } from 'myhours-api-wrapper';

// create an instance of the MyHours API
const mhWrapper = new MyHoursAPIWrapper();

// load some session data, this could be from a file or a database
const session: Session = {
    accessToken: 'my-auth-token',
    expiresIn: 1800,
    refreshToken: 'my-refresh-token',
    expiresDate: new Date() // the exact time & date when the access token expires, this is something the SDK adds for convenience
};

// login using an auth token
mhWrapper.setSession(session);

// No need to login explicitly now that we have restored the session
// Logging in again, with a valid unexpired session, will just skip the login process

// do something like getting all active projects
const projects = await mhWrapper.getActiveProjects();
console.log('Projects:', projects);

Sessions can be refreshed as well:

// later on, refresh your token & session
const freshSession = await mhWrapper.refresh();

// this will give you a new session with a new access token, but it's your responsibility to store it
// the SDK is effectively stateless, so you need to manage the session yourself

// store the new session somewhere
// you can serialize it to JSON and store it where you like, taking proper security precautions
JSON.stringify(freshSession);

Some other things you can do as well:

// add tasks to projects
const task = await mhWrapper.addTaskToProject('my-project-id', 'list-name', 'task-name', 'task-description', 0, 0, 'xyz');

// add time logs
const timeLog = await mhWrapper.addTimeLog('my-project-id', 'my-task-id', 'Working on a new feature', new Date(), new Date(), new Date(), true, 0);

// get all tags
const tags = await mhWrapper.getAllTags();

Contributing

This SDK is a work in progress, and contributions are welcome! If you find a bug, or want to add a feature, please open an issue or a pull request.

Most of the API is covered here (based on the MyHours postman documentation), but your results may vary if the MyHours API changes in the future. If you find any issues, please report them!