@mo7yw4ng/openape 1.0.0 → 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 (133) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +15 -5
  3. package/esm/_dnt.polyfills.d.ts +83 -6
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +127 -1
  6. package/esm/_dnt.shims.d.ts +1 -0
  7. package/esm/_dnt.shims.d.ts.map +1 -0
  8. package/esm/deno.d.ts +2 -0
  9. package/esm/deno.d.ts.map +1 -0
  10. package/esm/deno.js +2 -1
  11. package/esm/src/commands/announcements.d.ts +3 -0
  12. package/esm/src/commands/announcements.d.ts.map +1 -0
  13. package/esm/src/commands/announcements.js +135 -0
  14. package/esm/src/commands/auth.d.ts +3 -0
  15. package/esm/src/commands/auth.d.ts.map +1 -0
  16. package/esm/src/commands/auth.js +264 -0
  17. package/esm/src/commands/calendar.d.ts +3 -0
  18. package/esm/src/commands/calendar.d.ts.map +1 -0
  19. package/esm/src/commands/calendar.js +180 -0
  20. package/esm/src/commands/courses.d.ts +3 -0
  21. package/esm/src/commands/courses.d.ts.map +1 -0
  22. package/esm/src/commands/courses.js +348 -0
  23. package/esm/src/commands/forums.d.ts +3 -0
  24. package/esm/src/commands/forums.d.ts.map +1 -0
  25. package/esm/src/commands/forums.js +231 -0
  26. package/esm/src/commands/grades.d.ts +3 -0
  27. package/esm/src/commands/grades.d.ts.map +1 -0
  28. package/esm/src/commands/grades.js +121 -0
  29. package/esm/src/commands/materials.d.ts +3 -0
  30. package/esm/src/commands/materials.d.ts.map +1 -0
  31. package/esm/src/commands/materials.js +362 -0
  32. package/esm/src/commands/quizzes.d.ts +3 -0
  33. package/esm/src/commands/quizzes.d.ts.map +1 -0
  34. package/esm/src/commands/quizzes.js +160 -0
  35. package/esm/src/commands/skills.d.ts +3 -0
  36. package/esm/src/commands/skills.d.ts.map +1 -0
  37. package/esm/src/commands/skills.js +110 -0
  38. package/esm/src/commands/videos.d.ts +3 -0
  39. package/esm/src/commands/videos.d.ts.map +1 -0
  40. package/esm/src/commands/videos.js +302 -0
  41. package/esm/src/index.d.ts +27 -0
  42. package/esm/src/index.d.ts.map +1 -0
  43. package/esm/src/index.js +149 -0
  44. package/esm/src/lib/auth.d.ts +25 -0
  45. package/esm/src/lib/auth.d.ts.map +1 -0
  46. package/esm/src/lib/auth.js +194 -0
  47. package/esm/src/lib/config.d.ts +6 -0
  48. package/esm/src/lib/config.d.ts.map +1 -0
  49. package/esm/src/lib/config.js +36 -0
  50. package/esm/src/lib/logger.d.ts +3 -0
  51. package/esm/src/lib/logger.d.ts.map +1 -0
  52. package/esm/src/lib/logger.js +24 -0
  53. package/esm/src/lib/moodle.d.ts +205 -0
  54. package/esm/src/lib/moodle.d.ts.map +1 -0
  55. package/esm/src/lib/moodle.js +690 -0
  56. package/esm/src/lib/session.d.ts +8 -0
  57. package/esm/src/lib/session.d.ts.map +1 -0
  58. package/esm/src/lib/session.js +42 -0
  59. package/esm/src/lib/token.d.ts +38 -0
  60. package/esm/src/lib/token.d.ts.map +1 -0
  61. package/esm/src/lib/token.js +178 -0
  62. package/esm/src/lib/types.d.ts +271 -0
  63. package/esm/src/lib/types.d.ts.map +1 -0
  64. package/esm/src/lib/types.js +1 -0
  65. package/esm/src/lib/utils.d.ts +17 -0
  66. package/esm/src/lib/utils.d.ts.map +1 -0
  67. package/esm/src/lib/utils.js +51 -0
  68. package/package.json +7 -3
  69. package/script/_dnt.polyfills.d.ts +83 -6
  70. package/script/_dnt.polyfills.d.ts.map +1 -0
  71. package/script/_dnt.polyfills.js +128 -0
  72. package/script/_dnt.shims.d.ts +1 -0
  73. package/script/_dnt.shims.d.ts.map +1 -0
  74. package/script/deno.d.ts +2 -0
  75. package/script/deno.d.ts.map +1 -0
  76. package/script/deno.js +2 -1
  77. package/script/src/commands/announcements.d.ts +1 -0
  78. package/script/src/commands/announcements.d.ts.map +1 -0
  79. package/script/src/commands/announcements.js +75 -222
  80. package/script/src/commands/auth.d.ts +1 -0
  81. package/script/src/commands/auth.d.ts.map +1 -0
  82. package/script/src/commands/auth.js +49 -17
  83. package/script/src/commands/calendar.d.ts +1 -0
  84. package/script/src/commands/calendar.d.ts.map +1 -0
  85. package/script/src/commands/calendar.js +112 -301
  86. package/script/src/commands/courses.d.ts +1 -0
  87. package/script/src/commands/courses.d.ts.map +1 -0
  88. package/script/src/commands/courses.js +43 -173
  89. package/script/src/commands/forums.d.ts +1 -0
  90. package/script/src/commands/forums.d.ts.map +1 -0
  91. package/script/src/commands/forums.js +145 -311
  92. package/script/src/commands/grades.d.ts +1 -0
  93. package/script/src/commands/grades.d.ts.map +1 -0
  94. package/script/src/commands/grades.js +62 -194
  95. package/script/src/commands/materials.d.ts +1 -0
  96. package/script/src/commands/materials.d.ts.map +1 -0
  97. package/script/src/commands/materials.js +111 -166
  98. package/script/src/commands/quizzes.d.ts +1 -0
  99. package/script/src/commands/quizzes.d.ts.map +1 -0
  100. package/script/src/commands/quizzes.js +40 -102
  101. package/script/src/commands/skills.d.ts +1 -0
  102. package/script/src/commands/skills.d.ts.map +1 -0
  103. package/script/src/commands/skills.js +17 -18
  104. package/script/src/commands/videos.d.ts +1 -0
  105. package/script/src/commands/videos.d.ts.map +1 -0
  106. package/script/src/commands/videos.js +26 -52
  107. package/script/src/index.d.ts +1 -0
  108. package/script/src/index.d.ts.map +1 -0
  109. package/script/src/index.js +4 -4
  110. package/script/src/lib/auth.d.ts +1 -0
  111. package/script/src/lib/auth.d.ts.map +1 -0
  112. package/script/src/lib/auth.js +9 -10
  113. package/script/src/lib/config.d.ts +1 -0
  114. package/script/src/lib/config.d.ts.map +1 -0
  115. package/script/src/lib/config.js +6 -7
  116. package/script/src/lib/logger.d.ts +1 -0
  117. package/script/src/lib/logger.d.ts.map +1 -0
  118. package/script/src/lib/logger.js +1 -2
  119. package/script/src/lib/moodle.d.ts +25 -54
  120. package/script/src/lib/moodle.d.ts.map +1 -0
  121. package/script/src/lib/moodle.js +103 -324
  122. package/script/src/lib/session.d.ts +1 -0
  123. package/script/src/lib/session.d.ts.map +1 -0
  124. package/script/src/lib/session.js +3 -29
  125. package/script/src/lib/token.d.ts +16 -5
  126. package/script/src/lib/token.d.ts.map +1 -0
  127. package/script/src/lib/token.js +71 -36
  128. package/script/src/lib/types.d.ts +10 -0
  129. package/script/src/lib/types.d.ts.map +1 -0
  130. package/script/src/lib/utils.d.ts +12 -0
  131. package/script/src/lib/utils.d.ts.map +1 -0
  132. package/script/src/lib/utils.js +57 -11
  133. package/skills/openape/SKILL.md +331 -328
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 MO7YW4NG
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MO7YW4NG
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -12,9 +12,19 @@
12
12
 
13
13
  ## 安裝
14
14
 
15
- 透過 npm 安裝([Node.js v18+](https://nodejs.org/)):
15
+ 透過 npm 安裝為全域指令(推薦,[Node.js](https://nodejs.org/) v18+):
16
16
  ```bash
17
- npm install -g openape
17
+ npm install -g @mo7yw4ng/openape
18
+ ```
19
+
20
+ 或用 npx 單次執行(不需安裝):
21
+ ```bash
22
+ npx @mo7yw4ng/openape --help
23
+ ```
24
+
25
+ 或透過 Deno/JSR 安裝:
26
+ ```bash
27
+ deno install -A -g -n openape jsr:@openape/openape
18
28
  ```
19
29
 
20
30
  ## 核心指令
@@ -32,7 +42,7 @@ openape auth logout # 登出並清除 session
32
42
  openape courses list # 列出所有課程 (支援 --incomplete-only, --level)
33
43
  openape courses info <id> # 顯示特定課程的詳細資訊
34
44
  openape courses progress <id> # 顯示特定課程的進度
35
- openape courses syllabus <id> # 顯示課程大綱
45
+ openape courses syllabus <id> # 顯示課程大綱 (從 CMAP 取得)
36
46
  ```
37
47
 
38
48
  ### 影片 (Videos)
@@ -73,7 +83,7 @@ openape skills install --all # 自動偵測環境並安裝給所有支
73
83
  ```
74
84
  也可以透過 `npx skills` 安裝:
75
85
  ```bash
76
- npx skills add openape/openape
86
+ npx skills add mo7yw4ng/openape
77
87
  ```
78
88
 
79
89
  ## 開發
@@ -94,4 +104,4 @@ deno task compile
94
104
 
95
105
  此專案之版權規範採用 **MIT License** - 至 [LICENSE](LICENSE) 查看更多相關聲明
96
106
 
97
- > **免責聲明**:本工具為非官方開放原始碼專案,與中原大學官方無關。請斟酌使用腳本輔助功能,避免不當操作(如短時間發送大量請求修改系統狀態)而違反學術倫理或導致帳號遭封鎖。
107
+ > **免責聲明**:本工具為非官方開放原始碼專案,與中原大學官方無關。請斟酌使用腳本輔助功能,避免不當操作(如短時間發送大量請求修改系統狀態)而違反學術倫理或導致帳號遭封鎖。
@@ -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 +1,127 @@
1
- export {};
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
+ //@ts-ignore
14
+ import { createRequire } from "node:module";
15
+ //@ts-ignore
16
+ import { fileURLToPath, pathToFileURL } from "node:url";
17
+ //@ts-ignore
18
+ import { dirname } from "node:path";
19
+ const defineGlobalPonyfill = (symbolFor, fn) => {
20
+ if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
21
+ Object.defineProperty(globalThis, Symbol.for(symbolFor), {
22
+ configurable: true,
23
+ get() {
24
+ return fn;
25
+ },
26
+ });
27
+ }
28
+ };
29
+ export let import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
30
+ (() => {
31
+ const moduleImportMetaWM = new WeakMap();
32
+ return (require, module) => {
33
+ let importMetaCache = moduleImportMetaWM.get(module);
34
+ if (importMetaCache == null) {
35
+ const importMeta = Object.assign(Object.create(null), {
36
+ url: pathToFileURL(module.filename).href,
37
+ main: require.main == module,
38
+ resolve: (specifier, parentURL = importMeta.url) => {
39
+ return pathToFileURL((importMeta.url === parentURL
40
+ ? require
41
+ : createRequire(parentURL))
42
+ .resolve(specifier)).href;
43
+ },
44
+ filename: module.filename,
45
+ dirname: module.path,
46
+ });
47
+ moduleImportMetaWM.set(module, importMeta);
48
+ importMetaCache = importMeta;
49
+ }
50
+ return importMetaCache;
51
+ };
52
+ })());
53
+ defineGlobalPonyfill("import-meta-ponyfill-commonjs", import_meta_ponyfill_commonjs);
54
+ export let import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
55
+ ((importMeta) => {
56
+ const resolveFunStr = String(importMeta.resolve);
57
+ const shimWs = new WeakSet();
58
+ //@ts-ignore
59
+ const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
60
+ .replace(/\/{3,}/, "///");
61
+ const commonShim = (importMeta) => {
62
+ if (typeof importMeta.main !== "boolean") {
63
+ importMeta.main = importMeta.url === mainUrl;
64
+ }
65
+ if (typeof importMeta.filename !== "string") {
66
+ importMeta.filename = fileURLToPath(importMeta.url);
67
+ importMeta.dirname = dirname(importMeta.filename);
68
+ }
69
+ };
70
+ if (
71
+ // v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
72
+ resolveFunStr === "undefined" ||
73
+ // v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
74
+ resolveFunStr.startsWith("async")
75
+ // enable by --experimental-import-meta-resolve flag
76
+ ) {
77
+ import_meta_ponyfill_esmodule = (importMeta) => {
78
+ if (!shimWs.has(importMeta)) {
79
+ shimWs.add(importMeta);
80
+ const importMetaUrlRequire = {
81
+ url: importMeta.url,
82
+ require: createRequire(importMeta.url),
83
+ };
84
+ importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
85
+ return pathToFileURL((importMetaUrlRequire.url === parentURL
86
+ ? importMetaUrlRequire.require
87
+ : createRequire(parentURL)).resolve(specifier)).href;
88
+ };
89
+ commonShim(importMeta);
90
+ }
91
+ return importMeta;
92
+ };
93
+ }
94
+ else {
95
+ /// native support
96
+ import_meta_ponyfill_esmodule = (importMeta) => {
97
+ if (!shimWs.has(importMeta)) {
98
+ shimWs.add(importMeta);
99
+ commonShim(importMeta);
100
+ }
101
+ return importMeta;
102
+ };
103
+ }
104
+ return import_meta_ponyfill_esmodule(importMeta);
105
+ }));
106
+ defineGlobalPonyfill("import-meta-ponyfill-esmodule", import_meta_ponyfill_esmodule);
107
+ export let import_meta_ponyfill = ((...args) => {
108
+ const _MODULE = (() => {
109
+ if (typeof require === "function" && typeof module === "object") {
110
+ return "commonjs";
111
+ }
112
+ else {
113
+ // eval("typeof import.meta");
114
+ return "esmodule";
115
+ }
116
+ })();
117
+ if (_MODULE === "commonjs") {
118
+ //@ts-ignore
119
+ import_meta_ponyfill = (r, m) => import_meta_ponyfill_commonjs(r, m);
120
+ }
121
+ else {
122
+ //@ts-ignore
123
+ import_meta_ponyfill = (im) => import_meta_ponyfill_esmodule(im);
124
+ }
125
+ //@ts-ignore
126
+ return import_meta_ponyfill(...args);
127
+ });
@@ -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/esm/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/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "@openape/openape",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "CLI tool for CYCU i-Learning platform",
5
5
  "license": "MIT",
6
6
  "exports": "./src/index.ts",
@@ -10,6 +10,7 @@ export default {
10
10
  "build:npm": "deno run -A src/build_npm.ts"
11
11
  },
12
12
  "imports": {
13
+ "@deno/dnt": "jsr:@deno/dnt@^0.42.3",
13
14
  "commander": "npm:commander@^12.1.0",
14
15
  "playwright-core": "npm:playwright-core@^1.48.0",
15
16
  "node-html-parser": "npm:node-html-parser@^6.1.13"
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
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"}
@@ -0,0 +1,135 @@
1
+ import { getBaseDir } from "../lib/utils.js";
2
+ import { getSiteInfoApi, getMessagesApi, getDiscussionPostsApi } from "../lib/moodle.js";
3
+ import { createLogger } from "../lib/logger.js";
4
+ import { loadWsToken } from "../lib/token.js";
5
+ import path from "node:path";
6
+ import fs from "node:fs";
7
+ export function registerAnnouncementsCommand(program) {
8
+ const announcementsCmd = program.command("announcements");
9
+ announcementsCmd.description("Announcement operations");
10
+ // Helper to get output format from global or local options
11
+ function getOutputFormat(command) {
12
+ const opts = command.optsWithGlobals();
13
+ return opts.output || "json";
14
+ }
15
+ // Pure API context - no browser required (fast!)
16
+ async function createApiContext(options, command) {
17
+ const opts = command?.optsWithGlobals ? command.optsWithGlobals() : options;
18
+ const outputFormat = getOutputFormat(command || { optsWithGlobals: () => ({ output: "json" }) });
19
+ const silent = outputFormat === "json" && !opts.verbose;
20
+ const log = createLogger(opts.verbose, silent);
21
+ const baseDir = getBaseDir();
22
+ const sessionPath = path.resolve(baseDir, ".auth", "storage-state.json");
23
+ // Check if session exists
24
+ if (!fs.existsSync(sessionPath)) {
25
+ log.error("未找到登入 session。請先執行 'openape auth login' 進行登入。");
26
+ log.info(`Session 預期位置: ${sessionPath}`);
27
+ return null;
28
+ }
29
+ // Try to load WS token
30
+ const wsToken = loadWsToken(sessionPath);
31
+ if (!wsToken) {
32
+ log.error("未找到 WS token。請先執行 'openape auth login' 進行登入。");
33
+ return null;
34
+ }
35
+ return {
36
+ log,
37
+ session: {
38
+ wsToken,
39
+ moodleBaseUrl: "https://ilearning.cycu.edu.tw",
40
+ },
41
+ };
42
+ }
43
+ announcementsCmd
44
+ .command("list-all")
45
+ .description("List all announcements across all courses")
46
+ .option("--level <type>", "Course level: in_progress (default) | all", "in_progress")
47
+ .option("--unread-only", "Show only unread announcements")
48
+ .option("--limit <n>", "Maximum number of announcements to show", "20")
49
+ .option("--output <format>", "Output format: json|csv|table|silent")
50
+ .action(async (options, command) => {
51
+ const limit = parseInt(options.limit, 10);
52
+ const apiContext = await createApiContext(options, command);
53
+ if (!apiContext) {
54
+ process.exitCode = 1;
55
+ return;
56
+ }
57
+ // Get site info to retrieve userid
58
+ const siteInfo = await getSiteInfoApi(apiContext.session);
59
+ // Get messages for the current user
60
+ const messages = await getMessagesApi(apiContext.session, siteInfo.userid, {
61
+ limitnum: limit,
62
+ });
63
+ // Convert messages to announcement format
64
+ const allAnnouncements = messages.map(m => ({
65
+ course_id: 0, // Messages don't have courseId
66
+ course_name: "Notifications",
67
+ id: m.id,
68
+ subject: m.subject,
69
+ author: `User ${m.useridfrom}`,
70
+ authorId: m.useridfrom,
71
+ createdAt: m.timecreated,
72
+ modifiedAt: m.timecreated,
73
+ unread: false, // Messages API doesn't provide unread status
74
+ forumId: 0,
75
+ }));
76
+ // Sort by created date (newest first)
77
+ allAnnouncements.sort((a, b) => b.createdAt - a.createdAt);
78
+ // Apply limit
79
+ let filteredAnnouncements = allAnnouncements.slice(0, limit);
80
+ const output = {
81
+ status: "success",
82
+ timestamp: new Date().toISOString(),
83
+ level: options.level,
84
+ announcements: filteredAnnouncements.map(a => ({
85
+ course_id: a.course_id,
86
+ course_name: a.course_name,
87
+ id: a.id,
88
+ subject: a.subject,
89
+ author: a.author,
90
+ author_id: a.authorId,
91
+ created_at: new Date(a.createdAt * 1000).toISOString(),
92
+ modified_at: new Date(a.modifiedAt * 1000).toISOString(),
93
+ unread: a.unread,
94
+ })),
95
+ summary: {
96
+ total_announcements: allAnnouncements.length,
97
+ shown: filteredAnnouncements.length,
98
+ },
99
+ };
100
+ console.log(JSON.stringify(output));
101
+ });
102
+ announcementsCmd
103
+ .command("read")
104
+ .description("Read a specific announcement (shows full content)")
105
+ .argument("<announcement-id>", "Discussion ID of the announcement")
106
+ .option("--output <format>", "Output format: json|csv|table|silent")
107
+ .action(async (announcementId, options, command) => {
108
+ const apiContext = await createApiContext(options, command);
109
+ if (!apiContext) {
110
+ process.exitCode = 1;
111
+ return;
112
+ }
113
+ const posts = await getDiscussionPostsApi(apiContext.session, parseInt(announcementId, 10));
114
+ if (posts.length === 0) {
115
+ apiContext.log.error(`Announcement not found: ${announcementId}`);
116
+ process.exitCode = 1;
117
+ return;
118
+ }
119
+ const firstPost = posts[0];
120
+ const output = {
121
+ status: "success",
122
+ timestamp: new Date().toISOString(),
123
+ announcement: {
124
+ id: announcementId,
125
+ subject: firstPost.subject,
126
+ author: firstPost.author,
127
+ author_id: firstPost.authorId,
128
+ created_at: new Date(firstPost.created * 1000).toISOString(),
129
+ modified_at: new Date(firstPost.modified * 1000).toISOString(),
130
+ message: firstPost.message,
131
+ },
132
+ };
133
+ console.log(JSON.stringify(output));
134
+ });
135
+ }
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
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"}