canvaslms-cli 1.4.6 → 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.
Files changed (81) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +1 -9
  3. package/dist/commands/announcements.d.ts +3 -0
  4. package/dist/commands/announcements.d.ts.map +1 -0
  5. package/dist/commands/announcements.js +87 -0
  6. package/dist/commands/announcements.js.map +1 -0
  7. package/dist/commands/api.d.ts +3 -0
  8. package/dist/commands/api.d.ts.map +1 -0
  9. package/dist/commands/api.js +8 -0
  10. package/dist/commands/api.js.map +1 -0
  11. package/dist/commands/assignments.d.ts +3 -0
  12. package/dist/commands/assignments.d.ts.map +1 -0
  13. package/dist/commands/assignments.js +100 -0
  14. package/dist/commands/assignments.js.map +1 -0
  15. package/dist/commands/config.d.ts +6 -0
  16. package/dist/commands/config.d.ts.map +1 -0
  17. package/dist/commands/config.js +202 -0
  18. package/dist/commands/config.js.map +1 -0
  19. package/dist/commands/grades.d.ts +3 -0
  20. package/dist/commands/grades.d.ts.map +1 -0
  21. package/dist/commands/grades.js +128 -0
  22. package/dist/commands/grades.js.map +1 -0
  23. package/dist/commands/list.d.ts +3 -0
  24. package/dist/commands/list.d.ts.map +1 -0
  25. package/dist/commands/list.js +61 -0
  26. package/dist/commands/list.js.map +1 -0
  27. package/dist/commands/profile.d.ts +6 -0
  28. package/dist/commands/profile.d.ts.map +1 -0
  29. package/dist/commands/profile.js +30 -0
  30. package/dist/commands/profile.js.map +1 -0
  31. package/dist/commands/submit.d.ts +8 -0
  32. package/dist/commands/submit.d.ts.map +1 -0
  33. package/dist/commands/submit.js +319 -0
  34. package/dist/commands/submit.js.map +1 -0
  35. package/dist/index.d.ts +15 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +15 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/lib/api-client.d.ts +2 -0
  40. package/dist/lib/api-client.d.ts.map +1 -0
  41. package/dist/lib/api-client.js +69 -0
  42. package/dist/lib/api-client.js.map +1 -0
  43. package/dist/lib/config-validator.d.ts +4 -0
  44. package/dist/lib/config-validator.d.ts.map +1 -0
  45. package/dist/lib/config-validator.js +38 -0
  46. package/dist/lib/config-validator.js.map +1 -0
  47. package/dist/lib/config.d.ts +10 -0
  48. package/dist/lib/config.d.ts.map +1 -0
  49. package/dist/lib/config.js +85 -0
  50. package/dist/lib/config.js.map +1 -0
  51. package/dist/lib/file-upload.d.ts +3 -0
  52. package/dist/lib/file-upload.d.ts.map +1 -0
  53. package/dist/lib/file-upload.js +52 -0
  54. package/dist/lib/file-upload.js.map +1 -0
  55. package/dist/lib/interactive.d.ts +16 -0
  56. package/dist/lib/interactive.d.ts.map +1 -0
  57. package/dist/lib/interactive.js +756 -0
  58. package/dist/lib/interactive.js.map +1 -0
  59. package/dist/src/index.d.ts +3 -0
  60. package/dist/src/index.d.ts.map +1 -0
  61. package/dist/src/index.js +89 -0
  62. package/dist/src/index.js.map +1 -0
  63. package/dist/types/index.d.ts +146 -0
  64. package/dist/types/index.d.ts.map +1 -0
  65. package/dist/types/index.js +2 -0
  66. package/dist/types/index.js.map +1 -0
  67. package/package.json +76 -71
  68. package/commands/announcements.js +0 -102
  69. package/commands/api.js +0 -19
  70. package/commands/assignments.js +0 -100
  71. package/commands/config.js +0 -239
  72. package/commands/grades.js +0 -201
  73. package/commands/list.js +0 -68
  74. package/commands/profile.js +0 -35
  75. package/commands/submit.js +0 -603
  76. package/lib/api-client.js +0 -75
  77. package/lib/config-validator.js +0 -60
  78. package/lib/config.js +0 -103
  79. package/lib/file-upload.js +0 -74
  80. package/lib/interactive.js +0 -889
  81. package/src/index.js +0 -120
@@ -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
- }
@@ -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=${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
- }