canvas-client
Advanced tools
Comparing version 2.0.0 to 2.0.1
import { type CanvasAccount, CanvasCourse, type CanvasSection, type CanvasEnrollment, type CanvasEnrollmentPayload, type CanvasCoursePayload, CanvasSectionPayload, type CanvasGradingStandard, type CanvasID, type SpecialUserID, type SpecialSectionID, type SISSectionID, type SISUserID, type SpecialCourseID, type SISTermID, type SpecialTermID, CanvasEnrollmentTerm, type CanvasCourseParams, type CanvasEnrollmentParams, type CanvasCourseSettings, type CanvasCourseSettingsUpdate, type CanvasUserUpdatePayload, type CanvasCourseListFilters, type CanvasEnrollmentTermPayload, type CanvasEnrollmentTermParams, type CanvasCourseUsersParams, CanvasUser, CanvasAssignment, type CanvasAssignmentNew, type CanvasAssignmentSubmission, type CanvasAssignmentSubmissionNew, type UserDisplay } from './interfaces'; | ||
import { type ExternalTool, type ExternalToolPayload } from './interfaces/externaltool'; | ||
export declare class CanvasConnector { | ||
protected canvasUrl: string; | ||
protected canvasUrl?: string | undefined; | ||
protected token?: string | undefined; | ||
private rateLimit; | ||
private restUrl; | ||
constructor(canvasUrl: string, token?: string | undefined, options?: CanvasAPIOptions); | ||
constructor(canvasUrl?: string | undefined, token?: string | undefined, options?: CanvasAPIOptions); | ||
send(method: 'get' | 'post' | 'put' | 'delete' | 'head', url: string, payload?: any): Promise<Response & { | ||
@@ -10,0 +10,0 @@ data?: any; |
@@ -14,5 +14,12 @@ import { pLimit, omit, isNotEmpty } from 'txstate-utils'; | ||
this.rateLimit = pLimit(maxConnections); | ||
this.restUrl = new URL('/api/v1', canvasUrl); | ||
try { | ||
this.restUrl = new URL('/api/v1', canvasUrl); | ||
} | ||
catch (_b) { | ||
// let it go until later | ||
} | ||
} | ||
async send(method, url, payload = {}) { | ||
if (this.restUrl == null) | ||
throw new Error('Tried to contact Canvas API but no URL was set for canvas.'); | ||
let finalUrl; | ||
@@ -106,7 +113,3 @@ try { | ||
this.defaultCourseTimeZone = 'America/Chicago'; | ||
if (!(canvasUrl === null || canvasUrl === void 0 ? void 0 : canvasUrl.length)) | ||
throw new Error('Instantiated a canvas client with no URL.'); | ||
if (tokens && !tokens.length) | ||
throw new Error('Instantiated a canvas client with an empty token array. If creating the client in the browser and depending on cookies, do not include tokens parameter at all.'); | ||
if (!tokens) | ||
if (!(tokens === null || tokens === void 0 ? void 0 : tokens.length)) | ||
this.connectors = [new CanvasConnector(canvasUrl, undefined, options)]; | ||
@@ -113,0 +116,0 @@ else |
import { type CanvasAccount, CanvasCourse, type CanvasSection, type CanvasEnrollment, type CanvasEnrollmentPayload, type CanvasCoursePayload, CanvasSectionPayload, type CanvasGradingStandard, type CanvasID, type SpecialUserID, type SpecialSectionID, type SISSectionID, type SISUserID, type SpecialCourseID, type SISTermID, type SpecialTermID, CanvasEnrollmentTerm, type CanvasCourseParams, type CanvasEnrollmentParams, type CanvasCourseSettings, type CanvasCourseSettingsUpdate, type CanvasUserUpdatePayload, type CanvasCourseListFilters, type CanvasEnrollmentTermPayload, type CanvasEnrollmentTermParams, type CanvasCourseUsersParams, CanvasUser, CanvasAssignment, type CanvasAssignmentNew, type CanvasAssignmentSubmission, type CanvasAssignmentSubmissionNew, type UserDisplay } from './interfaces'; | ||
import { type ExternalTool, type ExternalToolPayload } from './interfaces/externaltool'; | ||
export declare class CanvasConnector { | ||
protected canvasUrl: string; | ||
protected canvasUrl?: string | undefined; | ||
protected token?: string | undefined; | ||
private rateLimit; | ||
private restUrl; | ||
constructor(canvasUrl: string, token?: string | undefined, options?: CanvasAPIOptions); | ||
constructor(canvasUrl?: string | undefined, token?: string | undefined, options?: CanvasAPIOptions); | ||
send(method: 'get' | 'post' | 'put' | 'delete' | 'head', url: string, payload?: any): Promise<Response & { | ||
@@ -10,0 +10,0 @@ data?: any; |
@@ -17,5 +17,12 @@ "use strict"; | ||
this.rateLimit = (0, txstate_utils_1.pLimit)(maxConnections); | ||
this.restUrl = new URL('/api/v1', canvasUrl); | ||
try { | ||
this.restUrl = new URL('/api/v1', canvasUrl); | ||
} | ||
catch (_b) { | ||
// let it go until later | ||
} | ||
} | ||
async send(method, url, payload = {}) { | ||
if (this.restUrl == null) | ||
throw new Error('Tried to contact Canvas API but no URL was set for canvas.'); | ||
let finalUrl; | ||
@@ -110,7 +117,3 @@ try { | ||
this.defaultCourseTimeZone = 'America/Chicago'; | ||
if (!(canvasUrl === null || canvasUrl === void 0 ? void 0 : canvasUrl.length)) | ||
throw new Error('Instantiated a canvas client with no URL.'); | ||
if (tokens && !tokens.length) | ||
throw new Error('Instantiated a canvas client with an empty token array. If creating the client in the browser and depending on cookies, do not include tokens parameter at all.'); | ||
if (!tokens) | ||
if (!(tokens === null || tokens === void 0 ? void 0 : tokens.length)) | ||
this.connectors = [new CanvasConnector(canvasUrl, undefined, options)]; | ||
@@ -117,0 +120,0 @@ else |
{ | ||
"name": "canvas-client", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Typescript library to make accessing the Canvas API more convenient.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
3091
131299