@mo7yw4ng/openape 1.0.4 → 1.0.5

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 (42) hide show
  1. package/esm/deno.js +1 -1
  2. package/esm/src/commands/announcements.js +3 -3
  3. package/esm/src/commands/auth.d.ts.map +1 -1
  4. package/esm/src/commands/auth.js +24 -14
  5. package/esm/src/commands/calendar.js +3 -3
  6. package/esm/src/commands/courses.js +3 -3
  7. package/esm/src/commands/forums.js +3 -3
  8. package/esm/src/commands/grades.js +3 -3
  9. package/esm/src/commands/materials.d.ts.map +1 -1
  10. package/esm/src/commands/materials.js +114 -191
  11. package/esm/src/commands/quizzes.d.ts.map +1 -1
  12. package/esm/src/commands/quizzes.js +33 -22
  13. package/esm/src/commands/videos.js +5 -5
  14. package/esm/src/lib/auth.js +2 -2
  15. package/esm/src/lib/logger.d.ts +1 -1
  16. package/esm/src/lib/logger.d.ts.map +1 -1
  17. package/esm/src/lib/logger.js +7 -4
  18. package/esm/src/lib/moodle.d.ts +4 -0
  19. package/esm/src/lib/moodle.d.ts.map +1 -1
  20. package/esm/src/lib/moodle.js +19 -2
  21. package/package.json +1 -1
  22. package/script/deno.js +1 -1
  23. package/script/src/commands/announcements.js +3 -3
  24. package/script/src/commands/auth.d.ts.map +1 -1
  25. package/script/src/commands/auth.js +24 -14
  26. package/script/src/commands/calendar.js +3 -3
  27. package/script/src/commands/courses.js +3 -3
  28. package/script/src/commands/forums.js +3 -3
  29. package/script/src/commands/grades.js +3 -3
  30. package/script/src/commands/materials.d.ts.map +1 -1
  31. package/script/src/commands/materials.js +111 -188
  32. package/script/src/commands/quizzes.d.ts.map +1 -1
  33. package/script/src/commands/quizzes.js +32 -21
  34. package/script/src/commands/videos.js +5 -5
  35. package/script/src/lib/auth.js +2 -2
  36. package/script/src/lib/logger.d.ts +1 -1
  37. package/script/src/lib/logger.d.ts.map +1 -1
  38. package/script/src/lib/logger.js +7 -4
  39. package/script/src/lib/moodle.d.ts +4 -0
  40. package/script/src/lib/moodle.d.ts.map +1 -1
  41. package/script/src/lib/moodle.js +20 -2
  42. package/skills/openape/SKILL.md +4 -2
@@ -58,6 +58,7 @@ exports.getIncompleteVideosApi = getIncompleteVideosApi;
58
58
  exports.getSupervideosInCourseApi = getSupervideosInCourseApi;
59
59
  exports.getQuizzesByCoursesApi = getQuizzesByCoursesApi;
60
60
  exports.startQuizAttemptApi = startQuizAttemptApi;
61
+ exports.getAllQuizAttemptDataApi = getAllQuizAttemptDataApi;
61
62
  exports.getQuizAttemptDataApi = getQuizAttemptDataApi;
62
63
  exports.processQuizAttemptApi = processQuizAttemptApi;
63
64
  exports.getResourcesByCoursesApi = getResourcesByCoursesApi;
@@ -410,7 +411,6 @@ async function addForumDiscussionApi(session, forumId, subject, message) {
410
411
  forumid: forumId,
411
412
  subject,
412
413
  message: message.replace(/\n/g, "<br>"),
413
- messageformat: 1,
414
414
  });
415
415
  if (data?.discussionid) {
416
416
  return { success: true, discussionId: data.discussionid };
@@ -1043,6 +1043,24 @@ async function startQuizAttemptApi(session, quizId, options = {}) {
1043
1043
  /**
1044
1044
  * Get quiz attempt data including questions via pure WS API.
1045
1045
  */
1046
+ async function getAllQuizAttemptDataApi(session, attemptId) {
1047
+ const firstPage = await getQuizAttemptDataApi(session, attemptId, 0);
1048
+ // Moodle re-indexes question keys per page (always starts at 0),
1049
+ // so we must re-key by actual slot number to avoid overwrites.
1050
+ const allQuestions = {};
1051
+ for (const q of Object.values(firstPage.questions)) {
1052
+ allQuestions[q.slot] = q;
1053
+ }
1054
+ let nextPage = firstPage.nextpage;
1055
+ while (nextPage !== undefined && nextPage !== null && nextPage !== -1) {
1056
+ const pageData = await getQuizAttemptDataApi(session, attemptId, nextPage);
1057
+ for (const q of Object.values(pageData.questions)) {
1058
+ allQuestions[q.slot] = q;
1059
+ }
1060
+ nextPage = pageData.nextpage;
1061
+ }
1062
+ return { ...firstPage, questions: allQuestions, nextpage: undefined };
1063
+ }
1046
1064
  async function getQuizAttemptDataApi(session, attemptId, page = 0) {
1047
1065
  const data = await moodleApiCall(session, "mod_quiz_get_attempt_data", { attemptid: attemptId, page });
1048
1066
  if (!data?.attempt || !data?.questions) {
@@ -1288,7 +1306,7 @@ async function uploadFileApi(session, filePath, options) {
1288
1306
  // Prepare multipart form data
1289
1307
  const formData = new FormData();
1290
1308
  formData.append("token", session.wsToken);
1291
- formData.append("file", new Blob([fileContent]), fileName);
1309
+ formData.append("file", new Blob([new Uint8Array(fileContent)]), fileName);
1292
1310
  formData.append("filepath", options?.filepath || "/");
1293
1311
  formData.append("itemid", String(draftItemId)); // Use our generated draft ID
1294
1312
  formData.append("contextid", String(userContextId)); // Use calculated user context
@@ -41,11 +41,13 @@ openape <command> [subcommand] [args] [flags]
41
41
 
42
42
  ### quizzes — Quiz operations
43
43
 
44
- - `list <course-id>` — List incomplete quizzes in a course
44
+ - `list <course-id>` — List incomplete quizzes in a course. Flags: `--all`
45
45
  - `list-all` — List all incomplete quizzes across courses. Flags: `--level in_progress|all`
46
46
  - `start <quiz-id>` — Start a new quiz attempt
47
47
  - `info <attempt-id>` — Get quiz attempt data and questions. Flags: `--page <number>`
48
- - `save <attempt-id> '<answers-json>'` — Save answers for a quiz attempt. JSON format: `[{"slot":1,"answer":"0"}]`. Multichoice: number, multichoices: `"0,2"`, shortanswer: text
48
+ - `save <attempt-id> '<answers-json>'` — Save answers for a quiz attempt. Flags: `--submit`. JSON format: `[{"slot":1,"answer":"0"}]`. Multichoice: number, multichoices: `"0,2"`, shortanswer: text
49
+
50
+ > **NEVER SUBMIT WITHOUT USER'S PERMISSION**, you have to make sure answer is saved before submitting.
49
51
 
50
52
  ### materials — Material/resource operations
51
53