Skip to content

v4. The Typescript release

Compare
Choose a tag to compare
@exacs exacs released this 17 Nov 15:19
· 67 commits to master since this release

From now on, this package is written in Typescript instead of JavaScript!

πŸŽ‰ Special thanks to

  • @jhsware at KTH for helping with the TypeScript migration and the migration plan (deprecating 3.x and so on)
  • @ssciolla for giving us feedback and reporting that module.exports doesn't work as we have expected #29

Breaking changes

New way to import

Due to inconsistencies between how ES Modules, TypeScript modules and CommonJS works, we decided to take a decision and choose one as the primary way to import this package. We have decided to support in this order: TypeScript first, CommonJS second and ES6 last.

This means that this package must be imported as follow:

TypeScript

import CanvasAPI from "@kth/canvas-api";
CommonJS
const CanvasAPI = require("@kth/canvas-api").default;

Non breaking changes

New method names

To add more clarity about what are the methods, we have decided to rename them as follow:

  • canvas.list becomes canvas.listItems
  • canvas.listPaginated becomes canvas.listPages
  • canvas.requestUrl becomes canvas.request

Old methods (.list and .listPaginated) are deprecated and will emit warnings if you use them.

New signature for listPages

Since listPages returns an iterator over pages and each of them is a different request to the Canvas API, the returned object iterates over Response objects instead of the body.

sendSis is deprecated in favor of sisImport

Previously, the sendSis method accepted three parameters: endpoint, attachment and body. However, at KTH we always call this function with the same parameters (endpoint = accounts/1/sis_import and body = {}) so we decided to drop the parameters and just accept attachment.

New CanvasApiError object

Whenever the request doesn't return a 200, the package will throw a custom CanvasApiError object. This class is also exported so you can use it to catch our methods:

import CanvasApi, { CanvasApiError } from "@kth/canvas-api";

const canvas = new CanvasApi(...);

try {
  await canvas.get(...)
} catch (err) {
  if (err instanceof CanvasApiError) {
    // handle
  }
}

New .client property

Now, once you construct the CanvasAPI instance, you will have .client property that contains the Got client used under the hood. That way you get all the features of the library Got (and we don't need to implement things that Got already has)