canvas-client
Advanced tools
| import { pLimit, omit, isNotEmpty } from 'txstate-utils'; | ||
| import { CanvasCourse, CanvasSectionPayload, CanvasEnrollmentTerm, CanvasCourseIncludes, CanvasUser, CanvasAssignment } from './interfaces'; | ||
| import { throwUnlessValidId, throwUnlessValidUserId } from './utils/utils'; | ||
| import { stringifyParams, throwUnlessValidId, throwUnlessValidUserId } from './utils/utils'; | ||
| import { GraphQLError } from './utils/errors'; | ||
@@ -33,3 +33,3 @@ import { parseLinkHeader } from './utils/parselink'; | ||
| if (!isPostOrPut && isNotEmpty(payload)) | ||
| finalUrl.search = new URLSearchParams(payload).toString(); | ||
| finalUrl.search = stringifyParams(payload); | ||
| const resp = await fetch(finalUrl, { | ||
@@ -36,0 +36,0 @@ method, |
| import { type CanvasID } from '../interfaces'; | ||
| export declare function throwUnlessValidId(id: CanvasID | string, prefix: string): void; | ||
| export declare function throwUnlessValidUserId(id: CanvasID | string): void; | ||
| export declare function stringifyParams(params: Record<string, any>): string; |
@@ -10,1 +10,29 @@ export function throwUnlessValidId(id, prefix) { | ||
| } | ||
| export function stringifyParams(params) { | ||
| const flattened = []; | ||
| for (const [key, val] of Object.entries(params)) { | ||
| if (Array.isArray(val)) { | ||
| const arrKey = key.endsWith('[]') ? key : key + '[]'; | ||
| flattened.push(...val.map(v => [arrKey, String(v)])); | ||
| } | ||
| else if (typeof val === 'object' && val !== null) { | ||
| for (const [subKey, subVal] of Object.entries(val)) { | ||
| if (Array.isArray(subVal)) { | ||
| flattened.push(...subVal.map((v) => [`${key}[${subKey}][]`, v])); | ||
| } | ||
| else if (typeof subVal === 'object' && subVal !== null) { | ||
| for (const [deepKey, deepVal] of Object.entries(subVal)) { | ||
| flattened.push([`${key}[${subKey}][${deepKey}]`, deepVal]); | ||
| } | ||
| } | ||
| else { | ||
| flattened.push([`${key}[${subKey}]`, String(subVal)]); | ||
| } | ||
| } | ||
| } | ||
| else { | ||
| flattened.push([key, String(val)]); | ||
| } | ||
| } | ||
| return '?' + flattened.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('&'); | ||
| } |
+1
-1
@@ -36,3 +36,3 @@ "use strict"; | ||
| if (!isPostOrPut && (0, txstate_utils_1.isNotEmpty)(payload)) | ||
| finalUrl.search = new URLSearchParams(payload).toString(); | ||
| finalUrl.search = (0, utils_1.stringifyParams)(payload); | ||
| const resp = await fetch(finalUrl, { | ||
@@ -39,0 +39,0 @@ method, |
| import { type CanvasID } from '../interfaces'; | ||
| export declare function throwUnlessValidId(id: CanvasID | string, prefix: string): void; | ||
| export declare function throwUnlessValidUserId(id: CanvasID | string): void; | ||
| export declare function stringifyParams(params: Record<string, any>): string; |
+30
-1
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.throwUnlessValidUserId = exports.throwUnlessValidId = void 0; | ||
| exports.stringifyParams = exports.throwUnlessValidUserId = exports.throwUnlessValidId = void 0; | ||
| function throwUnlessValidId(id, prefix) { | ||
@@ -15,1 +15,30 @@ if (typeof id === 'string' && isNaN(parseInt(id)) && !id.startsWith(prefix)) | ||
| exports.throwUnlessValidUserId = throwUnlessValidUserId; | ||
| function stringifyParams(params) { | ||
| const flattened = []; | ||
| for (const [key, val] of Object.entries(params)) { | ||
| if (Array.isArray(val)) { | ||
| const arrKey = key.endsWith('[]') ? key : key + '[]'; | ||
| flattened.push(...val.map(v => [arrKey, String(v)])); | ||
| } | ||
| else if (typeof val === 'object' && val !== null) { | ||
| for (const [subKey, subVal] of Object.entries(val)) { | ||
| if (Array.isArray(subVal)) { | ||
| flattened.push(...subVal.map((v) => [`${key}[${subKey}][]`, v])); | ||
| } | ||
| else if (typeof subVal === 'object' && subVal !== null) { | ||
| for (const [deepKey, deepVal] of Object.entries(subVal)) { | ||
| flattened.push([`${key}[${subKey}][${deepKey}]`, deepVal]); | ||
| } | ||
| } | ||
| else { | ||
| flattened.push([`${key}[${subKey}]`, String(subVal)]); | ||
| } | ||
| } | ||
| } | ||
| else { | ||
| flattened.push([key, String(val)]); | ||
| } | ||
| } | ||
| return '?' + flattened.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('&'); | ||
| } | ||
| exports.stringifyParams = stringifyParams; |
+1
-1
| { | ||
| "name": "canvas-client", | ||
| "version": "2.0.5", | ||
| "version": "2.0.6", | ||
| "description": "Typescript library to make accessing the Canvas API more convenient.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
136361
1.93%3158
1.9%