@mo7yw4ng/openape 1.0.1 → 1.0.2

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 (130) hide show
  1. package/esm/_dnt.polyfills.d.ts +83 -6
  2. package/esm/_dnt.polyfills.d.ts.map +1 -0
  3. package/esm/_dnt.polyfills.js +127 -1
  4. package/esm/_dnt.shims.d.ts +1 -0
  5. package/esm/_dnt.shims.d.ts.map +1 -0
  6. package/esm/deno.d.ts +2 -0
  7. package/esm/deno.d.ts.map +1 -0
  8. package/esm/deno.js +2 -1
  9. package/esm/src/commands/announcements.d.ts +3 -0
  10. package/esm/src/commands/announcements.d.ts.map +1 -0
  11. package/esm/src/commands/announcements.js +135 -0
  12. package/esm/src/commands/auth.d.ts +3 -0
  13. package/esm/src/commands/auth.d.ts.map +1 -0
  14. package/esm/src/commands/auth.js +264 -0
  15. package/esm/src/commands/calendar.d.ts +3 -0
  16. package/esm/src/commands/calendar.d.ts.map +1 -0
  17. package/esm/src/commands/calendar.js +180 -0
  18. package/esm/src/commands/courses.d.ts +3 -0
  19. package/esm/src/commands/courses.d.ts.map +1 -0
  20. package/esm/src/commands/courses.js +348 -0
  21. package/esm/src/commands/forums.d.ts +3 -0
  22. package/esm/src/commands/forums.d.ts.map +1 -0
  23. package/esm/src/commands/forums.js +231 -0
  24. package/esm/src/commands/grades.d.ts +3 -0
  25. package/esm/src/commands/grades.d.ts.map +1 -0
  26. package/esm/src/commands/grades.js +121 -0
  27. package/esm/src/commands/materials.d.ts +3 -0
  28. package/esm/src/commands/materials.d.ts.map +1 -0
  29. package/esm/src/commands/materials.js +362 -0
  30. package/esm/src/commands/quizzes.d.ts +3 -0
  31. package/esm/src/commands/quizzes.d.ts.map +1 -0
  32. package/esm/src/commands/quizzes.js +160 -0
  33. package/esm/src/commands/skills.d.ts +3 -0
  34. package/esm/src/commands/skills.d.ts.map +1 -0
  35. package/esm/src/commands/skills.js +110 -0
  36. package/esm/src/commands/videos.d.ts +3 -0
  37. package/esm/src/commands/videos.d.ts.map +1 -0
  38. package/esm/src/commands/videos.js +302 -0
  39. package/esm/src/index.d.ts +27 -0
  40. package/esm/src/index.d.ts.map +1 -0
  41. package/esm/src/index.js +149 -0
  42. package/esm/src/lib/auth.d.ts +25 -0
  43. package/esm/src/lib/auth.d.ts.map +1 -0
  44. package/esm/src/lib/auth.js +194 -0
  45. package/esm/src/lib/config.d.ts +6 -0
  46. package/esm/src/lib/config.d.ts.map +1 -0
  47. package/esm/src/lib/config.js +36 -0
  48. package/esm/src/lib/logger.d.ts +3 -0
  49. package/esm/src/lib/logger.d.ts.map +1 -0
  50. package/esm/src/lib/logger.js +24 -0
  51. package/esm/src/lib/moodle.d.ts +205 -0
  52. package/esm/src/lib/moodle.d.ts.map +1 -0
  53. package/esm/src/lib/moodle.js +690 -0
  54. package/esm/src/lib/session.d.ts +8 -0
  55. package/esm/src/lib/session.d.ts.map +1 -0
  56. package/esm/src/lib/session.js +42 -0
  57. package/esm/src/lib/token.d.ts +38 -0
  58. package/esm/src/lib/token.d.ts.map +1 -0
  59. package/esm/src/lib/token.js +178 -0
  60. package/esm/src/lib/types.d.ts +271 -0
  61. package/esm/src/lib/types.d.ts.map +1 -0
  62. package/esm/src/lib/types.js +1 -0
  63. package/esm/src/lib/utils.d.ts +17 -0
  64. package/esm/src/lib/utils.d.ts.map +1 -0
  65. package/esm/src/lib/utils.js +51 -0
  66. package/package.json +5 -4
  67. package/script/_dnt.polyfills.d.ts +83 -6
  68. package/script/_dnt.polyfills.d.ts.map +1 -0
  69. package/script/_dnt.polyfills.js +128 -0
  70. package/script/_dnt.shims.d.ts +1 -0
  71. package/script/_dnt.shims.d.ts.map +1 -0
  72. package/script/deno.d.ts +2 -0
  73. package/script/deno.d.ts.map +1 -0
  74. package/script/deno.js +2 -1
  75. package/script/src/commands/announcements.d.ts +1 -0
  76. package/script/src/commands/announcements.d.ts.map +1 -0
  77. package/script/src/commands/announcements.js +75 -222
  78. package/script/src/commands/auth.d.ts +1 -0
  79. package/script/src/commands/auth.d.ts.map +1 -0
  80. package/script/src/commands/auth.js +49 -17
  81. package/script/src/commands/calendar.d.ts +1 -0
  82. package/script/src/commands/calendar.d.ts.map +1 -0
  83. package/script/src/commands/calendar.js +112 -301
  84. package/script/src/commands/courses.d.ts +1 -0
  85. package/script/src/commands/courses.d.ts.map +1 -0
  86. package/script/src/commands/courses.js +43 -173
  87. package/script/src/commands/forums.d.ts +1 -0
  88. package/script/src/commands/forums.d.ts.map +1 -0
  89. package/script/src/commands/forums.js +145 -311
  90. package/script/src/commands/grades.d.ts +1 -0
  91. package/script/src/commands/grades.d.ts.map +1 -0
  92. package/script/src/commands/grades.js +62 -194
  93. package/script/src/commands/materials.d.ts +1 -0
  94. package/script/src/commands/materials.d.ts.map +1 -0
  95. package/script/src/commands/materials.js +111 -166
  96. package/script/src/commands/quizzes.d.ts +1 -0
  97. package/script/src/commands/quizzes.d.ts.map +1 -0
  98. package/script/src/commands/quizzes.js +40 -102
  99. package/script/src/commands/skills.d.ts +1 -0
  100. package/script/src/commands/skills.d.ts.map +1 -0
  101. package/script/src/commands/skills.js +17 -18
  102. package/script/src/commands/videos.d.ts +1 -0
  103. package/script/src/commands/videos.d.ts.map +1 -0
  104. package/script/src/commands/videos.js +26 -52
  105. package/script/src/index.d.ts +1 -0
  106. package/script/src/index.d.ts.map +1 -0
  107. package/script/src/index.js +4 -4
  108. package/script/src/lib/auth.d.ts +1 -0
  109. package/script/src/lib/auth.d.ts.map +1 -0
  110. package/script/src/lib/auth.js +9 -10
  111. package/script/src/lib/config.d.ts +1 -0
  112. package/script/src/lib/config.d.ts.map +1 -0
  113. package/script/src/lib/config.js +6 -7
  114. package/script/src/lib/logger.d.ts +1 -0
  115. package/script/src/lib/logger.d.ts.map +1 -0
  116. package/script/src/lib/logger.js +1 -2
  117. package/script/src/lib/moodle.d.ts +25 -54
  118. package/script/src/lib/moodle.d.ts.map +1 -0
  119. package/script/src/lib/moodle.js +103 -324
  120. package/script/src/lib/session.d.ts +1 -0
  121. package/script/src/lib/session.d.ts.map +1 -0
  122. package/script/src/lib/session.js +3 -29
  123. package/script/src/lib/token.d.ts +16 -5
  124. package/script/src/lib/token.d.ts.map +1 -0
  125. package/script/src/lib/token.js +71 -36
  126. package/script/src/lib/types.d.ts +10 -0
  127. package/script/src/lib/types.d.ts.map +1 -0
  128. package/script/src/lib/utils.d.ts +12 -0
  129. package/script/src/lib/utils.d.ts.map +1 -0
  130. package/script/src/lib/utils.js +57 -11
@@ -1,5 +1,49 @@
1
+ /**
2
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
3
+ * but instead of using npm to install additional dependencies,
4
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
5
+ *
6
+ * Note that this code might be imported multiple times
7
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
8
+ * or Node.js might dynamically clear the cache and then force a require).
9
+ * Therefore, it's important to avoid redundant writes to global objects.
10
+ * Additionally, consider that commonjs is used alongside esm,
11
+ * so the two ponyfill functions are stored independently in two separate global objects.
12
+ */
13
+ import { createRequire } from "node:module";
14
+ import { type URL } from "node:url";
1
15
  declare global {
2
16
  interface ImportMeta {
17
+ /** A string representation of the fully qualified module URL. When the
18
+ * module is loaded locally, the value will be a file URL (e.g.
19
+ * `file:///path/module.ts`).
20
+ *
21
+ * You can also parse the string as a URL to determine more information about
22
+ * how the current module was loaded. For example to determine if a module was
23
+ * local or not:
24
+ *
25
+ * ```ts
26
+ * const url = new URL(import.meta.url);
27
+ * if (url.protocol === "file:") {
28
+ * console.log("this module was loaded locally");
29
+ * }
30
+ * ```
31
+ */
32
+ url: string;
33
+ /**
34
+ * A function that returns resolved specifier as if it would be imported
35
+ * using `import(specifier)`.
36
+ *
37
+ * ```ts
38
+ * console.log(import.meta.resolve("./foo.js"));
39
+ * // file:///dev/foo.js
40
+ * ```
41
+ *
42
+ * @param specifier The module specifier to resolve relative to `parent`.
43
+ * @param parent The absolute parent module URL to resolve from.
44
+ * @returns The absolute (`file:`) URL string for the resolved module.
45
+ */
46
+ resolve(specifier: string, parent?: string | URL | undefined): string;
3
47
  /** A flag that indicates if the current module is the main module that was
4
48
  * called when starting the program under Deno.
5
49
  *
@@ -10,15 +54,48 @@ declare global {
10
54
  * ```
11
55
  */
12
56
  main: boolean;
13
- /** A function that returns resolved specifier as if it would be imported
14
- * using `import(specifier)`.
57
+ /** The absolute path of the current module.
15
58
  *
16
- * ```ts
17
- * console.log(import.meta.resolve("./foo.js"));
18
- * // file:///dev/foo.js
59
+ * This property is only provided for local modules (ie. using `file://` URLs).
60
+ *
61
+ * Example:
62
+ * ```
63
+ * // Unix
64
+ * console.log(import.meta.filename); // /home/alice/my_module.ts
65
+ *
66
+ * // Windows
67
+ * console.log(import.meta.filename); // C:\alice\my_module.ts
19
68
  * ```
20
69
  */
21
- resolve(specifier: string): string;
70
+ filename: string;
71
+ /** The absolute path of the directory containing the current module.
72
+ *
73
+ * This property is only provided for local modules (ie. using `file://` URLs).
74
+ *
75
+ * * Example:
76
+ * ```
77
+ * // Unix
78
+ * console.log(import.meta.dirname); // /home/alice
79
+ *
80
+ * // Windows
81
+ * console.log(import.meta.dirname); // C:\alice
82
+ * ```
83
+ */
84
+ dirname: string;
22
85
  }
23
86
  }
87
+ type NodeRequest = ReturnType<typeof createRequire>;
88
+ type NodeModule = NonNullable<NodeRequest["main"]>;
89
+ interface ImportMetaPonyfillCommonjs {
90
+ (require: NodeRequest, module: NodeModule): ImportMeta;
91
+ }
92
+ interface ImportMetaPonyfillEsmodule {
93
+ (importMeta: ImportMeta): ImportMeta;
94
+ }
95
+ interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyfillEsmodule {
96
+ }
97
+ export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
98
+ export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
99
+ export declare let import_meta_ponyfill: ImportMetaPonyfill;
24
100
  export {};
101
+ //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC"}
@@ -1,2 +1,130 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.import_meta_ponyfill = exports.import_meta_ponyfill_esmodule = exports.import_meta_ponyfill_commonjs = void 0;
4
+ /**
5
+ * Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
6
+ * but instead of using npm to install additional dependencies,
7
+ * this approach manually consolidates cjs/mjs/d.ts into a single file.
8
+ *
9
+ * Note that this code might be imported multiple times
10
+ * (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
11
+ * or Node.js might dynamically clear the cache and then force a require).
12
+ * Therefore, it's important to avoid redundant writes to global objects.
13
+ * Additionally, consider that commonjs is used alongside esm,
14
+ * so the two ponyfill functions are stored independently in two separate global objects.
15
+ */
16
+ //@ts-ignore
17
+ const node_module_1 = require("node:module");
18
+ //@ts-ignore
19
+ const node_url_1 = require("node:url");
20
+ //@ts-ignore
21
+ const node_path_1 = require("node:path");
22
+ const defineGlobalPonyfill = (symbolFor, fn) => {
23
+ if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
24
+ Object.defineProperty(globalThis, Symbol.for(symbolFor), {
25
+ configurable: true,
26
+ get() {
27
+ return fn;
28
+ },
29
+ });
30
+ }
31
+ };
32
+ exports.import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
33
+ (() => {
34
+ const moduleImportMetaWM = new WeakMap();
35
+ return (require, module) => {
36
+ let importMetaCache = moduleImportMetaWM.get(module);
37
+ if (importMetaCache == null) {
38
+ const importMeta = Object.assign(Object.create(null), {
39
+ url: (0, node_url_1.pathToFileURL)(module.filename).href,
40
+ main: require.main == module,
41
+ resolve: (specifier, parentURL = importMeta.url) => {
42
+ return (0, node_url_1.pathToFileURL)((importMeta.url === parentURL
43
+ ? require
44
+ : (0, node_module_1.createRequire)(parentURL))
45
+ .resolve(specifier)).href;
46
+ },
47
+ filename: module.filename,
48
+ dirname: module.path,
49
+ });
50
+ moduleImportMetaWM.set(module, importMeta);
51
+ importMetaCache = importMeta;
52
+ }
53
+ return importMetaCache;
54
+ };
55
+ })());
56
+ defineGlobalPonyfill("import-meta-ponyfill-commonjs", exports.import_meta_ponyfill_commonjs);
57
+ exports.import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
58
+ ((importMeta) => {
59
+ const resolveFunStr = String(importMeta.resolve);
60
+ const shimWs = new WeakSet();
61
+ //@ts-ignore
62
+ const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
63
+ .replace(/\/{3,}/, "///");
64
+ const commonShim = (importMeta) => {
65
+ if (typeof importMeta.main !== "boolean") {
66
+ importMeta.main = importMeta.url === mainUrl;
67
+ }
68
+ if (typeof importMeta.filename !== "string") {
69
+ importMeta.filename = (0, node_url_1.fileURLToPath)(importMeta.url);
70
+ importMeta.dirname = (0, node_path_1.dirname)(importMeta.filename);
71
+ }
72
+ };
73
+ if (
74
+ // v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
75
+ resolveFunStr === "undefined" ||
76
+ // v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
77
+ resolveFunStr.startsWith("async")
78
+ // enable by --experimental-import-meta-resolve flag
79
+ ) {
80
+ exports.import_meta_ponyfill_esmodule = (importMeta) => {
81
+ if (!shimWs.has(importMeta)) {
82
+ shimWs.add(importMeta);
83
+ const importMetaUrlRequire = {
84
+ url: importMeta.url,
85
+ require: (0, node_module_1.createRequire)(importMeta.url),
86
+ };
87
+ importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
88
+ return (0, node_url_1.pathToFileURL)((importMetaUrlRequire.url === parentURL
89
+ ? importMetaUrlRequire.require
90
+ : (0, node_module_1.createRequire)(parentURL)).resolve(specifier)).href;
91
+ };
92
+ commonShim(importMeta);
93
+ }
94
+ return importMeta;
95
+ };
96
+ }
97
+ else {
98
+ /// native support
99
+ exports.import_meta_ponyfill_esmodule = (importMeta) => {
100
+ if (!shimWs.has(importMeta)) {
101
+ shimWs.add(importMeta);
102
+ commonShim(importMeta);
103
+ }
104
+ return importMeta;
105
+ };
106
+ }
107
+ return (0, exports.import_meta_ponyfill_esmodule)(importMeta);
108
+ }));
109
+ defineGlobalPonyfill("import-meta-ponyfill-esmodule", exports.import_meta_ponyfill_esmodule);
110
+ exports.import_meta_ponyfill = ((...args) => {
111
+ const _MODULE = (() => {
112
+ if (typeof require === "function" && typeof module === "object") {
113
+ return "commonjs";
114
+ }
115
+ else {
116
+ // eval("typeof import.meta");
117
+ return "esmodule";
118
+ }
119
+ })();
120
+ if (_MODULE === "commonjs") {
121
+ //@ts-ignore
122
+ exports.import_meta_ponyfill = (r, m) => (0, exports.import_meta_ponyfill_commonjs)(r, m);
123
+ }
124
+ else {
125
+ //@ts-ignore
126
+ exports.import_meta_ponyfill = (im) => (0, exports.import_meta_ponyfill_esmodule)(im);
127
+ }
128
+ //@ts-ignore
129
+ return (0, exports.import_meta_ponyfill)(...args);
130
+ });
@@ -3,3 +3,4 @@ export { Deno } from "@deno/shim-deno";
3
3
  export declare const dntGlobalThis: Omit<typeof globalThis, "Deno"> & {
4
4
  Deno: typeof Deno;
5
5
  };
6
+ //# sourceMappingURL=_dnt.shims.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAKvC,eAAO,MAAM,aAAa;;CAA2C,CAAC"}
package/script/deno.d.ts CHANGED
@@ -10,6 +10,7 @@ declare namespace _default {
10
10
  "build:npm": string;
11
11
  };
12
12
  let imports: {
13
+ "@deno/dnt": string;
13
14
  commander: string;
14
15
  "playwright-core": string;
15
16
  "node-html-parser": string;
@@ -21,3 +22,4 @@ declare namespace _default {
21
22
  let unstable: string[];
22
23
  }
23
24
  export default _default;
25
+ //# sourceMappingURL=deno.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deno.d.ts","sourceRoot":"","sources":["../src/deno.js"],"names":[],"mappings":""}
package/script/deno.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
4
  "name": "@openape/openape",
5
- "version": "1.0.1",
5
+ "version": "1.0.2",
6
6
  "description": "CLI tool for CYCU i-Learning platform",
7
7
  "license": "MIT",
8
8
  "exports": "./src/index.ts",
@@ -12,6 +12,7 @@ exports.default = {
12
12
  "build:npm": "deno run -A src/build_npm.ts"
13
13
  },
14
14
  "imports": {
15
+ "@deno/dnt": "jsr:@deno/dnt@^0.42.3",
15
16
  "commander": "npm:commander@^12.1.0",
16
17
  "playwright-core": "npm:playwright-core@^1.48.0",
17
18
  "node-html-parser": "npm:node-html-parser@^6.1.13"
@@ -1,2 +1,3 @@
1
1
  import { Command } from "commander";
2
2
  export declare function registerAnnouncementsCommand(program: Command): void;
3
+ //# sourceMappingURL=announcements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"announcements.d.ts","sourceRoot":"","sources":["../../../src/src/commands/announcements.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqBpC,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqJnE"}
@@ -3,16 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.registerAnnouncementsCommand = void 0;
6
+ exports.registerAnnouncementsCommand = registerAnnouncementsCommand;
7
7
  const utils_js_1 = require("../lib/utils.js");
8
8
  const moodle_js_1 = require("../lib/moodle.js");
9
9
  const logger_js_1 = require("../lib/logger.js");
10
- const auth_js_1 = require("../lib/auth.js");
11
- const session_js_1 = require("../lib/session.js");
12
- const auth_js_2 = require("../lib/auth.js");
13
10
  const token_js_1 = require("../lib/token.js");
14
- const path_1 = __importDefault(require("path"));
15
- const fs_1 = __importDefault(require("fs"));
11
+ const node_path_1 = __importDefault(require("node:path"));
12
+ const node_fs_1 = __importDefault(require("node:fs"));
16
13
  function registerAnnouncementsCommand(program) {
17
14
  const announcementsCmd = program.command("announcements");
18
15
  announcementsCmd.description("Announcement operations");
@@ -28,14 +25,17 @@ function registerAnnouncementsCommand(program) {
28
25
  const silent = outputFormat === "json" && !opts.verbose;
29
26
  const log = (0, logger_js_1.createLogger)(opts.verbose, silent);
30
27
  const baseDir = (0, utils_js_1.getBaseDir)();
31
- const sessionPath = path_1.default.resolve(baseDir, ".auth", "storage-state.json");
28
+ const sessionPath = node_path_1.default.resolve(baseDir, ".auth", "storage-state.json");
32
29
  // Check if session exists
33
- if (!fs_1.default.existsSync(sessionPath)) {
30
+ if (!node_fs_1.default.existsSync(sessionPath)) {
31
+ log.error("未找到登入 session。請先執行 'openape auth login' 進行登入。");
32
+ log.info(`Session 預期位置: ${sessionPath}`);
34
33
  return null;
35
34
  }
36
35
  // Try to load WS token
37
36
  const wsToken = (0, token_js_1.loadWsToken)(sessionPath);
38
37
  if (!wsToken) {
38
+ log.error("未找到 WS token。請先執行 'openape auth login' 進行登入。");
39
39
  return null;
40
40
  }
41
41
  return {
@@ -46,46 +46,6 @@ function registerAnnouncementsCommand(program) {
46
46
  },
47
47
  };
48
48
  }
49
- // Helper function to create session context
50
- async function createSessionContext(options, command) {
51
- // Get global options if command is provided (for --verbose, --silent flags)
52
- const opts = command?.optsWithGlobals ? command.optsWithGlobals() : options;
53
- // Auto-enable silent mode for JSON output (unless --verbose is also set)
54
- const outputFormat = getOutputFormat(command || { optsWithGlobals: () => ({ output: "json" }) });
55
- const silent = outputFormat === "json" && !opts.verbose;
56
- const log = (0, logger_js_1.createLogger)(opts.verbose, silent);
57
- // Determine session path
58
- const baseDir = (0, utils_js_1.getBaseDir)();
59
- const sessionPath = path_1.default.resolve(baseDir, ".auth", "storage-state.json");
60
- // Check if session exists
61
- if (!fs_1.default.existsSync(sessionPath)) {
62
- log.error("未找到登入 session。請先執行 'openape auth login' 進行登入。");
63
- log.info(`Session 預期位置: ${sessionPath}`);
64
- return null;
65
- }
66
- // Create minimal config
67
- const config = {
68
- username: "",
69
- password: "",
70
- courseUrl: "",
71
- moodleBaseUrl: "https://ilearning.cycu.edu.tw",
72
- headless: !options.headed,
73
- slowMo: 0,
74
- authStatePath: sessionPath,
75
- ollamaBaseUrl: "",
76
- };
77
- log.info("啟動瀏覽器...");
78
- const { browser, context, page } = await (0, auth_js_1.launchAuthenticated)(config, log);
79
- try {
80
- const session = await (0, session_js_1.extractSessionInfo)(page, config, log);
81
- return { log, page, session, browser, context };
82
- }
83
- catch (err) {
84
- await context.close();
85
- await browser.close();
86
- throw err;
87
- }
88
- }
89
49
  announcementsCmd
90
50
  .command("list-all")
91
51
  .description("List all announcements across all courses")
@@ -95,155 +55,55 @@ function registerAnnouncementsCommand(program) {
95
55
  .option("--output <format>", "Output format: json|csv|table|silent")
96
56
  .action(async (options, command) => {
97
57
  const limit = parseInt(options.limit, 10);
98
- // Try pure API mode (no browser, fast!)
99
58
  const apiContext = await createApiContext(options, command);
100
- if (apiContext) {
101
- try {
102
- // Get site info to retrieve userid
103
- const siteInfo = await (0, moodle_js_1.getSiteInfoApi)(apiContext.session);
104
- // Get messages for the current user
105
- const messages = await (0, moodle_js_1.getMessagesApi)(apiContext.session, siteInfo.userid, {
106
- limitnum: limit,
107
- });
108
- // Convert messages to announcement format
109
- const allAnnouncements = messages.map(m => ({
110
- course_id: 0,
111
- course_name: "Notifications",
112
- id: m.id,
113
- subject: m.subject,
114
- author: `User ${m.useridfrom}`,
115
- authorId: m.useridfrom,
116
- createdAt: m.timecreated,
117
- modifiedAt: m.timecreated,
118
- unread: false,
119
- forumId: 0,
120
- }));
121
- // Sort by created date (newest first)
122
- allAnnouncements.sort((a, b) => b.createdAt - a.createdAt);
123
- // Apply limit
124
- let filteredAnnouncements = allAnnouncements.slice(0, limit);
125
- const output = {
126
- status: "success",
127
- timestamp: new Date().toISOString(),
128
- level: options.level,
129
- announcements: filteredAnnouncements.map(a => ({
130
- course_id: a.course_id,
131
- course_name: a.course_name,
132
- id: a.id,
133
- subject: a.subject,
134
- author: a.author,
135
- author_id: a.authorId,
136
- created_at: new Date(a.createdAt * 1000).toISOString(),
137
- modified_at: new Date(a.modifiedAt * 1000).toISOString(),
138
- unread: a.unread,
139
- })),
140
- summary: {
141
- total_announcements: allAnnouncements.length,
142
- shown: filteredAnnouncements.length,
143
- },
144
- };
145
- console.log(JSON.stringify(output));
146
- return;
147
- }
148
- catch (e) {
149
- // API failed, fall through to browser mode
150
- const msg = e instanceof Error ? e.message : String(e);
151
- console.error(`// API mode failed: ${msg}, trying browser mode...`);
152
- }
153
- }
154
- // Fallback to browser mode
155
- const context = await createSessionContext(options, command);
156
- if (!context) {
59
+ if (!apiContext) {
157
60
  process.exitCode = 1;
158
61
  return;
159
62
  }
160
- const { log, page, session, browser, context: browserContext } = context;
161
- try {
162
- const classification = options.level === "all" ? undefined : "inprogress";
163
- const courses = await (0, moodle_js_1.getEnrolledCourses)(page, session, log, { classification });
164
- const allAnnouncements = [];
165
- for (const course of courses) {
166
- const forums = await (0, moodle_js_1.getForumsInCourse)(page, session, course.id, log);
167
- // Find news/announcement forums (usually named "news" or "Announcements")
168
- const announcementForums = forums.filter(f => f.forumType === "news" ||
169
- f.name.toLowerCase().includes("news") ||
170
- f.name.toLowerCase().includes("announcement") ||
171
- f.name.toLowerCase().includes("公告"));
172
- for (const forum of announcementForums) {
173
- try {
174
- const discussions = await (0, moodle_js_1.getForumDiscussions)(page, session, parseInt(forum.cmid, 10));
175
- for (const discussion of discussions) {
176
- // Get the first post to get author info
177
- let author = "Unknown";
178
- let authorId = 0;
179
- let createdAt = discussion.timeModified;
180
- try {
181
- const posts = await (0, moodle_js_1.getDiscussionPosts)(page, session, discussion.id);
182
- if (posts.length > 0) {
183
- const firstPost = posts[0];
184
- author = firstPost.author;
185
- authorId = firstPost.authorId || 0;
186
- createdAt = firstPost.created;
187
- }
188
- }
189
- catch {
190
- // Ignore errors fetching posts
191
- }
192
- allAnnouncements.push({
193
- course_id: course.id,
194
- course_name: course.fullname,
195
- id: discussion.id,
196
- subject: discussion.name,
197
- author,
198
- authorId,
199
- createdAt,
200
- modifiedAt: discussion.timeModified,
201
- unread: discussion.unread,
202
- forumId: parseInt(forum.cmid, 10),
203
- });
204
- }
205
- }
206
- catch (err) {
207
- log.debug(`Failed to fetch announcements for ${course.fullname}: ${err}`);
208
- }
209
- }
210
- }
211
- // Sort by created date (newest first)
212
- allAnnouncements.sort((a, b) => b.createdAt - a.createdAt);
213
- // Apply limit
214
- let filteredAnnouncements = allAnnouncements.slice(0, limit);
215
- // Filter unread only if requested
216
- if (options.unreadOnly) {
217
- filteredAnnouncements = filteredAnnouncements.filter(a => a.unread);
218
- }
219
- const output = {
220
- status: "success",
221
- timestamp: new Date().toISOString(),
222
- announcements: filteredAnnouncements.map(a => ({
223
- course_id: a.course_id,
224
- course_name: a.course_name,
225
- id: a.id,
226
- subject: a.subject,
227
- author: a.author,
228
- author_id: a.authorId,
229
- created_at: new Date(a.createdAt * 1000).toISOString(),
230
- modified_at: new Date(a.modifiedAt * 1000).toISOString(),
231
- unread: a.unread,
232
- })),
233
- summary: {
234
- total_announcements: allAnnouncements.length,
235
- unread: allAnnouncements.filter(a => a.unread).length,
236
- shown: filteredAnnouncements.length,
237
- },
238
- };
239
- console.log(JSON.stringify(output));
240
- }
241
- catch (err) {
242
- log.error(`Error: ${err}`);
243
- }
244
- finally {
245
- await (0, auth_js_2.closeBrowserSafely)(browser, browserContext);
246
- }
63
+ // Get site info to retrieve userid
64
+ const siteInfo = await (0, moodle_js_1.getSiteInfoApi)(apiContext.session);
65
+ // Get messages for the current user
66
+ const messages = await (0, moodle_js_1.getMessagesApi)(apiContext.session, siteInfo.userid, {
67
+ limitnum: limit,
68
+ });
69
+ // Convert messages to announcement format
70
+ const allAnnouncements = messages.map(m => ({
71
+ course_id: 0, // Messages don't have courseId
72
+ course_name: "Notifications",
73
+ id: m.id,
74
+ subject: m.subject,
75
+ author: `User ${m.useridfrom}`,
76
+ authorId: m.useridfrom,
77
+ createdAt: m.timecreated,
78
+ modifiedAt: m.timecreated,
79
+ unread: false, // Messages API doesn't provide unread status
80
+ forumId: 0,
81
+ }));
82
+ // Sort by created date (newest first)
83
+ allAnnouncements.sort((a, b) => b.createdAt - a.createdAt);
84
+ // Apply limit
85
+ let filteredAnnouncements = allAnnouncements.slice(0, limit);
86
+ const output = {
87
+ status: "success",
88
+ timestamp: new Date().toISOString(),
89
+ level: options.level,
90
+ announcements: filteredAnnouncements.map(a => ({
91
+ course_id: a.course_id,
92
+ course_name: a.course_name,
93
+ id: a.id,
94
+ subject: a.subject,
95
+ author: a.author,
96
+ author_id: a.authorId,
97
+ created_at: new Date(a.createdAt * 1000).toISOString(),
98
+ modified_at: new Date(a.modifiedAt * 1000).toISOString(),
99
+ unread: a.unread,
100
+ })),
101
+ summary: {
102
+ total_announcements: allAnnouncements.length,
103
+ shown: filteredAnnouncements.length,
104
+ },
105
+ };
106
+ console.log(JSON.stringify(output));
247
107
  });
248
108
  announcementsCmd
249
109
  .command("read")
@@ -251,38 +111,31 @@ function registerAnnouncementsCommand(program) {
251
111
  .argument("<announcement-id>", "Discussion ID of the announcement")
252
112
  .option("--output <format>", "Output format: json|csv|table|silent")
253
113
  .action(async (announcementId, options, command) => {
254
- const context = await createSessionContext(options, command);
255
- if (!context) {
114
+ const apiContext = await createApiContext(options, command);
115
+ if (!apiContext) {
256
116
  process.exitCode = 1;
257
117
  return;
258
118
  }
259
- const { log, page, session, browser, context: browserContext } = context;
260
- try {
261
- const posts = await (0, moodle_js_1.getDiscussionPosts)(page, session, parseInt(announcementId, 10));
262
- if (posts.length === 0) {
263
- log.error(`Announcement not found: ${announcementId}`);
264
- process.exitCode = 1;
265
- return;
266
- }
267
- const firstPost = posts[0];
268
- const output = {
269
- status: "success",
270
- timestamp: new Date().toISOString(),
271
- announcement: {
272
- id: announcementId,
273
- subject: firstPost.subject,
274
- author: firstPost.author,
275
- author_id: firstPost.authorId,
276
- created_at: new Date(firstPost.created * 1000).toISOString(),
277
- modified_at: new Date(firstPost.modified * 1000).toISOString(),
278
- message: firstPost.message,
279
- },
280
- };
281
- console.log(JSON.stringify(output));
282
- }
283
- finally {
284
- await (0, auth_js_2.closeBrowserSafely)(browser, browserContext);
119
+ const posts = await (0, moodle_js_1.getDiscussionPostsApi)(apiContext.session, parseInt(announcementId, 10));
120
+ if (posts.length === 0) {
121
+ apiContext.log.error(`Announcement not found: ${announcementId}`);
122
+ process.exitCode = 1;
123
+ return;
285
124
  }
125
+ const firstPost = posts[0];
126
+ const output = {
127
+ status: "success",
128
+ timestamp: new Date().toISOString(),
129
+ announcement: {
130
+ id: announcementId,
131
+ subject: firstPost.subject,
132
+ author: firstPost.author,
133
+ author_id: firstPost.authorId,
134
+ created_at: new Date(firstPost.created * 1000).toISOString(),
135
+ modified_at: new Date(firstPost.modified * 1000).toISOString(),
136
+ message: firstPost.message,
137
+ },
138
+ };
139
+ console.log(JSON.stringify(output));
286
140
  });
287
141
  }
288
- exports.registerAnnouncementsCommand = registerAnnouncementsCommand;
@@ -1,2 +1,3 @@
1
1
  import { Command } from "commander";
2
2
  export declare function registerAuthCommand(program: Command): void;
3
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/src/commands/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAyQ1D"}