chukyo-sdk 0.1.0

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 (177) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +227 -0
  3. package/dist/cjs/albo/client.js +133 -0
  4. package/dist/cjs/albo/index.js +55 -0
  5. package/dist/cjs/albo/parser/albo.js +110 -0
  6. package/dist/cjs/albo/types/albo.js +351 -0
  7. package/dist/cjs/albo/types/alboCalendar.js +51 -0
  8. package/dist/cjs/albo/types/alboCommon.js +55 -0
  9. package/dist/cjs/albo/types/alboInformation.js +136 -0
  10. package/dist/cjs/albo/types/alboMenu.js +92 -0
  11. package/dist/cjs/albo/types/alboQuestionnaire.js +229 -0
  12. package/dist/cjs/albo/types/alboSharedItem.js +137 -0
  13. package/dist/cjs/albo/types/alboSystem.js +103 -0
  14. package/dist/cjs/albo/types/alboUniversalForm.js +51 -0
  15. package/dist/cjs/common/dom.js +137 -0
  16. package/dist/cjs/common/utils.js +29 -0
  17. package/dist/cjs/constants.js +127 -0
  18. package/dist/cjs/core/request.js +39 -0
  19. package/dist/cjs/cubics/client.js +49 -0
  20. package/dist/cjs/cubics/index.js +22 -0
  21. package/dist/cjs/cubics/parser/cubics.js +103 -0
  22. package/dist/cjs/cubics/types/cubics.js +90 -0
  23. package/dist/cjs/errors.js +55 -0
  24. package/dist/cjs/index.js +50 -0
  25. package/dist/cjs/manabo/client.js +135 -0
  26. package/dist/cjs/manabo/index.js +44 -0
  27. package/dist/cjs/manabo/parser/manaboClass.js +386 -0
  28. package/dist/cjs/manabo/parser/manaboEntry.js +38 -0
  29. package/dist/cjs/manabo/parser/manaboMail.js +153 -0
  30. package/dist/cjs/manabo/parser/manaboNews.js +26 -0
  31. package/dist/cjs/manabo/parser/manaboTimetable.js +93 -0
  32. package/dist/cjs/manabo/types/manaboClass.js +223 -0
  33. package/dist/cjs/manabo/types/manaboEntry.js +43 -0
  34. package/dist/cjs/manabo/types/manaboMail.js +117 -0
  35. package/dist/cjs/manabo/types/manaboNews.js +20 -0
  36. package/dist/cjs/manabo/types/manaboTimetable.js +79 -0
  37. package/dist/cjs/package.json +1 -0
  38. package/dist/cjs/shib/builder.js +239 -0
  39. package/dist/cjs/shib/index.js +32 -0
  40. package/dist/cjs/shib/parser/shibLogin.js +138 -0
  41. package/dist/cjs/shib/parser/shibUser.js +51 -0
  42. package/dist/cjs/shib/types/common.js +2 -0
  43. package/dist/cjs/shib/types/shibLogin.js +92 -0
  44. package/dist/cjs/shib/types/shibUser.js +44 -0
  45. package/dist/cjs/transports/fetch.js +84 -0
  46. package/dist/cjs/types.js +9 -0
  47. package/dist/esm/albo/client.d.ts +80 -0
  48. package/dist/esm/albo/client.d.ts.map +1 -0
  49. package/dist/esm/albo/client.js +129 -0
  50. package/dist/esm/albo/index.d.ts +12 -0
  51. package/dist/esm/albo/index.d.ts.map +1 -0
  52. package/dist/esm/albo/index.js +11 -0
  53. package/dist/esm/albo/parser/albo.d.ts +69 -0
  54. package/dist/esm/albo/parser/albo.d.ts.map +1 -0
  55. package/dist/esm/albo/parser/albo.js +84 -0
  56. package/dist/esm/albo/types/albo.d.ts +460 -0
  57. package/dist/esm/albo/types/albo.d.ts.map +1 -0
  58. package/dist/esm/albo/types/albo.js +348 -0
  59. package/dist/esm/albo/types/alboCalendar.d.ts +58 -0
  60. package/dist/esm/albo/types/alboCalendar.d.ts.map +1 -0
  61. package/dist/esm/albo/types/alboCalendar.js +48 -0
  62. package/dist/esm/albo/types/alboCommon.d.ts +52 -0
  63. package/dist/esm/albo/types/alboCommon.d.ts.map +1 -0
  64. package/dist/esm/albo/types/alboCommon.js +51 -0
  65. package/dist/esm/albo/types/alboInformation.d.ts +214 -0
  66. package/dist/esm/albo/types/alboInformation.d.ts.map +1 -0
  67. package/dist/esm/albo/types/alboInformation.js +133 -0
  68. package/dist/esm/albo/types/alboMenu.d.ts +114 -0
  69. package/dist/esm/albo/types/alboMenu.d.ts.map +1 -0
  70. package/dist/esm/albo/types/alboMenu.js +89 -0
  71. package/dist/esm/albo/types/alboQuestionnaire.d.ts +442 -0
  72. package/dist/esm/albo/types/alboQuestionnaire.d.ts.map +1 -0
  73. package/dist/esm/albo/types/alboQuestionnaire.js +226 -0
  74. package/dist/esm/albo/types/alboSharedItem.d.ts +205 -0
  75. package/dist/esm/albo/types/alboSharedItem.d.ts.map +1 -0
  76. package/dist/esm/albo/types/alboSharedItem.js +134 -0
  77. package/dist/esm/albo/types/alboSystem.d.ts +129 -0
  78. package/dist/esm/albo/types/alboSystem.d.ts.map +1 -0
  79. package/dist/esm/albo/types/alboSystem.js +100 -0
  80. package/dist/esm/albo/types/alboUniversalForm.d.ts +63 -0
  81. package/dist/esm/albo/types/alboUniversalForm.d.ts.map +1 -0
  82. package/dist/esm/albo/types/alboUniversalForm.js +48 -0
  83. package/dist/esm/common/dom.d.ts +35 -0
  84. package/dist/esm/common/dom.d.ts.map +1 -0
  85. package/dist/esm/common/dom.js +120 -0
  86. package/dist/esm/common/utils.d.ts +15 -0
  87. package/dist/esm/common/utils.d.ts.map +1 -0
  88. package/dist/esm/common/utils.js +22 -0
  89. package/dist/esm/constants.d.ts +113 -0
  90. package/dist/esm/constants.d.ts.map +1 -0
  91. package/dist/esm/constants.js +124 -0
  92. package/dist/esm/core/request.d.ts +29 -0
  93. package/dist/esm/core/request.d.ts.map +1 -0
  94. package/dist/esm/core/request.js +33 -0
  95. package/dist/esm/cubics/client.d.ts +13 -0
  96. package/dist/esm/cubics/client.d.ts.map +1 -0
  97. package/dist/esm/cubics/client.js +45 -0
  98. package/dist/esm/cubics/index.d.ts +4 -0
  99. package/dist/esm/cubics/index.d.ts.map +1 -0
  100. package/dist/esm/cubics/index.js +3 -0
  101. package/dist/esm/cubics/parser/cubics.d.ts +8 -0
  102. package/dist/esm/cubics/parser/cubics.d.ts.map +1 -0
  103. package/dist/esm/cubics/parser/cubics.js +99 -0
  104. package/dist/esm/cubics/types/cubics.d.ts +94 -0
  105. package/dist/esm/cubics/types/cubics.d.ts.map +1 -0
  106. package/dist/esm/cubics/types/cubics.js +87 -0
  107. package/dist/esm/errors.d.ts +46 -0
  108. package/dist/esm/errors.d.ts.map +1 -0
  109. package/dist/esm/errors.js +46 -0
  110. package/dist/esm/index.d.ts +19 -0
  111. package/dist/esm/index.d.ts.map +1 -0
  112. package/dist/esm/index.js +25 -0
  113. package/dist/esm/manabo/client.d.ts +75 -0
  114. package/dist/esm/manabo/client.d.ts.map +1 -0
  115. package/dist/esm/manabo/client.js +131 -0
  116. package/dist/esm/manabo/index.d.ts +12 -0
  117. package/dist/esm/manabo/index.d.ts.map +1 -0
  118. package/dist/esm/manabo/index.js +11 -0
  119. package/dist/esm/manabo/parser/manaboClass.d.ts +9 -0
  120. package/dist/esm/manabo/parser/manaboClass.d.ts.map +1 -0
  121. package/dist/esm/manabo/parser/manaboClass.js +377 -0
  122. package/dist/esm/manabo/parser/manaboEntry.d.ts +8 -0
  123. package/dist/esm/manabo/parser/manaboEntry.d.ts.map +1 -0
  124. package/dist/esm/manabo/parser/manaboEntry.js +33 -0
  125. package/dist/esm/manabo/parser/manaboMail.d.ts +8 -0
  126. package/dist/esm/manabo/parser/manaboMail.d.ts.map +1 -0
  127. package/dist/esm/manabo/parser/manaboMail.js +145 -0
  128. package/dist/esm/manabo/parser/manaboNews.d.ts +7 -0
  129. package/dist/esm/manabo/parser/manaboNews.d.ts.map +1 -0
  130. package/dist/esm/manabo/parser/manaboNews.js +22 -0
  131. package/dist/esm/manabo/parser/manaboTimetable.d.ts +4 -0
  132. package/dist/esm/manabo/parser/manaboTimetable.d.ts.map +1 -0
  133. package/dist/esm/manabo/parser/manaboTimetable.js +89 -0
  134. package/dist/esm/manabo/types/manaboClass.d.ts +294 -0
  135. package/dist/esm/manabo/types/manaboClass.d.ts.map +1 -0
  136. package/dist/esm/manabo/types/manaboClass.js +220 -0
  137. package/dist/esm/manabo/types/manaboEntry.d.ts +24 -0
  138. package/dist/esm/manabo/types/manaboEntry.d.ts.map +1 -0
  139. package/dist/esm/manabo/types/manaboEntry.js +40 -0
  140. package/dist/esm/manabo/types/manaboMail.d.ts +103 -0
  141. package/dist/esm/manabo/types/manaboMail.d.ts.map +1 -0
  142. package/dist/esm/manabo/types/manaboMail.js +114 -0
  143. package/dist/esm/manabo/types/manaboNews.d.ts +15 -0
  144. package/dist/esm/manabo/types/manaboNews.d.ts.map +1 -0
  145. package/dist/esm/manabo/types/manaboNews.js +17 -0
  146. package/dist/esm/manabo/types/manaboTimetable.d.ts +88 -0
  147. package/dist/esm/manabo/types/manaboTimetable.d.ts.map +1 -0
  148. package/dist/esm/manabo/types/manaboTimetable.js +76 -0
  149. package/dist/esm/package.json +1 -0
  150. package/dist/esm/shib/builder.d.ts +154 -0
  151. package/dist/esm/shib/builder.d.ts.map +1 -0
  152. package/dist/esm/shib/builder.js +212 -0
  153. package/dist/esm/shib/index.d.ts +15 -0
  154. package/dist/esm/shib/index.d.ts.map +1 -0
  155. package/dist/esm/shib/index.js +14 -0
  156. package/dist/esm/shib/parser/shibLogin.d.ts +47 -0
  157. package/dist/esm/shib/parser/shibLogin.d.ts.map +1 -0
  158. package/dist/esm/shib/parser/shibLogin.js +127 -0
  159. package/dist/esm/shib/parser/shibUser.d.ts +11 -0
  160. package/dist/esm/shib/parser/shibUser.d.ts.map +1 -0
  161. package/dist/esm/shib/parser/shibUser.js +46 -0
  162. package/dist/esm/shib/types/common.d.ts +20 -0
  163. package/dist/esm/shib/types/common.d.ts.map +1 -0
  164. package/dist/esm/shib/types/common.js +1 -0
  165. package/dist/esm/shib/types/shibLogin.d.ts +62 -0
  166. package/dist/esm/shib/types/shibLogin.d.ts.map +1 -0
  167. package/dist/esm/shib/types/shibLogin.js +89 -0
  168. package/dist/esm/shib/types/shibUser.d.ts +36 -0
  169. package/dist/esm/shib/types/shibUser.d.ts.map +1 -0
  170. package/dist/esm/shib/types/shibUser.js +41 -0
  171. package/dist/esm/transports/fetch.d.ts +36 -0
  172. package/dist/esm/transports/fetch.d.ts.map +1 -0
  173. package/dist/esm/transports/fetch.js +80 -0
  174. package/dist/esm/types.d.ts +71 -0
  175. package/dist/esm/types.d.ts.map +1 -0
  176. package/dist/esm/types.js +8 -0
  177. package/package.json +72 -0
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.fetchTransport = exports.TimeoutError = exports.NetworkError = exports.ChukyoMaintenanceError = exports.ExpiredSessionError = exports.ParseError = exports.ChukyoSdkError = exports.createChukyoClient = void 0;
18
+ const client_1 = require("./cubics/client");
19
+ const client_2 = require("./albo/client");
20
+ const client_3 = require("./manabo/client");
21
+ /** SDK クライアントを生成する。 */
22
+ const createChukyoClient = (options) => {
23
+ const ctx = {
24
+ transport: options.transport,
25
+ ...(options.session ? { session: options.session } : {}),
26
+ };
27
+ return {
28
+ cubics: new client_1.CubicsClient(ctx),
29
+ albo: new client_2.AlboClient(ctx),
30
+ manabo: new client_3.ManaboClient(ctx),
31
+ };
32
+ };
33
+ exports.createChukyoClient = createChukyoClient;
34
+ // ---- エラー ----
35
+ var errors_1 = require("./errors");
36
+ Object.defineProperty(exports, "ChukyoSdkError", { enumerable: true, get: function () { return errors_1.ChukyoSdkError; } });
37
+ Object.defineProperty(exports, "ParseError", { enumerable: true, get: function () { return errors_1.ParseError; } });
38
+ Object.defineProperty(exports, "ExpiredSessionError", { enumerable: true, get: function () { return errors_1.ExpiredSessionError; } });
39
+ Object.defineProperty(exports, "ChukyoMaintenanceError", { enumerable: true, get: function () { return errors_1.ChukyoMaintenanceError; } });
40
+ Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_1.NetworkError; } });
41
+ Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
42
+ // ---- Transport Adapter ----
43
+ var fetch_1 = require("./transports/fetch");
44
+ Object.defineProperty(exports, "fetchTransport", { enumerable: true, get: function () { return fetch_1.fetchTransport; } });
45
+ // ---- ポータル別 parser / 型 / クライアント ----
46
+ __exportStar(require("./cubics/index"), exports);
47
+ __exportStar(require("./albo/index"), exports);
48
+ __exportStar(require("./manabo/index"), exports);
49
+ // ---- 認証フロー(Shibboleth)の構造化ヘルパ(実行はしない) ----
50
+ __exportStar(require("./shib/index"), exports);
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ManaboClient = void 0;
4
+ /**
5
+ * MaNaBo クライアント(Glexa ベース)。API は無く、トップページへの POST
6
+ * `action=glexa_ajax_*` で HTML 断片を取得してパースする。
7
+ *
8
+ * ※ レート制限(リクエスト間隔の間引き)は SDK では行わない。必要な場合は
9
+ * 利用側が Transport 内で適用すること(例: umebo は manabo ホスト宛のみ 500ms 間隔)。
10
+ */
11
+ const constants_1 = require("../constants");
12
+ const request_1 = require("../core/request");
13
+ const manaboClass_1 = require("./parser/manaboClass");
14
+ const manaboEntry_1 = require("./parser/manaboEntry");
15
+ const manaboMail_1 = require("./parser/manaboMail");
16
+ const manaboTimetable_1 = require("./parser/manaboTimetable");
17
+ class ManaboClient {
18
+ ctx;
19
+ constructor(ctx) {
20
+ this.ctx = ctx;
21
+ }
22
+ fetchText(path, init) {
23
+ return (0, request_1.portalRequestText)(this.ctx, constants_1.SERVICES.manabo, {
24
+ method: init?.method ?? "GET",
25
+ url: `${constants_1.MANABO_URLS.base}${path}`,
26
+ ...(init?.body != null ? { body: init.body } : {}),
27
+ ...(init?.headers ? { headers: init.headers } : {}),
28
+ });
29
+ }
30
+ /** トップページに `action=...` を POST して HTML 断片を得る */
31
+ postAction(params) {
32
+ return this.fetchText("/", {
33
+ method: "POST",
34
+ body: new URLSearchParams(params).toString(),
35
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
36
+ });
37
+ }
38
+ /** 時間割を取得する */
39
+ async getTimetable() {
40
+ return (0, request_1.unwrap)((0, manaboTimetable_1.parseManaboTimetable)(await this.postAction({ action: "glexa_ajax_timetable_view" })));
41
+ }
42
+ /** 授業のお知らせ一覧を取得する */
43
+ async getClassNews(classId) {
44
+ return (0, request_1.unwrap)((0, manaboClass_1.parseManaboClassNews)(await this.postAction({ class_id: classId, directory_id: "0", action: "glexa_ajax_class_news_list" })));
45
+ }
46
+ /** 授業のシラバスを取得する */
47
+ async getClassSyllabus(classId) {
48
+ return (0, request_1.unwrap)((0, manaboClass_1.parseManaboClassSyllabus)(await this.postAction({ class_id: classId, action: "glexa_ajax_class_syllabus_view" })));
49
+ }
50
+ /** 授業の出席表(各回の出欠一覧)を取得する */
51
+ async getClassEntry(classId) {
52
+ return (0, request_1.unwrap)((0, manaboClass_1.parseManaboClassEntry)(await this.fetchText(`/?class_id=${classId}&action=glexa_modal_entry_view&_=${Date.now()}`)));
53
+ }
54
+ /** 授業のディレクトリ(週・回)一覧を取得する */
55
+ async getClassDirectory(classId) {
56
+ return (0, request_1.unwrap)((0, manaboClass_1.parseManaboClassDirectory)(await this.postAction({ class_id: classId, directory_id: "0", action: "glexa_ajax_class_directory_list" })));
57
+ }
58
+ /** 授業のディレクトリ配下の教材一覧を取得する */
59
+ async getClassContent(classId, directoryId, viewType) {
60
+ return (0, request_1.unwrap)((0, manaboClass_1.parseManaboClassContent)(await this.postAction({
61
+ class_id: classId,
62
+ directory_id: directoryId,
63
+ action: "glexa_ajax_class_content_list",
64
+ ...(viewType ? { view_type: viewType } : {}),
65
+ })));
66
+ }
67
+ /**
68
+ * 出席受付モーダル(出欠カード)のフォームを取得する。
69
+ * 返り値の `requiresCode` が `true` なら出席コード(パスワード)が必要で、
70
+ * {@link submitEntry} の `code` に教員指示のコードを渡す。`false`(パスワードなし授業)
71
+ * なら `code` を省略してそのまま送信できる。
72
+ */
73
+ async getEntryForm(classId) {
74
+ return (0, request_1.unwrap)((0, manaboEntry_1.parseManaboEntryForm)(await this.fetchText(`/?class_id=${classId}&action=glexa_modal_entry_form&_=${Date.now()}`)));
75
+ }
76
+ /**
77
+ * 出席登録を送信する({@link getEntryForm} で取得した entryId / uniqid を渡す)。
78
+ * 出席コード(パスワード)必須の授業では `code` に教員指示のコードを渡す。
79
+ * パスワードなし授業では `code` を省略する。
80
+ */
81
+ async submitEntry(params) {
82
+ const query = new URLSearchParams({
83
+ action: "glexa_modal_entry_form_accept",
84
+ class_id: params.classId,
85
+ directory_id: params.directoryId,
86
+ entry_id: params.entryId,
87
+ uniqid: params.uniqid,
88
+ ...(params.code != null ? { code: params.code } : {}),
89
+ _: String(Date.now()),
90
+ });
91
+ return (0, request_1.unwrap)((0, manaboEntry_1.parseManaboEntryResponse)(await this.fetchText(`/?${query.toString()}`)));
92
+ }
93
+ /**
94
+ * 受信メール一覧を取得する。
95
+ * リクエスト形は glexa JS の `glexa.loadMailReceives(p, q, o, unread, start, end)` で確認済み。
96
+ * @param options.page ページ番号(1 始まり) / q 検索語 / order 並び順 / unreadOnly 未読のみ / startDate・endDate 期間(YYYY-MM-DD)
97
+ */
98
+ async getReceivedMail(options = {}) {
99
+ return (0, request_1.unwrap)((0, manaboMail_1.parseManaboReceivedMail)(await this.postAction({
100
+ action: "glexa_ajax_mail_receive_list",
101
+ ...(options.page != null ? { p: String(options.page) } : {}),
102
+ ...(options.q ? { q: options.q } : {}),
103
+ ...(options.order ? { o: options.order } : {}),
104
+ ...(options.unreadOnly ? { unread: "1" } : {}),
105
+ ...(options.startDate ? { start_date: options.startDate } : {}),
106
+ ...(options.endDate ? { end_date: options.endDate } : {}),
107
+ })));
108
+ }
109
+ /**
110
+ * 送信メール一覧を取得する。
111
+ * リクエスト形は glexa JS の `glexa.loadMailSends(p, q, o, start, end)` で確認済み。
112
+ */
113
+ async getSentMail(options = {}) {
114
+ return (0, request_1.unwrap)((0, manaboMail_1.parseManaboSentMail)(await this.postAction({
115
+ action: "glexa_ajax_mail_send_list",
116
+ ...(options.page != null ? { p: String(options.page) } : {}),
117
+ ...(options.q ? { q: options.q } : {}),
118
+ ...(options.order ? { o: options.order } : {}),
119
+ ...(options.startDate ? { start_date: options.startDate } : {}),
120
+ ...(options.endDate ? { end_date: options.endDate } : {}),
121
+ })));
122
+ }
123
+ /** メール本文(閲覧モーダル)を取得する */
124
+ async getMailView(mailId) {
125
+ return (0, request_1.unwrap)((0, manaboMail_1.parseManaboMailView)(await this.fetchText(`/?mail_id=${mailId}&action=glexa_modal_mail_view&_=${Date.now()}`)));
126
+ }
127
+ /**
128
+ * メール作成モーダルで宛先候補メンバーを検索する(`q` は氏名/学籍番号などの検索語)。
129
+ * リクエスト形は HAR 内の inline JS(`glexa.ajax({ action: 'glexa_modal_mail_ajax_member_list', params: { q } })`)で確認済み。
130
+ */
131
+ async searchMailMembers(q) {
132
+ return (0, request_1.unwrap)((0, manaboMail_1.parseManaboMailMember)(await this.postAction({ action: "glexa_modal_mail_ajax_member_list", q })));
133
+ }
134
+ }
135
+ exports.ManaboClient = ManaboClient;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ManaboClient = exports.parseManaboMailMember = exports.parseManaboMailSend = exports.parseManaboMailView = exports.parseManaboSentMail = exports.parseManaboReceivedMail = exports.parseManaboEntryResponse = exports.parseManaboEntryForm = exports.parseManaboClassQuizResult = exports.parseManaboClassSyllabus = exports.parseManaboClassNews = exports.parseManaboClassEntry = exports.parseManaboClassContent = exports.parseManaboClassDirectory = exports.parseManaboNews = exports.parseManaboTimetable = void 0;
18
+ var manaboTimetable_1 = require("./parser/manaboTimetable");
19
+ Object.defineProperty(exports, "parseManaboTimetable", { enumerable: true, get: function () { return manaboTimetable_1.parseManaboTimetable; } });
20
+ var manaboNews_1 = require("./parser/manaboNews");
21
+ Object.defineProperty(exports, "parseManaboNews", { enumerable: true, get: function () { return manaboNews_1.parseManaboNews; } });
22
+ var manaboClass_1 = require("./parser/manaboClass");
23
+ Object.defineProperty(exports, "parseManaboClassDirectory", { enumerable: true, get: function () { return manaboClass_1.parseManaboClassDirectory; } });
24
+ Object.defineProperty(exports, "parseManaboClassContent", { enumerable: true, get: function () { return manaboClass_1.parseManaboClassContent; } });
25
+ Object.defineProperty(exports, "parseManaboClassEntry", { enumerable: true, get: function () { return manaboClass_1.parseManaboClassEntry; } });
26
+ Object.defineProperty(exports, "parseManaboClassNews", { enumerable: true, get: function () { return manaboClass_1.parseManaboClassNews; } });
27
+ Object.defineProperty(exports, "parseManaboClassSyllabus", { enumerable: true, get: function () { return manaboClass_1.parseManaboClassSyllabus; } });
28
+ Object.defineProperty(exports, "parseManaboClassQuizResult", { enumerable: true, get: function () { return manaboClass_1.parseManaboClassQuizResult; } });
29
+ var manaboEntry_1 = require("./parser/manaboEntry");
30
+ Object.defineProperty(exports, "parseManaboEntryForm", { enumerable: true, get: function () { return manaboEntry_1.parseManaboEntryForm; } });
31
+ Object.defineProperty(exports, "parseManaboEntryResponse", { enumerable: true, get: function () { return manaboEntry_1.parseManaboEntryResponse; } });
32
+ var manaboMail_1 = require("./parser/manaboMail");
33
+ Object.defineProperty(exports, "parseManaboReceivedMail", { enumerable: true, get: function () { return manaboMail_1.parseManaboReceivedMail; } });
34
+ Object.defineProperty(exports, "parseManaboSentMail", { enumerable: true, get: function () { return manaboMail_1.parseManaboSentMail; } });
35
+ Object.defineProperty(exports, "parseManaboMailView", { enumerable: true, get: function () { return manaboMail_1.parseManaboMailView; } });
36
+ Object.defineProperty(exports, "parseManaboMailSend", { enumerable: true, get: function () { return manaboMail_1.parseManaboMailSend; } });
37
+ Object.defineProperty(exports, "parseManaboMailMember", { enumerable: true, get: function () { return manaboMail_1.parseManaboMailMember; } });
38
+ __exportStar(require("./types/manaboTimetable"), exports);
39
+ __exportStar(require("./types/manaboNews"), exports);
40
+ __exportStar(require("./types/manaboClass"), exports);
41
+ __exportStar(require("./types/manaboEntry"), exports);
42
+ __exportStar(require("./types/manaboMail"), exports);
43
+ var client_1 = require("./client");
44
+ Object.defineProperty(exports, "ManaboClient", { enumerable: true, get: function () { return client_1.ManaboClient; } });
@@ -0,0 +1,386 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseManaboClassQuizResult = exports.parseManaboClassSyllabus = exports.parseManaboClassNews = exports.parseManaboClassEntry = exports.parseManaboClassContent = exports.parseManaboClassDirectory = void 0;
4
+ const dom_1 = require("../../common/dom");
5
+ const utils_1 = require("../../common/utils");
6
+ const manaboClass_1 = require("../types/manaboClass");
7
+ const findNextMatchingSibling = (element, selector) => {
8
+ let next = (0, dom_1.nextSiblingElement)(element);
9
+ while (next) {
10
+ if ((0, dom_1.matches)(next, selector)) {
11
+ return next;
12
+ }
13
+ next = (0, dom_1.nextSiblingElement)(next);
14
+ }
15
+ return null;
16
+ };
17
+ const parseManaboClassDirectory = (html) => {
18
+ const document = (0, dom_1.loadDocument)(html);
19
+ const classNode = (0, dom_1.queryOne)(".class-top-directory .x-content-drop", document);
20
+ const classId = (0, dom_1.getAttribute)(classNode, "class_id") ?? "";
21
+ const className = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)((0, dom_1.queryOne)(".class-top-directory .span-class-name", document)));
22
+ const directories = (0, dom_1.queryAll)(".div-panel-directory li[directory_id]", document)
23
+ .map((node) => {
24
+ const directoryId = (0, dom_1.getAttribute)(node, "directory_id") ?? "";
25
+ const title = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)((0, dom_1.queryOne)(".x-directory-name", node)));
26
+ return { directoryId, title };
27
+ })
28
+ .filter((directory) => directory.directoryId.length > 0 && directory.title.length > 0);
29
+ return manaboClass_1.ManaboClassDirectorySchema.safeParse({ classId, className, directories });
30
+ };
31
+ exports.parseManaboClassDirectory = parseManaboClassDirectory;
32
+ const parseManaboClassContent = (html) => {
33
+ const document = (0, dom_1.loadDocument)(html);
34
+ const extractDurations = (context) => {
35
+ const containers = (0, dom_1.queryAll)(".div-small", context);
36
+ const durations = [];
37
+ containers.forEach((container) => {
38
+ const boldElements = (0, dom_1.queryAll)("b", container);
39
+ boldElements.forEach((bold) => {
40
+ const label = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(bold));
41
+ const valueFragments = [];
42
+ let current = bold.next;
43
+ while (current) {
44
+ if ((0, dom_1.isElement)(current) && current.name.toLowerCase() === "b") {
45
+ break;
46
+ }
47
+ if ((0, dom_1.isElement)(current)) {
48
+ const tagName = current.name.toLowerCase();
49
+ if (tagName === "br") {
50
+ valueFragments.push(" ");
51
+ }
52
+ else {
53
+ valueFragments.push((0, dom_1.getTextContent)(current));
54
+ }
55
+ }
56
+ else {
57
+ valueFragments.push((0, dom_1.getTextContent)(current));
58
+ }
59
+ current = current.next;
60
+ }
61
+ const value = (0, utils_1.normalizeWhitespace)(valueFragments.join(" "));
62
+ if (label.length > 0 || value.length > 0) {
63
+ durations.push({ label, value });
64
+ }
65
+ });
66
+ });
67
+ return durations;
68
+ };
69
+ const contents = [];
70
+ const rows = (0, dom_1.queryAll)(".table-class-content tbody tr", document);
71
+ rows.forEach((row) => {
72
+ if ((0, dom_1.matches)(row, ".toggle-area")) {
73
+ return;
74
+ }
75
+ const cells = (0, dom_1.queryAll)("td", row);
76
+ if (!cells.length) {
77
+ return;
78
+ }
79
+ const detailCell = cells[1];
80
+ const pluginIconWrapper = (0, dom_1.queryOne)(".plugin-icon-wrapper", row);
81
+ const pluginIconSrc = (0, dom_1.getAttribute)((0, dom_1.queryOne)(".plugin-icon", row), "src") ?? "";
82
+ const isIconChecked = (pluginIconWrapper?.attribs?.class ?? "")
83
+ .split(/\s+/)
84
+ .filter((value) => value.length > 0)
85
+ .includes("img-checked");
86
+ const icon = { pluginIconSrc, isIconChecked };
87
+ const isFileRow = !!detailCell?.attribs?.colspan && detailCell.attribs.colspan === "2";
88
+ if (isFileRow) {
89
+ const commentNode = (0, dom_1.queryOne)(".x-drag-title .cf", row);
90
+ const comment = commentNode ? (0, dom_1.getInnerHtml)(commentNode).trim() : "";
91
+ const files = (0, dom_1.queryAll)(".margin-top-md .display-block", row)
92
+ .map((block) => {
93
+ const link = (0, dom_1.queryOne)("a", block);
94
+ const fileName = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(link));
95
+ const href = (0, dom_1.getAttribute)(link, "href") ?? "";
96
+ const fileIcon = (0, dom_1.getAttribute)((0, dom_1.queryOne)("img.icon", block), "src") ?? "";
97
+ return { fileName, href, icon: fileIcon };
98
+ })
99
+ .filter((file) => file.fileName.length > 0 || file.href.length > 0 || file.icon.length > 0);
100
+ contents.push({
101
+ type: "resource",
102
+ icon,
103
+ attachedFile: { comment, files, duration: extractDurations(row) },
104
+ });
105
+ return;
106
+ }
107
+ const titleAnchor = (0, dom_1.queryOne)("a.a-content-open", row);
108
+ const titleElement = titleAnchor ?? (0, dom_1.queryOne)("b", row);
109
+ const title = titleElement ? (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(titleElement)) : "";
110
+ const contentId = titleAnchor ? ((0, dom_1.getAttribute)(titleAnchor, "content_id") ?? "") : "";
111
+ const pluginKey = titleAnchor ? ((0, dom_1.getAttribute)(titleAnchor, "plugin_key") ?? "") : "";
112
+ const duration = extractDurations(row);
113
+ const toggleRow = findNextMatchingSibling(row, ".toggle-area");
114
+ const toggleContainer = toggleRow ? ((0, dom_1.queryOne)(".x-content-hide", toggleRow) ?? toggleRow) : null;
115
+ const descriptionNode = toggleContainer ? (0, dom_1.queryOne)(".description", toggleContainer) : null;
116
+ const description = descriptionNode ? (0, dom_1.getInnerHtml)(descriptionNode).trim() : "";
117
+ const errorNodes = toggleContainer ? (0, dom_1.queryAll)(".confirm .error", toggleContainer) : [];
118
+ const errorMessages = errorNodes
119
+ .map((errorNode) => (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(errorNode)))
120
+ .filter((message) => message.length > 0);
121
+ const hasNotAvailableYetError = errorMessages.some((message) => message.includes("まだ受講できません"));
122
+ const isNotAvailableYet = hasNotAvailableYetError;
123
+ // 「まだ受講できません」は将来の受講可能通知として扱い、期限切れとは区別する。
124
+ const isExpired = errorNodes.length > 0 ? !hasNotAvailableYetError : false;
125
+ const actions = toggleContainer
126
+ ? (0, dom_1.queryAll)(".confirm a.btn", toggleContainer).map((actionNode) => ({
127
+ title: (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(actionNode)),
128
+ href: (0, dom_1.getAttribute)(actionNode, "href") ?? "",
129
+ }))
130
+ : [];
131
+ contents.push({
132
+ type: "activity",
133
+ icon,
134
+ content: { title, contentId, pluginKey, duration },
135
+ toggleArea: { description, isExpired, isNotAvailableYet, actions },
136
+ });
137
+ });
138
+ return manaboClass_1.ManaboClassContentSchema.safeParse({ contents });
139
+ };
140
+ exports.parseManaboClassContent = parseManaboClassContent;
141
+ const parseManaboClassEntry = (html) => {
142
+ const document = (0, dom_1.loadDocument)(html);
143
+ const rows = (0, dom_1.queryAll)("table.table-default tbody tr", document)
144
+ .filter((row) => {
145
+ const cells = (0, dom_1.queryAll)("td", row);
146
+ const hasColspan = cells.some((cell) => (0, dom_1.getAttribute)(cell, "colspan") !== null);
147
+ return !hasColspan;
148
+ })
149
+ .map((row) => {
150
+ const cells = (0, dom_1.queryAll)("td", row);
151
+ const directory = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cells[0] ?? null));
152
+ const lectureDateRaw = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cells[1] ?? null));
153
+ const status = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cells[2] ?? null));
154
+ return { directory, lectureDate: lectureDateRaw.length ? lectureDateRaw : null, status };
155
+ });
156
+ return manaboClass_1.ManaboClassEntrySchema.safeParse({ rows });
157
+ };
158
+ exports.parseManaboClassEntry = parseManaboClassEntry;
159
+ const parseManaboClassNews = (html) => {
160
+ const document = (0, dom_1.loadDocument)(html);
161
+ const items = (0, dom_1.queryAll)("dl.x-openclose", document).map((dl) => {
162
+ const title = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)((0, dom_1.queryOne)("dt b", dl)));
163
+ const bodyHtml = (0, dom_1.getInnerHtml)((0, dom_1.queryOne)("dd", dl)).trim() || "";
164
+ const id = (0, dom_1.getAttribute)(dl, "id");
165
+ const newsId = id ? id.replace(/^class-news-/, "") : null;
166
+ return { id, newsId, title, bodyHtml };
167
+ });
168
+ return manaboClass_1.ManaboClassNewsSchema.safeParse({ items });
169
+ };
170
+ exports.parseManaboClassNews = parseManaboClassNews;
171
+ const parseManaboClassSyllabus = (html) => {
172
+ const document = (0, dom_1.loadDocument)(html);
173
+ const mainTable = (0, dom_1.queryOne)(".panel-body .table.table-default", document);
174
+ const rows = mainTable ? (0, dom_1.queryAll)("tr", mainTable).filter((row) => (0, dom_1.closest)(row, "table") === mainTable) : [];
175
+ let object = "";
176
+ let goal = [];
177
+ let method = "";
178
+ let usedMethods = [];
179
+ let evaluation = [];
180
+ const textbooks = [];
181
+ let references = [];
182
+ let officeHour = "";
183
+ let plan = [];
184
+ let comment = "";
185
+ let prePostStudy = "";
186
+ const isDataNode = (node) => !!node && typeof node.data === "string";
187
+ const collectSiblingText = (element) => {
188
+ if (!element) {
189
+ return "";
190
+ }
191
+ const fragments = [];
192
+ let current = element.next;
193
+ while (current) {
194
+ if ((0, dom_1.isElement)(current)) {
195
+ if (current.name.toLowerCase() === "br") {
196
+ break;
197
+ }
198
+ fragments.push((0, dom_1.getTextContent)(current));
199
+ }
200
+ else if (isDataNode(current)) {
201
+ fragments.push(current.data);
202
+ }
203
+ current = current.next;
204
+ }
205
+ return (0, utils_1.normalizeWhitespace)(fragments.join(" "));
206
+ };
207
+ rows.forEach((row) => {
208
+ const heading = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)((0, dom_1.queryOne)("th", row)));
209
+ const cell = (0, dom_1.queryOne)("td", row);
210
+ switch (heading) {
211
+ case "授業概要・目的": {
212
+ object = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cell));
213
+ break;
214
+ }
215
+ case "学修到達目標": {
216
+ goal = (0, dom_1.queryAll)("li", cell)
217
+ .map((item) => (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(item)))
218
+ .filter((item) => item.length > 0);
219
+ break;
220
+ }
221
+ case "授業方法": {
222
+ method = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cell));
223
+ break;
224
+ }
225
+ case "活用される授業方法": {
226
+ usedMethods = (0, dom_1.queryAll)("input.usemethod[checked]", cell)
227
+ .map((input) => collectSiblingText(input))
228
+ .filter((value) => value.length > 0);
229
+ break;
230
+ }
231
+ case "成績評価方法・基準": {
232
+ evaluation = (0, dom_1.queryAll)("table tr", cell)
233
+ .map((evalRow) => {
234
+ const columns = (0, dom_1.queryAll)("td", evalRow);
235
+ const type = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(columns[0] ?? null));
236
+ const weight = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(columns[1] ?? null));
237
+ if (!type || !weight) {
238
+ return null;
239
+ }
240
+ return { type, weight };
241
+ })
242
+ .filter((item) => item !== null);
243
+ break;
244
+ }
245
+ case "教科書・教材・参考文献": {
246
+ (0, dom_1.queryAll)("table tr", cell).forEach((bookRow) => {
247
+ const cells = (0, dom_1.queryAll)("td", bookRow);
248
+ const label = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cells[0] ?? null));
249
+ const valueCell = cells[1] ?? null;
250
+ if (!valueCell) {
251
+ return;
252
+ }
253
+ if (label.includes("教科書・教材")) {
254
+ const title = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(valueCell));
255
+ if (title) {
256
+ textbooks.push({ type: label, title });
257
+ }
258
+ }
259
+ else if (label.includes("参考文献")) {
260
+ references = (0, dom_1.queryAll)("li", valueCell)
261
+ .map((item) => {
262
+ const title = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(item));
263
+ const code = (0, dom_1.getAttribute)(item, "data-code") ?? "";
264
+ if (!title || !code) {
265
+ return null;
266
+ }
267
+ return { title, code };
268
+ })
269
+ .filter((item) => item !== null);
270
+ }
271
+ });
272
+ break;
273
+ }
274
+ case "質問への対応(オフィスアワー等)": {
275
+ officeHour = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cell));
276
+ break;
277
+ }
278
+ case "授業計画": {
279
+ const planTable = (0, dom_1.queryOne)("table", cell);
280
+ plan = (0, dom_1.queryAll)("tbody tr", planTable)
281
+ .map((planRow) => {
282
+ const cols = (0, dom_1.queryAll)("td", planRow);
283
+ const noText = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cols[0] ?? null));
284
+ const item = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cols[1] ?? null));
285
+ const content = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cols[2] ?? null));
286
+ const no = Number.parseInt(noText, 10);
287
+ if (!Number.isFinite(no) || !item || !content) {
288
+ return null;
289
+ }
290
+ return { no, item, content };
291
+ })
292
+ .filter((entry) => entry !== null);
293
+ break;
294
+ }
295
+ case "履修者へのコメント": {
296
+ comment = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cell));
297
+ break;
298
+ }
299
+ case "事前事後学習": {
300
+ prePostStudy = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cell)).replace(/\s+\(/g, "(");
301
+ break;
302
+ }
303
+ default:
304
+ break;
305
+ }
306
+ });
307
+ return manaboClass_1.ManaboClassSyllabusSchema.safeParse({
308
+ object,
309
+ goal,
310
+ method,
311
+ usedMethods,
312
+ evaluation,
313
+ textbooks,
314
+ references,
315
+ officeHour,
316
+ plan,
317
+ comment,
318
+ prePostStudy,
319
+ });
320
+ };
321
+ exports.parseManaboClassSyllabus = parseManaboClassSyllabus;
322
+ const parseManaboClassQuizResult = (html) => {
323
+ const document = (0, dom_1.loadDocument)(html);
324
+ const scoreText = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)((0, dom_1.queryOne)(".text-center .Red b", document)));
325
+ const totalTextRaw = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)((0, dom_1.queryOne)(".text-center", document)));
326
+ const totalText = totalTextRaw.split("/")[1] ?? "0";
327
+ const obtained = Number(scoreText.replace(/[^\d]/g, "")) || 0;
328
+ const total = Number(totalText.replace(/[^\d]/g, "")) || 0;
329
+ const paginationSummary = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)((0, dom_1.queryOne)(".row.margin-top-md .col-sm-2", document)));
330
+ let currentPage = "";
331
+ const questions = (0, dom_1.queryAll)("table.table-default-grade tbody tr", document).map((row) => {
332
+ const cells = (0, dom_1.queryAll)("td", row);
333
+ let cellIndex = 0;
334
+ const firstCell = cells[cellIndex];
335
+ const firstCellRowspan = (0, dom_1.getAttribute)(firstCell, "rowspan");
336
+ const hasPageCell = (firstCellRowspan !== null && firstCellRowspan !== "1") || cells.length === 7;
337
+ if (hasPageCell) {
338
+ currentPage = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(firstCell));
339
+ cellIndex += 1;
340
+ }
341
+ const questionNumber = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cells[cellIndex] ?? null));
342
+ cellIndex += 1;
343
+ const questionCell = cells[cellIndex] ?? null;
344
+ const instruction = (0, dom_1.queryOne)(".div-instructions", questionCell ?? undefined);
345
+ const questionText = (0, utils_1.normalizeWhitespace)(instruction ? (0, dom_1.getTextContent)(instruction) : (0, dom_1.getTextContent)(questionCell));
346
+ cellIndex += 1;
347
+ const correctAnswer = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cells[cellIndex] ?? null));
348
+ cellIndex += 1;
349
+ const studentAnswer = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cells[cellIndex] ?? null));
350
+ cellIndex += 1;
351
+ const resultCell = cells[cellIndex] ?? null;
352
+ const resultIcon = (0, dom_1.queryOne)("img", resultCell ?? undefined);
353
+ const resultIconSrc = (0, dom_1.getAttribute)(resultIcon, "src");
354
+ const resultCellText = (0, dom_1.getTextContent)(resultCell);
355
+ const pointsMatch = resultCellText.match(/\d+/);
356
+ const points = pointsMatch ? Number.parseInt(pointsMatch[0], 10) : null;
357
+ let isCorrect = null;
358
+ if (resultIconSrc) {
359
+ if (resultIconSrc.includes("point_good")) {
360
+ isCorrect = true;
361
+ }
362
+ else if (resultIconSrc.includes("point_worst") || resultIconSrc.includes("point_bad")) {
363
+ isCorrect = false;
364
+ }
365
+ }
366
+ cellIndex += 1;
367
+ const teacherComment = (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(cells[cellIndex] ?? null));
368
+ return {
369
+ page: currentPage,
370
+ questionNumber,
371
+ questionText,
372
+ correctAnswer,
373
+ studentAnswer,
374
+ isCorrect,
375
+ points,
376
+ resultIconSrc,
377
+ teacherComment: teacherComment.length ? teacherComment : null,
378
+ };
379
+ });
380
+ return manaboClass_1.ManaboClassQuizResultSchema.safeParse({
381
+ score: { obtained, total },
382
+ paginationSummary: paginationSummary.length ? paginationSummary : null,
383
+ questions,
384
+ });
385
+ };
386
+ exports.parseManaboClassQuizResult = parseManaboClassQuizResult;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseManaboEntryResponse = exports.parseManaboEntryForm = void 0;
4
+ const dom_1 = require("../../common/dom");
5
+ const utils_1 = require("../../common/utils");
6
+ const manaboEntry_1 = require("../types/manaboEntry");
7
+ const parseManaboEntryForm = (html) => {
8
+ const document = (0, dom_1.loadDocument)(html);
9
+ const form = (0, dom_1.queryOne)("#form-entry", document);
10
+ const messages = form
11
+ ? (0, dom_1.queryAll)("p", form)
12
+ .map((element) => (0, utils_1.normalizeWhitespace)((0, dom_1.getTextContent)(element)))
13
+ .filter((message) => message.length > 0)
14
+ : [];
15
+ return manaboEntry_1.ManaboEntryFormSchema.safeParse({
16
+ action: (0, dom_1.getAttribute)((0, dom_1.queryOne)('input[name="action"]', form), "value") ?? "",
17
+ classId: (0, dom_1.getAttribute)((0, dom_1.queryOne)('input[name="class_id"]', form), "value") ?? "",
18
+ directoryId: (0, dom_1.getAttribute)((0, dom_1.queryOne)('input[name="directory_id"]', form), "value") ?? "",
19
+ entryId: (0, dom_1.getAttribute)((0, dom_1.queryOne)('input[name="entry_id"]', form), "value") ?? "",
20
+ uniqid: (0, dom_1.getAttribute)((0, dom_1.queryOne)('input[name="uniqid"]', form), "value") ?? "",
21
+ // 出席コード(パスワード)入力欄の有無で必須かを判定する。
22
+ // パスワードなし授業ではこの input が存在しない。
23
+ requiresCode: (0, dom_1.queryOne)('input[name="code"]', form) != null,
24
+ messages,
25
+ });
26
+ };
27
+ exports.parseManaboEntryForm = parseManaboEntryForm;
28
+ const parseManaboEntryResponse = (json) => {
29
+ let parsed;
30
+ try {
31
+ parsed = JSON.parse(json);
32
+ }
33
+ catch {
34
+ parsed = undefined;
35
+ }
36
+ return manaboEntry_1.ManaboEntryResponseSchema.safeParse(parsed);
37
+ };
38
+ exports.parseManaboEntryResponse = parseManaboEntryResponse;