@peninsula-med/beisen-ehr-configure 1.0.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 (2) hide show
  1. package/index.js +168 -0
  2. package/package.json +23 -0
package/index.js ADDED
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 北森 EHR Plugin 配置向导
4
+ * 使用:npx beisen-ehr-configure
5
+ */
6
+
7
+ import readline from 'readline';
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ import os from 'os';
11
+
12
+ const rl = readline.createInterface({
13
+ input: process.stdin,
14
+ output: process.stdout,
15
+ });
16
+
17
+ function question(prompt) {
18
+ return new Promise((resolve) => {
19
+ rl.question(prompt, (answer) => {
20
+ resolve(answer);
21
+ });
22
+ });
23
+ }
24
+
25
+ function sleep(ms) {
26
+ return new Promise(resolve => setTimeout(resolve, ms));
27
+ }
28
+
29
+ async function main() {
30
+ console.log('');
31
+ console.log('🏢 北森 EHR Plugin 配置向导');
32
+ console.log('='.repeat(50));
33
+ console.log('');
34
+ console.log('这个向导将帮助你配置北森 EHR 插件');
35
+ console.log('');
36
+
37
+ await sleep(500);
38
+
39
+ console.log('📋 需要准备的凭证:');
40
+ console.log(' • App Key(应用标识)');
41
+ console.log(' • App Secret(应用密钥)');
42
+ console.log(' • Tenant ID(企业租户 ID)');
43
+ console.log(' • Staff ID(你的员工 ID)');
44
+ console.log(' • 企业邮箱(用于识别员工)');
45
+ console.log('');
46
+ console.log('💡 提示:联系北森管理员获取这些凭证');
47
+ console.log('');
48
+
49
+ const appKey = await question('请输入 App Key: ');
50
+ const appSecret = await question('请输入 App Secret: ');
51
+ const tenantId = await question('请输入 Tenant ID: ');
52
+ const staffId = await question('请输入 Staff ID: ');
53
+ const email = await question('请输入企业邮箱: ');
54
+
55
+ console.log('');
56
+ console.log('🔍 验证配置信息...');
57
+ await sleep(500);
58
+
59
+ const config = {
60
+ apiUrl: 'https://openapi.italent.cn',
61
+ appKey: appKey.trim(),
62
+ appSecret: appSecret.trim(),
63
+ staffId: staffId.trim(),
64
+ tenantId: tenantId.trim(),
65
+ email: email.trim(),
66
+ };
67
+
68
+ const homeDir = os.homedir();
69
+ const configPath = path.join(homeDir, '.openclaw', 'config.json');
70
+
71
+ console.log('✅ 配置信息验证通过');
72
+ console.log('');
73
+ console.log('📁 配置文件位置:', configPath);
74
+ console.log('');
75
+
76
+ let openclawConfig = {};
77
+ if (fs.existsSync(configPath)) {
78
+ console.log('📖 读取现有配置...');
79
+ try {
80
+ const content = fs.readFileSync(configPath, 'utf-8');
81
+ openclawConfig = JSON.parse(content);
82
+ } catch (parseError) {
83
+ console.log('⚠️ 配置文件解析失败,将创建新配置');
84
+ }
85
+ } else {
86
+ console.log('📝 创建新配置文件...');
87
+ }
88
+
89
+ await sleep(500);
90
+
91
+ if (!openclawConfig.plugins) {
92
+ openclawConfig.plugins = {};
93
+ }
94
+
95
+ openclawConfig.plugins['@peninsula-med/beisen-ehr-plugin'] = {
96
+ enabled: true,
97
+ config: config,
98
+ };
99
+
100
+ if (fs.existsSync(configPath)) {
101
+ const backupPath = configPath + '.bak.' + Date.now();
102
+ fs.copyFileSync(configPath, backupPath);
103
+ console.log('💾 已备份原配置:', backupPath);
104
+ }
105
+
106
+ const configDir = path.dirname(configPath);
107
+ if (!fs.existsSync(configDir)) {
108
+ fs.mkdirSync(configDir, { recursive: true });
109
+ }
110
+
111
+ try {
112
+ fs.writeFileSync(configPath, JSON.stringify(openclawConfig, null, 2), 'utf-8');
113
+ console.log('');
114
+ console.log('✅ 配置已保存!');
115
+ console.log('');
116
+
117
+ const verifyContent = fs.readFileSync(configPath, 'utf-8');
118
+ const verifyConfig = JSON.parse(verifyContent);
119
+ if (verifyConfig.plugins && verifyConfig.plugins['@peninsula-med/beisen-ehr-plugin']) {
120
+ console.log('✅ 配置验证成功!');
121
+ } else {
122
+ console.log('⚠️ 配置验证失败,请检查配置文件');
123
+ }
124
+ } catch (writeError) {
125
+ console.error('');
126
+ console.error('❌ 保存配置失败:', writeError.message);
127
+ console.error('');
128
+ console.error('请手动编辑配置文件:');
129
+ console.error(' ' + configPath);
130
+ console.error('');
131
+ throw writeError;
132
+ }
133
+
134
+ console.log('');
135
+ console.log('📋 配置摘要:');
136
+ console.log(' • API 地址:', config.apiUrl);
137
+ console.log(' • App Key:', config.appKey.substring(0, 8) + '...');
138
+ console.log(' • Staff ID:', config.staffId);
139
+ console.log(' • Tenant ID:', config.tenantId);
140
+ console.log(' • 邮箱:', config.email);
141
+ console.log('');
142
+
143
+ await sleep(500);
144
+
145
+ console.log('🎉 配置完成!');
146
+ console.log('');
147
+ console.log('下一步:');
148
+ console.log(' 1. 重启 OpenClaw:');
149
+ console.log(' openclaw restart');
150
+ console.log('');
151
+ console.log(' 2. 测试插件:');
152
+ console.log(' 在对话中说:"帮我提交一个加班申请"');
153
+ console.log('');
154
+ console.log('='.repeat(50));
155
+ console.log('');
156
+
157
+ rl.close();
158
+ }
159
+
160
+ main().catch((error) => {
161
+ console.error('');
162
+ console.error('❌ 配置失败:', error.message);
163
+ console.error('');
164
+ console.error('如需帮助,请联系管理员。');
165
+ console.error('');
166
+ rl.close();
167
+ process.exit(1);
168
+ });
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@peninsula-med/beisen-ehr-configure",
3
+ "version": "1.0.0",
4
+ "description": "北森 EHR Plugin 配置向导",
5
+ "type": "module",
6
+ "bin": {
7
+ "beisen-ehr-configure": "./index.js"
8
+ },
9
+ "keywords": [
10
+ "beisen",
11
+ "ehr",
12
+ "openclaw",
13
+ "configure",
14
+ "北森",
15
+ "配置"
16
+ ],
17
+ "author": "龙二 🐉",
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/your-org/beisen-ehr-configure.git"
22
+ }
23
+ }