@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.
- package/.env.example +41 -0
- package/CHANGELOG.md +223 -0
- package/Dockerfile +50 -0
- package/LICENSE +21 -0
- package/README.md +627 -0
- package/bin/lims-mcp.mjs +101 -0
- package/bin/lims.mjs +1639 -0
- package/docs/MARKETPLACE-GUIDELINES.md +99 -0
- package/docs/clawdao-mcp-listing.md +308 -0
- package/docs/clawdao-mcp-setup.md +294 -0
- package/docs/ddn-hub-postType-issue.md +54 -0
- package/docs/deploy-http.md +192 -0
- package/docs/install-mcp.md +268 -0
- package/docs/limschain-migration-and-readme-backfill.md +212 -0
- package/docs/marketplace-readmes/clawdao-video-factory.md +49 -0
- package/docs/node-free-install.md +196 -0
- package/docs/release-notes/v1.0.30-short.md +63 -0
- package/docs/site-design-studio-api.md +162 -0
- package/lib/articles.mjs +397 -0
- package/lib/client.mjs +588 -0
- package/lib/courses.mjs +169 -0
- package/lib/dao.mjs +195 -0
- package/lib/env.mjs +32 -0
- package/lib/feedback.mjs +68 -0
- package/lib/http-server.mjs +257 -0
- package/lib/marketplace-readme-path.mjs +17 -0
- package/lib/marketplace.mjs +273 -0
- package/lib/materials.mjs +260 -0
- package/lib/mcp-server.mjs +334 -0
- package/lib/site.mjs +471 -0
- package/lib/versions.mjs +904 -0
- package/mcp-listing.http.json +25 -0
- package/mcp-listing.json +34 -0
- package/package.json +77 -0
- package/scripts/build-binary.mjs +104 -0
- package/scripts/build-site-dashboard.mjs +52 -0
- package/scripts/collect-site-articles.mjs +432 -0
- package/scripts/export-ddn-env.mjs +107 -0
- package/scripts/fetch-article-stats.mjs +212 -0
- package/scripts/pack-and-verify.mjs +111 -0
- package/scripts/publisher.mjs +255 -0
- package/scripts/sync-marketplace-readme.mjs +380 -0
- package/scripts/tool-set.mjs +48 -0
- package/scripts/verify-binary.mjs +115 -0
- package/scripts/verify-clawdao-bridge.mjs +41 -0
- package/scripts/verify-e2e.mjs +176 -0
- package/scripts/verify-http-mcp.mjs +94 -0
- package/scripts/verify-listing-sync.mjs +90 -0
- package/scripts/verify-marketplace-readme.mjs +266 -0
- package/scripts/verify-mcp-handshake.mjs +98 -0
- package/scripts/verify-news-publish.mjs +257 -0
- package/scripts/verify-npx-install.mjs +171 -0
- package/scripts/verify-site-dashboard.mjs +87 -0
- package/scripts/verify-site-layout.mjs +194 -0
- package/tests/client-auth.test.mjs +159 -0
- package/tests/dao-profile.test.mjs +126 -0
- package/tests/marketplace-readme-path.test.mjs +16 -0
- package/tests/mcp-server.test.mjs +187 -0
- package/tests/member-submission.test.mjs +150 -0
- package/tests/official-listing.test.mjs +52 -0
- package/tests/smoke.mjs +262 -0
- package/tests/sync-marketplace-readme.test.mjs +50 -0
- package/tests/tool-set.test.mjs +54 -0
- package/tests/versions-sync-dryrun.test.mjs +315 -0
package/lib/courses.mjs
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 课程操作模块 - 亿检链课程管理
|
|
3
|
+
* 提供上传、列表、更新、管理等课程操作功能
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { LimsClient } from './client.mjs';
|
|
7
|
+
|
|
8
|
+
export class CourseManager {
|
|
9
|
+
#client;
|
|
10
|
+
|
|
11
|
+
constructor(clientOrConfig) {
|
|
12
|
+
this.#client = clientOrConfig instanceof LimsClient
|
|
13
|
+
? clientOrConfig
|
|
14
|
+
: new LimsClient(clientOrConfig);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 列出所有课程(管理端) */
|
|
18
|
+
async list({ page = 1, pageSize = 10, keyword, status, categoryUuid, sortBy, sortOrder } = {}) {
|
|
19
|
+
const result = await this.#client.listCourses({
|
|
20
|
+
page,
|
|
21
|
+
pageSize,
|
|
22
|
+
keyword: keyword || undefined,
|
|
23
|
+
status: status || undefined,
|
|
24
|
+
categoryUuid: categoryUuid || undefined,
|
|
25
|
+
sortBy: sortBy || undefined,
|
|
26
|
+
sortOrder: sortOrder || undefined,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (!result.ok) return result;
|
|
30
|
+
|
|
31
|
+
const data = result.data || {};
|
|
32
|
+
const items = data.items || data.list || [];
|
|
33
|
+
const pagination = data.pagination || { current: page, pageSize };
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
ok: true,
|
|
37
|
+
message: result.message,
|
|
38
|
+
items,
|
|
39
|
+
pagination,
|
|
40
|
+
total: pagination.total || items.length,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 列出已发布课程(公开) */
|
|
45
|
+
async listPublished({ page = 1, pageSize = 10, keyword, categoryUuid } = {}) {
|
|
46
|
+
const result = await this.#client.listPublishedCourses({
|
|
47
|
+
page,
|
|
48
|
+
pageSize,
|
|
49
|
+
keyword: keyword || undefined,
|
|
50
|
+
categoryUuid: categoryUuid || undefined,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (!result.ok) return result;
|
|
54
|
+
|
|
55
|
+
const data = result.data || {};
|
|
56
|
+
const items = data.items || data.list || [];
|
|
57
|
+
const pagination = data.pagination || { current: page, pageSize };
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
ok: true,
|
|
61
|
+
message: result.message,
|
|
62
|
+
items,
|
|
63
|
+
pagination,
|
|
64
|
+
total: pagination.total || items.length,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 获取课程详情 */
|
|
69
|
+
async get(courseId) {
|
|
70
|
+
return this.#client.getCourse(courseId);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 创建课程 */
|
|
74
|
+
async create({
|
|
75
|
+
title,
|
|
76
|
+
description,
|
|
77
|
+
coverImage,
|
|
78
|
+
categoryUuid,
|
|
79
|
+
teacherUuid,
|
|
80
|
+
price = 0,
|
|
81
|
+
difficulty,
|
|
82
|
+
status = 'draft',
|
|
83
|
+
body,
|
|
84
|
+
}) {
|
|
85
|
+
const payload = {
|
|
86
|
+
title,
|
|
87
|
+
...(description && { description }),
|
|
88
|
+
...(coverImage && { coverImage }),
|
|
89
|
+
...(categoryUuid && { categoryUuid }),
|
|
90
|
+
...(teacherUuid && { teacherUuid }),
|
|
91
|
+
price,
|
|
92
|
+
...(difficulty && { difficulty }),
|
|
93
|
+
status,
|
|
94
|
+
...(body && { body }),
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return this.#client.createCourse(payload);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 更新课程 */
|
|
101
|
+
async update(courseId, updates) {
|
|
102
|
+
return this.#client.updateCourse(courseId, updates);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** 删除课程 */
|
|
106
|
+
async delete(courseId) {
|
|
107
|
+
return this.#client.deleteCourse(courseId);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** 发布课程(更新状态为 published) */
|
|
111
|
+
async publish(courseId) {
|
|
112
|
+
return this.#client.updateCourseStatus(courseId, 'published');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 下架课程 */
|
|
116
|
+
async unpublish(courseId) {
|
|
117
|
+
return this.#client.updateCourseStatus(courseId, 'draft');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** 上传课程(一步创建) */
|
|
121
|
+
async upload({
|
|
122
|
+
title,
|
|
123
|
+
description,
|
|
124
|
+
coverImage,
|
|
125
|
+
categoryUuid,
|
|
126
|
+
teacherUuid,
|
|
127
|
+
price = 0,
|
|
128
|
+
difficulty,
|
|
129
|
+
body,
|
|
130
|
+
publish: shouldPublish = false,
|
|
131
|
+
}) {
|
|
132
|
+
const result = await this.create({
|
|
133
|
+
title,
|
|
134
|
+
description,
|
|
135
|
+
coverImage,
|
|
136
|
+
categoryUuid,
|
|
137
|
+
teacherUuid,
|
|
138
|
+
price,
|
|
139
|
+
difficulty,
|
|
140
|
+
body,
|
|
141
|
+
status: shouldPublish ? 'published' : 'draft',
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
if (!result.ok) return result;
|
|
145
|
+
|
|
146
|
+
const courseId = result.data?.id || result.data?.uuid;
|
|
147
|
+
return {
|
|
148
|
+
ok: true,
|
|
149
|
+
message: shouldPublish ? '课程已创建并发布' : '课程草稿已创建',
|
|
150
|
+
data: { courseId, ...result.data },
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** 列出课程分类 */
|
|
155
|
+
async listCategories(params = {}) {
|
|
156
|
+
return this.#client.listCourseCategories(params);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** 创建课程分类 */
|
|
160
|
+
async createCategory({ name, description, parentUuid, sort } = {}) {
|
|
161
|
+
const payload = {
|
|
162
|
+
name,
|
|
163
|
+
...(description && { description }),
|
|
164
|
+
...(parentUuid && { parentUuid }),
|
|
165
|
+
...(sort !== undefined && { sort }),
|
|
166
|
+
};
|
|
167
|
+
return this.#client.createCourseCategory(payload);
|
|
168
|
+
}
|
|
169
|
+
}
|
package/lib/dao.mjs
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DAO 档案(社区资料)操作模块 - 亿检链
|
|
3
|
+
* 站点 id === DAO id:`/api/v1/daos/:daoId` 既是站点基础信息,也是社区档案。
|
|
4
|
+
*
|
|
5
|
+
* 接口(实测 2026-11):
|
|
6
|
+
* GET /api/v1/daos/:daoId 社区详情(name/domain/category/logoUrl/bannerUrl/description/detail/links/motionDescription)
|
|
7
|
+
* —— 公开可读(不带 token 也能读),带 token 时额外返回 userPermissions
|
|
8
|
+
* PUT /api/v1/daos/:daoId 社区更新(需 dao:communities:update / config:config-dao:update)
|
|
9
|
+
* —— **局部更新**:只写提交的字段,未提交字段保持原样(已实测验证)
|
|
10
|
+
*
|
|
11
|
+
* 注意:档案字段会被**公开端**直接消费,改动前先确认文案口径与站点首页一致。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { LimsClient } from './client.mjs';
|
|
15
|
+
|
|
16
|
+
/** 允许通过本模块写入的档案字段(其余字段一律忽略,避免误改 domain / appSecret 等) */
|
|
17
|
+
export const DAO_PROFILE_FIELDS = [
|
|
18
|
+
'name', // 社区名称
|
|
19
|
+
'description', // 简介(短,1-2 句,列表页直接展示)
|
|
20
|
+
'detail', // 详细介绍(长文)
|
|
21
|
+
'category', // 分类
|
|
22
|
+
'logoUrl', // 头像 / logo
|
|
23
|
+
'bannerUrl', // 横幅
|
|
24
|
+
'links', // 相关链接 [{ url, name }]
|
|
25
|
+
'motionDescription', // 动态区简介
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/** 字段中文说明(CLI 展示用) */
|
|
29
|
+
export const DAO_PROFILE_FIELD_LABELS = {
|
|
30
|
+
name: '社区名称',
|
|
31
|
+
description: '简介',
|
|
32
|
+
detail: '详细介绍',
|
|
33
|
+
category: '分类',
|
|
34
|
+
logoUrl: '头像',
|
|
35
|
+
bannerUrl: '横幅',
|
|
36
|
+
links: '相关链接',
|
|
37
|
+
motionDescription: '动态简介',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const isFilled = (value) => typeof value === 'string' && value.trim().length > 0;
|
|
41
|
+
|
|
42
|
+
const isPlainObject = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
43
|
+
|
|
44
|
+
/** 档案里的敏感字段:读取时一律打码(CLI / 脚本都不需要这两个值) */
|
|
45
|
+
export const DAO_SECRET_FIELDS = ['appSecret', 'appKey'];
|
|
46
|
+
|
|
47
|
+
/** 把敏感字段打码,返回 { profile, redacted } */
|
|
48
|
+
export const redactProfile = (profile = {}) => {
|
|
49
|
+
const out = { ...profile };
|
|
50
|
+
const redacted = [];
|
|
51
|
+
for (const key of DAO_SECRET_FIELDS) {
|
|
52
|
+
if (out[key]) {
|
|
53
|
+
out[key] = '***';
|
|
54
|
+
redacted.push(key);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { profile: out, redacted };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export class DaoManager {
|
|
61
|
+
#client;
|
|
62
|
+
#daoId;
|
|
63
|
+
|
|
64
|
+
constructor(clientOrConfig) {
|
|
65
|
+
this.#client = clientOrConfig instanceof LimsClient
|
|
66
|
+
? clientOrConfig
|
|
67
|
+
: new LimsClient(clientOrConfig);
|
|
68
|
+
this.#daoId = clientOrConfig?.daoId || this.#client.getConfig().daoId || null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 当前 DAO id(站点 id 与 DAO id 相同) */
|
|
72
|
+
getDaoId() {
|
|
73
|
+
// ★ 优先用构造时传入的;否则回退到客户端的当前值
|
|
74
|
+
// (客户端在收到带 currentDao 的响应后会回填 daoId ⇒ API 访问令牌
|
|
75
|
+
// 绑定 DAO 时,用户根本不需要配 DDN_HUB_DAO_ID)。
|
|
76
|
+
return this.#daoId || this.#client.getConfig().daoId || null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 拿到可用的 DAO id(必要时向服务端探测一次)。
|
|
81
|
+
* @returns {Promise<string|null>}
|
|
82
|
+
*/
|
|
83
|
+
async #ensureDaoId() {
|
|
84
|
+
const known = this.getDaoId();
|
|
85
|
+
if (known) return known;
|
|
86
|
+
const client = this.#client;
|
|
87
|
+
if (client && typeof client.ensureDaoId === 'function') {
|
|
88
|
+
const discovered = await client.ensureDaoId();
|
|
89
|
+
return discovered || this.getDaoId() || null;
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 读取 DAO 档案 */
|
|
95
|
+
async getProfile() {
|
|
96
|
+
const daoId = await this.#ensureDaoId();
|
|
97
|
+
if (!daoId) return { ok: false, message: '需要 DDN_HUB_DAO_ID 才能读取 DAO 档案' };
|
|
98
|
+
const result = await this.#client.request({
|
|
99
|
+
method: 'GET',
|
|
100
|
+
path: `/api/v1/daos/${daoId}`,
|
|
101
|
+
authRequired: true,
|
|
102
|
+
});
|
|
103
|
+
if (!result.ok) return result;
|
|
104
|
+
const { profile, redacted } = redactProfile(result.data || {});
|
|
105
|
+
return { ok: true, message: result.message, profile, redacted };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 从任意对象里挑出可写的档案字段(忽略白名单外的键与 undefined)
|
|
110
|
+
* @param {object} source
|
|
111
|
+
* @returns {{patch: object, ignored: string[]}}
|
|
112
|
+
*/
|
|
113
|
+
static pickPatch(source = {}) {
|
|
114
|
+
const patch = {};
|
|
115
|
+
const ignored = [];
|
|
116
|
+
for (const [key, value] of Object.entries(source || {})) {
|
|
117
|
+
if (!DAO_PROFILE_FIELDS.includes(key)) {
|
|
118
|
+
ignored.push(key);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (value === undefined) continue;
|
|
122
|
+
patch[key] = value;
|
|
123
|
+
}
|
|
124
|
+
return { patch, ignored };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 更新 DAO 档案(局部更新:只提交 patch 里出现的字段)
|
|
129
|
+
* @param {object} patch 档案字段子集(键必须在 DAO_PROFILE_FIELDS 内)
|
|
130
|
+
* @param {{dryRun?: boolean}} [options]
|
|
131
|
+
*/
|
|
132
|
+
async updateProfile(patch, { dryRun = false } = {}) {
|
|
133
|
+
const daoId = await this.#ensureDaoId();
|
|
134
|
+
if (!daoId) return { ok: false, message: '需要 DDN_HUB_DAO_ID 才能更新 DAO 档案' };
|
|
135
|
+
if (!isPlainObject(patch)) return { ok: false, message: 'patch 必须是对象' };
|
|
136
|
+
|
|
137
|
+
const { patch: clean, ignored } = DaoManager.pickPatch(patch);
|
|
138
|
+
const keys = Object.keys(clean);
|
|
139
|
+
if (keys.length === 0) {
|
|
140
|
+
return { ok: false, message: `没有可写字段(可用:${DAO_PROFILE_FIELDS.join(' / ')})` };
|
|
141
|
+
}
|
|
142
|
+
// 文本字段不允许空白串(避免把简介清成空)
|
|
143
|
+
for (const key of ['name', 'description']) {
|
|
144
|
+
if (key in clean && !isFilled(clean[key])) {
|
|
145
|
+
return { ok: false, message: `${key} 不能为空` };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (dryRun) {
|
|
149
|
+
return { ok: true, message: `dry-run:将写入 ${keys.join(', ')}`, patch: clean, ignored, keys, dryRun: true };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const result = await this.#client.request({
|
|
153
|
+
method: 'PUT',
|
|
154
|
+
path: `/api/v1/daos/${daoId}`,
|
|
155
|
+
authRequired: true,
|
|
156
|
+
body: clean,
|
|
157
|
+
});
|
|
158
|
+
if (!result.ok) return result;
|
|
159
|
+
return { ok: true, message: result.message, patch: clean, ignored, keys, dryRun: false };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 回读校验:写入后逐字段比对是否真的持久化
|
|
164
|
+
* @param {object} expected 期望字段值
|
|
165
|
+
*/
|
|
166
|
+
async verify(expected = {}) {
|
|
167
|
+
const read = await this.getProfile();
|
|
168
|
+
if (!read.ok) return read;
|
|
169
|
+
const mismatched = [];
|
|
170
|
+
for (const [key, want] of Object.entries(expected)) {
|
|
171
|
+
const got = read.profile?.[key];
|
|
172
|
+
if (JSON.stringify(got) !== JSON.stringify(want)) mismatched.push({ key, expected: want, actual: got });
|
|
173
|
+
}
|
|
174
|
+
return { ok: mismatched.length === 0, message: mismatched.length === 0 ? '回读一致' : `${mismatched.length} 个字段不一致`, profile: read.profile, mismatched };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 禁用词检查(品牌残留扫描,覆盖档案里所有字符串字段)
|
|
179
|
+
* @param {string[]} words
|
|
180
|
+
*/
|
|
181
|
+
async scanForbidden(words = []) {
|
|
182
|
+
const read = await this.getProfile();
|
|
183
|
+
if (!read.ok) return read;
|
|
184
|
+
const hits = [];
|
|
185
|
+
for (const key of DAO_PROFILE_FIELDS) {
|
|
186
|
+
const value = read.profile?.[key];
|
|
187
|
+
if (value === undefined || value === null) continue;
|
|
188
|
+
const text = JSON.stringify(value);
|
|
189
|
+
for (const word of words) {
|
|
190
|
+
if (word && text.includes(word)) hits.push({ field: key, word });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return { ok: hits.length === 0, message: hits.length === 0 ? '档案无禁用词' : `命中 ${hits.length} 处禁用词`, hits, profile: read.profile };
|
|
194
|
+
}
|
|
195
|
+
}
|
package/lib/env.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 零依赖 .env 加载器
|
|
3
|
+
* 仓库根 .env → process.env(仅补缺失项,不覆盖已存在的环境变量)
|
|
4
|
+
*
|
|
5
|
+
* ★ 为什么放到 lib 而不是只放在 bin:
|
|
6
|
+
* 之前只有 CLI 会加载 .env,直接 import 本 lib 的脚本拿不到
|
|
7
|
+
* DDN_HUB_AUTH_TOKEN,报「需要 DDN_HUB_AUTH_TOKEN 才能调用此工具」。
|
|
8
|
+
* 抽成公共模块后,CLI 与脚本两条路径行为一致。
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
11
|
+
import { dirname, resolve } from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
|
|
14
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const ENV_PATH = resolve(__dirname, '..', '.env');
|
|
16
|
+
|
|
17
|
+
/** 载入仓库根 .env(幂等:已存在的环境变量不会被覆盖) */
|
|
18
|
+
export function loadEnv() {
|
|
19
|
+
try {
|
|
20
|
+
if (!existsSync(ENV_PATH)) return;
|
|
21
|
+
for (const line of readFileSync(ENV_PATH, 'utf-8').split(/\r?\n/)) {
|
|
22
|
+
const trimmed = line.trim();
|
|
23
|
+
if (!trimmed || trimmed.startsWith('#') || !trimmed.includes('=')) continue;
|
|
24
|
+
const eq = trimmed.indexOf('=');
|
|
25
|
+
const key = trimmed.slice(0, eq).trim();
|
|
26
|
+
const val = trimmed.slice(eq + 1).trim().replace(/^['"]|['"]$/g, '');
|
|
27
|
+
if (key && process.env[key] === undefined) process.env[key] = val;
|
|
28
|
+
}
|
|
29
|
+
} catch { /* .env 缺失或不可读时忽略,直接使用环境变量 */ }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
loadEnv();
|
package/lib/feedback.mjs
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 反馈提交模块 - 亿检链用户反馈
|
|
3
|
+
* 提供提交反馈、查看反馈列表等功能
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { LimsClient } from './client.mjs';
|
|
7
|
+
|
|
8
|
+
export class FeedbackManager {
|
|
9
|
+
#client;
|
|
10
|
+
|
|
11
|
+
constructor(clientOrConfig) {
|
|
12
|
+
this.#client = clientOrConfig instanceof LimsClient
|
|
13
|
+
? clientOrConfig
|
|
14
|
+
: new LimsClient(clientOrConfig);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 提交反馈
|
|
19
|
+
* 支持多种反馈类型:建议、问题报告、功能请求、内容纠错等
|
|
20
|
+
*/
|
|
21
|
+
async submit({
|
|
22
|
+
title,
|
|
23
|
+
content,
|
|
24
|
+
type = 'suggestion',
|
|
25
|
+
contact,
|
|
26
|
+
images,
|
|
27
|
+
postId,
|
|
28
|
+
courseId,
|
|
29
|
+
}) {
|
|
30
|
+
// 根据亿检链 API,反馈通过创建特定类型的文章或使用系统反馈接口
|
|
31
|
+
// 这里使用 CMS posts 的通用提交能力
|
|
32
|
+
const payload = {
|
|
33
|
+
title,
|
|
34
|
+
content,
|
|
35
|
+
postType: 'feedback',
|
|
36
|
+
feedbackType: type,
|
|
37
|
+
...(contact && { contact }),
|
|
38
|
+
...(images && { images }),
|
|
39
|
+
...(postId && { postId }),
|
|
40
|
+
...(courseId && { courseId }),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return this.#client.createPost(payload);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 获取反馈列表
|
|
48
|
+
*/
|
|
49
|
+
async list({ page = 1, limit = 20, status, type } = {}) {
|
|
50
|
+
const result = await this.#client.listPosts({
|
|
51
|
+
page,
|
|
52
|
+
limit,
|
|
53
|
+
postType: 'feedback',
|
|
54
|
+
status: status || undefined,
|
|
55
|
+
...(type && { feedbackType: type }),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (!result.ok) return result;
|
|
59
|
+
|
|
60
|
+
const items = result.data?.items || result.data?.list || [];
|
|
61
|
+
return {
|
|
62
|
+
ok: true,
|
|
63
|
+
message: result.message,
|
|
64
|
+
items,
|
|
65
|
+
total: result.data?.pagination?.total || items.length,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|