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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@groton/canvas-api

v0.3.4

Published

Typed access to Canvas LMS API with embedded documentation

Downloads

8

Readme

@groton/canvas-api

Typed access to Canvas LMS API with embedded documentation

npm version

Clients

This started as a component of @groton/canvas-cli, a command-line set of administrative scripts that I have banged together. However, access to the inline documentation and IntelliSense autocompletions in a few front-end applications evolved this package into an API-only package that depends on purpose-dependent client for use:

Install

Using the Node client.

npm install @groton/canvas-api @groton/canvas-api.client.node-cli

Usage

Again, using the Node client. See @groton/canvas-cli for a working example of using the @battis/qui-cli encapsulation.

import * as Canvas from '@groton/canvas-api';
import { Client } from '@groton/canvas-api.client.node-cli';

// initialize the client from environment variables
Canvas.init(
  new Client({
    instance_url: process.env.INSTANCE_URL,
    client_id: process.env.CLIENT_ID,
    client_secret: process.env.CLIENT_SECRET,
    redirect_uri: process.env.REDIRECT_URI
  })
);

// pull a paginated list of typed users from the API
for (const user of await Canvas.v1.Accounts.Users.list({
  pathParams: { account_id: 1 }
})) {
  console.log(user.name);
}

Mapping Canvas LMS documentation to TypeScript API

The automatically-generated documentation provided by the Canvas LMS API is automatically processed by @groton/canvas-api.swagger-renderer to generate TypeScript API.

Resources

Resources are organized as in the Canvas LMS API documentation, given that they are built from the same files. For example, a CourseProgress object is typed:

let progress: Canvas.Courses.CourseProgress;

…noting that, for all objects:

  • Sentence case and snake_case object names are all converted to CamelCase.
  • Properties remain unchanged in snake_case.
  • All namespaces are capitalized, and properties are lower-case per TypeScript norms.

Endpoints

In general, the endpoints map to method calls that are predictably named. For example, listing subgroups of outcome groups:

GET /api/v1/accounts/{account_id}/outcome_groups/{id}/subgroups

…is handled by:

await Canvas.v1.Accounts.OutcomeGroups.Subgroups.list({
  pathParams: {
    account_id: 123,
    id: 456
  },
  searchParams: {
    as_user_id: 789,
    per_page: 20
  }
});

…in which:

  • snake_case becomes CamelCase for namespaces and objects and pascalCase for methods.
  • Method names are shortened from their nicknames (list_subgroups_accounts) to remove redundancies in the TypeScript API.
  • All method calls are asynchronous.
  • Path parameters are passed as properties of the pathParams property, search/query parameters are passed as properties of the searchParams property, and body/form parameters are passed as properties of the params property.
  • Methods that upload files also require a file property, which may have either a filePath property or a url property. (Not all clients support both local and URL uploads).
  • All methods support masquerading via the as_user_id parameter passed as either in searchParams or the body params (if available).
  • Methods that return paginated responses can adjust the pagination via per_pages and will return the complete list as a result of the method.

Caution regarding === comparisons

Note that, in order to provide data integrity in JavaScript, per Instructure's note about large numbers in that language, I have introduced some type ambiguity into the model, which has ramifications for value tests:

Because numerical values may be represented as either strings or numbers, be very, very cautious about using === comparisons, which will fail when comparing a number to an equivalent string.

Known Issues

This is under steady development, as it underpins my own administrative and user-facing Canvas LMS tools. Known issues are documented in the GitHub repo.

Be aware that, due to eccentricities in the documentation of the Canvas LMS API, a number of the typing decisions have been manually overriden to provide empirically more accurate type definitions. This work is on-going and incomplete (and should end up in a pull request to the LMS repo).

overrides.json documents these eccentricities, is supported by src/Overrides.ts and is processed by @groton/canvas-api.swagger-renderer to generate the contents of src/Resources/ and src/Endpoints/.