@clawdao/limschain-agent 0.5.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 (64) hide show
  1. package/.env.example +41 -0
  2. package/CHANGELOG.md +223 -0
  3. package/Dockerfile +50 -0
  4. package/LICENSE +21 -0
  5. package/README.md +627 -0
  6. package/bin/lims-mcp.mjs +101 -0
  7. package/bin/lims.mjs +1639 -0
  8. package/docs/MARKETPLACE-GUIDELINES.md +99 -0
  9. package/docs/clawdao-mcp-listing.md +308 -0
  10. package/docs/clawdao-mcp-setup.md +294 -0
  11. package/docs/ddn-hub-postType-issue.md +54 -0
  12. package/docs/deploy-http.md +192 -0
  13. package/docs/install-mcp.md +268 -0
  14. package/docs/limschain-migration-and-readme-backfill.md +212 -0
  15. package/docs/marketplace-readmes/clawdao-video-factory.md +49 -0
  16. package/docs/node-free-install.md +196 -0
  17. package/docs/release-notes/v1.0.30-short.md +63 -0
  18. package/docs/site-design-studio-api.md +162 -0
  19. package/lib/articles.mjs +397 -0
  20. package/lib/client.mjs +588 -0
  21. package/lib/courses.mjs +169 -0
  22. package/lib/dao.mjs +195 -0
  23. package/lib/env.mjs +32 -0
  24. package/lib/feedback.mjs +68 -0
  25. package/lib/http-server.mjs +257 -0
  26. package/lib/marketplace-readme-path.mjs +17 -0
  27. package/lib/marketplace.mjs +273 -0
  28. package/lib/materials.mjs +260 -0
  29. package/lib/mcp-server.mjs +334 -0
  30. package/lib/site.mjs +471 -0
  31. package/lib/versions.mjs +904 -0
  32. package/mcp-listing.http.json +25 -0
  33. package/mcp-listing.json +34 -0
  34. package/package.json +77 -0
  35. package/scripts/build-binary.mjs +104 -0
  36. package/scripts/build-site-dashboard.mjs +52 -0
  37. package/scripts/collect-site-articles.mjs +432 -0
  38. package/scripts/export-ddn-env.mjs +107 -0
  39. package/scripts/fetch-article-stats.mjs +212 -0
  40. package/scripts/pack-and-verify.mjs +111 -0
  41. package/scripts/publisher.mjs +255 -0
  42. package/scripts/sync-marketplace-readme.mjs +380 -0
  43. package/scripts/tool-set.mjs +48 -0
  44. package/scripts/verify-binary.mjs +115 -0
  45. package/scripts/verify-clawdao-bridge.mjs +41 -0
  46. package/scripts/verify-e2e.mjs +176 -0
  47. package/scripts/verify-http-mcp.mjs +94 -0
  48. package/scripts/verify-listing-sync.mjs +90 -0
  49. package/scripts/verify-marketplace-readme.mjs +266 -0
  50. package/scripts/verify-mcp-handshake.mjs +98 -0
  51. package/scripts/verify-news-publish.mjs +257 -0
  52. package/scripts/verify-npx-install.mjs +171 -0
  53. package/scripts/verify-site-dashboard.mjs +87 -0
  54. package/scripts/verify-site-layout.mjs +194 -0
  55. package/tests/client-auth.test.mjs +159 -0
  56. package/tests/dao-profile.test.mjs +126 -0
  57. package/tests/marketplace-readme-path.test.mjs +16 -0
  58. package/tests/mcp-server.test.mjs +187 -0
  59. package/tests/member-submission.test.mjs +150 -0
  60. package/tests/official-listing.test.mjs +52 -0
  61. package/tests/smoke.mjs +262 -0
  62. package/tests/sync-marketplace-readme.test.mjs +50 -0
  63. package/tests/tool-set.test.mjs +54 -0
  64. package/tests/versions-sync-dryrun.test.mjs +315 -0
package/lib/client.mjs ADDED
@@ -0,0 +1,588 @@
1
+ /**
2
+ * 亿检链 API 客户端
3
+ * 基于 ddn-hub-mcp 的 client.mjs 封装,提供统一的 API 调用能力
4
+ */
5
+
6
+ import { readFileSync } from 'node:fs';
7
+
8
+ import './env.mjs'; // ★ 载入仓库根 .env(DDN_HUB_AUTH_TOKEN 等),保证脚本/CLI 行为一致
9
+
10
+ /** 包版本号 —— 从 package.json 读,避免与 npm 元数据漂移(读不到就用兜底)。 */
11
+ function packageVersion() {
12
+ try {
13
+ const raw = readFileSync(new URL('../package.json', import.meta.url), 'utf-8');
14
+ const v = JSON.parse(raw)?.version;
15
+ if (typeof v === 'string' && v) return v;
16
+ } catch { /* 读不到就用兜底 */ }
17
+ return '0.2.0';
18
+ }
19
+
20
+ const USER_AGENT = `@lims/lims-agent/${packageVersion()}`;
21
+ const DEFAULT_BASE_URL = 'https://limschain.com';
22
+ const DEFAULT_TIMEOUT_MS = 30000;
23
+
24
+ /**
25
+ * ddn-hub「API 访问令牌」的前缀(服务端约定,见 ddn-hub
26
+ * `server/app/middleware/auth/apiAccessToken.js` 的 TOKEN_PREFIX)。
27
+ *
28
+ * ⭐ 两类凭证在 appAuth 里走**同一条**认证通道(`Authorization: Bearer <token>`):
29
+ * - `session_jwt`:网页端登录后的会话 JWT,**会过期**(实测本仓 .env 里的那张 2 小时就失效了)
30
+ * - `api_token` :`jzd_<prefix8>_<secret64>`,用户自助签发、可吊销、可绑 DAO、**不过期**
31
+ * ⇒ 客户端只靠前缀区分两者,好在不引入任何额外配置项。
32
+ */
33
+ const API_TOKEN_PREFIX = 'jzd_';
34
+
35
+ /** 是不是 API 访问令牌(而非会话 JWT) */
36
+ export const isApiToken = (token) => typeof token === 'string' && token.startsWith(API_TOKEN_PREFIX);
37
+
38
+ const trimToUndefined = (value) => {
39
+ if (typeof value !== 'string') return undefined;
40
+ const trimmed = value.trim();
41
+ return trimmed.length > 0 ? trimmed : undefined;
42
+ };
43
+
44
+ const normalizeBaseUrl = (value) => {
45
+ const rawValue = trimToUndefined(value);
46
+ const baseUrl = rawValue || DEFAULT_BASE_URL;
47
+ try {
48
+ const normalized = new URL(baseUrl);
49
+ normalized.pathname = normalized.pathname.replace(/\/+$/, '') || '/';
50
+ return {
51
+ baseUrl: normalized.toString().replace(/\/$/, ''),
52
+ baseUrlValid: true,
53
+ baseUrlError: null,
54
+ };
55
+ } catch (error) {
56
+ return {
57
+ baseUrl,
58
+ baseUrlValid: false,
59
+ baseUrlError: error instanceof Error ? error.message : String(error),
60
+ };
61
+ }
62
+ };
63
+
64
+ const createTimeoutController = (timeoutMs) => {
65
+ const controller = new AbortController();
66
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
67
+ return { signal: controller.signal, cleanup: () => clearTimeout(timer) };
68
+ };
69
+
70
+ const appendQuery = (url, query = {}) => {
71
+ for (const [key, value] of Object.entries(query)) {
72
+ if (value === undefined || value === null || value === '') continue;
73
+ if (Array.isArray(value)) {
74
+ for (const item of value) url.searchParams.append(key, String(item));
75
+ continue;
76
+ }
77
+ url.searchParams.set(key, String(value));
78
+ }
79
+ };
80
+
81
+ const extractMessage = (body, fallback) => {
82
+ if (body && typeof body === 'object' && !Array.isArray(body)) {
83
+ const candidates = [body.msg, body.message, body.error];
84
+ for (const c of candidates) {
85
+ if (typeof c === 'string' && c.trim().length > 0) return c.trim();
86
+ }
87
+ }
88
+ return fallback;
89
+ };
90
+
91
+ const extractData = (body) => {
92
+ if (body && typeof body === 'object' && !Array.isArray(body) && 'data' in body) return body.data;
93
+ return body;
94
+ };
95
+
96
+ const parseResponseBody = async (response) => {
97
+ const text = await response.text();
98
+ if (!text) return { text: '', body: null };
99
+ try { return { text, body: JSON.parse(text) }; }
100
+ catch { return { text, body: null }; }
101
+ };
102
+
103
+ const buildHeaders = (opts) => {
104
+ const headers = {
105
+ Accept: 'application/json',
106
+ 'User-Agent': USER_AGENT,
107
+ };
108
+ if (opts.jsonBody) headers['Content-Type'] = 'application/json';
109
+ if (opts.authToken) headers.Authorization = `Bearer ${opts.authToken}`;
110
+ if (opts.daoId) {
111
+ headers['X-Dao-Id'] = opts.daoId;
112
+ headers['x-dao-id'] = opts.daoId;
113
+ }
114
+ // ★ 平台作用域声明头:平台后台(/platform)发起的请求会带这个头。
115
+ // 服务端 appAuth 只把它当「请求声明」,真正的放行条件是 isSystemAdmin
116
+ // (非平台管理员带这个头不会多出任何权限)。
117
+ // 用途:`product/versions` 这类**平台级**端点的权限码是租户域码
118
+ // (product:version:create 属于 daoCreator/daoAdmin 角色),
119
+ // 平台管理员在当前 DAO 里是成员身份 ⇒ 不带这个头会被 403。
120
+ if (opts.platformScope) headers['X-Platform-Scope'] = '1';
121
+ return headers;
122
+ };
123
+
124
+ export class LimsClient {
125
+ #config;
126
+
127
+ constructor(config = {}) {
128
+ const baseUrlState = normalizeBaseUrl(config.baseUrl || process.env.DDN_HUB_BASE_URL);
129
+ const authToken = trimToUndefined(
130
+ config.authToken || process.env.DDN_HUB_AUTH_TOKEN || process.env.DDN_HUB_API_KEY,
131
+ ) || null;
132
+ this.#config = {
133
+ ...baseUrlState,
134
+ authToken,
135
+ // ★ 平台级 token(product/versions 等平台级操作)
136
+ platformToken: trimToUndefined(config.platformToken || process.env.DDN_HUB_PLATFORM_TOKEN) || null,
137
+ // ★ 平台作用域声明(默认关闭):DDN_HUB_PLATFORM_SCOPE=1 时,
138
+ // 平台级请求(platformToken: true)会带 X-Platform-Scope: 1 头。
139
+ platformScope: config.platformScope ?? (process.env.DDN_HUB_PLATFORM_SCOPE === '1'),
140
+ daoId: trimToUndefined(config.daoId || process.env.DDN_HUB_DAO_ID) || null,
141
+ timeoutMs: config.timeoutMs || DEFAULT_TIMEOUT_MS,
142
+ // ★ 凭证种类:api_token(jzd_,推荐)还是 session_jwt(会过期)。
143
+ // 决定「DAO id 能不能省」——api_token 可绑 DAO,服务端会自动注入。
144
+ credentialKind: isApiToken(authToken) ? 'api_token' : 'session_jwt',
145
+ };
146
+ }
147
+
148
+ getConfig() {
149
+ return { ...this.#config };
150
+ }
151
+
152
+ getRuntimeSnapshot() {
153
+ const c = this.#config;
154
+ return {
155
+ baseUrl: c.baseUrl,
156
+ baseUrlValid: c.baseUrlValid,
157
+ timeoutMs: c.timeoutMs,
158
+ hasAuthToken: Boolean(c.authToken),
159
+ hasPlatformToken: Boolean(c.platformToken),
160
+ platformScope: Boolean(c.platformScope),
161
+ hasDaoId: Boolean(c.daoId),
162
+ daoId: c.daoId,
163
+ credentialKind: c.credentialKind,
164
+ };
165
+ }
166
+
167
+ /**
168
+ * 探明当前凭证对应的 DAO id(**只对 API 访问令牌有意义**)。
169
+ *
170
+ * ⭐ 为什么需要它:API 访问令牌可以在签发时绑定 DAO(ddn-hub
171
+ * `app/service/user/api_access_token.js` 的 `daoId`),绑定后
172
+ * 服务端的 appAuth 会把 `ctx.state.currentDao` 直接注入 ⇒
173
+ * **客户端不需要知道 DAO id**(实测:不带 X-Dao-Id 也能正常读文章)。
174
+ * 而会话 JWT 没有这个绑定 ⇒ 仍需显式配置 DDN_HUB_DAO_ID。
175
+ *
176
+ * 探测方式:打一个只读端点,从响应信封的 `currentDao.id` 里读服务端认定的 DAO。
177
+ * 失败一律返回 null(让上层按「缺 DAO」报错,不猜)。
178
+ */
179
+ async #discoverDaoId() {
180
+ if (this.#config.daoId) return this.#config.daoId;
181
+ if (!this.#config.authToken) return null;
182
+ if (this.#config.credentialKind !== 'api_token') return null;
183
+ try {
184
+ const response = await fetch(new URL('/api/v1/user/daos', this.#config.baseUrl), {
185
+ method: 'GET',
186
+ headers: buildHeaders({ authToken: this.#config.authToken }),
187
+ signal: AbortSignal.timeout(this.#config.timeoutMs),
188
+ });
189
+ if (!response.ok) return null;
190
+ const body = await response.json();
191
+ const id = body?.currentDao?.id;
192
+ if (typeof id === 'string' && id.trim().length > 0) {
193
+ this.#config.daoId = id.trim();
194
+ return this.#config.daoId;
195
+ }
196
+ } catch { /* 探测失败不当成致命错误:上层会给出可操作的提示 */ }
197
+ return null;
198
+ }
199
+
200
+ /**
201
+ * 公开入口:拿到「当前生效的 DAO id」,必要时自动探测。
202
+ * 供需要 DAO id 的管理器(如 DAO 档案)在发请求前调用。
203
+ */
204
+ async ensureDaoId() {
205
+ return await this.#discoverDaoId();
206
+ }
207
+
208
+ async request({ method, path, query, body, authRequired = false, daoRequired = false, daoId, platformToken = false }) {
209
+ if (!this.#config.baseUrlValid) {
210
+ return this.#fail('config_error', `DDN_HUB_BASE_URL 无效: ${this.#config.baseUrlError}`);
211
+ }
212
+
213
+ // ★ platformToken = true 时使用 DDN_HUB_PLATFORM_TOKEN(平台级权限)
214
+ const authToken = platformToken ? (this.#config.platformToken || this.#config.authToken) : this.#config.authToken;
215
+ if (authRequired && !authToken) {
216
+ return this.#fail('config_error', platformToken
217
+ ? '需要 DDN_HUB_PLATFORM_TOKEN 或 DDN_HUB_AUTH_TOKEN 才能调用此平台级工具'
218
+ : '需要 DDN_HUB_AUTH_TOKEN(或 DDN_HUB_API_KEY)才能调用此工具');
219
+ }
220
+
221
+ let resolvedDaoId = trimToUndefined(daoId) || this.#config.daoId;
222
+ if (daoRequired && !resolvedDaoId) {
223
+ // ★ API 访问令牌(jzd_)可能自带 DAO 绑定 ⇒ 先探一次,别急着报错。
224
+ resolvedDaoId = await this.#discoverDaoId();
225
+ }
226
+ if (daoRequired && !resolvedDaoId) {
227
+ return this.#fail('config_error', '需要 DDN_HUB_DAO_ID 才能调用此工具(API 访问令牌未绑定 DAO 时必须显式指定)');
228
+ }
229
+
230
+ // ★ 如果提供了 authToken 覆盖(如 platformToken),使用它
231
+ const finalAuthToken = authToken || this.#config.authToken;
232
+ // ★ 平台作用域头:**只**给平台级请求(platformToken: true),
233
+ // 且需要显式开启(DDN_HUB_PLATFORM_SCOPE=1)。
234
+ const usePlatformScope = Boolean(platformToken) && Boolean(this.#config.platformScope);
235
+ if (authRequired && !finalAuthToken) {
236
+ return this.#fail('config_error', '需要鉴权 token(DDN_HUB_AUTH_TOKEN 或 DDN_HUB_PLATFORM_TOKEN)');
237
+ }
238
+
239
+ const url = new URL(path, this.#config.baseUrl);
240
+ appendQuery(url, query);
241
+
242
+ const { signal, cleanup } = createTimeoutController(this.#config.timeoutMs);
243
+
244
+ try {
245
+ const response = await fetch(url, {
246
+ method,
247
+ headers: buildHeaders({
248
+ // ★ 修复:用 finalAuthToken(已根据 platformToken 选项选好 token),而不是固定 authToken
249
+ authToken: finalAuthToken,
250
+ daoId: resolvedDaoId,
251
+ jsonBody: body !== undefined,
252
+ platformScope: usePlatformScope,
253
+ }),
254
+ body: body === undefined ? undefined : JSON.stringify(body),
255
+ signal,
256
+ });
257
+
258
+ const parsed = await parseResponseBody(response);
259
+
260
+ // ★ 记住服务端认定的 currentDao:下一次请求就能带上 X-Dao-Id,
261
+ // 也让「DAO id 可省略」这件事在整条链路上成立(不必每次重新探测)。
262
+ if (!this.#config.daoId) {
263
+ const currentDaoId = parsed.body?.currentDao?.id;
264
+ if (typeof currentDaoId === 'string' && currentDaoId.trim().length > 0) {
265
+ this.#config.daoId = currentDaoId.trim();
266
+ }
267
+ }
268
+
269
+ const message = extractMessage(
270
+ parsed.body,
271
+ response.ok ? '请求成功' : `请求失败,状态码 ${response.status}`
272
+ );
273
+ const data = extractData(parsed.body);
274
+
275
+ if (!response.ok) {
276
+ return this.#fail('http_error', message, response.status, data, parsed.body || parsed.text);
277
+ }
278
+
279
+ // 后端业务错误检测(status: 1)
280
+ if (parsed.body && typeof parsed.body === 'object' && parsed.body.status === 1) {
281
+ return this.#fail('business_error', message, response.status, data, parsed.body);
282
+ }
283
+
284
+ return { ok: true, statusCode: response.status, message, data };
285
+ } catch (error) {
286
+ const aborted = error instanceof Error && error.name === 'AbortError';
287
+ return this.#fail(
288
+ aborted ? 'timeout' : 'network_error',
289
+ aborted ? `请求超时 (${this.#config.timeoutMs}ms)` : (error instanceof Error ? error.message : String(error))
290
+ );
291
+ } finally {
292
+ cleanup();
293
+ }
294
+ }
295
+
296
+ #fail(kind, message, statusCode = null, data = null, raw = null) {
297
+ return {
298
+ ok: false,
299
+ statusCode,
300
+ message,
301
+ data,
302
+ error: { kind, message, statusCode },
303
+ };
304
+ }
305
+
306
+ // ===== 文章/内容操作 =====
307
+
308
+ /** 获取文章列表 */
309
+ async listPosts(params = {}) {
310
+ return this.request({
311
+ method: 'GET',
312
+ path: '/api/v1/posts',
313
+ query: params,
314
+ });
315
+ }
316
+
317
+ /** 获取文章详情 */
318
+ async getPost(postId) {
319
+ return this.request({
320
+ method: 'GET',
321
+ path: `/api/v1/posts/${postId}`,
322
+ });
323
+ }
324
+
325
+ /** 创建文章 */
326
+ async createPost(body, daoId) {
327
+ return this.request({
328
+ method: 'POST',
329
+ path: '/api/v1/posts',
330
+ authRequired: true,
331
+ daoRequired: true,
332
+ daoId,
333
+ body,
334
+ });
335
+ }
336
+
337
+ /**
338
+ * 🔧 2026-11-27(plan fix-08):列出**当前组织**的分类树。
339
+ *
340
+ * ── 为什么必须有这个能力 ────────────────────────────────────────────────
341
+ * 文章挂在哪个分类(categoryId)决定了它出现在前台哪个栏目。
342
+ * 智能体要「发布到某个组织下的某个类别」,就需要**知道那个组织有哪些合法 categoryId**。
343
+ * 此前这个包**没有任何列分类的能力** ⇒ 智能体只能靠猜 categoryId
344
+ * (或者用户口头给一个数字)⇒ 结果要么发错栏目,要么发不进去。
345
+ */
346
+ async listCategories(daoId) {
347
+ return this.request({
348
+ method: 'GET',
349
+ path: '/api/v1/cms/public/categories',
350
+ authRequired: false,
351
+ daoRequired: false,
352
+ daoId,
353
+ });
354
+ }
355
+
356
+ /** 更新文章 */
357
+ async updatePost(postId, body) {
358
+ return this.request({
359
+ method: 'PUT',
360
+ path: `/api/v1/posts/${postId}`,
361
+ authRequired: true,
362
+ daoRequired: true,
363
+ body,
364
+ });
365
+ }
366
+
367
+ /** 发布文章 */
368
+ async publishPost(postId, daoId) {
369
+ return this.request({
370
+ method: 'POST',
371
+ path: `/api/v1/posts/${postId}/publish`,
372
+ authRequired: true,
373
+ daoRequired: true,
374
+ daoId,
375
+ });
376
+ }
377
+
378
+ /** 删除文章 */
379
+ async deletePost(postId) {
380
+ return this.request({
381
+ method: 'DELETE',
382
+ path: `/api/v1/posts/${postId}`,
383
+ authRequired: true,
384
+ daoRequired: true,
385
+ });
386
+ }
387
+
388
+ // ===== 平台侧文章操作(/api/v1/platform/posts)=====
389
+ // 租户侧 publish / update / delete 需要 cms:posts:update 等权限;
390
+ // 平台管理员账号在「当前 DAO」里往往只是成员身份(roleLabel=DAO成员),
391
+ // 这时会 403「权限不足:需要「更新内容」权限」。
392
+ // 平台侧走 platform:posts:manage(系统管理员自带),是官方后台同一套接口。
393
+
394
+ /** 平台侧读取文章详情 */
395
+ async platformGetPost(postId) {
396
+ return this.request({
397
+ method: 'GET',
398
+ path: `/api/v1/platform/posts/${postId}`,
399
+ authRequired: true,
400
+ platformToken: true,
401
+ });
402
+ }
403
+
404
+ /** 平台侧更新文章(含 extraData 等扩展属性) */
405
+ async platformUpdatePost(postId, body) {
406
+ return this.request({
407
+ method: 'PUT',
408
+ path: `/api/v1/platform/posts/${postId}`,
409
+ authRequired: true,
410
+ platformToken: true,
411
+ body,
412
+ });
413
+ }
414
+
415
+ /** 平台侧审核文章(action: approved / rejected) */
416
+ async platformReviewPost(postId, body = {}) {
417
+ return this.request({
418
+ method: 'POST',
419
+ path: `/api/v1/platform/posts/review/${postId}`,
420
+ authRequired: true,
421
+ platformToken: true,
422
+ body,
423
+ });
424
+ }
425
+
426
+ /** 平台侧改文章状态(走两轴状态机:approved 才能 published) */
427
+ async platformUpdatePostStatus(postId, status, reason) {
428
+ return this.request({
429
+ method: 'PUT',
430
+ path: `/api/v1/platform/posts/${postId}/status`,
431
+ authRequired: true,
432
+ platformToken: true,
433
+ query: { status, reason },
434
+ });
435
+ }
436
+
437
+ // ===== 用户投稿操作 =====
438
+
439
+ /** 获取用户投稿列表 */
440
+ async listUserContributions(params = {}) {
441
+ return this.request({
442
+ method: 'GET',
443
+ path: '/api/v1/cms/user/posts',
444
+ authRequired: true,
445
+ daoRequired: true,
446
+ query: params,
447
+ });
448
+ }
449
+
450
+ /** 创建投稿 */
451
+ async createContribution(postId, body = {}) {
452
+ return this.request({
453
+ method: 'POST',
454
+ path: `/api/v1/cms/user/posts/${postId}/contributions`,
455
+ authRequired: true,
456
+ daoRequired: true,
457
+ body,
458
+ });
459
+ }
460
+
461
+ // ===== 课程操作 =====
462
+
463
+ /** 获取已发布课程列表 */
464
+ async listPublishedCourses(params = {}) {
465
+ return this.request({
466
+ method: 'GET',
467
+ path: '/api/v1/course/courses/published',
468
+ query: params,
469
+ });
470
+ }
471
+
472
+ /** 获取课程列表(管理端) */
473
+ async listCourses(params = {}) {
474
+ return this.request({
475
+ method: 'GET',
476
+ path: '/api/v1/course/courses',
477
+ authRequired: true,
478
+ daoRequired: true,
479
+ query: params,
480
+ });
481
+ }
482
+
483
+ /** 获取课程详情 */
484
+ async getCourse(courseId) {
485
+ return this.request({
486
+ method: 'GET',
487
+ path: `/api/v1/course/courses/${courseId}`,
488
+ });
489
+ }
490
+
491
+ /** 创建课程 */
492
+ async createCourse(body) {
493
+ return this.request({
494
+ method: 'POST',
495
+ path: '/api/v1/course/courses',
496
+ authRequired: true,
497
+ daoRequired: true,
498
+ body,
499
+ });
500
+ }
501
+
502
+ /** 更新课程 */
503
+ async updateCourse(courseId, body) {
504
+ return this.request({
505
+ method: 'PUT',
506
+ path: `/api/v1/course/courses/${courseId}`,
507
+ authRequired: true,
508
+ daoRequired: true,
509
+ body,
510
+ });
511
+ }
512
+
513
+ /** 删除课程 */
514
+ async deleteCourse(courseId) {
515
+ return this.request({
516
+ method: 'DELETE',
517
+ path: `/api/v1/course/courses/${courseId}`,
518
+ authRequired: true,
519
+ daoRequired: true,
520
+ });
521
+ }
522
+
523
+ /** 更新课程状态 */
524
+ async updateCourseStatus(courseId, status) {
525
+ return this.request({
526
+ method: 'PUT',
527
+ path: `/api/v1/course/courses/${courseId}/status`,
528
+ authRequired: true,
529
+ daoRequired: true,
530
+ body: { status },
531
+ });
532
+ }
533
+
534
+ // ===== 课程分类操作 =====
535
+
536
+ /** 获取课程分类列表 */
537
+ async listCourseCategories(params = {}) {
538
+ return this.request({
539
+ method: 'GET',
540
+ path: '/api/v1/course/categories',
541
+ query: params,
542
+ });
543
+ }
544
+
545
+ /** 创建课程分类 */
546
+ async createCourseCategory(body) {
547
+ return this.request({
548
+ method: 'POST',
549
+ path: '/api/v1/course/categories',
550
+ authRequired: true,
551
+ daoRequired: true,
552
+ body,
553
+ });
554
+ }
555
+
556
+ // ===== 课程评价操作 =====
557
+
558
+ /** 获取课程评价列表 */
559
+ async listCourseReviews(params = {}) {
560
+ return this.request({
561
+ method: 'GET',
562
+ path: '/api/v1/course/reviews',
563
+ query: params,
564
+ });
565
+ }
566
+
567
+ /** 创建课程评价 */
568
+ async createCourseReview(body) {
569
+ return this.request({
570
+ method: 'POST',
571
+ path: '/api/v1/course/reviews',
572
+ authRequired: true,
573
+ body,
574
+ });
575
+ }
576
+
577
+ // ===== 系统/通用操作 =====
578
+
579
+ /** 健康检查 */
580
+ async healthCheck() {
581
+ return this.request({ method: 'GET', path: '/api/health' });
582
+ }
583
+
584
+ /** 获取系统配置 */
585
+ async getPublicConfig() {
586
+ return this.request({ method: 'GET', path: '/api/v1/public/config' });
587
+ }
588
+ }