canvaslms-cli 1.4.5 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +1 -9
- package/dist/commands/announcements.d.ts +3 -0
- package/dist/commands/announcements.d.ts.map +1 -0
- package/dist/commands/announcements.js +87 -0
- package/dist/commands/announcements.js.map +1 -0
- package/dist/commands/api.d.ts +3 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +8 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/assignments.d.ts +3 -0
- package/dist/commands/assignments.d.ts.map +1 -0
- package/dist/commands/assignments.js +100 -0
- package/dist/commands/assignments.js.map +1 -0
- package/dist/commands/config.d.ts +6 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +202 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/grades.d.ts +3 -0
- package/dist/commands/grades.d.ts.map +1 -0
- package/dist/commands/grades.js +128 -0
- package/dist/commands/grades.js.map +1 -0
- package/dist/commands/list.d.ts +3 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +61 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/profile.d.ts +6 -0
- package/dist/commands/profile.d.ts.map +1 -0
- package/dist/commands/profile.js +30 -0
- package/dist/commands/profile.js.map +1 -0
- package/dist/commands/submit.d.ts +8 -0
- package/dist/commands/submit.d.ts.map +1 -0
- package/dist/commands/submit.js +319 -0
- package/dist/commands/submit.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api-client.d.ts +2 -0
- package/dist/lib/api-client.d.ts.map +1 -0
- package/dist/lib/api-client.js +69 -0
- package/dist/lib/api-client.js.map +1 -0
- package/dist/lib/config-validator.d.ts +4 -0
- package/dist/lib/config-validator.d.ts.map +1 -0
- package/dist/lib/config-validator.js +38 -0
- package/dist/lib/config-validator.js.map +1 -0
- package/dist/lib/config.d.ts +10 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +85 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/file-upload.d.ts +3 -0
- package/dist/lib/file-upload.d.ts.map +1 -0
- package/dist/lib/file-upload.js +52 -0
- package/dist/lib/file-upload.js.map +1 -0
- package/dist/lib/interactive.d.ts +16 -0
- package/dist/lib/interactive.d.ts.map +1 -0
- package/dist/lib/interactive.js +756 -0
- package/dist/lib/interactive.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +89 -0
- package/dist/src/index.js.map +1 -0
- package/dist/types/index.d.ts +146 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +76 -71
- package/commands/announcements.js +0 -102
- package/commands/api.js +0 -19
- package/commands/assignments.js +0 -100
- package/commands/config.js +0 -239
- package/commands/grades.js +0 -201
- package/commands/list.js +0 -68
- package/commands/profile.js +0 -35
- package/commands/submit.js +0 -603
- package/lib/api-client.js +0 -75
- package/lib/config-validator.js +0 -60
- package/lib/config.js +0 -103
- package/lib/file-upload.js +0 -74
- package/lib/interactive.js +0 -889
- package/src/index.js +0 -120
package/lib/config-validator.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration validation and setup helpers
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { configExists, readConfig } from './config.js';
|
|
6
|
-
import { createReadlineInterface, askQuestion } from './interactive.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Check if configuration is valid and prompt setup if needed
|
|
10
|
-
*/
|
|
11
|
-
async function ensureConfig() {
|
|
12
|
-
if (!configExists()) {
|
|
13
|
-
console.log('No Canvas configuration found!');
|
|
14
|
-
console.log('\nLet\'s set up your Canvas CLI configuration...\n');
|
|
15
|
-
|
|
16
|
-
const rl = createReadlineInterface();
|
|
17
|
-
const setup = await askQuestion(rl, 'Would you like to set up your configuration now? (Y/n): ');
|
|
18
|
-
rl.close();
|
|
19
|
-
|
|
20
|
-
if (setup.toLowerCase() === 'n' || setup.toLowerCase() === 'no') {
|
|
21
|
-
console.log('\nTo set up later, run: canvas config setup');
|
|
22
|
-
console.log('Or set environment variables: CANVAS_DOMAIN and CANVAS_API_TOKEN');
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Import and run setup (dynamic import to avoid circular dependency)
|
|
27
|
-
const { setupConfig } = await import('../commands/config.js');
|
|
28
|
-
await setupConfig();
|
|
29
|
-
|
|
30
|
-
// Check if setup was successful
|
|
31
|
-
if (!configExists()) {
|
|
32
|
-
console.log('\nConfiguration setup was not completed. Please run "canvas config setup" to try again.');
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
console.log('\nConfiguration complete! You can now use Canvas CLI commands.');
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Validate existing config
|
|
41
|
-
const config = readConfig();
|
|
42
|
-
if (!config || !config.domain || !config.token) {
|
|
43
|
-
console.log('Invalid configuration found. Please run "canvas config setup" to reconfigure.');
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Wrapper function to ensure config exists before running a command
|
|
52
|
-
*/
|
|
53
|
-
export function requireConfig(fn) {
|
|
54
|
-
return async function(...args) {
|
|
55
|
-
await ensureConfig();
|
|
56
|
-
return fn(...args);
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export { ensureConfig };
|
package/lib/config.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration management for Canvas CLI
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import os from 'os';
|
|
8
|
-
|
|
9
|
-
// Configuration file path in user's home directory
|
|
10
|
-
const CONFIG_FILE = path.join(os.homedir(), '.canvaslms-cli-config.json');
|
|
11
|
-
|
|
12
|
-
// Get default configuration structure
|
|
13
|
-
export function getDefaultConfig() {
|
|
14
|
-
return {
|
|
15
|
-
domain: '',
|
|
16
|
-
token: '',
|
|
17
|
-
createdAt: new Date().toISOString(),
|
|
18
|
-
lastUpdated: new Date().toISOString()
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Load configuration from file
|
|
23
|
-
export function loadConfig() {
|
|
24
|
-
try {
|
|
25
|
-
// Load from config file
|
|
26
|
-
if (fs.existsSync(CONFIG_FILE)) {
|
|
27
|
-
const configData = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
28
|
-
if (configData.domain && configData.token) {
|
|
29
|
-
// Clean up domain - remove https:// and trailing slashes
|
|
30
|
-
const domain = configData.domain.replace(/^https?:\/\//, '').replace(/\/$/, '');
|
|
31
|
-
return { domain, token: configData.token };
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// No configuration found
|
|
35
|
-
console.error('No Canvas configuration found!');
|
|
36
|
-
console.error('\nPlease run "canvas config setup" to configure your Canvas credentials.');
|
|
37
|
-
process.exit(1);
|
|
38
|
-
} catch (error) {
|
|
39
|
-
console.error(`Error loading configuration: ${error.message}`);
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Save configuration to file
|
|
45
|
-
export function saveConfig(domain, token) {
|
|
46
|
-
try {
|
|
47
|
-
const config = {
|
|
48
|
-
domain: domain.replace(/^https?:\/\//, '').replace(/\/$/, ''),
|
|
49
|
-
token,
|
|
50
|
-
createdAt: new Date().toISOString(),
|
|
51
|
-
lastUpdated: new Date().toISOString()
|
|
52
|
-
};
|
|
53
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf8');
|
|
54
|
-
return true;
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error(`Error saving configuration: ${error.message}`);
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Check if config file exists
|
|
62
|
-
export function configExists() {
|
|
63
|
-
return fs.existsSync(CONFIG_FILE);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Get config file path
|
|
67
|
-
export function getConfigPath() {
|
|
68
|
-
return CONFIG_FILE;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Delete config file
|
|
72
|
-
export function deleteConfig() {
|
|
73
|
-
try {
|
|
74
|
-
if (fs.existsSync(CONFIG_FILE)) {
|
|
75
|
-
fs.unlinkSync(CONFIG_FILE);
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
return false;
|
|
79
|
-
} catch (error) {
|
|
80
|
-
console.error(`Error deleting configuration: ${error.message}`);
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Read current configuration (if exists)
|
|
86
|
-
export function readConfig() {
|
|
87
|
-
try {
|
|
88
|
-
if (fs.existsSync(CONFIG_FILE)) {
|
|
89
|
-
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.error(`Error reading configuration: ${error.message}`);
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Get the Canvas instance configuration
|
|
100
|
-
*/
|
|
101
|
-
export function getInstanceConfig() {
|
|
102
|
-
return loadConfig();
|
|
103
|
-
}
|
package/lib/file-upload.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File upload utilities for Canvas
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import axios from 'axios';
|
|
8
|
-
import FormData from 'form-data';
|
|
9
|
-
import { makeCanvasRequest } from './api-client.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Upload single file to Canvas and return the file ID
|
|
13
|
-
*/
|
|
14
|
-
export async function uploadSingleFileToCanvas(courseId, assignmentId, filePath) {
|
|
15
|
-
try {
|
|
16
|
-
// Check if file exists
|
|
17
|
-
if (!fs.existsSync(filePath)) {
|
|
18
|
-
throw new Error(`File not found: ${filePath}`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const fileName = path.basename(filePath);
|
|
22
|
-
const fileContent = fs.readFileSync(filePath);
|
|
23
|
-
|
|
24
|
-
// Step 1: Get upload URL from Canvas
|
|
25
|
-
const uploadParams = [
|
|
26
|
-
`name=${encodeURIComponent(fileName)}`,
|
|
27
|
-
`size=${fileContent.length}`,
|
|
28
|
-
'parent_folder_path=/assignments'
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
const uploadData = await makeCanvasRequest('post', `courses/${courseId}/assignments/${assignmentId}/submissions/self/files`, uploadParams);
|
|
32
|
-
|
|
33
|
-
if (!uploadData.upload_url) {
|
|
34
|
-
throw new Error('Failed to get upload URL from Canvas');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Step 2: Upload file to the provided URL
|
|
38
|
-
const form = new FormData();
|
|
39
|
-
|
|
40
|
-
// Add all the required fields from Canvas response
|
|
41
|
-
Object.keys(uploadData.upload_params).forEach(key => {
|
|
42
|
-
form.append(key, uploadData.upload_params[key]);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Add the file
|
|
46
|
-
form.append('file', fileContent, fileName);
|
|
47
|
-
|
|
48
|
-
const uploadResponse = await axios.post(uploadData.upload_url, form, {
|
|
49
|
-
headers: form.getHeaders(),
|
|
50
|
-
maxRedirects: 0,
|
|
51
|
-
validateStatus: (status) => status < 400
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// Return the file ID for later submission
|
|
55
|
-
return uploadData.id || uploadResponse.data.id;
|
|
56
|
-
|
|
57
|
-
} catch (error) {
|
|
58
|
-
throw new Error(`Failed to upload file ${filePath}: ${error.message}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Submit assignment with uploaded files
|
|
64
|
-
*/
|
|
65
|
-
export async function submitAssignmentWithFiles(courseId, assignmentId, fileIds) {
|
|
66
|
-
const submissionData = {
|
|
67
|
-
submission: {
|
|
68
|
-
submission_type: 'online_upload',
|
|
69
|
-
file_ids: fileIds
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
return await makeCanvasRequest('post', `courses/${courseId}/assignments/${assignmentId}/submissions`, [], JSON.stringify(submissionData));
|
|
74
|
-
}
|