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

shortcut-api

v4.1.3-alpha.1

Published

An API Wrapper for Shortcut, using an object oriented approach to interact with the Shortcut API

Downloads

116

Readme

Shortcut API Client

npm version codecov

Full Documentation

This is an object-oriented Node.js client for interacting with the Shortcut (formerly Clubhouse) REST API. It simplifies the process of making requests to the API by providing a set of easy-to-use classes and methods.

Features

  1. OOP Design: Provides classes for interacting with the Shortcut API, such as Client, Story, Iteration, Member, and Workflow.
  2. Stats: Provides additional stats on stories, such as the cycle time and lead time of individual stories.
  3. Type conversions: Automatically converts API responses to JavaScript objects (such as Dates and API resources).
  4. Caching: Caches API responses when member or workflow data is requested, reducing subsequent requests.

The structure of the client is designed to be intuitive and easy to use. Depending on your use case, it can help you reduce the amount of code you need to write in order to interact with the Shortcut API.

Example Usage

Navigating between related resources is simplified:

const client: Client = new Client()
const story: Story = await client.stories.get('story-id')
const epic: Epic = await story.epic
const owners: Member[] = await epic.owners
const team: Team = await story.team

// Now with that team, we can navigate easily to the team's members
const members: Member[] = await team.members

compared to the standard Shortcut Client:

const shortcut = new ShortcutClient();
const story = await shortcut.getStory(storyId);
let epic, owners, team;

if (story.epic_id) {
    epic = await shortcut.getEpic(story.epic_id);
}
for (const ownerId of story.owner_ids) {
    ownerDetails = await shortcut.getMember(ownerId);
    owners.push(ownerDetails);
}

if (story.group_id) {
    team = await shortcut.getGroup(story.group_id);
}

And taking actions on resources is intuitive, here's how you leave a comment on a story:

import SearchResponse from './search-response'
import Story from './story'

const oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);

const client: Client = new Client()
const search: SearchResponse<Story> = await client.stories.search('team:engineering is:started')
const outdatedStories: Story[] = search.results.filter(story => story.updatedAt < oneWeekAgo)

for (const story of outdatedStories) {
  const comment = 'This story has not been updated in over a week. Please provide an update.'
  await story.comment(comment)
}

Using the standard Shortcut Client:

const oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);

const shortcut = new ShortcutClient();
const {data} = await shortcut.searchStories('team:engineering is:started');
const outdatedStories = stories.filter(story => new Date(story.updated_at) < oneWeekAgo)

for (const story of outdatedStories) {
    const comment = 'This story has not been updated in over a week. Please provide an update.'
    await shortcut.createComment(story.id, {text: comment})
}

Installation

To use the Shortcut API Client in your project, you'll need to have Node.js 18+ installed. Once Node.js is set up, you can install the client via npm:

npm install shortcut-api

Or, if you prefer using Yarn:

yarn add shortcut-api

Configuration

This client requires a Shortcut API key to make requests to the API. You can generate an API key from your Shortcut account settings. Once you have your API key, you can pass it to the client when initializing it, or set it as an environment variable:

export SHORTCUT_API_KEY=YOUR_API_KEY

Or

const client = new Client('YOUR_API_KEY')

Usage

Full documentation for the package can be found here.

Full documentation for the Shortcut API can be found here.

Searching Stories

import SearchResponse from '@sx/utils/search-response'
import Story from '@sx/stories/story'

const client: Client = new Client()
const search: SearchResponse<Story> = await client.stories.search('team:engineering is:started')
const stories: Story[] = search.results
if(search.hasNextPage()) {
    const nextPage: SearchResponse<Story> = await search.next()
    stories.push(...nextPage.results)
}
console.log(stories)

Commenting on a Story

Also available on epics

const client: Client = new Client()
const story: Story = await client.stories.get('story-id')
const comment = await story.comment('This is a comment')

Listing Iterations

const client: Client = new Client();
const iterations: Iteration[] = await client.iterations.list();
console.log(iterations);

Creating an Iteration

const client: Client = new Client();
const startDate = new Date(2022, 1, 1);
const endDate = new Date(2022, 1, 14);
const iteration: Iteration = new Iteration({
    name: 'Sprint 1',
    start_date: startDate,
    end_date: endDate,
})
await iteration.save()

Delete a label

const client: Client = new Client();
const label: Label = await client.labels.get('label-id');
await label.delete();

Get a Team

const client: Client = new Client();
const team: Team = await client.teams.get('team-id');
console.log(team);

The syntax for all types is shared, so you can use the same methods for stories, iterations, members, workflows, teams, etc. Some methods are specific to certain types, such as comment for stories and epics. Refer to the full documentation for more information.

Contributing

We welcome contributions to make this client better! If you're interested in contributing, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and write tests if applicable.
  4. Submit a pull request with a clear description of your changes.

License

This project is licensed under the MIT License.

Acknowledgments

  • Special thanks to the Shortcut team for providing the API.

Questions or Feedback

If you have any questions or feedback about the Shortcut API Client, please open an issue on GitHub.