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

zwift-mobile-api

v0.3.19

Published

Libraries to simplify accessing the Zwift Mobile API

Downloads

83

Readme

GDPR and Zwift's Developer API

In July '08, this library was converted to use Zwift's new Developer API, in accordance with Zwift's policies.

The Developer API requires a special developer account, and won't work with regular rider accounts like before. Currently, Zwift is not able to offer developer accounts to hobby developers, but I'm hoping they'll be able to at some point. You can contact Zwift at [email protected] to register interest and ask for further information.

zwift-mobile-api

A simple javascript library to make it a bit easier to call some of the Zwift API endpoints

  • Automatically handle creating and renewing of a valid token (requires username and password to login with a valid Zwift account)
  • Decode protobuf data to get live current speed/power/time data for currently riding players
  • List and download previous activities, decoded from FIT files

Usage

$> npm install --save zwift-mobile-api

Login

var ZwiftAccount = require("zwift-mobile-api");
var account = new ZwiftAccount(username, password);

Rider Profiles

// Get profile for "me"
account.getProfile().profile().then(p => {
    console.log(p);  // JSON of rider profile (includes id property you can use below)
});

// Get profile data for a particular rider (requires Zwift player id)
var profile = account.getProfile(playerId);

profile.followers().then(followers => {
    console.log(followers); // JSON array of rider's followers
});

profile.followees().then(followees => {
    console.log(followees); // JSON array of rider's followees
});

// Give a RideOn (from 'playerId' to 'otherRiderId')
// Can lookup 'activityId' from 'currentActivityId' of profile() response
profile.giveRideOn(otherRiderId, activityId);

// Retrieve the goals you have
profile.goals().then(goal=> {
    console.log(goal); //JSON array of goals
})

// Delete a goal; goalID is printed from getGoals()
goalID = 200147
prof.deleteGoal(goalID)

List Riders

// (note: currently all riders are listed in world '1',
// so worlds 2 and 3 are empty no matter the schedule)

var world = account.getWorld(1);

world.riders().then(riders => {
    console.log(riders); // JSON array of all riders currently riding
});

Rider Status

// (note: currently all riders are listed in world '1',
// so worlds 2 and 3 are empty no matter the schedule)

var world = account.getWorld(1);

// Get the status of the specified rider
// (includes x,y position, speed, power, etc)
world.riderStatus(playerId).then(status => {
    console.log(status); // JSON of rider status
});

Events

var event = account.getEvent();

// Search for events
// options:
//   eventStartsAfter = earliest start time (milliseconds since 1970)
//   eventStartsBefore = latest start time (milliseconds since 1970)
const options = {
    eventStartsAfter: Date.now() - 3600000,
    eventStartsBefore: Date.now() + 600000
};
event.search(options).then(results => {
    results.forEach(event => console.log(
        `${event.id}: ${event.name} - sub groups `
        + event.eventSubgroups.map(g => `${g.label}:${g.id}`)
    ))
});

// Get riders who signed up to an event sub group
// (get subGroupId from search() results)
event.riders(subGroupId).then(riders =>
    riders.forEach(r => console.log(
        `${r.id} - ${r.firstName} ${r.lastName}`
    ))
);

// Get the results for an event subgroup.
// Note that results returned by Zwift are not sorted, even though they
// often come through as slowest first.
event.segmentResults(eventSubgroupId).then(results => {
    results.sort((a,b) => {
        if (a.elapsedMs > b.elapsedMs) {
            return 1;
        } else if (a.elapsedMs == b.elapsedMs) {
            return 0;
        }
        return -1;
    })
    for (let result of results) {
        console.log(result);
    }
});

Previous Activities

// Get profile data for a particular rider (requires Zwift player id)
var profile = account.getProfile(playerId);

// Get the list of previous activities
// (start, limit parameters for paging - e.g. (0,30) for first 30 activities)
profile.activities(start, limit).then(activities => {
    console.log(activities); // JSON array of activities
});

// Get full position data for an activity from FIT file
// (translated back into Zwift world coordinates)
account.getActivity(playerId).get(activityId).then(activity => {
    console.log(activity); // JSON of activity including positions
});