weaver-e9-assistant-cli 1.0.0 → 1.1.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.
- package/dist/auth.js +18 -8
- package/dist/blog.js +101 -8
- package/dist/cli.js +360 -59
- package/dist/client.js +26 -5
- package/dist/cube.js +121 -18
- package/dist/email.js +4 -1
- package/dist/subordinate.js +433 -0
- package/dist/todobatch.js +7 -0
- package/dist/wfuser.js +37 -0
- package/dist/workflow.js +33 -19
- package/dist/workplan.js +37 -0
- package/package.json +27 -25
package/dist/client.js
CHANGED
|
@@ -174,15 +174,36 @@ export class E9Api {
|
|
|
174
174
|
throw new Error(`请求失败:${method} ${url}。服务器可能不可达或网络不通。`);
|
|
175
175
|
return er;
|
|
176
176
|
}
|
|
177
|
-
/**
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
/**
|
|
178
|
+
* GET。URL+query 拼好后委托 requestWithRetry。
|
|
179
|
+
* opts.forceCookie=true 时强制走 cookie 头裸发一次(跳过 token/ensureValid)——
|
|
180
|
+
* 供 token 通道 no-op(200 但业务空、非 401 不走重试)的接口逃生,如 /api/ec/dev/app/getUserInfo。
|
|
181
|
+
*/
|
|
182
|
+
async get(path, query, opts = {}) {
|
|
183
|
+
const url = buildUrl(this.baseUrl, path, query);
|
|
184
|
+
if (opts?.forceCookie) {
|
|
185
|
+
const headers = await this.getHeaders(undefined, { forceCookie: true });
|
|
186
|
+
const res = await fetch(url, { method: 'GET', headers, signal: AbortSignal.timeout(30000) }).catch(() => null);
|
|
187
|
+
return res ? await toE9Response(res) : null;
|
|
188
|
+
}
|
|
189
|
+
return this.requestWithRetry('GET', url, undefined, 30000);
|
|
180
190
|
}
|
|
181
|
-
/**
|
|
182
|
-
|
|
191
|
+
/**
|
|
192
|
+
* POST。body 用 URLSearchParams(与原 e9Request 编码一致),委托 requestWithRetry。
|
|
193
|
+
* opts.forceCookie=true 时强制走 cookie 头裸发一次(跳过 token/ensureValid)——
|
|
194
|
+
* 供 token 通道 no-op(200 但业务空、非 401 不走重试)的接口逃生,如 hrm 下属查询。
|
|
195
|
+
*/
|
|
196
|
+
async post(path, body, opts = {}) {
|
|
183
197
|
const form = new URLSearchParams();
|
|
184
198
|
for (const [k, v] of Object.entries(body ?? {}))
|
|
185
199
|
form.append(k, v);
|
|
200
|
+
if (opts?.forceCookie) {
|
|
201
|
+
const headers = await this.getHeaders('application/x-www-form-urlencoded; charset=utf-8', { forceCookie: true });
|
|
202
|
+
const res = await fetch(buildUrl(this.baseUrl, path), {
|
|
203
|
+
method: 'POST', headers, body: form.toString(), signal: AbortSignal.timeout(30000),
|
|
204
|
+
}).catch(() => null);
|
|
205
|
+
return res ? await toE9Response(res) : null;
|
|
206
|
+
}
|
|
186
207
|
return this.requestWithRetry('POST', buildUrl(this.baseUrl, path), form.toString(), 30000);
|
|
187
208
|
}
|
|
188
209
|
}
|
package/dist/cube.js
CHANGED
|
@@ -79,6 +79,74 @@ export async function getCubeCondition(cfg, opts = {}) {
|
|
|
79
79
|
.filter((it) => it.label);
|
|
80
80
|
return { items, raw: j };
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* ★越权防护 人员条件 label 白名单(专项守卫正则,不复用 wfuser.js PERSON_LABEL——
|
|
84
|
+
* 它漏了 审批人/接收人/操作人/下属,且含 联系人 会误伤 联系人电话)。
|
|
85
|
+
* 判定前先剔除含 电话/手机/邮箱/号码/传真/部门/日期/时间 的字段(非人筛选)。
|
|
86
|
+
* 说明:方案A(label 正则)为主判据;conditionType 码未知,实跑校准后补 type 码 OR。
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* 明确排除的非人字段:联系方式(联系人电话…)/ 日期时间(填报日期…)/ 计数单位(人数/人次/人天…)。
|
|
90
|
+
* 不排除「部门」——部门负责人/部门经办人/部门审批人仍是人员,后缀「人」判据应当命中。
|
|
91
|
+
*/
|
|
92
|
+
const NON_PERSON_LABEL = /电话|手机|邮箱|号码|传真|日期|时间|区间|人数|人次|人天/;
|
|
93
|
+
/** 明确的人员白名单(不含「人」字或不在后缀规则内的:姓名/人员/联系人/下属/上级)。 */
|
|
94
|
+
export const PERSON_CONDITION_LABEL =
|
|
95
|
+
/^(姓名|人员|联系人|下属|上级|领导)$/u;
|
|
96
|
+
/** 人员后缀判据(先剔除 NON_PERSON 后):X人/ X人员/ X员/ X者(报销人/值班人员/采购员/阅读者…)。
|
|
97
|
+
* 人员类别/人员类型等「人员+名词」不是人员过滤(人员类别=正式工),靠「末尾字符∈人者员」排除。 */
|
|
98
|
+
const PERSON_SUFFIX = /[人者员]$/u;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 该 label 是否属于「按人过滤」查询条件(fail-closed:宁可多拦)。
|
|
102
|
+
* 判据 = 后缀启发式「X人」(报销人/使用人/领用人/申请人/审批人/经办人/填报人…全部覆盖)+
|
|
103
|
+
* 白名单(姓名/人员/联系人/下属/上级);先剔除联系方式/日期时间/计数单位。
|
|
104
|
+
* 后缀启发式替代旧白名单枚举——旧白名单漏「报销人/使用人/领用人」等,会放行越权查询。
|
|
105
|
+
*/
|
|
106
|
+
export function isPersonConditionLabel(label) {
|
|
107
|
+
if (typeof label !== 'string' || !label.trim())
|
|
108
|
+
return false;
|
|
109
|
+
const l = label.trim();
|
|
110
|
+
if (NON_PERSON_LABEL.test(l))
|
|
111
|
+
return false;
|
|
112
|
+
if (PERSON_SUFFIX.test(l))
|
|
113
|
+
return true;
|
|
114
|
+
if (l.includes('姓名'))
|
|
115
|
+
return true;
|
|
116
|
+
return PERSON_CONDITION_LABEL.test(l);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* ★越权防护 人员条件分类(纯函数,便于单测)。
|
|
121
|
+
* condItems:getCubeCondition 返回的条件项 [{label, domkey, type}]。
|
|
122
|
+
* rawPairs:[["键","值"],...](键可能是 domkey 也可能是中文 label)。
|
|
123
|
+
* 返回 [{label, domkey, value}]——命中人员条件白名单的键值对。
|
|
124
|
+
*/
|
|
125
|
+
export function classifyPersonConditions(condItems, rawPairs) {
|
|
126
|
+
if (!Array.isArray(rawPairs) || rawPairs.length === 0)
|
|
127
|
+
return [];
|
|
128
|
+
// domkey → label 索引(label 键也能命中 condItems 的 label)
|
|
129
|
+
const domToLabel = {};
|
|
130
|
+
for (const it of condItems || [])
|
|
131
|
+
for (const dk of (it.domkey ?? []))
|
|
132
|
+
if (it.label && !(dk in domToLabel))
|
|
133
|
+
domToLabel[dk] = it.label;
|
|
134
|
+
const labels = new Set((condItems || []).map((it) => it.label).filter(Boolean));
|
|
135
|
+
const personConditions = [];
|
|
136
|
+
for (const [k, v] of rawPairs) {
|
|
137
|
+
const key = String(k ?? '').trim();
|
|
138
|
+
const val = String(v ?? '').trim();
|
|
139
|
+
if (!key || !val)
|
|
140
|
+
continue;
|
|
141
|
+
const label = domToLabel[key] ?? (labels.has(key) ? key : null);
|
|
142
|
+
// 后缀启发式直接判按键名(即使条件定义缺失,也能拦「报销人=王五」);
|
|
143
|
+
// domkey 依赖 domToLabel 反查;两者皆无则落到 unverifiablePerson 由调用方 fail-closed 拒绝。
|
|
144
|
+
if (isPersonConditionLabel(label ?? key))
|
|
145
|
+
personConditions.push({ label: label ?? key, domkey: key, value: val });
|
|
146
|
+
}
|
|
147
|
+
return personConditions;
|
|
148
|
+
}
|
|
149
|
+
|
|
82
150
|
/**
|
|
83
151
|
* ★新 条件字符串 → conditionValues 映射(P2-3,0.4.8)。
|
|
84
152
|
*
|
|
@@ -86,7 +154,10 @@ export async function getCubeCondition(cfg, opts = {}) {
|
|
|
86
154
|
* - 键以 `con_`/`dom_`/`field`/`col` 开头 → 视为合法 domkey,原样透传(向后兼容)。
|
|
87
155
|
* - 其它 → 视为中文 label,用 getCubeCondition 的 label→domkey 映射自动转换;
|
|
88
156
|
* 未匹配时返回 unresolved(含候选 label 列表),由调用方报错提示,不静默放空。
|
|
89
|
-
*
|
|
157
|
+
* ★越权防护(1.1.0):只要传了条件就取一次条件定义——含 domkey 直传也要反查 label 分类,
|
|
158
|
+
* 堵 `con_7261=...` 直接给 domkey 绕开中文 label 的越权口;getCubeCondition 抛错 → 透传不阻断
|
|
159
|
+
* 但打 stderr 警告「本次未做人员越权校验」。
|
|
160
|
+
* 返回 { conditionValues, unresolved:[{label, candidates:[...]}], personConditions:[{label, domkey, value}] }。
|
|
90
161
|
*/
|
|
91
162
|
export async function resolveCubeCondition(cfg, opts = {}) {
|
|
92
163
|
const customid = String(opts.customid);
|
|
@@ -100,21 +171,27 @@ export async function resolveCubeCondition(cfg, opts = {}) {
|
|
|
100
171
|
pairs.push([kv.slice(0, i).trim(), kv.slice(i + 1).trim()]);
|
|
101
172
|
}
|
|
102
173
|
if (pairs.length === 0)
|
|
103
|
-
return { conditionValues, unresolved: [] };
|
|
174
|
+
return { conditionValues, unresolved: [], personConditions: [] };
|
|
104
175
|
// 判断是否含中文 label 键
|
|
105
176
|
const needsLabelMap = pairs.some(([k]) => !/^(con|dom|field|col)[-_]?/i.test(k));
|
|
106
|
-
let
|
|
107
|
-
let
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
177
|
+
let condItems = [];
|
|
178
|
+
let condFetched = false;
|
|
179
|
+
// ★越权防护:只要传了条件就取一次条件定义(含 domkey 直传也要反查 label 分类)
|
|
180
|
+
try {
|
|
181
|
+
const cond = await getCubeCondition(cfg, { customid });
|
|
182
|
+
condItems = cond.items;
|
|
183
|
+
condFetched = true;
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
// fail-closed:定义读不到时 domkey 无法反查 → 由下方 unverifiablePerson 拒绝;中文 label 按名称判定不受影响
|
|
187
|
+
if (pairs.some(([k]) => /^(con|dom|field|col)[-_]?/i.test(k)))
|
|
188
|
+
process.stderr.write('⚠ 无法读取台账查询条件定义:domkey 类条件将被拒绝(无法确认是否按人过滤),中文字段名条件按名称判定。\n');
|
|
117
189
|
}
|
|
190
|
+
const labelToDom = {};
|
|
191
|
+
for (const it of condItems)
|
|
192
|
+
for (const dk of (it.domkey ?? []))
|
|
193
|
+
if (it.label && !(it.label in labelToDom))
|
|
194
|
+
labelToDom[it.label] = dk;
|
|
118
195
|
const unresolved = [];
|
|
119
196
|
for (const [k, v] of pairs) {
|
|
120
197
|
if (/^(con|dom|field|col)[-_]?/i.test(k)) {
|
|
@@ -125,8 +202,8 @@ export async function resolveCubeCondition(cfg, opts = {}) {
|
|
|
125
202
|
if (domkey) {
|
|
126
203
|
conditionValues[domkey] = v;
|
|
127
204
|
}
|
|
128
|
-
else if (
|
|
129
|
-
//
|
|
205
|
+
else if (!condFetched) {
|
|
206
|
+
// 条件定义接口本身失败(网络抖动/无权限):按原样透传,不阻断(用户可能直接给了 domkey)——但已打越权警告
|
|
130
207
|
conditionValues[k] = v;
|
|
131
208
|
}
|
|
132
209
|
else {
|
|
@@ -135,7 +212,21 @@ export async function resolveCubeCondition(cfg, opts = {}) {
|
|
|
135
212
|
unresolved.push({ label: k, candidates });
|
|
136
213
|
}
|
|
137
214
|
}
|
|
138
|
-
|
|
215
|
+
// ★越权防护(fail-closed):无法确认是否按人过滤的条件 → 调用方硬拒绝。
|
|
216
|
+
// - 条件定义读取失败:domkey 类键无法反查 label → 无法确认;
|
|
217
|
+
// - 定义读取成功但 domkey 不在定义中:可能是未进筛选定义的人员字段 → 无法确认;
|
|
218
|
+
// 中文 label 键可经后缀启发式直接判定,不依赖定义。
|
|
219
|
+
const knownDom = new Set();
|
|
220
|
+
for (const it of condItems)
|
|
221
|
+
for (const dk of (it.domkey ?? []))
|
|
222
|
+
knownDom.add(dk);
|
|
223
|
+
let unverifiablePerson = false;
|
|
224
|
+
for (const [k, v] of pairs)
|
|
225
|
+
if (v && /^(con|dom|field|col)[-_]?/i.test(String(k)) && !knownDom.has(String(k).trim()))
|
|
226
|
+
unverifiablePerson = true;
|
|
227
|
+
// ★越权防护:人员条件分类(供调用方 assertNamesInScope 校验)
|
|
228
|
+
const personConditions = classifyPersonConditions(condItems, pairs);
|
|
229
|
+
return { conditionValues, unresolved, unverifiablePerson, personConditions };
|
|
139
230
|
}
|
|
140
231
|
/**
|
|
141
232
|
* ★新 字段下拉选项全表。GET /api/cube/search/getSearchColumnInfo?customid=<id>。
|
|
@@ -1112,9 +1203,13 @@ export async function submitCubeCard(cfg, opts = {}) {
|
|
|
1112
1203
|
await e9Request(ep, { method: 'POST', path: '/api/cube/new/card/cubeVerifyRepeat', body: { billid, type: '1', modeId, formId, _key, guid: 'card', verifys: '{}' } });
|
|
1113
1204
|
await e9Request(ep, { method: 'POST', path: '/api/cube/new/card/checkCardDataChange', body: { billid, type: '1', modeId, formId, _key, guid: 'card', changeDataTime: cdt, iscreate } });
|
|
1114
1205
|
// ④ JSONStr 全字段(cf.fields 所有 id,values 覆盖,未填给空)
|
|
1206
|
+
// 修复 #37:只读字段(isedit=false)未填时优先带 mainFields 返回的默认值 f.value——
|
|
1207
|
+
// 填报人(dkr)/填报日期(dkrq)/填报时间(dksj)/员工类型(yglx) 等由后端在新建态 mainFields
|
|
1208
|
+
// 预填当前用户/今天/当前时间,旧实现兜底 '' 覆盖为空格,实测 billid=35 这些字段提交后为空。
|
|
1209
|
+
// f.value 兜底同样修复 edit:编辑态 mainFields 带当前值,未传字段不再被清空。
|
|
1115
1210
|
const jsonObj = {};
|
|
1116
1211
|
for (const f of fields)
|
|
1117
|
-
jsonObj[`field${f.id}`] = String(values[f.id] ?? values[`field${f.id}`] ?? '');
|
|
1212
|
+
jsonObj[`field${f.id}`] = String(values[f.id] ?? values[`field${f.id}`] ?? f.value ?? '');
|
|
1118
1213
|
// ⑤ doSubmit(cookie,同 session)
|
|
1119
1214
|
const body = {
|
|
1120
1215
|
billid, type: '1', modeId, formId, _key, guid: 'card', token: cardToken,
|
|
@@ -1157,7 +1252,15 @@ export async function previewCubeCard(cfg, opts = {}) {
|
|
|
1157
1252
|
return { fieldId: String(fid), label: f?.label ?? `field${fid}`, value: so?.name ?? info.value };
|
|
1158
1253
|
});
|
|
1159
1254
|
}
|
|
1160
|
-
|
|
1255
|
+
// 未填字段并入 mainFields 默认值(只读字段填报人/填报日期等后端预填),
|
|
1256
|
+
// 保证 dry-run 确认表与真实提交字段集一致(同 submitCubeCard 的 f.value ?? '' 兜底)。
|
|
1257
|
+
const finalValues = { ...values };
|
|
1258
|
+
for (const f of fields) {
|
|
1259
|
+
const fid = String(f.id);
|
|
1260
|
+
if (finalValues[fid] === undefined && finalValues[`field${fid}`] === undefined && f.value !== undefined && f.value !== null && f.value !== '')
|
|
1261
|
+
finalValues[fid] = f.value;
|
|
1262
|
+
}
|
|
1263
|
+
return { modeId, formId, billid, layoutid, fields, finalValues, linked, files };
|
|
1161
1264
|
}
|
|
1162
1265
|
/** 删除台账记录(cookie)。GET /api/cube/expand/deleteData?operate=DeleteAction&billids=。 */
|
|
1163
1266
|
export async function deleteCubeData(cfg, opts = {}) {
|
package/dist/email.js
CHANGED
|
@@ -773,7 +773,10 @@ export async function uploadEmailAttachment(cfg, filePath, { name } = {}) {
|
|
|
773
773
|
catch {
|
|
774
774
|
j = null;
|
|
775
775
|
}
|
|
776
|
-
|
|
776
|
+
// 修复 #3:cookie 过期时后端返回 HTTP 200 + {msg:"登录信息超时",errorCode:"002",status:false},
|
|
777
|
+
// 旧判断把 r.ok(HTTP 200)当成功 → 附件实际未上传却显示成功。只认 body 的 status 成功标志。
|
|
778
|
+
const ok = j?.status === '1' || j?.status === 1 || j?.status === true;
|
|
779
|
+
return { ok, data: j?.data ?? null, raw: j };
|
|
777
780
|
}
|
|
778
781
|
/**
|
|
779
782
|
* 附件列表。链路:GET /api/email/attachment/list?filename=&subject= → sessionkey
|